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