@tarve/svelte 0.0.0-stage → 0.8.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/README.md +54 -3
- package/package.json +50 -4
- package/src/TitleBar.svelte +44 -0
- package/src/bun-preload.ts +4 -0
- package/src/bun.ts +13 -0
- package/src/compiler.ts +39 -0
- package/src/css.ts +606 -0
- package/src/dom-animation.ts +89 -0
- package/src/dom.ts +1533 -0
- package/src/editable.ts +372 -0
- package/src/elements.d.ts +43 -0
- package/src/events.ts +90 -0
- package/src/index.ts +126 -0
- package/src/install.ts +4 -0
- package/src/plugin.ts +83 -0
- package/src/render.ts +466 -0
- package/src/resolve.ts +39 -0
- package/src/selectors.ts +309 -0
- package/src/svelte-client.ts +8 -0
package/README.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @tarve/svelte
|
|
2
|
+
|
|
3
|
+
Svelte 5 components in native Tarve windows. `.svelte` files compile with Svelte's own
|
|
4
|
+
compiler (client output, runes, snippets, bindings, transitions' timing) and run on
|
|
5
|
+
Svelte's own runtime against a small retained DOM. Each element of that DOM is a
|
|
6
|
+
memoized Tarve subtree keyed by its identity and version, so a Svelte update re-renders
|
|
7
|
+
only the elements it touched and their ancestors. Every other compiled subtree is
|
|
8
|
+
reused without rendering or diffing, and native receives one `patch`/`mutate` per flush.
|
|
9
|
+
|
|
10
|
+
```svelte
|
|
11
|
+
<!-- App.svelte -->
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
let count = $state(0);
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<svelte:head><title>Clicked {count}</title></svelte:head>
|
|
17
|
+
<div class="p-6 gap-3">
|
|
18
|
+
<button onclick={() => count++}>Clicked {count}</button>
|
|
19
|
+
</div>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// main.ts
|
|
24
|
+
import { mount } from "@tarve/svelte";
|
|
25
|
+
import App from "./App.svelte";
|
|
26
|
+
mount(App, { window: { title: "Counter", width: 480, height: 320 } });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`tarve run|dev|build` (Bun, Node.js and txiki) compile `.svelte` imports when @tarve/svelte is installed.
|
|
30
|
+
Plain `bun main.ts` needs `preload = ["@tarve/svelte/bun-preload"]` in `bunfig.toml`.
|
|
31
|
+
|
|
32
|
+
- Other bundlers (esbuild, `Bun.build`): `sveltePlugin()` from `@tarve/svelte/plugin`.
|
|
33
|
+
|
|
34
|
+
Types: `drag-region`, `window-action` and Tarve's elements (`<row>`, `<column>`, `<view>`, `<scroll>`, `<markdown>`, `<titlebar>`) are declared for svelte-check and the Svelte language server (`src/elements.d.ts`, included through `@tarve/svelte`).
|
|
35
|
+
|
|
36
|
+
## What maps to what
|
|
37
|
+
|
|
38
|
+
| Svelte | Tarve |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| HTML elements | Tarve's HTML intrinsics (`div`, `p`, `button`, `input`, `select`, `form`, `ul`, `audio`…); unknown tags are `div` |
|
|
41
|
+
| `<row>`, `<column>`, `<view>`, `<scroll>`, `<text>`, `<markdown>`, `<code>` | the Tarve components of that name |
|
|
42
|
+
| `class="…"` | Tailwind utilities, except names the component's `<style>` selects |
|
|
43
|
+
| `<style>` | compound, descendant, child and sibling selectors, `:not/:is/:where/:has`, `:nth-child`, `:first/last-child`, `:checked`, `:hover/:focus/:active`, `::before/::after` (`content` with strings and `attr()`), `@media`, `@keyframes` + `animation`, `var()`, `em/rem/vw/vh`, `transform` |
|
|
44
|
+
| events | click, dblclick, auxclick, mousedown/up, pointerdown/up, mouse/pointer enter/leave/move, wheel, contextmenu, scroll, submit, input/change, focus/blur/focusin/focusout, keydown/keyup (every key), drag/dragstart/dragenter/dragover/dragleave/drop/dragend with `dataTransfer` — on elements, `<svelte:window>` and `<svelte:document>` |
|
|
45
|
+
| `contenteditable` | rich text: `<b>`, `<em>`, `<u>`, `<s>`, `<span style>`… style the text in a native text area; typing stays in the element it happened in; `window.getSelection()`, `document.execCommand` (`bold`, `italic`, `underline`, `strikeThrough`, `insertText`, `insertLineBreak`, `delete`, `forwardDelete`), `queryCommandState`, Ctrl+B/I/U |
|
|
46
|
+
| bindings | `value` (inputs, `<select>` with any values), `checked`, `group`, `textContent/innerHTML` (`contenteditable`), `clientWidth/Height`, `contentRect`, `innerWidth/innerHeight`, `<audio>`/`<video>` `paused/currentTime/duration/volume/muted`, `videoWidth/videoHeight` |
|
|
47
|
+
| layout reads | `getBoundingClientRect` (after ancestor scroll offsets), `offsetTop/Left/Width/Height`, `ResizeObserver`, `IntersectionObserver` (`root`, `rootMargin`, `threshold`; clipped by scroll ancestors and the window), `input.selectionStart/End`. Reads are synchronous like a browser's forced layout: after a change (or in `onMount`) native lays out and answers in ~1 ms |
|
|
48
|
+
| `transition:`, `in:`, `out:`, `animate()` | keyframes played at 60 fps, interpolated, with easing, iterations and direction |
|
|
49
|
+
| `querySelector(All)`, `matches`, `closest`, `MutationObserver` | over the Svelte DOM |
|
|
50
|
+
| `element.focus()`, `<svelte:head><title>` | native focus, the window title (updated live) |
|
|
51
|
+
| `<TitleBar>` (`import { TitleBar } from "@tarve/svelte"`) or `mount(App, { window: { titleBar: true } })` | Tarve's custom title bar instead of the native frame, showing the `<svelte:head><title>`; props `title`, `height`, `glass`, `appearance`, `showMinimize/Maximize/Close`, children replace the title. `window-action="minimize\|toggleMaximize\|close"` makes any element a window control, `drag-region` a drag handle |
|
|
52
|
+
|
|
53
|
+
`bun run smoke:svelte-input` drives a built app with real Windows input (cursor, clicks, wheel, keys)
|
|
54
|
+
and checks what the components saw; it moves the mouse while it runs.
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarve/svelte",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "Svelte 5 components in native Tarve windows",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"tarve",
|
|
9
|
+
"svelte",
|
|
10
|
+
"gui",
|
|
11
|
+
"desktop",
|
|
12
|
+
"native"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/omarcosr/tarve.git",
|
|
17
|
+
"directory": "packages/svelte"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"provenance": true
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./src/index.ts",
|
|
25
|
+
"./compiler": "./src/compiler.ts",
|
|
26
|
+
"./plugin": "./src/plugin.ts",
|
|
27
|
+
"./bun": "./src/bun.ts",
|
|
28
|
+
"./css": "./src/css.ts",
|
|
29
|
+
"./dom": "./src/dom.ts",
|
|
30
|
+
"./install": "./src/install.ts",
|
|
31
|
+
"./bun-preload": "./src/bun-preload.ts",
|
|
32
|
+
"./elements": {
|
|
33
|
+
"types": "./src/elements.d.ts"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"src",
|
|
38
|
+
"!src/**/*.test.ts",
|
|
39
|
+
"!src/fixtures",
|
|
40
|
+
"README.md"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"svelte": "^5.57.2"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@tarve/core": "^0.8.0"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"bun": ">=1.4.0",
|
|
50
|
+
"node": ">=26.10.0"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Tarve's custom title bar: the window drops its native frame and draws this bar,
|
|
3
|
+
with the minimize/maximize/close controls. Without `title` it shows the
|
|
4
|
+
`<svelte:head><title>`; children replace the title.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { Snippet } from "svelte";
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
title,
|
|
11
|
+
height,
|
|
12
|
+
glass,
|
|
13
|
+
appearance,
|
|
14
|
+
showMinimize,
|
|
15
|
+
showMaximize,
|
|
16
|
+
showClose,
|
|
17
|
+
class: className,
|
|
18
|
+
style,
|
|
19
|
+
children,
|
|
20
|
+
}: {
|
|
21
|
+
title?: string;
|
|
22
|
+
height?: number;
|
|
23
|
+
glass?: boolean | "regular" | "clear";
|
|
24
|
+
appearance?: "light" | "dark";
|
|
25
|
+
showMinimize?: boolean;
|
|
26
|
+
showMaximize?: boolean;
|
|
27
|
+
showClose?: boolean;
|
|
28
|
+
class?: string;
|
|
29
|
+
style?: string;
|
|
30
|
+
children?: Snippet;
|
|
31
|
+
} = $props();
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<titlebar
|
|
35
|
+
{title}
|
|
36
|
+
{height}
|
|
37
|
+
{appearance}
|
|
38
|
+
{style}
|
|
39
|
+
class={className}
|
|
40
|
+
glass={glass === true ? "" : glass || undefined}
|
|
41
|
+
show-minimize={showMinimize}
|
|
42
|
+
show-maximize={showMaximize}
|
|
43
|
+
show-close={showClose}
|
|
44
|
+
>{@render children?.()}</titlebar>
|
package/src/bun.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { sveltePlugin, type SveltePluginOptions } from "./plugin";
|
|
2
|
+
|
|
3
|
+
let registered = false;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Lets Bun import `.svelte` files at runtime. Register before the first `.svelte`
|
|
7
|
+
* import: from a `bunfig.toml` `preload`, or before a dynamic `import()`.
|
|
8
|
+
*/
|
|
9
|
+
export function registerSvelte(options?: SveltePluginOptions): void {
|
|
10
|
+
if (registered) return;
|
|
11
|
+
registered = true;
|
|
12
|
+
Bun.plugin(sveltePlugin(options) as unknown as Parameters<typeof Bun.plugin>[0]);
|
|
13
|
+
}
|
package/src/compiler.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { compile, compileModule, type CompileOptions } from "svelte/compiler";
|
|
2
|
+
import { parseCss } from "./css";
|
|
3
|
+
|
|
4
|
+
export interface CompileTarget {
|
|
5
|
+
/** Rewrites the compiled module's import specifiers (`svelte` to its client build, relative paths to absolute ones…). */
|
|
6
|
+
resolve?: (specifier: string) => string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const IMPORT = /(\bfrom\s*|\bimport\s*\(?\s*)(["'])([^"'\n]+)\2/g;
|
|
10
|
+
|
|
11
|
+
function rewriteImports(code: string, resolve: CompileTarget["resolve"]): string {
|
|
12
|
+
return resolve ? code.replace(IMPORT, (_, prefix: string, quote: string, specifier: string) => prefix + quote + resolve(specifier) + quote) : code;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CompiledSvelte {
|
|
16
|
+
code: string;
|
|
17
|
+
warnings: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Compiles a `.svelte` component for Tarve: Svelte's client output (createElement
|
|
22
|
+
* templates instead of innerHTML), with its CSS resolved into style rules at build time.
|
|
23
|
+
*/
|
|
24
|
+
export function compileSvelte(source: string, filename: string, options: CompileOptions = {}, target: CompileTarget = {}): CompiledSvelte {
|
|
25
|
+
const result = compile(source, { filename, generate: "client", css: "external", fragments: "tree", discloseVersion: false, ...options });
|
|
26
|
+
const warnings = result.warnings.map(warning => `${filename}: ${warning.message}`);
|
|
27
|
+
let code = 'import "@tarve/svelte/install";\n' + result.js.code;
|
|
28
|
+
if (result.css?.code) {
|
|
29
|
+
const rules = parseCss(result.css.code, message => warnings.push(`${filename}: ${message}`));
|
|
30
|
+
if (rules.length) code += `\nimport { registerCss as __tarve_registerCss } from "@tarve/svelte/css";\n__tarve_registerCss(${JSON.stringify(rules)});\n`;
|
|
31
|
+
}
|
|
32
|
+
return { code: rewriteImports(code, target.resolve), warnings };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Compiles a `.svelte.js`/`.svelte.ts` module (runes outside components). TypeScript must be stripped first. */
|
|
36
|
+
export function compileSvelteModule(source: string, filename: string, target: CompileTarget = {}): CompiledSvelte {
|
|
37
|
+
const result = compileModule(source, { filename, generate: "client" });
|
|
38
|
+
return { code: rewriteImports('import "@tarve/svelte/install";\n' + result.js.code, target.resolve), warnings: result.warnings.map(warning => `${filename}: ${warning.message}`) };
|
|
39
|
+
}
|