@codexo/exojs-tiled 0.15.3 → 0.16.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 (84) hide show
  1. package/README.md +59 -66
  2. package/dist/esm/TiledLayer.d.ts +2 -1
  3. package/dist/esm/TiledLayer.d.ts.map +1 -0
  4. package/dist/esm/TiledLayer.js +106 -108
  5. package/dist/esm/TiledLayer.js.map +1 -1
  6. package/dist/esm/TiledMap.d.ts +35 -7
  7. package/dist/esm/TiledMap.d.ts.map +1 -0
  8. package/dist/esm/TiledMap.js +714 -589
  9. package/dist/esm/TiledMap.js.map +1 -1
  10. package/dist/esm/TiledObject.d.ts +7 -0
  11. package/dist/esm/TiledObject.d.ts.map +1 -0
  12. package/dist/esm/TiledObject.js +59 -51
  13. package/dist/esm/TiledObject.js.map +1 -1
  14. package/dist/esm/TiledTileset.d.ts +11 -4
  15. package/dist/esm/TiledTileset.d.ts.map +1 -0
  16. package/dist/esm/TiledTileset.js +81 -70
  17. package/dist/esm/TiledTileset.js.map +1 -1
  18. package/dist/esm/data.d.ts +25 -7
  19. package/dist/esm/data.d.ts.map +1 -0
  20. package/dist/esm/decodeLayerData.d.ts +2 -1
  21. package/dist/esm/decodeLayerData.d.ts.map +1 -0
  22. package/dist/esm/decodeLayerData.js +53 -92
  23. package/dist/esm/decodeLayerData.js.map +1 -1
  24. package/dist/esm/gid.d.ts +2 -1
  25. package/dist/esm/gid.d.ts.map +1 -0
  26. package/dist/esm/gid.js +15 -24
  27. package/dist/esm/gid.js.map +1 -1
  28. package/dist/esm/index.d.ts +1 -0
  29. package/dist/esm/index.d.ts.map +1 -0
  30. package/dist/esm/index.js +14 -12
  31. package/dist/esm/loadTiledMap.d.ts +11 -5
  32. package/dist/esm/loadTiledMap.d.ts.map +1 -0
  33. package/dist/esm/loadTiledMap.js +82 -91
  34. package/dist/esm/loadTiledMap.js.map +1 -1
  35. package/dist/esm/objectAlignment.d.ts +28 -0
  36. package/dist/esm/objectAlignment.d.ts.map +1 -0
  37. package/dist/esm/objectAlignment.js +79 -0
  38. package/dist/esm/objectAlignment.js.map +1 -0
  39. package/dist/esm/public.d.ts +17 -15
  40. package/dist/esm/public.d.ts.map +1 -0
  41. package/dist/esm/public.js +14 -0
  42. package/dist/esm/tileMapType.d.ts +31 -0
  43. package/dist/esm/tileMapType.d.ts.map +1 -0
  44. package/dist/esm/tileMapType.js +42 -0
  45. package/dist/esm/tileMapType.js.map +1 -0
  46. package/dist/esm/tiledBuildInfo.d.ts +1 -0
  47. package/dist/esm/tiledBuildInfo.d.ts.map +1 -0
  48. package/dist/esm/tiledBuildInfo.js +6 -4
  49. package/dist/esm/tiledBuildInfo.js.map +1 -1
  50. package/dist/esm/tiledExtension.d.ts +7 -6
  51. package/dist/esm/tiledExtension.d.ts.map +1 -0
  52. package/dist/esm/tiledExtension.js +23 -25
  53. package/dist/esm/tiledExtension.js.map +1 -1
  54. package/dist/esm/tiledOptions.d.ts +5 -4
  55. package/dist/esm/tiledOptions.d.ts.map +1 -0
  56. package/dist/esm/tiledOptions.js +11 -13
  57. package/dist/esm/tiledOptions.js.map +1 -1
  58. package/dist/esm/tiledSourceType.d.ts +24 -0
  59. package/dist/esm/tiledSourceType.d.ts.map +1 -0
  60. package/dist/esm/tiledSourceType.js +44 -0
  61. package/dist/esm/tiledSourceType.js.map +1 -0
  62. package/dist/esm/url.d.ts +2 -1
  63. package/dist/esm/url.d.ts.map +1 -0
  64. package/dist/esm/url.js +26 -37
  65. package/dist/esm/url.js.map +1 -1
  66. package/dist/esm/validate.d.ts +11 -10
  67. package/dist/esm/validate.d.ts.map +1 -0
  68. package/dist/esm/validate.js +485 -534
  69. package/dist/esm/validate.js.map +1 -1
  70. package/dist/esm/wangSets.d.ts +5 -4
  71. package/dist/esm/wangSets.d.ts.map +1 -0
  72. package/dist/esm/wangSets.js +90 -115
  73. package/dist/esm/wangSets.js.map +1 -1
  74. package/package.json +10 -18
  75. package/dist/esm/index.js.map +0 -1
  76. package/dist/esm/register.d.ts +0 -1
  77. package/dist/esm/register.js +0 -22
  78. package/dist/esm/register.js.map +0 -1
  79. package/dist/esm/tiledMapBinding.d.ts +0 -19
  80. package/dist/esm/tiledMapBinding.js +0 -31
  81. package/dist/esm/tiledMapBinding.js.map +0 -1
  82. package/dist/esm/tiledRuntimeMapBinding.d.ts +0 -29
  83. package/dist/esm/tiledRuntimeMapBinding.js +0 -42
  84. package/dist/esm/tiledRuntimeMapBinding.js.map +0 -1
