zip-peek 0.3.1 → 0.5.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 CHANGED
@@ -136,7 +136,7 @@ const imageUrl = `${basePath}/slides/slide-1/hero.png`;
136
136
  - Decompresses when needed (stored or deflated entries).
137
137
  - Serves a normal cached response to the browser.
138
138
 
139
- From product code’s perspective, the zip bucket **behaves like a virtual folder**. The “impossible” migration was mostly: point `basePath` at `.zip`, initialize the worker, ensure the CDN supports `Accept-Ranges: bytes`.
139
+ From product code’s perspective, the zip bucket **behaves like a virtual folder**. The “impossible” migration was mostly: point `basePath` at `.zip`, initialize the worker, ensure the CDN supports `Accept-Ranges: bytes`, and configure **CORS** (S3 `ExposeHeaders` for `Content-Range` / `Accept-Ranges`, plus CloudFront `GET`/`HEAD`/`OPTIONS` with CORS preflight and **CORS-S3Origin** when applicable).
140
140
 
141
141
  **Simple flow:**
142
142
 
@@ -231,6 +231,7 @@ Mobile still downloads the zip, uncompresses it, and serves it on localhost for
231
231
  ## What had to be true on the infrastructure side
232
232
 
233
233
  - The zip origin must support **HTTP byte ranges** (`Accept-Ranges: bytes`, `206 Partial Content`).
234
+ - **CORS** must allow cross-origin `Range` requests: S3 `ExposeHeaders` must include **`Content-Range`** and **`Accept-Ranges`**; CloudFront behaviors must allow **`GET`**, **`HEAD`**, and **`OPTIONS`**, use **CORS-S3Origin**, and enable **CORS with preflight** on the response headers policy.
234
235
  - The service worker script must be served **same-origin** (with `Service-Worker-Allowed` when scope is wider than the worker path).
235
236
  - Package URLs should end with **`.zip`**.
236
237
 
@@ -319,9 +320,11 @@ type InitZipPeekOptions = {
319
320
  reloadOnFirstInstall?: boolean;
320
321
  cacheClearingStrategy?: ZipCacheClearingStrategy;
321
322
  allowedZipUrls?: string[];
323
+ requireExactManifestPath?: boolean;
322
324
  zipAssetCacheName?: string;
323
325
  assetCacheTtlMs?: number;
324
326
  logPrefix?: string;
327
+ onError?: (error: Error, info?: string) => void;
325
328
  };
326
329
 
327
330
  type ZipCacheClearingStrategy = "keep-all" | "keep-allowed-urls" | "clear-all";
@@ -395,6 +398,21 @@ allowedZipUrls: [
395
398
  ];
396
399
  ```
397
400
 
401
+ `requireExactManifestPath`
402
+
403
+ Defaults to `false`. Controls how the service worker resolves a requested inner path against the ZIP manifest.
404
+
405
+ - `false` (default): try an exact manifest key match first; if that fails, retry with `{zipBasename}/{requestedPath}` where `zipBasename` is the ZIP filename without the `.zip` extension (e.g. for `session.zip`, request `slides/image.png` falls back to manifest key `session/slides/image.png`).
406
+ - `true`: only exact manifest key matches are accepted.
407
+
408
+ When fallback resolution succeeds, the asset is still served normally, but `onError` is invoked informationally with details about the missed exact key and the resolved fallback key.
409
+
410
+ `onError`
411
+
412
+ Optional error handler for zip-peek failures and informational reports from the service worker. Receives `(error, info?)` where `info` carries additional context when available.
413
+
414
+ Besides initialization and fetch failures, `onError` is also called when exact manifest lookup fails but zip-basename folder fallback succeeds (see `requireExactManifestPath`). Use this to log or telemetry mismatches between request paths and manifest layout without blocking the response.
415
+
398
416
  `zipAssetCacheName`
399
417
 
400
418
  Overrides the browser Cache API bucket used by the service worker for ZIP manifests and extracted assets.
@@ -446,7 +464,79 @@ Content-Range: bytes start-end/total
446
464
 
447
465
  If the ZIP server does not support range requests, zip-peek cannot stream individual files.
448
466
 
449
- ### 2. The service worker file must be same-origin
467
+ ### 2. Configure CORS on the ZIP origin (required for cross-origin apps)
468
+
469
+ When your app and the ZIP URL are on **different origins** (for example, the app on `https://app.example.com` and the ZIP on `https://cdn.example.com`), the service worker performs **cross-origin** `fetch()` calls with a `Range` header on every manifest and entry read. That triggers a **CORS preflight** (`OPTIONS`). If CORS is misconfigured, the browser blocks the fetch and zip-peek logs `NetworkError when attempting to fetch resource.`
470
+
471
+ A normal CDN asset load (simple `GET` without `Range`) may work even when zip-peek fails — zip-peek has stricter requirements.
472
+
473
+ #### S3 bucket CORS
474
+
475
+ In the S3 console, open the ZIP bucket → **Permissions** → **Cross-origin resource sharing (CORS)** and add a rule like:
476
+
477
+ ```json
478
+ [
479
+ {
480
+ "AllowedHeaders": ["*"],
481
+ "AllowedMethods": ["GET", "HEAD"],
482
+ "AllowedOrigins": [
483
+ "https://your-app.example.com",
484
+ "http://localhost:3000"
485
+ ],
486
+ "ExposeHeaders": [
487
+ "Content-Range",
488
+ "Accept-Ranges"
489
+ ]
490
+ }
491
+ ]
492
+ ```
493
+
494
+ **Required for zip-peek:**
495
+
496
+ | Setting | Why |
497
+ |--------|-----|
498
+ | `AllowedHeaders: ["*"]` | Allows the `Range` request header (triggers preflight). |
499
+ | `AllowedMethods`: `GET`, `HEAD` | Manifest and asset reads. |
500
+ | `AllowedOrigins` | Must include your app origin(s). Use `*` only for quick local testing. |
501
+ | `ExposeHeaders`: **`Content-Range`**, **`Accept-Ranges`** | The service worker reads `Content-Range` when parsing the ZIP index. These two headers are **required** in `ExposeHeaders`. |
502
+
503
+ S3 answers `OPTIONS` preflight automatically when CORS is configured; you do not list `OPTIONS` in `AllowedMethods`.
504
+
505
+ #### CloudFront (when the ZIP is served through CloudFront)
506
+
507
+ S3 bucket CORS alone is often **not enough** when a CloudFront distribution sits in front of the bucket. CloudFront settings apply **per distribution and per behavior** — a working bucket on another path or origin does not guarantee the ZIP path is configured the same way.
508
+
509
+ On the CloudFront **behavior** that serves your ZIP objects, configure:
510
+
511
+ 1. **Allowed HTTP methods**: `GET`, `HEAD`, `OPTIONS`
512
+ `OPTIONS` is required so CORS preflight for `Range` requests succeeds.
513
+
514
+ 2. **Origin request policy**: **CORS-S3Origin** (AWS managed)
515
+ Forwards the `Origin` header (and related CORS preflight headers) to S3 so the bucket can return the correct CORS response.
516
+
517
+ 3. **Response headers policy**: **CORS** with **preflight** enabled
518
+ Ensures `Access-Control-Allow-Origin` and related headers are present on `206 Partial Content` responses. Match your app origin(s) in the policy.
519
+
520
+ After changing CORS or CloudFront settings, **invalidate the CloudFront cache** for the ZIP path so cached responses without CORS headers are not served.
521
+
522
+ **Verify from your app origin:**
523
+
524
+ ```bash
525
+ # Preflight — must not return 403
526
+ curl -sI -X OPTIONS \
527
+ -H "Origin: https://your-app.example.com" \
528
+ -H "Access-Control-Request-Method: GET" \
529
+ -H "Access-Control-Request-Headers: range" \
530
+ "https://cdn.example.com/packages/session.zip"
531
+
532
+ # Range GET — must return 206 with Access-Control-Allow-Origin
533
+ curl -sI -X GET \
534
+ -H "Origin: https://your-app.example.com" \
535
+ -H "Range: bytes=0-100" \
536
+ "https://cdn.example.com/packages/session.zip"
537
+ ```
538
+
539
+ ### 3. The service worker file must be same-origin
450
540
 
451
541
  Browsers require service worker scripts to be served from the same origin as the page.
452
542
 
@@ -462,7 +552,7 @@ Invalid if the page is on another origin:
462
552
  https://static-assets.example.com/zipServiceWorker.a1b2c3d4.js
463
553
  ```
464
554
 
465
- ### 3. Configure `Service-Worker-Allowed`
555
+ ### 4. Configure `Service-Worker-Allowed`
466
556
 
467
557
  By default, a service worker can only control pages under its own directory. If the worker file is served from a nested folder but needs to control a wider scope, the response for the worker file must include `Service-Worker-Allowed`.
468
558
 
@@ -480,7 +570,7 @@ Service-Worker-Allowed: /
480
570
 
481
571
  The header must be returned on the `zipServiceWorker.js` or `zipServiceWorker.<hash>.js` response itself.
482
572
 
483
- ### 4. Scope and worker location must match
573
+ ### 5. Scope and worker location must match
484
574
 
485
575
  The registered scope must be allowed by both:
486
576
 
@@ -620,11 +710,12 @@ For a detailed explanation of the modular service worker (`src/zipServiceWorker.
620
710
 
621
711
  - The ZIP URL must end with `.zip`.
622
712
  - The ZIP server must support HTTP range requests.
713
+ - Cross-origin ZIP URLs require CORS: S3 `ExposeHeaders` must expose `Content-Range` and `Accept-Ranges`; CloudFront (if used) must allow `GET`/`HEAD`/`OPTIONS` and use CORS-S3Origin plus a CORS response headers policy with preflight.
623
714
  - The service worker file must be same-origin.
624
715
  - The service worker can only intercept requests inside its registered scope.
625
716
  - Supported ZIP compression methods are stored (`0`) and deflated (`8`).
626
717
  - ZIP64 is not currently supported.
627
- - Ambiguous suffix path matches (e.g. two manifest keys ending in `/icon.png`) return 404.
718
+ - Manifest entry fallback prepends the ZIP basename only (e.g. `session/icon.png` for `session.zip`); generic `*/filename` suffix matching is not used.
628
719
  - Multi-range client requests are not supported (416).
629
720
  - The package is browser-only and depends on Service Worker, Cache API, and HTTP range request support.
630
721
 
