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