@seatmap-fyi/map-domain 0.1.0-alpha.3 → 0.1.0-alpha.48

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 (109) hide show
  1. package/dist/arc-fan-rebuild.d.ts +13 -0
  2. package/dist/arc-fan-rebuild.js +163 -0
  3. package/dist/arc-fan.d.ts +27 -0
  4. package/dist/arc-fan.interface.d.ts +83 -0
  5. package/dist/arc-fan.interface.js +30 -0
  6. package/dist/arc-fan.js +182 -0
  7. package/dist/catalog.d.ts +10 -3
  8. package/dist/catalog.js +66 -10
  9. package/dist/categories.d.ts +27 -0
  10. package/dist/categories.js +217 -0
  11. package/dist/editor-state.d.ts +4 -1
  12. package/dist/editor-state.js +61 -31
  13. package/dist/floors.d.ts +22 -0
  14. package/dist/floors.js +77 -0
  15. package/dist/geometry/boundary.d.ts +1 -1
  16. package/dist/geometry/boundary.js +16 -12
  17. package/dist/geometry/curve-warnings.d.ts +1 -1
  18. package/dist/geometry/curve-warnings.js +3 -5
  19. package/dist/geometry/decoration-bounds.d.ts +4 -0
  20. package/dist/geometry/decoration-bounds.js +42 -0
  21. package/dist/geometry/ellipse.js +4 -12
  22. package/dist/geometry/geometry.d.ts +12 -3
  23. package/dist/geometry/geometry.js +37 -28
  24. package/dist/geometry/layout-transform.d.ts +10 -0
  25. package/dist/geometry/layout-transform.interface.d.ts +6 -0
  26. package/dist/geometry/layout-transform.interface.js +1 -0
  27. package/dist/geometry/layout-transform.js +206 -0
  28. package/dist/geometry/polygon-curves.d.ts +17 -0
  29. package/dist/geometry/polygon-curves.interface.d.ts +21 -0
  30. package/dist/geometry/polygon-curves.interface.js +5 -0
  31. package/dist/geometry/polygon-curves.js +169 -0
  32. package/dist/geometry/primitives.d.ts +1 -1
  33. package/dist/geometry/primitives.js +2 -3
  34. package/dist/geometry/seat-shape.d.ts +24 -0
  35. package/dist/geometry/seat-shape.js +101 -0
  36. package/dist/geometry/seating-layout.d.ts +20 -3
  37. package/dist/geometry/seating-layout.js +113 -19
  38. package/dist/geometry/units.d.ts +8 -0
  39. package/dist/geometry/units.js +13 -0
  40. package/dist/geometry/venue-outline.d.ts +4 -18
  41. package/dist/geometry/venue-outline.interface.d.ts +23 -0
  42. package/dist/geometry/venue-outline.interface.js +7 -0
  43. package/dist/geometry/venue-outline.js +107 -49
  44. package/dist/identity.d.ts +3 -1
  45. package/dist/identity.js +32 -9
  46. package/dist/issues.d.ts +15 -2
  47. package/dist/issues.js +16 -6
  48. package/dist/labels.d.ts +12 -1
  49. package/dist/labels.js +76 -11
  50. package/dist/layers.d.ts +26 -0
  51. package/dist/layers.js +86 -0
  52. package/dist/media.d.ts +27 -0
  53. package/dist/media.js +89 -0
  54. package/dist/physical-document.interface.d.ts +592 -0
  55. package/dist/physical-document.interface.js +179 -0
  56. package/dist/preview.d.ts +1 -1
  57. package/dist/preview.js +70 -25
  58. package/dist/reference.js +1 -1
  59. package/dist/row-segments.d.ts +30 -0
  60. package/dist/row-segments.js +113 -0
  61. package/dist/schema.d.ts +1578 -68
  62. package/dist/schema.js +467 -98
  63. package/dist/seat-proximity.d.ts +4 -0
  64. package/dist/seat-proximity.js +119 -0
  65. package/dist/section-elevation.d.ts +5 -0
  66. package/dist/section-elevation.interface.d.ts +26 -0
  67. package/dist/section-elevation.interface.js +8 -0
  68. package/dist/section-elevation.js +53 -0
  69. package/dist/section-fill-rebuild.d.ts +10 -0
  70. package/dist/section-fill-rebuild.js +64 -0
  71. package/dist/section-fill.d.ts +84 -0
  72. package/dist/section-fill.interface.d.ts +94 -0
  73. package/dist/section-fill.interface.js +22 -0
  74. package/dist/section-fill.js +306 -0
  75. package/dist/section-growth.d.ts +11 -0
  76. package/dist/section-growth.interface.d.ts +12 -0
  77. package/dist/section-growth.interface.js +1 -0
  78. package/dist/section-growth.js +198 -0
  79. package/dist/section-layout.d.ts +95 -0
  80. package/dist/section-layout.interface.d.ts +8 -0
  81. package/dist/section-layout.interface.js +5 -0
  82. package/dist/section-layout.js +70 -0
  83. package/dist/section-outline-refit.d.ts +8 -0
  84. package/dist/section-outline-refit.js +246 -0
  85. package/dist/section-refit.d.ts +22 -0
  86. package/dist/section-refit.interface.d.ts +49 -0
  87. package/dist/section-refit.interface.js +6 -0
  88. package/dist/section-refit.js +179 -0
  89. package/dist/section-scale.d.ts +2 -0
  90. package/dist/section-scale.js +128 -0
  91. package/dist/sections.d.ts +23 -0
  92. package/dist/sections.js +144 -0
  93. package/dist/selling.d.ts +34 -0
  94. package/dist/selling.js +148 -0
  95. package/dist/spacing-repairs.d.ts +31 -0
  96. package/dist/spacing-repairs.js +168 -0
  97. package/dist/table-layout.d.ts +29 -0
  98. package/dist/table-layout.js +134 -0
  99. package/dist/validation.d.ts +7 -2
  100. package/dist/validation.interface.d.ts +20 -0
  101. package/dist/validation.interface.js +9 -0
  102. package/dist/validation.js +227 -78
  103. package/dist/wayfinding.d.ts +10 -0
  104. package/dist/wayfinding.interface.d.ts +52 -0
  105. package/dist/wayfinding.interface.js +28 -0
  106. package/dist/wayfinding.js +63 -0
  107. package/package.json +109 -4
  108. package/dist/types.d.ts +0 -313
  109. package/dist/types.js +0 -91
