vite-plugin-nscriptcss 1.0.0 → 1.0.1
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.js +78 -10
- package/dist/runtime.js +5 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,78 @@
|
|
|
1
|
-
/* © NScriptCSS
|
|
2
|
-
const
|
|
3
|
-
(function(_0xa,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})(_0xstr,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
/* © NScriptCSS Proprietary Binary */
|
|
2
|
+
const _0xarr=["\x73\x74\x61\x74\x65\x2e\x24\x31","\x75\x73\x65\x72\x4a\x73\x2e\x24\x31","\x20","\x73\x74\x61\x74\x65\x2e","\x75\x73\x65\x72\x4a\x73\x2e","\x73\x74\x79\x6c\x65\x2d","\x3c\x64\x69\x76\x3e\x3c\x2f\x64\x69\x76\x3e","\x2f","\x2a","\x7b","\x3b","\x3d","\x40\x74\x65\x6d\x70\x6c\x61\x74\x65","\x22","\x27","\x60","\x5c\x5c","\x7d","\x3a","\x2e\x6e\x73\x63\x73\x73","\x2e\x6e\x63\x73\x73","\x66\x75\x6c\x6c\x2d\x72\x65\x6c\x6f\x61\x64","\x2c","\x24\x7b\x6e\x7d","\x2c\x20","\x40\x73\x74\x61\x74\x65","\x40\x6a\x73"];
|
|
3
|
+
(function(_0xa,_0xb){const _0xr=function(_0xc){while(--_0xc){_0xa.push(_0xa.shift());}};_0xr(++_0xb);})(_0xarr,0x5);
|
|
4
|
+
function _0xstr(_0xi){return _0xarr[_0xi-0x0];}
|
|
5
|
+
function j(e,s){const n=`ncss-${Math.abs(N(s))}`,i=A(e),a=i.userJs,t=i.state,r=i.template,c=i.css;let p="";const h=[],g=b(c);for(const o of g){const l=o.selector.split(_0xstr(0x0)).map(f=>`${f.trim()}[data-ncss=_0xstr(0x1)]`).join(_0xstr(0x2)),d=[],x=[];for(const f of o.properties)if(f.value.includes(_0xstr(0x3))||f.value.includes(_0xstr(0x4))){const w=f.value.replace(/@state\.([a-zA-Z0-9_]+)/g,_0xstr(0x5)).replace(/@js\.([a-zA-Z0-9_]+)/g,_0xstr(0x6)),I=S(f.value);d.push({prop:f.name,exprCode:`(state, userJs) => (${w})`,deps:I})}else x.push(`${f.name}: ${f.value};`);x.length>0&&(p+=`${l} { ${x.join(_0xstr(0x7))} }
|
|
6
|
+
`),(d.length>0||o.events.length>0)&&h.push({selector:l,dynamicProps:d,events:o.events})}const u=[];let m=0;const $=r.replace(/@state\.([a-zA-Z0-9_]+(?:\s*\?\s*[^:]+\s*:\s*[^<\n]+)?)|@js\.([a-zA-Z0-9_]+(?:\([^)]*\))?)/g,o=>{const l=`<!--ncss-binding-${m}-->`,d=o.replace(/@state\.([a-zA-Z0-9_]+)/g,_0xstr(0x5)).replace(/@js\.([a-zA-Z0-9_]+)/g,_0xstr(0x6));return u.push({index:m,exprCode:`(state, userJs) => (${d})`,deps:S(o)}),m++,l}),J=Object.keys(t).map(o=>`${o}: ${t[o]}`).join(`,
|
|
7
|
+
`),v=h.map(o=>`{
|
|
8
|
+
selector: ${JSON.stringify(o.selector)},
|
|
9
|
+
dynamicProps: [${o.dynamicProps.map(l=>`{ prop: ${JSON.stringify(l.prop)}, fn: ${l.exprCode}, deps: ${JSON.stringify(l.deps)} }`).join(_0xstr(0x2))}],
|
|
10
|
+
events: [${o.events.map(l=>`{ event: ${JSON.stringify(l.event)}, fn: (state, userJs, event) => { ${l.code.replace(/@state\./g,_0xstr(0x8)).replace(/@js\./g,_0xstr(0x9))} } }`).join(_0xstr(0x2))}]
|
|
11
|
+
}`).join(`,
|
|
12
|
+
`),C=u.map(o=>`{
|
|
13
|
+
index: ${o.index},
|
|
14
|
+
fn: ${o.exprCode},
|
|
15
|
+
deps: ${JSON.stringify(o.deps)}
|
|
16
|
+
}`).join(`,
|
|
17
|
+
`);return{code:`
|
|
18
|
+
import { createNScriptRuntime } from 'vite-plugin-nscriptcss/runtime';
|
|
19
|
+
|
|
20
|
+
// C\xF3digo JS definido en @js (Aislado en closure)
|
|
21
|
+
const userJs = (function() {
|
|
22
|
+
const exports = {};
|
|
23
|
+
${a}
|
|
24
|
+
return { ...exports, ...((function() {
|
|
25
|
+
try { return { ${k(a)} }; } catch(e) { return {}; }
|
|
26
|
+
})()) };
|
|
27
|
+
})();
|
|
28
|
+
|
|
29
|
+
export const componentId = ${JSON.stringify(n)};
|
|
30
|
+
export const staticCss = ${JSON.stringify(p)};
|
|
31
|
+
export const rawTemplate = ${JSON.stringify($)};
|
|
32
|
+
|
|
33
|
+
// Reglas y suscripciones compiladas AOT (Cero eval en runtime)
|
|
34
|
+
export const dynamicRules = [
|
|
35
|
+
${v}
|
|
36
|
+
];
|
|
37
|
+
export const templateBindings = [
|
|
38
|
+
${C}
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
export function createInstance(options = {}) {
|
|
42
|
+
const initialState = {
|
|
43
|
+
${J}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return createNScriptRuntime({
|
|
47
|
+
componentId,
|
|
48
|
+
initialState,
|
|
49
|
+
rawTemplate,
|
|
50
|
+
dynamicRules,
|
|
51
|
+
templateBindings,
|
|
52
|
+
staticCss,
|
|
53
|
+
userJs
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const defaultInstance = {
|
|
58
|
+
mount(target) {
|
|
59
|
+
const inst = createInstance();
|
|
60
|
+
return inst.mount(target);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export default defaultInstance;
|
|
64
|
+
|
|
65
|
+
if (import.meta.hot) {
|
|
66
|
+
import.meta.hot.accept((newModule) => {
|
|
67
|
+
if (newModule) {
|
|
68
|
+
const existingStyle = document.getElementById(_0xstr(0xa) + componentId);
|
|
69
|
+
if (existingStyle) existingStyle.textContent = newModule.staticCss;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
`,css:p}}function A(e){let s="",n=_0xstr(0xb);const i={};let a="",t=0;const r=e.length;for(;t<r;){if(e[t]===_0xstr(0xc)&&e[t+1]===_0xstr(0xc)){for(;t<r&&e[t]!==`
|
|
74
|
+
`;)t++;continue}if(e[t]===_0xstr(0xc)&&e[t+1]===_0xstr(0xd)){for(t+=2;t<r&&!(e[t]===_0xstr(0xd)&&e[t+1]===_0xstr(0xc));)t++;t+=2;continue}if(e.startsWith(_0xstr(0x4),t)){for(t+=3;t<r&&/\s/.test(e[t])&&e[t]!==_0xstr(0xe)&&e[t]!==`
|
|
75
|
+
`;)t++;if(e[t]===_0xstr(0xe)){const c=y(e,t);s+=c.content+`
|
|
76
|
+
`,t=c.endIndex}else{let c="";for(;t<r&&e[t]!==`
|
|
77
|
+
`;)c+=e[t],t++;s+=c.trim()+`
|
|
78
|
+
`}continue}if(e.startsWith(_0xstr(0x3),t)){t+=6;let c="";for(;t<r&&e[t]!==_0xstr(0xf);)c+=e[t],t++;t++;const p=c.split(_0xstr(0x10));p.length===2&&(i[p[0].trim()]=p[1].trim());continue}if(e.startsWith(_0xstr(0x11),t)){for(t+=9;t<r&&e[t]!==_0xstr(0xe);)t++;const c=y(e,t);n=c.content.trim(),t=c.endIndex;continue}a+=e[t],t++}return{userJs:s,state:i,template:n,css:a}}function y(e,s){let n=0,i=null,a=-1;for(let t=s;t<e.length;t++){const r=e[t];if(!i&&(r===_0xstr(0x12)||r===_0xstr(0x13)||r===_0xstr(0x14))){i=r;continue}if(i&&r===i&&e[t-1]!==_0xstr(0x15)){i=null;continue}if(!i){if(r===_0xstr(0xe))n++,n===1&&(a=t+1);else if(r===_0xstr(0x16)&&(n--,n===0))return{content:e.substring(a,t),endIndex:t+1}}}return{content:"",endIndex:e.length}}function b(e){const s=[];let n=0;const i=e.length;for(;n<i;){if(/\s/.test(e[n])){n++;continue}let a="";for(;n<i&&e[n]!==_0xstr(0xe);)a+=e[n],n++;if(n>=i)break;const t=y(e,n);n=t.endIndex;const r=t.content,c=[],p=[],g=r.replace(/@on\s+([a-zA-Z]+)\s*\{([\s\S]*?)\}/g,(u,m,$)=>(p.push({event:m.trim(),code:$.trim()}),"")).split(_0xstr(0xf)).map(u=>u.trim()).filter(Boolean);for(const u of g){const m=u.indexOf(_0xstr(0x17));m!==-1&&c.push({name:u.substring(0,m).trim(),value:u.substring(m+1).trim()})}a.trim()&&s.push({selector:a.trim(),properties:c,events:p})}return s}function S(e){const s=[...e.matchAll(/@state\.([a-zA-Z0-9_]+)/g)];return[...new Set(s.map(n=>n[1]))]}function N(e){let s=0;for(let n=0;n<e.length;n++)s=(s<<5)-s+e.charCodeAt(n),s|=0;return s}function k(e){return[...e.matchAll(/(?:const|let|var|function)\s+([a-zA-Z0-9_]+)/g)].map(n=>n[1]).join(_0xstr(0x2))}function B(e={}){return{name:"vite-plugin-nscriptcss",enforce:"pre",transform(s,n){if(!n.endsWith(_0xstr(0x18))&&!n.endsWith(_0xstr(0x19)))return null;try{const{code:i}=j(s,n);return{code:i,map:null}}catch(i){this.error(`[NScriptCSS Compiler Error] en ${n}: ${i.message}`)}},handleHotUpdate({file:s,server:n}){(s.endsWith(_0xstr(0x18))||s.endsWith(_0xstr(0x19)))&&n.ws.send({type:_0xstr(0x1a)})}}}var Z=B;export{Z as default,B as nscriptcss};
|
package/dist/runtime.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
/* © NScriptCSS
|
|
2
|
-
const
|
|
3
|
-
(function(_0xa,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})(_0xstr, 0x8);
|
|
7
|
-
function _0xget(_0xi) { return _0xstr[_0xi - 0x0]; }
|
|
8
|
-
function _0xtamper() { return (function(){}).constructor("return this")(); }
|
|
9
|
-
|
|
10
|
-
export function createNScriptRuntime({_0xa0_w2n9,initialState,_0xa2_4250,_0xa3_toqn,_0xa4_bgk8,userJs,}){let _0xb1_t5w1=null let state={...initialState}let _0xb2_q4uv=null let styleTag=document.getElementById(_0xget(0x0)+_0xa0_w2n9) if (!styleTag){styleTag=document.createElement(_0xget(0x1)) styleTag.id=_0xget(0x0)+_0xa0_w2n9 document.head.appendChild(styleTag)}styleTag.textContent=_0xa4_bgk8 function render(root){for (const rule of _0xa3_toqn){const elements=root.querySelectorAll(rule.selector) for (const dyn of rule._0xa9_55zm){try{const evalFn=new Function( _0xget(0x2),_0xget(0x3),`_0xget(0x4);return (${dyn.expr});`,) const val=evalFn(state,userJs) elements.forEach((el)=>{el.style[_0xb5_u9d1(dyn.prop)]=val})}catch (e){}}}const textNodes=_0xb4_pvnq(root) for (const node of textNodes){if (!node._tpl) node._tpl=node.nodeValue let text=node._tpl text=text.replace(/@state\.([a-zA-Z0-9_]+(?:\s*\?\s*[^:]+\s*:\s*[^;\n]+)?)/g,(_,match)=>{try{return new Function( _0xget(0x2),_0xget(0x3),`_0xget(0x4);return (${match});`,)(state,userJs)}catch{return _0xget(0x5)}},) text=text.replace(/@js\.([a-zA-Z0-9_]+(?:\([^)]*\))?)/g,(_,match)=>{try{return new Function( _0xget(0x3),`_0xget(0x4);return userJs.${match};`,)(userJs)}catch{return _0xget(0x5)}}) if (node.nodeValue !==text) node.nodeValue=text}}function _0xb3_2r0x(root){for (const rule of _0xa3_toqn){if (!rule.events) continue const elements=root.querySelectorAll(rule.selector) elements.forEach((el)=>{for (const evt of rule.events){el.addEventListener(evt.event,(e)=>{try{const code=evt.code .replace(/@state\./g,_0xget(0x6)) .replace(/@js\./g,_0xget(0x7)) const run=new Function( _0xget(0x2),_0xget(0x3),_0xget(0x8),`_0xget(0x4);\n${code}`,) run(_0xb2_q4uv,userJs,e)}catch (err){console.error(`Error ejecutando @on ${evt.event}:`,err)}})}})}}return{mount(targetSelectorOrEl){const target=typeof targetSelectorOrEl===_0xget(0x9) ? document.querySelector(targetSelectorOrEl):targetSelectorOrEl if (!target) throw new Error( `[NScriptCSS] No se encontró el contenedor:${targetSelectorOrEl}`,) const wrapper=document.createElement(_0xget(0xa)) wrapper.setAttribute(_0xget(0xb),_0xa0_w2n9) wrapper.innerHTML=_0xa2_4250 wrapper .querySelectorAll(_0xget(0xc)) .forEach((el)=>el.setAttribute(_0xget(0xb),_0xa0_w2n9)) _0xb1_t5w1=wrapper target.appendChild(wrapper) _0xb2_q4uv=new Proxy(state,{set(t,p,v){t[p]=v render(_0xb1_t5w1) return true},}) _0xb3_2r0x(_0xb1_t5w1) render(_0xb1_t5w1) return{state:_0xb2_q4uv,unmount(){if (_0xb1_t5w1) _0xb1_t5w1.remove()},}},}}function _0xb5_u9d1(str){return str.replace(/-([a-z])/g,(g)=>g[1].toUpperCase())}function _0xb4_pvnq(node){let list=[] if (node.nodeType===3) list.push(node) else node.childNodes.forEach((c)=>(list=list.concat(_0xb4_pvnq(c)))) return list}
|
|
1
|
+
/* © NScriptCSS Proprietary Binary */
|
|
2
|
+
const _0xarr=["\x2a","\x6e\x63\x73\x73\x2d\x62\x69\x6e\x64\x69\x6e\x67\x2d","\x73\x74\x79\x6c\x65\x2d","\x73\x74\x79\x6c\x65","\x73\x74\x72\x69\x6e\x67","\x64\x69\x76","\x64\x61\x74\x61\x2d\x6e\x63\x73\x73"];
|
|
3
|
+
(function(_0xa,_0xb){const _0xr=function(_0xc){while(--_0xc){_0xa.push(_0xa.shift());}};_0xr(++_0xb);})(_0xarr,0x5);
|
|
4
|
+
function _0xstr(_0xi){return _0xarr[_0xi-0x0];}
|
|
5
|
+
function M({componentId:c,initialState:p,rawTemplate:x,dynamicRules:g,templateBindings:b,staticCss:w,userJs:m}){let h=null;const v={...p};let a=null;const d=new Map;function N(o,i){d.has(o)||d.set(o,new Set),d.get(o).add(i)}function S(o){d.has(o)&&d.get(o).forEach(i=>i())}let l=document.getElementById(_0xstr(0x0)+c);return l||(l=document.createElement(_0xstr(0x1)),l.id=_0xstr(0x0)+c,document.head.appendChild(l)),l.textContent=w,{mount(o){const i=typeof o==_0xstr(0x2)?document.querySelector(o):o;if(!i)throw new Error(`[NScriptCSS] Contenedor no encontrado: ${o}`);const s=document.createElement(_0xstr(0x3));s.setAttribute(_0xstr(0x4),c),s.innerHTML=x,s.querySelectorAll(_0xstr(0x5)).forEach(e=>e.setAttribute(_0xstr(0x4),c)),h=s,i.appendChild(s),a=new Proxy(v,{set(e,n,t){return e[n]===t||(e[n]=t,S(n)),!0}});for(const e of g){const n=s.querySelectorAll(e.selector);for(const t of e.dynamicProps){const r=()=>{const u=t.fn(a,m),E=A(t.prop);for(let y=0;y<n.length;y++)n[y].style[E]=u};r();for(const u of t.deps)N(u,r)}for(const t of e.events)for(let r=0;r<n.length;r++)n[r].addEventListener(t.event,u=>{t.fn(a,m,u)})}const T=document.createTreeWalker(s,NodeFilter.SHOW_COMMENT),C=[];let f;for(;f=T.nextNode();){const e=f.nodeValue;if(e.startsWith(_0xstr(0x6))){const n=parseInt(e.replace(_0xstr(0x6),"")),t=document.createTextNode("");f.parentNode.replaceChild(t,f),C[n]=t}}for(const e of b){const n=C[e.index];if(!n)continue;const t=()=>{n.nodeValue=e.fn(a,m)};t();for(const r of e.deps)N(r,t)}return{state:a,unmount(){d.clear(),h&&h.remove()}}}}}function A(c){return c.replace(/-([a-z])/g,p=>p[1].toUpperCase())}export{M as createNScriptRuntime};
|
package/package.json
CHANGED