@333eco/brand 1.9.0 → 1.11.0

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 CHANGED
@@ -139,8 +139,19 @@ an H3QR names whom you thank, and a B-QR is how that code is drawn.
139
139
  marker stands at the heart's point and its three markers mirror about the heart's own line (`bqrTurned`; always, no option). It
140
140
  shipped by the founder's override of a failed scan gate, kept on the record in `scripts/bqr.test.mjs` §turn. A small ™ stands in the
141
141
  bottom lobe: it names the **B-Emblem™**, never *B-QR* (unmarked), and shows which way is up. `lobe: "none"` or `autograph` (a person's own
142
- strokes, *Open* only, ⛔ throws in *Full*) are for a person's own picture. The other three positions mean nothing yet, so ⛔ nothing is
143
- drawn in one, and the top lobe keeps its dots. Codes printed before keep working.
142
+ strokes, *Open* only, ⛔ throws in *Full*) are for a person's own picture. Codes printed before keep working. ⚠️ Superseded by v1.11.0: *always turned* (only a B-Link
143
+ is) and *the top lobe keeps its dots* (in our own codes).
144
+ - **Centered, and a coded top lobe (v1.10.0, founder 2026-11-24).** The ™, and an autograph in its place, stand at the bottom lobe's center, each
145
+ version's own (`BQR_LOBE_CENTER`, solved from the silhouette by the test). An autograph is FITTED to its box: its own shape kept, wherever on
146
+ the pad it was drawn. `coded` puts 96 bits in the TOP lobe (Open only, ⛔ throws in Full): for a mark in a person's picture, where its caller
147
+ writes a short fingerprint of that picture, so a heart pasted on another is caught with no network. ⛔ Never a person, a serial, a claim or a
148
+ key; nothing about it is secret. Our own codes keep their dots.
149
+ - **Four positions, read from the address (v1.11.0, founder 2026-11-24: *"keep all four positions"*).** The middle marker stands at the POINT for a B-Link,
150
+ STANDARD for any other address of the estate, and at the NOTCH or NON-STANDARD for the same two drawn by an outsider through our API
151
+ (`by: "outside"`, which only the API passes). `bqrPosition` reads the address; a caller never chooses. ⛔ Any other address THROWS: our heart never
152
+ frames an address someone chose. ⛔ A position is a declaration, never a proof: nothing public may say one shows who drew it.
153
+ - **B-Watermark℠ (v1.11.0)** = the invisible mark, the B-QR, its position, B-Autograph℠ and B-Fingerprint℠, in a person's own picture: `/watermark/`. The
154
+ fingerprint is `qr/fingerprint.ts`, open and self-contained (`npm run fingerprint:test`).
144
155
  - **The card's words are PLACED, never aligned (v1.6.1).** `paintQrCard` measures each line, shrinks its size until it fits,
145
156
  and draws it from the left at the center minus half its width. Safari on iOS 26 ignores `textAlign = "center"` and the
146
157
  `maxWidth` argument for a complex script: a Khmer caption printed starting at the center line. Measured on the Simulator
package/brand.lock CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.9.0",
2
+ "version": "1.11.0",
3
3
  "files": {
4
4
  "css/metta.css": "9bfe986c46c303bf9a48be85322d68e3d626571a424ef3a8aa81faaf5c866692",
5
5
  "css/motion.css": "9bfbe39c0de6a9dfaf9fdc2c61e327b3c8e70221c34dff9befd85da448b9e0c2",
@@ -11,6 +11,7 @@
11
11
  "emblem/emblem.svg": "368f520ad2d2f9db50d83ca9cd7aee9475948dc8e38c61b7afa13f7717fef903",
12
12
  "emblem/emblem.ts": "6e150389eed576c392ff6231c0b38b8fea5d4c11f7a5b21936bb25afab069890",
13
13
  "qr/bqr-card.ts": "55b4cf3d742bb758f789fd18f91737e8da1169610b6b953ad71e95d8bb713168",
14
- "qr/bqr.ts": "82ae72c931f3e5453038625c2a37a4ff1928bcf5274891de3c68d53c0d477512"
14
+ "qr/bqr.ts": "fd55381f7298d3b79dcfbec01fbb5b6db117ddaffad48872f59f01bb15a3f6df",
15
+ "qr/fingerprint.ts": "4a587cdb3b5ff6026262f995889c329466a2513044a68c0b5d2fa31c2bdd45a3"
15
16
  }
16
17
  }
package/data/bodies.json CHANGED
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "bodies": [
20
20
  { "body": "H3", "name": "HeartBank®", "color": "rainbow — each code in its domain's hue", "owners": ["heartbank.us", "heartbank.me", "heartbank.org", "heartbank.ceo", "heartbank.net", "heartbank.com"], "why": "a rainbow is sunlight through water; H3 is the Water body" },
21
- { "body": "SW", "name": "Silicon Wat℠", "color": "orange robe", "owners": ["SW"], "prints": "deep ochre", "why": "the robe's kāsāya; SW is the Fire body" },
21
+ { "body": "SW", "name": "Silicon Wat ℠", "color": "orange robe", "owners": ["SW"], "prints": "deep ochre", "why": "the robe's kāsāya; SW is the Fire body" },
22
22
  { "body": "TH", "name": "THonly™", "color": "sky blue", "owners": ["TH"], "why": "Mind is the Air body; the sky" },
23
23
  { "body": "F333", "name": "Factory 333™", "color": "crimson moon", "owners": ["F333"], "why": "the workshop on the far side of the Moon; a red moon is lit by Earth's sunrises and sunsets, and F333 is the Earth body" },
24
24
  { "body": "MA", "name": "Miss Aquarius℠", "color": "clear sparkle", "owners": ["MA"], "prints": "graphite", "motion": "on screen the glint moves only when the viewer moves (tilt, pointer, scroll) — never by itself; still under reduced motion and in print", "why": "space holds the four colors and has none of its own; the light that crosses it sparkles" }
package/data/brand.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "into brand.lock, which is vendored byte-identical into every consumer,",
9
9
  "so 'which sites are on which brand version' is answerable by grep."
10
10
  ],
