@vvfx/sdk 0.2.8 → 0.2.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 (111) hide show
  1. package/dist/config.js +231 -0
  2. package/dist/exporter/config.js +18 -0
  3. package/dist/exporter/const.js +71 -0
  4. package/dist/exporter/export-media.js +878 -0
  5. package/dist/exporter/exporter.js +121 -0
  6. package/dist/exporter/index.js +1 -0
  7. package/dist/exporter/types.js +1 -0
  8. package/dist/exporter/utils.js +190 -0
  9. package/dist/exporter/wav-audio.js +50 -0
  10. package/dist/gesture-handler/gizmo/adsorption-gizmo.js +227 -0
  11. package/dist/gesture-handler/gizmo/control-gizmo.js +149 -0
  12. package/dist/gesture-handler/gizmo/gizmo.js +17 -0
  13. package/dist/gesture-handler/gizmo/icon-gizmo.js +189 -0
  14. package/dist/gesture-handler/gizmo/index.js +6 -0
  15. package/dist/gesture-handler/gizmo/item-create-gizmo.js +256 -0
  16. package/dist/gesture-handler/gizmo/loading-gizmo.js +320 -0
  17. package/dist/gesture-handler/gizmo/mask-gizmo.js +648 -0
  18. package/dist/gesture-handler/gizmo/picture-cut-gizmo.js +550 -0
  19. package/dist/gesture-handler/gizmo/picture-expand-gizmo.js +491 -0
  20. package/dist/gesture-handler/gizmo/preference-gizmo.js +148 -0
  21. package/dist/gesture-handler/gizmo/selector-gizmo.d.ts +1 -1
  22. package/dist/gesture-handler/gizmo/selector-gizmo.js +468 -0
  23. package/dist/gesture-handler/gizmo/sprite-text-edit-gizmo.js +247 -0
  24. package/dist/gesture-handler/gizmo/text-gizmo.js +1033 -0
  25. package/dist/gesture-handler/gizmo/transform-gizmo.js +1199 -0
  26. package/dist/gesture-handler/gizmo/type.js +18 -0
  27. package/dist/gesture-handler/index.js +3 -0
  28. package/dist/gesture-handler/src/gesture-handler.js +770 -0
  29. package/dist/gesture-handler/src/icons.js +24 -0
  30. package/dist/gesture-handler/utils.js +40 -0
  31. package/dist/html-overlay/anchor-navigation-runtime.js +27 -0
  32. package/dist/html-overlay/auto-height-layout.d.ts +6 -0
  33. package/dist/html-overlay/auto-height-layout.js +7 -0
  34. package/dist/html-overlay/auto-height-runtime.js +132 -0
  35. package/dist/html-overlay/document-runtime.js +71 -0
  36. package/dist/html-overlay/document-transform.js +96 -0
  37. package/dist/html-overlay/dom-order.js +8 -0
  38. package/dist/html-overlay/host-message-runtime.js +24 -0
  39. package/dist/html-overlay/html-capture-runtime.js +282 -0
  40. package/dist/html-overlay/html-viewport-style.js +10 -0
  41. package/dist/html-overlay/index.js +1 -0
  42. package/dist/html-overlay/manager.d.ts +1 -0
  43. package/dist/html-overlay/manager.js +1677 -0
  44. package/dist/html-overlay/mime-utils.js +21 -0
  45. package/dist/html-overlay/overlay-transform.js +57 -0
  46. package/dist/html-overlay/path-utils.js +35 -0
  47. package/dist/html-overlay/shell-runtime.js +12 -0
  48. package/dist/index.cjs +34 -8
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.js +13 -75311
  51. package/dist/index.mjs +75337 -0
  52. package/dist/index.mjs.map +1 -0
  53. package/dist/layer-order.js +8 -0
  54. package/dist/math/box2.js +396 -0
  55. package/dist/math/circle.js +131 -0
  56. package/dist/math/euler.js +35 -0
  57. package/dist/math/index.js +13 -0
  58. package/dist/math/line2.js +153 -0
  59. package/dist/math/line3.js +36 -0
  60. package/dist/math/matrix4.js +207 -0
  61. package/dist/math/plane.js +52 -0
  62. package/dist/math/quaternion.js +3 -0
  63. package/dist/math/ray-caster.js +25 -0
  64. package/dist/math/ray.js +47 -0
  65. package/dist/math/type.js +1 -0
  66. package/dist/math/utils.js +77 -0
  67. package/dist/math/vector2.js +70 -0
  68. package/dist/math/vector3.js +60 -0
  69. package/dist/screen-shot/index.js +1 -0
  70. package/dist/screen-shot/screen-shot.js +113 -0
  71. package/dist/sdk-item/base-item.js +160 -0
  72. package/dist/sdk-item/card-item.js +131 -0
  73. package/dist/sdk-item/effects-item.js +144 -0
  74. package/dist/sdk-item/frame-item.js +217 -0
  75. package/dist/sdk-item/generator-item.js +188 -0
  76. package/dist/sdk-item/group-item.js +116 -0
  77. package/dist/sdk-item/index.js +39 -0
  78. package/dist/sdk-item/sprite-item.js +147 -0
  79. package/dist/sdk-item/text-item.js +223 -0
  80. package/dist/sdk-item/types.d.ts +1 -1
  81. package/dist/sdk-item/types.js +15 -0
  82. package/dist/sdk-item/video-item.js +174 -0
  83. package/dist/sdk.js +1908 -0
  84. package/dist/service/UndoRedo.js +79 -0
  85. package/dist/shared/index.d.ts +1 -0
  86. package/dist/shared/index.js +2 -0
  87. package/dist/shared/player.d.ts +1 -1
  88. package/dist/shared/player.js +9 -0
  89. package/dist/shared/spec.d.ts +1 -0
  90. package/dist/shared/spec.js +1 -0
  91. package/dist/size-adapte/index.js +1 -0
  92. package/dist/size-adapte/size-adapt.js +395 -0
  93. package/dist/types.d.ts +5 -1
  94. package/dist/types.js +17 -0
  95. package/dist/utils/background-manager.js +189 -0
  96. package/dist/utils/common-utils.js +183 -0
  97. package/dist/utils/index.js +8 -0
  98. package/dist/utils/interaction-utils.js +205 -0
  99. package/dist/utils/json-data-utils.js +1529 -0
  100. package/dist/utils/layout-utils.js +1217 -0
  101. package/dist/utils/page-data-utils.js +5397 -0
  102. package/dist/utils/player-data-utils.js +48 -0
  103. package/dist/utils/types.js +8 -0
  104. package/dist/wireframe/common/box.js +18 -0
  105. package/dist/wireframe/common/dashed-line.js +21 -0
  106. package/dist/wireframe/common/line.js +17 -0
  107. package/dist/wireframe/common/pixi-ext.js +1 -0
  108. package/dist/wireframe/common/pixi.js +31 -0
  109. package/dist/wireframe/index.js +4 -0
  110. package/package.json +10 -3
  111. package/dist/index.js.map +0 -1
