@lark.js/mvc 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -23,7 +23,7 @@ __export(index_exports, {
23
23
  Bag: () => Bag,
24
24
  CALL_BREAK_TIME: () => CALL_BREAK_TIME,
25
25
  Cache: () => Cache,
26
- EVT_METHOD_REG: () => EVT_METHOD_REG,
26
+ EVENT_METHOD_REGEXP: () => EVENT_METHOD_REGEXP,
27
27
  EventDelegator: () => EventDelegator,
28
28
  EventEmitter: () => EventEmitter,
29
29
  Frame: () => Frame,
@@ -35,12 +35,9 @@ __export(index_exports, {
35
35
  SPLITTER: () => SPLITTER,
36
36
  Service: () => Service,
37
37
  State: () => State,
38
- TAG_ATTR_KEY: () => TAG_ATTR_KEY,
39
- TAG_KEY: () => TAG_KEY,
40
- TAG_NAME_REGEX: () => TAG_NAME_REGEX,
41
- TAG_VIEW_KEY: () => TAG_VIEW_KEY,
38
+ TAG_NAME_REGEXP: () => TAG_NAME_REGEXP,
42
39
  Updater: () => Updater,
43
- VIEW_EVT_METHOD_REG: () => VIEW_EVT_METHOD_REG,
40
+ VIEW_EVENT_METHOD_REGEXP: () => VIEW_EVENT_METHOD_REGEXP,
44
41
  View: () => View,
45
42
  applyIdUpdates: () => applyIdUpdates,
46
43
  applyStyle: () => applyStyle,
@@ -69,6 +66,7 @@ __export(index_exports, {
69
66
  getStore: () => getStore,
70
67
  getUseStore: () => getUseStore,
71
68
  has: () => has,
69
+ installFrameVisualizerBridge: () => installFrameVisualizerBridge,
72
70
  isArray: () => isArray,
73
71
  isPlainObject: () => isPlainObject,
74
72
  isPrimitive: () => isPrimitive,
@@ -89,6 +87,7 @@ __export(index_exports, {
89
87
  parseUri: () => parseUri,
90
88
  registerViewClass: () => registerViewClass,
91
89
  safeguard: () => safeguard,
90
+ serializeFrameTree: () => serializeFrameTree,
92
91
  setData: () => setData,
93
92
  shallowSet: () => shallowSet,
94
93
  storeMark: () => mark2,
@@ -116,21 +115,26 @@ var ROUTER_EVENTS = {
116
115
  CHANGED: "changed",
117
116
  PAGE_UNLOAD: "page_unload"
118
117
  };
119
- var TAG_KEY = "lark-key";
120
- var TAG_ATTR_KEY = "lark-attr-key";
121
- var TAG_VIEW_KEY = "lark-view-key";
122
- var LARK_VIEW = "lark-view";
123
- var EVT_METHOD_REG = new RegExp(
118
+ var LARK_KEYS = {
119
+ /** Attribute name: ldk (static key for skipping VDOM diff) */
120
+ DIFF_KEY: "ldk",
121
+ /** Attribute name: lak (static attribute key) */
122
+ ATTR_KEY: "lak",
123
+ /** Attribute name: lvk (view key for assign) */
124
+ VIEW_KEY: "lvk"
125
+ };
126
+ var LARK_VIEW = "v-lark";
127
+ var EVENT_METHOD_REGEXP = new RegExp(
124
128
  `(?:([\\w-]+)${SPLITTER})?([^(]+)\\(([\\s\\S]*?)?\\)`
125
129
  );
126
- var VIEW_EVT_METHOD_REG = /^(\$?)([\w]*)<(.*?)>(?:<([\w ,]*)>)?$/;
127
- var URL_TRIM_HASH_REGEX = /(?:^.*\/\/[^/]+|#.*$)/gi;
128
- var URL_TRIM_QUERY_REGEX = /^[^#]*#?!?/;
129
- var URL_PARAM_REGEX = /([^=&?/#]+)=?([^&#?]*)/g;
130
- var URL_QUERY_HASH_REGEX = /[#?].*$/;
130
+ var VIEW_EVENT_METHOD_REGEXP = /^(\$?)([\w]*)<(.*?)>(?:<([\w ,]*)>)?$/;
131
+ var URL_TRIM_HASH_REGEXP = /(?:^.*\/\/[^/]+|#.*$)/gi;
132
+ var URL_TRIM_QUERY_REGEXP = /^[^#]*#?!?/;
133
+ var URL_PARAM_REGEXP = /([^=&?/#]+)=?([^&#?]*)/g;
134
+ var URL_QUERY_HASH_REGEXP = /[#?].*$/;
131
135
  var SVG_NS = "http://www.w3.org/2000/svg";
132
136
  var MATH_NS = "http://www.w3.org/1998/Math/MathML";
133
- var TAG_NAME_REGEX = /<([a-z][^/\0>\x20\t\r\n\f]+)/i;
137
+ var TAG_NAME_REGEXP = /<([a-z][^/\0>\x20\t\r\n\f]+)/i;
134
138
  var CALL_BREAK_TIME = 48;
135
139
  function nextCounter() {
136
140
  return ++globalCounter;
@@ -268,10 +272,10 @@ function paramsReplacer(_match, name, value) {
268
272
  }
269
273
  function parseUri(uri) {
270
274
  paramsTemp = {};
271
- const path = uri.replace(URL_QUERY_HASH_REGEX, "");
275
+ const path = uri.replace(URL_QUERY_HASH_REGEXP, "");
272
276
  const pathname = path;
273
277
  const actualPath = uri === pathname && IS_URL_PARAMS.test(pathname) ? "" : pathname;
274
- uri.replace(actualPath, "").replace(URL_PARAM_REGEX, paramsReplacer);
278
+ uri.replace(actualPath, "").replace(URL_PARAM_REGEXP, paramsReplacer);
275
279
  return {
276
280
  path: actualPath,
277
281
  params: { ...paramsTemp }
@@ -311,13 +315,13 @@ function toMap(list, key) {
311
315
  function now() {
312
316
  return Date.now ? Date.now() : (/* @__PURE__ */ new Date()).getTime();
313
317
  }
314
- function classExtend(ctor, base, props, statics) {
318
+ function classExtend(make, base, props, statics) {
315
319
  const baseProto = base["prototype"] ?? {};
316
320
  const cProto = Object.create(baseProto);
317
321
  assign(cProto, props);
318
- Object.assign(ctor, statics);
319
- cProto.constructor = ctor;
320
- ctor["prototype"] = cProto;
322
+ Object.assign(make, statics);
323
+ cProto.constructor = make;
324
+ make["prototype"] = cProto;
321
325
  }
322
326
 
323
327
  // src/apply-style.ts
@@ -385,7 +389,7 @@ function unmark(host) {
385
389
  var proxiesPool = /* @__PURE__ */ new Map();
386
390
  var SAFEGUARD_SENTINEL = "_sf_";
387
391
  function safeguard(data, getter, setter, isRoot) {
388
- if (typeof window.__lark_debug === "undefined" || !window.__lark_debug) {
392
+ if (typeof window.__lark_Debug === "undefined" || !window.__lark_Debug) {
389
393
  return data;
390
394
  }
391
395
  if (typeof Proxy === "undefined") {
@@ -687,7 +691,7 @@ function teardownKeysRef(keyList) {
687
691
  if (count <= 0) {
688
692
  Reflect.deleteProperty(keyRefCounts, key);
689
693
  Reflect.deleteProperty(appData, key);
690
- if (typeof window.__lark_debug !== "undefined" && window.__lark_debug) {
694
+ if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug) {
691
695
  Reflect.deleteProperty(dataWhereSet, key);
692
696
  }
693
697
  }
@@ -730,7 +734,7 @@ var State = {
730
734
  */
731
735
  get(key) {
732
736
  const result = key ? appData[key] : appData;
733
- if (typeof window.__lark_debug !== "undefined" && window.__lark_debug) {
737
+ if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug) {
734
738
  return safeguard(
735
739
  result,
736
740
  (dataKey) => {
@@ -756,7 +760,7 @@ var State = {
756
760
  */
757
761
  set(data, excludes) {
758
762
  dataIsChanged = setData(data, appData, changedKeys, excludes || /* @__PURE__ */ new Set()) || dataIsChanged;
759
- if (typeof window.__lark_debug !== "undefined" && window.__lark_debug && booted) {
763
+ if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug && booted) {
760
764
  for (const p in data) {
761
765
  dataWhereSet[p] = window.location.pathname;
762
766
  }
@@ -771,7 +775,7 @@ var State = {
771
775
  State.set(data, excludes);
772
776
  }
773
777
  if (dataIsChanged) {
774
- if (typeof window.__lark_debug !== "undefined" && window.__lark_debug) {
778
+ if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug) {
775
779
  for (const p in changedKeys) {
776
780
  if (has(changedKeys, p)) {
777
781
  clearNotify(p);
@@ -802,7 +806,7 @@ var State = {
802
806
  */
803
807
  clean(keys2) {
804
808
  return {
805
- ctor: function() {
809
+ make: function() {
806
810
  const keyList = setupKeysRef(keys2);
807
811
  this.on("destroy", () => {
808
812
  teardownKeysRef(keyList);
@@ -965,8 +969,8 @@ var Router = {
965
969
  if (cached) {
966
970
  return cached;
967
971
  }
968
- const srcQuery = href.replace(URL_TRIM_HASH_REGEX, "");
969
- const srcHash = href.replace(URL_TRIM_QUERY_REGEX, "");
972
+ const srcQuery = href.replace(URL_TRIM_HASH_REGEXP, "");
973
+ const srcHash = href.replace(URL_TRIM_QUERY_REGEXP, "");
970
974
  const query = parseUri(srcQuery);
971
975
  const hash = parseUri(srcHash);
972
976
  const params = assign({}, query["params"], hash["params"]);
@@ -983,7 +987,7 @@ var Router = {
983
987
  attachViewAndPath(location);
984
988
  hrefCache.set(href, location);
985
989
  }
986
- if (typeof window.__lark_debug !== "undefined" && window.__lark_debug) {
990
+ if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug) {
987
991
  location["params"] = safeguard(location["params"]);
988
992
  }
989
993
  return location;
@@ -1007,7 +1011,7 @@ var Router = {
1007
1011
  );
1008
1012
  }
1009
1013
  silent = 0;
1010
- if (typeof window.__lark_debug !== "undefined" && window.__lark_debug && lastChanged) {
1014
+ if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug && lastChanged) {
1011
1015
  lastChanged = safeguard(lastChanged);
1012
1016
  }
1013
1017
  return lastChanged;
@@ -1068,9 +1072,9 @@ var Router = {
1068
1072
  join(...paths) {
1069
1073
  let result = paths.join("/");
1070
1074
  result = result.replace(/\/\.\//g, "/");
1071
- const doubleDotRegex = /\/[^/]+\/\.\.\//;
1072
- while (doubleDotRegex.test(result)) {
1073
- result = result.replace(doubleDotRegex, "/");
1075
+ const doubleDotRegExp = /\/[^/]+\/\.\.\//;
1076
+ while (doubleDotRegExp.test(result)) {
1077
+ result = result.replace(doubleDotRegExp, "/");
1074
1078
  }
1075
1079
  result = result.replace(/\/{2,}/g, "/");
1076
1080
  return result;
@@ -1172,7 +1176,7 @@ function parseEventInfo(eventInfo) {
1172
1176
  if (cached) {
1173
1177
  return assign({}, cached, { r: eventInfo });
1174
1178
  }
1175
- const match = eventInfo.match(EVT_METHOD_REG) || [];
1179
+ const match = eventInfo.match(EVENT_METHOD_REGEXP) || [];
1176
1180
  const result = {
1177
1181
  v: match[1] || "",
1178
1182
  n: match[2] || "",
@@ -1184,7 +1188,7 @@ function parseEventInfo(eventInfo) {
1184
1188
  function findFrameInfo(current, eventType) {
1185
1189
  const eventInfos = [];
1186
1190
  let begin = current;
1187
- const info = current.getAttribute(`lark-${eventType}`);
1191
+ const info = current.getAttribute(`@${eventType}`);
1188
1192
  let match;
1189
1193
  if (info) {
1190
1194
  match = parseEventInfo(info);
@@ -1229,7 +1233,7 @@ function findFrameInfo(current, eventType) {
1229
1233
  }
1230
1234
  }
1231
1235
  }
1232
- if (view.tmpl && !backtrace) {
1236
+ if (view.template && !backtrace) {
1233
1237
  if (match && !match.v) {
1234
1238
  match.v = frameId;
1235
1239
  }
@@ -1408,7 +1412,7 @@ function vdomGetNode(html, refNode) {
1408
1412
  } else if (ns === MATH_NS) {
1409
1413
  tag = "m";
1410
1414
  } else {
1411
- const match = TAG_NAME_REGEX.exec(html);
1415
+ const match = TAG_NAME_REGEXP.exec(html);
1412
1416
  tag = match ? match[1] : "";
1413
1417
  }
1414
1418
  const wrap = WrapMeta[tag] || WrapMeta["_"];
@@ -1428,7 +1432,7 @@ function vdomGetCompareKey(node) {
1428
1432
  }
1429
1433
  let key = el.autoId ? "" : el.getAttribute("id") || void 0;
1430
1434
  if (!key) {
1431
- key = el.getAttribute(TAG_KEY) || void 0;
1435
+ key = el.getAttribute(LARK_KEYS.DIFF_KEY) || void 0;
1432
1436
  }
1433
1437
  if (!key) {
1434
1438
  const larkView = el.getAttribute(LARK_VIEW);
@@ -1556,17 +1560,17 @@ function vdomSetChildNodes(oldParent, newParent, ref, frame, keys_) {
1556
1560
  }
1557
1561
  }
1558
1562
  function vdomSetNode(oldNode, newNode, oldParent, ref, frame, keys_) {
1559
- if (vdomSpecialDiff(oldNode, newNode) || oldNode.nodeType === 1 && oldNode.hasAttribute(TAG_VIEW_KEY) || !(oldNode.isEqualNode && oldNode.isEqualNode(newNode))) {
1563
+ if (vdomSpecialDiff(oldNode, newNode) || oldNode.nodeType === 1 && oldNode.hasAttribute(LARK_KEYS.VIEW_KEY) || !(oldNode.isEqualNode && oldNode.isEqualNode(newNode))) {
1560
1564
  if (oldNode.nodeType === newNode.nodeType && oldNode.nodeName === newNode.nodeName) {
1561
1565
  if (oldNode.nodeType === 1) {
1562
1566
  const oldEl = oldNode;
1563
1567
  const newEl = newNode;
1564
- const staticKey = newEl.getAttribute(TAG_KEY);
1565
- if (staticKey && staticKey === oldEl.getAttribute(TAG_KEY)) {
1568
+ const staticKey = newEl.getAttribute(LARK_KEYS.DIFF_KEY);
1569
+ if (staticKey && staticKey === oldEl.getAttribute(LARK_KEYS.DIFF_KEY)) {
1566
1570
  return;
1567
1571
  }
1568
1572
  const newLarkView = newEl.getAttribute(LARK_VIEW);
1569
- const updateAttribute = !newEl.getAttribute(TAG_ATTR_KEY) || newEl.getAttribute(TAG_ATTR_KEY) !== oldEl.getAttribute(TAG_ATTR_KEY);
1573
+ const updateAttribute = !newEl.getAttribute(LARK_KEYS.ATTR_KEY) || newEl.getAttribute(LARK_KEYS.ATTR_KEY) !== oldEl.getAttribute(LARK_KEYS.ATTR_KEY);
1570
1574
  let updateChildren = true;
1571
1575
  if (newLarkView) {
1572
1576
  const oldFrameId = oldEl.getAttribute("id") || "";
@@ -1637,10 +1641,10 @@ var EncoderMap = {
1637
1641
  "'": "#39",
1638
1642
  "`": "#96"
1639
1643
  };
1640
- var ENCODE_REGEX = /[&<>"'`]/g;
1644
+ var ENCODE_REGEXP = /[&<>"'`]/g;
1641
1645
  function encodeHTML(v) {
1642
1646
  return String(v == null ? "" : v).replace(
1643
- ENCODE_REGEX,
1647
+ ENCODE_REGEXP,
1644
1648
  (m) => "&" + EncoderMap[m] + ";"
1645
1649
  );
1646
1650
  }
@@ -1654,16 +1658,16 @@ var URIMap = {
1654
1658
  ")": "%29",
1655
1659
  "*": "%2A"
1656
1660
  };
1657
- var URI_ENCODE_REGEX = /[!')(*]/g;
1661
+ var URI_ENCODE_REGEXP = /[!')(*]/g;
1658
1662
  function encodeURIExtra(v) {
1659
1663
  return encodeURIComponent(encodeSafe(v)).replace(
1660
- URI_ENCODE_REGEX,
1664
+ URI_ENCODE_REGEXP,
1661
1665
  (m) => URIMap[m]
1662
1666
  );
1663
1667
  }
1664
- var QUOTE_REGEX = /['"\\]/g;
1668
+ var QUOTE_REGEXP = /['"\\]/g;
1665
1669
  function encodeQ(v) {
1666
- return encodeSafe(v).replace(QUOTE_REGEX, "\\$&");
1670
+ return encodeSafe(v).replace(QUOTE_REGEXP, "\\$&");
1667
1671
  }
1668
1672
 
1669
1673
  // src/updater.ts
@@ -1711,7 +1715,7 @@ var Updater = class {
1711
1715
  if (key) {
1712
1716
  result = this.data[key];
1713
1717
  }
1714
- if (typeof window !== "undefined" && window.__lark_debug) {
1718
+ if (typeof window !== "undefined" && window.__lark_Debug) {
1715
1719
  return safeguard(result);
1716
1720
  }
1717
1721
  return result;
@@ -1762,9 +1766,9 @@ var Updater = class {
1762
1766
  const view = frame?.view;
1763
1767
  const node = getById(this.viewId);
1764
1768
  if (changed && view && node && view.signature > 0) {
1765
- const tmpl = view.tmpl;
1766
- if (tmpl && typeof tmpl === "function") {
1767
- const html = tmpl(
1769
+ const template = view.template;
1770
+ if (template && typeof template === "function") {
1771
+ const html = template(
1768
1772
  this.data,
1769
1773
  this.viewId,
1770
1774
  this.refData,
@@ -1846,10 +1850,10 @@ var Updater = class {
1846
1850
  // src/view.ts
1847
1851
  var VIEW_GLOBALS = {};
1848
1852
  if (typeof window !== "undefined") {
1849
- VIEW_GLOBALS["win"] = window;
1853
+ VIEW_GLOBALS["window"] = window;
1850
1854
  }
1851
1855
  if (typeof document !== "undefined") {
1852
- VIEW_GLOBALS["doc"] = document;
1856
+ VIEW_GLOBALS["document"] = document;
1853
1857
  }
1854
1858
  function viewPrepare(oView) {
1855
1859
  if (oView.ctors) {
@@ -1869,7 +1873,7 @@ function viewPrepare(oView) {
1869
1873
  if (!has(proto, p)) continue;
1870
1874
  const currentFn = proto[p];
1871
1875
  if (typeof currentFn !== "function") continue;
1872
- const matches = p.match(VIEW_EVT_METHOD_REG);
1876
+ const matches = p.match(VIEW_EVENT_METHOD_REGEXP);
1873
1877
  if (!matches) continue;
1874
1878
  const isSelector = matches[1];
1875
1879
  const selectorOrCallback = matches[2];
@@ -1976,11 +1980,11 @@ function viewMergeMixins(mixins, viewClass, ctors) {
1976
1980
  if (!has(node, p)) continue;
1977
1981
  const fn = node[p];
1978
1982
  const exist = temp[p];
1979
- if (p === "ctor") {
1983
+ if (p === "make") {
1980
1984
  ctors.push(fn);
1981
1985
  continue;
1982
1986
  }
1983
- if (VIEW_EVT_METHOD_REG.test(p)) {
1987
+ if (VIEW_EVENT_METHOD_REGEXP.test(p)) {
1984
1988
  if (exist) {
1985
1989
  temp[p] = processMixinsSameEvent(fn, exist);
1986
1990
  } else {
@@ -2078,7 +2082,7 @@ var View = class _View {
2078
2082
  /** Whether rendered at least once */
2079
2083
  rendered;
2080
2084
  /** Whether view has template */
2081
- tmpl;
2085
+ template;
2082
2086
  /** Location observation config */
2083
2087
  locationObserved = {
2084
2088
  flag: 0,
@@ -2313,23 +2317,23 @@ var View = class _View {
2313
2317
  * Extend View to create a new View subclass.
2314
2318
  *
2315
2319
  * Supports:
2316
- * - props.ctor: constructor-like init (called with initParams + {node, deep})
2320
+ * - props.make: constructor-like init (called with initParams + {node, deep})
2317
2321
  * - props.mixins: array of mixin objects
2318
2322
  * - Event method patterns: `'name<click>'` etc.
2319
2323
  */
2320
2324
  static extend(props, statics) {
2321
2325
  props = props || {};
2322
- const ctor = props["ctor"];
2326
+ const make = props["make"];
2323
2327
  const ctors = [];
2324
- if (ctor) {
2325
- ctors.push(ctor);
2328
+ if (make) {
2329
+ ctors.push(make);
2326
2330
  }
2327
2331
  const ParentView = this;
2328
2332
  const ChildView = class extends ParentView {
2329
2333
  constructor(nodeId, ownerFrame, initParams, node, mixinCtors) {
2330
2334
  super(nodeId, ownerFrame, initParams, node, []);
2331
2335
  for (const key in props) {
2332
- if (has(props, key) && key !== "ctor") {
2336
+ if (has(props, key) && key !== "make") {
2333
2337
  this[key] = props[key];
2334
2338
  }
2335
2339
  }
@@ -2340,7 +2344,7 @@ var View = class _View {
2340
2344
  initParams,
2341
2345
  {
2342
2346
  node,
2343
- deep: !this.tmpl
2347
+ deep: !this.template
2344
2348
  }
2345
2349
  ];
2346
2350
  const concatCtors = ctors.concat(mixinCtors || []);
@@ -2351,7 +2355,7 @@ var View = class _View {
2351
2355
  };
2352
2356
  const proto = ChildView.prototype;
2353
2357
  for (const key in props) {
2354
- if (has(props, key) && key !== "ctor") {
2358
+ if (has(props, key) && key !== "make") {
2355
2359
  proto[key] = props[key];
2356
2360
  }
2357
2361
  }
@@ -2430,7 +2434,7 @@ var Frame = class _Frame extends EventEmitter {
2430
2434
  hasAltered = 0;
2431
2435
  /** Whether view is destroyed */
2432
2436
  destroyed = 0;
2433
- /** View path (lark-view attribute value) */
2437
+ /** View path (v-lark attribute value) */
2434
2438
  viewPath;
2435
2439
  /** Original template before mount */
2436
2440
  originalTemplate;
@@ -2468,8 +2472,8 @@ var Frame = class _Frame extends EventEmitter {
2468
2472
  * 5. Create View instance
2469
2473
  * 6. View_DelegateEvents (bind DOM events)
2470
2474
  * 7. Call view.init()
2471
- * 8. If view has tmpl, call render via Updater
2472
- * 9. If no tmpl, call endUpdate directly
2475
+ * 8. If view has template, call render via Updater
2476
+ * 9. If no template, call endUpdate directly
2473
2477
  */
2474
2478
  mountView(viewPath, viewInitParams) {
2475
2479
  const node = document.getElementById(this.id);
@@ -2513,14 +2517,14 @@ var Frame = class _Frame extends EventEmitter {
2513
2517
  viewDelegateEvents(view);
2514
2518
  const initResult = funcWithTry(
2515
2519
  view.init,
2516
- [params, { node, deep: !view.tmpl }],
2520
+ [params, { node, deep: !view.template }],
2517
2521
  view,
2518
2522
  noop
2519
2523
  );
2520
2524
  const nextSign = ++this.signature;
2521
2525
  Promise.resolve(initResult).then(() => {
2522
2526
  if (nextSign !== this.signature) return;
2523
- if (view.tmpl) {
2527
+ if (view.template) {
2524
2528
  const renderFn = view.$b;
2525
2529
  if (renderFn) {
2526
2530
  renderFn.call(view);
@@ -3157,6 +3161,114 @@ function serviceSend(service, attrs, done, flag, save) {
3157
3161
  }
3158
3162
  }
3159
3163
 
3164
+ // src/frame-visualizer/index.ts
3165
+ var MSG_PING = "LARK_VIS_PING";
3166
+ var MSG_PONG = "LARK_VIS_PONG";
3167
+ var MSG_REQUEST_TREE = "LARK_VIS_REQUEST_TREE";
3168
+ var MSG_TREE = "LARK_VIS_TREE";
3169
+ var MSG_TREE_DELTA = "LARK_VIS_TREE_DELTA";
3170
+ function serializeView(view) {
3171
+ return {
3172
+ id: view.id,
3173
+ rendered: !!view.rendered,
3174
+ signature: view.signature,
3175
+ observedStateKeys: view.observedStateKeys ?? null,
3176
+ locationObserved: {
3177
+ flag: view.locationObserved.flag,
3178
+ keys: view.locationObserved.keys,
3179
+ observePath: view.locationObserved.observePath
3180
+ },
3181
+ hasTemplate: !!view.template
3182
+ };
3183
+ }
3184
+ function serializeFrame(frameId) {
3185
+ const frame = Frame.get(frameId);
3186
+ if (!frame) return null;
3187
+ const view = frame.view;
3188
+ const children = [];
3189
+ for (const childId of frame.children()) {
3190
+ const childNode = serializeFrame(childId);
3191
+ if (childNode) {
3192
+ children.push(childNode);
3193
+ }
3194
+ }
3195
+ return {
3196
+ id: frame.id,
3197
+ parentId: frame.parentId ?? null,
3198
+ viewPath: frame.viewPath ?? null,
3199
+ childrenCount: frame.childrenCount,
3200
+ readyCount: frame.readyCount,
3201
+ childrenCreated: frame.childrenCreated,
3202
+ childrenAlter: frame.childrenAlter,
3203
+ destroyed: frame.destroyed,
3204
+ view: view ? serializeView(view) : null,
3205
+ children
3206
+ };
3207
+ }
3208
+ function serializeFrameTree() {
3209
+ const root = Frame.root();
3210
+ const rootNode = serializeFrame(root.id);
3211
+ let totalFrames = 0;
3212
+ const countFrames = (node) => {
3213
+ if (!node) return;
3214
+ totalFrames++;
3215
+ for (const child of node.children) {
3216
+ countFrames(child);
3217
+ }
3218
+ };
3219
+ countFrames(rootNode);
3220
+ return {
3221
+ root: rootNode,
3222
+ totalFrames,
3223
+ timestamp: Date.now(),
3224
+ rootId: root.id
3225
+ };
3226
+ }
3227
+ var bridgeInstalled = false;
3228
+ var lastTreeJson = "";
3229
+ function installFrameVisualizerBridge() {
3230
+ if (bridgeInstalled) return;
3231
+ if (typeof window === "undefined") return;
3232
+ bridgeInstalled = true;
3233
+ window.addEventListener("message", (event) => {
3234
+ const data = event.data;
3235
+ if (!data || typeof data !== "object") return;
3236
+ const type = data.type;
3237
+ if (type === MSG_PING) {
3238
+ const source = event.source;
3239
+ if (source) {
3240
+ source.postMessage({ type: MSG_PONG }, { targetOrigin: "*" });
3241
+ }
3242
+ return;
3243
+ }
3244
+ if (type === MSG_REQUEST_TREE) {
3245
+ const tree = serializeFrameTree();
3246
+ const source = event.source;
3247
+ if (source) {
3248
+ source.postMessage(
3249
+ { type: MSG_TREE, data: tree },
3250
+ { targetOrigin: "*" }
3251
+ );
3252
+ }
3253
+ }
3254
+ });
3255
+ Frame.on("add", () => {
3256
+ pushTreeUpdate();
3257
+ });
3258
+ Frame.on("remove", () => {
3259
+ pushTreeUpdate();
3260
+ });
3261
+ }
3262
+ function pushTreeUpdate() {
3263
+ if (window === window.parent) return;
3264
+ const tree = serializeFrameTree();
3265
+ const treeJson = JSON.stringify(tree);
3266
+ if (treeJson !== lastTreeJson) {
3267
+ lastTreeJson = treeJson;
3268
+ window.parent.postMessage({ type: MSG_TREE_DELTA, data: tree }, "*");
3269
+ }
3270
+ }
3271
+
3160
3272
  // src/framework.ts
3161
3273
  var config = {
3162
3274
  rootId: "lark-root",
@@ -3363,10 +3475,11 @@ var Framework = {
3363
3475
  booted3 = true;
3364
3476
  markBooted();
3365
3477
  markRouterBooted();
3478
+ installFrameVisualizerBridge();
3366
3479
  const rootFrame2 = Frame.root(config.rootId);
3367
3480
  Router._bind();
3368
3481
  const defaultView = config.defaultView || "";
3369
- if (defaultView) {
3482
+ if (defaultView && !rootFrame2.view) {
3370
3483
  rootFrame2.mountView(defaultView);
3371
3484
  }
3372
3485
  },
@@ -3795,20 +3908,20 @@ function createState(initialData, config2) {
3795
3908
  lazySet(state, initialData);
3796
3909
  return state;
3797
3910
  }
3798
- var currLazySetKey = null;
3911
+ var curLazySetKey = null;
3799
3912
  function lazySet(target, data) {
3800
3913
  if (isObject(data)) {
3801
3914
  Reflect.ownKeys(data).forEach((key) => {
3802
3915
  const strKey = key;
3803
- if (currLazySetKey) throw new Error("[lark-store] lazy set key conflict");
3804
- currLazySetKey = strKey;
3916
+ if (curLazySetKey) throw new Error("[lark-store] lazy set key conflict");
3917
+ curLazySetKey = strKey;
3805
3918
  target[strKey] = data[strKey];
3806
3919
  });
3807
3920
  }
3808
3921
  }
3809
3922
  function isLazySet(property) {
3810
- if (currLazySetKey === property) {
3811
- currLazySetKey = "";
3923
+ if (curLazySetKey === property) {
3924
+ curLazySetKey = "";
3812
3925
  return true;
3813
3926
  }
3814
3927
  return false;
@@ -4302,7 +4415,7 @@ function multi(useStore) {
4302
4415
  return useFn(view);
4303
4416
  });
4304
4417
  const mixinObj = {
4305
- ctor() {
4418
+ make() {
4306
4419
  if (!rootViewPath) {
4307
4420
  const owner = this["owner"];
4308
4421
  rootViewPath = owner?.["path"] || "";
@@ -4326,9 +4439,9 @@ function jsObjectToUrlParams(paramsStr) {
4326
4439
  if (objMatch) {
4327
4440
  const inner = objMatch[1];
4328
4441
  const pairs = [];
4329
- const pairRegex = /(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|([^,}]+))/g;
4442
+ const pairRegExp = /(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|([^,}]+))/g;
4330
4443
  let m;
4331
- while ((m = pairRegex.exec(inner)) !== null) {
4444
+ while ((m = pairRegExp.exec(inner)) !== null) {
4332
4445
  const key = m[1];
4333
4446
  const value = m[2] ?? m[3] ?? m[4]?.trim() ?? "";
4334
4447
  pairs.push(`${key}=${value}`);
@@ -4350,19 +4463,19 @@ function restoreComments(source, comments) {
4350
4463
  return comments[parseInt(index, 10)];
4351
4464
  });
4352
4465
  }
4353
- function processLarkEvents(source) {
4466
+ function processViewEvents(source) {
4354
4467
  return source.replace(
4355
- /lark-(\w+)="([^"]+)"/g,
4468
+ /@(\w+)="([^"]+)"/g,
4356
4469
  (fullAttr, eventName, attrValue) => {
4357
4470
  const eventMatch = attrValue.match(/^(\w+)\((.*)\)$/s);
4358
4471
  if (!eventMatch) return fullAttr;
4359
4472
  const handlerName = eventMatch[1];
4360
4473
  const paramsStr = eventMatch[2].trim();
4361
4474
  if (!paramsStr) {
4362
- return `lark-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER2}${handlerName}()"`;
4475
+ return `@${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER2}${handlerName}()"`;
4363
4476
  }
4364
4477
  const urlParams = jsObjectToUrlParams(paramsStr);
4365
- return `lark-${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER2}${handlerName}(${urlParams})"`;
4478
+ return `@${eventName}="${VIEW_ID_PLACEHOLDER}${SPLITTER2}${handlerName}(${urlParams})"`;
4366
4479
  }
4367
4480
  );
4368
4481
  }
@@ -4435,7 +4548,7 @@ function convertArtSyntax(source, debug) {
4435
4548
  }
4436
4549
  if (blockStack.length > 0) {
4437
4550
  const unclosed = blockStack.map((b) => `"${b.ctrl}" at line ${b.line}`).join(", ");
4438
- throw new Error(`[Lark Error(tmpl-art)] unclosed block(s): ${unclosed}`);
4551
+ throw new Error(`[@lark/mvc error] unclosed block(s): ${unclosed}`);
4439
4552
  }
4440
4553
  return result.join("");
4441
4554
  }
@@ -4534,7 +4647,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
4534
4647
  const object = tokens[0];
4535
4648
  if (tokens.length > 1 && tokens[1] !== "as") {
4536
4649
  throw new Error(
4537
- `[Lark Error(tmpl-art)] bad each syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{each list as item [index]}}`
4650
+ `[@lark/mvc error] bad each syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{each list as item [index]}}`
4538
4651
  );
4539
4652
  }
4540
4653
  const restTokens = tokens.slice(2);
@@ -4556,12 +4669,12 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
4556
4669
  }
4557
4670
  return `${debugPrefix}<%for(let ${index}=0${refExpr},${refObjCount}=${refObj}.length${lastCount};${index}<${refObjCount};${index}++){${firstAndLast}${valueDecl}%>`;
4558
4671
  }
4559
- case "forin": {
4560
- blockStack.push({ ctrl: "forin", line: lineNo });
4672
+ case "parse": {
4673
+ blockStack.push({ ctrl: "parse", line: lineNo });
4561
4674
  const object = tokens[0];
4562
4675
  if (tokens.length > 1 && tokens[1] !== "as") {
4563
4676
  throw new Error(
4564
- `[Lark Error(tmpl-art)] bad forin syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{forin obj as val [key]}}`
4677
+ `[@lark/mvc error] bad parse syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{for-in obj as val [key]}}`
4565
4678
  );
4566
4679
  }
4567
4680
  const restTokens2 = tokens.slice(2);
@@ -4582,18 +4695,18 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
4582
4695
  return `${debugPrefix}<%let ${tokens.join(" ")};%>`;
4583
4696
  case "/if":
4584
4697
  case "/each":
4585
- case "/forin":
4698
+ case "/parse":
4586
4699
  case "/for": {
4587
4700
  const expectedCtrl = keyword.substring(1);
4588
4701
  const last = blockStack.pop();
4589
4702
  if (!last) {
4590
4703
  throw new Error(
4591
- `[Lark Error(tmpl-art)] unexpected {{${code}}}: no matching open block`
4704
+ `[@lark/mvc error] unexpected {{${code}}}: no matching open block`
4592
4705
  );
4593
4706
  }
4594
4707
  if (last.ctrl !== expectedCtrl) {
4595
4708
  throw new Error(
4596
- `[Lark Error(tmpl-art)] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
4709
+ `[@lark/mvc error] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
4597
4710
  );
4598
4711
  }
4599
4712
  return `${debugPrefix}<%}%>`;
@@ -4670,12 +4783,12 @@ function compileToFunction(source, debug, file) {
4670
4783
  index - 2
4671
4784
  );
4672
4785
  const x11 = String.fromCharCode(17);
4673
- const artReg = new RegExp(`^'(\\d+)${x11}([^${x11}]+)${x11}'$`);
4674
- const artM = expr.match(artReg);
4786
+ const artRegExp = new RegExp(`^'(\\d+)${x11}([^${x11}]+)${x11}'$`);
4787
+ const artM = expr.match(artRegExp);
4675
4788
  let art = "";
4676
4789
  let line = -1;
4677
4790
  if (artM) {
4678
- expr = expr.replace(artReg, "");
4791
+ expr = expr.replace(artRegExp, "");
4679
4792
  art = artM[2];
4680
4793
  line = parseInt(artM[1], 10);
4681
4794
  } else {
@@ -4734,8 +4847,8 @@ function compileToFunction(source, debug, file) {
4734
4847
  const filePart = file ? `\\r\\n\\tat file:${file}` : "";
4735
4848
  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;}`;
4736
4849
  }
4737
- const viewIdReg = new RegExp(String.fromCharCode(31), "g");
4738
- funcSource = funcSource.replace(viewIdReg, `'+$viewId+'`);
4850
+ const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
4851
+ funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
4739
4852
  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;}}` : "";
4740
4853
  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)}`;
4741
4854
  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)}`;
@@ -4749,8 +4862,8 @@ function compileTemplate(source, options = {}) {
4749
4862
  const { debug = false, globalVars = [], file } = options;
4750
4863
  const { protectedSource, comments } = protectComments(source);
4751
4864
  const converted = convertArtSyntax(protectedSource, debug);
4752
- const larkEventProcessed = processLarkEvents(converted);
4753
- const finalSource = restoreComments(larkEventProcessed, comments);
4865
+ const viewEventProcessed = processViewEvents(converted);
4866
+ const finalSource = restoreComments(viewEventProcessed, comments);
4754
4867
  const funcBody = compileToFunction(finalSource, debug, file);
4755
4868
  const varDeclarations = globalVars.map((key) => `,${key}=$$.${key}`).join("");
4756
4869
  const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
@@ -4768,20 +4881,20 @@ function compileTemplate(source, options = {}) {
4768
4881
  }
4769
4882
  function extractGlobalVars(source) {
4770
4883
  const { protectedSource, comments: _comments } = protectComments(source);
4771
- const larkEventProcessed = processLarkEvents(protectedSource);
4772
- const converted = convertArtSyntax(larkEventProcessed, false);
4773
- const tmpl = restoreComments(converted, _comments);
4774
- const tmplCmdReg = /<%([@=!:])?([\s\S]*?)%>|$/g;
4884
+ const viewEventProcessed = processViewEvents(protectedSource);
4885
+ const converted = convertArtSyntax(viewEventProcessed, false);
4886
+ const template = restoreComments(converted, _comments);
4887
+ const templateCmdRegExp = /<%([@=!:])?([\s\S]*?)%>|$/g;
4775
4888
  const fnParts = [];
4776
4889
  const htmlStore = {};
4777
4890
  let htmlIndex = 0;
4778
4891
  let lastIndex = 0;
4779
4892
  const htmlKey = "";
4780
- tmpl.replace(
4781
- tmplCmdReg,
4893
+ template.replace(
4894
+ templateCmdRegExp,
4782
4895
  (match, operate, content, offset) => {
4783
4896
  const start = operate ? 3 : 2;
4784
- const htmlText = tmpl.substring(lastIndex, offset + start);
4897
+ const htmlText = template.substring(lastIndex, offset + start);
4785
4898
  const key = htmlKey + htmlIndex++ + htmlKey;
4786
4899
  htmlStore[key] = htmlText;
4787
4900
  lastIndex = offset + match.length - 2;
@@ -4866,17 +4979,17 @@ function extractGlobalVars(source) {
4866
4979
  }
4867
4980
  function fallbackExtractVariables(source) {
4868
4981
  const vars = /* @__PURE__ */ new Set();
4869
- const outputReg = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
4982
+ const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
4870
4983
  let m;
4871
- while ((m = outputReg.exec(source)) !== null) {
4984
+ while ((m = outputRegExp.exec(source)) !== null) {
4872
4985
  vars.add(m[1]);
4873
4986
  }
4874
- const eachReg = /\{\{each\s+([a-zA-Z_$][\w$]*)\s+as/g;
4875
- while ((m = eachReg.exec(source)) !== null) {
4987
+ const eachRegExp = /\{\{each\s+([a-zA-Z_$][\w$]*)\s+as/g;
4988
+ while ((m = eachRegExp.exec(source)) !== null) {
4876
4989
  vars.add(m[1]);
4877
4990
  }
4878
- const ifReg = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
4879
- while ((m = ifReg.exec(source)) !== null) {
4991
+ const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
4992
+ while ((m = ifRegExp.exec(source)) !== null) {
4880
4993
  vars.add(m[1]);
4881
4994
  }
4882
4995
  return Array.from(vars).filter((v) => !BUILTIN_GLOBAL_SET.has(v));
@@ -4939,7 +5052,7 @@ var BUILTIN_GLOBALS = {
4939
5052
  // {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
4940
5053
  // Not a standalone function; referenced inside $e's closure.
4941
5054
  $em: 1,
4942
- // HTML entity RegExp — internal regex used by $e:
5055
+ // HTML entity RegExp — internal regexp used by $e:
4943
5056
  // /[&<>"'`]/g
4944
5057
  $er: 1,
4945
5058
  // HTML entity replacer function — internal helper used by $e:
@@ -4953,19 +5066,18 @@ var BUILTIN_GLOBALS = {
4953
5066
  // Reference lookup: (refData, value) => key
4954
5067
  // Finds or allocates a SPLITTER-prefixed key in refData for a given
4955
5068
  // object reference. Used by {{@ref}} operator for passing object
4956
- // references to child views via lark-view attributes.
4957
- // Aligned with mx.js Updater_Ref.
5069
+ // references to child views via v-lark attributes.
4958
5070
  $i: 1,
4959
5071
  // URI encoder: v => encodeURIComponent($n(v)).replace(/[!')(*]/g, extraMap)
4960
5072
  // Extends encodeURIComponent with encoding of ! ' ( ) *.
4961
- // Applied to values in lark-event URL parameters and {{!uri}} contexts.
5073
+ // Applied to values in @event URL parameters and {{!uri}} contexts.
4962
5074
  $eu: 1,
4963
5075
  // Quote encoder: v => $n(v).replace(/['"\\]/g, '\\$&')
4964
5076
  // Escapes quotes and backslashes for safe embedding in HTML attribute
4965
5077
  // values (e.g. data-json='...').
4966
5078
  $eq: 1,
4967
5079
  // View ID — the unique identifier of the owning View instance.
4968
- // Injected into lark-event attribute values at render time so that
5080
+ // Injected into @event attribute values at render time so that
4969
5081
  // EventDelegator can dispatch events to the correct View handler.
4970
5082
  // The \x1f placeholder in compiled output is replaced with '+$viewId+'.
4971
5083
  $viewId: 1,
@@ -5056,7 +5168,7 @@ var BUILTIN_GLOBAL_SET = new Set(Object.keys(BUILTIN_GLOBALS));
5056
5168
  Bag,
5057
5169
  CALL_BREAK_TIME,
5058
5170
  Cache,
5059
- EVT_METHOD_REG,
5171
+ EVENT_METHOD_REGEXP,
5060
5172
  EventDelegator,
5061
5173
  EventEmitter,
5062
5174
  Frame,
@@ -5068,12 +5180,9 @@ var BUILTIN_GLOBAL_SET = new Set(Object.keys(BUILTIN_GLOBALS));
5068
5180
  SPLITTER,
5069
5181
  Service,
5070
5182
  State,
5071
- TAG_ATTR_KEY,
5072
- TAG_KEY,
5073
- TAG_NAME_REGEX,
5074
- TAG_VIEW_KEY,
5183
+ TAG_NAME_REGEXP,
5075
5184
  Updater,
5076
- VIEW_EVT_METHOD_REG,
5185
+ VIEW_EVENT_METHOD_REGEXP,
5077
5186
  View,
5078
5187
  applyIdUpdates,
5079
5188
  applyStyle,
@@ -5102,6 +5211,7 @@ var BUILTIN_GLOBAL_SET = new Set(Object.keys(BUILTIN_GLOBALS));
5102
5211
  getStore,
5103
5212
  getUseStore,
5104
5213
  has,
5214
+ installFrameVisualizerBridge,
5105
5215
  isArray,
5106
5216
  isPlainObject,
5107
5217
  isPrimitive,
@@ -5122,6 +5232,7 @@ var BUILTIN_GLOBAL_SET = new Set(Object.keys(BUILTIN_GLOBALS));
5122
5232
  parseUri,
5123
5233
  registerViewClass,
5124
5234
  safeguard,
5235
+ serializeFrameTree,
5125
5236
  setData,
5126
5237
  shallowSet,
5127
5238
  storeMark,