@oim-media/core 0.0.0-stage → 1.27.8

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 (110) hide show
  1. package/LICENSE +55 -0
  2. package/NOTICE +6 -0
  3. package/README.md +134 -3
  4. package/dist/api.d.ts +107 -0
  5. package/dist/api.js +79 -0
  6. package/dist/artisticTextCurve.d.ts +53 -0
  7. package/dist/artisticTextCurve.js +49 -0
  8. package/dist/artisticTextExtrusion.d.ts +37 -0
  9. package/dist/artisticTextExtrusion.js +53 -0
  10. package/dist/binary.d.ts +29 -0
  11. package/dist/binary.js +431 -0
  12. package/dist/canonical.d.ts +17 -0
  13. package/dist/canonical.js +93 -0
  14. package/dist/clipping.d.ts +55 -0
  15. package/dist/clipping.js +17 -0
  16. package/dist/compatibility.d.ts +113 -0
  17. package/dist/compatibility.js +291 -0
  18. package/dist/crop.d.ts +39 -0
  19. package/dist/crop.js +15 -0
  20. package/dist/css-gradient.d.ts +6 -0
  21. package/dist/css-gradient.js +85 -0
  22. package/dist/dimensions.d.ts +16 -0
  23. package/dist/dimensions.js +73 -0
  24. package/dist/drop-cap.d.ts +33 -0
  25. package/dist/drop-cap.js +38 -0
  26. package/dist/dynamic-colors.d.ts +51 -0
  27. package/dist/dynamic-colors.js +151 -0
  28. package/dist/effects/catalog.d.ts +19 -0
  29. package/dist/effects/catalog.js +111 -0
  30. package/dist/effects/index.d.ts +9 -0
  31. package/dist/effects/index.js +9 -0
  32. package/dist/effects/normalize.d.ts +12 -0
  33. package/dist/effects/normalize.js +82 -0
  34. package/dist/effects/texture-mask.d.ts +33 -0
  35. package/dist/effects/texture-mask.js +22 -0
  36. package/dist/effects/types.d.ts +50 -0
  37. package/dist/effects/types.js +25 -0
  38. package/dist/embeddedFonts.d.ts +39 -0
  39. package/dist/embeddedFonts.js +64 -0
  40. package/dist/fill.d.ts +91 -0
  41. package/dist/fill.js +199 -0
  42. package/dist/flip.d.ts +12 -0
  43. package/dist/flip.js +16 -0
  44. package/dist/fontFile.d.ts +32 -0
  45. package/dist/fontFile.js +91 -0
  46. package/dist/frame-silhouette.d.ts +33 -0
  47. package/dist/frame-silhouette.js +64 -0
  48. package/dist/generative/catalog.d.ts +8 -0
  49. package/dist/generative/catalog.js +233 -0
  50. package/dist/generative/index.d.ts +14 -0
  51. package/dist/generative/index.js +103 -0
  52. package/dist/generative/primitives/blob.d.ts +14 -0
  53. package/dist/generative/primitives/blob.js +64 -0
  54. package/dist/generative/primitives/gradient.d.ts +13 -0
  55. package/dist/generative/primitives/gradient.js +32 -0
  56. package/dist/generative/primitives/iso-grid.d.ts +13 -0
  57. package/dist/generative/primitives/iso-grid.js +53 -0
  58. package/dist/generative/primitives/layer-stack.d.ts +16 -0
  59. package/dist/generative/primitives/layer-stack.js +124 -0
  60. package/dist/generative/primitives/mesh.d.ts +13 -0
  61. package/dist/generative/primitives/mesh.js +49 -0
  62. package/dist/generative/primitives/radial.d.ts +15 -0
  63. package/dist/generative/primitives/radial.js +55 -0
  64. package/dist/generative/primitives/scatter.d.ts +15 -0
  65. package/dist/generative/primitives/scatter.js +74 -0
  66. package/dist/generative/proceduralNoise.d.ts +74 -0
  67. package/dist/generative/proceduralNoise.js +144 -0
  68. package/dist/generative/ramp.d.ts +12 -0
  69. package/dist/generative/ramp.js +95 -0
  70. package/dist/generative/rng.d.ts +11 -0
  71. package/dist/generative/rng.js +33 -0
  72. package/dist/generative/svg.d.ts +16 -0
  73. package/dist/generative/svg.js +81 -0
  74. package/dist/generative/types.d.ts +96 -0
  75. package/dist/generative/types.js +6 -0
  76. package/dist/geoShapes.d.ts +51 -0
  77. package/dist/geoShapes.js +134 -0
  78. package/dist/glitch.d.ts +53 -0
  79. package/dist/glitch.js +72 -0
  80. package/dist/groups.d.ts +66 -0
  81. package/dist/groups.js +92 -0
  82. package/dist/index.d.ts +39 -0
  83. package/dist/index.js +77 -0
  84. package/dist/keyframes.d.ts +30 -0
  85. package/dist/keyframes.js +66 -0
  86. package/dist/legacyKeys.d.ts +10 -0
  87. package/dist/legacyKeys.js +36 -0
  88. package/dist/limits.d.ts +32 -0
  89. package/dist/limits.js +32 -0
  90. package/dist/media-filters.d.ts +19 -0
  91. package/dist/media-filters.js +71 -0
  92. package/dist/oversize.d.ts +75 -0
  93. package/dist/oversize.js +94 -0
  94. package/dist/parallaxCss.d.ts +97 -0
  95. package/dist/parallaxCss.js +169 -0
  96. package/dist/patterns.d.ts +96 -0
  97. package/dist/patterns.js +239 -0
  98. package/dist/reeditPermission.d.ts +94 -0
  99. package/dist/reeditPermission.js +135 -0
  100. package/dist/reveal.d.ts +24 -0
  101. package/dist/reveal.js +47 -0
  102. package/dist/schema.d.ts +23002 -0
  103. package/dist/schema.js +844 -0
  104. package/dist/text-effects.d.ts +49 -0
  105. package/dist/text-effects.js +74 -0
  106. package/dist/text-marks.d.ts +75 -0
  107. package/dist/text-marks.js +171 -0
  108. package/dist/typography.d.ts +99 -0
  109. package/dist/typography.js +122 -0
  110. package/package.json +63 -3
