@edhspace/api 0.0.0-stage → 0.1.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.
@@ -0,0 +1,148 @@
1
+ export { E as ExtensionClient, c as createExtensionClient } from './client-DKX6ZfiJ.cjs';
2
+ import { z } from 'zod';
3
+ export { D as DeckOperation, a as ExtensionArguments, j as ExtensionCard, k as ExtensionDeck, i as ExtensionError, l as ExtensionErrorCode, n as ExtensionInvoker, E as ExtensionManifest, c as ExtensionMethod, d as ExtensionPermission, m as ExtensionRequest, e as ExtensionResponse, b as ExtensionResults, g as ExtensionTheme, N as NetworkEndpoint, o as NetworkRequest, P as ProposalReceipt, h as apiVersion, f as extensionManifestSchema } from './contracts-r8d4RACz.cjs';
4
+
5
+ declare const extensionPackageSchema: z.ZodObject<{
6
+ name: z.ZodString;
7
+ version: z.ZodString;
8
+ type: z.ZodLiteral<"module">;
9
+ title: z.ZodString;
10
+ description: z.ZodString;
11
+ author: z.ZodString;
12
+ icon: z.ZodString;
13
+ apiVersion: z.ZodLiteral<1>;
14
+ permissions: z.ZodArray<z.ZodEnum<{
15
+ "deck.read": "deck.read";
16
+ "selection.read": "selection.read";
17
+ "deck.propose": "deck.propose";
18
+ "cards.inspect": "cards.inspect";
19
+ "cards.search": "cards.search";
20
+ "workspace.open": "workspace.open";
21
+ "notifications.show": "notifications.show";
22
+ "storage.read": "storage.read";
23
+ "storage.write": "storage.write";
24
+ "preferences.read": "preferences.read";
25
+ "preferences.write": "preferences.write";
26
+ "network.request": "network.request";
27
+ }>>;
28
+ panels: z.ZodArray<z.ZodObject<{
29
+ id: z.ZodString;
30
+ title: z.ZodString;
31
+ entry: z.ZodString;
32
+ location: z.ZodDefault<z.ZodEnum<{
33
+ workspace: "workspace";
34
+ sidebar: "sidebar";
35
+ }>>;
36
+ }, z.core.$strict>>;
37
+ commands: z.ZodDefault<z.ZodArray<z.ZodObject<{
38
+ id: z.ZodString;
39
+ title: z.ZodString;
40
+ entry: z.ZodString;
41
+ }, z.core.$strict>>>;
42
+ preferences: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
43
+ id: z.ZodString;
44
+ title: z.ZodString;
45
+ description: z.ZodOptional<z.ZodString>;
46
+ type: z.ZodLiteral<"text">;
47
+ default: z.ZodString;
48
+ }, z.core.$strict>, z.ZodObject<{
49
+ id: z.ZodString;
50
+ title: z.ZodString;
51
+ description: z.ZodOptional<z.ZodString>;
52
+ type: z.ZodLiteral<"boolean">;
53
+ default: z.ZodBoolean;
54
+ }, z.core.$strict>, z.ZodObject<{
55
+ id: z.ZodString;
56
+ title: z.ZodString;
57
+ description: z.ZodOptional<z.ZodString>;
58
+ type: z.ZodLiteral<"number">;
59
+ default: z.ZodNumber;
60
+ }, z.core.$strict>, z.ZodObject<{
61
+ id: z.ZodString;
62
+ title: z.ZodString;
63
+ description: z.ZodOptional<z.ZodString>;
64
+ type: z.ZodLiteral<"select">;
65
+ default: z.ZodString;
66
+ options: z.ZodArray<z.ZodObject<{
67
+ value: z.ZodString;
68
+ label: z.ZodString;
69
+ }, z.core.$strict>>;
70
+ }, z.core.$strict>], "type">>>;
71
+ network: z.ZodDefault<z.ZodArray<z.ZodObject<{
72
+ id: z.ZodString;
73
+ title: z.ZodString;
74
+ url: z.ZodString;
75
+ methods: z.ZodArray<z.ZodEnum<{
76
+ GET: "GET";
77
+ POST: "POST";
78
+ }>>;
79
+ }, z.core.$strict>>>;
80
+ dependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
81
+ peerDependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
82
+ devDependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
83
+ scripts: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
84
+ bin: z.ZodOptional<z.ZodUndefined>;
85
+ exports: z.ZodObject<{
86
+ ".": z.ZodObject<{
87
+ types: z.ZodLiteral<"./dist/index.d.ts">;
88
+ import: z.ZodString;
89
+ }, z.core.$strict>;
90
+ "./package.json": z.ZodLiteral<"./package.json">;
91
+ }, z.core.$strict>;
92
+ }, z.core.$strip>;
93
+ type ExtensionPackage = z.infer<typeof extensionPackageSchema>;
94
+ declare function toExtensionManifest(value: unknown): {
95
+ id: string;
96
+ apiVersion: 1;
97
+ version: string;
98
+ title: string;
99
+ description: string;
100
+ author: string;
101
+ permissions: ("deck.read" | "selection.read" | "deck.propose" | "cards.inspect" | "cards.search" | "workspace.open" | "notifications.show" | "storage.read" | "storage.write" | "preferences.read" | "preferences.write" | "network.request")[];
102
+ panels: {
103
+ id: string;
104
+ title: string;
105
+ location?: "workspace" | "sidebar" | undefined;
106
+ }[];
107
+ commands: {
108
+ id: string;
109
+ title: string;
110
+ }[];
111
+ preferences: ({
112
+ id: string;
113
+ title: string;
114
+ type: "text";
115
+ default: string;
116
+ description?: string | undefined;
117
+ } | {
118
+ id: string;
119
+ title: string;
120
+ type: "boolean";
121
+ default: boolean;
122
+ description?: string | undefined;
123
+ } | {
124
+ id: string;
125
+ title: string;
126
+ type: "number";
127
+ default: number;
128
+ description?: string | undefined;
129
+ } | {
130
+ id: string;
131
+ title: string;
132
+ type: "select";
133
+ default: string;
134
+ options: {
135
+ value: string;
136
+ label: string;
137
+ }[];
138
+ description?: string | undefined;
139
+ })[];
140
+ network: {
141
+ id: string;
142
+ title: string;
143
+ url: string;
144
+ methods: ("GET" | "POST")[];
145
+ }[];
146
+ };
147
+
148
+ export { type ExtensionPackage, extensionPackageSchema, toExtensionManifest };
@@ -0,0 +1,148 @@
1
+ export { E as ExtensionClient, c as createExtensionClient } from './client-CSAi6AFj.js';
2
+ import { z } from 'zod';
3
+ export { D as DeckOperation, a as ExtensionArguments, j as ExtensionCard, k as ExtensionDeck, i as ExtensionError, l as ExtensionErrorCode, n as ExtensionInvoker, E as ExtensionManifest, c as ExtensionMethod, d as ExtensionPermission, m as ExtensionRequest, e as ExtensionResponse, b as ExtensionResults, g as ExtensionTheme, N as NetworkEndpoint, o as NetworkRequest, P as ProposalReceipt, h as apiVersion, f as extensionManifestSchema } from './contracts-r8d4RACz.js';
4
+
5
+ declare const extensionPackageSchema: z.ZodObject<{
6
+ name: z.ZodString;
7
+ version: z.ZodString;
8
+ type: z.ZodLiteral<"module">;
9
+ title: z.ZodString;
10
+ description: z.ZodString;
11
+ author: z.ZodString;
12
+ icon: z.ZodString;
13
+ apiVersion: z.ZodLiteral<1>;
14
+ permissions: z.ZodArray<z.ZodEnum<{
15
+ "deck.read": "deck.read";
16
+ "selection.read": "selection.read";
17
+ "deck.propose": "deck.propose";
18
+ "cards.inspect": "cards.inspect";
19
+ "cards.search": "cards.search";
20
+ "workspace.open": "workspace.open";
21
+ "notifications.show": "notifications.show";
22
+ "storage.read": "storage.read";
23
+ "storage.write": "storage.write";
24
+ "preferences.read": "preferences.read";
25
+ "preferences.write": "preferences.write";
26
+ "network.request": "network.request";
27
+ }>>;
28
+ panels: z.ZodArray<z.ZodObject<{
29
+ id: z.ZodString;
30
+ title: z.ZodString;
31
+ entry: z.ZodString;
32
+ location: z.ZodDefault<z.ZodEnum<{
33
+ workspace: "workspace";
34
+ sidebar: "sidebar";
35
+ }>>;
36
+ }, z.core.$strict>>;
37
+ commands: z.ZodDefault<z.ZodArray<z.ZodObject<{
38
+ id: z.ZodString;
39
+ title: z.ZodString;
40
+ entry: z.ZodString;
41
+ }, z.core.$strict>>>;
42
+ preferences: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
43
+ id: z.ZodString;
44
+ title: z.ZodString;
45
+ description: z.ZodOptional<z.ZodString>;
46
+ type: z.ZodLiteral<"text">;
47
+ default: z.ZodString;
48
+ }, z.core.$strict>, z.ZodObject<{
49
+ id: z.ZodString;
50
+ title: z.ZodString;
51
+ description: z.ZodOptional<z.ZodString>;
52
+ type: z.ZodLiteral<"boolean">;
53
+ default: z.ZodBoolean;
54
+ }, z.core.$strict>, z.ZodObject<{
55
+ id: z.ZodString;
56
+ title: z.ZodString;
57
+ description: z.ZodOptional<z.ZodString>;
58
+ type: z.ZodLiteral<"number">;
59
+ default: z.ZodNumber;
60
+ }, z.core.$strict>, z.ZodObject<{
61
+ id: z.ZodString;
62
+ title: z.ZodString;
63
+ description: z.ZodOptional<z.ZodString>;
64
+ type: z.ZodLiteral<"select">;
65
+ default: z.ZodString;
66
+ options: z.ZodArray<z.ZodObject<{
67
+ value: z.ZodString;
68
+ label: z.ZodString;
69
+ }, z.core.$strict>>;
70
+ }, z.core.$strict>], "type">>>;
71
+ network: z.ZodDefault<z.ZodArray<z.ZodObject<{
72
+ id: z.ZodString;
73
+ title: z.ZodString;
74
+ url: z.ZodString;
75
+ methods: z.ZodArray<z.ZodEnum<{
76
+ GET: "GET";
77
+ POST: "POST";
78
+ }>>;
79
+ }, z.core.$strict>>>;
80
+ dependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
81
+ peerDependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
82
+ devDependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
83
+ scripts: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
84
+ bin: z.ZodOptional<z.ZodUndefined>;
85
+ exports: z.ZodObject<{
86
+ ".": z.ZodObject<{
87
+ types: z.ZodLiteral<"./dist/index.d.ts">;
88
+ import: z.ZodString;
89
+ }, z.core.$strict>;
90
+ "./package.json": z.ZodLiteral<"./package.json">;
91
+ }, z.core.$strict>;
92
+ }, z.core.$strip>;
93
+ type ExtensionPackage = z.infer<typeof extensionPackageSchema>;
94
+ declare function toExtensionManifest(value: unknown): {
95
+ id: string;
96
+ apiVersion: 1;
97
+ version: string;
98
+ title: string;
99
+ description: string;
100
+ author: string;
101
+ permissions: ("deck.read" | "selection.read" | "deck.propose" | "cards.inspect" | "cards.search" | "workspace.open" | "notifications.show" | "storage.read" | "storage.write" | "preferences.read" | "preferences.write" | "network.request")[];
102
+ panels: {
103
+ id: string;
104
+ title: string;
105
+ location?: "workspace" | "sidebar" | undefined;
106
+ }[];
107
+ commands: {
108
+ id: string;
109
+ title: string;
110
+ }[];
111
+ preferences: ({
112
+ id: string;
113
+ title: string;
114
+ type: "text";
115
+ default: string;
116
+ description?: string | undefined;
117
+ } | {
118
+ id: string;
119
+ title: string;
120
+ type: "boolean";
121
+ default: boolean;
122
+ description?: string | undefined;
123
+ } | {
124
+ id: string;
125
+ title: string;
126
+ type: "number";
127
+ default: number;
128
+ description?: string | undefined;
129
+ } | {
130
+ id: string;
131
+ title: string;
132
+ type: "select";
133
+ default: string;
134
+ options: {
135
+ value: string;
136
+ label: string;
137
+ }[];
138
+ description?: string | undefined;
139
+ })[];
140
+ network: {
141
+ id: string;
142
+ title: string;
143
+ url: string;
144
+ methods: ("GET" | "POST")[];
145
+ }[];
146
+ };
147
+
148
+ export { type ExtensionPackage, extensionPackageSchema, toExtensionManifest };
package/dist/index.js ADDED
@@ -0,0 +1,234 @@
1
+ import {
2
+ ExtensionError,
3
+ apiVersion,
4
+ extensionManifestSchema,
5
+ maxRequestBytes,
6
+ maxResponseBytes,
7
+ messageBytes,
8
+ networkEndpointSchema,
9
+ networkRequestSchema,
10
+ parseResult,
11
+ permissionSchema,
12
+ preferenceSchema,
13
+ protocol,
14
+ requestSchema,
15
+ responseSchema
16
+ } from "./chunk-LBLXK5J2.js";
17
+
18
+ // src/client.ts
19
+ function createExtensionClient(invoke, sessionId, permissions, timeoutMs = 1e4, networkTimeoutMs = 9e4) {
20
+ const pending = /* @__PURE__ */ new Map();
21
+ let closed = false;
22
+ let revision;
23
+ const call = (method, params) => {
24
+ if (closed)
25
+ return Promise.reject(
26
+ new ExtensionError("Extension access has been revoked.", "revoked")
27
+ );
28
+ if (pending.size >= 4)
29
+ return Promise.reject(new ExtensionError("Too many pending calls.", "rate-limited"));
30
+ const parsed = requestSchema.safeParse({
31
+ protocol,
32
+ apiVersion,
33
+ type: "request",
34
+ sessionId,
35
+ id: crypto.randomUUID(),
36
+ method,
37
+ params
38
+ });
39
+ if (!parsed.success)
40
+ return Promise.reject(
41
+ new ExtensionError("The extension request is invalid.", "invalid")
42
+ );
43
+ const request = parsed.data;
44
+ if (messageBytes(request) > maxRequestBytes)
45
+ return Promise.reject(
46
+ new ExtensionError("The extension request is too large.", "invalid")
47
+ );
48
+ return new Promise((resolve, reject) => {
49
+ const timer = setTimeout(
50
+ () => {
51
+ pending.delete(request.id);
52
+ reject(new ExtensionError("The extension operation timed out.", "timeout"));
53
+ },
54
+ method === "network.request" ? networkTimeoutMs : timeoutMs
55
+ );
56
+ pending.set(request.id, { timer, reject });
57
+ Promise.resolve().then(() => invoke(request)).then(
58
+ (raw) => {
59
+ if (!pending.has(request.id)) return;
60
+ pending.delete(request.id);
61
+ clearTimeout(timer);
62
+ try {
63
+ if (messageBytes(raw) > maxResponseBytes)
64
+ throw new ExtensionError(
65
+ "The extension response is too large.",
66
+ "invalid"
67
+ );
68
+ const response = responseSchema.parse(raw);
69
+ if (response.sessionId !== sessionId || response.id !== request.id)
70
+ throw new ExtensionError(
71
+ "The host response belongs to another request.",
72
+ "invalid"
73
+ );
74
+ if (!response.ok)
75
+ throw new ExtensionError(
76
+ response.error.message,
77
+ response.error.code
78
+ );
79
+ resolve(parseResult(method, response.result));
80
+ } catch (error) {
81
+ reject(
82
+ error instanceof ExtensionError ? error : new ExtensionError(
83
+ "The host returned an invalid response.",
84
+ "invalid"
85
+ )
86
+ );
87
+ }
88
+ },
89
+ (error) => {
90
+ if (!pending.has(request.id)) return;
91
+ pending.delete(request.id);
92
+ clearTimeout(timer);
93
+ if (!(error instanceof ExtensionError))
94
+ console.error("Extension transport failed.", error);
95
+ reject(
96
+ error instanceof ExtensionError ? error : new ExtensionError(
97
+ "The extension operation failed.",
98
+ "unavailable"
99
+ )
100
+ );
101
+ }
102
+ );
103
+ });
104
+ };
105
+ const propose = async (operations) => {
106
+ if (!revision)
107
+ throw new ExtensionError("Read the deck before proposing changes.", "invalid");
108
+ const receipt = await call("deck.propose", { operations, expectedRevision: revision });
109
+ if (receipt.status === "applied") revision = receipt.revision;
110
+ return receipt;
111
+ };
112
+ return {
113
+ permissions: Object.freeze([...permissions]),
114
+ deck: {
115
+ read: async () => {
116
+ const deck = await call("deck.read", {});
117
+ revision = deck.revision;
118
+ return deck;
119
+ },
120
+ propose,
121
+ addCard: (cardId, category, quantity = 1) => propose([{ op: "add", cardId, category, quantity }]),
122
+ removeCard: (cardId, quantity = 1) => propose([{ op: "remove", cardId, quantity }]),
123
+ applyTags: (cardIds, tags) => propose([{ op: "tag", cardIds, tags }])
124
+ },
125
+ selection: { read: () => call("selection.read", {}) },
126
+ network: {
127
+ request: (request) => {
128
+ const parsed = networkRequestSchema.safeParse(request);
129
+ return parsed.success ? call("network.request", parsed.data) : Promise.reject(new ExtensionError("The API request is invalid.", "invalid"));
130
+ }
131
+ },
132
+ cards: {
133
+ inspect: (cardId) => call("cards.inspect", { cardId }),
134
+ search: (query, page = 1) => call("cards.search", { query, page }),
135
+ getByName: (name) => call("cards.get", { name })
136
+ },
137
+ workspace: {
138
+ openPanel: (panelId, location = "workspace") => call("workspace.open", { panelId, location })
139
+ },
140
+ notifications: {
141
+ show: (message, kind = "info") => call("notifications.show", { message, kind })
142
+ },
143
+ storage: {
144
+ get: (key) => call("storage.get", { key }),
145
+ set: (key, value) => call("storage.set", { key, value })
146
+ },
147
+ preferences: {
148
+ get: () => call("preferences.get", {}),
149
+ set: (key, value) => call("preferences.set", { key, value })
150
+ },
151
+ dispose: () => {
152
+ closed = true;
153
+ for (const item of pending.values()) {
154
+ clearTimeout(item.timer);
155
+ item.reject(new ExtensionError("Extension access has been revoked.", "revoked"));
156
+ }
157
+ pending.clear();
158
+ }
159
+ };
160
+ }
161
+
162
+ // src/manifest.ts
163
+ import { z } from "zod";
164
+ var label = z.string().trim().min(1).max(300);
165
+ var relativeFile = z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._/-]*$/).refine(
166
+ (value) => !value.includes("..") && !value.includes("//"),
167
+ "Paths must stay inside the extension."
168
+ );
169
+ var panel = z.strictObject({
170
+ id: z.string().regex(/^[a-z0-9][a-z0-9-]{0,49}$/),
171
+ title: label,
172
+ entry: relativeFile.refine((value) => value.endsWith(".tsx")),
173
+ location: z.enum(["workspace", "sidebar"]).default("workspace")
174
+ });
175
+ var extensionPackageSchema = z.object({
176
+ name: z.string().regex(/^@edhspace-extension\/[a-z0-9][a-z0-9-]{0,49}$/),
177
+ version: z.string().regex(/^\d+\.\d+\.\d+$/),
178
+ type: z.literal("module"),
179
+ title: label,
180
+ description: z.string().min(1).max(1e3),
181
+ author: label,
182
+ icon: relativeFile.refine((value) => /\.(svg|png)$/.test(value)),
183
+ apiVersion: z.literal(apiVersion),
184
+ permissions: z.array(permissionSchema),
185
+ panels: z.array(panel).min(1).max(6),
186
+ commands: z.array(
187
+ z.strictObject({
188
+ id: panel.shape.id,
189
+ title: label,
190
+ entry: relativeFile.refine((value) => value.endsWith(".ts"))
191
+ })
192
+ ).max(6).default([]),
193
+ preferences: z.array(preferenceSchema).max(20).default([]),
194
+ network: z.array(networkEndpointSchema).max(8).default([]),
195
+ dependencies: z.record(z.string(), z.string()).default({}),
196
+ peerDependencies: z.record(z.string(), z.string()).default({}),
197
+ devDependencies: z.record(z.string(), z.string()).default({}),
198
+ scripts: z.record(z.string(), z.string()).default({}),
199
+ bin: z.undefined({ error: "Executable bins are not allowed in extensions." }).optional(),
200
+ exports: z.strictObject({
201
+ ".": z.strictObject({ types: z.literal("./dist/index.d.ts"), import: z.string() }),
202
+ "./package.json": z.literal("./package.json")
203
+ })
204
+ }).refine(
205
+ (pkg) => pkg.panels[0].entry === "src/index.tsx" && pkg.exports["."].import === `./dist/${pkg.panels[0].id}.js`,
206
+ "The primary panel must use src/index.tsx and export its generated dist artifact."
207
+ ).refine((pkg) => {
208
+ const ids = [...pkg.panels, ...pkg.commands].map((entry) => entry.id);
209
+ return new Set(ids).size === ids.length;
210
+ }, "Panel and command IDs must be unique.");
211
+ function toExtensionManifest(value) {
212
+ const pkg = extensionPackageSchema.parse(value);
213
+ return extensionManifestSchema.parse({
214
+ id: pkg.name.slice(1).replace("/", "."),
215
+ apiVersion: pkg.apiVersion,
216
+ version: pkg.version,
217
+ title: pkg.title,
218
+ description: pkg.description,
219
+ author: pkg.author,
220
+ permissions: pkg.permissions,
221
+ preferences: pkg.preferences,
222
+ panels: pkg.panels.map(({ id, title, location }) => ({ id, title, location })),
223
+ commands: pkg.commands.map(({ id, title }) => ({ id, title })),
224
+ network: pkg.network
225
+ });
226
+ }
227
+ export {
228
+ ExtensionError,
229
+ apiVersion,
230
+ createExtensionClient,
231
+ extensionManifestSchema,
232
+ extensionPackageSchema,
233
+ toExtensionManifest
234
+ };
package/dist/math.cjs ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/math.ts
2
+ function drawProbability(model) {
3
+ const { population, successes, draws, atLeast } = model;
4
+ if (![population, successes, draws, atLeast].every(Number.isInteger) || population < 1 || population > 1e3 || successes < 0 || successes > population || draws < 0 || draws > population || atLeast < 0 || atLeast > draws)
5
+ throw new RangeError(
6
+ "Use whole numbers: library 1-1000, targets and draws within the library, and minimum within the draw."
7
+ );
8
+ return hypergeometricAtLeast(population, successes, draws, atLeast);
9
+ }
10
+ function manaCurve(cards) {
11
+ const bins = /* @__PURE__ */ new Map();
12
+ for (const card of cards) {
13
+ if (card.commander || /\bLand\b/.test(_nullishCoalesce(_optionalChain([card, 'access', _ => _.typeLine, 'optionalAccess', _2 => _2.split, 'call', _3 => _3(/\s*\/\/\s*/), 'access', _4 => _4[0]]), () => ( ""))))
14
+ continue;
15
+ const bin = card.manaValue === void 0 ? "Unknown" : card.manaValue >= 7 ? "7+" : String(card.manaValue);
16
+ bins.set(bin, (_nullishCoalesce(bins.get(bin), () => ( 0))) + card.quantity);
17
+ }
18
+ return [...bins].sort(
19
+ ([a], [b]) => (a === "Unknown" ? Infinity : parseFloat(a)) - (b === "Unknown" ? Infinity : parseFloat(b))
20
+ ).map(([manaValue, count]) => ({ manaValue, count }));
21
+ }
22
+ function binomialCoefficient(n, k) {
23
+ if (k > n || k < 0) return 0;
24
+ if (k === 0 || k === n) return 1;
25
+ k = Math.min(k, n - k);
26
+ let result = 1;
27
+ for (let i = 0; i < k; i++) {
28
+ result *= n - i;
29
+ result /= i + 1;
30
+ }
31
+ return result;
32
+ }
33
+ function hypergeometric(populationSize, successesInPopulation, sampleSize, successesInSample) {
34
+ const numerator = binomialCoefficient(successesInPopulation, successesInSample) * binomialCoefficient(populationSize - successesInPopulation, sampleSize - successesInSample);
35
+ const denominator = binomialCoefficient(populationSize, sampleSize);
36
+ return numerator / denominator;
37
+ }
38
+ function hypergeometricAtLeast(populationSize, successesInPopulation, sampleSize, minSuccesses) {
39
+ let probability = 0;
40
+ for (let k = minSuccesses; k <= Math.min(sampleSize, successesInPopulation); k++) {
41
+ probability += hypergeometric(populationSize, successesInPopulation, sampleSize, k);
42
+ }
43
+ return probability;
44
+ }
45
+ function hypergeometricAtMost(populationSize, successesInPopulation, sampleSize, maxSuccesses) {
46
+ let probability = 0;
47
+ for (let k = 0; k <= Math.min(maxSuccesses, sampleSize, successesInPopulation); k++) {
48
+ probability += hypergeometric(populationSize, successesInPopulation, sampleSize, k);
49
+ }
50
+ return probability;
51
+ }
52
+ function hypergeometricBetween(populationSize, successesInPopulation, sampleSize, minSuccesses, maxSuccesses) {
53
+ let probability = 0;
54
+ for (let k = minSuccesses; k <= Math.min(maxSuccesses, sampleSize, successesInPopulation); k++) {
55
+ probability += hypergeometric(populationSize, successesInPopulation, sampleSize, k);
56
+ }
57
+ return probability;
58
+ }
59
+ function multivariateHypergeometric(populationSize, groups, sampleSize) {
60
+ const totalGroupCards = groups.reduce((sum, g) => sum + g.count, 0);
61
+ if (totalGroupCards > populationSize) {
62
+ throw new Error("Total group cards exceeds population size");
63
+ }
64
+ const otherCards = populationSize - totalGroupCards;
65
+ let probability = 0;
66
+ function generateCombinations(groupIndex, currentCounts, remainingDraw) {
67
+ if (groupIndex === groups.length) {
68
+ let valid = true;
69
+ for (let i = 0; i < groups.length; i++) {
70
+ const min = _nullishCoalesce(groups[i].min, () => ( 1));
71
+ const max = _nullishCoalesce(groups[i].max, () => ( sampleSize));
72
+ if (currentCounts[i] < min || currentCounts[i] > max) {
73
+ valid = false;
74
+ break;
75
+ }
76
+ }
77
+ if (!valid) return;
78
+ let numerator = 1;
79
+ for (let i = 0; i < groups.length; i++) {
80
+ numerator *= binomialCoefficient(groups[i].count, currentCounts[i]);
81
+ }
82
+ const otherDrawn = remainingDraw;
83
+ numerator *= binomialCoefficient(otherCards, otherDrawn);
84
+ const denominator = binomialCoefficient(populationSize, sampleSize);
85
+ probability += numerator / denominator;
86
+ return;
87
+ }
88
+ const group = groups[groupIndex];
89
+ const minDraw = Math.max(0, _nullishCoalesce(group.min, () => ( 0)));
90
+ const maxDraw = Math.min(group.count, remainingDraw, _nullishCoalesce(group.max, () => ( sampleSize)));
91
+ for (let count = minDraw; count <= maxDraw; count++) {
92
+ currentCounts[groupIndex] = count;
93
+ generateCombinations(groupIndex + 1, currentCounts, remainingDraw - count);
94
+ }
95
+ }
96
+ generateCombinations(0, [], sampleSize);
97
+ return probability;
98
+ }
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+ exports.drawProbability = drawProbability; exports.hypergeometric = hypergeometric; exports.hypergeometricAtLeast = hypergeometricAtLeast; exports.hypergeometricAtMost = hypergeometricAtMost; exports.hypergeometricBetween = hypergeometricBetween; exports.manaCurve = manaCurve; exports.multivariateHypergeometric = multivariateHypergeometric;