@nifrajs/web-svelte 1.12.0 → 2.0.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/dist/Await.svelte +1 -1
- package/dist/Chain.svelte +2 -2
- package/dist/svg.d.ts +7 -0
- package/dist/svg.d.ts.map +1 -0
- package/dist/svg.js +42 -0
- package/dist/svg.js.map +1 -0
- package/package.json +9 -4
- package/src/Await.svelte +1 -1
- package/src/Chain.svelte +2 -2
- package/src/svg.ts +44 -0
package/dist/Await.svelte
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<script>
|
|
12
12
|
let { resolve, children, pending, error } = $props()
|
|
13
13
|
const isDeferred = (v) =>
|
|
14
|
-
v != null && typeof v === "object" && v.
|
|
14
|
+
v != null && typeof v === "object" && v.__nifra_deferred === true
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
{#if isDeferred(resolve)}
|
package/dist/Chain.svelte
CHANGED
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
{@const Page = chain[0]}
|
|
16
16
|
<Page {...props} />
|
|
17
17
|
{/if}
|
|
18
|
-
{:else if chain[0] && chain[0].
|
|
18
|
+
{:else if chain[0] && chain[0].__nifraErrorBoundary}
|
|
19
19
|
<!-- nifra `_error` boundary marker (from errorBoundary()): wrap the rest in <svelte:boundary>; the
|
|
20
20
|
`failed` snippet renders the route's _error component with the serialized error. -->
|
|
21
|
-
{@const Fallback = chain[0].
|
|
21
|
+
{@const Fallback = chain[0].__nifraErrorBoundary}
|
|
22
22
|
<svelte:boundary>
|
|
23
23
|
<Self chain={chain.slice(1)} {props} />
|
|
24
24
|
{#snippet failed(error)}
|
package/dist/svg.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BunPlugin } from "bun";
|
|
2
|
+
/** Wrap raw SVG XML in a Svelte 5 component: strip XML noise, spread props onto the root `<svg>`. */
|
|
3
|
+
export declare function svgToSvelte(xml: string): string;
|
|
4
|
+
/** The Svelte SVG-component plugin. `generate` selects Svelte's `"client"`/`"server"` output, matching
|
|
5
|
+
* `svelteBunPlugin`. */
|
|
6
|
+
export declare function svelteSvgComponentBunPlugin(generate: "dom" | "ssr"): BunPlugin;
|
|
7
|
+
//# sourceMappingURL=svg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAGpC,qGAAqG;AACrG,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAS/C;AAED;wBACwB;AACxB,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAe9E"}
|
package/dist/svg.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@nifrajs/web-svelte/svg` - the Svelte build of the SVG-as-component plugin. `import Icon from
|
|
3
|
+
* "./icon.svg?component"`, then `<Icon class="w-6 h-6" />`, props spread onto the root `<svg>`.
|
|
4
|
+
*
|
|
5
|
+
* Svelte markup accepts SVG almost verbatim (`class`, hyphenated attributes, an inline `style` string
|
|
6
|
+
* all work as-is), so - unlike the JSX adapters - no attribute rewriting is needed: the raw SVG is
|
|
7
|
+
* wrapped in a Svelte 5 component that spreads its props onto the root element, then compiled with the
|
|
8
|
+
* project's `svelte` compiler. Pass `"dom"` for the client bundle and preload `"ssr"` for the server;
|
|
9
|
+
* a plain `import "./icon.svg"` (asset URL) is untouched - only `?component` matches.
|
|
10
|
+
*/
|
|
11
|
+
import { SVG_COMPONENT_FILTER } from "@nifrajs/web/plugins/svg";
|
|
12
|
+
import { compile } from "svelte/compiler";
|
|
13
|
+
/** Wrap raw SVG XML in a Svelte 5 component: strip XML noise, spread props onto the root `<svg>`. */
|
|
14
|
+
export function svgToSvelte(xml) {
|
|
15
|
+
const cleaned = xml
|
|
16
|
+
.replace(/<\?xml[\s\S]*?\?>/g, "")
|
|
17
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
18
|
+
.replace(/<!DOCTYPE[^>]*>/gi, "")
|
|
19
|
+
.trim();
|
|
20
|
+
// `$props()` opts the component into runes (Svelte 5); spread onto the root so user attrs win.
|
|
21
|
+
const withSpread = cleaned.replace(/^(<svg\b[^>]*?)>/, "$1 {...props}>");
|
|
22
|
+
return `<script>const props = $props()</script>\n${withSpread}\n`;
|
|
23
|
+
}
|
|
24
|
+
/** The Svelte SVG-component plugin. `generate` selects Svelte's `"client"`/`"server"` output, matching
|
|
25
|
+
* `svelteBunPlugin`. */
|
|
26
|
+
export function svelteSvgComponentBunPlugin(generate) {
|
|
27
|
+
return {
|
|
28
|
+
name: `nifra-svelte-svg-${generate}`,
|
|
29
|
+
setup(build) {
|
|
30
|
+
build.onLoad({ filter: SVG_COMPONENT_FILTER }, async (args) => {
|
|
31
|
+
const path = args.path.split("?")[0] ?? args.path;
|
|
32
|
+
const xml = await Bun.file(path).text();
|
|
33
|
+
const { js } = compile(svgToSvelte(xml), {
|
|
34
|
+
generate: generate === "ssr" ? "server" : "client",
|
|
35
|
+
filename: path,
|
|
36
|
+
});
|
|
37
|
+
return { contents: js.code, loader: "js" };
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=svg.js.map
|
package/dist/svg.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.js","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAE/D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC,qGAAqG;AACrG,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,OAAO,GAAG,GAAG;SAChB,OAAO,C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4
|
"description": "Svelte 5 render adapter for @nifrajs/web — SSR + hydration + the .svelte compiler Bun-plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -68,6 +68,11 @@
|
|
|
68
68
|
"bun": "./src/mdx.ts",
|
|
69
69
|
"types": "./dist/mdx.d.ts",
|
|
70
70
|
"default": "./dist/mdx.js"
|
|
71
|
+
},
|
|
72
|
+
"./svg": {
|
|
73
|
+
"bun": "./src/svg.ts",
|
|
74
|
+
"types": "./dist/svg.d.ts",
|
|
75
|
+
"default": "./dist/svg.js"
|
|
71
76
|
}
|
|
72
77
|
},
|
|
73
78
|
"files": [
|
|
@@ -83,9 +88,9 @@
|
|
|
83
88
|
"access": "public"
|
|
84
89
|
},
|
|
85
90
|
"dependencies": {
|
|
86
|
-
"@nifrajs/i18n": "
|
|
87
|
-
"@nifrajs/image": "
|
|
88
|
-
"@nifrajs/web": "
|
|
91
|
+
"@nifrajs/i18n": "2.0.0",
|
|
92
|
+
"@nifrajs/image": "2.0.0",
|
|
93
|
+
"@nifrajs/web": "2.0.0"
|
|
89
94
|
},
|
|
90
95
|
"peerDependencies": {
|
|
91
96
|
"mdsvex": "^0.12",
|
package/src/Await.svelte
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<script>
|
|
12
12
|
let { resolve, children, pending, error } = $props()
|
|
13
13
|
const isDeferred = (v) =>
|
|
14
|
-
v != null && typeof v === "object" && v.
|
|
14
|
+
v != null && typeof v === "object" && v.__nifra_deferred === true
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
{#if isDeferred(resolve)}
|
package/src/Chain.svelte
CHANGED
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
{@const Page = chain[0]}
|
|
16
16
|
<Page {...props} />
|
|
17
17
|
{/if}
|
|
18
|
-
{:else if chain[0] && chain[0].
|
|
18
|
+
{:else if chain[0] && chain[0].__nifraErrorBoundary}
|
|
19
19
|
<!-- nifra `_error` boundary marker (from errorBoundary()): wrap the rest in <svelte:boundary>; the
|
|
20
20
|
`failed` snippet renders the route's _error component with the serialized error. -->
|
|
21
|
-
{@const Fallback = chain[0].
|
|
21
|
+
{@const Fallback = chain[0].__nifraErrorBoundary}
|
|
22
22
|
<svelte:boundary>
|
|
23
23
|
<Self chain={chain.slice(1)} {props} />
|
|
24
24
|
{#snippet failed(error)}
|
package/src/svg.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@nifrajs/web-svelte/svg` - the Svelte build of the SVG-as-component plugin. `import Icon from
|
|
3
|
+
* "./icon.svg?component"`, then `<Icon class="w-6 h-6" />`, props spread onto the root `<svg>`.
|
|
4
|
+
*
|
|
5
|
+
* Svelte markup accepts SVG almost verbatim (`class`, hyphenated attributes, an inline `style` string
|
|
6
|
+
* all work as-is), so - unlike the JSX adapters - no attribute rewriting is needed: the raw SVG is
|
|
7
|
+
* wrapped in a Svelte 5 component that spreads its props onto the root element, then compiled with the
|
|
8
|
+
* project's `svelte` compiler. Pass `"dom"` for the client bundle and preload `"ssr"` for the server;
|
|
9
|
+
* a plain `import "./icon.svg"` (asset URL) is untouched - only `?component` matches.
|
|
10
|
+
*/
|
|
11
|
+
import { SVG_COMPONENT_FILTER } from "@nifrajs/web/plugins/svg"
|
|
12
|
+
import type { BunPlugin } from "bun"
|
|
13
|
+
import { compile } from "svelte/compiler"
|
|
14
|
+
|
|
15
|
+
/** Wrap raw SVG XML in a Svelte 5 component: strip XML noise, spread props onto the root `<svg>`. */
|
|
16
|
+
export function svgToSvelte(xml: string): string {
|
|
17
|
+
const cleaned = xml
|
|
18
|
+
.replace(/<\?xml[\s\S]*?\?>/g, "")
|
|
19
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
20
|
+
.replace(/<!DOCTYPE[^>]*>/gi, "")
|
|
21
|
+
.trim()
|
|
22
|
+
// `$props()` opts the component into runes (Svelte 5); spread onto the root so user attrs win.
|
|
23
|
+
const withSpread = cleaned.replace(/^(<svg\b[^>]*?)>/, "$1 {...props}>")
|
|
24
|
+
return `<script>const props = $props()</script>\n${withSpread}\n`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The Svelte SVG-component plugin. `generate` selects Svelte's `"client"`/`"server"` output, matching
|
|
28
|
+
* `svelteBunPlugin`. */
|
|
29
|
+
export function svelteSvgComponentBunPlugin(generate: "dom" | "ssr"): BunPlugin {
|
|
30
|
+
return {
|
|
31
|
+
name: `nifra-svelte-svg-${generate}`,
|
|
32
|
+
setup(build) {
|
|
33
|
+
build.onLoad({ filter: SVG_COMPONENT_FILTER }, async (args) => {
|
|
34
|
+
const path = args.path.split("?")[0] ?? args.path
|
|
35
|
+
const xml = await Bun.file(path).text()
|
|
36
|
+
const { js } = compile(svgToSvelte(xml), {
|
|
37
|
+
generate: generate === "ssr" ? "server" : "client",
|
|
38
|
+
filename: path,
|
|
39
|
+
})
|
|
40
|
+
return { contents: js.code, loader: "js" }
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|