@seatmap-fyi/map-domain 0.1.0-alpha.2 → 0.1.0-alpha.4

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.
package/dist/catalog.d.ts CHANGED
@@ -1,13 +1,18 @@
1
- import type { PhysicalDocumentV1, SeatingGroup, UUID } from "./types.js";
1
+ import type { PhysicalDocumentV1, SeatingGroup, InventoryArea, UUID } from "./types.js";
2
+ import { type SegmentedRowEntry } from "./row-segments.js";
2
3
  import { type GeneratedSeat } from "./geometry/geometry.js";
3
4
  export declare function generatedSeats(group: SeatingGroup): readonly GeneratedSeat[];
5
+ /** Geometry remains shared; logical addresses are projected from the current document. */
6
+ export declare function documentGroupSeats(document: PhysicalDocumentV1, group: SeatingGroup): readonly GeneratedSeat[];
4
7
  export type DocumentCatalog = {
5
8
  groups: ReadonlyMap<UUID, SeatingGroup>;
9
+ areas: ReadonlyMap<UUID, InventoryArea>;
6
10
  seats: ReadonlyMap<UUID, {
7
11
  group: SeatingGroup;
8
12
  seat: GeneratedSeat;
9
13
  }>;
10
14
  rows: ReadonlyMap<UUID, SeatingGroup>;
15
+ segmentedRows: ReadonlyMap<UUID, SegmentedRowEntry>;
11
16
  sections: ReadonlyMap<UUID, string>;
12
17
  };
13
18
  /** Immutable, derived lookup; never an editable store. Untouched group geometry is shared. */
package/dist/catalog.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { rowSegments } from "./row-segments.js";
2
+ import { sequenceLabel } from "./labels.js";
1
3
  import { generateGroup } from "./geometry/geometry.js";
2
4
  const generated = new WeakMap();
3
5
  export function generatedSeats(group) {
@@ -8,6 +10,38 @@ export function generatedSeats(group) {
8
10
  }
9
11
  return cached;
10
12
  }
13
+ const documentSeats = new WeakMap();
14
+ /** Geometry remains shared; logical addresses are projected from the current document. */
15
+ export function documentGroupSeats(document, group) {
16
+ let cache = documentSeats.get(document);
17
+ if (!cache) {
18
+ cache = new Map();
19
+ documentSeats.set(document, cache);
20
+ }
21
+ const cached = cache.get(group);
22
+ if (cached)
23
+ return cached;
24
+ const segments = rowSegments(document);
25
+ const ordinals = new Map();
26
+ const result = generatedSeats(group).map((seat) => {
27
+ const segment = seat.rowId ? segments.get(seat.rowId) : undefined;
28
+ if (!segment)
29
+ return seat;
30
+ const ordinal = ordinals.get(segment.part.id) ?? 0;
31
+ ordinals.set(segment.part.id, ordinal + 1);
32
+ return {
33
+ ...seat,
34
+ label: seat.slot.labelOverride ??
35
+ sequenceLabel(segment.row.sequence, segment.firstIndex + ordinal, segment.totalSeats),
36
+ logicalRowId: segment.row.id,
37
+ logicalRowLabel: segment.row.label,
38
+ logicalPartIndex: segment.partIndex,
39
+ logicalSequence: segment.row.sequence,
40
+ };
41
+ });
42
+ cache.set(group, result);
43
+ return result;
44
+ }
11
45
  const catalogs = new WeakMap();
12
46
  /** Immutable, derived lookup; never an editable store. Untouched group geometry is shared. */