package/dist/index.d.ts CHANGED
@@ -11,5 +11,5 @@ export type { InitZipPeekOptions, InitZipPeekResult, ZipCacheClearingStrategy, Z
11
11
  * `cacheClearingStrategy` to keep existing cache entries, keep only allowed
12
12
  * ZIP URLs, or clear all zip-peek cache entries before use.
13
13
  */
14
- export declare function initZipPeek({ workerUrl, scopeUrl, reloadOnFirstInstall, cacheClearingStrategy, allowedZipUrls, zipAssetCacheName, assetCacheTtlMs, logPrefix, onError, }: InitZipPeekOptions): Promise<InitZipPeekResult>;
14
+ export declare function initZipPeek({ workerUrl, scopeUrl, reloadOnFirstInstall, cacheClearingStrategy, allowedZipUrls, requireExactManifestPath, zipAssetCacheName, assetCacheTtlMs, logPrefix, onError, }: InitZipPeekOptions): Promise<InitZipPeekResult>;
15
15
  export { isZipPackage };
package/dist/index.js CHANGED
@@ -195,7 +195,7 @@ async function postWorkerMessageOrThrow(message, info) {
195
195
  * `cacheClearingStrategy` to keep existing cache entries, keep only allowed
196
196
  * ZIP URLs, or clear all zip-peek cache entries before use.
197
197
  */
198
- async function initZipPeek({ workerUrl, scopeUrl, reloadOnFirstInstall = true, cacheClearingStrategy = "keep-all", allowedZipUrls, zipAssetCacheName, assetCacheTtlMs, logPrefix, onError, }) {
198
+ async function initZipPeek({ workerUrl, scopeUrl, reloadOnFirstInstall = true, cacheClearingStrategy = "keep-all", allowedZipUrls, requireExactManifestPath = false, zipAssetCacheName, assetCacheTtlMs, logPrefix, onError, }) {
199
199
  if (onError) {
200
200
  currentOnError = onError;
201
201
  }
@@ -230,6 +230,7 @@ async function initZipPeek({ workerUrl, scopeUrl, reloadOnFirstInstall = true, c
230
230
  assetCacheTtlMs,
231
231
  logPrefix,
232
232
  allowedZipUrls: normalizedAllowedZipUrls ?? null,
233
+ requireExactManifestPath,
233
234
  },
234
235
  }, "Failed to configure service worker");
235
236
  if (cacheClearingStrategy === "clear-all") {
@@ -243,6 +244,7 @@ async function initZipPeek({ workerUrl, scopeUrl, reloadOnFirstInstall = true, c
243
244
  assetCacheTtlMs,
244
245
  logPrefix,
245
246
  allowedZipUrls: normalizedAllowedZipUrls ?? null,
247
+ requireExactManifestPath,
246
248
  },
247
249
  }, "Failed to reconfigure service worker after cache clear");
248
250
  }
package/dist/types.d.ts CHANGED
@@ -11,6 +11,7 @@ export type InitZipPeekOptions = {
11
11
  reloadOnFirstInstall?: boolean;
12
12
  cacheClearingStrategy?: ZipCacheClearingStrategy;
13
13
  allowedZipUrls?: string[];
14
+ requireExactManifestPath?: boolean;
14
15
  zipAssetCacheName?: string;
15
16
  assetCacheTtlMs?: number;
16
17
  logPrefix?: string;
@@ -12,6 +12,8 @@ export type NormalizeZipUrlOptions = {
12
12
  * are not re-encoded.
13
13
  */
14
14
  export declare function normalizeZipUrl(urlString: string, options?: NormalizeZipUrlOptions): string;
15
+ /** Basename of the ZIP file from a package URL, without the `.zip` extension. */
16
+ export declare function zipBasenameWithoutExtension(zipUrl: string): string;
15
17
  /** Align zip entry names with URL paths under `*.zip/…`. */
16
18
  export declare function normalizeZipEntryPath(name: string): string;
17
19
  export type ParsedZipAssetRequest = {
package/dist/zip-utils.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isZipPackage = isZipPackage;
4
4
  exports.normalizeZipUrl = normalizeZipUrl;
5
+ exports.zipBasenameWithoutExtension = zipBasenameWithoutExtension;
5
6
  exports.normalizeZipEntryPath = normalizeZipEntryPath;
6
7
  exports.parseZipAssetRequest = parseZipAssetRequest;
7
8
  exports.canonicalZipAssetRequestUrl = canonicalZipAssetRequestUrl;
@@ -44,6 +45,19 @@ function normalizeZipUrl(urlString, options = {}) {
44
45
  return prefix + hashSection;
45
46
  return prefix + "?" + filtered.join("&") + hashSection;
46
47
  }
48
+ /** Basename of the ZIP file from a package URL, without the `.zip` extension. */
49
+ function zipBasenameWithoutExtension(zipUrl) {
50
+ try {
51
+ const pathname = new URL(zipUrl, "http://local").pathname;
52
+ const file = pathname.split("/").pop() ?? "";
53
+ return file.endsWith(".zip") ? file.slice(0, -4) : file;
54
+ }
55
+ catch {
56
+ const path = zipUrl.split("?")[0].split("#")[0];
57
+ const file = path.split("/").pop() ?? "";
58
+ return file.endsWith(".zip") ? file.slice(0, -4) : file;
59
+ }
60
+ }
47
61
  /** Align zip entry names with URL paths under `*.zip/…`. */
48
62
  function normalizeZipEntryPath(name) {
49
63
  let s = name.replace(/\\/g, "/"); // Replace backslashes with forward slashes.
@@ -1,2 +1,2 @@
1
- (()=>{"use strict";var t={257(t,e){function n(t){const n=t.trim();return n.startsWith(e.ZIP_PEEK_ERROR_PREFIX)?n:`${e.ZIP_PEEK_ERROR_PREFIX} ${n}`}Object.defineProperty(e,"__esModule",{value:!0}),e.ZIP_PEEK_ERROR_PREFIX=void 0,e.formatZipPeekError=n,e.createZipPeekError=function(t){return new Error(n(t))},e.toZipPeekError=function(t){const r=t instanceof Error?t:new Error(String(t));return r.message.startsWith(e.ZIP_PEEK_ERROR_PREFIX)||(r.message=n(r.message)),r},e.errorMessage=function(t){return t instanceof Error?t.message:String(t)},e.ZIP_PEEK_ERROR_PREFIX="[zip-peek-error]"},978(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.persistAllowedZipUrlsConfig=o,e.ensureAllowedZipUrlsLoaded=async function(){if(i.allowedZipUrlsLoaded)return i.allowedZipUrlsLoaded;const t=(async()=>{try{const t=await caches.open(i.CONFIG_CACHE_NAME),e=await t.match(i.CONFIG_CACHE_KEY);if(!e)return;const n=await e.json();Array.isArray(n.allowedZipUrls)?(0,i.setAllowedZipUrls)(new Set(n.allowedZipUrls.filter(t=>"string"==typeof t).map(t=>(0,r.normalizeZipUrl)(t)))):(0,i.setAllowedZipUrls)(null)}catch(t){(0,s.warn)("failed to load runtime config",t)}})();return(0,i.setAllowedZipUrlsLoaded)(t),t},e.applyRuntimeConfig=async function(t){if(!t)return;let e={...i.runtimeConfig},n=!1;if("string"==typeof t.zipAssetCacheName&&t.zipAssetCacheName.trim()&&(e.zipAssetCacheName=t.zipAssetCacheName,n=!0),"number"==typeof t.assetCacheTtlMs&&Number.isFinite(t.assetCacheTtlMs)&&(e.assetCacheTtlMs=t.assetCacheTtlMs,n=!0),"string"==typeof t.logPrefix&&t.logPrefix.trim()&&(e.logPrefix=t.logPrefix,n=!0),n&&(0,i.setRuntimeConfig)(e),"allowedZipUrls"in t){const e=Array.isArray(t.allowedZipUrls)?t.allowedZipUrls.map(t=>(0,r.normalizeZipUrl)(t)):null;(0,i.setAllowedZipUrls)(e?new Set(e):null),(0,i.setAllowedZipUrlsLoaded)(Promise.resolve()),await o(e)}},e.isZipUrlAllowed=function(t){return null===i.allowedZipUrls||i.allowedZipUrls.has(t)};const r=n(183),i=n(950),s=n(842);async function o(t){try{const e=await caches.open(i.CONFIG_CACHE_NAME);await e.put(new Request(i.CONFIG_CACHE_KEY),new Response(JSON.stringify({allowedZipUrls:t}),{headers:{"Content-Type":"application/json"}}))}catch(t){(0,s.warn)("failed to persist runtime config",t)}}},752(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.canonicalAssetRequest=function(t,e){return new Request((0,i.canonicalZipAssetRequestUrl)(t,e),{method:"GET"})},e.assetCacheEntryExpired=l,e.clearAllZipAssets=async function(){const t=await caches.open(s.runtimeConfig.zipAssetCacheName),e=await t.keys();await Promise.all(e.map(e=>t.delete(e))),await caches.delete(s.CONFIG_CACHE_NAME),s.zipManifests.clear(),s.pendingManifestLoads.clear(),(0,s.setAllowedZipUrlsLoaded)(Promise.resolve())},e.clearZipAssetsExceptAllowed=async function(t){try{const e=new Set(t),n=await caches.open(s.runtimeConfig.zipAssetCacheName),r=await n.keys();for(const t of r){const r=t.url;if(r.includes(s.MANIFEST_CACHE_KEY)){const i=(0,a.zipUrlFromManifestCacheKey)(r);i&&!e.has(i)&&await n.delete(t);continue}const o=(0,i.parseZipAssetRequest)(r);o&&!e.has(o.zipUrl)&&await n.delete(t)}for(const t of s.zipManifests.keys())e.has(t)||s.zipManifests.delete(t)}catch(t){throw(0,r.createZipPeekError)(`Failed to clear zip assets except allowed URLs: ${(0,r.errorMessage)(t)}`)}},e.putCachedFullAssetIfAbsent=async function(t,e){try{const n=await caches.open(s.runtimeConfig.zipAssetCacheName),r=await n.match(t);if(r&&!l(r))return;const i=e.type||"application/octet-stream";await n.put(t,new Response(e,{status:200,headers:{"Content-Type":i,"Content-Length":String(e.size),"Access-Control-Allow-Origin":"*",[s.ASSET_CACHED_AT_HEADER]:String(Date.now())}}))}catch(t){(0,o.warn)("asset cache put failed",t)}},e.readCachedZipAssetIfFresh=async function(t){let e=null,n="network";try{const r=await caches.open(s.runtimeConfig.zipAssetCacheName),i=await r.match(t);if(i)if(l(i))try{await r.delete(t)}catch(t){(0,o.warn)("asset cache delete expired failed",t)}else e=await i.blob(),n="cache-api"}catch(t){(0,o.warn)("asset cache read failed",t)}return{blob:e,assetSource:n}};const r=n(257),i=n(183),s=n(950),o=n(842),a=n(234);function l(t){const e=t.headers.get(s.ASSET_CACHED_AT_HEADER);if(!e)return!0;const n=parseInt(e,10);return!Number.isFinite(n)||Date.now()-n>s.runtimeConfig.assetCacheTtlMs}},886(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.installFetchHandler=function(){self.addEventListener("fetch",t=>{if("GET"!==t.request.method)return;const e=(0,i.parseZipAssetRequest)(t.request.url);if(!e)return;const n=(0,i.normalizeZipUrl)(e.zipUrl),f=e.internalPath,h=(0,i.normalizeZipEntryPath)(f);t.respondWith((async()=>{try{if(await(0,s.ensureAllowedZipUrlsLoaded)(),!(0,s.isZipUrlAllowed)(n))return(0,l.warn)("zip URL not allowed",{requestedZipUrl:n}),(0,c.corsErrorResponse)(`ZIP URL not allowed (not in allowedZipUrls): ${n}`,403);let e=a.zipManifests.get(n);if(e||(e=await(0,u.ensureManifestAvailable)(n,t.clientId||void 0)??void 0),!e){const t=Array.from(a.zipManifests.keys());return(0,l.warn)("manifest missing for zipUrl",{requestedZipUrl:n,knownZipUrls:t}),(0,c.corsErrorResponse)(`ZIP manifest not loaded for ${n}. Ensure the ZIP is reachable and supports byte-range requests.`,404)}const r=(0,u.resolveManifestEntry)(e,h);if(!r){const t=Array.from(e.keys()).slice(0,50);return(0,l.warn)("file not in manifest or ambiguous suffix match",{zipUrl:n,internalPathRaw:f,internalPathNormalized:h,manifestSize:e.size,sampleKeys:t}),(0,c.corsErrorResponse)(`File "${f}" not found in ZIP manifest for ${n}`,404)}const{key:i,info:p}=r;i!==h&&(0,l.log)("resolved via suffix match",{requested:h,manifestKey:i});const d=(0,o.canonicalAssetRequest)(n,i);let{blob:g,assetSource:v}=await(0,o.readCachedZipAssetIfFresh)(d);if(!g){const t=await(0,c.fetchUncompressedZipEntryFromNetwork)(n,i,p,d);if(!t.ok)return t.response;g=t.blob,v="network"}if(t.request.headers.has("range")){const e=t.request.headers.get("range").replace(/^bytes=/,"");if(e.includes(","))return new Response(null,{status:416,headers:{"Content-Range":`bytes */${g.size}`,"Access-Control-Allow-Origin":"*"}});const[n,r]=e.split("-"),i=""!==n?parseInt(n,10):NaN,s=""!==r?parseInt(r,10):g.size-1;if(isNaN(i)||isNaN(s)||i<0||s<i||i>=g.size)return new Response(null,{status:416,headers:{"Content-Range":`bytes */${g.size}`,"Access-Control-Allow-Origin":"*"}});const o=Math.min(s,g.size-1),l=g.slice(i,o+1);return new Response(l,{status:206,headers:{"Content-Type":g.type,"Content-Range":`bytes ${i}-${o}/${g.size}`,"Content-Length":l.size.toString(),"Accept-Ranges":"bytes","Access-Control-Allow-Origin":"*","Access-Control-Expose-Headers":a.ASSET_SOURCE_HEADER,[a.ASSET_SOURCE_HEADER]:v}})}return new Response(g,{status:200,headers:{"Content-Type":g.type,"Content-Length":g.size.toString(),"Access-Control-Allow-Origin":"*","Access-Control-Expose-Headers":a.ASSET_SOURCE_HEADER,[a.ASSET_SOURCE_HEADER]:v}})}catch(t){return(0,l.error)("fetch handler failed",{zipUrl:n,internalPath:f,message:(0,r.errorMessage)(t)}),(0,c.corsErrorResponse)(`Failed to serve "${f}" from ${n}: ${(0,r.errorMessage)(t)}`,500)}})())})};const r=n(257),i=n(183),s=n(978),o=n(752),a=n(950),l=n(842),u=n(234),c=n(878)},950(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.CONFIG_CACHE_KEY=e.allowedZipUrlsLoaded=e.allowedZipUrls=e.runtimeConfig=e.pendingManifestLoads=e.zipManifests=e.MANIFEST_CACHE_KEY=e.LOCAL_FILE_HEADER_SIG=e.MIME_TYPES=e.ASSET_SOURCE_HEADER=e.ASSET_CACHED_AT_HEADER=e.ALLOWED_CACHE_NAMES=e.CONFIG_CACHE_NAME=e.DEFAULT_ASSET_CACHE_TTL_MS=e.DEFAULT_ZIP_ASSET_CACHE_NAME=void 0,e.setRuntimeConfig=function(t){e.runtimeConfig=t},e.setAllowedZipUrls=function(t){e.allowedZipUrls=t},e.setAllowedZipUrlsLoaded=function(t){e.allowedZipUrlsLoaded=t},e.DEFAULT_ZIP_ASSET_CACHE_NAME="zip-cache-v1",e.DEFAULT_ASSET_CACHE_TTL_MS=72e5,e.CONFIG_CACHE_NAME="zip-peek-config-v1",e.ALLOWED_CACHE_NAMES=[e.DEFAULT_ZIP_ASSET_CACHE_NAME,e.CONFIG_CACHE_NAME],e.ASSET_CACHED_AT_HEADER="X-ZipSW-Cached-At",e.ASSET_SOURCE_HEADER="X-ZipSW-Asset-Source",e.MIME_TYPES={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",json:"application/json",js:"application/javascript",css:"text/css; charset=utf-8",html:"text/html; charset=utf-8",txt:"text/plain; charset=utf-8",mp4:"video/mp4",webm:"video/webm",mp3:"audio/mpeg",wav:"audio/wav",oga:"audio/ogg",ogg:"audio/ogg",xml:"application/xml",wasm:"application/wasm"},e.LOCAL_FILE_HEADER_SIG=67324752,e.MANIFEST_CACHE_KEY="__zipsw_manifest__=1",e.zipManifests=new Map,e.pendingManifestLoads=new Map,e.runtimeConfig={zipAssetCacheName:e.DEFAULT_ZIP_ASSET_CACHE_NAME,assetCacheTtlMs:e.DEFAULT_ASSET_CACHE_TTL_MS,logPrefix:"[zipSW]"},e.allowedZipUrls=null,e.allowedZipUrlsLoaded=null,e.CONFIG_CACHE_KEY=new URL("__zip_peek_runtime_config__",self.registration.scope).href},842(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.log=function(...t){console.log(i.runtimeConfig.logPrefix,...t)},e.warn=function(...t){console.warn(i.runtimeConfig.logPrefix,...t)},e.error=function(...t){console.error(i.runtimeConfig.logPrefix,r.ZIP_PEEK_ERROR_PREFIX,...t)},e.reportClientError=s,e.installClientErrorReporting=function(){self.addEventListener("error",t=>{s(t.error??t.message,"Service worker uncaught error")}),self.addEventListener("unhandledrejection",t=>{s(t.reason,"Service worker unhandled promise rejection")})};const r=n(257),i=n(950);function s(t,e){const n=(0,r.toZipPeekError)(t);self.clients.matchAll({type:"window",includeUncontrolled:!0}).then(t=>{const i={type:"ZIP_SW_ERROR",error:{message:n.message,stack:n.stack},info:e?(0,r.formatZipPeekError)(e):void 0};for(const e of t)e.postMessage(i)})}},234(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.manifestCacheKey=function(t){return t+(t.includes("?")?"&":"?")+i.MANIFEST_CACHE_KEY},e.parseCentralDirectoryToManifest=o,e.manifestFilesToMap=a,e.sendManifestToClientId=u,e.loadManifestFromClientId=c,e.fetchZipManifest=f,e.ensureManifestAvailable=function(t,e){const n=i.zipManifests.get(t);if(n)return Promise.resolve(n);let r=i.pendingManifestLoads.get(t);return r||(r=(async()=>{const n=await c(t,e);if(n)return i.zipManifests.set(t,n),(0,s.log)("restored manifest from client memory",{zipUrl:t,entryCount:n.size}),n;const r=await f(t);return r&&(i.zipManifests.set(t,r),await u(t,r,e),(0,s.log)("manifest fetched and stored in memory",{zipUrl:t,entryCount:r.size})),r})().finally(()=>{i.pendingManifestLoads.delete(t)}),i.pendingManifestLoads.set(t,r),r)},e.resolveManifestEntry=function(t,e){if(t.has(e))return{key:e,info:t.get(e)};const n=[];for(const r of t.keys())r.endsWith("/"+e)&&n.push(r);if(1===n.length){const e=n[0];return{key:e,info:t.get(e)}}return n.length>1?((0,s.error)("ambiguous suffix match for ZIP entry",{requested:e,candidates:n.slice(0,8)}),null):null},e.zipUrlFromManifestCacheKey=function(t){const e=i.MANIFEST_CACHE_KEY;if(!t.endsWith(e))return null;let n=t.slice(0,-e.length);return(n.endsWith("?")||n.endsWith("&"))&&(n=n.slice(0,-1)),n};const r=n(183),i=n(950),s=n(842);function o(t,e,n,i){const o=new DataView(t);let a=e;const l=[];for(;a+46<=t.byteLength&&33639248===o.getUint32(a,!0);){const e=o.getUint16(a+10,!0),n=o.getUint32(a+20,!0),i=o.getUint16(a+28,!0),s=o.getUint16(a+30,!0),u=o.getUint16(a+32,!0),c=o.getUint32(a+42,!0),f=new TextDecoder;if(a+46+i>t.byteLength)break;const h=new Uint8Array(t,a+46,i),p=f.decode(h),d=(0,r.normalizeZipEntryPath)(p);""!==d&&l.push({filename:d,offset:c,compressedSize:n,compression:e}),a+=46+i+s+u}if(0===l.length)return(0,s.error)("no files parsed from central directory",i),null;l.sort((t,e)=>t.offset-e.offset);const u=new Map;for(let t=0;t<l.length;t++){const e=l[t],i=(0,r.normalizeZipEntryPath)(e.filename);""!==i&&(u.has(i)&&(0,s.warn)("duplicate manifest key after normalize; overwriting",i),u.set(i,{filename:e.filename,offset:e.offset,compressedSize:e.compressedSize,compression:e.compression,nextOffset:t<l.length-1?l[t+1].offset:n}))}return u.size>0?u:null}function a(t){const e=new Map;for(const n of t){const t=(0,r.normalizeZipEntryPath)(n.filename);""!==t&&(e.has(t)&&(0,s.warn)("duplicate manifest key after normalize; overwriting",t),e.set(t,n))}return e.size>0?e:null}async function l(t){if(!t)return null;const e=await self.clients.get(t);return"window"===e?.type?e:null}async function u(t,e,n){const r=await l(n);if(!r)return;const i=Array.from(e.values());try{r.postMessage({type:"ZIP_SW_MANIFEST_CREATED",zipUrl:t,files:i})}catch(t){(0,s.warn)("failed to send manifest to client",t)}}async function c(t,e){const n=await l(e);return n?function(t,e){return new Promise(n=>{const r=new MessageChannel,i=setTimeout(()=>{r.port1.close(),n(null)},500);r.port1.onmessage=t=>{clearTimeout(i),r.port1.close();const e=t.data;e?.ok&&Array.isArray(e.files)?n(a(e.files)):n(null)},r.port1.onmessageerror=()=>{clearTimeout(i),r.port1.close(),n(null)};try{t.postMessage({type:"ZIP_SW_MANIFEST_REQUEST",zipUrl:e},[r.port2])}catch(t){clearTimeout(i),r.port1.close(),(0,s.warn)("failed to request manifest from client",t),n(null)}})}(n,t):null}async function f(t){const e=await fetch(t,{headers:{Range:"bytes=-65536"}});if(206!==e.status)return(0,s.error)("range requests not supported for ZIP manifest",{zipUrl:t,status:e.status}),null;const n=await e.arrayBuffer(),r=new DataView(n);let i=-1;for(let t=n.byteLength-22;t>=0;t--)if(101010256===r.getUint32(t,!0)){i=t;break}if(-1===i)return(0,s.error)("EOCD not found in last 64KB of ZIP file",t),null;const a=r.getUint32(i+16,!0),l=r.getUint32(i+12,!0);let u=n,c=-1;const f=e.headers.get("Content-Range");let h=0;if(f){const t=f.match(/\/(\d+)$/);t&&(h=parseInt(t[1],10))}if(h<=0)return(0,s.error)("could not determine ZIP file size from Content-Range header",{zipUrl:t,contentRange:f}),null;const p=h-n.byteLength;if(a>=p)c=a-p;else{const e=await fetch(t,{headers:{Range:`bytes=${a}-${a+l-1}`}});if(206!==e.status)return(0,s.error)("failed to fetch ZIP central directory",{zipUrl:t,status:e.status,cdOffset:a,cdSize:l}),null;u=await e.arrayBuffer(),c=0}return o(u,c,a,t)}},49(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.replyToMessage=f,e.installMessageHandler=function(){self.addEventListener("message",t=>{if(!t.data)return;const{type:e,zipUrl:n,files:h,config:p,allowedZipUrls:d}=t.data,g=function(t){if(!t||!("id"in t))return;const e=t.id;return"string"==typeof e?e:void 0}(t.source);if("ZIP_SW_CONFIG"===e){const e=(0,s.applyRuntimeConfig)(p).then(()=>f(t,{ok:!0})).catch(e=>f(t,c(e)));return void t.waitUntil(e)}if("ZIP_MANIFEST"===e){if(n&&h){const e=(0,i.normalizeZipUrl)(n),r=(0,u.manifestFilesToMap)(h),s=a.zipManifests.get(e);if(!r)return void(0,l.warn)("rejecting empty manifest; keeping existing",{zipUrl:e,existingSize:s?s.size:0});if(s&&s.size>r.size)return void(0,l.warn)("rejecting smaller manifest; keeping existing",{zipUrl:e,incomingSize:r.size,existingSize:s.size});a.zipManifests.set(e,r),t.waitUntil((0,u.sendManifestToClientId)(e,r,g));const o=Array.from(r.keys()).slice(0,40);(0,l.log)("ZIP_MANIFEST loaded",{zipUrl:e,entryCount:r.size,sampleKeys:o,replacedExistingSize:s?s.size:0})}}else if("CLEAR_ZIP_ASSETS_EXCEPT_ALLOWED"===e&&d){const e=(0,o.clearZipAssetsExceptAllowed)(d).then(()=>f(t,{ok:!0})).catch(e=>f(t,c(e)));t.waitUntil(e)}else if("CLEAR_ALL_ZIP_ASSETS"===e){const e=(0,o.clearAllZipAssets)().then(()=>f(t,{ok:!0})).catch(e=>f(t,c(e)));t.waitUntil(e)}else if("PRELOAD_ZIP_MANIFESTS"===e&&d){const e=async function(t,e){const n=await Promise.all(t.map(async t=>({zipUrl:t,manifest:await(0,u.ensureManifestAvailable)(t,e)}))),i=n.filter(t=>!t.manifest).map(t=>t.zipUrl);if(i.length>0)throw(0,r.createZipPeekError)(`Failed to preload ZIP manifest(s): ${i.join(", ")}`)}(d,g).then(()=>f(t,{ok:!0})).catch(e=>f(t,c(e)));t.waitUntil(e)}})};const r=n(257),i=n(183),s=n(978),o=n(752),a=n(950),l=n(842),u=n(234);function c(t){const e=(0,r.toZipPeekError)(t);return{ok:!1,error:e.message,errorStack:e.stack}}function f(t,e){t.ports[0]?.postMessage(e)}},878(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.corsErrorResponse=l,e.getMimeType=u,e.fetchUncompressedZipEntryFromNetwork=async function(t,e,n,i){const c=n.offset,f=n.nextOffset-1;(0,o.log)("fetching zip chunk from",{zipUrl:t,rangeStart:c,rangeEnd:f});const h=await fetch(t,{headers:{Range:`bytes=${c}-${f}`}});if(206!==h.status)return{ok:!1,response:l(`ZIP entry fetch for "${e}" expected HTTP 206 Partial Content from ${t}, got ${h.status}`,h.status>=400?h.status:502)};const p=await h.arrayBuffer(),d=new DataView(p);if(d.getUint32(0,!0)!==s.LOCAL_FILE_HEADER_SIG)return{ok:!1,response:l(`Invalid local file header for "${e}" in ${t} (expected ZIP signature 0x04034b50)`,500)};const g=30+d.getUint16(26,!0)+d.getUint16(28,!0);if(g>p.byteLength||g+n.compressedSize>p.byteLength)return{ok:!1,response:l(`Corrupt ZIP entry "${e}" in ${t}: dataStart=${g}, compressedSize=${n.compressedSize}, bufferLength=${p.byteLength}`,500)};const v=new Uint8Array(p,g,n.compressedSize);let m;if(8===n.compression)try{m=(0,r.inflateSync)(v)}catch(n){return(0,o.warn)("inflateSync failed",{zipUrl:t,manifestKey:e,error:n}),{ok:!1,response:l(`Failed to inflate DEFLATE-compressed entry "${e}" in ${t}`,500)}}else{if(0!==n.compression)return{ok:!1,response:l(`Unsupported compression method ${n.compression} for "${e}" in ${t} (only stored/0 and DEFLATE/8 are supported)`,500)};m=v}const y=u(e),w=new Blob([m],{type:y});return await(0,a.putCachedFullAssetIfAbsent)(i,w),{ok:!0,blob:w}};const r=n(845),i=n(257),s=n(950),o=n(842),a=n(752);function l(t,e){return new Response((0,i.formatZipPeekError)(t),{status:e,headers:{"Access-Control-Allow-Origin":"*"}})}function u(t){const e=t.split(".").pop()?.toLowerCase();return e?s.MIME_TYPES[e]??"application/octet-stream":"application/octet-stream"}},183(t,e){function n(t){try{return decodeURIComponent(t)}catch{return t}}Object.defineProperty(e,"__esModule",{value:!0}),e.isZipPackage=function(t){try{return new URL(t).pathname.endsWith(".zip")}catch{return t.split("?")[0].endsWith(".zip")}},e.normalizeZipUrl=function(t,e={}){const{stripCacheBuster:n=!0,stripHash:r=!0}=e,i=t=>r?t.split("#")[0]:t;if(!n)return i(t);const s=t.indexOf("?");if(-1===s)return i(t);const o=t.indexOf("#",s),a=t.substring(0,s),l=-1===o?t.substring(s+1):t.substring(s+1,o),u=r||-1===o?"":t.substring(o),c=l.split("&").filter(t=>{const e=t.indexOf("=");return"t"!==(-1===e?t:t.substring(0,e))});return 0===c.length?a+u:a+"?"+c.join("&")+u},e.normalizeZipEntryPath=function(t){let e=t.replace(/\\/g,"/");for(;e.startsWith("/");)e=e.slice(1);return e},e.parseZipAssetRequest=function(t){const e=/\.zip([/?])/.exec(t);if(!e)return null;const r=e.index+4,i=e[1],s=t.substring(0,r);if("/"===i){const e=t.substring(r+1),i=e.indexOf("?"),o=-1===i?e:e.substring(0,i);return""===o?null:{zipUrl:s,internalPath:n(o)}}const o=t.substring(r),a=o.indexOf("/");if(-1===a)return null;const l=o.substring(0,a),u=o.substring(a+1),c=u.indexOf("?"),f=-1===c?u:u.substring(0,c);return""===f?null:{zipUrl:s+l,internalPath:n(f)}},e.canonicalZipAssetRequestUrl=function(t,e){return t+"/"+encodeURIComponent(e)}},845(t,e){var n={},r=function(t,e,r,i,s){var o=new Worker(n[e]||(n[e]=URL.createObjectURL(new Blob([t+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return o.onmessage=function(t){var e=t.data,n=e.$e$;if(n){var r=new Error(n[0]);r.code=n[1],r.stack=n[2],s(r,null)}else s(null,e)},o.postMessage(r,i),o},i=Uint8Array,s=Uint16Array,o=Int32Array,a=new i([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),l=new i([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),u=new i([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),c=function(t,e){for(var n=new s(31),r=0;r<31;++r)n[r]=e+=1<<t[r-1];var i=new o(n[30]);for(r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)i[a]=a-n[r]<<5|r;return{b:n,r:i}},f=c(a,2),h=f.b,p=f.r;h[28]=258,p[258]=28;for(var d=c(l,0),g=d.b,v=d.r,m=new s(32768),y=0;y<32768;++y){var w=(43690&y)>>1|(21845&y)<<1;w=(61680&(w=(52428&w)>>2|(13107&w)<<2))>>4|(3855&w)<<4,m[y]=((65280&w)>>8|(255&w)<<8)>>1}var E=function(t,e,n){for(var r=t.length,i=0,o=new s(e);i<r;++i)t[i]&&++o[t[i]-1];var a,l=new s(e);for(i=1;i<e;++i)l[i]=l[i-1]+o[i-1]<<1;if(n){a=new s(1<<e);var u=15-e;for(i=0;i<r;++i)if(t[i])for(var c=i<<4|t[i],f=e-t[i],h=l[t[i]-1]++<<f,p=h|(1<<f)-1;h<=p;++h)a[m[h]>>u]=c}else for(a=new s(r),i=0;i<r;++i)t[i]&&(a[i]=m[l[t[i]-1]++]>>15-t[i]);return a},A=new i(288);for(y=0;y<144;++y)A[y]=8;for(y=144;y<256;++y)A[y]=9;for(y=256;y<280;++y)A[y]=7;for(y=280;y<288;++y)A[y]=8;var C=new i(32);for(y=0;y<32;++y)C[y]=5;var b=E(A,9,0),_=E(A,9,1),z=E(C,5,0),S=E(C,5,1),M=function(t){for(var e=t[0],n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},U=function(t,e,n){var r=e/8|0;return(t[r]|t[r+1]<<8)>>(7&e)&n},Z=function(t,e){var n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(7&e)},I=function(t){return(t+7)/8|0},T=function(t,e,n){return(null==e||e<0)&&(e=0),(null==n||n>t.length)&&(n=t.length),new i(t.subarray(e,n))};e.FlateErrorCode={UnexpectedEOF:0,InvalidBlockType:1,InvalidLengthLiteral:2,InvalidDistance:3,StreamFinished:4,NoStreamHandler:5,InvalidHeader:6,NoCallback:7,InvalidUTF8:8,ExtraFieldTooLong:9,InvalidDate:10,FilenameTooLong:11,StreamFinishing:12,InvalidZipData:13,UnknownCompressionMethod:14};var P=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],R=function(t,e,n){var r=new Error(e||P[t]);if(r.code=t,Error.captureStackTrace&&Error.captureStackTrace(r,R),!n)throw r;return r},k=function(t,e,n,r){var s=t.length,o=r?r.length:0;if(!s||e.f&&!e.l)return n||new i(0);var c=!n,f=c||2!=e.i,p=e.i;c&&(n=new i(3*s));var d=function(t){var e=n.length;if(t>e){var r=new i(Math.max(2*e,t));r.set(n),n=r}},v=e.f||0,m=e.p||0,y=e.b||0,w=e.l,A=e.d,C=e.m,b=e.n,z=8*s;do{if(!w){v=U(t,m,1);var P=U(t,m+1,3);if(m+=3,!P){var k=t[(G=I(m)+4)-4]|t[G-3]<<8,L=G+k;if(L>s){p&&R(0);break}f&&d(y+k),n.set(t.subarray(G,L),y),e.b=y+=k,e.p=m=8*L,e.f=v;continue}if(1==P)w=_,A=S,C=9,b=5;else if(2==P){var x=U(t,m,31)+257,F=U(t,m+10,15)+4,O=x+U(t,m+5,31)+1;m+=14;for(var D=new i(O),N=new i(19),H=0;H<F;++H)N[u[H]]=U(t,m+3*H,7);m+=3*F;var $=M(N),j=(1<<$)-1,q=E(N,$,1);for(H=0;H<O;){var G,K=q[U(t,m,j)];if(m+=15&K,(G=K>>4)<16)D[H++]=G;else{var W=0,Y=0;for(16==G?(Y=3+U(t,m,3),m+=2,W=D[H-1]):17==G?(Y=3+U(t,m,7),m+=3):18==G&&(Y=11+U(t,m,127),m+=7);Y--;)D[H++]=W}}var X=D.subarray(0,x),B=D.subarray(x);C=M(X),b=M(B),w=E(X,C,1),A=E(B,b,1)}else R(1);if(m>z){p&&R(0);break}}f&&d(y+131072);for(var V=(1<<C)-1,J=(1<<b)-1,Q=m;;Q=m){var tt=(W=w[Z(t,m)&V])>>4;if((m+=15&W)>z){p&&R(0);break}if(W||R(2),tt<256)n[y++]=tt;else{if(256==tt){Q=m,w=null;break}var et=tt-254;if(tt>264){var nt=a[H=tt-257];et=U(t,m,(1<<nt)-1)+h[H],m+=nt}var rt=A[Z(t,m)&J],it=rt>>4;if(rt||R(3),m+=15&rt,B=g[it],it>3&&(nt=l[it],B+=Z(t,m)&(1<<nt)-1,m+=nt),m>z){p&&R(0);break}f&&d(y+131072);var st=y+et;if(y<B){var ot=o-B,at=Math.min(B,st);for(ot+y<0&&R(3);y<at;++y)n[y]=r[ot+y]}for(;y<st;++y)n[y]=n[y-B]}}e.l=w,e.p=Q,e.b=y,e.f=v,w&&(v=1,e.m=C,e.d=A,e.n=b)}while(!v);return y!=n.length&&c?T(n,0,y):n.subarray(0,y)},L=function(t,e,n){n<<=7&e;var r=e/8|0;t[r]|=n,t[r+1]|=n>>8},x=function(t,e,n){n<<=7&e;var r=e/8|0;t[r]|=n,t[r+1]|=n>>8,t[r+2]|=n>>16},F=function(t,e){for(var n=[],r=0;r<t.length;++r)t[r]&&n.push({s:r,f:t[r]});var o=n.length,a=n.slice();if(!o)return{t:q,l:0};if(1==o){var l=new i(n[0].s+1);return l[n[0].s]=1,{t:l,l:1}}n.sort(function(t,e){return t.f-e.f}),n.push({s:-1,f:25001});var u=n[0],c=n[1],f=0,h=1,p=2;for(n[0]={s:-1,f:u.f+c.f,l:u,r:c};h!=o-1;)u=n[n[f].f<n[p].f?f++:p++],c=n[f!=h&&n[f].f<n[p].f?f++:p++],n[h++]={s:-1,f:u.f+c.f,l:u,r:c};var d=a[0].s;for(r=1;r<o;++r)a[r].s>d&&(d=a[r].s);var g=new s(d+1),v=O(n[h-1],g,0);if(v>e){r=0;var m=0,y=v-e,w=1<<y;for(a.sort(function(t,e){return g[e.s]-g[t.s]||t.f-e.f});r<o;++r){var E=a[r].s;if(!(g[E]>e))break;m+=w-(1<<v-g[E]),g[E]=e}for(m>>=y;m>0;){var A=a[r].s;g[A]<e?m-=1<<e-g[A]++-1:++r}for(;r>=0&&m;--r){var C=a[r].s;g[C]==e&&(--g[C],++m)}v=e}return{t:new i(g),l:v}},O=function(t,e,n){return-1==t.s?Math.max(O(t.l,e,n+1),O(t.r,e,n+1)):e[t.s]=n},D=function(t){for(var e=t.length;e&&!t[--e];);for(var n=new s(++e),r=0,i=t[0],o=1,a=function(t){n[r++]=t},l=1;l<=e;++l)if(t[l]==i&&l!=e)++o;else{if(!i&&o>2){for(;o>138;o-=138)a(32754);o>2&&(a(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(a(i),--o;o>6;o-=6)a(8304);o>2&&(a(o-3<<5|8208),o=0)}for(;o--;)a(i);o=1,i=t[l]}return{c:n.subarray(0,r),n:e}},N=function(t,e){for(var n=0,r=0;r<e.length;++r)n+=t[r]*e[r];return n},H=function(t,e,n){var r=n.length,i=I(e+2);t[i]=255&r,t[i+1]=r>>8,t[i+2]=255^t[i],t[i+3]=255^t[i+1];for(var s=0;s<r;++s)t[i+s+4]=n[s];return 8*(i+4+r)},$=function(t,e,n,r,i,o,c,f,h,p,d){L(e,d++,n),++i[256];for(var g=F(i,15),v=g.t,m=g.l,y=F(o,15),w=y.t,_=y.l,S=D(v),M=S.c,U=S.n,Z=D(w),I=Z.c,T=Z.n,P=new s(19),R=0;R<M.length;++R)++P[31&M[R]];for(R=0;R<I.length;++R)++P[31&I[R]];for(var k=F(P,7),O=k.t,$=k.l,j=19;j>4&&!O[u[j-1]];--j);var q,G,K,W,Y=p+5<<3,X=N(i,A)+N(o,C)+c,B=N(i,v)+N(o,w)+c+14+3*j+N(P,O)+2*P[16]+3*P[17]+7*P[18];if(h>=0&&Y<=X&&Y<=B)return H(e,d,t.subarray(h,h+p));if(L(e,d,1+(B<X)),d+=2,B<X){q=E(v,m,0),G=v,K=E(w,_,0),W=w;var V=E(O,$,0);for(L(e,d,U-257),L(e,d+5,T-1),L(e,d+10,j-4),d+=14,R=0;R<j;++R)L(e,d+3*R,O[u[R]]);d+=3*j;for(var J=[M,I],Q=0;Q<2;++Q){var tt=J[Q];for(R=0;R<tt.length;++R){var et=31&tt[R];L(e,d,V[et]),d+=O[et],et>15&&(L(e,d,tt[R]>>5&127),d+=tt[R]>>12)}}}else q=b,G=A,K=z,W=C;for(R=0;R<f;++R){var nt=r[R];if(nt>255){x(e,d,q[257+(et=nt>>18&31)]),d+=G[et+257],et>7&&(L(e,d,nt>>23&31),d+=a[et]);var rt=31&nt;x(e,d,K[rt]),d+=W[rt],rt>3&&(x(e,d,nt>>5&8191),d+=l[rt])}else x(e,d,q[nt]),d+=G[nt]}return x(e,d,q[256]),d+G[256]},j=new o([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),q=new i(0),G=function(t,e,n,r,u,c){var f=c.z||t.length,h=new i(r+f+5*(1+Math.ceil(f/7e3))+u),d=h.subarray(r,h.length-u),g=c.l,m=7&(c.r||0);if(e){m&&(d[0]=c.r>>3);for(var y=j[e-1],w=y>>13,E=8191&y,A=(1<<n)-1,C=c.p||new s(32768),b=c.h||new s(A+1),_=Math.ceil(n/3),z=2*_,S=function(e){return(t[e]^t[e+1]<<_^t[e+2]<<z)&A},M=new o(25e3),U=new s(288),Z=new s(32),P=0,R=0,k=c.i||0,L=0,x=c.w||0,F=0;k+2<f;++k){var O=S(k),D=32767&k,N=b[O];if(C[D]=N,b[O]=D,x<=k){var q=f-k;if((P>7e3||L>24576)&&(q>423||!g)){m=$(t,d,0,M,U,Z,R,L,F,k-F,m),L=P=R=0,F=k;for(var G=0;G<286;++G)U[G]=0;for(G=0;G<30;++G)Z[G]=0}var K=2,W=0,Y=E,X=D-N&32767;if(q>2&&O==S(k-X))for(var B=Math.min(w,q)-1,V=Math.min(32767,k),J=Math.min(258,q);X<=V&&--Y&&D!=N;){if(t[k+K]==t[k+K-X]){for(var Q=0;Q<J&&t[k+Q]==t[k+Q-X];++Q);if(Q>K){if(K=Q,W=X,Q>B)break;var tt=Math.min(X,Q-2),et=0;for(G=0;G<tt;++G){var nt=k-X+G&32767,rt=nt-C[nt]&32767;rt>et&&(et=rt,N=nt)}}}X+=(D=N)-(N=C[D])&32767}if(W){M[L++]=268435456|p[K]<<18|v[W];var it=31&p[K],st=31&v[W];R+=a[it]+l[st],++U[257+it],++Z[st],x=k+K,++P}else M[L++]=t[k],++U[t[k]]}}for(k=Math.max(k,x);k<f;++k)M[L++]=t[k],++U[t[k]];m=$(t,d,g,M,U,Z,R,L,F,k-F,m),g||(c.r=7&m|d[m/8|0]<<3,m-=7,c.h=b,c.p=C,c.i=k,c.w=x)}else{for(k=c.w||0;k<f+g;k+=65535){var ot=k+65535;ot>=f&&(d[m/8|0]=g,ot=f),m=H(d,m+1,t.subarray(k,ot))}c.i=f}return T(h,0,r+I(m)+u)},K=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var n=e,r=9;--r;)n=(1&n&&-306674912)^n>>>1;t[e]=n}return t}(),W=function(){var t=-1;return{p:function(e){for(var n=t,r=0;r<e.length;++r)n=K[255&n^e[r]]^n>>>8;t=n},d:function(){return~t}}},Y=function(){var t=1,e=0;return{p:function(n){for(var r=t,i=e,s=0|n.length,o=0;o!=s;){for(var a=Math.min(o+2655,s);o<a;++o)i+=r+=n[o];r=(65535&r)+15*(r>>16),i=(65535&i)+15*(i>>16)}t=r,e=i},d:function(){return(255&(t%=65521))<<24|(65280&t)<<8|(255&(e%=65521))<<8|e>>8}}},X=function(t,e,n,r,s){if(!s&&(s={l:1},e.dictionary)){var o=e.dictionary.subarray(-32768),a=new i(o.length+t.length);a.set(o),a.set(t,o.length),t=a,s.w=o.length}return G(t,null==e.level?6:e.level,null==e.mem?s.l?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(t.length)))):20:12+e.mem,n,r,s)},B=function(t,e){var n={};for(var r in t)n[r]=t[r];for(var r in e)n[r]=e[r];return n},V=function(t,e,n){for(var r=t(),i=t.toString(),s=i.slice(i.indexOf("[")+1,i.lastIndexOf("]")).replace(/\s+/g,"").split(","),o=0;o<r.length;++o){var a=r[o],l=s[o];if("function"==typeof a){e+=";"+l+"=";var u=a.toString();if(a.prototype)if(-1!=u.indexOf("[native code]")){var c=u.indexOf(" ",8)+1;e+=u.slice(c,u.indexOf("(",c))}else for(var f in e+=u,a.prototype)e+=";"+l+".prototype."+f+"="+a.prototype[f].toString();else e+=u}else n[l]=a}return e},J=[],Q=function(t,e,n,i){if(!J[n]){for(var s="",o={},a=t.length-1,l=0;l<a;++l)s=V(t[l],s,o);J[n]={c:V(t[a],s,o),e:o}}var u=B({},J[n].e);return r(J[n].c+";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage="+e.toString()+"}",n,u,function(t){var e=[];for(var n in t)t[n].buffer&&e.push((t[n]=new t[n].constructor(t[n])).buffer);return e}(u),i)},tt=function(){return[i,s,o,a,l,u,h,g,_,S,m,P,E,M,U,Z,I,T,R,k,Zt,ot,at]},et=function(){return[i,s,o,a,l,u,p,v,b,A,z,C,m,j,q,E,L,x,F,O,D,N,H,$,I,T,G,X,zt,ot]},nt=function(){return[gt,yt,dt,W,K]},rt=function(){return[vt,mt]},it=function(){return[wt,dt,Y]},st=function(){return[Et]},ot=function(t){return postMessage(t,[t.buffer])},at=function(t){return t&&{out:t.size&&new i(t.size),dictionary:t.dictionary}},lt=function(t,e,n,r,i,s){var o=Q(n,r,i,function(t,e){o.terminate(),s(t,e)});return o.postMessage([t,e],e.consume?[t.buffer]:[]),function(){o.terminate()}},ut=function(t){return t.ondata=function(t,e){return postMessage([t,e],[t.buffer])},function(e){e.data.length?(t.push(e.data[0],e.data[1]),postMessage([e.data[0].length])):t.flush()}},ct=function(t,e,n,r,i,s,o){var a,l=Q(t,r,i,function(t,n){t?(l.terminate(),e.ondata.call(e,t)):Array.isArray(n)?1==n.length?(e.queuedSize-=n[0],e.ondrain&&e.ondrain(n[0])):(n[1]&&l.terminate(),e.ondata.call(e,t,n[0],n[1])):o(n)});l.postMessage(n),e.queuedSize=0,e.push=function(t,n){e.ondata||R(5),a&&e.ondata(R(4,0,1),null,!!n),e.queuedSize+=t.length,l.postMessage([t,a=n],[t.buffer])},e.terminate=function(){l.terminate()},s&&(e.flush=function(){l.postMessage([])})},ft=function(t,e){return t[e]|t[e+1]<<8},ht=function(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},pt=function(t,e){return ht(t,e)+4294967296*ht(t,e+4)},dt=function(t,e,n){for(;n;++e)t[e]=n,n>>>=8},gt=function(t,e){var n=e.filename;if(t[0]=31,t[1]=139,t[2]=8,t[8]=e.level<2?4:9==e.level?2:0,t[9]=3,0!=e.mtime&&dt(t,4,Math.floor(new Date(e.mtime||Date.now())/1e3)),n){t[3]=8;for(var r=0;r<=n.length;++r)t[r+10]=n.charCodeAt(r)}},vt=function(t){31==t[0]&&139==t[1]&&8==t[2]||R(6,"invalid gzip data");var e=t[3],n=10;4&e&&(n+=2+(t[10]|t[11]<<8));for(var r=(e>>3&1)+(e>>4&1);r>0;r-=!t[n++]);return n+(2&e)},mt=function(t){var e=t.length;return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0},yt=function(t){return 10+(t.filename?t.filename.length+1:0)},wt=function(t,e){var n=e.level,r=0==n?0:n<6?1:9==n?3:2;if(t[0]=120,t[1]=r<<6|(e.dictionary&&32),t[1]|=31-(t[0]<<8|t[1])%31,e.dictionary){var i=Y();i.p(e.dictionary),dt(t,2,i.d())}},Et=function(t,e){return(8!=(15&t[0])||t[0]>>4>7||(t[0]<<8|t[1])%31)&&R(6,"invalid zlib data"),(t[1]>>5&1)==+!e&&R(6,"invalid zlib data: "+(32&t[1]?"need":"unexpected")+" dictionary"),2+(t[1]>>3&4)};function At(t,e){return"function"==typeof t&&(e=t,t={}),this.ondata=e,t}var Ct=function(){function t(t,e){if("function"==typeof t&&(e=t,t={}),this.ondata=e,this.o=t||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new i(98304),this.o.dictionary){var n=this.o.dictionary.subarray(-32768);this.b.set(n,32768-n.length),this.s.i=32768-n.length}}return t.prototype.p=function(t,e){this.ondata(X(t,this.o,0,0,this.s),e)},t.prototype.push=function(t,e){this.ondata||R(5),this.s.l&&R(4);var n=t.length+this.s.z;if(n>this.b.length){if(n>2*this.b.length-32768){var r=new i(-32768&n);r.set(this.b.subarray(0,this.s.z)),this.b=r}var s=this.b.length-this.s.z;this.b.set(t.subarray(0,s),this.s.z),this.s.z=this.b.length,this.p(this.b,!1),this.b.set(this.b.subarray(-32768)),this.b.set(t.subarray(s),32768),this.s.z=t.length-s+32768,this.s.i=32766,this.s.w=32768}else this.b.set(t,this.s.z),this.s.z+=t.length;this.s.l=1&e,(this.s.z>this.s.w+8191||e)&&(this.p(this.b,e||!1),this.s.w=this.s.i,this.s.i-=2)},t.prototype.flush=function(){this.ondata||R(5),this.s.l&&R(4),this.p(this.b,!1),this.s.w=this.s.i,this.s.i-=2},t}();e.Deflate=Ct;var bt=function(){return function(t,e){ct([et,function(){return[ut,Ct]}],this,At.call(this,t,e),function(t){var e=new Ct(t.data);onmessage=ut(e)},6,1)}}();function _t(t,e,n){return n||(n=e,e={}),"function"!=typeof n&&R(7),lt(t,e,[et],function(t){return ot(zt(t.data[0],t.data[1]))},0,n)}function zt(t,e){return X(t,e||{},0,0)}e.AsyncDeflate=bt,e.deflate=_t,e.deflateSync=zt;var St=function(){function t(t,e){"function"==typeof t&&(e=t,t={}),this.ondata=e;var n=t&&t.dictionary&&t.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new i(32768),this.p=new i(0),n&&this.o.set(n)}return t.prototype.e=function(t){if(this.ondata||R(5),this.d&&R(4),this.p.length){if(t.length){var e=new i(this.p.length+t.length);e.set(this.p),e.set(t,this.p.length),this.p=e}}else this.p=t},t.prototype.c=function(t){this.s.i=+(this.d=t||!1);var e=this.s.b,n=k(this.p,this.s,this.o);this.ondata(T(n,e,this.s.b),this.d),this.o=T(n,this.s.b-32768),this.s.b=this.o.length,this.p=T(this.p,this.s.p/8|0),this.s.p&=7},t.prototype.push=function(t,e){this.e(t),this.c(e)},t}();e.Inflate=St;var Mt=function(){return function(t,e){ct([tt,function(){return[ut,St]}],this,At.call(this,t,e),function(t){var e=new St(t.data);onmessage=ut(e)},7,0)}}();function Ut(t,e,n){return n||(n=e,e={}),"function"!=typeof n&&R(7),lt(t,e,[tt],function(t){return ot(Zt(t.data[0],at(t.data[1])))},1,n)}function Zt(t,e){return k(t,{i:2},e&&e.out,e&&e.dictionary)}e.AsyncInflate=Mt,e.inflate=Ut,e.inflateSync=Zt;var It=function(){function t(t,e){this.c=W(),this.l=0,this.v=1,Ct.call(this,t,e)}return t.prototype.push=function(t,e){this.c.p(t),this.l+=t.length,Ct.prototype.push.call(this,t,e)},t.prototype.p=function(t,e){var n=X(t,this.o,this.v&&yt(this.o),e&&8,this.s);this.v&&(gt(n,this.o),this.v=0),e&&(dt(n,n.length-8,this.c.d()),dt(n,n.length-4,this.l)),this.ondata(n,e)},t.prototype.flush=function(){Ct.prototype.flush.call(this)},t}();e.Gzip=It,e.Compress=It;var Tt=function(){return function(t,e){ct([et,nt,function(){return[ut,Ct,It]}],this,At.call(this,t,e),function(t){var e=new It(t.data);onmessage=ut(e)},8,1)}}();function Pt(t,e,n){return n||(n=e,e={}),"function"!=typeof n&&R(7),lt(t,e,[et,nt,function(){return[Rt]}],function(t){return ot(Rt(t.data[0],t.data[1]))},2,n)}function Rt(t,e){e||(e={});var n=W(),r=t.length;n.p(t);var i=X(t,e,yt(e),8),s=i.length;return gt(i,e),dt(i,s-8,n.d()),dt(i,s-4,r),i}e.AsyncGzip=Tt,e.AsyncCompress=Tt,e.gzip=Pt,e.compress=Pt,e.gzipSync=Rt,e.compressSync=Rt;var kt=function(){function t(t,e){this.v=1,this.r=0,St.call(this,t,e)}return t.prototype.push=function(t,e){if(St.prototype.e.call(this,t),this.r+=t.length,this.v){var n=this.p.subarray(this.v-1),r=n.length>3?vt(n):4;if(r>n.length){if(!e)return}else this.v>1&&this.onmember&&this.onmember(this.r-n.length);this.p=n.subarray(r),this.v=0}St.prototype.c.call(this,e),!this.s.f||this.s.l||e||(this.v=I(this.s.p)+9,this.s={i:0},this.o=new i(0),this.push(new i(0),e))},t}();e.Gunzip=kt;var Lt=function(){return function(t,e){var n=this;ct([tt,rt,function(){return[ut,St,kt]}],this,At.call(this,t,e),function(t){var e=new kt(t.data);e.onmember=function(t){return postMessage(t)},onmessage=ut(e)},9,0,function(t){return n.onmember&&n.onmember(t)})}}();function xt(t,e,n){return n||(n=e,e={}),"function"!=typeof n&&R(7),lt(t,e,[tt,rt,function(){return[Ft]}],function(t){return ot(Ft(t.data[0],t.data[1]))},3,n)}function Ft(t,e){var n=vt(t);return n+8>t.length&&R(6,"invalid gzip data"),k(t.subarray(n,-8),{i:2},e&&e.out||new i(mt(t)),e&&e.dictionary)}e.AsyncGunzip=Lt,e.gunzip=xt,e.gunzipSync=Ft;var Ot=function(){function t(t,e){this.c=Y(),this.v=1,Ct.call(this,t,e)}return t.prototype.push=function(t,e){this.c.p(t),Ct.prototype.push.call(this,t,e)},t.prototype.p=function(t,e){var n=X(t,this.o,this.v&&(this.o.dictionary?6:2),e&&4,this.s);this.v&&(wt(n,this.o),this.v=0),e&&dt(n,n.length-4,this.c.d()),this.ondata(n,e)},t.prototype.flush=function(){Ct.prototype.flush.call(this)},t}();e.Zlib=Ot;var Dt=function(){return function(t,e){ct([et,it,function(){return[ut,Ct,Ot]}],this,At.call(this,t,e),function(t){var e=new Ot(t.data);onmessage=ut(e)},10,1)}}();function Nt(t,e){e||(e={});var n=Y();n.p(t);var r=X(t,e,e.dictionary?6:2,4);return wt(r,e),dt(r,r.length-4,n.d()),r}e.AsyncZlib=Dt,e.zlib=function(t,e,n){return n||(n=e,e={}),"function"!=typeof n&&R(7),lt(t,e,[et,it,function(){return[Nt]}],function(t){return ot(Nt(t.data[0],t.data[1]))},4,n)},e.zlibSync=Nt;var Ht=function(){function t(t,e){St.call(this,t,e),this.v=t&&t.dictionary?2:1}return t.prototype.push=function(t,e){if(St.prototype.e.call(this,t),this.v){if(this.p.length<6&&!e)return;this.p=this.p.subarray(Et(this.p,this.v-1)),this.v=0}e&&(this.p.length<4&&R(6,"invalid zlib data"),this.p=this.p.subarray(0,-4)),St.prototype.c.call(this,e)},t}();e.Unzlib=Ht;var $t=function(){return function(t,e){ct([tt,st,function(){return[ut,St,Ht]}],this,At.call(this,t,e),function(t){var e=new Ht(t.data);onmessage=ut(e)},11,0)}}();function jt(t,e,n){return n||(n=e,e={}),"function"!=typeof n&&R(7),lt(t,e,[tt,st,function(){return[qt]}],function(t){return ot(qt(t.data[0],at(t.data[1])))},5,n)}function qt(t,e){return k(t.subarray(Et(t,e&&e.dictionary),-4),{i:2},e&&e.out,e&&e.dictionary)}e.AsyncUnzlib=$t,e.unzlib=jt,e.unzlibSync=qt;var Gt=function(){function t(t,e){this.o=At.call(this,t,e)||{},this.G=kt,this.I=St,this.Z=Ht}return t.prototype.i=function(){var t=this;this.s.ondata=function(e,n){t.ondata(e,n)}},t.prototype.push=function(t,e){if(this.ondata||R(5),this.s)this.s.push(t,e);else{if(this.p&&this.p.length){var n=new i(this.p.length+t.length);n.set(this.p),n.set(t,this.p.length)}else this.p=t;this.p.length>2&&(this.s=31==this.p[0]&&139==this.p[1]&&8==this.p[2]?new this.G(this.o):8!=(15&this.p[0])||this.p[0]>>4>7||(this.p[0]<<8|this.p[1])%31?new this.I(this.o):new this.Z(this.o),this.i(),this.s.push(this.p,e),this.p=null)}},t}();e.Decompress=Gt;var Kt=function(){function t(t,e){Gt.call(this,t,e),this.queuedSize=0,this.G=Lt,this.I=Mt,this.Z=$t}return t.prototype.i=function(){var t=this;this.s.ondata=function(e,n,r){t.ondata(e,n,r)},this.s.ondrain=function(e){t.queuedSize-=e,t.ondrain&&t.ondrain(e)}},t.prototype.push=function(t,e){this.queuedSize+=t.length,Gt.prototype.push.call(this,t,e)},t}();e.AsyncDecompress=Kt,e.decompress=function(t,e,n){return n||(n=e,e={}),"function"!=typeof n&&R(7),31==t[0]&&139==t[1]&&8==t[2]?xt(t,e,n):8!=(15&t[0])||t[0]>>4>7||(t[0]<<8|t[1])%31?Ut(t,e,n):jt(t,e,n)},e.decompressSync=function(t,e){return 31==t[0]&&139==t[1]&&8==t[2]?Ft(t,e):8!=(15&t[0])||t[0]>>4>7||(t[0]<<8|t[1])%31?Zt(t,e):qt(t,e)};var Wt=function(t,e,n,r){for(var s in t){var o=t[s],a=e+s,l=r;Array.isArray(o)&&(l=B(r,o[1]),o=o[0]),o instanceof i?n[a]=[o,l]:(n[a+="/"]=[new i(0),l],Wt(o,a,n,r))}},Yt="undefined"!=typeof TextEncoder&&new TextEncoder,Xt="undefined"!=typeof TextDecoder&&new TextDecoder,Bt=0;try{Xt.decode(q,{stream:!0}),Bt=1}catch(t){}var Vt=function(t){for(var e="",n=0;;){var r=t[n++],i=(r>127)+(r>223)+(r>239);if(n+i>t.length)return{s:e,r:T(t,n-1)};i?3==i?(r=((15&r)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536,e+=String.fromCharCode(55296|r>>10,56320|1023&r)):e+=1&i?String.fromCharCode((31&r)<<6|63&t[n++]):String.fromCharCode((15&r)<<12|(63&t[n++])<<6|63&t[n++]):e+=String.fromCharCode(r)}},Jt=function(){function t(t){this.ondata=t,Bt?this.t=new TextDecoder:this.p=q}return t.prototype.push=function(t,e){if(this.ondata||R(5),e=!!e,this.t)return this.ondata(this.t.decode(t,{stream:!0}),e),void(e&&(this.t.decode().length&&R(8),this.t=null));this.p||R(4);var n=new i(this.p.length+t.length);n.set(this.p),n.set(t,this.p.length);var r=Vt(n),s=r.s,o=r.r;e?(o.length&&R(8),this.p=null):this.p=o,this.ondata(s,e)},t}();e.DecodeUTF8=Jt;var Qt=function(){function t(t){this.ondata=t}return t.prototype.push=function(t,e){this.ondata||R(5),this.d&&R(4),this.ondata(te(t),this.d=e||!1)},t}();function te(t,e){if(e){for(var n=new i(t.length),r=0;r<t.length;++r)n[r]=t.charCodeAt(r);return n}if(Yt)return Yt.encode(t);var s=t.length,o=new i(t.length+(t.length>>1)),a=0,l=function(t){o[a++]=t};for(r=0;r<s;++r){if(a+5>o.length){var u=new i(a+8+(s-r<<1));u.set(o),o=u}var c=t.charCodeAt(r);c<128||e?l(c):c<2048?(l(192|c>>6),l(128|63&c)):c>55295&&c<57344?(l(240|(c=65536+(1047552&c)|1023&t.charCodeAt(++r))>>18),l(128|c>>12&63),l(128|c>>6&63),l(128|63&c)):(l(224|c>>12),l(128|c>>6&63),l(128|63&c))}return T(o,0,a)}function ee(t,e){if(e){for(var n="",r=0;r<t.length;r+=16384)n+=String.fromCharCode.apply(null,t.subarray(r,r+16384));return n}if(Xt)return Xt.decode(t);var i=Vt(t),s=i.s;return(n=i.r).length&&R(8),s}e.EncodeUTF8=Qt,e.strToU8=te,e.strFromU8=ee;var ne=function(t){return 1==t?3:t<6?2:9==t?1:0},re=function(t,e){return e+30+ft(t,e+26)+ft(t,e+28)},ie=function(t,e,n){var r=ft(t,e+28),i=ee(t.subarray(e+46,e+46+r),!(2048&ft(t,e+8))),s=e+46+r,o=ht(t,e+20),a=n&&4294967295==o?se(t,s):[o,ht(t,e+24),ht(t,e+42)],l=a[0],u=a[1],c=a[2];return[ft(t,e+10),l,u,i,s+ft(t,e+30)+ft(t,e+32),c]},se=function(t,e){for(;1!=ft(t,e);e+=4+ft(t,e+2));return[pt(t,e+12),pt(t,e+4),pt(t,e+20)]},oe=function(t){var e=0;if(t)for(var n in t){var r=t[n].length;r>65535&&R(9),e+=r+4}return e},ae=function(t,e,n,r,i,s,o,a){var l=r.length,u=n.extra,c=a&&a.length,f=oe(u);dt(t,e,null!=o?33639248:67324752),e+=4,null!=o&&(t[e++]=20,t[e++]=n.os),t[e]=20,e+=2,t[e++]=n.flag<<1|(s<0&&8),t[e++]=i&&8,t[e++]=255&n.compression,t[e++]=n.compression>>8;var h=new Date(null==n.mtime?Date.now():n.mtime),p=h.getFullYear()-1980;if((p<0||p>119)&&R(10),dt(t,e,p<<25|h.getMonth()+1<<21|h.getDate()<<16|h.getHours()<<11|h.getMinutes()<<5|h.getSeconds()>>1),e+=4,-1!=s&&(dt(t,e,n.crc),dt(t,e+4,s<0?-s-2:s),dt(t,e+8,n.size)),dt(t,e+12,l),dt(t,e+14,f),e+=16,null!=o&&(dt(t,e,c),dt(t,e+6,n.attrs),dt(t,e+10,o),e+=14),t.set(r,e),e+=l,f)for(var d in u){var g=u[d],v=g.length;dt(t,e,+d),dt(t,e+2,v),t.set(g,e+4),e+=4+v}return c&&(t.set(a,e),e+=c),e},le=function(t,e,n,r,i){dt(t,e,101010256),dt(t,e+8,n),dt(t,e+10,n),dt(t,e+12,r),dt(t,e+16,i)},ue=function(){function t(t){this.filename=t,this.c=W(),this.size=0,this.compression=0}return t.prototype.process=function(t,e){this.ondata(null,t,e)},t.prototype.push=function(t,e){this.ondata||R(5),this.c.p(t),this.size+=t.length,e&&(this.crc=this.c.d()),this.process(t,e||!1)},t}();e.ZipPassThrough=ue;var ce=function(){function t(t,e){var n=this;e||(e={}),ue.call(this,t),this.d=new Ct(e,function(t,e){n.ondata(null,t,e)}),this.compression=8,this.flag=ne(e.level)}return t.prototype.process=function(t,e){try{this.d.push(t,e)}catch(t){this.ondata(t,null,e)}},t.prototype.push=function(t,e){ue.prototype.push.call(this,t,e)},t}();e.ZipDeflate=ce;var fe=function(){function t(t,e){var n=this;e||(e={}),ue.call(this,t),this.d=new bt(e,function(t,e,r){n.ondata(t,e,r)}),this.compression=8,this.flag=ne(e.level),this.terminate=this.d.terminate}return t.prototype.process=function(t,e){this.d.push(t,e)},t.prototype.push=function(t,e){ue.prototype.push.call(this,t,e)},t}();e.AsyncZipDeflate=fe;var he=function(){function t(t){this.ondata=t,this.u=[],this.d=1}return t.prototype.add=function(t){var e=this;if(this.ondata||R(5),2&this.d)this.ondata(R(4+8*(1&this.d),0,1),null,!1);else{var n=te(t.filename),r=n.length,s=t.comment,o=s&&te(s),a=r!=t.filename.length||o&&s.length!=o.length,l=r+oe(t.extra)+30;r>65535&&this.ondata(R(11,0,1),null,!1);var u=new i(l);ae(u,0,t,n,a,-1);var c=[u],f=function(){for(var t=0,n=c;t<n.length;t++){var r=n[t];e.ondata(null,r,!1)}c=[]},h=this.d;this.d=0;var p=this.u.length,d=B(t,{f:n,u:a,o,t:function(){t.terminate&&t.terminate()},r:function(){if(f(),h){var t=e.u[p+1];t?t.r():e.d=1}h=1}}),g=0;t.ondata=function(n,r,s){if(n)e.ondata(n,r,s),e.terminate();else if(g+=r.length,c.push(r),s){var o=new i(16);dt(o,0,134695760),dt(o,4,t.crc),dt(o,8,g),dt(o,12,t.size),c.push(o),d.c=g,d.b=l+g+16,d.crc=t.crc,d.size=t.size,h&&d.r(),h=1}else h&&f()},this.u.push(d)}},t.prototype.end=function(){var t=this;2&this.d?this.ondata(R(4+8*(1&this.d),0,1),null,!0):(this.d?this.e():this.u.push({r:function(){1&t.d&&(t.u.splice(-1,1),t.e())},t:function(){}}),this.d=3)},t.prototype.e=function(){for(var t=0,e=0,n=0,r=0,s=this.u;r<s.length;r++)n+=46+(u=s[r]).f.length+oe(u.extra)+(u.o?u.o.length:0);for(var o=new i(n+22),a=0,l=this.u;a<l.length;a++){var u=l[a];ae(o,t,u,u.f,u.u,-u.c-2,e,u.o),t+=46+u.f.length+oe(u.extra)+(u.o?u.o.length:0),e+=u.b}le(o,t,this.u.length,n,e),this.ondata(null,o,!0),this.d=2},t.prototype.terminate=function(){for(var t=0,e=this.u;t<e.length;t++)e[t].t();this.d=2},t}();e.Zip=he,e.zip=function(t,e,n){n||(n=e,e={}),"function"!=typeof n&&R(7);var r={};Wt(t,"",r,e);var s=Object.keys(r),o=s.length,a=0,l=0,u=o,c=new Array(o),f=[],h=function(){for(var t=0;t<f.length;++t)f[t]()},p=function(t,e){me(function(){n(t,e)})};me(function(){p=n});var d=function(){var t=new i(l+22),e=a,n=l-a;l=0;for(var r=0;r<u;++r){var s=c[r];try{var o=s.c.length;ae(t,l,s,s.f,s.u,o);var f=30+s.f.length+oe(s.extra),h=l+f;t.set(s.c,h),ae(t,a,s,s.f,s.u,o,l,s.m),a+=16+f+(s.m?s.m.length:0),l=h+o}catch(t){return p(t,null)}}le(t,a,c.length,n,e),p(null,t)};o||d();for(var g=function(t){var e=s[t],n=r[e],i=n[0],u=n[1],g=W(),v=i.length;g.p(i);var m=te(e),y=m.length,w=u.comment,E=w&&te(w),A=E&&E.length,C=oe(u.extra),b=0==u.level?0:8,_=function(n,r){if(n)h(),p(n,null);else{var i=r.length;c[t]=B(u,{size:v,crc:g.d(),c:r,f:m,m:E,u:y!=e.length||E&&w.length!=A,compression:b}),a+=30+y+C+i,l+=76+2*(y+C)+(A||0)+i,--o||d()}};if(y>65535&&_(R(11,0,1),null),b)if(v<16e4)try{_(null,zt(i,u))}catch(t){_(t,null)}else f.push(_t(i,u,_));else _(null,i)},v=0;v<u;++v)g(v);return h},e.zipSync=function(t,e){e||(e={});var n={},r=[];Wt(t,"",n,e);var s=0,o=0;for(var a in n){var l=n[a],u=l[0],c=l[1],f=0==c.level?0:8,h=(_=te(a)).length,p=c.comment,d=p&&te(p),g=d&&d.length,v=oe(c.extra);h>65535&&R(11);var m=f?zt(u,c):u,y=m.length,w=W();w.p(u),r.push(B(c,{size:u.length,crc:w.d(),c:m,f:_,m:d,u:h!=a.length||d&&p.length!=g,o:s,compression:f})),s+=30+h+v+y,o+=76+2*(h+v)+(g||0)+y}for(var E=new i(o+22),A=s,C=o-s,b=0;b<r.length;++b){var _=r[b];ae(E,_.o,_,_.f,_.u,_.c.length);var z=30+_.f.length+oe(_.extra);E.set(_.c,_.o+z),ae(E,s,_,_.f,_.u,_.c.length,_.o,_.m),s+=16+z+(_.m?_.m.length:0)}return le(E,s,r.length,C,A),E};var pe=function(){function t(){}return t.prototype.push=function(t,e){this.ondata(null,t,e)},t.compression=0,t}();e.UnzipPassThrough=pe;var de=function(){function t(){var t=this;this.i=new St(function(e,n){t.ondata(null,e,n)})}return t.prototype.push=function(t,e){try{this.i.push(t,e)}catch(t){this.ondata(t,null,e)}},t.compression=8,t}();e.UnzipInflate=de;var ge=function(){function t(t,e){var n=this;e<32e4?this.i=new St(function(t,e){n.ondata(null,t,e)}):(this.i=new Mt(function(t,e,r){n.ondata(t,e,r)}),this.terminate=this.i.terminate)}return t.prototype.push=function(t,e){this.i.terminate&&(t=T(t,0)),this.i.push(t,e)},t.compression=8,t}();e.AsyncUnzipInflate=ge;var ve=function(){function t(t){this.onfile=t,this.k=[],this.o={0:pe},this.p=q}return t.prototype.push=function(t,e){var n=this;if(this.onfile||R(5),this.p||R(4),this.c>0){var r=Math.min(this.c,t.length),s=t.subarray(0,r);if(this.c-=r,this.d?this.d.push(s,!this.c):this.k[0].push(s),(t=t.subarray(r)).length)return this.push(t,e)}else{var o=0,a=0,l=void 0,u=void 0;this.p.length?t.length?((u=new i(this.p.length+t.length)).set(this.p),u.set(t,this.p.length)):u=this.p:u=t;for(var c=u.length,f=this.c,h=f&&this.d,p=function(){var t,e=ht(u,a);if(67324752==e){o=1,l=a,d.d=null,d.c=0;var r=ft(u,a+6),i=ft(u,a+8),s=2048&r,h=8&r,p=ft(u,a+26),g=ft(u,a+28);if(c>a+30+p+g){var v=[];d.k.unshift(v),o=2;var m,y=ht(u,a+18),w=ht(u,a+22),E=ee(u.subarray(a+30,a+=30+p),!s);4294967295==y?(t=h?[-2]:se(u,a),y=t[0],w=t[1]):h&&(y=-1),a+=g,d.c=y;var A={name:E,compression:i,start:function(){if(A.ondata||R(5),y){var t=n.o[i];t||A.ondata(R(14,"unknown compression type "+i,1),null,!1),(m=y<0?new t(E):new t(E,y,w)).ondata=function(t,e,n){A.ondata(t,e,n)};for(var e=0,r=v;e<r.length;e++){var s=r[e];m.push(s,!1)}n.k[0]==v&&n.c?n.d=m:m.push(q,!0)}else A.ondata(null,q,!0)},terminate:function(){m&&m.terminate&&m.terminate()}};y>=0&&(A.size=y,A.originalSize=w),d.onfile(A)}return"break"}if(f){if(134695760==e)return l=a+=12+(-2==f&&8),o=3,d.c=0,"break";if(33639248==e)return l=a-=4,o=3,d.c=0,"break"}},d=this;a<c-4&&"break"!==p();++a);if(this.p=q,f<0){var g=o?u.subarray(0,l-12-(-2==f&&8)-(134695760==ht(u,l-16)&&4)):u.subarray(0,a);h?h.push(g,!!o):this.k[+(2==o)].push(g)}if(2&o)return this.push(u.subarray(a),e);this.p=u.subarray(a)}e&&(this.c&&R(13),this.p=null)},t.prototype.register=function(t){this.o[t.compression]=t},t}();e.Unzip=ve;var me="function"==typeof queueMicrotask?queueMicrotask:"function"==typeof setTimeout?setTimeout:function(t){t()};e.unzip=function(t,e,n){n||(n=e,e={}),"function"!=typeof n&&R(7);var r=[],s=function(){for(var t=0;t<r.length;++t)r[t]()},o={},a=function(t,e){me(function(){n(t,e)})};me(function(){a=n});for(var l=t.length-22;101010256!=ht(t,l);--l)if(!l||t.length-l>65558)return a(R(13,0,1),null),s;var u=ft(t,l+8);if(u){var c=u,f=ht(t,l+16),h=4294967295==f||65535==c;if(h){var p=ht(t,l-12);(h=101075792==ht(t,p))&&(c=u=ht(t,p+32),f=ht(t,p+48))}for(var d=e&&e.filter,g=function(e){var n=ie(t,f,h),l=n[0],c=n[1],p=n[2],g=n[3],v=n[4],m=n[5],y=re(t,m);f=v;var w=function(t,e){t?(s(),a(t,null)):(e&&(o[g]=e),--u||a(null,o))};if(!d||d({name:g,size:c,originalSize:p,compression:l}))if(l)if(8==l){var E=t.subarray(y,y+c);if(p<524288||c>.8*p)try{w(null,Zt(E,{out:new i(p)}))}catch(t){w(t,null)}else r.push(Ut(E,{size:p},w))}else w(R(14,"unknown compression type "+l,1),null);else w(null,T(t,y,y+c));else w(null,null)},v=0;v<c;++v)g()}else a(null,{});return s},e.unzipSync=function(t,e){for(var n={},r=t.length-22;101010256!=ht(t,r);--r)(!r||t.length-r>65558)&&R(13);var s=ft(t,r+8);if(!s)return{};var o=ht(t,r+16),a=4294967295==o||65535==s;if(a){var l=ht(t,r-12);(a=101075792==ht(t,l))&&(s=ht(t,l+32),o=ht(t,l+48))}for(var u=e&&e.filter,c=0;c<s;++c){var f=ie(t,o,a),h=f[0],p=f[1],d=f[2],g=f[3],v=f[4],m=f[5],y=re(t,m);o=v,u&&!u({name:g,size:p,originalSize:d,compression:h})||(h?8==h?n[g]=Zt(t.subarray(y,y+p),{out:new i(d)}):R(14,"unknown compression type "+h):n[g]=T(t,y,y+p))}return n}}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var s=e[r]={exports:{}};return t[r](s,s.exports,n),s.exports}(()=>{const t=n(842),e=n(886),r=n(49);self.addEventListener("install",()=>{self.skipWaiting()}),self.addEventListener("activate",t=>{t.waitUntil(self.clients.claim())}),(0,t.installClientErrorReporting)(),(0,r.installMessageHandler)(),(0,e.installFetchHandler)()})()})();
1
+ (()=>{"use strict";var e={180(e,t){function n(e){const n=e.trim();return n.startsWith(t.ZIP_PEEK_ERROR_PREFIX)?n:`${t.ZIP_PEEK_ERROR_PREFIX} ${n}`}t.ZIP_PEEK_ERROR_PREFIX=void 0,t.formatZipPeekError=n,t.createZipPeekError=function(e){return new Error(n(e))},t.toZipPeekError=function(e){const r=e instanceof Error?e:new Error(String(e));return r.message.startsWith(t.ZIP_PEEK_ERROR_PREFIX)||(r.message=n(r.message)),r},t.errorMessage=function(e){return e instanceof Error?e.message:String(e)},t.ZIP_PEEK_ERROR_PREFIX="[zip-peek-error]"},451(e,t,n){t.ensureAllowedZipUrlsLoaded=async function(){if(i.allowedZipUrlsLoaded)return i.allowedZipUrlsLoaded;const e=(async()=>{try{const e=await caches.open(i.CONFIG_CACHE_NAME),t=await e.match(i.CONFIG_CACHE_KEY);if(!t)return;const n=await t.json();Array.isArray(n.allowedZipUrls)?(0,i.setAllowedZipUrls)(new Set(n.allowedZipUrls.filter(e=>"string"==typeof e).map(e=>(0,r.normalizeZipUrl)(e)))):(0,i.setAllowedZipUrls)(null)}catch(e){(0,s.warn)("failed to load runtime config",e)}})();return(0,i.setAllowedZipUrlsLoaded)(e),e},t.applyRuntimeConfig=async function(e){if(!e)return;let t={...i.runtimeConfig},n=!1;if("string"==typeof e.zipAssetCacheName&&e.zipAssetCacheName.trim()&&(t.zipAssetCacheName=e.zipAssetCacheName,n=!0),"number"==typeof e.assetCacheTtlMs&&Number.isFinite(e.assetCacheTtlMs)&&(t.assetCacheTtlMs=e.assetCacheTtlMs,n=!0),"string"==typeof e.logPrefix&&e.logPrefix.trim()&&(t.logPrefix=e.logPrefix,n=!0),"boolean"==typeof e.requireExactManifestPath&&(t.requireExactManifestPath=e.requireExactManifestPath,n=!0),n&&(0,i.setRuntimeConfig)(t),"allowedZipUrls"in e){const t=Array.isArray(e.allowedZipUrls)?e.allowedZipUrls.map(e=>(0,r.normalizeZipUrl)(e)):null;(0,i.setAllowedZipUrls)(t?new Set(t):null),(0,i.setAllowedZipUrlsLoaded)(Promise.resolve()),await async function(e){try{const t=await caches.open(i.CONFIG_CACHE_NAME);await t.put(new Request(i.CONFIG_CACHE_KEY),new Response(JSON.stringify({allowedZipUrls:e}),{headers:{"Content-Type":"application/json"}}))}catch(e){(0,s.warn)("failed to persist runtime config",e)}}(t)}},t.isZipUrlAllowed=function(e){return null===i.allowedZipUrls||i.allowedZipUrls.has(e)};const r=n(134),i=n(167),s=n(777)},919(e,t,n){t.canonicalAssetRequest=function(e,t){return new Request((0,i.canonicalZipAssetRequestUrl)(e,t),{method:"GET"})},t.clearAllZipAssets=async function(){const e=await caches.open(s.runtimeConfig.zipAssetCacheName),t=await e.keys();await Promise.all(t.map(t=>e.delete(t))),await caches.delete(s.CONFIG_CACHE_NAME),s.zipManifests.clear(),s.pendingManifestLoads.clear(),(0,s.setAllowedZipUrlsLoaded)(Promise.resolve())},t.clearZipAssetsExceptAllowed=async function(e){try{const t=new Set(e),n=await caches.open(s.runtimeConfig.zipAssetCacheName),r=await n.keys();for(const e of r){const r=e.url;if(r.includes(s.MANIFEST_CACHE_KEY)){const i=(0,o.zipUrlFromManifestCacheKey)(r);i&&!t.has(i)&&await n.delete(e);continue}const a=(0,i.parseZipAssetRequest)(r);a&&!t.has(a.zipUrl)&&await n.delete(e)}for(const e of s.zipManifests.keys())t.has(e)||s.zipManifests.delete(e)}catch(e){throw(0,r.createZipPeekError)(`Failed to clear zip assets except allowed URLs: ${(0,r.errorMessage)(e)}`)}},t.putCachedFullAssetIfAbsent=async function(e,t){try{const n=await caches.open(s.runtimeConfig.zipAssetCacheName),r=await n.match(e);if(r&&!l(r))return;const i=t.type||"application/octet-stream";await n.put(e,new Response(t,{status:200,headers:{"Content-Type":i,"Content-Length":String(t.size),"Access-Control-Allow-Origin":"*",[s.ASSET_CACHED_AT_HEADER]:String(Date.now())}}))}catch(e){(0,a.warn)("asset cache put failed",e)}},t.readCachedZipAssetIfFresh=async function(e){let t=null,n="network";try{const r=await caches.open(s.runtimeConfig.zipAssetCacheName),i=await r.match(e);if(i)if(l(i))try{await r.delete(e)}catch(e){(0,a.warn)("asset cache delete expired failed",e)}else t=await i.blob(),n="cache-api"}catch(e){(0,a.warn)("asset cache read failed",e)}return{blob:t,assetSource:n}};const r=n(180),i=n(134),s=n(167),a=n(777),o=n(483);function l(e){const t=e.headers.get(s.ASSET_CACHED_AT_HEADER);if(!t)return!0;const n=parseInt(t,10);return!Number.isFinite(n)||Date.now()-n>s.runtimeConfig.assetCacheTtlMs}},705(e,t,n){t.installFetchHandler=function(){self.addEventListener("fetch",e=>{const t=e.request.method;if("GET"!==t&&"HEAD"!==t)return;const n="HEAD"===t,d=(0,i.parseZipAssetRequest)(e.request.url);if(!d)return;const m=(0,i.normalizeZipUrl)(d.zipUrl),g=d.internalPath,h=(0,i.normalizeZipEntryPath)(g);e.respondWith((async()=>{try{if(await(0,s.ensureAllowedZipUrlsLoaded)(),!(0,s.isZipUrlAllowed)(m))return(0,l.warn)("zip URL not allowed",{requestedZipUrl:m}),(0,f.corsErrorResponse)(`ZIP URL not allowed (not in allowedZipUrls): ${m}`,403);let t=o.zipManifests.get(m);if(t||(t=await(0,c.ensureManifestAvailable)(m,e.clientId||void 0)??void 0),!t){const e=Array.from(o.zipManifests.keys());return(0,l.warn)("manifest missing for zipUrl",{requestedZipUrl:m,knownZipUrls:e}),(0,f.corsErrorResponse)(`ZIP manifest not loaded for ${m}. Ensure the ZIP is reachable and supports byte-range requests.`,404)}const i=(0,c.resolveManifestEntry)(t,h,m,o.runtimeConfig.requireExactManifestPath);if(!i){const e=Array.from(t.keys()).slice(0,50);return(0,l.warn)("file not in manifest",{zipUrl:m,internalPathRaw:g,internalPathNormalized:h,requireExactManifestPath:o.runtimeConfig.requireExactManifestPath,manifestSize:t.size,sampleKeys:e}),(0,f.corsErrorResponse)(`File "${g}" not found in ZIP manifest for ${m}`,404)}const{key:d,info:E,matchKind:w}=i;"zipBasenameFallback"===w&&((0,l.log)("resolved via zip-basename folder fallback",{requested:h,manifestKey:d}),(0,l.reportClientError)(new Error((0,r.formatZipPeekError)("Exact manifest path not found; resolved via zip-basename folder fallback")),`Exact manifest key "${h}" not found in ${m}; resolved using "${d}"`));const y=(0,a.canonicalAssetRequest)(m,d);if(n)return function(e,t,n){const r=(0,f.getMimeType)(t),i=(0,c.entryUncompressedSize)(n),s=e.headers.get("range");if(null!==i&&s)return p(null,r,i,"manifest",s);const a={"Content-Type":r,...u("manifest")};return null!==i&&(a["Content-Length"]=i.toString()),new Response(null,{status:200,headers:a})}(e.request,d,E);let{blob:A,assetSource:C}=await(0,a.readCachedZipAssetIfFresh)(y);if(!A){const e=await(0,f.fetchUncompressedZipEntryFromNetwork)(m,d,E,y);if(!e.ok)return e.response;A=e.blob,C="network"}return p(A,A.type,A.size,C,e.request.headers.get("range"))}catch(e){return(0,l.error)("fetch handler failed",{zipUrl:m,internalPath:g,message:(0,r.errorMessage)(e)}),(0,f.corsErrorResponse)(`Failed to serve "${g}" from ${m}: ${(0,r.errorMessage)(e)}`,500)}})())})};const r=n(180),i=n(134),s=n(451),a=n(919),o=n(167),l=n(777),c=n(483),f=n(237);function u(e){return{"Access-Control-Allow-Origin":"*","Access-Control-Expose-Headers":o.ASSET_SOURCE_HEADER,[o.ASSET_SOURCE_HEADER]:e}}function p(e,t,n,r,i){if(i){const s=i.replace(/^bytes=/,"");if(s.includes(","))return new Response(null,{status:416,headers:{"Content-Range":`bytes */${n}`,...u(r)}});const[a,o]=s.split("-"),l=""!==a?parseInt(a,10):NaN,c=""!==o?parseInt(o,10):n-1;if(isNaN(l)||isNaN(c)||l<0||c<l||l>=n)return new Response(null,{status:416,headers:{"Content-Range":`bytes */${n}`,...u(r)}});const f=Math.min(c,n-1),p=f-l+1,d=null===e?null:e.slice(l,f+1);return new Response(d,{status:206,headers:{"Content-Type":t,"Content-Range":`bytes ${l}-${f}/${n}`,"Content-Length":p.toString(),"Accept-Ranges":"bytes",...u(r)}})}return new Response(e,{status:200,headers:{"Content-Type":t,"Content-Length":n.toString(),...u(r)}})}},167(e,t){t.CONFIG_CACHE_KEY=t.allowedZipUrlsLoaded=t.allowedZipUrls=t.runtimeConfig=t.pendingManifestLoads=t.zipManifests=t.MANIFEST_CACHE_KEY=t.LOCAL_FILE_HEADER_SIG=t.MIME_TYPES=t.ASSET_SOURCE_HEADER=t.ASSET_CACHED_AT_HEADER=t.CONFIG_CACHE_NAME=t.kF=t.o2=void 0,t.setRuntimeConfig=function(e){t.runtimeConfig=e},t.setAllowedZipUrls=function(e){t.allowedZipUrls=e},t.setAllowedZipUrlsLoaded=function(e){t.allowedZipUrlsLoaded=e},t.o2="zip-cache-v1",t.kF=72e5,t.CONFIG_CACHE_NAME="zip-peek-config-v1",t.o2,t.CONFIG_CACHE_NAME,t.ASSET_CACHED_AT_HEADER="X-ZipSW-Cached-At",t.ASSET_SOURCE_HEADER="X-ZipSW-Asset-Source",t.MIME_TYPES={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",json:"application/json",js:"application/javascript",css:"text/css; charset=utf-8",html:"text/html; charset=utf-8",txt:"text/plain; charset=utf-8",mp4:"video/mp4",webm:"video/webm",mp3:"audio/mpeg",wav:"audio/wav",oga:"audio/ogg",ogg:"audio/ogg",xml:"application/xml",wasm:"application/wasm"},t.LOCAL_FILE_HEADER_SIG=67324752,t.MANIFEST_CACHE_KEY="__zipsw_manifest__=1",t.zipManifests=new Map,t.pendingManifestLoads=new Map,t.runtimeConfig={zipAssetCacheName:t.o2,assetCacheTtlMs:t.kF,logPrefix:"[zipSW]",requireExactManifestPath:!1},t.allowedZipUrls=null,t.allowedZipUrlsLoaded=null,t.CONFIG_CACHE_KEY=new URL("__zip_peek_runtime_config__",self.registration.scope).href},777(e,t,n){t.log=function(...e){console.log(i.runtimeConfig.logPrefix,...e)},t.warn=function(...e){console.warn(i.runtimeConfig.logPrefix,...e)},t.error=function(...e){console.error(i.runtimeConfig.logPrefix,r.ZIP_PEEK_ERROR_PREFIX,...e)},t.reportClientError=s,t.installClientErrorReporting=function(){self.addEventListener("error",e=>{s(e.error??e.message,"Service worker uncaught error")}),self.addEventListener("unhandledrejection",e=>{s(e.reason,"Service worker unhandled promise rejection")})};const r=n(180),i=n(167);function s(e,t){const n=(0,r.toZipPeekError)(e);self.clients.matchAll({type:"window",includeUncontrolled:!0}).then(e=>{const i={type:"ZIP_SW_ERROR",error:{message:n.message,stack:n.stack},info:t?(0,r.formatZipPeekError)(t):void 0};for(const t of e)t.postMessage(i)})}},483(e,t,n){t.manifestFilesToMap=a,t.sendManifestToClientId=l,t.ensureManifestAvailable=function(e,t){const n=i.zipManifests.get(e);if(n)return Promise.resolve(n);let c=i.pendingManifestLoads.get(e);return c||(c=(async()=>{const n=await async function(e,t){const n=await o(t);return n?function(e,t){return new Promise(n=>{const r=new MessageChannel,i=setTimeout(()=>{r.port1.close(),n(null)},500);r.port1.onmessage=e=>{clearTimeout(i),r.port1.close();const t=e.data;t?.ok&&Array.isArray(t.files)?n(a(t.files)):n(null)},r.port1.onmessageerror=()=>{clearTimeout(i),r.port1.close(),n(null)};try{e.postMessage({type:"ZIP_SW_MANIFEST_REQUEST",zipUrl:t},[r.port2])}catch(e){clearTimeout(i),r.port1.close(),(0,s.warn)("failed to request manifest from client",e),n(null)}})}(n,e):null}(e,t);if(n)return i.zipManifests.set(e,n),(0,s.log)("restored manifest from client memory",{zipUrl:e,entryCount:n.size}),n;const c=await async function(e){const t=await fetch(e,{headers:{Range:"bytes=-65536"}});if(206!==t.status)return(0,s.error)("range requests not supported for ZIP manifest",{zipUrl:e,status:t.status}),null;const n=await t.arrayBuffer(),i=new DataView(n);let a=-1;for(let e=n.byteLength-22;e>=0;e--)if(101010256===i.getUint32(e,!0)){a=e;break}if(-1===a)return(0,s.error)("EOCD not found in last 64KB of ZIP file",e),null;const o=i.getUint32(a+16,!0),l=i.getUint32(a+12,!0);let c=n,f=-1;const u=t.headers.get("Content-Range");let p=0;if(u){const e=u.match(/\/(\d+)$/);e&&(p=parseInt(e[1],10))}if(p<=0)return(0,s.error)("could not determine ZIP file size from Content-Range header",{zipUrl:e,contentRange:u}),null;const d=p-n.byteLength;if(o>=d)f=o-d;else{const t=await fetch(e,{headers:{Range:`bytes=${o}-${o+l-1}`}});if(206!==t.status)return(0,s.error)("failed to fetch ZIP central directory",{zipUrl:e,status:t.status,cdOffset:o,cdSize:l}),null;c=await t.arrayBuffer(),f=0}return function(e,t,n,i){const a=new DataView(e);let o=t;const l=[];for(;o+46<=e.byteLength&&33639248===a.getUint32(o,!0);){const t=a.getUint16(o+10,!0),n=a.getUint32(o+20,!0),i=a.getUint32(o+24,!0),s=a.getUint16(o+28,!0),c=a.getUint16(o+30,!0),f=a.getUint16(o+32,!0),u=a.getUint32(o+42,!0),p=new TextDecoder;if(o+46+s>e.byteLength)break;const d=new Uint8Array(e,o+46,s),m=p.decode(d),g=(0,r.normalizeZipEntryPath)(m);""!==g&&l.push({filename:g,offset:u,compressedSize:n,uncompressedSize:i,compression:t}),o+=46+s+c+f}if(0===l.length)return(0,s.error)("no files parsed from central directory",i),null;l.sort((e,t)=>e.offset-t.offset);const c=new Map;for(let e=0;e<l.length;e++){const t=l[e],i=(0,r.normalizeZipEntryPath)(t.filename);""!==i&&(c.has(i)&&(0,s.warn)("duplicate manifest key after normalize; overwriting",i),c.set(i,{filename:t.filename,offset:t.offset,compressedSize:t.compressedSize,uncompressedSize:t.uncompressedSize,compression:t.compression,nextOffset:e<l.length-1?l[e+1].offset:n}))}return c.size>0?c:null}(c,f,o,e)}(e);return c&&(i.zipManifests.set(e,c),await l(e,c,t),(0,s.log)("manifest fetched and stored in memory",{zipUrl:e,entryCount:c.size})),c})().finally(()=>{i.pendingManifestLoads.delete(e)}),i.pendingManifestLoads.set(e,c),c)},t.entryUncompressedSize=function(e){return void 0!==e.uncompressedSize?e.uncompressedSize:0===e.compression?e.compressedSize:null},t.resolveManifestEntry=function(e,t,n,i){if(e.has(t))return{key:t,info:e.get(t),matchKind:"exact"};if(i)return null;const s=(0,r.zipBasenameWithoutExtension)(n);if(!s)return null;const a=`${s}/${t}`;return e.has(a)?{key:a,info:e.get(a),matchKind:"zipBasenameFallback"}:null},t.zipUrlFromManifestCacheKey=function(e){const t=i.MANIFEST_CACHE_KEY;if(!e.endsWith(t))return null;let n=e.slice(0,-t.length);return(n.endsWith("?")||n.endsWith("&"))&&(n=n.slice(0,-1)),n};const r=n(134),i=n(167),s=n(777);function a(e){const t=new Map;for(const n of e){const e=(0,r.normalizeZipEntryPath)(n.filename);""!==e&&(t.has(e)&&(0,s.warn)("duplicate manifest key after normalize; overwriting",e),t.set(e,n))}return t.size>0?t:null}async function o(e){if(!e)return null;const t=await self.clients.get(e);return"window"===t?.type?t:null}async function l(e,t,n){const r=await o(n);if(!r)return;const i=Array.from(t.values());try{r.postMessage({type:"ZIP_SW_MANIFEST_CREATED",zipUrl:e,files:i})}catch(e){(0,s.warn)("failed to send manifest to client",e)}}},814(e,t,n){t.installMessageHandler=function(){self.addEventListener("message",e=>{if(!e.data)return;const{type:t,zipUrl:n,files:p,config:d,allowedZipUrls:m}=e.data,g=function(e){if(!e||!("id"in e))return;const t=e.id;return"string"==typeof t?t:void 0}(e.source);if("ZIP_SW_CONFIG"===t){const t=(0,s.applyRuntimeConfig)(d).then(()=>u(e,{ok:!0})).catch(t=>u(e,f(t)));return void e.waitUntil(t)}if("ZIP_MANIFEST"===t){if(n&&p){const t=(0,i.normalizeZipUrl)(n),r=(0,c.manifestFilesToMap)(p),s=o.zipManifests.get(t);if(!r)return void(0,l.warn)("rejecting empty manifest; keeping existing",{zipUrl:t,existingSize:s?s.size:0});if(s&&s.size>r.size)return void(0,l.warn)("rejecting smaller manifest; keeping existing",{zipUrl:t,incomingSize:r.size,existingSize:s.size});o.zipManifests.set(t,r),e.waitUntil((0,c.sendManifestToClientId)(t,r,g));const a=Array.from(r.keys()).slice(0,40);(0,l.log)("ZIP_MANIFEST loaded",{zipUrl:t,entryCount:r.size,sampleKeys:a,replacedExistingSize:s?s.size:0})}}else if("CLEAR_ZIP_ASSETS_EXCEPT_ALLOWED"===t&&m){const t=(0,a.clearZipAssetsExceptAllowed)(m).then(()=>u(e,{ok:!0})).catch(t=>u(e,f(t)));e.waitUntil(t)}else if("CLEAR_ALL_ZIP_ASSETS"===t){const t=(0,a.clearAllZipAssets)().then(()=>u(e,{ok:!0})).catch(t=>u(e,f(t)));e.waitUntil(t)}else if("PRELOAD_ZIP_MANIFESTS"===t&&m){const t=async function(e,t){const n=await Promise.all(e.map(async e=>({zipUrl:e,manifest:await(0,c.ensureManifestAvailable)(e,t)}))),i=n.filter(e=>!e.manifest).map(e=>e.zipUrl);if(i.length>0)throw(0,r.createZipPeekError)(`Failed to preload ZIP manifest(s): ${i.join(", ")}`)}(m,g).then(()=>u(e,{ok:!0})).catch(t=>u(e,f(t)));e.waitUntil(t)}})};const r=n(180),i=n(134),s=n(451),a=n(919),o=n(167),l=n(777),c=n(483);function f(e){const t=(0,r.toZipPeekError)(e);return{ok:!1,error:t.message,errorStack:t.stack}}function u(e,t){e.ports[0]?.postMessage(t)}},237(e,t,n){t.corsErrorResponse=l,t.getMimeType=c,t.fetchUncompressedZipEntryFromNetwork=async function(e,t,n,i){const f=n.offset,u=n.nextOffset-1;(0,a.log)("fetching zip chunk from",{zipUrl:e,rangeStart:f,rangeEnd:u});const p=await fetch(e,{headers:{Range:`bytes=${f}-${u}`}});if(206!==p.status)return{ok:!1,response:l(`ZIP entry fetch for "${t}" expected HTTP 206 Partial Content from ${e}, got ${p.status}`,p.status>=400?p.status:502)};const d=await p.arrayBuffer(),m=new DataView(d);if(m.getUint32(0,!0)!==s.LOCAL_FILE_HEADER_SIG)return{ok:!1,response:l(`Invalid local file header for "${t}" in ${e} (expected ZIP signature 0x04034b50)`,500)};const g=30+m.getUint16(26,!0)+m.getUint16(28,!0);if(g>d.byteLength||g+n.compressedSize>d.byteLength)return{ok:!1,response:l(`Corrupt ZIP entry "${t}" in ${e}: dataStart=${g}, compressedSize=${n.compressedSize}, bufferLength=${d.byteLength}`,500)};const h=new Uint8Array(d,g,n.compressedSize);let E;if(8===n.compression)try{E=(0,r.inflateSync)(h)}catch(n){return(0,a.warn)("inflateSync failed",{zipUrl:e,manifestKey:t,error:n}),{ok:!1,response:l(`Failed to inflate DEFLATE-compressed entry "${t}" in ${e}`,500)}}else{if(0!==n.compression)return{ok:!1,response:l(`Unsupported compression method ${n.compression} for "${t}" in ${e} (only stored/0 and DEFLATE/8 are supported)`,500)};E=h}const w=c(t),y=new Blob([E],{type:w});return await(0,o.putCachedFullAssetIfAbsent)(i,y),{ok:!0,blob:y}};const r=n(612),i=n(180),s=n(167),a=n(777),o=n(919);function l(e,t){return new Response((0,i.formatZipPeekError)(e),{status:t,headers:{"Access-Control-Allow-Origin":"*"}})}function c(e){const t=e.split(".").pop()?.toLowerCase();return t?s.MIME_TYPES[t]??"application/octet-stream":"application/octet-stream"}},134(e,t){function n(e){try{return decodeURIComponent(e)}catch{return e}}t.normalizeZipUrl=function(e,t={}){const{stripCacheBuster:n=!0,stripHash:r=!0}=t,i=e=>r?e.split("#")[0]:e;if(!n)return i(e);const s=e.indexOf("?");if(-1===s)return i(e);const a=e.indexOf("#",s),o=e.substring(0,s),l=-1===a?e.substring(s+1):e.substring(s+1,a),c=r||-1===a?"":e.substring(a),f=l.split("&").filter(e=>{const t=e.indexOf("=");return"t"!==(-1===t?e:e.substring(0,t))});return 0===f.length?o+c:o+"?"+f.join("&")+c},t.zipBasenameWithoutExtension=function(e){try{const t=new URL(e,"http://local").pathname.split("/").pop()??"";return t.endsWith(".zip")?t.slice(0,-4):t}catch{const t=e.split("?")[0].split("#")[0].split("/").pop()??"";return t.endsWith(".zip")?t.slice(0,-4):t}},t.normalizeZipEntryPath=function(e){let t=e.replace(/\\/g,"/");for(;t.startsWith("/");)t=t.slice(1);return t},t.parseZipAssetRequest=function(e){const t=/\.zip([/?])/.exec(e);if(!t)return null;const r=t.index+4,i=t[1],s=e.substring(0,r);if("/"===i){const t=e.substring(r+1),i=t.indexOf("?"),a=-1===i?t:t.substring(0,i);return""===a?null:{zipUrl:s,internalPath:n(a)}}const a=e.substring(r),o=a.indexOf("/");if(-1===o)return null;const l=a.substring(0,o),c=a.substring(o+1),f=c.indexOf("?"),u=-1===f?c:c.substring(0,f);return""===u?null:{zipUrl:s+l,internalPath:n(u)}},t.canonicalZipAssetRequestUrl=function(e,t){return e+"/"+encodeURIComponent(t)}},612(e,t){t.inflateSync=b;var n=Uint8Array,r=Uint16Array,i=Int32Array,s=new n([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),a=new n([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),o=new n([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=function(e,t){for(var n=new r(31),s=0;s<31;++s)n[s]=t+=1<<e[s-1];var a=new i(n[30]);for(s=1;s<30;++s)for(var o=n[s];o<n[s+1];++o)a[o]=o-n[s]<<5|s;return{b:n,r:a}},c=l(s,2),f=c.b,u=c.r;f[28]=258,u[258]=28;for(var p=l(a,0),d=p.b,m=(p.r,new r(32768)),g=0;g<32768;++g){var h=(43690&g)>>1|(21845&g)<<1;h=(61680&(h=(52428&h)>>2|(13107&h)<<2))>>4|(3855&h)<<4,m[g]=((65280&h)>>8|(255&h)<<8)>>1}var E=function(e,t,n){for(var i=e.length,s=0,a=new r(t);s<i;++s)e[s]&&++a[e[s]-1];var o,l=new r(t);for(s=1;s<t;++s)l[s]=l[s-1]+a[s-1]<<1;if(n){o=new r(1<<t);var c=15-t;for(s=0;s<i;++s)if(e[s])for(var f=s<<4|e[s],u=t-e[s],p=l[e[s]-1]++<<u,d=p|(1<<u)-1;p<=d;++p)o[m[p]>>c]=f}else for(o=new r(i),s=0;s<i;++s)e[s]&&(o[s]=m[l[e[s]-1]++]>>15-e[s]);return o},w=new n(288);for(g=0;g<144;++g)w[g]=8;for(g=144;g<256;++g)w[g]=9;for(g=256;g<280;++g)w[g]=7;for(g=280;g<288;++g)w[g]=8;var y=new n(32);for(g=0;g<32;++g)y[g]=5;var A=E(w,9,1),C=E(y,5,1),z=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},_=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(7&t)&n},U=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},S=function(e){return(e+7)/8|0},Z=function(e,t,r){return(null==t||t<0)&&(t=0),(null==r||r>e.length)&&(r=e.length),new n(e.subarray(t,r))},v=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],R=function(e,t,n){var r=new Error(t||v[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,R),!n)throw r;return r},P=function(e,t,r,i){var l=e.length,c=i?i.length:0;if(!l||t.f&&!t.l)return r||new n(0);var u=!r,p=u||2!=t.i,m=t.i;u&&(r=new n(3*l));var g=function(e){var t=r.length;if(e>t){var i=new n(Math.max(2*t,e));i.set(r),r=i}},h=t.f||0,w=t.p||0,y=t.b||0,v=t.l,P=t.d,M=t.m,b=t.n,I=8*l;do{if(!v){h=_(e,w,1);var k=_(e,w+1,3);if(w+=3,!k){var T=e[(W=S(w)+4)-4]|e[W-3]<<8,x=W+T;if(x>l){m&&R(0);break}p&&g(y+T),r.set(e.subarray(W,x),y),t.b=y+=T,t.p=w=8*x,t.f=h;continue}if(1==k)v=A,P=C,M=9,b=5;else if(2==k){var L=_(e,w,31)+257,F=_(e,w+10,15)+4,N=L+_(e,w+5,31)+1;w+=14;for(var O=new n(N),$=new n(19),H=0;H<F;++H)$[o[H]]=_(e,w+3*H,7);w+=3*F;var D=z($),q=(1<<D)-1,K=E($,D,1);for(H=0;H<N;){var W,j=K[_(e,w,q)];if(w+=15&j,(W=j>>4)<16)O[H++]=W;else{var G=0,Y=0;for(16==W?(Y=3+_(e,w,3),w+=2,G=O[H-1]):17==W?(Y=3+_(e,w,7),w+=3):18==W&&(Y=11+_(e,w,127),w+=7);Y--;)O[H++]=G}}var B=O.subarray(0,L),X=O.subarray(L);M=z(B),b=z(X),v=E(B,M,1),P=E(X,b,1)}else R(1);if(w>I){m&&R(0);break}}p&&g(y+131072);for(var V=(1<<M)-1,J=(1<<b)-1,Q=w;;Q=w){var ee=(G=v[U(e,w)&V])>>4;if((w+=15&G)>I){m&&R(0);break}if(G||R(2),ee<256)r[y++]=ee;else{if(256==ee){Q=w,v=null;break}var te=ee-254;if(ee>264){var ne=s[H=ee-257];te=_(e,w,(1<<ne)-1)+f[H],w+=ne}var re=P[U(e,w)&J],ie=re>>4;if(re||R(3),w+=15&re,X=d[ie],ie>3&&(ne=a[ie],X+=U(e,w)&(1<<ne)-1,w+=ne),w>I){m&&R(0);break}p&&g(y+131072);var se=y+te;if(y<X){var ae=c-X,oe=Math.min(X,se);for(ae+y<0&&R(3);y<oe;++y)r[y]=i[ae+y]}for(;y<se;++y)r[y]=r[y-X]}}t.l=v,t.p=Q,t.b=y,t.f=h,v&&(h=1,t.m=M,t.d=P,t.n=b)}while(!h);return y!=r.length&&u?Z(r,0,y):r.subarray(0,y)},M=new n(0);function b(e,t){return P(e,{i:2},t&&t.out,t&&t.dictionary)}var I="undefined"!=typeof TextDecoder&&new TextDecoder;try{I.decode(M,{stream:!0})}catch(e){}"function"==typeof queueMicrotask?queueMicrotask:"function"==typeof setTimeout&&setTimeout}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}(()=>{const e=n(777),t=n(705),r=n(814);self.addEventListener("install",()=>{self.skipWaiting()}),self.addEventListener("activate",e=>{e.waitUntil(self.clients.claim())}),(0,e.installClientErrorReporting)(),(0,r.installMessageHandler)(),(0,t.installFetchHandler)()})()})();
2
2
  //# sourceMappingURL=zipServiceWorker.js.map