@seatmap-fyi/map-domain 0.1.0-alpha.2 → 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 +1 -1
  43. package/dist/preview.js +65 -24
  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 +59 -3
  62. package/dist/types.d.ts +0 -313
package/dist/catalog.d.ts CHANGED
@@ -1,13 +1,20 @@
1
- import type { PhysicalDocumentV1, SeatingGroup, UUID } from "./types.js";
1
+ import type { PhysicalDocumentV1, SeatingGroup, InventoryArea, UUID } from "./physical-document.interface.js";
2
+ import { type SegmentedRowEntry } from "./row-segments.js";
2
3
  import { type GeneratedSeat } from "./geometry/geometry.js";
3
- export declare function generatedSeats(group: SeatingGroup): readonly GeneratedSeat[];
4
+ export type DocumentSeat = GeneratedSeat & {
5
+ sectionId: UUID | null;
6
+ };
7
+ /** Geometry remains shared; logical addresses are projected from the current document. */
8
+ export declare function documentGroupSeats(document: PhysicalDocumentV1, group: SeatingGroup): readonly DocumentSeat[];
4
9
  export type DocumentCatalog = {
5
10
  groups: ReadonlyMap<UUID, SeatingGroup>;
11
+ areas: ReadonlyMap<UUID, InventoryArea>;
6
12
  seats: ReadonlyMap<UUID, {
7
13
  group: SeatingGroup;
8
- seat: GeneratedSeat;
14
+ seat: DocumentSeat;
9
15
  }>;
10
16
  rows: ReadonlyMap<UUID, SeatingGroup>;
17
+ segmentedRows: ReadonlyMap<UUID, SegmentedRowEntry>;
11
18
  sections: ReadonlyMap<UUID, string>;
12
19
  };
13
20
  /** Immutable, derived lookup; never an editable store. Untouched group geometry is shared. */
