@lls/offline 24.20.0-debug

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/lib/index.js ADDED
@@ -0,0 +1,430 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
28
+ var require_react_production_min = __commonJS({
29
+ "../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js"(exports) {
30
+ "use strict";
31
+ var l = Symbol.for("react.element");
32
+ var n = Symbol.for("react.portal");
33
+ var p = Symbol.for("react.fragment");
34
+ var q = Symbol.for("react.strict_mode");
35
+ var r = Symbol.for("react.profiler");
36
+ var t = Symbol.for("react.provider");
37
+ var u = Symbol.for("react.context");
38
+ var v = Symbol.for("react.forward_ref");
39
+ var w = Symbol.for("react.suspense");
40
+ var x = Symbol.for("react.memo");
41
+ var y = Symbol.for("react.lazy");
42
+ var z = Symbol.iterator;
43
+ function A(a2) {
44
+ if (null === a2 || "object" !== typeof a2) return null;
45
+ a2 = z && a2[z] || a2["@@iterator"];
46
+ return "function" === typeof a2 ? a2 : null;
47
+ }
48
+ var B = { isMounted: function() {
49
+ return false;
50
+ }, enqueueForceUpdate: function() {
51
+ }, enqueueReplaceState: function() {
52
+ }, enqueueSetState: function() {
53
+ } };
54
+ var C = Object.assign;
55
+ var D = {};
56
+ function E(a2, b, e) {
57
+ this.props = a2;
58
+ this.context = b;
59
+ this.refs = D;
60
+ this.updater = e || B;
61
+ }
62
+ E.prototype.isReactComponent = {};
63
+ E.prototype.setState = function(a2, b) {
64
+ if ("object" !== typeof a2 && "function" !== typeof a2 && null != a2) throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");
65
+ this.updater.enqueueSetState(this, a2, b, "setState");
66
+ };
67
+ E.prototype.forceUpdate = function(a2) {
68
+ this.updater.enqueueForceUpdate(this, a2, "forceUpdate");
69
+ };
70
+ function F() {
71
+ }
72
+ F.prototype = E.prototype;
73
+ function G(a2, b, e) {
74
+ this.props = a2;
75
+ this.context = b;
76
+ this.refs = D;
77
+ this.updater = e || B;
78
+ }
79
+ var H = G.prototype = new F();
80
+ H.constructor = G;
81
+ C(H, E.prototype);
82
+ H.isPureReactComponent = true;
83
+ var I = Array.isArray;
84
+ var J = Object.prototype.hasOwnProperty;
85
+ var K = { current: null };
86
+ var L = { key: true, ref: true, __self: true, __source: true };
87
+ function M(a2, b, e) {
88
+ var d, c = {}, k = null, h = null;
89
+ if (null != b) for (d in void 0 !== b.ref && (h = b.ref), void 0 !== b.key && (k = "" + b.key), b) J.call(b, d) && !L.hasOwnProperty(d) && (c[d] = b[d]);
90
+ var g = arguments.length - 2;
91
+ if (1 === g) c.children = e;
92
+ else if (1 < g) {
93
+ for (var f = Array(g), m = 0; m < g; m++) f[m] = arguments[m + 2];
94
+ c.children = f;
95
+ }
96
+ if (a2 && a2.defaultProps) for (d in g = a2.defaultProps, g) void 0 === c[d] && (c[d] = g[d]);
97
+ return { $$typeof: l, type: a2, key: k, ref: h, props: c, _owner: K.current };
98
+ }
99
+ function N(a2, b) {
100
+ return { $$typeof: l, type: a2.type, key: b, ref: a2.ref, props: a2.props, _owner: a2._owner };
101
+ }
102
+ function O(a2) {
103
+ return "object" === typeof a2 && null !== a2 && a2.$$typeof === l;
104
+ }
105
+ function escape(a2) {
106
+ var b = { "=": "=0", ":": "=2" };
107
+ return "$" + a2.replace(/[=:]/g, function(a3) {
108
+ return b[a3];
109
+ });
110
+ }
111
+ var P = /\/+/g;
112
+ function Q(a2, b) {
113
+ return "object" === typeof a2 && null !== a2 && null != a2.key ? escape("" + a2.key) : b.toString(36);
114
+ }
115
+ function R(a2, b, e, d, c) {
116
+ var k = typeof a2;
117
+ if ("undefined" === k || "boolean" === k) a2 = null;
118
+ var h = false;
119
+ if (null === a2) h = true;
120
+ else switch (k) {
121
+ case "string":
122
+ case "number":
123
+ h = true;
124
+ break;
125
+ case "object":
126
+ switch (a2.$$typeof) {
127
+ case l:
128
+ case n:
129
+ h = true;
130
+ }
131
+ }
132
+ if (h) return h = a2, c = c(h), a2 = "" === d ? "." + Q(h, 0) : d, I(c) ? (e = "", null != a2 && (e = a2.replace(P, "$&/") + "/"), R(c, b, e, "", function(a3) {
133
+ return a3;
134
+ })) : null != c && (O(c) && (c = N(c, e + (!c.key || h && h.key === c.key ? "" : ("" + c.key).replace(P, "$&/") + "/") + a2)), b.push(c)), 1;
135
+ h = 0;
136
+ d = "" === d ? "." : d + ":";
137
+ if (I(a2)) for (var g = 0; g < a2.length; g++) {
138
+ k = a2[g];
139
+ var f = d + Q(k, g);
140
+ h += R(k, b, e, f, c);
141
+ }
142
+ else if (f = A(a2), "function" === typeof f) for (a2 = f.call(a2), g = 0; !(k = a2.next()).done; ) k = k.value, f = d + Q(k, g++), h += R(k, b, e, f, c);
143
+ else if ("object" === k) throw b = String(a2), Error("Objects are not valid as a React child (found: " + ("[object Object]" === b ? "object with keys {" + Object.keys(a2).join(", ") + "}" : b) + "). If you meant to render a collection of children, use an array instead.");
144
+ return h;
145
+ }
146
+ function S(a2, b, e) {
147
+ if (null == a2) return a2;
148
+ var d = [], c = 0;
149
+ R(a2, d, "", "", function(a3) {
150
+ return b.call(e, a3, c++);
151
+ });
152
+ return d;
153
+ }
154
+ function T(a2) {
155
+ if (-1 === a2._status) {
156
+ var b = a2._result;
157
+ b = b();
158
+ b.then(function(b2) {
159
+ if (0 === a2._status || -1 === a2._status) a2._status = 1, a2._result = b2;
160
+ }, function(b2) {
161
+ if (0 === a2._status || -1 === a2._status) a2._status = 2, a2._result = b2;
162
+ });
163
+ -1 === a2._status && (a2._status = 0, a2._result = b);
164
+ }
165
+ if (1 === a2._status) return a2._result.default;
166
+ throw a2._result;
167
+ }
168
+ var U = { current: null };
169
+ var V = { transition: null };
170
+ var W = { ReactCurrentDispatcher: U, ReactCurrentBatchConfig: V, ReactCurrentOwner: K };
171
+ function X() {
172
+ throw Error("act(...) is not supported in production builds of React.");
173
+ }
174
+ exports.Children = { map: S, forEach: function(a2, b, e) {
175
+ S(a2, function() {
176
+ b.apply(this, arguments);
177
+ }, e);
178
+ }, count: function(a2) {
179
+ var b = 0;
180
+ S(a2, function() {
181
+ b++;
182
+ });
183
+ return b;
184
+ }, toArray: function(a2) {
185
+ return S(a2, function(a3) {
186
+ return a3;
187
+ }) || [];
188
+ }, only: function(a2) {
189
+ if (!O(a2)) throw Error("React.Children.only expected to receive a single React element child.");
190
+ return a2;
191
+ } };
192
+ exports.Component = E;
193
+ exports.Fragment = p;
194
+ exports.Profiler = r;
195
+ exports.PureComponent = G;
196
+ exports.StrictMode = q;
197
+ exports.Suspense = w;
198
+ exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = W;
199
+ exports.act = X;
200
+ exports.cloneElement = function(a2, b, e) {
201
+ if (null === a2 || void 0 === a2) throw Error("React.cloneElement(...): The argument must be a React element, but you passed " + a2 + ".");
202
+ var d = C({}, a2.props), c = a2.key, k = a2.ref, h = a2._owner;
203
+ if (null != b) {
204
+ void 0 !== b.ref && (k = b.ref, h = K.current);
205
+ void 0 !== b.key && (c = "" + b.key);
206
+ if (a2.type && a2.type.defaultProps) var g = a2.type.defaultProps;
207
+ for (f in b) J.call(b, f) && !L.hasOwnProperty(f) && (d[f] = void 0 === b[f] && void 0 !== g ? g[f] : b[f]);
208
+ }
209
+ var f = arguments.length - 2;
210
+ if (1 === f) d.children = e;
211
+ else if (1 < f) {
212
+ g = Array(f);
213
+ for (var m = 0; m < f; m++) g[m] = arguments[m + 2];
214
+ d.children = g;
215
+ }
216
+ return { $$typeof: l, type: a2.type, key: c, ref: k, props: d, _owner: h };
217
+ };
218
+ exports.createContext = function(a2) {
219
+ a2 = { $$typeof: u, _currentValue: a2, _currentValue2: a2, _threadCount: 0, Provider: null, Consumer: null, _defaultValue: null, _globalName: null };
220
+ a2.Provider = { $$typeof: t, _context: a2 };
221
+ return a2.Consumer = a2;
222
+ };
223
+ exports.createElement = M;
224
+ exports.createFactory = function(a2) {
225
+ var b = M.bind(null, a2);
226
+ b.type = a2;
227
+ return b;
228
+ };
229
+ exports.createRef = function() {
230
+ return { current: null };
231
+ };
232
+ exports.forwardRef = function(a2) {
233
+ return { $$typeof: v, render: a2 };
234
+ };
235
+ exports.isValidElement = O;
236
+ exports.lazy = function(a2) {
237
+ return { $$typeof: y, _payload: { _status: -1, _result: a2 }, _init: T };
238
+ };
239
+ exports.memo = function(a2, b) {
240
+ return { $$typeof: x, type: a2, compare: void 0 === b ? null : b };
241
+ };
242
+ exports.startTransition = function(a2) {
243
+ var b = V.transition;
244
+ V.transition = {};
245
+ try {
246
+ a2();
247
+ } finally {
248
+ V.transition = b;
249
+ }
250
+ };
251
+ exports.unstable_act = X;
252
+ exports.useCallback = function(a2, b) {
253
+ return U.current.useCallback(a2, b);
254
+ };
255
+ exports.useContext = function(a2) {
256
+ return U.current.useContext(a2);
257
+ };
258
+ exports.useDebugValue = function() {
259
+ };
260
+ exports.useDeferredValue = function(a2) {
261
+ return U.current.useDeferredValue(a2);
262
+ };
263
+ exports.useEffect = function(a2, b) {
264
+ return U.current.useEffect(a2, b);
265
+ };
266
+ exports.useId = function() {
267
+ return U.current.useId();
268
+ };
269
+ exports.useImperativeHandle = function(a2, b, e) {
270
+ return U.current.useImperativeHandle(a2, b, e);
271
+ };
272
+ exports.useInsertionEffect = function(a2, b) {
273
+ return U.current.useInsertionEffect(a2, b);
274
+ };
275
+ exports.useLayoutEffect = function(a2, b) {
276
+ return U.current.useLayoutEffect(a2, b);
277
+ };
278
+ exports.useMemo = function(a2, b) {
279
+ return U.current.useMemo(a2, b);
280
+ };
281
+ exports.useReducer = function(a2, b, e) {
282
+ return U.current.useReducer(a2, b, e);
283
+ };
284
+ exports.useRef = function(a2) {
285
+ return U.current.useRef(a2);
286
+ };
287
+ exports.useState = function(a2) {
288
+ return U.current.useState(a2);
289
+ };
290
+ exports.useSyncExternalStore = function(a2, b, e) {
291
+ return U.current.useSyncExternalStore(a2, b, e);
292
+ };
293
+ exports.useTransition = function() {
294
+ return U.current.useTransition();
295
+ };
296
+ exports.version = "18.3.1";
297
+ }
298
+ });
299
+
300
+ // ../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js
301
+ var require_react = __commonJS({
302
+ "../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js"(exports, module) {
303
+ "use strict";
304
+ if (true) {
305
+ module.exports = require_react_production_min();
306
+ } else {
307
+ module.exports = null;
308
+ }
309
+ }
310
+ });
311
+
312
+ // src/utils/worker.ts
313
+ var makeSyncWorker = (offlineWorker, methodNames, dbg) => {
314
+ const dic = {};
315
+ const cbks = {};
316
+ const fn2 = ({ data: { eventId, methodName, results, error, arg } = {} } = {}) => {
317
+ if (eventId && eventId in dic) {
318
+ if (error) {
319
+ dic[eventId].reject(error);
320
+ } else {
321
+ dic[eventId].resolve(results);
322
+ }
323
+ } else {
324
+ if (methodName && !methodName.startsWith("async") && !(methodName in cbks)) {
325
+ console.error(`syncWorker: ${dbg}`, eventId, methodName, error);
326
+ }
327
+ }
328
+ methodName && cbks[methodName]?.(arg);
329
+ };
330
+ offlineWorker.onmessage = fn2;
331
+ const makeFn = (methodName) => {
332
+ return ({ ports, ...arg } = {}) => {
333
+ return new Promise((resolve, reject) => {
334
+ const eventId = `${methodName}:${Date.now()}`;
335
+ dic[eventId] = { resolve, reject };
336
+ offlineWorker.postMessage({ eventId, methodName, arg }, ports);
337
+ });
338
+ };
339
+ };
340
+ const obj = Object.assign(Object.fromEntries(methodNames.map((name) => [name, makeFn(name)])), {
341
+ on: (key, fn3) => {
342
+ cbks[key] = fn3;
343
+ }
344
+ });
345
+ return obj;
346
+ };
347
+ var a = (a2) => a2;
348
+ var makeSyncHandler = a(
349
+ (sender, services) => async ({ data: { eventId, methodName, arg } = {}, ports }) => {
350
+ try {
351
+ if (typeof methodName === "string" && methodName in services && services[methodName]) {
352
+ const results = await services[methodName](arg, { ports });
353
+ sender.postMessage({ eventId, methodName, results });
354
+ return;
355
+ }
356
+ throw new Error(`invalid methodName ${String(methodName)}`);
357
+ } catch (e) {
358
+ console.debug("failed", e);
359
+ sender.postMessage({ eventId, methodName, error: e });
360
+ }
361
+ }
362
+ );
363
+
364
+ // src/hooks/useOfflineWorker.ts
365
+ var import_react = __toESM(require_react(), 1);
366
+ var offlineWorkerSync = makeSyncWorker(
367
+ // @ts-ignore: TODO
368
+ new Worker("/src/worker/offlineWorker.js", { type: "module" }),
369
+ ["initChannel", "readZipEntry", "loadPreload", "loadBooks"],
370
+ "app:offlineWorker"
371
+ );
372
+ var setWorkersReady;
373
+ var workersReadyPromise = new Promise((resolve) => {
374
+ setWorkersReady = resolve;
375
+ });
376
+ var setBooksLoaded;
377
+ var setBooksLoadedPromise = new Promise((resolve) => {
378
+ setBooksLoaded = resolve;
379
+ });
380
+ var fn = async () => {
381
+ let fetchWorker = null;
382
+ await navigator.serviceWorker.getRegistrations().then(async (registrations) => {
383
+ for (const registration of registrations) {
384
+ await registration.unregister();
385
+ }
386
+ });
387
+ await navigator.serviceWorker.register("/fetch.worker.js", { type: "module" }).then((reg) => reg.update());
388
+ await navigator.serviceWorker.ready.then(async (reg) => {
389
+ console.debug("Service Worker registered:", reg.scope);
390
+ fetchWorker = reg.active;
391
+ }).catch((err) => console.error("Service Worker registration failed:", err));
392
+ if (!fetchWorker) {
393
+ return;
394
+ }
395
+ offlineWorkerSync.on("ready", setWorkersReady);
396
+ const channel = new MessageChannel();
397
+ offlineWorkerSync.initChannel({ ports: [channel.port1] });
398
+ fetchWorker.postMessage({ methodName: "initChannel" }, [channel.port2]);
399
+ await offlineWorkerSync.loadPreload();
400
+ await offlineWorkerSync.loadBooks();
401
+ setBooksLoaded();
402
+ };
403
+ fn();
404
+ var useOfflineWorker_default = () => {
405
+ const [ready, setReady] = (0, import_react.useState)(false);
406
+ (0, import_react.useEffect)(() => {
407
+ const fn2 = async () => {
408
+ await Promise.all([workersReadyPromise, setBooksLoadedPromise]);
409
+ setReady(true);
410
+ };
411
+ fn2();
412
+ }, []);
413
+ return ready;
414
+ };
415
+ export {
416
+ useOfflineWorker_default as useOfflineWorker
417
+ };
418
+ /*! Bundled license information:
419
+
420
+ react/cjs/react.production.min.js:
421
+ (**
422
+ * @license React
423
+ * react.production.min.js
424
+ *
425
+ * Copyright (c) Facebook, Inc. and its affiliates.
426
+ *
427
+ * This source code is licensed under the MIT license found in the
428
+ * LICENSE file in the root directory of this source tree.
429
+ *)
430
+ */
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@lls/offline",
3
+ "version": "24.20.0-debug",
4
+ "description": "offline",
5
+ "main": "./lib/index.js",
6
+ "module": "./lib/index.js",
7
+ "types": "./lib/builttypes/offline/src/index.d.ts",
8
+ "exports": {
9
+ ".": "./lib/index.js"
10
+ },
11
+ "files": [
12
+ "lib/",
13
+ "package.json",
14
+ "README.md"
15
+ ],
16
+ "type": "module",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/lelivrescolaire/monorepo.git"
20
+ },
21
+ "keywords": [],
22
+ "author": "",
23
+ "license": "ISC",
24
+ "bugs": {
25
+ "url": "https://github.com/lelivrescolaire/monorepo/issues"
26
+ },
27
+ "homepage": "https://github.com/lelivrescolaire/monorepo#readme",
28
+ "peerDependencies": {
29
+ "axios": "*",
30
+ "dayjs": "*",
31
+ "lodash": "*",
32
+ "react": "*",
33
+ "react-dom": "*",
34
+ "zod": "*"
35
+ },
36
+ "devDependencies": {
37
+ "@biomejs/biome": "1.9.4",
38
+ "@happy-dom/global-registrator": "15.11.0",
39
+ "@testing-library/react": "16.3.0",
40
+ "@types/react": "18.3.12",
41
+ "@types/react-dom": "18.3.1",
42
+ "@vitejs/plugin-react": "4.5.1",
43
+ "esbuild": "0.24.0",
44
+ "happy-dom": "15.11.0",
45
+ "lodash": "4.17.21",
46
+ "nock": "14.0.5",
47
+ "react": "18.3.1",
48
+ "react-dom": "18.3.1",
49
+ "typescript": "5.8.3",
50
+ "vite": "7.0.0",
51
+ "zod": "3.25.50",
52
+ "@lls/vitescripts": "24.20.0"
53
+ },
54
+ "dependencies": {
55
+ "fflate": "0.8.2"
56
+ },
57
+ "scripts": {
58
+ "start": "echo no devserver",
59
+ "dts": "pnpm tsc --project tsconfig.production.json",
60
+ "build": "node build",
61
+ "test": "bun test --bail",
62
+ "lint": "pnpm biome check --apply src __tests__"
63
+ }
64
+ }