runling 0.1.1

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.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -0
  3. package/bin/runling.js +26 -0
  4. package/bin/workflow-loader.js +10 -0
  5. package/dist/extensions/web-fetch.d.ts +8 -0
  6. package/dist/extensions/web-fetch.js +245 -0
  7. package/dist/src/agent.d.ts +78 -0
  8. package/dist/src/agent.js +450 -0
  9. package/dist/src/ansi.d.ts +1 -0
  10. package/dist/src/ansi.js +9 -0
  11. package/dist/src/cli.d.ts +8 -0
  12. package/dist/src/cli.js +46 -0
  13. package/dist/src/config-reloader.d.ts +20 -0
  14. package/dist/src/config-reloader.js +110 -0
  15. package/dist/src/events.d.ts +82 -0
  16. package/dist/src/events.js +21 -0
  17. package/dist/src/git.d.ts +9 -0
  18. package/dist/src/git.js +82 -0
  19. package/dist/src/id.d.ts +1 -0
  20. package/dist/src/id.js +7 -0
  21. package/dist/src/index.d.ts +15 -0
  22. package/dist/src/index.js +14 -0
  23. package/dist/src/input.d.ts +14 -0
  24. package/dist/src/input.js +49 -0
  25. package/dist/src/log.d.ts +35 -0
  26. package/dist/src/log.js +92 -0
  27. package/dist/src/markdown.d.ts +2 -0
  28. package/dist/src/markdown.js +32 -0
  29. package/dist/src/model.d.ts +5 -0
  30. package/dist/src/model.js +10 -0
  31. package/dist/src/paths.d.ts +10 -0
  32. package/dist/src/paths.js +18 -0
  33. package/dist/src/runner.d.ts +43 -0
  34. package/dist/src/runner.js +200 -0
  35. package/dist/src/runtime.d.ts +62 -0
  36. package/dist/src/runtime.js +44 -0
  37. package/dist/src/schema.d.ts +3 -0
  38. package/dist/src/schema.js +17 -0
  39. package/dist/src/shell.d.ts +47 -0
  40. package/dist/src/shell.js +170 -0
  41. package/dist/src/step.d.ts +5 -0
  42. package/dist/src/step.js +39 -0
  43. package/dist/src/system-prompt.d.ts +2 -0
  44. package/dist/src/system-prompt.js +23 -0
  45. package/dist/src/text.d.ts +2 -0
  46. package/dist/src/text.js +6 -0
  47. package/dist/src/tui.d.ts +46 -0
  48. package/dist/src/tui.js +477 -0
  49. package/dist/src/usage.d.ts +35 -0
  50. package/dist/src/usage.js +90 -0
  51. package/dist/src/utils.d.ts +2 -0
  52. package/dist/src/utils.js +16 -0
  53. package/dist/src/web-config.d.ts +16 -0
  54. package/dist/src/web-config.js +22 -0
  55. package/dist/src/web-server.d.ts +8 -0
  56. package/dist/src/web-server.js +91 -0
  57. package/dist/src/workflow.d.ts +11 -0
  58. package/dist/src/workflow.js +39 -0
  59. package/dist/web/client/_app/immutable/assets/0.DkxYLsNr.css +1 -0
  60. package/dist/web/client/_app/immutable/assets/0.DkxYLsNr.css.br +0 -0
  61. package/dist/web/client/_app/immutable/assets/0.DkxYLsNr.css.gz +0 -0
  62. package/dist/web/client/_app/immutable/assets/2.D0D6RatL.css +1 -0
  63. package/dist/web/client/_app/immutable/assets/2.D0D6RatL.css.br +0 -0
  64. package/dist/web/client/_app/immutable/assets/2.D0D6RatL.css.gz +0 -0
  65. package/dist/web/client/_app/immutable/assets/plus-jakarta-sans-latin-ext-wght-italic.DJWiFoht.woff2 +0 -0
  66. package/dist/web/client/_app/immutable/assets/plus-jakarta-sans-latin-ext-wght-normal.DmpS2jIq.woff2 +0 -0
  67. package/dist/web/client/_app/immutable/assets/plus-jakarta-sans-latin-wght-italic.DnD1KgkH.woff2 +0 -0
  68. package/dist/web/client/_app/immutable/assets/plus-jakarta-sans-latin-wght-normal.eXO_dkmS.woff2 +0 -0
  69. package/dist/web/client/_app/immutable/assets/plus-jakarta-sans-vietnamese-wght-italic.CPBsCcxN.woff2 +0 -0
  70. package/dist/web/client/_app/immutable/assets/plus-jakarta-sans-vietnamese-wght-normal.qRpaaN48.woff2 +0 -0
  71. package/dist/web/client/_app/immutable/chunks/DVu8M-Ny.js +1 -0
  72. package/dist/web/client/_app/immutable/chunks/DVu8M-Ny.js.br +0 -0
  73. package/dist/web/client/_app/immutable/chunks/DVu8M-Ny.js.gz +0 -0
  74. package/dist/web/client/_app/immutable/chunks/DZ8VO57n.js +2 -0
  75. package/dist/web/client/_app/immutable/chunks/DZ8VO57n.js.br +0 -0
  76. package/dist/web/client/_app/immutable/chunks/DZ8VO57n.js.gz +0 -0
  77. package/dist/web/client/_app/immutable/chunks/DcSF4jBT.js +2 -0
  78. package/dist/web/client/_app/immutable/chunks/DcSF4jBT.js.br +0 -0
  79. package/dist/web/client/_app/immutable/chunks/DcSF4jBT.js.gz +0 -0
  80. package/dist/web/client/_app/immutable/chunks/DhqrxzQW.js +1 -0
  81. package/dist/web/client/_app/immutable/chunks/DhqrxzQW.js.br +0 -0
  82. package/dist/web/client/_app/immutable/chunks/DhqrxzQW.js.gz +0 -0
  83. package/dist/web/client/_app/immutable/chunks/DqKc9n9r.js +1 -0
  84. package/dist/web/client/_app/immutable/chunks/DqKc9n9r.js.br +0 -0
  85. package/dist/web/client/_app/immutable/chunks/DqKc9n9r.js.gz +0 -0
  86. package/dist/web/client/_app/immutable/chunks/EYhLy6Dm.js +1 -0
  87. package/dist/web/client/_app/immutable/chunks/EYhLy6Dm.js.br +0 -0
  88. package/dist/web/client/_app/immutable/chunks/EYhLy6Dm.js.gz +0 -0
  89. package/dist/web/client/_app/immutable/chunks/Jt-Bo-2J.js +1 -0
  90. package/dist/web/client/_app/immutable/chunks/Jt-Bo-2J.js.br +0 -0
  91. package/dist/web/client/_app/immutable/chunks/Jt-Bo-2J.js.gz +0 -0
  92. package/dist/web/client/_app/immutable/chunks/N_quh2N-.js +1 -0
  93. package/dist/web/client/_app/immutable/chunks/N_quh2N-.js.br +0 -0
  94. package/dist/web/client/_app/immutable/chunks/N_quh2N-.js.gz +0 -0
  95. package/dist/web/client/_app/immutable/chunks/wbPk3Yxo.js +81 -0
  96. package/dist/web/client/_app/immutable/chunks/wbPk3Yxo.js.br +0 -0
  97. package/dist/web/client/_app/immutable/chunks/wbPk3Yxo.js.gz +0 -0
  98. package/dist/web/client/_app/immutable/entry/app.YNAAR_x0.js +2 -0
  99. package/dist/web/client/_app/immutable/entry/app.YNAAR_x0.js.br +0 -0
  100. package/dist/web/client/_app/immutable/entry/app.YNAAR_x0.js.gz +0 -0
  101. package/dist/web/client/_app/immutable/entry/start.BQmDILhe.js +1 -0
  102. package/dist/web/client/_app/immutable/entry/start.BQmDILhe.js.br +0 -0
  103. package/dist/web/client/_app/immutable/entry/start.BQmDILhe.js.gz +0 -0
  104. package/dist/web/client/_app/immutable/nodes/0.DNWnBVC3.js +1 -0
  105. package/dist/web/client/_app/immutable/nodes/0.DNWnBVC3.js.br +0 -0
  106. package/dist/web/client/_app/immutable/nodes/0.DNWnBVC3.js.gz +0 -0
  107. package/dist/web/client/_app/immutable/nodes/1.CZEgzXeT.js +1 -0
  108. package/dist/web/client/_app/immutable/nodes/1.CZEgzXeT.js.br +0 -0
  109. package/dist/web/client/_app/immutable/nodes/1.CZEgzXeT.js.gz +0 -0
  110. package/dist/web/client/_app/immutable/nodes/2.BSE8F3Ef.js +19 -0
  111. package/dist/web/client/_app/immutable/nodes/2.BSE8F3Ef.js.br +0 -0
  112. package/dist/web/client/_app/immutable/nodes/2.BSE8F3Ef.js.gz +0 -0
  113. package/dist/web/client/_app/version.json +1 -0
  114. package/dist/web/client/_app/version.json.br +0 -0
  115. package/dist/web/client/_app/version.json.gz +0 -0
  116. package/dist/web/env.js +70 -0
  117. package/dist/web/env.js.map +1 -0
  118. package/dist/web/handler.js +23 -0
  119. package/dist/web/handler.js.map +1 -0
  120. package/dist/web/index.js +146 -0
  121. package/dist/web/index.js.map +1 -0
  122. package/dist/web/server/chunks/chunks/exports.js-BZBK1HC9.js +161 -0
  123. package/dist/web/server/chunks/chunks/exports.js-BZBK1HC9.js.map +1 -0
  124. package/dist/web/server/chunks/chunks/internal.js-pcXelyRW.js +126 -0
  125. package/dist/web/server/chunks/chunks/internal.js-pcXelyRW.js.map +1 -0
  126. package/dist/web/server/chunks/chunks/root.js-HNgH7zyW.js +4349 -0
  127. package/dist/web/server/chunks/chunks/root.js-HNgH7zyW.js.map +1 -0
  128. package/dist/web/server/chunks/chunks/run-store.js-Dgbf5-M9.js +174 -0
  129. package/dist/web/server/chunks/chunks/run-store.js-Dgbf5-M9.js.map +1 -0
  130. package/dist/web/server/chunks/chunks/runs.js-vPPJr_ta.js +20 -0
  131. package/dist/web/server/chunks/chunks/runs.js-vPPJr_ta.js.map +1 -0
  132. package/dist/web/server/chunks/chunks/server.js-Bf8x1V_n.js +16 -0
  133. package/dist/web/server/chunks/chunks/server.js-Bf8x1V_n.js.map +1 -0
  134. package/dist/web/server/chunks/chunks/state.svelte.js-lAA5-aPf.js +12 -0
  135. package/dist/web/server/chunks/chunks/state.svelte.js-lAA5-aPf.js.map +1 -0
  136. package/dist/web/server/chunks/chunks/stream.js-CHB18nO5.js +51 -0
  137. package/dist/web/server/chunks/chunks/stream.js-CHB18nO5.js.map +1 -0
  138. package/dist/web/server/chunks/chunks/uneval.js-5Y6J9rDU.js +530 -0
  139. package/dist/web/server/chunks/chunks/uneval.js-5Y6J9rDU.js.map +1 -0
  140. package/dist/web/server/chunks/chunks/utils.js-BQzn9ikS.js +38 -0
  141. package/dist/web/server/chunks/chunks/utils.js-BQzn9ikS.js.map +1 -0
  142. package/dist/web/server/chunks/chunks/utils2.js-CPBdgO4h.js +1627 -0
  143. package/dist/web/server/chunks/chunks/utils2.js-CPBdgO4h.js.map +1 -0
  144. package/dist/web/server/chunks/chunks/web-config.js-CAwLL_g4.js +12 -0
  145. package/dist/web/server/chunks/chunks/web-config.js-CAwLL_g4.js.map +1 -0
  146. package/dist/web/server/chunks/chunks/webhook.js-nEb5r1eG.js +62 -0
  147. package/dist/web/server/chunks/chunks/webhook.js-nEb5r1eG.js.map +1 -0
  148. package/dist/web/server/chunks/entries/endpoints/api/config/events/_server.ts.js-DwgI16MG.js +20 -0
  149. package/dist/web/server/chunks/entries/endpoints/api/config/events/_server.ts.js-DwgI16MG.js.map +1 -0
  150. package/dist/web/server/chunks/entries/endpoints/api/runs/_id_/_server.ts.js-BSKmJv3K.js +14 -0
  151. package/dist/web/server/chunks/entries/endpoints/api/runs/_id_/_server.ts.js-BSKmJv3K.js.map +1 -0
  152. package/dist/web/server/chunks/entries/endpoints/api/runs/_id_/events/_server.ts.js-CWWee51l.js +23 -0
  153. package/dist/web/server/chunks/entries/endpoints/api/runs/_id_/events/_server.ts.js-CWWee51l.js.map +1 -0
  154. package/dist/web/server/chunks/entries/endpoints/api/runs/events/_server.ts.js-CY2mz9bH.js +28 -0
  155. package/dist/web/server/chunks/entries/endpoints/api/runs/events/_server.ts.js-CY2mz9bH.js.map +1 -0
  156. package/dist/web/server/chunks/entries/endpoints/api/runs/start/_name_/_server.ts.js-CD4RKiK6.js +30 -0
  157. package/dist/web/server/chunks/entries/endpoints/api/runs/start/_name_/_server.ts.js-CD4RKiK6.js.map +1 -0
  158. package/dist/web/server/chunks/entries/endpoints/api/webhooks/_name_/_server.ts.js-Dgh42cDJ.js +28 -0
  159. package/dist/web/server/chunks/entries/endpoints/api/webhooks/_name_/_server.ts.js-Dgh42cDJ.js.map +1 -0
  160. package/dist/web/server/chunks/entries/fallbacks/error.svelte.js-LEaHcOM2.js +27 -0
  161. package/dist/web/server/chunks/entries/fallbacks/error.svelte.js-LEaHcOM2.js.map +1 -0
  162. package/dist/web/server/chunks/entries/pages/_layout.svelte.js-D_wzPsk8.js +8 -0
  163. package/dist/web/server/chunks/entries/pages/_layout.svelte.js-D_wzPsk8.js.map +1 -0
  164. package/dist/web/server/chunks/entries/pages/_page.server.ts.js-oVQ0hBaN.js +27 -0
  165. package/dist/web/server/chunks/entries/pages/_page.server.ts.js-oVQ0hBaN.js.map +1 -0
  166. package/dist/web/server/chunks/entries/pages/_page.svelte.js-B7fSvh9U.js +141 -0
  167. package/dist/web/server/chunks/entries/pages/_page.svelte.js-B7fSvh9U.js.map +1 -0
  168. package/dist/web/server/chunks/handler-BpKA6eGq.js +1734 -0
  169. package/dist/web/server/chunks/handler-BpKA6eGq.js.map +1 -0
  170. package/dist/web/server/chunks/index.js-CVS44OGr.js +4157 -0
  171. package/dist/web/server/chunks/index.js-CVS44OGr.js.map +1 -0
  172. package/dist/web/server/chunks/manifest.js-CnB5rB3W.js +84 -0
  173. package/dist/web/server/chunks/manifest.js-CnB5rB3W.js.map +1 -0
  174. package/dist/web/server/chunks/nodes/0.js-BqA14fLU.js +9 -0
  175. package/dist/web/server/chunks/nodes/0.js-BqA14fLU.js.map +1 -0
  176. package/dist/web/server/chunks/nodes/1.js-DzvhRJCS.js +9 -0
  177. package/dist/web/server/chunks/nodes/1.js-DzvhRJCS.js.map +1 -0
  178. package/dist/web/server/chunks/nodes/2.js-DmujW_AW.js +20 -0
  179. package/dist/web/server/chunks/nodes/2.js-DmujW_AW.js.map +1 -0
  180. package/dist/web/shims.js +33 -0
  181. package/dist/web/shims.js.map +1 -0
  182. package/package.json +69 -0
