@seatmap-fyi/map-domain 0.1.0-alpha.1 → 0.1.0-alpha.29

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 (62) hide show
  1. package/dist/catalog.d.ts +10 -3
  2. package/dist/catalog.js +66 -10
  3. package/dist/categories.d.ts +26 -0
  4. package/dist/categories.js +168 -0
  5. package/dist/editor-state.d.ts +49 -0
  6. package/dist/editor-state.js +266 -0
  7. package/dist/floors.d.ts +19 -0
  8. package/dist/floors.js +68 -0
  9. package/dist/geometry/boundary.d.ts +1 -1
  10. package/dist/geometry/boundary.js +10 -12
  11. package/dist/geometry/curve-warnings.d.ts +1 -1
  12. package/dist/geometry/curve-warnings.js +3 -5
  13. package/dist/geometry/decoration-bounds.d.ts +4 -0
  14. package/dist/geometry/decoration-bounds.js +42 -0
  15. package/dist/geometry/ellipse.js +4 -12
  16. package/dist/geometry/geometry.d.ts +12 -3
  17. package/dist/geometry/geometry.js +35 -26
  18. package/dist/geometry/polygon-curves.d.ts +12 -0
  19. package/dist/geometry/polygon-curves.js +132 -0
  20. package/dist/geometry/primitives.d.ts +1 -1
  21. package/dist/geometry/primitives.js +2 -3
  22. package/dist/geometry/seat-shape.d.ts +24 -0
  23. package/dist/geometry/seat-shape.js +101 -0
  24. package/dist/geometry/seating-layout.d.ts +14 -3
  25. package/dist/geometry/seating-layout.js +91 -19
  26. package/dist/geometry/units.d.ts +1 -0
  27. package/dist/geometry/units.js +2 -0
  28. package/dist/geometry/venue-outline.d.ts +2 -2
  29. package/dist/geometry/venue-outline.js +8 -21
  30. package/dist/identity.d.ts +4 -1
  31. package/dist/identity.js +36 -10
  32. package/dist/issues.d.ts +9 -2
  33. package/dist/issues.js +8 -6
  34. package/dist/labels.d.ts +12 -1
  35. package/dist/labels.js +76 -11
  36. package/dist/layers.d.ts +26 -0
  37. package/dist/layers.js +86 -0
  38. package/dist/media.d.ts +27 -0
  39. package/dist/media.js +89 -0
  40. package/dist/physical-document.interface.d.ts +518 -0
  41. package/dist/{types.js → physical-document.interface.js} +71 -0
  42. package/dist/preview.d.ts +15 -0
  43. package/dist/preview.js +199 -0
  44. package/dist/reference.js +1 -1
  45. package/dist/row-segments.d.ts +30 -0
  46. package/dist/row-segments.js +112 -0
  47. package/dist/schema.d.ts +1192 -68
  48. package/dist/schema.js +372 -96
  49. package/dist/seat-proximity.d.ts +4 -0
  50. package/dist/seat-proximity.js +119 -0
  51. package/dist/sections.d.ts +23 -0
  52. package/dist/sections.js +149 -0
  53. package/dist/selling.d.ts +34 -0
  54. package/dist/selling.js +148 -0
  55. package/dist/spacing-repairs.d.ts +31 -0
  56. package/dist/spacing-repairs.js +168 -0
  57. package/dist/table-layout.d.ts +29 -0
  58. package/dist/table-layout.js +134 -0
  59. package/dist/validation.d.ts +3 -1
  60. package/dist/validation.js +124 -74
  61. package/package.json +63 -3
  62. package/dist/types.d.ts +0 -313
package/dist/schema.js CHANGED
@@ -1,19 +1,20 @@
1
- import { DocumentLimits, NumberingScheme, LabelDirection, RowLabelPosition, SeatingKind, CurveMode, DecorationKind, LabelAlignment, RowAlignment, SectionOutlineRole, AreaKind, ShapeKind, VenueGlyph, } from "./types.js";
1
+ import { polygonContour, polygonContourVertexCount, PolygonVertexLimit, PolygonCornerRadiusMaxM, } from "./geometry/polygon-curves.js";
2
+ import { DocumentLimits, TicketRestriction, TableBookingMode, TableChairDistribution, StandingBookingMode, SeatShape, TicketOptionLimit, NumberingScheme, LabelDirection, RowLabelPosition, AccessNeed, SeatingKind, CurveMode, DecorationKind, LabelAlignment, RowAlignment, RowEnds, RowJoin, SectionOutlineRole, AreaKind, ShapeKind, VenueGlyph, } from "./physical-document.interface.js";
2
3
  import { z } from "zod";
4
+ import { tableSellingValid, standingSellingValid } from "./selling.js";
5
+ import { ticketOptionNameKey } from "./categories.js";
3
6
  import { issue, IssueCode } from "./issues.js";
4
- import { footprint, generateGroup, project, worldMatrices, } from "./geometry/geometry.js";
5
- const uuid = z
6
- .string()
7
- .regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
7
+ import { footprint, generateGroup, project, worldMatrices } from "./geometry/geometry.js";
8
+ const uuid = z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
8
9
  const finite = z.number().finite();
9
10
  const coordinate = finite.min(-10000).max(10000);
10
11
  const dimension = finite.min(0.001).max(10000);