@@ -1,547 +1,498 @@
1
- // Runtime validation for Tiled JSON (TMJ/TSJ) data. Every exported function
2
- // takes `unknown` (the result of `JSON.parse`) and either returns a typed,
3
- // validated `Tiled*Data` value or throws a {@link TiledFormatError}.
4
- //
5
- // There is no fall-through: an unrecognised shape, an unsupported encoding,
6
- // or an out-of-range value is always a thrown error carrying the source URL
7
- // and a JSON-path-like field path, never a silently-substituted default.
1
+ import { TILED_OBJECT_ALIGNMENTS } from "./objectAlignment.js";
2
+
3
+ //#region src/validate.ts
8
4
  /**
9
- * Thrown when a Tiled JSON document does not match the expected shape.
10
- * `source` is the URL of the file being parsed; `path` is a JSON-path-like
11
- * pointer (e.g. `layers[2].objects[0].properties[1].value`) to the offending
12
- * value, or `''` for the document root.
13
- */
14
- class TiledFormatError extends Error {
15
- source;
16
- path;
17
- constructor(source, path, message) {
18
- super(`Invalid Tiled data in "${source}" at ${path === '' ? '<root>' : path}: ${message}`);
19
- this.name = 'TiledFormatError';
20
- this.source = source;
21
- this.path = path;
22
- }
23
- }
24
- // ── Primitive helpers ───────────────────────────────────────────────────────
25
- function describeValue(value) {
26
- if (value === null)
27
- return 'null';
28
- if (Array.isArray(value))
29
- return 'an array';
30
- return typeof value;
31
- }
32
- function joinPath(path, key) {
33
- if (typeof key === 'number')
34
- return `${path}[${key}]`;
35
- return path === '' ? key : `${path}.${key}`;
36
- }
37
- function expectObject(value, source, path) {
38
- if (typeof value !== 'object' || value === null || Array.isArray(value)) {
39
- throw new TiledFormatError(source, path, `expected an object, got ${describeValue(value)}`);
40
- }
41
- return value;
42
- }
43
- function expectArray(value, source, path) {
44
- if (!Array.isArray(value)) {
45
- throw new TiledFormatError(source, path, `expected an array, got ${describeValue(value)}`);
46
- }
47
- return value;
48
- }
49
- function expectString(value, source, path) {
50
- if (typeof value !== 'string') {
51
- throw new TiledFormatError(source, path, `expected a string, got ${describeValue(value)}`);
52
- }
53
- return value;
54
- }
55
- function expectNumber(value, source, path) {
56
- if (typeof value !== 'number' || !Number.isFinite(value)) {
57
- throw new TiledFormatError(source, path, `expected a finite number, got ${describeValue(value)}`);
58
- }
59
- return value;
60
- }
61
- function expectInteger(value, source, path) {
62
- const n = expectNumber(value, source, path);
63
- if (!Number.isInteger(n)) {
64
- throw new TiledFormatError(source, path, `expected an integer, got ${n}`);
65
- }
66
- return n;
67
- }
68
- function expectNonNegativeInteger(value, source, path) {
69
- const n = expectInteger(value, source, path);
70
- if (n < 0) {
71
- throw new TiledFormatError(source, path, `expected a non-negative integer, got ${n}`);
72
- }
73
- return n;
74
- }
75
- function expectPositiveInteger(value, source, path) {
76
- const n = expectInteger(value, source, path);
77
- if (n <= 0) {
78
- throw new TiledFormatError(source, path, `expected a positive integer, got ${n}`);
79
- }
80
- return n;
81
- }
82
- function expectBoolean(value, source, path) {
83
- if (typeof value !== 'boolean') {
84
- throw new TiledFormatError(source, path, `expected a boolean, got ${describeValue(value)}`);
85
- }
86
- return value;
87
- }
88
- function optionalString(obj, key, source, path) {
89
- const value = obj[key];
90
- return value === undefined ? undefined : expectString(value, source, joinPath(path, key));
91
- }
92
- function optionalNumber(obj, key, source, path) {
93
- const value = obj[key];
94
- return value === undefined ? undefined : expectNumber(value, source, joinPath(path, key));
95
- }
96
- function optionalInteger(obj, key, source, path) {
97
- const value = obj[key];
98
- return value === undefined ? undefined : expectInteger(value, source, joinPath(path, key));
99
- }
100
- function optionalNonNegativeInteger(obj, key, source, path) {
101
- const value = obj[key];
102
- return value === undefined ? undefined : expectNonNegativeInteger(value, source, joinPath(path, key));
103
- }
104
- function optionalBoolean(obj, key, source, path) {
105
- const value = obj[key];
106
- return value === undefined ? undefined : expectBoolean(value, source, joinPath(path, key));
107
- }
108
- function mapArray(value, source, path, fn) {
109
- const arr = expectArray(value, source, path);
110
- return arr.map((item, i) => fn(item, joinPath(path, i)));
111
- }
112
- function optionalMapArray(value, source, path, fn) {
113
- return value === undefined ? undefined : mapArray(value, source, path, fn);
114
- }
115
- // ── Custom properties ───────────────────────────────────────────────────────
116
- const PROPERTY_TYPES = ['string', 'int', 'float', 'bool', 'color', 'file', 'object', 'class'];
117
- function validateTiledClassPropertyValue(raw, source, path) {
118
- const obj = expectObject(raw, source, path);
119
- const result = {};
120
- for (const [key, value] of Object.entries(obj)) {
121
- const memberPath = joinPath(path, key);
122
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
123
- result[key] = value;
124
- }
125
- else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
126
- result[key] = validateTiledClassPropertyValue(value, source, memberPath);
127
- }
128
- else {
129
- throw new TiledFormatError(source, memberPath, `expected a string, number, boolean, or nested object, got ${describeValue(value)}`);
130
- }
131
- }
132
- return result;
133
- }
5
+ * Thrown when a Tiled JSON document does not match the expected shape.
6
+ * `source` is the URL of the file being parsed; `path` is a JSON-path-like
7
+ * pointer (e.g. `layers[2].objects[0].properties[1].value`) to the offending
8
+ * value, or `''` for the document root.
9
+ */
10
+ var TiledFormatError = class extends Error {
11
+ source;
12
+ path;
13
+ constructor(source, path, message) {
14
+ super(`Invalid Tiled data in "${source}" at ${path === "" ? "<root>" : path}: ${message}`);
15
+ this.name = "TiledFormatError";
16
+ this.source = source;
17
+ this.path = path;
18
+ }
19
+ };
20
+ const describeValue = (value) => {
21
+ if (value === null) return "null";
22
+ if (Array.isArray(value)) return "an array";
23
+ return typeof value;
24
+ };
25
+ const joinPath = (path, key) => {
26
+ if (typeof key === "number") return `${path}[${key}]`;
27
+ return path === "" ? key : `${path}.${key}`;
28
+ };
29
+ const expectObject = (value, source, path) => {
30
+ if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TiledFormatError(source, path, `expected an object, got ${describeValue(value)}`);
31
+ return value;
32
+ };
33
+ const expectArray = (value, source, path) => {
34
+ if (!Array.isArray(value)) throw new TiledFormatError(source, path, `expected an array, got ${describeValue(value)}`);
35
+ return value;
36
+ };
37
+ const expectString = (value, source, path) => {
38
+ if (typeof value !== "string") throw new TiledFormatError(source, path, `expected a string, got ${describeValue(value)}`);
39
+ return value;
40
+ };
41
+ const expectNumber = (value, source, path) => {
42
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new TiledFormatError(source, path, `expected a finite number, got ${describeValue(value)}`);
43
+ return value;
44
+ };
45
+ const expectInteger = (value, source, path) => {
46
+ const n = expectNumber(value, source, path);
47
+ if (!Number.isInteger(n)) throw new TiledFormatError(source, path, `expected an integer, got ${n}`);
48
+ return n;
49
+ };
50
+ const expectNonNegativeInteger = (value, source, path) => {
51
+ const n = expectInteger(value, source, path);
52
+ if (n < 0) throw new TiledFormatError(source, path, `expected a non-negative integer, got ${n}`);
53
+ return n;
54
+ };
55
+ const expectPositiveInteger = (value, source, path) => {
56
+ const n = expectInteger(value, source, path);
57
+ if (n <= 0) throw new TiledFormatError(source, path, `expected a positive integer, got ${n}`);
58
+ return n;
59
+ };
60
+ const expectBoolean = (value, source, path) => {
61
+ if (typeof value !== "boolean") throw new TiledFormatError(source, path, `expected a boolean, got ${describeValue(value)}`);
62
+ return value;
63
+ };
64
+ const optionalString = (obj, key, source, path) => {
65
+ const value = obj[key];
66
+ return value === void 0 ? void 0 : expectString(value, source, joinPath(path, key));
67
+ };
68
+ const optionalNumber = (obj, key, source, path) => {
69
+ const value = obj[key];
70
+ return value === void 0 ? void 0 : expectNumber(value, source, joinPath(path, key));
71
+ };
72
+ const optionalInteger = (obj, key, source, path) => {
73
+ const value = obj[key];
74
+ return value === void 0 ? void 0 : expectInteger(value, source, joinPath(path, key));
75
+ };
76
+ const optionalNonNegativeInteger = (obj, key, source, path) => {
77
+ const value = obj[key];
78
+ return value === void 0 ? void 0 : expectNonNegativeInteger(value, source, joinPath(path, key));
79
+ };
80
+ const optionalBoolean = (obj, key, source, path) => {
81
+ const value = obj[key];
82
+ return value === void 0 ? void 0 : expectBoolean(value, source, joinPath(path, key));
83
+ };
84
+ const mapArray = (value, source, path, fn) => {
85
+ return expectArray(value, source, path).map((item, i) => fn(item, joinPath(path, i)));
86
+ };
87
+ const optionalMapArray = (value, source, path, fn) => value === void 0 ? void 0 : mapArray(value, source, path, fn);
88
+ const PROPERTY_TYPES = [
89
+ "string",
90
+ "int",
91
+ "float",
92
+ "bool",
93
+ "color",
94
+ "file",
95
+ "object",
96
+ "class"
97
+ ];
98
+ const validateTiledClassPropertyValue = (raw, source, path) => {
99
+ const obj = expectObject(raw, source, path);
100
+ const result = {};
101
+ for (const [key, value] of Object.entries(obj)) {
102
+ const memberPath = joinPath(path, key);
103
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") result[key] = value;
104
+ else if (typeof value === "object" && value !== null && !Array.isArray(value)) result[key] = validateTiledClassPropertyValue(value, source, memberPath);
105
+ else throw new TiledFormatError(source, memberPath, `expected a string, number, boolean, or nested object, got ${describeValue(value)}`);
106
+ }
107
+ return result;
108
+ };
134
109
  /** @internal */