package/LICENSE ADDED
@@ -0,0 +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
package/NOTICE ADDED
@@ -0,0 +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.
package/README.md CHANGED
@@ -1,3 +1,134 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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).
package/dist/api.d.ts ADDED
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * OIM API contract: where the backend lives, how its endpoints are named and
8
+ * what shape the raw measurements sent to it have.
9
+ *
10
+ * It exists because the three plugins had drifted on their own. Two of them pointed at
11
+ * `http://localhost:8000` BY DEFAULT, so once published they would have called the user's
12
+ * own machine, and one sent the form field under a name the backend does not read,
13
+ * producing PNGs with no
14
+ * OIM data inside and returning 200 OK.
15
+ *
16
+ * The rule: no plugin writes a URL or a field name by hand.
17
+ */
18
+ /** Production. The default is NEVER localhost: a published plugin with that
19
+ * default URL calls the machine of whoever uses it, not yours. */
20
+ export declare const OIM_BACKEND_URL_DEFAULT = "https://api.oim.media";
21
+ /**
22
+ * Canonical routes. All under `/v1/`: the host is already `api.oim.media`, so the
23
+ * `/api` segment was noise.
24
+ *
25
+ * Four conventions used to coexist: `/v1/media/*`, `/api/v1/fonts/*`,
26
+ * `/api/v1/oim/compile` and four unversioned endpoints, one of them with a half-translated
27
+ * name (`/upload-y-empaquetar`). Compile and package, which are called in sequence, lived in
28
+ * different namespaces.
29
+ *
30
+ * The old routes still respond, with the `Deprecation` header, but they do not appear in
31
+ * the documentation and must not be used in new code.
32
+ */
33
+ export declare const OIM_ENDPOINTS: {
34
+ /** Translates raw pixel measurements into adaptive units. THE ONLY
35
+ * compiler in the system: no client normalizes on its own. */
36
+ readonly compile: "/v1/oim/compile";
37
+ /**
38
+ * Merges the base image with the metadata and returns the `.oim.png` as
39
+ * a binary in the response itself.
40
+ *
41
+ * An earlier `?temp=true` saved the file instead and returned a link. The file lived
42
+ * on the disk of ONE backend instance, and the download, being another request, could
43
+ * land on another one: with more than one instance it failed with 404.
44
+ * The state was not shared; it was removed.
45
+ */
46
+ readonly package: "/v1/oim/package";
47
+ /** Extracts the OIM metadata from an already packaged PNG. */
48
+ readonly extract: "/v1/oim/extract";
49
+ readonly sign: "/v1/media/sign-json";
50
+ readonly verifyAuthor: "/v1/media/verify-author";
51
+ readonly translate: "/v1/media/translate";
52
+ readonly publicKeys: "/v1/media/keys";
53
+ };
54
+ /**
55
+ * Names of the `multipart/form-data` fields that `package` expects.
56
+ *
57
+ * The backend accepts several aliases (`metadata`/`data`/`json`), but a new client
58
+ * must use these: the Framer plugin sent `metadata_json`, which is none of them, and the
59
+ * backend read it as an empty string without complaint.
60
+ */
61
+ export declare const OIM_PACKAGE_FIELDS: {
62
+ readonly file: "file";
63
+ readonly metadata: "metadata";
64
+ };
65
+ /**
66
+ * Raw measurements of a slot, in pixels and relative to the top-left corner of the
67
+ * canvas.
68
+ *
69
+ * The three plugins already emitted exactly these names, so this type translates nothing:
70
+ * it freezes them. The alternative that was considered (a conversion template per editor)
71
+ * would have meant translating a format into itself.
72
+ */
73
+ export interface OimRawSlotGeometry {
74
+ x_px: number;
75
+ y_px: number;
76
+ width_px: number;
77
+ height_px: number;
78
+ font_size_px?: number;
79
+ }
80
+ /** Body of `POST /v1/oim/compile`. */
81
+ export interface OimCompileRequest {
82
+ canvas_width: number;
83
+ canvas_height: number;
84
+ slots_raw: Array<OimRawSlotGeometry & {
85
+ id: string;
86
+ type?: string;
87
+ content?: Record<string, string>;
88
+ style?: Record<string, unknown>;
89
+ align?: string;
90
+ [extra: string]: unknown;
91
+ }>;
92
+ oim_id?: string;
93
+ allowed_domains?: string[];
94
+ immutable_lock?: boolean;
95
+ /** Which client compiles. Used to diagnose divergences by origin. */
96
+ source?: string;
97
+ }
98
+ /**
99
+ * Resolves the backend URL from an environment override.
100
+ *
101
+ * Accepts empty, undefined and whitespace as "not configured": a variable that is declared
102
+ * but has no value is the case that in practice breaks deployments, and `||` alone already
103
+ * covers it, but it does not cover `" "`.
104
+ */
105
+ export declare function resolveBackendUrl(override?: string | null): string;
106
+ /** Builds an absolute endpoint URL. */
107
+ export declare function oimEndpoint(endpoint: keyof typeof OIM_ENDPOINTS, backendUrl?: string | null): string;
package/dist/api.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * OIM API contract: where the backend lives, how its endpoints are named and
8
+ * what shape the raw measurements sent to it have.
9
+ *
10
+ * It exists because the three plugins had drifted on their own. Two of them pointed at
11
+ * `http://localhost:8000` BY DEFAULT, so once published they would have called the user's
12
+ * own machine, and one sent the form field under a name the backend does not read,
13
+ * producing PNGs with no
14
+ * OIM data inside and returning 200 OK.
15
+ *
16
+ * The rule: no plugin writes a URL or a field name by hand.
17
+ */
18
+ /** Production. The default is NEVER localhost: a published plugin with that
19
+ * default URL calls the machine of whoever uses it, not yours. */
20
+ export const OIM_BACKEND_URL_DEFAULT = "https://api.oim.media";
21
+ /**
22
+ * Canonical routes. All under `/v1/`: the host is already `api.oim.media`, so the
23
+ * `/api` segment was noise.
24
+ *
25
+ * Four conventions used to coexist: `/v1/media/*`, `/api/v1/fonts/*`,
26
+ * `/api/v1/oim/compile` and four unversioned endpoints, one of them with a half-translated
27
+ * name (`/upload-y-empaquetar`). Compile and package, which are called in sequence, lived in
28
+ * different namespaces.
29
+ *
30
+ * The old routes still respond, with the `Deprecation` header, but they do not appear in
31
+ * the documentation and must not be used in new code.
32
+ */
33
+ export const OIM_ENDPOINTS = {
34
+ /** Translates raw pixel measurements into adaptive units. THE ONLY
35
+ * compiler in the system: no client normalizes on its own. */
36
+ compile: "/v1/oim/compile",
37
+ /**
38
+ * Merges the base image with the metadata and returns the `.oim.png` as
39
+ * a binary in the response itself.
40
+ *
41
+ * An earlier `?temp=true` saved the file instead and returned a link. The file lived
42
+ * on the disk of ONE backend instance, and the download, being another request, could
43
+ * land on another one: with more than one instance it failed with 404.
44
+ * The state was not shared; it was removed.
45
+ */
46
+ package: "/v1/oim/package",
47
+ /** Extracts the OIM metadata from an already packaged PNG. */
48
+ extract: "/v1/oim/extract",
49
+ sign: "/v1/media/sign-json",
50
+ verifyAuthor: "/v1/media/verify-author",
51
+ translate: "/v1/media/translate",
52
+ publicKeys: "/v1/media/keys",
53
+ };
54
+ /**
55
+ * Names of the `multipart/form-data` fields that `package` expects.
56
+ *
57
+ * The backend accepts several aliases (`metadata`/`data`/`json`), but a new client
58
+ * must use these: the Framer plugin sent `metadata_json`, which is none of them, and the
59
+ * backend read it as an empty string without complaint.
60
+ */
61
+ export const OIM_PACKAGE_FIELDS = {
62
+ file: "file",
63
+ metadata: "metadata",
64
+ };
65
+ /**
66
+ * Resolves the backend URL from an environment override.
67
+ *
68
+ * Accepts empty, undefined and whitespace as "not configured": a variable that is declared
69
+ * but has no value is the case that in practice breaks deployments, and `||` alone already
70
+ * covers it, but it does not cover `" "`.
71
+ */
72
+ export function resolveBackendUrl(override) {
73
+ const clean = (override || "").trim();
74
+ return (clean || OIM_BACKEND_URL_DEFAULT).replace(/\/+$/, "");
75
+ }
76
+ /** Builds an absolute endpoint URL. */
77
+ export function oimEndpoint(endpoint, backendUrl) {
78
+ return `${resolveBackendUrl(backendUrl)}${OIM_ENDPOINTS[endpoint]}`;
79
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * The path along which curved artistic text runs.
8
+ *
9
+ * It lives here for the same reason as `typography.ts` and `fill.ts`: it was
10
+ * written TWICE -once in the editor, once in the player- and the two copies
11
+ * had diverged in both forms the editor offers:
12
+ *
13
+ * arc: the control point sat 80% higher in the player, and its endpoints
14
+ * 4 px above the editor's.
15
+ * wave: the editor's amplitude was 29% larger.
16
+ *
17
+ * The EDITOR's geometry is kept, not the player's, and not out of seniority:
18
+ * the editor's keeps the arc centred in the box -the apex rises by `deltaY/4`
19
+ * and the endpoints drop by `deltaY/2`-, whereas the player's anchored the
20
+ * endpoints to the baseline and pushed the apex upward. With the curve at its
21
+ * maximum, that left the text 11 px from the top edge of a 120 px box: clipped.
22
+ *
23
+ * It is no accident that it was copied and then diverged. The 3D extrusion was
24
+ * also copied and is still identical; the curve is what someone tweaks "to make
25
+ * it look better", and it gets tweaked on ONE side only.
26
+ */
27
+ /** The path shapes. The editor does not offer `arch`; it is accepted and
28
+ * treated as an arc, which is what it already did. */
29
+ export type TextCurveType = "arc" | "wave" | "arch";
30
+ /**
31
+ * Returns the `d` attribute of the path that the text follows.
32
+ *
33
+ * @param width width of the box, in px
34
+ * @param height height of the box, in px
35
+ * @param curveAmount curvature from -100 to 100; 0 is a straight line
36
+ * @param curveType shape of the path
37
+ */
38
+ export declare function calculateTextCurvePath(width: number, height: number, curveAmount: number, curveType?: TextCurveType): string;
39
+ /** One line of artistic text, placed around the vertical centre of its box. */
40
+ export interface ArtisticTextLine {
41
+ text: string;
42
+ /** Distance in px from the box's vertical centre to this line's centre. */
43
+ offset: number;
44
+ }
45
+ /**
46
+ * Splits artistic text into lines and centres the block vertically.
47
+ *
48
+ * An SVG `<text>` does not break lines: it paints "\n" as a space, which is
49
+ * why pressing Enter in 3D/vector text did nothing. Each line is drawn on its
50
+ * own, `offset` px from the centre. It lives here, shared, so the editor and
51
+ * the player stack lines the same way.
52
+ */
53
+ export declare function artisticTextLines(text: string, fontSize: number, lineHeight: number): ArtisticTextLine[];
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Returns the `d` attribute of the path that the text follows.
8
+ *
9
+ * @param width width of the box, in px
10
+ * @param height height of the box, in px
11
+ * @param curveAmount curvature from -100 to 100; 0 is a straight line
12
+ * @param curveType shape of the path
13
+ */
14
+ export function calculateTextCurvePath(width, height, curveAmount, curveType = "arc") {
15
+ const midY = height / 2;
16
+ const clampedCurve = Math.max(-100, Math.min(100, curveAmount));
17
+ if (clampedCurve === 0) {
18
+ return `M 0 ${midY} L ${width} ${midY}`;
19
+ }
20
+ // Maximum vertical displacement, proportional to the height and curvature
21
+ const maxDelta = height * 0.45;
22
+ const deltaY = (clampedCurve / 100) * maxDelta;
23
+ if (curveType === "wave") {
24
+ // Cubic sinusoidal wave
25
+ const cp1x = width * 0.25;
26
+ const cp1y = midY - deltaY;
27
+ const cp2x = width * 0.75;
28
+ const cp2y = midY + deltaY;
29
+ return `M 0 ${midY} C ${cp1x} ${cp1y}, ${cp2x} ${cp2y}, ${width} ${midY}`;
30
+ }
31
+ // Quadratic arc
32
+ const yStartEnd = midY + deltaY * 0.5;
33
+ const yControl = midY - deltaY;
34
+ return `M 0 ${yStartEnd} Q ${width / 2} ${yControl} ${width} ${yStartEnd}`;
35
+ }
36
+ /**
37
+ * Splits artistic text into lines and centres the block vertically.
38
+ *
39
+ * An SVG `<text>` does not break lines: it paints "\n" as a space, which is
40
+ * why pressing Enter in 3D/vector text did nothing. Each line is drawn on its
41
+ * own, `offset` px from the centre. It lives here, shared, so the editor and
42
+ * the player stack lines the same way.
43
+ */
44
+ export function artisticTextLines(text, fontSize, lineHeight) {
45
+ const lines = String(text ?? "").split(/\r\n|\r|\n/);
46
+ const step = fontSize * lineHeight;
47
+ const middle = (lines.length - 1) / 2;
48
+ return lines.map((line, i) => ({ text: line, offset: (i - middle) * step }));
49
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * The 3D extrusion of artistic text: the stacked layers behind the face.
8
+ *
9
+ * Seventh case of the same pattern. The editor and the player each had their
10
+ * own `shadeHexColor`, and they did opposite things: the editor darkened
11
+ * towards black, the player lightened towards white. With the same
12
+ * `#111827`, the author saw an almost black extrusion and whoever opened the
13
+ * .oim saw it white. The editor's darkening is kept: it is what the author
14
+ * designed, and what the editor's own test said the colours should do.
15
+ */
16
+ /** One layer of the extrusion, offset from the face. */
17
+ export interface ExtrusionStep {
18
+ dx: number;
19
+ dy: number;
20
+ color: string;
21
+ opacity: number;
22
+ }
23
+ /**
24
+ * Darkens a hex colour towards black by `percent` (0 = unchanged, 1 = black).
25
+ *
26
+ * Accepts `#rgb` and `#rrggbb`. Anything else (a named colour, a CSS
27
+ * variable) is returned untouched rather than guessed at.
28
+ */
29
+ export declare function shadeHexColor(color: string, percent: number): string;
30
+ /**
31
+ * The extrusion layers, deepest first, so they paint back to front.
32
+ *
33
+ * Depth is clamped to 0-60 and each layer is one px further along the angle.
34
+ * With shading, deeper layers are lighter and the ones next to the face are
35
+ * darker, which reads as a shadow cast by the face.
36
+ */
37
+ export declare function calculate3DExtrusionLayers(depth: number, angleDegrees: number, baseColor?: string, shading?: boolean): ExtrusionStep[];
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Darkens a hex colour towards black by `percent` (0 = unchanged, 1 = black).
8
+ *
9
+ * Accepts `#rgb` and `#rrggbb`. Anything else (a named colour, a CSS
10
+ * variable) is returned untouched rather than guessed at.
11
+ */
12
+ export function shadeHexColor(color, percent) {
13
+ if (typeof color !== "string" || !color.startsWith("#"))
14
+ return color;
15
+ let hex = color.slice(1);
16
+ if (hex.length === 3)
17
+ hex = hex.split("").map((c) => c + c).join("");
18
+ if (hex.length !== 6)
19
+ return color;
20
+ const num = parseInt(hex, 16);
21
+ if (Number.isNaN(num))
22
+ return color;
23
+ const channel = (value) => Math.max(0, Math.min(255, Math.floor(value * (1 - percent))));
24
+ const r = channel(num >> 16);
25
+ const g = channel((num >> 8) & 0xff);
26
+ const b = channel(num & 0xff);
27
+ return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
28
+ }
29
+ /**
30
+ * The extrusion layers, deepest first, so they paint back to front.
31
+ *
32
+ * Depth is clamped to 0-60 and each layer is one px further along the angle.
33
+ * With shading, deeper layers are lighter and the ones next to the face are
34
+ * darker, which reads as a shadow cast by the face.
35
+ */
36
+ export function calculate3DExtrusionLayers(depth, angleDegrees, baseColor = "#111827", shading = true) {
37
+ const clampedDepth = Math.max(0, Math.min(60, depth));
38
+ if (clampedDepth === 0)
39
+ return [];
40
+ const rad = (angleDegrees * Math.PI) / 180;
41
+ const cos = Math.cos(rad);
42
+ const sin = Math.sin(rad);
43
+ const steps = Math.max(1, Math.round(clampedDepth));
44
+ const layers = [];
45
+ for (let i = steps; i >= 1; i--) {
46
+ const t = i / steps;
47
+ const dx = Math.round(cos * i * 10) / 10;
48
+ const dy = Math.round(sin * i * 10) / 10;
49
+ const color = shading ? shadeHexColor(baseColor, 1 - t * 0.5) : baseColor;
50
+ layers.push({ dx, dy, color, opacity: 1 });
51
+ }
52
+ return layers;
53
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export declare function decodeAndDecompressJSON(base64Str: string, maxBytes?: number): Promise<any>;
7
+ export declare function compressAndEncodeJSON(jsonObj: any): Promise<string>;
8
+ export declare function decompressBytes(bytes: Uint8Array, format: 'deflate' | 'deflate-raw', maxBytes?: number): Promise<string>;
9
+ /**
10
+ * SHA-256 (hex) of the concatenated IDAT payloads, or null without image data.
11
+ * The backend signs this as `image_hash`, so the player can tell when signed
12
+ * metadata was pasted onto a different image.
13
+ */
14
+ export declare function imageDataHash(buffer: ArrayBuffer): Promise<string | null>;
15
+ export declare function extractOIM(blob: Blob): Promise<{
16
+ image: Blob;
17
+ metadata: any;
18
+ imageHash: string | null;
19
+ }>;
20
+ export declare function fetchMetadataTail(src: string, tailBytes?: number): Promise<any>;
21
+ /**
22
+ * Extracts OIM metadata from a ReadableStream<Uint8Array>, reading only the
23
+ * header chunks and aborting the stream as soon as it finds the OIM_Data chunk
24
+ * or the first IDAT chunk.
25
+ *
26
+ * This avoids downloading and loading images of several megabytes into memory
27
+ * on mobile devices when only the interactive interface needs to initialize.
28
+ */
29
+ export declare function extractOIMMetadataFromStream(stream: ReadableStream<Uint8Array>): Promise<any | null>;