@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
package/docs/examples.md CHANGED
@@ -156,8 +156,6 @@ The builder pattern provides a fluent way to configure QR codes, often starting
156
156
 
157
157
  **Example 1: Using `useTemplate` with a Predefined Template ('rounded')**
158
158
 
159
- ```javascript
160
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
161
159
 
162
160
  const qrFromTemplate = QRCodeJs.useTemplate('rounded') // Start builder with 'rounded' template
163
161
  .options({ data: 'Uses the rounded template via builder' }) // Add data
@@ -167,8 +165,6 @@ qrFromTemplate.append(document.getElementById('template-rounded-container'));
167
165
 
168
166
  **Example 2: Using `useTemplate` with a Custom Template Object**
169
167
 
170
- ```javascript
171
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
172
168
 
173
169
  const myCustomTemplate = {
174
170
  dotsOptions: { type: 'classy', color: '#8A2BE2' }, // BlueViolet classy dots
@@ -186,8 +182,6 @@ qrCustomTemplate.append(document.getElementById('template-custom-container'));
186
182
 
187
183
  **Example 3: Using `useStyle`**
188
184
 
189
- ```javascript
190
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
191
185
 
192
186
  const myStyle = {
193
187
  dotsOptions: { type: 'dots', color: '#FF4500' }, // OrangeRed dots
@@ -203,8 +197,6 @@ qrFromStyle.append(document.getElementById('style-container'));
203
197
 
204
198
  **Example 4: Chaining `useTemplate` and `useStyle`**
205
199
 
206
- ```javascript
207
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
208
200
 
209
201
  // Start with 'dots' template (black dots), then apply a style to change color
210
202
  const qrChained = QRCodeJs.useTemplate('dots')
@@ -225,8 +217,6 @@ Demonstrating fundamental settings like data, shape, and error correction.
225
217
 
226
218
  **Example 1: Minimal QR Code**
227
219
 
228
- ```javascript
229
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
230
220
  const qrMinimal = new QRCodeJs({
231
221
  data: 'Just the data!'
232
222
  });
@@ -235,8 +225,6 @@ qrMinimal.append(document.getElementById('minimal-qr-container'));
235
225
 
236
226
  **Example 2: Circle Shape**
237
227
 
238
- ```javascript
239
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
240
228
  const qrCircle = new QRCodeJs({
241
229
  data: 'https://example.com/circle',
242
230
  shape: 'circle' // Make the QR code boundary circular
@@ -246,8 +234,6 @@ qrCircle.append(document.getElementById('circle-qr-container'));
246
234
 
247
235
  **Example 3: High Error Correction**
248
236
 
249
- ```javascript
250
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
251
237
  const qrHighEC = new QRCodeJs({
252
238
  data: 'Important Data',
253
239
  qrOptions: {
@@ -265,8 +251,6 @@ Controlling margin, scale, and offsets.
265
251
 
266
252
  **Example 1: Adding Margin**
267
253
 
268
- ```javascript
269
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
270
254
  const qrMargin = new QRCodeJs({
271
255
  data: 'With Margin',
272
256
  margin: 20 // Add a 20px quiet zone around the QR code
@@ -276,8 +260,6 @@ qrMargin.append(document.getElementById('margin-qr-container'));
276
260
 
277
261
  **Example 2: Scaling Down**
278
262
 
279
- ```javascript
280
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
281
263
  const qrScaled = new QRCodeJs({
282
264
  data: 'Scaled Down',
283
265
  scale: 0.8 // Make the QR code 80% of its container/border size
@@ -293,8 +275,6 @@ Changing the appearance of the data dots.
293
275
 
294
276
  **Example 1: Rounded Dots**
295
277
 
296
- ```javascript
297
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
298
278
  const qrRoundedDots = new QRCodeJs({
299
279
  data: 'Rounded Dots',
300
280
  dotsOptions: {
@@ -307,8 +287,6 @@ qrRoundedDots.append(document.getElementById('rounded-dots-container'));
307
287
 
308
288
  **Example 2: Dot Style Dots**
309
289
 
310
- ```javascript
311
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
312
290
  const qrDotDots = new QRCodeJs({
313
291
  data: 'Dot Style Dots',
314
292
  dotsOptions: {
@@ -325,8 +303,6 @@ qrDotDots.append(document.getElementById('dot-dots-container'));
325
303
 
326
304
  Customizing the large corner squares.
327
305
 
328
- ```javascript
329
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
330
306
  const qrStyledCorners = new QRCodeJs({
331
307
  data: 'Styled Corners',
332
308
  dotsOptions: { color: '#333' }, // Standard dots
@@ -344,8 +320,6 @@ qrStyledCorners.append(document.getElementById('styled-corners-container'));
344
320
 
345
321
  Customizing the small dots inside the corner squares.
346
322
 
347
- ```javascript
348
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
349
323
  const qrStyledCornerDots = new QRCodeJs({
350
324
  data: 'Styled Corner Dots',
351
325
  dotsOptions: { color: '#4CAF50' }, // Green dots
@@ -366,8 +340,6 @@ Modifying the background color and shape.
366
340
 
367
341
  **Example 1: Colored Background**
368
342
 
369
- ```javascript
370
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
371
343
  const qrColoredBg = new QRCodeJs({
372
344
  data: 'Colored Background',
373
345
  dotsOptions: { color: '#FFFFFF' }, // White dots for contrast
@@ -380,8 +352,6 @@ qrColoredBg.append(document.getElementById('colored-bg-container'));
380
352
 
381
353
  **Example 2: Rounded Background**
382
354
 
383
- ```javascript
384
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
385
355
  const qrRoundedBg = new QRCodeJs({
386
356
  data: 'Rounded Background',
387
357
  backgroundOptions: {
@@ -395,7 +365,6 @@ qrRoundedBg.append(document.getElementById('rounded-bg-container'));
395
365
  **Example 3: Transparent Background**
396
366
 
397
367
  ```javascript
398
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
399
368
  const qrTransparentBg = new QRCodeJs({
400
369
  data: 'Transparent Background',
401
370
  backgroundOptions: false // Disable the background element
@@ -412,7 +381,6 @@ Applying simple gradients.
412
381
  **Example 1: Linear Gradient on Dots**
413
382
 
414
383
  ```javascript
415
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
416
384
  const qrGradientDots = new QRCodeJs({
417
385
  data: 'Gradient Dots',
418
386
  dotsOptions: {
@@ -433,7 +401,6 @@ qrGradientDots.append(document.getElementById('gradient-dots-container'));
433
401
  **Example 2: Radial Gradient on Background**
434
402
 
435
403
  ```javascript
436
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
437
404
  const qrGradientBg = new QRCodeJs({
438
405
  data: 'Gradient Background',
439
406
  backgroundOptions: {
@@ -455,8 +422,6 @@ qrGradientBg.append(document.getElementById('gradient-bg-container'));
455
422
 
456
423
  Adding a simple logo.
457
424
 
458
- ```javascript
459
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
460
425
  const qrWithLogo = new QRCodeJs({
461
426
  data: 'QR with Logo',
462
427
  qrOptions: { errorCorrectionLevel: 'Q' }, // Use Q or H with images
@@ -469,14 +434,82 @@ const qrWithLogo = new QRCodeJs({
469
434
  qrWithLogo.append(document.getElementById('logo-qr-container'));
470
435
  ```
471
436
 
437
+ **Example: Setting a Global Default Image with `setImage`**
438
+
439
+ ```javascript
440
+ // Set a default logo for all subsequent QR codes use url or data url
441
+ QRCodeJs.setImage('https://example.com/default-logo.png');
442
+
443
+ const qrWithGlobalImage = new QRCodeJs({
444
+ data: 'This QR uses the global default image'
445
+ });
446
+ qrWithGlobalImage.append(document.getElementById('global-image-container'));
447
+
448
+ // Override the global image for a specific instance
449
+ const qrOverrideGlobalImage = new QRCodeJs({
450
+ data: 'This QR overrides the global image',
451
+ image: 'https://example.com/another-logo.png'
452
+ });
453
+ qrOverrideGlobalImage.append(document.getElementById('override-global-image-container'));
454
+
455
+ // Clear the global image
456
+ // QRCodeJs.setImage(null);
457
+ ```
458
+
459
+ **Example: Using the Builder Pattern with `useImage`**
460
+
461
+ ```javascript
462
+ const qrBuiltWithImage = QRCodeJs.useImage('https://example.com/builder-logo.png')
463
+ .options({
464
+ data: 'This QR was built with a specific image via useImage',
465
+ qrOptions: { errorCorrectionLevel: 'Q' }
466
+ });
467
+ qrBuiltWithImage.append(document.getElementById('builder-image-container'));
468
+
469
+ // Combining with other builder methods
470
+ const qrCombinedBuilderImage = QRCodeJs.useTemplate('rounded')
471
+ .useImage('https://example.com/combined-builder-logo.png')
472
+ .useStyle({ dotsOptions: { color: 'green' } })
473
+ .options({
474
+ data: 'Combined builder methods with useImage'
475
+ });
476
+ qrCombinedBuilderImage.append(document.getElementById('combined-builder-image-container'));
477
+ ```
478
+
479
+ **Example: Using Override Option with Images**
480
+
481
+ ```javascript
482
+ // The override option ensures this image takes precedence over any other image
483
+ // settings, even those specified in the instance options
484
+ const qrWithOverrideImage = QRCodeJs.useImage('https://example.com/priority-logo.png', { override: true })
485
+ .options({
486
+ data: 'Image with override',
487
+ // This image will be ignored because of the override option
488
+ image: 'https://example.com/ignored-image.png',
489
+ dotsOptions: { color: '#333333' }
490
+ });
491
+ qrWithOverrideImage.append(document.getElementById('override-image-container'));
492
+
493
+ // Global image with override
494
+ QRCodeJs.setImage('https://example.com/global-priority.png', { override: true });
495
+
496
+ // This instance will use the global priority image despite specifying another image
497
+ const qrWithGlobalOverride = new QRCodeJs({
498
+ data: 'Global image override example',
499
+ image: 'https://example.com/will-be-ignored.png' // Ignored due to global override
500
+ });
501
+ qrWithGlobalOverride.append(document.getElementById('global-override-container'));
502
+
503
+ // Clear the global image when done
504
+ QRCodeJs.setImage(null);
505
+ ```
506
+
472
507
  ---
473
508
 
474
509
  ### Border Options (Free Version)
475
510
 
476
511
  Adding a basic border (includes "QR-Platform" branding).
477
512
 
478
- ```javascript
479
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
480
513
  const qrFreeBorder = new QRCodeJs({
481
514
  data: 'Free Border Example',
482
515
  borderOptions: {
@@ -489,6 +522,96 @@ const qrFreeBorder = new QRCodeJs({
489
522
  });
490
523
  qrFreeBorder.append(document.getElementById('free-border-container'));
491
524
  ```
525
+ **Example: Setting a Global Default Border**
526
+
527
+
528
+ // Set a default border configuration by name
529
+ QRCodeJs.setBorder('basic-thin'); // Assumes 'basic-thin' is a predefined border template
530
+
531
+ // This instance will use the 'basic-thin' border
532
+ const qrWithDefaultBorder = new QRCodeJs({
533
+ data: 'Uses default border'
534
+ });
535
+ qrWithDefaultBorder.append(document.getElementById('default-border-container'));
536
+
537
+ // You can also set by ID or with an options object:
538
+ // QRCodeJs.setBorderId('border-id-example');
539
+ // QRCodeJs.setBorder({ hasBorder: true, thickness: 10, color: 'red' });
540
+ ```
541
+
542
+ **Example: Using the Builder Pattern for Borders**
543
+
544
+
545
+ // Start the builder with a border configuration by name
546
+ const qrBuiltWithBorder = QRCodeJs.useBorder('basic-curved') // Assumes 'basic-curved' is predefined
547
+ .options({
548
+ data: 'Built with border'
549
+ });
550
+ qrBuiltWithBorder.append(document.getElementById('builder-border-container'));
551
+
552
+ // Start the builder with a border configuration by ID
553
+ const qrBuiltWithBorderId = QRCodeJs.useBorderId('border-id-example') // Assumes 'border-id-example' is predefined
554
+ .options({
555
+ data: 'Built with border ID'
556
+ });
557
+ qrBuiltWithBorderId.append(document.getElementById('builder-border-id-container'));
558
+ ```
559
+
560
+ **Example: Using Text in Borders with Override Option (Premium Feature)**
561
+
562
+ ```javascript
563
+ // Ensure license is activated first for premium border features
564
+ // await QRCodeJs.license('YOUR-LICENSE-KEY');
565
+
566
+ // Setting text that will override any text specified in borderOptions
567
+ QRCodeJs.setText({
568
+ topValue: 'TOP PRIORITY TEXT',
569
+ bottomValue: 'BOTTOM PRIORITY TEXT'
570
+ }, { override: true });
571
+
572
+ // Even though this instance specifies different text values in the border decorations,
573
+ // the global text with override option will take precedence
574
+ const qrWithTextOverride = new QRCodeJs({
575
+ data: 'Text Override Example',
576
+ borderOptions: {
577
+ hasBorder: true,
578
+ thickness: 30,
579
+ color: '#9C27B0',
580
+ decorations: {
581
+ top: {
582
+ enableText: true,
583
+ value: 'THIS TEXT WILL BE IGNORED' // Ignored due to override
584
+ },
585
+ bottom: {
586
+ enableText: true,
587
+ value: 'THIS WILL ALSO BE IGNORED' // Ignored due to override
588
+ }
589
+ }
590
+ }
591
+ });
592
+ qrWithTextOverride.append(document.getElementById('text-override-container'));
593
+
594
+ // Using the builder pattern with text override
595
+ const qrBuilderWithTextOverride = QRCodeJs.useText({
596
+ leftValue: 'LEFT OVERRIDE',
597
+ rightValue: 'RIGHT OVERRIDE'
598
+ }, { override: true })
599
+ .useBorder('fancy-border') // Assumes this is a predefined border
600
+ .options({
601
+ data: 'Builder Text Override Example',
602
+ borderOptions: {
603
+ decorations: {
604
+ left: { enableText: true, value: 'IGNORED' }, // Ignored due to override
605
+ right: { enableText: true, value: 'ALSO IGNORED' } // Ignored due to override
606
+ }
607
+ }
608
+ });
609
+ qrBuilderWithTextOverride.append(document.getElementById('builder-text-override-container'));
610
+
611
+ // Reset global text when done
612
+ QRCodeJs.setText(null);
613
+ ```
614
+
492
615
  *For custom border text and advanced features like inner/outer borders, a [Premium License](./license-management.md#start) is required.*
493
616
 
494
617
  ---
@@ -91,7 +91,7 @@ When using the basic border features in the free version, the library will autom
91
91
  - **Type**: `function(licenseKey: string): Promise<ValidationResult>`
92
92
  - **Process**:
93
93
  1. Calls `QRCodeJs.license('YOUR-LICENSE-KEY')`
94
- 2. Library sends key to backend endpoint (default: `POST /api/get-token`)
94
+ 2. Library sends key to backend endpoint (default: `POST /api/license/get-token`)
95
95
  3. Backend validates key and returns signed JWT
96
96
  4. Library validates JWT signature and expiration date
97
97
  5. If valid, token and key are stored
@@ -192,7 +192,7 @@ When using the basic border features in the free version, the library will autom
192
192
 
193
193
  - **Purpose**: Configure the endpoint for license key validation
194
194
  - **Type**: `function(url: string): typeof QRCodeJs`
195
- - **Default**: `/api/get-token`
195
+ - **Default**: `/api/license/get-token`
196
196
  - **Important**: Must be called before `QRCodeJs.license()`
197
197
  - **Returns**: `QRCodeJs` class for chaining
198
198
  - **Example**:
@@ -202,7 +202,7 @@ When using the basic border features in the free version, the library will autom
202
202
  ```
203
203
  - **Example** (chaining):
204
204
  ```typescript
205
- await QRCodeJs.setLicenseUrl('/my-api/get-license').license('YOUR-LICENSE-KEY');
205
+ await QRCodeJs.setLicenseUrl('/my-api/license/get-token').license('YOUR-LICENSE-KEY');
206
206
  ```
207
207
 
208
208
  ### Custom License Fetcher
@@ -334,7 +334,7 @@ async function activateWithTokenNode(token) {
334
334
 
335
335
  ### Endpoint
336
336
 
337
- - **Default Path**: `/api/get-token`
337
+ - **Default Path**: `/api/license/get-token`
338
338
  - **Method**: `POST`
339
339
  - **Content-Type**: `application/json`
340
340
 
@@ -55,8 +55,8 @@ interface Options {
55
55
  /** Options for styling the background. Set to false to disable. */
56
56
  backgroundOptions?: BackgroundOptions | false;
57
57
 
58
- /** URL, Buffer, or Blob of an image to embed in the QR code. */
59
- image?: string | Buffer | Blob;
58
+ /** URL, Buffer, or Blob of an image to embed in the QR code. Can be influenced by `QRCodeJs.setImage()` or `QRCodeJs.useImage()`. */
59
+ image?: string | DataURL | Buffer | Blob;
60
60
 
61
61
  /** Options for the embedded image. */
62
62
  imageOptions: ImageOptions;
@@ -278,6 +278,8 @@ const qrCodeWithGradient = new QRCodeJs({
278
278
  | `imageOptions.fill.color` | `string` | `'rgba(255,255,255,1)'` | Fill color for transparent areas. |
279
279
  | `imageOptions.fill.gradient`| `Gradient` object | `undefined` | Apply a gradient fill to transparent areas. See [Gradients](#gradients) for configuration details. |
280
280
 
281
+ **Note on Image Source:** The `image` can be specified directly in the options, set globally for subsequent instances using `QRCodeJs.setImage('your_image_url')`, or set for a specific builder chain using `QRCodeJs.useImage('your_image_url').options(...)`. The builder's `useImage` typically overrides the global `setImage`, which in turn overrides an image set by a template. Direct options in the constructor or `.options()` call provide the final override.
282
+
281
283
  **`ImageMode` Enum Values:** `center`, `overlay`, `background`.
282
284
 
283
285
  **Important Considerations:**
@@ -515,76 +517,104 @@ if (validationResult.isValid) {
515
517
  - **`QRCodeJs.configureLicenseFetcher(fetcher: (licenseKey: string) => Promise<string>): void`**
516
518
  Configures a custom function for fetching license tokens.
517
519
 
520
+ - **`QRCodeJs.setTemplate(templateNameOrOptions: string | RecursivePartial<Options>): void`**
521
+ Sets a global default template (by name or options object) for subsequent instances.
522
+
523
+ - **`QRCodeJs.setTemplateId(templateId: string): void`**
524
+ Sets a global default template by its ID.
525
+
526
+ - **`QRCodeJs.setStyle(styleNameOrOptions: string | StyleOptions): void`**
527
+ Sets a global default style (by name or options object) for subsequent instances.
528
+
529
+ - **`QRCodeJs.setStyleId(styleId: string): void`**
530
+ Sets a global default style by its ID.
531
+
532
+ - **`QRCodeJs.setBorder(borderNameOrOptions: string | RecursivePartial<BorderOptions>): void`**
533
+ Sets a global default border configuration (by name or options object) for subsequent instances.
534
+
535
+ - **`QRCodeJs.setBorderId(borderId: string): void`**
536
+ Sets a global default border configuration by its ID.
537
+
518
538
  - **`QRCodeJs.useTemplate(templateNameOrOptions: string | RecursivePartial<Options>): QRCodeBuilder`**
519
- Creates a `QRCodeBuilder` instance initialized with a specific template.
520
-
521
- ```typescript
522
- // Using a template name
523
- const qrBuilder1 = QRCodeJs.useTemplate('rounded').options({
524
- data: 'Built with rounded template',
525
- dotsOptions: { color: '#FF8C00' } // DarkOrange override
526
- });
527
-
528
- // Using inline options
529
- const qrBuilder2 = QRCodeJs.useTemplate({ shape: 'circle' }).options({
530
- data: 'Built with inline circle shape'
531
- });
532
- ```
539
+ Initiates the builder pattern pre-configured with a template (by name or options object).
540
+
541
+ - **`QRCodeJs.useTemplateId(templateId: string): QRCodeBuilder`**
542
+ Initiates the builder pattern pre-configured with a template by its ID.
533
543
 
534
544
  - **`QRCodeJs.useStyle(styleNameOrOptions: string | StyleOptions): QRCodeBuilder`**
535
- Creates a `QRCodeBuilder` instance initialized with a specific style.
545
+ Initiates the builder pattern pre-configured with a style (by name or options object).
536
546
 
537
- - **`QRCodeJs.setTemplate(templateNameOrOptions: string | RecursivePartial<Options>): void`**
538
- Sets a default template to be used for subsequent `QRCodeJs` instances. This template's options will be merged with the options provided during instantiation, with the instantiation options taking precedence. You can provide either the name of a predefined template (e.g., `'rounded'`, `'dots'`) or a custom options object.
539
-
540
- ```typescript
541
- // Set a predefined template by name
542
- QRCodeJs.setTemplate('rounded');
543
- const qr1 = new QRCodeJs({ data: 'Uses rounded template' });
544
-
545
- // Set a custom template object
546
- const myTemplate = { dotsOptions: { type: 'classy', color: '#AA00AA' } };
547
- QRCodeJs.setTemplate(myTemplate);
548
- const qr2 = new QRCodeJs({ data: 'Uses custom classy template' });
549
-
550
- // Clear the template (falls back to basic)
551
- // @ts-expect-error - Accessing private static for testing/clearing
552
- QRCodeJs._selectedTemplate = null;
553
- const qr3 = new QRCodeJs({ data: 'Uses basic template again' });
554
- ```
547
+ - **`QRCodeJs.useStyleId(styleId: string): QRCodeBuilder`**
548
+ Initiates the builder pattern pre-configured with a style by its ID.
549
+
550
+ - **`QRCodeJs.useBorder(borderNameOrOptions: string | BorderOptions): QRCodeBuilder`**
551
+ Initiates the builder pattern pre-configured with a border configuration (by name or options object).
555
552
 
553
+ - **`QRCodeJs.useBorderId(borderId: string): QRCodeBuilder`**
554
+ Initiates the builder pattern pre-configured with a border configuration by its ID.
556
555
 
556
+ - **`QRCodeJs.setImage(imageUrl: string | DataURL | null): void`**
557
+ Sets a global default image URL for subsequent `QRCodeJs` instances.
557
558
 
559
+ - **`QRCodeJs.useImage(imageUrl: string | DataURL): QRCodeBuilder`**
560
+ Initiates the builder pattern pre-configured with an image URL.
558
561
 
559
- ## Fluent Builder Pattern (`useTemplate`, `useStyle`, `build`)
562
+ ### Setting Global Defaults for Styles, Borders, and Images (`setStyle`, `setBorder`, `setImage`)
563
+
564
+ Similar to `setTemplate`, you can set global defaults for styles, border configurations, and images that will apply to subsequently created instances:
565
+
566
+ - **`QRCodeJs.setStyle(styleNameOrOptions)` / `QRCodeJs.setStyleId(styleId)`**: Sets a default style by name, object, or ID.
567
+ - **`QRCodeJs.setBorder(borderNameOrOptions)` / `QRCodeJs.setBorderId(borderId)`**: Sets a default border configuration by name, object, or ID.
568
+ - **`QRCodeJs.setImage(imageUrl)`**: Sets a default image URL.
569
+
570
+ Options provided directly to the `new QRCodeJs(...)` constructor or via builder methods will override these global defaults for that specific instance.
571
+ ```javascript
572
+ // Example of setting global image
573
+ QRCodeJs.setImage('https://example.com/default-logo.png');
574
+ const qrWithGlobalImage = new QRCodeJs({ data: 'Uses global image' });
575
+ // qrWithGlobalImage will use 'default-logo.png' unless overridden.
576
+ ```
577
+
578
+ ## Fluent Builder Pattern (`useTemplate`, `useStyle`, `useBorder`, `useImage`, `build`)
560
579
 
561
580
  For a more structured and readable configuration process, especially when combining predefined settings with custom overrides, QRCode.js offers a fluent builder pattern.
562
581
 
582
+
563
583
  **How it Works:**
564
584
 
565
- 1. **Start:** Begin by calling `QRCodeJs.useTemplate()` or `QRCodeJs.useStyle()` with either a predefined name (e.g., `'rounded'`) or a custom options/style object. This returns a `QRCodeBuilder` instance.
566
- 2. **Chain (Optional):** Call `.useTemplate()` or `.useStyle()` again on the builder instance to layer additional templates or styles. Options are merged, with later calls overriding earlier ones for the same properties.
585
+ 1. **Start:** Begin by calling `QRCodeJs.useTemplate()`, `QRCodeJs.useStyle()`, `QRCodeJs.useBorder()`, or `QRCodeJs.useImage()` with either a predefined name/ID or a custom options/style/border/image URL object. This returns a `QRCodeBuilder` instance.
586
+ 2. **Chain (Optional):** Call `.useTemplate()`, `.useStyle()`, `.useBorder()`, or `.useImage()` again on the builder instance to layer additional configurations. Options are merged, with later calls overriding earlier ones for the same properties.
567
587
  3. **Finalize:**
568
588
  * Call `.options(yourOptions)` to merge any final, specific options.
569
589
  * Or call `.build()` to create the `QRCodeJs` instance with the accumulated configuration. This is optional if `.options(yourOptions)` is NOT called. If `.options(yourOptions)` is called, calling `.build()` is not necessary. You can use `.update()` after `.build()` to update the data.
570
590
 
571
- **Combining Templates and Styles:**
591
+ **Combining Builder Methods:**
572
592
 
573
- When you chain `useTemplate` and `useStyle`, their options are merged. If both define the same property (e.g., `dotsOptions.color`), the value from the `useStyles` is always applied over the `useTemplate` options (e.g., `dotsOptions.color` from the `useTemplate` is overridden by the `dotsOptions.color` from the `useStyle`).
593
+ When you chain multiple `use...` methods, their options are merged. If different methods define the same property (e.g., `image` from `useImage()` and an image defined in a template via `useTemplate()`), the value from the method called *later* in the chain for that specific property generally takes precedence. The final `.options()` call provides the ultimate override.
574
594
 
575
595
  **Example:**
576
596
 
577
597
  ```typescript
578
- // Start with 'dots' template, override color with a style, add final data
598
+ // Start with 'dots' template, override color with a style, add an image, then final data
579
599
  const qrCode = QRCodeJs.useTemplate('dots') // Base: dots template (e.g., black square dots)
580
600
  .useStyle({ dotsOptions: { color: 'navy' } }) // Style: Change dot color to navy
581
- .options({ data: 'Built with Template and Style' }) // Final data
601
+ .useImage('https://example.com/my-logo.png') // Image: Set a logo
602
+ .options({ data: 'Built with Template, Style, and Image' }) // Final data
582
603
 
583
604
  qrCode.append(document.getElementById('builder-example-container'));
605
+
606
+ ### Builder Pattern for Styles, Borders, and Images (`useStyle`, `useBorder`, `useImage`)
607
+
608
+ The builder pattern fully supports styles, borders, and images:
609
+
610
+ - **`QRCodeJs.useStyle(styleNameOrOptions)` / `QRCodeJs.useStyleId(styleId)`**: Starts the builder pre-configured with a style.
611
+ - **`QRCodeJs.useBorder(borderNameOrOptions)` / `QRCodeJs.useBorderId(borderId)`**: Starts the builder pre-configured with a border configuration.
612
+ - **`QRCodeJs.useImage(imageUrl)`**: Starts the builder pre-configured with an image.
613
+
614
+ You can chain these methods (e.g., `QRCodeJs.useTemplate(...).useStyle(...).useBorder(...).useImage(...)`) before finalizing with `.options(...)` or `.build()`. Options are merged progressively, with later calls overriding earlier ones.
584
615
  ```
585
616
 
586
617
  ## FAQ
587
-
588
618
  ### How do I handle CORS issues with embedded images?
589
619
 
590
620
  Set `crossOrigin` in `imageOptions`:
@@ -0,0 +1,3 @@
1
+ export const SERVICE_ENDPOINT: "https://api.qr-platform.com";
2
+ export const GET_DATAURL_ROUTE: "/v1/utils/get-dataurl?url=";
3
+ export const GET_LICENSE_TOKEN_ROUTE: "/v1/license/get-token";
@@ -1,7 +1,13 @@
1
1
  import { CanvasOptions } from '~/utils/canvas-options';
2
- import { RecursivePartial } from '../types/helper';
2
+ import { MethodOverrideOptions, RecursivePartial } from '../types/helper';
3
3
  import { StyleOptions } from '../types/style-options';
4
- import { Options } from '../utils/options';
4
+ import { QRTextTemplateDefinition, TextOptions } from '../types/text-options';
5
+ import { BorderOptions, Options } from '../utils/options';
6
+ import { findStyleById, findStyleByName, QRStyleDefinition } from './templates/qr-styles';
7
+ import { findBorderById, findBorderByName } from './templates/qr-template-borders';
8
+ import { findTextByName, findTextById as findTextTemplateById } from './templates/qr-template-text';
9
+ import { findTemplateById, findTemplateByName, type QRTemplateDefinition } from './templates/qr-templates';
10
+ export type { QRTemplateDefinition, QRStyleDefinition, QRTextTemplateDefinition, StyleOptions };
5
11
  export declare enum FileExtension {
6
12
  svg = "svg",
7
13
  png = "png",
@@ -13,30 +19,99 @@ export declare class QRCodeJs {
13
19
  /** Library version injected at build time */
14
20
  static version: string;
15
21
  private static _selectedTemplate;
22
+ private static _selectedBorder;
16
23
  private static _selectedStyle;
24
+ private static _selectedImage;
25
+ private static _selectedImageOverride;
26
+ private static _selectedText;
27
+ private static _selectedTextOverride;
17
28
  private options;
18
29
  private container?;
19
30
  private qr?;
20
31
  private extension?;
21
32
  private svgDrawingPromise?;
22
33
  private qrSVG?;
34
+ private _svgId;
23
35
  get size(): {
24
36
  width: number;
25
37
  height: number;
26
38
  } | undefined;
27
39
  constructor(options: RecursivePartial<Options>, _?: boolean);
28
- static setTemplate(templateNameOrOptions: string | RecursivePartial<Options>): typeof QRCodeJs;
40
+ /**
41
+ * Sets the static template to be used as a base for new instances,
42
+ * accepting either a template name or a template options object.
43
+ * @param templateNameOrOptions - The user-friendly name of the template or a partial options object.
44
+ * @returns The QRCodeJs class for chaining.
45
+ */
46
+ static setTemplate(templateNameOrOptions: string | RecursivePartial<Options> | null): typeof QRCodeJs;
47
+ /**
48
+ * Sets the static template to be used as a base for new instances by its ID.
49
+ * @param templateId - The ID of the template (original key).
50
+ * @returns The QRCodeJs class for chaining.
51
+ */
52
+ static setTemplateId(templateId: string | null): typeof QRCodeJs;
53
+ static getTemplates(): {
54
+ findTextTemplateById: typeof findTextTemplateById;
55
+ findTextByName: typeof findTextByName;
56
+ findTemplateByName: typeof findTemplateByName;
57
+ findTemplateById: typeof findTemplateById;
58
+ findBorderById: typeof findBorderById;
59
+ findBorderByName: typeof findBorderByName;
60
+ findStyleById: typeof findStyleById;
61
+ findStyleByName: typeof findStyleByName;
62
+ baseTemplates: QRTemplateDefinition[];
63
+ borderTemplates: QRTemplateDefinition[];
64
+ styleTemplates: QRStyleDefinition[];
65
+ textTemplates: QRTextTemplateDefinition[];
66
+ };
29
67
  /**
30
68
  * Sets the static style to be used as a base for new instances.
31
69
  * Accepts either a predefined style name or a StyleOptions object.
32
70
  * @param styleNameOrOptions - The name of the style or the StyleOptions object.
71
+ * @param styleNameOrOptions - The name of the style or the StyleOptions object.
72
+ * @returns The QRCodeJs class for chaining.
73
+ */
74
+ static setStyle(styleNameOrOptions: string | StyleOptions | null): typeof QRCodeJs;
75
+ /**
76
+ * Sets the static border template to be used as a base for new instances,
77
+ * accepting either a border template name or a BorderOptions object.
78
+ * @param borderNameOrOptions - The user-friendly name of the border template or a BorderOptions object.
79
+ * @returns The QRCodeJs class for chaining.
80
+ */
81
+ static setBorder(borderNameOrOptions: string | RecursivePartial<BorderOptions> | null): typeof QRCodeJs;
82
+ /**
83
+ * Sets the static border template to be used as a base for new instances by its ID.
84
+ * @param borderId - The ID of the border template.
85
+ * @returns The QRCodeJs class for chaining.
86
+ */
87
+ static setBorderId(borderId: string | null): typeof QRCodeJs;
88
+ /**
89
+ * Sets the static style to be used as a base for new instances by its ID.
90
+ * @param styleId - The ID of the style.
91
+ * @returns The QRCodeJs class for chaining.
92
+ */
93
+ static setStyleId(styleId: string | null): typeof QRCodeJs;
94
+ /**
95
+ * Sets the static image URL to be used as a base for new instances.
96
+ * @param imageUrl - The URL of the image or null to clear.
97
+ * @returns The QRCodeJs class for chaining.
98
+ */
99
+ static setImage(imageUrl: string | null, overrideOpts?: MethodOverrideOptions): typeof QRCodeJs;
100
+ /**
101
+ * Sets the static text template or options to be used for new instances.
102
+ * @param textNameOrOptions - The name of the text template, a TextOptions object, or null to clear.
103
+ * @returns The QRCodeJs class for chaining.
104
+ */
105
+ static setText(textNameOrOptions: string | TextOptions | null, overrideOpts?: MethodOverrideOptions): typeof QRCodeJs;
106
+ /**
107
+ * Sets the static text template to be used for new instances by its ID.
108
+ * @param textId - The ID of the text template or null to clear.
33
109
  * @returns The QRCodeJs class for chaining.
34
110
  */
35
- static setStyle(styleNameOrOptions: string | StyleOptions): typeof QRCodeJs;
111
+ static setTextId(textId: string | null, overrideOpts?: MethodOverrideOptions): typeof QRCodeJs;
112
+ getOptions(): Options;
36
113
  update(options?: RecursivePartial<Options>): Promise<void>;
37
- append(
38
- /** This container will be used for appending of the QR code */
39
- container?: HTMLElement): QRCodeJs | undefined;
114
+ append(container?: HTMLElement): this;
40
115
  applyExtension(extension: ExtensionFunction): Promise<void>;
41
116
  deleteExtension(): Promise<void>;
42
117
  serialize(inverted?: boolean): Promise<string | undefined>;