@tenoxui/moxie 0.4.4 → 0.5.0-alpha.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.
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Z=Object.defineProperty;var W=Object.getOwnPropertySymbols;var _=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var V=(A,t,e)=>t in A?Z(A,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):A[t]=e,S=(A,t)=>{for(var e in t||(t={}))_.call(t,e)&&V(A,e,t[e]);if(W)for(var e of W(t))j.call(t,e)&&V(A,e,t[e]);return A};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class v{constructor({property:t={},values:e={},classes:s={},alwaysUseHyphens:n=!0}={}){this.property=S({moxie:({key:r,secondValue:l})=>l?null:r},t),this.values=e,this.classes=s,this.useHyphens=n}toKebabCase(t){if(/^(webkit|moz|ms|o)[A-Z]/.test(t)){const e=t.match(/^(webkit|moz|ms|o)/);if(e){const s=e[0];return`-${s}${t.slice(s.length).replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`)}`}}return t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}escapeCSSSelector(t){return t.replace(/^(\d)/,"\\3$1 ").replace(/([#{}.:;?%&,@+*~'"!^$[\]()=>|/])/g,"\\$1")}getAllClassNames(t){if(!t)return[];const e=new Set;return Object.entries(t).forEach(([s,n])=>{n&&typeof n=="object"&&Object.keys(n).forEach(r=>{e.add(r)})}),Array.from(e)}getTypePrefixes(t=[]){const e=this.property,s=this.classes,n=Object.keys(e);if(!s)return[...n,...t].sort((a,i)=>i.length-a.length);const l=[...this.getAllClassNames(s)];return[...n,...l,...t].sort((a,i)=>i.length-a.length)}regexp(t){const e=this.getTypePrefixes(t).join("|"),s="\\[[^\\]]+\\]",n="\\([^()]*(?:\\([^()]*\\)[^()]*)*\\)",r="\\{[^{}]*(?:\\{[^{}]*\\}[^{}]*)*\\}",l="[a-zA-Z0-9_-]+|[a-zA-Z0-9_-]+(?:-(?:"+s+"|"+n+"|"+r+"))|"+s+"|"+n+"|"+r,a=`(${e}|\\[[^\\]]+\\])`,i=this.useHyphens?"(?:-)":"(?:-)?",h="(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+s+"|"+r+"|"+n+"|(?:\\$[^\\s\\/]+))",y="([a-zA-Z%]*)",c="(?:\\/(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+s+"|"+r+"|"+n+"|(?:\\$[^\\s\\/]+))([a-zA-Z%]*))?";return{prefix:l,type:a,separator:i,value:h,unit:y,secondValuePattern:c,all:"(?:("+l+"):)?"+a+i+h+y+c}}generateClassNameRegEx(t=[]){return new RegExp(this.regexp(t).all)}parse(t,e){if(Object.values(this.classes).some(o=>o==null?void 0:o[t]))return[void 0,t,"","",void 0,void 0,t];const s=this.generateClassNameRegEx(e),n=(t+"-dummy").match(s);if(!n)return null;const[,r,l,a,i,h,y]=n,c=a?a==="dummy"?"":a.replace("-dummy",""):"",f=h?h==="dummy"?"":h.replace("-dummy",""):"";return[r,l,c,i||"",f,y,t]}processValue(t,e,s){if(!t)return"";const n=r=>r.replace(/\{([^}]+)\}/g,(l,a)=>{const i=this.values,h=i!==null?typeof i[s]=="object"?i[s][a]:i[a]:void 0;return typeof h=="string"?h:l});if(typeof this.values=="object"&&this.values!==null&&(this.values[s]&&typeof this.values[s]=="object"&&this.values[s][t]||this.values[t]))return typeof this.values[s]=="object"&&this.values[s]!==null?this.values[s][t]:this.values[t];if(t.startsWith("$"))return`var(--${t.slice(1)})`;if(t.startsWith("[")&&t.endsWith("]")||t.startsWith("(")&&t.endsWith(")")){const r=t.slice(1,-1).replace(/\\\_/g,"m0x13c55").replace(/\_/g," ").replace(/m0x13c55/g,"_");return r.includes("{")?n(r):r.startsWith("--")?`var(${r})`:r}return t+(e||"")}processShorthand(t="",e="",s="",n,r="",l="",a=!0){const i=this.property[t],h=/^(?:\(|\[)([^:]+):(.+)(?:\)|\])$/;let y=null,c=e||"";const f=c.match(h);f&&(y=f[1].trim(),c=f[2].trim());let o;e.includes(y+":")?o=e.startsWith("(")?`(${c})`:`[${c}]`:o=e;const p=this.processValue(o,s,t),g=this.processValue(r,l,t);if(t.startsWith("[")&&t.endsWith("]")){const C=t.slice(1,-1).split(",").map(u=>u.trim()).map(u=>`${u?u.startsWith("--")?String(u):this.toKebabCase(String(u)):null}: ${p}`).join("; ");return{className:`${`[${t.slice(1,-1)}]${a?"-":""}${e}${s}`}`,cssRules:C,value:null,prefix:n}}if(i){if(typeof i=="object"&&"property"in i){const C=i.group&&this.values[i.group][p]?this.values[i.group][p]:s?e:p,u=typeof i.property=="function"?i.property({value:e.startsWith("[")?p:C,unit:e.startsWith("[")?"":s,secondValue:e.startsWith("[")?"":l?r:g,secondUnit:e.startsWith("[")?"":l,key:y}):i.property,m=i.value||"{0}";let b;if(typeof m=="function")b=m({value:C,unit:s,secondValue:l?r:g,secondUnit:l,key:y});else if(typeof m=="string"){const d=i.group||t,P=this.processValue(o,s,d);this.values[d]&&typeof this.values[d]=="object"&&this.values[d][o]?b=this.values[d][o]:m.includes("{")?b=this.parseValuePattern(d,m,P,"",g,""):b=p}else b=null;const x=`${t}${e?`${a&&a?"-":""}${e}${s}`:""}${r?`/${r}${l}`:""}`;return typeof i.property=="string"&&typeof m=="string"&&!m.includes("{1")&&r?null:{className:x,cssRules:u?Array.isArray(u)?u:typeof u=="string"&&(u.includes(":")||u.includes("value:"))?u.includes("value:")?u.slice(6):this.toKebabCase(String(u)):this.toKebabCase(String(u)):null,value:m===null||u===null||u.includes(":")||u.includes("value:")?null:e.startsWith("[")?p:b,prefix:n}}const $=typeof i=="function"?i({value:e.startsWith("[")?p:s?e:p,unit:e.startsWith("[")?"":s,secondValue:e.startsWith("[")?"":l?r:g,secondUnit:e.startsWith("[")?"":l,key:y}):i;return(typeof i=="string"||Array.isArray(i))&&r?null:{className:`${t}${e?(a?"-":"")+e+s:""}${r?`/${r}${l}`:""}`,cssRules:$?Array.isArray(i)?$:typeof $=="string"&&($.includes(":")||$.startsWith("value:"))?$.startsWith("value:")?$.slice(6):this.toKebabCase(String($)):this.toKebabCase(String($)):null,value:typeof $=="string"&&$.includes(":")?null:p,prefix:n}}return null}parseValuePattern(t,e,s,n,r,l){if(!e.includes("{0}")&&!e.includes("{1")&&!e.includes("||"))return e;const[a,i]=e.split("||").map(c=>c.trim()),h=this.processValue(s,n,t),y=this.processValue(r,l,t);if(e.includes("{0}")&&e.includes("{1")||e.includes("{1")){let c=a;if(s&&(c=c.replace("{0}",h)),e.includes("{1")){const f=c.match(/{1([^}]*)}/);if(e.includes("{1}"))r?c=r.startsWith("[")?y:c.replace("{1}",y):c=i;else if(f){const o=f[0],p=f[1].trim();let g=y;!g&&p.includes("|")?g=p.split("|")[1].trim():g||(g=""),c=s.startsWith("[")?h:c.replace(o,g)}}return s?c:i||a}else return s?s.startsWith("[")?h:a.replace("{0}",h):i||a}getParentClass(t){return Object.keys(this.classes).filter(e=>Object.prototype.hasOwnProperty.call(this.classes[e],t))}processCustomClass(t,e="",s="",n="",r="",l="",a=!0){if(!t)return null;const i=this.getParentClass(t);if(i.length>0){const h=i.map(f=>{const o=this.classes[f];if(!o||e&&!o[t].includes("||")||e&&!o[t].includes("|"))return"";const p=this.parseValuePattern(t,o[t]||"",e,s,r,l);return`${this.toKebabCase(String(f))}: ${p}`}).filter(Boolean).join("; "),y=t.slice(-(e+s).length),c=`${t}${e?`${a?"-":""}${e}${s}`:""}${r?`/${r}${l}`:""}`;return{className:e===y?t:c,cssRules:h,value:null,prefix:n}}return null}process(t){const e=Array.isArray(t)?t:t.split(/\s+/),s=[];return e.forEach(n=>{if(!n)return this;const[r,l]=n.split(":"),a=l||r,i=l?r:void 0,h=this.parse(n),y=h||[i,a,"",""];if(!y)return this;const[c,f,o,p,g,$]=y,C=!n.includes((f||"")+(o||"")),u=this.getParentClass(`${f}${C?"-":""}${o}`).length>0?`${f}${C?"-":""}${o}`:f,m=this.processCustomClass(u,o,p,c,g,$,C);if(m){const{className:x,cssRules:d,prefix:P}=m;if(!d||d==="null")return;s.push({className:x,cssRules:d,value:null,prefix:P,raw:[P,f,o,p,g,$]});return}const b=this.processShorthand(f,o,p,c,g,$,C);if(b){const{className:x,cssRules:d,value:P,prefix:R}=b;if(!d||d==="null")return;s.push({className:x,cssRules:d,value:P,prefix:R,raw:[c,f,o,p,g,$]})}}),s}}exports.TenoxUI=v;exports.default=v;
1
+ "use strict";var Z=Object.defineProperty;var W=Object.getOwnPropertySymbols;var _=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var x=(d,s,t)=>s in d?Z(d,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[s]=t,P=(d,s)=>{for(var t in s||(s={}))_.call(s,t)&&x(d,t,s[t]);if(W)for(var t of W(s))z.call(s,t)&&x(d,t,s[t]);return d};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class S{constructor({property:s={},values:t={},classes:e={}}={}){this.property=P({moxie:({key:i,secondValue:r})=>r?null:i},s),this.values=t,this.classes=e}toKebabCase(s){if(/^(webkit|moz|ms|o)[A-Z]/.test(s)){const t=s.match(/^(webkit|moz|ms|o)/);if(t){const e=t[0];return`-${e}${s.slice(e.length).replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}`}}return s.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}escapeCSSSelector(s){return s.replace(/^(\d)/,"\\3$1 ").replace(/([#{}.:;?%&,@+*~'"!^$[\]()=>|/])/g,"\\$1")}getAllClassNames(s){if(!s)return[];const t=new Set;return Object.entries(s).forEach(([e,i])=>{i&&typeof i=="object"&&Object.keys(i).forEach(r=>{t.add(r)})}),Array.from(t)}getTypePrefixes(s=[]){const t=this.property,e=this.classes,i=Object.keys(t);if(!e)return[...i,...s].sort((l,n)=>n.length-l.length);const c=[...this.getAllClassNames(e)];return[...i,...c,...s].sort((l,n)=>n.length-l.length)}regexp(s){const t=this.getTypePrefixes(s).join("|"),e="\\[[^\\]]+\\]",i="\\([^()]*(?:\\([^()]*\\)[^()]*)*\\)",r="\\{[^{}]*(?:\\{[^{}]*\\}[^{}]*)*\\}",c="[a-zA-Z0-9_-]+|[a-zA-Z0-9_-]+(?:-(?:"+e+"|"+i+"|"+r+"))|"+e+"|"+i+"|"+r,l=`(${t}|\\[[^\\]]+\\])`,n="(?:-)",o="(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+e+"|"+r+"|"+i+"|(?:\\$[^\\s\\/]+))",u="([a-zA-Z%]*)",a="(?:\\/(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+e+"|"+r+"|"+i+"|(?:\\$[^\\s\\/]+))([a-zA-Z%]*))?";return{prefix:c,type:l,separator:n,value:o,unit:u,secondValuePattern:a,all:"(?:("+c+"):)?"+l+n+o+u+a}}generateClassNameRegEx(s=[]){return new RegExp(this.regexp(s).all)}parse(s,t){if(Object.values(this.classes).some(f=>f==null?void 0:f[s]))return[void 0,s,"","",void 0,void 0,s];const e=this.generateClassNameRegEx(t),i=(s+"-dummy").match(e);if(!i)return null;const[,r,c,l,n,o,u]=i,a=l?l==="dummy"?"":l.replace("-dummy",""):"",$=o?o==="dummy"?"":o.replace("-dummy",""):"",h=`${r?`${r}:`:""}${c}-${a}${n}${o?`/${$}${u}`:""}`;return[r,c,a,n||"",$,u,h]}processValue(s,t,e){if(!s)return"";const i=r=>r.replace(/\{([^}]+)\}/g,(c,l)=>{const n=this.values,o=n!==null?typeof n[e]=="object"?n[e][l]:n[l]:void 0;return typeof o=="string"?o:c});if(typeof this.values=="object"&&this.values!==null&&(this.values[e]&&typeof this.values[e]=="object"&&this.values[e][s]||this.values[s]))return typeof this.values[e]=="object"&&this.values[e]!==null?this.values[e][s]:this.values[s];if(s.startsWith("$"))return`var(--${s.slice(1)})`;if(s.startsWith("[")&&s.endsWith("]")||s.startsWith("(")&&s.endsWith(")")){const r=s.slice(1,-1).replace(/\\\_/g,"m0x13c55").replace(/\_/g," ").replace(/m0x13c55/g,"_");return r.includes("{")?i(r):r.startsWith("--")?`var(${r})`:r}return s+(t||"")}processShorthand(s="",t="",e="",i,r="",c="",l){const n=this.property[s],o=/^(?:\(|\[)([^:]+):(.+)(?:\)|\])$/;let u=null,a=t||"";const $=a.match(o);if($&&(u=$[1].trim(),a=$[2].trim()),(typeof n=="string"||Array.isArray(n))&&(!t||t.includes(u+":")||r))return null;let h;t.includes(u+":")?h=t.startsWith("(")?`(${a})`:`[${a}]`:h=t;const f=this.processValue(h,e,s),y=this.processValue(r,c,s);if(s.startsWith("[")&&s.endsWith("]")){if(!t||r)return null;const p=s.slice(1,-1).split(",").map(m=>m.trim().startsWith("--")?String(m.trim()):this.toKebabCase(String(m.trim())));return{className:`${s}-${t}${e}`,cssRules:p.length===1?p[0]:p,value:f,prefix:i}}if(n){if(typeof n=="object"&&"property"in n){const m=n.group&&this.values[n.group][f]?this.values[n.group][f]:e?t:f,g=typeof n.property=="function"?n.property({value:t.startsWith("[")?f:m,unit:t.startsWith("[")?"":e,secondValue:t.startsWith("[")?"":c?r:y,secondUnit:t.startsWith("[")?"":c,key:u,raw:l}):n.property,C=n.value||"{0}";let b;if(typeof C=="function")b=C({value:m,unit:e,secondValue:c?r:y,secondUnit:c,key:u,raw:l});else if(typeof C=="string"){const A=n.group||s,R=this.processValue(h,e,A);this.values[A]&&typeof this.values[A]=="object"&&this.values[A][h]?b=this.values[A][h]:C.includes("{")?b=this.parseValuePattern(A,C,R,"",y,""):b=f}else b=null;const V=`${s}${t?`-${t}${e}`:""}${r?`/${r}${c}`:""}`;return typeof n.property=="string"&&typeof C=="string"&&(t.includes(u+":")||!C.includes("{1")&&r)?null:{className:V,cssRules:g?Array.isArray(g)?g:typeof g=="string"&&(g.includes(":")||g.includes("value:"))?g.includes("value:")?g.slice(6):this.toKebabCase(String(g)):this.toKebabCase(String(g)):null,value:C===null||g===null||g.includes(":")||g.includes("value:")?null:t.startsWith("[")?f:b,prefix:i}}const p=typeof n=="function"?n({value:t.startsWith("[")?f:e?t:f,unit:t.startsWith("[")?"":e,secondValue:t.startsWith("[")?"":c?r:y,secondUnit:t.startsWith("[")?"":c,key:u,raw:l}):n;return{className:`${s}${t?"-"+t+e:""}${r?`/${r}${c}`:""}`,cssRules:p?Array.isArray(n)?p:typeof p=="string"&&(p.includes(":")||p.startsWith("value:"))?p.startsWith("value:")?p.slice(6):this.toKebabCase(String(p)):this.toKebabCase(String(p)):null,value:typeof p=="string"&&p.includes(":")?null:f,prefix:i}}return null}parseValuePattern(s,t,e,i,r,c){if(!t.includes("{0}")&&!t.includes("{1")&&!t.includes("||"))return t;const[l,n]=t.split("||").map(a=>a.trim()),o=this.processValue(e,i,s),u=this.processValue(r,c,s);if(t.includes("{0}")&&t.includes("{1")||t.includes("{1")){let a=l;if(e&&(a=a.replace("{0}",o)),t.includes("{1")){const $=a.match(/{1([^}]*)}/);if(t.includes("{1}"))r?a=r.startsWith("[")?u:a.replace("{1}",u):a=n;else if($){const h=$[0],f=$[1].trim();let y=u;!y&&f.includes("|")?y=f.split("|")[1].trim():y||(y=""),a=e.startsWith("[")?o:a.replace(h,y)}}return e?a:n||l}else return e?e.startsWith("[")?o:l.replace("{0}",o):n||l}getParentClass(s){return Object.keys(this.classes).filter(t=>Object.prototype.hasOwnProperty.call(this.classes[t],s))}processCustomClass(s,t="",e="",i="",r="",c=""){if(!s)return null;const l=this.getParentClass(s);if(l.length>0){const n=l.map(a=>{const $=this.classes[a];if(!$||t&&!$[s].includes("||")||t&&!$[s].includes("|"))return null;const h=this.parseValuePattern(s,$[s]||"",t,e,r,c);return`${this.toKebabCase(String(a))}: ${h}`}).filter(Boolean).join("; "),o=s.slice(-(t+e).length),u=`${s}${t?`-${t}${e}`:""}${r?`/${r}${c}`:""}`;return{className:t===o?s:u,cssRules:n,value:null,prefix:i}}return null}process(s){try{const t=Array.isArray(s)?s:s.split(/\s+/),e=[];for(const i of t)try{if(!i)continue;const r=this.parse(i);if(!r)continue;const[c,l,n,o,u,a]=r;if(!l)continue;const $=this.getParentClass(`${l}-${n}`).length>0?`${l}-${n}`:l;try{const h=this.processCustomClass($,n,o,c,u,a);if(h){const{className:f,cssRules:y,prefix:p}=h;if(!y||y==="null")continue;e.push({className:f,cssRules:y,value:null,prefix:p,raw:r});continue}}catch(h){console.warn(`Error processing custom class "${i}":`,h)}try{const h=this.processShorthand(l,n,o,c,u,a,r);if(h){const{className:f,cssRules:y,value:p,prefix:m}=h;if(!y||y==="null")continue;e.push({className:f,cssRules:y,value:p,prefix:m,raw:r})}}catch(h){console.warn(`Error processing shorthand "${i}":`,h)}}catch(r){console.warn(`Failed to process class \`${i}\`:`,r)}return e}catch(t){return console.error("Critical error in process method:",t),[]}}}exports.TenoxUI=S;exports.default=S;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import type { Config, Parsed, ProcessedStyle } from './types';
1
+ import type { Config, Parsed, ProcessedStyle, Results } from './types';
2
2
  export * from './types';
