pagyra-js 0.0.20 → 0.0.21
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 +55 -0
- package/dist/assets/fonts/licenses/selawik/SIL Open Font License.txt +43 -0
- package/dist/assets/fonts/ttf/arimo/Arimo-Bold.ttf +0 -0
- package/dist/assets/fonts/ttf/arimo/Arimo-BoldItalic.ttf +0 -0
- package/dist/assets/fonts/ttf/arimo/Arimo-Italic.ttf +0 -0
- package/dist/assets/fonts/ttf/arimo/Arimo-Regular.ttf +0 -0
- package/dist/assets/fonts/ttf/cinzeldecorative/CinzelDecorative-Black.ttf +0 -0
- package/dist/assets/fonts/ttf/cinzeldecorative/CinzelDecorative-Bold.ttf +0 -0
- package/dist/assets/fonts/ttf/cinzeldecorative/CinzelDecorative-Regular.ttf +0 -0
- package/dist/assets/fonts/ttf/dejavu/DejaVuSans.ttf +0 -0
- package/dist/assets/fonts/ttf/firecode/FiraCode-Bold.ttf +0 -0
- package/dist/assets/fonts/ttf/firecode/FiraCode-Light.ttf +0 -0
- package/dist/assets/fonts/ttf/firecode/FiraCode-Medium.ttf +0 -0
- package/dist/assets/fonts/ttf/firecode/FiraCode-Regular.ttf +0 -0
- package/dist/assets/fonts/ttf/firecode/FiraCode-SemiBold.ttf +0 -0
- package/dist/assets/fonts/ttf/notoemoji/NotoEmoji-Bold.ttf +0 -0
- package/dist/assets/fonts/ttf/notoemoji/NotoEmoji-Light.ttf +0 -0
- package/dist/assets/fonts/ttf/notoemoji/NotoEmoji-Medium.ttf +0 -0
- package/dist/assets/fonts/ttf/notoemoji/NotoEmoji-Regular.ttf +0 -0
- package/dist/assets/fonts/ttf/notoemoji/NotoEmoji-SemiBold.ttf +0 -0
- package/dist/assets/fonts/ttf/notosans/NotoSans-Regular.ttf +0 -0
- package/dist/assets/fonts/ttf/roboto/Roboto-Bold.ttf +0 -0
- package/dist/assets/fonts/ttf/roboto/Roboto-BoldItalic.ttf +0 -0
- package/dist/assets/fonts/ttf/roboto/Roboto-Italic.ttf +0 -0
- package/dist/assets/fonts/ttf/roboto/Roboto-Regular.ttf +0 -0
- package/dist/assets/fonts/ttf/selawik/selawk.ttf +0 -0
- package/dist/assets/fonts/ttf/selawik/selawkb.ttf +0 -0
- package/dist/assets/fonts/ttf/selawik/selawkl.ttf +0 -0
- package/dist/assets/fonts/ttf/selawik/selawksb.ttf +0 -0
- package/dist/assets/fonts/ttf/selawik/selawksl.ttf +0 -0
- package/dist/assets/fonts/ttf/stixtwomath/STIXTwoMath-Regular.ttf +0 -0
- package/dist/assets/fonts/ttf/tinos/Tinos-Bold.ttf +0 -0
- package/dist/assets/fonts/ttf/tinos/Tinos-BoldItalic.ttf +0 -0
- package/dist/assets/fonts/ttf/tinos/Tinos-Italic.ttf +0 -0
- package/dist/assets/fonts/ttf/tinos/Tinos-Regular.ttf +0 -0
- package/dist/assets/fonts/woff/lato/lato-latin-400-italic.woff +0 -0
- package/dist/assets/fonts/woff/lato/lato-latin-400-normal.woff +0 -0
- package/dist/assets/fonts/woff/lato/lato-latin-700-italic.woff +0 -0
- package/dist/assets/fonts/woff/lato/lato-latin-700-normal.woff +0 -0
- package/dist/assets/fonts/woff2/caveat/Caveat-Bold.woff2 +0 -0
- package/dist/assets/fonts/woff2/caveat/Caveat-Regular.woff2 +0 -0
- package/dist/assets/fonts/woff2/lato/lato-latin-400-italic.woff2 +0 -0
- package/dist/assets/fonts/woff2/lato/lato-latin-400-normal.woff2 +0 -0
- package/dist/assets/fonts/woff2/lato/lato-latin-700-italic.woff2 +0 -0
- package/dist/assets/fonts/woff2/lato/lato-latin-700-normal.woff2 +0 -0
- package/dist/browser/pagyra.min.js +34 -34
- package/dist/browser/pagyra.min.js.map +4 -4
- package/dist/playground/server.js +2 -0
- package/dist/src/css/compute-style/base-options.d.ts +7 -0
- package/dist/src/css/compute-style/base-options.js +24 -0
- package/dist/src/css/compute-style/declarations.d.ts +10 -0
- package/dist/src/css/compute-style/declarations.js +77 -0
- package/dist/src/css/compute-style/decoration.d.ts +8 -0
- package/dist/src/css/compute-style/decoration.js +55 -0
- package/dist/src/css/compute-style/defaults.d.ts +3 -0
- package/dist/src/css/compute-style/defaults.js +34 -0
- package/dist/src/css/compute-style/display.d.ts +3 -0
- package/dist/src/css/compute-style/display.js +85 -0
- package/dist/src/css/compute-style/float.d.ts +2 -0
- package/dist/src/css/compute-style/float.js +13 -0
- package/dist/src/css/compute-style/font.d.ts +12 -0
- package/dist/src/css/compute-style/font.js +57 -0
- package/dist/src/css/compute-style/overrides.d.ts +3 -0
- package/dist/src/css/compute-style/overrides.js +241 -0
- package/dist/src/css/compute-style.d.ts +2 -0
- package/dist/src/css/compute-style.js +34 -487
- package/dist/src/css/enums.d.ts +4 -0
- package/dist/src/css/enums.js +5 -0
- package/dist/src/css/layout-property-resolver.js +30 -18
- package/dist/src/css/length.d.ts +26 -2
- package/dist/src/css/length.js +48 -0
- package/dist/src/css/parsers/background-parser.js +1 -1
- package/dist/src/css/parsers/calc-parser.d.ts +2 -0
- package/dist/src/css/parsers/calc-parser.js +310 -0
- package/dist/src/css/parsers/content-parser.d.ts +2 -1
- package/dist/src/css/parsers/content-parser.js +7 -2
- package/dist/src/css/parsers/dimension-parser.js +37 -18
- package/dist/src/css/parsers/display-flex-parser.d.ts +4 -0
- package/dist/src/css/parsers/display-flex-parser.js +97 -0
- package/dist/src/css/parsers/filter-parser.d.ts +14 -0
- package/dist/src/css/parsers/filter-parser.js +255 -0
- package/dist/src/css/parsers/grid-parser-extended.d.ts +1 -0
- package/dist/src/css/parsers/grid-parser-extended.js +40 -1
- package/dist/src/css/parsers/grid-parser.d.ts +5 -2
- package/dist/src/css/parsers/grid-parser.js +71 -7
- package/dist/src/css/parsers/length-parser.d.ts +8 -3
- package/dist/src/css/parsers/length-parser.js +45 -2
- package/dist/src/css/parsers/margin-block-parser.js +3 -3
- package/dist/src/css/parsers/margin-parser.js +3 -3
- package/dist/src/css/parsers/padding-block-parser.js +3 -3
- package/dist/src/css/parsers/padding-inline-parser.js +3 -3
- package/dist/src/css/parsers/padding-parser.js +6 -6
- package/dist/src/css/parsers/position-parser.js +2 -22
- package/dist/src/css/parsers/register-parsers.js +29 -2
- package/dist/src/css/parsers/word-break-parser.d.ts +2 -0
- package/dist/src/css/parsers/word-break-parser.js +23 -0
- package/dist/src/css/properties/grid.d.ts +16 -2
- package/dist/src/css/properties/layout.d.ts +3 -1
- package/dist/src/css/properties/layout.js +1 -1
- package/dist/src/css/properties/misc.d.ts +5 -0
- package/dist/src/css/properties/typography.d.ts +3 -0
- package/dist/src/css/properties/visual.d.ts +36 -0
- package/dist/src/css/shorthands/box-shorthand.d.ts +2 -2
- package/dist/src/css/style-inheritance.d.ts +2 -1
- package/dist/src/css/style-inheritance.js +1 -0
- package/dist/src/css/style.d.ts +30 -10
- package/dist/src/css/style.js +8 -1
- package/dist/src/css/ua-defaults/base-defaults.d.ts +1 -0
- package/dist/src/css/ua-defaults/base-defaults.js +10 -1
- package/dist/src/css/ua-defaults/element-defaults.js +0 -2
- package/dist/src/html/css/parse-css.d.ts +2 -0
- package/dist/src/html/css/parse-css.js +32 -3
- package/dist/src/html/dom-converter/background-images.d.ts +3 -0
- package/dist/src/html/dom-converter/background-images.js +88 -0
- package/dist/src/html/dom-converter/convert-dom-node.d.ts +5 -0
- package/dist/src/html/dom-converter/convert-dom-node.js +81 -0
- package/dist/src/html/dom-converter/handlers/br-handler.d.ts +2 -0
- package/dist/src/html/dom-converter/handlers/br-handler.js +20 -0
- package/dist/src/html/dom-converter/handlers/form-control-handler.d.ts +2 -0
- package/dist/src/html/dom-converter/handlers/form-control-handler.js +28 -0
- package/dist/src/html/dom-converter/handlers/img-handler.d.ts +2 -0
- package/dist/src/html/dom-converter/handlers/img-handler.js +4 -0
- package/dist/src/html/dom-converter/handlers/index.d.ts +4 -0
- package/dist/src/html/dom-converter/handlers/index.js +19 -0
- package/dist/src/html/dom-converter/handlers/svg-handler.d.ts +2 -0
- package/dist/src/html/dom-converter/handlers/svg-handler.js +32 -0
- package/dist/src/html/dom-converter/handlers/types.d.ts +12 -0
- package/dist/src/html/dom-converter/handlers/types.js +2 -0
- package/dist/src/html/dom-converter/helpers.d.ts +7 -0
- package/dist/src/html/dom-converter/helpers.js +35 -0
- package/dist/src/html/dom-converter/index.d.ts +1 -0
- package/dist/src/html/dom-converter/index.js +1 -0
- package/dist/src/html/dom-converter/pseudo-elements.d.ts +6 -0
- package/dist/src/html/dom-converter/pseudo-elements.js +48 -0
- package/dist/src/html/dom-converter/text.d.ts +15 -0
- package/dist/src/html/dom-converter/text.js +170 -0
- package/dist/src/html/dom-converter.d.ts +1 -5
- package/dist/src/html/dom-converter.js +1 -417
- package/dist/src/html/image-converter.d.ts +5 -0
- package/dist/src/html-to-pdf/document-css.d.ts +14 -0
- package/dist/src/html-to-pdf/document-css.js +45 -0
- package/dist/src/html-to-pdf/fonts.d.ts +16 -0
- package/dist/src/html-to-pdf/fonts.js +74 -0
- package/dist/src/html-to-pdf/header-footer.d.ts +14 -0
- package/dist/src/html-to-pdf/header-footer.js +101 -0
- package/dist/src/html-to-pdf/html-parser.d.ts +6 -0
- package/dist/src/html-to-pdf/html-parser.js +81 -0
- package/dist/src/html-to-pdf/index.d.ts +3 -0
- package/dist/src/html-to-pdf/index.js +2 -0
- package/dist/src/html-to-pdf/layout-build.d.ts +37 -0
- package/dist/src/html-to-pdf/layout-build.js +73 -0
- package/dist/src/html-to-pdf/prepare-html-render.d.ts +2 -0
- package/dist/src/html-to-pdf/prepare-html-render.js +121 -0
- package/dist/src/html-to-pdf/render-finalize.d.ts +15 -0
- package/dist/src/html-to-pdf/render-finalize.js +27 -0
- package/dist/src/html-to-pdf/render-html-to-pdf.d.ts +3 -0
- package/dist/src/html-to-pdf/render-html-to-pdf.js +25 -0
- package/dist/src/html-to-pdf/resource-loader.d.ts +6 -0
- package/dist/src/html-to-pdf/resource-loader.js +120 -0
- package/dist/src/html-to-pdf/types.d.ts +38 -0
- package/dist/src/html-to-pdf/types.js +2 -0
- package/dist/src/html-to-pdf.d.ts +1 -37
- package/dist/src/html-to-pdf.js +1 -537
- package/dist/src/image/js-png-backend.d.ts +7 -0
- package/dist/src/image/js-png-backend.js +9 -0
- package/dist/src/image/png-backend.d.ts +5 -0
- package/dist/src/image/png-backend.js +1 -0
- package/dist/src/image/png-wasm-loader.d.ts +5 -0
- package/dist/src/image/png-wasm-loader.js +59 -0
- package/dist/src/image/wasm/png_decoder_wasm.d.ts +8 -0
- package/dist/src/image/wasm/png_decoder_wasm.js +24 -0
- package/dist/src/image/wasm/png_decoder_wasm_bg.js +16 -0
- package/dist/src/image/wasm-png-backend.d.ts +6 -0
- package/dist/src/image/wasm-png-backend.js +17 -0
- package/dist/src/layout/counter.d.ts +1 -2
- package/dist/src/layout/counter.js +18 -18
- package/dist/src/layout/inline/inline-utils.d.ts +1 -1
- package/dist/src/layout/inline/inline-utils.js +8 -7
- package/dist/src/layout/inline/layout.js +16 -3
- package/dist/src/layout/inline/run-placer.d.ts +1 -0
- package/dist/src/layout/inline/run-placer.js +2 -10
- package/dist/src/layout/pipeline/out-of-flow-manager.js +25 -1
- package/dist/src/layout/strategies/block.js +35 -24
- package/dist/src/layout/strategies/flex.js +305 -61
- package/dist/src/layout/strategies/form.d.ts +2 -0
- package/dist/src/layout/strategies/form.js +38 -13
- package/dist/src/layout/strategies/grid.js +166 -29
- package/dist/src/layout/strategies/image.js +53 -27
- package/dist/src/layout/strategies/inline.js +26 -21
- package/dist/src/layout/strategies/table.js +26 -18
- package/dist/src/layout/utils/content-measurer.d.ts +1 -1
- package/dist/src/layout/utils/content-measurer.js +8 -7
- package/dist/src/layout/utils/floats.d.ts +1 -0
- package/dist/src/layout/utils/floats.js +14 -12
- package/dist/src/layout/utils/margin.d.ts +4 -4
- package/dist/src/layout/utils/margin.js +20 -16
- package/dist/src/layout/utils/node-math.d.ts +12 -6
- package/dist/src/layout/utils/node-math.js +71 -41
- package/dist/src/layout/utils/sizing.js +2 -1
- package/dist/src/pdf/font-subset/font-registry.d.ts +6 -0
- package/dist/src/pdf/font-subset/font-registry.js +30 -2
- package/dist/src/pdf/header-footer-renderer.js +12 -1
- package/dist/src/pdf/layout-tree-builder.js +5 -1
- package/dist/src/pdf/page-painter.js +13 -0
- package/dist/src/pdf/pagination.js +2 -2
- package/dist/src/pdf/renderer/box-painter.js +28 -3
- package/dist/src/pdf/renderer/page-paint.js +11 -3
- package/dist/src/pdf/renderers/radius-utils.js +31 -38
- package/dist/src/pdf/renderers/shape-renderer.js +1 -1
- package/dist/src/pdf/renderers/shape-utils.js +1 -1
- package/dist/src/pdf/renderers/text-renderer.d.ts +9 -1
- package/dist/src/pdf/renderers/text-renderer.js +36 -2
- package/dist/src/pdf/stacking/build-stacking-contexts.js +1 -2
- package/dist/src/pdf/stacking/resolve-paint-order.d.ts +5 -6
- package/dist/src/pdf/stacking/resolve-paint-order.js +29 -9
- package/dist/src/pdf/stacking/types.d.ts +14 -0
- package/dist/src/pdf/svg/shape-renderer.js +47 -20
- package/dist/src/pdf/types.d.ts +7 -1
- package/dist/src/pdf/utils/border-radius-utils.js +31 -38
- package/dist/src/pdf/utils/color-utils.js +17 -2
- package/dist/src/pdf/utils/filter-utils.d.ts +29 -0
- package/dist/src/pdf/utils/filter-utils.js +85 -0
- package/dist/src/pdf/utils/node-text-run-factory.js +1 -1
- package/dist/src/pdf/utils/text-layout-adjuster.d.ts +0 -8
- package/dist/src/pdf/utils/text-layout-adjuster.js +12 -9
- package/dist/src/units/units.d.ts +1 -1
- package/dist/tests/css/box-sizing.spec.d.ts +1 -0
- package/dist/tests/css/box-sizing.spec.js +46 -0
- package/dist/tests/css/calc-parser.spec.d.ts +1 -0
- package/dist/tests/css/calc-parser.spec.js +68 -0
- package/dist/tests/css/container-query-units.spec.d.ts +1 -0
- package/dist/tests/css/container-query-units.spec.js +64 -0
- package/dist/tests/css/content-parser.spec.js +13 -0
- package/dist/tests/css/filter-parser.spec.d.ts +1 -0
- package/dist/tests/css/filter-parser.spec.js +116 -0
- package/dist/tests/css/flex-shorthand.spec.d.ts +1 -0
- package/dist/tests/css/flex-shorthand.spec.js +45 -0
- package/dist/tests/css/grid-clamp.spec.d.ts +1 -0
- package/dist/tests/css/grid-clamp.spec.js +82 -0
- package/dist/tests/css/parse-css-pseudo.spec.d.ts +1 -0
- package/dist/tests/css/parse-css-pseudo.spec.js +26 -0
- package/dist/tests/helpers/render-utils.d.ts +18 -2
- package/dist/tests/helpers/render-utils.js +25 -12
- package/dist/tests/html/dom-converter-pseudo-elements.spec.d.ts +1 -0
- package/dist/tests/html/dom-converter-pseudo-elements.spec.js +33 -0
- package/dist/tests/html/dom-converter-text.spec.d.ts +1 -0
- package/dist/tests/html/dom-converter-text.spec.js +67 -0
- package/dist/tests/image/png-backend.spec.d.ts +1 -0
- package/dist/tests/image/png-backend.spec.js +34 -0
- package/dist/tests/layout/box-sizing.spec.d.ts +1 -0
- package/dist/tests/layout/box-sizing.spec.js +75 -0
- package/dist/tests/layout/calc-padding.spec.d.ts +1 -0
- package/dist/tests/layout/calc-padding.spec.js +19 -0
- package/dist/tests/layout/container-query-units.spec.d.ts +1 -0
- package/dist/tests/layout/container-query-units.spec.js +24 -0
- package/dist/tests/layout/flex-auto-height.spec.d.ts +1 -0
- package/dist/tests/layout/flex-auto-height.spec.js +35 -0
- package/dist/tests/layout/flex-wrap-cards.spec.d.ts +1 -0
- package/dist/tests/layout/flex-wrap-cards.spec.js +16 -0
- package/dist/tests/layout/flex-wrap-grow-align-content.spec.d.ts +1 -0
- package/dist/tests/layout/flex-wrap-grow-align-content.spec.js +20 -0
- package/dist/tests/layout/grid-clamp-gap.spec.d.ts +1 -0
- package/dist/tests/layout/grid-clamp-gap.spec.js +22 -0
- package/dist/tests/layout/inline-fragments.spec.js +38 -0
- package/dist/tests/layout/paged-body-margin.spec.d.ts +1 -0
- package/dist/tests/layout/paged-body-margin.spec.js +92 -0
- package/dist/tests/layout/pseudo-counters-generated-content.spec.d.ts +1 -0
- package/dist/tests/layout/pseudo-counters-generated-content.spec.js +51 -0
- package/dist/tests/layout/responsive-clamp-grid-parity.spec.d.ts +1 -0
- package/dist/tests/layout/responsive-clamp-grid-parity.spec.js +75 -0
- package/dist/tests/layout/run-placer-baseline.spec.js +13 -11
- package/dist/tests/pdf/backdrop-filter-noop.spec.d.ts +1 -0
- package/dist/tests/pdf/backdrop-filter-noop.spec.js +140 -0
- package/dist/tests/pdf/filter-drop-shadow.spec.d.ts +1 -0
- package/dist/tests/pdf/filter-drop-shadow.spec.js +74 -0
- package/dist/tests/pdf/filter-opacity.spec.d.ts +1 -0
- package/dist/tests/pdf/filter-opacity.spec.js +30 -0
- package/dist/tests/pdf/font-subset-registry-key.spec.d.ts +1 -0
- package/dist/tests/pdf/font-subset-registry-key.spec.js +66 -0
- package/dist/tests/pdf/selawik-opt-in.spec.d.ts +1 -0
- package/dist/tests/pdf/selawik-opt-in.spec.js +106 -0
- package/dist/tests/pdf/system-ui-fallback-subset-regression.spec.d.ts +1 -0
- package/dist/tests/pdf/system-ui-fallback-subset-regression.spec.js +39 -0
- package/dist/tests/pdf/text-renderer-fallback.spec.js +55 -0
- package/dist/tests/pdf/text-transform-matrix.spec.js +8 -7
- package/package.json +2 -2
package/dist/src/css/length.d.ts
CHANGED
|
@@ -13,8 +13,21 @@ export interface RelativeLength {
|
|
|
13
13
|
readonly unit: RelativeLengthUnit;
|
|
14
14
|
readonly value: number;
|
|
15
15
|
}
|
|
16
|
+
export interface CalcLength {
|
|
17
|
+
readonly kind: "calc";
|
|
18
|
+
readonly px: number;
|
|
19
|
+
readonly percent: number;
|
|
20
|
+
readonly em?: number;
|
|
21
|
+
readonly rem?: number;
|
|
22
|
+
readonly cqw?: number;
|
|
23
|
+
readonly cqh?: number;
|
|
24
|
+
readonly cqi?: number;
|
|
25
|
+
readonly cqb?: number;
|
|
26
|
+
readonly cqmin?: number;
|
|
27
|
+
readonly cqmax?: number;
|
|
28
|
+
}
|
|
16
29
|
export type CSSLength = AbsoluteLength | AutoLength;
|
|
17
|
-
export type LengthLike = CSSLength | number | "auto";
|
|
30
|
+
export type LengthLike = CSSLength | CalcLength | number | "auto";
|
|
18
31
|
export type LengthInput = LengthLike | RelativeLength;
|
|
19
32
|
export type NumericLength = number | RelativeLength;
|
|
20
33
|
export declare const AUTO_LENGTH: AutoLength;
|
|
@@ -22,13 +35,24 @@ export declare function px(value: number): AbsoluteLength;
|
|
|
22
35
|
export declare function percent(ratio: number): AbsoluteLength;
|
|
23
36
|
export declare function relativeLength(unit: RelativeLengthUnit, value: number): RelativeLength;
|
|
24
37
|
export declare function isRelativeLength(value: unknown): value is RelativeLength;
|
|
38
|
+
export declare function isCalcLength(value: unknown): value is CalcLength;
|
|
25
39
|
export declare function resolveRelativeLength(value: RelativeLength, fontSize: number, rootFontSize: number): number;
|
|
26
40
|
export declare function resolveNumberLike(value: number | RelativeLength | undefined, fontSize: number, rootFontSize: number): number | undefined;
|
|
27
41
|
export declare function resolveLengthInput(value: LengthInput | undefined, fontSize: number, rootFontSize: number): LengthLike | undefined;
|
|
28
42
|
export declare function isAutoLength(value: LengthLike): value is AutoLength | "auto";
|
|
29
|
-
export declare function normalizeLength(value: LengthLike): CSSLength;
|
|
43
|
+
export declare function normalizeLength(value: LengthLike): CSSLength | CalcLength;
|
|
30
44
|
export interface ResolveLengthOptions {
|
|
31
45
|
auto?: "reference" | "zero" | number;
|
|
46
|
+
containerWidth?: number;
|
|
47
|
+
containerHeight?: number;
|
|
32
48
|
}
|
|
33
49
|
export declare function resolveLength(value: LengthLike | undefined, reference: number, options?: ResolveLengthOptions): number;
|
|
50
|
+
export interface ClampNumericLength {
|
|
51
|
+
readonly kind: "clamp";
|
|
52
|
+
readonly min: number | RelativeLength;
|
|
53
|
+
readonly preferred: number | RelativeLength;
|
|
54
|
+
readonly max: number | RelativeLength;
|
|
55
|
+
}
|
|
56
|
+
export declare function isClampNumericLength(value: unknown): value is ClampNumericLength;
|
|
57
|
+
export declare function resolveClampNumericLength(value: ClampNumericLength, fontSize: number, rootFontSize: number): number | undefined;
|
|
34
58
|
export declare function clampMinMax(value: number, minValue: number | undefined, maxValue: number | undefined): number;
|
package/dist/src/css/length.js
CHANGED
|
@@ -14,6 +14,12 @@ export function isRelativeLength(value) {
|
|
|
14
14
|
}
|
|
15
15
|
return value.kind === "relative";
|
|
16
16
|
}
|
|
17
|
+
export function isCalcLength(value) {
|
|
18
|
+
if (!value || typeof value !== "object") {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return value.kind === "calc";
|
|
22
|
+
}
|
|
17
23
|
export function resolveRelativeLength(value, fontSize, rootFontSize) {
|
|
18
24
|
return value.unit === "em" ? value.value * fontSize : value.value * rootFontSize;
|
|
19
25
|
}
|
|
@@ -33,6 +39,21 @@ export function resolveLengthInput(value, fontSize, rootFontSize) {
|
|
|
33
39
|
if (isRelativeLength(value)) {
|
|
34
40
|
return resolveRelativeLength(value, fontSize, rootFontSize);
|
|
35
41
|
}
|
|
42
|
+
if (isCalcLength(value)) {
|
|
43
|
+
return {
|
|
44
|
+
kind: "calc",
|
|
45
|
+
px: value.px + (value.em ?? 0) * fontSize + (value.rem ?? 0) * rootFontSize,
|
|
46
|
+
percent: value.percent,
|
|
47
|
+
em: 0,
|
|
48
|
+
rem: 0,
|
|
49
|
+
cqw: value.cqw ?? 0,
|
|
50
|
+
cqh: value.cqh ?? 0,
|
|
51
|
+
cqi: value.cqi ?? 0,
|
|
52
|
+
cqb: value.cqb ?? 0,
|
|
53
|
+
cqmin: value.cqmin ?? 0,
|
|
54
|
+
cqmax: value.cqmax ?? 0,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
36
57
|
return value;
|
|
37
58
|
}
|
|
38
59
|
export function isAutoLength(value) {
|
|
@@ -55,6 +76,8 @@ export function normalizeLength(value) {
|
|
|
55
76
|
}
|
|
56
77
|
export function resolveLength(value, reference, options = { auto: "reference" }) {
|
|
57
78
|
const autoBehavior = options.auto ?? "reference";
|
|
79
|
+
const containerWidth = options.containerWidth ?? reference;
|
|
80
|
+
const containerHeight = options.containerHeight ?? reference;
|
|
58
81
|
if (value === undefined) {
|
|
59
82
|
return 0;
|
|
60
83
|
}
|
|
@@ -67,11 +90,36 @@ export function resolveLength(value, reference, options = { auto: "reference" })
|
|
|
67
90
|
if (value.kind === "auto") {
|
|
68
91
|
return resolveAuto(autoBehavior, reference);
|
|
69
92
|
}
|
|
93
|
+
if (value.kind === "calc") {
|
|
94
|
+
const inlineSize = containerWidth;
|
|
95
|
+
const blockSize = containerHeight;
|
|
96
|
+
const minSize = Math.min(inlineSize, blockSize);
|
|
97
|
+
const maxSize = Math.max(inlineSize, blockSize);
|
|
98
|
+
return (value.px +
|
|
99
|
+
value.percent * reference +
|
|
100
|
+
(value.cqw ?? 0) * inlineSize +
|
|
101
|
+
(value.cqi ?? 0) * inlineSize +
|
|
102
|
+
(value.cqh ?? 0) * blockSize +
|
|
103
|
+
(value.cqb ?? 0) * blockSize +
|
|
104
|
+
(value.cqmin ?? 0) * minSize +
|
|
105
|
+
(value.cqmax ?? 0) * maxSize);
|
|
106
|
+
}
|
|
70
107
|
if (value.unit === "percent") {
|
|
71
108
|
return value.value * reference;
|
|
72
109
|
}
|
|
73
110
|
return value.value;
|
|
74
111
|
}
|
|
112
|
+
export function isClampNumericLength(value) {
|
|
113
|
+
return value !== null && typeof value === "object" && value.kind === "clamp";
|
|
114
|
+
}
|
|
115
|
+
export function resolveClampNumericLength(value, fontSize, rootFontSize) {
|
|
116
|
+
const min = resolveNumberLike(value.min, fontSize, rootFontSize);
|
|
117
|
+
const preferred = resolveNumberLike(value.preferred, fontSize, rootFontSize);
|
|
118
|
+
const max = resolveNumberLike(value.max, fontSize, rootFontSize);
|
|
119
|
+
if (min === undefined || preferred === undefined || max === undefined)
|
|
120
|
+
return undefined;
|
|
121
|
+
return Math.min(Math.max(preferred, min), max);
|
|
122
|
+
}
|
|
75
123
|
export function clampMinMax(value, minValue, maxValue) {
|
|
76
124
|
const upper = maxValue ?? Number.POSITIVE_INFINITY;
|
|
77
125
|
const lower = minValue ?? Number.NEGATIVE_INFINITY;
|
|
@@ -284,7 +284,7 @@ function isColorValue(value) {
|
|
|
284
284
|
if (lowerValue === "transparent") {
|
|
285
285
|
return true;
|
|
286
286
|
}
|
|
287
|
-
if (lowerValue.startsWith("#") && (lowerValue.length === 4 || lowerValue.length === 7)) {
|
|
287
|
+
if (lowerValue.startsWith("#") && (lowerValue.length === 4 || lowerValue.length === 5 || lowerValue.length === 7 || lowerValue.length === 9)) {
|
|
288
288
|
return true;
|
|
289
289
|
}
|
|
290
290
|
if (lowerValue.startsWith("rgb(") || lowerValue.startsWith("rgba(")) {
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { cmToPx, inToPx, mmToPx, pcToPx, ptToPx, qToPx } from "../../units/units.js";
|
|
2
|
+
import { getViewportHeight, getViewportWidth } from "../viewport.js";
|
|
3
|
+
function createCalcLength(partial = {}) {
|
|
4
|
+
return {
|
|
5
|
+
kind: "calc",
|
|
6
|
+
px: partial.px ?? 0,
|
|
7
|
+
percent: partial.percent ?? 0,
|
|
8
|
+
em: partial.em ?? 0,
|
|
9
|
+
rem: partial.rem ?? 0,
|
|
10
|
+
cqw: partial.cqw ?? 0,
|
|
11
|
+
cqh: partial.cqh ?? 0,
|
|
12
|
+
cqi: partial.cqi ?? 0,
|
|
13
|
+
cqb: partial.cqb ?? 0,
|
|
14
|
+
cqmin: partial.cqmin ?? 0,
|
|
15
|
+
cqmax: partial.cqmax ?? 0,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function addCalcLengths(left, right) {
|
|
19
|
+
return createCalcLength({
|
|
20
|
+
px: left.px + right.px,
|
|
21
|
+
percent: left.percent + right.percent,
|
|
22
|
+
em: (left.em ?? 0) + (right.em ?? 0),
|
|
23
|
+
rem: (left.rem ?? 0) + (right.rem ?? 0),
|
|
24
|
+
cqw: (left.cqw ?? 0) + (right.cqw ?? 0),
|
|
25
|
+
cqh: (left.cqh ?? 0) + (right.cqh ?? 0),
|
|
26
|
+
cqi: (left.cqi ?? 0) + (right.cqi ?? 0),
|
|
27
|
+
cqb: (left.cqb ?? 0) + (right.cqb ?? 0),
|
|
28
|
+
cqmin: (left.cqmin ?? 0) + (right.cqmin ?? 0),
|
|
29
|
+
cqmax: (left.cqmax ?? 0) + (right.cqmax ?? 0),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function scaleCalcLength(value, scalar) {
|
|
33
|
+
return createCalcLength({
|
|
34
|
+
px: value.px * scalar,
|
|
35
|
+
percent: value.percent * scalar,
|
|
36
|
+
em: (value.em ?? 0) * scalar,
|
|
37
|
+
rem: (value.rem ?? 0) * scalar,
|
|
38
|
+
cqw: (value.cqw ?? 0) * scalar,
|
|
39
|
+
cqh: (value.cqh ?? 0) * scalar,
|
|
40
|
+
cqi: (value.cqi ?? 0) * scalar,
|
|
41
|
+
cqb: (value.cqb ?? 0) * scalar,
|
|
42
|
+
cqmin: (value.cqmin ?? 0) * scalar,
|
|
43
|
+
cqmax: (value.cqmax ?? 0) * scalar,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
class CalcParser {
|
|
47
|
+
constructor(tokens) {
|
|
48
|
+
this.tokens = tokens;
|
|
49
|
+
this.index = 0;
|
|
50
|
+
}
|
|
51
|
+
parse() {
|
|
52
|
+
const value = this.parseExpression();
|
|
53
|
+
if (!value) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
if (this.index !== this.tokens.length) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
parseExpression() {
|
|
62
|
+
let left = this.parseTerm();
|
|
63
|
+
if (!left) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
while (true) {
|
|
67
|
+
const token = this.peek();
|
|
68
|
+
if (!token || token.type !== "op" || (token.value !== "+" && token.value !== "-")) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
this.index += 1;
|
|
72
|
+
const right = this.parseTerm();
|
|
73
|
+
if (!right) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
left = token.value === "+" ? addValues(left, right) : subtractValues(left, right);
|
|
77
|
+
if (!left) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return left;
|
|
82
|
+
}
|
|
83
|
+
parseTerm() {
|
|
84
|
+
let left = this.parseFactor();
|
|
85
|
+
if (!left) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
while (true) {
|
|
89
|
+
const token = this.peek();
|
|
90
|
+
if (!token || token.type !== "op" || (token.value !== "*" && token.value !== "/")) {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
this.index += 1;
|
|
94
|
+
const right = this.parseFactor();
|
|
95
|
+
if (!right) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
left = token.value === "*" ? multiplyValues(left, right) : divideValues(left, right);
|
|
99
|
+
if (!left) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return left;
|
|
104
|
+
}
|
|
105
|
+
parseFactor() {
|
|
106
|
+
const token = this.peek();
|
|
107
|
+
if (!token) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
if (token.type === "op" && (token.value === "+" || token.value === "-")) {
|
|
111
|
+
this.index += 1;
|
|
112
|
+
const factor = this.parseFactor();
|
|
113
|
+
if (!factor) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
if (token.value === "+") {
|
|
117
|
+
return factor;
|
|
118
|
+
}
|
|
119
|
+
return multiplyValues({ kind: "number", value: -1 }, factor);
|
|
120
|
+
}
|
|
121
|
+
if (token.type === "lparen") {
|
|
122
|
+
this.index += 1;
|
|
123
|
+
const expression = this.parseExpression();
|
|
124
|
+
if (!expression) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
const closing = this.peek();
|
|
128
|
+
if (!closing || closing.type !== "rparen") {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
this.index += 1;
|
|
132
|
+
return expression;
|
|
133
|
+
}
|
|
134
|
+
this.index += 1;
|
|
135
|
+
if (token.type === "number") {
|
|
136
|
+
return { kind: "number", value: token.value };
|
|
137
|
+
}
|
|
138
|
+
if (token.type === "dimension") {
|
|
139
|
+
return dimensionToValue(token.value, token.unit);
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
peek() {
|
|
144
|
+
return this.tokens[this.index];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function addValues(left, right) {
|
|
148
|
+
if (left.kind === "number" && right.kind === "number") {
|
|
149
|
+
return { kind: "number", value: left.value + right.value };
|
|
150
|
+
}
|
|
151
|
+
if (left.kind === "length" && right.kind === "length") {
|
|
152
|
+
return {
|
|
153
|
+
kind: "length",
|
|
154
|
+
value: addCalcLengths(left.value, right.value),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
function subtractValues(left, right) {
|
|
160
|
+
const negated = multiplyValues({ kind: "number", value: -1 }, right);
|
|
161
|
+
if (!negated) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
return addValues(left, negated);
|
|
165
|
+
}
|
|
166
|
+
function multiplyValues(left, right) {
|
|
167
|
+
if (left.kind === "number" && right.kind === "number") {
|
|
168
|
+
return { kind: "number", value: left.value * right.value };
|
|
169
|
+
}
|
|
170
|
+
if (left.kind === "number" && right.kind === "length") {
|
|
171
|
+
return {
|
|
172
|
+
kind: "length",
|
|
173
|
+
value: scaleCalcLength(right.value, left.value),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (left.kind === "length" && right.kind === "number") {
|
|
177
|
+
return multiplyValues(right, left);
|
|
178
|
+
}
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
function divideValues(left, right) {
|
|
182
|
+
if (right.kind !== "number") {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
if (right.value === 0) {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
return multiplyValues(left, { kind: "number", value: 1 / right.value });
|
|
189
|
+
}
|
|
190
|
+
function dimensionToValue(value, unit) {
|
|
191
|
+
const normalizedUnit = unit.toLowerCase();
|
|
192
|
+
switch (normalizedUnit) {
|
|
193
|
+
case "px":
|
|
194
|
+
return { kind: "length", value: createCalcLength({ px: value }) };
|
|
195
|
+
case "pt":
|
|
196
|
+
return { kind: "length", value: createCalcLength({ px: ptToPx(value) }) };
|
|
197
|
+
case "cm":
|
|
198
|
+
return { kind: "length", value: createCalcLength({ px: cmToPx(value) }) };
|
|
199
|
+
case "mm":
|
|
200
|
+
return { kind: "length", value: createCalcLength({ px: mmToPx(value) }) };
|
|
201
|
+
case "q":
|
|
202
|
+
return { kind: "length", value: createCalcLength({ px: qToPx(value) }) };
|
|
203
|
+
case "in":
|
|
204
|
+
return { kind: "length", value: createCalcLength({ px: inToPx(value) }) };
|
|
205
|
+
case "pc":
|
|
206
|
+
return { kind: "length", value: createCalcLength({ px: pcToPx(value) }) };
|
|
207
|
+
case "vw":
|
|
208
|
+
return {
|
|
209
|
+
kind: "length",
|
|
210
|
+
value: createCalcLength({ px: (value / 100) * getViewportWidth() }),
|
|
211
|
+
};
|
|
212
|
+
case "vh":
|
|
213
|
+
return {
|
|
214
|
+
kind: "length",
|
|
215
|
+
value: createCalcLength({ px: (value / 100) * getViewportHeight() }),
|
|
216
|
+
};
|
|
217
|
+
case "%":
|
|
218
|
+
return { kind: "length", value: createCalcLength({ percent: value / 100 }) };
|
|
219
|
+
case "em":
|
|
220
|
+
return { kind: "length", value: createCalcLength({ em: value }) };
|
|
221
|
+
case "rem":
|
|
222
|
+
return { kind: "length", value: createCalcLength({ rem: value }) };
|
|
223
|
+
case "cqw":
|
|
224
|
+
return { kind: "length", value: createCalcLength({ cqw: value / 100 }) };
|
|
225
|
+
case "cqh":
|
|
226
|
+
return { kind: "length", value: createCalcLength({ cqh: value / 100 }) };
|
|
227
|
+
case "cqi":
|
|
228
|
+
return { kind: "length", value: createCalcLength({ cqi: value / 100 }) };
|
|
229
|
+
case "cqb":
|
|
230
|
+
return { kind: "length", value: createCalcLength({ cqb: value / 100 }) };
|
|
231
|
+
case "cqmin":
|
|
232
|
+
return { kind: "length", value: createCalcLength({ cqmin: value / 100 }) };
|
|
233
|
+
case "cqmax":
|
|
234
|
+
return { kind: "length", value: createCalcLength({ cqmax: value / 100 }) };
|
|
235
|
+
default:
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function tokenizeCalcExpression(input) {
|
|
240
|
+
const tokens = [];
|
|
241
|
+
let i = 0;
|
|
242
|
+
while (i < input.length) {
|
|
243
|
+
const char = input[i];
|
|
244
|
+
if (/\s/.test(char)) {
|
|
245
|
+
i += 1;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (char === "+" || char === "-" || char === "*" || char === "/") {
|
|
249
|
+
tokens.push({ type: "op", value: char });
|
|
250
|
+
i += 1;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (char === "(") {
|
|
254
|
+
tokens.push({ type: "lparen" });
|
|
255
|
+
i += 1;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (char === ")") {
|
|
259
|
+
tokens.push({ type: "rparen" });
|
|
260
|
+
i += 1;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const numberMatch = input.slice(i).match(/^\d*\.?\d+/);
|
|
264
|
+
if (!numberMatch) {
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
const numberValue = Number.parseFloat(numberMatch[0]);
|
|
268
|
+
if (Number.isNaN(numberValue)) {
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
i += numberMatch[0].length;
|
|
272
|
+
const unitMatch = input.slice(i).match(/^(%|[a-zA-Z]+)/);
|
|
273
|
+
if (unitMatch) {
|
|
274
|
+
tokens.push({
|
|
275
|
+
type: "dimension",
|
|
276
|
+
value: numberValue,
|
|
277
|
+
unit: unitMatch[0],
|
|
278
|
+
});
|
|
279
|
+
i += unitMatch[0].length;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
tokens.push({ type: "number", value: numberValue });
|
|
283
|
+
}
|
|
284
|
+
return tokens;
|
|
285
|
+
}
|
|
286
|
+
export function parseCalcLength(value) {
|
|
287
|
+
if (!value) {
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
const trimmed = value.trim();
|
|
291
|
+
if (!trimmed.toLowerCase().startsWith("calc(") || !trimmed.endsWith(")")) {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
const expression = trimmed.slice(5, -1).trim();
|
|
295
|
+
if (!expression) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
const tokens = tokenizeCalcExpression(expression);
|
|
299
|
+
if (!tokens || tokens.length === 0) {
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
const parsed = new CalcParser(tokens).parse();
|
|
303
|
+
if (!parsed) {
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
if (parsed.kind === "number") {
|
|
307
|
+
return createCalcLength({ px: parsed.value });
|
|
308
|
+
}
|
|
309
|
+
return parsed.value;
|
|
310
|
+
}
|
|
@@ -12,7 +12,7 @@ export type ContentValue = {
|
|
|
12
12
|
} | {
|
|
13
13
|
type: "counter";
|
|
14
14
|
counter: string;
|
|
15
|
-
style?:
|
|
15
|
+
style?: CounterStyle;
|
|
16
16
|
} | {
|
|
17
17
|
type: "attr";
|
|
18
18
|
attribute: string;
|
|
@@ -25,6 +25,7 @@ export type ContentValue = {
|
|
|
25
25
|
} | {
|
|
26
26
|
type: "no-close-quote";
|
|
27
27
|
};
|
|
28
|
+
export type CounterStyle = "decimal" | "decimal-leading-zero" | "lower-roman" | "upper-roman" | "lower-alpha" | "upper-alpha";
|
|
28
29
|
/**
|
|
29
30
|
* Parse a CSS content property value into ContentValue[]
|
|
30
31
|
* Supports: strings, counter(), attr(), and quote functions
|
|
@@ -76,7 +76,7 @@ function parseContentValue(value) {
|
|
|
76
76
|
}
|
|
77
77
|
// Handle counter() function
|
|
78
78
|
if (value.slice(i).startsWith("counter(")) {
|
|
79
|
-
const match = /^counter\(\s*([a-zA-Z_][a-zA-Z0-9_-]*)\s*(?:,\s*(decimal|lower-roman|upper-roman|lower-alpha|upper-alpha))?\s*\)/i.exec(value.slice(i));
|
|
79
|
+
const match = /^counter\(\s*([a-zA-Z_][a-zA-Z0-9_-]*)\s*(?:,\s*(decimal-leading-zero|decimal|lower-roman|upper-roman|lower-alpha|upper-alpha))?\s*\)/i.exec(value.slice(i));
|
|
80
80
|
if (match) {
|
|
81
81
|
result.push({
|
|
82
82
|
type: "counter",
|
|
@@ -89,7 +89,7 @@ function parseContentValue(value) {
|
|
|
89
89
|
}
|
|
90
90
|
// Handle counters() function (plural - for nested counters)
|
|
91
91
|
if (value.slice(i).startsWith("counters(")) {
|
|
92
|
-
const match = /^counters\(\s*([a-zA-Z_][a-zA-Z0-9_-]*)\s*,\s*(["'])(.*)\2\s*(?:,\s*(decimal|lower-roman|upper-roman|lower-alpha|upper-alpha))?\s*\)/i.exec(value.slice(i));
|
|
92
|
+
const match = /^counters\(\s*([a-zA-Z_][a-zA-Z0-9_-]*)\s*,\s*(["'])(.*)\2\s*(?:,\s*(decimal-leading-zero|decimal|lower-roman|upper-roman|lower-alpha|upper-alpha))?\s*\)/i.exec(value.slice(i));
|
|
93
93
|
if (match) {
|
|
94
94
|
result.push({
|
|
95
95
|
type: "counter",
|
|
@@ -143,6 +143,11 @@ export function formatCounterValue(value, style) {
|
|
|
143
143
|
return String(value);
|
|
144
144
|
}
|
|
145
145
|
const lower = style.toLowerCase();
|
|
146
|
+
if (lower === "decimal-leading-zero") {
|
|
147
|
+
const sign = value < 0 ? "-" : "";
|
|
148
|
+
const abs = Math.abs(Math.trunc(value));
|
|
149
|
+
return `${sign}${String(abs).padStart(2, "0")}`;
|
|
150
|
+
}
|
|
146
151
|
if (lower === "lower-roman") {
|
|
147
152
|
return toRomanNumeral(value)?.toLowerCase() ?? String(value);
|
|
148
153
|
}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { parseLength, parseNumeric } from "./length-parser.js";
|
|
2
|
-
import { percent } from "../length.js";
|
|
3
|
-
const PERCENT_LENGTH_REGEX = /^(-?\d+(?:\.\d+)?)%$/;
|
|
4
|
-
function parseLengthOrPercent(value) {
|
|
5
|
-
const parsed = parseLength(value);
|
|
6
|
-
if (parsed !== undefined) {
|
|
7
|
-
return parsed;
|
|
8
|
-
}
|
|
9
|
-
const match = PERCENT_LENGTH_REGEX.exec(value.trim());
|
|
10
|
-
if (!match) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
const numeric = Number.parseFloat(match[1]);
|
|
14
|
-
if (Number.isNaN(numeric)) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
return percent(numeric / 100);
|
|
18
|
-
}
|
|
1
|
+
import { parseLength, parseLengthOrPercent, parseNumeric, parseClampArgs } from "./length-parser.js";
|
|
19
2
|
export function parseWidth(value, target) {
|
|
3
|
+
const clampArgs = parseClampArgs(value);
|
|
4
|
+
if (clampArgs) {
|
|
5
|
+
const min = parseLengthOrPercent(clampArgs[0]);
|
|
6
|
+
const preferred = parseLengthOrPercent(clampArgs[1]);
|
|
7
|
+
const max = parseLengthOrPercent(clampArgs[2]);
|
|
8
|
+
if (preferred !== undefined)
|
|
9
|
+
target.width = preferred;
|
|
10
|
+
if (min !== undefined)
|
|
11
|
+
target.minWidth ?? (target.minWidth = min);
|
|
12
|
+
if (max !== undefined)
|
|
13
|
+
target.maxWidth ?? (target.maxWidth = max);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
20
16
|
const parsed = parseLengthOrPercent(value);
|
|
21
17
|
if (parsed !== undefined) {
|
|
22
18
|
target.width = parsed;
|
|
@@ -35,6 +31,19 @@ export function parseMaxWidth(value, target) {
|
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
33
|
export function parseHeight(value, target) {
|
|
34
|
+
const clampArgs = parseClampArgs(value);
|
|
35
|
+
if (clampArgs) {
|
|
36
|
+
const min = parseLengthOrPercent(clampArgs[0]);
|
|
37
|
+
const preferred = parseLengthOrPercent(clampArgs[1]);
|
|
38
|
+
const max = parseLengthOrPercent(clampArgs[2]);
|
|
39
|
+
if (preferred !== undefined)
|
|
40
|
+
target.height = preferred;
|
|
41
|
+
if (min !== undefined)
|
|
42
|
+
target.minHeight ?? (target.minHeight = min);
|
|
43
|
+
if (max !== undefined)
|
|
44
|
+
target.maxHeight ?? (target.maxHeight = max);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
38
47
|
const parsed = parseLengthOrPercent(value);
|
|
39
48
|
if (parsed !== undefined) {
|
|
40
49
|
target.height = parsed;
|
|
@@ -53,6 +62,16 @@ export function parseMaxHeight(value, target) {
|
|
|
53
62
|
}
|
|
54
63
|
}
|
|
55
64
|
export function parseFontSize(value, target) {
|
|
65
|
+
const clampArgs = parseClampArgs(value);
|
|
66
|
+
if (clampArgs) {
|
|
67
|
+
const min = parseLength(clampArgs[0]) ?? parseNumeric(clampArgs[0]);
|
|
68
|
+
const preferred = parseLength(clampArgs[1]) ?? parseNumeric(clampArgs[1]);
|
|
69
|
+
const max = parseLength(clampArgs[2]) ?? parseNumeric(clampArgs[2]);
|
|
70
|
+
if (min !== undefined && preferred !== undefined && max !== undefined) {
|
|
71
|
+
target.fontSize = { kind: "clamp", min, preferred, max };
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
56
75
|
target.fontSize = parseNumeric(value) ?? target.fontSize;
|
|
57
76
|
}
|
|
58
77
|
function parseLineHeightValue(value) {
|
|
@@ -6,3 +6,7 @@ export declare function parseAlignContent(value: string, target: StyleAccumulato
|
|
|
6
6
|
export declare function parseAlignSelf(value: string, target: StyleAccumulator): void;
|
|
7
7
|
export declare function parseFlexDirection(value: string, target: StyleAccumulator): void;
|
|
8
8
|
export declare function parseFlexWrap(value: string, target: StyleAccumulator): void;
|
|
9
|
+
export declare function parseFlexGrow(value: string, target: StyleAccumulator): void;
|
|
10
|
+
export declare function parseFlexShrink(value: string, target: StyleAccumulator): void;
|
|
11
|
+
export declare function parseFlexBasis(value: string, target: StyleAccumulator): void;
|
|
12
|
+
export declare function parseFlex(value: string, target: StyleAccumulator): void;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
// src/css/parsers/display-flex-parser.ts
|
|
2
2
|
import { mapAlignContentValue, mapAlignItemsValue, mapAlignSelfValue, mapDisplay, mapJustifyContent, parseFlexDirectionValue, } from "./flex-parser.js";
|
|
3
|
+
import { parseLengthOrAuto } from "./length-parser.js";
|
|
4
|
+
function parseNonNegativeNumber(value) {
|
|
5
|
+
const trimmed = value.trim();
|
|
6
|
+
if (!/^\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const parsed = Number.parseFloat(trimmed);
|
|
10
|
+
if (Number.isNaN(parsed) || parsed < 0) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return parsed;
|
|
14
|
+
}
|
|
3
15
|
export function parseDisplay(value, target) {
|
|
4
16
|
target.display = mapDisplay(value);
|
|
5
17
|
}
|
|
@@ -42,3 +54,88 @@ export function parseFlexWrap(value, target) {
|
|
|
42
54
|
target.flexWrap = true;
|
|
43
55
|
}
|
|
44
56
|
}
|
|
57
|
+
export function parseFlexGrow(value, target) {
|
|
58
|
+
const parsed = parseNonNegativeNumber(value);
|
|
59
|
+
if (parsed !== undefined) {
|
|
60
|
+
target.flexGrow = parsed;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function parseFlexShrink(value, target) {
|
|
64
|
+
const parsed = parseNonNegativeNumber(value);
|
|
65
|
+
if (parsed !== undefined) {
|
|
66
|
+
target.flexShrink = parsed;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export function parseFlexBasis(value, target) {
|
|
70
|
+
const parsed = parseLengthOrAuto(value);
|
|
71
|
+
if (parsed !== undefined) {
|
|
72
|
+
target.flexBasis = parsed;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function parseFlex(value, target) {
|
|
76
|
+
const normalized = value.trim().toLowerCase();
|
|
77
|
+
if (!normalized) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (normalized === "none") {
|
|
81
|
+
target.flexGrow = 0;
|
|
82
|
+
target.flexShrink = 0;
|
|
83
|
+
target.flexBasis = "auto";
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (normalized === "auto") {
|
|
87
|
+
target.flexGrow = 1;
|
|
88
|
+
target.flexShrink = 1;
|
|
89
|
+
target.flexBasis = "auto";
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (normalized === "initial") {
|
|
93
|
+
target.flexGrow = 0;
|
|
94
|
+
target.flexShrink = 1;
|
|
95
|
+
target.flexBasis = "auto";
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const tokens = normalized.split(/\s+/).filter(Boolean);
|
|
99
|
+
if (tokens.length === 0) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const firstNumber = parseNonNegativeNumber(tokens[0]);
|
|
103
|
+
const firstBasis = parseLengthOrAuto(tokens[0]);
|
|
104
|
+
if (tokens.length === 1) {
|
|
105
|
+
if (firstNumber !== undefined) {
|
|
106
|
+
target.flexGrow = firstNumber;
|
|
107
|
+
target.flexShrink = 1;
|
|
108
|
+
target.flexBasis = 0;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (firstBasis !== undefined) {
|
|
112
|
+
target.flexGrow = 1;
|
|
113
|
+
target.flexShrink = 1;
|
|
114
|
+
target.flexBasis = firstBasis;
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const secondNumber = parseNonNegativeNumber(tokens[1]);
|
|
119
|
+
const secondBasis = parseLengthOrAuto(tokens[1]);
|
|
120
|
+
if (tokens.length === 2 && firstNumber !== undefined) {
|
|
121
|
+
target.flexGrow = firstNumber;
|
|
122
|
+
if (secondNumber !== undefined) {
|
|
123
|
+
target.flexShrink = secondNumber;
|
|
124
|
+
target.flexBasis = 0;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (secondBasis !== undefined) {
|
|
128
|
+
target.flexShrink = 1;
|
|
129
|
+
target.flexBasis = secondBasis;
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (tokens.length >= 3 && firstNumber !== undefined && secondNumber !== undefined) {
|
|
134
|
+
const thirdBasis = parseLengthOrAuto(tokens[2]);
|
|
135
|
+
if (thirdBasis !== undefined) {
|
|
136
|
+
target.flexGrow = firstNumber;
|
|
137
|
+
target.flexShrink = secondNumber;
|
|
138
|
+
target.flexBasis = thirdBasis;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|