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,39 @@
|
|
|
1
|
+
import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue, isIdentToken } from '../syntax/parser';
|
|
3
|
+
import { Context } from '../../core/context';
|
|
4
|
+
export const enum OBJECT_FIT {
|
|
5
|
+
FILL = 0,
|
|
6
|
+
CONTAIN = 1 << 1,
|
|
7
|
+
COVER = 1 << 2,
|
|
8
|
+
NONE = 1 << 3,
|
|
9
|
+
SCALE_DOWN = 1 << 4
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type ObjectFit = number;
|
|
13
|
+
|
|
14
|
+
export const objectFit: IPropertyListDescriptor<ObjectFit> = {
|
|
15
|
+
name: 'objectFit',
|
|
16
|
+
initialValue: 'fill',
|
|
17
|
+
prefix: false,
|
|
18
|
+
type: PropertyDescriptorParsingType.LIST,
|
|
19
|
+
parse: (_context: Context, tokens: CSSValue[]): ObjectFit => {
|
|
20
|
+
return tokens.filter(isIdentToken).reduce((bit, token) => {
|
|
21
|
+
return bit | parseDisplayValue(token.value);
|
|
22
|
+
}, OBJECT_FIT.FILL);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const parseDisplayValue = (display: string): ObjectFit => {
|
|
27
|
+
switch (display) {
|
|
28
|
+
case 'contain':
|
|
29
|
+
return OBJECT_FIT.CONTAIN;
|
|
30
|
+
case 'cover':
|
|
31
|
+
return OBJECT_FIT.COVER;
|
|
32
|
+
case 'none':
|
|
33
|
+
return OBJECT_FIT.NONE;
|
|
34
|
+
case 'scale-down':
|
|
35
|
+
return OBJECT_FIT.SCALE_DOWN;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return OBJECT_FIT.FILL;
|
|
39
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue, isNumberToken } from '../syntax/parser';
|
|
3
|
+
import { Context } from '../../core/context';
|
|
4
|
+
export const opacity: IPropertyValueDescriptor<number> = {
|
|
5
|
+
name: 'opacity',
|
|
6
|
+
initialValue: '1',
|
|
7
|
+
type: PropertyDescriptorParsingType.VALUE,
|
|
8
|
+
prefix: false,
|
|
9
|
+
parse: (_context: Context, token: CSSValue): number => {
|
|
10
|
+
if (isNumberToken(token)) {
|
|
11
|
+
return token.number;
|
|
12
|
+
}
|
|
13
|
+
return 1;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { Context } from '../../core/context';
|
|
3
|
+
export const enum OVERFLOW_WRAP {
|
|
4
|
+
NORMAL = 'normal',
|
|
5
|
+
BREAK_WORD = 'break-word'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const overflowWrap: IPropertyIdentValueDescriptor<OVERFLOW_WRAP> = {
|
|
9
|
+
name: 'overflow-wrap',
|
|
10
|
+
initialValue: 'normal',
|
|
11
|
+
prefix: false,
|
|
12
|
+
type: PropertyDescriptorParsingType.IDENT_VALUE,
|
|
13
|
+
parse: (_context: Context, overflow: string) => {
|
|
14
|
+
switch (overflow) {
|
|
15
|
+
case 'break-word':
|
|
16
|
+
return OVERFLOW_WRAP.BREAK_WORD;
|
|
17
|
+
case 'normal':
|
|
18
|
+
default:
|
|
19
|
+
return OVERFLOW_WRAP.NORMAL;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue, isIdentToken } from '../syntax/parser';
|
|
3
|
+
import { Context } from '../../core/context';
|
|
4
|
+
export const enum OVERFLOW {
|
|
5
|
+
VISIBLE = 0,
|
|
6
|
+
HIDDEN = 1,
|
|
7
|
+
SCROLL = 2,
|
|
8
|
+
CLIP = 3,
|
|
9
|
+
AUTO = 4
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const overflow: IPropertyListDescriptor<OVERFLOW[]> = {
|
|
13
|
+
name: 'overflow',
|
|
14
|
+
initialValue: 'visible',
|
|
15
|
+
prefix: false,
|
|
16
|
+
type: PropertyDescriptorParsingType.LIST,
|
|
17
|
+
parse: (_context: Context, tokens: CSSValue[]): OVERFLOW[] => {
|
|
18
|
+
return tokens.filter(isIdentToken).map((overflow) => {
|
|
19
|
+
switch (overflow.value) {
|
|
20
|
+
case 'hidden':
|
|
21
|
+
return OVERFLOW.HIDDEN;
|
|
22
|
+
case 'scroll':
|
|
23
|
+
return OVERFLOW.SCROLL;
|
|
24
|
+
case 'clip':
|
|
25
|
+
return OVERFLOW.CLIP;
|
|
26
|
+
case 'auto':
|
|
27
|
+
return OVERFLOW.AUTO;
|
|
28
|
+
case 'visible':
|
|
29
|
+
default:
|
|
30
|
+
return OVERFLOW.VISIBLE;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IPropertyTypeValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
|
|
3
|
+
const paddingForSide = (side: string): IPropertyTypeValueDescriptor => ({
|
|
4
|
+
name: `padding-${side}`,
|
|
5
|
+
initialValue: '0',
|
|
6
|
+
prefix: false,
|
|
7
|
+
type: PropertyDescriptorParsingType.TYPE_VALUE,
|
|
8
|
+
format: 'length-percentage'
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const paddingTop: IPropertyTypeValueDescriptor = paddingForSide('top');
|
|
12
|
+
export const paddingRight: IPropertyTypeValueDescriptor = paddingForSide('right');
|
|
13
|
+
export const paddingBottom: IPropertyTypeValueDescriptor = paddingForSide('bottom');
|
|
14
|
+
export const paddingLeft: IPropertyTypeValueDescriptor = paddingForSide('left');
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue, isIdentToken } from '../syntax/parser';
|
|
3
|
+
import { Context } from '../../core/context';
|
|
4
|
+
export const enum PAINT_ORDER_LAYER {
|
|
5
|
+
FILL,
|
|
6
|
+
STROKE,
|
|
7
|
+
MARKERS
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type PaintOrder = PAINT_ORDER_LAYER[];
|
|
11
|
+
|
|
12
|
+
export const paintOrder: IPropertyListDescriptor<PaintOrder> = {
|
|
13
|
+
name: 'paint-order',
|
|
14
|
+
initialValue: 'normal',
|
|
15
|
+
prefix: false,
|
|
16
|
+
type: PropertyDescriptorParsingType.LIST,
|
|
17
|
+
parse: (_context: Context, tokens: CSSValue[]): PaintOrder => {
|
|
18
|
+
const DEFAULT_VALUE = [PAINT_ORDER_LAYER.FILL, PAINT_ORDER_LAYER.STROKE, PAINT_ORDER_LAYER.MARKERS];
|
|
19
|
+
const layers: PaintOrder = [];
|
|
20
|
+
|
|
21
|
+
tokens.filter(isIdentToken).forEach((token) => {
|
|
22
|
+
switch (token.value) {
|
|
23
|
+
case 'stroke':
|
|
24
|
+
layers.push(PAINT_ORDER_LAYER.STROKE);
|
|
25
|
+
break;
|
|
26
|
+
case 'fill':
|
|
27
|
+
layers.push(PAINT_ORDER_LAYER.FILL);
|
|
28
|
+
break;
|
|
29
|
+
case 'markers':
|
|
30
|
+
layers.push(PAINT_ORDER_LAYER.MARKERS);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
DEFAULT_VALUE.forEach((value) => {
|
|
35
|
+
if (layers.indexOf(value) === -1) {
|
|
36
|
+
layers.push(value);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return layers;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { Context } from '../../core/context';
|
|
3
|
+
export const enum POSITION {
|
|
4
|
+
STATIC = 0,
|
|
5
|
+
RELATIVE = 1,
|
|
6
|
+
ABSOLUTE = 2,
|
|
7
|
+
FIXED = 3,
|
|
8
|
+
STICKY = 4
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const position: IPropertyIdentValueDescriptor<POSITION> = {
|
|
12
|
+
name: 'position',
|
|
13
|
+
initialValue: 'static',
|
|
14
|
+
prefix: false,
|
|
15
|
+
type: PropertyDescriptorParsingType.IDENT_VALUE,
|
|
16
|
+
parse: (_context: Context, position: string) => {
|
|
17
|
+
switch (position) {
|
|
18
|
+
case 'relative':
|
|
19
|
+
return POSITION.RELATIVE;
|
|
20
|
+
case 'absolute':
|
|
21
|
+
return POSITION.ABSOLUTE;
|
|
22
|
+
case 'fixed':
|
|
23
|
+
return POSITION.FIXED;
|
|
24
|
+
case 'sticky':
|
|
25
|
+
return POSITION.STICKY;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return POSITION.STATIC;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue, isStringToken } from '../syntax/parser';
|
|
3
|
+
import { TokenType } from '../syntax/tokenizer';
|
|
4
|
+
import { Context } from '../../core/context';
|
|
5
|
+
|
|
6
|
+
export interface QUOTE {
|
|
7
|
+
open: string;
|
|
8
|
+
close: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type Quotes = QUOTE[] | null;
|
|
12
|
+
|
|
13
|
+
export const quotes: IPropertyListDescriptor<Quotes> = {
|
|
14
|
+
name: 'quotes',
|
|
15
|
+
initialValue: 'none',
|
|
16
|
+
prefix: true,
|
|
17
|
+
type: PropertyDescriptorParsingType.LIST,
|
|
18
|
+
parse: (_context: Context, tokens: CSSValue[]) => {
|
|
19
|
+
if (tokens.length === 0) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const first = tokens[0];
|
|
24
|
+
|
|
25
|
+
if (first.type === TokenType.IDENT_TOKEN && first.value === 'none') {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const quotes = [];
|
|
30
|
+
const filtered = tokens.filter(isStringToken);
|
|
31
|
+
|
|
32
|
+
if (filtered.length % 2 !== 0) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < filtered.length; i += 2) {
|
|
37
|
+
const open = filtered[i].value;
|
|
38
|
+
const close = filtered[i + 1].value;
|
|
39
|
+
quotes.push({ open, close });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return quotes;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const getQuote = (quotes: Quotes, depth: number, open: boolean): string => {
|
|
47
|
+
if (!quotes) {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const quote = quotes[Math.min(depth, quotes.length - 1)];
|
|
52
|
+
if (!quote) {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return open ? quote.open : quote.close;
|
|
57
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue } from '../syntax/parser';
|
|
3
|
+
import { TokenType } from '../syntax/tokenizer';
|
|
4
|
+
import { Context } from '../../core/context';
|
|
5
|
+
import { angle } from '../types/angle';
|
|
6
|
+
|
|
7
|
+
export type Rotate = number | null;
|
|
8
|
+
|
|
9
|
+
export const rotate: IPropertyValueDescriptor<Rotate> = {
|
|
10
|
+
name: 'rotate',
|
|
11
|
+
initialValue: 'none',
|
|
12
|
+
prefix: false,
|
|
13
|
+
type: PropertyDescriptorParsingType.VALUE,
|
|
14
|
+
parse: (_context: Context, token: CSSValue): Rotate => {
|
|
15
|
+
if (token.type === TokenType.IDENT_TOKEN && token.value === 'none') {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (token.type === TokenType.NUMBER_TOKEN) {
|
|
20
|
+
if (token.number === 0) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (token.type === TokenType.DIMENSION_TOKEN) {
|
|
26
|
+
// Parse angle and convert to degrees for storage
|
|
27
|
+
const radians = angle.parse(_context, token);
|
|
28
|
+
// Store as degrees for consistency
|
|
29
|
+
return (radians * 180) / Math.PI;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { Context } from '../../core/context';
|
|
3
|
+
export const enum TEXT_ALIGN {
|
|
4
|
+
LEFT = 0,
|
|
5
|
+
CENTER = 1,
|
|
6
|
+
RIGHT = 2
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const textAlign: IPropertyIdentValueDescriptor<TEXT_ALIGN> = {
|
|
10
|
+
name: 'text-align',
|
|
11
|
+
initialValue: 'left',
|
|
12
|
+
prefix: false,
|
|
13
|
+
type: PropertyDescriptorParsingType.IDENT_VALUE,
|
|
14
|
+
parse: (_context: Context, textAlign: string) => {
|
|
15
|
+
switch (textAlign) {
|
|
16
|
+
case 'right':
|
|
17
|
+
return TEXT_ALIGN.RIGHT;
|
|
18
|
+
case 'center':
|
|
19
|
+
case 'justify':
|
|
20
|
+
return TEXT_ALIGN.CENTER;
|
|
21
|
+
case 'left':
|
|
22
|
+
default:
|
|
23
|
+
return TEXT_ALIGN.LEFT;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IPropertyTypeValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
|
|
3
|
+
export const textDecorationColor: IPropertyTypeValueDescriptor = {
|
|
4
|
+
name: `text-decoration-color`,
|
|
5
|
+
initialValue: 'transparent',
|
|
6
|
+
prefix: false,
|
|
7
|
+
type: PropertyDescriptorParsingType.TYPE_VALUE,
|
|
8
|
+
format: 'color'
|
|
9
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue, isIdentToken } from '../syntax/parser';
|
|
3
|
+
import { Context } from '../../core/context';
|
|
4
|
+
|
|
5
|
+
export const enum TEXT_DECORATION_LINE {
|
|
6
|
+
NONE = 0,
|
|
7
|
+
UNDERLINE = 1,
|
|
8
|
+
OVERLINE = 2,
|
|
9
|
+
LINE_THROUGH = 3,
|
|
10
|
+
BLINK = 4
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type TextDecorationLine = TEXT_DECORATION_LINE[];
|
|
14
|
+
|
|
15
|
+
export const textDecorationLine: IPropertyListDescriptor<TextDecorationLine> = {
|
|
16
|
+
name: 'text-decoration-line',
|
|
17
|
+
initialValue: 'none',
|
|
18
|
+
prefix: false,
|
|
19
|
+
type: PropertyDescriptorParsingType.LIST,
|
|
20
|
+
parse: (_context: Context, tokens: CSSValue[]): TextDecorationLine => {
|
|
21
|
+
return tokens
|
|
22
|
+
.filter(isIdentToken)
|
|
23
|
+
.map((token) => {
|
|
24
|
+
switch (token.value) {
|
|
25
|
+
case 'underline':
|
|
26
|
+
return TEXT_DECORATION_LINE.UNDERLINE;
|
|
27
|
+
case 'overline':
|
|
28
|
+
return TEXT_DECORATION_LINE.OVERLINE;
|
|
29
|
+
case 'line-through':
|
|
30
|
+
return TEXT_DECORATION_LINE.LINE_THROUGH;
|
|
31
|
+
case 'none':
|
|
32
|
+
return TEXT_DECORATION_LINE.BLINK;
|
|
33
|
+
}
|
|
34
|
+
return TEXT_DECORATION_LINE.NONE;
|
|
35
|
+
})
|
|
36
|
+
.filter((line) => line !== TEXT_DECORATION_LINE.NONE);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { Context } from '../../core/context';
|
|
3
|
+
|
|
4
|
+
export const enum TEXT_DECORATION_STYLE {
|
|
5
|
+
SOLID = 0,
|
|
6
|
+
DOUBLE = 1,
|
|
7
|
+
DOTTED = 2,
|
|
8
|
+
DASHED = 3,
|
|
9
|
+
WAVY = 4
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const textDecorationStyle: IPropertyIdentValueDescriptor<TEXT_DECORATION_STYLE> = {
|
|
13
|
+
name: 'text-decoration-style',
|
|
14
|
+
initialValue: 'solid',
|
|
15
|
+
prefix: false,
|
|
16
|
+
type: PropertyDescriptorParsingType.IDENT_VALUE,
|
|
17
|
+
parse: (_context: Context, style: string): TEXT_DECORATION_STYLE => {
|
|
18
|
+
switch (style) {
|
|
19
|
+
case 'double':
|
|
20
|
+
return TEXT_DECORATION_STYLE.DOUBLE;
|
|
21
|
+
case 'dotted':
|
|
22
|
+
return TEXT_DECORATION_STYLE.DOTTED;
|
|
23
|
+
case 'dashed':
|
|
24
|
+
return TEXT_DECORATION_STYLE.DASHED;
|
|
25
|
+
case 'wavy':
|
|
26
|
+
return TEXT_DECORATION_STYLE.WAVY;
|
|
27
|
+
case 'solid':
|
|
28
|
+
default:
|
|
29
|
+
return TEXT_DECORATION_STYLE.SOLID;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue, isIdentToken, isDimensionToken } from '../syntax/parser';
|
|
3
|
+
import { Context } from '../../core/context';
|
|
4
|
+
|
|
5
|
+
export type TextDecorationThickness = number | 'auto' | 'from-font';
|
|
6
|
+
|
|
7
|
+
export const textDecorationThickness: IPropertyValueDescriptor<TextDecorationThickness> = {
|
|
8
|
+
name: 'text-decoration-thickness',
|
|
9
|
+
initialValue: 'auto',
|
|
10
|
+
prefix: false,
|
|
11
|
+
type: PropertyDescriptorParsingType.VALUE,
|
|
12
|
+
parse: (_context: Context, token: CSSValue): TextDecorationThickness => {
|
|
13
|
+
if (isIdentToken(token)) {
|
|
14
|
+
switch (token.value) {
|
|
15
|
+
case 'auto':
|
|
16
|
+
return 'auto';
|
|
17
|
+
case 'from-font':
|
|
18
|
+
return 'from-font';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (isDimensionToken(token)) {
|
|
23
|
+
// Convert to pixels
|
|
24
|
+
return token.number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Default to auto
|
|
28
|
+
return 'auto';
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { Context } from '../../core/context';
|
|
3
|
+
|
|
4
|
+
export const enum TEXT_OVERFLOW {
|
|
5
|
+
CLIP = 0,
|
|
6
|
+
ELLIPSIS = 1
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const textOverflow: IPropertyIdentValueDescriptor<TEXT_OVERFLOW> = {
|
|
10
|
+
name: 'text-overflow',
|
|
11
|
+
initialValue: 'clip',
|
|
12
|
+
prefix: false,
|
|
13
|
+
type: PropertyDescriptorParsingType.IDENT_VALUE,
|
|
14
|
+
parse: (_context: Context, textOverflow: string) => {
|
|
15
|
+
switch (textOverflow) {
|
|
16
|
+
case 'ellipsis':
|
|
17
|
+
return TEXT_OVERFLOW.ELLIPSIS;
|
|
18
|
+
case 'clip':
|
|
19
|
+
default:
|
|
20
|
+
return TEXT_OVERFLOW.CLIP;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { PropertyDescriptorParsingType, IPropertyListDescriptor } from '../property-descriptor';
|
|
2
|
+
import { CSSValue, isIdentWithValue, parseFunctionArgs } from '../syntax/parser';
|
|
3
|
+
import { ZERO_LENGTH } from '../types/length-percentage';
|
|
4
|
+
import { color, Color, COLORS } from '../types/color';
|
|
5
|
+
import { isLength, Length } from '../types/length';
|
|
6
|
+
import { Context } from '../../core/context';
|
|
7
|
+
|
|
8
|
+
export type TextShadow = TextShadowItem[];
|
|
9
|
+
interface TextShadowItem {
|
|
10
|
+
color: Color;
|
|
11
|
+
offsetX: Length;
|
|
12
|
+
offsetY: Length;
|
|
13
|
+
blur: Length;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const textShadow: IPropertyListDescriptor<TextShadow> = {
|
|
17
|
+
name: 'text-shadow',
|
|
18
|
+
initialValue: 'none',
|
|
19
|
+
type: PropertyDescriptorParsingType.LIST,
|
|
20
|
+
prefix: false,
|
|
21
|
+
parse: (context: Context, tokens: CSSValue[]): TextShadow => {
|
|
22
|
+
if (tokens.length === 1 && isIdentWithValue(tokens[0], 'none')) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return parseFunctionArgs(tokens).map((values: CSSValue[]) => {
|
|
27
|
+
const shadow: TextShadowItem = {
|
|
28
|
+
color: COLORS.TRANSPARENT,
|
|
29
|
+
offsetX: ZERO_LENGTH,
|
|
30
|
+
offsetY: ZERO_LENGTH,
|
|
31
|
+
blur: ZERO_LENGTH
|
|
32
|
+
};
|
|
33
|
+
let c = 0;
|
|
34
|
+
for (let i = 0; i < values.length; i++) {
|
|
35
|
+
const token = values[i];
|
|
36
|
+
if (isLength(token)) {
|
|
37
|
+
if (c === 0) {
|
|
38
|
+
shadow.offsetX = token;
|
|
39
|
+
} else if (c === 1) {
|
|
40
|
+
shadow.offsetY = token;
|
|
41
|
+
} else {
|
|
42
|
+
shadow.blur = token;
|
|
43
|
+
}
|
|
44
|
+
c++;
|
|
45
|
+
} else {
|
|
46
|
+
shadow.color = color.parse(context, token);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return shadow;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { Context } from '../../core/context';
|
|
3
|
+
export const enum TEXT_TRANSFORM {
|
|
4
|
+
NONE = 0,
|
|
5
|
+
LOWERCASE = 1,
|
|
6
|
+
UPPERCASE = 2,
|
|
7
|
+
CAPITALIZE = 3
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const textTransform: IPropertyIdentValueDescriptor<TEXT_TRANSFORM> = {
|
|
11
|
+
name: 'text-transform',
|
|
12
|
+
initialValue: 'none',
|
|
13
|
+
prefix: false,
|
|
14
|
+
type: PropertyDescriptorParsingType.IDENT_VALUE,
|
|
15
|
+
parse: (_context: Context, textTransform: string) => {
|
|
16
|
+
switch (textTransform) {
|
|
17
|
+
case 'uppercase':
|
|
18
|
+
return TEXT_TRANSFORM.UPPERCASE;
|
|
19
|
+
case 'lowercase':
|
|
20
|
+
return TEXT_TRANSFORM.LOWERCASE;
|
|
21
|
+
case 'capitalize':
|
|
22
|
+
return TEXT_TRANSFORM.CAPITALIZE;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return TEXT_TRANSFORM.NONE;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue, isIdentToken, isDimensionToken } from '../syntax/parser';
|
|
3
|
+
import { Context } from '../../core/context';
|
|
4
|
+
|
|
5
|
+
export type TextUnderlineOffset = number | 'auto';
|
|
6
|
+
|
|
7
|
+
export const textUnderlineOffset: IPropertyValueDescriptor<TextUnderlineOffset> = {
|
|
8
|
+
name: 'text-underline-offset',
|
|
9
|
+
initialValue: 'auto',
|
|
10
|
+
prefix: false,
|
|
11
|
+
type: PropertyDescriptorParsingType.VALUE,
|
|
12
|
+
parse: (_context: Context, token: CSSValue): TextUnderlineOffset => {
|
|
13
|
+
if (isIdentToken(token)) {
|
|
14
|
+
if (token.value === 'auto') {
|
|
15
|
+
return 'auto';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (isDimensionToken(token)) {
|
|
20
|
+
// Return pixel value
|
|
21
|
+
return token.number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Default to auto
|
|
25
|
+
return 'auto';
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue } from '../syntax/parser';
|
|
3
|
+
import { isLengthPercentage, LengthPercentage } from '../types/length-percentage';
|
|
4
|
+
import { FLAG_INTEGER, TokenType } from '../syntax/tokenizer';
|
|
5
|
+
import { Context } from '../../core/context';
|
|
6
|
+
export type TransformOrigin = [LengthPercentage, LengthPercentage];
|
|
7
|
+
|
|
8
|
+
const DEFAULT_VALUE: LengthPercentage = {
|
|
9
|
+
type: TokenType.PERCENTAGE_TOKEN,
|
|
10
|
+
number: 50,
|
|
11
|
+
flags: FLAG_INTEGER
|
|
12
|
+
};
|
|
13
|
+
const DEFAULT: TransformOrigin = [DEFAULT_VALUE, DEFAULT_VALUE];
|
|
14
|
+
|
|
15
|
+
export const transformOrigin: IPropertyListDescriptor<TransformOrigin> = {
|
|
16
|
+
name: 'transform-origin',
|
|
17
|
+
initialValue: '50% 50%',
|
|
18
|
+
prefix: true,
|
|
19
|
+
type: PropertyDescriptorParsingType.LIST,
|
|
20
|
+
parse: (_context: Context, tokens: CSSValue[]) => {
|
|
21
|
+
const origins: LengthPercentage[] = tokens.filter(isLengthPercentage);
|
|
22
|
+
|
|
23
|
+
if (origins.length !== 2) {
|
|
24
|
+
return DEFAULT;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return [origins[0], origins[1]];
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
+
import { CSSValue } from '../syntax/parser';
|
|
3
|
+
import { NumberValueToken, TokenType } from '../syntax/tokenizer';
|
|
4
|
+
import { Context } from '../../core/context';
|
|
5
|
+
import { angle } from '../types/angle';
|
|
6
|
+
export type Matrix = [number, number, number, number, number, number];
|
|
7
|
+
export type Transform = Matrix | null;
|
|
8
|
+
|
|
9
|
+
export const transform: IPropertyValueDescriptor<Transform> = {
|
|
10
|
+
name: 'transform',
|
|
11
|
+
initialValue: 'none',
|
|
12
|
+
prefix: true,
|
|
13
|
+
type: PropertyDescriptorParsingType.VALUE,
|
|
14
|
+
parse: (_context: Context, token: CSSValue) => {
|
|
15
|
+
if (token.type === TokenType.IDENT_TOKEN && token.value === 'none') {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (token.type === TokenType.FUNCTION) {
|
|
20
|
+
const transformFunction = SUPPORTED_TRANSFORM_FUNCTIONS[token.name];
|
|
21
|
+
if (typeof transformFunction === 'undefined') {
|
|
22
|
+
throw new Error(`Attempting to parse an unsupported transform function "${token.name}"`);
|
|
23
|
+
}
|
|
24
|
+
return transformFunction(_context, token.values);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const matrix = (_context: Context, args: CSSValue[]): Transform => {
|
|
32
|
+
const values = args.filter((arg) => arg.type === TokenType.NUMBER_TOKEN).map((arg: NumberValueToken) => arg.number);
|
|
33
|
+
|
|
34
|
+
return values.length === 6 ? (values as Matrix) : null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// doesn't support 3D transforms at the moment
|
|
38
|
+
const matrix3d = (_context: Context, args: CSSValue[]): Transform => {
|
|
39
|
+
const values = args.filter((arg) => arg.type === TokenType.NUMBER_TOKEN).map((arg: NumberValueToken) => arg.number);
|
|
40
|
+
|
|
41
|
+
const [a1, b1, {}, {}, a2, b2, {}, {}, {}, {}, {}, {}, a4, b4, {}, {}] = values;
|
|
42
|
+
|
|
43
|
+
return values.length === 16 ? [a1, b1, a2, b2, a4, b4] : null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const rotate = (context: Context, args: CSSValue[]): Transform => {
|
|
47
|
+
if (args.length !== 1) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const arg = args[0];
|
|
52
|
+
let radians = 0;
|
|
53
|
+
|
|
54
|
+
if (arg.type === TokenType.NUMBER_TOKEN && arg.number === 0) {
|
|
55
|
+
radians = 0;
|
|
56
|
+
} else if (arg.type === TokenType.DIMENSION_TOKEN) {
|
|
57
|
+
radians = angle.parse(context, arg);
|
|
58
|
+
} else {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const cos = Math.cos(radians);
|
|
63
|
+
const sin = Math.sin(radians);
|
|
64
|
+
|
|
65
|
+
return [cos, sin, -sin, cos, 0, 0];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const SUPPORTED_TRANSFORM_FUNCTIONS: {
|
|
69
|
+
[key: string]: (context: Context, args: CSSValue[]) => Transform;
|
|
70
|
+
} = {
|
|
71
|
+
matrix: matrix,
|
|
72
|
+
matrix3d: matrix3d,
|
|
73
|
+
rotate: rotate
|
|
74
|
+
};
|