12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', { value: true });
- let taskIdCounter = 1,
- isCallbackScheduled = false,
- isPerformingWork = false,
- taskQueue = [],
- currentTask = null,
- shouldYieldToHost = null,
- yieldInterval = 5,
- deadline = 0,
- maxYieldInterval = 300,
- scheduleCallback = null,
- scheduledCallback = null;
- const maxSigned31BitInt = 1073741823;
- function setupScheduler() {
- const channel = new MessageChannel(),
- port = channel.port2;
- scheduleCallback = () => port.postMessage(null);
- channel.port1.onmessage = () => {
- if (scheduledCallback !== null) {
- const currentTime = performance.now();
- deadline = currentTime + yieldInterval;
- const hasTimeRemaining = true;
- try {
- const hasMoreWork = scheduledCallback(hasTimeRemaining, currentTime);
- if (!hasMoreWork) {
- scheduledCallback = null;
- } else port.postMessage(null);
- } catch (error) {
- port.postMessage(null);
- throw error;
- }
- }
- };
- if (navigator && navigator.scheduling && navigator.scheduling.isInputPending) {
- const scheduling = navigator.scheduling;
- shouldYieldToHost = () => {
- const currentTime = performance.now();
- if (currentTime >= deadline) {
- if (scheduling.isInputPending()) {
- return true;
- }
- return currentTime >= maxYieldInterval;
- } else {
- return false;
- }
- };
- } else {
- shouldYieldToHost = () => performance.now() >= deadline;
- }
- }
- function enqueue(taskQueue, task) {
- function findIndex() {
- let m = 0;
- let n = taskQueue.length - 1;
- while (m <= n) {
- let k = n + m >> 1;
- let cmp = task.expirationTime - taskQueue[k].expirationTime;
- if (cmp > 0) m = k + 1;else if (cmp < 0) n = k - 1;else return k;
- }
- return m;
- }
- taskQueue.splice(findIndex(), 0, task);
- }
- function requestCallback(fn, options) {
- if (!scheduleCallback) setupScheduler();
- let startTime = performance.now(),
- timeout = maxSigned31BitInt;
- if (options && options.timeout) timeout = options.timeout;
- const newTask = {
- id: taskIdCounter++,
- fn,
- startTime,
- expirationTime: startTime + timeout
- };
- enqueue(taskQueue, newTask);
- if (!isCallbackScheduled && !isPerformingWork) {
- isCallbackScheduled = true;
- scheduledCallback = flushWork;
- scheduleCallback();
- }
- return newTask;
- }
- function cancelCallback(task) {
- task.fn = null;
- }
- function flushWork(hasTimeRemaining, initialTime) {
- isCallbackScheduled = false;
- isPerformingWork = true;
- try {
- return workLoop(hasTimeRemaining, initialTime);
- } finally {
- currentTask = null;
- isPerformingWork = false;
- }
- }
- function workLoop(hasTimeRemaining, initialTime) {
- let currentTime = initialTime;
- currentTask = taskQueue[0] || null;
- while (currentTask !== null) {
- if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) {
- break;
- }
- const callback = currentTask.fn;
- if (callback !== null) {
- currentTask.fn = null;
- const didUserCallbackTimeout = currentTask.expirationTime <= currentTime;
- callback(didUserCallbackTimeout);
- currentTime = performance.now();
- if (currentTask === taskQueue[0]) {
- taskQueue.shift();
- }
- } else taskQueue.shift();
- currentTask = taskQueue[0] || null;
- }
- return currentTask !== null;
- }
- const sharedConfig = {};
- function setHydrateContext(context) {
- sharedConfig.context = context;
- }
- function nextHydrateContext() {
- return { ...sharedConfig.context,
- id: `${sharedConfig.context.id}${sharedConfig.context.count++}.`,
- count: 0
- };
- }
- const equalFn = (a, b) => a === b;
- const signalOptions = {
- equals: equalFn
- };
- let ERROR = null;
- let runEffects = runQueue;
- const NOTPENDING = {};
- const STALE = 1;
- const PENDING = 2;
- const UNOWNED = {
- owned: null,
- cleanups: null,
- context: null,
- owner: null
- };
- const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
- var Owner = null;
- var Listener = null;
- let Pending = null;
- let Updates = null;
- let Effects = null;
- let Transition = null;
- let ExecCount = 0;
- let rootCount = 0;
- function createRoot(fn, detachedOwner) {
- detachedOwner && (Owner = detachedOwner);
- const listener = Listener,
- owner = Owner,
- root = fn.length === 0 && !"_SOLID_DEV_" ? UNOWNED : {
- owned: null,
- cleanups: null,
- context: null,
- owner,
- attached: !!detachedOwner
- };
- if (owner) root.name = owner.name + "-r" + rootCount++;
- Owner = root;
- Listener = null;
- let result;
- try {
- runUpdates(() => result = fn(() => cleanNode(root)), true);
- } finally {
- Listener = listener;
- Owner = owner;
- }
- return result;
- }
- function createSignal(value, options) {
- options = options ? Object.assign({}, signalOptions, options) : signalOptions;
- const s = {
- value,
- observers: null,
- observerSlots: null,
- pending: NOTPENDING,
- comparator: options.equals || undefined
- };
- if ((!options || !options.internal)) s.name = registerGraph(options && options.name || hashValue(value), s);
- return [readSignal.bind(s), writeSignal.bind(s)];
- }
- function createComputed(fn, value, options) {
- updateComputation(createComputation(fn, value, true, options ));
- }
- function createRenderEffect(fn, value, options) {
- updateComputation(createComputation(fn, value, false, options ));
- }
- function createEffect(fn, value, options) {
- runEffects = runUserEffects;
- const c = createComputation(fn, value, false, options ),
- s = SuspenseContext && lookup(Owner, SuspenseContext.id);
- if (s) c.suspense = s;
- c.user = true;
- Effects && Effects.push(c);
- }
- function createMemo(fn, value, options) {
- options = options ? Object.assign({}, signalOptions, options) : signalOptions;
- const c = createComputation(fn, value, true, options );
- c.pending = NOTPENDING;
- c.observers = null;
- c.observerSlots = null;
- c.state = 0;
- c.comparator = options.equals || undefined;
- updateComputation(c);
- return readSignal.bind(c);
- }
- function createResource(source, fetcher, options = {}) {
- if (arguments.length === 2) {
- if (typeof fetcher === "object") {
- options = fetcher;
- fetcher = source;
- source = true;
- }
- } else if (arguments.length === 1) {
- fetcher = source;
- source = true;
- }
- const contexts = new Set(),
- [s, set] = createSignal(options.initialValue),
- [track, trigger] = createSignal(undefined, {
- equals: false
- }),
- [loading, setLoading] = createSignal(false),
- [error, setError] = createSignal();
- let err = undefined,
- pr = null,
- initP = null,
- id = null,
- loadedUnderTransition = false,
- dynamic = typeof source === "function";
- if (sharedConfig.context) {
- id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
- if (sharedConfig.context.loadResource) {
- initP = sharedConfig.context.loadResource(id);
- } else if (sharedConfig.resources && id && id in sharedConfig.resources) {
- initP = sharedConfig.resources[id];
- delete sharedConfig.resources[id];
- }
- }
- function loadEnd(p, v, e) {
- if (pr === p) {
- setError(err = e);
- pr = null;
- if (Transition && p && loadedUnderTransition) {
- Transition.promises.delete(p);
- loadedUnderTransition = false;
- runUpdates(() => {
- Transition.running = true;
- if (!Transition.promises.size) {
- Effects.push.apply(Effects, Transition.effects);
- Transition.effects = [];
- }
- completeLoad(v);
- }, false);
- } else completeLoad(v);
- }
- return v;
- }
- function completeLoad(v) {
- batch(() => {
- set(v);
- setLoading(false);
- for (let c of contexts.keys()) c.decrement();
- contexts.clear();
- });
- }
- function read() {
- const c = SuspenseContext && lookup(Owner, SuspenseContext.id),
- v = s();
- if (err) throw err;
- if (Listener && !Listener.user && c) {
- createComputed(() => {
- track();
- if (pr) {
- if (c.resolved && Transition) Transition.promises.add(pr);else if (!contexts.has(c)) {
- c.increment();
- contexts.add(c);
- }
- }
- });
- }
- return v;
- }
- function load() {
- setError(err = undefined);
- let lookup = dynamic ? source() : source;
- loadedUnderTransition = Transition && Transition.running;
- if (lookup == null || lookup === false) {
- loadEnd(pr, untrack(s));
- return;
- }
- if (Transition && pr) Transition.promises.delete(pr);
- const p = initP || fetcher(lookup, s);
- initP = null;
- if (typeof p !== "object" || !("then" in p)) {
- loadEnd(pr, p);
- return;
- }
- pr = p;
- batch(() => {
- setLoading(true);
- trigger();
- });
- p.then(v => loadEnd(p, v), e => loadEnd(p, e, e));
- }
- Object.defineProperties(read, {
- loading: {
- get() {
- return loading();
- }
- },
- error: {
- get() {
- return error();
- }
- }
- });
- if (dynamic) createComputed(load);else load();
- return [read, {
- refetch: load,
- mutate: set
- }];
- }
- function createDeferred(source, options) {
- let t,
- timeout = options ? options.timeoutMs : undefined;
- const node = createComputation(() => {
- if (!t || !t.fn) t = requestCallback(() => setDeferred(node.value), timeout !== undefined ? {
- timeout
- } : undefined);
- return source();
- }, undefined, true);
- const [deferred, setDeferred] = createSignal(node.value, options);
- updateComputation(node);
- setDeferred(node.value);
- return deferred;
- }
- function createSelector(source, fn = equalFn, options) {
- let subs = new Map();
- const node = createComputation(p => {
- const v = source();
- for (const key of subs.keys()) if (fn(key, v) || p !== undefined && fn(key, p)) {
- const l = subs.get(key);
- for (const c of l.values()) {
- c.state = STALE;
- if (c.pure) Updates.push(c);else Effects.push(c);
- }
- }
- return v;
- }, undefined, true, options );
- updateComputation(node);
- return key => {
- let listener;
- if (listener = Listener) {
- let l;
- if (l = subs.get(key)) l.add(listener);else subs.set(key, l = new Set([listener]));
- onCleanup(() => {
- l.size > 1 ? l.delete(listener) : subs.delete(key);
- });
- }
- return fn(key, node.value);
- };
- }
- function batch(fn) {
- if (Pending) return fn();
- let result;
- const q = Pending = [];
- try {
- result = fn();
- } finally {
- Pending = null;
- }
- runUpdates(() => {
- for (let i = 0; i < q.length; i += 1) {
- const data = q[i];
- if (data.pending !== NOTPENDING) {
- const pending = data.pending;
- data.pending = NOTPENDING;
- writeSignal.call(data, pending);
- }
- }
- }, false);
- return result;
- }
- function untrack(fn) {
- let result,
- listener = Listener;
- Listener = null;
- result = fn();
- Listener = listener;
- return result;
- }
- function on(deps, fn, options) {
- let isArray = Array.isArray(deps);
- let prev;
- let defer = options && options.defer;
- return prevResult => {
- let value;
- if (isArray) {
- value = [];
- for (let i = 0; i < deps.length; i++) value.push(deps[i]());
- } else value = deps();
- if (defer) {
- defer = false;
- return undefined;
- }
- const result = untrack(() => fn(value, prev, prevResult));
- prev = value;
- return result;
- };
- }
- function onMount(fn) {
- createEffect(() => untrack(fn));
- }
- function onCleanup(fn) {
- 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);
- return fn;
- }
- function onError(fn) {
- ERROR || (ERROR = Symbol("error"));
- if (Owner === null) console.warn("error handlers created outside a `createRoot` or `render` will never be run");else if (Owner.context === null) Owner.context = {
- [ERROR]: [fn]
- };else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn];else Owner.context[ERROR].push(fn);
- }
- function getListener() {
- return Listener;
- }
- function getOwner() {
- return Owner;
- }
- function runWithOwner(o, fn) {
- const prev = Owner;
- Owner = o;
- try {
- return fn();
- } finally {
- Owner = prev;
- }
- }
- function useTransition() {
- return [transPending, (fn, cb) => {
- if (SuspenseContext) {
- Transition || (Transition = {
- sources: new Set(),
- effects: [],
- promises: new Set(),
- disposed: new Set(),
- running: true,
- cb: []
- });
- cb && Transition.cb.push(cb);
- Transition.running = true;
- }
- batch(fn);
- if (!SuspenseContext && cb) cb();
- }];
- }
- function resumeEffects(e) {
- Transition && (Transition.running = true);
- Effects.push.apply(Effects, e);
- e.length = 0;
- }
- function devComponent(Comp, props) {
- const c = createComputation(() => untrack(() => Comp(props)), undefined, true);
- c.pending = NOTPENDING;
- c.observers = null;
- c.observerSlots = null;
- c.state = 0;
- c.componentName = Comp.name;
- updateComputation(c);
- return c.tValue !== undefined ? c.tValue : c.value;
- }
- function hashValue(v) {
- const s = new Set();
- return "s" + (typeof v === "string" ? hash(v) : hash(JSON.stringify(v, (k, v) => {
- if (typeof v === "object" && v != null) {
- if (s.has(v)) return;
- s.add(v);
- }
- return v;
- }) || ""));
- }
- function registerGraph(name, value) {
- let tryName = name;
- if (Owner) {
- let i = 0;
- Owner.sourceMap || (Owner.sourceMap = {});
- while (Owner.sourceMap[tryName]) tryName = name + "-" + ++i;
- Owner.sourceMap[tryName] = value;
- }
- return tryName;
- }
- function serializeGraph(owner) {
- owner || (owner = Owner);
- if (!owner) return {};
- return { ...serializeValues(owner.sourceMap),
- ...(owner.owned ? serializeChildren(owner) : {})
- };
- }
- function createContext(defaultValue) {
- const id = Symbol("context");
- return {
- id,
- Provider: createProvider(id),
- defaultValue
- };
- }
- function useContext(context) {
- return lookup(Owner, context.id) || context.defaultValue;
- }
- function children(fn) {
- const children = createMemo(fn);
- return createMemo(() => resolveChildren(children()));
- }
- let SuspenseContext;
- function getSuspenseContext() {
- return SuspenseContext || (SuspenseContext = createContext({}));
- }
- function readSignal() {
- if (this.state && this.sources) {
- const updates = Updates;
- Updates = null;
- this.state === STALE ? updateComputation(this) : lookDownstream(this);
- Updates = updates;
- }
- if (Listener) {
- const sSlot = this.observers ? this.observers.length : 0;
- if (!Listener.sources) {
- Listener.sources = [this];
- Listener.sourceSlots = [sSlot];
- } else {
- Listener.sources.push(this);
- Listener.sourceSlots.push(sSlot);
- }
- if (!this.observers) {
- this.observers = [Listener];
- this.observerSlots = [Listener.sources.length - 1];
- } else {
- this.observers.push(Listener);
- this.observerSlots.push(Listener.sources.length - 1);
- }
- }
- if (Transition && Transition.running && Transition.sources.has(this)) return this.tValue;
- return this.value;
- }
- function writeSignal(value, isComp) {
- if (this.comparator) {
- if (Transition && Transition.running && Transition.sources.has(this)) {
- if (this.comparator(this.tValue, value)) return value;
- } else if (this.comparator(this.value, value)) return value;
- }
- if (Pending) {
- if (this.pending === NOTPENDING) Pending.push(this);
- this.pending = value;
- return value;
- }
- if (Transition) {
- if (Transition.running || !isComp && Transition.sources.has(this)) {
- Transition.sources.add(this);
- this.tValue = value;
- }
- if (!Transition.running) this.value = value;
- } else this.value = value;
- if (this.observers && (!Updates || this.observers.length)) {
- runUpdates(() => {
- for (let i = 0; i < this.observers.length; i += 1) {
- const o = this.observers[i];
- if (Transition && Transition.running && Transition.disposed.has(o)) continue;
- if (o.observers && o.state !== PENDING) markUpstream(o);
- o.state = STALE;
- if (o.pure) Updates.push(o);else Effects.push(o);
- }
- if (Updates.length > 10e5) {
- Updates = [];
- if ("_SOLID_DEV_") throw new Error("Potential Infinite Loop Detected.");
- throw new Error();
- }
- }, false);
- }
- return value;
- }
- function updateComputation(node) {
- if (!node.fn) return;
- cleanNode(node);
- const owner = Owner,
- listener = Listener,
- time = ExecCount;
- Listener = Owner = node;
- runComputation(node, node.value, time);
- if (Transition && !Transition.running && Transition.sources.has(node)) {
- Transition.running = true;
- runComputation(node, node.tValue, time);
- Transition.running = false;
- }
- Listener = listener;
- Owner = owner;
- }
- function runComputation(node, value, time) {
- let nextValue;
- try {
- nextValue = node.fn(value);
- } catch (err) {
- handleError(err);
- }
- if (!node.updatedAt || node.updatedAt <= time) {
- if (node.observers && node.observers.length) {
- writeSignal.call(node, nextValue, true);
- } else if (Transition && Transition.running && node.pure) {
- Transition.sources.add(node);
- node.tValue = nextValue;
- } else node.value = nextValue;
- node.updatedAt = time;
- }
- }
- function createComputation(fn, init, pure, options) {
- const c = {
- fn,
- state: STALE,
- updatedAt: null,
- owned: null,
- sources: null,
- sourceSlots: null,
- cleanups: null,
- value: init,
- owner: Owner,
- context: null,
- pure
- };
- if (Owner === null) console.warn("computations created outside a `createRoot` or `render` will never be disposed");else if (Owner !== UNOWNED) {
- if (Transition && Transition.running && Owner.pure) {
- if (!Owner.tOwned) Owner.tOwned = [c];else Owner.tOwned.push(c);
- } else {
- if (!Owner.owned) Owner.owned = [c];else Owner.owned.push(c);
- }
- c.name = options && options.name || (Owner.name || "c") + "-" + (Owner.owned || Owner.tOwned).length;
- }
- return c;
- }
- function runTop(node) {
- let top = node.state === STALE && node,
- pending;
- if (node.suspense && untrack(node.suspense.inFallback)) return node.suspense.effects.push(node);
- const runningTransition = Transition && Transition.running;
- while ((node.fn || runningTransition && node.attached) && (node = node.owner)) {
- if (runningTransition && Transition.disposed.has(node)) return;
- if (node.state === PENDING) pending = node;else if (node.state === STALE) {
- top = node;
- pending = undefined;
- }
- }
- if (pending) {
- const updates = Updates;
- Updates = null;
- lookDownstream(pending);
- Updates = updates;
- if (!top || top.state !== STALE) return;
- if (runningTransition) {
- node = top;
- while ((node.fn || node.attached) && (node = node.owner)) {
- if (Transition.disposed.has(node)) return;
- }
- }
- }
- top && updateComputation(top);
- }
- function runUpdates(fn, init) {
- if (Updates) return fn();
- let wait = false;
- if (!init) Updates = [];
- if (Effects) wait = true;else Effects = [];
- ExecCount++;
- try {
- fn();
- } catch (err) {
- handleError(err);
- } finally {
- completeUpdates(wait);
- }
- }
- function completeUpdates(wait) {
- if (Updates) {
- runQueue(Updates);
- Updates = null;
- }
- if (wait) return;
- let cbs;
- if (Transition && Transition.running) {
- if (Transition.promises.size) {
- Transition.running = false;
- Transition.effects.push.apply(Transition.effects, Effects);
- Effects = null;
- setTransPending(true);
- return;
- }
- const sources = Transition.sources;
- cbs = Transition.cb;
- Transition = null;
- batch(() => {
- sources.forEach(v => {
- v.value = v.tValue;
- if (v.owned) {
- for (let i = 0, len = v.owned.length; i < len; i++) cleanNode(v.owned[i]);
- }
- if (v.tOwned) v.owned = v.tOwned;
- delete v.tValue;
- delete v.tOwned;
- });
- setTransPending(false);
- });
- }
- if (Effects.length) batch(() => {
- runEffects(Effects);
- Effects = null;
- });else {
- Effects = null;
- globalThis._$afterUpdate && globalThis._$afterUpdate();
- }
- if (cbs) cbs.forEach(cb => cb());
- }
- function runQueue(queue) {
- for (let i = 0; i < queue.length; i++) runTop(queue[i]);
- }
- function runUserEffects(queue) {
- let i,
- userLength = 0;
- for (i = 0; i < queue.length; i++) {
- const e = queue[i];
- if (!e.user) runTop(e);else queue[userLength++] = e;
- }
- const resume = queue.length;
- for (i = 0; i < userLength; i++) runTop(queue[i]);
- for (i = resume; i < queue.length; i++) runTop(queue[i]);
- }
- function lookDownstream(node) {
- node.state = 0;
- for (let i = 0; i < node.sources.length; i += 1) {
- const source = node.sources[i];
- if (source.sources) {
- if (source.state === STALE) runTop(source);else if (source.state === PENDING) lookDownstream(source);
- }
- }
- }
- function markUpstream(node) {
- for (let i = 0; i < node.observers.length; i += 1) {
- const o = node.observers[i];
- if (!o.state) {
- o.state = PENDING;
- o.observers && markUpstream(o);
- }
- }
- }
- function cleanNode(node) {
- let i;
- if (node.sources) {
- while (node.sources.length) {
- const source = node.sources.pop(),
- index = node.sourceSlots.pop(),
- obs = source.observers;
- if (obs && obs.length) {
- const n = obs.pop(),
- s = source.observerSlots.pop();
- if (index < obs.length) {
- n.sourceSlots[s] = index;
- obs[index] = n;
- source.observerSlots[index] = s;
- }
- }
- }
- }
- if (Transition && Transition.running && node.pure) {
- if (node.tOwned) {
- for (i = 0; i < node.tOwned.length; i++) cleanNode(node.tOwned[i]);
- delete node.tOwned;
- }
- reset(node, true);
- } else if (node.owned) {
- for (i = 0; i < node.owned.length; i++) cleanNode(node.owned[i]);
- node.owned = null;
- }
- if (node.cleanups) {
- for (i = 0; i < node.cleanups.length; i++) node.cleanups[i]();
- node.cleanups = null;
- }
- node.state = 0;
- node.context = null;
- }
- function reset(node, top) {
- if (!top) {
- node.state = 0;
- Transition.disposed.add(node);
- }
- if (node.owned) {
- for (let i = 0; i < node.owned.length; i++) reset(node.owned[i]);
- }
- }
- function handleError(err) {
- const fns = ERROR && lookup(Owner, ERROR);
- if (!fns) throw err;
- fns.forEach(f => f(err));
- }
- function lookup(owner, key) {
- return owner && (owner.context && owner.context[key] || owner.owner && lookup(owner.owner, key));
- }
- function resolveChildren(children) {
- if (typeof children === "function" && !children.length) return resolveChildren(children());
- if (Array.isArray(children)) {
- const results = [];
- for (let i = 0; i < children.length; i++) {
- let result = resolveChildren(children[i]);
- Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
- }
- return results;
- }
- return children;
- }
- function createProvider(id) {
- return function provider(props) {
- return createMemo(() => {
- Owner.context = {
- [id]: props.value
- };
- return children(() => props.children);
- });
- };
- }
- function hash(s) {
- for (var i = 0, h = 9; i < s.length;) h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
- return `${h ^ h >>> 9}`;
- }
- function serializeValues(sources = {}) {
- const k = Object.keys(sources);
- const result = {};
- for (let i = 0; i < k.length; i++) {
- const key = k[i];
- result[key] = sources[key].value;
- }
- return result;
- }
- function serializeChildren(root) {
- const result = {};
- for (let i = 0, len = root.owned.length; i < len; i++) {
- const node = root.owned[i];
- result[node.componentName ? `${node.componentName}:${node.name}` : node.name] = { ...serializeValues(node.sourceMap),
- ...(node.owned ? serializeChildren(node) : {})
- };
- }
- return result;
- }
- const $RAW = Symbol("state-raw"),
- $NODE = Symbol("state-node"),
- $PROXY = Symbol("state-proxy"),
- $NAME = Symbol("state-name");
- function wrap$1(value, name) {
- let p = value[$PROXY];
- if (!p) {
- Object.defineProperty(value, $PROXY, {
- value: p = new Proxy(value, proxyTraps$1)
- });
- let keys = Object.keys(value),
- desc = Object.getOwnPropertyDescriptors(value);
- for (let i = 0, l = keys.length; i < l; i++) {
- const prop = keys[i];
- if (desc[prop].get) {
- const get = desc[prop].get.bind(p);
- Object.defineProperty(value, prop, {
- get
- });
- }
- }
- if (name) Object.defineProperty(value, $NAME, {
- value: name
- });
- }
- return p;
- }
- function isWrappable(obj) {
- return obj != null && typeof obj === "object" && (!obj.__proto__ || obj.__proto__ === Object.prototype || Array.isArray(obj));
- }
- function unwrap(item, set = new Set()) {
- let result, unwrapped, v, prop;
- if (result = item != null && item[$RAW]) return result;
- if (!isWrappable(item) || set.has(item)) return item;
- if (Array.isArray(item)) {
- if (Object.isFrozen(item)) item = item.slice(0);else set.add(item);
- for (let i = 0, l = item.length; i < l; i++) {
- v = item[i];
- if ((unwrapped = unwrap(v, set)) !== v) item[i] = unwrapped;
- }
- } else {
- if (Object.isFrozen(item)) item = Object.assign({}, item);else set.add(item);
- let keys = Object.keys(item),
- desc = Object.getOwnPropertyDescriptors(item);
- for (let i = 0, l = keys.length; i < l; i++) {
- prop = keys[i];
- if (desc[prop].get) continue;
- v = item[prop];
- if ((unwrapped = unwrap(v, set)) !== v) item[prop] = unwrapped;
- }
- }
- return item;
- }
- function getDataNodes(target) {
- let nodes = target[$NODE];
- if (!nodes) Object.defineProperty(target, $NODE, {
- value: nodes = {}
- });
- return nodes;
- }
- function proxyDescriptor(target, property) {
- const desc = Reflect.getOwnPropertyDescriptor(target, property);
- if (!desc || desc.get || property === $PROXY || property === $NODE || property === $NAME) return desc;
- delete desc.value;
- delete desc.writable;
- desc.get = () => target[$PROXY][property];
- return desc;
- }
- function createDataNode() {
- const [s, set] = createSignal(undefined, {
- equals: false,
- internal: true
- }) ;
- s.set = set;
- return s;
- }
- const proxyTraps$1 = {
- get(target, property, receiver) {
- if (property === $RAW) return target;
- if (property === $PROXY) return receiver;
- const value = target[property];
- if (property === $NODE || property === "__proto__") return value;
- const wrappable = isWrappable(value);
- if (Listener && (typeof value !== "function" || target.hasOwnProperty(property))) {
- let nodes, node;
- if (wrappable && (nodes = getDataNodes(value))) {
- node = nodes._ || (nodes._ = createDataNode());
- node();
- }
- nodes = getDataNodes(target);
- node = nodes[property] || (nodes[property] = createDataNode());
- node();
- }
- return wrappable ? wrap$1(value, target[$NAME] && `${target[$NAME]}:${property}`) : value;
- },
- set() {
- return true;
- },
- deleteProperty() {
- return true;
- },
- getOwnPropertyDescriptor: proxyDescriptor
- };
- function setProperty(state, property, value) {
- if (state[property] === value) return;
- const array = Array.isArray(state);
- const len = state.length;
- const notify = array || !(property in state);
- if (value === undefined) {
- delete state[property];
- } else state[property] = value;
- let nodes = getDataNodes(state),
- node;
- (node = nodes[property]) && node.set();
- if (array && state.length !== len) (node = nodes.length) && node.set();
- notify && (node = nodes._) && node.set();
- }
- function mergeState(state, value) {
- const keys = Object.keys(value);
- for (let i = 0; i < keys.length; i += 1) {
- const key = keys[i];
- setProperty(state, key, value[key]);
- }
- }
- function updatePath(current, path, traversed = []) {
- let part,
- prev = current;
- if (path.length > 1) {
- part = path.shift();
- const partType = typeof part,
- isArray = Array.isArray(current);
- if (Array.isArray(part)) {
- for (let i = 0; i < part.length; i++) {
- updatePath(current, [part[i]].concat(path), [part[i]].concat(traversed));
- }
- return;
- } else if (isArray && partType === "function") {
- for (let i = 0; i < current.length; i++) {
- if (part(current[i], i)) updatePath(current, [i].concat(path), [i].concat(traversed));
- }
- return;
- } else if (isArray && partType === "object") {
- const {
- from = 0,
- to = current.length - 1,
- by = 1
- } = part;
- for (let i = from; i <= to; i += by) {
- updatePath(current, [i].concat(path), [i].concat(traversed));
- }
- return;
- } else if (path.length > 1) {
- updatePath(current[part], path, [part].concat(traversed));
- return;
- }
- prev = current[part];
- traversed = [part].concat(traversed);
- }
- let value = path[0];
- if (typeof value === "function") {
- value = value(prev, traversed);
- if (value === prev) return;
- }
- if (part === undefined && value == undefined) return;
- value = unwrap(value);
- if (part === undefined || isWrappable(prev) && isWrappable(value) && !Array.isArray(value)) {
- mergeState(prev, value);
- } else setProperty(current, part, value);
- }
- function createState(state, options) {
- const unwrappedState = unwrap(state || {});
- const wrappedState = wrap$1(unwrappedState, (options && options.name || hashValue(unwrappedState)));
- {
- const name = options && options.name || hashValue(unwrappedState);
- registerGraph(name, {
- value: unwrappedState
- });
- }
- function setState(...args) {
- batch(() => updatePath(unwrappedState, args));
- }
- return [wrappedState, setState];
- }
- const proxyTraps = {
- get(target, property, receiver) {
- if (property === $RAW) return target;
- if (property === $PROXY) return receiver;
- const value = target[property];
- if (property === $NODE || property === "__proto__") return value;
- const wrappable = isWrappable(value);
- if (Listener && (typeof value !== "function" || target.hasOwnProperty(property))) {
- let nodes, node;
- if (wrappable && (nodes = getDataNodes(value))) {
- node = nodes._ || (nodes._ = createDataNode());
- node();
- }
- nodes = getDataNodes(target);
- node = nodes[property] || (nodes[property] = createDataNode());
- node();
- }
- return wrappable ? wrap(value, target[$NAME] && `${target[$NAME]}:${property}`) : value;
- },
- set(target, property, value) {
- setProperty(target, property, unwrap(value));
- return true;
- },
- deleteProperty(target, property) {
- setProperty(target, property, undefined);
- return true;
- },
- getOwnPropertyDescriptor: proxyDescriptor
- };
- function wrap(value, name) {
- let p = value[$PROXY];
- if (!p) {
- Object.defineProperty(value, $PROXY, {
- value: p = new Proxy(value, proxyTraps)
- });
- let keys = Object.keys(value),
- desc = Object.getOwnPropertyDescriptors(value);
- for (let i = 0, l = keys.length; i < l; i++) {
- const prop = keys[i];
- if (desc[prop].get) {
- const get = desc[prop].get.bind(p);
- Object.defineProperty(value, prop, {
- get
- });
- }
- if (desc[prop].set) {
- const og = desc[prop].set,
- set = v => batch(() => og.call(p, v));
- Object.defineProperty(value, prop, {
- set
- });
- }
- }
- if (name) Object.defineProperty(value, $NAME, {
- value: name
- });
- }
- return p;
- }
- function createMutable(state, options) {
- const unwrappedState = unwrap(state || {});
- const wrappedState = wrap(unwrappedState, (options && options.name || hashValue(unwrappedState)));
- {
- const name = options && options.name || hashValue(unwrappedState);
- registerGraph(name, {
- value: unwrappedState
- });
- }
- return wrappedState;
- }
- function getSymbol() {
- const SymbolCopy = Symbol;
- return SymbolCopy.observable || '@@observable';
- }
- function observable(input) {
- const $$observable = getSymbol();
- return {
- subscribe(observer) {
- if (!(observer instanceof Object) || observer == null) {
- throw new TypeError("Expected the observer to be an object.");
- }
- const handler = "next" in observer ? observer.next : observer;
- let complete = false;
- createComputed(() => {
- if (complete) return;
- const v = input();
- untrack(() => handler(v));
- });
- return {
- unsubscribe() {
- complete = true;
- }
- };
- },
- [$$observable]() {
- return this;
- }
- };
- }
- function applyState(target, parent, property, merge, key) {
- let previous = parent[property];
- if (target === previous) return;
- if (!isWrappable(target) || !isWrappable(previous) || key && target[key] !== previous[key]) {
- target !== previous && setProperty(parent, property, target);
- return;
- }
- if (Array.isArray(target)) {
- if (target.length && previous.length && (!merge || key && target[0][key] != null)) {
- let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
- for (start = 0, end = Math.min(previous.length, target.length); start < end && (previous[start] === target[start] || key && previous[start][key] === target[start][key]); start++) {
- applyState(target[start], previous, start, merge, key);
- }
- const temp = new Array(target.length),
- newIndices = new Map();
- 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--) {
- temp[newEnd] = previous[end];
- }
- if (start > newEnd || start > end) {
- for (j = start; j <= newEnd; j++) setProperty(previous, j, target[j]);
- for (; j < target.length; j++) {
- setProperty(previous, j, temp[j]);
- applyState(target[j], previous, j, merge, key);
- }
- if (previous.length > target.length) setProperty(previous, "length", target.length);
- return;
- }
- newIndicesNext = new Array(newEnd + 1);
- for (j = newEnd; j >= start; j--) {
- item = target[j];
- keyVal = key ? item[key] : item;
- i = newIndices.get(keyVal);
- newIndicesNext[j] = i === undefined ? -1 : i;
- newIndices.set(keyVal, j);
- }
- for (i = start; i <= end; i++) {
- item = previous[i];
- keyVal = key ? item[key] : item;
- j = newIndices.get(keyVal);
- if (j !== undefined && j !== -1) {
- temp[j] = previous[i];
- j = newIndicesNext[j];
- newIndices.set(keyVal, j);
- }
- }
- for (j = start; j < target.length; j++) {
- if (j in temp) {
- setProperty(previous, j, temp[j]);
- applyState(target[j], previous, j, merge, key);
- } else setProperty(previous, j, target[j]);
- }
- } else {
- for (let i = 0, len = target.length; i < len; i++) {
- applyState(target[i], previous, i, merge, key);
- }
- }
- if (previous.length > target.length) setProperty(previous, "length", target.length);
- return;
- }
- const targetKeys = Object.keys(target);
- for (let i = 0, len = targetKeys.length; i < len; i++) {
- applyState(target[targetKeys[i]], previous, targetKeys[i], merge, key);
- }
- const previousKeys = Object.keys(previous);
- for (let i = 0, len = previousKeys.length; i < len; i++) {
- if (target[previousKeys[i]] === undefined) setProperty(previous, previousKeys[i], undefined);
- }
- }
- function reconcile(value, options = {}) {
- const {
- merge,
- key = "id"
- } = options,
- v = unwrap(value);
- return state => {
- if (!isWrappable(state) || !isWrappable(v)) return v;
- applyState(v, {
- state
- }, "state", merge, key);
- return state;
- };
- }
- const setterTraps = {
- get(target, property) {
- if (property === $RAW) return target;
- const value = target[property];
- return isWrappable(value) ? new Proxy(value, setterTraps) : value;
- },
- set(target, property, value) {
- setProperty(target, property, unwrap(value));
- return true;
- },
- deleteProperty(target, property) {
- setProperty(target, property, undefined);
- return true;
- }
- };
- function produce(fn) {
- return state => {
- if (isWrappable(state)) fn(new Proxy(state, setterTraps));
- return state;
- };
- }
- const FALLBACK = Symbol("fallback");
- function mapArray(list, mapFn, options = {}) {
- let items = [],
- mapped = [],
- disposers = [],
- len = 0,
- indexes = mapFn.length > 1 ? [] : null,
- ctx = Owner;
- onCleanup(() => {
- for (let i = 0, length = disposers.length; i < length; i++) disposers[i]();
- });
- return () => {
- let newItems = list() || [],
- i,
- j;
- return untrack(() => {
- let newLen = newItems.length,
- newIndices,
- newIndicesNext,
- temp,
- tempdisposers,
- tempIndexes,
- start,
- end,
- newEnd,
- item;
- if (newLen === 0) {
- if (len !== 0) {
- for (i = 0; i < len; i++) disposers[i]();
- disposers = [];
- items = [];
- mapped = [];
- len = 0;
- indexes && (indexes = []);
- }
- if (options.fallback) {
- items = [FALLBACK];
- mapped[0] = createRoot(disposer => {
- disposers[0] = disposer;
- return options.fallback();
- }, ctx);
- len = 1;
- }
- }
- else if (len === 0) {
- for (j = 0; j < newLen; j++) {
- items[j] = newItems[j];
- mapped[j] = createRoot(mapper, ctx);
- }
- len = newLen;
- } else {
- temp = new Array(newLen);
- tempdisposers = new Array(newLen);
- indexes && (tempIndexes = new Array(newLen));
- for (start = 0, end = Math.min(len, newLen); start < end && items[start] === newItems[start]; start++);
- for (end = len - 1, newEnd = newLen - 1; end >= start && newEnd >= start && items[end] === newItems[newEnd]; end--, newEnd--) {
- temp[newEnd] = mapped[end];
- tempdisposers[newEnd] = disposers[end];
- indexes && (tempIndexes[newEnd] = indexes[end]);
- }
- newIndices = new Map();
- newIndicesNext = new Array(newEnd + 1);
- for (j = newEnd; j >= start; j--) {
- item = newItems[j];
- i = newIndices.get(item);
- newIndicesNext[j] = i === undefined ? -1 : i;
- newIndices.set(item, j);
- }
- for (i = start; i <= end; i++) {
- item = items[i];
- j = newIndices.get(item);
- if (j !== undefined && j !== -1) {
- temp[j] = mapped[i];
- tempdisposers[j] = disposers[i];
- indexes && (tempIndexes[j] = indexes[i]);
- j = newIndicesNext[j];
- newIndices.set(item, j);
- } else disposers[i]();
- }
- for (j = start; j < newLen; j++) {
- if (j in temp) {
- mapped[j] = temp[j];
- disposers[j] = tempdisposers[j];
- if (indexes) {
- indexes[j] = tempIndexes[j];
- indexes[j](j);
- }
- } else mapped[j] = createRoot(mapper, ctx);
- }
- len = mapped.length = newLen;
- items = newItems.slice(0);
- }
- return mapped;
- });
- function mapper(disposer) {
- disposers[j] = disposer;
- if (indexes) {
- const [s, set] = createSignal(j);
- indexes[j] = set;
- return mapFn(newItems[j], s);
- }
- return mapFn(newItems[j]);
- }
- };
- }
- function indexArray(list, mapFn, options = {}) {
- let items = [],
- mapped = [],
- disposers = [],
- signals = [],
- len = 0,
- i,
- ctx = Owner;
- onCleanup(() => {
- for (let i = 0, length = disposers.length; i < length; i++) disposers[i]();
- });
- return () => {
- const newItems = list() || [];
- return untrack(() => {
- if (newItems.length === 0) {
- if (len !== 0) {
- for (i = 0; i < len; i++) disposers[i]();
- disposers = [];
- items = [];
- mapped = [];
- len = 0;
- signals = [];
- }
- if (options.fallback) {
- items = [FALLBACK];
- mapped[0] = createRoot(disposer => {
- disposers[0] = disposer;
- return options.fallback();
- }, ctx);
- len = 1;
- }
- return mapped;
- }
- if (items[0] === FALLBACK) {
- disposers[0]();
- disposers = [];
- items = [];
- mapped = [];
- len = 0;
- }
- for (i = 0; i < newItems.length; i++) {
- if (i < items.length && items[i] !== newItems[i]) {
- signals[i](newItems[i]);
- } else if (i >= items.length) {
- mapped[i] = createRoot(mapper, ctx);
- }
- }
- for (; i < items.length; i++) {
- disposers[i]();
- }
- len = mapped.length = signals.length = disposers.length = newItems.length;
- items = newItems.slice(0);
- return mapped;
- });
- function mapper(disposer) {
- disposers[i] = disposer;
- const [s, set] = createSignal(newItems[i]);
- signals[i] = set;
- return mapFn(s, i);
- }
- };
- }
- function createComponent(Comp, props) {
- if (sharedConfig.context) {
- const c = sharedConfig.context;
- setHydrateContext(nextHydrateContext());
- const r = devComponent(Comp, props) ;
- setHydrateContext(c);
- return r;
- }
- return devComponent(Comp, props);
- }
- function trueFn() {
- return true;
- }
- const propTraps = {
- get(_, property, receiver) {
- if (property === $PROXY) return receiver;
- return _.get(property);
- },
- has(_, property) {
- return _.has(property);
- },
- set: trueFn,
- deleteProperty: trueFn,
- getOwnPropertyDescriptor(_, property) {
- return {
- configurable: true,
- enumerable: true,
- get() {
- return _.get(property);
- },
- set: trueFn,
- deleteProperty: trueFn
- };
- },
- ownKeys(_) {
- return _.keys();
- }
- };
- function mergeProps(...sources) {
- return new Proxy({
- get(property) {
- for (let i = sources.length - 1; i >= 0; i--) {
- const v = sources[i][property];
- if (v !== undefined) return v;
- }
- },
- has(property) {
- for (let i = sources.length - 1; i >= 0; i--) {
- if (property in sources[i]) return true;
- }
- return false;
- },
- keys() {
- const keys = [];
- for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(sources[i]));
- return [...new Set(keys)];
- }
- }, propTraps);
- }
- function splitProps(props, ...keys) {
- const blocked = new Set(keys.flat());
- const descriptors = Object.getOwnPropertyDescriptors(props);
- const res = keys.map(k => {
- const clone = {};
- for (let i = 0; i < k.length; i++) {
- const key = k[i];
- Object.defineProperty(clone, key, descriptors[key] ? descriptors[key] : {
- get() {
- return props[key];
- }
- });
- }
- return clone;
- });
- res.push(new Proxy({
- get(property) {
- return blocked.has(property) ? undefined : props[property];
- },
- has(property) {
- return blocked.has(property) ? false : property in props;
- },
- keys() {
- return Object.keys(props).filter(k => !blocked.has(k));
- }
- }, propTraps));
- return res;
- }
- function lazy(fn) {
- let p;
- const wrap = props => {
- const ctx = sharedConfig.context;
- let comp;
- if (ctx && sharedConfig.resources) {
- ctx.count++;
- const [s, set] = createSignal();
- (p || (p = fn())).then(mod => {
- setHydrateContext(ctx);
- set(mod.default);
- setHydrateContext(undefined);
- });
- comp = s;
- } else {
- const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
- comp = s;
- }
- let Comp;
- return createMemo(() => (Comp = comp()) && untrack(() => {
- if (!ctx) return Comp(props);
- const c = sharedConfig.context;
- setHydrateContext(ctx);
- const r = Comp(props);
- setHydrateContext(c);
- return r;
- }));
- };
- wrap.preload = () => (p || (p = fn())).then(mod => mod.default);
- return wrap;
- }
- function For(props) {
- const fallback = "fallback" in props && {
- fallback: () => props.fallback
- };
- return createMemo(mapArray(() => props.each, props.children, fallback ? fallback : undefined), undefined, {
- equals: false
- });
- }
- function Index(props) {
- const fallback = "fallback" in props && {
- fallback: () => props.fallback
- };
- return createMemo(indexArray(() => props.each, props.children, fallback ? fallback : undefined), undefined, {
- equals: false
- });
- }
- function Show(props) {
- let strictEqual = false;
- const condition = createMemo(() => props.when, undefined, {
- equals: (a, b) => strictEqual ? a === b : !a === !b
- });
- return createMemo(() => {
- const c = condition();
- if (c) {
- const child = props.children;
- return (strictEqual = typeof child === "function" && child.length > 0) ? untrack(() => child(c)) : child;
- }
- return props.fallback;
- });
- }
- function Switch(props) {
- let strictEqual = false;
- const conditions = children(() => props.children),
- evalConditions = createMemo(() => {
- let conds = conditions();
- if (!Array.isArray(conds)) conds = [conds];
- for (let i = 0; i < conds.length; i++) {
- const c = conds[i].when;
- if (c) return [i, c, conds[i]];
- }
- return [-1];
- }, undefined, {
- equals: (a, b) => a && a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
- });
- return createMemo(() => {
- const [index, when, cond] = evalConditions();
- if (index < 0) return props.fallback;
- const c = cond.children;
- return (strictEqual = typeof c === "function" && c.length > 0) ? untrack(() => c(when)) : c;
- });
- }
- function Match(props) {
- return props;
- }
- function ErrorBoundary(props) {
- const [errored, setErrored] = createSignal();
- onError(setErrored);
- let e;
- return createMemo(() => {
- if ((e = errored()) != null) {
- const f = props.fallback;
- return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored(null))) : f;
- }
- return props.children;
- });
- }
- const SuspenseListContext = createContext();
- function SuspenseList(props) {
- let index = 0,
- suspenseSetter,
- showContent,
- showFallback;
- const listContext = useContext(SuspenseListContext);
- if (listContext) {
- const [inFallback, setFallback] = createSignal(false);
- suspenseSetter = setFallback;
- [showContent, showFallback] = listContext.register(inFallback);
- }
- const registry = [],
- comp = createComponent(SuspenseListContext.Provider, {
- value: {
- register: inFallback => {
- const [showingContent, showContent] = createSignal(false),
- [showingFallback, showFallback] = createSignal(false);
- registry[index++] = {
- inFallback,
- showContent,
- showFallback
- };
- return [showingContent, showingFallback];
- }
- },
- get children() {
- return props.children;
- }
- });
- createComputed(() => {
- const reveal = props.revealOrder,
- tail = props.tail,
- visibleContent = showContent ? showContent() : true,
- visibleFallback = showFallback ? showFallback() : true,
- reverse = reveal === "backwards";
- if (reveal === "together") {
- const all = registry.every(i => !i.inFallback());
- suspenseSetter && suspenseSetter(!all);
- registry.forEach(i => {
- i.showContent(all && visibleContent);
- i.showFallback(visibleFallback);
- });
- return;
- }
- let stop = false;
- for (let i = 0, len = registry.length; i < len; i++) {
- const n = reverse ? len - i - 1 : i,
- s = registry[n].inFallback();
- if (!stop && !s) {
- registry[n].showContent(visibleContent);
- registry[n].showFallback(visibleFallback);
- } else {
- const next = !stop;
- if (next && suspenseSetter) suspenseSetter(true);
- if (!tail || next && tail === "collapsed") {
- registry[n].showFallback(visibleFallback);
- } else registry[n].showFallback(false);
- stop = true;
- registry[n].showContent(next);
- }
- }
- if (!stop && suspenseSetter) suspenseSetter(false);
- });
- return comp;
- }
- function Suspense(props) {
- let counter = 0,
- showContent,
- showFallback;
- const [inFallback, setFallback] = createSignal(false),
- SuspenseContext = getSuspenseContext(),
- store = {
- increment: () => {
- if (++counter === 1) setFallback(true);
- },
- decrement: () => {
- if (--counter === 0) setFallback(false);
- },
- inFallback,
- effects: [],
- resolved: false
- };
- const listContext = useContext(SuspenseListContext);
- if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
- return createComponent(SuspenseContext.Provider, {
- value: store,
- get children() {
- const rendered = untrack(() => props.children);
- return createMemo(() => {
- const inFallback = store.inFallback(),
- visibleContent = showContent ? showContent() : true,
- visibleFallback = showFallback ? showFallback() : true;
- if (!inFallback && visibleContent) {
- store.resolved = true;
- resumeEffects(store.effects);
- return rendered;
- }
- if (!visibleFallback) return;
- return props.fallback;
- });
- }
- });
- }
- function awaitSuspense() {}
- exports.DEV = void 0;
- {
- exports.DEV = {
- writeSignal,
- serializeGraph
- };
- }
- if (globalThis) {
- if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
- }
- exports.$RAW = $RAW;
- exports.ErrorBoundary = ErrorBoundary;
- exports.For = For;
- exports.Index = Index;
- exports.Match = Match;
- exports.Show = Show;
- exports.Suspense = Suspense;
- exports.SuspenseList = SuspenseList;
- exports.Switch = Switch;
- exports.awaitSuspense = awaitSuspense;
- exports.batch = batch;
- exports.cancelCallback = cancelCallback;
- exports.children = children;
- exports.createComponent = createComponent;
- exports.createComputed = createComputed;
- exports.createContext = createContext;
- exports.createDeferred = createDeferred;
- exports.createEffect = createEffect;
- exports.createMemo = createMemo;
- exports.createMutable = createMutable;
- exports.createRenderEffect = createRenderEffect;
- exports.createResource = createResource;
- exports.createRoot = createRoot;
- exports.createSelector = createSelector;
- exports.createSignal = createSignal;
- exports.createState = createState;
- exports.equalFn = equalFn;
- exports.getListener = getListener;
- exports.getOwner = getOwner;
- exports.indexArray = indexArray;
- exports.lazy = lazy;
- exports.mapArray = mapArray;
- exports.mergeProps = mergeProps;
- exports.observable = observable;
- exports.on = on;
- exports.onCleanup = onCleanup;
- exports.onError = onError;
- exports.onMount = onMount;
- exports.produce = produce;
- exports.reconcile = reconcile;
- exports.requestCallback = requestCallback;
- exports.runWithOwner = runWithOwner;
- exports.sharedConfig = sharedConfig;
- exports.splitProps = splitProps;
- exports.untrack = untrack;
- exports.unwrap = unwrap;
- exports.useContext = useContext;
- exports.useTransition = useTransition;
|