@symbo.ls/scratch 3.14.780 → 3.14.781

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.
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var B=(e,r)=>{for(var t in r)M(e,t,{get:r[t],enumerable:!0})},K=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Q(r))!z.call(e,o)&&o!==t&&M(e,o,{get:()=>r[o],enumerable:!(n=H(r,o))||n.enumerable});return e};var U=e=>K(M({},"__esModule",{value:!0}),e);var I={};B(I,{STANDARD_SCHEME_QUERIES:()=>P,getColor:()=>S,getMediaColor:()=>N,quietColorProbe:()=>X,resolveColorRgb:()=>v,schemeGuardSelector:()=>j,schemeMediaQuery:()=>O,setAdaptiveSchemeVar:()=>L,setColor:()=>E,setGradient:()=>W});module.exports=U(I);var d=require("@symbo.ls/utils"),R=require("../factory.js"),g=require("../utils/index.js");const P={light:"(prefers-color-scheme: light)",dark:"(prefers-color-scheme: dark)"},O=(e,r)=>{const t=r.media&&r.media[e]||P[e];return t?"@media "+(t==="print"?`${t}`:`screen and ${t}`):null},j=e=>{const r=e.scopeSelector||":root";return`${r===":root"?":root:not([data-theme])":`:root:not([data-theme]) ${r}:not([data-theme])`} &`},y=new Set,J=new Set(["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"]),C=new Set,T=e=>{if(!e)return!1;const{color:r,gradient:t}=e;return!!((0,d.isObject)(r)&&Object.keys(r).length||(0,d.isObject)(t)&&Object.keys(t).length)},_=new Set;let D=0;const X=e=>{D++;try{return e()}finally{D--}},Y=(e,r)=>{if(!(0,d.isString)(e)||e.indexOf(" ")===-1)return null;const t=e.replace(/\s+/g,""),n=(0,g.parseColorToken)(t);if(!n||n.passthrough||n.cssVar)return null;const{color:o,gradient:c}=r;return!o[n.name]&&!c[n.name]?null:t},x=(e,r,t)=>{const n=Y(e,t);if(n){if(!_.has(e)){_.add(e);const a=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color token \`${e}\` has a space before its alpha/tone modifier${a} \u2014 did you mean \`${n}\`? The space form never resolves, so the atomic class it mints carries no CSS value and paints invisibly. Dropped rather than shipped invisible.`)}return}const o=(0,g.parseColorToken)(e);if(o&&o.name&&!o.passthrough&&!o.cssVar&&(o.alpha!==void 0||o.tone!==void 0)&&T(t)&&!t.color[o.name]&&!t.gradient[o.name]){if(!D&&!C.has(e)){C.add(e);const a=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color token \`${e}\` does not resolve${a} \u2014 \`${o.name}\` is not in the palette. Dropped rather than emitted as a raw value, which is invalid CSS the browser discards silently. Define it in designSystem/color.js or use a palette token.`)}return}const c=(0,d.isString)(r)?r.toLowerCase():"";if(!J.has(c)||!T(t))return e;if(!C.has(c)){C.add(c);const a=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color \`${e}\` is a CSS named colour that is not in the palette${a}. Dropped rather than emitted as a raw browser colour, which renders theme-blind and can be unreadable ("looks designed", so it ships unnoticed). Define it in designSystem/color.js or use a palette token.`)}},S=(e,r,t)=>{const n=t||(0,R.getActiveConfig)();if(!(0,d.isString)(e)){n.verbose&&console.warn(e,"- type for color is not valid");return}if((0,g.isCSSVar)(e))return`var(${e})`;r&&e[r]&&(e=e[r]);let o,c,a;if((0,d.isArray)(e))[o,c,a]=e;else{const i=(0,g.parseColorToken)(e);if(!i){const{color:h,gradient:V}=n;let b=V[e]||h[e];return b?(r&&b[r]&&(b=b[r]),n.useVariable?`var(${b.var})`:b.value):x(e,e,n)}if(i.passthrough)return i.passthrough;if(i.cssVar)return`var(${i.cssVar})`;o=i.name,c=i.alpha,a=i.tone}const{color:m,gradient:u}=n;let s=m[o]||u[o];if(!s)return x(e,o,n);if(r)if(s[r]!==void 0)s=s[r];else if((0,d.isArray)(s)){const i=r.charCodeAt(0)===64?r.slice(1):r;i==="dark"?s=s[1]!==void 0?s[1]:s[0]:(i!=="light"&&n.verbose&&console.warn(e," - array-form color tokens only support light/dark; falling back to the light slot for scheme",r),s=s[0])}else n.verbose&&console.warn(e," - does not have ",r);if((0,d.isString)(s)){if(y.has(o))return s;y.add(o);try{return S(s,null,t)}finally{y.delete(o)}}let p=s.rgb;if(!p){const i=n.useVariable?`var(${s.var})`:s.value;if((c||a)&&i){const h=c!==void 0?c:1;if(!a)return`rgb(from ${i} r g b / ${h})`;if(a.charCodeAt(0)===43||a.charCodeAt(0)===45){const b=parseFloat(a),f=b<0?"-":"+",l=Math.abs(b);return`rgb(from ${i} calc(r ${f} ${l}) calc(g ${f} ${l}) calc(b ${f} ${l}) / ${h})`}return`hsl(from ${i} h s ${a}% / ${h})`}return i}return a&&!s[a]&&(p=(0,g.getRgbTone)(p,a),s[a]={rgb:p,var:`${s.var}-${a}`}),s[a]&&(p=s[a].rgb),c?`rgba(${p}, ${c})`:a?`rgba(${p}, ${s.alpha!==void 0?s.alpha:1})`:n.useVariable?`var(${s.var})`:s.value!==void 0?s.value:`rgb(${p})`},q=e=>{const r=(0,g.colorStringToRgbaArray)(e);return!r||r.length<3||r[0]===0&&r[1]===0&&r[2]===0&&r[3]===0&&e.toLowerCase()!=="transparent"?null:{rgb:[r[0],r[1],r[2]],alpha:r[3]!==void 0?r[3]:1}},Z=(e,r)=>{if(!r)return e;let t=e.rgb;if(r.tone){const o=(0,g.getRgbTone)(t,r.tone);t=(0,d.isString)(o)?o.split(",").map(c=>parseFloat(c.trim())):o}const n=r.alpha!==void 0?parseFloat(r.alpha):e.alpha;return{rgb:t,alpha:n}},v=(e,r,t)=>{const n=r||(0,R.getActiveConfig)();if(!(0,d.isString)(e))return null;const o=(0,g.parseColorToken)(e);if(o){if(o.passthrough){const h=(0,g.colorStringToRgbaArray)(o.passthrough);return h&&h.length>=3?{rgb:[h[0],h[1],h[2]],alpha:h[3]!==void 0?h[3]:1}:null}if(o.cssVar)return null}const c=o?o.name:e,{color:a,gradient:m}=n;let u=a[c]||m[c];if(!u)return q(e);if((0,d.isString)(u)){let h;if(y.has(c))h=q(u);else{y.add(c);try{h=v(u,n,t)}finally{y.delete(c)}}return h?Z(h,o):null}if(u.rgb===void 0&&(0,d.isObject)(u)){const h=`@${t||"light"}`;u=u[h]!==void 0?u[h]:u["@light"]}if(!u||u.rgb===void 0)return null;let s=u.rgb;o&&o.tone&&(s=(0,g.getRgbTone)(s,o.tone));const p=(0,d.isString)(s)?s.split(",").map(h=>parseFloat(h.trim())):s,i=o&&o.alpha!==void 0?parseFloat(o.alpha):u.alpha!==void 0?u.alpha:1;return{rgb:p,alpha:i}},N=(e,r,t)=>{const n=t||(0,R.getActiveConfig)();if(r||(r=n.globalTheme==="auto"?null:n.globalTheme),!(0,d.isString)(e)){n.verbose&&console.warn(e,"- type for color is not valid");return}if((0,g.isCSSVar)(e))return`var(${e})`;let o,c,a;if((0,d.isArray)(e))o=e[0];else{const i=(0,g.parseColorToken)(e);if(i){if(i.passthrough)return i.passthrough;if(i.cssVar)return`var(${i.cssVar})`;o=i.name,c=i.alpha,a=i.tone}else o=e}const{color:m,gradient:u}=n,s=m[o]||u[o],p=(0,d.isObject)(s);if(p&&s.value)return S(e,`@${r}`,t);if(p){if(n.useVariable&&s.var)return c||a?S(e,null,t):`var(${s.var})`;if(r)return S(e,`@${r}`,t);{const i={},h=j(n);for(const V in s){if(V.charCodeAt(0)!==64)continue;const b=V.slice(1),f=S(e,V,t);if(f!==void 0&&(i[`[data-theme="${b}"] &`]=f,b==="light"||b==="dark")){const l=O(b,n);if(!l)continue;i[l]={[h]:f}}}return i}}else return x(e,o,n)},L=(e,r,t,n)=>{const c=`--${n.varPrefix?n.varPrefix+"-":""}${r}-${t}`;let a;const m={};for(const u in e){if(u.charCodeAt(0)!==64)continue;const s=u.slice(1),p=e[u],i=p&&(p.value||p);!i||typeof i!="string"||(m[s]=i,(s==="light"||a===void 0)&&(a=i))}if(a!==void 0){n.cssVars[c]=a,n.cssMediaVars||(n.cssMediaVars={});for(const u in m){const s=`[data-theme="${u}"]`;if(n.cssMediaVars[s]||(n.cssMediaVars[s]={}),n.cssMediaVars[s][c]=m[u],u==="light"||u==="dark"){const p=`@media (prefers-color-scheme: ${u})`;n.cssMediaVars[p]||(n.cssMediaVars[p]={}),n.cssMediaVars[p][c]=m[u]}}return e.var=c,c}},E=(e,r,t)=>{const n=(0,R.getActiveConfig)();if((0,d.isObject)(e)&&e.value!==void 0&&(e.rgb!==void 0||e.var!==void 0))return n.useVariable&&e.var&&(n.cssVars[e.var]=e.value),e;if((0,d.isString)(e)&&(0,g.isCSSVar)(e)){const f=e.slice(2);if(e=S(f),!(e.includes("rgb")||e.includes("var")||e.includes("#"))){const l=f.split(" ");let $=n.color[l[0]];if($&&!$.value&&!$.rgb&&((0,d.isString)($)||(0,d.isArray)($)||(0,d.isObject)($))&&!y.has(l[0])){y.add(l[0]);try{n.color[l[0]]=E($,l[0])}finally{y.delete(l[0])}$=n.color[l[0]]}if($&&$.value){let w=$.rgb;const A=l[1]!==void 0?l[1]:"1",k=l[2];k&&(w=(0,g.getRgbTone)(w,k)),e=`rgba(${w}, ${A})`}else{const w=l[2],A=l[1]!==void 0?l[1]:"1";if(w)try{const k=(0,g.colorStringToRgbaArray)(l[0]);k&&k.length>=3?e=`rgba(${(0,g.getRgbTone)(k.slice(0,3).join(", "),w)}, ${A})`:e=l[0]}catch{e=l[0]}else e=l[0]}}}if((0,d.isArray)(e)&&(e={"@light":e[0],"@dark":e[1]!==void 0?e[1]:e[0]}),(0,d.isObject)(e)){const f={};for(const l in e)l!=="var"&&(f[l]=E(e[l],r,l.slice(0,1)==="@"?l.slice(1):l));return n.useVariable&&L(f,"color",r,n),f}const c=`--${n.varPrefix?n.varPrefix+"-":""}color-${r}`+(t?`-${t}`:"");let a=e.value||e;if((0,d.isString)(a)&&!a.includes("(")&&!a.startsWith("#")){const f=(0,g.parseColorToken)(a);if(f&&f.name&&!f.passthrough&&!f.cssVar){const l=n.color[f.name];if(l&&!l.value&&!l.rgb&&((0,d.isString)(l)||(0,d.isArray)(l)||(0,d.isObject)(l))&&!y.has(f.name)){y.add(f.name);try{n.color[f.name]=E(l,f.name)}finally{y.delete(f.name)}}const $=n.color[f.name];if($&&$.rgb){let w=$.rgb;f.tone&&(w=(0,g.getRgbTone)(w,f.tone));const A=f.alpha!==void 0?parseFloat(f.alpha):$.alpha!==void 0?$.alpha:1;a=`rgba(${w}, ${A})`}}}const m=(0,g.colorStringToRgbaArray)(a),[u,s,p,i=1]=m,h=parseFloat(i.toFixed(2)),V=`${u}, ${s}, ${p}`,b=`rgba(${V}, ${h})`;return n.useVariable&&(n.cssVars[c]=b),{var:c,rgb:V,alpha:h,value:b}},W=(e,r,t)=>{const n=(0,R.getActiveConfig)();if((0,d.isObject)(e)&&e.value!==void 0&&e.var!==void 0)return n.useVariable&&(n.cssVars[e.var]=e.value),e;if((0,d.isString)(e)&&(0,g.isCSSVar)(e)&&(e=S(e.slice(2))),(0,d.isArray)(e)&&(e={"@light":e[0],"@dark":e[1]!==void 0?e[1]:e[0]}),(0,d.isObject)(e)){const a={};for(const m in e)m!=="var"&&(a[m]=W(e[m],r,m.slice(0,1)==="@"?m.slice(1):m));return n.useVariable&&L(a,"gradient",r,n),a}const c=`--${n.varPrefix?n.varPrefix+"-":""}gradient-${r}`+(t?`-${t}`:"");return n.useVariable&&(n.cssVars[c]=e.value||e),{var:c,value:e.value||e}};
1
+ "use strict";var D=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var J=(e,r)=>{for(var t in r)D(e,t,{get:r[t],enumerable:!0})},X=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of N(r))!Y.call(e,s)&&s!==t&&D(e,s,{get:()=>r[s],enumerable:!(n=B(r,s))||n.enumerable});return e};var Z=e=>X(D({},"__esModule",{value:!0}),e);var ie={};J(ie,{STANDARD_SCHEME_QUERIES:()=>H,getColor:()=>V,getMediaColor:()=>oe,isPlainColor:()=>O,quietColorProbe:()=>ee,resolveColorRgb:()=>U,schemeGuardSelector:()=>Q,schemeMediaQuery:()=>K,setAdaptiveSchemeVar:()=>_,setColor:()=>E,setGradient:()=>z});module.exports=Z(ie);var c=require("@symbo.ls/utils"),R=require("../factory.js"),p=require("../utils/index.js");const H={light:"(prefers-color-scheme: light)",dark:"(prefers-color-scheme: dark)"},K=(e,r)=>{const t=r.media&&r.media[e]||H[e];return t?"@media "+(t==="print"?`${t}`:`screen and ${t}`):null},Q=e=>{const r=e.scopeSelector||":root";return`${r===":root"?":root:not([data-theme])":`:root:not([data-theme]) ${r}:not([data-theme])`} &`},w=new Set,x=new Set(["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"]),I=/^(?:#[0-9a-f]{3,8}$|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix)\()/i,F=/gradient\(|url\(|image-set\(|var\(/i,G=new Set(["transparent","currentColor","currentcolor"]),O=e=>{if(!(0,c.isString)(e))return!1;const r=e.trim();return F.test(r)?!1:I.test(r)?!0:x.has(r)||G.has(r)},C=new Set,P=e=>{if(!e)return!1;const{color:r,gradient:t}=e;return!!((0,c.isObject)(r)&&Object.keys(r).length||(0,c.isObject)(t)&&Object.keys(t).length)},T=new Set;let L=0;const ee=e=>{L++;try{return e()}finally{L--}},re=(e,r)=>{if(!(0,c.isString)(e)||e.indexOf(" ")===-1)return null;const t=e.replace(/\s+/g,""),n=(0,p.parseColorToken)(t);if(!n||n.passthrough||n.cssVar)return null;const{color:s,gradient:a}=r;return!s[n.name]&&!a[n.name]?null:t},M=(e,r,t)=>{const n=re(e,t);if(n){if(!T.has(e)){T.add(e);const i=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color token \`${e}\` has a space before its alpha/tone modifier${i} \u2014 did you mean \`${n}\`? The space form never resolves, so the atomic class it mints carries no CSS value and paints invisibly. Dropped rather than shipped invisible.`)}return}const s=(0,p.parseColorToken)(e);if(s&&s.name&&!s.passthrough&&!s.cssVar&&(s.alpha!==void 0||s.tone!==void 0)&&P(t)&&!t.color[s.name]&&!t.gradient[s.name]){if(!L&&!C.has(e)){C.add(e);const i=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color token \`${e}\` does not resolve${i} \u2014 \`${s.name}\` is not in the palette. Dropped rather than emitted as a raw value, which is invalid CSS the browser discards silently. Define it in designSystem/color.js or use a palette token.`)}return}const a=(0,c.isString)(r)?r.toLowerCase():"";if(!x.has(a)||!P(t))return e;if(!C.has(a)){C.add(a);const i=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color \`${e}\` is a CSS named colour that is not in the palette${i}. Dropped rather than emitted as a raw browser colour, which renders theme-blind and can be unreadable ("looks designed", so it ships unnoticed). Define it in designSystem/color.js or use a palette token.`)}},q=(e,r,t)=>{const n=r!==void 0?r:1;if(!t)return`rgb(from ${e} r g b / ${n})`;if(t.charCodeAt(0)===43||t.charCodeAt(0)===45){const a=parseFloat(t),i=a<0?"-":"+",f=Math.abs(a);return`rgb(from ${e} calc(r ${i} ${f}) calc(g ${i} ${f}) calc(b ${i} ${f}) / ${n})`}return`hsl(from ${e} h s ${t}% / ${n})`},V=(e,r,t)=>{const n=t||(0,R.getActiveConfig)();if(!(0,c.isString)(e)){n.verbose&&console.warn(e,"- type for color is not valid");return}if((0,p.isCSSVar)(e))return`var(${e})`;r&&e[r]&&(e=e[r]);let s,a,i;if((0,c.isArray)(e))[s,a,i]=e;else{const l=(0,p.parseColorToken)(e);if(!l){const{color:g,gradient:k}=n;let $=k[e]||g[e];return $?(r&&$[r]&&($=$[r]),n.useVariable?`var(${$.var})`:$.value):M(e,e,n)}if(l.passthrough)return l.passthrough;if(l.cssVar)return`var(${l.cssVar})`;s=l.name,a=l.alpha,i=l.tone}const{color:f,gradient:d}=n;let o=f[s]||d[s];if(!o)return M(e,s,n);if(r)if(o[r]!==void 0)o=o[r];else if((0,c.isArray)(o)){const l=r.charCodeAt(0)===64?r.slice(1):r;l==="dark"?o=o[1]!==void 0?o[1]:o[0]:(l!=="light"&&n.verbose&&console.warn(e," - array-form color tokens only support light/dark; falling back to the light slot for scheme",r),o=o[0])}else n.verbose&&console.warn(e," - does not have ",r);if((0,c.isString)(o)){if(w.has(s))return o;w.add(s);try{return V(o,null,t)}finally{w.delete(s)}}let m=o.rgb;if(!m){const l=n.useVariable?`var(${o.var})`:o.value;return(a||i)&&l?q(l,a,i):l}return i&&!o[i]&&(m=(0,p.getRgbTone)(m,i),o[i]={rgb:m,var:`${o.var}-${i}`}),o[i]&&(m=o[i].rgb),a?`rgba(${m}, ${a})`:i?`rgba(${m}, ${o.alpha!==void 0?o.alpha:1})`:n.useVariable?`var(${o.var})`:o.value!==void 0?o.value:`rgb(${m})`},j=e=>{const r=(0,p.colorStringToRgbaArray)(e);return!r||r.length<3||r[0]===0&&r[1]===0&&r[2]===0&&r[3]===0&&e.toLowerCase()!=="transparent"?null:{rgb:[r[0],r[1],r[2]],alpha:r[3]!==void 0?r[3]:1}},ne=(e,r)=>{if(!r)return e;let t=e.rgb;if(r.tone){const s=(0,p.getRgbTone)(t,r.tone);t=(0,c.isString)(s)?s.split(",").map(a=>parseFloat(a.trim())):s}const n=r.alpha!==void 0?parseFloat(r.alpha):e.alpha;return{rgb:t,alpha:n}},U=(e,r,t)=>{const n=r||(0,R.getActiveConfig)();if(!(0,c.isString)(e))return null;const s=(0,p.parseColorToken)(e);if(s){if(s.passthrough){const g=(0,p.colorStringToRgbaArray)(s.passthrough);return g&&g.length>=3?{rgb:[g[0],g[1],g[2]],alpha:g[3]!==void 0?g[3]:1}:null}if(s.cssVar)return null}const a=s?s.name:e,{color:i,gradient:f}=n;let d=i[a]||f[a];if(!d)return j(e);if((0,c.isString)(d)){let g;if(w.has(a))g=j(d);else{w.add(a);try{g=U(d,n,t)}finally{w.delete(a)}}return g?ne(g,s):null}if(d.rgb===void 0&&(0,c.isObject)(d)){const g=`@${t||"light"}`;d=d[g]!==void 0?d[g]:d["@light"]}if(!d||d.rgb===void 0)return null;let o=d.rgb;s&&s.tone&&(o=(0,p.getRgbTone)(o,s.tone));const m=(0,c.isString)(o)?o.split(",").map(g=>parseFloat(g.trim())):o,l=s&&s.alpha!==void 0?parseFloat(s.alpha):d.alpha!==void 0?d.alpha:1;return{rgb:m,alpha:l}},W=e=>(0,c.isObject)(e)&&e.value!==void 0&&(e.rgb!==void 0||e.var!==void 0),v=e=>{if(!(0,c.isObject)(e)||e.value!==void 0)return null;const r=[];for(const t in e)if(t!=="var"){if(t.charCodeAt(0)!==64||!W(e[t]))return null;r.push(t.slice(1))}return r.length?r:null},te=e=>(0,c.isString)(e&&e.var)&&v(e)!==null,se=(e,r,t,n,s)=>{const a=v(r);if(!a)return;if((0,c.isString)(r.var)){const d=`var(${r.var})`;return t||n?q(d,t,n):d}if(a.length!==2||!a.includes("light")||!a.includes("dark"))return;const i=V(e,"@light",s),f=V(e,"@dark",s);if(!(!O(i)||!O(f)))return i===f?i:`light-dark(${i}, ${f})`},oe=(e,r,t)=>{const n=t||(0,R.getActiveConfig)();if(r||(r=n.globalTheme==="auto"?null:n.globalTheme),!(0,c.isString)(e)){n.verbose&&console.warn(e,"- type for color is not valid");return}if((0,p.isCSSVar)(e))return`var(${e})`;let s,a,i;if((0,c.isArray)(e))s=e[0];else{const l=(0,p.parseColorToken)(e);if(l){if(l.passthrough)return l.passthrough;if(l.cssVar)return`var(${l.cssVar})`;s=l.name,a=l.alpha,i=l.tone}else s=e}const{color:f,gradient:d}=n,o=f[s]||d[s],m=(0,c.isObject)(o);if(m&&o.value)return V(e,`@${r}`,t);if(m){if(n.useVariable&&o.var)return a||i?V(e,null,t):`var(${o.var})`;if(r){if(!n.useVariable&&f[s]===o){const l=se(e,o,a,i,t);if(l!==void 0)return l}return V(e,`@${r}`,t)}else{const l={},g=Q(n);for(const k in o){if(k.charCodeAt(0)!==64)continue;const $=k.slice(1),h=V(e,k,t);if(h!==void 0&&(l[`[data-theme="${$}"] &`]=h,$==="light"||$==="dark")){const u=K($,n);if(!u)continue;l[u]={[g]:h}}}return l}}else return M(e,s,n)},_=(e,r,t,n)=>{const a=`--${n.varPrefix?n.varPrefix+"-":""}${r}-${t}`;let i;const f={};for(const d in e){if(d.charCodeAt(0)!==64)continue;const o=d.slice(1),m=e[d],l=m&&(m.value||m);!l||typeof l!="string"||(f[o]=l,(o==="light"||i===void 0)&&(i=l))}if(i!==void 0){n.cssVars[a]=i,n.cssMediaVars||(n.cssMediaVars={});for(const d in f){const o=`[data-theme="${d}"]`;if(n.cssMediaVars[o]||(n.cssMediaVars[o]={}),n.cssMediaVars[o][a]=f[d],d==="light"||d==="dark"){const m=`@media (prefers-color-scheme: ${d})`;n.cssMediaVars[m]||(n.cssMediaVars[m]={}),n.cssMediaVars[m][a]=f[d]}}return e.var=a,a}},E=(e,r,t)=>{const n=(0,R.getActiveConfig)();if(W(e))return n.useVariable&&e.var&&(n.cssVars[e.var]=e.value),e;if(!n.useVariable&&te(e))return e;if((0,c.isString)(e)&&(0,p.isCSSVar)(e)){const h=e.slice(2);if(e=V(h),!(e.includes("rgb")||e.includes("var")||e.includes("#"))){const u=h.split(" ");let b=n.color[u[0]];if(b&&!b.value&&!b.rgb&&((0,c.isString)(b)||(0,c.isArray)(b)||(0,c.isObject)(b))&&!w.has(u[0])){w.add(u[0]);try{n.color[u[0]]=E(b,u[0])}finally{w.delete(u[0])}b=n.color[u[0]]}if(b&&b.value){let y=b.rgb;const A=u[1]!==void 0?u[1]:"1",S=u[2];S&&(y=(0,p.getRgbTone)(y,S)),e=`rgba(${y}, ${A})`}else{const y=u[2],A=u[1]!==void 0?u[1]:"1";if(y)try{const S=(0,p.colorStringToRgbaArray)(u[0]);S&&S.length>=3?e=`rgba(${(0,p.getRgbTone)(S.slice(0,3).join(", "),y)}, ${A})`:e=u[0]}catch{e=u[0]}else e=u[0]}}}if((0,c.isArray)(e)&&(e={"@light":e[0],"@dark":e[1]!==void 0?e[1]:e[0]}),(0,c.isObject)(e)){const h={};for(const u in e)u!=="var"&&(h[u]=E(e[u],r,u.slice(0,1)==="@"?u.slice(1):u));return n.useVariable&&_(h,"color",r,n),h}const a=`--${n.varPrefix?n.varPrefix+"-":""}color-${r}`+(t?`-${t}`:"");let i=e.value||e;if((0,c.isString)(i)&&!i.includes("(")&&!i.startsWith("#")){const h=(0,p.parseColorToken)(i);if(h&&h.name&&!h.passthrough&&!h.cssVar){const u=n.color[h.name];if(u&&!u.value&&!u.rgb&&((0,c.isString)(u)||(0,c.isArray)(u)||(0,c.isObject)(u))&&!w.has(h.name)){w.add(h.name);try{n.color[h.name]=E(u,h.name)}finally{w.delete(h.name)}}const b=n.color[h.name];if(b&&b.rgb){let y=b.rgb;h.tone&&(y=(0,p.getRgbTone)(y,h.tone));const A=h.alpha!==void 0?parseFloat(h.alpha):b.alpha!==void 0?b.alpha:1;i=`rgba(${y}, ${A})`}}}const f=(0,p.colorStringToRgbaArray)(i),[d,o,m,l=1]=f,g=parseFloat(l.toFixed(2)),k=`${d}, ${o}, ${m}`,$=`rgba(${k}, ${g})`;return n.useVariable&&(n.cssVars[a]=$),{var:a,rgb:k,alpha:g,value:$}},z=(e,r,t)=>{const n=(0,R.getActiveConfig)();if((0,c.isObject)(e)&&e.value!==void 0&&e.var!==void 0)return n.useVariable&&(n.cssVars[e.var]=e.value),e;if((0,c.isString)(e)&&(0,p.isCSSVar)(e)&&(e=V(e.slice(2))),(0,c.isArray)(e)&&(e={"@light":e[0],"@dark":e[1]!==void 0?e[1]:e[0]}),(0,c.isObject)(e)){const i={};for(const f in e)f!=="var"&&(i[f]=z(e[f],r,f.slice(0,1)==="@"?f.slice(1):f));return n.useVariable&&_(i,"gradient",r,n),i}const a=`--${n.varPrefix?n.varPrefix+"-":""}gradient-${r}`+(t?`-${t}`:"");return n.useVariable&&(n.cssVars[a]=e.value||e),{var:a,value:e.value||e}};
@@ -1 +1 @@
1
- "use strict";var j=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var Z=(e,o)=>{for(var r in o)j(e,r,{get:o[r],enumerable:!0})},J=(e,o,r,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of Q(o))!Y.call(e,i)&&i!==r&&j(e,i,{get:()=>o[i],enumerable:!(t=N(o,i))||t.enumerable});return e};var K=e=>J(j({},"__esModule",{value:!0}),e);var le={};Z(le,{getMediaTheme:()=>M,getTheme:()=>G,setMediaTheme:()=>O,setTheme:()=>ne});module.exports=K(le);var T=require("./color.js"),x=require("./shadow.js"),$=require("./border.js"),v=require("../factory.js"),V=require("../utils/color.js"),l=require("@symbo.ls/utils");const E=new Set(["black","white","red","green","blue","yellow","orange","purple","pink","brown","gray","grey","cyan","magenta","lime","olive","navy","teal","aqua","maroon","silver","fuchsia","transparent","currentColor","currentcolor","inherit","initial","unset","none","aliceblue","antiquewhite","aquamarine","azure","beige","bisque","blanchedalmond","blueviolet","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","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","gainsboro","ghostwhite","gold","goldenrod","greenyellow","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","limegreen","linen","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","oldlace","olivedrab","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","plum","powderblue","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","thistle","tomato","turquoise","violet","wheat","whitesmoke","yellowgreen","rebeccapurple"]),L=["color","Color","background","Background","fill","Fill","stroke","Stroke"],q=e=>{for(let o=0;o<L.length;o++)if(e.includes(L[o]))return!0;return!1},X={boxShadow:x.resolveShadowValue,textShadow:x.resolveShadowValue,border:$.resolveBorderValue,borderTop:$.resolveBorderValue,borderRight:$.resolveBorderValue,borderBottom:$.resolveBorderValue,borderLeft:$.resolveBorderValue,outline:$.resolveBorderValue,columnRule:$.resolveBorderValue},F=e=>{if(!e)return!1;const o=(0,V.parseColorToken)(e);return!o||!o.name||o.passthrough||o.cssVar?!1:o.alpha!==void 0||o.tone!==void 0},P=new Set,I=(e,o,r,t,i,a)=>{if(!(0,l.isLoudDevRuntime)())return;const s=`${e}::${o}::${r||""}::${t}`;P.has(s)||(P.add(s),console.warn(`[smbls/scratch] theme param "${o}" on "${e}"`+(r?` (${r})`:"")+` did not fully resolve: "${t}" -> "${i}" still contains the unresolved token "${a}". This is not valid CSS \u2014 the browser will drop the whole declaration. Register "${a}" as a design-system color token or fix the typo.`))},C=(e,o,r,t)=>{const i=X[o];if(!i)return(0,T.getColor)(r,t);let a=null;const s=i(r,t,h=>{!a&&F(h)&&(a=h)});return a&&I(e,o,t,r,s,a),s},G=(e,o)=>M(e,o),ee=e=>(0,l.isObject)(e)&&(0,l.isObjectLike)(e.value),oe=e=>{for(const o in e){const r=e[o];if((0,l.isString)(r)&&r.startsWith("var(--"))return!0}return!1},ne=(e,o)=>{const r=(0,v.getActiveConfig)();return ee(e)?!r.useVariable&&oe(e)?e:O(e.value,o):O(e,o)},D=(e,o)=>{const r=new Set;for(const t of o){const i=t.slice(0,1);if(!(i==="@"||i==="."||i===":")&&q(t))for(const a in e){if(r.has(a))continue;const s=e[a]?.[t];if(s===void 0)continue;const h=(0,T.getColor)(s,`@${a}`);h!==void 0&&(0,l.isString)(h)&&/^[a-z][a-zA-Z]+$/.test(h)&&!E.has(h)&&r.add(a)}}return r},re=new Set(["none","inherit","initial","unset","revert","revert-layer"]),te=/^(?:#[0-9a-f]{3,8}$|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix)\()/i,ie=/gradient\(|url\(|image-set\(|var\(/i,W=e=>{if(!(0,l.isString)(e))return!1;const o=e.trim();return ie.test(o)?!1:te.test(o)?!0:E.has(o)&&!re.has(o)},se=e=>e.startsWith("[data-theme=")||e.startsWith("@media"),R=(e,o)=>{for(const r in o){const t=o[r];(0,l.isObject)(t)?R(e[r]||(e[r]={}),t):e[r]=t}return e},B=(e,o,r,t)=>{if(R(e,{[`[data-theme="${o}"] &`]:r}),o!=="light"&&o!=="dark")return;const i=(0,T.schemeMediaQuery)(o,t);i&&R(e,{[i]:{[(0,T.schemeGuardSelector)(t)]:r}})},U=(e,o,r,t)=>{const i=r.globalTheme!==void 0?r.globalTheme:"auto",a=i&&i!=="auto"?String(i).replace(/^'|'$/g,""):null,s=new Set(t?Object.keys(t):[]);for(const n in e)if(e[n])for(const c of Object.keys(e[n]))s.add(c);const h=D(e,s),g={};for(const n of s){const c=n.slice(0,1);if(c==="@")continue;if(c==="."||c===":"){const u={};for(const w in e)(0,l.isObjectLike)(e[w]?.[n])&&(u[w]=e[w][n]);const m=t&&(0,l.isObjectLike)(t[n])?t[n]:void 0;if(!Object.keys(u).length&&!m)continue;const b=c==="."?n.slice(1):n.replace(/^:+/,"");g[n]=U(u,`${o}-${b}`,r,m);continue}const k=t&&!(0,l.isObjectLike)(t[n])?t[n]:void 0,p=new Set(Object.keys(e));k!==void 0&&(p.add("light"),p.add("dark"),a&&p.add(a));const d={};let f;for(const u of p){if(h.has(u))continue;let m=e[u]?.[n];if((m===void 0||(0,l.isObjectLike)(m))&&(m=k),m===void 0)continue;const b=C(o,n,m,`@${u}`);b!==void 0&&(d[u]=b,(a&&u===a||!a&&(u==="light"||f===void 0))&&(f=b))}const y={},S=Object.keys(d).filter(u=>d[u]!==f);if(S.length){const u=d.light!==void 0?d.light:f,m=d.dark!==void 0?d.dark:f;if(q(n)&&W(u)&&W(m)){y[n]=u===m?u:`light-dark(${u}, ${m})`;for(const b in d)b==="light"||b==="dark"||B(y,b,{[n]:d[b]},r)}else{f!==void 0&&(y[n]=f);for(const b of S)B(y,b,{[n]:d[b]},r)}}else{if(f===void 0)continue;y[n]=f}R(g,y),g[`.${n}`]=y}return(g.background||g.color||g.backgroundColor)&&(g[".inversed"]={color:g.background||g.backgroundColor,background:g.color}),g},_=(e,o,r)=>{const{cssVars:t}=r;r.cssMediaVars||(r.cssMediaVars={});const i=r.cssMediaVars,a=r.globalTheme!==void 0?r.globalTheme:"auto",s={},h=new Set;for(const n in e)if(e[n])for(const c of Object.keys(e[n]))h.add(c);const g=D(e,h);for(const n of h){const c=n.slice(0,1),k=Object.values(e).some(p=>(0,l.isObjectLike)(p?.[n]));if(c==="."&&k){const p=n.slice(1),d={};for(const f in e)(0,l.isObjectLike)(e[f]?.[n])&&(d[f]=e[f][n]);s[n]=_(d,`${o}-${p}`,r)}else if(c===":"&&k){const p=n.replace(/^:+/,""),d={};for(const f in e)(0,l.isObjectLike)(e[f]?.[n])&&(d[f]=e[f][n]);s[n]=_(d,`${o}-${p}`,r)}else if(c!=="@"&&c!=="."&&c!==":"){const d=`--${r.varPrefix?r.varPrefix+"-":""}theme-${o}-${n}`,f=a&&a!=="auto"?String(a).replace(/^'|'$/g,""):null;let y;for(const S in e){if(g.has(S))continue;const u=e[S]?.[n];if(u===void 0)continue;const m=C(o,n,u,`@${S}`);if(m===void 0)continue;(f&&S===f||!f&&(S==="light"||y===void 0))&&(y=m);const b=`[data-theme="${S}"]`;if(i[b]||(i[b]={}),i[b][d]=m,S==="dark"||S==="light"){const w=`@media (prefers-color-scheme: ${S})`;i[w]||(i[w]={}),i[w][d]=m}}y!==void 0&&(t[d]=y),s[n]=`var(${d})`,s[`.${n}`]={[n]:s[n]}}}return(s.background||s.color||s.backgroundColor)&&(s[".inversed"]={color:s.background||s.backgroundColor,background:s.color}),s},O=(e,o,r,t)=>{const i=(0,v.getActiveConfig)(),{cssVars:a}=i,s={value:e},h=!r&&!t;let g;if((0,l.isObjectLike)(e)){if(h&&i.useVariable){const n={};for(const c in e)c.startsWith("@")&&(0,l.isObjectLike)(e[c])&&(n[c.slice(1)]=e[c]);if(Object.keys(n).length){const c=_(n,o,i);Object.assign(s,c)}}else if(h){const n={},c={};for(const k in e)k.startsWith("@")?(0,l.isObjectLike)(e[k])&&(n[k.slice(1)]=e[k]):c[k]=e[k];g=U(n,o,i,c),Object.assign(s,g)}for(const n in e){const c=n.slice(0,1),k=e[n];if(c==="@"||c===":"||c==="."){const p=c==="@"&&n;s[n]=O(k,o,n,t||p)}else if(!h){const p=C(o,n,k,t),d=[...new Set([t,r].filter(u=>u).map(u=>u.slice(1)))],f=d.length?"-"+d.join("-"):"",S=`--${i.varPrefix?i.varPrefix+"-":""}theme-${o}${f}-${n}`;i.useVariable?(i.useThemeSuffixedVars&&(a[S]=p),s[n]=`var(${S})`):s[n]=p,s[`.${n}`]={[n]:s[n]}}}if(g)for(const n in g){const c=n.slice(0,1);(c==="."||c===":")&&(0,l.isObjectLike)(e[n])&&(s[n]=g[n])}!s[".inversed"]&&(s.background||s.color||s.backgroundColor)&&(s[".inversed"]={color:s.background||s.backgroundColor,background:s.color})}if((0,l.isString)(e)&&(0,V.isCSSVar)(e)){const c=i.theme[e.slice(2)];return M(c,t)}return s},A=(e,o)=>{const r={};for(const t in e){const i=t.slice(0,1);if((0,l.isObjectLike)(e[t]))if(o&&se(t))r[t]=R({},e[t]);else{if(i==="@")continue;i===":"?r[`&${t}`]=A(e[t],o):i==="."&&(r[`&${t}`]=A(e[t],o))}else r[t]=e[t]}return r},z=(e,o)=>{const r=o.shift();return e[r]?z(e[r],o):e},H=(e,o)=>(0,l.isArray)(o)?z(e,o):(0,l.isString)(o)&&e[o]?e[o]:e,ce=(e,o)=>(0,l.isString)(e)&&(0,V.isCSSVar)(e)?M(e.slice(2)):e,ae=e=>ce(e,ae),M=(e,o)=>{const r=(0,v.getActiveConfig)();if((0,l.isString)(e)&&(0,V.isCSSVar)(e)&&(e=M(e.slice(2))),!e||!(0,l.isString)(e)){r.verbose&&console.warn(`${e} - Theme is not a string`);return}const[t,...i]=(0,l.isArray)(e)?e:e.split(" ");let a=r.theme[t];return a&&i.length?a=H(a,i):a&&o&&(a=H(a,o)),A(a,!r.useVariable)};
1
+ "use strict";var A=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var Z=(e,o)=>{for(var r in o)A(e,r,{get:o[r],enumerable:!0})},J=(e,o,r,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of U(o))!Q.call(e,i)&&i!==r&&A(e,i,{get:()=>o[i],enumerable:!(t=H(o,i))||t.enumerable});return e};var X=e=>J(A({},"__esModule",{value:!0}),e);var ie={};Z(ie,{getMediaTheme:()=>R,getTheme:()=>G,setMediaTheme:()=>v,setTheme:()=>oe});module.exports=X(ie);var $=require("./color.js"),O=require("./shadow.js"),w=require("./border.js"),j=require("../factory.js"),V=require("../utils/color.js"),l=require("@symbo.ls/utils");const Y=new Set(["black","white","red","green","blue","yellow","orange","purple","pink","brown","gray","grey","cyan","magenta","lime","olive","navy","teal","aqua","maroon","silver","fuchsia","transparent","currentColor","currentcolor","inherit","initial","unset","none","aliceblue","antiquewhite","aquamarine","azure","beige","bisque","blanchedalmond","blueviolet","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","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","gainsboro","ghostwhite","gold","goldenrod","greenyellow","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","limegreen","linen","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","oldlace","olivedrab","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","plum","powderblue","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","thistle","tomato","turquoise","violet","wheat","whitesmoke","yellowgreen","rebeccapurple"]),_=["color","Color","background","Background","fill","Fill","stroke","Stroke"],E=e=>{for(let o=0;o<_.length;o++)if(e.includes(_[o]))return!0;return!1},K={boxShadow:O.resolveShadowValue,textShadow:O.resolveShadowValue,border:w.resolveBorderValue,borderTop:w.resolveBorderValue,borderRight:w.resolveBorderValue,borderBottom:w.resolveBorderValue,borderLeft:w.resolveBorderValue,outline:w.resolveBorderValue,columnRule:w.resolveBorderValue},N=e=>{if(!e)return!1;const o=(0,V.parseColorToken)(e);return!o||!o.name||o.passthrough||o.cssVar?!1:o.alpha!==void 0||o.tone!==void 0},P=new Set,F=(e,o,r,t,i,a)=>{if(!(0,l.isLoudDevRuntime)())return;const s=`${e}::${o}::${r||""}::${t}`;P.has(s)||(P.add(s),console.warn(`[smbls/scratch] theme param "${o}" on "${e}"`+(r?` (${r})`:"")+` did not fully resolve: "${t}" -> "${i}" still contains the unresolved token "${a}". This is not valid CSS \u2014 the browser will drop the whole declaration. Register "${a}" as a design-system color token or fix the typo.`))},C=(e,o,r,t)=>{const i=K[o];if(!i)return(0,$.getColor)(r,t);let a=null;const s=i(r,t,h=>{!a&&N(h)&&(a=h)});return a&&F(e,o,t,r,s,a),s},G=(e,o)=>R(e,o),I=e=>(0,l.isObject)(e)&&(0,l.isObjectLike)(e.value),ee=e=>{for(const o in e){const r=e[o];if((0,l.isString)(r)&&r.startsWith("var(--"))return!0}return!1},oe=(e,o)=>{const r=(0,j.getActiveConfig)();return I(e)?!r.useVariable&&ee(e)?e:v(e.value,o):v(e,o)},L=(e,o)=>{const r=new Set;for(const t of o){const i=t.slice(0,1);if(!(i==="@"||i==="."||i===":")&&E(t))for(const a in e){if(r.has(a))continue;const s=e[a]?.[t];if(s===void 0)continue;const h=(0,$.getColor)(s,`@${a}`);h!==void 0&&(0,l.isString)(h)&&/^[a-z][a-zA-Z]+$/.test(h)&&!Y.has(h)&&r.add(a)}}return r},ne=e=>e.startsWith("[data-theme=")||e.startsWith("@media"),M=(e,o)=>{for(const r in o){const t=o[r];(0,l.isObject)(t)?M(e[r]||(e[r]={}),t):e[r]=t}return e},B=(e,o,r,t)=>{if(M(e,{[`[data-theme="${o}"] &`]:r}),o!=="light"&&o!=="dark")return;const i=(0,$.schemeMediaQuery)(o,t);i&&M(e,{[i]:{[(0,$.schemeGuardSelector)(t)]:r}})},D=(e,o,r,t)=>{const i=r.globalTheme!==void 0?r.globalTheme:"auto",a=i&&i!=="auto"?String(i).replace(/^'|'$/g,""):null,s=new Set(t?Object.keys(t):[]);for(const n in e)if(e[n])for(const c of Object.keys(e[n]))s.add(c);const h=L(e,s),g={};for(const n of s){const c=n.slice(0,1);if(c==="@")continue;if(c==="."||c===":"){const u={};for(const T in e)(0,l.isObjectLike)(e[T]?.[n])&&(u[T]=e[T][n]);const m=t&&(0,l.isObjectLike)(t[n])?t[n]:void 0;if(!Object.keys(u).length&&!m)continue;const b=c==="."?n.slice(1):n.replace(/^:+/,"");g[n]=D(u,`${o}-${b}`,r,m);continue}const k=t&&!(0,l.isObjectLike)(t[n])?t[n]:void 0,p=new Set(Object.keys(e));k!==void 0&&(p.add("light"),p.add("dark"),a&&p.add(a));const d={};let f;for(const u of p){if(h.has(u))continue;let m=e[u]?.[n];if((m===void 0||(0,l.isObjectLike)(m))&&(m=k),m===void 0)continue;const b=C(o,n,m,`@${u}`);b!==void 0&&(d[u]=b,(a&&u===a||!a&&(u==="light"||f===void 0))&&(f=b))}const y={},S=Object.keys(d).filter(u=>d[u]!==f);if(S.length){const u=d.light!==void 0?d.light:f,m=d.dark!==void 0?d.dark:f;if(E(n)&&(0,$.isPlainColor)(u)&&(0,$.isPlainColor)(m)){y[n]=u===m?u:`light-dark(${u}, ${m})`;for(const b in d)b==="light"||b==="dark"||B(y,b,{[n]:d[b]},r)}else{f!==void 0&&(y[n]=f);for(const b of S)B(y,b,{[n]:d[b]},r)}}else{if(f===void 0)continue;y[n]=f}M(g,y),g[`.${n}`]=y}return(g.background||g.color||g.backgroundColor)&&(g[".inversed"]={color:g.background||g.backgroundColor,background:g.color}),g},q=(e,o,r)=>{const{cssVars:t}=r;r.cssMediaVars||(r.cssMediaVars={});const i=r.cssMediaVars,a=r.globalTheme!==void 0?r.globalTheme:"auto",s={},h=new Set;for(const n in e)if(e[n])for(const c of Object.keys(e[n]))h.add(c);const g=L(e,h);for(const n of h){const c=n.slice(0,1),k=Object.values(e).some(p=>(0,l.isObjectLike)(p?.[n]));if(c==="."&&k){const p=n.slice(1),d={};for(const f in e)(0,l.isObjectLike)(e[f]?.[n])&&(d[f]=e[f][n]);s[n]=q(d,`${o}-${p}`,r)}else if(c===":"&&k){const p=n.replace(/^:+/,""),d={};for(const f in e)(0,l.isObjectLike)(e[f]?.[n])&&(d[f]=e[f][n]);s[n]=q(d,`${o}-${p}`,r)}else if(c!=="@"&&c!=="."&&c!==":"){const d=`--${r.varPrefix?r.varPrefix+"-":""}theme-${o}-${n}`,f=a&&a!=="auto"?String(a).replace(/^'|'$/g,""):null;let y;for(const S in e){if(g.has(S))continue;const u=e[S]?.[n];if(u===void 0)continue;const m=C(o,n,u,`@${S}`);if(m===void 0)continue;(f&&S===f||!f&&(S==="light"||y===void 0))&&(y=m);const b=`[data-theme="${S}"]`;if(i[b]||(i[b]={}),i[b][d]=m,S==="dark"||S==="light"){const T=`@media (prefers-color-scheme: ${S})`;i[T]||(i[T]={}),i[T][d]=m}}y!==void 0&&(t[d]=y),s[n]=`var(${d})`,s[`.${n}`]={[n]:s[n]}}}return(s.background||s.color||s.backgroundColor)&&(s[".inversed"]={color:s.background||s.backgroundColor,background:s.color}),s},v=(e,o,r,t)=>{const i=(0,j.getActiveConfig)(),{cssVars:a}=i,s={value:e},h=!r&&!t;let g;if((0,l.isObjectLike)(e)){if(h&&i.useVariable){const n={};for(const c in e)c.startsWith("@")&&(0,l.isObjectLike)(e[c])&&(n[c.slice(1)]=e[c]);if(Object.keys(n).length){const c=q(n,o,i);Object.assign(s,c)}}else if(h){const n={},c={};for(const k in e)k.startsWith("@")?(0,l.isObjectLike)(e[k])&&(n[k.slice(1)]=e[k]):c[k]=e[k];g=D(n,o,i,c),Object.assign(s,g)}for(const n in e){const c=n.slice(0,1),k=e[n];if(c==="@"||c===":"||c==="."){const p=c==="@"&&n;s[n]=v(k,o,n,t||p)}else if(!h){const p=C(o,n,k,t),d=[...new Set([t,r].filter(u=>u).map(u=>u.slice(1)))],f=d.length?"-"+d.join("-"):"",S=`--${i.varPrefix?i.varPrefix+"-":""}theme-${o}${f}-${n}`;i.useVariable?(i.useThemeSuffixedVars&&(a[S]=p),s[n]=`var(${S})`):s[n]=p,s[`.${n}`]={[n]:s[n]}}}if(g)for(const n in g){const c=n.slice(0,1);(c==="."||c===":")&&(0,l.isObjectLike)(e[n])&&(s[n]=g[n])}!s[".inversed"]&&(s.background||s.color||s.backgroundColor)&&(s[".inversed"]={color:s.background||s.backgroundColor,background:s.color})}if((0,l.isString)(e)&&(0,V.isCSSVar)(e)){const c=i.theme[e.slice(2)];return R(c,t)}return s},x=(e,o)=>{const r={};for(const t in e){const i=t.slice(0,1);if((0,l.isObjectLike)(e[t]))if(o&&ne(t))r[t]=M({},e[t]);else{if(i==="@")continue;i===":"?r[`&${t}`]=x(e[t],o):i==="."&&(r[`&${t}`]=x(e[t],o))}else r[t]=e[t]}return r},W=(e,o)=>{const r=o.shift();return e[r]?W(e[r],o):e},z=(e,o)=>(0,l.isArray)(o)?W(e,o):(0,l.isString)(o)&&e[o]?e[o]:e,re=(e,o)=>(0,l.isString)(e)&&(0,V.isCSSVar)(e)?R(e.slice(2)):e,te=e=>re(e,te),R=(e,o)=>{const r=(0,j.getActiveConfig)();if((0,l.isString)(e)&&(0,V.isCSSVar)(e)&&(e=R(e.slice(2))),!e||!(0,l.isString)(e)){r.verbose&&console.warn(`${e} - Theme is not a string`);return}const[t,...i]=(0,l.isArray)(e)?e:e.split(" ");let a=r.theme[t];return a&&i.length?a=z(a,i):a&&o&&(a=z(a,o)),x(a,!r.useVariable)};
@@ -1 +1 @@
1
- import{isObject as w,isArray as k,isString as b}from"@symbo.ls/utils";import{getActiveConfig as M}from"../factory.js";import{colorStringToRgbaArray as D,getRgbTone as A,isCSSVar as x,parseColorToken as C}from"../utils/index.js";const W={light:"(prefers-color-scheme: light)",dark:"(prefers-color-scheme: dark)"},H=(e,n)=>{const t=n.media&&n.media[e]||W[e];return t?"@media "+(t==="print"?`${t}`:`screen and ${t}`):null},Q=e=>{const n=e.scopeSelector||":root";return`${n===":root"?":root:not([data-theme])":`:root:not([data-theme]) ${n}:not([data-theme])`} &`},$=new Set,z=new Set(["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"]),L=new Set,P=e=>{if(!e)return!1;const{color:n,gradient:t}=e;return!!(w(n)&&Object.keys(n).length||w(t)&&Object.keys(t).length)},O=new Set;let T=0;const I=e=>{T++;try{return e()}finally{T--}},B=(e,n)=>{if(!b(e)||e.indexOf(" ")===-1)return null;const t=e.replace(/\s+/g,""),r=C(t);if(!r||r.passthrough||r.cssVar)return null;const{color:o,gradient:c}=n;return!o[r.name]&&!c[r.name]?null:t},_=(e,n,t)=>{const r=B(e,t);if(r){if(!O.has(e)){O.add(e);const a=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color token \`${e}\` has a space before its alpha/tone modifier${a} \u2014 did you mean \`${r}\`? The space form never resolves, so the atomic class it mints carries no CSS value and paints invisibly. Dropped rather than shipped invisible.`)}return}const o=C(e);if(o&&o.name&&!o.passthrough&&!o.cssVar&&(o.alpha!==void 0||o.tone!==void 0)&&P(t)&&!t.color[o.name]&&!t.gradient[o.name]){if(!T&&!L.has(e)){L.add(e);const a=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color token \`${e}\` does not resolve${a} \u2014 \`${o.name}\` is not in the palette. Dropped rather than emitted as a raw value, which is invalid CSS the browser discards silently. Define it in designSystem/color.js or use a palette token.`)}return}const c=b(n)?n.toLowerCase():"";if(!z.has(c)||!P(t))return e;if(!L.has(c)){L.add(c);const a=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color \`${e}\` is a CSS named colour that is not in the palette${a}. Dropped rather than emitted as a raw browser colour, which renders theme-blind and can be unreadable ("looks designed", so it ships unnoticed). Define it in designSystem/color.js or use a palette token.`)}},R=(e,n,t)=>{const r=t||M();if(!b(e)){r.verbose&&console.warn(e,"- type for color is not valid");return}if(x(e))return`var(${e})`;n&&e[n]&&(e=e[n]);let o,c,a;if(k(e))[o,c,a]=e;else{const i=C(e);if(!i){const{color:f,gradient:V}=r;let p=V[e]||f[e];return p?(n&&p[n]&&(p=p[n]),r.useVariable?`var(${p.var})`:p.value):_(e,e,r)}if(i.passthrough)return i.passthrough;if(i.cssVar)return`var(${i.cssVar})`;o=i.name,c=i.alpha,a=i.tone}const{color:g,gradient:d}=r;let s=g[o]||d[o];if(!s)return _(e,o,r);if(n)if(s[n]!==void 0)s=s[n];else if(k(s)){const i=n.charCodeAt(0)===64?n.slice(1):n;i==="dark"?s=s[1]!==void 0?s[1]:s[0]:(i!=="light"&&r.verbose&&console.warn(e," - array-form color tokens only support light/dark; falling back to the light slot for scheme",n),s=s[0])}else r.verbose&&console.warn(e," - does not have ",n);if(b(s)){if($.has(o))return s;$.add(o);try{return R(s,null,t)}finally{$.delete(o)}}let h=s.rgb;if(!h){const i=r.useVariable?`var(${s.var})`:s.value;if((c||a)&&i){const f=c!==void 0?c:1;if(!a)return`rgb(from ${i} r g b / ${f})`;if(a.charCodeAt(0)===43||a.charCodeAt(0)===45){const p=parseFloat(a),u=p<0?"-":"+",l=Math.abs(p);return`rgb(from ${i} calc(r ${u} ${l}) calc(g ${u} ${l}) calc(b ${u} ${l}) / ${f})`}return`hsl(from ${i} h s ${a}% / ${f})`}return i}return a&&!s[a]&&(h=A(h,a),s[a]={rgb:h,var:`${s.var}-${a}`}),s[a]&&(h=s[a].rgb),c?`rgba(${h}, ${c})`:a?`rgba(${h}, ${s.alpha!==void 0?s.alpha:1})`:r.useVariable?`var(${s.var})`:s.value!==void 0?s.value:`rgb(${h})`},j=e=>{const n=D(e);return!n||n.length<3||n[0]===0&&n[1]===0&&n[2]===0&&n[3]===0&&e.toLowerCase()!=="transparent"?null:{rgb:[n[0],n[1],n[2]],alpha:n[3]!==void 0?n[3]:1}},K=(e,n)=>{if(!n)return e;let t=e.rgb;if(n.tone){const o=A(t,n.tone);t=b(o)?o.split(",").map(c=>parseFloat(c.trim())):o}const r=n.alpha!==void 0?parseFloat(n.alpha):e.alpha;return{rgb:t,alpha:r}},U=(e,n,t)=>{const r=n||M();if(!b(e))return null;const o=C(e);if(o){if(o.passthrough){const f=D(o.passthrough);return f&&f.length>=3?{rgb:[f[0],f[1],f[2]],alpha:f[3]!==void 0?f[3]:1}:null}if(o.cssVar)return null}const c=o?o.name:e,{color:a,gradient:g}=r;let d=a[c]||g[c];if(!d)return j(e);if(b(d)){let f;if($.has(c))f=j(d);else{$.add(c);try{f=U(d,r,t)}finally{$.delete(c)}}return f?K(f,o):null}if(d.rgb===void 0&&w(d)){const f=`@${t||"light"}`;d=d[f]!==void 0?d[f]:d["@light"]}if(!d||d.rgb===void 0)return null;let s=d.rgb;o&&o.tone&&(s=A(s,o.tone));const h=b(s)?s.split(",").map(f=>parseFloat(f.trim())):s,i=o&&o.alpha!==void 0?parseFloat(o.alpha):d.alpha!==void 0?d.alpha:1;return{rgb:h,alpha:i}},F=(e,n,t)=>{const r=t||M();if(n||(n=r.globalTheme==="auto"?null:r.globalTheme),!b(e)){r.verbose&&console.warn(e,"- type for color is not valid");return}if(x(e))return`var(${e})`;let o,c,a;if(k(e))o=e[0];else{const i=C(e);if(i){if(i.passthrough)return i.passthrough;if(i.cssVar)return`var(${i.cssVar})`;o=i.name,c=i.alpha,a=i.tone}else o=e}const{color:g,gradient:d}=r,s=g[o]||d[o],h=w(s);if(h&&s.value)return R(e,`@${n}`,t);if(h){if(r.useVariable&&s.var)return c||a?R(e,null,t):`var(${s.var})`;if(n)return R(e,`@${n}`,t);{const i={},f=Q(r);for(const V in s){if(V.charCodeAt(0)!==64)continue;const p=V.slice(1),u=R(e,V,t);if(u!==void 0&&(i[`[data-theme="${p}"] &`]=u,p==="light"||p==="dark")){const l=H(p,r);if(!l)continue;i[l]={[f]:u}}}return i}}else return _(e,o,r)},v=(e,n,t,r)=>{const c=`--${r.varPrefix?r.varPrefix+"-":""}${n}-${t}`;let a;const g={};for(const d in e){if(d.charCodeAt(0)!==64)continue;const s=d.slice(1),h=e[d],i=h&&(h.value||h);!i||typeof i!="string"||(g[s]=i,(s==="light"||a===void 0)&&(a=i))}if(a!==void 0){r.cssVars[c]=a,r.cssMediaVars||(r.cssMediaVars={});for(const d in g){const s=`[data-theme="${d}"]`;if(r.cssMediaVars[s]||(r.cssMediaVars[s]={}),r.cssMediaVars[s][c]=g[d],d==="light"||d==="dark"){const h=`@media (prefers-color-scheme: ${d})`;r.cssMediaVars[h]||(r.cssMediaVars[h]={}),r.cssMediaVars[h][c]=g[d]}}return e.var=c,c}},q=(e,n,t)=>{const r=M();if(w(e)&&e.value!==void 0&&(e.rgb!==void 0||e.var!==void 0))return r.useVariable&&e.var&&(r.cssVars[e.var]=e.value),e;if(b(e)&&x(e)){const u=e.slice(2);if(e=R(u),!(e.includes("rgb")||e.includes("var")||e.includes("#"))){const l=u.split(" ");let m=r.color[l[0]];if(m&&!m.value&&!m.rgb&&(b(m)||k(m)||w(m))&&!$.has(l[0])){$.add(l[0]);try{r.color[l[0]]=q(m,l[0])}finally{$.delete(l[0])}m=r.color[l[0]]}if(m&&m.value){let y=m.rgb;const E=l[1]!==void 0?l[1]:"1",S=l[2];S&&(y=A(y,S)),e=`rgba(${y}, ${E})`}else{const y=l[2],E=l[1]!==void 0?l[1]:"1";if(y)try{const S=D(l[0]);S&&S.length>=3?e=`rgba(${A(S.slice(0,3).join(", "),y)}, ${E})`:e=l[0]}catch{e=l[0]}else e=l[0]}}}if(k(e)&&(e={"@light":e[0],"@dark":e[1]!==void 0?e[1]:e[0]}),w(e)){const u={};for(const l in e)l!=="var"&&(u[l]=q(e[l],n,l.slice(0,1)==="@"?l.slice(1):l));return r.useVariable&&v(u,"color",n,r),u}const c=`--${r.varPrefix?r.varPrefix+"-":""}color-${n}`+(t?`-${t}`:"");let a=e.value||e;if(b(a)&&!a.includes("(")&&!a.startsWith("#")){const u=C(a);if(u&&u.name&&!u.passthrough&&!u.cssVar){const l=r.color[u.name];if(l&&!l.value&&!l.rgb&&(b(l)||k(l)||w(l))&&!$.has(u.name)){$.add(u.name);try{r.color[u.name]=q(l,u.name)}finally{$.delete(u.name)}}const m=r.color[u.name];if(m&&m.rgb){let y=m.rgb;u.tone&&(y=A(y,u.tone));const E=u.alpha!==void 0?parseFloat(u.alpha):m.alpha!==void 0?m.alpha:1;a=`rgba(${y}, ${E})`}}}const g=D(a),[d,s,h,i=1]=g,f=parseFloat(i.toFixed(2)),V=`${d}, ${s}, ${h}`,p=`rgba(${V}, ${f})`;return r.useVariable&&(r.cssVars[c]=p),{var:c,rgb:V,alpha:f,value:p}},J=(e,n,t)=>{const r=M();if(w(e)&&e.value!==void 0&&e.var!==void 0)return r.useVariable&&(r.cssVars[e.var]=e.value),e;if(b(e)&&x(e)&&(e=R(e.slice(2))),k(e)&&(e={"@light":e[0],"@dark":e[1]!==void 0?e[1]:e[0]}),w(e)){const a={};for(const g in e)g!=="var"&&(a[g]=J(e[g],n,g.slice(0,1)==="@"?g.slice(1):g));return r.useVariable&&v(a,"gradient",n,r),a}const c=`--${r.varPrefix?r.varPrefix+"-":""}gradient-${n}`+(t?`-${t}`:"");return r.useVariable&&(r.cssVars[c]=e.value||e),{var:c,value:e.value||e}};export{W as STANDARD_SCHEME_QUERIES,R as getColor,F as getMediaColor,I as quietColorProbe,U as resolveColorRgb,Q as schemeGuardSelector,H as schemeMediaQuery,v as setAdaptiveSchemeVar,q as setColor,J as setGradient};
1
+ import{isObject as w,isArray as R,isString as m}from"@symbo.ls/utils";import{getActiveConfig as D}from"../factory.js";import{colorStringToRgbaArray as L,getRgbTone as A,isCSSVar as M,parseColorToken as C}from"../utils/index.js";const z={light:"(prefers-color-scheme: light)",dark:"(prefers-color-scheme: dark)"},B=(e,r)=>{const t=r.media&&r.media[e]||z[e];return t?"@media "+(t==="print"?`${t}`:`screen and ${t}`):null},N=e=>{const r=e.scopeSelector||":root";return`${r===":root"?":root:not([data-theme])":`:root:not([data-theme]) ${r}:not([data-theme])`} &`},$=new Set,T=new Set(["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"]),Y=/^(?:#[0-9a-f]{3,8}$|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix)\()/i,J=/gradient\(|url\(|image-set\(|var\(/i,X=new Set(["transparent","currentColor","currentcolor"]),q=e=>{if(!m(e))return!1;const r=e.trim();return J.test(r)?!1:Y.test(r)?!0:T.has(r)||X.has(r)},O=new Set,j=e=>{if(!e)return!1;const{color:r,gradient:t}=e;return!!(w(r)&&Object.keys(r).length||w(t)&&Object.keys(t).length)},W=new Set;let _=0;const ie=e=>{_++;try{return e()}finally{_--}},Z=(e,r)=>{if(!m(e)||e.indexOf(" ")===-1)return null;const t=e.replace(/\s+/g,""),n=C(t);if(!n||n.passthrough||n.cssVar)return null;const{color:s,gradient:a}=r;return!s[n.name]&&!a[n.name]?null:t},x=(e,r,t)=>{const n=Z(e,t);if(n){if(!W.has(e)){W.add(e);const i=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color token \`${e}\` has a space before its alpha/tone modifier${i} \u2014 did you mean \`${n}\`? The space form never resolves, so the atomic class it mints carries no CSS value and paints invisibly. Dropped rather than shipped invisible.`)}return}const s=C(e);if(s&&s.name&&!s.passthrough&&!s.cssVar&&(s.alpha!==void 0||s.tone!==void 0)&&j(t)&&!t.color[s.name]&&!t.gradient[s.name]){if(!_&&!O.has(e)){O.add(e);const i=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color token \`${e}\` does not resolve${i} \u2014 \`${s.name}\` is not in the palette. Dropped rather than emitted as a raw value, which is invalid CSS the browser discards silently. Define it in designSystem/color.js or use a palette token.`)}return}const a=m(r)?r.toLowerCase():"";if(!T.has(a)||!j(t))return e;if(!O.has(a)){O.add(a);const i=t&&t.name?` (design system \`${t.name}\`)`:"";console.warn(`[scratch] color \`${e}\` is a CSS named colour that is not in the palette${i}. Dropped rather than emitted as a raw browser colour, which renders theme-blind and can be unreadable ("looks designed", so it ships unnoticed). Define it in designSystem/color.js or use a palette token.`)}},v=(e,r,t)=>{const n=r!==void 0?r:1;if(!t)return`rgb(from ${e} r g b / ${n})`;if(t.charCodeAt(0)===43||t.charCodeAt(0)===45){const a=parseFloat(t),i=a<0?"-":"+",u=Math.abs(a);return`rgb(from ${e} calc(r ${i} ${u}) calc(g ${i} ${u}) calc(b ${i} ${u}) / ${n})`}return`hsl(from ${e} h s ${t}% / ${n})`},V=(e,r,t)=>{const n=t||D();if(!m(e)){n.verbose&&console.warn(e,"- type for color is not valid");return}if(M(e))return`var(${e})`;r&&e[r]&&(e=e[r]);let s,a,i;if(R(e))[s,a,i]=e;else{const l=C(e);if(!l){const{color:h,gradient:k}=n;let b=k[e]||h[e];return b?(r&&b[r]&&(b=b[r]),n.useVariable?`var(${b.var})`:b.value):x(e,e,n)}if(l.passthrough)return l.passthrough;if(l.cssVar)return`var(${l.cssVar})`;s=l.name,a=l.alpha,i=l.tone}const{color:u,gradient:c}=n;let o=u[s]||c[s];if(!o)return x(e,s,n);if(r)if(o[r]!==void 0)o=o[r];else if(R(o)){const l=r.charCodeAt(0)===64?r.slice(1):r;l==="dark"?o=o[1]!==void 0?o[1]:o[0]:(l!=="light"&&n.verbose&&console.warn(e," - array-form color tokens only support light/dark; falling back to the light slot for scheme",r),o=o[0])}else n.verbose&&console.warn(e," - does not have ",r);if(m(o)){if($.has(s))return o;$.add(s);try{return V(o,null,t)}finally{$.delete(s)}}let g=o.rgb;if(!g){const l=n.useVariable?`var(${o.var})`:o.value;return(a||i)&&l?v(l,a,i):l}return i&&!o[i]&&(g=A(g,i),o[i]={rgb:g,var:`${o.var}-${i}`}),o[i]&&(g=o[i].rgb),a?`rgba(${g}, ${a})`:i?`rgba(${g}, ${o.alpha!==void 0?o.alpha:1})`:n.useVariable?`var(${o.var})`:o.value!==void 0?o.value:`rgb(${g})`},H=e=>{const r=L(e);return!r||r.length<3||r[0]===0&&r[1]===0&&r[2]===0&&r[3]===0&&e.toLowerCase()!=="transparent"?null:{rgb:[r[0],r[1],r[2]],alpha:r[3]!==void 0?r[3]:1}},I=(e,r)=>{if(!r)return e;let t=e.rgb;if(r.tone){const s=A(t,r.tone);t=m(s)?s.split(",").map(a=>parseFloat(a.trim())):s}const n=r.alpha!==void 0?parseFloat(r.alpha):e.alpha;return{rgb:t,alpha:n}},F=(e,r,t)=>{const n=r||D();if(!m(e))return null;const s=C(e);if(s){if(s.passthrough){const h=L(s.passthrough);return h&&h.length>=3?{rgb:[h[0],h[1],h[2]],alpha:h[3]!==void 0?h[3]:1}:null}if(s.cssVar)return null}const a=s?s.name:e,{color:i,gradient:u}=n;let c=i[a]||u[a];if(!c)return H(e);if(m(c)){let h;if($.has(a))h=H(c);else{$.add(a);try{h=F(c,n,t)}finally{$.delete(a)}}return h?I(h,s):null}if(c.rgb===void 0&&w(c)){const h=`@${t||"light"}`;c=c[h]!==void 0?c[h]:c["@light"]}if(!c||c.rgb===void 0)return null;let o=c.rgb;s&&s.tone&&(o=A(o,s.tone));const g=m(o)?o.split(",").map(h=>parseFloat(h.trim())):o,l=s&&s.alpha!==void 0?parseFloat(s.alpha):c.alpha!==void 0?c.alpha:1;return{rgb:g,alpha:l}},K=e=>w(e)&&e.value!==void 0&&(e.rgb!==void 0||e.var!==void 0),Q=e=>{if(!w(e)||e.value!==void 0)return null;const r=[];for(const t in e)if(t!=="var"){if(t.charCodeAt(0)!==64||!K(e[t]))return null;r.push(t.slice(1))}return r.length?r:null},G=e=>m(e&&e.var)&&Q(e)!==null,ee=(e,r,t,n,s)=>{const a=Q(r);if(!a)return;if(m(r.var)){const c=`var(${r.var})`;return t||n?v(c,t,n):c}if(a.length!==2||!a.includes("light")||!a.includes("dark"))return;const i=V(e,"@light",s),u=V(e,"@dark",s);if(!(!q(i)||!q(u)))return i===u?i:`light-dark(${i}, ${u})`},ae=(e,r,t)=>{const n=t||D();if(r||(r=n.globalTheme==="auto"?null:n.globalTheme),!m(e)){n.verbose&&console.warn(e,"- type for color is not valid");return}if(M(e))return`var(${e})`;let s,a,i;if(R(e))s=e[0];else{const l=C(e);if(l){if(l.passthrough)return l.passthrough;if(l.cssVar)return`var(${l.cssVar})`;s=l.name,a=l.alpha,i=l.tone}else s=e}const{color:u,gradient:c}=n,o=u[s]||c[s],g=w(o);if(g&&o.value)return V(e,`@${r}`,t);if(g){if(n.useVariable&&o.var)return a||i?V(e,null,t):`var(${o.var})`;if(r){if(!n.useVariable&&u[s]===o){const l=ee(e,o,a,i,t);if(l!==void 0)return l}return V(e,`@${r}`,t)}else{const l={},h=N(n);for(const k in o){if(k.charCodeAt(0)!==64)continue;const b=k.slice(1),f=V(e,k,t);if(f!==void 0&&(l[`[data-theme="${b}"] &`]=f,b==="light"||b==="dark")){const d=B(b,n);if(!d)continue;l[d]={[h]:f}}}return l}}else return x(e,s,n)},U=(e,r,t,n)=>{const a=`--${n.varPrefix?n.varPrefix+"-":""}${r}-${t}`;let i;const u={};for(const c in e){if(c.charCodeAt(0)!==64)continue;const o=c.slice(1),g=e[c],l=g&&(g.value||g);!l||typeof l!="string"||(u[o]=l,(o==="light"||i===void 0)&&(i=l))}if(i!==void 0){n.cssVars[a]=i,n.cssMediaVars||(n.cssMediaVars={});for(const c in u){const o=`[data-theme="${c}"]`;if(n.cssMediaVars[o]||(n.cssMediaVars[o]={}),n.cssMediaVars[o][a]=u[c],c==="light"||c==="dark"){const g=`@media (prefers-color-scheme: ${c})`;n.cssMediaVars[g]||(n.cssMediaVars[g]={}),n.cssMediaVars[g][a]=u[c]}}return e.var=a,a}},P=(e,r,t)=>{const n=D();if(K(e))return n.useVariable&&e.var&&(n.cssVars[e.var]=e.value),e;if(!n.useVariable&&G(e))return e;if(m(e)&&M(e)){const f=e.slice(2);if(e=V(f),!(e.includes("rgb")||e.includes("var")||e.includes("#"))){const d=f.split(" ");let p=n.color[d[0]];if(p&&!p.value&&!p.rgb&&(m(p)||R(p)||w(p))&&!$.has(d[0])){$.add(d[0]);try{n.color[d[0]]=P(p,d[0])}finally{$.delete(d[0])}p=n.color[d[0]]}if(p&&p.value){let y=p.rgb;const E=d[1]!==void 0?d[1]:"1",S=d[2];S&&(y=A(y,S)),e=`rgba(${y}, ${E})`}else{const y=d[2],E=d[1]!==void 0?d[1]:"1";if(y)try{const S=L(d[0]);S&&S.length>=3?e=`rgba(${A(S.slice(0,3).join(", "),y)}, ${E})`:e=d[0]}catch{e=d[0]}else e=d[0]}}}if(R(e)&&(e={"@light":e[0],"@dark":e[1]!==void 0?e[1]:e[0]}),w(e)){const f={};for(const d in e)d!=="var"&&(f[d]=P(e[d],r,d.slice(0,1)==="@"?d.slice(1):d));return n.useVariable&&U(f,"color",r,n),f}const a=`--${n.varPrefix?n.varPrefix+"-":""}color-${r}`+(t?`-${t}`:"");let i=e.value||e;if(m(i)&&!i.includes("(")&&!i.startsWith("#")){const f=C(i);if(f&&f.name&&!f.passthrough&&!f.cssVar){const d=n.color[f.name];if(d&&!d.value&&!d.rgb&&(m(d)||R(d)||w(d))&&!$.has(f.name)){$.add(f.name);try{n.color[f.name]=P(d,f.name)}finally{$.delete(f.name)}}const p=n.color[f.name];if(p&&p.rgb){let y=p.rgb;f.tone&&(y=A(y,f.tone));const E=f.alpha!==void 0?parseFloat(f.alpha):p.alpha!==void 0?p.alpha:1;i=`rgba(${y}, ${E})`}}}const u=L(i),[c,o,g,l=1]=u,h=parseFloat(l.toFixed(2)),k=`${c}, ${o}, ${g}`,b=`rgba(${k}, ${h})`;return n.useVariable&&(n.cssVars[a]=b),{var:a,rgb:k,alpha:h,value:b}},re=(e,r,t)=>{const n=D();if(w(e)&&e.value!==void 0&&e.var!==void 0)return n.useVariable&&(n.cssVars[e.var]=e.value),e;if(m(e)&&M(e)&&(e=V(e.slice(2))),R(e)&&(e={"@light":e[0],"@dark":e[1]!==void 0?e[1]:e[0]}),w(e)){const i={};for(const u in e)u!=="var"&&(i[u]=re(e[u],r,u.slice(0,1)==="@"?u.slice(1):u));return n.useVariable&&U(i,"gradient",r,n),i}const a=`--${n.varPrefix?n.varPrefix+"-":""}gradient-${r}`+(t?`-${t}`:"");return n.useVariable&&(n.cssVars[a]=e.value||e),{var:a,value:e.value||e}};export{z as STANDARD_SCHEME_QUERIES,V as getColor,ae as getMediaColor,q as isPlainColor,ie as quietColorProbe,F as resolveColorRgb,N as schemeGuardSelector,B as schemeMediaQuery,U as setAdaptiveSchemeVar,P as setColor,re as setGradient};
@@ -1 +1 @@
1
- import{getColor as A,schemeMediaQuery as Y,schemeGuardSelector as Z}from"./color.js";import{resolveShadowValue as x}from"./shadow.js";import{resolveBorderValue as T}from"./border.js";import{getActiveConfig as M}from"../factory.js";import{isCSSVar as v,parseColorToken as J}from"../utils/color.js";import{isObject as E,isString as $,isObjectLike as y,isArray as L,isLoudDevRuntime as K}from"@symbo.ls/utils";const q=new Set(["black","white","red","green","blue","yellow","orange","purple","pink","brown","gray","grey","cyan","magenta","lime","olive","navy","teal","aqua","maroon","silver","fuchsia","transparent","currentColor","currentcolor","inherit","initial","unset","none","aliceblue","antiquewhite","aquamarine","azure","beige","bisque","blanchedalmond","blueviolet","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","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","gainsboro","ghostwhite","gold","goldenrod","greenyellow","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","limegreen","linen","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","oldlace","olivedrab","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","plum","powderblue","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","thistle","tomato","turquoise","violet","wheat","whitesmoke","yellowgreen","rebeccapurple"]),P=["color","Color","background","Background","fill","Fill","stroke","Stroke"],D=e=>{for(let o=0;o<P.length;o++)if(e.includes(P[o]))return!0;return!1},X={boxShadow:x,textShadow:x,border:T,borderTop:T,borderRight:T,borderBottom:T,borderLeft:T,outline:T,columnRule:T},F=e=>{if(!e)return!1;const o=J(e);return!o||!o.name||o.passthrough||o.cssVar?!1:o.alpha!==void 0||o.tone!==void 0},W=new Set,I=(e,o,r,t,s,a)=>{if(!K())return;const i=`${e}::${o}::${r||""}::${t}`;W.has(i)||(W.add(i),console.warn(`[smbls/scratch] theme param "${o}" on "${e}"`+(r?` (${r})`:"")+` did not fully resolve: "${t}" -> "${s}" still contains the unresolved token "${a}". This is not valid CSS \u2014 the browser will drop the whole declaration. Register "${a}" as a design-system color token or fix the typo.`))},O=(e,o,r,t)=>{const s=X[o];if(!s)return A(r,t);let a=null;const i=s(r,t,g=>{!a&&F(g)&&(a=g)});return a&&I(e,o,t,r,i,a),i},ge=(e,o)=>R(e,o),G=e=>E(e)&&y(e.value),ee=e=>{for(const o in e){const r=e[o];if($(r)&&r.startsWith("var(--"))return!0}return!1},he=(e,o)=>{const r=M();return G(e)?!r.useVariable&&ee(e)?e:C(e.value,o):C(e,o)},B=(e,o)=>{const r=new Set;for(const t of o){const s=t.slice(0,1);if(!(s==="@"||s==="."||s===":")&&D(t))for(const a in e){if(r.has(a))continue;const i=e[a]?.[t];if(i===void 0)continue;const g=A(i,`@${a}`);g!==void 0&&$(g)&&/^[a-z][a-zA-Z]+$/.test(g)&&!q.has(g)&&r.add(a)}}return r},oe=new Set(["none","inherit","initial","unset","revert","revert-layer"]),ne=/^(?:#[0-9a-f]{3,8}$|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix)\()/i,re=/gradient\(|url\(|image-set\(|var\(/i,U=e=>{if(!$(e))return!1;const o=e.trim();return re.test(o)?!1:ne.test(o)?!0:q.has(o)&&!oe.has(o)},te=e=>e.startsWith("[data-theme=")||e.startsWith("@media"),V=(e,o)=>{for(const r in o){const t=o[r];E(t)?V(e[r]||(e[r]={}),t):e[r]=t}return e},z=(e,o,r,t)=>{if(V(e,{[`[data-theme="${o}"] &`]:r}),o!=="light"&&o!=="dark")return;const s=Y(o,t);s&&V(e,{[s]:{[Z(t)]:r}})},H=(e,o,r,t)=>{const s=r.globalTheme!==void 0?r.globalTheme:"auto",a=s&&s!=="auto"?String(s).replace(/^'|'$/g,""):null,i=new Set(t?Object.keys(t):[]);for(const n in e)if(e[n])for(const c of Object.keys(e[n]))i.add(c);const g=B(e,i),f={};for(const n of i){const c=n.slice(0,1);if(c==="@")continue;if(c==="."||c===":"){const d={};for(const w in e)y(e[w]?.[n])&&(d[w]=e[w][n]);const h=t&&y(t[n])?t[n]:void 0;if(!Object.keys(d).length&&!h)continue;const m=c==="."?n.slice(1):n.replace(/^:+/,"");f[n]=H(d,`${o}-${m}`,r,h);continue}const b=t&&!y(t[n])?t[n]:void 0,k=new Set(Object.keys(e));b!==void 0&&(k.add("light"),k.add("dark"),a&&k.add(a));const l={};let u;for(const d of k){if(g.has(d))continue;let h=e[d]?.[n];if((h===void 0||y(h))&&(h=b),h===void 0)continue;const m=O(o,n,h,`@${d}`);m!==void 0&&(l[d]=m,(a&&d===a||!a&&(d==="light"||u===void 0))&&(u=m))}const S={},p=Object.keys(l).filter(d=>l[d]!==u);if(p.length){const d=l.light!==void 0?l.light:u,h=l.dark!==void 0?l.dark:u;if(D(n)&&U(d)&&U(h)){S[n]=d===h?d:`light-dark(${d}, ${h})`;for(const m in l)m==="light"||m==="dark"||z(S,m,{[n]:l[m]},r)}else{u!==void 0&&(S[n]=u);for(const m of p)z(S,m,{[n]:l[m]},r)}}else{if(u===void 0)continue;S[n]=u}V(f,S),f[`.${n}`]=S}return(f.background||f.color||f.backgroundColor)&&(f[".inversed"]={color:f.background||f.backgroundColor,background:f.color}),f},j=(e,o,r)=>{const{cssVars:t}=r;r.cssMediaVars||(r.cssMediaVars={});const s=r.cssMediaVars,a=r.globalTheme!==void 0?r.globalTheme:"auto",i={},g=new Set;for(const n in e)if(e[n])for(const c of Object.keys(e[n]))g.add(c);const f=B(e,g);for(const n of g){const c=n.slice(0,1),b=Object.values(e).some(k=>y(k?.[n]));if(c==="."&&b){const k=n.slice(1),l={};for(const u in e)y(e[u]?.[n])&&(l[u]=e[u][n]);i[n]=j(l,`${o}-${k}`,r)}else if(c===":"&&b){const k=n.replace(/^:+/,""),l={};for(const u in e)y(e[u]?.[n])&&(l[u]=e[u][n]);i[n]=j(l,`${o}-${k}`,r)}else if(c!=="@"&&c!=="."&&c!==":"){const l=`--${r.varPrefix?r.varPrefix+"-":""}theme-${o}-${n}`,u=a&&a!=="auto"?String(a).replace(/^'|'$/g,""):null;let S;for(const p in e){if(f.has(p))continue;const d=e[p]?.[n];if(d===void 0)continue;const h=O(o,n,d,`@${p}`);if(h===void 0)continue;(u&&p===u||!u&&(p==="light"||S===void 0))&&(S=h);const m=`[data-theme="${p}"]`;if(s[m]||(s[m]={}),s[m][l]=h,p==="dark"||p==="light"){const w=`@media (prefers-color-scheme: ${p})`;s[w]||(s[w]={}),s[w][l]=h}}S!==void 0&&(t[l]=S),i[n]=`var(${l})`,i[`.${n}`]={[n]:i[n]}}}return(i.background||i.color||i.backgroundColor)&&(i[".inversed"]={color:i.background||i.backgroundColor,background:i.color}),i},C=(e,o,r,t)=>{const s=M(),{cssVars:a}=s,i={value:e},g=!r&&!t;let f;if(y(e)){if(g&&s.useVariable){const n={};for(const c in e)c.startsWith("@")&&y(e[c])&&(n[c.slice(1)]=e[c]);if(Object.keys(n).length){const c=j(n,o,s);Object.assign(i,c)}}else if(g){const n={},c={};for(const b in e)b.startsWith("@")?y(e[b])&&(n[b.slice(1)]=e[b]):c[b]=e[b];f=H(n,o,s,c),Object.assign(i,f)}for(const n in e){const c=n.slice(0,1),b=e[n];if(c==="@"||c===":"||c==="."){const k=c==="@"&&n;i[n]=C(b,o,n,t||k)}else if(!g){const k=O(o,n,b,t),l=[...new Set([t,r].filter(d=>d).map(d=>d.slice(1)))],u=l.length?"-"+l.join("-"):"",p=`--${s.varPrefix?s.varPrefix+"-":""}theme-${o}${u}-${n}`;s.useVariable?(s.useThemeSuffixedVars&&(a[p]=k),i[n]=`var(${p})`):i[n]=k,i[`.${n}`]={[n]:i[n]}}}if(f)for(const n in f){const c=n.slice(0,1);(c==="."||c===":")&&y(e[n])&&(i[n]=f[n])}!i[".inversed"]&&(i.background||i.color||i.backgroundColor)&&(i[".inversed"]={color:i.background||i.backgroundColor,background:i.color})}if($(e)&&v(e)){const c=s.theme[e.slice(2)];return R(c,t)}return i},_=(e,o)=>{const r={};for(const t in e){const s=t.slice(0,1);if(y(e[t]))if(o&&te(t))r[t]=V({},e[t]);else{if(s==="@")continue;s===":"?r[`&${t}`]=_(e[t],o):s==="."&&(r[`&${t}`]=_(e[t],o))}else r[t]=e[t]}return r},N=(e,o)=>{const r=o.shift();return e[r]?N(e[r],o):e},Q=(e,o)=>L(o)?N(e,o):$(o)&&e[o]?e[o]:e,ie=(e,o)=>$(e)&&v(e)?R(e.slice(2)):e,se=e=>ie(e,se),R=(e,o)=>{const r=M();if($(e)&&v(e)&&(e=R(e.slice(2))),!e||!$(e)){r.verbose&&console.warn(`${e} - Theme is not a string`);return}const[t,...s]=L(e)?e:e.split(" ");let a=r.theme[t];return a&&s.length?a=Q(a,s):a&&o&&(a=Q(a,o)),_(a,!r.useVariable)};export{R as getMediaTheme,ge as getTheme,C as setMediaTheme,he as setTheme};
1
+ import{getColor as x,isPlainColor as O,schemeMediaQuery as Z,schemeGuardSelector as J}from"./color.js";import{resolveShadowValue as _}from"./shadow.js";import{resolveBorderValue as w}from"./border.js";import{getActiveConfig as R}from"../factory.js";import{isCSSVar as j,parseColorToken as X}from"../utils/color.js";import{isObject as E,isString as T,isObjectLike as y,isArray as P,isLoudDevRuntime as Y}from"@symbo.ls/utils";const K=new Set(["black","white","red","green","blue","yellow","orange","purple","pink","brown","gray","grey","cyan","magenta","lime","olive","navy","teal","aqua","maroon","silver","fuchsia","transparent","currentColor","currentcolor","inherit","initial","unset","none","aliceblue","antiquewhite","aquamarine","azure","beige","bisque","blanchedalmond","blueviolet","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","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","gainsboro","ghostwhite","gold","goldenrod","greenyellow","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","limegreen","linen","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","oldlace","olivedrab","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","plum","powderblue","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","thistle","tomato","turquoise","violet","wheat","whitesmoke","yellowgreen","rebeccapurple"]),L=["color","Color","background","Background","fill","Fill","stroke","Stroke"],B=e=>{for(let n=0;n<L.length;n++)if(e.includes(L[n]))return!0;return!1},N={boxShadow:_,textShadow:_,border:w,borderTop:w,borderRight:w,borderBottom:w,borderLeft:w,outline:w,columnRule:w},F=e=>{if(!e)return!1;const n=X(e);return!n||!n.name||n.passthrough||n.cssVar?!1:n.alpha!==void 0||n.tone!==void 0},D=new Set,G=(e,n,r,t,s,a)=>{if(!Y())return;const i=`${e}::${n}::${r||""}::${t}`;D.has(i)||(D.add(i),console.warn(`[smbls/scratch] theme param "${n}" on "${e}"`+(r?` (${r})`:"")+` did not fully resolve: "${t}" -> "${s}" still contains the unresolved token "${a}". This is not valid CSS \u2014 the browser will drop the whole declaration. Register "${a}" as a design-system color token or fix the typo.`))},v=(e,n,r,t)=>{const s=N[n];if(!s)return x(r,t);let a=null;const i=s(r,t,g=>{!a&&F(g)&&(a=g)});return a&&G(e,n,t,r,i,a),i},de=(e,n)=>M(e,n),I=e=>E(e)&&y(e.value),ee=e=>{for(const n in e){const r=e[n];if(T(r)&&r.startsWith("var(--"))return!0}return!1},ue=(e,n)=>{const r=R();return I(e)?!r.useVariable&&ee(e)?e:C(e.value,n):C(e,n)},W=(e,n)=>{const r=new Set;for(const t of n){const s=t.slice(0,1);if(!(s==="@"||s==="."||s===":")&&B(t))for(const a in e){if(r.has(a))continue;const i=e[a]?.[t];if(i===void 0)continue;const g=x(i,`@${a}`);g!==void 0&&T(g)&&/^[a-z][a-zA-Z]+$/.test(g)&&!K.has(g)&&r.add(a)}}return r},oe=e=>e.startsWith("[data-theme=")||e.startsWith("@media"),V=(e,n)=>{for(const r in n){const t=n[r];E(t)?V(e[r]||(e[r]={}),t):e[r]=t}return e},z=(e,n,r,t)=>{if(V(e,{[`[data-theme="${n}"] &`]:r}),n!=="light"&&n!=="dark")return;const s=Z(n,t);s&&V(e,{[s]:{[J(t)]:r}})},H=(e,n,r,t)=>{const s=r.globalTheme!==void 0?r.globalTheme:"auto",a=s&&s!=="auto"?String(s).replace(/^'|'$/g,""):null,i=new Set(t?Object.keys(t):[]);for(const o in e)if(e[o])for(const c of Object.keys(e[o]))i.add(c);const g=W(e,i),f={};for(const o of i){const c=o.slice(0,1);if(c==="@")continue;if(c==="."||c===":"){const d={};for(const $ in e)y(e[$]?.[o])&&(d[$]=e[$][o]);const h=t&&y(t[o])?t[o]:void 0;if(!Object.keys(d).length&&!h)continue;const m=c==="."?o.slice(1):o.replace(/^:+/,"");f[o]=H(d,`${n}-${m}`,r,h);continue}const b=t&&!y(t[o])?t[o]:void 0,k=new Set(Object.keys(e));b!==void 0&&(k.add("light"),k.add("dark"),a&&k.add(a));const l={};let u;for(const d of k){if(g.has(d))continue;let h=e[d]?.[o];if((h===void 0||y(h))&&(h=b),h===void 0)continue;const m=v(n,o,h,`@${d}`);m!==void 0&&(l[d]=m,(a&&d===a||!a&&(d==="light"||u===void 0))&&(u=m))}const S={},p=Object.keys(l).filter(d=>l[d]!==u);if(p.length){const d=l.light!==void 0?l.light:u,h=l.dark!==void 0?l.dark:u;if(B(o)&&O(d)&&O(h)){S[o]=d===h?d:`light-dark(${d}, ${h})`;for(const m in l)m==="light"||m==="dark"||z(S,m,{[o]:l[m]},r)}else{u!==void 0&&(S[o]=u);for(const m of p)z(S,m,{[o]:l[m]},r)}}else{if(u===void 0)continue;S[o]=u}V(f,S),f[`.${o}`]=S}return(f.background||f.color||f.backgroundColor)&&(f[".inversed"]={color:f.background||f.backgroundColor,background:f.color}),f},A=(e,n,r)=>{const{cssVars:t}=r;r.cssMediaVars||(r.cssMediaVars={});const s=r.cssMediaVars,a=r.globalTheme!==void 0?r.globalTheme:"auto",i={},g=new Set;for(const o in e)if(e[o])for(const c of Object.keys(e[o]))g.add(c);const f=W(e,g);for(const o of g){const c=o.slice(0,1),b=Object.values(e).some(k=>y(k?.[o]));if(c==="."&&b){const k=o.slice(1),l={};for(const u in e)y(e[u]?.[o])&&(l[u]=e[u][o]);i[o]=A(l,`${n}-${k}`,r)}else if(c===":"&&b){const k=o.replace(/^:+/,""),l={};for(const u in e)y(e[u]?.[o])&&(l[u]=e[u][o]);i[o]=A(l,`${n}-${k}`,r)}else if(c!=="@"&&c!=="."&&c!==":"){const l=`--${r.varPrefix?r.varPrefix+"-":""}theme-${n}-${o}`,u=a&&a!=="auto"?String(a).replace(/^'|'$/g,""):null;let S;for(const p in e){if(f.has(p))continue;const d=e[p]?.[o];if(d===void 0)continue;const h=v(n,o,d,`@${p}`);if(h===void 0)continue;(u&&p===u||!u&&(p==="light"||S===void 0))&&(S=h);const m=`[data-theme="${p}"]`;if(s[m]||(s[m]={}),s[m][l]=h,p==="dark"||p==="light"){const $=`@media (prefers-color-scheme: ${p})`;s[$]||(s[$]={}),s[$][l]=h}}S!==void 0&&(t[l]=S),i[o]=`var(${l})`,i[`.${o}`]={[o]:i[o]}}}return(i.background||i.color||i.backgroundColor)&&(i[".inversed"]={color:i.background||i.backgroundColor,background:i.color}),i},C=(e,n,r,t)=>{const s=R(),{cssVars:a}=s,i={value:e},g=!r&&!t;let f;if(y(e)){if(g&&s.useVariable){const o={};for(const c in e)c.startsWith("@")&&y(e[c])&&(o[c.slice(1)]=e[c]);if(Object.keys(o).length){const c=A(o,n,s);Object.assign(i,c)}}else if(g){const o={},c={};for(const b in e)b.startsWith("@")?y(e[b])&&(o[b.slice(1)]=e[b]):c[b]=e[b];f=H(o,n,s,c),Object.assign(i,f)}for(const o in e){const c=o.slice(0,1),b=e[o];if(c==="@"||c===":"||c==="."){const k=c==="@"&&o;i[o]=C(b,n,o,t||k)}else if(!g){const k=v(n,o,b,t),l=[...new Set([t,r].filter(d=>d).map(d=>d.slice(1)))],u=l.length?"-"+l.join("-"):"",p=`--${s.varPrefix?s.varPrefix+"-":""}theme-${n}${u}-${o}`;s.useVariable?(s.useThemeSuffixedVars&&(a[p]=k),i[o]=`var(${p})`):i[o]=k,i[`.${o}`]={[o]:i[o]}}}if(f)for(const o in f){const c=o.slice(0,1);(c==="."||c===":")&&y(e[o])&&(i[o]=f[o])}!i[".inversed"]&&(i.background||i.color||i.backgroundColor)&&(i[".inversed"]={color:i.background||i.backgroundColor,background:i.color})}if(T(e)&&j(e)){const c=s.theme[e.slice(2)];return M(c,t)}return i},q=(e,n)=>{const r={};for(const t in e){const s=t.slice(0,1);if(y(e[t]))if(n&&oe(t))r[t]=V({},e[t]);else{if(s==="@")continue;s===":"?r[`&${t}`]=q(e[t],n):s==="."&&(r[`&${t}`]=q(e[t],n))}else r[t]=e[t]}return r},U=(e,n)=>{const r=n.shift();return e[r]?U(e[r],n):e},Q=(e,n)=>P(n)?U(e,n):T(n)&&e[n]?e[n]:e,ne=(e,n)=>T(e)&&j(e)?M(e.slice(2)):e,re=e=>ne(e,re),M=(e,n)=>{const r=R();if(T(e)&&j(e)&&(e=M(e.slice(2))),!e||!T(e)){r.verbose&&console.warn(`${e} - Theme is not a string`);return}const[t,...s]=P(e)?e:e.split(" ");let a=r.theme[t];return a&&s.length?a=Q(a,s):a&&n&&(a=Q(a,n)),q(a,!r.useVariable)};export{M as getMediaTheme,de as getTheme,C as setMediaTheme,ue as setTheme};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symbo.ls/scratch",
3
3
  "description": "Φ / CSS framework and methodology.",
4
4
  "author": "symbo.ls",
5
- "version": "3.14.780",
5
+ "version": "3.14.781",
6
6
  "files": [
7
7
  "dist",
8
8
  "*.js",