@hussmartinez/image-sdk 0.1.0 → 0.3.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 +98 -9
- package/dist/assets/image/render.worker.js +1 -1
- package/dist/element.d.ts +32 -2
- package/dist/element.js +2 -2
- package/dist/index.d.ts +41 -3
- package/dist/index.js +1 -1
- package/dist/lazy/{inline-worker-BVCwAPZU.js → inline-worker-l_ynDNuS.js} +2 -2
- package/dist/lazy/{inline-worker-BVCwAPZU.js.map → inline-worker-l_ynDNuS.js.map} +1 -1
- package/dist/react.d.ts +85 -2
- package/dist/react.js +1 -1
- package/dist/shared/{core-cKo2m54U.js → core-BWNmXDlB.js} +271 -79
- package/dist/shared/core-BWNmXDlB.js.map +1 -0
- package/dist/shared/{editor-Dv5EU2YJ.js → editor-CJXEK6MY.js} +262 -75
- package/dist/shared/editor-CJXEK6MY.js.map +1 -0
- package/dist/styles.css +126 -19
- package/package.json +8 -7
- package/dist/shared/core-cKo2m54U.js.map +0 -1
- package/dist/shared/editor-Dv5EU2YJ.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
# image-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Edit images entirely in the browser with **`@hussmartinez/image-sdk`**: crop, rotate, flip, adjust colour and tone, apply filter presets, resize on export, and export PNG, JPEG or WebP. It offers a headless core, a React editor (`ImageEditor`) and a `<hm-image-editor>` custom element. The SDK processes images on the user's device and uploads nothing; the host controls what it does with files returned by the SDK.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @hussmartinez/image-sdk @hussmartinez/ui@^0.7.0 react react-dom
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Use the same `@hussmartinez/ui` minor as the SDK's dependency (`^0.7.0` for image-sdk 0.2.0). React and React DOM `>=18.3` are required for the React editor and custom element. Headless consumers can install just `@hussmartinez/image-sdk`.
|
|
12
|
+
|
|
13
|
+
The package is ESM. Its root entry is server-safe and has no React or DOM access on import; image processing itself requires a browser. The `./react` entry starts with `"use client"`. Importing `./element` registers nothing until you call `defineImageEditorElement()`.
|
|
8
14
|
|
|
9
|
-
##
|
|
15
|
+
## React editor
|
|
10
16
|
|
|
11
|
-
Import `@hussmartinez/ui`'s stylesheet once, then this package's. **ui's stylesheet is required:** it carries the focus rings and minimum target sizes the editor's accessibility relies on ([sdk-core ADR 0036](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0036-ui-as-a-dependency-of-the-sdks.md)).
|
|
17
|
+
Import `@hussmartinez/ui`'s stylesheet once, then this package's. **ui's stylesheet is required:** it carries the focus rings and minimum target sizes the editor's accessibility relies on ([sdk-core ADR 0036](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0036-ui-as-a-dependency-of-the-sdks.md)). Give the editor a height in your application's CSS.
|
|
12
18
|
|
|
13
19
|
```tsx
|
|
14
20
|
import "@hussmartinez/ui/styles.css";
|
|
@@ -20,7 +26,87 @@ export function Editor({ file }: { file: File }) {
|
|
|
20
26
|
}
|
|
21
27
|
```
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
`initialFile` opens on mount. To replace the image later, call `open(blob)` on an `ImageEditorHandle` ref. The controlled document is `plan` with `onChange`: it describes edits over the current source, and changes are undoable. `onChange` fires after committed edits, open, undo and redo, never during a gesture. The React editor has no `file` prop.
|
|
30
|
+
|
|
31
|
+
| Configuration | Public API |
|
|
32
|
+
|---|---|
|
|
33
|
+
| Tools and toolbar groups | `tools` (ordered tool IDs), `toolbar` (groups of IDs); see [`imageTools`](src/features/tools.ts) |
|
|
34
|
+
| Inspector panels and export dialog | `features: { adjust, filters, info, export }`, all enabled by default; disabling export still permits the ref's `export()` |
|
|
35
|
+
| Theme and styling | `theme: "light" \| "dark" \| "system"`, `className`, `classNames`, `unstyled`, `icons`; page attributes `data-hm-theme` and `data-hm-density` |
|
|
36
|
+
| Translation | `messages` overrides, including shared control text, and `locale` for formatting; [`imageMessages`](src/messages/en.ts) is the catalogue |
|
|
37
|
+
| Limits and assets | `filePolicy`, `assetsUrl`; see [host integration](docs/hosting.md) |
|
|
38
|
+
| Host-owned processing | `engine`, `processor`, `session`; a supplied session must use the supplied engine |
|
|
39
|
+
| Host callbacks | `onEvent` receives anonymous usage events; `onExport(blob, details)` receives the exported file instead of the dialog offering a download |
|
|
40
|
+
|
|
41
|
+
The ref provides `session`, `open(blob)`, `execute(commandOrCommands)`, `export(format)`, `undo()` and `redo()`. For example, `await ref.current.export({ type: "jpeg", quality: 0.9 })` returns `{ blob, width, height, removed, kept }`; the host handles the returned file. The ref's export bypasses the dialog and its metadata summary, so show that summary in your own download flow.
|
|
42
|
+
|
|
43
|
+
For a custom layout, `ImageEditorProvider` supplies `ImageStage`, `ImageToolbar`, `ImageCropPanel`, `ImageAdjustPanel`, `ImageFilterPanel`, `ImageInfoPanel` and `ImageExportDialog`. Hooks include `useImageSession`, `useImageDocument`, `useImageView`, `useImageEditorState` and `useImageMessages`. The complete public signatures are in the [React API report](api/image-sdk-react.api.md).
|
|
44
|
+
|
|
45
|
+
## Custom element
|
|
46
|
+
|
|
47
|
+
In a bundled browser entry, import both stylesheets and register the element explicitly:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import "@hussmartinez/ui/styles.css";
|
|
51
|
+
import "@hussmartinez/image-sdk/styles.css";
|
|
52
|
+
import { defineImageEditorElement } from "@hussmartinez/image-sdk/element";
|
|
53
|
+
|
|
54
|
+
defineImageEditorElement();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<hm-image-editor theme="dark" locale="en"></hm-image-editor>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Set the element's height in host CSS. It renders into the light DOM and uses React internally. Its attributes are `theme`, `locale` and `tools` (space-separated IDs). Its properties are `file` (`Blob`), `plan`, `filePolicy`, `assetsUrl`, `messages`, `engine` and `processor`, as well as the attribute-backed properties. Set processing configuration before connecting the element. Setting `file` opens an image; the methods `open`, `execute`, `export`, `undo` and `redo` match the React handle.
|
|
62
|
+
|
|
63
|
+
Listen for `hm-image-editor-change` (plan), `hm-image-editor-event` (anonymous usage event), `hm-image-editor-error` (`{ code, details }`) and `hm-image-editor-export` (format, dimensions, size and metadata summary). Event payloads are in `event.detail`. The export event carries a report; call the element's `export(format)` method to obtain a file. See the [element API report](api/image-sdk-element.api.md).
|
|
64
|
+
|
|
65
|
+
## Headless session
|
|
66
|
+
|
|
67
|
+
A session holds one source and a serialisable edit plan, with undo and redo. Create the processor over the same engine, and release resources when finished:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import {
|
|
71
|
+
createImageEngine,
|
|
72
|
+
createImageProcessor,
|
|
73
|
+
createImageSession,
|
|
74
|
+
} from "@hussmartinez/image-sdk";
|
|
75
|
+
|
|
76
|
+
export async function brighten(file: Blob): Promise<Blob> {
|
|
77
|
+
const engine = createImageEngine();
|
|
78
|
+
const processor = createImageProcessor(engine);
|
|
79
|
+
const session = createImageSession({ engine, processor });
|
|
80
|
+
try {
|
|
81
|
+
await session.open(file);
|
|
82
|
+
session.execute({ type: "image.setDevelop", values: { exposure: 20 } });
|
|
83
|
+
const { blob } = await session.export({ type: "jpeg", quality: 0.9 });
|
|
84
|
+
return blob;
|
|
85
|
+
} finally {
|
|
86
|
+
await session.destroy();
|
|
87
|
+
await processor.destroy();
|
|
88
|
+
await engine.destroy();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Commands set crop, orientation, develop adjustments, filter, output size and kept metadata. `subscribe()` and `getSnapshot()` expose state, errors and limit warnings; `export()` accepts an abort signal and progress callback. A caller-supplied engine, processor or session remains the caller's responsibility to destroy. See the [core API report](api/image-sdk.api.md) and [portable format schemas](formats).
|
|
94
|
+
|
|
95
|
+
## Formats and browsers
|
|
96
|
+
|
|
97
|
+
The engine reads PNG, JPEG, WebP, GIF, BMP and AVIF with the browser's decoder after checking headers and limits in its worker. Animated inputs open as a single first frame. HEIC is recognised, but decoding depends on the browser: all three pinned test engines reject it with `DECODE_FAILED`. SVG is unsupported. Export formats are PNG, JPEG and WebP; an unavailable encoder fails with `UNSUPPORTED_FORMAT`. Exports are sRGB; colours outside sRGB can be clipped.
|
|
98
|
+
|
|
99
|
+
The family's [support target](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0013-browser-and-react-support.md) is the last two major versions of Chrome, Edge, Firefox and Safari on desktop and mobile, with ES2022 output and no polyfills. The [measured capability matrix](docs/capabilities.md) records the exact pinned Chromium, Firefox and WebKit builds checked in CI. These runs prove the generated fixtures, orientation handling and worker canvas paths in those builds; they do not constitute testing of every browser version or device. Playwright WebKit is not Safari and does not prove Apple system HEIC decoding or iOS canvas limits. Validate your target devices and choose limits suitable for them.
|
|
100
|
+
|
|
101
|
+
The editor requires Web Workers, worker `createImageBitmap`, a 2D `OffscreenCanvas` and `transferControlToOffscreen`. The renderer reports `UNSUPPORTED_ENVIRONMENT` when canvas transfer is unavailable; other worker/platform startup and decoding failures can have different codes. The engine and CSP suites exercise inline and self-hosted workers on all three engines; editor tests cover keyboard flows and axe checks, with separate visual comparisons in Chromium.
|
|
102
|
+
|
|
103
|
+
## Privacy and host security
|
|
104
|
+
|
|
105
|
+
Images are parsed, decoded, drawn and encoded in workers. The SDK has no upload or telemetry service; `onEvent` calls only the host. Exports keep no source metadata by default. Users can explicitly keep title, description, artist and copyright in PNG/JPEG; WebP exports carry no metadata. Location is never written. The export dialog shows the removal summary before download.
|
|
106
|
+
|
|
107
|
+
If a worker loses its image/canvas resources, the built-in engine becomes terminal and the editor shows a recovery notice. Explicitly recreate the editor and any host-owned processing resources, then reopen the image; opening it on the old engine cannot restore the preview. Unsaved edits require host-managed preservation.
|
|
108
|
+
|
|
109
|
+
See [host integration and security](docs/hosting.md) for resource limits, error handling, asset deployment, exact tested CSP directives and the host's responsibilities. Report vulnerabilities through the [security policy](SECURITY.md).
|
|
24
110
|
|
|
25
111
|
## Development
|
|
26
112
|
|
|
@@ -34,7 +120,7 @@ pnpm verify # everything CI runs
|
|
|
34
120
|
pnpm verify:fast # the subset the pre-push hook runs
|
|
35
121
|
```
|
|
36
122
|
|
|
37
|
-
|
|
123
|
+
The browser and end-to-end tests need Docker: they run in the pinned browser test image from [`ci/Dockerfile`](ci/Dockerfile), as in CI, through `hm-in-image` from `@hussmartinez/sdk-config` ([sdk-core ADR 0049](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0049-local-browser-tests-in-the-pinned-image.md)). The first run builds the image and installs the dependencies into its volumes. `pnpm test:browser:all` runs all three engines, as CI does.
|
|
38
124
|
|
|
39
125
|
`pnpm verify` runs, in order:
|
|
40
126
|
|
|
@@ -44,11 +130,14 @@ Browser tests need Playwright's browsers once: `pnpm exec playwright install chr
|
|
|
44
130
|
| CSS rules | `lint:css` | stylelint, with the `hm-` namespace and token rules |
|
|
45
131
|
| Types | `typecheck` | TypeScript |
|
|
46
132
|
| Dependency rules | `lint:deps` | dependency-cruiser, through `hm-lint-deps` |
|
|
133
|
+
| One copy of each family package | `check:single-copy` | `hm-check-single-copy` (sdk-core ADR 0047) |
|
|
134
|
+
| Playwright pinned to the browser test image | `check:playwright-image` | `hm-check-playwright-image` (sdk-core ADR 0025) |
|
|
47
135
|
| Build | `build` | Vite, then api-extractor for the type declarations |
|
|
48
136
|
| Unit tests | `test` | Vitest |
|
|
49
|
-
| Browser tests | `test:browser` | Vitest in Chromium, and in Firefox and WebKit too in CI |
|
|
137
|
+
| Browser tests | `test:browser` | Vitest in Chromium in the browser test image, and in Firefox and WebKit too in CI |
|
|
50
138
|
| Examples | `build:examples` | Vite, building `examples/vite` against the built package |
|
|
51
|
-
| End-to-end tests | `test:e2e` | Playwright against the built example: the engine on every format it reads, upright, with the inlined worker under `worker-src blob:` and the self-hosted one under `worker-src 'self'`; the [browser capability matrix](docs/capabilities.md); and no requests to other origins |
|
|
139
|
+
| End-to-end tests | `test:e2e` | Playwright in the browser test image, against the built example: the engine on every format it reads, upright, with the inlined worker under `worker-src blob:` and the self-hosted one under `worker-src 'self'`; the [browser capability matrix](docs/capabilities.md); and no requests to other origins |
|
|
140
|
+
| Screenshots | `test:visual` | Playwright in the browser test image, comparing each designed state with its committed screenshot (sdk-core ADR 0048); `test:visual:update` rewrites them |
|
|
52
141
|
| Size budgets | `check:size` | size-limit, brotli size of each entry point |
|
|
53
142
|
| API reports | `check:api` | api-extractor, one report per entry point in [`api`](api) |
|
|
54
143
|
| Package checks | `check:package` | publint and Are the Types Wrong? |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=!1;function t(){e||=!0}var n=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),r=class extends Error{name=`SdkError`;code;constructor(e,r,i={}){super(r,`cause`in i?{cause:i.cause}:void 0),t(),this.code=e,Object.defineProperty(this,n,{value:!0}),i.details!==void 0&&(this.details=i.details)}};function i(e,t){if(typeof e!=`object`||!e)return!1;let i=e;return(e instanceof r||i[n]===!0)&&typeof i.code==`string`&&typeof i.message==`string`&&(t===void 0||i.code===t)}var a=1<<20;function o(e,t,n){if(!Number.isSafeInteger(t)||t<n)throw RangeError(`The ${e} must be an integer of at least ${n}, not ${String(t)}.`)}function s(e,t={}){let n=t.windowSize??a;o(`window size`,n,1);let r=e.size,i=0,s=/* @__PURE__ */ new Uint8Array;return{size:r,async bytes(t,a){o(`offset`,t,0),o(`length`,a,0);let c=Math.min(t,r),l=Math.min(r,c+a);if(c<i||l>i+s.length){let t=Math.min(r,c+Math.max(a,n));s=new Uint8Array(await e.slice(c,t).arrayBuffer()),i=c}return s.subarray(c-i,l-i)}}}var c=8,l=16,u=`UNKNOWN`;function d(e,t={}){let n=t.includeStack??!1,r=_(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=f(e),s=n&&h(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),h(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function f(e){if(i(e)){let t={name:e.name,code:e.code,message:e.message},n=p(e.details);return n!==void 0&&(t.details=n),t}if(h(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:u,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:u,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:u,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function p(e){if(!g(e))return;let t=m(e,0);return g(t)?t:void 0}function m(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=l)){if(Array.isArray(e))return e.flatMap(e=>{let n=m(e,t+1);return n===void 0?[]:[n]});if(g(e)){let n={};for(let[r,i]of Object.entries(e)){let e=m(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function h(e){return typeof e==`object`&&!!e}function g(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function _(e){if(e===void 0)return c;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}var ee={maxFileSize:{code:`FILE_TOO_LARGE`,unit:`bytes`,default:1e8,warning:5e7},maxFiles:{code:`TOO_MANY_FILES`,unit:`count`,default:20},maxDecodedSize:{code:`DECODED_SIZE_TOO_LARGE`,unit:`bytes`,default:5e8},maxProcessingTime:{code:`PROCESSING_TIME_EXCEEDED`,unit:`milliseconds`,default:12e4}};function v(e,t={}){let n=t.errorClass??r;for(let[t,n]of Object.entries(e))y(`${t}.default`,n.default),n.warning!==void 0&&y(`${t}.warning`,n.warning);return{definitions:e,resolve(t={}){let r={};for(let[t,n]of Object.entries(e))r[t]={maximum:n.default,warning:n.warning??1/0};for(let[e,n]of Object.entries(t)){let t=Object.hasOwn(r,e)?r[e]:void 0;if(t===void 0)throw TypeError(`"${e}" isn't a file policy limit. Known limits: ${Object.keys(r).join(`, `)}.`);r[e]=te(e,t,n)}let i=(t,n)=>{let i=Object.hasOwn(r,t)?r[t]:void 0,a=Object.hasOwn(e,t)?e[t]:void 0;if(i===void 0||a===void 0)throw TypeError(`"${t}" isn't a file policy limit.`);if(typeof n!=`number`||Number.isNaN(n)||n<0)throw RangeError(`The value checked against ${t} must be a non-negative number, received ${String(n)}.`);return{resolved:i,definition:a,actual:n}},a=(e,t)=>{let r=i(e,t),{maximum:a}=r.resolved,{code:o,unit:s}=r.definition;return new n(o,`${e} is ${a} ${s}, but the value is ${r.actual}.`,{details:{limit:e,maximum:a,actual:r.actual,unit:s}})};return{limits:r,check(e,t){let{resolved:n}=i(e,t);if(t>n.maximum)throw a(e,t);return t>=n.warning?`warning`:void 0},error:(e,t)=>a(e,t)}}}}function te(e,t,n){if(typeof n==`number`)return y(e,n),{...t,maximum:n};if(typeof n!=`object`||!n)throw TypeError(`The setting for ${e} must be a number or { maximum, warning }.`);let{maximum:r=t.maximum,warning:i=t.warning,...a}=n,o=Object.keys(a);if(o.length>0)throw TypeError(`The setting for ${e} has unknown keys: ${o.join(`, `)}.`);return y(`${e}.maximum`,r),y(`${e}.warning`,i),{maximum:r,warning:i}}function y(e,t){if(typeof t!=`number`||Number.isNaN(t)||t<=0)throw RangeError(`${e} must be a positive number or Infinity, received ${String(t)}.`)}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var b=`hm-rpc`;function x(e){return{protocol:b,version:1,...e}}function ne(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function re(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=ae(e)?e:S(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return oe(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):w(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),se(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function ie(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function ae(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function S(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var C=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function oe(e){let t=globalThis;return C.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function w(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function se(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function ce(e,t={}){let n=t.scope??globalThis,i=t.includeStack??!1,a=/* @__PURE__ */ new Map,o=(e,t=[])=>{n.postMessage(e,t)},s=(e,t)=>{o(x({type:`error`,id:e,error:d(t,{includeStack:i})}))},c=(e,t,i)=>{let a=re(i,!0);try{ie((e,t)=>n.postMessage(e,t),x({type:`result`,id:e,output:a.value}),a.transferables)}catch(n){s(e,new r(`WORKER_DATA_NOT_CLONEABLE`,`The result of "${t}" can't be sent to the page.`,{cause:n,details:{method:t}}))}},l=t=>{let{id:n,method:i}=t,l=Object.hasOwn(e,i)?e[i]:void 0;if(typeof l!=`function`){s(n,new r(`WORKER_METHOD_NOT_FOUND`,`The worker has no method "${i}".`,{details:{method:i}}));return}let u=new AbortController;a.set(n,u);let d={signal:u.signal,progress:e=>{a.get(n)===u&&o(x({type:`progress`,id:n,value:e}))}};Promise.resolve().then(()=>l.call(e,t.input,d)).then(e=>{a.delete(n),c(n,i,e)},e=>{a.delete(n),s(n,e)})},u=e=>{o(x({type:`crash`,error:d(e,{includeStack:i})}))};n.addEventListener(`message`,e=>{let t=ne(e.data);t!==void 0&&t.version===1&&(t.type===`call`?l(t):t.type===`cancel`&&a.get(t.id)?.abort())}),n.addEventListener(`error`,e=>{let t=e;u(t.error??Error(t.message))}),n.addEventListener(`unhandledrejection`,e=>{u(e.reason)}),o(x({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var T=class extends r{name=`ImageError`},E=/* @__PURE__ */ v({...ee,maxDecodedSize:{...ee.maxDecodedSize,default:1e9,warning:4e8},maxImagePixels:{code:`IMAGE_TOO_LARGE`,unit:`pixels`,default:5e7,warning:24e6},maxImageDimension:{code:`IMAGE_DIMENSION_TOO_LARGE`,unit:`pixels`,default:16384},maxFrames:{code:`TOO_MANY_FRAMES`,unit:`count`,default:300,warning:100},maxSessionSize:{code:`SESSION_TOO_LARGE`,unit:`bytes`,default:1e9,warning:5e8},maxLayers:{code:`TOO_MANY_LAYERS`,unit:`count`,default:256}},{errorClass:T}),le=[`maxFileSize`,`maxImageDimension`,`maxImagePixels`,`maxFrames`,`maxDecodedSize`];function D(e,t,n){let{width:r,height:i}=n.oriented,a={maxFileSize:t,maxImageDimension:Math.max(r,i),maxImagePixels:r*i,maxFrames:n.frames,maxDecodedSize:n.decodedPixelBound*4};return le.filter(t=>e.check(t,a[t])===`warning`)}function O(e,t){e.check(`maxImageDimension`,Math.max(t.width,t.height)),e.check(`maxImagePixels`,t.width*t.height)}function ue(e){let t=Math.min(e.pixelRatio,4);return{width:Math.max(1,Math.round(e.width*t)),height:Math.max(1,Math.round(e.height*t))}}function de(e,t){let n=t.inset??0,r=Math.min((t.width-2*n)/e.width,(t.height-2*n)/e.height),i=Math.max(0,r)*t.zoom,a=e.width*i,o=e.height*i;return{x:(t.width-a)/2+t.pan.x,y:(t.height-o)/2+t.pan.y,width:a,height:o,scale:i}}var fe=Object.freeze({location:!1,camera:!1,timestamps:!1,thumbnail:!1,colourProfile:!1,other:!1}),pe=Object.freeze({title:``,description:``,artist:``,copyright:``}),me=2e3;function he(e,t){if(e.length<=t)return!1;let n=0;for(let r of e)if(n+=1,n>t)return!0;return!1}function k(e,t){return new T(`INVALID_IMAGE`,`Invalid ${e}: ${t}.`,{details:{format:e,problem:t}})}async function A(e,t,n,r,i){if(n+r>e.size)throw k(t,`${i} ends past the end of the file`);return e.bytes(n,r)}function j(e,t){return(e[t]??0)<<8|(e[t+1]??0)}function M(e,t){return((e[t]??0)<<24|(e[t+1]??0)<<16|(e[t+2]??0)<<8|(e[t+3]??0))>>>0}function N(e,t,n){let r=``;for(let i=t;i<t+n&&i<e.length;i+=1)r+=String.fromCharCode(e[i]??0);return r}function P(e,t){return t.every((t,n)=>e[n]===t)}function F(e,t){return(e[t]??0)|(e[t+1]??0)<<8}function I(e,t){return(e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16}function L(e,t){return((e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16|(e[t+3]??0)<<24)>>>0}function ge(e,t){return L(e,t)|0}var R=/* @__PURE__ */ new Set([12,40,52,56,108,124]);function _e(e){return N(e,0,2)===`BM`}async function ve(e){let t=await A(e,`bmp`,0,18,`the file header`),n=L(t,10),r=L(t,14);if(!R.has(r))throw k(`bmp`,`the DIB header size is unknown`);let i=await A(e,`bmp`,14,r,`the DIB header`),a,o,s;if(r===12?(a=F(i,4),o=F(i,6),s=F(i,10)):(a=ge(i,4),o=Math.abs(ge(i,8)),s=F(i,14)),F(i,r===12?8:12)!==1)throw k(`bmp`,`the plane count isn't 1`);if(a<1||o<1||a>2147483647||o>2147483647)throw k(`bmp`,`the dimensions are out of range`);if(![1,4,8,16,24,32].includes(s))throw k(`bmp`,`the bit depth is unsupported`);if(n<14+r||n>=e.size)throw k(`bmp`,`the pixel data starts outside the file`);let c=r===124&&[1279872587,1296188740].includes(L(i,56)),l={width:a,height:o};return{format:`bmp`,stored:l,oriented:l,orientation:1,frames:1,hasAlpha:s===32,decodedPixelBound:a*o,metadata:{...fe,colourProfile:c},keepable:pe}}var ye=1e6;function be(e){let t=N(e,0,6);return t===`GIF87a`||t===`GIF89a`}async function xe(e,t){let n=t;for(;;){let t=(await A(e,`gif`,n,1,`a data sub-block`))[0]??0;if(n+=1,t===0)return n;if(n+t>e.size)throw k(`gif`,`a data sub-block ends past the end of the file`);n+=t}}async function Se(e){let t=await A(e,`gif`,0,13,`the logical screen descriptor`),n=F(t,6),r=F(t,8);if(n<1||r<1)throw k(`gif`,`the logical screen has no pixels`);let i=t[10]??0,a=13+(i&128?3*2**((i&7)+1):0),o=0,s=!1,c=!1;for(let t=0;;t+=1){if(t>=ye)throw k(`gif`,`the file has too many blocks`);let i=(await A(e,`gif`,a,1,`a block`))[0];if(i===59)break;if(i===33){let t=(await A(e,`gif`,a+1,1,`an extension label`))[0];if(t===249){let t=await A(e,`gif`,a+2,6,`a graphic control extension`);if(t[0]!==4)throw k(`gif`,`a graphic control extension is the wrong size`);if((t[1]??0)&1&&(s=!0),((t[1]??0)>>>2&7)>3)throw k(`gif`,`a frame uses a reserved disposal method`)}else if(t===255){let t=N(await A(e,`gif`,a+2,12,`an application extension`),1,11);t!==`NETSCAPE2.0`&&t!==`ANIMEXTS1.0`&&(c=!0)}else t===254&&(c=!0);a=await xe(e,a+2)}else if(i===44){let t=await A(e,`gif`,a,10,`an image descriptor`),i=F(t,1),s=F(t,3),c=F(t,5),l=F(t,7);if(c<1||l<1||i+c>n||s+l>r)throw k(`gif`,`a frame doesn't fit inside the logical screen`);let u=t[9]??0;a+=10+(u&128?3*2**((u&7)+1):0);let d=(await A(e,`gif`,a,1,`an LZW minimum code size`))[0]??0;if(d<2||d>8)throw k(`gif`,`a frame's LZW minimum code size is out of range`);a=await xe(e,a+1),o+=1}else throw k(`gif`,`an unknown block`)}if(o===0)throw k(`gif`,`there are no frames`);let l={width:n,height:r};return{format:`gif`,stored:l,oriented:l,orientation:1,frames:o,hasAlpha:s,decodedPixelBound:o*n*r,metadata:{...fe,other:c},keepable:pe}}function z(e,t){return t>=5?{width:e.height,height:e.width}:e}function Ce(e,t){return e??{x:0,y:0,width:t.width,height:t.height}}function we(e,t){let{width:n,height:r}=Ce(e.base.crop,t);return e.base.orientation.rotate%180==0?{width:n,height:r}:{width:r,height:n}}function Te(e,t){let n=e.kind===`scale`?e.scale:Math.min(1,e.width/t.width,e.height/t.height);return{width:Math.max(1,Math.round(t.width*n)),height:Math.max(1,Math.round(t.height*n))}}function B(){return{orientation:1,location:!1,camera:!1,timestamps:!1,thumbnail:!1,other:!1,title:``,description:``,artist:``,copyright:``}}function Ee(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}var De=8,Oe=1e3,ke=/* @__PURE__ */ new Set([271,272,42033,42035,42036,42037,37500]),Ae=/* @__PURE__ */ new Set([306,36867,36868,36880,36881,36882]),je=/* @__PURE__ */ new Set([34665,34853,40965,513,514]),Me={1:1,2:1,3:2,4:4,5:8,6:1,7:1,8:2,9:4,10:8,11:4,12:8};function Ne(e,t){let n=B();if(e.length<8)throw k(t,`the EXIF block is too short`);let r=e[0]===73&&e[1]===73;if(!r&&(e[0]!==77||e[1]!==77))throw k(t,`the EXIF byte order is unknown`);let i=t=>r?(e[t]??0)|(e[t+1]??0)<<8:(e[t]??0)<<8|(e[t+1]??0),a=t=>(r?(e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16|(e[t+3]??0)<<24:(e[t]??0)<<24|(e[t+1]??0)<<16|(e[t+2]??0)<<8|(e[t+3]??0))>>>0;if(i(2)!==42)throw k(t,`the EXIF block isn't TIFF`);let o=(n,r,i,o)=>{let s=r*(Me[n]??1),c=s<=4?i:a(i);if(c+s>e.length)throw k(t,`an EXIF value ends past the block`);let l=e.subarray(c,c+s),u=(o?new TextDecoder(`utf-16le`).decode(l):Ee(l)).replace(/\0+$/,``);return he(u,2e3)?[...u].slice(0,me).join(``):u},s=/* @__PURE__ */ new Set,c=[{offset:a(4),kind:`main`}];for(;c.length>0;){let{offset:r,kind:l}=c.shift();if(r===0)continue;if(s.has(r))throw k(t,`EXIF directories loop`);if(s.size>=De)throw k(t,`the EXIF block has too many directories`);if(s.add(r),r+2>e.length)throw k(t,`an EXIF directory starts past the block`);let u=i(r);if(u>Oe||r+2+u*12+4>e.length)throw k(t,`an EXIF directory ends past the block`);l===`gps`&&u>0&&(n.location=!0);for(let e=0;e<u;e+=1){let t=r+2+e*12,s=i(t),u=i(t+2),d=a(t+4),f=t+8;if(l!==`gps`){if(s===274&&l===`main`){let e=i(f);n.orientation=e>=1&&e<=8?e:1}else s===34665?c.push({offset:a(f),kind:`exif`}):s===34853?(n.location=!0,c.push({offset:a(f),kind:`gps`})):l===`next`?n.thumbnail=!0:s===270&&u===2?n.description=o(u,d,f,!1):s===315&&u===2?n.artist=o(u,d,f,!1):s===33432&&u===2?n.copyright=o(u,d,f,!1):s===40091&&(u===1||u===7)?n.title=o(1,d,f,!0):ke.has(s)?n.camera=!0:Ae.has(s)?n.timestamps=!0:je.has(s)||(n.other=!0)}}l===`main`?c.push({offset:a(r+2+u*12),kind:`next`}):l===`next`&&(n.thumbnail=!0)}return n}var Pe=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`,`heic`,`heix`,`heim`,`heis`,`hevc`,`hevx`,`mif1`,`mif2`,`msf1`]),Fe=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`]),Ie=/* @__PURE__ */ new Set([`av01`,`hvc1`]),Le=/* @__PURE__ */ new Set([`urn:mpeg:mpegB:cicp:systems:auxiliary:alpha`,`urn:mpeg:hevc:2015:auxid:1`]),Re=/* @__PURE__ */ new Set([`dimg`,`auxl`,`thmb`]),ze=1024,Be=4<<20,Ve=4096,He=1024,Ue=1<<20;function We(e){return N(e,4,4)===`ftyp`&&Pe.has(N(e,8,4))}function Ge(e,t){return M(e,t)*2**32+M(e,t+4)}function V(e,t,n,r){let i=(t,n)=>{if(t.at+n>r)throw k(e,`a box is shorter than its fields`)},a={at:n,end:r,u8(){return i(a,1),a.at+=1,t[a.at-1]??0},u16(){return i(a,2),a.at+=2,j(t,a.at-2)},u32(){return i(a,4),a.at+=4,M(t,a.at-4)},uint(n){if(n===0)return 0;if(n===4)return a.u32();if(n===8)return i(a,8),a.at+=8,Ge(t,a.at-8);throw k(e,`a field has an unsupported size`)},fourcc(){return i(a,4),a.at+=4,N(t,a.at-4,4)},string(){let n=t.subarray(a.at,r).indexOf(0);if(n<0)throw k(e,`a string isn't terminated inside its box`);let i=N(t,a.at,n);return a.at+=n+1,i}};return a}function H(e,t,n,r){let i=[],a=n;for(;a<r;){if(i.length>=Ve)throw k(e,`a box holds too many boxes`);if(a+8>r)throw k(e,`a box header ends past its parent`);let n=M(t,a),o=8;if(n===1){if(a+16>r)throw k(e,`a box header ends past its parent`);n=Ge(t,a+8),o=16}else n===0&&(n=r-a);if(n<o||a+n>r)throw k(e,`a box ends past its parent`);i.push({type:N(t,a+4,4),start:a+o,end:a+n}),a+=n}return i}function U(e,t,n){let r=t.filter(e=>e.type===n);if(r.length>1)throw k(e,`a box that may appear once appears twice`);return r[0]}var Ke=[[1,[1,0,0,1]],[2,[-1,0,0,1]],[3,[-1,0,0,-1]],[4,[1,0,0,-1]],[5,[0,1,1,0]],[6,[0,-1,1,0]],[7,[0,-1,-1,0]],[8,[0,1,-1,0]]];function qe(e){return Ke.find(([t])=>t===e)?.[1]??[1,0,0,1]}function Je(e,t){let[n=0,r=0,i=0,a=0]=qe(t),[o=0,s=0,c=0,l=0]=qe(e),u=[n*o+r*c,n*s+r*l,i*o+a*c,i*s+a*l];return Ke.find(([,e])=>e.every((e,t)=>e===u[t]))?.[0]??1}function Ye(e,t,n){let r=n=>{let r=t.u32(),i=t.u32();if(i===0)throw k(e,`a clean aperture divides by zero`);return(n?r|0:r)/i},i=r(!1),a=r(!1),o=r(!0),s=r(!0);if(!Number.isInteger(i)||!Number.isInteger(a)||i<1||a<1)throw k(e,`a clean aperture isn't a whole number of pixels`);let c=(n.width-i)/2+o,l=(n.height-a)/2+s;if(c<0||l<0||c+i>n.width||l+a>n.height)throw k(e,`a clean aperture lies outside the image`);return{width:i,height:a}}var Xe=[1,8,3,6];async function Ze(e){let t=M(await A(e,`heif`,0,8,`the ftyp box`),0);if(t<16||t>4096)throw k(`heif`,`the ftyp box has an invalid size`);let n=await A(e,`heif`,8,t-8,`the ftyp box`),r=[N(n,0,4)];for(let e=8;e+4<=n.length;e+=4)r.push(N(n,e,4));let i=r.some(e=>Fe.has(e))?`avif`:`heif`,a,o=t;for(let t=0;o<e.size;t+=1){if(t>=ze)throw k(i,`the file has too many boxes`);let n=await A(e,i,o,8,`a box header`),r=M(n,0),s=8;if(r===1?(r=Ge(await A(e,i,o+8,8,`a box header`),0),s=16):r===0&&(r=e.size-o),r<s||o+r>e.size)throw k(i,`a box ends past the end of the file`);let c=N(n,4,4);if(c===`moov`)throw new T(`UNSUPPORTED_FORMAT`,`Image sequences in ${i} aren't supported.`,{details:{format:i}});if(c===`meta`){if(a!==void 0)throw k(i,`there are two meta boxes`);a={start:o+s,end:o+r}}o+=r}if(a===void 0)throw k(i,`there's no meta box`);if(a.end-a.start>Be)throw k(i,`the meta box is too large`);let s=await A(e,i,a.start,a.end-a.start,`the meta box`),c=H(i,s,4,s.length),l=U(i,c,`hdlr`),u=l&&V(i,s,l.start+8,l.end);if(u===void 0||u.fourcc()!==`pict`)throw k(i,`the meta box isn't for a picture`);let d=U(i,c,`pitm`);if(d===void 0)throw k(i,`there's no primary item`);let f=V(i,s,d.start,d.end),p=f.u8();f.at+=3;let m=p===0?f.u16():f.u32(),h=/* @__PURE__ */ new Map,g=U(i,c,`iinf`);if(g===void 0)throw k(i,`there's no item information`);let _=V(i,s,g.start,g.end),ee=_.u8();_.at+=3;let v=ee===0?_.u16():_.u32(),te=H(i,s,_.at,g.end).filter(e=>e.type===`infe`);if(te.length!==v)throw k(i,`the item count doesn't match the item entries`);for(let e of te){let t=V(i,s,e.start,e.end),n=t.u8();t.at+=3;let r;if(n<2)r={id:t.u16(),type:``};else{let e=n===2?t.u16():t.u32();t.u16(),r={id:e,type:t.fourcc()}}if(h.has(r.id))throw k(i,`two items share an ID`);h.set(r.id,r)}let y=h.get(m);if(y===void 0)throw k(i,`the primary item isn't declared`);if(y.type!==`grid`&&!Ie.has(y.type))throw new T(`UNSUPPORTED_FORMAT`,`The ${i} file's primary image type isn't supported.`,{details:{format:i}});let b=[],x=U(i,c,`iref`);if(x!==void 0){let e=s[x.start]??0;for(let t of H(i,s,x.start+4,x.end)){let n=V(i,s,t.start,t.end),r=e===0?n.u16():n.u32(),a=n.u16(),o=[];for(let t=0;t<a;t+=1)o.push(e===0?n.u16():n.u32());b.push({type:t.type,from:r,to:o})}}let ne=U(i,c,`iprp`);if(ne===void 0)throw k(i,`there are no item properties`);let re=H(i,s,ne.start,ne.end),ie=U(i,re,`ipco`);if(ie===void 0)throw k(i,`there's no property container`);let ae=H(i,s,ie.start,ie.end),S=/* @__PURE__ */ new Map;for(let e of re.filter(e=>e.type===`ipma`)){let t=V(i,s,e.start,e.end),n=t.u8();t.u16();let r=(t.u8()&1)==1,a=t.u32();if(a>Ve)throw k(i,`too many property associations`);for(let e=0;e<a;e+=1){let e=n<1?t.u16():t.u32();if(S.has(e))throw k(i,`an item's properties are associated twice`);let a=[],o=t.u8();for(let e=0;e<o;e+=1){let e=r?t.u16()&32767:t.u8()&127;if(e===0)continue;let n=ae[e-1];if(n===void 0)throw k(i,`an item refers to a property that doesn't exist`);a.push(n)}S.set(e,a)}}let C=(e,t)=>(S.get(e)??[]).filter(e=>e.type===t),oe=e=>{let t=C(e,`ispe`),n=t[0];if(n===void 0||t.length>1)throw k(i,`an image item has no single ispe`);let r=V(i,s,n.start+4,n.end),a={width:r.u32(),height:r.u32()};if(a.width<1||a.height<1)throw k(i,`an image item has no pixels`);return a},w=U(i,c,`idat`),se=/* @__PURE__ */ new Map,ce=U(i,c,`iloc`);if(ce!==void 0){let t=V(i,s,ce.start,ce.end),n=t.u8();if(t.at+=3,n>2)throw k(i,`the item location version is unknown`);let r=t.u8(),a=t.u8(),o=r>>>4,c=r&15,l=a>>>4,u=n===0?0:a&15,d=n<2?t.u16():t.u32();if(d>Ve)throw k(i,`too many item locations`);for(let r=0;r<d;r+=1){let r=n<2?t.u16():t.u32(),a=n===0?0:t.u16()&15;t.u16();let s=t.uint(l),d=t.u16(),f=[];for(let n=0;n<d;n+=1){t.uint(u);let n=s+t.uint(o),r=t.uint(c),l=a===0?e.size:a===1?(w?.end??0)-(w?.start??0):1/0,d=r===0?l-n:r;if(n+d>l||d<0)throw k(i,`an item's data lies outside the file`);f.push({offset:n,length:d})}if(se.has(r))throw k(i,`an item is located twice`);se.set(r,{method:a,extents:f})}}let E=async(t,n)=>{let r=se.get(t);if(r===void 0)throw k(i,`an item's data has no location`);let a=r.extents.reduce((e,t)=>e+t.length,0);if(a>n)throw k(i,`an item's data is too large`);let o=[];for(let t of r.extents)if(r.method===0)o.push(await e.bytes(t.offset,t.length));else if(r.method===1&&w!==void 0){let e=w.start+t.offset;o.push(s.subarray(e,e+t.length))}else throw k(i,`an item's data is stored in a way the probe doesn't read`);let c=new Uint8Array(a),l=0;for(let e of o)c.set(e,l),l+=e.length;return c},le=b.filter(e=>Re.has(e.type)),D=/* @__PURE__ */ new Set([m]);for(let e=[m];e.length>0;){let t=e.pop()??m;for(let n of le){let r=n.from===t?n.to:n.to.includes(t)?[n.from]:[];for(let t of r){if(!h.has(t))throw k(i,`a reference names an item that isn't declared`);D.has(t)||(D.add(t),e.push(t))}}}let O=new Map([...D].map(e=>[e,0])),ue=le.filter(e=>D.has(e.from));for(let e of ue)for(let t of e.to)O.set(t,(O.get(t)??0)+1);let de=[...O].filter(([,e])=>e===0).map(([e])=>e),fe=0;for(;de.length>0;){let e=de.pop()??0;fe+=1;for(let t of ue)if(t.from===e)for(let e of t.to){let t=(O.get(e)??0)-1;O.set(e,t),t===0&&de.push(e)}}if(fe!==D.size)throw k(i,`item references form a cycle`);let pe=0;for(let e of D){let t=oe(e);pe+=t.width*t.height,h.get(e)?.type===`grid`&&await me(e,t)}async function me(e,t){let n=b.filter(t=>t.type===`dimg`&&t.from===e),r=n[0]?.to??[];if(n.length!==1||r.length===0)throw k(i,`a grid doesn't name its tiles once`);if(r.length>He)throw k(i,`a grid has too many tiles`);let a=await E(e,64),o=V(i,a,0,a.length);if(o.u8()!==0)throw k(i,`the grid version is unknown`);let s=(o.u8()&1)==1,c=o.u8()+1,l=o.u8()+1,u=s?{width:o.u32(),height:o.u32()}:{width:o.u16(),height:o.u16()};if(c*l!==r.length)throw k(i,`a grid's tile count doesn't match its rows and columns`);if(u.width!==t.width||u.height!==t.height)throw k(i,`a grid's output differs from its ispe`);let d;for(let e of r){if(!Ie.has(h.get(e)?.type??``))throw k(i,`a grid tile isn't a coded image`);let t=oe(e);if(d!==void 0&&(t.width!==d.width||t.height!==d.height))throw k(i,`a grid's tiles differ in size`);d=t}if(d===void 0||t.width>l*d.width||t.height>c*d.height)throw k(i,`a grid's output doesn't fit its tiles`)}let he=oe(m),j=he,P=1,F=!1;for(let e of S.get(m)??[])if(e.type===`clap`){if(F||j!==he)throw k(i,`a clean aperture follows a transformation`);j=Ye(i,V(i,s,e.start,e.end),he)}else if(e.type===`irot`){F=!0;let t=V(i,s,e.start,e.end);P=Je(P,Xe[t.u8()&3]??1)}else if(e.type===`imir`){F=!0;let t=V(i,s,e.start,e.end);P=Je(P,t.u8()&1?2:4)}let I=e=>b.filter(t=>t.type===e&&t.to.includes(m)),L=I(`auxl`).some(e=>C(e.from,`auxC`).some(e=>{let t=V(i,s,e.start+4,e.end);return Le.has(t.string())})),ge=C(m,`colr`).some(e=>{let t=V(i,s,e.start,e.end).fourcc();return t===`prof`||t===`rICC`}),R=B(),_e=[...h.values()].find(e=>e.type===`Exif`);if(_e!==void 0){let e=await E(_e.id,Ue);if(e.length<4||4+M(e,0)>e.length)throw k(i,`the EXIF item's header offset is out of range`);Object.assign(R,Ne(e.subarray(4+M(e,0)),i))}let ve=R.other||[...h.values()].some(e=>e.type===`mime`||e.type===`uri `);return{format:i,stored:j,oriented:z(j,P),orientation:P,frames:1,hasAlpha:L,decodedPixelBound:pe,metadata:{location:R.location,camera:R.camera,timestamps:R.timestamps,thumbnail:R.thumbnail||I(`thmb`).length>0,colourProfile:ge,other:ve},keepable:{title:R.title,description:R.description,artist:R.artist,copyright:R.copyright}}}var Qe=[255,216,255],$e=1e4;function et(e){return e>=192&&e<=207&&e!==196&&e!==200&&e!==204}async function tt(e){let t=2,n,r=!1,i=B(),a=!1,o=!1;for(let s=0;!r;s+=1){if(s>=$e)throw k(`jpeg`,`the file has too many segments`);let c=await A(e,`jpeg`,t,2,`a marker`);if(c[0]!==255)throw k(`jpeg`,`a marker is missing`);let l=c[1]??0;if(l===255){t+=1;continue}if(l===216||l===217||l>=208&&l<=215||l===1){if(l===217)throw k(`jpeg`,`the image ends before its first scan`);t+=2;continue}let u=j(await A(e,`jpeg`,t+2,2,`a segment length`),0);if(u<2)throw k(`jpeg`,`a segment length is out of range`);let d=t+4,f=u-2;if(d+f>e.size)throw k(`jpeg`,`a segment ends past the end of the file`);if(et(l)){if(n!==void 0)throw k(`jpeg`,`there's more than one frame header before the scan`);if(f<6)throw k(`jpeg`,`the frame header is too short`);let t=await e.bytes(d,f),r=j(t,1),i=j(t,3),a=t[5]??0;if(r===0)throw k(`jpeg`,`the height is only defined after the scan`);if(i===0||a<1||a>4||f<6+a*3)throw k(`jpeg`,`the frame header is invalid`);n={width:i,height:r,components:a}}else if(l===218){if(n===void 0)throw k(`jpeg`,`the scan comes before a frame header`);r=!0}else if(l===225&&f>=6){if(N(await e.bytes(d,Math.min(f,64)),0,6)===`Exif\0\0`){if(a)i.other=!0;else{a=!0;let t=Ne((await e.bytes(d,f)).subarray(6),`jpeg`);Object.assign(i,t)}}else i.other=!0}else l===226&&f>=12?N(await e.bytes(d,12),0,12)===`ICC_PROFILE\0`?o=!0:i.other=!0:(l>=227&&l<=239||l===254)&&(i.other=!0);t=d+f}let s={width:n?.width??0,height:n?.height??0};return{format:`jpeg`,stored:s,oriented:z(s,i.orientation),orientation:i.orientation,frames:1,hasAlpha:!1,decodedPixelBound:s.width*s.height,metadata:{location:i.location,camera:i.camera,timestamps:i.timestamps,thumbnail:i.thumbnail,colourProfile:o,other:i.other},keepable:{title:i.title,description:i.description,artist:i.artist,copyright:i.copyright}}}var nt=[137,80,78,71,13,10,26,10],rt=2**31-1,it=1e5,at=1<<20,ot={Title:`title`,Description:`description`,Author:`artist`,Copyright:`copyright`};async function st(e){let t=8,n=0,r=0,i=!1,a,o=0,s=!1,c=!1,l=B(),u=!1;for(let d=0;!c;d+=1){if(d>=it)throw k(`png`,`the file has too many chunks`);let f=await A(e,`png`,t,8,`a chunk header`),p=M(f,0),m=N(f,4,4);if(p>2147483647)throw k(`png`,`a chunk length is out of range`);let h=t+8;if(h+p+4>e.size)throw k(`png`,`a chunk ends past the end of the file`);if(d===0&&m!==`IHDR`)throw k(`png`,`IHDR isn't the first chunk`);let g=async()=>{if(p>at)throw k(`png`,`the ${m} chunk is too large`);return e.bytes(h,p)};switch(m){case`IHDR`:{if(d!==0||p!==13)throw k(`png`,`IHDR is repeated or the wrong size`);let e=await g();if(n=M(e,0),r=M(e,4),n<1||r<1||n>rt||r>rt)throw k(`png`,`the dimensions are out of range`);let t=e[9];i=t===4||t===6;break}case`acTL`:if(s||a!==void 0||p!==8)throw k(`png`,`acTL is misplaced, repeated or the wrong size`);if(a=M(await g(),0),a<1)throw k(`png`,`acTL declares no frames`);break;case`fcTL`:{if(p!==26)throw k(`png`,`an fcTL is the wrong size`);let e=await g(),t=M(e,4),i=M(e,8),a=M(e,12),s=M(e,16);if(t<1||i<1||a+t>n||s+i>r)throw k(`png`,`a frame doesn't fit inside the image`);o+=1;break}case`IDAT`:s=!0;break;case`tRNS`:i=!0;break;case`iCCP`:case`sRGB`:case`cICP`:u||=m!==`sRGB`;break;case`tIME`:l.timestamps=!0;break;case`eXIf`:{let e=Ne(await g(),`png`);Object.assign(l,{...e,orientation:s?l.orientation:e.orientation,title:l.title||e.title,description:l.description||e.description,artist:l.artist||e.artist,copyright:l.copyright||e.copyright});break}case`tEXt`:case`iTXt`:case`zTXt`:{let e=await g(),t=e.indexOf(0),n=ot[N(e,0,t<0?Math.min(e.length,79):t)];if(n===void 0)l.other=!0;else if(m===`tEXt`&&t>=0)l[n]=new TextDecoder(`latin1`).decode(e.subarray(t+1)).slice(0,me);else if(m===`iTXt`&&t>=0&&e[t+1]===0){let r=t+3;for(let t=0;t<2&&r<e.length;r+=1)e[r]===0&&(t+=1);l[n]=new TextDecoder().decode(e.subarray(r)).slice(0,me)}else l.other=!0;break}case`IEND`:c=!0}t=h+p+4}if(!s)throw k(`png`,`there's no image data`);if(a!==void 0&&o!==a)throw k(`png`,`acTL's frame count doesn't match the frames`);let d=a??1,f={width:n,height:r};return{format:`png`,stored:f,oriented:z(f,l.orientation),orientation:l.orientation,frames:d,hasAlpha:i,decodedPixelBound:d*n*r,metadata:{location:l.location,camera:l.camera,timestamps:l.timestamps,thumbnail:l.thumbnail,colourProfile:u,other:l.other},keepable:{title:l.title,description:l.description,artist:l.artist,copyright:l.copyright}}}var ct=1e5,lt=1<<20;function ut(e){return N(e,0,4)===`RIFF`&&N(e,8,4)===`WEBP`}async function dt(e){let t=8+L(await A(e,`webp`,0,12,`the RIFF header`),4);if(t>e.size||t<20)throw k(`webp`,`the RIFF size doesn't match the file`);let n=0,r=0,i=!1,a,o=!1,s=0,c=B(),l=!1,u=12;for(let d=0;u<t;d+=1){if(d>=ct)throw k(`webp`,`the file has too many chunks`);let f=await A(e,`webp`,u,8,`a chunk header`),p=N(f,0,4),m=L(f,4),h=u+8;if(h+m>t)throw k(`webp`,`a chunk ends past the RIFF data`);if(d===0&&p!==`VP8 `&&p!==`VP8L`&&p!==`VP8X`)throw k(`webp`,`the first chunk isn't an image header`);switch(p){case`VP8X`:{if(d!==0||m<10)throw k(`webp`,`VP8X is misplaced or too short`);let t=await e.bytes(h,10),o=t[0]??0;i=!!(o&16),a={animated:!!(o&2)},n=I(t,4)+1,r=I(t,7)+1;break}case`VP8 `:if(d===0&&(o=!0),o||a!==void 0&&!a.animated){if(m<10)throw k(`webp`,`the VP8 frame header is too short`);let t=await e.bytes(h,10);if(t[3]!==157||t[4]!==1||t[5]!==42)throw k(`webp`,`the VP8 start code is missing`);let i=((t[6]??0)|(t[7]??0)<<8)&16383,a=((t[8]??0)|(t[9]??0)<<8)&16383;if(o)n=i,r=a;else if(i!==n||a!==r)throw k(`webp`,`the bitstream's size differs from the canvas`);s=1}break;case`VP8L`:if(d===0&&(o=!0),o||a!==void 0&&!a.animated){if(m<5)throw k(`webp`,`the VP8L header is too short`);let t=await e.bytes(h,5);if(t[0]!==47)throw k(`webp`,`the VP8L signature is missing`);let a=L(t,1),c=(a&16383)+1,l=(a>>>14&16383)+1;if(o)n=c,r=l,i=(a>>>28&1)==1;else if(c!==n||l!==r)throw k(`webp`,`the bitstream's size differs from the canvas`);s=1}break;case`ANMF`:{if(a?.animated!==!0)throw k(`webp`,`an animation frame without the animation flag`);if(m<16)throw k(`webp`,`an ANMF header is too short`);let t=await e.bytes(h,16),i=I(t,0)*2,o=I(t,3)*2,c=I(t,6)+1,l=I(t,9)+1;if(i+c>n||o+l>r)throw k(`webp`,`a frame doesn't fit inside the canvas`);s+=1;break}case`EXIF`:{if(m>lt)throw k(`webp`,`the EXIF chunk is too large`);let t=await e.bytes(h,m),n=N(t,0,6)===`Exif\0\0`?t.subarray(6):t;Object.assign(c,Ne(n,`webp`));break}case`ICCP`:l=!0;break;case`XMP `:c.other=!0}u=h+m+m%2}if(a?.animated===!0&&s===0)throw k(`webp`,`an animation without frames`);if(s===0||n<1||r<1)throw k(`webp`,`there's no image data`);let d={width:n,height:r};return{format:`webp`,stored:d,oriented:d,orientation:1,frames:s,hasAlpha:i,decodedPixelBound:s*n*r,metadata:{location:c.location,camera:c.camera,timestamps:c.timestamps,thumbnail:c.thumbnail,colourProfile:l,other:c.other},keepable:{title:c.title,description:c.description,artist:c.artist,copyright:c.copyright}}}async function ft(e){let t=await pt(e);return t.orientation===1?t:{...t,decodedPixelBound:t.decodedPixelBound+t.oriented.width*t.oriented.height}}async function pt(e){let t=await e.bytes(0,16);if(P(t,nt))return st(e);if(P(t,Qe))return tt(e);if(ut(t))return dt(e);if(be(t))return Se(e);if(We(t))return Ze(e);if(_e(t))return ve(e);throw new T(`UNSUPPORTED_FORMAT`,`The file isn't an image format the SDK reads.`,{details:{format:`unknown`}})}var mt=`AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUEAAAD/bWV0YQAAAAAAAAAhaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAAAAAAAOcGl0bQAAAAAAAQAAAB5pbG9jAAAAAEQAAAEAAQAAAAEAAAEnAAAAcgAAAChpaW5mAAAAAAABAAAAGmluZmUCAAAAAAEAAGF2MDFDb2xvcgAAAAB+aXBycAAAAF1pcGNvAAAAFGlzcGUAAAAAAAAAMAAAACAAAAAQcGl4aQAAAAADCAgIAAAADGF2MUOBIAAAAAAAE2NvbHJuY2x4AAEADQAAgAAAAAlpcm90AQAAAAlpbWlyAAAAABlpcG1hAAAAAAAAAAEAAQYBAoMEhYYAAAB6bWRhdBIACgg4FS/7CAhoATJkRAAA66GyTOByOdAYkRkr4m7XruCgkx+mYn1Qgy/LhM4TZqjxnONsI9XbAWAHGMpcPWGmUkXOiY7S7v9FNX7P7LNof17If68icGW/sP+HwSL0D+g3eqOYaSrFfjiDyX15CtJnQA==`,ht=`AAAAHGZ0eXBoZWljAAAAAG1pZjFoZWljbWlhZgAAAYdtZXRhAAAAAAAAACFoZGxyAAAAAAAAAABwaWN0AAAAAAAAAAAAAAAAAAAAACJpbG9jAAAAAERAAAEAAQAAAAABqwABAAAAAAAAAWgAAAAjaWluZgAAAAAAAQAAABVpbmZlAgAAAAABAABodmMxAAAAAA5waXRtAAAAAAABAAABB2lwcnAAAADmaXBjbwAAAHZodmNDAQNwAAAAkAAAAAAAHvAA/P34+AAADwNgAAEAGEABDAH//wNwAAADAJAAAAMAAAMAHroCQGEAAQAqQgEBA3AAAAMAkAAAAwAAAwAeoCCBBZbq5Ka5uAhoMCAAAAMDIAAAAwAhYgABAAZEAcFzwIkAAAATY29scm5jbHgAAQANAAaAAAAAFGlzcGUAAAAAAAAAQAAAAEAAAAAoY2xhcAAAADAAAAABAAAAIAAAAAH////wAAAAAv///+AAAAACAAAAEHBpeGkAAAAAAwgICAAAAAlpcm90AwAAABlpcG1hAAAAAAAAAAEAAQaBAgMFhIYAAAFwbWRhdAAAAWQoAa8GOFr3tt/M4H//+Vpvof3rcAh8Eib+lqP/9+gf/+RCoo6DBnp3DS7HVjpEKagkLLToAgLPf0gsRJBgcTX4smMnA56A3yusdiX58OB/cyikP5RcP/+9DOaSLzxpbfDIZx/2MvdnwDvv9lSv0freK1OdDW2Ic4mjihv4Uz//vczuufFs///BqPj3RM/C9DmybAdK2pHa/WML+n/ofh5OM4ta2QwoyoH3+alRlUJmOn32ErQy0y2l9of783mHK5kj3qBIVLt5C1BsgYvxBJJJhajHb4IsPzEa+wCUZ5YPLfyZ/uW52rOVP02LJknTKZhyZSGGlQM61gCojEG7/8aeNtxBJSuYa9zi2C0FUTZ4EDzXcIldzBDOZRRifvUNh8tXulTFvZTGIysgw+2l3qZ2NW5kvuf+S5yWynAG/xw+MPF+8sAgASh/Fw7rEV3MEM5lFGJ+9Q2Hy1eE3LPWi21NT3jguA==`;function gt(e,{width:t,height:n}){switch(e){case 2:return[-1,0,0,1,t,0];case 3:return[-1,0,0,-1,t,n];case 4:return[1,0,0,-1,0,n];case 5:return[0,1,1,0,0,0];case 6:return[0,1,-1,0,n,0];case 7:return[0,-1,-1,0,n,t];case 8:return[0,-1,1,0,0,t];default:return[1,0,0,1,0,0]}}function _t(e,t){let n={width:e.width,height:e.height},r=z(n,t),i=new OffscreenCanvas(r.width,r.height),a=i.getContext(`2d`);if(!a)throw e.close(),Error(`The worker has no 2D canvas.`);return a.setTransform(...gt(t,n)),a.drawImage(e,0,0),e.close(),i.transferToImageBitmap()}var vt=[[255,0,0],[0,255,0],[0,0,255],[255,255,0]];function yt(e){let[t,n,r,i]=gt(e,{width:0,height:0}),a=[[-1,-1],[1,-1],[-1,1],[1,1]],o=[];return a.forEach(([e,s],c)=>{let l=a.findIndex(([a,o])=>a===t*e+r*s&&o===n*e+i*s);o[l]=c}),o}var bt=(e,t)=>t.every((t,n)=>Math.abs((e[n]??NaN)-t)<=64);function xt(e,t,n){for(let r of[1,2,3,4,5,6,7,8]){let i=z(n,r);if(i.width===e.width&&i.height===e.height&&yt(r).every((e,n)=>bt(t[n]??[],vt[e]??[])))return r}}function St(e){let{width:t,height:n}=e,r=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});if(!r)throw Error(`The worker has no 2D canvas.`);return r.drawImage(e,0,0),[[t/4,n/4],[3*t/4,n/4],[t/4,3*n/4],[3*t/4,3*n/4]].map(([e=0,t=0])=>Array.from(r.getImageData(Math.floor(e),Math.floor(t),1,1).data))}var Ct={width:48,height:32};function wt(){let e=new OffscreenCanvas(Ct.width,Ct.height),t=e.getContext(`2d`);if(!t)throw Error(`The worker has no 2D canvas.`);return vt.forEach(([e,n,r],i)=>{t.fillStyle=`rgb(${e} ${n} ${r})`,t.fillRect(i%2*24,Math.floor(i/2)*16,24,16)}),e}function Tt(e){return Uint8Array.of(77,77,0,42,0,0,0,8,0,1,1,18,0,3,0,0,0,1,0,e,0,0,0,0,0,0)}var Et=Array.from({length:256},(e,t)=>{let n=t;for(let e=0;e<8;e+=1)n=n&1?3988292384^n>>>1:n>>>1;return n>>>0});function Dt(e){let t=4294967295;for(let n of e)t=(Et[(t^n)&255]??0)^t>>>8;return(t^4294967295)>>>0}var Ot=(e,t)=>Array.from({length:t},(n,r)=>e>>>8*(t-1-r)&255);async function kt(){let e=new Uint8Array(await(await wt().convertToBlob()).arrayBuffer()),t=Uint8Array.of(101,88,73,102,...Tt(7)),n=Uint8Array.of(...Ot(t.length-4,4),...t,...Ot(Dt(t),4));return new Blob([e.slice(0,33),n,e.slice(33)],{type:`image/png`})}function At(e){return e[2]===255&&e[3]===224?4+((e[4]??0)<<8|(e[5]??0)):2}async function jt(){let e=new Uint8Array(await(await wt().convertToBlob({type:`image/jpeg`,quality:1})).arrayBuffer()),t=Uint8Array.of(69,120,105,102,0,0,...Tt(7)),n=Uint8Array.of(255,225,...Ot(t.length+2,2),...t),r=At(e);return new Blob([e.slice(0,r),n,e.slice(r)],{type:`image/jpeg`})}var Mt=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0));async function Nt(e){switch(e){case`jpeg`:return jt();case`png`:return kt();case`avif`:return new Blob([Mt(mt)]);case`heif`:return new Blob([Mt(ht)]);default:return}}async function Pt(e){let t=await Nt(e);if(!t)return`unknown`;let n=await ft(s(t)),r=await createImageBitmap(t,{imageOrientation:`from-image`});try{let e=xt(r,St(r),n.stored);return n.orientation!==1&&e===n.orientation?`applied`:e===1?`not applied`:`unknown`}finally{r.close()}}var Ft=/* @__PURE__ */ new Map;function It(e,t=Pt){let n=Ft.get(e);return n||(n=t(e).catch(()=>(Ft.delete(e),`unknown`)),Ft.set(e,n)),n}var Lt={decode:e=>createImageBitmap(e,{imageOrientation:`from-image`,premultiplyAlpha:`none`,colorSpaceConversion:`default`}),calibrate:It},Rt=(e,t)=>new T(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:e.format,problem:t}});async function zt(e,t,n=Lt){let r;try{r=await n.decode(e)}catch(e){throw new T(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:t.format},cause:e})}if(t.orientation!==1){let e=await n.calibrate(t.format);if(e===`unknown`)throw r.close(),Rt(t,`this browser's orientation handling is unknown`);if(e===`not applied`)try{r=_t(r,t.orientation)}catch(e){throw new T(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:t.format,problem:`the worker couldn't orient it`},cause:e})}}if(r.width!==t.oriented.width||r.height!==t.oriented.height)throw r.close(),new T(`INVALID_IMAGE`,`The image decoded to another size than its header declares.`,{details:{format:t.format,problem:`the decoded size differs from the probe`}});return r}var Bt=e=>new TextEncoder().encode(e),W=e=>Uint8Array.from(e,e=>e.charCodeAt(0)&255),G=e=>[e>>>8&255,e&255],K=e=>[...G(e>>>16),...G(e&65535)];function q(e){let t=new Uint8Array(e.reduce((e,t)=>e+t.length,0)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t}var Vt=e=>Object.values(e).some(e=>e!==``);function Ht(e){let t=[];if(e.description&&t.push({tag:270,type:2,value:q([Bt(e.description),[0]])}),e.artist&&t.push({tag:315,type:2,value:q([Bt(e.artist),[0]])}),e.copyright&&t.push({tag:33432,type:2,value:q([Bt(e.copyright),[0]])}),e.title){let n=[];for(let t=0;t<e.title.length;t+=1){let r=e.title.charCodeAt(t);n.push(r&255,r>>>8)}n.push(0,0),t.push({tag:40091,type:1,value:Uint8Array.from(n)})}let n=8+(2+t.length*12+4),r=[...G(t.length)],i=[];for(let{tag:e,type:a,value:o}of t)r.push(...G(e),...G(a),...K(o.length)),o.length<=4?r.push(...o,...Array(4-o.length).fill(0)):(r.push(...K(n)),i.push(o),n+=o.length+o.length%2,o.length%2&&i.push(Uint8Array.of(0)));return r.push(...K(0)),q([W(`MM`),G(42),K(8),r,...i])}function Ut(e,t){let n=[e.subarray(0,2)],r=2,i=!1,a=()=>{if(i||!Vt(t))return;i=!0;let e=q([W(`Exif\0\0`),Ht(t)]);n.push(q([[255,225,...G(e.length+2)],e]))};for(;r+4<=e.length&&e[r]===255;){let t=e[r+1]??0;if(!(t>=224&&t<=239)&&t!==254)break;let i=(e[r+2]??0)<<8|(e[r+3]??0),a=e.subarray(r,r+2+i);t===224&&String.fromCharCode(...a.subarray(4,9))===`JFIF\0`&&n.push(a),r+=2+i}return a(),n.push(e.subarray(r)),q(n)}var Wt=Array.from({length:256},(e,t)=>{let n=t;for(let e=0;e<8;e+=1)n=n&1?3988292384^n>>>1:n>>>1;return n>>>0});function Gt(e,t){let n=q([W(e),t]),r=4294967295;for(let e of n)r=(Wt[(r^e)&255]??0)^r>>>8;return q([K(t.length),n,K((r^4294967295)>>>0)])}var Kt=/* @__PURE__ */ new Set([`IHDR`,`PLTE`,`tRNS`,`IDAT`,`IEND`]),qt={title:`Title`,description:`Description`,artist:`Author`,copyright:`Copyright`};function Jt(e,t){let n=[e.subarray(0,8)],r=8;for(;r+12<=e.length;){let i=((e[r]??0)<<24|(e[r+1]??0)<<16|(e[r+2]??0)<<8|(e[r+3]??0))>>>0,a=String.fromCharCode(...e.subarray(r+4,r+8)),o=r+12+i;if(Kt.has(a)&&n.push(e.subarray(r,o)),a===`IHDR`)for(let[e,r]of Object.entries(qt)){let i=t[e];i&&n.push(Gt(`iTXt`,q([W(r),[0,0,0,0,0],Bt(i)])))}r=o}return q(n)}function Yt(e){let t=[],n=12;for(;n+8<=e.length;){let r=String.fromCharCode(...e.subarray(n,n+4)),i=((e[n+4]??0)|(e[n+5]??0)<<8|(e[n+6]??0)<<16|(e[n+7]??0)<<24)>>>0,a=n+8+i+i%2,o=e.slice(n,a);r===`VP8X`?(o[8]=(o[8]??0)&-45,t.push(o)):(r===`VP8 `||r===`VP8L`||r===`ALPH`||r===`ANIM`||r===`ANMF`)&&t.push(o),n=a}let r=q([W(`WEBP`),...t]),i=r.length;return q([W(`RIFF`),[i&255,i>>>8&255,i>>>16&255,i>>>24],r])}var Xt=Object.freeze({temperature:0,tint:0,exposure:0,highlights:0,shadows:0,contrast:0,saturation:0,vibrance:0});Object.freeze({rotate:0,flipX:!1,flipY:!1}),Object.freeze({kind:`scale`,scale:1});var Zt=.2126,Qt=.7152,$t=.0722,en=[Zt,Qt,$t],J=(e,t)=>[[0,e],[255,t]],tn={vivid:{develop:{contrast:20,saturation:35,vibrance:25}},warm:{develop:{temperature:35,tint:5,vibrance:10}},cool:{develop:{temperature:-35,tint:-5}},fade:{develop:{contrast:-30,shadows:25},curves:[J(30,240),J(30,240),J(30,240)]},mono:{mono:en},noir:{develop:{contrast:50,shadows:-20},mono:en},sepia:{mono:en,curves:[J(40,255),J(20,235),J(0,190)]}},nn=2**20,rn=e=>Math.round(e*nn)/nn,an=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,on=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,Y=4095,sn=Float32Array.from({length:256},(e,t)=>rn(an(t/255))),X=Float32Array.from({length:4096},(e,t)=>rn(an(t/Y))),Z=Float32Array.from({length:4096},(e,t)=>rn(on(t/Y))),cn=Float64Array.from(X,e=>e>0?1/e:0),ln=e=>Math.min(1,Math.max(0,e)),un=e=>Math.round(ln(e)*Y),dn=e=>Math.round(ln(e)*255),fn=(e,t)=>t===0?e:ln(e+t*(e*e*(3-2*e)-e)),Q=e=>[e(0),e(1),e(2)];function pn(e){let t=rn(2**(e.exposure/50)),n=e.temperature/100,r=e.tint/100,i=[(1+.2*n)*t,(1-.2*r)*t,(1-.2*n)*t],[a,o,s]=Q(e=>Float32Array.from(sn,t=>Z[un(t*i[e])])),c=e.contrast/100,l=e.highlights/100*.25,u=e.shadows/100*.25,d=e.saturation/100,f=e.vibrance/100,p=l!==0||u!==0,m=d!==0||f!==0,h=(e,t,n,r)=>{let i=a[e],h=o[t],g=s[n];if(p){let e=Zt*i+Qt*h+$t*g,t=(e-.5)*2;t=Math.min(1,Math.max(0,t));let n=e*2;n=Math.min(1,Math.max(0,n));let r=l*t*t*(3-2*t)+u*(1-n*n*(3-2*n));i+=r,h+=r,g+=r,i=Math.min(1,Math.max(0,i)),h=Math.min(1,Math.max(0,h)),g=Math.min(1,Math.max(0,g))}if(c!==0&&(i+=c*(i*i*(3-2*i)-i),h+=c*(h*h*(3-2*h)-h),g+=c*(g*g*(3-2*g)-g),i=Math.min(1,Math.max(0,i)),h=Math.min(1,Math.max(0,h)),g=Math.min(1,Math.max(0,g))),m){let e=i*Y+.5|0,t=h*Y+.5|0,n=g*Y+.5|0,r=X[e],a=X[t],o=X[n],s=Zt*r+Qt*a+$t*o,c=1+d;if(f!==0){let r=Math.max(e,Math.max(t,n)),i=r>0?(X[r]-X[Math.min(e,Math.min(t,n))])*cn[r]:0;c+=f*(1-i)}i=s+(r-s)*c,h=s+(a-s)*c,g=s+(o-s)*c,i=Z[Math.min(1,Math.max(0,i))*Y+.5|0],h=Z[Math.min(1,Math.max(0,h))*Y+.5|0],g=Z[Math.min(1,Math.max(0,g))*Y+.5|0]}r[0]=i,r[1]=h,r[2]=g},[g,_,ee]=Q(e=>Uint16Array.from([a,o,s][e],e=>un(fn(e,c))));return{perChannel:p||m?void 0:Q(e=>Uint8Array.from([a,o,s][e],e=>dn(fn(e,c)))),run:p?h:(e,t,n,r)=>{let i=g[e],a=_[t],o=ee[n],s=X[i],c=X[a],l=X[o],u=Zt*s+Qt*c+$t*l,p=1+d;if(f!==0){let e=Math.max(i,Math.max(a,o)),t=e>0?(X[e]-X[Math.min(i,Math.min(a,o))])*cn[e]:0;p+=f*(1-t)}let m=u+(s-u)*p,h=u+(c-u)*p,v=u+(l-u)*p;m=Z[Math.min(1,Math.max(0,m))*Y+.5|0],h=Z[Math.min(1,Math.max(0,h))*Y+.5|0],v=Z[Math.min(1,Math.max(0,v))*Y+.5|0],r[0]=m,r[1]=h,r[2]=v}}}function mn(e){return Uint8Array.from({length:256},(t,n)=>{for(let t=1;t<e.length;t+=1){let[r,i]=e[t-1]??[0,0],[a,o]=e[t]??[255,255];if(n<=a)return Math.round(i+(o-i)*(n-r)/(a-r||1))}return e.at(-1)?.[1]??n})}var hn=e=>Object.values(e).every(e=>e===0);function gn(e,t){return!hn(e)||t!==null&&t.strength>0}var _n=e=>new Uint8Array(e.buffer,e.byteOffset,e.length),$=Uint8Array.from({length:256},(e,t)=>t);function vn(e,t){let n=hn(e)?void 0:pn(e),r=t===null||t.strength===0?void 0:tn[t.preset],i=(t?.strength??0)/100,a=r?.develop?pn({...Xt,...r.develop}):void 0,o=r?.curves?Q(e=>mn(r.curves?.[e]??[])):[$,$,$],s=r?.mono,c=r?.curves!==void 0,l=/* @__PURE__ */ new Float64Array(3),u=r!==void 0&&s===void 0&&(!a||a.perChannel)?Q(e=>Uint8Array.from($,t=>{let n=a?.perChannel?.[e][t]??t,r=o[e][n]??n;return Math.round(t+(r-t)*i)})):void 0,d=n?n.perChannel:[$,$,$];if(d&&(!r||u)){let[e,t,n]=Q(e=>Uint8Array.from(d[e],t=>u?u[e][t]??t:t));return r=>{let i=_n(r);for(let r=0;r<i.length;r+=4)i[r]=e[i[r]??0]??0,i[r+1]=t[i[r+1]??0]??0,i[r+2]=n[i[r+2]??0]??0}}return e=>{let t=_n(e);for(let e=0;e<t.length;e+=4){let f=t[e]??0,p=t[e+1]??0,m=t[e+2]??0;if(d?(f=d[0][f]??0,p=d[1][p]??0,m=d[2][m]??0):n&&(n.run(f,p,m,l),f=l[0]*255+.5|0,p=l[1]*255+.5|0,m=l[2]*255+.5|0),u)f=u[0][f]??f,p=u[1][p]??p,m=u[2][m]??m;else if(r){let e,t,n;if(a?.perChannel?(e=(a.perChannel[0][f]??0)/255,t=(a.perChannel[1][p]??0)/255,n=(a.perChannel[2][m]??0)/255):a?(a.run(f,p,m,l),e=l[0]??0,t=l[1]??0,n=l[2]??0):(e=f/255,t=p/255,n=m/255),s){let r=s[0]*e+s[1]*t+s[2]*n;e=r,t=r,n=r}let r=e*255+.5|0,u=t*255+.5|0,d=n*255+.5|0;c&&(r=o[0][r],u=o[1][u],d=o[2][d]),f=f+(r-f)*i+.5|0,p=p+(u-p)*i+.5|0,m=m+(d-m)*i+.5|0}t[e]=f,t[e+1]=p,t[e+2]=m}}}var yn=4e6;function bn(){return new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),e()},t.port2.postMessage(void 0)})}function xn(e,t){return Te(e.output,we(e,t))}async function Sn(e,t,n,r){let{develop:i,filter:a}=t.base,o=gn(i,a),s=Ce(t.base.crop,e),c=we(t,e),l=Te(t.output,c),u=new OffscreenCanvas(l.width,l.height),d=u.getContext(`2d`,{colorSpace:`srgb`,alpha:!n,willReadFrequently:o});if(!d)throw Error(`The worker has no 2D canvas.`);n&&(d.fillStyle=`#ffffff`,d.fillRect(0,0,l.width,l.height));let f=l.width/c.width,p=l.height/c.height;d.imageSmoothingEnabled=f!==1||p!==1,d.imageSmoothingQuality=`high`,d.scale(f,p);let{rotate:m,flipX:h,flipY:g}=t.base.orientation;if(h&&d.transform(-1,0,0,1,c.width,0),g&&d.transform(1,0,0,-1,0,c.height),m===90&&d.transform(0,1,-1,0,c.width,0),m===180&&d.transform(-1,0,0,-1,c.width,c.height),m===270&&d.transform(0,-1,1,0,0,c.height),d.drawImage(e,s.x,s.y,s.width,s.height,0,0,s.width,s.height),d.setTransform(1,0,0,1,0,0),o){let e=vn(i,a),t=Math.max(1,Math.floor(yn/(l.width*4)));for(let n=0;n<l.height;n+=t){if(r&&(await bn(),r.aborted))throw r.reason;let i=d.getImageData(0,n,l.width,Math.min(t,l.height-n),{colorSpace:`srgb`});e(i.data),d.putImageData(i,0,n)}}return u}var Cn={png:`image/png`,jpeg:`image/jpeg`,webp:`image/webp`};async function wn(e,t,n,r){let i=Cn[n.type],a=await Sn(e,t,n.type===`jpeg`,r),o=await a.convertToBlob({type:i,...n.type===`png`?{}:{quality:n.quality??.92}});if(a.width=0,a.height=0,r?.aborted)throw r.reason;if(o.type!==i)throw new T(`UNSUPPORTED_FORMAT`,`This browser can't encode the requested format.`,{details:{format:n.type}});let s=new Uint8Array(await o.arrayBuffer()),c=n.type===`jpeg`?Ut(s,t.metadata):n.type===`png`?Jt(s,t.metadata):Yt(s);return new Blob([c.slice()],{type:i})}async function Tn(e,t,n,r,i){let a=we(n,t),{width:o,height:s}=ue(r),c=Math.min(r.pixelRatio,4),l=de(a,r),u=l.scale*c,d=Math.min(1,u),f=await Sn(t,{...n,output:{kind:`scale`,scale:d}},!1,i);if(i?.aborted)throw f.width=0,i.reason;let{canvas:p}=e;(p.width!==o||p.height!==s)&&(p.width=o,p.height=s),e.clearRect(0,0,o,s),e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`,e.drawImage(f,l.x*c,l.y*c,l.width*c,l.height*c),f.width=0}function En(e,t){return e.format===t.format&&e.orientation===t.orientation&&e.frames===t.frames&&e.decodedPixelBound===t.decodedPixelBound&&e.stored.width===t.stored.width&&e.stored.height===t.stored.height&&e.oriented.width===t.oriented.width&&e.oriented.height===t.oriented.height}function Dn(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;ce({probe:({file:e})=>ft(s(e)),async register({id:e,file:n,probe:r,limits:i},{signal:a}){if(t.has(e))throw TypeError(`The source id "${e}" is already in use.`);let o=await ft(s(n));if(!En(o,r))throw new T(`INVALID_IMAGE`,`The probe doesn't describe this file.`,{details:{format:o.format,problem:`the probe describes another file`}});D(E.resolve(i),n.size,o);let c=await zt(n,o);if(a.aborted)throw c.close(),a.reason;return t.set(e,c),{width:c.width,height:c.height}},thumbnail({id:e,maxSize:n}){let r=t.get(e);if(!r)throw TypeError(`There's no source with the id "${e}".`);let i=Math.min(1,n/r.width,n/r.height);return createImageBitmap(r,{resizeWidth:Math.max(1,Math.round(r.width*i)),resizeHeight:Math.max(1,Math.round(r.height*i)),resizeQuality:`high`})},async export({plan:e,format:n,limits:r},{signal:i}){let a=t.get(e.base.source);if(!a)throw TypeError(`There's no source with the id "${e.base.source}".`);return O(E.resolve(r),xn(e,a)),wn(a,e,n,i)},attachCanvas({id:e,canvas:t}){let r=t.getContext(`2d`,{colorSpace:`srgb`});if(!r)throw Error(`The worker has no 2D canvas.`);n.set(e,r)},async render({id:e,plan:r,view:i,limits:a},{signal:o}){O(E.resolve(a),ue(i));let s=n.get(e);if(!s)throw TypeError(`There's no canvas with the id "${e}".`);let c=t.get(r.base.source);if(!c)throw TypeError(`There's no source with the id "${r.base.source}".`);await Tn(s,c,r,i,o)},detachCanvas({id:e}){let t=n.get(e);t&&(t.canvas.width=0,t.canvas.height=0),n.delete(e)},snapshot({id:e}){let t=n.get(e);if(!t)throw TypeError(`There's no canvas with the id "${e}".`);return createImageBitmap(t.canvas)},release({id:e}){t.get(e)?.close(),t.delete(e)}},{...e,packageVersion:`0.1.0`})}Dn();
|
|
1
|
+
var e=!1;function t(){e||=!0}var n=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),r=class extends Error{name=`SdkError`;code;constructor(e,r,i={}){super(r,`cause`in i?{cause:i.cause}:void 0),t(),this.code=e,Object.defineProperty(this,n,{value:!0}),i.details!==void 0&&(this.details=i.details)}};function i(e,t){if(typeof e!=`object`||!e)return!1;let i=e;return(e instanceof r||i[n]===!0)&&typeof i.code==`string`&&typeof i.message==`string`&&(t===void 0||i.code===t)}var a=1<<20;function o(e,t,n){if(!Number.isSafeInteger(t)||t<n)throw RangeError(`The ${e} must be an integer of at least ${n}, not ${String(t)}.`)}function s(e,t={}){let n=t.windowSize??a;o(`window size`,n,1);let r=e.size,i=0,s=/* @__PURE__ */ new Uint8Array;return{size:r,async bytes(t,a){o(`offset`,t,0),o(`length`,a,0);let c=Math.min(t,r),l=Math.min(r,c+a);if(c<i||l>i+s.length){let t=Math.min(r,c+Math.max(a,n));s=new Uint8Array(await e.slice(c,t).arrayBuffer()),i=c}return s.subarray(c-i,l-i)}}}var c=8,l=16,u=`UNKNOWN`;function d(e,t={}){let n=t.includeStack??!1,r=_(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=f(e),s=n&&h(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),h(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function f(e){if(i(e)){let t={name:e.name,code:e.code,message:e.message},n=p(e.details);return n!==void 0&&(t.details=n),t}if(h(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:u,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:u,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:u,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function p(e){if(!g(e))return;let t=m(e,0);return g(t)?t:void 0}function m(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=l)){if(Array.isArray(e))return e.flatMap(e=>{let n=m(e,t+1);return n===void 0?[]:[n]});if(g(e)){let n={};for(let[r,i]of Object.entries(e)){let e=m(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function h(e){return typeof e==`object`&&!!e}function g(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function _(e){if(e===void 0)return c;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}var ee={maxFileSize:{code:`FILE_TOO_LARGE`,unit:`bytes`,default:1e8,warning:5e7},maxFiles:{code:`TOO_MANY_FILES`,unit:`count`,default:20},maxDecodedSize:{code:`DECODED_SIZE_TOO_LARGE`,unit:`bytes`,default:5e8},maxProcessingTime:{code:`PROCESSING_TIME_EXCEEDED`,unit:`milliseconds`,default:12e4}};function v(e,t={}){let n=t.errorClass??r;for(let[t,n]of Object.entries(e))y(`${t}.default`,n.default),n.warning!==void 0&&y(`${t}.warning`,n.warning);return{definitions:e,resolve(t={}){let r={};for(let[t,n]of Object.entries(e))r[t]={maximum:n.default,warning:n.warning??1/0};for(let[e,n]of Object.entries(t)){let t=Object.hasOwn(r,e)?r[e]:void 0;if(t===void 0)throw TypeError(`"${e}" isn't a file policy limit. Known limits: ${Object.keys(r).join(`, `)}.`);r[e]=te(e,t,n)}let i=(t,n)=>{let i=Object.hasOwn(r,t)?r[t]:void 0,a=Object.hasOwn(e,t)?e[t]:void 0;if(i===void 0||a===void 0)throw TypeError(`"${t}" isn't a file policy limit.`);if(typeof n!=`number`||Number.isNaN(n)||n<0)throw RangeError(`The value checked against ${t} must be a non-negative number, received ${String(n)}.`);return{resolved:i,definition:a,actual:n}},a=(e,t)=>{let r=i(e,t),{maximum:a}=r.resolved,{code:o,unit:s}=r.definition;return new n(o,`${e} is ${a} ${s}, but the value is ${r.actual}.`,{details:{limit:e,maximum:a,actual:r.actual,unit:s}})};return{limits:r,check(e,t){let{resolved:n}=i(e,t);if(t>n.maximum)throw a(e,t);return t>=n.warning?`warning`:void 0},error:(e,t)=>a(e,t)}}}}function te(e,t,n){if(typeof n==`number`)return y(e,n),{...t,maximum:n};if(typeof n!=`object`||!n)throw TypeError(`The setting for ${e} must be a number or { maximum, warning }.`);let{maximum:r=t.maximum,warning:i=t.warning,...a}=n,o=Object.keys(a);if(o.length>0)throw TypeError(`The setting for ${e} has unknown keys: ${o.join(`, `)}.`);return y(`${e}.maximum`,r),y(`${e}.warning`,i),{maximum:r,warning:i}}function y(e,t){if(typeof t!=`number`||Number.isNaN(t)||t<=0)throw RangeError(`${e} must be a positive number or Infinity, received ${String(t)}.`)}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var b=`hm-rpc`;function x(e){return{protocol:b,version:1,...e}}function ne(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function re(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=ae(e)?e:S(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return oe(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):w(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),se(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function ie(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function ae(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function S(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var C=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function oe(e){let t=globalThis;return C.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function w(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function se(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function ce(e,t={}){let n=t.scope??globalThis,i=t.includeStack??!1,a=/* @__PURE__ */ new Map,o=(e,t=[])=>{n.postMessage(e,t)},s=(e,t)=>{o(x({type:`error`,id:e,error:d(t,{includeStack:i})}))},c=(e,t,i)=>{let a=re(i,!0);try{ie((e,t)=>n.postMessage(e,t),x({type:`result`,id:e,output:a.value}),a.transferables)}catch(n){s(e,new r(`WORKER_DATA_NOT_CLONEABLE`,`The result of "${t}" can't be sent to the page.`,{cause:n,details:{method:t}}))}},l=t=>{let{id:n,method:i}=t,l=Object.hasOwn(e,i)?e[i]:void 0;if(typeof l!=`function`){s(n,new r(`WORKER_METHOD_NOT_FOUND`,`The worker has no method "${i}".`,{details:{method:i}}));return}let u=new AbortController;a.set(n,u);let d={signal:u.signal,progress:e=>{a.get(n)===u&&o(x({type:`progress`,id:n,value:e}))}};Promise.resolve().then(()=>l.call(e,t.input,d)).then(e=>{a.delete(n),c(n,i,e)},e=>{a.delete(n),s(n,e)})},u=e=>{o(x({type:`crash`,error:d(e,{includeStack:i})}))};n.addEventListener(`message`,e=>{let t=ne(e.data);t!==void 0&&t.version===1&&(t.type===`call`?l(t):t.type===`cancel`&&a.get(t.id)?.abort())}),n.addEventListener(`error`,e=>{let t=e;u(t.error??Error(t.message))}),n.addEventListener(`unhandledrejection`,e=>{u(e.reason)}),o(x({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var T=class extends r{name=`ImageError`},E=/* @__PURE__ */ v({...ee,maxDecodedSize:{...ee.maxDecodedSize,default:1e9,warning:4e8},maxImagePixels:{code:`IMAGE_TOO_LARGE`,unit:`pixels`,default:5e7,warning:24e6},maxImageDimension:{code:`IMAGE_DIMENSION_TOO_LARGE`,unit:`pixels`,default:16384},maxFrames:{code:`TOO_MANY_FRAMES`,unit:`count`,default:300,warning:100},maxSessionSize:{code:`SESSION_TOO_LARGE`,unit:`bytes`,default:1e9,warning:5e8},maxLayers:{code:`TOO_MANY_LAYERS`,unit:`count`,default:256}},{errorClass:T}),le=[`maxFileSize`,`maxImageDimension`,`maxImagePixels`,`maxFrames`,`maxDecodedSize`];function D(e,t,n){let{width:r,height:i}=n.oriented,a={maxFileSize:t,maxImageDimension:Math.max(r,i),maxImagePixels:r*i,maxFrames:n.frames,maxDecodedSize:n.decodedPixelBound*4};return le.filter(t=>e.check(t,a[t])===`warning`)}function O(e,t){e.check(`maxImageDimension`,Math.max(t.width,t.height)),e.check(`maxImagePixels`,t.width*t.height)}function ue(e){let t=Math.min(e.pixelRatio,4);return{width:Math.max(1,Math.round(e.width*t)),height:Math.max(1,Math.round(e.height*t))}}function de(e,t){let n=t.inset??0,r=Math.min((t.width-2*n)/e.width,(t.height-2*n)/e.height),i=Math.max(0,r)*t.zoom,a=e.width*i,o=e.height*i;return{x:(t.width-a)/2+t.pan.x,y:(t.height-o)/2+t.pan.y,width:a,height:o,scale:i}}var fe=Object.freeze({location:!1,camera:!1,timestamps:!1,thumbnail:!1,colourProfile:!1,other:!1}),pe=Object.freeze({title:``,description:``,artist:``,copyright:``}),me=2e3;function he(e,t){if(e.length<=t)return!1;let n=0;for(let r of e)if(n+=1,n>t)return!0;return!1}function k(e,t){return new T(`INVALID_IMAGE`,`Invalid ${e}: ${t}.`,{details:{format:e,problem:t}})}async function A(e,t,n,r,i){if(n+r>e.size)throw k(t,`${i} ends past the end of the file`);return e.bytes(n,r)}function j(e,t){return(e[t]??0)<<8|(e[t+1]??0)}function M(e,t){return((e[t]??0)<<24|(e[t+1]??0)<<16|(e[t+2]??0)<<8|(e[t+3]??0))>>>0}function N(e,t,n){let r=``;for(let i=t;i<t+n&&i<e.length;i+=1)r+=String.fromCharCode(e[i]??0);return r}function P(e,t){return t.every((t,n)=>e[n]===t)}function F(e,t){return(e[t]??0)|(e[t+1]??0)<<8}function I(e,t){return(e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16}function L(e,t){return((e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16|(e[t+3]??0)<<24)>>>0}function ge(e,t){return L(e,t)|0}var R=/* @__PURE__ */ new Set([12,40,52,56,108,124]);function _e(e){return N(e,0,2)===`BM`}async function ve(e){let t=await A(e,`bmp`,0,18,`the file header`),n=L(t,10),r=L(t,14);if(!R.has(r))throw k(`bmp`,`the DIB header size is unknown`);let i=await A(e,`bmp`,14,r,`the DIB header`),a,o,s;if(r===12?(a=F(i,4),o=F(i,6),s=F(i,10)):(a=ge(i,4),o=Math.abs(ge(i,8)),s=F(i,14)),F(i,r===12?8:12)!==1)throw k(`bmp`,`the plane count isn't 1`);if(a<1||o<1||a>2147483647||o>2147483647)throw k(`bmp`,`the dimensions are out of range`);if(![1,4,8,16,24,32].includes(s))throw k(`bmp`,`the bit depth is unsupported`);if(n<14+r||n>=e.size)throw k(`bmp`,`the pixel data starts outside the file`);let c=r===124&&[1279872587,1296188740].includes(L(i,56)),l={width:a,height:o};return{format:`bmp`,stored:l,oriented:l,orientation:1,frames:1,hasAlpha:s===32,decodedPixelBound:a*o,metadata:{...fe,colourProfile:c},keepable:pe}}var ye=1e6;function be(e){let t=N(e,0,6);return t===`GIF87a`||t===`GIF89a`}async function xe(e,t){let n=t;for(;;){let t=(await A(e,`gif`,n,1,`a data sub-block`))[0]??0;if(n+=1,t===0)return n;if(n+t>e.size)throw k(`gif`,`a data sub-block ends past the end of the file`);n+=t}}async function Se(e){let t=await A(e,`gif`,0,13,`the logical screen descriptor`),n=F(t,6),r=F(t,8);if(n<1||r<1)throw k(`gif`,`the logical screen has no pixels`);let i=t[10]??0,a=13+(i&128?3*2**((i&7)+1):0),o=0,s=!1,c=!1;for(let t=0;;t+=1){if(t>=ye)throw k(`gif`,`the file has too many blocks`);let i=(await A(e,`gif`,a,1,`a block`))[0];if(i===59)break;if(i===33){let t=(await A(e,`gif`,a+1,1,`an extension label`))[0];if(t===249){let t=await A(e,`gif`,a+2,6,`a graphic control extension`);if(t[0]!==4)throw k(`gif`,`a graphic control extension is the wrong size`);if((t[1]??0)&1&&(s=!0),((t[1]??0)>>>2&7)>3)throw k(`gif`,`a frame uses a reserved disposal method`)}else if(t===255){let t=N(await A(e,`gif`,a+2,12,`an application extension`),1,11);t!==`NETSCAPE2.0`&&t!==`ANIMEXTS1.0`&&(c=!0)}else t===254&&(c=!0);a=await xe(e,a+2)}else if(i===44){let t=await A(e,`gif`,a,10,`an image descriptor`),i=F(t,1),s=F(t,3),c=F(t,5),l=F(t,7);if(c<1||l<1||i+c>n||s+l>r)throw k(`gif`,`a frame doesn't fit inside the logical screen`);let u=t[9]??0;a+=10+(u&128?3*2**((u&7)+1):0);let d=(await A(e,`gif`,a,1,`an LZW minimum code size`))[0]??0;if(d<2||d>8)throw k(`gif`,`a frame's LZW minimum code size is out of range`);a=await xe(e,a+1),o+=1}else throw k(`gif`,`an unknown block`)}if(o===0)throw k(`gif`,`there are no frames`);let l={width:n,height:r};return{format:`gif`,stored:l,oriented:l,orientation:1,frames:o,hasAlpha:s,decodedPixelBound:o*n*r,metadata:{...fe,other:c},keepable:pe}}function z(e,t){return t>=5?{width:e.height,height:e.width}:e}function Ce(e,t){return e??{x:0,y:0,width:t.width,height:t.height}}function we(e,t){let{width:n,height:r}=Ce(e.base.crop,t);return e.base.orientation.rotate%180==0?{width:n,height:r}:{width:r,height:n}}function Te(e,t){let n=e.kind===`scale`?e.scale:Math.min(1,e.width/t.width,e.height/t.height);return{width:Math.max(1,Math.round(t.width*n)),height:Math.max(1,Math.round(t.height*n))}}function B(){return{orientation:1,location:!1,camera:!1,timestamps:!1,thumbnail:!1,other:!1,title:``,description:``,artist:``,copyright:``}}function Ee(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}var De=8,Oe=1e3,ke=/* @__PURE__ */ new Set([271,272,42033,42035,42036,42037,37500]),Ae=/* @__PURE__ */ new Set([306,36867,36868,36880,36881,36882]),je=/* @__PURE__ */ new Set([34665,34853,40965,513,514]),Me={1:1,2:1,3:2,4:4,5:8,6:1,7:1,8:2,9:4,10:8,11:4,12:8};function Ne(e,t){let n=B();if(e.length<8)throw k(t,`the EXIF block is too short`);let r=e[0]===73&&e[1]===73;if(!r&&(e[0]!==77||e[1]!==77))throw k(t,`the EXIF byte order is unknown`);let i=t=>r?(e[t]??0)|(e[t+1]??0)<<8:(e[t]??0)<<8|(e[t+1]??0),a=t=>(r?(e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16|(e[t+3]??0)<<24:(e[t]??0)<<24|(e[t+1]??0)<<16|(e[t+2]??0)<<8|(e[t+3]??0))>>>0;if(i(2)!==42)throw k(t,`the EXIF block isn't TIFF`);let o=(n,r,i,o)=>{let s=r*(Me[n]??1),c=s<=4?i:a(i);if(c+s>e.length)throw k(t,`an EXIF value ends past the block`);let l=e.subarray(c,c+s),u=(o?new TextDecoder(`utf-16le`).decode(l):Ee(l)).replace(/\0+$/,``);return he(u,2e3)?[...u].slice(0,me).join(``):u},s=/* @__PURE__ */ new Set,c=[{offset:a(4),kind:`main`}];for(;c.length>0;){let{offset:r,kind:l}=c.shift();if(r===0)continue;if(s.has(r))throw k(t,`EXIF directories loop`);if(s.size>=De)throw k(t,`the EXIF block has too many directories`);if(s.add(r),r+2>e.length)throw k(t,`an EXIF directory starts past the block`);let u=i(r);if(u>Oe||r+2+u*12+4>e.length)throw k(t,`an EXIF directory ends past the block`);l===`gps`&&u>0&&(n.location=!0);for(let e=0;e<u;e+=1){let t=r+2+e*12,s=i(t),u=i(t+2),d=a(t+4),f=t+8;if(l!==`gps`){if(s===274&&l===`main`){let e=i(f);n.orientation=e>=1&&e<=8?e:1}else s===34665?c.push({offset:a(f),kind:`exif`}):s===34853?(n.location=!0,c.push({offset:a(f),kind:`gps`})):l===`next`?n.thumbnail=!0:s===270&&u===2?n.description=o(u,d,f,!1):s===315&&u===2?n.artist=o(u,d,f,!1):s===33432&&u===2?n.copyright=o(u,d,f,!1):s===40091&&(u===1||u===7)?n.title=o(1,d,f,!0):ke.has(s)?n.camera=!0:Ae.has(s)?n.timestamps=!0:je.has(s)||(n.other=!0)}}l===`main`?c.push({offset:a(r+2+u*12),kind:`next`}):l===`next`&&(n.thumbnail=!0)}return n}var Pe=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`,`heic`,`heix`,`heim`,`heis`,`hevc`,`hevx`,`mif1`,`mif2`,`msf1`]),Fe=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`]),Ie=/* @__PURE__ */ new Set([`av01`,`hvc1`]),Le=/* @__PURE__ */ new Set([`urn:mpeg:mpegB:cicp:systems:auxiliary:alpha`,`urn:mpeg:hevc:2015:auxid:1`]),Re=/* @__PURE__ */ new Set([`dimg`,`auxl`,`thmb`]),ze=1024,Be=4<<20,Ve=4096,He=1024,Ue=1<<20;function We(e){return N(e,4,4)===`ftyp`&&Pe.has(N(e,8,4))}function Ge(e,t){return M(e,t)*2**32+M(e,t+4)}function V(e,t,n,r){let i=(t,n)=>{if(t.at+n>r)throw k(e,`a box is shorter than its fields`)},a={at:n,end:r,u8(){return i(a,1),a.at+=1,t[a.at-1]??0},u16(){return i(a,2),a.at+=2,j(t,a.at-2)},u32(){return i(a,4),a.at+=4,M(t,a.at-4)},uint(n){if(n===0)return 0;if(n===4)return a.u32();if(n===8)return i(a,8),a.at+=8,Ge(t,a.at-8);throw k(e,`a field has an unsupported size`)},fourcc(){return i(a,4),a.at+=4,N(t,a.at-4,4)},string(){let n=t.subarray(a.at,r).indexOf(0);if(n<0)throw k(e,`a string isn't terminated inside its box`);let i=N(t,a.at,n);return a.at+=n+1,i}};return a}function H(e,t,n,r){let i=[],a=n;for(;a<r;){if(i.length>=Ve)throw k(e,`a box holds too many boxes`);if(a+8>r)throw k(e,`a box header ends past its parent`);let n=M(t,a),o=8;if(n===1){if(a+16>r)throw k(e,`a box header ends past its parent`);n=Ge(t,a+8),o=16}else n===0&&(n=r-a);if(n<o||a+n>r)throw k(e,`a box ends past its parent`);i.push({type:N(t,a+4,4),start:a+o,end:a+n}),a+=n}return i}function U(e,t,n){let r=t.filter(e=>e.type===n);if(r.length>1)throw k(e,`a box that may appear once appears twice`);return r[0]}var Ke=[[1,[1,0,0,1]],[2,[-1,0,0,1]],[3,[-1,0,0,-1]],[4,[1,0,0,-1]],[5,[0,1,1,0]],[6,[0,-1,1,0]],[7,[0,-1,-1,0]],[8,[0,1,-1,0]]];function qe(e){return Ke.find(([t])=>t===e)?.[1]??[1,0,0,1]}function Je(e,t){let[n=0,r=0,i=0,a=0]=qe(t),[o=0,s=0,c=0,l=0]=qe(e),u=[n*o+r*c,n*s+r*l,i*o+a*c,i*s+a*l];return Ke.find(([,e])=>e.every((e,t)=>e===u[t]))?.[0]??1}function Ye(e,t,n){let r=n=>{let r=t.u32(),i=t.u32();if(i===0)throw k(e,`a clean aperture divides by zero`);return(n?r|0:r)/i},i=r(!1),a=r(!1),o=r(!0),s=r(!0);if(!Number.isInteger(i)||!Number.isInteger(a)||i<1||a<1)throw k(e,`a clean aperture isn't a whole number of pixels`);let c=(n.width-i)/2+o,l=(n.height-a)/2+s;if(c<0||l<0||c+i>n.width||l+a>n.height)throw k(e,`a clean aperture lies outside the image`);return{width:i,height:a}}var Xe=[1,8,3,6];async function Ze(e){let t=M(await A(e,`heif`,0,8,`the ftyp box`),0);if(t<16||t>4096)throw k(`heif`,`the ftyp box has an invalid size`);let n=await A(e,`heif`,8,t-8,`the ftyp box`),r=[N(n,0,4)];for(let e=8;e+4<=n.length;e+=4)r.push(N(n,e,4));let i=r.some(e=>Fe.has(e))?`avif`:`heif`,a,o=t;for(let t=0;o<e.size;t+=1){if(t>=ze)throw k(i,`the file has too many boxes`);let n=await A(e,i,o,8,`a box header`),r=M(n,0),s=8;if(r===1?(r=Ge(await A(e,i,o+8,8,`a box header`),0),s=16):r===0&&(r=e.size-o),r<s||o+r>e.size)throw k(i,`a box ends past the end of the file`);let c=N(n,4,4);if(c===`moov`)throw new T(`UNSUPPORTED_FORMAT`,`Image sequences in ${i} aren't supported.`,{details:{format:i}});if(c===`meta`){if(a!==void 0)throw k(i,`there are two meta boxes`);a={start:o+s,end:o+r}}o+=r}if(a===void 0)throw k(i,`there's no meta box`);if(a.end-a.start>Be)throw k(i,`the meta box is too large`);let s=await A(e,i,a.start,a.end-a.start,`the meta box`),c=H(i,s,4,s.length),l=U(i,c,`hdlr`),u=l&&V(i,s,l.start+8,l.end);if(u===void 0||u.fourcc()!==`pict`)throw k(i,`the meta box isn't for a picture`);let d=U(i,c,`pitm`);if(d===void 0)throw k(i,`there's no primary item`);let f=V(i,s,d.start,d.end),p=f.u8();f.at+=3;let m=p===0?f.u16():f.u32(),h=/* @__PURE__ */ new Map,g=U(i,c,`iinf`);if(g===void 0)throw k(i,`there's no item information`);let _=V(i,s,g.start,g.end),ee=_.u8();_.at+=3;let v=ee===0?_.u16():_.u32(),te=H(i,s,_.at,g.end).filter(e=>e.type===`infe`);if(te.length!==v)throw k(i,`the item count doesn't match the item entries`);for(let e of te){let t=V(i,s,e.start,e.end),n=t.u8();t.at+=3;let r;if(n<2)r={id:t.u16(),type:``};else{let e=n===2?t.u16():t.u32();t.u16(),r={id:e,type:t.fourcc()}}if(h.has(r.id))throw k(i,`two items share an ID`);h.set(r.id,r)}let y=h.get(m);if(y===void 0)throw k(i,`the primary item isn't declared`);if(y.type!==`grid`&&!Ie.has(y.type))throw new T(`UNSUPPORTED_FORMAT`,`The ${i} file's primary image type isn't supported.`,{details:{format:i}});let b=[],x=U(i,c,`iref`);if(x!==void 0){let e=s[x.start]??0;for(let t of H(i,s,x.start+4,x.end)){let n=V(i,s,t.start,t.end),r=e===0?n.u16():n.u32(),a=n.u16(),o=[];for(let t=0;t<a;t+=1)o.push(e===0?n.u16():n.u32());b.push({type:t.type,from:r,to:o})}}let ne=U(i,c,`iprp`);if(ne===void 0)throw k(i,`there are no item properties`);let re=H(i,s,ne.start,ne.end),ie=U(i,re,`ipco`);if(ie===void 0)throw k(i,`there's no property container`);let ae=H(i,s,ie.start,ie.end),S=/* @__PURE__ */ new Map;for(let e of re.filter(e=>e.type===`ipma`)){let t=V(i,s,e.start,e.end),n=t.u8();t.u16();let r=(t.u8()&1)==1,a=t.u32();if(a>Ve)throw k(i,`too many property associations`);for(let e=0;e<a;e+=1){let e=n<1?t.u16():t.u32();if(S.has(e))throw k(i,`an item's properties are associated twice`);let a=[],o=t.u8();for(let e=0;e<o;e+=1){let e=r?t.u16()&32767:t.u8()&127;if(e===0)continue;let n=ae[e-1];if(n===void 0)throw k(i,`an item refers to a property that doesn't exist`);a.push(n)}S.set(e,a)}}let C=(e,t)=>(S.get(e)??[]).filter(e=>e.type===t),oe=e=>{let t=C(e,`ispe`),n=t[0];if(n===void 0||t.length>1)throw k(i,`an image item has no single ispe`);let r=V(i,s,n.start+4,n.end),a={width:r.u32(),height:r.u32()};if(a.width<1||a.height<1)throw k(i,`an image item has no pixels`);return a},w=U(i,c,`idat`),se=/* @__PURE__ */ new Map,ce=U(i,c,`iloc`);if(ce!==void 0){let t=V(i,s,ce.start,ce.end),n=t.u8();if(t.at+=3,n>2)throw k(i,`the item location version is unknown`);let r=t.u8(),a=t.u8(),o=r>>>4,c=r&15,l=a>>>4,u=n===0?0:a&15,d=n<2?t.u16():t.u32();if(d>Ve)throw k(i,`too many item locations`);for(let r=0;r<d;r+=1){let r=n<2?t.u16():t.u32(),a=n===0?0:t.u16()&15;t.u16();let s=t.uint(l),d=t.u16(),f=[];for(let n=0;n<d;n+=1){t.uint(u);let n=s+t.uint(o),r=t.uint(c),l=a===0?e.size:a===1?(w?.end??0)-(w?.start??0):1/0,d=r===0?l-n:r;if(n+d>l||d<0)throw k(i,`an item's data lies outside the file`);f.push({offset:n,length:d})}if(se.has(r))throw k(i,`an item is located twice`);se.set(r,{method:a,extents:f})}}let E=async(t,n)=>{let r=se.get(t);if(r===void 0)throw k(i,`an item's data has no location`);let a=r.extents.reduce((e,t)=>e+t.length,0);if(a>n)throw k(i,`an item's data is too large`);let o=[];for(let t of r.extents)if(r.method===0)o.push(await e.bytes(t.offset,t.length));else if(r.method===1&&w!==void 0){let e=w.start+t.offset;o.push(s.subarray(e,e+t.length))}else throw k(i,`an item's data is stored in a way the probe doesn't read`);let c=new Uint8Array(a),l=0;for(let e of o)c.set(e,l),l+=e.length;return c},le=b.filter(e=>Re.has(e.type)),D=/* @__PURE__ */ new Set([m]);for(let e=[m];e.length>0;){let t=e.pop()??m;for(let n of le){let r=n.from===t?n.to:n.to.includes(t)?[n.from]:[];for(let t of r){if(!h.has(t))throw k(i,`a reference names an item that isn't declared`);D.has(t)||(D.add(t),e.push(t))}}}let O=new Map([...D].map(e=>[e,0])),ue=le.filter(e=>D.has(e.from));for(let e of ue)for(let t of e.to)O.set(t,(O.get(t)??0)+1);let de=[...O].filter(([,e])=>e===0).map(([e])=>e),fe=0;for(;de.length>0;){let e=de.pop()??0;fe+=1;for(let t of ue)if(t.from===e)for(let e of t.to){let t=(O.get(e)??0)-1;O.set(e,t),t===0&&de.push(e)}}if(fe!==D.size)throw k(i,`item references form a cycle`);let pe=0;for(let e of D){let t=oe(e);pe+=t.width*t.height,h.get(e)?.type===`grid`&&await me(e,t)}async function me(e,t){let n=b.filter(t=>t.type===`dimg`&&t.from===e),r=n[0]?.to??[];if(n.length!==1||r.length===0)throw k(i,`a grid doesn't name its tiles once`);if(r.length>He)throw k(i,`a grid has too many tiles`);let a=await E(e,64),o=V(i,a,0,a.length);if(o.u8()!==0)throw k(i,`the grid version is unknown`);let s=(o.u8()&1)==1,c=o.u8()+1,l=o.u8()+1,u=s?{width:o.u32(),height:o.u32()}:{width:o.u16(),height:o.u16()};if(c*l!==r.length)throw k(i,`a grid's tile count doesn't match its rows and columns`);if(u.width!==t.width||u.height!==t.height)throw k(i,`a grid's output differs from its ispe`);let d;for(let e of r){if(!Ie.has(h.get(e)?.type??``))throw k(i,`a grid tile isn't a coded image`);let t=oe(e);if(d!==void 0&&(t.width!==d.width||t.height!==d.height))throw k(i,`a grid's tiles differ in size`);d=t}if(d===void 0||t.width>l*d.width||t.height>c*d.height)throw k(i,`a grid's output doesn't fit its tiles`)}let he=oe(m),j=he,P=1,F=!1;for(let e of S.get(m)??[])if(e.type===`clap`){if(F||j!==he)throw k(i,`a clean aperture follows a transformation`);j=Ye(i,V(i,s,e.start,e.end),he)}else if(e.type===`irot`){F=!0;let t=V(i,s,e.start,e.end);P=Je(P,Xe[t.u8()&3]??1)}else if(e.type===`imir`){F=!0;let t=V(i,s,e.start,e.end);P=Je(P,t.u8()&1?2:4)}let I=e=>b.filter(t=>t.type===e&&t.to.includes(m)),L=I(`auxl`).some(e=>C(e.from,`auxC`).some(e=>{let t=V(i,s,e.start+4,e.end);return Le.has(t.string())})),ge=C(m,`colr`).some(e=>{let t=V(i,s,e.start,e.end).fourcc();return t===`prof`||t===`rICC`}),R=B(),_e=[...h.values()].find(e=>e.type===`Exif`);if(_e!==void 0){let e=await E(_e.id,Ue);if(e.length<4||4+M(e,0)>e.length)throw k(i,`the EXIF item's header offset is out of range`);Object.assign(R,Ne(e.subarray(4+M(e,0)),i))}let ve=R.other||[...h.values()].some(e=>e.type===`mime`||e.type===`uri `);return{format:i,stored:j,oriented:z(j,P),orientation:P,frames:1,hasAlpha:L,decodedPixelBound:pe,metadata:{location:R.location,camera:R.camera,timestamps:R.timestamps,thumbnail:R.thumbnail||I(`thmb`).length>0,colourProfile:ge,other:ve},keepable:{title:R.title,description:R.description,artist:R.artist,copyright:R.copyright}}}var Qe=[255,216,255],$e=1e4;function et(e){return e>=192&&e<=207&&e!==196&&e!==200&&e!==204}async function tt(e){let t=2,n,r=!1,i=B(),a=!1,o=!1;for(let s=0;!r;s+=1){if(s>=$e)throw k(`jpeg`,`the file has too many segments`);let c=await A(e,`jpeg`,t,2,`a marker`);if(c[0]!==255)throw k(`jpeg`,`a marker is missing`);let l=c[1]??0;if(l===255){t+=1;continue}if(l===216||l===217||l>=208&&l<=215||l===1){if(l===217)throw k(`jpeg`,`the image ends before its first scan`);t+=2;continue}let u=j(await A(e,`jpeg`,t+2,2,`a segment length`),0);if(u<2)throw k(`jpeg`,`a segment length is out of range`);let d=t+4,f=u-2;if(d+f>e.size)throw k(`jpeg`,`a segment ends past the end of the file`);if(et(l)){if(n!==void 0)throw k(`jpeg`,`there's more than one frame header before the scan`);if(f<6)throw k(`jpeg`,`the frame header is too short`);let t=await e.bytes(d,f),r=j(t,1),i=j(t,3),a=t[5]??0;if(r===0)throw k(`jpeg`,`the height is only defined after the scan`);if(i===0||a<1||a>4||f<6+a*3)throw k(`jpeg`,`the frame header is invalid`);n={width:i,height:r,components:a}}else if(l===218){if(n===void 0)throw k(`jpeg`,`the scan comes before a frame header`);r=!0}else if(l===225&&f>=6){if(N(await e.bytes(d,Math.min(f,64)),0,6)===`Exif\0\0`){if(a)i.other=!0;else{a=!0;let t=Ne((await e.bytes(d,f)).subarray(6),`jpeg`);Object.assign(i,t)}}else i.other=!0}else l===226&&f>=12?N(await e.bytes(d,12),0,12)===`ICC_PROFILE\0`?o=!0:i.other=!0:(l>=227&&l<=239||l===254)&&(i.other=!0);t=d+f}let s={width:n?.width??0,height:n?.height??0};return{format:`jpeg`,stored:s,oriented:z(s,i.orientation),orientation:i.orientation,frames:1,hasAlpha:!1,decodedPixelBound:s.width*s.height,metadata:{location:i.location,camera:i.camera,timestamps:i.timestamps,thumbnail:i.thumbnail,colourProfile:o,other:i.other},keepable:{title:i.title,description:i.description,artist:i.artist,copyright:i.copyright}}}var nt=[137,80,78,71,13,10,26,10],rt=2**31-1,it=1e5,at=1<<20,ot={Title:`title`,Description:`description`,Author:`artist`,Copyright:`copyright`};async function st(e){let t=8,n=0,r=0,i=!1,a,o=0,s=!1,c=!1,l=B(),u=!1;for(let d=0;!c;d+=1){if(d>=it)throw k(`png`,`the file has too many chunks`);let f=await A(e,`png`,t,8,`a chunk header`),p=M(f,0),m=N(f,4,4);if(p>2147483647)throw k(`png`,`a chunk length is out of range`);let h=t+8;if(h+p+4>e.size)throw k(`png`,`a chunk ends past the end of the file`);if(d===0&&m!==`IHDR`)throw k(`png`,`IHDR isn't the first chunk`);let g=async()=>{if(p>at)throw k(`png`,`the ${m} chunk is too large`);return e.bytes(h,p)};switch(m){case`IHDR`:{if(d!==0||p!==13)throw k(`png`,`IHDR is repeated or the wrong size`);let e=await g();if(n=M(e,0),r=M(e,4),n<1||r<1||n>rt||r>rt)throw k(`png`,`the dimensions are out of range`);let t=e[9];i=t===4||t===6;break}case`acTL`:if(s||a!==void 0||p!==8)throw k(`png`,`acTL is misplaced, repeated or the wrong size`);if(a=M(await g(),0),a<1)throw k(`png`,`acTL declares no frames`);break;case`fcTL`:{if(p!==26)throw k(`png`,`an fcTL is the wrong size`);let e=await g(),t=M(e,4),i=M(e,8),a=M(e,12),s=M(e,16);if(t<1||i<1||a+t>n||s+i>r)throw k(`png`,`a frame doesn't fit inside the image`);o+=1;break}case`IDAT`:s=!0;break;case`tRNS`:i=!0;break;case`iCCP`:case`sRGB`:case`cICP`:u||=m!==`sRGB`;break;case`tIME`:l.timestamps=!0;break;case`eXIf`:{let e=Ne(await g(),`png`);Object.assign(l,{...e,orientation:s?l.orientation:e.orientation,title:l.title||e.title,description:l.description||e.description,artist:l.artist||e.artist,copyright:l.copyright||e.copyright});break}case`tEXt`:case`iTXt`:case`zTXt`:{let e=await g(),t=e.indexOf(0),n=ot[N(e,0,t<0?Math.min(e.length,79):t)];if(n===void 0)l.other=!0;else if(m===`tEXt`&&t>=0)l[n]=new TextDecoder(`latin1`).decode(e.subarray(t+1)).slice(0,me);else if(m===`iTXt`&&t>=0&&e[t+1]===0){let r=t+3;for(let t=0;t<2&&r<e.length;r+=1)e[r]===0&&(t+=1);l[n]=new TextDecoder().decode(e.subarray(r)).slice(0,me)}else l.other=!0;break}case`IEND`:c=!0}t=h+p+4}if(!s)throw k(`png`,`there's no image data`);if(a!==void 0&&o!==a)throw k(`png`,`acTL's frame count doesn't match the frames`);let d=a??1,f={width:n,height:r};return{format:`png`,stored:f,oriented:z(f,l.orientation),orientation:l.orientation,frames:d,hasAlpha:i,decodedPixelBound:d*n*r,metadata:{location:l.location,camera:l.camera,timestamps:l.timestamps,thumbnail:l.thumbnail,colourProfile:u,other:l.other},keepable:{title:l.title,description:l.description,artist:l.artist,copyright:l.copyright}}}var ct=1e5,lt=1<<20;function ut(e){return N(e,0,4)===`RIFF`&&N(e,8,4)===`WEBP`}async function dt(e){let t=8+L(await A(e,`webp`,0,12,`the RIFF header`),4);if(t>e.size||t<20)throw k(`webp`,`the RIFF size doesn't match the file`);let n=0,r=0,i=!1,a,o=!1,s=0,c=B(),l=!1,u=12;for(let d=0;u<t;d+=1){if(d>=ct)throw k(`webp`,`the file has too many chunks`);let f=await A(e,`webp`,u,8,`a chunk header`),p=N(f,0,4),m=L(f,4),h=u+8;if(h+m>t)throw k(`webp`,`a chunk ends past the RIFF data`);if(d===0&&p!==`VP8 `&&p!==`VP8L`&&p!==`VP8X`)throw k(`webp`,`the first chunk isn't an image header`);switch(p){case`VP8X`:{if(d!==0||m<10)throw k(`webp`,`VP8X is misplaced or too short`);let t=await e.bytes(h,10),o=t[0]??0;i=!!(o&16),a={animated:!!(o&2)},n=I(t,4)+1,r=I(t,7)+1;break}case`VP8 `:if(d===0&&(o=!0),o||a!==void 0&&!a.animated){if(m<10)throw k(`webp`,`the VP8 frame header is too short`);let t=await e.bytes(h,10);if(t[3]!==157||t[4]!==1||t[5]!==42)throw k(`webp`,`the VP8 start code is missing`);let i=((t[6]??0)|(t[7]??0)<<8)&16383,a=((t[8]??0)|(t[9]??0)<<8)&16383;if(o)n=i,r=a;else if(i!==n||a!==r)throw k(`webp`,`the bitstream's size differs from the canvas`);s=1}break;case`VP8L`:if(d===0&&(o=!0),o||a!==void 0&&!a.animated){if(m<5)throw k(`webp`,`the VP8L header is too short`);let t=await e.bytes(h,5);if(t[0]!==47)throw k(`webp`,`the VP8L signature is missing`);let a=L(t,1),c=(a&16383)+1,l=(a>>>14&16383)+1;if(o)n=c,r=l,i=(a>>>28&1)==1;else if(c!==n||l!==r)throw k(`webp`,`the bitstream's size differs from the canvas`);s=1}break;case`ANMF`:{if(a?.animated!==!0)throw k(`webp`,`an animation frame without the animation flag`);if(m<16)throw k(`webp`,`an ANMF header is too short`);let t=await e.bytes(h,16),i=I(t,0)*2,o=I(t,3)*2,c=I(t,6)+1,l=I(t,9)+1;if(i+c>n||o+l>r)throw k(`webp`,`a frame doesn't fit inside the canvas`);s+=1;break}case`EXIF`:{if(m>lt)throw k(`webp`,`the EXIF chunk is too large`);let t=await e.bytes(h,m),n=N(t,0,6)===`Exif\0\0`?t.subarray(6):t;Object.assign(c,Ne(n,`webp`));break}case`ICCP`:l=!0;break;case`XMP `:c.other=!0}u=h+m+m%2}if(a?.animated===!0&&s===0)throw k(`webp`,`an animation without frames`);if(s===0||n<1||r<1)throw k(`webp`,`there's no image data`);let d={width:n,height:r};return{format:`webp`,stored:d,oriented:d,orientation:1,frames:s,hasAlpha:i,decodedPixelBound:s*n*r,metadata:{location:c.location,camera:c.camera,timestamps:c.timestamps,thumbnail:c.thumbnail,colourProfile:l,other:c.other},keepable:{title:c.title,description:c.description,artist:c.artist,copyright:c.copyright}}}async function ft(e){let t=await pt(e);return t.orientation===1?t:{...t,decodedPixelBound:t.decodedPixelBound+t.oriented.width*t.oriented.height}}async function pt(e){let t=await e.bytes(0,16);if(P(t,nt))return st(e);if(P(t,Qe))return tt(e);if(ut(t))return dt(e);if(be(t))return Se(e);if(We(t))return Ze(e);if(_e(t))return ve(e);throw new T(`UNSUPPORTED_FORMAT`,`The file isn't an image format the SDK reads.`,{details:{format:`unknown`}})}var mt=`AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUEAAAD/bWV0YQAAAAAAAAAhaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAAAAAAAOcGl0bQAAAAAAAQAAAB5pbG9jAAAAAEQAAAEAAQAAAAEAAAEnAAAAcgAAAChpaW5mAAAAAAABAAAAGmluZmUCAAAAAAEAAGF2MDFDb2xvcgAAAAB+aXBycAAAAF1pcGNvAAAAFGlzcGUAAAAAAAAAMAAAACAAAAAQcGl4aQAAAAADCAgIAAAADGF2MUOBIAAAAAAAE2NvbHJuY2x4AAEADQAAgAAAAAlpcm90AQAAAAlpbWlyAAAAABlpcG1hAAAAAAAAAAEAAQYBAoMEhYYAAAB6bWRhdBIACgg4FS/7CAhoATJkRAAA66GyTOByOdAYkRkr4m7XruCgkx+mYn1Qgy/LhM4TZqjxnONsI9XbAWAHGMpcPWGmUkXOiY7S7v9FNX7P7LNof17If68icGW/sP+HwSL0D+g3eqOYaSrFfjiDyX15CtJnQA==`,ht=`AAAAHGZ0eXBoZWljAAAAAG1pZjFoZWljbWlhZgAAAYdtZXRhAAAAAAAAACFoZGxyAAAAAAAAAABwaWN0AAAAAAAAAAAAAAAAAAAAACJpbG9jAAAAAERAAAEAAQAAAAABqwABAAAAAAAAAWgAAAAjaWluZgAAAAAAAQAAABVpbmZlAgAAAAABAABodmMxAAAAAA5waXRtAAAAAAABAAABB2lwcnAAAADmaXBjbwAAAHZodmNDAQNwAAAAkAAAAAAAHvAA/P34+AAADwNgAAEAGEABDAH//wNwAAADAJAAAAMAAAMAHroCQGEAAQAqQgEBA3AAAAMAkAAAAwAAAwAeoCCBBZbq5Ka5uAhoMCAAAAMDIAAAAwAhYgABAAZEAcFzwIkAAAATY29scm5jbHgAAQANAAaAAAAAFGlzcGUAAAAAAAAAQAAAAEAAAAAoY2xhcAAAADAAAAABAAAAIAAAAAH////wAAAAAv///+AAAAACAAAAEHBpeGkAAAAAAwgICAAAAAlpcm90AwAAABlpcG1hAAAAAAAAAAEAAQaBAgMFhIYAAAFwbWRhdAAAAWQoAa8GOFr3tt/M4H//+Vpvof3rcAh8Eib+lqP/9+gf/+RCoo6DBnp3DS7HVjpEKagkLLToAgLPf0gsRJBgcTX4smMnA56A3yusdiX58OB/cyikP5RcP/+9DOaSLzxpbfDIZx/2MvdnwDvv9lSv0freK1OdDW2Ic4mjihv4Uz//vczuufFs///BqPj3RM/C9DmybAdK2pHa/WML+n/ofh5OM4ta2QwoyoH3+alRlUJmOn32ErQy0y2l9of783mHK5kj3qBIVLt5C1BsgYvxBJJJhajHb4IsPzEa+wCUZ5YPLfyZ/uW52rOVP02LJknTKZhyZSGGlQM61gCojEG7/8aeNtxBJSuYa9zi2C0FUTZ4EDzXcIldzBDOZRRifvUNh8tXulTFvZTGIysgw+2l3qZ2NW5kvuf+S5yWynAG/xw+MPF+8sAgASh/Fw7rEV3MEM5lFGJ+9Q2Hy1eE3LPWi21NT3jguA==`;function gt(e,{width:t,height:n}){switch(e){case 2:return[-1,0,0,1,t,0];case 3:return[-1,0,0,-1,t,n];case 4:return[1,0,0,-1,0,n];case 5:return[0,1,1,0,0,0];case 6:return[0,1,-1,0,n,0];case 7:return[0,-1,-1,0,n,t];case 8:return[0,-1,1,0,0,t];default:return[1,0,0,1,0,0]}}function _t(e,t){let n={width:e.width,height:e.height},r=z(n,t),i=new OffscreenCanvas(r.width,r.height),a=i.getContext(`2d`);if(!a)throw e.close(),Error(`The worker has no 2D canvas.`);return a.setTransform(...gt(t,n)),a.drawImage(e,0,0),e.close(),i.transferToImageBitmap()}var vt=[[255,0,0],[0,255,0],[0,0,255],[255,255,0]];function yt(e){let[t,n,r,i]=gt(e,{width:0,height:0}),a=[[-1,-1],[1,-1],[-1,1],[1,1]],o=[];return a.forEach(([e,s],c)=>{let l=a.findIndex(([a,o])=>a===t*e+r*s&&o===n*e+i*s);o[l]=c}),o}var bt=(e,t)=>t.every((t,n)=>Math.abs((e[n]??NaN)-t)<=64);function xt(e,t,n){for(let r of[1,2,3,4,5,6,7,8]){let i=z(n,r);if(i.width===e.width&&i.height===e.height&&yt(r).every((e,n)=>bt(t[n]??[],vt[e]??[])))return r}}function St(e){let{width:t,height:n}=e,r=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});if(!r)throw Error(`The worker has no 2D canvas.`);return r.drawImage(e,0,0),[[t/4,n/4],[3*t/4,n/4],[t/4,3*n/4],[3*t/4,3*n/4]].map(([e=0,t=0])=>Array.from(r.getImageData(Math.floor(e),Math.floor(t),1,1).data))}var Ct={width:48,height:32};function wt(){let e=new OffscreenCanvas(Ct.width,Ct.height),t=e.getContext(`2d`);if(!t)throw Error(`The worker has no 2D canvas.`);return vt.forEach(([e,n,r],i)=>{t.fillStyle=`rgb(${e} ${n} ${r})`,t.fillRect(i%2*24,Math.floor(i/2)*16,24,16)}),e}function Tt(e){return Uint8Array.of(77,77,0,42,0,0,0,8,0,1,1,18,0,3,0,0,0,1,0,e,0,0,0,0,0,0)}var Et=Array.from({length:256},(e,t)=>{let n=t;for(let e=0;e<8;e+=1)n=n&1?3988292384^n>>>1:n>>>1;return n>>>0});function Dt(e){let t=4294967295;for(let n of e)t=(Et[(t^n)&255]??0)^t>>>8;return(t^4294967295)>>>0}var Ot=(e,t)=>Array.from({length:t},(n,r)=>e>>>8*(t-1-r)&255);async function kt(){let e=new Uint8Array(await(await wt().convertToBlob()).arrayBuffer()),t=Uint8Array.of(101,88,73,102,...Tt(7)),n=Uint8Array.of(...Ot(t.length-4,4),...t,...Ot(Dt(t),4));return new Blob([e.slice(0,33),n,e.slice(33)],{type:`image/png`})}function At(e){return e[2]===255&&e[3]===224?4+((e[4]??0)<<8|(e[5]??0)):2}async function jt(){let e=new Uint8Array(await(await wt().convertToBlob({type:`image/jpeg`,quality:1})).arrayBuffer()),t=Uint8Array.of(69,120,105,102,0,0,...Tt(7)),n=Uint8Array.of(255,225,...Ot(t.length+2,2),...t),r=At(e);return new Blob([e.slice(0,r),n,e.slice(r)],{type:`image/jpeg`})}var Mt=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0));async function Nt(e){switch(e){case`jpeg`:return jt();case`png`:return kt();case`avif`:return new Blob([Mt(mt)]);case`heif`:return new Blob([Mt(ht)]);default:return}}async function Pt(e){let t=await Nt(e);if(!t)return`unknown`;let n=await ft(s(t)),r=await createImageBitmap(t,{imageOrientation:`from-image`});try{let e=xt(r,St(r),n.stored);return n.orientation!==1&&e===n.orientation?`applied`:e===1?`not applied`:`unknown`}finally{r.close()}}var Ft=/* @__PURE__ */ new Map;function It(e,t=Pt){let n=Ft.get(e);return n||(n=t(e).catch(()=>(Ft.delete(e),`unknown`)),Ft.set(e,n)),n}var Lt={decode:e=>createImageBitmap(e,{imageOrientation:`from-image`,premultiplyAlpha:`none`,colorSpaceConversion:`default`}),calibrate:It},Rt=(e,t)=>new T(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:e.format,problem:t}});async function zt(e,t,n=Lt){let r;try{r=await n.decode(e)}catch(e){throw new T(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:t.format},cause:e})}if(t.orientation!==1){let e=await n.calibrate(t.format);if(e===`unknown`)throw r.close(),Rt(t,`this browser's orientation handling is unknown`);if(e===`not applied`)try{r=_t(r,t.orientation)}catch(e){throw new T(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:t.format,problem:`the worker couldn't orient it`},cause:e})}}if(r.width!==t.oriented.width||r.height!==t.oriented.height)throw r.close(),new T(`INVALID_IMAGE`,`The image decoded to another size than its header declares.`,{details:{format:t.format,problem:`the decoded size differs from the probe`}});return r}var Bt=e=>new TextEncoder().encode(e),W=e=>Uint8Array.from(e,e=>e.charCodeAt(0)&255),G=e=>[e>>>8&255,e&255],K=e=>[...G(e>>>16),...G(e&65535)];function q(e){let t=new Uint8Array(e.reduce((e,t)=>e+t.length,0)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t}var Vt=e=>Object.values(e).some(e=>e!==``);function Ht(e){let t=[];if(e.description&&t.push({tag:270,type:2,value:q([Bt(e.description),[0]])}),e.artist&&t.push({tag:315,type:2,value:q([Bt(e.artist),[0]])}),e.copyright&&t.push({tag:33432,type:2,value:q([Bt(e.copyright),[0]])}),e.title){let n=[];for(let t=0;t<e.title.length;t+=1){let r=e.title.charCodeAt(t);n.push(r&255,r>>>8)}n.push(0,0),t.push({tag:40091,type:1,value:Uint8Array.from(n)})}let n=8+(2+t.length*12+4),r=[...G(t.length)],i=[];for(let{tag:e,type:a,value:o}of t)r.push(...G(e),...G(a),...K(o.length)),o.length<=4?r.push(...o,...Array(4-o.length).fill(0)):(r.push(...K(n)),i.push(o),n+=o.length+o.length%2,o.length%2&&i.push(Uint8Array.of(0)));return r.push(...K(0)),q([W(`MM`),G(42),K(8),r,...i])}function Ut(e,t){let n=[e.subarray(0,2)],r=2,i=!1,a=()=>{if(i||!Vt(t))return;i=!0;let e=q([W(`Exif\0\0`),Ht(t)]);n.push(q([[255,225,...G(e.length+2)],e]))};for(;r+4<=e.length&&e[r]===255;){let t=e[r+1]??0;if(!(t>=224&&t<=239)&&t!==254)break;let i=(e[r+2]??0)<<8|(e[r+3]??0),a=e.subarray(r,r+2+i);t===224&&String.fromCharCode(...a.subarray(4,9))===`JFIF\0`&&n.push(a),r+=2+i}return a(),n.push(e.subarray(r)),q(n)}var Wt=Array.from({length:256},(e,t)=>{let n=t;for(let e=0;e<8;e+=1)n=n&1?3988292384^n>>>1:n>>>1;return n>>>0});function Gt(e,t){let n=q([W(e),t]),r=4294967295;for(let e of n)r=(Wt[(r^e)&255]??0)^r>>>8;return q([K(t.length),n,K((r^4294967295)>>>0)])}var Kt=/* @__PURE__ */ new Set([`IHDR`,`PLTE`,`tRNS`,`IDAT`,`IEND`]),qt={title:`Title`,description:`Description`,artist:`Author`,copyright:`Copyright`};function Jt(e,t){let n=[e.subarray(0,8)],r=8;for(;r+12<=e.length;){let i=((e[r]??0)<<24|(e[r+1]??0)<<16|(e[r+2]??0)<<8|(e[r+3]??0))>>>0,a=String.fromCharCode(...e.subarray(r+4,r+8)),o=r+12+i;if(Kt.has(a)&&n.push(e.subarray(r,o)),a===`IHDR`)for(let[e,r]of Object.entries(qt)){let i=t[e];i&&n.push(Gt(`iTXt`,q([W(r),[0,0,0,0,0],Bt(i)])))}r=o}return q(n)}function Yt(e){let t=[],n=12;for(;n+8<=e.length;){let r=String.fromCharCode(...e.subarray(n,n+4)),i=((e[n+4]??0)|(e[n+5]??0)<<8|(e[n+6]??0)<<16|(e[n+7]??0)<<24)>>>0,a=n+8+i+i%2,o=e.slice(n,a);r===`VP8X`?(o[8]=(o[8]??0)&-45,t.push(o)):(r===`VP8 `||r===`VP8L`||r===`ALPH`||r===`ANIM`||r===`ANMF`)&&t.push(o),n=a}let r=q([W(`WEBP`),...t]),i=r.length;return q([W(`RIFF`),[i&255,i>>>8&255,i>>>16&255,i>>>24],r])}var Xt=Object.freeze({temperature:0,tint:0,exposure:0,highlights:0,shadows:0,contrast:0,saturation:0,vibrance:0});Object.freeze({rotate:0,flipX:!1,flipY:!1}),Object.freeze({kind:`scale`,scale:1});var Zt=.2126,Qt=.7152,$t=.0722,en=[Zt,Qt,$t],J=(e,t)=>[[0,e],[255,t]],tn={vivid:{develop:{contrast:20,saturation:35,vibrance:25}},warm:{develop:{temperature:35,tint:5,vibrance:10}},cool:{develop:{temperature:-35,tint:-5}},fade:{develop:{contrast:-30,shadows:25},curves:[J(30,240),J(30,240),J(30,240)]},mono:{mono:en},noir:{develop:{contrast:50,shadows:-20},mono:en},sepia:{mono:en,curves:[J(40,255),J(20,235),J(0,190)]}},nn=2**20,rn=e=>Math.round(e*nn)/nn,an=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,on=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,Y=4095,sn=Float32Array.from({length:256},(e,t)=>rn(an(t/255))),X=Float32Array.from({length:4096},(e,t)=>rn(an(t/Y))),Z=Float32Array.from({length:4096},(e,t)=>rn(on(t/Y))),cn=Float64Array.from(X,e=>e>0?1/e:0),ln=e=>Math.min(1,Math.max(0,e)),un=e=>Math.round(ln(e)*Y),dn=e=>Math.round(ln(e)*255),fn=(e,t)=>t===0?e:ln(e+t*(e*e*(3-2*e)-e)),Q=e=>[e(0),e(1),e(2)];function pn(e){let t=rn(2**(e.exposure/50)),n=e.temperature/100,r=e.tint/100,i=[(1+.2*n)*t,(1-.2*r)*t,(1-.2*n)*t],[a,o,s]=Q(e=>Float32Array.from(sn,t=>Z[un(t*i[e])])),c=e.contrast/100,l=e.highlights/100*.25,u=e.shadows/100*.25,d=e.saturation/100,f=e.vibrance/100,p=l!==0||u!==0,m=d!==0||f!==0,h=(e,t,n,r)=>{let i=a[e],h=o[t],g=s[n];if(p){let e=Zt*i+Qt*h+$t*g,t=(e-.5)*2;t=Math.min(1,Math.max(0,t));let n=e*2;n=Math.min(1,Math.max(0,n));let r=l*t*t*(3-2*t)+u*(1-n*n*(3-2*n));i+=r,h+=r,g+=r,i=Math.min(1,Math.max(0,i)),h=Math.min(1,Math.max(0,h)),g=Math.min(1,Math.max(0,g))}if(c!==0&&(i+=c*(i*i*(3-2*i)-i),h+=c*(h*h*(3-2*h)-h),g+=c*(g*g*(3-2*g)-g),i=Math.min(1,Math.max(0,i)),h=Math.min(1,Math.max(0,h)),g=Math.min(1,Math.max(0,g))),m){let e=i*Y+.5|0,t=h*Y+.5|0,n=g*Y+.5|0,r=X[e],a=X[t],o=X[n],s=Zt*r+Qt*a+$t*o,c=1+d;if(f!==0){let r=Math.max(e,Math.max(t,n)),i=r>0?(X[r]-X[Math.min(e,Math.min(t,n))])*cn[r]:0;c+=f*(1-i)}i=s+(r-s)*c,h=s+(a-s)*c,g=s+(o-s)*c,i=Z[Math.min(1,Math.max(0,i))*Y+.5|0],h=Z[Math.min(1,Math.max(0,h))*Y+.5|0],g=Z[Math.min(1,Math.max(0,g))*Y+.5|0]}r[0]=i,r[1]=h,r[2]=g},[g,_,ee]=Q(e=>Uint16Array.from([a,o,s][e],e=>un(fn(e,c))));return{perChannel:p||m?void 0:Q(e=>Uint8Array.from([a,o,s][e],e=>dn(fn(e,c)))),run:p?h:(e,t,n,r)=>{let i=g[e],a=_[t],o=ee[n],s=X[i],c=X[a],l=X[o],u=Zt*s+Qt*c+$t*l,p=1+d;if(f!==0){let e=Math.max(i,Math.max(a,o)),t=e>0?(X[e]-X[Math.min(i,Math.min(a,o))])*cn[e]:0;p+=f*(1-t)}let m=u+(s-u)*p,h=u+(c-u)*p,v=u+(l-u)*p;m=Z[Math.min(1,Math.max(0,m))*Y+.5|0],h=Z[Math.min(1,Math.max(0,h))*Y+.5|0],v=Z[Math.min(1,Math.max(0,v))*Y+.5|0],r[0]=m,r[1]=h,r[2]=v}}}function mn(e){return Uint8Array.from({length:256},(t,n)=>{for(let t=1;t<e.length;t+=1){let[r,i]=e[t-1]??[0,0],[a,o]=e[t]??[255,255];if(n<=a)return Math.round(i+(o-i)*(n-r)/(a-r||1))}return e.at(-1)?.[1]??n})}var hn=e=>Object.values(e).every(e=>e===0);function gn(e,t){return!hn(e)||t!==null&&t.strength>0}var _n=e=>new Uint8Array(e.buffer,e.byteOffset,e.length),$=Uint8Array.from({length:256},(e,t)=>t);function vn(e,t){let n=hn(e)?void 0:pn(e),r=t===null||t.strength===0?void 0:tn[t.preset],i=(t?.strength??0)/100,a=r?.develop?pn({...Xt,...r.develop}):void 0,o=r?.curves?Q(e=>mn(r.curves?.[e]??[])):[$,$,$],s=r?.mono,c=r?.curves!==void 0,l=/* @__PURE__ */ new Float64Array(3),u=r!==void 0&&s===void 0&&(!a||a.perChannel)?Q(e=>Uint8Array.from($,t=>{let n=a?.perChannel?.[e][t]??t,r=o[e][n]??n;return Math.round(t+(r-t)*i)})):void 0,d=n?n.perChannel:[$,$,$];if(d&&(!r||u)){let[e,t,n]=Q(e=>Uint8Array.from(d[e],t=>u?u[e][t]??t:t));return r=>{let i=_n(r);for(let r=0;r<i.length;r+=4)i[r]=e[i[r]??0]??0,i[r+1]=t[i[r+1]??0]??0,i[r+2]=n[i[r+2]??0]??0}}return e=>{let t=_n(e);for(let e=0;e<t.length;e+=4){let f=t[e]??0,p=t[e+1]??0,m=t[e+2]??0;if(d?(f=d[0][f]??0,p=d[1][p]??0,m=d[2][m]??0):n&&(n.run(f,p,m,l),f=l[0]*255+.5|0,p=l[1]*255+.5|0,m=l[2]*255+.5|0),u)f=u[0][f]??f,p=u[1][p]??p,m=u[2][m]??m;else if(r){let e,t,n;if(a?.perChannel?(e=(a.perChannel[0][f]??0)/255,t=(a.perChannel[1][p]??0)/255,n=(a.perChannel[2][m]??0)/255):a?(a.run(f,p,m,l),e=l[0]??0,t=l[1]??0,n=l[2]??0):(e=f/255,t=p/255,n=m/255),s){let r=s[0]*e+s[1]*t+s[2]*n;e=r,t=r,n=r}let r=e*255+.5|0,u=t*255+.5|0,d=n*255+.5|0;c&&(r=o[0][r],u=o[1][u],d=o[2][d]),f=f+(r-f)*i+.5|0,p=p+(u-p)*i+.5|0,m=m+(d-m)*i+.5|0}t[e]=f,t[e+1]=p,t[e+2]=m}}}var yn=4e6;function bn(){return new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),e()},t.port2.postMessage(void 0)})}function xn(e,t){return Te(e.output,we(e,t))}async function Sn(e,t,n,r){let{develop:i,filter:a}=t.base,o=gn(i,a),s=Ce(t.base.crop,e),c=we(t,e),l=Te(t.output,c),u=new OffscreenCanvas(l.width,l.height),d=u.getContext(`2d`,{colorSpace:`srgb`,alpha:!n,willReadFrequently:o});if(!d)throw Error(`The worker has no 2D canvas.`);n&&(d.fillStyle=`#ffffff`,d.fillRect(0,0,l.width,l.height));let f=l.width/c.width,p=l.height/c.height;d.imageSmoothingEnabled=f!==1||p!==1,d.imageSmoothingQuality=`high`,d.scale(f,p);let{rotate:m,flipX:h,flipY:g}=t.base.orientation;if(h&&d.transform(-1,0,0,1,c.width,0),g&&d.transform(1,0,0,-1,0,c.height),m===90&&d.transform(0,1,-1,0,c.width,0),m===180&&d.transform(-1,0,0,-1,c.width,c.height),m===270&&d.transform(0,-1,1,0,0,c.height),d.drawImage(e,s.x,s.y,s.width,s.height,0,0,s.width,s.height),d.setTransform(1,0,0,1,0,0),o){let e=vn(i,a),t=Math.max(1,Math.floor(yn/(l.width*4)));for(let n=0;n<l.height;n+=t){if(r&&(await bn(),r.aborted))throw r.reason;let i=d.getImageData(0,n,l.width,Math.min(t,l.height-n),{colorSpace:`srgb`});e(i.data),d.putImageData(i,0,n)}}return u}var Cn={png:`image/png`,jpeg:`image/jpeg`,webp:`image/webp`};async function wn(e,t,n,r){let i=Cn[n.type],a=await Sn(e,t,n.type===`jpeg`,r),o=await a.convertToBlob({type:i,...n.type===`png`?{}:{quality:n.quality??.92}});if(a.width=0,a.height=0,r?.aborted)throw r.reason;if(o.type!==i)throw new T(`UNSUPPORTED_FORMAT`,`This browser can't encode the requested format.`,{details:{format:n.type}});let s=new Uint8Array(await o.arrayBuffer()),c=n.type===`jpeg`?Ut(s,t.metadata):n.type===`png`?Jt(s,t.metadata):Yt(s);return new Blob([c.slice()],{type:i})}async function Tn(e,t,n,r,i){let a=we(n,t),{width:o,height:s}=ue(r),c=Math.min(r.pixelRatio,4),l=de(a,r),u=l.scale*c,d=Math.min(1,u),f=await Sn(t,{...n,output:{kind:`scale`,scale:d}},!1,i);if(i?.aborted)throw f.width=0,i.reason;let{canvas:p}=e;(p.width!==o||p.height!==s)&&(p.width=o,p.height=s),e.clearRect(0,0,o,s),e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`,e.drawImage(f,l.x*c,l.y*c,l.width*c,l.height*c),f.width=0}function En(e,t){return e.format===t.format&&e.orientation===t.orientation&&e.frames===t.frames&&e.decodedPixelBound===t.decodedPixelBound&&e.stored.width===t.stored.width&&e.stored.height===t.stored.height&&e.oriented.width===t.oriented.width&&e.oriented.height===t.oriented.height}function Dn(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;ce({probe:({file:e})=>ft(s(e)),async register({id:e,file:n,probe:r,limits:i},{signal:a}){if(t.has(e))throw TypeError(`The source id "${e}" is already in use.`);let o=await ft(s(n));if(!En(o,r))throw new T(`INVALID_IMAGE`,`The probe doesn't describe this file.`,{details:{format:o.format,problem:`the probe describes another file`}});D(E.resolve(i),n.size,o);let c=await zt(n,o);if(a.aborted)throw c.close(),a.reason;return t.set(e,c),{width:c.width,height:c.height}},thumbnail({id:e,maxSize:n}){let r=t.get(e);if(!r)throw TypeError(`There's no source with the id "${e}".`);let i=Math.min(1,n/r.width,n/r.height);return createImageBitmap(r,{resizeWidth:Math.max(1,Math.round(r.width*i)),resizeHeight:Math.max(1,Math.round(r.height*i)),resizeQuality:`high`})},async export({plan:e,format:n,limits:r},{signal:i}){let a=t.get(e.base.source);if(!a)throw TypeError(`There's no source with the id "${e.base.source}".`);return O(E.resolve(r),xn(e,a)),wn(a,e,n,i)},attachCanvas({id:e,canvas:t}){let r=t.getContext(`2d`,{colorSpace:`srgb`});if(!r)throw Error(`The worker has no 2D canvas.`);n.set(e,r)},async render({id:e,plan:r,view:i,limits:a},{signal:o}){O(E.resolve(a),ue(i));let s=n.get(e);if(!s)throw TypeError(`There's no canvas with the id "${e}".`);let c=t.get(r.base.source);if(!c)throw TypeError(`There's no source with the id "${r.base.source}".`);await Tn(s,c,r,i,o)},detachCanvas({id:e}){let t=n.get(e);t&&(t.canvas.width=0,t.canvas.height=0),n.delete(e)},snapshot({id:e}){let t=n.get(e);if(!t)throw TypeError(`There's no canvas with the id "${e}".`);return createImageBitmap(t.canvas)},release({id:e}){t.get(e)?.close(),t.delete(e)}},{...e,packageVersion:`0.3.0`})}Dn();
|
package/dist/element.d.ts
CHANGED
|
@@ -546,6 +546,7 @@ declare type ImageMessageCatalogue = typeof imageMessages;
|
|
|
546
546
|
* @public
|
|
547
547
|
*/
|
|
548
548
|
declare const imageMessages: {
|
|
549
|
+
readonly "editor.engineUnavailable": "Image processing stopped. Reload this page or reopen the editor, then choose the image again. Unsaved edits will be lost unless your application has saved them.";
|
|
549
550
|
readonly "errors.INVALID_IMAGE": "This file isn't a valid image, or it's too damaged to open.";
|
|
550
551
|
readonly "errors.UNSUPPORTED_FORMAT": "This image format isn't supported. Try converting the file to PNG or JPEG, then open it again.";
|
|
551
552
|
readonly "errors.DECODE_FAILED": "This browser can't open this kind of image. Try another browser, or convert the file to PNG or JPEG.";
|
|
@@ -634,6 +635,28 @@ declare const imageMessages: {
|
|
|
634
635
|
readonly "inspector.label": "Panels";
|
|
635
636
|
readonly "inspector.adjust": "Adjust";
|
|
636
637
|
readonly "inspector.filters": "Filters";
|
|
638
|
+
readonly "inspector.info": "Info";
|
|
639
|
+
readonly "notices.label": "Notices";
|
|
640
|
+
readonly "notices.dismiss": "Dismiss";
|
|
641
|
+
readonly "notices.colourProfile": "This image has a colour profile. Colours outside sRGB will be clipped in the exported file.";
|
|
642
|
+
readonly "info.panel": "Image info";
|
|
643
|
+
readonly "info.size": "Size";
|
|
644
|
+
readonly "info.sizeValue": "{width, number} × {height, number} pixels";
|
|
645
|
+
readonly "info.format": "Format";
|
|
646
|
+
readonly "info.formats.png": "PNG";
|
|
647
|
+
readonly "info.formats.jpeg": "JPEG";
|
|
648
|
+
readonly "info.formats.webp": "WebP";
|
|
649
|
+
readonly "info.formats.gif": "GIF";
|
|
650
|
+
readonly "info.formats.avif": "AVIF";
|
|
651
|
+
readonly "info.formats.heif": "HEIF";
|
|
652
|
+
readonly "info.formats.bmp": "BMP";
|
|
653
|
+
readonly "info.frames": "Frames";
|
|
654
|
+
readonly "info.fileSize": "File size";
|
|
655
|
+
readonly "info.fileSizeValue": "{size, fileSize}";
|
|
656
|
+
readonly "info.metadata": "Metadata in the file";
|
|
657
|
+
readonly "info.metadataNone": "None";
|
|
658
|
+
readonly "info.kept": "Kept on export";
|
|
659
|
+
readonly "info.keptNone": "Nothing";
|
|
637
660
|
readonly "develop.panel": "Adjust";
|
|
638
661
|
readonly "develop.temperature": "Temperature";
|
|
639
662
|
readonly "develop.tint": "Tint";
|
|
@@ -666,6 +689,7 @@ declare const imageMessages: {
|
|
|
666
689
|
readonly "export.formats.jpeg": "JPEG";
|
|
667
690
|
readonly "export.formats.webp": "WebP";
|
|
668
691
|
readonly "export.quality": "Quality";
|
|
692
|
+
readonly "export.qualityValue": "{quality, number}%";
|
|
669
693
|
readonly "export.size": "Size";
|
|
670
694
|
readonly "export.sizes.scale": "Scale";
|
|
671
695
|
readonly "export.sizes.fit": "Fit in a box";
|
|
@@ -924,7 +948,8 @@ declare interface ImageSession {
|
|
|
924
948
|
* ADR 0004). The newest open wins: an open that finishes after a later one
|
|
925
949
|
* started applies nothing, releases its source and rejects with
|
|
926
950
|
* `ABORTED`. A failed or cancelled open leaves the current document as it
|
|
927
|
-
* was.
|
|
951
|
+
* was. Probing and registration share the policy's `maxProcessingTime`
|
|
952
|
+
* deadline, which aborts their signal with `PROCESSING_TIME_EXCEEDED`.
|
|
928
953
|
*/
|
|
929
954
|
open(file: Blob, options?: {
|
|
930
955
|
readonly signal?: AbortSignal;
|
|
@@ -954,7 +979,10 @@ declare interface ImageSession {
|
|
|
954
979
|
redo(): boolean;
|
|
955
980
|
/**
|
|
956
981
|
* Renders and encodes the document (ADR 0003). An export that finishes
|
|
957
|
-
* after another file was opened rejects with `ABORTED`.
|
|
982
|
+
* after another file was opened rejects with `ABORTED`. The policy's
|
|
983
|
+
* `maxProcessingTime` aborts the processor's signal with
|
|
984
|
+
* `PROCESSING_TIME_EXCEEDED`. Custom adapters must observe that signal;
|
|
985
|
+
* a session cannot preempt an arbitrary adapter that ignores it.
|
|
958
986
|
*/
|
|
959
987
|
export(format: ImageExportFormat, options?: {
|
|
960
988
|
readonly signal?: AbortSignal;
|
|
@@ -1017,6 +1045,8 @@ declare interface ImageSessionSnapshot {
|
|
|
1017
1045
|
* @public
|
|
1018
1046
|
*/
|
|
1019
1047
|
declare interface ImageSessionSource extends ImageSourceInfo {
|
|
1048
|
+
/** The file's size in bytes, as it was opened. Never its name. */
|
|
1049
|
+
readonly fileSize: number;
|
|
1020
1050
|
/** Which kinds of metadata the file carried, never their values. */
|
|
1021
1051
|
readonly metadata: ImageMetadataPresence;
|
|
1022
1052
|
/** The fields the user may choose to keep, as the file had them. */
|
package/dist/element.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { tt as ImageError } from "./shared/core-BWNmXDlB.js";
|
|
2
|
+
import { t as ImageEditor, u as ExportListenerContext } from "./shared/editor-CJXEK6MY.js";
|
|
3
3
|
import { useEffect, useRef } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { createEditorElement } from "@hussmartinez/sdk-core/element";
|
package/dist/index.d.ts
CHANGED
|
@@ -99,6 +99,11 @@ export declare function compositionToSource(point: ImagePoint, crop: ImageCrop,
|
|
|
99
99
|
* the probe's oriented size exactly. The worker holds the sources until
|
|
100
100
|
* they're released or the engine is destroyed.
|
|
101
101
|
*
|
|
102
|
+
* Loss of a worker that owns sources or a transferred canvas makes this
|
|
103
|
+
* engine terminal (ADR 0008). Later processing rejects with
|
|
104
|
+
* `WORKER_TERMINATED` and `details.reason: "engine-invalidated"`; explicitly
|
|
105
|
+
* recreate processing resources and reopen the image. No work is replayed.
|
|
106
|
+
*
|
|
102
107
|
* Nothing starts until the first call. By default the worker is inlined,
|
|
103
108
|
* which needs `worker-src blob:` in a Content Security Policy; with
|
|
104
109
|
* `assetsUrl` it loads from your own origin, which needs `worker-src 'self'`
|
|
@@ -511,7 +516,10 @@ export declare interface ImageEngineOptions {
|
|
|
511
516
|
* worker is then `image/render.worker.js` there, and a Content Security
|
|
512
517
|
* Policy needs `worker-src 'self'` and no `blob:` (docs/adr/0002). Copy
|
|
513
518
|
* `dist/assets` again after every upgrade: a worker from another version
|
|
514
|
-
* is refused with `WORKER_START_FAILED`.
|
|
519
|
+
* is refused with `WORKER_START_FAILED`. The base may be absolute or
|
|
520
|
+
* relative to the page, including during server rendering: it is checked
|
|
521
|
+
* at setup and resolved only when the worker starts. By default the
|
|
522
|
+
* worker is inlined.
|
|
515
523
|
*/
|
|
516
524
|
readonly assetsUrl?: string | URL;
|
|
517
525
|
}
|
|
@@ -817,6 +825,7 @@ export declare type ImageMessageCatalogue = typeof imageMessages;
|
|
|
817
825
|
* @public
|
|
818
826
|
*/
|
|
819
827
|
export declare const imageMessages: {
|
|
828
|
+
readonly "editor.engineUnavailable": "Image processing stopped. Reload this page or reopen the editor, then choose the image again. Unsaved edits will be lost unless your application has saved them.";
|
|
820
829
|
readonly "errors.INVALID_IMAGE": "This file isn't a valid image, or it's too damaged to open.";
|
|
821
830
|
readonly "errors.UNSUPPORTED_FORMAT": "This image format isn't supported. Try converting the file to PNG or JPEG, then open it again.";
|
|
822
831
|
readonly "errors.DECODE_FAILED": "This browser can't open this kind of image. Try another browser, or convert the file to PNG or JPEG.";
|
|
@@ -905,6 +914,28 @@ export declare const imageMessages: {
|
|
|
905
914
|
readonly "inspector.label": "Panels";
|
|
906
915
|
readonly "inspector.adjust": "Adjust";
|
|
907
916
|
readonly "inspector.filters": "Filters";
|
|
917
|
+
readonly "inspector.info": "Info";
|
|
918
|
+
readonly "notices.label": "Notices";
|
|
919
|
+
readonly "notices.dismiss": "Dismiss";
|
|
920
|
+
readonly "notices.colourProfile": "This image has a colour profile. Colours outside sRGB will be clipped in the exported file.";
|
|
921
|
+
readonly "info.panel": "Image info";
|
|
922
|
+
readonly "info.size": "Size";
|
|
923
|
+
readonly "info.sizeValue": "{width, number} × {height, number} pixels";
|
|
924
|
+
readonly "info.format": "Format";
|
|
925
|
+
readonly "info.formats.png": "PNG";
|
|
926
|
+
readonly "info.formats.jpeg": "JPEG";
|
|
927
|
+
readonly "info.formats.webp": "WebP";
|
|
928
|
+
readonly "info.formats.gif": "GIF";
|
|
929
|
+
readonly "info.formats.avif": "AVIF";
|
|
930
|
+
readonly "info.formats.heif": "HEIF";
|
|
931
|
+
readonly "info.formats.bmp": "BMP";
|
|
932
|
+
readonly "info.frames": "Frames";
|
|
933
|
+
readonly "info.fileSize": "File size";
|
|
934
|
+
readonly "info.fileSizeValue": "{size, fileSize}";
|
|
935
|
+
readonly "info.metadata": "Metadata in the file";
|
|
936
|
+
readonly "info.metadataNone": "None";
|
|
937
|
+
readonly "info.kept": "Kept on export";
|
|
938
|
+
readonly "info.keptNone": "Nothing";
|
|
908
939
|
readonly "develop.panel": "Adjust";
|
|
909
940
|
readonly "develop.temperature": "Temperature";
|
|
910
941
|
readonly "develop.tint": "Tint";
|
|
@@ -937,6 +968,7 @@ export declare const imageMessages: {
|
|
|
937
968
|
readonly "export.formats.jpeg": "JPEG";
|
|
938
969
|
readonly "export.formats.webp": "WebP";
|
|
939
970
|
readonly "export.quality": "Quality";
|
|
971
|
+
readonly "export.qualityValue": "{quality, number}%";
|
|
940
972
|
readonly "export.size": "Size";
|
|
941
973
|
readonly "export.sizes.scale": "Scale";
|
|
942
974
|
readonly "export.sizes.fit": "Fit in a box";
|
|
@@ -1283,7 +1315,8 @@ export declare interface ImageSession {
|
|
|
1283
1315
|
* ADR 0004). The newest open wins: an open that finishes after a later one
|
|
1284
1316
|
* started applies nothing, releases its source and rejects with
|
|
1285
1317
|
* `ABORTED`. A failed or cancelled open leaves the current document as it
|
|
1286
|
-
* was.
|
|
1318
|
+
* was. Probing and registration share the policy's `maxProcessingTime`
|
|
1319
|
+
* deadline, which aborts their signal with `PROCESSING_TIME_EXCEEDED`.
|
|
1287
1320
|
*/
|
|
1288
1321
|
open(file: Blob, options?: {
|
|
1289
1322
|
readonly signal?: AbortSignal;
|
|
@@ -1313,7 +1346,10 @@ export declare interface ImageSession {
|
|
|
1313
1346
|
redo(): boolean;
|
|
1314
1347
|
/**
|
|
1315
1348
|
* Renders and encodes the document (ADR 0003). An export that finishes
|
|
1316
|
-
* after another file was opened rejects with `ABORTED`.
|
|
1349
|
+
* after another file was opened rejects with `ABORTED`. The policy's
|
|
1350
|
+
* `maxProcessingTime` aborts the processor's signal with
|
|
1351
|
+
* `PROCESSING_TIME_EXCEEDED`. Custom adapters must observe that signal;
|
|
1352
|
+
* a session cannot preempt an arbitrary adapter that ignores it.
|
|
1317
1353
|
*/
|
|
1318
1354
|
export(format: ImageExportFormat, options?: {
|
|
1319
1355
|
readonly signal?: AbortSignal;
|
|
@@ -1404,6 +1440,8 @@ export declare interface ImageSessionSnapshot {
|
|
|
1404
1440
|
* @public
|
|
1405
1441
|
*/
|
|
1406
1442
|
export declare interface ImageSessionSource extends ImageSourceInfo {
|
|
1443
|
+
/** The file's size in bytes, as it was opened. Never its name. */
|
|
1444
|
+
readonly fileSize: number;
|
|
1407
1445
|
/** Which kinds of metadata the file carried, never their values. */
|
|
1408
1446
|
readonly metadata: ImageMetadataPresence;
|
|
1409
1447
|
/** The fields the user may choose to keep, as the file had them. */
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as imageLimitDefinitions, A as onlyFields, B as createPlan, C as checkFilter, D as createImageReducer, E as checkOutput, F as DEVELOP_ADJUSTMENTS, G as placement, H as MAX_PIXEL_RATIO, I as FILTER_PRESETS, K as createImageProcessor, L as FULL_SIZE, M as MAX_METADATA_LENGTH, N as NO_METADATA, O as invalid, Q as checkOutputLimits, R as NEUTRAL_DEVELOP, S as checkDevelop, T as checkOrientation, U as backingSize, V as createImageRenderer, W as fittedView, X as PER_FILE_LIMITS, Y as OUTPUT_LIMITS, Z as checkFileLimits, _ as outputSize, a as compositionDeltaToSource, b as checkCrop, c as fitAspect, d as nudgeCropOnScreen, et as imageLimits, g as orientedSize, h as cropRect, i as aspectRatio, j as EMPTY_KEEPABLE_METADATA, k as isRecord, l as handleInSource, m as compositionToSource, n as createImageSession, nt as isImageError, o as cropInComposition, p as compositionSize, q as createImageEngine, r as ASPECT_PRESETS, s as dragHandle, t as imageMessages, tt as ImageError, u as moveCrop, v as sourceToComposition, w as checkMetadata, x as checkCropInSource, y as Invalid, z as UPRIGHT } from "./shared/core-BWNmXDlB.js";
|
|
2
2
|
// src/core/format/plan-document.ts
|
|
3
3
|
var IMAGE_PLAN_FORMAT = "hm-image-plan";
|
|
4
4
|
var IMAGE_PLAN_VERSION = 1;
|