@styleframe/transpiler 2.4.0 → 2.5.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/CHANGELOG.md +15 -0
- package/dist/transpiler.js +10 -10
- package/dist/transpiler.umd.cjs +6 -6
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @styleframe/transpiler
|
|
2
2
|
|
|
3
|
+
## 2.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#72](https://github.com/styleframe-dev/styleframe/pull/72) [`d98b650`](https://github.com/styleframe-dev/styleframe/commit/d98b65030170582ceacfabde3ba9ff7d92105389) Thanks [@alexgrozav](https://github.com/alexgrozav)! - feat: add support for .styleframe file imports
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#80](https://github.com/styleframe-dev/styleframe/pull/80) [`ff1a689`](https://github.com/styleframe-dev/styleframe/commit/ff1a689f36dc4294b2a7353949c6efd220451e9d) Thanks [@alexgrozav](https://github.com/alexgrozav)! - fix: Expand CSS selector escaping for arbitrary values
|
|
12
|
+
|
|
13
|
+
Consolidate escape logic into a single regex and extend escaping to cover additional special characters (#, (, ), %, ,) needed for arbitrary CSS value syntax like `[#1E3A8A]`, `[rgb(255,0,0)]`, and `[calc(100%-20px)]`.
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`d98b650`](https://github.com/styleframe-dev/styleframe/commit/d98b65030170582ceacfabde3ba9ff7d92105389)]:
|
|
16
|
+
- @styleframe/core@2.5.0
|
|
17
|
+
|
|
3
18
|
## 2.4.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/dist/transpiler.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const Fe = " ", N = ["charset", "import", "namespace"],
|
|
1
|
+
const Fe = " ", N = ["charset", "import", "namespace"], L = ["layer"], D = ({ name: e }) => `[data-theme="${e}"]`, I = ({
|
|
2
2
|
name: e,
|
|
3
3
|
value: t,
|
|
4
4
|
modifiers: r
|
|
5
|
-
}) => `._${[...r, e, ...t === "default" ? [] : [t]].filter(Boolean).join("\\:")}`, w = ({ name: e }) => e.replace(/^\.+|\.+$/g, "").replace(/\.+/g, "--");
|
|
5
|
+
}) => `._${[...r, e, ...t === "default" ? [] : [t]].filter(Boolean).join("\\:").replace(/[[\].#()%,]/g, "\\$&")}`, w = ({ name: e }) => e.replace(/^\.+|\.+$/g, "").replace(/\.+/g, "--");
|
|
6
6
|
function U(e, t) {
|
|
7
7
|
return `@${e}${t ? " " : ""}${t}`;
|
|
8
8
|
}
|
|
@@ -47,10 +47,10 @@ function x(e) {
|
|
|
47
47
|
function V(e, t) {
|
|
48
48
|
return e ? (Array.isArray(e) ? e : $(e)).map((r) => k(r)).join("") : "";
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function K(e, t) {
|
|
51
51
|
return x(V(e || ""));
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function q(e, t) {
|
|
54
54
|
return e ? (Array.isArray(e) ? e : $(e)).map((r) => r.toLowerCase()).join("-") : "";
|
|
55
55
|
}
|
|
56
56
|
function z(e) {
|
|
@@ -65,10 +65,10 @@ function Q(e) {
|
|
|
65
65
|
return e === e.toUpperCase();
|
|
66
66
|
}
|
|
67
67
|
function Z(e) {
|
|
68
|
-
return
|
|
68
|
+
return K(e);
|
|
69
69
|
}
|
|
70
70
|
function J(e) {
|
|
71
|
-
return
|
|
71
|
+
return q(e);
|
|
72
72
|
}
|
|
73
73
|
function W(e) {
|
|
74
74
|
return J(e);
|
|
@@ -137,7 +137,7 @@ function C(e) {
|
|
|
137
137
|
function te(e) {
|
|
138
138
|
const t = C(e);
|
|
139
139
|
return function(n, o) {
|
|
140
|
-
const s = N.includes(n.identifier), i =
|
|
140
|
+
const s = N.includes(n.identifier), i = L.includes(
|
|
141
141
|
n.identifier
|
|
142
142
|
), a = Object.keys(n.declarations).length > 0, c = n.variables.length > 0, u = n.children.length > 0, f = U(n.identifier, n.rule);
|
|
143
143
|
return s || i && !(a || c || u) ? `${f};` : t(f, n, o);
|
|
@@ -355,7 +355,7 @@ function Ae(e) {
|
|
|
355
355
|
function ge(e) {
|
|
356
356
|
const t = C(e);
|
|
357
357
|
return function(n, o) {
|
|
358
|
-
const i = (o.themes?.selector ??
|
|
358
|
+
const i = (o.themes?.selector ?? D)({ name: n.name });
|
|
359
359
|
return t(i, n, o);
|
|
360
360
|
};
|
|
361
361
|
}
|
|
@@ -567,12 +567,12 @@ async function Ne(e, {
|
|
|
567
567
|
export {
|
|
568
568
|
Fe as DEFAULT_INDENT,
|
|
569
569
|
N as STATEMENT_AT_RULES,
|
|
570
|
-
|
|
570
|
+
L as STATEMENT_OR_BLOCK_AT_RULES,
|
|
571
571
|
z as addIndentToLine,
|
|
572
572
|
d as consumeCSS,
|
|
573
573
|
j as consumeTS,
|
|
574
574
|
R as createFile,
|
|
575
|
-
|
|
575
|
+
D as defaultThemeSelectorFn,
|
|
576
576
|
I as defaultUtilitySelectorFn,
|
|
577
577
|
w as defaultVariableNameFn,
|
|
578
578
|
H as indentLines,
|
package/dist/transpiler.umd.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
(function(p,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(p=typeof globalThis<"u"?globalThis:p||self,j(p.transpiler={}))})(this,(function(p){"use strict";const w=["charset","import","namespace"],N=["layer"],O=({name:e})=>`[data-theme="${e}"]
|
|
2
|
-
`).map(t=>
|
|
1
|
+
(function(p,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(p=typeof globalThis<"u"?globalThis:p||self,j(p.transpiler={}))})(this,(function(p){"use strict";const w=["charset","import","namespace"],N=["layer"],O=({name:e})=>`[data-theme="${e}"]`,$=({name:e,value:t,modifiers:n})=>`._${[...n,e,...t==="default"?[]:[t]].filter(Boolean).join("\\:").replace(/[[\].#()%,]/g,"\\$&")}`,v=({name:e})=>e.replace(/^\.+|\.+$/g,"").replace(/\.+/g,"--");function K(e,t){return`@${e}${t?" ":""}${t}`}const q=/\d/,z=["-","_","/","."];function H(e=""){if(!q.test(e))return e!==e.toLowerCase()}function F(e,t){const n=z,r=[];if(!e||typeof e!="string")return r;let o="",a,i;for(const s of e){const c=n.includes(s);if(c===!0){r.push(o),o="",a=void 0;continue}const u=H(s);if(i===!1){if(a===!1&&u===!0){r.push(o),o=s,a=u;continue}if(a===!0&&u===!1&&o.length>1){const f=o.at(-1);r.push(o.slice(0,Math.max(0,o.length-1))),o=f+s,a=u;continue}}o+=s,a=u,i=c}return r.push(o),r}function Q(e){return e?e[0].toUpperCase()+e.slice(1):""}function Z(e){return e?e[0].toLowerCase()+e.slice(1):""}function x(e,t){return e?(Array.isArray(e)?e:F(e)).map(n=>Q(n)).join(""):""}function J(e,t){return Z(x(e||""))}function W(e,t){return e?(Array.isArray(e)?e:F(e)).map(n=>n.toLowerCase()).join("-"):""}function L(e){return` ${e}`}function B(e){return e.split(`
|
|
2
|
+
`).map(t=>L(t)).join(`
|
|
3
3
|
`)}function _(e){return e===e.toUpperCase()}function U(e){return J(e)}function D(e){return W(e)}function G(e){return D(e)}function I(e,t){return`${e.startsWith("--")?e:G(e)}: ${t};`}function Y(e){return`{${e.length>0?`
|
|
4
|
-
`:""}${e.map(t=>`${
|
|
4
|
+
`:""}${e.map(t=>`${B(`${t}`)}
|
|
5
5
|
`).join("")}}`}function M(e){return`--${(e.startsWith("--")?e.slice(2):e).replace(/[^a-zA-Z0-9_\-\u0080-\uFFFF]/g,"-")||"unknown-variable"}`}function X(e,t){return I(M(e),t)}function ee(e,t){return`var(${M(e)}${t?`, ${t}`:""})`}function P(e,t){return`${e} ${Y(t)}`}function te(e){return function(n,r){return Object.entries(n).map(([o,a])=>I(o,e(a,r)))}}function k(e){return function(n,r){const a=(r.variables?.name??v)({name:n.name});return X(a,e(n.value,r))}}function C(e){const t=k(e),n=te(e);return function(o,a,i){const{variables:s,declarations:c,children:u}=a,f=o===":root",l=(s??[]).map(S=>t(S,i)),m=n(c??{},i),y=(u??[]).map(S=>e(S,i)),d=l.length>0,A=m.length>0,E=y.length>0;return f?`${d||A?P(o,[...l,...d&&A?[""]:[],...m]):""}${E&&(d||A)?`
|
|
6
6
|
|
|
7
7
|
`:""}${y.join(`
|
|
8
8
|
|
|
9
|
-
`)}`:P(o,[...l,...d&&(E||A)?[""]:[],...m,...A&&E?[""]:[],...y.flatMap((S,
|
|
9
|
+
`)}`:P(o,[...l,...d&&(E||A)?[""]:[],...m,...A&&E?[""]:[],...y.flatMap((S,Be)=>Be===y.length-1?[S]:[S,""])])}}function ne(e){const t=C(e);return function(r,o){const a=w.includes(r.identifier),i=N.includes(r.identifier),s=Object.keys(r.declarations).length>0,c=r.variables.length>0,u=r.children.length>0,f=K(r.identifier,r.rule);return a||i&&!(s||c||u)?`${f};`:t(f,r,o)}}function re(e){return function(n,r){return n.value.map(o=>e(o,r)).join("").trim()}}function oe(e){return typeof e=="object"&&e!==null}function h(e,t){return oe(e)&&"type"in e&&e.type===t}function ce(e){return h(e,"variable")}function ue(e){return h(e,"reference")}function ie(e){return h(e,"selector")}function ae(e){return h(e,"at-rule")}function se(e){return h(e,"utility")}function le(e){return h(e,"css")}function fe(e){return h(e,"theme")}function V(e){return h(e,"root")}function me(e){return h(e,"recipe")}function pe(e){return e.charAt(0).toUpperCase()+e.slice(1)}function g(e){if(e instanceof Buffer)return Buffer.from(e);const t=e.constructor;return new t(e.buffer.slice(0),e.byteOffset,e.byteLength/e.BYTES_PER_ELEMENT||1)}function de(e){if(e=e||{},e.circular)return ye(e);const t=new Map;if(t.set(Date,i=>new Date(i)),t.set(Map,(i,s)=>new Map(r(Array.from(i),s))),t.set(Set,(i,s)=>new Set(r(Array.from(i),s))),e.constructorHandlers)for(const i of e.constructorHandlers)t.set(i[0],i[1]);let n;return e.proto?a:o;function r(i,s){const c=Object.keys(i),u=Array.from({length:c.length});for(let f=0;f<c.length;f++){const l=c[f],m=i[l];typeof m!="object"||m===null?u[l]=m:m.constructor!==Object&&(n=t.get(m.constructor))?u[l]=n(m,s):ArrayBuffer.isView(m)?u[l]=g(m):u[l]=s(m)}return u}function o(i){if(typeof i!="object"||i===null)return i;if(Array.isArray(i))return r(i,o);if(i.constructor!==Object&&(n=t.get(i.constructor)))return n(i,o);const s={};for(const c in i){if(Object.hasOwnProperty.call(i,c)===!1)continue;const u=i[c];typeof u!="object"||u===null?s[c]=u:u.constructor!==Object&&(n=t.get(u.constructor))?s[c]=n(u,o):ArrayBuffer.isView(u)?s[c]=g(u):s[c]=o(u)}return s}function a(i){if(typeof i!="object"||i===null)return i;if(Array.isArray(i))return r(i,a);if(i.constructor!==Object&&(n=t.get(i.constructor)))return n(i,a);const s={};for(const c in i){const u=i[c];typeof u!="object"||u===null?s[c]=u:u.constructor!==Object&&(n=t.get(u.constructor))?s[c]=n(u,a):ArrayBuffer.isView(u)?s[c]=g(u):s[c]=a(u)}return s}}function ye(e){const t=[],n=[],r=new Map;if(r.set(Date,c=>new Date(c)),r.set(Map,(c,u)=>new Map(a(Array.from(c),u))),r.set(Set,(c,u)=>new Set(a(Array.from(c),u))),e.constructorHandlers)for(const c of e.constructorHandlers)r.set(c[0],c[1]);let o;return e.proto?s:i;function a(c,u){const f=Object.keys(c),l=Array.from({length:f.length});for(let m=0;m<f.length;m++){const y=f[m],d=c[y];if(typeof d!="object"||d===null)l[y]=d;else if(d.constructor!==Object&&(o=r.get(d.constructor)))l[y]=o(d,u);else if(ArrayBuffer.isView(d))l[y]=g(d);else{const A=t.indexOf(d);A!==-1?l[y]=n[A]:l[y]=u(d)}}return l}function i(c){if(typeof c!="object"||c===null)return c;if(Array.isArray(c))return a(c,i);if(c.constructor!==Object&&(o=r.get(c.constructor)))return o(c,i);const u={};t.push(c),n.push(u);for(const f in c){if(Object.hasOwnProperty.call(c,f)===!1)continue;const l=c[f];if(typeof l!="object"||l===null)u[f]=l;else if(l.constructor!==Object&&(o=r.get(l.constructor)))u[f]=o(l,i);else if(ArrayBuffer.isView(l))u[f]=g(l);else{const m=t.indexOf(l);m!==-1?u[f]=n[m]:u[f]=i(l)}}return t.pop(),n.pop(),u}function s(c){if(typeof c!="object"||c===null)return c;if(Array.isArray(c))return a(c,s);if(c.constructor!==Object&&(o=r.get(c.constructor)))return o(c,s);const u={};t.push(c),n.push(u);for(const f in c){const l=c[f];if(typeof l!="object"||l===null)u[f]=l;else if(l.constructor!==Object&&(o=r.get(l.constructor)))u[f]=o(l,s);else if(ArrayBuffer.isView(l))u[f]=g(l);else{const m=t.indexOf(l);m!==-1?u[f]=n[m]:u[f]=s(l)}}return t.pop(),n.pop(),u}}de();function be(e){return function(n,r){return n!=null?`${n}`:""}}function he(e){return function(n,r){const a=(r.variables?.name??v)({name:n.name});return ee(a,n.fallback?e(n.fallback,r):void 0)}}function Ae(e){const t=C(e);return function(r,o){return r.themes.reduce((a,i)=>(a.push(e(i,o)),a),[t(":root",r,o)]).join(`
|
|
10
10
|
|
|
11
|
-
`)}}function ge(e){const t=C(e);return function(r,o){return t(r.query,r,o)}}function Se(e){const t=C(e);return function(r,o){const i=(o.themes?.selector??O)({name:r.name});return t(i,r,o)}}function Ce(e){const t=C(e);return function(r,o){const a=[],s=(o.utilities?.selector
|
|
11
|
+
`)}}function ge(e){const t=C(e);return function(r,o){return t(r.query,r,o)}}function Se(e){const t=C(e);return function(r,o){const i=(o.themes?.selector??O)({name:r.name});return t(i,r,o)}}function Ce(e){const t=C(e);return function(r,o){const a=[],s=(o.utilities?.selector??$)({name:r.name,value:r.value,modifiers:r.modifiers});return a.push(t(s,r,o)),a.join(`
|
|
12
12
|
|
|
13
13
|
`)}}function b(e,t){const n=Ae(b),r=ge(b),o=Ce(b),a=ne(b),i=Se(b),s=k(b),c=he(b),u=re(b),f=be();switch(!0){case ie(e):return r(e,t);case se(e):return o(e,t);case ae(e):return a(e,t);case V(e):return n(e,t);case fe(e):return i(e,t);case ce(e):return s(e,t);case ue(e):return c(e,t);case le(e):return u(e,t);default:return f(e,t)}}function je(e){return function(n,r){let o=U(n.name);n.name[0]&&_(n.name[0])&&(o=pe(o));const a=`${o}Recipe`,i=n._runtime??{};return`const ${a} = ${JSON.stringify(i,null,4)} as const satisfies RecipeRuntime;
|
|
14
14
|
|
|
@@ -25,4 +25,4 @@ dQ8di7mQHz+mCy96jQR4lFSDfHMgl27qaAh5VboTBRxgZliN8D5Fl590QkS94wAj
|
|
|
25
25
|
hC7NbH+hPcGc/qIaZSjZfyZeBIZS74qJkrzjEA7/pukROD8UQUrQ512HHZ6XlgMn
|
|
26
26
|
4bWT2K9CpWbbhsKFTecCHuxlmPkFJNMuvAb/LdP08BSnpntlyAJcQeBrna2qBen+
|
|
27
27
|
GwIDAQAB
|
|
28
|
-
-----END PUBLIC KEY-----`,Re="__licenseRequired",Ee="__licenseValidated";async function we(e){const t=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,""),n=Uint8Array.from(atob(t),r=>r.charCodeAt(0));return await crypto.subtle.importKey("spki",n,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!0,["verify"])}async function Ne({payload:e,signature:t}){const n=new TextEncoder().encode(e),r=Uint8Array.from(atob(t),a=>a.charCodeAt(0)),o=await we(ve);if(!await crypto.subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,r,n))throw new Error("License validation failed: Invalid signature detected. The license may have been modified or corrupted.");return JSON.parse(e)}function Oe(e){return Object.prototype.hasOwnProperty.call(e,Re)}async function
|
|
28
|
+
-----END PUBLIC KEY-----`,Re="__licenseRequired",Ee="__licenseValidated";async function we(e){const t=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,""),n=Uint8Array.from(atob(t),r=>r.charCodeAt(0));return await crypto.subtle.importKey("spki",n,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!0,["verify"])}async function Ne({payload:e,signature:t}){const n=new TextEncoder().encode(e),r=Uint8Array.from(atob(t),a=>a.charCodeAt(0)),o=await we(ve);if(!await crypto.subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,r,n))throw new Error("License validation failed: Invalid signature detected. The license may have been modified or corrupted.");return JSON.parse(e)}function Oe(e){return Object.prototype.hasOwnProperty.call(e,Re)}async function $e(e){const t=Object.getOwnPropertyDescriptor(e,Ee);if(!t?.value)return{key:"",instanceId:"",environment:"",valid:!1};const n=t.value;if(typeof n!="object"||n===null||!("payload"in n)||!("signature"in n)||typeof n.payload!="string"||typeof n.signature!="string")return{key:"",instanceId:"",environment:"",valid:!1};try{return await Ne(n)}catch{return{key:"",instanceId:"",environment:"",valid:!1}}}function Fe(e){const t=Math.floor(Math.random()*100);e.root.children.push({type:"selector",query:`html:nth-of-type(${t}n+1)::after`,variables:[],children:[],declarations:{content:'"Styleframe Pro: Development Mode – License required for production use"',zIndex:99999,position:"fixed",display:"block !important",opacity:"1 !important",bottom:0,left:0,background:"rgba(0, 0, 0, 0.5)",color:"white",fontSize:"12px",lineHeight:"1",padding:"0.5rem",fontFamily:"sans-serif"}})}function R(e,t=""){return{name:e,content:t}}async function Le(e,{type:t="all",consumers:n={css:b,ts:T}}={}){const r={files:[]},o=e.options;if(Oe(e)){const a=await $e(e);(!a.valid||a.instanceId!==e.id)&&Fe(e)}if(t==="all"||t==="css"){const a=R("index.css",n.css(e.root,o));r.files.push(a)}if(t==="all"||t==="ts"){const a=R("index.ts",n.ts(e.root,o));r.files.push(a)}return r}p.DEFAULT_INDENT=" ",p.STATEMENT_AT_RULES=w,p.STATEMENT_OR_BLOCK_AT_RULES=N,p.addIndentToLine=L,p.consumeCSS=b,p.consumeTS=T,p.createFile=R,p.defaultThemeSelectorFn=O,p.defaultUtilitySelectorFn=$,p.defaultVariableNameFn=v,p.indentLines=B,p.isUppercase=_,p.toCamelCase=U,p.toKebabCase=D,p.transpile=Le,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@styleframe/transpiler",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/transpiler.d.ts",
|
|
6
6
|
"module": "./dist/transpiler.js",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"scule": "^1.3.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@styleframe/core": "^2.
|
|
25
|
+
"@styleframe/core": "^2.5.0",
|
|
26
26
|
"@styleframe/license": "^2.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@styleframe/config-typescript": "^2",
|
|
30
30
|
"@styleframe/config-vite": "^2",
|
|
31
|
-
"@styleframe/core": "^2.
|
|
31
|
+
"@styleframe/core": "^2.5.0",
|
|
32
32
|
"@styleframe/license": "^2.0.0",
|
|
33
33
|
"@vitest/coverage-v8": "^3.2.4",
|
|
34
34
|
"typescript": "^5.8.3",
|