@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
@@ -393,13 +393,29 @@ Controls the QR code background.
393
393
 
394
394
  ### `image`
395
395
 
396
- - **Purpose**: URL, Buffer, or Blob of an image to embed in the QR code
396
+ - **Purpose**: URL, Buffer, or Blob of an image to embed in the QR code. This can be set directly in the options, or via `QRCodeJs.setImage()` for a global default, or `QRCodeJs.useImage()` for a builder-specific image.
397
397
  - **Type**: `string | Buffer | Blob`
398
398
  - **Example**:
399
399
  ```typescript
400
400
  image: 'https://example.com/logo.png'
401
401
  ```
402
402
 
403
+ #### Override Behavior with `setImage` and `useImage`
404
+
405
+ - Both `setImage` and `useImage` methods can accept an optional second parameter with `{ override: true }` to ensure the image takes precedence over any image set elsewhere.
406
+ - **Example with Override**:
407
+ ```typescript
408
+ // Global image that will override any instance-specific images
409
+ QRCodeJs.setImage('https://example.com/global-logo.png', { override: true });
410
+
411
+ // Builder pattern with image that will override final options
412
+ const qr = QRCodeJs.useImage('https://example.com/important-logo.png', { override: true })
413
+ .options({
414
+ data: 'https://example.com',
415
+ image: 'https://example.com/this-will-be-ignored.png' // Will be ignored due to override
416
+ });
417
+ ```
418
+
403
419
  ### `imageOptions`
404
420
 
405
421
  Options for the embedded image.
@@ -532,7 +548,7 @@ QRCode.js provides border features in both the free and premium versions, with s
532
548
 
533
549
  ### `borderOptions`
534
550
 
535
- Options for adding decorative borders around the QR code.
551
+ Options for adding decorative borders around the QR code. Borders can be configured globally using `QRCodeJs.setBorder()` / `QRCodeJs.setBorderId()` or on a per-instance basis using the builder pattern initiated with `QRCodeJs.useBorder()` / `QRCodeJs.useBorderId()`.
536
552
 
537
553
  #### `hasBorder`
538
554
 
@@ -767,6 +783,196 @@ if (licenseDetails) {
767
783
  }
