marko 6.0.155 → 6.0.157

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.
@@ -1,6 +1,8 @@
1
+ import { type Scope } from "./types";
1
2
  export declare function _el_read_error(): void;
2
3
  export declare function _hoist_read_error(): void;
3
4
  export declare function _assert_hoist(value: unknown): void;
5
+ export declare function _assert_init(scope: Scope, accessor: string): any;
4
6
  export declare function assertExclusiveAttrs(attrs: Record<string, unknown> | undefined, onError?: typeof throwErr): void;
5
7
  export declare function assertValidTagName(tagName: string): void;
6
8
  declare function throwErr(msg: string): void;
package/dist/debug/dom.js CHANGED
@@ -23,6 +23,7 @@ __export(dom_exports, {
23
23
  $signal: () => $signal,
24
24
  $signalReset: () => $signalReset,
25
25
  _assert_hoist: () => _assert_hoist,
26
+ _assert_init: () => _assert_init,
26
27
  _attr: () => _attr,
27
28
  _attr_class: () => _attr_class,
28
29
  _attr_class_item: () => _attr_class_item,
@@ -108,6 +109,7 @@ __export(dom_exports, {
108
109
  forTo: () => forTo,
109
110
  forUntil: () => forUntil,
110
111
  init: () => init,
112
+ initEmbedded: () => initEmbedded,
111
113
  run: () => run
112
114
  });
113
115
  module.exports = __toCommonJS(dom_exports);
@@ -158,6 +160,21 @@ function _assert_hoist(value) {
158
160
  );
159
161
  }
160
162
  }