135
- function validateTiledPropertyData(raw, source, path) {
136
- const obj = expectObject(raw, source, path);
137
- const name = expectString(obj.name, source, joinPath(path, 'name'));
138
- const typePath = joinPath(path, 'type');
139
- const typeName = obj.type === undefined ? 'string' : expectString(obj.type, source, typePath);
140
- if (!PROPERTY_TYPES.includes(typeName)) {
141
- throw new TiledFormatError(source, typePath, `unknown property type "${typeName}"`);
142
- }
143
- const type = typeName;
144
- const propertytype = optionalString(obj, 'propertytype', source, path);
145
- const valuePath = joinPath(path, 'value');
146
- let value;
147
- switch (type) {
148
- case 'string':
149
- case 'color':
150
- case 'file':
151
- value = expectString(obj.value, source, valuePath);
152
- break;
153
- case 'int':
154
- case 'float':
155
- case 'object':
156
- value = expectNumber(obj.value, source, valuePath);
157
- break;
158
- case 'bool':
159
- value = expectBoolean(obj.value, source, valuePath);
160
- break;
161
- case 'class':
162
- value = validateTiledClassPropertyValue(obj.value, source, valuePath);
163
- break;
164
- }
165
- return { name, type, propertytype, value };
166
- }
167
- function validateTiledPropertiesArray(value, source, path) {
168
- return optionalMapArray(value, source, path, (item, itemPath) => validateTiledPropertyData(item, source, itemPath));
169
- }
170
- // ── Points / animation frames ───────────────────────────────────────────────
171
- function validateTiledPointData(raw, source, path) {
172
- const obj = expectObject(raw, source, path);
173
- return {
174
- x: expectNumber(obj.x, source, joinPath(path, 'x')),
175
- y: expectNumber(obj.y, source, joinPath(path, 'y')),
176
- };
177
- }
178
- function validateTiledPointArray(value, source, path) {
179
- return mapArray(value, source, path, (item, itemPath) => validateTiledPointData(item, source, itemPath));
180
- }
110
+ const validateTiledPropertyData = (raw, source, path) => {
111
+ const obj = expectObject(raw, source, path);
112
+ const name = expectString(obj.name, source, joinPath(path, "name"));
113
+ const typePath = joinPath(path, "type");
114
+ const typeName = obj.type === void 0 ? "string" : expectString(obj.type, source, typePath);
115
+ if (!PROPERTY_TYPES.includes(typeName)) throw new TiledFormatError(source, typePath, `unknown property type "${typeName}"`);
116
+ const type = typeName;
117
+ const propertytype = optionalString(obj, "propertytype", source, path);
118
+ const valuePath = joinPath(path, "value");
119
+ let value;
120
+ switch (type) {
121
+ case "string":
122
+ case "color":
123
+ case "file":
124
+ value = expectString(obj.value, source, valuePath);
125
+ break;
126
+ case "int":
127
+ case "float":
128
+ case "object":
129
+ value = expectNumber(obj.value, source, valuePath);
130
+ break;
131
+ case "bool":
132
+ value = expectBoolean(obj.value, source, valuePath);
133
+ break;
134
+ case "class": value = validateTiledClassPropertyValue(obj.value, source, valuePath);
135
+ }
136
+ return {
137
+ name,
138
+ type,
139
+ propertytype,
140
+ value
141
+ };
142
+ };
143
+ const validateTiledPropertiesArray = (value, source, path) => optionalMapArray(value, source, path, (item, itemPath) => validateTiledPropertyData(item, source, itemPath));
144
+ const validateTiledPointData = (raw, source, path) => {
145
+ const obj = expectObject(raw, source, path);
146
+ return {
147
+ x: expectNumber(obj.x, source, joinPath(path, "x")),
148
+ y: expectNumber(obj.y, source, joinPath(path, "y"))
149
+ };
150
+ };
151
+ const validateTiledPointArray = (value, source, path) => mapArray(value, source, path, (item, itemPath) => validateTiledPointData(item, source, itemPath));
181
152
  /** @internal */
182
- function validateTiledAnimationFrameData(raw, source, path) {
183
- const obj = expectObject(raw, source, path);
184
- return {
185
- tileid: expectNonNegativeInteger(obj.tileid, source, joinPath(path, 'tileid')),
186
- duration: expectNonNegativeInteger(obj.duration, source, joinPath(path, 'duration')),
187
- };
188
- }
189
- // ── Text objects ─────────────────────────────────────────────────────────────
190
- const HALIGN_VALUES = ['center', 'right', 'justify', 'left'];
191
- const VALIGN_VALUES = ['center', 'bottom', 'top'];
192
- function validateTiledTextData(raw, source, path) {
193
- const obj = expectObject(raw, source, path);
194
- const text = expectString(obj.text, source, joinPath(path, 'text'));
195
- let halign;
196
- if (obj.halign !== undefined) {
197
- const value = expectString(obj.halign, source, joinPath(path, 'halign'));
198
- if (!HALIGN_VALUES.includes(value)) {
199
- throw new TiledFormatError(source, joinPath(path, 'halign'), `unknown horizontal alignment "${value}"`);
200
- }
201
- halign = value;
202
- }
203
- let valign;
204
- if (obj.valign !== undefined) {
205
- const value = expectString(obj.valign, source, joinPath(path, 'valign'));
206
- if (!VALIGN_VALUES.includes(value)) {
207
- throw new TiledFormatError(source, joinPath(path, 'valign'), `unknown vertical alignment "${value}"`);
208
- }
209
- valign = value;
210
- }
211
- return {
212
- text,
213
- bold: optionalBoolean(obj, 'bold', source, path),
214
- color: optionalString(obj, 'color', source, path),
215
- fontfamily: optionalString(obj, 'fontfamily', source, path),
216
- halign,
217
- italic: optionalBoolean(obj, 'italic', source, path),
218
- kerning: optionalBoolean(obj, 'kerning', source, path),
219
- pixelsize: optionalNonNegativeInteger(obj, 'pixelsize', source, path),
220
- strikeout: optionalBoolean(obj, 'strikeout', source, path),
221
- underline: optionalBoolean(obj, 'underline', source, path),
222
- valign,
223
- wrap: optionalBoolean(obj, 'wrap', source, path),
224
- };
225
- }
226
- // ── Objects ──────────────────────────────────────────────────────────────────
153
+ const validateTiledAnimationFrameData = (raw, source, path) => {
154
+ const obj = expectObject(raw, source, path);
155
+ return {
156
+ tileid: expectNonNegativeInteger(obj.tileid, source, joinPath(path, "tileid")),
157
+ duration: expectNonNegativeInteger(obj.duration, source, joinPath(path, "duration"))
158
+ };
159
+ };
160
+ const HALIGN_VALUES = [
161
+ "center",
162
+ "right",
163
+ "justify",
164
+ "left"
165
+ ];
166
+ const VALIGN_VALUES = [
167
+ "center",
168
+ "bottom",
169
+ "top"
170
+ ];
171
+ const validateTiledTextData = (raw, source, path) => {
172
+ const obj = expectObject(raw, source, path);
173
+ const text = expectString(obj.text, source, joinPath(path, "text"));
174
+ let halign;
175
+ if (obj.halign !== void 0) {
176
+ const value = expectString(obj.halign, source, joinPath(path, "halign"));
177
+ if (!HALIGN_VALUES.includes(value)) throw new TiledFormatError(source, joinPath(path, "halign"), `unknown horizontal alignment "${value}"`);
178
+ halign = value;
179
+ }
180
+ let valign;
181
+ if (obj.valign !== void 0) {
182
+ const value = expectString(obj.valign, source, joinPath(path, "valign"));
183
+ if (!VALIGN_VALUES.includes(value)) throw new TiledFormatError(source, joinPath(path, "valign"), `unknown vertical alignment "${value}"`);
184
+ valign = value;
185
+ }
186
+ return {
187
+ text,
188
+ bold: optionalBoolean(obj, "bold", source, path),
189
+ color: optionalString(obj, "color", source, path),
190
+ fontfamily: optionalString(obj, "fontfamily", source, path),
191
+ halign,
192
+ italic: optionalBoolean(obj, "italic", source, path),
193
+ kerning: optionalBoolean(obj, "kerning", source, path),
194
+ pixelsize: optionalNonNegativeInteger(obj, "pixelsize", source, path),
195
+ strikeout: optionalBoolean(obj, "strikeout", source, path),
196
+ underline: optionalBoolean(obj, "underline", source, path),
197
+ valign,
198
+ wrap: optionalBoolean(obj, "wrap", source, path)
199
+ };
200
+ };
227
201
  /** @internal */