768
784
  ```
769
785
 
786
+ ## Border Text Methods (Premium Feature)
787
+
788
+ QRCode.js provides dedicated methods for managing text on QR code borders, allowing for convenient text configuration across all sides.
789
+
790
+ ### Static Methods for Global Text Settings
791
+
792
+ #### `setText()`
793
+
794
+ - **Purpose**: Sets global default text for QR code borders that will apply to all subsequently created instances.
795
+ - **Type**: `function(textNameOrOptions: string | TextOptions | null, options?: { override?: boolean }): typeof QRCodeJs`
796
+ - **Parameters**:
797
+ - `textNameOrOptions`: A predefined text template name (e.g., 'Scan Me (Top)'), a custom `TextOptions` object, or `null` to clear
798
+ - `options`: Optional configuration with `override` property to ensure text takes precedence
799
+ - **Returns**: The QRCodeJs class for chaining
800
+ - **Example**:
801
+ ```typescript
802
+ // Set global text on top and bottom border sides
803
+ QRCodeJs.setText({
804
+ topValue: 'SCAN ME',
805
+ bottomValue: 'www.example.com'
806
+ });
807
+
808
+ // Use a predefined text template
809
+ QRCodeJs.setText('Scan Me (Top)');
810
+
811
+ // With override option to ensure it takes precedence
812
+ QRCodeJs.setText({ topValue: 'MUST DISPLAY THIS TEXT' }, { override: true });
813
+
814
+ // Clear global text
815
+ QRCodeJs.setText(null);
816
+ ```
817
+
818
+ #### `setTextId()`
819
+
820
+ - **Purpose**: Sets global default text for QR code borders by referencing a predefined template ID.
821
+ - **Type**: `function(textId: string | null, options?: { override?: boolean }): typeof QRCodeJs`
822
+ - **Parameters**:
823
+ - `textId`: ID of a predefined text template (e.g., 'visit-website-bottom') or `null` to clear
824
+ - `options`: Optional configuration with `override` property to ensure text takes precedence
825
+ - **Returns**: The QRCodeJs class for chaining
826
+ - **Example**:
827
+ ```typescript
828
+ // Set global text using a predefined template ID
829
+ QRCodeJs.setTextId('visit-website-bottom');
830
+
831
+ // With override option
832
+ QRCodeJs.setTextId('lost-found-all-sides', { override: true });
833
+
834
+ // Clear global text
835
+ QRCodeJs.setTextId(null);
836
+ ```
837
+
838
+ ### Builder Methods for Instance-Specific Text
839
+
840
+ #### `useText()`
841
+
842
+ - **Purpose**: Initiates a builder pattern pre-configured with border text from a template name or custom options.
843
+ - **Type**: `function(textNameOrOptions: string | TextOptions, options?: { override?: boolean }): QRCodeBuilder`
844
+ - **Parameters**:
845
+ - `textNameOrOptions`: A predefined text template name or a custom `TextOptions` object
846
+ - `options`: Optional configuration with `override` property to ensure text takes precedence
847
+ - **Returns**: A `QRCodeBuilder` instance for chaining
848
+ - **Example**:
849
+ ```typescript
850
+ // Start builder with custom text options
851
+ const qrCode = QRCodeJs.useText({
852
+ topValue: 'VISIT OUR WEBSITE',
853
+ bottomValue: 'www.example.com'
854
+ }).options({
855
+ data: 'https://example.com'
856
+ });
857
+
858
+ // Start builder with a predefined text template
859
+ const qrWithTemplate = QRCodeJs.useText('Scan Me (Bottom)')
860
+ .options({ data: 'https://example.com/scan-me' });
861
+
862
+ // With override option to ensure text takes precedence over final options
863
+ const qrWithOverride = QRCodeJs.useText(
864
+ { leftValue: 'IMPORTANT TEXT' },
865
+ { override: true }
866
+ ).options({
867
+ data: 'https://example.com',
868
+ borderOptions: {
869
+ decorations: {
870
+ left: { value: 'This will be ignored', enableText: true }
871
+ }
872
+ }
873
+ });
874
+ ```
875
+
876
+ #### `useTextId()`
877
+
878
+ - **Purpose**: Initiates a builder pattern pre-configured with border text from a predefined template ID.
879
+ - **Type**: `function(textId: string, options?: { override?: boolean }): QRCodeBuilder`
880
+ - **Parameters**:
881
+ - `textId`: ID of a predefined text template (e.g., 'visit-website-bottom')
882
+ - `options`: Optional configuration with `override` property to ensure text takes precedence
883
+ - **Returns**: A `QRCodeBuilder` instance for chaining
884
+ - **Example**:
885
+ ```typescript
886
+ // Start builder with a predefined text template by ID
887
+ const qrCode = QRCodeJs.useTextId('visit-website-bottom')
888
+ .options({ data: 'https://example.com' });
889
+
890
+ // With override option
891
+ const qrWithOverride = QRCodeJs.useTextId('scan-me-top', { override: true })
892
+ .options({ data: 'https://example.com' });
893
+ ```
894
+
895
+ ### TextOptions Structure
896
+
897
+ The `TextOptions` object allows you to specify text for each side of the QR code border:
898
+
899
+ ```typescript
900
+ interface TextOptions {
901
+ topValue?: string | null; // Text for top border (null explicitly disables)
902
+ rightValue?: string | null; // Text for right border
903
+ bottomValue?: string | null; // Text for bottom border
904
+ leftValue?: string | null; // Text for left border
905
+ }
906
+ ```
907
+
908
+ - Setting a value to `null` explicitly disables text on that side
909
+ - Omitting a property (undefined) leaves any existing text on that side unchanged
910
+ - Empty string (`''`) will be treated as no text but with `enableText: true`
911
+
912
+ ### Override Behavior
913
+
914
+ All text methods accept an optional `{ override: true }` parameter to ensure the text values take precedence over any text settings applied at a later stage:
915
+
916
+ - `setText()` with override will override text from instance options
917
+ - `setTextId()` with override will override text from instance options
918
+ - `useText()` with override will override text from final `.options()` call
919
+ - `useTextId()` with override will override text from final `.options()` call
920
+
921
+ This is particularly useful when you need to ensure specific text appears regardless of other configuration.
922
+
923
+ ### Example: Combining Text Methods with Border Options
924
+
925
+ ```typescript
926
+ // First activate license (required for custom border text)
927
+ await QRCodeJs.license('YOUR-LICENSE-KEY');
928
+
929
+ // Set global default for all QR codes
930
+ QRCodeJs.setText({
931
+ topValue: 'SCAN ME',
932
+ bottomValue: 'www.example.com'
933
+ });
934
+
935
+ // Create QR code with custom border that uses the global text
936
+ const qrCode = new QRCodeJs({
937
+ data: 'https://example.com',
938
+ borderOptions: {
939
+ hasBorder: true,
940
+ thickness: 40,
941
+ color: '#0033CC',
942
+ radius: '10%'
943
+ // No decoration settings needed - will use the global text
944
+ }
945
+ });
946
+
947
+ // Chain builder methods for more complex setup
948
+ const qrChained = QRCodeJs.useBorder('Rounded Border (Large)')
949
+ .useText({
950
+ topValue: 'POWERED BY',
951
+ bottomValue: 'QR-PLATFORM'
952
+ })
953
+ .options({ data: 'https://example.com/chained' });
954
+ ```
955
+
956
+ ### Clearing Text Settings
957
+
958
+ To remove text from borders:
959
+
960
+ ```typescript
961
+ // Clear global text settings
962
+ QRCodeJs.setText(null);
963
+
964
+ // Clear text on specific sides
965
+ QRCodeJs.setText({
966
+ topValue: null, // Explicitly remove top text
967
+ bottomValue: null, // Explicitly remove bottom text
968
+ });
969
+
970
+ // Use a predefined "empty" template to clear all sides
971
+ QRCodeJs.useText('empty-text-options').options({
972
+ data: 'https://example.com'
973
+ });
974
+ ```
975
+
770
976
  ## Scan Validation (Premium Feature)
771
977
 
772
978
  > **Note**: This is a Premium Feature requiring a license.
@@ -1054,8 +1260,30 @@ const qrBuilder2 = QRCodeJs.useTemplate({
1054
1260
 
1055
1261
  Choosing between `setTemplate` and `useTemplate` depends on whether you need a persistent global default or a one-off configuration based on a template.
1056
1262
 
1057
- ## Complete Examples
1263
+ ## Using Styles and Borders (Global Defaults vs. Builder)
1264
+
1265
+ Similar to templates, styles and border configurations can be applied globally or using the builder pattern.
1266
+
1267
+ ### Setting Global Defaults (`setStyle`, `setBorder`)
1268
+
1269
+ - **`QRCodeJs.setStyle(styleNameOrOptions)`**: Sets a default style (by name or object) that applies to subsequent instances. Options provided during instantiation override the global style.
1270
+ - **`QRCodeJs.setBorder(borderNameOrOptions)`**: Sets a default border configuration (by name or object) that applies to subsequent instances. Options provided during instantiation override the global border settings.
1271
+ - **`QRCodeJs.setStyleId(styleId)` / `QRCodeJs.setBorderId(borderId)`**: Similar to the above, but uses the predefined ID of the style or border.
1058
1272
 
1273
+ These methods are useful for establishing a consistent look and feel across multiple QR codes in your application.
1274
+
1275
+ ### Using the Builder Pattern (`useStyle`, `useBorder`)
1276
+
1277
+ - **`QRCodeJs.useStyle(styleNameOrOptions)`**: Initiates a builder pre-configured with the specified style.
1278
+ - **`QRCodeJs.useBorder(borderNameOrOptions)`**: Initiates a builder pre-configured with the specified border configuration.
1279
+ - **`QRCodeJs.useStyleId(styleId)` / `QRCodeJs.useBorderId(borderId)`**: Similar, but uses the predefined ID.
1280
+
1281
+ These methods return a `QRCodeBuilder` instance, allowing you to chain configurations and finalize with `.options({...})` or `.build()`. This approach is ideal for creating specific QR code instances with unique combinations of templates, styles, and borders without affecting global defaults.
1282
+
1283
+
1284
+ **Combining Methods:** You can combine global defaults with builder methods. For example, you could set a global template and then use the builder to apply a specific style, border, and image to an individual instance. Options are merged, with later steps in the configuration process (e.g., builder methods, final `.options()` call) overriding earlier ones (e.g., global defaults). The general precedence for the image source is: Builder's `useImage()` > Static `setImage()` > Template's image > Direct `options.image` in constructor.
1285
+
1286
+ ## Complete Examples
1059
1287
  ### Basic QR Code with Custom Dots
1060
1288
 
1061
1289
  ```typescript
