@qr-platform/qr-code.js 0.9.6 → 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 (64) 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/chunks/scan-validator-worker-nQmPU9X1.js +1 -0
  13. package/lib/config/runtime-config.d.ts +3 -0
  14. package/lib/core/qr-code-js.d.ts +82 -7
  15. package/lib/core/qr-options-validation.d.ts +1 -1
  16. package/lib/core/qr-svg.d.ts +3 -1
  17. package/lib/core/templates/qr-styles-dark.d.ts +2 -0
  18. package/lib/core/templates/qr-styles.d.ts +9 -0
  19. package/lib/core/templates/qr-template-borders.d.ts +4 -0
  20. package/lib/core/templates/qr-template-text.d.ts +4 -0
  21. package/lib/core/templates/qr-templates.d.ts +12 -0
  22. package/lib/demo.d.ts +1 -0
  23. package/lib/index.d.ts +135 -21
  24. package/lib/index.js +1 -1
  25. package/lib/license/LicenseManager.d.ts +1 -1
  26. package/lib/node/config/runtime-config.d.ts +3 -0
  27. package/lib/node/core/qr-code-js.d.ts +82 -7
  28. package/lib/node/core/qr-options-validation.d.ts +1 -1
  29. package/lib/node/core/qr-svg.d.ts +3 -1
  30. package/lib/node/core/templates/qr-styles-dark.d.ts +2 -0
  31. package/lib/node/core/templates/qr-styles.d.ts +9 -0
  32. package/lib/node/core/templates/qr-template-borders.d.ts +4 -0
  33. package/lib/node/core/templates/qr-template-text.d.ts +4 -0
  34. package/lib/node/core/templates/qr-templates.d.ts +12 -0
  35. package/lib/node/demo.d.ts +1 -0
  36. package/lib/node/index.d.ts +135 -21
  37. package/lib/node/license/LicenseManager.d.ts +1 -1
  38. package/lib/node/node.d.ts +128 -17
  39. package/lib/node/options-demo.d.ts +2 -239
  40. package/lib/node/templates/scan-validators/tests/cases/colors.d.ts +0 -6
  41. package/lib/node/types/helper.d.ts +3 -0
  42. package/lib/node/types/style-options.d.ts +8 -2
  43. package/lib/node/types/text-options.d.ts +11 -0
  44. package/lib/node/utils/_network-helpers_multi_env.d.ts +16 -0
  45. package/lib/node/utils/gradient.d.ts +2 -1
  46. package/lib/node/utils/network-helpers.d.ts +17 -0
  47. package/lib/node/utils/options.d.ts +26 -21
  48. package/lib/node.d.ts +128 -17
  49. package/lib/node.js +1 -1
  50. package/lib/options-demo.d.ts +2 -239
  51. package/lib/templates/scan-validators/tests/cases/colors.d.ts +0 -6
  52. package/lib/types/helper.d.ts +3 -0
  53. package/lib/types/style-options.d.ts +8 -2
  54. package/lib/types/text-options.d.ts +11 -0
  55. package/lib/utils/_network-helpers_multi_env.d.ts +16 -0
  56. package/lib/utils/gradient.d.ts +2 -1
  57. package/lib/utils/network-helpers.d.ts +17 -0
  58. package/lib/utils/options.d.ts +26 -21
  59. package/package.json +1 -1
  60. package/lib/chunks/scan-validator-worker-DfdvSWvZ.js +0 -1
  61. package/lib/core/qr-styles.d.ts +0 -4
  62. package/lib/core/qr-templates.d.ts +0 -10
  63. package/lib/node/core/qr-styles.d.ts +0 -4
  64. package/lib/node/core/qr-templates.d.ts +0 -10
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @qr-platform/qr-code-js
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4ec372c: added template and style, text and border combination for qrcode js class
8
+
3
9
  ## 0.9.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -16,6 +16,7 @@ QRCode.js is a professional JavaScript/TypeScript library for creating customize
16
16
  * **Gradients:** Apply linear or radial gradients to dots, corners, and backgrounds.
17
17
  * **Image Embedding:** Embed logos or other images in the center, as an overlay, or as a background.
18
18
  * **Borders (Free & Premium):** Add basic borders (with branding in free version) or advanced, customizable borders with text/images (Premium).
19
+ * **Flexible Border Configuration:** Set global border defaults (`setBorder`/`setBorderId`) or use the builder pattern (`useBorder`/`useBorderId`) for instance-specific borders.
19
20
  * **Flexible Output:** Generate QR codes as SVG elements in the browser or SVG strings in Node.js.
20
21
  * **Download Options:** Download QR codes as SVG, PNG, JPEG, or WEBP.
21
22
  * **TypeScript Support:** Fully typed for a better development experience.
@@ -13,9 +13,7 @@ These examples focus on the fundamental QR code generation settings.
13
13
 
14
14
  **Example 1: High Error Correction & Specific Type Number**
15
15
 