package/dist/catalog.js CHANGED
@@ -1,12 +1,58 @@
1
- import { generateGroup } from "./geometry/geometry.js";
2
- const generated = new WeakMap();
3
- export function generatedSeats(group) {
4
- let cached = generated.get(group);
5
- if (!cached) {
6
- cached = Object.freeze([...generateGroup(group)]);
7
- generated.set(group, cached);
1
+ import { sectionCatalog } from "./sections.js";
2
+ import { rowSegments } from "./row-segments.js";
3
+ import { sequenceLabel, rowDisplayLabel } from "./labels.js";
4
+ import { generatedSeats } from "./geometry/geometry.js";
5
+ const documentSeats = new WeakMap();
6
+ /** Geometry remains shared; logical addresses are projected from the current document. */
7
+ export function documentGroupSeats(document, group) {
8
+ let cache = documentSeats.get(document);
9
+ if (!cache) {
10
+ cache = new Map();
11
+ documentSeats.set(document, cache);
8
12
  }
9
- return cached;
13
+ const cached = cache.get(group);
14
+ if (cached)
15
+ return cached;
16
+ const segments = rowSegments(document);
17
+ const owners = sectionCatalog(document).owners;
18
+ const parts = new Map();
19
+ const result = generatedSeats(group).map((geometry) => {
20
+ const seat = { ...geometry, sectionId: owners.get(geometry.rowId ?? group.id) ?? null };
21
+ const segment = seat.rowId ? segments.get(seat.rowId) : undefined;
22
+ if (!segment)
23
+ return seat;
24
+ let part = parts.get(segment.part.id);
25
+ if (!part) {
26
+ part = {
27
+ ordinal: 0,
28
+ addressRowLabel: !segment.coherent || segment.row.qualifySeatLabels
29
+ ? rowDisplayLabel(segment.group, segment.group.rows.indexOf(segment.part))
30
+ : undefined,
31
+ };
32
+ parts.set(segment.part.id, part);
33
+ }
34
+ if (!segment.coherent)
35
+ return {
36
+ ...seat,
37
+ ownerLabel: segment.displayLabel,
38
+ addressRowLabel: part.addressRowLabel,
39
+ logicalPartIndex: segment.partIndex,
40
+ };
41
+ const ordinal = part.ordinal++;
42
+ return {
43
+ ...seat,
44
+ label: seat.slot.labelOverride ??
45
+ sequenceLabel(segment.row.sequence, segment.firstIndex + ordinal, segment.totalSeats),
46
+ bookingLabel: sequenceLabel(segment.row.sequence, segment.firstIndex + ordinal, segment.totalSeats),
47
+ addressRowLabel: part.addressRowLabel,
48
+ logicalRowId: segment.row.id,
49
+ logicalRowLabel: segment.displayLabel,
50
+ logicalPartIndex: segment.partIndex,
51
+ logicalSequence: segment.row.sequence,
52
+ };
53
+ });
54
+ cache.set(group, result);
55
+ return result;
10
56
  }
11
57
  const catalogs = new WeakMap();
12
58
  /** Immutable, derived lookup; never an editable store. Untouched group geometry is shared. */
@@ -16,20 +62,30 @@ export function documentCatalog(document) {
16
62
  return catalog;
17
63
  const groups = new Map(document.seatingGroups.map((g) => [g.id, g])), seats = new Map(), rows = new Map();
18
64
  for (const group of document.seatingGroups)
19
- for (const seat of generatedSeats(group)) {
65
+ for (const seat of documentGroupSeats(document, group)) {
20
66
  seats.set(seat.id, { group, seat });
21
67
  if (seat.rowId)
22
68
  rows.set(seat.rowId, group);
23
69
  }
24
70
  catalog = {
25
71
  groups,
72
+ areas: new Map(document.areas.map((area) => [area.id, area])),
26
73
  seats,
27
74
  rows,
75
+ segmentedRows: new Map((document.segmentedRows ?? []).map((row) => [
76
+ row.id,
77
+ {
78
+ row,
79
+ displayLabel: rowSegments(document).get(row.parts[0].rowId).displayLabel,
80
+ coherent: rowSegments(document).get(row.parts[0].rowId).coherent,
81
+ parts: row.parts.map((part) => rowSegments(document).get(part.rowId)),
82
+ },
83
+ ])),
28
84
  sections: new Map(document.sections.map((s) => [s.id, s.label])),
29
85
  };
30
86
  catalogs.set(document, catalog);
31
87
  return catalog;
32
88
  }
33
89
  export function inventoryAddress(document, seat) {
34
- return `${documentCatalog(document).sections.get(seat.sectionId ?? "") ?? "Unsectioned"}, ${seat.rowId ? "row" : "table"} ${seat.ownerLabel}, seat ${seat.label}`;
90
+ return `${documentCatalog(document).sections.get(sectionCatalog(document).owners.get(seat.rowId ?? seat.groupId) ?? "") ?? "Unsectioned"}, ${seat.rowId ? "row" : "table"} ${seat.addressRowLabel ?? seat.logicalRowLabel ?? seat.ownerLabel}, seat ${seat.bookingLabel}`;
35
91
  }
@@ -0,0 +1,26 @@
1
+ import type { MapCategory, PhysicalDocumentV1, RowSlot, SeatingGroup, SeatSlot, UUID } from "./physical-document.interface.js";
2
+ import { SeatShape } from "./physical-document.interface.js";
3
+ import { type DomainIssue } from "./issues.js";
4
+ export declare function categoryCatalog(document: PhysicalDocumentV1): ReadonlyMap<UUID, MapCategory>;
5
+ /** Absence inherits; explicit null records an unassigned child. */
6
+ export declare function seatCategoryId(group: SeatingGroup, slot: SeatSlot, row?: RowSlot): UUID | null;
7
+ export declare function categoryReferences(groups: readonly SeatingGroup[]): Generator<{
8
+ id: UUID;
9
+ categoryId: UUID;
10
+ }>;
11
+ /** Unresolved catalogue references are repairable draft findings, not invalid physical structure. */
12
+ export declare function categoryIssues(document: PhysicalDocumentV1): readonly DomainIssue[];
13
+ /** Fragment paste reuses catalogue identity; whole-map copy remaps it with the map. */
14
+ export declare function remapGroupCategories(group: SeatingGroup, ids: ReadonlyMap<UUID, UUID>): SeatingGroup;
15
+ export declare function categoryUsage(document: PhysicalDocumentV1): ReadonlyMap<UUID, number>;
16
+ export declare function ticketOptionNameKey(name: string): string;
17
+ export type CategoryPricing = {
18
+ onSale: boolean;
19
+ optionCount: number;
20
+ minimum: number | null;
21
+ maximum: number | null;
22
+ missing: boolean;
23
+ };
24
+ export declare function categoryPricing(category: MapCategory): CategoryPricing;
25
+ /** A personal circle remains an override; absence inherits the category shape. */
26
+ export declare function categorySeatShape(category?: MapCategory, slot?: SeatSlot): SeatShape;
@@ -0,0 +1,168 @@
1
+ import { AreaKind, SeatShape, SeatingKind } from "./physical-document.interface.js";
2
+ import { issue, IssueCode, IssueSeverity } from "./issues.js";
3
+ const catalogs = new WeakMap();
4
+ export function categoryCatalog(document) {
5
+ let catalog = catalogs.get(document);
6
+ if (!catalog) {
7
+ catalog = new Map((document.categories ?? []).map((category) => [category.id, category]));
8
+ catalogs.set(document, catalog);
9
+ }
10
+ return catalog;
11
+ }
12
+ /** Absence inherits; explicit null records an unassigned child. */
13
+ export function seatCategoryId(group, slot, row) {
14
+ if (slot.categoryId !== undefined)
15
+ return slot.categoryId;
16
+ if (row?.categoryId !== undefined)
17
+ return row.categoryId;
18
+ return group.categoryId ?? null;
19
+ }
20
+ export function* categoryReferences(groups) {
21
+ for (const group of groups) {
22
+ if (group.categoryId)
23
+ yield { id: group.id, categoryId: group.categoryId };
24
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved) {
25
+ for (const row of group.rows) {
26
+ if (row.categoryId)
27
+ yield { id: row.id, categoryId: row.categoryId };
28
+ for (const slot of row.seats)
29
+ if (slot.categoryId)
30
+ yield { id: slot.id, categoryId: slot.categoryId };
31
+ }
32
+ }
33
+ else {
34
+ const seats = group.kind === SeatingKind.Round ? group.chairs : Object.values(group.chairsBySide).flat();
35
+ for (const slot of seats)
36
+ if (slot.categoryId)
37
+ yield { id: slot.id, categoryId: slot.categoryId };
38
+ }
39
+ }
40
+ }
41
+ const categoryFindings = new WeakMap();
42
+ /** Unresolved catalogue references are repairable draft findings, not invalid physical structure. */
43
+ export function categoryIssues(document) {
44
+ const cached = categoryFindings.get(document);
45
+ if (cached)
46
+ return cached;
47
+ const categories = new Set((document.categories ?? []).map((category) => category.id));
48
+ const byOwner = new Map();
49
+ const check = (id, categoryId, ownerId) => {
50
+ if (categoryId && !categories.has(categoryId))
51
+ byOwner.set(id, issue(IssueCode.UnknownCategory, "Unknown category", [id], `${ownerId}.categoryId`));
52
+ };
53
+ for (const group of document.seatingGroups) {
54
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved) {
55
+ for (const row of group.rows)
56
+ for (const slot of row.seats) {
57
+ if (slot.gap)
58
+ continue;
59
+ const ownerId = slot.categoryId !== undefined ? slot.id : row.id;
60
+ const referenceId = slot.categoryId !== undefined ? slot.id : row.categoryId !== undefined ? row.id : group.id;
61
+ check(ownerId, seatCategoryId(group, slot, row), referenceId);
62
+ }
63
+ }
64
+ else {
65
+ const slots = group.kind === SeatingKind.Round ? group.chairs : Object.values(group.chairsBySide).flat();
66
+ for (const slot of slots) {
67
+ if (slot.gap)
68
+ continue;
69
+ const ownerId = slot.categoryId !== undefined ? slot.id : group.id;
70
+ check(ownerId, seatCategoryId(group, slot), ownerId);
71
+ }
72
+ }
73
+ }
74
+ for (const entity of [...document.areas, ...document.sections])
75
+ check(entity.id, entity.categoryId, entity.id);
76
+ const findings = [...byOwner.values()];
77
+ const uses = categoryUsage(document);
78
+ for (const category of document.categories ?? []) {
79
+ if (!uses.get(category.id) || !categoryPricing(category).missing)
80
+ continue;
81
+ const message = `Category "${category.name}" has no default price. Each event sets its price before it goes on sale`;
82
+ findings.push({
83
+ ...issue(IssueCode.MissingCategoryPrice, message, [category.id], `${category.id}.defaultPrice`),
84
+ severity: IssueSeverity.Warning,
85
+ description: message,
86
+ blocks: [],
87
+ });
88
+ }
89
+ categoryFindings.set(document, findings);
90
+ return findings;
91
+ }
92
+ /** Fragment paste reuses catalogue identity; whole-map copy remaps it with the map. */
93
+ export function remapGroupCategories(group, ids) {
94
+ const remap = (value) => {
95
+ const categoryId = value.categoryId ? ids.get(value.categoryId) : undefined;
96
+ return categoryId && categoryId !== value.categoryId ? { ...value, categoryId } : value;
97
+ };
98
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved)
99
+ return {
100
+ ...remap(group),
101
+ rows: group.rows.map((row) => ({
102
+ ...remap(row),
103
+ seats: row.seats.map(remap),
104
+ })),
105
+ };
106
+ if (group.kind === SeatingKind.Round)
107
+ return { ...remap(group), chairs: group.chairs.map(remap) };
108
+ return {
109
+ ...remap(group),
110
+ chairsBySide: {
111
+ top: group.chairsBySide.top.map(remap),
112
+ right: group.chairsBySide.right.map(remap),
113
+ bottom: group.chairsBySide.bottom.map(remap),
114
+ left: group.chairsBySide.left.map(remap),
115
+ },
116
+ };
117
+ }
118
+ const usage = new WeakMap();
119
+ export function categoryUsage(document) {
120
+ const cached = usage.get(document);
121
+ if (cached)
122
+ return cached;
123
+ const counts = new Map();
124
+ const count = (id, quantity = 1) => {
125
+ if (id)
126
+ counts.set(id, (counts.get(id) ?? 0) + quantity);
127
+ };
128
+ for (const group of document.seatingGroups) {
129
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved) {
130
+ for (const row of group.rows)
131
+ for (const slot of row.seats)
132
+ if (!slot.gap)
133
+ count(seatCategoryId(group, slot, row));
134
+ }
135
+ else {
136
+ const slots = group.kind === SeatingKind.Round ? group.chairs : Object.values(group.chairsBySide).flat();
137
+ for (const slot of slots)
138
+ if (!slot.gap)
139
+ count(seatCategoryId(group, slot));
140
+ }
141
+ }
142
+ for (const area of document.areas)
143
+ count(area.categoryId ?? null, area.kind === AreaKind.Booth ? 1 : area.capacity);
144
+ usage.set(document, counts);
145
+ return counts;
146
+ }
147
+ export function ticketOptionNameKey(name) {
148
+ return name.trim().toLowerCase();
149
+ }
150
+ export function categoryPricing(category) {
151
+ const options = category.ticketOptions ?? [];
152
+ const prices = options.length
153
+ ? options.map((option) => option.price)
154
+ : category.defaultPrice == null
155
+ ? []
156
+ : [category.defaultPrice];
157
+ return {
158
+ onSale: category.onSale !== false,
159
+ optionCount: options.length,
160
+ minimum: prices.length ? Math.min(...prices) : null,
161
+ maximum: prices.length ? Math.max(...prices) : null,
162
+ missing: category.onSale !== false && !prices.length,
163
+ };
164
+ }
165
+ /** A personal circle remains an override; absence inherits the category shape. */
166
+ export function categorySeatShape(category, slot) {
167
+ return slot?.seatShape ?? category?.seatShape ?? SeatShape.Circle;
168
+ }
@@ -0,0 +1,49 @@
1
+ import { z } from "zod";
2
+ import type { PhysicalDocumentV1, UUID } from "./physical-document.interface.js";
3
+ export declare const mapEditorStateSchema: z.ZodObject<{
4
+ version: z.ZodLiteral<1>;
5
+ lockedIds: z.ZodArray<z.ZodString>;
6
+ hiddenIds: z.ZodArray<z.ZodString>;
7
+ }, z.core.$strict>;
8
+ export type MapEditorState = z.infer<typeof mapEditorStateSchema>;
9
+ export declare const emptyMapEditorState: MapEditorState;
10
+ type EditorNode = {
11
+ id: UUID;
12
+ parentId?: UUID | null;
13
+ sectionId?: UUID | null;
14
+ };
15
+ export declare class MapEditorPolicy {
16
+ private readonly document;
17
+ readonly nodes: Map<string, EditorNode>;
18
+ readonly rows: Set<string>;
19
+ private readonly parents;
20
+ private readonly lockParents;
21
+ private readonly children;
22
+ private readonly locked;
23
+ private readonly hidden;
24
+ private readonly lockOwners;
25
+ private readonly hiddenOwners;
26
+ private readonly protectedContainers;
27
+ constructor(document: PhysicalDocumentV1, state: MapEditorState);
28
+ canLock(id: UUID): boolean;
29
+ canHide(id: UUID): boolean;
30
+ childIds(id: UUID): readonly UUID[];
31
+ /** Inventory ownership controls visibility; only structural parents pass down position locks. */
32
+ layoutChildIds(id: UUID): readonly UUID[];
33
+ private parentIds;
34
+ private owner;
35
+ lockOwner(id: UUID): UUID | undefined;
36
+ hiddenOwner(id: UUID): UUID | undefined;
37
+ inheritedLockOwner(id: UUID): UUID | undefined;
38
+ inheritedHiddenOwner(id: UUID): UUID | undefined;
39
+ protectedOwner(id: UUID): UUID | undefined;
40
+ }
41
+ export declare function mapEditorPolicy(document: PhysicalDocumentV1, state: MapEditorState): MapEditorPolicy;
42
+ export declare function canonicalEditorState(state: MapEditorState): MapEditorState;
43
+ export declare function parseMapEditorState(document: PhysicalDocumentV1, input: unknown): MapEditorState;
44
+ export declare function pruneMapEditorState(document: PhysicalDocumentV1, state: MapEditorState): MapEditorState;
45
+ export declare function serializedEditorState(state: MapEditorState): string | undefined;
46
+ export declare function remapMapEditorState(state: MapEditorState, identities: ReadonlyMap<UUID, UUID>): MapEditorState;
47
+ /** Compare committed layout only; display names, numbering, paints and labels remain editable. */
48
+ export declare function protectedLayoutChanges(before: PhysicalDocumentV1, after: PhysicalDocumentV1, state: MapEditorState): UUID[];
49
+ export {};
@@ -0,0 +1,266 @@
1
+ import { sectionCatalog } from "./sections.js";
2
+ import { z } from "zod";
3
+ import { documentCatalog } from "./catalog.js";
4
+ import { worldMatrices } from "./geometry/geometry.js";
5
+ import { uuidSchema } from "./schema.js";
6
+ export const mapEditorStateSchema = z.strictObject({
7
+ version: z.literal(1),
8
+ lockedIds: z.array(uuidSchema).max(100_000),
9
+ hiddenIds: z.array(uuidSchema).max(100_000),
10
+ });
11
+ export const emptyMapEditorState = {
12
+ version: 1,
13
+ lockedIds: [],
14
+ hiddenIds: [],
15
+ };
16
+ const policies = new WeakMap();
17
+ export class MapEditorPolicy {
18
+ document;
19
+ nodes = new Map();
20
+ rows = new Set();
21
+ parents = new Map();
22
+ lockParents = new Map();
23
+ children = new Map();
24
+ locked;
25
+ hidden;
26
+ lockOwners = new Map();
27
+ hiddenOwners = new Map();
28
+ protectedContainers = new Map();
29
+ constructor(document, state) {
30
+ this.document = document;
31
+ this.locked = new Set(state.lockedIds);
32
+ this.hidden = new Set(state.hiddenIds);
33
+ const owners = sectionCatalog(document).owners;
34
+ for (const node of [
35
+ ...document.collections,
36
+ ...document.sections,
37
+ ...document.seatingGroups,
38
+ ...document.areas,
39
+ ...document.decorations,
40
+ ]) {
41
+ this.nodes.set(node.id, node);
42
+ const structuralParents = "parentId" in node && node.parentId ? [node.parentId] : [];
43
+ this.lockParents.set(node.id, structuralParents);
44
+ const section = owners.get(node.id);
45
+ this.parents.set(node.id, section ? [...structuralParents, section] : structuralParents);
46
+ }
47
+ for (const group of document.seatingGroups) {
48
+ if (!("rows" in group))
49
+ continue;
50
+ for (const row of group.rows) {
51
+ this.nodes.set(row.id, row);
52
+ this.rows.add(row.id);
53
+ this.lockParents.set(row.id, [group.id]);
54
+ const section = owners.get(row.id);
55
+ this.parents.set(row.id, section ? [group.id, section] : [group.id]);
56
+ }
57
+ }
58
+ for (const [id, parents] of this.parents) {
59
+ for (const parent of parents) {
60
+ const children = this.children.get(parent) ?? [];
61
+ children.push(id);
62
+ this.children.set(parent, children);
63
+ }
64
+ }
65
+ for (const id of this.locked) {
66
+ const pending = [id], seen = new Set();
67
+ while (pending.length) {
68
+ const parent = pending.pop();
69
+ if (!parent || seen.has(parent))
70
+ continue;
71
+ seen.add(parent);
72
+ this.protectedContainers.set(parent, id);
73
+ pending.push(...(this.parents.get(parent) ?? []));
74
+ }
75
+ }
76
+ }
77
+ canLock(id) {
78
+ return this.nodes.has(id);
79
+ }
80
+ canHide(id) {
81
+ return this.nodes.has(id);
82
+ }
83
+ childIds(id) {
84
+ return this.children.get(id) ?? [];
85
+ }
86
+ /** Inventory ownership controls visibility; only structural parents pass down position locks. */
87
+ layoutChildIds(id) {
88
+ return this.childIds(id).filter((child) => this.lockParents.get(child)?.includes(id));
89
+ }
90
+ parentIds(id, graph) {
91
+ const parents = graph.get(id);
92
+ if (parents)
93
+ return parents;
94
+ const seat = documentCatalog(this.document).seats.get(id);
95
+ return seat ? [seat.seat.rowId ?? seat.group.id] : [];
96
+ }
97
+ owner(id, flags, cache, parents, visiting = new Set()) {
98
+ if (!flags.size || visiting.has(id))
99
+ return undefined;
100
+ if (cache.has(id))
101
+ return cache.get(id);
102
+ visiting.add(id);
103
+ let owner = flags.has(id) ? id : undefined;
104
+ for (const parent of this.parentIds(id, parents)) {
105
+ owner ??= this.owner(parent, flags, cache, parents, visiting);
106
+ }
107
+ visiting.delete(id);
108
+ cache.set(id, owner);
109
+ return owner;
110
+ }
111
+ lockOwner(id) {
112
+ return this.owner(id, this.locked, this.lockOwners, this.lockParents);
113
+ }
114
+ hiddenOwner(id) {
115
+ return this.owner(id, this.hidden, this.hiddenOwners, this.parents);
116
+ }
117
+ inheritedLockOwner(id) {
118
+ return this.parentIds(id, this.lockParents)
119
+ .map((parent) => this.lockOwner(parent))
120
+ .find((owner) => owner !== undefined);
121
+ }
122
+ inheritedHiddenOwner(id) {
123
+ return this.parentIds(id, this.parents)
124
+ .map((parent) => this.hiddenOwner(parent))
125
+ .find((owner) => owner !== undefined);
126
+ }
127
+ protectedOwner(id) {
128
+ return this.lockOwner(id) ?? this.protectedContainers.get(id);
129
+ }
130
+ }
131
+ export function mapEditorPolicy(document, state) {
132
+ let states = policies.get(document);
133
+ if (!states) {
134
+ states = new WeakMap();
135
+ policies.set(document, states);
136
+ }
137
+ let policy = states.get(state);
138
+ if (!policy) {
139
+ policy = new MapEditorPolicy(document, state);
140
+ states.set(state, policy);
141
+ }
142
+ return policy;
143
+ }
144
+ export function canonicalEditorState(state) {
145
+ return {
146
+ version: 1,
147
+ lockedIds: [...new Set(state.lockedIds)].sort(),
148
+ hiddenIds: [...new Set(state.hiddenIds)].sort(),
149
+ };
150
+ }
151
+ export function parseMapEditorState(document, input) {
152
+ if (input === undefined)
153
+ return emptyMapEditorState;
154
+ const state = mapEditorStateSchema.parse(input);
155
+ const policy = mapEditorPolicy(document, state);
156
+ return canonicalEditorState(mapEditorStateSchema
157
+ .superRefine((value, context) => {
158
+ for (const [key, ids] of [
159
+ ["lockedIds", value.lockedIds],
160
+ ["hiddenIds", value.hiddenIds],
161
+ ]) {
162
+ ids.forEach((id, index) => {
163
+ if (!(key === "lockedIds" ? policy.canLock(id) : policy.canHide(id))) {
164
+ context.addIssue({
165
+ code: "custom",
166
+ path: [key, index],
167
+ message: "Editor state refers to an unsupported or missing object.",
168
+ });
169
+ }
170
+ });
171
+ }
172
+ })
173
+ .parse(state));
174
+ }
175
+ export function pruneMapEditorState(document, state) {
176
+ if (!state.lockedIds.length && !state.hiddenIds.length)
177
+ return emptyMapEditorState;
178
+ const policy = mapEditorPolicy(document, state);
179
+ const next = canonicalEditorState({
180
+ version: 1,
181
+ lockedIds: state.lockedIds.filter((id) => policy.canLock(id)),
182
+ hiddenIds: state.hiddenIds.filter((id) => policy.canHide(id)),
183
+ });
184
+ return JSON.stringify(next) === JSON.stringify(state) ? state : next;
185
+ }
186
+ export function serializedEditorState(state) {
187
+ return state.lockedIds.length || state.hiddenIds.length ? JSON.stringify(canonicalEditorState(state)) : undefined;
188
+ }
189
+ export function remapMapEditorState(state, identities) {
190
+ const remap = (ids) => ids.flatMap((id) => {
191
+ const next = identities.get(id);
192
+ return next ? [next] : [];
193
+ });
194
+ return canonicalEditorState({
195
+ version: 1,
196
+ lockedIds: remap(state.lockedIds),
197
+ hiddenIds: remap(state.hiddenIds),
198
+ });
199
+ }
200
+ const appearanceFields = new Set([
201
+ "name",
202
+ "label",
203
+ "labels",
204
+ "labelOverride",
205
+ "seatSequenceOverride",
206
+ "aisleSeats",
207
+ "buyerNoun",
208
+ "selling",
209
+ "buyerNote",
210
+ "buyerPhoto",
211
+ "gap",
212
+ "seatShape",
213
+ "categoryId",
214
+ "attributes",
215
+ "seatLabelStyle",
216
+ "labelStyle",
217
+ "rowStyle",
218
+ "style",
219
+ "displayLabel",
220
+ "labelPlacement",
221
+ "text",
222
+ "fontSizeM",
223
+ "align",
224
+ "opacity",
225
+ "assetId",
226
+ "iconId",
227
+ "zIndex",
228
+ "capacity",
229
+ ]);
230
+ function layoutValue(value) {
231
+ if (Array.isArray(value))
232
+ return value.map(layoutValue);
233
+ if (value && typeof value === "object")
234
+ return Object.fromEntries(Object.entries(value)
235
+ .filter(([key]) => !appearanceFields.has(key))
236
+ .map(([key, child]) => [key, layoutValue(child)]));
237
+ return value;
238
+ }
239
+ /** Compare committed layout only; display names, numbering, paints and labels remain editable. */
240
+ export function protectedLayoutChanges(before, after, state) {
241
+ if (!state.lockedIds.length)
242
+ return [];
243
+ const previous = mapEditorPolicy(before, state), next = mapEditorPolicy(after, state);
244
+ const beforeMatrices = worldMatrices(before), afterMatrices = worldMatrices(after);
245
+ const changed = new Set();
246
+ for (const [id, node] of previous.nodes) {
247
+ const owner = previous.lockOwner(id);
248
+ if (!owner)
249
+ continue;
250
+ const candidate = next.nodes.get(id);
251
+ const matrixId = previous.rows.has(id) ? (documentCatalog(before).rows.get(id)?.id ?? id) : id;
252
+ const previousValue = {
253
+ layout: layoutValue(node),
254
+ matrix: beforeMatrices.get(matrixId),
255
+ children: [...previous.layoutChildIds(id)].sort(),
256
+ };
257
+ const nextValue = {
258
+ layout: layoutValue(candidate),
259
+ matrix: afterMatrices.get(matrixId),
260
+ children: [...next.layoutChildIds(id)].sort(),
261
+ };
262
+ if (!candidate || JSON.stringify(previousValue) !== JSON.stringify(nextValue))
263
+ changed.add(owner);
264
+ }
265
+ return [...changed];
266
+ }
@@ -0,0 +1,19 @@
1
+ import { type PhysicalDocumentV1, type UUID, type VenueFloor } from "./physical-document.interface.js";
2
+ export type FloorInventory = {
3
+ floor: VenueFloor | null;
4
+ members: readonly UUID[];
5
+ capacity: {
6
+ physicalSeats: number;
7
+ gaQuantity: number;
8
+ };
9
+ gapCount: number;
10
+ };
11
+ export type FloorCatalog = {
12
+ entries: ReadonlyMap<UUID | null, FloorInventory>;
13
+ owners: ReadonlyMap<UUID, UUID | null>;
14
+ };
15
+ /** Derive physical membership and counts once, without creating another editable document. */
16
+ export declare function floorCatalog(document: PhysicalDocumentV1): FloorCatalog;
17
+ /** Resolve seats through their physical owner; logical rows use their first physical part. */
18
+ export declare function objectFloorId(document: PhysicalDocumentV1, id: UUID): UUID | null;
19
+ export declare function floorLabel(floor: VenueFloor): string;