@@ -1459,7 +1687,39 @@ QRCodeJs.setStyle(styleNameOrOptions: string | RecursivePartial<StyleOptions>):
1459
1687
  Initiates a builder pattern pre-configured with a style.
1460
1688
 
1461
1689
  ```typescript
1462
- QRCodeJs.useTemplate(styleNameOrOptions: string | RecursivePartial<StyleOptions>): QRCodeBuilder
1690
+ QRCodeJs.useStyle(styleNameOrOptions: string | StyleOptions): QRCodeBuilder
1691
+ ```
1692
+
1693
+ #### `setBorder()`
1694
+
1695
+ Sets a global default border configuration for subsequent `QRCodeJs` instances.
1696
+
1697
+ ```typescript
1698
+ QRCodeJs.setBorder(borderNameOrOptions: string | RecursivePartial<BorderOptions>): void
1699
+ ```
1700
+
1701
+ #### `setBorderId()`
1702
+
1703
+ Sets a global default border configuration by its ID for subsequent `QRCodeJs` instances.
1704
+
1705
+ ```typescript
1706
+ QRCodeJs.setBorderId(borderId: string): void
1707
+ ```
1708
+
1709
+ #### `useBorder()`
1710
+
1711
+ Initiates a builder pattern pre-configured with a border configuration.
1712
+
1713
+ ```typescript
1714
+ QRCodeJs.useBorder(borderNameOrOptions: string | BorderOptions): QRCodeBuilder
1715
+ ```
1716
+
1717
+ #### `useBorderId()`
1718
+
1719
+ Initiates a builder pattern pre-configured with a border configuration by its ID.
1720
+
1721
+ ```typescript
1722
+ QRCodeJs.useBorderId(borderId: string): QRCodeBuilder
1463
1723
  ```
