@oim-media/core 1.27.8 → 1.27.10

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.
Files changed (57) hide show
  1. package/LICENSE +55 -55
  2. package/NOTICE +6 -6
  3. package/README.md +158 -134
  4. package/dist/canonical.d.ts +25 -0
  5. package/dist/canonical.js +18 -1
  6. package/dist/compatibility.d.ts +1 -1
  7. package/dist/compatibility.js +3 -1
  8. package/dist/generative/primitives/blob.js +4 -4
  9. package/dist/generative/primitives/iso-grid.js +7 -7
  10. package/dist/generative/primitives/mesh.js +3 -3
  11. package/dist/parallaxCss.js +8 -8
  12. package/dist/patterns.js +9 -9
  13. package/dist/v2/geometry-outline.d.ts +23 -0
  14. package/dist/v2/geometry-outline.js +35 -0
  15. package/dist/v2/index.d.ts +10 -0
  16. package/dist/v2/index.js +11 -0
  17. package/dist/v2/layer-blocks.d.ts +11 -0
  18. package/dist/v2/layer-blocks.js +34 -0
  19. package/dist/v2/paint-css.d.ts +46 -0
  20. package/dist/v2/paint-css.js +109 -0
  21. package/dist/v2/schema.d.ts +1180 -0
  22. package/dist/v2/schema.js +433 -0
  23. package/dist/v2/upgrade/animations.d.ts +7 -0
  24. package/dist/v2/upgrade/animations.js +255 -0
  25. package/dist/v2/upgrade/box.d.ts +10 -0
  26. package/dist/v2/upgrade/box.js +119 -0
  27. package/dist/v2/upgrade/context.d.ts +42 -0
  28. package/dist/v2/upgrade/context.js +54 -0
  29. package/dist/v2/upgrade/effects.d.ts +25 -0
  30. package/dist/v2/upgrade/effects.js +204 -0
  31. package/dist/v2/upgrade/geometry.d.ts +9 -0
  32. package/dist/v2/upgrade/geometry.js +162 -0
  33. package/dist/v2/upgrade/gradient.d.ts +14 -0
  34. package/dist/v2/upgrade/gradient.js +79 -0
  35. package/dist/v2/upgrade/keys.d.ts +9 -0
  36. package/dist/v2/upgrade/keys.js +31 -0
  37. package/dist/v2/upgrade/mask.d.ts +7 -0
  38. package/dist/v2/upgrade/mask.js +64 -0
  39. package/dist/v2/upgrade/paints.d.ts +21 -0
  40. package/dist/v2/upgrade/paints.js +258 -0
  41. package/dist/v2/upgrade/root.d.ts +21 -0
  42. package/dist/v2/upgrade/root.js +94 -0
  43. package/dist/v2/upgrade/svg-paths.d.ts +38 -0
  44. package/dist/v2/upgrade/svg-paths.js +225 -0
  45. package/dist/v2/upgrade/text.d.ts +7 -0
  46. package/dist/v2/upgrade/text.js +132 -0
  47. package/dist/v2/upgrade/tree.d.ts +15 -0
  48. package/dist/v2/upgrade/tree.js +49 -0
  49. package/dist/v2/upgrade/variables.d.ts +8 -0
  50. package/dist/v2/upgrade/variables.js +24 -0
  51. package/dist/v2/upgrade/zones.d.ts +12 -0
  52. package/dist/v2/upgrade/zones.js +63 -0
  53. package/dist/v2/upgrade.d.ts +17 -0
  54. package/dist/v2/upgrade.js +143 -0
  55. package/dist/v2/version.d.ts +6 -0
  56. package/dist/v2/version.js +7 -0
  57. package/package.json +6 -2
