marko 6.0.0-next.3.62 → 6.0.0-next.3.64

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.
@@ -305,12 +305,12 @@ runtime.x = (op, id, node, start, placeholderCallback) => {
305
305
  // repurpose "op" for callbacks ...carefully
306
306
  if (op = runtime.j[id]) {
307
307
  placeholderCallback = placeholder.c;
308
- placeholder.c = () => placeholderCallback() + op(runtime);
308
+ placeholder.c = () => placeholderCallback() + op(runtime.r);
309
309
  }
310
310
  }
311
311
  };
312
312
  })`
313
- ) : `(e=>{let i,t,r,l={},o=(e,i)=>{e.replaceWith(...i.childNodes),i.remove()};e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(d,n,a,c,p)=>{"#"==d?(l[n]=t).i++:a==r&&i(),"T"==a.tagName&&(n=a.getAttribute(e.i))&&((c=e.l["^"+n])&&(l[n]={i:1,c(i=e.l[n]||a){for(;i.parentNode!==c.parentNode;)i=i.parentNode;for(;i!=r;(r=c.nextSibling).remove());o(c,a)}}),r=a.nextSibling,t=l[n],i=()=>{c||o(e.l[n],a),--t.i||t.c()},(d=e.j[n])&&(p=t.c,t.c=()=>p()+d(e)))}})`;
313
+ ) : `(e=>{let i,t,r,l={},o=(e,i)=>{e.replaceWith(...i.childNodes),i.remove()};e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(d,n,a,c,p)=>{"#"==d?(l[n]=t).i++:a==r&&i(),"T"==a.tagName&&(n=a.getAttribute(e.i))&&((c=e.l["^"+n])&&(l[n]={i:1,c(i=e.l[n]||a){for(;i.parentNode!==c.parentNode;)i=i.parentNode;for(;i!=r;(r=c.nextSibling).remove());o(c,a)}}),r=a.nextSibling,t=l[n],i=()=>{c||o(e.l[n],a),--t.i||t.c()},(d=e.j[n])&&(p=t.c,t.c=()=>p()+d(e.r)))}})`;
314
314
 
315
315
  // src/html/serializer.ts
316
316
  var { hasOwnProperty } = {};
@@ -564,6 +564,7 @@ var State = class {
564
564
  ids = 0;
565
565
  flush = 0;
566
566
  flushed = false;
567
+ wroteUndefined = false;
567
568
  buf = [];
568
569
  refs = /* @__PURE__ */ new WeakMap();
569
570
  assigned = /* @__PURE__ */ new Set();
@@ -689,7 +690,12 @@ function writeRoot(state, root) {
689
690
  for (const chunk of buf) {
690
691
  result += chunk;
691
692
  }
692
- return "_=>" + result;
693
+ if (state.wroteUndefined) {
694
+ state.wroteUndefined = false;
695
+ return "(_,$)=>" + result;
696
+ } else {
697
+ return "_=>" + result;
698
+ }
693
699
  }
694
700
  function writeAssigned(state) {
695
701
  if (state.assigned.size) {
@@ -981,13 +987,23 @@ function writePlainObject(state, val, ref) {
981
987
  return true;
982
988
  }
983
989
  function writeArray(state, val, ref) {
984
- state.buf.push("[");
985
- writeProp(state, val[0], ref, "0");
986
- for (let i = 1; i < val.length; i++) {
987
- state.buf.push(",");
988
- writeProp(state, val[i], ref, "" + i);
990
+ let sep = "[";
991
+ for (let i = 0; i < val.length; i++) {
992
+ const item = val[i];
993
+ state.buf.push(sep);
994
+ sep = ",";
995
+ if (item === void 0) {
996
+ state.wroteUndefined = true;
997
+ state.buf.push("$");
998
+ } else {
999
+ writeProp(state, item, ref, "" + i);
1000
+ }
1001
+ }
1002
+ if (sep === "[") {
1003
+ state.buf.push("[]");
1004
+ } else {
1005
+ state.buf.push("]");
989
1006
  }
990
- state.buf.push("]");
991
1007
  return true;
992
1008
  }
993
1009
  function writeDate(state, val) {
@@ -1016,23 +1032,6 @@ function writeMap(state, val, ref) {
1016
1032
  state.buf.push("new Map");
1017
1033
  return true;
1018
1034
  }
1019
- const items = [];
1020
- let assigns;
1021
- for (let [itemKey, itemValue] of val) {
1022
- if (itemKey === val) {
1023
- itemKey = void 0;
1024
- (assigns ||= []).push("i[" + items.length + "][0]");
1025
- }
1026
- if (itemValue === val) {
1027
- itemValue = void 0;
1028
- (assigns ||= []).push("i[" + items.length + "][1]");
1029
- }
1030
- if (itemValue === void 0) {
1031
- items.push([itemKey]);
1032
- } else {
1033
- items.push([itemKey, itemValue]);
1034
- }
1035
- }
1036
1035
  const arrayRef = new Reference(
1037
1036
  ref,
1038
1037
  null,
@@ -1040,11 +1039,56 @@ function writeMap(state, val, ref) {
1040
1039
  null,
1041
1040
  nextRefAccess(state)
1042
1041
  );
1043
- state.buf.push(
1044
- (assigns ? "((m,i)=>(" + assignsToString(assigns, "m") + ",i.forEach(i=>m.set(i[0],i[1])),m))(new Map," : "new Map(") + arrayRef.id + "="
1045
- );
1046
- writeArray(state, items, arrayRef);
1047
- state.buf.push(")");
1042
+ const items = [];
1043
+ let assigns;
1044
+ let i = 0;
1045
+ if (val.size < 25) {
1046
+ for (let [itemKey, itemValue] of val) {
1047
+ if (itemKey === val) {
1048
+ itemKey = void 0;
1049
+ (assigns ||= []).push("a[" + i + "][0]");
1050
+ }
1051
+ if (itemValue === val) {
1052
+ itemValue = void 0;
1053
+ (assigns ||= []).push("a[" + i + "][1]");
1054
+ }
1055
+ i = items.push(
1056
+ itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]
1057
+ );
1058
+ }
1059
+ if (assigns) {
1060
+ state.buf.push(
1061
+ "((m,a)=>(" + assignsToString(assigns, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map," + arrayRef.id + "="
1062
+ );
1063
+ } else {
1064
+ state.buf.push("new Map(" + arrayRef.id + "=");
1065
+ }
1066
+ writeArray(state, items, arrayRef);
1067
+ state.buf.push(")");
1068
+ } else {
1069
+ for (let [itemKey, itemValue] of val) {
1070
+ if (itemKey === val) {
1071
+ itemKey = 0;
1072
+ (assigns ||= []).push("a[" + i + "]");
1073
+ }
1074
+ if (itemValue === val) {
1075
+ itemValue = 0;
1076
+ (assigns ||= []).push("a[" + (i + 1) + "]");
1077
+ }
1078
+ i = items.push(itemKey, itemValue);
1079
+ }
1080
+ if (assigns) {
1081
+ state.buf.push(
1082
+ "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignsToString(assigns, "new Map") + "))(" + arrayRef.id + "="
1083
+ );
1084
+ } else {
1085
+ state.buf.push(
1086
+ "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(" + arrayRef.id + "="
1087
+ );
1088
+ }
1089
+ writeArray(state, items, arrayRef);
1090
+ state.buf.push(")");
1091
+ }
1048
1092
  return true;
1049
1093
  }
1050
1094
  function writeSet(state, val, ref) {
@@ -1054,12 +1098,13 @@ function writeSet(state, val, ref) {
1054
1098
  }
1055
1099
  const items = [];
1056
1100
  let assigns;
1101
+ let i = 0;
1057
1102
  for (let item of val) {
1058
1103
  if (item === val) {
1059
- item = void 0;
1060
- (assigns ||= []).push("i[" + items.length + "]");
1104
+ item = 0;
1105
+ (assigns ||= []).push("i[" + i + "]");
1061
1106
  }
1062
- items.push(item);
1107
+ i = items.push(item);
1063
1108
  }
1064
1109
  const arrayRef = new Reference(
1065
1110
  ref,
@@ -1151,7 +1196,7 @@ function writeFormData(state, val) {
1151
1196
  let valStr = "";
1152
1197
  for (const [key, value] of val) {
1153
1198
  if (typeof value === "string") {
1154
- valStr += sep + "[" + quote(key, 0) + "," + quote(value, 0) + "]";
1199
+ valStr += sep + quote(key, 0) + "," + quote(value, 0);
1155
1200
  sep = ",";
1156
1201
  }
1157
1202
  }
@@ -1159,7 +1204,7 @@ function writeFormData(state, val) {
1159
1204
  state.buf.push("new FormData");
1160
1205
  } else {
1161
1206
  state.buf.push(
1162
- "((f,i)=>(f,i.forEach(i=>f.append(i[0],i[1])),f))(new FormData," + valStr + "])"
1207
+ valStr + "].reduce((f,v,i,a)=>i%2&&f.append(v,a[i+1])||f,new FormData)"
1163
1208
  );
1164
1209
  }
1165
1210
  return true;
@@ -221,12 +221,12 @@ runtime.x = (op, id, node, start, placeholderCallback) => {
221
221
  // repurpose "op" for callbacks ...carefully
222
222
  if (op = runtime.j[id]) {
223
223
  placeholderCallback = placeholder.c;
224
- placeholder.c = () => placeholderCallback() + op(runtime);
224
+ placeholder.c = () => placeholderCallback() + op(runtime.r);
225
225
  }
226
226
  }
227
227
  };
228
228
  })`
