@seatmap-fyi/map-domain 0.0.0-stage → 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.
- package/dist/case-fold-data.d.ts +1 -0
- package/dist/case-fold-data.js +4 -0
- package/dist/catalog.d.ts +15 -0
- package/dist/catalog.js +35 -0
- package/dist/geometry/boundary.d.ts +22 -0
- package/dist/geometry/boundary.js +69 -0
- package/dist/geometry/curve-warnings.d.ts +15 -0
- package/dist/geometry/curve-warnings.js +46 -0
- package/dist/geometry/ellipse.d.ts +5 -0
- package/dist/geometry/ellipse.js +74 -0
- package/dist/geometry/geometry.d.ts +37 -0
- package/dist/geometry/geometry.js +219 -0
- package/dist/geometry/primitives.d.ts +12 -0
- package/dist/geometry/primitives.js +35 -0
- package/dist/geometry/seating-layout.d.ts +43 -0
- package/dist/geometry/seating-layout.js +132 -0
- package/dist/geometry/venue-outline.d.ts +21 -0
- package/dist/geometry/venue-outline.js +120 -0
- package/dist/identity.d.ts +5 -0
- package/dist/identity.js +61 -0
- package/dist/issues.d.ts +46 -0
- package/dist/issues.js +55 -0
- package/dist/labels.d.ts +3 -0
- package/dist/labels.js +45 -0
- package/dist/preview.d.ts +15 -0
- package/dist/preview.js +158 -0
- package/dist/reference.d.ts +29 -0
- package/dist/reference.js +51 -0
- package/dist/schema.d.ts +1629 -0
- package/dist/schema.js +560 -0
- package/dist/types.d.ts +313 -0
- package/dist/types.js +91 -0
- package/dist/validation.d.ts +27 -0
- package/dist/validation.js +267 -0
- package/package.json +88 -4
- package/src/unicode-license.txt +39 -0
- package/README.md +0 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function emptyBounds() {
|
|
2
|
+
return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
|
|
3
|
+
}
|
|
4
|
+
export function extend(bounds, p) {
|
|
5
|
+
bounds.minX = Math.min(bounds.minX, p.x);
|
|
6
|
+
bounds.minY = Math.min(bounds.minY, p.y);
|
|
7
|
+
bounds.maxX = Math.max(bounds.maxX, p.x);
|
|
8
|
+
bounds.maxY = Math.max(bounds.maxY, p.y);
|
|
9
|
+
}
|
|
10
|
+
export function intersects(a, b) {
|
|
11
|
+
return (a.minX <= b.maxX && a.maxX >= b.minX && a.minY <= b.maxY && a.maxY >= b.minY);
|
|
12
|
+
}
|
|
13
|
+
export function pointsBounds(points) {
|
|
14
|
+
const b = emptyBounds();
|
|
15
|
+
for (const p of points)
|
|
16
|
+
extend(b, p);
|
|
17
|
+
return b;
|
|
18
|
+
}
|
|
19
|
+
export function containsPoint(ring, p) {
|
|
20
|
+
let inside = false;
|
|
21
|
+
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
22
|
+
const a = ring[j], b = ring[i];
|
|
23
|
+
const cross = (p.x - a.x) * (b.y - a.y) - (p.y - a.y) * (b.x - a.x);
|
|
24
|
+
if (Math.abs(cross) <= 1e-6 &&
|
|
25
|
+
p.x >= Math.min(a.x, b.x) - 1e-6 &&
|
|
26
|
+
p.x <= Math.max(a.x, b.x) + 1e-6 &&
|
|
27
|
+
p.y >= Math.min(a.y, b.y) - 1e-6 &&
|
|
28
|
+
p.y <= Math.max(a.y, b.y) + 1e-6)
|
|
29
|
+
return true;
|
|
30
|
+
if (a.y > p.y !== b.y > p.y &&
|
|
31
|
+
p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x)
|
|
32
|
+
inside = !inside;
|
|
33
|
+
}
|
|
34
|
+
return inside;
|
|
35
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { SeatingKind, type StraightRows, type CurvedRows, type RoundTable, type RectangularTable, type PointM } from "../types.js";
|
|
2
|
+
export type RowsGeometry = Pick<StraightRows, "kind" | "recipe"> | Pick<CurvedRows, "kind" | "recipe">;
|
|
3
|
+
export declare enum TableSide {
|
|
4
|
+
Top = "top",
|
|
5
|
+
Right = "right",
|
|
6
|
+
Bottom = "bottom",
|
|
7
|
+
Left = "left"
|
|
8
|
+
}
|
|
9
|
+
export type SeatGeometry = {
|
|
10
|
+
position: PointM;
|
|
11
|
+
rotationDeg: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function rowSeatGeometry(group: RowsGeometry, row: number, seat: number, count: number, longestRow?: number): SeatGeometry;
|
|
14
|
+
export declare function roundChairGeometry(recipe: RoundTable["recipe"], chairHeightM: number, seat: number, count: number): SeatGeometry;
|
|
15
|
+
export declare function rectangularChairGeometry(recipe: RectangularTable["recipe"], chairHeightM: number, side: TableSide, seat: number, count: number): SeatGeometry;
|
|
16
|
+
export type SeatingPreview = (RowsGeometry & {
|
|
17
|
+
rows: number;
|
|
18
|
+
seatsPerRow: number;
|
|
19
|
+
rowCounts?: readonly number[];
|
|
20
|
+
seatSizeM: number;
|
|
21
|
+
}) | {
|
|
22
|
+
kind: SeatingKind.Round;
|
|
23
|
+
recipe: RoundTable["recipe"];
|
|
24
|
+
chairs: number;
|
|
25
|
+
seatSizeM: number;
|
|
26
|
+
} | {
|
|
27
|
+
kind: SeatingKind.Rectangular;
|
|
28
|
+
recipe: RectangularTable["recipe"];
|
|
29
|
+
sides: Record<TableSide, number>;
|
|
30
|
+
seatSizeM: number;
|
|
31
|
+
};
|
|
32
|
+
export type PreviewNumbering = {
|
|
33
|
+
rowStart: number;
|
|
34
|
+
tableLabel: string;
|
|
35
|
+
seatFontSizeM: number;
|
|
36
|
+
rowFontSizeM: number;
|
|
37
|
+
};
|
|
38
|
+
export type PreviewSeat = {
|
|
39
|
+
position: PointM;
|
|
40
|
+
row: number | null;
|
|
41
|
+
ordinal: number;
|
|
42
|
+
};
|
|
43
|
+
export declare function previewSeats(layout: SeatingPreview): Generator<PreviewSeat>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { CurveMode, RowAlignment, SeatingKind, } from "../types.js";
|
|
2
|
+
import { ellipseAngleAtDistance } from "./ellipse.js";
|
|
3
|
+
export var TableSide;
|
|
4
|
+
(function (TableSide) {
|
|
5
|
+
TableSide["Top"] = "top";
|
|
6
|
+
TableSide["Right"] = "right";
|
|
7
|
+
TableSide["Bottom"] = "bottom";
|
|
8
|
+
TableSide["Left"] = "left";
|
|
9
|
+
})(TableSide || (TableSide = {}));
|
|
10
|
+
export function rowSeatGeometry(group, row, seat, count, longestRow = count) {
|
|
11
|
+
if (group.kind === SeatingKind.Straight)
|
|
12
|
+
return {
|
|
13
|
+
position: {
|
|
14
|
+
x: (seat +
|
|
15
|
+
(longestRow - count) *
|
|
16
|
+
(group.recipe.rowAlignment === RowAlignment.Center
|
|
17
|
+
? 0.5
|
|
18
|
+
: group.recipe.rowAlignment === RowAlignment.End
|
|
19
|
+
? 1
|
|
20
|
+
: 0)) *
|
|
21
|
+
group.recipe.seatPitchM,
|
|
22
|
+
y: row * group.recipe.rowPitchM,
|
|
23
|
+
},
|
|
24
|
+
rotationDeg: 0,
|
|
25
|
+
};
|
|
26
|
+
const radius = group.recipe.innerRadiusM + row * group.recipe.rowPitchM;
|
|
27
|
+
const horizontal = group.recipe.innerRadiusM * (group.recipe.axisRatio ?? 1) +
|
|
28
|
+
row * group.recipe.rowPitchM;
|
|
29
|
+
const p = group.recipe.placement;
|
|
30
|
+
const angle = p.kind === CurveMode.Pitch
|
|
31
|
+
? ellipseAngleAtDistance(horizontal, radius, (p.centerAngleDeg * Math.PI) / 180, (seat - (count - 1) / 2) * p.seatPitchM)
|
|
32
|
+
: ((p.startAngleDeg +
|
|
33
|
+
(count === 1
|
|
34
|
+
? p.sweepAngleDeg / 2
|
|
35
|
+
: (p.sweepAngleDeg * seat) /
|
|
36
|
+
(Math.abs(p.sweepAngleDeg) === 360 ? count : count - 1))) *
|
|
37
|
+
Math.PI) /
|
|
38
|
+
180;
|
|
39
|
+
return {
|
|
40
|
+
position: { x: horizontal * Math.cos(angle), y: radius * Math.sin(angle) },
|
|
41
|
+
rotationDeg: horizontal === radius
|
|
42
|
+
? (angle * 180) / Math.PI + 90
|
|
43
|
+
: (Math.atan2(radius * Math.cos(angle), -horizontal * Math.sin(angle)) *
|
|
44
|
+
180) /
|
|
45
|
+
Math.PI,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function roundChairGeometry(recipe, chairHeightM, seat, count) {
|
|
49
|
+
const radius = recipe.diameterM / 2 + recipe.chairGapM + chairHeightM / 2;
|
|
50
|
+
const angle = recipe.startAngleDeg + (360 * seat) / count;
|
|
51
|
+
return {
|
|
52
|
+
position: {
|
|
53
|
+
x: radius * Math.cos((angle * Math.PI) / 180),
|
|
54
|
+
y: radius * Math.sin((angle * Math.PI) / 180),
|
|
55
|
+
},
|
|
56
|
+
rotationDeg: angle + 180,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function rectangularChairGeometry(recipe, chairHeightM, side, seat, count) {
|
|
60
|
+
const horizontal = side === TableSide.Top || side === TableSide.Bottom;
|
|
61
|
+
const length = horizontal ? recipe.widthM : recipe.depthM;
|
|
62
|
+
const along = recipe.chairPitchM === undefined
|
|
63
|
+
? -length / 2 + ((seat + 1) * length) / (count + 1)
|
|
64
|
+
: (seat - (count - 1) / 2) * recipe.chairPitchM;
|
|
65
|
+
const gap = recipe.chairGapM + chairHeightM / 2;
|
|
66
|
+
switch (side) {
|
|
67
|
+
case TableSide.Top:
|
|
68
|
+
return {
|
|
69
|
+
position: { x: along, y: -recipe.depthM / 2 - gap },
|
|
70
|
+
rotationDeg: 90,
|
|
71
|
+
};
|
|
72
|
+
case TableSide.Right:
|
|
73
|
+
return {
|
|
74
|
+
position: { x: recipe.widthM / 2 + gap, y: along },
|
|
75
|
+
rotationDeg: 180,
|
|
76
|
+
};
|
|
77
|
+
case TableSide.Bottom:
|
|
78
|
+
return {
|
|
79
|
+
position: { x: -along, y: recipe.depthM / 2 + gap },
|
|
80
|
+
rotationDeg: -90,
|
|
81
|
+
};
|
|
82
|
+
case TableSide.Left:
|
|
83
|
+
return {
|
|
84
|
+
position: { x: -recipe.widthM / 2 - gap, y: -along },
|
|
85
|
+
rotationDeg: 0,
|
|
86
|
+
};
|
|
87
|
+
default: {
|
|
88
|
+
const exhaustive = side;
|
|
89
|
+
return exhaustive;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function* previewSeats(layout) {
|
|
94
|
+
switch (layout.kind) {
|
|
95
|
+
case SeatingKind.Straight:
|
|
96
|
+
case SeatingKind.Curved: {
|
|
97
|
+
const longestRow = layout.rowCounts?.reduce((max, count) => Math.max(max, count), 0) ??
|
|
98
|
+
layout.seatsPerRow;
|
|
99
|
+
for (let row = 0; row < layout.rows; row++)
|
|
100
|
+
for (let seat = 0; seat < (layout.rowCounts?.[row] ?? layout.seatsPerRow); seat++)
|
|
101
|
+
yield {
|
|
102
|
+
position: rowSeatGeometry(layout, row, seat, layout.rowCounts?.[row] ?? layout.seatsPerRow, longestRow).position,
|
|
103
|
+
row,
|
|
104
|
+
ordinal: seat + 1,
|
|
105
|
+
};
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
case SeatingKind.Round:
|
|
109
|
+
for (let seat = 0; seat < layout.chairs; seat++)
|
|
110
|
+
yield {
|
|
111
|
+
position: roundChairGeometry(layout.recipe, layout.seatSizeM, seat, layout.chairs).position,
|
|
112
|
+
row: null,
|
|
113
|
+
ordinal: seat + 1,
|
|
114
|
+
};
|
|
115
|
+
return;
|
|
116
|
+
case SeatingKind.Rectangular: {
|
|
117
|
+
let ordinal = 0;
|
|
118
|
+
for (const side of Object.values(TableSide))
|
|
119
|
+
for (let seat = 0; seat < layout.sides[side]; seat++)
|
|
120
|
+
yield {
|
|
121
|
+
position: rectangularChairGeometry(layout.recipe, layout.seatSizeM, side, seat, layout.sides[side]).position,
|
|
122
|
+
row: null,
|
|
123
|
+
ordinal: ++ordinal,
|
|
124
|
+
};
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
default: {
|
|
128
|
+
const exhaustive = layout;
|
|
129
|
+
return exhaustive;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PointM, PolygonM } from "../types.js";
|
|
2
|
+
export declare enum OutlineKind {
|
|
3
|
+
Rectangle = "rectangle",
|
|
4
|
+
Ellipse = "ellipse",
|
|
5
|
+
Sector = "sector",
|
|
6
|
+
Envelope = "envelope"
|
|
7
|
+
}
|
|
8
|
+
export type OutlineParameters = {
|
|
9
|
+
kind: Exclude<OutlineKind, "envelope">;
|
|
10
|
+
center: PointM;
|
|
11
|
+
radiusX: number;
|
|
12
|
+
radiusY: number;
|
|
13
|
+
innerRatio: number;
|
|
14
|
+
startDeg: number;
|
|
15
|
+
sweepDeg: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function sampledOutline(p: OutlineParameters): PolygonM;
|
|
18
|
+
/** Conservative convex envelope, with no invented architectural voids. */
|
|
19
|
+
export declare function memberEnvelope(points: readonly PointM[], paddingM?: number): PolygonM;
|
|
20
|
+
/** Deterministic widest interior scan interval; holes participate in every scan. */
|
|
21
|
+
export declare function interiorLabelPoint(polygon: PolygonM): PointM;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { pointsBounds, containsPoint } from "./primitives.js";
|
|
2
|
+
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 = {}));
|
|
10
|
+
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) ||
|
|
20
|
+
p.radiusX <= 0 ||
|
|
21
|
+
p.radiusY <= 0 ||
|
|
22
|
+
p.innerRatio < 0 ||
|
|
23
|
+
p.innerRatio >= 1 ||
|
|
24
|
+
Math.abs(p.sweepDeg) > 360 ||
|
|
25
|
+
p.sweepDeg === 0)
|
|
26
|
+
throw new Error("Use positive radii, an inner ratio below 1 and a nonzero sweep within 360°.");
|
|
27
|
+
const point = (t, ratio = 1) => ({
|
|
28
|
+
x: p.center.x + p.radiusX * ratio * Math.cos(t),
|
|
29
|
+
y: p.center.y + p.radiusY * ratio * Math.sin(t),
|
|
30
|
+
});
|
|
31
|
+
if (p.kind === OutlineKind.Rectangle)
|
|
32
|
+
return {
|
|
33
|
+
outer: [
|
|
34
|
+
{ x: p.center.x - p.radiusX, y: p.center.y - p.radiusY },
|
|
35
|
+
{ x: p.center.x + p.radiusX, y: p.center.y - p.radiusY },
|
|
36
|
+
{ x: p.center.x + p.radiusX, y: p.center.y + p.radiusY },
|
|
37
|
+
{ x: p.center.x - p.radiusX, y: p.center.y + p.radiusY },
|
|
38
|
+
],
|
|
39
|
+
holes: [],
|
|
40
|
+
};
|
|
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;
|
|
44
|
+
const count = ellipseSegments(p.radiusX, p.radiusY, sweep);
|
|
45
|
+
const arc = (ratio) => Array.from({ length: count + (full ? 0 : 1) }, (_, i) => point(start + (sweep * i) / count, ratio));
|
|
46
|
+
const outer = arc(1);
|
|
47
|
+
if (full)
|
|
48
|
+
return {
|
|
49
|
+
outer,
|
|
50
|
+
holes: p.innerRatio > 0 ? [arc(p.innerRatio).reverse()] : [],
|
|
51
|
+
};
|
|
52
|
+
const ring = [
|
|
53
|
+
...outer,
|
|
54
|
+
...(p.innerRatio > 0 ? arc(p.innerRatio).reverse() : [p.center]),
|
|
55
|
+
];
|
|
56
|
+
if (ring.length > 10000)
|
|
57
|
+
throw new Error("The sector exceeds the 10,000-vertex limit at 1mm accuracy.");
|
|
58
|
+
return { outer: ring, holes: [] };
|
|
59
|
+
}
|
|
60
|
+
/** Conservative convex envelope, with no invented architectural voids. */
|
|
61
|
+
export function memberEnvelope(points, paddingM = 0.15) {
|
|
62
|
+
if (!points.length)
|
|
63
|
+
throw new Error("This section has no member geometry to outline.");
|
|
64
|
+
const expanded = points.flatMap((p) => [
|
|
65
|
+
{ x: p.x - paddingM, y: p.y - paddingM },
|
|
66
|
+
{ x: p.x + paddingM, y: p.y - paddingM },
|
|
67
|
+
{ x: p.x + paddingM, y: p.y + paddingM },
|
|
68
|
+
{ x: p.x - paddingM, y: p.y + paddingM },
|
|
69
|
+
]);
|
|
70
|
+
expanded.sort((a, b) => a.x - b.x || a.y - b.y);
|
|
71
|
+
const unique = expanded.filter((p, i) => !i || p.x !== expanded[i - 1].x || p.y !== expanded[i - 1].y);
|
|
72
|
+
const cross = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
|
73
|
+
const half = (input) => {
|
|
74
|
+
const result = [];
|
|
75
|
+
for (const p of input) {
|
|
76
|
+
while (result.length > 1 &&
|
|
77
|
+
cross(result[result.length - 2], result[result.length - 1], p) <= 0)
|
|
78
|
+
result.pop();
|
|
79
|
+
result.push(p);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
const lower = half(unique), upper = half([...unique].reverse());
|
|
84
|
+
lower.pop();
|
|
85
|
+
upper.pop();
|
|
86
|
+
const outer = [...lower, ...upper];
|
|
87
|
+
if (outer.length > 10000)
|
|
88
|
+
throw new Error("The envelope exceeds the boundary vertex limit.");
|
|
89
|
+
return { outer, holes: [] };
|
|
90
|
+
}
|
|
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,
|
|
98
|
+
};
|
|
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));
|
|
109
|
+
}
|
|
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;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DocumentParseStatus, parsePhysicalDocument } from "./schema.js";
|
|
3
|
+
export function* remapDocumentSteps(source, name) {
|
|
4
|
+
const ids = new Map(), warnings = [];
|
|
5
|
+
function* allocate(value) {
|
|
6
|
+
if (!value || typeof value !== "object")
|
|
7
|
+
return;
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
yield 0;
|
|
10
|
+
for (const child of value)
|
|
11
|
+
yield* allocate(child);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const record = z.record(z.string(), z.unknown()).parse(value);
|
|
15
|
+
if (typeof record.id === "string")
|
|
16
|
+
ids.set(record.id, crypto.randomUUID());
|
|
17
|
+
yield typeof record.id === "string" ? 1 : 0;
|
|
18
|
+
for (const [key, child] of Object.entries(record))
|
|
19
|
+
if (key !== "assets")
|
|
20
|
+
yield* allocate(child);
|
|
21
|
+
}
|
|
22
|
+
yield* allocate(source);
|
|
23
|
+
function* remap(value, key = "") {
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
yield 0;
|
|
26
|
+
const result = [];
|
|
27
|
+
for (const child of value)
|
|
28
|
+
result.push(yield* remap(child, key));
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
if (value && typeof value === "object") {
|
|
32
|
+
const record = z.record(z.string(), z.unknown()).parse(value);
|
|
33
|
+
yield typeof record.id === "string" ? 1 : 0;
|
|
34
|
+
const result = {};
|
|
35
|
+
for (const [field, child] of Object.entries(record)) {
|
|
36
|
+
if (field === "companionForSeatId" &&
|
|
37
|
+
typeof child === "string" &&
|
|
38
|
+
!ids.has(child)) {
|
|
39
|
+
warnings.push("An external companion relationship was cleared.");
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
result[field] = yield* remap(child, field);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
if (typeof value === "string" &&
|
|
47
|
+
["id", "parentId", "sectionId", "companionForSeatId", "assetId"].includes(key))
|
|
48
|
+
return ids.get(value) ?? value;
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
const remapped = yield* remap(source);
|
|
52
|
+
const parsed = parsePhysicalDocument({
|
|
53
|
+
...z.record(z.string(), z.unknown()).parse(remapped),
|
|
54
|
+
mapId: crypto.randomUUID(),
|
|
55
|
+
name,
|
|
56
|
+
});
|
|
57
|
+
if (parsed.status !== DocumentParseStatus.Accepted)
|
|
58
|
+
throw new Error("Identity remapping produced invalid physical structure.");
|
|
59
|
+
yield 1;
|
|
60
|
+
return { document: parsed.document, warnings: [...new Set(warnings)] };
|
|
61
|
+
}
|
package/dist/issues.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { UUID } from "./types.js";
|
|
2
|
+
export declare enum IssueCode {
|
|
3
|
+
DuplicateId = "DUPLICATE_ID",
|
|
4
|
+
InvalidJson = "INVALID_JSON",
|
|
5
|
+
InvalidParent = "INVALID_PARENT",
|
|
6
|
+
InvalidStructure = "INVALID_STRUCTURE",
|
|
7
|
+
Limit = "LIMIT_EXCEEDED",
|
|
8
|
+
UnknownSection = "UNKNOWN_SECTION",
|
|
9
|
+
UnsupportedVersion = "UNSUPPORTED_VERSION",
|
|
10
|
+
WorldBounds = "WORLD_BOUNDS",
|
|
11
|
+
DuplicateLabel = "DUPLICATE_LABEL",
|
|
12
|
+
EmptyInventory = "EMPTY_INVENTORY",
|
|
13
|
+
InvalidBoundary = "INVALID_BOUNDARY",
|
|
14
|
+
InvalidCompanion = "INVALID_COMPANION",
|
|
15
|
+
InvalidLabel = "INVALID_LABEL",
|
|
16
|
+
MissingAsset = "MISSING_ASSET",
|
|
17
|
+
CurveOverrun = "CURVE_OVERRUN",
|
|
18
|
+
SeatClearance = "SEAT_CLEARANCE",
|
|
19
|
+
OutsideBoundary = "OUTSIDE_BOUNDARY",
|
|
20
|
+
InvalidCommand = "INVALID_COMMAND"
|
|
21
|
+
}
|
|
22
|
+
export declare enum IssueSeverity {
|
|
23
|
+
Error = "error",
|
|
24
|
+
Warning = "warning"
|
|
25
|
+
}
|
|
26
|
+
export declare enum IssueRemediation {
|
|
27
|
+
Edit = "edit",
|
|
28
|
+
Remove = "remove"
|
|
29
|
+
}
|
|
30
|
+
export declare enum BlockedAction {
|
|
31
|
+
FinalizeAssignment = "finalizeAssignment",
|
|
32
|
+
Publish = "publish",
|
|
33
|
+
ReplaceBinding = "replaceBinding"
|
|
34
|
+
}
|
|
35
|
+
export type DomainIssue = {
|
|
36
|
+
code: IssueCode;
|
|
37
|
+
severity: IssueSeverity;
|
|
38
|
+
message: string;
|
|
39
|
+
entityIds: UUID[];
|
|
40
|
+
fieldPath?: string;
|
|
41
|
+
relatedEntityIds?: UUID[];
|
|
42
|
+
remediation: IssueRemediation[];
|
|
43
|
+
blocks: BlockedAction[];
|
|
44
|
+
};
|
|
45
|
+
export declare function issue(code: IssueCode, message: string, entityIds: UUID[], fieldPath?: string): DomainIssue;
|
|
46
|
+
export declare function issueKey(value: DomainIssue): string;
|
package/dist/issues.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export var IssueCode;
|
|
2
|
+
(function (IssueCode) {
|
|
3
|
+
IssueCode["DuplicateId"] = "DUPLICATE_ID";
|
|
4
|
+
IssueCode["InvalidJson"] = "INVALID_JSON";
|
|
5
|
+
IssueCode["InvalidParent"] = "INVALID_PARENT";
|
|
6
|
+
IssueCode["InvalidStructure"] = "INVALID_STRUCTURE";
|
|
7
|
+
IssueCode["Limit"] = "LIMIT_EXCEEDED";
|
|
8
|
+
IssueCode["UnknownSection"] = "UNKNOWN_SECTION";
|
|
9
|
+
IssueCode["UnsupportedVersion"] = "UNSUPPORTED_VERSION";
|
|
10
|
+
IssueCode["WorldBounds"] = "WORLD_BOUNDS";
|
|
11
|
+
IssueCode["DuplicateLabel"] = "DUPLICATE_LABEL";
|
|
12
|
+
IssueCode["EmptyInventory"] = "EMPTY_INVENTORY";
|
|
13
|
+
IssueCode["InvalidBoundary"] = "INVALID_BOUNDARY";
|
|
14
|
+
IssueCode["InvalidCompanion"] = "INVALID_COMPANION";
|
|
15
|
+
IssueCode["InvalidLabel"] = "INVALID_LABEL";
|
|
16
|
+
IssueCode["MissingAsset"] = "MISSING_ASSET";
|
|
17
|
+
IssueCode["CurveOverrun"] = "CURVE_OVERRUN";
|
|
18
|
+
IssueCode["SeatClearance"] = "SEAT_CLEARANCE";
|
|
19
|
+
IssueCode["OutsideBoundary"] = "OUTSIDE_BOUNDARY";
|
|
20
|
+
IssueCode["InvalidCommand"] = "INVALID_COMMAND";
|
|
21
|
+
})(IssueCode || (IssueCode = {}));
|
|
22
|
+
export var IssueSeverity;
|
|
23
|
+
(function (IssueSeverity) {
|
|
24
|
+
IssueSeverity["Error"] = "error";
|
|
25
|
+
IssueSeverity["Warning"] = "warning";
|
|
26
|
+
})(IssueSeverity || (IssueSeverity = {}));
|
|
27
|
+
export var IssueRemediation;
|
|
28
|
+
(function (IssueRemediation) {
|
|
29
|
+
IssueRemediation["Edit"] = "edit";
|
|
30
|
+
IssueRemediation["Remove"] = "remove";
|
|
31
|
+
})(IssueRemediation || (IssueRemediation = {}));
|
|
32
|
+
export var BlockedAction;
|
|
33
|
+
(function (BlockedAction) {
|
|
34
|
+
BlockedAction["FinalizeAssignment"] = "finalizeAssignment";
|
|
35
|
+
BlockedAction["Publish"] = "publish";
|
|
36
|
+
BlockedAction["ReplaceBinding"] = "replaceBinding";
|
|
37
|
+
})(BlockedAction || (BlockedAction = {}));
|
|
38
|
+
export function issue(code, message, entityIds, fieldPath) {
|
|
39
|
+
return {
|
|
40
|
+
code,
|
|
41
|
+
severity: IssueSeverity.Error,
|
|
42
|
+
message,
|
|
43
|
+
entityIds,
|
|
44
|
+
fieldPath,
|
|
45
|
+
remediation: [IssueRemediation.Edit, IssueRemediation.Remove],
|
|
46
|
+
blocks: [
|
|
47
|
+
BlockedAction.FinalizeAssignment,
|
|
48
|
+
BlockedAction.Publish,
|
|
49
|
+
BlockedAction.ReplaceBinding,
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function issueKey(value) {
|
|
54
|
+
return `${value.code}:${[...value.entityIds].sort().join(",")}:${value.fieldPath ?? ""}`;
|
|
55
|
+
}
|
package/dist/labels.d.ts
ADDED
package/dist/labels.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { NumberingScheme, LabelDirection, } from "./types.js";
|
|
2
|
+
import { caseFoldData } from "./case-fold-data.js";
|
|
3
|
+
const folds = new Map(caseFoldData.split(";").map((entry) => {
|
|
4
|
+
const [from, to] = entry.split(":");
|
|
5
|
+
return [
|
|
6
|
+
Number.parseInt(from, 16),
|
|
7
|
+
String.fromCodePoint(...to.split(",").map((cp) => Number.parseInt(cp, 16))),
|
|
8
|
+
];
|
|
9
|
+
}));
|
|
10
|
+
// Unicode 17 White_Space, PropList.txt; same license as case-fold-data.
|
|
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,
|
|
14
|
+
]);
|
|
15
|
+
export function labelKey(value) {
|
|
16
|
+
const points = Array.from(value);
|
|
17
|
+
let start = 0;
|
|
18
|
+
let end = points.length;
|
|
19
|
+
while (start < end && whitespace.has(points[start].codePointAt(0)))
|
|
20
|
+
start++;
|
|
21
|
+
while (end > start && whitespace.has(points[end - 1].codePointAt(0)))
|
|
22
|
+
end--;
|
|
23
|
+
return Array.from(points.slice(start, end).join("").normalize("NFC"), (cp) => folds.get(cp.codePointAt(0)) ?? cp)
|
|
24
|
+
.join("")
|
|
25
|
+
.normalize("NFC");
|
|
26
|
+
}
|
|
27
|
+
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);
|
|
35
|
+
let label = String(n);
|
|
36
|
+
if (sequence.scheme === NumberingScheme.Alphabetic) {
|
|
37
|
+
label = "";
|
|
38
|
+
while (n > 0) {
|
|
39
|
+
n--;
|
|
40
|
+
label = String.fromCharCode(65 + (n % 26)) + label;
|
|
41
|
+
n = Math.floor(n / 26);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return (sequence.prefix ?? "") + label + (sequence.suffix ?? "");
|
|
45
|
+
}
|
|
@@ -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;
|