dev.js 50 KB

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