11
- "version": "1.9.0",
11
+ "version": "1.11.0",
12
12
  "wordmark": {
13
13
  "$comment": [
14
14
  "The composition has an internal short-name as of 2026-09-20: B-Wordmark",
package/dist/Brand.kt CHANGED
@@ -18,7 +18,7 @@ import androidx.compose.ui.graphics.lerp
18
18
  import androidx.compose.ui.unit.dp
19
19
 
20
20
  object Brand {
21
- const val VERSION = "1.9.0"
21
+ const val VERSION = "1.11.0"
22
22
 
23
23
  /** The B-Gem media-type palette. A colour here MEANS a medium.
24
24
  * Not a site palette, and not the six-TLD rainbow. */
package/dist/Brand.swift CHANGED
@@ -14,7 +14,7 @@
14
14
  import SwiftUI
15
15
 
16
16
  public enum Brand {
17
- public static let version = "1.9.0"
17
+ public static let version = "1.11.0"
18
18
 
19
19
  /// The B-Gem media-type palette. A colour here MEANS a medium.
20
20
  /// ⚠️ Not a site palette, and not the six-TLD rainbow. Using a gem as an
package/dist/tokens.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$comment": "GENERATED by scripts/generate.mjs. Do not edit. Values are parsed from css/tokens.css, which is canonical; semantics come from data/. Run `node scripts/generate.mjs --check` to prove this file is current.",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "gems": [
5
5
  {
6
6
  "name": "ruby",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@333eco/brand",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "The canonical brand layer for the institution — design tokens, themes, motion, and the B-Emblem. A READ-ONLY MIRROR; institution repos vendor this layer, they do not install it.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Thon Ly",
@@ -45,7 +45,8 @@
45
45
  "check": "node scripts/check-brand.mjs",
46
46
  "check:publish": "node scripts/check-publish.mjs",
47
47
  "generate": "node scripts/generate.mjs",
48
- "bqr:test": "node scripts/bqr.test.mjs"
48
+ "bqr:test": "node scripts/bqr.test.mjs",
49
+ "fingerprint:test": "node scripts/fingerprint.test.mjs"
49
50
  },
50
51
  "publishConfig": {
51
52
  "access": "public"
package/qr/bqr.ts CHANGED
@@ -35,9 +35,9 @@
35
35
  * chosen by a rule written into the test BEFORE its sweep ran: the LIGHTEST candidate that prints at ISO/IEC 15415
36
36
  * symbol-contrast grade A (Rpaper 0.85 − Rink ≥ 0.70) and decodes no worse than the old near-black by more than 2 of 90 cases on two
37
37
  * independent decoders. The prediction (#106430) was wrong and the rule's pick was kept — ⛔ never move the rule to a preferred shade.
38
- * ⭐ ONE MIRROR LINE (v1.9.0, founder 2026-11-23): the code is drawn turned a quarter counterclockwise (`bqrTurned`), so its middle
39
- * position marker stands at the heart's point and its three markers mirror about the heart's own line. Measured in §turn; nothing
40
- * printed before is reprinted (a code reads at any angle).
38
+ * ⭐ FOUR POSITIONS (v1.11.0, founder 2026-11-24): the middle position marker stands where the ADDRESS puts it (`bqrPosition`): at the heart's point
39
+ * for a B-Link, standard for any other address of the estate; the notch and non-standard are the same two from outside. At the point and
40
+ * the notch the code's mirror line is the heart's (v1.9.0, §turn). Nothing printed before is reprinted (a code reads at any angle).
41
41
  * ⭐ DETERMINISTIC: the decoration is seeded from a hash of the text, so the same address always draws the same picture and the preview
42
42
  * a person sees is the card they download.
43
43
  *
@@ -65,13 +65,19 @@ export const BQR_FILL_RING = 1;
65
65
  */
66
66
  export type BqrLobe = "tm" | "none";
67
67
  export const BQR_LOBE_DEFAULT: BqrLobe = "tm";
68
- /** The ™: its centre, its cap height, and the quiet space around it, in viewBox units. Drawn as bars, so it needs no font. */
69
- export const BQR_TM = { cx: 18.25, cy: 14.12, h: 1.05, pad: 0.5 } as const;
68
+ /**
69
+ * ⭐ v1.10.0 (founder 2026-11-24: *"horizontally and vertically center the ™ and the [autograph] within the bottom lobe"*) — the lobe's CENTER,
70
+ * each version's own: midway between the code's last column and the outline's inner edge on its row, and midway between the outline's
71
+ * inner edges on its column. Solved from the silhouette; `scripts/bqr.test.mjs` §center solves it again and holds these.
72
+ */
73
+ export const BQR_LOBE_CENTER = { pixels: { x: 17.86, y: 14.15 }, outline: { x: 17.62, y: 14.16 } } as const;
74
+ /** The ™: its cap height and the quiet space around it, in viewBox units. Drawn as bars, so it needs no font. */
75
+ export const BQR_TM = { h: 1.05, pad: 0.5 } as const;
70
76
  const TM = { t: 0.2, w: 0.84, gap: 0.13, m: 1.06 } as const; // stroke · T's width · the gap · M's width, as parts of the cap height
71
- export const bqrTmBox = () => { const w = BQR_TM.h * (TM.w + TM.gap + TM.m); return { x: BQR_TM.cx - w / 2, y: BQR_TM.cy - BQR_TM.h / 2, w, h: BQR_TM.h }; };
72
- /** The autograph's box in the bottom lobe, 5 : 3. ⭐ Not the largest that fits (5.2 × 3.12 at 15.65): that one stood so near the code that one
73
- * decoder lost 10 of 1,080 cards; this one, set further out, loses none (measured 2026-11-24, `scripts/bqr.test.mjs` §tm S5). */
74
- export const BQR_AUTOGRAPH = { x: 16.38, y: 12.86, w: 4.47, h: 2.68 } as const;
77
+ export const bqrTmBox = (style: keyof typeof BQR_LOBE_CENTER = "pixels") => { const w = BQR_TM.h * (TM.w + TM.gap + TM.m), c = BQR_LOBE_CENTER[style]; return { x: c.x - w / 2, y: c.y - BQR_TM.h / 2, w, h: BQR_TM.h }; };
78
+ /** The autograph's box, 5 : 3, centered in the Open version's bottom lobe. Its width is the largest that loses no reading (§center C3). */
79
+ const AUTOGRAPH_W = 4.27;
80
+ export const BQR_AUTOGRAPH = { x: BQR_LOBE_CENTER.outline.x - AUTOGRAPH_W / 2, y: BQR_LOBE_CENTER.outline.y - AUTOGRAPH_W * 0.3, w: AUTOGRAPH_W, h: AUTOGRAPH_W * 0.6 } as const;
75
81
  /** A person's B-Autograph℠, as points on a 100 × 60 pad: numbers only, ⛔ never a path's text (nothing here is ever parsed or injected). */
76
82
  export interface BqrAutograph { strokes: readonly (readonly (readonly [number, number])[])[] }
77
83
  export const BQR_PAD_W = 100, BQR_PAD_H = 60, BQR_AUTOGRAPH_PEN = 3, BQR_AUTOGRAPH_POINTS = 4000;
@@ -246,10 +252,14 @@ export interface BqrOptions {
246
252
  lobe?: BqrLobe;
247
253
  /** ⭐ v1.9.0 — a person's autograph in the bottom lobe, in the `outline` version only (⛔ throws in `pixels`); it replaces the ™. */
248
254
  autograph?: BqrAutograph;
249
- /** ⛔ TEST ONLY — `false` lets an autograph leave its box, for the check that must see it. */
250
- clipAutograph?: boolean;
251
- /** ⛔ TEST ONLY — `false` draws the code upright, the drawing before v1.9.0 (`scripts/bqr.test.mjs` §turn, the baseline). */
252
- turn?: boolean;
255
+ /** ⛔ TEST ONLY — `false` draws an autograph where it was drawn on the pad, not fitted and centered, for the checks that must see it. */
256
+ fitAutograph?: boolean;
257
+ /** ⭐ v1.10.0 — 96 bits in the TOP lobe, for a mark in a person's picture, in the `outline` version only (⛔ throws in `pixels`). */
258
+ coded?: readonly number[];
259
+ /** ⭐ v1.11.0 — who draws it. ⛔ Only our API passes "outside"; an app never says where the middle marker stands (the address does). */
260
+ by?: BqrBy;
261
+ /** ⛔ TEST ONLY — the position, whatever the address says. */
262
+ position?: BqrPosition;
253
263
  /** ⭐ v1.6.0 — the drawing's color family, drawn at `BQR_INK`'s darkness (`bqrInkFor`). Default: `BQR_INK` itself.
254
264
  * ⛔ Products pass `owner`, never `hue`; `hue` is for the brand page following a visitor's `--emblem`. */
255
265
  hue?: string;
@@ -338,28 +348,33 @@ function stream(seed: string): () => number {
338
348
  }
339
349
 
340
350
  /** Does a cell (its top left, its side) touch the sign's rounded quiet space? */
341
- function touchesSign(x: number, y: number, m: number): boolean {
342
- const b = bqrTmBox(), rx = b.w / 2 + BQR_TM.pad, ry = b.h / 2 + BQR_TM.pad;
343
- const nx = Math.max(x, Math.min(BQR_TM.cx, x + m)) - BQR_TM.cx, ny = Math.max(y, Math.min(BQR_TM.cy, y + m)) - BQR_TM.cy;
351
+ function touchesSign(x: number, y: number, m: number, style: BqrStyle): boolean {
352
+ const b = bqrTmBox(style), c = BQR_LOBE_CENTER[style], rx = b.w / 2 + BQR_TM.pad, ry = b.h / 2 + BQR_TM.pad;
353
+ const nx = Math.max(x, Math.min(c.x, x + m)) - c.x, ny = Math.max(y, Math.min(c.y, y + m)) - c.y;
344
354
  return (nx / rx) ** 2 + (ny / ry) ** 2 < 1;
345
355
  }
346
356
  /** The ™ as bars, in viewBox units. */
347
- function drawTm(g: CanvasRenderingContext2D): void {
348
- const b = bqrTmBox(), h = b.h, t = TM.t * h, w = TM.w * h, x1 = b.x + w + TM.gap * h, mw = TM.m * h, y = b.y;
357
+ function drawTm(g: CanvasRenderingContext2D, style: BqrStyle): void {
358
+ const b = bqrTmBox(style), h = b.h, t = TM.t * h, w = TM.w * h, x1 = b.x + w + TM.gap * h, mw = TM.m * h, y = b.y;
349
359
  g.fillRect(b.x, y, w, t); g.fillRect(b.x + w / 2 - t / 2, y, t, h);
350
360
  g.beginPath(); g.moveTo(x1, y + h); g.lineTo(x1, y); g.lineTo(x1 + t * 1.05, y); g.lineTo(x1 + mw / 2, y + h * 0.56); g.lineTo(x1 + mw - t * 1.05, y); g.lineTo(x1 + mw, y);
351
361
  g.lineTo(x1 + mw, y + h); g.lineTo(x1 + mw - t, y + h); g.lineTo(x1 + mw - t, y + h * 0.42); g.lineTo(x1 + mw / 2, y + h * 0.86); g.lineTo(x1 + t, y + h * 0.42); g.lineTo(x1 + t, y + h);
352
362
  g.closePath(); g.fill();
353
363
  }
354
364
  /** A person's autograph in its box: each stroke through the middles of its points, so a finger's corners come out round. */
355
- function drawAutograph(g: CanvasRenderingContext2D, a: BqrAutograph, ink: string, clip: boolean): void {
356
- const B = BQR_AUTOGRAPH, k = B.w / BQR_PAD_W;
365
+ /** ⭐ v1.10.0 — FITTED: the drawing keeps its own shape, grows to fill its box (at most twice the pad's own scale) and stands at the lobe's center,
366
+ * wherever on the pad it was drawn. It cannot leave its box, so it can never reach the code. */
367
+ function drawAutograph(g: CanvasRenderingContext2D, a: BqrAutograph, ink: string, fit: boolean): void {
368
+ const B = BQR_AUTOGRAPH, pad = B.w / BQR_PAD_W, pen = BQR_AUTOGRAPH_PEN * pad;
369
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
370
+ for (const s of a.strokes) for (const [x, y] of s) { x0 = Math.min(x0, x); x1 = Math.max(x1, x); y0 = Math.min(y0, y); y1 = Math.max(y1, y); }
371
+ const k = fit ? Math.min(2 * pad, (B.w - pen) / Math.max(x1 - x0, 1e-6), (B.h - pen) / Math.max(y1 - y0, 1e-6)) : pad;
357
372
  g.save();
358
- if (clip) { g.beginPath(); g.rect(B.x, B.y, B.w, B.h); g.clip(); }
359
- g.translate(B.x, B.y); g.scale(k, k);
360
- g.strokeStyle = ink; g.fillStyle = ink; g.lineWidth = BQR_AUTOGRAPH_PEN; g.lineCap = "round"; g.lineJoin = "round";
373
+ if (fit) { g.translate(B.x + B.w / 2, B.y + B.h / 2); g.scale(k, k); g.translate(-(x0 + x1) / 2, -(y0 + y1) / 2); }
374
+ else { g.translate(B.x, B.y); g.scale(k, k); }
375
+ g.strokeStyle = ink; g.fillStyle = ink; g.lineWidth = pen / k; g.lineCap = "round"; g.lineJoin = "round";
361
376
  for (const s of a.strokes) {
362
- if (s.length === 1) { g.beginPath(); g.arc(s[0][0], s[0][1], BQR_AUTOGRAPH_PEN / 2, 0, Math.PI * 2); g.fill(); continue; }
377
+ if (s.length === 1) { g.beginPath(); g.arc(s[0][0], s[0][1], pen / k / 2, 0, Math.PI * 2); g.fill(); continue; }
363
378
  g.beginPath(); g.moveTo(s[0][0], s[0][1]);
364
379
  for (let i = 1; i < s.length - 1; i++) g.quadraticCurveTo(s[i][0], s[i][1], (s[i][0] + s[i + 1][0]) / 2, (s[i][1] + s[i + 1][1]) / 2);
365
380
  g.lineTo(s[s.length - 1][0], s[s.length - 1][1]); g.stroke();
@@ -368,14 +383,44 @@ function drawAutograph(g: CanvasRenderingContext2D, a: BqrAutograph, ink: string
368
383
  }
369
384
 
370
385
  /**
371
- * ⭐ v1.9.0 (founder 2026-11-23) — the code turned a quarter COUNTERCLOCKWISE, so its middle position marker stands at the heart's point.
372
- * The emblem mirrors about one line, point to notch; a code's three markers mirror about one line too, through the middle one. Upright
373
- * the two lines cross; turned, they are the same line. Decoders read a code at any angle, so nothing printed before stops working.
386
+ * ⭐ v1.11.0 (founder 2026-11-24: *"keep all four positions"*) — WHERE THE MIDDLE MARKER STANDS SAYS WHAT KIND OF ADDRESS IT IS, read from the address
387
+ * itself: at the heart's POINT for a B-Link, STANDARD (top left) for any other address of the estate; the NOTCH and NON-STANDARD (bottom
388
+ * right) are the same two, drawn by an outsider through our API (`by: "outside"`; nothing passes it until that API exists). The point and
389
+ * the notch are the two where the code's own mirror line is the heart's (§turn), so a B-Link is the symmetric one. A camera reads any angle.
390
+ * ⛔ A declaration, never a proof: anyone can draw any position, so nothing public may say that one shows who drew it.
374
391
  */
375
- export function bqrTurned(mat: BqrMatrix): BqrMatrix {
376
- const n = mat.size, data = new Uint8Array(n * n);
377
- for (let r = 0; r < n; r++) for (let c = 0; c < n; c++) data[r * n + c] = mat.data[c * n + (n - 1 - r)] ? 1 : 0;
378
- return { size: n, data };
392
+ export type BqrPosition = "point" | "notch" | "standard" | "non-standard";
393
+ export type BqrBy = "us" | "outside";
394
+ /** Every domain a B-QR may open a page of: the estate's (b.333.eco's own list; §position K4 holds the two equal). */
395
+ export const BQR_HOSTS: readonly string[] = [
396
+ "333.eco", "heartbank.org", "heartbank.net", "heartbank.com", "heartbank.ceo", "heartbank.me", "heartbank.us",
397
+ "thonly.org", "thonly.com", "thonly.net", "siliconwat.com", "siliconwat.org", "siliconwat.dev",
398
+ "missaquarius.org", "missaquarius.com", "playsey.app", "sayyourname.app", "seysays.org",
399
+ ];
400
+ /** What a code's text is: a B-Link, another estate address, or no address at all (a bare gift code). ⛔ Throws for an address anywhere else: our
401
+ * heart never frames an address someone chose. `localhost` and the estate's Firebase preview hosts are a developer's phone. */
402
+ export function bqrKind(text: string, hosts: readonly string[] = BQR_HOSTS): "b-link" | "estate" | "text" {
403
+ if (!/^[a-z][a-z0-9+.-]*:/i.test(text.trim())) return "text";
404
+ let u: URL;
405
+ try { u = new URL(text.trim()); } catch { throw new Error("B-QR: that isn't an address."); }
406
+ if (/^(localhost|127\.0\.0\.1|192\.168\.\d+\.\d+|10\.\d+\.\d+\.\d+)$/.test(u.hostname) || /^(thank3-heartbank-com|heartbank-bc44f)(--[a-z0-9-]+)?\.(web\.app|firebaseapp\.com)$/.test(u.hostname)) return "estate";
407
+ if (u.protocol !== "https:" || u.port || u.username || u.password || !hosts.some((d) => u.hostname === d || u.hostname.endsWith("." + d))) throw new Error("B-QR: only an https address of the estate (" + u.hostname + ").");
408
+ return u.hostname === "b.333.eco" ? "b-link" : "estate";
409
+ }
410
+ export function bqrPosition(text: string, by: BqrBy = "us"): BqrPosition {
411
+ return bqrKind(text) === "b-link" ? (by === "outside" ? "notch" : "point") : by === "outside" ? "non-standard" : "standard";
412
+ }
413
+ /** Quarter turns counterclockwise from upright. */
414
+ export const BQR_TURNS: Readonly<Record<BqrPosition, 0 | 1 | 2 | 3>> = { standard: 0, point: 1, "non-standard": 2, notch: 3 };
415
+ /** The matrix turned that many quarters counterclockwise. Decoders read a code at any angle, so nothing printed before stops working. */
416
+ export function bqrTurned(mat: BqrMatrix, quarters = 1): BqrMatrix {
417
+ let m: BqrMatrix = mat;
418
+ for (let q = 0; q < quarters; q++) {
419
+ const n = m.size, data = new Uint8Array(n * n), from = m.data;
420
+ for (let r = 0; r < n; r++) for (let c = 0; c < n; c++) data[r * n + c] = from[c * n + (n - 1 - r)] ? 1 : 0;
421
+ m = { size: n, data };
422
+ }
423
+ return m;
379
424
  }
380
425
 
381
426
  /**
@@ -408,12 +453,27 @@ export function bqrLayout(mat: BqrMatrix, seed: string, o: { style?: BqrStyle; q
408
453
  if ((on(c - 1, r) && on(c - 2, r)) || (on(c, r - 1) && on(c, r - 2))) continue; // ⛔ never three in a run
409
454
  dark.add(`${c},${r}`);
410
455
  // ⭐ A whole dot or none: the sign never cuts one. It is dropped AFTER it counted for the run rule, so no other dot moves (§tm S3).
411
- if (sign && touchesSign(ox + c * m, oy + r * m, m)) continue;
456
+ if (sign && touchesSign(ox + c * m, oy + r * m, m, style)) continue;
412
457
  deco.push([c, r]);
413
458
  }
414
459
  return { n, m, ox, oy, deco, style, outline: G.outline };
415
460
  }
416
461
 
462
+ /** ⭐ v1.10.0 — the top lobe's coded cells, as [column, row] on the DRAWN (turned) code's grid, nearest the code first; bit i is in cells i and
463
+ * i + 96. A checkerboard, so no two stand side by side. ⛔ Throws when a code is too coarse for them (a mark's 12 characters never is). */
464
+ export const BQR_CODED_BITS = 96;
465
+ export function bqrLobeCells(mat: BqrMatrix, o: { style?: BqrStyle } = {}): [number, number][] {
466
+ const L = bqrLayout(mat, "", { style: o.style ?? "outline", lobe: "none" }), clear = (DOT / 2) * L.m * Math.SQRT2 + L.outline / 2 + 0.15 * L.m, out: [number, number][] = [];
467
+ const r0 = Math.floor((EMBLEM_BOX.y - L.oy) / L.m) - 1, c0 = Math.floor((EMBLEM_BOX.x - L.ox) / L.m) - 1, c1 = Math.ceil((EMBLEM_BOX.x + EMBLEM_BOX.w - L.ox) / L.m) + 1;
468
+ for (let r = -BQR_QUIET - 1; r >= r0; r--) for (let c = c0; c <= c1; c++) {
469
+ if ((c + r) & 1) continue;
470
+ const cx = L.ox + (c + 0.5) * L.m, cy = L.oy + (r + 0.5) * L.m;
471
+ if (insideEmblem(cx, cy) && edgeDistance(cx, cy) >= clear) out.push([c, r]);
472
+ }
473
+ if (out.length < 2 * BQR_CODED_BITS) throw new Error("B-QR: this code is too coarse for coded modules.");
474
+ return out.slice(0, 2 * BQR_CODED_BITS);
475
+ }
476
+
417
477
  // ---- drawing ------------------------------------------------------------------------------------------------------------------------
418
478
 
419
479
  /** Where the emblem lands in a `size` square at (x, y): canvas px = t + k · viewBox units. ⭐ Centres the PAINTED bbox, never the viewBox. */
@@ -424,8 +484,9 @@ export function bqrPlacement(size: number, x = 0, y = 0): { k: number; tx: numbe
424
484
 
425
485
  /** Paint a B-QR from a module matrix into a 2D context. Synchronous; `drawBqr` makes the matrix. */
426
486
  export function paintBqr(g: CanvasRenderingContext2D, upright: BqrMatrix, seed: string, o: BqrOptions): void {
427
- // ⭐ v1.9.0 — always turned: one drawing, whoever asks. The layout is the grid's, so the decoration and the outline do not move.
428
- const mat = o.turn === false ? upright : bqrTurned(upright);
487
+ // ⭐ v1.11.0 — turned by what the address IS (`bqrPosition`; it throws for an address outside the estate). The layout is the grid's, so the
488
+ // decoration and the outline do not move.
489
+ const where = bqrPosition(seed, o.by), mat = bqrTurned(upright, BQR_TURNS[o.position ?? where]);
429
490
  // ⭐ §4AA — one green for the whole drawing: the decoration and the outline default to the code's own ink.
430
491
  // ⭐ v1.6.0 — `hue` sets the code, the decoration and the outline at once, darkened by `bqrInkFor`; none = `BQR_INK`, verbatim.
431
492
  // ⭐ v1.7.0 — `owner` sets it from the body palette instead; ⛔ both at once throws (a product cannot pick its own color).
@@ -433,6 +494,7 @@ export function paintBqr(g: CanvasRenderingContext2D, upright: BqrMatrix, seed:
433
494
  const inkOfHue = o.owner !== undefined ? bqrOwnerInk(o.owner) : o.hue ? bqrInkFor(o.hue) : BQR_INK;
434
495
  const X = o.x ?? 0, Y = o.y ?? 0, size = o.size, accent = o.accent || inkOfHue;
435
496
  if (o.autograph !== undefined && (bqrStyleOf(o.style) !== "outline" || !isAutograph(o.autograph))) throw new Error("B-QR: an autograph is drawn in the `outline` version (the Open B-QR) only, from a person's own strokes.");
497
+ if (o.coded !== undefined && (bqrStyleOf(o.style) !== "outline" || o.coded.length !== BQR_CODED_BITS || !o.coded.every((b) => b === 0 || b === 1))) throw new Error("B-QR: coded modules are 96 bits in the `outline` version (the Open B-QR) only.");
436
498
  const lobe: BqrLobe = o.autograph ? "none" : o.lobe ?? BQR_LOBE_DEFAULT;
437
499
  const L = bqrLayout(mat, seed, { style: o.style, quiet: o.quiet, lobe });
438
500
  const { k, tx, ty } = bqrPlacement(size, X, Y);
@@ -454,9 +516,11 @@ export function paintBqr(g: CanvasRenderingContext2D, upright: BqrMatrix, seed:
454
516
  // The outline.
455
517
  // ⭐ §4Z — `outline` (Version 2) draws this wider, over a heart left white (§4AA: six times as wide).
456
518
  g.strokeStyle = accent; g.lineWidth = L.outline; g.lineJoin = "round"; g.stroke(path);
519
+ // ⭐ v1.10.0 — the top lobe's coded modules, each bit twice, dots as the decoration's own.
520
+ if (o.coded) { g.fillStyle = accent; bqrLobeCells(mat, { style: "outline" }).forEach(([c, r], i) => { if (o.coded![i % BQR_CODED_BITS]) g.fillRect(L.ox + c * L.m + inset, L.oy + r * L.m + inset, d, d); }); }
457
521
  // ⭐ v1.9.0 — the bottom lobe, in the code's own ink.
458
- if (o.autograph) drawAutograph(g, o.autograph, accent, o.clipAutograph !== false);
459
- else if (lobe === "tm") { g.fillStyle = accent; drawTm(g); }
522
+ if (o.autograph) drawAutograph(g, o.autograph, accent, o.fitAutograph !== false);
523
+ else if (lobe === "tm") { g.fillStyle = accent; drawTm(g, bqrStyleOf(o.style)); }
460
524
  g.restore();
461
525
 
462
526
  // ⭐ The code, in DEVICE pixels with every edge rounded, one rect per run — scaled sub-pixel rects leave hairline seams
@@ -484,11 +548,11 @@ export async function drawBqr(g: CanvasRenderingContext2D, text: string, o: BqrO
484
548
  }
485
549
 
486
550
  /** A B-QR as a PNG data URL — the on-screen preview of a code a person may also download, so what they see is what they print. */
487
- export async function bqrDataUrl(text: string, o: { size?: number; accent?: string; ecc?: "L" | "M" | "Q" | "H"; style?: BqrStyle; ground?: BqrGround; hue?: string; owner?: BqrOwner; lobe?: BqrLobe; autograph?: BqrAutograph } = {}): Promise<string> {
551
+ export async function bqrDataUrl(text: string, o: { size?: number; accent?: string; ecc?: "L" | "M" | "Q" | "H"; style?: BqrStyle; ground?: BqrGround; hue?: string; owner?: BqrOwner; lobe?: BqrLobe; autograph?: BqrAutograph; by?: BqrBy } = {}): Promise<string> {
488
552
  const size = o.size ?? 640;
489
553
  const canvas = document.createElement("canvas");
490
554
  canvas.width = size; canvas.height = size;
491
555
  // ⛔ v1.5.0 — `ground: "heart"` only for a picture that stays on screen; a URL handed to a download takes the default `paper`.
492
- await drawBqr(canvas.getContext("2d")!, text, { size, accent: o.accent, ecc: o.ecc, style: o.style, ground: o.ground, hue: o.hue, owner: o.owner, lobe: o.lobe, autograph: o.autograph });
556
+ await drawBqr(canvas.getContext("2d")!, text, { size, accent: o.accent, ecc: o.ecc, style: o.style, ground: o.ground, hue: o.hue, owner: o.owner, lobe: o.lobe, autograph: o.autograph, by: o.by });
493
557
  return canvas.toDataURL("image/png");
494
558
  }
@@ -0,0 +1,136 @@
1
+ /**
2
+ * B-Fingerprint℠ (founder 2026-11-24): what the dots in a marked heart's TOP lobe say — a short fingerprint of the PICTURE the heart was drawn for
3
+ * (⛔ never of a person), so a heart copied onto another picture is told apart by anyone, with no network. Open on purpose: this file writes it and
4
+ * reads it, and needs nothing but `bqr.ts`.
5
+ * ⛔ It says nothing about a person, carries no serial, no claim and no key, and none of it is secret: someone can redraw a heart for another
6
+ * picture. It catches a COPIED heart; the page the code opens shows the signed picture, and that decides.
7
+ * ⛔ An edited copy of the same picture looks the same to 36 coarse cells: this never says a picture is unchanged.
8
+ * Measured 2026-11-24 on 97 pictures, 194 posted corners at 70% white: the dots read whenever the code did (194 of 194 at 1,080 px q80, 182 of
9
+ * 182 at 720 q70) and never called the right picture different; a heart copied onto another varied photo was told apart 144 times of 152.
10
+ */
11
+ import { BQR_CODED_BITS, BQR_GEOMETRY, BQR_QUIET, BQR_TURNS, bqrLobeCells, bqrPlacement, bqrTurned, type BqrMatrix, type BqrPosition } from "./bqr";
12
+ export const GRID = 6, CELLS = GRID * GRID;
13
+ export type Kind = "corner" | "strip";
14
+ const KIND: Record<Kind, number> = { corner: 1, strip: 2 }; // the first four bits; any other number is not ours
15
+ export interface Box { x: number; y: number; s: number }
16
+ export interface Print { bits: number[]; seen: boolean[] }
17
+ /** 36 cells of a picture, each brighter or not than the picture's own middle; the cells the heart stands on are not seen. */
18
+ export function fingerprint(rgba: ArrayLike<number>, w: number, h: number, heart: Box | null): Print {
19
+ const sum = new Float64Array(CELLS), n = new Float64Array(CELLS);
20
+ for (let y = 0; y < h; y++) { const r = Math.min(GRID - 1, Math.floor(y * GRID / h)) * GRID; for (let x = 0, i = y * w * 4; x < w; x++, i += 4) { const c = r + Math.min(GRID - 1, Math.floor(x * GRID / w)); sum[c] += 0.299 * rgba[i] + 0.587 * rgba[i + 1] + 0.114 * rgba[i + 2]; n[c]++; } }
21
+ const mean = Array.from(sum, (v, i) => v / Math.max(1, n[i])), seen = mean.map(() => true);
22
+ if (heart) {
23
+ const p = heart.s * 0.04, x0 = (heart.x - p) * GRID / w, x1 = (heart.x + heart.s + p) * GRID / w, y0 = (heart.y - p) * GRID / h, y1 = (heart.y + heart.s + p) * GRID / h;
24
+ for (let r = 0; r < GRID; r++) for (let c = 0; c < GRID; c++) if (c + 1 > x0 && c < x1 && r + 1 > y0 && r < y1) seen[r * GRID + c] = false;
25
+ }
26
+ const used = mean.filter((_, i) => seen[i]).sort((a, b) => a - b), mid = used.length ? (used[(used.length - 1) >> 1] + used[used.length >> 1]) / 2 : 0;
27
+ return { bits: mean.map((v, i) => (seen[i] && v > mid ? 1 : 0)), seen };
28
+ }
29
+ // ---- the error correction: BCH over GF(2^7), 40 data bits + 56, up to 8 wrong bits put right. Written here so a reader needs nothing else;
30
+ // the same code TrustMark's BCH_SUPER is (polynomial 137), held to it by three recorded words in scripts/fingerprint.test.mjs ----
31
+ const M = 7, N = 127, T = 8, DATA = 40, ECC = 56;
32
+ const EXP = new Uint8Array(N * 2), LOG = new Uint8Array(N + 1);
33
+ for (let i = 0, x = 1; i < N; i++) { EXP[i] = EXP[i + N] = x; LOG[x] = i; x <<= 1; if (x & (1 << M)) x ^= 137; }
34
+ const mul = (a: number, b: number) => (a && b ? EXP[LOG[a] + LOG[b]] : 0);
35
+ /** The generator: the least polynomial with α¹ … α¹⁶ among its roots, highest power first. */
36
+ const GEN = (() => {
37
+ const roots = new Set<number>();
38
+ for (let j = 1; j <= 2 * T; j++) for (let k = 0, r = j; k < M; k++, r = (r * 2) % N) roots.add(r);
39
+ let g = [1];
40
+ for (const r of roots) { const n = new Array<number>(g.length + 1).fill(0); g.forEach((c, i) => { n[i] ^= c; n[i + 1] ^= mul(c, EXP[r]); }); g = n; }
41
+ return g;
42
+ })();
43
+ export function bchEncode(data: readonly number[]): number[] {
44
+ const r = [...data, ...new Array<number>(ECC).fill(0)];
45
+ for (let i = 0; i < DATA; i++) if (r[i]) for (let k = 0; k <= ECC; k++) r[i + k] ^= GEN[k];
46
+ return r.slice(DATA);
47
+ }
48
+ /** The 40 data bits, up to 8 wrong of the 96 put right; null when there are more. */
49
+ export function bchDecode(word: readonly number[]): number[] | null {
50
+ const n = DATA + ECC, s: number[] = [];
51
+ for (let j = 1; j <= 2 * T; j++) { let v = 0; for (let i = 0; i < n; i++) if (word[i]) v ^= EXP[(j * (n - 1 - i)) % N]; s.push(v); }
52
+ if (s.every((v) => v === 0)) return word.slice(0, DATA);
53
+ let c = [1], b = [1], L = 0, m = 1, bb = 1;
54
+ for (let k = 0; k < 2 * T; k++) {
55
+ let d = s[k]; for (let i = 1; i <= L; i++) d ^= mul(c[i] ?? 0, s[k - i]);
56
+ if (!d) { m++; continue; }
57
+ const t = [...c], f = EXP[(LOG[d] + N - LOG[bb]) % N];
58
+ for (let i = 0; i < b.length; i++) c[i + m] = (c[i + m] ?? 0) ^ mul(f, b[i]);
59
+ for (let i = 0; i < c.length; i++) c[i] ??= 0;
60
+ if (2 * L <= k) { L = k + 1 - L; b = t; bb = d; m = 1; } else m++;
61
+ }
62
+ if (L > T) return null;
63
+ const out = [...word]; let found = 0;
64
+ for (let i = 0; i < n; i++) { const x = (N - ((n - 1 - i) % N)) % N; let v = 0; for (let k = 0; k <= L; k++) v ^= mul(c[k] ?? 0, EXP[(k * x) % N]); if (!v) { out[i] ^= 1; found++; } }
65
+ return found === L ? out.slice(0, DATA) : null;
66
+ }
67
+ /** The 96 dots: the kind (4 bits), the 36 cells, and 56 bits that put up to 8 wrong ones right. */
68
+ export function codedOf(kind: Kind, p: Print): number[] {
69
+ const d = [...Array.from({ length: 4 }, (_, i) => (KIND[kind] >> (3 - i)) & 1), ...p.bits];
70
+ return [...d, ...bchEncode(d)];
71
+ }
72
+ /** The kind and cells these 96 read values carry, or null: not ours, or too damaged to put right. */
73
+ export function readCoded(bits: readonly boolean[]): { kind: Kind; bits: number[] } | null {
74
+ const d = bits.length === BQR_CODED_BITS ? bchDecode(bits.map(Number)) : null;
75
+ if (!d) return null;
76
+ const k = parseInt(d.slice(0, 4).join(""), 2), kind = (Object.keys(KIND) as Kind[]).find((x) => KIND[x] === k);
77
+ return kind ? { kind, bits: d.slice(4) } : null;
78
+ }
79
+ export type Pt = { x: number; y: number };
80
+ type Gray = (x: number, y: number) => number;
81
+ /** Light between pixels: at a small size a dot is two or three of them. */
82
+ export function gray(rgba: ArrayLike<number>, w: number, h: number): Gray {
83
+ const g = (a: number, b: number) => { const i = (b * w + a) * 4; return 0.299 * rgba[i] + 0.587 * rgba[i + 1] + 0.114 * rgba[i + 2]; };
84
+ return (x, y) => { const X = Math.max(0, Math.min(w - 1.001, x - 0.5)), Y = Math.max(0, Math.min(h - 1.001, y - 0.5)), a = Math.floor(X), b = Math.floor(Y), fx = X - a, fy = Y - b; return (g(a, b) * (1 - fx) + g(a + 1, b) * fx) * (1 - fy) + (g(a, b + 1) * (1 - fx) + g(a + 1, b + 1) * fx) * fy; };
85
+ }
86
+ /** Where the DRAWN (turned) grid lies: its left, its top and one module, in pixels. A posted picture is upright, so nothing else is needed. */
87
+ export interface Grid { x: number; y: number; m: number; position?: BqrPosition }
88
+ /**
89
+ * The grid, found again from the code itself: the reader's corners are about a pixel out, and the dots stand a whole code's width away, so
90
+ * the 625 modules, whose values are known, are laid over the photo and moved until they fit best. Null when they don't (a tilted photo).
91
+ */
92
+ export function register(upright: BqrMatrix, light: Gray, corners: readonly Pt[]): Grid | null {
93
+ let best: { grid: Grid; score: number } | null = null;
94
+ for (const position of ["point", "notch"] as const) { const r = fitted(bqrTurned(upright, BQR_TURNS[position]), light, corners); if (r && (!best || r.score > best.score)) best = { grid: { ...r.grid, position }, score: r.score }; }
95
+ return best?.grid ?? null;
96
+ }
97
+ function fitted(mat: BqrMatrix, light: Gray, corners: readonly Pt[]): { grid: Grid; score: number } | null {
98
+ const n = mat.size, xs = corners.map((p) => p.x).sort((a, b) => a - b), ys = corners.map((p) => p.y).sort((a, b) => a - b);
99
+ const start: Grid = { x: (xs[0] + xs[1]) / 2, y: (ys[0] + ys[1]) / 2, m: ((xs[2] + xs[3] - xs[0] - xs[1]) / 2 + (ys[2] + ys[3] - ys[0] - ys[1]) / 2) / 2 / n };
100
+ if (!(start.m > 0.5)) return null;
101
+ const cells: [number, number, number][] = []; // drawn column, drawn row, +1 light / −1 dark
102
+ let dark = 0;
103
+ for (let r = 0; r < n; r++) for (let c = 0; c < n; c++) { const d = mat.data[r * n + c] ? 1 : 0; dark += d; cells.push([c, r, d ? -1 : 1]); }
104
+ // near two corners of each module: its middle alone says nothing of where a large one ends
105
+ const fit = (g: Grid) => { let a = 0, b = 0; for (const [c, r, v] of cells) { const l = (light(g.x + (c + 0.22) * g.m, g.y + (r + 0.22) * g.m) + light(g.x + (c + 0.78) * g.m, g.y + (r + 0.78) * g.m)) / 2; if (v > 0) a += l; else b += l; } return a / (n * n - dark) - b / dark; };
106
+ let best = start, score = fit(start);
107
+ for (const step of [0.6, 0.3, 0.15, 0.07]) for (let turn = 0; turn < 6; turn++) {
108
+ let moved = false;
109
+ for (const g of [{ ...best, x: best.x + step }, { ...best, x: best.x - step }, { ...best, y: best.y + step }, { ...best, y: best.y - step },
110
+ { x: best.x - step * 0.5, y: best.y - step * 0.5, m: best.m + step / n }, { x: best.x + step * 0.5, y: best.y + step * 0.5, m: best.m - step / n }]) { const q = fit(g); if (q > score) { best = g; score = q; moved = true; } }
111
+ if (!moved) break;
112
+ }
113
+ return score > 25 ? { grid: best, score } : null;
114
+ }
115
+ /** The 96 values in a photo of the drawing: each dot's light, both places added, judged against the lobe's own light and dark. */
116
+ export function sampleCoded(mat: BqrMatrix, light: Gray, g: Grid): boolean[] {
117
+ const v = bqrLobeCells(mat).map(([c, r]) => { let s = 0; for (const [dx, dy] of [[0, 0], [-0.2, 0], [0.2, 0], [0, -0.2], [0, 0.2]]) s += light(g.x + (c + 0.5 + dx) * g.m, g.y + (r + 0.5 + dy) * g.m); return s / 5; });
118
+ const sorted = [...v].sort((a, b) => a - b), mid = (sorted[Math.floor(v.length * 0.15)] + sorted[Math.floor(v.length * 0.85)]) / 2;
119
+ return Array.from({ length: BQR_CODED_BITS }, (_, i) => (mid - v[i]) + (mid - v[i + BQR_CODED_BITS]) > 0);
120
+ }
121
+ /** Where the whole heart's square stands in the photo. */
122
+ export function heartBox(mat: BqrMatrix, g: Grid): Box {
123
+ const G = BQR_GEOMETRY.outline, m = G.body.s / (mat.size + 2 * BQR_QUIET), one = bqrPlacement(1), s = g.m / m / one.k;
124
+ return { s, x: g.x - (one.tx + (G.body.x + BQR_QUIET * m) * one.k) * s, y: g.y - (one.ty + (G.body.y + BQR_QUIET * m) * one.k) * s };
125
+ }
126
+ /** How the dots stand to the picture around them. ⛔ Never "unchanged": "same" means it looks like the picture the heart was drawn for. */
127
+ export const NEAR = 0.2;
128
+ export function drawnFor(read: { kind: Kind; bits: number[] }, rgba: ArrayLike<number>, w: number, h: number, box: Box): { answer: "same" | "different"; off: number; of: number } {
129
+ let H = h, heart: Box | null = box;
130
+ if (read.kind === "strip") { H = Math.max(GRID, Math.min(h, Math.round(box.y - (box.s / 0.9) * 0.05))); heart = null; }
131
+ const p = fingerprint(rgba, w, H, heart);
132
+ let off = 0, of = 0;
133
+ for (let i = 0; i < CELLS; i++) if (p.seen[i]) { of++; if (p.bits[i] !== read.bits[i]) off++; }
134
+ return { answer: off <= NEAR * of ? "same" : "different", off, of };
135
+ }
136
+