@ohmygame/plugin-ui 0.0.0-stage → 2.4.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # @ohmygame/plugin-ui
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
+ Styles, the host bridge and page components for
4
+ [OhMyGame](https://github.com/WhiteTowerAI/ohmygame) plugin pages.
5
+
6
+ The app serves these files to every plugin page, so a page loads them from the
7
+ app rather than from this package:
8
+
9
+ ```html
10
+ <link rel="stylesheet" href="/_ohmygame/plugin-ui.css" />
11
+ <script type="module" src="/_ohmygame/ui/1/index.js"></script>
12
+ <script type="module" src="./main.js"></script>
13
+ ```
14
+
15
+ ```js
16
+ import { connect } from "/_ohmygame/plugin-ui.js";
17
+
18
+ const host = await connect();
19
+ const project = await host.request("project.info");
20
+ ```
21
+
22
+ Pages allow no inline scripts and no other sites' scripts, so a page's own
23
+ script is a file beside it.
24
+
25
+ Install the package for its types and for editor support:
26
+
27
+ - `@ohmygame/plugin-ui` types the bridge, for example
28
+ `/** @type {import("@ohmygame/plugin-ui").PluginUiHost} */`.
29
+ - `@ohmygame/plugin-ui/ui/1` types the page components and their attributes.
30
+ - `ui/1/custom-elements.json` is a Custom Elements Manifest, which editors
31
+ read for completions.
32
+
33
+ The package's version is the plugin API it matches.
package/index.d.ts ADDED
@@ -0,0 +1,170 @@
1
+ export type PluginUiMethod =
2
+ | "theme.get"
3
+ | "project.info"
4
+ | "storage.get"
5
+ | "storage.set"
6
+ | "selection.get"
7
+ | "composer.fill"
8
+ | "command.run"
9
+ | "ui.toast"
10
+ | "ui.confirm"
11
+ | "files.list"
12
+ | "files.read"
13
+ | "files.write"
14
+ | "files.createFolder"
15
+ | "files.move"
16
+ | "files.delete"
17
+ | "history.list"
18
+ | "usage.get"
19
+ | "net.fetch";
20
+
21
+ /**
22
+ * An HTTPS request made by the app, for a project panel whose `panel.json`
23
+ * lists the host in `net`. No cookies go along, a redirect comes back as the
24
+ * answer rather than being followed, and it gives up after 30 seconds.
25
+ */
26
+ export interface PluginUiFetch {
27
+ url: string;
28
+ method?: "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE";
29
+ /** At most 30. */
30
+ headers?: Record<string, string>;
31
+ body?: string;
32
+ }
33
+
34
+ /** A `net.fetch` answer, its body as text of at most 5 MB. */
35
+ export interface PluginUiFetchResponse {
36
+ status: number;
37
+ statusText: string;
38
+ url: string;
39
+ /** Only content-type, content-length, etag, last-modified, location and retry-after. */
40
+ headers: Record<string, string>;
41
+ body: string;
42
+ }
43
+
44
+ /**
45
+ * Puts text, files or both in the composer, for a plugin with the `composer`
46
+ * capability. The person sends it; a page never can. Text goes after what is
47
+ * already there; files join the ones already attached, within the same
48
+ * limits as files the person attaches.
49
+ */
50
+ export interface PluginUiComposerFill {
51
+ /** At most 20,000 characters. */
52
+ text?: string;
53
+ /** At most 10 files. */
54
+ attachments?: Array<{ name: string; data: string | Blob; type?: string }>;
55
+ }
56
+
57
+ /** A turn that changed the project's files, from `history.list` with the `project.history` capability. */
58
+ export interface PluginHistoryTurn {
59
+ conversation: { id: string; title: string };
60
+ /** When the message was sent, as an ISO date. */
61
+ at?: string;
62
+ /** What the person asked, cut to 2,000 characters. */
63
+ message: string;
64
+ changes: Array<{ path: string; kind: "added" | "modified" | "removed"; lines?: { added: number; removed: number } }>;
65
+ /** The turn's changes were taken back with Undo. */
66
+ undone?: boolean;
67
+ }
68
+
69
+ /** One day's use of one model in the project, from `usage.get` with the `project.usage` capability. */
70
+ export interface PluginUsageRow {
71
+ /** Local calendar day, `YYYY-MM-DD`. */
72
+ date: string;
73
+ provider: string;
74
+ model: string;
75
+ input: number;
76
+ output: number;
77
+ cacheRead: number;
78
+ cacheWrite: number;
79
+ turns: number;
80
+ durationMs: number;
81
+ }
82
+
83
+ /** Shows a toast the app draws, under the plugin's id. A plugin shows at most 5 in 10 seconds. */
84
+ export interface PluginUiToast {
85
+ /** At most 500 characters. */
86
+ message: string;
87
+ tone?: "default" | "success" | "danger";
88
+ }
89
+
90
+ /**
91
+ * Asks the person in a dialog the app draws, which says which plugin asks;
92
+ * resolves to whether they agreed. A page that isn't showing can't ask, one
93
+ * question waits at a time, and a plugin asks at most 5 in a minute.
94
+ */
95
+ export interface PluginUiConfirm {
96
+ /** At most 200 characters. */
97
+ title: string;
98
+ /** At most 1,000 characters. */
99
+ message?: string;
100
+ /** The agreeing button; at most 40 characters. */
101
+ confirmLabel?: string;
102
+ }
103
+
104
+ /** A file or folder of the project. */
105
+ export interface PluginFileEntry {
106
+ /** Relative to the project, with forward slashes. */
107
+ path: string;
108
+ kind: "file" | "folder";
109
+ /** A file's size in bytes. */
110
+ size?: number;
111
+ /** When it last changed, as an ISO date. */
112
+ modified: string;
113
+ /** A media file's type, such as `image/png`. */
114
+ mediaType?: string;
115
+ }
116
+
117
+ /**
118
+ * The project's files, for a plugin whose manifest asks for `project.files`:
119
+ * `read` for the first four, `write` for all. Paths are relative to the project.
120
+ * Hidden files and folders are out of reach, and a page can't change the project
121
+ * file, an agent's instructions or Canvas documents. Each change to a file is
122
+ * one the person can undo, so a page changes only what the project's snapshots
123
+ * keep (not what a `.gitignore` leaves out); an empty folder isn't kept. A
124
+ * change is refused while an agent works in the project.
125
+ */
126
+ export interface PluginFiles {
127
+ /** A folder's entries, the project's root without a path; `recursive` skips generated folders such as `node_modules`. `truncated` means it stopped at 10,000. */
128
+ list(path?: string, options?: { recursive?: boolean }): Promise<{ entries: PluginFileEntry[]; truncated: boolean }>;
129
+ read(path: string): Promise<Blob>;
130
+ text(path: string): Promise<string>;
131
+ /** An address for `<img>`, `<audio>` or `<video>`; give it to `URL.revokeObjectURL` when done. */
132
+ url(path: string): Promise<string>;
133
+ /** Creates or replaces a file, and the folders it needs; at most 200 MB. Resolves to its path. */
134
+ write(path: string, contents: string | Blob | ArrayBuffer | ArrayBufferView): Promise<string>;
135
+ /** Creates a folder and the folders it needs; resolves to its path. */
136
+ createFolder(path: string): Promise<string>;
137
+ /** Moves or renames a file or folder, and refuses to replace anything. Resolves to its new path. */
138
+ move(from: string, to: string): Promise<string>;
139
+ /** Deletes a file, or a folder and everything in it. */
140
+ delete(path: string): Promise<null>;
141
+ }
142
+
143
+ export interface PluginUiHost {
144
+ plugin: { id: string; version: string; panel: string };
145
+ locale: "en" | "zh-CN";
146
+ files: PluginFiles;
147
+ request(method: "ui.toast", params: PluginUiToast): Promise<null>;
148
+ request(method: "ui.confirm", params: PluginUiConfirm): Promise<boolean>;
149
+ request(method: "composer.fill", params: PluginUiComposerFill): Promise<null>;
150
+ /** The project's latest turns that changed files, newest first; `limit` is 1 to 100, 20 when left out. */
151
+ request(method: "history.list", params?: { limit?: number }): Promise<{ turns: PluginHistoryTurn[] }>;
152
+ request(method: "usage.get"): Promise<{ rows: PluginUsageRow[] }>;
153
+ request(method: "net.fetch", params: PluginUiFetch): Promise<PluginUiFetchResponse>;
154
+ request<T = unknown>(method: PluginUiMethod, params?: Record<string, unknown>): Promise<T>;
155
+ /** The app's design tokens (`--color-surface`, `--text-md`…), already set on `:root`, and its appearance. */
156
+ on(event: "theme", listener: (theme: { tokens: Record<string, string>; appearance: "dark" | "light" }) => void): () => void;
157
+ on(event: "visibility", listener: (value: { visible: boolean }) => void): () => void;
158
+ /**
159
+ * Something changed the project's files, such as an agent, the page itself,
160
+ * or an edit outside OhMyGame. `paths` names them when the app knows, with
161
+ * `truncated` when there were more than it sends at once.
162
+ */
163
+ on(event: "files", listener: (value: { paths?: string[]; truncated?: boolean }) => void): () => void;
164
+ /** How one of the plugin's commands, by its manifest id, is going while it runs. */
165
+ on(event: "progress", listener: (value: { command: string; message: string }) => void): () => void;
166
+ /** A command the person ran from the panel's toolbar finished; it has `error` if it failed. */
167
+ on(event: "command", listener: (value: { command: string; result?: unknown; error?: string }) => void): () => void;
168
+ }
169
+
170
+ export function connect(): Promise<PluginUiHost>;
package/index.js ADDED
@@ -0,0 +1,127 @@
1
+ // The bridge a plugin page uses to talk to OhMyGame. The app serves this file
2
+ // next to every plugin page at /_ohmygame/plugin-ui.js:
3
+ //
4
+ // <link rel="stylesheet" href="/_ohmygame/plugin-ui.css">
5
+ // <script type="module" src="./main.js"></script>
6
+ //
7
+ // with the page's script in its own file, since the page's policy allows no
8
+ // inline scripts:
9
+ //
10
+ // import { connect } from "/_ohmygame/plugin-ui.js";
11
+ // const host = await connect();
12
+ // const project = await host.request("project.info");
13
+ //
14
+ // The page runs in a sandboxed frame with an opaque origin. The app sends it
15
+ // one end of a MessageChannel once it loads; everything goes through it.
16
+
17
+ const HANDSHAKE = "ohmygame-plugin-ui";
18
+
19
+ let connecting;
20
+
21
+ /** Waits for the app's port; resolves once, however often it is called. */
22
+ export function connect() {
23
+ connecting ??= new Promise((resolve) => {
24
+ const onMessage = (event) => {
25
+ if (event.source !== window.parent || event.data?.type !== HANDSHAKE || !event.ports?.[0]) return;
26
+ window.removeEventListener("message", onMessage);
27
+ resolve(bridge(event.ports[0], event.data));
28
+ };
29
+ window.addEventListener("message", onMessage);
30
+ });
31
+ return connecting;
32
+ }
33
+
34
+ function bridge(port, hello) {
35
+ let next = 0;
36
+ const pending = new Map();
37
+ const listeners = new Map();
38
+ const emit = (name, value) => listeners.get(name)?.forEach((listener) => listener(value));
39
+ port.onmessage = ({ data }) => {
40
+ if (data && typeof data.event === "string") {
41
+ // The app checks the page still answers; a page stuck in a loop can't, so it is offered a reload.
42
+ if (data.event === "ping") {
43
+ port.postMessage({ event: "pong" });
44
+ return;
45
+ }
46
+ if (data.event === "theme") applyTheme(data);
47
+ emit(data.event, data);
48
+ return;
49
+ }
50
+ const call = pending.get(data?.id);
51
+ if (!call) return;
52
+ pending.delete(data.id);
53
+ if ("error" in data) call.reject(new Error(data.error));
54
+ else call.resolve(data.result);
55
+ };
56
+ port.start();
57
+ // Errors the page doesn't catch go to its plugin's log in the app.
58
+ const report = (error) => {
59
+ try {
60
+ port.postMessage({ event: "error", message: String(error?.stack ?? error?.message ?? error).slice(0, 4000) });
61
+ } catch {
62
+ // A closed port has nowhere to send it.
63
+ }
64
+ };
65
+ window.addEventListener("error", (event) => report(event.error ?? event.message));
66
+ window.addEventListener("unhandledrejection", (event) => report(event.reason));
67
+ if (hello.theme) applyTheme(hello.theme);
68
+ // The app keeps the frame hidden until the page has its theme.
69
+ port.postMessage({ event: "ready" });
70
+ const api = {
71
+ /** Which plugin and project the page is for. */
72
+ plugin: hello.plugin,
73
+ locale: hello.locale,
74
+ /** Calls the app; rejects with the app's reason when it refuses. */
75
+ request(method, params) {
76
+ const id = next++;
77
+ return new Promise((resolve, reject) => {
78
+ pending.set(id, { resolve, reject });
79
+ port.postMessage(params === undefined ? { id, method } : { id, method, params });
80
+ });
81
+ },
82
+ /** `theme`, `visibility`, `progress`, `command` and `files` events; returns a function that stops listening. */
83
+ on(name, listener) {
84
+ if (!listeners.has(name)) listeners.set(name, new Set());
85
+ listeners.get(name).add(listener);
86
+ return () => listeners.get(name)?.delete(listener);
87
+ },
88
+ /** The project's files, for a plugin with the `project.files` capability. */
89
+ files: {
90
+ list(path, options = {}) {
91
+ return api.request("files.list", { ...(path ? { path } : {}), ...options });
92
+ },
93
+ /** A file's contents as a Blob. */
94
+ read(path) {
95
+ return api.request("files.read", { path });
96
+ },
97
+ async text(path) {
98
+ return (await api.request("files.read", { path })).text();
99
+ },
100
+ /** An address for `<img>`, `<audio>` or `<video>`; give it to `URL.revokeObjectURL` when done. */
101
+ async url(path) {
102
+ return URL.createObjectURL(await api.request("files.read", { path }));
103
+ },
104
+ write(path, contents) {
105
+ return api.request("files.write", { path, data: contents instanceof Blob ? contents : new Blob([contents]) });
106
+ },
107
+ createFolder(path) {
108
+ return api.request("files.createFolder", { path });
109
+ },
110
+ move(from, to) {
111
+ return api.request("files.move", { from, to });
112
+ },
113
+ delete(path) {
114
+ return api.request("files.delete", { path });
115
+ },
116
+ },
117
+ };
118
+ return api;
119
+ }
120
+
121
+ /** The app's colour tokens, so `plugin-ui.css` and the page match the app. */
122
+ function applyTheme({ tokens, appearance }) {
123
+ const root = document.documentElement;
124
+ for (const [name, value] of Object.entries(tokens ?? {}))
125
+ if (/^--[a-z0-9-]{1,40}$/.test(name)) root.style.setProperty(name, value);
126
+ if (appearance === "dark" || appearance === "light") root.dataset.appearance = appearance;
127
+ }
package/package.json CHANGED
@@ -1,6 +1,30 @@
1
1
  {
2
2
  "name": "@ohmygame/plugin-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.4.0",
4
+ "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/WhiteTowerAI/ohmygame.git",
8
+ "directory": "packages/plugin-ui"
9
+ },
10
+ "description": "Styles, the host bridge and page components for OhMyGame plugin pages.",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./index.d.ts",
15
+ "default": "./index.js"
16
+ },
17
+ "./plugin-ui.css": "./plugin-ui.css",
18
+ "./ui/1": {
19
+ "types": "./ui/1/index.d.ts"
20
+ },
21
+ "./ui/1/custom-elements.json": "./ui/1/custom-elements.json"
22
+ },
23
+ "files": [
24
+ "index.js",
25
+ "index.d.ts",
26
+ "plugin-ui.css",
27
+ "ui"
28
+ ],
29
+ "customElements": "ui/1/custom-elements.json"
30
+ }