zero-query 0.9.9 → 1.0.1

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 (99) hide show
  1. package/README.md +34 -33
  2. package/cli/args.js +1 -1
  3. package/cli/commands/build.js +2 -2
  4. package/cli/commands/bundle.js +21 -18
  5. package/cli/commands/create.js +9 -2
  6. package/cli/commands/dev/devtools/index.js +1 -1
  7. package/cli/commands/dev/devtools/js/core.js +14 -14
  8. package/cli/commands/dev/devtools/js/elements.js +4 -4
  9. package/cli/commands/dev/devtools/js/stats.js +1 -1
  10. package/cli/commands/dev/devtools/styles.css +2 -2
  11. package/cli/commands/dev/index.js +2 -2
  12. package/cli/commands/dev/logger.js +1 -1
  13. package/cli/commands/dev/overlay.js +21 -14
  14. package/cli/commands/dev/server.js +5 -5
  15. package/cli/commands/dev/validator.js +7 -7
  16. package/cli/commands/dev/watcher.js +6 -6
  17. package/cli/help.js +3 -3
  18. package/cli/index.js +1 -1
  19. package/cli/scaffold/default/app/app.js +17 -18
  20. package/cli/scaffold/default/app/components/about.js +9 -9
  21. package/cli/scaffold/default/app/components/api-demo.js +6 -6
  22. package/cli/scaffold/default/app/components/contact-card.js +4 -4
  23. package/cli/scaffold/default/app/components/contacts/contacts.css +2 -2
  24. package/cli/scaffold/default/app/components/contacts/contacts.html +3 -3
  25. package/cli/scaffold/default/app/components/contacts/contacts.js +11 -11
  26. package/cli/scaffold/default/app/components/counter.js +8 -8
  27. package/cli/scaffold/default/app/components/home.js +13 -13
  28. package/cli/scaffold/default/app/components/not-found.js +1 -1
  29. package/cli/scaffold/default/app/components/playground/playground.css +1 -1
  30. package/cli/scaffold/default/app/components/playground/playground.html +11 -11
  31. package/cli/scaffold/default/app/components/playground/playground.js +11 -11
  32. package/cli/scaffold/default/app/components/todos.js +8 -8
  33. package/cli/scaffold/default/app/components/toolkit/toolkit.css +1 -1
  34. package/cli/scaffold/default/app/components/toolkit/toolkit.html +4 -4
  35. package/cli/scaffold/default/app/components/toolkit/toolkit.js +7 -7
  36. package/cli/scaffold/default/app/routes.js +1 -1
  37. package/cli/scaffold/default/app/store.js +1 -1
  38. package/cli/scaffold/default/global.css +2 -2
  39. package/cli/scaffold/default/index.html +2 -2
  40. package/cli/scaffold/minimal/app/app.js +6 -7
  41. package/cli/scaffold/minimal/app/components/about.js +5 -5
  42. package/cli/scaffold/minimal/app/components/counter.js +6 -6
  43. package/cli/scaffold/minimal/app/components/home.js +8 -8
  44. package/cli/scaffold/minimal/app/components/not-found.js +1 -1
  45. package/cli/scaffold/minimal/app/routes.js +1 -1
  46. package/cli/scaffold/minimal/app/store.js +1 -1
  47. package/cli/scaffold/minimal/global.css +2 -2
  48. package/cli/scaffold/minimal/index.html +1 -1
  49. package/cli/scaffold/ssr/app/app.js +1 -2
  50. package/cli/scaffold/ssr/app/components/about.js +5 -5
  51. package/cli/scaffold/ssr/app/components/home.js +2 -2
  52. package/cli/scaffold/ssr/app/components/not-found.js +2 -2
  53. package/cli/scaffold/ssr/app/routes.js +1 -1
  54. package/cli/scaffold/ssr/global.css +3 -4
  55. package/cli/scaffold/ssr/index.html +2 -2
  56. package/cli/scaffold/ssr/server/index.js +26 -25
  57. package/cli/utils.js +6 -6
  58. package/dist/zquery.dist.zip +0 -0
  59. package/dist/zquery.js +508 -227
  60. package/dist/zquery.min.js +2 -2
  61. package/index.d.ts +16 -13
  62. package/index.js +7 -5
  63. package/package.json +3 -3
  64. package/src/component.js +64 -63
  65. package/src/core.js +15 -15
  66. package/src/diff.js +38 -38
  67. package/src/errors.js +17 -17
  68. package/src/expression.js +15 -17
  69. package/src/http.js +4 -4
  70. package/src/reactive.js +75 -9
  71. package/src/router.js +104 -24
  72. package/src/ssr.js +28 -28
  73. package/src/store.js +103 -21
  74. package/src/utils.js +64 -12
  75. package/tests/audit.test.js +143 -15
  76. package/tests/cli.test.js +20 -20
  77. package/tests/component.test.js +121 -121
  78. package/tests/core.test.js +56 -56
  79. package/tests/diff.test.js +42 -42
  80. package/tests/errors.test.js +5 -5
  81. package/tests/expression.test.js +58 -53
  82. package/tests/http.test.js +20 -20
  83. package/tests/reactive.test.js +185 -24
  84. package/tests/router.test.js +501 -74
  85. package/tests/ssr.test.js +15 -13
  86. package/tests/store.test.js +264 -23
  87. package/tests/test-minifier.js +153 -0
  88. package/tests/test-ssr.js +27 -0
  89. package/tests/utils.test.js +163 -26
  90. package/types/collection.d.ts +2 -2
  91. package/types/component.d.ts +5 -5
  92. package/types/errors.d.ts +3 -3
  93. package/types/http.d.ts +3 -3
  94. package/types/misc.d.ts +9 -9
  95. package/types/reactive.d.ts +25 -3
  96. package/types/router.d.ts +10 -6
  97. package/types/ssr.d.ts +2 -2
  98. package/types/store.d.ts +40 -5
  99. package/types/utils.d.ts +1 -1