3
3
  export declare class TenoxUI {
4
4
  private property;
5
5
  private values;
6
6
  private classes;
7
- private useHyphens;
8
- constructor({ property, values, classes, alwaysUseHyphens }?: Config);
7
+ constructor({ property, values, classes }?: Config);
9
8
  toKebabCase(str: string): string;
10
9
  escapeCSSSelector(str: string): string;
11
10
  private getAllClassNames;
@@ -22,10 +21,10 @@ export declare class TenoxUI {
22
21
  private generateClassNameRegEx;
23
22
  parse(className: string, safelist?: string[]): Parsed;
24
23
  processValue(value: string, unit: string, group: string): string;
25
- processShorthand(type: string | undefined, value: string | undefined, unit: string | undefined, prefix: string | undefined, secondValue?: string | undefined, secondUnit?: string | undefined, isHyphen?: boolean): ProcessedStyle | null;
24
+ processShorthand(type: string | undefined, value: string | undefined, unit: string | undefined, prefix: string | undefined, secondValue?: string | undefined, secondUnit?: string | undefined, raw?: Parsed): ProcessedStyle | null;
26
25
  private parseValuePattern;
27
26
  private getParentClass;
28
- processCustomClass(className: string | undefined, value?: string | undefined, unit?: string | undefined, prefix?: string | undefined, secValue?: string | undefined, secUnit?: string | undefined, isHyphen?: boolean): ProcessedStyle | null;
29
- process(classNames: string | string[]): ProcessedStyle[];
27
+ processCustomClass(className: string | undefined, value?: string | undefined, unit?: string | undefined, prefix?: string | undefined, secValue?: string | undefined, secUnit?: string | undefined): ProcessedStyle | null;
28
+ process(classNames: string | string[]): Results[];
30
29
  }
31
30
  export default TenoxUI;
package/dist/index.es.js CHANGED
@@ -1,268 +1,327 @@
1
1
  var R = Object.defineProperty;
2
2
  var W = Object.getOwnPropertySymbols;
3
3
  var Z = Object.prototype.hasOwnProperty, z = Object.prototype.propertyIsEnumerable;
4
- var V = (x, t, s) => t in x ? R(x, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : x[t] = s, S = (x, t) => {
5
- for (var s in t || (t = {}))
6
- Z.call(t, s) && V(x, s, t[s]);
4
+ var x = (m, s, t) => s in m ? R(m, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : m[s] = t, P = (m, s) => {
5
+ for (var t in s || (s = {}))
6
+ Z.call(s, t) && x(m, t, s[t]);
7
7
  if (W)
8
- for (var s of W(t))
9
- z.call(t, s) && V(x, s, t[s]);
10
- return x;
8
+ for (var t of W(s))
9
+ z.call(s, t) && x(m, t, s[t]);
10
+ return m;
11
11
  };
12
- class _ {
13
- constructor({ property: t = {}, values: s = {}, classes: e = {}, alwaysUseHyphens: n = !0 } = {}) {
14
- this.property = S({
12
+ class w {
13
+ constructor({ property: s = {}, values: t = {}, classes: e = {} } = {}) {
14
+ this.property = P({
15
15
  // use moxie-* to access all properties and variables
16
16
  // e.g. `moxie-(color:red)` => `color: red`, `moxie-(--my-var:20px_1rem)` => `--my-var: 20px 1rem`
17
- moxie: ({ key: r, secondValue: l }) => l ? null : r
18
- }, t), this.values = s, this.classes = e, this.useHyphens = n;
17
+ moxie: ({ key: i, secondValue: r }) => r ? null : i
18
+ }, s), this.values = t, this.classes = e;
19
19
  }
20
- toKebabCase(t) {
21
- if (/^(webkit|moz|ms|o)[A-Z]/.test(t)) {
22
- const s = t.match(/^(webkit|moz|ms|o)/);
23
- if (s) {
24
- const e = s[0];
25
- return `-${e}${t.slice(e.length).replace(/[A-Z]/g, (n) => `-${n.toLowerCase()}`)}`;
20
+ toKebabCase(s) {
21
+ if (/^(webkit|moz|ms|o)[A-Z]/.test(s)) {
22
+ const t = s.match(/^(webkit|moz|ms|o)/);
23
+ if (t) {
24
+ const e = t[0];
25
+ return `-${e}${s.slice(e.length).replace(/[A-Z]/g, (i) => `-${i.toLowerCase()}`)}`;
26
26
  }
27
27
  }
28
- return t.replace(/[A-Z]/g, (s) => `-${s.toLowerCase()}`);
28
+ return s.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
29
29
  }
30
- escapeCSSSelector(t) {
31
- return t.replace(/^(\d)/, "\\3$1 ").replace(/([#{}.:;?%&,@+*~'"!^$[\]()=>|/])/g, "\\$1");
30
+ escapeCSSSelector(s) {
31
+ return s.replace(/^(\d)/, "\\3$1 ").replace(/([#{}.:;?%&,@+*~'"!^$[\]()=>|/])/g, "\\$1");
32
32
  }
33
- getAllClassNames(t) {
34
- if (!t) return [];
35
- const s = /* @__PURE__ */ new Set();
36
- return Object.entries(t).forEach(([e, n]) => {
37
- n && typeof n == "object" && Object.keys(n).forEach((r) => {
38
- s.add(r);
33
+ getAllClassNames(s) {
34
+ if (!s) return [];
35
+ const t = /* @__PURE__ */ new Set();
36
+ return Object.entries(s).forEach(([e, i]) => {
37
+ i && typeof i == "object" && Object.keys(i).forEach((r) => {
38
+ t.add(r);
39
39
  });
40
- }), Array.from(s);
40
+ }), Array.from(t);
41
41
  }
42
- getTypePrefixes(t = []) {
43
- const s = this.property, e = this.classes, n = Object.keys(s);
42
+ getTypePrefixes(s = []) {
43
+ const t = this.property, e = this.classes, i = Object.keys(t);
44
44
  if (!e)
45
- return [...n, ...t].sort((a, i) => i.length - a.length);
46
- const l = [...this.getAllClassNames(e)];
47
- return [...n, ...l, ...t].sort((a, i) => i.length - a.length);
45
+ return [...i, ...s].sort((l, n) => n.length - l.length);
46
+ const c = [...this.getAllClassNames(e)];
47
+ return [...i, ...c, ...s].sort((l, n) => n.length - l.length);
48
48
  }
49
- regexp(t) {
50
- const s = this.getTypePrefixes(t).join("|"), e = "\\[[^\\]]+\\]", n = "\\([^()]*(?:\\([^()]*\\)[^()]*)*\\)", r = "\\{[^{}]*(?:\\{[^{}]*\\}[^{}]*)*\\}", l = (
49
+ regexp(s) {
50
+ const t = this.getTypePrefixes(s).join("|"), e = "\\[[^\\]]+\\]", i = "\\([^()]*(?:\\([^()]*\\)[^()]*)*\\)", r = "\\{[^{}]*(?:\\{[^{}]*\\}[^{}]*)*\\}", c = (
51
51
  // Simple prefix (hover, md, focus, etc.)
52
- "[a-zA-Z0-9_-]+|[a-zA-Z0-9_-]+(?:-(?:" + e + "|" + n + "|" + r + "))|" + // Direct bracket, parenthesis, or brace content
53
- e + "|" + n + "|" + r
54
- ), a = `(${s}|\\[[^\\]]+\\])`, i = this.useHyphens ? "(?:-)" : "(?:-)?", h = "(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|" + // Hex colors
52
+ "[a-zA-Z0-9_-]+|[a-zA-Z0-9_-]+(?:-(?:" + e + "|" + i + "|" + r + "))|" + // Direct bracket, parenthesis, or brace content
53
+ e + "|" + i + "|" + r
54
+ ), l = `(${t}|\\[[^\\]]+\\])`, n = "(?:-)", o = "(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|" + // Hex colors
55
55
  e + "|" + // Bracket content
56
56
  r + "|" + // Curly brace content
57
- n + "|(?:\\$[^\\s\\/]+))", y = "([a-zA-Z%]*)", c = "(?:\\/(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|" + e + "|" + r + "|" + n + "|(?:\\$[^\\s\\/]+))([a-zA-Z%]*))?";
57
+ i + "|(?:\\$[^\\s\\/]+))", u = "([a-zA-Z%]*)", a = "(?:\\/(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|" + e + "|" + r + "|" + i + "|(?:\\$[^\\s\\/]+))([a-zA-Z%]*))?";
58
58
  return {
59
- prefix: l,
60
- type: a,
61
- separator: i,
62
- value: h,
63
- unit: y,
64
- secondValuePattern: c,
65
- all: "(?:(" + l + "):)?" + a + i + h + y + c
59
+ prefix: c,
60
+ type: l,
61
+ separator: n,
62
+ value: o,
63
+ unit: u,
64
+ secondValuePattern: a,
65
+ all: "(?:(" + c + "):)?" + l + n + o + u + a
66
66
  };
67
67
  }
68
- generateClassNameRegEx(t = []) {
69
- return new RegExp(this.regexp(t).all);
68
+ generateClassNameRegEx(s = []) {
69
+ return new RegExp(this.regexp(s).all);
70
70
  }
71
- parse(t, s) {
72
- if (Object.values(this.classes).some((o) => o == null ? void 0 : o[t]))
73
- return [void 0, t, "", "", void 0, void 0, t];
74
- const e = this.generateClassNameRegEx(s), n = (t + "-dummy").match(e);
75
- if (!n) return null;
76
- const [, r, l, a, i, h, y] = n, c = a ? a === "dummy" ? "" : a.replace("-dummy", "") : "", f = h ? h === "dummy" ? "" : h.replace("-dummy", "") : "";
77
- return [r, l, c, i || "", f, y, t];
71
+ parse(s, t) {
72
+ if (Object.values(this.classes).some((f) => f == null ? void 0 : f[s]))
73
+ return [void 0, s, "", "", void 0, void 0, s];
74
+ const e = this.generateClassNameRegEx(t), i = (s + "-dummy").match(e);
75
+ if (!i) return null;
76
+ const [, r, c, l, n, o, u] = i, a = l ? l === "dummy" ? "" : l.replace("-dummy", "") : "", $ = o ? o === "dummy" ? "" : o.replace("-dummy", "") : "", h = `${r ? `${r}:` : ""}${c}-${a}${n}${o ? `/${$}${u}` : ""}`;
77
+ return [r, c, a, n || "", $, u, h];
78
78
  }
79
79
  // unique value parser
80
- processValue(t, s, e) {
81
- if (!t) return "";
82
- const n = (r) => r.replace(/\{([^}]+)\}/g, (l, a) => {
83
- const i = this.values, h = i !== null ? typeof i[e] == "object" ? i[e][a] : i[a] : void 0;
84
- return typeof h == "string" ? h : l;
80
+ processValue(s, t, e) {
81
+ if (!s) return "";
82
+ const i = (r) => r.replace(/\{([^}]+)\}/g, (c, l) => {
83
+ const n = this.values, o = n !== null ? typeof n[e] == "object" ? n[e][l] : n[l] : void 0;
84
+ return typeof o == "string" ? o : c;
85
85
  });
86
- if (typeof this.values == "object" && this.values !== null && (this.values[e] && typeof this.values[e] == "object" && this.values[e][t] || this.values[t]))
87
- return typeof this.values[e] == "object" && this.values[e] !== null ? this.values[e][t] : this.values[t];
88
- if (t.startsWith("$"))
89
- return `var(--${t.slice(1)})`;
90
- if (t.startsWith("[") && t.endsWith("]") || t.startsWith("(") && t.endsWith(")")) {
91
- const r = t.slice(1, -1).replace(/\\\_/g, "m0x13c55").replace(/\_/g, " ").replace(/m0x13c55/g, "_");
92
- return r.includes("{") ? n(r) : r.startsWith("--") ? `var(${r})` : r;
86
+ if (typeof this.values == "object" && this.values !== null && (this.values[e] && typeof this.values[e] == "object" && this.values[e][s] || this.values[s]))
87
+ return typeof this.values[e] == "object" && this.values[e] !== null ? this.values[e][s] : this.values[s];
88
+ if (s.startsWith("$"))
89
+ return `var(--${s.slice(1)})`;
90
+ if (s.startsWith("[") && s.endsWith("]") || s.startsWith("(") && s.endsWith(")")) {
91
+ const r = s.slice(1, -1).replace(/\\\_/g, "m0x13c55").replace(/\_/g, " ").replace(/m0x13c55/g, "_");
92
+ return r.includes("{") ? i(r) : r.startsWith("--") ? `var(${r})` : r;
93
93
  }
94
- return t + (s || "");
94
+ return s + (t || "");
95
95
  }
96
- processShorthand(t = "", s = "", e = "", n, r = "", l = "", a = !0) {
97
- const i = this.property[t], h = /^(?:\(|\[)([^:]+):(.+)(?:\)|\])$/;
98
- let y = null, c = s || "";
99
- const f = c.match(h);
100
- f && (y = f[1].trim(), c = f[2].trim());
101
- let o;
102
- s.includes(y + ":") ? o = s.startsWith("(") ? `(${c})` : `[${c}]` : o = s;
103
- const p = this.processValue(o, e, t), g = this.processValue(r, l, t);
104
- if (t.startsWith("[") && t.endsWith("]")) {
105
- const C = t.slice(1, -1).split(",").map((u) => u.trim()).map((u) => `${u ? u.startsWith("--") ? String(u) : this.toKebabCase(String(u)) : null}: ${p}`).join("; ");
96
+ processShorthand(s = "", t = "", e = "", i, r = "", c = "", l) {
97
+ const n = this.property[s], o = /^(?:\(|\[)([^:]+):(.+)(?:\)|\])$/;
98
+ let u = null, a = t || "";
99
+ const $ = a.match(o);
100
+ if ($ && (u = $[1].trim(), a = $[2].trim()), (typeof n == "string" || Array.isArray(n)) && (!t || t.includes(u + ":") || r))
101
+ return null;
102
+ let h;
103
+ t.includes(u + ":") ? h = t.startsWith("(") ? `(${a})` : `[${a}]` : h = t;
104
+ const f = this.processValue(h, e, s), y = this.processValue(r, c, s);
105
+ if (s.startsWith("[") && s.endsWith("]")) {
106
+ if (!t || r) return null;
107
+ const p = s.slice(1, -1).split(",").map(
108
+ (d) => d.trim().startsWith("--") ? String(d.trim()) : this.toKebabCase(String(d.trim()))
109
+ );
106
110
  return {
107
- className: `${`[${t.slice(1, -1)}]${a ? "-" : ""}${s}${e}`}`,
108
- cssRules: C,
109
- // return css rules directly
110
- value: null,
111
- // and set value to null to prevent value duplication
112
- prefix: n
111
+ className: `${s}-${t}${e}`,
112
+ cssRules: p.length === 1 ? p[0] : p,
113
+ value: f,
114
+ prefix: i
113
115
  };
114
116
  }
115
- if (i) {
116
- if (typeof i == "object" && "property" in i) {
117
- const C = i.group && this.values[i.group][p] ? this.values[i.group][p] : e ? s : p, u = typeof i.property == "function" ? i.property({
118
- value: s.startsWith("[") ? p : C,
119
- unit: s.startsWith("[") ? "" : e,
120
- secondValue: s.startsWith("[") ? "" : l ? r : g,
121
- secondUnit: s.startsWith("[") ? "" : l,
122
- key: y
123
- }) : i.property, m = i.value || "{0}";
117
+ if (n) {
118
+ if (typeof n == "object" && "property" in n) {
119
+ const d = n.group && this.values[n.group][f] ? this.values[n.group][f] : e ? t : f, g = (
120
+ // handle `properties.property` function
121
+ typeof n.property == "function" ? n.property({
122
+ value: t.startsWith("[") ? f : d,
123
+ unit: t.startsWith("[") ? "" : e,
124
+ secondValue: t.startsWith("[") ? "" : c ? r : y,
125
+ secondUnit: t.startsWith("[") ? "" : c,
126
+ key: u,
127
+ raw: l
128
+ }) : (
129
+ // defaulting to string property
130
+ // e.g. { property: { p: { property: 'padding', value: '{0} {1}' } }
131
+ // the `p` is the type or the shorthand for `padding` property -
132
+ // and has support for second value
133
+ n.property
134
+ )
135
+ ), C = n.value || "{0}";
124
136
  let A;
125
- if (typeof m == "function")
126
- A = m({
127
- value: C,
137
+ if (typeof C == "function")
138
+ A = C({
139
+ value: d,
128
140
  unit: e,
129
- secondValue: l ? r : g,
130
- secondUnit: l,
131
- key: y
141
+ secondValue: c ? r : y,
142
+ secondUnit: c,
143
+ key: u,
144
+ raw: l
132
145
  });
133
- else if (typeof m == "string") {
134
- const d = i.group || t, P = this.processValue(o, e, d);
135
- this.values[d] && typeof this.values[d] == "object" && this.values[d][o] ? A = this.values[d][o] : m.includes("{") ? A = this.parseValuePattern(
136
- d,
137
- m,
138
- P,
146
+ else if (typeof C == "string") {
147
+ const b = n.group || s, S = this.processValue(h, e, b);
148
+ this.values[b] && typeof this.values[b] == "object" && this.values[b][h] ? A = this.values[b][h] : C.includes("{") ? A = this.parseValuePattern(
149
+ b,
150
+ C,
151
+ S,
139
152
  "",
140
- g,
153
+ y,
141
154
  ""
142
- ) : A = p;
155
+ ) : A = f;
143
156
  } else A = null;
144
- const b = `${t}${s ? `${a && a ? "-" : ""}${s}${e}` : ""}${r ? `/${r}${l}` : ""}`;
145
- return typeof i.property == "string" && typeof m == "string" && !m.includes("{1") && r ? null : {
146
- className: b,
147
- cssRules: u ? Array.isArray(u) ? u : typeof u == "string" && (u.includes(":") || u.includes("value:")) ? u.includes("value:") ? u.slice(6) : this.toKebabCase(String(u)) : this.toKebabCase(String(u)) : null,
148
- value: m === null || u === null || u.includes(":") || u.includes("value:") ? null : s.startsWith("[") ? p : A,
149
- prefix: n
157
+ const V = `${s}${t ? `-${t}${e}` : ""}${r ? `/${r}${c}` : ""}`;
158
+ return typeof n.property == "string" && typeof C == "string" && (t.includes(u + ":") || !C.includes("{1") && r) ? null : {
159
+ className: V,
160
+ cssRules: (
161
+ // if not property, or when `properties.property` as function return null
162
+ g ? Array.isArray(g) ? g : (
163
+ // is direct CSS rules
164
+ typeof g == "string" && (g.includes(":") || g.includes("value:")) ? g.includes("value:") ? g.slice(6) : this.toKebabCase(String(g)) : (
165
+ // basic string property
166
+ this.toKebabCase(String(g))
167
+ )
168
+ ) : null
169
+ ),
170
+ value: C === null || g === null || g.includes(":") || g.includes("value:") ? null : t.startsWith("[") ? f : A,
171
+ prefix: i
150
172
  };
151
173
  }
152
- const $ = typeof i == "function" ? i({
153
- value: s.startsWith("[") ? p : e ? s : p,
154
- unit: s.startsWith("[") ? "" : e,
155
- secondValue: s.startsWith("[") ? "" : l ? r : g,
156
- secondUnit: s.startsWith("[") ? "" : l,
157
- key: y
158
- }) : i;
159
- return (typeof i == "string" || Array.isArray(i)) && r ? null : {
160
- className: `${t}${s ? (a ? "-" : "") + s + e : ""}${r ? `/${r}${l}` : ""}`,
161
- cssRules: $ ? Array.isArray(i) ? $ : typeof $ == "string" && ($.includes(":") || $.startsWith("value:")) ? $.startsWith("value:") ? $.slice(6) : this.toKebabCase(String($)) : this.toKebabCase(String($)) : null,
162
- value: typeof $ == "string" && $.includes(":") ? null : p,
163
- prefix: n
174
+ const p = (
175
+ // handle `properties` as function
176
+ // e.g. m: ({ value, unit }) => `margin: ${value}${unit || 'px'}`
177
+ // m-4 => margin: 4px
178
+ // m-4rem => margin: 4rem
179
+ typeof n == "function" ? n({
180
+ value: t.startsWith("[") ? f : e ? t : f,
181
+ unit: t.startsWith("[") ? "" : e,
182
+ secondValue: t.startsWith("[") ? "" : c ? r : y,
183
+ secondUnit: t.startsWith("[") ? "" : c,
184
+ key: u,
185
+ raw: l
186
+ }) : (
187
+ // e.g. { property: { bg: 'background' } }
188
+ // the `bg` is the type or the shorthand for `background` property
189
+ n
190
+ )
191
+ );
192
+ return {
193
+ className: `${s}${t ? "-" + t + e : ""}${r ? `/${r}${c}` : ""}`,
194
+ cssRules: p ? Array.isArray(n) ? p : typeof p == "string" && (p.includes(":") || p.startsWith("value:")) ? p.startsWith("value:") ? p.slice(6) : this.toKebabCase(String(p)) : this.toKebabCase(String(p)) : null,
195
+ value: typeof p == "string" && p.includes(":") ? null : f,
196
+ prefix: i
164
197
  };
165
198
  }
166
199
  return null;
167
200
  }
168
- parseValuePattern(t, s, e, n, r, l) {
169
- if (!s.includes("{0}") && !s.includes("{1") && !s.includes("||"))
170
- return s;
171
- const [a, i] = s.split("||").map((c) => c.trim()), h = this.processValue(e, n, t), y = this.processValue(r, l, t);
172
- if (s.includes("{0}") && s.includes("{1") || s.includes("{1")) {
173
- let c = a;
174
- if (e && (c = c.replace("{0}", h)), s.includes("{1")) {
175
- const f = c.match(/{1([^}]*)}/);
176
- if (s.includes("{1}"))
177
- r ? c = r.startsWith("[") ? y : c.replace("{1}", y) : c = i;
178
- else if (f) {
179
- const o = f[0], p = f[1].trim();
180
- let g = y;
181
- !g && p.includes("|") ? g = p.split("|")[1].trim() : g || (g = ""), c = e.startsWith("[") ? h : c.replace(o, g);
201
+ parseValuePattern(s, t, e, i, r, c) {
202
+ if (!t.includes("{0}") && !t.includes("{1") && !t.includes("||"))
203
+ return t;
204
+ const [l, n] = t.split("||").map((a) => a.trim()), o = this.processValue(e, i, s), u = this.processValue(r, c, s);
205
+ if (t.includes("{0}") && t.includes("{1") || t.includes("{1")) {
206
+ let a = l;
207
+ if (e && (a = a.replace("{0}", o)), t.includes("{1")) {
208
+ const $ = a.match(/{1([^}]*)}/);
209
+ if (t.includes("{1}"))
210
+ r ? a = r.startsWith("[") ? u : a.replace("{1}", u) : a = n;
211
+ else if ($) {
212
+ const h = $[0], f = $[1].trim();
213
+ let y = u;
214
+ !y && f.includes("|") ? y = f.split("|")[1].trim() : y || (y = ""), a = e.startsWith("[") ? o : a.replace(h, y);
182
215
  }
183
216
  }
184
- return e ? c : i || a;
217
+ return e ? a : n || l;
185
218
  } else
186
- return e ? e.startsWith("[") ? h : a.replace("{0}", h) : i || a;
219
+ return e ? e.startsWith("[") ? o : l.replace("{0}", o) : n || l;
187
220
  }
188
- getParentClass(t) {
221
+ getParentClass(s) {
189
222
  return Object.keys(this.classes).filter(
190
- (s) => Object.prototype.hasOwnProperty.call(
191
- this.classes[s],
192
- t
223
+ (t) => Object.prototype.hasOwnProperty.call(
224
+ this.classes[t],
225
+ s
193
226
  )
194
227
  );
195
228
  }
196
- processCustomClass(t, s = "", e = "", n = "", r = "", l = "", a = !0) {
197
- if (!t) return null;
198
- const i = this.getParentClass(t);
199
- if (i.length > 0) {
200
- const h = i.map((f) => {
201
- const o = this.classes[f];
202
- if (!o || s && !o[t].includes("||") || s && !o[t].includes("|"))
203
- return "";
204
- const p = this.parseValuePattern(
205
- t,
206
- o[t] || "",
229
+ processCustomClass(s, t = "", e = "", i = "", r = "", c = "") {
230
+ if (!s) return null;
231
+ const l = this.getParentClass(s);
232
+ if (l.length > 0) {
233
+ const n = l.map((a) => {
234
+ const $ = this.classes[a];
235
+ if (!$ || t && !$[s].includes("||") || t && !$[s].includes("|"))
236
+ return null;
237
+ const h = this.parseValuePattern(
207
238
  s,
239
+ $[s] || "",
240
+ t,
208
241
  e,
209
242
  r,
210
- l
243
+ c
211
244
  );
212
- return `${this.toKebabCase(String(f))}: ${p}`;
213
- }).filter(Boolean).join("; "), y = t.slice(-(s + e).length), c = `${t}${s ? `${a ? "-" : ""}${s}${e}` : ""}${r ? `/${r}${l}` : ""}`;
245
+ return `${this.toKebabCase(String(a))}: ${h}`;
246
+ }).filter(Boolean).join("; "), o = s.slice(-(t + e).length), u = `${s}${t ? `-${t}${e}` : ""}${r ? `/${r}${c}` : ""}`;
214
247
  return {
215
- className: s === y ? t : c,
216
- cssRules: h,
248
+ className: t === o ? s : u,
249
+ cssRules: n,
217
250
  value: null,
218
- prefix: n
251
+ prefix: i
219
252
  };
220
253
  }
221
254
  return null;
222
255
  }
223
- process(t) {
224
- const s = Array.isArray(t) ? t : t.split(/\s+/), e = [];
225
- return s.forEach((n) => {
226
- if (!n) return this;
227
- const [r, l] = n.split(":"), a = l || r, i = l ? r : void 0, h = this.parse(n), y = h || [i, a, "", ""];
228
- if (!y) return this;
229
- const [c, f, o, p, g, $] = y, C = !n.includes((f || "") + (o || "")), u = this.getParentClass(`${f}${C ? "-" : ""}${o}`).length > 0 ? `${f}${C ? "-" : ""}${o}` : f, m = this.processCustomClass(
230
- u,
231
- o,
232
- p,
233
- c,
234
- g,
235
- $,
236
- C
237
- );
238
- if (m) {
239
- const { className: b, cssRules: d, prefix: P } = m;
240
- if (!d || d === "null") return;
241
- e.push({
242
- className: b,
243
- cssRules: d,
244
- value: null,
245
- prefix: P,
246
- raw: [P, f, o, p, g, $]
247
- });
248
- return;
249
- }
250
- const A = this.processShorthand(f, o, p, c, g, $, C);
251
- if (A) {
252
- const { className: b, cssRules: d, value: P, prefix: v } = A;
253
- if (!d || d === "null") return;
254
- e.push({
255
- className: b,
256
- cssRules: d,
257
- value: P,
258
- prefix: v,
259
- raw: [c, f, o, p, g, $]
260
- });
261
- }
262
- }), e;
256
+ process(s) {
257
+ try {
258
+ const t = Array.isArray(s) ? s : s.split(/\s+/), e = [];
259
+ for (const i of t)
260
+ try {
261
+ if (!i) continue;
262
+ const r = this.parse(i);
263
+ if (!r) continue;
264
+ const [c, l, n, o, u, a] = r;
265
+ if (!l) continue;
266
+ const $ = this.getParentClass(`${l}-${n}`).length > 0 ? `${l}-${n}` : l;
267
+ try {
268
+ const h = this.processCustomClass(
269
+ $,
270
+ n,
271
+ o,
272
+ c,
273
+ u,
274
+ a
275
+ );
276
+ if (h) {
277
+ const { className: f, cssRules: y, prefix: p } = h;
278
+ if (!y || y === "null") continue;
279
+ e.push({
280
+ className: f,
281
+ cssRules: y,
282
+ value: null,
283
+ prefix: p,
284
+ raw: r
285
+ });
286
+ continue;
287
+ }
288
+ } catch (h) {
289
+ console.warn(`Error processing custom class "${i}":`, h);
290
+ }
291
+ try {
292
+ const h = this.processShorthand(
293
+ l,
294
+ n,
295
+ o,
296
+ c,
297
+ u,
298
+ a,
299
+ r
300
+ );
301
+ if (h) {
302
+ const { className: f, cssRules: y, value: p, prefix: d } = h;
303
+ if (!y || y === "null") continue;
304
+ e.push({
305
+ className: f,
306
+ cssRules: y,
307
+ value: p,
308
+ prefix: d,
309
+ raw: r
310
+ });
311
+ }
312
+ } catch (h) {
313
+ console.warn(`Error processing shorthand "${i}":`, h);
314
+ }
315
+ } catch (r) {
316
+ console.warn(`Failed to process class \`${i}\`:`, r);
317
+ }
318
+ return e;
319
+ } catch (t) {
320
+ return console.error("Critical error in process method:", t), [];
321
+ }
263
322
  }
264
323
  }
265
324
  export {
266
- _ as TenoxUI,
267
- _ as default
325
+ w as TenoxUI,
326
+ w as default
268
327
  };
@@ -1 +1 @@
1
- var __tenoxui_moxie__=function(C){"use strict";var Z=Object.defineProperty;var V=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var v=(C,m,A)=>m in C?Z(C,m,{enumerable:!0,configurable:!0,writable:!0,value:A}):C[m]=A,S=(C,m)=>{for(var A in m||(m={}))j.call(m,A)&&v(C,A,m[A]);if(V)for(var A of V(m))z.call(m,A)&&v(C,A,m[A]);return C};class m{constructor({property:t={},values:e={},classes:s={},alwaysUseHyphens:n=!0}={}){this.property=S({moxie:({key:r,secondValue:l})=>l?null:r},t),this.values=e,this.classes=s,this.useHyphens=n}toKebabCase(t){if(/^(webkit|moz|ms|o)[A-Z]/.test(t)){const e=t.match(/^(webkit|moz|ms|o)/);if(e){const s=e[0];return`-${s}${t.slice(s.length).replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`)}`}}return t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}escapeCSSSelector(t){return t.replace(/^(\d)/,"\\3$1 ").replace(/([#{}.:;?%&,@+*~'"!^$[\]()=>|/])/g,"\\$1")}getAllClassNames(t){if(!t)return[];const e=new Set;return Object.entries(t).forEach(([s,n])=>{n&&typeof n=="object"&&Object.keys(n).forEach(r=>{e.add(r)})}),Array.from(e)}getTypePrefixes(t=[]){const e=this.property,s=this.classes,n=Object.keys(e);if(!s)return[...n,...t].sort((a,i)=>i.length-a.length);const l=[...this.getAllClassNames(s)];return[...n,...l,...t].sort((a,i)=>i.length-a.length)}regexp(t){const e=this.getTypePrefixes(t).join("|"),s="\\[[^\\]]+\\]",n="\\([^()]*(?:\\([^()]*\\)[^()]*)*\\)",r="\\{[^{}]*(?:\\{[^{}]*\\}[^{}]*)*\\}",l="[a-zA-Z0-9_-]+|[a-zA-Z0-9_-]+(?:-(?:"+s+"|"+n+"|"+r+"))|"+s+"|"+n+"|"+r,a=`(${e}|\\[[^\\]]+\\])`,i=this.useHyphens?"(?:-)":"(?:-)?",h="(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+s+"|"+r+"|"+n+"|(?:\\$[^\\s\\/]+))",y="([a-zA-Z%]*)",c="(?:\\/(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+s+"|"+r+"|"+n+"|(?:\\$[^\\s\\/]+))([a-zA-Z%]*))?";return{prefix:l,type:a,separator:i,value:h,unit:y,secondValuePattern:c,all:"(?:("+l+"):)?"+a+i+h+y+c}}generateClassNameRegEx(t=[]){return new RegExp(this.regexp(t).all)}parse(t,e){if(Object.values(this.classes).some(o=>o==null?void 0:o[t]))return[void 0,t,"","",void 0,void 0,t];const s=this.generateClassNameRegEx(e),n=(t+"-dummy").match(s);if(!n)return null;const[,r,l,a,i,h,y]=n,c=a?a==="dummy"?"":a.replace("-dummy",""):"",f=h?h==="dummy"?"":h.replace("-dummy",""):"";return[r,l,c,i||"",f,y,t]}processValue(t,e,s){if(!t)return"";const n=r=>r.replace(/\{([^}]+)\}/g,(l,a)=>{const i=this.values,h=i!==null?typeof i[s]=="object"?i[s][a]:i[a]:void 0;return typeof h=="string"?h:l});if(typeof this.values=="object"&&this.values!==null&&(this.values[s]&&typeof this.values[s]=="object"&&this.values[s][t]||this.values[t]))return typeof this.values[s]=="object"&&this.values[s]!==null?this.values[s][t]:this.values[t];if(t.startsWith("$"))return`var(--${t.slice(1)})`;if(t.startsWith("[")&&t.endsWith("]")||t.startsWith("(")&&t.endsWith(")")){const r=t.slice(1,-1).replace(/\\\_/g,"m0x13c55").replace(/\_/g," ").replace(/m0x13c55/g,"_");return r.includes("{")?n(r):r.startsWith("--")?`var(${r})`:r}return t+(e||"")}processShorthand(t="",e="",s="",n,r="",l="",a=!0){const i=this.property[t],h=/^(?:\(|\[)([^:]+):(.+)(?:\)|\])$/;let y=null,c=e||"";const f=c.match(h);f&&(y=f[1].trim(),c=f[2].trim());let o;e.includes(y+":")?o=e.startsWith("(")?`(${c})`:`[${c}]`:o=e;const p=this.processValue(o,s,t),g=this.processValue(r,l,t);if(t.startsWith("[")&&t.endsWith("]")){const P=t.slice(1,-1).split(",").map(u=>u.trim()).map(u=>`${u?u.startsWith("--")?String(u):this.toKebabCase(String(u)):null}: ${p}`).join("; ");return{className:`${`[${t.slice(1,-1)}]${a?"-":""}${e}${s}`}`,cssRules:P,value:null,prefix:n}}if(i){if(typeof i=="object"&&"property"in i){const P=i.group&&this.values[i.group][p]?this.values[i.group][p]:s?e:p,u=typeof i.property=="function"?i.property({value:e.startsWith("[")?p:P,unit:e.startsWith("[")?"":s,secondValue:e.startsWith("[")?"":l?r:g,secondUnit:e.startsWith("[")?"":l,key:y}):i.property,b=i.value||"{0}";let x;if(typeof b=="function")x=b({value:P,unit:s,secondValue:l?r:g,secondUnit:l,key:y});else if(typeof b=="string"){const d=i.group||t,W=this.processValue(o,s,d);this.values[d]&&typeof this.values[d]=="object"&&this.values[d][o]?x=this.values[d][o]:b.includes("{")?x=this.parseValuePattern(d,b,W,"",g,""):x=p}else x=null;const _=`${t}${e?`${a&&a?"-":""}${e}${s}`:""}${r?`/${r}${l}`:""}`;return typeof i.property=="string"&&typeof b=="string"&&!b.includes("{1")&&r?null:{className:_,cssRules:u?Array.isArray(u)?u:typeof u=="string"&&(u.includes(":")||u.includes("value:"))?u.includes("value:")?u.slice(6):this.toKebabCase(String(u)):this.toKebabCase(String(u)):null,value:b===null||u===null||u.includes(":")||u.includes("value:")?null:e.startsWith("[")?p:x,prefix:n}}const $=typeof i=="function"?i({value:e.startsWith("[")?p:s?e:p,unit:e.startsWith("[")?"":s,secondValue:e.startsWith("[")?"":l?r:g,secondUnit:e.startsWith("[")?"":l,key:y}):i;return(typeof i=="string"||Array.isArray(i))&&r?null:{className:`${t}${e?(a?"-":"")+e+s:""}${r?`/${r}${l}`:""}`,cssRules:$?Array.isArray(i)?$:typeof $=="string"&&($.includes(":")||$.startsWith("value:"))?$.startsWith("value:")?$.slice(6):this.toKebabCase(String($)):this.toKebabCase(String($)):null,value:typeof $=="string"&&$.includes(":")?null:p,prefix:n}}return null}parseValuePattern(t,e,s,n,r,l){if(!e.includes("{0}")&&!e.includes("{1")&&!e.includes("||"))return e;const[a,i]=e.split("||").map(c=>c.trim()),h=this.processValue(s,n,t),y=this.processValue(r,l,t);if(e.includes("{0}")&&e.includes("{1")||e.includes("{1")){let c=a;if(s&&(c=c.replace("{0}",h)),e.includes("{1")){const f=c.match(/{1([^}]*)}/);if(e.includes("{1}"))r?c=r.startsWith("[")?y:c.replace("{1}",y):c=i;else if(f){const o=f[0],p=f[1].trim();let g=y;!g&&p.includes("|")?g=p.split("|")[1].trim():g||(g=""),c=s.startsWith("[")?h:c.replace(o,g)}}return s?c:i||a}else return s?s.startsWith("[")?h:a.replace("{0}",h):i||a}getParentClass(t){return Object.keys(this.classes).filter(e=>Object.prototype.hasOwnProperty.call(this.classes[e],t))}processCustomClass(t,e="",s="",n="",r="",l="",a=!0){if(!t)return null;const i=this.getParentClass(t);if(i.length>0){const h=i.map(f=>{const o=this.classes[f];if(!o||e&&!o[t].includes("||")||e&&!o[t].includes("|"))return"";const p=this.parseValuePattern(t,o[t]||"",e,s,r,l);return`${this.toKebabCase(String(f))}: ${p}`}).filter(Boolean).join("; "),y=t.slice(-(e+s).length),c=`${t}${e?`${a?"-":""}${e}${s}`:""}${r?`/${r}${l}`:""}`;return{className:e===y?t:c,cssRules:h,value:null,prefix:n}}return null}process(t){const e=Array.isArray(t)?t:t.split(/\s+/),s=[];return e.forEach(n=>{if(!n)return this;const[r,l]=n.split(":"),a=l||r,i=l?r:void 0,h=this.parse(n),y=h||[i,a,"",""];if(!y)return this;const[c,f,o,p,g,$]=y,P=!n.includes((f||"")+(o||"")),u=this.getParentClass(`${f}${P?"-":""}${o}`).length>0?`${f}${P?"-":""}${o}`:f,b=this.processCustomClass(u,o,p,c,g,$,P);if(b){const{className:_,cssRules:d,prefix:W}=b;if(!d||d==="null")return;s.push({className:_,cssRules:d,value:null,prefix:W,raw:[W,f,o,p,g,$]});return}const x=this.processShorthand(f,o,p,c,g,$,P);if(x){const{className:_,cssRules:d,value:W,prefix:R}=x;if(!d||d==="null")return;s.push({className:_,cssRules:d,value:W,prefix:R,raw:[c,f,o,p,g,$]})}}),s}}return C.TenoxUI=m,C.default=m,Object.defineProperties(C,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),C}({});
1
+ var __tenoxui_moxie__=function(m){"use strict";var Z=Object.defineProperty;var x=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable;var _=(m,g,C)=>g in m?Z(m,g,{enumerable:!0,configurable:!0,writable:!0,value:C}):m[g]=C,S=(m,g)=>{for(var C in g||(g={}))z.call(g,C)&&_(m,C,g[C]);if(x)for(var C of x(g))E.call(g,C)&&_(m,C,g[C]);return m};class g{constructor({property:s={},values:t={},classes:e={}}={}){this.property=S({moxie:({key:i,secondValue:r})=>r?null:i},s),this.values=t,this.classes=e}toKebabCase(s){if(/^(webkit|moz|ms|o)[A-Z]/.test(s)){const t=s.match(/^(webkit|moz|ms|o)/);if(t){const e=t[0];return`-${e}${s.slice(e.length).replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}`}}return s.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}escapeCSSSelector(s){return s.replace(/^(\d)/,"\\3$1 ").replace(/([#{}.:;?%&,@+*~'"!^$[\]()=>|/])/g,"\\$1")}getAllClassNames(s){if(!s)return[];const t=new Set;return Object.entries(s).forEach(([e,i])=>{i&&typeof i=="object"&&Object.keys(i).forEach(r=>{t.add(r)})}),Array.from(t)}getTypePrefixes(s=[]){const t=this.property,e=this.classes,i=Object.keys(t);if(!e)return[...i,...s].sort((l,n)=>n.length-l.length);const c=[...this.getAllClassNames(e)];return[...i,...c,...s].sort((l,n)=>n.length-l.length)}regexp(s){const t=this.getTypePrefixes(s).join("|"),e="\\[[^\\]]+\\]",i="\\([^()]*(?:\\([^()]*\\)[^()]*)*\\)",r="\\{[^{}]*(?:\\{[^{}]*\\}[^{}]*)*\\}",c="[a-zA-Z0-9_-]+|[a-zA-Z0-9_-]+(?:-(?:"+e+"|"+i+"|"+r+"))|"+e+"|"+i+"|"+r,l=`(${t}|\\[[^\\]]+\\])`,n="(?:-)",o="(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+e+"|"+r+"|"+i+"|(?:\\$[^\\s\\/]+))",u="([a-zA-Z%]*)",a="(?:\\/(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+e+"|"+r+"|"+i+"|(?:\\$[^\\s\\/]+))([a-zA-Z%]*))?";return{prefix:c,type:l,separator:n,value:o,unit:u,secondValuePattern:a,all:"(?:("+c+"):)?"+l+n+o+u+a}}generateClassNameRegEx(s=[]){return new RegExp(this.regexp(s).all)}parse(s,t){if(Object.values(this.classes).some(f=>f==null?void 0:f[s]))return[void 0,s,"","",void 0,void 0,s];const e=this.generateClassNameRegEx(t),i=(s+"-dummy").match(e);if(!i)return null;const[,r,c,l,n,o,u]=i,a=l?l==="dummy"?"":l.replace("-dummy",""):"",$=o?o==="dummy"?"":o.replace("-dummy",""):"",h=`${r?`${r}:`:""}${c}-${a}${n}${o?`/${$}${u}`:""}`;return[r,c,a,n||"",$,u,h]}processValue(s,t,e){if(!s)return"";const i=r=>r.replace(/\{([^}]+)\}/g,(c,l)=>{const n=this.values,o=n!==null?typeof n[e]=="object"?n[e][l]:n[l]:void 0;return typeof o=="string"?o:c});if(typeof this.values=="object"&&this.values!==null&&(this.values[e]&&typeof this.values[e]=="object"&&this.values[e][s]||this.values[s]))return typeof this.values[e]=="object"&&this.values[e]!==null?this.values[e][s]:this.values[s];if(s.startsWith("$"))return`var(--${s.slice(1)})`;if(s.startsWith("[")&&s.endsWith("]")||s.startsWith("(")&&s.endsWith(")")){const r=s.slice(1,-1).replace(/\\\_/g,"m0x13c55").replace(/\_/g," ").replace(/m0x13c55/g,"_");return r.includes("{")?i(r):r.startsWith("--")?`var(${r})`:r}return s+(t||"")}processShorthand(s="",t="",e="",i,r="",c="",l){const n=this.property[s],o=/^(?:\(|\[)([^:]+):(.+)(?:\)|\])$/;let u=null,a=t||"";const $=a.match(o);if($&&(u=$[1].trim(),a=$[2].trim()),(typeof n=="string"||Array.isArray(n))&&(!t||t.includes(u+":")||r))return null;let h;t.includes(u+":")?h=t.startsWith("(")?`(${a})`:`[${a}]`:h=t;const f=this.processValue(h,e,s),y=this.processValue(r,c,s);if(s.startsWith("[")&&s.endsWith("]")){if(!t||r)return null;const p=s.slice(1,-1).split(",").map(b=>b.trim().startsWith("--")?String(b.trim()):this.toKebabCase(String(b.trim())));return{className:`${s}-${t}${e}`,cssRules:p.length===1?p[0]:p,value:f,prefix:i}}if(n){if(typeof n=="object"&&"property"in n){const b=n.group&&this.values[n.group][f]?this.values[n.group][f]:e?t:f,d=typeof n.property=="function"?n.property({value:t.startsWith("[")?f:b,unit:t.startsWith("[")?"":e,secondValue:t.startsWith("[")?"":c?r:y,secondUnit:t.startsWith("[")?"":c,key:u,raw:l}):n.property,A=n.value||"{0}";let W;if(typeof A=="function")W=A({value:b,unit:e,secondValue:c?r:y,secondUnit:c,key:u,raw:l});else if(typeof A=="string"){const P=n.group||s,R=this.processValue(h,e,P);this.values[P]&&typeof this.values[P]=="object"&&this.values[P][h]?W=this.values[P][h]:A.includes("{")?W=this.parseValuePattern(P,A,R,"",y,""):W=f}else W=null;const V=`${s}${t?`-${t}${e}`:""}${r?`/${r}${c}`:""}`;return typeof n.property=="string"&&typeof A=="string"&&(t.includes(u+":")||!A.includes("{1")&&r)?null:{className:V,cssRules:d?Array.isArray(d)?d:typeof d=="string"&&(d.includes(":")||d.includes("value:"))?d.includes("value:")?d.slice(6):this.toKebabCase(String(d)):this.toKebabCase(String(d)):null,value:A===null||d===null||d.includes(":")||d.includes("value:")?null:t.startsWith("[")?f:W,prefix:i}}const p=typeof n=="function"?n({value:t.startsWith("[")?f:e?t:f,unit:t.startsWith("[")?"":e,secondValue:t.startsWith("[")?"":c?r:y,secondUnit:t.startsWith("[")?"":c,key:u,raw:l}):n;return{className:`${s}${t?"-"+t+e:""}${r?`/${r}${c}`:""}`,cssRules:p?Array.isArray(n)?p:typeof p=="string"&&(p.includes(":")||p.startsWith("value:"))?p.startsWith("value:")?p.slice(6):this.toKebabCase(String(p)):this.toKebabCase(String(p)):null,value:typeof p=="string"&&p.includes(":")?null:f,prefix:i}}return null}parseValuePattern(s,t,e,i,r,c){if(!t.includes("{0}")&&!t.includes("{1")&&!t.includes("||"))return t;const[l,n]=t.split("||").map(a=>a.trim()),o=this.processValue(e,i,s),u=this.processValue(r,c,s);if(t.includes("{0}")&&t.includes("{1")||t.includes("{1")){let a=l;if(e&&(a=a.replace("{0}",o)),t.includes("{1")){const $=a.match(/{1([^}]*)}/);if(t.includes("{1}"))r?a=r.startsWith("[")?u:a.replace("{1}",u):a=n;else if($){const h=$[0],f=$[1].trim();let y=u;!y&&f.includes("|")?y=f.split("|")[1].trim():y||(y=""),a=e.startsWith("[")?o:a.replace(h,y)}}return e?a:n||l}else return e?e.startsWith("[")?o:l.replace("{0}",o):n||l}getParentClass(s){return Object.keys(this.classes).filter(t=>Object.prototype.hasOwnProperty.call(this.classes[t],s))}processCustomClass(s,t="",e="",i="",r="",c=""){if(!s)return null;const l=this.getParentClass(s);if(l.length>0){const n=l.map(a=>{const $=this.classes[a];if(!$||t&&!$[s].includes("||")||t&&!$[s].includes("|"))return null;const h=this.parseValuePattern(s,$[s]||"",t,e,r,c);return`${this.toKebabCase(String(a))}: ${h}`}).filter(Boolean).join("; "),o=s.slice(-(t+e).length),u=`${s}${t?`-${t}${e}`:""}${r?`/${r}${c}`:""}`;return{className:t===o?s:u,cssRules:n,value:null,prefix:i}}return null}process(s){try{const t=Array.isArray(s)?s:s.split(/\s+/),e=[];for(const i of t)try{if(!i)continue;const r=this.parse(i);if(!r)continue;const[c,l,n,o,u,a]=r;if(!l)continue;const $=this.getParentClass(`${l}-${n}`).length>0?`${l}-${n}`:l;try{const h=this.processCustomClass($,n,o,c,u,a);if(h){const{className:f,cssRules:y,prefix:p}=h;if(!y||y==="null")continue;e.push({className:f,cssRules:y,value:null,prefix:p,raw:r});continue}}catch(h){console.warn(`Error processing custom class "${i}":`,h)}try{const h=this.processShorthand(l,n,o,c,u,a,r);if(h){const{className:f,cssRules:y,value:p,prefix:b}=h;if(!y||y==="null")continue;e.push({className:f,cssRules:y,value:p,prefix:b,raw:r})}}catch(h){console.warn(`Error processing shorthand "${i}":`,h)}}catch(r){console.warn(`Failed to process class \`${i}\`:`,r)}return e}catch(t){return console.error("Critical error in process method:",t),[]}}}return m.TenoxUI=g,m.default=g,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),m}({});
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(g,d){typeof exports=="object"&&typeof module!="undefined"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(g=typeof globalThis!="undefined"?globalThis:g||self,d(g.__tenoxui_moxie__={}))})(this,function(g){"use strict";var R=Object.defineProperty;var V=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var S=(g,d,C)=>d in g?R(g,d,{enumerable:!0,configurable:!0,writable:!0,value:C}):g[d]=C,v=(g,d)=>{for(var C in d||(d={}))Z.call(d,C)&&S(g,C,d[C]);if(V)for(var C of V(d))z.call(d,C)&&S(g,C,d[C]);return g};class d{constructor({property:e={},values:t={},classes:s={},alwaysUseHyphens:n=!0}={}){this.property=v({moxie:({key:r,secondValue:l})=>l?null:r},e),this.values=t,this.classes=s,this.useHyphens=n}toKebabCase(e){if(/^(webkit|moz|ms|o)[A-Z]/.test(e)){const t=e.match(/^(webkit|moz|ms|o)/);if(t){const s=t[0];return`-${s}${e.slice(s.length).replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`)}`}}return e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}escapeCSSSelector(e){return e.replace(/^(\d)/,"\\3$1 ").replace(/([#{}.:;?%&,@+*~'"!^$[\]()=>|/])/g,"\\$1")}getAllClassNames(e){if(!e)return[];const t=new Set;return Object.entries(e).forEach(([s,n])=>{n&&typeof n=="object"&&Object.keys(n).forEach(r=>{t.add(r)})}),Array.from(t)}getTypePrefixes(e=[]){const t=this.property,s=this.classes,n=Object.keys(t);if(!s)return[...n,...e].sort((a,i)=>i.length-a.length);const l=[...this.getAllClassNames(s)];return[...n,...l,...e].sort((a,i)=>i.length-a.length)}regexp(e){const t=this.getTypePrefixes(e).join("|"),s="\\[[^\\]]+\\]",n="\\([^()]*(?:\\([^()]*\\)[^()]*)*\\)",r="\\{[^{}]*(?:\\{[^{}]*\\}[^{}]*)*\\}",l="[a-zA-Z0-9_-]+|[a-zA-Z0-9_-]+(?:-(?:"+s+"|"+n+"|"+r+"))|"+s+"|"+n+"|"+r,a=`(${t}|\\[[^\\]]+\\])`,i=this.useHyphens?"(?:-)":"(?:-)?",f="(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+s+"|"+r+"|"+n+"|(?:\\$[^\\s\\/]+))",y="([a-zA-Z%]*)",o="(?:\\/(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+s+"|"+r+"|"+n+"|(?:\\$[^\\s\\/]+))([a-zA-Z%]*))?";return{prefix:l,type:a,separator:i,value:f,unit:y,secondValuePattern:o,all:"(?:("+l+"):)?"+a+i+f+y+o}}generateClassNameRegEx(e=[]){return new RegExp(this.regexp(e).all)}parse(e,t){if(Object.values(this.classes).some(c=>c==null?void 0:c[e]))return[void 0,e,"","",void 0,void 0,e];const s=this.generateClassNameRegEx(t),n=(e+"-dummy").match(s);if(!n)return null;const[,r,l,a,i,f,y]=n,o=a?a==="dummy"?"":a.replace("-dummy",""):"",h=f?f==="dummy"?"":f.replace("-dummy",""):"";return[r,l,o,i||"",h,y,e]}processValue(e,t,s){if(!e)return"";const n=r=>r.replace(/\{([^}]+)\}/g,(l,a)=>{const i=this.values,f=i!==null?typeof i[s]=="object"?i[s][a]:i[a]:void 0;return typeof f=="string"?f:l});if(typeof this.values=="object"&&this.values!==null&&(this.values[s]&&typeof this.values[s]=="object"&&this.values[s][e]||this.values[e]))return typeof this.values[s]=="object"&&this.values[s]!==null?this.values[s][e]:this.values[e];if(e.startsWith("$"))return`var(--${e.slice(1)})`;if(e.startsWith("[")&&e.endsWith("]")||e.startsWith("(")&&e.endsWith(")")){const r=e.slice(1,-1).replace(/\\\_/g,"m0x13c55").replace(/\_/g," ").replace(/m0x13c55/g,"_");return r.includes("{")?n(r):r.startsWith("--")?`var(${r})`:r}return e+(t||"")}processShorthand(e="",t="",s="",n,r="",l="",a=!0){const i=this.property[e],f=/^(?:\(|\[)([^:]+):(.+)(?:\)|\])$/;let y=null,o=t||"";const h=o.match(f);h&&(y=h[1].trim(),o=h[2].trim());let c;t.includes(y+":")?c=t.startsWith("(")?`(${o})`:`[${o}]`:c=t;const p=this.processValue(c,s,e),m=this.processValue(r,l,e);if(e.startsWith("[")&&e.endsWith("]")){const A=e.slice(1,-1).split(",").map(u=>u.trim()).map(u=>`${u?u.startsWith("--")?String(u):this.toKebabCase(String(u)):null}: ${p}`).join("; ");return{className:`${`[${e.slice(1,-1)}]${a?"-":""}${t}${s}`}`,cssRules:A,value:null,prefix:n}}if(i){if(typeof i=="object"&&"property"in i){const A=i.group&&this.values[i.group][p]?this.values[i.group][p]:s?t:p,u=typeof i.property=="function"?i.property({value:t.startsWith("[")?p:A,unit:t.startsWith("[")?"":s,secondValue:t.startsWith("[")?"":l?r:m,secondUnit:t.startsWith("[")?"":l,key:y}):i.property,b=i.value||"{0}";let P;if(typeof b=="function")P=b({value:A,unit:s,secondValue:l?r:m,secondUnit:l,key:y});else if(typeof b=="string"){const x=i.group||e,W=this.processValue(c,s,x);this.values[x]&&typeof this.values[x]=="object"&&this.values[x][c]?P=this.values[x][c]:b.includes("{")?P=this.parseValuePattern(x,b,W,"",m,""):P=p}else P=null;const _=`${e}${t?`${a&&a?"-":""}${t}${s}`:""}${r?`/${r}${l}`:""}`;return typeof i.property=="string"&&typeof b=="string"&&!b.includes("{1")&&r?null:{className:_,cssRules:u?Array.isArray(u)?u:typeof u=="string"&&(u.includes(":")||u.includes("value:"))?u.includes("value:")?u.slice(6):this.toKebabCase(String(u)):this.toKebabCase(String(u)):null,value:b===null||u===null||u.includes(":")||u.includes("value:")?null:t.startsWith("[")?p:P,prefix:n}}const $=typeof i=="function"?i({value:t.startsWith("[")?p:s?t:p,unit:t.startsWith("[")?"":s,secondValue:t.startsWith("[")?"":l?r:m,secondUnit:t.startsWith("[")?"":l,key:y}):i;return(typeof i=="string"||Array.isArray(i))&&r?null:{className:`${e}${t?(a?"-":"")+t+s:""}${r?`/${r}${l}`:""}`,cssRules:$?Array.isArray(i)?$:typeof $=="string"&&($.includes(":")||$.startsWith("value:"))?$.startsWith("value:")?$.slice(6):this.toKebabCase(String($)):this.toKebabCase(String($)):null,value:typeof $=="string"&&$.includes(":")?null:p,prefix:n}}return null}parseValuePattern(e,t,s,n,r,l){if(!t.includes("{0}")&&!t.includes("{1")&&!t.includes("||"))return t;const[a,i]=t.split("||").map(o=>o.trim()),f=this.processValue(s,n,e),y=this.processValue(r,l,e);if(t.includes("{0}")&&t.includes("{1")||t.includes("{1")){let o=a;if(s&&(o=o.replace("{0}",f)),t.includes("{1")){const h=o.match(/{1([^}]*)}/);if(t.includes("{1}"))r?o=r.startsWith("[")?y:o.replace("{1}",y):o=i;else if(h){const c=h[0],p=h[1].trim();let m=y;!m&&p.includes("|")?m=p.split("|")[1].trim():m||(m=""),o=s.startsWith("[")?f:o.replace(c,m)}}return s?o:i||a}else return s?s.startsWith("[")?f:a.replace("{0}",f):i||a}getParentClass(e){return Object.keys(this.classes).filter(t=>Object.prototype.hasOwnProperty.call(this.classes[t],e))}processCustomClass(e,t="",s="",n="",r="",l="",a=!0){if(!e)return null;const i=this.getParentClass(e);if(i.length>0){const f=i.map(h=>{const c=this.classes[h];if(!c||t&&!c[e].includes("||")||t&&!c[e].includes("|"))return"";const p=this.parseValuePattern(e,c[e]||"",t,s,r,l);return`${this.toKebabCase(String(h))}: ${p}`}).filter(Boolean).join("; "),y=e.slice(-(t+s).length),o=`${e}${t?`${a?"-":""}${t}${s}`:""}${r?`/${r}${l}`:""}`;return{className:t===y?e:o,cssRules:f,value:null,prefix:n}}return null}process(e){const t=Array.isArray(e)?e:e.split(/\s+/),s=[];return t.forEach(n=>{if(!n)return this;const[r,l]=n.split(":"),a=l||r,i=l?r:void 0,f=this.parse(n),y=f||[i,a,"",""];if(!y)return this;const[o,h,c,p,m,$]=y,A=!n.includes((h||"")+(c||"")),u=this.getParentClass(`${h}${A?"-":""}${c}`).length>0?`${h}${A?"-":""}${c}`:h,b=this.processCustomClass(u,c,p,o,m,$,A);if(b){const{className:_,cssRules:x,prefix:W}=b;if(!x||x==="null")return;s.push({className:_,cssRules:x,value:null,prefix:W,raw:[W,h,c,p,m,$]});return}const P=this.processShorthand(h,c,p,o,m,$,A);if(P){const{className:_,cssRules:x,value:W,prefix:j}=P;if(!x||x==="null")return;s.push({className:_,cssRules:x,value:W,prefix:j,raw:[o,h,c,p,m,$]})}}),s}}g.TenoxUI=d,g.default=d,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function($,y){typeof exports=="object"&&typeof module!="undefined"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):($=typeof globalThis!="undefined"?globalThis:$||self,y($.__tenoxui_moxie__={}))})(this,function($){"use strict";var Z=Object.defineProperty;var P=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var _=($,y,C)=>y in $?Z($,y,{enumerable:!0,configurable:!0,writable:!0,value:C}):$[y]=C,S=($,y)=>{for(var C in y||(y={}))j.call(y,C)&&_($,C,y[C]);if(P)for(var C of P(y))z.call(y,C)&&_($,C,y[C]);return $};class y{constructor({property:e={},values:s={},classes:t={}}={}){this.property=S({moxie:({key:i,secondValue:r})=>r?null:i},e),this.values=s,this.classes=t}toKebabCase(e){if(/^(webkit|moz|ms|o)[A-Z]/.test(e)){const s=e.match(/^(webkit|moz|ms|o)/);if(s){const t=s[0];return`-${t}${e.slice(t.length).replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}`}}return e.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`)}escapeCSSSelector(e){return e.replace(/^(\d)/,"\\3$1 ").replace(/([#{}.:;?%&,@+*~'"!^$[\]()=>|/])/g,"\\$1")}getAllClassNames(e){if(!e)return[];const s=new Set;return Object.entries(e).forEach(([t,i])=>{i&&typeof i=="object"&&Object.keys(i).forEach(r=>{s.add(r)})}),Array.from(s)}getTypePrefixes(e=[]){const s=this.property,t=this.classes,i=Object.keys(s);if(!t)return[...i,...e].sort((l,n)=>n.length-l.length);const c=[...this.getAllClassNames(t)];return[...i,...c,...e].sort((l,n)=>n.length-l.length)}regexp(e){const s=this.getTypePrefixes(e).join("|"),t="\\[[^\\]]+\\]",i="\\([^()]*(?:\\([^()]*\\)[^()]*)*\\)",r="\\{[^{}]*(?:\\{[^{}]*\\}[^{}]*)*\\}",c="[a-zA-Z0-9_-]+|[a-zA-Z0-9_-]+(?:-(?:"+t+"|"+i+"|"+r+"))|"+t+"|"+i+"|"+r,l=`(${s}|\\[[^\\]]+\\])`,n="(?:-)",a="(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+t+"|"+r+"|"+i+"|(?:\\$[^\\s\\/]+))",u="([a-zA-Z%]*)",o="(?:\\/(-?(?:\\d+(?:\\.\\d+)?)|(?:[a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)*(?:-[a-zA-Z0-9_]+)*)|(?:#[0-9a-fA-F]+)|"+t+"|"+r+"|"+i+"|(?:\\$[^\\s\\/]+))([a-zA-Z%]*))?";return{prefix:c,type:l,separator:n,value:a,unit:u,secondValuePattern:o,all:"(?:("+c+"):)?"+l+n+a+u+o}}generateClassNameRegEx(e=[]){return new RegExp(this.regexp(e).all)}parse(e,s){if(Object.values(this.classes).some(f=>f==null?void 0:f[e]))return[void 0,e,"","",void 0,void 0,e];const t=this.generateClassNameRegEx(s),i=(e+"-dummy").match(t);if(!i)return null;const[,r,c,l,n,a,u]=i,o=l?l==="dummy"?"":l.replace("-dummy",""):"",m=a?a==="dummy"?"":a.replace("-dummy",""):"",h=`${r?`${r}:`:""}${c}-${o}${n}${a?`/${m}${u}`:""}`;return[r,c,o,n||"",m,u,h]}processValue(e,s,t){if(!e)return"";const i=r=>r.replace(/\{([^}]+)\}/g,(c,l)=>{const n=this.values,a=n!==null?typeof n[t]=="object"?n[t][l]:n[l]:void 0;return typeof a=="string"?a:c});if(typeof this.values=="object"&&this.values!==null&&(this.values[t]&&typeof this.values[t]=="object"&&this.values[t][e]||this.values[e]))return typeof this.values[t]=="object"&&this.values[t]!==null?this.values[t][e]:this.values[e];if(e.startsWith("$"))return`var(--${e.slice(1)})`;if(e.startsWith("[")&&e.endsWith("]")||e.startsWith("(")&&e.endsWith(")")){const r=e.slice(1,-1).replace(/\\\_/g,"m0x13c55").replace(/\_/g," ").replace(/m0x13c55/g,"_");return r.includes("{")?i(r):r.startsWith("--")?`var(${r})`:r}return e+(s||"")}processShorthand(e="",s="",t="",i,r="",c="",l){const n=this.property[e],a=/^(?:\(|\[)([^:]+):(.+)(?:\)|\])$/;let u=null,o=s||"";const m=o.match(a);if(m&&(u=m[1].trim(),o=m[2].trim()),(typeof n=="string"||Array.isArray(n))&&(!s||s.includes(u+":")||r))return null;let h;s.includes(u+":")?h=s.startsWith("(")?`(${o})`:`[${o}]`:h=s;const f=this.processValue(h,t,e),d=this.processValue(r,c,e);if(e.startsWith("[")&&e.endsWith("]")){if(!s||r)return null;const p=e.slice(1,-1).split(",").map(b=>b.trim().startsWith("--")?String(b.trim()):this.toKebabCase(String(b.trim())));return{className:`${e}-${s}${t}`,cssRules:p.length===1?p[0]:p,value:f,prefix:i}}if(n){if(typeof n=="object"&&"property"in n){const b=n.group&&this.values[n.group][f]?this.values[n.group][f]:t?s:f,g=typeof n.property=="function"?n.property({value:s.startsWith("[")?f:b,unit:s.startsWith("[")?"":t,secondValue:s.startsWith("[")?"":c?r:d,secondUnit:s.startsWith("[")?"":c,key:u,raw:l}):n.property,x=n.value||"{0}";let A;if(typeof x=="function")A=x({value:b,unit:t,secondValue:c?r:d,secondUnit:c,key:u,raw:l});else if(typeof x=="string"){const W=n.group||e,R=this.processValue(h,t,W);this.values[W]&&typeof this.values[W]=="object"&&this.values[W][h]?A=this.values[W][h]:x.includes("{")?A=this.parseValuePattern(W,x,R,"",d,""):A=f}else A=null;const V=`${e}${s?`-${s}${t}`:""}${r?`/${r}${c}`:""}`;return typeof n.property=="string"&&typeof x=="string"&&(s.includes(u+":")||!x.includes("{1")&&r)?null:{className:V,cssRules:g?Array.isArray(g)?g:typeof g=="string"&&(g.includes(":")||g.includes("value:"))?g.includes("value:")?g.slice(6):this.toKebabCase(String(g)):this.toKebabCase(String(g)):null,value:x===null||g===null||g.includes(":")||g.includes("value:")?null:s.startsWith("[")?f:A,prefix:i}}const p=typeof n=="function"?n({value:s.startsWith("[")?f:t?s:f,unit:s.startsWith("[")?"":t,secondValue:s.startsWith("[")?"":c?r:d,secondUnit:s.startsWith("[")?"":c,key:u,raw:l}):n;return{className:`${e}${s?"-"+s+t:""}${r?`/${r}${c}`:""}`,cssRules:p?Array.isArray(n)?p:typeof p=="string"&&(p.includes(":")||p.startsWith("value:"))?p.startsWith("value:")?p.slice(6):this.toKebabCase(String(p)):this.toKebabCase(String(p)):null,value:typeof p=="string"&&p.includes(":")?null:f,prefix:i}}return null}parseValuePattern(e,s,t,i,r,c){if(!s.includes("{0}")&&!s.includes("{1")&&!s.includes("||"))return s;const[l,n]=s.split("||").map(o=>o.trim()),a=this.processValue(t,i,e),u=this.processValue(r,c,e);if(s.includes("{0}")&&s.includes("{1")||s.includes("{1")){let o=l;if(t&&(o=o.replace("{0}",a)),s.includes("{1")){const m=o.match(/{1([^}]*)}/);if(s.includes("{1}"))r?o=r.startsWith("[")?u:o.replace("{1}",u):o=n;else if(m){const h=m[0],f=m[1].trim();let d=u;!d&&f.includes("|")?d=f.split("|")[1].trim():d||(d=""),o=t.startsWith("[")?a:o.replace(h,d)}}return t?o:n||l}else return t?t.startsWith("[")?a:l.replace("{0}",a):n||l}getParentClass(e){return Object.keys(this.classes).filter(s=>Object.prototype.hasOwnProperty.call(this.classes[s],e))}processCustomClass(e,s="",t="",i="",r="",c=""){if(!e)return null;const l=this.getParentClass(e);if(l.length>0){const n=l.map(o=>{const m=this.classes[o];if(!m||s&&!m[e].includes("||")||s&&!m[e].includes("|"))return null;const h=this.parseValuePattern(e,m[e]||"",s,t,r,c);return`${this.toKebabCase(String(o))}: ${h}`}).filter(Boolean).join("; "),a=e.slice(-(s+t).length),u=`${e}${s?`-${s}${t}`:""}${r?`/${r}${c}`:""}`;return{className:s===a?e:u,cssRules:n,value:null,prefix:i}}return null}process(e){try{const s=Array.isArray(e)?e:e.split(/\s+/),t=[];for(const i of s)try{if(!i)continue;const r=this.parse(i);if(!r)continue;const[c,l,n,a,u,o]=r;if(!l)continue;const m=this.getParentClass(`${l}-${n}`).length>0?`${l}-${n}`:l;try{const h=this.processCustomClass(m,n,a,c,u,o);if(h){const{className:f,cssRules:d,prefix:p}=h;if(!d||d==="null")continue;t.push({className:f,cssRules:d,value:null,prefix:p,raw:r});continue}}catch(h){console.warn(`Error processing custom class "${i}":`,h)}try{const h=this.processShorthand(l,n,a,c,u,o,r);if(h){const{className:f,cssRules:d,value:p,prefix:b}=h;if(!d||d==="null")continue;t.push({className:f,cssRules:d,value:p,prefix:b,raw:r})}}catch(h){console.warn(`Error processing shorthand "${i}":`,h)}}catch(r){console.warn(`Failed to process class \`${i}\`:`,r)}return t}catch(s){return console.error("Critical error in process method:",s),[]}}}$.TenoxUI=y,$.default=y,Object.defineProperties($,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -5,16 +5,10 @@ export type PropertyParams = {
5
5
  unit?: string;
6
6
  secondValue?: string;
7
7
  secondUnit?: string;
8
- };
9
- export type ValueParams = {
10
- key?: string | null;
11
- value?: string;
12
- unit?: string;
13
- secondValue?: string;
14
- secondUnit?: string;
8
+ raw?: Parsed;
15
9
  };
16
10
  export type PropertyParamValue = GetCSSProperty | ((params: PropertyParams) => null | GetCSSProperty);
17
- export type ValuePropType = string | ((params: ValueParams) => string | null) | null;
11
+ export type ValuePropType = string | ((params: PropertyParams) => string | null) | null;
18
12
  export type PropertyValue = PropertyParamValue | {
19
13
  property?: PropertyParamValue;
20
14
  value?: ValuePropType;
@@ -27,7 +21,6 @@ export interface Config {
27
21
  property?: Property;
28
22
  values?: Values;
29
23
  classes?: Classes;
30
- alwaysUseHyphens?: boolean;
31
24
  }
32
25
  export type Parsed = null | (string | undefined)[];
33
26
  export type ProcessedStyle = {
package/package.json CHANGED
@@ -1,13 +1,20 @@
1
1
  {
2
2
  "name": "@tenoxui/moxie",
3
- "version": "0.4.4",
3
+ "version": "0.5.0-alpha.0",
4
4
  "description": "Very lightweight utility-first CSS engine for style generation",
5
5
  "author": "NOuSantx <nousantx@gmail.com>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/tenoxui/tenoxui#readme",
8
8
  "keywords": [
9
- "tenoxui",
10
- "css-framework"
9
+ "css",
10
+ "css-framework",
11
+ "css-engine",
12
+ "css-parser",
13
+ "utility-first",
14
+ "atomic-css",
15
+ "frontend",
16
+ "library",
17
+ "javascript-library"
11
18
  ],
12
19
  "repository": {
13
20
  "type": "git",