228
- function validateTiledObjectData(raw, source, path) {
229
- const obj = expectObject(raw, source, path);
230
- return {
231
- id: expectNonNegativeInteger(obj.id, source, joinPath(path, 'id')),
232
- name: expectString(obj.name, source, joinPath(path, 'name')),
233
- type: expectString(obj.type, source, joinPath(path, 'type')),
234
- x: expectNumber(obj.x, source, joinPath(path, 'x')),
235
- y: expectNumber(obj.y, source, joinPath(path, 'y')),
236
- width: expectNumber(obj.width, source, joinPath(path, 'width')),
237
- height: expectNumber(obj.height, source, joinPath(path, 'height')),
238
- rotation: expectNumber(obj.rotation, source, joinPath(path, 'rotation')),
239
- visible: expectBoolean(obj.visible, source, joinPath(path, 'visible')),
240
- gid: optionalNonNegativeInteger(obj, 'gid', source, path),
241
- point: optionalBoolean(obj, 'point', source, path),
242
- ellipse: optionalBoolean(obj, 'ellipse', source, path),
243
- polygon: obj.polygon === undefined ? undefined : validateTiledPointArray(obj.polygon, source, joinPath(path, 'polygon')),
244
- polyline: obj.polyline === undefined ? undefined : validateTiledPointArray(obj.polyline, source, joinPath(path, 'polyline')),
245
- text: obj.text === undefined ? undefined : validateTiledTextData(obj.text, source, joinPath(path, 'text')),
246
- template: optionalString(obj, 'template', source, path),
247
- properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, 'properties')),
248
- };
249
- }
250
- // ── Layers ───────────────────────────────────────────────────────────────────
251
- const LAYER_TYPES = ['tilelayer', 'objectgroup', 'imagelayer', 'group'];
252
- const SUPPORTED_TILE_LAYER_ENCODINGS = new Set(['csv']);
253
- const DRAW_ORDERS = ['topdown', 'index'];
254
- function validateTiledLayerBase(obj, source, path) {
255
- return {
256
- id: expectNonNegativeInteger(obj.id, source, joinPath(path, 'id')),
257
- name: expectString(obj.name, source, joinPath(path, 'name')),
258
- class: optionalString(obj, 'class', source, path),
259
- visible: expectBoolean(obj.visible, source, joinPath(path, 'visible')),
260
- opacity: expectNumber(obj.opacity, source, joinPath(path, 'opacity')),
261
- x: expectNumber(obj.x, source, joinPath(path, 'x')),
262
- y: expectNumber(obj.y, source, joinPath(path, 'y')),
263
- offsetx: optionalNumber(obj, 'offsetx', source, path),
264
- offsety: optionalNumber(obj, 'offsety', source, path),
265
- parallaxx: optionalNumber(obj, 'parallaxx', source, path),
266
- parallaxy: optionalNumber(obj, 'parallaxy', source, path),
267
- tintcolor: optionalString(obj, 'tintcolor', source, path),
268
- properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, 'properties')),
269
- };
270
- }
271
- function validateTiledGidArray(value, source, path) {
272
- return mapArray(value, source, path, (item, itemPath) => expectNonNegativeInteger(item, source, itemPath));
273
- }
274
- function validateTiledChunkData(raw, source, path) {
275
- const obj = expectObject(raw, source, path);
276
- return {
277
- x: expectInteger(obj.x, source, joinPath(path, 'x')),
278
- y: expectInteger(obj.y, source, joinPath(path, 'y')),
279
- width: expectPositiveInteger(obj.width, source, joinPath(path, 'width')),
280
- height: expectPositiveInteger(obj.height, source, joinPath(path, 'height')),
281
- data: validateTiledGidArray(obj.data, source, joinPath(path, 'data')),
282
- };
283
- }
284
- function validateTiledTileLayerData(obj, base, source, path) {
285
- // Validation runs AFTER the async decode pass (`decodeLayerData.ts`), which
286
- // turns base64/gzip/zlib `data` into a plain GID array and strips these
287
- // markers. Reaching here with them still set means the data was not decoded
288
- // (e.g. validate was called directly) reject rather than mis-parse.
289
- if (obj.compression !== undefined) {
290
- throw new TiledFormatError(source, joinPath(path, 'compression'), `compressed tile layer data is not supported (compression: ${JSON.stringify(obj.compression)})`);
291
- }
292
- const encoding = obj.encoding;
293
- if (encoding !== undefined && !(typeof encoding === 'string' && SUPPORTED_TILE_LAYER_ENCODINGS.has(encoding))) {
294
- throw new TiledFormatError(source, joinPath(path, 'encoding'), `unsupported tile layer encoding ${JSON.stringify(encoding)} (only plain CSV/array data is supported)`);
295
- }
296
- const width = expectNonNegativeInteger(obj.width, source, joinPath(path, 'width'));
297
- const height = expectNonNegativeInteger(obj.height, source, joinPath(path, 'height'));
298
- const hasData = obj.data !== undefined;
299
- const hasChunks = obj.chunks !== undefined;
300
- if (hasData === hasChunks) {
301
- throw new TiledFormatError(source, path, hasData ? 'tile layer has both "data" and "chunks"' : 'tile layer has neither "data" nor "chunks"');
302
- }
303
- return {
304
- ...base,
305
- type: 'tilelayer',
306
- width,
307
- height,
308
- data: hasData ? validateTiledGidArray(obj.data, source, joinPath(path, 'data')) : undefined,
309
- chunks: hasChunks ? mapArray(obj.chunks, source, joinPath(path, 'chunks'), (item, itemPath) => validateTiledChunkData(item, source, itemPath)) : undefined,
310
- };
311
- }
312
- function validateTiledObjectLayerData(obj, base, source, path) {
313
- let draworder;
314
- if (obj.draworder !== undefined) {
315
- const value = expectString(obj.draworder, source, joinPath(path, 'draworder'));
316
- if (!DRAW_ORDERS.includes(value)) {
317
- throw new TiledFormatError(source, joinPath(path, 'draworder'), `unknown draw order "${value}"`);
318
- }
319
- draworder = value;
320
- }
321
- return {
322
- ...base,
323
- type: 'objectgroup',
324
- draworder,
325
- objects: mapArray(obj.objects, source, joinPath(path, 'objects'), (item, itemPath) => validateTiledObjectData(item, source, itemPath)),
326
- };
327
- }
328
- function validateTiledImageLayerData(obj, base, source, path) {
329
- return {
330
- ...base,
331
- type: 'imagelayer',
332
- image: obj.image === undefined ? '' : expectString(obj.image, source, joinPath(path, 'image')),
333
- repeatx: optionalBoolean(obj, 'repeatx', source, path),
334
- repeaty: optionalBoolean(obj, 'repeaty', source, path),
335
- };
336
- }
337
- function validateTiledGroupLayerData(obj, base, source, path) {
338
- return {
339
- ...base,
340
- type: 'group',
341
- layers: mapArray(obj.layers, source, joinPath(path, 'layers'), (item, itemPath) => validateTiledLayerData(item, source, itemPath)),
342
- };
343
- }
202
+ const validateTiledObjectData = (raw, source, path) => {
203
+ const obj = expectObject(raw, source, path);
204
+ return {
205
+ id: expectNonNegativeInteger(obj.id, source, joinPath(path, "id")),
206
+ name: expectString(obj.name, source, joinPath(path, "name")),
207
+ type: optionalString(obj, "type", source, path) ?? "",
208
+ class: optionalString(obj, "class", source, path),
209
+ x: expectNumber(obj.x, source, joinPath(path, "x")),
210
+ y: expectNumber(obj.y, source, joinPath(path, "y")),
211
+ width: expectNumber(obj.width, source, joinPath(path, "width")),
212
+ height: expectNumber(obj.height, source, joinPath(path, "height")),
213
+ rotation: expectNumber(obj.rotation, source, joinPath(path, "rotation")),
214
+ visible: expectBoolean(obj.visible, source, joinPath(path, "visible")),
215
+ gid: optionalNonNegativeInteger(obj, "gid", source, path),
216
+ point: optionalBoolean(obj, "point", source, path),
217
+ ellipse: optionalBoolean(obj, "ellipse", source, path),
218
+ polygon: obj.polygon === void 0 ? void 0 : validateTiledPointArray(obj.polygon, source, joinPath(path, "polygon")),
219
+ polyline: obj.polyline === void 0 ? void 0 : validateTiledPointArray(obj.polyline, source, joinPath(path, "polyline")),
220
+ text: obj.text === void 0 ? void 0 : validateTiledTextData(obj.text, source, joinPath(path, "text")),
221
+ template: optionalString(obj, "template", source, path),
222
+ properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, "properties"))
223
+ };
224
+ };
225
+ const LAYER_TYPES = [
226
+ "tilelayer",
227
+ "objectgroup",
228
+ "imagelayer",
229
+ "group"
230
+ ];
231
+ const SUPPORTED_TILE_LAYER_ENCODINGS = /* @__PURE__ */ new Set(["csv"]);
232
+ const DRAW_ORDERS = ["topdown", "index"];
233
+ const validateTiledLayerBase = (obj, source, path) => ({
234
+ id: expectNonNegativeInteger(obj.id, source, joinPath(path, "id")),
235
+ name: expectString(obj.name, source, joinPath(path, "name")),
236
+ class: optionalString(obj, "class", source, path),
237
+ visible: expectBoolean(obj.visible, source, joinPath(path, "visible")),
238
+ opacity: expectNumber(obj.opacity, source, joinPath(path, "opacity")),
239
+ x: expectNumber(obj.x, source, joinPath(path, "x")),
240
+ y: expectNumber(obj.y, source, joinPath(path, "y")),
241
+ offsetx: optionalNumber(obj, "offsetx", source, path),
242
+ offsety: optionalNumber(obj, "offsety", source, path),
243
+ parallaxx: optionalNumber(obj, "parallaxx", source, path),
244
+ parallaxy: optionalNumber(obj, "parallaxy", source, path),
245
+ tintcolor: optionalString(obj, "tintcolor", source, path),
246
+ properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, "properties"))
247
+ });
248
+ const validateTiledGidArray = (value, source, path) => mapArray(value, source, path, (item, itemPath) => expectNonNegativeInteger(item, source, itemPath));
249
+ const validateTiledChunkData = (raw, source, path) => {
250
+ const obj = expectObject(raw, source, path);
251
+ return {
252
+ x: expectInteger(obj.x, source, joinPath(path, "x")),
253
+ y: expectInteger(obj.y, source, joinPath(path, "y")),
254
+ width: expectPositiveInteger(obj.width, source, joinPath(path, "width")),
255
+ height: expectPositiveInteger(obj.height, source, joinPath(path, "height")),
256
+ data: validateTiledGidArray(obj.data, source, joinPath(path, "data"))
257
+ };
258
+ };
259
+ const validateTiledTileLayerData = (obj, base, source, path) => {
260
+ if (obj.compression !== void 0) throw new TiledFormatError(source, joinPath(path, "compression"), `compressed tile layer data is not supported (compression: ${JSON.stringify(obj.compression)})`);
261
+ const encoding = obj.encoding;
262
+ if (encoding !== void 0 && !(typeof encoding === "string" && SUPPORTED_TILE_LAYER_ENCODINGS.has(encoding))) throw new TiledFormatError(source, joinPath(path, "encoding"), `unsupported tile layer encoding ${JSON.stringify(encoding)} (only plain CSV/array data is supported)`);
263
+ const width = expectNonNegativeInteger(obj.width, source, joinPath(path, "width"));
264
+ const height = expectNonNegativeInteger(obj.height, source, joinPath(path, "height"));
265
+ const hasData = obj.data !== void 0;
266
+ const hasChunks = obj.chunks !== void 0;
267
+ if (hasData === hasChunks) throw new TiledFormatError(source, path, hasData ? "tile layer has both \"data\" and \"chunks\"" : "tile layer has neither \"data\" nor \"chunks\"");
268
+ return {
269
+ ...base,
270
+ type: "tilelayer",
271
+ width,
272
+ height,
273
+ data: hasData ? validateTiledGidArray(obj.data, source, joinPath(path, "data")) : void 0,
274
+ chunks: hasChunks ? mapArray(obj.chunks, source, joinPath(path, "chunks"), (item, itemPath) => validateTiledChunkData(item, source, itemPath)) : void 0
275
+ };
276
+ };
277
+ const validateTiledObjectLayerData = (obj, base, source, path) => {
278
+ let draworder;
279
+ if (obj.draworder !== void 0) {
280
+ const value = expectString(obj.draworder, source, joinPath(path, "draworder"));
281
+ if (!DRAW_ORDERS.includes(value)) throw new TiledFormatError(source, joinPath(path, "draworder"), `unknown draw order "${value}"`);
282
+ draworder = value;
283
+ }
284
+ return {
285
+ ...base,
286
+ type: "objectgroup",
287
+ draworder,
288
+ objects: mapArray(obj.objects, source, joinPath(path, "objects"), (item, itemPath) => validateTiledObjectData(item, source, itemPath))
289
+ };
290
+ };
291
+ const validateTiledImageLayerData = (obj, base, source, path) => ({
292
+ ...base,
293
+ type: "imagelayer",
294
+ image: obj.image === void 0 ? "" : expectString(obj.image, source, joinPath(path, "image")),
295
+ repeatx: optionalBoolean(obj, "repeatx", source, path),
296
+ repeaty: optionalBoolean(obj, "repeaty", source, path)
297
+ });
298
+ const validateTiledGroupLayerData = (obj, base, source, path) => ({
299
+ ...base,
300
+ type: "group",
301
+ layers: mapArray(obj.layers, source, joinPath(path, "layers"), (item, itemPath) => validateTiledLayerData(item, source, itemPath))
302
+ });
344
303
  /** @internal */