@@ -0,0 +1,4349 @@
1
+ import { u as uneval } from './uneval.js-5Y6J9rDU.js';
2
+
3
+ const DERIVED = 1 << 1;
4
+ const EFFECT = 1 << 2;
5
+ const RENDER_EFFECT = 1 << 3;
6
+ const MANAGED_EFFECT = 1 << 24;
7
+ const BLOCK_EFFECT = 1 << 4;
8
+ const BRANCH_EFFECT = 1 << 5;
9
+ const ROOT_EFFECT = 1 << 6;
10
+ const BOUNDARY_EFFECT = 1 << 7;
11
+ const PAUSED = 1 << 8;
12
+ const CONNECTED = 1 << 9;
13
+ const CLEAN = 1 << 10;
14
+ const DIRTY = 1 << 11;
15
+ const MAYBE_DIRTY = 1 << 12;
16
+ const INERT = 1 << 13;
17
+ const DESTROYED = 1 << 14;
18
+ const REACTION_RAN = 1 << 15;
19
+ const DESTROYING = 1 << 25;
20
+ const EFFECT_TRANSPARENT = 1 << 16;
21
+ const EAGER_EFFECT = 1 << 17;
22
+ const HEAD_EFFECT = 1 << 18;
23
+ const EFFECT_PRESERVED = 1 << 19;
24
+ const USER_EFFECT = 1 << 20;
25
+ const WAS_MARKED = 1 << 16;
26
+ const REACTION_IS_UPDATING = 1 << 21;
27
+ const ASYNC = 1 << 22;
28
+ const ERROR_VALUE = 1 << 23;
29
+ const STATE_SYMBOL = /* @__PURE__ */ Symbol("$state");
30
+ const COMPONENT_SYMBOL = /* @__PURE__ */ Symbol("component");
31
+ const LEGACY_PROPS = /* @__PURE__ */ Symbol("legacy props");
32
+ const ATTRIBUTES_CACHE = /* @__PURE__ */ Symbol("attributes");
33
+ const CLASS_CACHE = /* @__PURE__ */ Symbol("class");
34
+ const STYLE_CACHE = /* @__PURE__ */ Symbol("style");
35
+ const TEXT_CACHE = /* @__PURE__ */ Symbol("text");
36
+ const STALE_REACTION = new class StaleReactionError extends Error {
37
+ name = "StaleReactionError";
38
+ message = "The reaction that called `getAbortSignal()` was re-run or destroyed";
39
+ }();
40
+ const COMMENT_NODE = 8;
41
+ const DEV = false;
42
+ var is_array = Array.isArray;
43
+ var index_of = Array.prototype.indexOf;
44
+ var includes = Array.prototype.includes;
45
+ var array_from = Array.from;
46
+ var define_property = Object.defineProperty;
47
+ var get_descriptor = Object.getOwnPropertyDescriptor;
48
+ var object_prototype = Object.prototype;
49
+ var array_prototype = Array.prototype;
50
+ var get_prototype_of = Object.getPrototypeOf;
51
+ var is_extensible = Object.isExtensible;
52
+ var has_own_property = Object.prototype.hasOwnProperty;
53
+ const noop = () => {
54
+ };
55
+ function run_all(arr) {
56
+ for (var i = 0; i < arr.length; i++) {
57
+ arr[i]();
58
+ }
59
+ }
60
+ function deferred() {
61
+ var resolve;
62
+ var reject;
63
+ var promise = new Promise((res, rej) => {
64
+ resolve = res;
65
+ reject = rej;
66
+ });
67
+ return { promise, resolve, reject };
68
+ }
69
+ function equals(value) {
70
+ return value === this.v;
71
+ }
72
+ function safe_not_equal(a, b) {
73
+ return a != a ? b == b : a !== b || a !== null && typeof a === "object" || typeof a === "function";
74
+ }
75
+ function safe_equals(value) {
76
+ return !safe_not_equal(value, this.v);
77
+ }
78
+ function lifecycle_outside_component(name) {
79
+ {
80
+ throw new Error(`https://svelte.dev/e/lifecycle_outside_component`);
81
+ }
82
+ }
83
+ function effect_update_depth_exceeded() {
84
+ {
85
+ throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`);
86
+ }
87
+ }
88
+ function hydration_failed() {
89
+ {
90
+ throw new Error(`https://svelte.dev/e/hydration_failed`);
91
+ }
92
+ }
93
+ function state_descriptors_fixed() {
94
+ {
95
+ throw new Error(`https://svelte.dev/e/state_descriptors_fixed`);
96
+ }
97
+ }
98
+ function state_prototype_fixed() {
99
+ {
100
+ throw new Error(`https://svelte.dev/e/state_prototype_fixed`);
101
+ }
102
+ }
103
+ function state_unsafe_mutation() {
104
+ {
105
+ throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
106
+ }
107
+ }
108
+ function svelte_boundary_reset_onerror() {
109
+ {
110
+ throw new Error(`https://svelte.dev/e/svelte_boundary_reset_onerror`);
111
+ }
112
+ }
113
+ let tracing_mode_flag = false;
114
+ const HYDRATION_START = "[";
115
+ const HYDRATION_START_ELSE = "[!";
116
+ const HYDRATION_START_FAILED = "[?";
117
+ const HYDRATION_END = "]";
118
+ const HYDRATION_ERROR = {};
119
+ const ELEMENT_IS_NAMESPACED = 1;
120
+ const ELEMENT_PRESERVE_ATTRIBUTE_CASE = 1 << 1;
121
+ const ELEMENT_IS_INPUT = 1 << 2;
122
+ const UNINITIALIZED = /* @__PURE__ */ Symbol("uninitialized");
123
+ function get_parent_context(context) {
124
+ let parent = context.p;
125
+ while (parent !== null && parent.c === null) {
126
+ parent = parent.p;
127
+ }
128
+ return parent?.c ?? null;
129
+ }
130
+ function get_or_init_context_map(context, name) {
131
+ if (context === null) {
132
+ lifecycle_outside_component();
133
+ }
134
+ return context.c ??= new Map(get_parent_context(context) || void 0);
135
+ }
136
+ let component_context = null;
137
+ function set_component_context(context) {
138
+ component_context = context;
139
+ }
140
+ function push$1(props, runes = false, fn) {
141
+ component_context = {
142
+ p: component_context,
143
+ i: false,
144
+ c: null,
145
+ e: null,
146
+ s: props,
147
+ x: null,
148
+ r: (
149
+ /** @type {Effect} */
150
+ active_effect
151
+ ),
152
+ l: null
153
+ };
154
+ }
155
+ function pop$1(component) {
156
+ var context = (
157
+ /** @type {ComponentContext} */
158
+ component_context
159
+ );
160
+ var effects = context.e;
161
+ if (effects !== null) {
162
+ context.e = null;
163
+ for (var fn of effects) {
164
+ create_user_effect(fn);
165
+ }
166
+ }
167
+ context.i = true;
168
+ component_context = context.p;
169
+ return mark_as_component(component);
170
+ }
171
+ function mark_as_component(component = {}) {
172
+ define_property(component, COMPONENT_SYMBOL, { value: true });
173
+ return component;
174
+ }
175
+ function is_runes() {
176
+ return true;
177
+ }
178
+ let micro_tasks = [];
179
+ function run_micro_tasks() {
180
+ var tasks = micro_tasks;
181
+ micro_tasks = [];
182
+ run_all(tasks);
183
+ }
184
+ function queue_micro_task(fn) {
185
+ if (micro_tasks.length === 0 && !is_flushing_sync) {
186
+ var tasks = micro_tasks;
187
+ queueMicrotask(() => {
188
+ if (tasks === micro_tasks) run_micro_tasks();
189
+ });
190
+ }
191
+ micro_tasks.push(fn);
192
+ }
193
+ function flush_tasks() {
194
+ while (micro_tasks.length > 0) {
195
+ run_micro_tasks();
196
+ }
197
+ }
198
+ function derived_inert() {
199
+ {
200
+ console.warn(`https://svelte.dev/e/derived_inert`);
201
+ }
202
+ }
203
+ function hydration_mismatch(location) {
204
+ {
205
+ console.warn(`https://svelte.dev/e/hydration_mismatch`);
206
+ }
207
+ }
208
+ function svelte_boundary_reset_noop() {
209
+ {
210
+ console.warn(`https://svelte.dev/e/svelte_boundary_reset_noop`);
211
+ }
212
+ }
213
+ let hydrating = false;
214
+ function set_hydrating(value) {
215
+ hydrating = value;
216
+ }
217
+ let hydrate_node;
218
+ function set_hydrate_node(node) {
219
+ if (node === null) {
220
+ hydration_mismatch();
221
+ throw HYDRATION_ERROR;
222
+ }
223
+ return hydrate_node = node;
224
+ }
225
+ function hydrate_next() {
226
+ return set_hydrate_node(/* @__PURE__ */ get_next_sibling(hydrate_node));
227
+ }
228
+ function next(count = 1) {
229
+ if (hydrating) {
230
+ var i = count;
231
+ var node = hydrate_node;
232
+ while (i--) {
233
+ node = /** @type {TemplateNode} */
234
+ /* @__PURE__ */ get_next_sibling(node);
235
+ }
236
+ hydrate_node = node;
237
+ }
238
+ }
239
+ function skip_nodes(remove = true) {
240
+ var depth = 0;
241
+ var node = hydrate_node;
242
+ while (true) {
243
+ if (node.nodeType === COMMENT_NODE) {
244
+ var data = (
245
+ /** @type {Comment} */
246
+ node.data
247
+ );
248
+ if (data === HYDRATION_END) {
249
+ if (depth === 0) return node;
250
+ depth -= 1;
251
+ } else if (data === HYDRATION_START || data === HYDRATION_START_ELSE || // "[1", "[2", etc. for if blocks
252
+ data[0] === "[" && !isNaN(Number(data.slice(1)))) {
253
+ depth += 1;
254
+ }
255
+ }
256
+ var next2 = (
257
+ /** @type {TemplateNode} */
258
+ /* @__PURE__ */ get_next_sibling(node)
259
+ );
260
+ if (remove) node.remove();
261
+ node = next2;
262
+ }
263
+ }
264
+ function proxy(value) {
265
+ if (typeof value !== "object" || value === null || STATE_SYMBOL in value || COMPONENT_SYMBOL in value) {
266
+ return value;
267
+ }
268
+ const prototype = get_prototype_of(value);
269
+ if (prototype !== object_prototype && prototype !== array_prototype) {
270
+ return value;
271
+ }
272
+ var sources = /* @__PURE__ */ new Map();
273
+ var is_proxied_array = is_array(value);
274
+ var version = /* @__PURE__ */ state(0);
275
+ var parent_version = update_version;
276
+ var with_parent = (fn) => {
277
+ if (update_version === parent_version) {
278
+ return fn();
279
+ }
280
+ var reaction = active_reaction;
281
+ var version2 = update_version;
282
+ set_active_reaction(null);
283
+ set_update_version(parent_version);
284
+ var result = fn();
285
+ set_active_reaction(reaction);
286
+ set_update_version(version2);
287
+ return result;
288
+ };
289
+ if (is_proxied_array) {
290
+ sources.set("length", /* @__PURE__ */ state(
291
+ /** @type {any[]} */
292
+ value.length
293
+ ));
294
+ }
295
+ return new Proxy(
296
+ /** @type {any} */
297
+ value,
298
+ {
299
+ defineProperty(_, prop, descriptor) {
300
+ if (!("value" in descriptor) || descriptor.configurable === false || descriptor.enumerable === false || descriptor.writable === false) {
301
+ state_descriptors_fixed();
302
+ }
303
+ var s = sources.get(prop);
304
+ if (s === void 0) {
305
+ with_parent(() => {
306
+ var s2 = /* @__PURE__ */ state(descriptor.value);
307
+ sources.set(prop, s2);
308
+ return s2;
309
+ });
310
+ } else {
311
+ set(s, descriptor.value, true);
312
+ }
313
+ return true;
314
+ },
315
+ deleteProperty(target, prop) {
316
+ var s = sources.get(prop);
317
+ if (s === void 0) {
318
+ if (prop in target) {
319
+ const s2 = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
320
+ sources.set(prop, s2);
321
+ increment(version);
322
+ }
323
+ } else {
324
+ set(s, UNINITIALIZED);
325
+ increment(version);
326
+ }
327
+ return true;
328
+ },
329
+ get(target, prop, receiver) {
330
+ if (prop === STATE_SYMBOL) {
331
+ return value;
332
+ }
333
+ var s = sources.get(prop);
334
+ var exists = prop in target;
335
+ if (s === void 0 && (!exists || get_descriptor(target, prop)?.writable)) {
336
+ s = with_parent(() => {
337
+ var p = proxy(exists ? target[prop] : UNINITIALIZED);
338
+ var s2 = /* @__PURE__ */ state(p);
339
+ return s2;
340
+ });
341
+ sources.set(prop, s);
342
+ }
343
+ if (s !== void 0) {
344
+ var v = get(s);
345
+ return v === UNINITIALIZED ? void 0 : v;
346
+ }
347
+ return Reflect.get(target, prop, receiver);
348
+ },
349
+ getOwnPropertyDescriptor(target, prop) {
350
+ var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
351
+ if (descriptor && "value" in descriptor) {
352
+ var s = sources.get(prop);
353
+ if (s) descriptor.value = get(s);
354
+ } else if (descriptor === void 0) {
355
+ var source2 = sources.get(prop);
356
+ var value2 = source2?.v;
357
+ if (source2 !== void 0 && value2 !== UNINITIALIZED) {
358
+ return {
359
+ enumerable: true,
360
+ configurable: true,
361
+ value: value2,
362
+ writable: true
363
+ };
364
+ }
365
+ }
366
+ return descriptor;
367
+ },
368
+ has(target, prop) {
369
+ if (prop === STATE_SYMBOL) {
370
+ return true;
371
+ }
372
+ var s = sources.get(prop);
373
+ var has = s !== void 0 && s.v !== UNINITIALIZED || Reflect.has(target, prop);
374
+ if (s !== void 0 || active_effect !== null && (!has || get_descriptor(target, prop)?.writable)) {
375
+ if (s === void 0) {
376
+ s = with_parent(() => {
377
+ var p = has ? proxy(target[prop]) : UNINITIALIZED;
378
+ var s2 = /* @__PURE__ */ state(p);
379
+ return s2;
380
+ });
381
+ sources.set(prop, s);
382
+ }
383
+ var value2 = get(s);
384
+ if (value2 === UNINITIALIZED) {
385
+ return false;
386
+ }
387
+ }
388
+ return has;
389
+ },
390
+ set(target, prop, value2, receiver) {
391
+ var s = sources.get(prop);
392
+ var has = prop in target;
393
+ if (is_proxied_array && prop === "length") {
394
+ for (var i = value2; i < /** @type {Source<number>} */
395
+ s.v; i += 1) {
396
+ var other_s = sources.get(i + "");
397
+ if (other_s !== void 0) {
398
+ set(other_s, UNINITIALIZED);
399
+ } else if (i in target) {
400
+ other_s = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
401
+ sources.set(i + "", other_s);
402
+ }
403
+ }
404
+ }
405
+ if (s === void 0) {
406
+ if (!has || get_descriptor(target, prop)?.writable) {
407
+ s = with_parent(() => /* @__PURE__ */ state(void 0));
408
+ set(s, proxy(value2));
409
+ sources.set(prop, s);
410
+ }
411
+ } else {
412
+ has = s.v !== UNINITIALIZED;
413
+ var p = with_parent(() => proxy(value2));
414
+ set(s, p);
415
+ }
416
+ var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
417
+ if (descriptor?.set) {
418
+ descriptor.set.call(receiver, value2);
419
+ }
420
+ if (!has) {
421
+ if (is_proxied_array && typeof prop === "string") {
422
+ var ls = (
423
+ /** @type {Source<number>} */
424
+ sources.get("length")
425
+ );
426
+ var n = Number(prop);
427
+ if (Number.isInteger(n) && n >= ls.v) {
428
+ set(ls, n + 1);
429
+ }
430
+ }
431
+ increment(version);
432
+ }
433
+ return true;
434
+ },
435
+ ownKeys(target) {
436
+ get(version);
437
+ var own_keys = Reflect.ownKeys(target).filter((key2) => {
438
+ var source3 = sources.get(key2);
439
+ return source3 === void 0 || source3.v !== UNINITIALIZED;
440
+ });
441
+ for (var [key, source2] of sources) {
442
+ if (source2.v !== UNINITIALIZED && !(key in target)) {
443
+ own_keys.push(key);
444
+ }
445
+ }
446
+ return own_keys;
447
+ },
448
+ setPrototypeOf() {
449
+ state_prototype_fixed();
450
+ }
451
+ }
452
+ );
453
+ }
454
+ var $window;
455
+ var first_child_getter;
456
+ var next_sibling_getter;
457
+ function init_operations() {
458
+ if ($window !== void 0) {
459
+ return;
460
+ }
461
+ $window = window;
462
+ var element_prototype = Element.prototype;
463
+ var node_prototype = Node.prototype;
464
+ var text_prototype = Text.prototype;
465
+ first_child_getter = get_descriptor(node_prototype, "firstChild").get;
466
+ next_sibling_getter = get_descriptor(node_prototype, "nextSibling").get;
467
+ if (is_extensible(element_prototype)) {
468
+ element_prototype[CLASS_CACHE] = void 0;
469
+ element_prototype[ATTRIBUTES_CACHE] = null;
470
+ element_prototype[STYLE_CACHE] = void 0;
471
+ element_prototype.__e = void 0;
472
+ }
473
+ if (is_extensible(text_prototype)) {
474
+ text_prototype[TEXT_CACHE] = void 0;
475
+ }
476
+ }
477
+ function create_text(value = "") {
478
+ return document.createTextNode(value);
479
+ }
480
+ // @__NO_SIDE_EFFECTS__
481
+ function get_first_child(node) {
482
+ return (
483
+ /** @type {TemplateNode | null} */
484
+ first_child_getter.call(node)
485
+ );
486
+ }
487
+ // @__NO_SIDE_EFFECTS__
488
+ function get_next_sibling(node) {
489
+ return (
490
+ /** @type {TemplateNode | null} */
491
+ next_sibling_getter.call(node)
492
+ );
493
+ }
494
+ function clear_text_content(node) {
495
+ node.textContent = "";
496
+ }
497
+ function handle_error(error) {
498
+ var effect = active_effect;
499
+ if (effect === null) {
500
+ active_reaction.f |= ERROR_VALUE;
501
+ return error;
502
+ }
503
+ if ((effect.f & REACTION_RAN) === 0 && (effect.f & EFFECT) === 0) {
504
+ throw error;
505
+ }
506
+ invoke_error_boundary(error, effect);
507
+ }
508
+ function invoke_error_boundary(error, effect) {
509
+ if (effect !== null && (effect.f & DESTROYED) !== 0) {
510
+ return;
511
+ }
512
+ while (effect !== null) {
513
+ if ((effect.f & BOUNDARY_EFFECT) !== 0 && (effect.f & (DESTROYED | DESTROYING)) === 0) {
514
+ if ((effect.f & REACTION_RAN) === 0) {
515
+ throw error;
516
+ }
517
+ try {
518
+ effect.b.error(error);
519
+ return;
520
+ } catch (e) {
521
+ error = e;
522
+ }
523
+ }
524
+ effect = effect.parent;
525
+ }
526
+ throw error;
527
+ }
528
+ const STATUS_MASK = -7169;
529
+ function set_signal_status(signal, status) {
530
+ signal.f = signal.f & STATUS_MASK | status;
531
+ }
532
+ function update_derived_status(derived2) {
533
+ if ((derived2.f & CONNECTED) !== 0 || derived2.deps === null) {
534
+ set_signal_status(derived2, CLEAN);
535
+ } else {
536
+ set_signal_status(derived2, MAYBE_DIRTY);
537
+ }
538
+ }
539
+ function clear_marked(deps) {
540
+ if (deps === null) return;
541
+ for (const dep of deps) {
542
+ if ((dep.f & DERIVED) === 0 || (dep.f & WAS_MARKED) === 0) {
543
+ continue;
544
+ }
545
+ dep.f ^= WAS_MARKED;
546
+ clear_marked(
547
+ /** @type {Derived} */
548
+ dep.deps
549
+ );
550
+ }
551
+ }
552
+ function defer_effect(effect, dirty_effects, maybe_dirty_effects) {
553
+ if ((effect.f & DIRTY) !== 0) {
554
+ dirty_effects.add(effect);
555
+ } else if ((effect.f & MAYBE_DIRTY) !== 0) {
556
+ maybe_dirty_effects.add(effect);
557
+ }
558
+ clear_marked(effect.deps);
559
+ set_signal_status(effect, CLEAN);
560
+ }
561
+ function without_reactive_context(fn) {
562
+ var previous_reaction = active_reaction;
563
+ var previous_effect = active_effect;
564
+ set_active_reaction(null);
565
+ set_active_effect(null);
566
+ try {
567
+ return fn();
568
+ } finally {
569
+ set_active_reaction(previous_reaction);
570
+ set_active_effect(previous_effect);
571
+ }
572
+ }
573
+ const OBSOLETE = /* @__PURE__ */ Symbol("obsolete");
574
+ function destroy_derived_effects(derived2) {
575
+ var effects = derived2.effects;
576
+ if (effects !== null) {
577
+ derived2.effects = null;
578
+ for (var i = 0; i < effects.length; i += 1) {
579
+ destroy_effect(
580
+ /** @type {Effect} */
581
+ effects[i]
582
+ );
583
+ }
584
+ }
585
+ }
586
+ function execute_derived(derived2) {
587
+ var value;
588
+ var prev_active_effect = active_effect;
589
+ var parent = derived2.parent;
590
+ if (!is_destroying_effect && parent !== null && derived2.v !== UNINITIALIZED && // if it was never evaluated before, it's guaranteed to fail downstream, so we try to execute instead
591
+ (parent.f & (DESTROYED | INERT)) !== 0) {
592
+ derived_inert();
593
+ return derived2.v;
594
+ }
595
+ set_active_effect(parent);
596
+ {
597
+ try {
598
+ derived2.f &= ~WAS_MARKED;
599
+ destroy_derived_effects(derived2);
600
+ value = update_reaction(derived2);
601
+ } finally {
602
+ set_active_effect(prev_active_effect);
603
+ }
604
+ }
605
+ return value;
606
+ }
607
+ function update_derived(derived2) {
608
+ var value = execute_derived(derived2);
609
+ if (!derived2.equals(value)) {
610
+ derived2.wv = increment_write_version();
611
+ if (!current_batch?.is_fork || derived2.deps === null) {
612
+ if (current_batch !== null) {
613
+ current_batch.capture(derived2, value, true);
614
+ previous_batch?.capture(derived2, value, true);
615
+ } else {
616
+ derived2.v = value;
617
+ }
618
+ if (derived2.deps === null) {
619
+ set_signal_status(derived2, CLEAN);
620
+ return;
621
+ }
622
+ }
623
+ }
624
+ if (is_destroying_effect) {
625
+ return;
626
+ }
627
+ if (batch_values !== null) {
628
+ if (effect_tracking() || current_batch?.is_fork) {
629
+ batch_values.set(derived2, value);
630
+ }
631
+ } else {
632
+ update_derived_status(derived2);
633
+ }
634
+ }
635
+ function freeze_derived_effects(derived2) {
636
+ if (derived2.effects === null) return;
637
+ for (const e of derived2.effects) {
638
+ if (e.teardown || e.ac) {
639
+ e.teardown?.();
640
+ if (e.ac !== null) {
641
+ without_reactive_context(() => {
642
+ e.ac.abort(STALE_REACTION);
643
+ e.ac = null;
644
+ });
645
+ }
646
+ if (e.fn !== null) e.teardown = noop;
647
+ remove_reactions(e, 0);
648
+ destroy_effect_children(e);
649
+ }
650
+ }
651
+ }
652
+ function unfreeze_derived_effects(derived2) {
653
+ if (derived2.effects === null) return;
654
+ for (const e of derived2.effects) {
655
+ if (e.teardown && e.fn !== null) {
656
+ update_effect(e);
657
+ }
658
+ }
659
+ }
660
+ let first_batch = null;
661
+ let last_batch = null;
662
+ let current_batch = null;
663
+ let previous_batch = null;
664
+ let batch_values = null;
665
+ let last_scheduled_effect = null;
666
+ let is_flushing_sync = false;
667
+ let is_processing = false;
668
+ let collected_effects = null;
669
+ let legacy_updates = null;
670
+ var flush_count = 0;
671
+ let uid = 1;
672
+ class Batch {
673
+ id = uid++;
674
+ /** True as soon as `#process` was called */
675
+ #started = false;
676
+ linked = true;
677
+ /** @type {Batch | null} */
678
+ #prev = null;
679
+ /** @type {Batch | null} */
680
+ #next = null;
681
+ /** @type {Map<Effect, ReturnType<typeof deferred<any>>>} */
682
+ async_deriveds = /* @__PURE__ */ new Map();
683
+ /**
684
+ * The current values of any signals that are updated in this batch.
685
+ * Tuple format: [value, is_derived] (note: is_derived is false for deriveds, too, if they were overridden via assignment)
686
+ * They keys of this map are identical to `this.#previous`
687
+ * @type {Map<Value, [any, boolean]>}
688
+ */
689
+ current = /* @__PURE__ */ new Map();
690
+ /**
691
+ * The values of any signals (sources and deriveds) that are updated in this batch _before_ those updates took place.
692
+ * They keys of this map are identical to `this.#current`
693
+ * @type {Map<Value, any>}
694
+ */
695
+ previous = /* @__PURE__ */ new Map();
696
+ /**
697
+ * When the batch is committed (and the DOM is updated), we need to remove old branches
698
+ * and append new ones by calling the functions added inside (if/each/key/etc) blocks
699
+ * @type {Set<(batch: Batch) => void>}
700
+ */
701
+ #commit_callbacks = /* @__PURE__ */ new Set();
702
+ /**
703
+ * If a fork is discarded, we need to destroy any effects that are no longer needed
704
+ * @type {Set<(batch: Batch) => void>}
705
+ */
706
+ #discard_callbacks = /* @__PURE__ */ new Set();
707
+ /**
708
+ * The number of async effects that are currently in flight
709
+ */
710
+ #pending = 0;
711
+ /**
712
+ * Async effects that are currently in flight, _not_ inside a pending boundary
713
+ * @type {Map<Effect, number>}
714
+ */
715
+ #blocking_pending = /* @__PURE__ */ new Map();
716
+ /**
717
+ * A deferred that resolves when the batch is committed, used with `settled()`
718
+ * TODO replace with Promise.withResolvers once supported widely enough
719
+ * @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null}
720
+ */
721
+ #deferred = null;
722
+ /**
723
+ * The root effects that need to be flushed
724
+ * @type {Effect[]}
725
+ */
726
+ #roots = [];
727
+ /**
728
+ * Effects created while this batch was active.
729
+ * @type {Effect[]}
730
+ */
731
+ #new_effects = [];
732
+ /**
733
+ * Deferred effects (which run after async work has completed) that are DIRTY
734
+ * @type {Set<Effect>}
735
+ */
736
+ #dirty_effects = /* @__PURE__ */ new Set();
737
+ /**
738
+ * Deferred effects that are MAYBE_DIRTY
739
+ * @type {Set<Effect>}
740
+ */
741
+ #maybe_dirty_effects = /* @__PURE__ */ new Set();
742
+ /**
743
+ * A map of branches that still exist, but will be destroyed when this batch
744
+ * is committed — we skip over these during `process`.
745
+ * The value contains child effects that were dirty/maybe_dirty before being reset,
746
+ * so they can be rescheduled if the branch survives.
747
+ * @type {Map<Effect, { d: Effect[], m: Effect[] }>}
748
+ */
749
+ #skipped_branches = /* @__PURE__ */ new Map();
750
+ /**
751
+ * Inverse of #skipped_branches which we need to tell prior batches to unskip them when committing
752
+ * @type {Set<Effect>}
753
+ */
754
+ #unskipped_branches = /* @__PURE__ */ new Set();
755
+ is_fork = false;
756
+ #decrement_queued = false;
757
+ constructor() {
758
+ if (last_batch === null) {
759
+ first_batch = last_batch = this;
760
+ } else {
761
+ last_batch.#next = this;
762
+ this.#prev = last_batch;
763
+ }
764
+ last_batch = this;
765
+ }
766
+ #is_deferred() {
767
+ if (this.is_fork) return true;
768
+ for (const effect of this.#blocking_pending.keys()) {
769
+ var e = effect;
770
+ var skipped = false;
771
+ while (e.parent !== null) {
772
+ if (this.#skipped_branches.has(e)) {
773
+ skipped = true;
774
+ break;
775
+ }
776
+ e = e.parent;
777
+ }
778
+ if (!skipped) {
779
+ return true;
780
+ }
781
+ }
782
+ return false;
783
+ }
784
+ /**
785
+ * Add an effect to the #skipped_branches map and reset its children
786
+ * @param {Effect} effect
787
+ */
788
+ skip_effect(effect) {
789
+ if (!this.#skipped_branches.has(effect)) {
790
+ this.#skipped_branches.set(effect, { d: [], m: [] });
791
+ }
792
+ this.#unskipped_branches.delete(effect);
793
+ }
794
+ /**
795
+ * Remove an effect from the #skipped_branches map and reschedule
796
+ * any tracked dirty/maybe_dirty child effects
797
+ * @param {Effect} effect
798
+ * @param {(e: Effect) => void} callback
799
+ */
800
+ unskip_effect(effect, callback = (e) => this.schedule(e)) {
801
+ var tracked = this.#skipped_branches.get(effect);
802
+ if (tracked) {
803
+ this.#skipped_branches.delete(effect);
804
+ for (var e of tracked.d) {
805
+ set_signal_status(e, DIRTY);
806
+ callback(e);
807
+ }
808
+ for (e of tracked.m) {
809
+ set_signal_status(e, MAYBE_DIRTY);
810
+ callback(e);
811
+ }
812
+ }
813
+ this.#unskipped_branches.add(effect);
814
+ }
815
+ #process() {
816
+ this.#started = true;
817
+ if (flush_count++ > 1e3) {
818
+ this.#unlink();
819
+ infinite_loop_guard();
820
+ }
821
+ for (const e of this.#dirty_effects) {
822
+ this.#maybe_dirty_effects.delete(e);
823
+ set_signal_status(e, DIRTY);
824
+ this.schedule(e);
825
+ }
826
+ for (const e of this.#maybe_dirty_effects) {
827
+ set_signal_status(e, MAYBE_DIRTY);
828
+ this.schedule(e);
829
+ }
830
+ const roots = this.#roots;
831
+ this.#roots = [];
832
+ this.apply();
833
+ var effects = collected_effects = [];
834
+ var render_effects = [];
835
+ var updates = legacy_updates = [];
836
+ for (const root2 of roots) {
837
+ try {
838
+ this.#traverse(root2, effects, render_effects);
839
+ } catch (e) {
840
+ reset_all(root2);
841
+ if (!this.#is_deferred()) this.discard();
842
+ throw e;
843
+ }
844
+ }
845
+ current_batch = null;
846
+ if (updates.length > 0) {
847
+ var batch = Batch.ensure();
848
+ for (const e of updates) {
849
+ batch.schedule(e);
850
+ }
851
+ }
852
+ collected_effects = null;
853
+ legacy_updates = null;
854
+ if (this.#is_deferred()) {
855
+ this.#defer_effects(render_effects);
856
+ this.#defer_effects(effects);
857
+ for (const [e, t] of this.#skipped_branches) {
858
+ reset_branch(e, t);
859
+ }
860
+ if (updates.length > 0) {
861
+ /** @type {unknown} */
862
+ current_batch.#process();
863
+ }
864
+ return;
865
+ }
866
+ const earlier_batch = this.#find_earlier_batch();
867
+ if (earlier_batch) {
868
+ this.#defer_effects(render_effects);
869
+ this.#defer_effects(effects);
870
+ earlier_batch.#merge(this);
871
+ return;
872
+ }
873
+ this.#dirty_effects.clear();
874
+ this.#maybe_dirty_effects.clear();
875
+ for (const fn of this.#commit_callbacks) fn(this);
876
+ this.#commit_callbacks.clear();
877
+ previous_batch = this;
878
+ flush_queued_effects(render_effects);
879
+ flush_queued_effects(effects);
880
+ previous_batch = null;
881
+ this.#deferred?.resolve();
882
+ var next_batch = (
883
+ /** @type {Batch | null} */
884
+ /** @type {unknown} */
885
+ current_batch
886
+ );
887
+ if (this.#pending === 0 && (this.#roots.length === 0 || next_batch !== null)) {
888
+ this.#unlink();
889
+ }
890
+ if (this.#roots.length > 0) {
891
+ if (next_batch !== null) {
892
+ const batch2 = next_batch;
893
+ batch2.#roots.push(...this.#roots.filter((r2) => !batch2.#roots.includes(r2)));
894
+ } else {
895
+ next_batch = this;
896
+ }
897
+ }
898
+ if (next_batch !== null) {
899
+ old_values.clear();
900
+ next_batch.#process();
901
+ }
902
+ }
903
+ /**
904
+ * Traverse the effect tree, executing effects or stashing
905
+ * them for later execution as appropriate
906
+ * @param {Effect} root
907
+ * @param {Effect[]} effects
908
+ * @param {Effect[]} render_effects
909
+ */
910
+ #traverse(root2, effects, render_effects) {
911
+ root2.f ^= CLEAN;
912
+ var effect = root2.first;
913
+ while (effect !== null) {
914
+ var flags2 = effect.f;
915
+ var is_branch = (flags2 & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0;
916
+ var is_skippable_branch = is_branch && (flags2 & CLEAN) !== 0;
917
+ var skip = is_skippable_branch || (flags2 & INERT) !== 0 || this.#skipped_branches.has(effect);
918
+ if (!skip && effect.fn !== null) {
919
+ if (is_branch) {
920
+ effect.f ^= CLEAN;
921
+ } else if ((flags2 & EFFECT) !== 0) {
922
+ effects.push(effect);
923
+ } else if (is_dirty(effect)) {
924
+ if ((flags2 & BLOCK_EFFECT) !== 0) this.#maybe_dirty_effects.add(effect);
925
+ update_effect(effect);
926
+ }
927
+ var child = effect.first;
928
+ if (child !== null) {
929
+ effect = child;
930
+ continue;
931
+ }
932
+ }
933
+ while (effect !== null) {
934
+ var next2 = effect.next;
935
+ if (next2 !== null) {
936
+ effect = next2;
937
+ break;
938
+ }
939
+ effect = effect.parent;
940
+ }
941
+ }
942
+ }
943
+ #find_earlier_batch() {
944
+ var batch = this.#prev;
945
+ while (batch !== null) {
946
+ if (!batch.is_fork) {
947
+ for (const [value, [, is_derived]] of this.current) {
948
+ if (batch.current.has(value) && !is_derived) {
949
+ return batch;
950
+ }
951
+ }
952
+ }
953
+ batch = batch.#prev;
954
+ }
955
+ return null;
956
+ }
957
+ /**
958
+ * @param {Batch} batch
959
+ */
960
+ #merge(batch) {
961
+ for (const [source2, value] of batch.current) {
962
+ if (!this.previous.has(source2) && batch.previous.has(source2)) {
963
+ this.previous.set(source2, batch.previous.get(source2));
964
+ }
965
+ this.current.set(source2, value);
966
+ }
967
+ for (const [effect, deferred2] of batch.async_deriveds) {
968
+ const d = this.async_deriveds.get(effect);
969
+ if (d) deferred2.promise.then(d.resolve).catch(d.reject);
970
+ }
971
+ batch.async_deriveds.clear();
972
+ this.transfer_effects(batch.#dirty_effects, batch.#maybe_dirty_effects);
973
+ const mark = (value) => {
974
+ var reactions = value.reactions;
975
+ if (reactions === null) return;
976
+ if ((value.f & DERIVED) !== 0 && (value.f & (DIRTY | MAYBE_DIRTY)) === 0) {
977
+ return;
978
+ }
979
+ for (const reaction of reactions) {
980
+ var flags2 = reaction.f;
981
+ if ((flags2 & DERIVED) !== 0) {
982
+ mark(
983
+ /** @type {Derived} */
984
+ reaction
985
+ );
986
+ } else {
987
+ var effect = (
988
+ /** @type {Effect} */
989
+ reaction
990
+ );
991
+ if (flags2 & (ASYNC | BLOCK_EFFECT) && !this.async_deriveds.has(effect)) {
992
+ this.#maybe_dirty_effects.delete(effect);
993
+ set_signal_status(effect, DIRTY);
994
+ this.schedule(effect);
995
+ }
996
+ }
997
+ }
998
+ };
999
+ for (const source2 of this.current.keys()) {
1000
+ mark(source2);
1001
+ }
1002
+ this.oncommit(() => batch.discard());
1003
+ batch.#unlink();
1004
+ current_batch = this;
1005
+ this.#process();
1006
+ }
1007
+ /**
1008
+ * @param {Effect[]} effects
1009
+ */
1010
+ #defer_effects(effects) {
1011
+ for (var i = 0; i < effects.length; i += 1) {
1012
+ defer_effect(effects[i], this.#dirty_effects, this.#maybe_dirty_effects);
1013
+ }
1014
+ }
1015
+ /**
1016
+ * Associate a change to a given source with the current
1017
+ * batch, noting its previous and current values
1018
+ * @param {Value} source
1019
+ * @param {any} value
1020
+ * @param {boolean} [is_derived]
1021
+ */
1022
+ capture(source2, value, is_derived = false) {
1023
+ if (source2.v !== UNINITIALIZED && !this.previous.has(source2)) {
1024
+ this.previous.set(source2, source2.v);
1025
+ }
1026
+ if ((source2.f & ERROR_VALUE) === 0) {
1027
+ this.current.set(source2, [value, is_derived]);
1028
+ batch_values?.set(source2, value);
1029
+ }
1030
+ if (!this.is_fork) {
1031
+ source2.v = value;
1032
+ }
1033
+ }
1034
+ activate() {
1035
+ current_batch = this;
1036
+ }
1037
+ deactivate() {
1038
+ current_batch = null;
1039
+ batch_values = null;
1040
+ }
1041
+ flush() {
1042
+ try {
1043
+ if (DEV) ;
1044
+ is_processing = true;
1045
+ current_batch = this;
1046
+ this.#process();
1047
+ } finally {
1048
+ flush_count = 0;
1049
+ last_scheduled_effect = null;
1050
+ collected_effects = null;
1051
+ legacy_updates = null;
1052
+ is_processing = false;
1053
+ current_batch = null;
1054
+ batch_values = null;
1055
+ old_values.clear();
1056
+ }
1057
+ }
1058
+ discard() {
1059
+ for (const fn of this.#discard_callbacks) fn(this);
1060
+ this.#discard_callbacks.clear();
1061
+ for (const deferred2 of this.async_deriveds.values()) {
1062
+ deferred2.reject(OBSOLETE);
1063
+ }
1064
+ this.#unlink();
1065
+ this.#deferred?.resolve();
1066
+ }
1067
+ /**
1068
+ * @param {Effect} effect
1069
+ */
1070
+ register_created_effect(effect) {
1071
+ this.#new_effects.push(effect);
1072
+ }
1073
+ #commit() {
1074
+ for (let batch = first_batch; batch !== null; batch = batch.#next) {
1075
+ var is_earlier = batch.id < this.id;
1076
+ var sources = [];
1077
+ for (const [source3, [value, is_derived]] of this.current) {
1078
+ if (batch.current.has(source3)) {
1079
+ var batch_value = (
1080
+ /** @type {[any, boolean]} */
1081
+ batch.current.get(source3)[0]
1082
+ );
1083
+ if (is_earlier && value !== batch_value) {
1084
+ batch.current.set(source3, [value, is_derived]);
1085
+ } else {
1086
+ continue;
1087
+ }
1088
+ }
1089
+ sources.push(source3);
1090
+ }
1091
+ if (is_earlier) {
1092
+ for (const [effect, deferred2] of this.async_deriveds) {
1093
+ const d = batch.async_deriveds.get(effect);
1094
+ if (d) deferred2.promise.then(d.resolve).catch(d.reject);
1095
+ }
1096
+ }
1097
+ var current = [...batch.current.keys()].filter(
1098
+ (source3) => !/** @type {[any, boolean]} */
1099
+ batch.current.get(source3)[1]
1100
+ );
1101
+ if (!batch.#started || current.length === 0) continue;
1102
+ var others = current.filter((source3) => !this.current.has(source3));
1103
+ if (others.length === 0) {
1104
+ if (is_earlier) {
1105
+ batch.discard();
1106
+ }
1107
+ } else if (sources.length > 0) {
1108
+ if (is_earlier) {
1109
+ for (const unskipped of this.#unskipped_branches) {
1110
+ batch.unskip_effect(unskipped, (e) => {
1111
+ if ((e.f & (BLOCK_EFFECT | ASYNC)) !== 0) {
1112
+ batch.schedule(e);
1113
+ } else {
1114
+ batch.#defer_effects([e]);
1115
+ }
1116
+ });
1117
+ }
1118
+ }
1119
+ batch.activate();
1120
+ var marked = /* @__PURE__ */ new Set();
1121
+ var checked = /* @__PURE__ */ new Map();
1122
+ for (var source2 of sources) {
1123
+ mark_effects(source2, others, marked, checked);
1124
+ }
1125
+ checked = /* @__PURE__ */ new Map();
1126
+ var current_unequal = [...batch.current].filter(([c, v1]) => {
1127
+ const v2 = this.current.get(c);
1128
+ if (!v2) return true;
1129
+ return v2[0] !== v1[0] || v2[1] !== v1[1];
1130
+ }).map(([c]) => c);
1131
+ if (current_unequal.length > 0) {
1132
+ for (const effect of this.#new_effects) {
1133
+ if ((effect.f & (DESTROYED | INERT | EAGER_EFFECT)) === 0 && depends_on(effect, current_unequal, checked)) {
1134
+ if ((effect.f & (ASYNC | BLOCK_EFFECT)) !== 0) {
1135
+ set_signal_status(effect, DIRTY);
1136
+ batch.schedule(effect);
1137
+ } else {
1138
+ batch.#dirty_effects.add(effect);
1139
+ }
1140
+ }
1141
+ }
1142
+ }
1143
+ if (batch.#roots.length > 0 && !batch.#decrement_queued) {
1144
+ batch.apply();
1145
+ for (var root2 of batch.#roots) {
1146
+ batch.#traverse(root2, [], []);
1147
+ }
1148
+ batch.#roots = [];
1149
+ }
1150
+ batch.deactivate();
1151
+ }
1152
+ }
1153
+ }
1154
+ /**
1155
+ * @param {boolean} blocking
1156
+ * @param {Effect} effect
1157
+ */
1158
+ increment(blocking, effect) {
1159
+ this.#pending += 1;
1160
+ if (blocking) {
1161
+ let blocking_pending_count = this.#blocking_pending.get(effect) ?? 0;
1162
+ this.#blocking_pending.set(effect, blocking_pending_count + 1);
1163
+ }
1164
+ }
1165
+ /**
1166
+ * @param {boolean} blocking
1167
+ * @param {Effect} effect
1168
+ */
1169
+ decrement(blocking, effect) {
1170
+ this.#pending -= 1;
1171
+ if (blocking) {
1172
+ let blocking_pending_count = this.#blocking_pending.get(effect) ?? 0;
1173
+ if (blocking_pending_count === 1) {
1174
+ this.#blocking_pending.delete(effect);
1175
+ } else {
1176
+ this.#blocking_pending.set(effect, blocking_pending_count - 1);
1177
+ }
1178
+ }
1179
+ if (this.#decrement_queued) return;
1180
+ this.#decrement_queued = true;
1181
+ queue_micro_task(() => {
1182
+ this.#decrement_queued = false;
1183
+ if (this.linked) {
1184
+ this.flush();
1185
+ }
1186
+ });
1187
+ }
1188
+ /**
1189
+ * @param {Set<Effect>} dirty_effects
1190
+ * @param {Set<Effect>} maybe_dirty_effects
1191
+ */
1192
+ transfer_effects(dirty_effects, maybe_dirty_effects) {
1193
+ for (const e of dirty_effects) {
1194
+ this.#dirty_effects.add(e);
1195
+ }
1196
+ for (const e of maybe_dirty_effects) {
1197
+ this.#maybe_dirty_effects.add(e);
1198
+ }
1199
+ dirty_effects.clear();
1200
+ maybe_dirty_effects.clear();
1201
+ }
1202
+ /** @param {(batch: Batch) => void} fn */
1203
+ oncommit(fn) {
1204
+ this.#commit_callbacks.add(fn);
1205
+ }
1206
+ /** @param {(batch: Batch) => void} fn */
1207
+ ondiscard(fn) {
1208
+ this.#discard_callbacks.add(fn);
1209
+ }
1210
+ settled() {
1211
+ return (this.#deferred ??= deferred()).promise;
1212
+ }
1213
+ static ensure() {
1214
+ if (current_batch === null) {
1215
+ const batch = current_batch = new Batch();
1216
+ if (!is_processing && !is_flushing_sync) {
1217
+ queue_micro_task(() => {
1218
+ if (!batch.#started) {
1219
+ batch.flush();
1220
+ }
1221
+ });
1222
+ }
1223
+ }
1224
+ return current_batch;
1225
+ }
1226
+ apply() {
1227
+ {
1228
+ batch_values = null;
1229
+ return;
1230
+ }
1231
+ }
1232
+ /**
1233
+ *
1234
+ * @param {Effect} effect
1235
+ */
1236
+ schedule(effect) {
1237
+ last_scheduled_effect = effect;
1238
+ if (effect.b?.is_pending && (effect.f & (EFFECT | RENDER_EFFECT | MANAGED_EFFECT)) !== 0 && (effect.f & REACTION_RAN) === 0) {
1239
+ effect.b.defer_effect(effect);
1240
+ return;
1241
+ }
1242
+ var e = effect;
1243
+ while (e.parent !== null) {
1244
+ e = e.parent;
1245
+ var flags2 = e.f;
1246
+ if (collected_effects !== null && e === active_effect) {
1247
+ if ((active_reaction === null || (active_reaction.f & DERIVED) === 0) && true) {
1248
+ return;
1249
+ }
1250
+ }
1251
+ if ((flags2 & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
1252
+ if ((flags2 & CLEAN) === 0) {
1253
+ return;
1254
+ }
1255
+ e.f ^= CLEAN;
1256
+ }
1257
+ }
1258
+ this.#roots.push(e);
1259
+ }
1260
+ #unlink() {
1261
+ if (!this.linked) return;
1262
+ var prev = this.#prev;
1263
+ var next2 = this.#next;
1264
+ if (prev === null) {
1265
+ first_batch = next2;
1266
+ } else {
1267
+ prev.#next = next2;
1268
+ }
1269
+ if (next2 === null) {
1270
+ last_batch = prev;
1271
+ } else {
1272
+ next2.#prev = prev;
1273
+ }
1274
+ this.linked = false;
1275
+ }
1276
+ }
1277
+ function flushSync(fn) {
1278
+ var was_flushing_sync = is_flushing_sync;
1279
+ is_flushing_sync = true;
1280
+ try {
1281
+ var result;
1282
+ if (fn) ;
1283
+ while (true) {
1284
+ flush_tasks();
1285
+ if (current_batch === null) {
1286
+ return (
1287
+ /** @type {T} */
1288
+ result
1289
+ );
1290
+ }
1291
+ current_batch.flush();
1292
+ }
1293
+ } finally {
1294
+ is_flushing_sync = was_flushing_sync;
1295
+ }
1296
+ }
1297
+ function infinite_loop_guard() {
1298
+ try {
1299
+ effect_update_depth_exceeded();
1300
+ } catch (error) {
1301
+ invoke_error_boundary(error, last_scheduled_effect);
1302
+ }
1303
+ }
1304
+ let eager_block_effects = null;
1305
+ function flush_queued_effects(effects) {
1306
+ var length = effects.length;
1307
+ if (length === 0) return;
1308
+ var i = 0;
1309
+ while (i < length) {
1310
+ var effect = effects[i++];
1311
+ if ((effect.f & (DESTROYED | INERT)) === 0 && is_dirty(effect)) {
1312
+ eager_block_effects = /* @__PURE__ */ new Set();
1313
+ update_effect(effect);
1314
+ if (effect.deps === null && effect.first === null && effect.nodes === null && effect.teardown === null && effect.ac === null) {
1315
+ unlink_effect(effect);
1316
+ }
1317
+ if (eager_block_effects?.size > 0) {
1318
+ old_values.clear();
1319
+ for (const e of eager_block_effects) {
1320
+ if ((e.f & (DESTROYED | INERT)) !== 0) continue;
1321
+ const ordered_effects = [e];
1322
+ let ancestor = e.parent;
1323
+ while (ancestor !== null) {
1324
+ if (eager_block_effects.has(ancestor)) {
1325
+ eager_block_effects.delete(ancestor);
1326
+ ordered_effects.push(ancestor);
1327
+ }
1328
+ ancestor = ancestor.parent;
1329
+ }
1330
+ for (let j = ordered_effects.length - 1; j >= 0; j--) {
1331
+ const e2 = ordered_effects[j];
1332
+ if ((e2.f & (DESTROYED | INERT)) !== 0) continue;
1333
+ update_effect(e2);
1334
+ }
1335
+ }
1336
+ eager_block_effects.clear();
1337
+ }
1338
+ }
1339
+ }
1340
+ eager_block_effects = null;
1341
+ }
1342
+ function mark_effects(value, sources, marked, checked) {
1343
+ if (marked.has(value)) return;
1344
+ marked.add(value);
1345
+ if (value.reactions !== null) {
1346
+ for (const reaction of value.reactions) {
1347
+ const flags2 = reaction.f;
1348
+ if ((flags2 & DERIVED) !== 0) {
1349
+ mark_effects(
1350
+ /** @type {Derived} */
1351
+ reaction,
1352
+ sources,
1353
+ marked,
1354
+ checked
1355
+ );
1356
+ } else if ((flags2 & (ASYNC | BLOCK_EFFECT)) !== 0 && (flags2 & DIRTY) === 0 && depends_on(reaction, sources, checked)) {
1357
+ set_signal_status(reaction, DIRTY);
1358
+ schedule_effect(
1359
+ /** @type {Effect} */
1360
+ reaction
1361
+ );
1362
+ }
1363
+ }
1364
+ }
1365
+ }
1366
+ function depends_on(reaction, sources, checked) {
1367
+ const depends = checked.get(reaction);
1368
+ if (depends !== void 0) return depends;
1369
+ if (reaction.deps !== null) {
1370
+ for (const dep of reaction.deps) {
1371
+ if (includes.call(sources, dep)) {
1372
+ return true;
1373
+ }
1374
+ if ((dep.f & DERIVED) !== 0 && depends_on(
1375
+ /** @type {Derived} */
1376
+ dep,
1377
+ sources,
1378
+ checked
1379
+ )) {
1380
+ checked.set(
1381
+ /** @type {Derived} */
1382
+ dep,
1383
+ true
1384
+ );
1385
+ return true;
1386
+ }
1387
+ }
1388
+ }
1389
+ checked.set(reaction, false);
1390
+ return false;
1391
+ }
1392
+ function schedule_effect(effect) {
1393
+ current_batch.schedule(effect);
1394
+ }
1395
+ function reset_branch(effect, tracked) {
1396
+ if ((effect.f & BRANCH_EFFECT) !== 0 && (effect.f & CLEAN) !== 0) {
1397
+ return;
1398
+ }
1399
+ if ((effect.f & DIRTY) !== 0) {
1400
+ tracked.d.push(effect);
1401
+ } else if ((effect.f & MAYBE_DIRTY) !== 0) {
1402
+ tracked.m.push(effect);
1403
+ }
1404
+ set_signal_status(effect, CLEAN);
1405
+ var e = effect.first;
1406
+ while (e !== null) {
1407
+ reset_branch(e, tracked);
1408
+ e = e.next;
1409
+ }
1410
+ }
1411
+ function reset_all(effect) {
1412
+ set_signal_status(effect, CLEAN);
1413
+ var e = effect.first;
1414
+ while (e !== null) {
1415
+ reset_all(e);
1416
+ e = e.next;
1417
+ }
1418
+ }
1419
+ let eager_effects = /* @__PURE__ */ new Set();
1420
+ const old_values = /* @__PURE__ */ new Map();
1421
+ let eager_effects_deferred = false;
1422
+ function source(v, stack) {
1423
+ var signal = {
1424
+ f: 0,
1425
+ // TODO ideally we could skip this altogether, but it causes type errors
1426
+ v,
1427
+ reactions: null,
1428
+ equals,
1429
+ rv: 0,
1430
+ wv: 0
1431
+ };
1432
+ return signal;
1433
+ }
1434
+ // @__NO_SIDE_EFFECTS__
1435
+ function state(v, stack) {
1436
+ const s = source(v);
1437
+ push_reaction_value(s);
1438
+ return s;
1439
+ }
1440
+ // @__NO_SIDE_EFFECTS__
1441
+ function mutable_source(initial_value, immutable = false, trackable = true) {
1442
+ const s = source(initial_value);
1443
+ if (!immutable) {
1444
+ s.equals = safe_equals;
1445
+ }
1446
+ return s;
1447
+ }
1448
+ function set(source2, value, should_proxy = false) {
1449
+ if (active_reaction !== null && // since we are untracking the function inside `$inspect.with` we need to add this check
1450
+ // to ensure we error if state is set inside an inspect effect
1451
+ (!untracking || (active_reaction.f & EAGER_EFFECT) !== 0) && is_runes() && (active_reaction.f & (DERIVED | BLOCK_EFFECT | ASYNC | EAGER_EFFECT)) !== 0 && (current_sources === null || !current_sources.has(source2))) {
1452
+ state_unsafe_mutation();
1453
+ }
1454
+ let new_value = should_proxy ? proxy(value) : value;
1455
+ return internal_set(source2, new_value, legacy_updates);
1456
+ }
1457
+ function internal_set(source2, value, updated_during_traversal = null) {
1458
+ if (!source2.equals(value)) {
1459
+ if (is_destroying_effect) {
1460
+ old_values.set(source2, value);
1461
+ } else if (!old_values.has(source2)) {
1462
+ old_values.set(source2, source2.v);
1463
+ }
1464
+ var batch = Batch.ensure();
1465
+ batch.capture(source2, value);
1466
+ if ((source2.f & DERIVED) !== 0) {
1467
+ const derived2 = (
1468
+ /** @type {Derived} */
1469
+ source2
1470
+ );
1471
+ if ((source2.f & DIRTY) !== 0) {
1472
+ execute_derived(derived2);
1473
+ }
1474
+ if (batch_values === null) {
1475
+ update_derived_status(derived2);
1476
+ }
1477
+ }
1478
+ source2.wv = increment_write_version();
1479
+ mark_reactions(source2, DIRTY, updated_during_traversal);
1480
+ if (active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
1481
+ if (untracked_writes === null) {
1482
+ set_untracked_writes([source2]);
1483
+ } else {
1484
+ untracked_writes.push(source2);
1485
+ }
1486
+ }
1487
+ if (!batch.is_fork && eager_effects.size > 0 && !eager_effects_deferred) {
1488
+ flush_eager_effects();
1489
+ }
1490
+ }
1491
+ return value;
1492
+ }
1493
+ function flush_eager_effects() {
1494
+ eager_effects_deferred = false;
1495
+ for (const effect of eager_effects) {
1496
+ if ((effect.f & CLEAN) !== 0) {
1497
+ set_signal_status(effect, MAYBE_DIRTY);
1498
+ }
1499
+ let dirty;
1500
+ try {
1501
+ dirty = is_dirty(effect);
1502
+ } catch {
1503
+ dirty = true;
1504
+ }
1505
+ if (dirty) {
1506
+ update_effect(effect);
1507
+ }
1508
+ }
1509
+ eager_effects.clear();
1510
+ }
1511
+ function increment(source2) {
1512
+ set(source2, source2.v + 1);
1513
+ }
1514
+ function mark_reactions(signal, status, updated_during_traversal) {
1515
+ var reactions = signal.reactions;
1516
+ if (reactions === null) return;
1517
+ var length = reactions.length;
1518
+ for (var i = 0; i < length; i++) {
1519
+ var reaction = reactions[i];
1520
+ var flags2 = reaction.f;
1521
+ var not_dirty = (flags2 & DIRTY) === 0;
1522
+ if (not_dirty) {
1523
+ set_signal_status(reaction, status);
1524
+ }
1525
+ if ((flags2 & EAGER_EFFECT) !== 0) {
1526
+ eager_effects.add(
1527
+ /** @type {Effect} */
1528
+ reaction
1529
+ );
1530
+ } else if ((flags2 & DERIVED) !== 0) {
1531
+ var derived2 = (
1532
+ /** @type {Derived} */
1533
+ reaction
1534
+ );
1535
+ batch_values?.delete(derived2);
1536
+ if ((flags2 & WAS_MARKED) === 0) {
1537
+ if (flags2 & CONNECTED && (active_effect === null || (active_effect.f & REACTION_IS_UPDATING) === 0)) {
1538
+ reaction.f |= WAS_MARKED;
1539
+ }
1540
+ mark_reactions(derived2, MAYBE_DIRTY, updated_during_traversal);
1541
+ }
1542
+ } else if (not_dirty) {
1543
+ var effect = (
1544
+ /** @type {Effect} */
1545
+ reaction
1546
+ );
1547
+ if ((flags2 & BLOCK_EFFECT) !== 0 && eager_block_effects !== null) {
1548
+ eager_block_effects.add(effect);
1549
+ }
1550
+ if (updated_during_traversal !== null) {
1551
+ updated_during_traversal.push(effect);
1552
+ } else {
1553
+ schedule_effect(effect);
1554
+ }
1555
+ }
1556
+ }
1557
+ }
1558
+ let is_updating_effect = false;
1559
+ let is_destroying_effect = false;
1560
+ function set_is_destroying_effect(value) {
1561
+ is_destroying_effect = value;
1562
+ }
1563
+ let active_reaction = null;
1564
+ let untracking = false;
1565
+ function set_active_reaction(reaction) {
1566
+ active_reaction = reaction;
1567
+ }
1568
+ let active_effect = null;
1569
+ function set_active_effect(effect) {
1570
+ active_effect = effect;
1571
+ }
1572
+ let current_sources = null;
1573
+ function push_reaction_value(value) {
1574
+ if (active_reaction !== null && true) {
1575
+ (current_sources ??= /* @__PURE__ */ new Set()).add(value);
1576
+ }
1577
+ }
1578
+ let new_deps = null;
1579
+ let skipped_deps = 0;
1580
+ let untracked_writes = null;
1581
+ function set_untracked_writes(value) {
1582
+ untracked_writes = value;
1583
+ }
1584
+ let write_version = 1;
1585
+ let read_version = 0;
1586
+ let update_version = read_version;
1587
+ function set_update_version(value) {
1588
+ update_version = value;
1589
+ }
1590
+ function increment_write_version() {
1591
+ return ++write_version;
1592
+ }
1593
+ function is_dirty(reaction) {
1594
+ var flags2 = reaction.f;
1595
+ if ((flags2 & DIRTY) !== 0) {
1596
+ return true;
1597
+ }
1598
+ if (flags2 & DERIVED) {
1599
+ reaction.f &= ~WAS_MARKED;
1600
+ }
1601
+ if ((flags2 & MAYBE_DIRTY) !== 0) {
1602
+ var dependencies = (
1603
+ /** @type {Value[]} */
1604
+ reaction.deps
1605
+ );
1606
+ var length = dependencies.length;
1607
+ for (var i = 0; i < length; i++) {
1608
+ var dependency = dependencies[i];
1609
+ if (is_dirty(
1610
+ /** @type {Derived} */
1611
+ dependency
1612
+ )) {
1613
+ update_derived(
1614
+ /** @type {Derived} */
1615
+ dependency
1616
+ );
1617
+ }
1618
+ if (dependency.wv > reaction.wv) {
1619
+ return true;
1620
+ }
1621
+ }
1622
+ if ((flags2 & CONNECTED) !== 0 && // During time traveling we don't want to reset the status so that
1623
+ // traversal of the graph in the other batches still happens
1624
+ batch_values === null) {
1625
+ set_signal_status(reaction, CLEAN);
1626
+ }
1627
+ }
1628
+ return false;
1629
+ }
1630
+ function schedule_possible_effect_self_invalidation(signal, effect, root2 = true) {
1631
+ var reactions = signal.reactions;
1632
+ if (reactions === null) return;
1633
+ if (current_sources !== null && current_sources.has(signal)) {
1634
+ return;
1635
+ }
1636
+ for (var i = 0; i < reactions.length; i++) {
1637
+ var reaction = reactions[i];
1638
+ if ((reaction.f & DERIVED) !== 0) {
1639
+ schedule_possible_effect_self_invalidation(
1640
+ /** @type {Derived} */
1641
+ reaction,
1642
+ effect,
1643
+ false
1644
+ );
1645
+ } else if (effect === reaction) {
1646
+ if (root2) {
1647
+ set_signal_status(reaction, DIRTY);
1648
+ } else if ((reaction.f & CLEAN) !== 0) {
1649
+ set_signal_status(reaction, MAYBE_DIRTY);
1650
+ }
1651
+ schedule_effect(
1652
+ /** @type {Effect} */
1653
+ reaction
1654
+ );
1655
+ }
1656
+ }
1657
+ }
1658
+ function update_reaction(reaction) {
1659
+ var previous_deps = new_deps;
1660
+ var previous_skipped_deps = skipped_deps;
1661
+ var previous_untracked_writes = untracked_writes;
1662
+ var previous_reaction = active_reaction;
1663
+ var previous_sources = current_sources;
1664
+ var previous_component_context = component_context;
1665
+ var previous_untracking = untracking;
1666
+ var previous_update_version = update_version;
1667
+ var flags2 = reaction.f;
1668
+ new_deps = /** @type {null | Value[]} */
1669
+ null;
1670
+ skipped_deps = 0;
1671
+ untracked_writes = null;
1672
+ active_reaction = (flags2 & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
1673
+ current_sources = null;
1674
+ set_component_context(reaction.ctx);
1675
+ untracking = false;
1676
+ update_version = ++read_version;
1677
+ if (reaction.ac !== null) {
1678
+ without_reactive_context(() => {
1679
+ reaction.ac.abort(STALE_REACTION);
1680
+ });
1681
+ reaction.ac = null;
1682
+ }
1683
+ try {
1684
+ reaction.f |= REACTION_IS_UPDATING;
1685
+ var fn = (
1686
+ /** @type {Function} */
1687
+ reaction.fn
1688
+ );
1689
+ var result = fn();
1690
+ reaction.f |= REACTION_RAN;
1691
+ var deps = update_dependencies(reaction);
1692
+ if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0) {
1693
+ for (var i = 0; i < /** @type {Source[]} */
1694
+ untracked_writes.length; i++) {
1695
+ schedule_possible_effect_self_invalidation(
1696
+ untracked_writes[i],
1697
+ /** @type {Effect} */
1698
+ reaction
1699
+ );
1700
+ }
1701
+ }
1702
+ if (previous_reaction !== null && previous_reaction !== reaction) {
1703
+ read_version++;
1704
+ if (previous_reaction.deps !== null) {
1705
+ for (let i2 = 0; i2 < previous_skipped_deps; i2 += 1) {
1706
+ previous_reaction.deps[i2].rv = read_version;
1707
+ }
1708
+ }
1709
+ if (previous_deps !== null) {
1710
+ for (const dep of previous_deps) {
1711
+ dep.rv = read_version;
1712
+ }
1713
+ }
1714
+ if (untracked_writes !== null) {
1715
+ if (previous_untracked_writes === null) {
1716
+ previous_untracked_writes = untracked_writes;
1717
+ } else {
1718
+ previous_untracked_writes.push(.../** @type {Source[]} */
1719
+ untracked_writes);
1720
+ }
1721
+ }
1722
+ }
1723
+ if ((reaction.f & ERROR_VALUE) !== 0) {
1724
+ reaction.f ^= ERROR_VALUE;
1725
+ }
1726
+ return result;
1727
+ } catch (error) {
1728
+ update_dependencies(reaction);
1729
+ return handle_error(error);
1730
+ } finally {
1731
+ reaction.f ^= REACTION_IS_UPDATING;
1732
+ new_deps = previous_deps;
1733
+ skipped_deps = previous_skipped_deps;
1734
+ untracked_writes = previous_untracked_writes;
1735
+ active_reaction = previous_reaction;
1736
+ current_sources = previous_sources;
1737
+ set_component_context(previous_component_context);
1738
+ untracking = previous_untracking;
1739
+ update_version = previous_update_version;
1740
+ }
1741
+ }
1742
+ function update_dependencies(reaction) {
1743
+ var deps = reaction.deps;
1744
+ var is_fork = current_batch?.is_fork;
1745
+ if (new_deps !== null) {
1746
+ var i;
1747
+ if (!is_fork) {
1748
+ remove_reactions(reaction, skipped_deps);
1749
+ }
1750
+ if (deps !== null && skipped_deps > 0) {
1751
+ deps.length = skipped_deps + new_deps.length;
1752
+ for (i = 0; i < new_deps.length; i++) {
1753
+ deps[skipped_deps + i] = new_deps[i];
1754
+ }
1755
+ } else {
1756
+ reaction.deps = deps = new_deps;
1757
+ }
1758
+ if (effect_tracking() && (reaction.f & CONNECTED) !== 0) {
1759
+ for (i = skipped_deps; i < deps.length; i++) {
1760
+ (deps[i].reactions ??= []).push(reaction);
1761
+ }
1762
+ }
1763
+ } else if (!is_fork && deps !== null && skipped_deps < deps.length) {
1764
+ remove_reactions(reaction, skipped_deps);
1765
+ deps.length = skipped_deps;
1766
+ }
1767
+ return deps;
1768
+ }
1769
+ function remove_reaction(signal, dependency) {
1770
+ let reactions = dependency.reactions;
1771
+ if (reactions !== null) {
1772
+ var index = index_of.call(reactions, signal);
1773
+ if (index !== -1) {
1774
+ var new_length = reactions.length - 1;
1775
+ if (new_length === 0) {
1776
+ reactions = dependency.reactions = null;
1777
+ } else {
1778
+ reactions[index] = reactions[new_length];
1779
+ reactions.pop();
1780
+ }
1781
+ }
1782
+ }
1783
+ if (reactions === null && (dependency.f & DERIVED) !== 0 && // Destroying a child effect while updating a parent effect can cause a dependency to appear
1784
+ // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
1785
+ // allows us to skip the expensive work of disconnecting and immediately reconnecting it
1786
+ (new_deps === null || !includes.call(new_deps, dependency))) {
1787
+ var derived2 = (
1788
+ /** @type {Derived} */
1789
+ dependency
1790
+ );
1791
+ if ((derived2.f & CONNECTED) !== 0) {
1792
+ derived2.f ^= CONNECTED;
1793
+ derived2.f &= ~WAS_MARKED;
1794
+ }
1795
+ if (derived2.v !== UNINITIALIZED) {
1796
+ update_derived_status(derived2);
1797
+ }
1798
+ if (derived2.ac !== null) {
1799
+ without_reactive_context(() => {
1800
+ derived2.ac.abort(STALE_REACTION);
1801
+ derived2.ac = null;
1802
+ set_signal_status(derived2, DIRTY);
1803
+ });
1804
+ }
1805
+ freeze_derived_effects(derived2);
1806
+ remove_reactions(derived2, 0);
1807
+ }
1808
+ }
1809
+ function remove_reactions(signal, start_index) {
1810
+ var dependencies = signal.deps;
1811
+ if (dependencies === null) return;
1812
+ for (var i = start_index; i < dependencies.length; i++) {
1813
+ remove_reaction(signal, dependencies[i]);
1814
+ }
1815
+ }
1816
+ function update_effect(effect) {
1817
+ var flags2 = effect.f;
1818
+ if ((flags2 & DESTROYED) !== 0) {
1819
+ return;
1820
+ }
1821
+ set_signal_status(effect, CLEAN);
1822
+ var previous_effect = active_effect;
1823
+ var was_updating_effect = is_updating_effect;
1824
+ active_effect = effect;
1825
+ is_updating_effect = (flags2 & (BRANCH_EFFECT | ROOT_EFFECT)) === 0;
1826
+ try {
1827
+ if ((flags2 & (BLOCK_EFFECT | MANAGED_EFFECT)) !== 0) {
1828
+ destroy_block_effect_children(effect);
1829
+ } else {
1830
+ destroy_effect_children(effect);
1831
+ }
1832
+ execute_effect_teardown(effect);
1833
+ var teardown = update_reaction(effect);
1834
+ effect.teardown = typeof teardown === "function" ? teardown : null;
1835
+ effect.wv = write_version;
1836
+ var dep;
1837
+ if (DEV && tracing_mode_flag && (effect.f & DIRTY) !== 0 && effect.deps !== null) ;
1838
+ } finally {
1839
+ is_updating_effect = was_updating_effect;
1840
+ active_effect = previous_effect;
1841
+ }
1842
+ }
1843
+ function get(signal) {
1844
+ var flags2 = signal.f;
1845
+ var is_derived = (flags2 & DERIVED) !== 0;
1846
+ if (active_reaction !== null && !untracking) {
1847
+ var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0;
1848
+ if (!destroyed && (current_sources === null || !current_sources.has(signal))) {
1849
+ var deps = active_reaction.deps;
1850
+ if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) {
1851
+ if (signal.rv < read_version) {
1852
+ signal.rv = read_version;
1853
+ if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
1854
+ skipped_deps++;
1855
+ } else if (new_deps === null) {
1856
+ new_deps = [signal];
1857
+ } else {
1858
+ new_deps.push(signal);
1859
+ }
1860
+ }
1861
+ } else {
1862
+ active_reaction.deps ??= [];
1863
+ if (!includes.call(active_reaction.deps, signal)) {
1864
+ active_reaction.deps.push(signal);
1865
+ }
1866
+ var reactions = signal.reactions;
1867
+ if (reactions === null) {
1868
+ signal.reactions = [active_reaction];
1869
+ } else if (!includes.call(reactions, active_reaction)) {
1870
+ reactions.push(active_reaction);
1871
+ }
1872
+ }
1873
+ }
1874
+ }
1875
+ if (is_destroying_effect && old_values.has(signal)) {
1876
+ return old_values.get(signal);
1877
+ }
1878
+ if (is_derived) {
1879
+ var derived2 = (
1880
+ /** @type {Derived} */
1881
+ signal
1882
+ );
1883
+ if (is_destroying_effect) {
1884
+ var value = derived2.v;
1885
+ if ((derived2.f & CLEAN) === 0 && derived2.reactions !== null || depends_on_old_values(derived2)) {
1886
+ value = execute_derived(derived2);
1887
+ }
1888
+ old_values.set(derived2, value);
1889
+ return value;
1890
+ }
1891
+ var should_connect = (derived2.f & CONNECTED) === 0 && !untracking && active_reaction !== null && (is_updating_effect || (active_reaction.f & CONNECTED) !== 0);
1892
+ var is_new = (derived2.f & REACTION_RAN) === 0;
1893
+ if (is_dirty(derived2)) {
1894
+ if (should_connect) {
1895
+ derived2.f |= CONNECTED;
1896
+ }
1897
+ update_derived(derived2);
1898
+ }
1899
+ if (should_connect && !is_new) {
1900
+ unfreeze_derived_effects(derived2);
1901
+ reconnect(derived2);
1902
+ }
1903
+ }
1904
+ if (batch_values?.has(signal)) {
1905
+ return batch_values.get(signal);
1906
+ }
1907
+ if ((signal.f & ERROR_VALUE) !== 0) {
1908
+ throw signal.v;
1909
+ }
1910
+ return signal.v;
1911
+ }
1912
+ function reconnect(derived2) {
1913
+ derived2.f |= CONNECTED;
1914
+ if (derived2.deps === null) return;
1915
+ for (const dep of derived2.deps) {
1916
+ (dep.reactions ??= []).push(derived2);
1917
+ if ((dep.f & DERIVED) !== 0 && (dep.f & CONNECTED) === 0) {
1918
+ unfreeze_derived_effects(
1919
+ /** @type {Derived} */
1920
+ dep
1921
+ );
1922
+ reconnect(
1923
+ /** @type {Derived} */
1924
+ dep
1925
+ );
1926
+ }
1927
+ }
1928
+ }
1929
+ function depends_on_old_values(derived2) {
1930
+ if (derived2.v === UNINITIALIZED) return true;
1931
+ if (derived2.deps === null) return false;
1932
+ for (const dep of derived2.deps) {
1933
+ if (old_values.has(dep)) {
1934
+ return true;
1935
+ }
1936
+ if ((dep.f & DERIVED) !== 0 && depends_on_old_values(
1937
+ /** @type {Derived} */
1938
+ dep
1939
+ )) {
1940
+ return true;
1941
+ }
1942
+ }
1943
+ return false;
1944
+ }
1945
+ function untrack(fn) {
1946
+ var previous_untracking = untracking;
1947
+ try {
1948
+ untracking = true;
1949
+ return fn();
1950
+ } finally {
1951
+ untracking = previous_untracking;
1952
+ }
1953
+ }
1954
+ function push_effect(effect, parent_effect) {
1955
+ var parent_last = parent_effect.last;
1956
+ if (parent_last === null) {
1957
+ parent_effect.last = parent_effect.first = effect;
1958
+ } else {
1959
+ parent_last.next = effect;
1960
+ effect.prev = parent_last;
1961
+ parent_effect.last = effect;
1962
+ }
1963
+ }
1964
+ function create_effect(type, fn) {
1965
+ var parent = active_effect;
1966
+ if (parent !== null && (parent.f & INERT) !== 0) {
1967
+ type |= INERT;
1968
+ }
1969
+ var effect = {
1970
+ ctx: component_context,
1971
+ deps: null,
1972
+ nodes: null,
1973
+ f: type | DIRTY | CONNECTED,
1974
+ first: null,
1975
+ fn,
1976
+ last: null,
1977
+ next: null,
1978
+ parent,
1979
+ b: parent && parent.b,
1980
+ prev: null,
1981
+ teardown: null,
1982
+ wv: 0,
1983
+ ac: null
1984
+ };
1985
+ current_batch?.register_created_effect(effect);
1986
+ var e = effect;
1987
+ if ((type & EFFECT) !== 0) {
1988
+ if (collected_effects !== null) {
1989
+ collected_effects.push(effect);
1990
+ } else {
1991
+ Batch.ensure().schedule(effect);
1992
+ }
1993
+ } else if (fn !== null) {
1994
+ try {
1995
+ update_effect(effect);
1996
+ } catch (e2) {
1997
+ destroy_effect(effect);
1998
+ throw e2;
1999
+ }
2000
+ if (e.deps === null && e.teardown === null && e.nodes === null && e.first === e.last && // either `null`, or a singular child
2001
+ (e.f & EFFECT_PRESERVED) === 0) {
2002
+ e = e.first;
2003
+ if ((type & BLOCK_EFFECT) !== 0 && (type & EFFECT_TRANSPARENT) !== 0 && e !== null) {
2004
+ e.f |= EFFECT_TRANSPARENT;
2005
+ }
2006
+ }
2007
+ }
2008
+ if (e !== null) {
2009
+ e.parent = parent;
2010
+ if (parent !== null) {
2011
+ push_effect(e, parent);
2012
+ }
2013
+ if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0 && (type & ROOT_EFFECT) === 0) {
2014
+ var derived2 = (
2015
+ /** @type {Derived} */
2016
+ active_reaction
2017
+ );
2018
+ (derived2.effects ??= []).push(e);
2019
+ }
2020
+ }
2021
+ return effect;
2022
+ }
2023
+ function effect_tracking() {
2024
+ return active_reaction !== null && !untracking;
2025
+ }
2026
+ function create_user_effect(fn) {
2027
+ return create_effect(EFFECT | USER_EFFECT, fn);
2028
+ }
2029
+ function component_root(fn) {
2030
+ Batch.ensure();
2031
+ const effect = create_effect(ROOT_EFFECT | EFFECT_PRESERVED, fn);
2032
+ return (options = {}) => {
2033
+ return new Promise((fulfil) => {
2034
+ if (options.outro) {
2035
+ pause_effect(effect, () => {
2036
+ destroy_effect(effect);
2037
+ fulfil(void 0);
2038
+ });
2039
+ } else {
2040
+ destroy_effect(effect);
2041
+ fulfil(void 0);
2042
+ }
2043
+ });
2044
+ };
2045
+ }
2046
+ function render_effect(fn, flags2 = 0) {
2047
+ return create_effect(RENDER_EFFECT | flags2, fn);
2048
+ }
2049
+ function block(fn, flags2 = 0) {
2050
+ var effect = create_effect(BLOCK_EFFECT | flags2, fn);
2051
+ return effect;
2052
+ }
2053
+ function branch(fn) {
2054
+ return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn);
2055
+ }
2056
+ function execute_effect_teardown(effect) {
2057
+ var teardown = effect.teardown;
2058
+ if (teardown !== null) {
2059
+ const previously_destroying_effect = is_destroying_effect;
2060
+ const previous_reaction = active_reaction;
2061
+ set_is_destroying_effect(true);
2062
+ set_active_reaction(null);
2063
+ try {
2064
+ teardown.call(null);
2065
+ } catch (error) {
2066
+ invoke_error_boundary(error, effect.parent);
2067
+ } finally {
2068
+ set_is_destroying_effect(previously_destroying_effect);
2069
+ set_active_reaction(previous_reaction);
2070
+ }
2071
+ }
2072
+ }
2073
+ function destroy_effect_children(signal, remove_dom = false) {
2074
+ var effect = signal.first;
2075
+ signal.first = signal.last = null;
2076
+ while (effect !== null) {
2077
+ const controller = effect.ac;
2078
+ if (controller !== null) {
2079
+ without_reactive_context(() => {
2080
+ controller.abort(STALE_REACTION);
2081
+ });
2082
+ }
2083
+ var next2 = effect.next;
2084
+ if ((effect.f & ROOT_EFFECT) !== 0) {
2085
+ effect.parent = null;
2086
+ } else {
2087
+ destroy_effect(effect, remove_dom);
2088
+ }
2089
+ effect = next2;
2090
+ }
2091
+ }
2092
+ function destroy_block_effect_children(signal) {
2093
+ var effect = signal.first;
2094
+ while (effect !== null) {
2095
+ var next2 = effect.next;
2096
+ if ((effect.f & BRANCH_EFFECT) === 0) {
2097
+ destroy_effect(effect);
2098
+ }
2099
+ effect = next2;
2100
+ }
2101
+ }
2102
+ function destroy_effect(effect, remove_dom = true) {
2103
+ var removed = false;
2104
+ if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes !== null && effect.nodes.end !== null) {
2105
+ remove_effect_dom(
2106
+ effect.nodes.start,
2107
+ /** @type {TemplateNode} */
2108
+ effect.nodes.end
2109
+ );
2110
+ removed = true;
2111
+ }
2112
+ effect.f |= DESTROYING;
2113
+ destroy_effect_children(effect, remove_dom && !removed);
2114
+ remove_reactions(effect, 0);
2115
+ var transitions = effect.nodes && effect.nodes.t;
2116
+ if (transitions !== null) {
2117
+ for (const transition of transitions) {
2118
+ transition.stop();
2119
+ }
2120
+ }
2121
+ execute_effect_teardown(effect);
2122
+ effect.f ^= DESTROYING;
2123
+ effect.f |= DESTROYED;
2124
+ var parent = effect.parent;
2125
+ if (parent !== null && parent.first !== null) {
2126
+ unlink_effect(effect);
2127
+ }
2128
+ effect.next = effect.prev = effect.teardown = effect.ctx = effect.deps = effect.fn = effect.nodes = effect.ac = effect.b = null;
2129
+ }
2130
+ function remove_effect_dom(node, end) {
2131
+ while (node !== null) {
2132
+ var next2 = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
2133
+ node.remove();
2134
+ node = next2;
2135
+ }
2136
+ }
2137
+ function unlink_effect(effect) {
2138
+ var parent = effect.parent;
2139
+ var prev = effect.prev;
2140
+ var next2 = effect.next;
2141
+ if (prev !== null) prev.next = next2;
2142
+ if (next2 !== null) next2.prev = prev;
2143
+ if (parent !== null) {
2144
+ if (parent.first === effect) parent.first = next2;
2145
+ if (parent.last === effect) parent.last = prev;
2146
+ }
2147
+ }
2148
+ function pause_effect(effect, callback, destroy = true) {
2149
+ var transitions = [];
2150
+ effect.f |= PAUSED;
2151
+ pause_children(effect, transitions, true);
2152
+ var fn = () => {
2153
+ if (destroy) destroy_effect(effect);
2154
+ if (callback) callback();
2155
+ };
2156
+ var remaining = transitions.length;
2157
+ if (remaining > 0) {
2158
+ var check = () => --remaining || fn();
2159
+ for (var transition of transitions) {
2160
+ transition.out(check);
2161
+ }
2162
+ } else {
2163
+ fn();
2164
+ }
2165
+ }
2166
+ function pause_children(effect, transitions, local) {
2167
+ if ((effect.f & INERT) !== 0) return;
2168
+ effect.f ^= INERT;
2169
+ var t = effect.nodes && effect.nodes.t;
2170
+ if (t !== null) {
2171
+ for (const transition of t) {
2172
+ if (transition.is_global || local) {
2173
+ transitions.push(transition);
2174
+ }
2175
+ }
2176
+ }
2177
+ var child = effect.first;
2178
+ while (child !== null) {
2179
+ var sibling = child.next;
2180
+ if ((child.f & ROOT_EFFECT) === 0) {
2181
+ var transparent = (child.f & EFFECT_TRANSPARENT) !== 0 || // If this is a branch effect without a block effect parent,
2182
+ // it means the parent block effect was pruned. In that case,
2183
+ // transparency information was transferred to the branch effect.
2184
+ (child.f & BRANCH_EFFECT) !== 0 && (effect.f & BLOCK_EFFECT) !== 0;
2185
+ pause_children(child, transitions, transparent ? local : false);
2186
+ }
2187
+ child = sibling;
2188
+ }
2189
+ }
2190
+ function move_effect(effect, fragment) {
2191
+ if (!effect.nodes) return;
2192
+ var node = effect.nodes.start;
2193
+ var end = effect.nodes.end;
2194
+ while (node !== null) {
2195
+ var next2 = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
2196
+ fragment.append(node);
2197
+ node = next2;
2198
+ }
2199
+ }
2200
+ const event_symbol = /* @__PURE__ */ Symbol("events");
2201
+ const all_registered_events = /* @__PURE__ */ new Set();
2202
+ const root_event_handles = /* @__PURE__ */ new Set();
2203
+ let last_propagated_event = null;
2204
+ let last_propagated_event_clear_scheduled = false;
2205
+ function handle_event_propagation(event) {
2206
+ var handler_element = this;
2207
+ var owner_document = (
2208
+ /** @type {Node} */
2209
+ handler_element.ownerDocument
2210
+ );
2211
+ var event_name = event.type;
2212
+ var path = event.composedPath?.() || [];
2213
+ var current_target = (
2214
+ /** @type {null | Element} */
2215
+ path[0] || event.target
2216
+ );
2217
+ last_propagated_event = event;
2218
+ if (!last_propagated_event_clear_scheduled) {
2219
+ last_propagated_event_clear_scheduled = true;
2220
+ setTimeout(() => {
2221
+ last_propagated_event_clear_scheduled = false;
2222
+ last_propagated_event = null;
2223
+ });
2224
+ }
2225
+ var path_idx = 0;
2226
+ var handled_at = last_propagated_event === event && event[event_symbol];
2227
+ if (handled_at) {
2228
+ var at_idx = path.indexOf(handled_at);
2229
+ if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
2230
+ window)) {
2231
+ event[event_symbol] = handler_element;
2232
+ return;
2233
+ }
2234
+ var handler_idx = path.indexOf(handler_element);
2235
+ if (handler_idx === -1) {
2236
+ return;
2237
+ }
2238
+ if (at_idx <= handler_idx) {
2239
+ path_idx = at_idx;
2240
+ }
2241
+ }
2242
+ current_target = /** @type {Element} */
2243
+ path[path_idx] || event.target;
2244
+ if (current_target === handler_element) return;
2245
+ define_property(event, "currentTarget", {
2246
+ configurable: true,
2247
+ get() {
2248
+ return current_target || owner_document;
2249
+ }
2250
+ });
2251
+ var previous_reaction = active_reaction;
2252
+ var previous_effect = active_effect;
2253
+ set_active_reaction(null);
2254
+ set_active_effect(null);
2255
+ try {
2256
+ var throw_error;
2257
+ var other_errors = [];
2258
+ while (current_target !== null) {
2259
+ if (current_target === handler_element) break;
2260
+ try {
2261
+ var delegated = current_target[event_symbol]?.[event_name];
2262
+ if (delegated != null && (!/** @type {any} */
2263
+ current_target.disabled || // DOM could've been updated already by the time this is reached, so we check this as well
2264
+ // -> the target could not have been disabled because it emits the event in the first place
2265
+ event.target === current_target)) {
2266
+ delegated.call(current_target, event);
2267
+ }
2268
+ } catch (error) {
2269
+ if (throw_error) {
2270
+ other_errors.push(error);
2271
+ } else {
2272
+ throw_error = error;
2273
+ }
2274
+ }
2275
+ if (event.cancelBubble) break;
2276
+ path_idx++;
2277
+ current_target = path_idx < path.length ? (
2278
+ /** @type {Element} */
2279
+ path[path_idx]
2280
+ ) : null;
2281
+ }
2282
+ if (throw_error) {
2283
+ for (let error of other_errors) {
2284
+ queueMicrotask(() => {
2285
+ throw error;
2286
+ });
2287
+ }
2288
+ throw throw_error;
2289
+ }
2290
+ } finally {
2291
+ event[event_symbol] = handler_element;
2292
+ delete event.currentTarget;
2293
+ set_active_reaction(previous_reaction);
2294
+ set_active_effect(previous_effect);
2295
+ }
2296
+ }
2297
+ function assign_nodes(start, end) {
2298
+ var effect = (
2299
+ /** @type {Effect} */
2300
+ active_effect
2301
+ );
2302
+ if (effect.nodes === null) {
2303
+ effect.nodes = { start, end, a: null, t: null };
2304
+ }
2305
+ }
2306
+ const DOM_BOOLEAN_ATTRIBUTES = [
2307
+ "allowfullscreen",
2308
+ "async",
2309
+ "autofocus",
2310
+ "autoplay",
2311
+ "checked",
2312
+ "controls",
2313
+ "default",
2314
+ "disabled",
2315
+ "formnovalidate",
2316
+ "indeterminate",
2317
+ "inert",
2318
+ "ismap",
2319
+ "loop",
2320
+ "multiple",
2321
+ "muted",
2322
+ "nomodule",
2323
+ "novalidate",
2324
+ "open",
2325
+ "playsinline",
2326
+ "readonly",
2327
+ "required",
2328
+ "reversed",
2329
+ "seamless",
2330
+ "selected",
2331
+ "webkitdirectory",
2332
+ "defer",
2333
+ "disablepictureinpicture",
2334
+ "disableremoteplayback"
2335
+ ];
2336
+ function is_boolean_attribute(name) {
2337
+ return DOM_BOOLEAN_ATTRIBUTES.includes(name);
2338
+ }
2339
+ const PASSIVE_EVENTS = ["touchstart", "touchmove"];
2340
+ function is_passive_event(name) {
2341
+ return PASSIVE_EVENTS.includes(name);
2342
+ }
2343
+ function createSubscriber(start) {
2344
+ let subscribers = 0;
2345
+ let version = source(0);
2346
+ let stop;
2347
+ return () => {
2348
+ if (effect_tracking()) {
2349
+ get(version);
2350
+ render_effect(() => {
2351
+ if (subscribers === 0) {
2352
+ stop = untrack(() => start(() => increment(version)));
2353
+ }
2354
+ subscribers += 1;
2355
+ return () => {
2356
+ queue_micro_task(() => {
2357
+ subscribers -= 1;
2358
+ if (subscribers === 0) {
2359
+ stop?.();
2360
+ stop = void 0;
2361
+ increment(version);
2362
+ }
2363
+ });
2364
+ };
2365
+ });
2366
+ }
2367
+ };
2368
+ }
2369
+ var flags = EFFECT_TRANSPARENT | EFFECT_PRESERVED;
2370
+ function boundary(node, props, children, transform_error) {
2371
+ new Boundary(node, props, children, transform_error);
2372
+ }
2373
+ class Boundary {
2374
+ /** @type {Boundary | null} */
2375
+ parent;
2376
+ is_pending = false;
2377
+ /**
2378
+ * API-level transformError transform function. Transforms errors before they reach the `failed` snippet.
2379
+ * Inherited from parent boundary, or defaults to identity.
2380
+ * @type {(error: unknown) => unknown}
2381
+ */
2382
+ transform_error;
2383
+ /** @type {TemplateNode} */
2384
+ #anchor;
2385
+ /** @type {TemplateNode | null} */
2386
+ #hydrate_open = hydrating ? hydrate_node : null;
2387
+ /** @type {BoundaryProps} */
2388
+ #props;
2389
+ /** @type {((anchor: Node) => void)} */
2390
+ #children;
2391
+ /** @type {Effect} */
2392
+ #effect;
2393
+ /** @type {Effect | null} */
2394
+ #main_effect = null;
2395
+ /** @type {Effect | null} */
2396
+ #pending_effect = null;
2397
+ /** @type {Effect | null} */
2398
+ #failed_effect = null;
2399
+ /** @type {DocumentFragment | null} */
2400
+ #offscreen_fragment = null;
2401
+ #local_pending_count = 0;
2402
+ #pending_count = 0;
2403
+ #pending_count_update_queued = false;
2404
+ /** @type {Set<Effect>} */
2405
+ #dirty_effects = /* @__PURE__ */ new Set();
2406
+ /** @type {Set<Effect>} */
2407
+ #maybe_dirty_effects = /* @__PURE__ */ new Set();
2408
+ /**
2409
+ * A source containing the number of pending async deriveds/expressions.
2410
+ * Only created if `$effect.pending()` is used inside the boundary,
2411
+ * otherwise updating the source results in needless `Batch.ensure()`
2412
+ * calls followed by no-op flushes
2413
+ * @type {Source<number> | null}
2414
+ */
2415
+ #effect_pending = null;
2416
+ #effect_pending_subscriber = createSubscriber(() => {
2417
+ this.#effect_pending = source(this.#local_pending_count);
2418
+ return () => {
2419
+ this.#effect_pending = null;
2420
+ };
2421
+ });
2422
+ /**
2423
+ * @param {TemplateNode} node
2424
+ * @param {BoundaryProps} props
2425
+ * @param {((anchor: Node) => void)} children
2426
+ * @param {((error: unknown) => unknown) | undefined} [transform_error]
2427
+ */
2428
+ constructor(node, props, children, transform_error) {
2429
+ this.#anchor = node;
2430
+ this.#props = props;
2431
+ this.#children = (anchor) => {
2432
+ var effect = (
2433
+ /** @type {Effect} */
2434
+ active_effect
2435
+ );
2436
+ effect.b = this;
2437
+ effect.f |= BOUNDARY_EFFECT;
2438
+ children(anchor);
2439
+ };
2440
+ this.parent = /** @type {Effect} */
2441
+ active_effect.b;
2442
+ this.transform_error = transform_error ?? this.parent?.transform_error ?? ((e) => e);
2443
+ this.#effect = block(() => {
2444
+ if (hydrating) {
2445
+ const comment = (
2446
+ /** @type {Comment} */
2447
+ this.#hydrate_open
2448
+ );
2449
+ hydrate_next();
2450
+ const server_rendered_pending = comment.data === HYDRATION_START_ELSE;
2451
+ const server_rendered_failed = comment.data.startsWith(HYDRATION_START_FAILED);
2452
+ if (server_rendered_failed) {
2453
+ const serialized_error = JSON.parse(comment.data.slice(HYDRATION_START_FAILED.length));
2454
+ this.#hydrate_failed_content(serialized_error);
2455
+ } else if (server_rendered_pending) {
2456
+ this.#hydrate_pending_content();
2457
+ } else {
2458
+ this.#hydrate_resolved_content();
2459
+ }
2460
+ } else {
2461
+ this.#render();
2462
+ }
2463
+ }, flags);
2464
+ if (hydrating) {
2465
+ this.#anchor = hydrate_node;
2466
+ }
2467
+ }
2468
+ #hydrate_resolved_content() {
2469
+ try {
2470
+ this.#main_effect = branch(() => this.#children(this.#anchor));
2471
+ } catch (error) {
2472
+ this.error(error);
2473
+ }
2474
+ }
2475
+ /**
2476
+ * @param {unknown} error The deserialized error from the server's hydration comment
2477
+ */
2478
+ #hydrate_failed_content(error) {
2479
+ const failed = this.#props.failed;
2480
+ const { reset, invoke_onerror } = this.#create_reset(error);
2481
+ queue_micro_task(invoke_onerror);
2482
+ if (!failed) return;
2483
+ this.#failed_effect = branch(() => {
2484
+ failed(
2485
+ this.#anchor,
2486
+ () => error,
2487
+ () => reset
2488
+ );
2489
+ });
2490
+ }
2491
+ /**
2492
+ * Creates the `reset` function for a failed boundary, along with a function
2493
+ * that invokes `onerror` with it (if provided)
2494
+ * @param {unknown} error
2495
+ * @returns {{ reset: () => void, invoke_onerror: () => void }}
2496
+ */
2497
+ #create_reset(error) {
2498
+ var did_reset = false;
2499
+ var calling_on_error = false;
2500
+ const reset = () => {
2501
+ if (did_reset) {
2502
+ svelte_boundary_reset_noop();
2503
+ return;
2504
+ }
2505
+ did_reset = true;
2506
+ if (calling_on_error) {
2507
+ svelte_boundary_reset_onerror();
2508
+ }
2509
+ if (this.#failed_effect !== null) {
2510
+ pause_effect(this.#failed_effect, () => {
2511
+ this.#failed_effect = null;
2512
+ });
2513
+ }
2514
+ this.#run(() => {
2515
+ this.#render();
2516
+ });
2517
+ };
2518
+ const invoke_onerror = () => {
2519
+ try {
2520
+ calling_on_error = true;
2521
+ this.#props.onerror?.(error, reset);
2522
+ calling_on_error = false;
2523
+ } catch (err) {
2524
+ invoke_error_boundary(err, this.#effect && this.#effect.parent);
2525
+ }
2526
+ };
2527
+ return { reset, invoke_onerror };
2528
+ }
2529
+ #hydrate_pending_content() {
2530
+ const pending = this.#props.pending;
2531
+ if (!pending) return;
2532
+ this.is_pending = true;
2533
+ this.#pending_effect = branch(() => pending(this.#anchor));
2534
+ queue_micro_task(() => {
2535
+ var fragment = this.#offscreen_fragment = document.createDocumentFragment();
2536
+ var anchor = create_text();
2537
+ var handled = false;
2538
+ fragment.append(anchor);
2539
+ this.#main_effect = this.#run(() => {
2540
+ try {
2541
+ return branch(() => this.#children(anchor));
2542
+ } catch (error) {
2543
+ try {
2544
+ this.error(error);
2545
+ handled = true;
2546
+ } catch (error2) {
2547
+ invoke_error_boundary(error2, this.#effect.parent);
2548
+ }
2549
+ return null;
2550
+ }
2551
+ });
2552
+ if (this.#main_effect === null) {
2553
+ this.#offscreen_fragment = null;
2554
+ if (handled) this.#resolve(
2555
+ /** @type {Batch} */
2556
+ current_batch
2557
+ );
2558
+ return;
2559
+ }
2560
+ if (this.#pending_count === 0) {
2561
+ this.#anchor.before(fragment);
2562
+ this.#offscreen_fragment = null;
2563
+ pause_effect(
2564
+ /** @type {Effect} */
2565
+ this.#pending_effect,
2566
+ () => {
2567
+ this.#pending_effect = null;
2568
+ }
2569
+ );
2570
+ this.#resolve(
2571
+ /** @type {Batch} */
2572
+ current_batch
2573
+ );
2574
+ }
2575
+ });
2576
+ }
2577
+ #render() {
2578
+ try {
2579
+ this.is_pending = this.has_pending_snippet();
2580
+ this.#pending_count = 0;
2581
+ this.#local_pending_count = 0;
2582
+ this.#main_effect = branch(() => {
2583
+ this.#children(this.#anchor);
2584
+ });
2585
+ if (this.#pending_count > 0) {
2586
+ var fragment = this.#offscreen_fragment = document.createDocumentFragment();
2587
+ move_effect(this.#main_effect, fragment);
2588
+ const pending = (
2589
+ /** @type {(anchor: Node) => void} */
2590
+ this.#props.pending
2591
+ );
2592
+ this.#pending_effect = branch(() => pending(this.#anchor));
2593
+ } else {
2594
+ this.#resolve(
2595
+ /** @type {Batch} */
2596
+ current_batch
2597
+ );
2598
+ }
2599
+ } catch (error) {
2600
+ this.error(error);
2601
+ }
2602
+ }
2603
+ /**
2604
+ * @param {Batch} batch
2605
+ */
2606
+ #resolve(batch) {
2607
+ this.is_pending = false;
2608
+ batch.transfer_effects(this.#dirty_effects, this.#maybe_dirty_effects);
2609
+ }
2610
+ /**
2611
+ * Defer an effect inside a pending boundary until the boundary resolves
2612
+ * @param {Effect} effect
2613
+ */
2614
+ defer_effect(effect) {
2615
+ defer_effect(effect, this.#dirty_effects, this.#maybe_dirty_effects);
2616
+ }
2617
+ /**
2618
+ * Returns `false` if the effect exists inside a boundary whose pending snippet is shown
2619
+ * @returns {boolean}
2620
+ */
2621
+ is_rendered() {
2622
+ return !this.is_pending && (!this.parent || this.parent.is_rendered());
2623
+ }
2624
+ has_pending_snippet() {
2625
+ return !!this.#props.pending;
2626
+ }
2627
+ /**
2628
+ * @template T
2629
+ * @param {() => T} fn
2630
+ */
2631
+ #run(fn) {
2632
+ var previous_effect = active_effect;
2633
+ var previous_reaction = active_reaction;
2634
+ var previous_ctx = component_context;
2635
+ set_active_effect(this.#effect);
2636
+ set_active_reaction(this.#effect);
2637
+ set_component_context(this.#effect.ctx);
2638
+ try {
2639
+ Batch.ensure();
2640
+ return fn();
2641
+ } finally {
2642
+ set_active_effect(previous_effect);
2643
+ set_active_reaction(previous_reaction);
2644
+ set_component_context(previous_ctx);
2645
+ }
2646
+ }
2647
+ /**
2648
+ * Updates the pending count associated with the currently visible pending snippet,
2649
+ * if any, such that we can replace the snippet with content once work is done
2650
+ * @param {1 | -1} d
2651
+ * @param {Batch} batch
2652
+ */
2653
+ #update_pending_count(d, batch) {
2654
+ if (!this.has_pending_snippet()) {
2655
+ if (this.parent) {
2656
+ this.parent.#update_pending_count(d, batch);
2657
+ }
2658
+ return;
2659
+ }
2660
+ this.#pending_count += d;
2661
+ if (this.#pending_count === 0) {
2662
+ this.#resolve(batch);
2663
+ if (this.#pending_effect) {
2664
+ pause_effect(this.#pending_effect, () => {
2665
+ this.#pending_effect = null;
2666
+ });
2667
+ }
2668
+ if (this.#offscreen_fragment) {
2669
+ this.#anchor.before(this.#offscreen_fragment);
2670
+ this.#offscreen_fragment = null;
2671
+ }
2672
+ }
2673
+ }
2674
+ /**
2675
+ * Update the source that powers `$effect.pending()` inside this boundary,
2676
+ * and controls when the current `pending` snippet (if any) is removed.
2677
+ * Do not call from inside the class
2678
+ * @param {1 | -1} d
2679
+ * @param {Batch} batch
2680
+ */
2681
+ update_pending_count(d, batch) {
2682
+ this.#update_pending_count(d, batch);
2683
+ this.#local_pending_count += d;
2684
+ if (!this.#effect_pending || this.#pending_count_update_queued) return;
2685
+ this.#pending_count_update_queued = true;
2686
+ queue_micro_task(() => {
2687
+ this.#pending_count_update_queued = false;
2688
+ if (this.#effect_pending) {
2689
+ internal_set(this.#effect_pending, this.#local_pending_count);
2690
+ }
2691
+ });
2692
+ }
2693
+ get_effect_pending() {
2694
+ this.#effect_pending_subscriber();
2695
+ return get(
2696
+ /** @type {Source<number>} */
2697
+ this.#effect_pending
2698
+ );
2699
+ }
2700
+ /** @param {unknown} error */
2701
+ error(error) {
2702
+ if (!this.#props.onerror && !this.#props.failed) {
2703
+ throw error;
2704
+ }
2705
+ if (current_batch?.is_fork) {
2706
+ if (this.#main_effect) current_batch.skip_effect(this.#main_effect);
2707
+ if (this.#pending_effect) current_batch.skip_effect(this.#pending_effect);
2708
+ if (this.#failed_effect) current_batch.skip_effect(this.#failed_effect);
2709
+ current_batch.oncommit(() => {
2710
+ this.#handle_error(error);
2711
+ });
2712
+ } else {
2713
+ this.#handle_error(error);
2714
+ }
2715
+ }
2716
+ /**
2717
+ * @param {unknown} error
2718
+ */
2719
+ #handle_error(error) {
2720
+ if (this.#main_effect) {
2721
+ destroy_effect(this.#main_effect);
2722
+ this.#main_effect = null;
2723
+ }
2724
+ if (this.#pending_effect) {
2725
+ destroy_effect(this.#pending_effect);
2726
+ this.#pending_effect = null;
2727
+ }
2728
+ if (this.#failed_effect) {
2729
+ destroy_effect(this.#failed_effect);
2730
+ this.#failed_effect = null;
2731
+ }
2732
+ if (hydrating) {
2733
+ set_hydrate_node(
2734
+ /** @type {TemplateNode} */
2735
+ this.#hydrate_open
2736
+ );
2737
+ next();
2738
+ set_hydrate_node(skip_nodes());
2739
+ }
2740
+ let failed = this.#props.failed;
2741
+ const handle_error_result = (transformed_error) => {
2742
+ const { reset, invoke_onerror } = this.#create_reset(transformed_error);
2743
+ invoke_onerror();
2744
+ if (failed) {
2745
+ this.#failed_effect = this.#run(() => {
2746
+ try {
2747
+ return branch(() => {
2748
+ var effect = (
2749
+ /** @type {Effect} */
2750
+ active_effect
2751
+ );
2752
+ effect.b = this;
2753
+ effect.f |= BOUNDARY_EFFECT;
2754
+ failed(
2755
+ this.#anchor,
2756
+ () => transformed_error,
2757
+ () => reset
2758
+ );
2759
+ });
2760
+ } catch (error2) {
2761
+ invoke_error_boundary(
2762
+ error2,
2763
+ /** @type {Effect} */
2764
+ this.#effect.parent
2765
+ );
2766
+ return null;
2767
+ }
2768
+ });
2769
+ }
2770
+ };
2771
+ queue_micro_task(() => {
2772
+ var result;
2773
+ try {
2774
+ result = this.transform_error(error);
2775
+ } catch (e) {
2776
+ invoke_error_boundary(e, this.#effect && this.#effect.parent);
2777
+ return;
2778
+ }
2779
+ if (result !== null && typeof result === "object" && typeof /** @type {any} */
2780
+ result.then === "function") {
2781
+ result.then(
2782
+ handle_error_result,
2783
+ /** @param {unknown} e */
2784
+ (e) => invoke_error_boundary(e, this.#effect && this.#effect.parent)
2785
+ );
2786
+ } else {
2787
+ handle_error_result(result);
2788
+ }
2789
+ });
2790
+ }
2791
+ }
2792
+ function mount(component, options) {
2793
+ return _mount(component, options);
2794
+ }
2795
+ function hydrate(component, options) {
2796
+ init_operations();
2797
+ options.intro = options.intro ?? false;
2798
+ const target = options.target;
2799
+ const was_hydrating = hydrating;
2800
+ const previous_hydrate_node = hydrate_node;
2801
+ try {
2802
+ var anchor = /* @__PURE__ */ get_first_child(target);
2803
+ while (anchor && (anchor.nodeType !== COMMENT_NODE || /** @type {Comment} */
2804
+ anchor.data !== HYDRATION_START)) {
2805
+ anchor = /* @__PURE__ */ get_next_sibling(anchor);
2806
+ }
2807
+ if (!anchor) {
2808
+ throw HYDRATION_ERROR;
2809
+ }
2810
+ set_hydrating(true);
2811
+ set_hydrate_node(
2812
+ /** @type {Comment} */
2813
+ anchor
2814
+ );
2815
+ const instance = _mount(component, { ...options, anchor });
2816
+ set_hydrating(false);
2817
+ return (
2818
+ /** @type {Exports} */
2819
+ instance
2820
+ );
2821
+ } catch (error) {
2822
+ if (error instanceof Error && error.message.split("\n").some((line) => line.startsWith("https://svelte.dev/e/"))) {
2823
+ throw error;
2824
+ }
2825
+ if (error !== HYDRATION_ERROR) {
2826
+ console.warn("Failed to hydrate: ", error);
2827
+ }
2828
+ if (options.recover === false) {
2829
+ hydration_failed();
2830
+ }
2831
+ init_operations();
2832
+ clear_text_content(target);
2833
+ set_hydrating(false);
2834
+ return mount(component, options);
2835
+ } finally {
2836
+ set_hydrating(was_hydrating);
2837
+ set_hydrate_node(previous_hydrate_node);
2838
+ }
2839
+ }
2840
+ const listeners = /* @__PURE__ */ new Map();
2841
+ function _mount(Component, { target, anchor, props = {}, events, context, intro = true, transformError }) {
2842
+ init_operations();
2843
+ var component = void 0;
2844
+ var unmount2 = component_root(() => {
2845
+ var anchor_node = anchor ?? target.appendChild(create_text());
2846
+ boundary(
2847
+ /** @type {TemplateNode} */
2848
+ anchor_node,
2849
+ {
2850
+ pending: () => {
2851
+ }
2852
+ },
2853
+ (anchor_node2) => {
2854
+ push$1({});
2855
+ var ctx = (
2856
+ /** @type {ComponentContext} */
2857
+ component_context
2858
+ );
2859
+ if (context) ctx.c = context;
2860
+ if (events) {
2861
+ props.$$events = events;
2862
+ }
2863
+ if (hydrating) {
2864
+ assign_nodes(
2865
+ /** @type {TemplateNode} */
2866
+ anchor_node2,
2867
+ null
2868
+ );
2869
+ }
2870
+ component = Component(anchor_node2, props) || mark_as_component();
2871
+ if (hydrating) {
2872
+ active_effect.nodes.end = hydrate_node;
2873
+ if (hydrate_node === null || hydrate_node.nodeType !== COMMENT_NODE || /** @type {Comment} */
2874
+ hydrate_node.data !== HYDRATION_END) {
2875
+ hydration_mismatch();
2876
+ throw HYDRATION_ERROR;
2877
+ }
2878
+ }
2879
+ pop$1();
2880
+ },
2881
+ transformError
2882
+ );
2883
+ var registered_events = /* @__PURE__ */ new Set();
2884
+ var event_handle = (events2) => {
2885
+ for (var i = 0; i < events2.length; i++) {
2886
+ var event_name = events2[i];
2887
+ if (registered_events.has(event_name)) continue;
2888
+ registered_events.add(event_name);
2889
+ var passive = is_passive_event(event_name);
2890
+ for (const node of [target, document]) {
2891
+ var counts = listeners.get(node);
2892
+ if (counts === void 0) {
2893
+ counts = /* @__PURE__ */ new Map();
2894
+ listeners.set(node, counts);
2895
+ }
2896
+ var count = counts.get(event_name);
2897
+ if (count === void 0) {
2898
+ node.addEventListener(event_name, handle_event_propagation, { passive });
2899
+ counts.set(event_name, 1);
2900
+ } else {
2901
+ counts.set(event_name, count + 1);
2902
+ }
2903
+ }
2904
+ }
2905
+ };
2906
+ event_handle(array_from(all_registered_events));
2907
+ root_event_handles.add(event_handle);
2908
+ return () => {
2909
+ for (var event_name of registered_events) {
2910
+ for (const node of [target, document]) {
2911
+ var counts = (
2912
+ /** @type {Map<string, number>} */
2913
+ listeners.get(node)
2914
+ );
2915
+ var count = (
2916
+ /** @type {number} */
2917
+ counts.get(event_name)
2918
+ );
2919
+ if (--count == 0) {
2920
+ node.removeEventListener(event_name, handle_event_propagation);
2921
+ counts.delete(event_name);
2922
+ if (counts.size === 0) {
2923
+ listeners.delete(node);
2924
+ }
2925
+ } else {
2926
+ counts.set(event_name, count);
2927
+ }
2928
+ }
2929
+ }
2930
+ root_event_handles.delete(event_handle);
2931
+ if (anchor_node !== anchor) {
2932
+ anchor_node.parentNode?.removeChild(anchor_node);
2933
+ }
2934
+ };
2935
+ });
2936
+ mounted_components.set(component, unmount2);
2937
+ return component;
2938
+ }
2939
+ let mounted_components = /* @__PURE__ */ new WeakMap();
2940
+ function unmount(component, options) {
2941
+ const fn = mounted_components.get(component);
2942
+ if (fn) {
2943
+ mounted_components.delete(component);
2944
+ return fn(options);
2945
+ }
2946
+ return Promise.resolve();
2947
+ }
2948
+ function asClassComponent$1(component) {
2949
+ return class extends Svelte4Component {
2950
+ /** @param {any} options */
2951
+ constructor(options) {
2952
+ super({
2953
+ component,
2954
+ ...options
2955
+ });
2956
+ }
2957
+ };
2958
+ }
2959
+ class Svelte4Component {
2960
+ /** @type {any} */
2961
+ #events;
2962
+ /** @type {Record<string, any>} */
2963
+ #instance;
2964
+ /**
2965
+ * @param {ComponentConstructorOptions & {
2966
+ * component: any;
2967
+ * }} options
2968
+ */
2969
+ constructor(options) {
2970
+ var sources = /* @__PURE__ */ new Map();
2971
+ var add_source = (key, value) => {
2972
+ var s = /* @__PURE__ */ mutable_source(value, false, false);
2973
+ sources.set(key, s);
2974
+ return s;
2975
+ };
2976
+ const props = new Proxy(
2977
+ { ...options.props || {}, $$events: {} },
2978
+ {
2979
+ get(target, prop) {
2980
+ return get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
2981
+ },
2982
+ has(target, prop) {
2983
+ if (prop === LEGACY_PROPS) return true;
2984
+ get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
2985
+ return Reflect.has(target, prop);
2986
+ },
2987
+ set(target, prop, value) {
2988
+ set(sources.get(prop) ?? add_source(prop, value), value);
2989
+ return Reflect.set(target, prop, value);
2990
+ }
2991
+ }
2992
+ );
2993
+ this.#instance = (options.hydrate ? hydrate : mount)(options.component, {
2994
+ target: options.target,
2995
+ anchor: options.anchor,
2996
+ props,
2997
+ context: options.context,
2998
+ intro: options.intro ?? false,
2999
+ recover: options.recover,
3000
+ transformError: options.transformError
3001
+ });
3002
+ if (!options?.props?.$$host || options.sync === false) {
3003
+ flushSync();
3004
+ }
3005
+ this.#events = props.$$events;
3006
+ for (const key of Object.keys(this.#instance)) {
3007
+ if (key === "$set" || key === "$destroy" || key === "$on") continue;
3008
+ define_property(this, key, {
3009
+ get() {
3010
+ return this.#instance[key];
3011
+ },
3012
+ /** @param {any} value */
3013
+ set(value) {
3014
+ this.#instance[key] = value;
3015
+ },
3016
+ enumerable: true
3017
+ });
3018
+ }
3019
+ this.#instance.$set = /** @param {Record<string, any>} next */
3020
+ (next2) => {
3021
+ Object.assign(props, next2);
3022
+ };
3023
+ this.#instance.$destroy = () => {
3024
+ unmount(this.#instance);
3025
+ };
3026
+ }
3027
+ /** @param {Record<string, any>} props */
3028
+ $set(props) {
3029
+ this.#instance.$set(props);
3030
+ }
3031
+ /**
3032
+ * @param {string} event
3033
+ * @param {(...args: any[]) => any} callback
3034
+ * @returns {any}
3035
+ */
3036
+ $on(event, callback) {
3037
+ this.#events[event] = this.#events[event] || [];
3038
+ const cb = (...args) => callback.call(this, ...args);
3039
+ this.#events[event].push(cb);
3040
+ return () => {
3041
+ this.#events[event] = this.#events[event].filter(
3042
+ /** @param {any} fn */
3043
+ (fn) => fn !== cb
3044
+ );
3045
+ };
3046
+ }
3047
+ $destroy() {
3048
+ this.#instance.$destroy();
3049
+ }
3050
+ }
3051
+ const ATTR_REGEX = /[&"<]/g;
3052
+ const CONTENT_REGEX = /[&<]/g;
3053
+ function escape_html(value, is_attr) {
3054
+ const str = String(value ?? "");
3055
+ const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX;
3056
+ pattern.lastIndex = 0;
3057
+ let escaped = "";
3058
+ let last = 0;
3059
+ while (pattern.test(str)) {
3060
+ const i = pattern.lastIndex - 1;
3061
+ const ch = str[i];
3062
+ escaped += str.substring(last, i) + (ch === "&" ? "&amp;" : ch === '"' ? "&quot;" : "&lt;");
3063
+ last = i + 1;
3064
+ }
3065
+ return escaped + str.substring(last);
3066
+ }
3067
+ function r(e) {
3068
+ var t, f, n = "";
3069
+ if ("string" == typeof e || "number" == typeof e) n += e;
3070
+ else if ("object" == typeof e) if (Array.isArray(e)) {
3071
+ var o = e.length;
3072
+ for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
3073
+ } else for (f in e) e[f] && (n && (n += " "), n += f);
3074
+ return n;
3075
+ }
3076
+ function clsx$1() {
3077
+ for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
3078
+ return n;
3079
+ }
3080
+ const replacements = {
3081
+ translate: /* @__PURE__ */ new Map([
3082
+ [true, "yes"],
3083
+ [false, "no"]
3084
+ ])
3085
+ };
3086
+ function attr(name, value, is_boolean = false) {
3087
+ if (name === "hidden" && value !== "until-found") {
3088
+ is_boolean = true;
3089
+ }
3090
+ if (value == null || is_boolean && !value && value !== "") return "";
3091
+ const normalized = has_own_property.call(replacements, name) && replacements[name].get(value) || value;
3092
+ const assignment = is_boolean ? `=""` : `="${escape_html(normalized, true)}"`;
3093
+ return ` ${name}${assignment}`;
3094
+ }
3095
+ function clsx(value) {
3096
+ if (typeof value === "object") {
3097
+ return clsx$1(value);
3098
+ } else {
3099
+ return value ?? "";
3100
+ }
3101
+ }
3102
+ const whitespace = [..." \n\r\f \v\uFEFF"];
3103
+ function to_class(value, hash, directives) {
3104
+ var classname = value == null ? "" : "" + value;
3105
+ if (hash) {
3106
+ classname = classname ? classname + " " + hash : hash;
3107
+ }
3108
+ if (directives) {
3109
+ for (var key of Object.keys(directives)) {
3110
+ if (directives[key]) {
3111
+ classname = classname ? classname + " " + key : key;
3112
+ } else if (classname.length) {
3113
+ var len = key.length;
3114
+ var a = 0;
3115
+ while ((a = classname.indexOf(key, a)) >= 0) {
3116
+ var b = a + len;
3117
+ if ((a === 0 || whitespace.includes(classname[a - 1])) && (b === classname.length || whitespace.includes(classname[b]))) {
3118
+ classname = (a === 0 ? "" : classname.substring(0, a)) + classname.substring(b + 1);
3119
+ } else {
3120
+ a = b;
3121
+ }
3122
+ }
3123
+ }
3124
+ }
3125
+ }
3126
+ return classname === "" ? null : classname;
3127
+ }
3128
+ function append_styles(styles, important = false) {
3129
+ var separator = important ? " !important;" : ";";
3130
+ var css = "";
3131
+ for (var key of Object.keys(styles)) {
3132
+ var value = styles[key];
3133
+ if (value != null && value !== "") {
3134
+ css += " " + key + ": " + value + separator;
3135
+ }
3136
+ }
3137
+ return css;
3138
+ }
3139
+ function to_css_name(name) {
3140
+ if (name[0] !== "-" || name[1] !== "-") {
3141
+ return name.toLowerCase();
3142
+ }
3143
+ return name;
3144
+ }
3145
+ function to_style(value, styles) {
3146
+ if (styles) {
3147
+ var new_style = "";
3148
+ var normal_styles;
3149
+ var important_styles;
3150
+ if (Array.isArray(styles)) {
3151
+ normal_styles = styles[0];
3152
+ important_styles = styles[1];
3153
+ } else {
3154
+ normal_styles = styles;
3155
+ }
3156
+ if (value) {
3157
+ value = String(value).replaceAll(/\/\*.*?\*\//g, "").trim();
3158
+ var in_str = false;
3159
+ var in_apo = 0;
3160
+ var in_comment = false;
3161
+ var reserved_names = [];
3162
+ if (normal_styles) {
3163
+ reserved_names.push(...Object.keys(normal_styles).map(to_css_name));
3164
+ }
3165
+ if (important_styles) {
3166
+ reserved_names.push(...Object.keys(important_styles).map(to_css_name));
3167
+ }
3168
+ var start_index = 0;
3169
+ var name_index = -1;
3170
+ const len = value.length;
3171
+ for (var i = 0; i < len; i++) {
3172
+ var c = value[i];
3173
+ if (in_comment) {
3174
+ if (c === "/" && value[i - 1] === "*") {
3175
+ in_comment = false;
3176
+ }
3177
+ } else if (in_str) {
3178
+ if (in_str === c) {
3179
+ in_str = false;
3180
+ }
3181
+ } else if (c === "/" && value[i + 1] === "*") {
3182
+ in_comment = true;
3183
+ } else if (c === '"' || c === "'") {
3184
+ in_str = c;
3185
+ } else if (c === "(") {
3186
+ in_apo++;
3187
+ } else if (c === ")") {
3188
+ in_apo--;
3189
+ }
3190
+ if (!in_comment && in_str === false && in_apo === 0) {
3191
+ if (c === ":" && name_index === -1) {
3192
+ name_index = i;
3193
+ } else if (c === ";" || i === len - 1) {
3194
+ if (name_index !== -1) {
3195
+ var name = to_css_name(value.substring(start_index, name_index).trim());
3196
+ if (!reserved_names.includes(name)) {
3197
+ if (c !== ";") {
3198
+ i++;
3199
+ }
3200
+ var property = value.substring(start_index, i).trim();
3201
+ new_style += " " + property + ";";
3202
+ }
3203
+ }
3204
+ start_index = i + 1;
3205
+ name_index = -1;
3206
+ }
3207
+ }
3208
+ }
3209
+ }
3210
+ if (normal_styles) {
3211
+ new_style += append_styles(normal_styles);
3212
+ }
3213
+ if (important_styles) {
3214
+ new_style += append_styles(important_styles, true);
3215
+ }
3216
+ new_style = new_style.trim();
3217
+ return new_style === "" ? null : new_style;
3218
+ }
3219
+ return value == null ? null : String(value);
3220
+ }
3221
+ const BLOCK_OPEN = `<!--${HYDRATION_START}-->`;
3222
+ const BLOCK_CLOSE = `<!--${HYDRATION_END}-->`;
3223
+ const EMPTY_COMMENT = `<!---->`;
3224
+ var ssr_context = null;
3225
+ function set_ssr_context(v) {
3226
+ ssr_context = v;
3227
+ }
3228
+ function getContext(key) {
3229
+ const context_map = get_or_init_context_map(ssr_context);
3230
+ const result = (
3231
+ /** @type {T} */
3232
+ context_map.get(key)
3233
+ );
3234
+ return result;
3235
+ }
3236
+ function setContext(key, context) {
3237
+ get_or_init_context_map(ssr_context).set(key, context);
3238
+ return context;
3239
+ }
3240
+ function push(fn) {
3241
+ ssr_context = { p: ssr_context, c: null, r: null };
3242
+ }
3243
+ function pop() {
3244
+ ssr_context = /** @type {SSRContext} */
3245
+ ssr_context.p;
3246
+ }
3247
+ function await_invalid() {
3248
+ const error = new Error(`await_invalid
3249
+ Encountered asynchronous work while rendering synchronously.
3250
+ https://svelte.dev/e/await_invalid`);
3251
+ error.name = "Svelte error";
3252
+ throw error;
3253
+ }
3254
+ function invalid_csp() {
3255
+ const error = new Error(`invalid_csp
3256
+ \`csp.nonce\` was set while \`csp.hash\` was \`true\`. These options cannot be used simultaneously.
3257
+ https://svelte.dev/e/invalid_csp`);
3258
+ error.name = "Svelte error";
3259
+ throw error;
3260
+ }
3261
+ function invalid_id_prefix() {
3262
+ const error = new Error(`invalid_id_prefix
3263
+ The \`idPrefix\` option cannot include \`--\`.
3264
+ https://svelte.dev/e/invalid_id_prefix`);
3265
+ error.name = "Svelte error";
3266
+ throw error;
3267
+ }
3268
+ function server_context_required() {
3269
+ const error = new Error(`server_context_required
3270
+ Could not resolve \`render\` context.
3271
+ https://svelte.dev/e/server_context_required`);
3272
+ error.name = "Svelte error";
3273
+ throw error;
3274
+ }
3275
+ function unresolved_hydratable(key, stack) {
3276
+ {
3277
+ console.warn(`https://svelte.dev/e/unresolved_hydratable`);
3278
+ }
3279
+ }
3280
+ function get_render_context() {
3281
+ const store = als?.getStore();
3282
+ {
3283
+ server_context_required();
3284
+ }
3285
+ return store;
3286
+ }
3287
+ let als = null;
3288
+ let text_encoder;
3289
+ let crypto;
3290
+ const obfuscated_import = (module_name) => import(
3291
+ /* @vite-ignore */
3292
+ module_name
3293
+ );
3294
+ async function sha256(data) {
3295
+ text_encoder ??= new TextEncoder();
3296
+ crypto ??= globalThis.crypto?.subtle?.digest ? globalThis.crypto : (
3297
+ // @ts-ignore - we don't install node types in the prod build
3298
+ // don't use import('node:crypto') directly because static analysers will think we rely on node when we don't
3299
+ (await obfuscated_import("node:crypto")).webcrypto
3300
+ );
3301
+ const hash_buffer = await crypto.subtle.digest("SHA-256", text_encoder.encode(data));
3302
+ return base64_encode(hash_buffer);
3303
+ }
3304
+ function base64_encode(bytes) {
3305
+ if (globalThis.Buffer) {
3306
+ return globalThis.Buffer.from(bytes).toString("base64");
3307
+ }
3308
+ let binary = "";
3309
+ for (let i = 0; i < bytes.length; i++) {
3310
+ binary += String.fromCharCode(bytes[i]);
3311
+ }
3312
+ return btoa(binary);
3313
+ }
3314
+ class Renderer {
3315
+ /**
3316
+ * The contents of the renderer.
3317
+ * @type {RendererItem[]}
3318
+ */
3319
+ #out = [];
3320
+ /**
3321
+ * Any `onDestroy` callbacks registered during execution of this renderer.
3322
+ * @type {(() => void)[] | undefined}
3323
+ */
3324
+ #on_destroy = void 0;
3325
+ /**
3326
+ * Whether this renderer is a component body.
3327
+ * @type {boolean}
3328
+ */
3329
+ #is_component_body = false;
3330
+ /**
3331
+ * If set, this renderer is an error boundary. When async collection
3332
+ * of the children fails, the failed snippet is rendered instead.
3333
+ * @type {{
3334
+ * failed: (renderer: Renderer, error: unknown, reset: () => void) => void;
3335
+ * transformError: (error: unknown) => unknown;
3336
+ * context: SSRContext | null;
3337
+ * } | null}
3338
+ */
3339
+ #boundary = null;
3340
+ /**
3341
+ * The type of string content that this renderer is accumulating.
3342
+ * @type {RendererType}
3343
+ */
3344
+ type;
3345
+ /** @type {Renderer | undefined} */
3346
+ #parent;
3347
+ /**
3348
+ * Asynchronous work associated with this renderer
3349
+ * @type {Promise<void> | undefined}
3350
+ */
3351
+ promise = void 0;
3352
+ /**
3353
+ * State which is associated with the content tree as a whole.
3354
+ * It will be re-exposed, uncopied, on all children.
3355
+ * @type {SSRState}
3356
+ * @readonly
3357
+ */
3358
+ global;
3359
+ /**
3360
+ * State that is local to the branch it is declared in.
3361
+ * It will be shallow-copied to all children.
3362
+ *
3363
+ * @type {{ select_value: any, multiple: boolean }}
3364
+ */
3365
+ local;
3366
+ /**
3367
+ * @param {SSRState} global
3368
+ * @param {Renderer | undefined} [parent]
3369
+ */
3370
+ constructor(global, parent) {
3371
+ this.#parent = parent;
3372
+ this.global = global;
3373
+ this.local = parent ? { ...parent.local } : { select_value: void 0, multiple: false };
3374
+ this.type = parent ? parent.type : "body";
3375
+ }
3376
+ /**
3377
+ * @param {(renderer: Renderer) => void} fn
3378
+ */
3379
+ head(fn) {
3380
+ const head2 = new Renderer(this.global, this);
3381
+ head2.type = "head";
3382
+ this.#out.push(head2);
3383
+ head2.child(fn);
3384
+ }
3385
+ /**
3386
+ * @param {Array<Promise<void>>} blockers
3387
+ * @param {(renderer: Renderer) => void} fn
3388
+ */
3389
+ async_block(blockers, fn) {
3390
+ this.#out.push(BLOCK_OPEN);
3391
+ this.async(blockers, fn);
3392
+ this.#out.push(BLOCK_CLOSE);
3393
+ }
3394
+ /**
3395
+ * @param {Array<Promise<void>>} blockers
3396
+ * @param {(renderer: Renderer) => void} fn
3397
+ */
3398
+ async(blockers, fn) {
3399
+ let callback = fn;
3400
+ if (blockers.length > 0) {
3401
+ const context = ssr_context;
3402
+ callback = (renderer) => {
3403
+ return Promise.all(blockers).then(() => {
3404
+ const previous_context = ssr_context;
3405
+ try {
3406
+ set_ssr_context(context);
3407
+ return fn(renderer);
3408
+ } finally {
3409
+ set_ssr_context(previous_context);
3410
+ }
3411
+ });
3412
+ };
3413
+ }
3414
+ this.child(callback);
3415
+ }
3416
+ /**
3417
+ * @param {Array<() => void>} thunks
3418
+ */
3419
+ run(thunks) {
3420
+ const context = ssr_context;
3421
+ let promise = Promise.resolve(thunks[0]());
3422
+ const promises = [promise];
3423
+ for (const fn of thunks.slice(1)) {
3424
+ promise = promise.then(() => {
3425
+ const previous_context = ssr_context;
3426
+ set_ssr_context(context);
3427
+ try {
3428
+ return fn();
3429
+ } finally {
3430
+ set_ssr_context(previous_context);
3431
+ }
3432
+ });
3433
+ promises.push(promise);
3434
+ }
3435
+ promise.catch(noop);
3436
+ this.promise = this.global.track(promise);
3437
+ return promises;
3438
+ }
3439
+ /**
3440
+ * @param {(renderer: Renderer) => MaybePromise<void>} fn
3441
+ */
3442
+ child_block(fn) {
3443
+ this.#out.push(BLOCK_OPEN);
3444
+ this.child(fn);
3445
+ this.#out.push(BLOCK_CLOSE);
3446
+ }
3447
+ /**
3448
+ * Create a child renderer. The child renderer inherits the state from the parent,
3449
+ * but has its own content.
3450
+ * @param {(renderer: Renderer) => MaybePromise<void>} fn
3451
+ */
3452
+ child(fn) {
3453
+ const child = new Renderer(this.global, this);
3454
+ this.#out.push(child);
3455
+ const parent = ssr_context;
3456
+ set_ssr_context({
3457
+ ...ssr_context,
3458
+ p: parent,
3459
+ c: null,
3460
+ r: child
3461
+ });
3462
+ const result = fn(child);
3463
+ set_ssr_context(parent);
3464
+ if (result instanceof Promise) {
3465
+ result.catch(noop);
3466
+ result.finally(() => set_ssr_context(null)).catch(noop);
3467
+ if (child.global.mode === "sync") {
3468
+ await_invalid();
3469
+ }
3470
+ child.promise = child.global.track(result);
3471
+ }
3472
+ return child;
3473
+ }
3474
+ /**
3475
+ * Render children inside an error boundary. If the children throw and the API-level
3476
+ * `transformError` transform handles the error (doesn't re-throw), the `failed` snippet is
3477
+ * rendered instead. Otherwise the error propagates.
3478
+ *
3479
+ * @param {{ failed?: (renderer: Renderer, error: unknown, reset: () => void) => void }} props
3480
+ * @param {(renderer: Renderer) => MaybePromise<void>} children_fn
3481
+ */
3482
+ boundary(props, children_fn) {
3483
+ const child = new Renderer(this.global, this);
3484
+ this.#out.push(child);
3485
+ const parent_context = ssr_context;
3486
+ if (props.failed) {
3487
+ child.#boundary = {
3488
+ failed: props.failed,
3489
+ transformError: this.global.transformError,
3490
+ context: parent_context
3491
+ };
3492
+ }
3493
+ set_ssr_context({
3494
+ ...ssr_context,
3495
+ p: parent_context,
3496
+ c: null,
3497
+ r: child
3498
+ });
3499
+ try {
3500
+ const result = children_fn(child);
3501
+ set_ssr_context(parent_context);
3502
+ if (result instanceof Promise) {
3503
+ if (child.global.mode === "sync") {
3504
+ await_invalid();
3505
+ }
3506
+ result.catch(noop);
3507
+ child.promise = child.global.track(result);
3508
+ }
3509
+ } catch (error) {
3510
+ set_ssr_context(parent_context);
3511
+ const failed_snippet = props.failed;
3512
+ if (!failed_snippet) throw error;
3513
+ const result = this.global.transformError(error);
3514
+ child.#out.length = 0;
3515
+ child.#boundary = null;
3516
+ if (result instanceof Promise) {
3517
+ if (this.global.mode === "sync") {
3518
+ await_invalid();
3519
+ }
3520
+ child.promise = child.global.track(
3521
+ /** @type {Promise<unknown>} */
3522
+ result.then((transformed) => {
3523
+ set_ssr_context(parent_context);
3524
+ child.#out.push(Renderer.#serialize_failed_boundary(transformed));
3525
+ failed_snippet(child, transformed, noop);
3526
+ child.#out.push(BLOCK_CLOSE);
3527
+ })
3528
+ );
3529
+ child.promise.catch(noop);
3530
+ } else {
3531
+ child.#out.push(Renderer.#serialize_failed_boundary(result));
3532
+ failed_snippet(child, result, noop);
3533
+ child.#out.push(BLOCK_CLOSE);
3534
+ }
3535
+ }
3536
+ }
3537
+ /**
3538
+ * Create a component renderer. The component renderer inherits the state from the parent,
3539
+ * but has its own content. It is treated as an ordering boundary for ondestroy callbacks.
3540
+ * @param {(renderer: Renderer) => MaybePromise<void>} fn
3541
+ * @param {Function} [component_fn]
3542
+ * @returns {void}
3543
+ */
3544
+ component(fn, component_fn) {
3545
+ push();
3546
+ this.child((renderer) => {
3547
+ renderer.#is_component_body = true;
3548
+ return fn(renderer);
3549
+ });
3550
+ pop();
3551
+ }
3552
+ /**
3553
+ * @param {Record<string, any>} attrs
3554
+ * @param {(renderer: Renderer) => void} fn
3555
+ * @param {string | undefined} [css_hash]
3556
+ * @param {Record<string, boolean> | undefined} [classes]
3557
+ * @param {Record<string, string> | undefined} [styles]
3558
+ * @param {number | undefined} [flags]
3559
+ * @param {boolean | undefined} [is_rich]
3560
+ * @returns {void}
3561
+ */
3562
+ select(attrs, fn, css_hash, classes, styles, flags2, is_rich) {
3563
+ const { value, defaultValue, ...select_attrs } = attrs;
3564
+ if (select_attrs.multiple === "") select_attrs.multiple = true;
3565
+ this.push(`<select${attributes(select_attrs, css_hash, classes, styles, flags2)}>`);
3566
+ this.child((renderer) => {
3567
+ renderer.local.select_value = value === void 0 ? defaultValue : value;
3568
+ renderer.local.multiple = !!select_attrs.multiple;
3569
+ fn(renderer);
3570
+ });
3571
+ this.push(`${is_rich ? "<!>" : ""}</select>`);
3572
+ }
3573
+ /**
3574
+ * @param {Record<string, any>} attrs
3575
+ * @param {string | number | boolean | ((renderer: Renderer) => void)} body
3576
+ * @param {string | undefined} [css_hash]
3577
+ * @param {Record<string, boolean> | undefined} [classes]
3578
+ * @param {Record<string, string> | undefined} [styles]
3579
+ * @param {number | undefined} [flags]
3580
+ * @param {boolean | undefined} [is_rich]
3581
+ */
3582
+ option(attrs, body, css_hash, classes, styles, flags2, is_rich) {
3583
+ this.#out.push(`<option${attributes(attrs, css_hash, classes, styles, flags2)}`);
3584
+ const close = (renderer, value, { head: head2, body: body2 }) => {
3585
+ if (has_own_property.call(attrs, "value")) {
3586
+ value = attrs.value;
3587
+ }
3588
+ var select_value = this.local.select_value;
3589
+ if (
3590
+ // Super edge-case, but theoretically someone could use arrays with non-multiple selects,
3591
+ // so we gotta check for the multiple attribute presence, too.
3592
+ this.local.multiple && is_array(select_value) ? select_value.includes(value) : value === select_value
3593
+ ) {
3594
+ renderer.#out.push(' selected=""');
3595
+ }
3596
+ renderer.#out.push(`>${body2}${is_rich ? "<!>" : ""}</option>`);
3597
+ if (head2) {
3598
+ renderer.head((child) => child.push(head2));
3599
+ }
3600
+ };
3601
+ if (typeof body === "function") {
3602
+ this.child((renderer) => {
3603
+ const r2 = new Renderer(this.global, this);
3604
+ body(r2);
3605
+ if (this.global.mode === "async") {
3606
+ return r2.#collect_content_async().then((content) => {
3607
+ close(renderer, content.body.replaceAll("<!---->", ""), content);
3608
+ });
3609
+ } else {
3610
+ const content = r2.#collect_content();
3611
+ close(renderer, content.body.replaceAll("<!---->", ""), content);
3612
+ }
3613
+ });
3614
+ } else {
3615
+ close(this, body, { body: escape_html(body) });
3616
+ }
3617
+ }
3618
+ /**
3619
+ * @param {(renderer: Renderer) => void} fn
3620
+ */
3621
+ title(fn) {
3622
+ const path = this.get_path();
3623
+ const close = (head2) => {
3624
+ this.global.set_title(head2, path);
3625
+ };
3626
+ this.child((renderer) => {
3627
+ const r2 = new Renderer(renderer.global, renderer);
3628
+ fn(r2);
3629
+ if (renderer.global.mode === "async") {
3630
+ return r2.#collect_content_async().then((content) => {
3631
+ close(content.head);
3632
+ });
3633
+ } else {
3634
+ const content = r2.#collect_content();
3635
+ close(content.head);
3636
+ }
3637
+ });
3638
+ }
3639
+ /**
3640
+ * @param {string | (() => Promise<string>)} content
3641
+ */
3642
+ push(content) {
3643
+ if (typeof content === "function") {
3644
+ this.child(async (renderer) => renderer.push(await content()));
3645
+ } else {
3646
+ this.#out.push(content);
3647
+ }
3648
+ }
3649
+ /**
3650
+ * @param {() => void} fn
3651
+ */
3652
+ on_destroy(fn) {
3653
+ (this.#on_destroy ??= []).push(fn);
3654
+ }
3655
+ /**
3656
+ * @returns {number[]}
3657
+ */
3658
+ get_path() {
3659
+ return this.#parent ? [...this.#parent.get_path(), this.#parent.#out.indexOf(this)] : [];
3660
+ }
3661
+ /**
3662
+ * @deprecated this is needed for legacy component bindings
3663
+ */
3664
+ copy() {
3665
+ const copy = new Renderer(this.global, this.#parent);
3666
+ copy.type = this.type;
3667
+ copy.#out = this.#out.map((item) => item instanceof Renderer ? item.copy() : item);
3668
+ copy.promise = this.promise;
3669
+ return copy;
3670
+ }
3671
+ /**
3672
+ * @param {Renderer} other
3673
+ * @deprecated this is needed for legacy component bindings
3674
+ */
3675
+ subsume(other) {
3676
+ if (this.global.mode !== other.global.mode) {
3677
+ throw new Error(
3678
+ "invariant: A renderer cannot switch modes. If you're seeing this, there's a compiler bug. File an issue!"
3679
+ );
3680
+ }
3681
+ this.local = other.local;
3682
+ this.#out = other.#out.map((item, i) => {
3683
+ const current = this.#out[i];
3684
+ if (current instanceof Renderer && item instanceof Renderer) {
3685
+ current.subsume(item);
3686
+ return current;
3687
+ }
3688
+ return item;
3689
+ });
3690
+ this.promise = other.promise;
3691
+ this.type = other.type;
3692
+ }
3693
+ get length() {
3694
+ return this.#out.length;
3695
+ }
3696
+ /**
3697
+ * Creates the hydration comment that marks the start of a failed boundary.
3698
+ * The error is JSON-serialized and embedded inside an HTML comment for the client
3699
+ * to parse during hydration. The JSON is escaped to prevent `-->` or `<!--` sequences
3700
+ * from breaking out of the comment (XSS). Uses unicode escapes which `JSON.parse()`
3701
+ * handles transparently.
3702
+ * @param {unknown} error
3703
+ * @returns {string}
3704
+ */
3705
+ static #serialize_failed_boundary(error) {
3706
+ var json = JSON.stringify(error);
3707
+ var escaped = json.replace(/>/g, "\\u003e").replace(/</g, "\\u003c");
3708
+ return `<!--${HYDRATION_START_FAILED}${escaped}-->`;
3709
+ }
3710
+ /**
3711
+ * Only available on the server and when compiling with the `server` option.
3712
+ * Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app.
3713
+ * @template {Record<string, any>} Props
3714
+ * @param {Component<Props>} component
3715
+ * @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string; csp?: Csp }} [options]
3716
+ * @returns {RenderOutput}
3717
+ */
3718
+ static render(component, options = {}) {
3719
+ let sync;
3720
+ const result = (
3721
+ /** @type {RenderOutput} */
3722
+ {}
3723
+ );
3724
+ Object.defineProperties(result, {
3725
+ html: {
3726
+ get: () => {
3727
+ return (sync ??= Renderer.#render(component, options)).body;
3728
+ }
3729
+ },
3730
+ head: {
3731
+ get: () => {
3732
+ return (sync ??= Renderer.#render(component, options)).head;
3733
+ }
3734
+ },
3735
+ body: {
3736
+ get: () => {
3737
+ return (sync ??= Renderer.#render(component, options)).body;
3738
+ }
3739
+ },
3740
+ hashes: {
3741
+ value: {
3742
+ script: ""
3743
+ }
3744
+ },
3745
+ then: {
3746
+ value: (
3747
+ /**
3748
+ * this is not type-safe, but honestly it's the best I can do right now, and it's a straightforward function.
3749
+ *
3750
+ * @template TResult1
3751
+ * @template [TResult2=never]
3752
+ * @param { (value: SyncRenderOutput) => TResult1 } onfulfilled
3753
+ * @param { (reason: unknown) => TResult2 } onrejected
3754
+ */
3755
+ (onfulfilled, onrejected) => {
3756
+ {
3757
+ const result2 = sync ??= Renderer.#render(component, options);
3758
+ const user_result = onfulfilled({
3759
+ head: result2.head,
3760
+ body: result2.body,
3761
+ html: result2.body,
3762
+ hashes: { script: [] }
3763
+ });
3764
+ return Promise.resolve(user_result);
3765
+ }
3766
+ }
3767
+ )
3768
+ }
3769
+ });
3770
+ return result;
3771
+ }
3772
+ /**
3773
+ * Collect all of the `onDestroy` callbacks registered during rendering. In an async context, this is only safe to call
3774
+ * after awaiting `collect_async`.
3775
+ *
3776
+ * Child renderers are "porous" and don't affect execution order, but component body renderers
3777
+ * create ordering boundaries. Within a renderer, callbacks run in order until hitting a component boundary.
3778
+ * @returns {Iterable<() => void>}
3779
+ */
3780
+ *#collect_on_destroy() {
3781
+ for (const component of this.#traverse_components()) {
3782
+ yield* component.#collect_ondestroy();
3783
+ }
3784
+ }
3785
+ /**
3786
+ * Performs a depth-first search of renderers, yielding the deepest components first, then additional components as we backtrack up the tree.
3787
+ * @returns {Iterable<Renderer>}
3788
+ */
3789
+ *#traverse_components() {
3790
+ for (const child of this.#out) {
3791
+ if (typeof child !== "string") {
3792
+ yield* child.#traverse_components();
3793
+ }
3794
+ }
3795
+ if (this.#is_component_body) {
3796
+ yield this;
3797
+ }
3798
+ }
3799
+ /**
3800
+ * @returns {Iterable<() => void>}
3801
+ */
3802
+ *#collect_ondestroy() {
3803
+ if (this.#on_destroy) {
3804
+ for (const fn of this.#on_destroy) {
3805
+ yield fn;
3806
+ }
3807
+ }
3808
+ for (const child of this.#out) {
3809
+ if (child instanceof Renderer && !child.#is_component_body) {
3810
+ yield* child.#collect_ondestroy();
3811
+ }
3812
+ }
3813
+ }
3814
+ /**
3815
+ * Runs every `onDestroy` callback in this renderer tree. On a failed render,
3816
+ * cleanup errors are suppressed so they do not mask the render error.
3817
+ * @param {boolean} suppress_errors
3818
+ */
3819
+ #run_on_destroy(suppress_errors) {
3820
+ let first_error;
3821
+ let has_error = false;
3822
+ for (const cleanup of this.#collect_on_destroy()) {
3823
+ try {
3824
+ cleanup();
3825
+ } catch (error) {
3826
+ if (!suppress_errors && !has_error) {
3827
+ first_error = error;
3828
+ has_error = true;
3829
+ }
3830
+ }
3831
+ }
3832
+ if (has_error) throw first_error;
3833
+ }
3834
+ /**
3835
+ * @param {'sync' | 'async'} mode
3836
+ * @param {{ idPrefix?: string; csp?: Csp; transformError?: (error: unknown) => unknown }} options
3837
+ * @returns {Renderer}
3838
+ */
3839
+ static #create(mode, options) {
3840
+ if (options.idPrefix?.includes("--")) {
3841
+ invalid_id_prefix();
3842
+ }
3843
+ return new Renderer(
3844
+ new SSRState(
3845
+ mode,
3846
+ options.idPrefix ? options.idPrefix + "-" : "",
3847
+ options.csp,
3848
+ options.transformError
3849
+ )
3850
+ );
3851
+ }
3852
+ /**
3853
+ * Render a component. Throws if any of the children are performing asynchronous work.
3854
+ *
3855
+ * @template {Record<string, any>} Props
3856
+ * @param {Component<Props>} component
3857
+ * @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string }} options
3858
+ * @returns {AccumulatedContent}
3859
+ */
3860
+ static #render(component, options) {
3861
+ var previous_context = ssr_context;
3862
+ const renderer = Renderer.#create("sync", options);
3863
+ let result;
3864
+ let render_error;
3865
+ let failed = false;
3866
+ try {
3867
+ try {
3868
+ Renderer.#open_render(renderer, component, options);
3869
+ result = Renderer.#close_render(renderer.#collect_content(), renderer);
3870
+ } catch (error) {
3871
+ render_error = error;
3872
+ failed = true;
3873
+ }
3874
+ renderer.#run_on_destroy(failed);
3875
+ if (failed) throw render_error;
3876
+ return (
3877
+ /** @type {AccumulatedContent} */
3878
+ result
3879
+ );
3880
+ } finally {
3881
+ renderer.global.abort();
3882
+ set_ssr_context(previous_context);
3883
+ }
3884
+ }
3885
+ /**
3886
+ * Render a component.
3887
+ *
3888
+ * @template {Record<string, any>} Props
3889
+ * @param {Component<Props>} component
3890
+ * @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string; csp?: Csp }} options
3891
+ * @returns {Promise<AccumulatedContent & { hashes: { script: Sha256Source[] } }>}
3892
+ */
3893
+ static async #render_async(component, options) {
3894
+ const previous_context = ssr_context;
3895
+ const renderer = Renderer.#create("async", options);
3896
+ let result;
3897
+ let render_error;
3898
+ let failed = false;
3899
+ try {
3900
+ try {
3901
+ Renderer.#open_render(renderer, component, options);
3902
+ const content = await renderer.#collect_content_async();
3903
+ const hydratables = await renderer.#collect_hydratables();
3904
+ if (hydratables !== null) {
3905
+ content.head = hydratables + content.head;
3906
+ }
3907
+ result = Renderer.#close_render(content, renderer);
3908
+ } catch (error) {
3909
+ render_error = error;
3910
+ failed = true;
3911
+ renderer.global.abort();
3912
+ await renderer.global.settle();
3913
+ }
3914
+ renderer.#run_on_destroy(failed);
3915
+ if (failed) throw render_error;
3916
+ return (
3917
+ /** @type {AccumulatedContent & { hashes: { script: Sha256Source[] } }} */
3918
+ result
3919
+ );
3920
+ } finally {
3921
+ set_ssr_context(previous_context);
3922
+ renderer.global.abort();
3923
+ }
3924
+ }
3925
+ /**
3926
+ * Collect all of the code from the `out` array and return it as a string, or a promise resolving to a string.
3927
+ * @param {AccumulatedContent} content
3928
+ * @returns {AccumulatedContent}
3929
+ */
3930
+ #collect_content(content = { head: "", body: "" }) {
3931
+ for (const item of this.#out) {
3932
+ if (typeof item === "string") {
3933
+ content[this.type] += item;
3934
+ } else if (item instanceof Renderer) {
3935
+ item.#collect_content(content);
3936
+ }
3937
+ }
3938
+ return content;
3939
+ }
3940
+ /**
3941
+ * Collect all of the code from the `out` array and return it as a string.
3942
+ * @param {AccumulatedContent} content
3943
+ * @returns {Promise<AccumulatedContent>}
3944
+ */
3945
+ async #collect_content_async(content = { head: "", body: "" }) {
3946
+ await this.promise;
3947
+ for (const item of this.#out) {
3948
+ if (typeof item === "string") {
3949
+ content[this.type] += item;
3950
+ } else if (item instanceof Renderer) {
3951
+ if (item.#boundary) {
3952
+ const boundary_content = { head: "", body: "" };
3953
+ try {
3954
+ await item.#collect_content_async(boundary_content);
3955
+ content.head += boundary_content.head;
3956
+ content.body += boundary_content.body;
3957
+ } catch (error) {
3958
+ const { context, failed, transformError } = item.#boundary;
3959
+ set_ssr_context(context);
3960
+ let promise = transformError(error);
3961
+ set_ssr_context(null);
3962
+ let transformed = await promise;
3963
+ set_ssr_context(context);
3964
+ const failed_renderer = new Renderer(item.global, item);
3965
+ failed_renderer.type = item.type;
3966
+ failed_renderer.#out.push(Renderer.#serialize_failed_boundary(transformed));
3967
+ failed(failed_renderer, transformed, noop);
3968
+ failed_renderer.#out.push(BLOCK_CLOSE);
3969
+ await failed_renderer.#collect_content_async(content);
3970
+ }
3971
+ } else {
3972
+ await item.#collect_content_async(content);
3973
+ }
3974
+ }
3975
+ }
3976
+ return content;
3977
+ }
3978
+ async #collect_hydratables() {
3979
+ const ctx = get_render_context().hydratable;
3980
+ for (const [_, key] of ctx.unresolved_promises) {
3981
+ unresolved_hydratable(key, ctx.lookup.get(key)?.stack ?? "<missing stack trace>");
3982
+ }
3983
+ for (const comparison of ctx.comparisons) {
3984
+ await comparison;
3985
+ }
3986
+ return await this.#hydratable_block(ctx);
3987
+ }
3988
+ /**
3989
+ * @template {Record<string, any>} Props
3990
+ * @param {Renderer} renderer
3991
+ * @param {import('svelte').Component<Props>} component
3992
+ * @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string; csp?: Csp; transformError?: (error: unknown) => unknown }} options
3993
+ * @returns {void}
3994
+ */
3995
+ static #open_render(renderer, component, options) {
3996
+ var previous_context = ssr_context;
3997
+ try {
3998
+ const context = { p: null, c: options.context ?? null, r: renderer };
3999
+ set_ssr_context(context);
4000
+ renderer.push(BLOCK_OPEN);
4001
+ component(renderer, options.props ?? {});
4002
+ renderer.push(BLOCK_CLOSE);
4003
+ } finally {
4004
+ set_ssr_context(previous_context);
4005
+ }
4006
+ }
4007
+ /**
4008
+ * @param {AccumulatedContent} content
4009
+ * @param {Renderer} renderer
4010
+ * @returns {AccumulatedContent & { hashes: { script: Sha256Source[] } }}
4011
+ */
4012
+ static #close_render(content, renderer) {
4013
+ let head2 = content.head + renderer.global.get_title();
4014
+ let body = content.body;
4015
+ for (const { hash, code } of renderer.global.css) {
4016
+ head2 += `<style id="${hash}">${code}</style>`;
4017
+ }
4018
+ return {
4019
+ head: head2,
4020
+ body,
4021
+ hashes: {
4022
+ script: renderer.global.csp.script_hashes
4023
+ }
4024
+ };
4025
+ }
4026
+ /**
4027
+ * @param {HydratableContext} ctx
4028
+ */
4029
+ async #hydratable_block(ctx) {
4030
+ if (ctx.lookup.size === 0) {
4031
+ return null;
4032
+ }
4033
+ let entries = [];
4034
+ let has_promises = false;
4035
+ for (const [k, v] of ctx.lookup) {
4036
+ if (v.promises) {
4037
+ has_promises = true;
4038
+ for (const p of v.promises) await p;
4039
+ }
4040
+ entries.push(`[${uneval(k)},${v.serialized}]`);
4041
+ }
4042
+ let prelude = `const h = (window.__svelte ??= {}).h ??= new Map();`;
4043
+ if (has_promises) {
4044
+ prelude = `const r = (v) => Promise.resolve(v);
4045
+ ${prelude}`;
4046
+ }
4047
+ const body = `
4048
+ {
4049
+ ${prelude}
4050
+
4051
+ for (const [k, v] of [
4052
+ ${entries.join(",\n ")}
4053
+ ]) {
4054
+ h.set(k, v);
4055
+ }
4056
+ }
4057
+ `;
4058
+ let csp_attr = "";
4059
+ if (this.global.csp.nonce) {
4060
+ csp_attr = ` nonce="${this.global.csp.nonce}"`;
4061
+ } else if (this.global.csp.hash) {
4062
+ const hash = await sha256(body);
4063
+ this.global.csp.script_hashes.push(`sha256-${hash}`);
4064
+ }
4065
+ return `
4066
+ <script${csp_attr}>${body}<\/script>`;
4067
+ }
4068
+ }
4069
+ class SSRState {
4070
+ /** @readonly @type {Csp & { script_hashes: Sha256Source[] }} */
4071
+ csp;
4072
+ /** @readonly @type {'sync' | 'async'} */
4073
+ mode;
4074
+ /** @readonly @type {() => string} */
4075
+ uid;
4076
+ /** @readonly @type {Set<{ hash: string; code: string }>} */
4077
+ css = /* @__PURE__ */ new Set();
4078
+ /** @type {Set<Promise<unknown>>} */
4079
+ #pending = /* @__PURE__ */ new Set();
4080
+ /** @type {AbortController | null} */
4081
+ #controller = null;
4082
+ #aborted = false;
4083
+ /**
4084
+ * `transformError` passed to `render`. Called when an error boundary catches an error.
4085
+ * Throws by default if unset in `render`.
4086
+ * @type {(error: unknown) => unknown}
4087
+ */
4088
+ transformError;
4089
+ /** @type {{ path: number[], value: string }} */
4090
+ #title = { path: [], value: "" };
4091
+ /**
4092
+ * @param {'sync' | 'async'} mode
4093
+ * @param {string} id_prefix
4094
+ * @param {Csp} csp
4095
+ * @param {((error: unknown) => unknown) | undefined} [transformError]
4096
+ */
4097
+ constructor(mode, id_prefix = "", csp = { hash: false }, transformError) {
4098
+ this.mode = mode;
4099
+ this.csp = { ...csp, script_hashes: [] };
4100
+ this.transformError = transformError ?? ((error) => {
4101
+ throw error;
4102
+ });
4103
+ let uid2 = 1;
4104
+ this.uid = () => `${id_prefix}s${uid2++}`;
4105
+ }
4106
+ /**
4107
+ * @template T
4108
+ * @param {Promise<T>} promise
4109
+ * @returns {Promise<T>}
4110
+ */
4111
+ track(promise) {
4112
+ this.#pending.add(promise);
4113
+ promise.then(
4114
+ () => this.#pending.delete(promise),
4115
+ () => this.#pending.delete(promise)
4116
+ );
4117
+ return promise;
4118
+ }
4119
+ async settle() {
4120
+ while (this.#pending.size > 0) {
4121
+ await Promise.allSettled([...this.#pending]);
4122
+ }
4123
+ }
4124
+ abort() {
4125
+ if (this.#aborted) return;
4126
+ this.#aborted = true;
4127
+ this.#controller?.abort(STALE_REACTION);
4128
+ }
4129
+ get_abort_signal() {
4130
+ const controller = this.#controller ??= new AbortController();
4131
+ if (this.#aborted) controller.abort(STALE_REACTION);
4132
+ return controller.signal;
4133
+ }
4134
+ get_title() {
4135
+ return this.#title.value;
4136
+ }
4137
+ /**
4138
+ * Performs a depth-first (lexicographic) comparison using the path. Rejects sets
4139
+ * from earlier than or equal to the current value.
4140
+ * @param {string} value
4141
+ * @param {number[]} path
4142
+ */
4143
+ set_title(value, path) {
4144
+ const current = this.#title.path;
4145
+ let i = 0;
4146
+ let l = Math.min(path.length, current.length);
4147
+ while (i < l && path[i] === current[i]) i += 1;
4148
+ if (path[i] === void 0) return;
4149
+ if (current[i] === void 0 || path[i] > current[i]) {
4150
+ this.#title.path = path;
4151
+ this.#title.value = value;
4152
+ }
4153
+ }
4154
+ }
4155
+ const INVALID_ATTR_NAME_CHAR_REGEX = /[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u;
4156
+ function render(component, options = {}) {
4157
+ if (options.csp?.hash && options.csp.nonce) {
4158
+ invalid_csp();
4159
+ }
4160
+ return Renderer.render(
4161
+ /** @type {Component<Props>} */
4162
+ component,
4163
+ options
4164
+ );
4165
+ }
4166
+ function head(hash, renderer, fn) {
4167
+ renderer.head((renderer2) => {
4168
+ renderer2.push(`<!--${hash}-->`);
4169
+ renderer2.child(fn);
4170
+ renderer2.push(EMPTY_COMMENT);
4171
+ });
4172
+ }
4173
+ function attributes(attrs, css_hash, classes, styles, flags2 = 0) {
4174
+ if (styles) {
4175
+ attrs.style = to_style(attrs.style, styles);
4176
+ }
4177
+ if (attrs.class) {
4178
+ attrs.class = clsx(attrs.class);
4179
+ }
4180
+ if (css_hash || classes) {
4181
+ attrs.class = to_class(attrs.class, css_hash, classes);
4182
+ }
4183
+ let attr_str = "";
4184
+ let name;
4185
+ const is_html = (flags2 & ELEMENT_IS_NAMESPACED) === 0;
4186
+ const lowercase = (flags2 & ELEMENT_PRESERVE_ATTRIBUTE_CASE) === 0;
4187
+ const is_input = (flags2 & ELEMENT_IS_INPUT) !== 0;
4188
+ for (name of Object.keys(attrs)) {
4189
+ if (typeof attrs[name] === "function") continue;
4190
+ if (name[0] === "$" && name[1] === "$") continue;
4191
+ if (name === "" || INVALID_ATTR_NAME_CHAR_REGEX.test(name)) continue;
4192
+ var value = attrs[name];
4193
+ var lower = name.toLowerCase();
4194
+ if (lowercase) name = lower;
4195
+ if (lower.length > 2 && lower.startsWith("on")) continue;
4196
+ if (is_input) {
4197
+ if (name === "defaultvalue" || name === "defaultchecked") {
4198
+ name = name === "defaultvalue" ? "value" : "checked";
4199
+ if (attrs[name]) continue;
4200
+ }
4201
+ }
4202
+ attr_str += attr(name, value, is_html && is_boolean_attribute(name));
4203
+ }
4204
+ return attr_str;
4205
+ }
4206
+ function attr_class(value, hash, directives) {
4207
+ var result = to_class(value, hash, directives);
4208
+ return result ? ` class="${escape_html(result, true)}"` : "";
4209
+ }
4210
+ function ensure_array_like(array_like_or_iterator) {
4211
+ if (array_like_or_iterator) {
4212
+ return array_like_or_iterator.length !== void 0 ? array_like_or_iterator : Array.from(array_like_or_iterator);
4213
+ }
4214
+ return [];
4215
+ }
4216
+ function once(get_value) {
4217
+ let value = (
4218
+ /** @type {V} */
4219
+ UNINITIALIZED
4220
+ );
4221
+ return () => {
4222
+ if (value === UNINITIALIZED) {
4223
+ value = get_value();
4224
+ }
4225
+ return value;
4226
+ };
4227
+ }
4228
+ function derived(fn) {
4229
+ const get_value = ssr_context === null ? fn : once(fn);
4230
+ let updated_value;
4231
+ return function(new_value) {
4232
+ if (arguments.length === 0) {
4233
+ return updated_value ?? get_value();
4234
+ }
4235
+ updated_value = new_value;
4236
+ return updated_value;
4237
+ };
4238
+ }
4239
+ function asClassComponent(component) {
4240
+ const component_constructor = asClassComponent$1(component);
4241
+ const _render = (props, { context, csp, transformError } = {}) => {
4242
+ const result = render(component, { props, context, csp, transformError });
4243
+ const munged = Object.defineProperties(
4244
+ /** @type {LegacyRenderResult & PromiseLike<LegacyRenderResult>} */
4245
+ {},
4246
+ {
4247
+ css: {
4248
+ value: { code: "", map: null }
4249
+ },
4250
+ head: {
4251
+ get: () => result.head
4252
+ },
4253
+ html: {
4254
+ get: () => result.body
4255
+ },
4256
+ then: {
4257
+ /**
4258
+ * this is not type-safe, but honestly it's the best I can do right now, and it's a straightforward function.
4259
+ *
4260
+ * @template TResult1
4261
+ * @template [TResult2=never]
4262
+ * @param { (value: LegacyRenderResult) => TResult1 } onfulfilled
4263
+ * @param { (reason: unknown) => TResult2 } onrejected
4264
+ */
4265
+ value: (onfulfilled, onrejected) => {
4266
+ {
4267
+ const user_result = onfulfilled({
4268
+ css: munged.css,
4269
+ head: munged.head,
4270
+ html: munged.html
4271
+ });
4272
+ return Promise.resolve(user_result);
4273
+ }
4274
+ }
4275
+ }
4276
+ }
4277
+ );
4278
+ return munged;
4279
+ };
4280
+ component_constructor.render = _render;
4281
+ return component_constructor;
4282
+ }
4283
+ function Root($$renderer, $$props) {
4284
+ $$renderer.component(($$renderer2) => {
4285
+ let {
4286
+ stores,
4287
+ page,
4288
+ constructors,
4289
+ components = [],
4290
+ form,
4291
+ data_0 = null,
4292
+ data_1 = null
4293
+ } = $$props;
4294
+ {
4295
+ setContext("__svelte__", stores);
4296
+ }
4297
+ {
4298
+ stores.page.set(page);
4299
+ }
4300
+ const Pyramid_1 = derived(() => constructors[1]);
4301
+ if (constructors[1]) {
4302
+ $$renderer2.push("<!--[0-->");
4303
+ const Pyramid_0 = constructors[0];
4304
+ if (Pyramid_0) {
4305
+ $$renderer2.push("<!--[-->");
4306
+ Pyramid_0($$renderer2, {
4307
+ data: data_0,
4308
+ form,
4309
+ params: page.params,
4310
+ children: ($$renderer3) => {
4311
+ if (Pyramid_1()) {
4312
+ $$renderer3.push("<!--[-->");
4313
+ Pyramid_1()($$renderer3, { data: data_1, form, params: page.params });
4314
+ $$renderer3.push("<!--]-->");
4315
+ } else {
4316
+ $$renderer3.push("<!--[!-->");
4317
+ $$renderer3.push("<!--]-->");
4318
+ }
4319
+ },
4320
+ $$slots: { default: true }
4321
+ });
4322
+ $$renderer2.push("<!--]-->");
4323
+ } else {
4324
+ $$renderer2.push("<!--[!-->");
4325
+ $$renderer2.push("<!--]-->");
4326
+ }
4327
+ } else {
4328
+ $$renderer2.push("<!--[-1-->");
4329
+ const Pyramid_0 = constructors[0];
4330
+ if (Pyramid_0) {
4331
+ $$renderer2.push("<!--[-->");
4332
+ Pyramid_0($$renderer2, { data: data_0, form, params: page.params });
4333
+ $$renderer2.push("<!--]-->");
4334
+ } else {
4335
+ $$renderer2.push("<!--[!-->");
4336
+ $$renderer2.push("<!--]-->");
4337
+ }
4338
+ }
4339
+ $$renderer2.push(`<!--]--> `);
4340
+ {
4341
+ $$renderer2.push("<!--[-1-->");
4342
+ }
4343
+ $$renderer2.push(`<!--]-->`);
4344
+ });
4345
+ }
4346
+ const root = asClassComponent(Root);
4347
+
4348
+ export { DEV as D, attr_class as a, attr as b, ensure_array_like as c, derived as d, escape_html as e, getContext as g, head as h, noop as n, root as r, safe_not_equal as s };
4349
+ //# sourceMappingURL=root.js-HNgH7zyW.js.map