@lark.js/mvc 0.0.8 → 0.0.10

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/runtime.cjs CHANGED
@@ -27,6 +27,12 @@ __export(runtime_exports, {
27
27
  strSafe: () => strSafe
28
28
  });
29
29
  module.exports = __toCommonJS(runtime_exports);
30
+
31
+ // src/common.ts
32
+ var SPLITTER = String.fromCharCode(30);
33
+ var EVENT_METHOD_REGEXP = new RegExp(
34
+ `(?:([\\w-]+)${SPLITTER})?([^(]+)\\(([\\s\\S]*?)?\\)`
35
+ );
30
36
  var HTML_ENT_MAP = {
31
37
  "&": "amp",
32
38
  "<": "lt",
@@ -35,9 +41,16 @@ var HTML_ENT_MAP = {
35
41
  "'": "#39",
36
42
  "`": "#96"
37
43
  };
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] + ";");
44
+ var HTML_ENT_REGEXP = /[&<>"'`]/g;
45
+ function encodeSafe(v) {
46
+ return String(v == null ? "" : v);
47
+ }
48
+ function encodeHTML(v) {
49
+ return String(v == null ? "" : v).replace(
50
+ HTML_ENT_REGEXP,
51
+ (m) => "&" + HTML_ENT_MAP[m] + ";"
52
+ );
53
+ }
41
54
  var URI_ENT_MAP = {
42
55
  "!": "%21",
43
56
  "'": "%27",
@@ -46,11 +59,17 @@ var URI_ENT_MAP = {
46
59
  "*": "%2A"
47
60
  };
48
61
  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);
62
+ function encodeURIExtra(v) {
63
+ return encodeURIComponent(encodeSafe(v)).replace(
64
+ URI_ENT_REGEXP,
65
+ (m) => URI_ENT_MAP[m]
66
+ );
67
+ }
68
+ var QUOTE_ENT_REGEXP = /['"\\]/g;
69
+ function encodeQ(v) {
70
+ return encodeSafe(v).replace(QUOTE_ENT_REGEXP, "\\$&");
71
+ }
72
+ function refFn(ref, value, key) {
54
73
  const counter = ref[SPLITTER];
55
74
  for (let i = counter; --i; ) {
56
75
  key = SPLITTER + i;
@@ -59,7 +78,13 @@ var refFn = (ref, value, key) => {
59
78
  key = SPLITTER + ref[SPLITTER]++;
60
79
  ref[key] = value;
61
80
  return key;
62
- };
81
+ }
82
+
83
+ // src/runtime.ts
84
+ var strSafe = encodeSafe;
85
+ var encHtml = encodeHTML;
86
+ var encUri = encodeURIExtra;
87
+ var encQuote = encodeQ;
63
88
  // Annotate the CommonJS export names for ESM import in node:
64
89
  0 && (module.exports = {
65
90
  encHtml,
@@ -1,3 +1,17 @@
1
+ /** Null-safe String conversion */
2
+ declare function encodeSafe(v: unknown): string;
3
+ /** HTML entity encoding for safe output */
4
+ declare function encodeHTML(v: unknown): string;
5
+ /** URI-encode with extra character encoding */
6
+ declare function encodeURIExtra(v: unknown): string;
7
+ /** Quote-encode for attribute values */
8
+ declare function encodeQ(v: unknown): string;
9
+ /**
10
+ * Template reference function for creating stable keys for objects.
11
+ * Stores objects in refData with SPLITTER-prefixed keys.
12
+ */
13
+ declare function refFn(ref: Record<string, unknown>, value: unknown, key: string): string;
14
+
1
15
  /**
2
16
  * Template runtime helpers.
3
17
  *
@@ -7,23 +21,18 @@
7
21
  *
8
22
  * The helpers below are aliased to `$strSafe / $encHtml / $encUri / $encQuote /
9
23
  * $refFn` inside the IIFE that the compiler produces — see `compiler.ts`.
24
+ *
25
+ * Canonical implementations live in `./common` so that dom.ts, runtime.ts,
26
+ * and updater.ts all share a single copy.
10
27
  */
28
+
11
29
  /** Null-safe `String(value)` — `null`/`undefined` become `""`. */
12
- declare const strSafe: (v: unknown) => string;
30
+ declare const strSafe: typeof encodeSafe;
13
31
  /** HTML-escape a value for safe embedding in markup. */
14
- declare const encHtml: (v: unknown) => string;
32
+ declare const encHtml: typeof encodeHTML;
15
33
  /** Percent-encode a value, with extra characters escaped for stricter URIs. */
16
- declare const encUri: (v: unknown) => string;
34
+ declare const encUri: typeof encodeURIExtra;
17
35
  /** 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;
36
+ declare const encQuote: typeof encodeQ;
28
37
 
29
38
  export { encHtml, encQuote, encUri, refFn, strSafe };
package/dist/runtime.d.ts CHANGED
@@ -1,3 +1,17 @@
1
+ /** Null-safe String conversion */
2
+ declare function encodeSafe(v: unknown): string;
3
+ /** HTML entity encoding for safe output */
4
+ declare function encodeHTML(v: unknown): string;
5
+ /** URI-encode with extra character encoding */
6
+ declare function encodeURIExtra(v: unknown): string;
7
+ /** Quote-encode for attribute values */
8
+ declare function encodeQ(v: unknown): string;
9
+ /**
10
+ * Template reference function for creating stable keys for objects.
11
+ * Stores objects in refData with SPLITTER-prefixed keys.
12
+ */
13
+ declare function refFn(ref: Record<string, unknown>, value: unknown, key: string): string;
14
+
1
15
  /**
2
16
  * Template runtime helpers.
3
17
  *
@@ -7,23 +21,18 @@
7
21
  *
8
22
  * The helpers below are aliased to `$strSafe / $encHtml / $encUri / $encQuote /
9
23
  * $refFn` inside the IIFE that the compiler produces — see `compiler.ts`.
24
+ *
25
+ * Canonical implementations live in `./common` so that dom.ts, runtime.ts,
26
+ * and updater.ts all share a single copy.
10
27
  */
28
+
11
29
  /** Null-safe `String(value)` — `null`/`undefined` become `""`. */
12
- declare const strSafe: (v: unknown) => string;
30
+ declare const strSafe: typeof encodeSafe;
13
31
  /** HTML-escape a value for safe embedding in markup. */
14
- declare const encHtml: (v: unknown) => string;
32
+ declare const encHtml: typeof encodeHTML;
15
33
  /** Percent-encode a value, with extra characters escaped for stricter URIs. */
16
- declare const encUri: (v: unknown) => string;
34
+ declare const encUri: typeof encodeURIExtra;
17
35
  /** 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;
36
+ declare const encQuote: typeof encodeQ;
28
37
 
29
38
  export { encHtml, encQuote, encUri, refFn, strSafe };
package/dist/runtime.js CHANGED
@@ -1,4 +1,8 @@
1
- // src/runtime.ts
1
+ // src/common.ts
2
+ var SPLITTER = String.fromCharCode(30);
3
+ var EVENT_METHOD_REGEXP = new RegExp(
4
+ `(?:([\\w-]+)${SPLITTER})?([^(]+)\\(([\\s\\S]*?)?\\)`
5
+ );
2
6
  var HTML_ENT_MAP = {
3
7
  "&": "amp",
4
8
  "<": "lt",
@@ -7,9 +11,16 @@ var HTML_ENT_MAP = {
7
11
  "'": "#39",
8
12
  "`": "#96"
9
13
  };
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] + ";");
14
+ var HTML_ENT_REGEXP = /[&<>"'`]/g;
15
+ function encodeSafe(v) {
16
+ return String(v == null ? "" : v);
17
+ }
18
+ function encodeHTML(v) {
19
+ return String(v == null ? "" : v).replace(
20
+ HTML_ENT_REGEXP,
21
+ (m) => "&" + HTML_ENT_MAP[m] + ";"
22
+ );
23
+ }
13
24
  var URI_ENT_MAP = {
14
25
  "!": "%21",
15
26
  "'": "%27",
@@ -18,11 +29,17 @@ var URI_ENT_MAP = {
18
29
  "*": "%2A"
19
30
  };
20
31
  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);
32
+ function encodeURIExtra(v) {
33
+ return encodeURIComponent(encodeSafe(v)).replace(
34
+ URI_ENT_REGEXP,
35
+ (m) => URI_ENT_MAP[m]
36
+ );
37
+ }
38
+ var QUOTE_ENT_REGEXP = /['"\\]/g;
39
+ function encodeQ(v) {
40
+ return encodeSafe(v).replace(QUOTE_ENT_REGEXP, "\\$&");
41
+ }
42
+ function refFn(ref, value, key) {
26
43
  const counter = ref[SPLITTER];
27
44
  for (let i = counter; --i; ) {
28
45
  key = SPLITTER + i;
@@ -31,7 +48,13 @@ var refFn = (ref, value, key) => {
31
48
  key = SPLITTER + ref[SPLITTER]++;
32
49
  ref[key] = value;
33
50
  return key;
34
- };
51
+ }
52
+
53
+ // src/runtime.ts
54
+ var strSafe = encodeSafe;
55
+ var encHtml = encodeHTML;
56
+ var encUri = encodeURIExtra;
57
+ var encQuote = encodeQ;
35
58
  export {
36
59
  encHtml,
37
60
  encQuote,
package/dist/vite.cjs CHANGED
@@ -14863,7 +14863,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
14863
14863
  const object = tokens[0];
14864
14864
  if (tokens.length > 1 && tokens[1] !== "as") {
14865
14865
  throw new Error(
14866
- `[@lark.js/mvc error] bad forIn syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{for-in obj as val [key]}}`
14866
+ `[@lark.js/mvc error] bad forIn syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{forIn obj as val [key]}}`
14867
14867
  );
14868
14868
  }
14869
14869
  const restTokens2 = tokens.slice(2);
@@ -15100,7 +15100,8 @@ function extractGlobalVars(source) {
15100
15100
  } catch {
15101
15101
  return fallbackExtractVariables(source);
15102
15102
  }
15103
- const globalExists = { ...BUILTIN_GLOBALS };
15103
+ const globalExists = {};
15104
+ for (const name of BUILTIN_GLOBALS) globalExists[name] = 1;
15104
15105
  const globalVars = /* @__PURE__ */ Object.create(null);
15105
15106
  const fnRange = [];
15106
15107
  walkAst(ast, {
@@ -15174,7 +15175,7 @@ function fallbackExtractVariables(source) {
15174
15175
  while ((m = ifRegExp.exec(source)) !== null) {
15175
15176
  vars.add(m[1]);
15176
15177
  }
15177
- return Array.from(vars).filter((v) => !BUILTIN_GLOBAL_SET.has(v));
15178
+ return Array.from(vars).filter((v) => !BUILTIN_GLOBALS.has(v));
15178
15179
  }
15179
15180
  function walkAst(ast, visitors) {
15180
15181
  function visit(node) {
@@ -15213,7 +15214,7 @@ function walkAst(ast, visitors) {
15213
15214
  function isAstNode(v) {
15214
15215
  return !!v && typeof v === "object" && typeof v.type === "string";
15215
15216
  }
15216
- var BUILTIN_GLOBALS = {
15217
+ var BUILTIN_GLOBALS = /* @__PURE__ */ new Set([
15217
15218
  // ─── Template runtime helpers (injected by compileToFunction) ───────
15218
15219
  //
15219
15220
  // These variables appear in the generated template function signature
@@ -15222,147 +15223,146 @@ var BUILTIN_GLOBALS = {
15222
15223
  // SPLITTER character constant (same as \x1e), used as namespace separator
15223
15224
  // for refData keys, event attribute encoding, and internal data structures.
15224
15225
  // Declared as: let $splitter='\x1e'
15225
- $splitter: 1,
15226
+ "$splitter",
15226
15227
  // Data — the data object passed from Updater to the template function.
15227
15228
  // User variables are destructured from $data at the top of the function:
15228
15229
  // let {name, age} = $data;
15229
15230
  // This is the first parameter of the generated arrow function.
15230
- $data: 1,
15231
+ "$data",
15231
15232
  // Null-safe toString: v => '' + (v == null ? '' : v)
15232
15233
  // Converts null/undefined to empty string, otherwise calls toString().
15233
15234
  // Wraps every {{!raw}} output to prevent "null" / "undefined" rendering.
15234
- $strSafe: 1,
15235
+ "$strSafe",
15235
15236
  // HTML entity encoder: v => $strSafe(v).replace(/[&<>"'`]/g, entityMap)
15236
15237
  // Encodes &, <, >, ", ', ` to HTML entities (&amp; &lt; etc.)
15237
15238
  // Applied to all {{=escaped}} and {{:binding}} outputs.
15238
- $encHtml: 1,
15239
+ "$encHtml",
15239
15240
  // HTML entity map — internal object used by $encHtml:
15240
15241
  // {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
15241
15242
  // Not a standalone function; referenced inside $encHtml's closure.
15242
- $entMap: 1,
15243
+ "$entMap",
15243
15244
  // HTML entity RegExp — internal regexp used by $encHtml:
15244
15245
  // /[&<>"'`]/g
15245
- $entReg: 1,
15246
+ "$entReg",
15246
15247
  // HTML entity replacer function — internal helper used by $encHtml:
15247
15248
  // m => '&' + $entMap[m] + ';'
15248
15249
  // Maps matched character to its entity string.
15249
- $entFn: 1,
15250
+ "$entFn",
15250
15251
  // Output buffer — the string accumulator for rendered HTML.
15251
15252
  // All template output is appended via $out += '...'.
15252
15253
  // Declared as: let $out = ''
15253
- $out: 1,
15254
+ "$out",
15254
15255
  // Reference lookup: (refData, value) => key
15255
15256
  // Finds or allocates a SPLITTER-prefixed key in refData for a given
15256
15257
  // object reference. Used by {{@ref}} operator for passing object
15257
15258
  // references to child views via v-lark attributes.
15258
- $refFn: 1,
15259
+ "$refFn",
15259
15260
  // URI encoder: v => encodeURIComponent($strSafe(v)).replace(/[!')(*]/g, extraMap)
15260
15261
  // Extends encodeURIComponent with encoding of ! ' ( ) *.
15261
15262
  // Applied to values in @event URL parameters and {{!uri}} contexts.
15262
- $encUri: 1,
15263
+ "$encUri",
15263
15264
  // URI encode map — internal object used by $encUri:
15264
15265
  // {'!':'%21','\'':'%27','(':'%28',')':'%29','*':'%2A'}
15265
- $uriMap: 1,
15266
+ "$uriMap",
15266
15267
  // URI encode replacer — internal helper used by $encUri:
15267
15268
  // m => $uriMap[m]
15268
- $uriFn: 1,
15269
+ "$uriFn",
15269
15270
  // URI encode regexp — internal regexp used by $encUri:
15270
15271
  // /[!')(*]/g
15271
- $uriReg: 1,
15272
+ "$uriReg",
15272
15273
  // Quote encoder: v => $strSafe(v).replace(/['"\\]/g, '\\$&')
15273
15274
  // Escapes quotes and backslashes for safe embedding in HTML attribute
15274
15275
  // values (e.g. data-json='...').
15275
- $encQuote: 1,
15276
+ "$encQuote",
15276
15277
  // Quote encode regexp — internal regexp used by $encQuote:
15277
15278
  // /['"\\]/g
15278
- $qReg: 1,
15279
+ "$qReg",
15279
15280
  // View ID — the unique identifier of the owning View instance.
15280
15281
  // Injected into @event attribute values at render time so that
15281
15282
  // EventDelegator can dispatch events to the correct View handler.
15282
15283
  // The \x1f placeholder in compiled output is replaced with '+$viewId+'.
15283
- $viewId: 1,
15284
+ "$viewId",
15284
15285
  // Debug: current expression text — stores the template expression being
15285
15286
  // evaluated, for error reporting. Only present in debug mode.
15286
15287
  // e.g. $dbgExpr='<%=user.name%>'
15287
- $dbgExpr: 1,
15288
+ "$dbgExpr",
15288
15289
  // Debug: original art syntax — stores the {{}} template syntax before
15289
15290
  // conversion, for error reporting. Only present in debug mode.
15290
15291
  // e.g. $dbgArt='{{=user.name}}'
15291
- $dbgArt: 1,
15292
+ "$dbgArt",
15292
15293
  // Debug: source line number — tracks the current line in the template
15293
15294
  // source, for error reporting. Only present in debug mode.
15294
- $dbgLine: 1,
15295
+ "$dbgLine",
15295
15296
  // RefData alias — fallback reference lookup table.
15296
15297
  // Defaults to $data when no explicit $refAlt is provided.
15297
15298
  // Ensures $refFn() does not crash when @ operator is used without refData.
15298
- $refAlt: 1,
15299
+ "$refAlt",
15299
15300
  // Temporary variable — used by the compiler for intermediate
15300
15301
  // expression results in generated code (e.g. loop variables,
15301
15302
  // conditional branches). Declared as: let $tmp
15302
- $tmp: 1,
15303
+ "$tmp",
15303
15304
  // JS literals
15304
- undefined: 1,
15305
- null: 1,
15306
- true: 1,
15307
- false: 1,
15308
- NaN: 1,
15309
- Infinity: 1,
15305
+ "undefined",
15306
+ "null",
15307
+ "true",
15308
+ "false",
15309
+ "NaN",
15310
+ "Infinity",
15310
15311
  // JS built-in globals
15311
- window: 1,
15312
- self: 1,
15313
- globalThis: 1,
15314
- document: 1,
15315
- console: 1,
15316
- JSON: 1,
15317
- Math: 1,
15318
- Intl: 1,
15319
- Promise: 1,
15320
- Symbol: 1,
15321
- Number: 1,
15322
- String: 1,
15323
- Boolean: 1,
15324
- Array: 1,
15325
- Object: 1,
15326
- Date: 1,
15327
- RegExp: 1,
15328
- Error: 1,
15329
- TypeError: 1,
15330
- RangeError: 1,
15331
- SyntaxError: 1,
15332
- Map: 1,
15333
- Set: 1,
15334
- WeakMap: 1,
15335
- WeakSet: 1,
15336
- Proxy: 1,
15337
- Reflect: 1,
15338
- ArrayBuffer: 1,
15339
- DataView: 1,
15340
- Float32Array: 1,
15341
- Float64Array: 1,
15342
- Int8Array: 1,
15343
- Int16Array: 1,
15344
- Int32Array: 1,
15345
- Uint8Array: 1,
15346
- Uint16Array: 1,
15347
- Uint32Array: 1,
15348
- Uint8ClampedArray: 1,
15312
+ "window",
15313
+ "self",
15314
+ "globalThis",
15315
+ "document",
15316
+ "console",
15317
+ "JSON",
15318
+ "Math",
15319
+ "Intl",
15320
+ "Promise",
15321
+ "Symbol",
15322
+ "Number",
15323
+ "String",
15324
+ "Boolean",
15325
+ "Array",
15326
+ "Object",
15327
+ "Date",
15328
+ "RegExp",
15329
+ "Error",
15330
+ "TypeError",
15331
+ "RangeError",
15332
+ "SyntaxError",
15333
+ "Map",
15334
+ "Set",
15335
+ "WeakMap",
15336
+ "WeakSet",
15337
+ "Proxy",
15338
+ "Reflect",
15339
+ "ArrayBuffer",
15340
+ "DataView",
15341
+ "Float32Array",
15342
+ "Float64Array",
15343
+ "Int8Array",
15344
+ "Int16Array",
15345
+ "Int32Array",
15346
+ "Uint8Array",
15347
+ "Uint16Array",
15348
+ "Uint32Array",
15349
+ "Uint8ClampedArray",
15349
15350
  // Functions
15350
- parseInt: 1,
15351
- parseFloat: 1,
15352
- isNaN: 1,
15353
- isFinite: 1,
15354
- encodeURIComponent: 1,
15355
- decodeURIComponent: 1,
15356
- encodeURI: 1,
15357
- decodeURI: 1,
15351
+ "parseInt",
15352
+ "parseFloat",
15353
+ "isNaN",
15354
+ "isFinite",
15355
+ "encodeURIComponent",
15356
+ "decodeURIComponent",
15357
+ "encodeURI",
15358
+ "decodeURI",
15358
15359
  // Babel helpers
15359
- arguments: 1,
15360
- this: 1,
15361
- require: 1,
15360
+ "arguments",
15361
+ "this",
15362
+ "require",
15362
15363
  // Lark framework
15363
- Lark: 1
15364
- };
15365
- var BUILTIN_GLOBAL_SET = new Set(Object.keys(BUILTIN_GLOBALS));
15364
+ "Lark"
15365
+ ]);
15366
15366
 
15367
15367
  // src/vite.ts
15368
15368
  var LARK_TEMPLATE_SUFFIX = "?lark-template";
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  compileTemplate,
3
3
  extractGlobalVars
4
- } from "./chunk-3HSA7OHB.js";
4
+ } from "./chunk-SIQF4YLC.js";
5
5
 
6
6
  // src/vite.ts
7
7
  import path from "path";