@@ -1,7 +1,7 @@
1
- // server/index.js SSR HTTP server
1
+ // server/index.js - SSR HTTP server
2
2
  //
3
3
  // Renders routes to HTML with zQuery SSR and serves them over HTTP.
4
- // Components are imported from app/components/ the same definitions
4
+ // Components are imported from app/components/ - the same definitions
5
5
  // the client uses.
6
6
  //
7
7
  // Usage:
@@ -14,7 +14,7 @@ import { join, extname, resolve } from 'node:path';
14
14
  import { fileURLToPath } from 'node:url';
15
15
  import { createSSRApp } from 'zero-query/ssr';
16
16
 
17
- // Shared component definitions same ones the client registers
17
+ // Shared component definitions - same ones the client registers
18
18
  import { homePage } from '../app/components/home.js';
19
19
  import { aboutPage } from '../app/components/about.js';
20
20
  import { notFound } from '../app/components/not-found.js';
@@ -40,32 +40,33 @@ function matchRoute(pathname) {
40
40
 
41
41
  // --- Render a full HTML page ------------------------------------------------
42
42
 
43
+ // Read the index.html shell once at startup — it already has z-link nav,
44
+ // client scripts (zquery.min.js + app/app.js), and the <z-outlet> tag.
45
+ // On each request we just inject the SSR body into <z-outlet>.
46
+ let shellCache = null;
47
+ async function getShell() {
48
+ if (!shellCache) shellCache = await readFile(join(ROOT, 'index.html'), 'utf-8');
49
+ return shellCache;
50
+ }
51
+
43
52
  async function render(pathname) {
44
53
  const component = matchRoute(pathname);
45
54
  const body = await app.renderToString(component);
55
+ const shell = await getShell();
56
+
57
+ // Inject SSR content into <z-outlet …> and add active class to nav
58
+ let html = shell.replace(/(<z-outlet[^>]*>)(<\/z-outlet>)?/, `$1${body}</z-outlet>`);
59
+
60
+ // Mark the active nav link for the current route
61
+ html = html.replace(
62
+ /(<a\s+z-link="([^"]*)"[^>]*class="nav-link)(">)/g,
63
+ (match, before, href, after) =>
64
+ href === pathname
65
+ ? `${before} active${after}`
66
+ : `${before}${after}`
67
+ );
46
68
 
47
- return `<!DOCTYPE html>
48
- <html lang="en">
49
- <head>
50
- <meta charset="UTF-8">
51
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
52
- <title>{{NAME}}</title>
53
- <link rel="stylesheet" href="/global.css">
54
- </head>
55
- <body>
56
- <nav class="navbar">
57
- <span class="brand">⚡ {{NAME}}</span>
58
- <div class="nav-links">
59
- ${routes.map(r =>
60
- ` <a href="${r.path}" class="nav-link${r.path === pathname ? ' active' : ''}">${
61
- r.path === '/' ? 'Home' : r.path.slice(1)[0].toUpperCase() + r.path.slice(2)
62
- }</a>`).join('\n')}
63
- </div>
64
- </nav>
65
- <main id="app">${body}</main>
66
- <footer class="footer"><small>Built with zQuery · SSR</small></footer>
67
- </body>
68
- </html>`;
69
+ return html;
69
70
  }
