dev.cjs 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. let taskIdCounter = 1,
  4. isCallbackScheduled = false,
  5. isPerformingWork = false,
  6. taskQueue = [],
  7. currentTask = null,
  8. shouldYieldToHost = null,
  9. yieldInterval = 5,
  10. deadline = 0,
  11. maxYieldInterval = 300,
  12. scheduleCallback = null,
  13. scheduledCallback = null;
  14. const maxSigned31BitInt = 1073741823;
  15. function setupScheduler() {
  16. const channel = new MessageChannel(),
  17. port = channel.port2;
  18. scheduleCallback = () => port.postMessage(null);
  19. channel.port1.onmessage = () => {
  20. if (scheduledCallback !== null) {
  21. const currentTime = performance.now();
  22. deadline = currentTime + yieldInterval;
  23. const hasTimeRemaining = true;
  24. try {
  25. const hasMoreWork = scheduledCallback(hasTimeRemaining, currentTime);
  26. if (!hasMoreWork) {
  27. scheduledCallback = null;
  28. } else port.postMessage(null);
  29. } catch (error) {
  30. port.postMessage(null);
  31. throw error;
  32. }
  33. }
  34. };
  35. if (navigator && navigator.scheduling && navigator.scheduling.isInputPending) {
  36. const scheduling = navigator.scheduling;
  37. shouldYieldToHost = () => {
  38. const currentTime = performance.now();
  39. if (currentTime >= deadline) {
  40. if (scheduling.isInputPending()) {
  41. return true;
  42. }
  43. return currentTime >= maxYieldInterval;
  44. } else {
  45. return false;
  46. }
  47. };
  48. } else {
  49. shouldYieldToHost = () => performance.now() >= deadline;
  50. }
  51. }
  52. function enqueue(taskQueue, task) {
  53. function findIndex() {
  54. let m = 0;
  55. let n = taskQueue.length - 1;
  56. while (m <= n) {
  57. let k = n + m >> 1;
  58. let cmp = task.expirationTime - taskQueue[k].expirationTime;
  59. if (cmp > 0) m = k + 1;else if (cmp < 0) n = k - 1;else return k;
  60. }
  61. return m;
  62. }
  63. taskQueue.splice(findIndex(), 0, task);
  64. }
  65. function requestCallback(fn, options) {
  66. if (!scheduleCallback) setupScheduler();
  67. let startTime = performance.now(),
  68. timeout = maxSigned31BitInt;
  69. if (options && options.timeout) timeout = options.timeout;
  70. const newTask = {
  71. id: taskIdCounter++,
  72. fn,
  73. startTime,
  74. expirationTime: startTime + timeout
  75. };
  76. enqueue(taskQueue, newTask);
  77. if (!isCallbackScheduled && !isPerformingWork) {
  78. isCallbackScheduled = true;
  79. scheduledCallback = flushWork;
  80. scheduleCallback();
  81. }
  82. return newTask;
  83. }
  84. function cancelCallback(task) {
  85. task.fn = null;
  86. }
  87. function flushWork(hasTimeRemaining, initialTime) {
  88. isCallbackScheduled = false;
  89. isPerformingWork = true;
  90. try {
  91. return workLoop(hasTimeRemaining, initialTime);
  92. } finally {
  93. currentTask = null;
  94. isPerformingWork = false;
  95. }
  96. }
  97. function workLoop(hasTimeRemaining, initialTime) {
  98. let currentTime = initialTime;
  99. currentTask = taskQueue[0] || null;
  100. while (currentTask !== null) {
  101. if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) {
  102. break;
  103. }
  104. const callback = currentTask.fn;
  105. if (callback !== null) {
  106. currentTask.fn = null;
  107. const didUserCallbackTimeout = currentTask.expirationTime <= currentTime;
  108. callback(didUserCallbackTimeout);
  109. currentTime = performance.now();
  110. if (currentTask === taskQueue[0]) {
  111. taskQueue.shift();
  112. }
  113. } else taskQueue.shift();
  114. currentTask = taskQueue[0] || null;
  115. }
  116. return currentTask !== null;
  117. }
  118. const sharedConfig = {};
  119. function setHydrateContext(context) {
  120. sharedConfig.context = context;
  121. }
  122. function nextHydrateContext() {
  123. return { ...sharedConfig.context,
  124. id: `${sharedConfig.context.id}${sharedConfig.context.count++}.`,
  125. count: 0
  126. };
  127. }
  128. const equalFn = (a, b) => a === b;
  129. const signalOptions = {
  130. equals: equalFn
  131. };
  132. let ERROR = null;
  133. let runEffects = runQueue;
  134. const NOTPENDING = {};
  135. const STALE = 1;
  136. const PENDING = 2;
  137. const UNOWNED = {
  138. owned: null,
  139. cleanups: null,
  140. context: null,
  141. owner: null
  142. };
  143. const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
  144. var Owner = null;
  145. var Listener = null;
  146. let Pending = null;
  147. let Updates = null;
  148. let Effects = null;
  149. let Transition = null;
  150. let ExecCount = 0;
  151. let rootCount = 0;
  152. function createRoot(fn, detachedOwner) {
  153. detachedOwner && (Owner = detachedOwner);
  154. const listener = Listener,
  155. owner = Owner,
  156. root = fn.length === 0 && !"_SOLID_DEV_" ? UNOWNED : {
  157. owned: null,
  158. cleanups: null,
  159. context: null,
  160. owner,
  161. attached: !!detachedOwner
  162. };
  163. if (owner) root.name = owner.name + "-r" + rootCount++;
  164. Owner = root;
  165. Listener = null;
  166. let result;
  167. try {
  168. runUpdates(() => result = fn(() => cleanNode(root)), true);
  169. } finally {
  170. Listener = listener;
  171. Owner = owner;
  172. }
  173. return result;
  174. }
  175. function createSignal(value, options) {
  176. options = options ? Object.assign({}, signalOptions, options) : signalOptions;
  177. const s = {
  178. value,
  179. observers: null,
  180. observerSlots: null,
  181. pending: NOTPENDING,
  182. comparator: options.equals || undefined
  183. };
  184. if ((!options || !options.internal)) s.name = registerGraph(options && options.name || hashValue(value), s);
  185. return [readSignal.bind(s), writeSignal.bind(s)];
  186. }
  187. function createComputed(fn, value, options) {
  188. updateComputation(createComputation(fn, value, true, options ));
  189. }
  190. function createRenderEffect(fn, value, options) {
  191. updateComputation(createComputation(fn, value, false, options ));
  192. }
  193. function createEffect(fn, value, options) {
  194. runEffects = runUserEffects;
  195. const c = createComputation(fn, value, false, options ),
  196. s = SuspenseContext && lookup(Owner, SuspenseContext.id);
  197. if (s) c.suspense = s;
  198. c.user = true;
  199. Effects && Effects.push(c);
  200. }
  201. function createMemo(fn, value, options) {
  202. options = options ? Object.assign({}, signalOptions, options) : signalOptions;
  203. const c = createComputation(fn, value, true, options );
  204. c.pending = NOTPENDING;
  205. c.observers = null;
  206. c.observerSlots = null;
  207. c.state = 0;
  208. c.comparator = options.equals || undefined;
  209. updateComputation(c);
  210. return readSignal.bind(c);
  211. }
  212. function createResource(source, fetcher, options = {}) {
  213. if (arguments.length === 2) {
  214. if (typeof fetcher === "object") {
  215. options = fetcher;
  216. fetcher = source;
  217. source = true;
  218. }
  219. } else if (arguments.length === 1) {
  220. fetcher = source;
  221. source = true;
  222. }
  223. const contexts = new Set(),
  224. [s, set] = createSignal(options.initialValue),
  225. [track, trigger] = createSignal(undefined, {
  226. equals: false
  227. }),
  228. [loading, setLoading] = createSignal(false),
  229. [error, setError] = createSignal();
  230. let err = undefined,
  231. pr = null,
  232. initP = null,
  233. id = null,
  234. loadedUnderTransition = false,
  235. dynamic = typeof source === "function";
  236. if (sharedConfig.context) {
  237. id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
  238. if (sharedConfig.context.loadResource) {
  239. initP = sharedConfig.context.loadResource(id);
  240. } else if (sharedConfig.resources && id && id in sharedConfig.resources) {
  241. initP = sharedConfig.resources[id];
  242. delete sharedConfig.resources[id];
  243. }
  244. }
  245. function loadEnd(p, v, e) {
  246. if (pr === p) {
  247. setError(err = e);
  248. pr = null;
  249. if (Transition && p && loadedUnderTransition) {
  250. Transition.promises.delete(p);
  251. loadedUnderTransition = false;
  252. runUpdates(() => {
  253. Transition.running = true;
  254. if (!Transition.promises.size) {
  255. Effects.push.apply(Effects, Transition.effects);
  256. Transition.effects = [];
  257. }
  258. completeLoad(v);
  259. }, false);
  260. } else completeLoad(v);
  261. }
  262. return v;
  263. }
  264. function completeLoad(v) {
  265. batch(() => {
  266. set(v);
  267. setLoading(false);
  268. for (let c of contexts.keys()) c.decrement();
  269. contexts.clear();
  270. });
  271. }
  272. function read() {
  273. const c = SuspenseContext && lookup(Owner, SuspenseContext.id),
  274. v = s();
  275. if (err) throw err;
  276. if (Listener && !Listener.user && c) {
  277. createComputed(() => {
  278. track();
  279. if (pr) {
  280. if (c.resolved && Transition) Transition.promises.add(pr);else if (!contexts.has(c)) {
  281. c.increment();
  282. contexts.add(c);
  283. }
  284. }
  285. });
  286. }
  287. return v;
  288. }
  289. function load() {
  290. setError(err = undefined);
  291. let lookup = dynamic ? source() : source;
  292. loadedUnderTransition = Transition && Transition.running;
  293. if (lookup == null || lookup === false) {
  294. loadEnd(pr, untrack(s));
  295. return;
  296. }
  297. if (Transition && pr) Transition.promises.delete(pr);
  298. const p = initP || fetcher(lookup, s);
  299. initP = null;
  300. if (typeof p !== "object" || !("then" in p)) {
  301. loadEnd(pr, p);
  302. return;
  303. }
  304. pr = p;
  305. batch(() => {
  306. setLoading(true);
  307. trigger();
  308. });
  309. p.then(v => loadEnd(p, v), e => loadEnd(p, e, e));
  310. }
  311. Object.defineProperties(read, {
  312. loading: {
  313. get() {
  314. return loading();
  315. }
  316. },
  317. error: {
  318. get() {
  319. return error();
  320. }
  321. }
  322. });
  323. if (dynamic) createComputed(load);else load();
  324. return [read, {
  325. refetch: load,
  326. mutate: set
  327. }];
  328. }
  329. function createDeferred(source, options) {
  330. let t,
  331. timeout = options ? options.timeoutMs : undefined;
  332. const node = createComputation(() => {
  333. if (!t || !t.fn) t = requestCallback(() => setDeferred(node.value), timeout !== undefined ? {
  334. timeout
  335. } : undefined);
  336. return source();
  337. }, undefined, true);
  338. const [deferred, setDeferred] = createSignal(node.value, options);
  339. updateComputation(node);
  340. setDeferred(node.value);
  341. return deferred;
  342. }
  343. function createSelector(source, fn = equalFn, options) {
  344. let subs = new Map();
  345. const node = createComputation(p => {
  346. const v = source();
  347. for (const key of subs.keys()) if (fn(key, v) || p !== undefined && fn(key, p)) {
  348. const l = subs.get(key);
  349. for (const c of l.values()) {
  350. c.state = STALE;
  351. if (c.pure) Updates.push(c);else Effects.push(c);
  352. }
  353. }
  354. return v;
  355. }, undefined, true, options );
  356. updateComputation(node);
  357. return key => {
  358. let listener;
  359. if (listener = Listener) {
  360. let l;
  361. if (l = subs.get(key)) l.add(listener);else subs.set(key, l = new Set([listener]));
  362. onCleanup(() => {
  363. l.size > 1 ? l.delete(listener) : subs.delete(key);
  364. });
  365. }
  366. return fn(key, node.value);
  367. };
  368. }
  369. function batch(fn) {
  370. if (Pending) return fn();
  371. let result;
  372. const q = Pending = [];
  373. try {
  374. result = fn();
  375. } finally {
  376. Pending = null;
  377. }
  378. runUpdates(() => {
  379. for (let i = 0; i < q.length; i += 1) {
  380. const data = q[i];
  381. if (data.pending !== NOTPENDING) {
  382. const pending = data.pending;
  383. data.pending = NOTPENDING;
  384. writeSignal.call(data, pending);
  385. }
  386. }
  387. }, false);
  388. return result;
  389. }
  390. function untrack(fn) {
  391. let result,
  392. listener = Listener;
  393. Listener = null;
  394. result = fn();
  395. Listener = listener;
  396. return result;
  397. }
  398. function on(deps, fn, options) {
  399. let isArray = Array.isArray(deps);
  400. let prev;
  401. let defer = options && options.defer;
  402. return prevResult => {
  403. let value;
  404. if (isArray) {
  405. value = [];
  406. for (let i = 0; i < deps.length; i++) value.push(deps[i]());
  407. } else value = deps();
  408. if (defer) {
  409. defer = false;
  410. return undefined;
  411. }
  412. const result = untrack(() => fn(value, prev, prevResult));
  413. prev = value;
  414. return result;
  415. };
  416. }
  417. function onMount(fn) {
  418. createEffect(() => untrack(fn));
  419. }
  420. function onCleanup(fn) {
  421. if (Owner === null) console.warn("cleanups created outside a `createRoot` or `render` will never be run");else if (Owner.cleanups === null) Owner.cleanups = [fn];else Owner.cleanups.push(fn);
  422. return fn;
  423. }
  424. function onError(fn) {
  425. ERROR || (ERROR = Symbol("error"));
  426. if (Owner === null) console.warn("error handlers created outside a `createRoot` or `render` will never be run");else if (Owner.context === null) Owner.context = {
  427. [ERROR]: [fn]
  428. };else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn];else Owner.context[ERROR].push(fn);
  429. }
  430. function getListener() {
  431. return Listener;
  432. }
  433. function getOwner() {
  434. return Owner;
  435. }
  436. function runWithOwner(o, fn) {
  437. const prev = Owner;
  438. Owner = o;
  439. try {
  440. return fn();
  441. } finally {
  442. Owner = prev;
  443. }
  444. }
  445. function useTransition() {
  446. return [transPending, (fn, cb) => {
  447. if (SuspenseContext) {
  448. Transition || (Transition = {
  449. sources: new Set(),
  450. effects: [],
  451. promises: new Set(),
  452. disposed: new Set(),
  453. running: true,
  454. cb: []
  455. });
  456. cb && Transition.cb.push(cb);
  457. Transition.running = true;
  458. }
  459. batch(fn);
  460. if (!SuspenseContext && cb) cb();
  461. }];
  462. }
  463. function resumeEffects(e) {
  464. Transition && (Transition.running = true);
  465. Effects.push.apply(Effects, e);
  466. e.length = 0;
  467. }
  468. function devComponent(Comp, props) {
  469. const c = createComputation(() => untrack(() => Comp(props)), undefined, true);
  470. c.pending = NOTPENDING;
  471. c.observers = null;
  472. c.observerSlots = null;
  473. c.state = 0;
  474. c.componentName = Comp.name;
  475. updateComputation(c);
  476. return c.tValue !== undefined ? c.tValue : c.value;
  477. }
  478. function hashValue(v) {
  479. const s = new Set();
  480. return "s" + (typeof v === "string" ? hash(v) : hash(JSON.stringify(v, (k, v) => {
  481. if (typeof v === "object" && v != null) {
  482. if (s.has(v)) return;
  483. s.add(v);
  484. }
  485. return v;
  486. }) || ""));
  487. }
  488. function registerGraph(name, value) {
  489. let tryName = name;
  490. if (Owner) {
  491. let i = 0;
  492. Owner.sourceMap || (Owner.sourceMap = {});
  493. while (Owner.sourceMap[tryName]) tryName = name + "-" + ++i;
  494. Owner.sourceMap[tryName] = value;
  495. }
  496. return tryName;
  497. }
  498. function serializeGraph(owner) {
  499. owner || (owner = Owner);
  500. if (!owner) return {};
  501. return { ...serializeValues(owner.sourceMap),
  502. ...(owner.owned ? serializeChildren(owner) : {})
  503. };
  504. }
  505. function createContext(defaultValue) {
  506. const id = Symbol("context");
  507. return {
  508. id,
  509. Provider: createProvider(id),
  510. defaultValue
  511. };
  512. }
  513. function useContext(context) {
  514. return lookup(Owner, context.id) || context.defaultValue;
  515. }
  516. function children(fn) {
  517. const children = createMemo(fn);
  518. return createMemo(() => resolveChildren(children()));
  519. }
  520. let SuspenseContext;
  521. function getSuspenseContext() {
  522. return SuspenseContext || (SuspenseContext = createContext({}));
  523. }
  524. function readSignal() {
  525. if (this.state && this.sources) {
  526. const updates = Updates;
  527. Updates = null;
  528. this.state === STALE ? updateComputation(this) : lookDownstream(this);
  529. Updates = updates;
  530. }
  531. if (Listener) {
  532. const sSlot = this.observers ? this.observers.length : 0;
  533. if (!Listener.sources) {
  534. Listener.sources = [this];
  535. Listener.sourceSlots = [sSlot];
  536. } else {
  537. Listener.sources.push(this);
  538. Listener.sourceSlots.push(sSlot);
  539. }
  540. if (!this.observers) {
  541. this.observers = [Listener];
  542. this.observerSlots = [Listener.sources.length - 1];
  543. } else {
  544. this.observers.push(Listener);
  545. this.observerSlots.push(Listener.sources.length - 1);
  546. }
  547. }
  548. if (Transition && Transition.running && Transition.sources.has(this)) return this.tValue;
  549. return this.value;
  550. }
  551. function writeSignal(value, isComp) {
  552. if (this.comparator) {
  553. if (Transition && Transition.running && Transition.sources.has(this)) {
  554. if (this.comparator(this.tValue, value)) return value;
  555. } else if (this.comparator(this.value, value)) return value;
  556. }
  557. if (Pending) {
  558. if (this.pending === NOTPENDING) Pending.push(this);
  559. this.pending = value;
  560. return value;
  561. }
  562. if (Transition) {
  563. if (Transition.running || !isComp && Transition.sources.has(this)) {
  564. Transition.sources.add(this);
  565. this.tValue = value;
  566. }
  567. if (!Transition.running) this.value = value;
  568. } else this.value = value;
  569. if (this.observers && (!Updates || this.observers.length)) {
  570. runUpdates(() => {
  571. for (let i = 0; i < this.observers.length; i += 1) {
  572. const o = this.observers[i];
  573. if (Transition && Transition.running && Transition.disposed.has(o)) continue;
  574. if (o.observers && o.state !== PENDING) markUpstream(o);
  575. o.state = STALE;
  576. if (o.pure) Updates.push(o);else Effects.push(o);
  577. }
  578. if (Updates.length > 10e5) {
  579. Updates = [];
  580. if ("_SOLID_DEV_") throw new Error("Potential Infinite Loop Detected.");
  581. throw new Error();
  582. }
  583. }, false);
  584. }
  585. return value;
  586. }
  587. function updateComputation(node) {
  588. if (!node.fn) return;
  589. cleanNode(node);
  590. const owner = Owner,
  591. listener = Listener,
  592. time = ExecCount;
  593. Listener = Owner = node;
  594. runComputation(node, node.value, time);
  595. if (Transition && !Transition.running && Transition.sources.has(node)) {
  596. Transition.running = true;
  597. runComputation(node, node.tValue, time);
  598. Transition.running = false;
  599. }
  600. Listener = listener;
  601. Owner = owner;
  602. }
  603. function runComputation(node, value, time) {
  604. let nextValue;
  605. try {
  606. nextValue = node.fn(value);
  607. } catch (err) {
  608. handleError(err);
  609. }
  610. if (!node.updatedAt || node.updatedAt <= time) {
  611. if (node.observers && node.observers.length) {
  612. writeSignal.call(node, nextValue, true);
  613. } else if (Transition && Transition.running && node.pure) {
  614. Transition.sources.add(node);
  615. node.tValue = nextValue;
  616. } else node.value = nextValue;
  617. node.updatedAt = time;
  618. }
  619. }
  620. function createComputation(fn, init, pure, options) {
  621. const c = {
  622. fn,
  623. state: STALE,
  624. updatedAt: null,
  625. owned: null,
  626. sources: null,
  627. sourceSlots: null,
  628. cleanups: null,
  629. value: init,
  630. owner: Owner,
  631. context: null,
  632. pure
  633. };
  634. if (Owner === null) console.warn("computations created outside a `createRoot` or `render` will never be disposed");else if (Owner !== UNOWNED) {
  635. if (Transition && Transition.running && Owner.pure) {
  636. if (!Owner.tOwned) Owner.tOwned = [c];else Owner.tOwned.push(c);
  637. } else {
  638. if (!Owner.owned) Owner.owned = [c];else Owner.owned.push(c);
  639. }
  640. c.name = options && options.name || (Owner.name || "c") + "-" + (Owner.owned || Owner.tOwned).length;
  641. }
  642. return c;
  643. }
  644. function runTop(node) {
  645. let top = node.state === STALE && node,
  646. pending;
  647. if (node.suspense && untrack(node.suspense.inFallback)) return node.suspense.effects.push(node);
  648. const runningTransition = Transition && Transition.running;
  649. while ((node.fn || runningTransition && node.attached) && (node = node.owner)) {
  650. if (runningTransition && Transition.disposed.has(node)) return;
  651. if (node.state === PENDING) pending = node;else if (node.state === STALE) {
  652. top = node;
  653. pending = undefined;
  654. }
  655. }
  656. if (pending) {
  657. const updates = Updates;
  658. Updates = null;
  659. lookDownstream(pending);
  660. Updates = updates;
  661. if (!top || top.state !== STALE) return;
  662. if (runningTransition) {
  663. node = top;
  664. while ((node.fn || node.attached) && (node = node.owner)) {
  665. if (Transition.disposed.has(node)) return;
  666. }
  667. }
  668. }
  669. top && updateComputation(top);
  670. }
  671. function runUpdates(fn, init) {
  672. if (Updates) return fn();
  673. let wait = false;
  674. if (!init) Updates = [];
  675. if (Effects) wait = true;else Effects = [];
  676. ExecCount++;
  677. try {
  678. fn();
  679. } catch (err) {
  680. handleError(err);
  681. } finally {
  682. completeUpdates(wait);
  683. }
  684. }
  685. function completeUpdates(wait) {
  686. if (Updates) {
  687. runQueue(Updates);
  688. Updates = null;
  689. }
  690. if (wait) return;
  691. let cbs;
  692. if (Transition && Transition.running) {
  693. if (Transition.promises.size) {
  694. Transition.running = false;
  695. Transition.effects.push.apply(Transition.effects, Effects);
  696. Effects = null;
  697. setTransPending(true);
  698. return;
  699. }
  700. const sources = Transition.sources;
  701. cbs = Transition.cb;
  702. Transition = null;
  703. batch(() => {
  704. sources.forEach(v => {
  705. v.value = v.tValue;
  706. if (v.owned) {
  707. for (let i = 0, len = v.owned.length; i < len; i++) cleanNode(v.owned[i]);
  708. }
  709. if (v.tOwned) v.owned = v.tOwned;
  710. delete v.tValue;
  711. delete v.tOwned;
  712. });
  713. setTransPending(false);
  714. });
  715. }
  716. if (Effects.length) batch(() => {
  717. runEffects(Effects);
  718. Effects = null;
  719. });else {
  720. Effects = null;
  721. globalThis._$afterUpdate && globalThis._$afterUpdate();
  722. }
  723. if (cbs) cbs.forEach(cb => cb());
  724. }
  725. function runQueue(queue) {
  726. for (let i = 0; i < queue.length; i++) runTop(queue[i]);
  727. }
  728. function runUserEffects(queue) {
  729. let i,
  730. userLength = 0;
  731. for (i = 0; i < queue.length; i++) {
  732. const e = queue[i];
  733. if (!e.user) runTop(e);else queue[userLength++] = e;
  734. }
  735. const resume = queue.length;
  736. for (i = 0; i < userLength; i++) runTop(queue[i]);
  737. for (i = resume; i < queue.length; i++) runTop(queue[i]);
  738. }
  739. function lookDownstream(node) {
  740. node.state = 0;
  741. for (let i = 0; i < node.sources.length; i += 1) {
  742. const source = node.sources[i];
  743. if (source.sources) {
  744. if (source.state === STALE) runTop(source);else if (source.state === PENDING) lookDownstream(source);
  745. }
  746. }
  747. }
  748. function markUpstream(node) {
  749. for (let i = 0; i < node.observers.length; i += 1) {
  750. const o = node.observers[i];
  751. if (!o.state) {
  752. o.state = PENDING;
  753. o.observers && markUpstream(o);
  754. }
  755. }
  756. }
  757. function cleanNode(node) {
  758. let i;
  759. if (node.sources) {
  760. while (node.sources.length) {
  761. const source = node.sources.pop(),
  762. index = node.sourceSlots.pop(),
  763. obs = source.observers;
  764. if (obs && obs.length) {
  765. const n = obs.pop(),
  766. s = source.observerSlots.pop();
  767. if (index < obs.length) {
  768. n.sourceSlots[s] = index;
  769. obs[index] = n;
  770. source.observerSlots[index] = s;
  771. }
  772. }
  773. }
  774. }
  775. if (Transition && Transition.running && node.pure) {
  776. if (node.tOwned) {
  777. for (i = 0; i < node.tOwned.length; i++) cleanNode(node.tOwned[i]);
  778. delete node.tOwned;
  779. }
  780. reset(node, true);
  781. } else if (node.owned) {
  782. for (i = 0; i < node.owned.length; i++) cleanNode(node.owned[i]);
  783. node.owned = null;
  784. }
  785. if (node.cleanups) {
  786. for (i = 0; i < node.cleanups.length; i++) node.cleanups[i]();
  787. node.cleanups = null;
  788. }
  789. node.state = 0;
  790. node.context = null;
  791. }
  792. function reset(node, top) {
  793. if (!top) {
  794. node.state = 0;
  795. Transition.disposed.add(node);
  796. }
  797. if (node.owned) {
  798. for (let i = 0; i < node.owned.length; i++) reset(node.owned[i]);
  799. }
  800. }
  801. function handleError(err) {
  802. const fns = ERROR && lookup(Owner, ERROR);
  803. if (!fns) throw err;
  804. fns.forEach(f => f(err));
  805. }
  806. function lookup(owner, key) {
  807. return owner && (owner.context && owner.context[key] || owner.owner && lookup(owner.owner, key));
  808. }
  809. function resolveChildren(children) {
  810. if (typeof children === "function" && !children.length) return resolveChildren(children());
  811. if (Array.isArray(children)) {
  812. const results = [];
  813. for (let i = 0; i < children.length; i++) {
  814. let result = resolveChildren(children[i]);
  815. Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
  816. }
  817. return results;
  818. }
  819. return children;
  820. }
  821. function createProvider(id) {
  822. return function provider(props) {
  823. return createMemo(() => {
  824. Owner.context = {
  825. [id]: props.value
  826. };
  827. return children(() => props.children);
  828. });
  829. };
  830. }
  831. function hash(s) {
  832. for (var i = 0, h = 9; i < s.length;) h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
  833. return `${h ^ h >>> 9}`;
  834. }
  835. function serializeValues(sources = {}) {
  836. const k = Object.keys(sources);
  837. const result = {};
  838. for (let i = 0; i < k.length; i++) {
  839. const key = k[i];
  840. result[key] = sources[key].value;
  841. }
  842. return result;
  843. }
  844. function serializeChildren(root) {
  845. const result = {};
  846. for (let i = 0, len = root.owned.length; i < len; i++) {
  847. const node = root.owned[i];
  848. result[node.componentName ? `${node.componentName}:${node.name}` : node.name] = { ...serializeValues(node.sourceMap),
  849. ...(node.owned ? serializeChildren(node) : {})
  850. };
  851. }
  852. return result;
  853. }
  854. const $RAW = Symbol("state-raw"),
  855. $NODE = Symbol("state-node"),
  856. $PROXY = Symbol("state-proxy"),
  857. $NAME = Symbol("state-name");
  858. function wrap$1(value, name) {
  859. let p = value[$PROXY];
  860. if (!p) {
  861. Object.defineProperty(value, $PROXY, {
  862. value: p = new Proxy(value, proxyTraps$1)
  863. });
  864. let keys = Object.keys(value),
  865. desc = Object.getOwnPropertyDescriptors(value);
  866. for (let i = 0, l = keys.length; i < l; i++) {
  867. const prop = keys[i];
  868. if (desc[prop].get) {
  869. const get = desc[prop].get.bind(p);
  870. Object.defineProperty(value, prop, {
  871. get
  872. });
  873. }
  874. }
  875. if (name) Object.defineProperty(value, $NAME, {
  876. value: name
  877. });
  878. }
  879. return p;
  880. }
  881. function isWrappable(obj) {
  882. return obj != null && typeof obj === "object" && (!obj.__proto__ || obj.__proto__ === Object.prototype || Array.isArray(obj));
  883. }
  884. function unwrap(item, set = new Set()) {
  885. let result, unwrapped, v, prop;
  886. if (result = item != null && item[$RAW]) return result;
  887. if (!isWrappable(item) || set.has(item)) return item;
  888. if (Array.isArray(item)) {
  889. if (Object.isFrozen(item)) item = item.slice(0);else set.add(item);
  890. for (let i = 0, l = item.length; i < l; i++) {
  891. v = item[i];
  892. if ((unwrapped = unwrap(v, set)) !== v) item[i] = unwrapped;
  893. }
  894. } else {
  895. if (Object.isFrozen(item)) item = Object.assign({}, item);else set.add(item);
  896. let keys = Object.keys(item),
  897. desc = Object.getOwnPropertyDescriptors(item);
  898. for (let i = 0, l = keys.length; i < l; i++) {
  899. prop = keys[i];
  900. if (desc[prop].get) continue;
  901. v = item[prop];
  902. if ((unwrapped = unwrap(v, set)) !== v) item[prop] = unwrapped;
  903. }
  904. }
  905. return item;
  906. }
  907. function getDataNodes(target) {
  908. let nodes = target[$NODE];
  909. if (!nodes) Object.defineProperty(target, $NODE, {
  910. value: nodes = {}
  911. });
  912. return nodes;
  913. }
  914. function proxyDescriptor(target, property) {
  915. const desc = Reflect.getOwnPropertyDescriptor(target, property);
  916. if (!desc || desc.get || property === $PROXY || property === $NODE || property === $NAME) return desc;
  917. delete desc.value;
  918. delete desc.writable;
  919. desc.get = () => target[$PROXY][property];
  920. return desc;
  921. }
  922. function createDataNode() {
  923. const [s, set] = createSignal(undefined, {
  924. equals: false,
  925. internal: true
  926. }) ;
  927. s.set = set;
  928. return s;
  929. }
  930. const proxyTraps$1 = {
  931. get(target, property, receiver) {
  932. if (property === $RAW) return target;
  933. if (property === $PROXY) return receiver;
  934. const value = target[property];
  935. if (property === $NODE || property === "__proto__") return value;
  936. const wrappable = isWrappable(value);
  937. if (Listener && (typeof value !== "function" || target.hasOwnProperty(property))) {
  938. let nodes, node;
  939. if (wrappable && (nodes = getDataNodes(value))) {
  940. node = nodes._ || (nodes._ = createDataNode());
  941. node();
  942. }
  943. nodes = getDataNodes(target);
  944. node = nodes[property] || (nodes[property] = createDataNode());
  945. node();
  946. }
  947. return wrappable ? wrap$1(value, target[$NAME] && `${target[$NAME]}:${property}`) : value;
  948. },
  949. set() {
  950. return true;
  951. },
  952. deleteProperty() {
  953. return true;
  954. },
  955. getOwnPropertyDescriptor: proxyDescriptor
  956. };
  957. function setProperty(state, property, value) {
  958. if (state[property] === value) return;
  959. const array = Array.isArray(state);
  960. const len = state.length;
  961. const notify = array || !(property in state);
  962. if (value === undefined) {
  963. delete state[property];
  964. } else state[property] = value;
  965. let nodes = getDataNodes(state),
  966. node;
  967. (node = nodes[property]) && node.set();
  968. if (array && state.length !== len) (node = nodes.length) && node.set();
  969. notify && (node = nodes._) && node.set();
  970. }
  971. function mergeState(state, value) {
  972. const keys = Object.keys(value);
  973. for (let i = 0; i < keys.length; i += 1) {
  974. const key = keys[i];
  975. setProperty(state, key, value[key]);
  976. }
  977. }
  978. function updatePath(current, path, traversed = []) {
  979. let part,
  980. prev = current;
  981. if (path.length > 1) {
  982. part = path.shift();
  983. const partType = typeof part,
  984. isArray = Array.isArray(current);
  985. if (Array.isArray(part)) {
  986. for (let i = 0; i < part.length; i++) {
  987. updatePath(current, [part[i]].concat(path), [part[i]].concat(traversed));
  988. }
  989. return;
  990. } else if (isArray && partType === "function") {
  991. for (let i = 0; i < current.length; i++) {
  992. if (part(current[i], i)) updatePath(current, [i].concat(path), [i].concat(traversed));
  993. }
  994. return;
  995. } else if (isArray && partType === "object") {
  996. const {
  997. from = 0,
  998. to = current.length - 1,
  999. by = 1
  1000. } = part;
  1001. for (let i = from; i <= to; i += by) {
  1002. updatePath(current, [i].concat(path), [i].concat(traversed));
  1003. }
  1004. return;
  1005. } else if (path.length > 1) {
  1006. updatePath(current[part], path, [part].concat(traversed));
  1007. return;
  1008. }
  1009. prev = current[part];
  1010. traversed = [part].concat(traversed);
  1011. }
  1012. let value = path[0];
  1013. if (typeof value === "function") {
  1014. value = value(prev, traversed);
  1015. if (value === prev) return;
  1016. }
  1017. if (part === undefined && value == undefined) return;
  1018. value = unwrap(value);
  1019. if (part === undefined || isWrappable(prev) && isWrappable(value) && !Array.isArray(value)) {
  1020. mergeState(prev, value);
  1021. } else setProperty(current, part, value);
  1022. }
  1023. function createState(state, options) {
  1024. const unwrappedState = unwrap(state || {});
  1025. const wrappedState = wrap$1(unwrappedState, (options && options.name || hashValue(unwrappedState)));
  1026. {
  1027. const name = options && options.name || hashValue(unwrappedState);
  1028. registerGraph(name, {
  1029. value: unwrappedState
  1030. });
  1031. }
  1032. function setState(...args) {
  1033. batch(() => updatePath(unwrappedState, args));
  1034. }
  1035. return [wrappedState, setState];
  1036. }
  1037. const proxyTraps = {
  1038. get(target, property, receiver) {
  1039. if (property === $RAW) return target;
  1040. if (property === $PROXY) return receiver;
  1041. const value = target[property];
  1042. if (property === $NODE || property === "__proto__") return value;
  1043. const wrappable = isWrappable(value);
  1044. if (Listener && (typeof value !== "function" || target.hasOwnProperty(property))) {
  1045. let nodes, node;
  1046. if (wrappable && (nodes = getDataNodes(value))) {
  1047. node = nodes._ || (nodes._ = createDataNode());
  1048. node();
  1049. }
  1050. nodes = getDataNodes(target);
  1051. node = nodes[property] || (nodes[property] = createDataNode());
  1052. node();
  1053. }
  1054. return wrappable ? wrap(value, target[$NAME] && `${target[$NAME]}:${property}`) : value;
  1055. },
  1056. set(target, property, value) {
  1057. setProperty(target, property, unwrap(value));
  1058. return true;
  1059. },
  1060. deleteProperty(target, property) {
  1061. setProperty(target, property, undefined);
  1062. return true;
  1063. },
  1064. getOwnPropertyDescriptor: proxyDescriptor
  1065. };
  1066. function wrap(value, name) {
  1067. let p = value[$PROXY];
  1068. if (!p) {
  1069. Object.defineProperty(value, $PROXY, {
  1070. value: p = new Proxy(value, proxyTraps)
  1071. });
  1072. let keys = Object.keys(value),
  1073. desc = Object.getOwnPropertyDescriptors(value);
  1074. for (let i = 0, l = keys.length; i < l; i++) {
  1075. const prop = keys[i];
  1076. if (desc[prop].get) {
  1077. const get = desc[prop].get.bind(p);
  1078. Object.defineProperty(value, prop, {
  1079. get
  1080. });
  1081. }
  1082. if (desc[prop].set) {
  1083. const og = desc[prop].set,
  1084. set = v => batch(() => og.call(p, v));
  1085. Object.defineProperty(value, prop, {
  1086. set
  1087. });
  1088. }
  1089. }
  1090. if (name) Object.defineProperty(value, $NAME, {
  1091. value: name
  1092. });
  1093. }
  1094. return p;
  1095. }
  1096. function createMutable(state, options) {
  1097. const unwrappedState = unwrap(state || {});
  1098. const wrappedState = wrap(unwrappedState, (options && options.name || hashValue(unwrappedState)));
  1099. {
  1100. const name = options && options.name || hashValue(unwrappedState);
  1101. registerGraph(name, {
  1102. value: unwrappedState
  1103. });
  1104. }
  1105. return wrappedState;
  1106. }
  1107. function getSymbol() {
  1108. const SymbolCopy = Symbol;
  1109. return SymbolCopy.observable || '@@observable';
  1110. }
  1111. function observable(input) {
  1112. const $$observable = getSymbol();
  1113. return {
  1114. subscribe(observer) {
  1115. if (!(observer instanceof Object) || observer == null) {
  1116. throw new TypeError("Expected the observer to be an object.");
  1117. }
  1118. const handler = "next" in observer ? observer.next : observer;
  1119. let complete = false;
  1120. createComputed(() => {
  1121. if (complete) return;
  1122. const v = input();
  1123. untrack(() => handler(v));
  1124. });
  1125. return {
  1126. unsubscribe() {
  1127. complete = true;
  1128. }
  1129. };
  1130. },
  1131. [$$observable]() {
  1132. return this;
  1133. }
  1134. };
  1135. }
  1136. function applyState(target, parent, property, merge, key) {
  1137. let previous = parent[property];
  1138. if (target === previous) return;
  1139. if (!isWrappable(target) || !isWrappable(previous) || key && target[key] !== previous[key]) {
  1140. target !== previous && setProperty(parent, property, target);
  1141. return;
  1142. }
  1143. if (Array.isArray(target)) {
  1144. if (target.length && previous.length && (!merge || key && target[0][key] != null)) {
  1145. let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
  1146. for (start = 0, end = Math.min(previous.length, target.length); start < end && (previous[start] === target[start] || key && previous[start][key] === target[start][key]); start++) {
  1147. applyState(target[start], previous, start, merge, key);
  1148. }
  1149. const temp = new Array(target.length),
  1150. newIndices = new Map();
  1151. for (end = previous.length - 1, newEnd = target.length - 1; end >= start && newEnd >= start && (previous[end] === target[newEnd] || key && previous[end][key] === target[newEnd][key]); end--, newEnd--) {
  1152. temp[newEnd] = previous[end];
  1153. }
  1154. if (start > newEnd || start > end) {
  1155. for (j = start; j <= newEnd; j++) setProperty(previous, j, target[j]);
  1156. for (; j < target.length; j++) {
  1157. setProperty(previous, j, temp[j]);
  1158. applyState(target[j], previous, j, merge, key);
  1159. }
  1160. if (previous.length > target.length) setProperty(previous, "length", target.length);
  1161. return;
  1162. }
  1163. newIndicesNext = new Array(newEnd + 1);
  1164. for (j = newEnd; j >= start; j--) {
  1165. item = target[j];
  1166. keyVal = key ? item[key] : item;
  1167. i = newIndices.get(keyVal);
  1168. newIndicesNext[j] = i === undefined ? -1 : i;
  1169. newIndices.set(keyVal, j);
  1170. }
  1171. for (i = start; i <= end; i++) {
  1172. item = previous[i];
  1173. keyVal = key ? item[key] : item;
  1174. j = newIndices.get(keyVal);
  1175. if (j !== undefined && j !== -1) {
  1176. temp[j] = previous[i];
  1177. j = newIndicesNext[j];
  1178. newIndices.set(keyVal, j);
  1179. }
  1180. }
  1181. for (j = start; j < target.length; j++) {
  1182. if (j in temp) {
  1183. setProperty(previous, j, temp[j]);
  1184. applyState(target[j], previous, j, merge, key);
  1185. } else setProperty(previous, j, target[j]);
  1186. }
  1187. } else {
  1188. for (let i = 0, len = target.length; i < len; i++) {
  1189. applyState(target[i], previous, i, merge, key);
  1190. }
  1191. }
  1192. if (previous.length > target.length) setProperty(previous, "length", target.length);
  1193. return;
  1194. }
  1195. const targetKeys = Object.keys(target);
  1196. for (let i = 0, len = targetKeys.length; i < len; i++) {
  1197. applyState(target[targetKeys[i]], previous, targetKeys[i], merge, key);
  1198. }
  1199. const previousKeys = Object.keys(previous);
  1200. for (let i = 0, len = previousKeys.length; i < len; i++) {
  1201. if (target[previousKeys[i]] === undefined) setProperty(previous, previousKeys[i], undefined);
  1202. }
  1203. }
  1204. function reconcile(value, options = {}) {
  1205. const {
  1206. merge,
  1207. key = "id"
  1208. } = options,
  1209. v = unwrap(value);
  1210. return state => {
  1211. if (!isWrappable(state) || !isWrappable(v)) return v;
  1212. applyState(v, {
  1213. state
  1214. }, "state", merge, key);
  1215. return state;
  1216. };
  1217. }
  1218. const setterTraps = {
  1219. get(target, property) {
  1220. if (property === $RAW) return target;
  1221. const value = target[property];
  1222. return isWrappable(value) ? new Proxy(value, setterTraps) : value;
  1223. },
  1224. set(target, property, value) {
  1225. setProperty(target, property, unwrap(value));
  1226. return true;
  1227. },
  1228. deleteProperty(target, property) {
  1229. setProperty(target, property, undefined);
  1230. return true;
  1231. }
  1232. };
  1233. function produce(fn) {
  1234. return state => {
  1235. if (isWrappable(state)) fn(new Proxy(state, setterTraps));
  1236. return state;
  1237. };
  1238. }
  1239. const FALLBACK = Symbol("fallback");
  1240. function mapArray(list, mapFn, options = {}) {
  1241. let items = [],
  1242. mapped = [],
  1243. disposers = [],
  1244. len = 0,
  1245. indexes = mapFn.length > 1 ? [] : null,
  1246. ctx = Owner;
  1247. onCleanup(() => {
  1248. for (let i = 0, length = disposers.length; i < length; i++) disposers[i]();
  1249. });
  1250. return () => {
  1251. let newItems = list() || [],
  1252. i,
  1253. j;
  1254. return untrack(() => {
  1255. let newLen = newItems.length,
  1256. newIndices,
  1257. newIndicesNext,
  1258. temp,
  1259. tempdisposers,
  1260. tempIndexes,
  1261. start,
  1262. end,
  1263. newEnd,
  1264. item;
  1265. if (newLen === 0) {
  1266. if (len !== 0) {
  1267. for (i = 0; i < len; i++) disposers[i]();
  1268. disposers = [];
  1269. items = [];
  1270. mapped = [];
  1271. len = 0;
  1272. indexes && (indexes = []);
  1273. }
  1274. if (options.fallback) {
  1275. items = [FALLBACK];
  1276. mapped[0] = createRoot(disposer => {
  1277. disposers[0] = disposer;
  1278. return options.fallback();
  1279. }, ctx);
  1280. len = 1;
  1281. }
  1282. }
  1283. else if (len === 0) {
  1284. for (j = 0; j < newLen; j++) {
  1285. items[j] = newItems[j];
  1286. mapped[j] = createRoot(mapper, ctx);
  1287. }
  1288. len = newLen;
  1289. } else {
  1290. temp = new Array(newLen);
  1291. tempdisposers = new Array(newLen);
  1292. indexes && (tempIndexes = new Array(newLen));
  1293. for (start = 0, end = Math.min(len, newLen); start < end && items[start] === newItems[start]; start++);
  1294. for (end = len - 1, newEnd = newLen - 1; end >= start && newEnd >= start && items[end] === newItems[newEnd]; end--, newEnd--) {
  1295. temp[newEnd] = mapped[end];
  1296. tempdisposers[newEnd] = disposers[end];
  1297. indexes && (tempIndexes[newEnd] = indexes[end]);
  1298. }
  1299. newIndices = new Map();
  1300. newIndicesNext = new Array(newEnd + 1);
  1301. for (j = newEnd; j >= start; j--) {
  1302. item = newItems[j];
  1303. i = newIndices.get(item);
  1304. newIndicesNext[j] = i === undefined ? -1 : i;
  1305. newIndices.set(item, j);
  1306. }
  1307. for (i = start; i <= end; i++) {
  1308. item = items[i];
  1309. j = newIndices.get(item);
  1310. if (j !== undefined && j !== -1) {
  1311. temp[j] = mapped[i];
  1312. tempdisposers[j] = disposers[i];
  1313. indexes && (tempIndexes[j] = indexes[i]);
  1314. j = newIndicesNext[j];
  1315. newIndices.set(item, j);
  1316. } else disposers[i]();
  1317. }
  1318. for (j = start; j < newLen; j++) {
  1319. if (j in temp) {
  1320. mapped[j] = temp[j];
  1321. disposers[j] = tempdisposers[j];
  1322. if (indexes) {
  1323. indexes[j] = tempIndexes[j];
  1324. indexes[j](j);
  1325. }
  1326. } else mapped[j] = createRoot(mapper, ctx);
  1327. }
  1328. len = mapped.length = newLen;
  1329. items = newItems.slice(0);
  1330. }
  1331. return mapped;
  1332. });
  1333. function mapper(disposer) {
  1334. disposers[j] = disposer;
  1335. if (indexes) {
  1336. const [s, set] = createSignal(j);
  1337. indexes[j] = set;
  1338. return mapFn(newItems[j], s);
  1339. }
  1340. return mapFn(newItems[j]);
  1341. }
  1342. };
  1343. }
  1344. function indexArray(list, mapFn, options = {}) {
  1345. let items = [],
  1346. mapped = [],
  1347. disposers = [],
  1348. signals = [],
  1349. len = 0,
  1350. i,
  1351. ctx = Owner;
  1352. onCleanup(() => {
  1353. for (let i = 0, length = disposers.length; i < length; i++) disposers[i]();
  1354. });
  1355. return () => {
  1356. const newItems = list() || [];
  1357. return untrack(() => {
  1358. if (newItems.length === 0) {
  1359. if (len !== 0) {
  1360. for (i = 0; i < len; i++) disposers[i]();
  1361. disposers = [];
  1362. items = [];
  1363. mapped = [];
  1364. len = 0;
  1365. signals = [];
  1366. }
  1367. if (options.fallback) {
  1368. items = [FALLBACK];
  1369. mapped[0] = createRoot(disposer => {
  1370. disposers[0] = disposer;
  1371. return options.fallback();
  1372. }, ctx);
  1373. len = 1;
  1374. }
  1375. return mapped;
  1376. }
  1377. if (items[0] === FALLBACK) {
  1378. disposers[0]();
  1379. disposers = [];
  1380. items = [];
  1381. mapped = [];
  1382. len = 0;
  1383. }
  1384. for (i = 0; i < newItems.length; i++) {
  1385. if (i < items.length && items[i] !== newItems[i]) {
  1386. signals[i](newItems[i]);
  1387. } else if (i >= items.length) {
  1388. mapped[i] = createRoot(mapper, ctx);
  1389. }
  1390. }
  1391. for (; i < items.length; i++) {
  1392. disposers[i]();
  1393. }
  1394. len = mapped.length = signals.length = disposers.length = newItems.length;
  1395. items = newItems.slice(0);
  1396. return mapped;
  1397. });
  1398. function mapper(disposer) {
  1399. disposers[i] = disposer;
  1400. const [s, set] = createSignal(newItems[i]);
  1401. signals[i] = set;
  1402. return mapFn(s, i);
  1403. }
  1404. };
  1405. }
  1406. function createComponent(Comp, props) {
  1407. if (sharedConfig.context) {
  1408. const c = sharedConfig.context;
  1409. setHydrateContext(nextHydrateContext());
  1410. const r = devComponent(Comp, props) ;
  1411. setHydrateContext(c);
  1412. return r;
  1413. }
  1414. return devComponent(Comp, props);
  1415. }
  1416. function trueFn() {
  1417. return true;
  1418. }
  1419. const propTraps = {
  1420. get(_, property, receiver) {
  1421. if (property === $PROXY) return receiver;
  1422. return _.get(property);
  1423. },
  1424. has(_, property) {
  1425. return _.has(property);
  1426. },
  1427. set: trueFn,
  1428. deleteProperty: trueFn,
  1429. getOwnPropertyDescriptor(_, property) {
  1430. return {
  1431. configurable: true,
  1432. enumerable: true,
  1433. get() {
  1434. return _.get(property);
  1435. },
  1436. set: trueFn,
  1437. deleteProperty: trueFn
  1438. };
  1439. },
  1440. ownKeys(_) {
  1441. return _.keys();
  1442. }
  1443. };
  1444. function mergeProps(...sources) {
  1445. return new Proxy({
  1446. get(property) {
  1447. for (let i = sources.length - 1; i >= 0; i--) {
  1448. const v = sources[i][property];
  1449. if (v !== undefined) return v;
  1450. }
  1451. },
  1452. has(property) {
  1453. for (let i = sources.length - 1; i >= 0; i--) {
  1454. if (property in sources[i]) return true;
  1455. }
  1456. return false;
  1457. },
  1458. keys() {
  1459. const keys = [];
  1460. for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(sources[i]));
  1461. return [...new Set(keys)];
  1462. }
  1463. }, propTraps);
  1464. }
  1465. function splitProps(props, ...keys) {
  1466. const blocked = new Set(keys.flat());
  1467. const descriptors = Object.getOwnPropertyDescriptors(props);
  1468. const res = keys.map(k => {
  1469. const clone = {};
  1470. for (let i = 0; i < k.length; i++) {
  1471. const key = k[i];
  1472. Object.defineProperty(clone, key, descriptors[key] ? descriptors[key] : {
  1473. get() {
  1474. return props[key];
  1475. }
  1476. });
  1477. }
  1478. return clone;
  1479. });
  1480. res.push(new Proxy({
  1481. get(property) {
  1482. return blocked.has(property) ? undefined : props[property];
  1483. },
  1484. has(property) {
  1485. return blocked.has(property) ? false : property in props;
  1486. },
  1487. keys() {
  1488. return Object.keys(props).filter(k => !blocked.has(k));
  1489. }
  1490. }, propTraps));
  1491. return res;
  1492. }
  1493. function lazy(fn) {
  1494. let p;
  1495. const wrap = props => {
  1496. const ctx = sharedConfig.context;
  1497. let comp;
  1498. if (ctx && sharedConfig.resources) {
  1499. ctx.count++;
  1500. const [s, set] = createSignal();
  1501. (p || (p = fn())).then(mod => {
  1502. setHydrateContext(ctx);
  1503. set(mod.default);
  1504. setHydrateContext(undefined);
  1505. });
  1506. comp = s;
  1507. } else {
  1508. const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
  1509. comp = s;
  1510. }
  1511. let Comp;
  1512. return createMemo(() => (Comp = comp()) && untrack(() => {
  1513. if (!ctx) return Comp(props);
  1514. const c = sharedConfig.context;
  1515. setHydrateContext(ctx);
  1516. const r = Comp(props);
  1517. setHydrateContext(c);
  1518. return r;
  1519. }));
  1520. };
  1521. wrap.preload = () => (p || (p = fn())).then(mod => mod.default);
  1522. return wrap;
  1523. }
  1524. function For(props) {
  1525. const fallback = "fallback" in props && {
  1526. fallback: () => props.fallback
  1527. };
  1528. return createMemo(mapArray(() => props.each, props.children, fallback ? fallback : undefined), undefined, {
  1529. equals: false
  1530. });
  1531. }
  1532. function Index(props) {
  1533. const fallback = "fallback" in props && {
  1534. fallback: () => props.fallback
  1535. };
  1536. return createMemo(indexArray(() => props.each, props.children, fallback ? fallback : undefined), undefined, {
  1537. equals: false
  1538. });
  1539. }
  1540. function Show(props) {
  1541. let strictEqual = false;
  1542. const condition = createMemo(() => props.when, undefined, {
  1543. equals: (a, b) => strictEqual ? a === b : !a === !b
  1544. });
  1545. return createMemo(() => {
  1546. const c = condition();
  1547. if (c) {
  1548. const child = props.children;
  1549. return (strictEqual = typeof child === "function" && child.length > 0) ? untrack(() => child(c)) : child;
  1550. }
  1551. return props.fallback;
  1552. });
  1553. }
  1554. function Switch(props) {
  1555. let strictEqual = false;
  1556. const conditions = children(() => props.children),
  1557. evalConditions = createMemo(() => {
  1558. let conds = conditions();
  1559. if (!Array.isArray(conds)) conds = [conds];
  1560. for (let i = 0; i < conds.length; i++) {
  1561. const c = conds[i].when;
  1562. if (c) return [i, c, conds[i]];
  1563. }
  1564. return [-1];
  1565. }, undefined, {
  1566. equals: (a, b) => a && a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
  1567. });
  1568. return createMemo(() => {
  1569. const [index, when, cond] = evalConditions();
  1570. if (index < 0) return props.fallback;
  1571. const c = cond.children;
  1572. return (strictEqual = typeof c === "function" && c.length > 0) ? untrack(() => c(when)) : c;
  1573. });
  1574. }
  1575. function Match(props) {
  1576. return props;
  1577. }
  1578. function ErrorBoundary(props) {
  1579. const [errored, setErrored] = createSignal();
  1580. onError(setErrored);
  1581. let e;
  1582. return createMemo(() => {
  1583. if ((e = errored()) != null) {
  1584. const f = props.fallback;
  1585. return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(null))) : f;
  1586. }
  1587. return props.children;
  1588. });
  1589. }
  1590. const SuspenseListContext = createContext();
  1591. function SuspenseList(props) {
  1592. let index = 0,
  1593. suspenseSetter,
  1594. showContent,
  1595. showFallback;
  1596. const listContext = useContext(SuspenseListContext);
  1597. if (listContext) {
  1598. const [inFallback, setFallback] = createSignal(false);
  1599. suspenseSetter = setFallback;
  1600. [showContent, showFallback] = listContext.register(inFallback);
  1601. }
  1602. const registry = [],
  1603. comp = createComponent(SuspenseListContext.Provider, {
  1604. value: {
  1605. register: inFallback => {
  1606. const [showingContent, showContent] = createSignal(false),
  1607. [showingFallback, showFallback] = createSignal(false);
  1608. registry[index++] = {
  1609. inFallback,
  1610. showContent,
  1611. showFallback
  1612. };
  1613. return [showingContent, showingFallback];
  1614. }
  1615. },
  1616. get children() {
  1617. return props.children;
  1618. }
  1619. });
  1620. createComputed(() => {
  1621. const reveal = props.revealOrder,
  1622. tail = props.tail,
  1623. visibleContent = showContent ? showContent() : true,
  1624. visibleFallback = showFallback ? showFallback() : true,
  1625. reverse = reveal === "backwards";
  1626. if (reveal === "together") {
  1627. const all = registry.every(i => !i.inFallback());
  1628. suspenseSetter && suspenseSetter(!all);
  1629. registry.forEach(i => {
  1630. i.showContent(all && visibleContent);
  1631. i.showFallback(visibleFallback);
  1632. });
  1633. return;
  1634. }
  1635. let stop = false;
  1636. for (let i = 0, len = registry.length; i < len; i++) {
  1637. const n = reverse ? len - i - 1 : i,
  1638. s = registry[n].inFallback();
  1639. if (!stop && !s) {
  1640. registry[n].showContent(visibleContent);
  1641. registry[n].showFallback(visibleFallback);
  1642. } else {
  1643. const next = !stop;
  1644. if (next && suspenseSetter) suspenseSetter(true);
  1645. if (!tail || next && tail === "collapsed") {
  1646. registry[n].showFallback(visibleFallback);
  1647. } else registry[n].showFallback(false);
  1648. stop = true;
  1649. registry[n].showContent(next);
  1650. }
  1651. }
  1652. if (!stop && suspenseSetter) suspenseSetter(false);
  1653. });
  1654. return comp;
  1655. }
  1656. function Suspense(props) {
  1657. let counter = 0,
  1658. showContent,
  1659. showFallback;
  1660. const [inFallback, setFallback] = createSignal(false),
  1661. SuspenseContext = getSuspenseContext(),
  1662. store = {
  1663. increment: () => {
  1664. if (++counter === 1) setFallback(true);
  1665. },
  1666. decrement: () => {
  1667. if (--counter === 0) setFallback(false);
  1668. },
  1669. inFallback,
  1670. effects: [],
  1671. resolved: false
  1672. };
  1673. const listContext = useContext(SuspenseListContext);
  1674. if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
  1675. return createComponent(SuspenseContext.Provider, {
  1676. value: store,
  1677. get children() {
  1678. const rendered = untrack(() => props.children);
  1679. return createMemo(() => {
  1680. const inFallback = store.inFallback(),
  1681. visibleContent = showContent ? showContent() : true,
  1682. visibleFallback = showFallback ? showFallback() : true;
  1683. if (!inFallback && visibleContent) {
  1684. store.resolved = true;
  1685. resumeEffects(store.effects);
  1686. return rendered;
  1687. }
  1688. if (!visibleFallback) return;
  1689. return props.fallback;
  1690. });
  1691. }
  1692. });
  1693. }
  1694. function awaitSuspense() {}
  1695. exports.DEV = void 0;
  1696. {
  1697. exports.DEV = {
  1698. writeSignal,
  1699. serializeGraph
  1700. };
  1701. }
  1702. if (globalThis) {
  1703. if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
  1704. }
  1705. exports.$RAW = $RAW;
  1706. exports.ErrorBoundary = ErrorBoundary;
  1707. exports.For = For;
  1708. exports.Index = Index;
  1709. exports.Match = Match;
  1710. exports.Show = Show;
  1711. exports.Suspense = Suspense;
  1712. exports.SuspenseList = SuspenseList;
  1713. exports.Switch = Switch;
  1714. exports.awaitSuspense = awaitSuspense;
  1715. exports.batch = batch;
  1716. exports.cancelCallback = cancelCallback;
  1717. exports.children = children;
  1718. exports.createComponent = createComponent;
  1719. exports.createComputed = createComputed;
  1720. exports.createContext = createContext;
  1721. exports.createDeferred = createDeferred;
  1722. exports.createEffect = createEffect;
  1723. exports.createMemo = createMemo;
  1724. exports.createMutable = createMutable;
  1725. exports.createRenderEffect = createRenderEffect;
  1726. exports.createResource = createResource;
  1727. exports.createRoot = createRoot;
  1728. exports.createSelector = createSelector;
  1729. exports.createSignal = createSignal;
  1730. exports.createState = createState;
  1731. exports.equalFn = equalFn;
  1732. exports.getListener = getListener;
  1733. exports.getOwner = getOwner;
  1734. exports.indexArray = indexArray;
  1735. exports.lazy = lazy;
  1736. exports.mapArray = mapArray;
  1737. exports.mergeProps = mergeProps;
  1738. exports.observable = observable;
  1739. exports.on = on;
  1740. exports.onCleanup = onCleanup;
  1741. exports.onError = onError;
  1742. exports.onMount = onMount;
  1743. exports.produce = produce;
  1744. exports.reconcile = reconcile;
  1745. exports.requestCallback = requestCallback;
  1746. exports.runWithOwner = runWithOwner;
  1747. exports.sharedConfig = sharedConfig;
  1748. exports.splitProps = splitProps;
  1749. exports.untrack = untrack;
  1750. exports.unwrap = unwrap;
  1751. exports.useContext = useContext;
  1752. exports.useTransition = useTransition;