@svelte-lean/vite 0.5.0 → 0.7.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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # @svelte-lean/vite
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3bb9f7d: `data-slean-findable` on any element injects the findable registration module, whatever its value
8
+ (`ATTRIBUTE_BEHAVIORS`).
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [3bb9f7d]
13
+ - @svelte-lean/primitives@0.7.0
14
+
15
+ ## 0.6.0
16
+
17
+ ### Minor Changes
18
+
19
+ - dda6d05: The scanner discovers attribute behaviors by attribute name: `data-slean-hint` and
20
+ `data-slean-copy` on any element inject the hint and copy registration modules, whether the value
21
+ is static, an `{expression}` or absent; they are never reported as dynamic markers. The mapping is
22
+ exported as `ATTRIBUTE_BEHAVIORS`.
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [dda6d05]
27
+ - @svelte-lean/primitives@0.6.0
28
+
3
29
  ## 0.5.0
4
30
 
5
31
  ### Patch Changes
package/README.md CHANGED
@@ -79,6 +79,22 @@ 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
+ <span data-slean-findable={short(row.id)}>…</span>
91
+ <!-- @svelte-lean/primitives/findable/register -->
92
+ ```
93
+
94
+ The attribute → behavior map is exported as `ATTRIBUTE_BEHAVIORS`. An attribute that reaches an
95
+ element only through a spread (`{...rest}`) is not visible to the scanner; import the registration
96
+ module manually.
97
+
82
98
  Not discovered (dynamic):
83
99
 
84
100
  ```svelte
@@ -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,21 @@ 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
+ findable: `${DEFAULT_PACKAGE}/findable/register`
78
+ });
79
+ /**
80
+ * Attribute behaviors (ADR 0009): an element carrying one of these attributes uses the behavior,
81
+ * whatever the attribute's value, static or `{expression}`. The attribute name decides the
82
+ * behavior, so a dynamic value is never a dynamic marker. Kept equal to the `attribute` of the
83
+ * `@svelte-lean/primitives` contracts by the drift test in packages/primitives/tests/registry.test.ts.
84
+ */
85
+ export const ATTRIBUTE_BEHAVIORS = Object.freeze({
86
+ 'data-slean-hint': 'hint',
87
+ 'data-slean-copy': 'copy',
88
+ 'data-slean-findable': 'findable'
75
89
  });
76
90
  /**
77
91
  * 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 `BUILTIN_BEHAVIORS` are exported for
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 and dynamic `data-slean={…}` markers in Svelte source.
16
+ * Finds static `data-slean="name"` markers, attribute behaviors (`data-slean-hint`,
17
+ * `data-slean-copy`, `data-slean-findable`) 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`,
15
+ * `data-slean-copy` or `data-slean-findable` 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 (attrName.toLowerCase() !== ATTRIBUTE)
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 and dynamic `data-slean={…}` markers in Svelte source.
368
+ * Finds static `data-slean="name"` markers, attribute behaviors (`data-slean-hint`,
369
+ * `data-slean-copy`, `data-slean-findable`) 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.5.0",
3
+ "version": "0.7.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.5.0",
32
+ "@svelte-lean/primitives": "^0.7.0",
33
33
  "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
34
34
  },
35
35
  "peerDependenciesMeta": {