@svelte-lean/vite 0.4.0 → 0.6.0
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/CHANGELOG.md +20 -0
- package/README.md +14 -0
- package/dist/behaviors.d.ts +7 -0
- package/dist/behaviors.js +13 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/scanner.d.ts +2 -1
- package/dist/scanner.js +11 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @svelte-lean/vite
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- dda6d05: The scanner discovers attribute behaviors by attribute name: `data-slean-hint` and
|
|
8
|
+
`data-slean-copy` on any element inject the hint and copy registration modules, whether the value
|
|
9
|
+
is static, an `{expression}` or absent; they are never reported as dynamic markers. The mapping is
|
|
10
|
+
exported as `ATTRIBUTE_BEHAVIORS`.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [dda6d05]
|
|
15
|
+
- @svelte-lean/primitives@0.6.0
|
|
16
|
+
|
|
17
|
+
## 0.5.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- @svelte-lean/primitives@0.5.0
|
|
22
|
+
|
|
3
23
|
## 0.4.0
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -79,6 +79,20 @@ Discovered:
|
|
|
79
79
|
<div data-slean=tabs>
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
Attribute behaviors (ADR 0009) are discovered by attribute name, on any element and whatever the
|
|
83
|
+
value, so a dynamic value is a use of the behavior and never a dynamic marker:
|
|
84
|
+
|
|
85
|
+
```svelte
|
|
86
|
+
<td data-slean-hint={row.name}>…</td>
|
|
87
|
+
<!-- @svelte-lean/primitives/hint/register -->
|
|
88
|
+
<button data-slean-copy={row.id}>…</button>
|
|
89
|
+
<!-- @svelte-lean/primitives/copy/register -->
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The attribute → behavior map is exported as `ATTRIBUTE_BEHAVIORS`. An attribute that reaches an
|
|
93
|
+
element only through a spread (`{...rest}`) is not visible to the scanner; import the registration
|
|
94
|
+
module manually.
|
|
95
|
+
|
|
82
96
|
Not discovered (dynamic):
|
|
83
97
|
|
|
84
98
|
```svelte
|
package/dist/behaviors.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ export declare const DEFAULT_PACKAGE = "@svelte-lean/primitives";
|
|
|
6
6
|
* runtime, so its marker is recorded for the manifest and report only.
|
|
7
7
|
*/
|
|
8
8
|
export declare const BUILTIN_BEHAVIORS: Readonly<Record<string, string | false>>;
|
|
9
|
+
/**
|
|
10
|
+
* Attribute behaviors (ADR 0009): an element carrying one of these attributes uses the behavior,
|
|
11
|
+
* whatever the attribute's value, static or `{expression}`. The attribute name decides the
|
|
12
|
+
* behavior, so a dynamic value is never a dynamic marker. Kept equal to the `attribute` of the
|
|
13
|
+
* `@svelte-lean/primitives` contracts by the drift test in packages/primitives/tests/registry.test.ts.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ATTRIBUTE_BEHAVIORS: Readonly<Record<string, string>>;
|
|
9
16
|
export type BehaviorResolution = {
|
|
10
17
|
kind: 'runtime';
|
|
11
18
|
module: string;
|
package/dist/behaviors.js
CHANGED
|
@@ -71,7 +71,19 @@ export const BUILTIN_BEHAVIORS = Object.freeze({
|
|
|
71
71
|
'context-menu': `${DEFAULT_PACKAGE}/context-menu/register`,
|
|
72
72
|
'file-drop': `${DEFAULT_PACKAGE}/file-drop/register`,
|
|
73
73
|
'hover-card': `${DEFAULT_PACKAGE}/hover-card/register`,
|
|
74
|
-
menubar: `${DEFAULT_PACKAGE}/menubar/register
|
|
74
|
+
menubar: `${DEFAULT_PACKAGE}/menubar/register`,
|
|
75
|
+
hint: `${DEFAULT_PACKAGE}/hint/register`,
|
|
76
|
+
copy: `${DEFAULT_PACKAGE}/copy/register`
|
|
77
|
+
});
|
|
78
|
+
/**
|
|
79
|
+
* Attribute behaviors (ADR 0009): an element carrying one of these attributes uses the behavior,
|
|
80
|
+
* whatever the attribute's value, static or `{expression}`. The attribute name decides the
|
|
81
|
+
* behavior, so a dynamic value is never a dynamic marker. Kept equal to the `attribute` of the
|
|
82
|
+
* `@svelte-lean/primitives` contracts by the drift test in packages/primitives/tests/registry.test.ts.
|
|
83
|
+
*/
|
|
84
|
+
export const ATTRIBUTE_BEHAVIORS = Object.freeze({
|
|
85
|
+
'data-slean-hint': 'hint',
|
|
86
|
+
'data-slean-copy': 'copy'
|
|
75
87
|
});
|
|
76
88
|
/**
|
|
77
89
|
* Maps a behavior name to what the build should do with it. `options.behaviors` wins over the
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { svelteLean } from './plugin.js';
|
|
2
2
|
export { scan } from './scanner.js';
|
|
3
|
-
export { BUILTIN_BEHAVIORS } from './behaviors.js';
|
|
3
|
+
export { ATTRIBUTE_BEHAVIORS, BUILTIN_BEHAVIORS } from './behaviors.js';
|
|
4
4
|
export type { SvelteLeanOptions, ScanResult, DynamicMarker, BehaviorManifest, ManifestBehavior } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Public entry. `svelteLean()` is the product; `scan()` and `
|
|
1
|
+
// Public entry. `svelteLean()` is the product; `scan()`, `BUILTIN_BEHAVIORS` and `ATTRIBUTE_BEHAVIORS` are exported for
|
|
2
2
|
// tooling that wants the same discovery without the plugin. Everything else in src/ is internal.
|
|
3
3
|
export { svelteLean } from './plugin.js';
|
|
4
4
|
export { scan } from './scanner.js';
|
|
5
|
-
export { BUILTIN_BEHAVIORS } from './behaviors.js';
|
|
5
|
+
export { ATTRIBUTE_BEHAVIORS, BUILTIN_BEHAVIORS } from './behaviors.js';
|
package/dist/scanner.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export declare function locate(source: string, index: number): {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function skipExpression(source: string, start: number, result?: ScanResult): number;
|
|
15
15
|
/**
|
|
16
|
-
* Finds static `data-slean="name"` markers
|
|
16
|
+
* Finds static `data-slean="name"` markers, attribute behaviors (`data-slean-hint`,
|
|
17
|
+
* `data-slean-copy`) and dynamic `data-slean={…}` markers in Svelte source.
|
|
17
18
|
* Pure: no I/O, no plugin context. `id` is only carried into the result for diagnostics.
|
|
18
19
|
*/
|
|
19
20
|
export declare function scan(source: string, id?: string): ScanResult;
|
package/dist/scanner.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ATTRIBUTE_BEHAVIORS } from './behaviors.js';
|
|
1
2
|
/**
|
|
2
3
|
* Lexical scanner for Svelte Lean behavior markers.
|
|
3
4
|
*
|
|
@@ -9,6 +10,10 @@
|
|
|
9
10
|
* string, template and regular-expression literals and comments are skipped so their quotes and
|
|
10
11
|
* braces cannot unbalance it; an expression that never closes is recorded in
|
|
11
12
|
* `ScanResult.unterminated` so a miss is never silent.
|
|
13
|
+
*
|
|
14
|
+
* Attribute behaviors (ADR 0009) are found by attribute name: `data-slean-hint` or
|
|
15
|
+
* `data-slean-copy` on an element uses that behavior whatever its value, static, `{expression}`
|
|
16
|
+
* or absent, so they never produce a dynamic marker.
|
|
12
17
|
*/
|
|
13
18
|
const ATTRIBUTE = 'data-slean';
|
|
14
19
|
const RAW_TEXT_ELEMENTS = new Set(['script', 'style']);
|
|
@@ -324,6 +329,9 @@ function scanTag(source, start, result) {
|
|
|
324
329
|
continue;
|
|
325
330
|
}
|
|
326
331
|
const attrName = source.slice(attrStart, i);
|
|
332
|
+
const lower = attrName.toLowerCase();
|
|
333
|
+
if (Object.hasOwn(ATTRIBUTE_BEHAVIORS, lower))
|
|
334
|
+
result.behaviors.add(ATTRIBUTE_BEHAVIORS[lower]);
|
|
327
335
|
let j = i;
|
|
328
336
|
while (j < n && isWhitespace(source.charCodeAt(j)))
|
|
329
337
|
j++;
|
|
@@ -334,7 +342,7 @@ function scanTag(source, start, result) {
|
|
|
334
342
|
j++;
|
|
335
343
|
const value = readAttributeValue(source, j, result);
|
|
336
344
|
i = value.end;
|
|
337
|
-
if (
|
|
345
|
+
if (lower !== ATTRIBUTE)
|
|
338
346
|
continue;
|
|
339
347
|
if (value.dynamic) {
|
|
340
348
|
const { line, column } = locate(source, attrStart);
|
|
@@ -357,7 +365,8 @@ function scanTag(source, start, result) {
|
|
|
357
365
|
return i;
|
|
358
366
|
}
|
|
359
367
|
/**
|
|
360
|
-
* Finds static `data-slean="name"` markers
|
|
368
|
+
* Finds static `data-slean="name"` markers, attribute behaviors (`data-slean-hint`,
|
|
369
|
+
* `data-slean-copy`) and dynamic `data-slean={…}` markers in Svelte source.
|
|
361
370
|
* Pure: no I/O, no plugin context. `id` is only carried into the result for diagnostics.
|
|
362
371
|
*/
|
|
363
372
|
export function scan(source, id) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svelte-lean/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Vite integration for Svelte Lean: discovers data-slean behaviors in Svelte markup at build time and injects only the registration modules that are used.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ömer Say",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test": "yarn run -T vitest run"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@svelte-lean/primitives": "^0.
|
|
32
|
+
"@svelte-lean/primitives": "^0.6.0",
|
|
33
33
|
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|