@teacss/rule-helpers 0.3.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 ADDED
@@ -0,0 +1,22 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2021-PRESENT Anthony Fu <https://github.com/antfu>
4
+ Copyright (c) 2026-PRESENT Billgo <hi@billgo.me>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # @teacss/rule-helpers
2
+
3
+ **Helpers for writing TeaCSS presets and directive transforms.**
4
+
5
+ ## Purpose
6
+
7
+ This package provides reusable rule builders, TeaCSS value resolvers, CSS value
8
+ grammar, theme helpers, and shared constants for preset authors.
9
+
10
+ Preset and directive authors use these helpers to implement behavior consistent
11
+ with TeaCSS parsing and value conventions. The package does not choose a
12
+ preset's public utility prefixes, theme schema, or vocabulary-specific scales
13
+ and aliases, register a preset, or run CSS generation; the calling preset or
14
+ integration selects the generic building blocks and owns those public
15
+ vocabulary decisions.
16
+
17
+ ## Usage
18
+
19
+ ```ts
20
+ import {
21
+ consumeCssIdentifier,
22
+ createValueHandler,
23
+ cssLengthPercentageUnitRESource,
24
+ cssLengthUnitRESource,
25
+ cssLengthUnits,
26
+ decodeArbitraryValue,
27
+ decodeCssIdentifier,
28
+ getBracket,
29
+ getOwn,
30
+ h,
31
+ isBareDashedIdentifier,
32
+ isCssIdentifier,
33
+ makeArbitraryValueRule,
34
+ makeGlobalRules,
35
+ makeGlobalValueRule,
36
+ makeShorthandRules,
37
+ makeStaticRules,
38
+ parseCssColor,
39
+ routeGlobalKeywordsToExactRules,
40
+ transformThemeFn,
41
+ valueHandlers,
42
+ } from "@teacss/rule-helpers";
43
+ ```
44
+
45
+ Use these helpers when a preset needs behavior compatible with TeaCSS's standard
46
+ value and condition model. Use `makeShorthandRules` for bare shorthand rules
47
+ that should emit in TeaCSS's primitives layer by default, e.g.
48
+ `makeShorthandRules("outline", DEFAULT_OUTLINE)`.
49
+
50
+ Use `makeGlobalRules` for enum rules that also need exact dynamic CSS-wide
51
+ keywords. Apply `routeGlobalKeywordsToExactRules` to the flattened preset rules
52
+ before appending user rules so broad preset fallbacks cannot shadow those exact
53
+ global-keyword rules.
54
+
55
+ Use `getOwn(record, key)` for user-controlled maps such as theme values and
56
+ static rule tables. It returns explicitly configured own properties—including
57
+ names such as `constructor`—while ignoring inherited object properties.
58
+
59
+ `cssLengthUnitRESource` and `cssLengthPercentageUnitRESource` are derived from
60
+ `cssLengthUnits`; reuse them when several helpers must validate the same modern
61
+ CSS length-unit vocabulary.
62
+
63
+ Use `makeArbitraryValueRule` for a dynamic fallback that accepts bracket values
64
+ and CSS variables. Use `makeGlobalValueRule` when the same fallback must also
65
+ accept CSS-wide keywords such as `inherit` and `unset`. Both builders preserve
66
+ the supplied matcher, CSS property, and autocomplete metadata; the rule value
67
+ must be the matcher's first capture group.
68
+
69
+ Use the chainable `h` parser when a value may take several forms. The first
70
+ matching handler wins, for example `h.bracket.cssvar.global.positiveInteger(value)`.
71
+ `valueHandlers` exposes the same parsers individually. Common CSS value types
72
+ include `alpha`, `integer`, `positiveInteger`, `customIdent`, and `url`, alongside
73
+ the existing bracket, variable, global-keyword, number, percentage, length, and
74
+ time handlers. Use `decodeArbitraryValue` when a helper needs exactly the same
75
+ arbitrary-value decoding as `h.bracket` without constructing a handler chain.
76
+ Use `isBareDashedIdentifier` when validating a CSS dashed identifier before
77
+ wrapping or otherwise interpreting it.
78
+
79
+ Import reusable TeaCSS value resolvers from their dedicated subpath:
80
+
81
+ ```ts
82
+ import {
83
+ applyOpacity,
84
+ isCssVariableToken,
85
+ resolveAlphaValue,
86
+ resolveKeyword,
87
+ resolveNumber,
88
+ resolveThemeVariable,
89
+ resolveTime,
90
+ } from "@teacss/rule-helpers/value-resolvers";
91
+ ```
92
+
93
+ Use `resolveThemeVariable` for typed theme groups, `resolveKeyword` for
94
+ caller-supplied keyword sets, `resolveTime` and `resolveNumber` for TeaCSS
95
+ tokens, `isCssVariableToken` for `$name` syntax, and the opacity helpers for
96
+ color modifiers. Theme schemas, variable prefixes, passthrough keys, and
97
+ allowed values remain owned by the calling preset.
98
+
99
+ Use `isCssIdentifier` to validate a complete CSS identifier,
100
+ `consumeCssIdentifier` while scanning a larger value, and
101
+ `decodeCssIdentifier` when escaped spellings need a shared identity. These
102
+ primitives support non-ASCII names and CSS escapes.
103
+
104
+ Import generic top-level CSS value scanners from the dedicated subpath so
105
+ presets can share token splitting without loading the rule-authoring entry:
106
+
107
+ ```ts
108
+ import {
109
+ findClosingParenthesis,
110
+ splitTopLevelCommas,
111
+ splitTopLevelWhitespace,
112
+ } from "@teacss/rule-helpers/css-syntax";
113
+ ```
114
+
115
+ Import complete CSS value grammar from its separate subpath:
116
+
117
+ ```ts
118
+ import {
119
+ inferNumericFunction,
120
+ isCssColorValue,
121
+ isCssEasingValue,
122
+ isCssLengthValue,
123
+ isCssTimeValue,
124
+ isValidDropShadowArgument,
125
+ } from "@teacss/rule-helpers/css-value-syntax";
126
+ ```
127
+
128
+ `css-syntax` contains lightweight top-level scanning and splitting primitives.
129
+ `css-value-syntax` contains complete validators and numeric type inference. Use
130
+ the dedicated grammar subpath when a consumer only needs value validation
131
+ without the root rule-authoring API. Resolvers that depend on the complete
132
+ grammar stay in `value-resolvers`, keeping the root rule-builder entry light.
133
+
134
+ ## Status
135
+
136
+ Pre-1.0. Helper behavior is kept framework-neutral and preset-oriented.
@@ -0,0 +1,14 @@
1
+ //#region src/constants.d.ts
2
+ declare const globalKeywords: readonly ["inherit", "initial", "revert", "revert-layer", "unset"];
3
+ declare const cssLengthUnits: readonly ["px", "pt", "pc", "in", "cm", "mm", "q", "rpx", "%", "em", "rem", "ex", "rex", "ch", "rch", "cap", "rcap", "ic", "ric", "lh", "rlh", "vw", "vh", "vi", "vb", "vmin", "vmax", "svw", "svh", "svi", "svb", "svmin", "svmax", "lvw", "lvh", "lvi", "lvb", "lvmin", "lvmax", "dvw", "dvh", "dvi", "dvb", "dvmin", "dvmax", "cqw", "cqh", "cqi", "cqb", "cqmin", "cqmax"];
4
+ /** CSS `<length>` units, excluding TeaCSS's spacing-only `rpx` and percentage. */
5
+ declare const cssLengthUnitRESource: string;
6
+ /** CSS `<length-percentage>` units from the same canonical unit list. */
7
+ declare const cssLengthPercentageUnitRESource: string;
8
+ /**
9
+ * CSS Color 4 `<named-color>` set (+ `transparent`), the single source of truth for recognizing a
10
+ * bare keyword as a color. Case-insensitive — compare against `value.toLowerCase()`.
11
+ */
12
+ declare const cssNamedColors: ReadonlySet<string>;
13
+ //#endregion
14
+ export { cssLengthPercentageUnitRESource, cssLengthUnitRESource, cssLengthUnits, cssNamedColors, globalKeywords };
@@ -0,0 +1 @@
1
+ const e=[`inherit`,`initial`,`revert`,`revert-layer`,`unset`],t=`px.pt.pc.in.cm.mm.q.rpx.%.em.rem.ex.rex.ch.rch.cap.rcap.ic.ric.lh.rlh.vw.vh.vi.vb.vmin.vmax.svw.svh.svi.svb.svmin.svmax.lvw.lvh.lvi.lvb.lvmin.lvmax.dvw.dvh.dvi.dvb.dvmin.dvmax.cqw.cqh.cqi.cqb.cqmin.cqmax`.split(`.`),n=`(?:${t.filter(e=>e!==`rpx`&&e!==`%`).join(`|`)})`,r=`(?:%|${t.filter(e=>e!==`rpx`&&e!==`%`).join(`|`)})`,i=new Set(`transparent.aliceblue.antiquewhite.aqua.aquamarine.azure.beige.bisque.black.blanchedalmond.blue.blueviolet.brown.burlywood.cadetblue.chartreuse.chocolate.coral.cornflowerblue.cornsilk.crimson.cyan.darkblue.darkcyan.darkgoldenrod.darkgray.darkgreen.darkgrey.darkkhaki.darkmagenta.darkolivegreen.darkorange.darkorchid.darkred.darksalmon.darkseagreen.darkslateblue.darkslategray.darkslategrey.darkturquoise.darkviolet.deeppink.deepskyblue.dimgray.dimgrey.dodgerblue.firebrick.floralwhite.forestgreen.fuchsia.gainsboro.ghostwhite.gold.goldenrod.gray.green.greenyellow.grey.honeydew.hotpink.indianred.indigo.ivory.khaki.lavender.lavenderblush.lawngreen.lemonchiffon.lightblue.lightcoral.lightcyan.lightgoldenrodyellow.lightgray.lightgreen.lightgrey.lightpink.lightsalmon.lightseagreen.lightskyblue.lightslategray.lightslategrey.lightsteelblue.lightyellow.lime.limegreen.linen.magenta.maroon.mediumaquamarine.mediumblue.mediumorchid.mediumpurple.mediumseagreen.mediumslateblue.mediumspringgreen.mediumturquoise.mediumvioletred.midnightblue.mintcream.mistyrose.moccasin.navajowhite.navy.oldlace.olive.olivedrab.orange.orangered.orchid.palegoldenrod.palegreen.paleturquoise.palevioletred.papayawhip.peachpuff.peru.pink.plum.powderblue.purple.rebeccapurple.red.rosybrown.royalblue.saddlebrown.salmon.sandybrown.seagreen.seashell.sienna.silver.skyblue.slateblue.slategray.slategrey.snow.springgreen.steelblue.tan.teal.thistle.tomato.turquoise.violet.wheat.white.whitesmoke.yellow.yellowgreen`.split(`.`));export{r as cssLengthPercentageUnitRESource,n as cssLengthUnitRESource,t as cssLengthUnits,i as cssNamedColors,e as globalKeywords};
@@ -0,0 +1,5 @@
1
+ function e(e){if(e==null)return!1;let t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function t(e){if(e==null)return!1;let t=e.charCodeAt(0);return t>=48&&t<=57}function n(e){if(e==null)return!1;let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function r(e){return e===` `||e===` `||e===`
2
+ `||e===`\r`||e===`\f`}function i(t){return t!=null&&(t===`_`||e(t)||t.charCodeAt(0)>=128)}function a(e){return e!=null&&(e===`-`||t(e)||i(e))}function o(e,t){let i=t+1;if(i>=e.length||e[i]===`
3
+ `||e[i]===`\r`||e[i]===`\f`)return;if(!n(e[i]))return i+1;let a=0;for(;i<e.length&&a<6&&n(e[i]);)i++,a++;return e[i]===`\r`&&e[i+1]===`
4
+ `?i+2:r(e[i])?i+1:i}function s(e,t){let n=t;for(;n<e.length;){if(a(e[n])){n++;continue}if(e[n]!==`\\`)break;let t=o(e,n);if(t==null)break;n=t}return n}function c(e,t=0){return i(e[t])?!0:e[t]===`\\`?o(e,t)!=null:e[t]===`-`?e[t+1]===`-`||i(e[t+1])||e[t+1]===`\\`&&o(e,t+1)!=null:!1}function l(e,t=0){if(c(e,t))return s(e,t)}function u(e){return l(e)===e.length}function d(e){let t=``;for(let i=0;i<e.length;){if(e[i]!==`\\`){t+=e[i],i++;continue}if(i++,i>=e.length)break;if(!n(e[i])){t+=e[i],i++;continue}let a=i;for(;i<e.length&&i-a<6&&n(e[i]);)i++;let o=Number.parseInt(e.slice(a,i),16);t+=o===0||o>1114111||o>=55296&&o<=57343?`�`:String.fromCodePoint(o),e[i]===`\r`&&e[i+1]===`
5
+ `?i+=2:r(e[i])&&i++}return t}export{u as a,r as c,d as i,l as n,a as o,s as r,i as s,o as t};
@@ -0,0 +1,16 @@
1
+ //#region src/css-syntax.d.ts
2
+ interface CssTokenSpan {
3
+ end: number;
4
+ start: number;
5
+ value: string;
6
+ }
7
+ declare function splitTopLevelDelimiter(value: string, delimiter: string): string[];
8
+ declare function splitTopLevelCommas(value: string): string[];
9
+ declare function splitTopLevelWhitespace(value: string): string[];
10
+ declare function topLevelWhitespaceSpans(value: string): CssTokenSpan[];
11
+ declare function findLastTopLevelDelimiter(value: string, delimiter: string): number;
12
+ declare function findFirstTopLevelDelimiter(value: string, delimiter: string): number;
13
+ declare function hasTopLevelDelimiter(value: string, delimiter: string): boolean;
14
+ declare function findClosingParenthesis(value: string, openIndex: number): number | undefined;
15
+ //#endregion
16
+ export { CssTokenSpan, findClosingParenthesis, findFirstTopLevelDelimiter, findLastTopLevelDelimiter, hasTopLevelDelimiter, splitTopLevelCommas, splitTopLevelDelimiter, splitTopLevelWhitespace, topLevelWhitespaceSpans };
@@ -0,0 +1 @@
1
+ import{c as e,t}from"./css-identifier-4yDg85cV.js";function n(e){return e===`(`?`)`:e===`[`?`]`:`}`}function r(e,t){let n=e.indexOf(`*/`,t+2);return n===-1?e.length:n+2}function i(e,i){let a=[],o;for(let s=0;s<e.length;s++){let c=e[s];if(o!=null){c===`\\`?s=(t(e,s)??s+2)-1:c===o&&(o=void 0);continue}if(c===`'`||c===`"`){o=c;continue}if(c===`\\`){s=(t(e,s)??s+2)-1;continue}if(c===`/`&&e[s+1]===`*`){s=r(e,s)-1;continue}if(c===`(`||c===`[`||c===`{`){a.push(n(c));continue}if(c===`)`||c===`]`||c===`}`){a.at(-1)===c&&a.pop();continue}if(a.length===0&&i(c,s))return s}}function a(e,t){let n=[],r=0;return i(e,(i,a)=>{i===t&&(n.push(e.slice(r,a).trim()),r=a+1)}),n.push(e.slice(r).trim()),n}function o(e){return a(e,`,`)}function s(e){let t=c(e),n=[];for(let e of t){let t=0;i(e.value,(r,i)=>{r===`/`&&(i>t&&n.push(e.value.slice(t,i)),n.push(`/`),t=i+1)}),t<e.value.length&&n.push(e.value.slice(t))}return n}function c(t){let n=[],r=0;i(t,(i,a)=>{if(!e(i))return;let o=[...t.slice(r,a)].findIndex(t=>!e(t));if(o>=0){let e=r+o;n.push({start:e,end:a,value:t.slice(e,a)})}r=a+1});let a=[...t.slice(r)].findIndex(t=>!e(t));if(a>=0){let e=r+a;n.push({start:e,end:t.length,value:t.slice(e)})}return n}function l(e,t){let n=-1;return i(e,(e,r)=>{e===t&&(n=r)}),n}function u(e,t){return i(e,e=>e===t)??-1}function d(e,t){return i(e,e=>e===t)!=null}function f(e,i){if(e[i]!==`(`)return;let a=[],o;for(let s=i;s<e.length;s++){let i=e[s];if(o!=null){i===`\\`?s=(t(e,s)??s+2)-1:i===o&&(o=void 0);continue}if(i===`'`||i===`"`){o=i;continue}if(i===`\\`){s=(t(e,s)??s+2)-1;continue}if(i===`/`&&e[s+1]===`*`){s=r(e,s)-1;continue}if(i===`(`||i===`[`||i===`{`){a.push(n(i));continue}if(i===`)`||i===`]`||i===`}`){if(a.at(-1)!==i)return;if(a.pop(),a.length===0)return s}}}export{f as findClosingParenthesis,u as findFirstTopLevelDelimiter,l as findLastTopLevelDelimiter,d as hasTopLevelDelimiter,o as splitTopLevelCommas,a as splitTopLevelDelimiter,s as splitTopLevelWhitespace,c as topLevelWhitespaceSpans};
@@ -0,0 +1 @@
1
+ import{cssLengthPercentageUnitRESource as e,cssLengthUnitRESource as t,cssNamedColors as n,globalKeywords as r}from"./constants.js";import{a as i,c as a,i as o,n as s,t as c}from"./css-identifier-4yDg85cV.js";import{findClosingParenthesis as l,splitTopLevelCommas as u,splitTopLevelDelimiter as d,splitTopLevelWhitespace as f}from"./css-syntax.js";const ee=new Set([`default`,...r]);function p(e){return e.includes(`\\`)&&i(e)?o(e).toLowerCase():e.toLowerCase()}function m(e){if(!i(e))return!1;let t=o(e);return t.startsWith(`--`)&&t.length>2}function h(e){return i(e)&&!ee.has(o(e).toLowerCase())}function g(e){if(!e.endsWith(`)`))return;let t=s(e);if(t==null||e[t]!==`(`)return;let n=l(e,t);if(n===e.length-1)return{name:o(e.slice(0,t)).toLowerCase(),args:e.slice(t+1,n).trim()}}function te(e){let t=g(e.trim());return t!=null&&(t.name===`var`||t.name===`env`)&&y(t.name,t.args)}function ne(e){let t=[],n=[],r=0;for(let i=0;i<e.length;){let a=e[i];if(a===`/`&&e[i+1]===`*`){let t=e.indexOf(`*/`,i+2);if(t<0)return;i=t+2;continue}if(a===`"`||a===`'`){let t=a;for(i++;i<e.length&&e[i]!==t;)i=e[i]===`\\`?c(e,i)??i+2:i+1;if(i>=e.length)return;i++;continue}let l=s(e,i);if(l!=null){if(e[l]!==`(`){i=l;continue}let n=o(e.slice(i,l)).toLowerCase(),a=n===`var`||n===`env`;t.push({start:i,open:l,close:`)`,name:n,activeSubstitution:a&&r===0}),a&&r++,i=l+1;continue}if(a===`\\`){i=c(e,i)??i+2;continue}if(a===`(`||a===`[`||a===`{`){t.push({start:i,open:i,close:a===`(`?`)`:a===`[`?`]`:`}`}),i++;continue}if(a===`,`){let e=t.at(-1);e!=null&&e.comma==null&&(e.comma=i),i++;continue}if(a===`)`||a===`]`||a===`}`){let o=t.pop();if(o==null||o.close!==a)return;if(o.name===`var`||o.name===`env`){r--;let t=e.slice(o.open+1,o.comma??i).trim();if(!v(o.name,t))return;if(o.activeSubstitution&&o.comma!=null){if(n.length>=63)return;n.push({start:o.start,end:i+1,fallback:e.slice(o.comma+1,i).trim()})}}i++;continue}i++}return t.length===0&&r===0?n:void 0}function _(e,t){let n=[e],r=new Set(n),i=new Set;for(;n.length>0;){let e=n.pop();if(r.delete(e),i.has(e))continue;if(i.size>=64||(i.add(e),!t(e)))return!1;let a=ne(e);if(a==null)return!1;for(let t of a){let a=e.slice(0,t.start)+t.fallback+e.slice(t.end);if(!(i.has(a)||r.has(a))){if(i.size+r.size>=64)return!1;n.push(a),r.add(a)}}}return!0}function v(e,t){if(e===`var`)return m(t);if(e!==`env`)return!1;let n=f(t);return n.length>0&&h(n[0])&&n.slice(1).every(e=>/^\+?\d+$/.test(e))}function y(e,t){return v(e,u(t)[0]??``)}function b(e){let t=u(e);if(t.length>2||!t[0])return!1;let n=f(t[0]);if(n.length!==1&&n.length!==2||!re(n[0]))return!1;if(n.length===1)return!0;let r=p(n[1]);if(r===`%`||r===`raw-string`||h(n[1]))return!0;let i=g(n[1]);return i?.name===`type`&&!!i.args}function re(e){let t=e.indexOf(`|`);return t<0?i(e):e.indexOf(`|`,t+1)<0&&(t===0||i(e.slice(0,t)))&&i(e.slice(t+1))}function x(e){let t=d(e,`;`);return t.at(-1)===``&&t.pop(),t.length>0&&t.every(e=>{let t=d(e,`:`);return t.length>=2&&!!t[0]})}function S(e,t){if(e.startsWith(`--`)&&e.length>2)return!t||u(t).every(Boolean);if(e===`if`)return!!t&&x(t);if(e===`inherit`){let e=u(t);return e.length<=2&&!!e[0]}if(e===`random-item`){let e=u(t);return e.length>=2&&!!e[0]}return!1}function C(e){let t=u(e);if(t.length<2||!t[0])return;let n=[],r=!1;for(let e of t.slice(1)){if(!e)return;let t=d(e,`:`);if(t.length<2){if(n.length===0||r)return;r=!0;continue}let i=t.slice(1).join(`:`).trim();if(!t[0]||!i)return;n.push(i),r=!1}return n.length>0&&!r?n:void 0}function ie(e,t=Boolean){let n=g(e.trim());if(n==null||!n.args)return!1;if(n.name===`first-valid`)return u(n.args).every(Boolean);if(n.name===`toggle`){let e=u(n.args);return e.every(Boolean)&&e.every(e=>!/(?:^|[^-\w])(?:attr|calc|toggle)\s*\(/i.test(e)&&t(e))}if(n.name!==`interpolate`)return!1;let r=C(n.args);if(r!=null)return r.every(t);let i=f(n.args),a=i.findIndex(e=>p(e)===`of`);return a>0&&a<i.length-1}const ae=new Set(`abs.acos.asin.atan.atan2.attr.calc.calc-interpolate.calc-mix.clamp.cos.env.exp.hypot.log.max.min.mod.pow.progress.random.rem.round.sibling-count.sibling-index.sign.sin.sqrt.tan.var`.split(`.`)),w=/^[+-]?(?:\d+|\d*\.\d+)(?:e[+-]?\d+)?$/i,T=/^\+?(?:\d+|\d*\.\d+)(?:e[+-]?\d+)?$/i,E=/^[+-]?(?:\d+|\d*\.\d+)(?:e[+-]?\d+)?%$/i,D=/^[+-]?(?:\d+|\d*\.\d+)(?:e[+-]?\d+)?(?:deg|grad|rad|turn)$/i,O=RegExp(`^[+-]?(?:\\d+|\\d*\\.\\d+)(?:e[+-]?\\d+)?${e}$`,`i`),oe=RegExp(`^([+-]?(?:\\d+|\\d*\\.\\d+)(?:e[+-]?\\d+)?)(${e})?$`,`i`),k=RegExp(`^\\+?(?:\\d+|\\d*\\.\\d+)(?:e[+-]?\\d+)?${e}$`,`i`),se=RegExp(`^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)${e}$`,`i`);function A(e){let t=e.trim();return(w.test(t)||O.test(t))&&Number.parseFloat(t)<0}function ce(e){return f(e).some(A)}const le=new Set([`deg`,`grad`,`rad`,`turn`]),ue=new Set([`fr`]),de=new Set([`hz`,`khz`]),fe=new Set([`dpcm`,`dpi`,`dppx`,`x`]),pe=new Set([`ms`,`s`]),me=new Set([`e`,`infinity`,`-infinity`,`nan`,`pi`]),he=RegExp(`^${t}$`,`i`);function j(e){if(le.has(e))return`angle`;if(ue.has(e))return`flex`;if(de.has(e))return`frequency`;if(fe.has(e))return`resolution`;if(pe.has(e))return`time`;if(he.test(e))return`length`}function M(e,t,n=!1){if(e===`unknown`)return t;if(t===`unknown`)return e;if(n&&(e===`length`&&t===`percentage`||e===`percentage`&&t===`length`))return`length-percentage`;if(n&&e===`length-percentage`&&(t===`length`||t===`percentage`))return e;if(n&&t===`length-percentage`&&(e===`length`||e===`percentage`))return t;if(typeof e==`string`||typeof t==`string`)return e===t?e:void 0;let r=new Set([...Object.keys(e.exponents),...Object.keys(t.exponents)]);return e.percentHint===t.percentHint&&[...r].every(n=>(e.exponents[n]??0)===(t.exponents[n]??0))?e:void 0}function N(e,t){return typeof e!=`string`||e===`unknown`?typeof e==`string`?void 0:e:e===`number`?{exponents:{}}:e===`length-percentage`?{exponents:{length:1},percentHint:`length`}:e===`percentage`?t?{exponents:{length:1},percentHint:`length`}:{exponents:{percent:1},percentHint:`percent`}:{exponents:{[e]:1}}}function P(e){let t=Object.fromEntries(Object.entries(e.exponents).filter(([,e])=>e!==0)),n=Object.entries(t);return n.length===0?`number`:n.length===1&&n[0][1]===1?n[0][0]===`percent`?`percentage`:n[0][0]===`length`?e.percentHint===`length`?`length-percentage`:`length`:n[0][0]:{exponents:t,percentHint:e.percentHint}}function F(e,t){return e==null?t:t==null||e===t?e:`conflict`}function I(e,t,n){if(e===`unknown`||t===`unknown`)return`unknown`;let r=N(e,n),i=N(t,n);if(r==null||i==null)return;let a={...r.exponents};for(let[e,t]of Object.entries(i.exponents))a[e]=(a[e]??0)+t;return P({exponents:a,percentHint:F(r.percentHint,i.percentHint)})}function L(e,t,n){if(e===`unknown`||t===`unknown`)return`unknown`;let r=N(e,n),i=N(t,n);if(r==null||i==null)return;let a={...r.exponents};for(let[e,t]of Object.entries(i.exponents))a[e]=(a[e]??0)-t;return P({exponents:a,percentHint:F(r.percentHint,i.percentHint)})}function R(e,t=!1){if(e.length!==0)return e.reduce((e,n)=>e==null?void 0:M(e,n,t),e[0])}function ge(e){let t=e.filter(e=>e!==`unknown`);return t.length===0?e.length>0?`unknown`:void 0:t.slice(1).reduce((e,t)=>e==null?void 0:M(e,t),t[0])}function _e(e){if(!b(e))return;let t=f(u(e)[0]);if(t.length===1)return`unknown`;let n=t[1],r=p(n);if(r===`number`)return`number`;if(r===`%`)return`percentage`;let i=j(r);if(i!=null)return i;let a=g(n);if(a?.name!==`type`)return`unknown`;let o=a.args.replace(/\s+/g,``).toLowerCase();return o===`<number>`||o===`<integer>`?`number`:o===`<percentage>`?`percentage`:/^<(?:angle|flex|frequency|length|resolution|time)>$/.test(o)?o.slice(1,-1):o===`<length-percentage>`?`length-percentage`:`unknown`}function z(e,t,n,r=!1){let i=0,o=()=>{for(;a(e[i]);)i++},c=()=>{if(o(),e[i]===`(`){i++;let t=d();return o(),t==null||e[i]!==`)`?void 0:(i++,t)}let a=e.slice(i).match(/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i)?.[0];if(a!=null){if(i+=a.length,e[i]===`%`)return i++,`percentage`;let t=s(e.slice(i));if(t!=null){let n=p(e.slice(i,i+t));return i+=t,j(n)}return`number`}let c=s(e.slice(i));if(c==null)return;let u=e.slice(i,i+c),f=p(u);if(i+=c,e[i]===`(`){let a=l(e,i);if(a==null)return;let o=e.slice(i+1,a).trim();return i=a+1,B(f,o,t,n,r)}if(me.has(f)||t.has(f)||n&&h(u))return`number`},u=()=>{let t=c();if(t!=null)for(;;){let n=i;o();let a=e[i];if(a!==`*`&&a!==`/`)return i=n,t;i++;let s=c();if(s==null||(t=a===`*`?I(t,s,r):L(t,s,r),t==null))return}},d=()=>{let t=u();if(t!=null)for(;;){let n=i;o();let a=i>n,s=e[i];if(s!==`+`&&s!==`-`)return t;if(!a)return;i++;let c=i;if(o(),i===c)return;let l=u();if(l==null||(t=M(t,l,r),t==null))return}},f=d();return o(),f!=null&&i===e.length?f:void 0}function B(e,t,n,r=!1,i=!1){if(e===`sibling-count`||e===`sibling-index`)return t?void 0:`number`;if(S(e,t))return`unknown`;if(!t)return;if(e===`var`||e===`env`)return y(e,t)?`unknown`:void 0;if(e===`attr`)return _e(t);if(!ae.has(e))return;let a=u(t),o=e=>{if(e.some(e=>!e))return;let t=e.map(e=>z(e,n,r,i));return t.some(e=>e==null)?void 0:t};if(e===`calc`)return a.length===1?z(t,n,r,i):void 0;if(e===`progress`){if(a.length!==3)return;let e=[...a],t=f(e[0]);p(t[0]??``)===`no-clamp`&&(e[0]=e[0].slice(t[0].length).trim());let n=o(e);return n!=null&&R(n,i)!=null?`number`:void 0}if(e===`calc-mix`){let e=a.map(e=>{let t=z(e,n,r,i);if(t!=null)return t;let a=f(e),o=a.at(-1);if(o==null||a.length<2)return;let s=z(o,n,r,!1);if(E.test(o)){let e=Number(o.slice(0,-1));if(e<0||e>100)return}else if(s!==`percentage`&&s!==`unknown`)return;return z(e.slice(0,e.length-o.length).trim(),n,r,i)});return e.some(e=>e==null)?void 0:R(e,i)}if(e===`calc-interpolate`){let e=C(t),n=e==null?void 0:o(e);return n==null?void 0:R(n,i)}if(e===`random`){if(a.length<2||a.length>4)return;let e=e=>{let t=g(e);if(t!=null&&(t.name===`var`||t.name===`env`))return y(t.name,t.args);let i=f(e);if(i.length===1&&p(i[0])===`auto`)return!0;if(p(i[0]??``)===`fixed`){if(i.length!==2)return!1;if(w.test(i[1]))return Number(i[1])>=0&&Number(i[1])<=1;let e=z(i[1],n,r,!1);return e===`number`||e===`unknown`}let a=!1,o=!1,s=!1;for(let e of i){let t=p(e);if(m(e)&&!a)a=!0;else if(t===`element-scoped`&&!o)o=!0;else if((t===`property-scoped`||t===`property-index-scoped`||h(e)&&t.startsWith(`ua-`))&&!s)s=!0;else return!1}return i.length>0},t=a,s=z(a[0],n,r,i);if(a.length===4||a.length===3&&s==null&&e(a[0])){if(!e(a[0]))return;t=a.slice(1)}let c=o(t);return c!=null&&(c.length===2||c.length===3)?R(c,i):void 0}if(e===`min`||e===`max`||e===`hypot`){let e=o(a);return e==null?void 0:R(e,i)}if(e===`clamp`){if(a.length!==3||p(a[1])===`none`)return;let e=o(a.filter((e,t)=>t===1||p(e)!==`none`));return e==null?void 0:R(e,i)}if(e===`round`){let e=[...a];/^(?:down|nearest|to-zero|up)$/.test(p(e[0]??``))&&e.shift();let t=e.length>=1&&e.length<=2?o(e):void 0;return t==null?void 0:R(t,i)}let s=o(a);if(s!=null){if(e===`sin`||e===`cos`||e===`tan`)return s.length===1&&(s[0]===`number`||s[0]===`angle`||s[0]===`unknown`)?`number`:void 0;if(e===`asin`||e===`acos`||e===`atan`)return s.length===1&&(s[0]===`number`||s[0]===`unknown`)?`angle`:void 0;if(e===`atan2`)return s.length===2&&ge(s)!=null?`angle`:void 0;if(e===`pow`)return s.length===2&&s.every(e=>e===`number`||e===`unknown`)?`number`:void 0;if(e===`sqrt`||e===`exp`)return s.length===1&&(s[0]===`number`||s[0]===`unknown`)?`number`:void 0;if(e===`log`)return(s.length===1||s.length===2)&&s.every(e=>e===`number`||e===`unknown`)?`number`:void 0;if(e===`abs`)return s.length===1?s[0]:void 0;if(e===`sign`)return s.length===1?`number`:void 0;if(e===`mod`||e===`rem`)return s.length===2?R(s,i):void 0}}function V(e,t,n=!1,r=!1){let i=g(e);return i==null?void 0:B(i.name,i.args,t,n,r)}function H(e){if(D.test(e))return!0;let t=V(e,new Set);return t===`angle`||t===`unknown`}function ve(e){return w.test(e)&&Number(e)===0||H(e)}function ye(e){if(w.test(e)||E.test(e))return!0;let t=V(e,new Set);return t===`number`||t===`percentage`||t===`unknown`}function U(e){if(w.test(e))return Number(e)===0;if(O.test(e))return!e.endsWith(`%`);let t=V(e,new Set);return t===`length`||t===`unknown`}function be(e){if(w.test(e))return Number(e)===0;if(O.test(e))return!0;let t=V(e,new Set,!1,!0);return t===`length`||t===`percentage`||t===`length-percentage`||t===`unknown`}function xe(e){if(A(e))return!1;if(k.test(e))return!0;if(T.test(e))return Number(e)===0;let t=V(e,new Set,!1,!0);return t===`length`||t===`percentage`||t===`length-percentage`||t===`unknown`}const Se=new Set([`alpha`,`color`,`color-hdr`,`color-interpolate`,`color-layers`,`color-mix`,`contrast-color`,`device-cmyk`,`hsl`,`hsla`,`hwb`,`ictcp`,`jzazbz`,`jzczhz`,`lab`,`lch`,`light-dark`,`oklab`,`oklch`,`rgb`,`rgba`,`var`,`env`]),Ce=new Set([`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`]),we=new Set([`accentcolor`,`accentcolortext`,`activetext`,`buttonborder`,`buttonface`,`buttontext`,`canvas`,`canvastext`,`field`,`fieldtext`,`graytext`,`highlight`,`highlighttext`,`linktext`,`mark`,`marktext`,`selecteditem`,`selecteditemtext`,`visitedtext`]),Te=new Set([`a98-rgb`,`display-p3`,`display-p3-linear`,`prophoto-rgb`,`rec2020`,`rec2100-hlg`,`rec2100-linear`,`rec2100-pq`,`srgb`,`srgb-linear`,`xyz`,`xyz-d50`,`xyz-d65`]),Ee=new Set([`a98-rgb`,`display-p3`,`display-p3-linear`,`hsl`,`hwb`,`lab`,`lch`,`oklab`,`oklch`,`prophoto-rgb`,`rec2020`,`srgb`,`srgb-linear`,`xyz`,`xyz-d50`,`xyz-d65`]),De=/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i;function W(e,t=new Set,n=!1,r=!0,i=!1){let a=p(e);if(r&&a===`none`||t.has(a)||w.test(e)||E.test(e)||n&&D.test(e))return!0;let o=V(e,t,i);return o===`unknown`||o===`number`||o===`percentage`||n&&o===`angle`}function G(e,t=new Set,n=!0){let r=p(e);if(n&&r===`none`||t.has(r)||w.test(e)||D.test(e))return!0;let i=V(e,t);return i===`unknown`||i===`number`||i===`angle`}function K(e){let t=f(e),n=t.indexOf(`/`);if(n<0)return{channels:t};if(t.lastIndexOf(`/`)===n&&n!==0&&n===t.length-2)return{channels:t.slice(0,n),alpha:t[n+1]}}function Oe(e,t){let n=u(t),r=e===`device-cmyk`;if(!r&&n.length!==3&&n.length!==4||r&&n.length!==4)return!1;let i=e=>{if(w.test(e))return!0;let t=V(e,new Set);return t===`number`||t===`unknown`},a=e=>{if(E.test(e))return!0;let t=V(e,new Set);return t===`percentage`||t===`unknown`};if(r)return n.every(i);let o=n[3];if(o!=null&&!W(o,new Set,!1,!1))return!1;if(e===`hsl`||e===`hsla`)return G(n[0],new Set,!1)&&a(n[1])&&a(n[2]);let s=n.slice(0,3);return s.every(i)||s.every(a)}const ke={rgb:new Set([`alpha`,`b`,`g`,`r`]),rgba:new Set([`alpha`,`b`,`g`,`r`]),hsl:new Set([`alpha`,`h`,`l`,`s`]),hsla:new Set([`alpha`,`h`,`l`,`s`]),hwb:new Set([`alpha`,`b`,`h`,`w`]),lab:new Set([`a`,`alpha`,`b`,`l`]),lch:new Set([`alpha`,`c`,`h`,`l`]),oklab:new Set([`a`,`alpha`,`b`,`l`]),oklch:new Set([`alpha`,`c`,`h`,`l`]),ictcp:new Set([`alpha`,`ct`,`cp`,`i`]),jzazbz:new Set([`a`,`alpha`,`b`,`j`]),jzczhz:new Set([`alpha`,`c`,`h`,`j`]),"device-cmyk":new Set([`alpha`,`c`,`k`,`m`,`y`])},Ae=new Set([`rgb`,`rgba`,`hsl`,`hsla`,`device-cmyk`]),je=new Set([`hsl`,`hwb`,`lch`,`oklch`,`jzczhz`]);function Me(e){let t=f(e);if(p(t[0]??``)!==`in`||t.length<2)return!1;let n=p(t[1]);return!Ee.has(n)&&!m(t[1])?!1:t.length===2||t.length===4&&je.has(n)&&/^(?:shorter|longer|increasing|decreasing)$/.test(p(t[2]))&&p(t[3])===`hue`}function q(e){if(E.test(e)){let t=Number(e.slice(0,-1));return t>=0&&t<=100}let t=V(e,new Set);return t===`percentage`||t===`unknown`}function Ne(e,t){if(u(t).length>1)return Ae.has(e)&&Oe(e,t);let n=f(t),r=p(n[0]??``)===`from`;if(r&&e===`device-cmyk`||r&&(n.length<2||!X(n[1])))return!1;let i=K(n.slice(r?2:0).join(` `));if(!i)return!1;let a=e===`device-cmyk`?4:3,o=e===`hsl`||e===`hsla`||e===`hwb`?0:e===`lch`||e===`oklch`||e===`jzczhz`?2:-1,s=r?ke[e]:new Set;return i.channels.length===a&&i.channels.every((e,t)=>t===o?G(e,s):W(e,s))&&(i.alpha==null||W(i.alpha,s))}function Pe(e){let t=u(e);if(t.some(e=>!e))return!1;let n=0;if(p(f(t[0])[0]??``)===`in`){if(!Me(t[0]))return!1;n=1}return n>=t.length?!1:t.slice(n).every(e=>{let t=f(e);return t.length===1?X(t[0]):t.length===2?X(t[0])&&q(t[1])||q(t[0])&&X(t[1]):!1})}function Fe(e){let t=u(e);if(t.some(e=>!e))return!1;let n=Ce.has(p(t[0]??``))?t.slice(1):t;return n.length>=2&&n.every(e=>X(e))}function J(e){if(w.test(e)){let t=Number(e);return t>=0?{literal:t}:void 0}let t=V(e,new Set);return t===`number`||t===`unknown`?{}:void 0}function Y(e){let t=f(e);if(t.length===1)return X(t[0])?[{}]:[];if(t.length!==2)return[];let n=[],r=J(t[1]);X(t[0])&&r!=null&&n.push(r);let i=J(t[0]);return i!=null&&X(t[1])&&n.push(i),n}function Ie(e){let{args:t,name:n}=e;if(S(n,t))return!0;if(!t||!Se.has(n))return!1;if(n===`var`||n===`env`)return y(n,t);if(n===`color-interpolate`)return C(t)?.every(e=>X(e))??!1;if(n===`color-layers`)return Fe(t);if(n===`color-mix`)return Pe(t);if(n===`light-dark`){let e=u(t);return e.length===2&&e.every(e=>X(e))}if(n===`contrast-color`)return u(t).length===1&&X(t);if(n===`color-hdr`){let e=u(t);if(e.length!==2)return!1;let n=Y(e[0]),r=Y(e[1]);return n.some(e=>r.some(t=>e.literal==null||t.literal==null||e.literal!==t.literal))}if(n===`alpha`){let e=f(t);if(p(e[0]??``)!==`from`||e.length<2||!X(e[1]))return!1;let n=e.slice(2);return n.length===0||n.length===2&&n[0]===`/`&&W(n[1],new Set([`alpha`]))}if(n===`color`){let e=f(t),n=p(e[0]??``)===`from`;if(n&&(e.length<3||!X(e[1])))return!1;let r=K(e.slice(n?2:0).join(` `));if(!r||r.channels.length<2)return!1;let a=r.channels[0],o=p(a);if(!Te.has(o)&&!m(a))return!1;let s=r.channels.slice(1),c=m(a),l=c?s.length:3,u=n?o===`xyz`||o===`xyz-d50`||o===`xyz-d65`?new Set([`alpha`,`x`,`y`,`z`]):c?new Set([`alpha`]):new Set([`alpha`,`b`,`g`,`r`]):new Set;return s.length===l&&s.every(e=>W(e,u,!1,!0,n&&c)||n&&c&&i(e))&&(r.alpha==null||W(r.alpha,u))}return Ne(n,t)}function X(e){let t=e.trim(),r=p(t);if(!t)return!1;if(t.startsWith(`#`))return De.test(t);if(r===`currentcolor`||n.has(r)||we.has(r))return!0;let i=g(t);return i?.name===`attr`?b(i.args):i!=null&&Ie(i)}const Le=RegExp(`^([+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:e[+-]?\\d+)?)${t}$`,`i`);function Re(e){let t=e.match(Le);return t!=null&&Number(t[1])<0}function ze(e){if(u(e).length!==1)return;let t=f(e);return t.length>0?t:void 0}function Be(e){let t=U(e),n=X(e);if(t&&n)return{kind:`unknown`};if(t)return{kind:`length`,negative:Re(e)};if(n)return{kind:`color`}}function Ve(e){let t=new Set([0]);for(let n of e){let e=new Set;for(let r of t){let t=r>>1,i=r&1;if(n.kind===`length`){t<3&&!(t===2&&n.negative)&&e.add(t+1<<1|i);continue}if(n.kind===`color`){i===0&&e.add(r|1);continue}for(let n=t;n<=3;n++){let t=n<<1|i;e.add(t),i===0&&e.add(t|1)}}if(e.size===0)return!1;t=e}for(let e of t)if(e>>1>=2)return!0;return!1}function He(e){let t=ze(e.trim());if(t==null||t.some(e=>/^(?:inset|none)$/i.test(e)))return!1;let n=t.map(Be);return n.length===1&&n[0]?.kind===`unknown`||n.every(e=>e!=null)&&Ve(n)}function Ue(e){return/^(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')$/.test(e)}const Z=new Set([`linear`,`ease`,`ease-in`,`ease-out`,`ease-in-out`,`step-start`,`step-end`]);function We(e){if(/^[+-]?(?:\d+|\d*\.\d+)(?:e[+-]?\d+)?(?:ms|s)$/i.test(e))return!0;let t=V(e,new Set);return t===`time`||t===`unknown`}function Q(e){if(w.test(e))return!0;let t=V(e,new Set);return t===`number`||t===`unknown`}function Ge(e){if(E.test(e))return!0;let t=V(e,new Set);return t===`percentage`||t===`unknown`}function $(e,t){let n=`${t}(`;return e.startsWith(n)&&e.endsWith(`)`)?e.slice(n.length,-1):void 0}function Ke(e){let t=$(e,`cubic-bezier`);if(t==null)return!1;let n=u(t);return n.length!==4||n.some(e=>!Q(e))?!1:[n[0],n[2]].every(e=>!w.test(e)||Number(e)>=0&&Number(e)<=1)}function qe(e){let t=$(e,`steps`);if(t==null)return!1;let n=u(t);if(n.length<1||n.length>2)return!1;let r=n[0],i=n[1]??`end`;if(!new Set([`jump-start`,`jump-end`,`jump-none`,`jump-both`,`start`,`end`]).has(i))return!1;if(w.test(r))return Number.isInteger(Number(r))&&Number(r)>=(i===`jump-none`?2:1);let a=V(r,new Set);return a===`number`||a===`unknown`}function Je(e){let t=$(e,`linear`);if(t==null)return!1;let n=u(t);return n.length>0&&n.every(e=>{let t=f(e);return t.length>=1&&t.length<=3&&Q(t[0])&&t.slice(1).every(Ge)})}function Ye(e){let t=u(e);return t.length>0&&t.every(e=>Z.has(e)||Ke(e)||qe(e)||Je(e)||V(e,new Set)===`unknown`)}export{te as C,_ as S,p as T,A as _,X as a,T as b,w as c,V as d,ve as f,ye as g,U as h,He as i,E as l,be as m,We as n,O as o,H as p,Ue as r,oe as s,Ye as t,ce as u,xe as v,ie as w,se as x,k as y};
@@ -0,0 +1,62 @@
1
+ import { splitTopLevelCommas, splitTopLevelWhitespace } from "./css-syntax.js";
2
+ //#region src/css-color-syntax.d.ts
3
+ /** True for a complete standard CSS <color> value or an unresolved substitution. */
4
+ declare function isCssColorValue(value: string): boolean;
5
+ //#endregion
6
+ //#region src/css-drop-shadow-syntax.d.ts
7
+ /** Validate the decoded argument of Filter Effects 1 `drop-shadow()`. */
8
+ declare function isValidDropShadowArgument(value: string): boolean;
9
+ //#endregion
10
+ //#region src/css-numeric-syntax.d.ts
11
+ declare const cssNumberRe: RegExp;
12
+ declare const nonnegativeCssNumberRe: RegExp;
13
+ declare const cssPercentageRe: RegExp;
14
+ declare const cssLengthPercentageRe: RegExp;
15
+ declare const cssLengthPercentageWithOptionalUnitRe: RegExp;
16
+ declare const nonnegativeCssLengthPercentageRe: RegExp;
17
+ declare const simpleCssLengthPercentageRe: RegExp;
18
+ /** True only for an explicit negative numeric literal; math functions keep CSS's computed-value clamping behavior. */
19
+ declare function isNegativeNumericLiteral(value: string): boolean;
20
+ declare function hasDefiniteNegativeComponent(value: string): boolean;
21
+ type CssBaseDimension = "angle" | "flex" | "frequency" | "length" | "resolution" | "time";
22
+ interface CssNumericDimension {
23
+ exponents: Partial<Record<CssBaseDimension | "percent", number>>;
24
+ percentHint?: "conflict" | "length" | "percent";
25
+ }
26
+ type CssNumericType = CssBaseDimension | "length-percentage" | "number" | "percentage" | "unknown" | CssNumericDimension;
27
+ declare function inferNumericFunction(value: string, allowedIdents: ReadonlySet<string>, allowAnyIdentifier?: boolean, allowLengthPercentage?: boolean): CssNumericType | undefined;
28
+ /** True when a value is a typed CSS angle or a substitution whose type is resolved later. */
29
+ declare function isCssAngleValue(value: string): boolean;
30
+ /** True for a CSS angle, unitless zero, or a substitution whose type is resolved later. */
31
+ declare function isCssAngleOrZeroValue(value: string): boolean;
32
+ /** True for a single CSS number/percentage or a substitution whose type is resolved later. */
33
+ declare function isCssNumberOrPercentageValue(value: string): boolean;
34
+ /** True for a single CSS length, unitless zero, or a substitution whose type is resolved later. */
35
+ declare function isCssLengthValue(value: string): boolean;
36
+ /** True for a single CSS length-percentage, unitless zero, or a substitution whose type is resolved later. */
37
+ declare function isCssLengthPercentageValue(value: string): boolean;
38
+ /** True for a nonnegative CSS length-percentage, unitless zero, or a substitution resolved later. */
39
+ declare function isNonnegativeCssLengthPercentageValue(value: string): boolean;
40
+ //#endregion
41
+ //#region src/css-string-syntax.d.ts
42
+ declare function isCssString(value: string): boolean;
43
+ //#endregion
44
+ //#region src/css-substitution-syntax.d.ts
45
+ /** True when a complete value is a syntactically valid unresolved var() or env() substitution. */
46
+ declare function isCssVariableSubstitutionValue(value: string): boolean;
47
+ /**
48
+ * Validate the unresolved value and every complete value reachable by taking
49
+ * an explicit var() / env() fallback.
50
+ */
51
+ declare function areCssSubstitutionFallbacksValid(value: string, validateValue: (candidate: string) => boolean): boolean;
52
+ /** True for a syntactically valid CSS Values 5 function that must occupy the entire property value. */
53
+ declare function isCssWholeValueFunction(value: string, validateCandidate?: (candidate: string) => boolean): boolean;
54
+ //#endregion
55
+ //#region src/css-timing-syntax.d.ts
56
+ declare function isCssTimeValue(value: string): boolean;
57
+ declare function isCssEasingValue(value: string): boolean;
58
+ //#endregion
59
+ //#region src/css-value-tokenizer.d.ts
60
+ declare function normalizedCssIdentifier(value: string): string;
61
+ //#endregion
62
+ export { areCssSubstitutionFallbacksValid, cssLengthPercentageRe, cssLengthPercentageWithOptionalUnitRe, cssNumberRe, cssPercentageRe, hasDefiniteNegativeComponent, inferNumericFunction, isCssAngleOrZeroValue, isCssAngleValue, isCssColorValue, isCssEasingValue, isCssLengthPercentageValue, isCssLengthValue, isCssNumberOrPercentageValue, isCssString, isCssTimeValue, isCssVariableSubstitutionValue, isCssWholeValueFunction, isNegativeNumericLiteral, isNonnegativeCssLengthPercentageValue, isValidDropShadowArgument, nonnegativeCssLengthPercentageRe, nonnegativeCssNumberRe, normalizedCssIdentifier, simpleCssLengthPercentageRe, splitTopLevelCommas, splitTopLevelWhitespace };
@@ -0,0 +1 @@
1
+ import{splitTopLevelCommas as e,splitTopLevelWhitespace as t}from"./css-syntax.js";import{C as n,S as r,T as i,_ as a,a as o,b as s,c,d as l,f as u,g as d,h as f,i as p,l as m,m as h,n as g,o as _,p as v,r as y,s as b,t as x,u as S,v as C,w,x as T,y as E}from"./css-value-syntax-CMg4Dex-.js";export{r as areCssSubstitutionFallbacksValid,_ as cssLengthPercentageRe,b as cssLengthPercentageWithOptionalUnitRe,c as cssNumberRe,m as cssPercentageRe,S as hasDefiniteNegativeComponent,l as inferNumericFunction,u as isCssAngleOrZeroValue,v as isCssAngleValue,o as isCssColorValue,x as isCssEasingValue,h as isCssLengthPercentageValue,f as isCssLengthValue,d as isCssNumberOrPercentageValue,y as isCssString,g as isCssTimeValue,n as isCssVariableSubstitutionValue,w as isCssWholeValueFunction,a as isNegativeNumericLiteral,C as isNonnegativeCssLengthPercentageValue,p as isValidDropShadowArgument,E as nonnegativeCssLengthPercentageRe,s as nonnegativeCssNumberRe,i as normalizedCssIdentifier,T as simpleCssLengthPercentageRe,e as splitTopLevelCommas,t as splitTopLevelWhitespace};
@@ -0,0 +1,283 @@
1
+ import { cssLengthPercentageUnitRESource, cssLengthUnitRESource, cssLengthUnits, cssNamedColors, globalKeywords } from "./constants.js";
2
+ import { CSSValueInput, DynamicRule, Rule, RuleMeta, StaticRule } from "@teacss/core";
3
+ //#region src/arbitrary-value.d.ts
4
+ declare function isBareDashedIdentifier(value: string): boolean;
5
+ /** Decode a TeaCSS arbitrary value using the same rules as `h.bracket`. */
6
+ declare function decodeArbitraryValue(value: string): string | undefined;
7
+ //#endregion
8
+ //#region src/breakpoint-range.d.ts
9
+ declare function calcMaxWidthBySize(size: string): string;
10
+ //#endregion
11
+ //#region src/colors.d.ts
12
+ interface CSSColorValue {
13
+ type: string;
14
+ components: (string | number)[];
15
+ alpha: string | number | undefined;
16
+ }
17
+ type RGBAColorValue = [number, number, number, number] | [number, number, number];
18
+ declare const cssColorFunctions: string[];
19
+ declare const rectangularColorSpace: string[];
20
+ declare const polarColorSpace: string[];
21
+ declare const hueInterpolationMethods: string[];
22
+ declare const alphaPlaceholders: string[];
23
+ declare const alphaPlaceholdersRE: RegExp;
24
+ declare function isInterpolatedMethod(type?: string): boolean;
25
+ declare function hex2rgba(hex?: string): RGBAColorValue | undefined;
26
+ declare function parseCssColor(str?: string): CSSColorValue | undefined;
27
+ declare function colorOpacityToString(color: CSSColorValue): string | number;
28
+ declare function colorToString(color: CSSColorValue | string, alphaOverride?: string | number): string;
29
+ //#endregion
30
+ //#region src/css-custom-property.d.ts
31
+ type CSSCustomPropertyName = `--${string}`;
32
+ interface DefinePropertyOptions {
33
+ syntax?: string;
34
+ inherits?: boolean;
35
+ initialValue?: string | number;
36
+ }
37
+ declare function defineProperty(property: CSSCustomPropertyName, options?: DefinePropertyOptions): CSSValueInput;
38
+ //#endregion
39
+ //#region src/css-identifier.d.ts
40
+ declare function isCssWhitespace(character: string | undefined): boolean;
41
+ declare function isCssNameStartCharacter(character: string | undefined): boolean;
42
+ declare function isCssNameCharacter(character: string | undefined): boolean;
43
+ declare function consumeCssEscape(value: string, start: number): number | undefined;
44
+ declare function consumeCssName(value: string, start: number): number;
45
+ declare function consumeCssIdentifier(value: string, index?: number): number | undefined;
46
+ declare function isCssIdentifier(value: string): boolean;
47
+ /** Decode CSS identifier escapes so equivalent spellings share one identity. */
48
+ declare function decodeCssIdentifier(value: string): string;
49
+ //#endregion
50
+ //#region src/css-value-patterns.d.ts
51
+ declare const numberWithUnitRE: RegExp;
52
+ declare const numberRE: RegExp;
53
+ declare const angleRE: RegExp;
54
+ declare const percentRE: RegExp;
55
+ declare const lengthRE: RegExp;
56
+ declare const unitOnlyMap: Record<string, number>;
57
+ declare const unitOnlyRE: RegExp;
58
+ declare const bracketTypeRe: RegExp;
59
+ //#endregion
60
+ //#region src/directive-functions.d.ts
61
+ declare function hasThemeFn(str: string): boolean;
62
+ declare function hasIconFn(str: string): boolean;
63
+ declare function transformThemeFn(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string;
64
+ declare function transformThemeString(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string | undefined;
65
+ //#endregion
66
+ //#region src/dynamic-rule-builders.d.ts
67
+ type RuleAutocomplete = NonNullable<RuleMeta["autocomplete"]>;
68
+ /** Create a dynamic fallback whose first capture accepts TeaCSS bracket values and CSS variables. */
69
+ declare function makeArbitraryValueRule<Theme extends object = object>(matcher: RegExp, property: string, autocomplete: RuleAutocomplete): DynamicRule<Theme>;
70
+ /** Create a dynamic fallback whose first capture also accepts CSS-wide global keywords. */
71
+ declare function makeGlobalValueRule<Theme extends object = object>(matcher: RegExp, property: string, autocomplete: RuleAutocomplete): DynamicRule<Theme>;
72
+ //#endregion
73
+ //#region src/static-rule-builders.d.ts
74
+ type StaticRuleName = readonly string[];
75
+ type StaticRuleValue = string | number;
76
+ type StaticRuleProperty = string;
77
+ type StaticRuleBody = StaticRule[1];
78
+ type StaticRuleValueMapEntry = StaticRuleValue | StaticRuleBody;
79
+ type StaticRuleValueMapStore = Readonly<Record<string, StaticRuleValueMapEntry>> | ReadonlyMap<string, StaticRuleValueMapEntry>;
80
+ type StaticRuleValueMapResolver = (value: string) => StaticRuleValueMapEntry | undefined;
81
+ type StaticRuleValueMap = StaticRuleValueMapStore | StaticRuleValueMapResolver;
82
+ type ShorthandRuleNames = string | readonly string[];
83
+ type ShorthandRuleValue = string | number | undefined;
84
+ interface StaticRuleOptions {
85
+ property?: StaticRuleProperty;
86
+ valueMap?: StaticRuleValueMap;
87
+ meta?: RuleMeta;
88
+ /** Extra values to skip in `false` bare mode (global keywords are always skipped). E.g. `["none"]` for display. */
89
+ bareExclude?: readonly StaticRuleValue[];
90
+ }
91
+ /** A class prefix, or `false` to also emit each value as a bare class (`flex` → `display:flex`). */
92
+ type StaticRulePrefix = string | false;
93
+ /** One prefix, or several. The first string prefix is primary and supplies the default CSS property. */
94
+ type StaticRuleNames = StaticRulePrefix | readonly StaticRulePrefix[];
95
+ interface ShorthandRuleOptions extends Omit<RuleMeta, "layer"> {
96
+ /** CSS property to emit. Defaults to the first shorthand name. */
97
+ property?: StaticRuleProperty;
98
+ }
99
+ /** Create bare shorthand rules that belong in the primitives layer by default. */
100
+ declare function makeShorthandRules(names: ShorthandRuleNames, value: ShorthandRuleValue, options?: ShorthandRuleOptions): StaticRule[];
101
+ declare function propsToValueMap(arr: readonly StaticRuleValue[], transform?: (key: string) => StaticRuleValueMapEntry, options?: {
102
+ as?: "record" | "map";
103
+ dedupe?: boolean;
104
+ ignores?: readonly StaticRuleValue[];
105
+ }): StaticRuleValueMapStore;
106
+ declare function hyphenToSpace(arr: readonly StaticRuleValue[], options?: {
107
+ as?: "record" | "map";
108
+ dedupe?: boolean;
109
+ ignores?: readonly StaticRuleValue[];
110
+ }): StaticRuleValueMapStore;
111
+ /**
112
+ * Create static enum rules.
113
+ *
114
+ * @param names one prefix (`"cursor"`) or several (`["display", "d"]`); the first
115
+ * string prefix is primary and supplies the default CSS property. Include `false`
116
+ * (e.g. `["display", "d", false]`) to also emit each value as a bare, prefix-less
117
+ * class (`flex` → `display:flex`); global keywords are always skipped, plus any
118
+ * `options.bareExclude` values.
119
+ * @param values enum values
120
+ * @param options `property` (defaults to the first prefix), `valueMap`, `meta`, `bareExclude`
121
+ */
122
+ declare function makeStaticRules(names: StaticRuleNames, values: readonly StaticRuleValue[], options?: StaticRuleOptions): StaticRule[];
123
+ //#endregion
124
+ //#region src/global-keyword-rules.d.ts
125
+ /**
126
+ * Build static enum rules plus one exact dynamic CSS-wide-keyword rule per
127
+ * property name. Exact global rules preserve the enum rule's property,
128
+ * value-map, metadata, and conflict position without expanding every keyword
129
+ * into the static rule map.
130
+ */
131
+ declare function makeGlobalRules(names: StaticRuleNames, values: readonly StaticRuleValue[], options?: StaticRuleOptions): Rule[];
132
+ /**
133
+ * Prevent broad preset fallbacks from shadowing exact global rules at their
134
+ * property-local conflict position. Apply this before appending user rules so
135
+ * later user-defined dynamic rules retain their normal priority.
136
+ */
137
+ declare function routeGlobalKeywordsToExactRules<Theme extends object>(rules: readonly Rule<Theme>[]): Rule<Theme>[];
138
+ //#endregion
139
+ //#region src/not-last-child-selector.d.ts
140
+ declare function notLastChildSelector(selector: string): string;
141
+ //#endregion
142
+ //#region src/object-access.d.ts
143
+ /** Read a record entry without exposing inherited Object prototype members. */
144
+ declare function getOwn<ObjectType extends object, Key extends keyof ObjectType>(record: ObjectType | null | undefined, key: Key): ObjectType[Key] | undefined;
145
+ //#endregion
146
+ //#region src/value-handler-factory.d.ts
147
+ type ValueHandlerResult = string | number | undefined;
148
+ type ValueHandlerCallback<T extends object> = (str: string, theme?: T) => ValueHandlerResult;
149
+ type SelectedValueHandlerResult<K extends string, T extends object, Handlers extends Record<K, ValueHandlerCallback<T>>, Selected extends K> = [Selected] extends [never] ? ValueHandlerResult : ReturnType<Handlers[Selected]>;
150
+ type ValueHandler<K extends string, T extends object, Handlers extends Record<K, ValueHandlerCallback<T>> = Record<K, ValueHandlerCallback<T>>, Selected extends K = never> = { [Name in K]: ValueHandler<K, T, Handlers, Selected | Name>; } & {
151
+ (str: string, theme?: T): SelectedValueHandlerResult<K, T, Handlers, Selected>;
152
+ readonly __options: {
153
+ readonly sequence: readonly K[];
154
+ };
155
+ };
156
+ declare function createValueHandler<K extends string, T extends object, const Handlers extends Record<K, ValueHandlerCallback<T>> = Record<K, ValueHandlerCallback<T>>>(handlers: Handlers): ValueHandler<K, T, Handlers>;
157
+ //#endregion
158
+ //#region src/standard-value-resolvers.d.ts
159
+ declare function numberWithUnit(str: string): string | undefined;
160
+ declare function auto(str: string): "auto" | undefined;
161
+ declare function full(str: string): "100%" | undefined;
162
+ declare function empty(str: string): "\"\"" | undefined;
163
+ declare function square(str: string): "1/1" | undefined;
164
+ declare function video(str: string): "16/9" | undefined;
165
+ declare function rem(str: string): string | undefined;
166
+ declare function px(str: string): string | undefined;
167
+ declare function number(str: string): number | undefined;
168
+ declare function integer(str: string): string | undefined;
169
+ declare function positiveInteger(str: string): string | undefined;
170
+ declare function customIdent(str: string): string | undefined;
171
+ declare function url(str: string): string | undefined;
172
+ declare function percent(str: string): string | undefined;
173
+ /** Resolve TeaCSS's 0–100 alpha scale while preserving authored decimal numbers. */
174
+ declare function alpha(str: string): string | undefined;
175
+ declare function fraction(str: string): string | undefined;
176
+ declare function spacing(str: string): string | undefined;
177
+ declare function bracket(str: string): string | undefined;
178
+ declare function cssvar(str: string): string | undefined;
179
+ declare function time(str: string): string | undefined;
180
+ declare function degree(str: string): string | undefined;
181
+ declare function global(str: string): string | undefined;
182
+ declare function properties(str: string): string | undefined;
183
+ declare function position(str: string): string | undefined;
184
+ declare function placement(str: string): string | undefined;
185
+ declare function none(str: string): "none" | undefined;
186
+ declare function zero(str: string): "0" | undefined;
187
+ //#endregion
188
+ //#region src/standard-value-handler.d.ts
189
+ /** The standard set of value handlers assembled into a chainable handler. */
190
+ declare const valueHandlers: Readonly<{
191
+ alpha: typeof alpha;
192
+ auto: typeof auto;
193
+ bracket: typeof bracket;
194
+ cssvar: typeof cssvar;
195
+ customIdent: typeof customIdent;
196
+ degree: typeof degree;
197
+ empty: typeof empty;
198
+ fraction: typeof fraction;
199
+ full: typeof full;
200
+ global: typeof global;
201
+ integer: typeof integer;
202
+ none: typeof none;
203
+ number: typeof number;
204
+ numberWithUnit: typeof numberWithUnit;
205
+ percent: typeof percent;
206
+ placement: typeof placement;
207
+ position: typeof position;
208
+ positiveInteger: typeof positiveInteger;
209
+ properties: typeof properties;
210
+ px: typeof px;
211
+ rem: typeof rem;
212
+ spacing: typeof spacing;
213
+ square: typeof square;
214
+ time: typeof time;
215
+ url: typeof url;
216
+ video: typeof video;
217
+ zero: typeof zero;
218
+ }>;
219
+ declare const handler: ValueHandler<string, object, Readonly<{
220
+ alpha: typeof alpha;
221
+ auto: typeof auto;
222
+ bracket: typeof bracket;
223
+ cssvar: typeof cssvar;
224
+ customIdent: typeof customIdent;
225
+ degree: typeof degree;
226
+ empty: typeof empty;
227
+ fraction: typeof fraction;
228
+ full: typeof full;
229
+ global: typeof global;
230
+ integer: typeof integer;
231
+ none: typeof none;
232
+ number: typeof number;
233
+ numberWithUnit: typeof numberWithUnit;
234
+ percent: typeof percent;
235
+ placement: typeof placement;
236
+ position: typeof position;
237
+ positiveInteger: typeof positiveInteger;
238
+ properties: typeof properties;
239
+ px: typeof px;
240
+ rem: typeof rem;
241
+ spacing: typeof spacing;
242
+ square: typeof square;
243
+ time: typeof time;
244
+ url: typeof url;
245
+ video: typeof video;
246
+ zero: typeof zero;
247
+ }>, never>;
248
+ declare const h: ValueHandler<string, object, Readonly<{
249
+ alpha: typeof alpha;
250
+ auto: typeof auto;
251
+ bracket: typeof bracket;
252
+ cssvar: typeof cssvar;
253
+ customIdent: typeof customIdent;
254
+ degree: typeof degree;
255
+ empty: typeof empty;
256
+ fraction: typeof fraction;
257
+ full: typeof full;
258
+ global: typeof global;
259
+ integer: typeof integer;
260
+ none: typeof none;
261
+ number: typeof number;
262
+ numberWithUnit: typeof numberWithUnit;
263
+ percent: typeof percent;
264
+ placement: typeof placement;
265
+ position: typeof position;
266
+ positiveInteger: typeof positiveInteger;
267
+ properties: typeof properties;
268
+ px: typeof px;
269
+ rem: typeof rem;
270
+ spacing: typeof spacing;
271
+ square: typeof square;
272
+ time: typeof time;
273
+ url: typeof url;
274
+ video: typeof video;
275
+ zero: typeof zero;
276
+ }>, never>;
277
+ //#endregion
278
+ //#region src/string-components.d.ts
279
+ declare function getBracket(str: string, open: string, close: string): string[] | undefined;
280
+ declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
281
+ declare function getStringComponents(str: string, separators: string | string[], limit?: number, open?: string, close?: string): string[] | undefined;
282
+ //#endregion
283
+ export { type CSSColorValue, type CSSCustomPropertyName, type DefinePropertyOptions, type RGBAColorValue, type ShorthandRuleNames, type ShorthandRuleOptions, type ShorthandRuleValue, type StaticRuleBody, type StaticRuleName, type StaticRuleNames, type StaticRuleOptions, type StaticRulePrefix, type StaticRuleProperty, type StaticRuleValue, type StaticRuleValueMap, type StaticRuleValueMapEntry, type StaticRuleValueMapResolver, type StaticRuleValueMapStore, type ValueHandler, type ValueHandlerCallback, type ValueHandlerResult, alphaPlaceholders, alphaPlaceholdersRE, angleRE, bracketTypeRe, calcMaxWidthBySize, colorOpacityToString, colorToString, consumeCssEscape, consumeCssIdentifier, consumeCssName, createValueHandler, cssColorFunctions, cssLengthPercentageUnitRESource, cssLengthUnitRESource, cssLengthUnits, cssNamedColors, decodeArbitraryValue, decodeCssIdentifier, defineProperty, getBracket, getOwn, getStringComponent, getStringComponents, globalKeywords, h, handler, hasIconFn, hasThemeFn, hex2rgba, hueInterpolationMethods, hyphenToSpace, isBareDashedIdentifier, isCssIdentifier, isCssNameCharacter, isCssNameStartCharacter, isCssWhitespace, isInterpolatedMethod, lengthRE, makeArbitraryValueRule, makeGlobalRules, makeGlobalValueRule, makeShorthandRules, makeStaticRules, notLastChildSelector, numberRE, numberWithUnitRE, parseCssColor, percentRE, polarColorSpace, propsToValueMap, rectangularColorSpace, routeGlobalKeywordsToExactRules, transformThemeFn, transformThemeString, unitOnlyMap, unitOnlyRE, valueHandlers };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{cssLengthPercentageUnitRESource as e,cssLengthUnitRESource as t,cssLengthUnits as n,cssNamedColors as r,globalKeywords as i}from"./constants.js";import{a,c as o,i as s,n as c,o as l,r as u,s as d,t as ee}from"./css-identifier-4yDg85cV.js";import{_ as te,a as f,b as p,c as m,d as ne,f as re,g as ie,h as ae,i as oe,l as h,m as g,n as _,o as v,p as y,r as b,s as x,t as se,u as S,v as ce,y as le}from"./standard-value-handler-DW0LevOJ.js";import{LAYER_PRIMITIVES as ue,LAYER_PROPERTIES as de,escapeRegExp as C,isStaticRule as fe,isString as pe,symbols as w,toArray as me}from"@teacss/core";function he(e){let t=e.match(/^-?\d+\.?\d*/)?.[0]||``,n=e.slice(t.length);if(n===`px`){let r=Number.parseFloat(t)-.1;return Number.isNaN(r)?e:`${r}${n}`}return`calc(${e} - 0.1px)`}function T(e,t,n){if(e===``)return;let r=e.length,i=0,a=!1,o=0;for(let s=0;s<r;s++)switch(e[s]){case t:a||(a=!0,o=s),i++;break;case n:if(--i,i<0)return;if(i===0)return[e.slice(o,s+1),e.slice(s+1),e.slice(0,o)];break}}function E(e,t,n,r){if(e===``||(pe(r)&&(r=[r]),r.length===0))return;let i=e.length,a=0;for(let o=0;o<i;o++)switch(e[o]){case t:a++;break;case n:if(--a<0)return;break;default:for(let t of r){let n=t.length;if(n&&t===e.slice(o,o+n)&&a===0)return o===0||o===i-n?void 0:[e.slice(0,o),e.slice(o+n)]}}if(a===0)return[e,``]}function D(e,t,n,r=`(`,i=`)`){n??=10;let a=[],o=0;for(;e!==``;){if(++o>n)return;let s=E(e,r,i,t);if(!s)return;let[c,l]=s;a.push(c),e=l}if(a.length>0)return a}const O=[`hsl`,`hsla`,`hwb`,`lab`,`lch`,`oklab`,`oklch`,`rgb`,`rgba`],k=[`srgb`,`srgb-linear`,`display-p3`,`display-p3-linear`,`a98-rgb`,`prophoto-rgb`,`rec2020`,`lab`,`oklab`,`xyz`,`xyz-d50`,`xyz-d65`],A=[`hsl`,`hwb`,`lch`,`oklch`],j=[`shorter`,`longer`,`increasing`,`decreasing`],M=[`%alpha`,`<alpha-value>`],N=new RegExp(M.map(e=>C(e)).join(`|`),`g`),P=new Set([...k,...A,...j]);function F(e){if(!e)return!1;let t=-1;for(let n=0;n<=e.length;n++){if(e[n]===`\\`||l(e[n])){t<0&&(t=n);continue}if(t>=0&&P.has(e.slice(t,n).toLowerCase()))return!0;t=-1}return!1}function I(e=``){let t=B(e);if(t!=null){let{components:e,alpha:n}=t;return n==null?e:[...e,n]}}function L(e=``){let t=ge(e);if(t==null||t===!1)return;let{type:n,components:r,alpha:i}=t,a=n.toLowerCase();if(r.length!==0&&!(O.includes(a)&&![1,3].includes(r.length)))return{type:a,components:r.map(e=>typeof e==`string`?e.trim():e),alpha:typeof i==`string`?i.trim():i}}function R(e){let t=e.alpha??1;return typeof t==`string`&&M.includes(t)?1:t}function z(e,t){if(typeof e==`string`)return e.replace(N,`${t??1}`);let{components:n}=e,{alpha:r,type:i}=e;return r=t??r,i=i.toLowerCase(),[`hsla`,`rgba`].includes(i)?`${i}(${n.join(`, `)}${r==null?``:`, ${r}`})`:(r=r==null?``:` / ${r}`,O.includes(i)?`${i}(${n.join(` `)}${r})`:`color(${i} ${n.join(` `)}${r})`)}function ge(e){if(!e)return;let t=B(e);if(t!=null||(t=_e(e),t!=null)||(t=ve(e),t!=null)||(t=be(e),t!=null)||(t=xe(e),t!=null))return t}function B(e){let[,t]=e.match(/^#([\da-f]+)$/i)||[];if(t)switch(t.length){case 3:case 4:{let e=Array.from(t,e=>Number.parseInt(e,16)).map(e=>e<<4|e);return{type:`rgb`,components:e.slice(0,3),alpha:t.length===3?void 0:V(e[3])}}case 6:case 8:{let e=Number.parseInt(t,16);return{type:`rgb`,components:t.length===6?[e>>16&255,e>>8&255,e&255]:[e>>24&255,e>>16&255,e>>8&255],alpha:t.length===6?void 0:V(e&255)}}}}function V(e){return Math.round(e/255*1e4)/1e4}const H={rebeccapurple:[102,51,153,1]};function _e(e){let t=S(H,e);if(t!=null)return{type:`rgb`,components:t.slice(0,3),alpha:t[3]}}function ve(e){let t=e.match(/^(rgb|rgba|hsl|hsla)\((.+)\)$/i);if(!t)return;let[,n,r]=t,i=D(r,`,`,5);if(i){if([3,4].includes(i.length))return{type:n,components:i.slice(0,3),alpha:i[3]};if(i.length!==1)return!1}}const ye=RegExp(`^(${O.join(`|`)})\\((.+)\\)$`,`i`);function be(e){let t=e.match(ye);if(!t)return;let[,n,r]=t,i=U(`${n} ${r}`);if(i){let{alpha:e,components:[t,...n]}=i;return{type:t,components:n,alpha:e}}}function xe(e){let t=e.match(/^color\((.+)\)$/);if(!t)return;let n=U(t[1]);if(n){let{alpha:e,components:[t,...r]}=n;return{type:t,components:r,alpha:e}}}function U(e){let t=D(e,` `);if(!t)return;let n=t.length;if(t[n-2]===`/`)return{components:t.slice(0,n-2),alpha:t[n-1]};if(t[n-2]!=null&&(t[n-2].endsWith(`/`)||t[n-1].startsWith(`/`))){let e=t.splice(n-2);t.push(e.join(` `)),--n}let r=D(t[n-1],`/`,2);if(!r)return;if(r.length===1||r[r.length-1]===``)return{components:t};let i=r.pop();return t[n-1]=r.join(`/`),{components:t,alpha:i}}function Se(e,t={}){let{syntax:n=`*`,inherits:r=!1,initialValue:i}=t,a={[w.shortcutsNoMerge]:!0,[w.noMerge]:!0,[w.variants]:()=>[{parent:``,layer:de,selector:()=>`@property ${e}`}],syntax:JSON.stringify(n),inherits:r?`true`:`false`};return i!=null&&(a[`initial-value`]=i),a}function W(e){return h(e,`theme`)}function Ce(e){return h(e,`icon`)}function we(e,t,n=!0){if(!W(e))return e;let r=[],i=0,a=0;for(;a<e.length;){let o=m(e,`theme`,a);if(o===-1)break;let s=Te(e,o);if(!s)break;if(a=s.end,!s.valid)continue;if(!s.argument)throw Error(`theme() expect exact one argument, but got 0`);let c=G(s.argument,t,n);c!==void 0&&(r.push(e.slice(i,o),c),i=s.end)}return i===0?e:(r.push(e.slice(i)),r.join(``))}function Te(e,t){let n=t+6;for(;/\s/.test(e[n]??``);)n++;let r=e[n]===`"`||e[n]===`'`?e[n++]:void 0,i=n;if(r){for(;n<e.length;){let t=e[n];if(t===`\\`){n+=2;continue}if(t===r)break;n++}if(n>=e.length)return;let t=e.slice(i,n);for(n++;/\s/.test(e[n]??``);)n++;return e[n]===`)`?{argument:t,end:n+1,valid:!0}:{argument:t,end:Ee(e,n),valid:!1}}for(;n<e.length&&e[n]!==`)`;)n++;if(!(n>=e.length))return{argument:e.slice(i,n).trim(),end:n+1,valid:!0}}function Ee(e,t){let n=e.indexOf(`)`,t);return n===-1?e.length:n+1}function G(e,t,n=!0){let r=e.indexOf(`/`),i=r<0?e:e.slice(0,r),a=r<0?void 0:e.slice(r+1),o=i.trim().split(`.`),s=t;for(let e of o){if(typeof s!=`object`||!s){s=void 0;break}s=S(s,e)}if(typeof s==`object`&&s&&(s=S(s,`DEFAULT`)),typeof s==`number`&&Number.isFinite(s)&&a==null)return String(s);if(typeof s==`string`){if(!a)return s;let e=De(a),t=L(s);return t?z(t,e):`color-mix(in oklab, ${s} ${e}, transparent)`}if(n)throw Error(`theme("${e}") was not found`)}function De(e){let t=e.trim();return/^\d{1,3}$/.test(t)&&Number(t)<=100?`${Number(t)}%`:t}function K(e){return f(e)??v(e)}function Oe(e){return K(e)??x(e)}function ke(e,t,n){return[e,([,e])=>({[t]:K(e)}),{autocomplete:n}]}function Ae(e,t,n){return[e,([,e])=>({[t]:Oe(e)}),{autocomplete:n}]}const je=new Set(i);function Me(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function Ne(e,t,n={}){let r=J(typeof e==`string`?[e]:e);if(r.length===0)return[];let{property:i,...a}=n,o=(i??r[0]??``).trim();if(!o)throw Error(`makeShorthandRules requires a non-empty property`);return r.map(e=>[e,{[o]:t},{...a,layer:ue}])}function q(e,t,n={}){let{as:r=`record`,dedupe:i=!0,ignores:a=[]}=n,o=new Set,s=a.length?new Set(a.map(String)):void 0,c=t??(e=>e);if(r===`map`){let t=new Map;for(let n of e){let e=String(n);s?.has(e)||i&&o.has(e)||(o.add(e),t.set(e,c(e)))}return t}let l={};for(let t of e){let e=String(t);if(s?.has(e)||i&&o.has(e))continue;o.add(e);let n=c(e);e===`__proto__`?Me(l,e,n):l[e]=n}return l}function Pe(e,t={}){return q(e,e=>e.includes(`-`)?e.replaceAll(`-`,` `):e,t)}function J(e){let t=new Set,n=[];for(let r of e)r&&(t.has(r)||(t.add(r),n.push(r)));return n}function Fe(e){let t=new Set,n=[];for(let r of e){let e=String(r);t.has(e)||(t.add(e),n.push(e))}return n}function Ie(e){if(!e)return()=>void 0;if(typeof e==`function`)return e;if(e instanceof Map)return t=>e.get(t);let t=e;return e=>S(t,e)}function Y(e,t){let n=(e??``).trim(),r=Ie(t);return e=>{let t=r(e);if(t!=null&&typeof t!=`string`&&typeof t!=`number`)return t;if(!n)throw Error(`makeStaticRules requires a non-empty property`);return{[n]:t??e}}}function X(e,t,n={}){let{valueMap:r,meta:i}=n,a=typeof e==`string`||e===!1?[e]:e,o=a.includes(!1),s=J(a.filter(e=>typeof e==`string`));if(s.length===0&&!o)return[];let c=Fe(t);if(c.length===0)return[];let l=Y(n.property??s[0],r),u=[],d=(e,t)=>u.push(i?[e,l(t),i]:[e,l(t)]);for(let e of s)for(let t of c)d(t?`${e}:${t}`:e,t);if(o){let e=new Set([...je,...(n.bareExclude??[]).map(String)]);for(let t of c)!t||e.has(t)||d(t,t)}return u}const Le=i.join(`|`),Z=new Set(i),Q=Symbol.for(`@teacss/rule-helpers/global-rule-name`);function $(e){return e[2]?.[Q]}function Re(e){if(e.flags)return;let t=e.source;if(!t.startsWith(`^`))return;let n=1;for(;n<t.length&&/[A-Za-z0-9_-]/.test(t[n]);)n++;return t[n]===`:`?t.slice(1,n):void 0}function ze(e,t,n={}){let r=J((typeof e==`string`||e===!1?[e]:e).filter(e=>typeof e==`string`)),i=X(e,t.filter(e=>!Z.has(String(e))),n);if(r.length===0)return i;let a=Y(n.property??r[0],n.valueMap),o=n.meta?.autocomplete,s=typeof o==`string`?[o]:o??[],c=n.meta?.prefix==null?[``]:me(n.meta.prefix);for(let e of r){let t={...n.meta,autocomplete:[...s,...c.map(t=>`${t}${e}:<globalKeyword>`)],[Q]:e},r=[RegExp(`^${C(e)}:(${Le})$`),([,e])=>a(e),t];i.push(r)}return i}function Be(e,t){let n=e.lastIndexOf(`:`);return n<=0||!Z.has(e.slice(n+1))?!1:t.has(e.slice(0,n))}function Ve(e){let t=new Set;for(let n of e){let e=$(n);e!=null&&t.add(e)}return t.size===0?[...e]:e.map(e=>{if(fe(e)||$(e)!=null)return e;let[n,r,i]=e,a=Re(n);if(a!=null&&!t.has(a))return e;let o=(e,n)=>{if(!Be(e[0],t))return r(e,n)};return i==null?[n,o]:[n,o,i]})}function He(e){let t=`>:not(:last-child)`;return e.includes(t)?`:where(${e})`:`:where(${e}${t})`}export{M as alphaPlaceholders,N as alphaPlaceholdersRE,y as angleRE,g as bracketTypeRe,he as calcMaxWidthBySize,R as colorOpacityToString,z as colorToString,ee as consumeCssEscape,c as consumeCssIdentifier,u as consumeCssName,oe as createValueHandler,O as cssColorFunctions,e as cssLengthPercentageUnitRESource,t as cssLengthUnitRESource,n as cssLengthUnits,r as cssNamedColors,ne as decodeArbitraryValue,s as decodeCssIdentifier,Se as defineProperty,T as getBracket,S as getOwn,E as getStringComponent,D as getStringComponents,i as globalKeywords,se as h,_ as handler,Ce as hasIconFn,W as hasThemeFn,I as hex2rgba,j as hueInterpolationMethods,Pe as hyphenToSpace,re as isBareDashedIdentifier,a as isCssIdentifier,l as isCssNameCharacter,d as isCssNameStartCharacter,o as isCssWhitespace,F as isInterpolatedMethod,ae as lengthRE,ke as makeArbitraryValueRule,ze as makeGlobalRules,Ae as makeGlobalValueRule,Ne as makeShorthandRules,X as makeStaticRules,He as notLastChildSelector,ie as numberRE,te as numberWithUnitRE,L as parseCssColor,ce as percentRE,A as polarColorSpace,q as propsToValueMap,k as rectangularColorSpace,Ve as routeGlobalKeywordsToExactRules,we as transformThemeFn,G as transformThemeString,le as unitOnlyMap,p as unitOnlyRE,b as valueHandlers};
@@ -0,0 +1 @@
1
+ import{cssLengthUnitRESource as e,cssLengthUnits as t,globalKeywords as n}from"./constants.js";import{a as r,i,o as a,t as o}from"./css-identifier-4yDg85cV.js";import{escapeSelector as s}from"@teacss/core";const c=`(?:${t.join(`|`)})`,l=RegExp(`^(-?\\d*(?:\\.\\d+)?)(${c})?$`,`i`),u=/^(-?\d*(?:\.\d+)?)$/,d=/^-?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|grad|rad|turn)$/,ee=/^-?(?:\d+(?:\.\d+)?|\.\d+)%$/,te=RegExp(`^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)${e}$`,`i`),f={px:1,vw:100,vh:100,svw:100,svh:100,dvw:100,dvh:100,lvh:100,lvw:100},p=RegExp(`^(${Object.keys(f).join(`|`)})$`,`i`),m=/^\[(color|image|length|size|position|quoted|string):/i;function h(e){return e.length>2&&e.startsWith(`--`)&&r(e)}function ne(e){let t=0,n,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(n){a===`\\`?i++:a===n&&(n=void 0,r=-1);continue}if(a===`"`||a===`'`)n=a,r=i;else if(a===`\\`)i++;else if(a===`[`)t++;else if(a===`]`&&--t<0)return!1}if(r>=0){for(let n=r+1;n<e.length;n++)if(e[n]===`\\`)n++;else if(e[n]===`[`)t++;else if(e[n]===`]`&&--t<0)return!1}return t===0}function g(e){if(!e)return;let t=e.length-1;if(!(t<2||e.charCodeAt(0)!==91||e.charCodeAt(t)!==93)&&(e.charCodeAt(1)!==45||e.charCodeAt(2)!==45)){for(let n=1;n<t;n++)switch(e.charCodeAt(n)){case 34:case 39:case 40:case 41:case 58:case 91:case 92:case 93:case 95:case 96:return}return e.slice(1,t)}}function _(e){let t=``;for(let n=0;n<e.length;n++)e[n]===`\\`&&e[n+1]===`_`?(t+=`_`,n++):t+=e[n]===`_`?` `:e[n];return t}function v(e,t){let n=0;for(;t>0&&e[--t]===`\\`;)n++;return n%2==1}function y(e,t){if(t===0)return!0;let n=e[t-1];return n===`_`&&!v(e,t-1)||n!==`\\`&&!a(n)}function re(e){let t=[],n=0,r=/url\(/gi,i;for(;(i=r.exec(e))!==null;){let a=i.index;if(!y(e,a))continue;t.push(_(e.slice(n,a)));let o=x(e,a+4);if(o===void 0)return t.push(_(e.slice(a))),t.join(``);t.push(e.slice(a,o)),n=o,r.lastIndex=o}return t.push(_(e.slice(n))),t.join(``)}function b(e){let t=[];return e.replace(/var\((--.+?)[,)]/g,(e,n)=>(t.push(n),e.replace(n,`--calc`))).replace(/(-?\d*\.?\d(?!-\d.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g,`$1 $2 `).replace(/--calc/g,()=>t.shift())}function ie(e){let t=[],n=/(?:calc|clamp|max|min)\(/gi,r=0,i;for(;(i=n.exec(e))!==null;){if(!y(e,i.index))continue;let a=x(e,n.lastIndex);a!=null&&(t.push(e.slice(r,i.index),b(e.slice(i.index,a))),r=a,n.lastIndex=a)}return r===0?e:(t.push(e.slice(r)),t.join(``))}function x(e,t){let n=1,r;for(let i=t;i<e.length;i++){let t=e[i];if(t===`\\`){i++;continue}if(r)t===r&&(r=void 0);else if(t===`"`||t===`'`)r=t;else if(t===`(`)n++;else if(t===`)`&&--n===0)return i+1}}function ae(e){let t=g(e);if(t!==void 0)return t;if(!e?.startsWith(`[`)||!e.endsWith(`]`))return;let n=e.match(m),r=e.slice(n?.[0].length??1,-1);if(!r||r===`=""`||!ne(r))return;h(r)&&(r=`var(${r})`);let i=n?.[1];return i===`string`?_(r):i===`quoted`?`"${_(r).replace(/(["\\])/g,`\\$1`)}"`:ie(re(r))}function S(e){return ae(e)}function oe(e,t){if(!(e==null||!Object.hasOwn(e,t)))return e[t]}function C(e,t,n=0){let r=`${t}(`,i;for(let t=n;t<=e.length-r.length;t++){let n=e[t];if(i!=null){n===`\\`?t=(o(e,t)??t+1)-1:n===i&&(i=void 0);continue}if(n===`'`||n===`"`){i=n;continue}if(n===`\\`){t=(o(e,t)??t+1)-1;continue}if(n===`/`&&e[t+1]===`*`){let n=e.indexOf(`*/`,t+2);if(n===-1)return-1;t=n+1;continue}if(!e.startsWith(r,t))continue;let s=e[t-1];if(t===0||!a(s))return t}return-1}function se(e,t){let n=C(e,t);return n>=0&&e.indexOf(`)`,n+t.length+1)>=0}function ce(e,t,n=!1){if(e.length<=t.length+1||e[t.length]!==`(`||e.at(-1)!==`)`)return!1;let r=e.slice(0,t.length);if(n?r.toLowerCase()!==t.toLowerCase():r!==t)return!1;let i=1,a;for(let n=t.length+1;n<e.length;n++){let t=e[n];if(t===`\\`){n++;continue}if(a!=null){t===a&&(a=void 0);continue}if(t===`'`||t===`"`){a=t;continue}if(t===`(`)i++;else if(t===`)`&&--i===0)return n===e.length-1}return!1}const w=new Set(n),T=String.raw`[+-]?(?:\d+|\d*\.\d+)(?:[eE][+-]?\d+)?`,E=RegExp(`^${T}$`),D=RegExp(`^${T}%$`),O=RegExp(`^(${T})(s|ms)?$`,`i`),k=RegExp(`^(${T})(deg|rad|grad|turn)?$`,`i`),A=`color.border-color.background-color.outline-color.text-decoration-color.flex-grow.flex.flex-shrink.caret-color.font.gap.opacity.visibility.z-index.font-weight.zoom.text-shadow.transform.box-shadow.border.background-position.left.right.top.bottom.object-position.max-height.min-height.max-width.min-width.height.width.border-width.margin.padding.outline-width.outline-offset.font-size.line-height.text-indent.vertical-align.border-spacing.letter-spacing.word-spacing.stroke.filter.backdrop-filter.fill.mask.mask-size.mask-border.clip-path.clip.border-radius`.split(`.`);function j(e){return+e.toFixed(10)}function M(e){let t=e.match(l);if(!t)return;let[,n,r]=t,i=Number.parseFloat(n);if(r&&!Number.isNaN(i))return`${j(i)}${r}`}function N(e){if(e===`auto`)return`auto`}function P(e){if(e===`full`)return`100%`}function F(e){if(e===`empty`)return`""`}function I(e){if(e===`square`)return`1/1`}function L(e){if(e===`video`)return`16/9`}function R(e){if(!e)return;if(p.test(e))return`${f[e.toLowerCase()]}${e}`;let t=e.match(l);if(!t)return;let[,n,r]=t,i=Number.parseFloat(n);if(!Number.isNaN(i))return i===0?`0`:r?`${j(i)}${r}`:`${j(i/4)}rem`}function z(e){if(p.test(e))return`${f[e.toLowerCase()]}${e}`;let t=e?.match(l);if(!t)return;let[,n,r]=t,i=Number.parseFloat(n);if(!Number.isNaN(i))return r?`${j(i)}${r}`:`${j(i)}px`}function B(e){if(!u.test(e))return;let t=Number.parseFloat(e);if(!Number.isNaN(t))return j(t)}function V(e){if(/^-?\d+$/.test(e))return e}function H(e){if(/^[1-9]\d*$/.test(e))return e}function U(e){if(!r(e))return;let t=i(e).toLowerCase();if(!(t==="default"||w.has(t)))return e}function W(e){if(e.length>5&&ce(e,`url`,!0))return e}function G(e){if(D.test(e))return e;if(u.test(e)){let t=Number.parseFloat(e);if(!Number.isNaN(t))return`${j(t)}%`}}function le(e){return/^\d*\.\d+$/.test(e)?e:G(e)}function K(e){if(!e)return;if(e===`full`)return`100%`;let t=e.indexOf(`/`);if(t<=0||t!==e.lastIndexOf(`/`)||t===e.length-1)return;let n=e.slice(0,t),r=e.slice(t+1);if(!E.test(n)||!E.test(r))return;let i=Number(r);if(i===0)return;let a=Number(n)/i;if(Number.isFinite(a))return a===0?`0`:`${j(a*100)}%`}function ue(e){let t=K(e)||B(e);if(t==null)return;let n=String(t).endsWith(`%`)?Number(String(t).slice(0,-1))/100:Number(t);return n===0?`0`:`calc(var(--spacing) * ${n})`}function q(e){return S(e)}function J(e){if(!/^\$[^\s'"`;{}]/.test(e))return;let t=e.slice(1),n=t.indexOf(`|`),r=n===-1?t:t.slice(0,n),i=n===-1?void 0:t.slice(n+1);if(!(!r||/[,\s'"`;{}]/.test(r))&&!(n!==-1&&!i))return`var(--${s(r)}${i?`, ${i}`:``})`}function de(e){let t=e.match(O);if(!t)return;let[,n,r]=t,i=Number(n);if(Number.isFinite(i))return i===0&&!r?`0s`:r?`${j(i)}${r}`:`${j(i)}ms`}function fe(e){let t=e.match(k);if(!t)return;let[,n,r]=t,i=Number(n);if(Number.isFinite(i))return i===0&&!r?`0`:r?`${j(i)}${r}`:`${j(i)}deg`}function Y(e){if(w.has(e))return e}function pe(e){if(e.split(`,`).every(e=>A.includes(e)))return e}function me(e){if([`top`,`left`,`right`,`bottom`,`center`].includes(e))return e}function he(e){if([`top`,`bottom`,`left`,`right`,`center`,`top-left`,`top-right`,`bottom-left`,`bottom-right`].includes(e))return e}function ge(e){if(e===`none`)return`none`}function X(e){if(e===`none`||e===`zero`)return`0`}function Z(e){if(Object.hasOwn(e,`__options`))throw Error(`"__options" is a reserved createValueHandler name`);let t=Object.keys(e),n=Object.create(Function.prototype),r=new WeakMap;function i(t){let i=Object.freeze([...t]),a=((t,n)=>{for(let r of i){let i=e[r](t,n);if(i!=null)return i}});return Object.defineProperty(a,"__options",{enumerable:!0,value:Object.freeze({sequence:Object.freeze([...i])})}),r.set(a,i),Object.setPrototypeOf(a,n),a}function a(e){for(let n of t)Object.defineProperty(e,n,{enumerable:!0,configurable:!0,get(){let e=i([...r.get(this)??[],n]);return Object.defineProperty(this,n,{enumerable:!0,configurable:!0,value:e}),e}})}a(n);let o=i([]);return a(o),o}const Q=Object.freeze({alpha:le,auto:N,bracket:q,cssvar:J,customIdent:U,degree:fe,empty:F,fraction:K,full:P,global:Y,integer:V,none:ge,number:B,numberWithUnit:M,percent:G,placement:he,position:me,positiveInteger:H,properties:pe,px:z,rem:R,spacing:ue,square:I,time:de,url:W,video:L,zero:X}),$=Z(Q),_e=$;export{l as _,q as a,p as b,C as c,S as d,h as f,u as g,te as h,Z as i,se as l,m,$ as n,J as o,d as p,Q as r,Y as s,_e as t,oe as u,ee as v,f as y};
@@ -0,0 +1,46 @@
1
+ import { Arrayable } from "@teacss/core";
2
+ //#region src/color-opacity.d.ts
3
+ declare function isValidOpacityModifier(value: string): boolean;
4
+ declare function resolveAlphaValue(value: string): string | undefined;
5
+ /** Apply an optional `/NN` opacity (number 0–100) to a color via `color-mix(in oklab, …)`; otherwise return the color unchanged. */
6
+ declare function applyOpacity(color: string, opacity?: string): string;
7
+ /** Split a color value on a depth-0 `/` into [color, opacity?]. */
8
+ declare function splitOpacity(value: string): [color: string, opacity?: string];
9
+ //#endregion
10
+ //#region src/css-variable-token.d.ts
11
+ declare function isCssVariableToken(value: string): boolean;
12
+ //#endregion
13
+ //#region src/keyword-value-resolvers.d.ts
14
+ declare function resolveKeyword(value: string, allowed: ReadonlySet<string>): string | undefined;
15
+ declare function resolveKeywordList(value: string, allowed: ReadonlySet<string>): string | undefined;
16
+ //#endregion
17
+ //#region src/number-value-resolvers.d.ts
18
+ /**
19
+ * Resolve a TeaCSS number or fraction to a numeric multiplier.
20
+ *
21
+ * A caller-supplied fallback is normalized with `Number`, preserving `NaN` so
22
+ * callers can distinguish a present nonnumeric token from a missing token.
23
+ */
24
+ declare function resolveNumber(value: string, fallback?: string | number): number | undefined;
25
+ //#endregion
26
+ //#region src/shadow-value.d.ts
27
+ declare function normalizeShadowLength(value: string): string | undefined;
28
+ declare function isNonnegativeLengthValue(value: string): boolean;
29
+ declare function splitShadowLayers(value: string): string[];
30
+ declare function hasInvalidTextShadowRadius(value: string): boolean;
31
+ //#endregion
32
+ //#region src/theme-variable.d.ts
33
+ type ThemeVariableValue = string | readonly string[];
34
+ type ThemeVariableGroup = Record<string, ThemeVariableValue>;
35
+ type ThemeVariableGroupKey<Theme> = { [K in keyof Theme]-?: Theme[K] extends ThemeVariableGroup | undefined ? K : never; }[keyof Theme] & string;
36
+ /**
37
+ * Convert a camelCase theme key to its kebab-case CSS variable segment.
38
+ */
39
+ declare function camelToKebab(value: string): string;
40
+ declare function resolveThemeVariable<Theme extends object, GroupKey extends ThemeVariableGroupKey<Theme>>(theme: Theme | undefined, groupKey: GroupKey, props: Arrayable<string>, variablePrefix?: string, passthrough?: ReadonlySet<string>): string | undefined;
41
+ //#endregion
42
+ //#region src/time-value-resolvers.d.ts
43
+ declare function resolveNonnegativeTime(value: string, keywords?: readonly string[]): string | undefined;
44
+ declare function resolveTime(value: string): string | undefined;
45
+ //#endregion
46
+ export { applyOpacity, camelToKebab, hasInvalidTextShadowRadius, isCssVariableToken, isNonnegativeLengthValue, isValidOpacityModifier, normalizeShadowLength, resolveAlphaValue, resolveKeyword, resolveKeywordList, resolveNonnegativeTime, resolveNumber, resolveThemeVariable, resolveTime, splitOpacity, splitShadowLayers };
@@ -0,0 +1 @@
1
+ import{cssLengthUnitRESource as e,globalKeywords as t}from"./constants.js";import{findLastTopLevelDelimiter as n,splitTopLevelCommas as r,topLevelWhitespaceSpans as i}from"./css-syntax.js";import{c as a,g as o,h as s,n as c,u as l}from"./css-value-syntax-CMg4Dex-.js";import{b as u,d,n as f,t as p,u as m}from"./standard-value-handler-DW0LevOJ.js";function h(e){return/^\d{1,3}$/.test(e)&&Number(e)<=100}function g(e){let t=p.global.cssvar(e);if(t!=null)return t;let n=p.bracket(e);return n==null?a.test(e)?/[.e]/i.test(e)?e:`${e}%`:p.alpha(e):o(n)?n:void 0}function _(e,t){return t!=null&&h(t)?`color-mix(in oklab, ${e} ${Number(t)}%, transparent)`:e}function v(e){let t=n(e,`/`);return t<0?[e]:[e.slice(0,t),e.slice(t+1)]}function y(e){return p.cssvar(e)!=null}function b(e,t){let n=p.cssvar.global(e);if(n!=null)return n;let r=p.bracket(e)??e;return p.global(r)??(t.has(r)?r:void 0)}function x(e,t){let n=p.cssvar.global(e);if(n!=null)return n;if(t.has(e))return e;let i=p.bracket(e);if(i==null)return;let a=p.global(i);if(a!=null)return a;let o=r(i);return o.length>0&&o.every(e=>t.has(e))?i:void 0}function S(e,t){let n=f.fraction.number(e)??t;if(n==null)return;let r=String(n);return r.endsWith(`%`)?Number(r.slice(0,-1))/100:Number(n)}const C=RegExp(`^([+-]?(?:\\d+|\\d*\\.\\d+)(?:e[+-]?\\d+)?)(${e})?$`,`i`),w=/^[+-]?(?:\d+|\d*\.\d+)(?:e[+-]?\d+)?%$/i,T=new Set(t);function E(e){return i(e).map(e=>e.value)}function D(e){return/rpx$/i.test(e)||w.test(e)?!1:u.test(e)||C.test(e)}function O(e){if(/rpx$/i.test(e))return;let t=p.px(e);if(t!=null)return t;let n=e.match(C);if(!n)return;let r=Number(n[1]);if(!Number.isFinite(r))return;let i=Number(r.toFixed(10));return n[2]?`${i}${n[2]}`:`${i}px`}function k(e){let t=d(e);return t==null?e.startsWith(`[`)||e.endsWith(`]`)?!1:y(e)?!0:e.startsWith(`-`)||T.has(e)?!1:D(e):A(t).length===1&&E(t).length===1&&s(t)&&!l(t)}function A(e){return r(e)}function j(e){return A(e).some(e=>E(e).filter(e=>C.test(e)).slice(2,4).some(e=>Number(e.match(C)?.[1])<0))}const M=new Set;function N(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function P(e){return typeof e==`string`?e:e.join(`-`)}function F(e,t,n,r,i=M){let a=m(e,t);if(!a)return;let o=P(n),s=m(a,o);if(s!=null)return i.has(o)?typeof s==`string`?s:s.join(` `):`var(--${r??N(t)}-${o})`}function I(e){return e.replace(/\/\*[\s\S]*?\*\//g,` `).trim()}function L(e,t=[]){let n=p.bracket(e);if(n!=null){let e=r(n);return e.length>0&&e.every(e=>{let n=I(e);return t.includes(n)||c(n)&&!B(n)})?n:void 0}let i=p.cssvar.global(e);if(i!=null)return i;if(t.includes(e))return e;let a=p.time(e);return a?.startsWith(`-`)?void 0:a}function R(e){let t=p.bracket(e);if(t!=null){let e=r(t);return e.length>0&&e.every(e=>c(I(e)))?t:void 0}return p.cssvar.global.time(e)}const z=/^([+-]?(?:\d+|\d*\.\d+)(?:e[+-]?\d+)?)(?:ms|s)?$/i;function B(e){let t=e.match(z);return t!=null&&Number(t[1])<0}export{_ as applyOpacity,N as camelToKebab,j as hasInvalidTextShadowRadius,y as isCssVariableToken,k as isNonnegativeLengthValue,h as isValidOpacityModifier,O as normalizeShadowLength,g as resolveAlphaValue,b as resolveKeyword,x as resolveKeywordList,L as resolveNonnegativeTime,S as resolveNumber,F as resolveThemeVariable,R as resolveTime,v as splitOpacity,A as splitShadowLayers};
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@teacss/rule-helpers",
3
+ "version": "0.3.0",
4
+ "description": "Helpers for authoring TeaCSS preset rules — static/dynamic rule builders and value resolvers.",
5
+ "homepage": "https://css.teasim.com",
6
+ "funding": "https://github.com/sponsors/billgo",
7
+ "license": "MIT",
8
+ "author": "Billgo <hi@billgo.me>",
9
+ "sideEffects": false,
10
+ "type": "module",
11
+ "exports": {
12
+ ".": "./dist/index.js",
13
+ "./constants": "./dist/constants.js",
14
+ "./css-syntax": "./dist/css-syntax.js",
15
+ "./css-value-syntax": "./dist/css-value-syntax.js",
16
+ "./value-resolvers": "./dist/value-resolvers.js",
17
+ "./package.json": "./package.json"
18
+ },
19
+ "types": "./dist/index.d.ts",
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "scripts": {
25
+ "build": "bunx rimraf dist && bunx tsdown --config tsdown.config.mts",
26
+ "dev": "tsdown --watch"
27
+ },
28
+ "dependencies": {
29
+ "@teacss/core": "0.3.0"
30
+ },
31
+ "engines": {
32
+ "node": ">=22.12.0"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
37
+ }