@mark1russell7/layout-contract 0.3.0 → 0.3.1

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.
@@ -350,6 +350,15 @@ interface LayoutInput {
350
350
  */
351
351
  readonly invalidated?: readonly string[];
352
352
  }
353
+ /**
354
+ * A link between two items of a packer input. A graph order of the packer reads the links.
355
+ * `a` and `b` are indexes into `PackInput.items`. The weight is 1 when it has no value.
356
+ */
357
+ interface PackLink {
358
+ readonly a: number;
359
+ readonly b: number;
360
+ readonly weight?: number;
361
+ }
353
362
  /** The input of a packer: a `layout-input/1` file without the edges. */
354
363
  interface PackInput {
355
364
  readonly container: LayoutContainer;
@@ -357,9 +366,26 @@ interface PackInput {
357
366
  readonly obstacles?: readonly Obstacle[];
358
367
  readonly gap?: number;
359
368
  readonly pairGaps?: readonly PairGap[];
369
+ /** The links between the items. An input without `links` has no graph, and the links have no effect on an order that does not read them. */
370
+ readonly links?: readonly PackLink[];
371
+ }
372
+ /** The options of `toPackInput`. */
373
+ interface PackInputOptions {
374
+ /** With `true`, the packer input gets the links of `packLinks`. The default is `false`, so the input has no `links`. */
375
+ readonly links?: boolean;
360
376
  }
361
- /** This function gives the packer input of a file. An input without a container gets `{ fixed: "none" }`, so the packer picks the size. */
362
- declare function toPackInput(input: LayoutInput): PackInput;
377
+ /**
378
+ * This function gives the packer input of a file. An input without a container gets `{ fixed: "none" }`, so the packer picks the size.
379
+ * The edges are not in the packer input. With the option `links`, their links are in it.
380
+ */
381
+ declare function toPackInput(input: LayoutInput, options?: PackInputOptions): PackInput;
382
+ /**
383
+ * This function gives the links of the edges of a file, with indexes into `input.boxes`.
384
+ * - Each link has `a` below `b`. The list is sorted by `a` and then by `b`.
385
+ * - The edges of one pair of boxes make one link. Its weight is the count of the edges, and a link of one edge has no weight.
386
+ * - The function does not use an edge to a box that is not in `input.boxes`, or an edge from a box to the same box.
387
+ */
388
+ declare function packLinks(input: LayoutInput): PackLink[];
363
389
  /**
364
390
  * This function gives the canonical form of an input. `documentHash` uses it for each `layout-input/1` document.
365
391
  * Each pair of `pairGaps` gets `a` before `b`, and the list is sorted by `a` and then by `b`.
@@ -556,5 +582,5 @@ declare function minEffectOf(spec: Pick<MeasureSpec, "minEffect">, a?: number, b
556
582
  * Two equal values are a tie, also two infinite values. A value `NaN` is an error.
557
583
  */
558
584
  declare function compareMeasure(candidate: number, baseline: number, spec: Pick<MeasureSpec, "direction" | "minEffect">): Verdict;
559
- export { SPLIT_SCHEMA as $, shapesOf as A, PairGap as B, itemShapeOf as C, translate as Ct, shapeKindsOf as D, shapeKindProblem as E, LayoutEdge as F, ClaimBreak as G, canonicalInput as H, LayoutGenerator as I, DeclaredClaim as J, CorpusEntry as K, LayoutInput as L, LayoutBox as M, LayoutCell as N, shapeLevel as O, LayoutContainer as P, FamilyCell as Q, Obstacle as R, isShapeKind as S, regionArea as St, shapeKindOf as T, portPoint as U, Port as V, toPackInput as W, FAMILY_ANY_KIND as X, Declares as Y, FamilyBy as Z, ShapeKindSpec as _, Sides as _t, MeasureSpec as a, declaredClaimOf as at, boxArea as b, marginSides as bt, minEffectOf as c, leaveOneSeedOut as ct, SHAPE_KINDS as d, Margin as dt, SplitCorpus as et, SHAPE_KIND_IDS as f, Point as ft, ShapeKind as g, Side as gt, ShapeGeometry as h, SIDES as ht, JointMeasureId as i, corpusHashOf as it, Item as j, shapeSupportProblems as k, DEFAULT_SHAPES as l, splitFileName as lt, ShapeCheck as m, Region as mt, JOINT_MEASURES as n, checkDeclared as nt, Verdict as o, declaredCounts as ot, ShapeBound as p, Rect as pt, CorpusSplit as q, JOINT_MOVED_MIN as r, checkSplit as rt, compareMeasure as s, familyOf as st, Direction as t, SplitFold as tt, RuleLevel as u, splitFolds as ut, ShapeLevel as v, boundsOf as vt, ruleLevel as w, checkShapes as x, overlapOf as xt, ShapeSupport as y, grow as yt, PackInput as z };
560
- //# sourceMappingURL=measures-CQAuu3T5.d.ts.map
585
+ export { FAMILY_ANY_KIND as $, shapesOf as A, PackInputOptions as B, itemShapeOf as C, marginSides as Ct, shapeKindsOf as D, shapeKindProblem as E, translate as Et, LayoutEdge as F, packLinks as G, PairGap as H, LayoutGenerator as I, ClaimBreak as J, portPoint as K, LayoutInput as L, LayoutBox as M, LayoutCell as N, shapeLevel as O, LayoutContainer as P, Declares as Q, Obstacle as R, isShapeKind as S, grow as St, shapeKindOf as T, regionArea as Tt, Port as U, PackLink as V, canonicalInput as W, CorpusSplit as X, CorpusEntry as Y, DeclaredClaim as Z, ShapeKindSpec as _, Region as _t, MeasureSpec as a, checkDeclared as at, boxArea as b, Sides as bt, minEffectOf as c, declaredClaimOf as ct, SHAPE_KINDS as d, leaveOneSeedOut as dt, FamilyBy as et, SHAPE_KIND_IDS as f, splitFileName as ft, ShapeKind as g, Rect as gt, ShapeGeometry as h, Point as ht, JointMeasureId as i, SplitFold as it, Item as j, shapeSupportProblems as k, DEFAULT_SHAPES as l, declaredCounts as lt, ShapeCheck as m, Margin as mt, JOINT_MEASURES as n, SPLIT_SCHEMA as nt, Verdict as o, checkSplit as ot, ShapeBound as p, splitFolds as pt, toPackInput as q, JOINT_MOVED_MIN as r, SplitCorpus as rt, compareMeasure as s, corpusHashOf as st, Direction as t, FamilyCell as tt, RuleLevel as u, familyOf as ut, ShapeLevel as v, SIDES as vt, ruleLevel as w, overlapOf as wt, checkShapes as x, boundsOf as xt, ShapeSupport as y, Side as yt, PackInput as z };
586
+ //# sourceMappingURL=measures-BLoTbQwB.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"measures-CQAuu3T5.d.ts","names":[],"sources":["../src/geometry.ts","../src/corpus.ts","../src/input.ts","../src/shapes.ts","../src/measures.ts"],"mappings":";KACY;;cAGC,gBAAgB;UAEZ;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;;;UAIM;WACN;WACA;WACA;WACA;;;;;;KAOC;WACG;WAAuB;WAAoB;WAAoB;WAAoB;;WAEnF;WACA;WACA;;WAEA;WAAyB;W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AkB;;KC5NpH;;;;;;UAOK,YAAY;WAClB,IAAI;WACJ;WACA,WAAW;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;;;;WAKA;aAAgC;;;WAEhC;;WAEA,kBAAkB;;;;;WAKlB,QAAQ;;;KAIP;;;;;cAoBC,yBAAyB,YAAY;;cAarC;;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-CQAuu3T5.js";
1
+ import { a as MeasureSpec } from "./measures-BLoTbQwB.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.3.0",
4
+ "version": "0.3.1",
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",
@@ -55,6 +55,9 @@
55
55
  "vitest": "^5.0.3",
56
56
  "tsdown": "^0.23.1"
57
57
  },
