@styleframe/core 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- (function(u,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(u=typeof globalThis<"u"?globalThis:u||self,b(u.styleframe={}))})(this,(function(u){"use strict";function b(e){return typeof e=="object"&&e!==null}function h(e,r){return b(e)&&"type"in e&&e.type===r}function W(e){return h(e,"variable")}function v(e){return h(e,"reference")}function pe(e){return h(e,"selector")}function ge(e){return h(e,"at-rule")}function be(e){return h(e,"utility")}function q(e){return h(e,"modifier")}function M(e){return h(e,"css")}function Ae(e){return h(e,"theme")}function R(e){return h(e,"root")}function je(e){return h(e,"recipe")}function I(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null}function C(e){return I(e)||v(e)||M(e)||Array.isArray(e)&&e.every(C)}function L(e){return b(e)&&"children"in e&&"declarations"in e&&"variables"in e}function ve(e){return b(e)&&"id"in e&&"root"in e&&"variable"in e&&"selector"in e&&"recipe"in e&&typeof e.id=="string"&&R(e.root)}function U(e){const r=typeof e=="function"?{replacer:e}:e??{},{replacer:n=c=>c,namespace:t}=r,i=Array.isArray(t)?t:t?[t]:[];return c=>{let s=c,a;if(typeof s=="string"&&s[0]==="@"){const o=s.slice(1),f=i.find(d=>o===d||o.startsWith(`${d}.`));let y,l;f?(y=o,l=o.startsWith(`${f}.`)?o.slice(f.length+1):o):i.length>0?(y=`${i[0]}.${o}`,l=o):(y=o,l=o),a=n(l),s={type:"reference",name:y}}else if(v(s)){let o=s.name;for(const f of i)if(o.startsWith(`${f}.`)){o=o.slice(f.length+1);break}a=n(o)}else a=`[${c}]`;return{[a]:s}}}function z(e,r){return function(t,...i){return{type:"css",value:t.reduce((s,a,o)=>(s.push(a),o<i.length&&s.push(i[o]),s),[])}}}function T(e,r){return function(t,i,c){const s={type:"at-rule",identifier:t,rule:i,declarations:{},variables:[],children:[]},a=k(s,r);return typeof c=="function"?s.declarations=c(a)??{}:c&&(s.declarations=c),V(s.declarations,a),e.children.push(s),s}}function G(e,r){const n=T(e,r);return function(i,c){return n("media",i,c)}}function Y(e,r){const n=T(e,r);return function(i,c){return n("keyframes",i,c)}}function Z(e,r){return function(t,i){return W(t)?{type:"reference",name:t.name,fallback:i}:{type:"reference",name:t,fallback:i}}}function J(e,r){return function(t,i){const c={type:"selector",query:t,declarations:{},variables:[],children:[]},s=k(c,r);return typeof i=="function"?c.declarations=i(s)??{}:L(i)?(c.variables=i.variables,c.declarations=i.declarations,c.children=i.children):c.declarations=i,V(c.declarations,s),e.children.push(c),c}}function Q(e,r){return function(t,i,c={default:!1}){const s=typeof t=="string"?t:t.name,a=e.variables.find(f=>f.name===s);if(c.default&&a)return a;if(a)return a.value=i,a;const o={type:"variable",name:s,value:i};return e.variables.push(o),o}}function k(e,r){const n=Q(e),t=J(e,r),i=T(e,r),c=Y(r,r),s=G(e,r),a=Z(),o=z();return{variable:n,selector:t,keyframes:c,atRule:i,media:s,ref:a,css:o}}function V(e,r){for(const n in e)if(n.startsWith("@")){const t=e[n];if(typeof t=="object"&&t!==null&&!C(t)){const i=n.replace(/^@(\w+).*/,"$1"),c=n.replace(`@${i}`,"").trim();r.atRule(i,c,t),delete e[n]}}else if(/^[.&:]/.test(n)||/^\d+%$/.test(n)||n==="from"||n==="to"){const t=e[n];typeof t=="object"&&(r.selector(n,t),delete e[n])}for(const n in e){const t=e[n];typeof t=="string"&&t[0]==="@"&&(e[n]=r.ref(t.slice(1)))}return e}function ke(e){return e.charAt(0).toUpperCase()+e.slice(1)}function w(e){if(e instanceof Buffer)return Buffer.from(e);const r=e.constructor;return new r(e.buffer.slice(0),e.byteOffset,e.byteLength/e.BYTES_PER_ELEMENT||1)}function X(e){if(e=e||{},e.circular)return we(e);const r=new Map;if(r.set(Date,s=>new Date(s)),r.set(Map,(s,a)=>new Map(t(Array.from(s),a))),r.set(Set,(s,a)=>new Set(t(Array.from(s),a))),e.constructorHandlers)for(const s of e.constructorHandlers)r.set(s[0],s[1]);let n;return e.proto?c:i;function t(s,a){const o=Object.keys(s),f=Array.from({length:o.length});for(let y=0;y<o.length;y++){const l=o[y],d=s[l];typeof d!="object"||d===null?f[l]=d:d.constructor!==Object&&(n=r.get(d.constructor))?f[l]=n(d,a):ArrayBuffer.isView(d)?f[l]=w(d):f[l]=a(d)}return f}function i(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return t(s,i);if(s.constructor!==Object&&(n=r.get(s.constructor)))return n(s,i);const a={};for(const o in s){if(Object.hasOwnProperty.call(s,o)===!1)continue;const f=s[o];typeof f!="object"||f===null?a[o]=f:f.constructor!==Object&&(n=r.get(f.constructor))?a[o]=n(f,i):ArrayBuffer.isView(f)?a[o]=w(f):a[o]=i(f)}return a}function c(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return t(s,c);if(s.constructor!==Object&&(n=r.get(s.constructor)))return n(s,c);const a={};for(const o in s){const f=s[o];typeof f!="object"||f===null?a[o]=f:f.constructor!==Object&&(n=r.get(f.constructor))?a[o]=n(f,c):ArrayBuffer.isView(f)?a[o]=w(f):a[o]=c(f)}return a}}function we(e){const r=[],n=[],t=new Map;if(t.set(Date,o=>new Date(o)),t.set(Map,(o,f)=>new Map(c(Array.from(o),f))),t.set(Set,(o,f)=>new Set(c(Array.from(o),f))),e.constructorHandlers)for(const o of e.constructorHandlers)t.set(o[0],o[1]);let i;return e.proto?a:s;function c(o,f){const y=Object.keys(o),l=Array.from({length:y.length});for(let d=0;d<y.length;d++){const g=y[d],m=o[g];if(typeof m!="object"||m===null)l[g]=m;else if(m.constructor!==Object&&(i=t.get(m.constructor)))l[g]=i(m,f);else if(ArrayBuffer.isView(m))l[g]=w(m);else{const F=r.indexOf(m);F!==-1?l[g]=n[F]:l[g]=f(m)}}return l}function s(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,s);if(o.constructor!==Object&&(i=t.get(o.constructor)))return i(o,s);const f={};r.push(o),n.push(f);for(const y in o){if(Object.hasOwnProperty.call(o,y)===!1)continue;const l=o[y];if(typeof l!="object"||l===null)f[y]=l;else if(l.constructor!==Object&&(i=t.get(l.constructor)))f[y]=i(l,s);else if(ArrayBuffer.isView(l))f[y]=w(l);else{const d=r.indexOf(l);d!==-1?f[y]=n[d]:f[y]=s(l)}}return r.pop(),n.pop(),f}function a(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,a);if(o.constructor!==Object&&(i=t.get(o.constructor)))return i(o,a);const f={};r.push(o),n.push(f);for(const y in o){const l=o[y];if(typeof l!="object"||l===null)f[y]=l;else if(l.constructor!==Object&&(i=t.get(l.constructor)))f[y]=i(l,a);else if(ArrayBuffer.isView(l))f[y]=w(l);else{const d=r.indexOf(l);d!==-1?f[y]=n[d]:f[y]=a(l)}}return r.pop(),n.pop(),f}}const O=X();function x(e,r=8){const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let t="";for(let i=0;i<r;i++){const c=Math.floor(Math.random()*n.length);t+=n[c]}return e?`${e}${t}`:t}function Re(e,r){const n=e.variables.find(t=>t.name===r);if(!n)throw new Error(`Variable "${r}" not found`);return n}function Ve(e,r){const n=e.utilities.find(t=>t.name===r);if(!n)throw new Error(`Utility "${r}" not found`);return n}function ee(e,r){const n=e.modifiers.find(t=>t.key.includes(r));if(!n)throw new Error(`Modifier "${r}" not found`);return n}function $(e,r){if(e===r)return!0;if(typeof e!=typeof r)return!1;if(e===null||r===null)return e===r;if(typeof e!="object"||typeof r!="object")return!1;if(Array.isArray(e)&&Array.isArray(r))return e.length!==r.length?!1:e.every((n,t)=>$(n,r[t]));if("type"in e&&"type"in r){if(e.type!==r.type)return!1;if(v(e)&&v(r))return e.name===r.name&&$(e.fallback,r.fallback);if(M(e)&&M(r))return $(e.value,r.value)}return!1}const te="__licenseRequired";function Fe(e){E(e)||Object.defineProperty(e,te,{value:!0,writable:!1,configurable:!1,enumerable:!0})}function E(e){return Object.prototype.hasOwnProperty.call(e,te)}function ne(e,r){const n=[...e];for(const t of r){const i=n.find(c=>c.name===t.name);i?i.value=t.value:n.push(t)}return n}function re(e,r){const n=[...e];for(const t of r){const i=n.find(c=>c.name===t.name);i?Object.assign(i,N(i,t)):n.push(t)}return n}function N(e,r){return Object.keys(e).reduce((n,t)=>(t==="variables"?n.variables=ne(e.variables,r.variables):t==="declarations"?n.declarations={...e.declarations,...r.declarations}:t==="themes"&&R(n)&&R(e)&&R(r)?n.themes=re(e.themes,r.themes):Array.isArray(e[t])&&(n[t]=e[t].concat(r[t])),n),{...e,...r})}function Me(e,...r){return r.reduce((n,t)=>{const i={...n,root:N(n.root,t.root)};return(E(n)||E(t))&&Fe(i),i},e)}function ie(e){const r=[];function n(t,i){i.length>0&&r.push([...i].sort());for(let c=t;c<e.length;c++){const s=e[c];if(s)if(s.length===1&&s[0])n(c+1,[...i,s[0]]);else for(const a of s)n(c+1,[...i,a])}}return n(0,[]),r.sort((t,i)=>t.length!==i.length?t.length-i.length:t.join(",").localeCompare(i.join(",")))}function se(e,r,n){const t={...e,modifiers:[...n.keys()]},i=k(t,r);for(const c of n.values())c.factory({...i,declarations:O(t.declarations),variables:O(t.variables),children:O(t.children)}),V(t.declarations,i);return t}function oe(e,r){return function(t,i){const c={type:"modifier",key:Array.isArray(t)?t:[t],factory:i};return r.modifiers.push(c),c}}function ce(){return{type:"root",declarations:{},utilities:[],modifiers:[],recipes:[],variables:[],children:[],themes:[]}}function Te(e,r){const n=U({namespace:e});return t=>{if(typeof t=="string"&&t[0]==="@"){const i=t.slice(1),c=e.find(s=>i===s||i.startsWith(`${s}.`));if(c){const s=i.slice(c.length+1)||i;if(r.variables.some(a=>a.name===i))return{[s]:{type:"reference",name:i}}}else for(const s of e){const a=`${s}.${i}`;if(r.variables.some(o=>o.name===a))return{[i]:{type:"reference",name:a}}}return n(t)}return n(t)}}function fe(e,r){return function(t,i,c={}){const s={type:"utility",name:t,factory:i,values:[],autogenerate:c.autogenerate??(Array.isArray(c.namespace)?Te(c.namespace,r):U(c.namespace?{namespace:c.namespace}:void 0)),namespace:c.namespace,create:(a,o=[])=>{let f=a;if(Array.isArray(a)){f={};for(const y of a){const l=s.autogenerate(y);f={...f,...l}}}for(const[y,l]of Object.entries(f)){let d=l;if(s.namespace&&v(l))if(r.variables.some(A=>A.name===l.name))d=l;else{const A=Array.isArray(s.namespace)?s.namespace:[s.namespace];let _=!1;for(const P of A){const p=`${P}.${y}`;if(p!==l.name&&r.variables.some(j=>j.name===p)){d={type:"reference",name:p},_=!0;break}}_||(d=y)}const g=s.values.find(A=>A.key===y&&A.modifiers.length===0),m={type:"utility",name:t,value:y,declarations:{},variables:[],children:[],modifiers:[]},F=k(m,r);if(m.declarations=i({...F,value:d})??{},V(m.declarations,F),g||(s.values.push({key:y,value:d,modifiers:[]}),e.children.push(m)),o&&o.length>0){const A=o.map(p=>p.key),P=ie(A).filter(p=>!s.values.find(j=>j.key===y&&j.modifiers.length===p.length&&j.modifiers.every(S=>p.includes(S)))).reduce((p,j)=>{const S=new Map;for(const he of j){const H=o.find($e=>$e.key.includes(he));H&&q(H)&&S.set(he,H)}return s.values.push({key:y,value:d,modifiers:j}),p.push(se(m,r,S)),p},[]);e.children.push(...P)}}}};return r.utilities.push(s),s.create}}function ae(e,r){return function(t,i){const c=r.themes.find(o=>o.name===t),s=c??{type:"theme",name:t,declarations:{},variables:[],children:[]};c||r.themes.push(s);const a=k(s,r);return i&&i(a),s}}function ue(e,r){return function(t){const i={type:"recipe",...t};return i._runtime=ye(i,r),me(i,r),r.recipes.push(i),i}}function le(e,r){const n=e.autogenerate(r);return Object.keys(n)[0]??"default"}function B(e,r){const n={};for(const[t,i]of Object.entries(e))if(de(i)){const c={};for(const[s,a]of Object.entries(i)){const o=D(r,s);o?c[s]=le(o,a):console.warn(`[styleframe] Utility "${s}" not found in registry. Skipping runtime generation for this declaration.`)}n[t]=c}else if(typeof i=="boolean")n[t]=i;else{const c=D(r,t);c?n[t]=le(c,i):console.warn(`[styleframe] Utility "${t}" not found in registry. Skipping runtime generation for this declaration.`)}return n}function ye(e,r){const n={};if(e.base&&(n.base=B(e.base,r)),e.variants){const t={};for(const[i,c]of Object.entries(e.variants)){const s={};for(const[a,o]of Object.entries(c))o==null?s[a]=null:s[a]=B(o,r);t[i]=s}n.variants=t}return e.defaultVariants&&(n.defaultVariants={...e.defaultVariants}),e.compoundVariants&&(n.compoundVariants=e.compoundVariants.map(t=>({match:{...t.match},css:B(t.css,r)}))),n}function de(e){return!v(e)&&typeof e=="object"&&e!==null}function K(e,r){const n=(t,i,c)=>{let s=r.get(t);s||(s=[],r.set(t,s)),s.push({value:i,modifiers:c})};for(const[t,i]of Object.entries(e))if(de(i)){const c=t.split(":");for(const[s,a]of Object.entries(i))n(s,a,c)}else n(t,i,[])}function D(e,r){const n=e.utilities.find(i=>i.name===r);if(n)return n;const t=r.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`);return e.utilities.find(i=>i.name===t)}function me(e,r){const n=new Map;if(e.base&&K(e.base,n),e.variants)for(const i of Object.values(e.variants))for(const c of Object.values(i))K(c,n);if(e.compoundVariants)for(const i of e.compoundVariants)i.css&&K(i.css,n);const t=new Map;for(const[i,c]of n){const s=D(r,i);if(!s){console.warn(`[styleframe] Utility "${i}" not found in registry. Skipping.`);continue}for(const a of c){const o=[];for(const f of a.modifiers){if(!t.has(f))try{t.set(f,ee(r,f))}catch{console.warn(`[styleframe] Modifier "${f}" not found in registry. Skipping modifier for utility "${i}".`),t.set(f,null)}const y=t.get(f);y&&o.push(y)}s.create([a.value],o.length>0?o:void 0)}}}function Oe(e){const r=x("sf-"),n=ce(),t={...e},i=fe(n,n),c=oe(n,n),s=ue(n,n),a=ae(n,n),{variable:o,selector:f,atRule:y,keyframes:l,media:d,ref:g,css:m}=k(n,n);return{id:r,root:n,variable:o,selector:f,utility:i,modifier:c,recipe:s,theme:a,atRule:y,keyframes:l,media:d,ref:g,css:m,options:t}}u.applyModifiers=se,u.capitalizeFirst=ke,u.combineKeys=ie,u.createAtRuleFunction=T,u.createCssFunction=z,u.createDeclarationsCallbackContext=k,u.createKeyframesFunction=Y,u.createMediaFunction=G,u.createModifierFunction=oe,u.createRecipeFunction=ue,u.createRefFunction=Z,u.createRoot=ce,u.createSelectorFunction=J,u.createThemeFunction=ae,u.createUtilityFunction=fe,u.createVariableFunction=Q,u.deepClone=O,u.generateRandomId=x,u.generateRecipeRuntime=ye,u.getModifier=ee,u.getUtility=Ve,u.getVariable=Re,u.isAtRule=ge,u.isCSS=M,u.isContainer=L,u.isModifier=q,u.isObject=b,u.isPrimitiveTokenValue=I,u.isRecipe=je,u.isRef=v,u.isRoot=R,u.isSelector=pe,u.isStyleframe=ve,u.isTheme=Ae,u.isToken=h,u.isTokenEqual=$,u.isTokenValue=C,u.isUtility=be,u.isVariable=W,u.merge=Me,u.mergeContainers=N,u.mergeThemesArray=re,u.mergeVariablesArray=ne,u.parseDeclarationsBlock=V,u.processRecipeUtilities=me,u.rfdc=X,u.styleframe=Oe,u.transformUtilityKey=U,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(u,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(u=typeof globalThis<"u"?globalThis:u||self,V(u.styleframe={}))})(this,(function(u){"use strict";function V(e){return typeof e=="object"&&e!==null}function g(e,t){return V(e)&&"type"in e&&e.type===t}function U(e){return g(e,"variable")}function v(e){return g(e,"reference")}function $e(e){return g(e,"selector")}function Y(e){return g(e,"at-rule")}function Te(e){return g(e,"utility")}function Z(e){return g(e,"modifier")}function T(e){return g(e,"css")}function Se(e){return g(e,"theme")}function F(e){return g(e,"root")}function Ce(e){return g(e,"recipe")}function J(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null}function S(e){return J(e)||v(e)||T(e)||Array.isArray(e)&&e.every(S)}function Ee(e){return V(e)&&"id"in e&&"children"in e&&"declarations"in e&&"variables"in e}function Q(e){return V(e)&&"children"in e&&"declarations"in e&&"variables"in e}function x(e){return typeof e=="string"&&e.startsWith("@")}function Oe(e){return V(e)&&"id"in e&&"root"in e&&"variable"in e&&"selector"in e&&"recipe"in e&&typeof e.id=="string"&&F(e.root)}function ee(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t+e.charCodeAt(r)&4294967295;return(t>>>0).toString(16).padStart(7,"0").slice(0,7)}function K(e){const t=typeof e=="function"?{replacer:e}:e??{},{replacer:r=c=>c,namespace:n}=t,s=Array.isArray(n)?n:n?[n]:[];return c=>{let i=c,a;if(typeof i=="string"&&i[0]==="@"){const o=i.slice(1),f=s.find(y=>o===y||o.startsWith(`${y}.`));let d,l;f?(d=o,l=o.startsWith(`${f}.`)?o.slice(f.length+1):o):s.length>0?(d=`${s[0]}.${o}`,l=o):(d=o,l=o),a=r(l),i={type:"reference",name:d}}else if(v(i)){let o=i.name;for(const f of s)if(o.startsWith(`${f}.`)){o=o.slice(f.length+1);break}a=r(o)}else{const o=String(c).trim();/\s/.test(o)?a=ee(o):a=`[${o}]`}return{[a]:i}}}const _e=({name:e,value:t,modifiers:r})=>`_${[...r,e,...t==="default"?[]:[t]].filter(Boolean).join(":")}`,N=/@([\w.-]+)/g;function P(e){const t=[];let r=0,n;for(N.lastIndex=0;(n=N.exec(e))!==null;)t.push(e.slice(r,n.index)),t.push({type:"reference",name:n[1]}),r=N.lastIndex;return t.push(e.slice(r)),t}function te(e,t,r){let n=t;for(;n;){if(n.variables.some(s=>s.name===e))return!0;if(n.parentId)n=r._registry.get(n.parentId);else break}return!1}function ne(e,t,r){if(!te(e,t,r))throw new Error(`[styleframe] Variable "${e}" is not defined. Check that the variable exists before referencing it with "@${e}".`)}function C(e,t){return function(n){if(typeof n!="string"||!n.includes("@"))return n;if(x(n)&&/^@[\w.-]+$/.test(n)){const i=n.slice(1);return ne(i,e,t),{type:"reference",name:i}}const s=P(n);return s.some(i=>v(i))?{type:"css",value:s}:n}}function B(e,t){return function(n,s){const c=C(e,t),i=s!=null?c(s):s;if(U(n))return{type:"reference",name:n.name,fallback:i};if(n==null)throw new Error(`[styleframe] ref() received ${String(n)}. This usually means you're referencing a variable that doesn't exist.`);return{type:"reference",name:n,fallback:i}}}function re(e,t){const r=B(e,t);return function(s,...c){return{type:"css",value:s.reduce((a,o,f)=>{if(a.push(...P(o)),f<c.length){const d=c[f];U(d)?a.push(r(d)):Y(d)?a.push(d.rule):a.push(d)}return a},[])}}}function Ue(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ke(e){return`.${e.replace(/[[\].#()%,:/]/g,"\\$&")}`}function k(e){if(e instanceof Buffer)return Buffer.from(e);const t=e.constructor;return new t(e.buffer.slice(0),e.byteOffset,e.byteLength/e.BYTES_PER_ELEMENT||1)}function ie(e){if(e=e||{},e.circular)return Ne(e);const t=new Map;if(t.set(Date,i=>new Date(i)),t.set(Map,(i,a)=>new Map(n(Array.from(i),a))),t.set(Set,(i,a)=>new Set(n(Array.from(i),a))),e.constructorHandlers)for(const i of e.constructorHandlers)t.set(i[0],i[1]);let r;return e.proto?c:s;function n(i,a){const o=Object.keys(i),f=Array.from({length:o.length});for(let d=0;d<o.length;d++){const l=o[d],y=i[l];typeof y!="object"||y===null?f[l]=y:y.constructor!==Object&&(r=t.get(y.constructor))?f[l]=r(y,a):ArrayBuffer.isView(y)?f[l]=k(y):f[l]=a(y)}return f}function s(i){if(typeof i!="object"||i===null)return i;if(Array.isArray(i))return n(i,s);if(i.constructor!==Object&&(r=t.get(i.constructor)))return r(i,s);const a={};for(const o in i){if(Object.hasOwnProperty.call(i,o)===!1)continue;const f=i[o];typeof f!="object"||f===null?a[o]=f:f.constructor!==Object&&(r=t.get(f.constructor))?a[o]=r(f,s):ArrayBuffer.isView(f)?a[o]=k(f):a[o]=s(f)}return a}function c(i){if(typeof i!="object"||i===null)return i;if(Array.isArray(i))return n(i,c);if(i.constructor!==Object&&(r=t.get(i.constructor)))return r(i,c);const a={};for(const o in i){const f=i[o];typeof f!="object"||f===null?a[o]=f:f.constructor!==Object&&(r=t.get(f.constructor))?a[o]=r(f,c):ArrayBuffer.isView(f)?a[o]=k(f):a[o]=c(f)}return a}}function Ne(e){const t=[],r=[],n=new Map;if(n.set(Date,o=>new Date(o)),n.set(Map,(o,f)=>new Map(c(Array.from(o),f))),n.set(Set,(o,f)=>new Set(c(Array.from(o),f))),e.constructorHandlers)for(const o of e.constructorHandlers)n.set(o[0],o[1]);let s;return e.proto?a:i;function c(o,f){const d=Object.keys(o),l=Array.from({length:d.length});for(let y=0;y<d.length;y++){const m=d[y],h=o[m];if(typeof h!="object"||h===null)l[m]=h;else if(h.constructor!==Object&&(s=n.get(h.constructor)))l[m]=s(h,f);else if(ArrayBuffer.isView(h))l[m]=k(h);else{const p=t.indexOf(h);p!==-1?l[m]=r[p]:l[m]=f(h)}}return l}function i(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,i);if(o.constructor!==Object&&(s=n.get(o.constructor)))return s(o,i);const f={};t.push(o),r.push(f);for(const d in o){if(Object.hasOwnProperty.call(o,d)===!1)continue;const l=o[d];if(typeof l!="object"||l===null)f[d]=l;else if(l.constructor!==Object&&(s=n.get(l.constructor)))f[d]=s(l,i);else if(ArrayBuffer.isView(l))f[d]=k(l);else{const y=t.indexOf(l);y!==-1?f[d]=r[y]:f[d]=i(l)}}return t.pop(),r.pop(),f}function a(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,a);if(o.constructor!==Object&&(s=n.get(o.constructor)))return s(o,a);const f={};t.push(o),r.push(f);for(const d in o){const l=o[d];if(typeof l!="object"||l===null)f[d]=l;else if(l.constructor!==Object&&(s=n.get(l.constructor)))f[d]=s(l,a);else if(ArrayBuffer.isView(l))f[d]=k(l);else{const y=t.indexOf(l);y!==-1?f[d]=r[y]:f[d]=a(l)}}return t.pop(),r.pop(),f}}const M=ie();function j(e,t=8){const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let s=0;s<t;s++){const c=Math.floor(Math.random()*r.length);n+=r[c]}return e?`${e}${n}`:n}function Pe(e,t){const r=e.variables.find(n=>n.name===t);if(!r)throw new Error(`Variable "${t}" not found`);return r}function Be(e,t){const r=e.utilities.find(n=>n.name===t);if(!r)throw new Error(`Utility "${t}" not found`);return r}function se(e,t){const r=e.modifiers.find(n=>n.key.includes(t));if(!r)throw new Error(`Modifier "${t}" not found`);return r}function E(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(e===null||t===null)return e===t;if(typeof e!="object"||typeof t!="object")return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((r,n)=>E(r,t[n]));if("type"in e&&"type"in t){if(e.type!==t.type)return!1;if(v(e)&&v(t))return e.name===t.name&&E(e.fallback,t.fallback);if(T(e)&&T(t))return E(e.value,t.value)}return!1}const ce="__licenseRequired";function Ie(e){I(e)||Object.defineProperty(e,ce,{value:!0,writable:!1,configurable:!1,enumerable:!0})}function I(e){return Object.prototype.hasOwnProperty.call(e,ce)}function oe(e,t){const r=[...e];for(const n of t){const s=r.find(c=>c.name===n.name);s?s.value=n.value:r.push(n)}return r}function ae(e,t){const r=[...e];for(const n of t){const s=r.find(c=>c.name===n.name);s?Object.assign(s,D(s,n)):r.push(n)}return r}function D(e,t){return Object.keys(e).reduce((r,n)=>(n==="variables"?r.variables=oe(e.variables,t.variables):n==="declarations"?r.declarations={...e.declarations,...t.declarations}:n==="themes"&&F(r)&&F(e)&&F(t)?r.themes=ae(e.themes,t.themes):Array.isArray(e[n])&&(r[n]=e[n].concat(t[n])),r),{...e,...t})}function W(e,t){for(const r of e)"id"in r&&typeof r.id=="string"&&(t._registry.set(r.id,r),"children"in r&&W(r.children,t))}function fe(e){e._registry=new Map,e._registry.set(e.id,e),W(e.children,e);for(const t of e.themes)e._registry.set(t.id,t),W(t.children,e)}function De(e,...t){return t.reduce((r,n)=>{const s={...r,root:D(r.root,n.root)};return fe(s.root),(I(r)||I(n))&&Ie(s),s},e)}function O(e,t){return function(n,s,c){const i={type:"at-rule",id:j("ar-"),parentId:e.id,identifier:n,rule:s,declarations:{},variables:[],children:[]};t._registry.set(i.id,i);const a=R(i,t);return typeof c=="function"?i.declarations=c(a)??{}:c&&(i.declarations=c),$(i.declarations,a,i,t),e.children.push(i),i}}function ue(e,t){const r=O(e,t);return function(s,c){return r("media",s,c)}}function le(e,t){const r=O(e,t);return function(s,c){return r("keyframes",s,c)}}function de(e,t){return function(n,s){const c={type:"selector",id:j("sel-"),parentId:e.id,query:n,declarations:{},variables:[],children:[]};t._registry.set(c.id,c);const i=R(c,t);return typeof s=="function"?c.declarations=s(i)??{}:Q(s)?(c.variables=s.variables,c.declarations=s.declarations,c.children=s.children):c.declarations=s,$(c.declarations,i,c,t),e.children.push(c),c}}function ye(e,t){return function(n,s,c={default:!1}){const i=typeof n=="string"?n:n.name,o=C(e,t)(s),f=e.variables.find(l=>l.name===i);if(c.default&&f)return f;if(f)return f.value=o,f;const d={type:"variable",id:j("var-"),parentId:e.id,name:i,value:o};return e.variables.push(d),d}}function R(e,t){const r=ye(e,t),n=de(e,t),s=O(e,t),c=le(t,t),i=ue(e,t),a=B(t,t),o=re(t,t);return{variable:r,selector:n,keyframes:c,atRule:s,media:i,ref:a,css:o}}function $(e,t,r,n){for(const c in e)if(c.startsWith("@")){const i=e[c];if(typeof i=="object"&&i!==null&&!S(i)){const a=c.replace(/^@(\w+).*/,"$1"),o=c.replace(`@${a}`,"").trim();t.atRule(a,o,i),delete e[c]}}else if(/^[.&:]/.test(c)||/^\d+%$/.test(c)||c==="from"||c==="to"){const i=e[c];typeof i=="object"&&(t.selector(c,i),delete e[c])}const s=C(r,n);for(const c in e){const i=e[c];if(S(i)){const a=s(i);a!==i&&(e[c]=a)}}return e}function me(e){const t=[];function r(n,s){s.length>0&&t.push([...s].sort());for(let c=n;c<e.length;c++){const i=e[c];if(i)if(i.length===1&&i[0])r(c+1,[...s,i[0]]);else for(const a of i)r(c+1,[...s,a])}}return r(0,[]),t.sort((n,s)=>n.length!==s.length?n.length-s.length:n.join(",").localeCompare(s.join(",")))}function he(e,t,r){const n={...e,id:j("ut-"),parentId:e.parentId,declarations:{...e.declarations},variables:[...e.variables],children:[...e.children],modifiers:[...r.keys()]};t._registry.set(n.id,n);const s=R(n,t);if(r.size>0){const c=M(e.declarations);let i=!1;for(const a of r.values()){const o=a.factory({...s,declarations:M(c),variables:M(n.variables),children:M(n.children)});o&&(i||(n.declarations={},i=!0),Object.assign(n.declarations,o),$(n.declarations,s,n,t))}}return n}function ge(e,t){return function(n,s){const c={type:"modifier",key:Array.isArray(n)?n:[n],factory:s};return t.modifiers.push(c),c}}function pe(){const e={type:"root",id:j("rt-"),declarations:{},utilities:[],modifiers:[],recipes:[],variables:[],children:[],themes:[],_registry:new Map};return e._registry.set(e.id,e),e}function We(e,t){const r=K({namespace:e});return n=>{if(typeof n=="string"&&n[0]==="@"){const s=n.slice(1),c=e.find(i=>s===i||s.startsWith(`${i}.`));if(c){const i=s.slice(c.length+1)||s;if(t.variables.some(a=>a.name===s))return{[i]:{type:"reference",name:s}}}else for(const i of e){const a=`${i}.${s}`;if(t.variables.some(o=>o.name===a))return{[s]:{type:"reference",name:a}}}return r(n)}return r(n)}}function be(e,t){return function(n,s,c={}){const i=t.utilities.find(o=>o.name===n);if(i)return i.create;const a={type:"utility",name:n,factory:s,values:[],autogenerate:c.autogenerate??(Array.isArray(c.namespace)?We(c.namespace,t):K(c.namespace?{namespace:c.namespace}:void 0)),namespace:c.namespace,create:(o,f=[])=>{let d=o;if(Array.isArray(o)){d={};for(const l of o){const y=a.autogenerate(l);d={...d,...y}}}for(const[l,y]of Object.entries(d)){let m=y;if(typeof y=="string"&&y[0]==="@"){const b=y.slice(1);!Array.isArray(d)&&b in d&&(m=d[b])}if(a.namespace&&v(y))if(t.variables.some(b=>b.name===y.name))m=y;else{const b=Array.isArray(a.namespace)?a.namespace:[a.namespace];let z=!1;for(const G of b){const A=`${G}.${l}`;if(A!==y.name&&t.variables.some(w=>w.name===A)){m={type:"reference",name:A},z=!0;break}}z||(m=l)}const h=a.values.find(b=>b.key===l&&b.modifiers.length===0),p={type:"utility",id:j("ut-"),parentId:e.id,name:n,value:l,declarations:{},variables:[],children:[],modifiers:[]};t._registry.set(p.id,p);const Fe=R(p,t);if(p.declarations=s({...Fe,value:m})??{},$(p.declarations,Fe,p,t),h||(a.values.push({key:l,value:m,modifiers:[]}),e.children.push(p)),f&&f.length>0){const b=f.map(A=>A.key),G=me(b).filter(A=>!a.values.find(w=>w.key===l&&w.modifiers.length===A.length&&w.modifiers.every(_=>A.includes(_)))).reduce((A,w)=>{const _=new Map;for(const Me of w){const X=f.find(Le=>Le.key.includes(Me));X&&Z(X)&&_.set(Me,X)}return a.values.push({key:l,value:m,modifiers:w}),A.push(he(p,t,_)),A},[]);e.children.push(...G)}}}};return t.utilities.push(a),a.create}}function Ae(e,t){return function(n,s){const c=t.themes.find(o=>o.name===n),i=c??{type:"theme",id:j("th-"),parentId:t.id,name:n,declarations:{},variables:[],children:[]};c||(t._registry.set(i.id,i),t.themes.push(i));const a=R(i,t);return s&&s(a),i}}function Ve(e,t){return function(n){const s={type:"recipe",...n};return s._runtime=ve(s,t),ke(s,t),t.recipes.push(s),s}}function je(e,t){const r=e.autogenerate(t);return Object.keys(r)[0]??"default"}function H(e,t){const r={};for(const[n,s]of Object.entries(e))if(we(s)){const c={};for(const[i,a]of Object.entries(s)){const o=q(t,i);if(!o)throw new Error(`[styleframe] Utility "${i}" not found in registry. Make sure the utility is registered before using it in a recipe.`);c[i]=je(o,a)}r[Re(n)]=c}else if(typeof s=="boolean")r[n]=s;else{const c=q(t,n);if(!c)throw new Error(`[styleframe] Utility "${n}" not found in registry. Make sure the utility is registered before using it in a recipe.`);r[n]=je(c,s)}return r}function ve(e,t){const r={};if(e.base&&(r.base=H(e.base,t)),e.variants){const n={};for(const[s,c]of Object.entries(e.variants)){const i={};for(const[a,o]of Object.entries(c))o==null?i[a]=null:i[a]=H(o,t);n[s]=i}r.variants=n}return e.defaultVariants&&(r.defaultVariants={...e.defaultVariants}),e.compoundVariants&&(r.compoundVariants=e.compoundVariants.map(n=>({match:{...n.match},css:H(n.css,t)}))),r}function we(e){return!v(e)&&typeof e=="object"&&e!==null}function Re(e){return e.startsWith("&::")?e.slice(3):e.startsWith("&:")?e.slice(2):e}function L(e,t){const r=(n,s,c)=>{let i=t.get(n);i||(i=[],t.set(n,i)),i.push({value:s,modifiers:c})};for(const[n,s]of Object.entries(e))if(we(s)){const c=Re(n).split(":");for(const[i,a]of Object.entries(s))r(i,a,c)}else r(n,s,[])}function q(e,t){const r=e.utilities.find(s=>s.name===t);if(r)return r;const n=t.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);return e.utilities.find(s=>s.name===n)}function ke(e,t){const r=new Map;if(e.base&&L(e.base,r),e.variants)for(const s of Object.values(e.variants))for(const c of Object.values(s))L(c,r);if(e.compoundVariants)for(const s of e.compoundVariants)s.css&&L(s.css,r);const n=new Map;for(const[s,c]of r){const i=q(t,s);if(!i)throw new Error(`[styleframe] Utility "${s}" not found in registry. Make sure the utility is registered before using it in a recipe.`);for(const a of c){const o=[];for(const f of a.modifiers){if(!n.has(f))try{n.set(f,se(t,f))}catch{throw new Error(`[styleframe] Modifier "${f}" not found in registry. Make sure the modifier is registered before using it in a recipe.`)}const d=n.get(f);d&&o.push(d)}i.create([a.value],o.length>0?o:void 0)}}}function He(e){const t=j("sf-"),r=pe(),n={...e},s=be(r,r),c=ge(r,r),i=Ve(r,r),a=Ae(r,r),{variable:o,selector:f,atRule:d,keyframes:l,media:y,ref:m,css:h}=R(r,r);return{id:t,root:r,variable:o,selector:f,utility:s,modifier:c,recipe:i,theme:a,atRule:d,keyframes:l,media:y,ref:m,css:h,options:n}}u.applyModifiers=he,u.capitalizeFirst=Ue,u.classNameToCssSelector=Ke,u.combineKeys=me,u.createAtRuleFunction=O,u.createCssFunction=re,u.createDeclarationsCallbackContext=R,u.createKeyframesFunction=le,u.createMediaFunction=ue,u.createModifierFunction=ge,u.createPropertyValueResolver=C,u.createRecipeFunction=Ve,u.createRefFunction=B,u.createRoot=pe,u.createSelectorFunction=de,u.createThemeFunction=Ae,u.createUtilityFunction=be,u.createVariableFunction=ye,u.deepClone=M,u.defaultUtilitySelectorFn=_e,u.findVariableInScope=te,u.generateRandomId=j,u.generateRecipeRuntime=ve,u.getModifier=se,u.getUtility=Be,u.getVariable=Pe,u.hashValue=ee,u.isAtRule=Y,u.isCSS=T,u.isContainer=Ee,u.isContainerInput=Q,u.isKeyReferenceValue=x,u.isModifier=Z,u.isObject=V,u.isPrimitiveTokenValue=J,u.isRecipe=Ce,u.isRef=v,u.isRoot=F,u.isSelector=$e,u.isStyleframe=Oe,u.isTheme=Se,u.isToken=g,u.isTokenEqual=E,u.isTokenValue=S,u.isUtility=Te,u.isVariable=U,u.merge=De,u.mergeContainers=D,u.mergeThemesArray=ae,u.mergeVariablesArray=oe,u.parseAtReferences=P,u.parseDeclarationsBlock=$,u.processRecipeUtilities=ke,u.rebuildRegistry=fe,u.rfdc=ie,u.styleframe=He,u.transformUtilityKey=K,u.validateReference=ne,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@styleframe/core",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "type": "module",
5
5
  "types": "./dist/styleframe.d.ts",
6
6
  "module": "./dist/styleframe.js",