@dice-plus/sdk 1.3.0 → 1.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/dist/index.js +17 -7
- package/dist/types/sdk/src/index.d.ts +12 -3
- package/dist/types/src/embed/protocol.d.ts +28 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -69,7 +69,7 @@ function formatRoomCode(roomId) {
|
|
|
69
69
|
}
|
|
70
70
|
//#endregion
|
|
71
71
|
//#region src/index.ts
|
|
72
|
-
var SDK_VERSION = "1.
|
|
72
|
+
var SDK_VERSION = "1.4.0";
|
|
73
73
|
var DEFAULT_BASE_URL = "https://dice-plus.missinglinkdev.com";
|
|
74
74
|
/** Room Code and Passcode helpers, so a page never has to guess our formats. */
|
|
75
75
|
var rooms = {
|
|
@@ -86,7 +86,7 @@ var rooms = {
|
|
|
86
86
|
};
|
|
87
87
|
/** One of our iframes: the handshake, calls and events every embed shares. */
|
|
88
88
|
var Embed = class {
|
|
89
|
-
constructor(options, path, title, style) {
|
|
89
|
+
constructor(options, path, title, style, attributes = {}) {
|
|
90
90
|
this.listeners = /* @__PURE__ */ new Map();
|
|
91
91
|
this.pending = /* @__PURE__ */ new Map();
|
|
92
92
|
this.queued = [];
|
|
@@ -114,6 +114,7 @@ var Embed = class {
|
|
|
114
114
|
const frame = document.createElement("iframe");
|
|
115
115
|
frame.src = new URL(path, base).href;
|
|
116
116
|
frame.title = title;
|
|
117
|
+
for (const [name, value] of Object.entries(attributes)) frame.setAttribute(name, value);
|
|
117
118
|
Object.assign(frame.style, {
|
|
118
119
|
position: "absolute",
|
|
119
120
|
inset: "0",
|
|
@@ -264,13 +265,14 @@ var DicePlusTray = class extends Embed {
|
|
|
264
265
|
background: "transparent",
|
|
265
266
|
colorScheme: "normal",
|
|
266
267
|
pointerEvents: "none"
|
|
268
|
+
}, {
|
|
269
|
+
allow: "autoplay",
|
|
270
|
+
"aria-hidden": "true",
|
|
271
|
+
tabindex: "-1"
|
|
267
272
|
});
|
|
268
273
|
this.settings = { ...options.settings ?? {} };
|
|
269
274
|
this.identity = options.identity;
|
|
270
275
|
this.dice = options.dice;
|
|
271
|
-
this.frame.setAttribute("allow", "autoplay");
|
|
272
|
-
this.frame.setAttribute("aria-hidden", "true");
|
|
273
|
-
this.frame.tabIndex = -1;
|
|
274
276
|
}
|
|
275
277
|
helloExtras() {
|
|
276
278
|
return {
|
|
@@ -286,6 +288,15 @@ var DicePlusTray = class extends Embed {
|
|
|
286
288
|
roll(request) {
|
|
287
289
|
return this.invoke("roll", request);
|
|
288
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Throw a finished roll again on this screen only, as a visual replay: no new
|
|
293
|
+
* numbers, nothing recorded, no 'roll-result'. Pass a result (or its `result`, or a
|
|
294
|
+
* history entry) whose `replay` is set. Resolves once the tray has taken it; if it
|
|
295
|
+
* can't play, 'roll-error' fires with a REPLAY_* `code`.
|
|
296
|
+
*/
|
|
297
|
+
replay(target) {
|
|
298
|
+
return this.invoke("replay", target);
|
|
299
|
+
}
|
|
289
300
|
/** Change some settings; the rest stay as they are. */
|
|
290
301
|
setSettings(settings) {
|
|
291
302
|
this.settings = {
|
|
@@ -354,8 +365,7 @@ var DicePlusTray = class extends Embed {
|
|
|
354
365
|
*/
|
|
355
366
|
var DicePlusBag = class extends Embed {
|
|
356
367
|
constructor(options) {
|
|
357
|
-
super(options, "/embed/bag.html", "Dice+ dice bag", {});
|
|
358
|
-
this.frame.setAttribute("allow", "clipboard-write");
|
|
368
|
+
super(options, "/embed/bag.html", "Dice+ dice bag", {}, { allow: "clipboard-write" });
|
|
359
369
|
}
|
|
360
370
|
/** Whether the player is signed in and a patron, once the bag has said. */
|
|
361
371
|
premium() {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type BagEvents, type EmbedTheme, type HelloMessage, type SiteDice, type TrayEvents, type TrayIdentity, type TrayMethods, type TraySettings, type UnauthorizedReason } from '../../src/embed/protocol';
|
|
1
|
+
import { type BagEvents, type EmbedTheme, type HelloMessage, type ReplayTarget, type SiteDice, type TrayEvents, type TrayIdentity, type TrayMethods, type TraySettings, type UnauthorizedReason } from '../../src/embed/protocol';
|
|
2
2
|
import { normalizeRoomId } from '../../src/platform/relay/protocol';
|
|
3
3
|
import { formatRoomCode } from '../../src/platform/relay/roomCode';
|
|
4
4
|
export type * from '../../src/embed/protocol';
|
|
5
|
-
export declare const SDK_VERSION = "1.
|
|
5
|
+
export declare const SDK_VERSION = "1.4.0";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://dice-plus.missinglinkdev.com";
|
|
7
7
|
/** Room Code and Passcode helpers, so a page never has to guess our formats. */
|
|
8
8
|
export declare const rooms: {
|
|
@@ -70,7 +70,7 @@ declare abstract class Embed<Events extends CommonEvents> {
|
|
|
70
70
|
private refused;
|
|
71
71
|
private theme;
|
|
72
72
|
private readonly onMessage;
|
|
73
|
-
protected constructor(options: EmbedOptions, path: string, title: string, style: Partial<CSSStyleDeclaration>);
|
|
73
|
+
protected constructor(options: EmbedOptions, path: string, title: string, style: Partial<CSSStyleDeclaration>, attributes?: Record<string, string>);
|
|
74
74
|
/** Listen for an event. Returns an unsubscribe. */
|
|
75
75
|
on<E extends keyof Events>(name: E, listener: Listener<Events[E]>): () => void;
|
|
76
76
|
once<E extends keyof Events>(name: E, listener: Listener<Events[E]>): () => void;
|
|
@@ -100,6 +100,15 @@ export declare class DicePlusTray extends Embed<DicePlusTrayEvents> {
|
|
|
100
100
|
roll(request: Parameters<TrayMethods['roll']>[0]): Promise<{
|
|
101
101
|
rollId: string;
|
|
102
102
|
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Throw a finished roll again on this screen only, as a visual replay: no new
|
|
105
|
+
* numbers, nothing recorded, no 'roll-result'. Pass a result (or its `result`, or a
|
|
106
|
+
* history entry) whose `replay` is set. Resolves once the tray has taken it; if it
|
|
107
|
+
* can't play, 'roll-error' fires with a REPLAY_* `code`.
|
|
108
|
+
*/
|
|
109
|
+
replay(target: ReplayTarget): Promise<{
|
|
110
|
+
rollId: string;
|
|
111
|
+
}>;
|
|
103
112
|
/** Change some settings; the rest stay as they are. */
|
|
104
113
|
setSettings(settings: TraySettings): Promise<void>;
|
|
105
114
|
setIdentity(identity: TrayIdentity): Promise<void>;
|
|
@@ -74,14 +74,38 @@ export interface DiceRollResult {
|
|
|
74
74
|
rollSummary: string;
|
|
75
75
|
groups: RolledGroup[];
|
|
76
76
|
tally?: Record<string, number>;
|
|
77
|
+
/** Throws this roll again on one screen, visual only (`replay`). Opaque; absent when it can't be replayed */
|
|
78
|
+
replay?: RollReplayData;
|
|
77
79
|
};
|
|
78
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* What a result carries to throw its roll again. Opaque: keep it with the
|
|
83
|
+
* result and hand it back, never read or build one. `v` is its format.
|
|
84
|
+
*/
|
|
85
|
+
export type RollReplayData = {
|
|
86
|
+
v: number;
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
};
|
|
89
|
+
/** Why a replay did not play, on `roll-error`'s `code`. */
|
|
90
|
+
export type ReplayErrorCode = 'REPLAY_BUSY' | 'REPLAY_UNAVAILABLE' | 'REPLAY_VERSION_MISMATCH';
|
|
91
|
+
/** Anything holding a roll's replay: a DiceRollResult, its `result`, or a history entry. */
|
|
92
|
+
export type ReplayTarget = {
|
|
93
|
+
replay?: RollReplayData;
|
|
94
|
+
} | {
|
|
95
|
+
result: {
|
|
96
|
+
replay?: RollReplayData;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
79
99
|
export interface DiceRollError {
|
|
80
100
|
rollId: string;
|
|
81
101
|
error: string;
|
|
82
102
|
notation: string;
|
|
83
103
|
/** The roll still went ahead; something in the request was ignored */
|
|
84
104
|
warning?: true;
|
|
105
|
+
/** Set when a replay did not play */
|
|
106
|
+
code?: ReplayErrorCode;
|
|
107
|
+
/** The replay request's requestId, echoed back (OBR broadcast only) */
|
|
108
|
+
requestId?: string;
|
|
85
109
|
}
|
|
86
110
|
export type SettleTime = 'very-fast' | 'fast' | 'normal' | 'slow' | 'very-slow';
|
|
87
111
|
export type DieType = 'd1' | 'd2' | 'd3' | 'd4' | 'd6' | 'd8' | 'd10' | 'd12' | 'd20' | 'd100' | 'dF';
|
|
@@ -166,6 +190,10 @@ export type TrayMethods = {
|
|
|
166
190
|
roll: (request: TrayRollRequest) => {
|
|
167
191
|
rollId: string;
|
|
168
192
|
};
|
|
193
|
+
/** Throw a finished roll again on this screen only: no new numbers, nothing recorded. Failures fire `roll-error` with a REPLAY_* code */
|
|
194
|
+
replay: (target: ReplayTarget) => {
|
|
195
|
+
rollId: string;
|
|
196
|
+
};
|
|
169
197
|
setSettings: (settings: TraySettings) => void;
|
|
170
198
|
setIdentity: (identity: TrayIdentity) => void;
|
|
171
199
|
setSiteDice: (dice: SiteDice | null) => void;
|