html2canvas-pro 1.4.3
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 +36 -0
- package/dist/html2canvas-pro.esm.js +7943 -0
- package/dist/html2canvas-pro.esm.js.map +1 -0
- package/dist/html2canvas-pro.js +7951 -0
- package/dist/html2canvas-pro.js.map +1 -0
- package/dist/html2canvas-pro.min.js +20 -0
- package/dist/lib/__tests__/index.js +144 -0
- package/dist/lib/__tests__/index.js.map +1 -0
- package/dist/lib/core/__mocks__/cache-storage.js +10 -0
- package/dist/lib/core/__mocks__/cache-storage.js.map +1 -0
- package/dist/lib/core/__mocks__/context.js +22 -0
- package/dist/lib/core/__mocks__/context.js.map +1 -0
- package/dist/lib/core/__mocks__/features.js +12 -0
- package/dist/lib/core/__mocks__/features.js.map +1 -0
- package/dist/lib/core/__mocks__/logger.js +24 -0
- package/dist/lib/core/__mocks__/logger.js.map +1 -0
- package/dist/lib/core/__tests__/cache-storage.js +420 -0
- package/dist/lib/core/__tests__/cache-storage.js.map +1 -0
- package/dist/lib/core/__tests__/logger.js +28 -0
- package/dist/lib/core/__tests__/logger.js.map +1 -0
- package/dist/lib/core/bitwise.js +6 -0
- package/dist/lib/core/bitwise.js.map +1 -0
- package/dist/lib/core/cache-storage.js +198 -0
- package/dist/lib/core/cache-storage.js.map +1 -0
- package/dist/lib/core/context.js +18 -0
- package/dist/lib/core/context.js.map +1 -0
- package/dist/lib/core/debugger.js +25 -0
- package/dist/lib/core/debugger.js.map +1 -0
- package/dist/lib/core/features.js +193 -0
- package/dist/lib/core/features.js.map +1 -0
- package/dist/lib/core/logger.js +88 -0
- package/dist/lib/core/logger.js.map +1 -0
- package/dist/lib/core/util.js +5 -0
- package/dist/lib/core/util.js.map +1 -0
- package/dist/lib/css/IPropertyDescriptor.js +3 -0
- package/dist/lib/css/IPropertyDescriptor.js.map +1 -0
- package/dist/lib/css/ITypeDescriptor.js +3 -0
- package/dist/lib/css/ITypeDescriptor.js.map +1 -0
- package/dist/lib/css/index.js +218 -0
- package/dist/lib/css/index.js.map +1 -0
- package/dist/lib/css/layout/__mocks__/bounds.js +9 -0
- package/dist/lib/css/layout/__mocks__/bounds.js.map +1 -0
- package/dist/lib/css/layout/bounds.js +42 -0
- package/dist/lib/css/layout/bounds.js.map +1 -0
- package/dist/lib/css/layout/text.js +137 -0
- package/dist/lib/css/layout/text.js.map +1 -0
- package/dist/lib/css/property-descriptors/__tests__/background-tests.js +48 -0
- package/dist/lib/css/property-descriptors/__tests__/background-tests.js.map +1 -0
- package/dist/lib/css/property-descriptors/__tests__/font-family.js +25 -0
- package/dist/lib/css/property-descriptors/__tests__/font-family.js.map +1 -0
- package/dist/lib/css/property-descriptors/__tests__/paint-order.js +88 -0
- package/dist/lib/css/property-descriptors/__tests__/paint-order.js.map +1 -0
- package/dist/lib/css/property-descriptors/__tests__/text-shadow.js +94 -0
- package/dist/lib/css/property-descriptors/__tests__/text-shadow.js.map +1 -0
- package/dist/lib/css/property-descriptors/__tests__/transform-tests.js +18 -0
- package/dist/lib/css/property-descriptors/__tests__/transform-tests.js.map +1 -0
- package/dist/lib/css/property-descriptors/background-clip.js +24 -0
- package/dist/lib/css/property-descriptors/background-clip.js.map +1 -0
- package/dist/lib/css/property-descriptors/background-color.js +11 -0
- package/dist/lib/css/property-descriptors/background-color.js.map +1 -0
- package/dist/lib/css/property-descriptors/background-image.js +24 -0
- package/dist/lib/css/property-descriptors/background-image.js.map +1 -0
- package/dist/lib/css/property-descriptors/background-origin.js +24 -0
- package/dist/lib/css/property-descriptors/background-origin.js.map +1 -0
- package/dist/lib/css/property-descriptors/background-position.js +17 -0
- package/dist/lib/css/property-descriptors/background-position.js.map +1 -0
- package/dist/lib/css/property-descriptors/background-repeat.js +36 -0
- package/dist/lib/css/property-descriptors/background-repeat.js.map +1 -0
- package/dist/lib/css/property-descriptors/background-size.js +24 -0
- package/dist/lib/css/property-descriptors/background-size.js.map +1 -0
- package/dist/lib/css/property-descriptors/border-color.js +15 -0
- package/dist/lib/css/property-descriptors/border-color.js.map +1 -0
- package/dist/lib/css/property-descriptors/border-radius.js +18 -0
- package/dist/lib/css/property-descriptors/border-radius.js.map +1 -0
- package/dist/lib/css/property-descriptors/border-style.js +27 -0
- package/dist/lib/css/property-descriptors/border-style.js.map +1 -0
- package/dist/lib/css/property-descriptors/border-width.js +21 -0
- package/dist/lib/css/property-descriptors/border-width.js.map +1 -0
- package/dist/lib/css/property-descriptors/box-shadow.js +55 -0
- package/dist/lib/css/property-descriptors/box-shadow.js.map +1 -0
- package/dist/lib/css/property-descriptors/color.js +11 -0
- package/dist/lib/css/property-descriptors/color.js.map +1 -0
- package/dist/lib/css/property-descriptors/content.js +20 -0
- package/dist/lib/css/property-descriptors/content.js.map +1 -0
- package/dist/lib/css/property-descriptors/counter-increment.js +31 -0
- package/dist/lib/css/property-descriptors/counter-increment.js.map +1 -0
- package/dist/lib/css/property-descriptors/counter-reset.js +27 -0
- package/dist/lib/css/property-descriptors/counter-reset.js.map +1 -0
- package/dist/lib/css/property-descriptors/direction.js +19 -0
- package/dist/lib/css/property-descriptors/direction.js.map +1 -0
- package/dist/lib/css/property-descriptors/display.js +82 -0
- package/dist/lib/css/property-descriptors/display.js.map +1 -0
- package/dist/lib/css/property-descriptors/duration.js +15 -0
- package/dist/lib/css/property-descriptors/duration.js.map +1 -0
- package/dist/lib/css/property-descriptors/float.js +23 -0
- package/dist/lib/css/property-descriptors/float.js.map +1 -0
- package/dist/lib/css/property-descriptors/font-family.js +33 -0
- package/dist/lib/css/property-descriptors/font-family.js.map +1 -0
- package/dist/lib/css/property-descriptors/font-size.js +11 -0
- package/dist/lib/css/property-descriptors/font-size.js.map +1 -0
- package/dist/lib/css/property-descriptors/font-style.js +21 -0
- package/dist/lib/css/property-descriptors/font-style.js.map +1 -0
- package/dist/lib/css/property-descriptors/font-variant.js +14 -0
- package/dist/lib/css/property-descriptors/font-variant.js.map +1 -0
- package/dist/lib/css/property-descriptors/font-weight.js +26 -0
- package/dist/lib/css/property-descriptors/font-weight.js.map +1 -0
- package/dist/lib/css/property-descriptors/letter-spacing.js +22 -0
- package/dist/lib/css/property-descriptors/letter-spacing.js.map +1 -0
- package/dist/lib/css/property-descriptors/line-break.js +24 -0
- package/dist/lib/css/property-descriptors/line-break.js.map +1 -0
- package/dist/lib/css/property-descriptors/line-height.js +25 -0
- package/dist/lib/css/property-descriptors/line-height.js.map +1 -0
- package/dist/lib/css/property-descriptors/list-style-image.js +17 -0
- package/dist/lib/css/property-descriptors/list-style-image.js.map +1 -0
- package/dist/lib/css/property-descriptors/list-style-position.js +19 -0
- package/dist/lib/css/property-descriptors/list-style-position.js.map +1 -0
- package/dist/lib/css/property-descriptors/list-style-type.js +123 -0
- package/dist/lib/css/property-descriptors/list-style-type.js.map +1 -0
- package/dist/lib/css/property-descriptors/margin.js +14 -0
- package/dist/lib/css/property-descriptors/margin.js.map +1 -0
- package/dist/lib/css/property-descriptors/object-fit.js +29 -0
- package/dist/lib/css/property-descriptors/object-fit.js.map +1 -0
- package/dist/lib/css/property-descriptors/opacity.js +17 -0
- package/dist/lib/css/property-descriptors/opacity.js.map +1 -0
- package/dist/lib/css/property-descriptors/overflow-wrap.js +19 -0
- package/dist/lib/css/property-descriptors/overflow-wrap.js.map +1 -0
- package/dist/lib/css/property-descriptors/overflow.js +28 -0
- package/dist/lib/css/property-descriptors/overflow.js.map +1 -0
- package/dist/lib/css/property-descriptors/padding.js +15 -0
- package/dist/lib/css/property-descriptors/padding.js.map +1 -0
- package/dist/lib/css/property-descriptors/paint-order.js +34 -0
- package/dist/lib/css/property-descriptors/paint-order.js.map +1 -0
- package/dist/lib/css/property-descriptors/position.js +23 -0
- package/dist/lib/css/property-descriptors/position.js.map +1 -0
- package/dist/lib/css/property-descriptors/quotes.js +42 -0
- package/dist/lib/css/property-descriptors/quotes.js.map +1 -0
- package/dist/lib/css/property-descriptors/text-align.js +22 -0
- package/dist/lib/css/property-descriptors/text-align.js.map +1 -0
- package/dist/lib/css/property-descriptors/text-decoration-color.js +11 -0
- package/dist/lib/css/property-descriptors/text-decoration-color.js.map +1 -0
- package/dist/lib/css/property-descriptors/text-decoration-line.js +29 -0
- package/dist/lib/css/property-descriptors/text-decoration-line.js.map +1 -0
- package/dist/lib/css/property-descriptors/text-shadow.js +47 -0
- package/dist/lib/css/property-descriptors/text-shadow.js.map +1 -0
- package/dist/lib/css/property-descriptors/text-transform.js +21 -0
- package/dist/lib/css/property-descriptors/text-transform.js.map +1 -0
- package/dist/lib/css/property-descriptors/transform-origin.js +25 -0
- package/dist/lib/css/property-descriptors/transform-origin.js.map +1 -0
- package/dist/lib/css/property-descriptors/transform.js +37 -0
- package/dist/lib/css/property-descriptors/transform.js.map +1 -0
- package/dist/lib/css/property-descriptors/visibility.js +21 -0
- package/dist/lib/css/property-descriptors/visibility.js.map +1 -0
- package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js +11 -0
- package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js.map +1 -0
- package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js +17 -0
- package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js.map +1 -0
- package/dist/lib/css/property-descriptors/word-break.js +27 -0
- package/dist/lib/css/property-descriptors/word-break.js.map +1 -0
- package/dist/lib/css/property-descriptors/z-index.js +20 -0
- package/dist/lib/css/property-descriptors/z-index.js.map +1 -0
- package/dist/lib/css/syntax/__tests__/tokernizer-tests.js +34 -0
- package/dist/lib/css/syntax/__tests__/tokernizer-tests.js.map +1 -0
- package/dist/lib/css/syntax/parser.js +147 -0
- package/dist/lib/css/syntax/parser.js.map +1 -0
- package/dist/lib/css/syntax/tokenizer.js +630 -0
- package/dist/lib/css/syntax/tokenizer.js.map +1 -0
- package/dist/lib/css/types/__tests__/color-tests.js +66 -0
- package/dist/lib/css/types/__tests__/color-tests.js.map +1 -0
- package/dist/lib/css/types/__tests__/image-tests.js +233 -0
- package/dist/lib/css/types/__tests__/image-tests.js.map +1 -0
- package/dist/lib/css/types/angle.js +81 -0
- package/dist/lib/css/types/angle.js.map +1 -0
- package/dist/lib/css/types/color.js +307 -0
- package/dist/lib/css/types/color.js.map +1 -0
- package/dist/lib/css/types/functions/-prefix-linear-gradient.js +33 -0
- package/dist/lib/css/types/functions/-prefix-linear-gradient.js.map +1 -0
- package/dist/lib/css/types/functions/-prefix-radial-gradient.js +84 -0
- package/dist/lib/css/types/functions/-prefix-radial-gradient.js.map +1 -0
- package/dist/lib/css/types/functions/-webkit-gradient.js +60 -0
- package/dist/lib/css/types/functions/-webkit-gradient.js.map +1 -0
- package/dist/lib/css/types/functions/__tests__/radial-gradient.js +68 -0
- package/dist/lib/css/types/functions/__tests__/radial-gradient.js.map +1 -0
- package/dist/lib/css/types/functions/counter.js +374 -0
- package/dist/lib/css/types/functions/counter.js.map +1 -0
- package/dist/lib/css/types/functions/gradient.js +165 -0
- package/dist/lib/css/types/functions/gradient.js.map +1 -0
- package/dist/lib/css/types/functions/linear-gradient.js +28 -0
- package/dist/lib/css/types/functions/linear-gradient.js.map +1 -0
- package/dist/lib/css/types/functions/radial-gradient.js +91 -0
- package/dist/lib/css/types/functions/radial-gradient.js.map +1 -0
- package/dist/lib/css/types/image.js +53 -0
- package/dist/lib/css/types/image.js.map +1 -0
- package/dist/lib/css/types/index.js +3 -0
- package/dist/lib/css/types/index.js.map +1 -0
- package/dist/lib/css/types/length-percentage.js +52 -0
- package/dist/lib/css/types/length-percentage.js.map +1 -0
- package/dist/lib/css/types/length.js +8 -0
- package/dist/lib/css/types/length.js.map +1 -0
- package/dist/lib/css/types/time.js +18 -0
- package/dist/lib/css/types/time.js.map +1 -0
- package/dist/lib/dom/__mocks__/document-cloner.js +24 -0
- package/dist/lib/dom/__mocks__/document-cloner.js.map +1 -0
- package/dist/lib/dom/document-cloner.js +530 -0
- package/dist/lib/dom/document-cloner.js.map +1 -0
- package/dist/lib/dom/element-container.js +35 -0
- package/dist/lib/dom/element-container.js.map +1 -0
- package/dist/lib/dom/elements/li-element-container.js +30 -0
- package/dist/lib/dom/elements/li-element-container.js.map +1 -0
- package/dist/lib/dom/elements/ol-element-container.js +31 -0
- package/dist/lib/dom/elements/ol-element-container.js.map +1 -0
- package/dist/lib/dom/elements/select-element-container.js +31 -0
- package/dist/lib/dom/elements/select-element-container.js.map +1 -0
- package/dist/lib/dom/elements/textarea-element-container.js +30 -0
- package/dist/lib/dom/elements/textarea-element-container.js.map +1 -0
- package/dist/lib/dom/node-parser.js +142 -0
- package/dist/lib/dom/node-parser.js.map +1 -0
- package/dist/lib/dom/replaced-elements/canvas-element-container.js +32 -0
- package/dist/lib/dom/replaced-elements/canvas-element-container.js.map +1 -0
- package/dist/lib/dom/replaced-elements/iframe-element-container.js +55 -0
- package/dist/lib/dom/replaced-elements/iframe-element-container.js.map +1 -0
- package/dist/lib/dom/replaced-elements/image-element-container.js +33 -0
- package/dist/lib/dom/replaced-elements/image-element-container.js.map +1 -0
- package/dist/lib/dom/replaced-elements/index.js +3 -0
- package/dist/lib/dom/replaced-elements/index.js.map +1 -0
- package/dist/lib/dom/replaced-elements/input-element-container.js +102 -0
- package/dist/lib/dom/replaced-elements/input-element-container.js.map +1 -0
- package/dist/lib/dom/replaced-elements/pseudo-elements.js +1 -0
- package/dist/lib/dom/replaced-elements/pseudo-elements.js.map +1 -0
- package/dist/lib/dom/replaced-elements/svg-element-container.js +38 -0
- package/dist/lib/dom/replaced-elements/svg-element-container.js.map +1 -0
- package/dist/lib/dom/text-container.js +32 -0
- package/dist/lib/dom/text-container.js.map +1 -0
- package/dist/lib/index.js +181 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/invariant.js +10 -0
- package/dist/lib/invariant.js.map +1 -0
- package/dist/lib/render/background.js +187 -0
- package/dist/lib/render/background.js.map +1 -0
- package/dist/lib/render/bezier-curve.js +36 -0
- package/dist/lib/render/bezier-curve.js.map +1 -0
- package/dist/lib/render/border.js +105 -0
- package/dist/lib/render/border.js.map +1 -0
- package/dist/lib/render/bound-curves.js +190 -0
- package/dist/lib/render/bound-curves.js.map +1 -0
- package/dist/lib/render/box-sizing.js +21 -0
- package/dist/lib/render/box-sizing.js.map +1 -0
- package/dist/lib/render/canvas/canvas-renderer.js +1106 -0
- package/dist/lib/render/canvas/canvas-renderer.js.map +1 -0
- package/dist/lib/render/canvas/foreignobject-renderer.js +108 -0
- package/dist/lib/render/canvas/foreignobject-renderer.js.map +1 -0
- package/dist/lib/render/effects.js +41 -0
- package/dist/lib/render/effects.js.map +1 -0
- package/dist/lib/render/font-metrics.js +55 -0
- package/dist/lib/render/font-metrics.js.map +1 -0
- package/dist/lib/render/path.js +27 -0
- package/dist/lib/render/path.js.map +1 -0
- package/dist/lib/render/renderer.js +12 -0
- package/dist/lib/render/renderer.js.map +1 -0
- package/dist/lib/render/stacking-context.js +172 -0
- package/dist/lib/render/stacking-context.js.map +1 -0
- package/dist/lib/render/vector.js +18 -0
- package/dist/lib/render/vector.js.map +1 -0
- package/dist/types/__tests__/index.d.ts +1 -0
- package/dist/types/core/__mocks__/cache-storage.d.ts +2 -0
- package/dist/types/core/__mocks__/context.d.ts +9 -0
- package/dist/types/core/__mocks__/features.d.ts +8 -0
- package/dist/types/core/__mocks__/logger.d.ts +9 -0
- package/dist/types/core/__tests__/cache-storage.d.ts +1 -0
- package/dist/types/core/__tests__/logger.d.ts +1 -0
- package/dist/types/core/bitwise.d.ts +1 -0
- package/dist/types/core/cache-storage.d.ts +26 -0
- package/dist/types/core/context.d.ts +15 -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/util.d.ts +1 -0
- package/dist/types/css/IPropertyDescriptor.d.ts +36 -0
- package/dist/types/css/ITypeDescriptor.d.ts +6 -0
- package/dist/types/css/index.d.ts +134 -0
- package/dist/types/css/layout/__mocks__/bounds.d.ts +2 -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-descriptors/__tests__/background-tests.d.ts +1 -0
- package/dist/types/css/property-descriptors/__tests__/font-family.d.ts +1 -0
- package/dist/types/css/property-descriptors/__tests__/paint-order.d.ts +1 -0
- package/dist/types/css/property-descriptors/__tests__/text-shadow.d.ts +1 -0
- package/dist/types/css/property-descriptors/__tests__/transform-tests.d.ts +1 -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-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-shadow.d.ts +14 -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 +7 -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/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.d.ts +2 -0
- package/dist/types/css/property-descriptors/font-weight.d.ts +2 -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/object-fit.d.ts +10 -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/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-shadow.d.ts +12 -0
- package/dist/types/css/property-descriptors/text-transform.d.ts +8 -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-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/z-index.d.ts +7 -0
- package/dist/types/css/syntax/__tests__/tokernizer-tests.d.ts +1 -0
- package/dist/types/css/syntax/parser.d.ts +34 -0
- package/dist/types/css/syntax/tokenizer.d.ts +94 -0
- package/dist/types/css/types/__tests__/color-tests.d.ts +1 -0
- package/dist/types/css/types/__tests__/image-tests.d.ts +1 -0
- package/dist/types/css/types/angle.d.ts +7 -0
- package/dist/types/css/types/color.d.ts +11 -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/__tests__/radial-gradient.d.ts +1 -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/image.d.ts +54 -0
- package/dist/types/css/types/index.d.ts +1 -0
- package/dist/types/css/types/length-percentage.d.ts +11 -0
- package/dist/types/css/types/length.d.ts +4 -0
- package/dist/types/css/types/time.d.ts +2 -0
- package/dist/types/dom/__mocks__/document-cloner.d.ts +6 -0
- package/dist/types/dom/document-cloner.d.ts +45 -0
- package/dist/types/dom/element-container.d.ts +19 -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 +23 -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 +11 -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 +12 -0
- package/dist/types/dom/replaced-elements/pseudo-elements.d.ts +0 -0
- package/dist/types/dom/replaced-elements/svg-element-container.d.ts +8 -0
- package/dist/types/dom/text-container.d.ts +8 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/invariant.d.ts +1 -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/canvas-renderer.d.ts +53 -0
- package/dist/types/render/canvas/foreignobject-renderer.d.ts +11 -0
- package/dist/types/render/effects.d.ts +38 -0
- package/dist/types/render/font-metrics.d.ts +11 -0
- package/dist/types/render/path.d.ts +13 -0
- package/dist/types/render/renderer.d.ts +7 -0
- package/dist/types/render/stacking-context.d.ts +24 -0
- package/dist/types/render/vector.d.ts +9 -0
- package/package.json +124 -0
- package/publish.sh +8 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,1106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.CanvasRenderer = void 0;
|
|
55
|
+
var stacking_context_1 = require("../stacking-context");
|
|
56
|
+
var color_1 = require("../../css/types/color");
|
|
57
|
+
var path_1 = require("../path");
|
|
58
|
+
var bound_curves_1 = require("../bound-curves");
|
|
59
|
+
var bezier_curve_1 = require("../bezier-curve");
|
|
60
|
+
var vector_1 = require("../vector");
|
|
61
|
+
var image_1 = require("../../css/types/image");
|
|
62
|
+
var border_1 = require("../border");
|
|
63
|
+
var background_1 = require("../background");
|
|
64
|
+
var parser_1 = require("../../css/syntax/parser");
|
|
65
|
+
var text_1 = require("../../css/layout/text");
|
|
66
|
+
var image_element_container_1 = require("../../dom/replaced-elements/image-element-container");
|
|
67
|
+
var box_sizing_1 = require("../box-sizing");
|
|
68
|
+
var canvas_element_container_1 = require("../../dom/replaced-elements/canvas-element-container");
|
|
69
|
+
var svg_element_container_1 = require("../../dom/replaced-elements/svg-element-container");
|
|
70
|
+
var effects_1 = require("../effects");
|
|
71
|
+
var bitwise_1 = require("../../core/bitwise");
|
|
72
|
+
var gradient_1 = require("../../css/types/functions/gradient");
|
|
73
|
+
var length_percentage_1 = require("../../css/types/length-percentage");
|
|
74
|
+
var font_metrics_1 = require("../font-metrics");
|
|
75
|
+
var bounds_1 = require("../../css/layout/bounds");
|
|
76
|
+
var line_height_1 = require("../../css/property-descriptors/line-height");
|
|
77
|
+
var input_element_container_1 = require("../../dom/replaced-elements/input-element-container");
|
|
78
|
+
var textarea_element_container_1 = require("../../dom/elements/textarea-element-container");
|
|
79
|
+
var select_element_container_1 = require("../../dom/elements/select-element-container");
|
|
80
|
+
var iframe_element_container_1 = require("../../dom/replaced-elements/iframe-element-container");
|
|
81
|
+
var renderer_1 = require("../renderer");
|
|
82
|
+
var MASK_OFFSET = 10000;
|
|
83
|
+
var CanvasRenderer = /** @class */ (function (_super) {
|
|
84
|
+
__extends(CanvasRenderer, _super);
|
|
85
|
+
function CanvasRenderer(context, options) {
|
|
86
|
+
var _this = _super.call(this, context, options) || this;
|
|
87
|
+
_this._activeEffects = [];
|
|
88
|
+
_this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
|
|
89
|
+
_this.ctx = _this.canvas.getContext('2d');
|
|
90
|
+
if (!options.canvas) {
|
|
91
|
+
_this.canvas.width = Math.floor(options.width * options.scale);
|
|
92
|
+
_this.canvas.height = Math.floor(options.height * options.scale);
|
|
93
|
+
_this.canvas.style.width = options.width + "px";
|
|
94
|
+
_this.canvas.style.height = options.height + "px";
|
|
95
|
+
}
|
|
96
|
+
_this.fontMetrics = new font_metrics_1.FontMetrics(document);
|
|
97
|
+
_this.ctx.scale(_this.options.scale, _this.options.scale);
|
|
98
|
+
_this.ctx.translate(-options.x, -options.y);
|
|
99
|
+
_this.ctx.textBaseline = 'bottom';
|
|
100
|
+
_this._activeEffects = [];
|
|
101
|
+
_this.context.logger.debug("Canvas renderer initialized (" + options.width + "x" + options.height + ") with scale " + options.scale);
|
|
102
|
+
return _this;
|
|
103
|
+
}
|
|
104
|
+
CanvasRenderer.prototype.applyEffects = function (effects) {
|
|
105
|
+
var _this = this;
|
|
106
|
+
while (this._activeEffects.length) {
|
|
107
|
+
this.popEffect();
|
|
108
|
+
}
|
|
109
|
+
effects.forEach(function (effect) { return _this.applyEffect(effect); });
|
|
110
|
+
};
|
|
111
|
+
CanvasRenderer.prototype.applyEffect = function (effect) {
|
|
112
|
+
this.ctx.save();
|
|
113
|
+
if (effects_1.isOpacityEffect(effect)) {
|
|
114
|
+
this.ctx.globalAlpha = effect.opacity;
|
|
115
|
+
}
|
|
116
|
+
if (effects_1.isTransformEffect(effect)) {
|
|
117
|
+
this.ctx.translate(effect.offsetX, effect.offsetY);
|
|
118
|
+
this.ctx.transform(effect.matrix[0], effect.matrix[1], effect.matrix[2], effect.matrix[3], effect.matrix[4], effect.matrix[5]);
|
|
119
|
+
this.ctx.translate(-effect.offsetX, -effect.offsetY);
|
|
120
|
+
}
|
|
121
|
+
if (effects_1.isClipEffect(effect)) {
|
|
122
|
+
this.path(effect.path);
|
|
123
|
+
this.ctx.clip();
|
|
124
|
+
}
|
|
125
|
+
this._activeEffects.push(effect);
|
|
126
|
+
};
|
|
127
|
+
CanvasRenderer.prototype.popEffect = function () {
|
|
128
|
+
this._activeEffects.pop();
|
|
129
|
+
this.ctx.restore();
|
|
130
|
+
};
|
|
131
|
+
CanvasRenderer.prototype.renderStack = function (stack) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
+
var styles;
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
switch (_a.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
styles = stack.element.container.styles;
|
|
138
|
+
if (!styles.isVisible()) return [3 /*break*/, 2];
|
|
139
|
+
return [4 /*yield*/, this.renderStackContent(stack)];
|
|
140
|
+
case 1:
|
|
141
|
+
_a.sent();
|
|
142
|
+
_a.label = 2;
|
|
143
|
+
case 2: return [2 /*return*/];
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
CanvasRenderer.prototype.renderNode = function (paint) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
if (bitwise_1.contains(paint.container.flags, 16 /* DEBUG_RENDER */)) {
|
|
154
|
+
debugger;
|
|
155
|
+
}
|
|
156
|
+
if (!paint.container.styles.isVisible()) return [3 /*break*/, 3];
|
|
157
|
+
return [4 /*yield*/, this.renderNodeBackgroundAndBorders(paint)];
|
|
158
|
+
case 1:
|
|
159
|
+
_a.sent();
|
|
160
|
+
return [4 /*yield*/, this.renderNodeContent(paint)];
|
|
161
|
+
case 2:
|
|
162
|
+
_a.sent();
|
|
163
|
+
_a.label = 3;
|
|
164
|
+
case 3: return [2 /*return*/];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
CanvasRenderer.prototype.renderTextWithLetterSpacing = function (text, letterSpacing, baseline) {
|
|
170
|
+
var _this = this;
|
|
171
|
+
if (letterSpacing === 0) {
|
|
172
|
+
this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
var letters = text_1.segmentGraphemes(text.text);
|
|
176
|
+
letters.reduce(function (left, letter) {
|
|
177
|
+
_this.ctx.fillText(letter, left, text.bounds.top + baseline);
|
|
178
|
+
return left + _this.ctx.measureText(letter).width;
|
|
179
|
+
}, text.bounds.left);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
CanvasRenderer.prototype.createFontStyle = function (styles) {
|
|
183
|
+
var fontVariant = styles.fontVariant
|
|
184
|
+
.filter(function (variant) { return variant === 'normal' || variant === 'small-caps'; })
|
|
185
|
+
.join('');
|
|
186
|
+
var fontFamily = fixIOSSystemFonts(styles.fontFamily).join(', ');
|
|
187
|
+
var fontSize = parser_1.isDimensionToken(styles.fontSize)
|
|
188
|
+
? "" + styles.fontSize.number + styles.fontSize.unit
|
|
189
|
+
: styles.fontSize.number + "px";
|
|
190
|
+
return [
|
|
191
|
+
[styles.fontStyle, fontVariant, styles.fontWeight, fontSize, fontFamily].join(' '),
|
|
192
|
+
fontFamily,
|
|
193
|
+
fontSize
|
|
194
|
+
];
|
|
195
|
+
};
|
|
196
|
+
CanvasRenderer.prototype.renderTextNode = function (text, styles) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
+
var _a, font, fontFamily, fontSize, _b, baseline, middle, paintOrder;
|
|
199
|
+
var _this = this;
|
|
200
|
+
return __generator(this, function (_c) {
|
|
201
|
+
_a = this.createFontStyle(styles), font = _a[0], fontFamily = _a[1], fontSize = _a[2];
|
|
202
|
+
this.ctx.font = font;
|
|
203
|
+
this.ctx.direction = styles.direction === 1 /* RTL */ ? 'rtl' : 'ltr';
|
|
204
|
+
this.ctx.textAlign = 'left';
|
|
205
|
+
this.ctx.textBaseline = 'alphabetic';
|
|
206
|
+
_b = this.fontMetrics.getMetrics(fontFamily, fontSize), baseline = _b.baseline, middle = _b.middle;
|
|
207
|
+
paintOrder = styles.paintOrder;
|
|
208
|
+
text.textBounds.forEach(function (text) {
|
|
209
|
+
paintOrder.forEach(function (paintOrderLayer) {
|
|
210
|
+
switch (paintOrderLayer) {
|
|
211
|
+
case 0 /* FILL */:
|
|
212
|
+
_this.ctx.fillStyle = color_1.asString(styles.color);
|
|
213
|
+
_this.renderTextWithLetterSpacing(text, styles.letterSpacing, baseline);
|
|
214
|
+
var textShadows = styles.textShadow;
|
|
215
|
+
if (textShadows.length && text.text.trim().length) {
|
|
216
|
+
textShadows
|
|
217
|
+
.slice(0)
|
|
218
|
+
.reverse()
|
|
219
|
+
.forEach(function (textShadow) {
|
|
220
|
+
_this.ctx.shadowColor = color_1.asString(textShadow.color);
|
|
221
|
+
_this.ctx.shadowOffsetX = textShadow.offsetX.number * _this.options.scale;
|
|
222
|
+
_this.ctx.shadowOffsetY = textShadow.offsetY.number * _this.options.scale;
|
|
223
|
+
_this.ctx.shadowBlur = textShadow.blur.number;
|
|
224
|
+
_this.renderTextWithLetterSpacing(text, styles.letterSpacing, baseline);
|
|
225
|
+
});
|
|
226
|
+
_this.ctx.shadowColor = '';
|
|
227
|
+
_this.ctx.shadowOffsetX = 0;
|
|
228
|
+
_this.ctx.shadowOffsetY = 0;
|
|
229
|
+
_this.ctx.shadowBlur = 0;
|
|
230
|
+
}
|
|
231
|
+
if (styles.textDecorationLine.length) {
|
|
232
|
+
_this.ctx.fillStyle = color_1.asString(styles.textDecorationColor || styles.color);
|
|
233
|
+
styles.textDecorationLine.forEach(function (textDecorationLine) {
|
|
234
|
+
switch (textDecorationLine) {
|
|
235
|
+
case 1 /* UNDERLINE */:
|
|
236
|
+
// Draws a line at the baseline of the font
|
|
237
|
+
// TODO As some browsers display the line as more than 1px if the font-size is big,
|
|
238
|
+
// need to take that into account both in position and size
|
|
239
|
+
_this.ctx.fillRect(text.bounds.left, Math.round(text.bounds.top + baseline), text.bounds.width, 1);
|
|
240
|
+
break;
|
|
241
|
+
case 2 /* OVERLINE */:
|
|
242
|
+
_this.ctx.fillRect(text.bounds.left, Math.round(text.bounds.top), text.bounds.width, 1);
|
|
243
|
+
break;
|
|
244
|
+
case 3 /* LINE_THROUGH */:
|
|
245
|
+
// TODO try and find exact position for line-through
|
|
246
|
+
_this.ctx.fillRect(text.bounds.left, Math.ceil(text.bounds.top + middle), text.bounds.width, 1);
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
break;
|
|
252
|
+
case 1 /* STROKE */:
|
|
253
|
+
if (styles.webkitTextStrokeWidth && text.text.trim().length) {
|
|
254
|
+
_this.ctx.strokeStyle = color_1.asString(styles.webkitTextStrokeColor);
|
|
255
|
+
_this.ctx.lineWidth = styles.webkitTextStrokeWidth;
|
|
256
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
257
|
+
_this.ctx.lineJoin = !!window.chrome ? 'miter' : 'round';
|
|
258
|
+
_this.ctx.strokeText(text.text, text.bounds.left, text.bounds.top + baseline);
|
|
259
|
+
}
|
|
260
|
+
_this.ctx.strokeStyle = '';
|
|
261
|
+
_this.ctx.lineWidth = 0;
|
|
262
|
+
_this.ctx.lineJoin = 'miter';
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
return [2 /*return*/];
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
CanvasRenderer.prototype.renderReplacedElement = function (container, curves, image) {
|
|
272
|
+
var intrinsicWidth = image.naturalWidth || container.intrinsicWidth;
|
|
273
|
+
var intrinsicHeight = image.naturalHeight || container.intrinsicHeight;
|
|
274
|
+
if (image && intrinsicWidth > 0 && intrinsicHeight > 0) {
|
|
275
|
+
var box = box_sizing_1.contentBox(container);
|
|
276
|
+
var path = bound_curves_1.calculatePaddingBoxPath(curves);
|
|
277
|
+
this.path(path);
|
|
278
|
+
this.ctx.save();
|
|
279
|
+
this.ctx.clip();
|
|
280
|
+
var sx = 0, sy = 0, sw = intrinsicWidth, sh = intrinsicHeight, dx = box.left, dy = box.top, dw = box.width, dh = box.height;
|
|
281
|
+
var objectFit = container.styles.objectFit;
|
|
282
|
+
var boxRatio = dw / dh;
|
|
283
|
+
var imgRatio = sw / sh;
|
|
284
|
+
if (objectFit === 2 /* CONTAIN */) {
|
|
285
|
+
if (imgRatio > boxRatio) {
|
|
286
|
+
dh = dw / imgRatio;
|
|
287
|
+
dy += (box.height - dh) / 2;
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
dw = dh * imgRatio;
|
|
291
|
+
dx += (box.width - dw) / 2;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else if (objectFit === 4 /* COVER */) {
|
|
295
|
+
if (imgRatio > boxRatio) {
|
|
296
|
+
sw = sh * boxRatio;
|
|
297
|
+
sx += (intrinsicWidth - sw) / 2;
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
sh = sw / boxRatio;
|
|
301
|
+
sy += (intrinsicHeight - sh) / 2;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
else if (objectFit === 8 /* NONE */) {
|
|
305
|
+
if (sw > dw) {
|
|
306
|
+
sx += (sw - dw) / 2;
|
|
307
|
+
sw = dw;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
dx += (dw - sw) / 2;
|
|
311
|
+
dw = sw;
|
|
312
|
+
}
|
|
313
|
+
if (sh > dh) {
|
|
314
|
+
sy += (sh - dh) / 2;
|
|
315
|
+
sh = dh;
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
dy += (dh - sh) / 2;
|
|
319
|
+
dh = sh;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
else if (objectFit === 16 /* SCALE_DOWN */) {
|
|
323
|
+
var containW = imgRatio > boxRatio ? dw : dh * imgRatio;
|
|
324
|
+
var noneW = sw > dw ? sw : dw;
|
|
325
|
+
if (containW < noneW) {
|
|
326
|
+
if (imgRatio > boxRatio) {
|
|
327
|
+
dh = dw / imgRatio;
|
|
328
|
+
dy += (box.height - dh) / 2;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
dw = dh * imgRatio;
|
|
332
|
+
dx += (box.width - dw) / 2;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
if (sw > dw) {
|
|
337
|
+
sx += (sw - dw) / 2;
|
|
338
|
+
sw = dw;
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
dx += (dw - sw) / 2;
|
|
342
|
+
dw = sw;
|
|
343
|
+
}
|
|
344
|
+
if (sh > dh) {
|
|
345
|
+
sy += (sh - dh) / 2;
|
|
346
|
+
sh = dh;
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
dy += (dh - sh) / 2;
|
|
350
|
+
dh = sh;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
this.ctx.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh);
|
|
355
|
+
this.ctx.restore();
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
CanvasRenderer.prototype.renderNodeContent = function (paint) {
|
|
359
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
360
|
+
var container, curves, styles, _i, _a, child, image, e_1, image, e_2, iframeRenderer, canvas, size, _b, fontFamily, fontSize, baseline, bounds, x, textBounds, img, image, url, e_3, fontFamily, bounds;
|
|
361
|
+
return __generator(this, function (_c) {
|
|
362
|
+
switch (_c.label) {
|
|
363
|
+
case 0:
|
|
364
|
+
this.applyEffects(paint.getEffects(4 /* CONTENT */));
|
|
365
|
+
container = paint.container;
|
|
366
|
+
curves = paint.curves;
|
|
367
|
+
styles = container.styles;
|
|
368
|
+
_i = 0, _a = container.textNodes;
|
|
369
|
+
_c.label = 1;
|
|
370
|
+
case 1:
|
|
371
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
372
|
+
child = _a[_i];
|
|
373
|
+
return [4 /*yield*/, this.renderTextNode(child, styles)];
|
|
374
|
+
case 2:
|
|
375
|
+
_c.sent();
|
|
376
|
+
_c.label = 3;
|
|
377
|
+
case 3:
|
|
378
|
+
_i++;
|
|
379
|
+
return [3 /*break*/, 1];
|
|
380
|
+
case 4:
|
|
381
|
+
if (!(container instanceof image_element_container_1.ImageElementContainer)) return [3 /*break*/, 8];
|
|
382
|
+
_c.label = 5;
|
|
383
|
+
case 5:
|
|
384
|
+
_c.trys.push([5, 7, , 8]);
|
|
385
|
+
return [4 /*yield*/, this.context.cache.match(container.src)];
|
|
386
|
+
case 6:
|
|
387
|
+
image = _c.sent();
|
|
388
|
+
this.renderReplacedElement(container, curves, image);
|
|
389
|
+
return [3 /*break*/, 8];
|
|
390
|
+
case 7:
|
|
391
|
+
e_1 = _c.sent();
|
|
392
|
+
this.context.logger.error("Error loading image " + container.src);
|
|
393
|
+
return [3 /*break*/, 8];
|
|
394
|
+
case 8:
|
|
395
|
+
if (container instanceof canvas_element_container_1.CanvasElementContainer) {
|
|
396
|
+
this.renderReplacedElement(container, curves, container.canvas);
|
|
397
|
+
}
|
|
398
|
+
if (!(container instanceof svg_element_container_1.SVGElementContainer)) return [3 /*break*/, 12];
|
|
399
|
+
_c.label = 9;
|
|
400
|
+
case 9:
|
|
401
|
+
_c.trys.push([9, 11, , 12]);
|
|
402
|
+
return [4 /*yield*/, this.context.cache.match(container.svg)];
|
|
403
|
+
case 10:
|
|
404
|
+
image = _c.sent();
|
|
405
|
+
this.renderReplacedElement(container, curves, image);
|
|
406
|
+
return [3 /*break*/, 12];
|
|
407
|
+
case 11:
|
|
408
|
+
e_2 = _c.sent();
|
|
409
|
+
this.context.logger.error("Error loading svg " + container.svg.substring(0, 255));
|
|
410
|
+
return [3 /*break*/, 12];
|
|
411
|
+
case 12:
|
|
412
|
+
if (!(container instanceof iframe_element_container_1.IFrameElementContainer && container.tree)) return [3 /*break*/, 14];
|
|
413
|
+
iframeRenderer = new CanvasRenderer(this.context, {
|
|
414
|
+
scale: this.options.scale,
|
|
415
|
+
backgroundColor: container.backgroundColor,
|
|
416
|
+
x: 0,
|
|
417
|
+
y: 0,
|
|
418
|
+
width: container.width,
|
|
419
|
+
height: container.height
|
|
420
|
+
});
|
|
421
|
+
return [4 /*yield*/, iframeRenderer.render(container.tree)];
|
|
422
|
+
case 13:
|
|
423
|
+
canvas = _c.sent();
|
|
424
|
+
if (container.width && container.height) {
|
|
425
|
+
this.ctx.drawImage(canvas, 0, 0, container.width, container.height, container.bounds.left, container.bounds.top, container.bounds.width, container.bounds.height);
|
|
426
|
+
}
|
|
427
|
+
_c.label = 14;
|
|
428
|
+
case 14:
|
|
429
|
+
if (container instanceof input_element_container_1.InputElementContainer) {
|
|
430
|
+
size = Math.min(container.bounds.width, container.bounds.height);
|
|
431
|
+
if (container.type === input_element_container_1.CHECKBOX) {
|
|
432
|
+
if (container.checked) {
|
|
433
|
+
this.ctx.save();
|
|
434
|
+
this.path([
|
|
435
|
+
new vector_1.Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79),
|
|
436
|
+
new vector_1.Vector(container.bounds.left + size * 0.16, container.bounds.top + size * 0.5549),
|
|
437
|
+
new vector_1.Vector(container.bounds.left + size * 0.27347, container.bounds.top + size * 0.44071),
|
|
438
|
+
new vector_1.Vector(container.bounds.left + size * 0.39694, container.bounds.top + size * 0.5649),
|
|
439
|
+
new vector_1.Vector(container.bounds.left + size * 0.72983, container.bounds.top + size * 0.23),
|
|
440
|
+
new vector_1.Vector(container.bounds.left + size * 0.84, container.bounds.top + size * 0.34085),
|
|
441
|
+
new vector_1.Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79)
|
|
442
|
+
]);
|
|
443
|
+
this.ctx.fillStyle = color_1.asString(input_element_container_1.INPUT_COLOR);
|
|
444
|
+
this.ctx.fill();
|
|
445
|
+
this.ctx.restore();
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
else if (container.type === input_element_container_1.RADIO) {
|
|
449
|
+
if (container.checked) {
|
|
450
|
+
this.ctx.save();
|
|
451
|
+
this.ctx.beginPath();
|
|
452
|
+
this.ctx.arc(container.bounds.left + size / 2, container.bounds.top + size / 2, size / 4, 0, Math.PI * 2, true);
|
|
453
|
+
this.ctx.fillStyle = color_1.asString(input_element_container_1.INPUT_COLOR);
|
|
454
|
+
this.ctx.fill();
|
|
455
|
+
this.ctx.restore();
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
if (isTextInputElement(container) && container.value.length) {
|
|
460
|
+
_b = this.createFontStyle(styles), fontFamily = _b[0], fontSize = _b[1];
|
|
461
|
+
baseline = this.fontMetrics.getMetrics(fontFamily, fontSize).baseline;
|
|
462
|
+
this.ctx.font = fontFamily;
|
|
463
|
+
this.ctx.fillStyle = color_1.asString(styles.color);
|
|
464
|
+
this.ctx.textBaseline = 'alphabetic';
|
|
465
|
+
this.ctx.textAlign = canvasTextAlign(container.styles.textAlign);
|
|
466
|
+
bounds = box_sizing_1.contentBox(container);
|
|
467
|
+
x = 0;
|
|
468
|
+
switch (container.styles.textAlign) {
|
|
469
|
+
case 1 /* CENTER */:
|
|
470
|
+
x += bounds.width / 2;
|
|
471
|
+
break;
|
|
472
|
+
case 2 /* RIGHT */:
|
|
473
|
+
x += bounds.width;
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
textBounds = bounds.add(x, 0, 0, -bounds.height / 2 + 1);
|
|
477
|
+
this.ctx.save();
|
|
478
|
+
this.path([
|
|
479
|
+
new vector_1.Vector(bounds.left, bounds.top),
|
|
480
|
+
new vector_1.Vector(bounds.left + bounds.width, bounds.top),
|
|
481
|
+
new vector_1.Vector(bounds.left + bounds.width, bounds.top + bounds.height),
|
|
482
|
+
new vector_1.Vector(bounds.left, bounds.top + bounds.height)
|
|
483
|
+
]);
|
|
484
|
+
this.ctx.clip();
|
|
485
|
+
this.renderTextWithLetterSpacing(new text_1.TextBounds(container.value, textBounds), styles.letterSpacing, baseline);
|
|
486
|
+
this.ctx.restore();
|
|
487
|
+
this.ctx.textBaseline = 'alphabetic';
|
|
488
|
+
this.ctx.textAlign = 'left';
|
|
489
|
+
}
|
|
490
|
+
if (!bitwise_1.contains(container.styles.display, 2048 /* LIST_ITEM */)) return [3 /*break*/, 20];
|
|
491
|
+
if (!(container.styles.listStyleImage !== null)) return [3 /*break*/, 19];
|
|
492
|
+
img = container.styles.listStyleImage;
|
|
493
|
+
if (!(img.type === 0 /* URL */)) return [3 /*break*/, 18];
|
|
494
|
+
image = void 0;
|
|
495
|
+
url = img.url;
|
|
496
|
+
_c.label = 15;
|
|
497
|
+
case 15:
|
|
498
|
+
_c.trys.push([15, 17, , 18]);
|
|
499
|
+
return [4 /*yield*/, this.context.cache.match(url)];
|
|
500
|
+
case 16:
|
|
501
|
+
image = _c.sent();
|
|
502
|
+
this.ctx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top);
|
|
503
|
+
return [3 /*break*/, 18];
|
|
504
|
+
case 17:
|
|
505
|
+
e_3 = _c.sent();
|
|
506
|
+
this.context.logger.error("Error loading list-style-image " + url);
|
|
507
|
+
return [3 /*break*/, 18];
|
|
508
|
+
case 18: return [3 /*break*/, 20];
|
|
509
|
+
case 19:
|
|
510
|
+
if (paint.listValue && container.styles.listStyleType !== -1 /* NONE */) {
|
|
511
|
+
fontFamily = this.createFontStyle(styles)[0];
|
|
512
|
+
this.ctx.font = fontFamily;
|
|
513
|
+
this.ctx.fillStyle = color_1.asString(styles.color);
|
|
514
|
+
this.ctx.textBaseline = 'middle';
|
|
515
|
+
this.ctx.textAlign = 'right';
|
|
516
|
+
bounds = new bounds_1.Bounds(container.bounds.left, container.bounds.top + length_percentage_1.getAbsoluteValue(container.styles.paddingTop, container.bounds.width), container.bounds.width, line_height_1.computeLineHeight(styles.lineHeight, styles.fontSize.number) / 2 + 1);
|
|
517
|
+
this.renderTextWithLetterSpacing(new text_1.TextBounds(paint.listValue, bounds), styles.letterSpacing, line_height_1.computeLineHeight(styles.lineHeight, styles.fontSize.number) / 2 + 2);
|
|
518
|
+
this.ctx.textBaseline = 'bottom';
|
|
519
|
+
this.ctx.textAlign = 'left';
|
|
520
|
+
}
|
|
521
|
+
_c.label = 20;
|
|
522
|
+
case 20: return [2 /*return*/];
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
};
|
|
527
|
+
CanvasRenderer.prototype.renderStackContent = function (stack) {
|
|
528
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
529
|
+
var _i, _a, child, _b, _c, child, _d, _e, child, _f, _g, child, _h, _j, child, _k, _l, child, _m, _o, child;
|
|
530
|
+
return __generator(this, function (_p) {
|
|
531
|
+
switch (_p.label) {
|
|
532
|
+
case 0:
|
|
533
|
+
if (bitwise_1.contains(stack.element.container.flags, 16 /* DEBUG_RENDER */)) {
|
|
534
|
+
debugger;
|
|
535
|
+
}
|
|
536
|
+
// https://www.w3.org/TR/css-position-3/#painting-order
|
|
537
|
+
// 1. the background and borders of the element forming the stacking context.
|
|
538
|
+
return [4 /*yield*/, this.renderNodeBackgroundAndBorders(stack.element)];
|
|
539
|
+
case 1:
|
|
540
|
+
// https://www.w3.org/TR/css-position-3/#painting-order
|
|
541
|
+
// 1. the background and borders of the element forming the stacking context.
|
|
542
|
+
_p.sent();
|
|
543
|
+
_i = 0, _a = stack.negativeZIndex;
|
|
544
|
+
_p.label = 2;
|
|
545
|
+
case 2:
|
|
546
|
+
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
547
|
+
child = _a[_i];
|
|
548
|
+
return [4 /*yield*/, this.renderStack(child)];
|
|
549
|
+
case 3:
|
|
550
|
+
_p.sent();
|
|
551
|
+
_p.label = 4;
|
|
552
|
+
case 4:
|
|
553
|
+
_i++;
|
|
554
|
+
return [3 /*break*/, 2];
|
|
555
|
+
case 5:
|
|
556
|
+
// 3. For all its in-flow, non-positioned, block-level descendants in tree order:
|
|
557
|
+
return [4 /*yield*/, this.renderNodeContent(stack.element)];
|
|
558
|
+
case 6:
|
|
559
|
+
// 3. For all its in-flow, non-positioned, block-level descendants in tree order:
|
|
560
|
+
_p.sent();
|
|
561
|
+
_b = 0, _c = stack.nonInlineLevel;
|
|
562
|
+
_p.label = 7;
|
|
563
|
+
case 7:
|
|
564
|
+
if (!(_b < _c.length)) return [3 /*break*/, 10];
|
|
565
|
+
child = _c[_b];
|
|
566
|
+
return [4 /*yield*/, this.renderNode(child)];
|
|
567
|
+
case 8:
|
|
568
|
+
_p.sent();
|
|
569
|
+
_p.label = 9;
|
|
570
|
+
case 9:
|
|
571
|
+
_b++;
|
|
572
|
+
return [3 /*break*/, 7];
|
|
573
|
+
case 10:
|
|
574
|
+
_d = 0, _e = stack.nonPositionedFloats;
|
|
575
|
+
_p.label = 11;
|
|
576
|
+
case 11:
|
|
577
|
+
if (!(_d < _e.length)) return [3 /*break*/, 14];
|
|
578
|
+
child = _e[_d];
|
|
579
|
+
return [4 /*yield*/, this.renderStack(child)];
|
|
580
|
+
case 12:
|
|
581
|
+
_p.sent();
|
|
582
|
+
_p.label = 13;
|
|
583
|
+
case 13:
|
|
584
|
+
_d++;
|
|
585
|
+
return [3 /*break*/, 11];
|
|
586
|
+
case 14:
|
|
587
|
+
_f = 0, _g = stack.nonPositionedInlineLevel;
|
|
588
|
+
_p.label = 15;
|
|
589
|
+
case 15:
|
|
590
|
+
if (!(_f < _g.length)) return [3 /*break*/, 18];
|
|
591
|
+
child = _g[_f];
|
|
592
|
+
return [4 /*yield*/, this.renderStack(child)];
|
|
593
|
+
case 16:
|
|
594
|
+
_p.sent();
|
|
595
|
+
_p.label = 17;
|
|
596
|
+
case 17:
|
|
597
|
+
_f++;
|
|
598
|
+
return [3 /*break*/, 15];
|
|
599
|
+
case 18:
|
|
600
|
+
_h = 0, _j = stack.inlineLevel;
|
|
601
|
+
_p.label = 19;
|
|
602
|
+
case 19:
|
|
603
|
+
if (!(_h < _j.length)) return [3 /*break*/, 22];
|
|
604
|
+
child = _j[_h];
|
|
605
|
+
return [4 /*yield*/, this.renderNode(child)];
|
|
606
|
+
case 20:
|
|
607
|
+
_p.sent();
|
|
608
|
+
_p.label = 21;
|
|
609
|
+
case 21:
|
|
610
|
+
_h++;
|
|
611
|
+
return [3 /*break*/, 19];
|
|
612
|
+
case 22:
|
|
613
|
+
_k = 0, _l = stack.zeroOrAutoZIndexOrTransformedOrOpacity;
|
|
614
|
+
_p.label = 23;
|
|
615
|
+
case 23:
|
|
616
|
+
if (!(_k < _l.length)) return [3 /*break*/, 26];
|
|
617
|
+
child = _l[_k];
|
|
618
|
+
return [4 /*yield*/, this.renderStack(child)];
|
|
619
|
+
case 24:
|
|
620
|
+
_p.sent();
|
|
621
|
+
_p.label = 25;
|
|
622
|
+
case 25:
|
|
623
|
+
_k++;
|
|
624
|
+
return [3 /*break*/, 23];
|
|
625
|
+
case 26:
|
|
626
|
+
_m = 0, _o = stack.positiveZIndex;
|
|
627
|
+
_p.label = 27;
|
|
628
|
+
case 27:
|
|
629
|
+
if (!(_m < _o.length)) return [3 /*break*/, 30];
|
|
630
|
+
child = _o[_m];
|
|
631
|
+
return [4 /*yield*/, this.renderStack(child)];
|
|
632
|
+
case 28:
|
|
633
|
+
_p.sent();
|
|
634
|
+
_p.label = 29;
|
|
635
|
+
case 29:
|
|
636
|
+
_m++;
|
|
637
|
+
return [3 /*break*/, 27];
|
|
638
|
+
case 30: return [2 /*return*/];
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
};
|
|
643
|
+
CanvasRenderer.prototype.mask = function (paths) {
|
|
644
|
+
this.ctx.beginPath();
|
|
645
|
+
this.ctx.moveTo(0, 0);
|
|
646
|
+
this.ctx.lineTo(this.canvas.width, 0);
|
|
647
|
+
this.ctx.lineTo(this.canvas.width, this.canvas.height);
|
|
648
|
+
this.ctx.lineTo(0, this.canvas.height);
|
|
649
|
+
this.ctx.lineTo(0, 0);
|
|
650
|
+
this.formatPath(paths.slice(0).reverse());
|
|
651
|
+
this.ctx.closePath();
|
|
652
|
+
};
|
|
653
|
+
CanvasRenderer.prototype.path = function (paths) {
|
|
654
|
+
this.ctx.beginPath();
|
|
655
|
+
this.formatPath(paths);
|
|
656
|
+
this.ctx.closePath();
|
|
657
|
+
};
|
|
658
|
+
CanvasRenderer.prototype.formatPath = function (paths) {
|
|
659
|
+
var _this = this;
|
|
660
|
+
paths.forEach(function (point, index) {
|
|
661
|
+
var start = bezier_curve_1.isBezierCurve(point) ? point.start : point;
|
|
662
|
+
if (index === 0) {
|
|
663
|
+
_this.ctx.moveTo(start.x, start.y);
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
_this.ctx.lineTo(start.x, start.y);
|
|
667
|
+
}
|
|
668
|
+
if (bezier_curve_1.isBezierCurve(point)) {
|
|
669
|
+
_this.ctx.bezierCurveTo(point.startControl.x, point.startControl.y, point.endControl.x, point.endControl.y, point.end.x, point.end.y);
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
};
|
|
673
|
+
CanvasRenderer.prototype.renderRepeat = function (path, pattern, offsetX, offsetY) {
|
|
674
|
+
this.path(path);
|
|
675
|
+
this.ctx.fillStyle = pattern;
|
|
676
|
+
this.ctx.translate(offsetX, offsetY);
|
|
677
|
+
this.ctx.fill();
|
|
678
|
+
this.ctx.translate(-offsetX, -offsetY);
|
|
679
|
+
};
|
|
680
|
+
CanvasRenderer.prototype.resizeImage = function (image, width, height) {
|
|
681
|
+
var _a;
|
|
682
|
+
if (image.width === width && image.height === height) {
|
|
683
|
+
return image;
|
|
684
|
+
}
|
|
685
|
+
var ownerDocument = (_a = this.canvas.ownerDocument) !== null && _a !== void 0 ? _a : document;
|
|
686
|
+
var canvas = ownerDocument.createElement('canvas');
|
|
687
|
+
canvas.width = Math.max(1, width);
|
|
688
|
+
canvas.height = Math.max(1, height);
|
|
689
|
+
var ctx = canvas.getContext('2d');
|
|
690
|
+
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
|
|
691
|
+
return canvas;
|
|
692
|
+
};
|
|
693
|
+
CanvasRenderer.prototype.renderBackgroundImage = function (container) {
|
|
694
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
695
|
+
var index, _loop_1, this_1, _i, _a, backgroundImage;
|
|
696
|
+
return __generator(this, function (_b) {
|
|
697
|
+
switch (_b.label) {
|
|
698
|
+
case 0:
|
|
699
|
+
index = container.styles.backgroundImage.length - 1;
|
|
700
|
+
_loop_1 = function (backgroundImage) {
|
|
701
|
+
var image, url, e_4, _c, path, x, y, width, height, pattern, _d, path, x, y, width, height, _e, lineLength, x0, x1, y0, y1, canvas, ctx, gradient_2, pattern, _f, path, left, top_1, width, height, position, x, y, _g, rx, ry, radialGradient_1, midX, midY, f, invF;
|
|
702
|
+
return __generator(this, function (_h) {
|
|
703
|
+
switch (_h.label) {
|
|
704
|
+
case 0:
|
|
705
|
+
if (!(backgroundImage.type === 0 /* URL */)) return [3 /*break*/, 5];
|
|
706
|
+
image = void 0;
|
|
707
|
+
url = backgroundImage.url;
|
|
708
|
+
_h.label = 1;
|
|
709
|
+
case 1:
|
|
710
|
+
_h.trys.push([1, 3, , 4]);
|
|
711
|
+
return [4 /*yield*/, this_1.context.cache.match(url)];
|
|
712
|
+
case 2:
|
|
713
|
+
image = _h.sent();
|
|
714
|
+
return [3 /*break*/, 4];
|
|
715
|
+
case 3:
|
|
716
|
+
e_4 = _h.sent();
|
|
717
|
+
this_1.context.logger.error("Error loading background-image " + url);
|
|
718
|
+
return [3 /*break*/, 4];
|
|
719
|
+
case 4:
|
|
720
|
+
if (image) {
|
|
721
|
+
_c = background_1.calculateBackgroundRendering(container, index, [
|
|
722
|
+
image.width,
|
|
723
|
+
image.height,
|
|
724
|
+
image.width / image.height
|
|
725
|
+
]), path = _c[0], x = _c[1], y = _c[2], width = _c[3], height = _c[4];
|
|
726
|
+
pattern = this_1.ctx.createPattern(this_1.resizeImage(image, width, height), 'repeat');
|
|
727
|
+
this_1.renderRepeat(path, pattern, x, y);
|
|
728
|
+
}
|
|
729
|
+
return [3 /*break*/, 6];
|
|
730
|
+
case 5:
|
|
731
|
+
if (image_1.isLinearGradient(backgroundImage)) {
|
|
732
|
+
_d = background_1.calculateBackgroundRendering(container, index, [null, null, null]), path = _d[0], x = _d[1], y = _d[2], width = _d[3], height = _d[4];
|
|
733
|
+
_e = gradient_1.calculateGradientDirection(backgroundImage.angle, width, height), lineLength = _e[0], x0 = _e[1], x1 = _e[2], y0 = _e[3], y1 = _e[4];
|
|
734
|
+
canvas = document.createElement('canvas');
|
|
735
|
+
canvas.width = width;
|
|
736
|
+
canvas.height = height;
|
|
737
|
+
ctx = canvas.getContext('2d');
|
|
738
|
+
gradient_2 = ctx.createLinearGradient(x0, y0, x1, y1);
|
|
739
|
+
gradient_1.processColorStops(backgroundImage.stops, lineLength).forEach(function (colorStop) {
|
|
740
|
+
return gradient_2.addColorStop(colorStop.stop, color_1.asString(colorStop.color));
|
|
741
|
+
});
|
|
742
|
+
ctx.fillStyle = gradient_2;
|
|
743
|
+
ctx.fillRect(0, 0, width, height);
|
|
744
|
+
if (width > 0 && height > 0) {
|
|
745
|
+
pattern = this_1.ctx.createPattern(canvas, 'repeat');
|
|
746
|
+
this_1.renderRepeat(path, pattern, x, y);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
else if (image_1.isRadialGradient(backgroundImage)) {
|
|
750
|
+
_f = background_1.calculateBackgroundRendering(container, index, [
|
|
751
|
+
null,
|
|
752
|
+
null,
|
|
753
|
+
null
|
|
754
|
+
]), path = _f[0], left = _f[1], top_1 = _f[2], width = _f[3], height = _f[4];
|
|
755
|
+
position = backgroundImage.position.length === 0 ? [length_percentage_1.FIFTY_PERCENT] : backgroundImage.position;
|
|
756
|
+
x = length_percentage_1.getAbsoluteValue(position[0], width);
|
|
757
|
+
y = length_percentage_1.getAbsoluteValue(position[position.length - 1], height);
|
|
758
|
+
_g = gradient_1.calculateRadius(backgroundImage, x, y, width, height), rx = _g[0], ry = _g[1];
|
|
759
|
+
if (rx > 0 && ry > 0) {
|
|
760
|
+
radialGradient_1 = this_1.ctx.createRadialGradient(left + x, top_1 + y, 0, left + x, top_1 + y, rx);
|
|
761
|
+
gradient_1.processColorStops(backgroundImage.stops, rx * 2).forEach(function (colorStop) {
|
|
762
|
+
return radialGradient_1.addColorStop(colorStop.stop, color_1.asString(colorStop.color));
|
|
763
|
+
});
|
|
764
|
+
this_1.path(path);
|
|
765
|
+
this_1.ctx.fillStyle = radialGradient_1;
|
|
766
|
+
if (rx !== ry) {
|
|
767
|
+
midX = container.bounds.left + 0.5 * container.bounds.width;
|
|
768
|
+
midY = container.bounds.top + 0.5 * container.bounds.height;
|
|
769
|
+
f = ry / rx;
|
|
770
|
+
invF = 1 / f;
|
|
771
|
+
this_1.ctx.save();
|
|
772
|
+
this_1.ctx.translate(midX, midY);
|
|
773
|
+
this_1.ctx.transform(1, 0, 0, f, 0, 0);
|
|
774
|
+
this_1.ctx.translate(-midX, -midY);
|
|
775
|
+
this_1.ctx.fillRect(left, invF * (top_1 - midY) + midY, width, height * invF);
|
|
776
|
+
this_1.ctx.restore();
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
this_1.ctx.fill();
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
_h.label = 6;
|
|
784
|
+
case 6:
|
|
785
|
+
index--;
|
|
786
|
+
return [2 /*return*/];
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
};
|
|
790
|
+
this_1 = this;
|
|
791
|
+
_i = 0, _a = container.styles.backgroundImage.slice(0).reverse();
|
|
792
|
+
_b.label = 1;
|
|
793
|
+
case 1:
|
|
794
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
795
|
+
backgroundImage = _a[_i];
|
|
796
|
+
return [5 /*yield**/, _loop_1(backgroundImage)];
|
|
797
|
+
case 2:
|
|
798
|
+
_b.sent();
|
|
799
|
+
_b.label = 3;
|
|
800
|
+
case 3:
|
|
801
|
+
_i++;
|
|
802
|
+
return [3 /*break*/, 1];
|
|
803
|
+
case 4: return [2 /*return*/];
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
});
|
|
807
|
+
};
|
|
808
|
+
CanvasRenderer.prototype.renderSolidBorder = function (color, side, curvePoints) {
|
|
809
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
810
|
+
return __generator(this, function (_a) {
|
|
811
|
+
this.path(border_1.parsePathForBorder(curvePoints, side));
|
|
812
|
+
this.ctx.fillStyle = color_1.asString(color);
|
|
813
|
+
this.ctx.fill();
|
|
814
|
+
return [2 /*return*/];
|
|
815
|
+
});
|
|
816
|
+
});
|
|
817
|
+
};
|
|
818
|
+
CanvasRenderer.prototype.renderDoubleBorder = function (color, width, side, curvePoints) {
|
|
819
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
820
|
+
var outerPaths, innerPaths;
|
|
821
|
+
return __generator(this, function (_a) {
|
|
822
|
+
switch (_a.label) {
|
|
823
|
+
case 0:
|
|
824
|
+
if (!(width < 3)) return [3 /*break*/, 2];
|
|
825
|
+
return [4 /*yield*/, this.renderSolidBorder(color, side, curvePoints)];
|
|
826
|
+
case 1:
|
|
827
|
+
_a.sent();
|
|
828
|
+
return [2 /*return*/];
|
|
829
|
+
case 2:
|
|
830
|
+
outerPaths = border_1.parsePathForBorderDoubleOuter(curvePoints, side);
|
|
831
|
+
this.path(outerPaths);
|
|
832
|
+
this.ctx.fillStyle = color_1.asString(color);
|
|
833
|
+
this.ctx.fill();
|
|
834
|
+
innerPaths = border_1.parsePathForBorderDoubleInner(curvePoints, side);
|
|
835
|
+
this.path(innerPaths);
|
|
836
|
+
this.ctx.fill();
|
|
837
|
+
return [2 /*return*/];
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
});
|
|
841
|
+
};
|
|
842
|
+
CanvasRenderer.prototype.renderNodeBackgroundAndBorders = function (paint) {
|
|
843
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
844
|
+
var styles, hasBackground, borders, backgroundPaintingArea, side, _i, borders_1, border;
|
|
845
|
+
var _this = this;
|
|
846
|
+
return __generator(this, function (_a) {
|
|
847
|
+
switch (_a.label) {
|
|
848
|
+
case 0:
|
|
849
|
+
this.applyEffects(paint.getEffects(2 /* BACKGROUND_BORDERS */));
|
|
850
|
+
styles = paint.container.styles;
|
|
851
|
+
hasBackground = !color_1.isTransparent(styles.backgroundColor) || styles.backgroundImage.length;
|
|
852
|
+
borders = [
|
|
853
|
+
{ style: styles.borderTopStyle, color: styles.borderTopColor, width: styles.borderTopWidth },
|
|
854
|
+
{ style: styles.borderRightStyle, color: styles.borderRightColor, width: styles.borderRightWidth },
|
|
855
|
+
{ style: styles.borderBottomStyle, color: styles.borderBottomColor, width: styles.borderBottomWidth },
|
|
856
|
+
{ style: styles.borderLeftStyle, color: styles.borderLeftColor, width: styles.borderLeftWidth }
|
|
857
|
+
];
|
|
858
|
+
backgroundPaintingArea = calculateBackgroundCurvedPaintingArea(background_1.getBackgroundValueForIndex(styles.backgroundClip, 0), paint.curves);
|
|
859
|
+
if (!(hasBackground || styles.boxShadow.length)) return [3 /*break*/, 2];
|
|
860
|
+
this.ctx.save();
|
|
861
|
+
this.path(backgroundPaintingArea);
|
|
862
|
+
this.ctx.clip();
|
|
863
|
+
if (!color_1.isTransparent(styles.backgroundColor)) {
|
|
864
|
+
this.ctx.fillStyle = color_1.asString(styles.backgroundColor);
|
|
865
|
+
this.ctx.fill();
|
|
866
|
+
}
|
|
867
|
+
return [4 /*yield*/, this.renderBackgroundImage(paint.container)];
|
|
868
|
+
case 1:
|
|
869
|
+
_a.sent();
|
|
870
|
+
this.ctx.restore();
|
|
871
|
+
styles.boxShadow
|
|
872
|
+
.slice(0)
|
|
873
|
+
.reverse()
|
|
874
|
+
.forEach(function (shadow) {
|
|
875
|
+
_this.ctx.save();
|
|
876
|
+
var borderBoxArea = bound_curves_1.calculateBorderBoxPath(paint.curves);
|
|
877
|
+
var maskOffset = shadow.inset ? 0 : MASK_OFFSET;
|
|
878
|
+
var shadowPaintingArea = path_1.transformPath(borderBoxArea, -maskOffset + (shadow.inset ? 1 : -1) * shadow.spread.number, (shadow.inset ? 1 : -1) * shadow.spread.number, shadow.spread.number * (shadow.inset ? -2 : 2), shadow.spread.number * (shadow.inset ? -2 : 2));
|
|
879
|
+
if (shadow.inset) {
|
|
880
|
+
_this.path(borderBoxArea);
|
|
881
|
+
_this.ctx.clip();
|
|
882
|
+
_this.mask(shadowPaintingArea);
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
_this.mask(borderBoxArea);
|
|
886
|
+
_this.ctx.clip();
|
|
887
|
+
_this.path(shadowPaintingArea);
|
|
888
|
+
}
|
|
889
|
+
_this.ctx.shadowOffsetX = shadow.offsetX.number + maskOffset;
|
|
890
|
+
_this.ctx.shadowOffsetY = shadow.offsetY.number;
|
|
891
|
+
_this.ctx.shadowColor = color_1.asString(shadow.color);
|
|
892
|
+
_this.ctx.shadowBlur = shadow.blur.number;
|
|
893
|
+
_this.ctx.fillStyle = shadow.inset ? color_1.asString(shadow.color) : 'rgba(0,0,0,1)';
|
|
894
|
+
_this.ctx.fill();
|
|
895
|
+
_this.ctx.restore();
|
|
896
|
+
});
|
|
897
|
+
_a.label = 2;
|
|
898
|
+
case 2:
|
|
899
|
+
side = 0;
|
|
900
|
+
_i = 0, borders_1 = borders;
|
|
901
|
+
_a.label = 3;
|
|
902
|
+
case 3:
|
|
903
|
+
if (!(_i < borders_1.length)) return [3 /*break*/, 13];
|
|
904
|
+
border = borders_1[_i];
|
|
905
|
+
if (!(border.style !== 0 /* NONE */ && !color_1.isTransparent(border.color) && border.width > 0)) return [3 /*break*/, 11];
|
|
906
|
+
if (!(border.style === 2 /* DASHED */)) return [3 /*break*/, 5];
|
|
907
|
+
return [4 /*yield*/, this.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 2 /* DASHED */)];
|
|
908
|
+
case 4:
|
|
909
|
+
_a.sent();
|
|
910
|
+
return [3 /*break*/, 11];
|
|
911
|
+
case 5:
|
|
912
|
+
if (!(border.style === 3 /* DOTTED */)) return [3 /*break*/, 7];
|
|
913
|
+
return [4 /*yield*/, this.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 3 /* DOTTED */)];
|
|
914
|
+
case 6:
|
|
915
|
+
_a.sent();
|
|
916
|
+
return [3 /*break*/, 11];
|
|
917
|
+
case 7:
|
|
918
|
+
if (!(border.style === 4 /* DOUBLE */)) return [3 /*break*/, 9];
|
|
919
|
+
return [4 /*yield*/, this.renderDoubleBorder(border.color, border.width, side, paint.curves)];
|
|
920
|
+
case 8:
|
|
921
|
+
_a.sent();
|
|
922
|
+
return [3 /*break*/, 11];
|
|
923
|
+
case 9: return [4 /*yield*/, this.renderSolidBorder(border.color, side, paint.curves)];
|
|
924
|
+
case 10:
|
|
925
|
+
_a.sent();
|
|
926
|
+
_a.label = 11;
|
|
927
|
+
case 11:
|
|
928
|
+
side++;
|
|
929
|
+
_a.label = 12;
|
|
930
|
+
case 12:
|
|
931
|
+
_i++;
|
|
932
|
+
return [3 /*break*/, 3];
|
|
933
|
+
case 13: return [2 /*return*/];
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
});
|
|
937
|
+
};
|
|
938
|
+
CanvasRenderer.prototype.renderDashedDottedBorder = function (color, width, side, curvePoints, style) {
|
|
939
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
940
|
+
var strokePaths, boxPaths, startX, startY, endX, endY, length, dashLength, spaceLength, useLineDash, multiplier, numberOfDashes, minSpace, maxSpace, path1, path2, path1, path2;
|
|
941
|
+
return __generator(this, function (_a) {
|
|
942
|
+
this.ctx.save();
|
|
943
|
+
strokePaths = border_1.parsePathForBorderStroke(curvePoints, side);
|
|
944
|
+
boxPaths = border_1.parsePathForBorder(curvePoints, side);
|
|
945
|
+
if (style === 2 /* DASHED */) {
|
|
946
|
+
this.path(boxPaths);
|
|
947
|
+
this.ctx.clip();
|
|
948
|
+
}
|
|
949
|
+
if (bezier_curve_1.isBezierCurve(boxPaths[0])) {
|
|
950
|
+
startX = boxPaths[0].start.x;
|
|
951
|
+
startY = boxPaths[0].start.y;
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
startX = boxPaths[0].x;
|
|
955
|
+
startY = boxPaths[0].y;
|
|
956
|
+
}
|
|
957
|
+
if (bezier_curve_1.isBezierCurve(boxPaths[1])) {
|
|
958
|
+
endX = boxPaths[1].end.x;
|
|
959
|
+
endY = boxPaths[1].end.y;
|
|
960
|
+
}
|
|
961
|
+
else {
|
|
962
|
+
endX = boxPaths[1].x;
|
|
963
|
+
endY = boxPaths[1].y;
|
|
964
|
+
}
|
|
965
|
+
if (side === 0 || side === 2) {
|
|
966
|
+
length = Math.abs(startX - endX);
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
length = Math.abs(startY - endY);
|
|
970
|
+
}
|
|
971
|
+
this.ctx.beginPath();
|
|
972
|
+
if (style === 3 /* DOTTED */) {
|
|
973
|
+
this.formatPath(strokePaths);
|
|
974
|
+
}
|
|
975
|
+
else {
|
|
976
|
+
this.formatPath(boxPaths.slice(0, 2));
|
|
977
|
+
}
|
|
978
|
+
dashLength = width < 3 ? width * 3 : width * 2;
|
|
979
|
+
spaceLength = width < 3 ? width * 2 : width;
|
|
980
|
+
if (style === 3 /* DOTTED */) {
|
|
981
|
+
dashLength = width;
|
|
982
|
+
spaceLength = width;
|
|
983
|
+
}
|
|
984
|
+
useLineDash = true;
|
|
985
|
+
if (length <= dashLength * 2) {
|
|
986
|
+
useLineDash = false;
|
|
987
|
+
}
|
|
988
|
+
else if (length <= dashLength * 2 + spaceLength) {
|
|
989
|
+
multiplier = length / (2 * dashLength + spaceLength);
|
|
990
|
+
dashLength *= multiplier;
|
|
991
|
+
spaceLength *= multiplier;
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
numberOfDashes = Math.floor((length + spaceLength) / (dashLength + spaceLength));
|
|
995
|
+
minSpace = (length - numberOfDashes * dashLength) / (numberOfDashes - 1);
|
|
996
|
+
maxSpace = (length - (numberOfDashes + 1) * dashLength) / numberOfDashes;
|
|
997
|
+
spaceLength =
|
|
998
|
+
maxSpace <= 0 || Math.abs(spaceLength - minSpace) < Math.abs(spaceLength - maxSpace)
|
|
999
|
+
? minSpace
|
|
1000
|
+
: maxSpace;
|
|
1001
|
+
}
|
|
1002
|
+
if (useLineDash) {
|
|
1003
|
+
if (style === 3 /* DOTTED */) {
|
|
1004
|
+
this.ctx.setLineDash([0, dashLength + spaceLength]);
|
|
1005
|
+
}
|
|
1006
|
+
else {
|
|
1007
|
+
this.ctx.setLineDash([dashLength, spaceLength]);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
if (style === 3 /* DOTTED */) {
|
|
1011
|
+
this.ctx.lineCap = 'round';
|
|
1012
|
+
this.ctx.lineWidth = width;
|
|
1013
|
+
}
|
|
1014
|
+
else {
|
|
1015
|
+
this.ctx.lineWidth = width * 2 + 1.1;
|
|
1016
|
+
}
|
|
1017
|
+
this.ctx.strokeStyle = color_1.asString(color);
|
|
1018
|
+
this.ctx.stroke();
|
|
1019
|
+
this.ctx.setLineDash([]);
|
|
1020
|
+
// dashed round edge gap
|
|
1021
|
+
if (style === 2 /* DASHED */) {
|
|
1022
|
+
if (bezier_curve_1.isBezierCurve(boxPaths[0])) {
|
|
1023
|
+
path1 = boxPaths[3];
|
|
1024
|
+
path2 = boxPaths[0];
|
|
1025
|
+
this.ctx.beginPath();
|
|
1026
|
+
this.formatPath([new vector_1.Vector(path1.end.x, path1.end.y), new vector_1.Vector(path2.start.x, path2.start.y)]);
|
|
1027
|
+
this.ctx.stroke();
|
|
1028
|
+
}
|
|
1029
|
+
if (bezier_curve_1.isBezierCurve(boxPaths[1])) {
|
|
1030
|
+
path1 = boxPaths[1];
|
|
1031
|
+
path2 = boxPaths[2];
|
|
1032
|
+
this.ctx.beginPath();
|
|
1033
|
+
this.formatPath([new vector_1.Vector(path1.end.x, path1.end.y), new vector_1.Vector(path2.start.x, path2.start.y)]);
|
|
1034
|
+
this.ctx.stroke();
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
this.ctx.restore();
|
|
1038
|
+
return [2 /*return*/];
|
|
1039
|
+
});
|
|
1040
|
+
});
|
|
1041
|
+
};
|
|
1042
|
+
CanvasRenderer.prototype.render = function (element) {
|
|
1043
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1044
|
+
var stack;
|
|
1045
|
+
return __generator(this, function (_a) {
|
|
1046
|
+
switch (_a.label) {
|
|
1047
|
+
case 0:
|
|
1048
|
+
if (this.options.backgroundColor) {
|
|
1049
|
+
this.ctx.fillStyle = color_1.asString(this.options.backgroundColor);
|
|
1050
|
+
this.ctx.fillRect(this.options.x, this.options.y, this.options.width, this.options.height);
|
|
1051
|
+
}
|
|
1052
|
+
stack = stacking_context_1.parseStackingContexts(element);
|
|
1053
|
+
return [4 /*yield*/, this.renderStack(stack)];
|
|
1054
|
+
case 1:
|
|
1055
|
+
_a.sent();
|
|
1056
|
+
this.applyEffects([]);
|
|
1057
|
+
return [2 /*return*/, this.canvas];
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
});
|
|
1061
|
+
};
|
|
1062
|
+
return CanvasRenderer;
|
|
1063
|
+
}(renderer_1.Renderer));
|
|
1064
|
+
exports.CanvasRenderer = CanvasRenderer;
|
|
1065
|
+
var isTextInputElement = function (container) {
|
|
1066
|
+
if (container instanceof textarea_element_container_1.TextareaElementContainer) {
|
|
1067
|
+
return true;
|
|
1068
|
+
}
|
|
1069
|
+
else if (container instanceof select_element_container_1.SelectElementContainer) {
|
|
1070
|
+
return true;
|
|
1071
|
+
}
|
|
1072
|
+
else if (container instanceof input_element_container_1.InputElementContainer && container.type !== input_element_container_1.RADIO && container.type !== input_element_container_1.CHECKBOX) {
|
|
1073
|
+
return true;
|
|
1074
|
+
}
|
|
1075
|
+
return false;
|
|
1076
|
+
};
|
|
1077
|
+
var calculateBackgroundCurvedPaintingArea = function (clip, curves) {
|
|
1078
|
+
switch (clip) {
|
|
1079
|
+
case 0 /* BORDER_BOX */:
|
|
1080
|
+
return bound_curves_1.calculateBorderBoxPath(curves);
|
|
1081
|
+
case 2 /* CONTENT_BOX */:
|
|
1082
|
+
return bound_curves_1.calculateContentBoxPath(curves);
|
|
1083
|
+
case 1 /* PADDING_BOX */:
|
|
1084
|
+
default:
|
|
1085
|
+
return bound_curves_1.calculatePaddingBoxPath(curves);
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
var canvasTextAlign = function (textAlign) {
|
|
1089
|
+
switch (textAlign) {
|
|
1090
|
+
case 1 /* CENTER */:
|
|
1091
|
+
return 'center';
|
|
1092
|
+
case 2 /* RIGHT */:
|
|
1093
|
+
return 'right';
|
|
1094
|
+
case 0 /* LEFT */:
|
|
1095
|
+
default:
|
|
1096
|
+
return 'left';
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
// see https://github.com/niklasvh/html2canvas/pull/2645
|
|
1100
|
+
var iOSBrokenFonts = ['-apple-system', 'system-ui'];
|
|
1101
|
+
var fixIOSSystemFonts = function (fontFamilies) {
|
|
1102
|
+
return /iPhone OS 15_(0|1)/.test(window.navigator.userAgent)
|
|
1103
|
+
? fontFamilies.filter(function (fontFamily) { return iOSBrokenFonts.indexOf(fontFamily) === -1; })
|
|
1104
|
+
: fontFamilies;
|
|
1105
|
+
};
|
|
1106
|
+
//# sourceMappingURL=canvas-renderer.js.map
|