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