@fluixi/compiler 1.0.0-alpha.82 → 1.0.0-alpha.83
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/analyze/static-graph.cjs +1 -0
- package/dist/analyze/static-graph.d.ts +103 -0
- package/dist/analyze/static-graph.d.ts.map +1 -0
- package/dist/analyze/static-graph.js +869 -0
- package/dist/analyze/static-graph.mjs +1 -0
- package/dist/{babel-4JUDAR2G.mjs → babel-VXKH6MRQ.mjs} +1 -1
- package/dist/chunk-5KMMN5QP.mjs +1 -0
- package/dist/chunk-YKZ54NVE.mjs +1 -0
- package/dist/codegen/backends/imperative.cjs +1 -1
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +62 -11
- package/dist/codegen/backends/imperative.mjs +1 -1
- package/dist/codegen/partial-template.cjs +1 -1
- package/dist/codegen/partial-template.mjs +1 -1
- package/dist/codegen/serialize-static.cjs +1 -1
- package/dist/codegen/serialize-static.d.ts +16 -0
- package/dist/codegen/serialize-static.d.ts.map +1 -1
- package/dist/codegen/serialize-static.js +25 -0
- package/dist/codegen/serialize-static.mjs +1 -1
- package/dist/frontend/babel/build-ir-lit.cjs +1 -1
- package/dist/frontend/babel/build-ir-lit.mjs +1 -1
- package/dist/frontend/babel/build-ir.cjs +1 -1
- package/dist/frontend/babel/build-ir.mjs +1 -1
- package/dist/frontend/babel/index.cjs +1 -1
- package/dist/frontend/babel/index.mjs +1 -1
- package/dist/frontend/babel/lower-template.cjs +1 -1
- package/dist/frontend/babel/lower-template.mjs +1 -1
- package/dist/frontend/babel/plugin.cjs +1 -1
- package/dist/frontend/babel/plugin.mjs +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.mjs +8 -8
- package/dist/integrations.cjs +18 -18
- package/dist/integrations.d.ts +16 -0
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +21 -2
- package/dist/integrations.mjs +5 -5
- package/dist/ir/nodes.cjs +1 -1
- package/dist/ir/nodes.d.ts +46 -0
- package/dist/ir/nodes.d.ts.map +1 -1
- package/dist/lower/compile-template.cjs +1 -1
- package/dist/lower/compile-template.d.ts +12 -0
- package/dist/lower/compile-template.d.ts.map +1 -1
- package/dist/lower/compile-template.js +5 -1
- package/dist/lower/compile-template.mjs +1 -1
- package/dist/lower/jsx.cjs +1 -1
- package/dist/lower/jsx.d.ts +2 -0
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +25 -3
- package/dist/lower/jsx.mjs +1 -1
- package/dist/lower/template.cjs +1 -1
- package/dist/lower/template.d.ts +14 -1
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +101 -15
- package/dist/lower/template.mjs +1 -1
- package/dist/transform/index.cjs +5 -5
- package/dist/transform/index.mjs +12 -12
- package/dist/transform/source-locations.cjs +1 -0
- package/dist/transform/source-locations.d.ts +44 -0
- package/dist/transform/source-locations.d.ts.map +1 -0
- package/dist/transform/source-locations.js +238 -0
- package/dist/transform/source-locations.mjs +1 -0
- package/dist/transform/templates.cjs +4 -4
- package/dist/transform/templates.d.ts +12 -4
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +72 -7
- package/dist/transform/templates.mjs +11 -11
- package/dist/transform-C4ZXRVGP.mjs +8 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/chunk-PVR2SN3B.mjs +0 -1
- package/dist/chunk-QUIYULS2.mjs +0 -1
- package/dist/chunk-YR3SAEO7.mjs +0 -1
- package/dist/transform-5WC4FWJE.mjs +0 -8
package/dist/integrations.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as C,f as M,g as h}from"./chunk-5KMMN5QP.mjs";import{a as j}from"./chunk-3SAEGOMQ.mjs";import{mkdirSync as U,readFileSync as w,writeFileSync as X}from"node:fs";import{dirname as E,relative as F,sep as k,resolve as b}from"node:path";var V=new Set(["Text","Image","Option","Audio","Comment","Range","Selection","Notification","Event","Document","Element","Node","Screen","Window","Location","History","Storage","Response","Request","Headers"]);function H(e){if(e.startsWith(".")||e.startsWith("/")||/^[~@]\//.test(e))return;let t=e.split("/");return e.startsWith("@")?t.slice(0,2).join("/"):t[0]}function x(e){return`_${e.replace(/[^A-Za-z0-9]/g,"_")}`}function O(e,t={}){let{available:n,builtins:s=!0,intrinsics:r=!0,generator:i="@fluixi/compiler",specifier:a=o=>o}=t,l=[...e];s&&l.push({components:M()});let c=C(l),d=n?new Set(n):void 0,p=[],f=[],S=[],y=new Map;for(let o of[...c.names()].sort()){let u=c.resolve(o);if(!u)continue;let m=H(u.module);V.has(o)?f.push(o):d&&m&&!d.has(m)?S.push(o):(p.push(o),y.set(o,u))}let N=r?[...new Set(Object.values(h).map(o=>o.module))]:[],T=[...new Set([...p.map(o=>y.get(o).module),...N])].sort().map(o=>`import * as ${x(o)} from '${a(o)}';`),_=p.map(o=>{let u=y.get(o),m=x(u.module);return u.export==="default"?` const ${o}: typeof ${m}.default;`:` export import ${o} = ${m}.${u.export};`}),B=f.length>0?`//
|
|
2
2
|
// Import these explicitly — lib.dom already declares the name, so an ambient
|
|
3
3
|
// declaration cannot win:
|
|
4
4
|
`+f.map(o=>{let u=c.resolve(o)?.module;return`// import { ${o} } from '${u?a(u):""}';
|
|
@@ -16,12 +16,12 @@ ${T.join(`
|
|
|
16
16
|
`:`
|
|
17
17
|
`)+`
|
|
18
18
|
declare global {
|
|
19
|
-
${[...
|
|
19
|
+
${[..._,...J].join(`
|
|
20
20
|
`)}
|
|
21
21
|
}
|
|
22
|
-
`,declared:p,shadowedByDom:f,unavailable:
|
|
23
|
-
imported by ${n}`:""))},async transform(t,n){if(!/\.(jsx|tsx|ts)$/i.test(n))return null;if(!e.babel)return v(t,n,e);let s=await $(e);try{let r=await import("@babel/core").catch(()=>null);if(!r)throw new Error(`[fluixi] @babel/core is required to compile ${n} but could not be loaded. Install it alongside @fluixi/compiler.`);let i=/\.tsx$/.test(n),a=/\.ts$/.test(n),l=[],c=[];if(i||a){let p=await import("@babel/preset-typescript").then(f=>f.default||f).catch(()=>null);p&&l.push([p,{isTSX:i,allExtensions:!0,jsxPragma:"jsx",jsxPragmaFrag:"Fragment",onlyRemoveTypeImports:!0}])}s&&s.plugin?c.push([s.plugin,s.getOptions()]):console.warn("[createVitePlugin] custom babel plugin not found");let d=await r.transformAsync(t,{filename:n,configFile:!1,babelrc:!1,presets:l,plugins:c,sourceMaps:e.sourceMaps!==!1});return{code:d?.code||t,map:d?.map}}catch(r){throw r}}}}function oe(e){return{resolve:e.resolve,litTag:e.litTag,templateClone:e.templateClone,partialTemplates:e.partialTemplates,runtimeModule:e.signalModule,controlFlowModule:e.controlFlowModule,routerModule:e.routerModule,reactiveModule:e.reactiveModule,propsDestructure:e.propsDestructure}}async function
|
|
22
|
+
`,declared:p,shadowedByDom:f,unavailable:S,patternRules:g}}var z="GENERATED by @fluixi/compiler",K="fluixi.d.ts";function Z(e,t){let n;try{let r=w(b(e,"tsconfig.json"),"utf8");n=JSON.parse(r.replace(/^\s*\/\/.*$/gm,""))}catch{return}if(n.extends!==void 0)return;if(!Array.isArray(n.include))return!0;let s=A(e,t);return n.include.some(r=>{if(typeof r!="string")return!1;let i=r.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*\//g,"(?:.*/)?").replace(/\*/g,"[^/]*");return new RegExp(`^${i}(?:/.*)?$`).test(s)})}function A(e,t){return F(e,t).split(k).join("/")}function Q(e,t,n){if(!e.startsWith("/"))return e;let s=b(n,e.slice(1)),r=F(t,s).split(k).join("/");return r.startsWith(".")||(r=`./${r}`),r.replace(/\.(tsx|ts|jsx|mts|cts)$/,".js")}function Y(e){try{let t=JSON.parse(w(b(e,"package.json"),"utf8"));return[...Object.keys(t.dependencies??{}),...Object.keys(t.devDependencies??{}),...Object.keys(t.peerDependencies??{})]}catch{return}}function G(e,t){if(e.globals===!1)return{status:"skipped",reason:"disabled"};let n=e.resolve??[],s=b(t,e.globals??K),r;try{r=w(s,"utf8")}catch{r=void 0}if(r!==void 0&&!r.includes(z))return{status:"skipped",reason:"foreign-file",path:s};let{source:i,declared:a}=O(n,{available:Y(t),specifier:l=>Q(l,E(s),t)});return r===i?{status:"unchanged",path:s,declared:a.length,warning:D(t,s)}:(U(E(s),{recursive:!0}),X(s,i),{status:"written",path:s,declared:a.length,warning:D(t,s)})}function D(e,t){if(Z(e,t)!==!1)return;let n=A(e,t);return`[fluixi] ${n} is not covered by "include" in tsconfig.json, so TypeScript will ignore it and every resolved component stays "Cannot find name". Add "${n}" to "include".`}import{readdirSync as pe,readFileSync as fe}from"node:fs";import{join as I}from"node:path";async function $(e={}){let t=null;try{t=await import("./babel-VXKH6MRQ.mjs")}catch(n){console.warn("Could not load the babel front-end:",n)}return{name:"babel-fluixi-jsx",plugin:t?t.default||t:null,getOptions(){return{importSource:e.importSource||"@fluixi/jsx",development:e.development||!1,delegateEvents:e.delegateEvents!==!1,...e.format?{format:e.format}:{},...e.resolve?{resolve:e.resolve}:{},...e.templateClone!==void 0?{templateClone:e.templateClone}:{},...e.partialTemplates!==void 0?{partialTemplates:e.partialTemplates}:{},...e.litTag?{litTag:e.litTag}:{},...e.signalModule?{signalModule:e.signalModule}:{},...e.controlFlowModule?{controlFlowModule:e.controlFlowModule}:{},...e.routerModule?{routerModule:e.routerModule}:{},...e.reactiveModule?{reactiveModule:e.reactiveModule}:{}}}}}function ee(e={}){let t=ne("typescript");return t?n=>{let s=r=>t.isJsxElement(r)||t.isJsxSelfClosingElement(r)?te(r,e,t):t.visitEachChild(r,s,n);return r=>t.visitNode(r,s)}:(console.warn("TypeScript not found, transformer unavailable"),n=>s=>s)}function te(e,t,n){return e}function ne(e){try{return j(e)}catch{return null}}var re={"@fluixi/core/router-next":"is now @fluixi/core/router","@fluixi/core/rx":"is gone — import signals and effects from @fluixi/reactive, or the server primitives it resolved to under node from @fluixi/core/server"};function se(e={}){return{name:"vite-fluixi-jsx",enforce:"pre",config(){return{esbuild:{jsx:"automatic",jsxImportSource:e.importSource||"@fluixi/jsx"}}},configResolved(t){let n=G(e,t?.root??process.cwd());n.warning&&console.warn(n.warning)},resolveId(t,n){let s=re[t];if(!s)return null;throw new Error(`[fluixi] ${t} ${s}`+(n?`
|
|
23
|
+
imported by ${n}`:""))},async transform(t,n){if(!/\.(jsx|tsx|ts)$/i.test(n))return null;if(!e.babel)return v(t,n,e);let s=await $(e);try{let r=await import("@babel/core").catch(()=>null);if(!r)throw new Error(`[fluixi] @babel/core is required to compile ${n} but could not be loaded. Install it alongside @fluixi/compiler.`);let i=/\.tsx$/.test(n),a=/\.ts$/.test(n),l=[],c=[];if(i||a){let p=await import("@babel/preset-typescript").then(f=>f.default||f).catch(()=>null);p&&l.push([p,{isTSX:i,allExtensions:!0,jsxPragma:"jsx",jsxPragmaFrag:"Fragment",onlyRemoveTypeImports:!0}])}s&&s.plugin?c.push([s.plugin,s.getOptions()]):console.warn("[createVitePlugin] custom babel plugin not found");let d=await r.transformAsync(t,{filename:n,configFile:!1,babelrc:!1,presets:l,plugins:c,sourceMaps:e.sourceMaps!==!1});return{code:d?.code||t,map:d?.map}}catch(r){throw r}}}}function oe(e,t){if(e.sourceLocations!==!0)return!1;if(e.sourceLocationsExternal)return!0;if(!t||t.includes("/node_modules/"))return!1;let n=e.sourceRoot;if(!n)return!0;let s=n.endsWith("/")?n:`${n}/`;return t.startsWith(s)}function ie(e,t){return{resolve:e.resolve,litTag:e.litTag,sourceLocations:oe(e,t),sourceRoot:e.sourceRoot,templateClone:e.templateClone,partialTemplates:e.partialTemplates,runtimeModule:e.signalModule,controlFlowModule:e.controlFlowModule,routerModule:e.routerModule,reactiveModule:e.reactiveModule,propsDestructure:e.propsDestructure}}async function ae(e,t,n){if(n.propsDestructure===!1)return e;let{transformProps:s}=await import("./transform-C4ZXRVGP.mjs"),r=s(e,t);return P({propsDiagnostics:r.diagnostics},t),r.rewritten>0?r.code:e}var L=new Set;function P(e,t){let n=e,s=r=>{let i=`${t}\0${r}`;L.has(i)||(L.add(i),console.warn(`[fluixi] ${t}: ${r}`))};for(let r of n?.unresolvedDiagnostics??[])s(r.message);for(let r of n?.loadDiagnostics??[])s(r.message);for(let r of n?.intrinsicDiagnostics??[])s(r.message);for(let r of n?.propsDiagnostics??[])s(`\`${r.name}\` was left destructured: ${r.message}. It reads once instead of tracking.`)}async function v(e,t,n){if(!n.babel){let{transformTemplates:l}=await import("./transform-C4ZXRVGP.mjs"),c=l(e,t,ie(n,t));return P(c,t),c}let s=await ae(e,t,n),r=await import("@babel/core").catch(()=>null),i=await $(n);if(!r||!i.plugin)throw new Error(`[fluixi] babel: true needs @babel/core, which could not be loaded for ${t}. Install it, or drop the option to use the built-in compiler.`);let a=await r.transformAsync(s,{filename:t,configFile:!1,babelrc:!1,plugins:[[i.plugin,i.getOptions()]],sourceMaps:n.sourceMaps!==!1});return a?.code?{code:a.code,map:a.map}:null}function le(e={}){return async function(t){let n=this.async();v(t,this.resourcePath,e).then(s=>{n(null,s?.code,s?.map)}).catch(s=>{n(s)})}}function ue(e={}){return{name:"rollup-fluixi-jsx",async transform(t,n){return/\.[jt]sx?$/.test(n)?v(t,n,e):null}}}function ce(e={}){return{name:"esbuild-fluixi-jsx",setup(t){t.onLoad({filter:/\.[jt]sx?$/},async n=>{let{readFileSync:s}=await import("node:fs"),r=s(n.path,"utf8");try{return{contents:(await v(r,n.path,e))?.code??r,loader:n.path.endsWith("x")?"tsx":"ts"}}catch(i){return{errors:[{text:`Transform error: ${i}`}]}}})}}}var R="virtual:fluixi-server-fns";function W(e,t=[]){let n;try{n=pe(e,{withFileTypes:!0})}catch{return t}for(let s of n){if(s.name==="node_modules"||s.name==="dist"||s.name.startsWith("."))continue;let r=I(e,s.name);if(s.isDirectory())W(r,t);else if(/\.[jt]sx?$/.test(s.name))try{fe(r,"utf8").includes("use server")&&t.push(r)}catch{}}return t}function je(e={}){let t=process.cwd();return{name:"fluixi-server-functions",enforce:"pre",configResolved(n){t=n.root||t},resolveId(n){return n===R||n==="@fluixi/start/server-fns"?"\0"+R:null},load(n){if(n!=="\0"+R)return null;let s=W(I(t,"src")),r=`import '@fluixi/start/server-fn-setup';
|
|
24
24
|
`,i=s.map(l=>`import ${JSON.stringify(l)};`).join(`
|
|
25
25
|
`);return r+i+`
|
|
26
26
|
export { isServerFnRequest, handleServerFn } from '@fluixi/start/server-fn';
|
|
27
|
-
`},async transform(n,s,r){if(!/\.[jt]sx?$/.test(s)||!n.includes("use server"))return null;let i={ssr:!!r?.ssr,filename:s,root:t};if(e.babel){let{transformServerFunctions:l}=await import("./server-functions-E3LKCZ4R.mjs");return l(n,i)}let{transformServerFns:a}=await import("./server-fns-6QM243HC.mjs");return a(n,i)}}}var
|
|
27
|
+
`},async transform(n,s,r){if(!/\.[jt]sx?$/.test(s)||!n.includes("use server"))return null;let i={ssr:!!r?.ssr,filename:s,root:t};if(e.babel){let{transformServerFunctions:l}=await import("./server-functions-E3LKCZ4R.mjs");return l(n,i)}let{transformServerFns:a}=await import("./server-fns-6QM243HC.mjs");return a(n,i)}}}var Ce={createBabelPlugin:$,createTypeScriptTransformer:ee,createVitePlugin:se,createWebpackLoader:le,createRollupPlugin:ue,createESBuildPlugin:ce};export{$ as createBabelPlugin,ce as createESBuildPlugin,ue as createRollupPlugin,ee as createTypeScriptTransformer,se as createVitePlugin,le as createWebpackLoader,Ce as default,je as serverFunctionsVitePlugin};
|
package/dist/ir/nodes.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=Object.defineProperty;var
|
|
1
|
+
"use strict";var t=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var c=(o,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of l(e))!p.call(o,n)&&n!==i&&t(o,n,{get:()=>e[n],enumerable:!(r=a(e,n))||r.enumerable});return o};var s=o=>c(t({},"__esModule",{value:!0}),o);var d={};module.exports=s(d);
|
package/dist/ir/nodes.d.ts
CHANGED
|
@@ -10,6 +10,14 @@ export interface SourceSpan {
|
|
|
10
10
|
start: number;
|
|
11
11
|
end: number;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Where a hole was written. Carried as data because the source map cannot say: a template is
|
|
15
|
+
* emitted as one overwrite, so every hole in it traces back to the line the root opens at.
|
|
16
|
+
*/
|
|
17
|
+
export interface HolePosition {
|
|
18
|
+
line: number;
|
|
19
|
+
column: number;
|
|
20
|
+
}
|
|
13
21
|
export type IRNode = IRElement | IRComponent | IRText | IRExpression | IRControl | IRFragment;
|
|
14
22
|
export type IRPropKind = 'attr' | 'prop' | 'event' | 'ref' | 'class' | 'style' | 'spread';
|
|
15
23
|
export interface IRProp {
|
|
@@ -25,6 +33,14 @@ export interface IRProp {
|
|
|
25
33
|
expr?: string;
|
|
26
34
|
/** When true, `expr` must be wired reactively (emitted as a `() => expr` thunk). */
|
|
27
35
|
reactive?: boolean;
|
|
36
|
+
/** Where the expression was written. Only kept when the host asked for source locations. */
|
|
37
|
+
at?: HolePosition;
|
|
38
|
+
/**
|
|
39
|
+
* The directive this prop was written as, when it is not recoverable at runtime.
|
|
40
|
+
* `bind:value` becomes an ordinary value plus an input handler, and nothing downstream
|
|
41
|
+
* could tell it from the two written by hand.
|
|
42
|
+
*/
|
|
43
|
+
directive?: string;
|
|
28
44
|
/**
|
|
29
45
|
* `expr` is an inline JSX element/fragment passed as a component prop (e.g.
|
|
30
46
|
* `<Suspense fallback={<div/>}>`). Emitted as a LAZY getter — like children — so the DOM is
|
|
@@ -46,6 +62,16 @@ export interface IRElement {
|
|
|
46
62
|
children: IRNode[];
|
|
47
63
|
/** analyze/statics: subtree has no dynamic parts → hoistable (template-clone) */
|
|
48
64
|
static: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Where the tag was written, when the transform was asked for source locations. A
|
|
67
|
+
* template is emitted as one string, so this is the only record of where each element in
|
|
68
|
+
* it came from.
|
|
69
|
+
*/
|
|
70
|
+
at?: {
|
|
71
|
+
file: string;
|
|
72
|
+
line: number;
|
|
73
|
+
column: number;
|
|
74
|
+
};
|
|
49
75
|
loc?: SourceSpan;
|
|
50
76
|
}
|
|
51
77
|
/**
|
|
@@ -88,6 +114,22 @@ export interface IRComponent {
|
|
|
88
114
|
* claims it, which is a diagnostic rather than a resolution.
|
|
89
115
|
*/
|
|
90
116
|
source?: IRComponentSource;
|
|
117
|
+
/**
|
|
118
|
+
* Where the tag was written, when the transform was asked for source locations. Distinct
|
|
119
|
+
* from `source`, which says where the component reference was resolved from.
|
|
120
|
+
*/
|
|
121
|
+
at?: {
|
|
122
|
+
file: string;
|
|
123
|
+
line: number;
|
|
124
|
+
column: number;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Where the `${…}` that drives this subtree was written — the condition of an `if=`,
|
|
128
|
+
* the list of an `each=`. The insert that adds and removes the subtree is a reactive
|
|
129
|
+
* binding, and this is the position it reports. Distinct from `at`, which marks the
|
|
130
|
+
* node itself rather than the binding that places it.
|
|
131
|
+
*/
|
|
132
|
+
bindAt?: HolePosition;
|
|
91
133
|
/**
|
|
92
134
|
* A `load:` strategy read off the tag by the frontend. The resolve pass folds it into
|
|
93
135
|
* `source.loading`; it lives here first because the frontend knows the directive and
|
|
@@ -106,6 +148,8 @@ export interface IRExpression {
|
|
|
106
148
|
code: string;
|
|
107
149
|
reactive: boolean;
|
|
108
150
|
loc?: SourceSpan;
|
|
151
|
+
/** Where the expression was written. Only kept when the host asked for source locations. */
|
|
152
|
+
at?: HolePosition;
|
|
109
153
|
}
|
|
110
154
|
export interface IRFragment {
|
|
111
155
|
kind: 'fragment';
|
|
@@ -118,6 +162,8 @@ export interface IRControl {
|
|
|
118
162
|
control: ControlKind;
|
|
119
163
|
props: IRProp[];
|
|
120
164
|
children: IRNode[];
|
|
165
|
+
/** As on IRComponent: where the hole driving this subtree was written. */
|
|
166
|
+
bindAt?: HolePosition;
|
|
121
167
|
loc?: SourceSpan;
|
|
122
168
|
}
|
|
123
169
|
//# sourceMappingURL=nodes.d.ts.map
|
package/dist/ir/nodes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../src/ir/nodes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,WAAW,UAAU;IAAG,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;CAAE;AAE3D,MAAM,MAAM,MAAM,GACd,SAAS,GACT,WAAW,GACX,MAAM,GACN,YAAY,GACZ,SAAS,GACT,UAAU,CAAC;AAEf,MAAM,MAAM,UAAU,GAClB,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,MAAM;IACrB,4FAA4F;IAC5F,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;IAC3C,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oFAAoF;IACpF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,sEAAsE;IACtE,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC9C;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,SAAS,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,iFAAiF;IACjF,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAC;IACxB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B;;;;OAIG;IACH,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,MAAM;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,UAAU,CAAC;CAAE;AAE1E,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,CAAC,EAAE,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../src/ir/nodes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,WAAW,UAAU;IAAG,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;CAAE;AAE3D;;;GAGG;AACH,MAAM,WAAW,YAAY;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;AAE9D,MAAM,MAAM,MAAM,GACd,SAAS,GACT,WAAW,GACX,MAAM,GACN,YAAY,GACZ,SAAS,GACT,UAAU,CAAC;AAEf,MAAM,MAAM,UAAU,GAClB,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,MAAM;IACrB,4FAA4F;IAC5F,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;IAC3C,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oFAAoF;IACpF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4FAA4F;IAC5F,EAAE,CAAC,EAAE,YAAY,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,sEAAsE;IACtE,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC9C;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,SAAS,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,iFAAiF;IACjF,MAAM,EAAE,OAAO,CAAC;IAChB;;;;OAIG;IACH,EAAE,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACpD,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAC;IACxB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B;;;OAGG;IACH,EAAE,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACpD;;;;;OAKG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;;OAIG;IACH,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,MAAM;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,UAAU,CAAC;CAAE;AAE1E,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,4FAA4F;IAC5F,EAAE,CAAC,EAAE,YAAY,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IAAG,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,CAAC,EAAE,UAAU,CAAC;CAAE;AAEvF,MAAM,MAAM,WAAW,GACnB,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAC7C,SAAS,GAAG,eAAe,GAAG,UAAU,CAAC;AAE7C,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var E=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ce=Object.prototype.hasOwnProperty;var pe=(t,e)=>{for(var n in e)E(t,n,{get:e[n],enumerable:!0})},de=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ae(e))!ce.call(t,r)&&r!==n&&E(t,r,{get:()=>e[r],enumerable:!(o=le(e,r))||o.enumerable});return t};var ue=t=>de(E({},"__esModule",{value:!0}),t);var Be={};pe(Be,{compilePieces:()=>se,compileTemplate:()=>_e});module.exports=ue(Be);function me(t){switch(t.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return t.reactive?"reactive-prop":t.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function L(t){let e=[],n=new Map,o=r=>{switch(r.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let i of r.children)o(i);return!1;case"fragment":for(let i of r.children)o(i);return!1;case"element":{let i=!0;for(let s of r.children)o(s)||(i=!1);let a;for(let s of r.props)if(a=me(s),a)break;return!a&&!i&&(a=fe(r)),r.static=!a,a?n.set(r,a):e.push(r),r.static}default:return!1}};for(let r of Array.isArray(t)?t:[t])o(r);return{staticElements:e,reasons:n}}function fe(t){for(let e of t.children){if(e.kind==="expr")return"expression-child";if(e.kind==="component")return"component-child";if(e.kind==="control")return"control-child";if(e.kind==="element"&&!e.static||e.kind==="fragment")return"expression-child"}return"expression-child"}var k={kind:"eager"},he=["pointerdown","focusin","keydown"],j=new Set(["eager","idle","visible","interaction","media","never"]),f=class extends Error{};function _(t,e){let n=t.slice(5);if(!j.has(n))throw new f(`Unknown load strategy 'load:${n}'. Expected one of ${[...j].join(", ")}.`);switch(n){case"eager":return k;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return e?{kind:"visible",rootMargin:e}:{kind:"visible"};case"interaction":return{kind:"interaction",events:e?ge(e):[...he]};case"media":if(!e)throw new f(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new f(`Unhandled load strategy '${n}'.`)}}function ge(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new f("'load:interaction' was given no event names.");return e}function B(t){return t.kind!=="eager"&&t.kind!=="never"}var w=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],T=["Suspense","SuspenseList","Await"],x=["Router","Outlet","Redirect","Link"],Je=[...w,...T,...x],$=new Set([...w,...T]);function H(t={}){let{controlFlowModule:e="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:o="@fluixi/core/router"}=t,r={};for(let i of w)r[i]=e;for(let i of T)r[i]=n;for(let i of x)r[i]=o;return r}function F(t,e={}){let{resolver:n,isBound:o,modules:r,strategyFor:i}=e,a=H(r),s=new Map,l=new Set,c=p=>{let{name:u}=p;if(!u||u.includes(".")||o?.(u))return;let m=d(u);if(!m){l.add(u);return}let v=m.origin==="builtin"&&$.has(u)?k:i?.(p)??k;p.source={...m,loading:v},s.set(u,p.source)},d=p=>{if($.has(p))return{module:a[p],export:p,origin:"builtin"};let u=n?.resolve(p);if(u)return{module:u.module,export:u.export,origin:"rule"};if(x.includes(p))return{module:a[p],export:p,origin:"builtin"}};return N(t,p=>{p.kind==="component"&&c(p)}),{resolved:s,unresolved:[...l]}}function N(t,e){let n=Array.isArray(t)?t:[t];for(let o of n){e(o);let r=o.children;r&&N(r,e)}}function z(t){let e=[];N(t,i=>{i.kind==="component"&&i.source&&e.push(i)});let n=new Set,o=new Set;for(let i of e){let{module:a,loading:s}=i.source;s.kind==="eager"&&n.add(a),s.kind==="never"&&o.add(a)}let r=new Map;for(let i of e){let a=i.source;B(a.loading)&&n.has(a.module)&&(a.loading={kind:"eager"},r.set(a.module,(r.get(a.module)??0)+1))}return{collapsed:r,conflicted:[...o].filter(i=>n.has(i))}}var Re=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),J={className:"class",htmlFor:"for"},ve=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),ke=new Set(["script","style","textarea","title"]);function S(t){return ke.has(t)}function U(t){return J[t]??t}function h(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!ve.has(t.name)}function P(t){if(!t.static||S(t.tag))return!1;for(let e of t.props)if(!h(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&P(e)))return!1;return!0}function g(t){let e=t.props.map(Ne).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return Re.has(t.tag)?n:`${n}${t.children.map(xe).join("")}</${t.tag}>`}function xe(t){if(t.kind==="text")return be(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return g(t)}function Ne(t){let e=J[t.name]??t.name,n=t.literal;return n===!0||n===void 0?` ${e}`:n===!1||n===null?"":` ${e}="${Ie(String(n))}"`}function Ie(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function be(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var ye="<!--fx-->",Ce="<!--fx/-->";function b(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function Ee(t){return t.kind==="text"||t.kind==="element"&&V(t)}function V(t){return t.svg||S(t.tag)||!t.props.every(e=>h(e))?!1:t.children.every(e=>Ee(e)||b(e))}function I(t){if(b(t))return!0;let e=t.children;return e?e.some(I):!1}function W(t){for(let e=0;e<t.children.length;e++){let n=t.children[e];if(n.kind==="text"&&(n.value===""||t.children[e+1]?.kind==="text"))return!1}return t.children.every(e=>e.kind!=="element"||W(e))}function q(t){if(!V(t)||!W(t)||!t.children.some(I))return null;let e=[],n=[],o=0,r=a=>{let s=`_n$${o++}`;return e.push({ref:s,expr:a}),s};return i(t,"_el$"),{html:we(t),tag:t.tag,steps:e,holes:n};function i(a,s){let l=-1;a.children.forEach((d,p)=>{I(d)&&(l=p)});let c=null;for(let d=0;d<=l;d++){let p=a.children[d],u=c?`${c}.nextSibling`:`${s}.firstChild`;if(b(p)){let v=r(u),D=r(`holeEnd(${v})`);n.push({parentRef:s,startRef:v,endRef:D,node:p}),c=D;continue}let m=r(u);p.kind==="element"&&I(p)&&i(p,m),c=m}}}function we(t){return g(G(t)).split(K).join(ye+Ce)}function G(t){return{...t,children:t.children.map(e=>b(e)?{kind:"text",value:K}:e.kind==="element"?G(e):e)}}var K="\0fx-hole\0";var M={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},et={version:2,module:"@fluixi/dom",symbols:[...M.symbols,"template","cloneTemplate","walk"]};var Te={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function $e(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function Z(t){return $e(t)?t:JSON.stringify(t)}function Se(t){return t.expr!==void 0?t.reactive?`() => (${t.expr})`:`(${t.expr})`:JSON.stringify(t.literal??!0)}function Pe(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function Me(t,e,n){let o=t.filter(s=>s.kind==="spread"),i=t.filter(s=>s.kind!=="spread").map(s=>`${Z(s.name)}: ${Se(s)}`);e!=null&&i.push(`children: ${e}`);let a=`{ ${i.join(", ")} }`;return o.length>0?(n.add("mergeProps"),`mergeProps(${o.map(s=>s.expr).join(", ")}, ${a})`):a}function X(t,e,n){return t.length===1?R(t[0],e,n):`[${t.map(o=>R(o,e,n)).join(", ")}]`}function Y(t,e,n,o,r){o.add("createMemo"),o.add("createComponent");let i=e.filter(c=>c.kind==="spread"),s=e.filter(c=>c.kind!=="spread").map(c=>`get ${Z(c.name)}() { return ${Pe(c)}; }`);n.length>0&&s.push(`get children() { return ${X(n,o,r)}; }`);let l=`{ ${s.join(", ")} }`;return i.length>0&&(o.add("mergeProps"),l=`mergeProps(${i.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${t}, ${l}))`}function Oe(t,e){let n=U(e.name),o=e.literal;return o===!0||o===void 0?`${t}.setAttribute(${JSON.stringify(n)}, "");`:o===!1||o===null?"":`${t}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(o))});`}var Q=!1;function R(t,e,n){switch(t.kind){case"text":return JSON.stringify(t.value);case"expr":return t.reactive?`() => (${t.code})`:`(${t.code})`;case"fragment":return t.children.length===0?"null":X(t.children,e,n);case"component":return Y(t.name,t.props,t.children,e,n);case"control":{let o=Te[t.control]??t.control;return e.add(o),Y(o,t.props,t.children,e,n)}case"element":{if(n&&t.static&&!t.svg&&P(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;return n.push({id:s,html:g(t),tag:t.tag,svg:!1}),`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&Q){let s=q(t);if(s){e.add("templateNode"),e.add("insert"),e.add("holeEnd"),e.add("holeContent"),e.add("holeScope");let l=`_tmpl$${n.length}`;n.push({id:l,html:s.html,tag:s.tag,svg:!1});let c=[`const _el$ = templateNode(${l}, ${JSON.stringify(s.tag)}, true);`];for(let d of s.steps)c.push(`const ${d.ref} = ${d.expr};`);for(let d of s.holes)c.push(`insert(${d.parentRef}, holeScope(${d.startRef}, () => (${R(d.node,e,n)})), ${d.endRef}, holeContent(${d.startRef}, ${d.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}e.add("createNativeElement");let o=JSON.stringify(t.tag),r="_el$",i=[],a=t.svg?`${o}, true`:o;if(i.push(`const ${r} = createNativeElement(${a});`),t.props.length>0)if(!t.svg&&t.props.every(h))for(let s of t.props)i.push(Oe(r,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";i.push(`spread({ element: ${r}, props: ${Me(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let l=R(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";i.push(c?`insert(${r}, ${l}, null);`:`insert(${r}, ${l});`)}return i.push(`return ${r};`),`(() => { ${i.join(" ")} })()`}}}function y(t,e){if(!e||e.length===0)return t;let n=new Map(e.map(o=>[o.id,JSON.stringify(o.html)]));return t.replace(/_tmpl\$\d+/g,o=>n.get(o)??o)}var C={name:"imperative",contract:M,emit(t,e){let n=new Set,o=e?.templateClone!==!1?[]:void 0;return Q=e?.partialTemplates===!0,{code:R(t,n,o),imports:Array.from(n),templates:o}}};var Ae=t=>"components"in t;function ee(t,e){return t.replace(/\$(\d+)/g,(n,o)=>e[Number(o)]??n)}function De(t,e){return typeof e=="string"?{module:e,export:t}:e}function te(t=[]){let e=new Map,n=[],o=[];for(let a of t){if(!Ae(a)){o.push(a);continue}for(let[s,l]of Object.entries(a.components)){let c=De(s,l),d=e.get(s);if(d&&d.module!==c.module){let p=n.find(u=>u.name===s);p?p.modules.push(c.module):n.push({name:s,modules:[d.module,c.module]});continue}e.set(s,c)}}let r=new Map;return{resolve:a=>{if(r.has(a))return r.get(a);let s=e.get(a);if(!s)for(let l of o){let c=a.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){s={module:ee(l.module,c),export:l.export?ee(l.export,c):a};break}}return r.set(a,s),s},names:()=>[...e.keys()],conflicts:()=>n}}var oe=require("@fluixi/template-parser");function O(t){let e=t.split(/\r\n|\n|\r/),n=0;for(let r=0;r<e.length;r++)/[^ \t]/.test(e[r])&&(n=r);let o="";for(let r=0;r<e.length;r++){let i=e[r].replace(/\t/g," ");r!==0&&(i=i.replace(/^ +/,"")),r!==e.length-1&&(i=i.replace(/ +$/,"")),i&&(r!==n&&(i+=" "),o+=i)}return o}var ne=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Le(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function re(t){return t.charAt(0).toUpperCase()+t.slice(1)}var A=class{constructor(e,n){this.holes=e;this.used=n}hole(e){return this.holes[e]??{code:"undefined",reactive:!1}}emit(e){let{code:n,imports:o,templates:r}=C.emit(e,{});for(let i of o)this.used.add(i);return y(n,r)}lowerRoot(e){let n=this.lowerChildren(e);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(e){let n=[];for(let o=0;o<e.length;o++){let r=e[o];if(r.kind==="Element"||r.kind==="Component"){let a=r.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=o+1;s<e.length&&this.isBlankText(e[s])&&s++;let l=e[s],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(d=>d.kind==="ElseDirective");n.push(this.lowerIf(r,a.hole,c?l:null)),c&&(o=s);continue}if(r.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(r));continue}}let i=this.lowerNode(r);i&&n.push(i)}return n}isBlankText(e){return e.kind==="Text"&&!e.raw&&O(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=O(e.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(e.hole);return{kind:"expr",code:n.code,reactive:n.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(e.children)};case"Element":return this.lowerElement(e);case"Component":return this.lowerComponent(e);default:return null}}lowerElement(e){let n=e.attributes.find(o=>o.kind==="Attribute"&&o.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let o=e.attributes.filter(i=>i!==n),r=this.lowerComponent({...e,kind:"Component",tag:"Dynamic",tagHole:null,attributes:o});return r.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),r}return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:this.lowerAttributes(e.attributes),children:this.lowerChildren(e.children),static:!1}}lowerComponent(e){let n=e.tagHole!=null?this.hole(e.tagHole).code:e.tag,o=this.lowerAttributes(e.attributes),{slots:r,rest:i}=this.partitionSlots(e.children);for(let[l,c]of r){let d=c.length===1?c[0]:{kind:"fragment",children:c},p={name:l,kind:"attr",expr:this.emit(d),jsxElement:!0},u=o.findIndex(m=>m.name===l);u>=0?o[u]=p:o.push(p)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?_(`load:${a.strategy}`,a.modifier):void 0;return{kind:"component",name:n,props:o,children:this.lowerChildren(i),...s?{load:s}:{}}}partitionSlots(e){let n=new Map,o=[];for(let r of e){if(r.kind==="Element"||r.kind==="Component"){let i=r.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(i&&i.value&&i.value.kind==="static"){let a={...r,attributes:r.attributes.filter(c=>c!==i)},s=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),l=n.get(i.value.value)??[];l.push(s),n.set(i.value.value,l);continue}}o.push(r)}return{slots:n,rest:o}}lowerIf(e,n,o){let r=this.hole(n),i=[{name:"when",kind:"attr",expr:r.code,reactive:r.reactive}];if(o){let s=this.stripAndLower(o,l=>l.kind==="ElseDirective");i.push({name:"fallback",kind:"attr",expr:this.emit(s),jsxElement:!0})}let a=this.stripAndLower(e,s=>s.kind==="IfDirective");return{kind:"component",name:"Show",props:i,children:[a]}}lowerEach(e){let n=e.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(e);let o=this.hole(n.hole),r=[{name:"each",kind:"attr",expr:o.code,reactive:o.reactive}];if(n.key){let l="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;r.push({name:"by",kind:"attr",expr:l})}let i=this.itemArrow(e),a;if(i){let l={kind:"expr",code:i.body,reactive:i.bodyReactive},c=this.rebuildWithChildren(e,[l]);a=`(${i.params.join(", ")}) => (${this.emit(c)})`}else{let l=this.stripAndLower(e,c=>c.kind==="EachDirective");a=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:r,children:[{kind:"expr",code:a,reactive:!1}]}}itemArrow(e){let n=e.children.filter(o=>!this.isBlankText(o));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(e,n){let o={...e,attributes:e.attributes.filter(r=>!n(r))};return o.kind==="Element"?this.lowerElement(o):this.lowerComponent(o)}rebuildWithChildren(e,n){let o=this.lowerAttributes(e.attributes.filter(r=>r.kind!=="EachDirective"));return e.kind==="Element"?{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:o,children:n,static:!1}:{kind:"component",name:e.tag,props:o,children:n}}lowerAttributes(e){let n=[],o=[],r=!1,i=[],a=!1,s=[];for(let l of e)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":n.push(this.plainAttr(l));break;case"PropertyBinding":n.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"EventBinding":n.push(this.eventProp(l));break;case"RefBinding":n.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let c=this.hole(l.hole);o.push(`${JSON.stringify(l.name)}: ${c.code}`),r=r||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);i.push(`${JSON.stringify(l.name)}: ${c.code}`),a=a||c.reactive;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole).code));break;case"UseDirective":{let c=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!c)break;s.push(l.name!=null&&l.hole!=null?`[${c}, () => (${this.hole(l.hole).code})]`:`[${c}]`);break}}return o.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:r}),i.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${i.join(", ")} }`,reactive:a}),s.length>0&&n.push({name:"use",kind:"attr",expr:`[${s.join(", ")}]`}),n}eventProp(e){let n=e.name.toLowerCase(),o=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+re(e.name),kind:"event",event:{name:n,delegated:ne.has(n)},expr:o};let i=this.wrapHandler(o,e.modifiers),a=this.eventOptions(e.modifiers),s=a?`[${i}, ${a}]`:i;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(e,n){let o=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",r=[];return n.includes("prevent")&&r.push("e.preventDefault();"),n.includes("stop")&&r.push("e.stopPropagation();"),!o&&r.length===0?e:`(e) => { ${o}${r.join(" ")} return (${e})(e); }`}eventOptions(e){let n=[];return e.includes("capture")&&n.push("capture: true"),e.includes("once")&&n.push("once: true"),e.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(e,n){let o=e==="checked",r=o?"change":"input",i=o?"checked":"value";this.used.add("bindPair");let a=`bindPair(${n})`;return[{name:e,kind:"attr",expr:`${a}[0]()`,reactive:!0},{name:"on"+re(r),kind:"event",event:{name:r,delegated:ne.has(r)},expr:`(e) => ${a}[1](e.target.${i})`}]}plainAttr(e){let n=e.value,o=e.name;e.name==="class"?o=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":e.name==="html"&&(o="innerHTML");let i={name:o,kind:"attr"};if(n==null)return i.literal=!0,i;if(n.kind==="static")return i.literal=n.value,i;if(n.kind==="hole"){let l=this.hole(n.hole);return i.expr=l.code,i.reactive=l.reactive,i}let a=!1,s=n.parts.map(l=>{if("text"in l)return Le(l.text);let c=this.hole(l.hole);return a=a||c.reactive,"${"+c.code+"}"}).join("");return i.expr="`"+s+"`",i.reactive=a,i}};function ie(t,e,n,o={}){let{root:r}=(0,oe.parseTemplate)(t,{svg:o.svg});return new A(e,n).lowerRoot(r.children)}function je(t){let e=[],n=0;return t.statics.forEach((o,r)=>{if(e.push({kind:"static",text:o,start:n}),n+=o.length,r<t.holes.length){let i=n+t.holes[r].code.length;e.push({kind:"hole",index:r,start:n,end:i}),n=i}}),e}function _e(t,e={}){if(t.statics.length!==t.holes.length+1)throw new Error(`[fluixi] compileTemplate: ${t.statics.length} static runs for ${t.holes.length} holes — a template always has exactly one more.`);return se(je(t),t.holes,e)}function se(t,e,n={}){let o=new Set,r=ie(t,[...e],o,{svg:n.svg});L(r),F(r,{resolver:te(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:l=>l.load}),z(r);let{code:i,imports:a,templates:s}=C.emit(r,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let l of a)o.add(l);return n.hoistTemplates?{code:i,imports:[...o],ir:r,templates:s}:{code:y(i,s),imports:[...o],ir:r}}
|
|
1
|
+
"use strict";var w=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var he=Object.prototype.hasOwnProperty;var Re=(t,e)=>{for(var n in e)w(t,n,{get:e[n],enumerable:!0})},ve=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ge(e))!he.call(t,r)&&r!==n&&w(t,r,{get:()=>e[r],enumerable:!(i=me(e,r))||i.enumerable});return t};var Ne=t=>ve(w({},"__esModule",{value:!0}),t);var Ge={};Re(Ge,{compilePieces:()=>fe,compileTemplate:()=>We});module.exports=Ne(Ge);function xe(t){switch(t.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return t.reactive?"reactive-prop":t.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function H(t){let e=[],n=new Map,i=r=>{switch(r.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let o of r.children)i(o);return!1;case"fragment":for(let o of r.children)i(o);return!1;case"element":{let o=!0;for(let s of r.children)i(s)||(o=!1);let a;for(let s of r.props)if(a=xe(s),a)break;return!a&&!o&&(a=ye(r)),r.static=!a,a?n.set(r,a):e.push(r),r.static}default:return!1}};for(let r of Array.isArray(t)?t:[t])i(r);return{staticElements:e,reasons:n}}function ye(t){for(let e of t.children){if(e.kind==="expr")return"expression-child";if(e.kind==="component")return"component-child";if(e.kind==="control")return"control-child";if(e.kind==="element"&&!e.static||e.kind==="fragment")return"expression-child"}return"expression-child"}var b={kind:"eager"},be=["pointerdown","focusin","keydown"],B=new Set(["eager","idle","visible","interaction","media","never"]),h=class extends Error{};function J(t,e){let n=t.slice(5);if(!B.has(n))throw new h(`Unknown load strategy 'load:${n}'. Expected one of ${[...B].join(", ")}.`);switch(n){case"eager":return b;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return e?{kind:"visible",rootMargin:e}:{kind:"visible"};case"interaction":return{kind:"interaction",events:e?ke(e):[...be]};case"media":if(!e)throw new h(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new h(`Unhandled load strategy '${n}'.`)}}function ke(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new h("'load:interaction' was given no event names.");return e}function V(t){return t.kind!=="eager"&&t.kind!=="never"}var T=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],A=["Suspense","SuspenseList","Await"],k=["Router","Outlet","Redirect","Link"],Xe=[...T,...A,...k],P=new Set([...T,...A]);function U(t={}){let{controlFlowModule:e="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:i="@fluixi/core/router"}=t,r={};for(let o of T)r[o]=e;for(let o of A)r[o]=n;for(let o of k)r[o]=i;return r}function K(t,e={}){let{resolver:n,isBound:i,modules:r,strategyFor:o}=e,a=U(r),s=new Map,u=new Set,c=p=>{let{name:d}=p;if(!d||d.includes(".")||i?.(d))return;let f=l(d);if(!f){u.add(d);return}let m=f.origin==="builtin"&&P.has(d)?b:o?.(p)??b;p.source={...f,loading:m},s.set(d,p.source)},l=p=>{if(P.has(p))return{module:a[p],export:p,origin:"builtin"};let d=n?.resolve(p);if(d)return{module:d.module,export:d.export,origin:"rule"};if(k.includes(p))return{module:a[p],export:p,origin:"builtin"}};return I(t,p=>{p.kind==="component"&&c(p)}),{resolved:s,unresolved:[...u]}}function I(t,e){let n=Array.isArray(t)?t:[t];for(let i of n){e(i);let r=i.children;r&&I(r,e)}}function z(t){let e=[];I(t,o=>{o.kind==="component"&&o.source&&e.push(o)});let n=new Set,i=new Set;for(let o of e){let{module:a,loading:s}=o.source;s.kind==="eager"&&n.add(a),s.kind==="never"&&i.add(a)}let r=new Map;for(let o of e){let a=o.source;V(a.loading)&&n.has(a.module)&&(a.loading={kind:"eager"},r.set(a.module,(r.get(a.module)??0)+1))}return{collapsed:r,conflicted:[...i].filter(o=>n.has(o))}}var Ie=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),W={className:"class",htmlFor:"for"},Ee=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Se=new Set(["script","style","textarea","title"]);function M(t){return Se.has(t)}function G(t){return W[t]??t}function R(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!Ee.has(t.name)}function O(t){if(!t.static||M(t.tag))return!1;for(let e of t.props)if(!R(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&O(e)))return!1;return!0}function v(t){let e=t.props.map(Ce).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return Ie.has(t.tag)?n:`${n}${t.children.map($e).join("")}</${t.tag}>`}function $e(t){if(t.kind==="text")return Te(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return v(t)}function Ce(t){let e=W[t.name]??t.name,n=t.literal;return n===!0||n===void 0?` ${e}`:n===!1||n===null?"":` ${e}="${we(String(n))}"`}function we(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Te(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function D(t){let e=[],n,i=r=>{n??=r.at?.file,e.push(r.at?.line??0,r.at?.column??0);for(let o of r.children)o.kind==="element"&&i(o)};return i(t),n&&e.some(r=>r!==0)?{file:n,pos:e}:void 0}var Ae="<!--fx-->",Pe="<!--fx/-->";function S(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function Me(t){return t.kind==="text"||t.kind==="element"&&q(t)}function q(t){return t.svg||M(t.tag)||!t.props.every(e=>R(e))?!1:t.children.every(e=>Me(e)||S(e))}function E(t){if(S(t))return!0;let e=t.children;return e?e.some(E):!1}function Y(t){for(let e=0;e<t.children.length;e++){let n=t.children[e];if(n.kind==="text"&&(n.value===""||t.children[e+1]?.kind==="text"))return!1}return t.children.every(e=>e.kind!=="element"||Y(e))}function Z(t){if(!q(t)||!Y(t)||!t.children.some(E))return null;let e=[],n=[],i=0,r=a=>{let s=`_n$${i++}`;return e.push({ref:s,expr:a}),s};return o(t,"_el$"),{html:Oe(t),tag:t.tag,steps:e,holes:n};function o(a,s){let u=-1;a.children.forEach((l,p)=>{E(l)&&(u=p)});let c=null;for(let l=0;l<=u;l++){let p=a.children[l],d=c?`${c}.nextSibling`:`${s}.firstChild`;if(S(p)){let m=r(d),y=r(`holeEnd(${m})`);n.push({parentRef:s,startRef:m,endRef:y,node:p}),c=y;continue}let f=r(d);p.kind==="element"&&E(p)&&o(p,f),c=f}}}function Oe(t){return v(X(t)).split(Q).join(Ae+Pe)}function X(t){return{...t,children:t.children.map(e=>S(e)?{kind:"text",value:Q}:e.kind==="element"?X(e):e)}}var Q="\0fx-hole\0";var _={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},ct={version:2,module:"@fluixi/dom",symbols:[..._.symbols,"template","cloneTemplate","walk"]};var g="@fluixi/reactive/signal",j={$signal:{export:"signal",module:g,returns:"signal-handle"},$memo:{export:"memo",module:g,returns:"memo-handle"},$effect:{export:"effect",module:g,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:g,returns:"resource-handle"},$selector:{export:"createSelector",module:g,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:g,returns:"memo-accessor"},$untrack:{export:"untrack",module:g,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}};var pt=new RegExp(`\\$(?:${Object.keys(j).map(t=>t.slice(1)).join("|")})\\s*\\(`);var ee="__fx_source";var De="__fx_hole",N=(t,e,n,i)=>`(globalThis.${De} ?? ((f) => f))(${t},${e},${n}${i===void 0?"":`,${JSON.stringify(i)}`})`,_e="__fx_props",te=(t,e)=>`(globalThis.${_e} ?? ((p) => p))(${t},${JSON.stringify(e)})`;var je={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Le(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function ie(t){return Le(t)?t:JSON.stringify(t)}function Fe(t){if(t.expr!==void 0){if(t.name==="ref"&&t.at)return N(`(${t.expr})`,t.at.line,t.at.column,t.expr);if(!t.reactive)return`(${t.expr})`;let e=`() => (${t.expr})`;return t.at?N(e,t.at.line,t.at.column,t.directive):e}return JSON.stringify(t.literal??!0)}function He(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function Be(t,e,n){let i=t.filter(s=>s.kind==="spread"),o=t.filter(s=>s.kind!=="spread").map(s=>`${ie(s.name)}: ${Fe(s)}`);e!=null&&o.push(`children: ${e}`);let a=`{ ${o.join(", ")} }`;return i.length>0?(n.add("mergeProps"),`mergeProps(${i.map(s=>s.expr).join(", ")}, ${a})`):a}function ne(t,e){return e?N(t,e.line,e.column):t}function oe(t,e,n){return t.length===1?x(t[0],e,n):`[${t.map(i=>x(i,e,n)).join(", ")}]`}function re(t,e,n,i,r,o){i.add("createMemo"),i.add("createComponent");let a=e.filter(d=>d.kind==="spread"),s=e.filter(d=>d.kind!=="spread"),u=s.map(d=>`get ${ie(d.name)}() { return ${He(d)}; }`);n.length>0&&u.push(`get children() { return ${oe(n,i,r)}; }`);let c=`{ ${u.join(", ")} }`;a.length>0&&(i.add("mergeProps"),c=`mergeProps(${a.map(d=>d.expr).join(", ")}, ${c})`);let l={};for(let d of s)d.at&&(l[d.name]=[d.at.line,d.at.column]);return Object.keys(l).length&&(c=te(c,l)),`createMemo((${o?`globalThis.${ee}?.(${JSON.stringify(o.file)},${o.line},${o.column},${JSON.stringify(t)}), `:""}() => createComponent(${t}, ${c})))`}function Je(t,e){let n=G(e.name),i=e.literal;return i===!0||i===void 0?`${t}.setAttribute(${JSON.stringify(n)}, "");`:i===!1||i===null?"":`${t}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(i))});`}var se=!1;function x(t,e,n){switch(t.kind){case"text":return JSON.stringify(t.value);case"expr":{if(!t.reactive)return`(${t.code})`;let i=`() => (${t.code})`;return t.at?N(i,t.at.line,t.at.column):i}case"fragment":return t.children.length===0?"null":oe(t.children,e,n);case"component":return ne(re(t.name,t.props,t.children,e,n,t.at),t.bindAt??t.at);case"control":{let i=je[t.control]??t.control;return e.add(i),ne(re(i,t.props,t.children,e,n),t.bindAt)}case"element":{if(n&&t.static&&!t.svg&&O(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;n.push({id:s,html:v(t),tag:t.tag,svg:!1});let u=D(t);return u?`templateNode(${s}, ${JSON.stringify(t.tag)}, false, false, ${JSON.stringify(u)})`:`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&se){let s=Z(t);if(s){e.add("templateNode"),e.add("insert"),e.add("holeEnd"),e.add("holeContent"),e.add("holeScope");let u=`_tmpl$${n.length}`;n.push({id:u,html:s.html,tag:s.tag,svg:!1});let c=D(t),l=[`const _el$ = templateNode(${u}, ${JSON.stringify(s.tag)}, true${c?`, false, ${JSON.stringify(c)}`:""});`];for(let p of s.steps)l.push(`const ${p.ref} = ${p.expr};`);for(let p of s.holes)l.push(`insert(${p.parentRef}, holeScope(${p.startRef}, () => (${x(p.node,e,n)})), ${p.endRef}, holeContent(${p.startRef}, ${p.endRef}));`);return l.push("return _el$;"),`(() => { ${l.join(" ")} })()`}}e.add("createNativeElement");let i=JSON.stringify(t.tag),r="_el$",o=[],a=t.at?`${i}, ${t.svg}, ${JSON.stringify(t.at)}`:t.svg?`${i}, true`:i;if(o.push(`const ${r} = createNativeElement(${a});`),t.props.length>0)if(!t.svg&&t.props.every(R))for(let s of t.props)o.push(Je(r,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";o.push(`spread({ element: ${r}, props: ${Be(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let u=x(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";o.push(c?`insert(${r}, ${u}, null);`:`insert(${r}, ${u});`)}return o.push(`return ${r};`),`(() => { ${o.join(" ")} })()`}}}function $(t,e){if(!e||e.length===0)return t;let n=new Map(e.map(i=>[i.id,JSON.stringify(i.html)]));return t.replace(/_tmpl\$\d+/g,i=>n.get(i)??i)}var C={name:"imperative",contract:_,emit(t,e){let n=new Set,i=e?.templateClone!==!1?[]:void 0;return se=e?.partialTemplates===!0,{code:x(t,n,i),imports:Array.from(n),templates:i}}};var Ve=t=>"components"in t;function ae(t,e){return t.replace(/\$(\d+)/g,(n,i)=>e[Number(i)]??n)}function Ue(t,e){return typeof e=="string"?{module:e,export:t}:e}function le(t=[]){let e=new Map,n=[],i=[];for(let a of t){if(!Ve(a)){i.push(a);continue}for(let[s,u]of Object.entries(a.components)){let c=Ue(s,u),l=e.get(s);if(l&&l.module!==c.module){let p=n.find(d=>d.name===s);p?p.modules.push(c.module):n.push({name:s,modules:[l.module,c.module]});continue}e.set(s,c)}}let r=new Map;return{resolve:a=>{if(r.has(a))return r.get(a);let s=e.get(a);if(!s)for(let u of i){let c=a.match(new RegExp(u.match.source,u.match.flags.replace("g","")));if(c){s={module:ae(u.module,c),export:u.export?ae(u.export,c):a};break}}return r.set(a,s),s},names:()=>[...e.keys()],conflicts:()=>n}}var pe=require("@fluixi/template-parser");function L(t){let e=t.split(/\r\n|\n|\r/),n=0;for(let r=0;r<e.length;r++)/[^ \t]/.test(e[r])&&(n=r);let i="";for(let r=0;r<e.length;r++){let o=e[r].replace(/\t/g," ");r!==0&&(o=o.replace(/^ +/,"")),r!==e.length-1&&(o=o.replace(/ +$/,"")),o&&(r!==n&&(o+=" "),i+=o)}return i}var ce=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Ke(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function ue(t){return t.charAt(0).toUpperCase()+t.slice(1)}var F=class{constructor(e,n,i,r){this.holes=e;this.used=n;this.sourceFile=i;this.positionAt=r}tagAt(e){let n=e.loc?.start;if(!this.sourceFile||!this.positionAt||n==null)return;let{line:i,column:r}=this.positionAt(n);return{file:this.sourceFile,line:i,column:r}}hole(e){return this.holes[e]??{code:"undefined",reactive:!1}}emit(e){let{code:n,imports:i,templates:r}=C.emit(e,{});for(let o of i)this.used.add(o);return $(n,r)}lowerRoot(e){let n=this.lowerChildren(e);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(e){let n=[];for(let i=0;i<e.length;i++){let r=e[i];if(r.kind==="Element"||r.kind==="Component"){let a=r.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=i+1;s<e.length&&this.isBlankText(e[s])&&s++;let u=e[s],c=u&&(u.kind==="Element"||u.kind==="Component")&&u.attributes.some(l=>l.kind==="ElseDirective");n.push(this.lowerIf(r,a.hole,c?u:null)),c&&(i=s);continue}if(r.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(r));continue}}let o=this.lowerNode(r);o&&n.push(o)}return n}isBlankText(e){return e.kind==="Text"&&!e.raw&&L(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=L(e.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(e.hole);return{kind:"expr",code:n.code,reactive:n.reactive,...n.at?{at:n.at}:{}}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(e.children)};case"Element":return this.lowerElement(e);case"Component":return this.lowerComponent(e);default:return null}}lowerElement(e){let n=e.attributes.find(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=e.attributes.filter(a=>a!==n),o=this.lowerComponent({...e,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return o.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),o}let i=this.tagAt(e);return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:this.lowerAttributes(e.attributes),children:this.lowerChildren(e.children),static:!1,...i?{at:i}:{}}}lowerComponent(e){let n=e.tagHole!=null?this.hole(e.tagHole).code:e.tag,i=this.lowerAttributes(e.attributes),{slots:r,rest:o}=this.partitionSlots(e.children);for(let[l,p]of r){let d=p.length===1?p[0]:{kind:"fragment",children:p},f={name:l,kind:"attr",expr:this.emit(d),jsxElement:!0},m=i.findIndex(y=>y.name===l);m>=0?i[m]=f:i.push(f)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?J(`load:${a.strategy}`,a.modifier):void 0,u=i.find(l=>l.at&&l.reactive)?.at,c=this.tagAt(e);return{kind:"component",name:n,props:i,children:this.lowerChildren(o),...c?{at:c}:{},...u?{bindAt:u}:{},...s?{load:s}:{}}}partitionSlots(e){let n=new Map,i=[];for(let r of e){if(r.kind==="Element"||r.kind==="Component"){let o=r.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(o&&o.value&&o.value.kind==="static"){let a={...r,attributes:r.attributes.filter(c=>c!==o)},s=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),u=n.get(o.value.value)??[];u.push(s),n.set(o.value.value,u);continue}}i.push(r)}return{slots:n,rest:i}}lowerIf(e,n,i){let r=this.hole(n),o=[{name:"when",kind:"attr",expr:r.code,reactive:r.reactive,...r.at?{at:r.at}:{}}];if(i){let u=this.stripAndLower(i,c=>c.kind==="ElseDirective");o.push({name:"fallback",kind:"attr",expr:this.emit(u),jsxElement:!0})}let a=this.stripAndLower(e,u=>u.kind==="IfDirective"),s=this.tagAt(e);return{kind:"component",name:"Show",props:o,children:[a],...s?{at:s}:{},...r.at?{bindAt:r.at}:{}}}lowerEach(e){let n=e.attributes.find(c=>c.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(e);let i=this.hole(n.hole),r=[{name:"each",kind:"attr",expr:i.code,reactive:i.reactive,...i.at?{at:i.at}:{}}];if(n.key){let c="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;r.push({name:"by",kind:"attr",expr:c})}let o=this.itemArrow(e),a;if(o){let c={kind:"expr",code:o.body,reactive:o.bodyReactive},l=this.rebuildWithChildren(e,[c]);a=`(${o.params.join(", ")}) => (${this.emit(l)})`}else{let c=this.stripAndLower(e,l=>l.kind==="EachDirective");a=`() => (${this.emit(c)})`}let s=[{kind:"expr",code:a,reactive:!1}],u=this.tagAt(e);return{kind:"component",name:"For",props:r,children:s,...u?{at:u}:{},...i.at?{bindAt:i.at}:{}}}itemArrow(e){let n=e.children.filter(i=>!this.isBlankText(i));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(e,n){let i={...e,attributes:e.attributes.filter(r=>!n(r))};return i.kind==="Element"?this.lowerElement(i):this.lowerComponent(i)}rebuildWithChildren(e,n){let i=this.lowerAttributes(e.attributes.filter(r=>r.kind!=="EachDirective"));if(e.kind==="Element"){let r=this.tagAt(e);return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:i,children:n,static:!1,...r?{at:r}:{}}}return{kind:"component",name:e.tag,props:i,children:n}}lowerAttributes(e){let n=[],i=[],r=!1,o,a=[],s=!1,u,c=[];for(let l of e)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":n.push(this.plainAttr(l));break;case"PropertyBinding":n.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive,...this.hole(l.hole).at?{at:this.hole(l.hole).at}:{}});break;case"EventBinding":n.push(this.eventProp(l));break;case"RefBinding":n.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive,...this.hole(l.hole).at?{at:this.hole(l.hole).at}:{}});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let p=this.hole(l.hole);i.push(`${JSON.stringify(l.name)}: ${p.code}`),r=r||p.reactive,o??=p.at;break}case"StyleDirective":{let p=this.hole(l.hole);a.push(`${JSON.stringify(l.name)}: ${p.code}`),s=s||p.reactive,u??=p.at;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole)));break;case"UseDirective":{let p=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!p)break;c.push(l.name!=null&&l.hole!=null?`[${p}, () => (${this.hole(l.hole).code})]`:`[${p}]`);break}}return i.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${i.join(", ")} }`,reactive:r,...o?{at:o}:{}}),a.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${a.join(", ")} }`,reactive:s,...u?{at:u}:{}}),c.length>0&&n.push({name:"use",kind:"attr",expr:`[${c.join(", ")}]`}),n}eventProp(e){let n=e.name.toLowerCase(),i=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+ue(e.name),kind:"event",event:{name:n,delegated:ce.has(n)},expr:i};let o=this.wrapHandler(i,e.modifiers),a=this.eventOptions(e.modifiers),s=a?`[${o}, ${a}]`:o;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(e,n){let i=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",r=[];return n.includes("prevent")&&r.push("e.preventDefault();"),n.includes("stop")&&r.push("e.stopPropagation();"),!i&&r.length===0?e:`(e) => { ${i}${r.join(" ")} return (${e})(e); }`}eventOptions(e){let n=[];return e.includes("capture")&&n.push("capture: true"),e.includes("once")&&n.push("once: true"),e.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(e,n){let i=n.code,r=e==="checked",o=r?"change":"input",a=r?"checked":"value";this.used.add("bindPair");let s=`bindPair(${i})`;return[{name:e,kind:"attr",expr:`${s}[0]()`,reactive:!0,directive:`bind:${e}`,...n.at?{at:n.at}:{}},{name:"on"+ue(o),kind:"event",event:{name:o,delegated:ce.has(o)},expr:`(e) => ${s}[1](e.target.${a})`}]}plainAttr(e){let n=e.value,i=e.name;e.name==="class"?i=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":e.name==="html"&&(i="innerHTML");let o={name:i,kind:"attr"};if(n==null)return o.literal=!0,o;if(n.kind==="static")return o.literal=n.value,o;if(n.kind==="hole"){let c=this.hole(n.hole);return o.expr=c.code,o.reactive=c.reactive,c.at&&(o.at=c.at),o}let a=!1,s,u=n.parts.map(c=>{if("text"in c)return Ke(c.text);let l=this.hole(c.hole);return a=a||l.reactive,s??=l.at,"${"+l.code+"}"}).join("");return o.expr="`"+u+"`",o.reactive=a,s&&(o.at=s),o}};function de(t,e,n,i={}){let{root:r}=(0,pe.parseTemplate)(t,{svg:i.svg});return new F(e,n,i.sourceFile,i.positionAt).lowerRoot(r.children)}function ze(t){let e=[],n=0;return t.statics.forEach((i,r)=>{if(e.push({kind:"static",text:i,start:n}),n+=i.length,r<t.holes.length){let o=n+t.holes[r].code.length;e.push({kind:"hole",index:r,start:n,end:o}),n=o}}),e}function We(t,e={}){if(t.statics.length!==t.holes.length+1)throw new Error(`[fluixi] compileTemplate: ${t.statics.length} static runs for ${t.holes.length} holes — a template always has exactly one more.`);return fe(ze(t),t.holes,e)}function fe(t,e,n={}){let i=new Set,r=de(t,[...e],i,{svg:n.svg,...n.sourceFile?{sourceFile:n.sourceFile}:{},...n.positionAt?{positionAt:n.positionAt}:{}});H(r),K(r,{resolver:le(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:u=>u.load}),z(r);let{code:o,imports:a,templates:s}=C.emit(r,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let u of a)i.add(u);return n.hoistTemplates?{code:o,imports:[...i],ir:r,templates:s}:{code:$(o,s),imports:[...i],ir:r}}
|
|
@@ -33,6 +33,18 @@ export interface CompileTemplateOptions {
|
|
|
33
33
|
* caller that has a module scope to declare them in. Off inlines them.
|
|
34
34
|
*/
|
|
35
35
|
hoistTemplates?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The author's file, and a way to turn the parser's offsets into positions in it.
|
|
38
|
+
*
|
|
39
|
+
* Only when the host asked for source locations. Together they let a tag written inside a
|
|
40
|
+
* template carry the same mark a JSX tag does — without it the nodes it makes are the only
|
|
41
|
+
* ones in a component with no mark of their own, and they take whichever one was left.
|
|
42
|
+
*/
|
|
43
|
+
sourceFile?: string;
|
|
44
|
+
positionAt?: (offset: number) => {
|
|
45
|
+
line: number;
|
|
46
|
+
column: number;
|
|
47
|
+
};
|
|
36
48
|
}
|
|
37
49
|
export interface CompileTemplateResult {
|
|
38
50
|
/** A JavaScript expression that builds the DOM when evaluated. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-template.d.ts","sourceRoot":"","sources":["../../src/lower/compile-template.ts"],"names":[],"mappings":"AAcA,OAAO,EAA2B,KAAK,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACvG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACjE,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,kDAAkD;IAClD,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,sBAAsB;IACrC,4EAA4E;IAC5E,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,yFAAyF;IACzF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iEAAiE;IACjE,OAAO,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAC3C,8EAA8E;IAC9E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uFAAuF;IACvF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"compile-template.d.ts","sourceRoot":"","sources":["../../src/lower/compile-template.ts"],"names":[],"mappings":"AAcA,OAAO,EAA2B,KAAK,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACvG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACjE,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,kDAAkD;IAClD,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,sBAAsB;IACrC,4EAA4E;IAC5E,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,yFAAyF;IACzF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iEAAiE;IACjE,OAAO,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAC3C,8EAA8E;IAC9E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uFAAuF;IACvF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACnE;AAED,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,sFAAsF;IACtF,EAAE,EAAE,MAAM,CAAC;IACX;;;;OAIG;IACH,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC;CAC9B;AAqBD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,sBAA2B,GACnC,qBAAqB,CASvB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,KAAK,EAAE,EACf,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,OAAO,GAAE,sBAA2B,GACnC,qBAAqB,CA8BvB"}
|
|
@@ -46,7 +46,11 @@ export function compileTemplate(source, options = {}) {
|
|
|
46
46
|
*/
|
|
47
47
|
export function compilePieces(pieces, holes, options = {}) {
|
|
48
48
|
const used = new Set();
|
|
49
|
-
const ir = lowerTemplate(pieces, [...holes], used, {
|
|
49
|
+
const ir = lowerTemplate(pieces, [...holes], used, {
|
|
50
|
+
svg: options.svg,
|
|
51
|
+
...(options.sourceFile ? { sourceFile: options.sourceFile } : {}),
|
|
52
|
+
...(options.positionAt ? { positionAt: options.positionAt } : {}),
|
|
53
|
+
});
|
|
50
54
|
analyzeStatic(ir);
|
|
51
55
|
// Same order as the Babel front-end: decide where each component reference
|
|
52
56
|
// comes from, then drop deferred boundaries around modules already in the chunk.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function oe(t){switch(t.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return t.reactive?"reactive-prop":t.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function D(t){let e=[],n=new Map,r=o=>{switch(o.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let i of o.children)r(i);return!1;case"fragment":for(let i of o.children)r(i);return!1;case"element":{let i=!0;for(let s of o.children)r(s)||(i=!1);let a;for(let s of o.props)if(a=oe(s),a)break;return!a&&!i&&(a=ie(o)),o.static=!a,a?n.set(o,a):e.push(o),o.static}default:return!1}};for(let o of Array.isArray(t)?t:[t])r(o);return{staticElements:e,reasons:n}}function ie(t){for(let e of t.children){if(e.kind==="expr")return"expression-child";if(e.kind==="component")return"component-child";if(e.kind==="control")return"control-child";if(e.kind==="element"&&!e.static||e.kind==="fragment")return"expression-child"}return"expression-child"}var k={kind:"eager"},se=["pointerdown","focusin","keydown"],L=new Set(["eager","idle","visible","interaction","media","never"]),f=class extends Error{};function j(t,e){let n=t.slice(5);if(!L.has(n))throw new f(`Unknown load strategy 'load:${n}'. Expected one of ${[...L].join(", ")}.`);switch(n){case"eager":return k;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return e?{kind:"visible",rootMargin:e}:{kind:"visible"};case"interaction":return{kind:"interaction",events:e?le(e):[...se]};case"media":if(!e)throw new f(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new f(`Unhandled load strategy '${n}'.`)}}function le(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new f("'load:interaction' was given no event names.");return e}function _(t){return t.kind!=="eager"&&t.kind!=="never"}var E=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],w=["Suspense","SuspenseList","Await"],x=["Router","Outlet","Redirect","Link"],Oe=[...E,...w,...x],T=new Set([...E,...w]);function B(t={}){let{controlFlowModule:e="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:r="@fluixi/core/router"}=t,o={};for(let i of E)o[i]=e;for(let i of w)o[i]=n;for(let i of x)o[i]=r;return o}function H(t,e={}){let{resolver:n,isBound:r,modules:o,strategyFor:i}=e,a=B(o),s=new Map,l=new Set,c=p=>{let{name:u}=p;if(!u||u.includes(".")||r?.(u))return;let m=d(u);if(!m){l.add(u);return}let v=m.origin==="builtin"&&T.has(u)?k:i?.(p)??k;p.source={...m,loading:v},s.set(u,p.source)},d=p=>{if(T.has(p))return{module:a[p],export:p,origin:"builtin"};let u=n?.resolve(p);if(u)return{module:u.module,export:u.export,origin:"rule"};if(x.includes(p))return{module:a[p],export:p,origin:"builtin"}};return N(t,p=>{p.kind==="component"&&c(p)}),{resolved:s,unresolved:[...l]}}function N(t,e){let n=Array.isArray(t)?t:[t];for(let r of n){e(r);let o=r.children;o&&N(o,e)}}function F(t){let e=[];N(t,i=>{i.kind==="component"&&i.source&&e.push(i)});let n=new Set,r=new Set;for(let i of e){let{module:a,loading:s}=i.source;s.kind==="eager"&&n.add(a),s.kind==="never"&&r.add(a)}let o=new Map;for(let i of e){let a=i.source;_(a.loading)&&n.has(a.module)&&(a.loading={kind:"eager"},o.set(a.module,(o.get(a.module)??0)+1))}return{collapsed:o,conflicted:[...r].filter(i=>n.has(i))}}var ae=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),z={className:"class",htmlFor:"for"},ce=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),pe=new Set(["script","style","textarea","title"]);function $(t){return pe.has(t)}function J(t){return z[t]??t}function h(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!ce.has(t.name)}function S(t){if(!t.static||$(t.tag))return!1;for(let e of t.props)if(!h(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&S(e)))return!1;return!0}function g(t){let e=t.props.map(ue).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return ae.has(t.tag)?n:`${n}${t.children.map(de).join("")}</${t.tag}>`}function de(t){if(t.kind==="text")return fe(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return g(t)}function ue(t){let e=z[t.name]??t.name,n=t.literal;return n===!0||n===void 0?` ${e}`:n===!1||n===null?"":` ${e}="${me(String(n))}"`}function me(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function fe(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var he="<!--fx-->",ge="<!--fx/-->";function b(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function Re(t){return t.kind==="text"||t.kind==="element"&&U(t)}function U(t){return t.svg||$(t.tag)||!t.props.every(e=>h(e))?!1:t.children.every(e=>Re(e)||b(e))}function I(t){if(b(t))return!0;let e=t.children;return e?e.some(I):!1}function V(t){for(let e=0;e<t.children.length;e++){let n=t.children[e];if(n.kind==="text"&&(n.value===""||t.children[e+1]?.kind==="text"))return!1}return t.children.every(e=>e.kind!=="element"||V(e))}function W(t){if(!U(t)||!V(t)||!t.children.some(I))return null;let e=[],n=[],r=0,o=a=>{let s=`_n$${r++}`;return e.push({ref:s,expr:a}),s};return i(t,"_el$"),{html:ve(t),tag:t.tag,steps:e,holes:n};function i(a,s){let l=-1;a.children.forEach((d,p)=>{I(d)&&(l=p)});let c=null;for(let d=0;d<=l;d++){let p=a.children[d],u=c?`${c}.nextSibling`:`${s}.firstChild`;if(b(p)){let v=o(u),A=o(`holeEnd(${v})`);n.push({parentRef:s,startRef:v,endRef:A,node:p}),c=A;continue}let m=o(u);p.kind==="element"&&I(p)&&i(p,m),c=m}}}function ve(t){return g(q(t)).split(G).join(he+ge)}function q(t){return{...t,children:t.children.map(e=>b(e)?{kind:"text",value:G}:e.kind==="element"?q(e):e)}}var G="\0fx-hole\0";var P={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Ue={version:2,module:"@fluixi/dom",symbols:[...P.symbols,"template","cloneTemplate","walk"]};var ke={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function xe(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function Y(t){return xe(t)?t:JSON.stringify(t)}function Ne(t){return t.expr!==void 0?t.reactive?`() => (${t.expr})`:`(${t.expr})`:JSON.stringify(t.literal??!0)}function Ie(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function be(t,e,n){let r=t.filter(s=>s.kind==="spread"),i=t.filter(s=>s.kind!=="spread").map(s=>`${Y(s.name)}: ${Ne(s)}`);e!=null&&i.push(`children: ${e}`);let a=`{ ${i.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(s=>s.expr).join(", ")}, ${a})`):a}function Z(t,e,n){return t.length===1?R(t[0],e,n):`[${t.map(r=>R(r,e,n)).join(", ")}]`}function K(t,e,n,r,o){r.add("createMemo"),r.add("createComponent");let i=e.filter(c=>c.kind==="spread"),s=e.filter(c=>c.kind!=="spread").map(c=>`get ${Y(c.name)}() { return ${Ie(c)}; }`);n.length>0&&s.push(`get children() { return ${Z(n,r,o)}; }`);let l=`{ ${s.join(", ")} }`;return i.length>0&&(r.add("mergeProps"),l=`mergeProps(${i.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${t}, ${l}))`}function ye(t,e){let n=J(e.name),r=e.literal;return r===!0||r===void 0?`${t}.setAttribute(${JSON.stringify(n)}, "");`:r===!1||r===null?"":`${t}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(r))});`}var X=!1;function R(t,e,n){switch(t.kind){case"text":return JSON.stringify(t.value);case"expr":return t.reactive?`() => (${t.code})`:`(${t.code})`;case"fragment":return t.children.length===0?"null":Z(t.children,e,n);case"component":return K(t.name,t.props,t.children,e,n);case"control":{let r=ke[t.control]??t.control;return e.add(r),K(r,t.props,t.children,e,n)}case"element":{if(n&&t.static&&!t.svg&&S(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;return n.push({id:s,html:g(t),tag:t.tag,svg:!1}),`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&X){let s=W(t);if(s){e.add("templateNode"),e.add("insert"),e.add("holeEnd"),e.add("holeContent"),e.add("holeScope");let l=`_tmpl$${n.length}`;n.push({id:l,html:s.html,tag:s.tag,svg:!1});let c=[`const _el$ = templateNode(${l}, ${JSON.stringify(s.tag)}, true);`];for(let d of s.steps)c.push(`const ${d.ref} = ${d.expr};`);for(let d of s.holes)c.push(`insert(${d.parentRef}, holeScope(${d.startRef}, () => (${R(d.node,e,n)})), ${d.endRef}, holeContent(${d.startRef}, ${d.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}e.add("createNativeElement");let r=JSON.stringify(t.tag),o="_el$",i=[],a=t.svg?`${r}, true`:r;if(i.push(`const ${o} = createNativeElement(${a});`),t.props.length>0)if(!t.svg&&t.props.every(h))for(let s of t.props)i.push(ye(o,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";i.push(`spread({ element: ${o}, props: ${be(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let l=R(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";i.push(c?`insert(${o}, ${l}, null);`:`insert(${o}, ${l});`)}return i.push(`return ${o};`),`(() => { ${i.join(" ")} })()`}}}function y(t,e){if(!e||e.length===0)return t;let n=new Map(e.map(r=>[r.id,JSON.stringify(r.html)]));return t.replace(/_tmpl\$\d+/g,r=>n.get(r)??r)}var C={name:"imperative",contract:P,emit(t,e){let n=new Set,r=e?.templateClone!==!1?[]:void 0;return X=e?.partialTemplates===!0,{code:R(t,n,r),imports:Array.from(n),templates:r}}};var Ce=t=>"components"in t;function Q(t,e){return t.replace(/\$(\d+)/g,(n,r)=>e[Number(r)]??n)}function Ee(t,e){return typeof e=="string"?{module:e,export:t}:e}function ee(t=[]){let e=new Map,n=[],r=[];for(let a of t){if(!Ce(a)){r.push(a);continue}for(let[s,l]of Object.entries(a.components)){let c=Ee(s,l),d=e.get(s);if(d&&d.module!==c.module){let p=n.find(u=>u.name===s);p?p.modules.push(c.module):n.push({name:s,modules:[d.module,c.module]});continue}e.set(s,c)}}let o=new Map;return{resolve:a=>{if(o.has(a))return o.get(a);let s=e.get(a);if(!s)for(let l of r){let c=a.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){s={module:Q(l.module,c),export:l.export?Q(l.export,c):a};break}}return o.set(a,s),s},names:()=>[...e.keys()],conflicts:()=>n}}import{parseTemplate as we}from"@fluixi/template-parser";function M(t){let e=t.split(/\r\n|\n|\r/),n=0;for(let o=0;o<e.length;o++)/[^ \t]/.test(e[o])&&(n=o);let r="";for(let o=0;o<e.length;o++){let i=e[o].replace(/\t/g," ");o!==0&&(i=i.replace(/^ +/,"")),o!==e.length-1&&(i=i.replace(/ +$/,"")),i&&(o!==n&&(i+=" "),r+=i)}return r}var te=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Te(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function ne(t){return t.charAt(0).toUpperCase()+t.slice(1)}var O=class{constructor(e,n){this.holes=e;this.used=n}hole(e){return this.holes[e]??{code:"undefined",reactive:!1}}emit(e){let{code:n,imports:r,templates:o}=C.emit(e,{});for(let i of r)this.used.add(i);return y(n,o)}lowerRoot(e){let n=this.lowerChildren(e);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(e){let n=[];for(let r=0;r<e.length;r++){let o=e[r];if(o.kind==="Element"||o.kind==="Component"){let a=o.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=r+1;s<e.length&&this.isBlankText(e[s])&&s++;let l=e[s],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(d=>d.kind==="ElseDirective");n.push(this.lowerIf(o,a.hole,c?l:null)),c&&(r=s);continue}if(o.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(o));continue}}let i=this.lowerNode(o);i&&n.push(i)}return n}isBlankText(e){return e.kind==="Text"&&!e.raw&&M(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=M(e.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(e.hole);return{kind:"expr",code:n.code,reactive:n.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(e.children)};case"Element":return this.lowerElement(e);case"Component":return this.lowerComponent(e);default:return null}}lowerElement(e){let n=e.attributes.find(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=e.attributes.filter(i=>i!==n),o=this.lowerComponent({...e,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return o.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),o}return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:this.lowerAttributes(e.attributes),children:this.lowerChildren(e.children),static:!1}}lowerComponent(e){let n=e.tagHole!=null?this.hole(e.tagHole).code:e.tag,r=this.lowerAttributes(e.attributes),{slots:o,rest:i}=this.partitionSlots(e.children);for(let[l,c]of o){let d=c.length===1?c[0]:{kind:"fragment",children:c},p={name:l,kind:"attr",expr:this.emit(d),jsxElement:!0},u=r.findIndex(m=>m.name===l);u>=0?r[u]=p:r.push(p)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?j(`load:${a.strategy}`,a.modifier):void 0;return{kind:"component",name:n,props:r,children:this.lowerChildren(i),...s?{load:s}:{}}}partitionSlots(e){let n=new Map,r=[];for(let o of e){if(o.kind==="Element"||o.kind==="Component"){let i=o.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(i&&i.value&&i.value.kind==="static"){let a={...o,attributes:o.attributes.filter(c=>c!==i)},s=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),l=n.get(i.value.value)??[];l.push(s),n.set(i.value.value,l);continue}}r.push(o)}return{slots:n,rest:r}}lowerIf(e,n,r){let o=this.hole(n),i=[{name:"when",kind:"attr",expr:o.code,reactive:o.reactive}];if(r){let s=this.stripAndLower(r,l=>l.kind==="ElseDirective");i.push({name:"fallback",kind:"attr",expr:this.emit(s),jsxElement:!0})}let a=this.stripAndLower(e,s=>s.kind==="IfDirective");return{kind:"component",name:"Show",props:i,children:[a]}}lowerEach(e){let n=e.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(e);let r=this.hole(n.hole),o=[{name:"each",kind:"attr",expr:r.code,reactive:r.reactive}];if(n.key){let l="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;o.push({name:"by",kind:"attr",expr:l})}let i=this.itemArrow(e),a;if(i){let l={kind:"expr",code:i.body,reactive:i.bodyReactive},c=this.rebuildWithChildren(e,[l]);a=`(${i.params.join(", ")}) => (${this.emit(c)})`}else{let l=this.stripAndLower(e,c=>c.kind==="EachDirective");a=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:o,children:[{kind:"expr",code:a,reactive:!1}]}}itemArrow(e){let n=e.children.filter(r=>!this.isBlankText(r));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(e,n){let r={...e,attributes:e.attributes.filter(o=>!n(o))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(e,n){let r=this.lowerAttributes(e.attributes.filter(o=>o.kind!=="EachDirective"));return e.kind==="Element"?{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:r,children:n,static:!1}:{kind:"component",name:e.tag,props:r,children:n}}lowerAttributes(e){let n=[],r=[],o=!1,i=[],a=!1,s=[];for(let l of e)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":n.push(this.plainAttr(l));break;case"PropertyBinding":n.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"EventBinding":n.push(this.eventProp(l));break;case"RefBinding":n.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let c=this.hole(l.hole);r.push(`${JSON.stringify(l.name)}: ${c.code}`),o=o||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);i.push(`${JSON.stringify(l.name)}: ${c.code}`),a=a||c.reactive;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole).code));break;case"UseDirective":{let c=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!c)break;s.push(l.name!=null&&l.hole!=null?`[${c}, () => (${this.hole(l.hole).code})]`:`[${c}]`);break}}return r.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:o}),i.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${i.join(", ")} }`,reactive:a}),s.length>0&&n.push({name:"use",kind:"attr",expr:`[${s.join(", ")}]`}),n}eventProp(e){let n=e.name.toLowerCase(),r=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+ne(e.name),kind:"event",event:{name:n,delegated:te.has(n)},expr:r};let i=this.wrapHandler(r,e.modifiers),a=this.eventOptions(e.modifiers),s=a?`[${i}, ${a}]`:i;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(e,n){let r=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",o=[];return n.includes("prevent")&&o.push("e.preventDefault();"),n.includes("stop")&&o.push("e.stopPropagation();"),!r&&o.length===0?e:`(e) => { ${r}${o.join(" ")} return (${e})(e); }`}eventOptions(e){let n=[];return e.includes("capture")&&n.push("capture: true"),e.includes("once")&&n.push("once: true"),e.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(e,n){let r=e==="checked",o=r?"change":"input",i=r?"checked":"value";this.used.add("bindPair");let a=`bindPair(${n})`;return[{name:e,kind:"attr",expr:`${a}[0]()`,reactive:!0},{name:"on"+ne(o),kind:"event",event:{name:o,delegated:te.has(o)},expr:`(e) => ${a}[1](e.target.${i})`}]}plainAttr(e){let n=e.value,r=e.name;e.name==="class"?r=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":e.name==="html"&&(r="innerHTML");let i={name:r,kind:"attr"};if(n==null)return i.literal=!0,i;if(n.kind==="static")return i.literal=n.value,i;if(n.kind==="hole"){let l=this.hole(n.hole);return i.expr=l.code,i.reactive=l.reactive,i}let a=!1,s=n.parts.map(l=>{if("text"in l)return Te(l.text);let c=this.hole(l.hole);return a=a||c.reactive,"${"+c.code+"}"}).join("");return i.expr="`"+s+"`",i.reactive=a,i}};function re(t,e,n,r={}){let{root:o}=we(t,{svg:r.svg});return new O(e,n).lowerRoot(o.children)}function $e(t){let e=[],n=0;return t.statics.forEach((r,o)=>{if(e.push({kind:"static",text:r,start:n}),n+=r.length,o<t.holes.length){let i=n+t.holes[o].code.length;e.push({kind:"hole",index:o,start:n,end:i}),n=i}}),e}function ct(t,e={}){if(t.statics.length!==t.holes.length+1)throw new Error(`[fluixi] compileTemplate: ${t.statics.length} static runs for ${t.holes.length} holes — a template always has exactly one more.`);return Se($e(t),t.holes,e)}function Se(t,e,n={}){let r=new Set,o=re(t,[...e],r,{svg:n.svg});D(o),H(o,{resolver:ee(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:l=>l.load}),F(o);let{code:i,imports:a,templates:s}=C.emit(o,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let l of a)r.add(l);return n.hoistTemplates?{code:i,imports:[...r],ir:o,templates:s}:{code:y(i,s),imports:[...r],ir:o}}export{Se as compilePieces,ct as compileTemplate};
|
|
1
|
+
function pe(t){switch(t.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return t.reactive?"reactive-prop":t.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function F(t){let e=[],n=new Map,i=r=>{switch(r.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let o of r.children)i(o);return!1;case"fragment":for(let o of r.children)i(o);return!1;case"element":{let o=!0;for(let s of r.children)i(s)||(o=!1);let a;for(let s of r.props)if(a=pe(s),a)break;return!a&&!o&&(a=de(r)),r.static=!a,a?n.set(r,a):e.push(r),r.static}default:return!1}};for(let r of Array.isArray(t)?t:[t])i(r);return{staticElements:e,reasons:n}}function de(t){for(let e of t.children){if(e.kind==="expr")return"expression-child";if(e.kind==="component")return"component-child";if(e.kind==="control")return"control-child";if(e.kind==="element"&&!e.static||e.kind==="fragment")return"expression-child"}return"expression-child"}var b={kind:"eager"},fe=["pointerdown","focusin","keydown"],H=new Set(["eager","idle","visible","interaction","media","never"]),h=class extends Error{};function B(t,e){let n=t.slice(5);if(!H.has(n))throw new h(`Unknown load strategy 'load:${n}'. Expected one of ${[...H].join(", ")}.`);switch(n){case"eager":return b;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return e?{kind:"visible",rootMargin:e}:{kind:"visible"};case"interaction":return{kind:"interaction",events:e?me(e):[...fe]};case"media":if(!e)throw new h(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new h(`Unhandled load strategy '${n}'.`)}}function me(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new h("'load:interaction' was given no event names.");return e}function J(t){return t.kind!=="eager"&&t.kind!=="never"}var w=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],T=["Suspense","SuspenseList","Await"],k=["Router","Outlet","Redirect","Link"],Je=[...w,...T,...k],A=new Set([...w,...T]);function V(t={}){let{controlFlowModule:e="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:i="@fluixi/core/router"}=t,r={};for(let o of w)r[o]=e;for(let o of T)r[o]=n;for(let o of k)r[o]=i;return r}function U(t,e={}){let{resolver:n,isBound:i,modules:r,strategyFor:o}=e,a=V(r),s=new Map,u=new Set,c=p=>{let{name:d}=p;if(!d||d.includes(".")||i?.(d))return;let f=l(d);if(!f){u.add(d);return}let m=f.origin==="builtin"&&A.has(d)?b:o?.(p)??b;p.source={...f,loading:m},s.set(d,p.source)},l=p=>{if(A.has(p))return{module:a[p],export:p,origin:"builtin"};let d=n?.resolve(p);if(d)return{module:d.module,export:d.export,origin:"rule"};if(k.includes(p))return{module:a[p],export:p,origin:"builtin"}};return I(t,p=>{p.kind==="component"&&c(p)}),{resolved:s,unresolved:[...u]}}function I(t,e){let n=Array.isArray(t)?t:[t];for(let i of n){e(i);let r=i.children;r&&I(r,e)}}function K(t){let e=[];I(t,o=>{o.kind==="component"&&o.source&&e.push(o)});let n=new Set,i=new Set;for(let o of e){let{module:a,loading:s}=o.source;s.kind==="eager"&&n.add(a),s.kind==="never"&&i.add(a)}let r=new Map;for(let o of e){let a=o.source;J(a.loading)&&n.has(a.module)&&(a.loading={kind:"eager"},r.set(a.module,(r.get(a.module)??0)+1))}return{collapsed:r,conflicted:[...i].filter(o=>n.has(o))}}var ge=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),z={className:"class",htmlFor:"for"},he=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Re=new Set(["script","style","textarea","title"]);function P(t){return Re.has(t)}function W(t){return z[t]??t}function R(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!he.has(t.name)}function M(t){if(!t.static||P(t.tag))return!1;for(let e of t.props)if(!R(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&M(e)))return!1;return!0}function v(t){let e=t.props.map(Ne).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return ge.has(t.tag)?n:`${n}${t.children.map(ve).join("")}</${t.tag}>`}function ve(t){if(t.kind==="text")return ye(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return v(t)}function Ne(t){let e=z[t.name]??t.name,n=t.literal;return n===!0||n===void 0?` ${e}`:n===!1||n===null?"":` ${e}="${xe(String(n))}"`}function xe(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function ye(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function O(t){let e=[],n,i=r=>{n??=r.at?.file,e.push(r.at?.line??0,r.at?.column??0);for(let o of r.children)o.kind==="element"&&i(o)};return i(t),n&&e.some(r=>r!==0)?{file:n,pos:e}:void 0}var be="<!--fx-->",ke="<!--fx/-->";function S(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function Ie(t){return t.kind==="text"||t.kind==="element"&&G(t)}function G(t){return t.svg||P(t.tag)||!t.props.every(e=>R(e))?!1:t.children.every(e=>Ie(e)||S(e))}function E(t){if(S(t))return!0;let e=t.children;return e?e.some(E):!1}function q(t){for(let e=0;e<t.children.length;e++){let n=t.children[e];if(n.kind==="text"&&(n.value===""||t.children[e+1]?.kind==="text"))return!1}return t.children.every(e=>e.kind!=="element"||q(e))}function Y(t){if(!G(t)||!q(t)||!t.children.some(E))return null;let e=[],n=[],i=0,r=a=>{let s=`_n$${i++}`;return e.push({ref:s,expr:a}),s};return o(t,"_el$"),{html:Ee(t),tag:t.tag,steps:e,holes:n};function o(a,s){let u=-1;a.children.forEach((l,p)=>{E(l)&&(u=p)});let c=null;for(let l=0;l<=u;l++){let p=a.children[l],d=c?`${c}.nextSibling`:`${s}.firstChild`;if(S(p)){let m=r(d),y=r(`holeEnd(${m})`);n.push({parentRef:s,startRef:m,endRef:y,node:p}),c=y;continue}let f=r(d);p.kind==="element"&&E(p)&&o(p,f),c=f}}}function Ee(t){return v(Z(t)).split(X).join(be+ke)}function Z(t){return{...t,children:t.children.map(e=>S(e)?{kind:"text",value:X}:e.kind==="element"?Z(e):e)}}var X="\0fx-hole\0";var D={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Qe={version:2,module:"@fluixi/dom",symbols:[...D.symbols,"template","cloneTemplate","walk"]};var g="@fluixi/reactive/signal",_={$signal:{export:"signal",module:g,returns:"signal-handle"},$memo:{export:"memo",module:g,returns:"memo-handle"},$effect:{export:"effect",module:g,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:g,returns:"resource-handle"},$selector:{export:"createSelector",module:g,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:g,returns:"memo-accessor"},$untrack:{export:"untrack",module:g,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}};var tt=new RegExp(`\\$(?:${Object.keys(_).map(t=>t.slice(1)).join("|")})\\s*\\(`);var Q="__fx_source";var Se="__fx_hole",N=(t,e,n,i)=>`(globalThis.${Se} ?? ((f) => f))(${t},${e},${n}${i===void 0?"":`,${JSON.stringify(i)}`})`,$e="__fx_props",ee=(t,e)=>`(globalThis.${$e} ?? ((p) => p))(${t},${JSON.stringify(e)})`;var Ce={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function we(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function re(t){return we(t)?t:JSON.stringify(t)}function Te(t){if(t.expr!==void 0){if(t.name==="ref"&&t.at)return N(`(${t.expr})`,t.at.line,t.at.column,t.expr);if(!t.reactive)return`(${t.expr})`;let e=`() => (${t.expr})`;return t.at?N(e,t.at.line,t.at.column,t.directive):e}return JSON.stringify(t.literal??!0)}function Ae(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function Pe(t,e,n){let i=t.filter(s=>s.kind==="spread"),o=t.filter(s=>s.kind!=="spread").map(s=>`${re(s.name)}: ${Te(s)}`);e!=null&&o.push(`children: ${e}`);let a=`{ ${o.join(", ")} }`;return i.length>0?(n.add("mergeProps"),`mergeProps(${i.map(s=>s.expr).join(", ")}, ${a})`):a}function te(t,e){return e?N(t,e.line,e.column):t}function ie(t,e,n){return t.length===1?x(t[0],e,n):`[${t.map(i=>x(i,e,n)).join(", ")}]`}function ne(t,e,n,i,r,o){i.add("createMemo"),i.add("createComponent");let a=e.filter(d=>d.kind==="spread"),s=e.filter(d=>d.kind!=="spread"),u=s.map(d=>`get ${re(d.name)}() { return ${Ae(d)}; }`);n.length>0&&u.push(`get children() { return ${ie(n,i,r)}; }`);let c=`{ ${u.join(", ")} }`;a.length>0&&(i.add("mergeProps"),c=`mergeProps(${a.map(d=>d.expr).join(", ")}, ${c})`);let l={};for(let d of s)d.at&&(l[d.name]=[d.at.line,d.at.column]);return Object.keys(l).length&&(c=ee(c,l)),`createMemo((${o?`globalThis.${Q}?.(${JSON.stringify(o.file)},${o.line},${o.column},${JSON.stringify(t)}), `:""}() => createComponent(${t}, ${c})))`}function Me(t,e){let n=W(e.name),i=e.literal;return i===!0||i===void 0?`${t}.setAttribute(${JSON.stringify(n)}, "");`:i===!1||i===null?"":`${t}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(i))});`}var oe=!1;function x(t,e,n){switch(t.kind){case"text":return JSON.stringify(t.value);case"expr":{if(!t.reactive)return`(${t.code})`;let i=`() => (${t.code})`;return t.at?N(i,t.at.line,t.at.column):i}case"fragment":return t.children.length===0?"null":ie(t.children,e,n);case"component":return te(ne(t.name,t.props,t.children,e,n,t.at),t.bindAt??t.at);case"control":{let i=Ce[t.control]??t.control;return e.add(i),te(ne(i,t.props,t.children,e,n),t.bindAt)}case"element":{if(n&&t.static&&!t.svg&&M(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;n.push({id:s,html:v(t),tag:t.tag,svg:!1});let u=O(t);return u?`templateNode(${s}, ${JSON.stringify(t.tag)}, false, false, ${JSON.stringify(u)})`:`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&oe){let s=Y(t);if(s){e.add("templateNode"),e.add("insert"),e.add("holeEnd"),e.add("holeContent"),e.add("holeScope");let u=`_tmpl$${n.length}`;n.push({id:u,html:s.html,tag:s.tag,svg:!1});let c=O(t),l=[`const _el$ = templateNode(${u}, ${JSON.stringify(s.tag)}, true${c?`, false, ${JSON.stringify(c)}`:""});`];for(let p of s.steps)l.push(`const ${p.ref} = ${p.expr};`);for(let p of s.holes)l.push(`insert(${p.parentRef}, holeScope(${p.startRef}, () => (${x(p.node,e,n)})), ${p.endRef}, holeContent(${p.startRef}, ${p.endRef}));`);return l.push("return _el$;"),`(() => { ${l.join(" ")} })()`}}e.add("createNativeElement");let i=JSON.stringify(t.tag),r="_el$",o=[],a=t.at?`${i}, ${t.svg}, ${JSON.stringify(t.at)}`:t.svg?`${i}, true`:i;if(o.push(`const ${r} = createNativeElement(${a});`),t.props.length>0)if(!t.svg&&t.props.every(R))for(let s of t.props)o.push(Me(r,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";o.push(`spread({ element: ${r}, props: ${Pe(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let u=x(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";o.push(c?`insert(${r}, ${u}, null);`:`insert(${r}, ${u});`)}return o.push(`return ${r};`),`(() => { ${o.join(" ")} })()`}}}function $(t,e){if(!e||e.length===0)return t;let n=new Map(e.map(i=>[i.id,JSON.stringify(i.html)]));return t.replace(/_tmpl\$\d+/g,i=>n.get(i)??i)}var C={name:"imperative",contract:D,emit(t,e){let n=new Set,i=e?.templateClone!==!1?[]:void 0;return oe=e?.partialTemplates===!0,{code:x(t,n,i),imports:Array.from(n),templates:i}}};var Oe=t=>"components"in t;function se(t,e){return t.replace(/\$(\d+)/g,(n,i)=>e[Number(i)]??n)}function De(t,e){return typeof e=="string"?{module:e,export:t}:e}function ae(t=[]){let e=new Map,n=[],i=[];for(let a of t){if(!Oe(a)){i.push(a);continue}for(let[s,u]of Object.entries(a.components)){let c=De(s,u),l=e.get(s);if(l&&l.module!==c.module){let p=n.find(d=>d.name===s);p?p.modules.push(c.module):n.push({name:s,modules:[l.module,c.module]});continue}e.set(s,c)}}let r=new Map;return{resolve:a=>{if(r.has(a))return r.get(a);let s=e.get(a);if(!s)for(let u of i){let c=a.match(new RegExp(u.match.source,u.match.flags.replace("g","")));if(c){s={module:se(u.module,c),export:u.export?se(u.export,c):a};break}}return r.set(a,s),s},names:()=>[...e.keys()],conflicts:()=>n}}import{parseTemplate as _e}from"@fluixi/template-parser";function j(t){let e=t.split(/\r\n|\n|\r/),n=0;for(let r=0;r<e.length;r++)/[^ \t]/.test(e[r])&&(n=r);let i="";for(let r=0;r<e.length;r++){let o=e[r].replace(/\t/g," ");r!==0&&(o=o.replace(/^ +/,"")),r!==e.length-1&&(o=o.replace(/ +$/,"")),o&&(r!==n&&(o+=" "),i+=o)}return i}var le=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function je(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function ce(t){return t.charAt(0).toUpperCase()+t.slice(1)}var L=class{constructor(e,n,i,r){this.holes=e;this.used=n;this.sourceFile=i;this.positionAt=r}tagAt(e){let n=e.loc?.start;if(!this.sourceFile||!this.positionAt||n==null)return;let{line:i,column:r}=this.positionAt(n);return{file:this.sourceFile,line:i,column:r}}hole(e){return this.holes[e]??{code:"undefined",reactive:!1}}emit(e){let{code:n,imports:i,templates:r}=C.emit(e,{});for(let o of i)this.used.add(o);return $(n,r)}lowerRoot(e){let n=this.lowerChildren(e);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(e){let n=[];for(let i=0;i<e.length;i++){let r=e[i];if(r.kind==="Element"||r.kind==="Component"){let a=r.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=i+1;s<e.length&&this.isBlankText(e[s])&&s++;let u=e[s],c=u&&(u.kind==="Element"||u.kind==="Component")&&u.attributes.some(l=>l.kind==="ElseDirective");n.push(this.lowerIf(r,a.hole,c?u:null)),c&&(i=s);continue}if(r.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(r));continue}}let o=this.lowerNode(r);o&&n.push(o)}return n}isBlankText(e){return e.kind==="Text"&&!e.raw&&j(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=j(e.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(e.hole);return{kind:"expr",code:n.code,reactive:n.reactive,...n.at?{at:n.at}:{}}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(e.children)};case"Element":return this.lowerElement(e);case"Component":return this.lowerComponent(e);default:return null}}lowerElement(e){let n=e.attributes.find(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=e.attributes.filter(a=>a!==n),o=this.lowerComponent({...e,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return o.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),o}let i=this.tagAt(e);return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:this.lowerAttributes(e.attributes),children:this.lowerChildren(e.children),static:!1,...i?{at:i}:{}}}lowerComponent(e){let n=e.tagHole!=null?this.hole(e.tagHole).code:e.tag,i=this.lowerAttributes(e.attributes),{slots:r,rest:o}=this.partitionSlots(e.children);for(let[l,p]of r){let d=p.length===1?p[0]:{kind:"fragment",children:p},f={name:l,kind:"attr",expr:this.emit(d),jsxElement:!0},m=i.findIndex(y=>y.name===l);m>=0?i[m]=f:i.push(f)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?B(`load:${a.strategy}`,a.modifier):void 0,u=i.find(l=>l.at&&l.reactive)?.at,c=this.tagAt(e);return{kind:"component",name:n,props:i,children:this.lowerChildren(o),...c?{at:c}:{},...u?{bindAt:u}:{},...s?{load:s}:{}}}partitionSlots(e){let n=new Map,i=[];for(let r of e){if(r.kind==="Element"||r.kind==="Component"){let o=r.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(o&&o.value&&o.value.kind==="static"){let a={...r,attributes:r.attributes.filter(c=>c!==o)},s=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),u=n.get(o.value.value)??[];u.push(s),n.set(o.value.value,u);continue}}i.push(r)}return{slots:n,rest:i}}lowerIf(e,n,i){let r=this.hole(n),o=[{name:"when",kind:"attr",expr:r.code,reactive:r.reactive,...r.at?{at:r.at}:{}}];if(i){let u=this.stripAndLower(i,c=>c.kind==="ElseDirective");o.push({name:"fallback",kind:"attr",expr:this.emit(u),jsxElement:!0})}let a=this.stripAndLower(e,u=>u.kind==="IfDirective"),s=this.tagAt(e);return{kind:"component",name:"Show",props:o,children:[a],...s?{at:s}:{},...r.at?{bindAt:r.at}:{}}}lowerEach(e){let n=e.attributes.find(c=>c.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(e);let i=this.hole(n.hole),r=[{name:"each",kind:"attr",expr:i.code,reactive:i.reactive,...i.at?{at:i.at}:{}}];if(n.key){let c="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;r.push({name:"by",kind:"attr",expr:c})}let o=this.itemArrow(e),a;if(o){let c={kind:"expr",code:o.body,reactive:o.bodyReactive},l=this.rebuildWithChildren(e,[c]);a=`(${o.params.join(", ")}) => (${this.emit(l)})`}else{let c=this.stripAndLower(e,l=>l.kind==="EachDirective");a=`() => (${this.emit(c)})`}let s=[{kind:"expr",code:a,reactive:!1}],u=this.tagAt(e);return{kind:"component",name:"For",props:r,children:s,...u?{at:u}:{},...i.at?{bindAt:i.at}:{}}}itemArrow(e){let n=e.children.filter(i=>!this.isBlankText(i));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(e,n){let i={...e,attributes:e.attributes.filter(r=>!n(r))};return i.kind==="Element"?this.lowerElement(i):this.lowerComponent(i)}rebuildWithChildren(e,n){let i=this.lowerAttributes(e.attributes.filter(r=>r.kind!=="EachDirective"));if(e.kind==="Element"){let r=this.tagAt(e);return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:i,children:n,static:!1,...r?{at:r}:{}}}return{kind:"component",name:e.tag,props:i,children:n}}lowerAttributes(e){let n=[],i=[],r=!1,o,a=[],s=!1,u,c=[];for(let l of e)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":n.push(this.plainAttr(l));break;case"PropertyBinding":n.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive,...this.hole(l.hole).at?{at:this.hole(l.hole).at}:{}});break;case"EventBinding":n.push(this.eventProp(l));break;case"RefBinding":n.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive,...this.hole(l.hole).at?{at:this.hole(l.hole).at}:{}});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let p=this.hole(l.hole);i.push(`${JSON.stringify(l.name)}: ${p.code}`),r=r||p.reactive,o??=p.at;break}case"StyleDirective":{let p=this.hole(l.hole);a.push(`${JSON.stringify(l.name)}: ${p.code}`),s=s||p.reactive,u??=p.at;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole)));break;case"UseDirective":{let p=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!p)break;c.push(l.name!=null&&l.hole!=null?`[${p}, () => (${this.hole(l.hole).code})]`:`[${p}]`);break}}return i.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${i.join(", ")} }`,reactive:r,...o?{at:o}:{}}),a.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${a.join(", ")} }`,reactive:s,...u?{at:u}:{}}),c.length>0&&n.push({name:"use",kind:"attr",expr:`[${c.join(", ")}]`}),n}eventProp(e){let n=e.name.toLowerCase(),i=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+ce(e.name),kind:"event",event:{name:n,delegated:le.has(n)},expr:i};let o=this.wrapHandler(i,e.modifiers),a=this.eventOptions(e.modifiers),s=a?`[${o}, ${a}]`:o;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(e,n){let i=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",r=[];return n.includes("prevent")&&r.push("e.preventDefault();"),n.includes("stop")&&r.push("e.stopPropagation();"),!i&&r.length===0?e:`(e) => { ${i}${r.join(" ")} return (${e})(e); }`}eventOptions(e){let n=[];return e.includes("capture")&&n.push("capture: true"),e.includes("once")&&n.push("once: true"),e.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(e,n){let i=n.code,r=e==="checked",o=r?"change":"input",a=r?"checked":"value";this.used.add("bindPair");let s=`bindPair(${i})`;return[{name:e,kind:"attr",expr:`${s}[0]()`,reactive:!0,directive:`bind:${e}`,...n.at?{at:n.at}:{}},{name:"on"+ce(o),kind:"event",event:{name:o,delegated:le.has(o)},expr:`(e) => ${s}[1](e.target.${a})`}]}plainAttr(e){let n=e.value,i=e.name;e.name==="class"?i=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":e.name==="html"&&(i="innerHTML");let o={name:i,kind:"attr"};if(n==null)return o.literal=!0,o;if(n.kind==="static")return o.literal=n.value,o;if(n.kind==="hole"){let c=this.hole(n.hole);return o.expr=c.code,o.reactive=c.reactive,c.at&&(o.at=c.at),o}let a=!1,s,u=n.parts.map(c=>{if("text"in c)return je(c.text);let l=this.hole(c.hole);return a=a||l.reactive,s??=l.at,"${"+l.code+"}"}).join("");return o.expr="`"+u+"`",o.reactive=a,s&&(o.at=s),o}};function ue(t,e,n,i={}){let{root:r}=_e(t,{svg:i.svg});return new L(e,n,i.sourceFile,i.positionAt).lowerRoot(r.children)}function Le(t){let e=[],n=0;return t.statics.forEach((i,r)=>{if(e.push({kind:"static",text:i,start:n}),n+=i.length,r<t.holes.length){let o=n+t.holes[r].code.length;e.push({kind:"hole",index:r,start:n,end:o}),n=o}}),e}function Tt(t,e={}){if(t.statics.length!==t.holes.length+1)throw new Error(`[fluixi] compileTemplate: ${t.statics.length} static runs for ${t.holes.length} holes — a template always has exactly one more.`);return Fe(Le(t),t.holes,e)}function Fe(t,e,n={}){let i=new Set,r=ue(t,[...e],i,{svg:n.svg,...n.sourceFile?{sourceFile:n.sourceFile}:{},...n.positionAt?{positionAt:n.positionAt}:{}});F(r),U(r,{resolver:ae(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:u=>u.load}),K(r);let{code:o,imports:a,templates:s}=C.emit(r,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let u of a)i.add(u);return n.hoistTemplates?{code:o,imports:[...i],ir:r,templates:s}:{code:$(o,s),imports:[...i],ir:r}}export{Fe as compilePieces,Tt as compileTemplate};
|
package/dist/lower/jsx.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var n in t)f(e,n,{get:t[n],enumerable:!0})},$=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of C(t))!X.call(e,r)&&r!==n&&f(e,r,{get:()=>t[r],enumerable:!(o=L(t,r))||o.enumerable});return e};var T=e=>$(f({},"__esModule",{value:!0}),e);var H={};A(H,{SVG_TAGS:()=>I,buildJsxIR:()=>W});module.exports=T(H);var D={kind:"eager"},P=["pointerdown","focusin","keydown"],k=new Set(["eager","idle","visible","interaction","media","never"]),c=class extends Error{};function m(e){return e.startsWith("load:")}function v(e,t){let n=e.slice(5);if(!k.has(n))throw new c(`Unknown load strategy 'load:${n}'. Expected one of ${[...k].join(", ")}.`);switch(n){case"eager":return D;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return t?{kind:"visible",rootMargin:t}:{kind:"visible"};case"interaction":return{kind:"interaction",events:t?M(t):[...P]};case"media":if(!t)throw new c(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new c(`Unhandled load strategy '${n}'.`)}}function M(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new c("'load:interaction' was given no event names.");return t}var O="children";function y(e){switch(e.kind){case"call":return!0;case"member":return e.property!==O;case"compound":return e.parts.some(y);case"opaque":return!1}}var j=new Set(["CallExpression","OptionalCallExpression"]),q=new Set(["MemberExpression","OptionalMemberExpression"]);function x(e){if(!e)return{kind:"opaque"};if(j.has(e.type))return{kind:"call"};if(q.has(e.type)){let t=e.property;return{kind:"member",property:!(e.computed===!0)&&t?.type==="Identifier"?t.name:null}}return e.type==="ConditionalExpression"?{kind:"compound",parts:[e.test,e.consequent,e.alternate].map(l)}:e.type==="LogicalExpression"||e.type==="BinaryExpression"?{kind:"compound",parts:[e.left,e.right].map(l)}:e.type==="TemplateLiteral"?{kind:"compound",parts:e.expressions.map(l)}:e.type==="ObjectExpression"?{kind:"compound",parts:e.properties.filter(n=>(n.type==="ObjectProperty"||n.type==="Property")&&n.computed!==!0).map(n=>l(n.value))}:e.type==="ArrayExpression"?{kind:"compound",parts:e.elements.filter(n=>n!=null&&n.type!=="SpreadElement").map(l)}:{kind:"opaque"}}var l=e=>x(e);function F(e){switch(e.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return e.reactive?"reactive-prop":e.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function S(e){let t=[],n=new Map,o=r=>{switch(r.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let s of r.children)o(s);return!1;case"fragment":for(let s of r.children)o(s);return!1;case"element":{let s=!0;for(let a of r.children)o(a)||(s=!1);let i;for(let a of r.props)if(i=F(a),i)break;return!i&&!s&&(i=B(r)),r.static=!i,i?n.set(r,i):t.push(r),r.static}default:return!1}};for(let r of Array.isArray(e)?e:[e])o(r);return{staticElements:t,reasons:n}}function B(e){for(let t of e.children){if(t.kind==="expr")return"expression-child";if(t.kind==="component")return"component-child";if(t.kind==="control")return"control-child";if(t.kind==="element"&&!t.static||t.kind==="fragment")return"expression-child"}return"expression-child"}function R(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let r=0;r<t.length;r++)/[^ \t]/.test(t[r])&&(n=r);let o="";for(let r=0;r<t.length;r++){let s=t[r].replace(/\t/g," ");r!==0&&(s=s.replace(/^ +/,"")),r!==t.length-1&&(s=s.replace(/ +$/,"")),s&&(r!==n&&(s+=" "),o+=s)}return o}var I=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),G=/^on[A-Z]/,_=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),w=e=>y(x(e)),u=(e,t)=>{if(!t.sourceFile)return;let n=e.loc?.start;return n?{line:n.line,column:n.column}:void 0};function d(e){if(e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral"||e.type==="Literal"&&(typeof e.value=="string"||typeof e.value=="number"||typeof e.value=="boolean"))return e.value}var g=e=>!!e&&typeof d(e)=="string";function K(e,t){return e.type==="JSXIdentifier"?{tag:e.name,component:e.name[0]!==e.name[0].toLowerCase()}:e.type==="JSXMemberExpression"?{tag:t.code(e),component:!0}:e.type==="JSXNamespacedName"?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function h(e){return e.type==="JSXIdentifier"?e.name==="class"?"className":e.name:e.type==="JSXNamespacedName"?`${e.namespace.name}:${e.name.name}`:"unknown"}function U(e,t){let n=h(e.name),o=G.test(n),r=o||n.startsWith("on:")||n==="ref",i={name:n,kind:o?"event":"attr"};if(o){let p=n.slice(2).toLowerCase();i.event={name:p,delegated:_.has(p)}}let a=e.value;if(a==null)return i.literal=!0,i.at=u(e,t),i;if(g(a))return i.literal=d(a),i.at=u(a,t),i;if(a.type==="JSXExpressionContainer"&&a.expression?.type!=="JSXEmptyExpression"){let p=a.expression,E=d(p);return E!==void 0?(i.literal=E,i.at=u(p,t),i):(i.expr=t.code(p),i.reactive=r?!1:w(p),i.at=u(p,t),(p.type==="JSXElement"||p.type==="JSXFragment")&&(i.jsxElement=!0),i)}return i.literal=!0,i}function N(e,t){let n=e.value;return n==null?null:g(n)?JSON.stringify(d(n)):n.type==="JSXExpressionContainer"&&n.expression?.type!=="JSXEmptyExpression"?t.code(n.expression):null}function V(e,t){let n=[],o=[];for(let r of e){if(r.type==="JSXSpreadAttribute"){n.push({name:"",kind:"spread",expr:t.code(r.argument)});continue}if(r.type!=="JSXAttribute"||m(h(r.name)))continue;let s=r.name.type==="JSXNamespacedName"?r.name.namespace.name:null;if(s==="use"){let i=r.name.name.name;t.used.add(i);let a=N(r,t);o.push(a!=null?`[${i}, () => (${a})]`:`[${i}]`);continue}if(s==="oncapture"){let i=r.name.name.name.toLowerCase(),a=N(r,t)??"undefined";n.push({name:"on:"+i,kind:"attr",expr:`[${a}, { capture: true }]`});continue}n.push(U(r,t))}return o.length>0&&n.push({name:"use",kind:"attr",expr:`[${o.join(", ")}]`}),n}function b(e,t){let n=[];for(let o of e)if(o.type==="JSXText"){let r=R(o.value);r&&n.push({kind:"text",value:r})}else if(o.type==="JSXExpressionContainer"){if(o.expression?.type!=="JSXEmptyExpression"){let r=o.expression,s=w(r);n.push({kind:"expr",code:t.code(r),reactive:s,...s?{at:u(r,t)}:{}})}}else o.type==="JSXElement"||o.type==="JSXFragment"?n.push(J(o,t)):o.type==="JSXSpreadChild"&&n.push({kind:"expr",code:t.code(o.expression),reactive:!1});return n}function z(e){for(let t of e){if(t.type!=="JSXAttribute")continue;let n=h(t.name);if(m(n)){if(t.value&&!g(t.value))throw new c(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return v(n,t.value?d(t.value):null)}}}function J(e,t){if(e.type==="JSXFragment")return{kind:"fragment",children:b(e.children,t)};let{tag:n,component:o}=K(e.openingElement.name,t),r=V(e.openingElement.attributes,t),s=b(e.children,t),i=t.sourceFile&&e.loc?.start?{file:t.sourceFile,line:e.loc.start.line,column:e.loc.start.column}:void 0;if(o){let a=z(e.openingElement.attributes);return{kind:"component",name:n,props:r,children:s,...a?{load:a}:{},...i?{at:i}:{}}}return{kind:"element",tag:n,svg:I.has(n),props:r,children:s,static:!1,...i?{at:i}:{}}}function W(e,t){let n=J(e,t);return S(n),n}
|
package/dist/lower/jsx.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface JsxContext {
|
|
|
16
16
|
code(node: Node): string;
|
|
17
17
|
/** Runtime symbols the emitted code needs; `use:` directives register here too. */
|
|
18
18
|
used: Set<string>;
|
|
19
|
+
/** The file being compiled, when component usage sites are to be recorded. */
|
|
20
|
+
sourceFile?: string;
|
|
19
21
|
}
|
|
20
22
|
export declare const SVG_TAGS: Set<string>;
|
|
21
23
|
/** Build IR from a JSXElement or JSXFragment. */
|
package/dist/lower/jsx.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../../src/lower/jsx.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAkB,MAAM,EAAsB,MAAM,gBAAgB,CAAC;AAOjF,UAAU,IAAI;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,+EAA+E;IAC/E,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;IACzB,mFAAmF;IACnF,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../../src/lower/jsx.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAkB,MAAM,EAAsB,MAAM,gBAAgB,CAAC;AAOjF,UAAU,IAAI;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,+EAA+E;IAC/E,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;IACzB,mFAAmF;IACnF,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,QAAQ,aAGnB,CAAC;AA4MH,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM,CAM9D"}
|