@qr-platform/qr-code.js 0.11.3 → 0.11.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qr-platform/qr-code.js",
3
- "version": "0.11.3",
3
+ "version": "0.11.5",
4
4
  "description": "QRCode.js is a professional JavaScript/TypeScript library for creating customized QR codes, offering a blend of simplicity and sophistication. With versatile styling options—dot shapes, colors, gradients, embedded images, borders, and text—it enables you to design unique, visually appealing QR codes that work flawlessly with standard scanners. QRCode.js is part of QR-Platform: All-in-One QR Codes Management Solution.",
5
5
  "type": "module",
6
6
  "main": "./lib/node.js",
@@ -1,28 +0,0 @@
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.
@@ -1,155 +0,0 @@
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];
@@ -1,124 +0,0 @@
1
- # Feature Task FT009 - Settings Option - Continuation Plan
2
-
3
- ## 1. Original Task Description (FT009)
4
-
5
- **Feature:** Settings Option
6
- **Task Description:** Add a mechanism to configure QR code instances using a comprehensive `SettingsOptions` object. This was initially planned as an instance method `setSettings()` and a static builder-style method `QRCodeJs.settings()`. The requirements evolved to include a `useSettings()` method for the `QRCodeBuilder` and to make the instance-level application a static utility method.
7
-
8
- **Core Requirements:**
9
- * Provide a centralized way to configure multiple QR code properties: `id`, `name`, `description`, `data`, `image`, `template`, `templateId`, `style`, `styleId`, `text`, `textId`, `border`, `borderId`, and a general `options` override.
10
- * Ensure this new configuration method interacts correctly with existing setup methods, generally by overriding previous settings.
11
-
12
- ## 2. Current Implementation Status
13
-
14
- ### 2.1. Core Class Changes ([`src/core/qr-code-js.ts`](src/core/qr-code-js.ts))
15
- * **`SettingsOptions` Type:** Defined in [`src/types/settings-options.ts`](src/types/settings-options.ts). It includes:
16
- ```typescript
17
- export interface SettingsOptions {
18
- id?: string;
19
- name?: string;
20
- description?: string;
21
- data?: string;
22
- image?: string | Buffer | Blob;
23
- template?: string | RecursivePartial<Options>;
24
- templateId?: string;
25
- style?: string | StyleOptions;
26
- styleId?: string;
27
- text?: string | TextOptions;
28
- textId?: string;
29
- border?: string | RecursivePartial<BorderOptions>;
30
- borderId?: string;
31
- options?: RecursivePartial<Options>;
32
- }
33
- ```
34
- * **Static `setSettings` Method:**
35
- * A `public static async setSettings(instance: QRCodeJs, settings: SettingsOptions): Promise<void>` method has been added to `QRCodeJs`.
36
- * This method applies the provided `SettingsOptions` to a given `QRCodeJs` instance.
37
- * It completely replaces the instance's current options by:
38
- 1. Starting with `baseQRTemplateOptions`.
39
- 2. Applying `template`, `style`, `text`, `border` from the `settings` object.
40
- 3. Setting `newOptions.image = settings.image` if `settings.image` is provided.
41
- 4. Setting `newOptions.data = settings.data` if `settings.data` is provided. If not, it attempts to use `settings.options.data`. If still not present, it retains `instance.options.data`.
42
- 5. Merging `settings.options` for any other direct overrides.
43
- 6. Validating and sanitizing the resulting options.
44
- 7. Calling `await instance.update()`.
45
- * **Removed Static Configuration:** The previously planned static `QRCodeJs.settings()` method (that would set static defaults like `_selectedSettings`) and related static properties (`_selectedSettings`, `_selectedData`) have been removed from `QRCodeJs` as per user feedback.
46
-
47
- ### 2.2. Documentation
48
- * [`docs/typescript-types-definitions.md`](docs/typescript-types-definitions.md): Updated with the `SettingsOptions` interface.
49
- * [`docs/api-reference-guide.md`](docs/api-reference-guide.md): Updated to reflect the new static `QRCodeJs.setSettings(instance, settings)` method and remove the old static `QRCodeJs.settings()` method.
50
- * [`docs/usage-guide.md`](docs/usage-guide.md): Updated with examples for the new static `QRCodeJs.setSettings(instance, settings)` method.
51
-
52
- ### 2.3. Unit Tests
53
- * [`tests/node/node.settings.test.ts`](tests/node/node.settings.test.ts): Initial tests for the static `setSettings(instance, settings)` method have been created and partially debugged. Import paths and type assertions have been refined.
54
-
55
- ## 3. Remaining Tasks
56
-
57
- ### 3.1. Implement `useSettings` in `QRCodeBuilder`
58
- This is the primary remaining coding task. The `useSettings` method needs to be added to the `QRCodeBuilder` class in both:
59
- * [`src/index.ts`](src/index.ts) (for browser environment)
60
- * [`src/node.ts`](src/node.ts) (for Node.js environment)
61
-
62
- **`QRCodeBuilder.useSettings(settings: SettingsOptions): this` Method Details:**
63
- * **Store Settings:**
64
- * Add a new protected property to `QRCodeBuilder`: `protected _settingsSource: SettingsOptions | null = null;`
65
- * The `useSettings` method will set `this._settingsSource = settings;`.
66
- * **Override Behavior:**
67
- * Calling `useSettings` must reset/nullify all other builder-specific configuration sources to ensure it takes precedence over any prior `useTemplate()`, `useStyle()`, `useBorder()`, `useText()`, `useImage()` calls, and `_initialOptions`. This includes:
68
- * `this._templateSource = null;`
69
- * `this._isTemplateById = false;`
70
- * `this._borderSource = null;`
71
- * `this._isBorderById = false;`
72
- * `this._styleSource = null;`
73
- * `this._isStyleById = false;`
74
- * `this._imageSource = null;`
75
- * `this._imageOverride = false;`
76
- * `this._textSource = null;`
77
- * `this._isTextById = false;`
78
- * `this._textOverride = false;`
79
- * `this._initialOptions = null;`
80
- * **Modify `_resolveAndMergeConfig(finalOptions: RecursivePartial<Options> = {})` in `QRCodeBuilder`:**
81
- * **Priority for `_settingsSource`:**
82
- 1. If `this._settingsSource` is set:
83
- * Initialize `resolvedConfig = mergeDeep({}, baseQRTemplateOptions)`.
84
- * Apply `template/templateId` from `this._settingsSource` to `resolvedConfig`.
85
- * Apply `style/styleId` from `this._settingsSource` (mapping style options) to `resolvedConfig`.
86
- * Apply `border/borderId` from `this._settingsSource` to `resolvedConfig`.
87
- * Apply `text/textId` from `this._settingsSource` (mapping to `borderOptions.decorations`) to `resolvedConfig`.
88
- * If `this._settingsSource.image` is defined, set `resolvedConfig.image = this._settingsSource.image;`.
89
- * If `this._settingsSource.data` is defined, set `resolvedConfig.data = this._settingsSource.data;`.
90
- * Merge `this._settingsSource.options` into `resolvedConfig`.
91
- * **Else (no `_settingsSource`):**
92
- * Follow the existing logic: apply `_initialOptions`, then `_templateSource`, `_borderSource`, `_styleSource`, `_imageSource` (non-override), `_textSource` (non-override).
93
- * **Final Merge & Overrides:**
94
- * Merge `finalOptions` (from a subsequent `.options()` call) into `resolvedConfig`. This allows `.options()` to override settings from `useSettings`.
95
- * The existing `_imageOverride` and `_textOverride` logic should apply last. If `useImage(..., {override:true})` or `useText(..., {override:true})` is called *after* `useSettings()`, it effectively clears `_settingsSource` (because `useSettings` resets those specific sources) and these specific overrides would then apply as intended.
96
-
97
- ### 3.2. Unit Testing
98
- * Add comprehensive unit tests for `QRCodeBuilder.useSettings` in both [`tests/node/node.settings.test.ts`](tests/node/node.settings.test.ts) and potentially a new browser-specific test file if behavior differs or requires DOM.
99
- * Tests should cover:
100
- * `useSettings` correctly applying all properties from `SettingsOptions`.
101
- * `useSettings` overriding configurations from previous `useTemplate`, `useStyle`, `useBorder`, `useText`, `useImage` calls.
102
- * A subsequent `.options()` call overriding configurations set by `useSettings`.
103
- * `.build()` using the correct configuration when `useSettings` is involved.
104
- * Interaction with `useImage(..., {override:true})` and `useText(..., {override:true})` when called after `useSettings`.
105
-
106
- ### 3.3. Documentation Updates
107
- * **[`docs/api-reference-guide.md`](docs/api-reference-guide.md):** Add `useSettings` to the `QRCodeBuilder` methods table.
108
- * **[`docs/usage-guide.md`](docs/usage-guide.md):** Add a new subsection explaining `QRCodeBuilder.useSettings` with clear examples, emphasizing its override behavior and interaction with `.options()`.
109
-
110
- ## 4. Files to be Modified for Remaining Tasks
111
- * [`src/index.ts`](src/index.ts) (for `QRCodeBuilder`)
112
- * [`src/node.ts`](src/node.ts) (for `QRCodeBuilder`)
113
- * [`tests/node/node.settings.test.ts`](tests/node/node.settings.test.ts) (and potentially new test files)
114
- * [`docs/api-reference-guide.md`](docs/api-reference-guide.md)
115
- * [`docs/usage-guide.md`](docs/usage-guide.md)
116
-
117
- ## 5. Key Considerations for `_resolveAndMergeConfig`
118
- The logic for merging needs to be precise:
119
- 1. If `_settingsSource` is present, it forms the new "base" by applying its constituent parts (template, style, border, text, image, data, options) sequentially on top of `baseQRTemplateOptions`.
120
- 2. If `_settingsSource` is NOT present, the old logic of applying `_initialOptions`, `_templateSource`, etc., applies.
121
- 3. `finalOptions` (from `.options()`) are merged *after* the above, allowing them to override anything set by `useSettings` or other builder methods.
122
- 4. Specific `override: true` calls for `useImage` or `useText` should still function as the ultimate override for those specific properties if they are called *after* `useSettings` (which would have nulled out `_settingsSource` and re-activated `_imageSource`/`_textSource`).
123
-
124
- This structured plan should allow for a smooth continuation of the task.
@@ -1,254 +0,0 @@
1
- # Feature FT009 - Settings Option Implementation Plan
2
-
3
- This document outlines the plan to implement the `setSettings()` instance method and the `.settings()` builder method for the `QRCodeJs` class, as per Task ID FT009.
4
-
5
- ## I. Define `SettingsOptions` Type
6
-
7
- 1. **Create/Update Type Definition File:**
8
- * A new file, `src/types/settings-options.ts`, will be created.
9
- * **Content:**
10
- ```typescript
11
- import { RecursivePartial } from './helper';
12
- import { Options, BorderOptions } from '../utils/options';
13
- import { StyleOptions } from './style-options';
14
- import { TextOptions } from './text-options';
15
-
16
- export interface SettingsOptions {
17
- id?: string;
18
- name?: string;
19
- description?: string;
20
- template?: string | RecursivePartial<Options>;
21
- templateId?: string;
22
- style?: string | StyleOptions;
23
- styleId?: string;
24
- text?: string | TextOptions;
25
- textId?: string;
26
- border?: string | RecursivePartial<BorderOptions>;
27
- borderId?: string;
28
- options?: RecursivePartial<Options>; // For direct overrides/merges into the main Options
29
- }
30
- ```
31
- 2. **Export:** Ensure `SettingsOptions` is exported from this new file.
32
- 3. **Import in `qr-code-js.ts`:** Add the necessary import for `SettingsOptions`.
33
-
34
- ## II. Implement Static `QRCodeJs.settings()` Method in `qr-code-js.ts`
35
-
36
- 1. **Add Static Property:**
37
- ```typescript
38
- private static _selectedSettings: SettingsOptions | null = null;
39
- ```
40
- 2. **Create Static `settings()` Method:**
41
- * Define the public static method:
42
- ```typescript
43
- public static settings(settings: SettingsOptions | null): typeof QRCodeJs {
44
- // 1. Reset all existing static configurations to ensure "replace" behavior
45
- QRCodeJs._selectedTemplate = null;
46
- QRCodeJs._selectedBorder = null;
47
- QRCodeJs._selectedStyle = null;
48
- QRCodeJs._selectedImage = null;
49
- QRCodeJs._selectedImageOverride = false;
50
- QRCodeJs._selectedText = null;
51
- QRCodeJs._selectedTextOverride = false;
52
- // Potentially other static states if any are missed here.
53
-
54
- if (settings === null) {
55
- QRCodeJs._selectedSettings = null;
56
- return QRCodeJs;
57
- }
58
-
59
- QRCodeJs._selectedSettings = settings;
60
-
61
- // 2. Apply individual configurations from the 'settings' object
62
- if (settings.templateId) {
63
- QRCodeJs.setTemplateId(settings.templateId);
64
- } else if (settings.template) {
65
- QRCodeJs.setTemplate(settings.template);
66
- }
67
-
68
- if (settings.styleId) {
69
- QRCodeJs.setStyleId(settings.styleId);
70
- } else if (settings.style) {
71
- QRCodeJs.setStyle(settings.style);
72
- }
73
-
74
- if (settings.textId) {
75
- QRCodeJs.setTextId(settings.textId);
76
- } else if (settings.text) {
77
- QRCodeJs.setText(settings.text);
78
- }
79
-
80
- if (settings.borderId) {
81
- QRCodeJs.setBorderId(settings.borderId);
82
- } else if (settings.border) {
83
- QRCodeJs.setBorder(settings.border);
84
- }
85
-
86
- return QRCodeJs;
87
- }
88
- ```
89
-
90
- ## III. Modify `QRCodeJs` Constructor in `qr-code-js.ts`
91
-
92
- * The constructor's option merging logic needs to account for `_selectedSettings`.
93
- * **Revised Constructor Logic (Conceptual):**
94
- 1. Initialize `baseOptions`.
95
- 2. Initialize `staticSettingsOptions = {}`.
96
- 3. **If `QRCodeJs._selectedSettings` exists:**
97
- * If `QRCodeJs._selectedSettings.options` exists, `staticSettingsOptions` is merged with `QRCodeJs._selectedSettings.options`.
98
- * The presence of `_selectedSettings` implies that `_selectedTemplate`, `_selectedStyle`, etc., would have already been set by the `QRCodeJs.settings()` static method. The existing constructor logic that processes these will pick up the values derived from `_selectedSettings`.
99
- 4. The merging order would be: `baseQRTemplateOptions`, then `staticSettingsOptions` (from `_selectedSettings.options`), then options from `_selectedTemplate`, `_selectedBorder`, `_selectedText`, `_selectedStyle`, `_selectedImage` (if any), and finally `rawOptions` passed to the constructor.
100
- 5. `mergeDeep` will handle the combination.
101
- 6. Proceed with validation and sanitization.
102
-
103
- ## IV. Implement Instance `setSettings()` Method in `qr-code-js.ts`
104
-
105
- 1. **Create Instance `setSettings()` Method:**
106
- ```typescript
107
- public async setSettings(settings: SettingsOptions): Promise<void> {
108
- let newOptions: RecursivePartial<Options> = { ...baseQRTemplateOptions }; // Start fresh for "replace"
109
-
110
- // 1. Apply template
111
- if (settings.templateId) {
112
- const foundTemplate = findTemplateById(settings.templateId);
113
- if (foundTemplate) newOptions = mergeDeep(newOptions, foundTemplate.options);
114
- } else if (settings.template) {
115
- if (typeof settings.template === 'string') {
116
- const foundTemplate = findTemplateByName(settings.template);
117
- if (foundTemplate) newOptions = mergeDeep(newOptions, foundTemplate.options);
118
- } else {
119
- newOptions = mergeDeep(newOptions, settings.template);
120
- }
121
- }
122
-
123
- // 2. Apply style
124
- if (settings.styleId) {
125
- const foundStyleDef = findStyleById(settings.styleId);
126
- if (foundStyleDef) newOptions = mergeDeep(newOptions, mapStyleToOptions(foundStyleDef.style));
127
- } else if (settings.style) {
128
- if (typeof settings.style === 'string') {
129
- const foundStyleDef = findStyleByName(settings.style);
130
- if (foundStyleDef) newOptions = mergeDeep(newOptions, mapStyleToOptions(foundStyleDef.style));
131
- } else {
132
- const { isValid, errors } = validateStyleOptions(settings.style);
133
- if (isValid) {
134
- newOptions = mergeDeep(newOptions, mapStyleToOptions(settings.style));
135
- } else {
136
- console.warn('Invalid style options in setSettings:', errors);
137
- }
138
- }
139
- }
140
-
141
- // 3. Apply text
142
- let textOptionsToApply: RecursivePartial<Options> = {};
143
- let textOpts: TextOptions | null = null;
144
- if (settings.textId) {
145
- const foundTextTemplate = findTextTemplateById(settings.textId);
146
- if (foundTextTemplate) textOpts = foundTextTemplate.options;
147
- } else if (settings.text) {
148
- if (typeof settings.text === 'string') {
149
- const foundTextTemplate = findTextByName(settings.text);
150
- if (foundTextTemplate) textOpts = foundTextTemplate.options;
151
- } else {
152
- textOpts = settings.text;
153
- }
154
- }
155
- if (textOpts) {
156
- // Logic to map textOpts to borderOptions.decorations (similar to constructor)
157
- if (!textOptionsToApply.borderOptions) textOptionsToApply.borderOptions = {};
158
- if (!textOptionsToApply.borderOptions.decorations) textOptionsToApply.borderOptions.decorations = {};
159
- const decorations = textOptionsToApply.borderOptions.decorations;
160
- // ... (full mapping logic for value, topValue, leftValue, etc.)
161
- newOptions = mergeDeep(newOptions, textOptionsToApply);
162
- }
163
-
164
- // 4. Apply border
165
- if (settings.borderId) {
166
- const foundBorder = findBorderById(settings.borderId);
167
- if (foundBorder) newOptions = mergeDeep(newOptions, foundBorder.options);
168
- } else if (settings.border) {
169
- if (typeof settings.border === 'string') {
170
- const foundBorder = findBorderByName(settings.border);
171
- if (foundBorder) newOptions = mergeDeep(newOptions, foundBorder.options);
172
- } else { // It's RecursivePartial<BorderOptions>
173
- newOptions = mergeDeep(newOptions, { borderOptions: settings.border });
174
- }
175
- }
176
-
177
- // 5. Apply direct options override
178
- if (settings.options) {
179
- newOptions = mergeDeep(newOptions, settings.options);
180
- }
181
-
182
- // 6. Validate and sanitize the completely new options
183
- const { warnings, validatedOptions } = validateQROptions(newOptions);
184
- if (warnings.length > 0) {
185
- this._logValidationWarnings('QR Code setSettings Validation Warnings:', warnings);
186
- }
187
-
188
- this.options = sanitizeOptions(validatedOptions as Options); // Replace current options
189
-
190
- // 7. Update the QR code
191
- await this.update();
192
- }
193
- ```
194
-
195
- ## V. Documentation and Tests
196
-
197
- 1. **Documentation:**
198
- * Add `SettingsOptions` to `docs/typescript-types-definitions.md`.
199
- * Document `QRCodeJs.settings()` and `instance.setSettings()` in `docs/api-reference-guide.md` and `docs/usage-guide.md`.
200
- * Clearly explain the "replace" behavior for both methods.
201
- * Provide usage examples.
202
- 2. **Unit Tests:**
203
- * Add comprehensive tests for static `settings()`, instance `setSettings()`, their "replace" behavior, and interactions.
204
-
205
- ## Mermaid Diagram
206
-
207
- ```mermaid
208
- graph TD
209
- subgraph Initialization
210
- A[Define SettingsOptions Interface in src/types/settings-options.ts]
211
- end
212
-
213
- subgraph Static/Builder Method
214
- B[Add static _selectedSettings to QRCodeJs]
215
- C[Implement static QRCodeJs.settings(settings)]
216
- C --> C1{settings === null?}
217
- C1 -- Yes --> C2[Reset _selectedSettings AND all other static config (_template, _style, etc.)]
218
- C1 -- No --> C3[Reset all other static config (_template, _style, etc.)]
219
- C3 --> C4[Store in _selectedSettings]
220
- C4 --> C5[Apply settings.template/Id via QRCodeJs.setTemplate/Id]
221
- C5 --> C6[Apply settings.style/Id via QRCodeJs.setStyle/Id]
222
- C6 --> C7[Apply settings.text/Id via QRCodeJs.setText/Id]
223
- C7 --> C8[Apply settings.border/Id via QRCodeJs.setBorder/Id]
224
- end
225
-
226
- subgraph Constructor Modification
227
- D[Modify QRCodeJs Constructor]
228
- D --> D1[If _selectedSettings exists, its .options form part of the base]
229
- D --> D2[Existing logic for _selectedTemplate, _selectedStyle, etc. then applies (values may come from _selectedSettings)]
230
- end
231
-
232
- subgraph Instance Method
233
- E[Implement instance.setSettings(settings)]
234
- E --> E1[Start with newOptions = baseQRTemplateOptions]
235
- E1 --> E2[Apply settings.template/Id to newOptions (mergeDeep)]
236
- E2 --> E3[Apply settings.style/Id to newOptions (map & mergeDeep)]
237
- E3 --> E4[Apply settings.text/Id to newOptions (convert & mergeDeep)]
238
- E4 --> E5[Apply settings.border/Id to newOptions (mergeDeep)]
239
- E5 --> E6[Apply settings.options to newOptions (mergeDeep)]
240
- E6 --> E7[Validate and Sanitize newOptions]
241
- E7 --> E8[this.options = sanitizedNewOptions (REPLACE)]
242
- E8 --> E9[Call this.update()]
243
- end
244
-
245
- subgraph Documentation & Testing
246
- F[Update Documentation (Type, Static Method, Instance Method)]
247
- G[Add Unit Tests (Static, Instance, Interactions, Replace Behavior)]
248
- end
249
-
250
- A --> C
251
- A --> E
252
- C8 --> D1
253
- E9 --> G
254
- F --> G
@@ -1,53 +0,0 @@
1
- # Plan: Update Documentation for `useTemplates` Feature
2
-
3
- **Objective:** Update the documentation in the `docs` directory to accurately reflect the template features, including modifying `useTemplate` to accept options directly and ensuring both `setTemplate` and the updated `useTemplate` builder pattern are correctly documented.
4
-
5
- ## Phase 1: Code Modification (To be done in Code Mode)
6
-
7
- 1. **Modify `useTemplate` Signature:**
8
- * In `src/index.ts`, change `QRCodeJs.useTemplate(templateName: string)` to `QRCodeJs.useTemplate(templateNameOrOptions: string | RecursivePartial<Options>)`.
9
- * In `src/node.ts`, make the same change: `QRCodeJs.useTemplate(templateNameOrOptions: string | RecursivePartial<Options>)`.
10
- 2. **Modify `QRCodeBuilder` Constructor:**
11
- * In `src/index.ts`, update the `QRCodeBuilder` constructor to handle the `templateNameOrOptions` parameter. If it's a string, look up the template; if it's an object, use it directly as the base configuration.
12
- * In `src/node.ts`, make the corresponding change to the `QRCodeBuilder` constructor.
13
-
14
- ## Phase 2: Documentation Update (Reflecting Both Methods)
15
-
16
- 1. **`docs/examples.md`:**
17
- * **`setTemplate` Section:** Ensure this section accurately explains setting global template defaults.
18
- * **`useTemplate` Section:** Update this section to:
19
- * Explain the builder pattern: `QRCodeJs.useTemplate(...).options({...})`.
20
- * Show examples using a template name: `useTemplate('rounded').options(...)`.
21
- * Show examples providing options directly: `useTemplate({ dotsOptions: {...} }).options(...)`.
22
- * Clarify that `.options()` is always needed to provide `data` and final overrides.
23
-
24
- 2. **`docs/usage-guide.md`:**
25
- * **`setTemplate`:** Verify its documentation is correct.
26
- * **`useTemplate`:** Update its description to reflect the new signature (`string | RecursivePartial<Options>`) and explain its use in the builder pattern.
27
- * **Static Methods List:** Ensure both `setTemplate` and the updated `useTemplate` are listed correctly.
28
-
29
- 3. **`docs/documentation.md`:**
30
- * **Verify `setTemplate`:** Ensure it's correctly described throughout (main body, API reference, FAQ).
31
- * **Update `useTemplate`:** Update its description in the API reference section to show the new signature and explain the builder pattern usage.
32
-
33
- 4. **`docs/api-reference-guide.md`:**
34
- * **Verify `setTemplate`:** Ensure it's listed correctly in the methods table.
35
- * **Update `useTemplate`:** Update the parameter type to `string | RecursivePartial<Options>` and clarify its role in initiating the builder pattern.
36
-
37
- 5. **Review Other Files:** Briefly check `advanced-examples.md`, `typescript-types-definitions.md`, and `license-management.md` for consistency regarding both `setTemplate` and the updated `useTemplate`.
38
-
39
- ## Conceptual Flow Diagram (`useTemplate`)
40
-
41
- ```mermaid
42
- graph LR
43
- subgraph useTemplate Flow
44
- A[User Code] --> B{QRCodeJs.useTemplate(nameOrOptions)};
45
- B -- name --> C[Lookup Template];
46
- B -- options --> D[Use Provided Options];
47
- C --> E{QRCodeBuilder Instance};
48
- D --> E;
49
- A --> F(Specific Options e.g., data);
50
- E --> G(builder.options(Specific Options));
51
- F --> G;
52
- G --> H(Final QRCodeJs Instance);
53
- end