@shipload/item-renderer 0.2.3 → 1.0.0-beta1
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/package.json +47 -49
- package/src/assets/stardust-base64.ts +1 -1
- package/src/errors.ts +14 -14
- package/src/fonts/index.ts +24 -24
- package/src/fonts/load-bun.ts +12 -12
- package/src/index.ts +31 -31
- package/src/links.ts +13 -13
- package/src/meta.ts +26 -26
- package/src/payload/base64url.ts +21 -21
- package/src/payload/codec.ts +19 -19
- package/src/primitives/category-icon.ts +88 -86
- package/src/primitives/compact-row.ts +32 -32
- package/src/primitives/divider.ts +14 -14
- package/src/primitives/icon-hex.ts +36 -36
- package/src/primitives/module-slot.ts +131 -131
- package/src/primitives/panel.ts +18 -18
- package/src/primitives/quantity-badge.ts +32 -32
- package/src/primitives/span-paragraph.ts +56 -56
- package/src/primitives/stat-bar.ts +72 -72
- package/src/primitives/svg.ts +16 -16
- package/src/primitives/text.ts +33 -33
- package/src/primitives/wrap.ts +19 -19
- package/src/render.ts +20 -20
- package/src/templates/_shared.ts +5 -5
- package/src/templates/component.ts +124 -124
- package/src/templates/index.ts +23 -23
- package/src/templates/item-cell.ts +84 -84
- package/src/templates/module.ts +182 -181
- package/src/templates/packed-entity.ts +22 -22
- package/src/templates/resource.ts +136 -134
- package/src/templates/ship-panel.ts +122 -118
- package/src/templates/social-card.ts +36 -36
- package/src/tokens/colors.ts +42 -42
- package/src/tokens/index.ts +6 -6
- package/src/tokens/spacing.ts +9 -9
- package/src/tokens/typography.ts +18 -18
- package/.claude/settings.local.json +0 -6
- package/.github/workflows/ci.yml +0 -14
- package/.gitignore +0 -6
- package/Makefile +0 -50
- package/biome.json +0 -18
- package/bun.lock +0 -123
- package/scripts/check-bundle-size.ts +0 -37
- package/scripts/copy-fonts.ts +0 -41
- package/scripts/preview.ts +0 -41
- package/test/__image_snapshots__/.gitkeep +0 -0
- package/test/__image_snapshots__/component-hull-plates.diff.png +0 -0
- package/test/__image_snapshots__/component-hull-plates.png +0 -0
- package/test/__image_snapshots__/module-engine-t1.diff.png +0 -0
- package/test/__image_snapshots__/module-engine-t1.png +0 -0
- package/test/__image_snapshots__/module-storage-t1.diff.png +0 -0
- package/test/__image_snapshots__/module-storage-t1.png +0 -0
- package/test/__image_snapshots__/packed-entity-ship-t1-only-engine.diff.png +0 -0
- package/test/__image_snapshots__/packed-entity-ship-t1-only-engine.png +0 -0
- package/test/__image_snapshots__/packed-entity-ship-t1-two-modules.diff.png +0 -0
- package/test/__image_snapshots__/packed-entity-ship-t1-two-modules.png +0 -0
- package/test/__image_snapshots__/resource-ore-t1.diff.png +0 -0
- package/test/__image_snapshots__/resource-ore-t1.png +0 -0
- package/test/__snapshots__/templates-component.test.ts.snap +0 -5
- package/test/__snapshots__/templates-item-cell.test.ts.snap +0 -9
- package/test/__snapshots__/templates-module.test.ts.snap +0 -17
- package/test/__snapshots__/templates-packed-entity.test.ts.snap +0 -5
- package/test/__snapshots__/templates-resource.test.ts.snap +0 -7
- package/test/base64url.test.ts +0 -33
- package/test/codec.test.ts +0 -34
- package/test/errors.test.ts +0 -24
- package/test/fixtures/cargo-items.ts +0 -122
- package/test/fonts.test.ts +0 -28
- package/test/links-meta.test.ts +0 -43
- package/test/pixel.test.ts +0 -69
- package/test/primitives-category-icon.test.ts +0 -86
- package/test/primitives-compact-row.test.ts +0 -44
- package/test/primitives-domain.test.ts +0 -83
- package/test/primitives-layout.test.ts +0 -56
- package/test/primitives-module-slot.test.ts +0 -88
- package/test/render.test.ts +0 -43
- package/test/sanity.test.ts +0 -6
- package/test/sdk-link.test.ts +0 -19
- package/test/snapshots/.gitkeep +0 -0
- package/test/svg.test.ts +0 -30
- package/test/templates-component.test.ts +0 -36
- package/test/templates-dispatch.test.ts +0 -35
- package/test/templates-item-cell.test.ts +0 -94
- package/test/templates-module.test.ts +0 -63
- package/test/templates-packed-entity.test.ts +0 -47
- package/test/templates-resource.test.ts +0 -71
- package/test/templates-ship-panel.test.ts +0 -91
- package/test/tokens.test.ts +0 -34
- package/tsconfig.json +0 -20
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { resolveItem, getStatDefinitions } from "@shipload/sdk";
|
|
3
|
-
import { renderResource } from "../src/templates/resource.ts";
|
|
4
|
-
import { FIXTURES } from "./fixtures/cargo-items.ts";
|
|
5
|
-
|
|
6
|
-
test("renders Crude Ore with category, mass, and three stat bars", () => {
|
|
7
|
-
const item = FIXTURES.oreT1;
|
|
8
|
-
const resolved = resolveItem(item.item_id, item.stats, item.modules);
|
|
9
|
-
const svg = renderResource(item, resolved);
|
|
10
|
-
expect(svg).toContain("Crude Ore");
|
|
11
|
-
expect(svg).toContain("Ore"); // category label
|
|
12
|
-
expect(svg).toContain("30,000"); // mass
|
|
13
|
-
expect(svg).toContain("STR"); // strength abbreviation
|
|
14
|
-
expect(svg).toContain("TOL");
|
|
15
|
-
expect(svg).toContain("DEN");
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("renders quantity badge when stack > 1", () => {
|
|
19
|
-
const item = FIXTURES.oreT1StackOf50;
|
|
20
|
-
const resolved = resolveItem(item.item_id, item.stats, item.modules);
|
|
21
|
-
const svg = renderResource(item, resolved);
|
|
22
|
-
expect(svg).toContain("×50");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("does not render quantity badge when stack == 1", () => {
|
|
26
|
-
const item = FIXTURES.oreT1;
|
|
27
|
-
const resolved = resolveItem(item.item_id, item.stats, item.modules);
|
|
28
|
-
const svg = renderResource(item, resolved);
|
|
29
|
-
expect(svg).not.toContain("×");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("matches the committed Crude Ore snapshot", async () => {
|
|
33
|
-
const item = FIXTURES.oreT1;
|
|
34
|
-
const resolved = resolveItem(item.item_id, item.stats, item.modules);
|
|
35
|
-
const svg = renderResource(item, resolved);
|
|
36
|
-
expect(svg).toMatchSnapshot("resource-ore-t1.svg");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("matches the committed Dense Gas snapshot", async () => {
|
|
40
|
-
const item = FIXTURES.gasT2;
|
|
41
|
-
const resolved = resolveItem(item.item_id, item.stats, item.modules);
|
|
42
|
-
const svg = renderResource(item, resolved);
|
|
43
|
-
expect(svg).toMatchSnapshot("resource-gas-t2.svg");
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test("renderResource ranges mode shows stat abbreviations with no values", () => {
|
|
47
|
-
const item = FIXTURES.oreT1;
|
|
48
|
-
const resolved = resolveItem(item.item_id);
|
|
49
|
-
const svg = renderResource(item, resolved, { mode: "ranges" });
|
|
50
|
-
const defs = getStatDefinitions(resolved.category!);
|
|
51
|
-
for (const def of defs) {
|
|
52
|
-
expect(svg).toContain(def.abbreviation);
|
|
53
|
-
}
|
|
54
|
-
expect(svg).not.toMatch(/>\d{3}<\/text>/);
|
|
55
|
-
expect(svg).toContain("Category");
|
|
56
|
-
expect(svg).toContain("Mass");
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("renderResource values mode (default) still shows concrete numbers", () => {
|
|
60
|
-
const item = FIXTURES.oreT1;
|
|
61
|
-
const resolved = resolveItem(item.item_id, item.stats);
|
|
62
|
-
const svg = renderResource(item, resolved);
|
|
63
|
-
expect(svg).toMatch(/>\d+<\/text>/);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("renderResource ranges mode matches snapshot", () => {
|
|
67
|
-
const item = FIXTURES.oreT1;
|
|
68
|
-
const resolved = resolveItem(item.item_id);
|
|
69
|
-
const svg = renderResource(item, resolved, { mode: "ranges" });
|
|
70
|
-
expect(svg).toMatchSnapshot("resource-ranges");
|
|
71
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "bun:test";
|
|
2
|
-
import { renderShipPanel } from "../src/templates/ship-panel.ts";
|
|
3
|
-
|
|
4
|
-
test("renderShipPanel with empty slots renders empty module rows", () => {
|
|
5
|
-
const svg = renderShipPanel({
|
|
6
|
-
name: "Ship T1 (Packed)",
|
|
7
|
-
tier: 1,
|
|
8
|
-
attributes: [
|
|
9
|
-
{
|
|
10
|
-
capability: "Hull",
|
|
11
|
-
attributes: [
|
|
12
|
-
{ label: "Mass", value: 100 },
|
|
13
|
-
{ label: "Capacity", value: 5000 },
|
|
14
|
-
],
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
slots: [{ installed: false }, { installed: false }, { installed: false }],
|
|
18
|
-
});
|
|
19
|
-
expect(svg).toContain("Ship T1 (Packed)");
|
|
20
|
-
expect(svg).toContain("HULL");
|
|
21
|
-
expect(svg).toContain("Mass");
|
|
22
|
-
expect(svg).toContain("Capacity");
|
|
23
|
-
expect((svg.match(/Empty module/g) ?? []).length).toBe(3);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("renderShipPanel with installed slots + string descriptions", () => {
|
|
27
|
-
const svg = renderShipPanel({
|
|
28
|
-
name: "Ship T1 (Packed)",
|
|
29
|
-
tier: 1,
|
|
30
|
-
attributes: [
|
|
31
|
-
{
|
|
32
|
-
capability: "Hull",
|
|
33
|
-
attributes: [{ label: "Mass", value: 100 }],
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
slots: [
|
|
37
|
-
{ name: "Engine", installed: true, description: "generates 500 thrust for travel" },
|
|
38
|
-
{ name: "Generator", installed: true, description: "holds 1000 energy" },
|
|
39
|
-
],
|
|
40
|
-
});
|
|
41
|
-
expect(svg).toContain("Engine:");
|
|
42
|
-
expect(svg).toContain("generates 500 thrust");
|
|
43
|
-
expect(svg).toContain("Generator:");
|
|
44
|
-
expect(svg).toContain("holds 1000 energy");
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("renderShipPanel with TextSpan[] descriptions preserves highlights", () => {
|
|
48
|
-
const svg = renderShipPanel({
|
|
49
|
-
name: "Ship T1 (Packed)",
|
|
50
|
-
tier: 1,
|
|
51
|
-
attributes: [
|
|
52
|
-
{
|
|
53
|
-
capability: "Hull",
|
|
54
|
-
attributes: [{ label: "Mass", value: 100 }],
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
slots: [
|
|
58
|
-
{
|
|
59
|
-
name: "Engine",
|
|
60
|
-
installed: true,
|
|
61
|
-
description: [
|
|
62
|
-
{ text: "generates " },
|
|
63
|
-
{ text: "700", highlight: true },
|
|
64
|
-
{ text: " thrust for travel" },
|
|
65
|
-
],
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
});
|
|
69
|
-
expect(svg).toContain(">700<");
|
|
70
|
-
expect(svg).toContain("generates");
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test("renderShipPanel mixed slots (installed + empty)", () => {
|
|
74
|
-
const svg = renderShipPanel({
|
|
75
|
-
name: "Ship T1 (Packed)",
|
|
76
|
-
tier: 1,
|
|
77
|
-
attributes: [
|
|
78
|
-
{
|
|
79
|
-
capability: "Hull",
|
|
80
|
-
attributes: [{ label: "Mass", value: 100 }],
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
slots: [
|
|
84
|
-
{ name: "Engine", installed: true, description: "generates 500 thrust" },
|
|
85
|
-
{ installed: false },
|
|
86
|
-
{ installed: false },
|
|
87
|
-
],
|
|
88
|
-
});
|
|
89
|
-
expect(svg).toContain("Engine:");
|
|
90
|
-
expect((svg.match(/Empty module/g) ?? []).length).toBe(2);
|
|
91
|
-
});
|
package/test/tokens.test.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { tierColors as sdkTierColors } from "@shipload/sdk";
|
|
3
|
-
import { tokens } from "../src/tokens/index.ts";
|
|
4
|
-
|
|
5
|
-
test("colors include all resource categories", () => {
|
|
6
|
-
for (const cat of ["ore", "crystal", "gas", "regolith", "biomass"]) {
|
|
7
|
-
expect(tokens.colors.category).toHaveProperty(cat);
|
|
8
|
-
expect(tokens.colors.category[cat as keyof typeof tokens.colors.category]).toMatch(
|
|
9
|
-
/^#[0-9a-f]{6}$/i,
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test("colors.tier is sourced from SDK tierColors", () => {
|
|
15
|
-
expect(tokens.colors.tier).toEqual(sdkTierColors);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("colors include all tiers t1..t5 with SDK values", () => {
|
|
19
|
-
expect(tokens.colors.tier.t1).toBe("#8b8b8b");
|
|
20
|
-
expect(tokens.colors.tier.t2).toBe("#4ade80");
|
|
21
|
-
expect(tokens.colors.tier.t3).toBe("#818cf8");
|
|
22
|
-
expect(tokens.colors.tier.t4).toBe("#c084fc");
|
|
23
|
-
expect(tokens.colors.tier.t5).toBe("#fbbf24");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("typography names three font stacks", () => {
|
|
27
|
-
expect(tokens.typography.display).toContain("Orbitron");
|
|
28
|
-
expect(tokens.typography.sans).toContain("Inter");
|
|
29
|
-
expect(tokens.typography.mono).toContain("JetBrains Mono");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("spacing has a default panel width", () => {
|
|
33
|
-
expect(tokens.spacing.panelWidth).toBe(280);
|
|
34
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"lib": ["ES2022", "DOM"],
|
|
7
|
-
"strict": true,
|
|
8
|
-
"noUncheckedIndexedAccess": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"noEmit": true,
|
|
12
|
-
"isolatedModules": true,
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"allowImportingTsExtensions": true,
|
|
15
|
-
"verbatimModuleSyntax": false,
|
|
16
|
-
"experimentalDecorators": true,
|
|
17
|
-
"types": ["bun-types"]
|
|
18
|
-
},
|
|
19
|
-
"include": ["src", "test", "scripts"]
|
|
20
|
-
}
|