@qr-platform/qr-code.js 0.8.19 → 0.8.21
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.
- package/.github/workflows/publish.yml +10 -5
- package/CHANGELOG.md +12 -0
- package/docs/examples.md +62 -0
- package/docs/usage-guide.md +20 -0
- package/lib/builder/index.d.ts +13 -0
- package/lib/builder/node.d.ts +13 -0
- package/lib/builder/qr-code-builder.d.ts +25 -0
- package/lib/core/qr-code-js.d.ts +2 -0
- package/lib/core/qr-templates.d.ts +3 -0
- package/lib/index.d.ts +8 -0
- package/lib/node.d.ts +8 -0
- package/lib/qr-code-js-node.js +1 -1
- package/lib/qr-code-js.js +1 -1
- package/package.json +1 -1
@@ -19,20 +19,25 @@ jobs:
|
|
19
19
|
node-version: '22'
|
20
20
|
registry-url: 'https://registry.npmjs.org'
|
21
21
|
|
22
|
-
|
22
|
+
# --- Check if version already exists ---
|
23
|
+
- name: Check if version exists on npm
|
23
24
|
id: check_version
|
24
25
|
run: |
|
26
|
+
PACKAGE_NAME=$(node -p "require('./package.json').name")
|
25
27
|
VERSION=$(node -p "require('./package.json').version")
|
26
|
-
if
|
27
|
-
|
28
|
+
echo "Checking if package '${PACKAGE_NAME}@${VERSION}' exists on npm..."
|
29
|
+
if npm view "${PACKAGE_NAME}@${VERSION}" version > /dev/null 2>&1; then
|
30
|
+
echo "Version ${VERSION} of ${PACKAGE_NAME} already exists on npm. Skipping publish."
|
28
31
|
echo "skip_publish=true" >> $GITHUB_OUTPUT
|
29
32
|
else
|
30
|
-
echo "Version ${VERSION} does not exist
|
33
|
+
echo "Version ${VERSION} of ${PACKAGE_NAME} does not exist on npm. Proceeding with publish."
|
31
34
|
echo "skip_publish=false" >> $GITHUB_OUTPUT
|
32
35
|
fi
|
33
36
|
|
37
|
+
# --- Publish Step ---
|
34
38
|
- name: Publish to npm
|
39
|
+
# Only run this step if check_version determined skip_publish is 'false'
|
35
40
|
if: steps.check_version.outputs.skip_publish == 'false'
|
36
|
-
run: npm publish
|
41
|
+
run: npm publish
|
37
42
|
env:
|
38
43
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# @qr-platform/qr-code-js
|
2
2
|
|
3
|
+
## 0.8.21
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- dc60e82: Added useTemplate local base template option method and setTemplate global static method for QRCodeJs class
|
8
|
+
|
9
|
+
## 0.8.20
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 90fd9b4: Update to license manager domain check array
|
14
|
+
|
3
15
|
## 0.8.19
|
4
16
|
|
5
17
|
### Patch Changes
|
package/docs/examples.md
CHANGED
@@ -37,6 +37,68 @@ if (container && qrCode.svgElement) {
|
|
37
37
|
|
38
38
|
---
|
39
39
|
|
40
|
+
## Using Templates
|
41
|
+
|
42
|
+
Templates provide a way to apply a predefined set of options easily. You can use built-in templates or define your own.
|
43
|
+
|
44
|
+
**Example 1: Using a Predefined Template ('rounded')**
|
45
|
+
|
46
|
+
```javascript
|
47
|
+
// filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
|
48
|
+
|
49
|
+
// Set the 'rounded' template globally for subsequent instances
|
50
|
+
QRCodeJs.setTemplate('rounded');
|
51
|
+
|
52
|
+
const qrUsingTemplate = new QRCodeJs({
|
53
|
+
data: 'Uses the rounded template'
|
54
|
+
});
|
55
|
+
qrUsingTemplate.append(document.getElementById('template-rounded-container'));
|
56
|
+
|
57
|
+
// Note: The template remains set until changed or cleared.
|
58
|
+
```
|
59
|
+
|
60
|
+
**Example 2: Using a Custom Template Object**
|
61
|
+
|
62
|
+
```javascript
|
63
|
+
// filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
|
64
|
+
|
65
|
+
const myCustomTemplate = {
|
66
|
+
dotsOptions: { type: 'classy', color: '#8A2BE2' }, // BlueViolet classy dots
|
67
|
+
backgroundOptions: { color: '#FAFAFA' }, // Off-white background
|
68
|
+
cornersSquareOptions: { type: 'dot', color: '#8A2BE2' }
|
69
|
+
};
|
70
|
+
|
71
|
+
// Set the custom template globally
|
72
|
+
QRCodeJs.setTemplate(myCustomTemplate);
|
73
|
+
|
74
|
+
const qrCustomTemplate = new QRCodeJs({
|
75
|
+
data: 'Uses a custom template object'
|
76
|
+
});
|
77
|
+
qrCustomTemplate.append(document.getElementById('template-custom-container'));
|
78
|
+
```
|
79
|
+
|
80
|
+
**Example 3: Overriding Template Options**
|
81
|
+
|
82
|
+
```javascript
|
83
|
+
// filepath: /Users/kurdin/projects/qr-platform/qr-code-js/docs/examples.md
|
84
|
+
|
85
|
+
// Assume 'dots' template is set globally
|
86
|
+
QRCodeJs.setTemplate('dots');
|
87
|
+
|
88
|
+
const qrOverrideTemplate = new QRCodeJs({
|
89
|
+
data: 'Overrides template color',
|
90
|
+
// This color will override the black color from the 'dots' template
|
91
|
+
dotsOptions: { color: '#FF4500' } // OrangeRed dots
|
92
|
+
});
|
93
|
+
qrOverrideTemplate.append(document.getElementById('template-override-container'));
|
94
|
+
|
95
|
+
// Remember to clear the template if you don't want it for subsequent QRs
|
96
|
+
// QRCodeJs.setTemplate(null); // Or set back to 'basic' or another template
|
97
|
+
```
|
98
|
+
|
99
|
+
---
|
100
|
+
|
101
|
+
|
40
102
|
## Examples by Option Group
|
41
103
|
|
42
104
|
### Core Options
|
package/docs/usage-guide.md
CHANGED
@@ -516,6 +516,26 @@ if (validationResult.isValid) {
|
|
516
516
|
Configures a custom function for fetching license tokens.
|
517
517
|
|
518
518
|
|
519
|
+
- **`QRCodeJs.setTemplate(templateNameOrOptions: string | RecursivePartial<Options>): void`**
|
520
|
+
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.
|
521
|
+
|
522
|
+
```typescript
|
523
|
+
// Set a predefined template by name
|
524
|
+
QRCodeJs.setTemplate('rounded');
|
525
|
+
const qr1 = new QRCodeJs({ data: 'Uses rounded template' });
|
526
|
+
|
527
|
+
// Set a custom template object
|
528
|
+
const myTemplate = { dotsOptions: { type: 'classy', color: '#AA00AA' } };
|
529
|
+
QRCodeJs.setTemplate(myTemplate);
|
530
|
+
const qr2 = new QRCodeJs({ data: 'Uses custom classy template' });
|
531
|
+
|
532
|
+
// Clear the template (falls back to basic)
|
533
|
+
// @ts-expect-error - Accessing private static for testing/clearing
|
534
|
+
QRCodeJs._selectedTemplate = null;
|
535
|
+
const qr3 = new QRCodeJs({ data: 'Uses basic template again' });
|
536
|
+
```
|
537
|
+
|
538
|
+
|
519
539
|
## FAQ
|
520
540
|
|
521
541
|
### How do I handle CORS issues with embedded images?
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { QRCodeJs } from '../index';
|
2
|
+
import { QRCodeBuilderCore } from './qr-code-builder';
|
3
|
+
/**
|
4
|
+
* Builder class specifically for the browser environment.
|
5
|
+
* Extends the core builder and provides the browser QRCodeJs constructor.
|
6
|
+
*/
|
7
|
+
export declare class QRCodeBuilder extends QRCodeBuilderCore<QRCodeJs> {
|
8
|
+
/**
|
9
|
+
* Creates a new QRCodeBuilder instance for the browser.
|
10
|
+
* @param templateName - Optional name of a predefined template to start with.
|
11
|
+
*/
|
12
|
+
constructor(templateName?: string);
|
13
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { QRCodeJs } from '../node';
|
2
|
+
import { QRCodeBuilderCore } from './qr-code-builder';
|
3
|
+
/**
|
4
|
+
* Builder class specifically for the Node.js environment.
|
5
|
+
* Extends the core builder and provides the node QRCodeJs constructor.
|
6
|
+
*/
|
7
|
+
export declare class QRCodeBuilder extends QRCodeBuilderCore<QRCodeJs> {
|
8
|
+
/**
|
9
|
+
* Creates a new QRCodeBuilder instance for Node.js.
|
10
|
+
* @param templateName - Optional name of a predefined template to start with.
|
11
|
+
*/
|
12
|
+
constructor(templateName?: string);
|
13
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { QRCodeJs as QRCodeJsBase } from '../core/qr-code-js';
|
2
|
+
import { RecursivePartial } from '../types/helper';
|
3
|
+
import { Options } from '../utils/options';
|
4
|
+
type QRCodeJsConstructor<T extends QRCodeJsBase = QRCodeJsBase> = new (options: Options) => T;
|
5
|
+
/**
|
6
|
+
* Core Builder class for fluently configuring QRCodeJs instances.
|
7
|
+
* This class is generic and requires the specific QRCodeJs constructor to be passed.
|
8
|
+
*/
|
9
|
+
export declare class QRCodeBuilderCore<T extends QRCodeJsBase> {
|
10
|
+
protected config: RecursivePartial<Options>;
|
11
|
+
protected qrCodeJsConstructor: QRCodeJsConstructor<T>;
|
12
|
+
/**
|
13
|
+
* Creates a new QRCodeBuilderCore instance.
|
14
|
+
* @param qrCodeJsConstructor - The constructor of the specific QRCodeJs class to use.
|
15
|
+
* @param templateName - Optional name of a predefined template to start with.
|
16
|
+
*/
|
17
|
+
constructor(qrCodeJsConstructor: QRCodeJsConstructor<T>, templateName?: string);
|
18
|
+
/**
|
19
|
+
* Merges the provided options into the builder's configuration and creates the QRCodeJs instance.
|
20
|
+
* @param options - A partial options object to merge.
|
21
|
+
* @returns The created QRCodeJs instance.
|
22
|
+
*/
|
23
|
+
options(options: RecursivePartial<Options>): T;
|
24
|
+
}
|
25
|
+
export {};
|
package/lib/core/qr-code-js.d.ts
CHANGED
@@ -9,6 +9,7 @@ export declare enum FileExtension {
|
|
9
9
|
}
|
10
10
|
export type ExtensionFunction = (svg: SVGElement, options: RecursivePartial<Options>) => void;
|
11
11
|
export declare class QRCodeJs {
|
12
|
+
private static _selectedTemplate;
|
12
13
|
private options;
|
13
14
|
private container?;
|
14
15
|
private qr?;
|
@@ -20,6 +21,7 @@ export declare class QRCodeJs {
|
|
20
21
|
height: number;
|
21
22
|
} | undefined;
|
22
23
|
constructor(options: RecursivePartial<Options>);
|
24
|
+
static setTemplate(templateNameOrOptions: string | RecursivePartial<Options>): typeof QRCodeJs;
|
23
25
|
update(options?: RecursivePartial<Options>): Promise<void>;
|
24
26
|
append(
|
25
27
|
/** This container will be used for appending of the QR code */
|
@@ -4,3 +4,6 @@ export declare const basicQRTemplate: RecursivePartial<Options>;
|
|
4
4
|
export declare const roundedQRTemplate: RecursivePartial<Options>;
|
5
5
|
export declare const dotsQRTemplate: RecursivePartial<Options>;
|
6
6
|
export declare const classyQRTemplate: RecursivePartial<Options>;
|
7
|
+
export declare const qrTemplates: {
|
8
|
+
[key: string]: RecursivePartial<Options>;
|
9
|
+
};
|
package/lib/index.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { QRCodeBuilder } from './builder';
|
1
2
|
import { QRCodeJs as _QRCodeJs } from './core/qr-code-js';
|
2
3
|
import { type Options as QRCodeJsOptions } from './utils/options';
|
3
4
|
import { ScanValidatorResponse } from './utils/scan-validators/abstract-scan-validator';
|
@@ -45,6 +46,13 @@ export declare class QRCodeJs extends _QRCodeJs {
|
|
45
46
|
}>;
|
46
47
|
validateScanning(validatorId?: string, // Default validator
|
47
48
|
debug?: boolean): Promise<ScanValidatorResponse>;
|
49
|
+
/**
|
50
|
+
* Creates a QRCodeBuilder instance initialized with a specific template.
|
51
|
+
* Allows for fluent configuration chaining.
|
52
|
+
* @param templateName - The name of the template to start with.
|
53
|
+
* @returns A new QRCodeBuilder instance.
|
54
|
+
*/
|
55
|
+
static useTemplate(templateName: string): QRCodeBuilder;
|
48
56
|
}
|
49
57
|
export declare class _ extends QRCodeJs {
|
50
58
|
protected _hls(): boolean;
|
package/lib/node.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { QRCodeBuilder } from './builder/node';
|
1
2
|
import { QRCodeJs as _QRCodeJs } from './core/qr-code-js';
|
2
3
|
import { type ValidationResult } from './license/LicenseManagerNode';
|
3
4
|
import type * as _browserUtils from './tools/browser-utils';
|
@@ -30,6 +31,13 @@ export declare class QRCodeJs extends _QRCodeJs {
|
|
30
31
|
static setLicenseUrl(url: string): typeof QRCodeJs;
|
31
32
|
constructor(options: RecursivePartial<Options>);
|
32
33
|
validateScanning(): Promise<ScanValidatorResponse>;
|
34
|
+
/**
|
35
|
+
* Creates a QRCodeBuilder instance initialized with a specific template.
|
36
|
+
* Allows for fluent configuration chaining.
|
37
|
+
* @param templateName - The name of the template to start with.
|
38
|
+
* @returns A new QRCodeBuilder instance.
|
39
|
+
*/
|
40
|
+
static useTemplate(templateName: string): QRCodeBuilder;
|
33
41
|
}
|
34
42
|
export declare class _ extends QRCodeJs {
|
35
43
|
protected _hls(): boolean;
|