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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/catalog.d.ts +10 -3
  2. package/dist/catalog.js +66 -10
  3. package/dist/categories.d.ts +26 -0
  4. package/dist/categories.js +168 -0
  5. package/dist/editor-state.d.ts +49 -0
  6. package/dist/editor-state.js +266 -0
  7. package/dist/floors.d.ts +19 -0
  8. package/dist/floors.js +68 -0
  9. package/dist/geometry/boundary.d.ts +1 -1
  10. package/dist/geometry/boundary.js +10 -12
  11. package/dist/geometry/curve-warnings.d.ts +1 -1
  12. package/dist/geometry/curve-warnings.js +3 -5
  13. package/dist/geometry/decoration-bounds.d.ts +4 -0
  14. package/dist/geometry/decoration-bounds.js +42 -0
  15. package/dist/geometry/ellipse.js +4 -12
  16. package/dist/geometry/geometry.d.ts +12 -3
  17. package/dist/geometry/geometry.js +35 -26
  18. package/dist/geometry/polygon-curves.d.ts +12 -0
  19. package/dist/geometry/polygon-curves.js +132 -0
  20. package/dist/geometry/primitives.d.ts +1 -1
  21. package/dist/geometry/primitives.js +2 -3
  22. package/dist/geometry/seat-shape.d.ts +24 -0
  23. package/dist/geometry/seat-shape.js +101 -0
  24. package/dist/geometry/seating-layout.d.ts +14 -3
  25. package/dist/geometry/seating-layout.js +91 -19
  26. package/dist/geometry/units.d.ts +1 -0
  27. package/dist/geometry/units.js +2 -0
  28. package/dist/geometry/venue-outline.d.ts +2 -2
  29. package/dist/geometry/venue-outline.js +8 -21
  30. package/dist/identity.d.ts +4 -1
  31. package/dist/identity.js +36 -10
  32. package/dist/issues.d.ts +9 -2
  33. package/dist/issues.js +8 -6
  34. package/dist/labels.d.ts +12 -1
  35. package/dist/labels.js +76 -11
  36. package/dist/layers.d.ts +26 -0
  37. package/dist/layers.js +86 -0
  38. package/dist/media.d.ts +27 -0
  39. package/dist/media.js +89 -0
  40. package/dist/physical-document.interface.d.ts +518 -0
  41. package/dist/{types.js → physical-document.interface.js} +71 -0
  42. package/dist/preview.d.ts +1 -1
  43. package/dist/preview.js +65 -24
  44. package/dist/reference.js +1 -1
  45. package/dist/row-segments.d.ts +30 -0
  46. package/dist/row-segments.js +112 -0
  47. package/dist/schema.d.ts +1192 -68
  48. package/dist/schema.js +372 -96
  49. package/dist/seat-proximity.d.ts +4 -0
  50. package/dist/seat-proximity.js +119 -0
  51. package/dist/sections.d.ts +23 -0
  52. package/dist/sections.js +149 -0
  53. package/dist/selling.d.ts +34 -0
  54. package/dist/selling.js +148 -0
  55. package/dist/spacing-repairs.d.ts +31 -0
  56. package/dist/spacing-repairs.js +168 -0
  57. package/dist/table-layout.d.ts +29 -0
  58. package/dist/table-layout.js +134 -0
  59. package/dist/validation.d.ts +3 -1
  60. package/dist/validation.js +124 -74
  61. package/package.json +59 -3
  62. package/dist/types.d.ts +0 -313
package/dist/preview.js CHANGED
@@ -1,6 +1,12 @@
1
- import { footprint, generateGroup, project, worldMatrices, } from "./geometry/geometry.js";
1
+ import { polygonContour } from "./geometry/polygon-curves.js";
2
+ import { layerCatalog } from "./layers.js";
3
+ import { sectionCatalog } from "./sections.js";
4
+ import { documentGroupSeats } from "./catalog.js";
5
+ import { footprint, project, worldMatrices, multiply, transformMatrix } from "./geometry/geometry.js";
2
6
  import { emptyBounds, extend } from "./geometry/primitives.js";
