@btps/sdk 1.2.0-rc.3.1 → 1.2.0-rc.3.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/CHANGELOG.md CHANGED
@@ -4,6 +4,194 @@ All notable changes to `@btps/sdk` and the BTPS protocol it implements. The
4
4
  format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
5
5
  versions follow [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [1.2.0-rc.3.2] — 2026-11-22 (beta, release candidate)
8
+
9
+ BoundView, as proved in a platform before release: the snapshot binds and draws
10
+ a design as the page shows it, a drawn signature follows one rule that a page
11
+ and the engine draw alike, an image under a fact is read by its pixels, and the
12
+ key facts are the ones agreed. A receiver's BoundView checks change with it
13
+ (key facts, images, up to 8 fonts); everything else is as in rc.3.1 below.
14
+
15
+ ### Added
16
+
17
+ - `@btps/boundview`: one rule for a drawn signature, in the new
18
+ `@btps/boundview/signature` entry (no engine, safe in any page) and the
19
+ package root: `SIGNATURE_STROKE` (8), `signatureDrawing(strokes)`, the
20
+ shapes with every attribute as the drawing writes it, and
21
+ `signatureSvg(strokes, colour?)`, a whole `<svg viewBox="0 0 1000 300">`.
22
+ The engine draws a `signature` element by the same function, so a page that
23
+ shows a signature this way and the receiver's picture cannot differ.
24
+
25
+ ### Changed
26
+
27
+ - A BoundView carries up to 8 fonts (`BTPS_FIELD_LIMITS.boundView.fonts`),
28
+ where it carried 4. Each weight, and each style with tabular figures, is a
29
+ font of its own, so a design that sets one family in several weights, with
30
+ and without tabular figures, needs more than 4.
31
+ - A BoundView's key facts leave out what the receiving app shows apart from
32
+ it (`issuer.name`, `recipient.name`), what follows from what is shown
33
+ (`subtotalAmount`, `discount`), and what does not change what is owed,
34
+ paid or said (an invoice's or receipt's `issuedAt`, `payment.method`,
35
+ `payment.reference`; a payslip's `employee.employeeId`, `issuedAt`,
36
+ `payRate`, `leave`, `yearToDate`; a letter's `id`). Each earning's and
37
+ deduction's description is now a key fact. 1.2.0-rc.3.1 required
38
+ `issuedAt` and `issuer.name` on every type, and `recipient.name`,
39
+ `subtotalAmount` and `discount` where a type carries them, but no
40
+ earning's or deduction's description. The Checks page lists each type's;
41
+ `keyFacts(document)` (`@btps/sdk/boundview`) gives a document's.
42
+ - A key fact counts as shown when an element bound to another field writes
43
+ it exactly the same in the same format: a receipt's total and amount paid,
44
+ or two dates on one day, share one element. 1.2.0-rc.3.1 counted only an
45
+ element bound to the fact itself.
46
+ - A binding's `range` is the code points of the value as its format writes
47
+ it, for any format, so a wrapped or split amount or date is bound in
48
+ pieces. 1.2.0-rc.3.1 refused a range with a format ("a range is for text
49
+ written as it is"). For text, a range means what it did.
50
+ - In a markdown note or body, a key fact need not show what a renderer does
51
+ not draw: the marks `#`, `*`, `_`, `` ` ``, `>`, `-` and `+`, a backslash
52
+ that escapes the next character, a link's brackets and destination, the
53
+ angle brackets of an autolink, and an ordered list's number.
54
+ `markdownHidden` (`@btps/sdk/boundview`) marks them. 1.2.0-rc.3.1 excused
55
+ only the marks, without `+`.
56
+ - An `image` element may carry `radius`, as a `rect` does; the receiver
57
+ clips the image to its rounded corners.
58
+ - "Not hidden" counts two boxes as overlapping only when they share more
59
+ than 0.005 pixels each way, half the format's 0.01 pixel precision, so
60
+ boxes that touch through the rounding of a sum do not cover each other,
61
+ and a box past the page's edge by no more than that is inside the page.
62
+ 1.2.0-rc.3.1 counted any overlap, and any reach past the edge.
63
+ - BoundView: an image under a fact is checked by its pixels for contrast,
64
+ not refused. Each pixel is blended beneath the fact as a shape's fill is,
65
+ so a faint watermark or soft background picture passes and a dark or busy
66
+ one where the fact lies fails the 3:1 contrast. A watermark or background
67
+ picture behind a fact is common in invoice designs, and contrast is what
68
+ keeps a fact readable. 1.2.0-rc.3.1 refused any image under a fact ("an
69
+ image lies under it").
70
+ - `@btps/boundview`: each bundled font also carries Latin Extended
71
+ (Vietnamese included), Greek, Cyrillic, general punctuation, currency signs
72
+ (`₹ ₩ ₪ ₺ ₽ ₱`), letterlike symbols (`№`), arrows and `− ≈ ≠ ≤ ≥ ∞`, as
73
+ far as the font has them, in a second file (`<name>-more.json`) loaded
74
+ only when a text needs one of them. `loadBundledFonts(names, characters?)`
75
+ takes the characters needed, and `bundledCharactersFor(document, view)`
76
+ names them. A typed signature's characters Caveat lacks are drawn in
77
+ Arimo. 1.2.0-rc.3.1 bundled Latin and Latin-1 only.
78
+ - `@btps/boundview`: a drawn signature's stroke of one point is drawn as a
79
+ dot as wide as the pen, and a point repeated at once counts once
80
+ (`signatureDrawing`). 1.2.0-rc.3.1 drew a stroke of one point as nothing.
81
+
82
+ ### Fixed
83
+
84
+ - `@btps/boundview`: `snapshotBoundView` draws every style whose font file it
85
+ cannot read with one shared bundled font, which carries every glyph they
86
+ draw. Each such style carried its own copy of the same bundled font, which
87
+ pushed a template past the font limit.
88
+ - `@btps/boundview`: `snapshotBoundView` binds each of a line's cells once,
89
+ at the first free place on the line, in the order the document lists its
90
+ columns. In 1.2.0-rc.3.1 a cell took every place its value was written on
91
+ its line, so on an untaxed line of one item, whose unit price and amount
92
+ are the same ("A$300.00" twice side by side), the unit price took both.
93
+ The line's amount went unbound, the BoundView failed its key-facts check,
94
+ and the sender's app sent the document without a picture.
95
+ - `@btps/boundview`: `snapshotBoundView` shares the places a value is written
96
+ between fields written alike, outside line items: a receipt's
97
+ `totalAmount` and `payment.amount`, or its `issuedAt` and `payment.paidAt`
98
+ on the same day. Each takes the first free place, and the last of them
99
+ takes every place left. In 1.2.0-rc.3.1 the first such field took every
100
+ place, so a receipt whose total equalled the amount paid could never show
101
+ `payment.amount`, and a page that wrote the date twice still could not
102
+ show `payment.paidAt`. The BoundView failed its key-facts check, and the
103
+ sender's app sent the document without a picture. A value written once
104
+ now shows every field written alike (see Changed).
105
+ - `@btps/boundview`: `snapshotBoundView` binds long text over several lines,
106
+ a letter's `body.content` or a markdown description, in order: each line
107
+ picks up where the last left off. A line is taken only when all it skips
108
+ is whitespace, or, for markdown, whitespace and what a renderer does not
109
+ draw (see Changed). A line break in the text that
110
+ the page lays out as a space ends one bound piece and starts the next, so
111
+ each piece writes exactly what it shows. In 1.2.0-rc.3.1 a line was
112
+ matched anywhere after the last, so a word another field shows first (a
113
+ letterhead's "Studio" before a letter signed "Kind regards, Studio") took
114
+ the match past the letter's text, and a soft line break drawn as a space
115
+ never matched. Either way `body.content` went unbound, the BoundView
116
+ failed its key-facts check, and the sender's app sent the document without
117
+ a picture.
118
+ - `@btps/boundview`: `snapshotBoundView` reads a page's woff2 fonts,
119
+ decompressed with Brotli, which it loads only for a woff2 file, and reads
120
+ a variable font at the page's weight and optical size. 1.2.0-rc.3.1 drew a
121
+ font offered only as woff2 with a bundled font of the same widths, and a
122
+ variable font at its default instance.
123
+ - `@btps/boundview`: `snapshotBoundView` reads every file of a family split
124
+ by `unicode-range`, and takes each character from the file the browser
125
+ drew it with: the last rule that holds it first, the next where that one
126
+ has no glyph. A character no page font has is drawn with the bundled font
127
+ of the same widths; only a bound value no font can draw fails. 1.2.0-rc.3.1
128
+ read one file of the family.
129
+ - `@btps/boundview`: `snapshotBoundView` finds a value however the page lays
130
+ it out: split across elements ("300" in an `<h1>` and "Empire" in an
131
+ `<h2>`, "INV-" and "0042" in touching spans), or wrapped over lines, an
132
+ amount wrapped at a space between its groups included. It binds the
133
+ pieces by range. Where values overlap, the longest match takes the place,
134
+ so "1,452" in "A$1,452.00" is the amount's. It also finds a line item
135
+ whose cells stand above or below its description, as a table row or a
136
+ card lays them out. A line is placed where most of its cells stand,
137
+ nearest them, so a heading repeating its description is not taken for
138
+ it, and a cell is never taken from inside another field's longer match
139
+ (a quantity "10" in "10/02/2026", an amount 1 in the invoice number "A1").
140
+ 1.2.0-rc.3.1 matched each line of text on its own and bound only long
141
+ text over several lines, so a split or wrapped value went unbound and the
142
+ BoundView failed its key-facts check.
143
+ - `@btps/boundview`: `snapshotBoundView` emits the `signature` element where
144
+ the page draws the document's visual signature: an SVG that draws, shape
145
+ for shape, what `signatureSvg` draws for its strokes, or the line that is
146
+ exactly its typed text, in the page's rarest typeface. Any other drawing
147
+ of the strokes is not taken as the signature. 1.2.0-rc.3.1 emitted none, so a letter or agreement with a
148
+ visual signature always failed its key-facts check.
149
+ - `@btps/boundview`: `snapshotBoundView` makes a text's box no wider than
150
+ the browser drew it, rounded down, so text touching what follows it is not
151
+ covered by it. 1.2.0-rc.3.1 rounded the box up from the value's measured
152
+ width, which could reach into the next element and fail "Not hidden".
153
+ - `@btps/boundview`: `snapshotBoundView` makes the page the preview's box
154
+ plus any overflow that is not clipped. 1.2.0-rc.3.1 used the box alone, so
155
+ a fact drawn in the overflow lay outside the page and failed "Not hidden".
156
+ - `@btps/boundview`: `BoundViewSnapshotError` carries `view`, the BoundView
157
+ a receiver would not show, when the snapshot made one.
158
+ - `@btps/boundview`: `renderBoundView` and the snapshot's SVG logo check
159
+ free the drawing engine's WebAssembly memory after each drawing. In
160
+ 1.2.0-rc.3.1, after some tens of thousands of drawings in one page, every
161
+ drawing failed.
162
+ - `@btps/sdk/boundview`: the BoundView schema checks an image's data with
163
+ `atob`. 1.2.0-rc.3.1 used Node's `Buffer`, so the check failed in a
164
+ browser without it.
165
+ - `@btps/boundview`: `snapshotBoundView` draws a 3D transform
166
+ (`perspective()`, `rotateX`/`rotateY`, `matrix3d`) as its 2D part, as
167
+ documented. The transform origin was placed before the 2D part was taken,
168
+ so with perspective the element was drawn small and elsewhere, and a design
169
+ could be refused for covering a fact. `rotate: y 25deg` (an axis given) is
170
+ turned about that axis, no longer read as a flat turn.
171
+ - BoundView: contrast is sampled strictly inside a fact's box, never on its
172
+ far edge, so a border or shadow that only touches a fact no longer gets it
173
+ refused.
174
+ - The sweep (`packages/boundview/sweep`) now makes payslips and agreements
175
+ too, and tests each claim of "What BoundView does not support".
176
+
177
+ ### Security
178
+
179
+ - `markdownHidden` (`@btps/sdk/boundview`), which every receiver runs on a
180
+ sender's markdown in a BoundView check, finds links and autolinks in one
181
+ pass each. Its patterns rescanned the rest of the text from each `[` or
182
+ `<`, so text made of many of them took time growing with the square of its
183
+ length. What it finds is unchanged.
184
+ - `@btps/boundview`: `signatureSvg` and `signatureShapes` take a colour only
185
+ as `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa` or `currentColor`, and throw a
186
+ `TypeError` on anything else, so a value passed in is never written into
187
+ the markup.
188
+ - BoundView: a font's glyph outlines are the sender's. A receiver checks
189
+ that every character of a bound value has a glyph and fits, not that a
190
+ glyph's shape is the character it stands for, so a dishonest sender could
191
+ draw a 1 as a 7. This is accepted and documented: the receiving app's own
192
+ view of the signed data is authoritative, and is shown alongside the
193
+ BoundView or a press away (Security model, "Glyph shapes are the sender's").
194
+
7
195
  ## [1.2.0-rc.3.1] — 2026-11-15 (beta, release candidate)
8
196
 
9
197
  Two fixes to `@btps/boundview`'s `snapshotBoundView`, found adding BoundView to
@@ -99,7 +99,7 @@ export declare const BTPS_FIELD_LIMITS: {
99
99
  readonly path: 20000;
100
100
  readonly paths: 100000;
101
101
  readonly stops: 8;
102
- readonly fonts: 4;
102
+ readonly fonts: 8;
103
103
  readonly glyphs: 256;
104
104
  readonly glyphPath: 4000;
105
105
  readonly kerning: 4096;
@@ -100,7 +100,7 @@ const BTPS_FIELD_LIMITS = {
100
100
  path: 2e4,
101
101
  paths: 1e5,
102
102
  stops: 8,
103
- fonts: 4,
103
+ fonts: 8,
104
104
  glyphs: 256,
105
105
  glyphPath: 4e3,
106
106
  kerning: 4096,
@@ -5,5 +5,5 @@
5
5
  * https://www.apache.org/licenses/LICENSE-2.0
6
6
  */
7
7
  export { BtpBoundViewSchema, isPathData, type BTPBoundView, type BTPBoundViewElement, type BTPBoundViewFont, } from './boundViewSchema.js';
8
- export { boundValue, bindingProblem, type BoundValue } from './boundViewBindings.js';
9
- export { checkBoundView, boundViewResultOf, writtenValue, CONTRAST_WORK_LIMIT, type BTPBoundViewResult, type BTPBoundViewProblem, type BTPBoundViewCheck, } from './boundViewChecks.js';
8
+ export { boundValue, bindingProblem, markdownHidden, type BoundValue } from './boundViewBindings.js';
9
+ export { checkBoundView, keyFacts, boundViewResultOf, writtenValue, CONTRAST_WORK_LIMIT, type BTPBoundViewResult, type BTPBoundViewProblem, type BTPBoundViewCheck, } from './boundViewChecks.js';
@@ -9,9 +9,10 @@ import {
9
9
  BtpBoundViewSchema,
10
10
  isPathData
11
11
  } from "./boundViewSchema.js";
12
- import { boundValue, bindingProblem } from "./boundViewBindings.js";
12
+ import { boundValue, bindingProblem, markdownHidden } from "./boundViewBindings.js";
13
13
  import {
14
14
  checkBoundView,
15
+ keyFacts,
15
16
  boundViewResultOf,
16
17
  writtenValue,
17
18
  CONTRAST_WORK_LIMIT
@@ -24,5 +25,7 @@ export {
24
25
  boundViewResultOf,
25
26
  checkBoundView,
26
27
  isPathData,
28
+ keyFacts,
29
+ markdownHidden,
27
30
  writtenValue
28
31
  };
@@ -4,6 +4,7 @@
4
4
  * Licensed under the Apache License, Version 2.0
5
5
  * https://www.apache.org/licenses/LICENSE-2.0
6
6
  */
7
+ import type { BTPBoundViewElement } from './boundViewSchema.js';
7
8
  export type BoundKind = 'text' | 'money' | 'date' | 'percent';
8
9
  /** A bound field's value: text, a date, whole basis points, or an amount in minor units of its currency. */
9
10
  export type BoundValue = {
@@ -37,4 +38,19 @@ type Bind = {
37
38
  };
38
39
  /** Why a binding cannot be drawn from `document`, or undefined when it can. */
39
40
  export declare const bindingProblem: (document: Doc, bind: Bind) => string | undefined;
41
+ type WrittenBind = Extract<BTPBoundViewElement, {
42
+ type: 'text';
43
+ }>['bind'];
44
+ /**
45
+ * A bound value as the receiver draws it, by its binding's format and range (Bindings and formats): the value written
46
+ * by its format, and of that, the code points its range names, when it has one.
47
+ */
48
+ export declare const writtenValue: (value: BoundValue, bind: WrittenBind) => string;
49
+ /**
50
+ * Which characters of markdown text a renderer may not draw as themselves (Checks: Key facts), each: 0 drawn; 1 a mark
51
+ * (`# * _ \` > - +`), which is not drawn as formatting but is as text (a hyphen); 2 never drawn: a backslash that
52
+ * escapes the next character, a link's brackets and destination, and an ordered list's number, which is drawn as the
53
+ * list's marker rather than as text.
54
+ */
55
+ export declare const markdownHidden: (text: string) => (0 | 1 | 2)[];
40
56
  export {};
@@ -5,6 +5,7 @@
5
5
  * https://www.apache.org/licenses/LICENSE-2.0
6
6
  */
7
7
 
8
+ import { CURRENCY_DECIMALS } from "../constants/currency.js";
8
9
  const ISSUER = [
9
10
  ["id", "text"],
10
11
  ["title", "text"],
@@ -104,13 +105,17 @@ const ISSUER = [
104
105
  return kind === "money" ? isRecord(value) && typeof value.amount == "number" && typeof value.currency == "string" ? { kind: "money", amount: value.amount, currency: value.currency } : void 0 : kind === "percent" ? typeof value == "number" ? { kind: "percent", basisPoints: value } : void 0 : kind === "date" ? typeof value == "string" ? { kind: "date", date: value } : void 0 : isRecord(value) && typeof value.content == "string" ? { kind: "text", text: value.content } : typeof value == "string" ? { kind: "text", text: value } : void 0;
105
106
  }
106
107
  }
107
- }, bindingProblem = (document, bind) => {
108
+ }, formatProblem = (document, bind) => {
108
109
  const value = boundValue(document, bind.field);
109
- if (value === void 0) return `binds ${bind.field}, which a BoundView may not bind or the document does not carry`;
110
+ if (value === void 0)
111
+ return `binds ${bind.field}, which a BoundView may not bind or the document does not carry`;
110
112
  const format = bind.format ?? {};
111
- if (value.kind === "money" && format.money === void 0) return "a money field is written with a money format";
112
- if (value.kind === "date" && format.date === void 0) return "a date field is written with a date format";
113
- if (value.kind === "percent" && format.percent === void 0) return "a percent is written with a percent format";
113
+ if (value.kind === "money" && format.money === void 0)
114
+ return "a money field is written with a money format";
115
+ if (value.kind === "date" && format.date === void 0)
116
+ return "a date field is written with a date format";
117
+ if (value.kind === "percent" && format.percent === void 0)
118
+ return "a percent is written with a percent format";
114
119
  if (value.kind === "text") {
115
120
  if (format.money !== void 0 || format.date !== void 0 || format.percent !== void 0)
116
121
  return "text is written as it is, or in groups";
@@ -118,11 +123,116 @@ const ISSUER = [
118
123
  const length = [...value.text.replace(/ /g, "")].length;
119
124
  if (format.groups.sizes.reduce((total, part) => total + part, 0) !== length) return "a groups format's sizes add up to the value's length";
120
125
  }
121
- if (bind.range !== void 0 && bind.range[1] > [...value.text].length)
122
- return "a range lies inside the value's characters";
123
126
  }
127
+ }, rangeProblem = (document, bind) => {
128
+ if (bind.range === void 0) return;
129
+ const value = boundValue(document, bind.field);
130
+ if (value === void 0) return;
131
+ const written = [...writtenValue(value, { ...bind, range: void 0 })];
132
+ return bind.range[1] > written.length ? "a range lies inside the value's characters as written" : void 0;
133
+ }, bindingProblem = (document, bind) => formatProblem(document, bind) ?? rangeProblem(document, bind), MONTHS = [
134
+ "January",
135
+ "February",
136
+ "March",
137
+ "April",
138
+ "May",
139
+ "June",
140
+ "July",
141
+ "August",
142
+ "September",
143
+ "October",
144
+ "November",
145
+ "December"
146
+ ], grouped = (digits, separator) => digits.replace(/\B(?=(\d{3})+(?!\d))/g, separator), writeDate = (iso, pattern) => {
147
+ const date = new Date(iso), d = String(date.getUTCDate()), dd = d.padStart(2, "0"), MM = String(date.getUTCMonth() + 1).padStart(2, "0"), month = MONTHS[date.getUTCMonth()] ?? "", yyyy = String(date.getUTCFullYear());
148
+ return {
149
+ "d MMM yyyy": `${d} ${month.slice(0, 3)} ${yyyy}`,
150
+ "d MMMM yyyy": `${d} ${month} ${yyyy}`,
151
+ "MMM d, yyyy": `${month.slice(0, 3)} ${d}, ${yyyy}`,
152
+ "MMMM d, yyyy": `${month} ${d}, ${yyyy}`,
153
+ "dd/MM/yyyy": `${dd}/${MM}/${yyyy}`,
154
+ "MM/dd/yyyy": `${MM}/${dd}/${yyyy}`,
155
+ "dd.MM.yyyy": `${dd}.${MM}.${yyyy}`,
156
+ "dd-MM-yyyy": `${dd}-${MM}-${yyyy}`,
157
+ "yyyy-MM-dd": `${yyyy}-${MM}-${dd}`
158
+ }[pattern] ?? "";
159
+ }, writtenWhole = (value, format) => {
160
+ if (value.kind === "money" && format && "money" in format) {
161
+ const { group, decimal, prefix = "", suffix = "" } = format.money, places = CURRENCY_DECIMALS[value.currency] ?? 2, digits = String(Math.abs(value.amount)).padStart(places + 1, "0"), whole = grouped(digits.slice(0, digits.length - places), group), number = places > 0 ? `${whole}${decimal}${digits.slice(-places)}` : whole;
162
+ return `${value.amount < 0 ? "-" : ""}${prefix}${number}${suffix}`;
163
+ }
164
+ if (value.kind === "date" && format && "date" in format)
165
+ return writeDate(value.date, format.date);
166
+ if (value.kind === "percent" && format && "percent" in format) {
167
+ const { decimals, decimal } = format.percent;
168
+ return `${(value.basisPoints / 100).toFixed(decimals).replace(".", decimal)}%`;
169
+ }
170
+ if (value.kind !== "text") return "";
171
+ if (format && "groups" in format) {
172
+ const characters = [...value.text.replace(/ /g, "")], parts = [];
173
+ let at = 0;
174
+ for (const size of format.groups.sizes)
175
+ parts.push(characters.slice(at, at + size).join("")), at += size;
176
+ return parts.join(format.groups.separator);
177
+ }
178
+ return value.text;
179
+ }, writtenValue = (value, bind) => {
180
+ const whole = writtenWhole(value, bind.format);
181
+ return bind.range ? [...whole].slice(bind.range[0], bind.range[1]).join("") : whole;
182
+ }, nextWhere = (text, stop) => {
183
+ const next = new Array(text.length + 1);
184
+ next[text.length] = text.length;
185
+ for (let at = text.length - 1; at >= 0; at--)
186
+ next[at] = stop(text[at]) ? at : next[at + 1];
187
+ return next;
188
+ }, links = (text) => {
189
+ const newline = nextWhere(text, (char) => char === `
190
+ `), bracket = nextWhere(text, (char) => char === "]"), paren = nextWhere(text, (char) => char === ")"), found = [];
191
+ for (let at = 0; at < text.length; at++) {
192
+ if (text[at] !== "[") continue;
193
+ const close = bracket[at + 1];
194
+ if (close >= text.length || newline[at + 1] < close || text[close + 1] !== "(")
195
+ continue;
196
+ const end = paren[close + 2];
197
+ end >= text.length || newline[close + 2] < end || (found.push([at, close, end + 1]), at = end);
198
+ }
199
+ return found;
200
+ }, autolinks = (text) => {
201
+ const stop = nextWhere(text, (char) => char === ">" || char.trim() === ""), found = [];
202
+ for (let at = 0; at < text.length; at++) {
203
+ if (text[at] !== "<") continue;
204
+ const scheme = text.startsWith("https:", at + 1) ? 6 : text.startsWith("http:", at + 1) ? 5 : 0, slash = 47;
205
+ if (scheme === 0 || text.charCodeAt(at + 1 + scheme) !== slash || text.charCodeAt(at + 2 + scheme) !== slash)
206
+ continue;
207
+ const from = at + 3 + scheme, end = stop[from];
208
+ end === from || text[end] !== ">" || (found.push([at, end + 1]), at = end);
209
+ }
210
+ return found;
211
+ }, markdownHidden = (text) => {
212
+ const characters = [...text], hidden = characters.map((char) => /[#*_`>+-]/.test(char) ? 1 : 0), mark = (from, to) => {
213
+ for (let at = from; at < to; at++) hidden[at] = 2;
214
+ };
215
+ characters.forEach((char, at) => {
216
+ char === "\\" && /[\p{P}\p{S}]/u.test(characters[at + 1] ?? "") && (hidden[at] = 2);
217
+ });
218
+ const joined = characters.join(""), index = [];
219
+ characters.forEach((char, at) => {
220
+ for (let unit = 0; unit < char.length; unit++) index.push(at);
221
+ }), index.push(characters.length);
222
+ const cp = (unit) => index[unit] ?? characters.length;
223
+ for (const [start, labelEnd, end] of links(joined))
224
+ mark(cp(start), cp(start + 1)), mark(cp(labelEnd), cp(end));
225
+ for (const [start, end] of autolinks(joined))
226
+ mark(cp(start), cp(start + 1)), mark(cp(end - 1), cp(end));
227
+ for (const match of joined.matchAll(/^([ \t]*)(\d{1,9}[.)])(?=[ \t])/gm)) {
228
+ const start = (match.index ?? 0) + (match[1] ?? "").length;
229
+ mark(cp(start), cp(start + (match[2] ?? "").length));
230
+ }
231
+ return hidden;
124
232
  };
125
233
  export {
126
234
  bindingProblem,
127
- boundValue
235
+ boundValue,
236
+ markdownHidden,
237
+ writtenValue
128
238
  };
@@ -4,12 +4,10 @@
4
4
  * Licensed under the Apache License, Version 2.0
5
5
  * https://www.apache.org/licenses/LICENSE-2.0
6
6
  */
7
- import { type BTPBoundView, type BTPBoundViewElement } from './boundViewSchema.js';
8
- import { type BoundValue } from './boundViewBindings.js';
7
+ import { type BTPBoundView } from './boundViewSchema.js';
8
+ import { writtenValue } from './boundViewBindings.js';
9
+ export { writtenValue };
9
10
  type Doc = Record<string, unknown>;
10
- type TextElement = Extract<BTPBoundViewElement, {
11
- type: 'text';
12
- }>;
13
11
  export type BTPBoundViewCheck = 'wellFormed' | 'keyFacts' | 'shownInFull' | 'notHidden';
14
12
  export type BTPBoundViewProblem = {
15
13
  check: BTPBoundViewCheck;
@@ -26,14 +24,14 @@ export type BTPBoundViewResult = {
26
24
  show: false;
27
25
  problems: BTPBoundViewProblem[];
28
26
  };
29
- /** A bound value as the receiver draws it, by its binding's format and range (Bindings and formats). */
30
- export declare const writtenValue: (value: BoundValue, bind: TextElement["bind"]) => string;
31
27
  /**
32
28
  * The most edge and point tests the contrast check makes on one BoundView. A
33
29
  * BoundView that would need more fails the check: a receiver is never made to
34
30
  * work without end on a crafted one.
35
31
  */
36
32
  export declare const CONTRAST_WORK_LIMIT = 20000000;
33
+ /** The key facts a document's BoundView shows, by field, among those it carries (Checks: Key facts). */
34
+ export declare const keyFacts: (document: Doc) => string[];
37
35
  /**
38
36
  * The checks on a well-formed BoundView, against the signed document it
39
37
  * belongs to: every key fact shown, every bound value shown in full, and
@@ -46,4 +44,3 @@ export declare const checkBoundView: (document: Doc, view: BTPBoundView) => BTPB
46
44
  * one that was not, and whose BoundView is not well formed, is never shown.
47
45
  */
48
46
  export declare const boundViewResultOf: (document: unknown) => BTPBoundViewResult | undefined;
49
- export {};