@awc-ui/svelte 1.0.0-beta.1 → 1.0.0-beta.11
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 +50 -43
- package/dist/index.d.ts +10 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/elements.d.ts +26 -0
- package/dist/lib/elements.d.ts.map +1 -0
- package/package.json +27 -6
- package/src/index.ts +10 -17
- package/src/lib/elements.ts +28 -0
package/README.md
CHANGED
|
@@ -1,55 +1,62 @@
|
|
|
1
|
-
# @awc-ui/svelte
|
|
1
|
+
# Svelte Web Components and SvelteKit SSR — @awc-ui/svelte
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Install
|
|
3
|
+
`@awc-ui/svelte` supplies types for AWC UI's native custom elements in Svelte 4
|
|
4
|
+
and 5. Property types and custom-event payloads come from the core declarations.
|
|
6
5
|
|
|
7
6
|
```bash
|
|
8
|
-
npm install @awc-ui/svelte @awc-ui/core
|
|
7
|
+
npm install @awc-ui/svelte @awc-ui/core
|
|
9
8
|
```
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
Register the custom elements once on the client, then use `md-*` tags directly in any `.svelte` file — Svelte has first-class custom-element support, so no per-component wrappers are needed:
|
|
10
|
+
For a client-rendered Vite application, load the theme and register the components
|
|
11
|
+
you use through static imports. Import the Svelte package's types once:
|
|
16
12
|
|
|
17
13
|
```ts
|
|
18
|
-
// main.ts
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```svelte
|
|
24
|
-
<md-button variant="filled" on:click={save}>Save</md-button>
|
|
25
|
-
<md-text-field label="Email" variant="outlined"></md-text-field>
|
|
14
|
+
// main.ts
|
|
15
|
+
import type {} from '@awc-ui/svelte';
|
|
16
|
+
import '@awc-ui/core/css/tokens.css';
|
|
17
|
+
import '@awc-ui/core/components/md-text-field';
|
|
18
|
+
import '@awc-ui/core/components/md-button';
|
|
26
19
|
```
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Registration is client-only — guard it so it runs in the browser:
|
|
21
|
+
Then use the native properties and custom events directly:
|
|
31
22
|
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Load the design tokens once (they carry the whole MD3 theme):
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
import '@awc-ui/tokens/tokens.css';
|
|
23
|
+
```svelte
|
|
24
|
+
<script lang="ts">
|
|
25
|
+
let name = '';
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<md-text-field
|
|
29
|
+
label="Project name"
|
|
30
|
+
value={name}
|
|
31
|
+
on:mdInput={(event) => name = event.detail}
|
|
32
|
+
></md-text-field>
|
|
33
|
+
<md-button variant="filled">Create project</md-button>
|
|
47
34
|
```
|
|
48
35
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
The `mdInput` payload is inferred as a string, and invalid component property
|
|
37
|
+
values are reported by `svelte-check`. Svelte 5 also supports the event-handler
|
|
38
|
+
property spelling `onmdInput`. Use `value` plus the component's `mdInput` or
|
|
39
|
+
`mdChange` event to synchronize forms; the custom elements do not expose a
|
|
40
|
+
Svelte `bind:value` contract.
|
|
41
|
+
|
|
42
|
+
`defineCustomElements` remains available from `@awc-ui/svelte` for applications
|
|
43
|
+
that deliberately deploy the lazy loader and its runtime chunks. Static component
|
|
44
|
+
imports work with Vite's module graph and keep registration limited to the
|
|
45
|
+
components you use.
|
|
46
|
+
|
|
47
|
+
## SvelteKit server-side rendering
|
|
48
|
+
|
|
49
|
+
Use SvelteKit 2.10 or later for the client initialization hook. On the server,
|
|
50
|
+
transform the completed HTML response with `renderToString` from
|
|
51
|
+
`@awc-ui/core/hydrate`; `createPageTransform` from `@awc-ui/core/ssr/sveltekit`
|
|
52
|
+
buffers response chunks until the document is complete.
|
|
53
|
+
|
|
54
|
+
On the client, create a shared `createSvelteHydration()` instance from
|
|
55
|
+
`@awc-ui/core/ssr/sveltekit`. Call `capture()` from `hooks.client.ts`'s `init`
|
|
56
|
+
before Svelte hydrates, then call `restore()` in the root layout's `onMount`
|
|
57
|
+
before dynamically importing the SSR-capable component entries. This preserves
|
|
58
|
+
AWC shadow roots while Svelte claims the surrounding document.
|
|
59
|
+
|
|
60
|
+
The helper must come from the same AWC UI release as the core components. Follow
|
|
61
|
+
the complete [SvelteKit reference app](https://github.com/awc-ui/core/tree/main/apps/example-sveltekit)
|
|
62
|
+
and [shared SSR guide](https://awc-ui.dev/frameworks/ssr/) for the server hook and client lifecycle.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Svelte 4/5 custom-element types and optional lazy-loader registration.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Registration is client-only. In a plain Vite/SPA app:
|
|
7
|
-
* @example
|
|
8
|
-
* import { defineCustomElements } from '@awc-ui/svelte';
|
|
9
|
-
* defineCustomElements(window);
|
|
10
|
-
*
|
|
11
|
-
* Under SvelteKit (SSR), guard it so it runs only in the browser — and for
|
|
12
|
-
* server-rendered markup use `@awc-ui/core/hydrate` (`renderToString`):
|
|
4
|
+
* In a client-rendered Vite app, load types and statically register what you use:
|
|
13
5
|
* @example
|
|
14
|
-
* import {
|
|
15
|
-
* import
|
|
16
|
-
*
|
|
6
|
+
* import type {} from '@awc-ui/svelte';
|
|
7
|
+
* import '@awc-ui/core/css/tokens.css';
|
|
8
|
+
* import '@awc-ui/core/components/md-button';
|
|
17
9
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
10
|
+
* Under SvelteKit, use @awc-ui/core/ssr/sveltekit to preserve server-rendered
|
|
11
|
+
* shadow roots, then dynamically import components after Svelte hydrates.
|
|
12
|
+
* See the Svelte framework guide for the complete client/server lifecycle.
|
|
21
13
|
*/
|
|
22
|
-
export * from './lib/components';
|
|
14
|
+
export * from './lib/components.js';
|
|
15
|
+
export type { AwcElementAttributes } from './lib/elements.js';
|
|
23
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,cAAc,qBAAqB,CAAC;AACpC,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { JSX as AwcJSX } from '@awc-ui/core';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
/** AWC event payloads, property types and their default HTML attribute spellings. */
|
|
4
|
+
type KebabCase<S extends string> = S extends `${infer First}${infer Rest}` ? `${First extends Lowercase<First> ? First : `-${Lowercase<First>}`}${KebabCase<Rest>}` : S;
|
|
5
|
+
type ComponentAttributes<Props> = Omit<HTMLAttributes<HTMLElement>, keyof Props> & {
|
|
6
|
+
[Key in keyof Props as Key extends `on${string}` ? never : Key]: Props[Key];
|
|
7
|
+
} & {
|
|
8
|
+
[Key in keyof Props as Key extends string ? Key extends `on${string}` ? never : KebabCase<Key> : never]: Props[Key];
|
|
9
|
+
} & {
|
|
10
|
+
[Key in keyof Props as Key extends `on${infer Event}` ? `on:${Uncapitalize<Event>}` | `on${Uncapitalize<Event>}` : never]: Props[Key];
|
|
11
|
+
};
|
|
12
|
+
export type AwcElementAttributes = {
|
|
13
|
+
[Tag in keyof AwcJSX.IntrinsicElements]: ComponentAttributes<AwcJSX.IntrinsicElements[Tag]>;
|
|
14
|
+
};
|
|
15
|
+
declare module 'svelte/elements' {
|
|
16
|
+
interface SvelteHTMLElements extends AwcElementAttributes {
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
declare global {
|
|
20
|
+
namespace svelteHTML {
|
|
21
|
+
interface IntrinsicElements extends AwcElementAttributes {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=elements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../src/lib/elements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,IAAI,MAAM,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,qFAAqF;AACrF,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,KAAK,GAAG,MAAM,IAAI,EAAE,GACtE,GAAG,KAAK,SAAS,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,GACtF,CAAC,CAAC;AAEN,KAAK,mBAAmB,CAAC,KAAK,IAAI,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,MAAM,KAAK,CAAC,GAC5E;KAAG,GAAG,IAAI,MAAM,KAAK,IAAI,GAAG,SAAS,KAAK,MAAM,EAAE,GAAG,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;CAAE,GAC/E;KAAG,GAAG,IAAI,MAAM,KAAK,IAAI,GAAG,SAAS,MAAM,GAAG,GAAG,SAAS,KAAK,MAAM,EAAE,GAAG,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC;CAAE,GACvH;KAAG,GAAG,IAAI,MAAM,KAAK,IAAI,GAAG,SAAS,KAAK,MAAM,KAAK,EAAE,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,YAAY,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC;CAAE,CAAC;AAE9I,MAAM,MAAM,oBAAoB,GAAG;KAChC,GAAG,IAAI,MAAM,MAAM,CAAC,iBAAiB,GAAG,mBAAmB,CAAC,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;CAC5F,CAAC;AAIF,OAAO,QAAQ,iBAAiB,CAAC;IAC/B,UAAU,kBAAmB,SAAQ,oBAAoB;KAAG;CAC7D;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU,CAAC;QACnB,UAAU,iBAAkB,SAAQ,oBAAoB;SAAG;KAC5D;CACF"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awc-ui/svelte",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
4
|
-
"description": "Svelte
|
|
3
|
+
"version": "1.0.0-beta.11",
|
|
4
|
+
"description": "Svelte 4 and 5 components for accessible Material Design 3 Web Components, with SvelteKit SSR and server-rendering guidance",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svelte",
|
|
7
|
+
"svelte-component",
|
|
7
8
|
"svelte-components",
|
|
9
|
+
"components",
|
|
8
10
|
"material-design",
|
|
9
11
|
"material-design-3",
|
|
10
12
|
"md3",
|
|
11
13
|
"ui-components",
|
|
12
14
|
"component-library",
|
|
13
15
|
"web-components",
|
|
14
|
-
"design-system"
|
|
16
|
+
"design-system",
|
|
17
|
+
"material-3",
|
|
18
|
+
"svelte-ui",
|
|
19
|
+
"custom-elements",
|
|
20
|
+
"typescript",
|
|
21
|
+
"accessibility",
|
|
22
|
+
"wcag",
|
|
23
|
+
"sveltekit",
|
|
24
|
+
"ssr",
|
|
25
|
+
"ui-library",
|
|
26
|
+
"svelte5",
|
|
27
|
+
"svelte-5",
|
|
28
|
+
"svelte-ui-library",
|
|
29
|
+
"svelte-ui-components",
|
|
30
|
+
"svelte-component-library",
|
|
31
|
+
"web-component",
|
|
32
|
+
"svelte-web-components",
|
|
33
|
+
"sveltekit-components",
|
|
34
|
+
"server-side-rendering"
|
|
15
35
|
],
|
|
16
36
|
"main": "dist/index.mjs",
|
|
17
37
|
"types": "dist/index.d.ts",
|
|
@@ -28,12 +48,12 @@
|
|
|
28
48
|
],
|
|
29
49
|
"peerDependencies": {
|
|
30
50
|
"svelte": ">=4",
|
|
31
|
-
"@awc-ui/core": "1.0.0-beta.
|
|
51
|
+
"@awc-ui/core": "1.0.0-beta.11"
|
|
32
52
|
},
|
|
33
53
|
"devDependencies": {
|
|
34
54
|
"esbuild": "^0.25.12",
|
|
35
55
|
"typescript": "^5.4.0",
|
|
36
|
-
"@awc-ui/core": "1.0.0-beta.
|
|
56
|
+
"@awc-ui/core": "1.0.0-beta.11"
|
|
37
57
|
},
|
|
38
58
|
"license": "MIT",
|
|
39
59
|
"author": "AWC UI",
|
|
@@ -53,6 +73,7 @@
|
|
|
53
73
|
},
|
|
54
74
|
"type": "module",
|
|
55
75
|
"scripts": {
|
|
56
|
-
"build": "rm -rf dist && tsc -p tsconfig.json --emitDeclarationOnly && esbuild src/index.ts --bundle --format=esm --target=es2020 --sourcemap --outfile=dist/index.mjs --external:svelte --external:@awc-ui/core --external:@awc-ui/core/*"
|
|
76
|
+
"build": "rm -rf dist && tsc -p tsconfig.json --emitDeclarationOnly && esbuild src/index.ts --bundle --format=esm --target=es2020 --sourcemap --outfile=dist/index.mjs --external:svelte --external:@awc-ui/core --external:@awc-ui/core/*",
|
|
77
|
+
"test:integration": "node tests/types.mjs"
|
|
57
78
|
}
|
|
58
79
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Svelte 4/5 custom-element types and optional lazy-loader registration.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Registration is client-only. In a plain Vite/SPA app:
|
|
7
|
-
* @example
|
|
8
|
-
* import { defineCustomElements } from '@awc-ui/svelte';
|
|
9
|
-
* defineCustomElements(window);
|
|
10
|
-
*
|
|
11
|
-
* Under SvelteKit (SSR), guard it so it runs only in the browser — and for
|
|
12
|
-
* server-rendered markup use `@awc-ui/core/hydrate` (`renderToString`):
|
|
4
|
+
* In a client-rendered Vite app, load types and statically register what you use:
|
|
13
5
|
* @example
|
|
14
|
-
* import {
|
|
15
|
-
* import
|
|
16
|
-
*
|
|
6
|
+
* import type {} from '@awc-ui/svelte';
|
|
7
|
+
* import '@awc-ui/core/css/tokens.css';
|
|
8
|
+
* import '@awc-ui/core/components/md-button';
|
|
17
9
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
10
|
+
* Under SvelteKit, use @awc-ui/core/ssr/sveltekit to preserve server-rendered
|
|
11
|
+
* shadow roots, then dynamically import components after Svelte hydrates.
|
|
12
|
+
* See the Svelte framework guide for the complete client/server lifecycle.
|
|
21
13
|
*/
|
|
22
|
-
export * from './lib/components';
|
|
14
|
+
export * from './lib/components.js';
|
|
15
|
+
export type { AwcElementAttributes } from './lib/elements.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { JSX as AwcJSX } from '@awc-ui/core';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
|
|
4
|
+
/** AWC event payloads, property types and their default HTML attribute spellings. */
|
|
5
|
+
type KebabCase<S extends string> = S extends `${infer First}${infer Rest}`
|
|
6
|
+
? `${First extends Lowercase<First> ? First : `-${Lowercase<First>}`}${KebabCase<Rest>}`
|
|
7
|
+
: S;
|
|
8
|
+
|
|
9
|
+
type ComponentAttributes<Props> = Omit<HTMLAttributes<HTMLElement>, keyof Props>
|
|
10
|
+
& { [Key in keyof Props as Key extends `on${string}` ? never : Key]: Props[Key] }
|
|
11
|
+
& { [Key in keyof Props as Key extends string ? Key extends `on${string}` ? never : KebabCase<Key> : never]: Props[Key] }
|
|
12
|
+
& { [Key in keyof Props as Key extends `on${infer Event}` ? `on:${Uncapitalize<Event>}` | `on${Uncapitalize<Event>}` : never]: Props[Key] };
|
|
13
|
+
|
|
14
|
+
export type AwcElementAttributes = {
|
|
15
|
+
[Tag in keyof AwcJSX.IntrinsicElements]: ComponentAttributes<AwcJSX.IntrinsicElements[Tag]>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Current Svelte 4 and 5 tooling reads svelte/elements; older Svelte 4 tooling
|
|
19
|
+
// reads the global namespace. Both derive from the same core declarations.
|
|
20
|
+
declare module 'svelte/elements' {
|
|
21
|
+
interface SvelteHTMLElements extends AwcElementAttributes {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare global {
|
|
25
|
+
namespace svelteHTML {
|
|
26
|
+
interface IntrinsicElements extends AwcElementAttributes {}
|
|
27
|
+
}
|
|
28
|
+
}
|