zero-query 1.0.0 → 1.0.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.
- package/README.md +48 -7
- package/cli/commands/bundle.js +6 -3
- package/cli/commands/create.js +7 -0
- package/cli/help.js +2 -1
- package/cli/index.js +1 -1
- package/cli/scaffold/default/app/app.js +3 -6
- package/cli/scaffold/default/global.css +13 -4
- package/cli/scaffold/default/index.html +8 -8
- package/cli/scaffold/minimal/app/app.js +3 -9
- package/cli/scaffold/minimal/global.css +13 -4
- package/cli/scaffold/minimal/index.html +3 -3
- package/cli/scaffold/ssr/app/app.js +18 -6
- package/cli/scaffold/ssr/app/components/about.js +42 -15
- package/cli/scaffold/ssr/app/components/blog/index.js +65 -0
- package/cli/scaffold/ssr/app/components/blog/post.js +78 -0
- package/cli/scaffold/ssr/app/components/not-found.js +1 -1
- package/cli/scaffold/ssr/app/routes.js +4 -2
- package/cli/scaffold/ssr/global.css +118 -3
- package/cli/scaffold/ssr/index.html +9 -3
- package/cli/scaffold/ssr/server/data/posts.js +144 -0
- package/cli/scaffold/ssr/server/index.js +168 -27
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +21 -6
- package/dist/zquery.min.js +2 -2
- package/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/component.js +17 -2
- package/tests/component.test.js +480 -0
- package/tests/test-minifier.js +153 -0
- package/tests/test-ssr.js +27 -0
- package/types/misc.d.ts +23 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
function minifyCSS(css) {
|
|
2
|
+
css = css.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
3
|
+
css = css.replace(/\s{2,}/g, ' ');
|
|
4
|
+
css = css.replace(/\s*([{};,])\s*/g, '$1');
|
|
5
|
+
css = css.replace(/:\s+/g, ':');
|
|
6
|
+
css = css.replace(/;}/g, '}');
|
|
7
|
+
return css.trim();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const tests = [
|
|
11
|
+
// Pseudo-classes with descendant combinator (the bug was that the space before :not() was being removed, which is incorrect)
|
|
12
|
+
['.docs-section :not(pre) > code { color: red }', 'space before :not()'],
|
|
13
|
+
['.foo :has(.bar) { color: red }', 'space before :has()'],
|
|
14
|
+
['.foo :is(.a, .b) { color: red }', 'space before :is()'],
|
|
15
|
+
['.foo :where(.a) { color: red }', 'space before :where()'],
|
|
16
|
+
|
|
17
|
+
// Pseudo-elements
|
|
18
|
+
['.foo::before { content: "x" }', '::before'],
|
|
19
|
+
['.foo ::after { content: "x" }', 'space before ::after'],
|
|
20
|
+
|
|
21
|
+
// Pseudo-classes directly on element (no space - should stay compact)
|
|
22
|
+
['a:hover { color: red }', ':hover no space'],
|
|
23
|
+
['li:nth-child(2n + 1) { color: red }', ':nth-child()'],
|
|
24
|
+
['input:focus-visible { outline: 1px }', ':focus-visible'],
|
|
25
|
+
|
|
26
|
+
// calc() - spaces around operators are significant!
|
|
27
|
+
['.foo { width: calc(100% - 20px) }', 'calc() spaces'],
|
|
28
|
+
['.foo { width: calc(50vw + 2rem) }', 'calc() addition'],
|
|
29
|
+
['.foo { font-size: clamp(1rem, 2vw, 3rem) }', 'clamp()'],
|
|
30
|
+
|
|
31
|
+
// @media
|
|
32
|
+
['@media (min-width: 768px) { .foo { color: red } }', '@media query'],
|
|
33
|
+
['@media screen and (max-width: 1024px) { .a { } }', '@media screen and'],
|
|
34
|
+
|
|
35
|
+
// Selector combinators
|
|
36
|
+
['.foo > .bar { color: red }', 'child combinator >'],
|
|
37
|
+
['.foo + .bar { color: red }', 'adjacent sibling +'],
|
|
38
|
+
['.foo ~ .bar { color: red }', 'general sibling ~'],
|
|
39
|
+
['.foo .bar { color: red }', 'descendant combinator'],
|
|
40
|
+
|
|
41
|
+
// Custom properties
|
|
42
|
+
['body { --main-color: #333; color: var(--main-color) }', 'CSS variables'],
|
|
43
|
+
|
|
44
|
+
// Attribute selectors
|
|
45
|
+
['[data-theme="dark"] { color: white }', 'attribute selector'],
|
|
46
|
+
['a[href^="https:"] { color: green }', 'attr with colon'],
|
|
47
|
+
|
|
48
|
+
// content with quotes
|
|
49
|
+
['.foo::before { content: "Hello World" }', 'content string'],
|
|
50
|
+
|
|
51
|
+
// Multiple selectors with newlines
|
|
52
|
+
['.a,\n.b,\n.c { color: red }', 'selector list'],
|
|
53
|
+
|
|
54
|
+
// Keyframes
|
|
55
|
+
['@keyframes fade { 0% { opacity: 0 } 100% { opacity: 1 } }', '@keyframes'],
|
|
56
|
+
|
|
57
|
+
// Nested :not with pseudo-class inside
|
|
58
|
+
['.foo :not(:last-child) { margin: 0 }', ':not(:last-child)'],
|
|
59
|
+
|
|
60
|
+
// Double :not
|
|
61
|
+
['.bar :not(.a):not(.b) { color: red }', 'chained :not()'],
|
|
62
|
+
|
|
63
|
+
// :first-child as descendant
|
|
64
|
+
['.list :first-child { font-weight: bold }', 'space before :first-child'],
|
|
65
|
+
|
|
66
|
+
// content with multiple spaces (potential issue)
|
|
67
|
+
['.foo::before { content: "a b" }', 'content double space'],
|
|
68
|
+
|
|
69
|
+
// grid-template-areas
|
|
70
|
+
['.grid { grid-template-areas: "a a" "b c" }', 'grid-template-areas'],
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
console.log('=== CSS Minifier Edge Case Tests ===\n');
|
|
74
|
+
let issues = 0;
|
|
75
|
+
for (const [input, label] of tests) {
|
|
76
|
+
const result = minifyCSS(input);
|
|
77
|
+
console.log(`${label.padEnd(30)}| ${result}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Specific assertions
|
|
81
|
+
console.log('\n=== Assertions ===\n');
|
|
82
|
+
function assert(input, expected, label) {
|
|
83
|
+
const result = minifyCSS(input);
|
|
84
|
+
const pass = result === expected;
|
|
85
|
+
console.log(`${pass ? 'PASS' : 'FAIL'} ${label}`);
|
|
86
|
+
if (!pass) {
|
|
87
|
+
console.log(` Expected: ${expected}`);
|
|
88
|
+
console.log(` Got: ${result}`);
|
|
89
|
+
issues++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
assert('.parent :not(pre) > code { color: red }',
|
|
94
|
+
'.parent :not(pre) > code{color:red}',
|
|
95
|
+
'space before :not() preserved');
|
|
96
|
+
|
|
97
|
+
assert('a:hover { color: red }',
|
|
98
|
+
'a:hover{color:red}',
|
|
99
|
+
':hover stays compact');
|
|
100
|
+
|
|
101
|
+
assert('.foo { width: calc(100% - 20px) }',
|
|
102
|
+
'.foo{width:calc(100% - 20px)}',
|
|
103
|
+
'calc() spaces preserved');
|
|
104
|
+
|
|
105
|
+
assert('@media (min-width: 768px) { .a { color: red } }',
|
|
106
|
+
'@media (min-width:768px){.a{color:red}}',
|
|
107
|
+
'@media colon stripped');
|
|
108
|
+
|
|
109
|
+
assert('.foo > .bar { color: red }',
|
|
110
|
+
'.foo > .bar{color:red}',
|
|
111
|
+
'child combinator preserved');
|
|
112
|
+
|
|
113
|
+
assert('.foo + .bar { color: red }',
|
|
114
|
+
'.foo + .bar{color:red}',
|
|
115
|
+
'adjacent sibling preserved');
|
|
116
|
+
|
|
117
|
+
assert('.foo .bar { color: red }',
|
|
118
|
+
'.foo .bar{color:red}',
|
|
119
|
+
'descendant space preserved');
|
|
120
|
+
|
|
121
|
+
assert('.foo::before { content: "x" }',
|
|
122
|
+
'.foo::before{content:"x"}',
|
|
123
|
+
'::before works');
|
|
124
|
+
|
|
125
|
+
assert('.foo ::after { content: "x" }',
|
|
126
|
+
'.foo ::after{content:"x"}',
|
|
127
|
+
'space before ::after preserved');
|
|
128
|
+
|
|
129
|
+
assert('li:nth-child(2n + 1) { color: red }',
|
|
130
|
+
'li:nth-child(2n + 1){color:red}',
|
|
131
|
+
':nth-child args preserved');
|
|
132
|
+
|
|
133
|
+
assert('.list :first-child { font-weight: bold }',
|
|
134
|
+
'.list :first-child{font-weight:bold}',
|
|
135
|
+
'space before :first-child preserved');
|
|
136
|
+
|
|
137
|
+
assert('.list :last-child { font-weight: bold }',
|
|
138
|
+
'.list :last-child{font-weight:bold}',
|
|
139
|
+
'space before :last-child preserved');
|
|
140
|
+
|
|
141
|
+
assert('.bar :not(.a):not(.b) { color: red }',
|
|
142
|
+
'.bar :not(.a):not(.b){color:red}',
|
|
143
|
+
'chained :not() with leading space');
|
|
144
|
+
|
|
145
|
+
// Edge case: content with double spaces inside quotes
|
|
146
|
+
const dblSpace = minifyCSS('.foo::before { content: "a b" }');
|
|
147
|
+
if (dblSpace.includes('content:"a b"')) {
|
|
148
|
+
console.log('WARN content double space - "a b" collapsed to "a b" (cosmetic, not functional)');
|
|
149
|
+
} else {
|
|
150
|
+
console.log('PASS content double space preserved');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
console.log(`\n${issues === 0 ? 'All assertions passed!' : issues + ' assertion(s) failed!'}`);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { execSync, spawn } = require('child_process');
|
|
3
|
+
const { mkdtempSync, rmSync } = require('fs');
|
|
4
|
+
const { join } = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
const root = join(__dirname, '..');
|
|
8
|
+
const tmp = mkdtempSync(join(os.tmpdir(), 'zq-ssr-'));
|
|
9
|
+
|
|
10
|
+
console.log(`Scaffolding SSR app to ${tmp}\n`);
|
|
11
|
+
execSync(`node cli/index.js create "${tmp}" --ssr`, { cwd: root, stdio: 'inherit' });
|
|
12
|
+
console.log(`\nInstalling local zero-query...\n`);
|
|
13
|
+
execSync(`npm install "${root}"`, { cwd: tmp, stdio: 'inherit' });
|
|
14
|
+
|
|
15
|
+
console.log(`\nStarting SSR server...\n`);
|
|
16
|
+
const child = spawn('node', ['server/index.js'], { cwd: tmp, stdio: 'inherit' });
|
|
17
|
+
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
const open = process.platform === 'win32' ? 'start'
|
|
20
|
+
: process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
21
|
+
try { execSync(`${open} http://localhost:3000`, { stdio: 'ignore' }); } catch {}
|
|
22
|
+
}, 500);
|
|
23
|
+
|
|
24
|
+
function cleanup() { try { rmSync(tmp, { recursive: true, force: true }); } catch {} }
|
|
25
|
+
process.on('SIGINT', () => { child.kill(); cleanup(); process.exit(); });
|
|
26
|
+
process.on('SIGTERM', () => { child.kill(); cleanup(); process.exit(); });
|
|
27
|
+
child.on('exit', () => { cleanup(); process.exit(); });
|
package/types/misc.d.ts
CHANGED
|
@@ -165,15 +165,37 @@ export function safeEval(expr: string, scope: object[]): any;
|
|
|
165
165
|
/**
|
|
166
166
|
* Supported event modifier strings for `@event` and `z-on:event` bindings.
|
|
167
167
|
* Modifiers are appended to the event name with dots, e.g. `@click.prevent.stop`.
|
|
168
|
+
*
|
|
169
|
+
* **Key modifiers** — named shortcuts (`.enter`, `.escape`, `.tab`, `.space`,
|
|
170
|
+
* `.delete`, `.up`, `.down`, `.left`, `.right`) plus any arbitrary key matched
|
|
171
|
+
* case-insensitively against `KeyboardEvent.key` (e.g. `.a`, `.f1`, `.+`).
|
|
172
|
+
*
|
|
173
|
+
* **System modifiers** — `.ctrl`, `.shift`, `.alt`, `.meta` require the
|
|
174
|
+
* corresponding modifier key to be held.
|
|
168
175
|
*/
|
|
169
176
|
export type EventModifier =
|
|
170
177
|
| 'prevent'
|
|
171
178
|
| 'stop'
|
|
172
179
|
| 'self'
|
|
173
180
|
| 'once'
|
|
181
|
+
| 'outside'
|
|
174
182
|
| 'capture'
|
|
175
183
|
| 'passive'
|
|
176
184
|
| `debounce`
|
|
177
185
|
| `debounce.${number}`
|
|
178
186
|
| `throttle`
|
|
179
|
-
| `throttle.${number}
|
|
187
|
+
| `throttle.${number}`
|
|
188
|
+
| 'enter'
|
|
189
|
+
| 'escape'
|
|
190
|
+
| 'tab'
|
|
191
|
+
| 'space'
|
|
192
|
+
| 'delete'
|
|
193
|
+
| 'up'
|
|
194
|
+
| 'down'
|
|
195
|
+
| 'left'
|
|
196
|
+
| 'right'
|
|
197
|
+
| 'ctrl'
|
|
198
|
+
| 'shift'
|
|
199
|
+
| 'alt'
|
|
200
|
+
| 'meta'
|
|
201
|
+
| (string & {});
|