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