@code-id-labs/composables 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +967 -0
- package/dist/index.d.cts +328 -0
- package/dist/index.d.ts +328 -0
- package/dist/index.js +964 -0
- package/package.json +36 -3
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,964 @@
|
|
|
1
|
+
//#region ../utils/dist/guard.js
|
|
2
|
+
const isPlainObject = (v) => {
|
|
3
|
+
if (typeof v !== "object" || v === null) return false;
|
|
4
|
+
const proto = Object.getPrototypeOf(v);
|
|
5
|
+
return proto === null || proto === Object.prototype;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region ../utils/dist/equal.js
|
|
9
|
+
const isArrayLike = (value) => Boolean(value) && typeof value === "object" && "length" in value;
|
|
10
|
+
const isArrayEqual = (a, b) => {
|
|
11
|
+
if (a.length !== b.length) return false;
|
|
12
|
+
for (let i = 0; i < a.length; i++) {
|
|
13
|
+
const aItem = a[i];
|
|
14
|
+
const bItem = b[i];
|
|
15
|
+
if (!isEqual(aItem, bItem)) return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
const isEqual = (a, b) => {
|
|
20
|
+
if (Object.is(a, b)) return true;
|
|
21
|
+
const aNil = a === null || a === void 0;
|
|
22
|
+
const bNil = b === null || b === void 0;
|
|
23
|
+
if (aNil !== bNil) return false;
|
|
24
|
+
if (aNil && bNil) return true;
|
|
25
|
+
const aObj = a;
|
|
26
|
+
const bObj = b;
|
|
27
|
+
if (typeof aObj?.isEqual === "function" && typeof bObj?.isEqual === "function") return aObj.isEqual(b);
|
|
28
|
+
if (typeof a === "function" && typeof b === "function") return a.toString() === b.toString();
|
|
29
|
+
if (Array.isArray(a) && Array.isArray(b)) return isArrayEqual(a, b);
|
|
30
|
+
if (isArrayLike(a) && isArrayLike(b)) return isArrayEqual(a, b);
|
|
31
|
+
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
32
|
+
const aKeys = Object.keys(aObj);
|
|
33
|
+
const bKeys = Object.keys(bObj);
|
|
34
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
35
|
+
for (let i = 0; i < bKeys.length; i++) {
|
|
36
|
+
const key = bKeys[i];
|
|
37
|
+
if (key === void 0 || !Reflect.has(aObj, key)) return false;
|
|
38
|
+
if (!isEqual(aObj[key], bObj[key])) return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region ../utils/dist/diff.js
|
|
44
|
+
function hasDeletedOrUndefinedKeys(prev, next) {
|
|
45
|
+
for (const k in prev) if (prev[k] !== void 0 && (!(k in next) || next[k] === void 0)) return true;
|
|
46
|
+
for (const k in next) if (next[k] === void 0) return true;
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
function stripUndefined(val) {
|
|
50
|
+
if (Array.isArray(val)) return val.map((v) => v === void 0 ? null : stripUndefined(v));
|
|
51
|
+
if (isPlainObject(val)) {
|
|
52
|
+
const out = {};
|
|
53
|
+
for (const k in val) {
|
|
54
|
+
const v = val[k];
|
|
55
|
+
if (v !== void 0) out[k] = stripUndefined(v);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
return val;
|
|
60
|
+
}
|
|
61
|
+
function diffSnapshot(prev, next, prefix) {
|
|
62
|
+
if (!prev) {
|
|
63
|
+
const cleaned = stripUndefined(next);
|
|
64
|
+
return prefix ? { [prefix]: cleaned } : cleaned;
|
|
65
|
+
}
|
|
66
|
+
const delta = {};
|
|
67
|
+
let hasDiff = false;
|
|
68
|
+
for (const k of Object.keys(next)) {
|
|
69
|
+
const path = prefix ? `${prefix}.${k}` : k;
|
|
70
|
+
const pVal = prev[k];
|
|
71
|
+
const nVal = next[k];
|
|
72
|
+
if (nVal === void 0) {
|
|
73
|
+
if (pVal !== void 0) {
|
|
74
|
+
delta[path] = null;
|
|
75
|
+
hasDiff = true;
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (pVal === nVal || Object.is(pVal, nVal)) continue;
|
|
80
|
+
if (Array.isArray(pVal) && Array.isArray(nVal)) {
|
|
81
|
+
if (pVal.length !== nVal.length) {
|
|
82
|
+
delta[path] = stripUndefined(nVal);
|
|
83
|
+
hasDiff = true;
|
|
84
|
+
} else for (let i = 0; i < nVal.length; i++) {
|
|
85
|
+
const pi = pVal[i];
|
|
86
|
+
const ni = nVal[i];
|
|
87
|
+
if (pi === ni || Object.is(pi, ni)) continue;
|
|
88
|
+
const subPath = `${path}[${i}]`;
|
|
89
|
+
if (isPlainObject(pi) && isPlainObject(ni)) {
|
|
90
|
+
if (hasDeletedOrUndefinedKeys(pi, ni)) {
|
|
91
|
+
if (!isEqual(pi, ni)) {
|
|
92
|
+
delta[subPath] = stripUndefined(ni);
|
|
93
|
+
hasDiff = true;
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
const sub = diffSnapshot(pi, ni, subPath);
|
|
97
|
+
if (sub) {
|
|
98
|
+
Object.assign(delta, sub);
|
|
99
|
+
hasDiff = true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} else if (!isEqual(pi, ni)) {
|
|
103
|
+
delta[subPath] = ni === void 0 ? null : stripUndefined(ni);
|
|
104
|
+
hasDiff = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} else if (isPlainObject(pVal) && isPlainObject(nVal)) {
|
|
108
|
+
if (hasDeletedOrUndefinedKeys(pVal, nVal)) {
|
|
109
|
+
if (!isEqual(pVal, nVal)) {
|
|
110
|
+
delta[path] = stripUndefined(nVal);
|
|
111
|
+
hasDiff = true;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
const sub = diffSnapshot(pVal, nVal, path);
|
|
115
|
+
if (sub) {
|
|
116
|
+
Object.assign(delta, sub);
|
|
117
|
+
hasDiff = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} else if (!isEqual(pVal, nVal)) {
|
|
121
|
+
delta[path] = stripUndefined(nVal);
|
|
122
|
+
hasDiff = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return hasDiff ? delta : null;
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region ../utils/dist/warning.js
|
|
129
|
+
function warn(...a) {
|
|
130
|
+
const m = a.length === 1 ? a[0] : a[1];
|
|
131
|
+
if ((a.length === 2 ? a[0] : true) && process.env.NODE_ENV !== "production") console.warn(m);
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/use-component-ref.ts
|
|
135
|
+
const LISTENER_SET_KEY = "__codeUiSnapshotListeners";
|
|
136
|
+
function resolveChild(instance, target) {
|
|
137
|
+
if (typeof target === "string") {
|
|
138
|
+
if (instance && typeof instance.selectComponent === "function") return instance.selectComponent(target);
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
return target;
|
|
142
|
+
}
|
|
143
|
+
function getChildInstance(child) {
|
|
144
|
+
return child?.__codeUiInstance ?? child;
|
|
145
|
+
}
|
|
146
|
+
function getChildMachine(child) {
|
|
147
|
+
const comp = getChildInstance(child);
|
|
148
|
+
if (comp?.__codeUiMachine) return comp.__codeUiMachine;
|
|
149
|
+
if (typeof comp?.getMachine === "function") return comp.getMachine();
|
|
150
|
+
}
|
|
151
|
+
function getChildService(child) {
|
|
152
|
+
if (child?.service) return child.service;
|
|
153
|
+
const comp = getChildInstance(child);
|
|
154
|
+
if (typeof comp?.getService === "function") return comp.getService();
|
|
155
|
+
return comp?.__codeUiMachine?.service;
|
|
156
|
+
}
|
|
157
|
+
function useComponentRef(instance, target, options = {}) {
|
|
158
|
+
const { key, connect, onChange } = options;
|
|
159
|
+
let activeChild = resolveChild(instance, target);
|
|
160
|
+
let unsubscribeMachine;
|
|
161
|
+
let isDisposed = false;
|
|
162
|
+
let latestSnapshot;
|
|
163
|
+
let prevSyncedSnapshot;
|
|
164
|
+
let pendingDelta = {};
|
|
165
|
+
let isBatchScheduled = false;
|
|
166
|
+
let isApiDirty = true;
|
|
167
|
+
const ensureChild = () => {
|
|
168
|
+
if (!activeChild || typeof target === "string" && activeChild.__wxExparserNodeId__ === void 0 && instance && typeof instance.selectComponent === "function") {
|
|
169
|
+
const resolved = resolveChild(instance, target);
|
|
170
|
+
if (resolved && resolved !== activeChild) {
|
|
171
|
+
activeChild = resolved;
|
|
172
|
+
isApiDirty = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return activeChild;
|
|
176
|
+
};
|
|
177
|
+
const flushSetData = () => {
|
|
178
|
+
isBatchScheduled = false;
|
|
179
|
+
if (isDisposed) {
|
|
180
|
+
pendingDelta = {};
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (Object.keys(pendingDelta).length > 0 && instance && typeof instance.setData === "function") {
|
|
184
|
+
const payload = pendingDelta;
|
|
185
|
+
pendingDelta = {};
|
|
186
|
+
instance.setData(payload);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const computeSnapshot = () => {
|
|
190
|
+
const child = ensureChild();
|
|
191
|
+
if (!child) return void 0;
|
|
192
|
+
const service = getChildService(child);
|
|
193
|
+
if (connect && service) return connect(service);
|
|
194
|
+
const comp = getChildInstance(child);
|
|
195
|
+
if (comp?.__codeUiApi !== void 0) return comp.__codeUiApi;
|
|
196
|
+
if (service?.context && typeof service.context.getSnapshot === "function") return service.context.getSnapshot();
|
|
197
|
+
};
|
|
198
|
+
const apiTarget = {};
|
|
199
|
+
const syncApiTarget = (snap) => {
|
|
200
|
+
if (!isApiDirty) return;
|
|
201
|
+
const child = ensureChild();
|
|
202
|
+
if (!child) return;
|
|
203
|
+
const currentSnap = snap ?? latestSnapshot ?? computeSnapshot();
|
|
204
|
+
if (currentSnap && typeof currentSnap === "object") {
|
|
205
|
+
for (const [k, v] of Object.entries(currentSnap)) if (typeof v === "function") apiTarget[k] = v.bind(currentSnap);
|
|
206
|
+
if (typeof currentSnap.clearValue === "function") apiTarget.clear = currentSnap.clearValue.bind(currentSnap);
|
|
207
|
+
if (typeof currentSnap.resetValue === "function") apiTarget.reset = currentSnap.resetValue.bind(currentSnap);
|
|
208
|
+
}
|
|
209
|
+
for (const k of Object.keys(child)) {
|
|
210
|
+
const v = child[k];
|
|
211
|
+
if (typeof v === "function" && !(k in apiTarget)) apiTarget[k] = v.bind(child);
|
|
212
|
+
}
|
|
213
|
+
const comp = getChildInstance(child);
|
|
214
|
+
if (comp) {
|
|
215
|
+
if (typeof comp.send === "function" && !("send" in apiTarget)) apiTarget.send = comp.send.bind(comp);
|
|
216
|
+
}
|
|
217
|
+
isApiDirty = false;
|
|
218
|
+
};
|
|
219
|
+
const apiProxy = new Proxy(apiTarget, {
|
|
220
|
+
get(targetObj, prop, receiver) {
|
|
221
|
+
if (isApiDirty) syncApiTarget();
|
|
222
|
+
if (typeof prop === "string" && prop in targetObj) return targetObj[prop];
|
|
223
|
+
const snap = latestSnapshot ?? computeSnapshot();
|
|
224
|
+
if (snap && typeof prop === "string" && prop in snap) {
|
|
225
|
+
const val = snap[prop];
|
|
226
|
+
return typeof val === "function" ? val.bind(snap) : val;
|
|
227
|
+
}
|
|
228
|
+
return Reflect.get(targetObj, prop, receiver);
|
|
229
|
+
},
|
|
230
|
+
has(targetObj, prop) {
|
|
231
|
+
if (isApiDirty) syncApiTarget();
|
|
232
|
+
if (prop in targetObj) return true;
|
|
233
|
+
const snap = latestSnapshot ?? computeSnapshot();
|
|
234
|
+
return snap ? prop in snap : false;
|
|
235
|
+
},
|
|
236
|
+
ownKeys(targetObj) {
|
|
237
|
+
if (isApiDirty) syncApiTarget();
|
|
238
|
+
const snap = latestSnapshot ?? computeSnapshot();
|
|
239
|
+
const keys = new Set(Reflect.ownKeys(targetObj));
|
|
240
|
+
if (snap) for (const k of Reflect.ownKeys(snap)) keys.add(k);
|
|
241
|
+
return Array.from(keys);
|
|
242
|
+
},
|
|
243
|
+
getOwnPropertyDescriptor(targetObj, prop) {
|
|
244
|
+
if (isApiDirty) syncApiTarget();
|
|
245
|
+
if (prop in targetObj) return Reflect.getOwnPropertyDescriptor(targetObj, prop);
|
|
246
|
+
const snap = latestSnapshot ?? computeSnapshot();
|
|
247
|
+
if (snap && prop in snap) return Reflect.getOwnPropertyDescriptor(snap, prop);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
const update = () => {
|
|
251
|
+
if (isDisposed) return;
|
|
252
|
+
const snapshot = computeSnapshot();
|
|
253
|
+
if (snapshot === void 0) return;
|
|
254
|
+
latestSnapshot = snapshot;
|
|
255
|
+
isApiDirty = true;
|
|
256
|
+
if (onChange) onChange(snapshot);
|
|
257
|
+
if (key && snapshot && typeof snapshot === "object") {
|
|
258
|
+
const delta = diffSnapshot(prevSyncedSnapshot, snapshot, key);
|
|
259
|
+
prevSyncedSnapshot = { ...snapshot };
|
|
260
|
+
if (!delta) return;
|
|
261
|
+
Object.assign(pendingDelta, delta);
|
|
262
|
+
if (!isBatchScheduled) {
|
|
263
|
+
isBatchScheduled = true;
|
|
264
|
+
queueMicrotask(flushSetData);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const bindChild = () => {
|
|
269
|
+
if (isDisposed || unsubscribeMachine) return;
|
|
270
|
+
const child = ensureChild();
|
|
271
|
+
if (!child) return;
|
|
272
|
+
const machine = getChildMachine(child);
|
|
273
|
+
if (machine && typeof machine.subscribe === "function") unsubscribeMachine = machine.subscribe(update);
|
|
274
|
+
const comp = getChildInstance(child);
|
|
275
|
+
if (comp && !unsubscribeMachine) {
|
|
276
|
+
if (!comp[LISTENER_SET_KEY]) {
|
|
277
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
278
|
+
comp[LISTENER_SET_KEY] = listeners;
|
|
279
|
+
const origOnSnapshot = comp.__codeUiOnSnapshot;
|
|
280
|
+
comp.__codeUiOnSnapshot = (snap) => {
|
|
281
|
+
origOnSnapshot?.(snap);
|
|
282
|
+
listeners.forEach((fn) => fn());
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
comp[LISTENER_SET_KEY].add(update);
|
|
286
|
+
unsubscribeMachine = () => {
|
|
287
|
+
comp[LISTENER_SET_KEY]?.delete(update);
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
update();
|
|
291
|
+
};
|
|
292
|
+
bindChild();
|
|
293
|
+
if (!activeChild && typeof target === "string" && instance) {
|
|
294
|
+
const pageOrComp = instance;
|
|
295
|
+
if (typeof wx !== "undefined" && typeof wx.nextTick === "function") wx.nextTick(bindChild);
|
|
296
|
+
else Promise.resolve().then(bindChild);
|
|
297
|
+
for (const hook of ["onReady", "ready"]) if (typeof pageOrComp[hook] === "function") {
|
|
298
|
+
const origHook = pageOrComp[hook];
|
|
299
|
+
pageOrComp[hook] = function(...args) {
|
|
300
|
+
bindChild();
|
|
301
|
+
return origHook.apply(this, args);
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const stop = () => {
|
|
306
|
+
if (isDisposed) return;
|
|
307
|
+
isDisposed = true;
|
|
308
|
+
if (unsubscribeMachine) {
|
|
309
|
+
unsubscribeMachine();
|
|
310
|
+
unsubscribeMachine = void 0;
|
|
311
|
+
}
|
|
312
|
+
pendingDelta = {};
|
|
313
|
+
isBatchScheduled = false;
|
|
314
|
+
};
|
|
315
|
+
if (instance) {
|
|
316
|
+
const pageOrComp = instance;
|
|
317
|
+
for (const hook of ["onUnload", "detached"]) if (typeof pageOrComp[hook] === "function") {
|
|
318
|
+
const origHook = pageOrComp[hook];
|
|
319
|
+
pageOrComp[hook] = function(...args) {
|
|
320
|
+
stop();
|
|
321
|
+
return origHook.apply(this, args);
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const send = (event) => {
|
|
326
|
+
if (!unsubscribeMachine) bindChild();
|
|
327
|
+
const child = ensureChild();
|
|
328
|
+
if (typeof child?.send === "function") {
|
|
329
|
+
child.send(event);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const machine = getChildMachine(child);
|
|
333
|
+
if (machine && typeof machine.send === "function") {
|
|
334
|
+
machine.send(event);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
warn(true, `[useComponentRef] Unable to send event; child component for target "${String(target)}" was not found.`);
|
|
338
|
+
};
|
|
339
|
+
const returnObj = {
|
|
340
|
+
getSnapshot: () => latestSnapshot ?? computeSnapshot(),
|
|
341
|
+
get snapshot() {
|
|
342
|
+
return latestSnapshot ?? computeSnapshot();
|
|
343
|
+
},
|
|
344
|
+
api: apiProxy,
|
|
345
|
+
send,
|
|
346
|
+
stop
|
|
347
|
+
};
|
|
348
|
+
Object.defineProperty(returnObj, "service", {
|
|
349
|
+
get() {
|
|
350
|
+
return getChildService(ensureChild());
|
|
351
|
+
},
|
|
352
|
+
enumerable: false,
|
|
353
|
+
configurable: true
|
|
354
|
+
});
|
|
355
|
+
Object.defineProperty(returnObj, "toJSON", {
|
|
356
|
+
value: () => void 0,
|
|
357
|
+
enumerable: false,
|
|
358
|
+
configurable: true
|
|
359
|
+
});
|
|
360
|
+
return returnObj;
|
|
361
|
+
}
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region ../../node_modules/.pnpm/alien-signals@3.2.1/node_modules/alien-signals/esm/system.mjs
|
|
364
|
+
function createReactiveSystem({ update, notify, unwatched }) {
|
|
365
|
+
return {
|
|
366
|
+
link,
|
|
367
|
+
unlink,
|
|
368
|
+
propagate,
|
|
369
|
+
checkDirty,
|
|
370
|
+
shallowPropagate
|
|
371
|
+
};
|
|
372
|
+
function link(dep, sub, version) {
|
|
373
|
+
const prevDep = sub.depsTail;
|
|
374
|
+
if (prevDep !== void 0 && prevDep.dep === dep) return;
|
|
375
|
+
const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
|
|
376
|
+
if (nextDep !== void 0 && nextDep.dep === dep) {
|
|
377
|
+
nextDep.version = version;
|
|
378
|
+
sub.depsTail = nextDep;
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const prevSub = dep.subsTail;
|
|
382
|
+
if (prevSub !== void 0 && prevSub.version === version && prevSub.sub === sub) return;
|
|
383
|
+
const newLink = sub.depsTail = dep.subsTail = {
|
|
384
|
+
version,
|
|
385
|
+
dep,
|
|
386
|
+
sub,
|
|
387
|
+
prevDep,
|
|
388
|
+
nextDep,
|
|
389
|
+
prevSub,
|
|
390
|
+
nextSub: void 0
|
|
391
|
+
};
|
|
392
|
+
if (nextDep !== void 0) nextDep.prevDep = newLink;
|
|
393
|
+
if (prevDep !== void 0) prevDep.nextDep = newLink;
|
|
394
|
+
else sub.deps = newLink;
|
|
395
|
+
if (prevSub !== void 0) prevSub.nextSub = newLink;
|
|
396
|
+
else dep.subs = newLink;
|
|
397
|
+
}
|
|
398
|
+
function unlink(link, sub = link.sub) {
|
|
399
|
+
const { dep, prevDep, nextDep, nextSub, prevSub } = link;
|
|
400
|
+
if (nextDep !== void 0) nextDep.prevDep = prevDep;
|
|
401
|
+
else sub.depsTail = prevDep;
|
|
402
|
+
if (prevDep !== void 0) prevDep.nextDep = nextDep;
|
|
403
|
+
else sub.deps = nextDep;
|
|
404
|
+
if (nextSub !== void 0) nextSub.prevSub = prevSub;
|
|
405
|
+
else dep.subsTail = prevSub;
|
|
406
|
+
if (prevSub !== void 0) prevSub.nextSub = nextSub;
|
|
407
|
+
else if ((dep.subs = nextSub) === void 0) unwatched(dep);
|
|
408
|
+
return nextDep;
|
|
409
|
+
}
|
|
410
|
+
function propagate(link, innerWrite) {
|
|
411
|
+
let next = link.nextSub;
|
|
412
|
+
let stack;
|
|
413
|
+
top: do {
|
|
414
|
+
const sub = link.sub;
|
|
415
|
+
let flags = sub.flags;
|
|
416
|
+
if (!(flags & 60)) {
|
|
417
|
+
sub.flags = flags | 32;
|
|
418
|
+
if (innerWrite) sub.flags |= 8;
|
|
419
|
+
} else if (!(flags & 12)) flags = 0;
|
|
420
|
+
else if (!(flags & 4)) sub.flags = flags & -9 | 32;
|
|
421
|
+
else if (!(flags & 48) && isValidLink(link, sub)) {
|
|
422
|
+
sub.flags = flags | 40;
|
|
423
|
+
flags &= 1;
|
|
424
|
+
} else flags = 0;
|
|
425
|
+
if (flags & 2) notify(sub);
|
|
426
|
+
if (flags & 1) {
|
|
427
|
+
const subSubs = sub.subs;
|
|
428
|
+
if (subSubs !== void 0) {
|
|
429
|
+
const nextSub = (link = subSubs).nextSub;
|
|
430
|
+
if (nextSub !== void 0) {
|
|
431
|
+
stack = {
|
|
432
|
+
value: next,
|
|
433
|
+
prev: stack
|
|
434
|
+
};
|
|
435
|
+
next = nextSub;
|
|
436
|
+
}
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if ((link = next) !== void 0) {
|
|
441
|
+
next = link.nextSub;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
while (stack !== void 0) {
|
|
445
|
+
link = stack.value;
|
|
446
|
+
stack = stack.prev;
|
|
447
|
+
if (link !== void 0) {
|
|
448
|
+
next = link.nextSub;
|
|
449
|
+
continue top;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
break;
|
|
453
|
+
} while (true);
|
|
454
|
+
}
|
|
455
|
+
function checkDirty(link, sub) {
|
|
456
|
+
let stack;
|
|
457
|
+
let checkDepth = 0;
|
|
458
|
+
let dirty = false;
|
|
459
|
+
top: do {
|
|
460
|
+
const dep = link.dep;
|
|
461
|
+
const flags = dep.flags;
|
|
462
|
+
if (sub.flags & 16) dirty = true;
|
|
463
|
+
else if ((flags & 17) === 17) {
|
|
464
|
+
const subs = dep.subs;
|
|
465
|
+
if (update(dep)) {
|
|
466
|
+
if (subs.nextSub !== void 0) shallowPropagate(subs);
|
|
467
|
+
dirty = true;
|
|
468
|
+
}
|
|
469
|
+
} else if ((flags & 33) === 33) {
|
|
470
|
+
stack = {
|
|
471
|
+
value: link,
|
|
472
|
+
prev: stack
|
|
473
|
+
};
|
|
474
|
+
link = dep.deps;
|
|
475
|
+
sub = dep;
|
|
476
|
+
++checkDepth;
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
if (!dirty) {
|
|
480
|
+
const nextDep = link.nextDep;
|
|
481
|
+
if (nextDep !== void 0) {
|
|
482
|
+
link = nextDep;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
while (checkDepth--) {
|
|
487
|
+
link = stack.value;
|
|
488
|
+
stack = stack.prev;
|
|
489
|
+
if (dirty) {
|
|
490
|
+
const subs = sub.subs;
|
|
491
|
+
if (update(sub)) {
|
|
492
|
+
if (subs.nextSub !== void 0) shallowPropagate(subs);
|
|
493
|
+
sub = link.sub;
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
dirty = false;
|
|
497
|
+
} else sub.flags &= -33;
|
|
498
|
+
sub = link.sub;
|
|
499
|
+
const nextDep = link.nextDep;
|
|
500
|
+
if (nextDep !== void 0) {
|
|
501
|
+
link = nextDep;
|
|
502
|
+
continue top;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return dirty && !!sub.flags;
|
|
506
|
+
} while (true);
|
|
507
|
+
}
|
|
508
|
+
function shallowPropagate(link) {
|
|
509
|
+
do {
|
|
510
|
+
const sub = link.sub;
|
|
511
|
+
const flags = sub.flags;
|
|
512
|
+
if ((flags & 48) === 32) {
|
|
513
|
+
sub.flags = flags | 16;
|
|
514
|
+
if ((flags & 6) === 2) notify(sub);
|
|
515
|
+
}
|
|
516
|
+
} while ((link = link.nextSub) !== void 0);
|
|
517
|
+
}
|
|
518
|
+
function isValidLink(checkLink, sub) {
|
|
519
|
+
let link = sub.depsTail;
|
|
520
|
+
while (link !== void 0) {
|
|
521
|
+
if (link === checkLink) return true;
|
|
522
|
+
link = link.prevDep;
|
|
523
|
+
}
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region ../../node_modules/.pnpm/alien-signals@3.2.1/node_modules/alien-signals/esm/index.mjs
|
|
529
|
+
const HasChildEffect = 64;
|
|
530
|
+
let cycle = 0;
|
|
531
|
+
let queuedLength = 0;
|
|
532
|
+
let activeSub;
|
|
533
|
+
const queued = [];
|
|
534
|
+
const { link, unlink, propagate, checkDirty, shallowPropagate } = createReactiveSystem({
|
|
535
|
+
update(node) {
|
|
536
|
+
if ("getter" in node) return updateComputed(node);
|
|
537
|
+
if ("currentValue" in node) return updateSignal(node);
|
|
538
|
+
node.flags = 1;
|
|
539
|
+
return true;
|
|
540
|
+
},
|
|
541
|
+
notify(effect) {
|
|
542
|
+
let insertIndex = queuedLength;
|
|
543
|
+
let firstInsertedIndex = insertIndex;
|
|
544
|
+
do {
|
|
545
|
+
queued[insertIndex++] = effect;
|
|
546
|
+
effect.flags &= -3;
|
|
547
|
+
effect = effect.subs?.sub;
|
|
548
|
+
if (effect === void 0 || !(effect.flags & 2)) break;
|
|
549
|
+
} while (true);
|
|
550
|
+
queuedLength = insertIndex;
|
|
551
|
+
while (firstInsertedIndex < --insertIndex) {
|
|
552
|
+
const left = queued[firstInsertedIndex];
|
|
553
|
+
queued[firstInsertedIndex++] = queued[insertIndex];
|
|
554
|
+
queued[insertIndex] = left;
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
unwatched(node) {
|
|
558
|
+
if ("getter" in node) {
|
|
559
|
+
if (node.depsTail !== void 0) {
|
|
560
|
+
node.flags = 17;
|
|
561
|
+
disposeAllDepsInReverse(node);
|
|
562
|
+
}
|
|
563
|
+
} else if ("currentValue" in node) {} else if ("fn" in node) effectOper.call(node);
|
|
564
|
+
else effectScopeOper.call(node);
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
function setActiveSub(sub) {
|
|
568
|
+
const prevSub = activeSub;
|
|
569
|
+
activeSub = sub;
|
|
570
|
+
return prevSub;
|
|
571
|
+
}
|
|
572
|
+
function updateComputed(c) {
|
|
573
|
+
if (c.flags & HasChildEffect) {
|
|
574
|
+
let link = c.depsTail;
|
|
575
|
+
while (link !== void 0) {
|
|
576
|
+
const prev = link.prevDep;
|
|
577
|
+
const dep = link.dep;
|
|
578
|
+
if (!("getter" in dep) && !("currentValue" in dep)) unlink(link, c);
|
|
579
|
+
link = prev;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
c.depsTail = void 0;
|
|
583
|
+
c.flags = 5;
|
|
584
|
+
const prevSub = setActiveSub(c);
|
|
585
|
+
try {
|
|
586
|
+
++cycle;
|
|
587
|
+
const oldValue = c.value;
|
|
588
|
+
return oldValue !== (c.value = c.getter(oldValue));
|
|
589
|
+
} finally {
|
|
590
|
+
activeSub = prevSub;
|
|
591
|
+
c.flags &= -5;
|
|
592
|
+
purgeDeps(c);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function updateSignal(s) {
|
|
596
|
+
s.flags = 1;
|
|
597
|
+
return s.currentValue !== (s.currentValue = s.pendingValue);
|
|
598
|
+
}
|
|
599
|
+
function runCleanup(e) {
|
|
600
|
+
const cleanup = e.cleanup;
|
|
601
|
+
e.cleanup = void 0;
|
|
602
|
+
const prevSub = activeSub;
|
|
603
|
+
activeSub = void 0;
|
|
604
|
+
try {
|
|
605
|
+
cleanup();
|
|
606
|
+
} finally {
|
|
607
|
+
activeSub = prevSub;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
function effectOper() {
|
|
611
|
+
effectScopeOper.call(this);
|
|
612
|
+
if (this.cleanup) runCleanup(this);
|
|
613
|
+
}
|
|
614
|
+
function effectScopeOper() {
|
|
615
|
+
this.flags = 0;
|
|
616
|
+
disposeAllDepsInReverse(this);
|
|
617
|
+
const sub = this.subs;
|
|
618
|
+
if (sub !== void 0) unlink(sub);
|
|
619
|
+
}
|
|
620
|
+
function disposeAllDepsInReverse(sub) {
|
|
621
|
+
let link = sub.depsTail;
|
|
622
|
+
while (link !== void 0) {
|
|
623
|
+
const prev = link.prevDep;
|
|
624
|
+
unlink(link, sub);
|
|
625
|
+
link = prev;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
function purgeDeps(sub) {
|
|
629
|
+
const depsTail = sub.depsTail;
|
|
630
|
+
let dep = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
|
|
631
|
+
while (dep !== void 0) dep = unlink(dep, sub);
|
|
632
|
+
}
|
|
633
|
+
//#endregion
|
|
634
|
+
//#region ../frameworks/miniapp/dist/behaviors/toast.js
|
|
635
|
+
function resolvePageId(instance) {
|
|
636
|
+
if (!instance) return void 0;
|
|
637
|
+
try {
|
|
638
|
+
if (typeof instance.getPageId === "function") {
|
|
639
|
+
const pid = instance.getPageId();
|
|
640
|
+
if (pid !== void 0 && pid !== null && pid !== "") return String(pid);
|
|
641
|
+
}
|
|
642
|
+
if (instance.__wxWebviewId__ !== void 0 && instance.__wxWebviewId__ !== null && String(instance.__wxWebviewId__) !== "") return String(instance.__wxWebviewId__);
|
|
643
|
+
if (typeof instance.__page__?.getPageId === "function") {
|
|
644
|
+
const pid = instance.__page__.getPageId();
|
|
645
|
+
if (pid !== void 0 && pid !== null && pid !== "") return String(pid);
|
|
646
|
+
}
|
|
647
|
+
if (typeof instance.$page?.getPageId === "function") {
|
|
648
|
+
const pid = instance.$page.getPageId();
|
|
649
|
+
if (pid !== void 0 && pid !== null && pid !== "") return String(pid);
|
|
650
|
+
}
|
|
651
|
+
} catch {}
|
|
652
|
+
}
|
|
653
|
+
const ACTIVE_KEY = "*";
|
|
654
|
+
const MAX_PENDING_PER_KEY = 20;
|
|
655
|
+
const globalScope$1 = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
|
|
656
|
+
if (!globalScope$1.__CODE_UI_TOAST_REGISTRY__) globalScope$1.__CODE_UI_TOAST_REGISTRY__ = {
|
|
657
|
+
hosts: [],
|
|
658
|
+
hostByInstance: /* @__PURE__ */ new WeakMap(),
|
|
659
|
+
pending: /* @__PURE__ */ new Map(),
|
|
660
|
+
orderCounter: 0,
|
|
661
|
+
toastIdCounter: 0
|
|
662
|
+
};
|
|
663
|
+
const registry = globalScope$1.__CODE_UI_TOAST_REGISTRY__;
|
|
664
|
+
function findHostByPageId(pageId) {
|
|
665
|
+
for (let i = registry.hosts.length - 1; i >= 0; i--) {
|
|
666
|
+
const host = registry.hosts[i];
|
|
667
|
+
if (host && host.pageId === pageId) return host;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
function findActiveToastHost(owner) {
|
|
671
|
+
if (owner) {
|
|
672
|
+
const own = registry.hostByInstance.get(owner);
|
|
673
|
+
if (own) return own;
|
|
674
|
+
if (owner.__cuiApp) {
|
|
675
|
+
const appHost = registry.hostByInstance.get(owner.__cuiApp);
|
|
676
|
+
if (appHost) return appHost;
|
|
677
|
+
}
|
|
678
|
+
if (owner.__cuiAppParent) {
|
|
679
|
+
const parentHost = registry.hostByInstance.get(owner.__cuiAppParent);
|
|
680
|
+
if (parentHost) return parentHost;
|
|
681
|
+
}
|
|
682
|
+
const pageId = resolvePageId(owner);
|
|
683
|
+
if (pageId) {
|
|
684
|
+
const match = findHostByPageId(pageId);
|
|
685
|
+
if (match) return match;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (typeof getCurrentPages === "function") try {
|
|
689
|
+
const pages = getCurrentPages();
|
|
690
|
+
const topPage = pages && pages[pages.length - 1];
|
|
691
|
+
if (topPage) {
|
|
692
|
+
if (topPage.__cuiApp) {
|
|
693
|
+
const appHost = registry.hostByInstance.get(topPage.__cuiApp);
|
|
694
|
+
if (appHost) return appHost;
|
|
695
|
+
}
|
|
696
|
+
const topPageId = resolvePageId(topPage);
|
|
697
|
+
if (topPageId) {
|
|
698
|
+
const host = findHostByPageId(topPageId);
|
|
699
|
+
if (host) return host;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
} catch {}
|
|
703
|
+
let best;
|
|
704
|
+
for (const host of registry.hosts) if (!best || host.order > best.order) best = host;
|
|
705
|
+
return best ?? registry.hosts[registry.hosts.length - 1];
|
|
706
|
+
}
|
|
707
|
+
function withToastHost(owner, op) {
|
|
708
|
+
const host = findActiveToastHost(owner);
|
|
709
|
+
if (host) {
|
|
710
|
+
op(host);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const key = owner && resolvePageId(owner) || ACTIVE_KEY;
|
|
714
|
+
const queue = registry.pending.get(key) ?? [];
|
|
715
|
+
if (queue.length >= MAX_PENDING_PER_KEY) queue.shift();
|
|
716
|
+
queue.push(op);
|
|
717
|
+
registry.pending.set(key, queue);
|
|
718
|
+
}
|
|
719
|
+
function updateToastHostConfig(owner, options) {
|
|
720
|
+
withToastHost(owner, (host) => {
|
|
721
|
+
if (options.max !== void 0) host.manager.setMax(options.max);
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
function addToast(entry, owner) {
|
|
725
|
+
const id = entry.id || `toast-${++registry.toastIdCounter}`;
|
|
726
|
+
const mode = entry.mode ?? "default";
|
|
727
|
+
const rawColor = entry.color || "neutral";
|
|
728
|
+
const color = rawColor === "error" ? "danger" : rawColor;
|
|
729
|
+
const toastItem = {
|
|
730
|
+
...entry,
|
|
731
|
+
id,
|
|
732
|
+
mode,
|
|
733
|
+
color,
|
|
734
|
+
open: entry.open ?? true,
|
|
735
|
+
duration: entry.duration ?? (mode === "native" ? 1500 : 4e3),
|
|
736
|
+
progress: entry.progress ?? mode !== "native",
|
|
737
|
+
progressPosition: entry.progressPosition ?? "bottom",
|
|
738
|
+
variant: entry.variant ?? "outline",
|
|
739
|
+
close: entry.close ?? true
|
|
740
|
+
};
|
|
741
|
+
withToastHost(owner, (host) => {
|
|
742
|
+
host.manager.add(toastItem);
|
|
743
|
+
});
|
|
744
|
+
return id;
|
|
745
|
+
}
|
|
746
|
+
function dismissToast(id, owner) {
|
|
747
|
+
withToastHost(owner, (host) => {
|
|
748
|
+
host.manager.dismiss(id);
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
function removeToast(id, owner) {
|
|
752
|
+
withToastHost(owner, (host) => {
|
|
753
|
+
host.manager.remove(id);
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
function clearToasts(owner) {
|
|
757
|
+
withToastHost(owner, (host) => {
|
|
758
|
+
host.manager.clear();
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
function updateToast(id, patch, owner) {
|
|
762
|
+
withToastHost(owner, (host) => {
|
|
763
|
+
host.manager.update(id, patch);
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
//#endregion
|
|
767
|
+
//#region src/use-toast.ts
|
|
768
|
+
function normalizeShorthand(titleOrOptions, extraOptions) {
|
|
769
|
+
if (typeof titleOrOptions === "string") return {
|
|
770
|
+
title: titleOrOptions,
|
|
771
|
+
...extraOptions
|
|
772
|
+
};
|
|
773
|
+
return {
|
|
774
|
+
...titleOrOptions,
|
|
775
|
+
...extraOptions
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
function useToast(optionsOrTarget) {
|
|
779
|
+
const isOptionsObject = Boolean(optionsOrTarget) && typeof optionsOrTarget === "object" && ("target" in optionsOrTarget || "max" in optionsOrTarget);
|
|
780
|
+
const explicitTarget = isOptionsObject ? optionsOrTarget.target : optionsOrTarget;
|
|
781
|
+
let pendingMax = isOptionsObject && typeof optionsOrTarget.max === "number" ? optionsOrTarget.max : void 0;
|
|
782
|
+
const resolveTarget = () => {
|
|
783
|
+
if (explicitTarget) return explicitTarget;
|
|
784
|
+
if (typeof getCurrentPages === "function") try {
|
|
785
|
+
const pages = getCurrentPages();
|
|
786
|
+
return pages && pages[pages.length - 1];
|
|
787
|
+
} catch {}
|
|
788
|
+
};
|
|
789
|
+
const applyPendingMax = (target) => {
|
|
790
|
+
if (pendingMax !== void 0) {
|
|
791
|
+
updateToastHostConfig(target, { max: pendingMax });
|
|
792
|
+
pendingMax = void 0;
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
const initialTarget = resolveTarget();
|
|
796
|
+
if (initialTarget && pendingMax !== void 0) applyPendingMax(initialTarget);
|
|
797
|
+
const add = (toast) => {
|
|
798
|
+
const target = resolveTarget();
|
|
799
|
+
applyPendingMax(target);
|
|
800
|
+
return addToast(toast, target);
|
|
801
|
+
};
|
|
802
|
+
return {
|
|
803
|
+
add,
|
|
804
|
+
show: add,
|
|
805
|
+
update: (id, patch) => updateToast(id, patch, resolveTarget()),
|
|
806
|
+
remove: (id) => removeToast(id, resolveTarget()),
|
|
807
|
+
dismiss: (id) => dismissToast(id, resolveTarget()),
|
|
808
|
+
clear: () => clearToasts(resolveTarget()),
|
|
809
|
+
config: (opts) => {
|
|
810
|
+
pendingMax = void 0;
|
|
811
|
+
updateToastHostConfig(resolveTarget(), opts);
|
|
812
|
+
},
|
|
813
|
+
success: (titleOrOptions, opts) => add({
|
|
814
|
+
color: "success",
|
|
815
|
+
...normalizeShorthand(titleOrOptions, opts)
|
|
816
|
+
}),
|
|
817
|
+
error: (titleOrOptions, opts) => add({
|
|
818
|
+
color: "danger",
|
|
819
|
+
...normalizeShorthand(titleOrOptions, opts)
|
|
820
|
+
}),
|
|
821
|
+
warning: (titleOrOptions, opts) => add({
|
|
822
|
+
color: "warning",
|
|
823
|
+
...normalizeShorthand(titleOrOptions, opts)
|
|
824
|
+
}),
|
|
825
|
+
info: (titleOrOptions, opts) => add({
|
|
826
|
+
color: "info",
|
|
827
|
+
...normalizeShorthand(titleOrOptions, opts)
|
|
828
|
+
}),
|
|
829
|
+
loading: (titleOrOptions, opts) => {
|
|
830
|
+
const normalized = normalizeShorthand(titleOrOptions, opts);
|
|
831
|
+
return add({
|
|
832
|
+
color: "loading",
|
|
833
|
+
duration: 0,
|
|
834
|
+
...normalized,
|
|
835
|
+
ui: {
|
|
836
|
+
icon: "animate-spin",
|
|
837
|
+
...normalized.ui
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
//#endregion
|
|
844
|
+
//#region ../frameworks/miniapp/dist/behaviors/theme.js
|
|
845
|
+
const globalScope = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
|
|
846
|
+
function detectSystemTheme() {
|
|
847
|
+
if (typeof wx === "undefined") return "light";
|
|
848
|
+
try {
|
|
849
|
+
const info = typeof wx.getAppBaseInfo === "function" ? wx.getAppBaseInfo() : typeof wx.getSystemInfoSync === "function" ? wx.getSystemInfoSync() : void 0;
|
|
850
|
+
if (info && info.theme === "dark") return "dark";
|
|
851
|
+
} catch {}
|
|
852
|
+
return "light";
|
|
853
|
+
}
|
|
854
|
+
function getRegistry() {
|
|
855
|
+
if (!globalScope.__CODE_UI_THEME_REGISTRY__) globalScope.__CODE_UI_THEME_REGISTRY__ = {
|
|
856
|
+
colorMode: "system",
|
|
857
|
+
systemMode: detectSystemTheme(),
|
|
858
|
+
colors: {},
|
|
859
|
+
cssVars: "",
|
|
860
|
+
baselineColors: null,
|
|
861
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
862
|
+
systemListening: false
|
|
863
|
+
};
|
|
864
|
+
return globalScope.__CODE_UI_THEME_REGISTRY__;
|
|
865
|
+
}
|
|
866
|
+
function resolveMode(reg) {
|
|
867
|
+
if (reg.colorMode === "dark") return "dark";
|
|
868
|
+
if (reg.colorMode === "light") return "light";
|
|
869
|
+
return reg.systemMode;
|
|
870
|
+
}
|
|
871
|
+
function buildState(reg) {
|
|
872
|
+
return {
|
|
873
|
+
colorMode: reg.colorMode,
|
|
874
|
+
resolvedMode: resolveMode(reg),
|
|
875
|
+
colors: { ...reg.colors },
|
|
876
|
+
cssVars: reg.cssVars
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
function ensureSystemListener() {
|
|
880
|
+
const reg = getRegistry();
|
|
881
|
+
if (reg.systemListening) return;
|
|
882
|
+
if (typeof wx === "undefined" || typeof wx.onThemeChange !== "function") return;
|
|
883
|
+
reg.systemListening = true;
|
|
884
|
+
wx.onThemeChange((res) => {
|
|
885
|
+
const currentReg = getRegistry();
|
|
886
|
+
currentReg.systemMode = res.theme === "dark" ? "dark" : "light";
|
|
887
|
+
if (currentReg.colorMode === "system") {
|
|
888
|
+
currentReg.onSystemChange?.(currentReg.systemMode);
|
|
889
|
+
const state = buildState(currentReg);
|
|
890
|
+
for (const listener of currentReg.listeners) listener(state);
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
function getAppTheme() {
|
|
895
|
+
return buildState(getRegistry());
|
|
896
|
+
}
|
|
897
|
+
function subscribeAppTheme(listener, immediate = false) {
|
|
898
|
+
const reg = getRegistry();
|
|
899
|
+
ensureSystemListener();
|
|
900
|
+
reg.listeners.add(listener);
|
|
901
|
+
if (immediate) listener(buildState(reg));
|
|
902
|
+
return () => {
|
|
903
|
+
reg.listeners.delete(listener);
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
//#endregion
|
|
907
|
+
//#region src/use-color-mode.ts
|
|
908
|
+
function getThemeRegistry() {
|
|
909
|
+
return globalThis.__CODE_UI_THEME_REGISTRY__;
|
|
910
|
+
}
|
|
911
|
+
function notifyRegistryListeners(reg) {
|
|
912
|
+
const state = getAppTheme();
|
|
913
|
+
for (const listener of reg.listeners) listener(state);
|
|
914
|
+
}
|
|
915
|
+
function useColorMode(options = {}) {
|
|
916
|
+
const { target, key, initialValue, onChange } = options;
|
|
917
|
+
getAppTheme();
|
|
918
|
+
if (initialValue) {
|
|
919
|
+
const reg = getThemeRegistry();
|
|
920
|
+
if (reg && reg.colorMode !== initialValue) {
|
|
921
|
+
reg.colorMode = initialValue;
|
|
922
|
+
notifyRegistryListeners(reg);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
let unsubscribe;
|
|
926
|
+
if (onChange || target && key && typeof target.setData === "function") unsubscribe = subscribeAppTheme((state) => {
|
|
927
|
+
onChange?.(state);
|
|
928
|
+
if (target && key && typeof target.setData === "function") target.setData({ [key]: state });
|
|
929
|
+
}, true);
|
|
930
|
+
const setMode = (mode) => {
|
|
931
|
+
const reg = getThemeRegistry();
|
|
932
|
+
if (!reg) return;
|
|
933
|
+
reg.colorMode = mode;
|
|
934
|
+
notifyRegistryListeners(reg);
|
|
935
|
+
};
|
|
936
|
+
const toggle = () => {
|
|
937
|
+
const current = getAppTheme().resolvedMode;
|
|
938
|
+
setMode(current === "dark" ? "light" : "dark");
|
|
939
|
+
};
|
|
940
|
+
const stop = () => {
|
|
941
|
+
unsubscribe?.();
|
|
942
|
+
unsubscribe = void 0;
|
|
943
|
+
};
|
|
944
|
+
return {
|
|
945
|
+
get mode() {
|
|
946
|
+
return getAppTheme().colorMode;
|
|
947
|
+
},
|
|
948
|
+
get resolvedMode() {
|
|
949
|
+
return getAppTheme().resolvedMode;
|
|
950
|
+
},
|
|
951
|
+
get colors() {
|
|
952
|
+
return getAppTheme().colors;
|
|
953
|
+
},
|
|
954
|
+
get cssVars() {
|
|
955
|
+
return getAppTheme().cssVars;
|
|
956
|
+
},
|
|
957
|
+
getState: () => getAppTheme(),
|
|
958
|
+
setMode,
|
|
959
|
+
toggle,
|
|
960
|
+
stop
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
//#endregion
|
|
964
|
+
export { useColorMode, useComponentRef, useToast };
|