@aethervtt/shard-cards 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Patrick Dias
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # Temporary Holding Version
1
+ # @aethervtt/shard-cards
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Part of [Shard](https://github.com/aethervtt/shard), a WebGPU-first 2D/3D game engine in TypeScript. See the repository for documentation.
@@ -0,0 +1,35 @@
1
+ export interface CardEntry {
2
+ instanceId: string;
3
+ definition: string;
4
+ faceDown?: boolean;
5
+ }
6
+ /** Logical cards have no entity, texture or per-frame work until a host exposes them. */
7
+ export declare class CardCollection {
8
+ readonly id: string;
9
+ private readonly entries;
10
+ private readonly ids;
11
+ version: number;
12
+ constructor(id: string, entries?: readonly CardEntry[]);
13
+ get count(): number;
14
+ at(index: number): Readonly<CardEntry> | undefined;
15
+ insert(entry: CardEntry, index?: number): void;
16
+ remove(index: number): CardEntry;
17
+ move(from: number, to: number): void;
18
+ draw(count: number, destination: CardCollection): void;
19
+ shuffle(seed: number): void;
20
+ snapshot(): {
21
+ id: string;
22
+ entries: CardEntry[];
23
+ };
24
+ private checkIndex;
25
+ }
26
+ export interface CardLayout {
27
+ kind: 'stack' | 'fan' | 'grid';
28
+ spacing?: number;
29
+ columns?: number;
30
+ angle?: number;
31
+ width?: number;
32
+ height?: number;
33
+ }
34
+ /** Writes xyz, then rotation about Z in radians. No allocations. */
35
+ export declare function cardPose(layout: CardLayout, index: number, count: number, out: Float64Array): void;
@@ -0,0 +1,114 @@
1
+ import { Rng, ShardError } from "@aethervtt/shard-core";
2
+ class CardCollection {
3
+ id;
4
+ entries = [];
5
+ ids = /* @__PURE__ */ new Set();
6
+ version = 0;
7
+ constructor(id, entries = []) {
8
+ this.id = id;
9
+ for (const entry of entries) this.insert(entry);
10
+ }
11
+ get count() {
12
+ return this.entries.length;
13
+ }
14
+ at(index) {
15
+ return this.entries[index];
16
+ }
17
+ insert(entry, index = this.count) {
18
+ if (!entry.instanceId || this.ids.has(entry.instanceId)) {
19
+ throw new ShardError("cards/duplicate-id", `Duplicate or empty card ID: ${entry.instanceId}`);
20
+ }
21
+ this.checkIndex(index, true);
22
+ this.entries.splice(index, 0, { ...entry });
23
+ this.ids.add(entry.instanceId);
24
+ this.version++;
25
+ }
26
+ remove(index) {
27
+ this.checkIndex(index);
28
+ const entry = this.entries.splice(index, 1)[0];
29
+ this.ids.delete(entry.instanceId);
30
+ this.version++;
31
+ return entry;
32
+ }
33
+ move(from, to) {
34
+ this.checkIndex(from);
35
+ this.checkIndex(to);
36
+ const entry = this.entries.splice(from, 1)[0];
37
+ this.entries.splice(to, 0, entry);
38
+ this.version++;
39
+ }
40
+ draw(count, destination) {
41
+ if (destination === this || !Number.isInteger(count) || count < 0 || count > this.count) {
42
+ throw new ShardError(
43
+ "cards/invalid-transfer",
44
+ "Draw needs a distinct destination and an available card count"
45
+ );
46
+ }
47
+ for (let i = 0; i < count; i++) {
48
+ if (destination.ids.has(this.entries[i].instanceId)) {
49
+ throw new ShardError(
50
+ "cards/duplicate-id",
51
+ `Destination already contains ${this.entries[i].instanceId}`
52
+ );
53
+ }
54
+ }
55
+ const moved = this.entries.splice(0, count);
56
+ for (const entry of moved) {
57
+ this.ids.delete(entry.instanceId);
58
+ destination.ids.add(entry.instanceId);
59
+ destination.entries.push(entry);
60
+ }
61
+ this.version++;
62
+ destination.version++;
63
+ }
64
+ shuffle(seed) {
65
+ const rng = new Rng(seed);
66
+ for (let i = this.count - 1; i > 0; i--) {
67
+ const range = i + 1;
68
+ const limit = Math.floor(4294967296 / range) * range;
69
+ let n;
70
+ do {
71
+ n = rng.nextU32();
72
+ } while (n >= limit);
73
+ const j = n % range;
74
+ const a = this.entries[i];
75
+ this.entries[i] = this.entries[j];
76
+ this.entries[j] = a;
77
+ }
78
+ this.version++;
79
+ }
80
+ snapshot() {
81
+ return { id: this.id, entries: this.entries.map((entry) => ({ ...entry })) };
82
+ }
83
+ checkIndex(index, end = false) {
84
+ if (!Number.isInteger(index) || index < 0 || index >= this.count + Number(end)) {
85
+ throw new ShardError("cards/invalid-index", `Index ${index} is outside ${this.id}`);
86
+ }
87
+ }
88
+ }
89
+ function cardPose(layout, index, count, out) {
90
+ const width = layout.width ?? 0.063;
91
+ const height = layout.height ?? 0.088;
92
+ const spacing = layout.spacing ?? 8e-3;
93
+ out[0] = out[1] = out[2] = out[3] = 0;
94
+ if (layout.kind === "stack") {
95
+ out[2] = index * (layout.spacing ?? 35e-5);
96
+ return;
97
+ }
98
+ if (layout.kind === "grid") {
99
+ const cols = Math.max(1, Math.floor(layout.columns ?? 5));
100
+ out[0] = (index % cols - (Math.min(cols, count) - 1) / 2) * (width + spacing);
101
+ out[1] = -Math.floor(index / cols) * (height + spacing);
102
+ return;
103
+ }
104
+ const a = (count < 2 ? 0 : index / (count - 1) - 0.5) * (layout.angle ?? 45) * Math.PI / 180;
105
+ const radius = Math.max(height, count * spacing);
106
+ out[0] = Math.sin(a) * radius;
107
+ out[1] = (Math.cos(a) - 1) * radius;
108
+ out[2] = index * 4e-4;
109
+ out[3] = -a;
110
+ }
111
+ export {
112
+ CardCollection,
113
+ cardPose
114
+ };
@@ -0,0 +1,75 @@
1
+ import { type Infer } from '@aethervtt/shard-core';
2
+ /** Data assets and runtime definitions use the same schema. */
3
+ export declare const CardDefinition: import("@aethervtt/shard-assets").DataType<{
4
+ readonly label: import("@aethervtt/shard-core").FieldType<string, "object">;
5
+ readonly size: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Vec2, "f32">;
6
+ readonly cornerRadius: import("@aethervtt/shard-core").FieldType<number, "f32">;
7
+ readonly thickness: import("@aethervtt/shard-core").FieldType<number, "f32">;
8
+ readonly edgeColor: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Color, "f32">;
9
+ readonly front: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").InferFields<{
10
+ art: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").AssetRef<"Texture"> | null, "object">;
11
+ fit: import("@aethervtt/shard-core").FieldType<"contain" | "cover" | "stretch", "u8">;
12
+ background: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Color, "f32">;
13
+ uvRect: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Vec4, "f32">;
14
+ rotation: import("@aethervtt/shard-core").FieldType<number, "u8">;
15
+ finishes: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").InferFields<{
16
+ family: import("@aethervtt/shard-core").FieldType<string, "object">;
17
+ strength: import("@aethervtt/shard-core").FieldType<number, "f32">;
18
+ mask: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").InferFields<{
19
+ texture: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").AssetRef<"Texture"> | null, "object">;
20
+ channel: import("@aethervtt/shard-core").FieldType<"a" | "b" | "g" | "r", "u8">;
21
+ space: import("@aethervtt/shard-core").FieldType<"art" | "face", "u8">;
22
+ invert: import("@aethervtt/shard-core").FieldType<boolean, "u8">;
23
+ scale: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Vec2, "f32">;
24
+ offset: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Vec2, "f32">;
25
+ }>, "object">;
26
+ parameters: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").JsonValue, "object">;
27
+ }>[], "object">;
28
+ }>, "object">;
29
+ readonly back: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").InferFields<{
30
+ art: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").AssetRef<"Texture"> | null, "object">;
31
+ fit: import("@aethervtt/shard-core").FieldType<"contain" | "cover" | "stretch", "u8">;
32
+ background: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Color, "f32">;
33
+ uvRect: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Vec4, "f32">;
34
+ rotation: import("@aethervtt/shard-core").FieldType<number, "u8">;
35
+ finishes: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").InferFields<{
36
+ family: import("@aethervtt/shard-core").FieldType<string, "object">;
37
+ strength: import("@aethervtt/shard-core").FieldType<number, "f32">;
38
+ mask: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").InferFields<{
39
+ texture: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").AssetRef<"Texture"> | null, "object">;
40
+ channel: import("@aethervtt/shard-core").FieldType<"a" | "b" | "g" | "r", "u8">;
41
+ space: import("@aethervtt/shard-core").FieldType<"art" | "face", "u8">;
42
+ invert: import("@aethervtt/shard-core").FieldType<boolean, "u8">;
43
+ scale: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Vec2, "f32">;
44
+ offset: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Vec2, "f32">;
45
+ }>, "object">;
46
+ parameters: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").JsonValue, "object">;
47
+ }>[], "object">;
48
+ }>, "object">;
49
+ }, "cards/CardDefinition">;
50
+ export type CardDefinitionValue = Infer<typeof CardDefinition>;
51
+ export type CardFace = CardDefinitionValue['front'];
52
+ export type CardFinishLayer = CardFace['finishes'][number];
53
+ export declare const CARD_SIZES: {
54
+ readonly poker: readonly [0.063, 0.088];
55
+ readonly bridge: readonly [0.057, 0.088];
56
+ readonly tarot: readonly [0.07, 0.12];
57
+ };
58
+ export declare function cardDefinition(json: unknown): CardDefinitionValue;
59
+ export declare const Card: import("@aethervtt/shard-core").ComponentDef<{
60
+ readonly instanceId: import("@aethervtt/shard-core").FieldType<string, "object">;
61
+ readonly definition: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").AssetRef<"cards/CardDefinition"> | null, "object">;
62
+ readonly seed: import("@aethervtt/shard-core").FieldType<number, "u32">;
63
+ readonly finishStrength: import("@aethervtt/shard-core").FieldType<number, "f32">;
64
+ readonly enabled: import("@aethervtt/shard-core").FieldType<boolean, "u8">;
65
+ }>;
66
+ export declare const CardTilt: import("@aethervtt/shard-core").ComponentDef<{
67
+ readonly enabled: import("@aethervtt/shard-core").FieldType<boolean, "u8">;
68
+ readonly maxDegrees: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").Vec2, "f32">;
69
+ readonly responseSeconds: import("@aethervtt/shard-core").FieldType<number, "f32">;
70
+ readonly returnSeconds: import("@aethervtt/shard-core").FieldType<number, "f32">;
71
+ }>;
72
+ export declare const CardInteraction: import("@aethervtt/shard-core").ComponentDef<{
73
+ readonly enabled: import("@aethervtt/shard-core").FieldType<boolean, "u8">;
74
+ readonly draggable: import("@aethervtt/shard-core").FieldType<boolean, "u8">;
75
+ }>;
@@ -0,0 +1,87 @@
1
+ import { defineDataType } from "@aethervtt/shard-assets";
2
+ import { defineComponent, ShardError, t } from "@aethervtt/shard-core";
3
+ const mask = t.struct({
4
+ texture: t.handle("Texture"),
5
+ channel: t.enum(["r", "g", "b", "a"]),
6
+ space: t.enum(["face", "art"]),
7
+ invert: t.bool(),
8
+ scale: t.vec2({ default: [1, 1] }),
9
+ offset: t.vec2()
10
+ });
11
+ const layer = t.struct({
12
+ family: t.string({ default: "cards/rainbow" }),
13
+ strength: t.f32({ default: 0.65, min: 0, max: 1 }),
14
+ mask,
15
+ parameters: t.json({ default: {} })
16
+ });
17
+ const face = t.struct({
18
+ art: t.handle("Texture"),
19
+ fit: t.enum(["contain", "cover", "stretch"]),
20
+ background: t.color({ default: [0.025, 0.03, 0.045, 1] }),
21
+ uvRect: t.vec4({ default: [0, 0, 1, 1] }),
22
+ rotation: t.u8({ min: 0, max: 3 }),
23
+ finishes: t.list(layer)
24
+ });
25
+ const CardDefinition = defineDataType(
26
+ "cards/CardDefinition",
27
+ {
28
+ label: t.string(),
29
+ size: t.vec2({ default: [0.063, 0.088], unit: "m" }),
30
+ cornerRadius: t.f32({ default: 3e-3, min: 0, unit: "m" }),
31
+ thickness: t.f32({ default: 3e-4, min: 0, unit: "m" }),
32
+ edgeColor: t.color({ default: [0.26, 0.28, 0.34, 1] }),
33
+ front: face,
34
+ back: face
35
+ },
36
+ {
37
+ extension: "card",
38
+ description: "Two-sided printed card with independently masked foil layers."
39
+ }
40
+ );
41
+ const CARD_SIZES = {
42
+ poker: [0.063, 0.088],
43
+ bridge: [0.057, 0.088],
44
+ tarot: [0.07, 0.12]
45
+ };
46
+ function cardDefinition(json) {
47
+ const value = CardDefinition.deserialize(json);
48
+ if (value.size[0] <= 0 || value.size[1] <= 0 || value.cornerRadius > Math.min(value.size[0], value.size[1]) / 2) {
49
+ throw new ShardError(
50
+ "cards/invalid-size",
51
+ "Card dimensions must be positive and fit the corner radius",
52
+ {
53
+ path: "/size",
54
+ hint: "Use dimensions in metres; poker is [0.063, 0.088]."
55
+ }
56
+ );
57
+ }
58
+ if (value.front.finishes.length > 4 || value.back.finishes.length > 4) {
59
+ throw new ShardError("cards/layer-limit", "Each face supports up to four independent finishes");
60
+ }
61
+ return value;
62
+ }
63
+ const Card = defineComponent("cards/Card", {
64
+ instanceId: t.string(),
65
+ definition: t.handle("cards/CardDefinition"),
66
+ seed: t.u32(),
67
+ finishStrength: t.f32({ default: 1, min: 0, max: 2 }),
68
+ enabled: t.bool({ default: true })
69
+ });
70
+ const CardTilt = defineComponent("cards/Tilt", {
71
+ enabled: t.bool({ default: false }),
72
+ maxDegrees: t.vec2({ default: [8, 8] }),
73
+ responseSeconds: t.f32({ default: 0.12, min: 0 }),
74
+ returnSeconds: t.f32({ default: 0.18, min: 0 })
75
+ });
76
+ const CardInteraction = defineComponent("cards/Interaction", {
77
+ enabled: t.bool({ default: true }),
78
+ draggable: t.bool({ default: false })
79
+ });
80
+ export {
81
+ CARD_SIZES,
82
+ Card,
83
+ CardDefinition,
84
+ CardInteraction,
85
+ CardTilt,
86
+ cardDefinition
87
+ };
@@ -0,0 +1,27 @@
1
+ import { defineSchema, type Fields } from '@aethervtt/shard-core';
2
+ export interface CardFinishOptions {
3
+ /** Up to four scalar parameters, packed from this schema in declaration order. */
4
+ fields?: Fields;
5
+ /** WESL function body. Inputs: ctx (CardFinishContext), base (linear RGB). Return linear RGB reflectance (clamped to [0, 1] in PBR). */
6
+ surface: string;
7
+ /** Optional WESL body: ctx and current (metallic, roughness); return vec2f.
8
+ * Coverage blends this response alongside surface color. Never emits light.
9
+ * Default foil response is metallic 0.35, roughness 0.28. Unlit ignores it.
10
+ */
11
+ response?: string;
12
+ baseline?: 'same' | 'unsupported';
13
+ animated?: false | {
14
+ fps: number;
15
+ };
16
+ description?: string;
17
+ }
18
+ export interface CardFinish {
19
+ readonly name: string;
20
+ readonly options: CardFinishOptions;
21
+ readonly schema: ReturnType<typeof defineSchema>;
22
+ readonly keys: readonly string[];
23
+ }
24
+ /** No global registration: each cardsPlugin owns its finish library. */
25
+ export declare function defineCardFinish(name: string, options: CardFinishOptions): CardFinish;
26
+ /** Constructed when the plugin is installed; importing cards registers no shader/material. */
27
+ export declare function builtinCardFinishes(): CardFinish[];
@@ -0,0 +1,79 @@
1
+ import { defineSchema, ShardError, t } from "@aethervtt/shard-core";
2
+ function defineCardFinish(name, options) {
3
+ if (!/^[\w-]+\/[\w-]+$/.test(name) || !options.surface.trim()) {
4
+ throw new ShardError(
5
+ "cards/invalid-finish",
6
+ "A finish needs a namespaced name and a WESL surface body"
7
+ );
8
+ }
9
+ const fields = options.fields ?? {};
10
+ if (options.animated && (!Number.isFinite(options.animated.fps) || options.animated.fps <= 0 || options.animated.fps > 60)) {
11
+ throw new ShardError(
12
+ "cards/finish-animation",
13
+ "Animated finishes must request a frame rate between 0 and 60 FPS, exclusive of zero"
14
+ );
15
+ }
16
+ const keys = Object.keys(fields);
17
+ if (keys.length > 4 || keys.some((key) => fields[key].kind !== "f32")) {
18
+ throw new ShardError("cards/finish-fields", "A finish accepts up to four f32 parameters");
19
+ }
20
+ const [namespace, local] = name.split("/");
21
+ const schemaName = `${namespace}/${local[0].toUpperCase()}${local.slice(1).replace(/-([a-z])/g, (_, c) => c.toUpperCase())}Params`;
22
+ return { name, options, keys, schema: defineSchema(schemaName, fields) };
23
+ }
24
+ function builtinCardFinishes() {
25
+ return [
26
+ defineCardFinish("cards/metallic", {
27
+ fields: {
28
+ roughness: t.f32({ default: 0.3, min: 0.05, max: 1 }),
29
+ warmth: t.f32({ default: 0.6 })
30
+ },
31
+ response: "return vec2f(0.75, ctx.params.x);",
32
+ surface: `
33
+ let shine = pow(max(0.0, dot(ctx.normal, normalize(ctx.view + ctx.light))), mix(110.0, 9.0, ctx.params.x));
34
+ let tint = mix(vec3f(0.7, 0.85, 1.0), vec3f(1.0, 0.65, 0.18), ctx.params.y);
35
+ return base * (0.65 + 0.35 * ctx.facing) + tint * (shine * 1.2 + ctx.grazing * 0.25);`
36
+ }),
37
+ defineCardFinish("cards/rainbow", {
38
+ fields: {
39
+ scale: t.f32({ default: 2.5 }),
40
+ phase: t.f32(),
41
+ roughness: t.f32({ default: 0.25 })
42
+ },
43
+ response: "return vec2f(0.35, ctx.params.z);",
44
+ surface: `
45
+ let p = ctx.uv.x * 0.65 + ctx.uv.y + ctx.shift.x * 0.7 + ctx.shift.y * 0.4;
46
+ let rainbow = card_spectrum(p * ctx.params.x + ctx.params.y);
47
+ return base * (0.82 + rainbow * 0.32) + rainbow * (0.08 + ctx.glare * 0.7 + ctx.grazing * 0.2);`
48
+ }),
49
+ defineCardFinish("cards/hologram", {
50
+ fields: { roughness: t.f32({ default: 0.25 }), scale: t.f32({ default: 3 }), phase: t.f32() },
51
+ response: "return vec2f(0.4, ctx.params.x);",
52
+ surface: `
53
+ let wave = sin((ctx.uv.x * 1.3 + ctx.uv.y * 0.7) * 30.0 + ctx.shift.x * 8.0);
54
+ let hue = dot(ctx.uv, vec2f(0.4, 1.0)) * ctx.params.y + ctx.shift.x * 0.8 - ctx.shift.y * 0.5;
55
+ let foil = card_spectrum(hue + ctx.params.z + wave * 0.09);
56
+ return base * (0.72 + foil * 0.45) + foil * (0.14 + ctx.glare * 0.9);`
57
+ }),
58
+ defineCardFinish("cards/sparkle", {
59
+ fields: {
60
+ density: t.f32({ default: 120, min: 1, max: 300 }),
61
+ phase: t.f32(),
62
+ intensity: t.f32({ default: 1 })
63
+ },
64
+ surface: `
65
+ let cell = floor(ctx.uv * ctx.params.x);
66
+ let rnd = card_hash(cell + vec2f(ctx.seed));
67
+ let pos = fract(ctx.uv * ctx.params.x) - vec2f(0.5);
68
+ let pulse = pow(max(0.0, sin(rnd * 120.0 + dot(ctx.shift, vec2f(12.0, 9.0)) + ctx.params.y)), 18.0);
69
+ let star = exp(-length(pos) * 18.0) + exp(-abs(pos.x) * 65.0 - abs(pos.y) * 9.0) * 0.4;
70
+ let filtered = 1.0 - smoothstep(0.5, 1.5, max(ctx.footprint.x, ctx.footprint.y) * ctx.params.x);
71
+ let glitter = star * pulse * filtered * ctx.params.z * 2.5;
72
+ return base + mix(vec3f(1.0), card_spectrum(rnd + ctx.shift.x), 0.55) * glitter;`
73
+ })
74
+ ];
75
+ }
76
+ export {
77
+ builtinCardFinishes,
78
+ defineCardFinish
79
+ };
@@ -0,0 +1,8 @@
1
+ export { CardCollection, type CardEntry, type CardLayout, cardPose } from './collection.js';
2
+ export { CARD_SIZES, Card, CardDefinition, type CardDefinitionValue, type CardFace, type CardFinishLayer, CardInteraction, CardTilt, cardDefinition, } from './definition.js';
3
+ export { builtinCardFinishes, type CardFinish, type CardFinishOptions, defineCardFinish, } from './finishes.js';
4
+ export { cardMesh } from './mesh.js';
5
+ export { CardAutomaticMotion, type CardAutomaticMotionValue, sampleCardMotion } from './motion.js';
6
+ export { type CardsPluginOptions, cardsPlugin } from './plugin.js';
7
+ export { CardHandle, type CardHit, type CardPose, Cards, CardTableState, cardTiltCoordinates, createCardHit, hitCards, } from './table.js';
8
+ export { type CardImage, type CardTexturePage, prepareCardTextures } from './textures.js';
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
1
+ import { CardCollection, cardPose } from "./collection.js";
2
+ import {
3
+ CARD_SIZES,
4
+ Card,
5
+ CardDefinition,
6
+ CardInteraction,
7
+ CardTilt,
8
+ cardDefinition
9
+ } from "./definition.js";
10
+ import {
11
+ builtinCardFinishes,
12
+ defineCardFinish
13
+ } from "./finishes.js";
14
+ import { cardMesh } from "./mesh.js";
15
+ import { CardAutomaticMotion, sampleCardMotion } from "./motion.js";
16
+ import { cardsPlugin } from "./plugin.js";
17
+ import {
18
+ CardHandle,
19
+ Cards,
20
+ CardTableState,
21
+ cardTiltCoordinates,
22
+ createCardHit,
23
+ hitCards
24
+ } from "./table.js";
25
+ import { prepareCardTextures } from "./textures.js";
26
+ export {
27
+ CARD_SIZES,
28
+ Card,
29
+ CardAutomaticMotion,
30
+ CardCollection,
31
+ CardDefinition,
32
+ CardHandle,
33
+ CardInteraction,
34
+ CardTableState,
35
+ CardTilt,
36
+ Cards,
37
+ builtinCardFinishes,
38
+ cardDefinition,
39
+ cardMesh,
40
+ cardPose,
41
+ cardTiltCoordinates,
42
+ cardsPlugin,
43
+ createCardHit,
44
+ defineCardFinish,
45
+ hitCards,
46
+ prepareCardTextures,
47
+ sampleCardMotion
48
+ };
package/dist/mesh.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { Mesh } from '@aethervtt/shard-mesh';
2
+ import type { CardDefinitionValue } from './definition.js';
3
+ /** True rounded geometry: picks, shadows and color share the same silhouette. */
4
+ export declare function cardMesh(def: CardDefinitionValue, segments?: number): Mesh;
package/dist/mesh.js ADDED
@@ -0,0 +1,55 @@
1
+ import { Mesh } from "@aethervtt/shard-mesh";
2
+ function cardMesh(def, segments = 12) {
3
+ const w = def.size[0] / 2, h = def.size[1] / 2, r = def.cornerRadius;
4
+ const n = 4 * (segments + 1);
5
+ const ring = [];
6
+ for (let corner = 0; corner < 4; corner++) {
7
+ const cx = (corner === 0 || corner === 3 ? 1 : -1) * (w - r);
8
+ const cy = (corner < 2 ? 1 : -1) * (h - r);
9
+ for (let j = 0; j <= segments; j++) {
10
+ const a = (corner + j / segments) * Math.PI / 2;
11
+ ring.push(cx + Math.cos(a) * r, cy + Math.sin(a) * r);
12
+ }
13
+ }
14
+ const p = [], normals = [], uv = [], uv1 = [];
15
+ const indices = [];
16
+ const vertex = (x, y, z, nx, ny, nz, side) => {
17
+ const id = p.length / 3;
18
+ p.push(x, y, z);
19
+ normals.push(nx, ny, nz);
20
+ uv.push(side === 1 ? 0.5 - x / (2 * w) : x / (2 * w) + 0.5, 0.5 - y / (2 * h));
21
+ uv1.push(side, 0);
22
+ return id;
23
+ };
24
+ for (let side = 0; side < 2; side++) {
25
+ const z = (side === 0 ? 1 : -1) * def.thickness / 2;
26
+ const c = vertex(0, 0, z, 0, 0, side === 0 ? 1 : -1, side);
27
+ for (let i = 0; i < n; i++)
28
+ vertex(ring[i * 2], ring[i * 2 + 1], z, 0, 0, side === 0 ? 1 : -1, side);
29
+ for (let i = 0; i < n; i++) {
30
+ const a = c + 1 + i, b = c + 1 + (i + 1) % n;
31
+ indices.push(c, side === 0 ? a : b, side === 0 ? b : a);
32
+ }
33
+ }
34
+ if (def.thickness > 0)
35
+ for (let i = 0; i < n; i++) {
36
+ const j = (i + 1) % n;
37
+ const ax = ring[i * 2], ay = ring[i * 2 + 1], bx = ring[j * 2], by = ring[j * 2 + 1];
38
+ const dx = bx - ax, dy = by - ay, len = Math.sqrt(dx * dx + dy * dy) || 1;
39
+ const a = vertex(ax, ay, -def.thickness / 2, dy / len, -dx / len, 0, 2);
40
+ vertex(bx, by, -def.thickness / 2, dy / len, -dx / len, 0, 2);
41
+ vertex(bx, by, def.thickness / 2, dy / len, -dx / len, 0, 2);
42
+ vertex(ax, ay, def.thickness / 2, dy / len, -dx / len, 0, 2);
43
+ indices.push(a, a + 1, a + 2, a, a + 2, a + 3);
44
+ }
45
+ return Mesh.create({
46
+ positions: new Float32Array(p),
47
+ normals: new Float32Array(normals),
48
+ uvs: new Float32Array(uv),
49
+ uvs1: new Float32Array(uv1),
50
+ indices: new Uint16Array(indices)
51
+ });
52
+ }
53
+ export {
54
+ cardMesh
55
+ };
@@ -0,0 +1,12 @@
1
+ import { type Infer } from '@aethervtt/shard-core';
2
+ export declare const CardAutomaticMotion: import("@aethervtt/shard-core").ComponentDef<{
3
+ readonly enabled: import("@aethervtt/shard-core").FieldType<boolean, "u8">;
4
+ readonly tilt: import("@aethervtt/shard-core").FieldType<boolean, "u8">;
5
+ readonly seconds: import("@aethervtt/shard-core").FieldType<number, "f32">;
6
+ readonly range: import("@aethervtt/shard-core").FieldType<number, "f32">;
7
+ readonly phase: import("@aethervtt/shard-core").FieldType<number, "f32">;
8
+ }>;
9
+ export type CardAutomaticMotionValue = Infer<typeof CardAutomaticMotion>;
10
+ /** Same integer waypoint generator and quintic interpolation as CARD_MOTION_WGSL. */
11
+ export declare function sampleCardMotion(time: number, seconds: number, range: number, phase: number, out: Float32Array): void;
12
+ export declare const CARD_MOTION_WGSL = "\nfn card_motion_point(step: u32) -> vec2f {\n let x = ((step & 65535u) * 25173u + 13849u) & 65535u;\n let y = (x * 25173u + 13849u) & 65535u;\n return vec2f(f32(x), f32(y)) / 32767.5 - vec2f(1.0);\n}\nfn card_motion(time: f32, seconds: f32, radius: f32, phase: f32) -> vec2f {\n let position = time / max(seconds, 0.25) + phase;\n let step = u32(floor(position));\n let t = fract(position);\n let ease = t * t * t * (t * (t * 6.0 - 15.0) + 10.0);\n return mix(card_motion_point(step), card_motion_point(step + 1u), ease) * radius;\n}\n";
package/dist/motion.js ADDED
@@ -0,0 +1,40 @@
1
+ import { defineSchema, t } from "@aethervtt/shard-core";
2
+ const CardAutomaticMotion = defineSchema("cards/AutomaticMotion", {
3
+ enabled: t.bool(),
4
+ tilt: t.bool(),
5
+ seconds: t.f32({ default: 4, min: 0.25, max: 60 }),
6
+ range: t.f32({ default: 0.85, min: 0, max: 1 }),
7
+ phase: t.f32({ min: 0, max: 1024 })
8
+ });
9
+ function sampleCardMotion(time, seconds, range, phase, out) {
10
+ const position = time / seconds + phase;
11
+ const step = Math.floor(position);
12
+ const t2 = position - step;
13
+ const ease = t2 * t2 * t2 * (t2 * (t2 * 6 - 15) + 10);
14
+ let a = Math.imul(step & 65535, 25173) + 13849 & 65535;
15
+ let b = Math.imul(step + 1 & 65535, 25173) + 13849 & 65535;
16
+ const ax = a / 32767.5 - 1, bx = b / 32767.5 - 1;
17
+ a = Math.imul(a, 25173) + 13849 & 65535;
18
+ b = Math.imul(b, 25173) + 13849 & 65535;
19
+ out[0] = (ax + (bx - ax) * ease) * range;
20
+ out[1] = (a / 32767.5 - 1 + (b - a) / 32767.5 * ease) * range;
21
+ }
22
+ const CARD_MOTION_WGSL = `
23
+ fn card_motion_point(step: u32) -> vec2f {
24
+ let x = ((step & 65535u) * 25173u + 13849u) & 65535u;
25
+ let y = (x * 25173u + 13849u) & 65535u;
26
+ return vec2f(f32(x), f32(y)) / 32767.5 - vec2f(1.0);
27
+ }
28
+ fn card_motion(time: f32, seconds: f32, radius: f32, phase: f32) -> vec2f {
29
+ let position = time / max(seconds, 0.25) + phase;
30
+ let step = u32(floor(position));
31
+ let t = fract(position);
32
+ let ease = t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
33
+ return mix(card_motion_point(step), card_motion_point(step + 1u), ease) * radius;
34
+ }
35
+ `;
36
+ export {
37
+ CARD_MOTION_WGSL,
38
+ CardAutomaticMotion,
39
+ sampleCardMotion
40
+ };
@@ -0,0 +1,13 @@
1
+ import { type Plugin } from '@aethervtt/shard-runtime';
2
+ import { type CardFinish } from './finishes.js';
3
+ import type { CardTexturePage } from './textures.js';
4
+ export interface CardsPluginOptions {
5
+ art: CardTexturePage;
6
+ masks: CardTexturePage;
7
+ /** Scene-lit PBR by default; unlit is an explicit presentation mode. */
8
+ lighting?: 'pbr' | 'unlit';
9
+ finishes?: readonly CardFinish[];
10
+ capacity?: number;
11
+ textureBudgetMiB?: number;
12
+ }
13
+ export declare function cardsPlugin(options: CardsPluginOptions): Plugin;