345
- function validateTiledLayerData(raw, source, path) {
346
- const obj = expectObject(raw, source, path);
347
- const type = expectString(obj.type, source, joinPath(path, 'type'));
348
- const base = validateTiledLayerBase(obj, source, path);
349
- switch (type) {
350
- case 'tilelayer':
351
- return validateTiledTileLayerData(obj, base, source, path);
352
- case 'objectgroup':
353
- return validateTiledObjectLayerData(obj, base, source, path);
354
- case 'imagelayer':
355
- return validateTiledImageLayerData(obj, base, source, path);
356
- case 'group':
357
- return validateTiledGroupLayerData(obj, base, source, path);
358
- default: {
359
- const known = LAYER_TYPES;
360
- throw new TiledFormatError(source, joinPath(path, 'type'), `unknown layer type "${type}" (expected one of ${known.join(', ')})`);
361
- }
362
- }
363
- }
304
+ const validateTiledLayerData = (raw, source, path) => {
305
+ const obj = expectObject(raw, source, path);
306
+ const type = expectString(obj.type, source, joinPath(path, "type"));
307
+ const base = validateTiledLayerBase(obj, source, path);
308
+ switch (type) {
309
+ case "tilelayer": return validateTiledTileLayerData(obj, base, source, path);
310
+ case "objectgroup": return validateTiledObjectLayerData(obj, base, source, path);
311
+ case "imagelayer": return validateTiledImageLayerData(obj, base, source, path);
312
+ case "group": return validateTiledGroupLayerData(obj, base, source, path);
313
+ default: {
314
+ const known = LAYER_TYPES;
315
+ throw new TiledFormatError(source, joinPath(path, "type"), `unknown layer type "${type}" (expected one of ${known.join(", ")})`);
316
+ }
317
+ }
318
+ };
364
319
  /**
365
- * Walks a layer tree and ensures every tile layer's `data`/`chunks` choice
366
- * matches the map's `infinite` flag. Tiled itself is consistent across an
367
- * entire map; a mismatch indicates a hand-edited or corrupt file.
368
- * @internal
369
- */
370
- function checkTiledLayerInfiniteConsistency(layers, infinite, source, path) {
371
- for (let i = 0; i < layers.length; i++) {
372
- const layer = layers[i];
373
- if (layer === undefined)
374
- continue;
375
- const layerPath = joinPath(path, i);
376
- if (layer.type === 'tilelayer') {
377
- const hasChunks = layer.chunks !== undefined;
378
- if (hasChunks !== infinite) {
379
- throw new TiledFormatError(source, layerPath, infinite ? 'tile layer is missing "chunks" on an infinite map' : 'tile layer has "chunks" on a finite map (expected "data")');
380
- }
381
- }
382
- else if (layer.type === 'group') {
383
- checkTiledLayerInfiniteConsistency(layer.layers, infinite, source, joinPath(layerPath, 'layers'));
384
- }
385
- }
386
- }
387
- // ── Tile definitions ─────────────────────────────────────────────────────────
320
+ * Walks a layer tree and ensures every tile layer's `data`/`chunks` choice
321
+ * matches the map's `infinite` flag. Tiled itself is consistent across an
322
+ * entire map; a mismatch indicates a hand-edited or corrupt file.
323
+ * @internal
324
+ */
325
+ const checkTiledLayerInfiniteConsistency = (layers, infinite, source, path) => {
326
+ for (let i = 0; i < layers.length; i++) {
327
+ const layer = layers[i];
328
+ if (layer === void 0) continue;
329
+ const layerPath = joinPath(path, i);
330
+ if (layer.type === "tilelayer") {
331
+ if (layer.chunks !== void 0 !== infinite) throw new TiledFormatError(source, layerPath, infinite ? "tile layer is missing \"chunks\" on an infinite map" : "tile layer has \"chunks\" on a finite map (expected \"data\")");
332
+ } else if (layer.type === "group") checkTiledLayerInfiniteConsistency(layer.layers, infinite, source, joinPath(layerPath, "layers"));
333
+ }
334
+ };
388
335
  /** @internal */
