browser-runtime-svelte 0.0.9 → 0.0.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 +5 -1
- package/package.json +2 -2
- package/src/index.js +21 -3
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Svelte 5 compiler and renderer plugin for [`browser-module-runtime`](https://www
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npm install browser-module-runtime@0.0.
|
|
8
|
+
npm install browser-module-runtime@0.0.11 browser-runtime-svelte@0.0.11 svelte@5
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
@@ -24,3 +24,7 @@ const handle = await runtime.mount({module:'/Counter.svelte',target:'#app'});
|
|
|
24
24
|
The adapter uses `svelte/compiler` and `svelte` runtime mounting. Generated stylesheet assets are registered and cleaned up with the mount. An exact `version` contributes a matching `svelte` package root to the runtime linker so compiled `svelte/internal/*` imports resolve consistently. Real browser CDN operation depends on the selected provider serving that version.
|
|
25
25
|
|
|
26
26
|
For HTML declarations of complete `.svelte` files, prefer `type="svelte"` with `data-src`, since nested `<script>` text cannot safely be embedded in an outer HTML script element.
|
|
27
|
+
|
|
28
|
+
### Children projection in native custom elements (0.0.11-dev.2 source)
|
|
29
|
+
|
|
30
|
+
The adapter translates authored default children into Svelte 5's `children` **snippet**. Since `createRawSnippet` expects one root element, the snippet owns a `span[data-runtime-children]` using `display:contents`; its `setup` appends clones of all supplied elements/text nodes. This preserves sibling children rather than silently keeping only the first. Components render them through `{@render children()}`; missing children mean the snippet is undefined. The wrapper affects DOM structure/direct-child selectors, though not the CSS layout box.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-runtime-svelte",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"browser-module-runtime": "0.0.
|
|
25
|
+
"browser-module-runtime": "0.0.11",
|
|
26
26
|
"svelte": "^5.0.0"
|
|
27
27
|
},
|
|
28
28
|
"description": "Svelte compiler and renderer adapter for browser-module-runtime.",
|
package/src/index.js
CHANGED
|
@@ -32,12 +32,30 @@ export function svelte({compiler,renderer,reactivity,version='5',provider='esm.s
|
|
|
32
32
|
}],
|
|
33
33
|
renderers:[{
|
|
34
34
|
name:'svelte',types:['svelte','svelte-module'],
|
|
35
|
-
async mount({component,target,props}){
|
|
35
|
+
async mount({component,target,props,children}){
|
|
36
36
|
runtime ||= await (ownerRuntime ? ownerRuntime.import('svelte') : import('svelte'));
|
|
37
37
|
reactiveNamespace ||= await (ownerRuntime ? ownerRuntime.import('svelte/reactivity') : import('svelte/reactivity'));
|
|
38
38
|
const MapType=reactiveNamespace.SvelteMap;
|
|
39
39
|
if(typeof MapType!=='function')throw new TypeError('Svelte 5 renderer requires SvelteMap from svelte/reactivity');
|
|
40
|
-
|
|
40
|
+
// Svelte 5 children must be a snippet, not DOM nodes or a plain string.
|
|
41
|
+
if(children?.count&&typeof runtime.createRawSnippet!=='function')
|
|
42
|
+
throw new TypeError('Svelte children projection requires createRawSnippet() from svelte');
|
|
43
|
+
// createRawSnippet expects exactly one root element. Returning authored
|
|
44
|
+
// sibling markup directly silently discards all but its first root in
|
|
45
|
+
// Svelte's client renderer. Keep the original DOM structure inside a
|
|
46
|
+
// display:contents host and append fresh DOM clones during setup.
|
|
47
|
+
// This also handles text-only children without producing an invalid
|
|
48
|
+
// raw-snippet root. The wrapper is owned/removed by the snippet.
|
|
49
|
+
const snippet=children?.count ? runtime.createRawSnippet(()=>({
|
|
50
|
+
render:()=>'<span data-runtime-children="" style="display:contents"></span>',
|
|
51
|
+
setup:element=>element.append(...children.nodes())
|
|
52
|
+
})) : undefined;
|
|
53
|
+
const withChildren=next=>{
|
|
54
|
+
const result=snapshotProps(next);
|
|
55
|
+
if(snippet&&!Object.hasOwn(result,'children'))result.children=snippet;
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
const data=new MapType(Object.entries(withChildren(props)));
|
|
41
59
|
const state=new Proxy(Object.create(null),{
|
|
42
60
|
get(_target,key){return data.get(key);},
|
|
43
61
|
has(_target,key){return data.has(key);},
|
|
@@ -52,7 +70,7 @@ export function svelte({compiler,renderer,reactivity,version='5',provider='esm.s
|
|
|
52
70
|
return {
|
|
53
71
|
async updateProps(next){
|
|
54
72
|
if(closed)throw new Error('Svelte mount has been disposed');
|
|
55
|
-
const incoming=
|
|
73
|
+
const incoming=withChildren(next);
|
|
56
74
|
for(const key of [...data.keys()])if(!Object.hasOwn(incoming,key))data.delete(key);
|
|
57
75
|
for(const [key,value] of Object.entries(incoming))data.set(key,value);
|
|
58
76
|
await runtime.tick?.();
|