@lark.js/mvc 0.0.3 → 0.0.4

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/vite.cjs CHANGED
@@ -14737,7 +14737,7 @@ function convertArtSyntax(source, debug) {
14737
14737
  }
14738
14738
  if (blockStack.length > 0) {
14739
14739
  const unclosed = blockStack.map((b) => `"${b.ctrl}" at line ${b.line}`).join(", ");
14740
- throw new Error(`[@lark/mvc error] unclosed block(s): ${unclosed}`);
14740
+ throw new Error(`[@lark.js/mvc error] unclosed block(s): ${unclosed}`);
14741
14741
  }
14742
14742
  return result.join("");
14743
14743
  }
@@ -14831,12 +14831,12 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
14831
14831
  }
14832
14832
  return `${debugPrefix}<%}else{%>`;
14833
14833
  }
14834
- case "each": {
14835
- blockStack.push({ ctrl: "each", line: lineNo });
14834
+ case "forOf": {
14835
+ blockStack.push({ ctrl: "forOf", line: lineNo });
14836
14836
  const object = tokens[0];
14837
14837
  if (tokens.length > 1 && tokens[1] !== "as") {
14838
14838
  throw new Error(
14839
- `[@lark/mvc error] bad each syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{each list as item [index]}}`
14839
+ `[@lark.js/mvc error] bad forOf syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{forOf list as item [index]}}`
14840
14840
  );
14841
14841
  }
14842
14842
  const restTokens = tokens.slice(2);
@@ -14858,12 +14858,12 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
14858
14858
  }
14859
14859
  return `${debugPrefix}<%for(let ${index}=0${refExpr},${refObjCount}=${refObj}.length${lastCount};${index}<${refObjCount};${index}++){${firstAndLast}${valueDecl}%>`;
14860
14860
  }