11
12
  const nonNegative = finite.min(0).max(10000);
12
13
  const angle = finite.min(-180).lt(180);
14
+ const unsupportedText = /[\u0000-\u001f\u007f-\u009f]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u;
13
15
  const text = (limit, multiline = false) => z
14
16
  .string()
15
- .refine((v) => Array.from(v).length <= limit &&
16
- !/[\u0000-\u001f\u007f-\u009f]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u.test(multiline ? v.replace(/\n/g, "") : v), "Text exceeds its limit or contains unsupported control/surrogate characters.")
17
+ .refine((v) => Array.from(v).length <= limit && !unsupportedText.test(multiline ? v.replace(/\n/g, "") : v), "Text exceeds its limit or contains unsupported control/surrogate characters.")
17
18
  .meta({
18
19
  maxLength: limit,
19
20
  description: multiline
@@ -27,6 +28,11 @@ const name = text(120)
27
28
  description: "Nonempty, trimmed name; at most 120 Unicode code points. Control characters and unpaired surrogates are rejected.",
28
29
  });
29
30
  const label = text(80);
31
+ // An inherited row name can be materialized when splitting, connecting or copying a row.
32
+ const rowLabelText = z
33
+ .string()
34
+ .refine((value) => !unsupportedText.test(value), "Use single-line text without control characters.")
35
+ .describe("Row label text without control characters or unpaired surrogates.");
30
36
  const point = z.strictObject({ x: coordinate, y: coordinate });
31
37
  const size = z.strictObject({ width: dimension, height: dimension });
