@oim-media/spec 1.35.2 → 1.36.2

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/CANONICAL_SPEC.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # OIM (Object Interactive Media) Canonical Metadata Specification
2
2
 
3
- **Contract version:** 1.35.2
3
+ > This document describes **1.x** (legacy, no longer painted by readers). The current format is OIM 2.0: see [CANONICAL_SPEC_2.md](CANONICAL_SPEC_2.md).
4
+
5
+ **Contract version:** 1.36.2
4
6
  **Date:** 2026-11-02 (reviewed against `packages/core/src/schema.ts`; the source of truth is the schema, this document summarises it)
5
7
  **Status:** Normative / In force
6
8
  **License:** Apache-2.0
@@ -0,0 +1,800 @@
1
+ <!--
2
+ Copyright (c) 2026 Xue Studios LLC
3
+ SPDX-License-Identifier: Apache-2.0
4
+ -->
5
+
6
+ # OIM 2.0 Canonical Specification
7
+
8
+ **Document version emitted by the reference writer:** `2.0.0` (`DOCUMENT_VERSION` in `@oim-media/core/v2`)
9
+ **Contract release this text was checked against:** 1.36.2
10
+ **Status:** Normative
11
+ **License:** Apache-2.0
12
+ **Authority:** Xue Studios LLC
13
+
14
+ The source of truth is code and data, and this document summarises them:
15
+
16
+ - the document schema, `packages/core/src/v2/schema.ts` and `layer-blocks.ts`, published as
17
+ [`schema/oim2.schema.json`](schema/oim2.schema.json);
18
+ - the container and signing code in `packages/core/src` (`binary.ts`, `canonical.ts`, `limits.ts`) and
19
+ `packages/player-oim/src/render` (`security.ts`, `keys.ts`);
20
+ - the reference painter in `packages/scene`.
21
+
22
+ Where this text and those files disagree, the files win, and the disagreement is a bug in this text.
23
+ Section 11 lists the places where the schema allows something the reference painter does not draw.
24
+
25
+ The key words MUST, MUST NOT, SHOULD, SHOULD NOT and MAY are used as in RFC 2119.
26
+
27
+ > This document describes **2.0**. The 1.x format is described by [CANONICAL_SPEC.md](CANONICAL_SPEC.md)
28
+ > and [BINARY_SPEC.md](BINARY_SPEC.md); it is legacy and no longer painted.
29
+
30
+ ---
31
+
32
+ ## 1. Scope, conformance and versioning
33
+
34
+ ### 1.1. Scope
35
+
36
+ A `.oim` file is a PNG image that carries, in an ancillary chunk, one JSON document (the **document**)
37
+ describing layers painted over a canvas. This specification defines the container (section 2), the
38
+ document (section 3), how a reader paints it (section 4), the limits a reader enforces (section 5) and
39
+ how a document is signed and verified (section 6).
40
+
41
+ ### 1.2. Conformance classes
42
+
43
+ - **Writer**: produces a `.oim`. A conforming writer MUST emit a document that validates against
44
+ `schema/oim2.schema.json` (section 3), MUST emit the container of section 2, and MUST NOT emit a
45
+ retired construct (section 2.5 for the container, Appendix B).
46
+ - **Reader / player**: paints a `.oim`. A conforming reader MUST follow sections 1.3, 2, 4, 5 and 6.
47
+ It MUST NOT execute anything the file carries, MUST NOT request any resource the file names
48
+ (section 5.4), and MUST NOT paint a file whose signature or image seal fails (section 6.4).
49
+ - **Signer**: a service that holds a private key and signs documents. A conforming signer MUST validate
50
+ the document before signing, MUST compute `image_hash` itself from the PNG it embeds (never take it from
51
+ the caller), MUST refuse a document with a number that has no canonical form (section 6.2), and MUST
52
+ produce the signature of section 6.3. Verification needs no private key; a verifier is a reader.
53
+
54
+ ### 1.3. Versioning
55
+
56
+ The root field `oim` is a string matching `^2\.\d+\.\d+(-[\w.]+)?$`. The reference writer emits the
57
+ value of `DOCUMENT_VERSION`, currently `2.0.0`. The signed vectors in `vectors-2/` were signed under the
58
+ pre-release string `2.0.0-draft.1` and are not re-signed: that string is still a valid `oim`.
59
+
60
+ - A reader MUST treat any `oim` that starts with `2.` as a 2.0 document and MUST NOT refuse it for its
61
+ minor, patch or pre-release part.
62
+ - A reader MUST NOT paint any other document. The reference player, given a document whose `oim` does not
63
+ start with `2.` (every 1.x file), paints no layer, keeps showing the PNG, and fires `oim:error` with
64
+ `detail.code === "unsupported-version"` on the player element.
65
+ - A 1.x file is converted once, by a tool, not by the reader: `upgrade(input)` from `@oim-media/core/v2`
66
+ reads a 1.x document and returns `{ document, retired, unhandled }`. It is pure; it signs nothing. The
67
+ result MUST be signed again before a reader will paint its layers (an unsigned file shows only its PNG,
68
+ section 6.4). `SPEC_2.md` names the command-line form as `oim upgrade`; that tool is not part of this repository.
69
+ - A document that is already 2.x is returned by `upgrade()` unchanged.
70
+
71
+ ---
72
+
73
+ ## 2. Container
74
+
75
+ ### 2.1. PNG
76
+
77
+ A `.oim` is a conforming PNG (ISO/IEC 15948) that starts with the 8-byte PNG signature. Any viewer that
78
+ does not know OIM shows it as an ordinary image. The pixels are the **base picture** (section 2.4).
79
+
80
+ ### 2.2. The document chunk
81
+
82
+ The document is stored in one ancillary text chunk:
83
+
84
+ | Property | Value |
85
+ |---|---|
86
+ | Chunk type | `zTXt` |
87
+ | Keyword | `OIM_Data` |
88
+ | Compression method byte | `0x00` |
89
+ | Payload | zlib (RFC 1950) of the UTF-8 JSON text, any zlib level (the reference signer uses 9) |
90
+
91
+ Layout of the chunk data: `"OIM_Data" 0x00 0x00 <zlib bytes>`.
92
+
93
+ - The chunk MUST come after `IHDR` and before `IEND`. It MAY come before or after the `IDAT` chunks, and a reader MUST
94
+ accept both (signed vectors exist in both orders; informative: the reference writer has put it after the last `IDAT` since 1.30.0).
95
+ - The PNG bytes of `IDAT` (and of every other chunk) MUST NOT be re-encoded when the chunk is inserted,
96
+ because `image_hash` covers the `IDAT` payloads (section 6.5).
97
+ - A reader MUST also accept the earlier forms: keyword `OIM_JSON_DATA`; a `tEXt` chunk whose value is
98
+ raw deflate bytes, or base64 of deflate, or base64 of plain JSON; and an `iTXt` chunk, compressed or not.
99
+ A reader that has inflated a payload tries zlib first, then raw deflate. Writers MUST NOT emit these forms.
100
+ - A reader MUST stop inflating when the output passes **10 MiB** and treat the file as corrupt.
101
+ - The JSON text MUST be a single document object (section 3).
102
+
103
+ ### 2.3. Document and PNG
104
+
105
+ The PNG is not stored inside the document. `image_hash` ties the two together (section 6.5).
106
+
107
+ ### 2.4. The base picture and `oim:base`
108
+
109
+ The PNG itself is addressable from inside the document as the image source `oim:base`.
110
+
111
+ - An image layer whose `image.src` is the literal string `oim:base` (also as the `value` or as any entry of
112
+ `modes` of a source exception, or through a `{ ref }` to an image paint whose `src` is `oim:base`)
113
+ declares that **the file's own picture is part of the content**. The reader shows the PNG it already
114
+ holds and does not paint that layer's image again. `oim:base` is valid only in an image layer's
115
+ `image.src`; a paint's `src` (a fill or a stroke) takes only a `data:image/` URI.
116
+ - A writer that wants the PNG to be the bottom of the composition SHOULD list one such layer first.
117
+ `upgrade()` writes it first, with id `oim-base`, covering the canvas, and every vector in `vectors-2/` has it.
118
+ - **No-thumbnail default.** A writer that does not want image viewers without OIM support to show the layers
119
+ renders into the PNG only the background the author chose (a plain or textured canvas, or a photo) and
120
+ lists the `oim:base` layer. Everything else is painted live from the document. Such a file looks like
121
+ its background in a plain image viewer and complete in a player.
122
+ - **Full poster.** A writer MAY instead render every layer into the PNG, as a preview, and list **no**
123
+ `oim:base` layer. A reader (`hasBaseLayer(document)` is false) treats the PNG then as a poster: it shows
124
+ it until the layers are painted and then fades it out, and the `poster="only"` player option shows just
125
+ the PNG. A poster PNG MUST NOT be relied on for any content the layers do not also draw.
126
+ - Whether the PNG is a base or a poster is decided only by the presence of an `oim:base` image layer.
127
+
128
+ ### 2.5. Retired container constructs
129
+
130
+ `OIM_Seal`, a `tEXt` chunk of 1.30.0 to 1.32.x holding a signed hash of the image placed before the
131
+ document, is **retired** (1.33.0). Writers MUST NOT emit it. Readers MUST ignore it if present; two vectors
132
+ in `vectors-2/` still carry one (`filter-shape`, `mask-frame-fill`). The image is sealed by `image_hash`
133
+ (section 6.5) and a PNG that is only shown runs nothing, so a poster needs no seal of its own.
134
+
135
+ ---
136
+
137
+ ## 3. The document
138
+
139
+ All objects are **strict**: a key that this section does not list is a validation error, except inside
140
+ `extensions` (section 3.17), inside `params` of an animation, and in the open maps of
141
+ `resources`, `variables` and `text.content`, whose keys are chosen by the author. An absent field means
142
+ its default; no object carries a switched-off value.
143
+
144
+ ### 3.1. Root
145
+
146
+ | Field | Type | Required | Meaning |
147
+ |---|---|---|---|
148
+ | `oim` | string | yes | Version, section 1.3. |
149
+ | `id` | string 0..128 | no | Document identifier. No `<`, `>`, `"` or control characters. |
150
+ | `name` | string ≤256 | no | Title of the work. |
151
+ | `description` | map language → string ≤1000 | no | What the whole work shows, for screen readers. |
152
+ | `canvas` | object | yes | `width`, `height`: positive numbers in design pixels. `fills`: array of paints, ≤8, the background (section 3.4). |
153
+ | `languages` | string[] 1..64 | yes | Languages of the document, each 1..16 characters. The first is the default. |
154
+ | `variables` | object | no | Section 3.14. |
155
+ | `resources` | map name → paint | no | Shared paints, section 3.15. |
156
+ | `fonts` | array | no | Embedded fonts, section 3.16. |
157
+ | `layers` | Layer[] ≤150 | yes | Bottom to top. |
158
+ | `reedit` | `public` \| `author_only` \| `sealed` | no | Section 3.17. |
159
+ | `extensionsUsed` | string[] (each ≤64) | no | Section 3.17. |
160
+ | `extensionsRequired` | string[] (each ≤64) | no | Section 3.17. |
161
+ | `extensions` | open map | no | Section 3.17. |
162
+ | `image_hash`, `image_hash_alg`, `signature`, `key_version`, `signed_at` | string | signed files | Section 6. |
163
+ | `timestamp` | string | no | ISO 8601, the time of packaging, written by the signer. Outside the signature (6.3); a reader MUST ignore it. |
164
+
165
+ Example of a minimal document (unsigned):
166
+
167
+ ```json
168
+ {
169
+ "oim": "2.0.0",
170
+ "canvas": { "width": 800, "height": 600 },
171
+ "languages": ["en"],
172
+ "layers": [
173
+ { "id": "oim-base", "type": "image", "box": { "x": 0, "y": 0, "width": 800, "height": 600 }, "image": { "src": "oim:base" } },
174
+ { "id": "title", "type": "text", "box": { "x": 80, "y": 60, "width": 400, "height": 90 }, "text": { "content": { "en": "Hello" }, "font": { "size": 40 }, "align": "center" } }
175
+ ]
176
+ }
177
+ ```
178
+
179
+ ### 3.2. Layers
180
+
181
+ A layer is an object with a `type` and a fixed set of blocks. The **common fields** of every layer:
182
+
183
+ | Field | Type | Meaning |
184
+ |---|---|---|
185
+ | `id` | string 1..128 | Required. Unique in the whole document, children included (a repeated id is an error). No `<`, `>`, `"` or control characters. |
186
+ | `type` | `text` \| `shape` \| `image` \| `lottie` \| `group` | Required. |
187
+ | `name` | string ≤256 | Author's name. |
188
+ | `box` | object | Required. Section 3.3. |
189
+ | `opacity` | number 0..1 | Of the layer as a whole. Default 1. |
190
+ | `visible` | boolean | Default true. `false` starts the layer hidden (an action can show it). |
191
+ | `blend` | `multiply` \| `screen` \| `overlay` \| `darken` \| `lighten` \| `color-dodge` \| `color-burn` \| `difference` | Absent is normal. |
192
+ | `languages` | string[] 1..64 | The layer is shown only in these languages; absent means every language. Each 1..16 characters. |
193
+ | `extensions` | open map | Section 3.17. |
194
+
195
+ The **blocks** a type admits (`LAYER_BLOCKS`). A block on a type that does not admit it is an error. The
196
+ **required** block of a type is marked with `*`; every other block is optional.
197
+
198
+ | Block | `text` | `shape` | `image` | `lottie` | `group` |
199
+ |---|:-:|:-:|:-:|:-:|:-:|
200
+ | `fills` | ✓ | ✓ | | | |
201
+ | `strokes` | ✓ | ✓ | ✓ | | |
202
+ | `effects` | ✓ | ✓ | ✓ | ✓ | ✓ |
203
+ | `animations` | ✓ | ✓ | ✓ | ✓ | ✓ |
204
+ | `motion` | ✓ | ✓ | ✓ | ✓ | ✓ |
205
+ | `mask` | ✓ | ✓ | ✓ | | |
206
+ | `geometry` | | ✓* | | | |
207
+ | `corners` | | ✓ | ✓ | | |
208
+ | `text` | ✓* | | | | |
209
+ | `image` | | | ✓* | | |
210
+ | `a11y` | | ✓ | ✓ | | |
211
+ | `interactions` | ✓ | ✓ | ✓ | | ✓ |
212
+ | `children` | | | | | ✓* |
213
+
214
+ `lottie` layers also carry the type-specific field `lottie`: `{ src?: string, loop?: boolean }`.
215
+
216
+ Counts: `fills` ≤8, `strokes` ≤8, `effects` ≤16, `animations` ≤16, `interactions` ≤8, `children` ≤150 per layer.
217
+ A `group` paints its `children` in order; a child's `box` is expressed in canvas units, not relative to the group.
218
+
219
+ ### 3.3. Box
220
+
221
+ | Field | Type | Meaning |
222
+ |---|---|---|
223
+ | `x`, `y` | number | Required. Position in design pixels. |
224
+ | `width`, `height` | number ≥0 | Optional. Left out, the layer fits its content, grown from its anchor. A width alone is a reference width (what an endless loop measures its copies by). |
225
+ | `anchor` | `top-left` \| `top` \| `top-right` \| `left` \| `center` \| `right` \| `bottom-left` \| `bottom` \| `bottom-right` | Which point of the box sits at `x, y`. Absent is `top-left`. |
226
+ | `rotation` | number | Degrees, clockwise. |
227
+ | `flipX`, `flipY` | boolean | Mirror on the layer's own axes. |
228
+
229
+ The box is the painted rectangle: there is no implicit centring and no relative unit. See section 4.
230
+
231
+ ### 3.4. Paints
232
+
233
+ A **paint** is one of the following objects. `opacity` is a number 0..1 on every paint except `{ ref }`.
234
+
235
+ | `kind` | Fields |
236
+ |---|---|
237
+ | `color` | `value`: a colour (3.5). |
238
+ | `gradient` | `gradient` or `preset` (exactly one). `gradient`: `type` (`linear` \| `radial` \| `conic`), `angle` (number), `stops` (2..32 of `{ color, at }`, `at` 0..1). `preset`: a name ≤64. |
239
+ | `image` | `src` (string; a `data:image/` URI), `fit` (`contain` \| `cover` \| `fill` \| `none` \| `scale-down`), `crop` (`{ x: 0..100, y: 0..100, zoom: 1..10 }`), `flipX`, `flipY`, `filters` (3.8). |
240
+ | `pattern` | `pattern`: `preset` (name ≤64), `colors` (≤16 colours), `bg` (colour), `scale`, `sizes`/`counts`/`dispersions` (numbers, ≤16), `svgs` (strings, ≤16), `fit` (≤32), `motion` (`direction`: `right` \| `left` \| `up` \| `down` \| `zoom-in` \| `zoom-out` \| `pulse`; `period` >0; `speed`), `tile`: `{ viewBox: number[4], paths: pathEntry[1..64] }` (a stored drawing; with it `preset` and `svgs` are ignored). |
241
+ | `generative` | `generative`: `generatorId` (`^[a-z0-9-]+$`, ≤64), `seed` (number), `params` (map of ≤64-char keys to number, string ≤256 or boolean), `colors` (`mode`: `monochrome` \| `palette`; `stops`: ≤16 colours; `direction`: `forward` \| `reverse` \| `radial`; `background`: colour; `backgroundVisible`: boolean). |
242
+ | `texture` | `texture`: `type` (1..32), `color`, `angle`, `crossed` (boolean), `thickness` ≥0, `size` ≥0. A drawn texture of lines or dots. |
243
+ | *(reference)* | `{ "ref": id }` only: the paint named `id` in `document.resources` (3.15). |
244
+
245
+ `canvas.fills` and a layer's `fills` paint in array order, first at the bottom.
246
+
247
+ A **stroke** is `{ paint, width, align?, style? }`: `paint` is a paint, `width` a length (3.5), `align` is
248
+ `center` (default) \| `inside` \| `outside`, `style` is `solid` \| `dashed` \| `dotted`.
249
+
250
+ ### 3.5. Colours and lengths
251
+
252
+ A **colour** is a string of at most 128 characters that matches the whitelist `CSS_COLOR_PATTERN`
253
+ (`dynamic-colors.ts`): a hex colour with 3, 4, 6 or 8 digits; `rgb()`, `rgba()`, `hsl()` or `hsla()` whose
254
+ arguments are only digits, letters, `.`, `,`, `%`, `/`, `+`, `-` and spaces; the keywords `transparent`,
255
+ `currentColor`, `none`, `inherit`; or `var(--name)` / `var(--name, fallback)` with a fallback that is itself
256
+ one of these, nested at most twice. Anything else is invalid; a reader MUST NOT paint it.
257
+
258
+ A **scalar** (a colour, or a length such as `text.font.size`, a stroke `width`, `maxWidth`) is one of:
259
+
260
+ - a literal;
261
+ - a **binding** `{ "var": name, "fallback"?: literal }`: the value of the variable `name` (section 3.14),
262
+ else `fallback`; `name` is 1..64 characters;
263
+ - an **exception** `{ "value": literal, "modes": { mode: literal } }`: `value`, except in the named modes.
264
+ The reference reader selects the exception by language.
265
+
266
+ ### 3.6. Effects
267
+
268
+ `effects` entries are objects discriminated by `kind`:
269
+
270
+ | `kind` | Fields |
271
+ |---|---|
272
+ | `shadow` | `x`, `y`, `blur` ≥0, `spread`, `color`, `opacity` 0..1, `inner` (boolean). |
273
+ | `glow` | `radius` ≥0 (required), `color`, `intensity`. |
274
+ | `blur` | `radius` ≥0 (required). |
275
+ | `backdrop` | The image filters of 3.8, applied to what is behind the layer. |
276
+ | `filter` | The image filters of 3.8, applied to the layer itself. |
277
+ | `grain` | `intensity` 0..100, `size` ≥0, `blend` (≤32), `color`. |
278
+ | `color-grade` | `preset` (required, 1..64), `intensity` 0..100. Presets: `warm-vintage`, `cool-cinema`, `cyberpunk`, `monochrome-contrast`, `teal-orange`, `bleach-bypass`, `cross-process`, `sepia`. An unknown preset paints nothing. |
279
+ | `texture` | `preset` (required, 1..64), `intensity` 0..100, `blend` (≤32), `scale`, `color`. Presets: `film-grain-35mm`, `fine-noise`, `dust-scratches`, `vintage-paper`, `rough-canvas`, `halftone-dots`, `scanlines`, `concentric-rings`. |
280
+
281
+ Effects apply in array order to the whole layer.
282
+
283
+ ### 3.7. Geometry and corners
284
+
285
+ `geometry` (required on `shape`) is discriminated by `kind`. Every kind may carry `trim`
286
+ (`{ start?: 0..1, end?: 0..1 }`, how much of the outline is drawn). The reference painter draws it on a figure
287
+ it draws as an SVG outline (a preset, a line, an ellipse, a single path); a plain rectangle is not trimmed.
288
+
289
+ | `kind` | Fields |
290
+ |---|---|
291
+ | `rect`, `ellipse`, `line` | none |
292
+ | `polygon` | `sides`: integer 3..64. |
293
+ | `star` | `points`: integer 3..64; `inner`: 0..1. |
294
+ | `preset` | `name` (1..64): a catalogue shape: `triangle`, `star`, `arrow`, `diamond`, `hexagon`, `circle`, `heart`, `line`, `blob`, `scribble`, `pill`, `octagon`, `pentagon`, `cross`, `moon`, `cloud`, `drop`, `bolt`, `bubble`, `flower`, `burst`, `arch`. A preset fills its box, drawn in the box's own pixels: `arch`, `pill`, `bubble` and `circle` keep round curves at any aspect ratio; every other preset is its drawing scaled to span the box. |
295
+ | `paths` | `viewBox`: 4 numbers; `paths`: 1..2000 entries `{ d (required), fillRule ("evenodd"), fill (≤128), stroke (≤128), strokeWidth ≥0, cap (round \| square), join (round \| bevel), opacity 0..1, transform (6 numbers) }`. The drawing is scaled from its `viewBox` into the box. |
296
+
297
+ `corners` (on `shape` and `image`) is a number ≥0 (all corners) or an array of exactly 4 numbers ≥0.
298
+
299
+ ### 3.8. Image filters
300
+
301
+ `filters` (in an image paint, an image block, and in `backdrop` and `filter` effects) is
302
+ `{ preset?, blur?, brightness?, contrast?, saturate?, hueRotate? }`: `preset` is a name ≤64; the numbers are
303
+ ≥0 except `hueRotate`. Presets: `grayscale`, `sepia`, `high-contrast`, `vintage`, `cool`, `warm`, `faded`,
304
+ `cinema`, `nordic`, `sunset`, `noir`, `dramatic`, `cyberpunk`, `pastel`, `vhs`. An unknown preset is ignored.
305
+
306
+ ### 3.9. Text
307
+
308
+ The `text` block of a `text` layer:
309
+
310
+ | Field | Type | Meaning |
311
+ |---|---|---|
312
+ | `content` | map language → string | Required. The words, per language. |
313
+ | `font` | object | `family` (≤256, no `<`, `>`, `"`, control characters), `size` (length), `weight` (number or string ≤16), `italic` (boolean). |
314
+ | `align` | `left` \| `center` \| `right` \| `justify` | Default `left`. |
315
+ | `lineHeight` | number or string ≤16 | |
316
+ | `letterSpacing` | number | In design pixels. |
317
+ | `transform` | `uppercase` \| `lowercase` \| `capitalize` | |
318
+ | `decoration` | string ≤64 | |
319
+ | `maxWidth` | length | |
320
+ | `marks` | map name → mark | Styles for `{name}…{/name}` spans of `content`; literal braces are doubled (`{{`, `}}`). A mark is `{ color, colorRole, bold, italic, underline, highlight }`; `colorRole` is one of `primary`, `on-primary`, `secondary`, `on-secondary`, `surface`, `on-surface`, `outline`, `accent`, `text-primary`, `text-secondary`, `text-muted`, `text-on-accent`; `highlight` is `{ style: marker \| box \| pill \| underline-thick, color, colorRole, paddingX, paddingY, borderRadius }` (padding and radius 0..64). |
321
+ | `runs` | map language → `{ fontSize, lineHeight, lines: [{ text, width, yOffset }] }` | Precalculated lines (≤500 per language) for readers with no paragraph layout. A reader that lays out text itself ignores them. |
322
+ | `highlight` | `{ enabled, color, style, paddingX, paddingY, borderRadius }` | Whole-text highlight. |
323
+ | `dropCap` | `{ enabled, lines: 2 \| 3, fontFamily, color, marginRight }` | |
324
+ | `artistic` | `{ preset (≤64), curve: { type: arc \| wave \| arch, amount }, extrusion: { depth ≥0, angle, color, shading } }` | Artistic text. |
325
+
326
+ **Languages and fallback.** A reader selects the document language from `languages`: the entry equal to the
327
+ reader's requested language (case-insensitive), else the first entry with the same primary subtag, else
328
+ `languages[0]`. A text then shows `content[language]`; if that entry is absent or empty, it shows `content.en`,
329
+ then `content.es`, then the first non-empty entry of `content`. (The last chain is what the reference painter
330
+ does; it is the 1.x behaviour kept so upgraded files look the same.) The language is chosen once and applies
331
+ to the whole document, including exceptions in scalars (3.5), image `src` exceptions (3.10) and `a11y`.
332
+
333
+ ### 3.10. Image
334
+
335
+ The `image` block of an `image` layer: `src`, `fit`, `crop`, `filters` (3.8).
336
+
337
+ `src` is one of: a string (`oim:base`, or a `data:image/` URI); `{ value, modes }` (a picture per language; an
338
+ empty string means that language shows none); or `{ ref }`, the name of an image paint in `resources`.
339
+ `fit` and `crop` are as in 3.4. Pixel sources are only `data:image/png`, `jpeg`, `jpg`, `webp` or `gif` with
340
+ base64 (section 5.4).
341
+
342
+ ### 3.11. Masks
343
+
344
+ `mask` is `{ mode?, invert?, feather?, scope? }`: `mode` is `window` \| `cutout`, `invert` is boolean,
345
+ `feather` ≥0, `scope` is `group` \| `canvas`. A cutout clips the layers before it in its parent (the canvas, or its group), in that parent's own units.
346
+
347
+ ### 3.12. Animations and motion
348
+
349
+ An animation:
350
+
351
+ | Field | Type | Meaning |
352
+ |---|---|---|
353
+ | `on` | `load` \| `loop` \| `enter` \| `hover` \| `press` \| `action` | Trigger. |
354
+ | `target` | `layer` \| `chars` \| `words` \| `lines` | What moves. Only `text` layers admit `chars`, `words`, `lines`; other types admit only `layer`. Absent is `layer`. |
355
+ | `preset` | string 1..64 | A named animation. Exactly one of `preset` and `tracks`. |
356
+ | `params` | open map | Preset-specific parameters. |
357
+ | `tracks` | 1..16 | Exactly one of `preset` and `tracks`. |
358
+ | `duration` | number ≥0 | Required. **Milliseconds.** |
359
+ | `delay` | number ≥0 | Milliseconds. |
360
+ | `stagger` | number ≥0 | Milliseconds between the units of a text entrance. Wins over `params.speed` (the same gap in seconds). |
361
+ | `easing` | easing | Default per preset. |
362
+
363
+ A **track** is `{ property, keyframes }`: `property` is one of `opacity`, `x`, `y`, `scale`, `rotation`,
364
+ `blur`, `trimStart`, `trimEnd`; `keyframes` has 2..240 entries `{ t, v, e? }`: `t` is 0..1, the share of the
365
+ animation's `duration`; `v` is the value (`opacity` as 0..1, `x` and `y` as canvas pixels, `scale` a factor,
366
+ `rotation` degrees, `blur` canvas pixels); `e` is the easing of the segment it starts. Values between
367
+ keyframes are straight lines unless `e` says otherwise.
368
+
369
+ An **easing** is `linear`, `ease-in`, `ease-out`, `ease-in-out`, `steps(1, end)`, or four numbers
370
+ `[x1, y1, x2, y2]` (a cubic Bézier).
371
+
372
+ **Presets.** The schema does not enumerate preset names (any string ≤64); the names a reader knows are
373
+ defined by the reader. The reference painter knows:
374
+
375
+ - `on: "loop"`: `pulse`, `float`, `bounce`, `spin`, `glow` (default durations 2, 3, 1.2, 4 and 2 seconds
376
+ when `duration` is 0);
377
+ - `on: "hover"`: `grow`, `shrink`, `lift`, `glow`;
378
+ - reveals, for a `target: "layer"` animation: `fade`, `slide-up`, `slide-down`, `slide-left`, `slide-right`,
379
+ `scale`;
380
+ - text, with a `chars`, `words` or `lines` target: `fade-chars`, `slide-up`, `bounce-chars`, `reveal-mask`,
381
+ `scale-in`, `rise-words`, `typewriter`, `wave-chars`, `glitch-cyberpunk`, `glitch-slice`.
382
+
383
+ A reader MUST ignore an animation whose preset it does not know; the file stays valid.
384
+
385
+ **Triggers.** `load` runs once when the layer is painted; `loop` repeats forever; `hover` runs while the pointer
386
+ is over the layer and reverses when it leaves; `enter` is how the layer appears (and, reversed, leaves) when an
387
+ action shows or hides it; `action` runs when a `play` action (3.13) targets the layer; `press` runs once on every
388
+ pointer press on the layer (`pointerdown`), leaves no end state and does nothing while the document is paused.
389
+ The `trimStart` and `trimEnd` tracks animate the geometry's trim (3.7) under `load`, `loop`, `hover`, `press` and
390
+ `action`; a track the animation lacks keeps the trim at rest.
391
+
392
+ **Motion.** `motion` is `{ loop?: { speedPxSec, direction?, mirror?, pauseOnHover? } }`. `loop` scrolls the
393
+ layer's content endlessly sideways: `speedPxSec` is −500..500 canvas pixels per second; `direction` is
394
+ `left_to_right` or `right_to_left` (default `right_to_left`); `mirror` mirrors every other copy so the seam
395
+ does not show (default true); `pauseOnHover` is boolean. The pointer-following parallax of 1.x does not exist in 2.0.
396
+
397
+ A reader MUST NOT animate when the host asks for no motion (the `disable-animations` attribute, or the
398
+ reader's reduced-motion preference); it paints the resting state.
399
+
400
+ ### 3.13. Interactions
401
+
402
+ `interactions` is an array (≤8) of `{ on, actions }`: `on` is `press` or `hover`; `actions` has 1..64 entries
403
+ `{ type, target, value? }`: `type` is `show`, `hide`, `toggle`, `setText` or `play`; `target` is the `id` of a
404
+ layer in the same document; `value` (≤10000 characters) is the new words for `setText`. A `press` runs its
405
+ actions and is not undone; a `hover` reverts its `show`, `hide` and `toggle` when the pointer leaves.
406
+ `setText` replaces the words of the target for the current language. `play` runs the target's animations with
407
+ `on: "action"`.
408
+
409
+ There are **no navigation actions**: an interaction cannot open a link, load a document, post a message or
410
+ change the page. This is a rule of the format, not a default (section 5.4). The reference player announces
411
+ each firing with the cancelable `oim:action` event (section 4); if the host calls `preventDefault()`, the
412
+ local effect does not run. `disable-actions` removes interactions altogether.
413
+
414
+ ### 3.14. Variables and colour bindings
415
+
416
+ `variables` is `{ modes?, defaults?, values? }`:
417
+
418
+ - `modes`: map mode name → 1..64 option names (each 1..64 characters). Two modes are meaningful:
419
+ `palette` (the named palettes) and `language`.
420
+ - `defaults`: map mode → option, for example `{ "palette": "dark" }`.
421
+ - `values`: map variable name → a string ≤256 or a number, or a map option → string ≤256 or number.
422
+
423
+ A named palette is the set of colours `values[role][paletteName]` for the colour roles of 3.9 (`primary`,
424
+ `on-primary`, …, `text-on-accent`). A colour bound by `{ "var": "<role>" }` takes the active palette's colour
425
+ for that role, else its `fallback`, else it paints nothing. The active palette is the one the host requests
426
+ (the `palette` attribute); else, when the document defines palettes named `dark` and `light`, the one that
427
+ matches the viewer's colour scheme; else `defaults.palette`. A host page may override a role with the CSS
428
+ custom property `--oim-color-<role>`.
429
+
430
+ ### 3.15. Resources
431
+
432
+ `resources` maps a name to a paint. A `{ "ref": name }` in `canvas.fills`, a layer's `fills`, a stroke's `paint`
433
+ or an image layer's `src` is replaced by that paint before painting (`resolveRefs`). A stroke whose ref is
434
+ missing is dropped; an image layer whose ref is missing or is not an image paint loses its `image` block; a
435
+ missing fill ref is dropped. A resource that points at another resource is followed at most four times.
436
+
437
+ ### 3.16. Fonts
438
+
439
+ `fonts` is an array of embedded variants:
440
+ `{ family (1..128), name, weight (integer 100..900), style (normal | italic), format (woff | woff2), data }`.
441
+ `name` MUST match `^oim-[0-9a-f]{8}-[A-Za-z0-9 ]{1,64}$` and is the face's unique registered name. `data` is
442
+ base64 and decodes to at most 400 KiB. A `woff` entry is a static instance (no `fvar`, `gvar`, `avar`, `HVAR`
443
+ or `MVAR`; `STAT` may remain) subset to the glyphs in use; writers emit `woff`, readers MUST also read `woff2`.
444
+ The decoded bytes start with the magic of the declared format (`wOFF` or `wOF2`). A reader registers each
445
+ face under its `name` before the first paint and binds a `font.family` to it; a face that fails to load falls
446
+ back to the family.
447
+
448
+ ### 3.17. Re-edit, extensions and a11y
449
+
450
+ `reedit` says who may re-edit the work: `public` (anyone), `author_only`, `sealed` (nobody). Absent, or any
451
+ other value, MUST be read as `author_only`, never as `public`. The field travels inside the file and is
452
+ covered by the signature; enforcement belongs to the registry that holds authorship, not to the reader.
453
+
454
+ `extensions` (on the document and on a layer) is the only open map: keys and values are free. A reader MUST
455
+ ignore an extension it does not know. `extensionsUsed` lists the extensions a writer used; `extensionsRequired`
456
+ those without which the work is not faithfully shown. A reader that sees a required extension it does not
457
+ implement MUST NOT paint it: it keeps showing the PNG and fires `oim:error` with `detail.code === "unsupported-extension"`
458
+ and `detail.extensions` (the names). The reference reader implements no extension, so every name in
459
+ `extensionsRequired` is unsupported. `extensionsUsed` is informative.
460
+
461
+ `a11y` (on `shape` and `image`) is `{ alt?: map language → string, decorative?: boolean }`. A decorative
462
+ layer is hidden from assistive technology; otherwise a reader SHOULD expose `alt` for the current language, and
463
+ the document's `description`.
464
+
465
+ ### 3.18. Complete example
466
+
467
+ ```json
468
+ {
469
+ "oim": "2.0.0",
470
+ "name": "Sale",
471
+ "description": { "en": "A sale poster", "es": "Un cartel de rebajas" },
472
+ "canvas": { "width": 1080, "height": 1080, "fills": [{ "kind": "color", "value": "#101014" }] },
473
+ "languages": ["en", "es"],
474
+ "variables": {
475
+ "modes": { "palette": ["dark", "light"] },
476
+ "defaults": { "palette": "dark" },
477
+ "values": { "accent": { "dark": "#ffffff", "light": "#101014" } }
478
+ },
479
+ "resources": { "wash": { "kind": "gradient", "gradient": { "type": "linear", "angle": 90, "stops": [{ "color": "#1c1c24", "at": 0 }, { "color": "#101014", "at": 1 }] } } },
480
+ "layers": [
481
+ {
482
+ "id": "card", "type": "shape", "name": "Card",
483
+ "box": { "x": 140, "y": 300, "width": 800, "height": 420 },
484
+ "geometry": { "kind": "rect" },
485
+ "corners": 32,
486
+ "fills": [{ "ref": "wash" }],
487
+ "strokes": [{ "paint": { "kind": "color", "value": { "var": "accent", "fallback": "#ffffff" } }, "width": 2, "align": "inside" }],
488
+ "effects": [{ "kind": "shadow", "y": 12, "blur": 40, "color": "rgba(0, 0, 0, 0.5)" }],
489
+ "a11y": { "decorative": true }
490
+ },
491
+ {
492
+ "id": "headline", "type": "text",
493
+ "box": { "x": 540, "y": 460, "width": 700, "anchor": "center" },
494
+ "text": {
495
+ "content": { "en": "Big {sale}", "es": "Gran {sale}" },
496
+ "font": { "family": "Inter", "size": { "value": 96, "modes": { "es": 88 } }, "weight": 700 },
497
+ "align": "center",
498
+ "marks": { "sale": { "italic": true } }
499
+ },
500
+ "animations": [{ "on": "load", "target": "words", "preset": "rise-words", "duration": 600, "stagger": 80 }],
501
+ "interactions": [{ "on": "press", "actions": [{ "type": "toggle", "target": "badge" }] }]
502
+ },
503
+ {
504
+ "id": "badge", "type": "shape",
505
+ "box": { "x": 540, "y": 640, "width": 160, "height": 60, "anchor": "center" },
506
+ "geometry": { "kind": "preset", "name": "pill" },
507
+ "fills": [{ "kind": "color", "value": "#ffffff" }],
508
+ "visible": false,
509
+ "animations": [{ "on": "enter", "preset": "scale", "duration": 250 }]
510
+ }
511
+ ],
512
+ "reedit": "author_only"
513
+ }
514
+ ```
515
+
516
+ ---
517
+
518
+ ## 4. Rendering model
519
+
520
+ [`SPEC_2.md`](SPEC_2.md) is the rendering reference; it, the vectors and their goldens
521
+ (`vectors-2/golden`) are the executable check. This section summarises the rules a reader applies.
522
+
523
+ 1. **Coordinates.** Everything is in design pixels of the canvas. `box.x`/`y` is the top-left corner of the
524
+ painted rectangle, unless `anchor` moves the anchor point to `x, y` (3.3). The reader scales the canvas to
525
+ its container preserving the aspect ratio and centres it; there is no relative unit in the document.
526
+ 2. **Paint order.** `canvas.fills` first, then `layers` in array order, bottom to top. Inside a group, its
527
+ `children` in array order. There is no z-index. Within a layer: its fills (first at the bottom), then
528
+ its strokes, then its effects over the result.
529
+ 3. **Transform.** The box is placed (position, then anchor shift, then `rotation`, then `flipX`/`flipY`);
530
+ the layer's animations move it relative to that.
531
+ 4. **Strokes.** `align: center` (the default) straddles the geometry's edge, half inside and half outside;
532
+ `inside` and `outside` put the stroke wholly on that side. The box never changes size because of a stroke.
533
+ A 400 × 200 box at (80, 80) with a 10 px stroke reaches x 75–485 (`center`), 80–480 (`inside`) or 70–490
534
+ (`outside`).
535
+ 5. **Text.** A text with no `runs` is aligned by `text.align` and centred vertically in its box. A text
536
+ with no `width` fits its content, grown from its anchor.
537
+ 6. **Opacity and blend.** `opacity` and `blend` apply to the layer as a whole (children included). A layer
538
+ blends with the layers under it inside the canvas, never with the page behind the reader.
539
+ 7. **Language.** One language is selected for the whole document (3.9) and used for every text, exception and
540
+ picture. A layer's `languages` list, when present, restricts the layer to those languages (compared without
541
+ regard to case, and by primary subtag as the document language is chosen: `en` matches `en-US` and `en-GB`): out of them it is hidden, and no action shows it until the language changes.
542
+ 8. **Hidden.** A `visible: false` layer is not shown until an action shows it.
543
+ 9. **Base picture.** See 2.4.
544
+ 10. **Motion.** A reader paints the resting state when motion is disabled, and runs no animation while the
545
+ host has paused it.
546
+
547
+ ### The reference player (informative)
548
+
549
+ `@oim-media/player-oim` defines the custom element `<oim-player>`.
550
+
551
+ - Attributes: `src`, `placeholder`, `poster`, `lang`, `activate-on`, `fit`, `align`, `dropdown-blur`,
552
+ `allow-lottie`, `palette`, `auto-rotate-lang`, `disable-animations`, `disable-actions`, `mode`, `show-slots`.
553
+ `allow-lottie` is off unless set; `mode="full"` enables animation and actions, and the default shows a
554
+ still image with its language.
555
+ - Events (bubbling from the element): `oim:loaded` (`detail`: `type`, `metadata`, `security`), `oim:error`
556
+ (`detail`: `code`, `message`; codes include `unsupported-version`, `unsupported-extension` and `chunk`), `oim:action` (cancelable;
557
+ `detail`: `slot`, `name`, `trigger`, `targets`, `types`), `oim:langchange` (`detail.lang`). `oim:incomplete`
558
+ and `oim:unsupported` report the 1.x `capabilities` and `min_player` fields and do not apply to a strict 2.0
559
+ document.
560
+
561
+ ---
562
+
563
+ ## 5. Security
564
+
565
+ A `.oim` is foreign data and travels to third parties. A reader treats everything in it as untrusted.
566
+
567
+ ### 5.1. Strict objects and sanitised strings
568
+
569
+ Every object is strict (section 3). Only `id` (document and layer) and `text.font.family` reject `<`, `>`, `"` and control characters (U+0000–U+001F, U+007F) so they can
570
+ never become markup or an attribute break. A layer `name` (max 256) and the `family` of an embedded font (max 128) are not restricted this way, which is one more reason a reader treats every string as plain text. A reader MUST NOT insert a document string as HTML: text is set as plain text.
571
+
572
+ ### 5.2. Colours
573
+
574
+ Every colour passes the whitelist of 3.5. A reader MUST NOT paint a colour that does not match it, and MUST NOT
575
+ splice a document string into CSS other than through that whitelist. Free CSS is not part of the format.
576
+
577
+ ### 5.3. Limits
578
+
579
+ | Limit | Value | Where |
580
+ |---|---|---|
581
+ | Layers per list (`layers`, each `children`) | 150 (`MAX_SLOTS`) | schema, player, signer |
582
+ | Layers in a document, groups included | 1000 (`MAX_TOTAL_LAYERS`) | player (and any signer) |
583
+ | Group nesting depth, top level = 1 | 32 (`MAX_LAYER_DEPTH`) | player |
584
+ | Decompressed document | 10 MiB | reader (section 2.2) |
585
+ | `fills` / `strokes` per layer | 8 / 8 | schema |
586
+ | `effects`, `animations` per layer | 16 / 16 | schema |
587
+ | `interactions` per layer; `actions` per interaction | 8; 64 | schema |
588
+ | Tracks per animation; keyframes per track | 16; 2..240 | schema |
589
+ | Gradient stops | 2..32 | schema |
590
+ | Pattern `colors`, `sizes`, `counts`, `dispersions`, `svgs` | ≤16 each | schema |
591
+ | Paths per `paths` geometry; per pattern `tile` | 1..2000; 1..64 | schema |
592
+ | `languages` (document, layer) | 1..64 entries of 1..16 characters | schema |
593
+ | Variable modes | ≤64 options of ≤64 characters | schema |
594
+ | Embedded font data | 400 KiB decoded | schema |
595
+ | Colour string; `id`; layer `name` | 128; 128; 256 | schema |
596
+ | Interaction `value`; document `description` per language | 10000; 1000 | schema |
597
+
598
+ A document over the limits of 150 layers per list, 1000 in total, nesting depth 32 or the 10 MiB cap is corrupt.
599
+ The reader MUST refuse it before it paints and before it copies it in full (this is what the player's
600
+ `validateOimMetadata` checks). For every other limit in the table, writers MUST respect it and a signer MUST
601
+ refuse a document over it; a reader is not required to check them.
602
+ A signer MUST NOT sign a document over any limit. A signer MAY set lower limits; it MUST NOT set higher ones, because a file no reader
603
+ shows is worse than a refusal. The total and depth limits are checked by the player's validation, not by
604
+ `documentSchema`.
605
+
606
+ ### 5.4. No network, no navigation
607
+
608
+ A reader MUST NOT make any request because a file asks it to, or reveal who is looking at it.
609
+
610
+ - Image sources are inline: `oim:base`, or `data:image/{png,jpeg,jpg,webp,gif};base64,…`. An `http(s)` URL,
611
+ a relative path or any other scheme is not a picture source and MUST NOT be fetched.
612
+ - A Lottie layer carries its animation inline (JSON, or a JSON `data:` URL); a reader MUST NOT fetch a URL there,
613
+ runs it without expressions or `eval`, and does so only when the host allows it (`allow-lottie`).
614
+ - Fonts are embedded (3.16); a reader MUST NOT fetch one from a CDN for a family the file carries.
615
+ - Interactions cannot navigate (3.13).
616
+ - Besides loading the file itself, the only thing a reader asks the network for is the signer's public keys,
617
+ and only when a signature names a key it does not embed (section 6.3).
618
+
619
+ ### 5.5. Unsigned and altered files
620
+
621
+ A file that is unsigned shows its PNG and no layer. A file whose signature or image seal fails is refused.
622
+ Section 6.4.
623
+
624
+ ---
625
+
626
+ ## 6. Signing
627
+
628
+ ### 6.1. Fields
629
+
630
+ A signed document carries at the root: `image_hash`, `image_hash_alg`, `signed_at`, `signature`,
631
+ `key_version`, and the signer's `timestamp` (outside the signature).
632
+
633
+ ### 6.2. The canonical form
634
+
635
+ The bytes that are signed are the **canonical form** of the document, implemented by `serializeCanonical`
636
+ (`canonical.ts`) and the same in every implementation (`canonical-cases.json` is the known-answer test). It
637
+ is the profile of [BINARY_SPEC.md](BINARY_SPEC.md) section 5.1, **not** RFC 8785:
638
+
639
+ 1. Take the decoded document.
640
+ 2. Remove from the root only `signature`, `key_version`, `timestamp` and `creator_user_id`. (`signed_at`,
641
+ `image_hash` and `image_hash_alg` stay in and are covered.) The same names nested elsewhere are kept.
642
+ 3. Numbers: a number with an integer value is written as an integer (`2.0` and `-0.0` become `2`, `0`); any other
643
+ is rounded to at most 6 decimal places. Every number at any depth MUST be finite and not exceed ±(2⁵³ − 1);
644
+ otherwise there is no canonical form: a signer MUST refuse the document and a verifier MUST treat the
645
+ signature as invalid.
646
+ 4. Object keys, at every depth, are ordered by ascending Unicode code point (not UTF-16 code unit).
647
+ Array order is kept.
648
+ 5. Compact JSON: no whitespace outside strings.
649
+ 6. Non-ASCII characters are written as UTF-8, never as `\uXXXX` escapes.
650
+ 7. The result is encoded as UTF-8.
651
+
652
+ ### 6.3. The signature
653
+
654
+ - Algorithm: ECDSA over NIST P-256 with SHA-256.
655
+ - Value: the 64 bytes `r ‖ s` (IEEE P1363, not ASN.1 DER), base64-encoded, in `signature`.
656
+ - `key_version` names the signing key (`kid`), for example `v1` or `v2`. `signed_at` is an ISO 8601 timestamp with
657
+ seconds and a time-zone designator, written by the signer and inside the signed bytes.
658
+ - The public keys are published in [`keys.json`](keys.json) and by the signer at
659
+ `https://api.oim.media/v1/media/keys`. A reader embeds the keys it knows and fetches the list only for a
660
+ `key_version` it does not.
661
+
662
+ ### 6.4. Verification
663
+
664
+ A reader verifies in this order:
665
+
666
+ 1. Extract the document (section 2). No document: the file is a plain image (`no_metadata`).
667
+ 2. Validate the limits of section 5.3. A violation: `corrupt`, refuse.
668
+ 3. If `signature` or `key_version` is absent: `unsigned`.
669
+ 4. Otherwise rebuild the canonical form (6.2) and verify the signature with the key `key_version`. A number with
670
+ no canonical form, an unknown key, or a failed verification: `invalid_signature`, refuse. When the
671
+ embedded key fails, the reader MAY retry once with the key the server publishes for the same `kid`.
672
+ (Informative: for older files the reference player also retries when the document has `creator_user_id`,
673
+ keeping that field and using UTF-16 key order with no number normalisation. Writers and signers MUST NOT rely on it.)
674
+ 5. If the key was retired (`not_after` earlier than `signed_at`) the signature is invalid. A key the player no
675
+ longer trusts by its own clock (`verify_until`) gives `expired_key`.
676
+ 6. Compute the image seal (6.5). If `image_hash_alg` is `sha256-idat` and `image_hash` is a string, they MUST
677
+ equal the computed hash, compared case-insensitively; otherwise `image_mismatch`, refuse. If the seal is
678
+ absent, the result is the weaker `image_unsealed`.
679
+ 7. Otherwise the file is `verified`, or `verified_authorless` when its `reedit` is `public` (a public file can be
680
+ re-signed by anyone, so it earns a weaker stamp).
681
+
682
+ What the reader does with each result:
683
+
684
+ | Result | Reader behaviour |
685
+ |---|---|
686
+ | `verified`, `verified_authorless`, `image_unsealed` | Paints the layers. |
687
+ | `unsigned`, `expired_key` | Shows the PNG and paints no layer. |
688
+ | `no_metadata` | Shows the PNG. |
689
+ | `invalid_signature`, `image_mismatch`, `corrupt` | Refuses the file: it is not shown as the work (the reference player raises an error and reports a tampered or corrupt file). |
690
+
691
+ ### 6.5. The image seal
692
+
693
+ `image_hash` is the SHA-256, as 64 lowercase hexadecimal characters, of the concatenation, in file order, of the
694
+ payloads (`Data` only) of every `IDAT` chunk. `image_hash_alg` is the literal `sha256-idat`. Because the
695
+ signature covers `image_hash`, a signed document cannot be pasted onto a different image. A signer MUST compute
696
+ the hash from the PNG it embeds; a hash supplied by the caller proves nothing.
697
+
698
+ Embedding the document changes no `IDAT` byte.
699
+
700
+ ---
701
+
702
+ ## 7. Conformance
703
+
704
+ The 2.0 conformance corpus is `vectors-2/`: 48 signed `.oim.png` files that exercise text and multilingual
705
+ content, strokes, effects, masks, patterns, generative and image fills, animation presets, interactions, groups,
706
+ loops, palettes, fonts and re-edit. Each has a golden image `vectors-2/golden/<name>.web.png` rendered by the web
707
+ reference (one vector, `background-pattern-order`, has none yet). A vector has no `.expected.json`: the
708
+ expectation is the golden. Known differences of a renderer go in an `exceptions.json` beside the goldens, with a
709
+ reason; an excepted vector that passes fails the run (`vectors-2/golden` has none today).
710
+
711
+ Procedure (800 px wide, device pixel ratio 1, animations disabled, white background, `sans-serif` host font),
712
+ metric (pixel channel difference above 40, 3 × 3 erosion, fail above 0.4 % area or a 576 px blob) and
713
+ calibration are those of [CANONICAL_SPEC.md](CANONICAL_SPEC.md) section 9.1 and `tools/parity-core.mjs`.
714
+
715
+ ```bash
716
+ pnpm --filter @oim-media/spec parity:v2 # web player against the goldens
717
+ pnpm --filter @oim-media/spec parity:scene # scene painter against the goldens
718
+ pnpm conformance # 1.x vectors upgrade to valid 2.0 documents, canonical form
719
+ pnpm --filter @oim-media/core exec vitest run
720
+ ```
721
+
722
+ A reader in another language writes `<vector>.png` per vector following the procedure and compares with
723
+ `node packages/spec/tools/parity.mjs <renders-dir> --renderer <name> --out <diff-dir>`.
724
+
725
+ A writer is checked by validating its documents against `schema/oim2.schema.json` (generated from
726
+ `documentSchema`; a test fails if the two drift). Every JSON example in this document validates against
727
+ `documentSchema`.
728
+
729
+ ---
730
+
731
+ ## 8. Appendix A: differences from 1.x
732
+
733
+ | Topic | 1.x | 2.0 |
734
+ |---|---|---|
735
+ | Root | `slots`, `zones`, `lang`, `canvas.natural_*`, `media_type`, `min_player`, `capabilities` | `layers` (tree), `languages`, `canvas.width/height`; no capability list; extensions |
736
+ | Layer types | `text`, `image`, `lottie`, `geo`, `shape`, `draw`, `svg`, `artistic-text`, `pattern`, `filter`, `container`, `group`, `component`, `mask`, `zone` | `text`, `shape`, `image`, `lottie`, `group`; the rest are blocks (`mask`, `text.artistic`, pattern/texture paints, `filter` effect) |
737
+ | Position | `position` in percent, `width_px`, `cqw` units | `box` in design pixels, `anchor` |
738
+ | Style | one flat `style` object | one block per idea, only on the types that admit it |
739
+ | Hierarchy | `groupId`, `childIds`, `zone_id` | `children` |
740
+ | Paint order | `slots` order, background pattern always behind | array order, no exception |
741
+ | Colours | `fillColor`, `*Role` fields, `palettes` | `{ var }` bindings, `variables.modes.palette` |
742
+ | Opacity | 0..100 | 0..1 |
743
+ | Animation | `loop`/`hover` presets in seconds, keyframes `t` in seconds, `reveal`, `textAnimationType` | `animations` in milliseconds with `on`, `preset` or `tracks`, `t` as 0..1 |
744
+ | Pointer parallax | `parallax` | retired; only the endless `motion.loop` remains |
745
+ | Interaction | `isInteractive`, `states.hover/active` | `interactions` with `press`/`hover`; no navigation |
746
+ | Re-edit | `reedit` and `immutable_lock` | `reedit` only |
747
+ | Unknown keys | passed through | validation error (except `extensions`) |
748
+ | PNG | the picture painted under the slots | `oim:base` layer, or a poster |
749
+ | Container | `tEXt` base64 deflate, later `zTXt`; `OIM_Seal` 1.30–1.32 | `zTXt` `OIM_Data`; `OIM_Seal` retired |
750
+ | Readers | paint 1.x | do not paint 1.x; `unsupported-version` |
751
+
752
+ ---
753
+
754
+ ## 9. Appendix B: retired in 2.0
755
+
756
+ `textRole`, `textHighlight` (whole-text highlight stays only as `text.highlight`), `custom_loop_css`,
757
+ `custom_keyframes`, `parallax` (pointer), `blur-chars`, `reedicion` (Spanish alias), `allowed_domains`,
758
+ `elements`, short slot aliases (`p`, `s`, `st`, `c`, `t`), `OIM_Seal`. `upgrade()` reports what it dropped in
759
+ `retired` and anything it could not convert in `unhandled`.
760
+
761
+ ---
762
+
763
+ ## 10. Appendix C: where the code is
764
+
765
+ | Subject | File |
766
+ |---|---|
767
+ | Document schema | `packages/core/src/v2/schema.ts`, `layer-blocks.ts` |
768
+ | 1.x → 2.0 | `packages/core/src/v2/upgrade.ts`, `upgrade/` |
769
+ | Limits | `packages/core/src/limits.ts` |
770
+ | Container | `packages/core/src/binary.ts` |
771
+ | Canonical form | `packages/core/src/canonical.ts` |
772
+ | Verification | `packages/player-oim/src/render/security.ts`, `keys.ts` |
773
+ | Painting | `packages/scene/src` |
774
+
775
+ ---
776
+
777
+ ## 11. Appendix D: what the schema allows and the reference painter does not draw
778
+
779
+ Checked against the working tree that follows release 1.36.2. A reader that does not draw one of these is still
780
+ conforming to the schema; a writer SHOULD NOT rely on them being painted.
781
+
782
+ - A gradient paint with `preset` and no `gradient`: the reference painter reads the preset only for an artistic
783
+ text (`text.artistic`), where it names the gradient type. On any other fill it draws nothing; writers SHOULD
784
+ give an explicit `gradient`. (Kept in the schema because a signed vector, `artistic-text`, uses it.)
785
+ - Length bindings `{ var }` for `font.size`, `maxWidth` and a stroke's `width` are not resolved; literals and
786
+ `{ value, modes }` are. Nothing in this repository writes them. Readers MAY ignore them; colour bindings are
787
+ resolved.
788
+ - A `{ ref }` chain through several resources beyond four steps: not drawn.
789
+ - Text marks in 2.0 are not limited by the schema to the 1.x pattern `^[a-z][a-z0-9-]{0,23}$` and 8 per
790
+ layer; writers SHOULD respect them because the shared parser of `{name}…{/name}` does.
791
+ - A trim is not drawn on a rectangle (a box, no outline) or on a drawing of several paths.
792
+ - A trimmed stroke drops a dashed or dotted style; the trim replaces it.
793
+ - A `geometry.trim` stroke (or one under a `trimStart` / `trimEnd` track) is drawn without `vector-effect: non-scaling-stroke` (the browser ignores
794
+ `pathLength` under it), so its width scales with the figure's box.
795
+ - A feathered cutout edge is drawn hard.
796
+ - The reference player does not check the per-layer schema limits (fills, strokes, effects, animations, interactions, actions, tracks, keyframes, gradient stops, paths and the like); only 150 per list, 1000 total, depth 32 and 10 MiB.
797
+
798
+ Painted since the draft of this appendix: `geometry.trim` and the `trimStart` / `trimEnd` tracks, an animation
799
+ `on: "press"`, `animation.stagger`, a layer's own `languages`, `extensionsRequired` (refusal), and a cutout mask
800
+ inside a group. The root `timestamp` is part of the schema (section 1.2).
package/README.md CHANGED
@@ -6,12 +6,15 @@ TypeScript.
6
6
 
