@teacss/rule-helpers 0.3.5 → 0.3.7
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/dist/index.d.ts
CHANGED
|
@@ -165,7 +165,6 @@ declare function createValueHandler<K extends string, T extends object, const Ha
|
|
|
165
165
|
//#region src/standard-value-resolvers.d.ts
|
|
166
166
|
declare function numberWithUnit(str: string): string | undefined;
|
|
167
167
|
declare function auto(str: string): "auto" | undefined;
|
|
168
|
-
declare function full(str: string): "100%" | undefined;
|
|
169
168
|
declare function empty(str: string): "\"\"" | undefined;
|
|
170
169
|
declare function square(str: string): "1/1" | undefined;
|
|
171
170
|
declare function video(str: string): "16/9" | undefined;
|
|
@@ -203,7 +202,6 @@ declare const valueHandlers: Readonly<{
|
|
|
203
202
|
degree: typeof degree;
|
|
204
203
|
empty: typeof empty;
|
|
205
204
|
fraction: typeof fraction;
|
|
206
|
-
full: typeof full;
|
|
207
205
|
global: typeof global;
|
|
208
206
|
integer: typeof integer;
|
|
209
207
|
none: typeof none;
|
|
@@ -232,7 +230,6 @@ declare const handler: ValueHandler<string, object, Readonly<{
|
|
|
232
230
|
degree: typeof degree;
|
|
233
231
|
empty: typeof empty;
|
|
234
232
|
fraction: typeof fraction;
|
|
235
|
-
full: typeof full;
|
|
236
233
|
global: typeof global;
|
|
237
234
|
integer: typeof integer;
|
|
238
235
|
none: typeof none;
|
|
@@ -261,7 +258,6 @@ declare const h: ValueHandler<string, object, Readonly<{
|
|
|
261
258
|
degree: typeof degree;
|
|
262
259
|
empty: typeof empty;
|
|
263
260
|
fraction: typeof fraction;
|
|
264
|
-
full: typeof full;
|
|
265
261
|
global: typeof global;
|
|
266
262
|
integer: typeof integer;
|
|
267
263
|
none: typeof none;
|
package/dist/index.js
CHANGED
|
@@ -1 +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 f}from"./css-identifier-4yDg85cV.js";import{_ as ee,a as p,b as m,d as h,f as g,g as te,h as ne,i as re,l as ie,m as ae,n as _,o as v,p as oe,r as y,s as b,t as x,u as S,v as C,x as se,y as ce}from"./standard-value-handler-CFhbhgol.js";import{LAYER_PRIMITIVES as le,LAYER_PROPERTIES as ue,escapeRegExp as w,isStaticRule as de,isString as fe,symbols as T,toArray as pe}from"@teacss/core";function me(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 he(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===``||(fe(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=>w(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=H(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 _e={rebeccapurple:[102,51,153,1]};function H(e){let t=h(_e,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={[T.shortcutsNoMerge]:!0,[T.noMerge]:!0,[T.variants]:()=>[{parent:``,layer:ue,selector:()=>`@property ${e}`}],syntax:JSON.stringify(n),inherits:r?`true`:`false`};return i!=null&&(a[`initial-value`]=i),a}function W(e){return S(e,`theme`)}function Ce(e){return S(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=ie(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=h(s,e)}if(typeof s==`object`&&s&&(s=h(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 p(e)??v(e)}function Oe(e){return K(e)??b(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:le}])}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=>h(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?[``]:pe(n.meta.prefix);for(let e of r){let t={...n.meta,autocomplete:[...s,...c.map(t=>`${t}${e}:<globalKeyword>`)],[Q]:e},r=[RegExp(`^${w(e)}:(${Le})$`),([,e])=>a(e),t];i.push(r)}if(n.escapeHatch){let e=(n.property??r[0]??``).trim();if(!e)throw Error(`escapeHatch requires a rule name or property`);for(let t of r){let r={...n.meta,autocomplete:[...s,...c.map(e=>`${e}${t}:[]`)]};i.push([RegExp(`^${w(t)}:(.+)$`),([,t])=>({[e]:p(t)??v(t)}),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(de(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,ae as angleRE,ne as bracketTypeRe,me as calcMaxWidthBySize,R as colorOpacityToString,z as colorToString,f as consumeCssEscape,c as consumeCssIdentifier,u as consumeCssName,re as createValueHandler,O as cssColorFunctions,e as cssLengthPercentageUnitRESource,t as cssLengthUnitRESource,n as cssLengthUnits,r as cssNamedColors,g as decodeArbitraryValue,s as decodeCssIdentifier,Se as defineProperty,he as getBracket,h as getOwn,E as getStringComponent,D as getStringComponents,i as globalKeywords,x as h,_ as handler,Ce as hasIconFn,W as hasThemeFn,I as hex2rgba,j as hueInterpolationMethods,Pe as hyphenToSpace,oe as isBareDashedIdentifier,a as isCssIdentifier,l as isCssNameCharacter,d as isCssNameStartCharacter,o as isCssWhitespace,F as isInterpolatedMethod,te as lengthRE,ke as makeArbitraryValueRule,ze as makeGlobalRules,Ae as makeGlobalValueRule,Ne as makeShorthandRules,X as makeStaticRules,He as notLastChildSelector,ee as numberRE,C 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,m as unitOnlyMap,se as unitOnlyRE,y as valueHandlers};
|
|
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 f}from"./css-identifier-4yDg85cV.js";import{_ as ee,a as p,b as m,d as h,f as g,g as te,h as ne,i as re,l as ie,m as ae,n as _,o as v,p as oe,r as y,s as b,t as x,u as S,v as C,x as se,y as ce}from"./standard-value-handler-CmAdwmcK.js";import{LAYER_PRIMITIVES as le,LAYER_PROPERTIES as ue,escapeRegExp as w,isStaticRule as de,isString as fe,symbols as T,toArray as pe}from"@teacss/core";function me(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 he(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===``||(fe(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=>w(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=H(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 _e={rebeccapurple:[102,51,153,1]};function H(e){let t=h(_e,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={[T.shortcutsNoMerge]:!0,[T.noMerge]:!0,[T.variants]:()=>[{parent:``,layer:ue,selector:()=>`@property ${e}`}],syntax:JSON.stringify(n),inherits:r?`true`:`false`};return i!=null&&(a[`initial-value`]=i),a}function W(e){return S(e,`theme`)}function Ce(e){return S(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=ie(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=h(s,e)}if(typeof s==`object`&&s&&(s=h(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 p(e)??v(e)}function Oe(e){return K(e)??b(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:le}])}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=>h(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?[``]:pe(n.meta.prefix);for(let e of r){let t={...n.meta,autocomplete:[...s,...c.map(t=>`${t}${e}:<globalKeyword>`)],[Q]:e},r=[RegExp(`^${w(e)}:(${Le})$`),([,e])=>a(e),t];i.push(r)}if(n.escapeHatch){let e=(n.property??r[0]??``).trim();if(!e)throw Error(`escapeHatch requires a rule name or property`);for(let t of r){let r={...n.meta,autocomplete:[...s,...c.map(e=>`${e}${t}:[]`)]};i.push([RegExp(`^${w(t)}:(.+)$`),([,t])=>({[e]:p(t)??v(t)}),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(de(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,ae as angleRE,ne as bracketTypeRe,me as calcMaxWidthBySize,R as colorOpacityToString,z as colorToString,f as consumeCssEscape,c as consumeCssIdentifier,u as consumeCssName,re as createValueHandler,O as cssColorFunctions,e as cssLengthPercentageUnitRESource,t as cssLengthUnitRESource,n as cssLengthUnits,r as cssNamedColors,g as decodeArbitraryValue,s as decodeCssIdentifier,Se as defineProperty,he as getBracket,h as getOwn,E as getStringComponent,D as getStringComponents,i as globalKeywords,x as h,_ as handler,Ce as hasIconFn,W as hasThemeFn,I as hex2rgba,j as hueInterpolationMethods,Pe as hyphenToSpace,oe as isBareDashedIdentifier,a as isCssIdentifier,l as isCssNameCharacter,d as isCssNameStartCharacter,o as isCssWhitespace,F as isInterpolatedMethod,te as lengthRE,ke as makeArbitraryValueRule,ze as makeGlobalRules,Ae as makeGlobalValueRule,Ne as makeShorthandRules,X as makeStaticRules,He as notLastChildSelector,ee as numberRE,C 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,m as unitOnlyMap,se as unitOnlyRE,y as valueHandlers};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cssLengthUnitRESource as e,cssLengthUnits as t,globalKeywords as n}from"./constants.js";import{a as r,c as i,i as a,n as o,o as s,t as c}from"./css-identifier-4yDg85cV.js";import{escapeSelector as l}from"@teacss/core";const u=`(?:${t.join(`|`)})`,d=RegExp(`^([+-]?\\d*(?:\\.\\d+)?(?:e[+-]?\\d+)?)(${u})?$`,`i`),f=/^([+-]?\d*(?:\.\d+)?(?:e[+-]?\d+)?)$/i,p=/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?(?:deg|grad|rad|turn)$/i,ee=/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?%$/i,te=RegExp(`^[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:e[+-]?\\d+)?${e}$`,`i`),m={px:1,vw:100,vh:100,svw:100,svh:100,dvw:100,dvh:100,lvh:100,lvw:100},h=RegExp(`^(${Object.keys(m).join(`|`)})$`,`i`),g=/^\[(color|image|length|size|position|quoted|string):/i,ne=new Set([...t,`angle`,`color`,`dpcm`,`deg`,`dpi`,`dppx`,`flex`,`fr`,`frequency`,`grad`,`hz`,`integer`,`khz`,`length`,`ms`,`number`,`percentage`,`rad`,`raw-string`,`resolution`,`s`,`string`,`time`,`turn`,`url`,`x`]);function _(e){return e.length>2&&e.startsWith(`--`)&&r(e)}function re(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 v(e){let t=(t,n)=>{let r=0,i;for(let a=t;a<e.length;a++){let t=e[a];if(i){t===`\\`?a++:t===i&&(i=void 0);continue}if(n&&(t===`"`||t===`'`))i=t;else if(t===`\\`)a++;else if(t===`/`&&e[a+1]===`*`){let t=e.indexOf(`*/`,a+2);if(t===-1)return!1;a=t+1}else if(t===`*`&&e[a+1]===`/`)return!1;else if(t===`(`||t===`{`)r++;else if(t===`)`||t===`}`){if(--r<0)return!1}else if(t===`;`&&r===0)return!1}return i===void 0?r===0:e.length},n=t(0,!0);return typeof n==`boolean`?n:t(0,!1)===!0}function y(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 59:case 91:case 92:case 93:case 95:case 96:case 123:case 125:return;case 42:case 47:if(e.charCodeAt(n+1)===42||e.charCodeAt(n+1)===47)return;break}return e.slice(1,t)}}function b(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 x(e,t){let n=0;for(;t>0&&e[--t]===`\\`;)n++;return n%2==1}function S(e,t){if(t===0)return!0;let n=e[t-1];return n===`_`&&!x(e,t-1)||n!==`\\`&&!s(n)}function C(e,t,n,r){for(let i=t;i<n;i++)e[i]===`_`&&!x(e,i)&&!w(e,i)&&r.add(i)}function w(e,t){let n=t-1,r=0;for(;n>=0&&r<6&&/[0-9a-f]/i.test(e[n]);)n--,r++;return r>0&&e[n]===`\\`&&!x(e,n)}function T(e,t,n){let r=e.lastIndexOf(`_`,n-1);for(;r>=t&&x(e,r);)r=e.lastIndexOf(`_`,r-1);return r}function E(e,t,n){let r=T(e,t,n);if(r<t)return n;if(r===n-1&&e[n]===`%`)return r;let i=a(e.slice(r+1,n)).toLowerCase();return ne.has(i)||i===`type`&&e[n]===`(`?r:n}function D(e){return e!=null&&e>=`0`&&e<=`9`}function ie(e,t,n){let r=D(e[n])||e[n]===`+`&&D(e[n+1]);if(e[n-1]===`_`&&!x(e,n-1)&&r)return n-1;let i=n;for(;i>t&&D(e[i-1]);)i--;if(i===n)return n;let a=n;for(;i>t&&e[i-1]===`_`&&!x(e,i-1);){a=--i;let n=i;for(;i>t&&D(e[i-1]);)i--;if(i===n)break}return a}function ae(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 oe(e){let t=[],n=/(?:calc|clamp|max|min)\(/gi,r=0,i;for(;(i=n.exec(e))!==null;){if(!S(e,i.index))continue;let a=k(e,n.lastIndex);a!=null&&(t.push(e.slice(r,i.index),ae(e.slice(i.index,a))),r=a,n.lastIndex=a)}return r===0?e:(t.push(e.slice(r)),t.join(``))}function O(e,t){let n=e[t];if(n===`"`||n===`'`){for(let r=t+1;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===n)return r+1;return e.length}if(e[t]===`/`&&e[t+1]===`*`){let n=e.indexOf(`*/`,t+2);return n<0?e.length:n+2}}function se(e,t){let n=t;for(;n<e.length;){if(i(e[n])||e[n]===`_`&&!x(e,n)){n++;continue}if(e[n]!==`/`||e[n+1]!==`*`)return n;let t=O(e,n);if(t==null)return n;n=t}return n}function ce(e){let t=new Set,n=[];for(let r=0;r<e.length;){let i=O(e,r);if(i!=null){r=i;continue}let s=o(e,r);if(s==null){r++;continue}if(!S(e,r)){if(e[s]!==`(`){r=s;continue}let t=e.lastIndexOf(`_`,s-1);r=t>r?t+1:s;continue}let c=a(e.slice(r,s));if(e[s]!==`(`){r=s;continue}let l=c.toLowerCase();if(l===`url`){let t=k(e,s+1);if(t==null)break;n.push({start:r,end:t}),r=t;continue}if(l===`attr`||l===`env`||l===`var`){let n=se(e,s+1),r=o(e,n);r!=null&&C(e,n,l===`attr`?E(e,n,r):l===`env`?ie(e,n,r):r,t)}r=s+1}return{indexes:t,literals:n}}function le(e){let t=ce(e),n=0,r=``;for(let i=0;i<e.length;i++){let a=t.literals[n];if(a&&i===a.start){r+=e.slice(a.start,a.end),i=a.end-1,n++;continue}if(e[i]===`\\`&&e[i+1]===`_`){r+=`_`,i++;continue}r+=e[i]===`_`&&!t.indexes.has(i)?` `:e[i]}return r}function k(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 A(e){let t=y(e);if(t!==void 0)return t;if(!e?.startsWith(`[`)||!e.endsWith(`]`))return;let n=e.match(g),r=e.slice(n?.[0].length??1,-1);if(!r||r===`=""`||!re(r))return;let i=n?.[1];if(i===`quoted`)return`"${b(r).replace(/(["\\])/g,`\\$1`)}"`;if(v(r))return i===`string`?b(r):(_(r)&&(r=`var(${r})`),oe(le(r)))}function j(e){return A(e)}function M(e,t){if(!(e==null||!Object.hasOwn(e,t)))return e[t]}function N(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=(c(e,t)??t+1)-1:n===i&&(i=void 0);continue}if(n===`'`||n===`"`){i=n;continue}if(n===`\\`){t=(c(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 a=e[t-1];if(t===0||!s(a))return t}return-1}function P(e,t){let n=N(e,t);return n>=0&&e.indexOf(`)`,n+t.length+1)>=0}function F(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 I=new Set(n),L=String.raw`[+-]?(?:\d+|\d*\.\d+)(?:[eE][+-]?\d+)?`,R=RegExp(`^${L}$`),z=RegExp(`^${L}%$`),B=RegExp(`^(${L})(s|ms)?$`,`i`),V=RegExp(`^(${L})(deg|rad|grad|turn)?$`,`i`),H=`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 U(e){return+e.toFixed(10)}function W(e){let t=e.match(d);if(!t)return;let[,n,r]=t,i=Number.parseFloat(n);if(r&&!Number.isNaN(i))return`${U(i)}${r}`}function ue(e){if(e===`auto`)return`auto`}function de(e){if(e===`empty`)return`""`}function fe(e){if(e===`square`)return`1/1`}function pe(e){if(e===`video`)return`16/9`}function me(e){if(!e)return;if(h.test(e))return`${m[e.toLowerCase()]}${e}`;let t=e.match(d);if(!t)return;let[,n,r]=t,i=Number.parseFloat(n);if(!Number.isNaN(i))return i===0?`0`:r?`${U(i)}${r}`:`${U(i/4)}rem`}function he(e){if(h.test(e))return`${m[e.toLowerCase()]}${e}`;let t=e?.match(d);if(!t)return;let[,n,r]=t,i=Number.parseFloat(n);if(!Number.isNaN(i))return r?`${U(i)}${r}`:`${U(i)}px`}function G(e){if(!f.test(e))return;let t=Number.parseFloat(e);if(!Number.isNaN(t))return U(t)}function ge(e){if(/^-?\d+$/.test(e))return e}function _e(e){if(/^[1-9]\d*$/.test(e))return e}function ve(e){if(!r(e))return;let t=a(e).toLowerCase();if(!(t==="default"||I.has(t)))return e}function ye(e){if(e.length>5&&F(e,`url`,!0))return e}function K(e){if(z.test(e))return e;if(f.test(e)){let t=Number.parseFloat(e);if(!Number.isNaN(t))return`${U(t)}%`}}function be(e){return/^\d*\.\d+$/.test(e)?e:K(e)}function xe(e){if(!e)return;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(!R.test(n)||!R.test(r))return;let i=Number(r);if(i===0)return;let a=Number(n)/i;if(Number.isFinite(a))return a===0?`0`:`${U(a*100)}%`}function Se(e){let t=G(e);if(t!=null)return Number(t)===0?`0`:`calc(var(--spacing) * ${t})`}function q(e){return j(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;let a=i;if(i?.startsWith(`$`)){if(a=J(i),a==null)return}else if(i!=null&&!v(i))return;return`var(--${l(r)}${a?`, ${a}`:``})`}function Ce(e){let t=e.match(B);if(!t)return;let[,n,r]=t,i=Number(n);if(Number.isFinite(i))return i===0&&!r?`0s`:r?`${U(i)}${r}`:`${U(i)}ms`}function we(e){let t=e.match(V);if(!t)return;let[,n,r]=t,i=Number(n);if(Number.isFinite(i))return i===0&&!r?`0`:r?`${U(i)}${r}`:`${U(i)}deg`}function Y(e){if(I.has(e))return e}function Te(e){if(e.split(`,`).every(e=>H.includes(e)))return e}function Ee(e){if([`top`,`left`,`right`,`bottom`,`center`].includes(e))return e}function De(e){if([`top`,`bottom`,`left`,`right`,`center`,`top-left`,`top-right`,`bottom-left`,`bottom-right`].includes(e))return e}function Oe(e){if(e===`none`)return`none`}function ke(e){if(e===`none`||e===`zero`)return`0`}function X(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 Z=Object.freeze({alpha:be,auto:ue,bracket:q,cssvar:J,customIdent:ve,degree:we,empty:de,fraction:xe,global:Y,integer:ge,none:Oe,number:G,numberWithUnit:W,percent:K,placement:De,position:Ee,positiveInteger:_e,properties:Te,px:he,rem:me,spacing:Se,square:fe,time:Ce,url:ye,video:pe,zero:ke}),Q=X(Z),$=Q;export{f as _,q as a,m as b,U as c,M as d,j as f,te as g,g as h,X as i,N as l,p as m,Q as n,J as o,_ as p,Z as r,Y as s,$ as t,P as u,d as v,h as x,ee as y};
|
|
@@ -2,7 +2,12 @@ import { Arrayable } from "@teacss/core";
|
|
|
2
2
|
//#region src/color-opacity.d.ts
|
|
3
3
|
declare function isValidOpacityModifier(value: string): boolean;
|
|
4
4
|
declare function resolveAlphaValue(value: string): string | undefined;
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Apply an optional `/NN` opacity (integer 0–100) to a color via
|
|
7
|
+
* `color-mix(in oklab, …)`. An invalid modifier throws instead of silently
|
|
8
|
+
* passing the color through — callers must pre-validate with
|
|
9
|
+
* {@link isValidOpacityModifier}.
|
|
10
|
+
*/
|
|
6
11
|
declare function applyOpacity(color: string, opacity?: string): string;
|
|
7
12
|
/** Split a color value on a depth-0 `/` into [color, opacity?]. */
|
|
8
13
|
declare function splitOpacity(value: string): [color: string, opacity?: string];
|
package/dist/value-resolvers.js
CHANGED
|
@@ -1 +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-sD8jGUUE.js";import{c as u,d,f,n as p,t as m,x as h}from"./standard-value-handler-
|
|
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-sD8jGUUE.js";import{c as u,d,f,n as p,t as m,x as h}from"./standard-value-handler-CmAdwmcK.js";function g(e){return/^\d{1,3}$/.test(e)&&Number(e)<=100}function _(e){let t=m.global.cssvar(e);if(t!=null)return t;let n=m.bracket(e);return n==null?a.test(e)?`${e}%`:m.alpha(e):o(n)?n:void 0}function v(e,t){if(t==null)return e;if(!g(t))throw Error(`applyOpacity received an invalid opacity modifier: ${t}`);return`color-mix(in oklab, ${e} ${Number(t)}%, transparent)`}function y(e){let t=n(e,`/`);return t<0?[e]:[e.slice(0,t),e.slice(t+1)]}function b(e){return m.cssvar(e)!=null}function x(e,t){return m.cssvar.global(e)??m.bracket(e)??(t.has(e)?e:void 0)}function S(e,t){return m.cssvar.global(e)??(t.has(e)?e:m.bracket(e))}function C(e,t){let n=p.fraction.number(e)??t;if(n==null)return;let r=String(n);return r.endsWith(`%`)?u(Number(r.slice(0,-1))/100):Number(n)}const w=RegExp(`^([+-]?(?:\\d+|\\d*\\.\\d+)(?:e[+-]?\\d+)?)(${e})?$`,`i`),T=/^[+-]?(?:\d+|\d*\.\d+)(?:e[+-]?\d+)?%$/i,E=new Set(t);function D(e){return i(e).map(e=>e.value)}function O(e){return/rpx$/i.test(e)||T.test(e)?!1:h.test(e)||w.test(e)}function k(e){if(/rpx$/i.test(e))return;let t=m.px(e);if(t!=null)return t;let n=e.match(w);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 A(e){let t=f(e);return t==null?e.startsWith(`[`)||e.endsWith(`]`)?!1:b(e)?!0:e.startsWith(`-`)||E.has(e)?!1:O(e):j(t).length===1&&D(t).length===1&&s(t)&&!l(t)}function j(e){return r(e)}function M(e){return j(e).some(e=>D(e).filter(e=>w.test(e)).slice(2,4).some(e=>Number(e.match(w)?.[1])<0))}const N=new Set;function P(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function F(e){return typeof e==`string`?e:e.join(`-`)}function I(e,t,n,r,i=N){let a=d(e,t);if(!a)return;let o=F(n),s=d(a,o);if(s!=null)return i.has(o)?typeof s==`string`?s:s.join(` `):`var(--${r??P(t)}-${o})`}function L(e){return e.replace(/\/\*[\s\S]*?\*\//g,` `).trim()}function R(e,t=[]){let n=m.bracket(e);if(n!=null){let e=r(n);return e.length>0&&e.every(e=>{let n=L(e);return t.includes(n)||c(n)&&!V(n)})?n:void 0}let i=m.cssvar.global(e);if(i!=null)return i;if(t.includes(e))return e;let a=m.time(e);return a?.startsWith(`-`)?void 0:a}function z(e){let t=m.bracket(e);if(t!=null){let e=r(t);return e.length>0&&e.every(e=>c(L(e)))?t:void 0}return m.cssvar.global.time(e)}const B=/^([+-]?(?:\d+|\d*\.\d+)(?:e[+-]?\d+)?)(?:ms|s)?$/i;function V(e){let t=e.match(B);return t!=null&&Number(t[1])<0}export{v as applyOpacity,P as camelToKebab,M as hasInvalidTextShadowRadius,b as isCssVariableToken,A as isNonnegativeLengthValue,g as isValidOpacityModifier,k as normalizeShadowLength,_ as resolveAlphaValue,x as resolveKeyword,S as resolveKeywordList,R as resolveNonnegativeTime,C as resolveNumber,I as resolveThemeVariable,z as resolveTime,y as splitOpacity,j as splitShadowLayers};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teacss/rule-helpers",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Helpers for authoring TeaCSS preset rules — static/dynamic rule builders and value resolvers.",
|
|
5
5
|
"homepage": "https://css.teasim.com",
|
|
6
6
|
"funding": "https://github.com/sponsors/billgo",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dev": "tsdown --watch"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@teacss/core": "0.3.
|
|
29
|
+
"@teacss/core": "0.3.7"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": ">=22.12.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{cssLengthUnitRESource as e,cssLengthUnits as t,globalKeywords as n}from"./constants.js";import{a as r,c as i,i as a,n as o,o as s,t as c}from"./css-identifier-4yDg85cV.js";import{escapeSelector as l}from"@teacss/core";const u=`(?:${t.join(`|`)})`,d=RegExp(`^(-?\\d*(?:\\.\\d+)?)(${u})?$`,`i`),f=/^(-?\d*(?:\.\d+)?)$/,p=/^-?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|grad|rad|turn)$/,m=/^-?(?:\d+(?:\.\d+)?|\.\d+)%$/,ee=RegExp(`^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)${e}$`,`i`),h={px:1,vw:100,vh:100,svw:100,svh:100,dvw:100,dvh:100,lvh:100,lvw:100},g=RegExp(`^(${Object.keys(h).join(`|`)})$`,`i`),_=/^\[(color|image|length|size|position|quoted|string):/i,te=new Set([...t,`angle`,`color`,`dpcm`,`deg`,`dpi`,`dppx`,`flex`,`fr`,`frequency`,`grad`,`hz`,`integer`,`khz`,`length`,`ms`,`number`,`percentage`,`rad`,`raw-string`,`resolution`,`s`,`string`,`time`,`turn`,`url`,`x`]);function v(e){return e.length>2&&e.startsWith(`--`)&&r(e)}function y(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 b(e){let t=(t,n)=>{let r=0,i;for(let a=t;a<e.length;a++){let t=e[a];if(i){t===`\\`?a++:t===i&&(i=void 0);continue}if(n&&(t===`"`||t===`'`))i=t;else if(t===`\\`)a++;else if(t===`(`||t===`{`)r++;else if(t===`)`||t===`}`){if(--r<0)return!1}else if(t===`;`&&r===0)return!1}return i===void 0?r===0:e.length},n=t(0,!0);return typeof n==`boolean`?n:t(0,!1)===!0}function x(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 59:case 91:case 92:case 93:case 95:case 96:case 123:case 125:return}return e.slice(1,t)}}function S(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 C(e,t){let n=0;for(;t>0&&e[--t]===`\\`;)n++;return n%2==1}function w(e,t){if(t===0)return!0;let n=e[t-1];return n===`_`&&!C(e,t-1)||n!==`\\`&&!s(n)}function T(e,t,n,r){for(let i=t;i<n;i++)e[i]===`_`&&!C(e,i)&&!ne(e,i)&&r.add(i)}function ne(e,t){let n=t-1,r=0;for(;n>=0&&r<6&&/[0-9a-f]/i.test(e[n]);)n--,r++;return r>0&&e[n]===`\\`&&!C(e,n)}function re(e,t,n){let r=e.lastIndexOf(`_`,n-1);for(;r>=t&&C(e,r);)r=e.lastIndexOf(`_`,r-1);return r}function ie(e,t,n){let r=re(e,t,n);if(r<t)return n;if(r===n-1&&e[n]===`%`)return r;let i=a(e.slice(r+1,n)).toLowerCase();return te.has(i)||i===`type`&&e[n]===`(`?r:n}function E(e){return e!=null&&e>=`0`&&e<=`9`}function ae(e,t,n){let r=E(e[n])||e[n]===`+`&&E(e[n+1]);if(e[n-1]===`_`&&!C(e,n-1)&&r)return n-1;let i=n;for(;i>t&&E(e[i-1]);)i--;if(i===n)return n;let a=n;for(;i>t&&e[i-1]===`_`&&!C(e,i-1);){a=--i;let n=i;for(;i>t&&E(e[i-1]);)i--;if(i===n)break}return a}function oe(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 se(e){let t=[],n=/(?:calc|clamp|max|min)\(/gi,r=0,i;for(;(i=n.exec(e))!==null;){if(!w(e,i.index))continue;let a=O(e,n.lastIndex);a!=null&&(t.push(e.slice(r,i.index),oe(e.slice(i.index,a))),r=a,n.lastIndex=a)}return r===0?e:(t.push(e.slice(r)),t.join(``))}function D(e,t){let n=e[t];if(n===`"`||n===`'`){for(let r=t+1;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===n)return r+1;return e.length}if(e[t]===`/`&&e[t+1]===`*`){let n=e.indexOf(`*/`,t+2);return n<0?e.length:n+2}}function ce(e,t){let n=t;for(;n<e.length;){if(i(e[n])||e[n]===`_`&&!C(e,n)){n++;continue}if(e[n]!==`/`||e[n+1]!==`*`)return n;let t=D(e,n);if(t==null)return n;n=t}return n}function le(e){let t=new Set,n=[];for(let r=0;r<e.length;){let i=D(e,r);if(i!=null){r=i;continue}let s=o(e,r);if(s==null||!w(e,r)){r++;continue}let c=a(e.slice(r,s));if(e[s]!==`(`){r=s;continue}let l=c.toLowerCase();if(l===`url`){let t=O(e,s+1);if(t==null)break;n.push({start:r,end:t}),r=t;continue}if(l===`attr`||l===`env`||l===`var`){let n=ce(e,s+1),r=o(e,n);r!=null&&T(e,n,l===`attr`?ie(e,n,r):l===`env`?ae(e,n,r):r,t)}r=s+1}return{indexes:t,literals:n}}function ue(e){let t=le(e),n=0,r=``;for(let i=0;i<e.length;i++){let a=t.literals[n];if(a&&i===a.start){r+=e.slice(a.start,a.end),i=a.end-1,n++;continue}if(e[i]===`\\`&&e[i+1]===`_`){r+=`_`,i++;continue}r+=e[i]===`_`&&!t.indexes.has(i)?` `:e[i]}return r}function O(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 k(e){let t=x(e);if(t!==void 0)return t;if(!e?.startsWith(`[`)||!e.endsWith(`]`))return;let n=e.match(_),r=e.slice(n?.[0].length??1,-1);if(!r||r===`=""`||!y(r))return;let i=n?.[1];if(i===`quoted`)return`"${S(r).replace(/(["\\])/g,`\\$1`)}"`;if(b(r))return i===`string`?S(r):(v(r)&&(r=`var(${r})`),se(ue(r)))}function A(e){return k(e)}function j(e,t){if(!(e==null||!Object.hasOwn(e,t)))return e[t]}function M(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=(c(e,t)??t+1)-1:n===i&&(i=void 0);continue}if(n===`'`||n===`"`){i=n;continue}if(n===`\\`){t=(c(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 a=e[t-1];if(t===0||!s(a))return t}return-1}function N(e,t){let n=M(e,t);return n>=0&&e.indexOf(`)`,n+t.length+1)>=0}function P(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 F=new Set(n),I=String.raw`[+-]?(?:\d+|\d*\.\d+)(?:[eE][+-]?\d+)?`,L=RegExp(`^${I}$`),R=RegExp(`^${I}%$`),z=RegExp(`^(${I})(s|ms)?$`,`i`),B=RegExp(`^(${I})(deg|rad|grad|turn)?$`,`i`),V=`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 H(e){return+e.toFixed(10)}function U(e){let t=e.match(d);if(!t)return;let[,n,r]=t,i=Number.parseFloat(n);if(r&&!Number.isNaN(i))return`${H(i)}${r}`}function de(e){if(e===`auto`)return`auto`}function fe(e){if(e===`full`)return`100%`}function pe(e){if(e===`empty`)return`""`}function me(e){if(e===`square`)return`1/1`}function he(e){if(e===`video`)return`16/9`}function ge(e){if(!e)return;if(g.test(e))return`${h[e.toLowerCase()]}${e}`;let t=e.match(d);if(!t)return;let[,n,r]=t,i=Number.parseFloat(n);if(!Number.isNaN(i))return i===0?`0`:r?`${H(i)}${r}`:`${H(i/4)}rem`}function _e(e){if(g.test(e))return`${h[e.toLowerCase()]}${e}`;let t=e?.match(d);if(!t)return;let[,n,r]=t,i=Number.parseFloat(n);if(!Number.isNaN(i))return r?`${H(i)}${r}`:`${H(i)}px`}function W(e){if(!f.test(e))return;let t=Number.parseFloat(e);if(!Number.isNaN(t))return H(t)}function ve(e){if(/^-?\d+$/.test(e))return e}function ye(e){if(/^[1-9]\d*$/.test(e))return e}function be(e){if(!r(e))return;let t=a(e).toLowerCase();if(!(t==="default"||F.has(t)))return e}function xe(e){if(e.length>5&&P(e,`url`,!0))return e}function G(e){if(R.test(e))return e;if(f.test(e)){let t=Number.parseFloat(e);if(!Number.isNaN(t))return`${H(t)}%`}}function Se(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(!L.test(n)||!L.test(r))return;let i=Number(r);if(i===0)return;let a=Number(n)/i;if(Number.isFinite(a))return a===0?`0`:`${H(a*100)}%`}function Ce(e){let t=K(e)||W(e);if(t==null)return;let n=String(t).endsWith(`%`)?H(Number(String(t).slice(0,-1))/100):Number(t);return n===0?`0`:`calc(var(--spacing) * ${n})`}function q(e){return A(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;let a=i;if(!(i?.startsWith(`$`)&&(a=J(i),a==null)))return`var(--${l(r)}${a?`, ${a}`:``})`}function we(e){let t=e.match(z);if(!t)return;let[,n,r]=t,i=Number(n);if(Number.isFinite(i))return i===0&&!r?`0s`:r?`${H(i)}${r}`:`${H(i)}ms`}function Y(e){let t=e.match(B);if(!t)return;let[,n,r]=t,i=Number(n);if(Number.isFinite(i))return i===0&&!r?`0`:r?`${H(i)}${r}`:`${H(i)}deg`}function X(e){if(F.has(e))return e}function Te(e){if(e.split(`,`).every(e=>V.includes(e)))return e}function Ee(e){if([`top`,`left`,`right`,`bottom`,`center`].includes(e))return e}function De(e){if([`top`,`bottom`,`left`,`right`,`center`,`top-left`,`top-right`,`bottom-left`,`bottom-right`].includes(e))return e}function Oe(e){if(e===`none`)return`none`}function ke(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:Se,auto:de,bracket:q,cssvar:J,customIdent:be,degree:Y,empty:pe,fraction:K,full:fe,global:X,integer:ve,none:Oe,number:W,numberWithUnit:U,percent:G,placement:De,position:Ee,positiveInteger:ye,properties:Te,px:_e,rem:ge,spacing:Ce,square:me,time:we,url:xe,video:he,zero:ke}),$=Z(Q),Ae=$;export{f as _,q as a,h as b,H as c,j as d,A as f,ee as g,_ as h,Z as i,M as l,p as m,$ as n,J as o,v as p,Q as r,X as s,Ae as t,N as u,d as v,g as x,m as y};
|