32
38
  const transform = z.strictObject({
@@ -38,41 +44,106 @@ const transform = z.strictObject({
38
44
  const ring = z
39
45
  .array(point)
40
46
  .min(3)
41
- .max(10000)
47
+ .max(PolygonVertexLimit)
42
48
  .refine((v) => v[0].x !== v[v.length - 1].x || v[0].y !== v[v.length - 1].y, "Rings close implicitly; do not repeat the first vertex.")
43
49
  .describe("Implicitly closed ring; the last vertex must not repeat the first.");
44
- const polygon = z.strictObject({
50
+ const polygon = z
51
+ .strictObject({
45
52
  outer: ring,
46
53
  holes: z.array(ring).max(10000),
54
+ edgeCurvature: z.array(finite.min(-100).max(100)).max(PolygonVertexLimit).optional(),
55
+ cornerRounding: finite.min(0).max(100).optional(),
56
+ cornerRadiusM: nonNegative.max(PolygonCornerRadiusMaxM).optional(),
57
+ })
58
+ .superRefine((value, context) => {
59
+ if (value.edgeCurvature && value.edgeCurvature.length !== value.outer.length) {
60
+ context.addIssue({
61
+ code: "custom",
62
+ path: ["edgeCurvature"],
63
+ message: "Provide one curvature value per outer side.",
64
+ });
65
+ return;
66
+ }
67
+ if (value.cornerRounding !== undefined && value.cornerRadiusM !== undefined) {
68
+ context.addIssue({ code: "custom", path: ["cornerRadiusM"], message: "Use one corner rounding mode." });
69
+ return;
70
+ }
71
+ if (polygonContourVertexCount(value) > PolygonVertexLimit)
72
+ context.addIssue({
73
+ code: "custom",
74
+ path: ["edgeCurvature"],
75
+ message: "The boundary exceeds the 1mm / 10,000-vertex curve limit.",
76
+ });
47
77
  });
78
+ export const hexColourSchema = z.string().regex(/^#[0-9a-fA-F]{6}$/);
48
79
  const paint = z.strictObject({
49
- color: z.string().regex(/^#[0-9a-fA-F]{6}$/),
80
+ color: hexColourSchema,
50
81
  opacity: finite.min(0).max(1),
51
82
  });
52
83
  const sequence = z
53
84
  .strictObject({
54
85
  scheme: z.enum(NumberingScheme),
55
- startAt: finite.int().min(1).max(1e9),
86
+ startAt: finite.int().min(0).max(1e9),
56
87
  direction: z.enum(LabelDirection),
57
88
  prefix: text(32).optional(),
58
89
  suffix: text(32).optional(),
90
+ numberFrom: z.enum(["first", "last"]).optional(),
91
+ lastAt: finite.int().min(0).max(1e9).optional(),
59
92
  })
60
- .refine((v) => v.scheme !== NumberingScheme.Odd || v.startAt % 2 === 1, "Odd numbering must start at an odd integer.")
61
- .refine((v) => v.scheme !== NumberingScheme.Even || v.startAt % 2 === 0, "Even numbering must start at an even integer.")
62
- .describe("Odd/even numbering requires a matching odd/even startAt value.");
93
+ .superRefine((value, context) => {
94
+ if (value.numberFrom === "last" && value.lastAt === undefined)
95
+ context.addIssue({
96
+ code: "custom",
97
+ path: ["lastAt"],
98
+ message: "Last-seat anchoring requires a last number.",
99
+ });
100
+ if (value.scheme === NumberingScheme.Roman && (value.startAt > 999 || (value.lastAt ?? 0) > 100999))
101
+ context.addIssue({
102
+ code: "custom",
103
+ path: ["startAt"],
104
+ message: "Roman start numbers must be at most 999.",
105
+ });
106
+ });
63
107
  const labelStyle = z.strictObject({
64
108
  visible: z.boolean(),
65
109
  fontSizeM: dimension,
110
+ style: z.enum(["plain", "pill"]).optional(),
111
+ rotationDeg: angle.optional(),
112
+ color: hexColourSchema.optional(),
113
+ });
114
+ const rowLabelStyle = labelStyle.extend({
115
+ position: z.enum(RowLabelPosition),
116
+ style: z.enum(["plain", "pill"]).optional(),
117
+ rotationDeg: angle.optional(),
118
+ });
119
+ export const buyerPhotoSchema = z.strictObject({ assetId: uuid });
120
+ export const seatPresentationSchema = z.strictObject({
121
+ buyerPhoto: buyerPhotoSchema.optional(),
122
+ gap: z.boolean().optional(),
123
+ buyerNote: text(160).optional(),
124
+ labelStyle: labelStyle.optional(),
66
125
  });
126
+ export const rowPresentationSchema = z.strictObject({
127
+ buyerPhoto: buyerPhotoSchema.optional(),
128
+ bookingLabel: rowLabelText.optional(),
129
+ buyerNoun: text(80).optional(),
130
+ buyerNote: text(160).optional(),
131
+ labelStyle: rowLabelStyle.optional(),
132
+ });
133
+ export const seatShapeSchema = z.enum(SeatShape);
67
134
  const seat = z.strictObject({
135
+ ...seatPresentationSchema.shape,
136
+ seatShape: seatShapeSchema.optional(),
68
137
  id: uuid,
138
+ categoryId: uuid.nullable().optional(),
69
139
  labelOverride: label.optional(),
70
140
  attributes: z
71
141
  .strictObject({
72
- accessible: z.boolean().optional(),
142
+ wheelchair: z.enum(["seat", "space"]).optional(),
143
+ accessNeeds: z.array(z.enum(AccessNeed)).max(Object.keys(AccessNeed).length).optional(),
144
+ obstructedView: z.boolean().optional(),
145
+ premium: z.boolean().optional(),
73
146
  restrictedView: z.boolean().optional(),
74
- hearingAssistance: z.boolean().optional(),
75
- semiAmbulatory: z.boolean().optional(),
76
147
  companionForSeatId: uuid.optional(),
77
148
  })
78
149
  .optional(),
@@ -84,21 +155,56 @@ const seat = z.strictObject({
84
155
  })
85
156
  .optional(),
86
157
  });
158
+ export const rowLayoutSchema = z.strictObject({
159
+ originM: point,
160
+ seatPitchM: dimension,
161
+ curveDeg: finite.min(-360).max(360),
162
+ rotationDeg: finite.min(-180).max(180),
163
+ seatRotationOffsetDeg: finite.min(-180).max(180).optional(),
164
+ });
87
165
  const row = z.strictObject({
166
+ zIndex: finite.int().min(-2147483648).max(2147483647).optional(),
167
+ ...rowPresentationSchema.shape,
88
168
  id: uuid,
89
- labelOverride: label.optional(),
169
+ categoryId: uuid.nullable().optional(),
170
+ labelOverride: rowLabelText.optional(),
90
171
  offsetM: point.optional(),
91
172
  seatSequenceOverride: sequence.optional(),
173
+ layout: rowLayoutSchema.optional(),
174
+ aisleSeats: z.enum(RowEnds).optional(),
92
175
  seats: z.array(seat).min(1).max(DocumentLimits.PhysicalSeats),
93
176
  });
94
177
  const drawable = {
178
+ floorId: uuid.describe("Physical floor identity when the map defines levels.").optional(),
95
179
  id: uuid,
96
180
  parentId: uuid.nullable(),
97
181
  transform,
98
182
  zIndex: finite.int().min(-2147483648).max(2147483647),
99
183
  };
184
+ const partySize = {
185
+ minGuests: finite.int().min(1).max(DocumentLimits.PhysicalSeats),
186
+ maxGuests: finite.int().min(1).max(DocumentLimits.PhysicalSeats),
187
+ };
188
+ const tableSelling = z.discriminatedUnion("mode", [
189
+ z.strictObject({
190
+ mode: z.enum([TableBookingMode.Individual, TableBookingMode.Whole]),
191
+ }),
192
+ z.strictObject({ mode: z.literal(TableBookingMode.Party), ...partySize }),
193
+ ]);
194
+ const standingSelling = z.discriminatedUnion("mode", [
195
+ z.strictObject({
196
+ mode: z.enum([StandingBookingMode.Standing, StandingBookingMode.Whole]),
197
+ wheelchairPlaces: finite.int().min(0).max(2147483647),
198
+ }),
199
+ z.strictObject({
200
+ mode: z.literal(StandingBookingMode.Party),
201
+ wheelchairPlaces: finite.int().min(0).max(2147483647),
202
+ ...partySize,
203
+ }),
204
+ ]);
100
205
  const groupBase = {
101
206
  ...drawable,
207
+ categoryId: uuid.nullable().optional(),
102
208
  name,
103
209
  sectionId: uuid.nullable(),
104
210
  seatSizeM: size,
@@ -108,17 +214,54 @@ const groupBase = {
108
214
  const rowsLabels = z.strictObject({
109
215
  rows: sequence,
110
216
  seats: sequence,
111
- rowStyle: z.strictObject({
112
- visible: z.boolean(),
113
- fontSizeM: dimension,
114
- position: z.enum(RowLabelPosition),
115
- }),
217
+ rowStyle: rowLabelStyle,
218
+ });
219
+ export const segmentedRowSchema = z.strictObject({
220
+ id: uuid,
221
+ label: rowLabelText.min(1, "Use a nonempty connected row label."),
222
+ sequence,
223
+ qualifySeatLabels: z.boolean().optional(),
224
+ smoothCorners: z.boolean().optional(),
225
+ parts: z
226
+ .array(z.strictObject({
227
+ rowId: uuid,
228
+ joinBefore: z.enum(RowJoin).nullable(),
229
+ labelOverride: rowLabelText.optional(),
230
+ }))
231
+ .min(1)
232
+ .max(DocumentLimits.PhysicalSeats),
116
233
  });
234
+ const inventoryNaming = { code: label, name: label.optional() };
117
235
  const tableLabels = z.strictObject({
118
- table: label,
236
+ ...inventoryNaming,
119
237
  chairs: sequence,
120
238
  tableStyle: labelStyle,
121
239
  });
240
+ const roundTableRecipe = z.strictObject({
241
+ diameterM: dimension,
242
+ chairGapM: nonNegative,
243
+ startAngleDeg: angle,
244
+ automaticSize: z.boolean().optional(),
245
+ seatArcDeg: z.number().finite().min(120).max(360).optional(),
246
+ });
247
+ const rectangularTableRecipe = z.strictObject({
248
+ widthM: dimension,
249
+ depthM: dimension,
250
+ chairGapM: nonNegative,
251
+ chairPitchM: dimension.optional(),
252
+ chairDistribution: z.enum(TableChairDistribution).optional(),
253
+ });
254
+ const longTableLayout = z
255
+ .strictObject({
256
+ recipe: rectangularTableRecipe,
257
+ sides: z.strictObject({
258
+ top: z.boolean(),
259
+ bottom: z.boolean(),
260
+ left: z.boolean(),
261
+ right: z.boolean(),
262
+ }),
263
+ })
264
+ .refine((value) => Object.values(value.sides).some(Boolean), "Choose at least one table side.");
122
265
  export const groupSchema = z.discriminatedUnion("kind", [
123
266
  z.strictObject({
124
267
  ...groupBase,
@@ -161,12 +304,9 @@ export const groupSchema = z.discriminatedUnion("kind", [
161
304
  .strictObject({
162
305
  ...groupBase,
163
306
  kind: z.literal(SeatingKind.Rectangular),
164
- recipe: z.strictObject({
165
- widthM: dimension,
166
- depthM: dimension,
167
- chairGapM: nonNegative,
168
- chairPitchM: dimension.optional(),
169
- }),
307
+ selling: tableSelling.optional(),
308
+ recipe: rectangularTableRecipe,
309
+ roundLayout: roundTableRecipe.optional(),
170
310
  labels: tableLabels,
171
311
  chairsBySide: z.strictObject({
172
312
  top: z.array(seat).max(DocumentLimits.PhysicalSeats),
@@ -175,18 +315,19 @@ export const groupSchema = z.discriminatedUnion("kind", [
175
315
  left: z.array(seat).max(DocumentLimits.PhysicalSeats),
176
316
  }),
177
317
  })
178
- .refine((v) => Object.values(v.chairsBySide).some((s) => s.length > 0), "A table needs at least one chair."),
179
- z.strictObject({
318
+ .refine((v) => Object.values(v.chairsBySide).some((s) => s.length > 0), "A table needs at least one chair.")
319
+ .refine(tableSellingValid, "Table selling requires valid guest limits and no personal chair settings."),
320
+ z
321
+ .strictObject({
180
322
  ...groupBase,
181
323
  kind: z.literal(SeatingKind.Round),
182
- recipe: z.strictObject({
183
- diameterM: dimension,
184
- chairGapM: nonNegative,
185
- startAngleDeg: angle,
186
- }),
324
+ selling: tableSelling.optional(),
325
+ recipe: roundTableRecipe,
326
+ longLayout: longTableLayout.optional(),
187
327
  labels: tableLabels,
188
328
  chairs: z.array(seat).min(1).max(DocumentLimits.PhysicalSeats),
189
- }),
329
+ })
330
+ .refine(tableSellingValid, "Table selling requires valid guest limits and no personal chair settings."),
190
331
  ]);
191
332
  export const decorationStyleSchema = z.strictObject({
192
333
  fill: paint.optional(),
@@ -242,11 +383,11 @@ const decoration = z.discriminatedUnion("kind", [
242
383
  opacity: finite.min(0).max(1),
243
384
  }),
244
385
  ]);
245
- const area = z.strictObject({
386
+ const areaBase = {
246
387
  ...drawable,
247
- kind: z.literal(AreaKind.GeneralAdmission),
388
+ ...inventoryNaming,
389
+ categoryId: uuid.nullable().optional(),
248
390
  sectionId: uuid.nullable(),
249
- label,
250
391
  labelStyle,
251
392
  capacity: finite.int().min(1).max(2147483647),
252
393
  shape: z.discriminatedUnion("kind", [
@@ -260,8 +401,67 @@ const area = z.strictObject({
260
401
  .refine((v) => v.cornerRadiusM <= Math.min(v.widthM, v.heightM) / 2),
261
402
  z.strictObject({ kind: z.literal(ShapeKind.Polygon), boundary: polygon }),
262
403
  ]),
404
+ };
405
+ const area = z.discriminatedUnion("kind", [
406
+ z
407
+ .strictObject({
408
+ ...areaBase,
409
+ kind: z.literal(AreaKind.GeneralAdmission),
410
+ selling: standingSelling.optional(),
411
+ })
412
+ .refine(standingSellingValid, "Standing selling must fit its capacity and one-party limit."),
413
+ z.strictObject({ ...areaBase, kind: z.literal(AreaKind.Booth) }),
414
+ ]);
415
+ const templatePrice = finite.min(0).max(1_000_000_000);
416
+ export const ticketOptionSchema = z.strictObject({
417
+ id: uuid,
418
+ name: text(80).refine((value) => value.length > 0 && value === value.trim(), "Use a trimmed, nonempty option name."),
419
+ price: templatePrice,
420
+ restriction: z.enum(TicketRestriction).optional(),
421
+ guidance: text(240, true).optional(),
422
+ });
423
+ export const categorySchema = z
424
+ .strictObject({
425
+ id: uuid,
426
+ name,
427
+ color: hexColourSchema,
428
+ defaultPrice: templatePrice.nullable().optional(),
429
+ onSale: z.boolean().optional(),
430
+ seatShape: seatShapeSchema.optional(),
431
+ ticketOptions: z.array(ticketOptionSchema).max(TicketOptionLimit).optional(),
432
+ })
433
+ .superRefine((category, context) => {
434
+ const names = new Set();
435
+ for (const [index, option] of (category.ticketOptions ?? []).entries()) {
436
+ const key = ticketOptionNameKey(option.name);
437
+ if (names.has(key))
438
+ context.addIssue({
439
+ code: "custom",
440
+ path: ["ticketOptions", index, "name"],
441
+ message: `${option.name} is already an option here`,
442
+ });
443
+ names.add(key);
444
+ }
445
+ });
446
+ export const categoriesSchema = z
447
+ .array(categorySchema)
448
+ .max(1024)
449
+ .superRefine((categories, context) => {
450
+ const ids = new Set();
451
+ for (const [index, category] of categories.entries()) {
452
+ for (const id of [category.id, ...(category.ticketOptions ?? []).map((option) => option.id)]) {
453
+ if (ids.has(id))
454
+ context.addIssue({
455
+ code: "custom",
456
+ path: [index],
457
+ message: "Category and ticket-option identities must be unique.",
458
+ });
459
+ ids.add(id);
460
+ }
461
+ }
263
462
  });
264
463
  export const documentSchema = z.strictObject({
464
+ buyerPhoto: buyerPhotoSchema.optional(),
265
465
  schemaVersion: z.literal(1),
266
466
  mapId: uuid,
267
467
  name,
@@ -272,10 +472,26 @@ export const documentSchema = z.strictObject({
272
472
  rotation: z.literal("clockwise"),
273
473
  }),
274
474
  background: paint,
475
+ categories: categoriesSchema.optional(),
476
+ floors: z
477
+ .array(z.strictObject({ id: uuid, name, baseHeightM: coordinate }))
478
+ .min(1)
479
+ .max(1024)
480
+ .describe("Physical levels in display order. When present, every section, collection and drawable must reference one of these floor identities.")
481
+ .optional(),
482
+ zones: z
483
+ .array(z.strictObject({ id: uuid, name, color: hexColourSchema }))
484
+ .max(1024)
485
+ .describe("Section groups in display order, independent of physical floors.")
486
+ .optional(),
275
487
  sections: z
276
488
  .array(z.strictObject({
489
+ buyerPhoto: buyerPhotoSchema.optional(),
277
490
  id: uuid,
278
491
  label,
492
+ floorId: uuid.describe("Physical floor identity when the map defines levels.").optional(),
493
+ zoneId: uuid.describe("Optional chart-wide zone membership.").optional(),
494
+ categoryId: uuid.nullable().optional(),
279
495
  displayLabel: text(80, true).optional(),
280
496
  outline: polygon.optional(),
281
497
  outlineRole: z.enum(SectionOutlineRole).optional(),
@@ -292,17 +508,13 @@ export const documentSchema = z.strictObject({
292
508
  .max(1024),
293
509
  collections: z.array(z.strictObject({ ...drawable, name })).max(10000),
294
510
  seatingGroups: z.array(groupSchema).max(DocumentLimits.PhysicalSeats),
511
+ segmentedRows: z.array(segmentedRowSchema).max(DocumentLimits.PhysicalSeats).optional(),
295
512
  areas: z.array(area).max(10000),
296
513
  decorations: z.array(decoration).max(10000),
297
514
  assets: z
298
515
  .array(z.strictObject({
299
516
  id: uuid,
300
- mimeType: z.enum([
301
- "image/png",
302
- "image/jpeg",
303
- "image/webp",
304
- "image/svg+xml",
305
- ]),
517
+ mimeType: z.enum(["image/png", "image/jpeg", "image/webp", "image/svg+xml"]),
306
518
  }))
307
519
  .max(256),
308
520
  });
@@ -315,14 +527,13 @@ export const paintSchema = paint;
315
527
  export const transformSchema = transform;
316
528
  export const mapNameSchema = name;
317
529
  export const sectionSchema = documentSchema.shape.sections.element;
530
+ export const floorsSchema = documentSchema.shape.floors.unwrap();
531
+ export const zonesSchema = documentSchema.shape.zones.unwrap();
318
532
  export const uuidSchema = uuid;
319
533
  export const dimensionSchema = dimension;
320
534
  export const coordinateSchema = coordinate;
321
535
  export const rotationSchema = angle;
322
- export const positiveCountSchema = finite
323
- .int()
324
- .min(1)
325
- .max(DocumentLimits.PhysicalSeats);
536
+ export const positiveCountSchema = finite.int().min(1).max(DocumentLimits.PhysicalSeats);
326
537
  export const labelSequenceSchema = sequence;
327
538
  export const inventoryLabelSchema = label;
328
539
  export const attributesSchema = seat.shape.attributes;
@@ -341,8 +552,7 @@ export var DocumentParseStatus;
341
552
  DocumentParseStatus["Rejected"] = "rejected";
342
553
  })(DocumentParseStatus || (DocumentParseStatus = {}));
343
554
  export function groupSeatCount(group) {
344
- return group.kind === SeatingKind.Straight ||
345
- group.kind === SeatingKind.Curved
555
+ return group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved
346
556
  ? group.rows.reduce((n, r) => n + r.seats.length, 0)
347
557
  : group.kind === SeatingKind.Round
348
558
  ? group.chairs.length
@@ -358,33 +568,90 @@ export function* seatSlots(group) {
358
568
  for (const side of ["top", "right", "bottom", "left"])
359
569
  yield* group.chairsBySide[side];
360
570
  }
571
+ const inventoryCounts = new WeakMap();
572
+ function slotInventoryCount(slots) {
573
+ let count = inventoryCounts.get(slots);
574
+ if (count === undefined) {
575
+ count = 0;
576
+ for (const slot of slots)
577
+ if (!slot.gap)
578
+ count++;
579
+ inventoryCounts.set(slots, count);
580
+ }
581
+ return count;
582
+ }
583
+ export function groupInventoryCount(group) {
584
+ if ("rows" in group)
585
+ return group.rows.reduce((sum, row) => sum + slotInventoryCount(row.seats), 0);
586
+ if ("chairs" in group)
587
+ return slotInventoryCount(group.chairs);
588
+ return Object.values(group.chairsBySide).reduce((sum, seats) => sum + slotInventoryCount(seats), 0);
589
+ }
361
590
  export function capacity(document) {
362
- return {
363
- physicalSeats: document.seatingGroups.reduce((n, g) => n + groupSeatCount(g), 0),
364
- gaQuantity: document.areas.reduce((n, a) => n + a.capacity, 0),
365
- };
591
+ let physicalSeats = document.seatingGroups.reduce((sum, group) => sum + groupInventoryCount(group), 0);
592
+ let gaQuantity = 0;
593
+ for (const area of document.areas) {
594
+ if (area.kind === AreaKind.Booth)
595
+ physicalSeats++;
596
+ else
597
+ gaQuantity += area.capacity;
598
+ }
599
+ return { physicalSeats, gaQuantity };
366
600
  }
367
601
  export function structuralIssues(document, changedGroups) {
368
602
  const errors = [];
369
603
  const ids = new Set([document.mapId]);
370
604
  const add = (id) => {
371
605
  if (ids.has(id))
372
- errors.push(issue(IssueCode.DuplicateId, "Physical identities must be unique.", [
373
- id,
374
- ]));
606
+ errors.push(issue(IssueCode.DuplicateId, "Physical identities must be unique.", [id]));
375
607
  ids.add(id);
376
608
  };
609
+ const floors = new Set((document.floors ?? []).map((floor) => floor.id));
610
+ for (const floor of document.floors ?? [])
611
+ add(floor.id);
612
+ for (const member of [
613
+ ...document.sections,
614
+ ...document.collections,
615
+ ...document.seatingGroups,
616
+ ...document.areas,
617
+ ...document.decorations,
618
+ ]) {
619
+ if (member.floorId ? !floors.has(member.floorId) : floors.size > 0) {
620
+ errors.push(issue(IssueCode.UnknownFloor, "Physical objects must reference an existing floor when levels are defined.", [
621
+ member.id,
622
+ ]));
623
+ }
624
+ }
377
625
  const sections = new Set(document.sections.map((s) => s.id));
378
626
  const parents = new Map(document.collections.map((c) => [c.id, c]));
627
+ const floorById = new Map([
628
+ ...document.sections,
629
+ ...document.collections,
630
+ ...document.seatingGroups,
631
+ ...document.areas,
632
+ ...document.decorations,
633
+ ].map((object) => [object.id, object.floorId]));
379
634
  let vertices = 0;
380
- const visitPolygon = (p) => {
381
- if (p)
382
- vertices += p.outer.length + p.holes.reduce((n, h) => n + h.length, 0);
635
+ const visitPolygon = (polygon) => {
636
+ if (polygon)
637
+ vertices += polygonContourVertexCount(polygon) + polygon.holes.reduce((total, hole) => total + hole.length, 0);
383
638
  };
639
+ const zones = new Set();
640
+ for (const zone of document.zones ?? []) {
641
+ add(zone.id);
642
+ zones.add(zone.id);
643
+ }
384
644
  for (const s of document.sections) {
385
645
  add(s.id);
646
+ if (s.zoneId && !zones.has(s.zoneId))
647
+ errors.push(issue(IssueCode.UnknownZone, "Section zone reference does not exist.", [s.id]));
386
648
  visitPolygon(s.outline);
387
649
  }
650
+ for (const category of document.categories ?? []) {
651
+ add(category.id);
652
+ for (const option of category.ticketOptions ?? [])
653
+ add(option.id);
654
+ }
388
655
  for (const a of document.assets)
389
656
  add(a.id);
390
657
  for (const object of [
@@ -394,18 +661,23 @@ export function structuralIssues(document, changedGroups) {
394
661
  ...document.decorations,
395
662
  ]) {
396
663
  add(object.id);
664
+ if ("sectionId" in object && object.sectionId !== null && !sections.has(object.sectionId))
665
+ errors.push(issue(IssueCode.UnknownSection, "Section reference does not exist.", [object.id]));
397
666
  if ("sectionId" in object &&
398
667
  object.sectionId !== null &&
399
- !sections.has(object.sectionId))
400
- errors.push(issue(IssueCode.UnknownSection, "Section reference does not exist.", [
401
- object.id,
402
- ]));
668
+ sections.has(object.sectionId) &&
669
+ floorById.get(object.sectionId) !== object.floorId)
670
+ errors.push(issue(IssueCode.UnknownSection, "A section and its contents must belong to the same floor.", [object.id]));
671
+ if (object.parentId && parents.has(object.parentId) && floorById.get(object.parentId) !== object.floorId)
672
+ errors.push(issue(IssueCode.InvalidParent, "A collection and its contents must belong to the same floor.", [object.id]));
403
673
  const visited = new Set([object.id]);
404
674
  let parent = object.parentId;
405
675
  let depth = 0;
406
676
  while (parent) {
407
677
  if (visited.has(parent) || !parents.has(parent) || ++depth > 64) {
408
- errors.push(issue(IssueCode.InvalidParent, "Parent must be an existing acyclic collection, within depth 64.", [object.id]));
678
+ errors.push(issue(IssueCode.InvalidParent, "Parent must be an existing acyclic collection, within depth 64.", [
679
+ object.id,
680
+ ]));
409
681
  break;
410
682
  }
411
683
  visited.add(parent);
@@ -424,6 +696,21 @@ export function structuralIssues(document, changedGroups) {
424
696
  for (const s of generateGroup(g))
425
697
  add(s.id);
426
698
  }
699
+ const rowOwners = new Map(document.seatingGroups.flatMap((group) => "rows" in group ? group.rows.map((row) => [row.id, { group, row }]) : []));
700
+ const assignedRows = new Set();
701
+ for (const logical of document.segmentedRows ?? []) {
702
+ add(logical.id);
703
+ for (let index = 0; index < logical.parts.length; index++) {
704
+ const part = logical.parts[index];
705
+ const owner = rowOwners.get(part.rowId);
706
+ if (!owner ||
707
+ assignedRows.has(part.rowId) ||
708
+ !owner.row.layout ||
709
+ (index === 0 ? part.joinBefore !== null : part.joinBefore === null))
710
+ errors.push(issue(IssueCode.InvalidStructure, "Each row part must have independent geometry, one logical owner and a valid join.", [logical.id, part.rowId]));
711
+ assignedRows.add(part.rowId);
712
+ }
713
+ }
427
714
  for (const a of document.areas)
428
715
  if (a.shape.kind === ShapeKind.Polygon)
429
716
  visitPolygon(a.shape.boundary);
@@ -433,17 +720,19 @@ export function structuralIssues(document, changedGroups) {
433
720
  else if (d.kind === DecorationKind.Polygon)
434
721
  visitPolygon(d.boundary);
435
722
  const counts = capacity(document);
436
- if (counts.physicalSeats > DocumentLimits.PhysicalSeats ||
723
+ if (document.seatingGroups.reduce((total, group) => total + groupSeatCount(group), 0) +
724
+ document.areas.filter((area) => area.kind === AreaKind.Booth).length >
725
+ DocumentLimits.PhysicalSeats ||
437
726
  !Number.isSafeInteger(counts.gaQuantity + counts.physicalSeats) ||
438
727
  vertices > 100000)
439
728
  errors.push(issue(IssueCode.Limit, "Document exceeds its inventory, capacity or vertex safety limit.", [document.mapId]));
440
729
  if (errors.length)
441
730
  return errors;
442
731
  const matrices = worldMatrices(document);
443
- const within = (p) => Number.isFinite(p.x) &&
444
- Number.isFinite(p.y) &&
445
- Math.abs(p.x) <= 10000 &&
446
- Math.abs(p.y) <= 10000;
732
+ const within = (p) => Number.isFinite(p.x) && Number.isFinite(p.y) && Math.abs(p.x) <= 10000 && Math.abs(p.y) <= 10000;
733
+ for (const section of document.sections)
734
+ if (section.outline && polygonContour(section.outline).outer.some((point) => !within(point)))
735
+ errors.push(issue(IssueCode.WorldBounds, "Derived section geometry exceeds its safety bounds.", [section.id]));
447
736
  for (const g of document.seatingGroups) {
448
737
  if (changedGroups && !changedGroups.has(g.id))
449
738
  continue;
@@ -457,23 +746,20 @@ export function structuralIssues(document, changedGroups) {
457
746
  if (d.kind === DecorationKind.Line)
458
747
  points = d.pointsM;
459
748
  else if (d.kind === DecorationKind.Polygon)
460
- points = [...d.boundary.outer, ...d.boundary.holes.flat()];
461
- else if (d.kind === AreaKind.GeneralAdmission &&
462
- d.shape.kind === ShapeKind.Polygon)
463
- points = [...d.shape.boundary.outer, ...d.shape.boundary.holes.flat()];
749
+ points = [...polygonContour(d.boundary).outer, ...d.boundary.holes.flat()];
750
+ else if ((d.kind === AreaKind.GeneralAdmission || d.kind === AreaKind.Booth) && d.shape.kind === ShapeKind.Polygon)
751
+ points = [...polygonContour(d.shape.boundary).outer, ...d.shape.boundary.holes.flat()];
464
752
  else {
465
753
  const w = d.kind === DecorationKind.Circle
466
754
  ? d.radiusM * 2
467
- : d.kind === AreaKind.GeneralAdmission &&
468
- d.shape.kind === ShapeKind.Rectangle
755
+ : (d.kind === AreaKind.GeneralAdmission || d.kind === AreaKind.Booth) && d.shape.kind === ShapeKind.Rectangle
469
756
  ? d.shape.widthM
470
757
  : "sizeM" in d
471
758
  ? d.sizeM.width
472
759
  : 0;
473
760
  const h = d.kind === DecorationKind.Circle
474
761
  ? d.radiusM * 2
475
- : d.kind === AreaKind.GeneralAdmission &&
476
- d.shape.kind === ShapeKind.Rectangle
762
+ : (d.kind === AreaKind.GeneralAdmission || d.kind === AreaKind.Booth) && d.shape.kind === ShapeKind.Rectangle
477
763
  ? d.shape.heightM
478
764
  : "sizeM" in d
479
765
  ? d.sizeM.height
@@ -493,9 +779,7 @@ export function structuralIssues(document, changedGroups) {
493
779
  export function parsePhysicalDocument(input) {
494
780
  let raw = input;
495
781
  try {
496
- if (typeof raw !== "string" &&
497
- new TextEncoder().encode(JSON.stringify(raw)).byteLength >
498
- DocumentLimits.JsonBytes)
782
+ if (typeof raw !== "string" && new TextEncoder().encode(JSON.stringify(raw)).byteLength > DocumentLimits.JsonBytes)
499
783
  return {
500
784
  status: DocumentParseStatus.Rejected,
501
785
  issues: [issue(IssueCode.Limit, "Document exceeds 64MiB.", [])],
@@ -512,9 +796,7 @@ export function parsePhysicalDocument(input) {
512
796
  catch {
513
797
  return {
514
798
  status: DocumentParseStatus.Rejected,
515
- issues: [
516
- issue(IssueCode.InvalidJson, "Document is not readable JSON.", []),
517
- ],
799
+ issues: [issue(IssueCode.InvalidJson, "Document is not readable JSON.", [])],
518
800
  };
519
801
  }
520
802
  const result = documentSchema.safeParse(raw);
@@ -523,9 +805,7 @@ export function parsePhysicalDocument(input) {
523
805
  status: DocumentParseStatus.Rejected,
524
806
  issues: result.error.issues
525
807
  .slice(0, 50)
526
- .map((e) => issue(e.path[0] === "schemaVersion"
527
- ? IssueCode.UnsupportedVersion
528
- : IssueCode.InvalidStructure, e.message, [], e.path.map(String).join("."))),
808
+ .map((e) => issue(e.path[0] === "schemaVersion" ? IssueCode.UnsupportedVersion : IssueCode.InvalidStructure, e.message, [], e.path.map(String).join("."))),
529
809
  };
530
810
  const document = result.data;
531
811
  const errors = structuralIssues(document);
@@ -536,17 +816,13 @@ export function parsePhysicalDocument(input) {
536
816
  /** Prepared entity schemas have already passed. Recheck global references and only changed world geometry. */
537
817
  export function validatePreparedDocument(document, changedGroups) {
538
818
  const { seatingGroups, ...metadata } = document;
539
- const result = documentSchema
540
- .omit({ seatingGroups: true })
541
- .safeParse(metadata);
819
+ const result = documentSchema.omit({ seatingGroups: true }).safeParse(metadata);
542
820
  if (!result.success)
543
821
  return result.error.issues
544
822
  .slice(0, 50)
545
823
  .map((error) => issue(IssueCode.InvalidStructure, error.message, [], error.path.map(String).join(".")));
546
824
  if (seatingGroups.length > DocumentLimits.PhysicalSeats)
547
- return [
548
- issue(IssueCode.Limit, "Too many seating owners.", [document.mapId]),
549
- ];
825
+ return [issue(IssueCode.Limit, "Too many seating owners.", [document.mapId])];
550
826
  return structuralIssues(document, changedGroups);
551
827
  }
552
828
  export function serializePhysicalDocument(document) {