7
7
  ```
8
8
  BINARY_SPEC.md Binary layout of the PNG container, compression and the image seal.
9
- CANONICAL_SPEC.md Canonical form of the metadata, the bytes a signature covers.
9
+ CANONICAL_SPEC_2.md Canonical specification of OIM 2.0 (the current format): container, document, security, signing.
10
+ SPEC_2.md 2.0 rendering rules (box, strokes, text, opacity and blend).
11
+ CANONICAL_SPEC.md Canonical specification of 1.x (legacy, no longer painted): metadata and the bytes a signature covers.
10
12
  schema/ oim.schema.json and ovm.schema.json: JSON Schema, generated from @oim-media/core.
11
13
  keys.json Public keys every player embeds (kid, jwk and key dates). Public parts only.
12
14
  marks-cases.json Known-answer cases for text marks, shared with the backend's validator tests.
13
15
  canonical-cases.json Known-answer case for the canonical form, checked by the TypeScript, Rust and Dart implementations.
14
- schema/oim2.schema.json Draft of the 2.0 document, generated from @oim-media/core/v2. Not the published format.
16
+ schema/oim2.schema.json The 2.0 document, generated from @oim-media/core/v2.
17
+ vectors-2/ 48 signed 2.0 .oim files with web goldens (golden/).
15
18
  vectors/ 39 signed .oim files, each with <name>.expected.json.
16
19
  tools/ Read-only checks: contract-summary.mjs, canonical-check.mjs, style-usage.mjs.
17
20
  ```
