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

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.
@@ -0,0 +1,313 @@
1
+ export declare const DocumentLimits: {
2
+ readonly PhysicalSeats: 100000;
3
+ readonly JsonBytes: number;
4
+ };
5
+ export type UUID = string;
6
+ export type PointM = {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ export type SizeM = {
11
+ width: number;
12
+ height: number;
13
+ };
14
+ export type Transform = {
15
+ positionM: PointM;
16
+ rotationDeg: number;
17
+ flipX?: boolean;
18
+ flipY?: boolean;
19
+ };
20
+ export type PolygonM = {
21
+ outer: PointM[];
22
+ holes: PointM[][];
23
+ };
24
+ export type Paint = {
25
+ color: string;
26
+ opacity: number;
27
+ };
28
+ export declare enum NumberingScheme {
29
+ Numeric = "numeric",
30
+ Odd = "odd",
31
+ Even = "even",
32
+ Alphabetic = "alphabetic"
33
+ }
34
+ export declare enum LabelDirection {
35
+ Forward = "forward",
36
+ Reverse = "reverse"
37
+ }
38
+ export type LabelSequence = {
39
+ scheme: NumberingScheme;
40
+ startAt: number;
41
+ direction: LabelDirection;
42
+ prefix?: string;
43
+ suffix?: string;
44
+ };
45
+ export type LabelStyle = {
46
+ visible: boolean;
47
+ fontSizeM: number;
48
+ };
49
+ export declare enum RowLabelPosition {
50
+ Left = "left",
51
+ Right = "right",
52
+ Both = "both"
53
+ }
54
+ export type RowLabelStyle = LabelStyle & {
55
+ position: RowLabelPosition;
56
+ };
57
+ export type SeatAttributes = {
58
+ accessible?: boolean;
59
+ restrictedView?: boolean;
60
+ hearingAssistance?: boolean;
61
+ semiAmbulatory?: boolean;
62
+ companionForSeatId?: UUID;
63
+ };
64
+ export type SeatSlot = {
65
+ id: UUID;
66
+ labelOverride?: string;
67
+ attributes?: SeatAttributes;
68
+ override?: {
69
+ offsetM?: PointM;
70
+ rotationDeltaDeg?: number;
71
+ sizeM?: SizeM;
72
+ };
73
+ };
74
+ export type RowSlot = {
75
+ id: UUID;
76
+ labelOverride?: string;
77
+ offsetM?: PointM;
78
+ seatSequenceOverride?: LabelSequence;
79
+ seats: SeatSlot[];
80
+ };
81
+ export type DrawableBase = {
82
+ id: UUID;
83
+ parentId: UUID | null;
84
+ transform: Transform;
85
+ zIndex: number;
86
+ };
87
+ export type GroupBase = DrawableBase & {
88
+ name: string;
89
+ sectionId: UUID | null;
90
+ seatSizeM: SizeM;
91
+ boundary?: PolygonM;
92
+ seatLabelStyle: LabelStyle;
93
+ };
94
+ export type RowsLabels = {
95
+ rows: LabelSequence;
96
+ seats: LabelSequence;
97
+ rowStyle: RowLabelStyle;
98
+ };
99
+ export declare enum RowAlignment {
100
+ Start = "start",
101
+ Center = "center",
102
+ End = "end"
103
+ }
104
+ export declare enum LabelAlignment {
105
+ Left = "left",
106
+ Center = "center",
107
+ Right = "right"
108
+ }
109
+ export type StraightRows = GroupBase & {
110
+ kind: SeatingKind.Straight;
111
+ recipe: {
112
+ seatPitchM: number;
113
+ rowPitchM: number;
114
+ rowAlignment?: RowAlignment;
115
+ };
116
+ labels: RowsLabels;
117
+ rows: RowSlot[];
118
+ };
119
+ export type CurvedRows = GroupBase & {
120
+ kind: SeatingKind.Curved;
121
+ recipe: {
122
+ innerRadiusM: number;
123
+ axisRatio?: number;
124
+ rowPitchM: number;
125
+ placement: {
126
+ kind: CurveMode.Sweep;
127
+ startAngleDeg: number;
128
+ sweepAngleDeg: number;
129
+ } | {
130
+ kind: CurveMode.Pitch;
131
+ centerAngleDeg: number;
132
+ seatPitchM: number;
133
+ };
134
+ };
135
+ labels: RowsLabels;
136
+ rows: RowSlot[];
137
+ };
138
+ export type TableLabels = {
139
+ table: string;
140
+ chairs: LabelSequence;
141
+ tableStyle: LabelStyle;
142
+ };
143
+ export type RectangularTable = GroupBase & {
144
+ kind: SeatingKind.Rectangular;
145
+ recipe: {
146
+ widthM: number;
147
+ depthM: number;
148
+ chairGapM: number;
149
+ chairPitchM?: number;
150
+ };
151
+ labels: TableLabels;
152
+ chairsBySide: {
153
+ top: SeatSlot[];
154
+ right: SeatSlot[];
155
+ bottom: SeatSlot[];
156
+ left: SeatSlot[];
157
+ };
158
+ };
159
+ export type RoundTable = GroupBase & {
160
+ kind: SeatingKind.Round;
161
+ recipe: {
162
+ diameterM: number;
163
+ chairGapM: number;
164
+ startAngleDeg: number;
165
+ };
166
+ labels: TableLabels;
167
+ chairs: SeatSlot[];
168
+ };
169
+ export type SeatingGroup = StraightRows | CurvedRows | RectangularTable | RoundTable;
170
+ export type GeneralAdmission = DrawableBase & {
171
+ kind: AreaKind.GeneralAdmission;
172
+ sectionId: UUID | null;
173
+ label: string;
174
+ labelStyle: LabelStyle;
175
+ capacity: number;
176
+ shape: {
177
+ kind: ShapeKind.Rectangle;
178
+ widthM: number;
179
+ heightM: number;
180
+ cornerRadiusM: number;
181
+ } | {
182
+ kind: ShapeKind.Polygon;
183
+ boundary: PolygonM;
184
+ };
185
+ };
186
+ export type DecorationStyle = {
187
+ fill?: Paint;
188
+ stroke?: Paint;
189
+ strokeWidthM?: number;
190
+ };
191
+ export type Decoration = DrawableBase & ({
192
+ kind: DecorationKind.Text;
193
+ text: string;
194
+ fontSizeM: number;
195
+ align: LabelAlignment;
196
+ } | {
197
+ kind: DecorationKind.Rectangle;
198
+ sizeM: SizeM;
199
+ cornerRadiusM: number;
200
+ } | {
201
+ kind: DecorationKind.Circle;
202
+ radiusM: number;
203
+ } | {
204
+ kind: DecorationKind.Line;
205
+ pointsM: PointM[];
206
+ } | {
207
+ kind: DecorationKind.Polygon;
208
+ boundary: PolygonM;
209
+ } | {
210
+ kind: DecorationKind.Icon;
211
+ iconId: VenueGlyph;
212
+ sizeM: SizeM;
213
+ } | {
214
+ kind: DecorationKind.Image;
215
+ assetId: UUID;
216
+ sizeM: SizeM;
217
+ opacity: number;
218
+ }) & {
219
+ style?: DecorationStyle;
220
+ };
221
+ export type SectionLabelPlacement = {
222
+ positionM: PointM;
223
+ rotationDeg: number;
224
+ align: LabelAlignment;
225
+ };
226
+ export declare enum SectionOutlineRole {
227
+ Boundary = "boundary",
228
+ Overview = "overview"
229
+ }
230
+ export type Section = {
231
+ id: UUID;
232
+ label: string;
233
+ displayLabel?: string;
234
+ outline?: PolygonM;
235
+ outlineRole?: SectionOutlineRole;
236
+ style?: DecorationStyle;
237
+ labelPlacement?: SectionLabelPlacement;
238
+ labelStyle: LabelStyle;
239
+ };
240
+ export type Collection = DrawableBase & {
241
+ name: string;
242
+ };
243
+ export type AssetRef = {
244
+ id: UUID;
245
+ mimeType: "image/png" | "image/jpeg" | "image/webp" | "image/svg+xml";
246
+ };
247
+ export type PhysicalDocumentV1 = {
248
+ schemaVersion: 1;
249
+ mapId: UUID;
250
+ name: string;
251
+ coordinateSystem: {
252
+ unit: "metre";
253
+ xAxis: "right";
254
+ yAxis: "down";
255
+ rotation: "clockwise";
256
+ };
257
+ background: Paint;
258
+ sections: Section[];
259
+ collections: Collection[];
260
+ seatingGroups: SeatingGroup[];
261
+ areas: GeneralAdmission[];
262
+ decorations: Decoration[];
263
+ assets: AssetRef[];
264
+ };
265
+ export declare enum EntityFamily {
266
+ Group = "group",
267
+ Area = "area",
268
+ Decoration = "decoration",
269
+ Collection = "collection",
270
+ Section = "section",
271
+ Asset = "asset",
272
+ Seat = "seat",
273
+ Row = "row"
274
+ }
275
+ export declare enum SeatingKind {
276
+ Straight = "straightRows",
277
+ Curved = "curvedRows",
278
+ Rectangular = "rectangularTable",
279
+ Round = "roundTable"
280
+ }
281
+ export declare enum DecorationKind {
282
+ Polygon = "polygon",
283
+ Text = "text",
284
+ Rectangle = "rectangle",
285
+ Circle = "circle",
286
+ Line = "line",
287
+ Icon = "icon",
288
+ Image = "image"
289
+ }
290
+ export declare enum AreaKind {
291
+ GeneralAdmission = "generalAdmission"
292
+ }
293
+ export declare enum VenueGlyph {
294
+ Stage = "stage",
295
+ Entrance = "entrance",
296
+ Exit = "exit",
297
+ Bar = "bar",
298
+ Restroom = "restroom",
299
+ Accessible = "accessible"
300
+ }
301
+ export declare enum ShapeKind {
302
+ Rectangle = "rectangle",
303
+ Polygon = "polygon"
304
+ }
305
+ export declare enum CurveMode {
306
+ Sweep = "fixedSweep",
307
+ Pitch = "fixedPitch"
308
+ }
309
+ export type Drawable = SeatingGroup | GeneralAdmission | Decoration | Collection;
310
+ export type EntityRef = {
311
+ family: EntityFamily;
312
+ id: UUID;
313
+ };
package/dist/types.js ADDED
@@ -0,0 +1,91 @@
1
+ // Structural capacity; the measured qualification workload remains 50,000 seats.
2
+ export const DocumentLimits = {
3
+ PhysicalSeats: 100_000,
4
+ JsonBytes: 64 * 1024 * 1024,
5
+ };
6
+ export var NumberingScheme;
7
+ (function (NumberingScheme) {
8
+ NumberingScheme["Numeric"] = "numeric";
9
+ NumberingScheme["Odd"] = "odd";
10
+ NumberingScheme["Even"] = "even";
11
+ NumberingScheme["Alphabetic"] = "alphabetic";
12
+ })(NumberingScheme || (NumberingScheme = {}));
13
+ export var LabelDirection;
14
+ (function (LabelDirection) {
15
+ LabelDirection["Forward"] = "forward";
16
+ LabelDirection["Reverse"] = "reverse";
17
+ })(LabelDirection || (LabelDirection = {}));
18
+ export var RowLabelPosition;
19
+ (function (RowLabelPosition) {
20
+ RowLabelPosition["Left"] = "left";
21
+ RowLabelPosition["Right"] = "right";
22
+ RowLabelPosition["Both"] = "both";
23
+ })(RowLabelPosition || (RowLabelPosition = {}));
24
+ export var RowAlignment;
25
+ (function (RowAlignment) {
26
+ RowAlignment["Start"] = "start";
27
+ RowAlignment["Center"] = "center";
28
+ RowAlignment["End"] = "end";
29
+ })(RowAlignment || (RowAlignment = {}));
30
+ export var LabelAlignment;
31
+ (function (LabelAlignment) {
32
+ LabelAlignment["Left"] = "left";
33
+ LabelAlignment["Center"] = "center";
34
+ LabelAlignment["Right"] = "right";
35
+ })(LabelAlignment || (LabelAlignment = {}));
36
+ export var SectionOutlineRole;
37
+ (function (SectionOutlineRole) {
38
+ SectionOutlineRole["Boundary"] = "boundary";
39
+ SectionOutlineRole["Overview"] = "overview";
40
+ })(SectionOutlineRole || (SectionOutlineRole = {}));
41
+ export var EntityFamily;
42
+ (function (EntityFamily) {
43
+ EntityFamily["Group"] = "group";
44
+ EntityFamily["Area"] = "area";
45
+ EntityFamily["Decoration"] = "decoration";
46
+ EntityFamily["Collection"] = "collection";
47
+ EntityFamily["Section"] = "section";
48
+ EntityFamily["Asset"] = "asset";
49
+ EntityFamily["Seat"] = "seat";
50
+ EntityFamily["Row"] = "row";
51
+ })(EntityFamily || (EntityFamily = {}));
52
+ export var SeatingKind;
53
+ (function (SeatingKind) {
54
+ SeatingKind["Straight"] = "straightRows";
55
+ SeatingKind["Curved"] = "curvedRows";
56
+ SeatingKind["Rectangular"] = "rectangularTable";
57
+ SeatingKind["Round"] = "roundTable";
58
+ })(SeatingKind || (SeatingKind = {}));
59
+ export var DecorationKind;
60
+ (function (DecorationKind) {
61
+ DecorationKind["Polygon"] = "polygon";
62
+ DecorationKind["Text"] = "text";
63
+ DecorationKind["Rectangle"] = "rectangle";
64
+ DecorationKind["Circle"] = "circle";
65
+ DecorationKind["Line"] = "line";
66
+ DecorationKind["Icon"] = "icon";
67
+ DecorationKind["Image"] = "image";
68
+ })(DecorationKind || (DecorationKind = {}));
69
+ export var AreaKind;
70
+ (function (AreaKind) {
71
+ AreaKind["GeneralAdmission"] = "generalAdmission";
72
+ })(AreaKind || (AreaKind = {}));
73
+ export var VenueGlyph;
74
+ (function (VenueGlyph) {
75
+ VenueGlyph["Stage"] = "stage";
76
+ VenueGlyph["Entrance"] = "entrance";
77
+ VenueGlyph["Exit"] = "exit";
78
+ VenueGlyph["Bar"] = "bar";
79
+ VenueGlyph["Restroom"] = "restroom";
80
+ VenueGlyph["Accessible"] = "accessible";
81
+ })(VenueGlyph || (VenueGlyph = {}));
82
+ export var ShapeKind;
83
+ (function (ShapeKind) {
84
+ ShapeKind["Rectangle"] = "rectangle";
85
+ ShapeKind["Polygon"] = "polygon";
86
+ })(ShapeKind || (ShapeKind = {}));
87
+ export var CurveMode;
88
+ (function (CurveMode) {
89
+ CurveMode["Sweep"] = "fixedSweep";
90
+ CurveMode["Pitch"] = "fixedPitch";
91
+ })(CurveMode || (CurveMode = {}));
@@ -0,0 +1,27 @@
1
+ import { type PhysicalDocumentV1, type UUID } from "./types.js";
2
+ import { type DomainIssue } from "./issues.js";
3
+ export type AssetReadiness = ReadonlySet<UUID>;
4
+ /** Label equality and collision ownership live here; consumers only project issues. */
5
+ export declare class ValidationIndex {
6
+ private document;
7
+ private assetReadiness;
8
+ private buckets;
9
+ private owners;
10
+ private collisions;
11
+ private groupIssues;
12
+ private seats;
13
+ private companions;
14
+ private baseIssues;
15
+ constructor(document: PhysicalDocumentV1, assetReadiness?: AssetReadiness);
16
+ private key;
17
+ private refresh;
18
+ private put;
19
+ private remove;
20
+ private indexGroup;
21
+ rebuild(document: PhysicalDocumentV1): void;
22
+ private refreshBaseIssues;
23
+ update(document: PhysicalDocumentV1, changedGroupIds: ReadonlySet<UUID>, refreshMetadata?: boolean): void;
24
+ issues(): DomainIssue[];
25
+ setAssetReadiness(assets: AssetReadiness): void;
26
+ }
27
+ export declare function validatePhysicalDocument(document: PhysicalDocumentV1, assets?: AssetReadiness): DomainIssue[];
@@ -0,0 +1,267 @@
1
+ import { SeatingKind } from "./types.js";
2
+ import { SectionOutlineRole, ShapeKind, DecorationKind, } from "./types.js";
3
+ import { IssueCode, IssueSeverity, issue, issueKey, } from "./issues.js";
4
+ import { labelKey, sequenceLabel } from "./labels.js";
5
+ import { footprint, footprintInside, generateGroup, invalidPolygon, worldMatrices, } from "./geometry/geometry.js";
6
+ import { curveWarnings, CurveWarningKind } from "./geometry/curve-warnings.js";
7
+ import { capacity } from "./schema.js";
8
+ /** Label equality and collision ownership live here; consumers only project issues. */
9
+ export class ValidationIndex {
10
+ document;
11
+ assetReadiness;
12
+ buckets = new Map();
13
+ owners = new Map();
14
+ collisions = new Map();
15
+ groupIssues = new Map();
16
+ seats = new Map();
17
+ companions = new Map();
18
+ baseIssues = [];
19
+ constructor(document, assetReadiness = new Set()) {
20
+ this.document = document;
21
+ this.assetReadiness = assetReadiness;
22
+ this.rebuild(document);
23
+ }
24
+ key(entry) {
25
+ return entry.scope + "\0" + labelKey(entry.label);
26
+ }
27
+ refresh(key) {
28
+ const entries = Array.from(this.buckets.get(key)?.values() ?? []);
29
+ if (entries.length > 1)
30
+ this.collisions.set(key, issue(IssueCode.DuplicateLabel, "Labels must be unique within their inventory scope.", entries.map((e) => e.id), entries[0].scope));
31
+ else
32
+ this.collisions.delete(key);
33
+ }
34
+ put(owner, entries) {
35
+ this.owners.set(owner, entries);
36
+ for (const entry of entries) {
37
+ const key = this.key(entry);
38
+ let bucket = this.buckets.get(key);
39
+ if (!bucket) {
40
+ bucket = new Map();
41
+ this.buckets.set(key, bucket);
42
+ }
43
+ bucket.set(entry.id, entry);
44
+ this.refresh(key);
45
+ }
46
+ }
47
+ remove(owner) {
48
+ for (const entry of this.owners.get(owner) ?? []) {
49
+ const key = this.key(entry);
50
+ const bucket = this.buckets.get(key);
51
+ bucket?.delete(entry.id);
52
+ if (!bucket?.size)
53
+ this.buckets.delete(key);
54
+ this.refresh(key);
55
+ this.seats.delete(entry.id);
56
+ this.companions.delete(entry.id);
57
+ }
58
+ this.owners.delete(owner);
59
+ this.groupIssues.delete(owner);
60
+ }
61
+ indexGroup(g) {
62
+ const entries = [];
63
+ const local = [];
64
+ const section = g.sectionId ?? "unsectioned";
65
+ if (g.kind === SeatingKind.Straight || g.kind === SeatingKind.Curved)
66
+ for (let i = 0; i < g.rows.length; i++) {
67
+ const row = g.rows[i];
68
+ entries.push({
69
+ id: row.id,
70
+ ownerId: g.id,
71
+ label: row.labelOverride ?? sequenceLabel(g.labels.rows, i, g.rows.length),
72
+ scope: `rows:${section}`,
73
+ field: `${row.id}.label`,
74
+ });
75
+ }
76
+ else
77
+ entries.push({
78
+ id: g.id,
79
+ ownerId: g.id,
80
+ label: g.labels.table,
81
+ scope: `tables:${section}`,
82
+ field: `${g.id}.labels.table`,
83
+ });
84
+ const assignedSection = this.document.sections.find((s) => s.id === g.sectionId);
85
+ const sectionOutline = (assignedSection?.outlineRole ?? SectionOutlineRole.Boundary) ===
86
+ SectionOutlineRole.Boundary
87
+ ? assignedSection?.outline
88
+ : undefined;
89
+ const matrix = sectionOutline
90
+ ? worldMatrices(this.document).get(g.id)
91
+ : undefined;
92
+ let outside = false;
93
+ for (const s of generateGroup(g)) {
94
+ entries.push({
95
+ id: s.id,
96
+ ownerId: g.id,
97
+ label: s.label,
98
+ scope: `chairs:${s.rowId ?? g.id}`,
99
+ field: `${s.id}.label`,
100
+ });
101
+ this.seats.set(s.id, {
102
+ groupId: g.id,
103
+ companion: s.slot.attributes?.companionForSeatId,
104
+ });
105
+ if (s.slot.attributes?.companionForSeatId)
106
+ this.companions.set(s.id, s.slot.attributes.companionForSeatId);
107
+ if ((g.boundary && !footprintInside(footprint(s), g.boundary)) ||
108
+ (sectionOutline &&
109
+ !footprintInside(footprint(s, matrix), sectionOutline)))
110
+ outside = true;
111
+ }
112
+ for (const e of entries)
113
+ if (!labelKey(e.label) || Array.from(e.label).length > 80)
114
+ local.push(issue(IssueCode.InvalidLabel, "Use a nonempty label of at most 80 characters.", [e.id], e.field));
115
+ if (outside)
116
+ local.push(issue(IssueCode.OutsideBoundary, "Inventory extends beyond its declared boundary. No seats have been removed.", [g.id], `${g.id}.boundary`));
117
+ if (g.boundary && invalidPolygon(g.boundary))
118
+ local.push(issue(IssueCode.InvalidBoundary, "Repair intersecting boundaries or invalid holes.", [g.id], `${g.id}.boundary`));
119
+ if (g.kind === SeatingKind.Curved) {
120
+ const warnings = curveWarnings(g.recipe, g.rows.map((r) => r.seats.length), g.seatSizeM, g.rows);
121
+ const overrun = warnings.find((w) => w.kind === CurveWarningKind.Overrun), clearance = warnings.find((w) => w.kind === CurveWarningKind.Clearance);
122
+ if (overrun)
123
+ local.push(issue(IssueCode.CurveOverrun, overrun.message, [g.id], `${g.id}.recipe`));
124
+ if (clearance)
125
+ local.push({
126
+ ...issue(IssueCode.SeatClearance, clearance.message, [g.id], `${g.id}.recipe`),
127
+ severity: IssueSeverity.Warning,
128
+ blocks: [],
129
+ });
130
+ }
131
+ this.put(g.id, entries);
132
+ this.groupIssues.set(g.id, local);
133
+ }
134
+ rebuild(document) {
135
+ this.document = document;
136
+ this.buckets.clear();
137
+ this.owners.clear();
138
+ this.collisions.clear();
139
+ this.groupIssues.clear();
140
+ this.seats.clear();
141
+ this.companions.clear();
142
+ this.baseIssues = [];
143
+ this.put(document.mapId, document.sections.map((s) => ({
144
+ id: s.id,
145
+ ownerId: document.mapId,
146
+ label: s.label,
147
+ scope: "sections",
148
+ field: `${s.id}.label`,
149
+ })));
150
+ for (const g of document.seatingGroups)
151
+ this.indexGroup(g);
152
+ for (const a of document.areas)
153
+ this.put(a.id, [
154
+ {
155
+ id: a.id,
156
+ ownerId: a.id,
157
+ label: a.label,
158
+ scope: `areas:${a.sectionId ?? "unsectioned"}`,
159
+ field: `${a.id}.label`,
160
+ },
161
+ ]);
162
+ this.refreshBaseIssues(document);
163
+ }
164
+ refreshBaseIssues(document) {
165
+ this.baseIssues = [];
166
+ for (const entity of [...document.sections, ...document.areas])
167
+ if (!labelKey(entity.label))
168
+ this.baseIssues.push(issue(IssueCode.InvalidLabel, "Use a nonempty inventory label.", [entity.id], `${entity.id}.label`));
169
+ for (const s of document.sections)
170
+ if (s.outline && invalidPolygon(s.outline))
171
+ this.baseIssues.push(issue(IssueCode.InvalidBoundary, "Section boundary needs repair.", [s.id], `${s.id}.outline`));
172
+ for (const a of document.areas)
173
+ if (a.shape.kind === ShapeKind.Polygon &&
174
+ invalidPolygon(a.shape.boundary))
175
+ this.baseIssues.push(issue(IssueCode.InvalidBoundary, "Area boundary needs repair.", [
176
+ a.id,
177
+ ]));
178
+ for (const d of document.decorations) {
179
+ if (d.kind === DecorationKind.Polygon && invalidPolygon(d.boundary))
180
+ this.baseIssues.push(issue(IssueCode.InvalidBoundary, "Artwork boundary needs repair.", [
181
+ d.id,
182
+ ]));
183
+ if (d.kind === DecorationKind.Image &&
184
+ (!document.assets.some((a) => a.id === d.assetId) ||
185
+ !this.assetReadiness.has(d.assetId)))
186
+ this.baseIssues.push(issue(IssueCode.MissingAsset, "Referenced artwork is unavailable. Retry or remove the reference.", [d.id], `${d.id}.assetId`));
187
+ }
188
+ }
189
+ update(document, changedGroupIds, refreshMetadata = false) {
190
+ const before = this.document;
191
+ this.document = document;
192
+ for (const id of changedGroupIds)
193
+ this.remove(id);
194
+ for (const g of document.seatingGroups)
195
+ if (changedGroupIds.has(g.id))
196
+ this.indexGroup(g);
197
+ if (refreshMetadata) {
198
+ this.remove(document.mapId);
199
+ for (const area of before.areas)
200
+ this.remove(area.id);
201
+ this.put(document.mapId, document.sections.map((section) => ({
202
+ id: section.id,
203
+ ownerId: document.mapId,
204
+ label: section.label,
205
+ scope: "sections",
206
+ field: `${section.id}.label`,
207
+ })));
208
+ for (const area of document.areas)
209
+ this.put(area.id, [
210
+ {
211
+ id: area.id,
212
+ ownerId: area.id,
213
+ label: area.label,
214
+ scope: `areas:${area.sectionId ?? "unsectioned"}`,
215
+ field: `${area.id}.label`,
216
+ },
217
+ ]);
218
+ this.refreshBaseIssues(document);
219
+ }
220
+ }
221
+ issues() {
222
+ const issues = [
223
+ ...this.baseIssues,
224
+ ...this.collisions.values(),
225
+ ...Array.from(this.groupIssues.values()).flat(),
226
+ ];
227
+ const companionStatus = new Map();
228
+ for (const id of this.companions.keys()) {
229
+ const visited = new Set();
230
+ let next = id;
231
+ let invalid = false;
232
+ while (next) {
233
+ if (companionStatus.has(next)) {
234
+ invalid = companionStatus.get(next);
235
+ break;
236
+ }
237
+ if (visited.has(next) || !this.seats.has(next)) {
238
+ invalid = true;
239
+ break;
240
+ }
241
+ visited.add(next);
242
+ next = this.seats.get(next)?.companion;
243
+ }
244
+ for (const member of visited)
245
+ companionStatus.set(member, invalid);
246
+ if (invalid)
247
+ issues.push(issue(IssueCode.InvalidCompanion, "Companion reference is missing, self-referential or cyclic.", [id], `${id}.attributes.companionForSeatId`));
248
+ }
249
+ if (capacity(this.document).physicalSeats +
250
+ capacity(this.document).gaQuantity ===
251
+ 0)
252
+ issues.push(issue(IssueCode.EmptyInventory, "Add inventory before assignment or publication.", [this.document.mapId]));
253
+ return issues.sort((a, b) => issueKey(a).localeCompare(issueKey(b)));
254
+ }
255
+ setAssetReadiness(assets) {
256
+ this.assetReadiness = assets;
257
+ this.baseIssues = this.baseIssues.filter((i) => i.code !== IssueCode.MissingAsset);
258
+ for (const d of this.document.decorations)
259
+ if (d.kind === DecorationKind.Image &&
260
+ (!this.document.assets.some((a) => a.id === d.assetId) ||
261
+ !assets.has(d.assetId)))
262
+ this.baseIssues.push(issue(IssueCode.MissingAsset, "Referenced artwork is unavailable. Retry or remove the reference.", [d.id], `${d.id}.assetId`));
263
+ }
264
+ }
265
+ export function validatePhysicalDocument(document, assets = new Set()) {
266
+ return new ValidationIndex(document, assets).issues();
267
+ }