package/LICENSE CHANGED
@@ -1,55 +1,55 @@
1
- Apache License
2
-
3
- Version 2.0, January 2004
4
-
5
- http://www.apache.org/licenses/
6
-
7
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
-
9
- 1. Definitions.
10
-
11
- "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
-
17
- "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
-
19
- "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
-
21
- "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
-
23
- "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
-
25
- "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
-
27
- "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
-
29
- "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
-
31
- 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
-
33
- 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
-
35
- 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
-
37
- You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
-
39
- You must cause any modified files to carry prominent notices stating that You changed the files; and
40
-
41
- You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42
-
43
- If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
-
45
- 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
-
47
- 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
-
49
- 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
-
51
- 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
-
53
- 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
-
55
- END OF TERMS AND CONDITIONS
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
+
19
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
+
21
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
+
23
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
+
25
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
+
27
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
+
29
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
+
31
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
+
35
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
+
37
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
+
39
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
40
+
41
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42
+
43
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
package/NOTICE CHANGED
@@ -1,6 +1,6 @@
1
- OIM Ecosystem
2
- Copyright 2026 Xue Studios LLC
3
-
4
- This product includes software developed at Xue Studios LLC.
5
-
6
- "OIM" and the "OIM compatible" mark are not licensed under Apache-2.0.
1
+ OIM Ecosystem
2
+ Copyright 2026 Xue Studios LLC
3
+
4
+ This product includes software developed at Xue Studios LLC.
5
+
6
+ "OIM" and the "OIM compatible" mark are not licensed under Apache-2.0.
package/README.md CHANGED
@@ -1,134 +1,158 @@
1
- # @oim-media/core
2
-
3
- The shared core of the [OIM format](../../README.md): the contract schema, the
4
- reader for the `.oim` container, the canonical form that signatures cover, and
5
- the rendering rules that every player must apply the same way.
6
-
7
- It is what the web players and the signing backend build on. You need it if you
8
- read or write `.oim` metadata from TypeScript or JavaScript. You do not need it to
9
- embed a file in a page; for that use [`@oim-media/player-oim`](../player-oim/README.md).
10
-
11
- ```bash
12
- pnpm add @oim-media/core
13
- ```
14
-
15
- The package is published to GitHub Packages. See the [install instructions](../../README.md#install).
16
-
17
- It needs `crypto.subtle`, `Blob`, `DecompressionStream` and `TextDecoder`, which current
18
- browsers and recent Node.js provide. It is ESM only and declares `sideEffects: false`, so
19
- bundlers can drop what you do not import.
20
-
21
- ## What it exports
22
-
23
- The root entry (`@oim-media/core`) re-exports everything below. Two subpaths
24
- exist for code that must stay light: `@oim-media/core/api` (backend routes and
25
- URLs only) and `@oim-media/core/generative` and `@oim-media/core/generative/catalog`.
26
-
27
- **Contract and validation**
28
-
29
- - `OimMetadataSchema`, `OvmMetadataSchema`, `OIMOrOVMMetadata`: Zod schemas of the
30
- metadata. Types `OIMMetadata`, `OVMMetadata`, `Slot`, `TextMark`, `Reveal`, ...
31
- - `CONTRACT_VERSION`: the contract version this build implements (`"1.27.8"`).
32
- - `BASE_CONTRACT_VERSION`, `PLAYER_CAPABILITIES`, `VERSION_BY_CAPABILITY`, `minVersionFor`.
33
- - `MAX_SLOTS`, `MAX_MARKS`, `MARK_NAME`, `PALETTE_NAME_PATTERN`, `CSS_GRADIENT_PATTERN`.
34
-
35
- **Binary: reading and writing the container**
36
-
37
- - `extractOIM(blob)`: returns `{ image, metadata, imageHash }`, where `image` is the PNG without the metadata chunk.
38
- - `extractOIMMetadataFromStream(stream)`: metadata from a stream, reading only as far as needed.
39
- - `fetchMetadataTail(url, tailBytes?)`: metadata from the end of a remote file with a range request.
40
- - `compressAndEncodeJSON(obj)` and `decodeAndDecompressJSON(base64)`, `decompressBytes(bytes, format)`.
41
- - `imageDataHash(arrayBuffer)`: SHA-256 (hex) of the PNG `IDAT` payloads. This is the image seal.
42
-
43
- **Canonical form (the bytes a signature covers)**
44
-
45
- - `serializeCanonical(metadata)`: returns the `Uint8Array` the signer hashes.
46
- - `normalizeCanonicalNumbers(value)` and `sortKeysByCodePoint(value)`: the two rules used by `serializeCanonical`.
47
-
48
- Signature *verification* is not in this package. The player verifies with its
49
- embedded keys (see [`@oim-media/spec`](../spec/README.md#embedded-player-keys)).
50
-
51
- **Compatibility**
52
-
53
- - `whatTheReaderCannotDo(metadata, { version, capabilities })`: returns a
54
- `MissingSupport` report (required version, missing capabilities, `cannotRender`).
55
- - `describeMissing(report)`: a human-readable sentence for that report.
56
-
57
- **Re-edit permission**
58
-
59
- - `permissionOf(metadata)`, `canReedit(permission, isAuthor)`, `mustRejectWithoutAsking(permission, isAuthor)`,
60
- `registryQuery(permission)`, `permissionFields(permission)`, `signatureStamp(permission)`.
61
- - `normalizeLegacyKeys(metadata)`: maps the Spanish keys of files signed before 1.23.0
62
- (`reedicion` and its values) to the English ones. Call it **after** verifying the
63
- signature, never before: the signature covers the keys as they were written.
64
-
65
- **Rendering rules shared by the players**
66
-
67
- - Layers and groups: `isGroup`, `slotParent`, `childrenByGroup`, `slotClipping`.
68
- - Text: `resolveLineHeight`, `inkMargin`, `parseMarks`, `validateMarks`, `markStyle`,
69
- `dropCapStyle`, `splitDropCap`, the entrance-effect functions (`entranceFrameAt`,
70
- `entranceKeyframes`, ...).
71
- - Fills, colours and palettes: `resolvePalette`, `resolveCssColor`, `isSafeCssColor`,
72
- `DYNAMIC_COLOR_ROLES`, the fill and pattern engine in `fill.ts` and `patterns.ts`.
73
- - Media: `mediaFilterCss`, `FILTER_PRESET_CSS`, `frame-silhouette`, `embeddedFonts`,
74
- `artisticTextCurve`, `artisticTextExtrusion`, `geoShapes`, `cropping` helpers.
75
- - Motion: `parallaxCss`, `oversizeScale`, `REVEAL_DEFAULT`, `flip`.
76
-
77
- **Effects and generative content**
78
-
79
- - `normalizeSlotEffects(style)`, `layerTextureMask(layer)`, `TEXTURE_CATALOG`.
80
- - `renderGenerativeSVG(config, { width, height, bleed? })` and `GENERATOR_CATALOG`,
81
- `getGeneratorSpec(id)` (from `@oim-media/core/generative`).
82
-
83
- **Backend**
84
-
85
- - `OIM_BACKEND_URL_DEFAULT`, `OIM_ENDPOINTS`, `OIM_PACKAGE_FIELDS`,
86
- `resolveBackendUrl(override?)`, `oimEndpoint(name, backendUrl?)`.
87
-
88
- ## Examples
89
-
90
- Read a file and check what it needs:
91
-
92
- ```ts
93
- import { extractOIM, whatTheReaderCannotDo, describeMissing, CONTRACT_VERSION } from "@oim-media/core";
94
-
95
- const file = await fetch("/art/poster.oim.png").then((r) => r.blob());
96
- const { metadata, imageHash } = await extractOIM(file);
97
-
98
- const report = whatTheReaderCannotDo(metadata, {
99
- version: CONTRACT_VERSION,
100
- capabilities: ["vector_parallax", "text_marks"],
101
- });
102
- if (report.cannotRender) console.warn(describeMissing(report));
103
- ```
104
-
105
- Check a re-edit permission after the signature has been verified:
106
-
107
- ```ts
108
- import { normalizeLegacyKeys, canReedit, permissionOf } from "@oim-media/core";
109
-
110
- const meta = normalizeLegacyKeys(verifiedMetadata); // verifiedMetadata: already checked by your verifier
111
- const verdict = canReedit(permissionOf(meta), /* isAuthor */ null);
112
- verdict.allowed; // false for "author_only" and "sealed" when the author is unknown
113
- ```
114
-
115
- Only the `public` permission is granted without knowing who the user is.
116
-
117
- Build the backend URL for a route:
118
-
119
- ```ts
120
- import { oimEndpoint } from "@oim-media/core/api";
121
-
122
- const url = oimEndpoint("compile"); // https://api.oim.media/v1/oim/compile
123
- ```
124
-
125
- ## Versioning
126
-
127
- `CONTRACT_VERSION` is the version of the **format**, not of this package. The
128
- package version and the contract version move together on each release tag, but a
129
- package can change without the format changing. See the
130
- [root README](../../README.md#versioning).
131
-
132
- ## Licence
133
-
134
- Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
1
+ # @oim-media/core
2
+
3
+ The shared core of the [OIM format](../../README.md): the contract schema, the
4
+ reader for the `.oim` container, the canonical form that signatures cover, and
5
+ the rendering rules that every player must apply the same way.
6
+
7
+ It is what the web players and the signing backend build on. You need it if you
8
+ read or write `.oim` metadata from TypeScript or JavaScript. You do not need it to
9
+ embed a file in a page; for that use [`@oim-media/player-oim`](../player-oim/README.md).
10
+
11
+ ```bash
12
+ pnpm add @oim-media/core
13
+ ```
14
+
15
+ It needs `crypto.subtle`, `Blob`, `DecompressionStream` and `TextDecoder`, which current
16
+ browsers and recent Node.js provide. It is ESM only and declares `sideEffects: false`, so
17
+ bundlers can drop what you do not import.
18
+
19
+ ## What it exports
20
+
21
+ The root entry (`@oim-media/core`) re-exports everything below. Two subpaths
22
+ exist for code that must stay light: `@oim-media/core/api` (backend routes and
23
+ URLs only) and `@oim-media/core/generative` and `@oim-media/core/generative/catalog`.
24
+
25
+ **Contract and validation**
26
+
27
+ - `OimMetadataSchema`, `OvmMetadataSchema`, `OIMOrOVMMetadata`: Zod schemas of the
28
+ metadata. Types `OIMMetadata`, `OVMMetadata`, `Slot`, `TextMark`, `Reveal`, ...
29
+ - `CONTRACT_VERSION`: the contract version this build implements (`"1.27.10"`).
30
+ - `BASE_CONTRACT_VERSION`, `PLAYER_CAPABILITIES`, `VERSION_BY_CAPABILITY`, `minVersionFor`.
31
+ - `MAX_SLOTS`, `MAX_MARKS`, `MARK_NAME`, `PALETTE_NAME_PATTERN`, `CSS_GRADIENT_PATTERN`.
32
+
33
+ **Binary: reading and writing the container**
34
+
35
+ - `extractOIM(blob)`: returns `{ image, metadata, imageHash }`, where `image` is the PNG without the metadata chunk.
36
+ - `extractOIMMetadataFromStream(stream)`: metadata from a stream, reading only as far as needed.
37
+ - `fetchMetadataTail(url, tailBytes?)`: metadata from the end of a remote file with a range request.
38
+ - `compressAndEncodeJSON(obj)` and `decodeAndDecompressJSON(base64)`, `decompressBytes(bytes, format)`.
39
+ - `imageDataHash(arrayBuffer)`: SHA-256 (hex) of the PNG `IDAT` payloads. This is the image seal.
40
+
41
+ **Canonical form (the bytes a signature covers)**
42
+
43
+ - `serializeCanonical(metadata)`: returns the `Uint8Array` the signer hashes.
44
+ - `normalizeCanonicalNumbers(value)` and `sortKeysByCodePoint(value)`: the two rules used by `serializeCanonical`.
45
+ - `hasNumberOutOfRange(value)` and `MAX_CANONICAL_NUMBER`: whether metadata holds a number beyond ±(2^53 − 1), which has no canonical form; a signer refuses it and a verifier reports the signature as invalid.
46
+
47
+ Signature *verification* is not in this package. The player verifies with its
48
+ embedded keys (see [`@oim-media/spec`](../spec/README.md#embedded-player-keys)).
49
+
50
+ **Compatibility**
51
+
52
+ - `whatTheReaderCannotDo(metadata, { version, capabilities })`: returns a
53
+ `MissingSupport` report (required version, missing capabilities, `cannotRender`).
54
+ - `describeMissing(report)`: a human-readable sentence for that report.
55
+
56
+ **Re-edit permission**
57
+
58
+ - `permissionOf(metadata)`, `canReedit(permission, isAuthor)`, `mustRejectWithoutAsking(permission, isAuthor)`,
59
+ `registryQuery(permission)`, `permissionFields(permission)`, `signatureStamp(permission)`.
60
+ - `normalizeLegacyKeys(metadata)`: maps the Spanish keys of files signed before 1.23.0
61
+ (`reedicion` and its values) to the English ones. Call it **after** verifying the
62
+ signature, never before: the signature covers the keys as they were written.
63
+
64
+ **Rendering rules shared by the players**
65
+
66
+ - Layers and groups: `isGroup`, `slotParent`, `childrenByGroup`, `slotClipping`.
67
+ - Text: `resolveLineHeight`, `inkMargin`, `parseMarks`, `validateMarks`, `markStyle`,
68
+ `dropCapStyle`, `splitDropCap`, the entrance-effect functions (`entranceFrameAt`,
69
+ `entranceKeyframes`, ...).
70
+ - Fills, colours and palettes: `resolvePalette`, `resolveCssColor`, `isSafeCssColor`,
71
+ `DYNAMIC_COLOR_ROLES`, the fill and pattern engine in `fill.ts` and `patterns.ts`.
72
+ - Media: `mediaFilterCss`, `FILTER_PRESET_CSS`, `frame-silhouette`, `embeddedFonts`,
73
+ `artisticTextCurve`, `artisticTextExtrusion`, `geoShapes`, `cropping` helpers.
74
+ - Motion: `parallaxCss`, `oversizeScale`, `REVEAL_DEFAULT`, `flip`.
75
+
76
+ **Effects and generative content**
77
+
78
+ - `normalizeSlotEffects(style)`, `layerTextureMask(layer)`, `TEXTURE_CATALOG`.
79
+ - `renderGenerativeSVG(config, { width, height, bleed? })` and `GENERATOR_CATALOG`,
80
+ `getGeneratorSpec(id)` (from `@oim-media/core/generative`).
81
+
82
+ **Backend**
83
+
84
+ - `OIM_BACKEND_URL_DEFAULT`, `OIM_ENDPOINTS`, `OIM_PACKAGE_FIELDS`,
85
+ `resolveBackendUrl(override?)`, `oimEndpoint(name, backendUrl?)`.
86
+
87
+ ## The 2.0 draft (`@oim-media/core/v2`)
88
+
89
+ An experimental entry for the next version of the document. The published format is still the one
90
+ above; no player reads 2.0 yet and its shape can change.
91
+
92
+ 2.0 keeps what a file can express and reorganises how it is written: five layer types (`text`,
93
+ `shape`, `image`, `lottie`, `group`) instead of fifteen, and one block per idea (`fills`, `strokes`,
94
+ `effects`, `text`, `geometry`, `mask`, `animations`, `interactions`) that is the same in every layer
95
+ that admits it. An absent field is its default.
96
+
97
+ - `documentSchema`, `layerSchema` and the schema of each block: the 2.0 document, in Zod.
98
+ - `LAYER_BLOCKS` and `admits(type, block)`: which block each layer type admits.
99
+ - `upgrade(v1)`: reads a 1.x document as 2.0. It returns `{ document, retired, unhandled }`.
100
+ `retired` lists the 1.x keys dropped on purpose; `unhandled` lists the ones nobody converted, and
101
+ is empty for every conformance vector. It is pure and does not sign: verify a 1.x file with its own
102
+ bytes first.
103
+ - `isV2(input)`: whether a document is already 2.0.
104
+
105
+ ```ts
106
+ import { upgrade } from "@oim-media/core/v2";
107
+
108
+ const { document, unhandled } = upgrade(metadata);
109
+ if (unhandled.length > 0) console.warn("not carried to 2.0:", unhandled);
110
+ ```
111
+
112
+ ## Examples
113
+
114
+ Read a file and check what it needs:
115
+
116
+ ```ts
117
+ import { extractOIM, whatTheReaderCannotDo, describeMissing, CONTRACT_VERSION } from "@oim-media/core";
118
+
119
+ const file = await fetch("/art/poster.oim.png").then((r) => r.blob());
120
+ const { metadata, imageHash } = await extractOIM(file);
121
+
122
+ const report = whatTheReaderCannotDo(metadata, {
123
+ version: CONTRACT_VERSION,
124
+ capabilities: ["vector_parallax", "text_marks"],
125
+ });
126
+ if (report.cannotRender) console.warn(describeMissing(report));
127
+ ```
128
+
129
+ Check a re-edit permission after the signature has been verified:
130
+
131
+ ```ts
132
+ import { normalizeLegacyKeys, canReedit, permissionOf } from "@oim-media/core";
133
+
134
+ const meta = normalizeLegacyKeys(verifiedMetadata); // verifiedMetadata: already checked by your verifier
135
+ const verdict = canReedit(permissionOf(meta), /* isAuthor */ null);
136
+ verdict.allowed; // false for "author_only" and "sealed" when the author is unknown
137
+ ```
138
+
139
+ Only the `public` permission is granted without knowing who the user is.
140
+
141
+ Build the backend URL for a route:
142
+
143
+ ```ts
144
+ import { oimEndpoint } from "@oim-media/core/api";
145
+
146
+ const url = oimEndpoint("compile"); // https://api.oim.media/v1/oim/compile
147
+ ```
148
+
149
+ ## Versioning
150
+
151
+ `CONTRACT_VERSION` is the version of the **format**, not of this package. The
152
+ package version and the contract version move together on each release tag, but a
153
+ package can change without the format changing. See the
154
+ [root README](../../README.md#versioning).
155
+
156
+ ## Licence
157
+
158
+ Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -3,6 +3,31 @@
3
3
  * Copyright (c) 2026 Xue Studios LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ /**
7
+ * Canonical serialization conforming to the 7 normative rules of the OIM specification
8
+ * (the BINARY_SPEC and README of the spec package) and the principles of RFC 8785 (JCS).
9
+ *
10
+ * SINGLE source of truth shared by @oim-media/core, @oim-media/cli and @oim-media/player-oim.
11
+ *
12
+ * The 7 canonical rules:
13
+ * 1. Deserialized base metadata object.
14
+ * 2. Strict exclusion at the root of: 'signature', 'key_version', 'timestamp', 'creator_user_id'.
15
+ * 3. Numeric normalization: decimals with a null fractional part become integers (2.0 -> 2);
16
+ * the rest is rounded to at most 6 decimals. A number that is not finite or lies
17
+ * beyond +/-(2^53 - 1) has no canonical form: see hasNumberOutOfRange.
18
+ * 4. Recursive lexical key ordering by Unicode code point (codePointAt).
19
+ * 5. Compact serialization without spaces between separators (',', ':').
20
+ * 6. Non-ASCII characters emitted directly in UTF-8 without escaping (no \uXXXX).
21
+ * 7. Native UTF-8 encoding.
22
+ */
23
+ /** Largest magnitude a signed number may have: every JSON parser reads it exactly. */
24
+ export declare const MAX_CANONICAL_NUMBER: number;
25
+ /**
26
+ * Whether the metadata carries, at any depth, a number with no canonical form.
27
+ * Beyond 2^53 - 1 parsers disagree on the value they read, so signers refuse
28
+ * such metadata and verifiers report its signature as invalid.
29
+ */
30
+ export declare function hasNumberOutOfRange(value: unknown): boolean;
6
31
  /**
7
32
  * Rule 3: integer floats are converted to int; the rest is rounded to 6 decimals.
8
33
  */
package/dist/canonical.js CHANGED
@@ -13,12 +13,29 @@
13
13
  * 1. Deserialized base metadata object.
14
14
  * 2. Strict exclusion at the root of: 'signature', 'key_version', 'timestamp', 'creator_user_id'.
15
15
  * 3. Numeric normalization: decimals with a null fractional part become integers (2.0 -> 2);
16
- * the rest is rounded to at most 6 decimals.
16
+ * the rest is rounded to at most 6 decimals. A number that is not finite or lies
17
+ * beyond +/-(2^53 - 1) has no canonical form: see hasNumberOutOfRange.
17
18
  * 4. Recursive lexical key ordering by Unicode code point (codePointAt).
18
19
  * 5. Compact serialization without spaces between separators (',', ':').
19
20
  * 6. Non-ASCII characters emitted directly in UTF-8 without escaping (no \uXXXX).
20
21
  * 7. Native UTF-8 encoding.
21
22
  */
23
+ /** Largest magnitude a signed number may have: every JSON parser reads it exactly. */
24
+ export const MAX_CANONICAL_NUMBER = Number.MAX_SAFE_INTEGER;
25
+ /**
26
+ * Whether the metadata carries, at any depth, a number with no canonical form.
27
+ * Beyond 2^53 - 1 parsers disagree on the value they read, so signers refuse
28
+ * such metadata and verifiers report its signature as invalid.
29
+ */
30
+ export function hasNumberOutOfRange(value) {
31
+ if (typeof value === 'number') {
32
+ return !Number.isFinite(value) || Math.abs(value) > MAX_CANONICAL_NUMBER;
33
+ }
34
+ if (value !== null && typeof value === 'object') {
35
+ return Object.values(value).some(hasNumberOutOfRange);
36
+ }
37
+ return false;
38
+ }
22
39
  const EXCLUDED_ROOT_KEYS = new Set([
23
40
  'signature',
24
41
  'key_version',
@@ -41,7 +41,7 @@
41
41
  * the format can change without the player being touched. Tying both numbers
42
42
  * together would make an internal fix look like a format break.
43
43
  */
44
- export declare const CONTRACT_VERSION = "1.27.8";
44
+ export declare const CONTRACT_VERSION = "1.27.10";
45
45
  /**
46
46
  * The first version of the format. Whatever requires nothing more requires this.
47
47
  *
@@ -41,7 +41,9 @@
41
41
  * the format can change without the player being touched. Tying both numbers
42
42
  * together would make an internal fix look like a format break.
43
43
  */
44
- export const CONTRACT_VERSION = "1.27.8";
44
+ export const CONTRACT_VERSION = "1.27.10";
45
+ // 1.27.10: no format change; the player paints from 2.0 and a zone is a group without its flow.
46
+ // 1.27.9: numbers beyond +/-(2^53 - 1) have no canonical form; the Rust crate parses decimals exactly.
45
47
  // 1.27.8: Flutter stroke and effects scale with the canvas; packages on npm, pub.dev and crates.io.
46
48
  // 1.27.7: Flutter ignores textRuns and lays text out like the web; the Flutter viewer follows the system language; no format change.
47
49
  // 1.27.6: a custom svgPath frame masks its fill-colour layer (web player); Flutter fixes (opacity 0..100, retired blendMode, media-filter scope, svgViewBox, container fills, default text colour); no format change.
@@ -54,10 +54,10 @@ export const renderBlob = (rawParams, ctx) => {
54
54
  pathD += ` Q ${p1.x} ${p1.y}, ${midX} ${midY}`;
55
55
  }
56
56
  pathD += " Z";
57
- markup += `
58
- <g transform="translate(${tx}, ${ty})">
59
- <path d="${pathD}" fill="${color}" opacity="${0.9 - b * 0.1}" />
60
- </g>
57
+ markup += `
58
+ <g transform="translate(${tx}, ${ty})">
59
+ <path d="${pathD}" fill="${color}" opacity="${0.9 - b * 0.1}" />
60
+ </g>
61
61
  `;
62
62
  }
63
63
  return markup;
@@ -34,17 +34,17 @@ export const renderIsoGrid = (rawParams, ctx) => {
34
34
  if (hollow) {
35
35
  // Hollow box frame
36
36
  const inset = stepX * 0.2;
37
- markup += `
38
- <rect x="${x}" y="${y}" width="${stepX}" height="${stepY}" fill="none"${strokeAttr} />
39
- <rect x="${x + inset}" y="${y + inset}" width="${stepX - inset * 2}" height="${stepY - inset * 2}" fill="${faceColor}" opacity="0.65" />
37
+ markup += `
38
+ <rect x="${x}" y="${y}" width="${stepX}" height="${stepY}" fill="none"${strokeAttr} />
39
+ <rect x="${x + inset}" y="${y + inset}" width="${stepX - inset * 2}" height="${stepY - inset * 2}" fill="${faceColor}" opacity="0.65" />
40
40
  `;
41
41
  }
42
42
  else {
43
43
  // 3D extruded cube with faces in perspective
44
- markup += `
45
- <rect x="${x}" y="${y}" width="${stepX}" height="${stepY}" fill="url(#${sharedGradId})"${strokeAttr} />
46
- <polygon points="${x},${y} ${x + extrudeOffset},${y - extrudeOffset} ${x + stepX + extrudeOffset},${y - extrudeOffset} ${x + stepX},${y}" fill="${faceColor}" opacity="0.75" />
47
- <polygon points="${x + stepX},${y} ${x + stepX + extrudeOffset},${y - extrudeOffset} ${x + stepX + extrudeOffset},${y + stepY - extrudeOffset} ${x + stepX},${y + stepY}" fill="#000000" opacity="0.35" />
44
+ markup += `
45
+ <rect x="${x}" y="${y}" width="${stepX}" height="${stepY}" fill="url(#${sharedGradId})"${strokeAttr} />
46
+ <polygon points="${x},${y} ${x + extrudeOffset},${y - extrudeOffset} ${x + stepX + extrudeOffset},${y - extrudeOffset} ${x + stepX},${y}" fill="${faceColor}" opacity="0.75" />
47
+ <polygon points="${x + stepX},${y} ${x + stepX + extrudeOffset},${y - extrudeOffset} ${x + stepX + extrudeOffset},${y + stepY - extrudeOffset} ${x + stepX},${y + stepY}" fill="#000000" opacity="0.35" />
48
48
  `;
49
49
  }
50
50
  }
@@ -39,9 +39,9 @@ export const renderMesh = (rawParams, ctx) => {
39
39
  const color1 = ctx.ramp(triangleIndex++, totalTriangles);
40
40
  const color2 = ctx.ramp(triangleIndex++, totalTriangles);
41
41
  const strokeAttr = borderWidth > 0 ? ` stroke="${params.borderColor || color1}" stroke-width="${borderWidth}" stroke-linejoin="bevel"` : "";
42
- markup += `
43
- <polygon points="${p1.x},${p1.y} ${p2.x},${p2.y} ${p3.x},${p3.y}" fill="${color1}"${strokeAttr} />
44
- <polygon points="${p2.x},${p2.y} ${p4.x},${p4.y} ${p3.x},${p3.y}" fill="${color2}"${strokeAttr} />
42
+ markup += `
43
+ <polygon points="${p1.x},${p1.y} ${p2.x},${p2.y} ${p3.x},${p3.y}" fill="${color1}"${strokeAttr} />
44
+ <polygon points="${p2.x},${p2.y} ${p4.x},${p4.y} ${p3.x},${p3.y}" fill="${color2}"${strokeAttr} />
45
45
  `;
46
46
  }
47
47
  }
@@ -27,14 +27,14 @@ const SEAM_OVERLAP_PX = 1;
27
27
  * means "pause while the cursor is over it"; without the variable, the default
28
28
  * `running` leaves the animation as it was.
29
29
  */
30
- export const CSS_PARALLAX = `@keyframes oim-parallax-infinite {
31
- 0% { transform: translateX(0px); }
32
- 100% { transform: translateX(calc(-1 * var(--oim-parallax-unit, 0px))); }
33
- }
34
- .${TRACK_CLASS}, .${LEGACY_TRACK_CLASS} { display: flex; width: max-content; will-change: transform; }
35
- .${TRACK_CLASS}:hover, .${LEGACY_TRACK_CLASS}:hover { animation-play-state: var(--oim-parallax-hover, running); }
36
- @media (prefers-reduced-motion: reduce) {
37
- .${TRACK_CLASS}, .${LEGACY_TRACK_CLASS} { animation: none !important; }
30
+ export const CSS_PARALLAX = `@keyframes oim-parallax-infinite {
31
+ 0% { transform: translateX(0px); }
32
+ 100% { transform: translateX(calc(-1 * var(--oim-parallax-unit, 0px))); }
33
+ }
34
+ .${TRACK_CLASS}, .${LEGACY_TRACK_CLASS} { display: flex; width: max-content; will-change: transform; }
35
+ .${TRACK_CLASS}:hover, .${LEGACY_TRACK_CLASS}:hover { animation-play-state: var(--oim-parallax-hover, running); }
36
+ @media (prefers-reduced-motion: reduce) {
37
+ .${TRACK_CLASS}, .${LEGACY_TRACK_CLASS} { animation: none !important; }
38
38
  }`;
39
39
  /**
40
40
  * Translates an infinite layer's configuration into pure CSS styles.