@@ -20,7 +23,7 @@ Published as `@oim-media/spec`. The tarball carries the schema, the vectors, bot
20
23
  specifications, `keys.json`, `marks-cases.json`, this README, LICENSE and NOTICE.
21
24
 
22
25
 
23
- **2.0 rendering rules:** [SPEC_2.md](SPEC_2.md).
26
+ **2.0:** the normative text is [CANONICAL_SPEC_2.md](CANONICAL_SPEC_2.md); the rendering rules are [SPEC_2.md](SPEC_2.md).
24
27
 
25
28
  ## Versioning
26
29
 
@@ -272,11 +275,11 @@ overrides all of them.
272
275
  A 1.20.0 file read by an earlier player is shown with each layer's fixed
273
276
  colours. Nothing breaks.
274
277
 
275
- ## The 2.0 draft
278
+ ## The 2.0 document
276
279
 
277
- `schema/oim2.schema.json` is the next version of the document, still a draft: no player reads it and
278
- it can change. `@oim-media/core/v2` exports `upgrade`, which reads any 1.x document as 2.0, and the
279
- conformance gate checks that every vector upgrades to a valid 2.0 document with no key left behind.
280
+ `schema/oim2.schema.json` is the 2.0 document, specified in [CANONICAL_SPEC_2.md](CANONICAL_SPEC_2.md). Players
281
+ paint 2.0 only; a 1.x file is not painted. `@oim-media/core/v2` exports `upgrade`, which reads any 1.x document
282
+ as 2.0, and the conformance gate checks that every 1.x vector upgrades to a valid 2.0 document with no key left behind.
280
283
 
