@hyacine/core 0.0.1

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/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@hyacine/core",
3
+ "version": "0.0.1",
4
+ "files": [
5
+ "dist",
6
+ "src"
7
+ ],
8
+ "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.ts",
12
+ "default": "./src/index.ts"
13
+ },
14
+ "./config": {
15
+ "types": "./src/config.ts",
16
+ "default": "./src/config.ts"
17
+ },
18
+ "./plugin": {
19
+ "types": "./src/plugin.d.ts",
20
+ "default": "./src/plugin.d.ts"
21
+ },
22
+ "./constants": {
23
+ "types": "./src/constants.ts",
24
+ "default": "./src/constants.ts"
25
+ }
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "lint": "bunx --bun oxlint --type-aware --type-check . --fix",
30
+ "format": "bunx oxfmt ."
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5"
34
+ }
35
+ }
package/src/config.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { PluginManifest } from "./plugin";
2
+
3
+ export type PluginFunction<O = any> = (options: O) => PluginManifest;
4
+
5
+ export function definePlugin(manifest: PluginManifest): PluginManifest {
6
+ return manifest;
7
+ }
8
+
9
+ export type injectPoint =
10
+ | "head"
11
+ | "layout"
12
+ | "right-nav"
13
+ | "left-nav"
14
+ | "post-meta"
15
+ | "sidebar"
16
+ | "footer"
17
+ | "widgets"
18
+ | "post-footer"
19
+ | "comment"
20
+ | "footer-status"
21
+ | "toolbar"
22
+ | "segments-sticky";
23
+
24
+ export type injectPoints = Record<string, string> & Partial<Record<injectPoint, string>>;
25
+
26
+ export interface HyacinePluginSystemConfig {
27
+ injectPoints: injectPoints;
28
+ plugins: Array<PluginManifest>;
29
+ }
30
+
31
+ export function defineConfig<T extends HyacinePluginSystemConfig>(config: T): T {
32
+ return config;
33
+ }
@@ -0,0 +1,5 @@
1
+ export const PLUGIN_API_VERSION = {
2
+ major: 0,
3
+ minor: 0,
4
+ patch: 1,
5
+ };
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./config";
2
+ export * from "./constants";
3
+ export * from "./plugin";
package/src/plugin.ts ADDED
@@ -0,0 +1,91 @@
1
+ import type { injectPoint } from "./config";
2
+
3
+ /**
4
+ * 对于一个插件而言,其渲染类型只能是以下三种之一
5
+ * - runtime-only: 仅运行时渲染,入口点只能包括一个或多个 js/ts 文件,不能包含任何模板文件
6
+ * - custom-element: 基于 Web Components 的渲染,入口点可以包含一个或多个 js/ts 文件和编译为 Web Component 的模板文件(或 Web Component本身),可以指定 universal 平台
7
+ * - ssr: 服务器端渲染,入口点可以包含一个或多个 js/ts 文件和用于服务器端渲染的模板文件,必须针对每个平台指定不同的入口点
8
+ */
9
+ export type pluginRenderType = "runtime-only" | "custom-element" | "ssr";
10
+
11
+ /**
12
+ * 插件支持的平台类型
13
+ * - astro: 适用于 Astro 框架的插件
14
+ * - valaxy: 适用于 Valaxy 框架的插件
15
+ * - universal: 通用插件,适用于所有支持插件的框架
16
+ */
17
+ export type pluginPlatformType = "astro" | "valaxy" | "universal";
18
+
19
+ export interface PluginManifestBase {
20
+ name: string;
21
+ version: string;
22
+ /**
23
+ * 此处接受 package.json 式的 semver 版本范围字符串,例如 ^0.0.1、~1.2.0 等
24
+ * 用于指定该插件兼容的插件 API 版本范围
25
+ * 如果未指定,则默认为 * ,表示兼容所有版本
26
+ */
27
+ compatibleAPIPattern?: string;
28
+ /**
29
+ * 插件的最小渲染能力,决定了插件可以包含的入口点类型
30
+ */
31
+ minRenderCapability: pluginRenderType;
32
+ }
33
+
34
+ export interface InjectEntry {
35
+ injectPoint?: injectPoint | (string & {});
36
+ type: "runtime-only" | "custom-element" | "ssr";
37
+ path: string;
38
+ name: string;
39
+ }
40
+
41
+ export interface RuntimeOnlyEntry extends InjectEntry {
42
+ type: "runtime-only";
43
+ /**
44
+ * 传递给 runtime-only 插件 init 函数的配置选项
45
+ * 注意:options 值必须是可序列化的,避免传递函数、Symbol 等不可序列化的值
46
+ */
47
+ options?: Record<string, unknown>;
48
+ }
49
+
50
+ export interface RuntimeOnlyPluginManifest extends PluginManifestBase {
51
+ minRenderCapability: "runtime-only";
52
+ entry: RuntimeOnlyEntry[];
53
+ }
54
+
55
+ /**
56
+ * 基于 Web Components 的插件入口点
57
+ * 入口点将会在 Layout 内放置一个隐藏的 Astro 组件,以确保其在页面加载时进行 SSR 水合
58
+ */
59
+ export interface CustomElementEntry extends InjectEntry {
60
+ type: "custom-element";
61
+ injectPoint: "layout";
62
+ }
63
+
64
+ export interface CustomElementPluginManifest extends PluginManifestBase {
65
+ minRenderCapability: "custom-element";
66
+ supportedPlatforms: pluginPlatformType[];
67
+ entry: Array<CustomElementEntry | RuntimeOnlyEntry>;
68
+ }
69
+
70
+ export interface SSREntry extends InjectEntry {
71
+ type: "ssr";
72
+ platform: pluginPlatformType;
73
+ injectPoint: string;
74
+ clientHydrationInstruction?: "load" | "idle" | "visible" | "media";
75
+ /**
76
+ * 传递给 SSR 组件的 props
77
+ * 注意:props 值必须是可序列化的,避免传递函数、Symbol 等不可序列化的值
78
+ */
79
+ props?: Record<string, unknown>;
80
+ }
81
+
82
+ export interface SSRPluginManifest extends PluginManifestBase {
83
+ minRenderCapability: "ssr";
84
+ supportedPlatforms: pluginPlatformType[];
85
+ entry: Array<SSREntry | CustomElementEntry | RuntimeOnlyEntry>;
86
+ }
87
+
88
+ export type PluginManifest =
89
+ | RuntimeOnlyPluginManifest
90
+ | CustomElementPluginManifest
91
+ | SSRPluginManifest;