@samva/vite 0.1.2 → 0.3.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/AGENTS.md +70 -1
- package/README.md +92 -44
- package/dist/build.d.ts +47 -28
- package/dist/build.js +166 -67
- package/dist/editor/assets/index-Cg4x6ewh.css +2 -0
- package/dist/editor/assets/index-Cot9JDdw.js +30 -0
- package/dist/editor/index.html +2 -2
- package/dist/email.d.ts +60 -0
- package/dist/email.js +126 -0
- package/dist/emit.d.ts +13 -30
- package/dist/emit.js +29 -123
- package/dist/index.d.ts +1 -4
- package/dist/index.js +480 -305
- package/dist/project.d.ts +116 -0
- package/dist/project.js +294 -0
- package/dist/theme-CBF6Czjm.js +50 -0
- package/package.json +28 -20
- package/dist/editor/assets/authoring-editor-ClA5aqFP-CO-FhsWG.js +0 -145
- package/dist/editor/assets/index-CI_j2PFe.css +0 -2
- package/dist/editor/assets/index-DbdWiln3.js +0 -84
- package/dist/theme-CfJe8s3k.js +0 -138
package/dist/theme-CfJe8s3k.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { readFile, readdir } from "node:fs/promises";
|
|
2
|
-
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
|
-
import { Result } from "effect";
|
|
4
|
-
import { parseThemeCss } from "@samva/markup/theme-css";
|
|
5
|
-
//#region src/discovery.ts
|
|
6
|
-
const kindForFile = (name) => {
|
|
7
|
-
if (name.endsWith(".tsx")) return "tsx";
|
|
8
|
-
if (name.endsWith(".samva")) return "samva";
|
|
9
|
-
};
|
|
10
|
-
const toPosix = (value) => sep === "/" ? value : value.split(sep).join("/");
|
|
11
|
-
/**
|
|
12
|
-
* Recursively lists template files under `dir`. Hidden entries and
|
|
13
|
-
* `node_modules` are skipped. Results are sorted by id for deterministic
|
|
14
|
-
* ordering (the preview list and build output must be stable).
|
|
15
|
-
*/
|
|
16
|
-
const discoverTemplateFiles = async (dir) => {
|
|
17
|
-
const found = [];
|
|
18
|
-
const walk = async (current) => {
|
|
19
|
-
const visible = (await readdir(current, { withFileTypes: true }).catch(() => [])).filter((entry) => !entry.name.startsWith(".") && entry.name !== "node_modules");
|
|
20
|
-
await Promise.all(visible.map(async (entry) => {
|
|
21
|
-
const full = join(current, entry.name);
|
|
22
|
-
if (entry.isDirectory()) {
|
|
23
|
-
await walk(full);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const kind = kindForFile(entry.name);
|
|
27
|
-
if (kind !== void 0) found.push({
|
|
28
|
-
path: full,
|
|
29
|
-
id: toPosix(relative(dir, full)),
|
|
30
|
-
kind
|
|
31
|
-
});
|
|
32
|
-
}));
|
|
33
|
-
};
|
|
34
|
-
await walk(dir);
|
|
35
|
-
return found.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
36
|
-
};
|
|
37
|
-
const NO_THEME = {
|
|
38
|
-
tokens: void 0,
|
|
39
|
-
diagnostics: []
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Resolves the `theme` plugin option to an absolute path, or `undefined` when
|
|
43
|
-
* theming is explicitly disabled (`theme: false`). A string is taken relative to
|
|
44
|
-
* `root` (absolute strings pass through); the default is `<root>/theme.css`.
|
|
45
|
-
*/
|
|
46
|
-
const resolveThemePath = (root, option) => {
|
|
47
|
-
if (option === false) return void 0;
|
|
48
|
-
const file = option ?? "theme.css";
|
|
49
|
-
return isAbsolute(file) ? file : resolve(root, file);
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Reads and parses the project theme file. A missing file is not an error —
|
|
53
|
-
* previews render with base tokens only, no warning (per the brief). A present
|
|
54
|
-
* file with parse errors yields the diagnostics and no tokens; the caller decides
|
|
55
|
-
* whether to keep a previously-good theme.
|
|
56
|
-
*/
|
|
57
|
-
const loadProjectTheme = async (themePath) => {
|
|
58
|
-
if (themePath === void 0) return NO_THEME;
|
|
59
|
-
const css = await readFile(themePath, "utf8").catch((cause) => cause.code === "ENOENT" ? void 0 : cause);
|
|
60
|
-
if (css === void 0) return NO_THEME;
|
|
61
|
-
if (typeof css !== "string") return {
|
|
62
|
-
tokens: void 0,
|
|
63
|
-
diagnostics: [{
|
|
64
|
-
code: "theme-read-error",
|
|
65
|
-
message: `could not read theme file: ${css.message}`,
|
|
66
|
-
span: {
|
|
67
|
-
start: 0,
|
|
68
|
-
end: 0
|
|
69
|
-
}
|
|
70
|
-
}]
|
|
71
|
-
};
|
|
72
|
-
const parsed = parseThemeCss(css);
|
|
73
|
-
if (Result.isFailure(parsed)) return {
|
|
74
|
-
tokens: void 0,
|
|
75
|
-
diagnostics: parsed.failure
|
|
76
|
-
};
|
|
77
|
-
return {
|
|
78
|
-
tokens: parsed.success,
|
|
79
|
-
diagnostics: []
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Folds a parsed theme into per-preview `CompileOptions` as the org-token layer,
|
|
84
|
-
* preserving any base/template layers the caller already configured. Returns the
|
|
85
|
-
* input unchanged when there is no theme to apply.
|
|
86
|
-
*/
|
|
87
|
-
const withThemeLayer = (compile, tokens) => {
|
|
88
|
-
if (tokens === void 0) return compile;
|
|
89
|
-
return {
|
|
90
|
-
...compile,
|
|
91
|
-
theme: {
|
|
92
|
-
...compile?.theme,
|
|
93
|
-
overrides: [tokens, ...compile?.theme?.overrides ?? []]
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Mutable holder for the dev server: parses `theme.css` on demand and keeps the
|
|
99
|
-
* LAST GOOD tokens when a re-parse fails, so an in-flight syntax error never
|
|
100
|
-
* blanks the preview — it renders the previous theme plus the parse diagnostics.
|
|
101
|
-
*/
|
|
102
|
-
var ThemeState = class {
|
|
103
|
-
themePath;
|
|
104
|
-
tokens = void 0;
|
|
105
|
-
diagnostics = [];
|
|
106
|
-
pending = Promise.resolve(NO_THEME);
|
|
107
|
-
constructor(themePath) {
|
|
108
|
-
this.themePath = themePath;
|
|
109
|
-
}
|
|
110
|
-
/** Re-reads + re-parses (serialized); on failure keeps the last good tokens. */
|
|
111
|
-
refresh() {
|
|
112
|
-
const run = async () => {
|
|
113
|
-
const next = await loadProjectTheme(this.themePath);
|
|
114
|
-
if (next.diagnostics.length === 0) {
|
|
115
|
-
this.tokens = next.tokens;
|
|
116
|
-
this.diagnostics = [];
|
|
117
|
-
} else this.diagnostics = next.diagnostics;
|
|
118
|
-
return this.current();
|
|
119
|
-
};
|
|
120
|
-
this.pending = this.pending.then(run, run);
|
|
121
|
-
return this.pending;
|
|
122
|
-
}
|
|
123
|
-
/** Current tokens (last good) + diagnostics (from the most recent parse). */
|
|
124
|
-
current() {
|
|
125
|
-
return {
|
|
126
|
-
tokens: this.tokens,
|
|
127
|
-
diagnostics: this.diagnostics
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/** Applies the current theme layer to a caller's compile options. */
|
|
131
|
-
applyTo(compile) {
|
|
132
|
-
return withThemeLayer(compile, this.tokens);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
//#endregion
|
|
136
|
-
export { discoverTemplateFiles as a, withThemeLayer as i, loadProjectTheme as n, resolveThemePath as r, ThemeState as t };
|
|
137
|
-
|
|
138
|
-
//# sourceMappingURL=theme-CfJe8s3k.js.map
|