@dice-plus/sdk 0.0.0-stage → 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MissingLinkDev
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,24 @@
1
- # Temporary Holding Version
1
+ # @dice-plus/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
+ Put the [Dice+](https://dice-plus.missinglinkdev.com) 3D physics dice tray and dice bag on your site. We run the physics, the rooms shared with Owlbear Rodeo players, the player's own dice and Patreon; you build the buttons and show the results your way.
4
+
5
+ ```bash
6
+ npm install @dice-plus/sdk
7
+ ```
8
+
9
+ ```js
10
+ import { DicePlusTray } from '@dice-plus/sdk';
11
+
12
+ const tray = new DicePlusTray({
13
+ apiKey: 'dp_your_key',
14
+ container: document.body,
15
+ identity: { name: 'Ari', color: '#e07a5f' },
16
+ });
17
+
18
+ tray.on('roll-result', ({ result }) => console.log(result.result.totalValue));
19
+ await tray.roll({ diceNotation: '2d20kh1+5' });
20
+ ```
21
+
22
+ You need an Access Key: request one at [dice-plus.missinglinkdev.com/devs](https://dice-plus.missinglinkdev.com/devs). Pages using Dice+ show "Dice powered by Dice+" with links to the site and [the Dice+ Patreon](https://patreon.com/MissingLinkDev).
23
+
24
+ Full reference: [dice-plus.missinglinkdev.com/devs/docs](https://dice-plus.missinglinkdev.com/devs/docs).
package/dist/index.js ADDED
@@ -0,0 +1,347 @@
1
+ //#region ../src/embed/protocol.ts
2
+ /** Every message carries this, so pages and frames ignore other postMessage traffic. */
3
+ var EMBED_TAG = "dice-plus-embed";
4
+ function isEmbedMessage(data) {
5
+ return !!data && typeof data === "object" && data.tag === "dice-plus-embed" && typeof data.type === "string";
6
+ }
7
+ //#endregion
8
+ //#region ../src/platform/relay/protocol.ts
9
+ var RELAY_LIMITS = {
10
+ maxSockets: 20,
11
+ /** One wire message: a 64KB broadcast payload plus its envelope. */
12
+ maxMessageBytes: 72 * 1024,
13
+ /** Token bucket per socket: sustained messages per second, and the burst a large chunked roll needs. */
14
+ messagesPerSecond: 5,
15
+ burst: 64,
16
+ keptMessages: 50,
17
+ /** A member's published metadata, as JSON. */
18
+ maxMetadataBytes: 8 * 1024,
19
+ webRoomIdleMs: 14400 * 1e3,
20
+ homeRoomIdleMs: 720 * 60 * 60 * 1e3,
21
+ /** How long a link request waits for its answer. */
22
+ linkAskMs: 60 * 1e3,
23
+ /** Before the same Guest may ask the same player again. */
24
+ linkCooldownMs: 10 * 1e3,
25
+ /** Denials from one player before that connection may not ask them again. */
26
+ linkDenials: 3,
27
+ /** Links a Room remembers. */
28
+ maxLinks: 64,
29
+ /** Wrong Passcodes from one address within a minute before it is turned away for a minute. */
30
+ passcodeTriesPerAddress: 5,
31
+ passcodeAddressWindowMs: 60 * 1e3,
32
+ passcodeAddressBlockMs: 60 * 1e3,
33
+ /** Wrong Passcodes for the room within 15 minutes before it refuses Passcode joins for 15 minutes. */
34
+ passcodeTriesPerRoom: 50,
35
+ passcodeRoomWindowMs: 900 * 1e3,
36
+ passcodeRoomLockMs: 900 * 1e3
37
+ };
38
+ /** A Room Code: 8 Crockford base32 characters, stored upper case without the dash. */
39
+ var ROOM_CODE = /^[0-9A-HJKMNP-TV-Z]{8}$/;
40
+ /** Room ids from before Room Codes: 16 random bytes in base64url. */
41
+ var LEGACY_ROOM_ID = /^[A-Za-z0-9_-]{16,64}$/;
42
+ new RegExp(`${ROOM_CODE.source}|${LEGACY_ROOM_ID.source}`);
43
+ /** A Passcode: six digits, leading zeros kept. */
44
+ var PASSCODE_PATTERN = /^\d{6}$/;
45
+ /**
46
+ * A room id from what a player typed: Room Codes ignore case, spaces and the
47
+ * dash, and read I and L as 1 and O as 0. Older long ids pass through exactly.
48
+ */
49
+ function normalizeRoomId(input) {
50
+ const text = input.trim();
51
+ if (LEGACY_ROOM_ID.test(text)) return text;
52
+ const code = text.replace(/[\s-]/g, "").toUpperCase().replace(/[IL]/g, "1").replace(/O/g, "0");
53
+ return ROOM_CODE.test(code) ? code : null;
54
+ }
55
+ //#endregion
56
+ //#region ../src/platform/relay/roomCode.ts
57
+ /** `K7M2-QX9P`; older long ids as they are. */
58
+ function formatRoomCode(roomId) {
59
+ return roomId.length === 8 ? `${roomId.slice(0, 4)}-${roomId.slice(4)}` : roomId;
60
+ }
61
+ //#endregion
62
+ //#region src/index.ts
63
+ var SDK_VERSION = "1.0.0";
64
+ var DEFAULT_BASE_URL = "https://dice-plus.missinglinkdev.com";
65
+ /** Room Code and Passcode helpers, so a page never has to guess our formats. */
66
+ var rooms = {
67
+ /** `K7M2-QX9P` from a stored id */
68
+ formatRoomCode,
69
+ /** The id from what a player typed (case, spaces and the dash ignored), or null if it is not a Room Code */
70
+ normalizeRoomCode: normalizeRoomId,
71
+ /** Six digits */
72
+ isPasscode: (value) => PASSCODE_PATTERN.test(value),
73
+ /** How long a player has to allow a link request */
74
+ linkAskMs: RELAY_LIMITS.linkAskMs,
75
+ /** Denials after which a player cannot be asked again on this connection */
76
+ linkDenials: RELAY_LIMITS.linkDenials
77
+ };
78
+ /** One of our iframes: the handshake, calls and events every embed shares. */
79
+ var Embed = class {
80
+ constructor(options, path, title, style) {
81
+ this.listeners = /* @__PURE__ */ new Map();
82
+ this.pending = /* @__PURE__ */ new Map();
83
+ this.queued = [];
84
+ this.lastEvents = /* @__PURE__ */ new Map();
85
+ this.nextId = 1;
86
+ this.isReady = false;
87
+ this.destroyed = false;
88
+ this.refused = null;
89
+ this.onMessage = (event) => this.receive(event);
90
+ if (!options?.container) throw new Error(`${title} needs a container element.`);
91
+ this.apiKey = options.apiKey;
92
+ const base = new URL(options.baseUrl ?? "https://dice-plus.missinglinkdev.com");
93
+ this.origin = base.origin;
94
+ let settle;
95
+ this.ready = new Promise((resolve, reject) => {
96
+ settle = {
97
+ resolve,
98
+ reject
99
+ };
100
+ });
101
+ this.ready.catch(() => {});
102
+ this.once("ready", (value) => settle.resolve(value));
103
+ this.once("unauthorized", (value) => settle.reject(new Error(value.message)));
104
+ const frame = document.createElement("iframe");
105
+ frame.src = new URL(path, base).href;
106
+ frame.title = title;
107
+ Object.assign(frame.style, {
108
+ position: "absolute",
109
+ inset: "0",
110
+ width: "100%",
111
+ height: "100%",
112
+ border: "0"
113
+ }, style);
114
+ frame.addEventListener("load", () => this.hello());
115
+ if (getComputedStyle(options.container).position === "static") options.container.style.position = "relative";
116
+ window.addEventListener("message", this.onMessage);
117
+ options.container.append(frame);
118
+ this.frame = frame;
119
+ }
120
+ /** Listen for an event. Returns an unsubscribe. */
121
+ on(name, listener) {
122
+ let set = this.listeners.get(name);
123
+ if (!set) {
124
+ set = /* @__PURE__ */ new Set();
125
+ this.listeners.set(name, set);
126
+ }
127
+ set.add(listener);
128
+ return () => {
129
+ set.delete(listener);
130
+ };
131
+ }
132
+ once(name, listener) {
133
+ const off = this.on(name, (data) => {
134
+ off();
135
+ listener(data);
136
+ });
137
+ return off;
138
+ }
139
+ /** Remove the embed and stop listening. */
140
+ destroy() {
141
+ if (this.destroyed) return;
142
+ this.destroyed = true;
143
+ window.removeEventListener("message", this.onMessage);
144
+ this.frame.remove();
145
+ for (const { reject } of this.pending.values()) reject(/* @__PURE__ */ new Error("The embed was destroyed."));
146
+ this.pending.clear();
147
+ this.listeners.clear();
148
+ }
149
+ /** The latest of an event, if it has come yet. */
150
+ last(name) {
151
+ return this.lastEvents.get(name);
152
+ }
153
+ /** What else this embed's hello carries. */
154
+ helloExtras() {
155
+ return {};
156
+ }
157
+ call(method, ...args) {
158
+ if (this.destroyed) return Promise.reject(/* @__PURE__ */ new Error("The embed was destroyed."));
159
+ if (this.refused) return Promise.reject(new Error(this.refused.message));
160
+ return new Promise((resolve, reject) => {
161
+ const send = () => {
162
+ const id = this.nextId++;
163
+ this.pending.set(id, {
164
+ resolve,
165
+ reject
166
+ });
167
+ this.post({
168
+ type: "call",
169
+ id,
170
+ method,
171
+ args
172
+ });
173
+ };
174
+ if (this.isReady) send();
175
+ else this.queued.push(send);
176
+ });
177
+ }
178
+ hello() {
179
+ if (this.destroyed) return;
180
+ this.isReady = false;
181
+ for (const { reject } of this.pending.values()) reject(/* @__PURE__ */ new Error("The embed reloaded."));
182
+ this.pending.clear();
183
+ this.post({
184
+ type: "hello",
185
+ protocol: 1,
186
+ sdkVersion: SDK_VERSION,
187
+ apiKey: this.apiKey,
188
+ ...this.helloExtras()
189
+ });
190
+ }
191
+ post(message) {
192
+ this.frame.contentWindow?.postMessage({
193
+ tag: EMBED_TAG,
194
+ ...message
195
+ }, this.origin);
196
+ }
197
+ receive(event) {
198
+ if (event.source !== this.frame.contentWindow || event.origin !== this.origin) return;
199
+ if (!isEmbedMessage(event.data)) return;
200
+ const message = event.data;
201
+ switch (message.type) {
202
+ case "ready": {
203
+ const { playerId } = message;
204
+ this.isReady = true;
205
+ this.emit("ready", { playerId });
206
+ this.queued.splice(0).forEach((send) => send());
207
+ break;
208
+ }
209
+ case "unauthorized": {
210
+ const { reason, message: text } = message;
211
+ this.refused = {
212
+ reason,
213
+ message: text
214
+ };
215
+ this.queued.splice(0);
216
+ this.emit("unauthorized", this.refused);
217
+ break;
218
+ }
219
+ case "reply": {
220
+ const reply = message;
221
+ const pending = this.pending.get(reply.id);
222
+ if (!pending) return;
223
+ this.pending.delete(reply.id);
224
+ if (reply.ok) pending.resolve(reply.value);
225
+ else pending.reject(new Error(reply.error ?? "The embed could not do that."));
226
+ break;
227
+ }
228
+ case "event": {
229
+ const { name, data } = message;
230
+ this.lastEvents.set(name, data);
231
+ this.emit(name, data);
232
+ break;
233
+ }
234
+ }
235
+ }
236
+ emit(name, data) {
237
+ for (const listener of [...this.listeners.get(name) ?? []]) try {
238
+ listener(data);
239
+ } catch (error) {
240
+ console.error(`[Dice+] ${String(name)} listener threw`, error);
241
+ }
242
+ }
243
+ };
244
+ /** The dice tray: rolls, the Room, and every result the player sees. Fills its container, see-through and click-through. */
245
+ var DicePlusTray = class extends Embed {
246
+ constructor(options) {
247
+ super(options, "/embed/tray.html", "Dice+ dice tray", {
248
+ background: "transparent",
249
+ colorScheme: "normal",
250
+ pointerEvents: "none"
251
+ });
252
+ this.settings = { ...options.settings ?? {} };
253
+ this.identity = options.identity;
254
+ this.dice = options.dice;
255
+ this.frame.setAttribute("allow", "autoplay");
256
+ this.frame.setAttribute("aria-hidden", "true");
257
+ this.frame.tabIndex = -1;
258
+ }
259
+ helloExtras() {
260
+ return {
261
+ settings: this.settings,
262
+ ...this.identity ? { identity: this.identity } : {},
263
+ ...this.dice ? { dice: this.dice } : {}
264
+ };
265
+ }
266
+ invoke(method, ...args) {
267
+ return this.call(method, ...args);
268
+ }
269
+ /** Roll dice. Resolves with the rollId once the tray has taken the roll; the result comes as a 'roll-result' event. */
270
+ roll(request) {
271
+ return this.invoke("roll", request);
272
+ }
273
+ /** Change some settings; the rest stay as they are. */
274
+ setSettings(settings) {
275
+ this.settings = {
276
+ ...this.settings,
277
+ ...settings
278
+ };
279
+ return this.invoke("setSettings", settings);
280
+ }
281
+ setIdentity(identity) {
282
+ this.identity = identity;
283
+ return this.invoke("setIdentity", identity);
284
+ }
285
+ /** Your site's look for dice the player's bag does not cover; null for ours. */
286
+ setSiteDice(dice) {
287
+ this.dice = dice ?? void 0;
288
+ return this.invoke("setSiteDice", dice);
289
+ }
290
+ getHistory() {
291
+ return this.invoke("getHistory");
292
+ }
293
+ /** A new Room with this browser as Host; in a Room already, a new Room Code and Passcode */
294
+ createRoom() {
295
+ return this.invoke("createRoom");
296
+ }
297
+ joinRoom(roomCode, passcode) {
298
+ return this.invoke("joinRoom", roomCode, passcode);
299
+ }
300
+ leaveRoom() {
301
+ return this.invoke("leaveRoom");
302
+ }
303
+ setPasscode(passcode) {
304
+ return this.invoke("setPasscode", passcode);
305
+ }
306
+ setGm(playerId, gm) {
307
+ return this.invoke("setGm", playerId, gm);
308
+ }
309
+ kick(playerId) {
310
+ return this.invoke("kick", playerId);
311
+ }
312
+ requestLink(playerId) {
313
+ return this.invoke("requestLink", playerId);
314
+ }
315
+ cancelLinkRequest() {
316
+ return this.invoke("cancelLinkRequest");
317
+ }
318
+ unlink(guestId) {
319
+ return this.invoke("unlink", guestId);
320
+ }
321
+ chooseNewPlayer() {
322
+ return this.invoke("chooseNewPlayer");
323
+ }
324
+ reconnect() {
325
+ return this.invoke("reconnect");
326
+ }
327
+ /** The latest of an event the tray repeats as state, if any yet. */
328
+ latest(name) {
329
+ return this.last(name);
330
+ }
331
+ };
332
+ /**
333
+ * The player's dice bag: their dice, collections, stats, cloud backup and
334
+ * Patreon sign-in. Fills its container; show it however suits your site.
335
+ */
336
+ var DicePlusBag = class extends Embed {
337
+ constructor(options) {
338
+ super(options, "/embed/bag.html", "Dice+ dice bag", {});
339
+ this.frame.setAttribute("allow", "clipboard-write");
340
+ }
341
+ /** Whether the player is signed in and a patron, once the bag has said. */
342
+ premium() {
343
+ return this.last("premium-changed");
344
+ }
345
+ };
346
+ //#endregion
347
+ export { DEFAULT_BASE_URL, DicePlusBag, DicePlusTray, SDK_VERSION, rooms };
@@ -0,0 +1,127 @@
1
+ import { type BagEvents, type HelloMessage, type SiteDice, type TrayEvents, type TrayIdentity, type TrayMethods, type TraySettings, type UnauthorizedReason } from '../../src/embed/protocol';
2
+ import { normalizeRoomId } from '../../src/platform/relay/protocol';
3
+ import { formatRoomCode } from '../../src/platform/relay/roomCode';
4
+ export type * from '../../src/embed/protocol';
5
+ export declare const SDK_VERSION = "1.0.0";
6
+ export declare const DEFAULT_BASE_URL = "https://dice-plus.missinglinkdev.com";
7
+ /** Room Code and Passcode helpers, so a page never has to guess our formats. */
8
+ export declare const rooms: {
9
+ /** `K7M2-QX9P` from a stored id */
10
+ readonly formatRoomCode: typeof formatRoomCode;
11
+ /** The id from what a player typed (case, spaces and the dash ignored), or null if it is not a Room Code */
12
+ readonly normalizeRoomCode: typeof normalizeRoomId;
13
+ /** Six digits */
14
+ readonly isPasscode: (value: string) => boolean;
15
+ /** How long a player has to allow a link request */
16
+ readonly linkAskMs: number;
17
+ /** Denials after which a player cannot be asked again on this connection */
18
+ readonly linkDenials: 3;
19
+ };
20
+ interface EmbedOptions {
21
+ /** Your Access Key from dice-plus.missinglinkdev.com/devs */
22
+ apiKey: string;
23
+ /** The embed fills this element; give it a size. */
24
+ container: HTMLElement;
25
+ /** Where our embeds are served from. Leave out except to test against a development build. */
26
+ baseUrl?: string;
27
+ }
28
+ export interface DicePlusTrayOptions extends EmbedOptions {
29
+ settings?: TraySettings;
30
+ /** The player's name and colour as others in the Room see them */
31
+ identity?: TrayIdentity;
32
+ /** Your site's look for dice the player's bag does not cover */
33
+ dice?: SiteDice;
34
+ }
35
+ export type DicePlusBagOptions = EmbedOptions;
36
+ export interface UnauthorizedEvent {
37
+ reason: UnauthorizedReason;
38
+ message: string;
39
+ }
40
+ /** Every embed tells you these. */
41
+ type CommonEvents = {
42
+ /** The embed is up (again, after it reloads) */
43
+ ready: {
44
+ playerId: string;
45
+ };
46
+ /** Your key or this page's origin was refused; the embed will not work */
47
+ unauthorized: UnauthorizedEvent;
48
+ };
49
+ export type DicePlusTrayEvents = TrayEvents & CommonEvents;
50
+ export type DicePlusBagEvents = BagEvents & CommonEvents;
51
+ type Listener<T> = (data: T) => void;
52
+ /** One of our iframes: the handshake, calls and events every embed shares. */
53
+ declare abstract class Embed<Events extends CommonEvents> {
54
+ /** Resolves once the embed first says it is ready; rejects if it refuses this page. */
55
+ readonly ready: Promise<{
56
+ playerId: string;
57
+ }>;
58
+ protected readonly frame: HTMLIFrameElement;
59
+ private readonly origin;
60
+ private readonly apiKey;
61
+ private readonly listeners;
62
+ private readonly pending;
63
+ private readonly queued;
64
+ private readonly lastEvents;
65
+ private nextId;
66
+ private isReady;
67
+ private destroyed;
68
+ private refused;
69
+ private readonly onMessage;
70
+ protected constructor(options: EmbedOptions, path: string, title: string, style: Partial<CSSStyleDeclaration>);
71
+ /** Listen for an event. Returns an unsubscribe. */
72
+ on<E extends keyof Events>(name: E, listener: Listener<Events[E]>): () => void;
73
+ once<E extends keyof Events>(name: E, listener: Listener<Events[E]>): () => void;
74
+ /** Remove the embed and stop listening. */
75
+ destroy(): void;
76
+ /** The latest of an event, if it has come yet. */
77
+ protected last<E extends keyof Events>(name: E): Events[E] | undefined;
78
+ /** What else this embed's hello carries. */
79
+ protected helloExtras(): Partial<HelloMessage>;
80
+ protected call(method: string, ...args: unknown[]): Promise<unknown>;
81
+ private hello;
82
+ private post;
83
+ private receive;
84
+ private emit;
85
+ }
86
+ /** The dice tray: rolls, the Room, and every result the player sees. Fills its container, see-through and click-through. */
87
+ export declare class DicePlusTray extends Embed<DicePlusTrayEvents> {
88
+ private settings;
89
+ private identity;
90
+ private dice;
91
+ constructor(options: DicePlusTrayOptions);
92
+ protected helloExtras(): Partial<HelloMessage>;
93
+ private invoke;
94
+ /** Roll dice. Resolves with the rollId once the tray has taken the roll; the result comes as a 'roll-result' event. */
95
+ roll(request: Parameters<TrayMethods['roll']>[0]): Promise<{
96
+ rollId: string;
97
+ }>;
98
+ /** Change some settings; the rest stay as they are. */
99
+ setSettings(settings: TraySettings): Promise<void>;
100
+ setIdentity(identity: TrayIdentity): Promise<void>;
101
+ /** Your site's look for dice the player's bag does not cover; null for ours. */
102
+ setSiteDice(dice: SiteDice | null): Promise<void>;
103
+ getHistory(): Promise<import(".").HistoryEntry[]>;
104
+ /** A new Room with this browser as Host; in a Room already, a new Room Code and Passcode */
105
+ createRoom(): Promise<void>;
106
+ joinRoom(roomCode: string, passcode: string | null): Promise<void>;
107
+ leaveRoom(): Promise<void>;
108
+ setPasscode(passcode: string | null): Promise<void>;
109
+ setGm(playerId: string, gm: boolean): Promise<void>;
110
+ kick(playerId: string): Promise<void>;
111
+ requestLink(playerId: string): Promise<void>;
112
+ cancelLinkRequest(): Promise<void>;
113
+ unlink(guestId: string): Promise<void>;
114
+ chooseNewPlayer(): Promise<void>;
115
+ reconnect(): Promise<void>;
116
+ /** The latest of an event the tray repeats as state, if any yet. */
117
+ latest<E extends 'room-state' | 'dice-availability' | 'history-changed'>(name: E): TrayEvents[E] | undefined;
118
+ }
119
+ /**
120
+ * The player's dice bag: their dice, collections, stats, cloud backup and
121
+ * Patreon sign-in. Fills its container; show it however suits your site.
122
+ */
123
+ export declare class DicePlusBag extends Embed<DicePlusBagEvents> {
124
+ constructor(options: DicePlusBagOptions);
125
+ /** Whether the player is signed in and a patron, once the bag has said. */
126
+ premium(): BagEvents['premium-changed'] | undefined;
127
+ }
@@ -0,0 +1,312 @@
1
+ import type { SiteDice } from '../features/site-dice/siteDiceTypes';
2
+ export type { SiteDice };
3
+ export type { StandardDiceStyle } from '../features/site-dice/siteDiceTypes';
4
+ export declare const EMBED_PROTOCOL = 1;
5
+ /** Every message carries this, so pages and frames ignore other postMessage traffic. */
6
+ export declare const EMBED_TAG = "dice-plus-embed";
7
+ export type RollTarget = 'everyone' | 'self' | 'dm' | 'gm_only';
8
+ /** One die in a result. */
9
+ export interface RolledDie {
10
+ diceId: string;
11
+ rollId: string;
12
+ diceType: string;
13
+ diceStyle?: string;
14
+ /** What it counts as: after custom face values, min/max, Fudge mapping and sign */
15
+ value: number;
16
+ /** The faces it physically landed on (every face of a compounding chain) */
17
+ faces?: number[];
18
+ /** The bag die's name */
19
+ customName?: string;
20
+ isAdvantage: boolean;
21
+ isDisadvantage: boolean;
22
+ /** Counted in the total (not dropped by kh/kl/dh/dl) */
23
+ kept: boolean;
24
+ groupDropped?: boolean;
25
+ isNegative?: boolean;
26
+ wasExploded?: boolean;
27
+ fromExplosion?: boolean;
28
+ wasRerolled?: boolean;
29
+ imploded?: boolean;
30
+ wasMinimum?: boolean;
31
+ wasMaximum?: boolean;
32
+ /** Pools: met the target */
33
+ success?: boolean;
34
+ failure?: boolean;
35
+ criticalSuccess?: boolean;
36
+ criticalFailure?: boolean;
37
+ /** A Text Face's text; `value` then counts toward nothing */
38
+ label?: string;
39
+ isFudge?: boolean;
40
+ /** Table rolls (T notation): each part's face, highest place value first */
41
+ tablePartValues?: number[];
42
+ }
43
+ /** The dice of one term of the notation, e.g. `3d6{Red} # Fire`. */
44
+ export interface RolledGroup {
45
+ /** The label after `#` */
46
+ description?: string;
47
+ /** The bag die asked for in `{}` */
48
+ diceModel?: string;
49
+ diceType: string;
50
+ dice: RolledDie[];
51
+ /** Total of kept dice, or successes for a pool */
52
+ total: number;
53
+ /** Text Faces among the kept dice, e.g. { "Skull": 2 } */
54
+ tally?: Record<string, number>;
55
+ isNegative?: boolean;
56
+ isPool?: boolean;
57
+ /** Very large groups (70+ dice) carry totals only */
58
+ isCondensed?: boolean;
59
+ condensedCount?: number;
60
+ }
61
+ /** A finished roll, as OBR's {source}/roll-result carries it. */
62
+ export interface DiceRollResult {
63
+ rollId: string;
64
+ playerId: string;
65
+ playerName: string;
66
+ rollTarget: RollTarget;
67
+ timestamp: number;
68
+ source: string;
69
+ showResults: boolean;
70
+ result: {
71
+ rollId: string;
72
+ diceNotation: string;
73
+ totalValue: number;
74
+ rollSummary: string;
75
+ groups: RolledGroup[];
76
+ tally?: Record<string, number>;
77
+ };
78
+ }
79
+ export interface DiceRollError {
80
+ rollId: string;
81
+ error: string;
82
+ notation: string;
83
+ /** The roll still went ahead; something in the request was ignored */
84
+ warning?: true;
85
+ }
86
+ export type SettleTime = 'very-fast' | 'fast' | 'normal' | 'slow' | 'very-slow';
87
+ export type DieType = 'd1' | 'd2' | 'd3' | 'd4' | 'd6' | 'd8' | 'd10' | 'd12' | 'd20' | 'd100' | 'dF';
88
+ export type CritDice = 'all' | Array<'d2' | 'd3' | 'd4' | 'd6' | 'd8' | 'd10' | 'd12' | 'd20' | 'd100'>;
89
+ /** Everything about the tray a site controls. Anything left out uses our default. */
90
+ export interface TraySettings {
91
+ /** How long dice tumble before settling */
92
+ settleTime?: SettleTime;
93
+ /** Seconds the dice stay after a roll, 1–10 */
94
+ clearDelaySeconds?: number;
95
+ sound?: boolean;
96
+ /** Flash a die when it settles */
97
+ settleFlash?: boolean;
98
+ /** Tint dice that rolled their min or max */
99
+ resultAccent?: boolean;
100
+ /** Mark the min and max of these dice critical without cs/cf */
101
+ critHighlight?: {
102
+ enabled: boolean;
103
+ dice?: CritDice;
104
+ };
105
+ /** Play effects for critical results */
106
+ critEffects?: {
107
+ enabled: boolean;
108
+ dice?: CritDice;
109
+ theme?: string;
110
+ };
111
+ /** 'results-only' skips drawing other players' dice */
112
+ performance?: 'normal' | 'default-dice-only' | 'results-only';
113
+ graphicsQuality?: 'auto' | 'high' | 'balanced' | 'low';
114
+ /**
115
+ * A Headless Tray: rolls in real time on a hidden canvas, draws nothing and
116
+ * makes no sound, for sites that show dice only on the VTT. Results arrive
117
+ * about 1.5 s after the dice settle, as they land on other screens. Not
118
+ * switchable while this player's roll is out.
119
+ */
120
+ headless?: boolean;
121
+ }
122
+ export interface TrayIdentity {
123
+ name: string;
124
+ /** `#rrggbb` */
125
+ color: string;
126
+ }
127
+ /** A roll, in the shape of OBR's dice-plus/roll-request. The tray fills in the player. */
128
+ export interface TrayRollRequest {
129
+ diceNotation: string;
130
+ rollTarget?: RollTarget;
131
+ /** Your id for the roll; one is made if left out */
132
+ rollId?: string;
133
+ /** Echoed on the result, e.g. which button rolled it */
134
+ source?: string;
135
+ /** Look for dice the player's bag does not cover */
136
+ dice?: SiteDice;
137
+ }
138
+ export interface HelloMessage {
139
+ tag: typeof EMBED_TAG;
140
+ type: 'hello';
141
+ protocol: number;
142
+ sdkVersion: string;
143
+ apiKey: string;
144
+ settings?: TraySettings;
145
+ identity?: TrayIdentity;
146
+ dice?: SiteDice;
147
+ }
148
+ export type TrayMethods = {
149
+ roll: (request: TrayRollRequest) => {
150
+ rollId: string;
151
+ };
152
+ setSettings: (settings: TraySettings) => void;
153
+ setIdentity: (identity: TrayIdentity) => void;
154
+ setSiteDice: (dice: SiteDice | null) => void;
155
+ getHistory: () => HistoryEntry[];
156
+ /** A new room with this browser as Host. In a room already, a new Room Code and Passcode: everyone else must rejoin */
157
+ createRoom: () => void;
158
+ joinRoom: (roomCode: string, passcode: string | null) => void;
159
+ leaveRoom: () => void;
160
+ /** Host or GM: a new six-digit Passcode, or null to turn it off */
161
+ setPasscode: (passcode: string | null) => void;
162
+ setGm: (playerId: string, gm: boolean) => void;
163
+ kick: (playerId: string) => void;
164
+ /** A Guest in an OBR room: ask that player to let this browser roll as them */
165
+ requestLink: (playerId: string) => void;
166
+ cancelLinkRequest: () => void;
167
+ /** End a link: this browser's own, or (the player or a GM) another's */
168
+ unlink: (guestId: string) => void;
169
+ /** Join an OBR room as a new player, not as one of its players */
170
+ chooseNewPlayer: () => void;
171
+ /** Try the room again now after the connection gave up */
172
+ reconnect: () => void;
173
+ };
174
+ export type TrayMethod = keyof TrayMethods;
175
+ export interface CallMessage<M extends TrayMethod = TrayMethod> {
176
+ tag: typeof EMBED_TAG;
177
+ type: 'call';
178
+ id: number;
179
+ method: M;
180
+ args: Parameters<TrayMethods[M]>;
181
+ }
182
+ export interface ReplyMessage {
183
+ tag: typeof EMBED_TAG;
184
+ type: 'reply';
185
+ id: number;
186
+ ok: boolean;
187
+ value?: unknown;
188
+ error?: string;
189
+ }
190
+ export interface ReadyMessage {
191
+ tag: typeof EMBED_TAG;
192
+ type: 'ready';
193
+ protocol: number;
194
+ playerId: string;
195
+ }
196
+ export type UnauthorizedReason = 'missing' | 'unknown' | 'revoked' | 'origin' | 'protocol';
197
+ export interface UnauthorizedMessage {
198
+ tag: typeof EMBED_TAG;
199
+ type: 'unauthorized';
200
+ reason: UnauthorizedReason;
201
+ message: string;
202
+ }
203
+ /** A roll this client saw finish, held until its dice settled here. */
204
+ export interface RollResultEvent {
205
+ result: DiceRollResult;
206
+ /** Rolled by this player (or this browser as a Linked Guest) */
207
+ isOwn: boolean;
208
+ }
209
+ /** How many dice of each type the player's bag holds in each state. */
210
+ export type DiceAvailability = Partial<Record<DieType, {
211
+ active: number;
212
+ jailed: number;
213
+ }>>;
214
+ export interface HistoryEntry {
215
+ id: string;
216
+ playerId: string;
217
+ playerName: string;
218
+ rollTarget: RollTarget;
219
+ timestamp: number;
220
+ result: DiceRollResult['result'];
221
+ }
222
+ export interface RoomMemberState {
223
+ id: string;
224
+ name: string;
225
+ color: string;
226
+ platform: string;
227
+ /** Created the room (website rooms) */
228
+ host: boolean;
229
+ gm: boolean;
230
+ /** A Linked Guest: the player it rolls as */
231
+ linkedTo?: string;
232
+ }
233
+ export interface RoomState {
234
+ /** Not in a room */
235
+ solo: boolean;
236
+ /** 'offline': gave up reconnecting for now; `reconnect` tries again */
237
+ status: 'connecting' | 'connected' | 'reconnecting' | 'offline' | 'closed';
238
+ /** The Room Code as players type it, `XXXX-XXXX` */
239
+ roomCode?: string;
240
+ /** Host or GM: the room's Passcode (null when off). A guest: the one they joined with. */
241
+ passcode?: string | null;
242
+ /** This browser created the room */
243
+ isHost: boolean;
244
+ /** 'web' rooms are made on a website; 'home' rooms belong to a VTT such as OBR */
245
+ kind?: 'web' | 'home';
246
+ you?: RoomMemberState;
247
+ members: RoomMemberState[];
248
+ /** Why the room closed, e.g. 'kicked', 'wrongPasscode', 'tooManyAttempts', 'full', 'outdated' */
249
+ closeReason?: string;
250
+ /** The Passcode was refused after this browser had been let in: the Host changed it */
251
+ passcodeChanged?: boolean;
252
+ /** A Guest in a home room: VTT players this browser may ask to roll as */
253
+ linkCandidates: RoomMemberState[];
254
+ /** This browser rolls as another player */
255
+ linkedAs?: {
256
+ playerId: string;
257
+ name: string;
258
+ color: string;
259
+ };
260
+ /** Joined a home room as a new player rather than as one of its players */
261
+ asNewPlayer: boolean;
262
+ }
263
+ export interface NoticeEvent {
264
+ message: string;
265
+ variant: 'DEFAULT' | 'INFO' | 'ERROR' | 'SUCCESS' | 'WARNING';
266
+ }
267
+ /** A link request did not go through. 'denied', 'timeout', 'offline' and 'blocked' are about `player`. */
268
+ export interface LinkRefusedEvent {
269
+ player: string;
270
+ reason: 'denied' | 'timeout' | 'offline' | 'busy' | 'cooldown' | 'blocked' | 'unavailable';
271
+ }
272
+ export type TrayEvents = {
273
+ 'roll-result': RollResultEvent;
274
+ 'roll-error': DiceRollError;
275
+ 'dice-availability': DiceAvailability;
276
+ 'history-changed': HistoryEntry[];
277
+ 'room-state': RoomState;
278
+ 'link-refused': LinkRefusedEvent;
279
+ notice: NoticeEvent;
280
+ /** This player's own roll went out (true) or finished (false), e.g. for a "Rolling…" state */
281
+ rolling: {
282
+ rolling: boolean;
283
+ };
284
+ };
285
+ export type TrayEventName = keyof TrayEvents;
286
+ export interface EventMessage<E extends TrayEventName = TrayEventName> {
287
+ tag: typeof EMBED_TAG;
288
+ type: 'event';
289
+ name: E;
290
+ data: TrayEvents[E];
291
+ }
292
+ /** Where the player stands with Patreon, as far as the page may know. */
293
+ export interface PremiumState {
294
+ /** Signed in with Patreon in this site's Dice+ */
295
+ signedIn: boolean;
296
+ /** A paying patron: premium materials, shapes, fonts and unlimited dice */
297
+ isPremium: boolean;
298
+ }
299
+ /** The Bag Embed has nothing to call in v1; the player drives it. */
300
+ export type BagMethods = Record<never, never>;
301
+ export type BagEvents = {
302
+ 'premium-changed': PremiumState;
303
+ /** The player pressed the bag's close button; hide it if you show it as a dialog */
304
+ 'close-requested': Record<string, never>;
305
+ };
306
+ export type BagEventName = keyof BagEvents;
307
+ export type PageToTray = HelloMessage | CallMessage;
308
+ export type TrayToPage = ReadyMessage | UnauthorizedMessage | ReplyMessage | EventMessage;
309
+ export declare function isEmbedMessage(data: unknown): data is {
310
+ tag: typeof EMBED_TAG;
311
+ type: string;
312
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
3
+ * Generated by scripts/generateDiceConfig.ts
4
+ *
5
+ * This file is automatically generated from metadata.json files in
6
+ * src/features/dice/models/
7
+ *
8
+ * To add a new dice shape:
9
+ * 1. Create the model directory with mesh.tsx, collider.tsx, and metadata.json
10
+ * 2. Run: npm run generate:dice-config
11
+ * 3. This file will be automatically updated
12
+ */
13
+ export type PhysicalDiceType = "d1" | "d10" | "d12" | "d2" | "d20" | "d3" | "d4" | "d6" | "d8";
14
+ export type DiceType = PhysicalDiceType | "d100" | "dF";
15
+ export type DiceStyle = "clipped" | "d6" | "gem" | "hex" | "rhombic" | "rounded" | "sharp" | "standard";
16
+ export interface DiceVariant {
17
+ id: DiceType;
18
+ name: string;
19
+ sides: number;
20
+ meshComponent: string;
21
+ colliderComponent: string;
22
+ availableStyles: readonly DiceStyle[];
23
+ defaultStyle: DiceStyle;
24
+ }
25
+ export interface SpawnConfiguration {
26
+ position: [number, number, number];
27
+ rotation: [number, number, number];
28
+ velocity: [number, number, number];
29
+ angularVelocity: [number, number, number];
30
+ }
31
+ export declare const DICE_VARIANTS: Partial<Record<DiceType, DiceVariant>>;
32
+ export declare const STYLE_COMPONENT_MAP: Partial<Record<DiceType, Partial<Record<DiceStyle, {
33
+ mesh: string;
34
+ collider: string;
35
+ }>>>>;
36
+ /** The die that is physically thrown: a d100 is two d10s, a Fudge die is a d6 marked −1, 0, +1. */
37
+ export declare function physicalDiceType(diceType: string): string;
38
+ export declare function getDiceVariant(diceType: DiceType): DiceVariant | undefined;
39
+ export declare function getDiceVariantSafe(diceType: DiceType): DiceVariant;
40
+ export declare function getComponentsForStyle(diceType: DiceType, style: DiceStyle): {
41
+ mesh: string;
42
+ collider: string;
43
+ };
@@ -0,0 +1,27 @@
1
+ import type { DiceStyle, DiceType } from '../dice/types/DiceTypes';
2
+ /** One die's look, from the free fields of the standard material. Anything left out keeps our default. */
3
+ export interface StandardDiceStyle {
4
+ /** Body colour, `#rrggbb` */
5
+ color?: string;
6
+ /** Number colour, `#rrggbb` */
7
+ numberColor?: string;
8
+ /** Free fonts only: 'standard', 'norse' or 'aelfa' */
9
+ font?: string;
10
+ /** A free shape for the die type, e.g. 'sharp' or 'rounded' */
11
+ shape?: DiceStyle;
12
+ /** 0–1 */
13
+ roughness?: number;
14
+ /** 0–1 */
15
+ metalness?: number;
16
+ /** 0–1 */
17
+ opacity?: number;
18
+ /** 0–1, glossy clear coat */
19
+ sheen?: number;
20
+ /** 0–1, how deep the numbers are engraved */
21
+ numberDepth?: number;
22
+ }
23
+ /** The look for a roll, or for the whole site: a default, and per die type. */
24
+ export interface SiteDice {
25
+ default?: StandardDiceStyle;
26
+ byType?: Partial<Record<DiceType, StandardDiceStyle>>;
27
+ }
@@ -0,0 +1,205 @@
1
+ export declare const RELAY_PROTOCOL = 1;
2
+ export type RelayPlatform = 'web' | 'obr' | 'embed' | 'foundry';
3
+ /**
4
+ * 'web' rooms are temporary sessions created on the website; 'home' rooms
5
+ * belong to a dedicated client's own room (an OBR room, a Foundry world).
6
+ */
7
+ export type RoomKind = 'web' | 'home';
8
+ export interface RelayPlayer {
9
+ id: string;
10
+ name: string;
11
+ color: string;
12
+ }
13
+ export interface RelayMember extends RelayPlayer {
14
+ platform: RelayPlatform;
15
+ /** What the player publishes about themselves (custom models, fonts), like OBR player metadata. */
16
+ metadata: Record<string, unknown>;
17
+ /** Holds the room key of a website room: assigns GM Tags. */
18
+ host: boolean;
19
+ /** Receives GM-only and GM & Self rolls. */
20
+ gm: boolean;
21
+ /**
22
+ * A Linked Guest: the Home Group player it rolls as. Its messages come from
23
+ * that id, and its name, colour and GM Tag are that player's.
24
+ */
25
+ linkedTo?: string;
26
+ }
27
+ /** Why the Relay did not pass on, or the player did not allow, a link request. */
28
+ export type LinkRefusal = 'denied'
29
+ /** The player did not answer in time. */
30
+ | 'timeout'
31
+ /** Not in the Room's Home Group now. */
32
+ | 'offline'
33
+ /** A request is already waiting, or this guest is already linked. */
34
+ | 'busy'
35
+ /** Asked the same player again too soon. */
36
+ | 'cooldown'
37
+ /** That player denied this connection too often. */
38
+ | 'blocked'
39
+ /** Not a home Room. */
40
+ | 'unavailable';
41
+ /** Who a message is for. Absent: everyone. Otherwise GM-tagged members and/or these player ids. */
42
+ export interface Audience {
43
+ gm?: boolean;
44
+ to?: string[];
45
+ }
46
+ export type ClientMessage = {
47
+ t: 'join';
48
+ v: number;
49
+ player: RelayPlayer;
50
+ platform: RelayPlatform;
51
+ metadata?: Record<string, unknown>;
52
+ /** The room key. The first join with a key creates the room's claim to it. */
53
+ key?: string;
54
+ /** With a valid key in a home room: this player is a GM on their own platform. */
55
+ claimGm?: boolean;
56
+ /** Only read when the key first claims the room. */
57
+ kind?: RoomKind;
58
+ /**
59
+ * Guests: the room's Passcode. The Host or a platform GM (with the key):
60
+ * the Passcode to set, null to turn it off; absent leaves it as it is.
61
+ */
62
+ passcode?: string | null;
63
+ /** A Linked Guest's token from an earlier `linked`: joins already linked. */
64
+ link?: string;
65
+ } | {
66
+ t: 'send';
67
+ ch: string;
68
+ data: unknown;
69
+ aud?: Audience;
70
+ keep?: boolean;
71
+ } | {
72
+ t: 'profile';
73
+ name: string;
74
+ color: string;
75
+ metadata?: Record<string, unknown>;
76
+ } | {
77
+ t: 'setGm';
78
+ player: string;
79
+ gm: boolean;
80
+ } | {
81
+ t: 'kick';
82
+ player: string;
83
+ }
84
+ /** The Host or a platform GM: a new Passcode, or null for none. Players already in stay. */
85
+ | {
86
+ t: 'setPasscode';
87
+ passcode: string | null;
88
+ }
89
+ /** A Guest in a home Room: ask this Home Group player to let it roll as them. */
90
+ | {
91
+ t: 'linkRequest';
92
+ player: string;
93
+ }
94
+ /** The Guest gave up waiting. */
95
+ | {
96
+ t: 'linkCancel';
97
+ }
98
+ /** The asked player's answer. */
99
+ | {
100
+ t: 'linkAnswer';
101
+ guest: string;
102
+ allow: boolean;
103
+ timedOut?: boolean;
104
+ }
105
+ /** End a link: the Linked Guest itself, the player it rolls as, or a GM. */
106
+ | {
107
+ t: 'unlink';
108
+ guest: string;
109
+ };
110
+ export interface RelayEnvelope {
111
+ from: string;
112
+ ch: string;
113
+ data: unknown;
114
+ }
115
+ export type ServerMessage = {
116
+ t: 'welcome';
117
+ you: RelayMember;
118
+ members: RelayMember[];
119
+ history: RelayEnvelope[];
120
+ kind: RoomKind;
121
+ } | {
122
+ t: 'members';
123
+ members: RelayMember[];
124
+ } | ({
125
+ t: 'msg';
126
+ } & RelayEnvelope)
127
+ /** To the asked player's sockets: a Guest wants to roll as them. */
128
+ | {
129
+ t: 'linkAsk';
130
+ guest: RelayPlayer;
131
+ }
132
+ /** To the asked player's sockets: the request is over (answered, cancelled, or the Guest left). */
133
+ | {
134
+ t: 'linkClosed';
135
+ guest: string;
136
+ }
137
+ /** To the Guest: it now rolls as `player`. Keep the token to rejoin linked. */
138
+ | {
139
+ t: 'linked';
140
+ player: string;
141
+ token: string;
142
+ } | {
143
+ t: 'linkRefused';
144
+ player: string;
145
+ reason: LinkRefusal;
146
+ }
147
+ /** To a Linked Guest: the link was ended. */
148
+ | {
149
+ t: 'unlinked';
150
+ };
151
+ /** WebSocket close codes the Relay uses; clients stop reconnecting on all but `replaced`. */
152
+ export declare const RELAY_CLOSE: {
153
+ readonly kicked: 4001;
154
+ readonly full: 4002;
155
+ readonly rateLimited: 4003;
156
+ readonly tooLarge: 4004;
157
+ readonly badRequest: 4005;
158
+ /** The same player connected again elsewhere (another tab took over). */
159
+ readonly replaced: 4006;
160
+ readonly outdated: 4007;
161
+ /** No Passcode, or the wrong one. */
162
+ readonly wrongPasscode: 4008;
163
+ /** Too many wrong Passcodes from this address, or for this room; try again later. */
164
+ readonly tooManyAttempts: 4009;
165
+ };
166
+ export declare const RELAY_LIMITS: {
167
+ readonly maxSockets: 20;
168
+ /** One wire message: a 64KB broadcast payload plus its envelope. */
169
+ readonly maxMessageBytes: number;
170
+ /** Token bucket per socket: sustained messages per second, and the burst a large chunked roll needs. */
171
+ readonly messagesPerSecond: 5;
172
+ readonly burst: 64;
173
+ readonly keptMessages: 50;
174
+ /** A member's published metadata, as JSON. */
175
+ readonly maxMetadataBytes: number;
176
+ readonly webRoomIdleMs: number;
177
+ readonly homeRoomIdleMs: number;
178
+ /** How long a link request waits for its answer. */
179
+ readonly linkAskMs: number;
180
+ /** Before the same Guest may ask the same player again. */
181
+ readonly linkCooldownMs: number;
182
+ /** Denials from one player before that connection may not ask them again. */
183
+ readonly linkDenials: 3;
184
+ /** Links a Room remembers. */
185
+ readonly maxLinks: 64;
186
+ /** Wrong Passcodes from one address within a minute before it is turned away for a minute. */
187
+ readonly passcodeTriesPerAddress: 5;
188
+ readonly passcodeAddressWindowMs: number;
189
+ readonly passcodeAddressBlockMs: number;
190
+ /** Wrong Passcodes for the room within 15 minutes before it refuses Passcode joins for 15 minutes. */
191
+ readonly passcodeTriesPerRoom: 50;
192
+ readonly passcodeRoomWindowMs: number;
193
+ readonly passcodeRoomLockMs: number;
194
+ };
195
+ export declare const ROOM_ID_PATTERN: RegExp;
196
+ /** A Passcode: six digits, leading zeros kept. */
197
+ export declare const PASSCODE_PATTERN: RegExp;
198
+ /**
199
+ * A room id from what a player typed: Room Codes ignore case, spaces and the
200
+ * dash, and read I and L as 1 and O as 0. Older long ids pass through exactly.
201
+ */
202
+ export declare function normalizeRoomId(input: string): string | null;
203
+ /** The keepalive text the Relay answers without waking (setWebSocketAutoResponse). */
204
+ export declare const RELAY_PING = "ping";
205
+ export declare const RELAY_PONG = "pong";
@@ -0,0 +1,12 @@
1
+ /** Random URL-safe text: 32 bytes for a Room key. */
2
+ export declare function randomToken(bytes: number): string;
3
+ /** 8 Crockford base32 characters: short enough to read out, 40 bits so codes never collide. */
4
+ export declare function newRoomCode(): string;
5
+ export declare function newPasscode(): string;
6
+ export declare function newRoomCredentials(): {
7
+ id: string;
8
+ key: string;
9
+ passcode: string;
10
+ };
11
+ /** `K7M2-QX9P`; older long ids as they are. */
12
+ export declare function formatRoomCode(roomId: string): string;
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@dice-plus/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Embed the Dice+ 3D physics dice tray and dice bag on your site",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "MissingLinkDev",
8
+ "homepage": "https://dice-plus.missinglinkdev.com/devs",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/MissingLinkDev/dice-plus.git",
12
+ "directory": "sdk"
13
+ },
14
+ "keywords": ["dice", "dice-roller", "3d", "physics", "ttrpg", "owlbear-rodeo", "vtt"],
15
+ "main": "./dist/index.js",
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/types/sdk/src/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/types/sdk/src/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": ["dist", "README.md", "LICENSE"],
25
+ "sideEffects": false,
26
+ "scripts": {
27
+ "build": "vite build && tsc -p tsconfig.build.json",
28
+ "typecheck": "tsc --noEmit",
29
+ "prepublishOnly": "npm run build"
30
+ }
31
+ }