@qr-platform/qr-code.js 0.9.10 → 0.10.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 (62) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -0
  3. package/docs/advanced-examples.md +177 -56
  4. package/docs/api-reference-guide.md +26 -6
  5. package/docs/border-methods-update-plan.md +28 -0
  6. package/docs/border-text-implementation-plan.md +155 -0
  7. package/docs/documentation.md +276 -11
  8. package/docs/examples.md +160 -37
  9. package/docs/license-management.md +4 -4
  10. package/docs/typescript-types-definitions.md +2 -2
  11. package/docs/usage-guide.md +71 -41
  12. package/lib/config/runtime-config.d.ts +3 -0
  13. package/lib/core/qr-code-js.d.ts +82 -7
  14. package/lib/core/qr-options-validation.d.ts +1 -1
  15. package/lib/core/qr-svg.d.ts +3 -1
  16. package/lib/core/templates/qr-styles-dark.d.ts +2 -0
  17. package/lib/core/templates/qr-styles.d.ts +9 -0
  18. package/lib/core/templates/qr-template-borders.d.ts +4 -0
  19. package/lib/core/templates/qr-template-text.d.ts +4 -0
  20. package/lib/core/templates/qr-templates.d.ts +12 -0
  21. package/lib/demo.d.ts +1 -0
  22. package/lib/index.d.ts +135 -21
  23. package/lib/index.js +1 -1
  24. package/lib/license/LicenseManager.d.ts +1 -1
  25. package/lib/node/config/runtime-config.d.ts +3 -0
  26. package/lib/node/core/qr-code-js.d.ts +82 -7
  27. package/lib/node/core/qr-options-validation.d.ts +1 -1
  28. package/lib/node/core/qr-svg.d.ts +3 -1
  29. package/lib/node/core/templates/qr-styles-dark.d.ts +2 -0
  30. package/lib/node/core/templates/qr-styles.d.ts +9 -0
  31. package/lib/node/core/templates/qr-template-borders.d.ts +4 -0
  32. package/lib/node/core/templates/qr-template-text.d.ts +4 -0
  33. package/lib/node/core/templates/qr-templates.d.ts +12 -0
  34. package/lib/node/demo.d.ts +1 -0
  35. package/lib/node/index.d.ts +135 -21
  36. package/lib/node/license/LicenseManager.d.ts +1 -1
  37. package/lib/node/node.d.ts +128 -17
  38. package/lib/node/options-demo.d.ts +2 -239
  39. package/lib/node/templates/scan-validators/tests/cases/colors.d.ts +0 -6
  40. package/lib/node/types/helper.d.ts +3 -0
  41. package/lib/node/types/style-options.d.ts +8 -2
  42. package/lib/node/types/text-options.d.ts +11 -0
  43. package/lib/node/utils/_network-helpers_multi_env.d.ts +16 -0
  44. package/lib/node/utils/gradient.d.ts +2 -1
  45. package/lib/node/utils/network-helpers.d.ts +17 -0
  46. package/lib/node/utils/options.d.ts +26 -21
  47. package/lib/node.d.ts +128 -17
  48. package/lib/node.js +1 -1
  49. package/lib/options-demo.d.ts +2 -239
  50. package/lib/templates/scan-validators/tests/cases/colors.d.ts +0 -6
  51. package/lib/types/helper.d.ts +3 -0
  52. package/lib/types/style-options.d.ts +8 -2
  53. package/lib/types/text-options.d.ts +11 -0
  54. package/lib/utils/_network-helpers_multi_env.d.ts +16 -0
  55. package/lib/utils/gradient.d.ts +2 -1
  56. package/lib/utils/network-helpers.d.ts +17 -0
  57. package/lib/utils/options.d.ts +26 -21
  58. package/package.json +1 -1
  59. package/lib/core/qr-styles.d.ts +0 -4
  60. package/lib/core/qr-templates.d.ts +0 -10
  61. package/lib/node/core/qr-styles.d.ts +0 -4
  62. package/lib/node/core/qr-templates.d.ts +0 -10
