@flighthq/spritesheet-formats 0.1.0

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 (75) hide show
  1. package/dist/asepriteParse.d.ts +18 -0
  2. package/dist/asepriteParse.d.ts.map +1 -0
  3. package/dist/asepriteParse.js +87 -0
  4. package/dist/asepriteParse.js.map +1 -0
  5. package/dist/asepriteSchema.d.ts +64 -0
  6. package/dist/asepriteSchema.d.ts.map +1 -0
  7. package/dist/asepriteSchema.js +6 -0
  8. package/dist/asepriteSchema.js.map +1 -0
  9. package/dist/asepriteSerialize.d.ts +14 -0
  10. package/dist/asepriteSerialize.d.ts.map +1 -0
  11. package/dist/asepriteSerialize.js +86 -0
  12. package/dist/asepriteSerialize.js.map +1 -0
  13. package/dist/cocosPlistParse.d.ts +15 -0
  14. package/dist/cocosPlistParse.d.ts.map +1 -0
  15. package/dist/cocosPlistParse.js +157 -0
  16. package/dist/cocosPlistParse.js.map +1 -0
  17. package/dist/cocosPlistSchema.d.ts +31 -0
  18. package/dist/cocosPlistSchema.d.ts.map +1 -0
  19. package/dist/cocosPlistSchema.js +6 -0
  20. package/dist/cocosPlistSchema.js.map +1 -0
  21. package/dist/cocosPlistSerialize.d.ts +8 -0
  22. package/dist/cocosPlistSerialize.d.ts.map +1 -0
  23. package/dist/cocosPlistSerialize.js +86 -0
  24. package/dist/cocosPlistSerialize.js.map +1 -0
  25. package/dist/index.d.ts +16 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +16 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/libgdxAtlasParse.d.ts +13 -0
  30. package/dist/libgdxAtlasParse.d.ts.map +1 -0
  31. package/dist/libgdxAtlasParse.js +209 -0
  32. package/dist/libgdxAtlasParse.js.map +1 -0
  33. package/dist/libgdxAtlasSchema.d.ts +38 -0
  34. package/dist/libgdxAtlasSchema.d.ts.map +1 -0
  35. package/dist/libgdxAtlasSchema.js +6 -0
  36. package/dist/libgdxAtlasSchema.js.map +1 -0
  37. package/dist/spritesheetDetect.d.ts +41 -0
  38. package/dist/spritesheetDetect.d.ts.map +1 -0
  39. package/dist/spritesheetDetect.js +101 -0
  40. package/dist/spritesheetDetect.js.map +1 -0
  41. package/dist/starlingParse.d.ts +20 -0
  42. package/dist/starlingParse.d.ts.map +1 -0
  43. package/dist/starlingParse.js +138 -0
  44. package/dist/starlingParse.js.map +1 -0
  45. package/dist/starlingSchema.d.ts +32 -0
  46. package/dist/starlingSchema.d.ts.map +1 -0
  47. package/dist/starlingSchema.js +6 -0
  48. package/dist/starlingSchema.js.map +1 -0
  49. package/dist/starlingSerialize.d.ts +8 -0
  50. package/dist/starlingSerialize.d.ts.map +1 -0
  51. package/dist/starlingSerialize.js +67 -0
  52. package/dist/starlingSerialize.js.map +1 -0
  53. package/dist/texturePackerParse.d.ts +15 -0
  54. package/dist/texturePackerParse.d.ts.map +1 -0
  55. package/dist/texturePackerParse.js +70 -0
  56. package/dist/texturePackerParse.js.map +1 -0
  57. package/dist/texturePackerSchema.d.ts +52 -0
  58. package/dist/texturePackerSchema.d.ts.map +1 -0
  59. package/dist/texturePackerSchema.js +5 -0
  60. package/dist/texturePackerSchema.js.map +1 -0
  61. package/dist/texturePackerSerialize.d.ts +14 -0
  62. package/dist/texturePackerSerialize.d.ts.map +1 -0
  63. package/dist/texturePackerSerialize.js +74 -0
  64. package/dist/texturePackerSerialize.js.map +1 -0
  65. package/package.json +41 -0
  66. package/src/asepriteParse.test.ts +235 -0
  67. package/src/asepriteSerialize.test.ts +218 -0
  68. package/src/cocosPlistParse.test.ts +131 -0
  69. package/src/cocosPlistSerialize.test.ts +56 -0
  70. package/src/libgdxAtlasParse.test.ts +100 -0
  71. package/src/spritesheetDetect.test.ts +217 -0
  72. package/src/starlingParse.test.ts +176 -0
  73. package/src/starlingSerialize.test.ts +117 -0
  74. package/src/texturePackerParse.test.ts +237 -0
  75. package/src/texturePackerSerialize.test.ts +200 -0
