@elastic/isomer-image-takumi 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.txt +0 -1571
- package/README.md +17 -6
- package/THIRD_PARTY_LICENSES.md +1 -933
- package/dist/backend.d.ts +30 -17
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +18 -8
- package/dist/backend.js.map +1 -1
- package/dist/cjs/backend.js +19 -9
- package/dist/cjs/backend.js.map +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/render_pdf.js +3 -3
- package/dist/cjs/render_pdf.js.map +1 -1
- package/dist/cjs/render_png.js +3 -3
- package/dist/cjs/render_png.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/render_pdf.d.ts +6 -6
- package/dist/render_pdf.d.ts.map +1 -1
- package/dist/render_pdf.js +3 -3
- package/dist/render_pdf.js.map +1 -1
- package/dist/render_png.d.ts +12 -11
- package/dist/render_png.d.ts.map +1 -1
- package/dist/render_png.js +3 -3
- package/dist/render_png.js.map +1 -1
- package/package.json +2 -6
package/dist/render_pdf.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PdfInput, TakumiPdfBackend, TakumiPdfOptions } from './backend.js';
|
|
2
|
-
import { type PngCheckedValidationResult, type
|
|
2
|
+
import { type PngCheckedValidationResult, type PngValidationResult, type SnapshotOptions } from './render_png.js';
|
|
3
3
|
/**
|
|
4
4
|
* The slice of `IsomerRuntime` this helper needs, declared structurally like
|
|
5
5
|
* {@link PdfInput}. A runtime built with `frames` satisfies it.
|
|
@@ -7,8 +7,8 @@ import { type PngCheckedValidationResult, type PngSvgOptions, type PngValidation
|
|
|
7
7
|
export interface PdfRuntime {
|
|
8
8
|
validate(composition: unknown): PngCheckedValidationResult;
|
|
9
9
|
surfaces: {
|
|
10
|
-
|
|
11
|
-
renderPages(compositions: readonly unknown[], options?:
|
|
10
|
+
snapshot: {
|
|
11
|
+
renderPages(compositions: readonly unknown[], options?: SnapshotOptions & {
|
|
12
12
|
onValidationError?: 'collect' | 'throw';
|
|
13
13
|
}): PdfInput;
|
|
14
14
|
};
|
|
@@ -16,8 +16,8 @@ export interface PdfRuntime {
|
|
|
16
16
|
}
|
|
17
17
|
/** Options for {@link renderPdf}. */
|
|
18
18
|
export interface RenderPdfOptions extends TakumiPdfOptions {
|
|
19
|
-
/** Forwarded to `runtime.surfaces.
|
|
20
|
-
|
|
19
|
+
/** Forwarded to `runtime.surfaces.snapshot.renderPages`, so every page shares one frame. */
|
|
20
|
+
snapshot?: SnapshotOptions;
|
|
21
21
|
}
|
|
22
22
|
/** What {@link renderPdf} resolves to: the bytes, the page count and size, and one finding set per composition. */
|
|
23
23
|
export interface RenderPdfResult {
|
|
@@ -38,5 +38,5 @@ export interface RenderPdfResult {
|
|
|
38
38
|
* `renderPages`, which discards its own result. An empty deck throws the
|
|
39
39
|
* runtime's `EMPTY_PAGES`.
|
|
40
40
|
*/
|
|
41
|
-
export declare const renderPdf: (runtime: PdfRuntime, deck: readonly unknown[], backend: TakumiPdfBackend, {
|
|
41
|
+
export declare const renderPdf: (runtime: PdfRuntime, deck: readonly unknown[], backend: TakumiPdfBackend, { snapshot, ...options }?: RenderPdfOptions) => Promise<RenderPdfResult>;
|
|
42
42
|
//# sourceMappingURL=render_pdf.d.ts.map
|
package/dist/render_pdf.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render_pdf.d.ts","sourceRoot":"","sources":["../src/render_pdf.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,
|
|
1
|
+
{"version":3,"file":"render_pdf.d.ts","sourceRoot":"","sources":["../src/render_pdf.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,WAAW,EAAE,OAAO,GAAG,0BAA0B,CAAC;IAC3D,QAAQ,EAAE;QACR,QAAQ,EAAE;YACR,WAAW,CACT,YAAY,EAAE,SAAS,OAAO,EAAE,EAChC,OAAO,CAAC,EAAE,eAAe,GAAG;gBAAE,iBAAiB,CAAC,EAAE,SAAS,GAAG,OAAO,CAAA;aAAE,GACtE,QAAQ,CAAC;SACb,CAAC;KACH,CAAC;CACH;AAED,qCAAqC;AACrC,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED,mHAAmH;AACnH,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,WAAW,EAAE,mBAAmB,EAAE,CAAC;CACpC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,GACpB,SAAS,UAAU,EACnB,MAAM,SAAS,OAAO,EAAE,EACxB,SAAS,gBAAgB,EACzB,2BAA0B,gBAAqB,KAC9C,OAAO,CAAC,eAAe,CAoBzB,CAAC"}
|
package/dist/render_pdf.js
CHANGED
|
@@ -15,11 +15,11 @@ import { checkedForDrawing, } from './render_png.js';
|
|
|
15
15
|
* `renderPages`, which discards its own result. An empty deck throws the
|
|
16
16
|
* runtime's `EMPTY_PAGES`.
|
|
17
17
|
*/
|
|
18
|
-
export const renderPdf = async (runtime, deck, backend, {
|
|
18
|
+
export const renderPdf = async (runtime, deck, backend, { snapshot, ...options } = {}) => {
|
|
19
19
|
const pages = deck.map((composition) => checkedForDrawing('renderPdf', runtime.validate(composition)));
|
|
20
20
|
const validations = pages.map(({ validation }) => validation);
|
|
21
|
-
const rendered = runtime.surfaces.
|
|
22
|
-
...
|
|
21
|
+
const rendered = runtime.surfaces.snapshot.renderPages(pages.map(({ checked }) => checked), {
|
|
22
|
+
...snapshot,
|
|
23
23
|
onValidationError: 'collect',
|
|
24
24
|
});
|
|
25
25
|
const pdf = await backend.pdf(rendered, options);
|
package/dist/render_pdf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render_pdf.js","sourceRoot":"","sources":["../src/render_pdf.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,iBAAiB,GAIlB,MAAM,cAAc,CAAC;AAkCtB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,OAAmB,EACnB,IAAwB,EACxB,OAAyB,EACzB,EAAE,
|
|
1
|
+
{"version":3,"file":"render_pdf.js","sourceRoot":"","sources":["../src/render_pdf.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,iBAAiB,GAIlB,MAAM,cAAc,CAAC;AAkCtB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,OAAmB,EACnB,IAAwB,EACxB,OAAyB,EACzB,EAAE,QAAQ,EAAE,GAAG,OAAO,KAAuB,EAAE,EACrB,EAAE;IAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CACrC,iBAAiB,CAAC,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAC9D,CAAC;IACF,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC;IAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CACpD,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,EACnC;QACE,GAAG,QAAQ;QACX,iBAAiB,EAAE,SAAS;KAC7B,CACF,CAAC;IACF,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,OAAO;QACL,GAAG;QACH,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM;QAChC,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,WAAW;KACZ,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { PdfInput, TakumiPdfBackend, TakumiPdfOptions } from './backend';\nimport {\n checkedForDrawing,\n type PngCheckedValidationResult,\n type PngValidationResult,\n type SnapshotOptions,\n} from './render_png';\n\n/**\n * The slice of `IsomerRuntime` this helper needs, declared structurally like\n * {@link PdfInput}. A runtime built with `frames` satisfies it.\n */\nexport interface PdfRuntime {\n validate(composition: unknown): PngCheckedValidationResult;\n surfaces: {\n snapshot: {\n renderPages(\n compositions: readonly unknown[],\n options?: SnapshotOptions & { onValidationError?: 'collect' | 'throw' }\n ): PdfInput;\n };\n };\n}\n\n/** Options for {@link renderPdf}. */\nexport interface RenderPdfOptions extends TakumiPdfOptions {\n /** Forwarded to `runtime.surfaces.snapshot.renderPages`, so every page shares one frame. */\n snapshot?: SnapshotOptions;\n}\n\n/** What {@link renderPdf} resolves to: the bytes, the page count and size, and one finding set per composition. */\nexport interface RenderPdfResult {\n pdf: Buffer;\n pageCount: number;\n width: number;\n height: number;\n /** One per composition, in order. */\n validations: PngValidationResult[];\n}\n\n/**\n * Validates, renders, and writes a deck as one PDF in one call, a page per\n * composition.\n *\n * Every composition is rendered, even an invalid one: `validations` is how a\n * caller finds out, rather than a thrown error. What is drawn is the copy\n * validation checked. Validation runs twice, once here and once inside\n * `renderPages`, which discards its own result. An empty deck throws the\n * runtime's `EMPTY_PAGES`.\n */\nexport const renderPdf = async (\n runtime: PdfRuntime,\n deck: readonly unknown[],\n backend: TakumiPdfBackend,\n { snapshot, ...options }: RenderPdfOptions = {}\n): Promise<RenderPdfResult> => {\n const pages = deck.map((composition) =>\n checkedForDrawing('renderPdf', runtime.validate(composition))\n );\n const validations = pages.map(({ validation }) => validation);\n const rendered = runtime.surfaces.snapshot.renderPages(\n pages.map(({ checked }) => checked),\n {\n ...snapshot,\n onValidationError: 'collect',\n }\n );\n const pdf = await backend.pdf(rendered, options);\n return {\n pdf,\n pageCount: rendered.pages.length,\n width: rendered.width,\n height: rendered.height,\n validations,\n };\n};\n"]}
|
package/dist/render_png.d.ts
CHANGED
|
@@ -20,10 +20,10 @@ export declare const checkedForDrawing: (caller: string, { composition, ...valid
|
|
|
20
20
|
validation: PngValidationResult;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
* The `
|
|
24
|
-
* `
|
|
23
|
+
* The `snapshot` surface's per-render options, mirroring the runtime's
|
|
24
|
+
* `SnapshotRenderOptions` so a caller gets completion without importing it.
|
|
25
25
|
*/
|
|
26
|
-
export interface
|
|
26
|
+
export interface SnapshotOptions {
|
|
27
27
|
/** Which of the runtime's frames this render uses; defaults to its `defaultFrame`. */
|
|
28
28
|
frame?: string;
|
|
29
29
|
/** Overrides the frame's `defaultWidth`. */
|
|
@@ -35,15 +35,15 @@ export interface PngSvgOptions {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* The slice of `IsomerRuntime` this helper needs, declared structurally like
|
|
38
|
-
* {@link ImageInput} so this package depends on no isomer package. `surfaces.
|
|
39
|
-
* is required where the runtime's generic form has `
|
|
40
|
-
* runtime built with `frames` carries `
|
|
38
|
+
* {@link ImageInput} so this package depends on no isomer package. `surfaces.snapshot`
|
|
39
|
+
* is required where the runtime's generic form has `SnapshotSurface | undefined`; a
|
|
40
|
+
* runtime built with `frames` carries `SnapshotSurface` there and satisfies this.
|
|
41
41
|
*/
|
|
42
42
|
export interface PngRuntime {
|
|
43
43
|
validate(composition: unknown): PngCheckedValidationResult;
|
|
44
44
|
surfaces: {
|
|
45
|
-
|
|
46
|
-
render(composition: unknown, options?:
|
|
45
|
+
snapshot: {
|
|
46
|
+
render(composition: unknown, options?: SnapshotOptions & {
|
|
47
47
|
onValidationError?: 'collect' | 'throw';
|
|
48
48
|
}): ImageInput;
|
|
49
49
|
};
|
|
@@ -51,12 +51,13 @@ export interface PngRuntime {
|
|
|
51
51
|
}
|
|
52
52
|
/** Options for {@link renderPng}. */
|
|
53
53
|
export interface RenderPngOptions extends TakumiRenderOptions {
|
|
54
|
-
/** Forwarded to `runtime.surfaces.
|
|
55
|
-
|
|
54
|
+
/** Forwarded to `runtime.surfaces.snapshot.render`. */
|
|
55
|
+
snapshot?: SnapshotOptions;
|
|
56
56
|
}
|
|
57
57
|
/** What {@link renderPng} resolves to: the bytes, their size, and the findings on the composition drawn. */
|
|
58
58
|
export interface RenderPngResult {
|
|
59
59
|
png: Buffer;
|
|
60
|
+
/** The viewport, in CSS pixels; the raster is this times `scale`, rounded. */
|
|
60
61
|
width: number;
|
|
61
62
|
height: number;
|
|
62
63
|
validation: PngValidationResult;
|
|
@@ -70,5 +71,5 @@ export interface RenderPngResult {
|
|
|
70
71
|
* `CompositionValidationError`. Validation runs twice, once here and once inside `render`, which
|
|
71
72
|
* discards its own result.
|
|
72
73
|
*/
|
|
73
|
-
export declare const renderPng: (runtime: PngRuntime, composition: unknown, backend: TakumiImageBackend, {
|
|
74
|
+
export declare const renderPng: (runtime: PngRuntime, composition: unknown, backend: TakumiImageBackend, { snapshot, ...options }?: RenderPngOptions) => Promise<RenderPngResult>;
|
|
74
75
|
//# sourceMappingURL=render_png.d.ts.map
|
package/dist/render_png.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render_png.d.ts","sourceRoot":"","sources":["../src/render_png.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,WAAW,CAAC;AAEnB,2FAA2F;AAC3F,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;CAC5B;AAED,iHAAiH;AACjH,MAAM,MAAM,0BAA0B,GAAG,mBAAmB,GAAG;IAC7D,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,EACd,gCAAgC,0BAA0B,KACzD;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,mBAAmB,CAAA;CAiBrD,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"render_png.d.ts","sourceRoot":"","sources":["../src/render_png.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,WAAW,CAAC;AAEnB,2FAA2F;AAC3F,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;CAC5B;AAED,iHAAiH;AACjH,MAAM,MAAM,0BAA0B,GAAG,mBAAmB,GAAG;IAC7D,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,EACd,gCAAgC,0BAA0B,KACzD;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,mBAAmB,CAAA;CAiBrD,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,sFAAsF;IACtF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sFAAsF;IACtF,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;CACnC;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,WAAW,EAAE,OAAO,GAAG,0BAA0B,CAAC;IAC3D,QAAQ,EAAE;QACR,QAAQ,EAAE;YACR,MAAM,CACJ,WAAW,EAAE,OAAO,EACpB,OAAO,CAAC,EAAE,eAAe,GAAG;gBAAE,iBAAiB,CAAC,EAAE,SAAS,GAAG,OAAO,CAAA;aAAE,GACtE,UAAU,CAAC;SACf,CAAC;KACH,CAAC;CACH;AAED,qCAAqC;AACrC,MAAM,WAAW,gBAAiB,SAAQ,mBAAmB;IAC3D,uDAAuD;IACvD,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED,4GAA4G;AAC5G,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,mBAAmB,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GACpB,SAAS,UAAU,EACnB,aAAa,OAAO,EACpB,SAAS,kBAAkB,EAC3B,2BAA0B,gBAAqB,KAC9C,OAAO,CAAC,eAAe,CAWzB,CAAC"}
|
package/dist/render_png.js
CHANGED
|
@@ -33,10 +33,10 @@ export const checkedForDrawing = (caller, { composition, ...validation }) => {
|
|
|
33
33
|
* `CompositionValidationError`. Validation runs twice, once here and once inside `render`, which
|
|
34
34
|
* discards its own result.
|
|
35
35
|
*/
|
|
36
|
-
export const renderPng = async (runtime, composition, backend, {
|
|
36
|
+
export const renderPng = async (runtime, composition, backend, { snapshot, ...options } = {}) => {
|
|
37
37
|
const { checked, validation } = checkedForDrawing('renderPng', runtime.validate(composition));
|
|
38
|
-
const rendered = runtime.surfaces.
|
|
39
|
-
...
|
|
38
|
+
const rendered = runtime.surfaces.snapshot.render(checked, {
|
|
39
|
+
...snapshot,
|
|
40
40
|
onValidationError: 'collect',
|
|
41
41
|
});
|
|
42
42
|
const png = await backend.png(rendered, options);
|
package/dist/render_png.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render_png.js","sourceRoot":"","sources":["../src/render_png.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAmBH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,EAAE,WAAW,EAAE,GAAG,UAAU,EAA8B,EACH,EAAE;IACzD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;IAC9C,CAAC;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,4DAA4D,CACtE,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,CAAC,MAAM,CACjB,IAAI,KAAK,CAAC,GAAG,MAAM,sDAAsD,CAAC,EAC1E;QACE,IAAI,EAAE,4BAA4B;QAClC,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE,UAAU,CAAC,MAAM;KAC1B,CACF,CAAC;AACJ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"render_png.js","sourceRoot":"","sources":["../src/render_png.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAmBH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,EAAE,WAAW,EAAE,GAAG,UAAU,EAA8B,EACH,EAAE;IACzD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;IAC9C,CAAC;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,4DAA4D,CACtE,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,CAAC,MAAM,CACjB,IAAI,KAAK,CAAC,GAAG,MAAM,sDAAsD,CAAC,EAC1E;QACE,IAAI,EAAE,4BAA4B;QAClC,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE,UAAU,CAAC,MAAM;KAC1B,CACF,CAAC;AACJ,CAAC,CAAC;AAkDF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,OAAmB,EACnB,WAAoB,EACpB,OAA2B,EAC3B,EAAE,QAAQ,EAAE,GAAG,OAAO,KAAuB,EAAE,EACrB,EAAE;IAC5B,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,iBAAiB,CAC/C,WAAW,EACX,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAC9B,CAAC;IACF,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE;QACzD,GAAG,QAAQ;QACX,iBAAiB,EAAE,SAAS;KAC7B,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;AAC7E,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type {\n ImageInput,\n TakumiImageBackend,\n TakumiRenderOptions,\n} from './backend';\n\n/** A validation result shaped like the SDK's `ValidationResult`, declared structurally. */\nexport interface PngValidationResult {\n valid: boolean;\n errors: readonly unknown[];\n}\n\n/** What `runtime.validate` returns: findings, and the copy they describe, `undefined` only for refused input. */\nexport type PngCheckedValidationResult = PngValidationResult & {\n composition: unknown;\n};\n\n/**\n * Splits a {@link PngCheckedValidationResult} into the copy to draw and the findings to report.\n *\n * Throws rather than draw the caller's value: shaped as the SDK's\n * `CompositionValidationError` when the runtime refused the input, and a plain\n * `Error` when the runtime returned no copy at all.\n */\nexport const checkedForDrawing = (\n caller: string,\n { composition, ...validation }: PngCheckedValidationResult\n): { checked: unknown; validation: PngValidationResult } => {\n if (composition !== undefined) {\n return { checked: composition, validation };\n }\n if (validation.valid) {\n throw new Error(\n `${caller}: runtime.validate returned no checked composition to draw`\n );\n }\n throw Object.assign(\n new Error(`${caller}: the runtime refused the composition before parsing`),\n {\n name: 'CompositionValidationError',\n code: 'COMPOSITION_INVALID',\n errors: validation.errors,\n }\n );\n};\n\n/**\n * The `snapshot` surface's per-render options, mirroring the runtime's\n * `SnapshotRenderOptions` so a caller gets completion without importing it.\n */\nexport interface SnapshotOptions {\n /** Which of the runtime's frames this render uses; defaults to its `defaultFrame`. */\n frame?: string;\n /** Overrides the frame's `defaultWidth`. */\n width?: number;\n /** Overrides the frame's estimated height. */\n height?: number;\n /** Theme mode; falls back to the composition's own `theme`. `auto` resolves light. */\n theme?: 'light' | 'dark' | 'auto';\n}\n\n/**\n * The slice of `IsomerRuntime` this helper needs, declared structurally like\n * {@link ImageInput} so this package depends on no isomer package. `surfaces.snapshot`\n * is required where the runtime's generic form has `SnapshotSurface | undefined`; a\n * runtime built with `frames` carries `SnapshotSurface` there and satisfies this.\n */\nexport interface PngRuntime {\n validate(composition: unknown): PngCheckedValidationResult;\n surfaces: {\n snapshot: {\n render(\n composition: unknown,\n options?: SnapshotOptions & { onValidationError?: 'collect' | 'throw' }\n ): ImageInput;\n };\n };\n}\n\n/** Options for {@link renderPng}. */\nexport interface RenderPngOptions extends TakumiRenderOptions {\n /** Forwarded to `runtime.surfaces.snapshot.render`. */\n snapshot?: SnapshotOptions;\n}\n\n/** What {@link renderPng} resolves to: the bytes, their size, and the findings on the composition drawn. */\nexport interface RenderPngResult {\n png: Buffer;\n /** The viewport, in CSS pixels; the raster is this times `scale`, rounded. */\n width: number;\n height: number;\n validation: PngValidationResult;\n}\n\n/**\n * Validates, renders, and rasterizes a composition in one call.\n *\n * The composition is rendered even when invalid: `validation` is how a caller\n * finds out, rather than a thrown error. What is drawn is the copy validation\n * checked, and input refused before parsing, which has none, throws\n * `CompositionValidationError`. Validation runs twice, once here and once inside `render`, which\n * discards its own result.\n */\nexport const renderPng = async (\n runtime: PngRuntime,\n composition: unknown,\n backend: TakumiImageBackend,\n { snapshot, ...options }: RenderPngOptions = {}\n): Promise<RenderPngResult> => {\n const { checked, validation } = checkedForDrawing(\n 'renderPng',\n runtime.validate(composition)\n );\n const rendered = runtime.surfaces.snapshot.render(checked, {\n ...snapshot,\n onValidationError: 'collect',\n });\n const png = await backend.png(rendered, options);\n return { png, width: rendered.width, height: rendered.height, validation };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elastic/isomer-image-takumi",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Takumi image backend for Isomer: rasterizes the
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Takumi image backend for Isomer: rasterizes the snapshot surface's output to PNG, SVG, or PDF.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"author": "Elastic",
|
|
7
7
|
"repository": {
|
|
@@ -32,10 +32,6 @@
|
|
|
32
32
|
"@takumi-rs/helpers": "2.14.0",
|
|
33
33
|
"takumi-pdf": "0.15.0"
|
|
34
34
|
},
|
|
35
|
-
"peerDependencies": {
|
|
36
|
-
"react": ">=18 <20",
|
|
37
|
-
"react-dom": ">=18 <20"
|
|
38
|
-
},
|
|
39
35
|
"devDependencies": {
|
|
40
36
|
"@fontsource/inter": "^5.3.0",
|
|
41
37
|
"@types/react": "^18.2.14",
|