163
+ function _assert_init(scope, accessor) {
164
+ if (scope["#Creating" /* Creating */] || !(accessor in scope)) {
165
+ try {
166
+ __UNINITIALIZED__;
167
+ const __UNINITIALIZED__ = 1;
168
+ } catch (err) {
169
+ err.message = err.message.replaceAll("__UNINITIALIZED__", accessor);
170
+ throw err;
171
+ }
172
+ throw new ReferenceError(
173
+ `Cannot access "${accessor}" before initialization.`
174
+ );
175
+ }
176
+ return scope[accessor];
177
+ }
161
178
  function assertExclusiveAttrs(attrs, onError = throwErr) {
162
179
  if (attrs) {
163
180
  let exclusiveAttrs;
@@ -412,12 +429,18 @@ function destroyBranch(branch) {
412
429
  branch["#ParentBranch" /* ParentBranch */]?.["#BranchScopes" /* BranchScopes */]?.delete(
413
430
  branch
414
431
  );
415
- destroyNestedBranches(branch);
432
+ destroyNestedScopes(branch);
433
+ }
434
+ function destroyScope(scope) {
435
+ if (!scope["#Destroyed" /* Destroyed */]) {
436
+ destroyNestedScopes(scope);
437
+ resetControllers(scope);
438
+ }
416
439
  }
417
- function destroyNestedBranches(branch) {
418
- branch["#Destroyed" /* Destroyed */] = 1;
419
- branch["#BranchScopes" /* BranchScopes */]?.forEach(destroyNestedBranches);
420
- branch["#AbortScopes" /* AbortScopes */]?.forEach(resetControllers);
440
+ function destroyNestedScopes(scope) {
441
+ scope["#Destroyed" /* Destroyed */] = 1;
442
+ scope["#BranchScopes" /* BranchScopes */]?.forEach(destroyNestedScopes);
443
+ scope["#AbortScopes" /* AbortScopes */]?.forEach(resetControllers);
421
444
  }
422
445
  function resetControllers(scope) {
423
446
  for (const id in scope["#AbortControllers" /* AbortControllers */]) {
@@ -612,11 +635,6 @@ function _closure(...closureSignals) {
612
635
  function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
613
636
  if (false) valueAccessor = decodeAccessor(valueAccessor);
614
637
  const closureSignal = ((scope) => {
615
- if (true) {
616
- if (!(valueAccessor in (getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */]))) {
617
- throwUninitialized(valueAccessor);
618
- }
619
- }
620
638
  scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
621
639
  fn(scope);
622
640
  subscribeToScopeSet(
@@ -701,16 +719,6 @@ function _hoist(...path) {
701
719
  function _hoist_resume(id, ...path) {
702
720
  return _resume(id, _hoist(...path));
703
721
  }
704
- function throwUninitialized(name) {
705
- try {
706
- __UNINITIALIZED__;
707
- let __UNINITIALIZED__;
708
- } catch (err) {
709
- err.message = err.message.replaceAll("__UNINITIALIZED__", name);
710
- throw err;
711
- }
712
- throw new ReferenceError(`Cannot access '${name}' before initialization`);
713
- }
714
722
 
715
723
  // src/dom/walker.ts
716
724
  var walker = /* @__PURE__ */ document.createTreeWalker(document);
@@ -887,22 +895,49 @@ function createCloneableHTML(html, ns) {
887
895
 
888
896
  // src/dom/resume.ts
889
897
  var registeredValues = {};
898
+ var curRuntimeId;
899
+ var readyLookup;
890
900
  var branchesEnabled;
901
+ var embedEnabled;
891
902
  function enableBranches() {
892
903
  branchesEnabled = 1;
893
904
  }
905
+ var ready = /* @__PURE__ */ ((_) => (id) => {
906
+ readyLookup[id]?.();
907
+ readyLookup[id] = 1;
908
+ })(readyLookup = {});
909
+ function initEmbedded(readyId, runtimeId) {
910
+ embedEnabled = 1;
911
+ ready(readyId);
912
+ init(runtimeId);
913
+ new MutationObserver(() => {
914
+ const renders = self[curRuntimeId];
915
+ for (const renderId in renders) {
916
+ const { s, n } = renders[renderId];
917
+ if (n && !n.isConnected) {
918
+ delete renders[renderId];
919
+ for (const id in s) {
920
+ destroyScope(s[id]);
921
+ }
922
+ }
923
+ }
924
+ }).observe(document.body, { childList: true, subtree: true });
925
+ }
894
926
  function init(runtimeId = DEFAULT_RUNTIME_ID) {
895
- if (true) {
896
- const descriptor = Object.getOwnPropertyDescriptor(self, runtimeId);
897
- if (descriptor && (descriptor.set || descriptor.configurable === false)) {
898
- throw new Error(
899
- `Marko initialized multiple times with the same $global.runtimeId of ${JSON.stringify(runtimeId)}. It could be that there are multiple copies of Marko running on the page.`
900
- );
927
+ if (curRuntimeId) {
928
+ if (true) {
929
+ if (curRuntimeId !== runtimeId) {
930
+ throw new Error(
931
+ `Marko initialized multiple times with different $global.runtimeId's of ${JSON.stringify(runtimeId)} and ${JSON.stringify(curRuntimeId)}.`
932
+ );
933
+ }
901
934
  }
935
+ return;
902
936
  }
937
+ curRuntimeId = runtimeId;
938
+ let resumeRender;
903
939
  const renders = self[runtimeId];
904
940
  const defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc);
905
- let resumeRender;
906
941
  const initRuntime = (renders2) => {
907
942
  defineRuntime({
908
943
  value: resumeRender = ((renderId) => {
@@ -976,6 +1011,10 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
976
1011
  }
977
1012
  };
978
1013
  })();
1014
+ const nextToken = () => lastToken = visitText.slice(
1015
+ lastTokenIndex,
1016
+ (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1
1017
+ );
979
1018
  let $global;
980
1019
  let lastEffect;
981
1020
  let visits;
@@ -987,11 +1026,26 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
987
1026
  let lastToken;
988
1027
  let lastTokenIndex;
989
1028
  let lastScopeId = 0;
990
- const nextToken = () => lastToken = visitText.slice(
991
- lastTokenIndex,
992
- (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1
993
- );
1029
+ if (true) {
1030
+ if (render.m) {
1031
+ throw new Error(
1032
+ `Marko rendered multiple times with $global.runtimeId as ${JSON.stringify(runtimeId)} and $global.renderId as ${JSON.stringify(renderId)}. Ensure each render into a page has a unique $global.renderId.`
1033
+ );
1034
+ }
1035
+ }
994
1036
  render.m = (effects = []) => {
1037
+ if (readyLookup) {
1038
+ for (const readyId in render.b) {
1039
+ if (readyLookup[readyId] !== 1) {
1040
+ readyLookup[readyId] = /* @__PURE__ */ ((prev) => () => {
1041
+ render.m();
1042
+ prev?.();
1043
+ })(readyLookup[readyId]);
1044
+ return effects;
1045
+ }
1046
+ }
1047
+ render.b = 0;
1048
+ }
995
1049
  for (const serialized of resumes = render.r || []) {
996
1050
  if (typeof serialized === "string") {
997
1051
  lastTokenIndex = 0;
@@ -1038,6 +1092,12 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
1038
1092
  visitBranches();
1039
1093
  }
1040
1094
  }
1095
+ if (embedEnabled) {
1096
+ render.n ||= visit?.parentNode.insertBefore(
1097
+ new Text(),
1098
+ visit.nextSibling
1099
+ );
1100
+ }
1041
1101
  visits.length = resumes.length = 0;
1042
1102
  return effects;
1043
1103
  };
@@ -44,6 +44,21 @@ function _assert_hoist(value) {
44
44
  );
45
45
  }
46
46
  }
47
+ function _assert_init(scope, accessor) {
48
+ if (scope["#Creating" /* Creating */] || !(accessor in scope)) {
49
+ try {
50
+ __UNINITIALIZED__;
51
+ const __UNINITIALIZED__ = 1;
52
+ } catch (err) {
53
+ err.message = err.message.replaceAll("__UNINITIALIZED__", accessor);
54
+ throw err;
55
+ }
56
+ throw new ReferenceError(
57
+ `Cannot access "${accessor}" before initialization.`
58
+ );
59
+ }
60
+ return scope[accessor];
61
+ }
47
62
  function assertExclusiveAttrs(attrs, onError = throwErr) {
48
63
  if (attrs) {
49
64
  let exclusiveAttrs;
@@ -298,12 +313,18 @@ function destroyBranch(branch) {
298
313
  branch["#ParentBranch" /* ParentBranch */]?.["#BranchScopes" /* BranchScopes */]?.delete(
299
314
  branch
300
315
  );
301
- destroyNestedBranches(branch);
316
+ destroyNestedScopes(branch);
317
+ }
318
+ function destroyScope(scope) {
319
+ if (!scope["#Destroyed" /* Destroyed */]) {
320
+ destroyNestedScopes(scope);
321
+ resetControllers(scope);
322
+ }
302
323
  }
303
- function destroyNestedBranches(branch) {
304
- branch["#Destroyed" /* Destroyed */] = 1;
305
- branch["#BranchScopes" /* BranchScopes */]?.forEach(destroyNestedBranches);
306
- branch["#AbortScopes" /* AbortScopes */]?.forEach(resetControllers);
324
+ function destroyNestedScopes(scope) {
325
+ scope["#Destroyed" /* Destroyed */] = 1;
326
+ scope["#BranchScopes" /* BranchScopes */]?.forEach(destroyNestedScopes);
327
+ scope["#AbortScopes" /* AbortScopes */]?.forEach(resetControllers);
307
328
  }
308
329
  function resetControllers(scope) {
309
330
  for (const id in scope["#AbortControllers" /* AbortControllers */]) {
@@ -498,11 +519,6 @@ function _closure(...closureSignals) {
498
519
  function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
499
520
  if (false) valueAccessor = decodeAccessor(valueAccessor);
500
521
  const closureSignal = ((scope) => {
501
- if (true) {
502
- if (!(valueAccessor in (getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */]))) {
503
- throwUninitialized(valueAccessor);
504
- }
505
- }
506
522
  scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
507
523
  fn(scope);
508
524
  subscribeToScopeSet(
@@ -587,16 +603,6 @@ function _hoist(...path) {
587
603
  function _hoist_resume(id, ...path) {
588
604
  return _resume(id, _hoist(...path));
589
605
  }
590
- function throwUninitialized(name) {
591
- try {
592
- __UNINITIALIZED__;
593
- let __UNINITIALIZED__;
594
- } catch (err) {
595
- err.message = err.message.replaceAll("__UNINITIALIZED__", name);
596
- throw err;
597
- }
598
- throw new ReferenceError(`Cannot access '${name}' before initialization`);
599
- }
600
606
 
601
607
  // src/dom/walker.ts
602
608
  var walker = /* @__PURE__ */ document.createTreeWalker(document);
@@ -773,22 +779,49 @@ function createCloneableHTML(html, ns) {
773
779
 
774
780
  // src/dom/resume.ts
775
781
  var registeredValues = {};
782
+ var curRuntimeId;
783
+ var readyLookup;
776
784
  var branchesEnabled;
785
+ var embedEnabled;
777
786
  function enableBranches() {
778
787
  branchesEnabled = 1;
779
788
  }
789
+ var ready = /* @__PURE__ */ ((_) => (id) => {
790
+ readyLookup[id]?.();
791
+ readyLookup[id] = 1;
792
+ })(readyLookup = {});
793
+ function initEmbedded(readyId, runtimeId) {
794
+ embedEnabled = 1;
795
+ ready(readyId);
796
+ init(runtimeId);
797
+ new MutationObserver(() => {
798
+ const renders = self[curRuntimeId];
799
+ for (const renderId in renders) {
800
+ const { s, n } = renders[renderId];
801
+ if (n && !n.isConnected) {
802
+ delete renders[renderId];
803
+ for (const id in s) {
804
+ destroyScope(s[id]);
805
+ }
806
+ }
807
+ }
808
+ }).observe(document.body, { childList: true, subtree: true });
809
+ }
780
810
  function init(runtimeId = DEFAULT_RUNTIME_ID) {
781
- if (true) {
782
- const descriptor = Object.getOwnPropertyDescriptor(self, runtimeId);
783
- if (descriptor && (descriptor.set || descriptor.configurable === false)) {
784
- throw new Error(
785
- `Marko initialized multiple times with the same $global.runtimeId of ${JSON.stringify(runtimeId)}. It could be that there are multiple copies of Marko running on the page.`
786
- );
811
+ if (curRuntimeId) {
812
+ if (true) {
813
+ if (curRuntimeId !== runtimeId) {
814
+ throw new Error(
815
+ `Marko initialized multiple times with different $global.runtimeId's of ${JSON.stringify(runtimeId)} and ${JSON.stringify(curRuntimeId)}.`
816
+ );
817
+ }
787
818
  }
819
+ return;
788
820
  }
821
+ curRuntimeId = runtimeId;
822
+ let resumeRender;
789
823
  const renders = self[runtimeId];
790
824
  const defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc);
791
- let resumeRender;
792
825
  const initRuntime = (renders2) => {
793
826
  defineRuntime({
794
827
  value: resumeRender = ((renderId) => {
@@ -862,6 +895,10 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
862
895
  }
863
896
  };
864
897
  })();
898
+ const nextToken = () => lastToken = visitText.slice(
899
+ lastTokenIndex,
900
+ (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1
901
+ );
865
902
  let $global;
866
903
  let lastEffect;
867
904
  let visits;
@@ -873,11 +910,26 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
873
910
  let lastToken;
874
911
  let lastTokenIndex;
875
912
  let lastScopeId = 0;
876
- const nextToken = () => lastToken = visitText.slice(
877
- lastTokenIndex,
878
- (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1
879
- );
913
+ if (true) {
914
+ if (render.m) {
915
+ throw new Error(
916
+ `Marko rendered multiple times with $global.runtimeId as ${JSON.stringify(runtimeId)} and $global.renderId as ${JSON.stringify(renderId)}. Ensure each render into a page has a unique $global.renderId.`
917
+ );
918
+ }
919
+ }
880
920
  render.m = (effects = []) => {
921
+ if (readyLookup) {
922
+ for (const readyId in render.b) {
923
+ if (readyLookup[readyId] !== 1) {
924
+ readyLookup[readyId] = /* @__PURE__ */ ((prev) => () => {
925
+ render.m();
926
+ prev?.();
927
+ })(readyLookup[readyId]);
928
+ return effects;
929
+ }
930
+ }
931
+ render.b = 0;
932
+ }
881
933
  for (const serialized of resumes = render.r || []) {
882
934
  if (typeof serialized === "string") {
883
935
  lastTokenIndex = 0;
@@ -924,6 +976,12 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
924
976
  visitBranches();
925
977
  }
926
978
  }
979
+ if (embedEnabled) {
980
+ render.n ||= visit?.parentNode.insertBefore(
981
+ new Text(),
982
+ visit.nextSibling
983
+ );
984
+ }
927
985
  visits.length = resumes.length = 0;
928
986
  return effects;
929
987
  };
@@ -2534,6 +2592,7 @@ export {
2534
2592
  $signal,
2535
2593
  $signalReset,
2536
2594
  _assert_hoist,
2595
+ _assert_init,
2537
2596
  _attr,
2538
2597
  _attr_class,
2539
2598
  _attr_class_item,
@@ -2619,5 +2678,6 @@ export {
2619
2678
  forTo,
2620
2679
  forUntil,
2621
2680
  init,
2681
+ initEmbedded,
2622
2682
  run
2623
2683
  };
@@ -2476,6 +2476,7 @@ var State2 = class {
2476
2476
  writeReorders = null;
2477
2477
  scopes = /* @__PURE__ */ new Map();
2478
2478
  writeScopes = null;
2479
+ ensureReady = null;
2479
2480
  serializeReason;
2480
2481
  get runtimePrefix() {
2481
2482
  const { $global: $global2 } = this;
@@ -2665,6 +2666,26 @@ var Chunk = class {
2665
2666
  WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
2666
2667
  );
2667
2668
  }
2669
+ if (state.ensureReady && state.hasMainRuntime) {
2670
+ let first = true;
2671
+ for (const id in state.ensureReady) {
2672
+ if (state.ensureReady[id]) {
2673
+ state.ensureReady[id] = 0;
2674
+ if (first) {
2675
+ scripts = concatScripts(
2676
+ scripts,
2677
+ "(" + runtimePrefix + ".b={})" + toAccess(toObjectKey(id)) + "=1"
2678
+ );
2679
+ } else {
2680
+ scripts = concatScripts(
2681
+ scripts,
2682
+ runtimePrefix + ".b" /* Blocking */ + toAccess(toObjectKey(id)) + "=1"
2683
+ );
2684
+ }
2685
+ }
2686
+ first = false;
2687
+ }
2688
+ }
2668
2689
  if (effects) {
2669
2690
  needsWalk = true;
2670
2691
  state.resumes = state.resumes ? state.resumes + ',"' + effects + '"' : '"' + effects + '"';
@@ -3454,8 +3475,9 @@ function NOOP2() {
3454
3475
  }
3455
3476
 
3456
3477
  // src/html/template.ts
3457
- var _template = (templateId, renderer) => {
3478
+ var _template = (templateId, renderer, page) => {
3458
3479
  renderer.render = render;
3480
+ renderer.___embed = !page;
3459
3481
  renderer._ = renderer;
3460
3482
  if (true) {
3461
3483
  renderer.mount = () => {
@@ -3472,7 +3494,7 @@ function render(input = {}) {
3472
3494
  ({ $global: $global2, ...input } = input);
3473
3495
  $global2 = {
3474
3496
  runtimeId: DEFAULT_RUNTIME_ID,
3475
- renderId: DEFAULT_RENDER_ID,
3497
+ renderId: getDefaultRenderId(this),
3476
3498
  ...$global2
3477
3499
  };
3478
3500
  if (true) {
@@ -3488,16 +3510,31 @@ function render(input = {}) {
3488
3510
  }
3489
3511
  }
3490
3512
  } else {
3491
- $global2 = { runtimeId: DEFAULT_RUNTIME_ID, renderId: DEFAULT_RENDER_ID };
3513
+ $global2 = {
3514
+ runtimeId: DEFAULT_RUNTIME_ID,
3515
+ renderId: getDefaultRenderId(this)
3516
+ };
3517
+ }
3518
+ const state = new State2($global2);
3519
+ const head = new Chunk(new Boundary(state, $global2.signal), null, null);
3520
+ if (this.___embed) {
3521
+ (state.ensureReady ||= {})[this.___id] = 1;
3492
3522
  }
3493
- const head = new Chunk(
3494
- new Boundary(new State2($global2), $global2.signal),
3495
- null,
3496
- null
3497
- );
3498
3523
  head.render(this, input);
3499
3524
  return new ServerRendered(head);
3500
3525
  }
3526
+ function getDefaultRenderId(template) {
3527
+ if (template.___embed) {
3528
+ const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
3529
+ let n = Math.random() * 4294967296 >>> 0;
3530
+ let r = ENCODE_CHARS[n % 53];
3531
+ for (n = n / 53 | 0; n; n >>>= 6) {
3532
+ r += ENCODE_CHARS[n & 63];
3533
+ }
3534
+ return r;
3535
+ }
3536
+ return DEFAULT_RENDER_ID;
3537
+ }
3501
3538
  var ServerRendered = class {
3502
3539
  #head;
3503
3540
  #cachedPromise = null;
@@ -2383,6 +2383,7 @@ var State2 = class {
2383
2383
  writeReorders = null;
2384
2384
  scopes = /* @__PURE__ */ new Map();
2385
2385
  writeScopes = null;
2386
+ ensureReady = null;
2386
2387
  serializeReason;
2387
2388
  get runtimePrefix() {
2388
2389
  const { $global: $global2 } = this;
@@ -2572,6 +2573,26 @@ var Chunk = class {
2572
2573
  WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
2573
2574
  );
2574
2575
  }
2576
+ if (state.ensureReady && state.hasMainRuntime) {
2577
+ let first = true;
2578
+ for (const id in state.ensureReady) {
2579
+ if (state.ensureReady[id]) {
2580
+ state.ensureReady[id] = 0;
2581
+ if (first) {
2582
+ scripts = concatScripts(
2583
+ scripts,
2584
+ "(" + runtimePrefix + ".b={})" + toAccess(toObjectKey(id)) + "=1"
2585
+ );
2586
+ } else {
2587
+ scripts = concatScripts(
2588
+ scripts,
2589
+ runtimePrefix + ".b" /* Blocking */ + toAccess(toObjectKey(id)) + "=1"
2590
+ );
2591
+ }
2592
+ }
2593
+ first = false;
2594
+ }
2595
+ }
2575
2596
  if (effects) {
2576
2597
  needsWalk = true;
2577
2598
  state.resumes = state.resumes ? state.resumes + ',"' + effects + '"' : '"' + effects + '"';
@@ -3361,8 +3382,9 @@ function NOOP2() {
3361
3382
  }
3362
3383
 
3363
3384
  // src/html/template.ts
3364
- var _template = (templateId, renderer) => {
3385
+ var _template = (templateId, renderer, page) => {
3365
3386
  renderer.render = render;
3387
+ renderer.___embed = !page;
3366
3388
  renderer._ = renderer;
3367
3389
  if (true) {
3368
3390
  renderer.mount = () => {
@@ -3379,7 +3401,7 @@ function render(input = {}) {
3379
3401
  ({ $global: $global2, ...input } = input);
3380
3402
  $global2 = {
3381
3403
  runtimeId: DEFAULT_RUNTIME_ID,
3382
- renderId: DEFAULT_RENDER_ID,
3404
+ renderId: getDefaultRenderId(this),
3383
3405
  ...$global2
3384
3406
  };
3385
3407
  if (true) {
@@ -3395,16 +3417,31 @@ function render(input = {}) {
3395
3417
  }
3396
3418
  }
3397
3419
  } else {
3398
- $global2 = { runtimeId: DEFAULT_RUNTIME_ID, renderId: DEFAULT_RENDER_ID };
3420
+ $global2 = {
3421
+ runtimeId: DEFAULT_RUNTIME_ID,
3422
+ renderId: getDefaultRenderId(this)
3423
+ };
3424
+ }
3425
+ const state = new State2($global2);
3426
+ const head = new Chunk(new Boundary(state, $global2.signal), null, null);
3427
+ if (this.___embed) {
3428
+ (state.ensureReady ||= {})[this.___id] = 1;
3399
3429
  }
3400
- const head = new Chunk(
3401
- new Boundary(new State2($global2), $global2.signal),
3402
- null,
3403
- null
3404
- );
3405
3430
  head.render(this, input);
3406
3431
  return new ServerRendered(head);
3407
3432
  }
3433
+ function getDefaultRenderId(template) {
3434
+ if (template.___embed) {
3435
+ const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
3436
+ let n = Math.random() * 4294967296 >>> 0;
3437
+ let r = ENCODE_CHARS[n % 53];
3438
+ for (n = n / 53 | 0; n; n >>>= 6) {
3439
+ r += ENCODE_CHARS[n & 63];
3440
+ }
3441
+ return r;
3442
+ }
3443
+ return DEFAULT_RENDER_ID;
3444
+ }
3408
3445
  var ServerRendered = class {
3409
3446
  #head;
3410
3447
  #cachedPromise = null;
@@ -12,7 +12,9 @@ export interface RenderData {
12
12
  r?: (string | ResumeFn)[];
13
13
  s?: Record<string, Scope>;
14
14
  w(): void;
15
- m(): unknown[];
15
+ m?(): unknown[];
16
+ n?: Text;
17
+ b?: 0 | Record<string, 1 | 0>;
16
18
  d: never;
17
19
  l: never;
18
20
  x: never;
@@ -20,6 +22,8 @@ export interface RenderData {
20
22
  p?: Record<string | number, AwaitCounter>;
21
23
  }
22
24
  export declare function enableBranches(): void;
25
+ export declare const ready: (id: string) => void;
26
+ export declare function initEmbedded(readyId: string, runtimeId?: string): void;
23
27
  export declare function init(runtimeId?: string): void;
24
28
  export declare let isResuming: undefined | 0 | 1;
25
29
  export declare function getRegisteredWithScope(id: string, scope?: Scope): unknown;
@@ -3,6 +3,7 @@ export declare function createScope($global: Scope[AccessorProp.Global], closest
3
3
  export declare function skipScope(): number;
4
4
  export declare function findBranchWithKey(scope: Scope, key: string): BranchScope | undefined;
5
5
  export declare function destroyBranch(branch: BranchScope): void;
6
+ export declare function destroyScope(scope: Scope): void;
6
7
  export declare function removeAndDestroyBranch(branch: BranchScope): void;
7
8
  export declare function insertBranchBefore(branch: BranchScope, parentNode: ParentNode, nextSibling: Node | null): void;
8
9
  export declare function tempDetachBranch(branch: BranchScope): void;
package/dist/dom.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { attrTag, attrTags } from "./common/attr-tag";
2
- export { _assert_hoist } from "./common/errors";
2
+ export { _assert_hoist, _assert_init } from "./common/errors";
3
3
  export { forIn, forOf, forTo, forUntil } from "./common/for";
4
4
  export { _call } from "./common/helpers";
5
5
  export { $signal, $signalReset } from "./dom/abort-signal";
@@ -10,6 +10,6 @@ export { _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content,
10
10
  export { _on } from "./dom/event";
11
11
  export { _enable_catch as _enable_catch, run } from "./dom/queue";
12
12
  export { _content, _content_closures, _content_resume } from "./dom/renderer";
13
- export { _el, _resume, _var_resume, init } from "./dom/resume";
13
+ export { _el, _resume, _var_resume, init, initEmbedded } from "./dom/resume";
14
14
  export { _child_setup, _closure, _closure_get, _const, _el_read, _for_closure, _hoist, _hoist_resume, _id, _if_closure, _let, _or, _return, _return_change, _script, _var, _var_change, } from "./dom/signals";
15
15
  export { _template } from "./dom/template";