@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
@@ -1,22 +1,11 @@
1
+ import { polygonContour } from "./polygon-curves.js";
1
2
  import { pointsBounds, containsPoint } from "./primitives.js";
2
3
  import { ellipseSegments } from "./ellipse.js";
3
- export var OutlineKind;
4
- (function (OutlineKind) {
5
- OutlineKind["Rectangle"] = "rectangle";
6
- OutlineKind["Ellipse"] = "ellipse";
7
- OutlineKind["Sector"] = "sector";
8
- OutlineKind["Envelope"] = "envelope";
9
- })(OutlineKind || (OutlineKind = {}));
4
+ import TinyQueue from "tinyqueue";
5
+ import { LayoutUnitM } from "./units.js";
6
+ import { OutlineKind } from "./venue-outline.interface.js";
10
7
  export function sampledOutline(p) {
11
- if (![
12
- p.center.x,
13
- p.center.y,
14
- p.radiusX,
15
- p.radiusY,
16
- p.innerRatio,
17
- p.startDeg,
18
- p.sweepDeg,
19
- ].every(Number.isFinite) ||
8
+ if (![p.center.x, p.center.y, p.radiusX, p.radiusY, p.innerRatio, p.startDeg, p.sweepDeg].every(Number.isFinite) ||
20
9
  p.radiusX <= 0 ||
21
10
  p.radiusY <= 0 ||
22
11
  p.innerRatio < 0 ||
@@ -38,9 +27,7 @@ export function sampledOutline(p) {
38
27
  ],
39
28
  holes: [],
40
29
  };
41
- const sweep = p.kind === OutlineKind.Ellipse
42
- ? Math.PI * 2
43
- : (p.sweepDeg * Math.PI) / 180, start = (p.startDeg * Math.PI) / 180, full = Math.abs(sweep) === Math.PI * 2;
30
+ const sweep = p.kind === OutlineKind.Ellipse ? Math.PI * 2 : (p.sweepDeg * Math.PI) / 180, start = (p.startDeg * Math.PI) / 180, full = Math.abs(sweep) === Math.PI * 2;
44
31
  const count = ellipseSegments(p.radiusX, p.radiusY, sweep);
45
32
  const arc = (ratio) => Array.from({ length: count + (full ? 0 : 1) }, (_, i) => point(start + (sweep * i) / count, ratio));
46
33
  const outer = arc(1);
@@ -49,10 +36,7 @@ export function sampledOutline(p) {
49
36
  outer,
50
37
  holes: p.innerRatio > 0 ? [arc(p.innerRatio).reverse()] : [],
51
38
  };
52
- const ring = [
53
- ...outer,
54
- ...(p.innerRatio > 0 ? arc(p.innerRatio).reverse() : [p.center]),
55
- ];
39
+ const ring = [...outer, ...(p.innerRatio > 0 ? arc(p.innerRatio).reverse() : [p.center])];
56
40
  if (ring.length > 10000)
57
41
  throw new Error("The sector exceeds the 10,000-vertex limit at 1mm accuracy.");
58
42
  return { outer: ring, holes: [] };
@@ -73,8 +57,7 @@ export function memberEnvelope(points, paddingM = 0.15) {
73
57
  const half = (input) => {
74
58
  const result = [];
75
59
  for (const p of input) {
76
- while (result.length > 1 &&
77
- cross(result[result.length - 2], result[result.length - 1], p) <= 0)
60
+ while (result.length > 1 && cross(result[result.length - 2], result[result.length - 1], p) <= 0)
78
61
  result.pop();
79
62
  result.push(p);
80
63
  }
@@ -88,33 +71,108 @@ export function memberEnvelope(points, paddingM = 0.15) {
88
71
  throw new Error("The envelope exceeds the boundary vertex limit.");
89
72
  return { outer, holes: [] };
90
73
  }
91
- /** Deterministic widest interior scan interval; holes participate in every scan. */
92
- export function interiorLabelPoint(polygon) {
93
- const bounds = pointsBounds(polygon.outer), inside = (p) => containsPoint(polygon.outer, p) &&
94
- !polygon.holes.some((h) => containsPoint(h, p));
95
- const center = {
96
- x: (bounds.minX + bounds.maxX) / 2,
97
- y: (bounds.minY + bounds.maxY) / 2,
74
+ const labelSearchPrecisionM = 1.5 * LayoutUnitM;
75
+ const labelInitialCellLimit = 64;
76
+ const labelSearchRoundoff = 16 * Number.EPSILON;
77
+ const labelPoints = new WeakMap();
78
+ function outlineClearance(polygon, point) {
79
+ let distanceSquared = Infinity;
80
+ for (const ring of [polygon.outer, ...polygon.holes]) {
81
+ for (let index = 0; index < ring.length; index++) {
82
+ const start = ring[index], end = ring[(index + 1) % ring.length];
83
+ const dx = end.x - start.x, dy = end.y - start.y;
84
+ const lengthSquared = dx * dx + dy * dy;
85
+ const fraction = lengthSquared === 0
86
+ ? 0
87
+ : Math.max(0, Math.min(1, ((point.x - start.x) * dx + (point.y - start.y) * dy) / lengthSquared));
88
+ const x = point.x - start.x - fraction * dx, y = point.y - start.y - fraction * dy;
89
+ distanceSquared = Math.min(distanceSquared, x * x + y * y);
90
+ }
91
+ }
92
+ const inside = containsPoint(polygon.outer, point) && !polygon.holes.some((hole) => containsPoint(hole, point));
93
+ return Math.sqrt(distanceSquared) * (inside ? 1 : -1);
94
+ }
95
+ function outlineCentroid(polygon) {
96
+ let area = 0, x = 0, y = 0;
97
+ const ring = polygon.outer;
98
+ const origin = ring[0];
99
+ for (let index = 0; index < ring.length; index++) {
100
+ const start = ring[index], end = ring[(index + 1) % ring.length];
101
+ const startX = start.x - origin.x, startY = start.y - origin.y;
102
+ const endX = end.x - origin.x, endY = end.y - origin.y;
103
+ const cross = startX * endY - endX * startY;
104
+ area += cross;
105
+ x += (startX + endX) * cross;
106
+ y += (startY + endY) * cross;
107
+ }
108
+ return area === 0 ? origin : { x: origin.x + x / (3 * area), y: origin.y + y / (3 * area) };
109
+ }
110
+ /** Maximum-clearance interior anchor. Holes and curved contours share the same geometry owner. */
111
+ export function interiorLabelPoint(source) {
112
+ const cached = labelPoints.get(source);
113
+ if (cached)
114
+ return cached;
115
+ const polygon = polygonContour(source);
116
+ const bounds = pointsBounds(polygon.outer);
117
+ const width = bounds.maxX - bounds.minX, height = bounds.maxY - bounds.minY;
118
+ const roundoffM = Math.max(width, height, Math.abs(bounds.minX), Math.abs(bounds.minY), Math.abs(bounds.maxX), Math.abs(bounds.maxY)) * labelSearchRoundoff;
119
+ const cell = (center, halfWidthM, halfHeightM) => {
120
+ const distanceM = outlineClearance(polygon, center);
121
+ return { center, halfWidthM, halfHeightM, distanceM, maximumM: distanceM + Math.hypot(halfWidthM, halfHeightM) };
98
122
  };
99
- if (inside(center))
100
- return center;
101
- let result = polygon.outer[0] ?? { x: 0, y: 0 }, width = -1;
102
- for (let scan = 1; scan < 64; scan++) {
103
- const y = bounds.minY + ((bounds.maxY - bounds.minY) * scan) / 64, cuts = [];
104
- for (const ring of [polygon.outer, ...polygon.holes])
105
- for (let i = 0; i < ring.length; i++) {
106
- const a = ring[i], b = ring[(i + 1) % ring.length];
107
- if (a.y > y !== b.y > y)
108
- cuts.push(a.x + ((b.x - a.x) * (y - a.y)) / (b.y - a.y));
123
+ let best = cell(outlineCentroid(polygon), 0, 0);
124
+ const center = cell({ x: (bounds.minX + bounds.maxX) / 2, y: (bounds.minY + bounds.maxY) / 2 }, 0, 0);
125
+ if (center.distanceM > best.distanceM + roundoffM)
126
+ best = center;
127
+ // A boundary vertex is an admissible initial point when both centroids fall in a void.
128
+ if (best.distanceM < 0)
129
+ best = cell(polygon.outer[0], 0, 0);
130
+ // No inscribed circle can exceed half the smaller bounding-box dimension.
131
+ if (Math.min(width, height) / 2 - best.distanceM <= labelSearchPrecisionM) {
132
+ labelPoints.set(source, best.center);
133
+ return best.center;
134
+ }
135
+ const queue = new TinyQueue([], (left, right) => {
136
+ const difference = right.maximumM - left.maximumM;
137
+ // Symmetric cells must keep the same queue order across layout-unit/metre conversion.
138
+ return Math.abs(difference) <= roundoffM ? 0 : difference;
139
+ });
140
+ const smallerSpanM = Math.min(width, height);
141
+ const coarsening = 2 ** Math.max(0, Math.ceil(Math.log2(Math.max(width, height) / smallerSpanM / labelInitialCellLimit)));
142
+ const sizeM = Math.max(labelSearchPrecisionM, smallerSpanM * coarsening);
143
+ const halfWidthM = Math.min(sizeM, width) / 2, halfHeightM = Math.min(sizeM, height) / 2;
144
+ for (let x = bounds.minX; x < bounds.maxX; x += sizeM) {
145
+ for (let y = bounds.minY; y < bounds.maxY; y += sizeM) {
146
+ queue.push(cell({ x: x + halfWidthM, y: y + halfHeightM }, halfWidthM, halfHeightM));
147
+ }
148
+ }
149
+ while (queue.length) {
150
+ const current = queue.pop();
151
+ if (current.distanceM > best.distanceM + roundoffM)
152
+ best = current;
153
+ if (smallerSpanM / 2 - best.distanceM <= labelSearchPrecisionM)
154
+ break;
155
+ if (current.maximumM - best.distanceM <= labelSearchPrecisionM)
156
+ continue;
157
+ const halfWidth = current.halfWidthM / 2, halfHeight = current.halfHeightM / 2;
158
+ if (current.halfWidthM > current.halfHeightM) {
159
+ for (const dx of [-halfWidth, halfWidth]) {
160
+ queue.push(cell({ x: current.center.x + dx, y: current.center.y }, halfWidth, current.halfHeightM));
109
161
  }
110
- cuts.sort((a, b) => a - b);
111
- for (let i = 1; i < cuts.length; i++) {
112
- const p = { x: (cuts[i - 1] + cuts[i]) / 2, y }, span = cuts[i] - cuts[i - 1];
113
- if (span > width && inside(p)) {
114
- result = p;
115
- width = span;
162
+ }
163
+ else if (current.halfHeightM > current.halfWidthM) {
164
+ for (const dy of [-halfHeight, halfHeight]) {
165
+ queue.push(cell({ x: current.center.x, y: current.center.y + dy }, current.halfWidthM, halfHeight));
166
+ }
167
+ }
168
+ else {
169
+ for (const dy of [-halfHeight, halfHeight]) {
170
+ for (const dx of [-halfWidth, halfWidth]) {
171
+ queue.push(cell({ x: current.center.x + dx, y: current.center.y + dy }, halfWidth, halfHeight));
172
+ }
116
173
  }
117
174
  }
118
175
  }
119
- return result;
176
+ labelPoints.set(source, best.center);
177
+ return best.center;
120
178
  }
@@ -1,4 +1,6 @@
1
- import type { PhysicalDocumentV1 } from "./types.js";
1
+ import type { PhysicalDocumentV1 } from "./physical-document.interface.js";
2
+ /** Work reported by allocation, remapping and final document validation. Assets keep their IDs. */
3
+ export declare function remapDocumentWork(source: PhysicalDocumentV1): number;
2
4
  export declare function remapDocumentSteps(source: PhysicalDocumentV1, name: string): Generator<number, {
3
5
  document: PhysicalDocumentV1;
4
6
  warnings: string[];
package/dist/identity.js CHANGED
@@ -1,5 +1,31 @@
1
1
  import { z } from "zod";
2
- import { DocumentParseStatus, parsePhysicalDocument } from "./schema.js";
2
+ import { DocumentParseStatus, groupSeatCount, parsePhysicalDocument } from "./schema.js";
3
+ const identityFields = new Set([
4
+ "id",
5
+ "parentId",
6
+ "sectionId",
7
+ "companionForSeatId",
8
+ "assetId",
9
+ "categoryId",
10
+ "rowId",
11
+ "floorId",
12
+ "zoneId",
13
+ "gateId",
14
+ ]);
15
+ const identityRecordSchema = z.record(z.string(), z.unknown());
16
+ /** Work reported by allocation, remapping and final document validation. Assets keep their IDs. */
17
+ export function remapDocumentWork(source) {
18
+ const identities = source.sections.length +
19
+ source.collections.length +
20
+ source.areas.length +
21
+ source.decorations.length +
22
+ (source.floors?.length ?? 0) +
23
+ (source.zones?.length ?? 0) +
24
+ (source.segmentedRows?.length ?? 0) +
25
+ (source.categories?.reduce((total, category) => total + 1 + (category.ticketOptions?.length ?? 0), 0) ?? 0) +
26
+ source.seatingGroups.reduce((total, group) => total + 1 + groupSeatCount(group) + ("rows" in group ? group.rows.length : 0), 0);
27
+ return identities * 2 + source.assets.length + 1;
28
+ }
3
29
  export function* remapDocumentSteps(source, name) {
4
30
  const ids = new Map(), warnings = [];
5
31
  function* allocate(value) {
@@ -11,7 +37,7 @@ export function* remapDocumentSteps(source, name) {
11
37
  yield* allocate(child);
12
38
  return;
13
39
  }
14
- const record = z.record(z.string(), z.unknown()).parse(value);
40
+ const record = identityRecordSchema.parse(value);
15
41
  if (typeof record.id === "string")
16
42
  ids.set(record.id, crypto.randomUUID());
17
43
  yield typeof record.id === "string" ? 1 : 0;
@@ -29,13 +55,11 @@ export function* remapDocumentSteps(source, name) {
29
55
  return result;
30
56
  }
31
57
  if (value && typeof value === "object") {
32
- const record = z.record(z.string(), z.unknown()).parse(value);
58
+ const record = identityRecordSchema.parse(value);
33
59
  yield typeof record.id === "string" ? 1 : 0;
34
60
  const result = {};
35
61
  for (const [field, child] of Object.entries(record)) {
36
- if (field === "companionForSeatId" &&
37
- typeof child === "string" &&
38
- !ids.has(child)) {
62
+ if (field === "companionForSeatId" && typeof child === "string" && !ids.has(child)) {
39
63
  warnings.push("An external companion relationship was cleared.");
40
64
  continue;
41
65
  }
@@ -43,14 +67,13 @@ export function* remapDocumentSteps(source, name) {
43
67
  }
44
68
  return result;
45
69
  }
46
- if (typeof value === "string" &&
47
- ["id", "parentId", "sectionId", "companionForSeatId", "assetId"].includes(key))
70
+ if (typeof value === "string" && identityFields.has(key))
48
71
  return ids.get(value) ?? value;
49
72
  return value;
50
73
  }
51
74
  const remapped = yield* remap(source);
52
75
  const parsed = parsePhysicalDocument({
53
- ...z.record(z.string(), z.unknown()).parse(remapped),
76
+ ...identityRecordSchema.parse(remapped),
54
77
  mapId: crypto.randomUUID(),
55
78
  name,
56
79
  });
package/dist/issues.d.ts CHANGED
@@ -1,21 +1,32 @@
1
- import type { UUID } from "./types.js";
1
+ import type { UUID } from "./physical-document.interface.js";
2
2
  export declare enum IssueCode {
3
3
  DuplicateId = "DUPLICATE_ID",
4
4
  InvalidJson = "INVALID_JSON",
5
5
  InvalidParent = "INVALID_PARENT",
6
6
  InvalidStructure = "INVALID_STRUCTURE",
7
+ InvalidSegmentedRow = "INVALID_SEGMENTED_ROW",
7
8
  Limit = "LIMIT_EXCEEDED",
8
9
  UnknownSection = "UNKNOWN_SECTION",
10
+ UnknownFloor = "UNKNOWN_FLOOR",
11
+ UnknownZone = "UNKNOWN_ZONE",
12
+ UnknownGate = "UNKNOWN_GATE",
13
+ UnknownCategory = "UNKNOWN_CATEGORY",
14
+ UnknownSeatCategory = "UNKNOWN_SEAT_CATEGORY",
15
+ MissingCategory = "MISSING_CATEGORY",
16
+ MissingCategoryPrice = "MISSING_CATEGORY_PRICE",
9
17
  UnsupportedVersion = "UNSUPPORTED_VERSION",
10
18
  WorldBounds = "WORLD_BOUNDS",
11
19
  DuplicateLabel = "DUPLICATE_LABEL",
12
20
  EmptyInventory = "EMPTY_INVENTORY",
21
+ EmptySection = "EMPTY_SECTION",
13
22
  InvalidBoundary = "INVALID_BOUNDARY",
14
23
  InvalidCompanion = "INVALID_COMPANION",
15
24
  InvalidLabel = "INVALID_LABEL",
25
+ MissingLabel = "MISSING_LABEL",
16
26
  MissingAsset = "MISSING_ASSET",
17
27
  CurveOverrun = "CURVE_OVERRUN",
18
- SeatClearance = "SEAT_CLEARANCE",
28
+ SeatOverlap = "SEAT_OVERLAP",
29
+ SeatCramped = "SEAT_CRAMPED",
19
30
  OutsideBoundary = "OUTSIDE_BOUNDARY",
20
31
  InvalidCommand = "INVALID_COMMAND"
21
32
  }
@@ -36,6 +47,7 @@ export type DomainIssue = {
36
47
  code: IssueCode;
37
48
  severity: IssueSeverity;
38
49
  message: string;
50
+ description?: string;
39
51
  entityIds: UUID[];
40
52
  fieldPath?: string;
41
53
  relatedEntityIds?: UUID[];
@@ -43,4 +55,5 @@ export type DomainIssue = {
43
55
  blocks: BlockedAction[];
44
56
  };
45
57
  export declare function issue(code: IssueCode, message: string, entityIds: UUID[], fieldPath?: string): DomainIssue;
58
+ export declare function missingLabelMessage(count: number): string;
46
59
  export declare function issueKey(value: DomainIssue): string;
package/dist/issues.js CHANGED
@@ -4,18 +4,29 @@ export var IssueCode;
4
4
  IssueCode["InvalidJson"] = "INVALID_JSON";
5
5
  IssueCode["InvalidParent"] = "INVALID_PARENT";
6
6
  IssueCode["InvalidStructure"] = "INVALID_STRUCTURE";
7
+ IssueCode["InvalidSegmentedRow"] = "INVALID_SEGMENTED_ROW";
7
8
  IssueCode["Limit"] = "LIMIT_EXCEEDED";
8
9
  IssueCode["UnknownSection"] = "UNKNOWN_SECTION";
10
+ IssueCode["UnknownFloor"] = "UNKNOWN_FLOOR";
11
+ IssueCode["UnknownZone"] = "UNKNOWN_ZONE";
12
+ IssueCode["UnknownGate"] = "UNKNOWN_GATE";
13
+ IssueCode["UnknownCategory"] = "UNKNOWN_CATEGORY";
14
+ IssueCode["UnknownSeatCategory"] = "UNKNOWN_SEAT_CATEGORY";
15
+ IssueCode["MissingCategory"] = "MISSING_CATEGORY";
16
+ IssueCode["MissingCategoryPrice"] = "MISSING_CATEGORY_PRICE";
9
17
  IssueCode["UnsupportedVersion"] = "UNSUPPORTED_VERSION";
10
18
  IssueCode["WorldBounds"] = "WORLD_BOUNDS";
11
19
  IssueCode["DuplicateLabel"] = "DUPLICATE_LABEL";
12
20
  IssueCode["EmptyInventory"] = "EMPTY_INVENTORY";
21
+ IssueCode["EmptySection"] = "EMPTY_SECTION";
13
22
  IssueCode["InvalidBoundary"] = "INVALID_BOUNDARY";
14
23
  IssueCode["InvalidCompanion"] = "INVALID_COMPANION";
15
24
  IssueCode["InvalidLabel"] = "INVALID_LABEL";
25
+ IssueCode["MissingLabel"] = "MISSING_LABEL";
16
26
  IssueCode["MissingAsset"] = "MISSING_ASSET";
17
27
  IssueCode["CurveOverrun"] = "CURVE_OVERRUN";
18
- IssueCode["SeatClearance"] = "SEAT_CLEARANCE";
28
+ IssueCode["SeatOverlap"] = "SEAT_OVERLAP";
29
+ IssueCode["SeatCramped"] = "SEAT_CRAMPED";
19
30
  IssueCode["OutsideBoundary"] = "OUTSIDE_BOUNDARY";
20
31
  IssueCode["InvalidCommand"] = "INVALID_COMMAND";
21
32
  })(IssueCode || (IssueCode = {}));
@@ -43,13 +54,12 @@ export function issue(code, message, entityIds, fieldPath) {
43
54
  entityIds,
44
55
  fieldPath,
45
56
  remediation: [IssueRemediation.Edit, IssueRemediation.Remove],
46
- blocks: [
47
- BlockedAction.FinalizeAssignment,
48
- BlockedAction.Publish,
49
- BlockedAction.ReplaceBinding,
50
- ],
57
+ blocks: [BlockedAction.FinalizeAssignment, BlockedAction.Publish, BlockedAction.ReplaceBinding],
51
58
  };
52
59
  }
60
+ export function missingLabelMessage(count) {
61
+ return `${count} ${count === 1 ? "object has" : "objects have"} no label`;
62
+ }
53
63
  export function issueKey(value) {
54
64
  return `${value.code}:${[...value.entityIds].sort().join(",")}:${value.fieldPath ?? ""}`;
55
65
  }
package/dist/labels.d.ts CHANGED
@@ -1,3 +1,14 @@
1
- import { type LabelSequence } from "./types.js";
1
+ import { type LabelSequence, type InventoryNaming, type RowInventory } from "./physical-document.interface.js";
2
+ /** An explicit buyer-facing name overrides the generated inventory code. */
3
+ export declare function inventoryName(naming: InventoryNaming): string;
4
+ /** Physical row identifiers remain stable when their displayed names change. */
5
+ export declare function rowBookingLabel(group: RowInventory, index: number): string;
6
+ export declare function rowDisplayLabel(group: RowInventory, index: number): string;
2
7
  export declare function labelKey(value: string): string;
8
+ /** Position in the buyer's sequence, independent of authored inventory identity. */
9
+ export declare function sequenceOrdinal(sequence: LabelSequence, index: number, count: number): number;
10
+ export declare function sequenceStep(sequence: LabelSequence): number;
11
+ /** Combined patterns own their order; the stored anchor remains available when switching back. */
12
+ export declare function sequenceOwnsOrder(scheme: string): boolean;
13
+ export declare function sequenceStart(sequence: LabelSequence, count: number): number;
3
14
  export declare function sequenceLabel(sequence: LabelSequence, index: number, count: number): string;
package/dist/labels.js CHANGED
@@ -1,4 +1,4 @@
1
- import { NumberingScheme, LabelDirection, } from "./types.js";
1
+ import { NumberingScheme, LabelDirection, } from "./physical-document.interface.js";
2
2
  import { caseFoldData } from "./case-fold-data.js";
3
3
  const folds = new Map(caseFoldData.split(";").map((entry) => {
4
4
  const [from, to] = entry.split(":");
@@ -9,9 +9,20 @@ const folds = new Map(caseFoldData.split(";").map((entry) => {
9
9
  }));
10
10
  // Unicode 17 White_Space, PropList.txt; same license as case-fold-data.
11
11
  const whitespace = new Set([
12
- 9, 10, 11, 12, 13, 32, 133, 160, 5760, 8192, 8193, 8194, 8195, 8196, 8197,
13
- 8198, 8199, 8200, 8201, 8202, 8232, 8233, 8239, 8287, 12288,
12
+ 9, 10, 11, 12, 13, 32, 133, 160, 5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202, 8232, 8233,
13
+ 8239, 8287, 12288,
14
14
  ]);
15
+ /** An explicit buyer-facing name overrides the generated inventory code. */
16
+ export function inventoryName(naming) {
17
+ return naming.name ?? naming.code;
18
+ }
19
+ /** Physical row identifiers remain stable when their displayed names change. */
20
+ export function rowBookingLabel(group, index) {
21
+ return group.rows[index].bookingLabel ?? sequenceLabel(group.labels.rows, index, group.rows.length);
22
+ }
23
+ export function rowDisplayLabel(group, index) {
24
+ return group.rows[index].labelOverride ?? rowBookingLabel(group, index);
25
+ }
15
26
  export function labelKey(value) {
16
27
  const points = Array.from(value);
17
28
  let start = 0;
@@ -24,22 +35,76 @@ export function labelKey(value) {
24
35
  .join("")
25
36
  .normalize("NFC");
26
37
  }
38
+ /** Position in the buyer's sequence, independent of authored inventory identity. */
39
+ export function sequenceOrdinal(sequence, index, count) {
40
+ const middle = Math.ceil(count / 2);
41
+ if (sequence.scheme === NumberingScheme.OutsideIn)
42
+ return index < middle ? index * 2 : (count - 1 - index) * 2 + 1;
43
+ if (sequence.scheme === NumberingScheme.InsideOut)
44
+ return index < middle ? (middle - 1 - index) * 2 : (index - middle) * 2 + 1;
45
+ if (sequence.direction === LabelDirection.Centre) {
46
+ const centre = Math.floor((count - 1) / 2);
47
+ if (index === centre)
48
+ return 0;
49
+ if (index < centre)
50
+ return (centre - index) * 2 - (count % 2);
51
+ return (index - centre) * 2 - (count % 2 === 0 ? 1 : 0);
52
+ }
53
+ return sequence.direction === LabelDirection.Reverse ? count - 1 - index : index;
54
+ }
55
+ export function sequenceStep(sequence) {
56
+ return sequence.scheme === NumberingScheme.Odd || sequence.scheme === NumberingScheme.Even ? 2 : 1;
57
+ }
58
+ /** Combined patterns own their order; the stored anchor remains available when switching back. */
59
+ export function sequenceOwnsOrder(scheme) {
60
+ return scheme === NumberingScheme.OutsideIn || scheme === NumberingScheme.InsideOut;
61
+ }
62
+ export function sequenceStart(sequence, count) {
63
+ let start = !sequenceOwnsOrder(sequence.scheme) && sequence.numberFrom === "last" && sequence.lastAt !== undefined
64
+ ? Math.max(0, sequence.lastAt - Math.max(0, count - 1) * sequenceStep(sequence))
65
+ : sequence.startAt;
66
+ if (sequence.scheme === NumberingScheme.Odd && start % 2 === 0)
67
+ start++;
68
+ if (sequence.scheme === NumberingScheme.Even && start % 2 === 1)
69
+ start++;
70
+ return start;
71
+ }
72
+ const romanParts = [
73
+ [1000, "M"],
74
+ [900, "CM"],
75
+ [500, "D"],
76
+ [400, "CD"],
77
+ [100, "C"],
78
+ [90, "XC"],
79
+ [50, "L"],
80
+ [40, "XL"],
81
+ [10, "X"],
82
+ [9, "IX"],
83
+ [5, "V"],
84
+ [4, "IV"],
85
+ [1, "I"],
86
+ ];
27
87
  export function sequenceLabel(sequence, index, count) {
28
- const ordinal = sequence.direction === LabelDirection.Reverse ? count - 1 - index : index;
29
- let n = sequence.startAt +
30
- ordinal *
31
- (sequence.scheme === NumberingScheme.Odd ||
32
- sequence.scheme === NumberingScheme.Even
33
- ? 2
34
- : 1);
88
+ let n = sequenceStart(sequence, count) + sequenceOrdinal(sequence, index, count) * sequenceStep(sequence);
35
89
  let label = String(n);
36
- if (sequence.scheme === NumberingScheme.Alphabetic) {
90
+ if (sequence.scheme === NumberingScheme.Alphabetic || sequence.scheme === NumberingScheme.LowerAlphabetic) {
91
+ n = Math.max(1, n);
37
92
  label = "";
38
93
  while (n > 0) {
39
94
  n--;
40
95
  label = String.fromCharCode(65 + (n % 26)) + label;
41
96
  n = Math.floor(n / 26);
42
97
  }
98
+ if (sequence.scheme === NumberingScheme.LowerAlphabetic)
99
+ label = label.toLowerCase();
100
+ }
101
+ else if (sequence.scheme === NumberingScheme.Roman && n > 0) {
102
+ label = "";
103
+ for (const [value, glyph] of romanParts) {
104
+ const repeats = Math.floor(n / value);
105
+ label += glyph.repeat(repeats);
106
+ n %= value;
107
+ }
43
108
  }
44
109
  return (sequence.prefix ?? "") + label + (sequence.suffix ?? "");
45
110
  }
@@ -0,0 +1,26 @@
1
+ import { type PhysicalDocumentV1, type UUID } from "./physical-document.interface.js";
2
+ export type LayerEntry = {
3
+ id: UUID;
4
+ parentId: UUID | null;
5
+ ownerId: UUID;
6
+ zIndex: number;
7
+ rowIndex: number;
8
+ };
9
+ export type LayerRun = {
10
+ ids: readonly UUID[];
11
+ order: number;
12
+ };
13
+ type LayerCatalog = {
14
+ runs: ReadonlyMap<UUID, readonly LayerRun[]>;
15
+ siblings: ReadonlyMap<UUID | null, readonly LayerEntry[]>;
16
+ targets: ReadonlyMap<UUID, readonly UUID[]>;
17
+ order: ReadonlyMap<UUID, number>;
18
+ };
19
+ /**
20
+ * @method layerCatalog
21
+ * @description Projects rows and drawables onto their collection's stacking plane without changing bank ownership.
22
+ * @param document Physical document whose collection hierarchy and row defaults determine the stacking order.
23
+ * @returns Cached sibling lists, actionable targets and flattened painter order, including each bank's first row.
24
+ */
25
+ export declare function layerCatalog(document: PhysicalDocumentV1): LayerCatalog;
26
+ export {};
package/dist/layers.js ADDED
@@ -0,0 +1,86 @@
1
+ import { SeatingKind } from "./physical-document.interface.js";
2
+ const catalogs = new WeakMap();
3
+ /**
4
+ * @method layerCatalog
5
+ * @description Projects rows and drawables onto their collection's stacking plane without changing bank ownership.
6
+ * @param document Physical document whose collection hierarchy and row defaults determine the stacking order.
7
+ * @returns Cached sibling lists, actionable targets and flattened painter order, including each bank's first row.
8
+ */
9
+ export function layerCatalog(document) {
10
+ const cached = catalogs.get(document);
11
+ if (cached) {
12
+ return cached;
13
+ }
14
+ const siblings = new Map();
15
+ const targets = new Map();
16
+ const collections = new Set(document.collections.map((collection) => collection.id));
17
+ const banks = new Map();
18
+ const entities = [
19
+ ...document.collections,
20
+ ...document.seatingGroups,
21
+ ...document.areas,
22
+ ...document.decorations,
23
+ ];
24
+ for (const entity of entities) {
25
+ const rows = "kind" in entity && (entity.kind === SeatingKind.Straight || entity.kind === SeatingKind.Curved)
26
+ ? entity.rows
27
+ : null;
28
+ const entries = rows
29
+ ? rows.map((row, rowIndex) => ({
30
+ id: row.id,
31
+ parentId: entity.parentId,
32
+ ownerId: entity.id,
33
+ zIndex: row.zIndex ?? entity.zIndex,
34
+ rowIndex,
35
+ }))
36
+ : [{ id: entity.id, parentId: entity.parentId, ownerId: entity.id, zIndex: entity.zIndex, rowIndex: 0 }];
37
+ const ids = entries.map((entry) => entry.id);
38
+ targets.set(entity.id, ids);
39
+ if (rows) {
40
+ banks.set(entity.id, ids);
41
+ for (const id of ids) {
42
+ targets.set(id, [id]);
43
+ }
44
+ }
45
+ const list = siblings.get(entity.parentId) ?? [];
46
+ list.push(...entries);
47
+ siblings.set(entity.parentId, list);
48
+ }
49
+ for (const logical of document.segmentedRows ?? []) {
50
+ targets.set(logical.id, logical.parts.map((part) => part.rowId));
51
+ }
52
+ for (const list of siblings.values()) {
53
+ list.sort((a, b) => a.zIndex - b.zIndex || a.ownerId.localeCompare(b.ownerId) || a.rowIndex - b.rowIndex);
54
+ }
55
+ const order = new Map();
56
+ const runs = new Map();
57
+ let previousOwner = null;
58
+ let ordinal = 0;
59
+ const visit = (parent) => {
60
+ for (const entry of siblings.get(parent) ?? []) {
61
+ if (collections.has(entry.id)) {
62
+ visit(entry.id);
63
+ }
64
+ else {
65
+ order.set(entry.id, ordinal);
66
+ const ownerRuns = runs.get(entry.ownerId) ?? [];
67
+ if (previousOwner === entry.ownerId) {
68
+ ownerRuns[ownerRuns.length - 1].ids.push(entry.id);
69
+ }
70
+ else {
71
+ ownerRuns.push({ ids: [entry.id], order: ordinal });
72
+ }
73
+ runs.set(entry.ownerId, ownerRuns);
74
+ previousOwner = entry.ownerId;
75
+ ordinal++;
76
+ }
77
+ }
78
+ };
79
+ visit(null);
80
+ for (const [id, rows] of banks) {
81
+ order.set(id, Math.min(...rows.map((row) => order.get(row))));
82
+ }
83
+ const catalog = { siblings, targets, order, runs };
84
+ catalogs.set(document, catalog);
85
+ return catalog;
86
+ }
@@ -0,0 +1,27 @@
1
+ import type { BuyerPhoto, PhysicalDocumentV1, UUID } from "./physical-document.interface.js";
2
+ import type { DocumentSeat } from "./catalog.js";
3
+ export declare enum MediaScope {
4
+ Artwork = "artwork",
5
+ Seat = "seat",
6
+ Row = "row",
7
+ Section = "section",
8
+ Venue = "venue",
9
+ Generated = "generated"
10
+ }
11
+ export type MediaReference = Readonly<{
12
+ scope: Exclude<MediaScope, MediaScope.Generated>;
13
+ ownerId: UUID;
14
+ assetId: UUID;
15
+ fieldPath: string;
16
+ }>;
17
+ /** All live consumers share resource identity, including photos on gap slots. */
18
+ export declare function mediaReferences(document: PhysicalDocumentV1): readonly MediaReference[];
19
+ export type ResolvedBuyerPhoto = {
20
+ scope: MediaScope.Generated;
21
+ } | {
22
+ scope: Exclude<MediaScope, MediaScope.Generated | MediaScope.Artwork>;
23
+ ownerId: UUID;
24
+ photo: BuyerPhoto;
25
+ };
26
+ /** Resolve the primary inventory address; overlapping editing scopes do not change inheritance. */
27
+ export declare function buyerPhotoForSeat(document: PhysicalDocumentV1, seat: DocumentSeat): ResolvedBuyerPhoto;