229
- ) : `(e=>{let i,t,r,l={},o=(e,i)=>{e.replaceWith(...i.childNodes),i.remove()};e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(d,n,a,c,p)=>{"#"==d?(l[n]=t).i++:a==r&&i(),"T"==a.tagName&&(n=a.getAttribute(e.i))&&((c=e.l["^"+n])&&(l[n]={i:1,c(i=e.l[n]||a){for(;i.parentNode!==c.parentNode;)i=i.parentNode;for(;i!=r;(r=c.nextSibling).remove());o(c,a)}}),r=a.nextSibling,t=l[n],i=()=>{c||o(e.l[n],a),--t.i||t.c()},(d=e.j[n])&&(p=t.c,t.c=()=>p()+d(e)))}})`;
229
+ ) : `(e=>{let i,t,r,l={},o=(e,i)=>{e.replaceWith(...i.childNodes),i.remove()};e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(d,n,a,c,p)=>{"#"==d?(l[n]=t).i++:a==r&&i(),"T"==a.tagName&&(n=a.getAttribute(e.i))&&((c=e.l["^"+n])&&(l[n]={i:1,c(i=e.l[n]||a){for(;i.parentNode!==c.parentNode;)i=i.parentNode;for(;i!=r;(r=c.nextSibling).remove());o(c,a)}}),r=a.nextSibling,t=l[n],i=()=>{c||o(e.l[n],a),--t.i||t.c()},(d=e.j[n])&&(p=t.c,t.c=()=>p()+d(e.r)))}})`;
230
230
 
