@ohos-ports/html2canvas-pro 0.0.0-stage → 2.3.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/dist/html2canvas-pro.cjs +11191 -0
- package/dist/html2canvas-pro.cjs.map +1 -0
- package/dist/html2canvas-pro.esm.js +11182 -0
- package/dist/html2canvas-pro.esm.js.map +1 -0
- package/dist/html2canvas-pro.js +11196 -0
- package/dist/html2canvas-pro.js.map +1 -0
- package/dist/html2canvas-pro.min.js +10 -0
- package/dist/lib/config.js +49 -0
- package/dist/lib/core/abort-helper.js +20 -0
- package/dist/lib/core/background-parser.js +41 -0
- package/dist/lib/core/bitwise.js +5 -0
- package/dist/lib/core/cache-storage.js +268 -0
- package/dist/lib/core/config-assembler.js +88 -0
- package/dist/lib/core/constants.js +25 -0
- package/dist/lib/core/context.js +19 -0
- package/dist/lib/core/debugger.js +27 -0
- package/dist/lib/core/features.js +190 -0
- package/dist/lib/core/logger.js +56 -0
- package/dist/lib/core/lru-map.js +66 -0
- package/dist/lib/core/origin-checker.js +53 -0
- package/dist/lib/core/performance-monitor.js +185 -0
- package/dist/lib/core/render-element.js +132 -0
- package/dist/lib/core/util.js +4 -0
- package/dist/lib/core/validator.js +500 -0
- package/dist/lib/css/grouped/background-styles.js +36 -0
- package/dist/lib/css/grouped/border-styles.js +75 -0
- package/dist/lib/css/grouped/font-styles.js +93 -0
- package/dist/lib/css/grouped/layout-styles.js +127 -0
- package/dist/lib/css/index.js +330 -0
- package/dist/lib/css/layout/bounds.js +52 -0
- package/dist/lib/css/layout/text.js +133 -0
- package/dist/lib/css/property-descriptor.js +2 -0
- package/dist/lib/css/property-descriptors/background-blend-mode.js +41 -0
- package/dist/lib/css/property-descriptors/background-clip.js +23 -0
- package/dist/lib/css/property-descriptors/background-color.js +10 -0
- package/dist/lib/css/property-descriptors/background-image.js +24 -0
- package/dist/lib/css/property-descriptors/background-origin.js +23 -0
- package/dist/lib/css/property-descriptors/background-position.js +19 -0
- package/dist/lib/css/property-descriptors/background-repeat.js +33 -0
- package/dist/lib/css/property-descriptors/background-size.js +23 -0
- package/dist/lib/css/property-descriptors/border-color.js +14 -0
- package/dist/lib/css/property-descriptors/border-image-repeat.js +42 -0
- package/dist/lib/css/property-descriptors/border-image-slice.js +45 -0
- package/dist/lib/css/property-descriptors/border-image-source.js +22 -0
- package/dist/lib/css/property-descriptors/border-radius.js +15 -0
- package/dist/lib/css/property-descriptors/border-style.js +26 -0
- package/dist/lib/css/property-descriptors/border-width.js +20 -0
- package/dist/lib/css/property-descriptors/box-decoration-break.js +18 -0
- package/dist/lib/css/property-descriptors/box-shadow.js +54 -0
- package/dist/lib/css/property-descriptors/clip-path.js +189 -0
- package/dist/lib/css/property-descriptors/color.js +10 -0
- package/dist/lib/css/property-descriptors/content.js +19 -0
- package/dist/lib/css/property-descriptors/counter-increment.js +35 -0
- package/dist/lib/css/property-descriptors/counter-reset.js +18 -0
- package/dist/lib/css/property-descriptors/direction.js +18 -0
- package/dist/lib/css/property-descriptors/display.js +81 -0
- package/dist/lib/css/property-descriptors/duration.js +14 -0
- package/dist/lib/css/property-descriptors/filter.js +76 -0
- package/dist/lib/css/property-descriptors/float.js +22 -0
- package/dist/lib/css/property-descriptors/font-family.js +32 -0
- package/dist/lib/css/property-descriptors/font-size.js +10 -0
- package/dist/lib/css/property-descriptors/font-style.js +20 -0
- package/dist/lib/css/property-descriptors/font-variant-ligatures.js +34 -0
- package/dist/lib/css/property-descriptors/font-variant.js +13 -0
- package/dist/lib/css/property-descriptors/font-weight.js +25 -0
- package/dist/lib/css/property-descriptors/image-rendering.js +33 -0
- package/dist/lib/css/property-descriptors/letter-spacing.js +21 -0
- package/dist/lib/css/property-descriptors/line-break.js +23 -0
- package/dist/lib/css/property-descriptors/line-height.js +24 -0
- package/dist/lib/css/property-descriptors/list-style-image.js +17 -0
- package/dist/lib/css/property-descriptors/list-style-position.js +18 -0
- package/dist/lib/css/property-descriptors/list-style-type.js +122 -0
- package/dist/lib/css/property-descriptors/margin.js +13 -0
- package/dist/lib/css/property-descriptors/mix-blend-mode.js +31 -0
- package/dist/lib/css/property-descriptors/object-fit.js +28 -0
- package/dist/lib/css/property-descriptors/object-position.js +42 -0
- package/dist/lib/css/property-descriptors/opacity.js +16 -0
- package/dist/lib/css/property-descriptors/overflow-wrap.js +18 -0
- package/dist/lib/css/property-descriptors/overflow.js +27 -0
- package/dist/lib/css/property-descriptors/padding.js +14 -0
- package/dist/lib/css/property-descriptors/paint-order.js +33 -0
- package/dist/lib/css/property-descriptors/position.js +22 -0
- package/dist/lib/css/property-descriptors/quotes.js +41 -0
- package/dist/lib/css/property-descriptors/rotate.js +27 -0
- package/dist/lib/css/property-descriptors/text-align.js +21 -0
- package/dist/lib/css/property-descriptors/text-decoration-color.js +10 -0
- package/dist/lib/css/property-descriptors/text-decoration-line.js +28 -0
- package/dist/lib/css/property-descriptors/text-decoration-style.js +24 -0
- package/dist/lib/css/property-descriptors/text-decoration-thickness.js +26 -0
- package/dist/lib/css/property-descriptors/text-overflow.js +18 -0
- package/dist/lib/css/property-descriptors/text-shadow.js +46 -0
- package/dist/lib/css/property-descriptors/text-transform.js +20 -0
- package/dist/lib/css/property-descriptors/text-underline-offset.js +23 -0
- package/dist/lib/css/property-descriptors/transform-origin.js +24 -0
- package/dist/lib/css/property-descriptors/transform.js +57 -0
- package/dist/lib/css/property-descriptors/visibility.js +20 -0
- package/dist/lib/css/property-descriptors/webkit-line-clamp.js +26 -0
- package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js +10 -0
- package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js +16 -0
- package/dist/lib/css/property-descriptors/word-break.js +26 -0
- package/dist/lib/css/property-descriptors/writing-mode.js +28 -0
- package/dist/lib/css/property-descriptors/z-index.js +19 -0
- package/dist/lib/css/property-descriptors/zoom.js +18 -0
- package/dist/lib/css/syntax/parser.js +140 -0
- package/dist/lib/css/syntax/token-constants.js +214 -0
- package/dist/lib/css/syntax/token-singletons.js +36 -0
- package/dist/lib/css/syntax/token-types.js +10 -0
- package/dist/lib/css/syntax/tokenizer.js +502 -0
- package/dist/lib/css/type-descriptor.js +2 -0
- package/dist/lib/css/types/angle.js +80 -0
- package/dist/lib/css/types/color-math.js +25 -0
- package/dist/lib/css/types/color-spaces/a98.js +78 -0
- package/dist/lib/css/types/color-spaces/p3.js +86 -0
- package/dist/lib/css/types/color-spaces/pro-photo.js +83 -0
- package/dist/lib/css/types/color-spaces/rec2020.js +85 -0
- package/dist/lib/css/types/color-spaces/srgb.js +79 -0
- package/dist/lib/css/types/color-utilities.js +342 -0
- package/dist/lib/css/types/color.js +400 -0
- package/dist/lib/css/types/functions/-prefix-linear-gradient.js +32 -0
- package/dist/lib/css/types/functions/-prefix-radial-gradient.js +83 -0
- package/dist/lib/css/types/functions/-webkit-gradient.js +59 -0
- package/dist/lib/css/types/functions/counter.js +367 -0
- package/dist/lib/css/types/functions/gradient.js +163 -0
- package/dist/lib/css/types/functions/linear-gradient.js +27 -0
- package/dist/lib/css/types/functions/radial-gradient.js +90 -0
- package/dist/lib/css/types/functions/repeating-linear-gradient.js +9 -0
- package/dist/lib/css/types/image.js +62 -0
- package/dist/lib/css/types/index.js +2 -0
- package/dist/lib/css/types/length-percentage.js +197 -0
- package/dist/lib/css/types/length.js +5 -0
- package/dist/lib/css/types/safe-eval.js +80 -0
- package/dist/lib/css/types/time.js +17 -0
- package/dist/lib/dom/document-cloner.js +597 -0
- package/dist/lib/dom/dom-normalizer.js +115 -0
- package/dist/lib/dom/element-container.js +56 -0
- package/dist/lib/dom/elements/li-element-container.js +11 -0
- package/dist/lib/dom/elements/ol-element-container.js +12 -0
- package/dist/lib/dom/elements/select-element-container.js +12 -0
- package/dist/lib/dom/elements/textarea-element-container.js +11 -0
- package/dist/lib/dom/node-parser.js +112 -0
- package/dist/lib/dom/node-type-guards.js +81 -0
- package/dist/lib/dom/replaced-elements/canvas-element-container.js +13 -0
- package/dist/lib/dom/replaced-elements/iframe-element-container.js +38 -0
- package/dist/lib/dom/replaced-elements/image-element-container.js +14 -0
- package/dist/lib/dom/replaced-elements/index.js +2 -0
- package/dist/lib/dom/replaced-elements/input-element-container.js +89 -0
- package/dist/lib/dom/replaced-elements/svg-element-container.js +19 -0
- package/dist/lib/dom/slot-cloner.js +176 -0
- package/dist/lib/dom/text-container.js +35 -0
- package/dist/lib/index.js +49 -0
- package/dist/lib/options.js +2 -0
- package/dist/lib/render/background.js +188 -0
- package/dist/lib/render/bezier-curve.js +34 -0
- package/dist/lib/render/border.js +104 -0
- package/dist/lib/render/bound-curves.js +188 -0
- package/dist/lib/render/box-sizing.js +20 -0
- package/dist/lib/render/canvas/background-renderer.js +327 -0
- package/dist/lib/render/canvas/border-image-renderer.js +153 -0
- package/dist/lib/render/canvas/border-renderer.js +184 -0
- package/dist/lib/render/canvas/canvas-path.js +25 -0
- package/dist/lib/render/canvas/canvas-renderer.js +312 -0
- package/dist/lib/render/canvas/content-renderer.js +204 -0
- package/dist/lib/render/canvas/effects-renderer.js +171 -0
- package/dist/lib/render/canvas/font-utils.js +29 -0
- package/dist/lib/render/canvas/foreignobject-renderer.js +38 -0
- package/dist/lib/render/canvas/text/text-decoration-renderer.js +99 -0
- package/dist/lib/render/canvas/text-renderer.js +485 -0
- package/dist/lib/render/effects.js +231 -0
- package/dist/lib/render/font-metrics.js +53 -0
- package/dist/lib/render/object-fit.js +91 -0
- package/dist/lib/render/path.js +26 -0
- package/dist/lib/render/renderer-interface.js +2 -0
- package/dist/lib/render/stacking-context.js +340 -0
- package/dist/lib/render/vector.js +16 -0
- package/dist/types/config.d.ts +44 -0
- package/dist/types/core/abort-helper.d.ts +12 -0
- package/dist/types/core/background-parser.d.ts +16 -0
- package/dist/types/core/bitwise.d.ts +1 -0
- package/dist/types/core/cache-storage.d.ts +68 -0
- package/dist/types/core/config-assembler.d.ts +28 -0
- package/dist/types/core/constants.d.ts +22 -0
- package/dist/types/core/context.d.ts +22 -0
- package/dist/types/core/debugger.d.ts +8 -0
- package/dist/types/core/features.d.ts +12 -0
- package/dist/types/core/logger.d.ts +18 -0
- package/dist/types/core/lru-map.d.ts +37 -0
- package/dist/types/core/origin-checker.d.ts +33 -0
- package/dist/types/core/performance-monitor.d.ts +120 -0
- package/dist/types/core/render-element.d.ts +3 -0
- package/dist/types/core/util.d.ts +1 -0
- package/dist/types/core/validator.d.ts +130 -0
- package/dist/types/css/grouped/background-styles.d.ts +16 -0
- package/dist/types/css/grouped/border-styles.d.ts +31 -0
- package/dist/types/css/grouped/font-styles.d.ts +35 -0
- package/dist/types/css/grouped/layout-styles.d.ts +46 -0
- package/dist/types/css/index.d.ts +185 -0
- package/dist/types/css/layout/bounds.d.ts +14 -0
- package/dist/types/css/layout/text.d.ts +10 -0
- package/dist/types/css/property-descriptor.d.ts +40 -0
- package/dist/types/css/property-descriptors/background-blend-mode.d.ts +23 -0
- package/dist/types/css/property-descriptors/background-clip.d.ts +8 -0
- package/dist/types/css/property-descriptors/background-color.d.ts +2 -0
- package/dist/types/css/property-descriptors/background-image.d.ts +3 -0
- package/dist/types/css/property-descriptors/background-origin.d.ts +8 -0
- package/dist/types/css/property-descriptors/background-position.d.ts +5 -0
- package/dist/types/css/property-descriptors/background-repeat.d.ts +9 -0
- package/dist/types/css/property-descriptors/background-size.d.ts +11 -0
- package/dist/types/css/property-descriptors/border-color.d.ts +5 -0
- package/dist/types/css/property-descriptors/border-image-repeat.d.ts +12 -0
- package/dist/types/css/property-descriptors/border-image-slice.d.ts +10 -0
- package/dist/types/css/property-descriptors/border-image-source.d.ts +4 -0
- package/dist/types/css/property-descriptors/border-radius.d.ts +7 -0
- package/dist/types/css/property-descriptors/border-style.d.ts +12 -0
- package/dist/types/css/property-descriptors/border-width.d.ts +5 -0
- package/dist/types/css/property-descriptors/box-decoration-break.d.ts +6 -0
- package/dist/types/css/property-descriptors/box-shadow.d.ts +14 -0
- package/dist/types/css/property-descriptors/clip-path.d.ts +62 -0
- package/dist/types/css/property-descriptors/color.d.ts +2 -0
- package/dist/types/css/property-descriptors/content.d.ts +4 -0
- package/dist/types/css/property-descriptors/counter-increment.d.ts +10 -0
- package/dist/types/css/property-descriptors/counter-reset.d.ts +7 -0
- package/dist/types/css/property-descriptors/direction.d.ts +6 -0
- package/dist/types/css/property-descriptors/display.d.ts +35 -0
- package/dist/types/css/property-descriptors/duration.d.ts +2 -0
- package/dist/types/css/property-descriptors/filter.d.ts +3 -0
- package/dist/types/css/property-descriptors/float.d.ts +9 -0
- package/dist/types/css/property-descriptors/font-family.d.ts +4 -0
- package/dist/types/css/property-descriptors/font-size.d.ts +2 -0
- package/dist/types/css/property-descriptors/font-style.d.ts +7 -0
- package/dist/types/css/property-descriptors/font-variant-ligatures.d.ts +14 -0
- package/dist/types/css/property-descriptors/font-variant.d.ts +2 -0
- package/dist/types/css/property-descriptors/font-weight.d.ts +2 -0
- package/dist/types/css/property-descriptors/image-rendering.d.ts +8 -0
- package/dist/types/css/property-descriptors/letter-spacing.d.ts +2 -0
- package/dist/types/css/property-descriptors/line-break.d.ts +6 -0
- package/dist/types/css/property-descriptors/line-height.d.ts +4 -0
- package/dist/types/css/property-descriptors/list-style-image.d.ts +3 -0
- package/dist/types/css/property-descriptors/list-style-position.d.ts +6 -0
- package/dist/types/css/property-descriptors/list-style-type.d.ts +58 -0
- package/dist/types/css/property-descriptors/margin.d.ts +5 -0
- package/dist/types/css/property-descriptors/mix-blend-mode.d.ts +21 -0
- package/dist/types/css/property-descriptors/object-fit.d.ts +10 -0
- package/dist/types/css/property-descriptors/object-position.d.ts +4 -0
- package/dist/types/css/property-descriptors/opacity.d.ts +2 -0
- package/dist/types/css/property-descriptors/overflow-wrap.d.ts +6 -0
- package/dist/types/css/property-descriptors/overflow.d.ts +9 -0
- package/dist/types/css/property-descriptors/padding.d.ts +5 -0
- package/dist/types/css/property-descriptors/paint-order.d.ts +8 -0
- package/dist/types/css/property-descriptors/position.d.ts +9 -0
- package/dist/types/css/property-descriptors/quotes.d.ts +8 -0
- package/dist/types/css/property-descriptors/rotate.d.ts +3 -0
- package/dist/types/css/property-descriptors/text-align.d.ts +7 -0
- package/dist/types/css/property-descriptors/text-decoration-color.d.ts +2 -0
- package/dist/types/css/property-descriptors/text-decoration-line.d.ts +10 -0
- package/dist/types/css/property-descriptors/text-decoration-style.d.ts +9 -0
- package/dist/types/css/property-descriptors/text-decoration-thickness.d.ts +3 -0
- package/dist/types/css/property-descriptors/text-overflow.d.ts +6 -0
- package/dist/types/css/property-descriptors/text-shadow.d.ts +12 -0
- package/dist/types/css/property-descriptors/text-transform.d.ts +8 -0
- package/dist/types/css/property-descriptors/text-underline-offset.d.ts +3 -0
- package/dist/types/css/property-descriptors/transform-origin.d.ts +4 -0
- package/dist/types/css/property-descriptors/transform.d.ts +4 -0
- package/dist/types/css/property-descriptors/visibility.d.ts +7 -0
- package/dist/types/css/property-descriptors/webkit-line-clamp.d.ts +7 -0
- package/dist/types/css/property-descriptors/webkit-text-stroke-color.d.ts +2 -0
- package/dist/types/css/property-descriptors/webkit-text-stroke-width.d.ts +2 -0
- package/dist/types/css/property-descriptors/word-break.d.ts +7 -0
- package/dist/types/css/property-descriptors/writing-mode.d.ts +11 -0
- package/dist/types/css/property-descriptors/z-index.d.ts +7 -0
- package/dist/types/css/property-descriptors/zoom.d.ts +3 -0
- package/dist/types/css/syntax/parser.d.ts +34 -0
- package/dist/types/css/syntax/token-constants.d.ts +74 -0
- package/dist/types/css/syntax/token-singletons.d.ts +22 -0
- package/dist/types/css/syntax/token-types.d.ts +72 -0
- package/dist/types/css/syntax/tokenizer.d.ts +32 -0
- package/dist/types/css/type-descriptor.d.ts +6 -0
- package/dist/types/css/types/angle.d.ts +7 -0
- package/dist/types/css/types/color-math.d.ts +12 -0
- package/dist/types/css/types/color-spaces/a98.d.ts +39 -0
- package/dist/types/css/types/color-spaces/p3.d.ts +45 -0
- package/dist/types/css/types/color-spaces/pro-photo.d.ts +45 -0
- package/dist/types/css/types/color-spaces/rec2020.d.ts +45 -0
- package/dist/types/css/types/color-spaces/srgb.d.ts +38 -0
- package/dist/types/css/types/color-utilities.d.ts +107 -0
- package/dist/types/css/types/color.d.ts +8 -0
- package/dist/types/css/types/functions/-prefix-linear-gradient.d.ts +4 -0
- package/dist/types/css/types/functions/-prefix-radial-gradient.d.ts +4 -0
- package/dist/types/css/types/functions/-webkit-gradient.d.ts +4 -0
- package/dist/types/css/types/functions/counter.d.ts +10 -0
- package/dist/types/css/types/functions/gradient.d.ts +7 -0
- package/dist/types/css/types/functions/linear-gradient.d.ts +4 -0
- package/dist/types/css/types/functions/radial-gradient.d.ts +12 -0
- package/dist/types/css/types/functions/repeating-linear-gradient.d.ts +4 -0
- package/dist/types/css/types/image.d.ts +56 -0
- package/dist/types/css/types/index.d.ts +1 -0
- package/dist/types/css/types/length-percentage.d.ts +62 -0
- package/dist/types/css/types/length.d.ts +4 -0
- package/dist/types/css/types/safe-eval.d.ts +8 -0
- package/dist/types/css/types/time.d.ts +2 -0
- package/dist/types/dom/document-cloner.d.ts +57 -0
- package/dist/types/dom/dom-normalizer.d.ts +62 -0
- package/dist/types/dom/element-container.d.ts +31 -0
- package/dist/types/dom/elements/li-element-container.d.ts +6 -0
- package/dist/types/dom/elements/ol-element-container.d.ts +7 -0
- package/dist/types/dom/elements/select-element-container.d.ts +6 -0
- package/dist/types/dom/elements/textarea-element-container.d.ts +6 -0
- package/dist/types/dom/node-parser.d.ts +3 -0
- package/dist/types/dom/node-type-guards.d.ts +32 -0
- package/dist/types/dom/replaced-elements/canvas-element-container.d.ts +8 -0
- package/dist/types/dom/replaced-elements/iframe-element-container.d.ts +14 -0
- package/dist/types/dom/replaced-elements/image-element-container.d.ts +8 -0
- package/dist/types/dom/replaced-elements/index.d.ts +4 -0
- package/dist/types/dom/replaced-elements/input-element-container.d.ts +14 -0
- package/dist/types/dom/replaced-elements/svg-element-container.d.ts +8 -0
- package/dist/types/dom/slot-cloner.d.ts +66 -0
- package/dist/types/dom/text-container.d.ts +8 -0
- package/dist/types/index.d.ts +36 -0
- package/dist/types/options.d.ts +62 -0
- package/dist/types/render/background.d.ts +16 -0
- package/dist/types/render/bezier-curve.d.ts +14 -0
- package/dist/types/render/border.d.ts +6 -0
- package/dist/types/render/bound-curves.d.ts +32 -0
- package/dist/types/render/box-sizing.d.ts +4 -0
- package/dist/types/render/canvas/background-renderer.d.ts +94 -0
- package/dist/types/render/canvas/border-image-renderer.d.ts +18 -0
- package/dist/types/render/canvas/border-renderer.d.ts +67 -0
- package/dist/types/render/canvas/canvas-path.d.ts +3 -0
- package/dist/types/render/canvas/canvas-renderer.d.ts +60 -0
- package/dist/types/render/canvas/content-renderer.d.ts +43 -0
- package/dist/types/render/canvas/effects-renderer.d.ts +90 -0
- package/dist/types/render/canvas/font-utils.d.ts +19 -0
- package/dist/types/render/canvas/foreignobject-renderer.d.ts +10 -0
- package/dist/types/render/canvas/text/text-decoration-renderer.d.ts +18 -0
- package/dist/types/render/canvas/text-renderer.d.ts +103 -0
- package/dist/types/render/effects.d.ts +112 -0
- package/dist/types/render/font-metrics.d.ts +11 -0
- package/dist/types/render/object-fit.d.ts +19 -0
- package/dist/types/render/path.d.ts +13 -0
- package/dist/types/render/renderer-interface.d.ts +28 -0
- package/dist/types/render/stacking-context.d.ts +49 -0
- package/dist/types/render/vector.d.ts +9 -0
- package/package.json +139 -4
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeDoctype = exports.copyCSSStyles = exports.DocumentCloner = void 0;
|
|
4
|
+
const node_type_guards_1 = require("./node-type-guards");
|
|
5
|
+
const parser_1 = require("../css/syntax/parser");
|
|
6
|
+
const counter_1 = require("../css/types/functions/counter");
|
|
7
|
+
const list_style_type_1 = require("../css/property-descriptors/list-style-type");
|
|
8
|
+
const index_1 = require("../css/index");
|
|
9
|
+
const quotes_1 = require("../css/property-descriptors/quotes");
|
|
10
|
+
const debugger_1 = require("../core/debugger");
|
|
11
|
+
const slot_cloner_1 = require("./slot-cloner");
|
|
12
|
+
/**
|
|
13
|
+
* Find the parent ShadowRoot of an element, if any
|
|
14
|
+
* @param element - The element to check
|
|
15
|
+
* @returns The parent ShadowRoot or null
|
|
16
|
+
*/
|
|
17
|
+
const findParentShadowRoot = (element) => {
|
|
18
|
+
let current = element;
|
|
19
|
+
while (current) {
|
|
20
|
+
// Check if we've reached a shadow root boundary
|
|
21
|
+
if (current.parentNode && current.parentNode.host) {
|
|
22
|
+
return current.parentNode;
|
|
23
|
+
}
|
|
24
|
+
// Use getRootNode to check if we're in a shadow root
|
|
25
|
+
const root = current.getRootNode();
|
|
26
|
+
if (root && root !== current.ownerDocument && root.host) {
|
|
27
|
+
return root;
|
|
28
|
+
}
|
|
29
|
+
current = current.parentNode;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
class DocumentCloner {
|
|
34
|
+
constructor(context, element, options) {
|
|
35
|
+
this.context = context;
|
|
36
|
+
this.options = options;
|
|
37
|
+
this.scrolledElements = [];
|
|
38
|
+
this.referenceElement = element;
|
|
39
|
+
this.counters = new counter_1.CounterState();
|
|
40
|
+
this.quoteDepth = 0;
|
|
41
|
+
this.slotCloner = new slot_cloner_1.SlotCloner((node, copyStyles) => this.cloneNode(node, copyStyles), { ignoreElements: options.ignoreElements, copyStyles: options.copyStyles ?? true }, context);
|
|
42
|
+
if (!element.ownerDocument) {
|
|
43
|
+
throw new Error('Cloned element does not have an owner document');
|
|
44
|
+
}
|
|
45
|
+
// Auto-detect Shadow Root if not explicitly provided
|
|
46
|
+
if (!this.options.iframeContainer) {
|
|
47
|
+
const shadowRoot = findParentShadowRoot(element);
|
|
48
|
+
if (shadowRoot) {
|
|
49
|
+
this.options.iframeContainer = shadowRoot;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
this.documentElement = this.cloneNode(element.ownerDocument.documentElement, false);
|
|
53
|
+
}
|
|
54
|
+
toIFrame(ownerDocument, windowSize) {
|
|
55
|
+
const iframe = createIFrameContainer(ownerDocument, windowSize, this.options.iframeContainer);
|
|
56
|
+
if (!iframe.contentWindow) {
|
|
57
|
+
throw new Error('Unable to find iframe window');
|
|
58
|
+
}
|
|
59
|
+
const scrollX = ownerDocument.defaultView.pageXOffset;
|
|
60
|
+
const scrollY = ownerDocument.defaultView.pageYOffset;
|
|
61
|
+
const cloneWindow = iframe.contentWindow;
|
|
62
|
+
const documentClone = cloneWindow.document;
|
|
63
|
+
/* Chrome doesn't detect relative background-images assigned in inline <style> sheets when fetched through getComputedStyle
|
|
64
|
+
if window url is about:blank, we can assign the url to current by writing onto the document
|
|
65
|
+
*/
|
|
66
|
+
const iframeLoad = iframeLoader(iframe).then(async () => {
|
|
67
|
+
this.scrolledElements.forEach(restoreNodeScroll);
|
|
68
|
+
if (cloneWindow) {
|
|
69
|
+
cloneWindow.scrollTo(windowSize.left, windowSize.top);
|
|
70
|
+
if (/AppleWebKit/g.test(navigator.userAgent) &&
|
|
71
|
+
(cloneWindow.scrollY !== windowSize.top || cloneWindow.scrollX !== windowSize.left)) {
|
|
72
|
+
this.context.logger.warn('Unable to restore scroll position for cloned document');
|
|
73
|
+
this.context.windowBounds = this.context.windowBounds.add(cloneWindow.scrollX - windowSize.left, cloneWindow.scrollY - windowSize.top, 0, 0);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const onclone = this.options.onclone;
|
|
77
|
+
const referenceElement = this.clonedReferenceElement;
|
|
78
|
+
if (typeof referenceElement === 'undefined') {
|
|
79
|
+
throw new Error(`Error finding the ${this.referenceElement.nodeName} in the cloned document`);
|
|
80
|
+
}
|
|
81
|
+
if (documentClone.fonts && documentClone.fonts.ready) {
|
|
82
|
+
await documentClone.fonts.ready;
|
|
83
|
+
}
|
|
84
|
+
if (/(AppleWebKit)/g.test(navigator.userAgent)) {
|
|
85
|
+
await imagesReady(documentClone);
|
|
86
|
+
}
|
|
87
|
+
if (typeof onclone === 'function') {
|
|
88
|
+
return Promise.resolve()
|
|
89
|
+
.then(() => onclone(documentClone, referenceElement))
|
|
90
|
+
.then(() => iframe);
|
|
91
|
+
}
|
|
92
|
+
return iframe;
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* The base URI used for resolving relative URLs (e.g. background-image) in the clone.
|
|
96
|
+
* Must come from the source document: the iframe document is about:blank, so
|
|
97
|
+
* documentClone.baseURI would break getComputedStyle() for relative background URLs.
|
|
98
|
+
*/
|
|
99
|
+
const baseUri = ownerDocument.baseURI;
|
|
100
|
+
documentClone.open();
|
|
101
|
+
// rawHTML is always a static, internally-generated string:
|
|
102
|
+
// serializeDoctype(document.doctype) + '<html></html>'
|
|
103
|
+
// No user-controlled input — safe for document.write in the sandbox iframe.
|
|
104
|
+
const rawHTML = (0, exports.serializeDoctype)(document.doctype) + '<html></html>';
|
|
105
|
+
try {
|
|
106
|
+
const ownerWindow = this.referenceElement.ownerDocument?.defaultView;
|
|
107
|
+
const trustedTypesFactory = ownerWindow && ownerWindow.trustedTypes;
|
|
108
|
+
let policy = trustedTypesFactory?.getPolicy?.('html2canvas-pro');
|
|
109
|
+
if (!policy && trustedTypesFactory) {
|
|
110
|
+
policy = trustedTypesFactory.createPolicy('html2canvas-pro', {
|
|
111
|
+
createHTML: (s) => s
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// Prefer Trusted Types when available; fallback is the same static HTML.
|
|
115
|
+
const html = policy ? policy.createHTML(rawHTML) : rawHTML;
|
|
116
|
+
// CodeQL:no - rawHTML is a static internal string, never user-controlled
|
|
117
|
+
documentClone.write(html);
|
|
118
|
+
}
|
|
119
|
+
catch (_e) {
|
|
120
|
+
// CodeQL:no - rawHTML is a static internal string, never user-controlled
|
|
121
|
+
documentClone.write(rawHTML);
|
|
122
|
+
}
|
|
123
|
+
// Chrome scrolls the parent document for some reason after the write to the cloned window???
|
|
124
|
+
restoreOwnerScroll(this.referenceElement.ownerDocument, scrollX, scrollY);
|
|
125
|
+
/**
|
|
126
|
+
* IMPORTANT: documentClone.close() MUST be called BEFORE adoptNode().
|
|
127
|
+
*
|
|
128
|
+
* In Chrome, calling adoptNode() while the document is still "open"
|
|
129
|
+
* (between document.open() and document.close()) causes CSS rules with
|
|
130
|
+
* uppercase characters in class names (e.g. ".MyClass") to not match
|
|
131
|
+
* correctly. Chrome's CSS engine only enters a fully-resolved matching
|
|
132
|
+
* mode once the document is closed.
|
|
133
|
+
*
|
|
134
|
+
* Correct order: open() → write() → close() → adoptNode() → replaceChild()
|
|
135
|
+
*
|
|
136
|
+
* Timing: close() queues the iframe 'load' event; because JS is single-threaded,
|
|
137
|
+
* the synchronous adoptNode() and replaceChild() below complete before that
|
|
138
|
+
* event is dispatched. iframeLoader's setInterval will therefore see the body
|
|
139
|
+
* already populated on its first tick.
|
|
140
|
+
*/
|
|
141
|
+
documentClone.close();
|
|
142
|
+
const adoptedNode = documentClone.adoptNode(this.documentElement);
|
|
143
|
+
addBase(adoptedNode, baseUri);
|
|
144
|
+
documentClone.replaceChild(adoptedNode, documentClone.documentElement);
|
|
145
|
+
return iframeLoad;
|
|
146
|
+
}
|
|
147
|
+
createElementClone(node) {
|
|
148
|
+
if ((0, debugger_1.isDebugging)(node, 2 /* DebuggerType.CLONE */)) {
|
|
149
|
+
debugger;
|
|
150
|
+
}
|
|
151
|
+
if ((0, node_type_guards_1.isCanvasElement)(node)) {
|
|
152
|
+
return this.createCanvasClone(node);
|
|
153
|
+
}
|
|
154
|
+
if ((0, node_type_guards_1.isVideoElement)(node)) {
|
|
155
|
+
return this.createVideoClone(node);
|
|
156
|
+
}
|
|
157
|
+
if ((0, node_type_guards_1.isStyleElement)(node)) {
|
|
158
|
+
return this.createStyleClone(node);
|
|
159
|
+
}
|
|
160
|
+
const clone = node.cloneNode(false);
|
|
161
|
+
if ((0, node_type_guards_1.isImageElement)(clone)) {
|
|
162
|
+
if ((0, node_type_guards_1.isImageElement)(node) && node.currentSrc && node.currentSrc !== node.src) {
|
|
163
|
+
clone.src = node.currentSrc;
|
|
164
|
+
clone.srcset = '';
|
|
165
|
+
}
|
|
166
|
+
if (clone.loading === 'lazy') {
|
|
167
|
+
clone.loading = 'eager';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if ((0, node_type_guards_1.isCustomElement)(clone) && !(0, node_type_guards_1.isSVGElementNode)(clone)) {
|
|
171
|
+
return this.createCustomElementClone(clone);
|
|
172
|
+
}
|
|
173
|
+
return clone;
|
|
174
|
+
}
|
|
175
|
+
createCustomElementClone(node) {
|
|
176
|
+
const clone = document.createElement('div');
|
|
177
|
+
clone.className = node.className;
|
|
178
|
+
(0, exports.copyCSSStyles)(node.style, clone);
|
|
179
|
+
// Clone shadow DOM if it exists
|
|
180
|
+
// Fix for Issue #108: This is critical for Web Components with slots to work correctly
|
|
181
|
+
if (node.shadowRoot) {
|
|
182
|
+
try {
|
|
183
|
+
clone.attachShadow({ mode: 'open' });
|
|
184
|
+
// The actual shadow DOM content will be cloned in cloneChildNodes
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
// Some elements cannot have shadow roots attached
|
|
188
|
+
// This can happen if the element doesn't support shadow DOM
|
|
189
|
+
this.context.logger.error('Failed to attach shadow root to custom element clone:', e);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return clone;
|
|
193
|
+
}
|
|
194
|
+
createStyleClone(node) {
|
|
195
|
+
try {
|
|
196
|
+
const sheet = node.sheet;
|
|
197
|
+
if (sheet && sheet.cssRules) {
|
|
198
|
+
const css = [].slice.call(sheet.cssRules, 0).reduce((css, rule) => {
|
|
199
|
+
if (rule && typeof rule.cssText === 'string') {
|
|
200
|
+
return css + rule.cssText;
|
|
201
|
+
}
|
|
202
|
+
return css;
|
|
203
|
+
}, '');
|
|
204
|
+
const style = node.cloneNode(false);
|
|
205
|
+
style.textContent = css;
|
|
206
|
+
if (this.options.cspNonce) {
|
|
207
|
+
style.nonce = this.options.cspNonce;
|
|
208
|
+
}
|
|
209
|
+
return style;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch (e) {
|
|
213
|
+
// accessing node.sheet.cssRules throws a DOMException
|
|
214
|
+
this.context.logger.error('Unable to access cssRules property', e);
|
|
215
|
+
if (e.name !== 'SecurityError') {
|
|
216
|
+
throw e;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const cloned = node.cloneNode(false);
|
|
220
|
+
if (this.options.cspNonce) {
|
|
221
|
+
cloned.nonce = this.options.cspNonce;
|
|
222
|
+
}
|
|
223
|
+
return cloned;
|
|
224
|
+
}
|
|
225
|
+
createCanvasClone(canvas) {
|
|
226
|
+
if (this.options.inlineImages && canvas.ownerDocument) {
|
|
227
|
+
const img = canvas.ownerDocument.createElement('img');
|
|
228
|
+
try {
|
|
229
|
+
img.src = canvas.toDataURL();
|
|
230
|
+
return img;
|
|
231
|
+
}
|
|
232
|
+
catch (e) {
|
|
233
|
+
this.context.logger.info(`Unable to inline canvas contents, canvas is tainted`, canvas);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const clonedCanvas = canvas.cloneNode(false);
|
|
237
|
+
try {
|
|
238
|
+
clonedCanvas.width = canvas.width;
|
|
239
|
+
clonedCanvas.height = canvas.height;
|
|
240
|
+
const ctx = canvas.getContext('2d');
|
|
241
|
+
const clonedCtx = clonedCanvas.getContext('2d', { willReadFrequently: true });
|
|
242
|
+
if (clonedCtx) {
|
|
243
|
+
if (!this.options.allowTaint && ctx) {
|
|
244
|
+
clonedCtx.putImageData(ctx.getImageData(0, 0, canvas.width, canvas.height), 0, 0);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const gl = canvas.getContext('webgl2') ?? canvas.getContext('webgl');
|
|
248
|
+
if (gl) {
|
|
249
|
+
const attribs = gl.getContextAttributes();
|
|
250
|
+
if (attribs?.preserveDrawingBuffer === false) {
|
|
251
|
+
this.context.logger.warn('Unable to clone WebGL context as it has preserveDrawingBuffer=false', canvas);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
clonedCtx.drawImage(canvas, 0, 0);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return clonedCanvas;
|
|
258
|
+
}
|
|
259
|
+
catch (e) {
|
|
260
|
+
this.context.logger.info(`Unable to clone canvas as it is tainted`, canvas);
|
|
261
|
+
}
|
|
262
|
+
return clonedCanvas;
|
|
263
|
+
}
|
|
264
|
+
createVideoClone(video) {
|
|
265
|
+
const canvas = video.ownerDocument.createElement('canvas');
|
|
266
|
+
canvas.width = video.offsetWidth;
|
|
267
|
+
canvas.height = video.offsetHeight;
|
|
268
|
+
const ctx = canvas.getContext('2d');
|
|
269
|
+
try {
|
|
270
|
+
if (ctx) {
|
|
271
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
272
|
+
if (!this.options.allowTaint) {
|
|
273
|
+
ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return canvas;
|
|
277
|
+
}
|
|
278
|
+
catch (e) {
|
|
279
|
+
this.context.logger.info(`Unable to clone video as it is tainted`, video);
|
|
280
|
+
}
|
|
281
|
+
const blankCanvas = video.ownerDocument.createElement('canvas');
|
|
282
|
+
blankCanvas.width = video.offsetWidth;
|
|
283
|
+
blankCanvas.height = video.offsetHeight;
|
|
284
|
+
return blankCanvas;
|
|
285
|
+
}
|
|
286
|
+
appendChildNode(clone, child, copyStyles) {
|
|
287
|
+
this.slotCloner.appendChildNode(clone, child, copyStyles);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Clone child nodes from source element to clone element.
|
|
291
|
+
* Delegates to SlotCloner which handles shadow DOM, slots, and light DOM.
|
|
292
|
+
*/
|
|
293
|
+
cloneChildNodes(node, clone, copyStyles) {
|
|
294
|
+
this.slotCloner.cloneChildNodes(node, clone, copyStyles);
|
|
295
|
+
}
|
|
296
|
+
cloneNode(node, copyStyles) {
|
|
297
|
+
if ((0, node_type_guards_1.isTextNode)(node)) {
|
|
298
|
+
return document.createTextNode(node.data);
|
|
299
|
+
}
|
|
300
|
+
if (!node.ownerDocument) {
|
|
301
|
+
return node.cloneNode(false);
|
|
302
|
+
}
|
|
303
|
+
const window = node.ownerDocument.defaultView;
|
|
304
|
+
if (window && (0, node_type_guards_1.isElementNode)(node) && ((0, node_type_guards_1.isHTMLElementNode)(node) || (0, node_type_guards_1.isSVGElementNode)(node))) {
|
|
305
|
+
const clone = this.createElementClone(node);
|
|
306
|
+
clone.style.transitionProperty = 'none';
|
|
307
|
+
const style = window.getComputedStyle(node);
|
|
308
|
+
// Per CSS spec, replaced elements, void elements, and SVG elements
|
|
309
|
+
// cannot have ::before / ::after pseudo-elements — skip these queries.
|
|
310
|
+
const checkPseudoElements = (0, node_type_guards_1.canHavePseudoElements)(node);
|
|
311
|
+
if (this.referenceElement === node && (0, node_type_guards_1.isHTMLElementNode)(clone)) {
|
|
312
|
+
this.clonedReferenceElement = clone;
|
|
313
|
+
}
|
|
314
|
+
if ((0, node_type_guards_1.isBodyElement)(clone)) {
|
|
315
|
+
createPseudoHideStyles(clone, this.options.cspNonce);
|
|
316
|
+
}
|
|
317
|
+
const counters = this.counters.parse(new index_1.CSSParsedCounterDeclaration(this.context, style));
|
|
318
|
+
if (checkPseudoElements) {
|
|
319
|
+
const styleBefore = window.getComputedStyle(node, ':before');
|
|
320
|
+
const before = this.resolvePseudoContent(node, clone, styleBefore, PseudoElementType.BEFORE);
|
|
321
|
+
if (before) {
|
|
322
|
+
clone.insertBefore(before, clone.firstChild);
|
|
323
|
+
}
|
|
324
|
+
const styleAfter = window.getComputedStyle(node, ':after');
|
|
325
|
+
const after = this.resolvePseudoContent(node, clone, styleAfter, PseudoElementType.AFTER);
|
|
326
|
+
if (after) {
|
|
327
|
+
clone.appendChild(after);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if ((0, node_type_guards_1.isCustomElement)(node)) {
|
|
331
|
+
copyStyles = true;
|
|
332
|
+
}
|
|
333
|
+
if (!(0, node_type_guards_1.isVideoElement)(node)) {
|
|
334
|
+
this.cloneChildNodes(node, clone, copyStyles);
|
|
335
|
+
}
|
|
336
|
+
this.counters.pop(counters);
|
|
337
|
+
if ((style && (this.options.copyStyles || (0, node_type_guards_1.isSVGElementNode)(node)) && !(0, node_type_guards_1.isIFrameElement)(node)) ||
|
|
338
|
+
copyStyles) {
|
|
339
|
+
(0, exports.copyCSSStyles)(style, clone);
|
|
340
|
+
}
|
|
341
|
+
if (node.scrollTop !== 0 || node.scrollLeft !== 0) {
|
|
342
|
+
this.scrolledElements.push([clone, node.scrollLeft, node.scrollTop]);
|
|
343
|
+
}
|
|
344
|
+
if (((0, node_type_guards_1.isTextareaElement)(node) || (0, node_type_guards_1.isSelectElement)(node)) &&
|
|
345
|
+
((0, node_type_guards_1.isTextareaElement)(clone) || (0, node_type_guards_1.isSelectElement)(clone))) {
|
|
346
|
+
clone.value = node.value;
|
|
347
|
+
}
|
|
348
|
+
return clone;
|
|
349
|
+
}
|
|
350
|
+
return node.cloneNode(false);
|
|
351
|
+
}
|
|
352
|
+
resolvePseudoContent(node, clone, style, pseudoElt) {
|
|
353
|
+
if (!style) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const value = style.content;
|
|
357
|
+
const document = clone.ownerDocument;
|
|
358
|
+
if (!document || !value || value === 'none' || value === '-moz-alt-content' || style.display === 'none') {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
this.counters.parse(new index_1.CSSParsedCounterDeclaration(this.context, style));
|
|
362
|
+
const declaration = new index_1.CSSParsedPseudoDeclaration(this.context, style);
|
|
363
|
+
const anonymousReplacedElement = document.createElement('html2canvaspseudoelement');
|
|
364
|
+
(0, exports.copyCSSStyles)(style, anonymousReplacedElement);
|
|
365
|
+
declaration.content.forEach((token) => {
|
|
366
|
+
if (token.type === 0 /* TokenType.STRING_TOKEN */) {
|
|
367
|
+
anonymousReplacedElement.appendChild(document.createTextNode(token.value));
|
|
368
|
+
}
|
|
369
|
+
else if (token.type === 22 /* TokenType.URL_TOKEN */) {
|
|
370
|
+
const img = document.createElement('img');
|
|
371
|
+
img.src = token.value;
|
|
372
|
+
img.style.opacity = '1';
|
|
373
|
+
anonymousReplacedElement.appendChild(img);
|
|
374
|
+
}
|
|
375
|
+
else if (token.type === 18 /* TokenType.FUNCTION */) {
|
|
376
|
+
if (token.name === 'attr') {
|
|
377
|
+
const attr = token.values.filter(parser_1.isIdentToken);
|
|
378
|
+
if (attr.length) {
|
|
379
|
+
anonymousReplacedElement.appendChild(document.createTextNode(node.getAttribute(attr[0].value) || ''));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else if (token.name === 'counter') {
|
|
383
|
+
const [counter, counterStyle] = token.values.filter(parser_1.nonFunctionArgSeparator);
|
|
384
|
+
if (counter && (0, parser_1.isIdentToken)(counter)) {
|
|
385
|
+
const counterState = this.counters.getCounterValue(counter.value);
|
|
386
|
+
const counterType = counterStyle && (0, parser_1.isIdentToken)(counterStyle)
|
|
387
|
+
? list_style_type_1.listStyleType.parse(this.context, counterStyle.value)
|
|
388
|
+
: 3 /* LIST_STYLE_TYPE.DECIMAL */;
|
|
389
|
+
anonymousReplacedElement.appendChild(document.createTextNode((0, counter_1.createCounterText)(counterState, counterType, false)));
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
else if (token.name === 'counters') {
|
|
393
|
+
const [counter, delim, counterStyle] = token.values.filter(parser_1.nonFunctionArgSeparator);
|
|
394
|
+
if (counter && (0, parser_1.isIdentToken)(counter)) {
|
|
395
|
+
const counterStates = this.counters.getCounterValues(counter.value);
|
|
396
|
+
const counterType = counterStyle && (0, parser_1.isIdentToken)(counterStyle)
|
|
397
|
+
? list_style_type_1.listStyleType.parse(this.context, counterStyle.value)
|
|
398
|
+
: 3 /* LIST_STYLE_TYPE.DECIMAL */;
|
|
399
|
+
const separator = delim && delim.type === 0 /* TokenType.STRING_TOKEN */ ? delim.value : '';
|
|
400
|
+
const text = counterStates
|
|
401
|
+
.map((value) => (0, counter_1.createCounterText)(value, counterType, false))
|
|
402
|
+
.join(separator);
|
|
403
|
+
anonymousReplacedElement.appendChild(document.createTextNode(text));
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
else if (token.type === 20 /* TokenType.IDENT_TOKEN */) {
|
|
408
|
+
switch (token.value) {
|
|
409
|
+
case 'open-quote':
|
|
410
|
+
anonymousReplacedElement.appendChild(document.createTextNode((0, quotes_1.getQuote)(declaration.quotes, this.quoteDepth++, true)));
|
|
411
|
+
break;
|
|
412
|
+
case 'close-quote':
|
|
413
|
+
anonymousReplacedElement.appendChild(document.createTextNode((0, quotes_1.getQuote)(declaration.quotes, --this.quoteDepth, false)));
|
|
414
|
+
break;
|
|
415
|
+
default:
|
|
416
|
+
// safari doesn't parse string tokens correctly because of lack of quotes
|
|
417
|
+
anonymousReplacedElement.appendChild(document.createTextNode(token.value));
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
anonymousReplacedElement.className = `${PSEUDO_HIDE_ELEMENT_CLASS_BEFORE} ${PSEUDO_HIDE_ELEMENT_CLASS_AFTER}`;
|
|
422
|
+
const newClassName = pseudoElt === PseudoElementType.BEFORE
|
|
423
|
+
? ` ${PSEUDO_HIDE_ELEMENT_CLASS_BEFORE}`
|
|
424
|
+
: ` ${PSEUDO_HIDE_ELEMENT_CLASS_AFTER}`;
|
|
425
|
+
if ((0, node_type_guards_1.isSVGElementNode)(clone)) {
|
|
426
|
+
clone.className.baseValue += newClassName;
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
clone.className += newClassName;
|
|
430
|
+
}
|
|
431
|
+
return anonymousReplacedElement;
|
|
432
|
+
}
|
|
433
|
+
static destroy(container) {
|
|
434
|
+
if (container.parentNode) {
|
|
435
|
+
container.parentNode.removeChild(container);
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
exports.DocumentCloner = DocumentCloner;
|
|
442
|
+
var PseudoElementType;
|
|
443
|
+
(function (PseudoElementType) {
|
|
444
|
+
PseudoElementType[PseudoElementType["BEFORE"] = 0] = "BEFORE";
|
|
445
|
+
PseudoElementType[PseudoElementType["AFTER"] = 1] = "AFTER";
|
|
446
|
+
})(PseudoElementType || (PseudoElementType = {}));
|
|
447
|
+
const createIFrameContainer = (ownerDocument, bounds, customContainer) => {
|
|
448
|
+
const cloneIframeContainer = ownerDocument.createElement('iframe');
|
|
449
|
+
cloneIframeContainer.className = 'html2canvas-container';
|
|
450
|
+
cloneIframeContainer.style.visibility = 'hidden';
|
|
451
|
+
cloneIframeContainer.style.position = 'fixed';
|
|
452
|
+
cloneIframeContainer.style.left = '-10000px';
|
|
453
|
+
cloneIframeContainer.style.top = '0px';
|
|
454
|
+
cloneIframeContainer.style.border = '0';
|
|
455
|
+
cloneIframeContainer.width = bounds.width.toString();
|
|
456
|
+
cloneIframeContainer.height = bounds.height.toString();
|
|
457
|
+
cloneIframeContainer.scrolling = 'no'; // ios won't scroll without it
|
|
458
|
+
cloneIframeContainer.setAttribute(slot_cloner_1.IGNORE_ATTRIBUTE, 'true');
|
|
459
|
+
// Use custom container if provided, otherwise use body
|
|
460
|
+
const container = customContainer || ownerDocument.body;
|
|
461
|
+
container.appendChild(cloneIframeContainer);
|
|
462
|
+
return cloneIframeContainer;
|
|
463
|
+
};
|
|
464
|
+
const imageReady = (img) => {
|
|
465
|
+
return new Promise((resolve) => {
|
|
466
|
+
if (img.complete) {
|
|
467
|
+
resolve();
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (!img.src) {
|
|
471
|
+
resolve();
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
img.onload = resolve;
|
|
475
|
+
img.onerror = resolve;
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
const imagesReady = (document) => {
|
|
479
|
+
return Promise.all([].slice.call(document.images, 0).map(imageReady));
|
|
480
|
+
};
|
|
481
|
+
const iframeLoader = (iframe) => {
|
|
482
|
+
return new Promise((resolve, reject) => {
|
|
483
|
+
const cloneWindow = iframe.contentWindow;
|
|
484
|
+
if (!cloneWindow) {
|
|
485
|
+
return reject(`No window assigned for iframe`);
|
|
486
|
+
}
|
|
487
|
+
const documentClone = cloneWindow.document;
|
|
488
|
+
cloneWindow.onload = iframe.onload = () => {
|
|
489
|
+
cloneWindow.onload = iframe.onload = null;
|
|
490
|
+
const MAX_POLL_ATTEMPTS = 600; // 30 seconds at 50ms intervals
|
|
491
|
+
let attempts = 0;
|
|
492
|
+
const interval = setInterval(() => {
|
|
493
|
+
attempts++;
|
|
494
|
+
if (documentClone.body.childNodes.length > 0 && documentClone.readyState === 'complete') {
|
|
495
|
+
clearInterval(interval);
|
|
496
|
+
resolve(iframe);
|
|
497
|
+
}
|
|
498
|
+
else if (attempts >= MAX_POLL_ATTEMPTS) {
|
|
499
|
+
clearInterval(interval);
|
|
500
|
+
resolve(iframe); // resolve anyway to avoid hanging
|
|
501
|
+
}
|
|
502
|
+
}, 50);
|
|
503
|
+
};
|
|
504
|
+
});
|
|
505
|
+
};
|
|
506
|
+
const ignoredStyleProperties = [
|
|
507
|
+
'all', // #2476
|
|
508
|
+
'd', // #2483
|
|
509
|
+
'content' // Safari shows pseudoelements if content is set
|
|
510
|
+
];
|
|
511
|
+
const copyCSSStyles = (style, target) => {
|
|
512
|
+
const parts = [];
|
|
513
|
+
for (let i = style.length - 1; i >= 0; i--) {
|
|
514
|
+
const property = style.item(i);
|
|
515
|
+
// fix: Chrome_138 ignore custom properties
|
|
516
|
+
if (ignoredStyleProperties.indexOf(property) === -1 && !property.startsWith('--')) {
|
|
517
|
+
const value = style.getPropertyValue(property);
|
|
518
|
+
if (value) {
|
|
519
|
+
const priority = style.getPropertyPriority(property);
|
|
520
|
+
parts.push(priority ? `${property}:${value} !${priority}` : `${property}:${value}`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (parts.length > 0) {
|
|
525
|
+
target.style.cssText = parts.join(';') + ';';
|
|
526
|
+
}
|
|
527
|
+
return target;
|
|
528
|
+
};
|
|
529
|
+
exports.copyCSSStyles = copyCSSStyles;
|
|
530
|
+
/**
|
|
531
|
+
* Serialise a document type declaration to an HTML string.
|
|
532
|
+
* @internal – exported for testing only, not part of the public API.
|
|
533
|
+
*/
|
|
534
|
+
const serializeDoctype = (doctype) => {
|
|
535
|
+
let str = '';
|
|
536
|
+
if (doctype) {
|
|
537
|
+
str += '<!DOCTYPE ';
|
|
538
|
+
if (doctype.name) {
|
|
539
|
+
str += doctype.name;
|
|
540
|
+
}
|
|
541
|
+
if (doctype.internalSubset) {
|
|
542
|
+
str += ' ' + doctype.internalSubset.replace(/"/g, '"').replace(/>/g, '>');
|
|
543
|
+
}
|
|
544
|
+
if (doctype.publicId) {
|
|
545
|
+
str += ' PUBLIC "' + doctype.publicId.replace(/"/g, '"') + '"';
|
|
546
|
+
if (doctype.systemId) {
|
|
547
|
+
str += ' "' + doctype.systemId.replace(/"/g, '"') + '"';
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
else if (doctype.systemId) {
|
|
551
|
+
str += ' SYSTEM "' + doctype.systemId.replace(/"/g, '"') + '"';
|
|
552
|
+
}
|
|
553
|
+
str += '>';
|
|
554
|
+
}
|
|
555
|
+
return str;
|
|
556
|
+
};
|
|
557
|
+
exports.serializeDoctype = serializeDoctype;
|
|
558
|
+
const restoreOwnerScroll = (ownerDocument, x, y) => {
|
|
559
|
+
if (ownerDocument &&
|
|
560
|
+
ownerDocument.defaultView &&
|
|
561
|
+
(x !== ownerDocument.defaultView.pageXOffset || y !== ownerDocument.defaultView.pageYOffset)) {
|
|
562
|
+
ownerDocument.defaultView.scrollTo(x, y);
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
const restoreNodeScroll = ([element, x, y]) => {
|
|
566
|
+
element.scrollLeft = x;
|
|
567
|
+
element.scrollTop = y;
|
|
568
|
+
};
|
|
569
|
+
const PSEUDO_BEFORE = ':before';
|
|
570
|
+
const PSEUDO_AFTER = ':after';
|
|
571
|
+
const PSEUDO_HIDE_ELEMENT_CLASS_BEFORE = '___html2canvas___pseudoelement_before';
|
|
572
|
+
const PSEUDO_HIDE_ELEMENT_CLASS_AFTER = '___html2canvas___pseudoelement_after';
|
|
573
|
+
const PSEUDO_HIDE_ELEMENT_STYLE = `{
|
|
574
|
+
content: "" !important;
|
|
575
|
+
display: none !important;
|
|
576
|
+
}`;
|
|
577
|
+
const createPseudoHideStyles = (body, cspNonce) => {
|
|
578
|
+
createStyles(body, `.${PSEUDO_HIDE_ELEMENT_CLASS_BEFORE}${PSEUDO_BEFORE}${PSEUDO_HIDE_ELEMENT_STYLE}
|
|
579
|
+
.${PSEUDO_HIDE_ELEMENT_CLASS_AFTER}${PSEUDO_AFTER}${PSEUDO_HIDE_ELEMENT_STYLE}`, cspNonce);
|
|
580
|
+
};
|
|
581
|
+
const createStyles = (body, styles, cspNonce) => {
|
|
582
|
+
const document = body.ownerDocument;
|
|
583
|
+
if (document) {
|
|
584
|
+
const style = document.createElement('style');
|
|
585
|
+
style.textContent = styles;
|
|
586
|
+
if (cspNonce) {
|
|
587
|
+
style.nonce = cspNonce;
|
|
588
|
+
}
|
|
589
|
+
body.appendChild(style);
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
const addBase = (targetELement, baseUri) => {
|
|
593
|
+
const baseNode = targetELement.ownerDocument.createElement('base');
|
|
594
|
+
baseNode.href = baseUri;
|
|
595
|
+
const headEle = targetELement.getElementsByTagName('head').item(0);
|
|
596
|
+
headEle?.insertBefore(baseNode, headEle?.firstChild ?? null);
|
|
597
|
+
};
|