@ohos-ports/html2canvas-pro 0.0.0-stage → 2.3.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/dist/html2canvas-pro.cjs +11191 -0
- package/dist/html2canvas-pro.cjs.map +1 -0
- package/dist/html2canvas-pro.esm.js +11182 -0
- package/dist/html2canvas-pro.esm.js.map +1 -0
- package/dist/html2canvas-pro.js +11196 -0
- package/dist/html2canvas-pro.js.map +1 -0
- package/dist/html2canvas-pro.min.js +10 -0
- package/dist/lib/config.js +49 -0
- package/dist/lib/core/abort-helper.js +20 -0
- package/dist/lib/core/background-parser.js +41 -0
- package/dist/lib/core/bitwise.js +5 -0
- package/dist/lib/core/cache-storage.js +268 -0
- package/dist/lib/core/config-assembler.js +88 -0
- package/dist/lib/core/constants.js +25 -0
- package/dist/lib/core/context.js +19 -0
- package/dist/lib/core/debugger.js +27 -0
- package/dist/lib/core/features.js +190 -0
- package/dist/lib/core/logger.js +56 -0
- package/dist/lib/core/lru-map.js +66 -0
- package/dist/lib/core/origin-checker.js +53 -0
- package/dist/lib/core/performance-monitor.js +185 -0
- package/dist/lib/core/render-element.js +132 -0
- package/dist/lib/core/util.js +4 -0
- package/dist/lib/core/validator.js +500 -0
- package/dist/lib/css/grouped/background-styles.js +36 -0
- package/dist/lib/css/grouped/border-styles.js +75 -0
- package/dist/lib/css/grouped/font-styles.js +93 -0
- package/dist/lib/css/grouped/layout-styles.js +127 -0
- package/dist/lib/css/index.js +330 -0
- package/dist/lib/css/layout/bounds.js +52 -0
- package/dist/lib/css/layout/text.js +133 -0
- package/dist/lib/css/property-descriptor.js +2 -0
- package/dist/lib/css/property-descriptors/background-blend-mode.js +41 -0
- package/dist/lib/css/property-descriptors/background-clip.js +23 -0
- package/dist/lib/css/property-descriptors/background-color.js +10 -0
- package/dist/lib/css/property-descriptors/background-image.js +24 -0
- package/dist/lib/css/property-descriptors/background-origin.js +23 -0
- package/dist/lib/css/property-descriptors/background-position.js +19 -0
- package/dist/lib/css/property-descriptors/background-repeat.js +33 -0
- package/dist/lib/css/property-descriptors/background-size.js +23 -0
- package/dist/lib/css/property-descriptors/border-color.js +14 -0
- package/dist/lib/css/property-descriptors/border-image-repeat.js +42 -0
- package/dist/lib/css/property-descriptors/border-image-slice.js +45 -0
- package/dist/lib/css/property-descriptors/border-image-source.js +22 -0
- package/dist/lib/css/property-descriptors/border-radius.js +15 -0
- package/dist/lib/css/property-descriptors/border-style.js +26 -0
- package/dist/lib/css/property-descriptors/border-width.js +20 -0
- package/dist/lib/css/property-descriptors/box-decoration-break.js +18 -0
- package/dist/lib/css/property-descriptors/box-shadow.js +54 -0
- package/dist/lib/css/property-descriptors/clip-path.js +189 -0
- package/dist/lib/css/property-descriptors/color.js +10 -0
- package/dist/lib/css/property-descriptors/content.js +19 -0
- package/dist/lib/css/property-descriptors/counter-increment.js +35 -0
- package/dist/lib/css/property-descriptors/counter-reset.js +18 -0
- package/dist/lib/css/property-descriptors/direction.js +18 -0
- package/dist/lib/css/property-descriptors/display.js +81 -0
- package/dist/lib/css/property-descriptors/duration.js +14 -0
- package/dist/lib/css/property-descriptors/filter.js +76 -0
- package/dist/lib/css/property-descriptors/float.js +22 -0
- package/dist/lib/css/property-descriptors/font-family.js +32 -0
- package/dist/lib/css/property-descriptors/font-size.js +10 -0
- package/dist/lib/css/property-descriptors/font-style.js +20 -0
- package/dist/lib/css/property-descriptors/font-variant-ligatures.js +34 -0
- package/dist/lib/css/property-descriptors/font-variant.js +13 -0
- package/dist/lib/css/property-descriptors/font-weight.js +25 -0
- package/dist/lib/css/property-descriptors/image-rendering.js +33 -0
- package/dist/lib/css/property-descriptors/letter-spacing.js +21 -0
- package/dist/lib/css/property-descriptors/line-break.js +23 -0
- package/dist/lib/css/property-descriptors/line-height.js +24 -0
- package/dist/lib/css/property-descriptors/list-style-image.js +17 -0
- package/dist/lib/css/property-descriptors/list-style-position.js +18 -0
- package/dist/lib/css/property-descriptors/list-style-type.js +122 -0
- package/dist/lib/css/property-descriptors/margin.js +13 -0
- package/dist/lib/css/property-descriptors/mix-blend-mode.js +31 -0
- package/dist/lib/css/property-descriptors/object-fit.js +28 -0
- package/dist/lib/css/property-descriptors/object-position.js +42 -0
- package/dist/lib/css/property-descriptors/opacity.js +16 -0
- package/dist/lib/css/property-descriptors/overflow-wrap.js +18 -0
- package/dist/lib/css/property-descriptors/overflow.js +27 -0
- package/dist/lib/css/property-descriptors/padding.js +14 -0
- package/dist/lib/css/property-descriptors/paint-order.js +33 -0
- package/dist/lib/css/property-descriptors/position.js +22 -0
- package/dist/lib/css/property-descriptors/quotes.js +41 -0
- package/dist/lib/css/property-descriptors/rotate.js +27 -0
- package/dist/lib/css/property-descriptors/text-align.js +21 -0
- package/dist/lib/css/property-descriptors/text-decoration-color.js +10 -0
- package/dist/lib/css/property-descriptors/text-decoration-line.js +28 -0
- package/dist/lib/css/property-descriptors/text-decoration-style.js +24 -0
- package/dist/lib/css/property-descriptors/text-decoration-thickness.js +26 -0
- package/dist/lib/css/property-descriptors/text-overflow.js +18 -0
- package/dist/lib/css/property-descriptors/text-shadow.js +46 -0
- package/dist/lib/css/property-descriptors/text-transform.js +20 -0
- package/dist/lib/css/property-descriptors/text-underline-offset.js +23 -0
- package/dist/lib/css/property-descriptors/transform-origin.js +24 -0
- package/dist/lib/css/property-descriptors/transform.js +57 -0
- package/dist/lib/css/property-descriptors/visibility.js +20 -0
- package/dist/lib/css/property-descriptors/webkit-line-clamp.js +26 -0
- package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js +10 -0
- package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js +16 -0
- package/dist/lib/css/property-descriptors/word-break.js +26 -0
- package/dist/lib/css/property-descriptors/writing-mode.js +28 -0
- package/dist/lib/css/property-descriptors/z-index.js +19 -0
- package/dist/lib/css/property-descriptors/zoom.js +18 -0
- package/dist/lib/css/syntax/parser.js +140 -0
- package/dist/lib/css/syntax/token-constants.js +214 -0
- package/dist/lib/css/syntax/token-singletons.js +36 -0
- package/dist/lib/css/syntax/token-types.js +10 -0
- package/dist/lib/css/syntax/tokenizer.js +502 -0
- package/dist/lib/css/type-descriptor.js +2 -0
- package/dist/lib/css/types/angle.js +80 -0
- package/dist/lib/css/types/color-math.js +25 -0
- package/dist/lib/css/types/color-spaces/a98.js +78 -0
- package/dist/lib/css/types/color-spaces/p3.js +86 -0
- package/dist/lib/css/types/color-spaces/pro-photo.js +83 -0
- package/dist/lib/css/types/color-spaces/rec2020.js +85 -0
- package/dist/lib/css/types/color-spaces/srgb.js +79 -0
- package/dist/lib/css/types/color-utilities.js +342 -0
- package/dist/lib/css/types/color.js +400 -0
- package/dist/lib/css/types/functions/-prefix-linear-gradient.js +32 -0
- package/dist/lib/css/types/functions/-prefix-radial-gradient.js +83 -0
- package/dist/lib/css/types/functions/-webkit-gradient.js +59 -0
- package/dist/lib/css/types/functions/counter.js +367 -0
- package/dist/lib/css/types/functions/gradient.js +163 -0
- package/dist/lib/css/types/functions/linear-gradient.js +27 -0
- package/dist/lib/css/types/functions/radial-gradient.js +90 -0
- package/dist/lib/css/types/functions/repeating-linear-gradient.js +9 -0
- package/dist/lib/css/types/image.js +62 -0
- package/dist/lib/css/types/index.js +2 -0
- package/dist/lib/css/types/length-percentage.js +197 -0
- package/dist/lib/css/types/length.js +5 -0
- package/dist/lib/css/types/safe-eval.js +80 -0
- package/dist/lib/css/types/time.js +17 -0
- package/dist/lib/dom/document-cloner.js +597 -0
- package/dist/lib/dom/dom-normalizer.js +115 -0
- package/dist/lib/dom/element-container.js +56 -0
- package/dist/lib/dom/elements/li-element-container.js +11 -0
- package/dist/lib/dom/elements/ol-element-container.js +12 -0
- package/dist/lib/dom/elements/select-element-container.js +12 -0
- package/dist/lib/dom/elements/textarea-element-container.js +11 -0
- package/dist/lib/dom/node-parser.js +112 -0
- package/dist/lib/dom/node-type-guards.js +81 -0
- package/dist/lib/dom/replaced-elements/canvas-element-container.js +13 -0
- package/dist/lib/dom/replaced-elements/iframe-element-container.js +38 -0
- package/dist/lib/dom/replaced-elements/image-element-container.js +14 -0
- package/dist/lib/dom/replaced-elements/index.js +2 -0
- package/dist/lib/dom/replaced-elements/input-element-container.js +89 -0
- package/dist/lib/dom/replaced-elements/svg-element-container.js +19 -0
- package/dist/lib/dom/slot-cloner.js +176 -0
- package/dist/lib/dom/text-container.js +35 -0
- package/dist/lib/index.js +49 -0
- package/dist/lib/options.js +2 -0
- package/dist/lib/render/background.js +188 -0
- package/dist/lib/render/bezier-curve.js +34 -0
- package/dist/lib/render/border.js +104 -0
- package/dist/lib/render/bound-curves.js +188 -0
- package/dist/lib/render/box-sizing.js +20 -0
- package/dist/lib/render/canvas/background-renderer.js +327 -0
- package/dist/lib/render/canvas/border-image-renderer.js +153 -0
- package/dist/lib/render/canvas/border-renderer.js +184 -0
- package/dist/lib/render/canvas/canvas-path.js +25 -0
- package/dist/lib/render/canvas/canvas-renderer.js +312 -0
- package/dist/lib/render/canvas/content-renderer.js +204 -0
- package/dist/lib/render/canvas/effects-renderer.js +171 -0
- package/dist/lib/render/canvas/font-utils.js +29 -0
- package/dist/lib/render/canvas/foreignobject-renderer.js +38 -0
- package/dist/lib/render/canvas/text/text-decoration-renderer.js +99 -0
- package/dist/lib/render/canvas/text-renderer.js +485 -0
- package/dist/lib/render/effects.js +231 -0
- package/dist/lib/render/font-metrics.js +53 -0
- package/dist/lib/render/object-fit.js +91 -0
- package/dist/lib/render/path.js +26 -0
- package/dist/lib/render/renderer-interface.js +2 -0
- package/dist/lib/render/stacking-context.js +340 -0
- package/dist/lib/render/vector.js +16 -0
- package/dist/types/config.d.ts +44 -0
- package/dist/types/core/abort-helper.d.ts +12 -0
- package/dist/types/core/background-parser.d.ts +16 -0
- package/dist/types/core/bitwise.d.ts +1 -0
- package/dist/types/core/cache-storage.d.ts +68 -0
- package/dist/types/core/config-assembler.d.ts +28 -0
- package/dist/types/core/constants.d.ts +22 -0
- package/dist/types/core/context.d.ts +22 -0
- package/dist/types/core/debugger.d.ts +8 -0
- package/dist/types/core/features.d.ts +12 -0
- package/dist/types/core/logger.d.ts +18 -0
- package/dist/types/core/lru-map.d.ts +37 -0
- package/dist/types/core/origin-checker.d.ts +33 -0
- package/dist/types/core/performance-monitor.d.ts +120 -0
- package/dist/types/core/render-element.d.ts +3 -0
- package/dist/types/core/util.d.ts +1 -0
- package/dist/types/core/validator.d.ts +130 -0
- package/dist/types/css/grouped/background-styles.d.ts +16 -0
- package/dist/types/css/grouped/border-styles.d.ts +31 -0
- package/dist/types/css/grouped/font-styles.d.ts +35 -0
- package/dist/types/css/grouped/layout-styles.d.ts +46 -0
- package/dist/types/css/index.d.ts +185 -0
- package/dist/types/css/layout/bounds.d.ts +14 -0
- package/dist/types/css/layout/text.d.ts +10 -0
- package/dist/types/css/property-descriptor.d.ts +40 -0
- package/dist/types/css/property-descriptors/background-blend-mode.d.ts +23 -0
- package/dist/types/css/property-descriptors/background-clip.d.ts +8 -0
- package/dist/types/css/property-descriptors/background-color.d.ts +2 -0
- package/dist/types/css/property-descriptors/background-image.d.ts +3 -0
- package/dist/types/css/property-descriptors/background-origin.d.ts +8 -0
- package/dist/types/css/property-descriptors/background-position.d.ts +5 -0
- package/dist/types/css/property-descriptors/background-repeat.d.ts +9 -0
- package/dist/types/css/property-descriptors/background-size.d.ts +11 -0
- package/dist/types/css/property-descriptors/border-color.d.ts +5 -0
- package/dist/types/css/property-descriptors/border-image-repeat.d.ts +12 -0
- package/dist/types/css/property-descriptors/border-image-slice.d.ts +10 -0
- package/dist/types/css/property-descriptors/border-image-source.d.ts +4 -0
- package/dist/types/css/property-descriptors/border-radius.d.ts +7 -0
- package/dist/types/css/property-descriptors/border-style.d.ts +12 -0
- package/dist/types/css/property-descriptors/border-width.d.ts +5 -0
- package/dist/types/css/property-descriptors/box-decoration-break.d.ts +6 -0
- package/dist/types/css/property-descriptors/box-shadow.d.ts +14 -0
- package/dist/types/css/property-descriptors/clip-path.d.ts +62 -0
- package/dist/types/css/property-descriptors/color.d.ts +2 -0
- package/dist/types/css/property-descriptors/content.d.ts +4 -0
- package/dist/types/css/property-descriptors/counter-increment.d.ts +10 -0
- package/dist/types/css/property-descriptors/counter-reset.d.ts +7 -0
- package/dist/types/css/property-descriptors/direction.d.ts +6 -0
- package/dist/types/css/property-descriptors/display.d.ts +35 -0
- package/dist/types/css/property-descriptors/duration.d.ts +2 -0
- package/dist/types/css/property-descriptors/filter.d.ts +3 -0
- package/dist/types/css/property-descriptors/float.d.ts +9 -0
- package/dist/types/css/property-descriptors/font-family.d.ts +4 -0
- package/dist/types/css/property-descriptors/font-size.d.ts +2 -0
- package/dist/types/css/property-descriptors/font-style.d.ts +7 -0
- package/dist/types/css/property-descriptors/font-variant-ligatures.d.ts +14 -0
- package/dist/types/css/property-descriptors/font-variant.d.ts +2 -0
- package/dist/types/css/property-descriptors/font-weight.d.ts +2 -0
- package/dist/types/css/property-descriptors/image-rendering.d.ts +8 -0
- package/dist/types/css/property-descriptors/letter-spacing.d.ts +2 -0
- package/dist/types/css/property-descriptors/line-break.d.ts +6 -0
- package/dist/types/css/property-descriptors/line-height.d.ts +4 -0
- package/dist/types/css/property-descriptors/list-style-image.d.ts +3 -0
- package/dist/types/css/property-descriptors/list-style-position.d.ts +6 -0
- package/dist/types/css/property-descriptors/list-style-type.d.ts +58 -0
- package/dist/types/css/property-descriptors/margin.d.ts +5 -0
- package/dist/types/css/property-descriptors/mix-blend-mode.d.ts +21 -0
- package/dist/types/css/property-descriptors/object-fit.d.ts +10 -0
- package/dist/types/css/property-descriptors/object-position.d.ts +4 -0
- package/dist/types/css/property-descriptors/opacity.d.ts +2 -0
- package/dist/types/css/property-descriptors/overflow-wrap.d.ts +6 -0
- package/dist/types/css/property-descriptors/overflow.d.ts +9 -0
- package/dist/types/css/property-descriptors/padding.d.ts +5 -0
- package/dist/types/css/property-descriptors/paint-order.d.ts +8 -0
- package/dist/types/css/property-descriptors/position.d.ts +9 -0
- package/dist/types/css/property-descriptors/quotes.d.ts +8 -0
- package/dist/types/css/property-descriptors/rotate.d.ts +3 -0
- package/dist/types/css/property-descriptors/text-align.d.ts +7 -0
- package/dist/types/css/property-descriptors/text-decoration-color.d.ts +2 -0
- package/dist/types/css/property-descriptors/text-decoration-line.d.ts +10 -0
- package/dist/types/css/property-descriptors/text-decoration-style.d.ts +9 -0
- package/dist/types/css/property-descriptors/text-decoration-thickness.d.ts +3 -0
- package/dist/types/css/property-descriptors/text-overflow.d.ts +6 -0
- package/dist/types/css/property-descriptors/text-shadow.d.ts +12 -0
- package/dist/types/css/property-descriptors/text-transform.d.ts +8 -0
- package/dist/types/css/property-descriptors/text-underline-offset.d.ts +3 -0
- package/dist/types/css/property-descriptors/transform-origin.d.ts +4 -0
- package/dist/types/css/property-descriptors/transform.d.ts +4 -0
- package/dist/types/css/property-descriptors/visibility.d.ts +7 -0
- package/dist/types/css/property-descriptors/webkit-line-clamp.d.ts +7 -0
- package/dist/types/css/property-descriptors/webkit-text-stroke-color.d.ts +2 -0
- package/dist/types/css/property-descriptors/webkit-text-stroke-width.d.ts +2 -0
- package/dist/types/css/property-descriptors/word-break.d.ts +7 -0
- package/dist/types/css/property-descriptors/writing-mode.d.ts +11 -0
- package/dist/types/css/property-descriptors/z-index.d.ts +7 -0
- package/dist/types/css/property-descriptors/zoom.d.ts +3 -0
- package/dist/types/css/syntax/parser.d.ts +34 -0
- package/dist/types/css/syntax/token-constants.d.ts +74 -0
- package/dist/types/css/syntax/token-singletons.d.ts +22 -0
- package/dist/types/css/syntax/token-types.d.ts +72 -0
- package/dist/types/css/syntax/tokenizer.d.ts +32 -0
- package/dist/types/css/type-descriptor.d.ts +6 -0
- package/dist/types/css/types/angle.d.ts +7 -0
- package/dist/types/css/types/color-math.d.ts +12 -0
- package/dist/types/css/types/color-spaces/a98.d.ts +39 -0
- package/dist/types/css/types/color-spaces/p3.d.ts +45 -0
- package/dist/types/css/types/color-spaces/pro-photo.d.ts +45 -0
- package/dist/types/css/types/color-spaces/rec2020.d.ts +45 -0
- package/dist/types/css/types/color-spaces/srgb.d.ts +38 -0
- package/dist/types/css/types/color-utilities.d.ts +107 -0
- package/dist/types/css/types/color.d.ts +8 -0
- package/dist/types/css/types/functions/-prefix-linear-gradient.d.ts +4 -0
- package/dist/types/css/types/functions/-prefix-radial-gradient.d.ts +4 -0
- package/dist/types/css/types/functions/-webkit-gradient.d.ts +4 -0
- package/dist/types/css/types/functions/counter.d.ts +10 -0
- package/dist/types/css/types/functions/gradient.d.ts +7 -0
- package/dist/types/css/types/functions/linear-gradient.d.ts +4 -0
- package/dist/types/css/types/functions/radial-gradient.d.ts +12 -0
- package/dist/types/css/types/functions/repeating-linear-gradient.d.ts +4 -0
- package/dist/types/css/types/image.d.ts +56 -0
- package/dist/types/css/types/index.d.ts +1 -0
- package/dist/types/css/types/length-percentage.d.ts +62 -0
- package/dist/types/css/types/length.d.ts +4 -0
- package/dist/types/css/types/safe-eval.d.ts +8 -0
- package/dist/types/css/types/time.d.ts +2 -0
- package/dist/types/dom/document-cloner.d.ts +57 -0
- package/dist/types/dom/dom-normalizer.d.ts +62 -0
- package/dist/types/dom/element-container.d.ts +31 -0
- package/dist/types/dom/elements/li-element-container.d.ts +6 -0
- package/dist/types/dom/elements/ol-element-container.d.ts +7 -0
- package/dist/types/dom/elements/select-element-container.d.ts +6 -0
- package/dist/types/dom/elements/textarea-element-container.d.ts +6 -0
- package/dist/types/dom/node-parser.d.ts +3 -0
- package/dist/types/dom/node-type-guards.d.ts +32 -0
- package/dist/types/dom/replaced-elements/canvas-element-container.d.ts +8 -0
- package/dist/types/dom/replaced-elements/iframe-element-container.d.ts +14 -0
- package/dist/types/dom/replaced-elements/image-element-container.d.ts +8 -0
- package/dist/types/dom/replaced-elements/index.d.ts +4 -0
- package/dist/types/dom/replaced-elements/input-element-container.d.ts +14 -0
- package/dist/types/dom/replaced-elements/svg-element-container.d.ts +8 -0
- package/dist/types/dom/slot-cloner.d.ts +66 -0
- package/dist/types/dom/text-container.d.ts +8 -0
- package/dist/types/index.d.ts +36 -0
- package/dist/types/options.d.ts +62 -0
- package/dist/types/render/background.d.ts +16 -0
- package/dist/types/render/bezier-curve.d.ts +14 -0
- package/dist/types/render/border.d.ts +6 -0
- package/dist/types/render/bound-curves.d.ts +32 -0
- package/dist/types/render/box-sizing.d.ts +4 -0
- package/dist/types/render/canvas/background-renderer.d.ts +94 -0
- package/dist/types/render/canvas/border-image-renderer.d.ts +18 -0
- package/dist/types/render/canvas/border-renderer.d.ts +67 -0
- package/dist/types/render/canvas/canvas-path.d.ts +3 -0
- package/dist/types/render/canvas/canvas-renderer.d.ts +60 -0
- package/dist/types/render/canvas/content-renderer.d.ts +43 -0
- package/dist/types/render/canvas/effects-renderer.d.ts +90 -0
- package/dist/types/render/canvas/font-utils.d.ts +19 -0
- package/dist/types/render/canvas/foreignobject-renderer.d.ts +10 -0
- package/dist/types/render/canvas/text/text-decoration-renderer.d.ts +18 -0
- package/dist/types/render/canvas/text-renderer.d.ts +103 -0
- package/dist/types/render/effects.d.ts +112 -0
- package/dist/types/render/font-metrics.d.ts +11 -0
- package/dist/types/render/object-fit.d.ts +19 -0
- package/dist/types/render/path.d.ts +13 -0
- package/dist/types/render/renderer-interface.d.ts +28 -0
- package/dist/types/render/stacking-context.d.ts +49 -0
- package/dist/types/render/vector.d.ts +9 -0
- package/package.json +139 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// https://www.w3.org/TR/css-syntax-3
|
|
3
|
+
// Token type system — enums, interfaces, and union types consumed by
|
|
4
|
+
// the tokenizer, parser, and property descriptors.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FLAG_NUMBER = exports.FLAG_INTEGER = exports.FLAG_ID = exports.FLAG_UNRESTRICTED = void 0;
|
|
7
|
+
exports.FLAG_UNRESTRICTED = 1 << 0;
|
|
8
|
+
exports.FLAG_ID = 1 << 1;
|
|
9
|
+
exports.FLAG_INTEGER = 1 << 2;
|
|
10
|
+
exports.FLAG_NUMBER = 1 << 3;
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// https://www.w3.org/TR/css-syntax-3
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Tokenizer = exports.COLUMN_TOKEN = exports.INCLUDE_MATCH_TOKEN = exports.DASH_MATCH_TOKEN = exports.SUBSTRING_MATCH_TOKEN = exports.SUFFIX_MATCH_TOKEN = exports.PREFIX_MATCH_TOKEN = exports.CDO_TOKEN = exports.CDC_TOKEN = exports.BAD_STRING_TOKEN = exports.BAD_URL_TOKEN = exports.EOF_TOKEN = exports.WHITESPACE_TOKEN = exports.RIGHT_SQUARE_BRACKET_TOKEN = exports.LEFT_SQUARE_BRACKET_TOKEN = exports.RIGHT_CURLY_BRACKET_TOKEN = exports.LEFT_CURLY_BRACKET_TOKEN = exports.RIGHT_PARENTHESIS_TOKEN = exports.LEFT_PARENTHESIS_TOKEN = exports.SEMICOLON_TOKEN = exports.COLON_TOKEN = exports.COMMA_TOKEN = exports.isNumberStart = exports.isNameStartCodePoint = exports.isIdentifierStart = exports.isValidEscape = exports.isNameCodePoint = exports.isWhiteSpace = exports.isHex = exports.isDigit = exports.FLAG_NUMBER = exports.FLAG_INTEGER = exports.FLAG_ID = exports.FLAG_UNRESTRICTED = void 0;
|
|
5
|
+
const css_line_break_1 = require("css-line-break");
|
|
6
|
+
const token_types_1 = require("./token-types");
|
|
7
|
+
const token_constants_1 = require("./token-constants");
|
|
8
|
+
const token_constants_2 = require("./token-constants");
|
|
9
|
+
const token_singletons_1 = require("./token-singletons");
|
|
10
|
+
var token_types_2 = require("./token-types");
|
|
11
|
+
Object.defineProperty(exports, "FLAG_UNRESTRICTED", { enumerable: true, get: function () { return token_types_2.FLAG_UNRESTRICTED; } });
|
|
12
|
+
Object.defineProperty(exports, "FLAG_ID", { enumerable: true, get: function () { return token_types_2.FLAG_ID; } });
|
|
13
|
+
Object.defineProperty(exports, "FLAG_INTEGER", { enumerable: true, get: function () { return token_types_2.FLAG_INTEGER; } });
|
|
14
|
+
Object.defineProperty(exports, "FLAG_NUMBER", { enumerable: true, get: function () { return token_types_2.FLAG_NUMBER; } });
|
|
15
|
+
var token_constants_3 = require("./token-constants");
|
|
16
|
+
Object.defineProperty(exports, "isDigit", { enumerable: true, get: function () { return token_constants_3.isDigit; } });
|
|
17
|
+
Object.defineProperty(exports, "isHex", { enumerable: true, get: function () { return token_constants_3.isHex; } });
|
|
18
|
+
Object.defineProperty(exports, "isWhiteSpace", { enumerable: true, get: function () { return token_constants_3.isWhiteSpace; } });
|
|
19
|
+
Object.defineProperty(exports, "isNameCodePoint", { enumerable: true, get: function () { return token_constants_3.isNameCodePoint; } });
|
|
20
|
+
Object.defineProperty(exports, "isValidEscape", { enumerable: true, get: function () { return token_constants_3.isValidEscape; } });
|
|
21
|
+
Object.defineProperty(exports, "isIdentifierStart", { enumerable: true, get: function () { return token_constants_3.isIdentifierStart; } });
|
|
22
|
+
Object.defineProperty(exports, "isNameStartCodePoint", { enumerable: true, get: function () { return token_constants_3.isNameStartCodePoint; } });
|
|
23
|
+
Object.defineProperty(exports, "isNumberStart", { enumerable: true, get: function () { return token_constants_3.isNumberStart; } });
|
|
24
|
+
var token_singletons_2 = require("./token-singletons");
|
|
25
|
+
Object.defineProperty(exports, "COMMA_TOKEN", { enumerable: true, get: function () { return token_singletons_2.COMMA_TOKEN; } });
|
|
26
|
+
Object.defineProperty(exports, "COLON_TOKEN", { enumerable: true, get: function () { return token_singletons_2.COLON_TOKEN; } });
|
|
27
|
+
Object.defineProperty(exports, "SEMICOLON_TOKEN", { enumerable: true, get: function () { return token_singletons_2.SEMICOLON_TOKEN; } });
|
|
28
|
+
Object.defineProperty(exports, "LEFT_PARENTHESIS_TOKEN", { enumerable: true, get: function () { return token_singletons_2.LEFT_PARENTHESIS_TOKEN; } });
|
|
29
|
+
Object.defineProperty(exports, "RIGHT_PARENTHESIS_TOKEN", { enumerable: true, get: function () { return token_singletons_2.RIGHT_PARENTHESIS_TOKEN; } });
|
|
30
|
+
Object.defineProperty(exports, "LEFT_CURLY_BRACKET_TOKEN", { enumerable: true, get: function () { return token_singletons_2.LEFT_CURLY_BRACKET_TOKEN; } });
|
|
31
|
+
Object.defineProperty(exports, "RIGHT_CURLY_BRACKET_TOKEN", { enumerable: true, get: function () { return token_singletons_2.RIGHT_CURLY_BRACKET_TOKEN; } });
|
|
32
|
+
Object.defineProperty(exports, "LEFT_SQUARE_BRACKET_TOKEN", { enumerable: true, get: function () { return token_singletons_2.LEFT_SQUARE_BRACKET_TOKEN; } });
|
|
33
|
+
Object.defineProperty(exports, "RIGHT_SQUARE_BRACKET_TOKEN", { enumerable: true, get: function () { return token_singletons_2.RIGHT_SQUARE_BRACKET_TOKEN; } });
|
|
34
|
+
Object.defineProperty(exports, "WHITESPACE_TOKEN", { enumerable: true, get: function () { return token_singletons_2.WHITESPACE_TOKEN; } });
|
|
35
|
+
Object.defineProperty(exports, "EOF_TOKEN", { enumerable: true, get: function () { return token_singletons_2.EOF_TOKEN; } });
|
|
36
|
+
Object.defineProperty(exports, "BAD_URL_TOKEN", { enumerable: true, get: function () { return token_singletons_2.BAD_URL_TOKEN; } });
|
|
37
|
+
Object.defineProperty(exports, "BAD_STRING_TOKEN", { enumerable: true, get: function () { return token_singletons_2.BAD_STRING_TOKEN; } });
|
|
38
|
+
Object.defineProperty(exports, "CDC_TOKEN", { enumerable: true, get: function () { return token_singletons_2.CDC_TOKEN; } });
|
|
39
|
+
Object.defineProperty(exports, "CDO_TOKEN", { enumerable: true, get: function () { return token_singletons_2.CDO_TOKEN; } });
|
|
40
|
+
Object.defineProperty(exports, "PREFIX_MATCH_TOKEN", { enumerable: true, get: function () { return token_singletons_2.PREFIX_MATCH_TOKEN; } });
|
|
41
|
+
Object.defineProperty(exports, "SUFFIX_MATCH_TOKEN", { enumerable: true, get: function () { return token_singletons_2.SUFFIX_MATCH_TOKEN; } });
|
|
42
|
+
Object.defineProperty(exports, "SUBSTRING_MATCH_TOKEN", { enumerable: true, get: function () { return token_singletons_2.SUBSTRING_MATCH_TOKEN; } });
|
|
43
|
+
Object.defineProperty(exports, "DASH_MATCH_TOKEN", { enumerable: true, get: function () { return token_singletons_2.DASH_MATCH_TOKEN; } });
|
|
44
|
+
Object.defineProperty(exports, "INCLUDE_MATCH_TOKEN", { enumerable: true, get: function () { return token_singletons_2.INCLUDE_MATCH_TOKEN; } });
|
|
45
|
+
Object.defineProperty(exports, "COLUMN_TOKEN", { enumerable: true, get: function () { return token_singletons_2.COLUMN_TOKEN; } });
|
|
46
|
+
class Tokenizer {
|
|
47
|
+
static get() {
|
|
48
|
+
return Tokenizer._pool.pop() || new Tokenizer();
|
|
49
|
+
}
|
|
50
|
+
static release(tokenizer) {
|
|
51
|
+
if (Tokenizer._pool.length < Tokenizer.MAX_POOL_SIZE) {
|
|
52
|
+
tokenizer._reset();
|
|
53
|
+
Tokenizer._pool.push(tokenizer);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
constructor() {
|
|
57
|
+
this._value = [];
|
|
58
|
+
}
|
|
59
|
+
_reset() {
|
|
60
|
+
this._value = [];
|
|
61
|
+
}
|
|
62
|
+
write(chunk) {
|
|
63
|
+
this._value = this._value.concat((0, css_line_break_1.toCodePoints)(chunk));
|
|
64
|
+
}
|
|
65
|
+
read() {
|
|
66
|
+
const tokens = [];
|
|
67
|
+
let token = this.consumeToken();
|
|
68
|
+
while (token !== token_singletons_1.EOF_TOKEN) {
|
|
69
|
+
tokens.push(token);
|
|
70
|
+
token = this.consumeToken();
|
|
71
|
+
}
|
|
72
|
+
return tokens;
|
|
73
|
+
}
|
|
74
|
+
consumeToken() {
|
|
75
|
+
const codePoint = this.consumeCodePoint();
|
|
76
|
+
switch (codePoint) {
|
|
77
|
+
case token_constants_1.QUOTATION_MARK:
|
|
78
|
+
return this.consumeStringToken(token_constants_1.QUOTATION_MARK);
|
|
79
|
+
case token_constants_1.NUMBER_SIGN: {
|
|
80
|
+
const c1 = this.peekCodePoint(0);
|
|
81
|
+
const c2 = this.peekCodePoint(1);
|
|
82
|
+
const c3 = this.peekCodePoint(2);
|
|
83
|
+
if ((0, token_constants_2.isNameCodePoint)(c1) || (0, token_constants_2.isValidEscape)(c2, c3)) {
|
|
84
|
+
const flags = (0, token_constants_2.isIdentifierStart)(c1, c2, c3) ? token_types_1.FLAG_ID : token_types_1.FLAG_UNRESTRICTED;
|
|
85
|
+
const value = this.consumeName();
|
|
86
|
+
return { type: 5 /* TokenType.HASH_TOKEN */, value, flags };
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case token_constants_1.DOLLAR_SIGN:
|
|
91
|
+
if (this.peekCodePoint(0) === token_constants_1.EQUALS_SIGN) {
|
|
92
|
+
this.consumeCodePoint();
|
|
93
|
+
return token_singletons_1.SUFFIX_MATCH_TOKEN;
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
case token_constants_1.APOSTROPHE:
|
|
97
|
+
return this.consumeStringToken(token_constants_1.APOSTROPHE);
|
|
98
|
+
case token_constants_1.LEFT_PARENTHESIS:
|
|
99
|
+
return token_singletons_1.LEFT_PARENTHESIS_TOKEN;
|
|
100
|
+
case token_constants_1.RIGHT_PARENTHESIS:
|
|
101
|
+
return token_singletons_1.RIGHT_PARENTHESIS_TOKEN;
|
|
102
|
+
case token_constants_1.ASTERISK:
|
|
103
|
+
if (this.peekCodePoint(0) === token_constants_1.EQUALS_SIGN) {
|
|
104
|
+
this.consumeCodePoint();
|
|
105
|
+
return token_singletons_1.SUBSTRING_MATCH_TOKEN;
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case token_constants_1.PLUS_SIGN:
|
|
109
|
+
if ((0, token_constants_2.isNumberStart)(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) {
|
|
110
|
+
this.reconsumeCodePoint(codePoint);
|
|
111
|
+
return this.consumeNumericToken();
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
case token_constants_1.COMMA:
|
|
115
|
+
return token_singletons_1.COMMA_TOKEN;
|
|
116
|
+
case token_constants_1.HYPHEN_MINUS: {
|
|
117
|
+
const e1 = codePoint;
|
|
118
|
+
const e2 = this.peekCodePoint(0);
|
|
119
|
+
const e3 = this.peekCodePoint(1);
|
|
120
|
+
if ((0, token_constants_2.isNumberStart)(e1, e2, e3)) {
|
|
121
|
+
this.reconsumeCodePoint(codePoint);
|
|
122
|
+
return this.consumeNumericToken();
|
|
123
|
+
}
|
|
124
|
+
if ((0, token_constants_2.isIdentifierStart)(e1, e2, e3)) {
|
|
125
|
+
this.reconsumeCodePoint(codePoint);
|
|
126
|
+
return this.consumeIdentLikeToken();
|
|
127
|
+
}
|
|
128
|
+
if (e2 === token_constants_1.HYPHEN_MINUS && e3 === token_constants_1.GREATER_THAN_SIGN) {
|
|
129
|
+
this.consumeCodePoint();
|
|
130
|
+
this.consumeCodePoint();
|
|
131
|
+
return token_singletons_1.CDC_TOKEN;
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case token_constants_1.FULL_STOP:
|
|
136
|
+
if ((0, token_constants_2.isNumberStart)(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) {
|
|
137
|
+
this.reconsumeCodePoint(codePoint);
|
|
138
|
+
return this.consumeNumericToken();
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
case token_constants_1.SOLIDUS:
|
|
142
|
+
if (this.peekCodePoint(0) === token_constants_1.ASTERISK) {
|
|
143
|
+
this.consumeCodePoint();
|
|
144
|
+
while (true) {
|
|
145
|
+
let c = this.consumeCodePoint();
|
|
146
|
+
if (c === token_constants_1.ASTERISK) {
|
|
147
|
+
c = this.consumeCodePoint();
|
|
148
|
+
if (c === token_constants_1.SOLIDUS) {
|
|
149
|
+
return this.consumeToken();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (c === token_constants_1.EOF) {
|
|
153
|
+
return this.consumeToken();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
case token_constants_1.COLON:
|
|
159
|
+
return token_singletons_1.COLON_TOKEN;
|
|
160
|
+
case token_constants_1.SEMICOLON:
|
|
161
|
+
return token_singletons_1.SEMICOLON_TOKEN;
|
|
162
|
+
case token_constants_1.LESS_THAN_SIGN:
|
|
163
|
+
if (this.peekCodePoint(0) === token_constants_1.EXCLAMATION_MARK &&
|
|
164
|
+
this.peekCodePoint(1) === token_constants_1.HYPHEN_MINUS &&
|
|
165
|
+
this.peekCodePoint(2) === token_constants_1.HYPHEN_MINUS) {
|
|
166
|
+
this.consumeCodePoint();
|
|
167
|
+
this.consumeCodePoint();
|
|
168
|
+
return token_singletons_1.CDO_TOKEN;
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
case token_constants_1.COMMERCIAL_AT: {
|
|
172
|
+
const a1 = this.peekCodePoint(0);
|
|
173
|
+
const a2 = this.peekCodePoint(1);
|
|
174
|
+
const a3 = this.peekCodePoint(2);
|
|
175
|
+
if ((0, token_constants_2.isIdentifierStart)(a1, a2, a3)) {
|
|
176
|
+
const value = this.consumeName();
|
|
177
|
+
return { type: 7 /* TokenType.AT_KEYWORD_TOKEN */, value };
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
case token_constants_1.LEFT_SQUARE_BRACKET:
|
|
182
|
+
return token_singletons_1.LEFT_SQUARE_BRACKET_TOKEN;
|
|
183
|
+
case token_constants_1.REVERSE_SOLIDUS:
|
|
184
|
+
if ((0, token_constants_2.isValidEscape)(codePoint, this.peekCodePoint(0))) {
|
|
185
|
+
this.reconsumeCodePoint(codePoint);
|
|
186
|
+
return this.consumeIdentLikeToken();
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
case token_constants_1.RIGHT_SQUARE_BRACKET:
|
|
190
|
+
return token_singletons_1.RIGHT_SQUARE_BRACKET_TOKEN;
|
|
191
|
+
case token_constants_1.CIRCUMFLEX_ACCENT:
|
|
192
|
+
if (this.peekCodePoint(0) === token_constants_1.EQUALS_SIGN) {
|
|
193
|
+
this.consumeCodePoint();
|
|
194
|
+
return token_singletons_1.PREFIX_MATCH_TOKEN;
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
case token_constants_1.LEFT_CURLY_BRACKET:
|
|
198
|
+
return token_singletons_1.LEFT_CURLY_BRACKET_TOKEN;
|
|
199
|
+
case token_constants_1.RIGHT_CURLY_BRACKET:
|
|
200
|
+
return token_singletons_1.RIGHT_CURLY_BRACKET_TOKEN;
|
|
201
|
+
case token_constants_1.u:
|
|
202
|
+
case token_constants_1.U: {
|
|
203
|
+
const u1 = this.peekCodePoint(0);
|
|
204
|
+
const u2 = this.peekCodePoint(1);
|
|
205
|
+
if (u1 === token_constants_1.PLUS_SIGN && ((0, token_constants_2.isHex)(u2) || u2 === token_constants_1.QUESTION_MARK)) {
|
|
206
|
+
this.consumeCodePoint();
|
|
207
|
+
this.consumeUnicodeRangeToken();
|
|
208
|
+
}
|
|
209
|
+
this.reconsumeCodePoint(codePoint);
|
|
210
|
+
return this.consumeIdentLikeToken();
|
|
211
|
+
}
|
|
212
|
+
case token_constants_1.VERTICAL_LINE:
|
|
213
|
+
if (this.peekCodePoint(0) === token_constants_1.EQUALS_SIGN) {
|
|
214
|
+
this.consumeCodePoint();
|
|
215
|
+
return token_singletons_1.DASH_MATCH_TOKEN;
|
|
216
|
+
}
|
|
217
|
+
if (this.peekCodePoint(0) === token_constants_1.VERTICAL_LINE) {
|
|
218
|
+
this.consumeCodePoint();
|
|
219
|
+
return token_singletons_1.COLUMN_TOKEN;
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
case token_constants_1.TILDE:
|
|
223
|
+
if (this.peekCodePoint(0) === token_constants_1.EQUALS_SIGN) {
|
|
224
|
+
this.consumeCodePoint();
|
|
225
|
+
return token_singletons_1.INCLUDE_MATCH_TOKEN;
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
case token_constants_1.EOF:
|
|
229
|
+
return token_singletons_1.EOF_TOKEN;
|
|
230
|
+
}
|
|
231
|
+
if ((0, token_constants_2.isWhiteSpace)(codePoint)) {
|
|
232
|
+
this.consumeWhiteSpace();
|
|
233
|
+
return token_singletons_1.WHITESPACE_TOKEN;
|
|
234
|
+
}
|
|
235
|
+
if ((0, token_constants_2.isDigit)(codePoint)) {
|
|
236
|
+
this.reconsumeCodePoint(codePoint);
|
|
237
|
+
return this.consumeNumericToken();
|
|
238
|
+
}
|
|
239
|
+
if ((0, token_constants_2.isNameStartCodePoint)(codePoint)) {
|
|
240
|
+
this.reconsumeCodePoint(codePoint);
|
|
241
|
+
return this.consumeIdentLikeToken();
|
|
242
|
+
}
|
|
243
|
+
return { type: 6 /* TokenType.DELIM_TOKEN */, value: (0, css_line_break_1.fromCodePoint)(codePoint) };
|
|
244
|
+
}
|
|
245
|
+
consumeCodePoint() {
|
|
246
|
+
const value = this._value.shift();
|
|
247
|
+
return typeof value === 'undefined' ? -1 : value;
|
|
248
|
+
}
|
|
249
|
+
reconsumeCodePoint(codePoint) {
|
|
250
|
+
this._value.unshift(codePoint);
|
|
251
|
+
}
|
|
252
|
+
peekCodePoint(delta) {
|
|
253
|
+
if (delta >= this._value.length) {
|
|
254
|
+
return -1;
|
|
255
|
+
}
|
|
256
|
+
return this._value[delta];
|
|
257
|
+
}
|
|
258
|
+
consumeUnicodeRangeToken() {
|
|
259
|
+
const digits = [];
|
|
260
|
+
let codePoint = this.consumeCodePoint();
|
|
261
|
+
while ((0, token_constants_2.isHex)(codePoint) && digits.length < 6) {
|
|
262
|
+
digits.push(codePoint);
|
|
263
|
+
codePoint = this.consumeCodePoint();
|
|
264
|
+
}
|
|
265
|
+
let questionMarks = false;
|
|
266
|
+
while (codePoint === token_constants_1.QUESTION_MARK && digits.length < 6) {
|
|
267
|
+
digits.push(codePoint);
|
|
268
|
+
codePoint = this.consumeCodePoint();
|
|
269
|
+
questionMarks = true;
|
|
270
|
+
}
|
|
271
|
+
if (questionMarks) {
|
|
272
|
+
const start = parseInt((0, css_line_break_1.fromCodePoint)(...digits.map((digit) => (digit === token_constants_1.QUESTION_MARK ? token_constants_1.ZERO : digit))), 16);
|
|
273
|
+
const end = parseInt((0, css_line_break_1.fromCodePoint)(...digits.map((digit) => (digit === token_constants_1.QUESTION_MARK ? token_constants_1.F : digit))), 16);
|
|
274
|
+
return { type: 30 /* TokenType.UNICODE_RANGE_TOKEN */, start, end };
|
|
275
|
+
}
|
|
276
|
+
const start = parseInt((0, css_line_break_1.fromCodePoint)(...digits), 16);
|
|
277
|
+
if (this.peekCodePoint(0) === token_constants_1.HYPHEN_MINUS && (0, token_constants_2.isHex)(this.peekCodePoint(1))) {
|
|
278
|
+
this.consumeCodePoint();
|
|
279
|
+
codePoint = this.consumeCodePoint();
|
|
280
|
+
const endDigits = [];
|
|
281
|
+
while ((0, token_constants_2.isHex)(codePoint) && endDigits.length < 6) {
|
|
282
|
+
endDigits.push(codePoint);
|
|
283
|
+
codePoint = this.consumeCodePoint();
|
|
284
|
+
}
|
|
285
|
+
const end = parseInt((0, css_line_break_1.fromCodePoint)(...endDigits), 16);
|
|
286
|
+
return { type: 30 /* TokenType.UNICODE_RANGE_TOKEN */, start, end };
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
return { type: 30 /* TokenType.UNICODE_RANGE_TOKEN */, start, end: start };
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
consumeIdentLikeToken() {
|
|
293
|
+
const value = this.consumeName();
|
|
294
|
+
if (value.toLowerCase() === 'url' && this.peekCodePoint(0) === token_constants_1.LEFT_PARENTHESIS) {
|
|
295
|
+
this.consumeCodePoint();
|
|
296
|
+
return this.consumeUrlToken();
|
|
297
|
+
}
|
|
298
|
+
else if (this.peekCodePoint(0) === token_constants_1.LEFT_PARENTHESIS) {
|
|
299
|
+
this.consumeCodePoint();
|
|
300
|
+
return { type: 19 /* TokenType.FUNCTION_TOKEN */, value };
|
|
301
|
+
}
|
|
302
|
+
return { type: 20 /* TokenType.IDENT_TOKEN */, value };
|
|
303
|
+
}
|
|
304
|
+
consumeUrlToken() {
|
|
305
|
+
const value = [];
|
|
306
|
+
this.consumeWhiteSpace();
|
|
307
|
+
if (this.peekCodePoint(0) === token_constants_1.EOF) {
|
|
308
|
+
return { type: 22 /* TokenType.URL_TOKEN */, value: '' };
|
|
309
|
+
}
|
|
310
|
+
const next = this.peekCodePoint(0);
|
|
311
|
+
if (next === token_constants_1.APOSTROPHE || next === token_constants_1.QUOTATION_MARK) {
|
|
312
|
+
const stringToken = this.consumeStringToken(this.consumeCodePoint());
|
|
313
|
+
if (stringToken.type === 0 /* TokenType.STRING_TOKEN */) {
|
|
314
|
+
this.consumeWhiteSpace();
|
|
315
|
+
if (this.peekCodePoint(0) === token_constants_1.EOF || this.peekCodePoint(0) === token_constants_1.RIGHT_PARENTHESIS) {
|
|
316
|
+
this.consumeCodePoint();
|
|
317
|
+
return { type: 22 /* TokenType.URL_TOKEN */, value: stringToken.value };
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
this.consumeBadUrlRemnants();
|
|
321
|
+
return token_singletons_1.BAD_URL_TOKEN;
|
|
322
|
+
}
|
|
323
|
+
while (true) {
|
|
324
|
+
const codePoint = this.consumeCodePoint();
|
|
325
|
+
if (codePoint === token_constants_1.EOF || codePoint === token_constants_1.RIGHT_PARENTHESIS) {
|
|
326
|
+
return { type: 22 /* TokenType.URL_TOKEN */, value: (0, css_line_break_1.fromCodePoint)(...value) };
|
|
327
|
+
}
|
|
328
|
+
else if ((0, token_constants_2.isWhiteSpace)(codePoint)) {
|
|
329
|
+
this.consumeWhiteSpace();
|
|
330
|
+
if (this.peekCodePoint(0) === token_constants_1.EOF || this.peekCodePoint(0) === token_constants_1.RIGHT_PARENTHESIS) {
|
|
331
|
+
this.consumeCodePoint();
|
|
332
|
+
return { type: 22 /* TokenType.URL_TOKEN */, value: (0, css_line_break_1.fromCodePoint)(...value) };
|
|
333
|
+
}
|
|
334
|
+
this.consumeBadUrlRemnants();
|
|
335
|
+
return token_singletons_1.BAD_URL_TOKEN;
|
|
336
|
+
}
|
|
337
|
+
else if (codePoint === token_constants_1.QUOTATION_MARK ||
|
|
338
|
+
codePoint === token_constants_1.APOSTROPHE ||
|
|
339
|
+
codePoint === token_constants_1.LEFT_PARENTHESIS ||
|
|
340
|
+
(0, token_constants_2.isNonPrintableCodePoint)(codePoint)) {
|
|
341
|
+
this.consumeBadUrlRemnants();
|
|
342
|
+
return token_singletons_1.BAD_URL_TOKEN;
|
|
343
|
+
}
|
|
344
|
+
else if (codePoint === token_constants_1.REVERSE_SOLIDUS) {
|
|
345
|
+
if ((0, token_constants_2.isValidEscape)(codePoint, this.peekCodePoint(0))) {
|
|
346
|
+
value.push(this.consumeEscapedCodePoint());
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
this.consumeBadUrlRemnants();
|
|
350
|
+
return token_singletons_1.BAD_URL_TOKEN;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
value.push(codePoint);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
consumeWhiteSpace() {
|
|
359
|
+
while ((0, token_constants_2.isWhiteSpace)(this.peekCodePoint(0))) {
|
|
360
|
+
this.consumeCodePoint();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
consumeBadUrlRemnants() {
|
|
364
|
+
while (true) {
|
|
365
|
+
const codePoint = this.consumeCodePoint();
|
|
366
|
+
if (codePoint === token_constants_1.RIGHT_PARENTHESIS || codePoint === token_constants_1.EOF) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if ((0, token_constants_2.isValidEscape)(codePoint, this.peekCodePoint(0))) {
|
|
370
|
+
this.consumeEscapedCodePoint();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
consumeStringSlice(count) {
|
|
375
|
+
const SLICE_STACK_SIZE = 50000;
|
|
376
|
+
let value = '';
|
|
377
|
+
while (count > 0) {
|
|
378
|
+
const amount = Math.min(SLICE_STACK_SIZE, count);
|
|
379
|
+
value += (0, css_line_break_1.fromCodePoint)(...this._value.splice(0, amount));
|
|
380
|
+
count -= amount;
|
|
381
|
+
}
|
|
382
|
+
this._value.shift();
|
|
383
|
+
return value;
|
|
384
|
+
}
|
|
385
|
+
consumeStringToken(endingCodePoint) {
|
|
386
|
+
let value = '';
|
|
387
|
+
let i = 0;
|
|
388
|
+
do {
|
|
389
|
+
const codePoint = this._value[i];
|
|
390
|
+
if (codePoint === token_constants_1.EOF || codePoint === undefined || codePoint === endingCodePoint) {
|
|
391
|
+
value += this.consumeStringSlice(i);
|
|
392
|
+
return { type: 0 /* TokenType.STRING_TOKEN */, value };
|
|
393
|
+
}
|
|
394
|
+
if (codePoint === token_constants_1.LINE_FEED) {
|
|
395
|
+
this._value.splice(0, i);
|
|
396
|
+
return token_singletons_1.BAD_STRING_TOKEN;
|
|
397
|
+
}
|
|
398
|
+
if (codePoint === token_constants_1.REVERSE_SOLIDUS) {
|
|
399
|
+
const next = this._value[i + 1];
|
|
400
|
+
if (next !== token_constants_1.EOF && next !== undefined) {
|
|
401
|
+
if (next === token_constants_1.LINE_FEED) {
|
|
402
|
+
value += this.consumeStringSlice(i);
|
|
403
|
+
i = -1;
|
|
404
|
+
this._value.shift();
|
|
405
|
+
}
|
|
406
|
+
else if ((0, token_constants_2.isValidEscape)(codePoint, next)) {
|
|
407
|
+
value += this.consumeStringSlice(i);
|
|
408
|
+
value += (0, css_line_break_1.fromCodePoint)(this.consumeEscapedCodePoint());
|
|
409
|
+
i = -1;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
i++;
|
|
414
|
+
} while (true);
|
|
415
|
+
}
|
|
416
|
+
consumeNumber() {
|
|
417
|
+
const repr = [];
|
|
418
|
+
let type = token_types_1.FLAG_INTEGER;
|
|
419
|
+
let c1 = this.peekCodePoint(0);
|
|
420
|
+
if (c1 === token_constants_1.PLUS_SIGN || c1 === token_constants_1.HYPHEN_MINUS) {
|
|
421
|
+
repr.push(this.consumeCodePoint());
|
|
422
|
+
}
|
|
423
|
+
while ((0, token_constants_2.isDigit)(this.peekCodePoint(0))) {
|
|
424
|
+
repr.push(this.consumeCodePoint());
|
|
425
|
+
}
|
|
426
|
+
c1 = this.peekCodePoint(0);
|
|
427
|
+
let c2 = this.peekCodePoint(1);
|
|
428
|
+
if (c1 === token_constants_1.FULL_STOP && (0, token_constants_2.isDigit)(c2)) {
|
|
429
|
+
repr.push(this.consumeCodePoint(), this.consumeCodePoint());
|
|
430
|
+
type = token_types_1.FLAG_NUMBER;
|
|
431
|
+
while ((0, token_constants_2.isDigit)(this.peekCodePoint(0))) {
|
|
432
|
+
repr.push(this.consumeCodePoint());
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
c1 = this.peekCodePoint(0);
|
|
436
|
+
c2 = this.peekCodePoint(1);
|
|
437
|
+
const c3 = this.peekCodePoint(2);
|
|
438
|
+
if ((c1 === token_constants_1.E || c1 === token_constants_1.e) && (((c2 === token_constants_1.PLUS_SIGN || c2 === token_constants_1.HYPHEN_MINUS) && (0, token_constants_2.isDigit)(c3)) || (0, token_constants_2.isDigit)(c2))) {
|
|
439
|
+
repr.push(this.consumeCodePoint(), this.consumeCodePoint());
|
|
440
|
+
type = token_types_1.FLAG_NUMBER;
|
|
441
|
+
while ((0, token_constants_2.isDigit)(this.peekCodePoint(0))) {
|
|
442
|
+
repr.push(this.consumeCodePoint());
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return [(0, token_constants_2.stringToNumber)(repr), type];
|
|
446
|
+
}
|
|
447
|
+
consumeNumericToken() {
|
|
448
|
+
const [number, flags] = this.consumeNumber();
|
|
449
|
+
const c1 = this.peekCodePoint(0);
|
|
450
|
+
const c2 = this.peekCodePoint(1);
|
|
451
|
+
const c3 = this.peekCodePoint(2);
|
|
452
|
+
if ((0, token_constants_2.isIdentifierStart)(c1, c2, c3)) {
|
|
453
|
+
const unit = this.consumeName();
|
|
454
|
+
return { type: 15 /* TokenType.DIMENSION_TOKEN */, number, flags, unit };
|
|
455
|
+
}
|
|
456
|
+
if (c1 === token_constants_1.PERCENTAGE_SIGN) {
|
|
457
|
+
this.consumeCodePoint();
|
|
458
|
+
return { type: 16 /* TokenType.PERCENTAGE_TOKEN */, number, flags };
|
|
459
|
+
}
|
|
460
|
+
return { type: 17 /* TokenType.NUMBER_TOKEN */, number, flags };
|
|
461
|
+
}
|
|
462
|
+
consumeEscapedCodePoint() {
|
|
463
|
+
const codePoint = this.consumeCodePoint();
|
|
464
|
+
if ((0, token_constants_2.isHex)(codePoint)) {
|
|
465
|
+
let hex = (0, css_line_break_1.fromCodePoint)(codePoint);
|
|
466
|
+
while ((0, token_constants_2.isHex)(this.peekCodePoint(0)) && hex.length < 6) {
|
|
467
|
+
hex += (0, css_line_break_1.fromCodePoint)(this.consumeCodePoint());
|
|
468
|
+
}
|
|
469
|
+
if ((0, token_constants_2.isWhiteSpace)(this.peekCodePoint(0))) {
|
|
470
|
+
this.consumeCodePoint();
|
|
471
|
+
}
|
|
472
|
+
const hexCodePoint = parseInt(hex, 16);
|
|
473
|
+
if (hexCodePoint === 0 || (0, token_constants_2.isSurrogateCodePoint)(hexCodePoint) || hexCodePoint > 0x10ffff) {
|
|
474
|
+
return token_constants_1.REPLACEMENT_CHARACTER;
|
|
475
|
+
}
|
|
476
|
+
return hexCodePoint;
|
|
477
|
+
}
|
|
478
|
+
if (codePoint === token_constants_1.EOF) {
|
|
479
|
+
return token_constants_1.REPLACEMENT_CHARACTER;
|
|
480
|
+
}
|
|
481
|
+
return codePoint;
|
|
482
|
+
}
|
|
483
|
+
consumeName() {
|
|
484
|
+
let result = '';
|
|
485
|
+
while (true) {
|
|
486
|
+
const codePoint = this.consumeCodePoint();
|
|
487
|
+
if ((0, token_constants_2.isNameCodePoint)(codePoint)) {
|
|
488
|
+
result += (0, css_line_break_1.fromCodePoint)(codePoint);
|
|
489
|
+
}
|
|
490
|
+
else if ((0, token_constants_2.isValidEscape)(codePoint, this.peekCodePoint(0))) {
|
|
491
|
+
result += (0, css_line_break_1.fromCodePoint)(this.consumeEscapedCodePoint());
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
this.reconsumeCodePoint(codePoint);
|
|
495
|
+
return result;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
exports.Tokenizer = Tokenizer;
|
|
501
|
+
Tokenizer._pool = [];
|
|
502
|
+
Tokenizer.MAX_POOL_SIZE = 40;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deg = exports.parseNamedSide = exports.isAngle = exports.angle = void 0;
|
|
4
|
+
const parser_1 = require("../syntax/parser");
|
|
5
|
+
const length_percentage_1 = require("./length-percentage");
|
|
6
|
+
const DEG = 'deg';
|
|
7
|
+
const GRAD = 'grad';
|
|
8
|
+
const RAD = 'rad';
|
|
9
|
+
const TURN = 'turn';
|
|
10
|
+
exports.angle = {
|
|
11
|
+
name: 'angle',
|
|
12
|
+
parse: (_context, value) => {
|
|
13
|
+
if (value.type === 15 /* TokenType.DIMENSION_TOKEN */) {
|
|
14
|
+
switch (value.unit) {
|
|
15
|
+
case DEG:
|
|
16
|
+
return (Math.PI * value.number) / 180;
|
|
17
|
+
case GRAD:
|
|
18
|
+
return (Math.PI / 200) * value.number;
|
|
19
|
+
case RAD:
|
|
20
|
+
return value.number;
|
|
21
|
+
case TURN:
|
|
22
|
+
return Math.PI * 2 * value.number;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`Unsupported angle type`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const isAngle = (value) => {
|
|
29
|
+
if (value.type === 15 /* TokenType.DIMENSION_TOKEN */) {
|
|
30
|
+
if (value.unit === DEG || value.unit === GRAD || value.unit === RAD || value.unit === TURN) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
36
|
+
exports.isAngle = isAngle;
|
|
37
|
+
const parseNamedSide = (tokens) => {
|
|
38
|
+
const sideOrCorner = tokens
|
|
39
|
+
.filter(parser_1.isIdentToken)
|
|
40
|
+
.map((ident) => ident.value)
|
|
41
|
+
.join(' ');
|
|
42
|
+
switch (sideOrCorner) {
|
|
43
|
+
case 'to bottom right':
|
|
44
|
+
case 'to right bottom':
|
|
45
|
+
case 'left top':
|
|
46
|
+
case 'top left':
|
|
47
|
+
return [length_percentage_1.ZERO_LENGTH, length_percentage_1.ZERO_LENGTH];
|
|
48
|
+
case 'to top':
|
|
49
|
+
case 'bottom':
|
|
50
|
+
return (0, exports.deg)(0);
|
|
51
|
+
case 'to bottom left':
|
|
52
|
+
case 'to left bottom':
|
|
53
|
+
case 'right top':
|
|
54
|
+
case 'top right':
|
|
55
|
+
return [length_percentage_1.ZERO_LENGTH, length_percentage_1.HUNDRED_PERCENT];
|
|
56
|
+
case 'to right':
|
|
57
|
+
case 'left':
|
|
58
|
+
return (0, exports.deg)(90);
|
|
59
|
+
case 'to top left':
|
|
60
|
+
case 'to left top':
|
|
61
|
+
case 'right bottom':
|
|
62
|
+
case 'bottom right':
|
|
63
|
+
return [length_percentage_1.HUNDRED_PERCENT, length_percentage_1.HUNDRED_PERCENT];
|
|
64
|
+
case 'to bottom':
|
|
65
|
+
case 'top':
|
|
66
|
+
return (0, exports.deg)(180);
|
|
67
|
+
case 'to top right':
|
|
68
|
+
case 'to right top':
|
|
69
|
+
case 'left bottom':
|
|
70
|
+
case 'bottom left':
|
|
71
|
+
return [length_percentage_1.HUNDRED_PERCENT, length_percentage_1.ZERO_LENGTH];
|
|
72
|
+
case 'to left':
|
|
73
|
+
case 'right':
|
|
74
|
+
return (0, exports.deg)(270);
|
|
75
|
+
}
|
|
76
|
+
return 0;
|
|
77
|
+
};
|
|
78
|
+
exports.parseNamedSide = parseNamedSide;
|
|
79
|
+
const deg = (deg) => (Math.PI * deg) / 180;
|
|
80
|
+
exports.deg = deg;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Color mathematics utilities
|
|
4
|
+
* Extracted to break circular dependency between srgb.ts and color-utilities.ts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.multiplyMatrices = exports.clamp = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Clamp a value between min and max
|
|
10
|
+
*/
|
|
11
|
+
const clamp = (value, min, max) => {
|
|
12
|
+
return Math.min(Math.max(value, min), max);
|
|
13
|
+
};
|
|
14
|
+
exports.clamp = clamp;
|
|
15
|
+
/**
|
|
16
|
+
* Multiply two 3x3 matrices
|
|
17
|
+
*/
|
|
18
|
+
const multiplyMatrices = (A, B) => {
|
|
19
|
+
return [
|
|
20
|
+
A[0] * B[0] + A[1] * B[1] + A[2] * B[2],
|
|
21
|
+
A[3] * B[0] + A[4] * B[1] + A[5] * B[2],
|
|
22
|
+
A[6] * B[0] + A[7] * B[1] + A[8] * B[2]
|
|
23
|
+
];
|
|
24
|
+
};
|
|
25
|
+
exports.multiplyMatrices = multiplyMatrices;
|