1464
1724
 
1465
1725
  ## Fluent Builder Pattern (`useTemplate`, `useStyle`, `build`)
@@ -1468,18 +1728,22 @@ QRCode.js offers a fluent builder pattern for a more readable and chainable way
1468
1728
 
1469
1729
  ### Overview
1470
1730
 
1471
- Instead of passing all options to the constructor, you can start with a base template or style using `QRCodeJs.useTemplate()` or `QRCodeJs.useStyle()`. These methods return a `QRCodeBuilder` instance. You can then chain further `.useTemplate()`, `.useStyle()`, and finally `.options()` or `.build()` to finalize the configuration.
1731
+ Instead of passing all options to the constructor, you can start with a base template, style, border, or image using `QRCodeJs.useTemplate()`, `QRCodeJs.useStyle()`, `QRCodeJs.useBorder()`, or `QRCodeJs.useImage()`. These methods return a `QRCodeBuilder` instance. You can then chain further `.useTemplate()`, `.useStyle()`, `.useBorder()`, `.useImage()`, and finally `.options()` or `.build()` to finalize the configuration.
1472
1732
 
1473
1733
  - `QRCodeJs.useTemplate(template)`: Starts a builder with a predefined or custom template.
1474
1734
  - `QRCodeJs.useStyle(style)`: Starts a builder and applies a predefined or custom style.
1475
- - `.useTemplate(template)` (on builder): Applies another template. Options merge, with later calls overriding earlier ones.
1476
- - `.useStyle(style)` (on builder): Applies another style. Options merge, with later calls overriding earlier ones.
1735
+ - `QRCodeJs.useBorder(border)`: Starts a builder and applies a predefined or custom border configuration.
1736
+ - `QRCodeJs.useImage(imageUrl)`: Starts a builder and sets an image.
1737
+ - `.useTemplate(template)` (on builder): Applies another template. Options merge.
1738
+ - `.useStyle(style)` (on builder): Applies another style. Options merge.
1739
+ - `.useBorder(border)` (on builder): Applies a border configuration. Options merge.
1740
+ - `.useImage(imageUrl)` (on builder): Sets or overrides the image.
1477
1741
  - `.options(options)` (on builder): Merges final specific options and returns the `QRCodeJs` instance.
1478
1742
  - `.build()` (on builder, optional method if options(options) is NOT called): Creates the `QRCodeJs` instance with the accumulated configuration.
1479
1743
 
1480
- ### How `useStyle` and `useTemplate` Work Together (Builder Pattern)
1744
+ ### How Builder Methods Work Together
1481
1745
 
1482
- You can chain `useTemplate` and `useStyle` calls. The options are merged progressively. If both a template and a style define the same option (e.g., `dotsOptions.color`), the option from the *last* applied template or style in the chain will take precedence.
1746
+ You can chain `useTemplate`, `useStyle`, `useBorder`, and `useImage` calls. The options are merged progressively. If multiple methods define the same option (e.g., `dotsOptions.color` from a template and a style, or `image` from `useImage` and a template), the option from the *last* applied method in the chain for that specific property will generally take precedence. The final `.options()` call provides the ultimate override.
1483
1747
 
1484
1748
  ### Examples
1485
1749
 
@@ -1516,17 +1780,18 @@ qrFromStyle.append(document.getElementById('qr-container-2'));
1516
1780
 
1517
1781
  **3. Chain Template and Style:**
1518
1782
 
1783
+
1519
1784
  ```typescript
1520
1785
  const qrCombined = QRCodeJs.useTemplate('dots') // Start with 'dots' template (black dots)
1521
1786
  .useStyle({ dotsOptions: { color: '#4682B4' } }) // Apply style, overriding dot color to SteelBlue
1522
- .options({ data: 'Template + Style' })
1787
+ .useImage('https://example.com/logo.png') // Add an image
1788
+ .options({ data: 'Template + Style + Image' })
1523
1789
  .build();
1524
1790
 
1525
1791
  qrCombined.append(document.getElementById('qr-container-3'));
1526
1792
  ```
1527
1793
 
1528
1794
  **4. Build without final options:**
1529
-
1530
1795
  ```typescript
1531
1796
  // Assume 'data' is part of the template or style
1532
1797
  const qrBuildDirectly = QRCodeJs.useTemplate({