@codexo/exojs-tiled 0.12.0 → 0.14.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.
- package/README.md +134 -71
- package/dist/esm/TiledLayer.d.ts +72 -0
- package/dist/esm/TiledLayer.js +117 -0
- package/dist/esm/TiledLayer.js.map +1 -0
- package/dist/esm/TiledMap.d.ts +57 -72
- package/dist/esm/TiledMap.js +362 -23
- package/dist/esm/TiledMap.js.map +1 -1
- package/dist/esm/TiledObject.d.ts +32 -0
- package/dist/esm/TiledObject.js +54 -0
- package/dist/esm/TiledObject.js.map +1 -0
- package/dist/esm/TiledTileset.d.ts +59 -0
- package/dist/esm/TiledTileset.js +70 -0
- package/dist/esm/TiledTileset.js.map +1 -0
- package/dist/esm/data.d.ts +217 -0
- package/dist/esm/gid.d.ts +13 -0
- package/dist/esm/gid.js +28 -0
- package/dist/esm/gid.js.map +1 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/loadTiledMap.d.ts +9 -0
- package/dist/esm/loadTiledMap.js +68 -0
- package/dist/esm/loadTiledMap.js.map +1 -0
- package/dist/esm/public.d.ts +42 -3
- package/dist/esm/register.js +7 -0
- package/dist/esm/register.js.map +1 -1
- package/dist/esm/tiledBuildInfo.js +2 -2
- package/dist/esm/tiledExtension.d.ts +10 -0
- package/dist/esm/tiledExtension.js +19 -48
- package/dist/esm/tiledExtension.js.map +1 -1
- package/dist/esm/tiledMapBinding.d.ts +19 -0
- package/dist/esm/tiledMapBinding.js +31 -0
- package/dist/esm/tiledMapBinding.js.map +1 -0
- package/dist/esm/tiledOptions.d.ts +31 -0
- package/dist/esm/tiledOptions.js +16 -0
- package/dist/esm/tiledOptions.js.map +1 -0
- package/dist/esm/tiledRuntimeMapBinding.d.ts +29 -0
- package/dist/esm/tiledRuntimeMapBinding.js +42 -0
- package/dist/esm/tiledRuntimeMapBinding.js.map +1 -0
- package/dist/esm/url.d.ts +18 -0
- package/dist/esm/url.js +41 -0
- package/dist/esm/url.js.map +1 -0
- package/dist/esm/validate.d.ts +49 -0
- package/dist/esm/validate.js +511 -0
- package/dist/esm/validate.js.map +1 -0
- package/package.json +11 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies defaults and returns a normalized options object.
|
|
3
|
+
*
|
|
4
|
+
* Tiled parsing is unconditionally strict: {@link validateTiledMapData} throws
|
|
5
|
+
* a `TiledFormatError` on any malformed *known* field and silently preserves
|
|
6
|
+
* unknown fields. There is intentionally no `strict` toggle — a permissive
|
|
7
|
+
* parse mode is a potential v0.14 follow-up, not part of v0.13.
|
|
8
|
+
*/
|
|
9
|
+
function resolveTiledOptions(options) {
|
|
10
|
+
return {
|
|
11
|
+
format: options?.format ?? 'tiled',
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { resolveTiledOptions };
|
|
16
|
+
//# sourceMappingURL=tiledOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiledOptions.js","sources":["../../../src/tiledOptions.ts"],"sourcesContent":[null],"names":[],"mappings":"AAqBA;;;;;;;AAOG;AACG,SAAU,mBAAmB,CAAC,OAAqC,EAAA;IACvE,OAAO;AACL,QAAA,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,OAAO;KACnC;AACH;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TileMap } from '@codexo/exojs-tilemap';
|
|
2
|
+
import { type TiledLoadOptions } from './tiledOptions';
|
|
3
|
+
/**
|
|
4
|
+
* Declarative asset binding for the runtime {@link TileMap} produced from a
|
|
5
|
+
* `.tmj` Tiled map file.
|
|
6
|
+
*
|
|
7
|
+
* This is the common-case binding: `loader.load(TileMap, 'world.tmj')` fetches
|
|
8
|
+
* and validates the TMJ, resolves external `.tsj` tilesets, loads tileset
|
|
9
|
+
* textures via the sub-load `loader.load(TiledMap, source)`, and synchronously
|
|
10
|
+
* converts the parsed {@link TiledMap} source model into a format-independent
|
|
11
|
+
* runtime {@link TileMap} via {@link TiledMap.toTileMap}.
|
|
12
|
+
*
|
|
13
|
+
* The sub-load flow guarantees that calling both `load(TileMap)` and
|
|
14
|
+
* `load(TiledMap)` for the same URL shares the Loader's cached `TiledMap`
|
|
15
|
+
* (no duplicate JSON fetches).
|
|
16
|
+
*
|
|
17
|
+
* Claiming the `tmj` extension enables the auto-routing shorthand
|
|
18
|
+
* `loader.load('world.tmj')` — the {@link ExtensionTypeMap} augmentation in
|
|
19
|
+
* this package maps `'tmj' → TileMap`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const tiledRuntimeMapBinding: {
|
|
22
|
+
type: typeof TileMap;
|
|
23
|
+
typeNames: string[];
|
|
24
|
+
extensions: string[];
|
|
25
|
+
create(): {
|
|
26
|
+
getIdentityKey(req: import("@codexo/exojs").AssetLoadRequest<TiledLoadOptions>): string;
|
|
27
|
+
load(req: import("@codexo/exojs").AssetLoadRequest<TiledLoadOptions>, ctx: import("@codexo/exojs").AssetLoaderContext): Promise<TileMap>;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TileMap } from '@codexo/exojs-tilemap';
|
|
2
|
+
import { TiledMap } from './TiledMap.js';
|
|
3
|
+
import { resolveTiledOptions } from './tiledOptions.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Declarative asset binding for the runtime {@link TileMap} produced from a
|
|
7
|
+
* `.tmj` Tiled map file.
|
|
8
|
+
*
|
|
9
|
+
* This is the common-case binding: `loader.load(TileMap, 'world.tmj')` fetches
|
|
10
|
+
* and validates the TMJ, resolves external `.tsj` tilesets, loads tileset
|
|
11
|
+
* textures via the sub-load `loader.load(TiledMap, source)`, and synchronously
|
|
12
|
+
* converts the parsed {@link TiledMap} source model into a format-independent
|
|
13
|
+
* runtime {@link TileMap} via {@link TiledMap.toTileMap}.
|
|
14
|
+
*
|
|
15
|
+
* The sub-load flow guarantees that calling both `load(TileMap)` and
|
|
16
|
+
* `load(TiledMap)` for the same URL shares the Loader's cached `TiledMap`
|
|
17
|
+
* (no duplicate JSON fetches).
|
|
18
|
+
*
|
|
19
|
+
* Claiming the `tmj` extension enables the auto-routing shorthand
|
|
20
|
+
* `loader.load('world.tmj')` — the {@link ExtensionTypeMap} augmentation in
|
|
21
|
+
* this package maps `'tmj' → TileMap`.
|
|
22
|
+
*/
|
|
23
|
+
const tiledRuntimeMapBinding = {
|
|
24
|
+
type: TileMap,
|
|
25
|
+
typeNames: ['tileMap'],
|
|
26
|
+
extensions: ['tmj'],
|
|
27
|
+
create() {
|
|
28
|
+
return {
|
|
29
|
+
getIdentityKey(req) {
|
|
30
|
+
const o = resolveTiledOptions(req.options);
|
|
31
|
+
return `${req.source}|${o.format}`;
|
|
32
|
+
},
|
|
33
|
+
async load(req, ctx) {
|
|
34
|
+
const tiledMap = await ctx.loader.load(TiledMap, req.source, req.options);
|
|
35
|
+
return tiledMap.toTileMap();
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { tiledRuntimeMapBinding };
|
|
42
|
+
//# sourceMappingURL=tiledRuntimeMapBinding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiledRuntimeMapBinding.js","sources":["../../../src/tiledRuntimeMapBinding.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAMA;;;;;;;;;;;;;;;;;AAiBG;AACI,MAAM,sBAAsB,GAAG;AACpC,IAAA,IAAI,EAAE,OAAO;IACb,SAAS,EAAE,CAAC,SAAS,CAAC;IACtB,UAAU,EAAE,CAAC,KAAK,CAAC;IACnB,MAAM,GAAA;QACJ,OAAO;AACL,YAAA,cAAc,CAAC,GAAG,EAAA;gBAChB,MAAM,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC1C,OAAO,CAAA,EAAG,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAA,CAAE;YACpC,CAAC;AACD,YAAA,MAAM,IAAI,CAAC,GAAG,EAAE,GAAG,EAAA;AACjB,gBAAA,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC;AACzE,gBAAA,OAAO,QAAQ,CAAC,SAAS,EAAE;YAC7B,CAAC;SACgD;IACrD,CAAC;;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves `ref` (a path read from a Tiled JSON file, e.g. a tileset
|
|
3
|
+
* `source` or an `image`) relative to `base` (the resolved location of the
|
|
4
|
+
* file that referenced it).
|
|
5
|
+
*
|
|
6
|
+
* - If `ref` is already absolute (has a scheme, is protocol- or
|
|
7
|
+
* root-relative, or is a `data:`/`blob:` URL), it is returned unchanged.
|
|
8
|
+
* - If `base` is an absolute URL, standard `new URL(ref, base)` resolution
|
|
9
|
+
* is used.
|
|
10
|
+
* - Otherwise both `ref` and `base` are relative ExoJS asset paths; `../`
|
|
11
|
+
* and `./` segments are collapsed via a synthetic origin and the result is
|
|
12
|
+
* returned relative again.
|
|
13
|
+
*
|
|
14
|
+
* Query strings and fragments on `ref` are preserved.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveTiledUrl(ref: string, base: string): string;
|
package/dist/esm/url.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Relative-path resolution for Tiled source references (TMJ → TSJ, TMJ/TSJ →
|
|
2
|
+
// image). Tiled stores every cross-file reference as a path relative to the
|
|
3
|
+
// file that contains it; ExoJS asset sources are themselves often relative
|
|
4
|
+
// (resolved against an asset root configured outside the Loader), so plain
|
|
5
|
+
// `new URL(ref, base)` cannot be used directly when `base` has no scheme.
|
|
6
|
+
/** Matches references that are already absolute and must not be re-resolved: scheme:, protocol-relative `//`, root-relative `/`, and data/blob URLs. */
|
|
7
|
+
const ABSOLUTE_REF = /^(?:[a-z][a-z\d+.-]*:|\/\/|\/)/i;
|
|
8
|
+
/** Matches a base that is itself an absolute URL with a scheme. */
|
|
9
|
+
const ABSOLUTE_BASE = /^[a-z][a-z\d+.-]*:/i;
|
|
10
|
+
/** Synthetic origin used to borrow `URL`'s `../`/`./` collapsing for relative bases. */
|
|
11
|
+
const SYNTHETIC_ORIGIN = 'https://exojs.invalid/';
|
|
12
|
+
/**
|
|
13
|
+
* Resolves `ref` (a path read from a Tiled JSON file, e.g. a tileset
|
|
14
|
+
* `source` or an `image`) relative to `base` (the resolved location of the
|
|
15
|
+
* file that referenced it).
|
|
16
|
+
*
|
|
17
|
+
* - If `ref` is already absolute (has a scheme, is protocol- or
|
|
18
|
+
* root-relative, or is a `data:`/`blob:` URL), it is returned unchanged.
|
|
19
|
+
* - If `base` is an absolute URL, standard `new URL(ref, base)` resolution
|
|
20
|
+
* is used.
|
|
21
|
+
* - Otherwise both `ref` and `base` are relative ExoJS asset paths; `../`
|
|
22
|
+
* and `./` segments are collapsed via a synthetic origin and the result is
|
|
23
|
+
* returned relative again.
|
|
24
|
+
*
|
|
25
|
+
* Query strings and fragments on `ref` are preserved.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
function resolveTiledUrl(ref, base) {
|
|
30
|
+
if (ABSOLUTE_REF.test(ref)) {
|
|
31
|
+
return ref;
|
|
32
|
+
}
|
|
33
|
+
if (ABSOLUTE_BASE.test(base)) {
|
|
34
|
+
return new URL(ref, base).href;
|
|
35
|
+
}
|
|
36
|
+
const resolved = new URL(ref, SYNTHETIC_ORIGIN + base.replace(/^\/+/, ''));
|
|
37
|
+
return resolved.href.slice(SYNTHETIC_ORIGIN.length);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { resolveTiledUrl };
|
|
41
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sources":["../../../src/url.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA;AACA,MAAM,YAAY,GAAG,iCAAiC;AAEtD;AACA,MAAM,aAAa,GAAG,qBAAqB;AAE3C;AACA,MAAM,gBAAgB,GAAG,wBAAwB;AAEjD;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,eAAe,CAAC,GAAW,EAAE,IAAY,EAAA;AACvD,IAAA,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;AAC1B,QAAA,OAAO,GAAG;IACZ;AAEA,IAAA,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC5B,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,IAAI;IAChC;AAEA,IAAA,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAE1E,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC;AACrD;;;;"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { TiledAnimationFrameData, TiledLayerData, TiledMapData, TiledObjectData, TiledPropertyData, TiledTileData, TiledTilesetData, TiledTilesetRefData } from './data';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a Tiled JSON document does not match the expected shape.
|
|
4
|
+
* `source` is the URL of the file being parsed; `path` is a JSON-path-like
|
|
5
|
+
* pointer (e.g. `layers[2].objects[0].properties[1].value`) to the offending
|
|
6
|
+
* value, or `''` for the document root.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TiledFormatError extends Error {
|
|
9
|
+
readonly source: string;
|
|
10
|
+
readonly path: string;
|
|
11
|
+
constructor(source: string, path: string, message: string);
|
|
12
|
+
}
|
|
13
|
+
/** @internal */
|
|
14
|
+
export declare function validateTiledPropertyData(raw: unknown, source: string, path: string): TiledPropertyData;
|
|
15
|
+
/** @internal */
|
|
16
|
+
export declare function validateTiledAnimationFrameData(raw: unknown, source: string, path: string): TiledAnimationFrameData;
|
|
17
|
+
/** @internal */
|
|
18
|
+
export declare function validateTiledObjectData(raw: unknown, source: string, path: string): TiledObjectData;
|
|
19
|
+
/** @internal */
|
|
20
|
+
export declare function validateTiledLayerData(raw: unknown, source: string, path: string): TiledLayerData;
|
|
21
|
+
/**
|
|
22
|
+
* Walks a layer tree and ensures every tile layer's `data`/`chunks` choice
|
|
23
|
+
* matches the map's `infinite` flag. Tiled itself is consistent across an
|
|
24
|
+
* entire map; a mismatch indicates a hand-edited or corrupt file.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export declare function checkTiledLayerInfiniteConsistency(layers: readonly TiledLayerData[], infinite: boolean, source: string, path: string): void;
|
|
28
|
+
/** @internal */
|
|
29
|
+
export declare function validateTiledTileData(raw: unknown, source: string, path: string): TiledTileData;
|
|
30
|
+
/** @internal */
|
|
31
|
+
export declare function validateTiledTilesetData(obj: Record<string, unknown>, source: string, path: string): TiledTilesetData;
|
|
32
|
+
/**
|
|
33
|
+
* Validates one entry of a map's `tilesets` array: either `{ firstgid,
|
|
34
|
+
* source }` (external `.tsj`) or `{ firstgid, ...embedded tileset fields }`.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateTiledTilesetRefData(raw: unknown, source: string, path: string): TiledTilesetRefData;
|
|
38
|
+
/**
|
|
39
|
+
* Validates the root of a `.tmj` file. Throws {@link TiledFormatError} on
|
|
40
|
+
* any structural problem, including unsupported tile-layer encodings and
|
|
41
|
+
* `infinite`/`data`/`chunks` inconsistencies.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export declare function validateTiledMapData(raw: unknown, source: string): TiledMapData;
|
|
45
|
+
/**
|
|
46
|
+
* Validates a standalone `.tsj` tileset file's root object.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export declare function validateTiledTilesetFileData(raw: unknown, source: string): TiledTilesetData;
|