@@ -1,5 +1,5 @@
1
1
  import { RecursivePartial } from '../types/helper';
2
- import { Options } from '../utils/options.js';
2
+ import { Options } from '../utils/options';
3
3
  export interface ValidationWarning {
4
4
  path: string;
5
5
  message: string;
@@ -19,6 +19,7 @@ type QRSVGOptions = Pick<Options, 'width' | 'height' | 'isResponsive' | 'margin'
19
19
  };
20
20
  export declare class QRSVG {
21
21
  static instanceCount: number;
22
+ private static readonly FALLBACK_IMAGE_DATA_URL;
22
23
  private _element;
23
24
  private defs;
24
25
  private backgroundMask?;
@@ -53,11 +54,12 @@ export declare class QRSVG {
53
54
  drawBackgroundForBorder(padding: number, baseRadius: number): SVGElement | undefined;
54
55
  drawDots(filter?: (i: number, j: number) => boolean): void;
55
56
  drawCorners(): void;
56
- drawImage({ width, height, count, dotSize }: {
57
+ drawImage({ width, height, count, dotSize, radius }: {
57
58
  width: number;
58
59
  height: number;
59
60
  count: number;
60
61
  dotSize: number;
62
+ radius?: string | number;
61
63
  }): Promise<void>;
62
64
  createColor({ options, borderOptions, color, additionalRotation, x, y, height, width, name, returnSVGGroup }: {
63
65
  options?: Gradient;
@@ -0,0 +1,2 @@
1
+ import { QRStyleDefinition } from './qr-styles';
2
+ export declare const qrStyleDarkDefinitions: QRStyleDefinition[];
@@ -0,0 +1,9 @@
1
+ import { StyleOptions } from '../../types/style-options';
2
+ export interface QRStyleDefinition {
3
+ id: string;
4
+ name: string;
5
+ style: StyleOptions;
6
+ }
7
+ export declare const qrStyleDefinitions: QRStyleDefinition[];
8
+ export declare function findStyleByName(name: string): QRStyleDefinition | undefined;
9
+ export declare function findStyleById(id: string): QRStyleDefinition | undefined;
@@ -0,0 +1,4 @@
1
+ import { QRTemplateDefinition } from './qr-templates';
2
+ export declare const qrBorderTemplates: QRTemplateDefinition[];
3
+ export declare function findBorderByName(name: string): QRTemplateDefinition | undefined;
4
+ export declare function findBorderById(id: string): QRTemplateDefinition | undefined;
@@ -0,0 +1,4 @@
1
+ import { QRTextTemplateDefinition } from '../../types/text-options';
2
+ export declare const qrTextTemplates: QRTextTemplateDefinition[];
3
+ export declare function findTextByName(name: string): QRTextTemplateDefinition | undefined;
4
+ export declare function findTextById(id: string): QRTextTemplateDefinition | undefined;
@@ -0,0 +1,12 @@
1
+ import { type Options } from '~/utils/options';
2
+ import { RecursivePartial } from '~/types/helper';
3
+ export interface QRTemplateDefinition {
4
+ id: string;
5
+ name: string;
6
+ options: RecursivePartial<Options>;
7
+ }
8
+ export declare const baseQRTemplateOptions: RecursivePartial<Options>;
9
+ export declare const qrTemplates: QRTemplateDefinition[];
10
+ export declare function findTemplateByName(name: string): QRTemplateDefinition | undefined;
11
+ export declare function findTemplateById(id: string): QRTemplateDefinition | undefined;
12
+ export declare const baseQRTemplate: QRTemplateDefinition | undefined;
package/lib/demo.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const initializeQRCode: () => Promise<void>;
package/lib/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { QRCodeJs as _QRCodeJs } from './core/qr-code-js';
2
- import { RecursivePartial } from './types/helper';
2
+ import { MethodOverrideOptions, RecursivePartial } from './types/helper';
3
3
  import { StyleOptions } from './types/style-options';
4
- import { Options, type Options as QRCodeJsOptions } from './utils/options';
4
+ import { TextOptions } from './types/text-options';
5
+ import { type Options as _QRCodeJsOptions, type BorderOptions } from './utils/options';
5
6
  import { ScanValidatorResponse } from './utils/scan-validators/abstract-scan-validator';
6
7
  import { type DecodedLicenseToken } from './utils/token-validator';
7
8
  export { ErrorCorrectionLevel, Mode, TypeNumber } from './lib/qrcode/QRCodeMinimal';
@@ -11,9 +12,13 @@ export { type RecursivePartial } from './types/helper';
11
12
  export { type CanvasOptions } from './utils/canvas-options';
12
13
  export { GradientType, type Gradient } from './utils/gradient';
13
14
  export { STORAGE_KEY } from './license/LicenseManager';
14
- export { type BorderOptions, CornerDotType, CornerSquareType, DotType, ImageMode, ShapeType, type Options as QRCodeJsOptions } from './utils/options.js';
15
+ export { type BorderOptions, // Keep exporting the type
16
+ CornerDotType, CornerSquareType, DotType, ImageMode, ShapeType } from './utils/options.js';
17
+ export type Options = RecursivePartial<_QRCodeJsOptions>;
18
+ export type { Options as QRCodeJsOptions };
19
+ type QRCodeJsConstructor = new (options: Options, internal?: boolean) => QRCodeJs;
15
20
  export declare class QRCodeJs extends _QRCodeJs {
16
- constructor(options: RecursivePartial<QRCodeJsOptions>, _?: boolean);
21
+ constructor(options: RecursivePartial<_QRCodeJsOptions>, _?: boolean);
17
22
  protected _hls(): boolean;
18
23
  static initializeIfNeeded(): Promise<boolean>;
19
24
  static get hls(): boolean;
@@ -48,13 +53,19 @@ export declare class QRCodeJs extends _QRCodeJs {
48
53
  validateScanning(_validatorId?: string, // Default validator
49
54
  debug?: boolean): Promise<ScanValidatorResponse>;
50
55
  /**
51
- * Creates a QRCodeBuilder instance initialized with a specific template.
52
- * Allows for fluent configuration chaining. We need it here to avoid circular dependency
53
- * @param templateName - The name of the template to start with.
54
- * @param templateNameOrOptions - The name of the template or a partial options object to start with.
56
+ * Creates a QRCodeBuilder instance initialized with a specific template by its name.
57
+ * Allows for fluent configuration chaining.
58
+ * @param templateName - The user-friendly name of the template to start with.
55
59
  * @returns A new QRCodeBuilder instance.
56
60
  */
57
- static useTemplate(templateNameOrOptions: string | RecursivePartial<Options>): QRCodeBuilder;
61
+ static useTemplate(templateName: string): QRCodeBuilder;
62
+ /**
63
+ * Creates a QRCodeBuilder instance initialized with a specific template by its ID.
64
+ * Allows for fluent configuration chaining.
65
+ * @param templateId - The ID (original key) of the template to start with.
66
+ * @returns A new QRCodeBuilder instance.
67
+ */
68
+ static useTemplateId(templateId: string): QRCodeBuilder;
58
69
  /**
59
70
  * Creates a QRCodeBuilder instance initialized with a specific style.
60
71
  * Allows for fluent configuration chaining.
@@ -62,37 +73,140 @@ export declare class QRCodeJs extends _QRCodeJs {
62
73
  * @returns A new QRCodeBuilder instance.
63
74
  */
64
75
  static useStyle(styleNameOrOptions: string | StyleOptions): QRCodeBuilder;
76
+ /**
77
+ * Creates a QRCodeBuilder instance initialized with a specific style by its ID.
78
+ * Allows for fluent configuration chaining.
79
+ * @param styleId - The ID of the predefined style.
80
+ * @returns A new QRCodeBuilder instance.
81
+ */
82
+ static useStyleId(styleId: string): QRCodeBuilder;
83
+ /**
84
+ * Creates a QRCodeBuilder instance initialized with specific border options.
85
+ * Allows for fluent configuration chaining.
86
+ * @param borderNameOrOptions - The name of the predefined border or a BorderOptions object.
87
+ * @returns A new QRCodeBuilder instance.
88
+ */
89
+ static useBorder(borderNameOrOptions: string | BorderOptions): QRCodeBuilder;
90
+ /**
91
+ * Creates a QRCodeBuilder instance initialized with a specific border by its ID.
92
+ * Allows for fluent configuration chaining.
93
+ * @param borderId - The ID of the predefined border.
94
+ * @returns A new QRCodeBuilder instance.
95
+ */
96
+ static useBorderId(borderId: string): QRCodeBuilder;
97
+ /**
98
+ * Creates a QRCodeBuilder instance initialized with a specific image.
99
+ * Allows for fluent configuration chaining.
100
+ * @param imageUrl - The URL or data URL of the image to use.
101
+ * @returns A new QRCodeBuilder instance.
102
+ */
103
+ static useImage(imageUrl: string, overrideOpts?: MethodOverrideOptions): QRCodeBuilder;
104
+ /**
105
+ * Creates a QRCodeBuilder instance initialized with specific text options.
106
+ * Allows for fluent configuration chaining.
107
+ * @param textNameOrOptions - The name of the predefined text template or a TextOptions object.
108
+ * @returns A new QRCodeBuilder instance.
109
+ */
110
+ static useText(textNameOrOptions: string | TextOptions, overrideOpts?: MethodOverrideOptions): QRCodeBuilder;
111
+ /**
112
+ * Creates a QRCodeBuilder instance initialized with a specific text template by its ID.
113
+ * Allows for fluent configuration chaining.
114
+ * @param textId - The ID of the predefined text template.
115
+ * @returns A new QRCodeBuilder instance.
116
+ */
117
+ static useTextId(textId: string, overrideOpts?: MethodOverrideOptions): QRCodeBuilder;
65
118
  }
66
119
  export declare class _ extends QRCodeJs {
67
120
  protected _hls(): boolean;
68
- constructor(options: QRCodeJsOptions);
121
+ constructor(options: Options);
69
122
  }
70
123
  declare class QRCodeBuilder {
71
- protected config: RecursivePartial<Options>;
124
+ private _qrCodeConstructor;
125
+ protected _templateSource: string | Options | null;
126
+ protected _borderSource: string | BorderOptions | null;
127
+ protected _styleSource: string | StyleOptions | null;
128
+ protected _imageSource: string | null;
129
+ protected _imageOverride: boolean;
130
+ protected _textSource: string | TextOptions | null;
131
+ protected _textOverride: boolean;
132
+ protected _isTemplateById: boolean;
133
+ protected _isBorderById: boolean;
134
+ protected _isStyleById: boolean;
135
+ protected _isTextById: boolean;
136
+ protected _initialOptions: Options | null;
72
137
  /**
73
138
  * Creates a new QRCodeBuilder instance.
139
+ * @param qrCodeConstructor - The constructor function (QRCodeJs or _) to use for the final instance.
74
140
  * @param templateNameOrOptions - Optional name of a predefined template or a partial options object to start with.
75
141
  */
76
- constructor(templateNameOrOptions?: string | RecursivePartial<Options>);
142
+ constructor(qrCodeConstructor: QRCodeJsConstructor, templateNameOrOptions?: string | Options);
77
143
  /**
78
- * Applies a template to the builder's configuration. Template options
79
- * will be overridden by subsequently chained .style() or .options() calls.
80
- * @param templateNameOrOptions - The name of the template or a partial options object to apply.
144
+ * Sets the template to use by its name. Overwrites any previously set template.
145
+ * @param templateName - The user-friendly name of the template to apply.
81
146
  * @returns The builder instance for chaining.
82
147
  */
83
- useTemplate(templateNameOrOptions: string | RecursivePartial<Options>): this;
148
+ useTemplate(templateName: string): this;
84
149
  /**
85
- * Applies style options to the builder's configuration.
86
- * @param styleNameOrOptions - Name of a predefined style or Style options object to apply.
150
+ * Sets the template to use by its ID. Overwrites any previously set template.
151
+ * @param templateId - The ID (original key) of the template to apply.
152
+ * @returns The builder instance for chaining.
153
+ */
154
+ useTemplateId(templateId: string): this;
155
+ /**
156
+ * Sets the style to use by its name or a style options object. Overwrites any previously set style.
157
+ * @param styleNameOrOptions - Name of a predefined style or a StyleOptions object to apply.
87
158
  * @returns The builder instance for chaining.
88
159
  */
89
160
  useStyle(styleNameOrOptions: string | StyleOptions): this;
90
161
  /**
91
- * Merges the provided options into the builder's configuration.
92
- * @param options - A partial options object to merge.
162
+ * Sets the style to use by its ID. Overwrites any previously set style.
163
+ * @param styleId - ID of the predefined style to apply.
164
+ * @returns The builder instance for chaining.
165
+ */
166
+ useStyleId(styleId: string): this;
167
+ /**
168
+ * Sets the border to use by its name or a border options object. Overwrites any previously set border.
169
+ * @param borderNameOrOptions - Name of a predefined border or a BorderOptions object to apply.
170
+ * @returns The builder instance for chaining.
171
+ */
172
+ useBorder(borderNameOrOptions: string | BorderOptions): this;
173
+ /**
174
+ * Sets the border to use by its ID. Overwrites any previously set border.
175
+ * @param borderId - ID of the predefined border to apply.
176
+ * @returns The builder instance for chaining.
177
+ */
178
+ useBorderId(borderId: string): this;
179
+ /**
180
+ * Sets the image to use. Overwrites any previously set image from other sources like templates.
181
+ * @param imageUrl - The URL or data URL of the image to apply.
93
182
  * @returns The builder instance for chaining.
94
183
  */
95
- options(options: RecursivePartial<Options>): QRCodeJs;
184
+ useImage(imageUrl: string, overrideOpts?: MethodOverrideOptions): this;
185
+ /**
186
+ * Sets the text to use by its name or a text options object. Overwrites any previously set text.
187
+ * @param textNameOrOptions - Name of a predefined text template or a TextOptions object to apply.
188
+ * @returns The builder instance for chaining.
189
+ */
190
+ useText(textNameOrOptions: string | TextOptions, overrideOpts?: MethodOverrideOptions): this;
191
+ /**
192
+ * Sets the text to use by its ID. Overwrites any previously set text.
193
+ * @param textId - ID of the predefined text template to apply.
194
+ * @returns The builder instance for chaining.
195
+ */
196
+ useTextId(textId: string, overrideOpts?: MethodOverrideOptions): this;
197
+ /**
198
+ * Resolves the template, border, style, and image sources and merges them in the correct order.
199
+ * Order: Base Template -> Selected Template -> Selected Border -> Selected Text -> Selected Style -> Selected Image -> Final Options
200
+ * @param finalOptions - The final options object passed to .options() or .build().
201
+ * @returns The fully resolved and merged Options object.
202
+ */
203
+ private _resolveAndMergeConfig;
204
+ /**
205
+ * Merges the provided options into the builder's configuration and creates the QRCodeJs instance.
206
+ * @param options - A partial options object to merge as the final step.
207
+ * @returns The created QRCodeJs instance.
208
+ */
209
+ options(options: Options): QRCodeJs;
96
210
  /**
97
211
  * Builds the QRCodeJs instance with the accumulated configuration.
98
212
  * @returns The created QRCodeJs instance.