281
284
  ```
282
285
  node tools/upgrade-report.mjs --vectors # the same check, as a report
package/SPEC_2.md ADDED
@@ -0,0 +1,42 @@
1
+ <!--
2
+ Copyright (c) 2026 Xue Studios LLC
3
+ SPDX-License-Identifier: Apache-2.0
4
+ -->
5
+
6
+ # OIM 2.0 — Rendering rules
7
+
8
+ The 2.0 contract describes what is painted, not how a browser paints it. Every reader
9
+ (web, Flutter, native) applies these rules with its own tools, and the 2.0 goldens
10
+ (`vectors-2/golden`) are the executable check. 1.x files are not painted by readers:
11
+ they are upgraded once by a tool (`oim upgrade`, or the editor on import).
12
+
13
+ ## Box
14
+
15
+ `box` is the painted rectangle: `x`/`y` is its top-left corner in design pixels and
16
+ `width`/`height` its size. There is no implicit centring and no relative unit.
17
+ `anchor` (a text fitted to its content) is the only case where `x`/`y` is an anchor
18
+ point instead of a corner.
19
+
20
+ ## Strokes
21
+
22
+ By default (`align` absent or `"center"`) a stroke is centred on the geometry's edge:
23
+ half inside, half outside. `"inside"` puts it wholly inside, `"outside"` wholly
24
+ outside. The box never changes size because of a stroke.
25
+
26
+ Example: a 400 × 200 box at (80, 80) with a 10 px stroke. The stroke's outer edges are
27
+
28
+ | `align` | x | y |
29
+ |---|---|---|
30
+ | `center` | 75 – 485 | 75 – 285 |
31
+ | `inside` | 80 – 480 | 80 – 280 |
32
+ | `outside` | 70 – 490 | 70 – 290 |
33
+
34
+ ## Text without runs
35
+
36
+ A text with no `textRuns` is aligned by `text.align` and centred vertically in its box.
37
+
38
+ ## Opacity and blend
39
+
40
+ `opacity` and `blend` apply to the layer as a whole. A layer blends with the layers
41
+ painted under it inside the canvas, never with the page behind the reader. (The 1.x web
42
+ player lost `blend` inside its stacking wrappers; 2.0 readers paint it.)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oim-media/spec",
3
- "version": "1.35.2",
3
+ "version": "1.36.2",
4
4
  "description": "OIM format contract: JSON Schema, normative specification and conformance vectors that every OIM player must pass.",
5
5
  "keywords": [
6
6
  "oim",
@@ -17,6 +17,8 @@
17
17
  "vectors-2",
18
18
  "BINARY_SPEC.md",
19
19
  "CANONICAL_SPEC.md",
20
+ "CANONICAL_SPEC_2.md",
21
+ "SPEC_2.md",
20
22
  "README.md",
21
23
  "marks-cases.json",
22
24
  "canonical-cases.json",
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://oim.media/spec/1.35.2/oim.schema.json",
3
+ "$id": "https://oim.media/spec/1.36.2/oim.schema.json",
4
4
  "title": "OIM document metadata",
5
- "specVersion": "1.35.2",
5
+ "specVersion": "1.36.2",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "description": {
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://oim.media/spec/2.0.0-draft.1/oim.schema.json",
4
- "title": "OIM document 2.0 (draft)",
5
- "specVersion": "2.0.0-draft.1",
3
+ "$id": "https://oim.media/spec/2.0.0/oim.schema.json",
4
+ "title": "OIM document 2.0",
5
+ "specVersion": "2.0.0",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "oim": {
@@ -61,6 +61,9 @@
61
61
  },
62
62
  "signed_at": {
63
63
  "$ref": "#/$defs/__schema94"
64
+ },
65
+ "timestamp": {
66
+ "$ref": "#/$defs/__schema95"
64
67
  }
65
68
  },
66
69
  "required": [
@@ -2802,6 +2805,9 @@
2802
2805
  },
2803
2806
  "__schema94": {
2804
2807
  "type": "string"
2808
+ },
2809
+ "__schema95": {
2810
+ "type": "string"
2805
2811
  }
2806
2812
  }
2807
2813
  }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://oim.media/spec/1.35.2/ovm.schema.json",
3
+ "$id": "https://oim.media/spec/1.36.2/ovm.schema.json",
4
4
  "title": "OVM document metadata",
5
- "specVersion": "1.35.2",
5
+ "specVersion": "1.36.2",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "ovm_version": {