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