@openfairygui/functions 0.2.0-alpha.2 → 0.2.0-alpha.21

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 (54) hide show
  1. package/README.md +48 -6
  2. package/dist/atlas-C6tbl7nn.d.ts +193 -0
  3. package/dist/atlas-CHsu2Y8i.d.cts +193 -0
  4. package/dist/index.cjs +16 -3603
  5. package/dist/index.d.cts +5 -294
  6. package/dist/index.d.ts +5 -294
  7. package/dist/index.js +3 -3594
  8. package/dist/node.cjs +256 -0
  9. package/dist/node.d.cts +36 -0
  10. package/dist/node.d.ts +36 -0
  11. package/dist/node.js +254 -0
  12. package/dist/publish-BJ_eelME.js +3267 -0
  13. package/dist/publish-xFWT9Slz.cjs +3338 -0
  14. package/dist/restore-BW2xacB3.cjs +936 -0
  15. package/dist/restore-BeWaJNjR.d.cts +288 -0
  16. package/dist/restore-Clk62n0O.js +931 -0
  17. package/dist/restore-Dh0-Nvms.d.ts +288 -0
  18. package/dist/uam-transaction.cjs +44 -1
  19. package/dist/uam-transaction.d.cts +16 -1
  20. package/dist/uam-transaction.d.ts +16 -1
  21. package/dist/uam-transaction.js +44 -1
  22. package/dist/web.cjs +274 -0
  23. package/dist/web.d.cts +41 -0
  24. package/dist/web.d.ts +41 -0
  25. package/dist/web.js +273 -0
  26. package/package.json +28 -4
  27. package/src/adapters/node/plugins.ts +82 -0
  28. package/src/adapters/node/publish.ts +130 -0
  29. package/src/adapters/node/restore.ts +187 -0
  30. package/src/adapters/web/publish.ts +159 -0
  31. package/src/adapters/web/raster.ts +251 -0
  32. package/src/atlas/font.ts +95 -0
  33. package/src/atlas/inputs.ts +515 -0
  34. package/src/atlas/jta.ts +211 -0
  35. package/src/atlas/packing.ts +767 -0
  36. package/src/atlas.ts +116 -1221
  37. package/src/codegen.ts +106 -67
  38. package/src/index.ts +43 -3
  39. package/src/node.ts +8 -0
  40. package/src/plugins/types.ts +56 -0
  41. package/src/publish/contracts.ts +80 -0
  42. package/src/publish/external-resources.ts +117 -0
  43. package/src/publish/options.ts +180 -0
  44. package/src/publish/package-context.ts +608 -0
  45. package/src/publish/resource-references.ts +210 -0
  46. package/src/publish.ts +290 -968
  47. package/src/restore-internals/font.ts +100 -0
  48. package/src/restore-internals/movie-clip.ts +104 -0
  49. package/src/restore-internals/output-transaction.ts +164 -0
  50. package/src/restore.ts +112 -311
  51. package/src/shared-types.ts +4 -8
  52. package/src/uam-transaction.ts +68 -0
  53. package/src/utils.ts +28 -0
  54. package/src/web.ts +11 -0