389
- function validateTiledTileData(raw, source, path) {
390
- const obj = expectObject(raw, source, path);
391
- let objectgroup;
392
- if (obj.objectgroup !== undefined) {
393
- const objectgroupPath = joinPath(path, 'objectgroup');
394
- const layer = validateTiledLayerData(obj.objectgroup, source, objectgroupPath);
395
- if (layer.type !== 'objectgroup') {
396
- throw new TiledFormatError(source, objectgroupPath, `expected an "objectgroup" layer, got "${layer.type}"`);
397
- }
398
- objectgroup = layer;
399
- }
400
- return {
401
- id: expectNonNegativeInteger(obj.id, source, joinPath(path, 'id')),
402
- type: optionalString(obj, 'type', source, path),
403
- properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, 'properties')),
404
- animation: optionalMapArray(obj.animation, source, joinPath(path, 'animation'), (item, itemPath) => validateTiledAnimationFrameData(item, source, itemPath)),
405
- objectgroup,
406
- image: optionalString(obj, 'image', source, path),
407
- imagewidth: optionalNonNegativeInteger(obj, 'imagewidth', source, path),
408
- imageheight: optionalNonNegativeInteger(obj, 'imageheight', source, path),
409
- };
410
- }
411
- // ── Wangsets ─────────────────────────────────────────────────────────────────
412
- function validateTiledWangColorData(raw, source, path) {
413
- const obj = expectObject(raw, source, path);
414
- return {
415
- name: expectString(obj.name, source, joinPath(path, 'name')),
416
- color: expectString(obj.color, source, joinPath(path, 'color')),
417
- tile: expectInteger(obj.tile, source, joinPath(path, 'tile')),
418
- probability: expectNumber(obj.probability, source, joinPath(path, 'probability')),
419
- };
420
- }
421
- function validateTiledWangTileData(raw, source, path) {
422
- const obj = expectObject(raw, source, path);
423
- const tileid = expectNonNegativeInteger(obj.tileid, source, joinPath(path, 'tileid'));
424
- const wangid = mapArray(obj.wangid, source, joinPath(path, 'wangid'), (item, itemPath) => expectNonNegativeInteger(item, source, itemPath));
425
- return { tileid, wangid };
426
- }
427
- function validateTiledWangSetData(raw, source, path) {
428
- const obj = expectObject(raw, source, path);
429
- return {
430
- name: expectString(obj.name, source, joinPath(path, 'name')),
431
- // type is accepted as any string unknown values are treated as-is per spec
432
- type: expectString(obj.type, source, joinPath(path, 'type')),
433
- tile: expectInteger(obj.tile, source, joinPath(path, 'tile')),
434
- colors: mapArray(obj.colors, source, joinPath(path, 'colors'), (item, itemPath) => validateTiledWangColorData(item, source, itemPath)),
435
- wangtiles: mapArray(obj.wangtiles, source, joinPath(path, 'wangtiles'), (item, itemPath) => validateTiledWangTileData(item, source, itemPath)),
436
- properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, 'properties')),
437
- };
438
- }
439
- function validateTiledWangSets(value, source, path) {
440
- return optionalMapArray(value, source, path, (item, itemPath) => validateTiledWangSetData(item, source, itemPath));
441
- }
442
- // ── Tilesets ─────────────────────────────────────────────────────────────────
443
- function validateTiledVersion(value, source, path) {
444
- if (typeof value !== 'string' && typeof value !== 'number') {
445
- throw new TiledFormatError(source, path, `expected a string or number, got ${describeValue(value)}`);
446
- }
447
- return value;
448
- }
336
+ const validateTiledTileData = (raw, source, path) => {
337
+ const obj = expectObject(raw, source, path);
338
+ let objectgroup;
339
+ if (obj.objectgroup !== void 0) {
340
+ const objectgroupPath = joinPath(path, "objectgroup");
341
+ const layer = validateTiledLayerData(obj.objectgroup, source, objectgroupPath);
342
+ if (layer.type !== "objectgroup") throw new TiledFormatError(source, objectgroupPath, `expected an "objectgroup" layer, got "${layer.type}"`);
343
+ objectgroup = layer;
344
+ }
345
+ return {
346
+ id: expectNonNegativeInteger(obj.id, source, joinPath(path, "id")),
347
+ type: optionalString(obj, "type", source, path),
348
+ properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, "properties")),
349
+ animation: optionalMapArray(obj.animation, source, joinPath(path, "animation"), (item, itemPath) => validateTiledAnimationFrameData(item, source, itemPath)),
350
+ objectgroup,
351
+ image: optionalString(obj, "image", source, path),
352
+ imagewidth: optionalNonNegativeInteger(obj, "imagewidth", source, path),
353
+ imageheight: optionalNonNegativeInteger(obj, "imageheight", source, path)
354
+ };
355
+ };
356
+ const validateTiledWangColorData = (raw, source, path) => {
357
+ const obj = expectObject(raw, source, path);
358
+ return {
359
+ name: expectString(obj.name, source, joinPath(path, "name")),
360
+ color: expectString(obj.color, source, joinPath(path, "color")),
361
+ tile: expectInteger(obj.tile, source, joinPath(path, "tile")),
362
+ probability: expectNumber(obj.probability, source, joinPath(path, "probability"))
363
+ };
364
+ };
365
+ const validateTiledWangTileData = (raw, source, path) => {
366
+ const obj = expectObject(raw, source, path);
367
+ return {
368
+ tileid: expectNonNegativeInteger(obj.tileid, source, joinPath(path, "tileid")),
369
+ wangid: mapArray(obj.wangid, source, joinPath(path, "wangid"), (item, itemPath) => expectNonNegativeInteger(item, source, itemPath))
370
+ };
371
+ };
372
+ const validateTiledWangSetData = (raw, source, path) => {
373
+ const obj = expectObject(raw, source, path);
374
+ return {
375
+ name: expectString(obj.name, source, joinPath(path, "name")),
376
+ type: expectString(obj.type, source, joinPath(path, "type")),
377
+ tile: expectInteger(obj.tile, source, joinPath(path, "tile")),
378
+ colors: mapArray(obj.colors, source, joinPath(path, "colors"), (item, itemPath) => validateTiledWangColorData(item, source, itemPath)),
379
+ wangtiles: mapArray(obj.wangtiles, source, joinPath(path, "wangtiles"), (item, itemPath) => validateTiledWangTileData(item, source, itemPath)),
380
+ properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, "properties"))
381
+ };
382
+ };
383
+ const validateTiledWangSets = (value, source, path) => optionalMapArray(value, source, path, (item, itemPath) => validateTiledWangSetData(item, source, itemPath));
384
+ const validateTiledVersion = (value, source, path) => {
385
+ if (typeof value !== "string" && typeof value !== "number") throw new TiledFormatError(source, path, `expected a string or number, got ${describeValue(value)}`);
386
+ return value;
387
+ };
388
+ const validateTiledObjectAlignment = (obj, source, path) => {
389
+ const value = obj.objectalignment;
390
+ if (value === void 0) return void 0;
391
+ const alignmentPath = joinPath(path, "objectalignment");
392
+ const name = expectString(value, source, alignmentPath);
393
+ if (!TILED_OBJECT_ALIGNMENTS.includes(name)) throw new TiledFormatError(source, alignmentPath, `unknown object alignment "${name}" (expected one of ${TILED_OBJECT_ALIGNMENTS.join(", ")})`);
394
+ return name;
395
+ };
449
396
  /** @internal */