58
+ "dependencies": {
59
+ "@mark1russell7/rigor-generators": "^0.1.0"
60
+ },
58
61
  "scripts": {
59
62
  "build": "tsdown",
60
63
  "test": "vitest run",
package/src/input.ts CHANGED
@@ -182,6 +182,16 @@ export interface LayoutInput {
182
182
  readonly invalidated?: readonly string[];
183
183
  }
184
184
 
185
+ /**
186
+ * A link between two items of a packer input. A graph order of the packer reads the links.
187
+ * `a` and `b` are indexes into `PackInput.items`. The weight is 1 when it has no value.
188
+ */
189
+ export interface PackLink {
190
+ readonly a: number;
191
+ readonly b: number;
192
+ readonly weight?: number;
193
+ }
194
+
185
195
  /** The input of a packer: a `layout-input/1` file without the edges. */
186
196
  export interface PackInput {
187
197
  readonly container: LayoutContainer;
@@ -189,19 +199,57 @@ export interface PackInput {
189
199
  readonly obstacles?: readonly Obstacle[];
190
200
  readonly gap?: number;
191
201
  readonly pairGaps?: readonly PairGap[];
202
+ /** The links between the items. An input without `links` has no graph, and the links have no effect on an order that does not read them. */
203
+ readonly links?: readonly PackLink[];
192
204
  }
193
205
 
194
- /** This function gives the packer input of a file. An input without a container gets `{ fixed: "none" }`, so the packer picks the size. */
195
- export function toPackInput(input: LayoutInput): PackInput {
206
+ /** The options of `toPackInput`. */
207
+ export interface PackInputOptions {
208
+ /** With `true`, the packer input gets the links of `packLinks`. The default is `false`, so the input has no `links`. */
209
+ readonly links?: boolean;
210
+ }
211
+
212
+ /**
213
+ * This function gives the packer input of a file. An input without a container gets `{ fixed: "none" }`, so the packer picks the size.
214
+ * The edges are not in the packer input. With the option `links`, their links are in it.
215
+ */
216
+ export function toPackInput(input: LayoutInput, options: PackInputOptions = {}): PackInput {
196
217
  return {
197
218
  container: input.container ?? { fixed: "none" },
198
219
  items: input.boxes,
199
220
  ...(input.obstacles === undefined ? {} : { obstacles: input.obstacles }),
200
221
  ...(input.gap === undefined ? {} : { gap: input.gap }),
201
222
  ...(input.pairGaps === undefined ? {} : { pairGaps: input.pairGaps }),
223
+ ...(options.links === true ? { links: packLinks(input) } : {}),
202
224
  };
203
225
  }
204
226
 
227
+ /**
228
+ * This function gives the links of the edges of a file, with indexes into `input.boxes`.
229
+ * - Each link has `a` below `b`. The list is sorted by `a` and then by `b`.
230
+ * - The edges of one pair of boxes make one link. Its weight is the count of the edges, and a link of one edge has no weight.
231
+ * - The function does not use an edge to a box that is not in `input.boxes`, or an edge from a box to the same box.
232
+ */
233
+ export function packLinks(input: LayoutInput): PackLink[] {
234
+ const index = new Map<string, number>();
235
+ input.boxes.forEach((box, i) => {
236
+ if (!index.has(box.id)) index.set(box.id, i);
237
+ });
238
+ const count = new Map<string, { a: number; b: number; n: number }>();
239
+ for (const edge of input.edges ?? []) {
240
+ const s = index.get(edge.source);
241
+ const t = index.get(edge.target);
242
+ if (s === undefined || t === undefined || s === t) continue;
243
+ const a = Math.min(s, t);
244
+ const b = Math.max(s, t);
245
+ const key = `${a} ${b}`;
246
+ const c = count.get(key);
247
+ if (c === undefined) count.set(key, { a, b, n: 1 });
248
+ else c.n += 1;
249
+ }
250
+ return [...count.values()].sort((x, y) => x.a - y.a || x.b - y.b).map(({ a, b, n }) => (n === 1 ? { a, b } : { a, b, weight: n }));
251
+ }
252
+
205
253
  /** This function compares two strings by their UTF-16 code units, as `Array.prototype.sort` does without a compare function. */
206
254
  const byCode = (x: string, y: string): number => (x < y ? -1 : x > y ? 1 : 0);
207
255
 
package/src/random.ts CHANGED
@@ -1,17 +1,18 @@
1
+ import { mulberry32 as homeMulberry32 } from "@mark1russell7/rigor-generators";
1
2
  import { utf8 } from "./utf8.ts";
2
3
 
3
- /** This function gives a generator of random numbers in [0, 1). It is `mulberry32`, as in `docs/FORMAT.md` of `packing`. */
4
+ /**
5
+ * This function gives a generator of random numbers in [0, 1). It is `mulberry32`, as in `docs/FORMAT.md` of `packing`.
6
+ * Its home is `@mark1russell7/rigor-generators`. This function keeps the name and the signature of the API.
7
+ */
4
8
  export function mulberry32(seed: number): () => number {
5
- let s = seed >>> 0;
6
- return () => {
7
- s = (s + 0x6d2b79f5) | 0;
8
- let t = Math.imul(s ^ (s >>> 15), 1 | s);
9
- t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
10
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
11
- };
9
+ return homeMulberry32(seed);
12
10
  }
13
11
 
14
- /** This function gives the FNV-1a hash of 32 bits of the UTF-8 bytes of a string. */
12
+ /**
13
+ * This function gives the FNV-1a hash of 32 bits of the UTF-8 bytes of a string.
14
+ * It stays here because `fnv1a32` of `@mark1russell7/rigor-generators` encodes a lone surrogate as U+FFFD. This function encodes the 3 bytes of its code.
15
+ */
15
16
  export function fnv1a32(text: string): number {
16
17
  let h = 0x811c9dc5;
17
18
  for (const b of utf8(text)) h = Math.imul(h ^ b, 0x01000193) >>> 0;
package/src/utf8.ts CHANGED
@@ -43,7 +43,7 @@ export function utf8Write(text: string, out?: Uint8Array, at = 0): number {
43
43
  return n;
44
44
  }
45
45
 
46
- /** This function gives the UTF-8 bytes of a string. The package has no runtime dependencies, thus it does not use `TextEncoder`. */
46
+ /** This function gives the UTF-8 bytes of a string. It does not use `TextEncoder`, because `TextEncoder` encodes a lone surrogate as U+FFFD. */
47
47
  export function utf8(text: string): Uint8Array {
48
48
  const bytes = new Uint8Array(utf8Write(text));
49
49
  utf8Write(text, bytes);