dompdf.js 1.1.1 → 1.2.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/.versionrc +8 -0
- package/CHANGELOG.md +32 -543
- package/README.md +172 -160
- package/README_CN.md +233 -238
- package/dist/dompdf.esm.js +124 -124
- package/dist/dompdf.esm.js.map +1 -1
- package/dist/dompdf.js +124 -124
- package/dist/dompdf.js.map +1 -1
- package/dist/dompdf.min.js +67 -0
- package/dist/index.d.ts +2 -1
- 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 +92 -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 +216 -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 +30 -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/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 +311 -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 +39 -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 +306 -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 +54 -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 +274 -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/foreignobject-renderer.js +108 -0
- package/dist/lib/render/canvas/foreignobject-renderer.js.map +1 -0
- package/dist/lib/render/canvas/pdf-renderer.js +1340 -0
- package/dist/lib/render/canvas/pdf-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/page-format-map.js +54 -0
- package/dist/lib/render/page-format-map.js.map +1 -0
- package/dist/lib/render/paginate copy 2.js +178 -0
- package/dist/lib/render/paginate copy 2.js.map +1 -0
- package/dist/lib/render/paginate.js +211 -0
- package/dist/lib/render/paginate.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/lib/utils/css-utils.js +19 -0
- package/dist/lib/utils/css-utils.js.map +1 -0
- package/dist/lib/utils/element-utils.js +25 -0
- package/dist/lib/utils/element-utils.js.map +1 -0
- package/dist/lib/utils/font-utils.js +70 -0
- package/dist/lib/utils/font-utils.js.map +1 -0
- package/dist/lib/utils/index.js +22 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/type-utils.js +40 -0
- package/dist/lib/utils/type-utils.js.map +1 -0
- package/dist/lib/utils/url-path.js +22 -0
- package/dist/lib/utils/url-path.js.map +1 -0
- package/dist/render/canvas/pdf-renderer.d.ts +2 -2
- package/dist/render/paginate copy 2.d.ts +3 -0
- package/dist/render/paginate.d.ts +1 -1
- 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 +132 -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/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 +23 -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 +17 -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/foreignobject-renderer.d.ts +11 -0
- package/dist/types/render/canvas/pdf-renderer.d.ts +110 -0
- package/dist/types/render/effects.d.ts +38 -0
- package/dist/types/render/font-metrics.d.ts +11 -0
- package/dist/types/render/page-format-map.d.ts +4 -0
- package/dist/types/render/paginate copy 2.d.ts +3 -0
- package/dist/types/render/paginate.d.ts +3 -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/dist/types/utils/css-utils.d.ts +2 -0
- package/dist/types/utils/element-utils.d.ts +7 -0
- package/dist/types/utils/font-utils.d.ts +9 -0
- package/dist/types/utils/index.d.ts +5 -0
- package/dist/types/utils/type-utils.d.ts +4 -0
- package/dist/types/utils/url-path.d.ts +7 -0
- package/dist/utils/font-utils.d.ts +2 -0
- package/fontconverter/fontconverter.html +2 -2
- package/package.json +135 -135
- package/page_sizes.md +50 -0
- package/.vscode/settings.json +0 -5
- package/html2pdf-userscript.js +0 -936
|
@@ -0,0 +1,1340 @@
|
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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 = exports.JsPdfContext2d = void 0;
|
|
55
|
+
var jspdf_1 = require("jspdf");
|
|
56
|
+
require("jspdf/dist/polyfills.es.js");
|
|
57
|
+
var bitwise_1 = require("../../core/bitwise");
|
|
58
|
+
var bounds_1 = require("../../css/layout/bounds");
|
|
59
|
+
var text_1 = require("../../css/layout/text");
|
|
60
|
+
var line_height_1 = require("../../css/property-descriptors/line-height");
|
|
61
|
+
var parser_1 = require("../../css/syntax/parser");
|
|
62
|
+
var color_1 = require("../../css/types/color");
|
|
63
|
+
var gradient_1 = require("../../css/types/functions/gradient");
|
|
64
|
+
var image_1 = require("../../css/types/image");
|
|
65
|
+
var length_percentage_1 = require("../../css/types/length-percentage");
|
|
66
|
+
var select_element_container_1 = require("../../dom/elements/select-element-container");
|
|
67
|
+
var textarea_element_container_1 = require("../../dom/elements/textarea-element-container");
|
|
68
|
+
// import {ReplacedElementContainer} from '../../dom/replaced-elements';
|
|
69
|
+
var canvas_element_container_1 = require("../../dom/replaced-elements/canvas-element-container");
|
|
70
|
+
var iframe_element_container_1 = require("../../dom/replaced-elements/iframe-element-container");
|
|
71
|
+
var image_element_container_1 = require("../../dom/replaced-elements/image-element-container");
|
|
72
|
+
var input_element_container_1 = require("../../dom/replaced-elements/input-element-container");
|
|
73
|
+
var svg_element_container_1 = require("../../dom/replaced-elements/svg-element-container");
|
|
74
|
+
var background_1 = require("../background");
|
|
75
|
+
var bezier_curve_1 = require("../bezier-curve");
|
|
76
|
+
var border_1 = require("../border");
|
|
77
|
+
var bound_curves_1 = require("../bound-curves");
|
|
78
|
+
var box_sizing_1 = require("../box-sizing");
|
|
79
|
+
var effects_1 = require("../effects");
|
|
80
|
+
var font_metrics_1 = require("../font-metrics");
|
|
81
|
+
// transformPath
|
|
82
|
+
var utils_1 = require("../../utils");
|
|
83
|
+
var path_1 = require("../path");
|
|
84
|
+
var renderer_1 = require("../renderer");
|
|
85
|
+
var stacking_context_1 = require("../stacking-context");
|
|
86
|
+
var vector_1 = require("../vector");
|
|
87
|
+
var JsPdfContext2d = /** @class */ (function () {
|
|
88
|
+
function JsPdfContext2d() {
|
|
89
|
+
}
|
|
90
|
+
return JsPdfContext2d;
|
|
91
|
+
}());
|
|
92
|
+
exports.JsPdfContext2d = JsPdfContext2d;
|
|
93
|
+
var CanvasRenderer = /** @class */ (function (_super) {
|
|
94
|
+
__extends(CanvasRenderer, _super);
|
|
95
|
+
function CanvasRenderer(context, options) {
|
|
96
|
+
var _this = _super.call(this, context, options) || this;
|
|
97
|
+
_this._activeEffects = [];
|
|
98
|
+
_this.totalPages = 1;
|
|
99
|
+
_this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
|
|
100
|
+
// this.ctx = this.canvas.getContext('2d') as CanvasRenderingContext2D;
|
|
101
|
+
_this.pxToPt = function (px) { return px * (72 / 96); };
|
|
102
|
+
var pageWidth = _this.pxToPt(options.width);
|
|
103
|
+
var pageHeight = _this.pxToPt(options.height);
|
|
104
|
+
// 如果 format 是数组,则将 px 转换为 pt
|
|
105
|
+
var format = Array.isArray(options.format) ? options.format.map(function (v) { return _this.pxToPt(v); }) : options.format;
|
|
106
|
+
_this.jspdfCtx = new jspdf_1.jsPDF({
|
|
107
|
+
// orientation: pageWidth > pageHeight ? 'landscape' : 'landscape',
|
|
108
|
+
unit: 'pt',
|
|
109
|
+
format: options.pagination && format ? format : [pageHeight, pageWidth],
|
|
110
|
+
hotfixes: ['px_scaling'],
|
|
111
|
+
putOnlyUsedFonts: options.putOnlyUsedFonts,
|
|
112
|
+
compress: options.compress,
|
|
113
|
+
precision: options.precision,
|
|
114
|
+
floatPrecision: options.floatPrecision,
|
|
115
|
+
encryption: options.encryption
|
|
116
|
+
});
|
|
117
|
+
_this.context2dCtx = _this.jspdfCtx.context2d;
|
|
118
|
+
_this.context2dCtx.scale(0.75, 0.75);
|
|
119
|
+
_this.context2dCtx.translate(-options.x, -options.y);
|
|
120
|
+
if (options.fontConfig) {
|
|
121
|
+
try {
|
|
122
|
+
_this.addFontToJsPDF();
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
console.warn('Failed to set font:', error);
|
|
126
|
+
_this.jspdfCtx.setFont('Helvetica');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (!options.canvas) {
|
|
130
|
+
_this.canvas.width = 10;
|
|
131
|
+
_this.canvas.height = 10;
|
|
132
|
+
_this.canvas.style.width = "10px";
|
|
133
|
+
_this.canvas.style.height = "10px";
|
|
134
|
+
}
|
|
135
|
+
_this.fontMetrics = new font_metrics_1.FontMetrics(document);
|
|
136
|
+
_this.context2dCtx.textBaseline = 'bottom';
|
|
137
|
+
_this._activeEffects = [];
|
|
138
|
+
_this.context.logger.debug("Canvas renderer initialized (".concat(options.width, "x").concat(options.height, ") with scale ").concat(options.scale));
|
|
139
|
+
return _this;
|
|
140
|
+
}
|
|
141
|
+
CanvasRenderer.prototype.addFontToJsPDF = function () {
|
|
142
|
+
var _this = this;
|
|
143
|
+
if ((0, utils_1.isEmptyValue)(this.options.fontConfig)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
var fonts = (0, utils_1.isObject)(this.options.fontConfig)
|
|
147
|
+
? [this.options.fontConfig]
|
|
148
|
+
: this.options.fontConfig;
|
|
149
|
+
fonts.forEach(function (v) {
|
|
150
|
+
_this.jspdfCtx.addFileToVFS("".concat(v.fontFamily, ".ttf"), v.fontBase64);
|
|
151
|
+
_this.jspdfCtx.addFont("".concat(v.fontFamily, ".ttf"), v.fontFamily, 'normal');
|
|
152
|
+
_this.jspdfCtx.setFont(v.fontFamily);
|
|
153
|
+
});
|
|
154
|
+
// console.log('render getFont', this.jspdfCtx.getFont());
|
|
155
|
+
this.context.logger.debug("setFont renderer initialized");
|
|
156
|
+
};
|
|
157
|
+
// reset all font
|
|
158
|
+
CanvasRenderer.prototype.resetJsPDFFont = function () {
|
|
159
|
+
var _this = this;
|
|
160
|
+
if ((0, utils_1.isArray)(this.options.fontConfig) && !(0, utils_1.isEmptyValue)(this.options.fontConfig)) {
|
|
161
|
+
this.options.fontConfig.forEach(function (v) {
|
|
162
|
+
v.fontFamily && _this.jspdfCtx.setFont(v.fontFamily);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
// setFont form options
|
|
167
|
+
CanvasRenderer.prototype.setTextFont = function (styles) {
|
|
168
|
+
var _a, _b, _c;
|
|
169
|
+
// console.log(styles.fontWeight, styles.fontStyle, styles.fontFamily, 'styles');
|
|
170
|
+
if ((0, utils_1.isEmptyValue)(this.options.fontConfig)) {
|
|
171
|
+
return '';
|
|
172
|
+
}
|
|
173
|
+
var fontConfigRef = this.options.fontConfig;
|
|
174
|
+
// 处理字体图标场景
|
|
175
|
+
var isIconFont = fontConfigRef.find(function (v) { return v.iconFont; });
|
|
176
|
+
var otherFonts = fontConfigRef.filter(function (v) { return !v.iconFont; });
|
|
177
|
+
if (isIconFont && styles.fontFamily.some(function (family) { return family.includes(isIconFont.fontFamily); })) {
|
|
178
|
+
isIconFont.fontFamily && this.jspdfCtx.setFont(isIconFont.fontFamily);
|
|
179
|
+
return isIconFont.fontFamily;
|
|
180
|
+
}
|
|
181
|
+
// 除开字体图标场景
|
|
182
|
+
if (otherFonts.length === 1) {
|
|
183
|
+
var fontFamilyCustom_1 = (_a = otherFonts[0].fontFamily) !== null && _a !== void 0 ? _a : '';
|
|
184
|
+
fontFamilyCustom_1 && this.jspdfCtx.setFont(fontFamilyCustom_1);
|
|
185
|
+
return fontFamilyCustom_1;
|
|
186
|
+
}
|
|
187
|
+
var fontFamilyCustom = (_c = (_b = otherFonts.find(function (v) { return v.fontWeight === (styles.fontWeight > 500 ? 700 : 400) && v.fontStyle === styles.fontStyle; })) === null || _b === void 0 ? void 0 : _b.fontFamily) !== null && _c !== void 0 ? _c : '';
|
|
188
|
+
fontFamilyCustom && this.jspdfCtx.setFont(fontFamilyCustom);
|
|
189
|
+
return fontFamilyCustom;
|
|
190
|
+
};
|
|
191
|
+
CanvasRenderer.prototype.applyEffects = function (effects) {
|
|
192
|
+
var _this = this;
|
|
193
|
+
while (this._activeEffects.length) {
|
|
194
|
+
this.popEffect();
|
|
195
|
+
}
|
|
196
|
+
effects.forEach(function (effect) { return _this.applyEffect(effect); });
|
|
197
|
+
};
|
|
198
|
+
CanvasRenderer.prototype.applyEffect = function (effect) {
|
|
199
|
+
this.context2dCtx.save();
|
|
200
|
+
if ((0, effects_1.isOpacityEffect)(effect)) {
|
|
201
|
+
this.context2dCtx.globalAlpha = effect.opacity;
|
|
202
|
+
}
|
|
203
|
+
if ((0, effects_1.isTransformEffect)(effect)) {
|
|
204
|
+
this.context2dCtx.translate(effect.offsetX, effect.offsetY);
|
|
205
|
+
this.context2dCtx.transform(effect.matrix[0], effect.matrix[1], effect.matrix[2], effect.matrix[3], effect.matrix[4], effect.matrix[5]);
|
|
206
|
+
this.context2dCtx.translate(-effect.offsetX, -effect.offsetY);
|
|
207
|
+
}
|
|
208
|
+
if ((0, effects_1.isClipEffect)(effect)) {
|
|
209
|
+
this.path(effect.path);
|
|
210
|
+
this.context2dCtx.clip();
|
|
211
|
+
}
|
|
212
|
+
this._activeEffects.push(effect);
|
|
213
|
+
};
|
|
214
|
+
CanvasRenderer.prototype.popEffect = function () {
|
|
215
|
+
this._activeEffects.pop();
|
|
216
|
+
this.context2dCtx.restore();
|
|
217
|
+
this.resetJsPDFFont();
|
|
218
|
+
};
|
|
219
|
+
CanvasRenderer.prototype.renderStack = function (stack) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
+
var styles;
|
|
222
|
+
return __generator(this, function (_a) {
|
|
223
|
+
switch (_a.label) {
|
|
224
|
+
case 0:
|
|
225
|
+
styles = stack.element.container.styles;
|
|
226
|
+
if (!styles.isVisible()) return [3 /*break*/, 2];
|
|
227
|
+
return [4 /*yield*/, this.renderStackContent(stack)];
|
|
228
|
+
case 1:
|
|
229
|
+
_a.sent();
|
|
230
|
+
_a.label = 2;
|
|
231
|
+
case 2: return [2 /*return*/];
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
CanvasRenderer.prototype.renderNode = function (paint) {
|
|
237
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
238
|
+
return __generator(this, function (_a) {
|
|
239
|
+
switch (_a.label) {
|
|
240
|
+
case 0:
|
|
241
|
+
if ((0, bitwise_1.contains)(paint.container.flags, 16 /* FLAGS.DEBUG_RENDER */)) {
|
|
242
|
+
debugger;
|
|
243
|
+
}
|
|
244
|
+
if (!paint.container.styles.isVisible()) return [3 /*break*/, 3];
|
|
245
|
+
return [4 /*yield*/, this.renderNodeBackgroundAndBorders(paint)];
|
|
246
|
+
case 1:
|
|
247
|
+
_a.sent();
|
|
248
|
+
return [4 /*yield*/, this.renderNodeContent(paint)];
|
|
249
|
+
case 2:
|
|
250
|
+
_a.sent();
|
|
251
|
+
_a.label = 3;
|
|
252
|
+
case 3: return [2 /*return*/];
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
CanvasRenderer.prototype.renderTextWithLetterSpacing = function (text, letterSpacing, baseline) {
|
|
258
|
+
var _this = this;
|
|
259
|
+
if (letterSpacing === 0) {
|
|
260
|
+
this.context2dCtx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
var letters = (0, text_1.segmentGraphemes)(text.text);
|
|
264
|
+
letters.reduce(function (left, letter) {
|
|
265
|
+
_this.context2dCtx.fillText(letter, left, text.bounds.top + baseline);
|
|
266
|
+
return left + _this.context2dCtx.measureText(letter);
|
|
267
|
+
// return left + this.context2dCtx.measureText(letter).width;
|
|
268
|
+
}, text.bounds.left);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
CanvasRenderer.prototype.createFontStyle = function (styles) {
|
|
272
|
+
var fontVariant = styles.fontVariant
|
|
273
|
+
.filter(function (variant) { return variant === 'normal' || variant === 'small-caps'; })
|
|
274
|
+
.join('');
|
|
275
|
+
var fontFamily = fixIOSSystemFonts(styles.fontFamily).join(', ');
|
|
276
|
+
var fontSize = (0, parser_1.isDimensionToken)(styles.fontSize)
|
|
277
|
+
? "".concat(styles.fontSize.number).concat(styles.fontSize.unit)
|
|
278
|
+
: "".concat(styles.fontSize.number, "px");
|
|
279
|
+
return [
|
|
280
|
+
[styles.fontStyle, fontVariant, styles.fontWeight, fontSize, fontFamily].join(' '),
|
|
281
|
+
fontFamily,
|
|
282
|
+
fontSize
|
|
283
|
+
];
|
|
284
|
+
};
|
|
285
|
+
CanvasRenderer.prototype.convertColor = function (color) {
|
|
286
|
+
if ((0, color_1.isTransparent)(color)) {
|
|
287
|
+
return '#FFFFFF';
|
|
288
|
+
}
|
|
289
|
+
var r = 0xff & (color >> 24);
|
|
290
|
+
var g = 0xff & (color >> 16);
|
|
291
|
+
var b = 0xff & (color >> 8);
|
|
292
|
+
return "#".concat(r.toString(16).padStart(2, '0')).concat(g.toString(16).padStart(2, '0')).concat(b
|
|
293
|
+
.toString(16)
|
|
294
|
+
.padStart(2, '0'));
|
|
295
|
+
// return asString(color);
|
|
296
|
+
};
|
|
297
|
+
CanvasRenderer.prototype.renderTextNode = function (text, styles) {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
299
|
+
var _a, font, fontFamily, fontSize, fontFamilyFinal, fontSizePt, _b, baseline, middle, paintOrder;
|
|
300
|
+
var _this = this;
|
|
301
|
+
return __generator(this, function (_c) {
|
|
302
|
+
_a = this.createFontStyle(styles), font = _a[0], fontFamily = _a[1], fontSize = _a[2];
|
|
303
|
+
fontFamilyFinal = this.setTextFont(styles);
|
|
304
|
+
this.context2dCtx.font = fontFamilyFinal || font;
|
|
305
|
+
// console.log(fontFamilyFinal, styles, 'render getFont', this.jspdfCtx.getFont());
|
|
306
|
+
// jspdf context2d not supported ‘direction’
|
|
307
|
+
// this.context2dCtx.direction = styles.direction === DIRECTION.RTL ? 'rtl' : 'ltr';
|
|
308
|
+
this.context2dCtx.textAlign = 'left';
|
|
309
|
+
fontSizePt = styles.fontSize.number;
|
|
310
|
+
this.jspdfCtx.setFontSize(fontSizePt);
|
|
311
|
+
_b = this.fontMetrics.getMetrics(fontFamily, fontSize), baseline = _b.baseline, middle = _b.middle;
|
|
312
|
+
paintOrder = styles.paintOrder;
|
|
313
|
+
text.textBounds.forEach(function (textItem) {
|
|
314
|
+
paintOrder.forEach(function (paintOrderLayer) {
|
|
315
|
+
switch (paintOrderLayer) {
|
|
316
|
+
case 0 /* PAINT_ORDER_LAYER.FILL */:
|
|
317
|
+
_this.context2dCtx.fillStyle = (0, color_1.asString)(styles.color);
|
|
318
|
+
_this.renderTextWithLetterSpacing(textItem, styles.letterSpacing, baseline);
|
|
319
|
+
if (styles.textDecorationLine.length) {
|
|
320
|
+
_this.context2dCtx.fillStyle = (0, color_1.asString)(styles.textDecorationColor || styles.color);
|
|
321
|
+
styles.textDecorationLine.forEach(function (textDecorationLine) {
|
|
322
|
+
var x = textItem.bounds.left;
|
|
323
|
+
var width = textItem.bounds.width;
|
|
324
|
+
var y_underline = Math.round(textItem.bounds.top + baseline);
|
|
325
|
+
var y_overline = Math.round(textItem.bounds.top);
|
|
326
|
+
var y_line_through = Math.ceil(textItem.bounds.top + middle);
|
|
327
|
+
var thickness = 1;
|
|
328
|
+
switch (textDecorationLine) {
|
|
329
|
+
case 1 /* TEXT_DECORATION_LINE.UNDERLINE */:
|
|
330
|
+
_this.context2dCtx.fillRect(x, y_underline, width, thickness);
|
|
331
|
+
break;
|
|
332
|
+
case 2 /* TEXT_DECORATION_LINE.OVERLINE */:
|
|
333
|
+
_this.context2dCtx.fillRect(x, y_overline, width, thickness);
|
|
334
|
+
break;
|
|
335
|
+
case 3 /* TEXT_DECORATION_LINE.LINE_THROUGH */:
|
|
336
|
+
_this.context2dCtx.fillRect(x, y_line_through, width, thickness);
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
break;
|
|
342
|
+
case 1 /* PAINT_ORDER_LAYER.STROKE */:
|
|
343
|
+
if (styles.webkitTextStrokeWidth && textItem.text.trim().length) {
|
|
344
|
+
_this.context2dCtx.strokeStyle = (0, color_1.asString)(styles.webkitTextStrokeColor);
|
|
345
|
+
_this.context2dCtx.lineWidth = styles.webkitTextStrokeWidth;
|
|
346
|
+
_this.context2dCtx.strokeText(textItem.text, textItem.bounds.left, textItem.bounds.top + baseline);
|
|
347
|
+
}
|
|
348
|
+
_this.context2dCtx.strokeStyle = '';
|
|
349
|
+
_this.context2dCtx.lineWidth = 0;
|
|
350
|
+
_this.context2dCtx.lineJoin = 'miter';
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
return [2 /*return*/];
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
CanvasRenderer.prototype.renderReplacedJsPdfImage = function (container, image) {
|
|
360
|
+
var bounds = (0, box_sizing_1.contentBox)(container);
|
|
361
|
+
var x = this.pxToPt(bounds.left - this.options.x);
|
|
362
|
+
var y = this.pxToPt(bounds.top - this.options.y);
|
|
363
|
+
var width = this.pxToPt(bounds.width);
|
|
364
|
+
var height = this.pxToPt(bounds.height);
|
|
365
|
+
// fix: url is svg image export
|
|
366
|
+
if ((0, utils_1.getImageTypeByPath)(container.src, 'svg')) {
|
|
367
|
+
var canvas = document.createElement('canvas');
|
|
368
|
+
canvas.width = width;
|
|
369
|
+
canvas.height = height;
|
|
370
|
+
var ctx = canvas.getContext('2d');
|
|
371
|
+
if (ctx) {
|
|
372
|
+
ctx.clearRect(0, 0, width, height);
|
|
373
|
+
ctx.drawImage(image, 0, 0, width, height);
|
|
374
|
+
var dataURL = canvas.toDataURL('image/png', 0.8);
|
|
375
|
+
this.addImagePdf(dataURL, 'PNG', x, y, width, height);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
this.addImagePdf(image, 'JPEG', x, y, width, height);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
CanvasRenderer.prototype.renderReplacedJsPdfSvg = function (container, image) {
|
|
383
|
+
var bounds = (0, box_sizing_1.contentBox)(container);
|
|
384
|
+
var x = this.pxToPt(bounds.left - this.options.x);
|
|
385
|
+
var y = this.pxToPt(bounds.top - this.options.y);
|
|
386
|
+
var width = this.pxToPt(bounds.width);
|
|
387
|
+
var height = this.pxToPt(bounds.height);
|
|
388
|
+
var canvas = document.createElement('canvas');
|
|
389
|
+
canvas.width = width;
|
|
390
|
+
canvas.height = height;
|
|
391
|
+
var ctx = canvas.getContext('2d');
|
|
392
|
+
if (ctx) {
|
|
393
|
+
ctx.clearRect(0, 0, width, height);
|
|
394
|
+
ctx.drawImage(image, 0, 0, width, height);
|
|
395
|
+
var dataURL = canvas.toDataURL('image/png', 0.8);
|
|
396
|
+
this.addImagePdf(dataURL, 'PNG', x, y, width, height);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
CanvasRenderer.prototype.renderReplacedJsPdfCanvasImage = function (container) {
|
|
400
|
+
var bounds = (0, box_sizing_1.contentBox)(container);
|
|
401
|
+
var x = this.pxToPt(bounds.left - this.options.x);
|
|
402
|
+
var y = this.pxToPt(bounds.top - this.options.y);
|
|
403
|
+
var width = this.pxToPt(bounds.width);
|
|
404
|
+
var height = this.pxToPt(bounds.height);
|
|
405
|
+
var dataURL = container.canvas.toDataURL('image/png', 0.8);
|
|
406
|
+
this.addImagePdf(dataURL, 'PNG', x, y, width, height);
|
|
407
|
+
};
|
|
408
|
+
CanvasRenderer.prototype.renderNodeContent = function (paint) {
|
|
409
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
410
|
+
var container, styles, _i, _a, child, image, e_1, image, e_2, size, _b, fontFamily, fontSize, baseline, bounds, x, textBounds, img, image, url, iconWidth, iconHeight, e_3, fontFamily, bounds;
|
|
411
|
+
return __generator(this, function (_c) {
|
|
412
|
+
switch (_c.label) {
|
|
413
|
+
case 0:
|
|
414
|
+
this.applyEffects(paint.getEffects(4 /* EffectTarget.CONTENT */));
|
|
415
|
+
container = paint.container;
|
|
416
|
+
styles = container.styles;
|
|
417
|
+
this.resetJsPDFFont();
|
|
418
|
+
_i = 0, _a = container.textNodes;
|
|
419
|
+
_c.label = 1;
|
|
420
|
+
case 1:
|
|
421
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
422
|
+
child = _a[_i];
|
|
423
|
+
return [4 /*yield*/, this.renderTextNode(child, styles)];
|
|
424
|
+
case 2:
|
|
425
|
+
_c.sent();
|
|
426
|
+
_c.label = 3;
|
|
427
|
+
case 3:
|
|
428
|
+
_i++;
|
|
429
|
+
return [3 /*break*/, 1];
|
|
430
|
+
case 4:
|
|
431
|
+
if (!(container instanceof image_element_container_1.ImageElementContainer)) return [3 /*break*/, 8];
|
|
432
|
+
_c.label = 5;
|
|
433
|
+
case 5:
|
|
434
|
+
_c.trys.push([5, 7, , 8]);
|
|
435
|
+
return [4 /*yield*/, this.context.cache.match(container.src)];
|
|
436
|
+
case 6:
|
|
437
|
+
image = _c.sent();
|
|
438
|
+
this.renderReplacedJsPdfImage(container, image);
|
|
439
|
+
return [3 /*break*/, 8];
|
|
440
|
+
case 7:
|
|
441
|
+
e_1 = _c.sent();
|
|
442
|
+
this.context.logger.error("Error loading image ".concat(container));
|
|
443
|
+
return [3 /*break*/, 8];
|
|
444
|
+
case 8:
|
|
445
|
+
if (container instanceof canvas_element_container_1.CanvasElementContainer) {
|
|
446
|
+
try {
|
|
447
|
+
this.renderReplacedJsPdfCanvasImage(container);
|
|
448
|
+
}
|
|
449
|
+
catch (err) {
|
|
450
|
+
this.context.logger.error("Error adding canvas to PDF: ".concat(err));
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
if (!(container instanceof svg_element_container_1.SVGElementContainer)) return [3 /*break*/, 12];
|
|
454
|
+
_c.label = 9;
|
|
455
|
+
case 9:
|
|
456
|
+
_c.trys.push([9, 11, , 12]);
|
|
457
|
+
return [4 /*yield*/, this.context.cache.match(container.svg)];
|
|
458
|
+
case 10:
|
|
459
|
+
image = _c.sent();
|
|
460
|
+
this.renderReplacedJsPdfSvg(container, image);
|
|
461
|
+
return [3 /*break*/, 12];
|
|
462
|
+
case 11:
|
|
463
|
+
e_2 = _c.sent();
|
|
464
|
+
this.context.logger.error("Error loading svg ".concat(e_2));
|
|
465
|
+
return [3 /*break*/, 12];
|
|
466
|
+
case 12:
|
|
467
|
+
if (container instanceof iframe_element_container_1.IFrameElementContainer && container.tree) {
|
|
468
|
+
}
|
|
469
|
+
if (container instanceof input_element_container_1.InputElementContainer) {
|
|
470
|
+
size = Math.min(container.bounds.width, container.bounds.height);
|
|
471
|
+
if (container.type === input_element_container_1.CHECKBOX) {
|
|
472
|
+
if (container.checked) {
|
|
473
|
+
this.context2dCtx.save();
|
|
474
|
+
this.path([
|
|
475
|
+
new vector_1.Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79),
|
|
476
|
+
new vector_1.Vector(container.bounds.left + size * 0.16, container.bounds.top + size * 0.5549),
|
|
477
|
+
new vector_1.Vector(container.bounds.left + size * 0.27347, container.bounds.top + size * 0.44071),
|
|
478
|
+
new vector_1.Vector(container.bounds.left + size * 0.39694, container.bounds.top + size * 0.5649),
|
|
479
|
+
new vector_1.Vector(container.bounds.left + size * 0.72983, container.bounds.top + size * 0.23),
|
|
480
|
+
new vector_1.Vector(container.bounds.left + size * 0.84, container.bounds.top + size * 0.34085),
|
|
481
|
+
new vector_1.Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79)
|
|
482
|
+
]);
|
|
483
|
+
this.context2dCtx.fillStyle = this.convertColor(input_element_container_1.INPUT_COLOR);
|
|
484
|
+
this.context2dCtx.fill();
|
|
485
|
+
this.context2dCtx.restore();
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
else if (container.type === input_element_container_1.RADIO) {
|
|
489
|
+
if (container.checked) {
|
|
490
|
+
this.context2dCtx.save();
|
|
491
|
+
this.context2dCtx.beginPath();
|
|
492
|
+
this.context2dCtx.arc(container.bounds.left + size / 2, container.bounds.top + size / 2, size / 4, 0, Math.PI * 2, true);
|
|
493
|
+
this.context2dCtx.fillStyle = this.convertColor(input_element_container_1.INPUT_COLOR);
|
|
494
|
+
this.context2dCtx.fill();
|
|
495
|
+
this.context2dCtx.restore();
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (isTextInputElement(container) && container.value.length) {
|
|
500
|
+
_b = this.createFontStyle(styles), fontFamily = _b[0], fontSize = _b[1];
|
|
501
|
+
baseline = this.fontMetrics.getMetrics(fontFamily, fontSize).baseline;
|
|
502
|
+
this.context2dCtx.fillStyle = this.convertColor(styles.color);
|
|
503
|
+
this.context2dCtx.textBaseline = 'alphabetic';
|
|
504
|
+
this.context2dCtx.textAlign = canvasTextAlign(container.styles.textAlign);
|
|
505
|
+
bounds = (0, box_sizing_1.contentBox)(container);
|
|
506
|
+
x = 0;
|
|
507
|
+
switch (container.styles.textAlign) {
|
|
508
|
+
case 1 /* TEXT_ALIGN.CENTER */:
|
|
509
|
+
x += bounds.width / 2;
|
|
510
|
+
break;
|
|
511
|
+
case 2 /* TEXT_ALIGN.RIGHT */:
|
|
512
|
+
x += bounds.width;
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
textBounds = bounds.add(x, 0, 0, -bounds.height / 2 + 1);
|
|
516
|
+
this.context2dCtx.save();
|
|
517
|
+
this.path([
|
|
518
|
+
new vector_1.Vector(bounds.left, bounds.top),
|
|
519
|
+
new vector_1.Vector(bounds.left + bounds.width, bounds.top),
|
|
520
|
+
new vector_1.Vector(bounds.left + bounds.width, bounds.top + bounds.height),
|
|
521
|
+
new vector_1.Vector(bounds.left, bounds.top + bounds.height)
|
|
522
|
+
]);
|
|
523
|
+
this.context2dCtx.clip();
|
|
524
|
+
this.renderTextWithLetterSpacing(new text_1.TextBounds(container.value, textBounds), styles.letterSpacing, baseline);
|
|
525
|
+
this.context2dCtx.restore();
|
|
526
|
+
this.context2dCtx.textBaseline = 'alphabetic';
|
|
527
|
+
this.context2dCtx.textAlign = 'left';
|
|
528
|
+
}
|
|
529
|
+
if (!(0, bitwise_1.contains)(container.styles.display, 2048 /* DISPLAY.LIST_ITEM */)) return [3 /*break*/, 18];
|
|
530
|
+
if (!(container.styles.listStyleImage !== null)) return [3 /*break*/, 17];
|
|
531
|
+
img = container.styles.listStyleImage;
|
|
532
|
+
if (!(img.type === 0 /* CSSImageType.URL */)) return [3 /*break*/, 16];
|
|
533
|
+
image = void 0;
|
|
534
|
+
url = img.url;
|
|
535
|
+
_c.label = 13;
|
|
536
|
+
case 13:
|
|
537
|
+
_c.trys.push([13, 15, , 16]);
|
|
538
|
+
return [4 /*yield*/, this.context.cache.match(url)];
|
|
539
|
+
case 14:
|
|
540
|
+
image = _c.sent();
|
|
541
|
+
iconWidth = image.width;
|
|
542
|
+
iconHeight = image.height;
|
|
543
|
+
this.context2dCtx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top, iconWidth, iconHeight);
|
|
544
|
+
return [3 /*break*/, 16];
|
|
545
|
+
case 15:
|
|
546
|
+
e_3 = _c.sent();
|
|
547
|
+
this.context.logger.error("Error loading list-style-image ".concat(url));
|
|
548
|
+
return [3 /*break*/, 16];
|
|
549
|
+
case 16: return [3 /*break*/, 18];
|
|
550
|
+
case 17:
|
|
551
|
+
if (paint.listValue && container.styles.listStyleType !== -1 /* LIST_STYLE_TYPE.NONE */) {
|
|
552
|
+
fontFamily = this.createFontStyle(styles)[0];
|
|
553
|
+
this.context2dCtx.font = fontFamily;
|
|
554
|
+
this.context2dCtx.fillStyle = this.convertColor(styles.color);
|
|
555
|
+
this.context2dCtx.textBaseline = 'middle';
|
|
556
|
+
this.context2dCtx.textAlign = 'right';
|
|
557
|
+
bounds = new bounds_1.Bounds(container.bounds.left, container.bounds.top + (0, length_percentage_1.getAbsoluteValue)(container.styles.paddingTop, container.bounds.width), container.bounds.width, (0, line_height_1.computeLineHeight)(styles.lineHeight, styles.fontSize.number) / 2 + 1);
|
|
558
|
+
this.renderTextWithLetterSpacing(new text_1.TextBounds(paint.listValue, bounds), styles.letterSpacing, (0, line_height_1.computeLineHeight)(styles.lineHeight, styles.fontSize.number) / 2 + 2);
|
|
559
|
+
this.context2dCtx.textBaseline = 'bottom';
|
|
560
|
+
this.context2dCtx.textAlign = 'left';
|
|
561
|
+
}
|
|
562
|
+
_c.label = 18;
|
|
563
|
+
case 18: return [2 /*return*/];
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
};
|
|
568
|
+
CanvasRenderer.prototype.renderStackContent = function (stack) {
|
|
569
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
570
|
+
var _i, _a, child, _b, _c, child, _d, _e, child, _f, _g, child, _h, _j, child, _k, _l, child, _m, _o, child;
|
|
571
|
+
return __generator(this, function (_p) {
|
|
572
|
+
switch (_p.label) {
|
|
573
|
+
case 0:
|
|
574
|
+
if ((0, bitwise_1.contains)(stack.element.container.flags, 16 /* FLAGS.DEBUG_RENDER */)) {
|
|
575
|
+
debugger;
|
|
576
|
+
}
|
|
577
|
+
return [4 /*yield*/, this.renderNodeBackgroundAndBorders(stack.element)];
|
|
578
|
+
case 1:
|
|
579
|
+
_p.sent();
|
|
580
|
+
_i = 0, _a = stack.negativeZIndex;
|
|
581
|
+
_p.label = 2;
|
|
582
|
+
case 2:
|
|
583
|
+
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
584
|
+
child = _a[_i];
|
|
585
|
+
return [4 /*yield*/, this.renderStack(child)];
|
|
586
|
+
case 3:
|
|
587
|
+
_p.sent();
|
|
588
|
+
_p.label = 4;
|
|
589
|
+
case 4:
|
|
590
|
+
_i++;
|
|
591
|
+
return [3 /*break*/, 2];
|
|
592
|
+
case 5: return [4 /*yield*/, this.renderNodeContent(stack.element)];
|
|
593
|
+
case 6:
|
|
594
|
+
_p.sent();
|
|
595
|
+
_b = 0, _c = stack.nonInlineLevel;
|
|
596
|
+
_p.label = 7;
|
|
597
|
+
case 7:
|
|
598
|
+
if (!(_b < _c.length)) return [3 /*break*/, 10];
|
|
599
|
+
child = _c[_b];
|
|
600
|
+
return [4 /*yield*/, this.renderNode(child)];
|
|
601
|
+
case 8:
|
|
602
|
+
_p.sent();
|
|
603
|
+
_p.label = 9;
|
|
604
|
+
case 9:
|
|
605
|
+
_b++;
|
|
606
|
+
return [3 /*break*/, 7];
|
|
607
|
+
case 10:
|
|
608
|
+
_d = 0, _e = stack.nonPositionedFloats;
|
|
609
|
+
_p.label = 11;
|
|
610
|
+
case 11:
|
|
611
|
+
if (!(_d < _e.length)) return [3 /*break*/, 14];
|
|
612
|
+
child = _e[_d];
|
|
613
|
+
return [4 /*yield*/, this.renderStack(child)];
|
|
614
|
+
case 12:
|
|
615
|
+
_p.sent();
|
|
616
|
+
_p.label = 13;
|
|
617
|
+
case 13:
|
|
618
|
+
_d++;
|
|
619
|
+
return [3 /*break*/, 11];
|
|
620
|
+
case 14:
|
|
621
|
+
_f = 0, _g = stack.nonPositionedInlineLevel;
|
|
622
|
+
_p.label = 15;
|
|
623
|
+
case 15:
|
|
624
|
+
if (!(_f < _g.length)) return [3 /*break*/, 18];
|
|
625
|
+
child = _g[_f];
|
|
626
|
+
return [4 /*yield*/, this.renderStack(child)];
|
|
627
|
+
case 16:
|
|
628
|
+
_p.sent();
|
|
629
|
+
_p.label = 17;
|
|
630
|
+
case 17:
|
|
631
|
+
_f++;
|
|
632
|
+
return [3 /*break*/, 15];
|
|
633
|
+
case 18:
|
|
634
|
+
_h = 0, _j = stack.inlineLevel;
|
|
635
|
+
_p.label = 19;
|
|
636
|
+
case 19:
|
|
637
|
+
if (!(_h < _j.length)) return [3 /*break*/, 22];
|
|
638
|
+
child = _j[_h];
|
|
639
|
+
return [4 /*yield*/, this.renderNode(child)];
|
|
640
|
+
case 20:
|
|
641
|
+
_p.sent();
|
|
642
|
+
_p.label = 21;
|
|
643
|
+
case 21:
|
|
644
|
+
_h++;
|
|
645
|
+
return [3 /*break*/, 19];
|
|
646
|
+
case 22:
|
|
647
|
+
_k = 0, _l = stack.zeroOrAutoZIndexOrTransformedOrOpacity;
|
|
648
|
+
_p.label = 23;
|
|
649
|
+
case 23:
|
|
650
|
+
if (!(_k < _l.length)) return [3 /*break*/, 26];
|
|
651
|
+
child = _l[_k];
|
|
652
|
+
return [4 /*yield*/, this.renderStack(child)];
|
|
653
|
+
case 24:
|
|
654
|
+
_p.sent();
|
|
655
|
+
_p.label = 25;
|
|
656
|
+
case 25:
|
|
657
|
+
_k++;
|
|
658
|
+
return [3 /*break*/, 23];
|
|
659
|
+
case 26:
|
|
660
|
+
_m = 0, _o = stack.positiveZIndex;
|
|
661
|
+
_p.label = 27;
|
|
662
|
+
case 27:
|
|
663
|
+
if (!(_m < _o.length)) return [3 /*break*/, 30];
|
|
664
|
+
child = _o[_m];
|
|
665
|
+
return [4 /*yield*/, this.renderStack(child)];
|
|
666
|
+
case 28:
|
|
667
|
+
_p.sent();
|
|
668
|
+
_p.label = 29;
|
|
669
|
+
case 29:
|
|
670
|
+
_m++;
|
|
671
|
+
return [3 /*break*/, 27];
|
|
672
|
+
case 30: return [2 /*return*/];
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
};
|
|
677
|
+
CanvasRenderer.prototype.mask = function (paths) {
|
|
678
|
+
this.context2dCtx.beginPath();
|
|
679
|
+
this.context2dCtx.moveTo(0, 0);
|
|
680
|
+
this.context2dCtx.lineTo(this.options.width, 0);
|
|
681
|
+
this.context2dCtx.lineTo(this.options.width, this.options.height);
|
|
682
|
+
this.context2dCtx.lineTo(0, this.options.height);
|
|
683
|
+
this.context2dCtx.lineTo(0, 0);
|
|
684
|
+
this.formatPath(paths.slice(0).reverse());
|
|
685
|
+
this.context2dCtx.closePath();
|
|
686
|
+
};
|
|
687
|
+
CanvasRenderer.prototype.path = function (paths, ctx2d) {
|
|
688
|
+
var contextCtx = ctx2d ? ctx2d : this.context2dCtx;
|
|
689
|
+
contextCtx.beginPath();
|
|
690
|
+
this.formatPath(paths, contextCtx);
|
|
691
|
+
contextCtx.closePath();
|
|
692
|
+
};
|
|
693
|
+
CanvasRenderer.prototype.formatPath = function (paths, ctx2d) {
|
|
694
|
+
var contextCtx = ctx2d ? ctx2d : this.context2dCtx;
|
|
695
|
+
paths.forEach(function (point, index) {
|
|
696
|
+
var start = (0, bezier_curve_1.isBezierCurve)(point) ? point.start : point;
|
|
697
|
+
if (index === 0) {
|
|
698
|
+
contextCtx.moveTo(start.x, start.y);
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
contextCtx.lineTo(start.x, start.y);
|
|
702
|
+
}
|
|
703
|
+
if ((0, bezier_curve_1.isBezierCurve)(point)) {
|
|
704
|
+
contextCtx.bezierCurveTo(point.startControl.x, point.startControl.y, point.endControl.x, point.endControl.y, point.end.x, point.end.y);
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
};
|
|
708
|
+
CanvasRenderer.prototype.renderRepeat = function (boxs, ctx, path, pattern) {
|
|
709
|
+
// renderRepeat(boxs: Bounds, ctx: CanvasRenderingContext2D, path: Path[], pattern: CanvasPattern | CanvasGradient, offsetX: number, offsetY: number): void {
|
|
710
|
+
var contextCtx = ctx;
|
|
711
|
+
this.path(path, contextCtx);
|
|
712
|
+
contextCtx.fillStyle = pattern;
|
|
713
|
+
contextCtx.translate(0, 0);
|
|
714
|
+
// contextCtx.fill();
|
|
715
|
+
contextCtx.fillRect(0, 0, boxs.width, boxs.height); // 绘制填充矩形(此时坐标系已偏移)
|
|
716
|
+
contextCtx.translate(-0, -0);
|
|
717
|
+
};
|
|
718
|
+
CanvasRenderer.prototype.resizeImage = function (image, width, height) {
|
|
719
|
+
var _a;
|
|
720
|
+
if (image.width === width && image.height === height) {
|
|
721
|
+
return image;
|
|
722
|
+
}
|
|
723
|
+
var ownerDocument = (_a = this.canvas.ownerDocument) !== null && _a !== void 0 ? _a : document;
|
|
724
|
+
var canvas = ownerDocument.createElement('canvas');
|
|
725
|
+
canvas.width = Math.max(1, width);
|
|
726
|
+
canvas.height = Math.max(1, height);
|
|
727
|
+
var ctx = canvas.getContext('2d');
|
|
728
|
+
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
|
|
729
|
+
return canvas;
|
|
730
|
+
};
|
|
731
|
+
CanvasRenderer.prototype.renderBackgroundImage = function (container) {
|
|
732
|
+
var _a, _b;
|
|
733
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
734
|
+
var index, _loop_1, this_1, _i, _c, backgroundImage;
|
|
735
|
+
return __generator(this, function (_d) {
|
|
736
|
+
switch (_d.label) {
|
|
737
|
+
case 0:
|
|
738
|
+
index = container.styles.backgroundImage.length - 1;
|
|
739
|
+
_loop_1 = function (backgroundImage) {
|
|
740
|
+
var image, url, _e, path, x, y, width, height, boxs, ownerDocument, canvas, ctx, repeatStr, xPt, yPt, widthPt, heightPt, resizeImg, pattern, pathTs, dataURL, xPt, yPt, widthPt, heightPt, e_4, _f, path, x, y, width, height, _g, lineLength, x0, x1, y0, y1, boxs, canvas, ctx, gradient_2, pattern, pathTs, dataURL, xPt, yPt, widthPt, heightPt, _h, path, left, top_1, width, height, position, x, y, _j, rx, ry, ownerDocument, canvas, ctx, radialGradient_1, pathTs, midX, midY, f, invF, dataURL, xPt, yPt, widthPt, heightPt;
|
|
741
|
+
return __generator(this, function (_k) {
|
|
742
|
+
switch (_k.label) {
|
|
743
|
+
case 0:
|
|
744
|
+
if (!(backgroundImage.type === 0 /* CSSImageType.URL */)) return [3 /*break*/, 5];
|
|
745
|
+
image = void 0;
|
|
746
|
+
url = backgroundImage.url;
|
|
747
|
+
_k.label = 1;
|
|
748
|
+
case 1:
|
|
749
|
+
_k.trys.push([1, 3, , 4]);
|
|
750
|
+
return [4 /*yield*/, this_1.context.cache.match(url)];
|
|
751
|
+
case 2:
|
|
752
|
+
image = _k.sent();
|
|
753
|
+
if (image) {
|
|
754
|
+
_e = (0, background_1.calculateBackgroundRendering)(container, index, [
|
|
755
|
+
image.width,
|
|
756
|
+
image.height,
|
|
757
|
+
image.width / image.height
|
|
758
|
+
]), path = _e[0], x = _e[1], y = _e[2], width = _e[3], height = _e[4];
|
|
759
|
+
boxs = (0, box_sizing_1.contentBox)(container);
|
|
760
|
+
ownerDocument = (_a = this_1.canvas.ownerDocument) !== null && _a !== void 0 ? _a : document;
|
|
761
|
+
canvas = ownerDocument.createElement('canvas');
|
|
762
|
+
canvas.width = Math.max(1, boxs.width);
|
|
763
|
+
canvas.height = Math.max(1, boxs.height);
|
|
764
|
+
ctx = canvas.getContext('2d');
|
|
765
|
+
ctx.save();
|
|
766
|
+
repeatStr = (0, utils_1.getBackgroundRepeat)(container.styles.backgroundRepeat[0]);
|
|
767
|
+
if (container.styles.backgroundRepeat[0] === 1 /* BACKGROUND_REPEAT.NO_REPEAT */) {
|
|
768
|
+
xPt = this_1.pxToPt(x - this_1.options.x);
|
|
769
|
+
yPt = this_1.pxToPt(y - this_1.options.y);
|
|
770
|
+
widthPt = this_1.pxToPt(width);
|
|
771
|
+
heightPt = this_1.pxToPt(height);
|
|
772
|
+
this_1.addImagePdf(image, 'JPEG', xPt, yPt, widthPt, heightPt);
|
|
773
|
+
}
|
|
774
|
+
else {
|
|
775
|
+
resizeImg = this_1.resizeImage(image, width, height);
|
|
776
|
+
pattern = ctx.createPattern(resizeImg, repeatStr);
|
|
777
|
+
pathTs = (0, path_1.transformPath)(path, -x, -y, 0, 0);
|
|
778
|
+
this_1.renderRepeat(boxs, ctx, pathTs, pattern);
|
|
779
|
+
dataURL = canvas.toDataURL('image/jpeg', 0.8);
|
|
780
|
+
// console.log(dataURL, 'dataURL', image)
|
|
781
|
+
ctx.restore();
|
|
782
|
+
xPt = this_1.pxToPt(boxs.left - this_1.options.x);
|
|
783
|
+
yPt = this_1.pxToPt(boxs.top - this_1.options.y);
|
|
784
|
+
widthPt = this_1.pxToPt(boxs.width);
|
|
785
|
+
heightPt = this_1.pxToPt(boxs.height);
|
|
786
|
+
this_1.addImagePdf(dataURL, 'JPEG', xPt, yPt, widthPt, heightPt);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
return [3 /*break*/, 4];
|
|
790
|
+
case 3:
|
|
791
|
+
e_4 = _k.sent();
|
|
792
|
+
this_1.context.logger.error("Error loading background-image ".concat(url));
|
|
793
|
+
return [3 /*break*/, 4];
|
|
794
|
+
case 4: return [3 /*break*/, 6];
|
|
795
|
+
case 5:
|
|
796
|
+
if ((0, image_1.isLinearGradient)(backgroundImage)) {
|
|
797
|
+
_f = (0, background_1.calculateBackgroundRendering)(container, index, [null, null, null]), path = _f[0], x = _f[1], y = _f[2], width = _f[3], height = _f[4];
|
|
798
|
+
_g = (0, gradient_1.calculateGradientDirection)(backgroundImage.angle, width, height), lineLength = _g[0], x0 = _g[1], x1 = _g[2], y0 = _g[3], y1 = _g[4];
|
|
799
|
+
boxs = (0, box_sizing_1.contentBox)(container);
|
|
800
|
+
canvas = document.createElement('canvas');
|
|
801
|
+
canvas.width = width;
|
|
802
|
+
canvas.height = height;
|
|
803
|
+
ctx = canvas.getContext('2d');
|
|
804
|
+
gradient_2 = ctx.createLinearGradient(x0, y0, x1, y1);
|
|
805
|
+
(0, gradient_1.processColorStops)(backgroundImage.stops, lineLength).forEach(function (colorStop) {
|
|
806
|
+
return gradient_2.addColorStop(colorStop.stop, (0, color_1.asString)(colorStop.color));
|
|
807
|
+
});
|
|
808
|
+
ctx.fillStyle = gradient_2;
|
|
809
|
+
ctx.fillRect(0, 0, width, height);
|
|
810
|
+
if (width > 0 && height > 0) {
|
|
811
|
+
pattern = ctx.createPattern(canvas, 'repeat');
|
|
812
|
+
pathTs = (0, path_1.transformPath)(path, -x, -y, 0, 0);
|
|
813
|
+
this_1.renderRepeat(boxs, ctx, pathTs, pattern);
|
|
814
|
+
}
|
|
815
|
+
dataURL = canvas.toDataURL('image/jpeg', 0.8);
|
|
816
|
+
// console.log(dataURL, 'dataURL', image)
|
|
817
|
+
ctx.restore();
|
|
818
|
+
xPt = this_1.pxToPt(x - this_1.options.x);
|
|
819
|
+
yPt = this_1.pxToPt(y - this_1.options.y);
|
|
820
|
+
widthPt = this_1.pxToPt(width);
|
|
821
|
+
heightPt = this_1.pxToPt(height);
|
|
822
|
+
this_1.addImagePdf(dataURL, 'JPEG', xPt, yPt, widthPt, heightPt);
|
|
823
|
+
}
|
|
824
|
+
else if ((0, image_1.isRadialGradient)(backgroundImage)) {
|
|
825
|
+
_h = (0, background_1.calculateBackgroundRendering)(container, index, [
|
|
826
|
+
null,
|
|
827
|
+
null,
|
|
828
|
+
null
|
|
829
|
+
]), path = _h[0], left = _h[1], top_1 = _h[2], width = _h[3], height = _h[4];
|
|
830
|
+
position = backgroundImage.position.length === 0 ? [length_percentage_1.FIFTY_PERCENT] : backgroundImage.position;
|
|
831
|
+
x = (0, length_percentage_1.getAbsoluteValue)(position[0], width);
|
|
832
|
+
y = (0, length_percentage_1.getAbsoluteValue)(position[position.length - 1], height);
|
|
833
|
+
_j = (0, gradient_1.calculateRadius)(backgroundImage, x, y, width, height), rx = _j[0], ry = _j[1];
|
|
834
|
+
ownerDocument = (_b = this_1.canvas.ownerDocument) !== null && _b !== void 0 ? _b : document;
|
|
835
|
+
canvas = ownerDocument.createElement('canvas');
|
|
836
|
+
canvas.width = Math.max(1, width);
|
|
837
|
+
canvas.height = Math.max(1, height);
|
|
838
|
+
ctx = canvas.getContext('2d');
|
|
839
|
+
if (rx > 0 && ry > 0) {
|
|
840
|
+
radialGradient_1 = ctx.createRadialGradient(x, y, 0, x, y, rx);
|
|
841
|
+
(0, gradient_1.processColorStops)(backgroundImage.stops, rx * 2).forEach(function (colorStop) {
|
|
842
|
+
return radialGradient_1.addColorStop(colorStop.stop, (0, color_1.asString)(colorStop.color));
|
|
843
|
+
});
|
|
844
|
+
pathTs = (0, path_1.transformPath)(path, -left, -top_1, 0, 0);
|
|
845
|
+
this_1.path(pathTs, ctx);
|
|
846
|
+
ctx.fillStyle = radialGradient_1;
|
|
847
|
+
if (rx !== ry) {
|
|
848
|
+
midX = 0 + 0.5 * width;
|
|
849
|
+
midY = 0 + 0.5 * height;
|
|
850
|
+
f = ry / rx;
|
|
851
|
+
invF = 1 / f;
|
|
852
|
+
ctx.save();
|
|
853
|
+
ctx.translate(midX, midY);
|
|
854
|
+
ctx.transform(1, 0, 0, f, 0, 0);
|
|
855
|
+
ctx.translate(-midX, -midY);
|
|
856
|
+
ctx.fillRect(0, invF * (0 - midY) + midY, width, height * invF);
|
|
857
|
+
// ctx.fillRect(left, invF * (top - midY) + midY, width, height * invF);
|
|
858
|
+
ctx.restore();
|
|
859
|
+
}
|
|
860
|
+
else {
|
|
861
|
+
ctx.fill();
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
dataURL = canvas.toDataURL('image/jpeg', 0.8);
|
|
865
|
+
xPt = this_1.pxToPt(left - this_1.options.x);
|
|
866
|
+
yPt = this_1.pxToPt(top_1 - this_1.options.y);
|
|
867
|
+
widthPt = this_1.pxToPt(width);
|
|
868
|
+
heightPt = this_1.pxToPt(height);
|
|
869
|
+
this_1.addImagePdf(dataURL, 'JPEG', xPt, yPt, widthPt, heightPt);
|
|
870
|
+
}
|
|
871
|
+
_k.label = 6;
|
|
872
|
+
case 6:
|
|
873
|
+
index--;
|
|
874
|
+
return [2 /*return*/];
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
};
|
|
878
|
+
this_1 = this;
|
|
879
|
+
_i = 0, _c = container.styles.backgroundImage.slice(0).reverse();
|
|
880
|
+
_d.label = 1;
|
|
881
|
+
case 1:
|
|
882
|
+
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
|
883
|
+
backgroundImage = _c[_i];
|
|
884
|
+
return [5 /*yield**/, _loop_1(backgroundImage)];
|
|
885
|
+
case 2:
|
|
886
|
+
_d.sent();
|
|
887
|
+
_d.label = 3;
|
|
888
|
+
case 3:
|
|
889
|
+
_i++;
|
|
890
|
+
return [3 /*break*/, 1];
|
|
891
|
+
case 4: return [2 /*return*/];
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
});
|
|
895
|
+
};
|
|
896
|
+
CanvasRenderer.prototype.renderSolidBorder = function (color, side, curvePoints) {
|
|
897
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
898
|
+
return __generator(this, function (_a) {
|
|
899
|
+
this.path((0, border_1.parsePathForBorder)(curvePoints, side));
|
|
900
|
+
this.context2dCtx.fillStyle = this.convertColor(color);
|
|
901
|
+
this.jspdfCtx.fill();
|
|
902
|
+
this.context2dCtx.fill();
|
|
903
|
+
return [2 /*return*/];
|
|
904
|
+
});
|
|
905
|
+
});
|
|
906
|
+
};
|
|
907
|
+
CanvasRenderer.prototype.renderDoubleBorder = function (color, width, side, curvePoints) {
|
|
908
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
909
|
+
var outerPaths, innerPaths;
|
|
910
|
+
return __generator(this, function (_a) {
|
|
911
|
+
switch (_a.label) {
|
|
912
|
+
case 0:
|
|
913
|
+
if (!(width < 3)) return [3 /*break*/, 2];
|
|
914
|
+
return [4 /*yield*/, this.renderSolidBorder(color, side, curvePoints)];
|
|
915
|
+
case 1:
|
|
916
|
+
_a.sent();
|
|
917
|
+
return [2 /*return*/];
|
|
918
|
+
case 2:
|
|
919
|
+
outerPaths = (0, border_1.parsePathForBorderDoubleOuter)(curvePoints, side);
|
|
920
|
+
this.path(outerPaths);
|
|
921
|
+
this.context2dCtx.fillStyle = this.convertColor(color);
|
|
922
|
+
this.context2dCtx.fill();
|
|
923
|
+
innerPaths = (0, border_1.parsePathForBorderDoubleInner)(curvePoints, side);
|
|
924
|
+
this.path(innerPaths);
|
|
925
|
+
this.context2dCtx.fill();
|
|
926
|
+
return [2 /*return*/];
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
});
|
|
930
|
+
};
|
|
931
|
+
CanvasRenderer.prototype.renderNodeBackgroundAndBorders = function (paint) {
|
|
932
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
933
|
+
var styles, hasBackground, borders, backgroundPaintingArea, foreignobjectrendering, side, _i, borders_1, border;
|
|
934
|
+
return __generator(this, function (_a) {
|
|
935
|
+
switch (_a.label) {
|
|
936
|
+
case 0:
|
|
937
|
+
this.applyEffects(paint.getEffects(2 /* EffectTarget.BACKGROUND_BORDERS */));
|
|
938
|
+
styles = paint.container.styles;
|
|
939
|
+
hasBackground = !(0, color_1.isTransparent)(styles.backgroundColor) || styles.backgroundImage.length;
|
|
940
|
+
borders = [
|
|
941
|
+
{ style: styles.borderTopStyle, color: styles.borderTopColor, width: styles.borderTopWidth },
|
|
942
|
+
{ style: styles.borderRightStyle, color: styles.borderRightColor, width: styles.borderRightWidth },
|
|
943
|
+
{ style: styles.borderBottomStyle, color: styles.borderBottomColor, width: styles.borderBottomWidth },
|
|
944
|
+
{ style: styles.borderLeftStyle, color: styles.borderLeftColor, width: styles.borderLeftWidth }
|
|
945
|
+
];
|
|
946
|
+
backgroundPaintingArea = calculateBackgroundCurvedPaintingArea((0, background_1.getBackgroundValueForIndex)(styles.backgroundClip, 0), paint.curves);
|
|
947
|
+
foreignobjectrendering = paint.container.foreignobjectrendering;
|
|
948
|
+
if (!(hasBackground || styles.boxShadow.length)) return [3 /*break*/, 2];
|
|
949
|
+
// console.log('render getFont', this.jspdfCtx.getFont());
|
|
950
|
+
if (!foreignobjectrendering) {
|
|
951
|
+
this.context2dCtx.save();
|
|
952
|
+
this.path(backgroundPaintingArea);
|
|
953
|
+
this.context2dCtx.clip();
|
|
954
|
+
if (!(0, color_1.isTransparent)(styles.backgroundColor)) {
|
|
955
|
+
this.context2dCtx.fillStyle = this.convertColor(styles.backgroundColor);
|
|
956
|
+
this.context2dCtx.fill();
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
return [4 /*yield*/, this.renderBackgroundImage(paint.container)];
|
|
960
|
+
case 1:
|
|
961
|
+
_a.sent();
|
|
962
|
+
this.context2dCtx.restore();
|
|
963
|
+
this.resetJsPDFFont();
|
|
964
|
+
_a.label = 2;
|
|
965
|
+
case 2:
|
|
966
|
+
side = 0;
|
|
967
|
+
_i = 0, borders_1 = borders;
|
|
968
|
+
_a.label = 3;
|
|
969
|
+
case 3:
|
|
970
|
+
if (!(_i < borders_1.length)) return [3 /*break*/, 13];
|
|
971
|
+
border = borders_1[_i];
|
|
972
|
+
if (!(border.style !== 0 /* BORDER_STYLE.NONE */ && !(0, color_1.isTransparent)(border.color) && border.width > 0)) return [3 /*break*/, 11];
|
|
973
|
+
if (!(border.style === 2 /* BORDER_STYLE.DASHED */)) return [3 /*break*/, 5];
|
|
974
|
+
return [4 /*yield*/, this.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 2 /* BORDER_STYLE.DASHED */)];
|
|
975
|
+
case 4:
|
|
976
|
+
_a.sent();
|
|
977
|
+
return [3 /*break*/, 11];
|
|
978
|
+
case 5:
|
|
979
|
+
if (!(border.style === 3 /* BORDER_STYLE.DOTTED */)) return [3 /*break*/, 7];
|
|
980
|
+
return [4 /*yield*/, this.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 3 /* BORDER_STYLE.DOTTED */)];
|
|
981
|
+
case 6:
|
|
982
|
+
_a.sent();
|
|
983
|
+
return [3 /*break*/, 11];
|
|
984
|
+
case 7:
|
|
985
|
+
if (!(border.style === 4 /* BORDER_STYLE.DOUBLE */)) return [3 /*break*/, 9];
|
|
986
|
+
return [4 /*yield*/, this.renderDoubleBorder(border.color, border.width, side, paint.curves)];
|
|
987
|
+
case 8:
|
|
988
|
+
_a.sent();
|
|
989
|
+
return [3 /*break*/, 11];
|
|
990
|
+
case 9:
|
|
991
|
+
if (!!foreignobjectrendering) return [3 /*break*/, 11];
|
|
992
|
+
return [4 /*yield*/, this.renderSolidBorder(border.color, side, paint.curves)];
|
|
993
|
+
case 10:
|
|
994
|
+
_a.sent();
|
|
995
|
+
_a.label = 11;
|
|
996
|
+
case 11:
|
|
997
|
+
side++;
|
|
998
|
+
_a.label = 12;
|
|
999
|
+
case 12:
|
|
1000
|
+
_i++;
|
|
1001
|
+
return [3 /*break*/, 3];
|
|
1002
|
+
case 13: return [2 /*return*/];
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
});
|
|
1006
|
+
};
|
|
1007
|
+
CanvasRenderer.prototype.renderDashedDottedBorder = function (color, width, side, curvePoints, style) {
|
|
1008
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1009
|
+
var strokePaths, boxPaths, startX, startY, endX, endY, length, dashLength, spaceLength, useLineDash, multiplier, numberOfDashes, minSpace, maxSpace, path1, path2, path1, path2;
|
|
1010
|
+
return __generator(this, function (_a) {
|
|
1011
|
+
this.context2dCtx.save();
|
|
1012
|
+
strokePaths = (0, border_1.parsePathForBorderStroke)(curvePoints, side);
|
|
1013
|
+
boxPaths = (0, border_1.parsePathForBorder)(curvePoints, side);
|
|
1014
|
+
if (style === 2 /* BORDER_STYLE.DASHED */) {
|
|
1015
|
+
this.path(boxPaths);
|
|
1016
|
+
this.context2dCtx.clip();
|
|
1017
|
+
}
|
|
1018
|
+
if ((0, bezier_curve_1.isBezierCurve)(boxPaths[0])) {
|
|
1019
|
+
startX = boxPaths[0].start.x;
|
|
1020
|
+
startY = boxPaths[0].start.y;
|
|
1021
|
+
}
|
|
1022
|
+
else {
|
|
1023
|
+
startX = boxPaths[0].x;
|
|
1024
|
+
startY = boxPaths[0].y;
|
|
1025
|
+
}
|
|
1026
|
+
if ((0, bezier_curve_1.isBezierCurve)(boxPaths[1])) {
|
|
1027
|
+
endX = boxPaths[1].end.x;
|
|
1028
|
+
endY = boxPaths[1].end.y;
|
|
1029
|
+
}
|
|
1030
|
+
else {
|
|
1031
|
+
endX = boxPaths[1].x;
|
|
1032
|
+
endY = boxPaths[1].y;
|
|
1033
|
+
}
|
|
1034
|
+
if (side === 0 || side === 2) {
|
|
1035
|
+
length = Math.abs(startX - endX);
|
|
1036
|
+
}
|
|
1037
|
+
else {
|
|
1038
|
+
length = Math.abs(startY - endY);
|
|
1039
|
+
}
|
|
1040
|
+
this.context2dCtx.beginPath();
|
|
1041
|
+
if (style === 3 /* BORDER_STYLE.DOTTED */) {
|
|
1042
|
+
this.formatPath(strokePaths);
|
|
1043
|
+
}
|
|
1044
|
+
else {
|
|
1045
|
+
this.formatPath(boxPaths.slice(0, 2));
|
|
1046
|
+
}
|
|
1047
|
+
dashLength = width < 3 ? width * 3 : width * 2;
|
|
1048
|
+
spaceLength = width < 3 ? width * 2 : width;
|
|
1049
|
+
if (style === 3 /* BORDER_STYLE.DOTTED */) {
|
|
1050
|
+
dashLength = width;
|
|
1051
|
+
spaceLength = width;
|
|
1052
|
+
}
|
|
1053
|
+
useLineDash = true;
|
|
1054
|
+
if (length <= dashLength * 2) {
|
|
1055
|
+
useLineDash = false;
|
|
1056
|
+
}
|
|
1057
|
+
else if (length <= dashLength * 2 + spaceLength) {
|
|
1058
|
+
multiplier = length / (2 * dashLength + spaceLength);
|
|
1059
|
+
dashLength *= multiplier;
|
|
1060
|
+
spaceLength *= multiplier;
|
|
1061
|
+
}
|
|
1062
|
+
else {
|
|
1063
|
+
numberOfDashes = Math.floor((length + spaceLength) / (dashLength + spaceLength));
|
|
1064
|
+
minSpace = (length - numberOfDashes * dashLength) / (numberOfDashes - 1);
|
|
1065
|
+
maxSpace = (length - (numberOfDashes + 1) * dashLength) / numberOfDashes;
|
|
1066
|
+
spaceLength =
|
|
1067
|
+
maxSpace <= 0 || Math.abs(spaceLength - minSpace) < Math.abs(spaceLength - maxSpace)
|
|
1068
|
+
? minSpace
|
|
1069
|
+
: maxSpace;
|
|
1070
|
+
}
|
|
1071
|
+
if (useLineDash) {
|
|
1072
|
+
if (style === 3 /* BORDER_STYLE.DOTTED */) {
|
|
1073
|
+
this.context2dCtx.setLineDash([0, dashLength + spaceLength]);
|
|
1074
|
+
}
|
|
1075
|
+
else {
|
|
1076
|
+
this.context2dCtx.setLineDash([dashLength, spaceLength]);
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
if (style === 3 /* BORDER_STYLE.DOTTED */) {
|
|
1080
|
+
this.context2dCtx.lineCap = 'round';
|
|
1081
|
+
this.context2dCtx.lineWidth = width;
|
|
1082
|
+
}
|
|
1083
|
+
else {
|
|
1084
|
+
this.context2dCtx.lineWidth = width * 2 + 1.1;
|
|
1085
|
+
}
|
|
1086
|
+
this.context2dCtx.strokeStyle = (0, color_1.asString)(color);
|
|
1087
|
+
this.context2dCtx.stroke();
|
|
1088
|
+
this.context2dCtx.setLineDash([]);
|
|
1089
|
+
// dashed round edge gap
|
|
1090
|
+
if (style === 2 /* BORDER_STYLE.DASHED */) {
|
|
1091
|
+
if ((0, bezier_curve_1.isBezierCurve)(boxPaths[0])) {
|
|
1092
|
+
path1 = boxPaths[3];
|
|
1093
|
+
path2 = boxPaths[0];
|
|
1094
|
+
this.context2dCtx.beginPath();
|
|
1095
|
+
this.formatPath([new vector_1.Vector(path1.end.x, path1.end.y), new vector_1.Vector(path2.start.x, path2.start.y)]);
|
|
1096
|
+
this.context2dCtx.stroke();
|
|
1097
|
+
}
|
|
1098
|
+
if ((0, bezier_curve_1.isBezierCurve)(boxPaths[1])) {
|
|
1099
|
+
path1 = boxPaths[1];
|
|
1100
|
+
path2 = boxPaths[2];
|
|
1101
|
+
this.context2dCtx.beginPath();
|
|
1102
|
+
this.formatPath([new vector_1.Vector(path1.end.x, path1.end.y), new vector_1.Vector(path2.start.x, path2.start.y)]);
|
|
1103
|
+
this.context2dCtx.stroke();
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
this.context2dCtx.restore();
|
|
1107
|
+
return [2 /*return*/];
|
|
1108
|
+
});
|
|
1109
|
+
});
|
|
1110
|
+
};
|
|
1111
|
+
CanvasRenderer.prototype.addPage = function (offsetY) {
|
|
1112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1113
|
+
return __generator(this, function (_a) {
|
|
1114
|
+
this.context2dCtx.translate(0, -offsetY);
|
|
1115
|
+
this.jspdfCtx.addPage();
|
|
1116
|
+
return [2 /*return*/];
|
|
1117
|
+
});
|
|
1118
|
+
});
|
|
1119
|
+
};
|
|
1120
|
+
CanvasRenderer.prototype.renderPage = function (element, pageNum) {
|
|
1121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1122
|
+
var cfg, pageW, pageH, mt, mb, bx, by, bw, bh, stack, headerText, headerPos, footerText, footerPos;
|
|
1123
|
+
return __generator(this, function (_a) {
|
|
1124
|
+
switch (_a.label) {
|
|
1125
|
+
case 0:
|
|
1126
|
+
cfg = this.options.pageConfig;
|
|
1127
|
+
pageW = this.jspdfCtx.internal.pageSize.getWidth();
|
|
1128
|
+
pageH = this.jspdfCtx.internal.pageSize.getHeight();
|
|
1129
|
+
mt = 0;
|
|
1130
|
+
mb = 0;
|
|
1131
|
+
if (this.options.backgroundColor) {
|
|
1132
|
+
this.jspdfCtx.setFillColor(this.convertColor(this.options.backgroundColor));
|
|
1133
|
+
bx = this.safe(this.options.x);
|
|
1134
|
+
by = this.safe(this.options.y);
|
|
1135
|
+
bw = Math.max(1, this.safe(this.options.width, 1));
|
|
1136
|
+
bh = Math.max(1, this.safe(this.options.height, 1));
|
|
1137
|
+
this.jspdfCtx.rect(bx, by, bw, bh, 'F');
|
|
1138
|
+
}
|
|
1139
|
+
stack = (0, stacking_context_1.parseStackingContexts)(element);
|
|
1140
|
+
return [4 /*yield*/, this.renderStack(stack)];
|
|
1141
|
+
case 1:
|
|
1142
|
+
_a.sent();
|
|
1143
|
+
this.applyEffects([]);
|
|
1144
|
+
if (cfg === null || cfg === void 0 ? void 0 : cfg.header) {
|
|
1145
|
+
if (typeof cfg.header.content === 'function') {
|
|
1146
|
+
cfg.header.content(this, String(pageNum));
|
|
1147
|
+
}
|
|
1148
|
+
else {
|
|
1149
|
+
headerText = String(cfg.header.content)
|
|
1150
|
+
.replace('${currentPage}', String(pageNum))
|
|
1151
|
+
.replace('${totalPages}', String(this.totalPages));
|
|
1152
|
+
this.jspdfCtx.setFontSize(this.safe(this.pxToPt(cfg.header.contentFontSize), 1));
|
|
1153
|
+
this.setTextColorFromString(cfg.header.contentColor);
|
|
1154
|
+
headerPos = this.computeContentPosition(cfg.header.contentPosition, pageW, pageH, cfg.header.height, mt, mb, 'header', cfg.header.padding);
|
|
1155
|
+
this.textPdf(headerText, headerPos.x, headerPos.y, headerPos.align);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
if (cfg === null || cfg === void 0 ? void 0 : cfg.footer) {
|
|
1159
|
+
if (typeof cfg.footer.content === 'function') {
|
|
1160
|
+
cfg.footer.content(this, String(pageNum));
|
|
1161
|
+
}
|
|
1162
|
+
else {
|
|
1163
|
+
footerText = String(cfg.footer.content)
|
|
1164
|
+
.replace('${currentPage}', String(pageNum))
|
|
1165
|
+
.replace('${totalPages}', String(this.totalPages));
|
|
1166
|
+
this.jspdfCtx.setFontSize(this.safe(this.pxToPt(cfg.footer.contentFontSize), 1));
|
|
1167
|
+
this.setTextColorFromString(cfg.footer.contentColor);
|
|
1168
|
+
footerPos = this.computeContentPosition(cfg.footer.contentPosition, pageW, pageH, cfg.footer.height, mt, mb, 'footer', cfg.footer.padding);
|
|
1169
|
+
this.textPdf(footerText, footerPos.x, footerPos.y, footerPos.align);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return [2 /*return*/];
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
});
|
|
1176
|
+
};
|
|
1177
|
+
CanvasRenderer.prototype.setTotalPages = function (total) {
|
|
1178
|
+
this.totalPages = total;
|
|
1179
|
+
};
|
|
1180
|
+
CanvasRenderer.prototype.setTextColorFromString = function (color) {
|
|
1181
|
+
var _a;
|
|
1182
|
+
var named = {
|
|
1183
|
+
black: [0, 0, 0],
|
|
1184
|
+
white: [255, 255, 255],
|
|
1185
|
+
red: [255, 0, 0],
|
|
1186
|
+
green: [0, 128, 0],
|
|
1187
|
+
blue: [0, 0, 255],
|
|
1188
|
+
gray: [128, 128, 128]
|
|
1189
|
+
};
|
|
1190
|
+
var r = 0, g = 0, b = 0;
|
|
1191
|
+
var c = (color === null || color === void 0 ? void 0 : color.toLowerCase()) || 'black';
|
|
1192
|
+
if (c in named) {
|
|
1193
|
+
_a = named[c], r = _a[0], g = _a[1], b = _a[2];
|
|
1194
|
+
}
|
|
1195
|
+
else if (c.startsWith('#') && (c.length === 7 || c.length === 4)) {
|
|
1196
|
+
var hex = c.length === 4 ? "#".concat(c[1]).concat(c[1]).concat(c[2]).concat(c[2]).concat(c[3]).concat(c[3]) : c;
|
|
1197
|
+
r = parseInt(hex.slice(1, 3), 16);
|
|
1198
|
+
g = parseInt(hex.slice(3, 5), 16);
|
|
1199
|
+
b = parseInt(hex.slice(5, 7), 16);
|
|
1200
|
+
}
|
|
1201
|
+
this.jspdfCtx.setTextColor(r, g, b);
|
|
1202
|
+
};
|
|
1203
|
+
CanvasRenderer.prototype.safe = function (n, min) {
|
|
1204
|
+
if (min === void 0) { min = 0; }
|
|
1205
|
+
var v = Number(n);
|
|
1206
|
+
return Number.isFinite(v) ? v : min;
|
|
1207
|
+
};
|
|
1208
|
+
CanvasRenderer.prototype.textPdf = function (text, x, y, align) {
|
|
1209
|
+
var sx = this.safe(x);
|
|
1210
|
+
var sy = this.safe(y);
|
|
1211
|
+
this.jspdfCtx.text(String(text), sx, sy, { align: align });
|
|
1212
|
+
};
|
|
1213
|
+
CanvasRenderer.prototype.computeContentPosition = function (pos, pageW, pageH, areaH, mt, mb, area, paddingPx) {
|
|
1214
|
+
var _this = this;
|
|
1215
|
+
var _a = (paddingPx !== null && paddingPx !== void 0 ? paddingPx : [24, 24, 24, 24]).map(function (v) { return _this.pxToPt(v); }), pt = _a[0], pr = _a[1], pb = _a[2], pl = _a[3];
|
|
1216
|
+
var areaHPt = this.pxToPt(areaH);
|
|
1217
|
+
var mtPt = this.pxToPt(mt);
|
|
1218
|
+
var mbPt = this.pxToPt(mb);
|
|
1219
|
+
if (Array.isArray(pos) && pos.length >= 2) {
|
|
1220
|
+
return { x: this.pxToPt(pos[0]), y: this.pxToPt(pos[1]), align: 'left' };
|
|
1221
|
+
}
|
|
1222
|
+
if (area === 'header') {
|
|
1223
|
+
switch (pos) {
|
|
1224
|
+
case 'center':
|
|
1225
|
+
return {
|
|
1226
|
+
x: pageW / 2,
|
|
1227
|
+
y: mtPt + pt + (areaHPt - pt - pb) / 2,
|
|
1228
|
+
align: 'center'
|
|
1229
|
+
};
|
|
1230
|
+
case 'centerLeft':
|
|
1231
|
+
return { x: pl, y: mtPt + pt + (areaHPt - pt - pb) / 2, align: 'left' };
|
|
1232
|
+
case 'centerRight':
|
|
1233
|
+
return { x: pageW - pr, y: mtPt + pt + (areaHPt - pt - pb) / 2, align: 'right' };
|
|
1234
|
+
case 'centerTop':
|
|
1235
|
+
return { x: pageW / 2, y: mtPt + pt, align: 'center' };
|
|
1236
|
+
case 'centerBottom':
|
|
1237
|
+
return { x: pageW / 2, y: mtPt + areaHPt - pb, align: 'center' };
|
|
1238
|
+
case 'leftTop':
|
|
1239
|
+
return { x: pl, y: mtPt + pt, align: 'left' };
|
|
1240
|
+
case 'leftBottom':
|
|
1241
|
+
return { x: pl, y: mtPt + areaHPt - pb, align: 'left' };
|
|
1242
|
+
case 'rightTop':
|
|
1243
|
+
return { x: pageW - pr, y: mtPt + pt, align: 'right' };
|
|
1244
|
+
case 'rightBottom':
|
|
1245
|
+
return { x: pageW - pr, y: mtPt + areaHPt - pb, align: 'right' };
|
|
1246
|
+
default:
|
|
1247
|
+
return { x: pl, y: mtPt + pt, align: 'left' };
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
else {
|
|
1251
|
+
switch (pos) {
|
|
1252
|
+
case 'center':
|
|
1253
|
+
return {
|
|
1254
|
+
x: pageW / 2,
|
|
1255
|
+
y: pageH - mbPt - areaHPt + pt + (areaHPt - pt - pb) / 2,
|
|
1256
|
+
align: 'center'
|
|
1257
|
+
};
|
|
1258
|
+
case 'centerLeft':
|
|
1259
|
+
return { x: pl, y: pageH - mbPt - areaHPt + pt + (areaHPt - pt - pb) / 2, align: 'left' };
|
|
1260
|
+
case 'centerRight':
|
|
1261
|
+
return { x: pageW - pr, y: pageH - mbPt - areaHPt + pt + (areaHPt - pt - pb) / 2, align: 'right' };
|
|
1262
|
+
case 'centerTop':
|
|
1263
|
+
return { x: pageW / 2, y: pageH - mbPt - areaHPt + pt, align: 'center' };
|
|
1264
|
+
case 'centerBottom':
|
|
1265
|
+
return { x: pageW / 2, y: pageH - mbPt - pb, align: 'center' };
|
|
1266
|
+
case 'leftTop':
|
|
1267
|
+
return { x: pl, y: pageH - mbPt - areaHPt + pt, align: 'left' };
|
|
1268
|
+
case 'leftBottom':
|
|
1269
|
+
return { x: pl, y: pageH - mbPt - pb, align: 'left' };
|
|
1270
|
+
case 'rightTop':
|
|
1271
|
+
return { x: pageW - pr, y: pageH - mbPt - areaHPt + pt, align: 'right' };
|
|
1272
|
+
case 'rightBottom':
|
|
1273
|
+
return { x: pageW - pr, y: pageH - mbPt - pb, align: 'right' };
|
|
1274
|
+
default:
|
|
1275
|
+
return { x: pl, y: pageH - mbPt - pb, align: 'left' };
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
CanvasRenderer.prototype.addImagePdf = function (img, format, x, y, w, h) {
|
|
1280
|
+
var sx = this.safe(x);
|
|
1281
|
+
var sy = this.safe(y);
|
|
1282
|
+
var sw = Math.max(1, this.safe(w, 1));
|
|
1283
|
+
var sh = Math.max(1, this.safe(h, 1));
|
|
1284
|
+
// draw a big image,jsPDF:Error: Invalid image dimensions: width and height must be positive numbers.
|
|
1285
|
+
this.jspdfCtx.addImage(img, format, sx, sy, sw, sh, '', 'FAST');
|
|
1286
|
+
};
|
|
1287
|
+
CanvasRenderer.prototype.output = function () {
|
|
1288
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1289
|
+
var pdfBlob;
|
|
1290
|
+
return __generator(this, function (_a) {
|
|
1291
|
+
pdfBlob = this.jspdfCtx.output('blob');
|
|
1292
|
+
return [2 /*return*/, pdfBlob];
|
|
1293
|
+
});
|
|
1294
|
+
});
|
|
1295
|
+
};
|
|
1296
|
+
return CanvasRenderer;
|
|
1297
|
+
}(renderer_1.Renderer));
|
|
1298
|
+
exports.CanvasRenderer = CanvasRenderer;
|
|
1299
|
+
var isTextInputElement = function (container) {
|
|
1300
|
+
if (container instanceof textarea_element_container_1.TextareaElementContainer) {
|
|
1301
|
+
return true;
|
|
1302
|
+
}
|
|
1303
|
+
else if (container instanceof select_element_container_1.SelectElementContainer) {
|
|
1304
|
+
return true;
|
|
1305
|
+
}
|
|
1306
|
+
else if (container instanceof input_element_container_1.InputElementContainer && container.type !== input_element_container_1.RADIO && container.type !== input_element_container_1.CHECKBOX) {
|
|
1307
|
+
return true;
|
|
1308
|
+
}
|
|
1309
|
+
return false;
|
|
1310
|
+
};
|
|
1311
|
+
var calculateBackgroundCurvedPaintingArea = function (clip, curves) {
|
|
1312
|
+
switch (clip) {
|
|
1313
|
+
case 0 /* BACKGROUND_CLIP.BORDER_BOX */:
|
|
1314
|
+
return (0, bound_curves_1.calculateBorderBoxPath)(curves);
|
|
1315
|
+
case 2 /* BACKGROUND_CLIP.CONTENT_BOX */:
|
|
1316
|
+
return (0, bound_curves_1.calculateContentBoxPath)(curves);
|
|
1317
|
+
case 1 /* BACKGROUND_CLIP.PADDING_BOX */:
|
|
1318
|
+
default:
|
|
1319
|
+
return (0, bound_curves_1.calculatePaddingBoxPath)(curves);
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
var canvasTextAlign = function (textAlign) {
|
|
1323
|
+
switch (textAlign) {
|
|
1324
|
+
case 1 /* TEXT_ALIGN.CENTER */:
|
|
1325
|
+
return 'center';
|
|
1326
|
+
case 2 /* TEXT_ALIGN.RIGHT */:
|
|
1327
|
+
return 'right';
|
|
1328
|
+
case 0 /* TEXT_ALIGN.LEFT */:
|
|
1329
|
+
default:
|
|
1330
|
+
return 'left';
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
// see https://github.com/niklasvh/html2canvas/pull/2645
|
|
1334
|
+
var iOSBrokenFonts = ['-apple-system', 'system-ui'];
|
|
1335
|
+
var fixIOSSystemFonts = function (fontFamilies) {
|
|
1336
|
+
return /iPhone OS 15_(0|1)/.test(window.navigator.userAgent)
|
|
1337
|
+
? fontFamilies.filter(function (fontFamily) { return iOSBrokenFonts.indexOf(fontFamily) === -1; })
|
|
1338
|
+
: fontFamilies;
|
|
1339
|
+
};
|
|
1340
|
+
//# sourceMappingURL=pdf-renderer.js.map
|