@lark.js/mvc 0.0.4 → 0.0.6

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.
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/runtime.ts
21
+ var runtime_exports = {};
22
+ __export(runtime_exports, {
23
+ encHtml: () => encHtml,
24
+ encQuote: () => encQuote,
25
+ encUri: () => encUri,
26
+ refFn: () => refFn,
27
+ strSafe: () => strSafe
28
+ });
29
+ module.exports = __toCommonJS(runtime_exports);
30
+ var HTML_ENT_MAP = {
31
+ "&": "amp",
32
+ "<": "lt",
33
+ ">": "gt",
34
+ '"': "#34",
35
+ "'": "#39",
36
+ "`": "#96"
37
+ };
38
+ var HTML_ENT_REGEXP = /[&<>"`']/g;
39
+ var strSafe = (v) => "" + (v == null ? "" : v);
40
+ var encHtml = (v) => strSafe(v).replace(HTML_ENT_REGEXP, (m) => "&" + HTML_ENT_MAP[m] + ";");
41
+ var URI_ENT_MAP = {
42
+ "!": "%21",
43
+ "'": "%27",
44
+ "(": "%28",
45
+ ")": "%29",
46
+ "*": "%2A"
47
+ };
48
+ var URI_ENT_REGEXP = /[!')(*]/g;
49
+ var encUri = (v) => encodeURIComponent(strSafe(v)).replace(URI_ENT_REGEXP, (m) => URI_ENT_MAP[m]);
50
+ var QUOTE_REGEXP = /['"\\]/g;
51
+ var encQuote = (v) => strSafe(v).replace(QUOTE_REGEXP, "\\$&");
52
+ var refFn = (ref, value, key) => {
53
+ const SPLITTER = String.fromCharCode(30);
54
+ const counter = ref[SPLITTER];
55
+ for (let i = counter; --i; ) {
56
+ key = SPLITTER + i;
57
+ if (ref[key] === value) return key;
58
+ }
59
+ key = SPLITTER + ref[SPLITTER]++;
60
+ ref[key] = value;
61
+ return key;
62
+ };
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ encHtml,
66
+ encQuote,
67
+ encUri,
68
+ refFn,
69
+ strSafe
70
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Template runtime helpers.
3
+ *
4
+ * Compiled templates import these helpers from `@lark.js/mvc/runtime` instead
5
+ * of inlining the implementations. That keeps each compiled `.html` module
6
+ * small — no more ~400 bytes of duplicated helper code per template.
7
+ *
8
+ * The helpers below are aliased to `$strSafe / $encHtml / $encUri / $encQuote /
9
+ * $refFn` inside the IIFE that the compiler produces — see `compiler.ts`.
10
+ */
11
+ /** Null-safe `String(value)` — `null`/`undefined` become `""`. */
12
+ declare const strSafe: (v: unknown) => string;
13
+ /** HTML-escape a value for safe embedding in markup. */
14
+ declare const encHtml: (v: unknown) => string;
15
+ /** Percent-encode a value, with extra characters escaped for stricter URIs. */
16
+ declare const encUri: (v: unknown) => string;
17
+ /** Backslash-escape quotes and backslashes for attribute string contents. */
18
+ declare const encQuote: (v: unknown) => string;
19
+ /**
20
+ * Look up (or assign) a stable refData token for an object value.
21
+ *
22
+ * Templates use `{{@expr}}` to pass live JS values (objects/functions) through
23
+ * the DOM by writing the token into an attribute, then resolving it back to
24
+ * the original value when the event fires. `refData[SPLITTER]` holds the
25
+ * monotonic counter; `refData[SPLITTER + n]` holds the slot.
26
+ */
27
+ declare const refFn: (ref: Record<string, unknown>, value: unknown, key: string) => string;
28
+
29
+ export { encHtml, encQuote, encUri, refFn, strSafe };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Template runtime helpers.
3
+ *
4
+ * Compiled templates import these helpers from `@lark.js/mvc/runtime` instead
5
+ * of inlining the implementations. That keeps each compiled `.html` module
6
+ * small — no more ~400 bytes of duplicated helper code per template.
7
+ *
8
+ * The helpers below are aliased to `$strSafe / $encHtml / $encUri / $encQuote /
9
+ * $refFn` inside the IIFE that the compiler produces — see `compiler.ts`.
10
+ */
11
+ /** Null-safe `String(value)` — `null`/`undefined` become `""`. */
12
+ declare const strSafe: (v: unknown) => string;
13
+ /** HTML-escape a value for safe embedding in markup. */
14
+ declare const encHtml: (v: unknown) => string;
15
+ /** Percent-encode a value, with extra characters escaped for stricter URIs. */
16
+ declare const encUri: (v: unknown) => string;
17
+ /** Backslash-escape quotes and backslashes for attribute string contents. */
18
+ declare const encQuote: (v: unknown) => string;
19
+ /**
20
+ * Look up (or assign) a stable refData token for an object value.
21
+ *
22
+ * Templates use `{{@expr}}` to pass live JS values (objects/functions) through
23
+ * the DOM by writing the token into an attribute, then resolving it back to
24
+ * the original value when the event fires. `refData[SPLITTER]` holds the
25
+ * monotonic counter; `refData[SPLITTER + n]` holds the slot.
26
+ */
27
+ declare const refFn: (ref: Record<string, unknown>, value: unknown, key: string) => string;
28
+
29
+ export { encHtml, encQuote, encUri, refFn, strSafe };
@@ -0,0 +1,41 @@
1
+ // src/runtime.ts
2
+ var HTML_ENT_MAP = {
3
+ "&": "amp",
4
+ "<": "lt",
5
+ ">": "gt",
6
+ '"': "#34",
7
+ "'": "#39",
8
+ "`": "#96"
9
+ };
10
+ var HTML_ENT_REGEXP = /[&<>"`']/g;
11
+ var strSafe = (v) => "" + (v == null ? "" : v);
12
+ var encHtml = (v) => strSafe(v).replace(HTML_ENT_REGEXP, (m) => "&" + HTML_ENT_MAP[m] + ";");
13
+ var URI_ENT_MAP = {
14
+ "!": "%21",
15
+ "'": "%27",
16
+ "(": "%28",
17
+ ")": "%29",
18
+ "*": "%2A"
19
+ };
20
+ var URI_ENT_REGEXP = /[!')(*]/g;
21
+ var encUri = (v) => encodeURIComponent(strSafe(v)).replace(URI_ENT_REGEXP, (m) => URI_ENT_MAP[m]);
22
+ var QUOTE_REGEXP = /['"\\]/g;
23
+ var encQuote = (v) => strSafe(v).replace(QUOTE_REGEXP, "\\$&");
24
+ var refFn = (ref, value, key) => {
25
+ const SPLITTER = String.fromCharCode(30);
26
+ const counter = ref[SPLITTER];
27
+ for (let i = counter; --i; ) {
28
+ key = SPLITTER + i;
29
+ if (ref[key] === value) return key;
30
+ }
31
+ key = SPLITTER + ref[SPLITTER]++;
32
+ ref[key] = value;
33
+ return key;
34
+ };
35
+ export {
36
+ encHtml,
37
+ encQuote,
38
+ encUri,
39
+ refFn,
40
+ strSafe
41
+ };
package/dist/vite.cjs CHANGED
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // ../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js
33
+ // ../../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js
34
34
  var require_lib = __commonJS({
35
- "../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js"(exports2) {
35
+ "../../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js"(exports2) {
36
36
  "use strict";
37
37
  Object.defineProperty(exports2, "__esModule", {
38
38
  value: true
@@ -14617,8 +14617,8 @@ var import_fs = __toESM(require("fs"), 1);
14617
14617
 
14618
14618
  // src/compiler.ts
14619
14619
  var import_parser = __toESM(require_lib(), 1);
14620
- var SPLITTER = "";
14621
- var VIEW_ID_PLACEHOLDER = "";
14620
+ var SPLITTER = String.fromCharCode(30);
14621
+ var VIEW_ID_PLACEHOLDER = String.fromCharCode(31);
14622
14622
  function jsObjectToUrlParams(paramsStr) {
14623
14623
  const trimmed = paramsStr.trim();
14624
14624
  if (!/^[{[]/.test(trimmed) && /=/.test(trimmed)) {
@@ -14678,7 +14678,7 @@ function addLineMarkers(source) {
14678
14678
  if (parts.length > 1) {
14679
14679
  const reconstructed = parts.map((part, i) => {
14680
14680
  if (i === 0) return part;
14681
- return openTag + SPLITTER + ++lineNo;
14681
+ return openTag + SPLITTER + ++lineNo + part;
14682
14682
  }).join("");
14683
14683
  result.push(reconstructed);
14684
14684
  } else {
@@ -14814,7 +14814,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
14814
14814
  return `${debugPrefix}<%for(${forExpr}){%>`;
14815
14815
  }
14816
14816
  const tokens = code.split(/\s+/);
14817
- const keyword = tokens.shift();
14817
+ const keyword = tokens.shift() ?? "";
14818
14818
  switch (keyword) {
14819
14819
  case "if": {
14820
14820
  blockStack.push({ ctrl: "if", line: lineNo });
@@ -15038,13 +15038,9 @@ function compileToFunction(source, debug, file) {
15038
15038
  }
15039
15039
  const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
15040
15040
  funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
15041
- const atRule = hasAtRule ? `if(!$refFn){$refFn=(ref,v,k,f)=>{for(f=ref[$splitter];--f;)if(ref[k=$splitter+f]===v)return k;ref[k=$splitter+ref[$splitter]++]=v;return k;}}` : "";
15042
- const encode = `if(!$strSafe){let $entMap={'&':'amp','<':'lt','>':'gt','"':'#34','\\'':'#39','\`':'#96'},$entReg=/[&<>"'\`]/g,$entFn=m=>'&'+$entMap[m]+';';$strSafe=v=>''+(v==null?'':v);$encHtml=v=>$strSafe(v).replace($entReg,$entFn)}`;
15043
- const encodeURIMore = `if(!$encUri){let $uriMap={'!':'%21','\\'':'%27','(':'%28',')':'%29','*':'%2A'},$uriFn=m=>$uriMap[m],$uriReg=/[!')(*]/g;$encUri=v=>encodeURIComponent($strSafe(v)).replace($uriReg,$uriFn)}`;
15044
- const encodeQuote = `if(!$encQuote){let $qReg=/['"\\\\]/g;$encQuote=v=>$strSafe(v).replace($qReg,'\\\\$&')}`;
15041
+ void hasAtRule;
15045
15042
  const refFallback = "if(!$refAlt)$refAlt=$data;";
15046
- const fns = `${refFallback}${encode}${encodeURIMore}${encodeQuote}${atRule};`;
15047
- const fullSource = `${fns}let $splitter='\\x1e',$tmp,$out=''{{VARS}};${funcSource}return $out`;
15043
+ const fullSource = `${refFallback}let $splitter='\\x1e',$tmp,$out=''{{VARS}};${funcSource}return $out`;
15048
15044
  return `($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)=>{${fullSource}}`;
15049
15045
  }
15050
15046
  function compileTemplate(source, options = {}) {
@@ -15056,15 +15052,12 @@ function compileTemplate(source, options = {}) {
15056
15052
  const funcBody = compileToFunction(finalSource, debug, file);
15057
15053
  const varDeclarations = globalVars.map((key) => `,${key}=$data.${key}`).join("");
15058
15054
  const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
15059
- return `export default function(data, selfId, refData) {
15055
+ return `import { encHtml as __larkEncHtml, strSafe as __larkStrSafe, encUri as __larkEncUri, encQuote as __larkEncQuote, refFn as __larkRefFn } from "@lark.js/mvc/runtime";
15056
+ export default function(data, viewId, refData) {
15060
15057
  let $data = data || {},
15061
- $viewId = selfId || '';
15058
+ $viewId = viewId || '';
15062
15059
  return (${funcWithVars})($data, $viewId, refData,
15063
- /* $encHtml */ v => String(v == null ? '' : v).replace(/[&<>"'\`]/g, m => '&' + ({'&':'amp','<':'lt','>':'gt','"':'#34',"'":'#39','\`':'#96'})[m] + ';'),
15064
- /* $strSafe */ v => String(v == null ? '' : v),
15065
- /* $encUri */ null,
15066
- /* $refFn */ null,
15067
- /* $encQuote */ null
15060
+ __larkEncHtml, __larkStrSafe, __larkEncUri, __larkRefFn, __larkEncQuote
15068
15061
  );
15069
15062
  }`;
15070
15063
  }
@@ -15078,7 +15071,7 @@ function extractGlobalVars(source) {
15078
15071
  const htmlStore = {};
15079
15072
  let htmlIndex = 0;
15080
15073
  let lastIndex = 0;
15081
- const htmlKey = "";
15074
+ const htmlKey = String.fromCharCode(5);
15082
15075
  template.replace(
15083
15076
  templateCmdRegExp,
15084
15077
  (match, operate, content, offset) => {
@@ -15189,31 +15182,37 @@ function walkAst(ast, visitors) {
15189
15182
  if (visitors[type]) {
15190
15183
  visitors[type](node);
15191
15184
  }
15185
+ const bag = node;
15192
15186
  for (const key of Object.keys(node)) {
15193
15187
  if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "range")
15194
15188
  continue;
15195
- if (type === "MemberExpression" && key === "property" && !node.computed)
15196
- continue;
15197
- if (type === "ObjectProperty" && key === "key" && !node.computed) {
15198
- continue;
15189
+ if (type === "MemberExpression" && key === "property") {
15190
+ const me = node;
15191
+ if (!me.computed) continue;
15199
15192
  }
15200
- if (type === "ObjectMethod" && key === "key" && !node.computed) {
15201
- continue;
15193
+ if (type === "ObjectProperty" && key === "key") {
15194
+ const op = node;
15195
+ if (!op.computed) continue;
15202
15196
  }
15203
- const child = node[key];
15197
+ if (type === "ObjectMethod" && key === "key") {
15198
+ const om = node;
15199
+ if (!om.computed) continue;
15200
+ }
15201
+ const child = bag[key];
15204
15202
  if (Array.isArray(child)) {
15205
15203
  for (const item of child) {
15206
- if (item && typeof item === "object" && typeof item.type === "string") {
15207
- visit(item);
15208
- }
15204
+ if (isAstNode(item)) visit(item);
15209
15205
  }
15210
- } else if (child && typeof child === "object" && typeof child.type === "string") {
15206
+ } else if (isAstNode(child)) {
15211
15207
  visit(child);
15212
15208
  }
15213
15209
  }
15214
15210
  }
15215
15211
  visit(ast);
15216
15212
  }
15213
+ function isAstNode(v) {
15214
+ return !!v && typeof v === "object" && typeof v.type === "string";
15215
+ }
15217
15216
  var BUILTIN_GLOBALS = {
15218
15217
  // ─── Template runtime helpers (injected by compileToFunction) ───────
15219
15218
  //
package/dist/vite.d.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
3
  /**
4
- * @lark/framework Vite Plugin for Template Compilation
4
+ * @lark.js/mvc Vite Plugin for Template Compilation
5
5
  *
6
- * Compiles .html template files using @lark/framework template syntax
6
+ * Compiles .html template files using @lark.js/mvc template syntax
7
7
  * into JS function modules at build/dev time.
8
8
  *
9
9
  * 0 configuration — just add the plugin and it works.
@@ -16,7 +16,7 @@ import { Plugin } from 'vite';
16
16
  *
17
17
  * Usage in vite.config.ts:
18
18
  * ```ts
19
- * import { larkMvcPlugin } from '@lark/framework/vite-plugin';
19
+ * import { larkMvcPlugin } from '@lark.js/mvc/vite';
20
20
  *
21
21
  * export default defineConfig({
22
22
  * plugins: [larkMvcPlugin()],
package/dist/vite.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
3
  /**
4
- * @lark/framework Vite Plugin for Template Compilation
4
+ * @lark.js/mvc Vite Plugin for Template Compilation
5
5
  *
6
- * Compiles .html template files using @lark/framework template syntax
6
+ * Compiles .html template files using @lark.js/mvc template syntax
7
7
  * into JS function modules at build/dev time.
8
8
  *
9
9
  * 0 configuration — just add the plugin and it works.
@@ -16,7 +16,7 @@ import { Plugin } from 'vite';
16
16
  *
17
17
  * Usage in vite.config.ts:
18
18
  * ```ts
19
- * import { larkMvcPlugin } from '@lark/framework/vite-plugin';
19
+ * import { larkMvcPlugin } from '@lark.js/mvc/vite';
20
20
  *
21
21
  * export default defineConfig({
22
22
  * plugins: [larkMvcPlugin()],
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  compileTemplate,
3
3
  extractGlobalVars
4
- } from "./chunk-ANWA22AX.js";
4
+ } from "./chunk-3HSA7OHB.js";
5
5
 
6
6
  // src/vite.ts
7
7
  import path from "path";
package/dist/webpack.cjs CHANGED
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // ../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js
33
+ // ../../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js
34
34
  var require_lib = __commonJS({
35
- "../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js"(exports2) {
35
+ "../../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js"(exports2) {
36
36
  "use strict";
37
37
  Object.defineProperty(exports2, "__esModule", {
38
38
  value: true
@@ -14615,8 +14615,8 @@ module.exports = __toCommonJS(webpack_exports);
14615
14615
 
14616
14616
  // src/compiler.ts
14617
14617
  var import_parser = __toESM(require_lib(), 1);
14618
- var SPLITTER = "";
14619
- var VIEW_ID_PLACEHOLDER = "";
14618
+ var SPLITTER = String.fromCharCode(30);
14619
+ var VIEW_ID_PLACEHOLDER = String.fromCharCode(31);
14620
14620
  function jsObjectToUrlParams(paramsStr) {
14621
14621
  const trimmed = paramsStr.trim();
14622
14622
  if (!/^[{[]/.test(trimmed) && /=/.test(trimmed)) {
@@ -14676,7 +14676,7 @@ function addLineMarkers(source) {
14676
14676
  if (parts.length > 1) {
14677
14677
  const reconstructed = parts.map((part, i) => {
14678
14678
  if (i === 0) return part;
14679
- return openTag + SPLITTER + ++lineNo;
14679
+ return openTag + SPLITTER + ++lineNo + part;
14680
14680
  }).join("");
14681
14681
  result.push(reconstructed);
14682
14682
  } else {
@@ -14812,7 +14812,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
14812
14812
  return `${debugPrefix}<%for(${forExpr}){%>`;
14813
14813
  }
14814
14814
  const tokens = code.split(/\s+/);
14815
- const keyword = tokens.shift();
14815
+ const keyword = tokens.shift() ?? "";
14816
14816
  switch (keyword) {
14817
14817
  case "if": {
14818
14818
  blockStack.push({ ctrl: "if", line: lineNo });
@@ -15036,13 +15036,9 @@ function compileToFunction(source, debug, file) {
15036
15036
  }
15037
15037
  const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
15038
15038
  funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
15039
- const atRule = hasAtRule ? `if(!$refFn){$refFn=(ref,v,k,f)=>{for(f=ref[$splitter];--f;)if(ref[k=$splitter+f]===v)return k;ref[k=$splitter+ref[$splitter]++]=v;return k;}}` : "";
15040
- const encode = `if(!$strSafe){let $entMap={'&':'amp','<':'lt','>':'gt','"':'#34','\\'':'#39','\`':'#96'},$entReg=/[&<>"'\`]/g,$entFn=m=>'&'+$entMap[m]+';';$strSafe=v=>''+(v==null?'':v);$encHtml=v=>$strSafe(v).replace($entReg,$entFn)}`;
15041
- const encodeURIMore = `if(!$encUri){let $uriMap={'!':'%21','\\'':'%27','(':'%28',')':'%29','*':'%2A'},$uriFn=m=>$uriMap[m],$uriReg=/[!')(*]/g;$encUri=v=>encodeURIComponent($strSafe(v)).replace($uriReg,$uriFn)}`;
15042
- const encodeQuote = `if(!$encQuote){let $qReg=/['"\\\\]/g;$encQuote=v=>$strSafe(v).replace($qReg,'\\\\$&')}`;
15039
+ void hasAtRule;
15043
15040
  const refFallback = "if(!$refAlt)$refAlt=$data;";
15044
- const fns = `${refFallback}${encode}${encodeURIMore}${encodeQuote}${atRule};`;
15045
- const fullSource = `${fns}let $splitter='\\x1e',$tmp,$out=''{{VARS}};${funcSource}return $out`;
15041
+ const fullSource = `${refFallback}let $splitter='\\x1e',$tmp,$out=''{{VARS}};${funcSource}return $out`;
15046
15042
  return `($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)=>{${fullSource}}`;
15047
15043
  }
15048
15044
  function compileTemplate(source, options = {}) {
@@ -15054,15 +15050,12 @@ function compileTemplate(source, options = {}) {
15054
15050
  const funcBody = compileToFunction(finalSource, debug, file);
15055
15051
  const varDeclarations = globalVars.map((key) => `,${key}=$data.${key}`).join("");
15056
15052
  const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
15057
- return `export default function(data, selfId, refData) {
15053
+ return `import { encHtml as __larkEncHtml, strSafe as __larkStrSafe, encUri as __larkEncUri, encQuote as __larkEncQuote, refFn as __larkRefFn } from "@lark.js/mvc/runtime";
15054
+ export default function(data, viewId, refData) {
15058
15055
  let $data = data || {},
15059
- $viewId = selfId || '';
15056
+ $viewId = viewId || '';
15060
15057
  return (${funcWithVars})($data, $viewId, refData,
15061
- /* $encHtml */ v => String(v == null ? '' : v).replace(/[&<>"'\`]/g, m => '&' + ({'&':'amp','<':'lt','>':'gt','"':'#34',"'":'#39','\`':'#96'})[m] + ';'),
15062
- /* $strSafe */ v => String(v == null ? '' : v),
15063
- /* $encUri */ null,
15064
- /* $refFn */ null,
15065
- /* $encQuote */ null
15058
+ __larkEncHtml, __larkStrSafe, __larkEncUri, __larkRefFn, __larkEncQuote
15066
15059
  );
15067
15060
  }`;
15068
15061
  }
@@ -15076,7 +15069,7 @@ function extractGlobalVars(source) {
15076
15069
  const htmlStore = {};
15077
15070
  let htmlIndex = 0;
15078
15071
  let lastIndex = 0;
15079
- const htmlKey = "";
15072
+ const htmlKey = String.fromCharCode(5);
15080
15073
  template.replace(
15081
15074
  templateCmdRegExp,
15082
15075
  (match, operate, content, offset) => {
@@ -15187,31 +15180,37 @@ function walkAst(ast, visitors) {
15187
15180
  if (visitors[type]) {
15188
15181
  visitors[type](node);
15189
15182
  }
15183
+ const bag = node;
15190
15184
  for (const key of Object.keys(node)) {
15191
15185
  if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "range")
15192
15186
  continue;
15193
- if (type === "MemberExpression" && key === "property" && !node.computed)
15194
- continue;
15195
- if (type === "ObjectProperty" && key === "key" && !node.computed) {
15196
- continue;
15187
+ if (type === "MemberExpression" && key === "property") {
15188
+ const me = node;
15189
+ if (!me.computed) continue;
15197
15190
  }
15198
- if (type === "ObjectMethod" && key === "key" && !node.computed) {
15199
- continue;
15191
+ if (type === "ObjectProperty" && key === "key") {
15192
+ const op = node;
15193
+ if (!op.computed) continue;
15200
15194
  }
15201
- const child = node[key];
15195
+ if (type === "ObjectMethod" && key === "key") {
15196
+ const om = node;
15197
+ if (!om.computed) continue;
15198
+ }
15199
+ const child = bag[key];
15202
15200
  if (Array.isArray(child)) {
15203
15201
  for (const item of child) {
15204
- if (item && typeof item === "object" && typeof item.type === "string") {
15205
- visit(item);
15206
- }
15202
+ if (isAstNode(item)) visit(item);
15207
15203
  }
15208
- } else if (child && typeof child === "object" && typeof child.type === "string") {
15204
+ } else if (isAstNode(child)) {
15209
15205
  visit(child);
15210
15206
  }
15211
15207
  }
15212
15208
  }
15213
15209
  visit(ast);
15214
15210
  }
15211
+ function isAstNode(v) {
15212
+ return !!v && typeof v === "object" && typeof v.type === "string";
15213
+ }
15215
15214
  var BUILTIN_GLOBALS = {
15216
15215
  // ─── Template runtime helpers (injected by compileToFunction) ───────
15217
15216
  //
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  compileTemplate,
3
3
  extractGlobalVars
4
- } from "./chunk-ANWA22AX.js";
4
+ } from "./chunk-3HSA7OHB.js";
5
5
 
6
6
  // src/webpack.ts
7
7
  function larkMvcLoader(source) {
package/package.json CHANGED
@@ -1,10 +1,23 @@
1
1
  {
2
2
  "name": "@lark.js/mvc",
3
- "version": "0.0.4",
4
- "description": "Lark - TypeScript MVC framework",
3
+ "version": "0.0.6",
4
+ "description": "@lark.js/mvc - TypeScript MVC framework",
5
+ "keywords": [
6
+ "framework",
7
+ "lark",
8
+ "mvc"
9
+ ],
10
+ "license": "ISC",
11
+ "author": "https://github.com/hangtiancheng",
5
12
  "files": [
6
- "dist"
13
+ "dist",
14
+ "src/client.d.ts",
15
+ "README.md"
7
16
  ],
17
+ "type": "module",
18
+ "main": "dist/index.cjs",
19
+ "module": "dist/index.js",
20
+ "types": "dist/index.d.ts",
8
21
  "exports": {
9
22
  ".": {
10
23
  "import": {
@@ -35,12 +48,20 @@
35
48
  "types": "./dist/webpack.d.cts",
36
49
  "default": "./dist/webpack.cjs"
37
50
  }
51
+ },
52
+ "./runtime": {
53
+ "import": {
54
+ "types": "./dist/runtime.d.ts",
55
+ "default": "./dist/runtime.js"
56
+ },
57
+ "require": {
58
+ "types": "./dist/runtime.d.cts",
59
+ "default": "./dist/runtime.cjs"
60
+ }
38
61
  }
39
62
  },
40
- "main": "dist/index.cjs",
41
- "module": "dist/index.js",
42
- "types": "dist/index.d.ts",
43
63
  "scripts": {
64
+ "prepublish": "pnpm build",
44
65
  "build": "pnpm build:tsup",
45
66
  "build:rollup": "rollup -c rollup.config.mjs",
46
67
  "build:tsup": "tsup",
@@ -51,37 +72,30 @@
51
72
  "test:watch": "vitest",
52
73
  "test:coverage": "vitest run --coverage"
53
74
  },
54
- "keywords": [
55
- "lark",
56
- "mvc",
57
- "framework"
58
- ],
59
- "author": "https://github.com/hangtiancheng",
60
- "license": "ISC",
61
- "packageManager": "pnpm@10.33.0",
75
+ "dependencies": {
76
+ "@babel/parser": "^7.29.7",
77
+ "@babel/types": "^7.29.7"
78
+ },
62
79
  "devDependencies": {
63
- "@rollup/plugin-commonjs": "^29.0.2",
80
+ "@rollup/plugin-commonjs": "^29.0.3",
64
81
  "@rollup/plugin-node-resolve": "^16.0.3",
65
82
  "@rollup/plugin-typescript": "^12.3.0",
83
+ "@types/node": "^25.9.2",
66
84
  "@vitest/coverage-v8": "4.1.6",
67
- "rollup": "^4.60.3",
85
+ "rollup": "^4.61.1",
68
86
  "rollup-plugin-dts": "^6.4.1",
69
87
  "tsup": "^8.5.1",
70
- "typescript": "^5.8.3",
71
- "vite": "^8.0.14",
72
- "vitest": "^4.1.6"
88
+ "typescript": "^5.9.3",
89
+ "vite": "^8.0.16",
90
+ "vitest": "^4.1.8"
91
+ },
92
+ "peerDependencies": {
93
+ "vite": "^8.0.14"
73
94
  },
74
95
  "lint-staged": {
75
96
  "*.{json,jsonc,js,cjs,mjs,jsx,ts,cts,mts,tsx,html,vue,css,scss,md,mdx}": [
76
97
  "pnpm format"
77
98
  ]
78
99
  },
79
- "type": "module",
80
- "peerDependencies": {
81
- "vite": "^8.0.14"
82
- },
83
- "dependencies": {
84
- "@babel/parser": "^7.29.7",
85
- "@babel/types": "^7.29.7"
86
- }
100
+ "packageManager": "pnpm@10.33.0"
87
101
  }