16
- ```typescript
17
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
18
- const qrCoreHighEC = new QRCodeJs({
16
+ ```typescriptconst qrCoreHighEC = new QRCodeJs({
19
17
  data: 'https://example.com/high-ec',
20
18
  qrOptions: {
21
19
  typeNumber: 10, // Larger QR code version
@@ -30,9 +28,7 @@ qrCoreHighEC.append(document.getElementById('core-high-ec-container'));
30
28
 
31
29
  **Example 2: Auto Type Number & Medium Error Correction**
32
30
 
33
- ```typescript
34
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
35
- const qrCoreAutoEC = new QRCodeJs({
31
+ ```typescriptconst qrCoreAutoEC = new QRCodeJs({
36
32
  data: 'https://example.com/auto-ec-medium',
37
33
  qrOptions: {
38
34
  typeNumber: 0, // Auto-detect size
@@ -53,9 +49,7 @@ Demonstrates how to control the positioning and scaling within the container or
53
49
 
54
50
  **Example 1: Scaled Down with Offsets**
55
51
 
56
- ```typescript
57
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
58
- const qrLayoutScaledOffset = new QRCodeJs({
52
+ ```typescriptconst qrLayoutScaledOffset = new QRCodeJs({
59
53
  data: 'https://example.com/layout-scaled-offset',
60
54
  scale: 0.75, // QR code occupies 75% of the space
61
55
  offset: -15, // Moves QR code 15px up relative to center
@@ -73,9 +67,7 @@ qrLayoutScaledOffset.append(document.getElementById('layout-scaled-offset-contai
73
67
 
74
68
  **Example 2: Responsive QR Code**
75
69
 
76
- ```typescript
77
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
78
- const qrLayoutResponsive = new QRCodeJs({
70
+ ```typescriptconst qrLayoutResponsive = new QRCodeJs({
79
71
  data: 'https://example.com/layout-responsive',
80
72
  isResponsive: true, // SVG will resize with container
81
73
  margin: 10, // Add a 10px quiet zone
@@ -100,9 +92,7 @@ Showcases different shapes and colors for the main data dots.
100
92
 
101
93
  **Example 1: Classy Rounded Dots**
102
94
 
103
- ```typescript
104
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
105
- const qrDotsClassy = new QRCodeJs({
95
+ ```typescriptconst qrDotsClassy = new QRCodeJs({
106
96
  data: 'https://example.com/dots-classy',
107
97
  dotsOptions: {
108
98
  type: 'classyRounded',
@@ -115,9 +105,7 @@ qrDotsClassy.append(document.getElementById('dots-classy-container'));
115
105
 
116
106
  **Example 2: Star Dots**
117
107
 
118
- ```typescript
119
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
120
- const qrDotsStar = new QRCodeJs({
108
+ ```typescriptconst qrDotsStar = new QRCodeJs({
121
109
  data: 'https://example.com/dots-star',
122
110
  dotsOptions: {
123
111
  type: 'star',
@@ -130,9 +118,7 @@ qrDotsStar.append(document.getElementById('dots-star-container'));
130
118
 
131
119
  **Example 3: Diamond Dots**
132
120
 
133
- ```typescript
134
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
135
- const qrDotsDiamond = new QRCodeJs({
121
+ ```typescriptconst qrDotsDiamond = new QRCodeJs({
136
122
  data: 'https://example.com/dots-diamond',
137
123
  dotsOptions: {
138
124
  type: 'diamond',
@@ -151,9 +137,7 @@ Customizes the three large corner squares.
151
137
 
152
138
  **Example 1: Outpoint Corner Squares**
153
139
 
154
- ```typescript
155
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
156
- const qrCornerSquareOutpoint = new QRCodeJs({
140
+ ```typescriptconst qrCornerSquareOutpoint = new QRCodeJs({
157
141
  data: 'https://example.com/corner-square-outpoint',
158
142
  dotsOptions: { color: '#444' },
159
143
  cornersSquareOptions: {
@@ -166,9 +150,7 @@ qrCornerSquareOutpoint.append(document.getElementById('corner-square-outpoint-co
166
150
 
167
151
  **Example 2: Rounded Corner Squares**
168
152
 
169
- ```typescript
170
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
171
- const qrCornerSquareRounded = new QRCodeJs({
153
+ ```typescriptconst qrCornerSquareRounded = new QRCodeJs({
172
154
  data: 'https://example.com/corner-square-rounded',
173
155
  dotsOptions: { type: 'dot', color: '#7B1FA2' }, // Purple dots
174
156
  cornersSquareOptions: {
@@ -187,9 +169,7 @@ Customizes the smaller dots within the corner squares.
187
169
 
188
170
  **Example 1: Heart Corner Dots**
189
171
 
190
- ```typescript
191
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
192
- const qrCornerDotHeart = new QRCodeJs({
172
+ ```typescriptconst qrCornerDotHeart = new QRCodeJs({
193
173
  data: 'https://example.com/corner-dot-heart',
194
174
  dotsOptions: { color: '#555' },
195
175
  cornersSquareOptions: { type: 'square', color: '#E64A19' }, // Orange square corners
@@ -203,9 +183,7 @@ qrCornerDotHeart.append(document.getElementById('corner-dot-heart-container'));
203
183
 
204
184
  **Example 2: Square Corner Dots with Different Color**
205
185
 
206
- ```typescript
207
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
208
- const qrCornerDotSquare = new QRCodeJs({
186
+ ```typescriptconst qrCornerDotSquare = new QRCodeJs({
209
187
  data: 'https://example.com/corner-dot-square',
210
188
  dotsOptions: { type: 'rounded', color: '#004D40' }, // Dark Teal dots
211
189
  cornersSquareOptions: { type: 'rounded', color: '#FBC02D' }, // Yellow rounded corners
@@ -225,9 +203,7 @@ Applies color, rounding, and gradients to the background.
225
203
 
226
204
  **Example 1: Colored and Rounded Background**
227
205
 
228
- ```typescript
229
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
230
- const qrBackgroundStyled = new QRCodeJs({
206
+ ```typescriptconst qrBackgroundStyled = new QRCodeJs({
231
207
  data: 'https://example.com/background-styled',
232
208
  dotsOptions: { color: '#FFFFFF' }, // White dots for contrast
233
209
  backgroundOptions: {
@@ -240,9 +216,7 @@ qrBackgroundStyled.append(document.getElementById('background-styled-container')
240
216
 
241
217
  **Example 2: Background with Subtle Radial Gradient**
242
218
 
243
- ```typescript
244
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
245
- const qrBackgroundGradient = new QRCodeJs({
219
+ ```typescriptconst qrBackgroundGradient = new QRCodeJs({
246
220
  data: 'https://example.com/background-gradient',
247
221
  dotsOptions: { color: '#333' },
248
222
  backgroundOptions: {
@@ -267,9 +241,7 @@ Applies linear and radial gradients to various elements.
267
241
 
268
242
  **Example 1: Linear Gradient on Dots**
269
243
 
270
- ```typescript
271
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
272
- const qrGradientDotsLinear = new QRCodeJs({
244
+ ```typescriptconst qrGradientDotsLinear = new QRCodeJs({
273
245
  data: 'https://example.com/gradient-dots-linear',
274
246
  dotsOptions: {
275
247
  type: 'rounded',
@@ -289,9 +261,7 @@ qrGradientDotsLinear.append(document.getElementById('gradient-dots-linear-contai
289
261
 
290
262
  **Example 2: Radial Gradient on Corner Squares & Linear on Dots**
291
263
 
292
- ```typescript
293
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
294
- const qrGradientMultiple = new QRCodeJs({
264
+ ```typescriptconst qrGradientMultiple = new QRCodeJs({
295
265
  data: 'https://example.com/gradient-multiple',
296
266
  dotsOptions: {
297
267
  type: 'square',
@@ -337,9 +307,7 @@ Embeds logos or images within the QR code.
337
307
 
338
308
  **Example 1: Centered Logo with Fill**
339
309
 
340
- ```typescript
341
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
342
- const qrImageCenter = new QRCodeJs({
310
+ ```typescriptconst qrImageCenter = new QRCodeJs({
343
311
  data: 'https://example.com/image-center',
344
312
  qrOptions: { errorCorrectionLevel: 'Q' }, // Higher EC recommended
345
313
  image: 'https://upload.wikimedia.org/wikipedia/commons/a/a5/Instagram_icon.png', // Example: Instagram logo
@@ -357,9 +325,7 @@ qrImageCenter.append(document.getElementById('image-center-container'));
357
325
 
358
326
  **Example 2: Image as Background**
359
327
 
360
- ```typescript
361
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
362
- const qrImageBackground = new QRCodeJs({
328
+ ```typescriptconst qrImageBackground = new QRCodeJs({
363
329
  data: 'https://example.com/image-background',
364
330
  qrOptions: { errorCorrectionLevel: 'M' },
365
331
  image: 'https://source.unsplash.com/random/300x300?nature,water', // Example: Random nature image
@@ -379,19 +345,108 @@ const qrImageBackground = new QRCodeJs({
379
345
  qrImageBackground.append(document.getElementById('image-background-container'));
380
346
  ```
381
347
 
348
+ **Example 3: Using the Override Option with Images**
349
+
350
+ ```typescript
351
+ // Setting a global image with override that will take precedence
352
+ // even over images specified in instance options
353
+ QRCodeJs.setImage('https://example.com/global-priority-logo.png', { override: true });
354
+
355
+ // Even when an instance specifies an image, the global one with override will be used
356
+ const qrImageOverride = new QRCodeJs({
357
+ data: 'https://example.com/image-override-example',
358
+ image: 'https://example.com/this-will-be-ignored.png', // Will be ignored due to override
359
+ dotsOptions: { color: '#333333' }
360
+ });
361
+ qrImageOverride.append(document.getElementById('image-override-container'));
362
+
363
+ // Using the builder pattern with image override
364
+ const qrBuilderImageOverride = QRCodeJs.useImage('https://example.com/builder-priority-logo.png', { override: true })
365
+ .options({
366
+ data: 'https://example.com/builder-image-override-example',
367
+ image: 'https://example.com/another-ignored-image.png', // Will be ignored due to override
368
+ dotsOptions: { type: 'rounded', color: '#555555' }
369
+ });
370
+ qrBuilderImageOverride.append(document.getElementById('builder-image-override-container'));
371
+
372
+ // Reset the global image when done
373
+ QRCodeJs.setImage(null);
374
+ ```
375
+
382
376
  ---
383
377
 
384
378
  ### Border Options and Decorations (Premium Feature)
385
379
 
386
380
  Uses premium border features for advanced styling and text. Requires a license.
387
381
 
388
- **Example 1: Elaborate Border with Multiple Decorations**
382
+ **Example 1: Using Text Override Option**
389
383
 
390
384
  ```typescript
391
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
392
385
  // Ensure license is activated first
393
386
  // await QRCodeJs.license('YOUR-LICENSE-KEY');
394
387
 
388
+ // Setting global text with override that will take precedence
389
+ // even over text specified in instance options
390
+ QRCodeJs.setText({
391
+ topValue: 'GLOBAL OVERRIDE TEXT',
392
+ bottomValue: 'PRIORITY FOOTER TEXT'
393
+ }, { override: true });
394
+
395
+ // Even when an instance specifies border text, the global one with override will be used
396
+ const qrTextOverride = new QRCodeJs({
397
+ data: 'https://example.com/text-override-example',
398
+ borderOptions: {
399
+ hasBorder: true,
400
+ thickness: 30,
401
+ color: '#FF5722',
402
+ decorations: {
403
+ top: {
404
+ enableText: true,
405
+ value: 'THIS TEXT WILL BE IGNORED' // Ignored due to global override
406
+ },
407
+ bottom: {
408
+ enableText: true,
409
+ value: 'THIS BOTTOM TEXT ALSO IGNORED' // Ignored due to global override
410
+ }
411
+ }
412
+ }
413
+ });
414
+ qrTextOverride.append(document.getElementById('text-override-container'));
415
+
416
+ // Using the builder pattern with text override
417
+ const qrBuilderTextOverride = QRCodeJs.useText({
418
+ leftValue: 'LEFT OVERRIDE TEXT',
419
+ rightValue: 'RIGHT OVERRIDE TEXT'
420
+ }, { override: true })
421
+ .options({
422
+ data: 'https://example.com/builder-text-override-example',
423
+ borderOptions: {
424
+ hasBorder: true,
425
+ thickness: 30,
426
+ color: '#3F51B5',
427
+ decorations: {
428
+ left: {
429
+ enableText: true,
430
+ value: 'IGNORED LEFT TEXT' // Will be ignored due to override
431
+ },
432
+ right: {
433
+ enableText: true,
434
+ value: 'IGNORED RIGHT TEXT' // Will be ignored due to override
435
+ }
436
+ }
437
+ }
438
+ });
439
+ qrBuilderTextOverride.append(document.getElementById('builder-text-override-container'));
440
+
441
+ // Reset the global text when done
442
+ QRCodeJs.setText(null);
443
+ ```
444
+
445
+ **Example 2: Elaborate Border with Multiple Decorations**
446
+
447
+ ```typescript// Ensure license is activated first
448
+ // await QRCodeJs.license('YOUR-LICENSE-KEY');
449
+
395
450
  const qrBorderElaborate = new QRCodeJs({
396
451
  data: 'https://example.com/border-elaborate',
397
452
  dotsOptions: {
@@ -532,13 +587,79 @@ const qrBuilderExample = new QRCodeJs({ data: 'https://example.com/class-instanc
532
587
  ```
533
588
  ---
534
589
 
590
+ ### Combining Global Defaults (`setTemplate`, `setStyle`, `setBorder`)
591
+
592
+ This example shows how to set global defaults for a template, style, and border configuration. Subsequent `QRCodeJs` instances will inherit these settings unless overridden during instantiation.
593
+
594
+ ```typescript
595
+ // 1. Define and set global defaults
596
+ const globalTemplate = { backgroundOptions: { color: '#E8F5E9' } }; // Light Green background
597
+ const globalStyle = { dotsOptions: { type: 'classy', color: '#1B5E20' } }; // Dark Green classy dots
598
+ const globalBorder = { borderOptions: { hasBorder: true, thickness: 15, color: '#A5D6A7' } }; // Light Green border
599
+
600
+ QRCodeJs.setTemplate(globalTemplate);
601
+ QRCodeJs.setStyle(globalStyle);
602
+ QRCodeJs.setBorder(globalBorder); // Set the global border
603
+ QRCodeJs.setImage('https://example.com/global-default-logo.svg'); // Set a global default image or data URL
604
+
605
+ // 2. Create instance - it inherits all global defaults, including the image
606
+ const qrGlobalCombined = new QRCodeJs({
607
+ data: 'https://example.com/global-combined-with-image'
608
+ // No image option here, it will use the global default
609
+ });
610
+ qrGlobalCombined.append(document.getElementById('global-combined-container'));
611
+
612
+ // 3. Create another instance, overriding the global image and border color
613
+ const qrGlobalCombinedOverride = new QRCodeJs({
614
+ data: 'https://example.com/global-combined-override-image',
615
+ image: 'https://example.com/override-logo.png', // Override global image
616
+ borderOptions: { color: '#FF0000' } // Override border color to Red
617
+ });
618
+ qrGlobalCombinedOverride.append(document.getElementById('global-combined-override-container'));
619
+
620
+ // Remember to clear defaults if needed for subsequent unrelated QR codes
621
+ // QRCodeJs.setTemplate('basic');
622
+ // QRCodeJs.setStyle(null);
623
+ // QRCodeJs.setBorder(null);
624
+ // QRCodeJs.setImage(null);
625
+ ```
626
+
627
+ ---
628
+
629
+ ### Combining Builder Methods (`useTemplate`, `useStyle`, `useBorder`, `useImage`)
630
+
631
+ This example demonstrates chaining builder methods to combine a template, style, and border configuration for a single instance without affecting global defaults.
632
+
633
+ ```typescript
634
+ // 1. Define components (optional, could be predefined names or IDs)
635
+ const baseTpl = { qrOptions: { errorCorrectionLevel: 'M' }, margin: 5 };
636
+ const dotsStyle = { dotsOptions: { type: 'dots', color: '#01579B' } }; // Light Blue dots
637
+ const frameBorder = { borderOptions: { hasBorder: true, thickness: 20, color: '#B3E5FC', radius: '10%' } }; // Light Blue border
638
+
639
+ // 2. Chain builder methods
640
+ const qrBuilderCombined = QRCodeJs.useTemplate(baseTpl) // Start with base template
641
+ .useStyle(dotsStyle) // Apply dot style
642
+ .useBorder(frameBorder) // Apply border configuration
643
+ .useImage('https://example.com/builder-specific-logo.svg') // Add an image via builder
644
+ .options({ data: 'https://example.com/builder-combined-with-image' }); // Add final data
645
+
646
+ qrBuilderCombined.append(document.getElementById('builder-combined-container'));
647
+
648
+ // Example using predefined names (assuming 'rounded', 'blue-gradient', 'thick-frame' exist)
649
+ // const qrBuilderNames = QRCodeJs.useTemplate('rounded')
650
+ // .useStyle('blue-gradient')
651
+ // .useBorder('thick-frame')
652
+ // .useImage('another-logo.png')
653
+ // .options({ data: 'https://example.com/builder-names-with-image' });
654
+ // qrBuilderNames.append(document.getElementById('builder-names-container'));
655
+ ```
656
+ ---
657
+
535
658
  ### Scan Validation (Premium Feature)
536
659
 
537
660
  Validate if the generated QR code is scannable using the built-in validator. This requires a premium license.
538
661
 
539
- ```typescript
540
- // filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/advanced-examples.md
541
- // Ensure license is activated first
662
+ ```typescript// Ensure license is activated first
542
663
  // await QRCodeJs.license('YOUR-LICENSE-KEY');
543
664
 
544
665
  const qrCodeToValidate = new QRCodeJs({
@@ -48,7 +48,7 @@ qrCode.append(document.getElementById('qr-container'));
48
48
  | `backgroundOptions.color` | `string` | `'#FFFFFF'` | The background color. |
49
49
  | `backgroundOptions.round` | `number \| string` | `0` | Rounds the corners of the background (0-1 or percentage). |
50
50
  | `backgroundOptions.gradient` | `Gradient` object | `undefined` | Apply a gradient fill to the background. See [Gradient options](#gradientoptions) for configuration details.
51
- | `image` | `string \| Buffer \| Blob` | `undefined` | URL, Buffer, or Blob of an image to embed in the QR code. |
51
+ | `image` | `string \| Buffer \| Blob` | `undefined` | URL, Buffer, or Blob of an image to embed in the QR code. Can be set globally via `QRCodeJs.setImage()` or per-instance via `QRCodeJs.useImage()` or direct options. |
52
52
  | `imageOptions` | `object` | `{...}` | Options for the embedded image. |
53
53
  | `imageOptions.mode` | `ImageMode` enum | `'center'` | How the image is embedded. See `ImageMode` enum. |
54
54
  | `imageOptions.imageSize` | `number` | `0.4` | Relative size of the image (0-1). |
@@ -57,7 +57,7 @@ qrCode.append(document.getElementById('qr-container'));
57
57
  | `imageOptions.fill` | `object` | `{...}` | Fill `color` or `gradient`. |
58
58
  | `imageOptions.fill.color` | `string` | `'rgba(255,255,255,1)'` | Fill color.
59
59
  | `imageOptions.fill.gradient` | `Gradient` object | `undefined` | Apply a gradient fill to the QR code. See [Gradient options](#gradientoptions) for configuration details.
60
- | `borderOptions` | `BorderOptions` object | `undefined` | Options for adding decorative borders. See below for sub-options. **Premium option** |
60
+ | `borderOptions` | `BorderOptions` object | `undefined` | Options for adding decorative borders. Can be configured globally via `QRCodeJs.setBorder()`/`setBorderId()` or per-instance via the builder pattern (`useBorder()`/`useBorderId()`). See below for sub-options. **Premium option** |
61
61
 
62
62
  ---
63
63
 
@@ -71,7 +71,7 @@ qrCode.append(document.getElementById('qr-container'));
71
71
  | `cornersDotOptions.type` | `CornerDotType` enum| `Inherits` | Specifies the shape of the corner dots. Refer to the `CornerDotType` enum for available options (e.g., square, rounded). |
72
72
  | `cornersDotOptions.color`| `string` | `Inherits` | Defines the solid color of the corner dots. Accepts any valid CSS color string (e.g., `'#FF0000'`, `'red'`, `'rgba(255, 0, 0, 0.5)'`). |
73
73
  | `cornersDotOptions.gradient` | `Gradient` object | `undefined`| Applies a gradient fill to the corner dots, overriding the `color` property if both are set. See [Gradient Sub-options](#gradient-sub-options) for configuration details. |
74
-
74
+
75
75
  ### Additional Notes
76
76
  - The `data` option is the only required option for generating a QR code.
77
77
  - Premium features like `borderOptions` and `validateScanning` require a valid license to use.
@@ -86,13 +86,28 @@ qrCode.append(document.getElementById('qr-container'));
86
86
  | `serialize` | `inverted?: boolean` | Converts the QR code to an SVG string. Returns `Promise<string \| undefined>`. |
87
87
  | `download` | `downloadOptions?: { name?: string; extension: 'svg' \| 'png' \| 'jpeg' \| 'webp' }, canvasOptions?: CanvasOptions` | Downloads the QR code as a file. Returns `Promise<void>`. |
88
88
  | `update` | `options?: RecursivePartial<Options>` | Updates the QR code with new options. Returns `void`. |
89
- | `setTemplate` | `templateNameOrOptions: string \| RecursivePartial<Options>` | Sets a global default template for subsequent instances. Returns `void`. |\n| `useTemplate` | `templateNameOrOptions: string \| RecursivePartial<Options>` | Initiates a builder pattern pre-configured with a template. Returns `QRCodeBuilder`. |
89
+ | `setTemplate` | `templateNameOrOptions: string \| RecursivePartial<Options>` | Sets a global default template (by name or options object) for subsequent instances. Returns `void`. |
90
+ | `setTemplateId` | `templateId: string` | Sets a global default template by its ID. Returns `void`. |
91
+ | `setStyle` | `styleNameOrOptions: string \| StyleOptions` | Sets a global default style (by name or options object) for subsequent instances. Returns `void`. |
92
+ | `setStyleId` | `styleId: string` | Sets a global default style by its ID. Returns `void`. |
93
+ | `setText` | `textNameOrOptions: string \| TextOptions \| null, options?: { override?: boolean }` | Sets a global default text configuration for border text. With `{ override: true }`, the text will take precedence over any instance-specific border text. Returns `void`. |
94
+ | `setTextId` | `textId: string \| null, options?: { override?: boolean }` | Sets a global default text configuration by its ID. With `{ override: true }`, the text will take precedence over any instance-specific border text. Returns `void`. |
95
+ | `setBorder` | `borderNameOrOptions: string \| RecursivePartial<BorderOptions>` | Sets a global default border configuration (by name or options object) for subsequent instances. Returns `void`. |
96
+ | `setBorderId` | `borderId: string` | Sets a global default border configuration by its ID. Returns `void`. |
97
+ | `setImage` | `imageUrl: string \| DataURL \| null, options?: { override?: boolean }` | Sets a global default image URL for subsequent instances. With `{ override: true }`, the image will take precedence over any instance-specific images.
98
+ | `useTemplate` | `templateNameOrOptions: string \| RecursivePartial<Options>` | Initiates a builder pattern pre-configured with a template (by name or options object). Returns `QRCodeBuilder`. |
99
+ | `useTemplateId` | `templateId: string` | Initiates a builder pattern pre-configured with a template by its ID. Returns `QRCodeBuilder`. |
100
+ | `useStyle` | `styleNameOrOptions: string \| StyleOptions` | Initiates a builder pattern pre-configured with a style (by name or options object). Returns `QRCodeBuilder`. |
101
+ | `useStyleId` | `styleId: string` | Initiates a builder pattern pre-configured with a style by its ID. Returns `QRCodeBuilder`. |
102
+ | `useText` | `textNameOrOptions: string \| TextOptions, options?: { override?: boolean }` | Initiates a builder pattern pre-configured with text for border sides. With `{ override: true }`, the text will take precedence over any text set in final options. Returns `QRCodeBuilder`. |
103
+ | `useTextId` | `textId: string, options?: { override?: boolean }` | Initiates a builder pattern pre-configured with text by its ID. With `{ override: true }`, the text will take precedence over any text set in final options. Returns `QRCodeBuilder`. |
104
+ | `useBorder` | `borderNameOrOptions: string \| BorderOptions` | Initiates a builder pattern pre-configured with a border configuration (by name or options object). Returns `QRCodeBuilder`. |
105
+ | `useBorderId` | `borderId: string` | Initiates a builder pattern pre-configured with a border configuration by its ID. Returns `QRCodeBuilder`. |
106
+ | `useImage` | `imageUrl: string \| DataURL, options?: { override?: boolean }` | Initiates a builder pattern pre-configured with an image URL. With `{ override: true }`, the image will take precedence over any image set in final options.
90
107
  | `validateScanning` | `validatorId?: string, debug?: boolean` | **(Premium method)** Validates that the QR code is scannable. Returns `Promise<ScanValidatorResponse>`. |
91
108
 
92
109
  ---
93
110
 
94
- | `useStyle` | `styleNameOrOptions: string \| StyleOptions` | Creates a `QRCodeBuilder` instance initialized with a specific style. Returns `QRCodeBuilder`. |
95
- | `useTemplate` | `templateNameOrOptions: string \| RecursivePartial<Options>` | Creates a `QRCodeBuilder` instance initialized with a specific template. Returns `QRCodeBuilder`. |
96
111
  <a id="borderoptions"></a>
97
112
  ### borderOptions Options
98
113
 
@@ -280,6 +295,11 @@ const qr3 = QRCodeJs.useTemplate('basic')
280
295
  | :------------ | :------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------- |
281
296
  | `useTemplate` | `templateNameOrOptions: string \| RecursivePartial<Options>` | Applies a template's options to the current configuration. Options from subsequent calls take precedence. Returns `this`. |
282
297
  | `useStyle` | `styleNameOrOptions: string \| StyleOptions` | Applies style options (mapping them to `Options`) to the current configuration. Returns `this`. |
298
+ | `useText` | `textNameOrOptions: string \| TextOptions, options?: { override?: boolean }` | Applies text configuration for border sides. With `{ override: true}`, text will take precedence over any text set in final options. Returns `this`. |
299
+ | `useTextId` | `textId: string, options?: { override?: boolean }` | Applies text configuration by its ID. With `{ override: true}`, text will take precedence over any text set in final options. Returns `this`. |
300
+ | `useBorder` | `borderNameOrOptions: string \| BorderOptions` | Applies border configuration (by name or options object) to the current configuration. Returns `this`. |
301
+ | `useBorderId` | `borderId: string` | Applies border configuration by its ID to the current configuration. Returns `this`. |
302
+ | `useImage` | `imageUrl: string, options?: { override?: boolean }` | Sets the image URL for the current configuration. With `{ override: true}`, the image will take precedence over any image set in final options. Returns `this`. |
283
303
  | `options` | `options: RecursivePartial<Options>` | Merges the provided `Options` into the current configuration and returns the final `QRCodeJs` instance. |
284
304
  | `build` | - | Creates and returns the final `QRCodeJs` instance based on the accumulated configuration. |
285
305
  ### See Also
@@ -0,0 +1,28 @@
1
+ # Plan: Update Documentation for Border Methods
2
+
3
+ **Objective:** Update documentation files to include information about the new border configuration methods: `setBorder`, `setBorderId`, `useBorder`, and `useBorderId`.
4
+
5
+ ## 1. Target Files
6
+
7
+ * `README.md`
8
+ * `docs/documentation.md`
9
+ * `docs/usage-guide.md`
10
+ * `docs/api-reference-guide.md`
11
+ * `docs/examples.md`
12
+ * `docs/advanced-examples.md`
13
+ * `docs/typescript-types-definitions.md`
14
+
15
+ ## 2. Update Strategy & Content
16
+
17
+ * **Update README:** Briefly mention the new static methods (`setBorder`, `setBorderId`, `useBorder`, `useBorderId`) in a relevant section (e.g., Features) and link to the main documentation for details.
18
+ * **Explain Both Mechanisms:** In `documentation.md` and `usage-guide.md`, clearly differentiate the `set...` (global default) and `use...` (builder pattern) approaches for border configuration.
19
+ * **Update Method Tables:** Add entries for `setBorder`, `setBorderId`, `useBorder`, and `useBorderId` to static method tables in relevant files, detailing parameters, return types, and purpose.
20
+ * **Add Examples:**
21
+ * In `examples.md`, add simple examples for `setBorder`, `setBorderId`, `useBorder`, and `useBorderId`.
22
+ * In `advanced-examples.md`, add examples combining global defaults (`setTemplate`/`setStyle`/`setBorder`) and builder methods (`useTemplate`/`useStyle`/`useBorder`).
23
+ * **Update Options Tables:** Ensure the `borderOptions` description mentions configuration via the new static/builder methods.
24
+ * **Verify Types:** Briefly check `docs/typescript-types-definitions.md` for `BorderOptions`.
25
+
26
+ ## 3. Implementation
27
+
28
+ This plan will be implemented by switching to Code mode after approval.
@@ -0,0 +1,155 @@
1
+ # Plan for Implementing Border Text Functionality
2
+
3
+ This document outlines the plan to implement `setText`, `useText`, `setTextId`, and `useTextId` functionality for managing text on QR code borders.
4
+
5
+ ## Phase 1: Define Core Structures and Text Templates
6
+
7
+ 1. **Create `TextOptions` and `QRTextTemplateDefinition` Types:**
8
+ * Define these interfaces. A new file like `src/types/text-options.ts` or an existing relevant types file (e.g., `src/utils/options.ts` or `src/types/style-options.ts`) can be used.
9
+ * **`TextOptions` Interface:**
10
+ ```typescript
11
+ export interface TextOptions {
12
+ topValue?: string | null;
13
+ leftValue?: string | null;
14
+ rightValue?: string | null;
15
+ bottomValue?: string | null;
16
+ }
17
+ ```
18
+ * **`QRTextTemplateDefinition` Interface:** (similar to `QRTemplateDefinition`)
19
+ ```typescript
20
+ // Assuming TextOptions is in 'text-options.ts' or similar
21
+ import { TextOptions } from './text-options'; // Adjust path as needed
22
+
23
+ export interface QRTextTemplateDefinition {
24
+ id: string;
25
+ name: string;
26
+ options: TextOptions;
27
+ }
28
+ ```
29
+
30
+ 2. **Create New Text Templates File: `src/core/templates/qr-template-text.ts`**
31
+ * This file will be analogous to `src/core/templates/qr-template-borders.ts`.
32
+ * It will import `QRTextTemplateDefinition` and `TextOptions`.
33
+ * Define at least 20 unique `QRTextTemplateDefinition` objects.
34
+ * Each template will have a unique `id` (e.g., `"scan-me-top"`, `"return-if-found-bottom-left"`).
35
+ * Each template will have a unique, descriptive `name` (e.g., `"Scan Me (Top Text)"`, `"Return If Found (Bottom & Left Text)"`).
36
+ * The `options` field will be a `TextOptions` object with various combinations of `topValue`, `leftValue`, `rightValue`, `bottomValue`.
37
+ * Include `null` values where appropriate to signify no text for a particular side.
38
+ * Focus on call-to-action phrases like "Scan Me", "Visit Website", "Follow Us", "Contact Info", "Scan to Pay", "Product Details", "Event Info", "Lost & Found", etc.
39
+ * Export an array `qrTextTemplates: QRTextTemplateDefinition[]`.
40
+ * Export helper functions `findTextByName(name: string): QRTextTemplateDefinition | undefined` and `findTextById(id: string): QRTextTemplateDefinition | undefined`.
41
+
42
+ ## Phase 2: Implement Core Logic in `QRCodeJs` (`src/core/qr-code-js.ts`)
43
+
44
+ 1. **Add Static Properties for Selected Text:**
45
+ * `private static _selectedText: QRTextTemplateDefinition | TextOptions | null = null;`
46
+
47
+ 2. **Implement `setText` Static Method:**
48
+ * `public static setText(textNameOrOptions: string | TextOptions | null): typeof QRCodeJs`
49
+ * If `null`, set `_selectedText` to `null`.
50
+ * If `string`, use `findTextByName` from `qr-template-text.ts` to find the template. If found, store the `QRTextTemplateDefinition` in `_selectedText`. If not found, log a warning.
51
+ * If `object` (instance of `TextOptions`), store it directly in `_selectedText`.
52
+
53
+ 3. **Implement `setTextId` Static Method:**
54
+ * `public static setTextId(textId: string | null): typeof QRCodeJs`
55
+ * If `null`, set `_selectedText` to `null`.
56
+ * Use `findTextById` from `qr-template-text.ts`. If found, store the `QRTextTemplateDefinition` in `_selectedText`. If not found, log a warning.
57
+
58
+ 4. **Update Constructor and `update` Method Logic:**
59
+ * In the constructor and `update` method, after merging `borderOptions`, apply `_selectedText`.
60
+ * **Merging Logic:**
61
+ * Resolve `_selectedText` to a `TextOptions` object (either from `QRTextTemplateDefinition.options` or directly).
62
+ * Iterate through `topValue`, `leftValue`, `rightValue`, `bottomValue` of the resolved `TextOptions`.
63
+ * For each provided value (not `undefined`):
64
+ * Update `this.options.borderOptions.decorations.<side>.value`.
65
+ * Set `this.options.borderOptions.decorations.<side>.enableText = true`.
66
+ * If the value is `null`, set `this.options.borderOptions.decorations.<side>.value = null` and `this.options.borderOptions.decorations.<side>.enableText = false`.
67
+ * Ensure `this.options.borderOptions.decorations` and each side object (`top`, `left`, etc.) are initialized if they don't exist.
68
+
69
+ ## Phase 3: Implement Builder Logic in `QRCodeBuilder` (`src/index.ts` and `src/node.ts`)
70
+
71
+ * Changes need to be mirrored in `QRCodeBuilder` in both `src/index.ts` and `src/node.ts`.
72
+
73
+ 1. **Add Properties to `QRCodeBuilder`:**
74
+ * `protected _textSource: string | TextOptions | null = null;`
75
+ * `protected _isTextById: boolean = false;`
76
+
77
+ 2. **Implement `useText` Method in `QRCodeBuilder`:**
78
+ * `public useText(textNameOrOptions: string | TextOptions): this`
79
+ * Stores `textNameOrOptions` in `_textSource`. Sets `_isTextById = false`.
80
+
81
+ 3. **Implement `useTextId` Method in `QRCodeBuilder`:**
82
+ * `public useTextId(textId: string): this`
83
+ * Stores `textId` in `_textSource`. Sets `_isTextById = true`.
84
+
85
+ 4. **Update `_resolveAndMergeConfig` in `QRCodeBuilder`:**
86
+ * Add a step to apply text options after border options.
87
+ * **Order:** Base Template -> Selected Template -> Selected Border -> **Selected Text** -> Selected Style -> Selected Image -> Final Options.
88
+ * **Logic:**
89
+ * Resolve `_textSource` (using `findTextById`/`findTextByName` if string, or directly if object).
90
+ * If valid `TextOptions` are found:
91
+ * Create a partial `Options` object: `let textOptionsToApply: RecursivePartial<Options> = { borderOptions: { decorations: {} } };`
92
+ * For each key in resolved `TextOptions` (e.g., `topValue`):
93
+ * `textOptionsToApply.borderOptions.decorations.top = { value: textOptions.topValue, enableText: textOptions.topValue !== null };`
94
+ * Repeat for `left`, `right`, `bottom`.
95
+ * Merge `textOptionsToApply` into `resolvedConfig`.
96
+
97
+ 5. **Add Static `useText` and `useTextId` Methods to `QRCodeJs` class (in `src/index.ts` and `src/node.ts`):**
98
+ * `public static useText(textNameOrOptions: string | TextOptions): QRCodeBuilder`
99
+ * `return new QRCodeBuilder(this).useText(textNameOrOptions);`
100
+ * `public static useTextId(textId: string): QRCodeBuilder`
101
+ * `return new QRCodeBuilder(this).useTextId(textId);`
102
+
103
+ ## Phase 4: Update Imports and Exports
104
+
105
+ 1. **In `src/index.ts` and `src/node.ts`:**
106
+ * Import `findTextById`, `findTextByName` from `./core/templates/qr-template-text`.
107
+ * Import `TextOptions`, `QRTextTemplateDefinition` (if in a separate file).
108
+ * Export these types if intended for public use.
109
+
110
+ ## Phase 5: Testing and Documentation
111
+
112
+ 1. **Update `src/templates/borders-templates.html`:**
113
+ * Add a new dropdown selector for "Text Templates" populated from `qrTextTemplates`.
114
+ * Modify the rendering loop:
115
+ * After applying base template, style, and border, add a step to apply a selected text template using `QRCodeJs.setTextId()` or `QRCodeJs.setText()`.
116
+ * This will demonstrate the override behavior where `setText` modifies the text values on borders already configured by `setBorder`.
117
+ * Ensure the visual output clearly shows the text being applied/overridden.
118
+
119
+ 2. **Add Unit Tests (Recommended):**
120
+ * Test `findTextByName` and `findTextById`.
121
+ * Test `setText`/`setTextId` in `QRCodeJs` core.
122
+ * Test `useText`/`useTextId` in `QRCodeBuilder`.
123
+
124
+ 3. **Update Documentation (`README.md`, API docs):**
125
+ * Document new types, static methods, and builder methods.
126
+ * Provide usage examples.
127
+
128
+ ## Mermaid Diagram: `QRCodeBuilder._resolveAndMergeConfig` Flow
129
+
130
+ ```mermaid
131
+ graph TD
132
+ A[Start _resolveAndMergeConfig] --> B{Initial Options or Base Template};
133
+ B -- Initial Options --> C[Merge Initial Options];
134
+ B -- Base Template --> C[Merge baseQRTemplateOptions];
135
+ C --> D{Template Source Set?};
136
+ D -- Yes --> E[Find/Apply Template Options];
137
+ D -- No --> F;
138
+ E --> F;
139
+ F{Border Source Set?} --> G;
140
+ G -- Yes --> H[Find/Apply Border Options];
141
+ G -- No --> I;
142
+ H --> I;
143
+ I{Text Source Set?} --> J;
144
+ J -- Yes --> K[Find/Apply Text Options to Decorations];
145
+ J -- No --> L;
146
+ K --> L;
147
+ L{Style Source Set?} --> M;
148
+ M -- Yes --> N[Find/Apply Style Options];
149
+ M -- No --> O;
150
+ N --> O;
151
+ O{Image Source Set?} --> P;
152
+ P -- Yes --> Q[Apply Image Option];
153
+ P -- No --> R;
154
+ Q --> R;
155
+ R[Merge Final User Options] --> S[Return Resolved Config];