zero-query 1.1.1 → 1.2.2

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 (156) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -0
  3. package/cli/args.js +33 -33
  4. package/cli/commands/build-api.js +442 -442
  5. package/cli/commands/build.js +253 -247
  6. package/cli/commands/bundle.js +1226 -1224
  7. package/cli/commands/create.js +178 -121
  8. package/cli/commands/dev/devtools/index.js +56 -56
  9. package/cli/commands/dev/devtools/js/components.js +49 -49
  10. package/cli/commands/dev/devtools/js/core.js +423 -423
  11. package/cli/commands/dev/devtools/js/elements.js +421 -421
  12. package/cli/commands/dev/devtools/js/network.js +166 -166
  13. package/cli/commands/dev/devtools/js/performance.js +73 -73
  14. package/cli/commands/dev/devtools/js/router.js +105 -105
  15. package/cli/commands/dev/devtools/js/source.js +132 -132
  16. package/cli/commands/dev/devtools/js/stats.js +35 -35
  17. package/cli/commands/dev/devtools/js/tabs.js +79 -79
  18. package/cli/commands/dev/devtools/panel.html +95 -95
  19. package/cli/commands/dev/devtools/styles.css +244 -244
  20. package/cli/commands/dev/index.js +107 -107
  21. package/cli/commands/dev/logger.js +75 -75
  22. package/cli/commands/dev/overlay.js +858 -858
  23. package/cli/commands/dev/server.js +220 -220
  24. package/cli/commands/dev/validator.js +94 -94
  25. package/cli/commands/dev/watcher.js +172 -172
  26. package/cli/help.js +114 -112
  27. package/cli/index.js +52 -52
  28. package/cli/scaffold/default/LICENSE +21 -21
  29. package/cli/scaffold/default/app/app.js +207 -207
  30. package/cli/scaffold/default/app/components/about.js +201 -201
  31. package/cli/scaffold/default/app/components/api-demo.js +143 -143
  32. package/cli/scaffold/default/app/components/contact-card.js +231 -231
  33. package/cli/scaffold/default/app/components/contacts/contacts.css +706 -706
  34. package/cli/scaffold/default/app/components/contacts/contacts.html +200 -200
  35. package/cli/scaffold/default/app/components/contacts/contacts.js +196 -196
  36. package/cli/scaffold/default/app/components/counter.js +127 -127
  37. package/cli/scaffold/default/app/components/home.js +249 -249
  38. package/cli/scaffold/default/app/components/not-found.js +16 -16
  39. package/cli/scaffold/default/app/components/playground/playground.css +115 -115
  40. package/cli/scaffold/default/app/components/playground/playground.html +161 -161
  41. package/cli/scaffold/default/app/components/playground/playground.js +116 -116
  42. package/cli/scaffold/default/app/components/todos.js +225 -225
  43. package/cli/scaffold/default/app/components/toolkit/toolkit.css +97 -97
  44. package/cli/scaffold/default/app/components/toolkit/toolkit.html +146 -146
  45. package/cli/scaffold/default/app/components/toolkit/toolkit.js +280 -280
  46. package/cli/scaffold/default/app/routes.js +15 -15
  47. package/cli/scaffold/default/app/store.js +101 -101
  48. package/cli/scaffold/default/global.css +552 -552
  49. package/cli/scaffold/default/index.html +99 -99
  50. package/cli/scaffold/minimal/app/app.js +85 -85
  51. package/cli/scaffold/minimal/app/components/about.js +68 -68
  52. package/cli/scaffold/minimal/app/components/counter.js +122 -122
  53. package/cli/scaffold/minimal/app/components/home.js +68 -68
  54. package/cli/scaffold/minimal/app/components/not-found.js +16 -16
  55. package/cli/scaffold/minimal/app/routes.js +9 -9
  56. package/cli/scaffold/minimal/app/store.js +36 -36
  57. package/cli/scaffold/minimal/global.css +300 -300
  58. package/cli/scaffold/minimal/index.html +44 -44
  59. package/cli/scaffold/ssr/app/app.js +41 -41
  60. package/cli/scaffold/ssr/app/components/about.js +55 -55
  61. package/cli/scaffold/ssr/app/components/blog/index.js +65 -65
  62. package/cli/scaffold/ssr/app/components/blog/post.js +86 -86
  63. package/cli/scaffold/ssr/app/components/home.js +37 -37
  64. package/cli/scaffold/ssr/app/components/not-found.js +15 -15
  65. package/cli/scaffold/ssr/app/routes.js +8 -8
  66. package/cli/scaffold/ssr/global.css +228 -228
  67. package/cli/scaffold/ssr/index.html +37 -37
  68. package/cli/scaffold/ssr/package.json +8 -8
  69. package/cli/scaffold/ssr/server/data/posts.js +144 -144
  70. package/cli/scaffold/ssr/server/index.js +213 -213
  71. package/cli/scaffold/webrtc/app/app.js +11 -0
  72. package/cli/scaffold/webrtc/app/components/video-room.js +441 -0
  73. package/cli/scaffold/webrtc/assets/.gitkeep +0 -0
  74. package/cli/scaffold/webrtc/global.css +250 -0
  75. package/cli/scaffold/webrtc/index.html +21 -0
  76. package/cli/scaffold/webrtc/package.json +16 -0
  77. package/cli/scaffold/webrtc/server/index.js +198 -0
  78. package/cli/utils.js +305 -287
  79. package/dist/API.md +661 -0
  80. package/dist/zquery.dist.zip +0 -0
  81. package/dist/zquery.js +10454 -6614
  82. package/dist/zquery.min.js +8 -631
  83. package/index.d.ts +570 -371
  84. package/index.js +311 -240
  85. package/package.json +77 -70
  86. package/src/component.js +1758 -1691
  87. package/src/core.js +929 -921
  88. package/src/diff.js +497 -497
  89. package/src/errors.js +209 -209
  90. package/src/expression.js +929 -922
  91. package/src/http.js +242 -242
  92. package/src/package.json +1 -1
  93. package/src/reactive.js +271 -255
  94. package/src/router.js +878 -843
  95. package/src/ssr.js +421 -418
  96. package/src/store.js +325 -318
  97. package/src/utils.js +534 -515
  98. package/src/webrtc/e2ee.js +351 -0
  99. package/src/webrtc/errors.js +116 -0
  100. package/src/webrtc/ice.js +301 -0
  101. package/src/webrtc/index.js +131 -0
  102. package/src/webrtc/joinToken.js +119 -0
  103. package/src/webrtc/observe.js +172 -0
  104. package/src/webrtc/peer.js +351 -0
  105. package/src/webrtc/reactive.js +268 -0
  106. package/src/webrtc/room.js +625 -0
  107. package/src/webrtc/sdp.js +302 -0
  108. package/src/webrtc/sfu/index.js +43 -0
  109. package/src/webrtc/sfu/livekit.js +131 -0
  110. package/src/webrtc/sfu/mediasoup.js +150 -0
  111. package/src/webrtc/signaling.js +373 -0
  112. package/src/webrtc/turn.js +237 -0
  113. package/tests/_helpers/webrtcFakes.js +289 -0
  114. package/tests/audit.test.js +4158 -4158
  115. package/tests/bench/render.bench.js +77 -0
  116. package/tests/cli.test.js +1136 -1103
  117. package/tests/compare.test.js +497 -486
  118. package/tests/component.test.js +4076 -3938
  119. package/tests/core.test.js +1926 -1910
  120. package/tests/dev-server.test.js +489 -489
  121. package/tests/diff.test.js +1416 -1416
  122. package/tests/docs.test.js +1664 -1650
  123. package/tests/electron-features.test.js +864 -864
  124. package/tests/errors.test.js +619 -619
  125. package/tests/expression.test.js +1087 -1056
  126. package/tests/http.test.js +693 -648
  127. package/tests/reactive.test.js +844 -819
  128. package/tests/router.test.js +2423 -2327
  129. package/tests/ssr.test.js +916 -870
  130. package/tests/store.test.js +840 -830
  131. package/tests/test-minifier.js +153 -153
  132. package/tests/test-ssr.js +27 -27
  133. package/tests/utils.test.js +1411 -1377
  134. package/tests/webrtc/e2ee.test.js +283 -0
  135. package/tests/webrtc/ice.test.js +202 -0
  136. package/tests/webrtc/joinToken.test.js +89 -0
  137. package/tests/webrtc/observe.test.js +111 -0
  138. package/tests/webrtc/peer.test.js +373 -0
  139. package/tests/webrtc/reactive.test.js +235 -0
  140. package/tests/webrtc/room.test.js +406 -0
  141. package/tests/webrtc/sdp.test.js +151 -0
  142. package/tests/webrtc/sfu-livekit.test.js +119 -0
  143. package/tests/webrtc/sfu.test.js +160 -0
  144. package/tests/webrtc/signaling.test.js +251 -0
  145. package/tests/webrtc/turn.test.js +256 -0
  146. package/types/collection.d.ts +383 -383
  147. package/types/component.d.ts +186 -186
  148. package/types/errors.d.ts +135 -135
  149. package/types/http.d.ts +92 -92
  150. package/types/misc.d.ts +201 -201
  151. package/types/reactive.d.ts +98 -98
  152. package/types/router.d.ts +190 -190
  153. package/types/ssr.d.ts +102 -102
  154. package/types/store.d.ts +146 -146
  155. package/types/utils.d.ts +245 -245
  156. package/types/webrtc.d.ts +653 -0
