breakout into monorepo

This commit is contained in:
Dominic Ferrando
2026-03-02 13:39:47 -05:00
parent 6421f6527f
commit 45acec2cfd
90 changed files with 12179 additions and 2987 deletions
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="128" viewBox="0 0 107 128"><title>svelte-logo</title><path d="M94.157 22.819c-10.4-14.885-30.94-19.297-45.792-9.835L22.282 29.608A29.92 29.92 0 0 0 8.764 49.65a31.5 31.5 0 0 0 3.108 20.231 30 30 0 0 0-4.477 11.183 31.9 31.9 0 0 0 5.448 24.116c10.402 14.887 30.942 19.297 45.791 9.835l26.083-16.624A29.92 29.92 0 0 0 98.235 78.35a31.53 31.53 0 0 0-3.105-20.232 30 30 0 0 0 4.474-11.182 31.88 31.88 0 0 0-5.447-24.116" style="fill:#ff3e00"/><path d="M45.817 106.582a20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.503 18 18 0 0 1 .624-2.435l.49-1.498 1.337.981a33.6 33.6 0 0 0 10.203 5.098l.97.294-.09.968a5.85 5.85 0 0 0 1.052 3.878 6.24 6.24 0 0 0 6.695 2.485 5.8 5.8 0 0 0 1.603-.704L69.27 76.28a5.43 5.43 0 0 0 2.45-3.631 5.8 5.8 0 0 0-.987-4.371 6.24 6.24 0 0 0-6.698-2.487 5.7 5.7 0 0 0-1.6.704l-9.953 6.345a19 19 0 0 1-5.296 2.326 20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.502 17.99 17.99 0 0 1 8.13-12.052l26.081-16.623a19 19 0 0 1 5.3-2.329 20.72 20.72 0 0 1 22.237 8.243 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-.624 2.435l-.49 1.498-1.337-.98a33.6 33.6 0 0 0-10.203-5.1l-.97-.294.09-.968a5.86 5.86 0 0 0-1.052-3.878 6.24 6.24 0 0 0-6.696-2.485 5.8 5.8 0 0 0-1.602.704L37.73 51.72a5.42 5.42 0 0 0-2.449 3.63 5.79 5.79 0 0 0 .986 4.372 6.24 6.24 0 0 0 6.698 2.486 5.8 5.8 0 0 0 1.602-.704l9.952-6.342a19 19 0 0 1 5.295-2.328 20.72 20.72 0 0 1 22.237 8.242 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-8.13 12.053l-26.081 16.622a19 19 0 0 1-5.3 2.328" style="fill:#fff"/></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