@@ -0,0 +1,211 @@
1
+ export interface JtaFrameMeta {
2
+ addDelay: number;
3
+ offsetX: number;
4
+ offsetY: number;
5
+ width: number;
6
+ height: number;
7
+ textureIndex: number;
8
+ }
9
+
10
+ export interface JtaMeta {
11
+ interval: number;
12
+ repeatDelay: number;
13
+ swing: boolean;
14
+ width: number;
15
+ height: number;
16
+ frames: JtaFrameMeta[];
17
+ }
18
+
19
+ export interface ExtractedJtaData {
20
+ frames: Uint8Array[];
21
+ meta?: JtaMeta;
22
+ }
23
+
24
+ const PNG_SIGNATURE = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
25
+
26
+ export function extractJtaFrames(data: Uint8Array): ExtractedJtaData {
27
+ const frames: Uint8Array[] = [];
28
+ let offset = 0;
29
+ let firstPngOffset = -1;
30
+
31
+ while (offset < data.length) {
32
+ const signatureIndex = findPngSignature(data, offset);
33
+ if (signatureIndex === -1) break;
34
+ if (firstPngOffset === -1) firstPngOffset = signatureIndex;
35
+ const end = findPngEnd(data, signatureIndex);
36
+ if (end === -1) break;
37
+ frames.push(data.subarray(signatureIndex, end));
38
+ offset = end;
39
+ }
40
+
41
+ if (firstPngOffset === -1 || frames.length === 0) {
42
+ return { frames: [] };
43
+ }
44
+
45
+ return {
46
+ frames,
47
+ meta: parseJtaHeader(data, firstPngOffset, frames.length),
48
+ };
49
+ }
50
+
51
+ function findPngSignature(data: Uint8Array, fromIndex: number): number {
52
+ for (let index = fromIndex; index <= data.length - PNG_SIGNATURE.length; index += 1) {
53
+ let matched = true;
54
+ for (let signatureIndex = 0; signatureIndex < PNG_SIGNATURE.length; signatureIndex += 1) {
55
+ if (data[index + signatureIndex] !== PNG_SIGNATURE[signatureIndex]) {
56
+ matched = false;
57
+ break;
58
+ }
59
+ }
60
+ if (matched) return index;
61
+ }
62
+ return -1;
63
+ }
64
+
65
+ function findPngEnd(data: Uint8Array, start: number): number {
66
+ let position = start + PNG_SIGNATURE.length;
67
+ while (position + 8 <= data.length) {
68
+ const length = readUint32BE(data, position);
69
+ position += 8;
70
+ if (position + length + 4 > data.length) return -1;
71
+ const isEnd =
72
+ data[position - 4] === 0x49 &&
73
+ data[position - 3] === 0x45 &&
74
+ data[position - 2] === 0x4e &&
75
+ data[position - 1] === 0x44;
76
+ position += length + 4;
77
+ if (isEnd) return position;
78
+ }
79
+ return -1;
80
+ }
81
+
82
+ function parseJtaHeader(data: Uint8Array, firstPngOffset: number, frameCount: number): JtaMeta | undefined {
83
+ if (data.length < 10) return undefined;
84
+
85
+ const state = { offset: 0 };
86
+ const end = Math.min(firstPngOffset, data.length);
87
+ const mark = readUtfBE(data, state, end);
88
+ if (!mark) return undefined;
89
+
90
+ const version = readInt32BEAt(data, state, end);
91
+ if (version == null) return undefined;
92
+
93
+ const fpsRaw = readInt8At(data, state, end);
94
+ if (fpsRaw == null) return undefined;
95
+ const fps = fpsRaw > 0 ? fpsRaw : 24;
96
+
97
+ if (state.offset + 3 > end) return undefined;
98
+ state.offset += 3;
99
+
100
+ if (version < 102) return undefined;
101
+
102
+ readUint16BEAt(data, state, end);
103
+ readUint16BEAt(data, state, end);
104
+ const width = readUint16BEAt(data, state, end);
105
+ const height = readUint16BEAt(data, state, end);
106
+ if (width == null || height == null) return undefined;
107
+
108
+ const speedRaw = readUint8At(data, state, end);
109
+ const repeatDelayRaw = readUint8At(data, state, end);
110
+ const swingRaw = readInt8At(data, state, end);
111
+ const frameTableCount = readInt16BEAt(data, state, end);
112
+ if (speedRaw == null || repeatDelayRaw == null || swingRaw == null || frameTableCount == null) return undefined;
113
+
114
+ const frames: JtaFrameMeta[] = [];
115
+ for (let index = 0; index < frameTableCount; index += 1) {
116
+ const delayRaw = readInt16BEAt(data, state, end);
117
+ const offsetX = readInt16BEAt(data, state, end);
118
+ const offsetY = readInt16BEAt(data, state, end);
119
+ const frameWidth = readInt16BEAt(data, state, end);
120
+ const frameHeight = readInt16BEAt(data, state, end);
121
+ const textureIndex = readInt16BEAt(data, state, end);
122
+ if (
123
+ delayRaw == null ||
124
+ offsetX == null ||
125
+ offsetY == null ||
126
+ frameWidth == null ||
127
+ frameHeight == null ||
128
+ textureIndex == null
129
+ ) {
130
+ break;
131
+ }
132
+ frames.push({
133
+ addDelay: Math.trunc((1000 / fps) * delayRaw),
134
+ offsetX,
135
+ offsetY,
136
+ width: frameWidth,
137
+ height: frameHeight,
138
+ textureIndex,
139
+ });
140
+ }
141
+
142
+ return {
143
+ interval: Math.trunc((1000 / fps) * (speedRaw || 1)),
144
+ repeatDelay: Math.trunc((1000 / fps) * repeatDelayRaw),
145
+ swing: swingRaw === 1,
146
+ width,
147
+ height,
148
+ frames: frames.length === 0 && frameCount > 0 ? [] : frames,
149
+ };
150
+ }
151
+
152
+ function readUtfBE(data: Uint8Array, state: { offset: number }, end: number): string | null {
153
+ const length = readUint16BEAt(data, state, end);
154
+ if (length == null || state.offset + length > end) return null;
155
+ const value = new TextDecoder().decode(data.subarray(state.offset, state.offset + length));
156
+ state.offset += length;
157
+ return value;
158
+ }
159
+
160
+ function readUint8At(data: Uint8Array, state: { offset: number }, end: number): number | null {
161
+ if (state.offset + 1 > end) return null;
162
+ const value = data[state.offset];
163
+ state.offset += 1;
164
+ return value ?? 0;
165
+ }
166
+
167
+ function readInt8At(data: Uint8Array, state: { offset: number }, end: number): number | null {
168
+ if (state.offset + 1 > end) return null;
169
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
170
+ const value = view.getInt8(state.offset);
171
+ state.offset += 1;
172
+ return value;
173
+ }
174
+
175
+ function readUint16BEAt(data: Uint8Array, state: { offset: number }, end: number): number | null {
176
+ if (state.offset + 2 > end) return null;
177
+ const value = readUint16BE(data, state.offset);
178
+ state.offset += 2;
179
+ return value;
180
+ }
181
+
182
+ function readInt16BEAt(data: Uint8Array, state: { offset: number }, end: number): number | null {
183
+ if (state.offset + 2 > end) return null;
184
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
185
+ const value = view.getInt16(state.offset, false);
186
+ state.offset += 2;
187
+ return value;
188
+ }
189
+
190
+ function readInt32BEAt(data: Uint8Array, state: { offset: number }, end: number): number | null {
191
+ if (state.offset + 4 > end) return null;
192
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
193
+ const value = view.getInt32(state.offset, false);
194
+ state.offset += 4;
195
+ return value;
196
+ }
197
+
198
+ function readUint16BE(data: Uint8Array, offset: number): number {
199
+ if (offset + 1 >= data.length) return 0;
200
+ return (data[offset] << 8) | data[offset + 1];
201
+ }
202
+
203
+ function readUint32BE(data: Uint8Array, offset: number): number {
204
+ if (offset + 3 >= data.length) return 0;
205
+ return (
206
+ data[offset] * 0x1000000 +
207
+ ((data[offset + 1] ?? 0) << 16) +
208
+ ((data[offset + 2] ?? 0) << 8) +
209
+ (data[offset + 3] ?? 0)
210
+ );
211
+ }