70
71
 
71
72
  // --- Static files -----------------------------------------------------------
package/cli/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * cli/utils.js shared utility functions
2
+ * cli/utils.js - shared utility functions
3
3
  *
4
4
  * Context-aware comment stripping, quick minification, size formatting,
5
5
  * and recursive directory copying. These are consumed by both the
@@ -12,7 +12,7 @@ const fs = require('fs');
12
12
  const path = require('path');
13
13
 
14
14
  // ---------------------------------------------------------------------------
15
- // _copyTemplateLiteral copy a template literal verbatim, tracking ${…}
15
+ // _copyTemplateLiteral - copy a template literal verbatim, tracking ${…}
16
16
  // nesting so that `//` inside template text isn't mistaken for a comment.
17
17
  // ---------------------------------------------------------------------------
18
18
 
@@ -49,7 +49,7 @@ function _copyTemplateLiteral(code, start) {
49
49
  }
50
50
 
51
51
  // ---------------------------------------------------------------------------
52
- // stripComments context-aware, skips strings / templates / regex
52
+ // stripComments - context-aware, skips strings / templates / regex
53
53
  // ---------------------------------------------------------------------------
54
54
 
55
55
  function stripComments(code) {
@@ -127,7 +127,7 @@ function stripComments(code) {
127
127
  }
128
128
 
129
129
  // ---------------------------------------------------------------------------
130
- // minify single-pass minification
130
+ // minify - single-pass minification
131
131
  // Strips comments, collapses whitespace to the minimum required,
132
132
  // and preserves string / template-literal / regex content verbatim.
133
133
  // ---------------------------------------------------------------------------
@@ -251,7 +251,7 @@ function _isRegexCtx(out) {
251
251
  }
252
252
 
253
253
  // ---------------------------------------------------------------------------
254
- // sizeKB human-readable file size
254
+ // sizeKB - human-readable file size
255
255
  // ---------------------------------------------------------------------------
256
256
 
257
257
  function sizeKB(buf) {
@@ -259,7 +259,7 @@ function sizeKB(buf) {
259
259
  }
260
260
 
261
261
  // ---------------------------------------------------------------------------
262
- // copyDirSync recursive directory copy
262
+ // copyDirSync - recursive directory copy
263
263
  // ---------------------------------------------------------------------------
264
264
 
265
265
  function copyDirSync(src, dest) {
Binary file