@@ -0,0 +1,295 @@
<script lang="ts">
import {
LevelCalculator,
Activity,
Attribute,
Gender,
lbToKg,
range,
type LevelCalculatorOutput,
type Standards,
type ActivityPerformance,
type Player,
} from "@blade-and-brawn/calculator";
interface CalcData {
levels?: LevelCalculatorOutput;
player: Player;
activityPerformances: ActivityPerformance[];
}
interface Props {
allStandards: Standards;
}
const { allStandards }: Props = $props();
const levelCalculator = $derived(new LevelCalculator(allStandards));
let calculations = $state([] as CalcData[]);
$effect(() => {
for (const calculation of calculations) {
calculation.levels = levelCalculator.calculate(
calculation.player,
calculation.activityPerformances,
);
}
});
$effect(() => {
const savedCalcs = localStorage.getItem("calculations");
if (savedCalcs) calculations = JSON.parse(savedCalcs);
});
$effect(() => {
localStorage.setItem("calculations", JSON.stringify(calculations));
});
$inspect(calculations[0]);
const createCalculation = function (name: string) {
return {
player: {
name: name,
metrics: {
age: 18,
weight: lbToKg(180),
gender: Gender.Male,
},
},
activityPerformances: Object.values(Activity).map((a) => ({
activity: a,
performance: 0,
})),
};
};
function downloadObject(obj: unknown, filename = "data.json") {
const json = JSON.stringify(obj, null, 2);
const blob = new Blob([json], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
}
const formatMs = (ms: number) => {
const total = Math.floor(ms / 1000);
const m = Math.floor(total / 60);
const s = total % 60;
return `${m}m ${s}s`;
};
const inchesToFeetInches = (inches: number) => {
const ft = Math.floor(inches / 12);
const rem = inches - ft * 12;
const whole = Math.floor(rem);
const isHalf = Math.abs(rem - whole - 0.5) < 1e-9;
const inchLabel = isHalf ? `${whole}½` : `${whole}`;
return `${ft}' ${inchLabel}"`;
};
const formatSeconds = (ms: number) => (ms / 1000).toFixed(2) + " seconds";
const performanceOptionsFromActivity = function (activity: Activity) {
const options: { name: string; value: string }[] = [];
switch (activity) {
case Activity.BackSquat:
case Activity.Deadlift:
case Activity.BenchPress:
for (let i = 0; i < 600; ++i) {
options.push({
name: String(i) + " lb",
value: String(lbToKg(i)),
});
}
break;
case Activity.Run: {
const MAX_MIN = 30;
for (let ms = 0; ms <= MAX_MIN * 60_000; ms += 1_000) {
options.push({ name: formatMs(ms), value: String(ms) });
}
break;
}
case Activity.BroadJump: {
const MAX_INCHES = 15 * 12 + 5;
for (let halfStep = 0; halfStep <= MAX_INCHES * 2; halfStep++) {
const inches = halfStep / 2;
options.push({
name: inchesToFeetInches(inches),
value: (inches * 2.54).toFixed(1),
});
}
break;
}
case Activity.ConeDrill: {
const MIN_MS = 5_000;
const MAX_MS = 20_000;
for (let ms = MIN_MS; ms <= MAX_MS; ms += 10) {
options.push({
name: formatSeconds(ms),
value: String(ms),
});
}
break;
}
}
return options;
};
</script>
<div class="mt-5 mb-5 flex w-full">
<div class="ml-auto">
<button
onclick={() =>
calculations.push(
createCalculation(String(calculations.length)),
)}
class="btn btn-primary">New</button
>
<button
onclick={() => downloadObject(calculations)}
class="btn btn-secondary">Export</button
>
</div>
</div>
<section
class="w-full px-3 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"
>
{#each calculations as calculation, index}
<div
class="card card-compact bg-base-200 p-4 shadow-lg max-w-sm w-full"
>
<div class="card-body gap-4 p-4">
<input
class="input input-bordered input-sm w-full"
type="text"
bind:value={calculation.player.name}
placeholder="Player name"
/>
<ul
class="bg-base-100 rounded-box shadow-xs divide-y divide-base-300"
>
<li class="p-3">
<div class="flex items-center justify-between">
<div class="font-semibold text-sm">OVERALL</div>
<div class="badge badge-neutral badge-xs">
{calculation?.levels?.player || "N/A"}
</div>
</div>
</li>
{#each Object.values(Attribute) as attribute}
<li class="p-3">
<div class="flex items-center justify-between">
<div class="opacity-80 text-sm">
{attribute}
</div>
<div class="badge badge-ghost badge-xs">
{calculation?.levels?.attributes?.[
attribute
] || "N/A"}
</div>
</div>
</li>
{/each}
</ul>
<fieldset
class="fieldset bg-base-200/60 rounded-lg"
onchange={() =>
(calculation.levels = levelCalculator.calculate(
calculation.player,
calculation.activityPerformances,
))}
>
<div class="grid grid-cols-1 md:grid-cols-3 gap-3">
<label class="form-control">
<span class="label mb-1 text-xs">Gender</span>
<select
class="select select-bordered select-sm w-full"
bind:value={calculation.player.metrics.gender}
>
{#each Object.values(Gender) as gender}
<option value={gender}>{gender}</option>
{/each}
</select>
</label>
<label class="form-control">
<span class="label mb-1 text-xs">Age</span>
<input
class="input input-bordered input-sm w-full"
type="number"
min="1"
max="100"
step="1"
bind:value={calculation.player.metrics.age}
/>
</label>
<label class="form-control">
<span class="label mb-1 text-xs">Weight</span>
<select
class="select select-bordered select-sm w-full"
bind:value={calculation.player.metrics.weight}
>
{#each range(400) as weight}
<option value={String(lbToKg(weight))}
>{weight}</option
>
{/each}
</select>
</label>
</div>
</fieldset>
<fieldset
class="fieldset bg-base-200/60 rounded-lg"
onchange={() =>
(calculation.levels = levelCalculator.calculate(
calculation.player,
calculation.activityPerformances,
))}
>
<div class="grid grid-cols-2 gap-3">
{#each calculation.activityPerformances as activityPerformance}
<label class="form-control space-y-1">
<span class="label mb-1 text-xs">
{activityPerformance.activity}
</span>
<select
class="select select-bordered select-sm w-full"
bind:value={activityPerformance.performance}
>
{#each performanceOptionsFromActivity(activityPerformance.activity) as option}
<option value={option.value}
>{option.name}</option
>
{/each}
</select>
</label>
{/each}
</div>
</fieldset>
</div>
<button
onclick={() =>
confirm(`Delete ${calculation.player.name}?`) &&
calculations.splice(index, 1)}
class="btn btn-error btn-sm w-1/4">Delete</button
>
</div>
{/each}
</section>
@@ -0,0 +1,128 @@
<script lang="ts">
import {
Standards,
Activity,
cmToIn,
kgToLb,
range,
type Metrics,
type Standard,
type StandardsConfig,
} from "@blade-and-brawn/calculator";
interface Props {
allStandards: Standards;
selected: {
activity: Activity;
metrics: Metrics;
cfg: StandardsConfig;
};
}
const { selected, allStandards }: Props = $props();
const getLvlValue = (
activity: Activity,
standard: Standard,
lvl: number,
): string => {
const rawValue = standard.levels[lvl];
const unit = allStandards.byActivity(activity).getMetadata().unit;
switch (unit) {
case "ms":
const seconds = (rawValue / 1000).toFixed(1);
return `${seconds}`;
case "cm": {
const totalInches = cmToIn(rawValue);
const feet = Math.floor(totalInches / 12);
const inches = Math.round(totalInches % 12);
return `${feet}'${inches}"`;
}
case "kg":
return String(Math.round(kgToLb(rawValue)));
default:
return "";
}
};
</script>
<section class="w-full">
<div>
<div class="flex items-center">
<p class="text-xs label">
{#if selected.cfg.activity[selected.activity].enableGeneration && allStandards
.byActivity(selected.activity)
.getMetadata().generators.length}
(Generated data: {allStandards
.byActivity(selected.activity)
.getMetadata()
.generators.map((g) => g.metric)
.join(", ")})
{:else}
(Generated data: NONE)
{/if}
</p>
</div>
</div>
{#if !selected.metrics.age}
{#each allStandards.agesFor(selected.activity, selected.metrics.gender) as age}
{@render standardsTable(selected.activity, {
...selected.metrics,
age,
})}
{/each}
{:else}
{@render standardsTable(selected.activity, selected.metrics)}
{/if}
</section>
{#snippet standardsTable(activity: Activity, metrics: Metrics)}
{#snippet standardsTableRow(standard: Standard)}
<tr class="hover:bg-base-300">
<th>
{standard.metrics.weight
? parseFloat(kgToLb(standard.metrics.weight).toFixed(2))
: "None"}</th
>
{#each range(selected.cfg.global.maxLevel).map((i) => ++i) as lvl}
<td>{getLvlValue(activity, standard, lvl)}</td>
{/each}
</tr>
{/snippet}
<div class="mt-5">
<h3 class="text-lg italic font-semibold">{metrics.age}</h3>
<div class="overflow-x-auto">
<table class="table table-zebra table-pin-cols">
<thead>
<tr>
<th>Body weight</th>
{#each range(selected.cfg.global.maxLevel).map((i) => ++i) as lvl}
<td>{lvl}</td>
{/each}
</tr>
</thead>
<tbody>
{#if metrics.weight}
{@const standard = allStandards
.byActivity(activity)
.byGender(metrics.gender)
.byAge(metrics.age)
.byWeight(metrics.weight)
.getOneInterpolated()}
{@render standardsTableRow(standard)}
{:else}
{@const standards = allStandards
.byActivity(activity)
.byGender(metrics.gender)
.byAge(metrics.age)
.getAllInterpolated({ normalizeForLb: true })}
{#each standards as standard}
{@render standardsTableRow(standard)}
{/each}
{/if}
</tbody>
</table>
</div>
</div>
{/snippet}