@sealpixel/core 1.0.0-rc.15 → 1.0.0-rc.19

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/dist/index.d.ts CHANGED
@@ -7,11 +7,12 @@ export { resetExternalKernels, runExternalKernel } from './external-kernel.js';
7
7
  export { canRedo, canUndo, createHistory, current, dispatch, redo, timeTravel, undo, } from './history.js';
8
8
  export { estimateMemoryMB, type ImageSize, readImageSize } from './image-size.js';
9
9
  export { InlineRenderer } from './inline-renderer.js';
10
+ export { editLogHash, MANIFEST_VERSION, parseRenderManifest, type RendererIdentity, type RenderManifest, RenderManifestSchema, renderHash, } from './manifest.js';
10
11
  export { configurePlugins, type PluginOptionsMap, pluginOptionsOf } from './options.js';
11
12
  export { type ChromaSubsampling, type ColorStage, type CoreFormat, type CoreOutputOptions, type CropStage, type Fit, type Geometry, PLAN_VERSION, type PlanRect, type RenderPlan, type ResizeStage, type Size, type SourceInfo, type Stage, type StageGeometry, toRenderPlan, } from './plan.js';
12
13
  export type * from './plugin.js';
13
14
  export { createRegistry, type ParseIssue, type ParseOptions, type ParseResult, type RegisteredOperation, type Registry, } from './registry.js';
14
- export { type PipelineOptions, render, runPipeline, toCoreOutput } from './render.js';
15
+ export { fromCoreOutput, type PipelineOptions, render, runPipeline, toCoreOutput, } from './render.js';
15
16
  export type { Renderer } from './renderer.js';
16
17
  export { type ExportRequest, type ExportResult, type LoadedSource, RendererCore, type RendererCoreOptions, type RendererLoadOptions, type RenderRequest, } from './renderer-core.js';
17
18
  export { browserSaveFile, createEditorSession, type DownloadOptions, type EditorSession, type ExportOptions, type LoadOptions, type LoadSource, type PreviewState, type SessionOptions, type SessionState, } from './session.js';
package/dist/index.js CHANGED
@@ -7,10 +7,11 @@ export { resetExternalKernels, runExternalKernel } from './external-kernel.js';
7
7
  export { canRedo, canUndo, createHistory, current, dispatch, redo, timeTravel, undo, } from './history.js';
8
8
  export { estimateMemoryMB, readImageSize } from './image-size.js';
9
9
  export { InlineRenderer } from './inline-renderer.js';
10
+ export { editLogHash, MANIFEST_VERSION, parseRenderManifest, RenderManifestSchema, renderHash, } from './manifest.js';
10
11
  export { configurePlugins, pluginOptionsOf } from './options.js';
11
12
  export { PLAN_VERSION, toRenderPlan, } from './plan.js';
12
13
  export { createRegistry, } from './registry.js';
13
- export { render, runPipeline, toCoreOutput } from './render.js';
14
+ export { fromCoreOutput, render, runPipeline, toCoreOutput, } from './render.js';
14
15
  export { RendererCore, } from './renderer-core.js';
15
16
  export { browserSaveFile, createEditorSession, } from './session.js';
16
17
  export { transferablesOf, webTransport, } from './worker-protocol.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAsB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EAAE,cAAc,EAA2B,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EACL,OAAO,EACP,OAAO,EACP,aAAa,EACb,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,IAAI,GACL,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAkB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAyB,eAAe,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAQL,YAAY,EAQZ,YAAY,GACb,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,cAAc,GAMf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAwB,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEtF,OAAO,EAIL,YAAY,GAIb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,eAAe,EACf,mBAAmB,GASpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAEL,eAAe,EAGf,YAAY,GACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,wFAAwF;AACxF,MAAM,UAAU,aAAa,CAC3B,MAAwB,EACxB,QAA2C;IAE3C,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;AACpF,CAAC","sourcesContent":["export {\n type AssetResolver,\n type AssetResolverOptions,\n createAssetResolver,\n missingAssetId,\n staticAssetResolver,\n wasmSha256,\n webCryptoSha256,\n withAssets,\n} from './assets.js';\nexport { canonicalJson } from './canonical-json.js';\nexport { compile, type PipelineStage, toCoreStages, toPipeline } from './compile.js';\nexport { PNG_KEYWORD, readEmbeddedEditLog, readEmbeddedState } from './embedded.js';\nexport { SealpixelError, type SealpixelErrorCode } from './errors.js';\nexport { resetExternalKernels, runExternalKernel } from './external-kernel.js';\nexport {\n canRedo,\n canUndo,\n createHistory,\n current,\n dispatch,\n redo,\n timeTravel,\n undo,\n} from './history.js';\nexport { estimateMemoryMB, type ImageSize, readImageSize } from './image-size.js';\nexport { InlineRenderer } from './inline-renderer.js';\nexport { configurePlugins, type PluginOptionsMap, pluginOptionsOf } from './options.js';\nexport {\n type ChromaSubsampling,\n type ColorStage,\n type CoreFormat,\n type CoreOutputOptions,\n type CropStage,\n type Fit,\n type Geometry,\n PLAN_VERSION,\n type PlanRect,\n type RenderPlan,\n type ResizeStage,\n type Size,\n type SourceInfo,\n type Stage,\n type StageGeometry,\n toRenderPlan,\n} from './plan.js';\nexport type * from './plugin.js';\nexport {\n createRegistry,\n type ParseIssue,\n type ParseOptions,\n type ParseResult,\n type RegisteredOperation,\n type Registry,\n} from './registry.js';\nexport { type PipelineOptions, render, runPipeline, toCoreOutput } from './render.js';\nexport type { Renderer } from './renderer.js';\nexport {\n type ExportRequest,\n type ExportResult,\n type LoadedSource,\n RendererCore,\n type RendererCoreOptions,\n type RendererLoadOptions,\n type RenderRequest,\n} from './renderer-core.js';\nexport {\n browserSaveFile,\n createEditorSession,\n type DownloadOptions,\n type EditorSession,\n type ExportOptions,\n type LoadOptions,\n type LoadSource,\n type PreviewState,\n type SessionOptions,\n type SessionState,\n} from './session.js';\nexport type * from './types.js';\nexport {\n type Transport,\n transferablesOf,\n type WorkerRequest,\n type WorkerResponse,\n webTransport,\n} from './worker-protocol.js';\nexport { WorkerRenderer } from './worker-renderer.js';\n\nimport type { EditLog, SourceDescriptor } from './types.js';\n\n/** Creates an empty edit log for `source`, recording the registered plugin versions. */\nexport function createEditLog(\n source: SourceDescriptor,\n registry?: import('./registry.js').Registry,\n): EditLog {\n return { version: 1, source, plugins: registry?.pluginVersions() ?? {}, ops: [] };\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAsB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EAAE,cAAc,EAA2B,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EACL,OAAO,EACP,OAAO,EACP,aAAa,EACb,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,IAAI,GACL,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAkB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EAGnB,oBAAoB,EACpB,UAAU,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAyB,eAAe,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAQL,YAAY,EAQZ,YAAY,GACb,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,cAAc,GAMf,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,cAAc,EAEd,MAAM,EACN,WAAW,EACX,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAIL,YAAY,GAIb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,eAAe,EACf,mBAAmB,GASpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAEL,eAAe,EAGf,YAAY,GACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,wFAAwF;AACxF,MAAM,UAAU,aAAa,CAC3B,MAAwB,EACxB,QAA2C;IAE3C,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;AACpF,CAAC","sourcesContent":["export {\n type AssetResolver,\n type AssetResolverOptions,\n createAssetResolver,\n missingAssetId,\n staticAssetResolver,\n wasmSha256,\n webCryptoSha256,\n withAssets,\n} from './assets.js';\nexport { canonicalJson } from './canonical-json.js';\nexport { compile, type PipelineStage, toCoreStages, toPipeline } from './compile.js';\nexport { PNG_KEYWORD, readEmbeddedEditLog, readEmbeddedState } from './embedded.js';\nexport { SealpixelError, type SealpixelErrorCode } from './errors.js';\nexport { resetExternalKernels, runExternalKernel } from './external-kernel.js';\nexport {\n canRedo,\n canUndo,\n createHistory,\n current,\n dispatch,\n redo,\n timeTravel,\n undo,\n} from './history.js';\nexport { estimateMemoryMB, type ImageSize, readImageSize } from './image-size.js';\nexport { InlineRenderer } from './inline-renderer.js';\nexport {\n editLogHash,\n MANIFEST_VERSION,\n parseRenderManifest,\n type RendererIdentity,\n type RenderManifest,\n RenderManifestSchema,\n renderHash,\n} from './manifest.js';\nexport { configurePlugins, type PluginOptionsMap, pluginOptionsOf } from './options.js';\nexport {\n type ChromaSubsampling,\n type ColorStage,\n type CoreFormat,\n type CoreOutputOptions,\n type CropStage,\n type Fit,\n type Geometry,\n PLAN_VERSION,\n type PlanRect,\n type RenderPlan,\n type ResizeStage,\n type Size,\n type SourceInfo,\n type Stage,\n type StageGeometry,\n toRenderPlan,\n} from './plan.js';\nexport type * from './plugin.js';\nexport {\n createRegistry,\n type ParseIssue,\n type ParseOptions,\n type ParseResult,\n type RegisteredOperation,\n type Registry,\n} from './registry.js';\nexport {\n fromCoreOutput,\n type PipelineOptions,\n render,\n runPipeline,\n toCoreOutput,\n} from './render.js';\nexport type { Renderer } from './renderer.js';\nexport {\n type ExportRequest,\n type ExportResult,\n type LoadedSource,\n RendererCore,\n type RendererCoreOptions,\n type RendererLoadOptions,\n type RenderRequest,\n} from './renderer-core.js';\nexport {\n browserSaveFile,\n createEditorSession,\n type DownloadOptions,\n type EditorSession,\n type ExportOptions,\n type LoadOptions,\n type LoadSource,\n type PreviewState,\n type SessionOptions,\n type SessionState,\n} from './session.js';\nexport type * from './types.js';\nexport {\n type Transport,\n transferablesOf,\n type WorkerRequest,\n type WorkerResponse,\n webTransport,\n} from './worker-protocol.js';\nexport { WorkerRenderer } from './worker-renderer.js';\n\nimport type { EditLog, SourceDescriptor } from './types.js';\n\n/** Creates an empty edit log for `source`, recording the registered plugin versions. */\nexport function createEditLog(\n source: SourceDescriptor,\n registry?: import('./registry.js').Registry,\n): EditLog {\n return { version: 1, source, plugins: registry?.pluginVersions() ?? {}, ops: [] };\n}\n"]}
