estreui 1.2.2 → 1.2.4

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/scripts/boot.js CHANGED
@@ -13,7 +13,7 @@ const isSamsungMobile = isSamsungBrowser && isMobile;
13
13
 
14
14
 
15
15
  window.isLog = true;
16
- window.isDebug = true;
16
+ window.isDebug = location.host.replace("class.mangoedu.co.kr", "").length > 0;
17
17
  window.isVerbose = false;
18
18
  Object.defineProperty(window, "isLogging", {
19
19
  "get": function () { return this.isLog || this.isDebug; },
@@ -44,7 +44,7 @@ const updateInsets = function (e) {
44
44
  root.style.setProperty('--fvw', `${width}px`);
45
45
  root.style.setProperty('--fvh', `${height}px`);
46
46
  }
47
-
47
+
48
48
  const vvpw = vvp.width;
49
49
  const vvph = vvp.height;
50
50
  const vvpt = vvp.offsetTop;
@@ -86,7 +86,6 @@ if (isAppleMobile) {
86
86
  document.documentElement.style.setProperty('--viewport-inset-bottom', 'var(--safe-area-inset-bottom)');
87
87
  }
88
88
 
89
-
90
89
  const releaseInsetForApp = () => {
91
90
  const insets = window.safeAreaInsets;
92
91
 
@@ -112,20 +111,39 @@ window.addEventListener('safeAreaInsetsChanged', function () {
112
111
  releaseInsetForApp();
113
112
 
114
113
 
115
- // Service Worker
116
-
114
+ /**
115
+ * Service Worker management handler.
116
+ * Tracks the registration/install/waiting/activation lifecycle and performs cache management via messaging protocol.
117
+ * 4-tier cache strategy: Application / Common / Static / Stony.
118
+ * @type {Object}
119
+ */
117
120
  const serviceWorkerHandler = {
121
+ /** @type {ServiceWorkerRegistration|null} Service worker registration object. */
118
122
  registeration: null,
123
+ /** @type {ServiceWorker|null} Installing worker. */
119
124
  installing: null,
125
+ /** @type {ServiceWorker|null} Waiting worker. */
120
126
  waiting: null,
127
+ /** @type {ServiceWorker|null} Activating worker. */
121
128
  activating: null,
129
+ /** @type {ServiceWorker|null} Activated worker. */
122
130
  activated: null,
131
+ /** @type {boolean|null} Whether this is a fresh install. */
123
132
  isInitialSetup: null,
124
133
 
134
+ /** @type {ServiceWorkerContainer} navigator.serviceWorker. */
125
135
  get service() { return navigator.serviceWorker; },
136
+ /** @type {ServiceWorker|null} Current controller. */
126
137
  get controller() { return this.service?.controller; },
138
+ /** @type {ServiceWorker|null} Latest worker (in order: controller → activated → activating → waiting → installing). */
127
139
  get worker() { return this.controller ?? this.activated ?? this.activating ?? this.waiting ?? this.installing; },
128
140
 
141
+ /**
142
+ * Sends a message to the worker.
143
+ * @param {ServiceWorker|null} worker - Target worker. If null, uses current worker.
144
+ * @param {Object} message - Message object to send.
145
+ * @param {Transferable[]} [transfer] - Transferable objects.
146
+ */
129
147
  postMessage(worker, message, transfer) {
130
148
  (worker ?? this.worker)?.postMessage(message, transfer);
131
149
  },
@@ -152,6 +170,7 @@ const serviceWorkerHandler = {
152
170
  }
153
171
  },
154
172
 
173
+ /** Checks for service worker updates. @returns {Promise<ServiceWorker|false|null|undefined>} */
155
174
  async update() {
156
175
  if (this.registeration == null) return null;
157
176
  try {
@@ -171,6 +190,7 @@ const serviceWorkerHandler = {
171
190
 
172
191
  registerationOnInstalling(worker) {
173
192
  this.installing = worker;
193
+ // this.controller?.let(it => this.clearCache(it));
174
194
  this.onInstalling?.(worker);
175
195
  },
176
196
 
@@ -231,7 +251,7 @@ const serviceWorkerHandler = {
231
251
  controllerChangeListener(event) {
232
252
  if (isVerbosely) console.log("Service Worker controller changed:", event, "\n", serviceWorkerHandler.service.controller);
233
253
  else if (isLogging) console.log("Service Worker controller changed:", event.scriptURL);
234
- serviceWorkerHandler.controllerOnChanged(event);
254
+ serviceWorkerHandler.controllerOnChanged(event);
235
255
  },
236
256
 
237
257
  messageListener(event) {
@@ -247,7 +267,7 @@ const serviceWorkerHandler = {
247
267
  }
248
268
  }
249
269
  break;
250
-
270
+
251
271
  default:
252
272
  if (isVerbosely) console.log("Received message with unknown type '" + event.data.type + "'", event);
253
273
  else if (isLogging) console.log("Received message with unknown type '" + event.data.type + "'");
@@ -255,6 +275,14 @@ const serviceWorkerHandler = {
255
275
  }
256
276
  },
257
277
 
278
+ /**
279
+ * Sends a request to the worker and receives the response via callback.
280
+ * @param {string} type - Request type.
281
+ * @param {Object} [content={}] - Request content.
282
+ * @param {Function} [onSuccess] - Success callback.
283
+ * @param {Function} [onError] - Error callback.
284
+ * @param {ServiceWorker} [worker=this.worker] - Target worker.
285
+ */
258
286
  async sendRequest(type, content = {}, onSuccess, onError, worker = this.worker) {
259
287
  if (worker != null) {
260
288
  const sequence = this.issueRequestSequence;
@@ -263,20 +291,30 @@ const serviceWorkerHandler = {
263
291
  } else onError?.("Service Worker is not exist.");
264
292
  },
265
293
 
294
+ /**
295
+ * Sends a request to the worker and awaits the response as a Promise.
296
+ * @param {string} type - Request type.
297
+ * @param {Object} [content={}] - Request content.
298
+ * @param {ServiceWorker} [worker=this.worker] - Target worker.
299
+ * @returns {Promise<*>}
300
+ */
266
301
  sendRequestForWait(type, content = {}, worker = this.worker) {
267
302
  return new Promise((resolve, reject) => {
268
303
  this.sendRequest(type, content, resolve, reject, worker);
269
304
  });
270
305
  },
271
306
 
307
+ /** Requests the waiting worker to activate immediately. @param {ServiceWorker} [worker=this.waiting] */
272
308
  skipWaiting(worker = this.waiting) {
273
309
  worker?.postMessage({ type: "SKIP_WAITING" });
274
310
  },
275
311
 
312
+ /** Requests the active worker to immediately control all clients. @param {ServiceWorker} [worker=this.activated] */
276
313
  clientsClaim(worker = this.activated) {
277
314
  worker?.postMessage({ type: "CLIENTS_CLAIM" });
278
315
  },
279
316
 
317
+ /** Deletes the Application cache. @param {ServiceWorker} [worker] @returns {Promise<*>} */
280
318
  async clearCache(worker = this.worker) {
281
319
  try {
282
320
  return await this.sendRequestForWait("clearCache", {}, worker);
@@ -285,6 +323,7 @@ const serviceWorkerHandler = {
285
323
  }
286
324
  },
287
325
 
326
+ /** Deletes the Common cache. @param {ServiceWorker} [worker] @returns {Promise<*>} */
288
327
  async clearCommonCache(worker = this.worker) {
289
328
  try {
290
329
  return await this.sendRequestForWait("clearCommonCache", {}, worker);
@@ -293,6 +332,7 @@ const serviceWorkerHandler = {
293
332
  }
294
333
  },
295
334
 
335
+ /** Deletes the Static cache. @param {ServiceWorker} [worker] @returns {Promise<*>} */
296
336
  async clearStaticCache(worker = this.worker) {
297
337
  try {
298
338
  return await this.sendRequestForWait("clearStaticCache", {}, worker);
@@ -301,6 +341,7 @@ const serviceWorkerHandler = {
301
341
  }
302
342
  },
303
343
 
344
+ /** Deletes the Stony cache. @param {ServiceWorker} [worker] @returns {Promise<*>} */
304
345
  async clearStonyCache(worker = this.worker) {
305
346
  try {
306
347
  return await this.sendRequestForWait("clearStonyCache", {}, worker);
@@ -309,6 +350,7 @@ const serviceWorkerHandler = {
309
350
  }
310
351
  },
311
352
 
353
+ /** Deletes all caches (Application + Common + Static + Stony). @param {ServiceWorker} [worker] @returns {Promise<*>} */
312
354
  async clearAllCaches(worker = this.worker) {
313
355
  try {
314
356
  return await this.sendRequestForWait("clearAllCaches", {}, worker);
@@ -317,6 +359,7 @@ const serviceWorkerHandler = {
317
359
  }
318
360
  },
319
361
 
362
+ /** Retrieves the worker version info. @param {ServiceWorker} [worker] @returns {Promise<*>} */
320
363
  async getVersion(worker = this.worker) {
321
364
  try {
322
365
  return await this.sendRequestForWait("getVersion", {}, worker);
@@ -325,10 +368,12 @@ const serviceWorkerHandler = {
325
368
  }
326
369
  },
327
370
 
371
+ /** Retrieves the version of the waiting worker. @returns {Promise<*>} */
328
372
  getVersionWaiting() {
329
373
  return this.getVersion(this.waiting);
330
374
  },
331
375
 
376
+ /** Retrieves the number of entries in the Application cache. @param {ServiceWorker} [worker] @returns {Promise<number>} */
332
377
  async getApplicationCount(worker = this.controller) {
333
378
  try {
334
379
  return worker != null ? await this.sendRequestForWait("getApplicationCount", {}, worker) : 0;
@@ -351,6 +396,9 @@ if ("serviceWorker" in navigator) {
351
396
 
352
397
  const serviceWorkerOnWaiting = (worker) => {
353
398
  if (worker) {
399
+ // console.log("Service Worker is waiting to activate.");
400
+ // registration.waiting.postMessage({ type: "SKIP_WAITING" });
401
+
354
402
  if (isLogging) console.log("Service Worker is waiting:", worker.scriptURL);
355
403
  else if (isVerbosely) console.log("Service Worker is waiting:", worker);
356
404
  serviceWorkerHandler.registerationOnWaiting(worker);
@@ -374,72 +422,64 @@ if ("serviceWorker" in navigator) {
374
422
  };
375
423
 
376
424
  // window.addEventListener("load", () => {
377
- navigator.serviceWorker.register("./serviceWorker.js", {
378
- // scope: "/", // When use service worker file out of location of index.html, have to set scope with HTTP Server response Header 'Service-Worker-Allowed: /'
379
- updateViaCache: "none",
380
-
381
- // vv PWA required set HTTP server response headers vv
382
- // Cache-Control: no-cache
383
- // Pragma: no-cache
384
- // Expires: 0
385
- }).then(registration => {
386
- serviceWorkerHandler.registeration = registration;
387
- if (isLogging) console.log("Service Worker registered with scope:", registration.scope);
388
-
389
- serviceWorkerOnInstalling(registration.installing);
390
- serviceWorkerOnWaiting(registration.waiting);
391
-
392
- registration.addEventListener("statechange", () => {
393
- const activated = registration.active;
394
- const constoller = navigator.serviceWorker.controller;
395
- if (activated) {
396
- if (isLogging) console.log("Service Worker state changed to:", activated.state);
397
- serviceWorkerOnActive(registration.active, controller != null && activated != controller);
398
- }
399
- });
425
+ navigator.serviceWorker.register("./scripts/serviceWorker.js", { scope: "/", updateViaCache: "none" }).then(registration => {
426
+ serviceWorkerHandler.registeration = registration;
427
+ if (isLogging) console.log("Service Worker registered with scope:", registration.scope);
428
+
429
+ serviceWorkerOnInstalling(registration.installing);
430
+ serviceWorkerOnWaiting(registration.waiting);
431
+
432
+ registration.addEventListener("statechange", () => {
433
+ const activated = registration.active;
434
+ const constoller = navigator.serviceWorker.controller;
435
+ if (activated) {
436
+ if (isLogging) console.log("Service Worker state changed to:", activated.state);
437
+ serviceWorkerOnActive(registration.active, controller != null && activated != controller);
438
+ }
439
+ });
400
440
 
401
- serviceWorkerOnActive(registration.active);
402
- serviceWorkerHandler.isInitialSetup = registration.active == null;
403
-
404
- registration.addEventListener("updatefound", () => {
405
- const newWorker = registration.installing;
406
- if (isLogging) console.log("New Service Worker found:", newWorker.scriptURL);
407
- else if (isVerbosely) console.log("New Service Worker found:", newWorker);
408
- serviceWorkerOnInstalling(newWorker);
409
-
410
- newWorker.addEventListener("statechange", () => {
411
- if (isLogging) console.log("New Service Worker state changed to:", newWorker.state);
412
- switch (newWorker.state) {
413
- case "installed":
414
- if (isLogging) console.log("New Service Worker installed and waiting to activate.");
415
- const controllerExist = navigator.serviceWorker.controller;
416
- const isWaiting = registration.waiting == newWorker;
417
- serviceWorkerHandler.registerationOnUpdated();
418
- if (isWaiting) {
419
- if (controllerExist) {
420
- serviceWorkerOnWaiting(newWorker);
421
- } else {
422
- // do nothing (first install)
441
+ serviceWorkerOnActive(registration.active);
442
+ serviceWorkerHandler.isInitialSetup = registration.active == null;
443
+
444
+ registration.addEventListener("updatefound", () => {
445
+ const newWorker = registration.installing;
446
+ if (isLogging) console.log("New Service Worker found:", newWorker.scriptURL);
447
+ else if (isVerbosely) console.log("New Service Worker found:", newWorker);
448
+ serviceWorkerOnInstalling(newWorker);
449
+
450
+ newWorker.addEventListener("statechange", () => {
451
+ if (isLogging) console.log("New Service Worker state changed to:", newWorker.state);
452
+ switch (newWorker.state) {
453
+ case "installed":
454
+ if (isLogging) console.log("New Service Worker installed and waiting to activate.");
455
+ const controllerExist = navigator.serviceWorker.controller;
456
+ const isWaiting = registration.waiting == newWorker;
457
+ serviceWorkerHandler.registerationOnUpdated();
458
+ if (isWaiting) {
459
+ if (controllerExist) {
460
+ serviceWorkerOnWaiting(newWorker);
461
+ } else {
462
+ // do nothing (first install)
463
+ }
423
464
  }
424
- }
425
- break;
465
+ break;
426
466
 
427
- case "activating":
428
- serviceWorkerOnActivating(newWorker, true);
429
- break;
467
+ case "activating":
468
+ serviceWorkerOnActivating(newWorker, true);
469
+ break;
430
470
 
431
- case "activated":
432
- serviceWorkerOnActive(newWorker, true);
433
- break;
434
- }
471
+ case "activated":
472
+ serviceWorkerOnActive(newWorker, true);
473
+ break;
474
+ }
435
475
 
436
- if (newWorker == navigator.serviceWorker.controller) {
437
- if (isLogging) console.log("New Service Worker is attached.");
438
- }
476
+ if (newWorker == navigator.serviceWorker.controller) {
477
+ if (isLogging) console.log("New Service Worker is attached.");
478
+ }
479
+ });
439
480
  });
481
+ }).catch(error => {
482
+ console.error("Service Worker registration failed:", error);
440
483
  });
441
- }).catch(error => {
442
- console.error("Service Worker registration failed:", error);
443
- });
444
484
  // });
445
485
  }