@hyperframes/sdk 0.6.113

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 (78) hide show
  1. package/LICENSE +190 -0
  2. package/dist/adapters/fs.d.ts +9 -0
  3. package/dist/adapters/fs.d.ts.map +1 -0
  4. package/dist/adapters/fs.js +122 -0
  5. package/dist/adapters/fs.js.map +1 -0
  6. package/dist/adapters/headless.d.ts +3 -0
  7. package/dist/adapters/headless.d.ts.map +1 -0
  8. package/dist/adapters/headless.js +17 -0
  9. package/dist/adapters/headless.js.map +1 -0
  10. package/dist/adapters/iframe.d.ts +102 -0
  11. package/dist/adapters/iframe.d.ts.map +1 -0
  12. package/dist/adapters/iframe.js +569 -0
  13. package/dist/adapters/iframe.js.map +1 -0
  14. package/dist/adapters/memory.d.ts +5 -0
  15. package/dist/adapters/memory.d.ts.map +1 -0
  16. package/dist/adapters/memory.js +54 -0
  17. package/dist/adapters/memory.js.map +1 -0
  18. package/dist/adapters/types.d.ts +65 -0
  19. package/dist/adapters/types.d.ts.map +1 -0
  20. package/dist/adapters/types.js +2 -0
  21. package/dist/adapters/types.js.map +1 -0
  22. package/dist/document.d.ts +25 -0
  23. package/dist/document.d.ts.map +1 -0
  24. package/dist/document.js +238 -0
  25. package/dist/document.js.map +1 -0
  26. package/dist/engine/apply-patches.d.ts +20 -0
  27. package/dist/engine/apply-patches.d.ts.map +1 -0
  28. package/dist/engine/apply-patches.js +284 -0
  29. package/dist/engine/apply-patches.js.map +1 -0
  30. package/dist/engine/cssWriter.d.ts +18 -0
  31. package/dist/engine/cssWriter.d.ts.map +1 -0
  32. package/dist/engine/cssWriter.js +139 -0
  33. package/dist/engine/cssWriter.js.map +1 -0
  34. package/dist/engine/keyframeBackfill.d.ts +17 -0
  35. package/dist/engine/keyframeBackfill.d.ts.map +1 -0
  36. package/dist/engine/keyframeBackfill.js +43 -0
  37. package/dist/engine/keyframeBackfill.js.map +1 -0
  38. package/dist/engine/model.d.ts +55 -0
  39. package/dist/engine/model.d.ts.map +1 -0
  40. package/dist/engine/model.js +256 -0
  41. package/dist/engine/model.js.map +1 -0
  42. package/dist/engine/mutate.d.ts +26 -0
  43. package/dist/engine/mutate.d.ts.map +1 -0
  44. package/dist/engine/mutate.js +1243 -0
  45. package/dist/engine/mutate.js.map +1 -0
  46. package/dist/engine/patches.d.ts +71 -0
  47. package/dist/engine/patches.d.ts.map +1 -0
  48. package/dist/engine/patches.js +197 -0
  49. package/dist/engine/patches.js.map +1 -0
  50. package/dist/engine/serialize.d.ts +15 -0
  51. package/dist/engine/serialize.d.ts.map +1 -0
  52. package/dist/engine/serialize.js +20 -0
  53. package/dist/engine/serialize.js.map +1 -0
  54. package/dist/engine/variableModel.d.ts +29 -0
  55. package/dist/engine/variableModel.d.ts.map +1 -0
  56. package/dist/engine/variableModel.js +81 -0
  57. package/dist/engine/variableModel.js.map +1 -0
  58. package/dist/history.d.ts +39 -0
  59. package/dist/history.d.ts.map +1 -0
  60. package/dist/history.js +116 -0
  61. package/dist/history.js.map +1 -0
  62. package/dist/index.d.ts +15 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +11 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/persist-queue.d.ts +24 -0
  67. package/dist/persist-queue.d.ts.map +1 -0
  68. package/dist/persist-queue.js +62 -0
  69. package/dist/persist-queue.js.map +1 -0
  70. package/dist/session.d.ts +38 -0
  71. package/dist/session.d.ts.map +1 -0
  72. package/dist/session.js +514 -0
  73. package/dist/session.js.map +1 -0
  74. package/dist/types.d.ts +521 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +16 -0
  77. package/dist/types.js.map +1 -0
  78. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 HeyGen, Inc.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,9 @@
