dphelper 3.9.0 → 3.9.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.
Files changed (63) hide show
  1. package/ai-plugin.json +1 -1
  2. package/index.cjs +1 -1
  3. package/index.js +1 -1
  4. package/llms.txt +9 -3
  5. package/package.json +1 -1
  6. package/docs/README.md +0 -402
  7. package/docs/SUMMARY.md +0 -83
  8. package/docs/_config.yml +0 -1
  9. package/docs/markdown/ai.md +0 -345
  10. package/docs/markdown/anchor.md +0 -156
  11. package/docs/markdown/array.md +0 -208
  12. package/docs/markdown/audio.md +0 -113
  13. package/docs/markdown/avoid.md +0 -53
  14. package/docs/markdown/biometric.md +0 -338
  15. package/docs/markdown/browser.md +0 -203
  16. package/docs/markdown/check.md +0 -65
  17. package/docs/markdown/color.md +0 -159
  18. package/docs/markdown/compress.md +0 -310
  19. package/docs/markdown/cookie.md +0 -115
  20. package/docs/markdown/coords.md +0 -127
  21. package/docs/markdown/credits.md +0 -56
  22. package/docs/markdown/date.md +0 -260
  23. package/docs/markdown/disable.md +0 -109
  24. package/docs/markdown/dispatch.md +0 -108
  25. package/docs/markdown/element.md +0 -53
  26. package/docs/markdown/event.md +0 -85
  27. package/docs/markdown/fetch.md +0 -122
  28. package/docs/markdown/form.md +0 -302
  29. package/docs/markdown/format.md +0 -122
  30. package/docs/markdown/i18n.md +0 -292
  31. package/docs/markdown/image.md +0 -298
  32. package/docs/markdown/json.md +0 -269
  33. package/docs/markdown/load.md +0 -133
  34. package/docs/markdown/logging.md +0 -99
  35. package/docs/markdown/math.md +0 -172
  36. package/docs/markdown/memory.md +0 -85
  37. package/docs/markdown/navigation.md +0 -152
  38. package/docs/markdown/net.md +0 -60
  39. package/docs/markdown/obj.md +0 -242
  40. package/docs/markdown/path.md +0 -46
  41. package/docs/markdown/promise.md +0 -94
  42. package/docs/markdown/sanitize.md +0 -118
  43. package/docs/markdown/screen.md +0 -78
  44. package/docs/markdown/scrollbar.md +0 -82
  45. package/docs/markdown/security.md +0 -289
  46. package/docs/markdown/shortcut.md +0 -100
  47. package/docs/markdown/socket.md +0 -134
  48. package/docs/markdown/sse.md +0 -120
  49. package/docs/markdown/svg.md +0 -167
  50. package/docs/markdown/sync.md +0 -147
  51. package/docs/markdown/system.md +0 -78
  52. package/docs/markdown/terminal.md +0 -73
  53. package/docs/markdown/text.md +0 -245
  54. package/docs/markdown/timer.md +0 -98
  55. package/docs/markdown/tools.md +0 -111
  56. package/docs/markdown/translators.md +0 -65
  57. package/docs/markdown/trigger.md +0 -99
  58. package/docs/markdown/triggers.md +0 -133
  59. package/docs/markdown/type.md +0 -109
  60. package/docs/markdown/types.md +0 -102
  61. package/docs/markdown/ui.md +0 -45
  62. package/docs/markdown/window.md +0 -211
  63. package/docs/markdown/worker.md +0 -223
