solid.cjs 47 KB

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