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