qr-code-styling-node 1.12.0 → 1.13.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.
@@ -0,0 +1,7 @@
1
+ import { RequiredOptions } from "../core/QROptions";
2
+ import { PluginArea, PluginDrawContext } from "../types";
3
+ /** Lets each plugin's configure() adjust the options, in order. */
4
+ export declare function configurePlugins(options: RequiredOptions): RequiredOptions;
5
+ /** Where the code is drawn in the output, frames included. */
6
+ export declare function getPluginArea(options: RequiredOptions, count: number): PluginArea;
7
+ export declare function runAfterDraw(options: RequiredOptions, draw: Omit<PluginDrawContext, "options">): Promise<void>;
@@ -162,6 +162,8 @@ export type Options = {
162
162
  */
163
163
  shape?: ShapeType;
164
164
  /** SVG output only. */
165
+ /** Plugins that adjust options and draw on top of the code. See QRPlugin. */
166
+ plugins?: QRPlugin[];
165
167
  svgOptions?: {
166
168
  /** Draw all dots as one path instead of one element per module: smaller files, faster rendering. Default false. */
167
169
  mergePaths?: boolean;
@@ -260,4 +262,38 @@ export type RotateFigureArgsCanvas = RotateFigureArgs & {
260
262
  context: CanvasRenderingContext2D;
261
263
  };
262
264
  export type GetNeighbor = (x: number, y: number) => boolean;
265
+ /** Where the code (without margin and frame) is drawn in the output, in pixels. */
266
+ export interface PluginArea {
267
+ x: number;
268
+ y: number;
269
+ /** Width and height of the code. */
270
+ size: number;
271
+ /** Size of one module. */
272
+ dotSize: number;
273
+ /** Modules across. */
274
+ count: number;
275
+ }
276
+ export interface PluginDrawContext {
277
+ type: DrawType;
278
+ options: Options;
279
+ area: PluginArea;
280
+ width: number;
281
+ height: number;
282
+ /** Canvas output: the 2D context to draw on. */
283
+ context?: CanvasRenderingContext2D;
284
+ /** SVG output: the root <svg> element, and the document to create elements with. */
285
+ svg?: SVGElement;
286
+ document?: Document;
287
+ }
288
+ /**
289
+ * A plugin. Both hooks are optional.
290
+ * - configure(options): return option changes to merge in before drawing (called again on every update, so
291
+ * return the same changes for the same options).
292
+ * - afterDraw(draw): draw extra things on top, on the canvas context or into the SVG.
293
+ */
294
+ export interface QRPlugin {
295
+ name?: string;
296
+ configure?: (options: Options) => Partial<Options> | void;
297
+ afterDraw?: (draw: PluginDrawContext) => void | Promise<void>;
298
+ }
263
299
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qr-code-styling-node",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Style your QR codes: dots, corners, gradients and a logo. Works in the browser and on Node.js.",
5
5
  "keywords": [
6
6
  "qr",