@picloom/theme-sdk 0.0.0-stage → 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -2
  3. package/index.ts +207 -0
  4. package/package.json +24 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 lllei
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,46 @@
1
- # Temporary Holding Version
1
+ # @picloom/theme-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript contracts for trusted Picloom home and login themes.
4
+ Create a project with `bun create @picloom/theme@0.1.1 ./my-theme`, or install
5
+ the types with `bun add --dev @picloom/theme-sdk@0.1.1`.
6
+
7
+ ```ts
8
+ import type { ThemeContext } from "@picloom/theme-sdk";
9
+
10
+ export function mount(container: HTMLElement, context: ThemeContext) {
11
+ const unsubscribe = context.subscribe((state) => {
12
+ container.textContent = state.site.name;
13
+ });
14
+ return { dispose() { unsubscribe(); container.replaceChildren(); } };
15
+ }
16
+ ```
17
+
18
+ Bundle your own framework and dispose listeners and framework instances when unmounted.
19
+ The host injects runtime capabilities; do not import application-internal modules.
20
+ Theme configuration and package assets are public. Theme code is trusted and login
21
+ themes can read entered credentials; install reviewed packages only.
22
+
23
+ Use `@picloom/create-theme` for a standalone Vue project using the independently maintained
24
+ template in `tools/create-theme/template/`. Horizon in the separate `picloom-extensions/themes/horizon` project is the advanced example.
25
+
26
+ SDK snapshots and helpers are framework-independent. In Vue themes, assign each `subscribe()` snapshot to a local ref and derive computed values from that ref. Calls such as `t()`, `localized()` and `links.format()` do not establish reactive dependencies in the theme's bundled Vue runtime: do not cache their results in a computed value without explicitly depending on the relevant snapshot fields (`locale` or `copy.format`). The examples call these helpers during rendering, which is triggered by their snapshot subscription. Configuration is fixed for a mount; draft changes are picked up when a new preview is loaded.
27
+
28
+ Core errors and notifications in snapshots are translated at display time and update with the current language. Recognized error codes use core dictionaries; unknown errors preserve their original text. Themes continue to receive strings and do not need access to core translation keys. Language changes do not restart notification dismissal timers.
29
+
30
+ ## Documentation
31
+
32
+ - [Quick start](https://llleixx.github.io/picloom/development/theme-tooling.html)
33
+ - [Theme protocol and localized configuration](https://llleixx.github.io/picloom/development/themes.html)
34
+ - [Schema reference](https://llleixx.github.io/picloom/development/schema.html)
35
+ - [Messages and form hints](https://llleixx.github.io/picloom/development/package-localization.html)
36
+ - [Tool maintenance](https://llleixx.github.io/picloom/development/theme-tooling-maintenance.html)
37
+
38
+ ## Development tools / 开发工具
39
+
40
+ This package exports types only. `@picloom/theme-tools` provides the `picloom-theme`
41
+ CLI for simulated preview, Vite builds and ZIP packaging. `@picloom/create-theme`
42
+ generates a project using both packages. Framework plugins remain in the theme's
43
+ Vite configuration; no development tools are bundled into the theme.
44
+
45
+ SDK 仅维护主题与宿主之间的公共类型协议。模拟预览、构建和 ZIP 打包由
46
+ `@picloom/theme-tools` 统一维护,脚手架负责生成项目。消费项目使用 `@picloom/theme-sdk@0.1.1`,无需引用本地源码或压缩包。
package/index.ts ADDED
@@ -0,0 +1,207 @@
1
+ /** Browser-only public contract. No application/runtime imports. */
2
+ export type Json =
3
+ | null
4
+ | boolean
5
+ | number
6
+ | string
7
+ | Json[]
8
+ | { [key: string]: Json };
9
+ export type Config = Record<string, Json>;
10
+ export type Page = "home" | "login";
11
+ export type Locale = string;
12
+ export type SchemaFormat =
13
+ | "date"
14
+ | "time"
15
+ | "date-time"
16
+ | "duration"
17
+ | "email"
18
+ | "hostname"
19
+ | "ipv4"
20
+ | "ipv6"
21
+ | "uri"
22
+ | "uri-reference"
23
+ | "uuid"
24
+ | "regex";
25
+ /** Static properties/items define structure; branches only constrain existing fields. */
26
+ export interface Field {
27
+ $schema?: string;
28
+ type:
29
+ | "object"
30
+ | "array"
31
+ | "string"
32
+ | "number"
33
+ | "integer"
34
+ | "boolean"
35
+ | "null";
36
+ properties?: Record<string, Field>;
37
+ items?: Field;
38
+ required?: string[];
39
+ additionalProperties?: false;
40
+ enum?: Json[];
41
+ const?: Json;
42
+ /** Initial draft data only; localized strings use a language dictionary here. */
43
+ default?: Json;
44
+ minimum?: number;
45
+ maximum?: number;
46
+ exclusiveMinimum?: number;
47
+ exclusiveMaximum?: number;
48
+ multipleOf?: number;
49
+ minLength?: number;
50
+ maxLength?: number;
51
+ pattern?: string;
52
+ format?: SchemaFormat;
53
+ minItems?: number;
54
+ maxItems?: number;
55
+ uniqueItems?: boolean;
56
+ allOf?: Constraint[];
57
+ anyOf?: Constraint[];
58
+ oneOf?: Constraint[];
59
+ not?: Constraint;
60
+ if?: Constraint;
61
+ then?: Constraint;
62
+ else?: Constraint;
63
+ /** String fields only: store a language dictionary and validate each language's string. */
64
+ "x-localized"?: boolean;
65
+ "x-ui"?: {
66
+ labelKey?: string;
67
+ descriptionKey?: string;
68
+ enumKeys?: string[];
69
+ groupKey?: string;
70
+ order?: number;
71
+ advanced?: boolean;
72
+ widget?: "textarea" | "password";
73
+ visibleWhen?: { path: string; equals: Json };
74
+ };
75
+ }
76
+ export type Constraint = Omit<
77
+ Partial<Field>,
78
+ "properties" | "items" | "default" | "x-ui" | "x-localized"
79
+ > & {
80
+ properties?: Record<string, Constraint>;
81
+ items?: Constraint;
82
+ default?: never;
83
+ "x-ui"?: never;
84
+ "x-localized"?: never;
85
+ };
86
+ export interface Manifest {
87
+ id: string;
88
+ author?: string;
89
+ /** Package text fallback only; does not select the visitor or site language. */
90
+ defaultLocale: Locale;
91
+ nameKey: string;
92
+ version: string;
93
+ apiVersion: 1;
94
+ supportedLocales: Locale[];
95
+ pages: Partial<Record<Page, { entry: string; styles?: string[] }>>;
96
+ styles?: string[];
97
+ preview?: string;
98
+ /** Optional object schema; omission permits only an empty configuration. */
99
+ configSchema?: Field & { type: "object" };
100
+ messages: Record<Locale, Record<string, string>>;
101
+ }
102
+ export interface ThemeView {
103
+ manifest: Manifest;
104
+ config: Config;
105
+ baseUrl: string;
106
+ draftLanguage?: { defaultLocale: string; languageRevision: number };
107
+ languageRevision?: number;
108
+ siteDefaultLocale?: string;
109
+ enabledLocales?: string[];
110
+ }
111
+ export interface InstalledTheme extends ThemeView {
112
+ active: boolean;
113
+ compatible: boolean;
114
+ }
115
+ export interface Profile {
116
+ id: string;
117
+ name: string;
118
+ enabled: boolean;
119
+ available: boolean;
120
+ maxUploadBytes: number;
121
+ allowedMimeTypes: string[];
122
+ reason: string | null;
123
+ }
124
+ export interface Upload {
125
+ id: string;
126
+ name: string;
127
+ size: number;
128
+ profileName: string;
129
+ sourceUrl?: string;
130
+ status:
131
+ | "queued"
132
+ | "uploading"
133
+ | "processing"
134
+ | "success"
135
+ | "failed"
136
+ | "cancelled";
137
+ progress: number;
138
+ resumable?: boolean;
139
+ error?: string;
140
+ result?: { id: string; url: string };
141
+ }
142
+ export interface Snapshot {
143
+ page: Page;
144
+ site: {
145
+ name: string;
146
+ homeTitle: string;
147
+ description: string;
148
+ logoUrl: string;
149
+ faviconUrl: string;
150
+ };
151
+ user: { name: string } | null;
152
+ locale: Locale;
153
+ locales: readonly Locale[];
154
+ languages: readonly { tag: string; name: string; direction: string }[];
155
+ /** Effective site default (or the preview draft choice), not the package default. */
156
+ defaultLocale: string;
157
+ mode: "light" | "dark" | "auto";
158
+ dark: boolean;
159
+ profiles: readonly Profile[];
160
+ selectedProfileId: string;
161
+ uploads: readonly Upload[];
162
+ loading: boolean;
163
+ error: string;
164
+ login: {
165
+ busy: boolean;
166
+ error: string;
167
+ expired: boolean;
168
+ unavailable: boolean;
169
+ };
170
+ copy: { format: string; auto: boolean; formats: readonly string[] };
171
+ notice: string;
172
+ }
173
+ export interface ThemeContext {
174
+ apiVersion: 1;
175
+ config: Config;
176
+ getSnapshot(): Snapshot;
177
+ subscribe(listener: (snapshot: Snapshot) => void): () => void;
178
+ asset(path: string): string;
179
+ t(key: string, params?: Record<string, string | number>): string;
180
+ /** Read current-language administrator text; missing or empty text never falls back. */
181
+ localized(value: Json | undefined): string;
182
+ setLocale(locale: Locale): void;
183
+ setMode(mode: Snapshot["mode"]): void;
184
+ navigate(page: Page | "app"): void;
185
+ selectProfile(id: string): void;
186
+ refresh(): Promise<void>;
187
+ uploads: {
188
+ add(files: File[]): void;
189
+ addUrls(urls: string[]): void;
190
+ cancel(id: string): Promise<void>;
191
+ resume(id: string): void;
192
+ dismiss(id: string): Promise<void>;
193
+ };
194
+ links: {
195
+ format(url: string): string;
196
+ copy(url: string): Promise<void>;
197
+ copyAll(): Promise<void>;
198
+ setPreferences(format: string, auto: boolean): void;
199
+ };
200
+ login(username: string, password: string): Promise<void>;
201
+ }
202
+ export interface ThemeModule {
203
+ mount(
204
+ container: HTMLElement,
205
+ context: ThemeContext,
206
+ ): { dispose(): void } | Promise<{ dispose(): void }>;
207
+ }
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "@picloom/theme-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "types": "./index.ts",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./index.ts"
9
+ }
10
+ },
11
+ "files": [
12
+ "index.ts",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "license": "MIT",
17
+ "description": "Browser-only public contracts for Picloom themes",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/llleixx/picloom-tooling.git",
21
+ "directory": "theme-sdk"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ }
26
+ }