@@ -1,121 +1,178 @@
1
- // cli/commands/create.js - scaffold a new zQuery project
2
- //
3
- // Templates live in cli/scaffold/<variant>/ (default or minimal).
4
- // Reads template files, replaces {{NAME}} with the project name,
5
- // and writes them into the target directory.
6
-
7
- const fs = require('fs');
8
- const path = require('path');
9
- const { execSync, spawn } = require('child_process');
10
- const { flag } = require('../args');
11
-
12
- /**
13
- * Recursively collect every file under `dir`, returning paths relative to `dir`.
14
- */
15
- function walkDir(dir, prefix = '') {
16
- const entries = [];
17
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
18
- const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
19
- if (entry.isDirectory()) {
20
- entries.push(...walkDir(path.join(dir, entry.name), rel));
21
- } else {
22
- entries.push(rel);
23
- }
24
- }
25
- return entries;
26
- }
27
-
28
- function createProject(args) {
29
- // First positional arg after "create" is the target dir (skip flags)
30
- const dirArg = args.slice(1).find(a => !a.startsWith('-'));
31
- const target = dirArg ? path.resolve(dirArg) : process.cwd();
32
- const name = path.basename(target);
33
-
34
- // Determine scaffold variant: --minimal / -m or --ssr / -s or default
35
- const variant = flag('minimal', 'm') ? 'minimal'
36
- : flag('ssr', 's') ? 'ssr'
37
- : 'default';
38
-
39
- // Guard: refuse to overwrite existing files
40
- const checkFiles = ['index.html', 'global.css', 'app', 'assets'];
41
- if (variant === 'ssr') checkFiles.push('server');
42
- const conflicts = checkFiles.filter(f =>
43
- fs.existsSync(path.join(target, f))
44
- );
45
- if (conflicts.length) {
46
- console.error(`\n Directory already contains: ${conflicts.join(', ')}`);
47
- console.error(` Aborting to avoid overwriting existing files.\n`);
48
- process.exit(1);
49
- }
50
-
51
- console.log(`\n zQuery - Create Project (${variant})\n`);
52
- console.log(` Scaffolding into ${target}\n`);
53
-
54
- // Resolve the scaffold template directory for the chosen variant
55
- const scaffoldDir = path.resolve(__dirname, '..', 'scaffold', variant);
56
-
57
- if (!fs.existsSync(scaffoldDir)) {
58
- console.error(`\n ✗ Scaffold variant "${variant}" not found.\n`);
59
- process.exit(1);
60
- }
61
-
62
- // Walk the scaffold directory and copy each file
63
- const templateFiles = walkDir(scaffoldDir);
64
-
65
- for (const rel of templateFiles) {
66
- const src = path.join(scaffoldDir, rel);
67
- let content = fs.readFileSync(src, 'utf-8');
68
-
69
- // Replace the {{NAME}} placeholder with the actual project name
70
- content = content.replace(/\{\{NAME\}\}/g, name);
71
-
72
- const dest = path.join(target, rel);
73
- fs.mkdirSync(path.dirname(dest), { recursive: true });
74
- fs.writeFileSync(dest, content, 'utf-8');
75
- console.log(` ✓ ${rel}`);
76
- }
77
-
78
- const devCmd = `npx zquery dev${target !== process.cwd() ? ` ${dirArg}` : ''}`;
79
-
80
- if (variant === 'ssr') {
81
- console.log(`\n Installing dependencies...\n`);
82
- // Install zero-query from the same package that provides this CLI
83
- // (works both in local dev and when installed from npm)
84
- const zqRoot = path.resolve(__dirname, '..', '..');
85
- try {
86
- execSync(`npm install "${zqRoot}"`, { cwd: target, stdio: 'inherit' });
87
- } catch {
88
- console.error(`\n ✗ npm install failed. Run it manually:\n\n cd ${dirArg || '.'}\n npm install\n node server/index.js\n`);
89
- process.exit(1);
90
- }
91
-
92
- // Copy zquery.min.js into the project root so the SSR server can serve it
93
- const zqMin = path.join(target, 'node_modules', 'zero-query', 'dist', 'zquery.min.js');
94
- if (fs.existsSync(zqMin)) {
95
- fs.copyFileSync(zqMin, path.join(target, 'zquery.min.js'));
96
- console.log(` zquery.min.js`);
97
- }
98
-
99
- console.log(`\n Starting SSR server...\n`);
100
- const child = spawn('node', ['server/index.js'], { cwd: target, stdio: 'inherit' });
101
-
102
- setTimeout(() => {
103
- const open = process.platform === 'win32' ? 'start'
104
- : process.platform === 'darwin' ? 'open' : 'xdg-open';
105
- try { execSync(`${open} http://localhost:3000`, { stdio: 'ignore' }); } catch {}
106
- }, 500);
107
-
108
- process.on('SIGINT', () => { child.kill(); process.exit(); });
109
- process.on('SIGTERM', () => { child.kill(); process.exit(); });
110
- child.on('exit', (code) => process.exit(code || 0));
111
- return; // keep process alive for the server
112
- } else {
113
- console.log(`
114
- Done! Next steps:
115
-
116
- ${devCmd}
117
- `);
118
- }
119
- }
120
-
121
- module.exports = createProject;
1
+ // cli/commands/create.js - scaffold a new zQuery project
2
+ //
3
+ // Templates live in cli/scaffold/<variant>/ (default or minimal).
4
+ // Reads template files, replaces {{NAME}} with the project name,
5
+ // and writes them into the target directory.
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const { execSync, spawn } = require('child_process');
10
+ const { flag } = require('../args');
11
+
12
+ /**
13
+ * Recursively collect every file under `dir`, returning paths relative to `dir`.
14
+ */
15
+ function walkDir(dir, prefix = '') {
16
+ const entries = [];
17
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
18
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
19
+ if (entry.isDirectory()) {
20
+ entries.push(...walkDir(path.join(dir, entry.name), rel));
21
+ } else {
22
+ entries.push(rel);
23
+ }
24
+ }
25
+ return entries;
26
+ }
27
+
28
+ function createProject(args) {
29
+ // First positional arg after "create" is the target dir (skip flags)
30
+ const dirArg = args.slice(1).find(a => !a.startsWith('-'));
31
+ const target = dirArg ? path.resolve(dirArg) : process.cwd();
32
+ const name = path.basename(target);
33
+
34
+ // Determine scaffold variant: --minimal / -m or --ssr / -s or --webrtc-demo / -w or default
35
+ const variant = flag('minimal', 'm') ? 'minimal'
36
+ : flag('ssr', 's') ? 'ssr'
37
+ : flag('webrtc-demo', 'w') ? 'webrtc'
38
+ : 'default';
39
+
40
+ // Guard: refuse to overwrite existing files
41
+ const checkFiles = ['index.html', 'global.css', 'app', 'assets'];
42
+ if (variant === 'ssr' || variant === 'webrtc') checkFiles.push('server');
43
+ const conflicts = checkFiles.filter(f =>
44
+ fs.existsSync(path.join(target, f))
45
+ );
46
+ if (conflicts.length) {
47
+ console.error(`\n Directory already contains: ${conflicts.join(', ')}`);
48
+ console.error(` Aborting to avoid overwriting existing files.\n`);
49
+ process.exit(1);
50
+ }
51
+
52
+ console.log(`\n zQuery - Create Project (${variant})\n`);
53
+ console.log(` Scaffolding into ${target}\n`);
54
+
55
+ // Resolve the scaffold template directory for the chosen variant
56
+ const scaffoldDir = path.resolve(__dirname, '..', 'scaffold', variant);
57
+
58
+ if (!fs.existsSync(scaffoldDir)) {
59
+ console.error(`\n ✗ Scaffold variant "${variant}" not found.\n`);
60
+ process.exit(1);
61
+ }
62
+
63
+ // Walk the scaffold directory and copy each file
64
+ const templateFiles = walkDir(scaffoldDir);
65
+
66
+ for (const rel of templateFiles) {
67
+ const src = path.join(scaffoldDir, rel);
68
+ let content = fs.readFileSync(src, 'utf-8');
69
+
70
+ // Replace the {{NAME}} placeholder with the actual project name
71
+ content = content.replace(/\{\{NAME\}\}/g, name);
72
+
73
+ const dest = path.join(target, rel);
74
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
75
+ fs.writeFileSync(dest, content, 'utf-8');
76
+ console.log(` ✓ ${rel}`);
77
+ }
78
+
79
+ const devCmd = `npx zquery dev${target !== process.cwd() ? ` ${dirArg}` : ''}`;
80
+
81
+ // Copy zquery.min.js from the package's pre-built dist into the project root
82
+ // so file:// previews and the dev/SSR servers all serve the same minified
83
+ // bundle that ships with the installed zero-query package. The dev server
84
+ // also intercepts requests for "zquery.min.js" and will fall back to the
85
+ // package copy if the file is missing, so this is a convenience for direct
86
+ // file access (Open in Browser, etc.).
87
+ {
88
+ const zqRoot = path.resolve(__dirname, '..', '..');
89
+ const zqMin = path.join(zqRoot, 'dist', 'zquery.min.js');
90
+ if (fs.existsSync(zqMin)) {
91
+ fs.copyFileSync(zqMin, path.join(target, 'zquery.min.js'));
92
+ console.log(` ✓ zquery.min.js`);
93
+ }
94
+ }
95
+
96
+ if (variant === 'ssr') {
97
+ console.log(`\n Installing dependencies...\n`);
98
+ // Install zero-query from the same package that provides this CLI
99
+ // (works both in local dev and when installed from npm)
100
+ const zqRoot = path.resolve(__dirname, '..', '..');
101
+ try {
102
+ execSync(`npm install "${zqRoot}"`, { cwd: target, stdio: 'inherit' });
103
+ } catch {
104
+ console.error(`\n ✗ npm install failed. Run it manually:\n\n cd ${dirArg || '.'}\n npm install\n node server/index.js\n`);
105
+ process.exit(1);
106
+ }
107
+
108
+ // Copy zquery.min.js into the project root so the SSR server can serve it
109
+ const zqMin = path.join(target, 'node_modules', 'zero-query', 'dist', 'zquery.min.js');
110
+ if (fs.existsSync(zqMin)) {
111
+ fs.copyFileSync(zqMin, path.join(target, 'zquery.min.js'));
112
+ console.log(` zquery.min.js`);
113
+ }
114
+
115
+ console.log(`\n Starting SSR server...\n`);
116
+ const child = spawn('node', ['server/index.js'], { cwd: target, stdio: 'inherit' });
117
+
118
+ setTimeout(() => {
119
+ const open = process.platform === 'win32' ? 'start'
120
+ : process.platform === 'darwin' ? 'open' : 'xdg-open';
121
+ try { execSync(`${open} http://localhost:3000`, { stdio: 'ignore' }); } catch {}
122
+ }, 500);
123
+
124
+ process.on('SIGINT', () => { child.kill(); process.exit(); });
125
+ process.on('SIGTERM', () => { child.kill(); process.exit(); });
126
+ child.on('exit', (code) => process.exit(code || 0));
127
+ return; // keep process alive for the server
128
+ } else if (variant === 'webrtc') {
129
+ console.log(`\n Installing dependencies...\n`);
130
+ // Install zero-query from the same package that provides this CLI so
131
+ // local-dev and published-npm both work. Dev deps (@zero-server/sdk +
132
+ // @zero-server/webrtc) are declared in the scaffold's package.json and
133
+ // get installed by the same `npm install`. The server has its own
134
+ // install-prompt as a safety net.
135
+ const zqRoot = path.resolve(__dirname, '..', '..');
136
+ try {
137
+ execSync(`npm install "${zqRoot}"`, { cwd: target, stdio: 'inherit' });
138
+ execSync(`npm install`, { cwd: target, stdio: 'inherit' });
139
+ } catch {
140
+ console.error(`\n ✗ npm install failed. Run it manually:\n\n cd ${dirArg || '.'}\n npm install\n node server/index.js\n`);
141
+ process.exit(1);
142
+ }
143
+
144
+ // Refresh zquery.min.js from the installed package (preferred over the
145
+ // pre-copied one above so post-install rebuilds win).
146
+ const zqMin = path.join(target, 'node_modules', 'zero-query', 'dist', 'zquery.min.js');
147
+ if (fs.existsSync(zqMin)) {
148
+ fs.copyFileSync(zqMin, path.join(target, 'zquery.min.js'));
149
+ console.log(` ✓ zquery.min.js`);
150
+ }
151
+
152
+ console.log(`
153
+ Done! The WebRTC demo needs the signaling server running. In one terminal:
154
+
155
+ cd ${dirArg || '.'}
156
+ node server/index.js
157
+
158
+ Then in another terminal serve the static client:
159
+
160
+ ${devCmd}
161
+
162
+ Notes:
163
+ - Camera, microphone, and screen-share are OFF by default. Users opt-in
164
+ from inside the room.
165
+ - Set WEBRTC_JWT_SECRET to enforce signed join tokens.
166
+ - Set TURN_SECRET + TURN_URLS to issue time-limited TURN credentials.
167
+ `);
168
+ return;
169
+ } else {
170
+ console.log(`
171
+ Done! Next steps:
172
+
173
+ ${devCmd}
174
+ `);
175
+ }
176
+ }
177
+
178
+ module.exports = createProject;
@@ -1,56 +1,56 @@
1
- /**
2
- * cli/commands/dev/devtools/index.js - DevTools HTML assembler
3
- *
4
- * Reads CSS, HTML, and JS partials from this folder and concatenates them
5
- * into a single self-contained HTML page served at /_devtools.
6
- *
7
- * Communication:
8
- * - window.opener: direct DOM access (same-origin popup)
9
- * - BroadcastChannel('__zq_devtools'): cross-tab fallback
10
- */
11
-
12
- 'use strict';
13
-
14
- const { readFileSync } = require('fs');
15
- const { join } = require('path');
16
-
17
- const dir = __dirname;
18
- const read = (f) => readFileSync(join(dir, f), 'utf8');
19
-
20
- const css = read('styles.css');
21
- const html = read('panel.html');
22
-
23
- const jsFiles = [
24
- 'js/core.js',
25
- 'js/tabs.js',
26
- 'js/source.js',
27
- 'js/elements.js',
28
- 'js/network.js',
29
- 'js/components.js',
30
- 'js/performance.js',
31
- 'js/router.js',
32
- 'js/stats.js'
33
- ];
34
-
35
- const js = jsFiles.map(read).join('\n\n');
36
-
37
- module.exports = `<!DOCTYPE html>
38
- <html lang="en">
39
- <head>
40
- <meta charset="UTF-8">
41
- <meta name="viewport" content="width=device-width,initial-scale=1">
42
- <title>zQuery DevTools</title>
43
- <style>
44
- ${css}
45
- </style>
46
- </head>
47
- <body>
48
- ${html}
49
- <script>
50
- (function() {
51
- 'use strict';
52
- ${js}
53
- })();
54
- </script>
55
- </body>
56
- </html>`;
1
+ /**
2
+ * cli/commands/dev/devtools/index.js - DevTools HTML assembler
3
+ *
4
+ * Reads CSS, HTML, and JS partials from this folder and concatenates them
5
+ * into a single self-contained HTML page served at /_devtools.
6
+ *
7
+ * Communication:
8
+ * - window.opener: direct DOM access (same-origin popup)
9
+ * - BroadcastChannel('__zq_devtools'): cross-tab fallback
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ const { readFileSync } = require('fs');
15
+ const { join } = require('path');
16
+
17
+ const dir = __dirname;
18
+ const read = (f) => readFileSync(join(dir, f), 'utf8');
19
+
20
+ const css = read('styles.css');
21
+ const html = read('panel.html');
22
+
23
+ const jsFiles = [
24
+ 'js/core.js',
25
+ 'js/tabs.js',
26
+ 'js/source.js',
27
+ 'js/elements.js',
28
+ 'js/network.js',
29
+ 'js/components.js',
30
+ 'js/performance.js',
31
+ 'js/router.js',
32
+ 'js/stats.js'
33
+ ];
34
+
35
+ const js = jsFiles.map(read).join('\n\n');
36
+
37
+ module.exports = `<!DOCTYPE html>
38
+ <html lang="en">
39
+ <head>
40
+ <meta charset="UTF-8">
41
+ <meta name="viewport" content="width=device-width,initial-scale=1">
42
+ <title>zQuery DevTools</title>
43
+ <style>
44
+ ${css}
45
+ </style>
46
+ </head>
47
+ <body>
48
+ ${html}
49
+ <script>
50
+ (function() {
51
+ 'use strict';
52
+ ${js}
53
+ })();
54
+ </script>
55
+ </body>
56
+ </html>`;
@@ -1,49 +1,49 @@
1
- // ===================================================================
2
- // Components
3
- // ===================================================================
4
- function renderComponents() {
5
- var list = document.getElementById('comp-list');
6
- if (!targetWin || !targetWin.$) {
7
- list.innerHTML = '<div class="empty-state">Waiting for zQuery to load...</div>';
8
- return;
9
- }
10
- var $ = targetWin.$;
11
- var html = '';
12
-
13
- // Iterate mounted components if components registry exists
14
- if ($ && typeof $.components === 'function') {
15
- var names = Object.keys($.components());
16
- if (!names.length) {
17
- list.innerHTML = '<div class="empty-state">No components registered</div>';
18
- return;
19
- }
20
- for (var n = 0; n < names.length; n++) {
21
- var name = names[n];
22
- // Find mounted instances (exclude scoped <style> tags that carry data-zq-component)
23
- var hosts = targetDoc.querySelectorAll(name + ':not(style)');
24
- html += '<div class="comp-card">';
25
- html += '<div class="comp-name">&lt;' + name + '&gt;</div>';
26
- html += '<div class="comp-host">' + hosts.length + ' instance' + (hosts.length !== 1 ? 's' : '') + ' mounted</div>';
27
- hosts.forEach(function(host) {
28
- try {
29
- var inst = $.getInstance(host);
30
- if (inst && inst.state) {
31
- html += '<div class="comp-state">';
32
- var keys = Object.keys(inst.state);
33
- for (var k = 0; k < keys.length; k++) {
34
- var key = keys[k];
35
- var val = inst.state[key];
36
- var display = typeof val === 'object' ? JSON.stringify(val) : String(val);
37
- if (display.length > 80) display = display.slice(0, 80) + '...';
38
- html += '<div class="detail-row"><span class="comp-state-key">' + esc(key) + '</span><span class="comp-state-val">' + esc(display) + '</span></div>';
39
- }
40
- html += '</div>';
41
- }
42
- } catch(e) {}
43
- });
44
- html += '</div>';
45
- }
46
- }
47
- if (!html) html = '<div class="empty-state">No components found</div>';
48
- list.innerHTML = html;
49
- }
1
+ // ===================================================================
2
+ // Components
3
+ // ===================================================================
4
+ function renderComponents() {
5
+ var list = document.getElementById('comp-list');
6
+ if (!targetWin || !targetWin.$) {
7
+ list.innerHTML = '<div class="empty-state">Waiting for zQuery to load...</div>';
8
+ return;
9
+ }
10
+ var $ = targetWin.$;
11
+ var html = '';
12
+
13
+ // Iterate mounted components if components registry exists
14
+ if ($ && typeof $.components === 'function') {
15
+ var names = Object.keys($.components());
16
+ if (!names.length) {
17
+ list.innerHTML = '<div class="empty-state">No components registered</div>';
18
+ return;
19
+ }
20
+ for (var n = 0; n < names.length; n++) {
21
+ var name = names[n];
22
+ // Find mounted instances (exclude scoped <style> tags that carry data-zq-component)
23
+ var hosts = targetDoc.querySelectorAll(name + ':not(style)');
24
+ html += '<div class="comp-card">';
25
+ html += '<div class="comp-name">&lt;' + name + '&gt;</div>';
26
+ html += '<div class="comp-host">' + hosts.length + ' instance' + (hosts.length !== 1 ? 's' : '') + ' mounted</div>';
27
+ hosts.forEach(function(host) {
28
+ try {
29
+ var inst = $.getInstance(host);
30
+ if (inst && inst.state) {
31
+ html += '<div class="comp-state">';
32
+ var keys = Object.keys(inst.state);
33
+ for (var k = 0; k < keys.length; k++) {
34
+ var key = keys[k];
35
+ var val = inst.state[key];
36
+ var display = typeof val === 'object' ? JSON.stringify(val) : String(val);
37
+ if (display.length > 80) display = display.slice(0, 80) + '...';
38
+ html += '<div class="detail-row"><span class="comp-state-key">' + esc(key) + '</span><span class="comp-state-val">' + esc(display) + '</span></div>';
39
+ }
40
+ html += '</div>';
41
+ }
42
+ } catch(e) {}
43
+ });
44
+ html += '</div>';
45
+ }
46
+ }
47
+ if (!html) html = '<div class="empty-state">No components found</div>';
48
+ list.innerHTML = html;
49
+ }