@rific/auto-paper 0.1.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/README.md +189 -0
- package/dist/index.d.mts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +2011 -0
- package/dist/index.mjs +1967 -0
- package/package.json +83 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2011 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
31
|
+
|
|
32
|
+
// src/index.ts
|
|
33
|
+
var index_exports = {};
|
|
34
|
+
__export(index_exports, {
|
|
35
|
+
ThemeProvider: () => ThemeProvider,
|
|
36
|
+
configureSplashScreen: () => configureSplashScreen,
|
|
37
|
+
getBlendedColor: () => getBlendedColor,
|
|
38
|
+
getHex: () => getHex,
|
|
39
|
+
getRgb: () => getRgb,
|
|
40
|
+
getTriadicPalette: () => getTriadicPalette,
|
|
41
|
+
isDarkColor: () => isDarkColor,
|
|
42
|
+
themeActions: () => themeActions,
|
|
43
|
+
themeReducer: () => themeReducer,
|
|
44
|
+
useComputedTheme: () => useComputedTheme
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(index_exports);
|
|
47
|
+
|
|
48
|
+
// node_modules/redux/dist/redux.mjs
|
|
49
|
+
var randomString = () => Math.random().toString(36).substring(7).split("").join(".");
|
|
50
|
+
var ActionTypes = {
|
|
51
|
+
INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`,
|
|
52
|
+
REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
|
|
53
|
+
PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
|
|
54
|
+
};
|
|
55
|
+
function isPlainObject(obj) {
|
|
56
|
+
if (typeof obj !== "object" || obj === null)
|
|
57
|
+
return false;
|
|
58
|
+
let proto = obj;
|
|
59
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
60
|
+
proto = Object.getPrototypeOf(proto);
|
|
61
|
+
}
|
|
62
|
+
return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
|
|
63
|
+
}
|
|
64
|
+
function compose(...funcs) {
|
|
65
|
+
if (funcs.length === 0) {
|
|
66
|
+
return (arg) => arg;
|
|
67
|
+
}
|
|
68
|
+
if (funcs.length === 1) {
|
|
69
|
+
return funcs[0];
|
|
70
|
+
}
|
|
71
|
+
return funcs.reduce((a, b) => (...args) => a(b(...args)));
|
|
72
|
+
}
|
|
73
|
+
function isAction(action) {
|
|
74
|
+
return isPlainObject(action) && "type" in action && typeof action.type === "string";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// node_modules/immer/dist/immer.mjs
|
|
78
|
+
var NOTHING = /* @__PURE__ */ Symbol.for("immer-nothing");
|
|
79
|
+
var DRAFTABLE = /* @__PURE__ */ Symbol.for("immer-draftable");
|
|
80
|
+
var DRAFT_STATE = /* @__PURE__ */ Symbol.for("immer-state");
|
|
81
|
+
var errors = process.env.NODE_ENV !== "production" ? [
|
|
82
|
+
// All error codes, starting by 0:
|
|
83
|
+
function(plugin) {
|
|
84
|
+
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
|
|
85
|
+
},
|
|
86
|
+
function(thing) {
|
|
87
|
+
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
|
|
88
|
+
},
|
|
89
|
+
"This object has been frozen and should not be mutated",
|
|
90
|
+
function(data) {
|
|
91
|
+
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
92
|
+
},
|
|
93
|
+
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
94
|
+
"Immer forbids circular references",
|
|
95
|
+
"The first or second argument to `produce` must be a function",
|
|
96
|
+
"The third argument to `produce` must be a function or undefined",
|
|
97
|
+
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
98
|
+
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
99
|
+
function(thing) {
|
|
100
|
+
return `'current' expects a draft, got: ${thing}`;
|
|
101
|
+
},
|
|
102
|
+
"Object.defineProperty() cannot be used on an Immer draft",
|
|
103
|
+
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
104
|
+
"Immer only supports deleting array indices",
|
|
105
|
+
"Immer only supports setting array indices and the 'length' property",
|
|
106
|
+
function(thing) {
|
|
107
|
+
return `'original' expects a draft, got: ${thing}`;
|
|
108
|
+
}
|
|
109
|
+
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
110
|
+
// See Patches.ts for additional errors
|
|
111
|
+
] : [];
|
|
112
|
+
function die(error, ...args) {
|
|
113
|
+
if (process.env.NODE_ENV !== "production") {
|
|
114
|
+
const e = errors[error];
|
|
115
|
+
const msg = isFunction(e) ? e.apply(null, args) : e;
|
|
116
|
+
throw new Error(`[Immer] ${msg}`);
|
|
117
|
+
}
|
|
118
|
+
throw new Error(
|
|
119
|
+
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
var O = Object;
|
|
123
|
+
var getPrototypeOf = O.getPrototypeOf;
|
|
124
|
+
var CONSTRUCTOR = "constructor";
|
|
125
|
+
var PROTOTYPE = "prototype";
|
|
126
|
+
var CONFIGURABLE = "configurable";
|
|
127
|
+
var ENUMERABLE = "enumerable";
|
|
128
|
+
var WRITABLE = "writable";
|
|
129
|
+
var VALUE = "value";
|
|
130
|
+
var isDraft = (value) => !!value && !!value[DRAFT_STATE];
|
|
131
|
+
function isDraftable(value) {
|
|
132
|
+
if (!value)
|
|
133
|
+
return false;
|
|
134
|
+
return isPlainObject2(value) || isArray(value) || !!value[DRAFTABLE] || !!value[CONSTRUCTOR]?.[DRAFTABLE] || isMap(value) || isSet(value);
|
|
135
|
+
}
|
|
136
|
+
var objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString();
|
|
137
|
+
var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
|
|
138
|
+
function isPlainObject2(value) {
|
|
139
|
+
if (!value || !isObjectish(value))
|
|
140
|
+
return false;
|
|
141
|
+
const proto = getPrototypeOf(value);
|
|
142
|
+
if (proto === null || proto === O[PROTOTYPE])
|
|
143
|
+
return true;
|
|
144
|
+
const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR];
|
|
145
|
+
if (Ctor === Object)
|
|
146
|
+
return true;
|
|
147
|
+
if (!isFunction(Ctor))
|
|
148
|
+
return false;
|
|
149
|
+
let ctorString = cachedCtorStrings.get(Ctor);
|
|
150
|
+
if (ctorString === void 0) {
|
|
151
|
+
ctorString = Function.toString.call(Ctor);
|
|
152
|
+
cachedCtorStrings.set(Ctor, ctorString);
|
|
153
|
+
}
|
|
154
|
+
return ctorString === objectCtorString;
|
|
155
|
+
}
|
|
156
|
+
function each(obj, iter, strict = true) {
|
|
157
|
+
if (getArchtype(obj) === 0) {
|
|
158
|
+
const keys = strict ? Reflect.ownKeys(obj) : O.keys(obj);
|
|
159
|
+
keys.forEach((key) => {
|
|
160
|
+
iter(key, obj[key], obj);
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
obj.forEach((entry, index) => iter(index, entry, obj));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function getArchtype(thing) {
|
|
167
|
+
const state = thing[DRAFT_STATE];
|
|
168
|
+
return state ? state.type_ : isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
169
|
+
}
|
|
170
|
+
var has = (thing, prop, type = getArchtype(thing)) => type === 2 ? thing.has(prop) : O[PROTOTYPE].hasOwnProperty.call(thing, prop);
|
|
171
|
+
var get = (thing, prop, type = getArchtype(thing)) => (
|
|
172
|
+
// @ts-ignore
|
|
173
|
+
type === 2 ? thing.get(prop) : thing[prop]
|
|
174
|
+
);
|
|
175
|
+
var set = (thing, propOrOldValue, value, type = getArchtype(thing)) => {
|
|
176
|
+
if (type === 2)
|
|
177
|
+
thing.set(propOrOldValue, value);
|
|
178
|
+
else if (type === 3) {
|
|
179
|
+
thing.add(value);
|
|
180
|
+
} else
|
|
181
|
+
thing[propOrOldValue] = value;
|
|
182
|
+
};
|
|
183
|
+
function is(x, y) {
|
|
184
|
+
if (x === y) {
|
|
185
|
+
return x !== 0 || 1 / x === 1 / y;
|
|
186
|
+
} else {
|
|
187
|
+
return x !== x && y !== y;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
var isArray = Array.isArray;
|
|
191
|
+
var isMap = (target) => target instanceof Map;
|
|
192
|
+
var isSet = (target) => target instanceof Set;
|
|
193
|
+
var isObjectish = (target) => typeof target === "object";
|
|
194
|
+
var isFunction = (target) => typeof target === "function";
|
|
195
|
+
var isBoolean = (target) => typeof target === "boolean";
|
|
196
|
+
function isArrayIndex(value) {
|
|
197
|
+
const n = +value;
|
|
198
|
+
return Number.isInteger(n) && String(n) === value;
|
|
199
|
+
}
|
|
200
|
+
var latest = (state) => state.copy_ || state.base_;
|
|
201
|
+
var getFinalValue = (state) => state.modified_ ? state.copy_ : state.base_;
|
|
202
|
+
function shallowCopy(base, strict) {
|
|
203
|
+
if (isMap(base)) {
|
|
204
|
+
return new Map(base);
|
|
205
|
+
}
|
|
206
|
+
if (isSet(base)) {
|
|
207
|
+
return new Set(base);
|
|
208
|
+
}
|
|
209
|
+
if (isArray(base))
|
|
210
|
+
return Array[PROTOTYPE].slice.call(base);
|
|
211
|
+
const isPlain = isPlainObject2(base);
|
|
212
|
+
if (strict === true || strict === "class_only" && !isPlain) {
|
|
213
|
+
const descriptors = O.getOwnPropertyDescriptors(base);
|
|
214
|
+
delete descriptors[DRAFT_STATE];
|
|
215
|
+
let keys = Reflect.ownKeys(descriptors);
|
|
216
|
+
for (let i = 0; i < keys.length; i++) {
|
|
217
|
+
const key = keys[i];
|
|
218
|
+
const desc = descriptors[key];
|
|
219
|
+
if (desc[WRITABLE] === false) {
|
|
220
|
+
desc[WRITABLE] = true;
|
|
221
|
+
desc[CONFIGURABLE] = true;
|
|
222
|
+
}
|
|
223
|
+
if (desc.get || desc.set)
|
|
224
|
+
descriptors[key] = {
|
|
225
|
+
[CONFIGURABLE]: true,
|
|
226
|
+
[WRITABLE]: true,
|
|
227
|
+
// could live with !!desc.set as well here...
|
|
228
|
+
[ENUMERABLE]: desc[ENUMERABLE],
|
|
229
|
+
[VALUE]: base[key]
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
return O.create(getPrototypeOf(base), descriptors);
|
|
233
|
+
} else {
|
|
234
|
+
const proto = getPrototypeOf(base);
|
|
235
|
+
if (proto !== null && isPlain) {
|
|
236
|
+
return { ...base };
|
|
237
|
+
}
|
|
238
|
+
const obj = O.create(proto);
|
|
239
|
+
return O.assign(obj, base);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function freeze(obj, deep = false) {
|
|
243
|
+
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
|
|
244
|
+
return obj;
|
|
245
|
+
if (getArchtype(obj) > 1) {
|
|
246
|
+
O.defineProperties(obj, {
|
|
247
|
+
set: dontMutateMethodOverride,
|
|
248
|
+
add: dontMutateMethodOverride,
|
|
249
|
+
clear: dontMutateMethodOverride,
|
|
250
|
+
delete: dontMutateMethodOverride
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
O.freeze(obj);
|
|
254
|
+
if (deep)
|
|
255
|
+
each(
|
|
256
|
+
obj,
|
|
257
|
+
(_key, value) => {
|
|
258
|
+
freeze(value, true);
|
|
259
|
+
},
|
|
260
|
+
false
|
|
261
|
+
);
|
|
262
|
+
return obj;
|
|
263
|
+
}
|
|
264
|
+
function dontMutateFrozenCollections() {
|
|
265
|
+
die(2);
|
|
266
|
+
}
|
|
267
|
+
var dontMutateMethodOverride = {
|
|
268
|
+
[VALUE]: dontMutateFrozenCollections
|
|
269
|
+
};
|
|
270
|
+
function isFrozen(obj) {
|
|
271
|
+
if (obj === null || !isObjectish(obj))
|
|
272
|
+
return true;
|
|
273
|
+
return O.isFrozen(obj);
|
|
274
|
+
}
|
|
275
|
+
var PluginMapSet = "MapSet";
|
|
276
|
+
var PluginPatches = "Patches";
|
|
277
|
+
var PluginArrayMethods = "ArrayMethods";
|
|
278
|
+
var plugins = {};
|
|
279
|
+
function getPlugin(pluginKey) {
|
|
280
|
+
const plugin = plugins[pluginKey];
|
|
281
|
+
if (!plugin) {
|
|
282
|
+
die(0, pluginKey);
|
|
283
|
+
}
|
|
284
|
+
return plugin;
|
|
285
|
+
}
|
|
286
|
+
var isPluginLoaded = (pluginKey) => !!plugins[pluginKey];
|
|
287
|
+
var currentScope;
|
|
288
|
+
var getCurrentScope = () => currentScope;
|
|
289
|
+
var createScope = (parent_, immer_) => ({
|
|
290
|
+
drafts_: [],
|
|
291
|
+
parent_,
|
|
292
|
+
immer_,
|
|
293
|
+
// Whenever the modified draft contains a draft from another scope, we
|
|
294
|
+
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
295
|
+
canAutoFreeze_: true,
|
|
296
|
+
unfinalizedDrafts_: 0,
|
|
297
|
+
handledSet_: /* @__PURE__ */ new Set(),
|
|
298
|
+
processedForPatches_: /* @__PURE__ */ new Set(),
|
|
299
|
+
mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0,
|
|
300
|
+
arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) ? getPlugin(PluginArrayMethods) : void 0
|
|
301
|
+
});
|
|
302
|
+
function usePatchesInScope(scope, patchListener) {
|
|
303
|
+
if (patchListener) {
|
|
304
|
+
scope.patchPlugin_ = getPlugin(PluginPatches);
|
|
305
|
+
scope.patches_ = [];
|
|
306
|
+
scope.inversePatches_ = [];
|
|
307
|
+
scope.patchListener_ = patchListener;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function revokeScope(scope) {
|
|
311
|
+
leaveScope(scope);
|
|
312
|
+
scope.drafts_.forEach(revokeDraft);
|
|
313
|
+
scope.drafts_ = null;
|
|
314
|
+
}
|
|
315
|
+
function leaveScope(scope) {
|
|
316
|
+
if (scope === currentScope) {
|
|
317
|
+
currentScope = scope.parent_;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
var enterScope = (immer2) => currentScope = createScope(currentScope, immer2);
|
|
321
|
+
function revokeDraft(draft) {
|
|
322
|
+
const state = draft[DRAFT_STATE];
|
|
323
|
+
if (state.type_ === 0 || state.type_ === 1)
|
|
324
|
+
state.revoke_();
|
|
325
|
+
else
|
|
326
|
+
state.revoked_ = true;
|
|
327
|
+
}
|
|
328
|
+
function processResult(result, scope) {
|
|
329
|
+
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
330
|
+
const baseDraft = scope.drafts_[0];
|
|
331
|
+
const isReplaced = result !== void 0 && result !== baseDraft;
|
|
332
|
+
if (isReplaced) {
|
|
333
|
+
if (baseDraft[DRAFT_STATE].modified_) {
|
|
334
|
+
revokeScope(scope);
|
|
335
|
+
die(4);
|
|
336
|
+
}
|
|
337
|
+
if (isDraftable(result)) {
|
|
338
|
+
result = finalize(scope, result);
|
|
339
|
+
}
|
|
340
|
+
const { patchPlugin_ } = scope;
|
|
341
|
+
if (patchPlugin_) {
|
|
342
|
+
patchPlugin_.generateReplacementPatches_(
|
|
343
|
+
baseDraft[DRAFT_STATE].base_,
|
|
344
|
+
result,
|
|
345
|
+
scope
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
result = finalize(scope, baseDraft);
|
|
350
|
+
}
|
|
351
|
+
maybeFreeze(scope, result, true);
|
|
352
|
+
revokeScope(scope);
|
|
353
|
+
if (scope.patches_) {
|
|
354
|
+
scope.patchListener_(scope.patches_, scope.inversePatches_);
|
|
355
|
+
}
|
|
356
|
+
return result !== NOTHING ? result : void 0;
|
|
357
|
+
}
|
|
358
|
+
function finalize(rootScope, value) {
|
|
359
|
+
if (isFrozen(value))
|
|
360
|
+
return value;
|
|
361
|
+
const state = value[DRAFT_STATE];
|
|
362
|
+
if (!state) {
|
|
363
|
+
const finalValue = handleValue(value, rootScope.handledSet_, rootScope);
|
|
364
|
+
return finalValue;
|
|
365
|
+
}
|
|
366
|
+
if (!isSameScope(state, rootScope)) {
|
|
367
|
+
return value;
|
|
368
|
+
}
|
|
369
|
+
if (!state.modified_) {
|
|
370
|
+
return state.base_;
|
|
371
|
+
}
|
|
372
|
+
if (!state.finalized_) {
|
|
373
|
+
const { callbacks_ } = state;
|
|
374
|
+
if (callbacks_) {
|
|
375
|
+
while (callbacks_.length > 0) {
|
|
376
|
+
const callback = callbacks_.pop();
|
|
377
|
+
callback(rootScope);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
generatePatchesAndFinalize(state, rootScope);
|
|
381
|
+
}
|
|
382
|
+
return state.copy_;
|
|
383
|
+
}
|
|
384
|
+
function maybeFreeze(scope, value, deep = false) {
|
|
385
|
+
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
|
|
386
|
+
freeze(value, deep);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function markStateFinalized(state) {
|
|
390
|
+
state.finalized_ = true;
|
|
391
|
+
state.scope_.unfinalizedDrafts_--;
|
|
392
|
+
}
|
|
393
|
+
var isSameScope = (state, rootScope) => state.scope_ === rootScope;
|
|
394
|
+
var EMPTY_LOCATIONS_RESULT = [];
|
|
395
|
+
function updateDraftInParent(parent, draftValue, finalizedValue, originalKey) {
|
|
396
|
+
const parentCopy = latest(parent);
|
|
397
|
+
const parentType = parent.type_;
|
|
398
|
+
if (originalKey !== void 0) {
|
|
399
|
+
const currentValue = get(parentCopy, originalKey, parentType);
|
|
400
|
+
if (currentValue === draftValue) {
|
|
401
|
+
set(parentCopy, originalKey, finalizedValue, parentType);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (!parent.draftLocations_) {
|
|
406
|
+
const draftLocations = parent.draftLocations_ = /* @__PURE__ */ new Map();
|
|
407
|
+
each(parentCopy, (key, value) => {
|
|
408
|
+
if (isDraft(value)) {
|
|
409
|
+
const keys = draftLocations.get(value) || [];
|
|
410
|
+
keys.push(key);
|
|
411
|
+
draftLocations.set(value, keys);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
const locations = parent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT;
|
|
416
|
+
for (const location of locations) {
|
|
417
|
+
set(parentCopy, location, finalizedValue, parentType);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function registerChildFinalizationCallback(parent, child, key) {
|
|
421
|
+
parent.callbacks_.push(function childCleanup(rootScope) {
|
|
422
|
+
const state = child;
|
|
423
|
+
if (!state || !isSameScope(state, rootScope)) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
rootScope.mapSetPlugin_?.fixSetContents(state);
|
|
427
|
+
const finalizedValue = getFinalValue(state);
|
|
428
|
+
updateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key);
|
|
429
|
+
generatePatchesAndFinalize(state, rootScope);
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
function generatePatchesAndFinalize(state, rootScope) {
|
|
433
|
+
const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 || state.type_ === 1 && state.allIndicesReassigned_ || (state.assigned_?.size ?? 0) > 0);
|
|
434
|
+
if (shouldFinalize) {
|
|
435
|
+
const { patchPlugin_ } = rootScope;
|
|
436
|
+
if (patchPlugin_) {
|
|
437
|
+
const basePath = patchPlugin_.getPath(state);
|
|
438
|
+
if (basePath) {
|
|
439
|
+
patchPlugin_.generatePatches_(state, basePath, rootScope);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
markStateFinalized(state);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function handleCrossReference(target, key, value) {
|
|
446
|
+
const { scope_ } = target;
|
|
447
|
+
if (isDraft(value)) {
|
|
448
|
+
const state = value[DRAFT_STATE];
|
|
449
|
+
if (isSameScope(state, scope_)) {
|
|
450
|
+
state.callbacks_.push(function crossReferenceCleanup() {
|
|
451
|
+
prepareCopy(target);
|
|
452
|
+
const finalizedValue = getFinalValue(state);
|
|
453
|
+
updateDraftInParent(target, value, finalizedValue, key);
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
} else if (isDraftable(value)) {
|
|
457
|
+
target.callbacks_.push(function nestedDraftCleanup() {
|
|
458
|
+
const targetCopy = latest(target);
|
|
459
|
+
if (target.type_ === 3) {
|
|
460
|
+
if (targetCopy.has(value)) {
|
|
461
|
+
handleValue(value, scope_.handledSet_, scope_);
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
if (get(targetCopy, key, target.type_) === value) {
|
|
465
|
+
if (scope_.drafts_.length > 1 && (target.assigned_.get(key) ?? false) === true && target.copy_) {
|
|
466
|
+
handleValue(
|
|
467
|
+
get(target.copy_, key, target.type_),
|
|
468
|
+
scope_.handledSet_,
|
|
469
|
+
scope_
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function handleValue(target, handledSet, rootScope) {
|
|
478
|
+
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
|
|
479
|
+
return target;
|
|
480
|
+
}
|
|
481
|
+
if (isDraft(target) || handledSet.has(target) || !isDraftable(target) || isFrozen(target)) {
|
|
482
|
+
return target;
|
|
483
|
+
}
|
|
484
|
+
handledSet.add(target);
|
|
485
|
+
each(target, (key, value) => {
|
|
486
|
+
if (isDraft(value)) {
|
|
487
|
+
const state = value[DRAFT_STATE];
|
|
488
|
+
if (isSameScope(state, rootScope)) {
|
|
489
|
+
const updatedValue = getFinalValue(state);
|
|
490
|
+
set(target, key, updatedValue, target.type_);
|
|
491
|
+
markStateFinalized(state);
|
|
492
|
+
}
|
|
493
|
+
} else if (isDraftable(value)) {
|
|
494
|
+
handleValue(value, handledSet, rootScope);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
return target;
|
|
498
|
+
}
|
|
499
|
+
function createProxyProxy(base, parent) {
|
|
500
|
+
const baseIsArray = isArray(base);
|
|
501
|
+
const state = {
|
|
502
|
+
type_: baseIsArray ? 1 : 0,
|
|
503
|
+
// Track which produce call this is associated with.
|
|
504
|
+
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
505
|
+
// True for both shallow and deep changes.
|
|
506
|
+
modified_: false,
|
|
507
|
+
// Used during finalization.
|
|
508
|
+
finalized_: false,
|
|
509
|
+
// Track which properties have been assigned (true) or deleted (false).
|
|
510
|
+
// actually instantiated in `prepareCopy()`
|
|
511
|
+
assigned_: void 0,
|
|
512
|
+
// The parent draft state.
|
|
513
|
+
parent_: parent,
|
|
514
|
+
// The base state.
|
|
515
|
+
base_: base,
|
|
516
|
+
// The base proxy.
|
|
517
|
+
draft_: null,
|
|
518
|
+
// set below
|
|
519
|
+
// The base copy with any updated values.
|
|
520
|
+
copy_: null,
|
|
521
|
+
// Called by the `produce` function.
|
|
522
|
+
revoke_: null,
|
|
523
|
+
isManual_: false,
|
|
524
|
+
// `callbacks` actually gets assigned in `createProxy`
|
|
525
|
+
callbacks_: void 0
|
|
526
|
+
};
|
|
527
|
+
let target = state;
|
|
528
|
+
let traps = objectTraps;
|
|
529
|
+
if (baseIsArray) {
|
|
530
|
+
target = [state];
|
|
531
|
+
traps = arrayTraps;
|
|
532
|
+
}
|
|
533
|
+
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
534
|
+
state.draft_ = proxy;
|
|
535
|
+
state.revoke_ = revoke;
|
|
536
|
+
return [proxy, state];
|
|
537
|
+
}
|
|
538
|
+
var objectTraps = {
|
|
539
|
+
get(state, prop) {
|
|
540
|
+
if (prop === DRAFT_STATE)
|
|
541
|
+
return state;
|
|
542
|
+
let arrayPlugin = state.scope_.arrayMethodsPlugin_;
|
|
543
|
+
const isArrayWithStringProp = state.type_ === 1 && typeof prop === "string";
|
|
544
|
+
if (isArrayWithStringProp) {
|
|
545
|
+
if (arrayPlugin?.isArrayOperationMethod(prop)) {
|
|
546
|
+
return arrayPlugin.createMethodInterceptor(state, prop);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const source = latest(state);
|
|
550
|
+
if (!has(source, prop, state.type_)) {
|
|
551
|
+
return readPropFromProto(state, source, prop);
|
|
552
|
+
}
|
|
553
|
+
const value = source[prop];
|
|
554
|
+
if (state.finalized_ || !isDraftable(value)) {
|
|
555
|
+
return value;
|
|
556
|
+
}
|
|
557
|
+
if (isArrayWithStringProp && state.operationMethod && arrayPlugin?.isMutatingArrayMethod(
|
|
558
|
+
state.operationMethod
|
|
559
|
+
) && isArrayIndex(prop)) {
|
|
560
|
+
return value;
|
|
561
|
+
}
|
|
562
|
+
if (value === peek(state.base_, prop)) {
|
|
563
|
+
prepareCopy(state);
|
|
564
|
+
const childKey = state.type_ === 1 ? +prop : prop;
|
|
565
|
+
const childDraft = createProxy(state.scope_, value, state, childKey);
|
|
566
|
+
return state.copy_[childKey] = childDraft;
|
|
567
|
+
}
|
|
568
|
+
return value;
|
|
569
|
+
},
|
|
570
|
+
has(state, prop) {
|
|
571
|
+
return prop in latest(state);
|
|
572
|
+
},
|
|
573
|
+
ownKeys(state) {
|
|
574
|
+
return Reflect.ownKeys(latest(state));
|
|
575
|
+
},
|
|
576
|
+
set(state, prop, value) {
|
|
577
|
+
const desc = getDescriptorFromProto(latest(state), prop);
|
|
578
|
+
if (desc?.set) {
|
|
579
|
+
desc.set.call(state.draft_, value);
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
if (!state.modified_) {
|
|
583
|
+
const current2 = peek(latest(state), prop);
|
|
584
|
+
const currentState = current2?.[DRAFT_STATE];
|
|
585
|
+
if (currentState && currentState.base_ === value) {
|
|
586
|
+
state.copy_[prop] = value;
|
|
587
|
+
state.assigned_.set(prop, false);
|
|
588
|
+
return true;
|
|
589
|
+
}
|
|
590
|
+
if (is(value, current2) && (value !== void 0 || has(state.base_, prop, state.type_)))
|
|
591
|
+
return true;
|
|
592
|
+
prepareCopy(state);
|
|
593
|
+
markChanged(state);
|
|
594
|
+
}
|
|
595
|
+
if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
|
|
596
|
+
(value !== void 0 || prop in state.copy_) || // special case: NaN
|
|
597
|
+
Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
|
|
598
|
+
return true;
|
|
599
|
+
state.copy_[prop] = value;
|
|
600
|
+
state.assigned_.set(prop, true);
|
|
601
|
+
handleCrossReference(state, prop, value);
|
|
602
|
+
return true;
|
|
603
|
+
},
|
|
604
|
+
deleteProperty(state, prop) {
|
|
605
|
+
prepareCopy(state);
|
|
606
|
+
if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
|
|
607
|
+
state.assigned_.set(prop, false);
|
|
608
|
+
markChanged(state);
|
|
609
|
+
} else {
|
|
610
|
+
state.assigned_.delete(prop);
|
|
611
|
+
}
|
|
612
|
+
if (state.copy_) {
|
|
613
|
+
delete state.copy_[prop];
|
|
614
|
+
}
|
|
615
|
+
return true;
|
|
616
|
+
},
|
|
617
|
+
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
618
|
+
// the same guarantee in ES5 mode.
|
|
619
|
+
getOwnPropertyDescriptor(state, prop) {
|
|
620
|
+
const owner = latest(state);
|
|
621
|
+
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
622
|
+
if (!desc)
|
|
623
|
+
return desc;
|
|
624
|
+
return {
|
|
625
|
+
[WRITABLE]: true,
|
|
626
|
+
[CONFIGURABLE]: state.type_ !== 1 || prop !== "length",
|
|
627
|
+
[ENUMERABLE]: desc[ENUMERABLE],
|
|
628
|
+
[VALUE]: owner[prop]
|
|
629
|
+
};
|
|
630
|
+
},
|
|
631
|
+
defineProperty() {
|
|
632
|
+
die(11);
|
|
633
|
+
},
|
|
634
|
+
getPrototypeOf(state) {
|
|
635
|
+
return getPrototypeOf(state.base_);
|
|
636
|
+
},
|
|
637
|
+
setPrototypeOf() {
|
|
638
|
+
die(12);
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
var arrayTraps = {};
|
|
642
|
+
for (let key in objectTraps) {
|
|
643
|
+
let fn = objectTraps[key];
|
|
644
|
+
arrayTraps[key] = function() {
|
|
645
|
+
const args = arguments;
|
|
646
|
+
args[0] = args[0][0];
|
|
647
|
+
return fn.apply(this, args);
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
arrayTraps.deleteProperty = function(state, prop) {
|
|
651
|
+
if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
|
|
652
|
+
die(13);
|
|
653
|
+
return arrayTraps.set.call(this, state, prop, void 0);
|
|
654
|
+
};
|
|
655
|
+
arrayTraps.set = function(state, prop, value) {
|
|
656
|
+
if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
|
|
657
|
+
die(14);
|
|
658
|
+
return objectTraps.set.call(this, state[0], prop, value, state[0]);
|
|
659
|
+
};
|
|
660
|
+
function peek(draft, prop) {
|
|
661
|
+
const state = draft[DRAFT_STATE];
|
|
662
|
+
const source = state ? latest(state) : draft;
|
|
663
|
+
return source[prop];
|
|
664
|
+
}
|
|
665
|
+
function readPropFromProto(state, source, prop) {
|
|
666
|
+
const desc = getDescriptorFromProto(source, prop);
|
|
667
|
+
return desc ? VALUE in desc ? desc[VALUE] : (
|
|
668
|
+
// This is a very special case, if the prop is a getter defined by the
|
|
669
|
+
// prototype, we should invoke it with the draft as context!
|
|
670
|
+
desc.get?.call(state.draft_)
|
|
671
|
+
) : void 0;
|
|
672
|
+
}
|
|
673
|
+
function getDescriptorFromProto(source, prop) {
|
|
674
|
+
if (!(prop in source))
|
|
675
|
+
return void 0;
|
|
676
|
+
let proto = getPrototypeOf(source);
|
|
677
|
+
while (proto) {
|
|
678
|
+
const desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
679
|
+
if (desc)
|
|
680
|
+
return desc;
|
|
681
|
+
proto = getPrototypeOf(proto);
|
|
682
|
+
}
|
|
683
|
+
return void 0;
|
|
684
|
+
}
|
|
685
|
+
function markChanged(state) {
|
|
686
|
+
if (!state.modified_) {
|
|
687
|
+
state.modified_ = true;
|
|
688
|
+
if (state.parent_) {
|
|
689
|
+
markChanged(state.parent_);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
function prepareCopy(state) {
|
|
694
|
+
if (!state.copy_) {
|
|
695
|
+
state.assigned_ = /* @__PURE__ */ new Map();
|
|
696
|
+
state.copy_ = shallowCopy(
|
|
697
|
+
state.base_,
|
|
698
|
+
state.scope_.immer_.useStrictShallowCopy_
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
var Immer2 = class {
|
|
703
|
+
constructor(config) {
|
|
704
|
+
this.autoFreeze_ = true;
|
|
705
|
+
this.useStrictShallowCopy_ = false;
|
|
706
|
+
this.useStrictIteration_ = false;
|
|
707
|
+
this.produce = (base, recipe, patchListener) => {
|
|
708
|
+
if (isFunction(base) && !isFunction(recipe)) {
|
|
709
|
+
const defaultBase = recipe;
|
|
710
|
+
recipe = base;
|
|
711
|
+
const self = this;
|
|
712
|
+
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
713
|
+
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
if (!isFunction(recipe))
|
|
717
|
+
die(6);
|
|
718
|
+
if (patchListener !== void 0 && !isFunction(patchListener))
|
|
719
|
+
die(7);
|
|
720
|
+
let result;
|
|
721
|
+
if (isDraftable(base)) {
|
|
722
|
+
const scope = enterScope(this);
|
|
723
|
+
const proxy = createProxy(scope, base, void 0);
|
|
724
|
+
let hasError = true;
|
|
725
|
+
try {
|
|
726
|
+
result = recipe(proxy);
|
|
727
|
+
hasError = false;
|
|
728
|
+
} finally {
|
|
729
|
+
if (hasError)
|
|
730
|
+
revokeScope(scope);
|
|
731
|
+
else
|
|
732
|
+
leaveScope(scope);
|
|
733
|
+
}
|
|
734
|
+
usePatchesInScope(scope, patchListener);
|
|
735
|
+
return processResult(result, scope);
|
|
736
|
+
} else if (!base || !isObjectish(base)) {
|
|
737
|
+
result = recipe(base);
|
|
738
|
+
if (result === void 0)
|
|
739
|
+
result = base;
|
|
740
|
+
if (result === NOTHING)
|
|
741
|
+
result = void 0;
|
|
742
|
+
if (this.autoFreeze_)
|
|
743
|
+
freeze(result, true);
|
|
744
|
+
if (patchListener) {
|
|
745
|
+
const p = [];
|
|
746
|
+
const ip = [];
|
|
747
|
+
getPlugin(PluginPatches).generateReplacementPatches_(base, result, {
|
|
748
|
+
patches_: p,
|
|
749
|
+
inversePatches_: ip
|
|
750
|
+
});
|
|
751
|
+
patchListener(p, ip);
|
|
752
|
+
}
|
|
753
|
+
return result;
|
|
754
|
+
} else
|
|
755
|
+
die(1, base);
|
|
756
|
+
};
|
|
757
|
+
this.produceWithPatches = (base, recipe) => {
|
|
758
|
+
if (isFunction(base)) {
|
|
759
|
+
return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
760
|
+
}
|
|
761
|
+
let patches, inversePatches;
|
|
762
|
+
const result = this.produce(base, recipe, (p, ip) => {
|
|
763
|
+
patches = p;
|
|
764
|
+
inversePatches = ip;
|
|
765
|
+
});
|
|
766
|
+
return [result, patches, inversePatches];
|
|
767
|
+
};
|
|
768
|
+
if (isBoolean(config?.autoFreeze))
|
|
769
|
+
this.setAutoFreeze(config.autoFreeze);
|
|
770
|
+
if (isBoolean(config?.useStrictShallowCopy))
|
|
771
|
+
this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
772
|
+
if (isBoolean(config?.useStrictIteration))
|
|
773
|
+
this.setUseStrictIteration(config.useStrictIteration);
|
|
774
|
+
}
|
|
775
|
+
createDraft(base) {
|
|
776
|
+
if (!isDraftable(base))
|
|
777
|
+
die(8);
|
|
778
|
+
if (isDraft(base))
|
|
779
|
+
base = current(base);
|
|
780
|
+
const scope = enterScope(this);
|
|
781
|
+
const proxy = createProxy(scope, base, void 0);
|
|
782
|
+
proxy[DRAFT_STATE].isManual_ = true;
|
|
783
|
+
leaveScope(scope);
|
|
784
|
+
return proxy;
|
|
785
|
+
}
|
|
786
|
+
finishDraft(draft, patchListener) {
|
|
787
|
+
const state = draft && draft[DRAFT_STATE];
|
|
788
|
+
if (!state || !state.isManual_)
|
|
789
|
+
die(9);
|
|
790
|
+
const { scope_: scope } = state;
|
|
791
|
+
usePatchesInScope(scope, patchListener);
|
|
792
|
+
return processResult(void 0, scope);
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Pass true to automatically freeze all copies created by Immer.
|
|
796
|
+
*
|
|
797
|
+
* By default, auto-freezing is enabled.
|
|
798
|
+
*/
|
|
799
|
+
setAutoFreeze(value) {
|
|
800
|
+
this.autoFreeze_ = value;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Pass true to enable strict shallow copy.
|
|
804
|
+
*
|
|
805
|
+
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
806
|
+
*/
|
|
807
|
+
setUseStrictShallowCopy(value) {
|
|
808
|
+
this.useStrictShallowCopy_ = value;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Pass false to use faster iteration that skips non-enumerable properties
|
|
812
|
+
* but still handles symbols for compatibility.
|
|
813
|
+
*
|
|
814
|
+
* By default, strict iteration is enabled (includes all own properties).
|
|
815
|
+
*/
|
|
816
|
+
setUseStrictIteration(value) {
|
|
817
|
+
this.useStrictIteration_ = value;
|
|
818
|
+
}
|
|
819
|
+
shouldUseStrictIteration() {
|
|
820
|
+
return this.useStrictIteration_;
|
|
821
|
+
}
|
|
822
|
+
applyPatches(base, patches) {
|
|
823
|
+
let i;
|
|
824
|
+
for (i = patches.length - 1; i >= 0; i--) {
|
|
825
|
+
const patch = patches[i];
|
|
826
|
+
if (patch.path.length === 0 && patch.op === "replace") {
|
|
827
|
+
base = patch.value;
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (i > -1) {
|
|
832
|
+
patches = patches.slice(i + 1);
|
|
833
|
+
}
|
|
834
|
+
const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_;
|
|
835
|
+
if (isDraft(base)) {
|
|
836
|
+
return applyPatchesImpl(base, patches);
|
|
837
|
+
}
|
|
838
|
+
return this.produce(
|
|
839
|
+
base,
|
|
840
|
+
(draft) => applyPatchesImpl(draft, patches)
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
function createProxy(rootScope, value, parent, key) {
|
|
845
|
+
const [draft, state] = isMap(value) ? getPlugin(PluginMapSet).proxyMap_(value, parent) : isSet(value) ? getPlugin(PluginMapSet).proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
846
|
+
const scope = parent?.scope_ ?? getCurrentScope();
|
|
847
|
+
scope.drafts_.push(draft);
|
|
848
|
+
state.callbacks_ = parent?.callbacks_ ?? [];
|
|
849
|
+
state.key_ = key;
|
|
850
|
+
if (parent && key !== void 0) {
|
|
851
|
+
registerChildFinalizationCallback(parent, state, key);
|
|
852
|
+
} else {
|
|
853
|
+
state.callbacks_.push(function rootDraftCleanup(rootScope2) {
|
|
854
|
+
rootScope2.mapSetPlugin_?.fixSetContents(state);
|
|
855
|
+
const { patchPlugin_ } = rootScope2;
|
|
856
|
+
if (state.modified_ && patchPlugin_) {
|
|
857
|
+
patchPlugin_.generatePatches_(state, [], rootScope2);
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
return draft;
|
|
862
|
+
}
|
|
863
|
+
function current(value) {
|
|
864
|
+
if (!isDraft(value))
|
|
865
|
+
die(10, value);
|
|
866
|
+
return currentImpl(value);
|
|
867
|
+
}
|
|
868
|
+
function currentImpl(value) {
|
|
869
|
+
if (!isDraftable(value) || isFrozen(value))
|
|
870
|
+
return value;
|
|
871
|
+
const state = value[DRAFT_STATE];
|
|
872
|
+
let copy;
|
|
873
|
+
let strict = true;
|
|
874
|
+
if (state) {
|
|
875
|
+
if (!state.modified_)
|
|
876
|
+
return state.base_;
|
|
877
|
+
state.finalized_ = true;
|
|
878
|
+
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
879
|
+
strict = state.scope_.immer_.shouldUseStrictIteration();
|
|
880
|
+
} else {
|
|
881
|
+
copy = shallowCopy(value, true);
|
|
882
|
+
}
|
|
883
|
+
each(
|
|
884
|
+
copy,
|
|
885
|
+
(key, childValue) => {
|
|
886
|
+
set(copy, key, currentImpl(childValue));
|
|
887
|
+
},
|
|
888
|
+
strict
|
|
889
|
+
);
|
|
890
|
+
if (state) {
|
|
891
|
+
state.finalized_ = false;
|
|
892
|
+
}
|
|
893
|
+
return copy;
|
|
894
|
+
}
|
|
895
|
+
var immer = new Immer2();
|
|
896
|
+
var produce = immer.produce;
|
|
897
|
+
|
|
898
|
+
// node_modules/@reduxjs/toolkit/dist/redux-toolkit.modern.mjs
|
|
899
|
+
var composeWithDevTools = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function() {
|
|
900
|
+
if (arguments.length === 0) return void 0;
|
|
901
|
+
if (typeof arguments[0] === "object") return compose;
|
|
902
|
+
return compose.apply(null, arguments);
|
|
903
|
+
};
|
|
904
|
+
var devToolsEnhancer = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ : function() {
|
|
905
|
+
return function(noop3) {
|
|
906
|
+
return noop3;
|
|
907
|
+
};
|
|
908
|
+
};
|
|
909
|
+
var hasMatchFunction = (v) => {
|
|
910
|
+
return v && typeof v.match === "function";
|
|
911
|
+
};
|
|
912
|
+
function createAction(type, prepareAction) {
|
|
913
|
+
function actionCreator(...args) {
|
|
914
|
+
if (prepareAction) {
|
|
915
|
+
let prepared = prepareAction(...args);
|
|
916
|
+
if (!prepared) {
|
|
917
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(0) : "prepareAction did not return an object");
|
|
918
|
+
}
|
|
919
|
+
return {
|
|
920
|
+
type,
|
|
921
|
+
payload: prepared.payload,
|
|
922
|
+
..."meta" in prepared && {
|
|
923
|
+
meta: prepared.meta
|
|
924
|
+
},
|
|
925
|
+
..."error" in prepared && {
|
|
926
|
+
error: prepared.error
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
return {
|
|
931
|
+
type,
|
|
932
|
+
payload: args[0]
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
actionCreator.toString = () => `${type}`;
|
|
936
|
+
actionCreator.type = type;
|
|
937
|
+
actionCreator.match = (action) => isAction(action) && action.type === type;
|
|
938
|
+
return actionCreator;
|
|
939
|
+
}
|
|
940
|
+
function freezeDraftable(val) {
|
|
941
|
+
return isDraftable(val) ? produce(val, () => {
|
|
942
|
+
}) : val;
|
|
943
|
+
}
|
|
944
|
+
function getOrInsertComputed(map, key, compute) {
|
|
945
|
+
if (map.has(key)) return map.get(key);
|
|
946
|
+
return map.set(key, compute(key)).get(key);
|
|
947
|
+
}
|
|
948
|
+
function executeReducerBuilderCallback(builderCallback) {
|
|
949
|
+
const actionsMap = {};
|
|
950
|
+
const actionMatchers = [];
|
|
951
|
+
let defaultCaseReducer;
|
|
952
|
+
const builder = {
|
|
953
|
+
addCase(typeOrActionCreator, reducer) {
|
|
954
|
+
if (process.env.NODE_ENV !== "production") {
|
|
955
|
+
if (actionMatchers.length > 0) {
|
|
956
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(26) : "`builder.addCase` should only be called before calling `builder.addMatcher`");
|
|
957
|
+
}
|
|
958
|
+
if (defaultCaseReducer) {
|
|
959
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(27) : "`builder.addCase` should only be called before calling `builder.addDefaultCase`");
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
const type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
|
963
|
+
if (!type) {
|
|
964
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(28) : "`builder.addCase` cannot be called with an empty action type");
|
|
965
|
+
}
|
|
966
|
+
if (type in actionsMap) {
|
|
967
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(29) : `\`builder.addCase\` cannot be called with two reducers for the same action type '${type}'`);
|
|
968
|
+
}
|
|
969
|
+
actionsMap[type] = reducer;
|
|
970
|
+
return builder;
|
|
971
|
+
},
|
|
972
|
+
addAsyncThunk(asyncThunk, reducers) {
|
|
973
|
+
if (process.env.NODE_ENV !== "production") {
|
|
974
|
+
if (defaultCaseReducer) {
|
|
975
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(43) : "`builder.addAsyncThunk` should only be called before calling `builder.addDefaultCase`");
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
if (reducers.pending) actionsMap[asyncThunk.pending.type] = reducers.pending;
|
|
979
|
+
if (reducers.rejected) actionsMap[asyncThunk.rejected.type] = reducers.rejected;
|
|
980
|
+
if (reducers.fulfilled) actionsMap[asyncThunk.fulfilled.type] = reducers.fulfilled;
|
|
981
|
+
if (reducers.settled) actionMatchers.push({
|
|
982
|
+
matcher: asyncThunk.settled,
|
|
983
|
+
reducer: reducers.settled
|
|
984
|
+
});
|
|
985
|
+
return builder;
|
|
986
|
+
},
|
|
987
|
+
addMatcher(matcher, reducer) {
|
|
988
|
+
if (process.env.NODE_ENV !== "production") {
|
|
989
|
+
if (defaultCaseReducer) {
|
|
990
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(30) : "`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
actionMatchers.push({
|
|
994
|
+
matcher,
|
|
995
|
+
reducer
|
|
996
|
+
});
|
|
997
|
+
return builder;
|
|
998
|
+
},
|
|
999
|
+
addDefaultCase(reducer) {
|
|
1000
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1001
|
+
if (defaultCaseReducer) {
|
|
1002
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(31) : "`builder.addDefaultCase` can only be called once");
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
defaultCaseReducer = reducer;
|
|
1006
|
+
return builder;
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
builderCallback(builder);
|
|
1010
|
+
return [actionsMap, actionMatchers, defaultCaseReducer];
|
|
1011
|
+
}
|
|
1012
|
+
function isStateFunction(x) {
|
|
1013
|
+
return typeof x === "function";
|
|
1014
|
+
}
|
|
1015
|
+
function createReducer(initialState2, mapOrBuilderCallback) {
|
|
1016
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1017
|
+
if (typeof mapOrBuilderCallback === "object") {
|
|
1018
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(8) : "The object notation for `createReducer` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
let [actionsMap, finalActionMatchers, finalDefaultCaseReducer] = executeReducerBuilderCallback(mapOrBuilderCallback);
|
|
1022
|
+
let getInitialState;
|
|
1023
|
+
if (isStateFunction(initialState2)) {
|
|
1024
|
+
getInitialState = () => freezeDraftable(initialState2());
|
|
1025
|
+
} else {
|
|
1026
|
+
const frozenInitialState = freezeDraftable(initialState2);
|
|
1027
|
+
getInitialState = () => frozenInitialState;
|
|
1028
|
+
}
|
|
1029
|
+
function reducer(state = getInitialState(), action) {
|
|
1030
|
+
let caseReducers = [actionsMap[action.type], ...finalActionMatchers.filter(({
|
|
1031
|
+
matcher
|
|
1032
|
+
}) => matcher(action)).map(({
|
|
1033
|
+
reducer: reducer2
|
|
1034
|
+
}) => reducer2)];
|
|
1035
|
+
if (caseReducers.filter((cr) => !!cr).length === 0) {
|
|
1036
|
+
caseReducers = [finalDefaultCaseReducer];
|
|
1037
|
+
}
|
|
1038
|
+
return caseReducers.reduce((previousState, caseReducer) => {
|
|
1039
|
+
if (caseReducer) {
|
|
1040
|
+
if (isDraft(previousState)) {
|
|
1041
|
+
const draft = previousState;
|
|
1042
|
+
const result = caseReducer(draft, action);
|
|
1043
|
+
if (result === void 0) {
|
|
1044
|
+
return previousState;
|
|
1045
|
+
}
|
|
1046
|
+
return result;
|
|
1047
|
+
} else if (!isDraftable(previousState)) {
|
|
1048
|
+
const result = caseReducer(previousState, action);
|
|
1049
|
+
if (result === void 0) {
|
|
1050
|
+
if (previousState === null) {
|
|
1051
|
+
return previousState;
|
|
1052
|
+
}
|
|
1053
|
+
throw Error("A case reducer on a non-draftable value must not return undefined");
|
|
1054
|
+
}
|
|
1055
|
+
return result;
|
|
1056
|
+
} else {
|
|
1057
|
+
return produce(previousState, (draft) => {
|
|
1058
|
+
return caseReducer(draft, action);
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
return previousState;
|
|
1063
|
+
}, state);
|
|
1064
|
+
}
|
|
1065
|
+
reducer.getInitialState = getInitialState;
|
|
1066
|
+
return reducer;
|
|
1067
|
+
}
|
|
1068
|
+
var matches = (matcher, action) => {
|
|
1069
|
+
if (hasMatchFunction(matcher)) {
|
|
1070
|
+
return matcher.match(action);
|
|
1071
|
+
} else {
|
|
1072
|
+
return matcher(action);
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
function isAnyOf(...matchers) {
|
|
1076
|
+
return (action) => {
|
|
1077
|
+
return matchers.some((matcher) => matches(matcher, action));
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
var urlAlphabet = "ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW";
|
|
1081
|
+
var nanoid = (size = 21) => {
|
|
1082
|
+
let id = "";
|
|
1083
|
+
let i = size;
|
|
1084
|
+
while (i--) {
|
|
1085
|
+
id += urlAlphabet[Math.random() * 64 | 0];
|
|
1086
|
+
}
|
|
1087
|
+
return id;
|
|
1088
|
+
};
|
|
1089
|
+
var commonProperties = ["name", "message", "stack", "code"];
|
|
1090
|
+
var RejectWithValue = class {
|
|
1091
|
+
constructor(payload, meta) {
|
|
1092
|
+
__publicField(this, "payload");
|
|
1093
|
+
__publicField(this, "meta");
|
|
1094
|
+
/*
|
|
1095
|
+
type-only property to distinguish between RejectWithValue and FulfillWithMeta
|
|
1096
|
+
does not exist at runtime
|
|
1097
|
+
*/
|
|
1098
|
+
__publicField(this, "_type");
|
|
1099
|
+
this.payload = payload;
|
|
1100
|
+
this.meta = meta;
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
var FulfillWithMeta = class {
|
|
1104
|
+
constructor(payload, meta) {
|
|
1105
|
+
__publicField(this, "payload");
|
|
1106
|
+
__publicField(this, "meta");
|
|
1107
|
+
/*
|
|
1108
|
+
type-only property to distinguish between RejectWithValue and FulfillWithMeta
|
|
1109
|
+
does not exist at runtime
|
|
1110
|
+
*/
|
|
1111
|
+
__publicField(this, "_type");
|
|
1112
|
+
this.payload = payload;
|
|
1113
|
+
this.meta = meta;
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
var miniSerializeError = (value) => {
|
|
1117
|
+
if (typeof value === "object" && value !== null) {
|
|
1118
|
+
const simpleError = {};
|
|
1119
|
+
for (const property of commonProperties) {
|
|
1120
|
+
if (typeof value[property] === "string") {
|
|
1121
|
+
simpleError[property] = value[property];
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return simpleError;
|
|
1125
|
+
}
|
|
1126
|
+
return {
|
|
1127
|
+
message: String(value)
|
|
1128
|
+
};
|
|
1129
|
+
};
|
|
1130
|
+
var externalAbortMessage = "External signal was aborted";
|
|
1131
|
+
var createAsyncThunk = /* @__PURE__ */ (() => {
|
|
1132
|
+
function createAsyncThunk2(typePrefix, payloadCreator, options) {
|
|
1133
|
+
const fulfilled = createAction(typePrefix + "/fulfilled", (payload, requestId, arg, meta) => ({
|
|
1134
|
+
payload,
|
|
1135
|
+
meta: {
|
|
1136
|
+
...meta || {},
|
|
1137
|
+
arg,
|
|
1138
|
+
requestId,
|
|
1139
|
+
requestStatus: "fulfilled"
|
|
1140
|
+
}
|
|
1141
|
+
}));
|
|
1142
|
+
const pending = createAction(typePrefix + "/pending", (requestId, arg, meta) => ({
|
|
1143
|
+
payload: void 0,
|
|
1144
|
+
meta: {
|
|
1145
|
+
...meta || {},
|
|
1146
|
+
arg,
|
|
1147
|
+
requestId,
|
|
1148
|
+
requestStatus: "pending"
|
|
1149
|
+
}
|
|
1150
|
+
}));
|
|
1151
|
+
const rejected = createAction(typePrefix + "/rejected", (error, requestId, arg, payload, meta) => ({
|
|
1152
|
+
payload,
|
|
1153
|
+
error: (options && options.serializeError || miniSerializeError)(error || "Rejected"),
|
|
1154
|
+
meta: {
|
|
1155
|
+
...meta || {},
|
|
1156
|
+
arg,
|
|
1157
|
+
requestId,
|
|
1158
|
+
rejectedWithValue: !!payload,
|
|
1159
|
+
requestStatus: "rejected",
|
|
1160
|
+
aborted: error?.name === "AbortError",
|
|
1161
|
+
condition: error?.name === "ConditionError"
|
|
1162
|
+
}
|
|
1163
|
+
}));
|
|
1164
|
+
function actionCreator(arg, {
|
|
1165
|
+
signal
|
|
1166
|
+
} = {}) {
|
|
1167
|
+
return (dispatch, getState, extra) => {
|
|
1168
|
+
const requestId = options?.idGenerator ? options.idGenerator(arg) : nanoid();
|
|
1169
|
+
const abortController = new AbortController();
|
|
1170
|
+
let abortHandler;
|
|
1171
|
+
let abortReason;
|
|
1172
|
+
function abort(reason) {
|
|
1173
|
+
abortReason = reason;
|
|
1174
|
+
abortController.abort();
|
|
1175
|
+
}
|
|
1176
|
+
if (signal) {
|
|
1177
|
+
if (signal.aborted) {
|
|
1178
|
+
abort(externalAbortMessage);
|
|
1179
|
+
} else {
|
|
1180
|
+
signal.addEventListener("abort", () => abort(externalAbortMessage), {
|
|
1181
|
+
once: true
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
const promise = (async function() {
|
|
1186
|
+
let finalAction;
|
|
1187
|
+
try {
|
|
1188
|
+
let conditionResult = options?.condition?.(arg, {
|
|
1189
|
+
getState,
|
|
1190
|
+
extra
|
|
1191
|
+
});
|
|
1192
|
+
if (isThenable(conditionResult)) {
|
|
1193
|
+
conditionResult = await conditionResult;
|
|
1194
|
+
}
|
|
1195
|
+
if (conditionResult === false || abortController.signal.aborted) {
|
|
1196
|
+
throw {
|
|
1197
|
+
name: "ConditionError",
|
|
1198
|
+
message: "Aborted due to condition callback returning false."
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
const abortedPromise = new Promise((_, reject) => {
|
|
1202
|
+
abortHandler = () => {
|
|
1203
|
+
reject({
|
|
1204
|
+
name: "AbortError",
|
|
1205
|
+
message: abortReason || "Aborted"
|
|
1206
|
+
});
|
|
1207
|
+
};
|
|
1208
|
+
abortController.signal.addEventListener("abort", abortHandler, {
|
|
1209
|
+
once: true
|
|
1210
|
+
});
|
|
1211
|
+
});
|
|
1212
|
+
dispatch(pending(requestId, arg, options?.getPendingMeta?.({
|
|
1213
|
+
requestId,
|
|
1214
|
+
arg
|
|
1215
|
+
}, {
|
|
1216
|
+
getState,
|
|
1217
|
+
extra
|
|
1218
|
+
})));
|
|
1219
|
+
finalAction = await Promise.race([abortedPromise, Promise.resolve(payloadCreator(arg, {
|
|
1220
|
+
dispatch,
|
|
1221
|
+
getState,
|
|
1222
|
+
extra,
|
|
1223
|
+
requestId,
|
|
1224
|
+
signal: abortController.signal,
|
|
1225
|
+
abort,
|
|
1226
|
+
rejectWithValue: ((value, meta) => {
|
|
1227
|
+
return new RejectWithValue(value, meta);
|
|
1228
|
+
}),
|
|
1229
|
+
fulfillWithValue: ((value, meta) => {
|
|
1230
|
+
return new FulfillWithMeta(value, meta);
|
|
1231
|
+
})
|
|
1232
|
+
})).then((result) => {
|
|
1233
|
+
if (result instanceof RejectWithValue) {
|
|
1234
|
+
throw result;
|
|
1235
|
+
}
|
|
1236
|
+
if (result instanceof FulfillWithMeta) {
|
|
1237
|
+
return fulfilled(result.payload, requestId, arg, result.meta);
|
|
1238
|
+
}
|
|
1239
|
+
return fulfilled(result, requestId, arg);
|
|
1240
|
+
})]);
|
|
1241
|
+
} catch (err) {
|
|
1242
|
+
finalAction = err instanceof RejectWithValue ? rejected(null, requestId, arg, err.payload, err.meta) : rejected(err, requestId, arg);
|
|
1243
|
+
} finally {
|
|
1244
|
+
if (abortHandler) {
|
|
1245
|
+
abortController.signal.removeEventListener("abort", abortHandler);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
const skipDispatch = options && !options.dispatchConditionRejection && rejected.match(finalAction) && finalAction.meta.condition;
|
|
1249
|
+
if (!skipDispatch) {
|
|
1250
|
+
dispatch(finalAction);
|
|
1251
|
+
}
|
|
1252
|
+
return finalAction;
|
|
1253
|
+
})();
|
|
1254
|
+
return Object.assign(promise, {
|
|
1255
|
+
abort,
|
|
1256
|
+
requestId,
|
|
1257
|
+
arg,
|
|
1258
|
+
unwrap() {
|
|
1259
|
+
return promise.then(unwrapResult);
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
return Object.assign(actionCreator, {
|
|
1265
|
+
pending,
|
|
1266
|
+
rejected,
|
|
1267
|
+
fulfilled,
|
|
1268
|
+
settled: isAnyOf(rejected, fulfilled),
|
|
1269
|
+
typePrefix
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
createAsyncThunk2.withTypes = () => createAsyncThunk2;
|
|
1273
|
+
return createAsyncThunk2;
|
|
1274
|
+
})();
|
|
1275
|
+
function unwrapResult(action) {
|
|
1276
|
+
if (action.meta && action.meta.rejectedWithValue) {
|
|
1277
|
+
throw action.payload;
|
|
1278
|
+
}
|
|
1279
|
+
if (action.error) {
|
|
1280
|
+
throw action.error;
|
|
1281
|
+
}
|
|
1282
|
+
return action.payload;
|
|
1283
|
+
}
|
|
1284
|
+
function isThenable(value) {
|
|
1285
|
+
return value !== null && typeof value === "object" && typeof value.then === "function";
|
|
1286
|
+
}
|
|
1287
|
+
var asyncThunkSymbol = /* @__PURE__ */ Symbol.for("rtk-slice-createasyncthunk");
|
|
1288
|
+
var asyncThunkCreator = {
|
|
1289
|
+
[asyncThunkSymbol]: createAsyncThunk
|
|
1290
|
+
};
|
|
1291
|
+
function getType(slice2, actionKey) {
|
|
1292
|
+
return `${slice2}/${actionKey}`;
|
|
1293
|
+
}
|
|
1294
|
+
function buildCreateSlice({
|
|
1295
|
+
creators
|
|
1296
|
+
} = {}) {
|
|
1297
|
+
const cAT = creators?.asyncThunk?.[asyncThunkSymbol];
|
|
1298
|
+
return function createSlice2(options) {
|
|
1299
|
+
const {
|
|
1300
|
+
name,
|
|
1301
|
+
reducerPath = name
|
|
1302
|
+
} = options;
|
|
1303
|
+
if (!name) {
|
|
1304
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(11) : "`name` is a required option for createSlice");
|
|
1305
|
+
}
|
|
1306
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
1307
|
+
if (options.initialState === void 0) {
|
|
1308
|
+
console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
const reducers = (typeof options.reducers === "function" ? options.reducers(buildReducerCreators()) : options.reducers) || {};
|
|
1312
|
+
const reducerNames = Object.keys(reducers);
|
|
1313
|
+
const context = {
|
|
1314
|
+
sliceCaseReducersByName: {},
|
|
1315
|
+
sliceCaseReducersByType: {},
|
|
1316
|
+
actionCreators: {},
|
|
1317
|
+
sliceMatchers: []
|
|
1318
|
+
};
|
|
1319
|
+
const contextMethods = {
|
|
1320
|
+
addCase(typeOrActionCreator, reducer2) {
|
|
1321
|
+
const type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
|
1322
|
+
if (!type) {
|
|
1323
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : "`context.addCase` cannot be called with an empty action type");
|
|
1324
|
+
}
|
|
1325
|
+
if (type in context.sliceCaseReducersByType) {
|
|
1326
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : "`context.addCase` cannot be called with two reducers for the same action type: " + type);
|
|
1327
|
+
}
|
|
1328
|
+
context.sliceCaseReducersByType[type] = reducer2;
|
|
1329
|
+
return contextMethods;
|
|
1330
|
+
},
|
|
1331
|
+
addMatcher(matcher, reducer2) {
|
|
1332
|
+
context.sliceMatchers.push({
|
|
1333
|
+
matcher,
|
|
1334
|
+
reducer: reducer2
|
|
1335
|
+
});
|
|
1336
|
+
return contextMethods;
|
|
1337
|
+
},
|
|
1338
|
+
exposeAction(name2, actionCreator) {
|
|
1339
|
+
context.actionCreators[name2] = actionCreator;
|
|
1340
|
+
return contextMethods;
|
|
1341
|
+
},
|
|
1342
|
+
exposeCaseReducer(name2, reducer2) {
|
|
1343
|
+
context.sliceCaseReducersByName[name2] = reducer2;
|
|
1344
|
+
return contextMethods;
|
|
1345
|
+
}
|
|
1346
|
+
};
|
|
1347
|
+
reducerNames.forEach((reducerName) => {
|
|
1348
|
+
const reducerDefinition = reducers[reducerName];
|
|
1349
|
+
const reducerDetails = {
|
|
1350
|
+
reducerName,
|
|
1351
|
+
type: getType(name, reducerName),
|
|
1352
|
+
createNotation: typeof options.reducers === "function"
|
|
1353
|
+
};
|
|
1354
|
+
if (isAsyncThunkSliceReducerDefinition(reducerDefinition)) {
|
|
1355
|
+
handleThunkCaseReducerDefinition(reducerDetails, reducerDefinition, contextMethods, cAT);
|
|
1356
|
+
} else {
|
|
1357
|
+
handleNormalReducerDefinition(reducerDetails, reducerDefinition, contextMethods);
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1360
|
+
function buildReducer() {
|
|
1361
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1362
|
+
if (typeof options.extraReducers === "object") {
|
|
1363
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : "The object notation for `createSlice.extraReducers` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createSlice");
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
const [extraReducers = {}, actionMatchers = [], defaultCaseReducer = void 0] = typeof options.extraReducers === "function" ? executeReducerBuilderCallback(options.extraReducers) : [options.extraReducers];
|
|
1367
|
+
const finalCaseReducers = {
|
|
1368
|
+
...extraReducers,
|
|
1369
|
+
...context.sliceCaseReducersByType
|
|
1370
|
+
};
|
|
1371
|
+
return createReducer(options.initialState, (builder) => {
|
|
1372
|
+
for (let key in finalCaseReducers) {
|
|
1373
|
+
builder.addCase(key, finalCaseReducers[key]);
|
|
1374
|
+
}
|
|
1375
|
+
for (let sM of context.sliceMatchers) {
|
|
1376
|
+
builder.addMatcher(sM.matcher, sM.reducer);
|
|
1377
|
+
}
|
|
1378
|
+
for (let m of actionMatchers) {
|
|
1379
|
+
builder.addMatcher(m.matcher, m.reducer);
|
|
1380
|
+
}
|
|
1381
|
+
if (defaultCaseReducer) {
|
|
1382
|
+
builder.addDefaultCase(defaultCaseReducer);
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
const selectSelf = (state) => state;
|
|
1387
|
+
const injectedSelectorCache = /* @__PURE__ */ new Map();
|
|
1388
|
+
const injectedStateCache = /* @__PURE__ */ new WeakMap();
|
|
1389
|
+
let _reducer;
|
|
1390
|
+
function reducer(state, action) {
|
|
1391
|
+
if (!_reducer) _reducer = buildReducer();
|
|
1392
|
+
return _reducer(state, action);
|
|
1393
|
+
}
|
|
1394
|
+
function getInitialState() {
|
|
1395
|
+
if (!_reducer) _reducer = buildReducer();
|
|
1396
|
+
return _reducer.getInitialState();
|
|
1397
|
+
}
|
|
1398
|
+
function makeSelectorProps(reducerPath2, injected = false) {
|
|
1399
|
+
function selectSlice(state) {
|
|
1400
|
+
let sliceState = state[reducerPath2];
|
|
1401
|
+
if (typeof sliceState === "undefined") {
|
|
1402
|
+
if (injected) {
|
|
1403
|
+
sliceState = getOrInsertComputed(injectedStateCache, selectSlice, getInitialState);
|
|
1404
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
1405
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(15) : "selectSlice returned undefined for an uninjected slice reducer");
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
return sliceState;
|
|
1409
|
+
}
|
|
1410
|
+
function getSelectors(selectState = selectSelf) {
|
|
1411
|
+
const selectorCache = getOrInsertComputed(injectedSelectorCache, injected, () => /* @__PURE__ */ new WeakMap());
|
|
1412
|
+
return getOrInsertComputed(selectorCache, selectState, () => {
|
|
1413
|
+
const map = {};
|
|
1414
|
+
for (const [name2, selector] of Object.entries(options.selectors ?? {})) {
|
|
1415
|
+
map[name2] = wrapSelector(selector, selectState, () => getOrInsertComputed(injectedStateCache, selectState, getInitialState), injected);
|
|
1416
|
+
}
|
|
1417
|
+
return map;
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
return {
|
|
1421
|
+
reducerPath: reducerPath2,
|
|
1422
|
+
getSelectors,
|
|
1423
|
+
get selectors() {
|
|
1424
|
+
return getSelectors(selectSlice);
|
|
1425
|
+
},
|
|
1426
|
+
selectSlice
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
const slice2 = {
|
|
1430
|
+
name,
|
|
1431
|
+
reducer,
|
|
1432
|
+
actions: context.actionCreators,
|
|
1433
|
+
caseReducers: context.sliceCaseReducersByName,
|
|
1434
|
+
getInitialState,
|
|
1435
|
+
...makeSelectorProps(reducerPath),
|
|
1436
|
+
injectInto(injectable, {
|
|
1437
|
+
reducerPath: pathOpt,
|
|
1438
|
+
...config
|
|
1439
|
+
} = {}) {
|
|
1440
|
+
const newReducerPath = pathOpt ?? reducerPath;
|
|
1441
|
+
injectable.inject({
|
|
1442
|
+
reducerPath: newReducerPath,
|
|
1443
|
+
reducer
|
|
1444
|
+
}, config);
|
|
1445
|
+
return {
|
|
1446
|
+
...slice2,
|
|
1447
|
+
...makeSelectorProps(newReducerPath, true)
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1451
|
+
return slice2;
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
function wrapSelector(selector, selectState, getInitialState, injected) {
|
|
1455
|
+
function wrapper(rootState, ...args) {
|
|
1456
|
+
let sliceState = selectState(rootState);
|
|
1457
|
+
if (typeof sliceState === "undefined") {
|
|
1458
|
+
if (injected) {
|
|
1459
|
+
sliceState = getInitialState();
|
|
1460
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
1461
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(16) : "selectState returned undefined for an uninjected slice reducer");
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
return selector(sliceState, ...args);
|
|
1465
|
+
}
|
|
1466
|
+
wrapper.unwrapped = selector;
|
|
1467
|
+
return wrapper;
|
|
1468
|
+
}
|
|
1469
|
+
var createSlice = /* @__PURE__ */ buildCreateSlice();
|
|
1470
|
+
function buildReducerCreators() {
|
|
1471
|
+
function asyncThunk(payloadCreator, config) {
|
|
1472
|
+
return {
|
|
1473
|
+
_reducerDefinitionType: "asyncThunk",
|
|
1474
|
+
payloadCreator,
|
|
1475
|
+
...config
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
asyncThunk.withTypes = () => asyncThunk;
|
|
1479
|
+
return {
|
|
1480
|
+
reducer(caseReducer) {
|
|
1481
|
+
return Object.assign({
|
|
1482
|
+
// hack so the wrapping function has the same name as the original
|
|
1483
|
+
// we need to create a wrapper so the `reducerDefinitionType` is not assigned to the original
|
|
1484
|
+
[caseReducer.name](...args) {
|
|
1485
|
+
return caseReducer(...args);
|
|
1486
|
+
}
|
|
1487
|
+
}[caseReducer.name], {
|
|
1488
|
+
_reducerDefinitionType: "reducer"
|
|
1489
|
+
/* reducer */
|
|
1490
|
+
});
|
|
1491
|
+
},
|
|
1492
|
+
preparedReducer(prepare, reducer) {
|
|
1493
|
+
return {
|
|
1494
|
+
_reducerDefinitionType: "reducerWithPrepare",
|
|
1495
|
+
prepare,
|
|
1496
|
+
reducer
|
|
1497
|
+
};
|
|
1498
|
+
},
|
|
1499
|
+
asyncThunk
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
function handleNormalReducerDefinition({
|
|
1503
|
+
type,
|
|
1504
|
+
reducerName,
|
|
1505
|
+
createNotation
|
|
1506
|
+
}, maybeReducerWithPrepare, context) {
|
|
1507
|
+
let caseReducer;
|
|
1508
|
+
let prepareCallback;
|
|
1509
|
+
if ("reducer" in maybeReducerWithPrepare) {
|
|
1510
|
+
if (createNotation && !isCaseReducerWithPrepareDefinition(maybeReducerWithPrepare)) {
|
|
1511
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(17) : "Please use the `create.preparedReducer` notation for prepared action creators with the `create` notation.");
|
|
1512
|
+
}
|
|
1513
|
+
caseReducer = maybeReducerWithPrepare.reducer;
|
|
1514
|
+
prepareCallback = maybeReducerWithPrepare.prepare;
|
|
1515
|
+
} else {
|
|
1516
|
+
caseReducer = maybeReducerWithPrepare;
|
|
1517
|
+
}
|
|
1518
|
+
context.addCase(type, caseReducer).exposeCaseReducer(reducerName, caseReducer).exposeAction(reducerName, prepareCallback ? createAction(type, prepareCallback) : createAction(type));
|
|
1519
|
+
}
|
|
1520
|
+
function isAsyncThunkSliceReducerDefinition(reducerDefinition) {
|
|
1521
|
+
return reducerDefinition._reducerDefinitionType === "asyncThunk";
|
|
1522
|
+
}
|
|
1523
|
+
function isCaseReducerWithPrepareDefinition(reducerDefinition) {
|
|
1524
|
+
return reducerDefinition._reducerDefinitionType === "reducerWithPrepare";
|
|
1525
|
+
}
|
|
1526
|
+
function handleThunkCaseReducerDefinition({
|
|
1527
|
+
type,
|
|
1528
|
+
reducerName
|
|
1529
|
+
}, reducerDefinition, context, cAT) {
|
|
1530
|
+
if (!cAT) {
|
|
1531
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(18) : "Cannot use `create.asyncThunk` in the built-in `createSlice`. Use `buildCreateSlice({ creators: { asyncThunk: asyncThunkCreator } })` to create a customised version of `createSlice`.");
|
|
1532
|
+
}
|
|
1533
|
+
const {
|
|
1534
|
+
payloadCreator,
|
|
1535
|
+
fulfilled,
|
|
1536
|
+
pending,
|
|
1537
|
+
rejected,
|
|
1538
|
+
settled,
|
|
1539
|
+
options
|
|
1540
|
+
} = reducerDefinition;
|
|
1541
|
+
const thunk = cAT(type, payloadCreator, options);
|
|
1542
|
+
context.exposeAction(reducerName, thunk);
|
|
1543
|
+
if (fulfilled) {
|
|
1544
|
+
context.addCase(thunk.fulfilled, fulfilled);
|
|
1545
|
+
}
|
|
1546
|
+
if (pending) {
|
|
1547
|
+
context.addCase(thunk.pending, pending);
|
|
1548
|
+
}
|
|
1549
|
+
if (rejected) {
|
|
1550
|
+
context.addCase(thunk.rejected, rejected);
|
|
1551
|
+
}
|
|
1552
|
+
if (settled) {
|
|
1553
|
+
context.addMatcher(thunk.settled, settled);
|
|
1554
|
+
}
|
|
1555
|
+
context.exposeCaseReducer(reducerName, {
|
|
1556
|
+
fulfilled: fulfilled || noop,
|
|
1557
|
+
pending: pending || noop,
|
|
1558
|
+
rejected: rejected || noop,
|
|
1559
|
+
settled: settled || noop
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1562
|
+
function noop() {
|
|
1563
|
+
}
|
|
1564
|
+
var listener = "listener";
|
|
1565
|
+
var completed = "completed";
|
|
1566
|
+
var cancelled = "cancelled";
|
|
1567
|
+
var taskCancelled = `task-${cancelled}`;
|
|
1568
|
+
var taskCompleted = `task-${completed}`;
|
|
1569
|
+
var listenerCancelled = `${listener}-${cancelled}`;
|
|
1570
|
+
var listenerCompleted = `${listener}-${completed}`;
|
|
1571
|
+
var {
|
|
1572
|
+
assign
|
|
1573
|
+
} = Object;
|
|
1574
|
+
var alm = "listenerMiddleware";
|
|
1575
|
+
var addListener = /* @__PURE__ */ assign(/* @__PURE__ */ createAction(`${alm}/add`), {
|
|
1576
|
+
withTypes: () => addListener
|
|
1577
|
+
});
|
|
1578
|
+
var clearAllListeners = /* @__PURE__ */ createAction(`${alm}/removeAll`);
|
|
1579
|
+
var removeListener = /* @__PURE__ */ assign(/* @__PURE__ */ createAction(`${alm}/remove`), {
|
|
1580
|
+
withTypes: () => removeListener
|
|
1581
|
+
});
|
|
1582
|
+
function formatProdErrorMessage(code) {
|
|
1583
|
+
return `Minified Redux Toolkit error #${code}; visit https://redux-toolkit.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
// src/redux/themeSlice.ts
|
|
1587
|
+
var initialState = {
|
|
1588
|
+
appearance: "system",
|
|
1589
|
+
color: "#6750a4"
|
|
1590
|
+
};
|
|
1591
|
+
var slice = createSlice({
|
|
1592
|
+
name: "theme",
|
|
1593
|
+
initialState,
|
|
1594
|
+
reducers: {
|
|
1595
|
+
initialize: (state, action) => ({ ...state, ...action.payload }),
|
|
1596
|
+
setAppearance: (state, action) => ({ ...state, appearance: action.payload }),
|
|
1597
|
+
setColor: (state, action) => ({ ...state, color: action.payload })
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
var themeActions = slice.actions;
|
|
1601
|
+
var themeReducer = slice.reducer;
|
|
1602
|
+
|
|
1603
|
+
// src/ThemeProvider.tsx
|
|
1604
|
+
var SplashScreen2 = __toESM(require("expo-splash-screen"));
|
|
1605
|
+
var import_react_native2 = require("react-native");
|
|
1606
|
+
var import_react_native_paper2 = require("react-native-paper");
|
|
1607
|
+
|
|
1608
|
+
// src/useComputedTheme.ts
|
|
1609
|
+
var SplashScreen = __toESM(require("expo-splash-screen"));
|
|
1610
|
+
var import_react = require("react");
|
|
1611
|
+
var import_react_native = require("react-native");
|
|
1612
|
+
var import_react_native_paper = require("react-native-paper");
|
|
1613
|
+
|
|
1614
|
+
// src/utils/colorNames.ts
|
|
1615
|
+
var colorNames = {
|
|
1616
|
+
aliceblue: "#f0f8ff",
|
|
1617
|
+
antiquewhite: "#faebd7",
|
|
1618
|
+
aqua: "#00ffff",
|
|
1619
|
+
aquamarine: "#7fffd4",
|
|
1620
|
+
azure: "#f0ffff",
|
|
1621
|
+
beige: "#f5f5dc",
|
|
1622
|
+
bisque: "#ffe4c4",
|
|
1623
|
+
black: "#000000",
|
|
1624
|
+
blanchedalmond: "#ffebcd",
|
|
1625
|
+
blue: "#0000ff",
|
|
1626
|
+
blueviolet: "#8a2be2",
|
|
1627
|
+
brown: "#a52a2a",
|
|
1628
|
+
burlywood: "#deb887",
|
|
1629
|
+
cadetblue: "#5f9ea0",
|
|
1630
|
+
chartreuse: "#7fff00",
|
|
1631
|
+
chocolate: "#d2691e",
|
|
1632
|
+
coral: "#ff7f50",
|
|
1633
|
+
cornflowerblue: "#6495ed",
|
|
1634
|
+
cornsilk: "#fff8dc",
|
|
1635
|
+
crimson: "#dc143c",
|
|
1636
|
+
cyan: "#00ffff",
|
|
1637
|
+
darkblue: "#00008b",
|
|
1638
|
+
darkcyan: "#008b8b",
|
|
1639
|
+
darkgoldenrod: "#b8860b",
|
|
1640
|
+
darkgray: "#a9a9a9",
|
|
1641
|
+
darkgrey: "#a9a9a9",
|
|
1642
|
+
darkgreen: "#006400",
|
|
1643
|
+
darkkhaki: "#bdb76b",
|
|
1644
|
+
darkmagenta: "#8b008b",
|
|
1645
|
+
darkolivegreen: "#556b2f",
|
|
1646
|
+
darkorange: "#ff8c00",
|
|
1647
|
+
darkorchid: "#9932cc",
|
|
1648
|
+
darkred: "#8b0000",
|
|
1649
|
+
darksalmon: "#e9967a",
|
|
1650
|
+
darkseagreen: "#8fbc8f",
|
|
1651
|
+
darkslateblue: "#483d8b",
|
|
1652
|
+
darkslategray: "#2f4f4f",
|
|
1653
|
+
darkslategrey: "#2f4f4f",
|
|
1654
|
+
darkturquoise: "#00ced1",
|
|
1655
|
+
darkviolet: "#9400d3",
|
|
1656
|
+
deeppink: "#ff1493",
|
|
1657
|
+
deepskyblue: "#00bfff",
|
|
1658
|
+
dimgray: "#696969",
|
|
1659
|
+
dimgrey: "#696969",
|
|
1660
|
+
dodgerblue: "#1e90ff",
|
|
1661
|
+
firebrick: "#b22222",
|
|
1662
|
+
floralwhite: "#fffaf0",
|
|
1663
|
+
forestgreen: "#228b22",
|
|
1664
|
+
fuchsia: "#ff00ff",
|
|
1665
|
+
gainsboro: "#dcdcdc",
|
|
1666
|
+
ghostwhite: "#f8f8ff",
|
|
1667
|
+
gold: "#ffd700",
|
|
1668
|
+
goldenrod: "#daa520",
|
|
1669
|
+
gray: "#808080",
|
|
1670
|
+
grey: "#808080",
|
|
1671
|
+
green: "#008000",
|
|
1672
|
+
greenyellow: "#adff2f",
|
|
1673
|
+
honeydew: "#f0fff0",
|
|
1674
|
+
hotpink: "#ff69b4",
|
|
1675
|
+
indianred: "#cd5c5c",
|
|
1676
|
+
indigo: "#4b0082",
|
|
1677
|
+
ivory: "#fffff0",
|
|
1678
|
+
khaki: "#f0e68c",
|
|
1679
|
+
lavender: "#e6e6fa",
|
|
1680
|
+
lavenderblush: "#fff0f5",
|
|
1681
|
+
lawngreen: "#7cfc00",
|
|
1682
|
+
lemonchiffon: "#fffacd",
|
|
1683
|
+
lightblue: "#add8e6",
|
|
1684
|
+
lightcoral: "#f08080",
|
|
1685
|
+
lightcyan: "#e0ffff",
|
|
1686
|
+
lightgoldenrodyellow: "#fafad2",
|
|
1687
|
+
lightgray: "#d3d3d3",
|
|
1688
|
+
lightgrey: "#d3d3d3",
|
|
1689
|
+
lightgreen: "#90ee90",
|
|
1690
|
+
lightpink: "#ffb6c1",
|
|
1691
|
+
lightsalmon: "#ffa07a",
|
|
1692
|
+
lightseagreen: "#20b2aa",
|
|
1693
|
+
lightskyblue: "#87cefa",
|
|
1694
|
+
lightslategray: "#778899",
|
|
1695
|
+
lightslategrey: "#778899",
|
|
1696
|
+
lightsteelblue: "#b0c4de",
|
|
1697
|
+
lightyellow: "#ffffe0",
|
|
1698
|
+
lime: "#00ff00",
|
|
1699
|
+
limegreen: "#32cd32",
|
|
1700
|
+
linen: "#faf0e6",
|
|
1701
|
+
magenta: "#ff00ff",
|
|
1702
|
+
maroon: "#800000",
|
|
1703
|
+
mediumaquamarine: "#66cdaa",
|
|
1704
|
+
mediumblue: "#0000cd",
|
|
1705
|
+
mediumorchid: "#ba55d3",
|
|
1706
|
+
mediumpurple: "#9370db",
|
|
1707
|
+
mediumseagreen: "#3cb371",
|
|
1708
|
+
mediumslateblue: "#7b68ee",
|
|
1709
|
+
mediumspringgreen: "#00fa9a",
|
|
1710
|
+
mediumturquoise: "#48d1cc",
|
|
1711
|
+
mediumvioletred: "#c71585",
|
|
1712
|
+
midnightblue: "#191970",
|
|
1713
|
+
mintcream: "#f5fffa",
|
|
1714
|
+
mistyrose: "#ffe4e1",
|
|
1715
|
+
moccasin: "#ffe4b5",
|
|
1716
|
+
navajowhite: "#ffdead",
|
|
1717
|
+
navy: "#000080",
|
|
1718
|
+
oldlace: "#fdf5e6",
|
|
1719
|
+
olive: "#808000",
|
|
1720
|
+
olivedrab: "#6b8e23",
|
|
1721
|
+
orange: "#ffa500",
|
|
1722
|
+
orangered: "#ff4500",
|
|
1723
|
+
orchid: "#da70d6",
|
|
1724
|
+
palegoldenrod: "#eee8aa",
|
|
1725
|
+
palegreen: "#98fb98",
|
|
1726
|
+
paleturquoise: "#afeeee",
|
|
1727
|
+
palevioletred: "#db7093",
|
|
1728
|
+
papayawhip: "#ffefd5",
|
|
1729
|
+
peachpuff: "#ffdab9",
|
|
1730
|
+
peru: "#cd853f",
|
|
1731
|
+
pink: "#ffc0cb",
|
|
1732
|
+
plum: "#dda0dd",
|
|
1733
|
+
powderblue: "#b0e0e6",
|
|
1734
|
+
purple: "#800080",
|
|
1735
|
+
rebeccapurple: "#663399",
|
|
1736
|
+
red: "#ff0000",
|
|
1737
|
+
rosybrown: "#bc8f8f",
|
|
1738
|
+
royalblue: "#4169e1",
|
|
1739
|
+
saddlebrown: "#8b4513",
|
|
1740
|
+
salmon: "#fa8072",
|
|
1741
|
+
sandybrown: "#f4a460",
|
|
1742
|
+
seagreen: "#2e8b57",
|
|
1743
|
+
seashell: "#fff5ee",
|
|
1744
|
+
sienna: "#a0522d",
|
|
1745
|
+
silver: "#c0c0c0",
|
|
1746
|
+
skyblue: "#87ceeb",
|
|
1747
|
+
slateblue: "#6a5acd",
|
|
1748
|
+
slategray: "#708090",
|
|
1749
|
+
slategrey: "#708090",
|
|
1750
|
+
snow: "#fffafa",
|
|
1751
|
+
springgreen: "#00ff7f",
|
|
1752
|
+
steelblue: "#4682b4",
|
|
1753
|
+
tan: "#d2b48c",
|
|
1754
|
+
teal: "#008080",
|
|
1755
|
+
thistle: "#d8bfd8",
|
|
1756
|
+
tomato: "#ff6347",
|
|
1757
|
+
transparent: "transparent",
|
|
1758
|
+
turquoise: "#40e0d0",
|
|
1759
|
+
violet: "#ee82ee",
|
|
1760
|
+
wheat: "#f5deb3",
|
|
1761
|
+
white: "#ffffff",
|
|
1762
|
+
whitesmoke: "#f5f5f5",
|
|
1763
|
+
yellow: "#ffff00",
|
|
1764
|
+
yellowgreen: "#9acd32"
|
|
1765
|
+
};
|
|
1766
|
+
|
|
1767
|
+
// src/utils/getRgb.ts
|
|
1768
|
+
var getRgb = (value) => {
|
|
1769
|
+
if (!value) return null;
|
|
1770
|
+
let trimmed = value.trim().toLowerCase();
|
|
1771
|
+
const namedColor = colorNames[trimmed];
|
|
1772
|
+
if (namedColor) trimmed = namedColor;
|
|
1773
|
+
const hexMatch = trimmed.match(/^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i);
|
|
1774
|
+
if (hexMatch) {
|
|
1775
|
+
const hex = hexMatch[1];
|
|
1776
|
+
let normalized = hex;
|
|
1777
|
+
if (hex.length === 3) {
|
|
1778
|
+
normalized = hex.split("").map((c) => c + c).join("");
|
|
1779
|
+
} else if (hex.length === 8) {
|
|
1780
|
+
const alpha = parseInt(hex.substring(6, 8), 16);
|
|
1781
|
+
normalized = hex.substring(0, 6);
|
|
1782
|
+
const intVal2 = parseInt(normalized, 16);
|
|
1783
|
+
return {
|
|
1784
|
+
r: intVal2 >> 16 & 255,
|
|
1785
|
+
g: intVal2 >> 8 & 255,
|
|
1786
|
+
b: intVal2 & 255,
|
|
1787
|
+
a: alpha / 255
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1790
|
+
const intVal = parseInt(normalized, 16);
|
|
1791
|
+
return {
|
|
1792
|
+
r: intVal >> 16 & 255,
|
|
1793
|
+
g: intVal >> 8 & 255,
|
|
1794
|
+
b: intVal & 255
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
const rgbMatch = trimmed.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*([0-9.]+))?\s*\)$/i);
|
|
1798
|
+
if (rgbMatch) {
|
|
1799
|
+
const result = {
|
|
1800
|
+
r: Number(rgbMatch[1]),
|
|
1801
|
+
g: Number(rgbMatch[2]),
|
|
1802
|
+
b: Number(rgbMatch[3])
|
|
1803
|
+
};
|
|
1804
|
+
if (rgbMatch[4] !== void 0) {
|
|
1805
|
+
result.a = Number(rgbMatch[4]);
|
|
1806
|
+
}
|
|
1807
|
+
return result;
|
|
1808
|
+
}
|
|
1809
|
+
return null;
|
|
1810
|
+
};
|
|
1811
|
+
|
|
1812
|
+
// src/utils/getHex.ts
|
|
1813
|
+
var getHex = (value) => {
|
|
1814
|
+
const rgb = getRgb(value);
|
|
1815
|
+
if (!rgb) return null;
|
|
1816
|
+
const toHex = (n) => {
|
|
1817
|
+
const hex = Math.round(n).toString(16);
|
|
1818
|
+
return hex.length === 1 ? "0" + hex : hex;
|
|
1819
|
+
};
|
|
1820
|
+
const hexString = `#${toHex(rgb.r)}${toHex(rgb.g)}${toHex(rgb.b)}`;
|
|
1821
|
+
if (rgb.a !== void 0) {
|
|
1822
|
+
return `${hexString}${toHex(rgb.a * 255)}`;
|
|
1823
|
+
}
|
|
1824
|
+
return hexString;
|
|
1825
|
+
};
|
|
1826
|
+
|
|
1827
|
+
// src/utils/getBlendedColor.ts
|
|
1828
|
+
var getBlendedColor = (foreground, background, alpha) => {
|
|
1829
|
+
const fg = getRgb(foreground);
|
|
1830
|
+
const bg = getRgb(background);
|
|
1831
|
+
if (!fg || !bg) return background;
|
|
1832
|
+
const safeAlpha = Math.min(1, Math.max(0, alpha));
|
|
1833
|
+
const r = Math.round(fg.r * safeAlpha + bg.r * (1 - safeAlpha));
|
|
1834
|
+
const g = Math.round(fg.g * safeAlpha + bg.g * (1 - safeAlpha));
|
|
1835
|
+
const b = Math.round(fg.b * safeAlpha + bg.b * (1 - safeAlpha));
|
|
1836
|
+
return getHex(`rgb(${r}, ${g}, ${b})`) ?? background;
|
|
1837
|
+
};
|
|
1838
|
+
|
|
1839
|
+
// src/utils/getTriadicPalette.ts
|
|
1840
|
+
function getTriadicPalette(primaryColor) {
|
|
1841
|
+
const rgb = getRgb(primaryColor);
|
|
1842
|
+
if (!rgb) throw new Error(`Invalid color format: ${primaryColor}`);
|
|
1843
|
+
const r = rgb.r / 255;
|
|
1844
|
+
const g = rgb.g / 255;
|
|
1845
|
+
const b = rgb.b / 255;
|
|
1846
|
+
const max = Math.max(r, g, b);
|
|
1847
|
+
const min = Math.min(r, g, b);
|
|
1848
|
+
const l = (max + min) / 2;
|
|
1849
|
+
let h = 0;
|
|
1850
|
+
let s = 0;
|
|
1851
|
+
if (max !== min) {
|
|
1852
|
+
const d = max - min;
|
|
1853
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
1854
|
+
switch (max) {
|
|
1855
|
+
case r:
|
|
1856
|
+
h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
|
1857
|
+
break;
|
|
1858
|
+
case g:
|
|
1859
|
+
h = ((b - r) / d + 2) / 6;
|
|
1860
|
+
break;
|
|
1861
|
+
case b:
|
|
1862
|
+
h = ((r - g) / d + 4) / 6;
|
|
1863
|
+
break;
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
return {
|
|
1867
|
+
primary: getHex(primaryColor) ?? primaryColor,
|
|
1868
|
+
secondary: hslToHex((h + 1 / 3) % 1, s, l),
|
|
1869
|
+
tertiary: hslToHex((h + 2 / 3) % 1, s, l)
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
function hslToHex(h, s, l) {
|
|
1873
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
1874
|
+
const x = c * (1 - Math.abs(h * 6 % 2 - 1));
|
|
1875
|
+
const m = l - c / 2;
|
|
1876
|
+
let r = 0;
|
|
1877
|
+
let g = 0;
|
|
1878
|
+
let b = 0;
|
|
1879
|
+
if (h < 1 / 6) {
|
|
1880
|
+
r = c;
|
|
1881
|
+
g = x;
|
|
1882
|
+
b = 0;
|
|
1883
|
+
} else if (h < 2 / 6) {
|
|
1884
|
+
r = x;
|
|
1885
|
+
g = c;
|
|
1886
|
+
b = 0;
|
|
1887
|
+
} else if (h < 3 / 6) {
|
|
1888
|
+
r = 0;
|
|
1889
|
+
g = c;
|
|
1890
|
+
b = x;
|
|
1891
|
+
} else if (h < 4 / 6) {
|
|
1892
|
+
r = 0;
|
|
1893
|
+
g = x;
|
|
1894
|
+
b = c;
|
|
1895
|
+
} else if (h < 5 / 6) {
|
|
1896
|
+
r = x;
|
|
1897
|
+
g = 0;
|
|
1898
|
+
b = c;
|
|
1899
|
+
} else {
|
|
1900
|
+
r = c;
|
|
1901
|
+
g = 0;
|
|
1902
|
+
b = x;
|
|
1903
|
+
}
|
|
1904
|
+
const toHex = (value) => {
|
|
1905
|
+
const hex = Math.round((value + m) * 255).toString(16);
|
|
1906
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
1907
|
+
};
|
|
1908
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
// src/utils/isDarkColor.ts
|
|
1912
|
+
var isDarkColor = (value) => {
|
|
1913
|
+
const rgb = getRgb(value);
|
|
1914
|
+
if (!rgb) return false;
|
|
1915
|
+
const [r, g, b] = [rgb.r / 255, rgb.g / 255, rgb.b / 255];
|
|
1916
|
+
const [rs, gs, bs] = [r, g, b].map((c) => c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4));
|
|
1917
|
+
const luminance = 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
|
|
1918
|
+
return luminance < 0.5;
|
|
1919
|
+
};
|
|
1920
|
+
|
|
1921
|
+
// src/useComputedTheme.ts
|
|
1922
|
+
function useComputedTheme(appearance, color, options) {
|
|
1923
|
+
const splashScreen = options?.splashScreen !== false;
|
|
1924
|
+
const [theme, setTheme] = (0, import_react.useState)(null);
|
|
1925
|
+
const computeTheme = (0, import_react.useCallback)(() => {
|
|
1926
|
+
let resolved = appearance;
|
|
1927
|
+
if (resolved === "system") resolved = import_react_native.Appearance.getColorScheme();
|
|
1928
|
+
if (resolved === "no-preference" || !resolved) resolved = "light";
|
|
1929
|
+
const base = resolved === "dark" ? import_react_native_paper.MD3DarkTheme : import_react_native_paper.MD3LightTheme;
|
|
1930
|
+
const _theme = {
|
|
1931
|
+
...base,
|
|
1932
|
+
colors: {
|
|
1933
|
+
...base.colors,
|
|
1934
|
+
elevation: { ...base.colors.elevation }
|
|
1935
|
+
}
|
|
1936
|
+
};
|
|
1937
|
+
const palette = getTriadicPalette(color);
|
|
1938
|
+
const surface = base.colors.surface;
|
|
1939
|
+
_theme.colors.primary = palette.primary;
|
|
1940
|
+
_theme.colors.onPrimary = isDarkColor(palette.primary) ? "#ffffff" : "#000000";
|
|
1941
|
+
_theme.colors.primaryContainer = getBlendedColor(palette.primary, surface, 0.15);
|
|
1942
|
+
_theme.colors.onPrimaryContainer = isDarkColor(_theme.colors.primaryContainer) ? "#ffffff" : "#000000";
|
|
1943
|
+
_theme.colors.secondary = palette.secondary;
|
|
1944
|
+
_theme.colors.onSecondary = isDarkColor(palette.secondary) ? "#ffffff" : "#000000";
|
|
1945
|
+
_theme.colors.secondaryContainer = getBlendedColor(palette.secondary, surface, 0.15);
|
|
1946
|
+
_theme.colors.onSecondaryContainer = isDarkColor(_theme.colors.secondaryContainer) ? "#ffffff" : "#000000";
|
|
1947
|
+
_theme.colors.tertiary = palette.tertiary;
|
|
1948
|
+
_theme.colors.onTertiary = isDarkColor(palette.tertiary) ? "#ffffff" : "#000000";
|
|
1949
|
+
_theme.colors.tertiaryContainer = getBlendedColor(palette.tertiary, surface, 0.15);
|
|
1950
|
+
_theme.colors.onTertiaryContainer = isDarkColor(_theme.colors.tertiaryContainer) ? "#ffffff" : "#000000";
|
|
1951
|
+
const blended = getBlendedColor(color, palette.secondary, 0.5);
|
|
1952
|
+
const tintSurface = (alpha) => getBlendedColor(blended, surface, alpha);
|
|
1953
|
+
_theme.colors.surface = surface;
|
|
1954
|
+
_theme.colors.surfaceVariant = tintSurface(0.2);
|
|
1955
|
+
_theme.colors.outline = getBlendedColor(color, base.colors.outline, 0.45);
|
|
1956
|
+
const grey = base.dark ? "#424242" : "#c2c2c2";
|
|
1957
|
+
const blendedGrey = getBlendedColor(blended, grey, 0.05);
|
|
1958
|
+
_theme.colors.elevation = {
|
|
1959
|
+
..._theme.colors.elevation,
|
|
1960
|
+
level1: _theme.colors.surface,
|
|
1961
|
+
level2: getBlendedColor(blendedGrey, _theme.colors.surface, 0.25),
|
|
1962
|
+
level3: getBlendedColor(blendedGrey, _theme.colors.surface, 0.4),
|
|
1963
|
+
level4: getBlendedColor(blendedGrey, _theme.colors.surface, 0.55),
|
|
1964
|
+
level5: getBlendedColor(blendedGrey, _theme.colors.surface, 0.7)
|
|
1965
|
+
};
|
|
1966
|
+
setTheme(_theme);
|
|
1967
|
+
}, [appearance, color]);
|
|
1968
|
+
(0, import_react.useEffect)(() => {
|
|
1969
|
+
computeTheme();
|
|
1970
|
+
}, [computeTheme]);
|
|
1971
|
+
(0, import_react.useEffect)(() => {
|
|
1972
|
+
const subscription = import_react_native.Appearance.addChangeListener(computeTheme);
|
|
1973
|
+
return subscription.remove;
|
|
1974
|
+
}, [computeTheme]);
|
|
1975
|
+
(0, import_react.useEffect)(() => {
|
|
1976
|
+
if (theme && splashScreen) SplashScreen.hideAsync();
|
|
1977
|
+
}, [theme, splashScreen]);
|
|
1978
|
+
return theme;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
// src/ThemeProvider.tsx
|
|
1982
|
+
function configureSplashScreen(options) {
|
|
1983
|
+
SplashScreen2.preventAutoHideAsync();
|
|
1984
|
+
if (options) {
|
|
1985
|
+
SplashScreen2.setOptions({
|
|
1986
|
+
duration: options.duration ?? 500,
|
|
1987
|
+
fade: options.fade ?? true
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
function ThemeProvider({ appearance, color, splashScreen = true, children }) {
|
|
1992
|
+
const theme = useComputedTheme(appearance, color, { splashScreen });
|
|
1993
|
+
if (!theme) return null;
|
|
1994
|
+
return /* @__PURE__ */ React.createElement(import_react_native_paper2.Provider, { theme }, /* @__PURE__ */ React.createElement(import_react_native2.StatusBar, { backgroundColor: theme.colors.background, barStyle: theme.dark ? "light-content" : "dark-content" }), /* @__PURE__ */ React.createElement(import_react_native2.View, { style: styles.flex }, children));
|
|
1995
|
+
}
|
|
1996
|
+
var styles = import_react_native2.StyleSheet.create({
|
|
1997
|
+
flex: { flex: 1 }
|
|
1998
|
+
});
|
|
1999
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2000
|
+
0 && (module.exports = {
|
|
2001
|
+
ThemeProvider,
|
|
2002
|
+
configureSplashScreen,
|
|
2003
|
+
getBlendedColor,
|
|
2004
|
+
getHex,
|
|
2005
|
+
getRgb,
|
|
2006
|
+
getTriadicPalette,
|
|
2007
|
+
isDarkColor,
|
|
2008
|
+
themeActions,
|
|
2009
|
+
themeReducer,
|
|
2010
|
+
useComputedTheme
|
|
2011
|
+
});
|