1
+ import type { PersistAdapter } from "./types.js";
2
+ export interface FsAdapterOptions {
3
+ /** Root directory for composition files */
4
+ root: string;
5
+ /** Max versions to keep per file. Default: 20 */
6
+ maxVersions?: number;
7
+ }
8
+ export declare function createFsAdapter(opts: FsAdapterOptions): PersistAdapter;
9
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/adapters/fs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAuB,MAAM,YAAY,CAAC;AAKtE,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAkID,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,cAAc,CAEtE"}
@@ -0,0 +1,122 @@
1
+ import { readFile, writeFile, mkdir, readdir, unlink } from "node:fs/promises";
2
+ import { join, dirname } from "node:path";
3
+ const DEFAULT_MAX_VERSIONS = 20;
4
+ let _versionCounter = 0;
5
+ class FsAdapter {
6
+ root;
7
+ maxVersions;
8
+ errorHandlers = [];
9
+ inflightWrites = new Set();
10
+ _writeLocks = new Map();
11
+ constructor(opts) {
12
+ this.root = opts.root;
13
+ this.maxVersions = opts.maxVersions ?? DEFAULT_MAX_VERSIONS;
14
+ }
15
+ async read(path) {
16
+ try {
17
+ return await readFile(this.abs(path), "utf8");
18
+ }
19
+ catch (err) {
20
+ if (isNotFound(err))
21
+ return undefined;
22
+ throw err;
23
+ }
24
+ }
25
+ async write(path, content) {
26
+ const p = this.doWrite(path, content);
27
+ this.inflightWrites.add(p);
28
+ try {
29
+ await p;
30
+ }
31
+ finally {
32
+ this.inflightWrites.delete(p);
33
+ }
34
+ }
35
+ async doWrite(path, content) {
36
+ try {
37
+ const abs = this.abs(path);
38
+ await mkdir(dirname(abs), { recursive: true });
39
+ await writeFile(abs, content, "utf8");
40
+ await this.appendVersion(path, content);
41
+ }
42
+ catch (err) {
43
+ for (const h of this.errorHandlers)
44
+ h({ error: { message: String(err), cause: err } });
45
+ }
46
+ }
47
+ async flush() {
48
+ // Promise.all rejects on the first write failure; per-write errors are also
49
+ // surfaced individually through the persist:error event channel.
50
+ await Promise.all([...this.inflightWrites]);
51
+ }
52
+ async listVersions(path) {
53
+ const dir = this.versionsDir(path);
54
+ try {
55
+ const entries = await readdir(dir);
56
+ const sorted = entries
57
+ .filter((f) => f.endsWith(".html"))
58
+ .sort()
59
+ .reverse();
60
+ return Promise.all(sorted.map(async (f) => {
61
+ const key = f.replace(/\.html$/, "");
62
+ return {
63
+ key,
64
+ content: await readFile(join(dir, f), "utf8"),
65
+ timestamp: Number(key.split("-")[0]),
66
+ };
67
+ }));
68
+ }
69
+ catch {
70
+ return [];
71
+ }
72
+ }
73
+ async loadFrom(path, versionKey) {
74
+ try {
75
+ return await readFile(join(this.versionsDir(path), `${versionKey}.html`), "utf8");
76
+ }
77
+ catch {
78
+ return undefined;
79
+ }
80
+ }
81
+ on(event, handler) {
82
+ if (event !== "persist:error")
83
+ return () => { };
84
+ this.errorHandlers.push(handler);
85
+ return () => {
86
+ const i = this.errorHandlers.indexOf(handler);
87
+ if (i !== -1)
88
+ this.errorHandlers.splice(i, 1);
89
+ };
90
+ }
91
+ abs(path) {
92
+ return join(this.root, path);
93
+ }
94
+ versionsDir(path) {
95
+ return join(this.root, ".hf-versions", path);
96
+ }
97
+ async appendVersion(path, content) {
98
+ const prior = this._writeLocks.get(path) ?? Promise.resolve();
99
+ const next = prior.then(() => this._doAppendVersion(path, content));
100
+ this._writeLocks.set(path, next.catch(() => { }));
101
+ return next;
102
+ }
103
+ async _doAppendVersion(path, content) {
104
+ const dir = this.versionsDir(path);
105
+ await mkdir(dir, { recursive: true });
106
+ const key = `${Date.now()}-${String(++_versionCounter).padStart(4, "0")}`;
107
+ await writeFile(join(dir, `${key}.html`), content, "utf8");
108
+ // prune oldest beyond maxVersions
109
+ const all = (await readdir(dir)).filter((f) => f.endsWith(".html")).sort();
110
+ const excess = all.length - this.maxVersions;
111
+ if (excess > 0) {
112
+ await Promise.all(all.slice(0, excess).map((f) => unlink(join(dir, f)).catch(() => { })));
113
+ }
114
+ }
115
+ }
116
+ function isNotFound(err) {
117
+ return err?.code === "ENOENT";
118
+ }
119
+ export function createFsAdapter(opts) {
120
+ return new FsAdapter(opts);
121
+ }
122
+ //# sourceMappingURL=fs.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I,CAAC,WAAW,CAAC;QAC7C,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACf,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;CACF;AAED,SAAS,UAAU,CAAC,GAAY;IAC9B,OAAQ,GAA6B,EAAE,IAAI,KAAK,QAAQ,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAsB;IACpD,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { PreviewAdapter } from "./types.js";
2
+ export declare function createHeadlessAdapter(): PreviewAdapter;
3
+ //# sourceMappingURL=headless.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headless.d.ts","sourceRoot":"","sources":["../../src/adapters/headless.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAoC,MAAM,YAAY,CAAC;AAqBnF,wBAAgB,qBAAqB,IAAI,cAAc,CAEtD"}
@@ -0,0 +1,17 @@
1
+ /** Null PreviewAdapter for headless use (agents, CI, server-side rendering). */
2
+ class HeadlessPreviewAdapter {
3
+ elementAtPoint(_x, _y, _opts) {
4
+ return null;
5
+ }
6
+ applyDraft(_id, _props) { }
7
+ commitPreview() { }
8
+ cancelPreview() { }
9
+ select(_ids, _opts) { }
10
+ on(_event, _handler) {
11
+ return () => { };
12
+ }
13
+ }
14
+ export function createHeadlessAdapter() {
15
+ return new HeadlessPreviewAdapter();
16
+ }
17
+ //# sourceMappingURL=headless.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headless.js","sourceRoot":"","sources":["../../src/adapters/headless.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,MAAM,sBAAsB;IAC1B,cAAc,CAAC,EAAU,EAAE,EAAU,EAAE,KAA2B;QAChE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,UAAU,CAAC,GAAW,EAAE,MAAkB,IAAS,CAAC;IAEpD,aAAa,KAAU,CAAC;IAExB,aAAa,KAAU,CAAC;IAExB,MAAM,CAAC,IAAc,EAAE,KAA8B,IAAS,CAAC;IAE/D,EAAE,CAAC,MAAmB,EAAE,QAAiC;QACvD,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC;CACF;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,sBAAsB,EAAE,CAAC;AACtC,CAAC"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Same-origin iframe PreviewAdapter — WS-A1 (hit-test + selection) +
3
+ * WS-A2 (applyDraft / commitPreview / cancelPreview → moveElement) +
4
+ * WS-G (image-alpha hit-test, phase 1).
5
+ *
6
+ * Requirements:
7
+ * - The iframe MUST be same-origin (srcdoc / blob URL). Cross-origin access to
8
+ * contentDocument throws a DOMException; this adapter does not guard that —
9
+ * the caller is responsible for ensuring same-origin.
10
+ *
11
+ * Image-alpha (phase 1):
12
+ * - Replaces elementFromPoint with elementsFromPoint (z-stack) so transparent
13
+ * image hits fall through to the element behind.
14
+ * - For <img> hits, maps the client point to the natural-pixel coordinate
15
+ * (object-fit/object-position aware), draws to an offscreen canvas (cached
16
+ * by src + natural dimensions, so a srcset re-render gets a fresh canvas),
17
+ * samples alpha. Transparent pixel → miss, continue the stack.
18
+ * - Cross-origin images taint the canvas → getImageData throws SecurityError
19
+ * → falls back to treating the pixel as OPAQUE (never drop an unverifiable
20
+ * hit) and warns once per src. Callers must ensure CORS or accept the fallback.
21
+ * - A CSS rotation/skew on the image or an ancestor also falls back to opaque
22
+ * (the axis-aligned rect mapping can't sample a rotated image correctly);
23
+ * transform-inverse mapping is phase 2.
24
+ * - Images above a pixel budget skip alpha-testing (opaque) to bound canvas
25
+ * memory. Limitation: animated <img> (gif) or src swaps invalidate the cache
26
+ * only when currentSrc/dimensions change. Phase 1 is optimized for static images.
27
+ * - Phase 2 (full per-pixel alpha via drawElement rasterization) is NOT built
28
+ * here — gated on a perf spike.
29
+ */
30
+ import type { PreviewAdapter, ElementAtPointResult } from "./types.js";
31
+ import type { EditOp } from "../types.js";
32
+ /**
33
+ * Walk from `el` upward through parentElement, looking for the nearest node
34
+ * that carries `[data-hf-id]` and is NOT `[data-hf-root]`.
35
+ *
36
+ * Returns null when:
37
+ * - The walk exits the tree without finding `[data-hf-id]`
38
+ * - The matching node is `[data-hf-root]` (transparent to hit-testing)
39
+ * - `isVisible(node)` returns false for the matching node
40
+ *
41
+ * Keeping this a pure function (no elementFromPoint, no window access) makes
42
+ * it unit-testable in a plain Node environment.
43
+ */
44
+ export declare function resolveNearestHfElement(el: Element | null, isVisible: (el: Element) => boolean): ElementAtPointResult | null;
45
+ /**
46
+ * Compute the new absolute x/y for a moveElement op given:
47
+ * - the element's current `data-x` / `data-y` string values (may be null)
48
+ * - the accumulated drag delta (dx, dy) from applyDraft calls
49
+ *
50
+ * `data-x` / `data-y` default to 0 when absent or non-numeric.
51
+ */
52
+ export declare function computeDraftPosition(dataX: string | null, dataY: string | null, dx: number, dy: number): {
53
+ x: number;
54
+ y: number;
55
+ };
56
+ /**
57
+ * Returns true when the first pixel in `imageData` has alpha >= threshold.
58
+ *
59
+ * Pure — no DOM access; unit-testable with a plain Uint8ClampedArray.
60
+ * threshold defaults to 1 so a fully-transparent pixel (a=0) is a miss.
61
+ */
62
+ export declare function alphaIsOpaque(imageData: ImageData, threshold?: number): boolean;
63
+ /**
64
+ * Map a client-space point to the natural-pixel coordinates of the image.
65
+ *
66
+ * Handles object-fit: fill | cover | contain (default=fill when unset).
67
+ * object-position is parsed as two percentage/px values (default "50% 50%").
68
+ *
69
+ * Returns null when the point falls outside the rendered image area (e.g.
70
+ * the letterbox region of a contain-fitted image). A null result means the
71
+ * image does not own this pixel — the caller should continue the z-stack.
72
+ *
73
+ * Pure — no DOM/window access; unit-testable with plain objects.
74
+ */
75
+ export declare function mapPointToImagePixel(rect: {
76
+ left: number;
77
+ top: number;
78
+ width: number;
79
+ height: number;
80
+ }, natural: {
81
+ width: number;
82
+ height: number;
83
+ }, objectFit: string, objectPosition: string, point: {
84
+ x: number;
85
+ y: number;
86
+ }): {
87
+ px: number;
88
+ py: number;
89
+ } | null;
90
+ /**
91
+ * Cache of offscreen canvases keyed by image currentSrc.
92
+ *
93
+ * Canvases are drawn once; the same canvas is reused across hit-tests.
94
+ * Animated images (gif) or dynamic src swaps are NOT tracked — this is a
95
+ * phase-1 static-image optimization. A tainted entry stores null to record
96
+ * that the image is cross-origin and all pixels should be treated as opaque.
97
+ *
98
+ * Exported for tests that need to reset the cache between runs.
99
+ */
100
+ export declare const _imgCanvasCache: Map<string, OffscreenCanvas | null>;
101
+ export declare function createIframePreviewAdapter(iframe: HTMLIFrameElement, dispatch?: (op: EditOp) => void): PreviewAdapter;
102
+ //# sourceMappingURL=iframe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iframe.d.ts","sourceRoot":"","sources":["../../src/adapters/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAc,MAAM,YAAY,CAAC;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAS1C;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,OAAO,GAAG,IAAI,EAClB,SAAS,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,GAClC,oBAAoB,GAAG,IAAI,CAY7B;AAID;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,KAAK,EAAE,MAAM,GA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