html2canvas-pro 2.0.4 → 2.1.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/README.md +8 -6
- package/dist/html2canvas-pro.esm.js +10018 -9922
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +10017 -9922
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +5 -5
- package/dist/lib/config.js +3 -4
- package/dist/lib/core/bitwise.js +0 -1
- package/dist/lib/core/cache-storage.js +34 -48
- package/dist/lib/core/context.js +0 -1
- package/dist/lib/core/debugger.js +0 -1
- package/dist/lib/core/features.js +0 -1
- package/dist/lib/core/logger.js +0 -1
- package/dist/lib/core/origin-checker.js +0 -1
- package/dist/lib/core/performance-monitor.js +1 -24
- package/dist/lib/core/render-element.js +210 -0
- package/dist/lib/core/util.js +0 -1
- package/dist/lib/core/validator.js +0 -1
- package/dist/lib/css/index.js +149 -90
- package/dist/lib/css/layout/bounds.js +0 -1
- package/dist/lib/css/layout/text.js +0 -1
- package/dist/lib/css/{ITypeDescriptor.js → property-descriptor.js} +0 -1
- package/dist/lib/css/property-descriptors/background-clip.js +0 -1
- package/dist/lib/css/property-descriptors/background-color.js +0 -1
- package/dist/lib/css/property-descriptors/background-image.js +0 -1
- package/dist/lib/css/property-descriptors/background-origin.js +0 -1
- package/dist/lib/css/property-descriptors/background-position.js +0 -1
- package/dist/lib/css/property-descriptors/background-repeat.js +0 -1
- package/dist/lib/css/property-descriptors/background-size.js +0 -1
- package/dist/lib/css/property-descriptors/border-color.js +0 -1
- package/dist/lib/css/property-descriptors/border-radius.js +0 -1
- package/dist/lib/css/property-descriptors/border-style.js +0 -1
- package/dist/lib/css/property-descriptors/border-width.js +0 -1
- package/dist/lib/css/property-descriptors/box-shadow.js +0 -1
- package/dist/lib/css/property-descriptors/clip-path.js +0 -1
- package/dist/lib/css/property-descriptors/color.js +0 -1
- package/dist/lib/css/property-descriptors/content.js +0 -1
- package/dist/lib/css/property-descriptors/counter-increment.js +0 -1
- package/dist/lib/css/property-descriptors/counter-reset.js +0 -1
- package/dist/lib/css/property-descriptors/direction.js +0 -1
- package/dist/lib/css/property-descriptors/display.js +0 -1
- package/dist/lib/css/property-descriptors/duration.js +0 -1
- package/dist/lib/css/property-descriptors/float.js +0 -1
- package/dist/lib/css/property-descriptors/font-family.js +0 -1
- package/dist/lib/css/property-descriptors/font-size.js +0 -1
- package/dist/lib/css/property-descriptors/font-style.js +0 -1
- package/dist/lib/css/property-descriptors/font-variant.js +0 -1
- package/dist/lib/css/property-descriptors/font-weight.js +0 -1
- package/dist/lib/css/property-descriptors/image-rendering.js +0 -1
- package/dist/lib/css/property-descriptors/letter-spacing.js +0 -1
- package/dist/lib/css/property-descriptors/line-break.js +0 -1
- package/dist/lib/css/property-descriptors/line-height.js +0 -1
- package/dist/lib/css/property-descriptors/list-style-image.js +0 -1
- package/dist/lib/css/property-descriptors/list-style-position.js +0 -1
- package/dist/lib/css/property-descriptors/list-style-type.js +0 -1
- package/dist/lib/css/property-descriptors/margin.js +0 -1
- package/dist/lib/css/property-descriptors/mix-blend-mode.js +31 -0
- package/dist/lib/css/property-descriptors/object-fit.js +0 -1
- package/dist/lib/css/property-descriptors/opacity.js +0 -1
- package/dist/lib/css/property-descriptors/overflow-wrap.js +0 -1
- package/dist/lib/css/property-descriptors/overflow.js +0 -1
- package/dist/lib/css/property-descriptors/padding.js +0 -1
- package/dist/lib/css/property-descriptors/paint-order.js +0 -1
- package/dist/lib/css/property-descriptors/position.js +0 -1
- package/dist/lib/css/property-descriptors/quotes.js +0 -1
- package/dist/lib/css/property-descriptors/rotate.js +0 -1
- package/dist/lib/css/property-descriptors/text-align.js +0 -1
- package/dist/lib/css/property-descriptors/text-decoration-color.js +0 -1
- package/dist/lib/css/property-descriptors/text-decoration-line.js +0 -1
- package/dist/lib/css/property-descriptors/text-decoration-style.js +0 -1
- package/dist/lib/css/property-descriptors/text-decoration-thickness.js +0 -1
- package/dist/lib/css/property-descriptors/text-overflow.js +0 -1
- package/dist/lib/css/property-descriptors/text-shadow.js +0 -1
- package/dist/lib/css/property-descriptors/text-transform.js +0 -1
- package/dist/lib/css/property-descriptors/text-underline-offset.js +0 -1
- package/dist/lib/css/property-descriptors/transform-origin.js +0 -1
- package/dist/lib/css/property-descriptors/transform.js +0 -1
- package/dist/lib/css/property-descriptors/visibility.js +0 -1
- package/dist/lib/css/property-descriptors/webkit-line-clamp.js +0 -1
- package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js +0 -1
- package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js +0 -1
- package/dist/lib/css/property-descriptors/word-break.js +0 -1
- package/dist/lib/css/property-descriptors/writing-mode.js +0 -1
- package/dist/lib/css/property-descriptors/z-index.js +0 -1
- package/dist/lib/css/syntax/parser.js +0 -1
- package/dist/lib/css/syntax/tokenizer.js +14 -1
- package/dist/lib/css/{IPropertyDescriptor.js → type-descriptor.js} +0 -1
- package/dist/lib/css/types/angle.js +0 -1
- package/dist/lib/css/types/color-math.js +0 -1
- package/dist/lib/css/types/color-spaces/a98.js +0 -1
- package/dist/lib/css/types/color-spaces/p3.js +0 -1
- package/dist/lib/css/types/color-spaces/pro-photo.js +0 -1
- package/dist/lib/css/types/color-spaces/rec2020.js +0 -1
- package/dist/lib/css/types/color-spaces/srgb.js +0 -1
- package/dist/lib/css/types/color-utilities.js +0 -1
- package/dist/lib/css/types/color.js +0 -1
- package/dist/lib/css/types/functions/-prefix-linear-gradient.js +0 -1
- package/dist/lib/css/types/functions/-prefix-radial-gradient.js +0 -1
- package/dist/lib/css/types/functions/-webkit-gradient.js +0 -1
- package/dist/lib/css/types/functions/counter.js +0 -1
- package/dist/lib/css/types/functions/gradient.js +0 -1
- package/dist/lib/css/types/functions/linear-gradient.js +0 -1
- package/dist/lib/css/types/functions/radial-gradient.js +0 -1
- package/dist/lib/css/types/image.js +0 -1
- package/dist/lib/css/types/index.js +0 -1
- package/dist/lib/css/types/length-percentage.js +0 -1
- package/dist/lib/css/types/length.js +0 -1
- package/dist/lib/css/types/time.js +0 -1
- package/dist/lib/dom/document-cloner.js +27 -22
- package/dist/lib/dom/dom-normalizer.js +0 -1
- package/dist/lib/dom/element-container.js +7 -6
- package/dist/lib/dom/elements/li-element-container.js +0 -1
- package/dist/lib/dom/elements/ol-element-container.js +0 -1
- package/dist/lib/dom/elements/select-element-container.js +0 -1
- package/dist/lib/dom/elements/textarea-element-container.js +0 -1
- package/dist/lib/dom/node-parser.js +37 -53
- package/dist/lib/dom/node-type-guards.js +62 -25
- package/dist/lib/dom/replaced-elements/canvas-element-container.js +0 -1
- package/dist/lib/dom/replaced-elements/iframe-element-container.js +0 -1
- package/dist/lib/dom/replaced-elements/image-element-container.js +0 -1
- package/dist/lib/dom/replaced-elements/index.js +0 -1
- package/dist/lib/dom/replaced-elements/input-element-container.js +0 -1
- package/dist/lib/dom/replaced-elements/pseudo-elements.js +0 -1
- package/dist/lib/dom/replaced-elements/svg-element-container.js +0 -1
- package/dist/lib/dom/text-container.js +0 -1
- package/dist/lib/index.js +32 -210
- package/dist/lib/invariant.js +0 -1
- package/dist/lib/options.js +2 -0
- package/dist/lib/render/background.js +0 -1
- package/dist/lib/render/bezier-curve.js +0 -1
- package/dist/lib/render/border.js +0 -1
- package/dist/lib/render/bound-curves.js +0 -1
- package/dist/lib/render/box-sizing.js +0 -1
- package/dist/lib/render/canvas/background-renderer.js +2 -24
- package/dist/lib/render/canvas/border-renderer.js +0 -1
- package/dist/lib/render/canvas/canvas-path.js +25 -0
- package/dist/lib/render/canvas/canvas-renderer.js +23 -96
- package/dist/lib/render/canvas/effects-renderer.js +3 -1
- package/dist/lib/render/canvas/foreignobject-renderer.js +8 -16
- package/dist/lib/render/canvas/text-renderer.js +61 -117
- package/dist/lib/render/effects.js +11 -2
- package/dist/lib/render/font-metrics.js +0 -1
- package/dist/lib/render/object-fit.js +87 -0
- package/dist/lib/render/path.js +0 -1
- package/dist/lib/render/renderer-interface.js +0 -1
- package/dist/lib/render/stacking-context.js +16 -8
- package/dist/lib/render/vector.js +0 -1
- package/dist/types/core/cache-storage.d.ts +5 -6
- package/dist/types/core/performance-monitor.d.ts +0 -11
- package/dist/types/core/render-element.d.ts +3 -0
- package/dist/types/css/index.d.ts +3 -0
- package/dist/types/css/property-descriptors/background-clip.d.ts +1 -1
- package/dist/types/css/property-descriptors/background-color.d.ts +1 -1
- package/dist/types/css/property-descriptors/background-image.d.ts +1 -1
- package/dist/types/css/property-descriptors/background-origin.d.ts +1 -1
- package/dist/types/css/property-descriptors/background-position.d.ts +1 -1
- package/dist/types/css/property-descriptors/background-repeat.d.ts +1 -1
- package/dist/types/css/property-descriptors/background-size.d.ts +1 -1
- package/dist/types/css/property-descriptors/border-color.d.ts +1 -1
- package/dist/types/css/property-descriptors/border-radius.d.ts +1 -1
- package/dist/types/css/property-descriptors/border-style.d.ts +1 -1
- package/dist/types/css/property-descriptors/border-width.d.ts +1 -1
- package/dist/types/css/property-descriptors/box-shadow.d.ts +1 -1
- package/dist/types/css/property-descriptors/clip-path.d.ts +1 -1
- package/dist/types/css/property-descriptors/color.d.ts +1 -1
- package/dist/types/css/property-descriptors/content.d.ts +1 -1
- package/dist/types/css/property-descriptors/counter-increment.d.ts +1 -1
- package/dist/types/css/property-descriptors/counter-reset.d.ts +1 -1
- package/dist/types/css/property-descriptors/direction.d.ts +1 -1
- package/dist/types/css/property-descriptors/display.d.ts +1 -1
- package/dist/types/css/property-descriptors/duration.d.ts +1 -1
- package/dist/types/css/property-descriptors/float.d.ts +1 -1
- package/dist/types/css/property-descriptors/font-family.d.ts +1 -1
- package/dist/types/css/property-descriptors/font-size.d.ts +1 -1
- package/dist/types/css/property-descriptors/font-style.d.ts +1 -1
- package/dist/types/css/property-descriptors/font-variant.d.ts +1 -1
- package/dist/types/css/property-descriptors/font-weight.d.ts +1 -1
- package/dist/types/css/property-descriptors/image-rendering.d.ts +1 -1
- package/dist/types/css/property-descriptors/letter-spacing.d.ts +1 -1
- package/dist/types/css/property-descriptors/line-break.d.ts +1 -1
- package/dist/types/css/property-descriptors/line-height.d.ts +1 -1
- package/dist/types/css/property-descriptors/list-style-image.d.ts +1 -1
- package/dist/types/css/property-descriptors/list-style-position.d.ts +1 -1
- package/dist/types/css/property-descriptors/list-style-type.d.ts +1 -1
- package/dist/types/css/property-descriptors/margin.d.ts +1 -1
- package/dist/types/css/property-descriptors/mix-blend-mode.d.ts +21 -0
- package/dist/types/css/property-descriptors/object-fit.d.ts +1 -1
- package/dist/types/css/property-descriptors/opacity.d.ts +1 -1
- package/dist/types/css/property-descriptors/overflow-wrap.d.ts +1 -1
- package/dist/types/css/property-descriptors/overflow.d.ts +1 -1
- package/dist/types/css/property-descriptors/padding.d.ts +1 -1
- package/dist/types/css/property-descriptors/paint-order.d.ts +1 -1
- package/dist/types/css/property-descriptors/position.d.ts +1 -1
- package/dist/types/css/property-descriptors/quotes.d.ts +1 -1
- package/dist/types/css/property-descriptors/rotate.d.ts +1 -1
- package/dist/types/css/property-descriptors/text-align.d.ts +1 -1
- package/dist/types/css/property-descriptors/text-decoration-color.d.ts +1 -1
- package/dist/types/css/property-descriptors/text-decoration-line.d.ts +1 -1
- package/dist/types/css/property-descriptors/text-decoration-style.d.ts +1 -1
- package/dist/types/css/property-descriptors/text-decoration-thickness.d.ts +1 -1
- package/dist/types/css/property-descriptors/text-overflow.d.ts +1 -1
- package/dist/types/css/property-descriptors/text-shadow.d.ts +1 -1
- package/dist/types/css/property-descriptors/text-transform.d.ts +1 -1
- package/dist/types/css/property-descriptors/text-underline-offset.d.ts +1 -1
- package/dist/types/css/property-descriptors/transform-origin.d.ts +1 -1
- package/dist/types/css/property-descriptors/transform.d.ts +1 -1
- package/dist/types/css/property-descriptors/visibility.d.ts +1 -1
- package/dist/types/css/property-descriptors/webkit-line-clamp.d.ts +1 -1
- package/dist/types/css/property-descriptors/webkit-text-stroke-color.d.ts +1 -1
- package/dist/types/css/property-descriptors/webkit-text-stroke-width.d.ts +1 -1
- package/dist/types/css/property-descriptors/word-break.d.ts +1 -1
- package/dist/types/css/property-descriptors/writing-mode.d.ts +1 -1
- package/dist/types/css/property-descriptors/z-index.d.ts +1 -1
- package/dist/types/css/syntax/tokenizer.d.ts +5 -0
- package/dist/types/css/types/angle.d.ts +1 -1
- package/dist/types/css/types/color.d.ts +1 -1
- package/dist/types/css/types/image.d.ts +1 -1
- package/dist/types/css/types/time.d.ts +1 -1
- package/dist/types/dom/element-container.d.ts +4 -11
- package/dist/types/dom/node-parser.d.ts +2 -15
- package/dist/types/dom/node-type-guards.d.ts +21 -22
- package/dist/types/index.d.ts +28 -48
- package/dist/types/options.d.ts +51 -0
- package/dist/types/render/canvas/background-renderer.d.ts +0 -6
- package/dist/types/render/canvas/canvas-path.d.ts +3 -0
- package/dist/types/render/canvas/canvas-renderer.d.ts +4 -2
- package/dist/types/render/canvas/foreignobject-renderer.d.ts +2 -3
- package/dist/types/render/canvas/text-renderer.d.ts +5 -0
- package/dist/types/render/effects.d.ts +9 -1
- package/dist/types/render/object-fit.d.ts +18 -0
- package/package.json +43 -35
- package/src/__tests__/index.ts +99 -0
- package/src/config.ts +107 -0
- package/src/core/__mocks__/cache-storage.ts +1 -0
- package/src/core/__mocks__/context.ts +19 -0
- package/{dist/lib/core/__mocks__/features.js → src/core/__mocks__/features.ts} +1 -5
- package/src/core/__mocks__/logger.ts +17 -0
- package/{dist/lib/core/__tests__/cache-storage.test.js → src/core/__tests__/cache-storage.test.ts} +95 -48
- package/{dist/lib/core/__tests__/cache-storage.js → src/core/__tests__/cache-storage.ts} +117 -64
- package/{dist/lib/core/__tests__/logger.js → src/core/__tests__/logger.ts} +10 -8
- package/{dist/lib/core/__tests__/validator.js → src/core/__tests__/validator.ts} +161 -98
- package/src/core/bitwise.ts +1 -0
- package/src/core/cache-storage.ts +315 -0
- package/src/core/context.ts +31 -0
- package/src/core/debugger.ts +32 -0
- package/src/core/features.ts +222 -0
- package/src/core/logger.ts +64 -0
- package/src/core/origin-checker.ts +57 -0
- package/src/core/performance-monitor.ts +241 -0
- package/src/core/render-element.ts +272 -0
- package/src/core/util.ts +1 -0
- package/src/core/validator.ts +593 -0
- package/src/css/index.ts +427 -0
- package/src/css/layout/__mocks__/bounds.ts +6 -0
- package/src/css/layout/bounds.ts +79 -0
- package/src/css/layout/text.ts +161 -0
- package/src/css/property-descriptor.ts +49 -0
- package/src/css/property-descriptors/__tests__/background-tests.ts +65 -0
- package/src/css/property-descriptors/__tests__/clip-path.test.ts +280 -0
- package/src/css/property-descriptors/__tests__/font-family.ts +25 -0
- package/src/css/property-descriptors/__tests__/image-rendering-integration.test.ts +153 -0
- package/{dist/lib/css/property-descriptors/__tests__/image-rendering-performance.test.js → src/css/property-descriptors/__tests__/image-rendering-performance.test.ts} +74 -66
- package/src/css/property-descriptors/__tests__/image-rendering.test.ts +72 -0
- package/src/css/property-descriptors/__tests__/paint-order.ts +87 -0
- package/src/css/property-descriptors/__tests__/text-shadow.ts +94 -0
- package/src/css/property-descriptors/__tests__/transform-tests.ts +18 -0
- package/src/css/property-descriptors/background-clip.ts +30 -0
- package/src/css/property-descriptors/background-color.ts +9 -0
- package/src/css/property-descriptors/background-image.ts +27 -0
- package/src/css/property-descriptors/background-origin.ts +31 -0
- package/src/css/property-descriptors/background-position.ts +38 -0
- package/src/css/property-descriptors/background-repeat.ts +44 -0
- package/src/css/property-descriptors/background-size.ts +27 -0
- package/src/css/property-descriptors/border-color.ts +13 -0
- package/src/css/property-descriptors/border-radius.ts +19 -0
- package/src/css/property-descriptors/border-style.ts +34 -0
- package/src/css/property-descriptors/border-width.ts +20 -0
- package/src/css/property-descriptors/box-shadow.ts +60 -0
- package/src/css/property-descriptors/clip-path.ts +271 -0
- package/src/css/property-descriptors/color.ts +9 -0
- package/src/css/property-descriptors/content.ts +26 -0
- package/src/css/property-descriptors/counter-increment.ts +43 -0
- package/src/css/property-descriptors/counter-reset.ts +36 -0
- package/src/css/property-descriptors/direction.ts +23 -0
- package/src/css/property-descriptors/display.ts +117 -0
- package/src/css/property-descriptors/duration.ts +14 -0
- package/src/css/property-descriptors/float.ts +29 -0
- package/src/css/property-descriptors/font-family.ts +38 -0
- package/src/css/property-descriptors/font-size.ts +9 -0
- package/src/css/property-descriptors/font-style.ts +25 -0
- package/src/css/property-descriptors/font-variant.ts +12 -0
- package/src/css/property-descriptors/font-weight.ts +26 -0
- package/src/css/property-descriptors/image-rendering.ts +33 -0
- package/src/css/property-descriptors/letter-spacing.ts +25 -0
- package/src/css/property-descriptors/line-break.ts +22 -0
- package/src/css/property-descriptors/line-height.ts +22 -0
- package/src/css/property-descriptors/list-style-image.ts +19 -0
- package/src/css/property-descriptors/list-style-position.ts +22 -0
- package/src/css/property-descriptors/list-style-type.ts +179 -0
- package/src/css/property-descriptors/margin.ts +13 -0
- package/src/css/property-descriptors/mix-blend-mode.ts +35 -0
- package/src/css/property-descriptors/object-fit.ts +39 -0
- package/src/css/property-descriptors/opacity.ts +15 -0
- package/src/css/property-descriptors/overflow-wrap.ts +22 -0
- package/src/css/property-descriptors/overflow.ts +34 -0
- package/src/css/property-descriptors/padding.ts +14 -0
- package/src/css/property-descriptors/paint-order.ts +42 -0
- package/src/css/property-descriptors/position.ts +30 -0
- package/src/css/property-descriptors/quotes.ts +57 -0
- package/src/css/property-descriptors/rotate.ts +34 -0
- package/src/css/property-descriptors/text-align.ts +26 -0
- package/src/css/property-descriptors/text-decoration-color.ts +9 -0
- package/src/css/property-descriptors/text-decoration-line.ts +38 -0
- package/src/css/property-descriptors/text-decoration-style.ts +32 -0
- package/src/css/property-descriptors/text-decoration-thickness.ts +30 -0
- package/src/css/property-descriptors/text-overflow.ts +23 -0
- package/src/css/property-descriptors/text-shadow.ts +52 -0
- package/src/css/property-descriptors/text-transform.ts +27 -0
- package/src/css/property-descriptors/text-underline-offset.ts +27 -0
- package/src/css/property-descriptors/transform-origin.ts +29 -0
- package/src/css/property-descriptors/transform.ts +74 -0
- package/src/css/property-descriptors/visibility.ts +25 -0
- package/src/css/property-descriptors/webkit-line-clamp.ts +30 -0
- package/src/css/property-descriptors/webkit-text-stroke-color.ts +8 -0
- package/src/css/property-descriptors/webkit-text-stroke-width.ts +15 -0
- package/src/css/property-descriptors/word-break.ts +25 -0
- package/src/css/property-descriptors/writing-mode.ts +37 -0
- package/src/css/property-descriptors/z-index.ts +27 -0
- package/src/css/syntax/__tests__/tokernizer-tests.ts +29 -0
- package/src/css/syntax/parser.ts +188 -0
- package/src/css/syntax/tokenizer.ts +822 -0
- package/src/css/type-descriptor.ts +7 -0
- package/src/css/types/__tests__/color-tests.ts +147 -0
- package/src/css/types/__tests__/image-tests.ts +239 -0
- package/src/css/types/angle.ts +86 -0
- package/src/css/types/color-math.ts +22 -0
- package/src/css/types/color-spaces/a98.ts +86 -0
- package/src/css/types/color-spaces/p3.ts +92 -0
- package/src/css/types/color-spaces/pro-photo.ts +87 -0
- package/src/css/types/color-spaces/rec2020.ts +90 -0
- package/src/css/types/color-spaces/srgb.ts +87 -0
- package/src/css/types/color-utilities.ts +452 -0
- package/src/css/types/color.ts +485 -0
- package/src/css/types/functions/-prefix-linear-gradient.ts +35 -0
- package/src/css/types/functions/-prefix-radial-gradient.ts +106 -0
- package/src/css/types/functions/-webkit-gradient.ts +69 -0
- package/src/css/types/functions/__tests__/radial-gradient.ts +69 -0
- package/src/css/types/functions/counter.ts +511 -0
- package/src/css/types/functions/gradient.ts +206 -0
- package/src/css/types/functions/linear-gradient.ts +28 -0
- package/src/css/types/functions/radial-gradient.ts +101 -0
- package/src/css/types/image.ts +120 -0
- package/src/css/types/index.ts +1 -0
- package/src/css/types/length-percentage.ts +137 -0
- package/src/css/types/length.ts +7 -0
- package/src/css/types/time.ts +20 -0
- package/src/dom/__mocks__/document-cloner.ts +22 -0
- package/{dist/lib/dom/__tests__/dom-normalizer.test.js → src/dom/__tests__/dom-normalizer.test.ts} +64 -44
- package/src/dom/__tests__/element-container.test.ts +129 -0
- package/src/dom/document-cloner.ts +929 -0
- package/src/dom/dom-normalizer.ts +133 -0
- package/src/dom/element-container.ts +75 -0
- package/src/dom/elements/li-element-container.ts +10 -0
- package/src/dom/elements/ol-element-container.ts +12 -0
- package/src/dom/elements/select-element-container.ts +10 -0
- package/src/dom/elements/textarea-element-container.ts +9 -0
- package/src/dom/node-parser.ts +177 -0
- package/src/dom/node-type-guards.ts +70 -0
- package/src/dom/replaced-elements/canvas-element-container.ts +15 -0
- package/src/dom/replaced-elements/iframe-element-container.ts +55 -0
- package/src/dom/replaced-elements/image-element-container.ts +16 -0
- package/src/dom/replaced-elements/index.ts +5 -0
- package/src/dom/replaced-elements/input-element-container.ts +105 -0
- package/src/dom/replaced-elements/pseudo-elements.ts +0 -0
- package/src/dom/replaced-elements/svg-element-container.ts +23 -0
- package/src/dom/text-container.ts +42 -0
- package/src/global.d.ts +19 -0
- package/src/index.ts +82 -0
- package/src/invariant.ts +5 -0
- package/src/options.ts +55 -0
- package/src/render/__tests__/object-fit.test.ts +85 -0
- package/src/render/background.ts +298 -0
- package/src/render/bezier-curve.ts +47 -0
- package/src/render/border.ts +165 -0
- package/src/render/bound-curves.ts +388 -0
- package/src/render/box-sizing.ts +31 -0
- package/{dist/lib/render/canvas/__tests__/background-renderer.test.js → src/render/canvas/__tests__/background-renderer.test.ts} +32 -25
- package/src/render/canvas/__tests__/border-renderer.test.ts +24 -0
- package/src/render/canvas/__tests__/effects-renderer.test.ts +32 -0
- package/src/render/canvas/__tests__/text-renderer.test.ts +471 -0
- package/src/render/canvas/background-renderer.ts +271 -0
- package/src/render/canvas/border-renderer.ts +224 -0
- package/src/render/canvas/canvas-path.ts +31 -0
- package/src/render/canvas/canvas-renderer.ts +641 -0
- package/src/render/canvas/effects-renderer.ts +130 -0
- package/src/render/canvas/foreignobject-renderer.ts +53 -0
- package/src/render/canvas/text-renderer.ts +700 -0
- package/src/render/effects.ts +75 -0
- package/src/render/font-metrics.ts +72 -0
- package/src/render/object-fit.ts +100 -0
- package/src/render/path.ts +37 -0
- package/src/render/renderer-interface.ts +28 -0
- package/src/render/stacking-context.ts +386 -0
- package/src/render/vector.ts +19 -0
- package/demo/image-smoothing-demo.html +0 -256
- package/demo/refactoring-test.html +0 -602
- package/dist/lib/__tests__/index.js +0 -85
- package/dist/lib/__tests__/index.js.map +0 -1
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/core/__mocks__/cache-storage.js +0 -7
- package/dist/lib/core/__mocks__/cache-storage.js.map +0 -1
- package/dist/lib/core/__mocks__/context.js +0 -19
- package/dist/lib/core/__mocks__/context.js.map +0 -1
- package/dist/lib/core/__mocks__/features.js.map +0 -1
- package/dist/lib/core/__mocks__/logger.js +0 -16
- package/dist/lib/core/__mocks__/logger.js.map +0 -1
- package/dist/lib/core/__tests__/cache-storage.js.map +0 -1
- package/dist/lib/core/__tests__/cache-storage.test.js.map +0 -1
- package/dist/lib/core/__tests__/logger.js.map +0 -1
- package/dist/lib/core/__tests__/validator.js.map +0 -1
- package/dist/lib/core/bitwise.js.map +0 -1
- package/dist/lib/core/cache-storage.js.map +0 -1
- package/dist/lib/core/context.js.map +0 -1
- package/dist/lib/core/debugger.js.map +0 -1
- package/dist/lib/core/features.js.map +0 -1
- package/dist/lib/core/logger.js.map +0 -1
- package/dist/lib/core/origin-checker.js.map +0 -1
- package/dist/lib/core/performance-monitor.js.map +0 -1
- package/dist/lib/core/util.js.map +0 -1
- package/dist/lib/core/validator.js.map +0 -1
- package/dist/lib/css/IPropertyDescriptor.js.map +0 -1
- package/dist/lib/css/ITypeDescriptor.js.map +0 -1
- package/dist/lib/css/index.js.map +0 -1
- package/dist/lib/css/layout/__mocks__/bounds.js +0 -9
- package/dist/lib/css/layout/__mocks__/bounds.js.map +0 -1
- package/dist/lib/css/layout/bounds.js.map +0 -1
- package/dist/lib/css/layout/text.js.map +0 -1
- package/dist/lib/css/property-descriptors/__tests__/background-tests.js +0 -49
- package/dist/lib/css/property-descriptors/__tests__/background-tests.js.map +0 -1
- package/dist/lib/css/property-descriptors/__tests__/clip-path.test.js +0 -273
- package/dist/lib/css/property-descriptors/__tests__/clip-path.test.js.map +0 -1
- package/dist/lib/css/property-descriptors/__tests__/font-family.js +0 -19
- package/dist/lib/css/property-descriptors/__tests__/font-family.js.map +0 -1
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-integration.test.js +0 -143
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-integration.test.js.map +0 -1
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-performance.test.js.map +0 -1
- package/dist/lib/css/property-descriptors/__tests__/image-rendering.test.js +0 -61
- package/dist/lib/css/property-descriptors/__tests__/image-rendering.test.js.map +0 -1
- package/dist/lib/css/property-descriptors/__tests__/paint-order.js +0 -66
- package/dist/lib/css/property-descriptors/__tests__/paint-order.js.map +0 -1
- package/dist/lib/css/property-descriptors/__tests__/text-shadow.js +0 -82
- package/dist/lib/css/property-descriptors/__tests__/text-shadow.js.map +0 -1
- package/dist/lib/css/property-descriptors/__tests__/transform-tests.js +0 -14
- package/dist/lib/css/property-descriptors/__tests__/transform-tests.js.map +0 -1
- package/dist/lib/css/property-descriptors/background-clip.js.map +0 -1
- package/dist/lib/css/property-descriptors/background-color.js.map +0 -1
- package/dist/lib/css/property-descriptors/background-image.js.map +0 -1
- package/dist/lib/css/property-descriptors/background-origin.js.map +0 -1
- package/dist/lib/css/property-descriptors/background-position.js.map +0 -1
- package/dist/lib/css/property-descriptors/background-repeat.js.map +0 -1
- package/dist/lib/css/property-descriptors/background-size.js.map +0 -1
- package/dist/lib/css/property-descriptors/border-color.js.map +0 -1
- package/dist/lib/css/property-descriptors/border-radius.js.map +0 -1
- package/dist/lib/css/property-descriptors/border-style.js.map +0 -1
- package/dist/lib/css/property-descriptors/border-width.js.map +0 -1
- package/dist/lib/css/property-descriptors/box-shadow.js.map +0 -1
- package/dist/lib/css/property-descriptors/clip-path.js.map +0 -1
- package/dist/lib/css/property-descriptors/color.js.map +0 -1
- package/dist/lib/css/property-descriptors/content.js.map +0 -1
- package/dist/lib/css/property-descriptors/counter-increment.js.map +0 -1
- package/dist/lib/css/property-descriptors/counter-reset.js.map +0 -1
- package/dist/lib/css/property-descriptors/direction.js.map +0 -1
- package/dist/lib/css/property-descriptors/display.js.map +0 -1
- package/dist/lib/css/property-descriptors/duration.js.map +0 -1
- package/dist/lib/css/property-descriptors/float.js.map +0 -1
- package/dist/lib/css/property-descriptors/font-family.js.map +0 -1
- package/dist/lib/css/property-descriptors/font-size.js.map +0 -1
- package/dist/lib/css/property-descriptors/font-style.js.map +0 -1
- package/dist/lib/css/property-descriptors/font-variant.js.map +0 -1
- package/dist/lib/css/property-descriptors/font-weight.js.map +0 -1
- package/dist/lib/css/property-descriptors/image-rendering.js.map +0 -1
- package/dist/lib/css/property-descriptors/letter-spacing.js.map +0 -1
- package/dist/lib/css/property-descriptors/line-break.js.map +0 -1
- package/dist/lib/css/property-descriptors/line-height.js.map +0 -1
- package/dist/lib/css/property-descriptors/list-style-image.js.map +0 -1
- package/dist/lib/css/property-descriptors/list-style-position.js.map +0 -1
- package/dist/lib/css/property-descriptors/list-style-type.js.map +0 -1
- package/dist/lib/css/property-descriptors/margin.js.map +0 -1
- package/dist/lib/css/property-descriptors/object-fit.js.map +0 -1
- package/dist/lib/css/property-descriptors/opacity.js.map +0 -1
- package/dist/lib/css/property-descriptors/overflow-wrap.js.map +0 -1
- package/dist/lib/css/property-descriptors/overflow.js.map +0 -1
- package/dist/lib/css/property-descriptors/padding.js.map +0 -1
- package/dist/lib/css/property-descriptors/paint-order.js.map +0 -1
- package/dist/lib/css/property-descriptors/position.js.map +0 -1
- package/dist/lib/css/property-descriptors/quotes.js.map +0 -1
- package/dist/lib/css/property-descriptors/rotate.js.map +0 -1
- package/dist/lib/css/property-descriptors/text-align.js.map +0 -1
- package/dist/lib/css/property-descriptors/text-decoration-color.js.map +0 -1
- package/dist/lib/css/property-descriptors/text-decoration-line.js.map +0 -1
- package/dist/lib/css/property-descriptors/text-decoration-style.js.map +0 -1
- package/dist/lib/css/property-descriptors/text-decoration-thickness.js.map +0 -1
- package/dist/lib/css/property-descriptors/text-overflow.js.map +0 -1
- package/dist/lib/css/property-descriptors/text-shadow.js.map +0 -1
- package/dist/lib/css/property-descriptors/text-transform.js.map +0 -1
- package/dist/lib/css/property-descriptors/text-underline-offset.js.map +0 -1
- package/dist/lib/css/property-descriptors/transform-origin.js.map +0 -1
- package/dist/lib/css/property-descriptors/transform.js.map +0 -1
- package/dist/lib/css/property-descriptors/visibility.js.map +0 -1
- package/dist/lib/css/property-descriptors/webkit-line-clamp.js.map +0 -1
- package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js.map +0 -1
- package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js.map +0 -1
- package/dist/lib/css/property-descriptors/word-break.js.map +0 -1
- package/dist/lib/css/property-descriptors/writing-mode.js.map +0 -1
- package/dist/lib/css/property-descriptors/z-index.js.map +0 -1
- package/dist/lib/css/syntax/__tests__/tokernizer-tests.js +0 -26
- package/dist/lib/css/syntax/__tests__/tokernizer-tests.js.map +0 -1
- package/dist/lib/css/syntax/parser.js.map +0 -1
- package/dist/lib/css/syntax/tokenizer.js.map +0 -1
- package/dist/lib/css/types/__tests__/color-tests.js +0 -111
- package/dist/lib/css/types/__tests__/color-tests.js.map +0 -1
- package/dist/lib/css/types/__tests__/image-tests.js +0 -215
- package/dist/lib/css/types/__tests__/image-tests.js.map +0 -1
- package/dist/lib/css/types/angle.js.map +0 -1
- package/dist/lib/css/types/color-math.js.map +0 -1
- package/dist/lib/css/types/color-spaces/a98.js.map +0 -1
- package/dist/lib/css/types/color-spaces/p3.js.map +0 -1
- package/dist/lib/css/types/color-spaces/pro-photo.js.map +0 -1
- package/dist/lib/css/types/color-spaces/rec2020.js.map +0 -1
- package/dist/lib/css/types/color-spaces/srgb.js.map +0 -1
- package/dist/lib/css/types/color-utilities.js.map +0 -1
- package/dist/lib/css/types/color.js.map +0 -1
- package/dist/lib/css/types/functions/-prefix-linear-gradient.js.map +0 -1
- package/dist/lib/css/types/functions/-prefix-radial-gradient.js.map +0 -1
- package/dist/lib/css/types/functions/-webkit-gradient.js.map +0 -1
- package/dist/lib/css/types/functions/__tests__/radial-gradient.js +0 -63
- package/dist/lib/css/types/functions/__tests__/radial-gradient.js.map +0 -1
- package/dist/lib/css/types/functions/counter.js.map +0 -1
- package/dist/lib/css/types/functions/gradient.js.map +0 -1
- package/dist/lib/css/types/functions/linear-gradient.js.map +0 -1
- package/dist/lib/css/types/functions/radial-gradient.js.map +0 -1
- package/dist/lib/css/types/image.js.map +0 -1
- package/dist/lib/css/types/index.js.map +0 -1
- package/dist/lib/css/types/length-percentage.js.map +0 -1
- package/dist/lib/css/types/length.js.map +0 -1
- package/dist/lib/css/types/time.js.map +0 -1
- package/dist/lib/dom/__mocks__/document-cloner.js +0 -23
- package/dist/lib/dom/__mocks__/document-cloner.js.map +0 -1
- package/dist/lib/dom/__tests__/dom-normalizer.test.js.map +0 -1
- package/dist/lib/dom/__tests__/element-container.test.js +0 -109
- package/dist/lib/dom/__tests__/element-container.test.js.map +0 -1
- package/dist/lib/dom/document-cloner.js.map +0 -1
- package/dist/lib/dom/dom-normalizer.js.map +0 -1
- package/dist/lib/dom/element-container.js.map +0 -1
- package/dist/lib/dom/elements/li-element-container.js.map +0 -1
- package/dist/lib/dom/elements/ol-element-container.js.map +0 -1
- package/dist/lib/dom/elements/select-element-container.js.map +0 -1
- package/dist/lib/dom/elements/textarea-element-container.js.map +0 -1
- package/dist/lib/dom/node-parser.js.map +0 -1
- package/dist/lib/dom/node-type-guards.js.map +0 -1
- package/dist/lib/dom/replaced-elements/canvas-element-container.js.map +0 -1
- package/dist/lib/dom/replaced-elements/iframe-element-container.js.map +0 -1
- package/dist/lib/dom/replaced-elements/image-element-container.js.map +0 -1
- package/dist/lib/dom/replaced-elements/index.js.map +0 -1
- package/dist/lib/dom/replaced-elements/input-element-container.js.map +0 -1
- package/dist/lib/dom/replaced-elements/pseudo-elements.js.map +0 -1
- package/dist/lib/dom/replaced-elements/svg-element-container.js.map +0 -1
- package/dist/lib/dom/text-container.js.map +0 -1
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/invariant.js.map +0 -1
- package/dist/lib/render/background.js.map +0 -1
- package/dist/lib/render/bezier-curve.js.map +0 -1
- package/dist/lib/render/border.js.map +0 -1
- package/dist/lib/render/bound-curves.js.map +0 -1
- package/dist/lib/render/box-sizing.js.map +0 -1
- package/dist/lib/render/canvas/__tests__/background-renderer.test.js.map +0 -1
- package/dist/lib/render/canvas/__tests__/border-renderer.test.js +0 -23
- package/dist/lib/render/canvas/__tests__/border-renderer.test.js.map +0 -1
- package/dist/lib/render/canvas/__tests__/effects-renderer.test.js +0 -30
- package/dist/lib/render/canvas/__tests__/effects-renderer.test.js.map +0 -1
- package/dist/lib/render/canvas/__tests__/text-renderer.test.js +0 -402
- package/dist/lib/render/canvas/__tests__/text-renderer.test.js.map +0 -1
- package/dist/lib/render/canvas/background-renderer.js.map +0 -1
- package/dist/lib/render/canvas/border-renderer.js.map +0 -1
- package/dist/lib/render/canvas/canvas-renderer.js.map +0 -1
- package/dist/lib/render/canvas/effects-renderer.js.map +0 -1
- package/dist/lib/render/canvas/foreignobject-renderer.js.map +0 -1
- package/dist/lib/render/canvas/text-renderer.js.map +0 -1
- package/dist/lib/render/effects.js.map +0 -1
- package/dist/lib/render/font-metrics.js.map +0 -1
- package/dist/lib/render/path.js.map +0 -1
- package/dist/lib/render/renderer-interface.js.map +0 -1
- package/dist/lib/render/renderer.js +0 -11
- package/dist/lib/render/renderer.js.map +0 -1
- package/dist/lib/render/stacking-context.js.map +0 -1
- package/dist/lib/render/vector.js.map +0 -1
- package/dist/types/__tests__/index.d.ts +0 -1
- package/dist/types/core/__mocks__/cache-storage.d.ts +0 -2
- package/dist/types/core/__mocks__/context.d.ts +0 -9
- package/dist/types/core/__mocks__/features.d.ts +0 -8
- package/dist/types/core/__mocks__/logger.d.ts +0 -9
- package/dist/types/core/__tests__/cache-storage.d.ts +0 -1
- package/dist/types/core/__tests__/cache-storage.test.d.ts +0 -1
- package/dist/types/core/__tests__/logger.d.ts +0 -1
- package/dist/types/core/__tests__/validator.d.ts +0 -1
- package/dist/types/css/layout/__mocks__/bounds.d.ts +0 -2
- package/dist/types/css/property-descriptors/__tests__/background-tests.d.ts +0 -1
- package/dist/types/css/property-descriptors/__tests__/clip-path.test.d.ts +0 -1
- package/dist/types/css/property-descriptors/__tests__/font-family.d.ts +0 -1
- package/dist/types/css/property-descriptors/__tests__/image-rendering-integration.test.d.ts +0 -1
- package/dist/types/css/property-descriptors/__tests__/image-rendering-performance.test.d.ts +0 -1
- package/dist/types/css/property-descriptors/__tests__/image-rendering.test.d.ts +0 -1
- package/dist/types/css/property-descriptors/__tests__/paint-order.d.ts +0 -1
- package/dist/types/css/property-descriptors/__tests__/text-shadow.d.ts +0 -1
- package/dist/types/css/property-descriptors/__tests__/transform-tests.d.ts +0 -1
- package/dist/types/css/syntax/__tests__/tokernizer-tests.d.ts +0 -1
- package/dist/types/css/types/__tests__/color-tests.d.ts +0 -1
- package/dist/types/css/types/__tests__/image-tests.d.ts +0 -1
- package/dist/types/css/types/functions/__tests__/radial-gradient.d.ts +0 -1
- package/dist/types/dom/__mocks__/document-cloner.d.ts +0 -6
- package/dist/types/dom/__tests__/dom-normalizer.test.d.ts +0 -1
- package/dist/types/dom/__tests__/element-container.test.d.ts +0 -1
- package/dist/types/render/canvas/__tests__/background-renderer.test.d.ts +0 -1
- package/dist/types/render/canvas/__tests__/border-renderer.test.d.ts +0 -1
- package/dist/types/render/canvas/__tests__/effects-renderer.test.d.ts +0 -1
- package/dist/types/render/canvas/__tests__/text-renderer.test.d.ts +0 -1
- package/dist/types/render/renderer.d.ts +0 -7
- package/eslint.config.js +0 -35
- package/jest.config.cjs +0 -5
- package/karma.conf.cjs +0 -300
- /package/dist/types/css/{IPropertyDescriptor.d.ts → property-descriptor.d.ts} +0 -0
- /package/dist/types/css/{ITypeDescriptor.d.ts → type-descriptor.d.ts} +0 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import { CSSValue, isIdentToken, isNumberToken, nonFunctionArgSeparator, Parser } from '../syntax/parser';
|
|
2
|
+
import { HashToken, TokenType } from '../syntax/tokenizer';
|
|
3
|
+
import { ITypeDescriptor } from '../type-descriptor';
|
|
4
|
+
import { Context } from '../../core/context';
|
|
5
|
+
import { srgbFromXYZ, srgbLinearFromXYZ } from './color-spaces/srgb';
|
|
6
|
+
import {
|
|
7
|
+
packSrgbLinear,
|
|
8
|
+
packSrgb,
|
|
9
|
+
packHSL,
|
|
10
|
+
packLch,
|
|
11
|
+
packOkLch,
|
|
12
|
+
packOkLab,
|
|
13
|
+
packLab,
|
|
14
|
+
isRelativeTransform,
|
|
15
|
+
pack,
|
|
16
|
+
getTokenColorValue,
|
|
17
|
+
convertXyz,
|
|
18
|
+
convertXyz50,
|
|
19
|
+
rgbToXyz,
|
|
20
|
+
hslToXyz,
|
|
21
|
+
labToXyz,
|
|
22
|
+
lchToXyz,
|
|
23
|
+
oklabToXyz,
|
|
24
|
+
oklchToXyz,
|
|
25
|
+
xyzFromXYZ,
|
|
26
|
+
xyz50FromXYZ
|
|
27
|
+
} from './color-utilities';
|
|
28
|
+
import { convertP3, p3FromXYZ } from './color-spaces/p3';
|
|
29
|
+
import { a98FromXYZ, convertA98rgb } from './color-spaces/a98';
|
|
30
|
+
import { convertProPhoto, proPhotoFromXYZ } from './color-spaces/pro-photo';
|
|
31
|
+
import { convertRec2020, rec2020FromXYZ } from './color-spaces/rec2020';
|
|
32
|
+
|
|
33
|
+
export type Color = number;
|
|
34
|
+
|
|
35
|
+
export const color: ITypeDescriptor<Color> = {
|
|
36
|
+
name: 'color',
|
|
37
|
+
parse: (context: Context, value: CSSValue): Color => {
|
|
38
|
+
if (value.type === TokenType.FUNCTION) {
|
|
39
|
+
const colorFunction = SUPPORTED_COLOR_FUNCTIONS[value.name];
|
|
40
|
+
if (typeof colorFunction === 'undefined') {
|
|
41
|
+
throw new Error(`Attempting to parse an unsupported color function "${value.name}"`);
|
|
42
|
+
}
|
|
43
|
+
return colorFunction(context, value.values);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (value.type === TokenType.HASH_TOKEN) {
|
|
47
|
+
const [r, g, b, a] = hash2rgb(value);
|
|
48
|
+
return pack(r, g, b, a);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (value.type === TokenType.IDENT_TOKEN) {
|
|
52
|
+
const namedColor = COLORS[value.value.toUpperCase()];
|
|
53
|
+
if (typeof namedColor !== 'undefined') {
|
|
54
|
+
return namedColor;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return COLORS.TRANSPARENT;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const hash2rgb = (token: HashToken): [number, number, number, number] => {
|
|
63
|
+
if (token.value.length === 3) {
|
|
64
|
+
const r = token.value.substring(0, 1);
|
|
65
|
+
const g = token.value.substring(1, 2);
|
|
66
|
+
const b = token.value.substring(2, 3);
|
|
67
|
+
return [parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), 1];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (token.value.length === 4) {
|
|
71
|
+
const r = token.value.substring(0, 1);
|
|
72
|
+
const g = token.value.substring(1, 2);
|
|
73
|
+
const b = token.value.substring(2, 3);
|
|
74
|
+
const a = token.value.substring(3, 4);
|
|
75
|
+
return [parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), parseInt(a + a, 16) / 255];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (token.value.length === 6) {
|
|
79
|
+
const r = token.value.substring(0, 2);
|
|
80
|
+
const g = token.value.substring(2, 4);
|
|
81
|
+
const b = token.value.substring(4, 6);
|
|
82
|
+
return [parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), 1];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (token.value.length === 8) {
|
|
86
|
+
const r = token.value.substring(0, 2);
|
|
87
|
+
const g = token.value.substring(2, 4);
|
|
88
|
+
const b = token.value.substring(4, 6);
|
|
89
|
+
const a = token.value.substring(6, 8);
|
|
90
|
+
return [parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), parseInt(a, 16) / 255];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return [0, 0, 0, 1];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const rgb = (_context: Context, args: CSSValue[]): number => {
|
|
97
|
+
const tokens = args.filter(nonFunctionArgSeparator);
|
|
98
|
+
|
|
99
|
+
if (isRelativeTransform(tokens)) {
|
|
100
|
+
throw new Error('Relative color not supported for rgb()');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (tokens.length === 3) {
|
|
104
|
+
const [r, g, b] = tokens.map(getTokenColorValue);
|
|
105
|
+
return pack(r, g, b, 1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (tokens.length === 4) {
|
|
109
|
+
const [r, g, b, a] = tokens.map(getTokenColorValue);
|
|
110
|
+
return pack(r, g, b, a);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Handle modern CSS syntax with / separator: rgb(r g b / alpha)
|
|
114
|
+
// tokens[0] = r, tokens[1] = g, tokens[2] = b, tokens[3] = '/', tokens[4] = alpha
|
|
115
|
+
if (tokens.length === 5 && tokens[3].type === TokenType.DELIM_TOKEN && tokens[3].value === '/') {
|
|
116
|
+
const r = getTokenColorValue(tokens[0], 0);
|
|
117
|
+
const g = getTokenColorValue(tokens[1], 1);
|
|
118
|
+
const b = getTokenColorValue(tokens[2], 2);
|
|
119
|
+
const a = getTokenColorValue(tokens[4], 3);
|
|
120
|
+
return pack(r, g, b, a);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return 0;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Handle the CSS color() function
|
|
128
|
+
*
|
|
129
|
+
* @param context
|
|
130
|
+
* @param args
|
|
131
|
+
*/
|
|
132
|
+
const _color = (context: Context, args: CSSValue[]) => {
|
|
133
|
+
const tokens = args.filter(nonFunctionArgSeparator),
|
|
134
|
+
token_1_value = tokens[0].type === TokenType.IDENT_TOKEN ? tokens[0].value : 'unknown',
|
|
135
|
+
is_absolute = !isRelativeTransform(tokens);
|
|
136
|
+
|
|
137
|
+
if (is_absolute) {
|
|
138
|
+
const color_space = token_1_value,
|
|
139
|
+
colorSpaceFunction = SUPPORTED_COLOR_SPACES_ABSOLUTE[color_space];
|
|
140
|
+
if (typeof colorSpaceFunction === 'undefined') {
|
|
141
|
+
throw new Error(`Attempting to parse an unsupported color space "${color_space}" for color() function`);
|
|
142
|
+
}
|
|
143
|
+
const c1 = isNumberToken(tokens[1]) ? tokens[1].number : 0,
|
|
144
|
+
c2 = isNumberToken(tokens[2]) ? tokens[2].number : 0,
|
|
145
|
+
c3 = isNumberToken(tokens[3]) ? tokens[3].number : 0,
|
|
146
|
+
a =
|
|
147
|
+
tokens.length > 4 &&
|
|
148
|
+
tokens[4].type === TokenType.DELIM_TOKEN &&
|
|
149
|
+
tokens[4].value === '/' &&
|
|
150
|
+
isNumberToken(tokens[5])
|
|
151
|
+
? tokens[5].number
|
|
152
|
+
: 1;
|
|
153
|
+
|
|
154
|
+
return colorSpaceFunction([c1, c2, c3, a]);
|
|
155
|
+
} else {
|
|
156
|
+
const extractComponent = (color: [number, number, number, number], token: CSSValue) => {
|
|
157
|
+
if (isNumberToken(token)) {
|
|
158
|
+
return token.number;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const posFromVal = (value: string): number => {
|
|
162
|
+
return value === 'r' || value === 'x' ? 0 : value === 'g' || value === 'y' ? 1 : 2;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
if (isIdentToken(token)) {
|
|
166
|
+
const position = posFromVal(token.value);
|
|
167
|
+
return color[position];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const parseCalc = (args: CSSValue[]): string => {
|
|
171
|
+
const parts = args.filter(nonFunctionArgSeparator);
|
|
172
|
+
let expression = '(';
|
|
173
|
+
for (const part of parts) {
|
|
174
|
+
expression +=
|
|
175
|
+
part.type === TokenType.FUNCTION && part.name === 'calc'
|
|
176
|
+
? parseCalc(part.values)
|
|
177
|
+
: isNumberToken(part)
|
|
178
|
+
? part.number
|
|
179
|
+
: part.type === TokenType.DELIM_TOKEN || isIdentToken(part)
|
|
180
|
+
? part.value
|
|
181
|
+
: '';
|
|
182
|
+
}
|
|
183
|
+
expression += ')';
|
|
184
|
+
return expression;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
if (token.type === TokenType.FUNCTION) {
|
|
188
|
+
const args = token.values.filter(nonFunctionArgSeparator);
|
|
189
|
+
if (token.name === 'calc') {
|
|
190
|
+
const expression = parseCalc(args)
|
|
191
|
+
.replace(/r|x/, color[0].toString())
|
|
192
|
+
.replace(/g|y/, color[1].toString())
|
|
193
|
+
.replace(/b|z/, color[2].toString());
|
|
194
|
+
|
|
195
|
+
return new Function('return ' + expression)();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return null;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const from_colorspace =
|
|
203
|
+
tokens[1].type === TokenType.FUNCTION
|
|
204
|
+
? tokens[1].name
|
|
205
|
+
: isIdentToken(tokens[1]) || tokens[1].type === TokenType.HASH_TOKEN
|
|
206
|
+
? 'rgb'
|
|
207
|
+
: 'unknown',
|
|
208
|
+
to_colorspace = isIdentToken(tokens[2]) ? tokens[2].value : 'unknown';
|
|
209
|
+
|
|
210
|
+
let from =
|
|
211
|
+
tokens[1].type === TokenType.FUNCTION ? tokens[1].values : isIdentToken(tokens[1]) ? [tokens[1]] : [];
|
|
212
|
+
|
|
213
|
+
if (isIdentToken(tokens[1])) {
|
|
214
|
+
const named_color = COLORS[tokens[1].value.toUpperCase()];
|
|
215
|
+
if (typeof named_color === 'undefined') {
|
|
216
|
+
throw new Error(`Attempting to use unknown color in relative color 'from'`);
|
|
217
|
+
} else {
|
|
218
|
+
const _c = parseColor(context, tokens[1].value),
|
|
219
|
+
alpha = 0xff & _c,
|
|
220
|
+
blue = 0xff & (_c >> 8),
|
|
221
|
+
green = 0xff & (_c >> 16),
|
|
222
|
+
red = 0xff & (_c >> 24);
|
|
223
|
+
from = [
|
|
224
|
+
{ type: TokenType.NUMBER_TOKEN, number: red, flags: 1 },
|
|
225
|
+
{ type: TokenType.NUMBER_TOKEN, number: green, flags: 1 },
|
|
226
|
+
{ type: TokenType.NUMBER_TOKEN, number: blue, flags: 1 },
|
|
227
|
+
{ type: TokenType.NUMBER_TOKEN, number: alpha > 1 ? alpha / 255 : alpha, flags: 1 }
|
|
228
|
+
];
|
|
229
|
+
}
|
|
230
|
+
} else if (tokens[1].type === TokenType.HASH_TOKEN) {
|
|
231
|
+
const [red, green, blue, alpha] = hash2rgb(tokens[1]);
|
|
232
|
+
from = [
|
|
233
|
+
{ type: TokenType.NUMBER_TOKEN, number: red, flags: 1 },
|
|
234
|
+
{ type: TokenType.NUMBER_TOKEN, number: green, flags: 1 },
|
|
235
|
+
{ type: TokenType.NUMBER_TOKEN, number: blue, flags: 1 },
|
|
236
|
+
{ type: TokenType.NUMBER_TOKEN, number: alpha > 1 ? alpha / 255 : alpha, flags: 1 }
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (from.length === 0) {
|
|
241
|
+
throw new Error(`Attempting to use unknown color in relative color 'from'`);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (to_colorspace === 'unknown') {
|
|
245
|
+
throw new Error(`Attempting to use unknown colorspace in relative color 'to'`);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const fromColorToXyz = SUPPORTED_COLOR_SPACES_TO_XYZ[from_colorspace],
|
|
249
|
+
toColorFromXyz = SUPPORTED_COLOR_SPACES_FROM_XYZ[to_colorspace],
|
|
250
|
+
toColorPack = SUPPORTED_COLOR_SPACES_ABSOLUTE[to_colorspace];
|
|
251
|
+
|
|
252
|
+
if (typeof fromColorToXyz === 'undefined') {
|
|
253
|
+
throw new Error(`Attempting to parse an unsupported color space "${from_colorspace}" for color() function`);
|
|
254
|
+
}
|
|
255
|
+
if (typeof toColorFromXyz === 'undefined') {
|
|
256
|
+
throw new Error(`Attempting to parse an unsupported color space "${to_colorspace}" for color() function`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const from_color: [number, number, number, number] = fromColorToXyz(context, from),
|
|
260
|
+
from_final_colorspace: [number, number, number, number] = toColorFromXyz(from_color),
|
|
261
|
+
c1 = extractComponent(from_final_colorspace, tokens[3]),
|
|
262
|
+
c2 = extractComponent(from_final_colorspace, tokens[4]),
|
|
263
|
+
c3 = extractComponent(from_final_colorspace, tokens[5]),
|
|
264
|
+
a =
|
|
265
|
+
tokens.length > 6 &&
|
|
266
|
+
tokens[6].type === TokenType.DELIM_TOKEN &&
|
|
267
|
+
tokens[6].value === '/' &&
|
|
268
|
+
isNumberToken(tokens[7])
|
|
269
|
+
? tokens[7].number
|
|
270
|
+
: 1;
|
|
271
|
+
if (c1 === null || c2 === null || c3 === null) {
|
|
272
|
+
throw new Error(`Invalid relative color in color() function`);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return toColorPack([c1, c2, c3, a]);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const SUPPORTED_COLOR_SPACES_ABSOLUTE: {
|
|
280
|
+
[key: string]: (args: number[]) => number;
|
|
281
|
+
} = {
|
|
282
|
+
srgb: packSrgb,
|
|
283
|
+
'srgb-linear': packSrgbLinear,
|
|
284
|
+
'display-p3': convertP3,
|
|
285
|
+
'a98-rgb': convertA98rgb,
|
|
286
|
+
'prophoto-rgb': convertProPhoto,
|
|
287
|
+
xyz: convertXyz,
|
|
288
|
+
'xyz-d50': convertXyz50,
|
|
289
|
+
'xyz-d65': convertXyz,
|
|
290
|
+
rec2020: convertRec2020
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const SUPPORTED_COLOR_SPACES_TO_XYZ: {
|
|
294
|
+
[key: string]: (context: Context, args: CSSValue[]) => [number, number, number, number];
|
|
295
|
+
} = {
|
|
296
|
+
rgb: rgbToXyz,
|
|
297
|
+
hsl: hslToXyz,
|
|
298
|
+
lab: labToXyz,
|
|
299
|
+
lch: lchToXyz,
|
|
300
|
+
oklab: oklabToXyz,
|
|
301
|
+
oklch: oklchToXyz
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const SUPPORTED_COLOR_SPACES_FROM_XYZ: {
|
|
305
|
+
[key: string]: (args: [number, number, number, number]) => [number, number, number, number];
|
|
306
|
+
} = {
|
|
307
|
+
srgb: srgbFromXYZ,
|
|
308
|
+
'srgb-linear': srgbLinearFromXYZ,
|
|
309
|
+
'display-p3': p3FromXYZ,
|
|
310
|
+
'a98-rgb': a98FromXYZ,
|
|
311
|
+
'prophoto-rgb': proPhotoFromXYZ,
|
|
312
|
+
xyz: xyzFromXYZ,
|
|
313
|
+
'xyz-d50': xyz50FromXYZ,
|
|
314
|
+
'xyz-d65': xyzFromXYZ,
|
|
315
|
+
rec2020: rec2020FromXYZ
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const SUPPORTED_COLOR_FUNCTIONS: {
|
|
319
|
+
[key: string]: (context: Context, args: CSSValue[]) => number;
|
|
320
|
+
} = {
|
|
321
|
+
hsl: packHSL,
|
|
322
|
+
hsla: packHSL,
|
|
323
|
+
rgb: rgb,
|
|
324
|
+
rgba: rgb,
|
|
325
|
+
lch: packLch,
|
|
326
|
+
oklch: packOkLch,
|
|
327
|
+
oklab: packOkLab,
|
|
328
|
+
lab: packLab,
|
|
329
|
+
color: _color
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export const parseColor = (context: Context, value: string): Color =>
|
|
333
|
+
color.parse(context, Parser.create(value).parseComponentValue());
|
|
334
|
+
|
|
335
|
+
export const COLORS: { [key: string]: Color } = {
|
|
336
|
+
ALICEBLUE: 0xf0f8ffff,
|
|
337
|
+
ANTIQUEWHITE: 0xfaebd7ff,
|
|
338
|
+
AQUA: 0x00ffffff,
|
|
339
|
+
AQUAMARINE: 0x7fffd4ff,
|
|
340
|
+
AZURE: 0xf0ffffff,
|
|
341
|
+
BEIGE: 0xf5f5dcff,
|
|
342
|
+
BISQUE: 0xffe4c4ff,
|
|
343
|
+
BLACK: 0x000000ff,
|
|
344
|
+
BLANCHEDALMOND: 0xffebcdff,
|
|
345
|
+
BLUE: 0x0000ffff,
|
|
346
|
+
BLUEVIOLET: 0x8a2be2ff,
|
|
347
|
+
BROWN: 0xa52a2aff,
|
|
348
|
+
BURLYWOOD: 0xdeb887ff,
|
|
349
|
+
CADETBLUE: 0x5f9ea0ff,
|
|
350
|
+
CHARTREUSE: 0x7fff00ff,
|
|
351
|
+
CHOCOLATE: 0xd2691eff,
|
|
352
|
+
CORAL: 0xff7f50ff,
|
|
353
|
+
CORNFLOWERBLUE: 0x6495edff,
|
|
354
|
+
CORNSILK: 0xfff8dcff,
|
|
355
|
+
CRIMSON: 0xdc143cff,
|
|
356
|
+
CYAN: 0x00ffffff,
|
|
357
|
+
DARKBLUE: 0x00008bff,
|
|
358
|
+
DARKCYAN: 0x008b8bff,
|
|
359
|
+
DARKGOLDENROD: 0xb886bbff,
|
|
360
|
+
DARKGRAY: 0xa9a9a9ff,
|
|
361
|
+
DARKGREEN: 0x006400ff,
|
|
362
|
+
DARKGREY: 0xa9a9a9ff,
|
|
363
|
+
DARKKHAKI: 0xbdb76bff,
|
|
364
|
+
DARKMAGENTA: 0x8b008bff,
|
|
365
|
+
DARKOLIVEGREEN: 0x556b2fff,
|
|
366
|
+
DARKORANGE: 0xff8c00ff,
|
|
367
|
+
DARKORCHID: 0x9932ccff,
|
|
368
|
+
DARKRED: 0x8b0000ff,
|
|
369
|
+
DARKSALMON: 0xe9967aff,
|
|
370
|
+
DARKSEAGREEN: 0x8fbc8fff,
|
|
371
|
+
DARKSLATEBLUE: 0x483d8bff,
|
|
372
|
+
DARKSLATEGRAY: 0x2f4f4fff,
|
|
373
|
+
DARKSLATEGREY: 0x2f4f4fff,
|
|
374
|
+
DARKTURQUOISE: 0x00ced1ff,
|
|
375
|
+
DARKVIOLET: 0x9400d3ff,
|
|
376
|
+
DEEPPINK: 0xff1493ff,
|
|
377
|
+
DEEPSKYBLUE: 0x00bfffff,
|
|
378
|
+
DIMGRAY: 0x696969ff,
|
|
379
|
+
DIMGREY: 0x696969ff,
|
|
380
|
+
DODGERBLUE: 0x1e90ffff,
|
|
381
|
+
FIREBRICK: 0xb22222ff,
|
|
382
|
+
FLORALWHITE: 0xfffaf0ff,
|
|
383
|
+
FORESTGREEN: 0x228b22ff,
|
|
384
|
+
FUCHSIA: 0xff00ffff,
|
|
385
|
+
GAINSBORO: 0xdcdcdcff,
|
|
386
|
+
GHOSTWHITE: 0xf8f8ffff,
|
|
387
|
+
GOLD: 0xffd700ff,
|
|
388
|
+
GOLDENROD: 0xdaa520ff,
|
|
389
|
+
GRAY: 0x808080ff,
|
|
390
|
+
GREEN: 0x008000ff,
|
|
391
|
+
GREENYELLOW: 0xadff2fff,
|
|
392
|
+
GREY: 0x808080ff,
|
|
393
|
+
HONEYDEW: 0xf0fff0ff,
|
|
394
|
+
HOTPINK: 0xff69b4ff,
|
|
395
|
+
INDIANRED: 0xcd5c5cff,
|
|
396
|
+
INDIGO: 0x4b0082ff,
|
|
397
|
+
IVORY: 0xfffff0ff,
|
|
398
|
+
KHAKI: 0xf0e68cff,
|
|
399
|
+
LAVENDER: 0xe6e6faff,
|
|
400
|
+
LAVENDERBLUSH: 0xfff0f5ff,
|
|
401
|
+
LAWNGREEN: 0x7cfc00ff,
|
|
402
|
+
LEMONCHIFFON: 0xfffacdff,
|
|
403
|
+
LIGHTBLUE: 0xadd8e6ff,
|
|
404
|
+
LIGHTCORAL: 0xf08080ff,
|
|
405
|
+
LIGHTCYAN: 0xe0ffffff,
|
|
406
|
+
LIGHTGOLDENRODYELLOW: 0xfafad2ff,
|
|
407
|
+
LIGHTGRAY: 0xd3d3d3ff,
|
|
408
|
+
LIGHTGREEN: 0x90ee90ff,
|
|
409
|
+
LIGHTGREY: 0xd3d3d3ff,
|
|
410
|
+
LIGHTPINK: 0xffb6c1ff,
|
|
411
|
+
LIGHTSALMON: 0xffa07aff,
|
|
412
|
+
LIGHTSEAGREEN: 0x20b2aaff,
|
|
413
|
+
LIGHTSKYBLUE: 0x87cefaff,
|
|
414
|
+
LIGHTSLATEGRAY: 0x778899ff,
|
|
415
|
+
LIGHTSLATEGREY: 0x778899ff,
|
|
416
|
+
LIGHTSTEELBLUE: 0xb0c4deff,
|
|
417
|
+
LIGHTYELLOW: 0xffffe0ff,
|
|
418
|
+
LIME: 0x00ff00ff,
|
|
419
|
+
LIMEGREEN: 0x32cd32ff,
|
|
420
|
+
LINEN: 0xfaf0e6ff,
|
|
421
|
+
MAGENTA: 0xff00ffff,
|
|
422
|
+
MAROON: 0x800000ff,
|
|
423
|
+
MEDIUMAQUAMARINE: 0x66cdaaff,
|
|
424
|
+
MEDIUMBLUE: 0x0000cdff,
|
|
425
|
+
MEDIUMORCHID: 0xba55d3ff,
|
|
426
|
+
MEDIUMPURPLE: 0x9370dbff,
|
|
427
|
+
MEDIUMSEAGREEN: 0x3cb371ff,
|
|
428
|
+
MEDIUMSLATEBLUE: 0x7b68eeff,
|
|
429
|
+
MEDIUMSPRINGGREEN: 0x00fa9aff,
|
|
430
|
+
MEDIUMTURQUOISE: 0x48d1ccff,
|
|
431
|
+
MEDIUMVIOLETRED: 0xc71585ff,
|
|
432
|
+
MIDNIGHTBLUE: 0x191970ff,
|
|
433
|
+
MINTCREAM: 0xf5fffaff,
|
|
434
|
+
MISTYROSE: 0xffe4e1ff,
|
|
435
|
+
MOCCASIN: 0xffe4b5ff,
|
|
436
|
+
NAVAJOWHITE: 0xffdeadff,
|
|
437
|
+
NAVY: 0x000080ff,
|
|
438
|
+
OLDLACE: 0xfdf5e6ff,
|
|
439
|
+
OLIVE: 0x808000ff,
|
|
440
|
+
OLIVEDRAB: 0x6b8e23ff,
|
|
441
|
+
ORANGE: 0xffa500ff,
|
|
442
|
+
ORANGERED: 0xff4500ff,
|
|
443
|
+
ORCHID: 0xda70d6ff,
|
|
444
|
+
PALEGOLDENROD: 0xeee8aaff,
|
|
445
|
+
PALEGREEN: 0x98fb98ff,
|
|
446
|
+
PALETURQUOISE: 0xafeeeeff,
|
|
447
|
+
PALEVIOLETRED: 0xdb7093ff,
|
|
448
|
+
PAPAYAWHIP: 0xffefd5ff,
|
|
449
|
+
PEACHPUFF: 0xffdab9ff,
|
|
450
|
+
PERU: 0xcd853fff,
|
|
451
|
+
PINK: 0xffc0cbff,
|
|
452
|
+
PLUM: 0xdda0ddff,
|
|
453
|
+
POWDERBLUE: 0xb0e0e6ff,
|
|
454
|
+
PURPLE: 0x800080ff,
|
|
455
|
+
REBECCAPURPLE: 0x663399ff,
|
|
456
|
+
RED: 0xff0000ff,
|
|
457
|
+
ROSYBROWN: 0xbc8f8fff,
|
|
458
|
+
ROYALBLUE: 0x4169e1ff,
|
|
459
|
+
SADDLEBROWN: 0x8b4513ff,
|
|
460
|
+
SALMON: 0xfa8072ff,
|
|
461
|
+
SANDYBROWN: 0xf4a460ff,
|
|
462
|
+
SEAGREEN: 0x2e8b57ff,
|
|
463
|
+
SEASHELL: 0xfff5eeff,
|
|
464
|
+
SIENNA: 0xa0522dff,
|
|
465
|
+
SILVER: 0xc0c0c0ff,
|
|
466
|
+
SKYBLUE: 0x87ceebff,
|
|
467
|
+
SLATEBLUE: 0x6a5acdff,
|
|
468
|
+
SLATEGRAY: 0x708090ff,
|
|
469
|
+
SLATEGREY: 0x708090ff,
|
|
470
|
+
SNOW: 0xfffafaff,
|
|
471
|
+
SPRINGGREEN: 0x00ff7fff,
|
|
472
|
+
STEELBLUE: 0x4682b4ff,
|
|
473
|
+
TAN: 0xd2b48cff,
|
|
474
|
+
TEAL: 0x008080ff,
|
|
475
|
+
THISTLE: 0xd8bfd8ff,
|
|
476
|
+
TOMATO: 0xff6347ff,
|
|
477
|
+
TRANSPARENT: 0x00000000,
|
|
478
|
+
TURQUOISE: 0x40e0d0ff,
|
|
479
|
+
VIOLET: 0xee82eeff,
|
|
480
|
+
WHEAT: 0xf5deb3ff,
|
|
481
|
+
WHITE: 0xffffffff,
|
|
482
|
+
WHITESMOKE: 0xf5f5f5ff,
|
|
483
|
+
YELLOW: 0xffff00ff,
|
|
484
|
+
YELLOWGREEN: 0x9acd32ff
|
|
485
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CSSValue, parseFunctionArgs } from '../../syntax/parser';
|
|
2
|
+
import { CSSImageType, CSSLinearGradientImage, GradientCorner, UnprocessedGradientColorStop } from '../image';
|
|
3
|
+
import { TokenType } from '../../syntax/tokenizer';
|
|
4
|
+
import { isAngle, angle as angleType, parseNamedSide, deg } from '../angle';
|
|
5
|
+
import { parseColorStop } from './gradient';
|
|
6
|
+
import { Context } from '../../../core/context';
|
|
7
|
+
|
|
8
|
+
export const prefixLinearGradient = (context: Context, tokens: CSSValue[]): CSSLinearGradientImage => {
|
|
9
|
+
let angle: number | GradientCorner = deg(180);
|
|
10
|
+
const stops: UnprocessedGradientColorStop[] = [];
|
|
11
|
+
|
|
12
|
+
parseFunctionArgs(tokens).forEach((arg, i) => {
|
|
13
|
+
if (i === 0) {
|
|
14
|
+
const firstToken = arg[0];
|
|
15
|
+
if (
|
|
16
|
+
firstToken.type === TokenType.IDENT_TOKEN &&
|
|
17
|
+
['top', 'left', 'right', 'bottom'].indexOf(firstToken.value) !== -1
|
|
18
|
+
) {
|
|
19
|
+
angle = parseNamedSide(arg);
|
|
20
|
+
return;
|
|
21
|
+
} else if (isAngle(firstToken)) {
|
|
22
|
+
angle = (angleType.parse(context, firstToken) + deg(270)) % deg(360);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const colorStop = parseColorStop(context, arg);
|
|
27
|
+
stops.push(colorStop);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
angle,
|
|
32
|
+
stops,
|
|
33
|
+
type: CSSImageType.LINEAR_GRADIENT
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { CSSValue, isIdentToken, parseFunctionArgs } from '../../syntax/parser';
|
|
2
|
+
import {
|
|
3
|
+
CSSImageType,
|
|
4
|
+
CSSRadialExtent,
|
|
5
|
+
CSSRadialGradientImage,
|
|
6
|
+
CSSRadialShape,
|
|
7
|
+
CSSRadialSize,
|
|
8
|
+
UnprocessedGradientColorStop
|
|
9
|
+
} from '../image';
|
|
10
|
+
import { parseColorStop } from './gradient';
|
|
11
|
+
import {
|
|
12
|
+
FIFTY_PERCENT,
|
|
13
|
+
HUNDRED_PERCENT,
|
|
14
|
+
isLengthPercentage,
|
|
15
|
+
LengthPercentage,
|
|
16
|
+
ZERO_LENGTH
|
|
17
|
+
} from '../length-percentage';
|
|
18
|
+
import { isLength } from '../length';
|
|
19
|
+
import {
|
|
20
|
+
CIRCLE,
|
|
21
|
+
CLOSEST_CORNER,
|
|
22
|
+
CLOSEST_SIDE,
|
|
23
|
+
CONTAIN,
|
|
24
|
+
COVER,
|
|
25
|
+
ELLIPSE,
|
|
26
|
+
FARTHEST_CORNER,
|
|
27
|
+
FARTHEST_SIDE
|
|
28
|
+
} from './radial-gradient';
|
|
29
|
+
import { Context } from '../../../core/context';
|
|
30
|
+
|
|
31
|
+
export const prefixRadialGradient = (context: Context, tokens: CSSValue[]): CSSRadialGradientImage => {
|
|
32
|
+
let shape: CSSRadialShape = CSSRadialShape.CIRCLE;
|
|
33
|
+
let size: CSSRadialSize = CSSRadialExtent.FARTHEST_CORNER;
|
|
34
|
+
const stops: UnprocessedGradientColorStop[] = [];
|
|
35
|
+
const position: LengthPercentage[] = [];
|
|
36
|
+
|
|
37
|
+
parseFunctionArgs(tokens).forEach((arg, i) => {
|
|
38
|
+
let isColorStop = true;
|
|
39
|
+
if (i === 0) {
|
|
40
|
+
isColorStop = arg.reduce((acc, token) => {
|
|
41
|
+
if (isIdentToken(token)) {
|
|
42
|
+
switch (token.value) {
|
|
43
|
+
case 'center':
|
|
44
|
+
position.push(FIFTY_PERCENT);
|
|
45
|
+
return false;
|
|
46
|
+
case 'top':
|
|
47
|
+
case 'left':
|
|
48
|
+
position.push(ZERO_LENGTH);
|
|
49
|
+
return false;
|
|
50
|
+
case 'right':
|
|
51
|
+
case 'bottom':
|
|
52
|
+
position.push(HUNDRED_PERCENT);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
} else if (isLengthPercentage(token) || isLength(token)) {
|
|
56
|
+
position.push(token);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return acc;
|
|
61
|
+
}, isColorStop);
|
|
62
|
+
} else if (i === 1) {
|
|
63
|
+
isColorStop = arg.reduce((acc, token) => {
|
|
64
|
+
if (isIdentToken(token)) {
|
|
65
|
+
switch (token.value) {
|
|
66
|
+
case CIRCLE:
|
|
67
|
+
shape = CSSRadialShape.CIRCLE;
|
|
68
|
+
return false;
|
|
69
|
+
case ELLIPSE:
|
|
70
|
+
shape = CSSRadialShape.ELLIPSE;
|
|
71
|
+
return false;
|
|
72
|
+
case CONTAIN:
|
|
73
|
+
case CLOSEST_SIDE:
|
|
74
|
+
size = CSSRadialExtent.CLOSEST_SIDE;
|
|
75
|
+
return false;
|
|
76
|
+
case FARTHEST_SIDE:
|
|
77
|
+
size = CSSRadialExtent.FARTHEST_SIDE;
|
|
78
|
+
return false;
|
|
79
|
+
case CLOSEST_CORNER:
|
|
80
|
+
size = CSSRadialExtent.CLOSEST_CORNER;
|
|
81
|
+
return false;
|
|
82
|
+
case COVER:
|
|
83
|
+
case FARTHEST_CORNER:
|
|
84
|
+
size = CSSRadialExtent.FARTHEST_CORNER;
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
} else if (isLength(token) || isLengthPercentage(token)) {
|
|
88
|
+
if (!Array.isArray(size)) {
|
|
89
|
+
size = [];
|
|
90
|
+
}
|
|
91
|
+
size.push(token);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return acc;
|
|
96
|
+
}, isColorStop);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (isColorStop) {
|
|
100
|
+
const colorStop = parseColorStop(context, arg);
|
|
101
|
+
stops.push(colorStop);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return { size, shape, stops, position, type: CSSImageType.RADIAL_GRADIENT };
|
|
106
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CSSValue, isIdentToken, isNumberToken, nonFunctionArgSeparator, parseFunctionArgs } from '../../syntax/parser';
|
|
2
|
+
import {
|
|
3
|
+
CSSImageType,
|
|
4
|
+
CSSLinearGradientImage,
|
|
5
|
+
CSSRadialExtent,
|
|
6
|
+
CSSRadialGradientImage,
|
|
7
|
+
CSSRadialShape,
|
|
8
|
+
CSSRadialSize,
|
|
9
|
+
UnprocessedGradientColorStop
|
|
10
|
+
} from '../image';
|
|
11
|
+
import { deg } from '../angle';
|
|
12
|
+
import { TokenType } from '../../syntax/tokenizer';
|
|
13
|
+
import { color as colorType } from '../color';
|
|
14
|
+
import { HUNDRED_PERCENT, LengthPercentage, ZERO_LENGTH } from '../length-percentage';
|
|
15
|
+
import { Context } from '../../../core/context';
|
|
16
|
+
|
|
17
|
+
export const webkitGradient = (
|
|
18
|
+
context: Context,
|
|
19
|
+
tokens: CSSValue[]
|
|
20
|
+
): CSSLinearGradientImage | CSSRadialGradientImage => {
|
|
21
|
+
const angle = deg(180);
|
|
22
|
+
const stops: UnprocessedGradientColorStop[] = [];
|
|
23
|
+
let type = CSSImageType.LINEAR_GRADIENT;
|
|
24
|
+
const shape: CSSRadialShape = CSSRadialShape.CIRCLE;
|
|
25
|
+
const size: CSSRadialSize = CSSRadialExtent.FARTHEST_CORNER;
|
|
26
|
+
const position: LengthPercentage[] = [];
|
|
27
|
+
parseFunctionArgs(tokens).forEach((arg, i) => {
|
|
28
|
+
const firstToken = arg[0];
|
|
29
|
+
if (i === 0) {
|
|
30
|
+
if (isIdentToken(firstToken) && firstToken.value === 'linear') {
|
|
31
|
+
type = CSSImageType.LINEAR_GRADIENT;
|
|
32
|
+
return;
|
|
33
|
+
} else if (isIdentToken(firstToken) && firstToken.value === 'radial') {
|
|
34
|
+
type = CSSImageType.RADIAL_GRADIENT;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (firstToken.type === TokenType.FUNCTION) {
|
|
40
|
+
if (firstToken.name === 'from') {
|
|
41
|
+
const color = colorType.parse(context, firstToken.values[0]);
|
|
42
|
+
stops.push({ stop: ZERO_LENGTH, color });
|
|
43
|
+
} else if (firstToken.name === 'to') {
|
|
44
|
+
const color = colorType.parse(context, firstToken.values[0]);
|
|
45
|
+
stops.push({ stop: HUNDRED_PERCENT, color });
|
|
46
|
+
} else if (firstToken.name === 'color-stop') {
|
|
47
|
+
const values = firstToken.values.filter(nonFunctionArgSeparator);
|
|
48
|
+
if (values.length === 2) {
|
|
49
|
+
const color = colorType.parse(context, values[1]);
|
|
50
|
+
const stop = values[0];
|
|
51
|
+
if (isNumberToken(stop)) {
|
|
52
|
+
stops.push({
|
|
53
|
+
stop: { type: TokenType.PERCENTAGE_TOKEN, number: stop.number * 100, flags: stop.flags },
|
|
54
|
+
color
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return type === CSSImageType.LINEAR_GRADIENT
|
|
63
|
+
? {
|
|
64
|
+
angle: (angle + deg(180)) % deg(360),
|
|
65
|
+
stops,
|
|
66
|
+
type
|
|
67
|
+
}
|
|
68
|
+
: { size, shape, stops, position, type };
|
|
69
|
+
};
|