css-calipers 1.0.0 → 1.1.0-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.txt +1 -1
- package/README.md +70 -424
- package/dist/cjs/color/formats/display-p3/display-p3.js +25 -0
- package/dist/cjs/color/formats/escalate.js +41 -0
- package/dist/cjs/color/formats/hex/hex.js +28 -0
- package/dist/cjs/color/formats/hexAlpha/hexAlpha.js +25 -0
- package/dist/cjs/color/formats/hsl/hsl.js +23 -0
- package/dist/cjs/color/formats/hwb/hwb.js +24 -0
- package/dist/cjs/color/formats/index.js +36 -0
- package/dist/cjs/color/formats/internals.js +93 -0
- package/dist/cjs/color/formats/lab/lab.js +24 -0
- package/dist/cjs/color/formats/lch/lch.js +23 -0
- package/dist/cjs/color/formats/oklab/oklab.js +24 -0
- package/dist/cjs/color/formats/oklch/oklch.js +28 -0
- package/dist/cjs/color/formats/resolve.js +16 -0
- package/dist/cjs/color/formats/rgb/rgb.js +29 -0
- package/dist/cjs/color/formats/rgba/rgba.js +27 -0
- package/dist/cjs/color/formats/types.js +11 -0
- package/dist/cjs/color/index.js +619 -0
- package/dist/cjs/color/types.js +2 -0
- package/dist/cjs/core.js +11 -8
- package/dist/cjs/corpus.js +53 -0
- package/dist/cjs/css-values/cssValues.js +78 -0
- package/dist/cjs/css-values/index.js +36 -0
- package/dist/cjs/css-values/multi.js +290 -0
- package/dist/cjs/css-values/propertyMap.js +2 -0
- package/dist/cjs/css-values/spec.js +197 -0
- package/dist/cjs/default.js +17 -0
- package/dist/cjs/factory.js +1 -1
- package/dist/cjs/float.js +110 -0
- package/dist/cjs/index.js +29 -9
- package/dist/cjs/integer.js +114 -0
- package/dist/cjs/internal/createCoreApi.js +103 -38
- package/dist/cjs/internal/errors.js +13 -14
- package/dist/cjs/internal/toPlainDecimal.js +31 -0
- package/dist/cjs/measurements.js +41 -0
- package/dist/cjs/ratio.js +57 -22
- package/dist/cjs/scalar.js +9 -0
- package/dist/cjs/units/absolute.js +8 -8
- package/dist/cjs/units/angle.js +5 -5
- package/dist/cjs/units/container.js +7 -7
- package/dist/cjs/units/font-relative.js +13 -13
- package/dist/cjs/units/frequency.js +3 -3
- package/dist/cjs/units/grid.js +2 -2
- package/dist/cjs/units/index.js +9 -9
- package/dist/cjs/units/percent.js +4 -4
- package/dist/cjs/units/resolution.js +4 -4
- package/dist/cjs/units/time.js +3 -3
- package/dist/cjs/units/viewport-dynamic.js +7 -7
- package/dist/cjs/units/viewport-large.js +7 -7
- package/dist/cjs/units/viewport-small.js +7 -7
- package/dist/cjs/units/viewport.js +7 -7
- package/dist/esm/color/formats/display-p3/display-p3.d.ts +10 -0
- package/dist/esm/color/formats/display-p3/display-p3.d.ts.map +1 -0
- package/dist/esm/color/formats/display-p3/display-p3.js +22 -0
- package/dist/esm/color/formats/escalate.d.ts +10 -0
- package/dist/esm/color/formats/escalate.d.ts.map +1 -0
- package/dist/esm/color/formats/escalate.js +37 -0
- package/dist/esm/color/formats/hex/hex.d.ts +9 -0
- package/dist/esm/color/formats/hex/hex.d.ts.map +1 -0
- package/dist/esm/color/formats/hex/hex.js +25 -0
- package/dist/esm/color/formats/hexAlpha/hexAlpha.d.ts +9 -0
- package/dist/esm/color/formats/hexAlpha/hexAlpha.d.ts.map +1 -0
- package/dist/esm/color/formats/hexAlpha/hexAlpha.js +22 -0
- package/dist/esm/color/formats/hsl/hsl.d.ts +8 -0
- package/dist/esm/color/formats/hsl/hsl.d.ts.map +1 -0
- package/dist/esm/color/formats/hsl/hsl.js +20 -0
- package/dist/esm/color/formats/hwb/hwb.d.ts +9 -0
- package/dist/esm/color/formats/hwb/hwb.d.ts.map +1 -0
- package/dist/esm/color/formats/hwb/hwb.js +21 -0
- package/dist/esm/color/formats/index.d.ts +24 -0
- package/dist/esm/color/formats/index.d.ts.map +1 -0
- package/dist/esm/color/formats/index.js +32 -0
- package/dist/esm/color/formats/internals.d.ts +35 -0
- package/dist/esm/color/formats/internals.d.ts.map +1 -0
- package/dist/esm/color/formats/internals.js +78 -0
- package/dist/esm/color/formats/lab/lab.d.ts +9 -0
- package/dist/esm/color/formats/lab/lab.d.ts.map +1 -0
- package/dist/esm/color/formats/lab/lab.js +21 -0
- package/dist/esm/color/formats/lch/lch.d.ts +8 -0
- package/dist/esm/color/formats/lch/lch.d.ts.map +1 -0
- package/dist/esm/color/formats/lch/lch.js +20 -0
- package/dist/esm/color/formats/oklab/oklab.d.ts +9 -0
- package/dist/esm/color/formats/oklab/oklab.d.ts.map +1 -0
- package/dist/esm/color/formats/oklab/oklab.js +21 -0
- package/dist/esm/color/formats/oklch/oklch.d.ts +13 -0
- package/dist/esm/color/formats/oklch/oklch.d.ts.map +1 -0
- package/dist/esm/color/formats/oklch/oklch.js +25 -0
- package/dist/esm/color/formats/resolve.d.ts +15 -0
- package/dist/esm/color/formats/resolve.d.ts.map +1 -0
- package/dist/esm/color/formats/resolve.js +12 -0
- package/dist/esm/color/formats/rgb/rgb.d.ts +11 -0
- package/dist/esm/color/formats/rgb/rgb.d.ts.map +1 -0
- package/dist/esm/color/formats/rgb/rgb.js +26 -0
- package/dist/esm/color/formats/rgba/rgba.d.ts +9 -0
- package/dist/esm/color/formats/rgba/rgba.d.ts.map +1 -0
- package/dist/esm/color/formats/rgba/rgba.js +24 -0
- package/dist/esm/color/formats/types.d.ts +48 -0
- package/dist/esm/color/formats/types.d.ts.map +1 -0
- package/dist/esm/color/formats/types.js +7 -0
- package/dist/esm/color/index.d.ts +81 -0
- package/dist/esm/color/index.d.ts.map +1 -0
- package/dist/esm/color/index.js +609 -0
- package/dist/esm/color/types.d.ts +294 -0
- package/dist/esm/color/types.d.ts.map +1 -0
- package/dist/esm/color/types.js +1 -0
- package/dist/esm/core.d.ts +76 -270
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/core.js +5 -7
- package/dist/esm/corpus.d.ts +26 -0
- package/dist/esm/corpus.d.ts.map +1 -0
- package/dist/esm/corpus.js +37 -0
- package/dist/esm/css-values/cssValues.d.ts +60 -0
- package/dist/esm/css-values/cssValues.d.ts.map +1 -0
- package/dist/esm/css-values/cssValues.js +74 -0
- package/dist/esm/css-values/index.d.ts +6 -0
- package/dist/esm/css-values/index.d.ts.map +1 -0
- package/dist/esm/css-values/index.js +12 -0
- package/dist/esm/css-values/multi.d.ts +188 -0
- package/dist/esm/css-values/multi.d.ts.map +1 -0
- package/dist/esm/css-values/multi.js +281 -0
- package/dist/esm/css-values/propertyMap.d.ts +39 -0
- package/dist/esm/css-values/propertyMap.d.ts.map +1 -0
- package/dist/esm/css-values/propertyMap.js +1 -0
- package/dist/esm/css-values/spec.d.ts +36 -0
- package/dist/esm/css-values/spec.d.ts.map +1 -0
- package/dist/esm/css-values/spec.js +194 -0
- package/dist/esm/default.d.ts +267 -0
- package/dist/esm/default.d.ts.map +1 -0
- package/dist/esm/default.js +14 -0
- package/dist/esm/factory.d.ts +1 -1
- package/dist/esm/factory.d.ts.map +1 -1
- package/dist/esm/factory.js +3 -3
- package/dist/esm/float.d.ts +35 -0
- package/dist/esm/float.d.ts.map +1 -0
- package/dist/esm/float.js +104 -0
- package/dist/esm/index.d.ts +11 -9
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +19 -9
- package/dist/esm/integer.d.ts +36 -0
- package/dist/esm/integer.d.ts.map +1 -0
- package/dist/esm/integer.js +108 -0
- package/dist/esm/internal/buildMeasurementCreationError.tests.d.ts +1 -1
- package/dist/esm/internal/buildMeasurementCreationError.tests.d.ts.map +1 -1
- package/dist/esm/internal/createCoreApi.d.ts +9 -1
- package/dist/esm/internal/createCoreApi.d.ts.map +1 -1
- package/dist/esm/internal/createCoreApi.js +103 -38
- package/dist/esm/internal/createUnitsApi.d.ts +1 -1
- package/dist/esm/internal/createUnitsApi.d.ts.map +1 -1
- package/dist/esm/internal/errors.d.ts +3 -3
- package/dist/esm/internal/errors.d.ts.map +1 -1
- package/dist/esm/internal/errors.js +13 -14
- package/dist/esm/internal/toPlainDecimal.d.ts +2 -0
- package/dist/esm/internal/toPlainDecimal.d.ts.map +1 -0
- package/dist/esm/internal/toPlainDecimal.js +27 -0
- package/dist/esm/measurements.d.ts +16 -0
- package/dist/esm/measurements.d.ts.map +1 -0
- package/dist/esm/measurements.js +25 -0
- package/dist/esm/ratio.d.ts +14 -5
- package/dist/esm/ratio.d.ts.map +1 -1
- package/dist/esm/ratio.js +57 -22
- package/dist/esm/scalar.d.ts +14 -0
- package/dist/esm/scalar.d.ts.map +1 -0
- package/dist/esm/scalar.js +5 -0
- package/dist/esm/units/absolute.d.ts +1 -1
- package/dist/esm/units/absolute.d.ts.map +1 -1
- package/dist/esm/units/absolute.js +1 -1
- package/dist/esm/units/angle.d.ts +1 -1
- package/dist/esm/units/angle.d.ts.map +1 -1
- package/dist/esm/units/angle.js +1 -1
- package/dist/esm/units/container.d.ts +1 -1
- package/dist/esm/units/container.d.ts.map +1 -1
- package/dist/esm/units/container.js +1 -1
- package/dist/esm/units/font-relative.d.ts +1 -1
- package/dist/esm/units/font-relative.d.ts.map +1 -1
- package/dist/esm/units/font-relative.js +1 -1
- package/dist/esm/units/frequency.d.ts +1 -1
- package/dist/esm/units/frequency.d.ts.map +1 -1
- package/dist/esm/units/frequency.js +1 -1
- package/dist/esm/units/grid.d.ts +1 -1
- package/dist/esm/units/grid.d.ts.map +1 -1
- package/dist/esm/units/grid.js +1 -1
- package/dist/esm/units/index.d.ts +9 -9
- package/dist/esm/units/index.d.ts.map +1 -1
- package/dist/esm/units/index.js +9 -9
- package/dist/esm/units/percent.d.ts +1 -1
- package/dist/esm/units/percent.d.ts.map +1 -1
- package/dist/esm/units/percent.js +1 -1
- package/dist/esm/units/resolution.d.ts +1 -1
- package/dist/esm/units/resolution.d.ts.map +1 -1
- package/dist/esm/units/resolution.js +1 -1
- package/dist/esm/units/time.d.ts +1 -1
- package/dist/esm/units/time.d.ts.map +1 -1
- package/dist/esm/units/time.js +1 -1
- package/dist/esm/units/viewport-dynamic.d.ts +1 -1
- package/dist/esm/units/viewport-dynamic.d.ts.map +1 -1
- package/dist/esm/units/viewport-dynamic.js +1 -1
- package/dist/esm/units/viewport-large.d.ts +1 -1
- package/dist/esm/units/viewport-large.d.ts.map +1 -1
- package/dist/esm/units/viewport-large.js +1 -1
- package/dist/esm/units/viewport-small.d.ts +1 -1
- package/dist/esm/units/viewport-small.d.ts.map +1 -1
- package/dist/esm/units/viewport-small.js +1 -1
- package/dist/esm/units/viewport.d.ts +1 -1
- package/dist/esm/units/viewport.d.ts.map +1 -1
- package/dist/esm/units/viewport.js +1 -1
- package/package.json +54 -12
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The per-property CSS-VALUE HELPER LAYER: typed helpers for single-value CSS
|
|
2
|
+
// properties (`opacity`, `zIndex`, ...), each a constrained scalar (built on the
|
|
3
|
+
// `i()` / `f()` primitives) plus that property's keyword companions, with
|
|
4
|
+
// `.css()` typed against csstype's `Property`. The bare helper exports are
|
|
5
|
+
// `createCssValues()` at its defaults (`outOfRange: 'throw'`).
|
|
6
|
+
import { createCssValues } from './cssValues';
|
|
7
|
+
export { createCssValues, } from './cssValues';
|
|
8
|
+
export { borderImageOutset, borderImageSlice, borderImageWidth, counterIncrement, counterReset, counterSet, gridColumnEnd, gridColumnStart, gridRowEnd, gridRowStart, maskBorderOutset, maskBorderSlice, maskBorderWidth, scale, span, strokeDasharray, strokeDashoffset, strokeWidth, tabSize, } from './multi';
|
|
9
|
+
export { CSS_VALUE_SPEC, } from './spec';
|
|
10
|
+
/** The default instance: the bare helpers below are bound to it. */
|
|
11
|
+
const defaults = createCssValues();
|
|
12
|
+
export const { animationIterationCount, columnCount, fillOpacity, flexGrow, flexShrink, floodOpacity, fontSizeAdjust, fontWeight, lineClamp, lineHeight, mathDepth, opacity, order, orphans, shapeImageThreshold, stopOpacity, strokeMiterlimit, strokeOpacity, widows, zIndex, zoom, } = defaults;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { Property } from 'csstype';
|
|
2
|
+
import type { IMeasurement } from '../core';
|
|
3
|
+
/**
|
|
4
|
+
* The MULTI-PART CSS-VALUE HELPER LAYER.
|
|
5
|
+
*
|
|
6
|
+
* The single-value layer in `./cssValues.ts` is table-driven: one constrained
|
|
7
|
+
* scalar plus a keyword union per property, rendered through `i()` / `f()`. The
|
|
8
|
+
* properties here do not fit that one-scalar-one-keyword shape. Each accepts a
|
|
9
|
+
* *composite* value: a list of `<custom-ident> <integer>` pairs (the counter
|
|
10
|
+
* trio), a tri-state grid-line position (integer line, `span N`, named line, or
|
|
11
|
+
* `auto`), one-to-three scale factors, or a number-or-length `tab-size`.
|
|
12
|
+
*
|
|
13
|
+
* They share the single layer's contracts: numeric pieces go through `i()` /
|
|
14
|
+
* `f()` (so out-of-range and non-integer inputs throw at build time), keywords
|
|
15
|
+
* pass through untouched, and `.css()` is typed against the property's csstype
|
|
16
|
+
* `Property.X` value type via {@link MultiPropertyValueMap}.
|
|
17
|
+
*
|
|
18
|
+
* Every value object exposes the same trio as the single layer's `CssValue`:
|
|
19
|
+
* `.css()` (typed render), `.toString()` (mirrors `.css()`), and `.value()`
|
|
20
|
+
* (the raw `string` render). Builders validate eagerly and throw on bad input.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* An indexable bridge over csstype's `Property` namespace for the multi-part
|
|
24
|
+
* properties, mirroring `./propertyMap.ts`'s {@link PropertyValueMap}. A helper's
|
|
25
|
+
* PascalCase key (e.g. `'CounterReset'`) indexes this to recover
|
|
26
|
+
* `Property.CounterReset`, so each `.css()` is typed against the right csstype
|
|
27
|
+
* value type. Add a helper here -> add its `Property` key.
|
|
28
|
+
*/
|
|
29
|
+
export interface MultiPropertyValueMap {
|
|
30
|
+
CounterReset: Property.CounterReset;
|
|
31
|
+
CounterIncrement: Property.CounterIncrement;
|
|
32
|
+
CounterSet: Property.CounterSet;
|
|
33
|
+
GridRowStart: Property.GridRowStart;
|
|
34
|
+
GridRowEnd: Property.GridRowEnd;
|
|
35
|
+
GridColumnStart: Property.GridColumnStart;
|
|
36
|
+
GridColumnEnd: Property.GridColumnEnd;
|
|
37
|
+
Scale: Property.Scale;
|
|
38
|
+
TabSize: Property.TabSize;
|
|
39
|
+
BorderImageWidth: Property.BorderImageWidth;
|
|
40
|
+
BorderImageOutset: Property.BorderImageOutset;
|
|
41
|
+
BorderImageSlice: Property.BorderImageSlice;
|
|
42
|
+
MaskBorderWidth: Property.MaskBorderWidth;
|
|
43
|
+
MaskBorderOutset: Property.MaskBorderOutset;
|
|
44
|
+
MaskBorderSlice: Property.MaskBorderSlice;
|
|
45
|
+
StrokeWidth: Property.StrokeWidth;
|
|
46
|
+
StrokeDashoffset: Property.StrokeDashoffset;
|
|
47
|
+
StrokeDasharray: Property.StrokeDasharray;
|
|
48
|
+
}
|
|
49
|
+
/** The set of csstype `Property` keys the multi-part layer covers. */
|
|
50
|
+
export type MultiPropertyKey = keyof MultiPropertyValueMap;
|
|
51
|
+
/**
|
|
52
|
+
* A single typed multi-part CSS value. Built through a property helper
|
|
53
|
+
* (`scale(1, 2)`, `counterReset(['page', 1])`), rendered with `.css()` (typed
|
|
54
|
+
* against the property's csstype `Property` key). `.value()` returns the raw
|
|
55
|
+
* rendered `string`; `.toString()` mirrors `.css()`.
|
|
56
|
+
*/
|
|
57
|
+
export interface MultiCssValue<CssProperty extends MultiPropertyKey> {
|
|
58
|
+
css: () => MultiPropertyValueMap[CssProperty];
|
|
59
|
+
toString: () => string;
|
|
60
|
+
value: () => string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* One `<custom-ident> <integer>?` entry of a counter property. A bare string is
|
|
64
|
+
* the ident with the property's default integer; a `[ident, integer]` tuple
|
|
65
|
+
* supplies the integer explicitly. The integer is hardened with `i()`.
|
|
66
|
+
*/
|
|
67
|
+
export type CounterEntry = string | readonly [
|
|
68
|
+
name: string,
|
|
69
|
+
value: number
|
|
70
|
+
];
|
|
71
|
+
/**
|
|
72
|
+
* `counter-reset`: `<custom-ident> <integer>?` pairs (omitted integer defaults
|
|
73
|
+
* to `0`) or `none`. `.css()` is `Property.CounterReset`.
|
|
74
|
+
*/
|
|
75
|
+
export declare const counterReset: (first: CounterEntry, ...rest: readonly CounterEntry[]) => MultiCssValue<"CounterReset">;
|
|
76
|
+
/**
|
|
77
|
+
* `counter-increment`: `<custom-ident> <integer>?` pairs (omitted integer
|
|
78
|
+
* defaults to `1`) or `none`. `.css()` is `Property.CounterIncrement`.
|
|
79
|
+
*/
|
|
80
|
+
export declare const counterIncrement: (first: CounterEntry, ...rest: readonly CounterEntry[]) => MultiCssValue<"CounterIncrement">;
|
|
81
|
+
/**
|
|
82
|
+
* `counter-set`: `<custom-ident> <integer>?` pairs (omitted integer defaults to
|
|
83
|
+
* `0`) or `none`. `.css()` is `Property.CounterSet`.
|
|
84
|
+
*/
|
|
85
|
+
export declare const counterSet: (first: CounterEntry, ...rest: readonly CounterEntry[]) => MultiCssValue<"CounterSet">;
|
|
86
|
+
/**
|
|
87
|
+
* A grid-line position: a nonzero `<integer>` line number (negatives count from
|
|
88
|
+
* the end edge), `'auto'`, a `<custom-ident>` named line (a string that is not
|
|
89
|
+
* `'auto'` / `'span'`), or a `span N` count (`>= 1`) via {@link span}.
|
|
90
|
+
*/
|
|
91
|
+
export type GridLineInput = number | string | SpanInput;
|
|
92
|
+
/** A `span <integer>` grid-line value, built by {@link span}. */
|
|
93
|
+
export interface SpanInput {
|
|
94
|
+
readonly span: number;
|
|
95
|
+
readonly name?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Build a `span N` (optionally `span N name`) grid-line value. `count` is
|
|
99
|
+
* hardened to an integer `>= 1`. Pass the result to a grid-line helper:
|
|
100
|
+
* `gridColumnEnd(span(2))`.
|
|
101
|
+
*/
|
|
102
|
+
export declare const span: (count: number, name?: string) => SpanInput;
|
|
103
|
+
/** `grid-row-start`. `.css()` is `Property.GridRowStart`. */
|
|
104
|
+
export declare const gridRowStart: (line: GridLineInput) => MultiCssValue<"GridRowStart">;
|
|
105
|
+
/** `grid-row-end`. `.css()` is `Property.GridRowEnd`. */
|
|
106
|
+
export declare const gridRowEnd: (line: GridLineInput) => MultiCssValue<"GridRowEnd">;
|
|
107
|
+
/** `grid-column-start`. `.css()` is `Property.GridColumnStart`. */
|
|
108
|
+
export declare const gridColumnStart: (line: GridLineInput) => MultiCssValue<"GridColumnStart">;
|
|
109
|
+
/** `grid-column-end`. `.css()` is `Property.GridColumnEnd`. */
|
|
110
|
+
export declare const gridColumnEnd: (line: GridLineInput) => MultiCssValue<"GridColumnEnd">;
|
|
111
|
+
/**
|
|
112
|
+
* `scale`: one to three number factors (negatives allowed; the percentage form
|
|
113
|
+
* is out of scope), or the keyword `'none'`. Each factor is hardened through
|
|
114
|
+
* `f()`. `.css()` is `Property.Scale`.
|
|
115
|
+
*/
|
|
116
|
+
export declare function scale(keyword: 'none'): MultiCssValue<'Scale'>;
|
|
117
|
+
export declare function scale(x: number, y?: number, z?: number): MultiCssValue<'Scale'>;
|
|
118
|
+
/**
|
|
119
|
+
* `tab-size`: a `<number>` `>= 0` (NOT restricted to an integer; `2.5` is
|
|
120
|
+
* valid) hardened through `f()`, or a length supplied as an `IMeasurement`. The
|
|
121
|
+
* percentage form is out of scope. `.css()` is `Property.TabSize`.
|
|
122
|
+
*/
|
|
123
|
+
export declare const tabSize: (value: number | IMeasurement) => MultiCssValue<"TabSize">;
|
|
124
|
+
/**
|
|
125
|
+
* One entry of a number-or-length property: a unitless `<number>` (a
|
|
126
|
+
* css-calipers float input, hardened through `f()`) or a length supplied as an
|
|
127
|
+
* `IMeasurement` (rendered via its `.css()`). The percentage form is out of
|
|
128
|
+
* scope, so a percentage must be passed as an `IMeasurement` carrying a `%`
|
|
129
|
+
* unit, never as a bare number.
|
|
130
|
+
*/
|
|
131
|
+
export type NumberOrLength = number | IMeasurement;
|
|
132
|
+
/**
|
|
133
|
+
* `border-image-width`: one to four entries, each a non-negative `<number>`
|
|
134
|
+
* multiplier (hardened through `f({ min: 0 })`), an `IMeasurement` length, or
|
|
135
|
+
* the keyword `'auto'`. `.css()` is `Property.BorderImageWidth`.
|
|
136
|
+
*/
|
|
137
|
+
export declare const borderImageWidth: (first: NumberOrLength | string, ...rest: readonly (NumberOrLength | string)[]) => MultiCssValue<"BorderImageWidth">;
|
|
138
|
+
/**
|
|
139
|
+
* `border-image-outset`: one to four entries, each a non-negative `<number>`
|
|
140
|
+
* (hardened through `f({ min: 0 })`) or an `IMeasurement` length. `.css()` is
|
|
141
|
+
* `Property.BorderImageOutset`.
|
|
142
|
+
*/
|
|
143
|
+
export declare const borderImageOutset: (first: NumberOrLength | string, ...rest: readonly (NumberOrLength | string)[]) => MultiCssValue<"BorderImageOutset">;
|
|
144
|
+
/**
|
|
145
|
+
* `mask-border-width`: like {@link borderImageWidth} (non-negative `<number>`,
|
|
146
|
+
* `IMeasurement`, or `'auto'`; one to four entries). `.css()` is
|
|
147
|
+
* `Property.MaskBorderWidth`.
|
|
148
|
+
*/
|
|
149
|
+
export declare const maskBorderWidth: (first: NumberOrLength | string, ...rest: readonly (NumberOrLength | string)[]) => MultiCssValue<"MaskBorderWidth">;
|
|
150
|
+
/**
|
|
151
|
+
* `mask-border-outset`: like {@link borderImageOutset} (non-negative
|
|
152
|
+
* `<number>` or `IMeasurement`; one to four entries). `.css()` is
|
|
153
|
+
* `Property.MaskBorderOutset`.
|
|
154
|
+
*/
|
|
155
|
+
export declare const maskBorderOutset: (first: NumberOrLength | string, ...rest: readonly (NumberOrLength | string)[]) => MultiCssValue<"MaskBorderOutset">;
|
|
156
|
+
/**
|
|
157
|
+
* `border-image-slice`: one to four non-negative `<number>` entries, with an
|
|
158
|
+
* optional trailing `'fill'` keyword. The percentage form is out of scope.
|
|
159
|
+
* `.css()` is `Property.BorderImageSlice`.
|
|
160
|
+
*/
|
|
161
|
+
export declare const borderImageSlice: (first: number, ...rest: readonly (number | "fill")[]) => MultiCssValue<"BorderImageSlice">;
|
|
162
|
+
/**
|
|
163
|
+
* `mask-border-slice`: like {@link borderImageSlice} (one to four non-negative
|
|
164
|
+
* `<number>` entries plus an optional trailing `'fill'`). `.css()` is
|
|
165
|
+
* `Property.MaskBorderSlice`.
|
|
166
|
+
*/
|
|
167
|
+
export declare const maskBorderSlice: (first: number, ...rest: readonly (number | "fill")[]) => MultiCssValue<"MaskBorderSlice">;
|
|
168
|
+
/**
|
|
169
|
+
* `stroke-width`: a single non-negative `<number>` (SVG user units, hardened
|
|
170
|
+
* through `f({ min: 0 })`) or an `IMeasurement` length. The percentage form is
|
|
171
|
+
* out of scope. `.css()` is `Property.StrokeWidth`.
|
|
172
|
+
*/
|
|
173
|
+
export declare const strokeWidth: (value: NumberOrLength) => MultiCssValue<"StrokeWidth">;
|
|
174
|
+
/**
|
|
175
|
+
* `stroke-dashoffset`: a single `<number>` (any value; SVG user units, hardened
|
|
176
|
+
* through `f()`) or an `IMeasurement` length. The percentage form is out of
|
|
177
|
+
* scope. `.css()` is `Property.StrokeDashoffset`.
|
|
178
|
+
*/
|
|
179
|
+
export declare const strokeDashoffset: (value: NumberOrLength) => MultiCssValue<"StrokeDashoffset">;
|
|
180
|
+
/**
|
|
181
|
+
* `stroke-dasharray`: the keyword `'none'`, or a list of one or more entries,
|
|
182
|
+
* each a non-negative `<number>` (SVG user units, hardened through
|
|
183
|
+
* `f({ min: 0 })`) or an `IMeasurement` length. The percentage form is out of
|
|
184
|
+
* scope. `.css()` is `Property.StrokeDasharray`.
|
|
185
|
+
*/
|
|
186
|
+
export declare function strokeDasharray(keyword: 'none'): MultiCssValue<'StrokeDasharray'>;
|
|
187
|
+
export declare function strokeDasharray(first: NumberOrLength, ...rest: readonly NumberOrLength[]): MultiCssValue<'StrokeDasharray'>;
|
|
188
|
+
//# sourceMappingURL=multi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi.d.ts","sourceRoot":"","sources":["../../../src/css-values/multi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAA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ACpC,wBAAgB,eAAe,CAC7B,KAAK,EAAE,cAAc,EACrB,GAAG,IAAI,EAAE,SAAS,cAAc,EAAE,GACjC,aAAa,CAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { isMeasurement } from '../default';
|
|
2
|
+
import { f } from '../float';
|
|
3
|
+
import { i } from '../integer';
|
|
4
|
+
/**
|
|
5
|
+
* Wrap a finished render string as a typed value object. Every
|
|
6
|
+
* `MultiPropertyValueMap[CssProperty]` widens to include `(string & {})`, so the
|
|
7
|
+
* rendered `string` is directly assignable; no cast is needed.
|
|
8
|
+
*/
|
|
9
|
+
const wrap = (rendered) => ({
|
|
10
|
+
css: () => rendered,
|
|
11
|
+
toString: () => rendered,
|
|
12
|
+
value: () => rendered,
|
|
13
|
+
});
|
|
14
|
+
const CUSTOM_IDENT = /^-?[_a-zA-Z][\w-]*$/;
|
|
15
|
+
const assertCustomIdent = (name, helper) => {
|
|
16
|
+
if (!CUSTOM_IDENT.test(name)) {
|
|
17
|
+
throw new Error(`${helper}: '${name}' is not a valid <custom-ident> ` +
|
|
18
|
+
`(letters, digits, '-', '_'; must not start with a digit)`);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Build a counter helper. Accepts the keyword `'none'`, or one or more
|
|
23
|
+
* `<custom-ident> <integer>?` entries. A bare ident uses `defaultValue`; a
|
|
24
|
+
* `[ident, n]` tuple hardens `n` through `i()` (any integer, negatives allowed).
|
|
25
|
+
*/
|
|
26
|
+
const makeCounterHelper = (helper, defaultValue) => (
|
|
27
|
+
// `'none'` is accepted as the standalone keyword; at the type level it is a
|
|
28
|
+
// `string`, indistinct from a `<custom-ident>`, so the union is just
|
|
29
|
+
// `CounterEntry`. The keyword is recognized (and guarded against being
|
|
30
|
+
// combined with entries) at runtime below.
|
|
31
|
+
first, ...rest) => {
|
|
32
|
+
if (first === 'none') {
|
|
33
|
+
if (rest.length > 0) {
|
|
34
|
+
throw new Error(`${helper}: 'none' cannot be combined with counter entries`);
|
|
35
|
+
}
|
|
36
|
+
return wrap('none');
|
|
37
|
+
}
|
|
38
|
+
const entries = [
|
|
39
|
+
first,
|
|
40
|
+
...rest,
|
|
41
|
+
];
|
|
42
|
+
const parts = entries.map((entry) => {
|
|
43
|
+
const [name, value,] = typeof entry === 'string'
|
|
44
|
+
? [
|
|
45
|
+
entry,
|
|
46
|
+
defaultValue,
|
|
47
|
+
]
|
|
48
|
+
: entry;
|
|
49
|
+
assertCustomIdent(name, helper);
|
|
50
|
+
const n = i(value, { context: helper }).css();
|
|
51
|
+
return `${name} ${n}`;
|
|
52
|
+
});
|
|
53
|
+
return wrap(parts.join(' '));
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* `counter-reset`: `<custom-ident> <integer>?` pairs (omitted integer defaults
|
|
57
|
+
* to `0`) or `none`. `.css()` is `Property.CounterReset`.
|
|
58
|
+
*/
|
|
59
|
+
export const counterReset = makeCounterHelper('counterReset', 0);
|
|
60
|
+
/**
|
|
61
|
+
* `counter-increment`: `<custom-ident> <integer>?` pairs (omitted integer
|
|
62
|
+
* defaults to `1`) or `none`. `.css()` is `Property.CounterIncrement`.
|
|
63
|
+
*/
|
|
64
|
+
export const counterIncrement = makeCounterHelper('counterIncrement', 1);
|
|
65
|
+
/**
|
|
66
|
+
* `counter-set`: `<custom-ident> <integer>?` pairs (omitted integer defaults to
|
|
67
|
+
* `0`) or `none`. `.css()` is `Property.CounterSet`.
|
|
68
|
+
*/
|
|
69
|
+
export const counterSet = makeCounterHelper('counterSet', 0);
|
|
70
|
+
/**
|
|
71
|
+
* Build a `span N` (optionally `span N name`) grid-line value. `count` is
|
|
72
|
+
* hardened to an integer `>= 1`. Pass the result to a grid-line helper:
|
|
73
|
+
* `gridColumnEnd(span(2))`.
|
|
74
|
+
*/
|
|
75
|
+
export const span = (count, name) => ({
|
|
76
|
+
span: count,
|
|
77
|
+
name,
|
|
78
|
+
});
|
|
79
|
+
const makeGridLineHelper = (helper) => (line) => {
|
|
80
|
+
if (typeof line === 'number') {
|
|
81
|
+
if (line === 0) {
|
|
82
|
+
throw new Error(`${helper}: a grid line number must be nonzero (got 0)`);
|
|
83
|
+
}
|
|
84
|
+
return wrap(i(line, { context: helper }).css());
|
|
85
|
+
}
|
|
86
|
+
if (typeof line === 'string') {
|
|
87
|
+
if (line === 'span') {
|
|
88
|
+
throw new Error(`${helper}: use span(n) to build a 'span' value`);
|
|
89
|
+
}
|
|
90
|
+
if (line !== 'auto') {
|
|
91
|
+
assertCustomIdent(line, helper);
|
|
92
|
+
}
|
|
93
|
+
return wrap(line);
|
|
94
|
+
}
|
|
95
|
+
// SpanInput
|
|
96
|
+
const count = i(line.span, {
|
|
97
|
+
min: 1,
|
|
98
|
+
context: `${helper} span`,
|
|
99
|
+
}).css();
|
|
100
|
+
if (line.name !== undefined) {
|
|
101
|
+
assertCustomIdent(line.name, helper);
|
|
102
|
+
return wrap(`span ${count} ${line.name}`);
|
|
103
|
+
}
|
|
104
|
+
return wrap(`span ${count}`);
|
|
105
|
+
};
|
|
106
|
+
/** `grid-row-start`. `.css()` is `Property.GridRowStart`. */
|
|
107
|
+
export const gridRowStart = makeGridLineHelper('gridRowStart');
|
|
108
|
+
/** `grid-row-end`. `.css()` is `Property.GridRowEnd`. */
|
|
109
|
+
export const gridRowEnd = makeGridLineHelper('gridRowEnd');
|
|
110
|
+
/** `grid-column-start`. `.css()` is `Property.GridColumnStart`. */
|
|
111
|
+
export const gridColumnStart = makeGridLineHelper('gridColumnStart');
|
|
112
|
+
/** `grid-column-end`. `.css()` is `Property.GridColumnEnd`. */
|
|
113
|
+
export const gridColumnEnd = makeGridLineHelper('gridColumnEnd');
|
|
114
|
+
export function scale(first, y, z) {
|
|
115
|
+
if (first === 'none') {
|
|
116
|
+
return wrap('none');
|
|
117
|
+
}
|
|
118
|
+
const factors = [
|
|
119
|
+
first,
|
|
120
|
+
y,
|
|
121
|
+
z,
|
|
122
|
+
].filter((n) => n !== undefined);
|
|
123
|
+
const rendered = factors
|
|
124
|
+
.map((n) => f(n, { context: 'scale' }).css())
|
|
125
|
+
.join(' ');
|
|
126
|
+
return wrap(rendered);
|
|
127
|
+
}
|
|
128
|
+
// --- tab-size -------------------------------------------------------------
|
|
129
|
+
/**
|
|
130
|
+
* `tab-size`: a `<number>` `>= 0` (NOT restricted to an integer; `2.5` is
|
|
131
|
+
* valid) hardened through `f()`, or a length supplied as an `IMeasurement`. The
|
|
132
|
+
* percentage form is out of scope. `.css()` is `Property.TabSize`.
|
|
133
|
+
*/
|
|
134
|
+
export const tabSize = (value) => {
|
|
135
|
+
if (typeof value === 'number') {
|
|
136
|
+
return wrap(f(value, { min: 0, context: 'tabSize' }).css());
|
|
137
|
+
}
|
|
138
|
+
return wrap(value.css());
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Render one number-or-length entry. A number is hardened through `f()` with the
|
|
142
|
+
* given bounds (so out-of-range / non-finite inputs throw); an `IMeasurement`
|
|
143
|
+
* renders through its `.css()`. Anything else throws with the helper name.
|
|
144
|
+
*/
|
|
145
|
+
const renderNumberOrLength = (entry, helper, min) => {
|
|
146
|
+
if (typeof entry === 'number') {
|
|
147
|
+
return f(entry, { min, context: helper }).css();
|
|
148
|
+
}
|
|
149
|
+
if (isMeasurement(entry)) {
|
|
150
|
+
return entry.css();
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`${helper}: expected a <number> or an IMeasurement (got ${typeof entry})`);
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Build a 1-to-4-value helper whose entries are each a `<number>` (hardened
|
|
156
|
+
* with `min`) or an `IMeasurement`, with an optional per-entry keyword
|
|
157
|
+
* (`'auto'` for the *-width properties). Mirrors the box-edge `{1,4}` shape
|
|
158
|
+
* (`border-image-width`, `border-image-outset`, ...): supply one to four
|
|
159
|
+
* entries, rendered space-separated in order.
|
|
160
|
+
*/
|
|
161
|
+
const makeEdgeQuadHelper = (helper, min, keywords) => (first, ...rest) => {
|
|
162
|
+
const entries = [
|
|
163
|
+
first,
|
|
164
|
+
...rest,
|
|
165
|
+
];
|
|
166
|
+
if (entries.length > 4) {
|
|
167
|
+
throw new Error(`${helper}: expected 1 to 4 entries (got ${entries.length})`);
|
|
168
|
+
}
|
|
169
|
+
const keywordSet = new Set(keywords);
|
|
170
|
+
const parts = entries.map((entry) => {
|
|
171
|
+
if (typeof entry === 'string') {
|
|
172
|
+
if (!keywordSet.has(entry)) {
|
|
173
|
+
throw new Error(`${helper}: '${entry}' is not a valid keyword` +
|
|
174
|
+
` (expected one of: ${keywords.join(', ') || 'none'})`);
|
|
175
|
+
}
|
|
176
|
+
return entry;
|
|
177
|
+
}
|
|
178
|
+
return renderNumberOrLength(entry, helper, min);
|
|
179
|
+
});
|
|
180
|
+
return wrap(parts.join(' '));
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* `border-image-width`: one to four entries, each a non-negative `<number>`
|
|
184
|
+
* multiplier (hardened through `f({ min: 0 })`), an `IMeasurement` length, or
|
|
185
|
+
* the keyword `'auto'`. `.css()` is `Property.BorderImageWidth`.
|
|
186
|
+
*/
|
|
187
|
+
export const borderImageWidth = makeEdgeQuadHelper('borderImageWidth', 0, [
|
|
188
|
+
'auto',
|
|
189
|
+
]);
|
|
190
|
+
/**
|
|
191
|
+
* `border-image-outset`: one to four entries, each a non-negative `<number>`
|
|
192
|
+
* (hardened through `f({ min: 0 })`) or an `IMeasurement` length. `.css()` is
|
|
193
|
+
* `Property.BorderImageOutset`.
|
|
194
|
+
*/
|
|
195
|
+
export const borderImageOutset = makeEdgeQuadHelper('borderImageOutset', 0, []);
|
|
196
|
+
/**
|
|
197
|
+
* `mask-border-width`: like {@link borderImageWidth} (non-negative `<number>`,
|
|
198
|
+
* `IMeasurement`, or `'auto'`; one to four entries). `.css()` is
|
|
199
|
+
* `Property.MaskBorderWidth`.
|
|
200
|
+
*/
|
|
201
|
+
export const maskBorderWidth = makeEdgeQuadHelper('maskBorderWidth', 0, [
|
|
202
|
+
'auto',
|
|
203
|
+
]);
|
|
204
|
+
/**
|
|
205
|
+
* `mask-border-outset`: like {@link borderImageOutset} (non-negative
|
|
206
|
+
* `<number>` or `IMeasurement`; one to four entries). `.css()` is
|
|
207
|
+
* `Property.MaskBorderOutset`.
|
|
208
|
+
*/
|
|
209
|
+
export const maskBorderOutset = makeEdgeQuadHelper('maskBorderOutset', 0, []);
|
|
210
|
+
/**
|
|
211
|
+
* Build a `border-image-slice` / `mask-border-slice` helper: one to four
|
|
212
|
+
* non-negative `<number>` entries (hardened through `f({ min: 0 })`; the
|
|
213
|
+
* percentage form is out of scope), with an optional trailing `'fill'`
|
|
214
|
+
* keyword. The slice properties accept numbers (and percentages), not lengths,
|
|
215
|
+
* so an `IMeasurement` is rejected.
|
|
216
|
+
*/
|
|
217
|
+
const makeSliceHelper = (helper) => (first, ...rest) => {
|
|
218
|
+
const all = [
|
|
219
|
+
first,
|
|
220
|
+
...rest,
|
|
221
|
+
];
|
|
222
|
+
let fill = false;
|
|
223
|
+
if (all[all.length - 1] === 'fill') {
|
|
224
|
+
fill = true;
|
|
225
|
+
all.pop();
|
|
226
|
+
}
|
|
227
|
+
if (all.some((entry) => entry === 'fill')) {
|
|
228
|
+
throw new Error(`${helper}: 'fill' may only appear as the trailing keyword`);
|
|
229
|
+
}
|
|
230
|
+
if (all.length < 1 || all.length > 4) {
|
|
231
|
+
throw new Error(`${helper}: expected 1 to 4 numbers (got ${all.length})`);
|
|
232
|
+
}
|
|
233
|
+
const parts = all.map((entry) => {
|
|
234
|
+
if (typeof entry !== 'number') {
|
|
235
|
+
throw new Error(`${helper}: expected a <number> (got ${typeof entry})`);
|
|
236
|
+
}
|
|
237
|
+
return f(entry, { min: 0, context: helper }).css();
|
|
238
|
+
});
|
|
239
|
+
if (fill) {
|
|
240
|
+
parts.push('fill');
|
|
241
|
+
}
|
|
242
|
+
return wrap(parts.join(' '));
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* `border-image-slice`: one to four non-negative `<number>` entries, with an
|
|
246
|
+
* optional trailing `'fill'` keyword. The percentage form is out of scope.
|
|
247
|
+
* `.css()` is `Property.BorderImageSlice`.
|
|
248
|
+
*/
|
|
249
|
+
export const borderImageSlice = makeSliceHelper('borderImageSlice');
|
|
250
|
+
/**
|
|
251
|
+
* `mask-border-slice`: like {@link borderImageSlice} (one to four non-negative
|
|
252
|
+
* `<number>` entries plus an optional trailing `'fill'`). `.css()` is
|
|
253
|
+
* `Property.MaskBorderSlice`.
|
|
254
|
+
*/
|
|
255
|
+
export const maskBorderSlice = makeSliceHelper('maskBorderSlice');
|
|
256
|
+
/**
|
|
257
|
+
* `stroke-width`: a single non-negative `<number>` (SVG user units, hardened
|
|
258
|
+
* through `f({ min: 0 })`) or an `IMeasurement` length. The percentage form is
|
|
259
|
+
* out of scope. `.css()` is `Property.StrokeWidth`.
|
|
260
|
+
*/
|
|
261
|
+
export const strokeWidth = (value) => wrap(renderNumberOrLength(value, 'strokeWidth', 0));
|
|
262
|
+
/**
|
|
263
|
+
* `stroke-dashoffset`: a single `<number>` (any value; SVG user units, hardened
|
|
264
|
+
* through `f()`) or an `IMeasurement` length. The percentage form is out of
|
|
265
|
+
* scope. `.css()` is `Property.StrokeDashoffset`.
|
|
266
|
+
*/
|
|
267
|
+
export const strokeDashoffset = (value) => wrap(renderNumberOrLength(value, 'strokeDashoffset'));
|
|
268
|
+
export function strokeDasharray(first, ...rest) {
|
|
269
|
+
if (first === 'none') {
|
|
270
|
+
if (rest.length > 0) {
|
|
271
|
+
throw new Error(`strokeDasharray: 'none' cannot be combined with entries`);
|
|
272
|
+
}
|
|
273
|
+
return wrap('none');
|
|
274
|
+
}
|
|
275
|
+
const entries = [
|
|
276
|
+
first,
|
|
277
|
+
...rest,
|
|
278
|
+
];
|
|
279
|
+
const parts = entries.map((entry) => renderNumberOrLength(entry, 'strokeDasharray', 0));
|
|
280
|
+
return wrap(parts.join(' '));
|
|
281
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Property } from 'csstype';
|
|
2
|
+
/**
|
|
3
|
+
* An indexable bridge over csstype's `Property` NAMESPACE.
|
|
4
|
+
*
|
|
5
|
+
* csstype exposes per-property value types as namespace members (`Property.Opacity`,
|
|
6
|
+
* `Property.ZIndex`), and a namespace cannot be `keyof`-ed or indexed by a generic
|
|
7
|
+
* key. This interface re-exposes exactly the members the spec table uses, so a row's
|
|
8
|
+
* PascalCase `cssProperty` key (e.g. `'Opacity'`) can index it: `PropertyValueMap['Opacity']`
|
|
9
|
+
* is `Property.Opacity`. That is what lets one generic factory type every helper's
|
|
10
|
+
* `.css()` return against the right csstype value type.
|
|
11
|
+
*
|
|
12
|
+
* Add a row to the spec table -> add its `Property` key here.
|
|
13
|
+
*/
|
|
14
|
+
export interface PropertyValueMap {
|
|
15
|
+
Opacity: Property.Opacity;
|
|
16
|
+
FillOpacity: Property.FillOpacity;
|
|
17
|
+
StrokeOpacity: Property.StrokeOpacity;
|
|
18
|
+
StopOpacity: Property.StopOpacity;
|
|
19
|
+
FloodOpacity: Property.FloodOpacity;
|
|
20
|
+
ShapeImageThreshold: Property.ShapeImageThreshold;
|
|
21
|
+
LineHeight: Property.LineHeight;
|
|
22
|
+
FlexGrow: Property.FlexGrow;
|
|
23
|
+
FlexShrink: Property.FlexShrink;
|
|
24
|
+
AnimationIterationCount: Property.AnimationIterationCount;
|
|
25
|
+
FontSizeAdjust: Property.FontSizeAdjust;
|
|
26
|
+
Zoom: Property.Zoom;
|
|
27
|
+
FontWeight: Property.FontWeight;
|
|
28
|
+
StrokeMiterlimit: Property.StrokeMiterlimit;
|
|
29
|
+
ZIndex: Property.ZIndex;
|
|
30
|
+
Order: Property.Order;
|
|
31
|
+
MathDepth: Property.MathDepth;
|
|
32
|
+
ColumnCount: Property.ColumnCount;
|
|
33
|
+
Orphans: Property.Orphans;
|
|
34
|
+
Widows: Property.Widows;
|
|
35
|
+
WebkitLineClamp: Property.WebkitLineClamp;
|
|
36
|
+
}
|
|
37
|
+
/** The set of csstype `Property` keys the css-value layer covers. */
|
|
38
|
+
export type CssPropertyKey = keyof PropertyValueMap;
|
|
39
|
+
//# sourceMappingURL=propertyMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyMap.d.ts","sourceRoot":"","sources":["../../../src/css-values/propertyMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC;IAC1B,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC;IAClC,aAAa,EAAE,QAAQ,CAAC,aAAa,CAAC;IACtC,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC;IAClC,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC;IACpC,mBAAmB,EAAE,QAAQ,CAAC,mBAAmB,CAAC;IAClD,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC;IAChC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC;IAC5B,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC;IAChC,uBAAuB,EAAE,QAAQ,CAAC,uBAAuB,CAAC;IAC1D,cAAc,EAAE,QAAQ,CAAC,cAAc,CAAC;IACxC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;IACpB,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC;IAChC,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB,CAAC;IAC5C,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;IACxB,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC;IACtB,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC;IAC9B,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC;IAClC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC;IAC1B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;IACxB,eAAe,EAAE,QAAQ,CAAC,eAAe,CAAC;CAC3C;AAED,qEAAqE;AACrE,MAAM,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CssPropertyKey } from './propertyMap';
|
|
2
|
+
/**
|
|
3
|
+
* One row of the css-value spec table. Each row describes a single-value CSS
|
|
4
|
+
* property: the constrained scalar (an integer or a float, with optional
|
|
5
|
+
* `min`/`max` bounds) plus that property's keyword companions.
|
|
6
|
+
*
|
|
7
|
+
* - `name` is the camelCase helper name (`opacity`, `zIndex`).
|
|
8
|
+
* - `cssProperty` is the csstype `Property` key, so `.css()` is typed against
|
|
9
|
+
* that property's `Property.X` value type (via `PropertyValueMap`).
|
|
10
|
+
* - `keywords` is the literal union of bare keywords the property also accepts
|
|
11
|
+
* (`'auto'`, `'normal'`, ...). It passes through untouched.
|
|
12
|
+
*
|
|
13
|
+
* The two generics (`CssProperty`, `Keyword`) are preserved per row so each
|
|
14
|
+
* generated helper carries its own `.css()` return type and keyword union.
|
|
15
|
+
*/
|
|
16
|
+
export interface SpecRow<Name extends string = string, CssProperty extends CssPropertyKey = CssPropertyKey, Keyword extends string = string> {
|
|
17
|
+
readonly name: Name;
|
|
18
|
+
readonly kind: 'int' | 'float';
|
|
19
|
+
readonly min?: number;
|
|
20
|
+
readonly max?: number;
|
|
21
|
+
readonly keywords: readonly Keyword[];
|
|
22
|
+
readonly cssProperty: CssProperty;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The css-value spec table: one row per single-value property. The factory in
|
|
26
|
+
* `./cssValues.ts` generates a typed helper from each row, so adding a property
|
|
27
|
+
* is a one-line table edit, not a hand-written function.
|
|
28
|
+
*
|
|
29
|
+
* Sourced from `docs/css-number-value-types.md`. Multi-value properties and
|
|
30
|
+
* those lacking a clean single-value mapping (e.g. `maxLines`, the counter
|
|
31
|
+
* trio, grid lines, `scale`, `tabSize`) are intentionally excluded.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CSS_VALUE_SPEC: readonly [SpecRow<"opacity", "Opacity", never>, SpecRow<"fillOpacity", "FillOpacity", never>, SpecRow<"strokeOpacity", "StrokeOpacity", never>, SpecRow<"stopOpacity", "StopOpacity", never>, SpecRow<"floodOpacity", "FloodOpacity", never>, SpecRow<"shapeImageThreshold", "ShapeImageThreshold", never>, SpecRow<"lineHeight", "LineHeight", "normal">, SpecRow<"flexGrow", "FlexGrow", never>, SpecRow<"flexShrink", "FlexShrink", never>, SpecRow<"animationIterationCount", "AnimationIterationCount", "infinite">, SpecRow<"fontSizeAdjust", "FontSizeAdjust", "from-font" | "none">, SpecRow<"zoom", "Zoom", never>, SpecRow<"fontWeight", "FontWeight", "normal" | "bold" | "bolder" | "lighter">, SpecRow<"strokeMiterlimit", "StrokeMiterlimit", never>, SpecRow<"zIndex", "ZIndex", "auto">, SpecRow<"order", "Order", never>, SpecRow<"mathDepth", "MathDepth", "auto-add">, SpecRow<"columnCount", "ColumnCount", "auto">, SpecRow<"orphans", "Orphans", never>, SpecRow<"widows", "Widows", never>, SpecRow<"lineClamp", "WebkitLineClamp", "none">];
|
|
34
|
+
/** The spec table's type (a readonly tuple of {@link SpecRow}s). */
|
|
35
|
+
export type CssValueSpec = typeof CSS_VALUE_SPEC;
|
|
36
|
+
//# sourceMappingURL=spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec.d.ts","sourceRoot":"","sources":["../../../src/css-values/spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,OAAO,CACtB,IAAI,SAAS,MAAM,GAAG,MAAM,EAC5B,WAAW,SAAS,cAAc,GAAG,cAAc,EACnD,OAAO,SAAS,MAAM,GAAG,MAAM;IAE/B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;IAC/B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC;AAgBD;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,qgCAqLjB,CAAC;AAEX,oEAAoE;AACpE,MAAM,MAAM,YAAY,GAAG,OAAO,cAAc,CAAC"}
|