@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.
@@ -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,85 @@
1
+ import {
2
+ createExtensionClient
3
+ } from "./chunk-4STXB3BK.js";
4
+ import {
5
+ ExtensionError,
6
+ apiVersion,
7
+ extensionManifestSchema,
8
+ networkEndpointSchema,
9
+ permissionSchema,
10
+ preferenceSchema
11
+ } from "./chunk-LBLXK5J2.js";
12
+
13
+ // src/manifest.ts
14
+ import { z } from "zod";
15
+ var label = z.string().trim().min(1).max(300);
16
+ var relativeFile = z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._/-]*$/).refine(
17
+ (value) => !value.includes("..") && !value.includes("//"),
18
+ "Paths must stay inside the extension."
19
+ );
20
+ var panel = z.strictObject({
21
+ id: z.string().regex(/^[a-z0-9][a-z0-9-]{0,49}$/),
22
+ title: label,
23
+ entry: relativeFile.refine((value) => value.endsWith(".tsx")),
24
+ location: z.enum(["workspace", "sidebar"]).default("workspace")
25
+ });
26
+ var extensionPackageSchema = z.object({
27
+ name: z.string().regex(/^@edhspace-extension\/[a-z0-9][a-z0-9-]{0,49}$/),
28
+ version: z.string().regex(/^\d+\.\d+\.\d+$/),
29
+ type: z.literal("module"),
30
+ title: label,
31
+ description: z.string().min(1).max(1e3),
32
+ author: label,
33
+ icon: relativeFile.refine((value) => /\.(svg|png)$/.test(value)),
34
+ apiVersion: z.literal(apiVersion),
35
+ permissions: z.array(permissionSchema),
36
+ panels: z.array(panel).min(1).max(6),
37
+ commands: z.array(
38
+ z.strictObject({
39
+ id: panel.shape.id,
40
+ title: label,
41
+ entry: relativeFile.refine((value) => value.endsWith(".ts"))
42
+ })
43
+ ).max(6).default([]),
44
+ preferences: z.array(preferenceSchema).max(20).default([]),
45
+ network: z.array(networkEndpointSchema).max(8).default([]),
46
+ dependencies: z.record(z.string(), z.string()).default({}),
47
+ peerDependencies: z.record(z.string(), z.string()).default({}),
48
+ devDependencies: z.record(z.string(), z.string()).default({}),
49
+ scripts: z.record(z.string(), z.string()).default({}),
50
+ bin: z.undefined({ error: "Executable bins are not allowed in extensions." }).optional(),
51
+ exports: z.strictObject({
52
+ ".": z.strictObject({ types: z.literal("./dist/index.d.ts"), import: z.string() }),
53
+ "./package.json": z.literal("./package.json")
54
+ })
55
+ }).refine(
56
+ (pkg) => pkg.panels[0].entry === "src/index.tsx" && pkg.exports["."].import === `./dist/${pkg.panels[0].id}.js`,
57
+ "The primary panel must use src/index.tsx and export its generated dist artifact."
58
+ ).refine((pkg) => {
59
+ const ids = [...pkg.panels, ...pkg.commands].map((entry) => entry.id);
60
+ return new Set(ids).size === ids.length;
61
+ }, "Panel and command IDs must be unique.");
62
+ function toExtensionManifest(value) {
63
+ const pkg = extensionPackageSchema.parse(value);
64
+ return extensionManifestSchema.parse({
65
+ id: pkg.name.slice(1).replace("/", "."),
66
+ apiVersion: pkg.apiVersion,
67
+ version: pkg.version,
68
+ title: pkg.title,
69
+ description: pkg.description,
70
+ author: pkg.author,
71
+ permissions: pkg.permissions,
72
+ preferences: pkg.preferences,
73
+ panels: pkg.panels.map(({ id, title, location }) => ({ id, title, location })),
74
+ commands: pkg.commands.map(({ id, title }) => ({ id, title })),
75
+ network: pkg.network
76
+ });
77
+ }
78
+ export {
79
+ ExtensionError,
80
+ apiVersion,
81
+ createExtensionClient,
82
+ extensionManifestSchema,
83
+ extensionPackageSchema,
84
+ toExtensionManifest
85
+ };
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;
@@ -0,0 +1,70 @@
1
+ import { j as ExtensionCard } from './contracts-r8d4RACz.cjs';
2
+ import 'zod';
3
+
4
+ declare function drawProbability(model: {
5
+ population: number;
6
+ successes: number;
7
+ draws: number;
8
+ atLeast: number;
9
+ }): number;
10
+ declare function manaCurve(cards: readonly ExtensionCard[]): {
11
+ manaValue: string;
12
+ count: number;
13
+ }[];
14
+ /**
15
+ * Calculate hypergeometric probability
16
+ *
17
+ * @param populationSize - Total number of cards in deck (N)
18
+ * @param successesInPopulation - Number of success cards in deck (K) - e.g., number of lands
19
+ * @param sampleSize - Number of cards drawn (n) - e.g., opening hand of 7
20
+ * @param successesInSample - Exact number of successes you want (k) - e.g., exactly 3 lands
21
+ * @returns Probability of drawing exactly k successes
22
+ */
23
+ declare function hypergeometric(populationSize: number, successesInPopulation: number, sampleSize: number, successesInSample: number): number;
24
+ /**
25
+ * Calculate probability of drawing AT LEAST k successes
26
+ *
27
+ * @param populationSize - Total number of cards in deck (N)
28
+ * @param successesInPopulation - Number of success cards in deck (K)
29
+ * @param sampleSize - Number of cards drawn (n)
30
+ * @param minSuccesses - Minimum number of successes you want (k or more)
31
+ * @returns Probability of drawing at least k successes
32
+ */
33
+ declare function hypergeometricAtLeast(populationSize: number, successesInPopulation: number, sampleSize: number, minSuccesses: number): number;
34
+ /**
35
+ * Calculate probability of drawing AT MOST k successes
36
+ *
37
+ * @param populationSize - Total number of cards in deck (N)
38
+ * @param successesInPopulation - Number of success cards in deck (K)
39
+ * @param sampleSize - Number of cards drawn (n)
40
+ * @param maxSuccesses - Maximum number of successes you want (k or fewer)
41
+ * @returns Probability of drawing at most k successes
42
+ */
43
+ declare function hypergeometricAtMost(populationSize: number, successesInPopulation: number, sampleSize: number, maxSuccesses: number): number;
44
+ /**
45
+ * Calculate probability of drawing BETWEEN k1 and k2 successes (inclusive)
46
+ */
47
+ declare function hypergeometricBetween(populationSize: number, successesInPopulation: number, sampleSize: number, minSuccesses: number, maxSuccesses: number): number;
48
+ /**
49
+ * Card group for multivariate hypergeometric calculation
50
+ */
51
+ interface CardGroup {
52
+ count: number;
53
+ min?: number;
54
+ max?: number;
55
+ }
56
+ /**
57
+ * Calculate probability of drawing specific amounts from multiple card groups
58
+ * Uses multivariate hypergeometric distribution
59
+ *
60
+ * Example: "What's the probability of drawing at least 1 Sanguine Bond effect (3 in deck)
61
+ * AND at least 1 Exquisite Blood effect (2 in deck) in 15 cards?"
62
+ *
63
+ * @param populationSize - Total number of cards in deck (N)
64
+ * @param groups - Array of card groups with their counts and constraints
65
+ * @param sampleSize - Number of cards drawn (n)
66
+ * @returns Probability of meeting all group constraints simultaneously
67
+ */
68
+ declare function multivariateHypergeometric(populationSize: number, groups: CardGroup[], sampleSize: number): number;
69
+
70
+ export { type CardGroup, drawProbability, hypergeometric, hypergeometricAtLeast, hypergeometricAtMost, hypergeometricBetween, manaCurve, multivariateHypergeometric };
package/dist/math.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ import { j as ExtensionCard } from './contracts-r8d4RACz.js';
2
+ import 'zod';
3
+
4
+ declare function drawProbability(model: {
5
+ population: number;
6
+ successes: number;
7
+ draws: number;
8
+ atLeast: number;
9
+ }): number;
10
+ declare function manaCurve(cards: readonly ExtensionCard[]): {
11
+ manaValue: string;
12
+ count: number;
13
+ }[];
14
+ /**
15
+ * Calculate hypergeometric probability
16
+ *
17
+ * @param populationSize - Total number of cards in deck (N)
18
+ * @param successesInPopulation - Number of success cards in deck (K) - e.g., number of lands
19
+ * @param sampleSize - Number of cards drawn (n) - e.g., opening hand of 7
20
+ * @param successesInSample - Exact number of successes you want (k) - e.g., exactly 3 lands
21
+ * @returns Probability of drawing exactly k successes
22
+ */
23
+ declare function hypergeometric(populationSize: number, successesInPopulation: number, sampleSize: number, successesInSample: number): number;
24
+ /**
25
+ * Calculate probability of drawing AT LEAST k successes
26
+ *
27
+ * @param populationSize - Total number of cards in deck (N)
28
+ * @param successesInPopulation - Number of success cards in deck (K)
29
+ * @param sampleSize - Number of cards drawn (n)
30
+ * @param minSuccesses - Minimum number of successes you want (k or more)
31
+ * @returns Probability of drawing at least k successes
32
+ */
33
+ declare function hypergeometricAtLeast(populationSize: number, successesInPopulation: number, sampleSize: number, minSuccesses: number): number;
34
+ /**
35
+ * Calculate probability of drawing AT MOST k successes
36
+ *
37
+ * @param populationSize - Total number of cards in deck (N)
38
+ * @param successesInPopulation - Number of success cards in deck (K)
39
+ * @param sampleSize - Number of cards drawn (n)
40
+ * @param maxSuccesses - Maximum number of successes you want (k or fewer)
41
+ * @returns Probability of drawing at most k successes
42
+ */
43
+ declare function hypergeometricAtMost(populationSize: number, successesInPopulation: number, sampleSize: number, maxSuccesses: number): number;
44
+ /**
45
+ * Calculate probability of drawing BETWEEN k1 and k2 successes (inclusive)
46
+ */
47
+ declare function hypergeometricBetween(populationSize: number, successesInPopulation: number, sampleSize: number, minSuccesses: number, maxSuccesses: number): number;
48
+ /**
49
+ * Card group for multivariate hypergeometric calculation
50
+ */
51
+ interface CardGroup {
52
+ count: number;
53
+ min?: number;
54
+ max?: number;
55
+ }
56
+ /**
57
+ * Calculate probability of drawing specific amounts from multiple card groups
58
+ * Uses multivariate hypergeometric distribution
59
+ *
60
+ * Example: "What's the probability of drawing at least 1 Sanguine Bond effect (3 in deck)
61
+ * AND at least 1 Exquisite Blood effect (2 in deck) in 15 cards?"
62
+ *
63
+ * @param populationSize - Total number of cards in deck (N)
64
+ * @param groups - Array of card groups with their counts and constraints
65
+ * @param sampleSize - Number of cards drawn (n)
66
+ * @returns Probability of meeting all group constraints simultaneously
67
+ */
68
+ declare function multivariateHypergeometric(populationSize: number, groups: CardGroup[], sampleSize: number): number;
69
+
70
+ export { type CardGroup, drawProbability, hypergeometric, hypergeometricAtLeast, hypergeometricAtMost, hypergeometricBetween, manaCurve, multivariateHypergeometric };
package/dist/math.js ADDED
@@ -0,0 +1,107 @@
1
+ // 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(card.typeLine?.split(/\s*\/\/\s*/)[0] ?? ""))
14
+ continue;
15
+ const bin = card.manaValue === void 0 ? "Unknown" : card.manaValue >= 7 ? "7+" : String(card.manaValue);
16
+ bins.set(bin, (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 = groups[i].min ?? 1;
71
+ const max = 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, group.min ?? 0);
90
+ const maxDraw = Math.min(group.count, remainingDraw, 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
+ export {
100
+ drawProbability,
101
+ hypergeometric,
102
+ hypergeometricAtLeast,
103
+ hypergeometricAtMost,
104
+ hypergeometricBetween,
105
+ manaCurve,
106
+ multivariateHypergeometric
107
+ };
package/dist/react.cjs ADDED
@@ -0,0 +1,69 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/react.tsx
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+ var _react = require('react');
10
+ var _jsxruntime = require('react/jsx-runtime');
11
+ var Context = _react.createContext.call(void 0, void 0);
12
+ function ExtensionProvider({
13
+ api,
14
+ revision,
15
+ children
16
+ }) {
17
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Context.Provider, { value: { api, revision }, children });
18
+ }
19
+ function useContextValue() {
20
+ const context = _react.useContext.call(void 0, 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 = _react.useRef.call(void 0, 0);
29
+ const [data, setData] = _react.useState.call(void 0, );
30
+ const [error, setError] = _react.useState.call(void 0, );
31
+ const [loading, setLoading] = _react.useState.call(void 0, true);
32
+ const refresh = _react.useCallback.call(void 0, 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
+ _react.useEffect.call(void 0, () => {
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
+
65
+
66
+
67
+
68
+
69
+ exports.ExtensionProvider = ExtensionProvider; exports.useActiveDeck = useActiveDeck; exports.useExtension = useExtension; exports.useSelectedCards = useSelectedCards;