450
- function validateTiledTilesetData(obj, source, path) {
451
- return {
452
- name: expectString(obj.name, source, joinPath(path, 'name')),
453
- class: optionalString(obj, 'class', source, path),
454
- tilewidth: expectPositiveInteger(obj.tilewidth, source, joinPath(path, 'tilewidth')),
455
- tileheight: expectPositiveInteger(obj.tileheight, source, joinPath(path, 'tileheight')),
456
- tilecount: expectNonNegativeInteger(obj.tilecount, source, joinPath(path, 'tilecount')),
457
- columns: expectNonNegativeInteger(obj.columns, source, joinPath(path, 'columns')),
458
- spacing: optionalNonNegativeInteger(obj, 'spacing', source, path),
459
- margin: optionalNonNegativeInteger(obj, 'margin', source, path),
460
- image: optionalString(obj, 'image', source, path),
461
- imagewidth: optionalNonNegativeInteger(obj, 'imagewidth', source, path),
462
- imageheight: optionalNonNegativeInteger(obj, 'imageheight', source, path),
463
- tileoffset: obj.tileoffset === undefined ? undefined : validateTiledPointData(obj.tileoffset, source, joinPath(path, 'tileoffset')),
464
- objectalignment: optionalString(obj, 'objectalignment', source, path),
465
- tiles: optionalMapArray(obj.tiles, source, joinPath(path, 'tiles'), (item, itemPath) => validateTiledTileData(item, source, itemPath)),
466
- wangsets: validateTiledWangSets(obj.wangsets, source, joinPath(path, 'wangsets')),
467
- properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, 'properties')),
468
- tiledversion: optionalString(obj, 'tiledversion', source, path),
469
- version: obj.version === undefined ? undefined : validateTiledVersion(obj.version, source, joinPath(path, 'version')),
470
- };
471
- }
397
+ const validateTiledTilesetData = (obj, source, path) => ({
398
+ name: expectString(obj.name, source, joinPath(path, "name")),
399
+ class: optionalString(obj, "class", source, path),
400
+ tilewidth: expectPositiveInteger(obj.tilewidth, source, joinPath(path, "tilewidth")),
401
+ tileheight: expectPositiveInteger(obj.tileheight, source, joinPath(path, "tileheight")),
402
+ tilecount: expectNonNegativeInteger(obj.tilecount, source, joinPath(path, "tilecount")),
403
+ columns: expectNonNegativeInteger(obj.columns, source, joinPath(path, "columns")),
404
+ spacing: optionalNonNegativeInteger(obj, "spacing", source, path),
405
+ margin: optionalNonNegativeInteger(obj, "margin", source, path),
406
+ image: optionalString(obj, "image", source, path),
407
+ imagewidth: optionalNonNegativeInteger(obj, "imagewidth", source, path),
408
+ imageheight: optionalNonNegativeInteger(obj, "imageheight", source, path),
409
+ tileoffset: obj.tileoffset === void 0 ? void 0 : validateTiledPointData(obj.tileoffset, source, joinPath(path, "tileoffset")),
410
+ objectalignment: validateTiledObjectAlignment(obj, source, path),
411
+ tiles: optionalMapArray(obj.tiles, source, joinPath(path, "tiles"), (item, itemPath) => validateTiledTileData(item, source, itemPath)),
412
+ wangsets: validateTiledWangSets(obj.wangsets, source, joinPath(path, "wangsets")),
413
+ properties: validateTiledPropertiesArray(obj.properties, source, joinPath(path, "properties")),
414
+ tiledversion: optionalString(obj, "tiledversion", source, path),
415
+ version: obj.version === void 0 ? void 0 : validateTiledVersion(obj.version, source, joinPath(path, "version"))
416
+ });
472
417
  /**
473
- * Validates one entry of a map's `tilesets` array: either `{ firstgid,
474
- * source }` (external `.tsj`) or `{ firstgid, ...embedded tileset fields }`.
475
- * @internal
476
- */
477
- function validateTiledTilesetRefData(raw, source, path) {
478
- const obj = expectObject(raw, source, path);
479
- const firstgid = expectPositiveInteger(obj.firstgid, source, joinPath(path, 'firstgid'));
480
- if ('source' in obj) {
481
- return { firstgid, source: expectString(obj.source, source, joinPath(path, 'source')) };
482
- }
483
- return { ...validateTiledTilesetData(obj, source, path), firstgid };
484
- }
485
- // ── Map ──────────────────────────────────────────────────────────────────────
486
- const ORIENTATIONS = ['orthogonal', 'isometric', 'staggered', 'hexagonal'];
487
- const RENDER_ORDERS = ['right-down', 'right-up', 'left-down', 'left-up'];
418
+ * Validates one entry of a map's `tilesets` array: either `{ firstgid,
419
+ * source }` (external `.tsj`) or `{ firstgid, ...embedded tileset fields }`.
420
+ * @internal
421
+ */
422
+ const validateTiledTilesetRefData = (raw, source, path) => {
423
+ const obj = expectObject(raw, source, path);
424
+ const firstgid = expectPositiveInteger(obj.firstgid, source, joinPath(path, "firstgid"));
425
+ if ("source" in obj) return {
426
+ firstgid,
427
+ source: expectString(obj.source, source, joinPath(path, "source"))
428
+ };
429
+ return {
430
+ ...validateTiledTilesetData(obj, source, path),
431
+ firstgid
432
+ };
433
+ };
434
+ const ORIENTATIONS = [
435
+ "orthogonal",
436
+ "isometric",
437
+ "staggered",
438
+ "hexagonal"
439
+ ];
440
+ const RENDER_ORDERS = [
441
+ "right-down",
442
+ "right-up",
443
+ "left-down",
444
+ "left-up"
445
+ ];
488
446
  /**
489
- * Validates the root of a `.tmj` file. Throws {@link TiledFormatError} on
490
- * any structural problem, including unsupported tile-layer encodings and
491
- * `infinite`/`data`/`chunks` inconsistencies.
492
- * @internal
493
- */
494
- function validateTiledMapData(raw, source) {
495
- const obj = expectObject(raw, source, '');
496
- const type = expectString(obj.type, source, 'type');
497
- if (type !== 'map') {
498
- throw new TiledFormatError(source, 'type', `expected "map", got "${type}"`);
499
- }
500
- const version = validateTiledVersion(obj.version, source, 'version');
501
- const orientationValue = expectString(obj.orientation, source, 'orientation');
502
- if (!ORIENTATIONS.includes(orientationValue)) {
503
- throw new TiledFormatError(source, 'orientation', `unknown orientation "${orientationValue}" (expected one of ${ORIENTATIONS.join(', ')})`);
504
- }
505
- const orientation = orientationValue;
506
- let renderorder;
507
- if (obj.renderorder !== undefined) {
508
- const value = expectString(obj.renderorder, source, 'renderorder');
509
- if (!RENDER_ORDERS.includes(value)) {
510
- throw new TiledFormatError(source, 'renderorder', `unknown render order "${value}" (expected one of ${RENDER_ORDERS.join(', ')})`);
511
- }
512
- renderorder = value;
513
- }
514
- const infinite = expectBoolean(obj.infinite, source, 'infinite');
515
- const layers = mapArray(obj.layers, source, 'layers', (item, itemPath) => validateTiledLayerData(item, source, itemPath));
516
- checkTiledLayerInfiniteConsistency(layers, infinite, source, 'layers');
517
- return {
518
- type: 'map',
519
- version,
520
- tiledversion: optionalString(obj, 'tiledversion', source, ''),
521
- class: optionalString(obj, 'class', source, ''),
522
- orientation,
523
- renderorder,
524
- width: expectNonNegativeInteger(obj.width, source, 'width'),
525
- height: expectNonNegativeInteger(obj.height, source, 'height'),
526
- tilewidth: expectPositiveInteger(obj.tilewidth, source, 'tilewidth'),
527
- tileheight: expectPositiveInteger(obj.tileheight, source, 'tileheight'),
528
- infinite,
529
- compressionlevel: optionalInteger(obj, 'compressionlevel', source, ''),
530
- nextlayerid: optionalNonNegativeInteger(obj, 'nextlayerid', source, ''),
531
- nextobjectid: optionalNonNegativeInteger(obj, 'nextobjectid', source, ''),
532
- backgroundcolor: optionalString(obj, 'backgroundcolor', source, ''),
533
- layers,
534
- tilesets: mapArray(obj.tilesets, source, 'tilesets', (item, itemPath) => validateTiledTilesetRefData(item, source, itemPath)),
535
- properties: validateTiledPropertiesArray(obj.properties, source, 'properties'),
536
- };
537
- }
447
+ * Validates the root of a `.tmj` file. Throws {@link TiledFormatError} on
448
+ * any structural problem, including unsupported tile-layer encodings and
449
+ * `infinite`/`data`/`chunks` inconsistencies.
450
+ * @internal
451
+ */
452
+ const validateTiledMapData = (raw, source) => {
453
+ const obj = expectObject(raw, source, "");
454
+ const type = expectString(obj.type, source, "type");
455
+ if (type !== "map") throw new TiledFormatError(source, "type", `expected "map", got "${type}"`);
456
+ const version = validateTiledVersion(obj.version, source, "version");
457
+ const orientationValue = expectString(obj.orientation, source, "orientation");
458
+ if (!ORIENTATIONS.includes(orientationValue)) throw new TiledFormatError(source, "orientation", `unknown orientation "${orientationValue}" (expected one of ${ORIENTATIONS.join(", ")})`);
459
+ const orientation = orientationValue;
460
+ let renderorder;
461
+ if (obj.renderorder !== void 0) {
462
+ const value = expectString(obj.renderorder, source, "renderorder");
463
+ if (!RENDER_ORDERS.includes(value)) throw new TiledFormatError(source, "renderorder", `unknown render order "${value}" (expected one of ${RENDER_ORDERS.join(", ")})`);
464
+ renderorder = value;
465
+ }
466
+ const infinite = expectBoolean(obj.infinite, source, "infinite");
467
+ const layers = mapArray(obj.layers, source, "layers", (item, itemPath) => validateTiledLayerData(item, source, itemPath));
468
+ checkTiledLayerInfiniteConsistency(layers, infinite, source, "layers");
469
+ return {
470
+ type: "map",
471
+ version,
472
+ tiledversion: optionalString(obj, "tiledversion", source, ""),
473
+ class: optionalString(obj, "class", source, ""),
474
+ orientation,
475
+ renderorder,
476
+ width: expectNonNegativeInteger(obj.width, source, "width"),
477
+ height: expectNonNegativeInteger(obj.height, source, "height"),
478
+ tilewidth: expectPositiveInteger(obj.tilewidth, source, "tilewidth"),
479
+ tileheight: expectPositiveInteger(obj.tileheight, source, "tileheight"),
480
+ infinite,
481
+ compressionlevel: optionalInteger(obj, "compressionlevel", source, ""),
482
+ nextlayerid: optionalNonNegativeInteger(obj, "nextlayerid", source, ""),
483
+ nextobjectid: optionalNonNegativeInteger(obj, "nextobjectid", source, ""),
484
+ backgroundcolor: optionalString(obj, "backgroundcolor", source, ""),
485
+ layers,
486
+ tilesets: mapArray(obj.tilesets, source, "tilesets", (item, itemPath) => validateTiledTilesetRefData(item, source, itemPath)),
487
+ properties: validateTiledPropertiesArray(obj.properties, source, "properties")
488
+ };
489
+ };
538
490
  /**
539
- * Validates a standalone `.tsj` tileset file's root object.
540
- * @internal
541
- */
542
- function validateTiledTilesetFileData(raw, source) {
543
- return validateTiledTilesetData(expectObject(raw, source, ''), source, '');
544
- }
491
+ * Validates a standalone `.tsj` tileset file's root object.
492
+ * @internal
493
+ */
494
+ const validateTiledTilesetFileData = (raw, source) => validateTiledTilesetData(expectObject(raw, source, ""), source, "");
545
495
 
496
+ //#endregion
546
497
  export { TiledFormatError, checkTiledLayerInfiniteConsistency, validateTiledAnimationFrameData, validateTiledLayerData, validateTiledMapData, validateTiledObjectData, validateTiledPropertyData, validateTiledTileData, validateTiledTilesetData, validateTiledTilesetFileData, validateTiledTilesetRefData };
547
- //# sourceMappingURL=validate.js.map
498
+ //# sourceMappingURL=validate.js.map