@mark1russell7/layout-contract 0.9.2 → 0.9.4

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.
@@ -27,6 +27,17 @@ interface SizedRect {
27
27
  declare function toRect(rect: SizedRect): Rect;
28
28
  /** This function gives the `SizedRect` of a `Rect`. It copies each number, and it does not round. */
29
29
  declare function toSizedRect(rect: Rect): SizedRect;
30
+ /**
31
+ * This function gives a rectangle on whole pixels. It rounds each edge with `Math.round`, not the size. Thus two
32
+ * rectangles that touch still touch after the rounding, and no gap or overlap of one pixel comes between them.
33
+ */
34
+ declare function snapRect(rect: Rect): Rect;
35
+ /**
36
+ * This function gives a rectangle with each coordinate and each size times `factor`. It changes the unit of a
37
+ * rectangle, for example from the CSS pixels of a zoomed page to the pixels of its window. It does not round:
38
+ * `snapRect` comes after it. A factor that is negative or not finite gives a `RangeError`.
39
+ */
40
+ declare function scaleRect(rect: Rect, factor: number): Rect;
30
41
  /** A value for each side of a box. */
31
42
  interface Sides {
32
43
  readonly top: number;
@@ -646,5 +657,5 @@ declare function minEffectOf(spec: Pick<MeasureSpec, "minEffect">, a?: number, b
646
657
  * Two equal values are a tie, also two infinite values. A value `NaN` is an error.
647
658
  */
648
659
  declare function compareMeasure(candidate: number, baseline: number, spec: Pick<MeasureSpec, "direction" | "minEffect">): Verdict;
649
- export { CorpusSplit as $, shapeKindsOf as A, overlapOf as At, LayoutInput as B, checkShapes as C, Sides as Ct, ruleLevel as D, dropIndex as Dt, itemShapeOf as E, crossingPoint as Et, LayoutBox as F, toSizedRect as Ft, PairGap as G, PackInput as H, LayoutCell as I, translate as It, packLinks as J, Port as K, LayoutContainer as L, shapeSupportProblems as M, regionArea as Mt, shapesOf as N, segmentsCross as Nt, shapeKindOf as O, grow as Ot, Item as P, toRect as Pt, CorpusEntry as Q, LayoutEdge as R, boxArea as S, Side as St, isShapeKind as T, boundsOf as Tt, PackInputOptions as U, Obstacle as V, PackLink as W, toPackInput as X, portPoint as Y, ClaimBreak as Z, ShapeKind as _, Margin as _t, MeasureSpec as a, SPLIT_SCHEMA as at, ShapeLimit as b, Region as bt, minEffectOf as c, checkDeclared as ct, SHAPE_KINDS as d, declaredClaimOf as dt, DeclaredClaim as et, SHAPE_KIND_IDS as f, declaredCounts as ft, ShapeInput as g, splitFolds as gt, ShapeGeometry as h, splitFileName as ht, JointMeasureId as i, FamilyCell as it, shapeLevel as j, pointSegmentDistance as jt, shapeKindProblem as k, marginSides as kt, DEFAULT_SHAPES as l, checkSplit as lt, ShapeCheck as m, leaveOneSeedOut as mt, JOINT_MEASURES as n, FAMILY_ANY_KIND as nt, Verdict as o, SplitCorpus as ot, ShapeBound as p, familyOf as pt, canonicalInput as q, JOINT_MOVED_MIN as r, FamilyBy as rt, compareMeasure as s, SplitFold as st, Direction as t, Declares as tt, RuleLevel as u, corpusHashOf as ut, ShapeKindSpec as v, Point as vt, inputShapeLevel as w, SizedRect as wt, ShapeSupport as x, SIDES as xt, ShapeLevel as y, Rect as yt, LayoutGenerator as z };
650
- //# sourceMappingURL=measures-DGKAulWv.d.ts.map
660
+ export { CorpusSplit as $, shapeKindsOf as A, overlapOf as At, LayoutInput as B, checkShapes as C, Sides as Ct, ruleLevel as D, dropIndex as Dt, itemShapeOf as E, crossingPoint as Et, LayoutBox as F, snapRect as Ft, PairGap as G, PackInput as H, LayoutCell as I, toRect as It, packLinks as J, Port as K, LayoutContainer as L, toSizedRect as Lt, shapeSupportProblems as M, regionArea as Mt, shapesOf as N, scaleRect as Nt, shapeKindOf as O, grow as Ot, Item as P, segmentsCross as Pt, CorpusEntry as Q, LayoutEdge as R, translate as Rt, boxArea as S, Side as St, isShapeKind as T, boundsOf as Tt, PackInputOptions as U, Obstacle as V, PackLink as W, toPackInput as X, portPoint as Y, ClaimBreak as Z, ShapeKind as _, Margin as _t, MeasureSpec as a, SPLIT_SCHEMA as at, ShapeLimit as b, Region as bt, minEffectOf as c, checkDeclared as ct, SHAPE_KINDS as d, declaredClaimOf as dt, DeclaredClaim as et, SHAPE_KIND_IDS as f, declaredCounts as ft, ShapeInput as g, splitFolds as gt, ShapeGeometry as h, splitFileName as ht, JointMeasureId as i, FamilyCell as it, shapeLevel as j, pointSegmentDistance as jt, shapeKindProblem as k, marginSides as kt, DEFAULT_SHAPES as l, checkSplit as lt, ShapeCheck as m, leaveOneSeedOut as mt, JOINT_MEASURES as n, FAMILY_ANY_KIND as nt, Verdict as o, SplitCorpus as ot, ShapeBound as p, familyOf as pt, canonicalInput as q, JOINT_MOVED_MIN as r, FamilyBy as rt, compareMeasure as s, SplitFold as st, Direction as t, Declares as tt, RuleLevel as u, corpusHashOf as ut, ShapeKindSpec as v, Point as vt, inputShapeLevel as w, SizedRect as wt, ShapeSupport as x, SIDES as xt, ShapeLevel as y, Rect as yt, LayoutGenerator as z };
661
+ //# sourceMappingURL=measures-B_n_KDMd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measures-B_n_KDMd.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;;;;;;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;WACA;;WAEA;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,QA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,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-DGKAulWv.js";
1
+ import { a as MeasureSpec } from "./measures-B_n_KDMd.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.2",
4
+ "version": "0.9.4",
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",
package/src/geometry.ts CHANGED
@@ -38,6 +38,29 @@ export function toSizedRect(rect: Rect): SizedRect {
38
38
  return { x: rect.x, y: rect.y, width: rect.w, height: rect.h };
39
39
  }
40
40
 
41
+ /** This function rounds a number to a whole number with `Math.round`. It gives 0, not -0, for a small negative number. */
42
+ const roundEdge = (value: number): number => Math.round(value) + 0;
43
+
44
+ /**
45
+ * This function gives a rectangle on whole pixels. It rounds each edge with `Math.round`, not the size. Thus two
46
+ * rectangles that touch still touch after the rounding, and no gap or overlap of one pixel comes between them.
47
+ */
48
+ export function snapRect(rect: Rect): Rect {
49
+ const x = roundEdge(rect.x);
50
+ const y = roundEdge(rect.y);
51
+ return { x, y, w: roundEdge(rect.x + rect.w) - x, h: roundEdge(rect.y + rect.h) - y };
52
+ }
53
+
54
+ /**
55
+ * This function gives a rectangle with each coordinate and each size times `factor`. It changes the unit of a
56
+ * rectangle, for example from the CSS pixels of a zoomed page to the pixels of its window. It does not round:
57
+ * `snapRect` comes after it. A factor that is negative or not finite gives a `RangeError`.
58
+ */
59
+ export function scaleRect(rect: Rect, factor: number): Rect {
60
+ if (!Number.isFinite(factor) || factor < 0) throw new RangeError(`The factor of scaleRect must be a finite number of 0 or more, not ${factor}.`);
61
+ return { x: rect.x * factor, y: rect.y * factor, w: rect.w * factor, h: rect.h * factor };
62
+ }
63
+
41
64
  /** A value for each side of a box. */
42
65
  export interface Sides {
43
66
  readonly top: number;
@@ -1 +0,0 @@
1
- {"version":3,"file":"measures-DGKAulWv.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;;;;;;UAOM;WACN;WACA;WACA;WACA;;;iBAIK,OAAO,MAAM,YAAY;;iBAKzB,YAAY,MAAM,OAAO;;UAK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