@@ -0,0 +1,127 @@
1
+ import { z } from 'zod';
2
+ import type { RenderPlan } from './plan.js';
3
+ import type { EditLog } from './types.js';
4
+ /**
5
+ * The render manifest: what a render was made from and the hash of what it
6
+ * produced, so that anyone with the original can check the result later.
7
+ *
8
+ * Version 1. `render({ manifest: true })` writes it, `verify()` in
9
+ * `@sealpixel/render` and `sealpixel verify` in the native CLI read it. The
10
+ * fields are public API: a field is added with a default, never renamed or
11
+ * removed, and an incompatible change bumps `version`. The native CLI's
12
+ * `sealpixel_core::manifest` is the same format.
13
+ */
14
+ export declare const MANIFEST_VERSION = 1;
15
+ /** Which build produced the pixels. `kind` is `wasm` here, `native` for the CLI. */
16
+ export interface RendererIdentity {
17
+ kind: 'wasm' | 'native';
18
+ version: string;
19
+ /** sha256 of the WebAssembly binary or the native executable, when the loader saw its bytes. */
20
+ binarySha256: string | null;
21
+ }
22
+ export interface RenderManifest {
23
+ version: 1;
24
+ source: {
25
+ /** The size after EXIF orientation, as the edit log states it. */
26
+ width: number;
27
+ height: number;
28
+ /** sha256 of the original's bytes. */
29
+ hash: string;
30
+ mimeType?: string;
31
+ };
32
+ /** `{ log, index }` as the editor keeps it. Absent in a manifest the native CLI wrote. */
33
+ editLog?: {
34
+ log: EditLog;
35
+ index: number;
36
+ };
37
+ /** sha256 of `editLog` in canonical JSON: the text `embedEditLog` stores in a file. */
38
+ editLogHash?: string;
39
+ /** The core plan, when every stage of the render ran in the core. */
40
+ plan?: RenderPlan;
41
+ /** The stages that ran outside the core, when any did: then there is no `plan`. */
42
+ kernels?: string[];
43
+ /** The plugin versions the log was compiled with. */
44
+ plugins: Record<string, number>;
45
+ renderer: RendererIdentity;
46
+ output: {
47
+ /** The encoder options in the core's form: `{ "format": "png", ... }`, never with `embed`. */
48
+ options: Record<string, unknown>;
49
+ /** The file holds the edit log, as `embedEditLog: true` stores it. */
50
+ embedEditLog?: boolean;
51
+ width: number;
52
+ height: number;
53
+ /** sha256 over the rendered pixels, before encoding. Survives any change to the file. */
54
+ pixelHash: string;
55
+ /** sha256 of the encoded bytes as the renderer wrote them. */
56
+ byteHash: string;
57
+ };
58
+ /** One id for this render. See `renderHash()`. */
59
+ renderHash: string;
60
+ }
61
+ /**
62
+ * The manifest as untrusted input: the shape, the hashes and the numbers. The
63
+ * edit log inside it is only an object here; `verify()` parses it with the
64
+ * registry, and the core checks the plan when it renders.
65
+ */
66
+ export declare const RenderManifestSchema: z.ZodObject<{
67
+ version: z.ZodLiteral<1>;
68
+ source: z.ZodObject<{
69
+ width: z.ZodNumber;
70
+ height: z.ZodNumber;
71
+ hash: z.ZodString;
72
+ mimeType: z.ZodOptional<z.ZodString>;
73
+ }, z.core.$strip>;
74
+ editLog: z.ZodOptional<z.ZodObject<{
75
+ log: z.ZodRecord<z.ZodString, z.ZodUnknown>;
76
+ index: z.ZodNumber;
77
+ }, z.core.$strip>>;
78
+ editLogHash: z.ZodOptional<z.ZodString>;
79
+ plan: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
80
+ kernels: z.ZodOptional<z.ZodArray<z.ZodString>>;
81
+ plugins: z.ZodRecord<z.ZodString, z.ZodNumber>;
82
+ renderer: z.ZodObject<{
83
+ kind: z.ZodEnum<{
84
+ wasm: "wasm";
85
+ native: "native";
86
+ }>;
87
+ version: z.ZodString;
88
+ binarySha256: z.ZodNullable<z.ZodString>;
89
+ }, z.core.$strip>;
90
+ output: z.ZodObject<{
91
+ options: z.ZodRecord<z.ZodString, z.ZodUnknown>;
92
+ embedEditLog: z.ZodOptional<z.ZodBoolean>;
93
+ width: z.ZodNumber;
94
+ height: z.ZodNumber;
95
+ pixelHash: z.ZodString;
96
+ byteHash: z.ZodString;
97
+ }, z.core.$strip>;
98
+ renderHash: z.ZodString;
99
+ }, z.core.$strip>;
100
+ /** Parses an untrusted manifest. Throws `INVALID_REQUEST` with the first problem. */
101
+ export declare function parseRenderManifest(input: unknown): RenderManifest;
102
+ /**
103
+ * The id of a render: a sha256 over the facts the manifest states, in a
104
+ * fixed text form that every runtime builds with string operations alone,
105
+ * so no canonical-JSON rules are needed to agree on it. `verify` does not
106
+ * recompute it; it checks the facts.
107
+ *
108
+ * ```text
109
+ * sealpixel-render/1
110
+ * <source hash>
111
+ * <edit log hash, or the plan hash for a manifest without a log>
112
+ * <plugins as id@version, sorted by id, joined by ','>
113
+ * <renderer kind> <renderer version> <binary sha256 or '-'>
114
+ * <pixel hash>
115
+ * <byte hash>
116
+ * ```
117
+ */
118
+ export declare function renderHash(sha256Hex: (bytes: Uint8Array) => string, facts: {
119
+ sourceHash: string;
120
+ editsHash: string;
121
+ plugins: Record<string, number>;
122
+ renderer: RendererIdentity;
123
+ pixelHash: string;
124
+ byteHash: string;
125
+ }): string;
126
+ /** The hash `editLogHash` and the embedded log share: canonical JSON of `{ log, index }`. */
127
+ export declare function editLogHash(sha256Hex: (bytes: Uint8Array) => string, log: EditLog, index: number): string;
@@ -0,0 +1,115 @@
1
+ import { z } from 'zod';
2
+ import { canonicalJson } from './canonical-json.js';
3
+ import { SealpixelError } from './errors.js';
4
+ /**
5
+ * The render manifest: what a render was made from and the hash of what it
6
+ * produced, so that anyone with the original can check the result later.
7
+ *
8
+ * Version 1. `render({ manifest: true })` writes it, `verify()` in
9
+ * `@sealpixel/render` and `sealpixel verify` in the native CLI read it. The
10
+ * fields are public API: a field is added with a default, never renamed or
11
+ * removed, and an incompatible change bumps `version`. The native CLI's
12
+ * `sealpixel_core::manifest` is the same format.
13
+ */
14
+ export const MANIFEST_VERSION = 1;
15
+ const sha256 = z.string().regex(/^[0-9a-f]{64}$/);
16
+ /**
17
+ * The manifest as untrusted input: the shape, the hashes and the numbers. The
18
+ * edit log inside it is only an object here; `verify()` parses it with the
19
+ * registry, and the core checks the plan when it renders.
20
+ */
21
+ export const RenderManifestSchema = z.object({
22
+ version: z.literal(1),
23
+ source: z.object({
24
+ width: z.number().int().positive(),
25
+ height: z.number().int().positive(),
26
+ hash: sha256,
27
+ mimeType: z.string().optional(),
28
+ }),
29
+ editLog: z
30
+ .object({
31
+ log: z.record(z.string(), z.unknown()),
32
+ index: z.number().int().nonnegative(),
33
+ })
34
+ .optional(),
35
+ editLogHash: sha256.optional(),
36
+ plan: z.record(z.string(), z.unknown()).optional(),
37
+ kernels: z.array(z.string()).optional(),
38
+ plugins: z.record(z.string(), z.number().int()),
39
+ renderer: z.object({
40
+ kind: z.enum(['wasm', 'native']),
41
+ version: z.string(),
42
+ binarySha256: sha256.nullable(),
43
+ }),
44
+ output: z.object({
45
+ options: z.record(z.string(), z.unknown()),
46
+ embedEditLog: z.boolean().optional(),
47
+ width: z.number().int().positive(),
48
+ height: z.number().int().positive(),
49
+ pixelHash: sha256,
50
+ byteHash: sha256,
51
+ }),
52
+ renderHash: sha256,
53
+ });
54
+ /** Parses an untrusted manifest. Throws `INVALID_REQUEST` with the first problem. */
55
+ export function parseRenderManifest(input) {
56
+ const result = RenderManifestSchema.safeParse(input);
57
+ if (!result.success) {
58
+ const issue = result.error.issues[0];
59
+ throw new SealpixelError('INVALID_REQUEST', `manifest: ${issue ? `${issue.path.join('.') || '(root)'}: ${issue.message}` : 'invalid'}`);
60
+ }
61
+ return result.data;
62
+ }
63
+ /**
64
+ * The id of a render: a sha256 over the facts the manifest states, in a
65
+ * fixed text form that every runtime builds with string operations alone,
66
+ * so no canonical-JSON rules are needed to agree on it. `verify` does not
67
+ * recompute it; it checks the facts.
68
+ *
69
+ * ```text
70
+ * sealpixel-render/1
71
+ * <source hash>
72
+ * <edit log hash, or the plan hash for a manifest without a log>
73
+ * <plugins as id@version, sorted by id, joined by ','>
74
+ * <renderer kind> <renderer version> <binary sha256 or '-'>
75
+ * <pixel hash>
76
+ * <byte hash>
77
+ * ```
78
+ */
79
+ export function renderHash(sha256Hex, facts) {
80
+ const plugins = Object.keys(facts.plugins)
81
+ .sort(byCodePoint)
82
+ .map((id) => `${id}@${facts.plugins[id]}`)
83
+ .join(',');
84
+ const renderer = `${facts.renderer.kind} ${facts.renderer.version} ${facts.renderer.binarySha256 ?? '-'}`;
85
+ const text = [
86
+ `sealpixel-render/${MANIFEST_VERSION}`,
87
+ facts.sourceHash,
88
+ facts.editsHash,
89
+ plugins,
90
+ renderer,
91
+ facts.pixelHash,
92
+ facts.byteHash,
93
+ ].join('\n');
94
+ return sha256Hex(new TextEncoder().encode(text));
95
+ }
96
+ /**
97
+ * Code point order, which is the byte order of UTF-8 and the order a Rust
98
+ * `BTreeMap<String, _>` iterates in. JavaScript's default sort compares
99
+ * UTF-16 code units, which differs for characters outside the basic plane.
100
+ */
101
+ function byCodePoint(a, b) {
102
+ const x = Array.from(a, (c) => c.codePointAt(0) ?? 0);
103
+ const y = Array.from(b, (c) => c.codePointAt(0) ?? 0);
104
+ for (let i = 0; i < Math.min(x.length, y.length); i++) {
105
+ const d = (x[i] ?? 0) - (y[i] ?? 0);
106
+ if (d !== 0)
107
+ return d;
108
+ }
109
+ return x.length - y.length;
110
+ }
111
+ /** The hash `editLogHash` and the embedded log share: canonical JSON of `{ log, index }`. */
112
+ export function editLogHash(sha256Hex, log, index) {
113
+ return sha256Hex(new TextEncoder().encode(canonicalJson({ log, index })));
114
+ }
115
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,G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,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;AAC7B,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,WAAW,CACzB,SAAwC,EACxC,GAAY,EACZ,KAAa;IAEb,OAAO,SAAS,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import { z } from 'zod';\nimport { canonicalJson } from './canonical-json.js';\nimport { SealpixelError } from './errors.js';\nimport type { RenderPlan } from './plan.js';\nimport type { EditLog } from './types.js';\n\n/**\n * The render manifest: what a render was made from and the hash of what it\n * produced, so that anyone with the original can check the result later.\n *\n * Version 1. `render({ manifest: true })` writes it, `verify()` in\n * `@sealpixel/render` and `sealpixel verify` in the native CLI read it. The\n * fields are public API: a field is added with a default, never renamed or\n * removed, and an incompatible change bumps `version`. The native CLI's\n * `sealpixel_core::manifest` is the same format.\n */\nexport const MANIFEST_VERSION = 1;\n\n/** Which build produced the pixels. `kind` is `wasm` here, `native` for the CLI. */\nexport interface RendererIdentity {\n kind: 'wasm' | 'native';\n version: string;\n /** sha256 of the WebAssembly binary or the native executable, when the loader saw its bytes. */\n binarySha256: string | null;\n}\n\nexport interface RenderManifest {\n version: 1;\n source: {\n /** The size after EXIF orientation, as the edit log states it. */\n width: number;\n height: number;\n /** sha256 of the original's bytes. */\n hash: string;\n mimeType?: string;\n };\n /** `{ log, index }` as the editor keeps it. Absent in a manifest the native CLI wrote. */\n editLog?: { log: EditLog; index: number };\n /** sha256 of `editLog` in canonical JSON: the text `embedEditLog` stores in a file. */\n editLogHash?: string;\n /** The core plan, when every stage of the render ran in the core. */\n plan?: RenderPlan;\n /** The stages that ran outside the core, when any did: then there is no `plan`. */\n kernels?: string[];\n /** The plugin versions the log was compiled with. */\n plugins: Record<string, number>;\n renderer: RendererIdentity;\n output: {\n /** The encoder options in the core's form: `{ \"format\": \"png\", ... }`, never with `embed`. */\n options: Record<string, unknown>;\n /** The file holds the edit log, as `embedEditLog: true` stores it. */\n embedEditLog?: boolean;\n width: number;\n height: number;\n /** sha256 over the rendered pixels, before encoding. Survives any change to the file. */\n pixelHash: string;\n /** sha256 of the encoded bytes as the renderer wrote them. */\n byteHash: string;\n };\n /** One id for this render. See `renderHash()`. */\n renderHash: string;\n}\n\nconst sha256 = z.string().regex(/^[0-9a-f]{64}$/);\n\n/**\n * The manifest as untrusted input: the shape, the hashes and the numbers. The\n * edit log inside it is only an object here; `verify()` parses it with the\n * registry, and the core checks the plan when it renders.\n */\nexport const RenderManifestSchema = z.object({\n version: z.literal(1),\n source: z.object({\n width: z.number().int().positive(),\n height: z.number().int().positive(),\n hash: sha256,\n mimeType: z.string().optional(),\n }),\n editLog: z\n .object({\n log: z.record(z.string(), z.unknown()),\n index: z.number().int().nonnegative(),\n })\n .optional(),\n editLogHash: sha256.optional(),\n plan: z.record(z.string(), z.unknown()).optional(),\n kernels: z.array(z.string()).optional(),\n plugins: z.record(z.string(), z.number().int()),\n renderer: z.object({\n kind: z.enum(['wasm', 'native']),\n version: z.string(),\n binarySha256: sha256.nullable(),\n }),\n output: z.object({\n options: z.record(z.string(), z.unknown()),\n embedEditLog: z.boolean().optional(),\n width: z.number().int().positive(),\n height: z.number().int().positive(),\n pixelHash: sha256,\n byteHash: sha256,\n }),\n renderHash: sha256,\n});\n\n/** Parses an untrusted manifest. Throws `INVALID_REQUEST` with the first problem. */\nexport function parseRenderManifest(input: unknown): RenderManifest {\n const result = RenderManifestSchema.safeParse(input);\n if (!result.success) {\n const issue = result.error.issues[0];\n throw new SealpixelError(\n 'INVALID_REQUEST',\n `manifest: ${issue ? `${issue.path.join('.') || '(root)'}: ${issue.message}` : 'invalid'}`,\n );\n }\n return result.data as unknown as RenderManifest;\n}\n\n/**\n * The id of a render: a sha256 over the facts the manifest states, in a\n * fixed text form that every runtime builds with string operations alone,\n * so no canonical-JSON rules are needed to agree on it. `verify` does not\n * recompute it; it checks the facts.\n *\n * ```text\n * sealpixel-render/1\n * <source hash>\n * <edit log hash, or the plan hash for a manifest without a log>\n * <plugins as id@version, sorted by id, joined by ','>\n * <renderer kind> <renderer version> <binary sha256 or '-'>\n * <pixel hash>\n * <byte hash>\n * ```\n */\nexport function renderHash(\n sha256Hex: (bytes: Uint8Array) => string,\n facts: {\n sourceHash: string;\n editsHash: string;\n plugins: Record<string, number>;\n renderer: RendererIdentity;\n pixelHash: string;\n byteHash: string;\n },\n): string {\n const plugins = Object.keys(facts.plugins)\n .sort(byCodePoint)\n .map((id) => `${id}@${facts.plugins[id]}`)\n .join(',');\n const renderer = `${facts.renderer.kind} ${facts.renderer.version} ${facts.renderer.binarySha256 ?? '-'}`;\n const text = [\n `sealpixel-render/${MANIFEST_VERSION}`,\n facts.sourceHash,\n facts.editsHash,\n plugins,\n renderer,\n facts.pixelHash,\n facts.byteHash,\n ].join('\\n');\n return sha256Hex(new TextEncoder().encode(text));\n}\n\n/**\n * Code point order, which is the byte order of UTF-8 and the order a Rust\n * `BTreeMap<String, _>` iterates in. JavaScript's default sort compares\n * UTF-16 code units, which differs for characters outside the basic plane.\n */\nfunction byCodePoint(a: string, b: string): number {\n const x = Array.from(a, (c) => c.codePointAt(0) ?? 0);\n const y = Array.from(b, (c) => c.codePointAt(0) ?? 0);\n for (let i = 0; i < Math.min(x.length, y.length); i++) {\n const d = (x[i] ?? 0) - (y[i] ?? 0);\n if (d !== 0) return d;\n }\n return x.length - y.length;\n}\n\n/** The hash `editLogHash` and the embedded log share: canonical JSON of `{ log, index }`. */\nexport function editLogHash(\n sha256Hex: (bytes: Uint8Array) => string,\n log: EditLog,\n index: number,\n): string {\n return sha256Hex(new TextEncoder().encode(canonicalJson({ log, index })));\n}\n"]}
package/dist/render.d.ts CHANGED
@@ -22,3 +22,8 @@ export interface PipelineOptions {
22
22
  export declare function runPipeline(wasm: SealpixelWasm, registry: Registry, image: RgbaBuffer, log: EditLog, options: PipelineOptions): Promise<RgbaBuffer>;
23
23
  /** Maps the public output options onto the Rust `OutputOptions` JSON. */
24
24
  export declare function toCoreOutput(output: OutputOptions): Record<string, unknown>;
25
+ /**
26
+ * The inverse of `toCoreOutput`, for the options a render manifest records.
27
+ * `embed` is not an option here: `embedEditLog` regenerates it from the log.
28
+ */
29
+ export declare function fromCoreOutput(core: Record<string, unknown>): OutputOptions;
package/dist/render.js CHANGED
@@ -1,9 +1,10 @@
1
- import { loadSealpixelWasm } from '@sealpixel/wasm';
1
+ import { loadSealpixelWasm, } from '@sealpixel/wasm';
2
2
  import { withAssets } from './assets.js';
3
3
  import { canonicalJson } from './canonical-json.js';
4
4
  import { compile, toCoreStages, toPipeline } from './compile.js';
5
5
  import { SealpixelError } from './errors.js';
6
6
  import { runExternalKernel } from './external-kernel.js';
7
+ import { editLogHash, MANIFEST_VERSION, renderHash } from './manifest.js';
7
8
  import { PLAN_VERSION } from './plan.js';
8
9
  import { createRegistry } from './registry.js';
9
10
  const FORMAT_TO_CORE = {
@@ -24,10 +25,24 @@ export async function render(source, log, options) {
24
25
  const wasm = options.wasm ?? (await loadSealpixelWasm());
25
26
  const registry = options.registry ?? EMPTY_REGISTRY;
26
27
  throwIfAborted(options.signal);
28
+ const mode = options.mode ?? 'truth';
29
+ // What a manifest needs is checked before the hash and the decode, the
30
+ // expensive steps. A buffer source names its hash explicitly: the log's
31
+ // `source.hash` is a claim about bytes this call never saw.
32
+ if (options.manifest && mode !== 'truth') {
33
+ throw new SealpixelError('INVALID_REQUEST', 'a manifest describes a truth render; a preview cannot be verified');
34
+ }
35
+ const sourceHash = !options.manifest
36
+ ? undefined
37
+ : source instanceof Uint8Array
38
+ ? wasm.sha256Hex(source)
39
+ : options.sourceHash;
40
+ if (options.manifest && sourceHash === undefined) {
41
+ throw new SealpixelError('INVALID_REQUEST', 'a manifest needs the hash of the original: pass the bytes as source, or sourceHash with a buffer');
42
+ }
27
43
  const t0 = now();
28
44
  const image = source instanceof Uint8Array ? tryCore(() => wasm.decode(source)) : source;
29
45
  const decodeMs = now() - t0;
30
- const mode = options.mode ?? 'truth';
31
46
  if (mode === 'truth' &&
32
47
  (image.width !== log.source.width || image.height !== log.source.height)) {
33
48
  throw new SealpixelError('SOURCE_MISMATCH', `truth render expects ${log.source.width}x${log.source.height}, got ${image.width}x${image.height}`);
@@ -37,9 +52,10 @@ export async function render(source, log, options) {
37
52
  }
38
53
  throwIfAborted(options.signal);
39
54
  const t1 = now();
40
- const rendered = await withAssets(() => runPipeline(wasm, registry, image, log, {
55
+ const { stages, logical } = compileStages(registry, image, log, mode, options.upTo);
56
+ const rendered = await withAssets(() => executeStages(wasm, stages, image, logical, {
41
57
  mode,
42
- ...(options.upTo === undefined ? {} : { upTo: options.upTo }),
58
+ ...(options.manifest ? { pixelHash: true } : {}),
43
59
  ...(options.signal === undefined ? {} : { signal: options.signal }),
44
60
  }), options.assets, (id, bytes) => wasm.assetPut(id, bytes));
45
61
  const renderMs = now() - t1;
@@ -49,9 +65,13 @@ export async function render(source, log, options) {
49
65
  if (options.embedEditLog) {
50
66
  coreOutput['embed'] = canonicalJson({ log, index: options.upTo ?? log.ops.length });
51
67
  }
52
- const bytes = tryCore(() => wasm.encode(rendered, JSON.stringify(coreOutput)));
68
+ // A decoded source carries its ICC profile; pixels given by the caller carry
69
+ // what the caller attached, if anything. No `instanceof`: a typed array from
70
+ // another realm is still a profile.
71
+ const icc = image.icc;
72
+ const bytes = tryCore(() => wasm.encode(rendered, JSON.stringify(coreOutput), icc));
53
73
  const encodeMs = now() - t2;
54
- return {
74
+ const result = {
55
75
  bytes,
56
76
  mimeType: options.output.format,
57
77
  width: rendered.width,
@@ -60,24 +80,96 @@ export async function render(source, log, options) {
60
80
  coreVersion: wasm.version(),
61
81
  timings: { decode: decodeMs, render: renderMs, encode: encodeMs },
62
82
  };
83
+ if (options.manifest && sourceHash !== undefined) {
84
+ const t3 = now();
85
+ result.manifest = buildManifest(wasm, registry, stages, logical, log, options, {
86
+ sourceHash,
87
+ rendered,
88
+ bytes: result.hash,
89
+ output: toCoreOutput(options.output),
90
+ mimeType: image.mimeType,
91
+ });
92
+ result.timings['manifest'] = now() - t3;
93
+ }
94
+ return result;
95
+ }
96
+ /**
97
+ * The manifest of a finished render, from the stages that rendered. The plan
98
+ * is the single core plan of a render whose stages all ran in the core; a
99
+ * pipeline with a plugin kernel outside the core lists the kernels instead,
100
+ * and only a JavaScript runtime can verify it. `output.options` never
101
+ * carries `embed`: the log is in `editLog`, and `embedEditLog` says whether
102
+ * the file holds it too.
103
+ */
104
+ function buildManifest(wasm, registry, stages, logical, log, options, result) {
105
+ const index = options.upTo ?? log.ops.length;
106
+ const kernels = stages.filter((s) => s.kind !== 'core').map((s) => s.name);
107
+ const plan = kernels.length === 0
108
+ ? { version: PLAN_VERSION, source: logical, bufferScale: 1, stages: toCoreStages(stages) }
109
+ : undefined;
110
+ const plugins = registry.pluginVersions();
111
+ const renderer = wasm.identity();
112
+ // From the core when the last stage ran there; a kernel outside the core
113
+ // leaves its buffer in JavaScript, which is then hashed from there.
114
+ const pixelHash = result.rendered.pixelHash ?? wasm.pixelHash(result.rendered);
115
+ const logHash = editLogHash(wasm.sha256Hex, log, index);
116
+ return {
117
+ version: MANIFEST_VERSION,
118
+ source: {
119
+ width: log.source.width,
120
+ height: log.source.height,
121
+ hash: result.sourceHash,
122
+ ...(result.mimeType === undefined ? {} : { mimeType: result.mimeType }),
123
+ },
124
+ editLog: { log, index },
125
+ editLogHash: logHash,
126
+ ...(plan ? { plan } : { kernels }),
127
+ plugins,
128
+ renderer,
129
+ output: {
130
+ options: result.output,
131
+ ...(options.embedEditLog ? { embedEditLog: true } : {}),
132
+ width: result.rendered.width,
133
+ height: result.rendered.height,
134
+ pixelHash,
135
+ byteHash: result.bytes,
136
+ },
137
+ renderHash: renderHash(wasm.sha256Hex, {
138
+ sourceHash: result.sourceHash,
139
+ editsHash: logHash,
140
+ plugins,
141
+ renderer,
142
+ pixelHash,
143
+ byteHash: result.bytes,
144
+ }),
145
+ };
63
146
  }
64
147
  /**
65
148
  * Compiles the log and executes it: consecutive core stages become one wasm
66
149
  * call, every external kernel runs in between on the RGBA buffer.
67
150
  */
68
151
  export async function runPipeline(wasm, registry, image, log, options) {
69
- const doc = compile(log, registry, options.upTo);
152
+ const { stages, logical } = compileStages(registry, image, log, options.mode, options.upTo);
153
+ return executeStages(wasm, stages, image, logical, options);
154
+ }
155
+ /** Compiles `ops[0..upTo)` into the ordered stages for a buffer of `image`'s size. */
156
+ function compileStages(registry, image, log, mode, upTo) {
157
+ const doc = compile(log, registry, upTo);
70
158
  const logical = { width: log.source.width, height: log.source.height };
71
159
  const ctx = {
72
160
  logical,
73
161
  actual: { width: image.width, height: image.height },
74
162
  scale: image.width / log.source.width,
75
- mode: options.mode,
163
+ mode,
76
164
  };
77
- const stages = toPipeline(doc, registry, ctx);
165
+ return { stages: toPipeline(doc, registry, ctx), logical };
166
+ }
167
+ /** Runs the stages: consecutive core stages as one wasm call, every external kernel in between. */
168
+ async function executeStages(wasm, stages, image, logical, options) {
78
169
  let current = image;
79
170
  let currentLogical = logical;
80
- for (const segment of segments(stages)) {
171
+ const all = [...segments(stages)];
172
+ for (const [i, segment] of all.entries()) {
81
173
  throwIfAborted(options.signal);
82
174
  if (segment.kind === 'core') {
83
175
  const plan = {
@@ -88,7 +180,8 @@ export async function runPipeline(wasm, registry, image, log, options) {
88
180
  };
89
181
  const planJson = JSON.stringify(plan);
90
182
  const geometry = JSON.parse(tryCore(() => wasm.resolveGeometry(planJson, current.width, current.height)));
91
- current = tryCore(() => wasm.renderRgba(current, planJson));
183
+ const last = i === all.length - 1;
184
+ current = tryCore(() => wasm.renderRgba(current, planJson, options.pixelHash && last ? { pixelHash: true } : {}));
92
185
  currentLogical = geometry.logicalOut;
93
186
  }
94
187
  else {
@@ -146,6 +239,28 @@ export function toCoreOutput(output) {
146
239
  core['background'] = output.background;
147
240
  return core;
148
241
  }
242
+ /**
243
+ * The inverse of `toCoreOutput`, for the options a render manifest records.
244
+ * `embed` is not an option here: `embedEditLog` regenerates it from the log.
245
+ */
246
+ export function fromCoreOutput(core) {
247
+ const format = Object.keys(FORMAT_TO_CORE).find((f) => FORMAT_TO_CORE[f] === core['format']);
248
+ if (format === undefined) {
249
+ throw new SealpixelError('INVALID_REQUEST', `unknown output format ${String(core['format'])}`);
250
+ }
251
+ const output = { format };
252
+ if (typeof core['quality'] === 'number')
253
+ output.quality = core['quality'];
254
+ if (typeof core['progressive'] === 'boolean')
255
+ output.progressive = core['progressive'];
256
+ if (core['chromaSubsampling'] === '4:2:0' || core['chromaSubsampling'] === '4:4:4')
257
+ output.chromaSubsampling = core['chromaSubsampling'];
258
+ if (typeof core['lossless'] === 'boolean')
259
+ output.lossless = core['lossless'];
260
+ if (Array.isArray(core['background']) && core['background'].length === 3)
261
+ output.background = core['background'];
262
+ return output;
263
+ }
149
264
  function tryCore(fn) {
150
265
  try {
151
266
  return fn();
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAuC,MAAM,iBAAiB,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAsB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAiB,YAAY,EAAmB,MAAM,WAAW,CAAC;AAEzE,OAAO,EAAE,cAAc,E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CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC;AAC7E,CAAC","sourcesContent":["import { loadSealpixelWasm, type RgbaBuffer, type SealpixelWasm } from '@sealpixel/wasm';\nimport { withAssets } from './assets.js';\nimport { canonicalJson } from './canonical-json.js';\nimport { compile, type PipelineStage, toCoreStages, toPipeline } from './compile.js';\nimport { SealpixelError } from './errors.js';\nimport { runExternalKernel } from './external-kernel.js';\nimport { type Geometry, PLAN_VERSION, type RenderPlan } from './plan.js';\nimport type { KernelContext, PlanContext } from './plugin.js';\nimport { createRegistry, type Registry } from './registry.js';\nimport type {\n EditLog,\n OutputFormat,\n OutputOptions,\n RenderOptions,\n RenderResult,\n RenderSource,\n} from './types.js';\n\nconst FORMAT_TO_CORE: Record<OutputFormat, string> = {\n 'image/png': 'png',\n 'image/jpeg': 'jpeg',\n 'image/webp': 'webp',\n};\n\nconst EMPTY_REGISTRY = createRegistry([]);\n\n/**\n * Renders `log` against `source` and encodes the result.\n *\n * Pure with respect to its inputs: same bytes, same log, same options, same\n * plugins and the same core version produce the same output bytes on every\n * runtime. Core stages run inside the wasm; JS kernels run between them\n * through the same orchestrator on every runtime.\n */\nexport async function render(\n source: RenderSource,\n log: EditLog,\n options: RenderOptions,\n): Promise<RenderResult> {\n const wasm = options.wasm ?? (await loadSealpixelWasm());\n const registry = options.registry ?? EMPTY_REGISTRY;\n throwIfAborted(options.signal);\n\n const t0 = now();\n const image = source instanceof Uint8Array ? tryCore(() => wasm.decode(source)) : source;\n const decodeMs = now() - t0;\n\n const mode = options.mode ?? 'truth';\n if (\n mode === 'truth' &&\n (image.width !== log.source.width || image.height !== log.source.height)\n ) {\n throw new SealpixelError(\n 'SOURCE_MISMATCH',\n `truth render expects ${log.source.width}x${log.source.height}, got ${image.width}x${image.height}`,\n );\n }\n if (log.ops.length > 0 && registry === EMPTY_REGISTRY) {\n throw new SealpixelError('INVALID_EDIT_LOG', 'log has ops but no registry was given');\n }\n throwIfAborted(options.signal);\n\n const t1 = now();\n const rendered = await withAssets(\n () =>\n runPipeline(wasm, registry, image, log, {\n mode,\n ...(options.upTo === undefined ? {} : { upTo: options.upTo }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n }),\n options.assets,\n (id, bytes) => wasm.assetPut(id, bytes),\n );\n const renderMs = now() - t1;\n throwIfAborted(options.signal);\n\n const t2 = now();\n const coreOutput = toCoreOutput(options.output);\n if (options.embedEditLog) {\n coreOutput['embed'] = canonicalJson({ log, index: options.upTo ?? log.ops.length });\n }\n const bytes = tryCore(() => wasm.encode(rendered, JSON.stringify(coreOutput)));\n const encodeMs = now() - t2;\n\n return {\n bytes,\n mimeType: options.output.format,\n width: rendered.width,\n height: rendered.height,\n hash: wasm.sha256Hex(bytes),\n coreVersion: wasm.version(),\n timings: { decode: decodeMs, render: renderMs, encode: encodeMs },\n };\n}\n\nexport interface PipelineOptions {\n mode: 'truth' | 'preview';\n upTo?: number;\n signal?: AbortSignal;\n}\n\n/**\n * Compiles the log and executes it: consecutive core stages become one wasm\n * call, every external kernel runs in between on the RGBA buffer.\n */\nexport async function runPipeline(\n wasm: SealpixelWasm,\n registry: Registry,\n image: RgbaBuffer,\n log: EditLog,\n options: PipelineOptions,\n): Promise<RgbaBuffer> {\n const doc = compile(log, registry, options.upTo);\n const logical = { width: log.source.width, height: log.source.height };\n const ctx: PlanContext = {\n logical,\n actual: { width: image.width, height: image.height },\n scale: image.width / log.source.width,\n mode: options.mode,\n };\n const stages = toPipeline(doc, registry, ctx);\n\n let current = image;\n let currentLogical = logical;\n for (const segment of segments(stages)) {\n throwIfAborted(options.signal);\n if (segment.kind === 'core') {\n const plan: RenderPlan = {\n version: PLAN_VERSION,\n source: currentLogical,\n bufferScale: current.width / currentLogical.width,\n stages: toCoreStages(segment.stages),\n };\n const planJson = JSON.stringify(plan);\n const geometry = JSON.parse(\n tryCore(() => wasm.resolveGeometry(planJson, current.width, current.height)),\n ) as Geometry;\n current = tryCore(() => wasm.renderRgba(current, planJson));\n currentLogical = geometry.logicalOut;\n } else {\n const stage = segment.stage;\n const kctx: KernelContext = {\n logical: currentLogical,\n actual: { width: current.width, height: current.height },\n scale: current.width / currentLogical.width,\n mode: options.mode,\n asset: (id) => {\n throw new SealpixelError(\n 'INVALID_EDIT_LOG',\n `asset \"${id}\" requested but assets are not supported yet (S3.3)`,\n );\n },\n signal: options.signal ?? new AbortController().signal,\n };\n const out = await runExternalKernel(stage.plugin, current, stage.params, kctx);\n if (out.width !== current.width || out.height !== current.height) {\n currentLogical = {\n width: Math.round(currentLogical.width * (out.width / current.width)),\n height: Math.round(currentLogical.height * (out.height / current.height)),\n };\n }\n current = out;\n }\n }\n return current;\n}\n\ntype Segment =\n | { kind: 'core'; stages: PipelineStage[] }\n | { kind: 'external'; stage: Extract<PipelineStage, { kind: 'js' | 'wasm' }> };\n\nfunction* segments(stages: PipelineStage[]): Generator<Segment> {\n let run: PipelineStage[] = [];\n for (const stage of stages) {\n if (stage.kind === 'core') {\n run.push(stage);\n continue;\n }\n if (run.length > 0) {\n yield { kind: 'core', stages: run };\n run = [];\n }\n yield { kind: 'external', stage };\n }\n if (run.length > 0) yield { kind: 'core', stages: run };\n}\n\n/** Maps the public output options onto the Rust `OutputOptions` JSON. */\nexport function toCoreOutput(output: OutputOptions): Record<string, unknown> {\n const core: Record<string, unknown> = { format: FORMAT_TO_CORE[output.format] };\n if (output.quality !== undefined) core['quality'] = output.quality;\n if (output.progressive !== undefined) core['progressive'] = output.progressive;\n if (output.chromaSubsampling !== undefined) core['chromaSubsampling'] = output.chromaSubsampling;\n if (output.lossless !== undefined) core['lossless'] = output.lossless;\n if (output.background !== undefined) core['background'] = output.background;\n return core;\n}\n\nfunction tryCore<T>(fn: () => T): T {\n try {\n return fn();\n } catch (error) {\n throw SealpixelError.from(error);\n }\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted) throw new SealpixelError('ABORTED', 'render aborted');\n}\n\nfunction now(): number {\n return typeof performance === 'undefined' ? Date.now() : performance.now();\n}\n"]}
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,GAGlB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAsB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAuB,UAAU,EAAE,MAAM,eAAe,CAAC;AAC/F,OAAO,EAAiB,YAAY,EAAmB,MAAM,WAAW,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAiB,MAAM,eAAe,CAAC;AAU9D,MAAM,cAAc,GAAiC;IACnD,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,MAAM;IACpB,YAAY,EAAE,MAAM;CACrB,CAAC;AAEF,MAAM,cAAc,GAAG,cAAc,CAAC,EAAE,CAAC,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,MAAoB,EACpB,GAAY,EACZ,OAAsB;IAEtB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,MAAM,iBAAiB,EAAE,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,cAAc,CAAC;IACpD,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC;IACrC,uEAAuE;IACvE,wEAAwE;IACxE,4DAA4D;IAC5D,IAAI,OAAO,CAAC,QAAQ,IAAI,IAAI,KAAK,OAAO,EAAE,C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I,IAAI,CAAC,mBAAmB,CAAC,KAAK,OAAO,IAAI,IAAI,CAAC,mBAAmB,CAAC,KAAK,OAAO;QAChF,MAAM,CAAC,iBAAiB,GAAG,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACvD,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,SAAS;QAAE,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9E,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC;QACtE,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,CAA6B,CAAC;IACrE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,OAAO,CAAI,EAAW;IAC7B,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,MAA+B;IACrD,IAAI,MAAM,EAAE,OAAO;QAAE,MAAM,IAAI,cAAc,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,GAAG;IACV,OAAO,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC;AAC7E,CAAC","sourcesContent":["import {\n type DecodedImage,\n loadSealpixelWasm,\n type RgbaBuffer,\n type SealpixelWasm,\n} from '@sealpixel/wasm';\nimport { withAssets } from './assets.js';\nimport { canonicalJson } from './canonical-json.js';\nimport { compile, type PipelineStage, toCoreStages, toPipeline } from './compile.js';\nimport { SealpixelError } from './errors.js';\nimport { runExternalKernel } from './external-kernel.js';\nimport { editLogHash, MANIFEST_VERSION, type RenderManifest, renderHash } from './manifest.js';\nimport { type Geometry, PLAN_VERSION, type RenderPlan } from './plan.js';\nimport type { KernelContext, PlanContext } from './plugin.js';\nimport { createRegistry, type Registry } from './registry.js';\nimport type {\n EditLog,\n OutputFormat,\n OutputOptions,\n RenderOptions,\n RenderResult,\n RenderSource,\n} from './types.js';\n\nconst FORMAT_TO_CORE: Record<OutputFormat, string> = {\n 'image/png': 'png',\n 'image/jpeg': 'jpeg',\n 'image/webp': 'webp',\n};\n\nconst EMPTY_REGISTRY = createRegistry([]);\n\n/**\n * Renders `log` against `source` and encodes the result.\n *\n * Pure with respect to its inputs: same bytes, same log, same options, same\n * plugins and the same core version produce the same output bytes on every\n * runtime. Core stages run inside the wasm; JS kernels run between them\n * through the same orchestrator on every runtime.\n */\nexport async function render(\n source: RenderSource,\n log: EditLog,\n options: RenderOptions,\n): Promise<RenderResult> {\n const wasm = options.wasm ?? (await loadSealpixelWasm());\n const registry = options.registry ?? EMPTY_REGISTRY;\n throwIfAborted(options.signal);\n\n const mode = options.mode ?? 'truth';\n // What a manifest needs is checked before the hash and the decode, the\n // expensive steps. A buffer source names its hash explicitly: the log's\n // `source.hash` is a claim about bytes this call never saw.\n if (options.manifest && mode !== 'truth') {\n throw new SealpixelError(\n 'INVALID_REQUEST',\n 'a manifest describes a truth render; a preview cannot be verified',\n );\n }\n const sourceHash = !options.manifest\n ? undefined\n : source instanceof Uint8Array\n ? wasm.sha256Hex(source)\n : options.sourceHash;\n if (options.manifest && sourceHash === undefined) {\n throw new SealpixelError(\n 'INVALID_REQUEST',\n 'a manifest needs the hash of the original: pass the bytes as source, or sourceHash with a buffer',\n );\n }\n\n const t0 = now();\n const image = source instanceof Uint8Array ? tryCore(() => wasm.decode(source)) : source;\n const decodeMs = now() - t0;\n\n if (\n mode === 'truth' &&\n (image.width !== log.source.width || image.height !== log.source.height)\n ) {\n throw new SealpixelError(\n 'SOURCE_MISMATCH',\n `truth render expects ${log.source.width}x${log.source.height}, got ${image.width}x${image.height}`,\n );\n }\n if (log.ops.length > 0 && registry === EMPTY_REGISTRY) {\n throw new SealpixelError('INVALID_EDIT_LOG', 'log has ops but no registry was given');\n }\n throwIfAborted(options.signal);\n\n const t1 = now();\n const { stages, logical } = compileStages(registry, image, log, mode, options.upTo);\n const rendered = await withAssets(\n () =>\n executeStages(wasm, stages, image, logical, {\n mode,\n ...(options.manifest ? { pixelHash: true } : {}),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n }),\n options.assets,\n (id, bytes) => wasm.assetPut(id, bytes),\n );\n const renderMs = now() - t1;\n throwIfAborted(options.signal);\n\n const t2 = now();\n const coreOutput = toCoreOutput(options.output);\n if (options.embedEditLog) {\n coreOutput['embed'] = canonicalJson({ log, index: options.upTo ?? log.ops.length });\n }\n // A decoded source carries its ICC profile; pixels given by the caller carry\n // what the caller attached, if anything. No `instanceof`: a typed array from\n // another realm is still a profile.\n const icc = (image as Partial<DecodedImage>).icc;\n const bytes = tryCore(() => wasm.encode(rendered, JSON.stringify(coreOutput), icc));\n const encodeMs = now() - t2;\n\n const result: RenderResult = {\n bytes,\n mimeType: options.output.format,\n width: rendered.width,\n height: rendered.height,\n hash: wasm.sha256Hex(bytes),\n coreVersion: wasm.version(),\n timings: { decode: decodeMs, render: renderMs, encode: encodeMs },\n };\n if (options.manifest && sourceHash !== undefined) {\n const t3 = now();\n result.manifest = buildManifest(wasm, registry, stages, logical, log, options, {\n sourceHash,\n rendered,\n bytes: result.hash,\n output: toCoreOutput(options.output),\n mimeType: (image as Partial<DecodedImage>).mimeType,\n });\n result.timings['manifest'] = now() - t3;\n }\n return result;\n}\n\n/**\n * The manifest of a finished render, from the stages that rendered. The plan\n * is the single core plan of a render whose stages all ran in the core; a\n * pipeline with a plugin kernel outside the core lists the kernels instead,\n * and only a JavaScript runtime can verify it. `output.options` never\n * carries `embed`: the log is in `editLog`, and `embedEditLog` says whether\n * the file holds it too.\n */\nfunction buildManifest(\n wasm: SealpixelWasm,\n registry: Registry,\n stages: readonly PipelineStage[],\n logical: { width: number; height: number },\n log: EditLog,\n options: RenderOptions,\n result: {\n sourceHash: string;\n rendered: RgbaBuffer & { pixelHash?: string };\n bytes: string;\n output: Record<string, unknown>;\n mimeType: string | undefined;\n },\n): RenderManifest {\n const index = options.upTo ?? log.ops.length;\n const kernels = stages.filter((s) => s.kind !== 'core').map((s) => s.name);\n const plan: RenderPlan | undefined =\n kernels.length === 0\n ? { version: PLAN_VERSION, source: logical, bufferScale: 1, stages: toCoreStages(stages) }\n : undefined;\n const plugins = registry.pluginVersions();\n const renderer = wasm.identity();\n // From the core when the last stage ran there; a kernel outside the core\n // leaves its buffer in JavaScript, which is then hashed from there.\n const pixelHash = result.rendered.pixelHash ?? wasm.pixelHash(result.rendered);\n const logHash = editLogHash(wasm.sha256Hex, log, index);\n return {\n version: MANIFEST_VERSION,\n source: {\n width: log.source.width,\n height: log.source.height,\n hash: result.sourceHash,\n ...(result.mimeType === undefined ? {} : { mimeType: result.mimeType }),\n },\n editLog: { log, index },\n editLogHash: logHash,\n ...(plan ? { plan } : { kernels }),\n plugins,\n renderer,\n output: {\n options: result.output,\n ...(options.embedEditLog ? { embedEditLog: true } : {}),\n width: result.rendered.width,\n height: result.rendered.height,\n pixelHash,\n byteHash: result.bytes,\n },\n renderHash: renderHash(wasm.sha256Hex, {\n sourceHash: result.sourceHash,\n editsHash: logHash,\n plugins,\n renderer,\n pixelHash,\n byteHash: result.bytes,\n }),\n };\n}\n\nexport interface PipelineOptions {\n mode: 'truth' | 'preview';\n upTo?: number;\n signal?: AbortSignal;\n}\n\n/**\n * Compiles the log and executes it: consecutive core stages become one wasm\n * call, every external kernel runs in between on the RGBA buffer.\n */\nexport async function runPipeline(\n wasm: SealpixelWasm,\n registry: Registry,\n image: RgbaBuffer,\n log: EditLog,\n options: PipelineOptions,\n): Promise<RgbaBuffer> {\n const { stages, logical } = compileStages(registry, image, log, options.mode, options.upTo);\n return executeStages(wasm, stages, image, logical, options);\n}\n\n/** Compiles `ops[0..upTo)` into the ordered stages for a buffer of `image`'s size. */\nfunction compileStages(\n registry: Registry,\n image: RgbaBuffer,\n log: EditLog,\n mode: 'truth' | 'preview',\n upTo: number | undefined,\n): { stages: PipelineStage[]; logical: { width: number; height: number } } {\n const doc = compile(log, registry, upTo);\n const logical = { width: log.source.width, height: log.source.height };\n const ctx: PlanContext = {\n logical,\n actual: { width: image.width, height: image.height },\n scale: image.width / log.source.width,\n mode,\n };\n return { stages: toPipeline(doc, registry, ctx), logical };\n}\n\n/** Runs the stages: consecutive core stages as one wasm call, every external kernel in between. */\nasync function executeStages(\n wasm: SealpixelWasm,\n stages: readonly PipelineStage[],\n image: RgbaBuffer,\n logical: { width: number; height: number },\n options: Pick<PipelineOptions, 'mode' | 'signal'> & { pixelHash?: boolean },\n): Promise<RgbaBuffer & { pixelHash?: string }> {\n let current: RgbaBuffer & { pixelHash?: string } = image;\n let currentLogical = logical;\n const all = [...segments(stages)];\n for (const [i, segment] of all.entries()) {\n throwIfAborted(options.signal);\n if (segment.kind === 'core') {\n const plan: RenderPlan = {\n version: PLAN_VERSION,\n source: currentLogical,\n bufferScale: current.width / currentLogical.width,\n stages: toCoreStages(segment.stages),\n };\n const planJson = JSON.stringify(plan);\n const geometry = JSON.parse(\n tryCore(() => wasm.resolveGeometry(planJson, current.width, current.height)),\n ) as Geometry;\n const last = i === all.length - 1;\n current = tryCore(() =>\n wasm.renderRgba(current, planJson, options.pixelHash && last ? { pixelHash: true } : {}),\n );\n currentLogical = geometry.logicalOut;\n } else {\n const stage = segment.stage;\n const kctx: KernelContext = {\n logical: currentLogical,\n actual: { width: current.width, height: current.height },\n scale: current.width / currentLogical.width,\n mode: options.mode,\n asset: (id) => {\n throw new SealpixelError(\n 'INVALID_EDIT_LOG',\n `asset \"${id}\" requested but assets are not supported yet (S3.3)`,\n );\n },\n signal: options.signal ?? new AbortController().signal,\n };\n const out = await runExternalKernel(stage.plugin, current, stage.params, kctx);\n if (out.width !== current.width || out.height !== current.height) {\n currentLogical = {\n width: Math.round(currentLogical.width * (out.width / current.width)),\n height: Math.round(currentLogical.height * (out.height / current.height)),\n };\n }\n current = out;\n }\n }\n return current;\n}\n\ntype Segment =\n | { kind: 'core'; stages: PipelineStage[] }\n | { kind: 'external'; stage: Extract<PipelineStage, { kind: 'js' | 'wasm' }> };\n\nfunction* segments(stages: readonly PipelineStage[]): Generator<Segment> {\n let run: PipelineStage[] = [];\n for (const stage of stages) {\n if (stage.kind === 'core') {\n run.push(stage);\n continue;\n }\n if (run.length > 0) {\n yield { kind: 'core', stages: run };\n run = [];\n }\n yield { kind: 'external', stage };\n }\n if (run.length > 0) yield { kind: 'core', stages: run };\n}\n\n/** Maps the public output options onto the Rust `OutputOptions` JSON. */\nexport function toCoreOutput(output: OutputOptions): Record<string, unknown> {\n const core: Record<string, unknown> = { format: FORMAT_TO_CORE[output.format] };\n if (output.quality !== undefined) core['quality'] = output.quality;\n if (output.progressive !== undefined) core['progressive'] = output.progressive;\n if (output.chromaSubsampling !== undefined) core['chromaSubsampling'] = output.chromaSubsampling;\n if (output.lossless !== undefined) core['lossless'] = output.lossless;\n if (output.background !== undefined) core['background'] = output.background;\n return core;\n}\n\n/**\n * The inverse of `toCoreOutput`, for the options a render manifest records.\n * `embed` is not an option here: `embedEditLog` regenerates it from the log.\n */\nexport function fromCoreOutput(core: Record<string, unknown>): OutputOptions {\n const format = (Object.keys(FORMAT_TO_CORE) as OutputFormat[]).find(\n (f) => FORMAT_TO_CORE[f] === core['format'],\n );\n if (format === undefined) {\n throw new SealpixelError('INVALID_REQUEST', `unknown output format ${String(core['format'])}`);\n }\n const output: OutputOptions = { format };\n if (typeof core['quality'] === 'number') output.quality = core['quality'];\n if (typeof core['progressive'] === 'boolean') output.progressive = core['progressive'];\n if (core['chromaSubsampling'] === '4:2:0' || core['chromaSubsampling'] === '4:4:4')\n output.chromaSubsampling = core['chromaSubsampling'];\n if (typeof core['lossless'] === 'boolean') output.lossless = core['lossless'];\n if (Array.isArray(core['background']) && core['background'].length === 3)\n output.background = core['background'] as [number, number, number];\n return output;\n}\n\nfunction tryCore<T>(fn: () => T): T {\n try {\n return fn();\n } catch (error) {\n throw SealpixelError.from(error);\n }\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted) throw new SealpixelError('ABORTED', 'render aborted');\n}\n\nfunction now(): number {\n return typeof performance === 'undefined' ? Date.now() : performance.now();\n}\n"]}
@@ -54,6 +54,8 @@ export declare class RendererCore {
54
54
  readonly registry: Registry;
55
55
  private readonly options;
56
56
  private full;
57
+ /** The source's ICC profile, kept with the resident pixels for the export. */
58
+ private icc;
57
59
  private workingCopy;
58
60
  private descriptor;
59
61
  private readonly cache;
@@ -10,6 +10,8 @@ export class RendererCore {
10
10
  registry;
11
11
  options;
12
12
  full = null;
13
+ /** The source's ICC profile, kept with the resident pixels for the export. */
14
+ icc;
13
15
  workingCopy = null;
14
16
  descriptor = null;
15
17
  cache = new Map();
@@ -43,6 +45,7 @@ export class RendererCore {
43
45
  const resident = megapixels <= maxClientMegapixels;
44
46
  const workingCopy = this.wasm.resizeWorkingCopy(decoded, this.options.workingCopyMaxSide);
45
47
  this.full = resident ? decoded : null;
48
+ this.icc = resident ? decoded.icc : undefined;
46
49
  this.workingCopy = workingCopy;
47
50
  this.descriptor = descriptor;
48
51
  this.cache.clear();
@@ -59,6 +62,7 @@ export class RendererCore {
59
62
  /** Accepts pixels decoded elsewhere, for example by a native decoder. Never resident. */
60
63
  loadWorkingCopy(workingCopy, descriptor) {
61
64
  this.full = null;
65
+ this.icc = undefined;
62
66
  this.workingCopy = workingCopy;
63
67
  this.descriptor = descriptor;
64
68
  this.cache.clear();
@@ -76,6 +80,7 @@ export class RendererCore {
76
80
  }
77
81
  unload() {
78
82
  this.full = null;
83
+ this.icc = undefined;
79
84
  this.workingCopy = null;
80
85
  this.descriptor = null;
81
86
  this.cache.clear();
@@ -111,7 +116,7 @@ export class RendererCore {
111
116
  if (req.embedEditLog) {
112
117
  coreOutput['embed'] = canonicalJson({ log: req.log, index: req.upTo ?? req.log.ops.length });
113
118
  }
114
- const bytes = this.wasm.encode(rendered, JSON.stringify(coreOutput));
119
+ const bytes = this.wasm.encode(rendered, JSON.stringify(coreOutput), this.icc);
115
120
  return {
116
121
  bytes,
117
122
  mimeType: req.output.format,
@@ -1 +1 @@
1
- {"version":3,"file":"renderer-core.js","sourceRoot":"","sources":["../src/renderer-core.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAsB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAiB,YAAY,EAAmB,MAAM,WAAW,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAiB,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAkD3C,MAAM,OAAO,YAAY;IASZ;IARF,QAAQ,CAAW;IACX,OAAO,CAAsB;IACtC,IAAI,GAAsB,IAAI,CAAC;IAC/B,WAAW,GAAsB,IAAI,CAAC;IACtC,UAAU,GAA4B,IAAI,CAAC;IAClC,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEvD,YACW,IAAmB,EAC5B,OAA4B;QADnB,SAAI,GAAJ,IAAI,CAAe;QAG5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,QAAQ,CAAC,EAAU,EAAE,KAAiB;QACpC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,QAAQ,CAAC,EAAU;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ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,CAAC;YAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;YAC9C,IAAI,MAAM,KAAK,SAAS;gBAAE,MAAM;YAChC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,iDAAiD;IACjD,SAAS;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;CACF","sourcesContent":["/**\n * The renderer's logic, independent of where it runs. `startSealpixelWorker`\n * wraps it behind a message protocol; `InlineRenderer` calls it directly.\n * It owns the decoded source, the working copy, and a per-stage preview cache.\n */\nimport type { RgbaBuffer, SealpixelWasm } from '@sealpixel/wasm';\nimport { canonicalJson } from './canonical-json.js';\nimport { compile, type PipelineStage, toCoreStages, toPipeline } from './compile.js';\nimport { SealpixelError } from './errors.js';\nimport { runExternalKernel } from './external-kernel.js';\nimport { type Geometry, PLAN_VERSION, type RenderPlan } from './plan.js';\nimport type { AnyPlugin, KernelContext, PlanContext } from './plugin.js';\nimport { createRegistry, type Registry } from './registry.js';\nimport { toCoreOutput } from './render.js';\nimport type { EditLog, OutputOptions, SourceDescriptor } from './types.js';\n\nexport interface LoadedSource {\n descriptor: SourceDescriptor;\n /** Full-resolution pixels are kept only when under the megapixel limit. */\n resident: boolean;\n workingCopy: RgbaBuffer;\n}\n\nexport interface RenderRequest {\n log: EditLog;\n /** `workingCopy` renders on the working copy in preview mode; `full` renders the resident source in truth mode. */\n target: 'workingCopy' | 'full';\n upTo?: number;\n signal?: AbortSignal;\n}\n\nexport interface ExportRequest {\n log: EditLog;\n output: OutputOptions;\n upTo?: number;\n embedEditLog?: boolean;\n}\n\nexport interface ExportResult {\n /** Backed by a plain `ArrayBuffer`, so it is a `BlobPart`. */\n bytes: Uint8Array<ArrayBuffer>;\n mimeType: OutputOptions['format'];\n width: number;\n height: number;\n hash: string;\n}\n\nexport interface RendererCoreOptions {\n plugins: readonly AnyPlugin[];\n /** Full-resolution pixels above this are not kept after loading. `RendererLoadOptions` overrides it per load. */\n maxClientMegapixels: number;\n /** Longest side of the preview working copy. */\n workingCopyMaxSide: number;\n /** Cached stage outputs kept for the preview pipeline. */\n cacheEntries?: number;\n}\n\n/** Per-load overrides of `RendererCoreOptions`. The session passes its `limits` here. */\nexport interface RendererLoadOptions {\n /** Full-resolution pixels above this are not kept after loading. Defaults to the renderer's option. */\n maxClientMegapixels?: number;\n}\n\nexport class RendererCore {\n readonly registry: Registry;\n private readonly options: RendererCoreOptions;\n private full: RgbaBuffer | null = null;\n private workingCopy: RgbaBuffer | null = null;\n private descriptor: SourceDescriptor | null = null;\n private readonly cache = new Map<string, RgbaBuffer>();\n\n constructor(\n readonly wasm: SealpixelWasm,\n options: RendererCoreOptions,\n ) {\n this.options = options;\n this.registry = createRegistry(options.plugins);\n }\n\n putAsset(id: string, bytes: Uint8Array): void {\n this.wasm.assetPut(id, bytes);\n }\n\n hasAsset(id: string): boolean {\n return this.wasm.assetHas(id);\n }\n\n info(): { coreVersion: string; plugins: Record<string, number> } {\n return { coreVersion: this.wasm.version(), plugins: this.registry.pluginVersions() };\n }\n\n /** Decodes `bytes`, derives the descriptor and working copy, and drops the full image when too large. */\n load(bytes: Uint8Array, id: string, loadOptions: RendererLoadOptions = {}): LoadedSource {\n const decoded = this.wasm.decode(bytes);\n const hash = this.wasm.sha256Hex(bytes);\n const descriptor: SourceDescriptor = {\n id,\n width: decoded.width,\n height: decoded.height,\n hash,\n mimeType: decoded.mimeType,\n };\n const megapixels = (decoded.width * decoded.height) / 1e6;\n const maxClientMegapixels = loadOptions.maxClientMegapixels ?? this.options.maxClientMegapixels;\n const resident = megapixels <= maxClientMegapixels;\n const workingCopy = this.wasm.resizeWorkingCopy(decoded, this.options.workingCopyMaxSide);\n this.full = resident ? decoded : null;\n this.workingCopy = workingCopy;\n this.descriptor = descriptor;\n this.cache.clear();\n return {\n descriptor,\n resident,\n workingCopy: { ...workingCopy, data: new Uint8Array(workingCopy.data) },\n };\n }\n\n /** Decodes an encoded working copy (for example one the host built elsewhere) and uses it as the preview source. */\n loadWorkingCopyEncoded(bytes: Uint8Array, descriptor: SourceDescriptor): LoadedSource {\n return this.loadWorkingCopy(this.wasm.decode(bytes), descriptor);\n }\n\n /** Accepts pixels decoded elsewhere, for example by a native decoder. Never resident. */\n loadWorkingCopy(workingCopy: RgbaBuffer, descriptor: SourceDescriptor): LoadedSource {\n this.full = null;\n this.workingCopy = workingCopy;\n this.descriptor = descriptor;\n this.cache.clear();\n return {\n descriptor,\n resident: false,\n workingCopy: { ...workingCopy, data: new Uint8Array(workingCopy.data) },\n };\n }\n\n hasSource(): boolean {\n return this.descriptor !== null;\n }\n\n isResident(): boolean {\n return this.full !== null;\n }\n\n unload(): void {\n this.full = null;\n this.workingCopy = null;\n this.descriptor = null;\n this.cache.clear();\n }\n\n /** Renders the log. Preview renders are split per stage and cached by prefix. */\n async render(req: RenderRequest): Promise<RgbaBuffer> {\n const { descriptor } = this.require();\n const image = req.target === 'full' ? this.full : this.workingCopy;\n if (!image) {\n throw new SealpixelError(\n 'SOURCE_MISMATCH',\n req.target === 'full'\n ? 'full-resolution pixels are not resident; render the original outside the browser'\n : 'no source loaded',\n );\n }\n const mode = req.target === 'full' ? 'truth' : 'preview';\n const doc = compile(req.log, this.registry, req.upTo);\n const logical = { width: descriptor.width, height: descriptor.height };\n const ctx: PlanContext = {\n logical,\n actual: { width: image.width, height: image.height },\n scale: image.width / logical.width,\n mode,\n };\n const stages = toPipeline(doc, this.registry, ctx);\n return this.runStages(stages, image, logical, mode, req.signal, mode === 'preview');\n }\n\n async export(req: ExportRequest): Promise<ExportResult> {\n const rendered = await this.render({\n log: req.log,\n target: 'full',\n ...(req.upTo === undefined ? {} : { upTo: req.upTo }),\n });\n const coreOutput = toCoreOutput(req.output);\n if (req.embedEditLog) {\n coreOutput['embed'] = canonicalJson({ log: req.log, index: req.upTo ?? req.log.ops.length });\n }\n const bytes = this.wasm.encode(rendered, JSON.stringify(coreOutput));\n return {\n bytes,\n mimeType: req.output.format,\n width: rendered.width,\n height: rendered.height,\n hash: this.wasm.sha256Hex(bytes),\n };\n }\n\n geometry(log: EditLog, target: 'workingCopy' | 'full', upTo?: number): Geometry {\n const { descriptor } = this.require();\n const image = (target === 'full' ? this.full : this.workingCopy) ?? this.workingCopy;\n if (!image) throw new SealpixelError('SOURCE_MISMATCH', 'no source loaded');\n const logical = { width: descriptor.width, height: descriptor.height };\n const doc = compile(log, this.registry, upTo);\n const stages = toPipeline(doc, this.registry, {\n logical,\n actual: { width: image.width, height: image.height },\n scale: image.width / logical.width,\n mode: target === 'full' ? 'truth' : 'preview',\n });\n const core = stages.filter((s) => s.kind === 'core');\n const plan: RenderPlan = {\n version: PLAN_VERSION,\n source: logical,\n bufferScale: image.width / logical.width,\n stages: toCoreStages(core),\n };\n return JSON.parse(\n this.wasm.resolveGeometry(JSON.stringify(plan), image.width, image.height),\n ) as Geometry;\n }\n\n private require(): { descriptor: SourceDescriptor } {\n if (!this.descriptor) throw new SealpixelError('SOURCE_MISMATCH', 'no source loaded');\n return { descriptor: this.descriptor };\n }\n\n private async runStages(\n stages: PipelineStage[],\n image: RgbaBuffer,\n logical: { width: number; height: number },\n mode: 'truth' | 'preview',\n signal: AbortSignal | undefined,\n useCache: boolean,\n ): Promise<RgbaBuffer> {\n let current = image;\n let currentLogical = logical;\n let prefix = `${image.width}x${image.height}`;\n for (const stage of stages) {\n if (signal?.aborted) throw new SealpixelError('ABORTED', 'render aborted');\n prefix += `|${canonicalJson({ n: stage.name, p: stage.params })}`;\n const cached = useCache ? this.cache.get(prefix) : undefined;\n if (cached) {\n current = cached;\n currentLogical = this.logicalAfter(stage, currentLogical, current, image, logical);\n continue;\n }\n if (stage.kind === 'core') {\n const plan: RenderPlan = {\n version: PLAN_VERSION,\n source: currentLogical,\n bufferScale: current.width / currentLogical.width,\n stages: toCoreStages([stage]),\n };\n const planJson = JSON.stringify(plan);\n const geometry = JSON.parse(\n this.wasm.resolveGeometry(planJson, current.width, current.height),\n ) as Geometry;\n current = this.wasm.renderRgba(current, planJson);\n currentLogical = geometry.logicalOut;\n } else {\n const kctx: KernelContext = {\n logical: currentLogical,\n actual: { width: current.width, height: current.height },\n scale: current.width / currentLogical.width,\n mode,\n asset: (id) => {\n throw new SealpixelError(\n 'MISSING_ASSET',\n `asset \"${id}\" is not available to JS kernels yet`,\n { assetId: id },\n );\n },\n signal: signal ?? new AbortController().signal,\n };\n const out = await runExternalKernel(stage.plugin, current, stage.params, kctx);\n if (out.width !== current.width || out.height !== current.height) {\n currentLogical = {\n width: Math.round(currentLogical.width * (out.width / current.width)),\n height: Math.round(currentLogical.height * (out.height / current.height)),\n };\n }\n current = out;\n }\n if (useCache) this.remember(prefix, current);\n }\n return current;\n }\n\n /** Recomputes the logical size after a cached stage by asking the core for its geometry. */\n private logicalAfter(\n stage: PipelineStage,\n logicalIn: { width: number; height: number },\n out: RgbaBuffer,\n _image: RgbaBuffer,\n _sourceLogical: { width: number; height: number },\n ): { width: number; height: number } {\n if (stage.kind !== 'core') {\n return {\n width: Math.round(logicalIn.width * (out.width / out.width)),\n height: logicalIn.height,\n };\n }\n // The cached buffer already has the output size; the logical size is the\n // geometry of this single stage on a buffer with the input's logical size.\n const plan: RenderPlan = {\n version: PLAN_VERSION,\n source: logicalIn,\n bufferScale: 1,\n stages: toCoreStages([stage]),\n };\n const g = JSON.parse(\n this.wasm.resolveGeometry(JSON.stringify(plan), logicalIn.width, logicalIn.height),\n ) as Geometry;\n return g.logicalOut;\n }\n\n private remember(key: string, value: RgbaBuffer): void {\n const limit = this.options.cacheEntries ?? 6;\n if (this.cache.has(key)) this.cache.delete(key);\n this.cache.set(key, value);\n while (this.cache.size > limit) {\n const oldest = this.cache.keys().next().value;\n if (oldest === undefined) break;\n this.cache.delete(oldest);\n }\n }\n\n /** For tests: number of cached stage outputs. */\n cacheSize(): number {\n return this.cache.size;\n }\n}\n"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AC3B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;YAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;YAC9C,IAAI,MAAM,KAAK,SAAS;gBAAE,MAAM;YAChC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,iDAAiD;IACjD,SAAS;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;CACF","sourcesContent":["/**\n * The renderer's logic, independent of where it runs. `startSealpixelWorker`\n * wraps it behind a message protocol; `InlineRenderer` calls it directly.\n * It owns the decoded source, the working copy, and a per-stage preview cache.\n */\nimport type { RgbaBuffer, SealpixelWasm } from '@sealpixel/wasm';\nimport { canonicalJson } from './canonical-json.js';\nimport { compile, type PipelineStage, toCoreStages, toPipeline } from './compile.js';\nimport { SealpixelError } from './errors.js';\nimport { runExternalKernel } from './external-kernel.js';\nimport { type Geometry, PLAN_VERSION, type RenderPlan } from './plan.js';\nimport type { AnyPlugin, KernelContext, PlanContext } from './plugin.js';\nimport { createRegistry, type Registry } from './registry.js';\nimport { toCoreOutput } from './render.js';\nimport type { EditLog, OutputOptions, SourceDescriptor } from './types.js';\n\nexport interface LoadedSource {\n descriptor: SourceDescriptor;\n /** Full-resolution pixels are kept only when under the megapixel limit. */\n resident: boolean;\n workingCopy: RgbaBuffer;\n}\n\nexport interface RenderRequest {\n log: EditLog;\n /** `workingCopy` renders on the working copy in preview mode; `full` renders the resident source in truth mode. */\n target: 'workingCopy' | 'full';\n upTo?: number;\n signal?: AbortSignal;\n}\n\nexport interface ExportRequest {\n log: EditLog;\n output: OutputOptions;\n upTo?: number;\n embedEditLog?: boolean;\n}\n\nexport interface ExportResult {\n /** Backed by a plain `ArrayBuffer`, so it is a `BlobPart`. */\n bytes: Uint8Array<ArrayBuffer>;\n mimeType: OutputOptions['format'];\n width: number;\n height: number;\n hash: string;\n}\n\nexport interface RendererCoreOptions {\n plugins: readonly AnyPlugin[];\n /** Full-resolution pixels above this are not kept after loading. `RendererLoadOptions` overrides it per load. */\n maxClientMegapixels: number;\n /** Longest side of the preview working copy. */\n workingCopyMaxSide: number;\n /** Cached stage outputs kept for the preview pipeline. */\n cacheEntries?: number;\n}\n\n/** Per-load overrides of `RendererCoreOptions`. The session passes its `limits` here. */\nexport interface RendererLoadOptions {\n /** Full-resolution pixels above this are not kept after loading. Defaults to the renderer's option. */\n maxClientMegapixels?: number;\n}\n\nexport class RendererCore {\n readonly registry: Registry;\n private readonly options: RendererCoreOptions;\n private full: RgbaBuffer | null = null;\n /** The source's ICC profile, kept with the resident pixels for the export. */\n private icc: Uint8Array | undefined;\n private workingCopy: RgbaBuffer | null = null;\n private descriptor: SourceDescriptor | null = null;\n private readonly cache = new Map<string, RgbaBuffer>();\n\n constructor(\n readonly wasm: SealpixelWasm,\n options: RendererCoreOptions,\n ) {\n this.options = options;\n this.registry = createRegistry(options.plugins);\n }\n\n putAsset(id: string, bytes: Uint8Array): void {\n this.wasm.assetPut(id, bytes);\n }\n\n hasAsset(id: string): boolean {\n return this.wasm.assetHas(id);\n }\n\n info(): { coreVersion: string; plugins: Record<string, number> } {\n return { coreVersion: this.wasm.version(), plugins: this.registry.pluginVersions() };\n }\n\n /** Decodes `bytes`, derives the descriptor and working copy, and drops the full image when too large. */\n load(bytes: Uint8Array, id: string, loadOptions: RendererLoadOptions = {}): LoadedSource {\n const decoded = this.wasm.decode(bytes);\n const hash = this.wasm.sha256Hex(bytes);\n const descriptor: SourceDescriptor = {\n id,\n width: decoded.width,\n height: decoded.height,\n hash,\n mimeType: decoded.mimeType,\n };\n const megapixels = (decoded.width * decoded.height) / 1e6;\n const maxClientMegapixels = loadOptions.maxClientMegapixels ?? this.options.maxClientMegapixels;\n const resident = megapixels <= maxClientMegapixels;\n const workingCopy = this.wasm.resizeWorkingCopy(decoded, this.options.workingCopyMaxSide);\n this.full = resident ? decoded : null;\n this.icc = resident ? decoded.icc : undefined;\n this.workingCopy = workingCopy;\n this.descriptor = descriptor;\n this.cache.clear();\n return {\n descriptor,\n resident,\n workingCopy: { ...workingCopy, data: new Uint8Array(workingCopy.data) },\n };\n }\n\n /** Decodes an encoded working copy (for example one the host built elsewhere) and uses it as the preview source. */\n loadWorkingCopyEncoded(bytes: Uint8Array, descriptor: SourceDescriptor): LoadedSource {\n return this.loadWorkingCopy(this.wasm.decode(bytes), descriptor);\n }\n\n /** Accepts pixels decoded elsewhere, for example by a native decoder. Never resident. */\n loadWorkingCopy(workingCopy: RgbaBuffer, descriptor: SourceDescriptor): LoadedSource {\n this.full = null;\n this.icc = undefined;\n this.workingCopy = workingCopy;\n this.descriptor = descriptor;\n this.cache.clear();\n return {\n descriptor,\n resident: false,\n workingCopy: { ...workingCopy, data: new Uint8Array(workingCopy.data) },\n };\n }\n\n hasSource(): boolean {\n return this.descriptor !== null;\n }\n\n isResident(): boolean {\n return this.full !== null;\n }\n\n unload(): void {\n this.full = null;\n this.icc = undefined;\n this.workingCopy = null;\n this.descriptor = null;\n this.cache.clear();\n }\n\n /** Renders the log. Preview renders are split per stage and cached by prefix. */\n async render(req: RenderRequest): Promise<RgbaBuffer> {\n const { descriptor } = this.require();\n const image = req.target === 'full' ? this.full : this.workingCopy;\n if (!image) {\n throw new SealpixelError(\n 'SOURCE_MISMATCH',\n req.target === 'full'\n ? 'full-resolution pixels are not resident; render the original outside the browser'\n : 'no source loaded',\n );\n }\n const mode = req.target === 'full' ? 'truth' : 'preview';\n const doc = compile(req.log, this.registry, req.upTo);\n const logical = { width: descriptor.width, height: descriptor.height };\n const ctx: PlanContext = {\n logical,\n actual: { width: image.width, height: image.height },\n scale: image.width / logical.width,\n mode,\n };\n const stages = toPipeline(doc, this.registry, ctx);\n return this.runStages(stages, image, logical, mode, req.signal, mode === 'preview');\n }\n\n async export(req: ExportRequest): Promise<ExportResult> {\n const rendered = await this.render({\n log: req.log,\n target: 'full',\n ...(req.upTo === undefined ? {} : { upTo: req.upTo }),\n });\n const coreOutput = toCoreOutput(req.output);\n if (req.embedEditLog) {\n coreOutput['embed'] = canonicalJson({ log: req.log, index: req.upTo ?? req.log.ops.length });\n }\n const bytes = this.wasm.encode(rendered, JSON.stringify(coreOutput), this.icc);\n return {\n bytes,\n mimeType: req.output.format,\n width: rendered.width,\n height: rendered.height,\n hash: this.wasm.sha256Hex(bytes),\n };\n }\n\n geometry(log: EditLog, target: 'workingCopy' | 'full', upTo?: number): Geometry {\n const { descriptor } = this.require();\n const image = (target === 'full' ? this.full : this.workingCopy) ?? this.workingCopy;\n if (!image) throw new SealpixelError('SOURCE_MISMATCH', 'no source loaded');\n const logical = { width: descriptor.width, height: descriptor.height };\n const doc = compile(log, this.registry, upTo);\n const stages = toPipeline(doc, this.registry, {\n logical,\n actual: { width: image.width, height: image.height },\n scale: image.width / logical.width,\n mode: target === 'full' ? 'truth' : 'preview',\n });\n const core = stages.filter((s) => s.kind === 'core');\n const plan: RenderPlan = {\n version: PLAN_VERSION,\n source: logical,\n bufferScale: image.width / logical.width,\n stages: toCoreStages(core),\n };\n return JSON.parse(\n this.wasm.resolveGeometry(JSON.stringify(plan), image.width, image.height),\n ) as Geometry;\n }\n\n private require(): { descriptor: SourceDescriptor } {\n if (!this.descriptor) throw new SealpixelError('SOURCE_MISMATCH', 'no source loaded');\n return { descriptor: this.descriptor };\n }\n\n private async runStages(\n stages: PipelineStage[],\n image: RgbaBuffer,\n logical: { width: number; height: number },\n mode: 'truth' | 'preview',\n signal: AbortSignal | undefined,\n useCache: boolean,\n ): Promise<RgbaBuffer> {\n let current = image;\n let currentLogical = logical;\n let prefix = `${image.width}x${image.height}`;\n for (const stage of stages) {\n if (signal?.aborted) throw new SealpixelError('ABORTED', 'render aborted');\n prefix += `|${canonicalJson({ n: stage.name, p: stage.params })}`;\n const cached = useCache ? this.cache.get(prefix) : undefined;\n if (cached) {\n current = cached;\n currentLogical = this.logicalAfter(stage, currentLogical, current, image, logical);\n continue;\n }\n if (stage.kind === 'core') {\n const plan: RenderPlan = {\n version: PLAN_VERSION,\n source: currentLogical,\n bufferScale: current.width / currentLogical.width,\n stages: toCoreStages([stage]),\n };\n const planJson = JSON.stringify(plan);\n const geometry = JSON.parse(\n this.wasm.resolveGeometry(planJson, current.width, current.height),\n ) as Geometry;\n current = this.wasm.renderRgba(current, planJson);\n currentLogical = geometry.logicalOut;\n } else {\n const kctx: KernelContext = {\n logical: currentLogical,\n actual: { width: current.width, height: current.height },\n scale: current.width / currentLogical.width,\n mode,\n asset: (id) => {\n throw new SealpixelError(\n 'MISSING_ASSET',\n `asset \"${id}\" is not available to JS kernels yet`,\n { assetId: id },\n );\n },\n signal: signal ?? new AbortController().signal,\n };\n const out = await runExternalKernel(stage.plugin, current, stage.params, kctx);\n if (out.width !== current.width || out.height !== current.height) {\n currentLogical = {\n width: Math.round(currentLogical.width * (out.width / current.width)),\n height: Math.round(currentLogical.height * (out.height / current.height)),\n };\n }\n current = out;\n }\n if (useCache) this.remember(prefix, current);\n }\n return current;\n }\n\n /** Recomputes the logical size after a cached stage by asking the core for its geometry. */\n private logicalAfter(\n stage: PipelineStage,\n logicalIn: { width: number; height: number },\n out: RgbaBuffer,\n _image: RgbaBuffer,\n _sourceLogical: { width: number; height: number },\n ): { width: number; height: number } {\n if (stage.kind !== 'core') {\n return {\n width: Math.round(logicalIn.width * (out.width / out.width)),\n height: logicalIn.height,\n };\n }\n // The cached buffer already has the output size; the logical size is the\n // geometry of this single stage on a buffer with the input's logical size.\n const plan: RenderPlan = {\n version: PLAN_VERSION,\n source: logicalIn,\n bufferScale: 1,\n stages: toCoreStages([stage]),\n };\n const g = JSON.parse(\n this.wasm.resolveGeometry(JSON.stringify(plan), logicalIn.width, logicalIn.height),\n ) as Geometry;\n return g.logicalOut;\n }\n\n private remember(key: string, value: RgbaBuffer): void {\n const limit = this.options.cacheEntries ?? 6;\n if (this.cache.has(key)) this.cache.delete(key);\n this.cache.set(key, value);\n while (this.cache.size > limit) {\n const oldest = this.cache.keys().next().value;\n if (oldest === undefined) break;\n this.cache.delete(oldest);\n }\n }\n\n /** For tests: number of cached stage outputs. */\n cacheSize(): number {\n return this.cache.size;\n }\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -98,6 +98,19 @@ export interface RenderOptions {
98
98
  * text the user does not want to ship.
99
99
  */
100
100
  embedEditLog?: boolean;
101
+ /**
102
+ * Also return a render manifest: the source hash, the edit log, the plan,
103
+ * this renderer's identity and the hash of the rendered pixels. Off by
104
+ * default, because the pixel hash reads the whole rendered buffer once.
105
+ */
106
+ manifest?: boolean;
107
+ /**
108
+ * sha256 of the original's bytes, for the manifest, when `source` is a
109
+ * buffer that was decoded elsewhere. Required then, because the log's
110
+ * `source.hash` is a claim about bytes this call never sees. Ignored when
111
+ * `source` is bytes, which are hashed here.
112
+ */
113
+ sourceHash?: string;
101
114
  }
102
115
  export interface RenderResult {
103
116
  /** Backed by a plain `ArrayBuffer`, so it is a `BlobPart`. */
@@ -110,5 +123,7 @@ export interface RenderResult {
110
123
  /** Version of the core that produced the bytes. */
111
124
  coreVersion: string;
112
125
  timings: Record<string, number>;
126
+ /** Present when `manifest: true` was asked for. */
127
+ manifest?: import('./manifest.js').RenderManifest;
113
128
  }
114
129
  export type RenderSource = Uint8Array | RgbaBuffer;
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { RgbaBuffer } from '@sealpixel/wasm';\n\nexport type { DecodedImage, RgbaBuffer, SealpixelWasm } from '@sealpixel/wasm';\n\n/** Normalised coordinate in 0..1. */\nexport type Unit = number;\n/** Length in pixels of the logical, full-resolution stage. */\nexport type SourcePx = number;\nexport type Radians = number;\n\nexport interface Point {\n x: Unit;\n y: Unit;\n}\nexport interface Rect {\n x: Unit;\n y: Unit;\n width: Unit;\n height: Unit;\n}\n/** sRGB colour with straight alpha, each channel 0..1. */\nexport type Color = [r: number, g: number, b: number, a: number];\n\n/** Identity and logical dimensions of the original image after EXIF orientation. */\nexport interface SourceDescriptor {\n id: string;\n width: number;\n height: number;\n /** sha256 of the original bytes. The server verifies it before rendering. */\n hash?: string;\n mimeType?: string;\n}\n\n/** Augmented by plugins via `declare module '@sealpixel/core'`. */\n// biome-ignore lint/suspicious/noEmptyInterface: augmentation target\nexport interface OperationRegistry {}\nexport type OperationType = keyof OperationRegistry & string;\n/**\n * Union of every registered operation. Falls back to the bare base shape when\n * no plugin has augmented the registry (for example inside `@sealpixel/core`'s\n * own tests), so generic code can still read `type` and `id`.\n */\nexport type Operation = [OperationType] extends [never]\n ? OperationBase<string>\n : OperationRegistry[OperationType];\n\nexport interface OperationBase<T extends string> {\n type: T;\n /** Unique per log entry. Ignored by the renderer. */\n id: string;\n /** Wall-clock timestamp. Ignored by the renderer. */\n at?: number | undefined;\n}\n\n/** The only state of an editing session. Serialisable as JSON. */\nexport interface EditLog {\n version: 1;\n source: SourceDescriptor;\n /** Plugin id to plugin version, for migrations. */\n plugins: Record<string, number>;\n /**\n * Assets the ops reference that are not declared by a plugin (for example\n * an uploaded sticker). Hosts must make `url` reachable for other devices\n * and the server.\n */\n assets?: import('./plugin.js').AssetDeclaration[];\n ops: Operation[];\n}\n\n/** Undo/redo position over an edit log: `ops[0..index)` is the current state. */\nexport interface History {\n log: EditLog;\n index: number;\n}\n\nexport type OutputFormat = 'image/png' | 'image/jpeg' | 'image/webp';\n\nexport interface OutputOptions {\n format: OutputFormat;\n /** 0..1, lossy formats only. Default 0.9. */\n quality?: number;\n /** JPEG only. Default false. */\n progressive?: boolean;\n /** JPEG only. Default '4:2:0'. */\n chromaSubsampling?: '4:2:0' | '4:4:4';\n /** WebP only. V1 always encodes lossless. */\n lossless?: boolean;\n /** Opaque colour that alpha is flattened onto for JPEG, 0..255 each. Default white. */\n background?: [r: number, g: number, b: number];\n}\n\nexport interface RenderOptions {\n output: OutputOptions;\n /**\n * `truth` (default) requires the buffer to have the logical source\n * dimensions. `preview` accepts a working copy and scales lengths accordingly.\n */\n mode?: 'truth' | 'preview';\n /** Render only `ops[0..upTo)`. Defaults to all ops. */\n upTo?: number;\n signal?: AbortSignal;\n /** Pre-loaded core. Servers pass this to reuse one instance across requests. */\n wasm?: import('@sealpixel/wasm').SealpixelWasm;\n /** Plugins that interpret the log's ops. Required when the log has ops. */\n registry?: import('./registry.js').Registry;\n /** Supplies fonts and images referenced by the log. */\n assets?: import('./assets.js').AssetResolver;\n /**\n * Store `canonicalJson({ log, index })` in the file's metadata so it can be\n * reopened with `readEmbeddedState`. Off by default: the log may contain\n * text the user does not want to ship.\n */\n embedEditLog?: boolean;\n}\n\nexport interface RenderResult {\n /** Backed by a plain `ArrayBuffer`, so it is a `BlobPart`. */\n bytes: Uint8Array<ArrayBuffer>;\n mimeType: OutputFormat;\n width: number;\n height: number;\n /** sha256 of `bytes`, computed inside the core. */\n hash: string;\n /** Version of the core that produced the bytes. */\n coreVersion: string;\n timings: Record<string, number>;\n}\n\nexport type RenderSource = Uint8Array | RgbaBuffer;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { RgbaBuffer } from '@sealpixel/wasm';\n\nexport type { DecodedImage, RgbaBuffer, SealpixelWasm } from '@sealpixel/wasm';\n\n/** Normalised coordinate in 0..1. */\nexport type Unit = number;\n/** Length in pixels of the logical, full-resolution stage. */\nexport type SourcePx = number;\nexport type Radians = number;\n\nexport interface Point {\n x: Unit;\n y: Unit;\n}\nexport interface Rect {\n x: Unit;\n y: Unit;\n width: Unit;\n height: Unit;\n}\n/** sRGB colour with straight alpha, each channel 0..1. */\nexport type Color = [r: number, g: number, b: number, a: number];\n\n/** Identity and logical dimensions of the original image after EXIF orientation. */\nexport interface SourceDescriptor {\n id: string;\n width: number;\n height: number;\n /** sha256 of the original bytes. The server verifies it before rendering. */\n hash?: string;\n mimeType?: string;\n}\n\n/** Augmented by plugins via `declare module '@sealpixel/core'`. */\n// biome-ignore lint/suspicious/noEmptyInterface: augmentation target\nexport interface OperationRegistry {}\nexport type OperationType = keyof OperationRegistry & string;\n/**\n * Union of every registered operation. Falls back to the bare base shape when\n * no plugin has augmented the registry (for example inside `@sealpixel/core`'s\n * own tests), so generic code can still read `type` and `id`.\n */\nexport type Operation = [OperationType] extends [never]\n ? OperationBase<string>\n : OperationRegistry[OperationType];\n\nexport interface OperationBase<T extends string> {\n type: T;\n /** Unique per log entry. Ignored by the renderer. */\n id: string;\n /** Wall-clock timestamp. Ignored by the renderer. */\n at?: number | undefined;\n}\n\n/** The only state of an editing session. Serialisable as JSON. */\nexport interface EditLog {\n version: 1;\n source: SourceDescriptor;\n /** Plugin id to plugin version, for migrations. */\n plugins: Record<string, number>;\n /**\n * Assets the ops reference that are not declared by a plugin (for example\n * an uploaded sticker). Hosts must make `url` reachable for other devices\n * and the server.\n */\n assets?: import('./plugin.js').AssetDeclaration[];\n ops: Operation[];\n}\n\n/** Undo/redo position over an edit log: `ops[0..index)` is the current state. */\nexport interface History {\n log: EditLog;\n index: number;\n}\n\nexport type OutputFormat = 'image/png' | 'image/jpeg' | 'image/webp';\n\nexport interface OutputOptions {\n format: OutputFormat;\n /** 0..1, lossy formats only. Default 0.9. */\n quality?: number;\n /** JPEG only. Default false. */\n progressive?: boolean;\n /** JPEG only. Default '4:2:0'. */\n chromaSubsampling?: '4:2:0' | '4:4:4';\n /** WebP only. V1 always encodes lossless. */\n lossless?: boolean;\n /** Opaque colour that alpha is flattened onto for JPEG, 0..255 each. Default white. */\n background?: [r: number, g: number, b: number];\n}\n\nexport interface RenderOptions {\n output: OutputOptions;\n /**\n * `truth` (default) requires the buffer to have the logical source\n * dimensions. `preview` accepts a working copy and scales lengths accordingly.\n */\n mode?: 'truth' | 'preview';\n /** Render only `ops[0..upTo)`. Defaults to all ops. */\n upTo?: number;\n signal?: AbortSignal;\n /** Pre-loaded core. Servers pass this to reuse one instance across requests. */\n wasm?: import('@sealpixel/wasm').SealpixelWasm;\n /** Plugins that interpret the log's ops. Required when the log has ops. */\n registry?: import('./registry.js').Registry;\n /** Supplies fonts and images referenced by the log. */\n assets?: import('./assets.js').AssetResolver;\n /**\n * Store `canonicalJson({ log, index })` in the file's metadata so it can be\n * reopened with `readEmbeddedState`. Off by default: the log may contain\n * text the user does not want to ship.\n */\n embedEditLog?: boolean;\n /**\n * Also return a render manifest: the source hash, the edit log, the plan,\n * this renderer's identity and the hash of the rendered pixels. Off by\n * default, because the pixel hash reads the whole rendered buffer once.\n */\n manifest?: boolean;\n /**\n * sha256 of the original's bytes, for the manifest, when `source` is a\n * buffer that was decoded elsewhere. Required then, because the log's\n * `source.hash` is a claim about bytes this call never sees. Ignored when\n * `source` is bytes, which are hashed here.\n */\n sourceHash?: string;\n}\n\nexport interface RenderResult {\n /** Backed by a plain `ArrayBuffer`, so it is a `BlobPart`. */\n bytes: Uint8Array<ArrayBuffer>;\n mimeType: OutputFormat;\n width: number;\n height: number;\n /** sha256 of `bytes`, computed inside the core. */\n hash: string;\n /** Version of the core that produced the bytes. */\n coreVersion: string;\n timings: Record<string, number>;\n /** Present when `manifest: true` was asked for. */\n manifest?: import('./manifest.js').RenderManifest;\n}\n\nexport type RenderSource = Uint8Array | RgbaBuffer;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealpixel/core",
3
- "version": "1.0.0-rc.15",
3
+ "version": "1.0.0-rc.19",
4
4
  "description": "Sealpixel headless core: edit log types, compile(), render(), editor session. Runtime-agnostic.",
5
5
  "license": "BUSL-1.1",
6
6
  "repository": {
@@ -28,7 +28,7 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@sealpixel/wasm": "1.0.0-rc.15",
31
+ "@sealpixel/wasm": "1.0.0-rc.19",
32
32
  "zod": "^4.0.0"
33
33
  },
34
34
  "devDependencies": {