@polotno/schema 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +13 -6
- package/README.md +1 -3
- package/lib/migrate.d.ts +9 -3
- package/lib/migrate.js +72 -9
- package/package.json +1 -1
package/LICENSE.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
Polotno
|
|
1
|
+
# Polotno Schema License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2014–present Anton Lavrenov.
|
|
3
|
+
Copyright (c) 2014–present Anton Lavrenov. All rights reserved.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
production
|
|
5
|
+
You can use and change this package for free, with no time limit, including in
|
|
6
|
+
production. The Polotno design format is open: any person, and any AI agent, can
|
|
7
|
+
read and write it.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
This package is not open source. Do not republish it as a library, and do not
|
|
10
|
+
sublicense it.
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
This package is provided "as is", without warranty. To the maximum limit that
|
|
13
|
+
the law permits, the copyright holder has no liability for a claim or for
|
|
14
|
+
damages.
|
|
15
|
+
|
|
16
|
+
Subscription terms for other Polotno packages:
|
|
17
|
+
https://polotno.com/legal/license
|
package/README.md
CHANGED
|
@@ -76,6 +76,4 @@ import type { Design, Page, Element, TextElement } from '@polotno/schema';
|
|
|
76
76
|
|
|
77
77
|
## License
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
subscription. See [LICENSE.md](./LICENSE.md) ·
|
|
81
|
-
[full terms](https://polotno.com/legal/license).
|
|
79
|
+
See [LICENSE.md](./LICENSE.md).
|
package/lib/migrate.d.ts
CHANGED
|
@@ -7,9 +7,15 @@ export interface MigrateOptions {
|
|
|
7
7
|
*/
|
|
8
8
|
modernTextRenderer?: boolean;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* The v2→3 background policy. Three states, no new argument needed:
|
|
11
|
+
*
|
|
12
|
+
* - `undefined` (default) — **auto**: infer the pre-v3 renderer from the
|
|
13
|
+
* design, as `usesRichTextEditor` below explains.
|
|
14
|
+
* - `true` — **per-line**: never stamp; every pre-v3 background renders as
|
|
15
|
+
* the per-line polygon.
|
|
16
|
+
* - `false` — **full-rect**: always stamp; every pre-v3 background renders as
|
|
17
|
+
* a full rect. The escape hatch for a rich-text client whose designs happen
|
|
18
|
+
* to hold only bare strings, which auto cannot tell from a plain design.
|
|
13
19
|
*/
|
|
14
20
|
modernizeTextBackground?: boolean;
|
|
15
21
|
}
|
package/lib/migrate.js
CHANGED
|
@@ -18,10 +18,63 @@
|
|
|
18
18
|
// one. Designs written before the field existed are precisely the ones that
|
|
19
19
|
// need migrating, so absence has to mean "old". `store.toJSON()` always
|
|
20
20
|
// stamps the current version, so a round-tripped design is never re-migrated.
|
|
21
|
+
//
|
|
22
|
+
// **Overriding a migration? Migrate ONCE, then reuse the result.** The options
|
|
23
|
+
// below reach `store.loadJSON`, but the converters call `parseDesign`/
|
|
24
|
+
// `normalizeDesign`, which take no migration options and never will — a design's
|
|
25
|
+
// meaning must not depend on which entry point opened it. So resolve the intent
|
|
26
|
+
// yourself, before any renderer sees the JSON:
|
|
27
|
+
//
|
|
28
|
+
// const migrated = migrateDesign(raw, { modernizeTextBackground: false });
|
|
29
|
+
// store.loadJSON(migrated); // canvas
|
|
30
|
+
// await jsonToPDF(migrated); // and every converter
|
|
31
|
+
//
|
|
32
|
+
// `migrateDesign` bumps `schemaVersion` to the current one and writes the
|
|
33
|
+
// decision into the design (`legacyBackground`), so the second pass through any
|
|
34
|
+
// entry point is a no-op and every renderer reads the same resolved intent.
|
|
21
35
|
import { CURRENT_SCHEMA_VERSION } from './schema.js';
|
|
22
36
|
import { TEXT_DEFAULTS } from './defaults.js';
|
|
23
37
|
/** Named effects that never used the -100..100 intensity range. */
|
|
24
38
|
const UNSCALED_FILTERS = ['warm', 'cold', 'natural'];
|
|
39
|
+
/** The tags Quill actually emitted. Anything else is not evidence. */
|
|
40
|
+
const QUILL_TAG = /<\/?(?:p|br|span|strong|em|ol|ul|li)\b[^>]*>/i;
|
|
41
|
+
/**
|
|
42
|
+
* Was this design written in the rich-text (Quill) editor, rather than the
|
|
43
|
+
* plain one?
|
|
44
|
+
*
|
|
45
|
+
* This is the whole v2→3 decision. The two pre-v3 text engines drew the
|
|
46
|
+
* background differently — plain Konva per line, rich text as one full rect —
|
|
47
|
+
* and a pre-v3 design does not record which one wrote it. But it does record
|
|
48
|
+
* the text, and only the rich editor ever stored markup: the plain editor kept
|
|
49
|
+
* a bare string with `\n` for newlines, and the rich pipeline never rewrites a
|
|
50
|
+
* bare string into `<p>` (see the `includes('<')` short-circuits in
|
|
51
|
+
* `@polotno/core/rich-text-html`). So markup is evidence of provenance — and
|
|
52
|
+
* evidence the CONVERTERS can read, unlike the editor flag this originally
|
|
53
|
+
* keyed on, which nothing below `polotno` can see.
|
|
54
|
+
*
|
|
55
|
+
* **Asked once per design, deliberately.** The renderer was a client-wide
|
|
56
|
+
* setting, never per element, so one marked-up element means the whole design
|
|
57
|
+
* was written in the rich editor. That matters because the rich editor did not
|
|
58
|
+
* always keep the markup: it simplified some `<p>hello</p>` back to `hello`, so
|
|
59
|
+
* a rich design routinely mixes marked-up and bare elements. Asking per element
|
|
60
|
+
* would split such a design down the middle and give two of its backgrounds two
|
|
61
|
+
* different shapes.
|
|
62
|
+
*
|
|
63
|
+
* Only known Quill tags count, so plain text holding a less-than ("a < b") or
|
|
64
|
+
* something merely tag-shaped is not mistaken for markup. A design that is
|
|
65
|
+
* entirely bare stays ambiguous and no heuristic can resolve it; it lands on
|
|
66
|
+
* per-line, and `modernizeTextBackground: false` overrides that.
|
|
67
|
+
*/
|
|
68
|
+
function usesRichTextEditor(pages) {
|
|
69
|
+
let rich = false;
|
|
70
|
+
forEveryElement(pages, (element) => {
|
|
71
|
+
if (rich || element.type !== 'text')
|
|
72
|
+
return;
|
|
73
|
+
if (QUILL_TAG.test(String(element.text ?? '')))
|
|
74
|
+
rich = true;
|
|
75
|
+
});
|
|
76
|
+
return rich;
|
|
77
|
+
}
|
|
25
78
|
/**
|
|
26
79
|
* Local element walk. Schema sits below core, so it cannot use core's
|
|
27
80
|
* `forEveryNode` — but it visits the same element nodes: nested `children`
|
|
@@ -64,7 +117,9 @@ function forEveryElement(pages, cb) {
|
|
|
64
117
|
* unchanged apart from the clone.
|
|
65
118
|
*/
|
|
66
119
|
export function migrateDesign(json, options = {}) {
|
|
67
|
-
|
|
120
|
+
// No default for modernizeTextBackground: `undefined` is a real state here
|
|
121
|
+
// (decide per element), distinct from either explicit boolean.
|
|
122
|
+
const { modernTextRenderer = true, modernizeTextBackground } = options;
|
|
68
123
|
// Guard BEFORE the round-trip: JSON.parse(JSON.stringify(undefined)) throws a
|
|
69
124
|
// raw SyntaxError, and a circular object throws TypeError. Non-designs must
|
|
70
125
|
// reach the zod pass untouched so they surface as a structured
|
|
@@ -117,14 +172,22 @@ export function migrateDesign(json, options = {}) {
|
|
|
117
172
|
}
|
|
118
173
|
});
|
|
119
174
|
}
|
|
120
|
-
if (from < 3 && modernTextRenderer
|
|
121
|
-
// Freeze pre-v3
|
|
122
|
-
// preserved exactly
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
175
|
+
if (from < 3 && modernTextRenderer) {
|
|
176
|
+
// Freeze a pre-v3 RICH-TEXT design's backgrounds as full rects, so the old
|
|
177
|
+
// render is preserved exactly; leave a plain-text design to the per-line
|
|
178
|
+
// polygon it was authored with. `modernizeTextBackground` is the inverse of
|
|
179
|
+
// the stamp — "modernize" is exactly "do not freeze" — and when it is unset
|
|
180
|
+
// the design decides. See rule 2 in the header: intent, not geometry.
|
|
181
|
+
const stamp = modernizeTextBackground === undefined
|
|
182
|
+
? usesRichTextEditor(data.pages)
|
|
183
|
+
: !modernizeTextBackground;
|
|
184
|
+
if (stamp) {
|
|
185
|
+
forEveryElement(data.pages, (element) => {
|
|
186
|
+
if (element.type === 'text' && element.backgroundEnabled) {
|
|
187
|
+
element.legacyBackground = true;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
128
191
|
}
|
|
129
192
|
// v3→4 is a marker only: v4 is the video time-anchor render change. Nothing
|
|
130
193
|
// to transform, but the bump lets a future migration target pre-v4 designs.
|
package/package.json
CHANGED