@openaction/svelte-pi 1.0.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,19 @@
1
+ MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # @openaction/svelte-pi
2
+
3
+ A Svelte library for ergonomically and concisely creating Property Inspectors for the [OpenAction API](https://openaction.amankhanna.me) (backwards-compatible with the Stream Deck SDK)
4
+
5
+ ```svelte
6
+ <script lang="ts">
7
+ import {
8
+ actionSettings,
9
+ globalSettings,
10
+ eventTarget,
11
+ sendToPlugin,
12
+ openUrl,
13
+ } from "@openaction/svelte-pi";
14
+
15
+ actionSettings.subscribe((value) =>
16
+ console.log("Action settings updated:", value),
17
+ );
18
+ globalSettings.subscribe((value) =>
19
+ console.log("Global settings updated:", value),
20
+ );
21
+
22
+ eventTarget.addEventListener("sendToPropertyInspector", (event: any) => {
23
+ console.log("sendToPropertyInspector event received:", event.detail);
24
+ });
25
+
26
+ sendToPlugin({ a: 1 });
27
+ openUrl("https://example.com");
28
+ </script>
29
+
30
+ <p>{JSON.stringify($actionSettings)}</p>
31
+ <p>{JSON.stringify($globalSettings)}</p>
32
+
33
+ <button onclick={() => $actionSettings.value = Math.random()}>Click me</button>
34
+ ```
35
+
36
+ For the OpenAction server to be able to pass connection details to your property inspector, you must include the following snippet in the `<head>` of your `app.html`:
37
+
38
+ ```html
39
+ <script>
40
+ window.connectOpenActionSocketData = new Promise((resolve) => {
41
+ window.connectOpenActionSocket = (...args) => resolve(args);
42
+ window.connectElgatoStreamDeckSocket = window.connectOpenActionSocket;
43
+ });
44
+ </script>
45
+ ```
46
+
47
+ See [OpenActionPlugins/discord](https://github.com/OpenActionPlugins/discord) for an example complete project setup using this library.
@@ -0,0 +1,6 @@
1
+ export declare const actionSettings: import("svelte/store").Writable<any>;
2
+ export declare const globalSettings: import("svelte/store").Writable<any>;
3
+ export declare const eventTarget: EventTarget;
4
+ export declare function sendToPlugin(payload: any): void;
5
+ export declare function openUrl(url: string): void;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,sCAAoB,CAAC;AAChD,eAAO,MAAM,cAAc,sCAAoB,CAAC;AAEhD,eAAO,MAAM,WAAW,aAAoB,CAAC;AAI7C,wBAAgB,YAAY,CAAC,OAAO,EAAE,GAAG,QAexC;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,QAalC"}
package/dist/index.js ADDED
@@ -0,0 +1,97 @@
1
+ import { writable, get } from "svelte/store";
2
+ export const actionSettings = writable({});
3
+ export const globalSettings = writable({});
4
+ export const eventTarget = new EventTarget();
5
+ let ws, action, context;
6
+ export function sendToPlugin(payload) {
7
+ if (ws?.readyState == WebSocket.OPEN) {
8
+ ws.send(JSON.stringify({
9
+ event: "sendToPlugin",
10
+ action,
11
+ context,
12
+ payload,
13
+ }));
14
+ }
15
+ else {
16
+ console.warn("Failed to send sendToPlugin event: not connected to OpenAction server");
17
+ }
18
+ }
19
+ export function openUrl(url) {
20
+ if (ws?.readyState == WebSocket.OPEN) {
21
+ ws.send(JSON.stringify({
22
+ event: "openUrl",
23
+ payload: { url },
24
+ }));
25
+ }
26
+ else {
27
+ console.warn("Failed to send openUrl event: not connected to OpenAction server");
28
+ }
29
+ }
30
+ // @ts-expect-error
31
+ if (globalThis.connectOpenActionSocketData) {
32
+ const [port, propertyInspectorUUID, registerEvent, _info, actionInfo] =
33
+ // @ts-expect-error
34
+ await globalThis.connectOpenActionSocketData;
35
+ ws = new WebSocket("ws://localhost:" + port);
36
+ const actionData = JSON.parse(actionInfo);
37
+ action = actionData.action;
38
+ context = actionData.context;
39
+ let actionSettingsSubscribed = false, globalSettingsSubscribed = false;
40
+ actionSettings.set(actionData.payload.settings ?? {});
41
+ actionSettings.subscribe((settings) => {
42
+ if (!actionSettingsSubscribed) {
43
+ actionSettingsSubscribed = true;
44
+ return;
45
+ }
46
+ ws.send(JSON.stringify({
47
+ event: "setSettings",
48
+ context,
49
+ payload: settings,
50
+ }));
51
+ });
52
+ ws.onopen = () => {
53
+ ws.send(JSON.stringify({
54
+ event: registerEvent,
55
+ uuid: propertyInspectorUUID,
56
+ }));
57
+ ws.send(JSON.stringify({
58
+ event: "getGlobalSettings",
59
+ context,
60
+ }));
61
+ };
62
+ ws.onmessage = (event) => {
63
+ const json = JSON.parse(event.data);
64
+ if (json.event == "didReceiveSettings") {
65
+ const settings = json.payload.settings;
66
+ if (settings != get(actionSettings))
67
+ actionSettings.set(settings);
68
+ }
69
+ else if (json.event == "didReceiveGlobalSettings") {
70
+ const settings = json.payload.settings;
71
+ if (settings != get(globalSettings))
72
+ globalSettings.set(settings);
73
+ globalSettings.subscribe((settings) => {
74
+ if (!globalSettingsSubscribed) {
75
+ globalSettingsSubscribed = true;
76
+ return;
77
+ }
78
+ ws.send(JSON.stringify({
79
+ event: "setGlobalSettings",
80
+ context,
81
+ payload: settings,
82
+ }));
83
+ });
84
+ }
85
+ eventTarget.dispatchEvent(new CustomEvent(json.event, { detail: json }));
86
+ };
87
+ ws.onerror = (event) => {
88
+ console.error("Encountered a WebSocket error:", event);
89
+ };
90
+ ws.onclose = () => {
91
+ console.error("WebSocket connection to OpenAction server closed");
92
+ };
93
+ }
94
+ else {
95
+ console.error("Failed to connect to OpenAction server: connection details not provided");
96
+ }
97
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAM,EAAE,CAAC,CAAC;AAChD,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAM,EAAE,CAAC,CAAC;AAEhD,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAE7C,IAAI,EAAa,EAAE,MAAc,EAAE,OAAe,CAAC;AAEnD,MAAM,UAAU,YAAY,CAAC,OAAY;IACxC,IAAI,EAAE,EAAE,UAAU,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;QACtC,EAAE,CAAC,IAAI,CACN,IAAI,CAAC,SAAS,CAAC;YACd,KAAK,EAAE,cAAc;YACrB,MAAM;YACN,OAAO;YACP,OAAO;SACP,CAAC,CACF,CAAC;IACH,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,IAAI,CACX,uEAAuE,CACvE,CAAC;IACH,CAAC;AACF,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,GAAW;IAClC,IAAI,EAAE,EAAE,UAAU,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;QACtC,EAAE,CAAC,IAAI,CACN,IAAI,CAAC,SAAS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ACtB,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC;IACF,EAAE,CAAC,OAAO,GAAG,GAAG,EAAE;QACjB,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACnE,CAAC,CAAC;AACH,CAAC;KAAM,CAAC;IACP,OAAO,CAAC,KAAK,CACZ,yEAAyE,CACzE,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@openaction/svelte-pi",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "author": "nekename",
6
+ "description": "A Svelte library for ergonomically and concisely creating Property Inspectors for the OpenAction API",
7
+ "repository": "https://github.com/OpenActionAPI/svelte-pi",
8
+ "private": false,
9
+ "type": "module",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "peerDependencies": {
20
+ "svelte": "^5"
21
+ },
22
+ "devDependencies": {
23
+ "svelte": "^5",
24
+ "typescript": "^5.9",
25
+ "prettier": "^3.7"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "format": "prettier --write ."
30
+ },
31
+ "prettier": {
32
+ "useTabs": true
33
+ }
34
+ }