@flighthq/skeleton2d-formats 0.3.1-next.575.c1f8e01 → 0.3.1-next.616.aa7ae7f
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.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/skeletonDetect.d.ts +1 -0
- package/dist/skeletonDetect.d.ts.map +1 -1
- package/dist/skeletonDetect.js +36 -12
- package/dist/skeletonDetect.js.map +1 -1
- package/package.json +7 -6
- package/src/skeletonDetect.test.ts +21 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { parseDragonBonesSkeleton } from './contract';
|
|
2
|
-
export { parseSkeleton2D, registerSkeleton2DFormat, unregisterSkeleton2DFormat } from './contract';
|
|
2
|
+
export { getSkeleton2DFormatKinds, parseSkeleton2D, registerSkeleton2DFormat, unregisterSkeleton2DFormat, } from './contract';
|
|
3
3
|
export { parseSpineSkeleton } from './contract';
|
|
4
4
|
export { parseSpineSkeletonBinary } from './contract';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { parseDragonBonesSkeleton } from './contract';
|
|
2
|
-
export { parseSkeleton2D, registerSkeleton2DFormat, unregisterSkeleton2DFormat } from './contract';
|
|
2
|
+
export { getSkeleton2DFormatKinds, parseSkeleton2D, registerSkeleton2DFormat, unregisterSkeleton2DFormat, } from './contract';
|
|
3
3
|
export { parseSpineSkeleton } from './contract';
|
|
4
4
|
export { parseSpineSkeletonBinary } from './contract';
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/skeletonDetect.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ImportDiagnostic, Skeleton2DImport } from '@flighthq/types/contract';
|
|
2
|
+
export declare function getSkeleton2DFormatKinds(): readonly string[];
|
|
2
3
|
export declare function parseSkeleton2D(text: string, diagnostics?: ImportDiagnostic[]): Skeleton2DImport | null;
|
|
3
4
|
export declare function registerSkeleton2DFormat(kind: string, detect: (text: string) => boolean, parse: (text: string, diagnostics?: ImportDiagnostic[]) => Skeleton2DImport | null): void;
|
|
4
5
|
export declare function unregisterSkeleton2DFormat(kind: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skeletonDetect.d.ts","sourceRoot":"","sources":["../src/skeletonDetect.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"skeletonDetect.d.ts","sourceRoot":"","sources":["../src/skeletonDetect.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAc,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AA8C/F,wBAAgB,wBAAwB,IAAI,SAAS,MAAM,EAAE,CAI5D;AAKD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,GAAG,IAAI,CAKvG;AAKD,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,EACjC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,GAAG,IAAI,GACjF,IAAI,CAEN;AAKD,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE7D"}
|
package/dist/skeletonDetect.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
+
import { createKeyedTable, getRegistryTableEntry, getRegistryTableKeys, withRegistryTableEntry, withoutRegistryTableEntry, } from '@flighthq/registry/contract';
|
|
1
2
|
import { parseDragonBonesSkeleton } from './dragonBonesParse';
|
|
2
3
|
import { parseSpineSkeleton } from './spineParse';
|
|
3
|
-
let _registry = null;
|
|
4
4
|
function getRegistry() {
|
|
5
5
|
if (_registry !== null)
|
|
6
6
|
return _registry;
|
|
7
|
-
_registry =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
detect: detectDragonBones,
|
|
11
|
-
parse: (text, diagnostics) => parseDragonBonesSkeleton(text, diagnostics),
|
|
12
|
-
});
|
|
7
|
+
_registry = createKeyedTable('Skeleton2DFormat', 'Unclaimed');
|
|
8
|
+
bindSkeleton2DFormat('Spine', detectSpine, (text, diagnostics) => parseSpineSkeleton(text, diagnostics));
|
|
9
|
+
bindSkeleton2DFormat('DragonBones', detectDragonBones, (text, diagnostics) => parseDragonBonesSkeleton(text, diagnostics));
|
|
13
10
|
return _registry;
|
|
14
11
|
}
|
|
15
12
|
// A DragonBones skeleton JSON is an object carrying an `armature` array (its skeleton container). Distinct
|
|
@@ -28,13 +25,20 @@ function detectSpine(text) {
|
|
|
28
25
|
return false;
|
|
29
26
|
return /"bones"\s*:/.test(text) || /"skeleton"\s*:/.test(text) || /"slots"\s*:/.test(text);
|
|
30
27
|
}
|
|
28
|
+
// A sorted snapshot of every bound skeleton-format kind. Detection retains registration precedence
|
|
29
|
+
// separately; this enumeration is stable for callers and agrees with resolution after removal.
|
|
30
|
+
export function getSkeleton2DFormatKinds() {
|
|
31
|
+
const kinds = [];
|
|
32
|
+
getRegistryTableKeys(kinds, getRegistry());
|
|
33
|
+
return kinds;
|
|
34
|
+
}
|
|
31
35
|
// Auto-detects the skeleton format of `text` and parses it, threading the optional diagnostics sink.
|
|
32
36
|
// Returns the sentinel `null` when no registered format recognizes the input (the expected
|
|
33
37
|
// "unrecognized format" failure) or the recognized parser itself rejects it.
|
|
34
38
|
export function parseSkeleton2D(text, diagnostics) {
|
|
35
|
-
for (const
|
|
36
|
-
if (entry.detect(text))
|
|
37
|
-
return entry.parse(text, diagnostics);
|
|
39
|
+
for (const registered of getSkeleton2DFormatsInDetectionOrder()) {
|
|
40
|
+
if (registered.entry.detect(text))
|
|
41
|
+
return registered.entry.parse(text, diagnostics);
|
|
38
42
|
}
|
|
39
43
|
return null;
|
|
40
44
|
}
|
|
@@ -42,12 +46,32 @@ export function parseSkeleton2D(text, diagnostics) {
|
|
|
42
46
|
// e.g. `'acme.Rig'`; bare names are reserved for built-ins). `detect` decides whether a text is this
|
|
43
47
|
// format; `parse` maps it to a Skeleton2DImport (or `null` on rejection).
|
|
44
48
|
export function registerSkeleton2DFormat(kind, detect, parse) {
|
|
45
|
-
|
|
49
|
+
bindSkeleton2DFormat(kind, detect, parse);
|
|
46
50
|
}
|
|
47
51
|
// Removes a registered format, so the registry is not write-only. Every other registry in the SDK pairs
|
|
48
52
|
// its `register*` with this — a caller that can add a vendor format must be able to take it back out, and
|
|
49
53
|
// a test that registers one has no way to leave the module global as it found it otherwise.
|
|
50
54
|
export function unregisterSkeleton2DFormat(kind) {
|
|
51
|
-
getRegistry()
|
|
55
|
+
_registry = withoutRegistryTableEntry(getRegistry(), kind);
|
|
56
|
+
}
|
|
57
|
+
function bindSkeleton2DFormat(kind, detect, parse) {
|
|
58
|
+
const registry = getRegistry();
|
|
59
|
+
const current = getRegistryTableEntry(registry, kind);
|
|
60
|
+
_registry = withRegistryTableEntry(registry, kind, {
|
|
61
|
+
entry: { detect, parse },
|
|
62
|
+
order: current?.order ?? _nextFormatOrder++,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function getSkeleton2DFormatsInDetectionOrder() {
|
|
66
|
+
const formats = [];
|
|
67
|
+
for (const kind of getSkeleton2DFormatKinds()) {
|
|
68
|
+
const registered = getRegistryTableEntry(getRegistry(), kind);
|
|
69
|
+
if (registered !== null)
|
|
70
|
+
formats.push(registered);
|
|
71
|
+
}
|
|
72
|
+
formats.sort((a, b) => a.order - b.order);
|
|
73
|
+
return formats;
|
|
52
74
|
}
|
|
75
|
+
let _registry = null;
|
|
76
|
+
let _nextFormatOrder = 0;
|
|
53
77
|
//# sourceMappingURL=skeletonDetect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skeletonDetect.js","sourceRoot":"","sources":["../src/skeletonDetect.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"skeletonDetect.js","sourceRoot":"","sources":["../src/skeletonDetect.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,6BAA6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AE,CAAC;QAC9C,MAAM,UAAU,GAAG,qBAAqB,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAC;QAC9D,IAAI,UAAU,KAAK,IAAI;YAAE,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,IAAI,SAAS,GAAgD,IAAI,CAAC;AAClE,IAAI,gBAAgB,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/skeleton2d-formats",
|
|
3
|
-
"version": "0.3.1-next.
|
|
3
|
+
"version": "0.3.1-next.616.aa7ae7f",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,11 +38,12 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/animation": "0.3.1-next.
|
|
42
|
-
"@flighthq/easing": "0.3.1-next.
|
|
43
|
-
"@flighthq/importdiagnostics": "0.3.1-next.
|
|
44
|
-
"@flighthq/
|
|
45
|
-
"@flighthq/
|
|
41
|
+
"@flighthq/animation": "0.3.1-next.616.aa7ae7f",
|
|
42
|
+
"@flighthq/easing": "0.3.1-next.616.aa7ae7f",
|
|
43
|
+
"@flighthq/importdiagnostics": "0.3.1-next.616.aa7ae7f",
|
|
44
|
+
"@flighthq/registry": "0.3.1-next.616.aa7ae7f",
|
|
45
|
+
"@flighthq/skeleton2d": "0.3.1-next.616.aa7ae7f",
|
|
46
|
+
"@flighthq/types": "0.3.1-next.616.aa7ae7f"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"typescript": "^5.3.0"
|
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import type { ImportDiagnostic, Skeleton2DImport } from '@flighthq/types/contract';
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getSkeleton2DFormatKinds,
|
|
6
|
+
parseSkeleton2D,
|
|
7
|
+
registerSkeleton2DFormat,
|
|
8
|
+
unregisterSkeleton2DFormat,
|
|
9
|
+
} from './skeletonDetect';
|
|
10
|
+
|
|
11
|
+
describe('getSkeleton2DFormatKinds', () => {
|
|
12
|
+
it('enumerates sorted bound kinds and stops naming one after it is unregistered', () => {
|
|
13
|
+
registerSkeleton2DFormat(
|
|
14
|
+
'acme.Rig',
|
|
15
|
+
(text) => text.startsWith('ACME'),
|
|
16
|
+
() => null,
|
|
17
|
+
);
|
|
18
|
+
expect(getSkeleton2DFormatKinds()).toEqual(['DragonBones', 'Spine', 'acme.Rig']);
|
|
19
|
+
|
|
20
|
+
unregisterSkeleton2DFormat('acme.Rig');
|
|
21
|
+
|
|
22
|
+
expect(getSkeleton2DFormatKinds()).toEqual(['DragonBones', 'Spine']);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
5
25
|
|
|
6
26
|
describe('parseSkeleton2D', () => {
|
|
7
27
|
it('auto-detects a Spine JSON document and parses it', () => {
|