@@ -0,0 +1,86 @@
1
+ /** Serialise a SpritesheetData to a Cocos Creator / Cocos2d-x plist XML atlas string.
2
+ *
3
+ * Pass the `document` returned by `parseCocosPlistSpritesheetDocument` to preserve any
4
+ * fields that don't round-trip through the data (format version, metadata). */
5
+ export function serializeCocosPlistSpritesheet(data, existing) {
6
+ const frames = {};
7
+ for (const frame of data.frames) {
8
+ frames[frame.name] = frameToEntry(frame);
9
+ }
10
+ const doc = {
11
+ frames,
12
+ metadata: {
13
+ format: existing?.metadata?.format ?? 3,
14
+ size: `{${data.imageWidth},${data.imageHeight}}`,
15
+ textureFileName: data.imageFile || existing?.metadata?.textureFileName || '',
16
+ },
17
+ };
18
+ return documentToXml(doc);
19
+ }
20
+ function documentToXml(doc) {
21
+ const lines = [
22
+ '<?xml version="1.0" encoding="UTF-8"?>',
23
+ '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
24
+ '<plist version="1.0">',
25
+ '<dict>',
26
+ '\t<key>frames</key>',
27
+ '\t<dict>',
28
+ ];
29
+ for (const [name, frame] of Object.entries(doc.frames)) {
30
+ lines.push(`\t\t<key>${escapeXml(name)}</key>`);
31
+ lines.push('\t\t<dict>');
32
+ lines.push(`\t\t\t<key>frame</key>`);
33
+ lines.push(`\t\t\t<string>${escapeXml(frame.frame)}</string>`);
34
+ lines.push(`\t\t\t<key>spriteOffset</key>`);
35
+ lines.push(`\t\t\t<string>${escapeXml(frame.spriteOffset)}</string>`);
36
+ lines.push(`\t\t\t<key>spriteSize</key>`);
37
+ lines.push(`\t\t\t<string>${escapeXml(frame.spriteSize)}</string>`);
38
+ lines.push(`\t\t\t<key>spriteSourceSize</key>`);
39
+ lines.push(`\t\t\t<string>${escapeXml(frame.spriteSourceSize)}</string>`);
40
+ lines.push(`\t\t\t<key>spriteTrimmed</key>`);
41
+ lines.push(`\t\t\t${plistValue(frame.spriteTrimmed)}`);
42
+ lines.push(`\t\t\t<key>textureRotated</key>`);
43
+ lines.push(`\t\t\t${plistValue(frame.textureRotated)}`);
44
+ lines.push('\t\t</dict>');
45
+ }
46
+ lines.push('\t</dict>');
47
+ lines.push('\t<key>metadata</key>');
48
+ lines.push('\t<dict>');
49
+ lines.push('\t\t<key>format</key>');
50
+ lines.push(`\t\t<integer>${doc.metadata.format}</integer>`);
51
+ lines.push('\t\t<key>size</key>');
52
+ lines.push(`\t\t<string>${escapeXml(doc.metadata.size)}</string>`);
53
+ lines.push('\t\t<key>textureFileName</key>');
54
+ lines.push(`\t\t<string>${escapeXml(doc.metadata.textureFileName)}</string>`);
55
+ lines.push('\t</dict>');
56
+ lines.push('</dict>');
57
+ lines.push('</plist>');
58
+ return lines.join('\n');
59
+ }
60
+ function escapeXml(s) {
61
+ return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
62
+ }
63
+ function frameToEntry(frame) {
64
+ const rectStr = `{{${frame.x},${frame.y}},{${frame.width},${frame.height}}}`;
65
+ const offsetStr = `{${frame.offsetX},${frame.offsetY}}`;
66
+ const sourceSizeStr = `{${frame.sourceWidth},${frame.sourceHeight}}`;
67
+ const sizeStr = `{${frame.width},${frame.height}}`;
68
+ const trimmed = frame.offsetX !== 0 ||
69
+ frame.offsetY !== 0 ||
70
+ frame.sourceWidth !== frame.width ||
71
+ frame.sourceHeight !== frame.height;
72
+ return {
73
+ frame: rectStr,
74
+ spriteOffset: offsetStr,
75
+ spriteSize: sizeStr,
76
+ spriteSourceSize: sourceSizeStr,
77
+ spriteTrimmed: trimmed,
78
+ textureRotated: frame.rotated,
79
+ };
80
+ }
81
+ function plistValue(el) {
82
+ if (typeof el === 'boolean')
83
+ return el ? '<true/>' : '<false/>';
84
+ return `<string>${escapeXml(String(el))}</string>`;
85
+ }
86
+ //# sourceMappingURL=cocosPlistSerialize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cocosPlistSerialize.js","sourceRoot":"","sources":["../src/cocosPlistSerialize.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Aa;QAC/B,aAAa,EAAE,OAAO;QACtB,cAAc,EAAE,KAAK,CAAC,OAAO;KAC9B,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,EAAW;IAC7B,IAAI,OAAO,EAAE,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;IAChE,OAAO,WAAW,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC;AACrD,CAAC"}
@@ -0,0 +1,16 @@
1
+ export * from './asepriteParse';
2
+ export * from './asepriteSchema';
3
+ export * from './asepriteSerialize';
4
+ export * from './cocosPlistParse';
5
+ export * from './cocosPlistSchema';
6
+ export * from './cocosPlistSerialize';
7
+ export * from './libgdxAtlasParse';
8
+ export * from './libgdxAtlasSchema';
9
+ export * from './spritesheetDetect';
10
+ export * from './starlingParse';
11
+ export * from './starlingSchema';
12
+ export * from './starlingSerialize';
13
+ export * from './texturePackerParse';
14
+ export * from './texturePackerSchema';
15
+ export * from './texturePackerSerialize';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ export * from './asepriteParse';
2
+ export * from './asepriteSchema';
3
+ export * from './asepriteSerialize';
4
+ export * from './cocosPlistParse';
5
+ export * from './cocosPlistSchema';
6
+ export * from './cocosPlistSerialize';
7
+ export * from './libgdxAtlasParse';
8
+ export * from './libgdxAtlasSchema';
9
+ export * from './spritesheetDetect';
10
+ export * from './starlingParse';
11
+ export * from './starlingSchema';
12
+ export * from './starlingSerialize';
13
+ export * from './texturePackerParse';
14
+ export * from './texturePackerSchema';
15
+ export * from './texturePackerSerialize';
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { SpritesheetData } from '@flighthq/spritesheet';
2
+ export interface LibgdxAtlasParseOptions {
3
+ /** Default duration (ms) per frame when building inferred animations. Defaults to 100. */
4
+ frameDuration?: number;
5
+ }
6
+ /** Parse a LibGDX `.atlas` text string directly to a `SpritesheetData`.
7
+ *
8
+ * Single-pass line-by-line parser. Handles single-page and multi-page atlases.
9
+ * `rotate: true` regions are marked as `rotated` (90° clockwise in the atlas).
10
+ * Animations are inferred from the standard `baseName_NNN` frame-naming convention;
11
+ * indexed regions (`index >= 0`) are also grouped into animations. */
12
+ export declare function parseLibgdxAtlasSpritesheet(text: string, options?: LibgdxAtlasParseOptions): SpritesheetData;
13
+ //# sourceMappingURL=libgdxAtlasParse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libgdxAtlasParse.d.ts","sourceRoot":"","sources":["../src/libgdxAtlasParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,eAAe,EAAwB,MAAM,uBAAuB,CAAC;AAU7G,MAAM,WAAW,uBAAuB;IACtC,0FAA0F;IAC1F,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAoND;;;;;uEAKuE;AACvE,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,eAAe,CAyB5G"}
@@ -0,0 +1,209 @@
1
+ import { createSpritesheetAnimationData, createSpritesheetData, createSpritesheetFrameData, } from '@flighthq/spritesheet';
2
+ import { createTextureAtlas } from '@flighthq/textureatlas';
3
+ import { parseTextureAtlasLibgdxAtlas } from '@flighthq/textureatlas-formats';
4
+ // ─── Parser ───────────────────────────────────────────────────────────────────
5
+ function parseIntPair(value) {
6
+ const parts = value.split(',');
7
+ return [parseInt(parts[0] ?? '0', 10), parseInt(parts[1] ?? '0', 10)];
8
+ }
9
+ function isFilename(line) {
10
+ return /[./]/.test(line) || /^\w+\.\w+$/.test(line);
11
+ }
12
+ function parseLibgdxAtlas(text) {
13
+ const lines = text.split(/\r?\n/);
14
+ const pages = [];
15
+ const regions = [];
16
+ let currentPage = null;
17
+ let currentRegion = null;
18
+ for (const raw of lines) {
19
+ const trimmed = raw.trim();
20
+ if (trimmed === '') {
21
+ // Blank line: commit any in-progress region; next unindented non-empty line is a page filename
22
+ if (currentRegion !== null) {
23
+ regions.push(currentRegion);
24
+ currentRegion = null;
25
+ }
26
+ continue;
27
+ }
28
+ const isIndented = raw[0] === ' ' || raw[0] === '\t';
29
+ if (isIndented) {
30
+ // Key: value line belonging to current page header or current region
31
+ const colonIdx = trimmed.indexOf(':');
32
+ if (colonIdx === -1)
33
+ continue;
34
+ const key = trimmed.slice(0, colonIdx).trim();
35
+ const value = trimmed.slice(colonIdx + 1).trim();
36
+ if (currentRegion !== null) {
37
+ // Region attribute
38
+ switch (key) {
39
+ case 'rotate':
40
+ currentRegion.rotated = value === 'true';
41
+ break;
42
+ case 'xy': {
43
+ const [x, y] = parseIntPair(value);
44
+ currentRegion.x = x;
45
+ currentRegion.y = y;
46
+ break;
47
+ }
48
+ case 'size': {
49
+ const [w, h] = parseIntPair(value);
50
+ currentRegion.spriteWidth = w;
51
+ currentRegion.spriteHeight = h;
52
+ break;
53
+ }
54
+ case 'orig': {
55
+ const [sw, sh] = parseIntPair(value);
56
+ currentRegion.sourceWidth = sw;
57
+ currentRegion.sourceHeight = sh;
58
+ break;
59
+ }
60
+ case 'offset': {
61
+ const [ox, oy] = parseIntPair(value);
62
+ currentRegion.offsetX = ox;
63
+ currentRegion.offsetY = oy;
64
+ break;
65
+ }
66
+ case 'index':
67
+ currentRegion.index = parseInt(value, 10);
68
+ break;
69
+ }
70
+ }
71
+ else if (currentPage !== null) {
72
+ // Page header attribute
73
+ switch (key) {
74
+ case 'size': {
75
+ const [w, h] = parseIntPair(value);
76
+ currentPage.width = w;
77
+ currentPage.height = h;
78
+ break;
79
+ }
80
+ }
81
+ }
82
+ }
83
+ else {
84
+ // Unindented non-empty line: either a page filename or a region name
85
+ if (currentRegion !== null) {
86
+ regions.push(currentRegion);
87
+ currentRegion = null;
88
+ }
89
+ if (isFilename(trimmed) && currentPage === null) {
90
+ // First unindented non-kv line after a blank (or at start) is a page filename
91
+ currentPage = { filename: trimmed, height: 0, width: 0 };
92
+ pages.push(currentPage);
93
+ }
94
+ else if (isFilename(trimmed) && currentPage !== null && trimmed !== currentPage.filename) {
95
+ // Another page filename (multi-page atlas)
96
+ currentPage = { filename: trimmed, height: 0, width: 0 };
97
+ pages.push(currentPage);
98
+ }
99
+ else {
100
+ // Region name
101
+ if (currentPage === null) {
102
+ // Malformed: no page seen yet; create a stub page
103
+ currentPage = { filename: '', height: 0, width: 0 };
104
+ pages.push(currentPage);
105
+ }
106
+ currentRegion = {
107
+ index: -1,
108
+ name: trimmed,
109
+ offsetX: 0,
110
+ offsetY: 0,
111
+ page: currentPage,
112
+ rotated: false,
113
+ sourceHeight: 0,
114
+ sourceWidth: 0,
115
+ spriteHeight: 0,
116
+ spriteWidth: 0,
117
+ x: 0,
118
+ y: 0,
119
+ };
120
+ }
121
+ }
122
+ }
123
+ // Commit trailing region
124
+ if (currentRegion !== null) {
125
+ regions.push(currentRegion);
126
+ }
127
+ return { pages, regions };
128
+ }
129
+ // ─── Internal helpers ─────────────────────────────────────────────────────────
130
+ // Maps an atlas region (geometry owned by @flighthq/textureatlas-formats — incl. libGDX rotate/orig/
131
+ // offset handling and the `name_index` disambiguation for indexed regions) to a spritesheet frame.
132
+ function frameFromRegion(region) {
133
+ return createSpritesheetFrameData({
134
+ height: region.height,
135
+ name: region.name ?? '',
136
+ offsetX: region.sourceX,
137
+ offsetY: region.sourceY,
138
+ pivotX: region.pivotX,
139
+ pivotY: region.pivotY,
140
+ rotated: region.rotated,
141
+ sourceHeight: region.originalHeight ?? region.height,
142
+ sourceWidth: region.originalWidth ?? region.width,
143
+ width: region.width,
144
+ x: region.x,
145
+ y: region.y,
146
+ });
147
+ }
148
+ /** Infer animations from frame names using the `baseName_NNN` convention.
149
+ * Frames whose names do not end in a numeric suffix are left as standalone frames. */
150
+ function inferAnimations(frameNames, frameDuration) {
151
+ const groups = new Map();
152
+ for (const name of frameNames) {
153
+ const noExt = name.replace(/\.\w+$/, '');
154
+ const match = noExt.match(/^(.*?)_?(\d+)$/);
155
+ if (!match)
156
+ continue;
157
+ const [, base, numStr] = match;
158
+ const index = parseInt(numStr, 10);
159
+ const bucket = groups.get(base);
160
+ if (bucket)
161
+ bucket.push({ index, name });
162
+ else
163
+ groups.set(base, [{ index, name }]);
164
+ }
165
+ const animations = [];
166
+ for (const [base, entries] of groups) {
167
+ if (entries.length < 2)
168
+ continue;
169
+ entries.sort((a, b) => a.index - b.index);
170
+ animations.push(createSpritesheetAnimationData({
171
+ frameDuration,
172
+ frameNames: entries.map((e) => e.name),
173
+ loop: true,
174
+ name: base,
175
+ }));
176
+ }
177
+ return animations;
178
+ }
179
+ // ─── Public API ───────────────────────────────────────────────────────────────
180
+ /** Parse a LibGDX `.atlas` text string directly to a `SpritesheetData`.
181
+ *
182
+ * Single-pass line-by-line parser. Handles single-page and multi-page atlases.
183
+ * `rotate: true` regions are marked as `rotated` (90° clockwise in the atlas).
184
+ * Animations are inferred from the standard `baseName_NNN` frame-naming convention;
185
+ * indexed regions (`index >= 0`) are also grouped into animations. */
186
+ export function parseLibgdxAtlasSpritesheet(text, options) {
187
+ const frameDuration = options?.frameDuration ?? 100;
188
+ // Page metadata (image file + size) is libGDX-specific and not modeled by TextureAtlas, so it is read
189
+ // from the local page parse; the region geometry is delegated to the atlas-formats parser.
190
+ const { pages } = parseLibgdxAtlas(text);
191
+ // Use the first page for top-level image metadata
192
+ const firstPage = pages[0];
193
+ const imageFile = firstPage?.filename ?? '';
194
+ const imageWidth = firstPage?.width ?? 0;
195
+ const imageHeight = firstPage?.height ?? 0;
196
+ const regions = parseTextureAtlasLibgdxAtlas(text, createTextureAtlas()).regions;
197
+ const frames = regions.map(frameFromRegion);
198
+ const frameNames = frames.map((f) => f.name);
199
+ const animations = inferAnimations(frameNames, frameDuration);
200
+ return createSpritesheetData({
201
+ animations,
202
+ frames,
203
+ imageFile,
204
+ imageHeight,
205
+ imageWidth,
206
+ scale: 1,
207
+ });
208
+ }
209
+ //# sourceMappingURL=libgdxAtlasParse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libgdxAtlasParse.js","sourceRoot":"","sources":["../src/libgdxAtlasParse.ts"],"names":[],"mappings":"AACA,OAAO,EACL,8BAA8B,EAC9B,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,4BAA4B,EAAE,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S;QACT,WAAW;QACX,UAAU;QACV,KAAK,EAAE,CAAC;KACT,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,38 @@
1
+ export interface LibgdxAtlasDocument {
2
+ pages: LibgdxAtlasPage[];
3
+ }
4
+ export interface LibgdxAtlasPage {
5
+ /** Texture filter for downscaling. */
6
+ filterMag: string;
7
+ /** Texture filter for upscaling. */
8
+ filterMin: string;
9
+ /** Pixel format string (e.g. 'RGBA8888'). */
10
+ format: string;
11
+ /** Relative path to the atlas image file for this page. */
12
+ imageFile: string;
13
+ /** Regions packed onto this page. */
14
+ regions: LibgdxAtlasRegion[];
15
+ /** Texture repeat mode. */
16
+ repeat: string;
17
+ /** Atlas image dimensions [width, height]. */
18
+ size: [number, number];
19
+ }
20
+ export interface LibgdxAtlasRegion {
21
+ /** Zero-based sequential index for animation grouping (-1 when unused). */
22
+ index: number;
23
+ /** Region name as written in the atlas. */
24
+ name: string;
25
+ /** Packed [x, y] position used for 9-patch or trim (same as xy when untrimmed). */
26
+ offset: [number, number];
27
+ /** Offset from original image top-left to the trimmed content [x, y]. */
28
+ orig: [number, number];
29
+ /** [originalWidth, originalHeight] of the region before trimming. */
30
+ origSize: [number, number];
31
+ /** Whether the region is rotated 90° CCW in the atlas. */
32
+ rotate: boolean;
33
+ /** [width, height] of the region in the atlas. */
34
+ size: [number, number];
35
+ /** [x, y] position of the region in the atlas. */
36
+ xy: [number, number];
37
+ }
38
+ //# sourceMappingURL=libgdxAtlasSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libgdxAtlasSchema.d.ts","sourceRoot":"","sources":["../src/libgdxAtlasSchema.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,eAAe,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,mFAAmF;IACnF,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzB,yEAAyE;IACzE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvB,qEAAqE;IACrE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,0DAA0D;IAC1D,MAAM,EAAE,OAAO,CAAC;IAChB,kDAAkD;IAClD,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvB,kDAAkD;IAClD,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtB"}
@@ -0,0 +1,6 @@
1
+ // libGDX / Spine text-format atlas schema.
2
+ // Reference: https://libgdx.com/wiki/tools/texture-packer#atlas-file-format
3
+ // The .atlas / pack.atlas text format is widely used across libGDX, Spine, and related tooling.
4
+ // A file may contain multiple pages, each beginning with a blank line followed by the image filename.
5
+ export {};
6
+ //# sourceMappingURL=libgdxAtlasSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libgdxAtlasSchema.js","sourceRoot":"","sources":["../src/libgdxAtlasSchema.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,4EAA4E;AAC5E,gGAAgG;AAChG,sGAAsG"}
@@ -0,0 +1,41 @@
1
+ import type { SpritesheetData } from '@flighthq/spritesheet';
2
+ import type { SpritesheetFormatKind } from '@flighthq/types';
3
+ export interface SpritesheetParseOptions {
4
+ /** Default frame duration in ms used by formats that do not embed per-frame timing. Defaults to 100. */
5
+ frameDuration?: number;
6
+ /** Atlas image height for formats that omit dimensions (e.g. Starling). */
7
+ imageHeight?: number;
8
+ /** Atlas image width for formats that omit dimensions (e.g. Starling). */
9
+ imageWidth?: number;
10
+ }
11
+ /** Detect the format kind of a spritesheet text document.
12
+ *
13
+ * Returns the `SpritesheetFormatKind` of the first registered format whose
14
+ * `detect` function returns `true`, or `null` when no format is recognized. */
15
+ export declare function detectSpritesheetFormat(text: string): SpritesheetFormatKind | null;
16
+ /** Retrieve the registered entry for a given `SpritesheetFormatKind`.
17
+ *
18
+ * Returns the `{ detect, parse }` entry for the given kind, or `null` when no
19
+ * format with that kind has been registered. Useful for introspecting which formats
20
+ * are in the registry or for building meta-dispatch logic on top of the registry. */
21
+ export declare function getSpritesheetFormat(kind: SpritesheetFormatKind): Readonly<{
22
+ detect: (text: string) => boolean;
23
+ parse: (text: string, options: SpritesheetParseOptions) => SpritesheetData;
24
+ }> | null;
25
+ /** Parse a spritesheet text document to a SpritesheetData, auto-detecting the format.
26
+ *
27
+ * Accepts an optional `formatKind` override — useful when the format is known in advance
28
+ * and sniffing overhead is undesirable, or when the input is ambiguous.
29
+ *
30
+ * Returns `null` when the format cannot be recognized (expected failure — not a throw). */
31
+ export declare function parseSpritesheet(text: string, formatKind?: SpritesheetFormatKind, options?: SpritesheetParseOptions): SpritesheetData | null;
32
+ /** Register a custom spritesheet format for use with `detectSpritesheetFormat` and `parseSpritesheet`.
33
+ *
34
+ * Registration is last-write-wins; a built-in entry can be replaced by registering
35
+ * the same `SpritesheetFormatKind`. Third-party formats should use a vendor-prefixed kind
36
+ * (e.g. `'acme.MyAtlas'`) to avoid colliding with built-ins. */
37
+ export declare function registerSpritesheetFormat(kind: SpritesheetFormatKind, entry: {
38
+ detect: (text: string) => boolean;
39
+ parse: (text: string, options: SpritesheetParseOptions) => SpritesheetData;
40
+ }): void;
41
+ //# sourceMappingURL=spritesheetDetect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spritesheetDetect.d.ts","sourceRoot":"","sources":["../src/spritesheetDetect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAe7D,MAAM,WAAW,uBAAuB;IACtC,wGAAwG;IACxG,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAkED;;;gFAGgF;AAChF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,GAAG,IAAI,CAKlF;AAED;;;;sFAIsF;AACtF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,qBAAqB,GAAG,QAAQ,CAAC;IAC1E,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAClC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,KAAK,eAAe,CAAC;CAC5E,CAAC,GAAG,IAAI,CAER;AAED;;;;;4FAK4F;AAC5F,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,qBAAqB,EAClC,OAAO,CAAC,EAAE,uBAAuB,GAChC,eAAe,GAAG,IAAI,CAOxB;AAED;;;;iEAIiE;AACjE,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,qBAAqB,EAC3B,KAAK,EAAE;IACL,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAClC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,KAAK,eAAe,CAAC;CAC5E,GACA,IAAI,CAEN"}
@@ -0,0 +1,101 @@
1
+ import { SpritesheetFormatKindAseprite as ASEPRITE, SpritesheetFormatKindCocosPlist as COCOS_PLIST, SpritesheetFormatKindLibgdxAtlas as LIBGDX_ATLAS, SpritesheetFormatKindStarling as STARLING, SpritesheetFormatKindTexturePacker as TEXTURE_PACKER, } from '@flighthq/types';
2
+ import { parseAsepriteSpritesheet } from './asepriteParse';
3
+ import { parseCocosPlistSpritesheet } from './cocosPlistParse';
4
+ import { parseLibgdxAtlasSpritesheet } from './libgdxAtlasParse';
5
+ import { parseStarlingSpritesheet } from './starlingParse';
6
+ import { parseTexturePackerSpritesheet } from './texturePackerParse';
7
+ let _registry = null;
8
+ function detectTexturePacker(text) {
9
+ if (text.trimStart()[0] !== '{')
10
+ return false;
11
+ return /"meta"\s*:/.test(text) && /"app"\s*:/.test(text);
12
+ }
13
+ function detectAseprite(text) {
14
+ if (text.trimStart()[0] !== '{')
15
+ return false;
16
+ return /"meta"\s*:/.test(text) && /aseprite\.org/i.test(text);
17
+ }
18
+ function detectCocosPlist(text) {
19
+ const trimmed = text.trimStart();
20
+ return (trimmed[0] === '<' || trimmed.startsWith('<?xml')) && /<plist\b/i.test(text);
21
+ }
22
+ function detectStarling(text) {
23
+ return /<TextureAtlas\b/i.test(text);
24
+ }
25
+ function detectLibgdxAtlas(text) {
26
+ const ch = text.trimStart()[0];
27
+ if (ch === '<' || ch === '{')
28
+ return false;
29
+ return /^\s*rotate\s*:/m.test(text) || /^\s*xy\s*:/m.test(text);
30
+ }
31
+ function getRegistry() {
32
+ if (_registry !== null)
33
+ return _registry;
34
+ _registry = new Map();
35
+ _registry.set(ASEPRITE, {
36
+ detect: detectAseprite,
37
+ parse: (text) => parseAsepriteSpritesheet(text),
38
+ });
39
+ _registry.set(COCOS_PLIST, {
40
+ detect: detectCocosPlist,
41
+ parse: (text) => parseCocosPlistSpritesheet(text),
42
+ });
43
+ _registry.set(TEXTURE_PACKER, {
44
+ detect: detectTexturePacker,
45
+ parse: (text) => parseTexturePackerSpritesheet(text),
46
+ });
47
+ _registry.set(STARLING, {
48
+ detect: detectStarling,
49
+ parse: (text, opts) => parseStarlingSpritesheet(text, { frameDuration: opts.frameDuration }),
50
+ });
51
+ _registry.set(LIBGDX_ATLAS, {
52
+ detect: detectLibgdxAtlas,
53
+ parse: (text, opts) => parseLibgdxAtlasSpritesheet(text, { frameDuration: opts.frameDuration }),
54
+ });
55
+ return _registry;
56
+ }
57
+ // ─── Public API ──────────────────────────────────────────────────────────────
58
+ /** Detect the format kind of a spritesheet text document.
59
+ *
60
+ * Returns the `SpritesheetFormatKind` of the first registered format whose
61
+ * `detect` function returns `true`, or `null` when no format is recognized. */
62
+ export function detectSpritesheetFormat(text) {
63
+ for (const [kind, entry] of getRegistry()) {
64
+ if (entry.detect(text))
65
+ return kind;
66
+ }
67
+ return null;
68
+ }
69
+ /** Retrieve the registered entry for a given `SpritesheetFormatKind`.
70
+ *
71
+ * Returns the `{ detect, parse }` entry for the given kind, or `null` when no
72
+ * format with that kind has been registered. Useful for introspecting which formats
73
+ * are in the registry or for building meta-dispatch logic on top of the registry. */
74
+ export function getSpritesheetFormat(kind) {
75
+ return getRegistry().get(kind) ?? null;
76
+ }
77
+ /** Parse a spritesheet text document to a SpritesheetData, auto-detecting the format.
78
+ *
79
+ * Accepts an optional `formatKind` override — useful when the format is known in advance
80
+ * and sniffing overhead is undesirable, or when the input is ambiguous.
81
+ *
82
+ * Returns `null` when the format cannot be recognized (expected failure — not a throw). */
83
+ export function parseSpritesheet(text, formatKind, options) {
84
+ const opts = options ?? {};
85
+ const kind = formatKind ?? detectSpritesheetFormat(text);
86
+ if (!kind)
87
+ return null;
88
+ const entry = getRegistry().get(kind);
89
+ if (!entry)
90
+ return null;
91
+ return entry.parse(text, opts);
92
+ }
93
+ /** Register a custom spritesheet format for use with `detectSpritesheetFormat` and `parseSpritesheet`.
94
+ *
95
+ * Registration is last-write-wins; a built-in entry can be replaced by registering
96
+ * the same `SpritesheetFormatKind`. Third-party formats should use a vendor-prefixed kind
97
+ * (e.g. `'acme.MyAtlas'`) to avoid colliding with built-ins. */
98
+ export function registerSpritesheetFormat(kind, entry) {
99
+ getRegistry().set(kind, entry);
100
+ }
101
+ //# sourceMappingURL=spritesheetDetect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spritesheetDetect.js","sourceRoot":"","sources":["../src/spritesheetDetect.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,6BAA6B,IAAI,QAAQ,EACzC,+BAA+B,IAAI,WAAW,EAC9C,gCAAgC,IAAI,YAAY,EAChD,6BAA6B,IAAI,QAAQ,EACzC,kCAAkC,IAAI,cAAc,GACrD,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAoBrE,IAAI,SAAS,GAA0B,IAAI,CAAC;AAE5C,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IAC9C,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,cAAc,CAAC,IAAY;IAClC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IAC9C,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY;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ACxB,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAED;;;;iEAIiE;AACjE,MAAM,UAAU,yBAAyB,CACvC,IAA2B,EAC3B,KAGC;IAED,WAAW,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { SpritesheetData } from '@flighthq/spritesheet';
2
+ import type { StarlingDocument } from './starlingSchema';
3
+ export interface StarlingParsed {
4
+ data: SpritesheetData;
5
+ document: StarlingDocument;
6
+ }
7
+ export interface StarlingParseOptions {
8
+ /** Default duration (ms) per frame when building inferred animations. Defaults to 100. */
9
+ frameDuration?: number;
10
+ }
11
+ /** Parse a Starling / Sparrow XML atlas string directly to a SpritesheetData.
12
+ *
13
+ * Single-pass: no intermediate document object is allocated.
14
+ * Animations are inferred from the standard `baseName_NNN` frame-naming convention.
15
+ * Use `parseStarlingSpritesheetDocument` instead when you need round-trip serialisation. */
16
+ export declare function parseStarlingSpritesheet(xml: string, options?: StarlingParseOptions): SpritesheetData;
17
+ /** Parse a Starling / Sparrow XML atlas string and preserve the full document
18
+ * for round-trip serialisation via `serializeStarlingSpritesheet`. */
19
+ export declare function parseStarlingSpritesheetDocument(xml: string, options?: StarlingParseOptions): StarlingParsed;
20
+ //# sourceMappingURL=starlingParse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"starlingParse.d.ts","sourceRoot":"","sources":["../src/starlingParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,eAAe,EAAwB,MAAM,uBAAuB,CAAC;AAU7G,OAAO,KAAK,EAAE,gBAAgB,EAAsB,MAAM,kBAAkB,CAAC;AAE7E,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED,MAAM,WAAW,oBAAoB;IACnC,0FAA0F;IAC1F,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAkID;;;;6FAI6F;AAC7F,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,eAAe,CAErG;AAED;uEACuE;AACvE,wBAAgB,gCAAgC,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,cAAc,CAG5G"}