@edhspace/api 0.0.0-stage → 0.2.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 +14 -0
- package/README.md +43 -2
- package/dist/chunk-4STXB3BK.js +160 -0
- package/dist/chunk-F72S63D3.cjs +160 -0
- package/dist/chunk-HL56LR6P.cjs +311 -0
- package/dist/chunk-LBLXK5J2.js +311 -0
- package/dist/client-CSAi6AFj.d.ts +136 -0
- package/dist/client-DKX6ZfiJ.d.cts +136 -0
- package/dist/contracts-r8d4RACz.d.cts +474 -0
- package/dist/contracts-r8d4RACz.d.ts +474 -0
- package/dist/host.cjs +356 -0
- package/dist/host.d.cts +57 -0
- package/dist/host.d.ts +57 -0
- package/dist/host.js +356 -0
- package/dist/index.cjs +85 -0
- package/dist/index.d.cts +148 -0
- package/dist/index.d.ts +148 -0
- package/dist/index.js +85 -0
- package/dist/math.cjs +107 -0
- package/dist/math.d.cts +70 -0
- package/dist/math.d.ts +70 -0
- package/dist/math.js +107 -0
- package/dist/react.cjs +69 -0
- package/dist/react.d.cts +177 -0
- package/dist/react.d.ts +177 -0
- package/dist/react.js +69 -0
- package/dist/sideload.cjs +213 -0
- package/dist/sideload.d.cts +290 -0
- package/dist/sideload.d.ts +290 -0
- package/dist/sideload.js +213 -0
- package/package.json +81 -5
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as zod from 'zod';
|
|
2
|
+
import { D as DeckOperation, o as NetworkRequest, a as ExtensionArguments } from './contracts-r8d4RACz.cjs';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import { E as ExtensionClient } from './client-DKX6ZfiJ.cjs';
|
|
6
|
+
|
|
7
|
+
declare function ExtensionProvider({ api, revision, children, }: {
|
|
8
|
+
api: ExtensionClient;
|
|
9
|
+
revision: string;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}): react.JSX.Element;
|
|
12
|
+
declare function useExtension(): {
|
|
13
|
+
permissions: readonly ("deck.read" | "selection.read" | "deck.propose" | "cards.inspect" | "cards.search" | "workspace.open" | "notifications.show" | "storage.read" | "storage.write" | "preferences.read" | "preferences.write" | "network.request")[];
|
|
14
|
+
deck: {
|
|
15
|
+
read: () => Promise<{
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
format: string;
|
|
19
|
+
revision: string;
|
|
20
|
+
cards: {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
quantity: number;
|
|
24
|
+
manaCost?: string | undefined;
|
|
25
|
+
manaValue?: number | undefined;
|
|
26
|
+
typeLine?: string | undefined;
|
|
27
|
+
commander?: boolean | undefined;
|
|
28
|
+
}[];
|
|
29
|
+
}>;
|
|
30
|
+
propose: (operations: DeckOperation[]) => Promise<{
|
|
31
|
+
id: string;
|
|
32
|
+
status: "pending" | "dismissed";
|
|
33
|
+
revision?: string | undefined;
|
|
34
|
+
undoId?: string | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
id: string;
|
|
37
|
+
status: "applied";
|
|
38
|
+
revision: string;
|
|
39
|
+
undoId: string;
|
|
40
|
+
}>;
|
|
41
|
+
addCard: (cardId: string, category: string, quantity?: number) => Promise<{
|
|
42
|
+
id: string;
|
|
43
|
+
status: "pending" | "dismissed";
|
|
44
|
+
revision?: string | undefined;
|
|
45
|
+
undoId?: string | undefined;
|
|
46
|
+
} | {
|
|
47
|
+
id: string;
|
|
48
|
+
status: "applied";
|
|
49
|
+
revision: string;
|
|
50
|
+
undoId: string;
|
|
51
|
+
}>;
|
|
52
|
+
removeCard: (cardId: string, quantity?: number) => Promise<{
|
|
53
|
+
id: string;
|
|
54
|
+
status: "pending" | "dismissed";
|
|
55
|
+
revision?: string | undefined;
|
|
56
|
+
undoId?: string | undefined;
|
|
57
|
+
} | {
|
|
58
|
+
id: string;
|
|
59
|
+
status: "applied";
|
|
60
|
+
revision: string;
|
|
61
|
+
undoId: string;
|
|
62
|
+
}>;
|
|
63
|
+
applyTags: (cardIds: string[], tags: string[]) => Promise<{
|
|
64
|
+
id: string;
|
|
65
|
+
status: "pending" | "dismissed";
|
|
66
|
+
revision?: string | undefined;
|
|
67
|
+
undoId?: string | undefined;
|
|
68
|
+
} | {
|
|
69
|
+
id: string;
|
|
70
|
+
status: "applied";
|
|
71
|
+
revision: string;
|
|
72
|
+
undoId: string;
|
|
73
|
+
}>;
|
|
74
|
+
};
|
|
75
|
+
selection: {
|
|
76
|
+
read: () => Promise<{
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
quantity: number;
|
|
80
|
+
manaCost?: string | undefined;
|
|
81
|
+
manaValue?: number | undefined;
|
|
82
|
+
typeLine?: string | undefined;
|
|
83
|
+
commander?: boolean | undefined;
|
|
84
|
+
}[]>;
|
|
85
|
+
};
|
|
86
|
+
network: {
|
|
87
|
+
request: (request: NetworkRequest) => Promise<{
|
|
88
|
+
status: number;
|
|
89
|
+
data: zod.JSONType;
|
|
90
|
+
}>;
|
|
91
|
+
};
|
|
92
|
+
cards: {
|
|
93
|
+
inspect: (cardId: string) => Promise<{
|
|
94
|
+
opened: true;
|
|
95
|
+
}>;
|
|
96
|
+
search: (query: string, page?: number) => Promise<{
|
|
97
|
+
cards: {
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
100
|
+
quantity: number;
|
|
101
|
+
manaCost?: string | undefined;
|
|
102
|
+
manaValue?: number | undefined;
|
|
103
|
+
typeLine?: string | undefined;
|
|
104
|
+
commander?: boolean | undefined;
|
|
105
|
+
}[];
|
|
106
|
+
nextPage?: number | undefined;
|
|
107
|
+
}>;
|
|
108
|
+
getByName: (name: string) => Promise<{
|
|
109
|
+
id: string;
|
|
110
|
+
name: string;
|
|
111
|
+
quantity: number;
|
|
112
|
+
manaCost?: string | undefined;
|
|
113
|
+
manaValue?: number | undefined;
|
|
114
|
+
typeLine?: string | undefined;
|
|
115
|
+
commander?: boolean | undefined;
|
|
116
|
+
} | null>;
|
|
117
|
+
};
|
|
118
|
+
workspace: {
|
|
119
|
+
openPanel: (panelId: string, location?: "workspace" | "sidebar") => Promise<{
|
|
120
|
+
panelId: string;
|
|
121
|
+
}>;
|
|
122
|
+
};
|
|
123
|
+
notifications: {
|
|
124
|
+
show: (message: string, kind?: "info" | "success" | "error") => Promise<{
|
|
125
|
+
shown: true;
|
|
126
|
+
}>;
|
|
127
|
+
};
|
|
128
|
+
storage: {
|
|
129
|
+
get: (key: string) => Promise<zod.JSONType>;
|
|
130
|
+
set: (key: string, value: ExtensionArguments["storage.set"]["value"]) => Promise<{
|
|
131
|
+
saved: true;
|
|
132
|
+
}>;
|
|
133
|
+
};
|
|
134
|
+
preferences: {
|
|
135
|
+
get: () => Promise<Record<string, zod.JSONType>>;
|
|
136
|
+
set: (key: string, value: ExtensionArguments["preferences.set"]["value"]) => Promise<{
|
|
137
|
+
saved: true;
|
|
138
|
+
}>;
|
|
139
|
+
};
|
|
140
|
+
dispose: () => void;
|
|
141
|
+
};
|
|
142
|
+
declare function useActiveDeck(): {
|
|
143
|
+
data: {
|
|
144
|
+
id: string;
|
|
145
|
+
name: string;
|
|
146
|
+
format: string;
|
|
147
|
+
revision: string;
|
|
148
|
+
cards: {
|
|
149
|
+
id: string;
|
|
150
|
+
name: string;
|
|
151
|
+
quantity: number;
|
|
152
|
+
manaCost?: string | undefined;
|
|
153
|
+
manaValue?: number | undefined;
|
|
154
|
+
typeLine?: string | undefined;
|
|
155
|
+
commander?: boolean | undefined;
|
|
156
|
+
}[];
|
|
157
|
+
} | undefined;
|
|
158
|
+
error: Error | undefined;
|
|
159
|
+
loading: boolean;
|
|
160
|
+
refresh: () => Promise<void>;
|
|
161
|
+
};
|
|
162
|
+
declare function useSelectedCards(): {
|
|
163
|
+
data: {
|
|
164
|
+
id: string;
|
|
165
|
+
name: string;
|
|
166
|
+
quantity: number;
|
|
167
|
+
manaCost?: string | undefined;
|
|
168
|
+
manaValue?: number | undefined;
|
|
169
|
+
typeLine?: string | undefined;
|
|
170
|
+
commander?: boolean | undefined;
|
|
171
|
+
}[] | undefined;
|
|
172
|
+
error: Error | undefined;
|
|
173
|
+
loading: boolean;
|
|
174
|
+
refresh: () => Promise<void>;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export { ExtensionProvider, useActiveDeck, useExtension, useSelectedCards };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as zod from 'zod';
|
|
2
|
+
import { D as DeckOperation, o as NetworkRequest, a as ExtensionArguments } from './contracts-r8d4RACz.js';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import { E as ExtensionClient } from './client-CSAi6AFj.js';
|
|
6
|
+
|
|
7
|
+
declare function ExtensionProvider({ api, revision, children, }: {
|
|
8
|
+
api: ExtensionClient;
|
|
9
|
+
revision: string;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}): react.JSX.Element;
|
|
12
|
+
declare function useExtension(): {
|
|
13
|
+
permissions: readonly ("deck.read" | "selection.read" | "deck.propose" | "cards.inspect" | "cards.search" | "workspace.open" | "notifications.show" | "storage.read" | "storage.write" | "preferences.read" | "preferences.write" | "network.request")[];
|
|
14
|
+
deck: {
|
|
15
|
+
read: () => Promise<{
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
format: string;
|
|
19
|
+
revision: string;
|
|
20
|
+
cards: {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
quantity: number;
|
|
24
|
+
manaCost?: string | undefined;
|
|
25
|
+
manaValue?: number | undefined;
|
|
26
|
+
typeLine?: string | undefined;
|
|
27
|
+
commander?: boolean | undefined;
|
|
28
|
+
}[];
|
|
29
|
+
}>;
|
|
30
|
+
propose: (operations: DeckOperation[]) => Promise<{
|
|
31
|
+
id: string;
|
|
32
|
+
status: "pending" | "dismissed";
|
|
33
|
+
revision?: string | undefined;
|
|
34
|
+
undoId?: string | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
id: string;
|
|
37
|
+
status: "applied";
|
|
38
|
+
revision: string;
|
|
39
|
+
undoId: string;
|
|
40
|
+
}>;
|
|
41
|
+
addCard: (cardId: string, category: string, quantity?: number) => Promise<{
|
|
42
|
+
id: string;
|
|
43
|
+
status: "pending" | "dismissed";
|
|
44
|
+
revision?: string | undefined;
|
|
45
|
+
undoId?: string | undefined;
|
|
46
|
+
} | {
|
|
47
|
+
id: string;
|
|
48
|
+
status: "applied";
|
|
49
|
+
revision: string;
|
|
50
|
+
undoId: string;
|
|
51
|
+
}>;
|
|
52
|
+
removeCard: (cardId: string, quantity?: number) => Promise<{
|
|
53
|
+
id: string;
|
|
54
|
+
status: "pending" | "dismissed";
|
|
55
|
+
revision?: string | undefined;
|
|
56
|
+
undoId?: string | undefined;
|
|
57
|
+
} | {
|
|
58
|
+
id: string;
|
|
59
|
+
status: "applied";
|
|
60
|
+
revision: string;
|
|
61
|
+
undoId: string;
|
|
62
|
+
}>;
|
|
63
|
+
applyTags: (cardIds: string[], tags: string[]) => Promise<{
|
|
64
|
+
id: string;
|
|
65
|
+
status: "pending" | "dismissed";
|
|
66
|
+
revision?: string | undefined;
|
|
67
|
+
undoId?: string | undefined;
|
|
68
|
+
} | {
|
|
69
|
+
id: string;
|
|
70
|
+
status: "applied";
|
|
71
|
+
revision: string;
|
|
72
|
+
undoId: string;
|
|
73
|
+
}>;
|
|
74
|
+
};
|
|
75
|
+
selection: {
|
|
76
|
+
read: () => Promise<{
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
quantity: number;
|
|
80
|
+
manaCost?: string | undefined;
|
|
81
|
+
manaValue?: number | undefined;
|
|
82
|
+
typeLine?: string | undefined;
|
|
83
|
+
commander?: boolean | undefined;
|
|
84
|
+
}[]>;
|
|
85
|
+
};
|
|
86
|
+
network: {
|
|
87
|
+
request: (request: NetworkRequest) => Promise<{
|
|
88
|
+
status: number;
|
|
89
|
+
data: zod.JSONType;
|
|
90
|
+
}>;
|
|
91
|
+
};
|
|
92
|
+
cards: {
|
|
93
|
+
inspect: (cardId: string) => Promise<{
|
|
94
|
+
opened: true;
|
|
95
|
+
}>;
|
|
96
|
+
search: (query: string, page?: number) => Promise<{
|
|
97
|
+
cards: {
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
100
|
+
quantity: number;
|
|
101
|
+
manaCost?: string | undefined;
|
|
102
|
+
manaValue?: number | undefined;
|
|
103
|
+
typeLine?: string | undefined;
|
|
104
|
+
commander?: boolean | undefined;
|
|
105
|
+
}[];
|
|
106
|
+
nextPage?: number | undefined;
|
|
107
|
+
}>;
|
|
108
|
+
getByName: (name: string) => Promise<{
|
|
109
|
+
id: string;
|
|
110
|
+
name: string;
|
|
111
|
+
quantity: number;
|
|
112
|
+
manaCost?: string | undefined;
|
|
113
|
+
manaValue?: number | undefined;
|
|
114
|
+
typeLine?: string | undefined;
|
|
115
|
+
commander?: boolean | undefined;
|
|
116
|
+
} | null>;
|
|
117
|
+
};
|
|
118
|
+
workspace: {
|
|
119
|
+
openPanel: (panelId: string, location?: "workspace" | "sidebar") => Promise<{
|
|
120
|
+
panelId: string;
|
|
121
|
+
}>;
|
|
122
|
+
};
|
|
123
|
+
notifications: {
|
|
124
|
+
show: (message: string, kind?: "info" | "success" | "error") => Promise<{
|
|
125
|
+
shown: true;
|
|
126
|
+
}>;
|
|
127
|
+
};
|
|
128
|
+
storage: {
|
|
129
|
+
get: (key: string) => Promise<zod.JSONType>;
|
|
130
|
+
set: (key: string, value: ExtensionArguments["storage.set"]["value"]) => Promise<{
|
|
131
|
+
saved: true;
|
|
132
|
+
}>;
|
|
133
|
+
};
|
|
134
|
+
preferences: {
|
|
135
|
+
get: () => Promise<Record<string, zod.JSONType>>;
|
|
136
|
+
set: (key: string, value: ExtensionArguments["preferences.set"]["value"]) => Promise<{
|
|
137
|
+
saved: true;
|
|
138
|
+
}>;
|
|
139
|
+
};
|
|
140
|
+
dispose: () => void;
|
|
141
|
+
};
|
|
142
|
+
declare function useActiveDeck(): {
|
|
143
|
+
data: {
|
|
144
|
+
id: string;
|
|
145
|
+
name: string;
|
|
146
|
+
format: string;
|
|
147
|
+
revision: string;
|
|
148
|
+
cards: {
|
|
149
|
+
id: string;
|
|
150
|
+
name: string;
|
|
151
|
+
quantity: number;
|
|
152
|
+
manaCost?: string | undefined;
|
|
153
|
+
manaValue?: number | undefined;
|
|
154
|
+
typeLine?: string | undefined;
|
|
155
|
+
commander?: boolean | undefined;
|
|
156
|
+
}[];
|
|
157
|
+
} | undefined;
|
|
158
|
+
error: Error | undefined;
|
|
159
|
+
loading: boolean;
|
|
160
|
+
refresh: () => Promise<void>;
|
|
161
|
+
};
|
|
162
|
+
declare function useSelectedCards(): {
|
|
163
|
+
data: {
|
|
164
|
+
id: string;
|
|
165
|
+
name: string;
|
|
166
|
+
quantity: number;
|
|
167
|
+
manaCost?: string | undefined;
|
|
168
|
+
manaValue?: number | undefined;
|
|
169
|
+
typeLine?: string | undefined;
|
|
170
|
+
commander?: boolean | undefined;
|
|
171
|
+
}[] | undefined;
|
|
172
|
+
error: Error | undefined;
|
|
173
|
+
loading: boolean;
|
|
174
|
+
refresh: () => Promise<void>;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export { ExtensionProvider, useActiveDeck, useExtension, useSelectedCards };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/react.tsx
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useCallback,
|
|
7
|
+
useRef,
|
|
8
|
+
useState
|
|
9
|
+
} from "react";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
var Context = createContext(void 0);
|
|
12
|
+
function ExtensionProvider({
|
|
13
|
+
api,
|
|
14
|
+
revision,
|
|
15
|
+
children
|
|
16
|
+
}) {
|
|
17
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value: { api, revision }, children });
|
|
18
|
+
}
|
|
19
|
+
function useContextValue() {
|
|
20
|
+
const context = useContext(Context);
|
|
21
|
+
if (!context) throw new Error("Render this extension inside an EDHspace ExtensionProvider.");
|
|
22
|
+
return context;
|
|
23
|
+
}
|
|
24
|
+
function useExtension() {
|
|
25
|
+
return useContextValue().api;
|
|
26
|
+
}
|
|
27
|
+
function useResource(load, revision) {
|
|
28
|
+
const generation = useRef(0);
|
|
29
|
+
const [data, setData] = useState();
|
|
30
|
+
const [error, setError] = useState();
|
|
31
|
+
const [loading, setLoading] = useState(true);
|
|
32
|
+
const refresh = useCallback(async () => {
|
|
33
|
+
const current = ++generation.current;
|
|
34
|
+
setLoading(true);
|
|
35
|
+
setError(void 0);
|
|
36
|
+
try {
|
|
37
|
+
const result = await load();
|
|
38
|
+
if (generation.current === current) setData(result);
|
|
39
|
+
} catch (error2) {
|
|
40
|
+
if (generation.current === current)
|
|
41
|
+
setError(
|
|
42
|
+
error2 instanceof Error ? error2 : new Error("Extension data could not be read.")
|
|
43
|
+
);
|
|
44
|
+
} finally {
|
|
45
|
+
if (generation.current === current) setLoading(false);
|
|
46
|
+
}
|
|
47
|
+
}, [load]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
void refresh();
|
|
50
|
+
return () => {
|
|
51
|
+
generation.current++;
|
|
52
|
+
};
|
|
53
|
+
}, [refresh, revision]);
|
|
54
|
+
return { data, error, loading, refresh };
|
|
55
|
+
}
|
|
56
|
+
function useActiveDeck() {
|
|
57
|
+
const { api, revision } = useContextValue();
|
|
58
|
+
return useResource(api.deck.read, revision);
|
|
59
|
+
}
|
|
60
|
+
function useSelectedCards() {
|
|
61
|
+
const { api, revision } = useContextValue();
|
|
62
|
+
return useResource(api.selection.read, revision);
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
ExtensionProvider,
|
|
66
|
+
useActiveDeck,
|
|
67
|
+
useExtension,
|
|
68
|
+
useSelectedCards
|
|
69
|
+
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkF72S63D3cjs = require('./chunk-F72S63D3.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkHL56LR6Pcjs = require('./chunk-HL56LR6P.cjs');
|
|
12
|
+
|
|
13
|
+
// src/sideload.ts
|
|
14
|
+
var _zod = require('zod');
|
|
15
|
+
var sideloadProtocol = "edhspace-sideload";
|
|
16
|
+
var sideloadVersion = 1;
|
|
17
|
+
var maxSideloadBytes = 8 * 1024 * 1024;
|
|
18
|
+
var bytes = (value) => new TextEncoder().encode(value).byteLength;
|
|
19
|
+
var panelId = _zod.z.string().regex(/^[a-z0-9][a-z0-9.-]{0,99}$/);
|
|
20
|
+
var sideloadPanelSchema = _zod.z.strictObject({
|
|
21
|
+
id: panelId,
|
|
22
|
+
javascript: _zod.z.string().min(1).max(2 * 1024 * 1024).refine(
|
|
23
|
+
(value) => bytes(value) <= 2 * 1024 * 1024,
|
|
24
|
+
"Sideload JavaScript exceeds 2 MiB."
|
|
25
|
+
),
|
|
26
|
+
css: _zod.z.string().max(262144).refine(
|
|
27
|
+
(value) => bytes(value) <= 262144,
|
|
28
|
+
"Sideload CSS exceeds 256 KiB."
|
|
29
|
+
)
|
|
30
|
+
});
|
|
31
|
+
var sideloadBundleSchema = _zod.z.strictObject({
|
|
32
|
+
protocol: _zod.z.literal(sideloadProtocol),
|
|
33
|
+
version: _zod.z.literal(sideloadVersion),
|
|
34
|
+
manifest: _chunkHL56LR6Pcjs.extensionManifestSchema,
|
|
35
|
+
panels: _zod.z.array(sideloadPanelSchema).min(1).max(16)
|
|
36
|
+
}).superRefine((bundle, context) => {
|
|
37
|
+
const ids = new Set(bundle.panels.map((panel) => panel.id));
|
|
38
|
+
if (ids.size !== bundle.panels.length || ids.size !== bundle.manifest.panels.length || bundle.manifest.panels.some((panel) => !ids.has(panel.id)))
|
|
39
|
+
context.addIssue({
|
|
40
|
+
code: "custom",
|
|
41
|
+
message: "The bundle must contain exactly one entry for each declared panel."
|
|
42
|
+
});
|
|
43
|
+
if (bytes(JSON.stringify(bundle)) > maxSideloadBytes)
|
|
44
|
+
context.addIssue({ code: "custom", message: "Sideload bundle exceeds 8 MiB." });
|
|
45
|
+
});
|
|
46
|
+
var envelope = {
|
|
47
|
+
protocol: _zod.z.literal(sideloadProtocol),
|
|
48
|
+
version: _zod.z.literal(sideloadVersion)
|
|
49
|
+
};
|
|
50
|
+
var sideloadReadySchema = _zod.z.strictObject({
|
|
51
|
+
...envelope,
|
|
52
|
+
type: _zod.z.literal("ready"),
|
|
53
|
+
panelId
|
|
54
|
+
});
|
|
55
|
+
var sideloadInitSchema = _zod.z.strictObject({
|
|
56
|
+
...envelope,
|
|
57
|
+
type: _zod.z.literal("init"),
|
|
58
|
+
sessionId: _zod.z.uuid(),
|
|
59
|
+
permissions: _zod.z.array(_chunkHL56LR6Pcjs.permissionSchema).max(12).refine(
|
|
60
|
+
(values) => new Set(values).size === values.length
|
|
61
|
+
),
|
|
62
|
+
revision: _zod.z.string().max(300),
|
|
63
|
+
theme: _zod.z.enum(["light", "dark"])
|
|
64
|
+
});
|
|
65
|
+
var sideloadStateSchema = _zod.z.strictObject({
|
|
66
|
+
...envelope,
|
|
67
|
+
type: _zod.z.literal("state"),
|
|
68
|
+
revision: _zod.z.string().max(300),
|
|
69
|
+
theme: _zod.z.enum(["light", "dark"])
|
|
70
|
+
});
|
|
71
|
+
var sideloadRevokeSchema = _zod.z.strictObject({
|
|
72
|
+
...envelope,
|
|
73
|
+
type: _zod.z.literal("revoke")
|
|
74
|
+
});
|
|
75
|
+
var sideloadErrorSchema = _zod.z.strictObject({
|
|
76
|
+
...envelope,
|
|
77
|
+
type: _zod.z.literal("error"),
|
|
78
|
+
message: _zod.z.string().min(1).max(300)
|
|
79
|
+
});
|
|
80
|
+
function createSideloadConnection(port, raw) {
|
|
81
|
+
const init = sideloadInitSchema.parse(raw);
|
|
82
|
+
let state = { revision: init.revision, theme: init.theme };
|
|
83
|
+
let closed = false;
|
|
84
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
85
|
+
const pending = /* @__PURE__ */ new Map();
|
|
86
|
+
const publish = (next) => {
|
|
87
|
+
state = next;
|
|
88
|
+
for (const listener of listeners) listener();
|
|
89
|
+
};
|
|
90
|
+
const close = (error) => {
|
|
91
|
+
if (closed) return;
|
|
92
|
+
closed = true;
|
|
93
|
+
for (const call of pending.values()) {
|
|
94
|
+
clearTimeout(call.timer);
|
|
95
|
+
call.reject(error);
|
|
96
|
+
}
|
|
97
|
+
pending.clear();
|
|
98
|
+
api.dispose();
|
|
99
|
+
port.removeEventListener("message", receive);
|
|
100
|
+
port.removeEventListener("messageerror", invalid);
|
|
101
|
+
port.close();
|
|
102
|
+
publish({ ...state, error });
|
|
103
|
+
listeners.clear();
|
|
104
|
+
};
|
|
105
|
+
const invalid = () => close(new (0, _chunkHL56LR6Pcjs.ExtensionError)("The host sent an invalid message.", "invalid"));
|
|
106
|
+
const receive = (event) => {
|
|
107
|
+
if (closed) return;
|
|
108
|
+
if (sideloadRevokeSchema.safeParse(event.data).success) {
|
|
109
|
+
close(new (0, _chunkHL56LR6Pcjs.ExtensionError)("Extension access has been revoked.", "revoked"));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const update = sideloadStateSchema.safeParse(event.data);
|
|
113
|
+
if (update.success) {
|
|
114
|
+
publish({ revision: update.data.revision, theme: update.data.theme });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
if (_chunkHL56LR6Pcjs.messageBytes.call(void 0, event.data) > _chunkHL56LR6Pcjs.maxResponseBytes) return invalid();
|
|
119
|
+
} catch (e) {
|
|
120
|
+
return invalid();
|
|
121
|
+
}
|
|
122
|
+
const response = _chunkHL56LR6Pcjs.responseSchema.safeParse(event.data);
|
|
123
|
+
if (!response.success || response.data.sessionId !== init.sessionId) return invalid();
|
|
124
|
+
const call = pending.get(response.data.id);
|
|
125
|
+
if (!call) return;
|
|
126
|
+
pending.delete(response.data.id);
|
|
127
|
+
clearTimeout(call.timer);
|
|
128
|
+
call.resolve(response.data);
|
|
129
|
+
};
|
|
130
|
+
const api = _chunkF72S63D3cjs.createExtensionClient.call(void 0, (request) => new Promise((resolve, reject) => {
|
|
131
|
+
if (closed) {
|
|
132
|
+
reject(new (0, _chunkHL56LR6Pcjs.ExtensionError)("Extension access has been revoked.", "revoked"));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const timer = setTimeout(() => {
|
|
136
|
+
pending.delete(request.id);
|
|
137
|
+
reject(new (0, _chunkHL56LR6Pcjs.ExtensionError)("The extension operation timed out.", "timeout"));
|
|
138
|
+
}, request.method === "network.request" ? 9e4 : 1e4);
|
|
139
|
+
pending.set(request.id, { resolve, reject, timer });
|
|
140
|
+
try {
|
|
141
|
+
port.postMessage(request);
|
|
142
|
+
} catch (e2) {
|
|
143
|
+
close(new (0, _chunkHL56LR6Pcjs.ExtensionError)("The extension transport failed.", "unavailable"));
|
|
144
|
+
}
|
|
145
|
+
}), init.sessionId, init.permissions);
|
|
146
|
+
port.addEventListener("message", receive);
|
|
147
|
+
port.addEventListener("messageerror", invalid);
|
|
148
|
+
port.start();
|
|
149
|
+
return {
|
|
150
|
+
api,
|
|
151
|
+
getSnapshot: () => state,
|
|
152
|
+
subscribe: (listener) => {
|
|
153
|
+
listeners.add(listener);
|
|
154
|
+
return () => {
|
|
155
|
+
listeners.delete(listener);
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
dispose: () => close(new (0, _chunkHL56LR6Pcjs.ExtensionError)("Extension access has been revoked.", "revoked"))
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function connectSideload(panel, timeoutMs = 1e4) {
|
|
162
|
+
panelId.parse(panel);
|
|
163
|
+
if (window.parent === window)
|
|
164
|
+
return Promise.reject(new (0, _chunkHL56LR6Pcjs.ExtensionError)("Open this bundle through EDHspace.", "unavailable"));
|
|
165
|
+
return new Promise((resolve, reject) => {
|
|
166
|
+
const timer = setTimeout(() => {
|
|
167
|
+
window.removeEventListener("message", initialize);
|
|
168
|
+
reject(new (0, _chunkHL56LR6Pcjs.ExtensionError)("EDHspace did not connect to the extension.", "timeout"));
|
|
169
|
+
}, timeoutMs);
|
|
170
|
+
function initialize(event) {
|
|
171
|
+
if (event.source !== window.parent) return;
|
|
172
|
+
const init = sideloadInitSchema.safeParse(event.data);
|
|
173
|
+
if (!init.success || event.ports.length !== 1) return;
|
|
174
|
+
clearTimeout(timer);
|
|
175
|
+
window.removeEventListener("message", initialize);
|
|
176
|
+
resolve(createSideloadConnection(event.ports[0], init.data));
|
|
177
|
+
}
|
|
178
|
+
window.addEventListener("message", initialize);
|
|
179
|
+
window.parent.postMessage({
|
|
180
|
+
protocol: sideloadProtocol,
|
|
181
|
+
version: sideloadVersion,
|
|
182
|
+
type: "ready",
|
|
183
|
+
panelId: panel
|
|
184
|
+
}, "*");
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
var base64 = (value) => {
|
|
188
|
+
const encoded = new TextEncoder().encode(value);
|
|
189
|
+
let binary = "";
|
|
190
|
+
for (let offset = 0; offset < encoded.length; offset += 8192)
|
|
191
|
+
binary += String.fromCharCode(...encoded.subarray(offset, offset + 8192));
|
|
192
|
+
return btoa(binary);
|
|
193
|
+
};
|
|
194
|
+
function createSideloadDocument(raw) {
|
|
195
|
+
const panel = sideloadPanelSchema.parse(raw);
|
|
196
|
+
const csp = "default-src 'none'; script-src data:; style-src 'unsafe-inline' data:; img-src data: blob:; font-src data:; connect-src 'none'; frame-src 'none'; worker-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'";
|
|
197
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${csp}"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="data:text/css;base64,${base64(panel.css)}"><style>body{margin:0;font:16px system-ui}html[data-theme=dark]{color-scheme:dark;--set-panel:#202620;--set-text:#f3f6f3;--set-muted:#bfcbbf;--set-accent:#8fca9b;--set-border:#81968b}</style></head><body><div id="root"></div><script src="data:text/javascript;base64,${base64(panel.javascript)}"></script></body></html>`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
exports.connectSideload = connectSideload; exports.createSideloadConnection = createSideloadConnection; exports.createSideloadDocument = createSideloadDocument; exports.maxSideloadBytes = maxSideloadBytes; exports.sideloadBundleSchema = sideloadBundleSchema; exports.sideloadErrorSchema = sideloadErrorSchema; exports.sideloadInitSchema = sideloadInitSchema; exports.sideloadPanelSchema = sideloadPanelSchema; exports.sideloadProtocol = sideloadProtocol; exports.sideloadReadySchema = sideloadReadySchema; exports.sideloadRevokeSchema = sideloadRevokeSchema; exports.sideloadStateSchema = sideloadStateSchema; exports.sideloadVersion = sideloadVersion;
|