@ternkit/tern 1.3.0 → 1.5.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/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/runtime/deferred.d.ts +5 -1
- package/dist/runtime/deferred.js +27 -11
- package/dist/runtime/validate.d.ts +31 -0
- package/dist/runtime/validate.js +168 -0
- package/dist/server/intl.js +55 -12
- package/dist/ui/AlertDialog.svelte +79 -0
- package/dist/ui/AlertDialog.svelte.d.ts +24 -0
- package/dist/ui/AreaChart.svelte +9 -0
- package/dist/ui/AreaChart.svelte.d.ts +26 -0
- package/dist/ui/AspectRatio.svelte +33 -0
- package/dist/ui/AspectRatio.svelte.d.ts +10 -0
- package/dist/ui/BarChart.svelte +170 -0
- package/dist/ui/BarChart.svelte.d.ts +40 -0
- package/dist/ui/Breadcrumb.svelte +92 -0
- package/dist/ui/Breadcrumb.svelte.d.ts +14 -0
- package/dist/ui/ButtonGroup.svelte +61 -0
- package/dist/ui/ButtonGroup.svelte.d.ts +12 -0
- package/dist/ui/Calendar.svelte +265 -0
- package/dist/ui/Calendar.svelte.d.ts +28 -0
- package/dist/ui/Carousel.svelte +169 -0
- package/dist/ui/Carousel.svelte.d.ts +36 -0
- package/dist/ui/ChartFrame.svelte +174 -0
- package/dist/ui/ChartFrame.svelte.d.ts +24 -0
- package/dist/ui/Checkbox.svelte +13 -1
- package/dist/ui/Collapsible.svelte +59 -0
- package/dist/ui/Collapsible.svelte.d.ts +12 -0
- package/dist/ui/Combobox.svelte +350 -0
- package/dist/ui/Combobox.svelte.d.ts +24 -0
- package/dist/ui/Command.svelte +268 -0
- package/dist/ui/Command.svelte.d.ts +28 -0
- package/dist/ui/ConsentScreen.svelte +125 -0
- package/dist/ui/ConsentScreen.svelte.d.ts +21 -0
- package/dist/ui/ContextMenu.svelte +78 -0
- package/dist/ui/ContextMenu.svelte.d.ts +13 -0
- package/dist/ui/DataTable.svelte +277 -0
- package/dist/ui/DataTable.svelte.d.ts +53 -0
- package/dist/ui/DatePicker.svelte +138 -0
- package/dist/ui/DatePicker.svelte.d.ts +25 -0
- package/dist/ui/Dialog.svelte +168 -27
- package/dist/ui/Dialog.svelte.d.ts +10 -0
- package/dist/ui/DonutChart.svelte +115 -0
- package/dist/ui/DonutChart.svelte.d.ts +40 -0
- package/dist/ui/Drawer.svelte +19 -0
- package/dist/ui/Drawer.svelte.d.ts +14 -0
- package/dist/ui/Empty.svelte +62 -0
- package/dist/ui/Empty.svelte.d.ts +15 -0
- package/dist/ui/Field.svelte +22 -2
- package/dist/ui/Field.svelte.d.ts +2 -0
- package/dist/ui/Form.svelte +159 -0
- package/dist/ui/Form.svelte.d.ts +21 -0
- package/dist/ui/HoverCard.svelte +106 -0
- package/dist/ui/HoverCard.svelte.d.ts +26 -0
- package/dist/ui/Input.svelte +2 -1
- package/dist/ui/InputGroup.svelte +80 -0
- package/dist/ui/InputGroup.svelte.d.ts +13 -0
- package/dist/ui/InputOTP.svelte +140 -0
- package/dist/ui/InputOTP.svelte.d.ts +18 -0
- package/dist/ui/Item.svelte +86 -0
- package/dist/ui/Item.svelte.d.ts +17 -0
- package/dist/ui/Label.svelte +29 -0
- package/dist/ui/Label.svelte.d.ts +10 -0
- package/dist/ui/LineChart.svelte +171 -0
- package/dist/ui/LineChart.svelte.d.ts +42 -0
- package/dist/ui/Menu.svelte +22 -151
- package/dist/ui/Menu.svelte.d.ts +3 -10
- package/dist/ui/MenuList.svelte +317 -0
- package/dist/ui/MenuList.svelte.d.ts +29 -0
- package/dist/ui/Menubar.svelte +133 -0
- package/dist/ui/Menubar.svelte.d.ts +14 -0
- package/dist/ui/NavigationMenu.svelte +208 -0
- package/dist/ui/NavigationMenu.svelte.d.ts +18 -0
- package/dist/ui/Pagination.svelte +114 -0
- package/dist/ui/Pagination.svelte.d.ts +16 -0
- package/dist/ui/PasswordInput.svelte +134 -0
- package/dist/ui/PasswordInput.svelte.d.ts +11 -0
- package/dist/ui/Popover.svelte +127 -0
- package/dist/ui/Popover.svelte.d.ts +29 -0
- package/dist/ui/Resizable.svelte +122 -0
- package/dist/ui/Resizable.svelte.d.ts +16 -0
- package/dist/ui/ScrollArea.svelte +43 -0
- package/dist/ui/ScrollArea.svelte.d.ts +13 -0
- package/dist/ui/Select.svelte +3 -2
- package/dist/ui/SelectMenu.svelte +301 -0
- package/dist/ui/SelectMenu.svelte.d.ts +18 -0
- package/dist/ui/Sheet.svelte +21 -0
- package/dist/ui/Sheet.svelte.d.ts +16 -0
- package/dist/ui/Sidebar.svelte +263 -0
- package/dist/ui/Sidebar.svelte.d.ts +35 -0
- package/dist/ui/SignIn.svelte +182 -0
- package/dist/ui/SignIn.svelte.d.ts +38 -0
- package/dist/ui/SignUp.svelte +106 -0
- package/dist/ui/SignUp.svelte.d.ts +23 -0
- package/dist/ui/Slider.svelte +196 -0
- package/dist/ui/Slider.svelte.d.ts +19 -0
- package/dist/ui/Sparkline.svelte +23 -0
- package/dist/ui/Sparkline.svelte.d.ts +11 -0
- package/dist/ui/Stat.svelte +91 -0
- package/dist/ui/Stat.svelte.d.ts +18 -0
- package/dist/ui/Table.svelte +70 -0
- package/dist/ui/Table.svelte.d.ts +36 -0
- package/dist/ui/Textarea.svelte +2 -1
- package/dist/ui/Toggle.svelte +82 -0
- package/dist/ui/Toggle.svelte.d.ts +17 -0
- package/dist/ui/ToggleGroup.svelte +143 -0
- package/dist/ui/ToggleGroup.svelte.d.ts +27 -0
- package/dist/ui/Tooltip.svelte +27 -19
- package/dist/ui/Tooltip.svelte.d.ts +2 -1
- package/dist/ui/chart.d.ts +26 -0
- package/dist/ui/chart.js +89 -0
- package/dist/ui/dates.d.ts +13 -0
- package/dist/ui/dates.js +64 -0
- package/dist/ui/field.d.ts +8 -0
- package/dist/ui/floating.d.ts +44 -0
- package/dist/ui/floating.js +97 -0
- package/dist/ui/form.d.ts +12 -0
- package/dist/ui/form.js +8 -0
- package/dist/ui/index.d.ts +54 -0
- package/dist/ui/index.js +43 -0
- package/dist/ui/menu.d.ts +25 -0
- package/dist/ui/menu.js +1 -0
- package/dist/ui/options.d.ts +17 -0
- package/dist/ui/options.js +22 -0
- package/dist/ui/table.d.ts +26 -0
- package/dist/ui/table.js +1 -0
- package/dist/ui/theme.css +25 -0
- package/dist/vite/index.js +12 -3
- package/dist/vite/native.d.ts +3 -0
- package/dist/vite/native.js +122 -0
- package/package.json +3 -2
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { parse } from 'acorn';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
export const NATIVE_IR = '.tern/native/ir.json';
|
|
5
|
+
function svelteVersion(root) {
|
|
6
|
+
try {
|
|
7
|
+
const pkg = path.join(path.dirname(require_resolve('svelte/package.json', root)));
|
|
8
|
+
return JSON.parse(fs.readFileSync(path.join(pkg, 'package.json'), 'utf8')).version;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function require_resolve(spec, root) {
|
|
15
|
+
// Find svelte's package.json from the app's node_modules, as Vite does.
|
|
16
|
+
let dir = root;
|
|
17
|
+
for (;;) {
|
|
18
|
+
const candidate = path.join(dir, 'node_modules', spec);
|
|
19
|
+
if (fs.existsSync(candidate))
|
|
20
|
+
return candidate;
|
|
21
|
+
const up = path.dirname(dir);
|
|
22
|
+
if (up === dir)
|
|
23
|
+
throw new Error(`cannot find ${spec}`);
|
|
24
|
+
dir = up;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function nativePlugin(getRoot, entry) {
|
|
28
|
+
const modules = new Map();
|
|
29
|
+
let active = false;
|
|
30
|
+
let env = {};
|
|
31
|
+
let base = '/';
|
|
32
|
+
// Asset URLs are placeholders in a module (import.meta.ROLLDOWN_FILE_URL_…)
|
|
33
|
+
// until the bundle is written: their final URLs go in the IR.
|
|
34
|
+
const fileRefs = new Set();
|
|
35
|
+
const fileUrls = {};
|
|
36
|
+
const bundled = {};
|
|
37
|
+
const rel = (file) => path.relative(getRoot(), file).split(path.sep).join('/');
|
|
38
|
+
// Every module is recorded, Svelte's own runtime included: compiling its
|
|
39
|
+
// code, rather than rewriting it, keeps the output exactly Svelte's.
|
|
40
|
+
const native = (_file) => false;
|
|
41
|
+
return {
|
|
42
|
+
name: 'tern:native-ir',
|
|
43
|
+
enforce: 'post',
|
|
44
|
+
configResolved(config) {
|
|
45
|
+
active = !!config.build.ssr && process.env.TERN_NATIVE === '1';
|
|
46
|
+
env = JSON.parse(JSON.stringify({ ...config.env, SSR: true }));
|
|
47
|
+
base = config.base || '/';
|
|
48
|
+
},
|
|
49
|
+
async transform(code, id) {
|
|
50
|
+
if (!active || id.startsWith('\0'))
|
|
51
|
+
return null;
|
|
52
|
+
// Modules with a query, such as an asset's ?url, are recorded under
|
|
53
|
+
// their whole id; what isn't JavaScript fails to parse and is left out.
|
|
54
|
+
const file = id;
|
|
55
|
+
const query = id.includes('?');
|
|
56
|
+
if ((!query && !/\.(svelte|[cm]?[jt]s|[jt]sx|json)$/.test(file)) || native(file))
|
|
57
|
+
return null;
|
|
58
|
+
try {
|
|
59
|
+
const ast = parse(code, { ecmaVersion: 'latest', sourceType: 'module' });
|
|
60
|
+
const imports = {};
|
|
61
|
+
for (const node of ast.body) {
|
|
62
|
+
const source = node.type === 'ImportDeclaration' || node.type === 'ExportAllDeclaration' || (node.type === 'ExportNamedDeclaration' && node.source)
|
|
63
|
+
? node.source.value
|
|
64
|
+
: null;
|
|
65
|
+
if (source === null || source in imports)
|
|
66
|
+
continue;
|
|
67
|
+
const resolved = await this.resolve(source, id, { ssr: true });
|
|
68
|
+
const target = resolved && !resolved.external && !resolved.id.startsWith('\0') ? resolved.id : null;
|
|
69
|
+
imports[source] = target && !native(target) ? rel(target) : null;
|
|
70
|
+
}
|
|
71
|
+
modules.set(file, { id: rel(file), imports, ast, code });
|
|
72
|
+
for (const m of code.matchAll(/import\.meta\.((?:ROLLDOWN|ROLLUP|VITE)_FILE_URL_([\w$]+))/g))
|
|
73
|
+
fileRefs.add(m[1]);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Not JavaScript we can read: the module stays unrecorded, so
|
|
77
|
+
// whatever imports it renders with the JavaScript engine.
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
},
|
|
81
|
+
generateBundle(_opts, bundle) {
|
|
82
|
+
if (!active)
|
|
83
|
+
return;
|
|
84
|
+
// What the bundler kept code of: modules it tree-shook away aren't
|
|
85
|
+
// compiled.
|
|
86
|
+
for (const out of Object.values(bundle)) {
|
|
87
|
+
if (out.type !== 'chunk')
|
|
88
|
+
continue;
|
|
89
|
+
for (const [id, m] of Object.entries(out.modules))
|
|
90
|
+
if (m.renderedLength > 0)
|
|
91
|
+
bundled[rel(id)] = true;
|
|
92
|
+
}
|
|
93
|
+
for (const ref of fileRefs) {
|
|
94
|
+
try {
|
|
95
|
+
fileUrls[ref] = path.posix.join(base, this.getFileName(ref.replace(/^(?:ROLLDOWN|ROLLUP|VITE)_FILE_URL_/, '')));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Not a file of this build: the module falls back.
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
closeBundle() {
|
|
103
|
+
if (!active)
|
|
104
|
+
return;
|
|
105
|
+
const root = getRoot();
|
|
106
|
+
const out = path.join(root, NATIVE_IR);
|
|
107
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
108
|
+
const ir = { version: 1, svelte: svelteVersion(root), entry, env, fileUrls, bundled, modules: [...modules.values()] };
|
|
109
|
+
try {
|
|
110
|
+
// BigInt literals keep their digits in the node's bigint field;
|
|
111
|
+
// their value, which JSON can't hold, is left out.
|
|
112
|
+
fs.writeFileSync(out, JSON.stringify(ir, (_k, v) => (typeof v === 'bigint' ? null : v)));
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
// Native rendering is an optimisation: without the IR, tern build
|
|
116
|
+
// skips it and pages render with the JavaScript engine.
|
|
117
|
+
fs.rmSync(out, { force: true });
|
|
118
|
+
this.warn(`native rendering skipped: ${err.message}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ternkit/tern",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Client runtime and Vite plugin for Tern: Svelte on the client, Go on the server",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -71,7 +71,8 @@
|
|
|
71
71
|
"vite": "^8.0.0"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@sveltejs/vite-plugin-svelte": "^7.3.1"
|
|
74
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
75
|
+
"acorn": "^8.19.0"
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
78
|
"@sveltejs/package": "^3.0.2",
|