@@ -0,0 +1,217 @@
1
+ import { AreaKind, SeatShape, SeatingKind } from "./physical-document.interface.js";
2
+ import { issue, IssueCode, IssueSeverity } from "./issues.js";
3
+ import { rowDisplayLabel } from "./labels.js";
4
+ const catalogs = new WeakMap();
5
+ export function categoryCatalog(document) {
6
+ let catalog = catalogs.get(document);
7
+ if (!catalog) {
8
+ catalog = new Map((document.categories ?? []).map((category) => [category.id, category]));
9
+ catalogs.set(document, catalog);
10
+ }
11
+ return catalog;
12
+ }
13
+ /** Absence inherits; explicit null records an unassigned child. */
14
+ export function seatCategoryId(group, slot, row) {
15
+ if (slot.categoryId !== undefined)
16
+ return slot.categoryId;
17
+ if (row?.categoryId !== undefined)
18
+ return row.categoryId;
19
+ return group.categoryId ?? null;
20
+ }
21
+ export function* categoryReferences(groups) {
22
+ for (const group of groups) {
23
+ if (group.categoryId)
24
+ yield { id: group.id, categoryId: group.categoryId };
25
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved) {
26
+ for (const row of group.rows) {
27
+ if (row.categoryId)
28
+ yield { id: row.id, categoryId: row.categoryId };
29
+ for (const slot of row.seats)
30
+ if (slot.categoryId)
31
+ yield { id: slot.id, categoryId: slot.categoryId };
32
+ }
33
+ }
34
+ else {
35
+ const seats = group.kind === SeatingKind.Round ? group.chairs : Object.values(group.chairsBySide).flat();
36
+ for (const slot of seats)
37
+ if (slot.categoryId)
38
+ yield { id: slot.id, categoryId: slot.categoryId };
39
+ }
40
+ }
41
+ }
42
+ const categoryFindings = new WeakMap();
43
+ export function missingCategoryLabel(places) {
44
+ return `${places} ${places === 1 ? "place has" : "places have"} no category`;
45
+ }
46
+ /** Unresolved catalogue references are repairable draft findings, not invalid physical structure. */
47
+ export function categoryIssues(document) {
48
+ const cached = categoryFindings.get(document);
49
+ if (cached)
50
+ return cached;
51
+ const categories = new Set((document.categories ?? []).map((category) => category.id));
52
+ const byOwner = new Map();
53
+ const check = (id, categoryId, ownerId) => {
54
+ if (categoryId && !categories.has(categoryId))
55
+ byOwner.set(id, issue(IssueCode.UnknownCategory, "Unknown category", [id], `${ownerId}.categoryId`));
56
+ };
57
+ const missingRows = [];
58
+ let missingPlaces = 0;
59
+ const seatWarnings = [];
60
+ for (const group of document.seatingGroups) {
61
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved) {
62
+ group.rows.forEach((row, index) => {
63
+ let missing = 0;
64
+ let unknownSeats = 0;
65
+ let unknownRowCategory;
66
+ for (const slot of row.seats) {
67
+ if (slot.gap)
68
+ continue;
69
+ const categoryId = seatCategoryId(group, slot, row);
70
+ if (categoryId === null)
71
+ missing++;
72
+ else if (!categories.has(categoryId)) {
73
+ if (slot.categoryId === undefined)
74
+ unknownRowCategory = categoryId;
75
+ else
76
+ unknownSeats++;
77
+ }
78
+ }
79
+ if (missing) {
80
+ missingRows.push(row.id);
81
+ missingPlaces += missing;
82
+ }
83
+ if (unknownRowCategory) {
84
+ const label = rowDisplayLabel(group, index);
85
+ const message = `"${label}" references unknown category "${unknownRowCategory}"`;
86
+ const referenceId = row.categoryId === undefined ? group.id : row.id;
87
+ byOwner.set(row.id, {
88
+ ...issue(IssueCode.UnknownCategory, message, [row.id], `${referenceId}.categoryId`),
89
+ description: message,
90
+ });
91
+ }
92
+ if (unknownSeats) {
93
+ const rowName = `Row “${rowDisplayLabel(group, index)}”`;
94
+ const seats = unknownSeats === 1 ? "seat" : "seats";
95
+ seatWarnings.push({
96
+ ...issue(IssueCode.UnknownSeatCategory, `${rowName} has ${unknownSeats} ${seats} with no category`, [
97
+ row.id,
98
+ ]),
99
+ severity: IssueSeverity.Warning,
100
+ description: `${unknownSeats} ${seats} in ${rowName} have no category, so buyers see no price or colour for them.`,
101
+ blocks: [],
102
+ });
103
+ }
104
+ });
105
+ }
106
+ else {
107
+ const slots = group.kind === SeatingKind.Round ? group.chairs : Object.values(group.chairsBySide).flat();
108
+ for (const slot of slots) {
109
+ if (slot.gap)
110
+ continue;
111
+ const ownerId = slot.categoryId !== undefined ? slot.id : group.id;
112
+ check(ownerId, seatCategoryId(group, slot), ownerId);
113
+ }
114
+ }
115
+ }
116
+ for (const entity of [...document.areas, ...document.sections])
117
+ check(entity.id, entity.categoryId, entity.id);
118
+ const findings = [...byOwner.values(), ...seatWarnings];
119
+ if (missingPlaces) {
120
+ findings.unshift({
121
+ ...issue(IssueCode.MissingCategory, missingCategoryLabel(missingPlaces), missingRows),
122
+ severity: IssueSeverity.Warning,
123
+ blocks: [],
124
+ });
125
+ }
126
+ const uses = categoryUsage(document);
127
+ for (const category of document.categories ?? []) {
128
+ if (!uses.get(category.id) || !categoryPricing(category).missing)
129
+ continue;
130
+ const message = `Category "${category.name}" has no default price. Each event sets its price before it goes on sale`;
131
+ findings.push({
132
+ ...issue(IssueCode.MissingCategoryPrice, message, [category.id], `${category.id}.defaultPrice`),
133
+ severity: IssueSeverity.Warning,
134
+ description: message,
135
+ blocks: [],
136
+ });
137
+ }
138
+ categoryFindings.set(document, findings);
139
+ return findings;
140
+ }
141
+ /** Fragment paste reuses catalogue identity; whole-map copy remaps it with the map. */
142
+ export function remapGroupCategories(group, ids) {
143
+ const remap = (value) => {
144
+ const categoryId = value.categoryId ? ids.get(value.categoryId) : undefined;
145
+ return categoryId && categoryId !== value.categoryId ? { ...value, categoryId } : value;
146
+ };
147
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved)
148
+ return {
149
+ ...remap(group),
150
+ rows: group.rows.map((row) => ({
151
+ ...remap(row),
152
+ seats: row.seats.map(remap),
153
+ })),
154
+ };
155
+ if (group.kind === SeatingKind.Round)
156
+ return { ...remap(group), chairs: group.chairs.map(remap) };
157
+ return {
158
+ ...remap(group),
159
+ chairsBySide: {
160
+ top: group.chairsBySide.top.map(remap),
161
+ right: group.chairsBySide.right.map(remap),
162
+ bottom: group.chairsBySide.bottom.map(remap),
163
+ left: group.chairsBySide.left.map(remap),
164
+ },
165
+ };
166
+ }
167
+ const usage = new WeakMap();
168
+ export function categoryUsage(document) {
169
+ const cached = usage.get(document);
170
+ if (cached)
171
+ return cached;
172
+ const counts = new Map();
173
+ const count = (id, quantity = 1) => {
174
+ if (id)
175
+ counts.set(id, (counts.get(id) ?? 0) + quantity);
176
+ };
177
+ for (const group of document.seatingGroups) {
178
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved) {
179
+ for (const row of group.rows)
180
+ for (const slot of row.seats)
181
+ if (!slot.gap)
182
+ count(seatCategoryId(group, slot, row));
183
+ }
184
+ else {
185
+ const slots = group.kind === SeatingKind.Round ? group.chairs : Object.values(group.chairsBySide).flat();
186
+ for (const slot of slots)
187
+ if (!slot.gap)
188
+ count(seatCategoryId(group, slot));
189
+ }
190
+ }
191
+ for (const area of document.areas)
192
+ count(area.categoryId ?? null, area.kind === AreaKind.Booth ? 1 : area.capacity);
193
+ usage.set(document, counts);
194
+ return counts;
195
+ }
196
+ export function ticketOptionNameKey(name) {
197
+ return name.trim().toLowerCase();
198
+ }
199
+ export function categoryPricing(category) {
200
+ const options = category.ticketOptions ?? [];
201
+ const prices = options.length
202
+ ? options.map((option) => option.price)
203
+ : category.defaultPrice == null
204
+ ? []
205
+ : [category.defaultPrice];
206
+ return {
207
+ onSale: category.onSale !== false,
208
+ optionCount: options.length,
209
+ minimum: prices.length ? Math.min(...prices) : null,
210
+ maximum: prices.length ? Math.max(...prices) : null,
211
+ missing: category.onSale !== false && !prices.length,
212
+ };
213
+ }
214
+ /** A personal circle remains an override; absence inherits the category shape. */
215
+ export function categorySeatShape(category, slot) {
216
+ return slot?.seatShape ?? category?.seatShape ?? SeatShape.Circle;
217
+ }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import type { PhysicalDocumentV1, UUID } from "./types.js";
2
+ import { type PhysicalDocumentV1, type UUID } from "./physical-document.interface.js";
3
3
  export declare const mapEditorStateSchema: z.ZodObject<{
4
4
  version: z.ZodLiteral<1>;
5
5
  lockedIds: z.ZodArray<z.ZodString>;
@@ -17,6 +17,7 @@ export declare class MapEditorPolicy {
17
17
  readonly nodes: Map<string, EditorNode>;
18
18
  readonly rows: Set<string>;
19
19
  private readonly parents;
20
+ private readonly lockParents;
20
21
  private readonly children;
21
22
  private readonly locked;
22
23
  private readonly hidden;
@@ -27,6 +28,8 @@ export declare class MapEditorPolicy {
27
28
  canLock(id: UUID): boolean;
28
29
  canHide(id: UUID): boolean;
29
30
  childIds(id: UUID): readonly UUID[];
31
+ /** Inventory ownership controls visibility; only structural parents pass down position locks. */
32
+ layoutChildIds(id: UUID): readonly UUID[];
30
33
  private parentIds;
31
34
  private owner;
32
35
  lockOwner(id: UUID): UUID | undefined;
@@ -1,7 +1,9 @@
1
+ import { sectionCatalog } from "./sections.js";
1
2
  import { z } from "zod";
2
3
  import { documentCatalog } from "./catalog.js";
3
4
  import { worldMatrices } from "./geometry/geometry.js";
4
5
  import { uuidSchema } from "./schema.js";
6
+ import { DecorationKind } from "./physical-document.interface.js";
5
7
  export const mapEditorStateSchema = z.strictObject({
6
8
  version: z.literal(1),
7
9
  lockedIds: z.array(uuidSchema).max(100_000),
@@ -18,6 +20,7 @@ export class MapEditorPolicy {
18
20
  nodes = new Map();
19
21
  rows = new Set();
20
22
  parents = new Map();
23
+ lockParents = new Map();
21
24
  children = new Map();
22
25
  locked;
23
26
  hidden;
@@ -28,6 +31,7 @@ export class MapEditorPolicy {
28
31
  this.document = document;
29
32
  this.locked = new Set(state.lockedIds);
30
33
  this.hidden = new Set(state.hiddenIds);
34
+ const owners = sectionCatalog(document).owners;
31
35
  for (const node of [
32
36
  ...document.collections,
33
37
  ...document.sections,
@@ -36,11 +40,10 @@ export class MapEditorPolicy {
36
40
  ...document.decorations,
37
41
  ]) {
38
42
  this.nodes.set(node.id, node);
39
- const parents = [
40
- "parentId" in node ? node.parentId : null,
41
- "sectionId" in node ? node.sectionId : null,
42
- ].filter((id) => !!id);
43
- this.parents.set(node.id, parents);
43
+ const structuralParents = "parentId" in node && node.parentId ? [node.parentId] : [];
44
+ this.lockParents.set(node.id, structuralParents);
45
+ const section = owners.get(node.id);
46
+ this.parents.set(node.id, section ? [...structuralParents, section] : structuralParents);
44
47
  }
45
48
  for (const group of document.seatingGroups) {
46
49
  if (!("rows" in group))
@@ -48,7 +51,9 @@ export class MapEditorPolicy {
48
51
  for (const row of group.rows) {
49
52
  this.nodes.set(row.id, row);
50
53
  this.rows.add(row.id);
51
- this.parents.set(row.id, [group.id]);
54
+ this.lockParents.set(row.id, [group.id]);
55
+ const section = owners.get(row.id);
56
+ this.parents.set(row.id, section ? [group.id, section] : [group.id]);
52
57
  }
53
58
  }
54
59
  for (const [id, parents] of this.parents) {
@@ -71,7 +76,7 @@ export class MapEditorPolicy {
71
76
  }
72
77
  }
73
78
  canLock(id) {
74
- return this.nodes.has(id) && !this.rows.has(id);
79
+ return this.nodes.has(id);
75
80
  }
76
81
  canHide(id) {
77
82
  return this.nodes.has(id);
@@ -79,40 +84,44 @@ export class MapEditorPolicy {
79
84
  childIds(id) {
80
85
  return this.children.get(id) ?? [];
81
86
  }
82
- parentIds(id) {
83
- const parents = this.parents.get(id);
87
+ /** Inventory ownership controls visibility; only structural parents pass down position locks. */
88
+ layoutChildIds(id) {
89
+ return this.childIds(id).filter((child) => this.lockParents.get(child)?.includes(id));
90
+ }
91
+ parentIds(id, graph) {
92
+ const parents = graph.get(id);
84
93
  if (parents)
85
94
  return parents;
86
95
  const seat = documentCatalog(this.document).seats.get(id);
87
96
  return seat ? [seat.seat.rowId ?? seat.group.id] : [];
88
97
  }
89
- owner(id, flags, cache, visiting = new Set()) {
98
+ owner(id, flags, cache, parents, visiting = new Set()) {
90
99
  if (!flags.size || visiting.has(id))
91
100
  return undefined;
92
101
  if (cache.has(id))
93
102
  return cache.get(id);
94
103
  visiting.add(id);
95
104
  let owner = flags.has(id) ? id : undefined;
96
- for (const parent of this.parentIds(id)) {
97
- owner ??= this.owner(parent, flags, cache, visiting);
105
+ for (const parent of this.parentIds(id, parents)) {
106
+ owner ??= this.owner(parent, flags, cache, parents, visiting);
98
107
  }
99
108
  visiting.delete(id);
100
109
  cache.set(id, owner);
101
110
  return owner;
102
111
  }
103
112
  lockOwner(id) {
104
- return this.owner(id, this.locked, this.lockOwners);
113
+ return this.owner(id, this.locked, this.lockOwners, this.lockParents);
105
114
  }
106
115
  hiddenOwner(id) {
107
- return this.owner(id, this.hidden, this.hiddenOwners);
116
+ return this.owner(id, this.hidden, this.hiddenOwners, this.parents);
108
117
  }
109
118
  inheritedLockOwner(id) {
110
- return this.parentIds(id)
119
+ return this.parentIds(id, this.lockParents)
111
120
  .map((parent) => this.lockOwner(parent))
112
121
  .find((owner) => owner !== undefined);
113
122
  }
114
123
  inheritedHiddenOwner(id) {
115
- return this.parentIds(id)
124
+ return this.parentIds(id, this.parents)
116
125
  .map((parent) => this.hiddenOwner(parent))
117
126
  .find((owner) => owner !== undefined);
118
127
  }
@@ -176,9 +185,7 @@ export function pruneMapEditorState(document, state) {
176
185
  return JSON.stringify(next) === JSON.stringify(state) ? state : next;
177
186
  }
178
187
  export function serializedEditorState(state) {
179
- return state.lockedIds.length || state.hiddenIds.length
180
- ? JSON.stringify(canonicalEditorState(state))
181
- : undefined;
188
+ return state.lockedIds.length || state.hiddenIds.length ? JSON.stringify(canonicalEditorState(state)) : undefined;
182
189
  }
183
190
  export function remapMapEditorState(state, identities) {
184
191
  const remap = (ids) => ids.flatMap((id) => {
@@ -191,16 +198,25 @@ export function remapMapEditorState(state, identities) {
191
198
  hiddenIds: remap(state.hiddenIds),
192
199
  });
193
200
  }
194
- const appearanceFields = new Set([
201
+ const nonLayoutFields = new Set([
195
202
  "name",
196
203
  "label",
197
204
  "labels",
198
205
  "labelOverride",
199
206
  "seatSequenceOverride",
207
+ "aisleSeats",
208
+ "buyerNoun",
209
+ "selling",
210
+ "buyerNote",
211
+ "buyerPhoto",
212
+ "gap",
213
+ "seatShape",
214
+ "categoryId",
200
215
  "attributes",
201
216
  "seatLabelStyle",
202
217
  "labelStyle",
203
218
  "rowStyle",
219
+ "rowRefitStrength",
204
220
  "style",
205
221
  "displayLabel",
206
222
  "labelPlacement",
@@ -212,14 +228,26 @@ const appearanceFields = new Set([
212
228
  "iconId",
213
229
  "zIndex",
214
230
  "capacity",
231
+ "gate",
232
+ "entrance",
233
+ "route",
234
+ "lineCap",
235
+ "lineJoin",
236
+ "startEnding",
237
+ "endEnding",
215
238
  ]);
239
+ const decorationKinds = new Set(Object.values(DecorationKind));
216
240
  function layoutValue(value) {
217
241
  if (Array.isArray(value))
218
242
  return value.map(layoutValue);
219
- if (value && typeof value === "object")
243
+ if (value && typeof value === "object") {
244
+ // Authored extrusion height is separate from a drawable's locked 2D footprint.
245
+ const decoration = "id" in value && "kind" in value && typeof value.kind === "string" && decorationKinds.has(value.kind);
220
246
  return Object.fromEntries(Object.entries(value)
221
- .filter(([key]) => !appearanceFields.has(key))
247
+ .filter(([key]) => !nonLayoutFields.has(key) && !(decoration && key === "heightM"))
248
+ .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
222
249
  .map(([key, child]) => [key, layoutValue(child)]));
250
+ }
223
251
  return value;
224
252
  }
225
253
  /** Compare committed layout only; display names, numbering, paints and labels remain editable. */
@@ -234,21 +262,23 @@ export function protectedLayoutChanges(before, after, state) {
234
262
  if (!owner)
235
263
  continue;
236
264
  const candidate = next.nodes.get(id);
237
- const matrixId = previous.rows.has(id)
238
- ? (documentCatalog(before).rows.get(id)?.id ?? id)
239
- : id;
265
+ const ownerId = previous.rows.has(id) ? (documentCatalog(before).rows.get(id)?.id ?? id) : id;
266
+ const nextOwnerId = next.rows.has(id) ? (documentCatalog(after).rows.get(id)?.id ?? id) : id;
267
+ if (!candidate || ownerId !== nextOwnerId) {
268
+ changed.add(owner);
269
+ continue;
270
+ }
240
271
  const previousValue = {
241
272
  layout: layoutValue(node),
242
- matrix: beforeMatrices.get(matrixId),
243
- children: [...previous.childIds(id)].sort(),
273
+ matrix: beforeMatrices.get(ownerId),
274
+ children: [...previous.layoutChildIds(id)].sort(),
244
275
  };
245
276
  const nextValue = {
246
277
  layout: layoutValue(candidate),
247
- matrix: afterMatrices.get(matrixId),
248
- children: [...next.childIds(id)].sort(),
278
+ matrix: afterMatrices.get(nextOwnerId),
279
+ children: [...next.layoutChildIds(id)].sort(),
249
280
  };
250
- if (!candidate ||
251
- JSON.stringify(previousValue) !== JSON.stringify(nextValue))
281
+ if (JSON.stringify(previousValue) !== JSON.stringify(nextValue))
252
282
  changed.add(owner);
253
283
  }
254
284
  return [...changed];
@@ -0,0 +1,22 @@
1
+ import { type PhysicalDocumentV1, type PointM, 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;
20
+ export declare const DefaultFloorFocalPoint: Readonly<PointM>;
21
+ export declare function authoredFloorFocalPoint(document: PhysicalDocumentV1, floorId: UUID | null): PointM | undefined;
22
+ export declare function sameFocalPoint(first: PointM | undefined, second: PointM | undefined): boolean;
package/dist/floors.js ADDED
@@ -0,0 +1,77 @@
1
+ import { documentCatalog } from "./catalog.js";
2
+ import { groupInventoryCount } from "./schema.js";
3
+ import { LayoutUnitM } from "./geometry/units.js";
4
+ import { AreaKind, } from "./physical-document.interface.js";
5
+ const catalogs = new WeakMap();
6
+ /** Derive physical membership and counts once, without creating another editable document. */
7
+ export function floorCatalog(document) {
8
+ const cached = catalogs.get(document);
9
+ if (cached)
10
+ return cached;
11
+ const entries = new Map();
12
+ const owners = new Map();
13
+ for (const floor of document.floors ?? [])
14
+ entries.set(floor.id, { floor, members: [], capacity: { physicalSeats: 0, gaQuantity: 0 }, gapCount: 0 });
15
+ if (!document.floors)
16
+ entries.set(null, { floor: null, members: [], capacity: { physicalSeats: 0, gaQuantity: 0 }, gapCount: 0 });
17
+ for (const member of [
18
+ ...document.sections,
19
+ ...document.collections,
20
+ ...document.seatingGroups,
21
+ ...document.areas,
22
+ ...document.decorations,
23
+ ]) {
24
+ const id = member.floorId ?? null;
25
+ owners.set(member.id, id);
26
+ entries.get(id).members.push(member.id);
27
+ }
28
+ for (const group of document.seatingGroups) {
29
+ const id = group.floorId ?? null;
30
+ const entry = entries.get(id);
31
+ const inventoryCount = groupInventoryCount(group);
32
+ let slotCount = 0;
33
+ if ("rows" in group) {
34
+ for (const row of group.rows) {
35
+ owners.set(row.id, id);
36
+ slotCount += row.seats.length;
37
+ }
38
+ }
39
+ else if ("chairs" in group)
40
+ slotCount = group.chairs.length;
41
+ else
42
+ for (const side of Object.values(group.chairsBySide))
43
+ slotCount += side.length;
44
+ entry.capacity.physicalSeats += inventoryCount;
45
+ entry.gapCount += slotCount - inventoryCount;
46
+ }
47
+ for (const area of document.areas) {
48
+ const count = entries.get(area.floorId ?? null).capacity;
49
+ if (area.kind === AreaKind.Booth)
50
+ count.physicalSeats++;
51
+ else
52
+ count.gaQuantity += area.capacity;
53
+ }
54
+ for (const row of document.segmentedRows ?? [])
55
+ owners.set(row.id, owners.get(row.parts[0].rowId));
56
+ const catalog = { entries, owners };
57
+ catalogs.set(document, catalog);
58
+ return catalog;
59
+ }
60
+ /** Resolve seats through their physical owner; logical rows use their first physical part. */
61
+ export function objectFloorId(document, id) {
62
+ const owners = floorCatalog(document).owners;
63
+ if (owners.has(id))
64
+ return owners.get(id);
65
+ return documentCatalog(document).seats.get(id)?.group.floorId ?? null;
66
+ }
67
+ export function floorLabel(floor) {
68
+ return /^\d+$/u.test(floor.name) ? `Floor ${floor.name}` : floor.name;
69
+ }
70
+ const DefaultFocalOffset = 40 * LayoutUnitM;
71
+ export const DefaultFloorFocalPoint = Object.freeze({ x: 0, y: -DefaultFocalOffset });
72
+ export function authoredFloorFocalPoint(document, floorId) {
73
+ return document.floors?.find((floor) => floor.id === floorId)?.focalPoint;
74
+ }
75
+ export function sameFocalPoint(first, second) {
76
+ return first?.x === second?.x && first?.y === second?.y;
77
+ }
@@ -1,4 +1,4 @@
1
- import type { PointM, PolygonM } from "../types.js";
1
+ import type { PointM, PolygonM } from "../physical-document.interface.js";
2
2
  import { type Bounds } from "./primitives.js";
3
3
  export declare enum BoundaryLocation {
4
4
  Inside = "inside",
@@ -1,4 +1,5 @@
1
- import { containsPoint, pointsBounds, intersects, } from "./primitives.js";
1
+ import { polygonContour } from "./polygon-curves.js";
2
+ import { containsPoint, pointsBounds, intersects } from "./primitives.js";
2
3
  export var BoundaryLocation;
3
4
  (function (BoundaryLocation) {
4
5
  BoundaryLocation["Inside"] = "inside";
@@ -11,10 +12,11 @@ export function prepareBoundary(polygon) {
11
12
  const cached = prepared.get(polygon);
12
13
  if (cached)
13
14
  return cached;
15
+ const contour = polygonContour(polygon);
14
16
  const boundary = {
15
- polygon,
16
- bounds: pointsBounds(polygon.outer),
17
- edges: [polygon.outer, ...polygon.holes].flatMap((r) => r.map((a, i) => ({
17
+ polygon: contour,
18
+ bounds: pointsBounds(contour.outer),
19
+ edges: [contour.outer, ...contour.holes].flatMap((r) => r.map((a, i) => ({
18
20
  a,
19
21
  b: r[(i + 1) % r.length],
20
22
  bounds: pointsBounds([a, r[(i + 1) % r.length]]),
@@ -24,16 +26,19 @@ export function prepareBoundary(polygon) {
24
26
  return boundary;
25
27
  }
26
28
  function onEdge(edge, p) {
27
- const dx = edge.b.x - edge.a.x, dy = edge.b.y - edge.a.y, t = Math.max(0, Math.min(1, ((p.x - edge.a.x) * dx + (p.y - edge.a.y) * dy) /
28
- Math.max(1e-30, dx * dx + dy * dy)));
29
- return (Math.hypot(p.x - edge.a.x - t * dx, p.y - edge.a.y - t * dy) <=
30
- BoundaryToleranceM);
29
+ const dx = edge.b.x - edge.a.x, dy = edge.b.y - edge.a.y, t = Math.max(0, Math.min(1, ((p.x - edge.a.x) * dx + (p.y - edge.a.y) * dy) / Math.max(1e-30, dx * dx + dy * dy)));
30
+ return Math.hypot(p.x - edge.a.x - t * dx, p.y - edge.a.y - t * dy) <= BoundaryToleranceM;
31
31
  }
32
32
  export function classifyBoundary(boundary, p) {
33
+ const { minX, minY, maxX, maxY } = boundary.bounds;
34
+ if (p.x < minX - BoundaryToleranceM ||
35
+ p.x > maxX + BoundaryToleranceM ||
36
+ p.y < minY - BoundaryToleranceM ||
37
+ p.y > maxY + BoundaryToleranceM)
38
+ return BoundaryLocation.Outside;
33
39
  if (boundary.edges.some((e) => onEdge(e, p)))
34
40
  return BoundaryLocation.Boundary;
35
- if (!containsPoint(boundary.polygon.outer, p) ||
36
- boundary.polygon.holes.some((h) => containsPoint(h, p)))
41
+ if (!containsPoint(boundary.polygon.outer, p) || boundary.polygon.holes.some((h) => containsPoint(h, p)))
37
42
  return BoundaryLocation.Outside;
38
43
  return BoundaryLocation.Inside;
39
44
  }
@@ -55,8 +60,7 @@ export function footprintInBoundary(boundary, points) {
55
60
  cuts.sort((l, r) => l - r);
56
61
  for (let j = 1; j < cuts.length; j++) {
57
62
  const t = (cuts[j - 1] + cuts[j]) / 2;
58
- if (classifyBoundary(boundary, { x: a.x + t * dx, y: a.y + t * dy }) ===
59
- BoundaryLocation.Outside)
63
+ if (classifyBoundary(boundary, { x: a.x + t * dx, y: a.y + t * dy }) === BoundaryLocation.Outside)
60
64
  return false;
61
65
  }
62
66
  }
@@ -1,4 +1,4 @@
1
- import { type CurvedRows, type RowSlot } from "../types.js";
1
+ import { type CurvedRows, type RowSlot } from "../physical-document.interface.js";
2
2
  export declare enum CurveWarningKind {
3
3
  Overrun = "overrun",
4
4
  Clearance = "clearance"
@@ -1,4 +1,4 @@
1
- import { CurveMode, SeatingKind, } from "../types.js";
1
+ import { CurveMode, SeatingKind } from "../physical-document.interface.js";
2
2
  import { ellipsePerimeter } from "./ellipse.js";
3
3
  import { rowSeatGeometry } from "./seating-layout.js";
4
4
  export var CurveWarningKind;
@@ -13,8 +13,7 @@ export function curveWarnings(recipe, counts, size, slots) {
13
13
  for (let row = 0; row < counts.length; row++) {
14
14
  const count = counts[row], b = recipe.innerRadiusM + row * recipe.rowPitchM, a = recipe.innerRadiusM * (recipe.axisRatio ?? 1) + row * recipe.rowPitchM;
15
15
  if (recipe.placement.kind === CurveMode.Pitch &&
16
- (count - 1) * recipe.placement.seatPitchM + size.width >
17
- ellipsePerimeter(a, b)) {
16
+ (count - 1) * recipe.placement.seatPitchM + size.width > ellipsePerimeter(a, b)) {
18
17
  warnings.push({
19
18
  kind: CurveWarningKind.Overrun,
20
19
  row,
@@ -30,8 +29,7 @@ export function curveWarnings(recipe, counts, size, slots) {
30
29
  }, seatSize = slot?.override?.sizeM ?? size;
31
30
  if (previous &&
32
31
  Math.hypot(point.x - previous.point.x, point.y - previous.point.y) <
33
- Math.min(previous.size.width + seatSize.width, previous.size.height + seatSize.height) /
34
- 2) {
32
+ Math.min(previous.size.width + seatSize.width, previous.size.height + seatSize.height) / 2) {
35
33
  warnings.push({
36
34
  kind: CurveWarningKind.Clearance,
37
35
  row,
@@ -0,0 +1,4 @@
1
+ import { type Decoration } from "../physical-document.interface.js";
2
+ import { type Bounds, type Matrix } from "./geometry.js";
3
+ /** World bounds of the physical artwork, independent of editor selection and section ownership. */
4
+ export declare function decorationBounds(decoration: Decoration, matrix: Matrix): Bounds;