14861
- case "parse": {
14862
- blockStack.push({ ctrl: "parse", line: lineNo });
14861
+ case "forIn": {
14862
+ blockStack.push({ ctrl: "forIn", line: lineNo });
14863
14863
  const object = tokens[0];
14864
14864
  if (tokens.length > 1 && tokens[1] !== "as") {
14865
14865
  throw new Error(
14866
- `[@lark/mvc error] bad parse 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: {{for-in obj as val [key]}}`
14867
14867
  );
14868
14868
  }
14869
14869
  const restTokens2 = tokens.slice(2);
@@ -14883,19 +14883,19 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
14883
14883
  case "set":
14884
14884
  return `${debugPrefix}<%let ${tokens.join(" ")};%>`;
14885
14885
  case "/if":
14886
- case "/each":
14887
- case "/parse":
14886
+ case "/forOf":
14887
+ case "/forIn":
14888
14888
  case "/for": {
14889
14889
  const expectedCtrl = keyword.substring(1);
14890
14890
  const last = blockStack.pop();
14891
14891
  if (!last) {
14892
14892
  throw new Error(
14893
- `[@lark/mvc error] unexpected {{${code}}}: no matching open block`
14893
+ `[@lark.js/mvc error] unexpected {{${code}}}: no matching open block`
14894
14894
  );
14895
14895
  }
14896
14896
  if (last.ctrl !== expectedCtrl) {
14897
14897
  throw new Error(
14898
- `[@lark/mvc error] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
14898
+ `[@lark.js/mvc error] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
14899
14899
  );
14900
14900
  }
14901
14901
  return `${debugPrefix}<%}%>`;
@@ -14959,7 +14959,7 @@ function parseAsExpr(expr) {
14959
14959
  function compileToFunction(source, debug, file) {
14960
14960
  const matcher = /<%([@=!:])?([\s\S]*?)%>|$/g;
14961
14961
  let index = 0;
14962
- let funcSource = `$p+='`;
14962
+ let funcSource = `$out+='`;
14963
14963
  let hasAtRule = false;
14964
14964
  const escapeSlashRegExp = /\\|'/g;
14965
14965
  const escapeBreakReturnRegExp = /\r|\n/g;
@@ -14985,17 +14985,17 @@ function compileToFunction(source, debug, file) {
14985
14985
  }
14986
14986
  if (operate === "@") {
14987
14987
  hasAtRule = true;
14988
- funcSource += `'+($expr='<%${operate + expr}%>',$i($$ref,${content}))+'`;
14988
+ funcSource += `'+($dbgExpr='<%${operate + expr}%>',$refFn($refAlt,${content}))+'`;
14989
14989
  } else if (operate === "=" || operate === ":") {
14990
- funcSource += `'+($expr='<%${operate + expr}%>',$e(${content}))+'`;
14990
+ funcSource += `'+($dbgExpr='<%${operate + expr}%>',$encHtml(${content}))+'`;
14991
14991
  } else if (operate === "!") {
14992
- if (!content.startsWith("$eu(") || !content.endsWith(")")) {
14993
- content = `$n(${content})`;
14992
+ if (!content.startsWith("$encUri(") || !content.endsWith(")")) {
14993
+ content = `$strSafe(${content})`;
14994
14994
  }
14995
- funcSource += `'+($expr='<%${operate + expr}%>',${content})+'`;
14995
+ funcSource += `'+($dbgExpr='<%${operate + expr}%>',${content})+'`;
14996
14996
  } else if (content) {
14997
14997
  if (line > -1) {
14998
- funcSource += `';$line=${line};$art='${art}';`;
14998
+ funcSource += `';$dbgLine=${line};$dbgArt='${art}';`;
14999
14999
  content = "";
15000
15000
  } else {
15001
15001
  funcSource += `';`;
@@ -15004,19 +15004,19 @@ function compileToFunction(source, debug, file) {
15004
15004
  funcSource = funcSource.substring(0, funcSource.length - 4) + ";";
15005
15005
  }
15006
15006
  if (expr) {
15007
- funcSource += `$expr='<%${expr}%>';`;
15007
+ funcSource += `$dbgExpr='<%${expr}%>';`;
15008
15008
  }
15009
- funcSource += content + `;$p+='`;
15009
+ funcSource += content + `;$out+='`;
15010
15010
  }
15011
15011
  } else {
15012
15012
  if (operate === "@") {
15013
15013
  hasAtRule = true;
15014
- funcSource += `'+$i($$ref,${content})+'`;
15014
+ funcSource += `'+$refFn($refAlt,${content})+'`;
15015
15015
  } else if (operate === "=" || operate === ":") {
15016
- funcSource += `'+$e(${content})+'`;
15016
+ funcSource += `'+$encHtml(${content})+'`;
15017
15017
  } else if (operate === "!") {
15018
- if (!content.startsWith("$eu(") || !content.endsWith(")")) {
15019
- content = `$n(${content})`;
15018
+ if (!content.startsWith("$encUri(") || !content.endsWith(")")) {
15019
+ content = `$strSafe(${content})`;
15020
15020
  }
15021
15021
  funcSource += `'+${content}+'`;
15022
15022
  } else if (content) {
@@ -15024,28 +15024,28 @@ function compileToFunction(source, debug, file) {
15024
15024
  if (funcSource.endsWith(`+'';`)) {
15025
15025
  funcSource = funcSource.substring(0, funcSource.length - 4) + ";";
15026
15026
  }
15027
- funcSource += `${content};$p+='`;
15027
+ funcSource += `${content};$out+='`;
15028
15028
  }
15029
15029
  }
15030
15030
  return match;
15031
15031
  });
15032
15032
  funcSource += `';`;
15033
- funcSource = funcSource.replace(/\$p\+='';/g, "");
15034
- funcSource = funcSource.replace(/\$p\+=''\+/g, "$p+=");
15033
+ funcSource = funcSource.replace(/\$out\+='';/g, "");
15034
+ funcSource = funcSource.replace(/\$out\+=''\+/g, "$out+=");
15035
15035
  if (debug) {
15036
15036
  const filePart = file ? `\\r\\n\\tat file:${file}` : "";
15037
- funcSource = `let $expr,$art,$line;try{${funcSource}}catch(ex){let msg='render view error:'+(ex.message||ex);if($art)msg+='\\r\\n\\tsrc art:{{'+$art+'}}\\r\\n\\tat line:'+$line;msg+='\\r\\n\\t'+($art?'translate to:':'expr:');msg+=$expr+'${filePart}';throw msg;}`;
15037
+ funcSource = `let $dbgExpr,$dbgArt,$dbgLine;try{${funcSource}}catch(ex){let msg='render view error:'+(ex.message||ex);if($dbgArt)msg+='\\r\\n\\tsrc art:{{'+$dbgArt+'}}\\r\\n\\tat line:'+$dbgLine;msg+='\\r\\n\\t'+($dbgArt?'translate to:':'expr:');msg+=$dbgExpr+'${filePart}';throw msg;}`;
15038
15038
  }
15039
15039
  const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
15040
15040
  funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
15041
- const atRule = hasAtRule ? `if(!$i){$i=(ref,v,k,f)=>{for(f=ref[$g];--f;)if(ref[k=$g+f]===v)return k;ref[k=$g+ref[$g]++]=v;return k;}}` : "";
15042
- const encode = `if(!$n){let $em={'&':'amp','<':'lt','>':'gt','"':'#34','\\'':'#39','\`':'#96'},$er=/[&<>"'\`]/g,$ef=m=>'&'+$em[m]+';';$n=v=>''+(v==null?'':v);$e=v=>$n(v).replace($er,$ef)}`;
15043
- const encodeURIMore = `if(!$eu){let $um={'!':'%21','\\'':'%27','(':'%28',')':'%29','*':'%2A'},$uf=m=>$um[m],$uq=/[!')(*]/g;$eu=v=>encodeURIComponent($n(v)).replace($uq,$uf)}`;
15044
- const encodeQuote = `if(!$eq){let $qr=/['"\\\\]/g;$eq=v=>$n(v).replace($qr,'\\\\$&')}`;
15045
- const refFallback = "if(!$$ref)$$ref=$$;";
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,'\\\\$&')}`;
15045
+ const refFallback = "if(!$refAlt)$refAlt=$data;";
15046
15046
  const fns = `${refFallback}${encode}${encodeURIMore}${encodeQuote}${atRule};`;
15047
- const fullSource = `${fns}let $g='\\x1e',$_temp,$p=''{{VARS}};${funcSource}return $p`;
15048
- return `($$,$viewId,$$ref,$e,$n,$eu,$i,$eq)=>{${fullSource}}`;
15047
+ const fullSource = `${fns}let $splitter='\\x1e',$tmp,$out=''{{VARS}};${funcSource}return $out`;
15048
+ return `($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)=>{${fullSource}}`;
15049
15049
  }
15050
15050
  function compileTemplate(source, options = {}) {
15051
15051
  const { debug = false, globalVars = [], file } = options;
@@ -15054,17 +15054,17 @@ function compileTemplate(source, options = {}) {
15054
15054
  const viewEventProcessed = processViewEvents(converted);
15055
15055
  const finalSource = restoreComments(viewEventProcessed, comments);
15056
15056
  const funcBody = compileToFunction(finalSource, debug, file);
15057
- const varDeclarations = globalVars.map((key) => `,${key}=$$.${key}`).join("");
15057
+ const varDeclarations = globalVars.map((key) => `,${key}=$data.${key}`).join("");
15058
15058
  const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
15059
15059
  return `export default function(data, selfId, refData) {
15060
- let $$ = data || {},
15060
+ let $data = data || {},
15061
15061
  $viewId = selfId || '';
15062
- return (${funcWithVars})($$, $viewId, refData,
15063
- /* $e */ v => String(v == null ? '' : v).replace(/[&<>"'\`]/g, m => '&' + ({'&':'amp','<':'lt','>':'gt','"':'#34',"'":'#39','\`':'#96'})[m] + ';'),
15064
- /* $n */ v => String(v == null ? '' : v),
15065
- /* $eu */ null,
15066
- /* $i */ null,
15067
- /* $eq */ null
15062
+ 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
15068
15068
  );
15069
15069
  }`;
15070
15070
  }
@@ -15173,7 +15173,7 @@ function fallbackExtractVariables(source) {
15173
15173
  while ((m = outputRegExp.exec(source)) !== null) {
15174
15174
  vars.add(m[1]);
15175
15175
  }
15176
- const eachRegExp = /\{\{each\s+([a-zA-Z_$][\w$]*)\s+as/g;
15176
+ const eachRegExp = /\{\{forOf\s+([a-zA-Z_$][\w$]*)\s+as/g;
15177
15177
  while ((m = eachRegExp.exec(source)) !== null) {
15178
15178
  vars.add(m[1]);
15179
15179
  }
@@ -15219,52 +15219,64 @@ var BUILTIN_GLOBALS = {
15219
15219
  //
15220
15220
  // These variables appear in the generated template function signature
15221
15221
  // or body. They must be excluded from extractGlobalVars() so that
15222
- // they are not mistaken for user data variables and destructured from $$.
15222
+ // they are not mistaken for user data variables and destructured from $data.
15223
15223
  // SPLITTER character constant (same as \x1e), used as namespace separator
15224
15224
  // for refData keys, event attribute encoding, and internal data structures.
15225
- // Declared as: let $g='\x1e'
15226
- $g: 1,
15227
- // refData — the data object passed from Updater to the template function.
15228
- // User variables are destructured from $$ at the top of the function:
15229
- // let {name, age} = $$;
15225
+ // Declared as: let $splitter='\x1e'
15226
+ $splitter: 1,
15227
+ // Data — the data object passed from Updater to the template function.
15228
+ // User variables are destructured from $data at the top of the function:
15229
+ // let {name, age} = $data;
15230
15230
  // This is the first parameter of the generated arrow function.
15231
- $$: 1,
15231
+ $data: 1,
15232
15232
  // Null-safe toString: v => '' + (v == null ? '' : v)
15233
15233
  // Converts null/undefined to empty string, otherwise calls toString().
15234
15234
  // Wraps every {{!raw}} output to prevent "null" / "undefined" rendering.
15235
- $n: 1,
15236
- // HTML entity encoder: v => $n(v).replace(/[&<>"'`]/g, entityMap)
15235
+ $strSafe: 1,
15236
+ // HTML entity encoder: v => $strSafe(v).replace(/[&<>"'`]/g, entityMap)
15237
15237
  // Encodes &, <, >, ", ', ` to HTML entities (&amp; &lt; etc.)
15238
15238
  // Applied to all {{=escaped}} and {{:binding}} outputs.
15239
- $e: 1,
15240
- // HTML entity map — internal object used by $e:
15239
+ $encHtml: 1,
15240
+ // HTML entity map — internal object used by $encHtml:
15241
15241
  // {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
15242
- // Not a standalone function; referenced inside $e's closure.
15243
- $em: 1,
15244
- // HTML entity RegExp — internal regexp used by $e:
15242
+ // Not a standalone function; referenced inside $encHtml's closure.
15243
+ $entMap: 1,
15244
+ // HTML entity RegExp — internal regexp used by $encHtml:
15245
15245
  // /[&<>"'`]/g
15246
- $er: 1,
15247
- // HTML entity replacer function — internal helper used by $e:
15248
- // m => '&' + $em[m] + ';'
15249
- // Maps each matched character to its entity string.
15250
- $ef: 1,
15246
+ $entReg: 1,
15247
+ // HTML entity replacer function — internal helper used by $encHtml:
15248
+ // m => '&' + $entMap[m] + ';'
15249
+ // Maps matched character to its entity string.
15250
+ $entFn: 1,
15251
15251
  // Output buffer — the string accumulator for rendered HTML.
15252
- // All template output is appended via $p += '...'.
15253
- // Declared as: let $p = ''
15254
- $p: 1,
15252
+ // All template output is appended via $out += '...'.
15253
+ // Declared as: let $out = ''
15254
+ $out: 1,
15255
15255
  // Reference lookup: (refData, value) => key
15256
15256
  // Finds or allocates a SPLITTER-prefixed key in refData for a given
15257
15257
  // object reference. Used by {{@ref}} operator for passing object
15258
15258
  // references to child views via v-lark attributes.
15259
- $i: 1,
15260
- // URI encoder: v => encodeURIComponent($n(v)).replace(/[!')(*]/g, extraMap)
15259
+ $refFn: 1,
15260
+ // URI encoder: v => encodeURIComponent($strSafe(v)).replace(/[!')(*]/g, extraMap)
15261
15261
  // Extends encodeURIComponent with encoding of ! ' ( ) *.
15262
15262
  // Applied to values in @event URL parameters and {{!uri}} contexts.
15263
- $eu: 1,
15264
- // Quote encoder: v => $n(v).replace(/['"\\]/g, '\\$&')
15263
+ $encUri: 1,
15264
+ // URI encode map internal object used by $encUri:
15265
+ // {'!':'%21','\'':'%27','(':'%28',')':'%29','*':'%2A'}
15266
+ $uriMap: 1,
15267
+ // URI encode replacer — internal helper used by $encUri:
15268
+ // m => $uriMap[m]
15269
+ $uriFn: 1,
15270
+ // URI encode regexp — internal regexp used by $encUri:
15271
+ // /[!')(*]/g
15272
+ $uriReg: 1,
15273
+ // Quote encoder: v => $strSafe(v).replace(/['"\\]/g, '\\$&')
15265
15274
  // Escapes quotes and backslashes for safe embedding in HTML attribute
15266
15275
  // values (e.g. data-json='...').
15267
- $eq: 1,
15276
+ $encQuote: 1,
15277
+ // Quote encode regexp — internal regexp used by $encQuote:
15278
+ // /['"\\]/g
15279
+ $qReg: 1,
15268
15280
  // View ID — the unique identifier of the owning View instance.
15269
15281
  // Injected into @event attribute values at render time so that
15270
15282
  // EventDelegator can dispatch events to the correct View handler.
@@ -15272,23 +15284,23 @@ var BUILTIN_GLOBALS = {
15272
15284
  $viewId: 1,
15273
15285
  // Debug: current expression text — stores the template expression being
15274
15286
  // evaluated, for error reporting. Only present in debug mode.
15275
- // e.g. $expr='<%=user.name%>'
15276
- $expr: 1,
15287
+ // e.g. $dbgExpr='<%=user.name%>'
15288
+ $dbgExpr: 1,
15277
15289
  // Debug: original art syntax — stores the {{}} template syntax before
15278
15290
  // conversion, for error reporting. Only present in debug mode.
15279
- // e.g. $art='{{=user.name}}'
15280
- $art: 1,
15291
+ // e.g. $dbgArt='{{=user.name}}'
15292
+ $dbgArt: 1,
15281
15293
  // Debug: source line number — tracks the current line in the template
15282
15294
  // source, for error reporting. Only present in debug mode.
15283
- $line: 1,
15284
- // refData alias — fallback reference lookup table.
15285
- // Defaults to $$ when no explicit $$ref is provided.
15286
- // Ensures $i() does not crash when @ operator is used without refData.
15287
- $$ref: 1,
15295
+ $dbgLine: 1,
15296
+ // RefData alias — fallback reference lookup table.
15297
+ // Defaults to $data when no explicit $refAlt is provided.
15298
+ // Ensures $refFn() does not crash when @ operator is used without refData.
15299
+ $refAlt: 1,
15288
15300
  // Temporary variable — used by the compiler for intermediate
15289
15301
  // expression results in generated code (e.g. loop variables,
15290
- // conditional branches). Declared as: let $_temp
15291
- $_temp: 1,
15302
+ // conditional branches). Declared as: let $tmp
15303
+ $tmp: 1,
15292
15304
  // JS literals
15293
15305
  undefined: 1,
15294
15306
  null: 1,
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  compileTemplate,
3
3
  extractGlobalVars
4
- } from "./chunk-Y72BUONO.js";
4
+ } from "./chunk-ANWA22AX.js";
5
5
 
6
6
  // src/vite.ts
7
7
  import path from "path";