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