3
- import { DecorationKind, SeatingKind, ShapeKind } from "./types.js";
7
+ import { categoryCatalog, categorySeatShape } from "./categories.js";
8
+ import { seatShapeParts, SeatShapePartKind } from "./geometry/seat-shape.js";
9
+ import { DecorationKind, SeatingKind, ShapeKind, SeatShape } from "./physical-document.interface.js";
4
10
  export const ThumbnailPolicy = {
5
11
  MaximumSvgLength: 128000,
6
12
  MaximumContentLength: 120000,
@@ -13,6 +19,8 @@ export const ThumbnailPolicy = {
13
19
  export function projectMapPreview(document) {
14
20
  const bounds = emptyBounds();
15
21
  const matrices = worldMatrices(document);
22
+ const categories = categoryCatalog(document);
23
+ const owners = sectionCatalog(document).owners;
16
24
  const sections = new Map(document.sections.map((section) => [section.id, section]));
17
25
  const foreground = parseInt(document.background.color.slice(1, 3), 16) +
18
26
  parseInt(document.background.color.slice(3, 5), 16) +
@@ -22,19 +30,24 @@ export function projectMapPreview(document) {
22
30
  : "#ffffff";
23
31
  const paint = (value, fallback = foreground) => `fill="${value?.color ?? fallback}" fill-opacity="${value?.opacity ?? 0.45}"`;
24
32
  const number = (value) => value.toFixed(3);
33
+ const layers = layerCatalog(document);
34
+ const fragments = [];
35
+ let layer = -Infinity;
25
36
  let content = "";
26
37
  let glyphs = 0;
27
38
  let empty = true;
28
39
  const append = (markup) => {
29
- if (content.length + markup.length <= ThumbnailPolicy.MaximumContentLength)
40
+ if (content.length + markup.length <= ThumbnailPolicy.MaximumContentLength) {
30
41
  content += markup;
42
+ fragments.push({ order: layer, markup });
43
+ }
31
44
  };
32
45
  const point = (value, matrix) => {
33
46
  const result = matrix ? project(matrix, value) : value;
34
47
  extend(bounds, result);
35
48
  return `${number(result.x)},${number(result.y)}`;
36
49
  };
37
- const polygon = (value, matrix) => [value.outer, ...value.holes]
50
+ const polygon = (value, matrix) => [polygonContour(value).outer, ...value.holes]
38
51
  .map((ring) => {
39
52
  for (const entry of ring)
40
53
  point(entry, matrix);
@@ -58,9 +71,10 @@ export function projectMapPreview(document) {
58
71
  append(`<path d="${polygon(section.outline)}" ${paint(section.style?.fill)} fill-rule="evenodd"/>`);
59
72
  }
60
73
  for (const group of document.seatingGroups) {
74
+ layer = layers.order.get(group.id);
61
75
  empty = false;
62
76
  const matrix = matrices.get(group.id);
63
- const colour = sections.get(group.sectionId ?? "")?.style?.fill?.color ?? foreground;
77
+ const colour = sections.get(owners.get(group.id) ?? "")?.style?.fill?.color ?? foreground;
64
78
  if (group.boundary)
65
79
  append(`<path d="${polygon(group.boundary, matrix)}" fill="${colour}" fill-opacity=".3" fill-rule="evenodd"/>`);
66
80
  if (group.kind === SeatingKind.Rectangular)
@@ -73,12 +87,15 @@ export function projectMapPreview(document) {
73
87
  append(`<path d="${polygon({ outer: ring, holes: [] }, matrix)}" fill="${colour}" fill-opacity=".55"/>`);
74
88
  }
75
89
  const rows = new Map();
76
- const rowCounts = new Map("rows" in group
77
- ? group.rows.map((row) => [row.id, row.seats.length])
78
- : []);
90
+ const rowCounts = new Map("rows" in group ? group.rows.map((row) => [row.id, row.seats.length]) : []);
79
91
  let index = 0;
80
92
  const rowIndices = new Map();
81
- for (const seat of generateGroup(group)) {
93
+ for (const seat of documentGroupSeats(document, group)) {
94
+ layer = layers.order.get(seat.rowId ?? group.id);
95
+ if (seat.slot.gap) {
96
+ index++;
97
+ continue;
98
+ }
82
99
  const position = project(matrix, seat.position);
83
100
  const radius = Math.max(seat.size.width, seat.size.height) / 2;
84
101
  for (const corner of footprint(seat, matrix))
@@ -88,31 +105,57 @@ export function projectMapPreview(document) {
88
105
  const count = rowCounts.get(seat.rowId) ?? 1;
89
106
  const slot = rowIndices.get(seat.rowId) ?? 0;
90
107
  rowIndices.set(seat.rowId, slot + 1);
91
- if (slot % Math.max(1, Math.ceil(count / 24)) === 0 ||
92
- slot === count - 1)
108
+ if (slot % Math.max(1, Math.ceil(count / 24)) === 0 || slot === count - 1)
93
109
  row.push(`${number(position.x)},${number(position.y)}`);
94
110
  rows.set(seat.rowId, row);
95
111
  }
96
112
  if (glyphs < ThumbnailPolicy.MaximumSeatGlyphs && index % 8 === 0) {
97
- append(`<circle cx="${number(position.x)}" cy="${number(position.y)}" r="${number(radius)}" fill="${colour}" fill-opacity=".8"/>`);
113
+ const category = seat.categoryId ? categories.get(seat.categoryId) : undefined;
114
+ const shape = categorySeatShape(category, seat.slot);
115
+ const seatColour = category?.color ?? colour;
116
+ if (shape === SeatShape.Circle) {
117
+ append(`<circle cx="${number(position.x)}" cy="${number(position.y)}" r="${number(radius)}" fill="${seatColour}" fill-opacity=".8"/>`);
118
+ }
119
+ else {
120
+ const transform = multiply(matrix, transformMatrix({
121
+ positionM: seat.position,
122
+ rotationDeg: seat.rotationDeg,
123
+ }));
124
+ const shapeMarkup = seatShapeParts(shape)
125
+ .map((part) => {
126
+ if (part.kind === SeatShapePartKind.Rectangle)
127
+ return `<rect x="${number(part.x * seat.size.width)}" y="${number(part.y * seat.size.height)}" width="${number(part.width * seat.size.width)}" height="${number(part.height * seat.size.height)}" rx="${number(part.radius * Math.min(seat.size.width, seat.size.height))}"/>`;
128
+ const points = [];
129
+ for (let index = 0; index < part.points.length; index += 2)
130
+ points.push(`${number(part.points[index] * seat.size.width)},${number(part.points[index + 1] * seat.size.height)}`);
131
+ return `<polygon points="${points.join(" ")}"/>`;
132
+ })
133
+ .join("");
134
+ append(`<g transform="matrix(${transform.a} ${transform.b} ${transform.c} ${transform.d} ${transform.tx} ${transform.ty})" fill="${seatColour}" fill-opacity=".8">${shapeMarkup}</g>`);
135
+ }
98
136
  glyphs++;
99
137
  }
100
138
  index++;
101
139
  }
102
140
  if (!group.boundary) {
103
- for (const points of rows.values())
141
+ for (const [id, points] of rows) {
142
+ layer = layers.order.get(id);
104
143
  append(`<polyline points="${points.join(" ")}" fill="none" stroke="${colour}" stroke-width="${number(group.seatSizeM.height)}" stroke-opacity=".6" stroke-linecap="round"/>`);
144
+ }
105
145
  }
106
146
  }
107
147
  for (const area of document.areas) {
148
+ layer = layers.order.get(area.id);
108
149
  empty = false;
109
150
  const matrix = matrices.get(area.id);
110
151
  const path = area.shape.kind === ShapeKind.Polygon
111
152
  ? polygon(area.shape.boundary, matrix)
112
153
  : rectangle(area.shape.widthM, area.shape.heightM, matrix);
113
- append(`<path d="${path}" ${paint(sections.get(area.sectionId ?? "")?.style?.fill)} fill-rule="evenodd"/>`);
154
+ const category = area.categoryId ? categories.get(area.categoryId) : undefined;
155
+ append(`<path d="${path}" ${paint(category ? { color: category.color, opacity: 1 } : sections.get(owners.get(area.id) ?? "")?.style?.fill)} fill-rule="evenodd"/>`);
114
156
  }
115
- for (const art of [...document.decorations].sort((left, right) => left.zIndex - right.zIndex)) {
157
+ for (const art of document.decorations) {
158
+ layer = layers.order.get(art.id);
116
159
  empty = false;
117
160
  const matrix = matrices.get(art.id);
118
161
  let path;
@@ -132,17 +175,15 @@ export function projectMapPreview(document) {
132
175
  path = rectangle(Math.max(art.fontSizeM, Array.from(art.text).length * art.fontSizeM * 0.65), art.fontSizeM, matrix);
133
176
  else
134
177
  path = rectangle(art.sizeM.width, art.sizeM.height, matrix);
135
- const outline = art.kind === DecorationKind.Image ||
136
- art.kind === DecorationKind.Line ||
137
- art.kind === DecorationKind.Text;
178
+ const outline = art.kind === DecorationKind.Image || art.kind === DecorationKind.Line || art.kind === DecorationKind.Text;
138
179
  append(`<path d="${path}" ${outline ? 'fill="none"' : paint(art.style?.fill)} stroke="${art.style?.stroke?.color ?? foreground}" stroke-opacity="${art.style?.stroke?.opacity ?? 0.5}" stroke-width="${art.style?.strokeWidthM ?? 0.08}" fill-rule="evenodd"/>`);
139
180
  }
140
- const width = Number.isFinite(bounds.minX)
141
- ? Math.max(1, bounds.maxX - bounds.minX)
142
- : 1;
143
- const height = Number.isFinite(bounds.minY)
144
- ? Math.max(1, bounds.maxY - bounds.minY)
145
- : 1;
181
+ content = fragments
182
+ .sort((a, b) => a.order - b.order)
183
+ .map((fragment) => fragment.markup)
184
+ .join("");
185
+ const width = Number.isFinite(bounds.minX) ? Math.max(1, bounds.maxX - bounds.minX) : 1;
186
+ const height = Number.isFinite(bounds.minY) ? Math.max(1, bounds.maxY - bounds.minY) : 1;
146
187
  const padding = Math.max(width, height) * 0.08;
147
188
  const x = Number.isFinite(bounds.minX) ? bounds.minX - padding : -padding;
148
189
  const y = Number.isFinite(bounds.minY) ? bounds.minY - padding : -padding;
package/dist/reference.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DocumentLimits } from "./types.js";
1
+ import { DocumentLimits } from "./physical-document.interface.js";
2
2
  import { z } from "zod";
3
3
  import { uuidSchema } from "./schema.js";
4
4
  // Reference presentation is a dated observation, never authoritative inventory.
@@ -0,0 +1,30 @@
1
+ import { RowEnds, type PhysicalDocumentV1, type SeatingGroup, type RowInventory, type RowSlot, type SegmentedRow, type UUID, type PointM } from "./physical-document.interface.js";
2
+ export type RowSegment = {
3
+ row: SegmentedRow;
4
+ displayLabel: string;
5
+ coherent: boolean;
6
+ group: RowInventory;
7
+ part: RowSlot;
8
+ partIndex: number;
9
+ firstIndex: number;
10
+ totalSeats: number;
11
+ };
12
+ export type SegmentedRowEntry = {
13
+ row: SegmentedRow;
14
+ displayLabel: string;
15
+ coherent: boolean;
16
+ parts: readonly RowSegment[];
17
+ };
18
+ export declare function isRowInventory(group: SeatingGroup): group is RowInventory;
19
+ /** Logical rows associate independent physical parts without moving them between rendering banks. */
20
+ export declare function rowSegments(document: PhysicalDocumentV1): ReadonlyMap<UUID, RowSegment>;
21
+ export declare function changedSegmentGroups(before: PhysicalDocumentV1, after: PhysicalDocumentV1): ReadonlySet<UUID>;
22
+ export declare function suggestedRowEnds(document: PhysicalDocumentV1, rowId: UUID): RowEnds;
23
+ export type RowAisleGap = {
24
+ nextPartIndex: number;
25
+ distanceM: number;
26
+ requiredM: number;
27
+ deltaM: PointM;
28
+ };
29
+ /** A marked aisle leaves one seat of space between the adjacent seat centres. */
30
+ export declare function rowAisleGaps(document: PhysicalDocumentV1, rowId: UUID): RowAisleGap[];
@@ -0,0 +1,112 @@
1
+ import { generateGroup, project, worldMatrices } from "./geometry/geometry.js";
2
+ import { SeatingKind, RowEnds, RowJoin, } from "./physical-document.interface.js";
3
+ const segments = new WeakMap();
4
+ export function isRowInventory(group) {
5
+ return group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved;
6
+ }
7
+ /** Logical rows associate independent physical parts without moving them between rendering banks. */
8
+ export function rowSegments(document) {
9
+ const cached = segments.get(document);
10
+ if (cached)
11
+ return cached;
12
+ const owners = new Map(document.seatingGroups.flatMap((group) => isRowInventory(group) ? group.rows.map((part) => [part.id, { group, part }]) : []));
13
+ const result = new Map();
14
+ for (const row of document.segmentedRows ?? []) {
15
+ const parts = row.parts.map((part) => owners.get(part.rowId));
16
+ const names = row.parts.map((part) => part.labelOverride ?? row.label);
17
+ const coherent = names.every((name) => name === names[0]);
18
+ const totalSeats = parts.reduce((sum, item) => sum + item.part.seats.length, 0);
19
+ let firstIndex = 0;
20
+ parts.forEach((item, partIndex) => {
21
+ result.set(item.part.id, {
22
+ row,
23
+ displayLabel: names[partIndex],
24
+ coherent,
25
+ ...item,
26
+ partIndex,
27
+ firstIndex,
28
+ totalSeats,
29
+ });
30
+ firstIndex += item.part.seats.length;
31
+ });
32
+ }
33
+ segments.set(document, result);
34
+ return result;
35
+ }
36
+ export function changedSegmentGroups(before, after) {
37
+ const groups = new Set();
38
+ if (before.segmentedRows === after.segmentedRows && before.seatingGroups === after.seatingGroups)
39
+ return groups;
40
+ const previous = new Map((before.segmentedRows ?? []).map((row) => [row.id, row]));
41
+ const next = new Map((after.segmentedRows ?? []).map((row) => [row.id, row]));
42
+ for (const id of new Set([...previous.keys(), ...next.keys()])) {
43
+ const previousRow = previous.get(id), nextRow = next.get(id);
44
+ if (previousRow === nextRow &&
45
+ previousRow?.parts.every((part) => rowSegments(before).get(part.rowId).part.seats.length ===
46
+ rowSegments(after).get(part.rowId).part.seats.length))
47
+ continue;
48
+ for (const part of previous.get(id)?.parts ?? [])
49
+ groups.add(rowSegments(before).get(part.rowId).group.id);
50
+ for (const part of next.get(id)?.parts ?? [])
51
+ groups.add(rowSegments(after).get(part.rowId).group.id);
52
+ }
53
+ return groups;
54
+ }
55
+ export function suggestedRowEnds(document, rowId) {
56
+ const segment = rowSegments(document).get(rowId);
57
+ if (!segment)
58
+ return RowEnds.Both;
59
+ const first = segment.partIndex === 0 || segment.row.parts[segment.partIndex].joinBefore === RowJoin.Aisle;
60
+ const last = segment.partIndex === segment.row.parts.length - 1 ||
61
+ segment.row.parts[segment.partIndex + 1].joinBefore === RowJoin.Aisle;
62
+ if (first && last)
63
+ return RowEnds.Both;
64
+ if (first)
65
+ return RowEnds.Start;
66
+ return last ? RowEnds.End : RowEnds.None;
67
+ }
68
+ /** A marked aisle leaves one seat of space between the adjacent seat centres. */
69
+ export function rowAisleGaps(document, rowId) {
70
+ const row = document.segmentedRows.find((row) => row.id === rowId);
71
+ const segments = rowSegments(document);
72
+ const matrices = worldMatrices(document);
73
+ const seats = new Map();
74
+ const edges = row.parts.map((part) => {
75
+ const segment = segments.get(part.rowId);
76
+ let generated = seats.get(segment.group.id);
77
+ if (!generated) {
78
+ generated = [...generateGroup(segment.group)];
79
+ seats.set(segment.group.id, generated);
80
+ }
81
+ const physical = generated.filter((seat) => seat.rowId === part.rowId);
82
+ const matrix = matrices.get(segment.group.id);
83
+ return {
84
+ first: project(matrix, physical[0].position),
85
+ last: project(matrix, physical.at(-1).position),
86
+ pitchM: segment.part.layout.seatPitchM,
87
+ };
88
+ });
89
+ return row.parts.flatMap((part, index) => {
90
+ if (!index || part.joinBefore !== RowJoin.Aisle)
91
+ return [];
92
+ const previous = edges[index - 1], next = edges[index];
93
+ const dx = next.first.x - previous.last.x;
94
+ const dy = next.first.y - previous.last.y;
95
+ const distanceM = Math.hypot(dx, dy);
96
+ const requiredM = previous.pitchM + next.pitchM;
97
+ if (distanceM >= requiredM - 1e-9)
98
+ return [];
99
+ const angle = Math.atan2(dy, dx);
100
+ return [
101
+ {
102
+ nextPartIndex: index,
103
+ distanceM,
104
+ requiredM,
105
+ deltaM: {
106
+ x: Math.cos(angle) * (requiredM - distanceM),
107
+ y: Math.sin(angle) * (requiredM - distanceM),
108
+ },
109
+ },
110
+ ];
111
+ });
112
+ }