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

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.
@@ -0,0 +1,15 @@
1
+ import type { PhysicalDocumentV1 } from "./types.js";
2
+ export declare const ThumbnailPolicy: {
3
+ readonly MaximumSvgLength: 128000;
4
+ readonly MaximumContentLength: 120000;
5
+ readonly MaximumRingPoints: 64;
6
+ readonly MaximumSeatGlyphs: 512;
7
+ readonly Width: 480;
8
+ readonly Height: 300;
9
+ };
10
+ /** Produces bounded, external-resource-free geometry for recovery and private map previews. */
11
+ export declare function projectMapPreview(document: PhysicalDocumentV1): {
12
+ svg: string;
13
+ empty: boolean;
14
+ };
15
+ export declare function thumbnailSvg(document: PhysicalDocumentV1): string;
@@ -0,0 +1,158 @@
1
+ import { footprint, generateGroup, project, worldMatrices, } from "./geometry/geometry.js";
2
+ import { emptyBounds, extend } from "./geometry/primitives.js";
3
+ import { DecorationKind, SeatingKind, ShapeKind } from "./types.js";
4
+ export const ThumbnailPolicy = {
5
+ MaximumSvgLength: 128000,
6
+ MaximumContentLength: 120000,
7
+ MaximumRingPoints: 64,
8
+ MaximumSeatGlyphs: 512,
9
+ Width: 480,
10
+ Height: 300,
11
+ };
12
+ /** Produces bounded, external-resource-free geometry for recovery and private map previews. */
13
+ export function projectMapPreview(document) {
14
+ const bounds = emptyBounds();
15
+ const matrices = worldMatrices(document);
16
+ const sections = new Map(document.sections.map((section) => [section.id, section]));
17
+ const foreground = parseInt(document.background.color.slice(1, 3), 16) +
18
+ parseInt(document.background.color.slice(3, 5), 16) +
19
+ parseInt(document.background.color.slice(5, 7), 16) >
20
+ 382
21
+ ? "#000000"
22
+ : "#ffffff";
23
+ const paint = (value, fallback = foreground) => `fill="${value?.color ?? fallback}" fill-opacity="${value?.opacity ?? 0.45}"`;
24
+ const number = (value) => value.toFixed(3);
25
+ let content = "";
26
+ let glyphs = 0;
27
+ let empty = true;
28
+ const append = (markup) => {
29
+ if (content.length + markup.length <= ThumbnailPolicy.MaximumContentLength)
30
+ content += markup;
31
+ };
32
+ const point = (value, matrix) => {
33
+ const result = matrix ? project(matrix, value) : value;
34
+ extend(bounds, result);
35
+ return `${number(result.x)},${number(result.y)}`;
36
+ };
37
+ const polygon = (value, matrix) => [value.outer, ...value.holes]
38
+ .map((ring) => {
39
+ for (const entry of ring)
40
+ point(entry, matrix);
41
+ const length = Math.min(ring.length, ThumbnailPolicy.MaximumRingPoints);
42
+ return `M${Array.from({ length }, (_, index) => point(ring[Math.floor((index * ring.length) / length)], matrix)).join("L")}Z`;
43
+ })
44
+ .join("");
45
+ const rectangle = (width, height, matrix) => polygon({
46
+ outer: [
47
+ { x: -width / 2, y: -height / 2 },
48
+ { x: width / 2, y: -height / 2 },
49
+ { x: width / 2, y: height / 2 },
50
+ { x: -width / 2, y: height / 2 },
51
+ ],
52
+ holes: [],
53
+ }, matrix);
54
+ for (const section of document.sections) {
55
+ if (!section.outline)
56
+ continue;
57
+ empty = false;
58
+ append(`<path d="${polygon(section.outline)}" ${paint(section.style?.fill)} fill-rule="evenodd"/>`);
59
+ }
60
+ for (const group of document.seatingGroups) {
61
+ empty = false;
62
+ const matrix = matrices.get(group.id);
63
+ const colour = sections.get(group.sectionId ?? "")?.style?.fill?.color ?? foreground;
64
+ if (group.boundary)
65
+ append(`<path d="${polygon(group.boundary, matrix)}" fill="${colour}" fill-opacity=".3" fill-rule="evenodd"/>`);
66
+ if (group.kind === SeatingKind.Rectangular)
67
+ append(`<path d="${rectangle(group.recipe.widthM, group.recipe.depthM, matrix)}" fill="${colour}" fill-opacity=".55"/>`);
68
+ if (group.kind === SeatingKind.Round) {
69
+ const ring = Array.from({ length: 32 }, (_, index) => ({
70
+ x: (Math.cos((index * Math.PI) / 16) * group.recipe.diameterM) / 2,
71
+ y: (Math.sin((index * Math.PI) / 16) * group.recipe.diameterM) / 2,
72
+ }));
73
+ append(`<path d="${polygon({ outer: ring, holes: [] }, matrix)}" fill="${colour}" fill-opacity=".55"/>`);
74
+ }
75
+ const rows = new Map();
76
+ const rowCounts = new Map("rows" in group
77
+ ? group.rows.map((row) => [row.id, row.seats.length])
78
+ : []);
79
+ let index = 0;
80
+ const rowIndices = new Map();
81
+ for (const seat of generateGroup(group)) {
82
+ const position = project(matrix, seat.position);
83
+ const radius = Math.max(seat.size.width, seat.size.height) / 2;
84
+ for (const corner of footprint(seat, matrix))
85
+ extend(bounds, corner);
86
+ if (seat.rowId !== null) {
87
+ const row = rows.get(seat.rowId) ?? [];
88
+ const count = rowCounts.get(seat.rowId) ?? 1;
89
+ const slot = rowIndices.get(seat.rowId) ?? 0;
90
+ rowIndices.set(seat.rowId, slot + 1);
91
+ if (slot % Math.max(1, Math.ceil(count / 24)) === 0 ||
92
+ slot === count - 1)
93
+ row.push(`${number(position.x)},${number(position.y)}`);
94
+ rows.set(seat.rowId, row);
95
+ }
96
+ 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"/>`);
98
+ glyphs++;
99
+ }
100
+ index++;
101
+ }
102
+ if (!group.boundary) {
103
+ for (const points of rows.values())
104
+ append(`<polyline points="${points.join(" ")}" fill="none" stroke="${colour}" stroke-width="${number(group.seatSizeM.height)}" stroke-opacity=".6" stroke-linecap="round"/>`);
105
+ }
106
+ }
107
+ for (const area of document.areas) {
108
+ empty = false;
109
+ const matrix = matrices.get(area.id);
110
+ const path = area.shape.kind === ShapeKind.Polygon
111
+ ? polygon(area.shape.boundary, matrix)
112
+ : rectangle(area.shape.widthM, area.shape.heightM, matrix);
113
+ append(`<path d="${path}" ${paint(sections.get(area.sectionId ?? "")?.style?.fill)} fill-rule="evenodd"/>`);
114
+ }
115
+ for (const art of [...document.decorations].sort((left, right) => left.zIndex - right.zIndex)) {
116
+ empty = false;
117
+ const matrix = matrices.get(art.id);
118
+ let path;
119
+ if (art.kind === DecorationKind.Polygon)
120
+ path = polygon(art.boundary, matrix);
121
+ else if (art.kind === DecorationKind.Line)
122
+ path = `M${art.pointsM.map((value) => point(value, matrix)).join("L")}`;
123
+ else if (art.kind === DecorationKind.Circle)
124
+ path = polygon({
125
+ outer: Array.from({ length: 32 }, (_, index) => ({
126
+ x: Math.cos((index * Math.PI) / 16) * art.radiusM,
127
+ y: Math.sin((index * Math.PI) / 16) * art.radiusM,
128
+ })),
129
+ holes: [],
130
+ }, matrix);
131
+ else if (art.kind === DecorationKind.Text)
132
+ path = rectangle(Math.max(art.fontSizeM, Array.from(art.text).length * art.fontSizeM * 0.65), art.fontSizeM, matrix);
133
+ else
134
+ 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;
138
+ 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
+ }
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;
146
+ const padding = Math.max(width, height) * 0.08;
147
+ const x = Number.isFinite(bounds.minX) ? bounds.minX - padding : -padding;
148
+ const y = Number.isFinite(bounds.minY) ? bounds.minY - padding : -padding;
149
+ const viewWidth = width + padding * 2;
150
+ const viewHeight = height + padding * 2;
151
+ return {
152
+ empty,
153
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" width="480" height="300" viewBox="${x} ${y} ${viewWidth} ${viewHeight}"><rect x="${x}" y="${y}" width="${viewWidth}" height="${viewHeight}" ${paint(document.background)}/>${content}</svg>`,
154
+ };
155
+ }
156
+ export function thumbnailSvg(document) {
157
+ return projectMapPreview(document).svg;
158
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seatmap-fyi/map-domain",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.2",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -72,6 +72,10 @@
72
72
  "./identity": {
73
73
  "types": "./dist/identity.d.ts",
74
74
  "import": "./dist/identity.js"
75
+ },
76
+ "./preview": {
77
+ "types": "./dist/preview.d.ts",
78
+ "import": "./dist/preview.js"
75
79
  }
76
80
  },
77
81
  "scripts": {