@formepdf/svelte 0.14.0 → 0.16.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/dist/components/AreaChart.svelte +1 -1
- package/dist/components/BarChart.svelte +1 -1
- package/dist/components/Barcode.svelte +1 -1
- package/dist/components/Canvas.svelte +1 -1
- package/dist/components/Cell.svelte +1 -1
- package/dist/components/Checkbox.svelte +1 -1
- package/dist/components/Code.svelte +1 -1
- package/dist/components/Document.svelte +2 -2
- package/dist/components/Document.svelte.d.ts +1 -1
- package/dist/components/DotPlot.svelte +1 -1
- package/dist/components/Dropdown.svelte +1 -1
- package/dist/components/Em.svelte +1 -1
- package/dist/components/Fixed.svelte +1 -1
- package/dist/components/H1.svelte +1 -1
- package/dist/components/H2.svelte +1 -1
- package/dist/components/H3.svelte +1 -1
- package/dist/components/H4.svelte +1 -1
- package/dist/components/H5.svelte +1 -1
- package/dist/components/H6.svelte +1 -1
- package/dist/components/Image.svelte +1 -1
- package/dist/components/LineChart.svelte +1 -1
- package/dist/components/Link.svelte +1 -1
- package/dist/components/ListItem.svelte +1 -1
- package/dist/components/OrderedList.svelte +1 -1
- package/dist/components/Page.svelte +1 -1
- package/dist/components/PieChart.svelte +1 -1
- package/dist/components/QrCode.svelte +1 -1
- package/dist/components/RadioButton.svelte +1 -1
- package/dist/components/Row.svelte +1 -1
- package/dist/components/Strong.svelte +1 -1
- package/dist/components/Svg.svelte +1 -1
- package/dist/components/Table.svelte +1 -1
- package/dist/components/Text.svelte +1 -1
- package/dist/components/TextField.svelte +1 -1
- package/dist/components/UnorderedList.svelte +1 -1
- package/dist/components/View.svelte +1 -1
- package/dist/components/Watermark.svelte +1 -1
- package/dist/serialize.js +1 -1
- package/package.json +6 -6
- package/dist/encode.d.ts +0 -27
- package/dist/encode.js +0 -93
- package/dist/parser.d.ts +0 -30
- package/dist/parser.js +0 -756
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { CanvasContext, Style } from '@formepdf/shared';
|
|
3
3
|
import { recordCanvasOperations } from '@formepdf/shared';
|
|
4
|
-
import { encodeProps } from '
|
|
4
|
+
import { encodeProps } from '@formepdf/shared';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
/** Canvas width in points. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { CertificationConfig, FontRegistration, Style } from '@formepdf/shared';
|
|
4
|
-
import { encodeProps } from '
|
|
4
|
+
import { encodeProps } from '@formepdf/shared';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
title?: string;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
/** Whether to produce a tagged (accessible) PDF with structure tree. */
|
|
16
16
|
tagged?: boolean;
|
|
17
17
|
/** PDF/A conformance level. "2a" requires tagging, "2b" is visual-only compliance. */
|
|
18
|
-
pdfa?: '2a' | '2b';
|
|
18
|
+
pdfa?: '2a' | '2b' | '2u';
|
|
19
19
|
/** When true, the PDF claims PDF/UA-1 conformance. Forces tagging. */
|
|
20
20
|
pdfUa?: boolean;
|
|
21
21
|
/** Digital certification configuration. Certifies the PDF with an X.509 certificate. */
|
|
@@ -12,7 +12,7 @@ interface Props {
|
|
|
12
12
|
/** Whether to produce a tagged (accessible) PDF with structure tree. */
|
|
13
13
|
tagged?: boolean;
|
|
14
14
|
/** PDF/A conformance level. "2a" requires tagging, "2b" is visual-only compliance. */
|
|
15
|
-
pdfa?: '2a' | '2b';
|
|
15
|
+
pdfa?: '2a' | '2b' | '2u';
|
|
16
16
|
/** When true, the PDF claims PDF/UA-1 conformance. Forces tagging. */
|
|
17
17
|
pdfUa?: boolean;
|
|
18
18
|
/** Digital certification configuration. Certifies the PDF with an X.509 certificate. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { Style } from '@formepdf/shared';
|
|
4
|
-
import { encodeProps } from '
|
|
4
|
+
import { encodeProps } from '@formepdf/shared';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
/** Which page edge this element repeats on. Fixed elements reduce
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { Style } from '@formepdf/shared';
|
|
4
|
-
import { encodeProps } from '
|
|
4
|
+
import { encodeProps } from '@formepdf/shared';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
/** Marker style. Defaults to 'decimal'. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { Edges, Style } from '@formepdf/shared';
|
|
4
|
-
import { encodeProps } from '
|
|
4
|
+
import { encodeProps } from '@formepdf/shared';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
size?: 'A4' | 'A3' | 'A5' | 'Letter' | 'Legal' | 'Tabloid' | { width: number; height: number };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { Style } from '@formepdf/shared';
|
|
4
|
-
import { encodeProps } from '
|
|
4
|
+
import { encodeProps } from '@formepdf/shared';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
/** Header rows repeat at the top of every continuation page when
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { ColumnDef, Style } from '@formepdf/shared';
|
|
4
|
-
import { encodeProps } from '
|
|
4
|
+
import { encodeProps } from '@formepdf/shared';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
/** Column width definitions: `{ fraction }`, `{ fixed }`, or `'auto'`.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { Style } from '@formepdf/shared';
|
|
4
|
-
import { encodeProps } from '
|
|
4
|
+
import { encodeProps } from '@formepdf/shared';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
/** Bullet glyph style. Defaults to 'disc'. */
|
package/dist/serialize.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* and returns a JSON string, not PDF bytes.
|
|
15
15
|
*/
|
|
16
16
|
import { render as renderSvelteMarkup } from 'svelte/server';
|
|
17
|
-
import { parseMarkup } from '
|
|
17
|
+
import { parseMarkup } from '@formepdf/shared';
|
|
18
18
|
/**
|
|
19
19
|
* Serialize a Svelte template into a Forme JSON document object.
|
|
20
20
|
* The template's top-level element must be a `<Document>`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formepdf/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Svelte-to-JSON serializer for Forme PDF engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"test:watch": "npm run embed-preview && vitest"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@formepdf/shared": "0.
|
|
28
|
+
"@formepdf/shared": "0.16.0",
|
|
29
29
|
"parse5": "^7.2.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@formepdf/core": "^0.
|
|
32
|
+
"@formepdf/core": "^0.16.0",
|
|
33
33
|
"svelte": "^5.30.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@formepdf/core": "0.
|
|
42
|
-
"@formepdf/react": "0.
|
|
43
|
-
"@formepdf/tailwind": "0.
|
|
41
|
+
"@formepdf/core": "0.16.0",
|
|
42
|
+
"@formepdf/react": "0.16.0",
|
|
43
|
+
"@formepdf/tailwind": "0.16.0",
|
|
44
44
|
"@sveltejs/package": "^2.3.10",
|
|
45
45
|
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
|
46
46
|
"@types/react": "^19.0.0",
|
package/dist/encode.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prop encoding for the emitting components.
|
|
3
|
-
*
|
|
4
|
-
* Each Forme Svelte component renders one placeholder tag whose
|
|
5
|
-
* `props` attribute carries the component's props as JSON (part of
|
|
6
|
-
* the internal emitter/parser contract - see `parser.ts`). Values
|
|
7
|
-
* that cannot survive the JSON round-trip fail loudly here, naming
|
|
8
|
-
* the component and prop, rather than silently producing a wrong PDF.
|
|
9
|
-
* The one exception is `Uint8Array` (byte font sources on
|
|
10
|
-
* `<Document fonts>`): it is tunneled through a marker object and
|
|
11
|
-
* restored by the parser's reviver, so byte sources survive
|
|
12
|
-
* serialization exactly as they do in the react adapter.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* `JSON.parse` reviver restoring `Uint8Array` values that
|
|
16
|
-
* `encodeProps` tunneled through byte markers.
|
|
17
|
-
*/
|
|
18
|
-
export declare function reviveBytesMarker(_key: string, value: unknown): unknown;
|
|
19
|
-
/**
|
|
20
|
-
* JSON-encode a component's props for the placeholder `props`
|
|
21
|
-
* attribute. `undefined` values are omitted (matching how absent
|
|
22
|
-
* props behave in the react adapter). `Uint8Array` values become
|
|
23
|
-
* byte markers (see `reviveBytesMarker`). Functions, symbols,
|
|
24
|
-
* bigints, and circular structures throw an error naming the
|
|
25
|
-
* component and the offending prop.
|
|
26
|
-
*/
|
|
27
|
-
export declare function encodeProps(component: string, props: object): string;
|
package/dist/encode.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prop encoding for the emitting components.
|
|
3
|
-
*
|
|
4
|
-
* Each Forme Svelte component renders one placeholder tag whose
|
|
5
|
-
* `props` attribute carries the component's props as JSON (part of
|
|
6
|
-
* the internal emitter/parser contract - see `parser.ts`). Values
|
|
7
|
-
* that cannot survive the JSON round-trip fail loudly here, naming
|
|
8
|
-
* the component and prop, rather than silently producing a wrong PDF.
|
|
9
|
-
* The one exception is `Uint8Array` (byte font sources on
|
|
10
|
-
* `<Document fonts>`): it is tunneled through a marker object and
|
|
11
|
-
* restored by the parser's reviver, so byte sources survive
|
|
12
|
-
* serialization exactly as they do in the react adapter.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Marker key wrapping a base64-encoded `Uint8Array` inside the props
|
|
16
|
-
* JSON. Part of the internal emitter/parser contract.
|
|
17
|
-
*/
|
|
18
|
-
const BYTES_MARKER = '__formeBytes';
|
|
19
|
-
/** Encode bytes to base64 without Node APIs (works in edge runtimes). */
|
|
20
|
-
function bytesToBase64(bytes) {
|
|
21
|
-
let binary = '';
|
|
22
|
-
const chunk = 0x8000;
|
|
23
|
-
for (let i = 0; i < bytes.length; i += chunk) {
|
|
24
|
-
binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
25
|
-
}
|
|
26
|
-
return btoa(binary);
|
|
27
|
-
}
|
|
28
|
-
function base64ToBytes(b64) {
|
|
29
|
-
const binary = atob(b64);
|
|
30
|
-
const bytes = new Uint8Array(binary.length);
|
|
31
|
-
for (let i = 0; i < binary.length; i++)
|
|
32
|
-
bytes[i] = binary.charCodeAt(i);
|
|
33
|
-
return bytes;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* `JSON.parse` reviver restoring `Uint8Array` values that
|
|
37
|
-
* `encodeProps` tunneled through byte markers.
|
|
38
|
-
*/
|
|
39
|
-
export function reviveBytesMarker(_key, value) {
|
|
40
|
-
if (value !== null &&
|
|
41
|
-
typeof value === 'object' &&
|
|
42
|
-
typeof value[BYTES_MARKER] === 'string') {
|
|
43
|
-
return base64ToBytes(value[BYTES_MARKER]);
|
|
44
|
-
}
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* JSON-encode a component's props for the placeholder `props`
|
|
49
|
-
* attribute. `undefined` values are omitted (matching how absent
|
|
50
|
-
* props behave in the react adapter). `Uint8Array` values become
|
|
51
|
-
* byte markers (see `reviveBytesMarker`). Functions, symbols,
|
|
52
|
-
* bigints, and circular structures throw an error naming the
|
|
53
|
-
* component and the offending prop.
|
|
54
|
-
*/
|
|
55
|
-
export function encodeProps(component, props) {
|
|
56
|
-
const parts = [];
|
|
57
|
-
for (const [key, value] of Object.entries(props)) {
|
|
58
|
-
if (value === undefined)
|
|
59
|
-
continue;
|
|
60
|
-
let json;
|
|
61
|
-
try {
|
|
62
|
-
json = JSON.stringify(value, (_k, v) => {
|
|
63
|
-
const t = typeof v;
|
|
64
|
-
if (t === 'function' || t === 'symbol' || t === 'bigint') {
|
|
65
|
-
throw new TypeError(`contains a ${t}, which cannot be serialized to JSON`);
|
|
66
|
-
}
|
|
67
|
-
if (v instanceof Uint8Array) {
|
|
68
|
-
return { [BYTES_MARKER]: bytesToBase64(v) };
|
|
69
|
-
}
|
|
70
|
-
// A user object carrying the marker key would be revived as a
|
|
71
|
-
// Uint8Array on the other side - fail loudly instead of
|
|
72
|
-
// silently corrupting it. (Marker objects produced above are
|
|
73
|
-
// never re-visited by the replacer, so this only fires on
|
|
74
|
-
// user-supplied values.)
|
|
75
|
-
if (v !== null && t === 'object' && BYTES_MARKER in v) {
|
|
76
|
-
throw new TypeError(`contains a reserved "${BYTES_MARKER}" key`);
|
|
77
|
-
}
|
|
78
|
-
return v;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
const reason = err instanceof Error ? err.message : String(err);
|
|
83
|
-
throw new Error(`[Forme] <${component}>: prop "${key}" is not serializable: ${reason}`);
|
|
84
|
-
}
|
|
85
|
-
// JSON.stringify returns undefined (without throwing) for values
|
|
86
|
-
// with no JSON representation at the top level, e.g. functions -
|
|
87
|
-
// drop such props rather than emitting invalid JSON.
|
|
88
|
-
if (json === undefined)
|
|
89
|
-
continue;
|
|
90
|
-
parts.push(`${JSON.stringify(key)}:${json}`);
|
|
91
|
-
}
|
|
92
|
-
return `{${parts.join(',')}}`;
|
|
93
|
-
}
|
package/dist/parser.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Markup parser: Svelte SSR output in, Forme document model out.
|
|
3
|
-
*
|
|
4
|
-
* The Forme Svelte components render namespaced placeholder tags
|
|
5
|
-
* (`<forme-document>`, `<forme-page>`, `<forme-view>`, `<forme-text>`)
|
|
6
|
-
* with a single `props` attribute holding the JSON-encoded component
|
|
7
|
-
* props. This module parses that markup - the emitting components and
|
|
8
|
-
* this parser are a matched pair inside this package. The placeholder
|
|
9
|
-
* tag/attribute vocabulary is an INTERNAL contract, not a public
|
|
10
|
-
* format: it may change in any release without notice.
|
|
11
|
-
*
|
|
12
|
-
* Whitespace is normalized to JSX-equivalent semantics so that a
|
|
13
|
-
* `.svelte` template and its TSX counterpart serialize identically:
|
|
14
|
-
* indentation and newlines never leak into text content, while
|
|
15
|
-
* interior spaces and interpolation boundaries are preserved. The
|
|
16
|
-
* Svelte compiler trims fragment edges and collapses inter-element
|
|
17
|
-
* whitespace before we ever see the markup, so the remaining rules
|
|
18
|
-
* are applied here (see `cleanJsxText`). Known divergences from JSX,
|
|
19
|
-
* where the compiler destroys the distinction before serialization -
|
|
20
|
-
* each matches how Svelte itself renders the template to the DOM:
|
|
21
|
-
*
|
|
22
|
-
* - Same-line leading/trailing spaces inside `<Text>` are trimmed
|
|
23
|
-
* (`<Text> a </Text>` → `"a"`; JSX keeps them).
|
|
24
|
-
* - Interpolations split across lines join with a single space
|
|
25
|
-
* (JSX drops the whitespace-only literal between them entirely).
|
|
26
|
-
* - Newlines inside interpolated *values* are treated like template
|
|
27
|
-
* text and collapse to a space.
|
|
28
|
-
*/
|
|
29
|
-
import type { FormeDocument } from '@formepdf/shared';
|
|
30
|
-
export declare function parseMarkup(markup: string): FormeDocument;
|