root.js 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815
  1. import { H as HYDRATION_ERROR, C as COMMENT_NODE, a as HYDRATION_END, b as HYDRATION_START, c as HYDRATION_START_ELSE, r as run_all, B as BOUNDARY_EFFECT, R as REACTION_RAN, E as ERROR_VALUE, d as EFFECT, f as CONNECTED, h as CLEAN, M as MAYBE_DIRTY, D as DIRTY, i as DERIVED, W as WAS_MARKED, I as INERT, j as BLOCK_EFFECT, U as UNINITIALIZED, k as DESTROYED, l as EAGER_EFFECT, A as ASYNC, m as deferred, o as RENDER_EFFECT, p as MANAGED_EFFECT, q as ROOT_EFFECT, t as BRANCH_EFFECT, u as includes, v as HYDRATION_START_FAILED, w as EFFECT_TRANSPARENT, x as EFFECT_PRESERVED, S as STALE_REACTION, n as noop, y as STATE_SYMBOL, z as object_prototype, F as array_prototype, G as get_descriptor, J as get_prototype_of, K as is_array, L as is_extensible, N as HEAD_EFFECT, O as DESTROYING, P as USER_EFFECT, Q as REACTION_IS_UPDATING, T as index_of, V as define_property, X as array_from, Y as is_passive_event, Z as LEGACY_PROPS, _ as render, $ as setContext, a0 as derived } from "./renderer.js";
  2. import { B as BROWSER } from "./false.js";
  3. let tracing_mode_flag = false;
  4. function effect_update_depth_exceeded() {
  5. {
  6. throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`);
  7. }
  8. }
  9. function hydration_failed() {
  10. {
  11. throw new Error(`https://svelte.dev/e/hydration_failed`);
  12. }
  13. }
  14. function state_descriptors_fixed() {
  15. {
  16. throw new Error(`https://svelte.dev/e/state_descriptors_fixed`);
  17. }
  18. }
  19. function state_prototype_fixed() {
  20. {
  21. throw new Error(`https://svelte.dev/e/state_prototype_fixed`);
  22. }
  23. }
  24. function state_unsafe_mutation() {
  25. {
  26. throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
  27. }
  28. }
  29. function svelte_boundary_reset_onerror() {
  30. {
  31. throw new Error(`https://svelte.dev/e/svelte_boundary_reset_onerror`);
  32. }
  33. }
  34. function hydration_mismatch(location) {
  35. {
  36. console.warn(`https://svelte.dev/e/hydration_mismatch`);
  37. }
  38. }
  39. function svelte_boundary_reset_noop() {
  40. {
  41. console.warn(`https://svelte.dev/e/svelte_boundary_reset_noop`);
  42. }
  43. }
  44. let hydrating = false;
  45. function set_hydrating(value) {
  46. hydrating = value;
  47. }
  48. let hydrate_node;
  49. function set_hydrate_node(node) {
  50. if (node === null) {
  51. hydration_mismatch();
  52. throw HYDRATION_ERROR;
  53. }
  54. return hydrate_node = node;
  55. }
  56. function hydrate_next() {
  57. return set_hydrate_node(/* @__PURE__ */ get_next_sibling(hydrate_node));
  58. }
  59. function next(count = 1) {
  60. if (hydrating) {
  61. var i = count;
  62. var node = hydrate_node;
  63. while (i--) {
  64. node = /** @type {TemplateNode} */
  65. /* @__PURE__ */ get_next_sibling(node);
  66. }
  67. hydrate_node = node;
  68. }
  69. }
  70. function skip_nodes(remove = true) {
  71. var depth = 0;
  72. var node = hydrate_node;
  73. while (true) {
  74. if (node.nodeType === COMMENT_NODE) {
  75. var data = (
  76. /** @type {Comment} */
  77. node.data
  78. );
  79. if (data === HYDRATION_END) {
  80. if (depth === 0) return node;
  81. depth -= 1;
  82. } else if (data === HYDRATION_START || data === HYDRATION_START_ELSE || // "[1", "[2", etc. for if blocks
  83. data[0] === "[" && !isNaN(Number(data.slice(1)))) {
  84. depth += 1;
  85. }
  86. }
  87. var next2 = (
  88. /** @type {TemplateNode} */
  89. /* @__PURE__ */ get_next_sibling(node)
  90. );
  91. if (remove) node.remove();
  92. node = next2;
  93. }
  94. }
  95. function equals(value) {
  96. return value === this.v;
  97. }
  98. function safe_not_equal(a, b) {
  99. return a != a ? b == b : a !== b || a !== null && typeof a === "object" || typeof a === "function";
  100. }
  101. function safe_equals(value) {
  102. return !safe_not_equal(value, this.v);
  103. }
  104. let component_context = null;
  105. function set_component_context(context) {
  106. component_context = context;
  107. }
  108. function push(props, runes = false, fn) {
  109. component_context = {
  110. p: component_context,
  111. i: false,
  112. c: null,
  113. e: null,
  114. s: props,
  115. x: null,
  116. r: (
  117. /** @type {Effect} */
  118. active_effect
  119. ),
  120. l: null
  121. };
  122. }
  123. function pop(component) {
  124. var context = (
  125. /** @type {ComponentContext} */
  126. component_context
  127. );
  128. var effects = context.e;
  129. if (effects !== null) {
  130. context.e = null;
  131. for (var fn of effects) {
  132. create_user_effect(fn);
  133. }
  134. }
  135. context.i = true;
  136. component_context = context.p;
  137. return (
  138. /** @type {T} */
  139. {}
  140. );
  141. }
  142. function is_runes() {
  143. return true;
  144. }
  145. let micro_tasks = [];
  146. function run_micro_tasks() {
  147. var tasks = micro_tasks;
  148. micro_tasks = [];
  149. run_all(tasks);
  150. }
  151. function queue_micro_task(fn) {
  152. if (micro_tasks.length === 0 && !is_flushing_sync) {
  153. var tasks = micro_tasks;
  154. queueMicrotask(() => {
  155. if (tasks === micro_tasks) run_micro_tasks();
  156. });
  157. }
  158. micro_tasks.push(fn);
  159. }
  160. function flush_tasks() {
  161. while (micro_tasks.length > 0) {
  162. run_micro_tasks();
  163. }
  164. }
  165. function handle_error(error) {
  166. var effect = active_effect;
  167. if (effect === null) {
  168. active_reaction.f |= ERROR_VALUE;
  169. return error;
  170. }
  171. if ((effect.f & REACTION_RAN) === 0 && (effect.f & EFFECT) === 0) {
  172. throw error;
  173. }
  174. invoke_error_boundary(error, effect);
  175. }
  176. function invoke_error_boundary(error, effect) {
  177. while (effect !== null) {
  178. if ((effect.f & BOUNDARY_EFFECT) !== 0) {
  179. if ((effect.f & REACTION_RAN) === 0) {
  180. throw error;
  181. }
  182. try {
  183. effect.b.error(error);
  184. return;
  185. } catch (e) {
  186. error = e;
  187. }
  188. }
  189. effect = effect.parent;
  190. }
  191. throw error;
  192. }
  193. const STATUS_MASK = -7169;
  194. function set_signal_status(signal, status) {
  195. signal.f = signal.f & STATUS_MASK | status;
  196. }
  197. function update_derived_status(derived2) {
  198. if ((derived2.f & CONNECTED) !== 0 || derived2.deps === null) {
  199. set_signal_status(derived2, CLEAN);
  200. } else {
  201. set_signal_status(derived2, MAYBE_DIRTY);
  202. }
  203. }
  204. function clear_marked(deps) {
  205. if (deps === null) return;
  206. for (const dep of deps) {
  207. if ((dep.f & DERIVED) === 0 || (dep.f & WAS_MARKED) === 0) {
  208. continue;
  209. }
  210. dep.f ^= WAS_MARKED;
  211. clear_marked(
  212. /** @type {Derived} */
  213. dep.deps
  214. );
  215. }
  216. }
  217. function defer_effect(effect, dirty_effects, maybe_dirty_effects) {
  218. if ((effect.f & DIRTY) !== 0) {
  219. dirty_effects.add(effect);
  220. } else if ((effect.f & MAYBE_DIRTY) !== 0) {
  221. maybe_dirty_effects.add(effect);
  222. }
  223. clear_marked(effect.deps);
  224. set_signal_status(effect, CLEAN);
  225. }
  226. const batches = /* @__PURE__ */ new Set();
  227. let current_batch = null;
  228. let batch_values = null;
  229. let last_scheduled_effect = null;
  230. let is_flushing_sync = false;
  231. let is_processing = false;
  232. let collected_effects = null;
  233. let legacy_updates = null;
  234. var flush_count = 0;
  235. let uid = 1;
  236. class Batch {
  237. id = uid++;
  238. /**
  239. * The current values of any signals that are updated in this batch.
  240. * Tuple format: [value, is_derived] (note: is_derived is false for deriveds, too, if they were overridden via assignment)
  241. * They keys of this map are identical to `this.#previous`
  242. * @type {Map<Value, [any, boolean]>}
  243. */
  244. current = /* @__PURE__ */ new Map();
  245. /**
  246. * The values of any signals (sources and deriveds) that are updated in this batch _before_ those updates took place.
  247. * They keys of this map are identical to `this.#current`
  248. * @type {Map<Value, any>}
  249. */
  250. previous = /* @__PURE__ */ new Map();
  251. /**
  252. * When the batch is committed (and the DOM is updated), we need to remove old branches
  253. * and append new ones by calling the functions added inside (if/each/key/etc) blocks
  254. * @type {Set<(batch: Batch) => void>}
  255. */
  256. #commit_callbacks = /* @__PURE__ */ new Set();
  257. /**
  258. * If a fork is discarded, we need to destroy any effects that are no longer needed
  259. * @type {Set<(batch: Batch) => void>}
  260. */
  261. #discard_callbacks = /* @__PURE__ */ new Set();
  262. /**
  263. * Async effects that are currently in flight
  264. * @type {Map<Effect, number>}
  265. */
  266. #pending = /* @__PURE__ */ new Map();
  267. /**
  268. * Async effects that are currently in flight, _not_ inside a pending boundary
  269. * @type {Map<Effect, number>}
  270. */
  271. #blocking_pending = /* @__PURE__ */ new Map();
  272. /**
  273. * A deferred that resolves when the batch is committed, used with `settled()`
  274. * TODO replace with Promise.withResolvers once supported widely enough
  275. * @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null}
  276. */
  277. #deferred = null;
  278. /**
  279. * The root effects that need to be flushed
  280. * @type {Effect[]}
  281. */
  282. #roots = [];
  283. /**
  284. * Effects created while this batch was active.
  285. * @type {Effect[]}
  286. */
  287. #new_effects = [];
  288. /**
  289. * Deferred effects (which run after async work has completed) that are DIRTY
  290. * @type {Set<Effect>}
  291. */
  292. #dirty_effects = /* @__PURE__ */ new Set();
  293. /**
  294. * Deferred effects that are MAYBE_DIRTY
  295. * @type {Set<Effect>}
  296. */
  297. #maybe_dirty_effects = /* @__PURE__ */ new Set();
  298. /**
  299. * A map of branches that still exist, but will be destroyed when this batch
  300. * is committed — we skip over these during `process`.
  301. * The value contains child effects that were dirty/maybe_dirty before being reset,
  302. * so they can be rescheduled if the branch survives.
  303. * @type {Map<Effect, { d: Effect[], m: Effect[] }>}
  304. */
  305. #skipped_branches = /* @__PURE__ */ new Map();
  306. is_fork = false;
  307. #decrement_queued = false;
  308. /** @type {Set<Batch>} */
  309. #blockers = /* @__PURE__ */ new Set();
  310. #is_deferred() {
  311. return this.is_fork || this.#blocking_pending.size > 0;
  312. }
  313. #is_blocked() {
  314. for (const batch of this.#blockers) {
  315. for (const effect of batch.#blocking_pending.keys()) {
  316. var skipped = false;
  317. var e = effect;
  318. while (e.parent !== null) {
  319. if (this.#skipped_branches.has(e)) {
  320. skipped = true;
  321. break;
  322. }
  323. e = e.parent;
  324. }
  325. if (!skipped) {
  326. return true;
  327. }
  328. }
  329. }
  330. return false;
  331. }
  332. /**
  333. * Add an effect to the #skipped_branches map and reset its children
  334. * @param {Effect} effect
  335. */
  336. skip_effect(effect) {
  337. if (!this.#skipped_branches.has(effect)) {
  338. this.#skipped_branches.set(effect, { d: [], m: [] });
  339. }
  340. }
  341. /**
  342. * Remove an effect from the #skipped_branches map and reschedule
  343. * any tracked dirty/maybe_dirty child effects
  344. * @param {Effect} effect
  345. */
  346. unskip_effect(effect) {
  347. var tracked = this.#skipped_branches.get(effect);
  348. if (tracked) {
  349. this.#skipped_branches.delete(effect);
  350. for (var e of tracked.d) {
  351. set_signal_status(e, DIRTY);
  352. this.schedule(e);
  353. }
  354. for (e of tracked.m) {
  355. set_signal_status(e, MAYBE_DIRTY);
  356. this.schedule(e);
  357. }
  358. }
  359. }
  360. #process() {
  361. if (flush_count++ > 1e3) {
  362. batches.delete(this);
  363. infinite_loop_guard();
  364. }
  365. if (!this.#is_deferred()) {
  366. for (const e of this.#dirty_effects) {
  367. this.#maybe_dirty_effects.delete(e);
  368. set_signal_status(e, DIRTY);
  369. this.schedule(e);
  370. }
  371. for (const e of this.#maybe_dirty_effects) {
  372. set_signal_status(e, MAYBE_DIRTY);
  373. this.schedule(e);
  374. }
  375. }
  376. const roots = this.#roots;
  377. this.#roots = [];
  378. this.apply();
  379. var effects = collected_effects = [];
  380. var render_effects = [];
  381. var updates = legacy_updates = [];
  382. for (const root2 of roots) {
  383. try {
  384. this.#traverse(root2, effects, render_effects);
  385. } catch (e) {
  386. reset_all(root2);
  387. throw e;
  388. }
  389. }
  390. current_batch = null;
  391. if (updates.length > 0) {
  392. var batch = Batch.ensure();
  393. for (const e of updates) {
  394. batch.schedule(e);
  395. }
  396. }
  397. collected_effects = null;
  398. legacy_updates = null;
  399. if (this.#is_deferred() || this.#is_blocked()) {
  400. this.#defer_effects(render_effects);
  401. this.#defer_effects(effects);
  402. for (const [e, t] of this.#skipped_branches) {
  403. reset_branch(e, t);
  404. }
  405. } else {
  406. if (this.#pending.size === 0) {
  407. batches.delete(this);
  408. }
  409. this.#dirty_effects.clear();
  410. this.#maybe_dirty_effects.clear();
  411. for (const fn of this.#commit_callbacks) fn(this);
  412. this.#commit_callbacks.clear();
  413. flush_queued_effects(render_effects);
  414. flush_queued_effects(effects);
  415. this.#deferred?.resolve();
  416. }
  417. var next_batch = (
  418. /** @type {Batch | null} */
  419. /** @type {unknown} */
  420. current_batch
  421. );
  422. if (this.#roots.length > 0) {
  423. const batch2 = next_batch ??= this;
  424. batch2.#roots.push(...this.#roots.filter((r) => !batch2.#roots.includes(r)));
  425. }
  426. if (next_batch !== null) {
  427. batches.add(next_batch);
  428. next_batch.#process();
  429. }
  430. if (!batches.has(this)) {
  431. this.#commit();
  432. }
  433. }
  434. /**
  435. * Traverse the effect tree, executing effects or stashing
  436. * them for later execution as appropriate
  437. * @param {Effect} root
  438. * @param {Effect[]} effects
  439. * @param {Effect[]} render_effects
  440. */
  441. #traverse(root2, effects, render_effects) {
  442. root2.f ^= CLEAN;
  443. var effect = root2.first;
  444. while (effect !== null) {
  445. var flags2 = effect.f;
  446. var is_branch = (flags2 & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0;
  447. var is_skippable_branch = is_branch && (flags2 & CLEAN) !== 0;
  448. var skip = is_skippable_branch || (flags2 & INERT) !== 0 || this.#skipped_branches.has(effect);
  449. if (!skip && effect.fn !== null) {
  450. if (is_branch) {
  451. effect.f ^= CLEAN;
  452. } else if ((flags2 & EFFECT) !== 0) {
  453. effects.push(effect);
  454. } else if (is_dirty(effect)) {
  455. if ((flags2 & BLOCK_EFFECT) !== 0) this.#maybe_dirty_effects.add(effect);
  456. update_effect(effect);
  457. }
  458. var child = effect.first;
  459. if (child !== null) {
  460. effect = child;
  461. continue;
  462. }
  463. }
  464. while (effect !== null) {
  465. var next2 = effect.next;
  466. if (next2 !== null) {
  467. effect = next2;
  468. break;
  469. }
  470. effect = effect.parent;
  471. }
  472. }
  473. }
  474. /**
  475. * @param {Effect[]} effects
  476. */
  477. #defer_effects(effects) {
  478. for (var i = 0; i < effects.length; i += 1) {
  479. defer_effect(effects[i], this.#dirty_effects, this.#maybe_dirty_effects);
  480. }
  481. }
  482. /**
  483. * Associate a change to a given source with the current
  484. * batch, noting its previous and current values
  485. * @param {Value} source
  486. * @param {any} old_value
  487. * @param {boolean} [is_derived]
  488. */
  489. capture(source2, old_value, is_derived = false) {
  490. if (old_value !== UNINITIALIZED && !this.previous.has(source2)) {
  491. this.previous.set(source2, old_value);
  492. }
  493. if ((source2.f & ERROR_VALUE) === 0) {
  494. this.current.set(source2, [source2.v, is_derived]);
  495. batch_values?.set(source2, source2.v);
  496. }
  497. }
  498. activate() {
  499. current_batch = this;
  500. }
  501. deactivate() {
  502. current_batch = null;
  503. batch_values = null;
  504. }
  505. flush() {
  506. try {
  507. is_processing = true;
  508. current_batch = this;
  509. this.#process();
  510. } finally {
  511. flush_count = 0;
  512. last_scheduled_effect = null;
  513. collected_effects = null;
  514. legacy_updates = null;
  515. is_processing = false;
  516. current_batch = null;
  517. batch_values = null;
  518. old_values.clear();
  519. }
  520. }
  521. discard() {
  522. for (const fn of this.#discard_callbacks) fn(this);
  523. this.#discard_callbacks.clear();
  524. batches.delete(this);
  525. }
  526. /**
  527. * @param {Effect} effect
  528. */
  529. register_created_effect(effect) {
  530. this.#new_effects.push(effect);
  531. }
  532. #commit() {
  533. for (const batch of batches) {
  534. var is_earlier = batch.id < this.id;
  535. var sources = [];
  536. for (const [source3, [value, is_derived]] of this.current) {
  537. if (batch.current.has(source3)) {
  538. var batch_value = (
  539. /** @type {[any, boolean]} */
  540. batch.current.get(source3)[0]
  541. );
  542. if (is_earlier && value !== batch_value) {
  543. batch.current.set(source3, [value, is_derived]);
  544. } else {
  545. continue;
  546. }
  547. }
  548. sources.push(source3);
  549. }
  550. var others = [...batch.current.keys()].filter((s) => !this.current.has(s));
  551. if (others.length === 0) {
  552. if (is_earlier) {
  553. batch.discard();
  554. }
  555. } else if (sources.length > 0) {
  556. batch.activate();
  557. var marked = /* @__PURE__ */ new Set();
  558. var checked = /* @__PURE__ */ new Map();
  559. for (var source2 of sources) {
  560. mark_effects(source2, others, marked, checked);
  561. }
  562. checked = /* @__PURE__ */ new Map();
  563. var current_unequal = [...batch.current.keys()].filter(
  564. (c) => this.current.has(c) ? (
  565. /** @type {[any, boolean]} */
  566. this.current.get(c)[0] !== c
  567. ) : true
  568. );
  569. for (const effect of this.#new_effects) {
  570. if ((effect.f & (DESTROYED | INERT | EAGER_EFFECT)) === 0 && depends_on(effect, current_unequal, checked)) {
  571. if ((effect.f & (ASYNC | BLOCK_EFFECT)) !== 0) {
  572. set_signal_status(effect, DIRTY);
  573. batch.schedule(effect);
  574. } else {
  575. batch.#dirty_effects.add(effect);
  576. }
  577. }
  578. }
  579. if (batch.#roots.length > 0) {
  580. batch.apply();
  581. for (var root2 of batch.#roots) {
  582. batch.#traverse(root2, [], []);
  583. }
  584. batch.#roots = [];
  585. }
  586. batch.deactivate();
  587. }
  588. }
  589. for (const batch of batches) {
  590. if (batch.#blockers.has(this)) {
  591. batch.#blockers.delete(this);
  592. if (batch.#blockers.size === 0 && !batch.#is_deferred()) {
  593. batch.activate();
  594. batch.#process();
  595. }
  596. }
  597. }
  598. }
  599. /**
  600. * @param {boolean} blocking
  601. * @param {Effect} effect
  602. */
  603. increment(blocking, effect) {
  604. let pending_count = this.#pending.get(effect) ?? 0;
  605. this.#pending.set(effect, pending_count + 1);
  606. if (blocking) {
  607. let blocking_pending_count = this.#blocking_pending.get(effect) ?? 0;
  608. this.#blocking_pending.set(effect, blocking_pending_count + 1);
  609. }
  610. }
  611. /**
  612. * @param {boolean} blocking
  613. * @param {Effect} effect
  614. * @param {boolean} skip - whether to skip updates (because this is triggered by a stale reaction)
  615. */
  616. decrement(blocking, effect, skip) {
  617. let pending_count = this.#pending.get(effect) ?? 0;
  618. if (pending_count === 1) {
  619. this.#pending.delete(effect);
  620. } else {
  621. this.#pending.set(effect, pending_count - 1);
  622. }
  623. if (blocking) {
  624. let blocking_pending_count = this.#blocking_pending.get(effect) ?? 0;
  625. if (blocking_pending_count === 1) {
  626. this.#blocking_pending.delete(effect);
  627. } else {
  628. this.#blocking_pending.set(effect, blocking_pending_count - 1);
  629. }
  630. }
  631. if (this.#decrement_queued || skip) return;
  632. this.#decrement_queued = true;
  633. queue_micro_task(() => {
  634. this.#decrement_queued = false;
  635. this.flush();
  636. });
  637. }
  638. /**
  639. * @param {Set<Effect>} dirty_effects
  640. * @param {Set<Effect>} maybe_dirty_effects
  641. */
  642. transfer_effects(dirty_effects, maybe_dirty_effects) {
  643. for (const e of dirty_effects) {
  644. this.#dirty_effects.add(e);
  645. }
  646. for (const e of maybe_dirty_effects) {
  647. this.#maybe_dirty_effects.add(e);
  648. }
  649. dirty_effects.clear();
  650. maybe_dirty_effects.clear();
  651. }
  652. /** @param {(batch: Batch) => void} fn */
  653. oncommit(fn) {
  654. this.#commit_callbacks.add(fn);
  655. }
  656. /** @param {(batch: Batch) => void} fn */
  657. ondiscard(fn) {
  658. this.#discard_callbacks.add(fn);
  659. }
  660. settled() {
  661. return (this.#deferred ??= deferred()).promise;
  662. }
  663. static ensure() {
  664. if (current_batch === null) {
  665. const batch = current_batch = new Batch();
  666. if (!is_processing) {
  667. batches.add(current_batch);
  668. if (!is_flushing_sync) {
  669. queue_micro_task(() => {
  670. if (current_batch !== batch) {
  671. return;
  672. }
  673. batch.flush();
  674. });
  675. }
  676. }
  677. }
  678. return current_batch;
  679. }
  680. apply() {
  681. {
  682. batch_values = null;
  683. return;
  684. }
  685. }
  686. /**
  687. *
  688. * @param {Effect} effect
  689. */
  690. schedule(effect) {
  691. last_scheduled_effect = effect;
  692. if (effect.b?.is_pending && (effect.f & (EFFECT | RENDER_EFFECT | MANAGED_EFFECT)) !== 0 && (effect.f & REACTION_RAN) === 0) {
  693. effect.b.defer_effect(effect);
  694. return;
  695. }
  696. var e = effect;
  697. while (e.parent !== null) {
  698. e = e.parent;
  699. var flags2 = e.f;
  700. if (collected_effects !== null && e === active_effect) {
  701. if ((active_reaction === null || (active_reaction.f & DERIVED) === 0) && true) {
  702. return;
  703. }
  704. }
  705. if ((flags2 & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
  706. if ((flags2 & CLEAN) === 0) {
  707. return;
  708. }
  709. e.f ^= CLEAN;
  710. }
  711. }
  712. this.#roots.push(e);
  713. }
  714. }
  715. function flushSync(fn) {
  716. var was_flushing_sync = is_flushing_sync;
  717. is_flushing_sync = true;
  718. try {
  719. var result;
  720. if (fn) ;
  721. while (true) {
  722. flush_tasks();
  723. if (current_batch === null) {
  724. return (
  725. /** @type {T} */
  726. result
  727. );
  728. }
  729. current_batch.flush();
  730. }
  731. } finally {
  732. is_flushing_sync = was_flushing_sync;
  733. }
  734. }
  735. function infinite_loop_guard() {
  736. try {
  737. effect_update_depth_exceeded();
  738. } catch (error) {
  739. invoke_error_boundary(error, last_scheduled_effect);
  740. }
  741. }
  742. let eager_block_effects = null;
  743. function flush_queued_effects(effects) {
  744. var length = effects.length;
  745. if (length === 0) return;
  746. var i = 0;
  747. while (i < length) {
  748. var effect = effects[i++];
  749. if ((effect.f & (DESTROYED | INERT)) === 0 && is_dirty(effect)) {
  750. eager_block_effects = /* @__PURE__ */ new Set();
  751. update_effect(effect);
  752. if (effect.deps === null && effect.first === null && effect.nodes === null && effect.teardown === null && effect.ac === null) {
  753. unlink_effect(effect);
  754. }
  755. if (eager_block_effects?.size > 0) {
  756. old_values.clear();
  757. for (const e of eager_block_effects) {
  758. if ((e.f & (DESTROYED | INERT)) !== 0) continue;
  759. const ordered_effects = [e];
  760. let ancestor = e.parent;
  761. while (ancestor !== null) {
  762. if (eager_block_effects.has(ancestor)) {
  763. eager_block_effects.delete(ancestor);
  764. ordered_effects.push(ancestor);
  765. }
  766. ancestor = ancestor.parent;
  767. }
  768. for (let j = ordered_effects.length - 1; j >= 0; j--) {
  769. const e2 = ordered_effects[j];
  770. if ((e2.f & (DESTROYED | INERT)) !== 0) continue;
  771. update_effect(e2);
  772. }
  773. }
  774. eager_block_effects.clear();
  775. }
  776. }
  777. }
  778. eager_block_effects = null;
  779. }
  780. function mark_effects(value, sources, marked, checked) {
  781. if (marked.has(value)) return;
  782. marked.add(value);
  783. if (value.reactions !== null) {
  784. for (const reaction of value.reactions) {
  785. const flags2 = reaction.f;
  786. if ((flags2 & DERIVED) !== 0) {
  787. mark_effects(
  788. /** @type {Derived} */
  789. reaction,
  790. sources,
  791. marked,
  792. checked
  793. );
  794. } else if ((flags2 & (ASYNC | BLOCK_EFFECT)) !== 0 && (flags2 & DIRTY) === 0 && depends_on(reaction, sources, checked)) {
  795. set_signal_status(reaction, DIRTY);
  796. schedule_effect(
  797. /** @type {Effect} */
  798. reaction
  799. );
  800. }
  801. }
  802. }
  803. }
  804. function depends_on(reaction, sources, checked) {
  805. const depends = checked.get(reaction);
  806. if (depends !== void 0) return depends;
  807. if (reaction.deps !== null) {
  808. for (const dep of reaction.deps) {
  809. if (includes.call(sources, dep)) {
  810. return true;
  811. }
  812. if ((dep.f & DERIVED) !== 0 && depends_on(
  813. /** @type {Derived} */
  814. dep,
  815. sources,
  816. checked
  817. )) {
  818. checked.set(
  819. /** @type {Derived} */
  820. dep,
  821. true
  822. );
  823. return true;
  824. }
  825. }
  826. }
  827. checked.set(reaction, false);
  828. return false;
  829. }
  830. function schedule_effect(effect) {
  831. current_batch.schedule(effect);
  832. }
  833. function reset_branch(effect, tracked) {
  834. if ((effect.f & BRANCH_EFFECT) !== 0 && (effect.f & CLEAN) !== 0) {
  835. return;
  836. }
  837. if ((effect.f & DIRTY) !== 0) {
  838. tracked.d.push(effect);
  839. } else if ((effect.f & MAYBE_DIRTY) !== 0) {
  840. tracked.m.push(effect);
  841. }
  842. set_signal_status(effect, CLEAN);
  843. var e = effect.first;
  844. while (e !== null) {
  845. reset_branch(e, tracked);
  846. e = e.next;
  847. }
  848. }
  849. function reset_all(effect) {
  850. set_signal_status(effect, CLEAN);
  851. var e = effect.first;
  852. while (e !== null) {
  853. reset_all(e);
  854. e = e.next;
  855. }
  856. }
  857. function createSubscriber(start) {
  858. let subscribers = 0;
  859. let version = source(0);
  860. let stop;
  861. return () => {
  862. if (effect_tracking()) {
  863. get(version);
  864. render_effect(() => {
  865. if (subscribers === 0) {
  866. stop = untrack(() => start(() => increment(version)));
  867. }
  868. subscribers += 1;
  869. return () => {
  870. queue_micro_task(() => {
  871. subscribers -= 1;
  872. if (subscribers === 0) {
  873. stop?.();
  874. stop = void 0;
  875. increment(version);
  876. }
  877. });
  878. };
  879. });
  880. }
  881. };
  882. }
  883. var flags = EFFECT_TRANSPARENT | EFFECT_PRESERVED;
  884. function boundary(node, props, children, transform_error) {
  885. new Boundary(node, props, children, transform_error);
  886. }
  887. class Boundary {
  888. /** @type {Boundary | null} */
  889. parent;
  890. is_pending = false;
  891. /**
  892. * API-level transformError transform function. Transforms errors before they reach the `failed` snippet.
  893. * Inherited from parent boundary, or defaults to identity.
  894. * @type {(error: unknown) => unknown}
  895. */
  896. transform_error;
  897. /** @type {TemplateNode} */
  898. #anchor;
  899. /** @type {TemplateNode | null} */
  900. #hydrate_open = hydrating ? hydrate_node : null;
  901. /** @type {BoundaryProps} */
  902. #props;
  903. /** @type {((anchor: Node) => void)} */
  904. #children;
  905. /** @type {Effect} */
  906. #effect;
  907. /** @type {Effect | null} */
  908. #main_effect = null;
  909. /** @type {Effect | null} */
  910. #pending_effect = null;
  911. /** @type {Effect | null} */
  912. #failed_effect = null;
  913. /** @type {DocumentFragment | null} */
  914. #offscreen_fragment = null;
  915. #local_pending_count = 0;
  916. #pending_count = 0;
  917. #pending_count_update_queued = false;
  918. /** @type {Set<Effect>} */
  919. #dirty_effects = /* @__PURE__ */ new Set();
  920. /** @type {Set<Effect>} */
  921. #maybe_dirty_effects = /* @__PURE__ */ new Set();
  922. /**
  923. * A source containing the number of pending async deriveds/expressions.
  924. * Only created if `$effect.pending()` is used inside the boundary,
  925. * otherwise updating the source results in needless `Batch.ensure()`
  926. * calls followed by no-op flushes
  927. * @type {Source<number> | null}
  928. */
  929. #effect_pending = null;
  930. #effect_pending_subscriber = createSubscriber(() => {
  931. this.#effect_pending = source(this.#local_pending_count);
  932. return () => {
  933. this.#effect_pending = null;
  934. };
  935. });
  936. /**
  937. * @param {TemplateNode} node
  938. * @param {BoundaryProps} props
  939. * @param {((anchor: Node) => void)} children
  940. * @param {((error: unknown) => unknown) | undefined} [transform_error]
  941. */
  942. constructor(node, props, children, transform_error) {
  943. this.#anchor = node;
  944. this.#props = props;
  945. this.#children = (anchor) => {
  946. var effect = (
  947. /** @type {Effect} */
  948. active_effect
  949. );
  950. effect.b = this;
  951. effect.f |= BOUNDARY_EFFECT;
  952. children(anchor);
  953. };
  954. this.parent = /** @type {Effect} */
  955. active_effect.b;
  956. this.transform_error = transform_error ?? this.parent?.transform_error ?? ((e) => e);
  957. this.#effect = block(() => {
  958. if (hydrating) {
  959. const comment = (
  960. /** @type {Comment} */
  961. this.#hydrate_open
  962. );
  963. hydrate_next();
  964. const server_rendered_pending = comment.data === HYDRATION_START_ELSE;
  965. const server_rendered_failed = comment.data.startsWith(HYDRATION_START_FAILED);
  966. if (server_rendered_failed) {
  967. const serialized_error = JSON.parse(comment.data.slice(HYDRATION_START_FAILED.length));
  968. this.#hydrate_failed_content(serialized_error);
  969. } else if (server_rendered_pending) {
  970. this.#hydrate_pending_content();
  971. } else {
  972. this.#hydrate_resolved_content();
  973. }
  974. } else {
  975. this.#render();
  976. }
  977. }, flags);
  978. if (hydrating) {
  979. this.#anchor = hydrate_node;
  980. }
  981. }
  982. #hydrate_resolved_content() {
  983. try {
  984. this.#main_effect = branch(() => this.#children(this.#anchor));
  985. } catch (error) {
  986. this.error(error);
  987. }
  988. }
  989. /**
  990. * @param {unknown} error The deserialized error from the server's hydration comment
  991. */
  992. #hydrate_failed_content(error) {
  993. const failed = this.#props.failed;
  994. if (!failed) return;
  995. this.#failed_effect = branch(() => {
  996. failed(
  997. this.#anchor,
  998. () => error,
  999. () => () => {
  1000. }
  1001. );
  1002. });
  1003. }
  1004. #hydrate_pending_content() {
  1005. const pending = this.#props.pending;
  1006. if (!pending) return;
  1007. this.is_pending = true;
  1008. this.#pending_effect = branch(() => pending(this.#anchor));
  1009. queue_micro_task(() => {
  1010. var fragment = this.#offscreen_fragment = document.createDocumentFragment();
  1011. var anchor = create_text();
  1012. fragment.append(anchor);
  1013. this.#main_effect = this.#run(() => {
  1014. return branch(() => this.#children(anchor));
  1015. });
  1016. if (this.#pending_count === 0) {
  1017. this.#anchor.before(fragment);
  1018. this.#offscreen_fragment = null;
  1019. pause_effect(
  1020. /** @type {Effect} */
  1021. this.#pending_effect,
  1022. () => {
  1023. this.#pending_effect = null;
  1024. }
  1025. );
  1026. this.#resolve(
  1027. /** @type {Batch} */
  1028. current_batch
  1029. );
  1030. }
  1031. });
  1032. }
  1033. #render() {
  1034. try {
  1035. this.is_pending = this.has_pending_snippet();
  1036. this.#pending_count = 0;
  1037. this.#local_pending_count = 0;
  1038. this.#main_effect = branch(() => {
  1039. this.#children(this.#anchor);
  1040. });
  1041. if (this.#pending_count > 0) {
  1042. var fragment = this.#offscreen_fragment = document.createDocumentFragment();
  1043. move_effect(this.#main_effect, fragment);
  1044. const pending = (
  1045. /** @type {(anchor: Node) => void} */
  1046. this.#props.pending
  1047. );
  1048. this.#pending_effect = branch(() => pending(this.#anchor));
  1049. } else {
  1050. this.#resolve(
  1051. /** @type {Batch} */
  1052. current_batch
  1053. );
  1054. }
  1055. } catch (error) {
  1056. this.error(error);
  1057. }
  1058. }
  1059. /**
  1060. * @param {Batch} batch
  1061. */
  1062. #resolve(batch) {
  1063. this.is_pending = false;
  1064. batch.transfer_effects(this.#dirty_effects, this.#maybe_dirty_effects);
  1065. }
  1066. /**
  1067. * Defer an effect inside a pending boundary until the boundary resolves
  1068. * @param {Effect} effect
  1069. */
  1070. defer_effect(effect) {
  1071. defer_effect(effect, this.#dirty_effects, this.#maybe_dirty_effects);
  1072. }
  1073. /**
  1074. * Returns `false` if the effect exists inside a boundary whose pending snippet is shown
  1075. * @returns {boolean}
  1076. */
  1077. is_rendered() {
  1078. return !this.is_pending && (!this.parent || this.parent.is_rendered());
  1079. }
  1080. has_pending_snippet() {
  1081. return !!this.#props.pending;
  1082. }
  1083. /**
  1084. * @template T
  1085. * @param {() => T} fn
  1086. */
  1087. #run(fn) {
  1088. var previous_effect = active_effect;
  1089. var previous_reaction = active_reaction;
  1090. var previous_ctx = component_context;
  1091. set_active_effect(this.#effect);
  1092. set_active_reaction(this.#effect);
  1093. set_component_context(this.#effect.ctx);
  1094. try {
  1095. Batch.ensure();
  1096. return fn();
  1097. } catch (e) {
  1098. handle_error(e);
  1099. return null;
  1100. } finally {
  1101. set_active_effect(previous_effect);
  1102. set_active_reaction(previous_reaction);
  1103. set_component_context(previous_ctx);
  1104. }
  1105. }
  1106. /**
  1107. * Updates the pending count associated with the currently visible pending snippet,
  1108. * if any, such that we can replace the snippet with content once work is done
  1109. * @param {1 | -1} d
  1110. * @param {Batch} batch
  1111. */
  1112. #update_pending_count(d, batch) {
  1113. if (!this.has_pending_snippet()) {
  1114. if (this.parent) {
  1115. this.parent.#update_pending_count(d, batch);
  1116. }
  1117. return;
  1118. }
  1119. this.#pending_count += d;
  1120. if (this.#pending_count === 0) {
  1121. this.#resolve(batch);
  1122. if (this.#pending_effect) {
  1123. pause_effect(this.#pending_effect, () => {
  1124. this.#pending_effect = null;
  1125. });
  1126. }
  1127. if (this.#offscreen_fragment) {
  1128. this.#anchor.before(this.#offscreen_fragment);
  1129. this.#offscreen_fragment = null;
  1130. }
  1131. }
  1132. }
  1133. /**
  1134. * Update the source that powers `$effect.pending()` inside this boundary,
  1135. * and controls when the current `pending` snippet (if any) is removed.
  1136. * Do not call from inside the class
  1137. * @param {1 | -1} d
  1138. * @param {Batch} batch
  1139. */
  1140. update_pending_count(d, batch) {
  1141. this.#update_pending_count(d, batch);
  1142. this.#local_pending_count += d;
  1143. if (!this.#effect_pending || this.#pending_count_update_queued) return;
  1144. this.#pending_count_update_queued = true;
  1145. queue_micro_task(() => {
  1146. this.#pending_count_update_queued = false;
  1147. if (this.#effect_pending) {
  1148. internal_set(this.#effect_pending, this.#local_pending_count);
  1149. }
  1150. });
  1151. }
  1152. get_effect_pending() {
  1153. this.#effect_pending_subscriber();
  1154. return get(
  1155. /** @type {Source<number>} */
  1156. this.#effect_pending
  1157. );
  1158. }
  1159. /** @param {unknown} error */
  1160. error(error) {
  1161. var onerror = this.#props.onerror;
  1162. let failed = this.#props.failed;
  1163. if (!onerror && !failed) {
  1164. throw error;
  1165. }
  1166. if (this.#main_effect) {
  1167. destroy_effect(this.#main_effect);
  1168. this.#main_effect = null;
  1169. }
  1170. if (this.#pending_effect) {
  1171. destroy_effect(this.#pending_effect);
  1172. this.#pending_effect = null;
  1173. }
  1174. if (this.#failed_effect) {
  1175. destroy_effect(this.#failed_effect);
  1176. this.#failed_effect = null;
  1177. }
  1178. if (hydrating) {
  1179. set_hydrate_node(
  1180. /** @type {TemplateNode} */
  1181. this.#hydrate_open
  1182. );
  1183. next();
  1184. set_hydrate_node(skip_nodes());
  1185. }
  1186. var did_reset = false;
  1187. var calling_on_error = false;
  1188. const reset = () => {
  1189. if (did_reset) {
  1190. svelte_boundary_reset_noop();
  1191. return;
  1192. }
  1193. did_reset = true;
  1194. if (calling_on_error) {
  1195. svelte_boundary_reset_onerror();
  1196. }
  1197. if (this.#failed_effect !== null) {
  1198. pause_effect(this.#failed_effect, () => {
  1199. this.#failed_effect = null;
  1200. });
  1201. }
  1202. this.#run(() => {
  1203. this.#render();
  1204. });
  1205. };
  1206. const handle_error_result = (transformed_error) => {
  1207. try {
  1208. calling_on_error = true;
  1209. onerror?.(transformed_error, reset);
  1210. calling_on_error = false;
  1211. } catch (error2) {
  1212. invoke_error_boundary(error2, this.#effect && this.#effect.parent);
  1213. }
  1214. if (failed) {
  1215. this.#failed_effect = this.#run(() => {
  1216. try {
  1217. return branch(() => {
  1218. var effect = (
  1219. /** @type {Effect} */
  1220. active_effect
  1221. );
  1222. effect.b = this;
  1223. effect.f |= BOUNDARY_EFFECT;
  1224. failed(
  1225. this.#anchor,
  1226. () => transformed_error,
  1227. () => reset
  1228. );
  1229. });
  1230. } catch (error2) {
  1231. invoke_error_boundary(
  1232. error2,
  1233. /** @type {Effect} */
  1234. this.#effect.parent
  1235. );
  1236. return null;
  1237. }
  1238. });
  1239. }
  1240. };
  1241. queue_micro_task(() => {
  1242. var result;
  1243. try {
  1244. result = this.transform_error(error);
  1245. } catch (e) {
  1246. invoke_error_boundary(e, this.#effect && this.#effect.parent);
  1247. return;
  1248. }
  1249. if (result !== null && typeof result === "object" && typeof /** @type {any} */
  1250. result.then === "function") {
  1251. result.then(
  1252. handle_error_result,
  1253. /** @param {unknown} e */
  1254. (e) => invoke_error_boundary(e, this.#effect && this.#effect.parent)
  1255. );
  1256. } else {
  1257. handle_error_result(result);
  1258. }
  1259. });
  1260. }
  1261. }
  1262. function destroy_derived_effects(derived2) {
  1263. var effects = derived2.effects;
  1264. if (effects !== null) {
  1265. derived2.effects = null;
  1266. for (var i = 0; i < effects.length; i += 1) {
  1267. destroy_effect(
  1268. /** @type {Effect} */
  1269. effects[i]
  1270. );
  1271. }
  1272. }
  1273. }
  1274. function get_derived_parent_effect(derived2) {
  1275. var parent = derived2.parent;
  1276. while (parent !== null) {
  1277. if ((parent.f & DERIVED) === 0) {
  1278. return (parent.f & DESTROYED) === 0 ? (
  1279. /** @type {Effect} */
  1280. parent
  1281. ) : null;
  1282. }
  1283. parent = parent.parent;
  1284. }
  1285. return null;
  1286. }
  1287. function execute_derived(derived2) {
  1288. var value;
  1289. var prev_active_effect = active_effect;
  1290. set_active_effect(get_derived_parent_effect(derived2));
  1291. {
  1292. try {
  1293. derived2.f &= ~WAS_MARKED;
  1294. destroy_derived_effects(derived2);
  1295. value = update_reaction(derived2);
  1296. } finally {
  1297. set_active_effect(prev_active_effect);
  1298. }
  1299. }
  1300. return value;
  1301. }
  1302. function update_derived(derived2) {
  1303. var old_value = derived2.v;
  1304. var value = execute_derived(derived2);
  1305. if (!derived2.equals(value)) {
  1306. derived2.wv = increment_write_version();
  1307. if (!current_batch?.is_fork || derived2.deps === null) {
  1308. derived2.v = value;
  1309. current_batch?.capture(derived2, old_value, true);
  1310. if (derived2.deps === null) {
  1311. set_signal_status(derived2, CLEAN);
  1312. return;
  1313. }
  1314. }
  1315. }
  1316. if (is_destroying_effect) {
  1317. return;
  1318. }
  1319. if (batch_values !== null) {
  1320. if (effect_tracking() || current_batch?.is_fork) {
  1321. batch_values.set(derived2, value);
  1322. }
  1323. } else {
  1324. update_derived_status(derived2);
  1325. }
  1326. }
  1327. function freeze_derived_effects(derived2) {
  1328. if (derived2.effects === null) return;
  1329. for (const e of derived2.effects) {
  1330. if (e.teardown || e.ac) {
  1331. e.teardown?.();
  1332. e.ac?.abort(STALE_REACTION);
  1333. e.teardown = noop;
  1334. e.ac = null;
  1335. remove_reactions(e, 0);
  1336. destroy_effect_children(e);
  1337. }
  1338. }
  1339. }
  1340. function unfreeze_derived_effects(derived2) {
  1341. if (derived2.effects === null) return;
  1342. for (const e of derived2.effects) {
  1343. if (e.teardown) {
  1344. update_effect(e);
  1345. }
  1346. }
  1347. }
  1348. let eager_effects = /* @__PURE__ */ new Set();
  1349. const old_values = /* @__PURE__ */ new Map();
  1350. let eager_effects_deferred = false;
  1351. function source(v, stack) {
  1352. var signal = {
  1353. f: 0,
  1354. // TODO ideally we could skip this altogether, but it causes type errors
  1355. v,
  1356. reactions: null,
  1357. equals,
  1358. rv: 0,
  1359. wv: 0
  1360. };
  1361. return signal;
  1362. }
  1363. // @__NO_SIDE_EFFECTS__
  1364. function state(v, stack) {
  1365. const s = source(v);
  1366. push_reaction_value(s);
  1367. return s;
  1368. }
  1369. // @__NO_SIDE_EFFECTS__
  1370. function mutable_source(initial_value, immutable = false, trackable = true) {
  1371. const s = source(initial_value);
  1372. if (!immutable) {
  1373. s.equals = safe_equals;
  1374. }
  1375. return s;
  1376. }
  1377. function set(source2, value, should_proxy = false) {
  1378. if (active_reaction !== null && // since we are untracking the function inside `$inspect.with` we need to add this check
  1379. // to ensure we error if state is set inside an inspect effect
  1380. (!untracking || (active_reaction.f & EAGER_EFFECT) !== 0) && is_runes() && (active_reaction.f & (DERIVED | BLOCK_EFFECT | ASYNC | EAGER_EFFECT)) !== 0 && (current_sources === null || !includes.call(current_sources, source2))) {
  1381. state_unsafe_mutation();
  1382. }
  1383. let new_value = should_proxy ? proxy(value) : value;
  1384. return internal_set(source2, new_value, legacy_updates);
  1385. }
  1386. function internal_set(source2, value, updated_during_traversal = null) {
  1387. if (!source2.equals(value)) {
  1388. var old_value = source2.v;
  1389. if (is_destroying_effect) {
  1390. old_values.set(source2, value);
  1391. } else {
  1392. old_values.set(source2, old_value);
  1393. }
  1394. source2.v = value;
  1395. var batch = Batch.ensure();
  1396. batch.capture(source2, old_value);
  1397. if ((source2.f & DERIVED) !== 0) {
  1398. const derived2 = (
  1399. /** @type {Derived} */
  1400. source2
  1401. );
  1402. if ((source2.f & DIRTY) !== 0) {
  1403. execute_derived(derived2);
  1404. }
  1405. if (batch_values === null) {
  1406. update_derived_status(derived2);
  1407. }
  1408. }
  1409. source2.wv = increment_write_version();
  1410. mark_reactions(source2, DIRTY, updated_during_traversal);
  1411. if (active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
  1412. if (untracked_writes === null) {
  1413. set_untracked_writes([source2]);
  1414. } else {
  1415. untracked_writes.push(source2);
  1416. }
  1417. }
  1418. if (!batch.is_fork && eager_effects.size > 0 && !eager_effects_deferred) {
  1419. flush_eager_effects();
  1420. }
  1421. }
  1422. return value;
  1423. }
  1424. function flush_eager_effects() {
  1425. eager_effects_deferred = false;
  1426. for (const effect of eager_effects) {
  1427. if ((effect.f & CLEAN) !== 0) {
  1428. set_signal_status(effect, MAYBE_DIRTY);
  1429. }
  1430. if (is_dirty(effect)) {
  1431. update_effect(effect);
  1432. }
  1433. }
  1434. eager_effects.clear();
  1435. }
  1436. function increment(source2) {
  1437. set(source2, source2.v + 1);
  1438. }
  1439. function mark_reactions(signal, status, updated_during_traversal) {
  1440. var reactions = signal.reactions;
  1441. if (reactions === null) return;
  1442. var length = reactions.length;
  1443. for (var i = 0; i < length; i++) {
  1444. var reaction = reactions[i];
  1445. var flags2 = reaction.f;
  1446. var not_dirty = (flags2 & DIRTY) === 0;
  1447. if (not_dirty) {
  1448. set_signal_status(reaction, status);
  1449. }
  1450. if ((flags2 & DERIVED) !== 0) {
  1451. var derived2 = (
  1452. /** @type {Derived} */
  1453. reaction
  1454. );
  1455. batch_values?.delete(derived2);
  1456. if ((flags2 & WAS_MARKED) === 0) {
  1457. if (flags2 & CONNECTED) {
  1458. reaction.f |= WAS_MARKED;
  1459. }
  1460. mark_reactions(derived2, MAYBE_DIRTY, updated_during_traversal);
  1461. }
  1462. } else if (not_dirty) {
  1463. var effect = (
  1464. /** @type {Effect} */
  1465. reaction
  1466. );
  1467. if ((flags2 & BLOCK_EFFECT) !== 0 && eager_block_effects !== null) {
  1468. eager_block_effects.add(effect);
  1469. }
  1470. if (updated_during_traversal !== null) {
  1471. updated_during_traversal.push(effect);
  1472. } else {
  1473. schedule_effect(effect);
  1474. }
  1475. }
  1476. }
  1477. }
  1478. function proxy(value) {
  1479. if (typeof value !== "object" || value === null || STATE_SYMBOL in value) {
  1480. return value;
  1481. }
  1482. const prototype = get_prototype_of(value);
  1483. if (prototype !== object_prototype && prototype !== array_prototype) {
  1484. return value;
  1485. }
  1486. var sources = /* @__PURE__ */ new Map();
  1487. var is_proxied_array = is_array(value);
  1488. var version = /* @__PURE__ */ state(0);
  1489. var parent_version = update_version;
  1490. var with_parent = (fn) => {
  1491. if (update_version === parent_version) {
  1492. return fn();
  1493. }
  1494. var reaction = active_reaction;
  1495. var version2 = update_version;
  1496. set_active_reaction(null);
  1497. set_update_version(parent_version);
  1498. var result = fn();
  1499. set_active_reaction(reaction);
  1500. set_update_version(version2);
  1501. return result;
  1502. };
  1503. if (is_proxied_array) {
  1504. sources.set("length", /* @__PURE__ */ state(
  1505. /** @type {any[]} */
  1506. value.length
  1507. ));
  1508. }
  1509. return new Proxy(
  1510. /** @type {any} */
  1511. value,
  1512. {
  1513. defineProperty(_, prop, descriptor) {
  1514. if (!("value" in descriptor) || descriptor.configurable === false || descriptor.enumerable === false || descriptor.writable === false) {
  1515. state_descriptors_fixed();
  1516. }
  1517. var s = sources.get(prop);
  1518. if (s === void 0) {
  1519. with_parent(() => {
  1520. var s2 = /* @__PURE__ */ state(descriptor.value);
  1521. sources.set(prop, s2);
  1522. return s2;
  1523. });
  1524. } else {
  1525. set(s, descriptor.value, true);
  1526. }
  1527. return true;
  1528. },
  1529. deleteProperty(target, prop) {
  1530. var s = sources.get(prop);
  1531. if (s === void 0) {
  1532. if (prop in target) {
  1533. const s2 = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
  1534. sources.set(prop, s2);
  1535. increment(version);
  1536. }
  1537. } else {
  1538. set(s, UNINITIALIZED);
  1539. increment(version);
  1540. }
  1541. return true;
  1542. },
  1543. get(target, prop, receiver) {
  1544. if (prop === STATE_SYMBOL) {
  1545. return value;
  1546. }
  1547. var s = sources.get(prop);
  1548. var exists = prop in target;
  1549. if (s === void 0 && (!exists || get_descriptor(target, prop)?.writable)) {
  1550. s = with_parent(() => {
  1551. var p = proxy(exists ? target[prop] : UNINITIALIZED);
  1552. var s2 = /* @__PURE__ */ state(p);
  1553. return s2;
  1554. });
  1555. sources.set(prop, s);
  1556. }
  1557. if (s !== void 0) {
  1558. var v = get(s);
  1559. return v === UNINITIALIZED ? void 0 : v;
  1560. }
  1561. return Reflect.get(target, prop, receiver);
  1562. },
  1563. getOwnPropertyDescriptor(target, prop) {
  1564. var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
  1565. if (descriptor && "value" in descriptor) {
  1566. var s = sources.get(prop);
  1567. if (s) descriptor.value = get(s);
  1568. } else if (descriptor === void 0) {
  1569. var source2 = sources.get(prop);
  1570. var value2 = source2?.v;
  1571. if (source2 !== void 0 && value2 !== UNINITIALIZED) {
  1572. return {
  1573. enumerable: true,
  1574. configurable: true,
  1575. value: value2,
  1576. writable: true
  1577. };
  1578. }
  1579. }
  1580. return descriptor;
  1581. },
  1582. has(target, prop) {
  1583. if (prop === STATE_SYMBOL) {
  1584. return true;
  1585. }
  1586. var s = sources.get(prop);
  1587. var has = s !== void 0 && s.v !== UNINITIALIZED || Reflect.has(target, prop);
  1588. if (s !== void 0 || active_effect !== null && (!has || get_descriptor(target, prop)?.writable)) {
  1589. if (s === void 0) {
  1590. s = with_parent(() => {
  1591. var p = has ? proxy(target[prop]) : UNINITIALIZED;
  1592. var s2 = /* @__PURE__ */ state(p);
  1593. return s2;
  1594. });
  1595. sources.set(prop, s);
  1596. }
  1597. var value2 = get(s);
  1598. if (value2 === UNINITIALIZED) {
  1599. return false;
  1600. }
  1601. }
  1602. return has;
  1603. },
  1604. set(target, prop, value2, receiver) {
  1605. var s = sources.get(prop);
  1606. var has = prop in target;
  1607. if (is_proxied_array && prop === "length") {
  1608. for (var i = value2; i < /** @type {Source<number>} */
  1609. s.v; i += 1) {
  1610. var other_s = sources.get(i + "");
  1611. if (other_s !== void 0) {
  1612. set(other_s, UNINITIALIZED);
  1613. } else if (i in target) {
  1614. other_s = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
  1615. sources.set(i + "", other_s);
  1616. }
  1617. }
  1618. }
  1619. if (s === void 0) {
  1620. if (!has || get_descriptor(target, prop)?.writable) {
  1621. s = with_parent(() => /* @__PURE__ */ state(void 0));
  1622. set(s, proxy(value2));
  1623. sources.set(prop, s);
  1624. }
  1625. } else {
  1626. has = s.v !== UNINITIALIZED;
  1627. var p = with_parent(() => proxy(value2));
  1628. set(s, p);
  1629. }
  1630. var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
  1631. if (descriptor?.set) {
  1632. descriptor.set.call(receiver, value2);
  1633. }
  1634. if (!has) {
  1635. if (is_proxied_array && typeof prop === "string") {
  1636. var ls = (
  1637. /** @type {Source<number>} */
  1638. sources.get("length")
  1639. );
  1640. var n = Number(prop);
  1641. if (Number.isInteger(n) && n >= ls.v) {
  1642. set(ls, n + 1);
  1643. }
  1644. }
  1645. increment(version);
  1646. }
  1647. return true;
  1648. },
  1649. ownKeys(target) {
  1650. get(version);
  1651. var own_keys = Reflect.ownKeys(target).filter((key2) => {
  1652. var source3 = sources.get(key2);
  1653. return source3 === void 0 || source3.v !== UNINITIALIZED;
  1654. });
  1655. for (var [key, source2] of sources) {
  1656. if (source2.v !== UNINITIALIZED && !(key in target)) {
  1657. own_keys.push(key);
  1658. }
  1659. }
  1660. return own_keys;
  1661. },
  1662. setPrototypeOf() {
  1663. state_prototype_fixed();
  1664. }
  1665. }
  1666. );
  1667. }
  1668. var $window;
  1669. var first_child_getter;
  1670. var next_sibling_getter;
  1671. function init_operations() {
  1672. if ($window !== void 0) {
  1673. return;
  1674. }
  1675. $window = window;
  1676. var element_prototype = Element.prototype;
  1677. var node_prototype = Node.prototype;
  1678. var text_prototype = Text.prototype;
  1679. first_child_getter = get_descriptor(node_prototype, "firstChild").get;
  1680. next_sibling_getter = get_descriptor(node_prototype, "nextSibling").get;
  1681. if (is_extensible(element_prototype)) {
  1682. element_prototype.__click = void 0;
  1683. element_prototype.__className = void 0;
  1684. element_prototype.__attributes = null;
  1685. element_prototype.__style = void 0;
  1686. element_prototype.__e = void 0;
  1687. }
  1688. if (is_extensible(text_prototype)) {
  1689. text_prototype.__t = void 0;
  1690. }
  1691. }
  1692. function create_text(value = "") {
  1693. return document.createTextNode(value);
  1694. }
  1695. // @__NO_SIDE_EFFECTS__
  1696. function get_first_child(node) {
  1697. return (
  1698. /** @type {TemplateNode | null} */
  1699. first_child_getter.call(node)
  1700. );
  1701. }
  1702. // @__NO_SIDE_EFFECTS__
  1703. function get_next_sibling(node) {
  1704. return (
  1705. /** @type {TemplateNode | null} */
  1706. next_sibling_getter.call(node)
  1707. );
  1708. }
  1709. function clear_text_content(node) {
  1710. node.textContent = "";
  1711. }
  1712. function without_reactive_context(fn) {
  1713. var previous_reaction = active_reaction;
  1714. var previous_effect = active_effect;
  1715. set_active_reaction(null);
  1716. set_active_effect(null);
  1717. try {
  1718. return fn();
  1719. } finally {
  1720. set_active_reaction(previous_reaction);
  1721. set_active_effect(previous_effect);
  1722. }
  1723. }
  1724. function push_effect(effect, parent_effect) {
  1725. var parent_last = parent_effect.last;
  1726. if (parent_last === null) {
  1727. parent_effect.last = parent_effect.first = effect;
  1728. } else {
  1729. parent_last.next = effect;
  1730. effect.prev = parent_last;
  1731. parent_effect.last = effect;
  1732. }
  1733. }
  1734. function create_effect(type, fn) {
  1735. var parent = active_effect;
  1736. if (parent !== null && (parent.f & INERT) !== 0) {
  1737. type |= INERT;
  1738. }
  1739. var effect = {
  1740. ctx: component_context,
  1741. deps: null,
  1742. nodes: null,
  1743. f: type | DIRTY | CONNECTED,
  1744. first: null,
  1745. fn,
  1746. last: null,
  1747. next: null,
  1748. parent,
  1749. b: parent && parent.b,
  1750. prev: null,
  1751. teardown: null,
  1752. wv: 0,
  1753. ac: null
  1754. };
  1755. current_batch?.register_created_effect(effect);
  1756. var e = effect;
  1757. if ((type & EFFECT) !== 0) {
  1758. if (collected_effects !== null) {
  1759. collected_effects.push(effect);
  1760. } else {
  1761. Batch.ensure().schedule(effect);
  1762. }
  1763. } else if (fn !== null) {
  1764. try {
  1765. update_effect(effect);
  1766. } catch (e2) {
  1767. destroy_effect(effect);
  1768. throw e2;
  1769. }
  1770. if (e.deps === null && e.teardown === null && e.nodes === null && e.first === e.last && // either `null`, or a singular child
  1771. (e.f & EFFECT_PRESERVED) === 0) {
  1772. e = e.first;
  1773. if ((type & BLOCK_EFFECT) !== 0 && (type & EFFECT_TRANSPARENT) !== 0 && e !== null) {
  1774. e.f |= EFFECT_TRANSPARENT;
  1775. }
  1776. }
  1777. }
  1778. if (e !== null) {
  1779. e.parent = parent;
  1780. if (parent !== null) {
  1781. push_effect(e, parent);
  1782. }
  1783. if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0 && (type & ROOT_EFFECT) === 0) {
  1784. var derived2 = (
  1785. /** @type {Derived} */
  1786. active_reaction
  1787. );
  1788. (derived2.effects ??= []).push(e);
  1789. }
  1790. }
  1791. return effect;
  1792. }
  1793. function effect_tracking() {
  1794. return active_reaction !== null && !untracking;
  1795. }
  1796. function create_user_effect(fn) {
  1797. return create_effect(EFFECT | USER_EFFECT, fn);
  1798. }
  1799. function component_root(fn) {
  1800. Batch.ensure();
  1801. const effect = create_effect(ROOT_EFFECT | EFFECT_PRESERVED, fn);
  1802. return (options = {}) => {
  1803. return new Promise((fulfil) => {
  1804. if (options.outro) {
  1805. pause_effect(effect, () => {
  1806. destroy_effect(effect);
  1807. fulfil(void 0);
  1808. });
  1809. } else {
  1810. destroy_effect(effect);
  1811. fulfil(void 0);
  1812. }
  1813. });
  1814. };
  1815. }
  1816. function render_effect(fn, flags2 = 0) {
  1817. return create_effect(RENDER_EFFECT | flags2, fn);
  1818. }
  1819. function block(fn, flags2 = 0) {
  1820. var effect = create_effect(BLOCK_EFFECT | flags2, fn);
  1821. return effect;
  1822. }
  1823. function branch(fn) {
  1824. return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn);
  1825. }
  1826. function execute_effect_teardown(effect) {
  1827. var teardown = effect.teardown;
  1828. if (teardown !== null) {
  1829. const previously_destroying_effect = is_destroying_effect;
  1830. const previous_reaction = active_reaction;
  1831. set_is_destroying_effect(true);
  1832. set_active_reaction(null);
  1833. try {
  1834. teardown.call(null);
  1835. } finally {
  1836. set_is_destroying_effect(previously_destroying_effect);
  1837. set_active_reaction(previous_reaction);
  1838. }
  1839. }
  1840. }
  1841. function destroy_effect_children(signal, remove_dom = false) {
  1842. var effect = signal.first;
  1843. signal.first = signal.last = null;
  1844. while (effect !== null) {
  1845. const controller = effect.ac;
  1846. if (controller !== null) {
  1847. without_reactive_context(() => {
  1848. controller.abort(STALE_REACTION);
  1849. });
  1850. }
  1851. var next2 = effect.next;
  1852. if ((effect.f & ROOT_EFFECT) !== 0) {
  1853. effect.parent = null;
  1854. } else {
  1855. destroy_effect(effect, remove_dom);
  1856. }
  1857. effect = next2;
  1858. }
  1859. }
  1860. function destroy_block_effect_children(signal) {
  1861. var effect = signal.first;
  1862. while (effect !== null) {
  1863. var next2 = effect.next;
  1864. if ((effect.f & BRANCH_EFFECT) === 0) {
  1865. destroy_effect(effect);
  1866. }
  1867. effect = next2;
  1868. }
  1869. }
  1870. function destroy_effect(effect, remove_dom = true) {
  1871. var removed = false;
  1872. if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes !== null && effect.nodes.end !== null) {
  1873. remove_effect_dom(
  1874. effect.nodes.start,
  1875. /** @type {TemplateNode} */
  1876. effect.nodes.end
  1877. );
  1878. removed = true;
  1879. }
  1880. set_signal_status(effect, DESTROYING);
  1881. destroy_effect_children(effect, remove_dom && !removed);
  1882. remove_reactions(effect, 0);
  1883. var transitions = effect.nodes && effect.nodes.t;
  1884. if (transitions !== null) {
  1885. for (const transition of transitions) {
  1886. transition.stop();
  1887. }
  1888. }
  1889. execute_effect_teardown(effect);
  1890. effect.f ^= DESTROYING;
  1891. effect.f |= DESTROYED;
  1892. var parent = effect.parent;
  1893. if (parent !== null && parent.first !== null) {
  1894. unlink_effect(effect);
  1895. }
  1896. effect.next = effect.prev = effect.teardown = effect.ctx = effect.deps = effect.fn = effect.nodes = effect.ac = effect.b = null;
  1897. }
  1898. function remove_effect_dom(node, end) {
  1899. while (node !== null) {
  1900. var next2 = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
  1901. node.remove();
  1902. node = next2;
  1903. }
  1904. }
  1905. function unlink_effect(effect) {
  1906. var parent = effect.parent;
  1907. var prev = effect.prev;
  1908. var next2 = effect.next;
  1909. if (prev !== null) prev.next = next2;
  1910. if (next2 !== null) next2.prev = prev;
  1911. if (parent !== null) {
  1912. if (parent.first === effect) parent.first = next2;
  1913. if (parent.last === effect) parent.last = prev;
  1914. }
  1915. }
  1916. function pause_effect(effect, callback, destroy = true) {
  1917. var transitions = [];
  1918. pause_children(effect, transitions, true);
  1919. var fn = () => {
  1920. if (destroy) destroy_effect(effect);
  1921. if (callback) callback();
  1922. };
  1923. var remaining = transitions.length;
  1924. if (remaining > 0) {
  1925. var check = () => --remaining || fn();
  1926. for (var transition of transitions) {
  1927. transition.out(check);
  1928. }
  1929. } else {
  1930. fn();
  1931. }
  1932. }
  1933. function pause_children(effect, transitions, local) {
  1934. if ((effect.f & INERT) !== 0) return;
  1935. effect.f ^= INERT;
  1936. var t = effect.nodes && effect.nodes.t;
  1937. if (t !== null) {
  1938. for (const transition of t) {
  1939. if (transition.is_global || local) {
  1940. transitions.push(transition);
  1941. }
  1942. }
  1943. }
  1944. var child = effect.first;
  1945. while (child !== null) {
  1946. var sibling = child.next;
  1947. var transparent = (child.f & EFFECT_TRANSPARENT) !== 0 || // If this is a branch effect without a block effect parent,
  1948. // it means the parent block effect was pruned. In that case,
  1949. // transparency information was transferred to the branch effect.
  1950. (child.f & BRANCH_EFFECT) !== 0 && (effect.f & BLOCK_EFFECT) !== 0;
  1951. pause_children(child, transitions, transparent ? local : false);
  1952. child = sibling;
  1953. }
  1954. }
  1955. function move_effect(effect, fragment) {
  1956. if (!effect.nodes) return;
  1957. var node = effect.nodes.start;
  1958. var end = effect.nodes.end;
  1959. while (node !== null) {
  1960. var next2 = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
  1961. fragment.append(node);
  1962. node = next2;
  1963. }
  1964. }
  1965. let is_updating_effect = false;
  1966. let is_destroying_effect = false;
  1967. function set_is_destroying_effect(value) {
  1968. is_destroying_effect = value;
  1969. }
  1970. let active_reaction = null;
  1971. let untracking = false;
  1972. function set_active_reaction(reaction) {
  1973. active_reaction = reaction;
  1974. }
  1975. let active_effect = null;
  1976. function set_active_effect(effect) {
  1977. active_effect = effect;
  1978. }
  1979. let current_sources = null;
  1980. function push_reaction_value(value) {
  1981. if (active_reaction !== null && true) {
  1982. if (current_sources === null) {
  1983. current_sources = [value];
  1984. } else {
  1985. current_sources.push(value);
  1986. }
  1987. }
  1988. }
  1989. let new_deps = null;
  1990. let skipped_deps = 0;
  1991. let untracked_writes = null;
  1992. function set_untracked_writes(value) {
  1993. untracked_writes = value;
  1994. }
  1995. let write_version = 1;
  1996. let read_version = 0;
  1997. let update_version = read_version;
  1998. function set_update_version(value) {
  1999. update_version = value;
  2000. }
  2001. function increment_write_version() {
  2002. return ++write_version;
  2003. }
  2004. function is_dirty(reaction) {
  2005. var flags2 = reaction.f;
  2006. if ((flags2 & DIRTY) !== 0) {
  2007. return true;
  2008. }
  2009. if (flags2 & DERIVED) {
  2010. reaction.f &= ~WAS_MARKED;
  2011. }
  2012. if ((flags2 & MAYBE_DIRTY) !== 0) {
  2013. var dependencies = (
  2014. /** @type {Value[]} */
  2015. reaction.deps
  2016. );
  2017. var length = dependencies.length;
  2018. for (var i = 0; i < length; i++) {
  2019. var dependency = dependencies[i];
  2020. if (is_dirty(
  2021. /** @type {Derived} */
  2022. dependency
  2023. )) {
  2024. update_derived(
  2025. /** @type {Derived} */
  2026. dependency
  2027. );
  2028. }
  2029. if (dependency.wv > reaction.wv) {
  2030. return true;
  2031. }
  2032. }
  2033. if ((flags2 & CONNECTED) !== 0 && // During time traveling we don't want to reset the status so that
  2034. // traversal of the graph in the other batches still happens
  2035. batch_values === null) {
  2036. set_signal_status(reaction, CLEAN);
  2037. }
  2038. }
  2039. return false;
  2040. }
  2041. function schedule_possible_effect_self_invalidation(signal, effect, root2 = true) {
  2042. var reactions = signal.reactions;
  2043. if (reactions === null) return;
  2044. if (current_sources !== null && includes.call(current_sources, signal)) {
  2045. return;
  2046. }
  2047. for (var i = 0; i < reactions.length; i++) {
  2048. var reaction = reactions[i];
  2049. if ((reaction.f & DERIVED) !== 0) {
  2050. schedule_possible_effect_self_invalidation(
  2051. /** @type {Derived} */
  2052. reaction,
  2053. effect,
  2054. false
  2055. );
  2056. } else if (effect === reaction) {
  2057. if (root2) {
  2058. set_signal_status(reaction, DIRTY);
  2059. } else if ((reaction.f & CLEAN) !== 0) {
  2060. set_signal_status(reaction, MAYBE_DIRTY);
  2061. }
  2062. schedule_effect(
  2063. /** @type {Effect} */
  2064. reaction
  2065. );
  2066. }
  2067. }
  2068. }
  2069. function update_reaction(reaction) {
  2070. var previous_deps = new_deps;
  2071. var previous_skipped_deps = skipped_deps;
  2072. var previous_untracked_writes = untracked_writes;
  2073. var previous_reaction = active_reaction;
  2074. var previous_sources = current_sources;
  2075. var previous_component_context = component_context;
  2076. var previous_untracking = untracking;
  2077. var previous_update_version = update_version;
  2078. var flags2 = reaction.f;
  2079. new_deps = /** @type {null | Value[]} */
  2080. null;
  2081. skipped_deps = 0;
  2082. untracked_writes = null;
  2083. active_reaction = (flags2 & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
  2084. current_sources = null;
  2085. set_component_context(reaction.ctx);
  2086. untracking = false;
  2087. update_version = ++read_version;
  2088. if (reaction.ac !== null) {
  2089. without_reactive_context(() => {
  2090. reaction.ac.abort(STALE_REACTION);
  2091. });
  2092. reaction.ac = null;
  2093. }
  2094. try {
  2095. reaction.f |= REACTION_IS_UPDATING;
  2096. var fn = (
  2097. /** @type {Function} */
  2098. reaction.fn
  2099. );
  2100. var result = fn();
  2101. reaction.f |= REACTION_RAN;
  2102. var deps = reaction.deps;
  2103. var is_fork = current_batch?.is_fork;
  2104. if (new_deps !== null) {
  2105. var i;
  2106. if (!is_fork) {
  2107. remove_reactions(reaction, skipped_deps);
  2108. }
  2109. if (deps !== null && skipped_deps > 0) {
  2110. deps.length = skipped_deps + new_deps.length;
  2111. for (i = 0; i < new_deps.length; i++) {
  2112. deps[skipped_deps + i] = new_deps[i];
  2113. }
  2114. } else {
  2115. reaction.deps = deps = new_deps;
  2116. }
  2117. if (effect_tracking() && (reaction.f & CONNECTED) !== 0) {
  2118. for (i = skipped_deps; i < deps.length; i++) {
  2119. (deps[i].reactions ??= []).push(reaction);
  2120. }
  2121. }
  2122. } else if (!is_fork && deps !== null && skipped_deps < deps.length) {
  2123. remove_reactions(reaction, skipped_deps);
  2124. deps.length = skipped_deps;
  2125. }
  2126. if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0) {
  2127. for (i = 0; i < /** @type {Source[]} */
  2128. untracked_writes.length; i++) {
  2129. schedule_possible_effect_self_invalidation(
  2130. untracked_writes[i],
  2131. /** @type {Effect} */
  2132. reaction
  2133. );
  2134. }
  2135. }
  2136. if (previous_reaction !== null && previous_reaction !== reaction) {
  2137. read_version++;
  2138. if (previous_reaction.deps !== null) {
  2139. for (let i2 = 0; i2 < previous_skipped_deps; i2 += 1) {
  2140. previous_reaction.deps[i2].rv = read_version;
  2141. }
  2142. }
  2143. if (previous_deps !== null) {
  2144. for (const dep of previous_deps) {
  2145. dep.rv = read_version;
  2146. }
  2147. }
  2148. if (untracked_writes !== null) {
  2149. if (previous_untracked_writes === null) {
  2150. previous_untracked_writes = untracked_writes;
  2151. } else {
  2152. previous_untracked_writes.push(.../** @type {Source[]} */
  2153. untracked_writes);
  2154. }
  2155. }
  2156. }
  2157. if ((reaction.f & ERROR_VALUE) !== 0) {
  2158. reaction.f ^= ERROR_VALUE;
  2159. }
  2160. return result;
  2161. } catch (error) {
  2162. return handle_error(error);
  2163. } finally {
  2164. reaction.f ^= REACTION_IS_UPDATING;
  2165. new_deps = previous_deps;
  2166. skipped_deps = previous_skipped_deps;
  2167. untracked_writes = previous_untracked_writes;
  2168. active_reaction = previous_reaction;
  2169. current_sources = previous_sources;
  2170. set_component_context(previous_component_context);
  2171. untracking = previous_untracking;
  2172. update_version = previous_update_version;
  2173. }
  2174. }
  2175. function remove_reaction(signal, dependency) {
  2176. let reactions = dependency.reactions;
  2177. if (reactions !== null) {
  2178. var index = index_of.call(reactions, signal);
  2179. if (index !== -1) {
  2180. var new_length = reactions.length - 1;
  2181. if (new_length === 0) {
  2182. reactions = dependency.reactions = null;
  2183. } else {
  2184. reactions[index] = reactions[new_length];
  2185. reactions.pop();
  2186. }
  2187. }
  2188. }
  2189. if (reactions === null && (dependency.f & DERIVED) !== 0 && // Destroying a child effect while updating a parent effect can cause a dependency to appear
  2190. // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
  2191. // allows us to skip the expensive work of disconnecting and immediately reconnecting it
  2192. (new_deps === null || !includes.call(new_deps, dependency))) {
  2193. var derived2 = (
  2194. /** @type {Derived} */
  2195. dependency
  2196. );
  2197. if ((derived2.f & CONNECTED) !== 0) {
  2198. derived2.f ^= CONNECTED;
  2199. derived2.f &= ~WAS_MARKED;
  2200. }
  2201. update_derived_status(derived2);
  2202. freeze_derived_effects(derived2);
  2203. remove_reactions(derived2, 0);
  2204. }
  2205. }
  2206. function remove_reactions(signal, start_index) {
  2207. var dependencies = signal.deps;
  2208. if (dependencies === null) return;
  2209. for (var i = start_index; i < dependencies.length; i++) {
  2210. remove_reaction(signal, dependencies[i]);
  2211. }
  2212. }
  2213. function update_effect(effect) {
  2214. var flags2 = effect.f;
  2215. if ((flags2 & DESTROYED) !== 0) {
  2216. return;
  2217. }
  2218. set_signal_status(effect, CLEAN);
  2219. var previous_effect = active_effect;
  2220. var was_updating_effect = is_updating_effect;
  2221. active_effect = effect;
  2222. is_updating_effect = true;
  2223. try {
  2224. if ((flags2 & (BLOCK_EFFECT | MANAGED_EFFECT)) !== 0) {
  2225. destroy_block_effect_children(effect);
  2226. } else {
  2227. destroy_effect_children(effect);
  2228. }
  2229. execute_effect_teardown(effect);
  2230. var teardown = update_reaction(effect);
  2231. effect.teardown = typeof teardown === "function" ? teardown : null;
  2232. effect.wv = write_version;
  2233. var dep;
  2234. if (BROWSER && tracing_mode_flag && (effect.f & DIRTY) !== 0 && effect.deps !== null) ;
  2235. } finally {
  2236. is_updating_effect = was_updating_effect;
  2237. active_effect = previous_effect;
  2238. }
  2239. }
  2240. function get(signal) {
  2241. var flags2 = signal.f;
  2242. var is_derived = (flags2 & DERIVED) !== 0;
  2243. if (active_reaction !== null && !untracking) {
  2244. var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0;
  2245. if (!destroyed && (current_sources === null || !includes.call(current_sources, signal))) {
  2246. var deps = active_reaction.deps;
  2247. if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) {
  2248. if (signal.rv < read_version) {
  2249. signal.rv = read_version;
  2250. if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
  2251. skipped_deps++;
  2252. } else if (new_deps === null) {
  2253. new_deps = [signal];
  2254. } else {
  2255. new_deps.push(signal);
  2256. }
  2257. }
  2258. } else {
  2259. (active_reaction.deps ??= []).push(signal);
  2260. var reactions = signal.reactions;
  2261. if (reactions === null) {
  2262. signal.reactions = [active_reaction];
  2263. } else if (!includes.call(reactions, active_reaction)) {
  2264. reactions.push(active_reaction);
  2265. }
  2266. }
  2267. }
  2268. }
  2269. if (is_destroying_effect && old_values.has(signal)) {
  2270. return old_values.get(signal);
  2271. }
  2272. if (is_derived) {
  2273. var derived2 = (
  2274. /** @type {Derived} */
  2275. signal
  2276. );
  2277. if (is_destroying_effect) {
  2278. var value = derived2.v;
  2279. if ((derived2.f & CLEAN) === 0 && derived2.reactions !== null || depends_on_old_values(derived2)) {
  2280. value = execute_derived(derived2);
  2281. }
  2282. old_values.set(derived2, value);
  2283. return value;
  2284. }
  2285. var should_connect = (derived2.f & CONNECTED) === 0 && !untracking && active_reaction !== null && (is_updating_effect || (active_reaction.f & CONNECTED) !== 0);
  2286. var is_new = (derived2.f & REACTION_RAN) === 0;
  2287. if (is_dirty(derived2)) {
  2288. if (should_connect) {
  2289. derived2.f |= CONNECTED;
  2290. }
  2291. update_derived(derived2);
  2292. }
  2293. if (should_connect && !is_new) {
  2294. unfreeze_derived_effects(derived2);
  2295. reconnect(derived2);
  2296. }
  2297. }
  2298. if (batch_values?.has(signal)) {
  2299. return batch_values.get(signal);
  2300. }
  2301. if ((signal.f & ERROR_VALUE) !== 0) {
  2302. throw signal.v;
  2303. }
  2304. return signal.v;
  2305. }
  2306. function reconnect(derived2) {
  2307. derived2.f |= CONNECTED;
  2308. if (derived2.deps === null) return;
  2309. for (const dep of derived2.deps) {
  2310. (dep.reactions ??= []).push(derived2);
  2311. if ((dep.f & DERIVED) !== 0 && (dep.f & CONNECTED) === 0) {
  2312. unfreeze_derived_effects(
  2313. /** @type {Derived} */
  2314. dep
  2315. );
  2316. reconnect(
  2317. /** @type {Derived} */
  2318. dep
  2319. );
  2320. }
  2321. }
  2322. }
  2323. function depends_on_old_values(derived2) {
  2324. if (derived2.v === UNINITIALIZED) return true;
  2325. if (derived2.deps === null) return false;
  2326. for (const dep of derived2.deps) {
  2327. if (old_values.has(dep)) {
  2328. return true;
  2329. }
  2330. if ((dep.f & DERIVED) !== 0 && depends_on_old_values(
  2331. /** @type {Derived} */
  2332. dep
  2333. )) {
  2334. return true;
  2335. }
  2336. }
  2337. return false;
  2338. }
  2339. function untrack(fn) {
  2340. var previous_untracking = untracking;
  2341. try {
  2342. untracking = true;
  2343. return fn();
  2344. } finally {
  2345. untracking = previous_untracking;
  2346. }
  2347. }
  2348. const event_symbol = /* @__PURE__ */ Symbol("events");
  2349. const all_registered_events = /* @__PURE__ */ new Set();
  2350. const root_event_handles = /* @__PURE__ */ new Set();
  2351. let last_propagated_event = null;
  2352. function handle_event_propagation(event) {
  2353. var handler_element = this;
  2354. var owner_document = (
  2355. /** @type {Node} */
  2356. handler_element.ownerDocument
  2357. );
  2358. var event_name = event.type;
  2359. var path = event.composedPath?.() || [];
  2360. var current_target = (
  2361. /** @type {null | Element} */
  2362. path[0] || event.target
  2363. );
  2364. last_propagated_event = event;
  2365. var path_idx = 0;
  2366. var handled_at = last_propagated_event === event && event[event_symbol];
  2367. if (handled_at) {
  2368. var at_idx = path.indexOf(handled_at);
  2369. if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
  2370. window)) {
  2371. event[event_symbol] = handler_element;
  2372. return;
  2373. }
  2374. var handler_idx = path.indexOf(handler_element);
  2375. if (handler_idx === -1) {
  2376. return;
  2377. }
  2378. if (at_idx <= handler_idx) {
  2379. path_idx = at_idx;
  2380. }
  2381. }
  2382. current_target = /** @type {Element} */
  2383. path[path_idx] || event.target;
  2384. if (current_target === handler_element) return;
  2385. define_property(event, "currentTarget", {
  2386. configurable: true,
  2387. get() {
  2388. return current_target || owner_document;
  2389. }
  2390. });
  2391. var previous_reaction = active_reaction;
  2392. var previous_effect = active_effect;
  2393. set_active_reaction(null);
  2394. set_active_effect(null);
  2395. try {
  2396. var throw_error;
  2397. var other_errors = [];
  2398. while (current_target !== null) {
  2399. var parent_element = current_target.assignedSlot || current_target.parentNode || /** @type {any} */
  2400. current_target.host || null;
  2401. try {
  2402. var delegated = current_target[event_symbol]?.[event_name];
  2403. if (delegated != null && (!/** @type {any} */
  2404. current_target.disabled || // DOM could've been updated already by the time this is reached, so we check this as well
  2405. // -> the target could not have been disabled because it emits the event in the first place
  2406. event.target === current_target)) {
  2407. delegated.call(current_target, event);
  2408. }
  2409. } catch (error) {
  2410. if (throw_error) {
  2411. other_errors.push(error);
  2412. } else {
  2413. throw_error = error;
  2414. }
  2415. }
  2416. if (event.cancelBubble || parent_element === handler_element || parent_element === null) {
  2417. break;
  2418. }
  2419. current_target = parent_element;
  2420. }
  2421. if (throw_error) {
  2422. for (let error of other_errors) {
  2423. queueMicrotask(() => {
  2424. throw error;
  2425. });
  2426. }
  2427. throw throw_error;
  2428. }
  2429. } finally {
  2430. event[event_symbol] = handler_element;
  2431. delete event.currentTarget;
  2432. set_active_reaction(previous_reaction);
  2433. set_active_effect(previous_effect);
  2434. }
  2435. }
  2436. function assign_nodes(start, end) {
  2437. var effect = (
  2438. /** @type {Effect} */
  2439. active_effect
  2440. );
  2441. if (effect.nodes === null) {
  2442. effect.nodes = { start, end, a: null, t: null };
  2443. }
  2444. }
  2445. function mount(component, options) {
  2446. return _mount(component, options);
  2447. }
  2448. function hydrate(component, options) {
  2449. init_operations();
  2450. options.intro = options.intro ?? false;
  2451. const target = options.target;
  2452. const was_hydrating = hydrating;
  2453. const previous_hydrate_node = hydrate_node;
  2454. try {
  2455. var anchor = /* @__PURE__ */ get_first_child(target);
  2456. while (anchor && (anchor.nodeType !== COMMENT_NODE || /** @type {Comment} */
  2457. anchor.data !== HYDRATION_START)) {
  2458. anchor = /* @__PURE__ */ get_next_sibling(anchor);
  2459. }
  2460. if (!anchor) {
  2461. throw HYDRATION_ERROR;
  2462. }
  2463. set_hydrating(true);
  2464. set_hydrate_node(
  2465. /** @type {Comment} */
  2466. anchor
  2467. );
  2468. const instance = _mount(component, { ...options, anchor });
  2469. set_hydrating(false);
  2470. return (
  2471. /** @type {Exports} */
  2472. instance
  2473. );
  2474. } catch (error) {
  2475. if (error instanceof Error && error.message.split("\n").some((line) => line.startsWith("https://svelte.dev/e/"))) {
  2476. throw error;
  2477. }
  2478. if (error !== HYDRATION_ERROR) {
  2479. console.warn("Failed to hydrate: ", error);
  2480. }
  2481. if (options.recover === false) {
  2482. hydration_failed();
  2483. }
  2484. init_operations();
  2485. clear_text_content(target);
  2486. set_hydrating(false);
  2487. return mount(component, options);
  2488. } finally {
  2489. set_hydrating(was_hydrating);
  2490. set_hydrate_node(previous_hydrate_node);
  2491. }
  2492. }
  2493. const listeners = /* @__PURE__ */ new Map();
  2494. function _mount(Component, { target, anchor, props = {}, events, context, intro = true, transformError }) {
  2495. init_operations();
  2496. var component = void 0;
  2497. var unmount2 = component_root(() => {
  2498. var anchor_node = anchor ?? target.appendChild(create_text());
  2499. boundary(
  2500. /** @type {TemplateNode} */
  2501. anchor_node,
  2502. {
  2503. pending: () => {
  2504. }
  2505. },
  2506. (anchor_node2) => {
  2507. push({});
  2508. var ctx = (
  2509. /** @type {ComponentContext} */
  2510. component_context
  2511. );
  2512. if (context) ctx.c = context;
  2513. if (events) {
  2514. props.$$events = events;
  2515. }
  2516. if (hydrating) {
  2517. assign_nodes(
  2518. /** @type {TemplateNode} */
  2519. anchor_node2,
  2520. null
  2521. );
  2522. }
  2523. component = Component(anchor_node2, props) || {};
  2524. if (hydrating) {
  2525. active_effect.nodes.end = hydrate_node;
  2526. if (hydrate_node === null || hydrate_node.nodeType !== COMMENT_NODE || /** @type {Comment} */
  2527. hydrate_node.data !== HYDRATION_END) {
  2528. hydration_mismatch();
  2529. throw HYDRATION_ERROR;
  2530. }
  2531. }
  2532. pop();
  2533. },
  2534. transformError
  2535. );
  2536. var registered_events = /* @__PURE__ */ new Set();
  2537. var event_handle = (events2) => {
  2538. for (var i = 0; i < events2.length; i++) {
  2539. var event_name = events2[i];
  2540. if (registered_events.has(event_name)) continue;
  2541. registered_events.add(event_name);
  2542. var passive = is_passive_event(event_name);
  2543. for (const node of [target, document]) {
  2544. var counts = listeners.get(node);
  2545. if (counts === void 0) {
  2546. counts = /* @__PURE__ */ new Map();
  2547. listeners.set(node, counts);
  2548. }
  2549. var count = counts.get(event_name);
  2550. if (count === void 0) {
  2551. node.addEventListener(event_name, handle_event_propagation, { passive });
  2552. counts.set(event_name, 1);
  2553. } else {
  2554. counts.set(event_name, count + 1);
  2555. }
  2556. }
  2557. }
  2558. };
  2559. event_handle(array_from(all_registered_events));
  2560. root_event_handles.add(event_handle);
  2561. return () => {
  2562. for (var event_name of registered_events) {
  2563. for (const node of [target, document]) {
  2564. var counts = (
  2565. /** @type {Map<string, number>} */
  2566. listeners.get(node)
  2567. );
  2568. var count = (
  2569. /** @type {number} */
  2570. counts.get(event_name)
  2571. );
  2572. if (--count == 0) {
  2573. node.removeEventListener(event_name, handle_event_propagation);
  2574. counts.delete(event_name);
  2575. if (counts.size === 0) {
  2576. listeners.delete(node);
  2577. }
  2578. } else {
  2579. counts.set(event_name, count);
  2580. }
  2581. }
  2582. }
  2583. root_event_handles.delete(event_handle);
  2584. if (anchor_node !== anchor) {
  2585. anchor_node.parentNode?.removeChild(anchor_node);
  2586. }
  2587. };
  2588. });
  2589. mounted_components.set(component, unmount2);
  2590. return component;
  2591. }
  2592. let mounted_components = /* @__PURE__ */ new WeakMap();
  2593. function unmount(component, options) {
  2594. const fn = mounted_components.get(component);
  2595. if (fn) {
  2596. mounted_components.delete(component);
  2597. return fn(options);
  2598. }
  2599. return Promise.resolve();
  2600. }
  2601. function asClassComponent$1(component) {
  2602. return class extends Svelte4Component {
  2603. /** @param {any} options */
  2604. constructor(options) {
  2605. super({
  2606. component,
  2607. ...options
  2608. });
  2609. }
  2610. };
  2611. }
  2612. class Svelte4Component {
  2613. /** @type {any} */
  2614. #events;
  2615. /** @type {Record<string, any>} */
  2616. #instance;
  2617. /**
  2618. * @param {ComponentConstructorOptions & {
  2619. * component: any;
  2620. * }} options
  2621. */
  2622. constructor(options) {
  2623. var sources = /* @__PURE__ */ new Map();
  2624. var add_source = (key, value) => {
  2625. var s = /* @__PURE__ */ mutable_source(value, false, false);
  2626. sources.set(key, s);
  2627. return s;
  2628. };
  2629. const props = new Proxy(
  2630. { ...options.props || {}, $$events: {} },
  2631. {
  2632. get(target, prop) {
  2633. return get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
  2634. },
  2635. has(target, prop) {
  2636. if (prop === LEGACY_PROPS) return true;
  2637. get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
  2638. return Reflect.has(target, prop);
  2639. },
  2640. set(target, prop, value) {
  2641. set(sources.get(prop) ?? add_source(prop, value), value);
  2642. return Reflect.set(target, prop, value);
  2643. }
  2644. }
  2645. );
  2646. this.#instance = (options.hydrate ? hydrate : mount)(options.component, {
  2647. target: options.target,
  2648. anchor: options.anchor,
  2649. props,
  2650. context: options.context,
  2651. intro: options.intro ?? false,
  2652. recover: options.recover,
  2653. transformError: options.transformError
  2654. });
  2655. if (!options?.props?.$$host || options.sync === false) {
  2656. flushSync();
  2657. }
  2658. this.#events = props.$$events;
  2659. for (const key of Object.keys(this.#instance)) {
  2660. if (key === "$set" || key === "$destroy" || key === "$on") continue;
  2661. define_property(this, key, {
  2662. get() {
  2663. return this.#instance[key];
  2664. },
  2665. /** @param {any} value */
  2666. set(value) {
  2667. this.#instance[key] = value;
  2668. },
  2669. enumerable: true
  2670. });
  2671. }
  2672. this.#instance.$set = /** @param {Record<string, any>} next */
  2673. (next2) => {
  2674. Object.assign(props, next2);
  2675. };
  2676. this.#instance.$destroy = () => {
  2677. unmount(this.#instance);
  2678. };
  2679. }
  2680. /** @param {Record<string, any>} props */
  2681. $set(props) {
  2682. this.#instance.$set(props);
  2683. }
  2684. /**
  2685. * @param {string} event
  2686. * @param {(...args: any[]) => any} callback
  2687. * @returns {any}
  2688. */
  2689. $on(event, callback) {
  2690. this.#events[event] = this.#events[event] || [];
  2691. const cb = (...args) => callback.call(this, ...args);
  2692. this.#events[event].push(cb);
  2693. return () => {
  2694. this.#events[event] = this.#events[event].filter(
  2695. /** @param {any} fn */
  2696. (fn) => fn !== cb
  2697. );
  2698. };
  2699. }
  2700. $destroy() {
  2701. this.#instance.$destroy();
  2702. }
  2703. }
  2704. function asClassComponent(component) {
  2705. const component_constructor = asClassComponent$1(component);
  2706. const _render = (props, { context, csp, transformError } = {}) => {
  2707. const result = render(component, { props, context, csp, transformError });
  2708. const munged = Object.defineProperties(
  2709. /** @type {LegacyRenderResult & PromiseLike<LegacyRenderResult>} */
  2710. {},
  2711. {
  2712. css: {
  2713. value: { code: "", map: null }
  2714. },
  2715. head: {
  2716. get: () => result.head
  2717. },
  2718. html: {
  2719. get: () => result.body
  2720. },
  2721. then: {
  2722. /**
  2723. * this is not type-safe, but honestly it's the best I can do right now, and it's a straightforward function.
  2724. *
  2725. * @template TResult1
  2726. * @template [TResult2=never]
  2727. * @param { (value: LegacyRenderResult) => TResult1 } onfulfilled
  2728. * @param { (reason: unknown) => TResult2 } onrejected
  2729. */
  2730. value: (onfulfilled, onrejected) => {
  2731. {
  2732. const user_result = onfulfilled({
  2733. css: munged.css,
  2734. head: munged.head,
  2735. html: munged.html
  2736. });
  2737. return Promise.resolve(user_result);
  2738. }
  2739. }
  2740. }
  2741. }
  2742. );
  2743. return munged;
  2744. };
  2745. component_constructor.render = _render;
  2746. return component_constructor;
  2747. }
  2748. function Root($$renderer, $$props) {
  2749. $$renderer.component(($$renderer2) => {
  2750. let {
  2751. stores,
  2752. page,
  2753. constructors,
  2754. components = [],
  2755. form,
  2756. data_0 = null,
  2757. data_1 = null
  2758. } = $$props;
  2759. {
  2760. setContext("__svelte__", stores);
  2761. }
  2762. {
  2763. stores.page.set(page);
  2764. }
  2765. const Pyramid_1 = derived(() => constructors[1]);
  2766. if (constructors[1]) {
  2767. $$renderer2.push("<!--[0-->");
  2768. const Pyramid_0 = constructors[0];
  2769. if (Pyramid_0) {
  2770. $$renderer2.push("<!--[-->");
  2771. Pyramid_0($$renderer2, {
  2772. data: data_0,
  2773. form,
  2774. params: page.params,
  2775. children: ($$renderer3) => {
  2776. if (Pyramid_1()) {
  2777. $$renderer3.push("<!--[-->");
  2778. Pyramid_1()($$renderer3, { data: data_1, form, params: page.params });
  2779. $$renderer3.push("<!--]-->");
  2780. } else {
  2781. $$renderer3.push("<!--[!-->");
  2782. $$renderer3.push("<!--]-->");
  2783. }
  2784. },
  2785. $$slots: { default: true }
  2786. });
  2787. $$renderer2.push("<!--]-->");
  2788. } else {
  2789. $$renderer2.push("<!--[!-->");
  2790. $$renderer2.push("<!--]-->");
  2791. }
  2792. } else {
  2793. $$renderer2.push("<!--[-1-->");
  2794. const Pyramid_0 = constructors[0];
  2795. if (Pyramid_0) {
  2796. $$renderer2.push("<!--[-->");
  2797. Pyramid_0($$renderer2, { data: data_0, form, params: page.params });
  2798. $$renderer2.push("<!--]-->");
  2799. } else {
  2800. $$renderer2.push("<!--[!-->");
  2801. $$renderer2.push("<!--]-->");
  2802. }
  2803. }
  2804. $$renderer2.push(`<!--]--> `);
  2805. {
  2806. $$renderer2.push("<!--[-1-->");
  2807. }
  2808. $$renderer2.push(`<!--]-->`);
  2809. });
  2810. }
  2811. const root = asClassComponent(Root);
  2812. export {
  2813. root as r,
  2814. safe_not_equal as s
  2815. };