qrcodesolid 0.0.0 → 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.
- package/README.md +493 -2
- package/dist/color-parse-empty.d.ts +6 -0
- package/dist/color-parse-empty.js +7 -0
- package/dist/color-parse.d.ts +8 -0
- package/dist/color-parse.js +49 -0
- package/dist/index.d.ts +372 -0
- package/dist/index.js +2640 -0
- package/dist/paint-ChCPh-rm.d.ts +29 -0
- package/dist/payload.d.ts +53 -0
- package/dist/payload.js +93 -0
- package/dist/server.d.ts +399 -0
- package/dist/server.js +2833 -0
- package/dist/source/components/GradientDef.jsx +19 -0
- package/dist/source/components/QRCode.jsx +10 -0
- package/dist/source/components/QRCodeCanvas.jsx +72 -0
- package/dist/source/components/QRCodeSVG.jsx +57 -0
- package/dist/source/core/caption.js +77 -0
- package/dist/source/core/color-names.js +34 -0
- package/dist/source/core/color-parse-empty.js +5 -0
- package/dist/source/core/color-parse.js +41 -0
- package/dist/source/core/encode.js +120 -0
- package/dist/source/core/logo.js +90 -0
- package/dist/source/core/options.js +56 -0
- package/dist/source/core/output.js +23 -0
- package/dist/source/core/paint.js +30 -0
- package/dist/source/core/path.js +46 -0
- package/dist/source/core/qrcodegen.js +875 -0
- package/dist/source/core/scene.js +141 -0
- package/dist/source/core/stages.js +24 -0
- package/dist/source/core/warnings.js +38 -0
- package/dist/source/export/index.js +105 -0
- package/dist/source/index.js +16 -0
- package/dist/source/payload/contact.js +42 -0
- package/dist/source/payload/escape.js +3 -0
- package/dist/source/payload/index.js +3 -0
- package/dist/source/payload/message.js +19 -0
- package/dist/source/payload/place.js +40 -0
- package/dist/source/primitives/createColorScheme.js +18 -0
- package/dist/source/primitives/createPixelRatio.js +25 -0
- package/dist/source/primitives/createQRCode.js +47 -0
- package/dist/source/render/canvas.js +46 -0
- package/dist/source/render/color.js +63 -0
- package/dist/source/render/image.js +123 -0
- package/dist/source/render/svg-string.js +55 -0
- package/dist/source/shapes/bars.js +50 -0
- package/dist/source/shapes/finders.js +30 -0
- package/dist/source/shapes/frames.js +62 -0
- package/dist/source/shapes/modules.js +39 -0
- package/dist/source/shapes/types.js +8 -0
- package/llms.txt +117 -0
- package/package.json +95 -6
- package/skills/qrcodesolid/SKILL.md +101 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** A colour spaced evenly, or an `[offset, color]` pair with offset 0 to 1. */
|
|
2
|
+
type GradientStop = string | readonly [offset: number, color: string];
|
|
3
|
+
type Stops = readonly GradientStop[];
|
|
4
|
+
type Gradient = {
|
|
5
|
+
type: 'linear';
|
|
6
|
+
/** Degrees. 0 runs left to right. */
|
|
7
|
+
rotate?: number;
|
|
8
|
+
stops: Stops;
|
|
9
|
+
} | {
|
|
10
|
+
type: 'radial';
|
|
11
|
+
stops: Stops;
|
|
12
|
+
};
|
|
13
|
+
type Paint = string | Gradient;
|
|
14
|
+
type PlacedStops = readonly (readonly [number, string])[];
|
|
15
|
+
type PlacedPaint = string | {
|
|
16
|
+
readonly type: 'linear';
|
|
17
|
+
readonly x1: number;
|
|
18
|
+
readonly y1: number;
|
|
19
|
+
readonly x2: number;
|
|
20
|
+
readonly y2: number;
|
|
21
|
+
readonly stops: PlacedStops;
|
|
22
|
+
} | {
|
|
23
|
+
readonly type: 'radial';
|
|
24
|
+
readonly cx: number;
|
|
25
|
+
readonly cy: number;
|
|
26
|
+
readonly r: number;
|
|
27
|
+
readonly stops: PlacedStops;
|
|
28
|
+
};
|
|
29
|
+
export { PlacedPaint as i, GradientStop as n, Paint as r, Gradient as t };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare function wifi(o: {
|
|
2
|
+
ssid: string;
|
|
3
|
+
password?: string;
|
|
4
|
+
auth?: 'WPA' | 'WEP' | 'nopass';
|
|
5
|
+
hidden?: boolean;
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function vcard(o: {
|
|
8
|
+
name: {
|
|
9
|
+
first?: string;
|
|
10
|
+
last?: string;
|
|
11
|
+
};
|
|
12
|
+
org?: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
phone?: string | string[];
|
|
15
|
+
email?: string | string[];
|
|
16
|
+
url?: string;
|
|
17
|
+
address?: string;
|
|
18
|
+
note?: string;
|
|
19
|
+
}): string;
|
|
20
|
+
export declare function mecard(o: {
|
|
21
|
+
name: string;
|
|
22
|
+
phone?: string;
|
|
23
|
+
email?: string;
|
|
24
|
+
url?: string;
|
|
25
|
+
address?: string;
|
|
26
|
+
note?: string;
|
|
27
|
+
}): string;
|
|
28
|
+
export declare function mailto(o: {
|
|
29
|
+
to: string | string[];
|
|
30
|
+
subject?: string;
|
|
31
|
+
body?: string;
|
|
32
|
+
cc?: string | string[];
|
|
33
|
+
bcc?: string | string[];
|
|
34
|
+
}): string;
|
|
35
|
+
export declare const sms: (o: {
|
|
36
|
+
to: string;
|
|
37
|
+
body?: string;
|
|
38
|
+
}) => string;
|
|
39
|
+
export declare function tel(number: string): string;
|
|
40
|
+
export declare function geo(o: {
|
|
41
|
+
lat: number;
|
|
42
|
+
lng: number;
|
|
43
|
+
altitude?: number;
|
|
44
|
+
query?: string;
|
|
45
|
+
}): string;
|
|
46
|
+
export declare function event(o: {
|
|
47
|
+
title: string;
|
|
48
|
+
start: Date;
|
|
49
|
+
end?: Date;
|
|
50
|
+
location?: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
allDay?: boolean;
|
|
53
|
+
}): string;
|
package/dist/payload.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// src/payload/escape.ts
|
|
2
|
+
const escapeWifi = (s) => s.replace(/[\\;,:"]/g, "\\$&");
|
|
3
|
+
const escapeText = (s) => s.replace(/[\\;,]/g, "\\$&").replace(/\r?\n/g, "\\n");
|
|
4
|
+
const toList = (v) => v === void 0 ? [] : [v].flat();
|
|
5
|
+
// src/payload/contact.ts
|
|
6
|
+
function wifi(o) {
|
|
7
|
+
if (!o.ssid) throw new TypeError("wifi: ssid is required");
|
|
8
|
+
const auth = o.auth ?? (o.password ? "WPA" : "nopass");
|
|
9
|
+
const password = o.password && auth !== "nopass" ? `P:${escapeWifi(o.password)};` : "";
|
|
10
|
+
return `WIFI:T:${auth};S:${escapeWifi(o.ssid)};${password}${o.hidden ? "H:true;" : ""};`;
|
|
11
|
+
}
|
|
12
|
+
function vcard(o) {
|
|
13
|
+
const { first = "", last = "" } = o.name;
|
|
14
|
+
const lines = [
|
|
15
|
+
"BEGIN:VCARD",
|
|
16
|
+
"VERSION:3.0",
|
|
17
|
+
`N:${escapeText(last)};${escapeText(first)};;;`,
|
|
18
|
+
`FN:${escapeText([first, last].filter(Boolean).join(" "))}`
|
|
19
|
+
];
|
|
20
|
+
const add = (key, value) => value && lines.push(`${key}:${escapeText(value)}`);
|
|
21
|
+
add("ORG", o.org);
|
|
22
|
+
add("TITLE", o.title);
|
|
23
|
+
for (const p of toList(o.phone)) add("TEL", p);
|
|
24
|
+
for (const e of toList(o.email)) add("EMAIL", e);
|
|
25
|
+
add("URL", o.url);
|
|
26
|
+
if (o.address) lines.push(`ADR:;;${escapeText(o.address)};;;;`);
|
|
27
|
+
add("NOTE", o.note);
|
|
28
|
+
lines.push("END:VCARD");
|
|
29
|
+
return lines.join("\r\n");
|
|
30
|
+
}
|
|
31
|
+
function mecard(o) {
|
|
32
|
+
return `MECARD:${[
|
|
33
|
+
["N", o.name],
|
|
34
|
+
["TEL", o.phone],
|
|
35
|
+
["EMAIL", o.email],
|
|
36
|
+
["URL", o.url],
|
|
37
|
+
["ADR", o.address],
|
|
38
|
+
["NOTE", o.note]
|
|
39
|
+
].flatMap(([k, v]) => v ? [`${k}:${escapeWifi(v)};`] : []).join("")};`;
|
|
40
|
+
}
|
|
41
|
+
// src/payload/message.ts
|
|
42
|
+
const encode = (s) => encodeURIComponent(s).replace(/%40/g, "@");
|
|
43
|
+
function mailto(o) {
|
|
44
|
+
const addresses = (v) => toList(v).map(encode).join(",");
|
|
45
|
+
const params = [
|
|
46
|
+
["subject", o.subject && encode(o.subject)],
|
|
47
|
+
["body", o.body && encode(o.body)],
|
|
48
|
+
["cc", o.cc && addresses(o.cc)],
|
|
49
|
+
["bcc", o.bcc && addresses(o.bcc)]
|
|
50
|
+
].flatMap(([k, v]) => v ? [`${k}=${v}`] : []);
|
|
51
|
+
return `mailto:${addresses(o.to)}${params.length ? `?${params.join("&")}` : ""}`;
|
|
52
|
+
}
|
|
53
|
+
const sms = (o) => `SMSTO:${o.to}${o.body ? `:${o.body}` : ""}`;
|
|
54
|
+
function tel(number) {
|
|
55
|
+
const cleaned = number.replace(/[\s\-.()]/g, "");
|
|
56
|
+
if (!/^\+?\d+$/.test(cleaned)) throw new TypeError("tel: expected digits and a leading +");
|
|
57
|
+
return `tel:${cleaned}`;
|
|
58
|
+
}
|
|
59
|
+
// src/payload/place.ts
|
|
60
|
+
function geo(o) {
|
|
61
|
+
if (!Number.isFinite(o.lat) || o.lat < -90 || o.lat > 90) throw new TypeError("geo: bad lat");
|
|
62
|
+
if (!Number.isFinite(o.lng) || o.lng < -180 || o.lng > 180) throw new TypeError("geo: bad lng");
|
|
63
|
+
if (o.altitude !== void 0 && !Number.isFinite(o.altitude)) throw new TypeError("geo: bad altitude");
|
|
64
|
+
const alt = o.altitude === void 0 ? "" : `,${o.altitude}`;
|
|
65
|
+
const query = o.query ? `?q=${encodeURIComponent(o.query)}` : "";
|
|
66
|
+
return `geo:${o.lat},${o.lng}${alt}${query}`;
|
|
67
|
+
}
|
|
68
|
+
function checked(d, name) {
|
|
69
|
+
if (!(d instanceof Date) || Number.isNaN(d.getTime())) throw new TypeError(`event: bad ${name}`);
|
|
70
|
+
return d;
|
|
71
|
+
}
|
|
72
|
+
const stamp = (d) => d.toISOString().replace(/[-:]|\.\d{3}/g, "");
|
|
73
|
+
const pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
74
|
+
const day = (d) => `${pad(d.getFullYear(), 4)}${pad(d.getMonth() + 1)}${pad(d.getDate())}`;
|
|
75
|
+
function event(o) {
|
|
76
|
+
const start = checked(o.start, "start");
|
|
77
|
+
const end = o.end && checked(o.end, "end");
|
|
78
|
+
const time = (key, d) => o.allDay ? `${key};VALUE=DATE:${day(d)}` : `${key}:${stamp(d)}`;
|
|
79
|
+
const lines = [
|
|
80
|
+
"BEGIN:VEVENT",
|
|
81
|
+
`SUMMARY:${escapeText(o.title)}`,
|
|
82
|
+
time("DTSTART", start)
|
|
83
|
+
];
|
|
84
|
+
if (o.allDay) {
|
|
85
|
+
const last = end ?? start;
|
|
86
|
+
lines.push(time("DTEND", new Date(last.getFullYear(), last.getMonth(), last.getDate() + 1)));
|
|
87
|
+
} else if (end) lines.push(time("DTEND", end));
|
|
88
|
+
if (o.location) lines.push(`LOCATION:${escapeText(o.location)}`);
|
|
89
|
+
if (o.description) lines.push(`DESCRIPTION:${escapeText(o.description)}`);
|
|
90
|
+
lines.push("END:VEVENT");
|
|
91
|
+
return lines.join("\r\n");
|
|
92
|
+
}
|
|
93
|
+
export { event, geo, mailto, mecard, sms, tel, vcard, wifi };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { JSX } from "@solidjs/web";
|
|
2
|
+
import { Accessor } from "solid-js";
|
|
3
|
+
type Level = 'L' | 'M' | 'Q' | 'H';
|
|
4
|
+
/** An array encodes its strings in order, each in its own mode. */
|
|
5
|
+
type QRValue = string | readonly string[];
|
|
6
|
+
interface EncodeOptions {
|
|
7
|
+
level?: Level;
|
|
8
|
+
minVersion?: number;
|
|
9
|
+
maxVersion?: number;
|
|
10
|
+
/** -1 picks the best mask, 0-7 forces one. */
|
|
11
|
+
mask?: number;
|
|
12
|
+
boostLevel?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const Region: {
|
|
15
|
+
readonly Data: 0;
|
|
16
|
+
readonly Finder: 1;
|
|
17
|
+
readonly Alignment: 2;
|
|
18
|
+
readonly Timing: 3;
|
|
19
|
+
readonly Format: 4;
|
|
20
|
+
};
|
|
21
|
+
export type Region = (typeof Region)[keyof typeof Region];
|
|
22
|
+
/**
|
|
23
|
+
* `encode` caches matrices and returns the same frozen object for the same input.
|
|
24
|
+
* Do not write to `dark` or `region`: a change would reach every later caller.
|
|
25
|
+
*/
|
|
26
|
+
interface QRMatrix {
|
|
27
|
+
readonly size: number;
|
|
28
|
+
readonly version: number;
|
|
29
|
+
readonly level: Level;
|
|
30
|
+
readonly mask: number;
|
|
31
|
+
readonly dark: Uint8Array;
|
|
32
|
+
readonly region: Uint8Array;
|
|
33
|
+
/** Top-left corner of each 7x7 finder pattern. */
|
|
34
|
+
readonly finders: readonly (readonly [number, number])[];
|
|
35
|
+
}
|
|
36
|
+
export declare class QRCapacityError extends Error {
|
|
37
|
+
readonly version: number;
|
|
38
|
+
readonly level: Level;
|
|
39
|
+
/** Sum of segment character counts (characters or bytes, by mode). */
|
|
40
|
+
readonly dataLength: number;
|
|
41
|
+
constructor(version: number, level: Level,
|
|
42
|
+
/** Sum of segment character counts (characters or bytes, by mode). */
|
|
43
|
+
dataLength: number);
|
|
44
|
+
}
|
|
45
|
+
export declare function isDark(m: QRMatrix, x: number, y: number): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Encodes `value` into a module matrix, without Solid.
|
|
48
|
+
* Repeat calls with the same input return the cached object; see `QRMatrix`.
|
|
49
|
+
* `level` defaults to `'L'` here. The components default to `'M'`, or `'Q'` with a logo.
|
|
50
|
+
* @throws {QRCapacityError} when the data does not fit `maxVersion`.
|
|
51
|
+
* @throws {RangeError} when `minVersion` exceeds `maxVersion`, or a version or mask is out of range.
|
|
52
|
+
*/
|
|
53
|
+
export declare function encode(value: QRValue, options?: EncodeOptions): QRMatrix;
|
|
54
|
+
/** A colour spaced evenly, or an `[offset, color]` pair with offset 0 to 1. */
|
|
55
|
+
type GradientStop = string | readonly [offset: number, color: string];
|
|
56
|
+
type Stops = readonly GradientStop[];
|
|
57
|
+
type Gradient = {
|
|
58
|
+
type: 'linear';
|
|
59
|
+
/** Degrees. 0 runs left to right. */
|
|
60
|
+
rotate?: number;
|
|
61
|
+
stops: Stops;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'radial';
|
|
64
|
+
stops: Stops;
|
|
65
|
+
};
|
|
66
|
+
type Paint = string | Gradient;
|
|
67
|
+
type PlacedStops = readonly (readonly [number, string])[];
|
|
68
|
+
type PlacedPaint = string | {
|
|
69
|
+
readonly type: 'linear';
|
|
70
|
+
readonly x1: number;
|
|
71
|
+
readonly y1: number;
|
|
72
|
+
readonly x2: number;
|
|
73
|
+
readonly y2: number;
|
|
74
|
+
readonly stops: PlacedStops;
|
|
75
|
+
} | {
|
|
76
|
+
readonly type: 'radial';
|
|
77
|
+
readonly cx: number;
|
|
78
|
+
readonly cy: number;
|
|
79
|
+
readonly r: number;
|
|
80
|
+
readonly stops: PlacedStops;
|
|
81
|
+
};
|
|
82
|
+
interface ModuleContext {
|
|
83
|
+
/** Scene coords of the cell's top-left corner. */
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
neighbors: {
|
|
87
|
+
n: boolean;
|
|
88
|
+
e: boolean;
|
|
89
|
+
s: boolean;
|
|
90
|
+
w: boolean;
|
|
91
|
+
};
|
|
92
|
+
/** True inside an alignment pattern. Sparse shapes draw it solid so scanners can find it. */
|
|
93
|
+
alignment?: boolean;
|
|
94
|
+
}
|
|
95
|
+
interface LayerContext {
|
|
96
|
+
readonly matrix: QRMatrix;
|
|
97
|
+
/** False for finder cells, cells under the logo, and cells off the matrix. */
|
|
98
|
+
readonly include: (x: number, y: number) => boolean;
|
|
99
|
+
/** Add to matrix coords to get scene coords. */
|
|
100
|
+
readonly offset: Readonly<{
|
|
101
|
+
x: number;
|
|
102
|
+
y: number;
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A module shape draws one cell. A layer shape draws the whole layer: it reads matrix coords
|
|
107
|
+
* and returns a path in scene coords (`x + offset.x`).
|
|
108
|
+
*/
|
|
109
|
+
type Shape = {
|
|
110
|
+
kind: 'module';
|
|
111
|
+
draw: (m: ModuleContext) => string;
|
|
112
|
+
} | {
|
|
113
|
+
kind: 'layer';
|
|
114
|
+
draw: (layer: LayerContext) => string;
|
|
115
|
+
};
|
|
116
|
+
type ShapeInput = Shape | ((m: ModuleContext) => string);
|
|
117
|
+
export declare function defineModuleShape(draw: (m: ModuleContext) => string): Shape;
|
|
118
|
+
export declare function defineLayerShape(draw: (layer: LayerContext) => string): Shape;
|
|
119
|
+
/** Path for one finder part. Origin is the top-left of the 7x7 pattern, in scene units. */
|
|
120
|
+
type FinderPart = (x: number, y: number) => string;
|
|
121
|
+
type FinderOuterName = 'square' | 'rounded' | 'circle';
|
|
122
|
+
type FinderInnerName = 'square' | 'rounded' | 'dot' | 'diamond';
|
|
123
|
+
interface FinderStyle {
|
|
124
|
+
outer?: FinderOuterName | FinderPart;
|
|
125
|
+
inner?: FinderInnerName | FinderPart;
|
|
126
|
+
color?: Paint;
|
|
127
|
+
innerColor?: Paint;
|
|
128
|
+
}
|
|
129
|
+
interface Layer {
|
|
130
|
+
id: 'bg' | 'modules' | 'finder-outer' | 'finder-inner' | `frame-${string}`;
|
|
131
|
+
d: string;
|
|
132
|
+
fill: PlacedPaint;
|
|
133
|
+
fillRule?: 'evenodd';
|
|
134
|
+
}
|
|
135
|
+
interface SceneImage {
|
|
136
|
+
href: string;
|
|
137
|
+
x: number;
|
|
138
|
+
y: number;
|
|
139
|
+
width: number;
|
|
140
|
+
height: number;
|
|
141
|
+
radius: number;
|
|
142
|
+
opacity: number;
|
|
143
|
+
crossOrigin?: CrossOrigin;
|
|
144
|
+
}
|
|
145
|
+
interface SceneText {
|
|
146
|
+
text: string;
|
|
147
|
+
x: number;
|
|
148
|
+
y: number;
|
|
149
|
+
fontSize: number;
|
|
150
|
+
fontFamily: string;
|
|
151
|
+
fontWeight: string | number;
|
|
152
|
+
fill: PlacedPaint;
|
|
153
|
+
}
|
|
154
|
+
/** Scene units are modules. `qr` is the code box, margin included. */
|
|
155
|
+
interface Layout {
|
|
156
|
+
width: number;
|
|
157
|
+
height: number;
|
|
158
|
+
qr: {
|
|
159
|
+
x: number;
|
|
160
|
+
y: number;
|
|
161
|
+
size: number;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
type PaintKey = 'fg' | 'bg' | 'finder' | 'finderInner' | 'caption';
|
|
165
|
+
interface Geometry extends Layout {
|
|
166
|
+
paths: {
|
|
167
|
+
id: Layer['id'];
|
|
168
|
+
d: string;
|
|
169
|
+
fillRule?: 'evenodd';
|
|
170
|
+
paint: PaintKey | Paint;
|
|
171
|
+
}[];
|
|
172
|
+
image?: SceneImage;
|
|
173
|
+
texts: (Omit<SceneText, 'fill'> & {
|
|
174
|
+
paint: PaintKey | Paint;
|
|
175
|
+
})[];
|
|
176
|
+
/** Scan or layout risks the caption and frames found. Dev builds log them. */
|
|
177
|
+
warnings?: string[];
|
|
178
|
+
}
|
|
179
|
+
interface Scene {
|
|
180
|
+
width: number;
|
|
181
|
+
height: number;
|
|
182
|
+
layers: Layer[];
|
|
183
|
+
image?: SceneImage;
|
|
184
|
+
texts: SceneText[];
|
|
185
|
+
}
|
|
186
|
+
/** Wraps the layout. It may move `qr` and grow the size; it never resizes `qr`. */
|
|
187
|
+
type FramePlugin = (layout: Layout) => {
|
|
188
|
+
layout: Layout;
|
|
189
|
+
paths: Geometry['paths'];
|
|
190
|
+
texts: Geometry['texts'];
|
|
191
|
+
warnings?: string[];
|
|
192
|
+
};
|
|
193
|
+
interface Design {
|
|
194
|
+
margin: number;
|
|
195
|
+
modules: ShapeInput;
|
|
196
|
+
finder: FinderStyle;
|
|
197
|
+
image?: ImageOptions;
|
|
198
|
+
caption?: CaptionShape;
|
|
199
|
+
/** One frame, or a stack applied from the inside out: the last frame wraps the others. */
|
|
200
|
+
frame?: FramePlugin | readonly FramePlugin[];
|
|
201
|
+
}
|
|
202
|
+
interface Paints {
|
|
203
|
+
fg: Paint;
|
|
204
|
+
bg: Paint;
|
|
205
|
+
finder?: Paint;
|
|
206
|
+
finderInner?: Paint;
|
|
207
|
+
/** Default fg. */
|
|
208
|
+
caption?: Paint;
|
|
209
|
+
}
|
|
210
|
+
/** The caption fields that shape the layout. The colour is a paint, not geometry. */
|
|
211
|
+
type CaptionShape = Omit<CaptionOptions, 'color'>;
|
|
212
|
+
type CrossOrigin = '' | 'anonymous' | 'use-credentials';
|
|
213
|
+
interface ImageOptions {
|
|
214
|
+
src: string;
|
|
215
|
+
/** Fraction of the code width without margin. Default 0.2. */
|
|
216
|
+
size?: number;
|
|
217
|
+
/** Width over height. Default 1. */
|
|
218
|
+
aspect?: number;
|
|
219
|
+
/** In modules. Default 1. */
|
|
220
|
+
padding?: number;
|
|
221
|
+
/** 0 to 0.5 of the shorter side. Default 0. */
|
|
222
|
+
radius?: number;
|
|
223
|
+
/** Clears the modules under the image. Default true. */
|
|
224
|
+
excavate?: boolean;
|
|
225
|
+
opacity?: number;
|
|
226
|
+
crossOrigin?: CrossOrigin;
|
|
227
|
+
}
|
|
228
|
+
interface CaptionOptions {
|
|
229
|
+
text: string;
|
|
230
|
+
position?: 'top' | 'bottom';
|
|
231
|
+
/** In modules. Default 2. */
|
|
232
|
+
fontSize?: number;
|
|
233
|
+
/** Default 'system-ui, sans-serif'. */
|
|
234
|
+
fontFamily?: string;
|
|
235
|
+
fontWeight?: string | number;
|
|
236
|
+
/** Default fg. */
|
|
237
|
+
color?: Paint;
|
|
238
|
+
}
|
|
239
|
+
/** The one options type shared by components, primitives and export. */
|
|
240
|
+
interface QRCodeOptions {
|
|
241
|
+
value: QRValue;
|
|
242
|
+
size?: number;
|
|
243
|
+
level?: Level;
|
|
244
|
+
margin?: number;
|
|
245
|
+
fg?: Paint;
|
|
246
|
+
bg?: Paint;
|
|
247
|
+
modules?: ShapeInput;
|
|
248
|
+
finder?: FinderStyle;
|
|
249
|
+
image?: ImageOptions;
|
|
250
|
+
caption?: CaptionOptions;
|
|
251
|
+
/** One frame, or a stack applied from the inside out: `[border(), banner()]` bands the border. */
|
|
252
|
+
frame?: FramePlugin | readonly FramePlugin[];
|
|
253
|
+
title?: string;
|
|
254
|
+
id?: string;
|
|
255
|
+
encoding?: Omit<EncodeOptions, 'level'>;
|
|
256
|
+
}
|
|
257
|
+
type QRCodeCanvasProps = QRCodeOptions & {
|
|
258
|
+
/** Runs after each draw once the image, if any, has loaded or failed. */
|
|
259
|
+
onReady?: (canvas: HTMLCanvasElement) => void;
|
|
260
|
+
/**
|
|
261
|
+
* Any value; a new value redraws the canvas. Use it when a class or attribute change
|
|
262
|
+
* gives the colours new values, for example a `data-theme` switch.
|
|
263
|
+
*/
|
|
264
|
+
repaint?: unknown;
|
|
265
|
+
/** Milliseconds before the logo load gives up. Default 10000. */
|
|
266
|
+
imageTimeout?: number;
|
|
267
|
+
} & Omit<JSX.CanvasHTMLAttributes<HTMLCanvasElement>, keyof QRCodeOptions | 'width' | 'height'>;
|
|
268
|
+
/**
|
|
269
|
+
* Renders a QR code to a canvas sized for the device pixel ratio.
|
|
270
|
+
* It redraws when `prefers-color-scheme` changes, since CSS colours may depend on it.
|
|
271
|
+
*/
|
|
272
|
+
export declare function QRCodeCanvas(props: QRCodeCanvasProps): JSX.Element;
|
|
273
|
+
type QRCodeSVGProps = QRCodeOptions & Omit<JSX.SvgSVGAttributes<SVGSVGElement>, keyof QRCodeOptions | 'width' | 'height' | 'viewBox'>;
|
|
274
|
+
/** Renders a QR code as inline SVG. The markup matches `sceneToSVGString`. */
|
|
275
|
+
export declare function QRCodeSVG(props: QRCodeSVGProps): JSX.Element;
|
|
276
|
+
type QRCodeProps = (QRCodeSVGProps & {
|
|
277
|
+
renderAs?: 'svg';
|
|
278
|
+
}) | (QRCodeCanvasProps & {
|
|
279
|
+
renderAs: 'canvas';
|
|
280
|
+
});
|
|
281
|
+
/** Renders a QR code with the renderer that `renderAs` names. Default 'svg'. */
|
|
282
|
+
export declare function QRCode(props: QRCodeProps): JSX.Element;
|
|
283
|
+
type ColorScheme = 'light' | 'dark';
|
|
284
|
+
/** Tracks `prefers-color-scheme`. 'light' on the server and where `matchMedia` is missing. */
|
|
285
|
+
export declare function createColorScheme(): Accessor<ColorScheme>;
|
|
286
|
+
/** Tracks `devicePixelRatio`, which changes on zoom or a move to another screen. 1 on the server. */
|
|
287
|
+
export declare function createPixelRatio(): Accessor<number>;
|
|
288
|
+
/**
|
|
289
|
+
* Derives the matrix, geometry and scene from options, which may be a reactive props object.
|
|
290
|
+
* A colour change repaints the scene only; it does not encode or rebuild paths.
|
|
291
|
+
*/
|
|
292
|
+
export declare function createQRCode(options: QRCodeOptions): {
|
|
293
|
+
matrix: Accessor<QRMatrix>;
|
|
294
|
+
geometry: Accessor<Geometry>;
|
|
295
|
+
scene: Accessor<Scene>;
|
|
296
|
+
};
|
|
297
|
+
type Context = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
|
|
298
|
+
interface DrawOptions {
|
|
299
|
+
/** Pixels per scene unit. */
|
|
300
|
+
scale: number;
|
|
301
|
+
image?: CanvasImageSource;
|
|
302
|
+
resolveColor: (color: string) => string;
|
|
303
|
+
}
|
|
304
|
+
/** Paints a scene onto a 2D context. The caller sizes and clears the canvas. */
|
|
305
|
+
export declare function drawScene(ctx: Context, scene: Scene, options: DrawOptions): void;
|
|
306
|
+
/**
|
|
307
|
+
* Replaces var() and currentColor in every paint, for output that has no page CSS.
|
|
308
|
+
* With `el`, they resolve against it, as on a canvas drawn there. A detached `el` is ignored.
|
|
309
|
+
*/
|
|
310
|
+
export declare function resolveSceneColors(scene: Scene, el?: Element): Scene;
|
|
311
|
+
/** Serialises a scene to a standalone SVG document string. */
|
|
312
|
+
export declare function sceneToSVGString(scene: Scene, options: {
|
|
313
|
+
size: number;
|
|
314
|
+
idPrefix: string;
|
|
315
|
+
title?: string;
|
|
316
|
+
}): string;
|
|
317
|
+
type AnyCanvas = HTMLCanvasElement | OffscreenCanvas;
|
|
318
|
+
type ExportOptions = QRCodeOptions & {
|
|
319
|
+
/** Milliseconds before the logo load gives up, in the DOM and in a fetch. Default 10000. */
|
|
320
|
+
imageTimeout?: number;
|
|
321
|
+
/**
|
|
322
|
+
* Largest logo in bytes. Default 2 MB. Applies only to a fetch (a worker raster or an
|
|
323
|
+
* embedded SVG logo): in the DOM, the browser loads the image itself.
|
|
324
|
+
*/
|
|
325
|
+
imageMaxBytes?: number;
|
|
326
|
+
/**
|
|
327
|
+
* Resolves `var()` and `currentColor` against this element, as `QRCodeCanvas` does.
|
|
328
|
+
* A detached element is ignored.
|
|
329
|
+
* Without it they take their `var()` fallback, or black.
|
|
330
|
+
*/
|
|
331
|
+
element?: Element;
|
|
332
|
+
};
|
|
333
|
+
type RasterOptions = ExportOptions & {
|
|
334
|
+
/** Pixels per CSS pixel of `size`. Default 1. */
|
|
335
|
+
scale?: number;
|
|
336
|
+
};
|
|
337
|
+
/** The scene `createQRCode` derives, computed once without Solid. */
|
|
338
|
+
export declare function toScene(options: QRCodeOptions): Scene;
|
|
339
|
+
/**
|
|
340
|
+
* A standalone SVG document. Ids start with `options.id`, else `qr`.
|
|
341
|
+
* `resolveColors` replaces var() and currentColor, for files that have no page CSS.
|
|
342
|
+
* `element` then resolves them against a mounted element; a detached one is ignored.
|
|
343
|
+
*/
|
|
344
|
+
export declare function toSVGString(options: QRCodeOptions & {
|
|
345
|
+
resolveColors?: boolean;
|
|
346
|
+
element?: Element;
|
|
347
|
+
}): string;
|
|
348
|
+
/** Draws the code onto `canvas`, or onto a new canvas, preferring OffscreenCanvas. */
|
|
349
|
+
export declare function toCanvas(options: RasterOptions, canvas?: AnyCanvas): Promise<AnyCanvas>;
|
|
350
|
+
/** A PNG of the code. Rejects with a SecurityError when a cross-origin image taints it. */
|
|
351
|
+
export declare function toPNGBlob(options: RasterOptions): Promise<Blob>;
|
|
352
|
+
/**
|
|
353
|
+
* A data URL of the code as PNG or SVG. SVG colours are resolved: a data URL has no page CSS.
|
|
354
|
+
* The SVG embeds the logo as a data URL, or keeps its URL when the fetch fails.
|
|
355
|
+
*/
|
|
356
|
+
export declare function toDataURL(options: RasterOptions, type?: 'image/png' | 'image/svg+xml'): Promise<string>;
|
|
357
|
+
/** Saves the code as a file. A `.svg` filename saves SVG with the logo embedded, any other saves PNG. */
|
|
358
|
+
export declare function download(options: RasterOptions, filename?: string): Promise<void>;
|
|
359
|
+
export declare function copyToClipboard(options: RasterOptions): Promise<void>;
|
|
360
|
+
/** Square modules, merged into one subpath per horizontal run. */
|
|
361
|
+
export declare const square: Shape;
|
|
362
|
+
export declare const dots: Shape;
|
|
363
|
+
export declare const diamond: Shape;
|
|
364
|
+
/** A corner is round only when both orthogonal neighbours on that side are not drawn. */
|
|
365
|
+
export declare const rounded: Shape;
|
|
366
|
+
export declare const verticalBars: Shape;
|
|
367
|
+
export declare const horizontalBars: Shape;
|
|
368
|
+
/** A ring of `width` modules around the code. Default colour is fg. */
|
|
369
|
+
export declare function border(o?: {
|
|
370
|
+
width?: number;
|
|
371
|
+
radius?: number;
|
|
372
|
+
color?: Paint;
|
|
373
|
+
}): FramePlugin;
|
|
374
|
+
/** A rounded panel `padding` modules wider than the code on every side. */
|
|
375
|
+
export declare function card(o?: {
|
|
376
|
+
padding?: number;
|
|
377
|
+
radius?: number;
|
|
378
|
+
color?: Paint;
|
|
379
|
+
}): FramePlugin;
|
|
380
|
+
/**
|
|
381
|
+
* A band with a label above or below the code, outside its quiet zone.
|
|
382
|
+
* Long text shrinks to fit the width, down to 1 module, and the band shrinks with it.
|
|
383
|
+
*/
|
|
384
|
+
export declare function banner(o: {
|
|
385
|
+
text: string;
|
|
386
|
+
position?: 'top' | 'bottom';
|
|
387
|
+
color?: Paint;
|
|
388
|
+
textColor?: Paint;
|
|
389
|
+
fontSize?: number;
|
|
390
|
+
}): FramePlugin;
|
|
391
|
+
/** Outer presets are two subpaths (contour + hole); the layer fills with `evenodd`. */
|
|
392
|
+
export declare const finderOuter: Record<FinderOuterName, FinderPart>;
|
|
393
|
+
export declare const finderInner: Record<FinderInnerName, FinderPart>;
|
|
394
|
+
type FinderParts = {
|
|
395
|
+
outer: FinderPart;
|
|
396
|
+
inner: FinderPart;
|
|
397
|
+
};
|
|
398
|
+
export declare function getFinder(style: FinderStyle): FinderParts;
|
|
399
|
+
export type { CaptionOptions, ColorScheme, CrossOrigin, Design, DrawOptions, EncodeOptions, FinderInnerName, FinderOuterName, FinderPart, FinderParts, FinderStyle, FramePlugin, Geometry, Gradient, GradientStop, ImageOptions, Layer, LayerContext, Layout, Level, ModuleContext, Paint, PaintKey, Paints, PlacedPaint, QRCodeCanvasProps, QRCodeOptions, QRCodeProps, QRCodeSVGProps, QRMatrix, QRValue, Scene, SceneImage, SceneText, Shape, ShapeInput };
|