@symbo.ls/scratch 3.14.769 → 3.14.771
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/CHANGELOG.md +6 -0
- package/dist/cjs/src/factory.js +1 -1
- package/dist/cjs/src/set.js +1 -1
- package/dist/cjs/src/system/color.js +1 -1
- package/dist/cjs/src/system/index.js +1 -1
- package/dist/cjs/src/system/ink.js +1 -0
- package/dist/cjs/src/utils/color.js +1 -1
- package/dist/esm/src/factory.js +1 -1
- package/dist/esm/src/set.js +1 -1
- package/dist/esm/src/system/color.js +1 -1
- package/dist/esm/src/system/index.js +1 -1
- package/dist/esm/src/system/ink.js +1 -0
- package/dist/esm/src/utils/color.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cjs/src/factory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var x=Object.create;var m=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var P=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},d=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of O(t))!V.call(e,n)&&n!==o&&m(e,n,{get:()=>t[n],enumerable:!(s=A(t,n))||s.enumerable});return e};var R=(e,t,o)=>(o=e!=null?x(y(e)):{},d(t||!e||!e.__esModule?m(o,"default",{value:e,enumerable:!0}):o,e)),F=e=>d(m({},"__esModule",{value:!0}),e);var B={};P(B,{CONFIG:()=>i,FACTORY:()=>l,activateConfig:()=>j,createConfig:()=>z,cssMediaVars:()=>v,cssVars:()=>h,defineResolvedThemeSignal:()=>p,defineThemeSignal:()=>f,getActiveConfig:()=>T,getResolvedThemeSignal:()=>M,getThemeSignal:()=>I,popConfig:()=>w,pushConfig:()=>L,setActiveConfig:()=>G,toCamel:()=>C});module.exports=F(B);var r=require("@symbo.ls/utils"),b=require("@symbo.ls/signal"),D=R(require("./defaultConfig/index.js"),1);const h={},v={},g=D,_={},C=e=>e.replace(/_([a-z])/g,(t,o)=>o.toUpperCase());for(const e in g){const t=e.toLowerCase();_[t]=g[e];const o=C(t);o!==t&&(_[o]=g[e]),t!==e&&(_[e]=g[e])}const i={verbose:!1,useVariable:!0,useReset:!0,globalTheme:"auto",cssVars:h,cssMediaVars:v,CSS_VARS:h,CSS_MEDIA_VARS:v,_scratchConfig:!0,..._},f=(e,t)=>{if(!e)return null;if(e.__globalThemeSignal)return(0,r.isDefined)(t)&&e.__globalThemeSignal.set(t),e.__globalThemeSignal;const o=(0,r.isDefined)(t)?t:e.globalTheme,s=(0,b.createSignal)((0,r.isDefined)(o)?o:"auto");return Object.defineProperty(e,"globalTheme",{get(){return s.get()},set(n){s.set(n)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"__globalThemeSignal",{value:s,enumerable:!1,configurable:!0,writable:!0}),s},I=e=>e?f(e):null,p=(e,t)=>{if(!e)return null;if(e.__resolvedThemeSignal)return(0,r.isDefined)(t)&&e.__resolvedThemeSignal.set(t),e.__resolvedThemeSignal;const o=(0,r.isDefined)(t)?t:e.resolvedTheme,s=(0,b.createSignal)((0,r.isDefined)(o)?o:null);return Object.defineProperty(e,"resolvedTheme",{get(){return s.get()},set(n){s.set(n)},enumerable:!1,configurable:!0}),Object.defineProperty(e,"__resolvedThemeSignal",{value:s,enumerable:!1,configurable:!0,writable:!0}),s},M=e=>e?p(e):null;f(i),p(i);const S=(0,r.deepClone)(i),l={active:"0",0:i},j=e=>((0,r.isDefined)(e)&&(l.active=e),l[e||l.active]),u=[],L=e=>{e&&e._scratchConfig&&u.push(e)},w=()=>{u.pop()},T=e=>u.length?u[u.length-1]:l[e||l.active]||i,G=e=>{if((0,r.isObject)(e))return l.active="1",l[1]=(0,r.deepMerge)(e,(0,r.deepClone)(S)),f(l[1]),p(l[1]),e},E=["useReset","useFontImport","useIconSprite","useSvgSprite","useDocumentTheme","useDefaultIcons","useDefaultConfig"],N=["useVariable","globalTheme","verbose"],k=[["fontfamily","fontFamily","font_family"],["fontfamilytypes","fontFamilyTypes"],["semanticicons","semanticIcons"],["svgdata","svgData"]],U=e=>{for(const t of k){let o;for(const s of t){const n=e[s];(0,r.isObject)(n)&&(o=o?(0,r.deepMerge)(n,o):n)}if(o)for(const s of t)(0,r.isObject)(e[s])&&(e[s]=o)}},z=(e,t,{cleanBase:o=!1}={})=>{const s=o?null:T(),n=(0,r.deepClone)(!o&&s&&s._scratchConfig?s:S);for(const c of E)delete n[c];for(const c of N)Object.prototype.hasOwnProperty.call(S,c)?n[c]=S[c]:delete n[c];const a=(0,r.deepMerge)(t||{},n);return a.cssVars={},a.cssMediaVars={},a.CSS_VARS=a.cssVars,a.CSS_MEDIA_VARS=a.cssMediaVars,a._scratchConfig=!0,U(a),f(a),p(a),e&&(l[e]=a),a};
|
package/dist/cjs/src/set.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var x=Object.defineProperty;var
|
|
1
|
+
"use strict";var x=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var N=(t,s)=>{for(var e in s)x(t,e,{get:s[e],enumerable:!0})},H=(t,s,e,c)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of G(s))!W.call(t,r)&&r!==e&&x(t,r,{get:()=>s[r],enumerable:!(c=q(s,r))||c.enumerable});return t};var Y=t=>H(x({},"__esModule",{value:!0}),t);var K={};N(K,{VALUE_TRANSFORMERS:()=>D,changeGlobalTheme:()=>B,set:()=>J,setEach:()=>j,setValue:()=>M});module.exports=Y(K);var v=require("./factory.js"),o=require("./system/index.js"),T=require("@symbo.ls/utils"),u=require("./utils/host.js");const $=(t,s)=>{const e=(0,v.getActiveConfig)(),{cssVars:c}=e,r=s.startsWith("--")?s:`--${s}`;return c[r]=t,t},f=t=>t,D={color:o.setColor,gradient:o.setGradient,font:o.setFont,fontFamily:o.setFontFamily,fontfamily:o.setFontFamily,theme:o.setTheme,icons:o.setSvgIcon,semanticIcons:f,semanticicons:f,svg:o.setSVG,svgData:f,typography:f,shadow:o.setShadow,spacing:f,media:f,grid:f,class:f,timing:f,reset:f,unit:f,animation:f,vars:$,sizes:f,shape:f},z=(t,s,e,c)=>{(0,u.parkHostObject)(t,e,s);const r={};for(const n of c)t[n]===s&&(t[n]=r);return t.verbose&&console.warn("[scratch] design-system family",e,"resolved to a host object; parked it and allocated a plain bucket"),r},M=(t,s,e)=>{const c=(0,v.getActiveConfig)(),r=(0,v.toCamel)(t),n=r.toLowerCase(),d=c[r]||c[n]||c[t],i=(0,u.isHostObject)(d)?z(c,d,n,[r,n,t]):d,m=D[r]||D[n];if(m)try{const a=m(s,e);return i&&(i[e]=a),i}catch(a){c.verbose&&console.warn("Error setting",n,"value",s,e,a)}if(!m){const a=i||(c[n]={});return a[e]=s,a}c.verbose&&console.warn("Can not find",n,"method in scratch")},j=(t,s)=>{const e=(0,v.getActiveConfig)(),c=t.toLowerCase();return(0,u.isHostObject)(s)?((0,u.parkHostObject)(e,c,s),e.verbose&&console.warn("[scratch] ignoring host object passed as the",c,"design-system family"),e[c]||e[t]):(Object.keys(s).sort((n,d)=>{const i=(0,T.isObject)(s[n])||(0,T.isArray)(s[n])?1:0,m=(0,T.isObject)(s[d])||(0,T.isArray)(s[d])?1:0;return i-m}).forEach(n=>{try{return M(c,s[n],n)}catch(d){e.verbose&&console.warn("Error setting",c,"value",s[n],n,d)}}),e[c]||e[t])},B=(t,s)=>{const e=s||(0,v.getActiveConfig)();e.globalTheme=t;const r=(0,u.resolveConfigDocument)(e)||(typeof document<"u"?document:null),n=r&&r.defaultView||(typeof window<"u"?window:null);if(r){const i=e.themeRoot||r.documentElement;if(t&&t!=="auto")i.setAttribute("data-theme",t),e.resolvedTheme=t,t==="dark"||t==="light"?i.style.colorScheme=t:i.style.colorScheme="light dark";else if(n&&n.matchMedia){const a=p=>{const S=p.matches?"dark":"light";i.setAttribute("data-theme",S),e.resolvedTheme=S},h=n.matchMedia("(prefers-color-scheme: dark)");if(a(h),i.style.colorScheme="light dark",!e.__prefersListener){e.__prefersListener=a;try{h.addEventListener("change",a)}catch{h.addListener(a)}}}else i.setAttribute("data-theme","light"),e.resolvedTheme="light",i.style.colorScheme="light"}const d=e.varPrefix?`--${e.varPrefix}-theme-`:"--theme-";for(const i in e.cssVars)i.startsWith(d)&&delete e.cssVars[i];for(const i in e.cssMediaVars)delete e.cssMediaVars[i];if(r&&e.cssVars){const i=e.scopeSelector||":root",m=r.styleSheets;for(let a=0;a<m.length;a++)try{const h=m[a].cssRules;for(let p=0;p<h.length;p++)if(h[p].selectorText===i){for(const S in e.cssVars)h[p].style.setProperty(S,e.cssVars[S]);return e}}catch{}}return e},U={},J=(t,s=U)=>{let e=s.config||(0,v.getActiveConfig)();const{version:c,verbose:r,useVariable:n,useReset:d,useSvgSprite:i,useFontImport:m,useIconSprite:a,globalTheme:h,themeRoot:p,useDocumentTheme:S,useDefaultConfig:E,semanticIcons:R,hoverMedia:A,files:L,assets:F,...y}=t;s.newConfig&&(e=(0,v.setActiveConfig)(s.newConfig)),(0,u.isDomDocument)(y.document)&&(e.__domDocument=y.document,delete y.document),(0,u.isDomDocument)(e.document)&&(e.__domDocument||(e.__domDocument=e.document),e.document={}),L!==void 0&&(e.files=L),F!==void 0&&(e.assets=F),r!==void 0&&(e.verbose=r),n!==void 0&&(e.useVariable=n),d!==void 0&&(e.useReset=d),m!==void 0&&(e.useFontImport=m),i!==void 0&&(e.useSvgSprite=i),a!==void 0&&(e.useIconSprite=a),S!==void 0&&(e.useDocumentTheme=S),h!==void 0&&(e.globalTheme=h),p!==void 0&&(e.themeRoot=p),t.useThemeSuffixedVars!==void 0&&(e.useThemeSuffixedVars=t.useThemeSuffixedVars),E!==void 0&&(e.useDefaultConfig=E),R!==void 0&&(e.semanticIcons=R),A!==void 0&&(e.hoverMedia=A),e.verbose&&console.log(e);const w=(0,u.resolveConfigDocument)(e)||(typeof document<"u"?document:null),C=w&&w.defaultView||(typeof window<"u"?window:null),b=w&&(e.themeRoot||w.documentElement);if(b&&typeof b.setAttribute=="function")if(e.globalTheme&&e.globalTheme!=="auto")b.setAttribute("data-theme",e.globalTheme),e.resolvedTheme=e.globalTheme,e.globalTheme==="dark"||e.globalTheme==="light"?b.style.colorScheme=e.globalTheme:b.style.colorScheme="light dark";else if(C&&C.matchMedia){const g=P=>{const k=P.matches?"dark":"light";b.setAttribute("data-theme",k),e.resolvedTheme=k},V=C.matchMedia("(prefers-color-scheme: dark)");if(g(V),b.style.colorScheme="light dark",!e.__prefersListener){e.__prefersListener=g;try{V.addEventListener("change",g)}catch{V.addListener(g)}}}else b.setAttribute("data-theme","light"),e.resolvedTheme="light",b.style.colorScheme="light";e.__svgCache||(e.__svgCache={});const _=Object.keys(y).filter(l=>!l.startsWith("__")),I=new Set(_);if(_.forEach(l=>{const g=l.toLowerCase();g!==l&&I.has(g)&&(0,T.deepMerge)(y[g],y[l])}),_.map(l=>{const g=l.toLowerCase();if(!(g!==l&&I.has(g)))return j(l,y[l])}),e.varPrefix&&(e.typography&&(e.typography.varPrefix=e.varPrefix),e.spacing&&(e.spacing.varPrefix=e.varPrefix),e.timing&&(e.timing.varPrefix=e.varPrefix)),y.typography)try{(0,o.applyTypographySequence)()}catch(l){e.verbose&&console.warn("Error applying typography sequence",l)}if(y.spacing)try{(0,o.applySpacingSequence)()}catch(l){e.verbose&&console.warn("Error applying spacing sequence",l)}if(y.timing)try{(0,o.applyTimingSequence)()}catch(l){e.verbose&&console.warn("Error applying timing sequence",l)}(0,o.applyDocument)();const O=(0,o.applyReset)();return O&&(e.reset=O),e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var
|
|
1
|
+
"use strict";var w=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var F=(r,t)=>{for(var g in t)w(r,g,{get:t[g],enumerable:!0})},q=(r,t,g,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of O(t))!j.call(r,a)&&a!==g&&w(r,a,{get:()=>t[a],enumerable:!(e=L(t,a))||e.enumerable});return r};var _=r=>q(w({},"__esModule",{value:!0}),r);var N={};F(N,{STANDARD_SCHEME_QUERIES:()=>P,getColor:()=>A,getMediaColor:()=>H,resolveColorRgb:()=>D,setAdaptiveSchemeVar:()=>E,setColor:()=>M,setGradient:()=>T});module.exports=_(N);var d=require("@symbo.ls/utils"),S=require("../factory.js"),h=require("../utils/index.js");const P={light:"(prefers-color-scheme: light)",dark:"(prefers-color-scheme: dark)"},A=(r,t,g)=>{const e=g||(0,S.getActiveConfig)();if(!(0,d.isString)(r)){e.verbose&&console.warn(r,"- type for color is not valid");return}if((0,h.isCSSVar)(r))return`var(${r})`;t&&r[t]&&(r=r[t]);let a,l,o;if((0,d.isArray)(r))[a,l,o]=r;else{const s=(0,h.parseColorToken)(r);if(!s){const{color:i,gradient:C}=e;let $=C[r]||i[r];return $?(t&&$[t]&&($=$[t]),e.useVariable?`var(${$.var})`:$.value):r}if(s.passthrough)return s.passthrough;if(s.cssVar)return`var(${s.cssVar})`;a=s.name,l=s.alpha,o=s.tone}const{color:b,gradient:f}=e;let n=b[a]||f[a];if(!n)return e.verbose&&console.warn("Can't find color ",a),r;if(t)if(n[t]!==void 0)n=n[t];else if((0,d.isArray)(n)){const s=t.charCodeAt(0)===64?t.slice(1):t;s==="dark"?n=n[1]!==void 0?n[1]:n[0]:(s!=="light"&&e.verbose&&console.warn(r," - array-form color tokens only support light/dark; falling back to the light slot for scheme",t),n=n[0])}else e.verbose&&console.warn(r," - does not have ",t);if((0,d.isString)(n))return A(n,null,g);let p=n.rgb;if(!p){const s=e.useVariable?`var(${n.var})`:n.value;if((l||o)&&s){const i=l!==void 0?l:1;if(!o)return`rgb(from ${s} r g b / ${i})`;if(o.charCodeAt(0)===43||o.charCodeAt(0)===45){const $=parseFloat(o),u=$<0?"-":"+",c=Math.abs($);return`rgb(from ${s} calc(r ${u} ${c}) calc(g ${u} ${c}) calc(b ${u} ${c}) / ${i})`}return`hsl(from ${s} h s ${o}% / ${i})`}return s}return o&&!n[o]&&(p=(0,h.getRgbTone)(p,o),n[o]={rgb:p,var:`${n.var}-${o}`}),n[o]&&(p=n[o].rgb),l?`rgba(${p}, ${l})`:o?`rgba(${p}, 1)`:e.useVariable?`var(${n.var})`:`rgb(${p})`},D=(r,t,g)=>{const e=t||(0,S.getActiveConfig)();if(!(0,d.isString)(r))return null;const a=(0,h.parseColorToken)(r);if(a){if(a.passthrough){const i=(0,h.colorStringToRgbaArray)(a.passthrough);return i&&i.length>=3?{rgb:[i[0],i[1],i[2]],alpha:i[3]!==void 0?i[3]:1}:null}if(a.cssVar)return null}const l=a?a.name:r,{color:o,gradient:b}=e;let f=o[l]||b[l];if(!f){const i=(0,h.colorStringToRgbaArray)(r);return!i||i.length<3||i[0]===0&&i[1]===0&&i[2]===0&&i[3]===0&&r.toLowerCase()!=="transparent"?null:{rgb:[i[0],i[1],i[2]],alpha:i[3]!==void 0?i[3]:1}}if((0,d.isString)(f))return D(f,e,g);if(f.rgb===void 0&&(0,d.isObject)(f)){const i=`@${g||"light"}`;f=f[i]!==void 0?f[i]:f["@light"]}if(!f||f.rgb===void 0)return null;let n=f.rgb;a&&a.tone&&(n=(0,h.getRgbTone)(n,a.tone));const p=(0,d.isString)(n)?n.split(",").map(i=>parseFloat(i.trim())):n,s=a&&a.alpha!==void 0?parseFloat(a.alpha):f.alpha!==void 0?f.alpha:1;return{rgb:p,alpha:s}},H=(r,t,g)=>{const e=g||(0,S.getActiveConfig)();if(t||(t=e.globalTheme==="auto"?null:e.globalTheme),!(0,d.isString)(r)){e.verbose&&console.warn(r,"- type for color is not valid");return}if((0,h.isCSSVar)(r))return`var(${r})`;let a,l,o;if((0,d.isArray)(r))a=r[0];else{const s=(0,h.parseColorToken)(r);if(s){if(s.passthrough)return s.passthrough;if(s.cssVar)return`var(${s.cssVar})`;a=s.name,l=s.alpha,o=s.tone}else a=r}const{color:b,gradient:f}=e,n=b[a]||f[a],p=(0,d.isObject)(n);if(p&&n.value)return A(r,`@${t}`,g);if(p){if(e.useVariable&&n.var)return l||o?A(r,null,g):`var(${n.var})`;if(t)return A(r,`@${t}`,g);{const s={};for(const i in n){if(i.charCodeAt(0)!==64)continue;const C=i.slice(1),$=e.media&&e.media[C]||P[C];if(!$)continue;const u="@media "+($==="print"?`${$}`:`screen and ${$}`);s[u]=A(r,i,g)}return s}}else return e.verbose&&console.warn("Can't find color",r),r},E=(r,t,g,e)=>{const l=`--${e.varPrefix?e.varPrefix+"-":""}${t}-${g}`;let o;const b={};for(const f in r){if(f.charCodeAt(0)!==64)continue;const n=f.slice(1),p=r[f],s=p&&(p.value||p);!s||typeof s!="string"||(b[n]=s,(n==="light"||o===void 0)&&(o=s))}if(o!==void 0){e.cssVars[l]=o,e.cssMediaVars||(e.cssMediaVars={});for(const f in b){const n=`[data-theme="${f}"]`;if(e.cssMediaVars[n]||(e.cssMediaVars[n]={}),e.cssMediaVars[n][l]=b[f],f==="light"||f==="dark"){const p=`@media (prefers-color-scheme: ${f})`;e.cssMediaVars[p]||(e.cssMediaVars[p]={}),e.cssMediaVars[p][l]=b[f]}}return r.var=l,l}},M=(r,t,g)=>{const e=(0,S.getActiveConfig)();if((0,d.isObject)(r)&&r.value!==void 0&&(r.rgb!==void 0||r.var!==void 0))return e.useVariable&&r.var&&(e.cssVars[r.var]=r.value),r;if((0,d.isString)(r)&&(0,h.isCSSVar)(r)){const u=r.slice(2);if(r=A(u),!(r.includes("rgb")||r.includes("var")||r.includes("#"))){const c=u.split(" ");let m=e.color[c[0]];if(m&&!m.value&&!m.rgb&&((0,d.isString)(m)||(0,d.isArray)(m)||(0,d.isObject)(m))&&(e.color[c[0]]=M(m,c[0]),m=e.color[c[0]]),m&&m.value){let V=m.rgb;const x=c[1]!==void 0?c[1]:"1",R=c[2];R&&(V=(0,h.getRgbTone)(V,R)),r=`rgba(${V}, ${x})`}else{const V=c[2],x=c[1]!==void 0?c[1]:"1";if(V)try{const R=(0,h.colorStringToRgbaArray)(c[0]);R&&R.length>=3?r=`rgba(${(0,h.getRgbTone)(R.slice(0,3).join(", "),V)}, ${x})`:r=c[0]}catch{r=c[0]}else r=c[0]}}}if((0,d.isArray)(r)&&(r={"@light":r[0],"@dark":r[1]!==void 0?r[1]:r[0]}),(0,d.isObject)(r)){const u={};for(const c in r)c!=="var"&&(u[c]=M(r[c],t,c.slice(0,1)==="@"?c.slice(1):c));return e.useVariable&&E(u,"color",t,e),u}const l=`--${e.varPrefix?e.varPrefix+"-":""}color-${t}`+(g?`-${g}`:"");let o=r.value||r;if((0,d.isString)(o)&&!o.includes("(")&&!o.startsWith("#")){const u=(0,h.parseColorToken)(o);if(u&&u.name&&!u.passthrough&&!u.cssVar){const c=e.color[u.name];c&&!c.value&&!c.rgb&&((0,d.isString)(c)||(0,d.isArray)(c)||(0,d.isObject)(c))&&(e.color[u.name]=M(c,u.name));const m=e.color[u.name];if(m&&m.rgb){let V=m.rgb;u.tone&&(V=(0,h.getRgbTone)(V,u.tone));const x=u.alpha?parseFloat(u.alpha):1;o=`rgba(${V}, ${x})`}}}const b=(0,h.colorStringToRgbaArray)(o),[f,n,p,s=1]=b,i=parseFloat(s.toFixed(2)),C=`${f}, ${n}, ${p}`,$=`rgba(${C}, ${i})`;return e.useVariable&&(e.cssVars[l]=$),{var:l,rgb:C,alpha:i,value:$}},T=(r,t,g)=>{const e=(0,S.getActiveConfig)();if((0,d.isObject)(r)&&r.value!==void 0&&r.var!==void 0)return e.useVariable&&(e.cssVars[r.var]=r.value),r;if((0,d.isString)(r)&&(0,h.isCSSVar)(r)&&(r=A(r.slice(2))),(0,d.isArray)(r)&&(r={"@light":r[0],"@dark":r[1]!==void 0?r[1]:r[0]}),(0,d.isObject)(r)){const o={};for(const b in r)b!=="var"&&(o[b]=T(r[b],t,b.slice(0,1)==="@"?b.slice(1):b));return e.useVariable&&E(o,"gradient",t,e),o}const l=`--${e.varPrefix?e.varPrefix+"-":""}gradient-${t}`+(g?`-${g}`:"");return e.useVariable&&(e.cssVars[l]=r.value||r),{var:l,value:r.value||r}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var p=(e,t,m,x)=>{if(t&&typeof t=="object"||typeof t=="function")for(let f of i(t))!u.call(e,f)&&f!==m&&s(e,f,{get:()=>t[f],enumerable:!(x=c(t,f))||x.enumerable});return e},o=(e,t,m)=>(p(e,t,"default"),m&&p(m,t,"default"));var a=e=>p(s({},"__esModule",{value:!0}),e);var r={};module.exports=a(r);o(r,require("./color.js"),module.exports);o(r,require("./theme.js"),module.exports);o(r,require("./font.js"),module.exports);o(r,require("./typography.js"),module.exports);o(r,require("./spacing.js"),module.exports);o(r,require("./shape.js"),module.exports);o(r,require("./shadow.js"),module.exports);o(r,require("./timing.js"),module.exports);o(r,require("./document.js"),module.exports);o(r,require("./svg.js"),module.exports);o(r,require("./reset.js"),module.exports);
|
|
1
|
+
"use strict";var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var p=(e,t,m,x)=>{if(t&&typeof t=="object"||typeof t=="function")for(let f of i(t))!u.call(e,f)&&f!==m&&s(e,f,{get:()=>t[f],enumerable:!(x=c(t,f))||x.enumerable});return e},o=(e,t,m)=>(p(e,t,"default"),m&&p(m,t,"default"));var a=e=>p(s({},"__esModule",{value:!0}),e);var r={};module.exports=a(r);o(r,require("./color.js"),module.exports);o(r,require("./ink.js"),module.exports);o(r,require("./theme.js"),module.exports);o(r,require("./font.js"),module.exports);o(r,require("./typography.js"),module.exports);o(r,require("./spacing.js"),module.exports);o(r,require("./shape.js"),module.exports);o(r,require("./shadow.js"),module.exports);o(r,require("./timing.js"),module.exports);o(r,require("./document.js"),module.exports);o(r,require("./svg.js"),module.exports);o(r,require("./reset.js"),module.exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var C=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var T=(a,e)=>{for(var l in e)C(a,l,{get:e[l],enumerable:!0})},ee=(a,e,l,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _(e))!k.call(a,o)&&o!==l&&C(a,o,{get:()=>e[o],enumerable:!(c=Z(e,o))||c.enumerable});return a};var te=a=>ee(C({},"__esModule",{value:!0}),a);var re={};T(re,{getSafeInk:()=>K,getSafeInkInfo:()=>oe});module.exports=te(re);var j=require("@symbo.ls/utils"),F=require("../factory.js"),r=require("../utils/index.js"),g=require("./color.js");const K=(a,e,l={},c)=>{const o=c||(0,F.getActiveConfig)(),{min:N=4.5,large:O=!1,scheme:V,meta:B=!1,maxIterations:E=15}=l,v=O?3:N,m=V||(o.globalTheme&&o.globalTheme!=="auto"?o.globalTheme:"light"),I=(0,j.isString)(e)?e:String(e),h=(0,r.parseColorToken)(a),x=h&&!h.passthrough&&!h.cssVar?h.name:null,b=(t,n)=>B?{value:t,...n}:t;if(x){const t=o.color[`${x}Safe`];if(t){const n=`${I}@${m}`,s=t[n]!==void 0?t[n]:t[I];if(s!==void 0){const D=s&&s.rgb!==void 0?o.useVariable&&s.var?`var(${s.var})`:s.value:(0,g.getColor)(s,null,o);return b(D,{ratio:null,deviation:0,derived:!1,overridden:!0})}}}const M=(0,g.getColor)(a,m?`@${m}`:null,o),i=(0,g.resolveColorRgb)(a,o,m),p=(0,g.resolveColorRgb)(e,o,m);if(!i||!p)return o.verbose&&console.warn("getSafeInk: could not resolve",a,e,"\u2014 returning hue unchanged"),b(M,{ratio:null,deviation:0,derived:!1,overridden:!1,unresolved:!0});const f=(0,r.compositeOverBackdrop)(p.rgb,p.alpha),G=(0,r.compositeOverBackdrop)(i.rgb,i.alpha,f),L=(0,r.contrastRatio)(G,f);if(L>=v-.02)return b(M,{ratio:L,deviation:0,derived:!1,overridden:!1});const[H,P,q]=(0,r.rgbToHSL)(i.rgb[0]/255,i.rgb[1]/255,i.rgb[2]/255),u=q*100,y=(0,r.relativeLuminance)(f)>.5,z=y?u:100-u,w=t=>{const n=y?u-t:u+t,s=Math.max(0,Math.min(100,n));return{rgb:(0,r.hslToRgb)(H,P,s/100).map(Y=>Math.max(0,Math.min(1,Y))*255),L:s}},R=t=>{const{rgb:n}=w(t),s=(0,r.compositeOverBackdrop)(n,i.alpha,f);return(0,r.contrastRatio)(s,f)};let S=0,d=z;const A=R(d)>=v;if(A)for(let t=0;t<E;t++){const n=(S+d)/2;R(n)>=v?d=n:S=n}else S=d;const{rgb:J,L:Q}=w(d),$=J.map(t=>Math.round(t)),U=R(d),W=i.alpha<1?`rgba(${$.join(", ")}, ${i.alpha})`:`rgb(${$.join(", ")})`,X=Math.abs(Q-u);return b(W,{rgb:$,ratio:U,startRatio:L,deviation:X,derived:!0,overridden:!1,reachable:A})},oe=(a,e,l={},c)=>K(a,e,{...l,meta:!0},c);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var I=(t,e)=>{for(var r in e)u(t,r,{get:e[r],enumerable:!0})},L=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of S(e))!$.call(t,n)&&n!==r&&u(t,n,{get:()=>e[n],enumerable:!(s=y(e,n))||s.enumerable});return t};var O=t=>L(u({},"__esModule",{value:!0}),t);var K={};I(K,{CSS_NATIVE_COLOR_REGEX:()=>w,changeLightness:()=>N,colorStringToRgbaArray:()=>c,compositeOverBackdrop:()=>k,contrastRatio:()=>Z,getColorShade:()=>d,getRgbTone:()=>D,hexToRgb:()=>A,hexToRgbArray:()=>f,hexToRgba:()=>_,hslToRgb:()=>g,isCSSVar:()=>b,isResolvedColor:()=>G,mixTwoColors:()=>E,mixTwoRgb:()=>H,mixTwoRgba:()=>l,opacify:()=>j,parseColorToken:()=>z,relativeLuminance:()=>h,rgbArrayToHex:()=>x,rgbToHSL:()=>m,rgbToHex:()=>F,splitTopLevelCommas:()=>X,toLinearChannel:()=>p});module.exports=O(K);var a=require("@symbo.ls/utils");const c=t=>{if(t==="")return[0,0,0,0];if(t.toLowerCase()==="transparent")return[0,0,0,0];if(t[0]==="#")return t.length<7&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(t.length>4?t[4]+t[4]:"")),[parseInt(t.substr(1,2),16),parseInt(t.substr(3,2),16),parseInt(t.substr(5,2),16),t.length>7?parseInt(t.substr(7,2),16)/255:1];if(t.indexOf("rgb")===-1&&a.document&&a.window){const e=a.document.body.appendChild(a.document.createElement("fictum")),r="rgb(1, 2, 3)";if(e.style.color=r,e.style.color!==r){a.document.body.removeChild(e);return}if(e.style.color=t,e.style.color===r||e.style.color==="")return a.document.body.removeChild(e),[0,0,0,0];t=a.window.getComputedStyle(e).color,a.document.body.removeChild(e)}return t.indexOf("rgb")===0?(t.indexOf("rgba")===-1&&(t=`${t}, 1`),t.match(/[\.\d]+/g).map(e=>+e)):[0,0,0,0]},E=(t,e,r=.5)=>(t=c(t),e=c(e),l(t,e,r)),A=(t,e=1)=>{const[r,s,n]=t.match(/\w\w/g).map(o=>parseInt(o,16));return`rgb(${r},${s},${n})`},f=(t,e=1)=>{const[r,s,n]=t.match(/\w\w/g).map(o=>parseInt(o,16));return[r,s,n]},F=(t,e,r)=>"#"+(1<<24|t<<16|e<<8|r).toString(16).slice(1),x=([t,e,r])=>((1<<24)+(t<<16)+(e<<8)+r).toString(16).slice(1),_=(t,e=1)=>{const[r,s,n]=t.match(/\w\w/g).map(o=>parseInt(o,16));return`rgba(${r},${s},${n},${e})`},H=(t,e,r=.5)=>{const s=[];for(let n=0;n<3;n++)s[n]=~~(t[n]+(e[n]-t[n])*r);return`rgb(${s})`},N=(t,e)=>{const[r,s,n]=e,o=Math.max(0,Math.min(100,n+parseFloat(t)));return[r,s,o]},m=(t,e,r)=>{const s=Math.max(t,e,r),n=s-Math.min(t,e,r),o=1-Math.abs(s+s-n-1),i=n&&(s==t?(e-r)/n:s==e?2+(r-t)/n:4+(t-e)/n);return[60*(i<0?i+6:i),o?n/o:0,(s+s-n)/2]},g=(t,e,r,s=e*Math.min(r,1-r),n=(o,i=(o+t/30)%12)=>r-s*Math.max(Math.min(i-3,9-i,1),-1))=>[n(0),n(8),n(4)],d=(t,e)=>{const r=parseInt(t,16);let s=(r>>16)+e;s>255?s=255:s<0&&(s=0);let n=(r>>8&255)+e;n>255?n=255:n<0&&(n=0);let o=(r&255)+e;return o>255?o=255:o<0&&(o=0),((o|n<<8|s<<16)+16777216).toString(16).slice(1)},l=(t,e,r=.5)=>{const s=[];for(let n=0;n<4;n++){const o=n===3?i=>i:Math.round;s[n]=o(t[n]+(e[n]-t[n])*r)}return`rgba(${s})`},j=(t,e)=>{const r=c(t);if(!r){(0,a.isNotProduction)()&&console.warn(t+" color is not rgba");return}return r[3]=e,`rgba(${r})`},b=t=>t.charCodeAt(0)===45&&t.charCodeAt(1)===45,w=/(?:rgba?\(|hsla?\(|#[0-9a-fA-F]{3,8}\b)/,V=/^([a-zA-Z]\w*(?:-[a-zA-Z]\w*)*)(?:\.(\d+))?(?:([+-]\d+|=\d+))?$/,z=t=>{if(!(0,a.isString)(t))return null;if(w.test(t))return{passthrough:t};if(b(t))return{cssVar:t};const e=t.match(V);if(!e)return null;const[,r,s,n]=e,o=s!==void 0?`0.${s}`:void 0,i=n&&n[0]==="="?n.slice(1):n;return{name:r,alpha:o,tone:i}},G=t=>(0,a.isString)(t)&&(t.includes("rgb")||t.includes("var(")||t.includes("#")),X=t=>{const e=[];let r="",s=0;for(const n of t){if(n==="("?s+=1:n===")"&&s>0&&(s-=1),n===","&&s===0){e.push(r),r="";continue}r+=n}return(r.length||!e.length)&&e.push(r),e},p=t=>(t/=255,t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)),h=t=>.2126*p(t[0])+.7152*p(t[1])+.0722*p(t[2]),Z=(t,e)=>{const r=h(t)+.05,s=h(e)+.05;return r>s?r/s:s/r},k=(t,e=1,r=[255,255,255])=>e>=1?t:t.map((s,n)=>s*e+r[n]*(1-e)),D=(t,e)=>{(0,a.isString)(t)&&t.includes("rgb")&&(t=c(t).join(", ")),(0,a.isString)(t)&&(t=t.split(",").map(n=>parseFloat(n.trim()))),(0,a.isNumber)(e)&&(e+="");const r=x(t),s=e.slice(0,1);if(s==="-"||s==="+"){const n=d(r,parseFloat(e));return f(n).join(", ")}else{const[n,o,i]=t,[C,T]=m(n/255,o/255,i/255),R=Math.max(0,Math.min(100,parseFloat(e)))/100;return g(C,T,R).map(M=>Math.round(Math.max(0,Math.min(1,M))*255)).join(", ")}};
|
package/dist/esm/src/factory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{deepClone as
|
|
1
|
+
import{deepClone as S,deepMerge as b,isDefined as l,isObject as h}from"@symbo.ls/utils";import{createSignal as v}from"@symbo.ls/signal";import*as T from"./defaultConfig/index.js";const d={},C={},f=T,p={},x=e=>e.replace(/_([a-z])/g,(t,o)=>o.toUpperCase());for(const e in f){const t=e.toLowerCase();p[t]=f[e];const o=x(t);o!==t&&(p[o]=f[e]),t!==e&&(p[e]=f[e])}const i={verbose:!1,useVariable:!0,useReset:!0,globalTheme:"auto",cssVars:d,cssMediaVars:C,CSS_VARS:d,CSS_MEDIA_VARS:C,_scratchConfig:!0,...p},m=(e,t)=>{if(!e)return null;if(e.__globalThemeSignal)return l(t)&&e.__globalThemeSignal.set(t),e.__globalThemeSignal;const o=l(t)?t:e.globalTheme,s=v(l(o)?o:"auto");return Object.defineProperty(e,"globalTheme",{get(){return s.get()},set(r){s.set(r)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"__globalThemeSignal",{value:s,enumerable:!1,configurable:!0,writable:!0}),s},D=e=>e?m(e):null,g=(e,t)=>{if(!e)return null;if(e.__resolvedThemeSignal)return l(t)&&e.__resolvedThemeSignal.set(t),e.__resolvedThemeSignal;const o=l(t)?t:e.resolvedTheme,s=v(l(o)?o:null);return Object.defineProperty(e,"resolvedTheme",{get(){return s.get()},set(r){s.set(r)},enumerable:!1,configurable:!0}),Object.defineProperty(e,"__resolvedThemeSignal",{value:s,enumerable:!1,configurable:!0,writable:!0}),s},I=e=>e?g(e):null;m(i),g(i);const _=S(i),a={active:"0",0:i},M=e=>(l(e)&&(a.active=e),a[e||a.active]),u=[],j=e=>{e&&e._scratchConfig&&u.push(e)},L=()=>{u.pop()},A=e=>u.length?u[u.length-1]:a[e||a.active]||i,w=e=>{if(h(e))return a.active="1",a[1]=b(e,S(_)),m(a[1]),g(a[1]),e},O=["useReset","useFontImport","useIconSprite","useSvgSprite","useDocumentTheme","useDefaultIcons","useDefaultConfig"],y=["useVariable","globalTheme","verbose"],V=[["fontfamily","fontFamily","font_family"],["fontfamilytypes","fontFamilyTypes"],["semanticicons","semanticIcons"],["svgdata","svgData"]],P=e=>{for(const t of V){let o;for(const s of t){const r=e[s];h(r)&&(o=o?b(r,o):r)}if(o)for(const s of t)h(e[s])&&(e[s]=o)}},G=(e,t,{cleanBase:o=!1}={})=>{const s=o?null:A(),r=S(!o&&s&&s._scratchConfig?s:_);for(const c of O)delete r[c];for(const c of y)Object.prototype.hasOwnProperty.call(_,c)?r[c]=_[c]:delete r[c];const n=b(t||{},r);return n.cssVars={},n.cssMediaVars={},n.CSS_VARS=n.cssVars,n.CSS_MEDIA_VARS=n.cssMediaVars,n._scratchConfig=!0,P(n),m(n),g(n),e&&(a[e]=n),n};export{i as CONFIG,a as FACTORY,M as activateConfig,G as createConfig,C as cssMediaVars,d as cssVars,g as defineResolvedThemeSignal,m as defineThemeSignal,A as getActiveConfig,I as getResolvedThemeSignal,D as getThemeSignal,L as popConfig,j as pushConfig,w as setActiveConfig,x as toCamel};
|
package/dist/esm/src/set.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getActiveConfig as
|
|
1
|
+
import{getActiveConfig as v,setActiveConfig as G,toCamel as W}from"./factory.js";import{setColor as N,setGradient as H,setFont as Y,setFontFamily as F,setTheme as $,setSvgIcon as z,setSVG as B,applyTypographySequence as U,applySpacingSequence as J,applyReset as K,applyTimingSequence as Q,applyDocument as X,setShadow as Z}from"./system/index.js";import{deepMerge as ee,isObject as I,isArray as O}from"@symbo.ls/utils";import{isDomDocument as P,isHostObject as k,parkHostObject as M,resolveConfigDocument as j}from"./utils/host.js";const te=(t,s)=>{const e=v(),{cssVars:n}=e,i=s.startsWith("--")?s:`--${s}`;return n[i]=t,t},l=t=>t,q={color:N,gradient:H,font:Y,fontFamily:F,fontfamily:F,theme:$,icons:z,semanticIcons:l,semanticicons:l,svg:B,svgData:l,typography:l,shadow:Z,spacing:l,media:l,grid:l,class:l,timing:l,reset:l,unit:l,animation:l,vars:te,sizes:l,shape:l},se=(t,s,e,n)=>{M(t,e,s);const i={};for(const o of n)t[o]===s&&(t[o]=i);return t.verbose&&console.warn("[scratch] design-system family",e,"resolved to a host object; parked it and allocated a plain bucket"),i},oe=(t,s,e)=>{const n=v(),i=W(t),o=i.toLowerCase(),f=n[i]||n[o]||n[t],r=k(f)?se(n,f,o,[i,o,t]):f,d=q[i]||q[o];if(d)try{const c=d(s,e);return r&&(r[e]=c),r}catch(c){n.verbose&&console.warn("Error setting",o,"value",s,e,c)}if(!d){const c=r||(n[o]={});return c[e]=s,c}n.verbose&&console.warn("Can not find",o,"method in scratch")},re=(t,s)=>{const e=v(),n=t.toLowerCase();return k(s)?(M(e,n,s),e.verbose&&console.warn("[scratch] ignoring host object passed as the",n,"design-system family"),e[n]||e[t]):(Object.keys(s).sort((o,f)=>{const r=I(s[o])||O(s[o])?1:0,d=I(s[f])||O(s[f])?1:0;return r-d}).forEach(o=>{try{return oe(n,s[o],o)}catch(f){e.verbose&&console.warn("Error setting",n,"value",s[o],o,f)}}),e[n]||e[t])},me=(t,s)=>{const e=s||v();e.globalTheme=t;const i=j(e)||(typeof document<"u"?document:null),o=i&&i.defaultView||(typeof window<"u"?window:null);if(i){const r=e.themeRoot||i.documentElement;if(t&&t!=="auto")r.setAttribute("data-theme",t),e.resolvedTheme=t,t==="dark"||t==="light"?r.style.colorScheme=t:r.style.colorScheme="light dark";else if(o&&o.matchMedia){const c=h=>{const y=h.matches?"dark":"light";r.setAttribute("data-theme",y),e.resolvedTheme=y},m=o.matchMedia("(prefers-color-scheme: dark)");if(c(m),r.style.colorScheme="light dark",!e.__prefersListener){e.__prefersListener=c;try{m.addEventListener("change",c)}catch{m.addListener(c)}}}else r.setAttribute("data-theme","light"),e.resolvedTheme="light",r.style.colorScheme="light"}const f=e.varPrefix?`--${e.varPrefix}-theme-`:"--theme-";for(const r in e.cssVars)r.startsWith(f)&&delete e.cssVars[r];for(const r in e.cssMediaVars)delete e.cssMediaVars[r];if(i&&e.cssVars){const r=e.scopeSelector||":root",d=i.styleSheets;for(let c=0;c<d.length;c++)try{const m=d[c].cssRules;for(let h=0;h<m.length;h++)if(m[h].selectorText===r){for(const y in e.cssVars)m[h].style.setProperty(y,e.cssVars[y]);return e}}catch{}}return e},ne={},ue=(t,s=ne)=>{let e=s.config||v();const{version:n,verbose:i,useVariable:o,useReset:f,useSvgSprite:r,useFontImport:d,useIconSprite:c,globalTheme:m,themeRoot:h,useDocumentTheme:y,useDefaultConfig:C,semanticIcons:_,hoverMedia:V,files:x,assets:D,...g}=t;s.newConfig&&(e=G(s.newConfig)),P(g.document)&&(e.__domDocument=g.document,delete g.document),P(e.document)&&(e.__domDocument||(e.__domDocument=e.document),e.document={}),x!==void 0&&(e.files=x),D!==void 0&&(e.assets=D),i!==void 0&&(e.verbose=i),o!==void 0&&(e.useVariable=o),f!==void 0&&(e.useReset=f),d!==void 0&&(e.useFontImport=d),r!==void 0&&(e.useSvgSprite=r),c!==void 0&&(e.useIconSprite=c),y!==void 0&&(e.useDocumentTheme=y),m!==void 0&&(e.globalTheme=m),h!==void 0&&(e.themeRoot=h),t.useThemeSuffixedVars!==void 0&&(e.useThemeSuffixedVars=t.useThemeSuffixedVars),C!==void 0&&(e.useDefaultConfig=C),_!==void 0&&(e.semanticIcons=_),V!==void 0&&(e.hoverMedia=V),e.verbose&&console.log(e);const b=j(e)||(typeof document<"u"?document:null),S=b&&b.defaultView||(typeof window<"u"?window:null),p=b&&(e.themeRoot||b.documentElement);if(p&&typeof p.setAttribute=="function")if(e.globalTheme&&e.globalTheme!=="auto")p.setAttribute("data-theme",e.globalTheme),e.resolvedTheme=e.globalTheme,e.globalTheme==="dark"||e.globalTheme==="light"?p.style.colorScheme=e.globalTheme:p.style.colorScheme="light dark";else if(S&&S.matchMedia){const u=A=>{const L=A.matches?"dark":"light";p.setAttribute("data-theme",L),e.resolvedTheme=L},w=S.matchMedia("(prefers-color-scheme: dark)");if(u(w),p.style.colorScheme="light dark",!e.__prefersListener){e.__prefersListener=u;try{w.addEventListener("change",u)}catch{w.addListener(u)}}}else p.setAttribute("data-theme","light"),e.resolvedTheme="light",p.style.colorScheme="light";e.__svgCache||(e.__svgCache={});const T=Object.keys(g).filter(a=>!a.startsWith("__")),E=new Set(T);if(T.forEach(a=>{const u=a.toLowerCase();u!==a&&E.has(u)&&ee(g[u],g[a])}),T.map(a=>{const u=a.toLowerCase();if(!(u!==a&&E.has(u)))return re(a,g[a])}),e.varPrefix&&(e.typography&&(e.typography.varPrefix=e.varPrefix),e.spacing&&(e.spacing.varPrefix=e.varPrefix),e.timing&&(e.timing.varPrefix=e.varPrefix)),g.typography)try{U()}catch(a){e.verbose&&console.warn("Error applying typography sequence",a)}if(g.spacing)try{J()}catch(a){e.verbose&&console.warn("Error applying spacing sequence",a)}if(g.timing)try{Q()}catch(a){e.verbose&&console.warn("Error applying timing sequence",a)}X();const R=K();return R&&(e.reset=R),e};export{q as VALUE_TRANSFORMERS,me as changeGlobalTheme,ue as set,re as setEach,oe as setValue};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as C,isArray as R,isString as
|
|
1
|
+
import{isObject as C,isArray as R,isString as $}from"@symbo.ls/utils";import{getActiveConfig as M}from"../factory.js";import{colorStringToRgbaArray as E,getRgbTone as w,isCSSVar as P,parseColorToken as D}from"../utils/index.js";const O={light:"(prefers-color-scheme: light)",dark:"(prefers-color-scheme: dark)"},S=(r,a,g)=>{const e=g||M();if(!$(r)){e.verbose&&console.warn(r,"- type for color is not valid");return}if(P(r))return`var(${r})`;a&&r[a]&&(r=r[a]);let f,d,s;if(R(r))[f,d,s]=r;else{const t=D(r);if(!t){const{color:o,gradient:V}=e;let h=V[r]||o[r];return h?(a&&h[a]&&(h=h[a]),e.useVariable?`var(${h.var})`:h.value):r}if(t.passthrough)return t.passthrough;if(t.cssVar)return`var(${t.cssVar})`;f=t.name,d=t.alpha,s=t.tone}const{color:p,gradient:c}=e;let n=p[f]||c[f];if(!n)return e.verbose&&console.warn("Can't find color ",f),r;if(a)if(n[a]!==void 0)n=n[a];else if(R(n)){const t=a.charCodeAt(0)===64?a.slice(1):a;t==="dark"?n=n[1]!==void 0?n[1]:n[0]:(t!=="light"&&e.verbose&&console.warn(r," - array-form color tokens only support light/dark; falling back to the light slot for scheme",a),n=n[0])}else e.verbose&&console.warn(r," - does not have ",a);if($(n))return S(n,null,g);let u=n.rgb;if(!u){const t=e.useVariable?`var(${n.var})`:n.value;if((d||s)&&t){const o=d!==void 0?d:1;if(!s)return`rgb(from ${t} r g b / ${o})`;if(s.charCodeAt(0)===43||s.charCodeAt(0)===45){const h=parseFloat(s),l=h<0?"-":"+",i=Math.abs(h);return`rgb(from ${t} calc(r ${l} ${i}) calc(g ${l} ${i}) calc(b ${l} ${i}) / ${o})`}return`hsl(from ${t} h s ${s}% / ${o})`}return t}return s&&!n[s]&&(u=w(u,s),n[s]={rgb:u,var:`${n.var}-${s}`}),n[s]&&(u=n[s].rgb),d?`rgba(${u}, ${d})`:s?`rgba(${u}, 1)`:e.useVariable?`var(${n.var})`:`rgb(${u})`},j=(r,a,g)=>{const e=a||M();if(!$(r))return null;const f=D(r);if(f){if(f.passthrough){const o=E(f.passthrough);return o&&o.length>=3?{rgb:[o[0],o[1],o[2]],alpha:o[3]!==void 0?o[3]:1}:null}if(f.cssVar)return null}const d=f?f.name:r,{color:s,gradient:p}=e;let c=s[d]||p[d];if(!c){const o=E(r);return!o||o.length<3||o[0]===0&&o[1]===0&&o[2]===0&&o[3]===0&&r.toLowerCase()!=="transparent"?null:{rgb:[o[0],o[1],o[2]],alpha:o[3]!==void 0?o[3]:1}}if($(c))return j(c,e,g);if(c.rgb===void 0&&C(c)){const o=`@${g||"light"}`;c=c[o]!==void 0?c[o]:c["@light"]}if(!c||c.rgb===void 0)return null;let n=c.rgb;f&&f.tone&&(n=w(n,f.tone));const u=$(n)?n.split(",").map(o=>parseFloat(o.trim())):n,t=f&&f.alpha!==void 0?parseFloat(f.alpha):c.alpha!==void 0?c.alpha:1;return{rgb:u,alpha:t}},Q=(r,a,g)=>{const e=g||M();if(a||(a=e.globalTheme==="auto"?null:e.globalTheme),!$(r)){e.verbose&&console.warn(r,"- type for color is not valid");return}if(P(r))return`var(${r})`;let f,d,s;if(R(r))f=r[0];else{const t=D(r);if(t){if(t.passthrough)return t.passthrough;if(t.cssVar)return`var(${t.cssVar})`;f=t.name,d=t.alpha,s=t.tone}else f=r}const{color:p,gradient:c}=e,n=p[f]||c[f],u=C(n);if(u&&n.value)return S(r,`@${a}`,g);if(u){if(e.useVariable&&n.var)return d||s?S(r,null,g):`var(${n.var})`;if(a)return S(r,`@${a}`,g);{const t={};for(const o in n){if(o.charCodeAt(0)!==64)continue;const V=o.slice(1),h=e.media&&e.media[V]||O[V];if(!h)continue;const l="@media "+(h==="print"?`${h}`:`screen and ${h}`);t[l]=S(r,o,g)}return t}}else return e.verbose&&console.warn("Can't find color",r),r},L=(r,a,g,e)=>{const d=`--${e.varPrefix?e.varPrefix+"-":""}${a}-${g}`;let s;const p={};for(const c in r){if(c.charCodeAt(0)!==64)continue;const n=c.slice(1),u=r[c],t=u&&(u.value||u);!t||typeof t!="string"||(p[n]=t,(n==="light"||s===void 0)&&(s=t))}if(s!==void 0){e.cssVars[d]=s,e.cssMediaVars||(e.cssMediaVars={});for(const c in p){const n=`[data-theme="${c}"]`;if(e.cssMediaVars[n]||(e.cssMediaVars[n]={}),e.cssMediaVars[n][d]=p[c],c==="light"||c==="dark"){const u=`@media (prefers-color-scheme: ${c})`;e.cssMediaVars[u]||(e.cssMediaVars[u]={}),e.cssMediaVars[u][d]=p[c]}}return r.var=d,d}},T=(r,a,g)=>{const e=M();if(C(r)&&r.value!==void 0&&(r.rgb!==void 0||r.var!==void 0))return e.useVariable&&r.var&&(e.cssVars[r.var]=r.value),r;if($(r)&&P(r)){const l=r.slice(2);if(r=S(l),!(r.includes("rgb")||r.includes("var")||r.includes("#"))){const i=l.split(" ");let b=e.color[i[0]];if(b&&!b.value&&!b.rgb&&($(b)||R(b)||C(b))&&(e.color[i[0]]=T(b,i[0]),b=e.color[i[0]]),b&&b.value){let m=b.rgb;const x=i[1]!==void 0?i[1]:"1",A=i[2];A&&(m=w(m,A)),r=`rgba(${m}, ${x})`}else{const m=i[2],x=i[1]!==void 0?i[1]:"1";if(m)try{const A=E(i[0]);A&&A.length>=3?r=`rgba(${w(A.slice(0,3).join(", "),m)}, ${x})`:r=i[0]}catch{r=i[0]}else r=i[0]}}}if(R(r)&&(r={"@light":r[0],"@dark":r[1]!==void 0?r[1]:r[0]}),C(r)){const l={};for(const i in r)i!=="var"&&(l[i]=T(r[i],a,i.slice(0,1)==="@"?i.slice(1):i));return e.useVariable&&L(l,"color",a,e),l}const d=`--${e.varPrefix?e.varPrefix+"-":""}color-${a}`+(g?`-${g}`:"");let s=r.value||r;if($(s)&&!s.includes("(")&&!s.startsWith("#")){const l=D(s);if(l&&l.name&&!l.passthrough&&!l.cssVar){const i=e.color[l.name];i&&!i.value&&!i.rgb&&($(i)||R(i)||C(i))&&(e.color[l.name]=T(i,l.name));const b=e.color[l.name];if(b&&b.rgb){let m=b.rgb;l.tone&&(m=w(m,l.tone));const x=l.alpha?parseFloat(l.alpha):1;s=`rgba(${m}, ${x})`}}}const p=E(s),[c,n,u,t=1]=p,o=parseFloat(t.toFixed(2)),V=`${c}, ${n}, ${u}`,h=`rgba(${V}, ${o})`;return e.useVariable&&(e.cssVars[d]=h),{var:d,rgb:V,alpha:o,value:h}},F=(r,a,g)=>{const e=M();if(C(r)&&r.value!==void 0&&r.var!==void 0)return e.useVariable&&(e.cssVars[r.var]=r.value),r;if($(r)&&P(r)&&(r=S(r.slice(2))),R(r)&&(r={"@light":r[0],"@dark":r[1]!==void 0?r[1]:r[0]}),C(r)){const s={};for(const p in r)p!=="var"&&(s[p]=F(r[p],a,p.slice(0,1)==="@"?p.slice(1):p));return e.useVariable&&L(s,"gradient",a,e),s}const d=`--${e.varPrefix?e.varPrefix+"-":""}gradient-${a}`+(g?`-${g}`:"");return e.useVariable&&(e.cssVars[d]=r.value||r),{var:d,value:r.value||r}};export{O as STANDARD_SCHEME_QUERIES,S as getColor,Q as getMediaColor,j as resolveColorRgb,L as setAdaptiveSchemeVar,T as setColor,F as setGradient};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./color.js";export*from"./theme.js";export*from"./font.js";export*from"./typography.js";export*from"./spacing.js";export*from"./shape.js";export*from"./shadow.js";export*from"./timing.js";export*from"./document.js";export*from"./svg.js";export*from"./reset.js";
|
|
1
|
+
export*from"./color.js";export*from"./ink.js";export*from"./theme.js";export*from"./font.js";export*from"./typography.js";export*from"./spacing.js";export*from"./shape.js";export*from"./shadow.js";export*from"./timing.js";export*from"./document.js";export*from"./svg.js";export*from"./reset.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isString as X}from"@symbo.ls/utils";import{getActiveConfig as Y}from"../factory.js";import{parseColorToken as Z,rgbToHSL as _,hslToRgb as k,relativeLuminance as T,contrastRatio as A,compositeOverBackdrop as S}from"../utils/index.js";import{getColor as D,resolveColorRgb as j}from"./color.js";const ee=(s,n,f={},u)=>{const r=u||Y(),{min:F=4.5,large:K=!1,scheme:N,meta:O=!1,maxIterations:V=15}=f,h=K?3:F,l=N||(r.globalTheme&&r.globalTheme!=="auto"?r.globalTheme:"light"),$=X(n)?n:String(n),g=Z(s),C=g&&!g.passthrough&&!g.cssVar?g.name:null,m=(e,t)=>O?{value:e,...t}:e;if(C){const e=r.color[`${C}Safe`];if(e){const t=`${$}@${l}`,o=e[t]!==void 0?e[t]:e[$];if(o!==void 0){const w=o&&o.rgb!==void 0?r.useVariable&&o.var?`var(${o.var})`:o.value:D(o,null,r);return m(w,{ratio:null,deviation:0,derived:!1,overridden:!0})}}}const I=D(s,l?`@${l}`:null,r),a=j(s,r,l),b=j(n,r,l);if(!a||!b)return r.verbose&&console.warn("getSafeInk: could not resolve",s,n,"\u2014 returning hue unchanged"),m(I,{ratio:null,deviation:0,derived:!1,overridden:!1,unresolved:!0});const c=S(b.rgb,b.alpha),B=S(a.rgb,a.alpha,c),v=A(B,c);if(v>=h-.02)return m(I,{ratio:v,deviation:0,derived:!1,overridden:!1});const[E,G,H]=_(a.rgb[0]/255,a.rgb[1]/255,a.rgb[2]/255),d=H*100,x=T(c)>.5,P=x?d:100-d,M=e=>{const t=x?d-e:d+e,o=Math.max(0,Math.min(100,t));return{rgb:k(E,G,o/100).map(W=>Math.max(0,Math.min(1,W))*255),L:o}},p=e=>{const{rgb:t}=M(e),o=S(t,a.alpha,c);return A(o,c)};let L=0,i=P;const y=p(i)>=h;if(y)for(let e=0;e<V;e++){const t=(L+i)/2;p(t)>=h?i=t:L=t}else L=i;const{rgb:q,L:z}=M(i),R=q.map(e=>Math.round(e)),J=p(i),Q=a.alpha<1?`rgba(${R.join(", ")}, ${a.alpha})`:`rgb(${R.join(", ")})`,U=Math.abs(z-d);return m(Q,{rgb:R,ratio:J,startRatio:v,deviation:U,derived:!0,overridden:!1,reachable:y})},ne=(s,n,f={},u)=>ee(s,n,{...f,meta:!0},u);export{ee as getSafeInk,ne as getSafeInkInfo};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{document as
|
|
1
|
+
import{document as i,window as h,isString as c,isNumber as l,isNotProduction as b}from"@symbo.ls/utils";const p=t=>{if(t==="")return[0,0,0,0];if(t.toLowerCase()==="transparent")return[0,0,0,0];if(t[0]==="#")return t.length<7&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(t.length>4?t[4]+t[4]:"")),[parseInt(t.substr(1,2),16),parseInt(t.substr(3,2),16),parseInt(t.substr(5,2),16),t.length>7?parseInt(t.substr(7,2),16)/255:1];if(t.indexOf("rgb")===-1&&i&&h){const e=i.body.appendChild(i.createElement("fictum")),r="rgb(1, 2, 3)";if(e.style.color=r,e.style.color!==r){i.body.removeChild(e);return}if(e.style.color=t,e.style.color===r||e.style.color==="")return i.body.removeChild(e),[0,0,0,0];t=h.getComputedStyle(e).color,i.body.removeChild(e)}return t.indexOf("rgb")===0?(t.indexOf("rgba")===-1&&(t=`${t}, 1`),t.match(/[\.\d]+/g).map(e=>+e)):[0,0,0,0]},E=(t,e,r=.5)=>(t=p(t),e=p(e),y(t,e,r)),A=(t,e=1)=>{const[r,s,n]=t.match(/\w\w/g).map(o=>parseInt(o,16));return`rgb(${r},${s},${n})`},w=(t,e=1)=>{const[r,s,n]=t.match(/\w\w/g).map(o=>parseInt(o,16));return[r,s,n]},F=(t,e,r)=>"#"+(1<<24|t<<16|e<<8|r).toString(16).slice(1),C=([t,e,r])=>((1<<24)+(t<<16)+(e<<8)+r).toString(16).slice(1),_=(t,e=1)=>{const[r,s,n]=t.match(/\w\w/g).map(o=>parseInt(o,16));return`rgba(${r},${s},${n},${e})`},H=(t,e,r=.5)=>{const s=[];for(let n=0;n<3;n++)s[n]=~~(t[n]+(e[n]-t[n])*r);return`rgb(${s})`},N=(t,e)=>{const[r,s,n]=e,o=Math.max(0,Math.min(100,n+parseFloat(t)));return[r,s,o]},T=(t,e,r)=>{const s=Math.max(t,e,r),n=s-Math.min(t,e,r),o=1-Math.abs(s+s-n-1),a=n&&(s==t?(e-r)/n:s==e?2+(r-t)/n:4+(t-e)/n);return[60*(a<0?a+6:a),o?n/o:0,(s+s-n)/2]},R=(t,e,r,s=e*Math.min(r,1-r),n=(o,a=(o+t/30)%12)=>r-s*Math.max(Math.min(a-3,9-a,1),-1))=>[n(0),n(8),n(4)],M=(t,e)=>{const r=parseInt(t,16);let s=(r>>16)+e;s>255?s=255:s<0&&(s=0);let n=(r>>8&255)+e;n>255?n=255:n<0&&(n=0);let o=(r&255)+e;return o>255?o=255:o<0&&(o=0),((o|n<<8|s<<16)+16777216).toString(16).slice(1)},y=(t,e,r=.5)=>{const s=[];for(let n=0;n<4;n++){const o=n===3?a=>a:Math.round;s[n]=o(t[n]+(e[n]-t[n])*r)}return`rgba(${s})`},j=(t,e)=>{const r=p(t);if(!r){b()&&console.warn(t+" color is not rgba");return}return r[3]=e,`rgba(${r})`},S=t=>t.charCodeAt(0)===45&&t.charCodeAt(1)===45,$=/(?:rgba?\(|hsla?\(|#[0-9a-fA-F]{3,8}\b)/,I=/^([a-zA-Z]\w*(?:-[a-zA-Z]\w*)*)(?:\.(\d+))?(?:([+-]\d+|=\d+))?$/,V=t=>{if(!c(t))return null;if($.test(t))return{passthrough:t};if(S(t))return{cssVar:t};const e=t.match(I);if(!e)return null;const[,r,s,n]=e,o=s!==void 0?`0.${s}`:void 0,a=n&&n[0]==="="?n.slice(1):n;return{name:r,alpha:o,tone:a}},z=t=>c(t)&&(t.includes("rgb")||t.includes("var(")||t.includes("#")),G=t=>{const e=[];let r="",s=0;for(const n of t){if(n==="("?s+=1:n===")"&&s>0&&(s-=1),n===","&&s===0){e.push(r),r="";continue}r+=n}return(r.length||!e.length)&&e.push(r),e},u=t=>(t/=255,t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)),f=t=>.2126*u(t[0])+.7152*u(t[1])+.0722*u(t[2]),X=(t,e)=>{const r=f(t)+.05,s=f(e)+.05;return r>s?r/s:s/r},Z=(t,e=1,r=[255,255,255])=>e>=1?t:t.map((s,n)=>s*e+r[n]*(1-e)),k=(t,e)=>{c(t)&&t.includes("rgb")&&(t=p(t).join(", ")),c(t)&&(t=t.split(",").map(n=>parseFloat(n.trim()))),l(e)&&(e+="");const r=C(t),s=e.slice(0,1);if(s==="-"||s==="+"){const n=M(r,parseFloat(e));return w(n).join(", ")}else{const[n,o,a]=t,[x,m]=T(n/255,o/255,a/255),g=Math.max(0,Math.min(100,parseFloat(e)))/100;return R(x,m,g).map(d=>Math.round(Math.max(0,Math.min(1,d))*255)).join(", ")}};export{$ as CSS_NATIVE_COLOR_REGEX,N as changeLightness,p as colorStringToRgbaArray,Z as compositeOverBackdrop,X as contrastRatio,M as getColorShade,k as getRgbTone,A as hexToRgb,w as hexToRgbArray,_ as hexToRgba,R as hslToRgb,S as isCSSVar,z as isResolvedColor,E as mixTwoColors,H as mixTwoRgb,y as mixTwoRgba,j as opacify,V as parseColorToken,f as relativeLuminance,C as rgbArrayToHex,T as rgbToHSL,F as rgbToHex,G as splitTopLevelCommas,u as toLinearChannel};
|