@@ -1,223 +0,0 @@
1
- # worker
2
-
3
- Web Worker management utilities for multi-threaded JavaScript execution, including worker creation, pool management, and parallel task processing.
4
-
5
- ## Functions
6
-
7
- | Function | Description | Example |
8
- |----------|-------------|---------|
9
- | `create` | Create a worker from URL | `dphelper.worker.create('worker.js', { onmessage: (e) => console.log(e.data) })` |
10
- | `createInline` | Create worker from inline code | `dphelper.worker.createInline('self.onmessage = e => postMessage(e.data * 2)')` |
11
- | `post` | Send message to worker | `dphelper.worker.post(worker, { type: 'compute', data: 42 })` |
12
- | `terminate` | Stop a worker | `dphelper.worker.terminate(worker)` |
13
- | `pool` | Create worker pool | `dphelper.worker.pool('worker.js', 4)` |
14
- | `poolExec` | Execute tasks in pool | `dphelper.worker.poolExec(pool, tasks)` |
15
- | `importScripts` | Import scripts into worker | `dphelper.worker.importScripts(worker, ['lib1.js', 'lib2.js'])` |
16
- | `shared` | Create SharedWorker | `dphelper.worker.shared('my-worker.js', { name: 'shared' })` |
17
-
18
- ## Description
19
-
20
- Powerful Web Worker management module providing:
21
- - **Inline Workers** - Create workers from JavaScript strings without external files
22
- - **Worker Pools** - Manage multiple workers for parallel processing
23
- - **SharedWorkers** - Cross-tab communication via shared worker
24
- - **Script Import** - Dynamically import external scripts into workers
25
- - **Transferable Support** - Efficient data transfer using Transferable objects
26
-
27
- ## Usage Examples
28
-
29
- ### Basic Worker Creation
30
-
31
- ```javascript
32
- // Create worker from external file
33
- const worker = dphelper.worker.create('worker.js', {
34
- onmessage: (e) => {
35
- console.log('Received:', e.data);
36
- },
37
- onerror: (e) => {
38
- console.error('Worker error:', e);
39
- }
40
- });
41
-
42
- // Send message to worker
43
- dphelper.worker.post(worker, { type: 'hello', data: 'world' });
44
-
45
- // When done, terminate worker
46
- dphelper.worker.terminate(worker);
47
- ```
48
-
49
- ### Inline Workers
50
-
51
- ```javascript
52
- // Create worker from inline code
53
- const worker = dphelper.worker.createInline(`
54
- self.onmessage = function(e) {
55
- // Perform heavy computation
56
- const result = e.data * 2;
57
- postMessage(result);
58
- };
59
- `, {
60
- onmessage: (e) => {
61
- console.log('Result:', e.data); // 84
62
- }
63
- });
64
-
65
- dphelper.worker.post(worker, 42);
66
- ```
67
-
68
- ### Worker Pool for Parallel Processing
69
-
70
- ```javascript
71
- // Create a pool of 4 workers
72
- const pool = dphelper.worker.pool('compute-worker.js', 4);
73
-
74
- // Prepare tasks
75
- const tasks = [
76
- { id: 1, data: 100 },
77
- { id: 2, data: 200 },
78
- { id: 3, data: 300 },
79
- { id: 4, data: 400 },
80
- { id: 5, data: 500 }
81
- ];
82
-
83
- // Execute all tasks in parallel across the pool
84
- const results = await dphelper.worker.poolExec(pool, tasks);
85
- console.log(results); // [200, 400, 600, 800, 1000]
86
- ```
87
-
88
- ### SharedWorker for Cross-Tab Communication
89
-
90
- ```javascript
91
- // Create shared worker (accessible from multiple tabs)
92
- const shared = dphelper.worker.shared('shared-worker.js', {
93
- name: 'my-shared-worker',
94
- onconnect: (e) => {
95
- console.log('New connection:', e.ports[0]);
96
- },
97
- onmessage: (e) => {
98
- console.log('Shared message:', e.data);
99
- }
100
- });
101
-
102
- // Send message through port
103
- shared.port.postMessage({ type: 'hello' });
104
- shared.port.start();
105
- ```
106
-
107
- ### Importing Scripts
108
-
109
- ```javascript
110
- const worker = dphelper.worker.create('main-worker.js');
111
-
112
- // Import external libraries into worker
113
- dphelper.worker.importScripts(worker, [
114
- 'https://cdn.example.com/lib1.js',
115
- 'https://cdn.example.com/lib2.js'
116
- ]);
117
- ```
118
-
119
- ## Advanced Usage
120
-
121
- ### Parallel Data Processing
122
-
123
- ```javascript
124
- // Worker file: data-processor.js
125
- /*
126
- self.onmessage = function(e) {
127
- const { id, numbers } = e.data;
128
-
129
- // Heavy computation
130
- const sum = numbers.reduce((a, b) => a + b, 0);
131
- const avg = sum / numbers.length;
132
-
133
- postMessage({ id, sum, avg });
134
- };
135
- */
136
-
137
- async function processData(items) {
138
- const pool = dphelper.worker.pool('data-processor.js', navigator.hardwareConcurrency || 4);
139
-
140
- const tasks = items.map((item, index) => ({
141
- index,
142
- data: { id: item.id, numbers: item.values }
143
- }));
144
-
145
- const results = await dphelper.worker.poolExec(pool, tasks);
146
-
147
- // Sort by original index
148
- return results.sort((a, b) => a.id - b.id);
149
- }
150
-
151
- // Usage
152
- const data = [
153
- { id: 1, values: [1, 2, 3, 4, 5] },
154
- { id: 2, values: [10, 20, 30] },
155
- { id: 3, values: [100, 200] }
156
- ];
157
-
158
- const processed = await processData(data);
159
- console.log(processed);
160
- ```
161
-
162
- ### Real-time Communication with Pool
163
-
164
- ```javascript
165
- class WorkerPoolManager {
166
- constructor(workerScript, poolSize = 4) {
167
- this.pool = dphelper.worker.pool(workerScript, poolSize);
168
- this.results = new Map();
169
- }
170
-
171
- async processTask(taskId, data) {
172
- return new Promise((resolve, reject) => {
173
- const handler = (e) => {
174
- if (e.data.taskId === taskId) {
175
- this.results.delete(taskId);
176
- resolve(e.data.result);
177
- }
178
- };
179
-
180
- this.pool.workers.forEach(w => w.addEventListener('message', handler));
181
-
182
- dphelper.worker.post(this.pool.workers[0], { taskId, data });
183
- });
184
- }
185
-
186
- terminate() {
187
- this.pool.workers.forEach(w => dphelper.worker.terminate(w));
188
- }
189
- }
190
- ```
191
-
192
- ### Web Worker with Transferables
193
-
194
- ```javascript
195
- // Efficiently transfer large data without copying
196
- const buffer = new ArrayBuffer(1024 * 1024); // 1MB
197
- const numbers = new Uint8Array(buffer);
198
-
199
- // Fill with data...
200
-
201
- const worker = dphelper.worker.createInline(`
202
- self.onmessage = function(e) {
203
- const data = new Uint8Array(e.data.buffer);
204
- // Process data...
205
- postMessage({ processed: true }, [e.data.buffer]);
206
- };
207
- `);
208
-
209
- // Transfer the buffer ownership to worker
210
- dphelper.worker.post(worker, numbers, [buffer]);
211
- ```
212
-
213
- ## Details
214
-
215
- - **Author:** Dario Passariello
216
- - **Version:** 0.0.1
217
- - **Creation Date:** 20260313
218
- - **Last Modified:** 20260313
219
- - **Environment:** Client-side only (browser)
220
-
221
- ---
222
-
223
- *Automatically generated document*