13
47
  export function documentCatalog(document) {
@@ -16,20 +50,28 @@ export function documentCatalog(document) {
16
50
  return catalog;
17
51
  const groups = new Map(document.seatingGroups.map((g) => [g.id, g])), seats = new Map(), rows = new Map();
18
52
  for (const group of document.seatingGroups)
19
- for (const seat of generatedSeats(group)) {
53
+ for (const seat of documentGroupSeats(document, group)) {
20
54
  seats.set(seat.id, { group, seat });
21
55
  if (seat.rowId)
22
56
  rows.set(seat.rowId, group);
23
57
  }
24
58
  catalog = {
25
59
  groups,
60
+ areas: new Map(document.areas.map((area) => [area.id, area])),
26
61
  seats,
27
62
  rows,
63
+ segmentedRows: new Map((document.segmentedRows ?? []).map((row) => [
64
+ row.id,
65
+ {
66
+ row,
67
+ parts: row.parts.map((part) => rowSegments(document).get(part.rowId)),
68
+ },
69
+ ])),
28
70
  sections: new Map(document.sections.map((s) => [s.id, s.label])),
29
71
  };
30
72
  catalogs.set(document, catalog);
31
73
  return catalog;
32
74
  }
33
75
  export function inventoryAddress(document, seat) {
34
- return `${documentCatalog(document).sections.get(seat.sectionId ?? "") ?? "Unsectioned"}, ${seat.rowId ? "row" : "table"} ${seat.ownerLabel}, seat ${seat.label}`;
76
+ return `${documentCatalog(document).sections.get(seat.sectionId ?? "") ?? "Unsectioned"}, ${seat.rowId ? "row" : "table"} ${seat.logicalRowLabel ?? seat.ownerLabel}, seat ${seat.label}`;
35
77
  }
@@ -0,0 +1,25 @@
1
+ import type { MapCategory, PhysicalDocumentV1, RowSlot, SeatingGroup, SeatSlot, UUID } from "./types.js";
2
+ import { SeatShape } from "./types.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
+ export declare function categoryIssues(document: PhysicalDocumentV1): DomainIssue[];
12
+ /** Fragment paste reuses catalogue identity; whole-map copy remaps it with the map. */
13
+ export declare function remapGroupCategories(group: SeatingGroup, ids: ReadonlyMap<UUID, UUID>): SeatingGroup;
14
+ export declare function categoryUsage(document: PhysicalDocumentV1): ReadonlyMap<UUID, number>;
15
+ export declare function ticketOptionNameKey(name: string): string;
16
+ export type CategoryPricing = {
17
+ onSale: boolean;
18
+ optionCount: number;
19
+ minimum: number | null;
20
+ maximum: number | null;
21
+ missing: boolean;
22
+ };
23
+ export declare function categoryPricing(category: MapCategory): CategoryPricing;
24
+ /** A personal circle remains an override; absence inherits the category shape. */
25
+ export declare function categorySeatShape(category?: MapCategory, slot?: SeatSlot): SeatShape;
@@ -0,0 +1,138 @@
1
+ import { AreaKind, SeatShape, SeatingKind } from "./types.js";
2
+ import { issue, IssueCode } 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 ||
25
+ 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
36
+ ? group.chairs
37
+ : Object.values(group.chairsBySide).flat();
38
+ for (const slot of seats)
39
+ if (slot.categoryId)
40
+ yield { id: slot.id, categoryId: slot.categoryId };
41
+ }
42
+ }
43
+ }
44
+ export function categoryIssues(document) {
45
+ const categories = new Set((document.categories ?? []).map((category) => category.id));
46
+ return [
47
+ ...categoryReferences(document.seatingGroups),
48
+ ...[...document.areas, ...document.sections].flatMap((entity) => entity.categoryId
49
+ ? [{ id: entity.id, categoryId: entity.categoryId }]
50
+ : []),
51
+ ]
52
+ .filter((reference) => !categories.has(reference.categoryId))
53
+ .map((reference) => issue(IssueCode.InvalidStructure, "Category reference does not exist.", [
54
+ reference.id,
55
+ ]));
56
+ }
57
+ /** Fragment paste reuses catalogue identity; whole-map copy remaps it with the map. */
58
+ export function remapGroupCategories(group, ids) {
59
+ const remap = (value) => {
60
+ const categoryId = value.categoryId ? ids.get(value.categoryId) : undefined;
61
+ return categoryId && categoryId !== value.categoryId
62
+ ? { ...value, categoryId }
63
+ : value;
64
+ };
65
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved)
66
+ return {
67
+ ...remap(group),
68
+ rows: group.rows.map((row) => ({
69
+ ...remap(row),
70
+ seats: row.seats.map(remap),
71
+ })),
72
+ };
73
+ if (group.kind === SeatingKind.Round)
74
+ return { ...remap(group), chairs: group.chairs.map(remap) };
75
+ return {
76
+ ...remap(group),
77
+ chairsBySide: {
78
+ top: group.chairsBySide.top.map(remap),
79
+ right: group.chairsBySide.right.map(remap),
80
+ bottom: group.chairsBySide.bottom.map(remap),
81
+ left: group.chairsBySide.left.map(remap),
82
+ },
83
+ };
84
+ }
85
+ const usage = new WeakMap();
86
+ export function categoryUsage(document) {
87
+ const cached = usage.get(document);
88
+ if (cached)
89
+ return cached;
90
+ const counts = new Map();
91
+ const count = (id, quantity = 1) => {
92
+ if (id)
93
+ counts.set(id, (counts.get(id) ?? 0) + quantity);
94
+ };
95
+ for (const group of document.seatingGroups) {
96
+ if (group.kind === SeatingKind.Straight ||
97
+ group.kind === SeatingKind.Curved) {
98
+ for (const row of group.rows)
99
+ for (const slot of row.seats)
100
+ if (!slot.gap)
101
+ count(seatCategoryId(group, slot, row));
102
+ }
103
+ else {
104
+ const slots = group.kind === SeatingKind.Round
105
+ ? group.chairs
106
+ : Object.values(group.chairsBySide).flat();
107
+ for (const slot of slots)
108
+ if (!slot.gap)
109
+ count(seatCategoryId(group, slot));
110
+ }
111
+ }
112
+ for (const area of document.areas)
113
+ count(area.categoryId ?? null, area.kind === AreaKind.Booth ? 1 : area.capacity);
114
+ usage.set(document, counts);
115
+ return counts;
116
+ }
117
+ export function ticketOptionNameKey(name) {
118
+ return name.trim().toLowerCase();
119
+ }
120
+ export function categoryPricing(category) {
121
+ const options = category.ticketOptions ?? [];
122
+ const prices = options.length
123
+ ? options.map((option) => option.price)
124
+ : category.defaultPrice == null
125
+ ? []
126
+ : [category.defaultPrice];
127
+ return {
128
+ onSale: category.onSale !== false,
129
+ optionCount: options.length,
130
+ minimum: prices.length ? Math.min(...prices) : null,
131
+ maximum: prices.length ? Math.max(...prices) : null,
132
+ missing: category.onSale !== false && !prices.length,
133
+ };
134
+ }
135
+ /** A personal circle remains an override; absence inherits the category shape. */
136
+ export function categorySeatShape(category, slot) {
137
+ return slot?.seatShape ?? category?.seatShape ?? SeatShape.Circle;
138
+ }
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import type { PhysicalDocumentV1, UUID } from "./types.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 children;
21
+ private readonly locked;
22
+ private readonly hidden;
23
+ private readonly lockOwners;
24
+ private readonly hiddenOwners;
25
+ private readonly protectedContainers;
26
+ constructor(document: PhysicalDocumentV1, state: MapEditorState);
27
+ canLock(id: UUID): boolean;
28
+ canHide(id: UUID): boolean;
29
+ childIds(id: UUID): readonly UUID[];
30
+ private parentIds;
31
+ private owner;
32
+ lockOwner(id: UUID): UUID | undefined;
33
+ hiddenOwner(id: UUID): UUID | undefined;
34
+ inheritedLockOwner(id: UUID): UUID | undefined;
35
+ inheritedHiddenOwner(id: UUID): UUID | undefined;
36
+ protectedOwner(id: UUID): UUID | undefined;
37
+ }
38
+ export declare function mapEditorPolicy(document: PhysicalDocumentV1, state: MapEditorState): MapEditorPolicy;
39
+ export declare function canonicalEditorState(state: MapEditorState): MapEditorState;
40
+ export declare function parseMapEditorState(document: PhysicalDocumentV1, input: unknown): MapEditorState;
41
+ export declare function pruneMapEditorState(document: PhysicalDocumentV1, state: MapEditorState): MapEditorState;
42
+ export declare function serializedEditorState(state: MapEditorState): string | undefined;
43
+ export declare function remapMapEditorState(state: MapEditorState, identities: ReadonlyMap<UUID, UUID>): MapEditorState;
44
+ /** Compare committed layout only; display names, numbering, paints and labels remain editable. */
45
+ export declare function protectedLayoutChanges(before: PhysicalDocumentV1, after: PhysicalDocumentV1, state: MapEditorState): UUID[];
46
+ export {};
@@ -0,0 +1,262 @@
1
+ import { z } from "zod";
2
+ import { documentCatalog } from "./catalog.js";
3
+ import { worldMatrices } from "./geometry/geometry.js";
4
+ import { uuidSchema } from "./schema.js";
5
+ export const mapEditorStateSchema = z.strictObject({
6
+ version: z.literal(1),
7
+ lockedIds: z.array(uuidSchema).max(100_000),
8
+ hiddenIds: z.array(uuidSchema).max(100_000),
9
+ });
10
+ export const emptyMapEditorState = {
11
+ version: 1,
12
+ lockedIds: [],
13
+ hiddenIds: [],
14
+ };
15
+ const policies = new WeakMap();
16
+ export class MapEditorPolicy {
17
+ document;
18
+ nodes = new Map();
19
+ rows = new Set();
20
+ parents = new Map();
21
+ children = new Map();
22
+ locked;
23
+ hidden;
24
+ lockOwners = new Map();
25
+ hiddenOwners = new Map();
26
+ protectedContainers = new Map();
27
+ constructor(document, state) {
28
+ this.document = document;
29
+ this.locked = new Set(state.lockedIds);
30
+ this.hidden = new Set(state.hiddenIds);
31
+ for (const node of [
32
+ ...document.collections,
33
+ ...document.sections,
34
+ ...document.seatingGroups,
35
+ ...document.areas,
36
+ ...document.decorations,
37
+ ]) {
38
+ 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);
44
+ }
45
+ for (const group of document.seatingGroups) {
46
+ if (!("rows" in group))
47
+ continue;
48
+ for (const row of group.rows) {
49
+ this.nodes.set(row.id, row);
50
+ this.rows.add(row.id);
51
+ this.parents.set(row.id, [group.id]);
52
+ }
53
+ }
54
+ for (const [id, parents] of this.parents) {
55
+ for (const parent of parents) {
56
+ const children = this.children.get(parent) ?? [];
57
+ children.push(id);
58
+ this.children.set(parent, children);
59
+ }
60
+ }
61
+ for (const id of this.locked) {
62
+ const pending = [id], seen = new Set();
63
+ while (pending.length) {
64
+ const parent = pending.pop();
65
+ if (!parent || seen.has(parent))
66
+ continue;
67
+ seen.add(parent);
68
+ this.protectedContainers.set(parent, id);
69
+ pending.push(...(this.parents.get(parent) ?? []));
70
+ }
71
+ }
72
+ }
73
+ canLock(id) {
74
+ return this.nodes.has(id);
75
+ }
76
+ canHide(id) {
77
+ return this.nodes.has(id);
78
+ }
79
+ childIds(id) {
80
+ return this.children.get(id) ?? [];
81
+ }
82
+ parentIds(id) {
83
+ const parents = this.parents.get(id);
84
+ if (parents)
85
+ return parents;
86
+ const seat = documentCatalog(this.document).seats.get(id);
87
+ return seat ? [seat.seat.rowId ?? seat.group.id] : [];
88
+ }
89
+ owner(id, flags, cache, visiting = new Set()) {
90
+ if (!flags.size || visiting.has(id))
91
+ return undefined;
92
+ if (cache.has(id))
93
+ return cache.get(id);
94
+ visiting.add(id);
95
+ let owner = flags.has(id) ? id : undefined;
96
+ for (const parent of this.parentIds(id)) {
97
+ owner ??= this.owner(parent, flags, cache, visiting);
98
+ }
99
+ visiting.delete(id);
100
+ cache.set(id, owner);
101
+ return owner;
102
+ }
103
+ lockOwner(id) {
104
+ return this.owner(id, this.locked, this.lockOwners);
105
+ }
106
+ hiddenOwner(id) {
107
+ return this.owner(id, this.hidden, this.hiddenOwners);
108
+ }
109
+ inheritedLockOwner(id) {
110
+ return this.parentIds(id)
111
+ .map((parent) => this.lockOwner(parent))
112
+ .find((owner) => owner !== undefined);
113
+ }
114
+ inheritedHiddenOwner(id) {
115
+ return this.parentIds(id)
116
+ .map((parent) => this.hiddenOwner(parent))
117
+ .find((owner) => owner !== undefined);
118
+ }
119
+ protectedOwner(id) {
120
+ return this.lockOwner(id) ?? this.protectedContainers.get(id);
121
+ }
122
+ }
123
+ export function mapEditorPolicy(document, state) {
124
+ let states = policies.get(document);
125
+ if (!states) {
126
+ states = new WeakMap();
127
+ policies.set(document, states);
128
+ }
129
+ let policy = states.get(state);
130
+ if (!policy) {
131
+ policy = new MapEditorPolicy(document, state);
132
+ states.set(state, policy);
133
+ }
134
+ return policy;
135
+ }
136
+ export function canonicalEditorState(state) {
137
+ return {
138
+ version: 1,
139
+ lockedIds: [...new Set(state.lockedIds)].sort(),
140
+ hiddenIds: [...new Set(state.hiddenIds)].sort(),
141
+ };
142
+ }
143
+ export function parseMapEditorState(document, input) {
144
+ if (input === undefined)
145
+ return emptyMapEditorState;
146
+ const state = mapEditorStateSchema.parse(input);
147
+ const policy = mapEditorPolicy(document, state);
148
+ return canonicalEditorState(mapEditorStateSchema
149
+ .superRefine((value, context) => {
150
+ for (const [key, ids] of [
151
+ ["lockedIds", value.lockedIds],
152
+ ["hiddenIds", value.hiddenIds],
153
+ ]) {
154
+ ids.forEach((id, index) => {
155
+ if (!(key === "lockedIds" ? policy.canLock(id) : policy.canHide(id))) {
156
+ context.addIssue({
157
+ code: "custom",
158
+ path: [key, index],
159
+ message: "Editor state refers to an unsupported or missing object.",
160
+ });
161
+ }
162
+ });
163
+ }
164
+ })
165
+ .parse(state));
166
+ }
167
+ export function pruneMapEditorState(document, state) {
168
+ if (!state.lockedIds.length && !state.hiddenIds.length)
169
+ return emptyMapEditorState;
170
+ const policy = mapEditorPolicy(document, state);
171
+ const next = canonicalEditorState({
172
+ version: 1,
173
+ lockedIds: state.lockedIds.filter((id) => policy.canLock(id)),
174
+ hiddenIds: state.hiddenIds.filter((id) => policy.canHide(id)),
175
+ });
176
+ return JSON.stringify(next) === JSON.stringify(state) ? state : next;
177
+ }
178
+ export function serializedEditorState(state) {
179
+ return state.lockedIds.length || state.hiddenIds.length
180
+ ? JSON.stringify(canonicalEditorState(state))
181
+ : undefined;
182
+ }
183
+ export function remapMapEditorState(state, identities) {
184
+ const remap = (ids) => ids.flatMap((id) => {
185
+ const next = identities.get(id);
186
+ return next ? [next] : [];
187
+ });
188
+ return canonicalEditorState({
189
+ version: 1,
190
+ lockedIds: remap(state.lockedIds),
191
+ hiddenIds: remap(state.hiddenIds),
192
+ });
193
+ }
194
+ const appearanceFields = new Set([
195
+ "name",
196
+ "label",
197
+ "labels",
198
+ "labelOverride",
199
+ "seatSequenceOverride",
200
+ "aisleSeats",
201
+ "buyerNoun",
202
+ "selling",
203
+ "buyerNote",
204
+ "gap",
205
+ "seatShape",
206
+ "categoryId",
207
+ "attributes",
208
+ "seatLabelStyle",
209
+ "labelStyle",
210
+ "rowStyle",
211
+ "style",
212
+ "displayLabel",
213
+ "labelPlacement",
214
+ "text",
215
+ "fontSizeM",
216
+ "align",
217
+ "opacity",
218
+ "assetId",
219
+ "iconId",
220
+ "zIndex",
221
+ "capacity",
222
+ ]);
223
+ function layoutValue(value) {
224
+ if (Array.isArray(value))
225
+ return value.map(layoutValue);
226
+ if (value && typeof value === "object")
227
+ return Object.fromEntries(Object.entries(value)
228
+ .filter(([key]) => !appearanceFields.has(key))
229
+ .map(([key, child]) => [key, layoutValue(child)]));
230
+ return value;
231
+ }
232
+ /** Compare committed layout only; display names, numbering, paints and labels remain editable. */
233
+ export function protectedLayoutChanges(before, after, state) {
234
+ if (!state.lockedIds.length)
235
+ return [];
236
+ const previous = mapEditorPolicy(before, state), next = mapEditorPolicy(after, state);
237
+ const beforeMatrices = worldMatrices(before), afterMatrices = worldMatrices(after);
238
+ const changed = new Set();
239
+ for (const [id, node] of previous.nodes) {
240
+ const owner = previous.lockOwner(id);
241
+ if (!owner)
242
+ continue;
243
+ const candidate = next.nodes.get(id);
244
+ const matrixId = previous.rows.has(id)
245
+ ? (documentCatalog(before).rows.get(id)?.id ?? id)
246
+ : id;
247
+ const previousValue = {
248
+ layout: layoutValue(node),
249
+ matrix: beforeMatrices.get(matrixId),
250
+ children: [...previous.childIds(id)].sort(),
251
+ };
252
+ const nextValue = {
253
+ layout: layoutValue(candidate),
254
+ matrix: afterMatrices.get(matrixId),
255
+ children: [...next.childIds(id)].sort(),
256
+ };
257
+ if (!candidate ||
258
+ JSON.stringify(previousValue) !== JSON.stringify(nextValue))
259
+ changed.add(owner);
260
+ }
261
+ return [...changed];
262
+ }
@@ -1,4 +1,4 @@
1
- import { type PhysicalDocumentV1, type PointM, type PolygonM, type SeatingGroup, type SeatSlot, type SizeM, type Transform, type UUID } from "../types.js";
1
+ import { type PhysicalDocumentV1, type PointM, type PolygonM, type SeatingGroup, type SeatSlot, type SizeM, type Transform, type UUID, type LabelSequence } from "../types.js";
2
2
  export type Matrix = {
3
3
  a: number;
4
4
  b: number;
@@ -16,10 +16,16 @@ export type GeneratedSeat = {
16
16
  sectionId: UUID | null;
17
17
  label: string;
18
18
  ownerLabel: string;
19
+ logicalRowLabel?: string;
20
+ logicalRowId?: UUID;
21
+ logicalPartIndex?: number;
22
+ logicalSequence?: LabelSequence;
19
23
  position: PointM;
20
24
  rotationDeg: number;
21
25
  size: SizeM;
22
26
  slot: SeatSlot;
27
+ aisle: boolean;
28
+ categoryId: UUID | null;
23
29
  };
24
30
  export declare const identityMatrix: Matrix;
25
31
  export declare const radians: (value: number) => number;
@@ -1,6 +1,7 @@
1
1
  import { rowSeatGeometry, roundChairGeometry, rectangularChairGeometry, TableSide, } from "./seating-layout.js";
2
- import { SeatingKind, } from "../types.js";
2
+ import { SeatingKind, TableChairDistribution, RowEnds, } from "../types.js";
3
3
  import { sequenceLabel } from "../labels.js";
4
+ import { seatCategoryId } from "../categories.js";
4
5
  import { containsPoint, intersects, pointsBounds, } from "./primitives.js";
5
6
  export { containsPoint, emptyBounds, extend, intersects, pointsBounds, } from "./primitives.js";
6
7
  import { prepareBoundary, footprintInBoundary } from "./boundary.js";
@@ -89,7 +90,7 @@ export function worldMatrices(document) {
89
90
  return result;
90
91
  }
91
92
  export function* generateGroup(group) {
92
- const emit = (slot, p, rotationDeg, label, ownerLabel, rowId) => ({
93
+ const emit = (slot, p, rotationDeg, label, ownerLabel, rowId, aisle = false, categoryId = seatCategoryId(group, slot)) => ({
93
94
  id: slot.id,
94
95
  groupId: group.id,
95
96
  rowId,
@@ -103,6 +104,8 @@ export function* generateGroup(group) {
103
104
  rotationDeg: normalizeAngle(rotationDeg + (slot.override?.rotationDeltaDeg ?? 0)),
104
105
  size: slot.override?.sizeM ?? group.seatSizeM,
105
106
  slot,
107
+ aisle,
108
+ categoryId,
106
109
  });
107
110
  if (group.kind === SeatingKind.Straight ||
108
111
  group.kind === SeatingKind.Curved) {
@@ -112,11 +115,17 @@ export function* generateGroup(group) {
112
115
  const owner = row.labelOverride ??
113
116
  sequenceLabel(group.labels.rows, r, group.rows.length);
114
117
  for (let i = 0; i < row.seats.length; i++) {
115
- const geometry = rowSeatGeometry(group, r, i, row.seats.length, longestRow);
118
+ const geometry = rowSeatGeometry(group, r, i, row.seats.length, longestRow, row.layout);
116
119
  let p = geometry.position;
117
120
  const rotation = geometry.rotationDeg;
118
121
  p = { x: p.x + (row.offsetM?.x ?? 0), y: p.y + (row.offsetM?.y ?? 0) };
119
- yield emit(row.seats[i], p, rotation, sequenceLabel(row.seatSequenceOverride ?? group.labels.seats, i, row.seats.length), owner, row.id);
122
+ const seat = emit(row.seats[i], p, rotation, sequenceLabel(row.seatSequenceOverride ?? group.labels.seats, i, row.seats.length), owner, row.id, (i === 0 &&
123
+ (row.aisleSeats === RowEnds.Start ||
124
+ row.aisleSeats === RowEnds.Both)) ||
125
+ (i === row.seats.length - 1 &&
126
+ (row.aisleSeats === RowEnds.End ||
127
+ row.aisleSeats === RowEnds.Both)), seatCategoryId(group, row.seats[i], row));
128
+ yield seat;
120
129
  }
121
130
  }
122
131
  }
@@ -127,7 +136,9 @@ export function* generateGroup(group) {
127
136
  }
128
137
  }
129
138
  else {
130
- const sides = Object.values(TableSide);
139
+ const sides = group.recipe.chairDistribution === TableChairDistribution.EqualSegments
140
+ ? [TableSide.Top, TableSide.Bottom, TableSide.Left, TableSide.Right]
141
+ : Object.values(TableSide);
131
142
  const total = sides.reduce((n, s) => n + group.chairsBySide[s].length, 0);
132
143
  let ordinal = 0;
133
144
  for (const side of sides) {
@@ -0,0 +1,24 @@
1
+ import { SeatShape } from "../types.js";
2
+ export declare enum SeatShapePartKind {
3
+ Rectangle = "rectangle",
4
+ Polygon = "polygon"
5
+ }
6
+ export type SeatShapePart = {
7
+ kind: SeatShapePartKind.Rectangle;
8
+ x: number;
9
+ y: number;
10
+ width: number;
11
+ height: number;
12
+ radius: number;
13
+ } | {
14
+ kind: SeatShapePartKind.Polygon;
15
+ points: readonly number[];
16
+ };
17
+ export declare function seatShapeParts(shape: SeatShape): readonly SeatShapePart[];
18
+ /**
19
+ * @method seatShapeContour
20
+ * @description Reuses bounded normalized contours so small furniture corners stay smooth after scaling.
21
+ * @param {SeatShapePart} part Shared normalized furniture primitive.
22
+ * @returns {readonly number[]} Cached polygon coordinates for the primitive.
23
+ */
24
+ export declare function seatShapeContour(part: SeatShapePart): readonly number[];