inkless 0.0.0-stage → 0.1.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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -2
  3. package/bin/inkless.js +10 -0
  4. package/console-dist/assets/BlueprintTool-CLWuM21a.js +4226 -0
  5. package/console-dist/assets/index-CIqLZU6s.js +33 -0
  6. package/console-dist/assets/index-Dv7Gg9qm.css +1 -0
  7. package/console-dist/favicon.svg +11 -0
  8. package/console-dist/index.html +18 -0
  9. package/native/linux/rfcomm.py +84 -0
  10. package/native/macos/build/InklessBluetooth.app/Contents/Info.plist +26 -0
  11. package/native/macos/build/InklessBluetooth.app/Contents/MacOS/InklessBluetooth +0 -0
  12. package/native/macos/build/InklessBluetooth.app/Contents/_CodeSignature/CodeResources +115 -0
  13. package/package.json +60 -4
  14. package/skills/inkless/SKILL.md +213 -0
  15. package/src/core/bits.js +143 -0
  16. package/src/core/blueprint/demos.js +119 -0
  17. package/src/core/blueprint/geometry.js +232 -0
  18. package/src/core/blueprint/index.js +100 -0
  19. package/src/core/blueprint/layout.js +210 -0
  20. package/src/core/blueprint/mesh.js +101 -0
  21. package/src/core/blueprint/methods.js +95 -0
  22. package/src/core/blueprint/remesh.js +250 -0
  23. package/src/core/blueprint/slice.js +134 -0
  24. package/src/core/blueprint/unfold.js +185 -0
  25. package/src/core/design/codes.js +39 -0
  26. package/src/core/design/filters.js +109 -0
  27. package/src/core/design/render.js +317 -0
  28. package/src/core/design/schema.js +132 -0
  29. package/src/core/formats/fit.js +46 -0
  30. package/src/core/formats/index.js +210 -0
  31. package/src/core/formats/library.js +341 -0
  32. package/src/core/formats/share.js +65 -0
  33. package/src/core/index.js +15 -0
  34. package/src/core/printers/hp6.js +160 -0
  35. package/src/core/printers/index.js +14 -0
  36. package/src/core/printers/pm290.js +115 -0
  37. package/src/core/session.js +56 -0
  38. package/src/node/artwork.js +33 -0
  39. package/src/node/cli.js +430 -0
  40. package/src/node/console/actions.js +30 -0
  41. package/src/node/console/client.js +68 -0
  42. package/src/node/console/paths.js +8 -0
  43. package/src/node/console/server.js +286 -0
  44. package/src/node/design.js +99 -0
  45. package/src/node/formats.js +39 -0
  46. package/src/node/frames.js +93 -0
  47. package/src/node/index.js +6 -0
  48. package/src/node/kit.js +12 -0
  49. package/src/node/skill.js +44 -0
  50. package/src/node/transports/index.js +21 -0
  51. package/src/node/transports/linux.js +52 -0
  52. package/src/node/transports/macos.js +81 -0
