MCPcopy
hub / github.com/bubkoo/html-to-image / cloneCSSStyle

Function cloneCSSStyle

src/clone-node.ts:122–164  ·  view source on GitHub ↗
(
  nativeNode: T,
  clonedNode: T,
  options: Options,
)

Source from the content-addressed store, hash-verified

120}
121
122function cloneCSSStyle<T extends HTMLElement>(
123 nativeNode: T,
124 clonedNode: T,
125 options: Options,
126) {
127 const targetStyle = clonedNode.style
128 if (!targetStyle) {
129 return
130 }
131
132 const sourceStyle = window.getComputedStyle(nativeNode)
133 if (sourceStyle.cssText) {
134 targetStyle.cssText = sourceStyle.cssText
135 targetStyle.transformOrigin = sourceStyle.transformOrigin
136 } else {
137 getStyleProperties(options).forEach((name) => {
138 let value = sourceStyle.getPropertyValue(name)
139 if (name === 'font-size' && value.endsWith('px')) {
140 const reducedFont =
141 Math.floor(parseFloat(value.substring(0, value.length - 2))) - 0.1
142 value = `${reducedFont}px`
143 }
144
145 if (
146 isInstanceOfElement(nativeNode, HTMLIFrameElement) &&
147 name === 'display' &&
148 value === 'inline'
149 ) {
150 value = 'block'
151 }
152
153 if (name === 'd' && clonedNode.getAttribute('d')) {
154 value = `path(${clonedNode.getAttribute('d')})`
155 }
156
157 targetStyle.setProperty(
158 name,
159 value,
160 sourceStyle.getPropertyPriority(name),
161 )
162 })
163 }
164}
165
166function cloneInputValue<T extends HTMLElement>(nativeNode: T, clonedNode: T) {
167 if (isInstanceOfElement(nativeNode, HTMLTextAreaElement)) {

Callers 1

decorateFunction · 0.85

Calls 2

getStylePropertiesFunction · 0.90
isInstanceOfElementFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…