@@ -0,0 +1,282 @@
1
+ const CAPTURE_TIMEOUT = 5000;
2
+ const MOTION_PROPERTIES = /^(animation|transition)(?:-|$)/i;
3
+ const RUNTIME_SELECTOR = [
4
+ '[data-hm-stream-runtime]',
5
+ '[data-vvfx-card-html-auto-height]',
6
+ '[data-vvfx-card-html-anchor-navigation-guard]',
7
+ 'script',
8
+ 'noscript',
9
+ 'template',
10
+ ].join(',');
11
+ export function captureViewportSize(logicalSize, _displayedBounds) {
12
+ return {
13
+ width: Math.max(1, logicalSize.width),
14
+ height: Math.max(1, logicalSize.height),
15
+ };
16
+ }
17
+ export function serializeComputedCaptureStyle(style) {
18
+ const declarations = [];
19
+ for (const property of style) {
20
+ if (MOTION_PROPERTIES.test(property)) {
21
+ continue;
22
+ }
23
+ const value = style.getPropertyValue(property);
24
+ if (!value) {
25
+ continue;
26
+ }
27
+ const priority = style.getPropertyPriority(property);
28
+ declarations.push(`${property}:${value}${priority ? `!${priority}` : ''}`);
29
+ }
30
+ declarations.push('animation:none!important', 'transition:none!important');
31
+ return declarations.join(';');
32
+ }
33
+ export async function createHTMLCaptureReplica(ownerDocument, html, logicalSize) {
34
+ const size = captureViewportSize(logicalSize);
35
+ const iframe = ownerDocument.createElement('iframe');
36
+ Object.assign(iframe.style, {
37
+ position: 'fixed',
38
+ left: '-100000px',
39
+ top: '0',
40
+ width: `${size.width}px`,
41
+ height: `${size.height}px`,
42
+ border: '0',
43
+ pointerEvents: 'none',
44
+ opacity: '1',
45
+ zIndex: '-1',
46
+ });
47
+ iframe.srcdoc = html;
48
+ const loaded = waitForNextLoad(iframe);
49
+ ownerDocument.body.appendChild(iframe);
50
+ await withCaptureTimeout(loaded);
51
+ const sourceDocument = iframe.contentDocument;
52
+ if (!sourceDocument?.documentElement || !sourceDocument.body) {
53
+ iframe.remove();
54
+ return undefined;
55
+ }
56
+ const replica = await createHTMLCaptureReplicaFromDocument(ownerDocument, sourceDocument, size);
57
+ if (!replica) {
58
+ iframe.remove();
59
+ return undefined;
60
+ }
61
+ return {
62
+ target: replica.target,
63
+ cleanup: () => {
64
+ replica.cleanup();
65
+ iframe.remove();
66
+ },
67
+ };
68
+ }
69
+ export async function createHTMLCaptureReplicaFromDocument(ownerDocument, sourceDocument, logicalSize) {
70
+ if (!sourceDocument.documentElement || !sourceDocument.body || !sourceDocument.defaultView) {
71
+ return undefined;
72
+ }
73
+ await withCaptureTimeout(waitForCaptureReady(sourceDocument));
74
+ const target = createComputedCaptureTarget(ownerDocument, sourceDocument, captureViewportSize(logicalSize));
75
+ return {
76
+ target,
77
+ cleanup: () => {
78
+ target.remove();
79
+ },
80
+ };
81
+ }
82
+ function createComputedCaptureTarget(ownerDocument, sourceDocument, size) {
83
+ const sourceWindow = sourceDocument.defaultView;
84
+ if (!sourceWindow) {
85
+ throw new Error('HTML capture replica has no window');
86
+ }
87
+ const frame = ownerDocument.createElement('div');
88
+ frame.setAttribute('data-vvfx-html-capture-replica', 'true');
89
+ frame.style.cssText = serializeComputedCaptureStyle(sourceWindow.getComputedStyle(sourceDocument.documentElement));
90
+ Object.assign(frame.style, {
91
+ position: 'fixed',
92
+ left: '-100000px',
93
+ top: '0',
94
+ width: `${size.width}px`,
95
+ height: `${size.height}px`,
96
+ overflow: 'hidden',
97
+ pointerEvents: 'none',
98
+ opacity: '1',
99
+ zIndex: '-1',
100
+ transform: 'none',
101
+ });
102
+ appendDocumentFontSurface(frame, sourceDocument, ownerDocument);
103
+ const sourceBody = sourceDocument.body;
104
+ const bodyClone = sourceBody.cloneNode(true);
105
+ bodyClone.querySelectorAll(RUNTIME_SELECTOR).forEach(node => {
106
+ node.remove();
107
+ });
108
+ if (bodyClone.matches(RUNTIME_SELECTOR)) {
109
+ bodyClone.replaceChildren();
110
+ }
111
+ frame.appendChild(bodyClone);
112
+ ownerDocument.body.appendChild(frame);
113
+ const sources = [sourceBody, ...Array.from(sourceBody.querySelectorAll('*'))]
114
+ .filter(isStylableElement)
115
+ .filter(node => !node.matches(RUNTIME_SELECTOR) && !node.closest(RUNTIME_SELECTOR));
116
+ const clones = [bodyClone, ...Array.from(bodyClone.querySelectorAll('*'))]
117
+ .filter(isStylableElement)
118
+ .filter(node => !node.matches(RUNTIME_SELECTOR) && !node.closest(RUNTIME_SELECTOR));
119
+ const pseudoRules = [];
120
+ sources.forEach((source, index) => {
121
+ const clone = clones[index];
122
+ if (!clone) {
123
+ return;
124
+ }
125
+ clone.style.cssText = serializeComputedCaptureStyle(sourceWindow.getComputedStyle(source));
126
+ freezeViewportPosition(source, clone, sourceWindow);
127
+ preserveLiveElementState(source, clone, ownerDocument);
128
+ appendPseudoRule(source, clone, sourceWindow, pseudoRules, index);
129
+ });
130
+ if (pseudoRules.length) {
131
+ const style = ownerDocument.createElement('style');
132
+ style.setAttribute('data-vvfx-html-capture-pseudo', 'true');
133
+ style.textContent = pseudoRules.join('\n');
134
+ frame.prepend(style);
135
+ }
136
+ return frame;
137
+ }
138
+ function appendDocumentFontSurface(frame, sourceDocument, ownerDocument) {
139
+ const fontRules = [];
140
+ const SourceCSSFontFaceRule = sourceDocument.defaultView?.CSSFontFaceRule;
141
+ Array.from(sourceDocument.styleSheets).forEach(sheet => {
142
+ try {
143
+ Array.from(sheet.cssRules).forEach(rule => {
144
+ if (SourceCSSFontFaceRule && rule instanceof SourceCSSFontFaceRule) {
145
+ fontRules.push(rule.cssText);
146
+ }
147
+ });
148
+ }
149
+ catch {
150
+ // Cross-origin font stylesheets are already loaded in the replica but cannot be read.
151
+ }
152
+ });
153
+ if (!fontRules.length) {
154
+ return;
155
+ }
156
+ const style = ownerDocument.createElement('style');
157
+ style.setAttribute('data-vvfx-html-capture-fonts', 'true');
158
+ style.textContent = fontRules.join('\n');
159
+ frame.appendChild(style);
160
+ }
161
+ function isStylableElement(element) {
162
+ return 'style' in element;
163
+ }
164
+ function freezeViewportPosition(source, clone, sourceWindow) {
165
+ if (sourceWindow.getComputedStyle(source).position !== 'fixed') {
166
+ return;
167
+ }
168
+ const rect = source.getBoundingClientRect();
169
+ Object.assign(clone.style, {
170
+ position: 'absolute',
171
+ left: `${rect.left}px`,
172
+ top: `${rect.top}px`,
173
+ right: 'auto',
174
+ bottom: 'auto',
175
+ width: `${rect.width}px`,
176
+ height: `${rect.height}px`,
177
+ });
178
+ }
179
+ function preserveLiveElementState(source, clone, ownerDocument) {
180
+ if (source instanceof source.ownerDocument.defaultView.HTMLImageElement && clone instanceof ownerDocument.defaultView.HTMLImageElement) {
181
+ clone.src = source.currentSrc || source.src;
182
+ }
183
+ if (source instanceof source.ownerDocument.defaultView.HTMLInputElement && clone instanceof ownerDocument.defaultView.HTMLInputElement) {
184
+ clone.value = source.value;
185
+ clone.checked = source.checked;
186
+ }
187
+ if (source instanceof source.ownerDocument.defaultView.HTMLTextAreaElement && clone instanceof ownerDocument.defaultView.HTMLTextAreaElement) {
188
+ clone.value = source.value;
189
+ clone.textContent = source.value;
190
+ }
191
+ if (source instanceof source.ownerDocument.defaultView.HTMLCanvasElement && clone instanceof ownerDocument.defaultView.HTMLCanvasElement) {
192
+ clone.width = source.width;
193
+ clone.height = source.height;
194
+ try {
195
+ clone.getContext('2d')?.drawImage(source, 0, 0);
196
+ }
197
+ catch {
198
+ // Tainted canvases remain empty; snapdom cannot legally read them either.
199
+ }
200
+ }
201
+ }
202
+ function appendPseudoRule(source, clone, sourceWindow, rules, index) {
203
+ const attribute = `capture-${index}`;
204
+ clone.setAttribute('data-vvfx-capture-node', attribute);
205
+ ['::before', '::after'].forEach(pseudo => {
206
+ const style = sourceWindow.getComputedStyle(source, pseudo);
207
+ if (!style.content || style.content === 'none' || style.content === 'normal') {
208
+ return;
209
+ }
210
+ rules.push(`[data-vvfx-capture-node="${attribute}"]${pseudo}{${serializeComputedCaptureStyle(style)}}`);
211
+ });
212
+ }
213
+ async function waitForCaptureReady(document) {
214
+ await document.fonts?.ready;
215
+ await Promise.all(Array.from(document.images).map(async (image) => {
216
+ try {
217
+ if (!image.complete) {
218
+ await new Promise(resolve => {
219
+ image.addEventListener('load', () => {
220
+ resolve();
221
+ }, { once: true });
222
+ image.addEventListener('error', () => {
223
+ resolve();
224
+ }, { once: true });
225
+ });
226
+ }
227
+ await image.decode?.();
228
+ }
229
+ catch {
230
+ // snapdom applies its own image placeholder policy after readiness.
231
+ }
232
+ }));
233
+ await waitForStableLayout(document);
234
+ }
235
+ async function waitForStableLayout(document) {
236
+ const view = document.defaultView;
237
+ if (!view) {
238
+ return;
239
+ }
240
+ const startedAt = performance.now();
241
+ let previous = '';
242
+ let stableFrames = 0;
243
+ while (performance.now() - startedAt < CAPTURE_TIMEOUT && stableFrames < 3) {
244
+ await new Promise(resolve => view.requestAnimationFrame(() => {
245
+ resolve();
246
+ }));
247
+ const current = [
248
+ document.documentElement.scrollWidth,
249
+ document.documentElement.scrollHeight,
250
+ document.body?.scrollWidth ?? 0,
251
+ document.body?.scrollHeight ?? 0,
252
+ document.styleSheets.length,
253
+ document.querySelectorAll('style').length,
254
+ ].join(':');
255
+ stableFrames = current === previous ? stableFrames + 1 : 0;
256
+ previous = current;
257
+ }
258
+ }
259
+ function waitForNextLoad(iframe) {
260
+ return new Promise(resolve => {
261
+ iframe.addEventListener('load', () => {
262
+ resolve();
263
+ }, { once: true });
264
+ iframe.addEventListener('error', () => {
265
+ resolve();
266
+ }, { once: true });
267
+ });
268
+ }
269
+ function withCaptureTimeout(promise) {
270
+ return new Promise(resolve => {
271
+ const timer = globalThis.setTimeout(() => {
272
+ resolve(undefined);
273
+ }, CAPTURE_TIMEOUT);
274
+ promise.then(value => {
275
+ globalThis.clearTimeout(timer);
276
+ resolve(value);
277
+ }, () => {
278
+ globalThis.clearTimeout(timer);
279
+ resolve(undefined);
280
+ });
281
+ });
282
+ }
@@ -0,0 +1,10 @@
1
+ export function withCardHTMLViewportStyle(html) {
2
+ const viewportStyle = '<style data-vvfx-html-viewport>html,body{width:100%;height:100%;margin:0;}*,*::before,*::after{box-sizing:border-box;}</style>';
3
+ if (/<head(?:\s[^>]*)?>/i.test(html)) {
4
+ return html.replace(/<head(\s[^>]*)?>/i, match => `${match}${viewportStyle}`);
5
+ }
6
+ if (/<html(?:\s[^>]*)?>/i.test(html)) {
7
+ return html.replace(/<html(\s[^>]*)?>/i, match => `${match}<head>${viewportStyle}</head>`);
8
+ }
9
+ return `<!doctype html><html><head>${viewportStyle}</head><body>${html}</body></html>`;
10
+ }
@@ -0,0 +1 @@
1
+ export { HTMLOverlayManager } from './manager';
@@ -137,6 +137,7 @@ export declare class HTMLOverlayManager {
137
137
  private isAutoHeightStreamActive;
138
138
  private getAutoHeightAnchor;
139
139
  private getAutoHeightItemHeight;
140
+ private getAutoHeightLimit;
140
141
  private isAutoHeightEnabled;
141
142
  private isAutoScaleEnabled;
142
143
  }