@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,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculatePaddingBoxPath = exports.calculateContentBoxPath = exports.calculateBorderBoxPath = exports.BoundCurves = void 0;
|
|
4
|
+
const length_percentage_1 = require("../css/types/length-percentage");
|
|
5
|
+
const vector_1 = require("./vector");
|
|
6
|
+
const bezier_curve_1 = require("./bezier-curve");
|
|
7
|
+
class BoundCurves {
|
|
8
|
+
constructor(element) {
|
|
9
|
+
const styles = element.styles;
|
|
10
|
+
const bounds = element.bounds;
|
|
11
|
+
let [tlh, tlv] = (0, length_percentage_1.getAbsoluteValueForTuple)(styles.borderTopLeftRadius, bounds.width, bounds.height);
|
|
12
|
+
let [trh, trv] = (0, length_percentage_1.getAbsoluteValueForTuple)(styles.borderTopRightRadius, bounds.width, bounds.height);
|
|
13
|
+
let [brh, brv] = (0, length_percentage_1.getAbsoluteValueForTuple)(styles.borderBottomRightRadius, bounds.width, bounds.height);
|
|
14
|
+
let [blh, blv] = (0, length_percentage_1.getAbsoluteValueForTuple)(styles.borderBottomLeftRadius, bounds.width, bounds.height);
|
|
15
|
+
const factors = [];
|
|
16
|
+
factors.push((tlh + trh) / bounds.width);
|
|
17
|
+
factors.push((blh + brh) / bounds.width);
|
|
18
|
+
factors.push((tlv + blv) / bounds.height);
|
|
19
|
+
factors.push((trv + brv) / bounds.height);
|
|
20
|
+
const maxFactor = Math.max(...factors);
|
|
21
|
+
if (maxFactor > 1) {
|
|
22
|
+
tlh /= maxFactor;
|
|
23
|
+
tlv /= maxFactor;
|
|
24
|
+
trh /= maxFactor;
|
|
25
|
+
trv /= maxFactor;
|
|
26
|
+
brh /= maxFactor;
|
|
27
|
+
brv /= maxFactor;
|
|
28
|
+
blh /= maxFactor;
|
|
29
|
+
blv /= maxFactor;
|
|
30
|
+
}
|
|
31
|
+
const topWidth = bounds.width - trh;
|
|
32
|
+
const rightHeight = bounds.height - brv;
|
|
33
|
+
const bottomWidth = bounds.width - brh;
|
|
34
|
+
const leftHeight = bounds.height - blv;
|
|
35
|
+
const borderTopWidth = styles.borderTopWidth;
|
|
36
|
+
const borderRightWidth = styles.borderRightWidth;
|
|
37
|
+
const borderBottomWidth = styles.borderBottomWidth;
|
|
38
|
+
const borderLeftWidth = styles.borderLeftWidth;
|
|
39
|
+
const paddingTop = (0, length_percentage_1.getAbsoluteValue)(styles.paddingTop, element.bounds.width);
|
|
40
|
+
const paddingRight = (0, length_percentage_1.getAbsoluteValue)(styles.paddingRight, element.bounds.width);
|
|
41
|
+
const paddingBottom = (0, length_percentage_1.getAbsoluteValue)(styles.paddingBottom, element.bounds.width);
|
|
42
|
+
const paddingLeft = (0, length_percentage_1.getAbsoluteValue)(styles.paddingLeft, element.bounds.width);
|
|
43
|
+
this.topLeftBorderDoubleOuterBox =
|
|
44
|
+
tlh > 0 || tlv > 0
|
|
45
|
+
? getCurvePoints(bounds.left + borderLeftWidth / 3, bounds.top + borderTopWidth / 3, tlh - borderLeftWidth / 3, tlv - borderTopWidth / 3, CORNER.TOP_LEFT)
|
|
46
|
+
: new vector_1.Vector(bounds.left + borderLeftWidth / 3, bounds.top + borderTopWidth / 3);
|
|
47
|
+
this.topRightBorderDoubleOuterBox =
|
|
48
|
+
tlh > 0 || tlv > 0
|
|
49
|
+
? getCurvePoints(bounds.left + topWidth, bounds.top + borderTopWidth / 3, trh - borderRightWidth / 3, trv - borderTopWidth / 3, CORNER.TOP_RIGHT)
|
|
50
|
+
: new vector_1.Vector(bounds.left + bounds.width - borderRightWidth / 3, bounds.top + borderTopWidth / 3);
|
|
51
|
+
this.bottomRightBorderDoubleOuterBox =
|
|
52
|
+
brh > 0 || brv > 0
|
|
53
|
+
? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh - borderRightWidth / 3, brv - borderBottomWidth / 3, CORNER.BOTTOM_RIGHT)
|
|
54
|
+
: new vector_1.Vector(bounds.left + bounds.width - borderRightWidth / 3, bounds.top + bounds.height - borderBottomWidth / 3);
|
|
55
|
+
this.bottomLeftBorderDoubleOuterBox =
|
|
56
|
+
blh > 0 || blv > 0
|
|
57
|
+
? getCurvePoints(bounds.left + borderLeftWidth / 3, bounds.top + leftHeight, blh - borderLeftWidth / 3, blv - borderBottomWidth / 3, CORNER.BOTTOM_LEFT)
|
|
58
|
+
: new vector_1.Vector(bounds.left + borderLeftWidth / 3, bounds.top + bounds.height - borderBottomWidth / 3);
|
|
59
|
+
this.topLeftBorderDoubleInnerBox =
|
|
60
|
+
tlh > 0 || tlv > 0
|
|
61
|
+
? getCurvePoints(bounds.left + (borderLeftWidth * 2) / 3, bounds.top + (borderTopWidth * 2) / 3, tlh - (borderLeftWidth * 2) / 3, tlv - (borderTopWidth * 2) / 3, CORNER.TOP_LEFT)
|
|
62
|
+
: new vector_1.Vector(bounds.left + (borderLeftWidth * 2) / 3, bounds.top + (borderTopWidth * 2) / 3);
|
|
63
|
+
this.topRightBorderDoubleInnerBox =
|
|
64
|
+
tlh > 0 || tlv > 0
|
|
65
|
+
? getCurvePoints(bounds.left + topWidth, bounds.top + (borderTopWidth * 2) / 3, trh - (borderRightWidth * 2) / 3, trv - (borderTopWidth * 2) / 3, CORNER.TOP_RIGHT)
|
|
66
|
+
: new vector_1.Vector(bounds.left + bounds.width - (borderRightWidth * 2) / 3, bounds.top + (borderTopWidth * 2) / 3);
|
|
67
|
+
this.bottomRightBorderDoubleInnerBox =
|
|
68
|
+
brh > 0 || brv > 0
|
|
69
|
+
? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh - (borderRightWidth * 2) / 3, brv - (borderBottomWidth * 2) / 3, CORNER.BOTTOM_RIGHT)
|
|
70
|
+
: new vector_1.Vector(bounds.left + bounds.width - (borderRightWidth * 2) / 3, bounds.top + bounds.height - (borderBottomWidth * 2) / 3);
|
|
71
|
+
this.bottomLeftBorderDoubleInnerBox =
|
|
72
|
+
blh > 0 || blv > 0
|
|
73
|
+
? getCurvePoints(bounds.left + (borderLeftWidth * 2) / 3, bounds.top + leftHeight, blh - (borderLeftWidth * 2) / 3, blv - (borderBottomWidth * 2) / 3, CORNER.BOTTOM_LEFT)
|
|
74
|
+
: new vector_1.Vector(bounds.left + (borderLeftWidth * 2) / 3, bounds.top + bounds.height - (borderBottomWidth * 2) / 3);
|
|
75
|
+
this.topLeftBorderStroke =
|
|
76
|
+
tlh > 0 || tlv > 0
|
|
77
|
+
? getCurvePoints(bounds.left + borderLeftWidth / 2, bounds.top + borderTopWidth / 2, tlh - borderLeftWidth / 2, tlv - borderTopWidth / 2, CORNER.TOP_LEFT)
|
|
78
|
+
: new vector_1.Vector(bounds.left + borderLeftWidth / 2, bounds.top + borderTopWidth / 2);
|
|
79
|
+
this.topRightBorderStroke =
|
|
80
|
+
tlh > 0 || tlv > 0
|
|
81
|
+
? getCurvePoints(bounds.left + topWidth, bounds.top + borderTopWidth / 2, trh - borderRightWidth / 2, trv - borderTopWidth / 2, CORNER.TOP_RIGHT)
|
|
82
|
+
: new vector_1.Vector(bounds.left + bounds.width - borderRightWidth / 2, bounds.top + borderTopWidth / 2);
|
|
83
|
+
this.bottomRightBorderStroke =
|
|
84
|
+
brh > 0 || brv > 0
|
|
85
|
+
? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh - borderRightWidth / 2, brv - borderBottomWidth / 2, CORNER.BOTTOM_RIGHT)
|
|
86
|
+
: new vector_1.Vector(bounds.left + bounds.width - borderRightWidth / 2, bounds.top + bounds.height - borderBottomWidth / 2);
|
|
87
|
+
this.bottomLeftBorderStroke =
|
|
88
|
+
blh > 0 || blv > 0
|
|
89
|
+
? getCurvePoints(bounds.left + borderLeftWidth / 2, bounds.top + leftHeight, blh - borderLeftWidth / 2, blv - borderBottomWidth / 2, CORNER.BOTTOM_LEFT)
|
|
90
|
+
: new vector_1.Vector(bounds.left + borderLeftWidth / 2, bounds.top + bounds.height - borderBottomWidth / 2);
|
|
91
|
+
this.topLeftBorderBox =
|
|
92
|
+
tlh > 0 || tlv > 0
|
|
93
|
+
? getCurvePoints(bounds.left, bounds.top, tlh, tlv, CORNER.TOP_LEFT)
|
|
94
|
+
: new vector_1.Vector(bounds.left, bounds.top);
|
|
95
|
+
this.topRightBorderBox =
|
|
96
|
+
trh > 0 || trv > 0
|
|
97
|
+
? getCurvePoints(bounds.left + topWidth, bounds.top, trh, trv, CORNER.TOP_RIGHT)
|
|
98
|
+
: new vector_1.Vector(bounds.left + bounds.width, bounds.top);
|
|
99
|
+
this.bottomRightBorderBox =
|
|
100
|
+
brh > 0 || brv > 0
|
|
101
|
+
? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh, brv, CORNER.BOTTOM_RIGHT)
|
|
102
|
+
: new vector_1.Vector(bounds.left + bounds.width, bounds.top + bounds.height);
|
|
103
|
+
this.bottomLeftBorderBox =
|
|
104
|
+
blh > 0 || blv > 0
|
|
105
|
+
? getCurvePoints(bounds.left, bounds.top + leftHeight, blh, blv, CORNER.BOTTOM_LEFT)
|
|
106
|
+
: new vector_1.Vector(bounds.left, bounds.top + bounds.height);
|
|
107
|
+
this.topLeftPaddingBox =
|
|
108
|
+
tlh > 0 || tlv > 0
|
|
109
|
+
? getCurvePoints(bounds.left + borderLeftWidth, bounds.top + borderTopWidth, Math.max(0, tlh - borderLeftWidth), Math.max(0, tlv - borderTopWidth), CORNER.TOP_LEFT)
|
|
110
|
+
: new vector_1.Vector(bounds.left + borderLeftWidth, bounds.top + borderTopWidth);
|
|
111
|
+
this.topRightPaddingBox =
|
|
112
|
+
trh > 0 || trv > 0
|
|
113
|
+
? getCurvePoints(bounds.left + Math.min(topWidth, bounds.width - borderRightWidth), bounds.top + borderTopWidth, topWidth > bounds.width + borderRightWidth ? 0 : Math.max(0, trh - borderRightWidth), Math.max(0, trv - borderTopWidth), CORNER.TOP_RIGHT)
|
|
114
|
+
: new vector_1.Vector(bounds.left + bounds.width - borderRightWidth, bounds.top + borderTopWidth);
|
|
115
|
+
this.bottomRightPaddingBox =
|
|
116
|
+
brh > 0 || brv > 0
|
|
117
|
+
? getCurvePoints(bounds.left + Math.min(bottomWidth, bounds.width - borderLeftWidth), bounds.top + Math.min(rightHeight, bounds.height - borderBottomWidth), Math.max(0, brh - borderRightWidth), Math.max(0, brv - borderBottomWidth), CORNER.BOTTOM_RIGHT)
|
|
118
|
+
: new vector_1.Vector(bounds.left + bounds.width - borderRightWidth, bounds.top + bounds.height - borderBottomWidth);
|
|
119
|
+
this.bottomLeftPaddingBox =
|
|
120
|
+
blh > 0 || blv > 0
|
|
121
|
+
? getCurvePoints(bounds.left + borderLeftWidth, bounds.top + Math.min(leftHeight, bounds.height - borderBottomWidth), Math.max(0, blh - borderLeftWidth), Math.max(0, blv - borderBottomWidth), CORNER.BOTTOM_LEFT)
|
|
122
|
+
: new vector_1.Vector(bounds.left + borderLeftWidth, bounds.top + bounds.height - borderBottomWidth);
|
|
123
|
+
this.topLeftContentBox =
|
|
124
|
+
tlh > 0 || tlv > 0
|
|
125
|
+
? getCurvePoints(bounds.left + borderLeftWidth + paddingLeft, bounds.top + borderTopWidth + paddingTop, Math.max(0, tlh - (borderLeftWidth + paddingLeft)), Math.max(0, tlv - (borderTopWidth + paddingTop)), CORNER.TOP_LEFT)
|
|
126
|
+
: new vector_1.Vector(bounds.left + borderLeftWidth + paddingLeft, bounds.top + borderTopWidth + paddingTop);
|
|
127
|
+
this.topRightContentBox =
|
|
128
|
+
trh > 0 || trv > 0
|
|
129
|
+
? getCurvePoints(bounds.left + Math.min(topWidth, bounds.width + borderLeftWidth + paddingLeft), bounds.top + borderTopWidth + paddingTop, topWidth > bounds.width + borderLeftWidth + paddingLeft ? 0 : trh - borderLeftWidth + paddingLeft, trv - (borderTopWidth + paddingTop), CORNER.TOP_RIGHT)
|
|
130
|
+
: new vector_1.Vector(bounds.left + bounds.width - (borderRightWidth + paddingRight), bounds.top + borderTopWidth + paddingTop);
|
|
131
|
+
this.bottomRightContentBox =
|
|
132
|
+
brh > 0 || brv > 0
|
|
133
|
+
? getCurvePoints(bounds.left + Math.min(bottomWidth, bounds.width - (borderLeftWidth + paddingLeft)), bounds.top + Math.min(rightHeight, bounds.height + borderTopWidth + paddingTop), Math.max(0, brh - (borderRightWidth + paddingRight)), brv - (borderBottomWidth + paddingBottom), CORNER.BOTTOM_RIGHT)
|
|
134
|
+
: new vector_1.Vector(bounds.left + bounds.width - (borderRightWidth + paddingRight), bounds.top + bounds.height - (borderBottomWidth + paddingBottom));
|
|
135
|
+
this.bottomLeftContentBox =
|
|
136
|
+
blh > 0 || blv > 0
|
|
137
|
+
? getCurvePoints(bounds.left + borderLeftWidth + paddingLeft, bounds.top + leftHeight, Math.max(0, blh - (borderLeftWidth + paddingLeft)), blv - (borderBottomWidth + paddingBottom), CORNER.BOTTOM_LEFT)
|
|
138
|
+
: new vector_1.Vector(bounds.left + borderLeftWidth + paddingLeft, bounds.top + bounds.height - (borderBottomWidth + paddingBottom));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.BoundCurves = BoundCurves;
|
|
142
|
+
var CORNER;
|
|
143
|
+
(function (CORNER) {
|
|
144
|
+
CORNER[CORNER["TOP_LEFT"] = 0] = "TOP_LEFT";
|
|
145
|
+
CORNER[CORNER["TOP_RIGHT"] = 1] = "TOP_RIGHT";
|
|
146
|
+
CORNER[CORNER["BOTTOM_RIGHT"] = 2] = "BOTTOM_RIGHT";
|
|
147
|
+
CORNER[CORNER["BOTTOM_LEFT"] = 3] = "BOTTOM_LEFT";
|
|
148
|
+
})(CORNER || (CORNER = {}));
|
|
149
|
+
const getCurvePoints = (x, y, r1, r2, position) => {
|
|
150
|
+
const kappa = 4 * ((Math.sqrt(2) - 1) / 3);
|
|
151
|
+
const ox = r1 * kappa; // control point offset horizontal
|
|
152
|
+
const oy = r2 * kappa; // control point offset vertical
|
|
153
|
+
const xm = x + r1; // x-middle
|
|
154
|
+
const ym = y + r2; // y-middle
|
|
155
|
+
switch (position) {
|
|
156
|
+
case CORNER.TOP_LEFT:
|
|
157
|
+
return new bezier_curve_1.BezierCurve(new vector_1.Vector(x, ym), new vector_1.Vector(x, ym - oy), new vector_1.Vector(xm - ox, y), new vector_1.Vector(xm, y));
|
|
158
|
+
case CORNER.TOP_RIGHT:
|
|
159
|
+
return new bezier_curve_1.BezierCurve(new vector_1.Vector(x, y), new vector_1.Vector(x + ox, y), new vector_1.Vector(xm, ym - oy), new vector_1.Vector(xm, ym));
|
|
160
|
+
case CORNER.BOTTOM_RIGHT:
|
|
161
|
+
return new bezier_curve_1.BezierCurve(new vector_1.Vector(xm, y), new vector_1.Vector(xm, y + oy), new vector_1.Vector(x + ox, ym), new vector_1.Vector(x, ym));
|
|
162
|
+
case CORNER.BOTTOM_LEFT:
|
|
163
|
+
default:
|
|
164
|
+
return new bezier_curve_1.BezierCurve(new vector_1.Vector(xm, ym), new vector_1.Vector(xm - ox, ym), new vector_1.Vector(x, y + oy), new vector_1.Vector(x, y));
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const calculateBorderBoxPath = (curves) => {
|
|
168
|
+
return [curves.topLeftBorderBox, curves.topRightBorderBox, curves.bottomRightBorderBox, curves.bottomLeftBorderBox];
|
|
169
|
+
};
|
|
170
|
+
exports.calculateBorderBoxPath = calculateBorderBoxPath;
|
|
171
|
+
const calculateContentBoxPath = (curves) => {
|
|
172
|
+
return [
|
|
173
|
+
curves.topLeftContentBox,
|
|
174
|
+
curves.topRightContentBox,
|
|
175
|
+
curves.bottomRightContentBox,
|
|
176
|
+
curves.bottomLeftContentBox
|
|
177
|
+
];
|
|
178
|
+
};
|
|
179
|
+
exports.calculateContentBoxPath = calculateContentBoxPath;
|
|
180
|
+
const calculatePaddingBoxPath = (curves) => {
|
|
181
|
+
return [
|
|
182
|
+
curves.topLeftPaddingBox,
|
|
183
|
+
curves.topRightPaddingBox,
|
|
184
|
+
curves.bottomRightPaddingBox,
|
|
185
|
+
curves.bottomLeftPaddingBox
|
|
186
|
+
];
|
|
187
|
+
};
|
|
188
|
+
exports.calculatePaddingBoxPath = calculatePaddingBoxPath;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contentBox = exports.paddingBox = void 0;
|
|
4
|
+
const length_percentage_1 = require("../css/types/length-percentage");
|
|
5
|
+
const paddingBox = (element) => {
|
|
6
|
+
const bounds = element.bounds;
|
|
7
|
+
const styles = element.styles;
|
|
8
|
+
return bounds.add(styles.borderLeftWidth, styles.borderTopWidth, -(styles.borderRightWidth + styles.borderLeftWidth), -(styles.borderTopWidth + styles.borderBottomWidth));
|
|
9
|
+
};
|
|
10
|
+
exports.paddingBox = paddingBox;
|
|
11
|
+
const contentBox = (element) => {
|
|
12
|
+
const styles = element.styles;
|
|
13
|
+
const bounds = element.bounds;
|
|
14
|
+
const paddingLeft = (0, length_percentage_1.getAbsoluteValue)(styles.paddingLeft, bounds.width);
|
|
15
|
+
const paddingRight = (0, length_percentage_1.getAbsoluteValue)(styles.paddingRight, bounds.width);
|
|
16
|
+
const paddingTop = (0, length_percentage_1.getAbsoluteValue)(styles.paddingTop, bounds.width);
|
|
17
|
+
const paddingBottom = (0, length_percentage_1.getAbsoluteValue)(styles.paddingBottom, bounds.width);
|
|
18
|
+
return bounds.add(paddingLeft + styles.borderLeftWidth, paddingTop + styles.borderTopWidth, -(styles.borderRightWidth + styles.borderLeftWidth + paddingLeft + paddingRight), -(styles.borderTopWidth + styles.borderBottomWidth + paddingTop + paddingBottom));
|
|
19
|
+
};
|
|
20
|
+
exports.contentBox = contentBox;
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Background Renderer
|
|
4
|
+
*
|
|
5
|
+
* Handles rendering of element backgrounds including:
|
|
6
|
+
* - Background colors
|
|
7
|
+
* - Background images (URL)
|
|
8
|
+
* - Linear gradients
|
|
9
|
+
* - Radial gradients
|
|
10
|
+
* - Background patterns and repeats
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.BackgroundRenderer = void 0;
|
|
14
|
+
const image_1 = require("../../css/types/image");
|
|
15
|
+
const background_1 = require("../background");
|
|
16
|
+
const gradient_1 = require("../../css/types/functions/gradient");
|
|
17
|
+
const length_percentage_1 = require("../../css/types/length-percentage");
|
|
18
|
+
const color_utilities_1 = require("../../css/types/color-utilities");
|
|
19
|
+
const image_rendering_1 = require("../../css/property-descriptors/image-rendering");
|
|
20
|
+
const canvas_path_1 = require("./canvas-path");
|
|
21
|
+
const lru_map_1 = require("../../core/lru-map");
|
|
22
|
+
/**
|
|
23
|
+
* Background Renderer
|
|
24
|
+
*
|
|
25
|
+
* Specialized renderer for element backgrounds.
|
|
26
|
+
* Extracted from CanvasRenderer to improve code organization and maintainability.
|
|
27
|
+
*/
|
|
28
|
+
class BackgroundRenderer {
|
|
29
|
+
constructor(deps) {
|
|
30
|
+
/**
|
|
31
|
+
* Instance-level LRU cache for background-image patterns.
|
|
32
|
+
* CanvasPatterns are tied to the rendering context and must not be
|
|
33
|
+
* shared across different render passes. This cache lives for the
|
|
34
|
+
* duration of one html2canvas() call.
|
|
35
|
+
*/
|
|
36
|
+
this.patternCache = new lru_map_1.LRUMap(50);
|
|
37
|
+
this.ctx = deps.ctx;
|
|
38
|
+
this.context = deps.context;
|
|
39
|
+
this.canvas = deps.canvas;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Render background images for a container
|
|
43
|
+
* Supports URL images, linear gradients, and radial gradients
|
|
44
|
+
*
|
|
45
|
+
* @param container - Element container with background styles
|
|
46
|
+
*/
|
|
47
|
+
async renderBackgroundImage(container) {
|
|
48
|
+
let index = container.styles.backgroundImage.length - 1;
|
|
49
|
+
const blendModes = container.styles.backgroundBlendMode;
|
|
50
|
+
let layerCount = 0;
|
|
51
|
+
for (const backgroundImage of container.styles.backgroundImage.slice(0).reverse()) {
|
|
52
|
+
// Save context and apply blend mode for non-first layers
|
|
53
|
+
if (layerCount > 0) {
|
|
54
|
+
const blendMode = blendModes[layerCount] ?? blendModes[0] ?? 'normal';
|
|
55
|
+
if (blendMode !== 'normal') {
|
|
56
|
+
this.ctx.save();
|
|
57
|
+
this.ctx.globalCompositeOperation = blendMode;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (backgroundImage.type === 0 /* CSSImageType.URL */) {
|
|
61
|
+
await this.renderBackgroundURLImage(container, backgroundImage, index);
|
|
62
|
+
}
|
|
63
|
+
else if ((0, image_1.isLinearGradient)(backgroundImage)) {
|
|
64
|
+
this.renderLinearGradient(container, backgroundImage, index);
|
|
65
|
+
}
|
|
66
|
+
else if ((0, image_1.isRepeatingLinearGradient)(backgroundImage)) {
|
|
67
|
+
this.renderRepeatingLinearGradient(container, backgroundImage, index);
|
|
68
|
+
}
|
|
69
|
+
else if ((0, image_1.isRadialGradient)(backgroundImage)) {
|
|
70
|
+
this.renderRadialGradient(container, backgroundImage, index);
|
|
71
|
+
}
|
|
72
|
+
if (layerCount > 0) {
|
|
73
|
+
const blendMode = blendModes[layerCount] ?? blendModes[0] ?? 'normal';
|
|
74
|
+
if (blendMode !== 'normal') {
|
|
75
|
+
this.ctx.restore();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
index--;
|
|
79
|
+
layerCount++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Render a URL-based background image
|
|
84
|
+
*/
|
|
85
|
+
async renderBackgroundURLImage(container, backgroundImage, index) {
|
|
86
|
+
let image;
|
|
87
|
+
const url = backgroundImage.url;
|
|
88
|
+
try {
|
|
89
|
+
image = await this.context.cache.match(url);
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
this.context.logger.error(`Error loading background-image ${url}`);
|
|
93
|
+
this.context.onError?.(e instanceof Error ? e : new Error(String(e)));
|
|
94
|
+
}
|
|
95
|
+
if (image) {
|
|
96
|
+
const imageWidth = isNaN(image.width) || image.width === 0 ? 1 : image.width;
|
|
97
|
+
const imageHeight = isNaN(image.height) || image.height === 0 ? 1 : image.height;
|
|
98
|
+
const [path, x, y, width, height] = (0, background_1.calculateBackgroundRendering)(container, index, [
|
|
99
|
+
imageWidth,
|
|
100
|
+
imageHeight,
|
|
101
|
+
imageWidth / imageHeight
|
|
102
|
+
]);
|
|
103
|
+
// Determine repetition mode based on CSS background-repeat
|
|
104
|
+
const repeat = (0, background_1.getBackgroundValueForIndex)(container.styles.backgroundRepeat, index);
|
|
105
|
+
const repeatMode = repeat === 1 /* BACKGROUND_REPEAT.NO_REPEAT */
|
|
106
|
+
? 'no-repeat'
|
|
107
|
+
: repeat === 2 /* BACKGROUND_REPEAT.REPEAT_X */
|
|
108
|
+
? 'repeat-x'
|
|
109
|
+
: repeat === 3 /* BACKGROUND_REPEAT.REPEAT_Y */
|
|
110
|
+
? 'repeat-y'
|
|
111
|
+
: 'repeat';
|
|
112
|
+
// Cache key: URL + resized dimensions + imageRendering + repeat mode (pattern is dependent on all four)
|
|
113
|
+
const cacheKey = `${url}|${Math.round(width)}x${Math.round(height)}|${container.styles.imageRendering}|${repeatMode}`;
|
|
114
|
+
let pattern = this.patternCache.get(cacheKey);
|
|
115
|
+
if (!pattern) {
|
|
116
|
+
const resized = this.resizeImage(image, width, height, container.styles.imageRendering);
|
|
117
|
+
pattern = this.ctx.createPattern(resized, repeatMode);
|
|
118
|
+
this.patternCache.set(cacheKey, pattern);
|
|
119
|
+
}
|
|
120
|
+
this.renderRepeat(path, pattern, x, y);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Render a repeating linear gradient background.
|
|
125
|
+
* Renders one cycle of the gradient to a pattern canvas, then fills
|
|
126
|
+
* the background area using createPattern('repeat').
|
|
127
|
+
*/
|
|
128
|
+
renderRepeatingLinearGradient(container, backgroundImage, index) {
|
|
129
|
+
const [path, x, y, width, height] = (0, background_1.calculateBackgroundRendering)(container, index, [null, null, null]);
|
|
130
|
+
const [lineLength, x0, x1, y0, y1] = (0, gradient_1.calculateGradientDirection)(backgroundImage.angle, width, height);
|
|
131
|
+
// Determine the repeating pattern length from color stops
|
|
132
|
+
const processedStops = (0, gradient_1.processColorStops)(backgroundImage.stops, lineLength || 1);
|
|
133
|
+
const lastStop = processedStops[processedStops.length - 1];
|
|
134
|
+
const firstStop = processedStops[0];
|
|
135
|
+
const patternLength = lastStop.stop - firstStop.stop;
|
|
136
|
+
if (patternLength <= 0) {
|
|
137
|
+
// Fallback: render as normal linear gradient
|
|
138
|
+
this.renderLinearGradient(container, backgroundImage, index);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
// Scale direction vectors to match the pattern length
|
|
142
|
+
const dirX = x1 - x0;
|
|
143
|
+
const dirY = y1 - y0;
|
|
144
|
+
const totalLength = Math.sqrt(dirX * dirX + dirY * dirY);
|
|
145
|
+
const scale = patternLength / (totalLength || 1);
|
|
146
|
+
const pX0 = x0;
|
|
147
|
+
const pY0 = y0;
|
|
148
|
+
const pX1 = x0 + dirX * scale;
|
|
149
|
+
const pY1 = y0 + dirY * scale;
|
|
150
|
+
const ownerDocument = this.canvas.ownerDocument ?? document;
|
|
151
|
+
// Cache key for this repeating gradient pattern
|
|
152
|
+
const cacheKey = `rlg|${backgroundImage.angle}|${Math.round(patternLength)}|${JSON.stringify(backgroundImage.stops)}`;
|
|
153
|
+
let pattern = this.patternCache.get(cacheKey);
|
|
154
|
+
if (!pattern) {
|
|
155
|
+
const canvas = ownerDocument.createElement('canvas');
|
|
156
|
+
// Create a canvas large enough to hold one full repeating unit
|
|
157
|
+
const canvasSize = Math.max(1, Math.ceil(patternLength));
|
|
158
|
+
canvas.width = canvasSize;
|
|
159
|
+
canvas.height = canvasSize;
|
|
160
|
+
const ctx = canvas.getContext('2d');
|
|
161
|
+
if (!ctx) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const gradient = ctx.createLinearGradient(pX0 - x, pY0 - y, pX1 - x, pY1 - y);
|
|
165
|
+
// Normalize stops to [0, 1] range for one repeating unit
|
|
166
|
+
processedStops.forEach((colorStop) => {
|
|
167
|
+
gradient.addColorStop((colorStop.stop - firstStop.stop) / patternLength, (0, color_utilities_1.asString)(colorStop.color));
|
|
168
|
+
});
|
|
169
|
+
ctx.fillStyle = gradient;
|
|
170
|
+
ctx.fillRect(0, 0, canvasSize, canvasSize);
|
|
171
|
+
if (canvasSize > 0) {
|
|
172
|
+
pattern = this.ctx.createPattern(canvas, 'repeat');
|
|
173
|
+
this.patternCache.set(cacheKey, pattern);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (pattern) {
|
|
177
|
+
this.renderRepeat(path, pattern, x, y);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Render a linear gradient background
|
|
182
|
+
*/
|
|
183
|
+
renderLinearGradient(container, backgroundImage, index) {
|
|
184
|
+
const [path, x, y, width, height] = (0, background_1.calculateBackgroundRendering)(container, index, [null, null, null]);
|
|
185
|
+
const [lineLength, x0, x1, y0, y1] = (0, gradient_1.calculateGradientDirection)(backgroundImage.angle, width, height);
|
|
186
|
+
// Cache key: angle + dimensions + serialised colour stops
|
|
187
|
+
const cacheKey = `lg|${backgroundImage.angle}|${Math.round(width)}x${Math.round(height)}|${JSON.stringify(backgroundImage.stops)}`;
|
|
188
|
+
let pattern = this.patternCache.get(cacheKey);
|
|
189
|
+
if (!pattern) {
|
|
190
|
+
const ownerDocument = this.canvas.ownerDocument ?? document;
|
|
191
|
+
const canvas = ownerDocument.createElement('canvas');
|
|
192
|
+
canvas.width = width;
|
|
193
|
+
canvas.height = height;
|
|
194
|
+
const ctx = canvas.getContext('2d');
|
|
195
|
+
if (!ctx) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
|
|
199
|
+
(0, gradient_1.processColorStops)(backgroundImage.stops, lineLength || 1).forEach((colorStop) => gradient.addColorStop(colorStop.stop, (0, color_utilities_1.asString)(colorStop.color)));
|
|
200
|
+
ctx.fillStyle = gradient;
|
|
201
|
+
ctx.fillRect(0, 0, width, height);
|
|
202
|
+
if (width > 0 && height > 0) {
|
|
203
|
+
pattern = this.ctx.createPattern(canvas, 'repeat');
|
|
204
|
+
this.patternCache.set(cacheKey, pattern);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (pattern) {
|
|
208
|
+
this.renderRepeat(path, pattern, x, y);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Render a radial gradient background
|
|
213
|
+
*/
|
|
214
|
+
renderRadialGradient(container, backgroundImage, index) {
|
|
215
|
+
const [path, left, top, width, height] = (0, background_1.calculateBackgroundRendering)(container, index, [null, null, null]);
|
|
216
|
+
const position = backgroundImage.position.length === 0 ? [length_percentage_1.FIFTY_PERCENT] : backgroundImage.position;
|
|
217
|
+
const x = (0, length_percentage_1.getAbsoluteValue)(position[0], width);
|
|
218
|
+
const y = (0, length_percentage_1.getAbsoluteValue)(position[position.length - 1], height);
|
|
219
|
+
let [rx, ry] = (0, gradient_1.calculateRadius)(backgroundImage, x, y, width, height);
|
|
220
|
+
// Handle edge case where radial gradient size is 0
|
|
221
|
+
// Use a minimum value of 0.01 to ensure gradient is still rendered
|
|
222
|
+
if (rx === 0 || ry === 0) {
|
|
223
|
+
rx = Math.max(rx, 0.01);
|
|
224
|
+
ry = Math.max(ry, 0.01);
|
|
225
|
+
}
|
|
226
|
+
if (rx > 0 && ry > 0) {
|
|
227
|
+
// Cache key for radial gradient: position + radii + colour stops
|
|
228
|
+
const cacheKey = `rg|${Math.round(x)}x${Math.round(y)}|${Math.round(rx)}x${Math.round(ry)}|${JSON.stringify(backgroundImage.stops)}`;
|
|
229
|
+
let pattern = this.patternCache.get(cacheKey);
|
|
230
|
+
if (!pattern) {
|
|
231
|
+
const ownerDocument = this.canvas.ownerDocument ?? document;
|
|
232
|
+
const size = Math.ceil(Math.max(rx, ry) * 2);
|
|
233
|
+
const offscreen = ownerDocument.createElement('canvas');
|
|
234
|
+
offscreen.width = size;
|
|
235
|
+
offscreen.height = size;
|
|
236
|
+
const offCtx = offscreen.getContext('2d');
|
|
237
|
+
if (offCtx) {
|
|
238
|
+
const offRadius = Math.max(rx, ry);
|
|
239
|
+
const gradient = offCtx.createRadialGradient(offRadius, offRadius, 0, offRadius, offRadius, offRadius);
|
|
240
|
+
(0, gradient_1.processColorStops)(backgroundImage.stops, offRadius * 2).forEach((s) => gradient.addColorStop(s.stop, (0, color_utilities_1.asString)(s.color)));
|
|
241
|
+
offCtx.fillStyle = gradient;
|
|
242
|
+
if (rx !== ry)
|
|
243
|
+
offCtx.scale(1, ry / rx);
|
|
244
|
+
offCtx.fillRect(0, 0, offRadius * 2, offRadius * 2);
|
|
245
|
+
pattern = this.ctx.createPattern(offscreen, 'no-repeat');
|
|
246
|
+
this.patternCache.set(cacheKey, pattern);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (pattern) {
|
|
250
|
+
this.path(path);
|
|
251
|
+
this.ctx.save();
|
|
252
|
+
this.ctx.clip();
|
|
253
|
+
this.ctx.translate(left + x - Math.max(rx, ry), top + y - Math.max(rx, ry));
|
|
254
|
+
this.ctx.fillStyle = pattern;
|
|
255
|
+
this.ctx.fillRect(0, 0, Math.max(rx, ry) * 2, Math.max(rx, ry) * 2);
|
|
256
|
+
this.ctx.restore();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Render a repeating pattern with offset
|
|
262
|
+
*
|
|
263
|
+
* @param path - Path to fill
|
|
264
|
+
* @param pattern - Canvas pattern or gradient
|
|
265
|
+
* @param offsetX - X offset for pattern
|
|
266
|
+
* @param offsetY - Y offset for pattern
|
|
267
|
+
*/
|
|
268
|
+
renderRepeat(path, pattern, offsetX, offsetY) {
|
|
269
|
+
this.path(path);
|
|
270
|
+
this.ctx.fillStyle = pattern;
|
|
271
|
+
this.ctx.translate(offsetX, offsetY);
|
|
272
|
+
this.ctx.fill();
|
|
273
|
+
this.ctx.translate(-offsetX, -offsetY);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Resize an image to target dimensions
|
|
277
|
+
*
|
|
278
|
+
* @param image - Source image
|
|
279
|
+
* @param width - Target width
|
|
280
|
+
* @param height - Target height
|
|
281
|
+
* @param imageRendering - CSS image-rendering property value
|
|
282
|
+
* @returns Resized canvas or original image
|
|
283
|
+
*/
|
|
284
|
+
resizeImage(image, width, height, imageRendering) {
|
|
285
|
+
// NOTE: Early-return optimisation disabled per upstream investigation
|
|
286
|
+
// (https://github.com/niklasvh/html2canvas/pull/2911).
|
|
287
|
+
// Returning the original image when dimensions match caused subtle
|
|
288
|
+
// rendering issues — a resized copy through a fresh offscreen canvas
|
|
289
|
+
// is always safer, even when width/height are unchanged.
|
|
290
|
+
const ownerDocument = this.canvas.ownerDocument ?? document;
|
|
291
|
+
const canvas = ownerDocument.createElement('canvas');
|
|
292
|
+
canvas.width = Math.max(1, width);
|
|
293
|
+
canvas.height = Math.max(1, height);
|
|
294
|
+
const ctx = canvas.getContext('2d');
|
|
295
|
+
if (!ctx) {
|
|
296
|
+
return image;
|
|
297
|
+
}
|
|
298
|
+
// Apply image smoothing based on CSS image-rendering property
|
|
299
|
+
if (imageRendering === image_rendering_1.IMAGE_RENDERING.PIXELATED || imageRendering === image_rendering_1.IMAGE_RENDERING.CRISP_EDGES) {
|
|
300
|
+
this.context.logger.debug(`Disabling image smoothing for background image due to CSS image-rendering`);
|
|
301
|
+
ctx.imageSmoothingEnabled = false;
|
|
302
|
+
}
|
|
303
|
+
else if (imageRendering === image_rendering_1.IMAGE_RENDERING.SMOOTH) {
|
|
304
|
+
this.context.logger.debug(`Enabling image smoothing for background image due to CSS image-rendering: smooth`);
|
|
305
|
+
ctx.imageSmoothingEnabled = true;
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
// AUTO: inherit from main renderer context
|
|
309
|
+
ctx.imageSmoothingEnabled = this.ctx.imageSmoothingEnabled;
|
|
310
|
+
}
|
|
311
|
+
// Inherit quality setting
|
|
312
|
+
if (this.ctx.imageSmoothingQuality) {
|
|
313
|
+
ctx.imageSmoothingQuality = this.ctx.imageSmoothingQuality;
|
|
314
|
+
}
|
|
315
|
+
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
|
|
316
|
+
return canvas;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Create a canvas path from path array
|
|
320
|
+
*
|
|
321
|
+
* @param paths - Array of path points
|
|
322
|
+
*/
|
|
323
|
+
path(paths) {
|
|
324
|
+
(0, canvas_path_1.createCanvasPath)(this.ctx, paths);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
exports.BackgroundRenderer = BackgroundRenderer;
|