@@ -0,0 +1,210 @@
1
+ // @ts-check
2
+ // Label formats: reusable layouts with {{key}} placeholders that agents and
3
+ // people fill in, adapt to a printer, tweak, and save as new formats.
4
+ import { normalizeDesign } from "../design/schema.js";
5
+ import { retargetDesign } from "./fit.js";
6
+ import { BUILT_IN } from "./library.js";
7
+
8
+ /**
9
+ * @typedef {import("../design/schema.js").Design} Design
10
+ * @typedef {import("../design/schema.js").PrinterId} PrinterId
11
+ * @typedef {{ key: string, label: string, example: string }} FormatField
12
+ * @typedef {"square" | "wide" | "tall" | "round" | "tape" | "sheet"} FormFactor
13
+ * @typedef {object} Format
14
+ * @property {string} id lowercase letters, digits and dashes
15
+ * @property {string} name
16
+ * @property {string} [description]
17
+ * @property {FormFactor} formFactor
18
+ * @property {{ widthMm: number, heightMm: number }} size
19
+ * @property {PrinterId[]} printers the printers it fits; the first is the one it was drawn for
20
+ * @property {FormatField[]} fields
21
+ * @property {Design} design text, qr and barcode values may hold {{key}}
22
+ * @property {boolean} [saved] a format someone saved, not a built-in one
23
+ *
24
+ * A filled design remembers where it came from in `design.format`
25
+ * ({ id, name, fields, values }) and each filled element keeps its original
26
+ * `template`, so the fields can be changed again after the layout was edited.
27
+ */
28
+
29
+ export const FORM_FACTORS = /** @type {FormFactor[]} */ (["square", "wide", "tall", "round", "tape", "sheet"]);
30
+ const PRINTERS = ["pm290", "hp6"];
31
+ const PLACEHOLDER = /\{\{\s*([a-z][a-z0-9_]*)\s*\}\}/gi;
32
+ const CONTENT = { text: "text", qr: "value", barcode: "value" };
33
+
34
+ /**
35
+ * Fill {{key}} placeholders; unknown keys stay as they are. Wi-Fi QR payloads
36
+ * escape \ ; , : and " in values, so a password like "a;b" still scans.
37
+ */
38
+ export function fillText(template, values) {
39
+ const wifi = template.startsWith("WIFI:");
40
+ return template.replace(PLACEHOLDER, (match, key) => {
41
+ if (!(key in values)) return match;
42
+ const value = String(values[key]);
43
+ return wifi ? value.replace(/[\\;,:"]/g, "\\$&") : value;
44
+ });
45
+ }
46
+
47
+ const keysIn = (text) => [...String(text).matchAll(PLACEHOLDER)].map((m) => m[1]);
48
+ const elementsOf = (design) => design.pages.flatMap((page) => page.elements);
49
+
50
+ /** Every placeholder key a design uses, in order of first use. */
51
+ export const placeholders = (design) => [...new Set(elementsOf(design).flatMap((el) => (CONTENT[el.type] ? keysIn(el.template ?? el[CONTENT[el.type]]) : [])))];
52
+
53
+ /** Does a label of this size suit a printer without shrinking it into something unreadable? */
54
+ export function fitsPrinter(size, printer) {
55
+ if (printer === "pm290") return true;
56
+ const aspect = size.widthMm / size.heightMm;
57
+ return aspect >= 2.4 && aspect <= 3.75;
58
+ }
59
+
60
+ export const slug = (text) => String(text).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 48);
61
+
62
+ /**
63
+ * Check a format and fill in what can be worked out. Throws with a plain reason.
64
+ * @returns {Format}
65
+ */
66
+ export function validateFormat(input) {
67
+ const f = input ?? {};
68
+ const fail = (why) => { throw new Error(`format ${f.id ?? f.name ?? ""}: ${why}`.replace(/ +/, " ")); };
69
+ if (typeof f.id !== "string" || !/^[a-z0-9]+(-[a-z0-9]+)*$/.test(f.id)) fail("id must be lowercase letters, digits and dashes");
70
+ if (typeof f.name !== "string" || !f.name.trim()) fail("needs a name");
71
+ if (!FORM_FACTORS.includes(f.formFactor)) fail(`formFactor is one of ${FORM_FACTORS.join(", ")}`);
72
+ let design;
73
+ try {
74
+ design = normalizeDesign(f.design);
75
+ } catch (error) {
76
+ fail(error.message);
77
+ }
78
+ const printers = Array.isArray(f.printers) && f.printers.length ? f.printers : [design.printer];
79
+ if (printers.some((p) => !PRINTERS.includes(p))) fail(`printers are ${PRINTERS.join(" and ")}`);
80
+ if (printers[0] !== design.printer) fail(`its first printer must be the design's (${design.printer})`);
81
+ const fields = Array.isArray(f.fields) ? f.fields : [];
82
+ const keys = fields.map((field) => field?.key);
83
+ if (keys.some((k) => typeof k !== "string" || !/^[a-z][a-z0-9_]*$/.test(k))) fail("field keys are lowercase letters, digits and _");
84
+ if (new Set(keys).size !== keys.length) fail("two fields share a key");
85
+ const used = placeholders(design);
86
+ const missing = used.find((k) => !keys.includes(k));
87
+ if (missing) fail(`{{${missing}}} has no field`);
88
+ const unused = keys.find((k) => !used.includes(k));
89
+ if (unused) fail(`field ${unused} is not used in the design`);
90
+ return {
91
+ id: f.id,
92
+ name: f.name.trim(),
93
+ ...(f.description && { description: String(f.description) }),
94
+ formFactor: f.formFactor,
95
+ size: { ...design.size },
96
+ printers,
97
+ fields: fields.map(({ key, label, example }) => ({ key, label: String(label || key), example: String(example ?? "") })),
98
+ design,
99
+ ...(f.saved && { saved: true }),
100
+ };
101
+ }
102
+
103
+ const LIBRARY = BUILT_IN.map(validateFormat);
104
+
105
+ /** The built-in formats, optionally only those for one printer or form factor. */
106
+ export function listFormats({ printer, formFactor } = {}) {
107
+ return LIBRARY.filter((f) => (!printer || f.printers.includes(printer)) && (!formFactor || f.formFactor === formFactor));
108
+ }
109
+
110
+ /** A built-in format by id, or undefined. */
111
+ export const getFormat = (id) => LIBRARY.find((f) => f.id === id);
112
+
113
+ /**
114
+ * A ready-to-print design from a format. Missing values use each field's
115
+ * example; unknown keys are an error so typos never pass silently.
116
+ * @param {Format} format
117
+ * @param {Record<string, string>} [values]
118
+ * @param {{ printer?: PrinterId }} [options] adapt it to this printer (one the format lists)
119
+ * @returns {Design}
120
+ */
121
+ export function fillFormat(format, values = {}, { printer } = {}) {
122
+ const keys = format.fields.map((f) => f.key);
123
+ const stray = Object.keys(values).find((k) => !keys.includes(k));
124
+ if (stray) throw new Error(`${format.name} has no field "${stray}"; its fields are ${keys.join(", ")}`);
125
+ if (printer && !format.printers.includes(printer)) {
126
+ throw new Error(`${format.name} does not fit the ${printer === "hp6" ? "HP6-C" : "PM290"}; it fits ${format.printers.join(", ")}`);
127
+ }
128
+ const all = Object.fromEntries(format.fields.map((f) => [f.key, values[f.key] ?? f.example]));
129
+ const design = structuredClone(format.design);
130
+ for (const el of elementsOf(design)) {
131
+ const prop = CONTENT[el.type];
132
+ if (!prop || !keysIn(el[prop]).length) continue;
133
+ el.template = el[prop];
134
+ el[prop] = fillText(el.template, all);
135
+ }
136
+ const filled = normalizeDesign({
137
+ ...design,
138
+ title: design.title ?? format.name,
139
+ format: { id: format.id, name: format.name, fields: format.fields, values: all },
140
+ });
141
+ return printer ? retargetDesign(filled, printer).design : filled;
142
+ }
143
+
144
+ /**
145
+ * Change the field values of a filled design, keeping its layout. An element
146
+ * whose content was edited by hand keeps that edit and stops following its field.
147
+ * @param {Design & { format?: any }} design
148
+ * @param {Record<string, string>} values
149
+ */
150
+ export function refillDesign(design, values) {
151
+ if (!design.format) return design;
152
+ const before = design.format.values ?? {};
153
+ const after = { ...before, ...values };
154
+ const pages = design.pages.map((page) => ({
155
+ ...page,
156
+ elements: page.elements.map((el) => {
157
+ const prop = CONTENT[el.type];
158
+ if (!prop || el.template === undefined) return el;
159
+ if (el[prop] !== fillText(el.template, before)) {
160
+ const { template, ...edited } = el;
161
+ return edited;
162
+ }
163
+ return { ...el, [prop]: fillText(el.template, after) };
164
+ }),
165
+ }));
166
+ return { ...design, pages, format: { ...design.format, values: after } };
167
+ }
168
+
169
+ /**
170
+ * Turn a design into a format to save. Filled elements go back to their
171
+ * placeholders; a {{key}} typed into any text becomes a field too.
172
+ * @param {Design & { format?: any }} design
173
+ * @param {{ name: string, id?: string, description?: string, formFactor?: FormFactor, fields?: FormatField[] }} meta
174
+ * @returns {Format}
175
+ */
176
+ export function formatFromDesign(design, meta) {
177
+ const doc = normalizeDesign(design);
178
+ const { format: origin, ...rest } = /** @type {any} */ (doc);
179
+ const pages = rest.pages.map((page) => ({
180
+ ...page,
181
+ elements: page.elements.map((el) => {
182
+ const { template, ...plain } = el;
183
+ return template === undefined ? plain : { ...plain, [CONTENT[el.type]]: template };
184
+ }),
185
+ }));
186
+ const blank = { ...rest, title: meta.name, pages };
187
+ const known = new Map([...(origin?.fields ?? []), ...(meta.fields ?? [])].map((f) => [f.key, f]));
188
+ const values = origin?.values ?? {};
189
+ const fields = placeholders(blank).map((key) => {
190
+ const field = known.get(key);
191
+ return { key, label: field?.label ?? key.replace(/_/g, " "), example: values[key] ?? field?.example ?? "" };
192
+ });
193
+ const { widthMm, heightMm } = doc.size;
194
+ const aspect = widthMm / heightMm;
195
+ const formFactor = meta.formFactor ?? (aspect > 2.4 ? "tape" : aspect > 1.15 ? "wide" : aspect < 0.87 ? (heightMm > 64 ? "sheet" : "tall") : "square");
196
+ const printers = /** @type {PrinterId[]} */ ([doc.printer, ...PRINTERS.filter((p) => p !== doc.printer && fitsPrinter(doc.size, p))]);
197
+ const id = slug(meta.id ?? meta.name) || "my-format";
198
+ return validateFormat({
199
+ id: getFormat(id) ? `my-${id}` : id,
200
+ name: meta.name,
201
+ description: meta.description,
202
+ formFactor,
203
+ printers,
204
+ fields,
205
+ design: blank,
206
+ saved: true,
207
+ });
208
+ }
209
+
210
+ export { retargetDesign, clampLength } from "./fit.js";
@@ -0,0 +1,341 @@
1
+ // @ts-check
2
+ // The built-in label formats. Millimetres, 8 dots per mm. Text without a size
3
+ // fits its box, so a long value shrinks instead of running off the label.
4
+
5
+ const text = (id, x, y, w, h, value, more = {}) => ({ id, type: "text", x, y, w, h, text: value, font: "sans", ...more });
6
+ const bold = (id, x, y, w, h, value, more = {}) => text(id, x, y, w, h, value, { weight: 700, ...more });
7
+ const mono = (id, x, y, w, h, value, more = {}) => text(id, x, y, w, h, value, { font: "mono", ...more });
8
+ const rule = (id, x, y, w, strokeMm = 0.3) => ({ id, type: "shape", shape: "line", x, y, w, h: 0, strokeMm });
9
+ const box = (id, x, y, w, h, more = {}) => ({ id, type: "shape", shape: "rect", x, y, w, h, ...more });
10
+ const qr = (id, x, y, size, value) => ({ id, type: "qr", x, y, w: size, h: size, value });
11
+ const barcode = (id, x, y, w, h, value) => ({ id, type: "barcode", x, y, w, h, value });
12
+ /** A drawing in its own box: it stretches with the box, the pen keeps its width. */
13
+ const drawing = (id, x, y, w, h, d, strokeMm = 0.4, more = {}) => ({ id, type: "path", x, y, w, h, viewW: w, viewH: h, d, strokeMm, ...more });
14
+
15
+ const label = (printer, widthMm, heightMm, elements) => ({
16
+ version: 1, printer, size: { widthMm, heightMm }, pages: [{ id: "page-1", elements }],
17
+ });
18
+ const pm290 = (heightMm, elements) => label("pm290", 48, heightMm, elements);
19
+ const hp6 = (elements) => label("hp6", 36, 12, elements);
20
+
21
+ export const BUILT_IN = [
22
+ {
23
+ id: "parts-bin",
24
+ name: "Parts bin",
25
+ description: "Drawers and bins of small parts: what it is, the size, and where it lives.",
26
+ formFactor: "wide",
27
+ printers: ["pm290"],
28
+ fields: [
29
+ { key: "name", label: "Part", example: "M3 SCREWS" },
30
+ { key: "detail", label: "Details", example: "12 mm · socket head · A2 steel" },
31
+ { key: "bin", label: "Bin", example: "07" },
32
+ { key: "shelf", label: "Shelf", example: "B" },
33
+ { key: "link", label: "QR link", example: "https://example.com/parts/m3-12" },
34
+ ],
35
+ design: pm290(30, [
36
+ bold("name", 2.5, 2, 43, 8, "{{name}}"),
37
+ mono("detail", 2.5, 10.5, 43, 3.5, "{{detail}}"),
38
+ rule("rule", 2.5, 15.5, 43),
39
+ mono("bin-caption", 2.5, 17.5, 12, 2.5, "BIN"),
40
+ bold("bin", 2.5, 20, 12, 7, "{{bin}}", { font: "mono" }),
41
+ mono("shelf-caption", 16, 17.5, 14, 2.5, "SHELF"),
42
+ bold("shelf", 16, 20, 14, 7, "{{shelf}}", { font: "mono" }),
43
+ qr("link", 34.5, 17, 11, "{{link}}"),
44
+ ]),
45
+ },
46
+ {
47
+ id: "cable-flag",
48
+ name: "Cable flag",
49
+ description: "Wraps around a cable and sticks to itself as a flag that reads from both sides.",
50
+ formFactor: "tape",
51
+ printers: ["hp6", "pm290"],
52
+ fields: [
53
+ { key: "name", label: "Name", example: "ROUTER" },
54
+ { key: "detail", label: "Details", example: "WAN · port 1" },
55
+ ],
56
+ design: hp6([
57
+ bold("name-a", 1, 1.5, 13, 5.5, "{{name}}", { align: "center" }),
58
+ text("detail-a", 1, 7.5, 13, 3, "{{detail}}", { align: "center" }),
59
+ drawing("fold-a", 15.5, 1, 0.1, 10, "M0 0V1.5M0 3V4.5M0 6V7.5M0 9V10", 0.2),
60
+ drawing("fold-b", 20.5, 1, 0.1, 10, "M0 0V1.5M0 3V4.5M0 6V7.5M0 9V10", 0.2),
61
+ bold("name-b", 22, 1.5, 13, 5.5, "{{name}}", { align: "center" }),
62
+ text("detail-b", 22, 7.5, 13, 3, "{{detail}}", { align: "center" }),
63
+ ]),
64
+ },
65
+ {
66
+ id: "drawer-tape",
67
+ name: "Drawer label",
68
+ description: "A short tape for drawers, shelves and switches: a code, a name and a hint.",
69
+ formFactor: "tape",
70
+ printers: ["hp6", "pm290"],
71
+ fields: [
72
+ { key: "code", label: "Code", example: "A1" },
73
+ { key: "name", label: "Name", example: "BATTERIES" },
74
+ { key: "detail", label: "Details", example: "AA · AAA · coin cells" },
75
+ ],
76
+ design: hp6([
77
+ box("code-box", 1, 1, 9, 10, { fill: true, radiusMm: 1 }),
78
+ bold("code", 1.5, 3, 8, 6, "{{code}}", { align: "center", invert: true }),
79
+ bold("name", 11.5, 1.2, 23.5, 6, "{{name}}"),
80
+ text("detail", 11.5, 7.6, 23.5, 3, "{{detail}}"),
81
+ ]),
82
+ },
83
+ {
84
+ id: "file-folder",
85
+ name: "File folder",
86
+ description: "The tab of a folder or the front of a binder: title, what is inside, and a code.",
87
+ formFactor: "tape",
88
+ printers: ["pm290", "hp6"],
89
+ fields: [
90
+ { key: "title", label: "Title", example: "TAXES 2026" },
91
+ { key: "detail", label: "Contents", example: "Receipts · Jan to Jun" },
92
+ { key: "code", label: "Code", example: "F-03" },
93
+ ],
94
+ design: pm290(16, [
95
+ bold("title", 2, 1.8, 32, 7.5, "{{title}}"),
96
+ text("detail", 2, 10, 32, 3.8, "{{detail}}"),
97
+ box("code-box", 35.5, 1.5, 11, 13, { fill: true, radiusMm: 1.2 }),
98
+ bold("code", 36.2, 5.5, 9.6, 5, "{{code}}", { align: "center", invert: true, font: "mono" }),
99
+ ]),
100
+ },
101
+ {
102
+ id: "name-badge",
103
+ name: "Name badge",
104
+ description: "Events and first days: a header band, a big name, and a line about the person.",
105
+ formFactor: "wide",
106
+ printers: ["pm290"],
107
+ fields: [
108
+ { key: "header", label: "Header", example: "HELLO, MY NAME IS" },
109
+ { key: "name", label: "Name", example: "Lucia Rabbit" },
110
+ { key: "detail", label: "About", example: "Design team" },
111
+ ],
112
+ design: pm290(32, [
113
+ box("band", 0, 0, 48, 8, { fill: true }),
114
+ bold("header", 4, 2.2, 40, 3.8, "{{header}}", { align: "center", invert: true }),
115
+ bold("name", 3, 10.5, 42, 11, "{{name}}", { align: "center" }),
116
+ rule("rule", 12, 24, 24, 0.3),
117
+ text("detail", 3, 26, 42, 3.8, "{{detail}}", { align: "center" }),
118
+ ]),
119
+ },
120
+ {
121
+ id: "asset-tag",
122
+ name: "Asset tag",
123
+ description: "Laptops, tools and kit you lend out: who owns it, its number as a barcode, and who to call.",
124
+ formFactor: "wide",
125
+ printers: ["pm290"],
126
+ fields: [
127
+ { key: "owner", label: "Owner", example: "ACME LABS" },
128
+ { key: "asset", label: "Asset number", example: "IT-0042" },
129
+ { key: "contact", label: "If found", example: "If found, call 020 7946 0042" },
130
+ ],
131
+ design: pm290(30, [
132
+ box("band", 0, 0, 48, 6.5, { fill: true }),
133
+ mono("owner-caption", 2.5, 1.9, 18, 2.8, "PROPERTY OF", { invert: true, weight: 700 }),
134
+ bold("owner", 21, 1.6, 24.5, 3.4, "{{owner}}", { align: "right", invert: true }),
135
+ bold("asset", 2.5, 8.5, 43, 6, "{{asset}}", { font: "mono" }),
136
+ barcode("barcode", 2.5, 15.5, 43, 8, "{{asset}}"),
137
+ text("contact", 2.5, 25, 43, 3, "{{contact}}", { align: "center" }),
138
+ ]),
139
+ },
140
+ {
141
+ id: "wifi-qr",
142
+ name: "Wi-Fi QR",
143
+ description: "Guests scan it to join the network. The name and password are printed too.",
144
+ formFactor: "square",
145
+ printers: ["pm290"],
146
+ fields: [
147
+ { key: "network", label: "Network", example: "Home Network" },
148
+ { key: "password", label: "Password", example: "correct-horse-battery" },
149
+ ],
150
+ design: pm290(48, [
151
+ drawing("icon", 2.5, 2.5, 8, 6, "M0.4 2.4A6 6 0 0 1 7.6 2.4M1.8 3.9A3.8 3.8 0 0 1 6.2 3.9M3.2 5.2A1.6 1.6 0 0 1 4.8 5.2", 0.7),
152
+ bold("title", 12, 2.3, 22, 6, "Wi-Fi"),
153
+ mono("hint", 26, 3.6, 19.5, 3, "SCAN TO JOIN", { align: "right" }),
154
+ qr("qr", 12, 10, 24, "WIFI:T:WPA;S:{{network}};P:{{password}};;"),
155
+ mono("network-caption", 2.5, 35.5, 15, 2.5, "NETWORK"),
156
+ bold("network", 17, 35, 28.5, 3.8, "{{network}}"),
157
+ mono("password-caption", 2.5, 41, 15, 2.5, "PASSWORD"),
158
+ mono("password", 17, 40.5, 28.5, 3.8, "{{password}}", { weight: 700 }),
159
+ ]),
160
+ },
161
+ {
162
+ id: "manual-qr",
163
+ name: "Manual QR",
164
+ description: "Stick it on an appliance or a machine: scan it for the manual, the warranty or the how-to.",
165
+ formFactor: "wide",
166
+ printers: ["pm290"],
167
+ fields: [
168
+ { key: "title", label: "Thing", example: "Dishwasher" },
169
+ { key: "detail", label: "Model", example: "Bosch SMS4\nBought 2024" },
170
+ { key: "caption", label: "Caption", example: "SCAN FOR\nTHE MANUAL" },
171
+ { key: "link", label: "Link", example: "https://example.com/manuals/sms4" },
172
+ ],
173
+ design: pm290(30, [
174
+ qr("qr", 2, 3, 24, "{{link}}"),
175
+ mono("caption", 28, 3.5, 18, 6, "{{caption}}", { weight: 700, lineHeight: 1.15 }),
176
+ rule("rule", 28, 11.5, 18),
177
+ bold("title", 28, 13.5, 18, 5.5, "{{title}}"),
178
+ text("detail", 28, 19.8, 18, 6.5, "{{detail}}"),
179
+ ]),
180
+ },
181
+ {
182
+ id: "freezer-date",
183
+ name: "Freezer date",
184
+ description: "Bags and boxes in the freezer: what it is, how much, when it went in and when to use it.",
185
+ formFactor: "wide",
186
+ printers: ["pm290"],
187
+ fields: [
188
+ { key: "contents", label: "Contents", example: "Vegetable stock" },
189
+ { key: "detail", label: "Amount", example: "2 portions · 800 ml" },
190
+ { key: "frozen", label: "Frozen on", example: "05 DEC 2026" },
191
+ { key: "use_by", label: "Use by", example: "05 MAR 2027" },
192
+ ],
193
+ design: pm290(30, [
194
+ drawing("flake", 2.5, 2.5, 9, 9, "M4.5 0V9M0.6 2.25L8.4 6.75M0.6 6.75L8.4 2.25M3.3 0.6L4.5 1.6L5.7 0.6M3.3 8.4L4.5 7.4L5.7 8.4", 0.6),
195
+ bold("contents", 13.5, 2, 32, 6.5, "{{contents}}"),
196
+ text("detail", 13.5, 9, 32, 3.5, "{{detail}}"),
197
+ rule("rule", 2.5, 14.5, 43),
198
+ mono("frozen-caption", 2.5, 16.5, 20, 2.5, "FROZEN"),
199
+ bold("frozen", 2.5, 19.5, 20, 4.5, "{{frozen}}", { font: "mono" }),
200
+ box("use-box", 24.5, 16, 21, 11.5, { fill: true, radiusMm: 1.2 }),
201
+ mono("use-caption", 26, 17.5, 18, 2.5, "USE BY", { invert: true }),
202
+ bold("use_by", 26, 21, 18, 4.5, "{{use_by}}", { font: "mono", invert: true }),
203
+ ]),
204
+ },
205
+ {
206
+ id: "price-tag",
207
+ name: "Price tag",
208
+ description: "Markets, shops and yard sales: the item, a big price and a barcode, on a tag with a hole.",
209
+ formFactor: "tall",
210
+ printers: ["pm290"],
211
+ fields: [
212
+ { key: "item", label: "Item", example: "Linen shirt" },
213
+ { key: "detail", label: "Details", example: "Size M · navy" },
214
+ { key: "price", label: "Price", example: "€24" },
215
+ { key: "sku", label: "Code", example: "SKU-40112" },
216
+ ],
217
+ design: pm290(60, [
218
+ drawing("outline", 1, 1, 46, 58, "M8 0H38L46 8V58H0V8Z", 0.4),
219
+ { id: "hole", type: "shape", shape: "ellipse", x: 21, y: 4, w: 6, h: 6, strokeMm: 0.4 },
220
+ bold("item", 4, 13, 40, 6.5, "{{item}}", { align: "center" }),
221
+ text("detail", 4, 20.5, 40, 3.8, "{{detail}}", { align: "center" }),
222
+ bold("price", 4, 27, 40, 15, "{{price}}", { align: "center", font: "display", weight: 400 }),
223
+ barcode("barcode", 6, 45, 36, 7, "{{sku}}"),
224
+ mono("sku", 6, 52.8, 36, 2.8, "{{sku}}", { align: "center" }),
225
+ ]),
226
+ },
227
+ {
228
+ id: "plant-marker",
229
+ name: "Plant marker",
230
+ description: "A stake for pots and beds: the plant, its variety, when it was sown and how to care for it.",
231
+ formFactor: "tall",
232
+ printers: ["pm290"],
233
+ fields: [
234
+ { key: "name", label: "Plant", example: "Basil" },
235
+ { key: "variety", label: "Variety", example: "Genovese" },
236
+ { key: "sown", label: "Sown", example: "12 MAR 2026" },
237
+ { key: "care", label: "Care", example: "Full sun\nWater when dry" },
238
+ ],
239
+ design: pm290(80, [
240
+ drawing("outline", 1, 1, 46, 78, "M0 0H46V58L23 78L0 58Z", 0.4),
241
+ drawing("leaf", 18, 5, 12, 10, "M1 9C1 3 6 0.5 11 0.5C11 6 7 9.5 1 9.5ZM1 9.5L7 4", 0.5),
242
+ bold("name", 4, 17, 40, 9, "{{name}}", { align: "center" }),
243
+ text("variety", 4, 27, 40, 5, "{{variety}}", { align: "center", font: "serif" }),
244
+ rule("rule", 10, 35, 28),
245
+ mono("sown-caption", 4, 38, 40, 2.5, "SOWN", { align: "center" }),
246
+ bold("sown", 4, 41.5, 40, 4.5, "{{sown}}", { align: "center", font: "mono" }),
247
+ text("care", 6, 50, 36, 10, "{{care}}", { align: "center" }),
248
+ ]),
249
+ },
250
+ {
251
+ id: "book-spine",
252
+ name: "Book spine",
253
+ description: "Runs along the spine of a binder, a box file or a thick book, with a volume number on top.",
254
+ formFactor: "tall",
255
+ printers: ["pm290"],
256
+ fields: [
257
+ { key: "volume", label: "Volume", example: "03" },
258
+ { key: "title", label: "Title", example: "FIELD NOTES" },
259
+ { key: "detail", label: "Subtitle", example: "Bristol harbour survey" },
260
+ { key: "year", label: "Year", example: "2026" },
261
+ ],
262
+ design: pm290(140, [
263
+ box("top", 0, 0, 48, 16, { fill: true }),
264
+ bold("volume", 4, 2.5, 40, 11, "{{volume}}", { align: "center", invert: true, font: "mono" }),
265
+ bold("title", -21, 62.5, 100, 15, "{{title}}", { rotation: 90 }),
266
+ text("detail", -36, 67, 100, 6, "{{detail}}", { rotation: 90 }),
267
+ rule("rule", 4, 126, 40),
268
+ bold("year", 4, 129, 40, 8, "{{year}}", { align: "center", font: "mono" }),
269
+ ]),
270
+ },
271
+ {
272
+ id: "storage-box",
273
+ name: "Storage box",
274
+ description: "Moving and storage boxes: a number you can read across the room, where it goes, and what is inside.",
275
+ formFactor: "sheet",
276
+ printers: ["pm290"],
277
+ fields: [
278
+ { key: "number", label: "Box", example: "12" },
279
+ { key: "room", label: "Room", example: "GARAGE" },
280
+ { key: "contents", label: "Contents", example: "Camping stove\nTent pegs\nHead torches\nRope" },
281
+ { key: "link", label: "QR link", example: "https://example.com/boxes/12" },
282
+ ],
283
+ design: pm290(64, [
284
+ box("top", 0, 0, 48, 22, { fill: true }),
285
+ mono("caption", 3, 2.5, 20, 3, "BOX", { invert: true, weight: 700 }),
286
+ bold("number", 3, 5, 42, 15, "{{number}}", { invert: true, font: "display", weight: 400 }),
287
+ bold("room", 3, 24.5, 42, 7, "{{room}}"),
288
+ rule("rule", 3, 33, 42),
289
+ mono("contents-caption", 3, 35, 20, 2.5, "INSIDE"),
290
+ text("contents", 3, 38.5, 26, 22, "{{contents}}", { lineHeight: 1.25 }),
291
+ qr("qr", 31, 38, 14, "{{link}}"),
292
+ mono("qr-caption", 31, 53, 14, 4.5, "FULL\nLIST", { align: "center" }),
293
+ ]),
294
+ },
295
+ {
296
+ id: "shipping-address",
297
+ name: "Shipping address",
298
+ description: "Parcels and envelopes: who it is from, who it goes to in big type, and an order barcode.",
299
+ formFactor: "sheet",
300
+ printers: ["pm290"],
301
+ fields: [
302
+ { key: "from", label: "From", example: "Inkless Studio\n4 Harbour Lane, Bristol BS1 4QA" },
303
+ { key: "to_name", label: "To", example: "Lucia Rabbit" },
304
+ { key: "to_address", label: "Address", example: "12 Calle Mayor\n28013 Madrid\nSpain" },
305
+ { key: "order", label: "Order", example: "ORD-10482" },
306
+ ],
307
+ design: pm290(76, [
308
+ mono("from-caption", 3, 2.5, 12, 2.5, "FROM"),
309
+ text("from", 3, 5.5, 42, 6, "{{from}}"),
310
+ rule("rule", 0, 14, 48, 0.5),
311
+ box("to-tag", 3, 17, 10, 5, { fill: true, radiusMm: 0.8 }),
312
+ mono("to-caption", 3, 18, 10, 3, "TO", { align: "center", invert: true, weight: 700 }),
313
+ bold("to_name", 3, 24, 42, 8, "{{to_name}}"),
314
+ text("to_address", 3, 33, 42, 18, "{{to_address}}", { lineHeight: 1.25 }),
315
+ rule("rule-2", 0, 55, 48, 0.5),
316
+ barcode("barcode", 3, 58, 42, 10, "{{order}}"),
317
+ mono("order", 3, 69.5, 42, 3.5, "{{order}}", { align: "center" }),
318
+ ]),
319
+ },
320
+ {
321
+ id: "thank-you-seal",
322
+ name: "Thank-you seal",
323
+ description: "A round seal for parcels and gift wrap: a big thank you, your name and a short note.",
324
+ formFactor: "round",
325
+ printers: ["pm290"],
326
+ fields: [
327
+ { key: "headline", label: "Headline", example: "THANK YOU" },
328
+ { key: "name", label: "Name", example: "Inkless Studio" },
329
+ { key: "note", label: "Note", example: "for your order" },
330
+ ],
331
+ design: pm290(48, [
332
+ { id: "ring", type: "shape", shape: "ellipse", x: 1, y: 1, w: 46, h: 46, strokeMm: 0.8 },
333
+ { id: "ring-inner", type: "shape", shape: "ellipse", x: 3.5, y: 3.5, w: 41, h: 41, strokeMm: 0.3 },
334
+ drawing("star", 20.5, 8, 7, 7, "M3.5 0L4.4 2.6L7 3.5L4.4 4.4L3.5 7L2.6 4.4L0 3.5L2.6 2.6Z", 0.3, { fill: true }),
335
+ bold("headline", 7, 17, 34, 8.5, "{{headline}}", { align: "center" }),
336
+ rule("rule", 15, 27.5, 18),
337
+ text("name", 8, 29.5, 32, 4.5, "{{name}}", { align: "center", font: "serif" }),
338
+ text("note", 12, 35, 24, 3.2, "{{note}}", { align: "center" }),
339
+ ]),
340
+ },
341
+ ];
@@ -0,0 +1,65 @@
1
+ // @ts-check
2
+ // Share links: a whole design packed into the URL hash (deflate, base64url), so
3
+ // an agent can hand a person a console link with the label already in it.
4
+
5
+ export const SITE_URL = "https://inkless.sh";
6
+
7
+ /** Push bytes through a CompressionStream or DecompressionStream. */
8
+ async function through(bytes, stream) {
9
+ const writer = stream.writable.getWriter();
10
+ writer.write(bytes).catch(() => {});
11
+ writer.close().catch(() => {});
12
+ const reader = stream.readable.getReader();
13
+ const chunks = [];
14
+ for (;;) {
15
+ const { value, done } = await reader.read();
16
+ if (done) break;
17
+ chunks.push(value);
18
+ }
19
+ const out = new Uint8Array(chunks.reduce((n, c) => n + c.length, 0));
20
+ let at = 0;
21
+ for (const c of chunks) {
22
+ out.set(c, at);
23
+ at += c.length;
24
+ }
25
+ return out;
26
+ }
27
+
28
+ const toBase64Url = (bytes) => {
29
+ let binary = "";
30
+ for (let i = 0; i < bytes.length; i += 0x8000) binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
31
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
32
+ };
33
+ const fromBase64Url = (text) => Uint8Array.from(atob(text.replace(/-/g, "+").replace(/_/g, "/")), (c) => c.charCodeAt(0));
34
+
35
+ /** A design as a short URL-safe string. */
36
+ export async function encodeShare(design) {
37
+ return toBase64Url(await through(new TextEncoder().encode(JSON.stringify(design)), new CompressionStream("deflate-raw")));
38
+ }
39
+
40
+ /** The design inside a string from encodeShare. Throws when it is damaged. */
41
+ export async function decodeShare(text) {
42
+ try {
43
+ return JSON.parse(new TextDecoder().decode(await through(fromBase64Url(text), new DecompressionStream("deflate-raw"))));
44
+ } catch {
45
+ throw new Error("this link does not hold a label; it may be cut short");
46
+ }
47
+ }
48
+
49
+ /** The website's label designer with this design loaded. */
50
+ export async function shareLink(design, site = SITE_URL) {
51
+ return `${site.replace(/\/$/, "")}/label/#d=${await encodeShare(design)}`;
52
+ }
53
+
54
+ /**
55
+ * What a console URL hash asks for: `#d=<design>` or `#format=<id>`.
56
+ * @returns {{ design?: string, format?: string, printer?: string }}
57
+ */
58
+ export function readShareHash(hash) {
59
+ const params = new URLSearchParams(String(hash ?? "").replace(/^#/, ""));
60
+ return {
61
+ ...(params.get("d") && { design: params.get("d") }),
62
+ ...(params.get("format") && { format: params.get("format") }),
63
+ ...(params.get("printer") && { printer: params.get("printer") }),
64
+ };
65
+ }
@@ -0,0 +1,15 @@
1
+ // @ts-check
2
+ // Browser-safe core: rasters, printer protocols, the print session, the
3
+ // design document and its renderer. 3D pen blueprints load separately from
4
+ // "inkless/blueprint" so the 3D model loaders stay out of the main bundle.
5
+ export * from "./bits.js";
6
+ export { printers, getPrinter, pm290, hp6 } from "./printers/index.js";
7
+ export { buildTsplJob, Pm290Replies } from "./printers/pm290.js";
8
+ export { buildHp6Job, rasterRows, fitWidth, frame as hp6Frame, Hp6Replies } from "./printers/hp6.js";
9
+ export { runSession, CHUNK_BYTES, PACE_MS, TIMEOUTS } from "./session.js";
10
+ export * from "./design/schema.js";
11
+ export { renderDesign, renderPage, designFromArtwork } from "./design/render.js";
12
+ export { applyFilter, FILTER_MODES } from "./design/filters.js";
13
+ export { qrModules, code128Bars } from "./design/codes.js";
14
+ export * from "./formats/index.js";
15
+ export { encodeShare, decodeShare, shareLink, readShareHash, SITE_URL } from "./formats/share.js";