231
231
  // src/html/serializer.ts
232
232
  var { hasOwnProperty } = {};
@@ -480,6 +480,7 @@ var State = class {
480
480
  ids = 0;
481
481
  flush = 0;
482
482
  flushed = false;
483
+ wroteUndefined = false;
483
484
  buf = [];
484
485
  refs = /* @__PURE__ */ new WeakMap();
485
486
  assigned = /* @__PURE__ */ new Set();
@@ -605,7 +606,12 @@ function writeRoot(state, root) {
605
606
  for (const chunk of buf) {
606
607
  result += chunk;
607
608
  }
608
- return "_=>" + result;
609
+ if (state.wroteUndefined) {
610
+ state.wroteUndefined = false;
611
+ return "(_,$)=>" + result;
612
+ } else {
613
+ return "_=>" + result;
614
+ }
609
615
  }
610
616
  function writeAssigned(state) {
611
617
  if (state.assigned.size) {
@@ -897,13 +903,23 @@ function writePlainObject(state, val, ref) {
897
903
  return true;
898
904
  }
899
905
  function writeArray(state, val, ref) {
900
- state.buf.push("[");
901
- writeProp(state, val[0], ref, "0");
902
- for (let i = 1; i < val.length; i++) {
903
- state.buf.push(",");
904
- writeProp(state, val[i], ref, "" + i);
906
+ let sep = "[";
907
+ for (let i = 0; i < val.length; i++) {
908
+ const item = val[i];
909
+ state.buf.push(sep);
910
+ sep = ",";
911
+ if (item === void 0) {
912
+ state.wroteUndefined = true;
913
+ state.buf.push("$");
914
+ } else {
915
+ writeProp(state, item, ref, "" + i);
916
+ }
917
+ }
918
+ if (sep === "[") {
919
+ state.buf.push("[]");
920
+ } else {
921
+ state.buf.push("]");
905
922
  }
906
- state.buf.push("]");
907
923
  return true;
908
924
  }
909
925
  function writeDate(state, val) {
@@ -932,23 +948,6 @@ function writeMap(state, val, ref) {
932
948
  state.buf.push("new Map");
933
949
  return true;
934
950
  }
935
- const items = [];
936
- let assigns;
937
- for (let [itemKey, itemValue] of val) {
938
- if (itemKey === val) {
939
- itemKey = void 0;
940
- (assigns ||= []).push("i[" + items.length + "][0]");
941
- }
942
- if (itemValue === val) {
943
- itemValue = void 0;
944
- (assigns ||= []).push("i[" + items.length + "][1]");
945
- }
946
- if (itemValue === void 0) {
947
- items.push([itemKey]);
948
- } else {
949
- items.push([itemKey, itemValue]);
950
- }
951
- }
952
951
  const arrayRef = new Reference(
953
952
  ref,
954
953
  null,
@@ -956,11 +955,56 @@ function writeMap(state, val, ref) {
956
955
  null,
957
956
  nextRefAccess(state)
958
957
  );
959
- state.buf.push(
960
- (assigns ? "((m,i)=>(" + assignsToString(assigns, "m") + ",i.forEach(i=>m.set(i[0],i[1])),m))(new Map," : "new Map(") + arrayRef.id + "="
961
- );
962
- writeArray(state, items, arrayRef);
963
- state.buf.push(")");
958
+ const items = [];
959
+ let assigns;
960
+ let i = 0;
961
+ if (val.size < 25) {
962
+ for (let [itemKey, itemValue] of val) {
963
+ if (itemKey === val) {
964
+ itemKey = void 0;
965
+ (assigns ||= []).push("a[" + i + "][0]");
966
+ }
967
+ if (itemValue === val) {
968
+ itemValue = void 0;
969
+ (assigns ||= []).push("a[" + i + "][1]");
970
+ }
971
+ i = items.push(
972
+ itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]
973
+ );
974
+ }
975
+ if (assigns) {
976
+ state.buf.push(
977
+ "((m,a)=>(" + assignsToString(assigns, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map," + arrayRef.id + "="
978
+ );
979
+ } else {
980
+ state.buf.push("new Map(" + arrayRef.id + "=");
981
+ }
982
+ writeArray(state, items, arrayRef);
983
+ state.buf.push(")");
984
+ } else {
985
+ for (let [itemKey, itemValue] of val) {
986
+ if (itemKey === val) {
987
+ itemKey = 0;
988
+ (assigns ||= []).push("a[" + i + "]");
989
+ }
990
+ if (itemValue === val) {
991
+ itemValue = 0;
992
+ (assigns ||= []).push("a[" + (i + 1) + "]");
993
+ }
994
+ i = items.push(itemKey, itemValue);
995
+ }
996
+ if (assigns) {
997
+ state.buf.push(
998
+ "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignsToString(assigns, "new Map") + "))(" + arrayRef.id + "="
999
+ );
1000
+ } else {
1001
+ state.buf.push(
1002
+ "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(" + arrayRef.id + "="
1003
+ );
1004
+ }
1005
+ writeArray(state, items, arrayRef);
1006
+ state.buf.push(")");
1007
+ }
964
1008
  return true;
965
1009
  }
966
1010
  function writeSet(state, val, ref) {
@@ -970,12 +1014,13 @@ function writeSet(state, val, ref) {
970
1014
  }
971
1015
  const items = [];
972
1016
  let assigns;
1017
+ let i = 0;
973
1018
  for (let item of val) {
974
1019
  if (item === val) {
975
- item = void 0;
976
- (assigns ||= []).push("i[" + items.length + "]");
1020
+ item = 0;
1021
+ (assigns ||= []).push("i[" + i + "]");
977
1022
  }
978
- items.push(item);
1023
+ i = items.push(item);
979
1024
  }
980
1025
  const arrayRef = new Reference(
981
1026
  ref,
@@ -1067,7 +1112,7 @@ function writeFormData(state, val) {
1067
1112
  let valStr = "";
1068
1113
  for (const [key, value] of val) {
1069
1114
  if (typeof value === "string") {
1070
- valStr += sep + "[" + quote(key, 0) + "," + quote(value, 0) + "]";
1115
+ valStr += sep + quote(key, 0) + "," + quote(value, 0);
1071
1116
  sep = ",";
1072
1117
  }
1073
1118
  }
@@ -1075,7 +1120,7 @@ function writeFormData(state, val) {
1075
1120
  state.buf.push("new FormData");
1076
1121
  } else {
1077
1122
  state.buf.push(
1078
- "((f,i)=>(f,i.forEach(i=>f.append(i[0],i[1])),f))(new FormData," + valStr + "])"
1123
+ valStr + "].reduce((f,v,i,a)=>i%2&&f.append(v,a[i+1])||f,new FormData)"
1079
1124
  );
1080
1125
  }
1081
1126
  return true;
@@ -6,6 +6,7 @@ export declare function createTry(nodeAccessor: Accessor, tryContent: Renderer):
6
6
  catch: unknown;
7
7
  placeholder: unknown;
8
8
  }) => void;
9
+ export declare function renderCatch(scope: Scope, error: unknown, async?: boolean): void;
9
10
  export declare function conditional(nodeAccessor: Accessor, ...branches: Renderer[]): (scope: Scope, newBranch: number) => void;
10
11
  export declare function patchDynamicTag(fn: <T extends typeof dynamicTag>(cond: T) => T): void;
11
12
  export declare let dynamicTag: (nodeAccessor: Accessor, getContent?: ((scope: Scope) => Renderer) | 0, getTagVar?: (() => Signal<unknown>) | 0, inputIsArgs?: 1) => Signal<Renderer | string | undefined>;
@@ -1,12 +1,14 @@
1
- import { type Scope } from "../common/types";
1
+ import type { Scope } from "../common/types";
2
2
  import type { Signal } from "./signals";
3
3
  type ExecFn<S extends Scope = Scope> = (scope: S, arg?: any) => void;
4
+ export declare const caughtError: WeakSet<unknown[]>;
5
+ export declare const placeholderShown: WeakSet<unknown[]>;
4
6
  export declare let pendingEffects: unknown[];
5
7
  export declare let rendering: boolean;
6
8
  export declare function queueRender<T>(scope: Scope, signal: Signal<T>, signalKey: number, value?: T, scopeKey?: number): void;
7
9
  export declare function queueEffect<S extends Scope, T extends ExecFn<S>>(scope: S, fn: T): void;
8
10
  export declare function run(): void;
9
11
  export declare function prepareEffects(fn: () => void): unknown[];
10
- export declare function runEffects(effects: unknown[]): void;
12
+ export declare let runEffects: (effects: unknown[]) => void;
11
13
  export declare let enableCatch: () => void;
12
14
  export {};
@@ -2,6 +2,7 @@ import type { BranchScope, Scope } from "../common/types";
2
2
  export declare function createScope($global: Scope["$global"], closestBranch?: BranchScope): Scope;
3
3
  export declare function skipScope(scope: Scope): number;
4
4
  export declare function finishPendingScopes(): void;
5
+ export declare function findBranchWithKey(scope: Scope, key: string): BranchScope | undefined;
5
6
  export declare function destroyBranch(branch: BranchScope): void;
6
7
  export declare function removeAndDestroyBranch(branch: BranchScope): void;
7
8
  export declare function insertBranchBefore(branch: BranchScope, parentNode: ParentNode, nextSibling: Node | null): void;