@mark1russell7/layout-contract 0.9.5 → 0.9.7
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/README.md +5 -2
- package/build/index.d.ts +92 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +189 -10
- package/build/index.js.map +1 -1
- package/build/{measures-D5hOVn9j.d.ts → measures-Aan-rHz1.d.ts} +16 -2
- package/build/measures-Aan-rHz1.d.ts.map +1 -0
- package/build/text.d.ts +1 -1
- package/package.json +2 -2
- package/src/hash.ts +5 -1
- package/src/index.ts +1 -0
- package/src/input.ts +15 -0
- package/src/output.ts +11 -2
- package/src/record.ts +41 -2
- package/src/resize.ts +92 -0
- package/src/rules.ts +35 -0
- package/src/strategy-catalog.ts +50 -4
- package/src/turn.ts +15 -2
- package/build/measures-D5hOVn9j.d.ts.map +0 -1
|
@@ -280,6 +280,18 @@ interface Port {
|
|
|
280
280
|
* Another port gives `undefined`, because the router picks its point.
|
|
281
281
|
*/
|
|
282
282
|
declare function portPoint(box: Pick<LayoutBox, "w" | "h">, port: Port): Point | undefined;
|
|
283
|
+
/**
|
|
284
|
+
* The sizes that a packer can give a box. Each bound is in the axes of the box before a turn.
|
|
285
|
+
* A bound that the value does not set is the size of the box. Thus `{ maxW: 300 }` lets the width grow from `w` to 300, and the height stays `h`.
|
|
286
|
+
* With `aspect: "keep"`, the ratio of the width to the height stays the ratio of `w` to `h`. The default is `free`.
|
|
287
|
+
*/
|
|
288
|
+
interface Resize {
|
|
289
|
+
readonly minW?: number;
|
|
290
|
+
readonly maxW?: number;
|
|
291
|
+
readonly minH?: number;
|
|
292
|
+
readonly maxH?: number;
|
|
293
|
+
readonly aspect?: "keep" | "free";
|
|
294
|
+
}
|
|
283
295
|
/** A box of an input. In the packer, its name is item. */
|
|
284
296
|
interface LayoutBox {
|
|
285
297
|
readonly id: string;
|
|
@@ -306,6 +318,8 @@ interface LayoutBox {
|
|
|
306
318
|
readonly margin?: Margin;
|
|
307
319
|
/** The packer can turn the box by 90 degrees. The output has the turned box and ports. */
|
|
308
320
|
readonly turnable?: boolean;
|
|
321
|
+
/** The packer can give the box another size in these bounds. The placement has the new size. Only a `rect` box without a shape can have it. */
|
|
322
|
+
readonly resize?: Resize;
|
|
309
323
|
/** The free data of the node. The grouping rule `keys` of `highways` reads `data.group`. */
|
|
310
324
|
readonly data?: Readonly<Record<string, unknown>>;
|
|
311
325
|
}
|
|
@@ -670,5 +684,5 @@ declare function minEffectOf(spec: Pick<MeasureSpec, "minEffect">, a?: number, b
|
|
|
670
684
|
* Two equal values are a tie, also two infinite values. A value `NaN` is an error.
|
|
671
685
|
*/
|
|
672
686
|
declare function compareMeasure(candidate: number, baseline: number, spec: Pick<MeasureSpec, "direction" | "minEffect">): Verdict;
|
|
673
|
-
export {
|
|
674
|
-
//# sourceMappingURL=measures-
|
|
687
|
+
export { CorpusEntry as $, shapeKindsOf as A, dropIndex as At, LayoutInput as B, snapRect as Bt, checkShapes as C, SIDES as Ct, ruleLevel as D, boundsOf as Dt, itemShapeOf as E, SizedRect as Et, LayoutBox as F, pointInRings as Ft, PairGap as G, PackInput as H, toSizedRect as Ht, LayoutCell as I, pointSegmentDistance as It, canonicalInput as J, Port as K, LayoutContainer as L, regionArea as Lt, shapeSupportProblems as M, marginSides as Mt, shapesOf as N, overlapOf as Nt, shapeKindOf as O, boxCenterDistance as Ot, Item as P, pointInRing as Pt, ClaimBreak as Q, LayoutEdge as R, scaleRect as Rt, boxArea as S, Ring as St, isShapeKind as T, Sides as Tt, PackInputOptions as U, translate as Ut, Obstacle as V, toRect as Vt, PackLink as W, portPoint as X, packLinks as Y, toPackInput as Z, ShapeKind as _, splitFolds as _t, MeasureSpec as a, FamilyCell as at, ShapeLimit as b, Rect as bt, minEffectOf as c, SplitFold as ct, SHAPE_KINDS as d, corpusHashOf as dt, CorpusSplit as et, SHAPE_KIND_IDS as f, declaredClaimOf as ft, ShapeInput as g, splitFileName as gt, ShapeGeometry as h, leaveOneSeedOut as ht, JointMeasureId as i, FamilyBy as it, shapeLevel as j, grow as jt, shapeKindProblem as k, crossingPoint as kt, DEFAULT_SHAPES as l, checkDeclared as lt, ShapeCheck as m, familyOf as mt, JOINT_MEASURES as n, Declares as nt, Verdict as o, SPLIT_SCHEMA as ot, ShapeBound as p, declaredCounts as pt, Resize as q, JOINT_MOVED_MIN as r, FAMILY_ANY_KIND as rt, compareMeasure as s, SplitCorpus as st, Direction as t, DeclaredClaim as tt, RuleLevel as u, checkSplit as ut, ShapeKindSpec as v, Margin as vt, inputShapeLevel as w, Side as wt, ShapeSupport as x, Region as xt, ShapeLevel as y, Point as yt, LayoutGenerator as z, segmentsCross as zt };
|
|
688
|
+
//# sourceMappingURL=measures-Aan-rHz1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measures-Aan-rHz1.d.ts","names":[],"sources":["../src/geometry.ts","../src/corpus.ts","../src/input.ts","../src/shapes.ts","../src/measures.ts"],"mappings":";KAGY;;cAGC,gBAAgB;UAEZ;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;;;;;;UAOM;WACN;WACA;WACA;WACA;;;iBAIK,OAAO,MAAM,YAAY;;iBAKzB,YAAY,MAAM,OAAO;;;;;iBAWzB,SAAS,MAAM,OAAO;;;;;;iBAWtB,UAAU,MAAM,MAAM,iBAAiB;;UAMtC;WACN;WACA;WACA;WACA;;;;;;KAOC;WACG;WAAuB;WAAoB;WAAoB;WAAoB;;WAEnF;WACA,QAAQ;WACR,iBAAiB;;WAEjB;WAAyB;WAAqB;WAAqB;;WACnE;WAA0B;WAAqB;WAAqB;WAAqB;;;KAG5F,kBAAkB;;iBAGd,YAAY,QAAQ,qBAAqB;;iBAOzC,KAAK,MAAM,MAAM,QAAQ,qBAAqB;;iBAM9C,SAAS,QAAQ,SAAS;;;;;iBA4B1B,WAAW,QAAQ;;iBAyBnB,UAAU,QAAQ,QAAQ,YAAY,aAAa;;;;;iBAoBnD,UAAU,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QAAQ;;WAER,QAAQ;;;;;;;;UASF;WACN;;WAEA;;WAEA;;;;;;;;;;;;;;;;;;;;;UAsBM;WACN,iBAAiB;WACjB;;;KAIC;;iBAGI,UAAU,MAAM,KAAK,kCAAkC,MAAM,YAAY;;KAM7E,aAAa;;;;;iBAMT,WAAW,KAAK,KAAK,4CAA4C,MAAM,YAAY;;KAOvF,aAAa,KAAK,+BAA+B,QAAQ,KAAK;;;;;iBAe1D,gBAAgB,KAAK,KAAK,sDAAsD,MAAM,WAAW,OAAO,aAAa;;;;;;;iBAWrH,qBAAqB,eAAe;;iBAwCpC,YAAY,iBAAiB,SAAS;;;;;iBAQtC,YAAY,KAAK,YAAY;;;;;;;iBAW7B,QAAQ,KAAK;;iBAQb,aAAa,OAAO,KAAK,wBAAwB;;iBAMjD,YAAY,OAAO,KAAK,wBAAwB;;iBAMhD,iBAAiB,KAAK;;iBAWtB,SAAS,KAAK,KAAK,mCAAmC;;UAKrD;;;;;;WAMN;;;;;;;;iBASK,YAAY,OAAO,YAAY,eAAe,gBAAgB,UAAS,aAAkB;;KCtQ7F;;;;;;UAOK,YAAY;WAClB,IAAI;WACJ;WACA,WAAW;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;;;;WAKA;aAAgC;;;WAEhC;;WAEA,kBAAkB;;;;;WAKlB,QAAQ;;;KAIP;;;;;cAqBC,yBAAyB,YAAY;;cAcrC;;KAGD;;;;;;iBAOI,YAAY,MAAM,KAAK,2BAA2B,YAAO;;;;;;;iBAezD,eAAe,mBAAmB,kBAAkB,MAAM,KAAK,0CAA0C"}
|
package/build/text.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as MeasureSpec } from "./measures-
|
|
1
|
+
import { a as MeasureSpec } from "./measures-Aan-rHz1.js";
|
|
2
2
|
/**
|
|
3
3
|
* The advance function of a host: the width of a run of text in a font, in pixels.
|
|
4
4
|
* A browser host gives `canvasAdvance(context)`. A test or a server host gives a function of a font file.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/layout-contract",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.7",
|
|
5
5
|
"description": "The shared contract of the packing and highways layout engines: the input and record formats, the turn rule, margins, tolerances and hard rules.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"layout",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@mark1russell7/cue": "^2.1.1",
|
|
53
53
|
"@types/node": "^26.6.4",
|
|
54
|
-
"@vitest/coverage-v8": "5.0
|
|
54
|
+
"@vitest/coverage-v8": "5.1.0",
|
|
55
55
|
"esbuild": "^0.28.2",
|
|
56
56
|
"fast-check": "^4.10.2",
|
|
57
57
|
"layout-contract-0221": "npm:@mark1russell7/layout-contract@0.2.21",
|
package/src/hash.ts
CHANGED
|
@@ -95,13 +95,17 @@ function byId(a: { readonly id: string }, b: { readonly id: string }): number {
|
|
|
95
95
|
* The placements, the moved obstacles and the overflow are in the order of their ids. A placement without `turn` gets `turn: 0`.
|
|
96
96
|
* Thus two packers with the same result in a different order have the same form.
|
|
97
97
|
* The function throws a `RangeError` when `placements`, `overflow` or `moved` has an id two times.
|
|
98
|
+
*
|
|
99
|
+
* A placement has `w` and `h` only when the packer set them, so the form of an output without a resize does not change.
|
|
98
100
|
*/
|
|
99
101
|
export function packOutputForm(output: PackOutput): unknown {
|
|
100
102
|
uniqueIds("placements", output.placements.map((p) => p.id));
|
|
101
103
|
uniqueIds("overflow", output.overflow);
|
|
102
104
|
uniqueIds("moved", output.moved.map((m) => m.id));
|
|
103
105
|
return {
|
|
104
|
-
placements: output.placements
|
|
106
|
+
placements: output.placements
|
|
107
|
+
.map((p) => ({ id: p.id, x: p.x, y: p.y, turn: p.turn ?? 0, ...(p.w === undefined ? {} : { w: p.w }), ...(p.h === undefined ? {} : { h: p.h }) }))
|
|
108
|
+
.sort(byId),
|
|
105
109
|
overflow: [...output.overflow].sort(),
|
|
106
110
|
size: { w: output.size.w, h: output.size.h },
|
|
107
111
|
moved: output.moved.map((m) => ({ id: m.id, x: m.x, y: m.y })).sort(byId),
|
package/src/index.ts
CHANGED
package/src/input.ts
CHANGED
|
@@ -40,6 +40,19 @@ export function portPoint(box: Pick<LayoutBox, "w" | "h">, port: Port): Point |
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* The sizes that a packer can give a box. Each bound is in the axes of the box before a turn.
|
|
45
|
+
* A bound that the value does not set is the size of the box. Thus `{ maxW: 300 }` lets the width grow from `w` to 300, and the height stays `h`.
|
|
46
|
+
* With `aspect: "keep"`, the ratio of the width to the height stays the ratio of `w` to `h`. The default is `free`.
|
|
47
|
+
*/
|
|
48
|
+
export interface Resize {
|
|
49
|
+
readonly minW?: number;
|
|
50
|
+
readonly maxW?: number;
|
|
51
|
+
readonly minH?: number;
|
|
52
|
+
readonly maxH?: number;
|
|
53
|
+
readonly aspect?: "keep" | "free";
|
|
54
|
+
}
|
|
55
|
+
|
|
43
56
|
/** A box of an input. In the packer, its name is item. */
|
|
44
57
|
export interface LayoutBox {
|
|
45
58
|
readonly id: string;
|
|
@@ -66,6 +79,8 @@ export interface LayoutBox {
|
|
|
66
79
|
readonly margin?: Margin;
|
|
67
80
|
/** The packer can turn the box by 90 degrees. The output has the turned box and ports. */
|
|
68
81
|
readonly turnable?: boolean;
|
|
82
|
+
/** The packer can give the box another size in these bounds. The placement has the new size. Only a `rect` box without a shape can have it. */
|
|
83
|
+
readonly resize?: Resize;
|
|
69
84
|
/** The free data of the node. The grouping rule `keys` of `highways` reads `data.group`. */
|
|
70
85
|
readonly data?: Readonly<Record<string, unknown>>;
|
|
71
86
|
}
|
package/src/output.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { boundsOf, translate } from "./geometry.ts";
|
|
2
2
|
import type { LayoutInput } from "./input.ts";
|
|
3
|
+
import { resizeBox } from "./resize.ts";
|
|
3
4
|
import { turnBox } from "./turn.ts";
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* The position of one item. `turn` is 90 when the packer turned a turnable item.
|
|
8
|
+
* `w` and `h` are the size of the placed item after the turn, when the packer resized an item with `resize`. Without them, the item keeps its size.
|
|
9
|
+
*/
|
|
6
10
|
export interface Placement {
|
|
7
11
|
readonly id: string;
|
|
8
12
|
readonly x: number;
|
|
9
13
|
readonly y: number;
|
|
10
14
|
readonly turn?: 0 | 90;
|
|
15
|
+
readonly w?: number;
|
|
16
|
+
readonly h?: number;
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
/** The facts of one stage of a strategy, for the records and the site. */
|
|
@@ -33,6 +39,8 @@ export interface PackOutput {
|
|
|
33
39
|
* This function gives the input with the output of a packer applied. Each placed box gets its position.
|
|
34
40
|
* A turned box gets its turned size, ports, margin and shape. Each moved obstacle moves.
|
|
35
41
|
* The container gets the size of the output. The router reads this result. It does not read `turn`.
|
|
42
|
+
*
|
|
43
|
+
* A placement with `w` or `h` gives the box that size after the turn (`resizeBox`).
|
|
36
44
|
*/
|
|
37
45
|
export function applyPack(input: LayoutInput, output: PackOutput): LayoutInput {
|
|
38
46
|
const at = new Map(output.placements.map((p) => [p.id, p]));
|
|
@@ -41,7 +49,8 @@ export function applyPack(input: LayoutInput, output: PackOutput): LayoutInput {
|
|
|
41
49
|
const p = at.get(box.id);
|
|
42
50
|
if (p === undefined) return box;
|
|
43
51
|
const turned = p.turn === 90 ? turnBox(box) : box;
|
|
44
|
-
|
|
52
|
+
const sized = p.w === undefined && p.h === undefined ? turned : resizeBox(turned, p.w ?? turned.w, p.h ?? turned.h);
|
|
53
|
+
return { ...sized, x: p.x, y: p.y };
|
|
45
54
|
});
|
|
46
55
|
const obstacles = input.obstacles?.map((o) => {
|
|
47
56
|
const m = moved.get(o.id);
|
package/src/record.ts
CHANGED
|
@@ -88,6 +88,23 @@ export interface Carried {
|
|
|
88
88
|
readonly fingerprints: Readonly<Record<string, string>>;
|
|
89
89
|
/** The id of the run that measured the record. */
|
|
90
90
|
readonly run?: string;
|
|
91
|
+
/** The facts of a change of the measure code between the measure and the run that keeps the record. Without the field, the measure code did not change. */
|
|
92
|
+
readonly code?: CarriedCode;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The facts of a carry over a change of the measure code (L147 rule B). A run kept the record because a code audit gave no difference.
|
|
97
|
+
* Such a record is a bridge only: the next full run at the commit `to` or later measures it again.
|
|
98
|
+
*/
|
|
99
|
+
export interface CarriedCode {
|
|
100
|
+
/** The commit of the measure code of the record. A record that a run carried before keeps this commit. */
|
|
101
|
+
readonly from: string;
|
|
102
|
+
/** The commit of the run that keeps the record. */
|
|
103
|
+
readonly to: string;
|
|
104
|
+
/** The count of the pairs of the code audit. Each pair had the same record, without the times, at the two commits. */
|
|
105
|
+
readonly audit: number;
|
|
106
|
+
/** The 95 % upper bound of the rate of a difference, from 0 differences in `audit` pairs (the Wilson interval). It is above 0 and not above 1. */
|
|
107
|
+
readonly upper: number;
|
|
91
108
|
}
|
|
92
109
|
|
|
93
110
|
/**
|
|
@@ -159,18 +176,32 @@ function numberMap(out: string[], v: unknown, name: string): void {
|
|
|
159
176
|
/** This function tells if a value is an object whose values are strings. */
|
|
160
177
|
const isStringMap = (v: unknown): v is Readonly<Record<string, string>> => isFields(v) && Object.values(v).every((s) => typeof s === "string");
|
|
161
178
|
|
|
179
|
+
/** This function gives the problems of the field `carried.code` of a record. */
|
|
180
|
+
function codeProblems(code: unknown): string[] {
|
|
181
|
+
if (!isFields(code)) return ["carried.code is not an object"];
|
|
182
|
+
const out: string[] = [];
|
|
183
|
+
for (const key of ["from", "to"] as const) if (typeof code[key] !== "string" || code[key] === "") out.push(`carried.code.${key} is not a commit`);
|
|
184
|
+
if (out.length === 0 && code["from"] === code["to"]) out.push("carried.code.to is the commit of carried.code.from");
|
|
185
|
+
if (!Number.isInteger(code["audit"]) || (code["audit"] as number) < 1) out.push("carried.code.audit is not a count of 1 or more");
|
|
186
|
+
const upper = code["upper"];
|
|
187
|
+
if (typeof upper !== "number" || !(upper > 0 && upper <= 1)) out.push("carried.code.upper is not above 0 and at most 1");
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
|
|
162
191
|
/** This function gives the problems of the field `carried` of a record. */
|
|
163
192
|
function carriedProblems(carried: unknown): string[] {
|
|
164
193
|
if (!isFields(carried)) return ["carried is not an object"];
|
|
165
194
|
const out: string[] = [];
|
|
166
195
|
for (const key of ["from", "to", "fingerprints"] as const) if (!isStringMap(carried[key])) out.push(`carried.${key} is not a map of strings`);
|
|
167
196
|
if (carried["run"] !== undefined && typeof carried["run"] !== "string") out.push("carried.run is not a string");
|
|
197
|
+
if (carried["code"] !== undefined) out.push(...codeProblems(carried["code"]));
|
|
168
198
|
if (out.length > 0) return out;
|
|
169
199
|
const from = carried["from"] as Readonly<Record<string, string>>;
|
|
170
200
|
const to = carried["to"] as Readonly<Record<string, string>>;
|
|
171
201
|
const names = (m: Readonly<Record<string, string>>): string => Object.keys(m).sort().join(",");
|
|
172
202
|
if (names(from) === "" || names(from) !== names(to)) out.push("carried.from and carried.to do not name the same engines");
|
|
173
|
-
|
|
203
|
+
// A carry over a change of the measure code can keep the engine versions. Each other carry needs a change of a version.
|
|
204
|
+
else if (carried["code"] === undefined && Object.keys(from).every((name) => from[name] === to[name])) out.push("carried.to has no other version than carried.from");
|
|
174
205
|
if (Object.keys(carried["fingerprints"] as object).length === 0) out.push("carried.fingerprints is empty");
|
|
175
206
|
return out;
|
|
176
207
|
}
|
|
@@ -254,10 +285,16 @@ export interface CarryFacts {
|
|
|
254
285
|
readonly from?: Readonly<Record<string, string>>;
|
|
255
286
|
/** The id of the run that measured the record. A record that a run carried before keeps its `carried.run`. */
|
|
256
287
|
readonly run?: string;
|
|
288
|
+
/**
|
|
289
|
+
* The facts of a change of the measure code, for a carry over such a change. A record with `carried.code` keeps its `carried.code.from`.
|
|
290
|
+
* Without this value, a record keeps its `carried.code`.
|
|
291
|
+
*/
|
|
292
|
+
readonly code?: CarriedCode;
|
|
257
293
|
}
|
|
258
294
|
|
|
259
295
|
/**
|
|
260
296
|
* This function gives a record that a run keeps after an engine release, with the field `carried` (L147).
|
|
297
|
+
* With `facts.code`, the run keeps the record over a change of the measure code. Then the engine versions can be the same.
|
|
261
298
|
* A record that a run carried before keeps the versions and the run of its measure, so `carried.from` always names the measure.
|
|
262
299
|
* The function throws a `RangeError` for a skipped record: a skip makes no claim on an output, so the run measures the pair again.
|
|
263
300
|
* It also throws a `RangeError` when `checkLayoutRecord` refuses the field `carried` of the result.
|
|
@@ -267,7 +304,9 @@ export function carryRecord(record: LayoutRecord, facts: CarryFacts): LayoutReco
|
|
|
267
304
|
const from = record.carried?.from ?? facts.from;
|
|
268
305
|
if (from === undefined) throw new RangeError(`The record of ${record.strategy} on ${record.input} has no carried.from, so the carry needs from.`);
|
|
269
306
|
const run = record.carried?.run ?? facts.run;
|
|
270
|
-
const
|
|
307
|
+
const before = record.carried?.code;
|
|
308
|
+
const code = facts.code === undefined ? before : { ...facts.code, from: before?.from ?? facts.code.from };
|
|
309
|
+
const carried: Carried = { from, to: facts.to, fingerprints: facts.fingerprints, ...(run === undefined ? {} : { run }), ...(code === undefined ? {} : { code }) };
|
|
271
310
|
const problems = carriedProblems(carried);
|
|
272
311
|
if (problems.length > 0) throw new RangeError(`The carry of ${record.strategy} on ${record.input} is bad: ${problems.join(", ")}.`);
|
|
273
312
|
return { ...record, carried };
|
package/src/resize.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// The resize of a box (`LayoutBox.resize`): the sizes that a packer can give a box, and the box at a new size.
|
|
2
|
+
import type { LayoutBox, Port } from "./input.ts";
|
|
3
|
+
import { shapeKindOf } from "./shapes.ts";
|
|
4
|
+
import { RECORD_EPS } from "./tolerance.ts";
|
|
5
|
+
|
|
6
|
+
/** The bounds of the size of a box, with each value set. */
|
|
7
|
+
export interface SizeBounds {
|
|
8
|
+
readonly minW: number;
|
|
9
|
+
readonly maxW: number;
|
|
10
|
+
readonly minH: number;
|
|
11
|
+
readonly maxH: number;
|
|
12
|
+
/** With `keep`, the ratio of the width to the height stays the ratio of `w` to `h` of the box. */
|
|
13
|
+
readonly aspect: "keep" | "free";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The names of the bounds of a resize. */
|
|
17
|
+
const BOUNDS = ["minW", "maxW", "minH", "maxH"] as const;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This function gives the bounds of the size of a box. A bound that `resize` does not set is the size of the box.
|
|
21
|
+
* A box without `resize` gives the bounds of its own size, so it keeps its size.
|
|
22
|
+
*/
|
|
23
|
+
export function sizeBoundsOf(box: LayoutBox): SizeBounds {
|
|
24
|
+
const r = box.resize;
|
|
25
|
+
return {
|
|
26
|
+
minW: r?.minW ?? box.w,
|
|
27
|
+
maxW: r?.maxW ?? box.w,
|
|
28
|
+
minH: r?.minH ?? box.h,
|
|
29
|
+
maxH: r?.maxH ?? box.h,
|
|
30
|
+
aspect: r?.aspect ?? "free",
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This function tells if a size is in the bounds of a box, with the tolerance `RECORD_EPS` of the records.
|
|
36
|
+
* With the aspect `keep`, the ratio of `w` to `h` also stays the ratio of the box, in the same tolerance.
|
|
37
|
+
* A size that is not positive and finite is not in the bounds.
|
|
38
|
+
*/
|
|
39
|
+
export function sizeFits(box: LayoutBox, w: number, h: number): boolean {
|
|
40
|
+
if (!(w > 0 && h > 0 && Number.isFinite(w) && Number.isFinite(h))) return false;
|
|
41
|
+
const b = sizeBoundsOf(box);
|
|
42
|
+
if (w < b.minW - RECORD_EPS || w > b.maxW + RECORD_EPS || h < b.minH - RECORD_EPS || h > b.maxH + RECORD_EPS) return false;
|
|
43
|
+
// A grid step of RECORD_EPS on w and h moves w * box.h - h * box.w by up to RECORD_EPS * (box.w + box.h).
|
|
44
|
+
return b.aspect === "free" || Math.abs(w * box.h - h * box.w) <= RECORD_EPS * (box.w + box.h);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** This function gives a port of a box of the size `w` by `h` after a resize to `toW` by `toH`. A port with `along` keeps its value. */
|
|
48
|
+
function resizePort(port: Port, w: number, h: number, toW: number, toH: number): Port {
|
|
49
|
+
return {
|
|
50
|
+
...port,
|
|
51
|
+
...(port.x === undefined ? {} : { x: (port.x * toW) / w }),
|
|
52
|
+
...(port.y === undefined ? {} : { y: (port.y * toH) / h }),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* This function gives a box at the size `w` by `h`. The position, the margin and the other fields stay.
|
|
58
|
+
* A port with `x` or `y` moves with the scale of its axis. A port with `along` keeps its place on its side.
|
|
59
|
+
* The function does not test the bounds: `sizeFits` does. A box with a shape is a bad input for a resize (`resizeProblems`).
|
|
60
|
+
*/
|
|
61
|
+
export function resizeBox(box: LayoutBox, w: number, h: number): LayoutBox {
|
|
62
|
+
if (w === box.w && h === box.h) return box;
|
|
63
|
+
return {
|
|
64
|
+
...box,
|
|
65
|
+
w,
|
|
66
|
+
h,
|
|
67
|
+
...(box.ports === undefined ? {} : { ports: box.ports.map((p) => resizePort(p, box.w, box.h, w, h)) }),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* This function gives the problems of the `resize` of a box. A box without `resize` has no problem.
|
|
73
|
+
* Only a `rect` box without a shape can have a resize. Each bound is a positive finite number.
|
|
74
|
+
* The size of the box is in its bounds, and `aspect` is `keep` or `free`.
|
|
75
|
+
*/
|
|
76
|
+
export function resizeProblems(box: LayoutBox): string[] {
|
|
77
|
+
const r = box.resize;
|
|
78
|
+
if (r === undefined) return [];
|
|
79
|
+
const at = `box ${box.id}`;
|
|
80
|
+
if (typeof r !== "object" || r === null) return [`${at}: the resize is not an object`];
|
|
81
|
+
const problems: string[] = [];
|
|
82
|
+
if (box.shape !== undefined || shapeKindOf(box) !== "rect") problems.push(`${at}: only a rect box without a shape can have a resize`);
|
|
83
|
+
for (const k of BOUNDS) {
|
|
84
|
+
const v = r[k];
|
|
85
|
+
if (v !== undefined && !(typeof v === "number" && v > 0 && Number.isFinite(v))) problems.push(`${at}: the resize bound ${k} ${String(v)} is not positive and finite`);
|
|
86
|
+
}
|
|
87
|
+
if (r.aspect !== undefined && r.aspect !== "keep" && r.aspect !== "free") problems.push(`${at}: the resize aspect ${String(r.aspect)} is not keep or free`);
|
|
88
|
+
const b = sizeBoundsOf(box);
|
|
89
|
+
if (!(b.minW <= box.w && box.w <= b.maxW)) problems.push(`${at}: the width ${box.w} is not in the resize bounds ${b.minW} to ${b.maxW}`);
|
|
90
|
+
if (!(b.minH <= box.h && box.h <= b.maxH)) problems.push(`${at}: the height ${box.h} is not in the resize bounds ${b.minH} to ${b.maxH}`);
|
|
91
|
+
return problems;
|
|
92
|
+
}
|
package/src/rules.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { boundsOf, grow, marginSides, overlapOf, pointInRings, type Margin, type Point, type Rect, type Region } from "./geometry.ts";
|
|
2
2
|
import type { LayoutBox, LayoutContainer, LayoutInput, Obstacle, PairGap, Port } from "./input.ts";
|
|
3
3
|
import { applyPack, type PackOutput } from "./output.ts";
|
|
4
|
+
import { resizeProblems, sizeFits } from "./resize.ts";
|
|
4
5
|
import { SHAPE_KIND_IDS, shapeKindProblem, type ShapeSupport } from "./shapes.ts";
|
|
5
6
|
import { DEFAULT_TOLERANCE, EPS, RECORD_EPS } from "./tolerance.ts";
|
|
7
|
+
import { turnBox } from "./turn.ts";
|
|
6
8
|
|
|
7
9
|
/** This function gives the area of a placed box: its shape or its rectangle, at its position. A box without a position gives `undefined`. */
|
|
8
10
|
export function placedRect(box: LayoutBox): Rect | undefined {
|
|
@@ -374,6 +376,11 @@ export interface PackHard {
|
|
|
374
376
|
readonly "in-container": number;
|
|
375
377
|
readonly "locked-kept": number;
|
|
376
378
|
readonly complete: number;
|
|
379
|
+
/**
|
|
380
|
+
* The count of the placements whose size is not in the bounds of their box (`countResizeBreaks`).
|
|
381
|
+
* `packHard` gives it only when a box of the input has `resize` or a placement has `w` or `h`. Thus the counts of the other inputs do not change.
|
|
382
|
+
*/
|
|
383
|
+
readonly "size-kept"?: number;
|
|
377
384
|
}
|
|
378
385
|
|
|
379
386
|
/**
|
|
@@ -553,6 +560,24 @@ export function countObstacleHits(
|
|
|
553
560
|
return count;
|
|
554
561
|
}
|
|
555
562
|
|
|
563
|
+
/**
|
|
564
|
+
* This function gives the count of the placements whose size is not in the bounds of their box (`sizeFits`).
|
|
565
|
+
* The bounds are in the axes of the placed box: a turned box has the turned bounds. A placement without `w` or `h` keeps that size of the box.
|
|
566
|
+
* A placement of an id that is not in the input does not count.
|
|
567
|
+
*/
|
|
568
|
+
export function countResizeBreaks(input: LayoutInput, output: PackOutput): number {
|
|
569
|
+
const was = new Map(input.boxes.map((b) => [b.id, b]));
|
|
570
|
+
let count = 0;
|
|
571
|
+
for (const p of output.placements) {
|
|
572
|
+
if (p.w === undefined && p.h === undefined) continue;
|
|
573
|
+
const box = was.get(p.id);
|
|
574
|
+
if (box === undefined) continue;
|
|
575
|
+
const placed = p.turn === 90 ? turnBox(box) : box;
|
|
576
|
+
if (!sizeFits(placed, p.w ?? placed.w, p.h ?? placed.h)) count++;
|
|
577
|
+
}
|
|
578
|
+
return count;
|
|
579
|
+
}
|
|
580
|
+
|
|
556
581
|
/**
|
|
557
582
|
* This function gives the count of each hard rule of the output of a packer.
|
|
558
583
|
* It applies the output with `applyPack`. Only the placed boxes and the locked boxes count for the overlaps and the container.
|
|
@@ -561,6 +586,7 @@ export function countObstacleHits(
|
|
|
561
586
|
* A locked box without a placement, or with a move of more than `RECORD_EPS`, breaks `locked-kept`.
|
|
562
587
|
* A locked box without a position in the input is a bad input, not a break. `checkInput` finds it.
|
|
563
588
|
* Another box without a placement that is not in `overflow` breaks `complete`.
|
|
589
|
+
* `size-kept` is in the result only when a box has `resize` or a placement has `w` or `h` (`countResizeBreaks`).
|
|
564
590
|
*
|
|
565
591
|
* `options` goes to `countOutside` for `in-container`.
|
|
566
592
|
*/
|
|
@@ -590,14 +616,22 @@ export function packHard(input: LayoutInput, output: PackOutput, tolerance: numb
|
|
|
590
616
|
"in-container": countOutside({ ...after, boxes: kept }, tolerance, options),
|
|
591
617
|
"locked-kept": lockedMoved,
|
|
592
618
|
complete: incomplete,
|
|
619
|
+
...(resizes(input, output) ? { "size-kept": countResizeBreaks(input, output) } : {}),
|
|
593
620
|
};
|
|
594
621
|
}
|
|
595
622
|
|
|
623
|
+
/** This function tells if a box of the input has `resize` or a placement of the output has `w` or `h`. */
|
|
624
|
+
function resizes(input: LayoutInput, output: PackOutput): boolean {
|
|
625
|
+
return input.boxes.some((b) => b.resize !== undefined) || output.placements.some((p) => p.w !== undefined || p.h !== undefined);
|
|
626
|
+
}
|
|
627
|
+
|
|
596
628
|
/**
|
|
597
629
|
* This function gives the problems of an input file. An empty list tells that the file is good.
|
|
598
630
|
* A problem is a bad input, not a break of a hard rule. Thus an engine refuses the input.
|
|
599
631
|
* In `pairGaps`, an unknown box, a pair of one box, a repeated pair in either order, a bad `gap` and bad `lanes` are problems.
|
|
600
632
|
* A port with `along` and no `side`, with `x` or `y`, or with a value outside [0, 1] is a problem.
|
|
633
|
+
*
|
|
634
|
+
* A bad `resize` is a problem (`resizeProblems`).
|
|
601
635
|
*/
|
|
602
636
|
export function checkInput(input: LayoutInput): readonly string[] {
|
|
603
637
|
const problems: string[] = [];
|
|
@@ -610,6 +644,7 @@ export function checkInput(input: LayoutInput): readonly string[] {
|
|
|
610
644
|
const shape = shapeKindProblem(box);
|
|
611
645
|
if (shape !== undefined) problems.push(shape);
|
|
612
646
|
for (const port of box.ports ?? []) problems.push(...alongProblems(box.id, port));
|
|
647
|
+
problems.push(...resizeProblems(box));
|
|
613
648
|
}
|
|
614
649
|
if (countPortsOffBorder(input.boxes) > 0) problems.push("a fixed port is not on the border of its box");
|
|
615
650
|
for (const edge of input.edges ?? []) {
|
package/src/strategy-catalog.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { canonicalJson } from "./hash.ts";
|
|
3
3
|
import type { Supports } from "./record.ts";
|
|
4
4
|
import { type AnyOption, declarationIssues, type ListItem, type NoDefaultReason, optionIssue, type OptionScale, type ValueOption } from "./strategy-space.ts";
|
|
5
|
-
import type { ParamValue, StrategySpace } from "./strategy-space.ts";
|
|
5
|
+
import type { ParamValue, SpaceParam, StageOption, StrategySpace } from "./strategy-space.ts";
|
|
6
6
|
|
|
7
7
|
/** The newest schema of a strategy catalog. A new field is a new version of the schema. */
|
|
8
8
|
export const STRATEGY_CATALOG_SCHEMA = "strategy-catalog/3";
|
|
@@ -167,16 +167,22 @@ export interface SupportProbe {
|
|
|
167
167
|
*
|
|
168
168
|
* - `spaceOnly` tells that the place sets no option, with one sentence that tells why. A stage option without an entry can also have this statement.
|
|
169
169
|
* - `option` names the option of the param, when the option has another name. `value` gives the option value of one param value, and `undefined` when the param value sets no option.
|
|
170
|
+
* - `strategy` is for a stage option that is one value of another strategy. The params of the stage option examine against the declarations of that strategy.
|
|
171
|
+
* `fixed` holds the options that the stage option sets, in the JSON form of their declarations. The params cannot have the name of a fixed option.
|
|
170
172
|
*/
|
|
171
173
|
export type ParamRoute =
|
|
172
174
|
| { readonly spaceOnly: string }
|
|
175
|
+
| { readonly strategy: string; readonly fixed?: Readonly<Record<string, unknown>> }
|
|
173
176
|
| { readonly option?: string; readonly value?: (value: ParamValue) => unknown };
|
|
174
177
|
|
|
175
178
|
/** The options of `checkCatalog`. */
|
|
176
179
|
export interface CatalogCheckOptions {
|
|
177
180
|
/** Each param of these spaces is examined against the declaration of its option. */
|
|
178
181
|
readonly spaces?: readonly StrategySpace[];
|
|
179
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* The routes of the params of `spaces`. The key is `<stage>/<option>.<param>`, or `<stage>/<option>` for a stage option. A route that matches nothing is a fault.
|
|
184
|
+
* Only a stage option can have a `strategy` route.
|
|
185
|
+
*/
|
|
180
186
|
readonly paramRoutes?: Readonly<Record<string, ParamRoute>>;
|
|
181
187
|
readonly probes?: readonly SupportProbe[];
|
|
182
188
|
/** This function runs `owner` with `choice` in its option `option`. It gives `true` for a refusal, or `undefined` if the input cannot go to `owner`. */
|
|
@@ -888,6 +894,41 @@ function checkParamValues(entry: CatalogEntry, engine: string, place: string, op
|
|
|
888
894
|
}
|
|
889
895
|
}
|
|
890
896
|
|
|
897
|
+
/** This function examines each option that a `strategy` route fixes. A fixed option is declared, its value is inside the declaration, and no param has its name. */
|
|
898
|
+
function checkFixed(entry: CatalogEntry, engine: string, name: string, fixed: Readonly<Record<string, unknown>>, params: readonly SpaceParam[], faults: string[]): void {
|
|
899
|
+
for (const [key, value] of Object.entries(fixed)) {
|
|
900
|
+
const declaration = entry.options[key];
|
|
901
|
+
if (declaration === undefined) faults.push(`${entry.key}: the route "${name}" fixes "${key}", and the strategy has no such option.`);
|
|
902
|
+
else {
|
|
903
|
+
const issue = optionIssue(key, value, declaration);
|
|
904
|
+
if (issue !== undefined) faults.push(`${entry.key}: the route "${name}" of the space ${engine} fixes a value outside the declaration. ${issue.message}`);
|
|
905
|
+
}
|
|
906
|
+
if (params.some((p) => p.name === key)) faults.push(`${entry.key}: the route "${name}" fixes "${key}", and the stage option also has the param "${key}".`);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* This function gives the entry of a stage option: its own entry, or the strategy of its `strategy` route.
|
|
912
|
+
* It gives `null` for a stage option without an entry or a `strategy` route, and `undefined` after a fault.
|
|
913
|
+
*/
|
|
914
|
+
function stageEntry(space: StrategySpace, name: string, option: StageOption, entries: ReadonlyMap<string, CatalogEntry>, check: SpaceCheck): CatalogEntry | undefined | null {
|
|
915
|
+
const own = entries.get(name) ?? entries.get(option.id);
|
|
916
|
+
const route = check.routes[name];
|
|
917
|
+
if (route === undefined || !("strategy" in route)) return own ?? null;
|
|
918
|
+
check.used.add(name);
|
|
919
|
+
if (own !== undefined) {
|
|
920
|
+
check.faults.push(`${own.key}: the route "${name}" names the strategy "${route.strategy}", and the stage option has its own entry.`);
|
|
921
|
+
return undefined;
|
|
922
|
+
}
|
|
923
|
+
const entry = entries.get(route.strategy);
|
|
924
|
+
if (entry === undefined) {
|
|
925
|
+
check.faults.push(`The route "${name}" names the strategy "${route.strategy}", and the catalog has no such entry.`);
|
|
926
|
+
return undefined;
|
|
927
|
+
}
|
|
928
|
+
checkFixed(entry, space.engine, name, route.fixed ?? {}, option.params, check.faults);
|
|
929
|
+
return entry;
|
|
930
|
+
}
|
|
931
|
+
|
|
891
932
|
/** This function examines each param of a space against the declaration of its option, with the routes of the engine. */
|
|
892
933
|
function checkSpaceParams(space: StrategySpace, entries: ReadonlyMap<string, CatalogEntry>, check: SpaceCheck): void {
|
|
893
934
|
const { routes, used, faults, notMatched, spaceOnly } = check;
|
|
@@ -899,8 +940,9 @@ function checkSpaceParams(space: StrategySpace, entries: ReadonlyMap<string, Cat
|
|
|
899
940
|
for (const stage of space.stages) {
|
|
900
941
|
for (const option of stage.options) {
|
|
901
942
|
const name = `${stage.name}/${option.id}`;
|
|
902
|
-
const entry =
|
|
903
|
-
if (entry === undefined)
|
|
943
|
+
const entry = stageEntry(space, name, option, entries, check);
|
|
944
|
+
if (entry === undefined) continue;
|
|
945
|
+
if (entry === null) {
|
|
904
946
|
const reason = routes[name];
|
|
905
947
|
if (reason !== undefined && "spaceOnly" in reason) {
|
|
906
948
|
used.add(name);
|
|
@@ -918,6 +960,10 @@ function checkSpaceParams(space: StrategySpace, entries: ReadonlyMap<string, Cat
|
|
|
918
960
|
else faults.push(`${entry.key}: the route "${place}" says that the param is only in the space, and the strategy has this option.`);
|
|
919
961
|
continue;
|
|
920
962
|
}
|
|
963
|
+
if (route !== undefined && "strategy" in route) {
|
|
964
|
+
faults.push(`${entry.key}: the route "${place}" names a strategy, and only a stage option can have a strategy route.`);
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
921
967
|
const target = route?.option ?? param.name;
|
|
922
968
|
if (entry.options[target] === undefined) {
|
|
923
969
|
if (route === undefined) notMatched.push(place);
|
package/src/turn.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SIDES, marginSides, type Margin, type Region, type Side } from "./geometry.ts";
|
|
2
|
-
import type { LayoutBox, Port } from "./input.ts";
|
|
2
|
+
import type { LayoutBox, Port, Resize } from "./input.ts";
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* The turn: 90 degrees clockwise, with the y axis down. The turned box has `w` and `h` swapped,
|
|
@@ -42,6 +42,18 @@ export function turnMargin(margin: Margin): Margin {
|
|
|
42
42
|
return { top: m.left, right: m.top, bottom: m.right, left: m.bottom };
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/** This function gives the bounds of a resize after the turn: the bounds of the width and of the height change places. */
|
|
46
|
+
export function turnResize(resize: Resize): Resize {
|
|
47
|
+
const { minW, maxW, minH, maxH, ...rest } = resize;
|
|
48
|
+
return {
|
|
49
|
+
...rest,
|
|
50
|
+
...(minH === undefined ? {} : { minW: minH }),
|
|
51
|
+
...(maxH === undefined ? {} : { maxW: maxH }),
|
|
52
|
+
...(minW === undefined ? {} : { minH: minW }),
|
|
53
|
+
...(maxW === undefined ? {} : { maxH: maxW }),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
45
57
|
/** This function gives a region relative to the origin of a box of height `h` after the turn. */
|
|
46
58
|
export function turnRegion(region: Region, h: number): Region {
|
|
47
59
|
switch (region.kind) {
|
|
@@ -60,7 +72,7 @@ export function turnRegion(region: Region, h: number): Region {
|
|
|
60
72
|
}
|
|
61
73
|
}
|
|
62
74
|
|
|
63
|
-
/** This function gives a box after the turn: the size, the ports, the margin and the
|
|
75
|
+
/** This function gives a box after the turn: the size, the ports, the margin, the shape and the bounds of a resize turn. The position stays. */
|
|
64
76
|
export function turnBox(box: LayoutBox): LayoutBox {
|
|
65
77
|
return {
|
|
66
78
|
...box,
|
|
@@ -69,5 +81,6 @@ export function turnBox(box: LayoutBox): LayoutBox {
|
|
|
69
81
|
...(box.ports === undefined ? {} : { ports: box.ports.map((p) => turnPort(p, box.h)) }),
|
|
70
82
|
...(box.margin === undefined ? {} : { margin: turnMargin(box.margin) }),
|
|
71
83
|
...(box.shape === undefined ? {} : { shape: turnRegion(box.shape, box.h) }),
|
|
84
|
+
...(box.resize === undefined ? {} : { resize: turnResize(box.resize) }),
|
|
72
85
|
};
|
|
73
86
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"measures-D5hOVn9j.d.ts","names":[],"sources":["../src/geometry.ts","../src/corpus.ts","../src/input.ts","../src/shapes.ts","../src/measures.ts"],"mappings":";KAGY;;cAGC,gBAAgB;UAEZ;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;;;;;;UAOM;WACN;WACA;WACA;WACA;;;iBAIK,OAAO,MAAM,YAAY;;iBAKzB,YAAY,MAAM,OAAO;;;;;iBAWzB,SAAS,MAAM,OAAO;;;;;;iBAWtB,UAAU,MAAM,MAAM,iBAAiB;;UAMtC;WACN;WACA;WACA;WACA;;;;;;KAOC;WACG;WAAuB;WAAoB;WAAoB;WAAoB;;WAEnF;WACA,QAAQ;WACR,iBAAiB;;WAEjB;WAAyB;WAAqB;WAAqB;;WACnE;WAA0B;WAAqB;WAAqB;WAAqB;;;KAG5F,kBAAkB;;iBAGd,YAAY,QAAQ,qBAAqB;;iBAOzC,KAAK,MAAM,MAAM,QAAQ,qBAAqB;;iBAM9C,SAAS,QAAQ,SAAS;;;;;iBA4B1B,WAAW,QAAQ;;iBAyBnB,UAAU,QAAQ,QAAQ,YAAY,aAAa;;;;;iBAoBnD,UAAU,GAAG,MAAM,GAAG;WAA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