ultimatedarktowerdisplay 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.
- package/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/README.md +212 -0
- package/dist/TowerDisplay.d.ts +23 -0
- package/dist/TowerStateReadout.d.ts +33 -0
- package/dist/index.cjs.js +186 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.esm.js +275 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/styles.d.ts +10 -0
- package/dist/types.d.ts +15 -0
- package/package.json +79 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-03-22
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Initial release
|
|
14
|
+
- `TowerDisplay` wrapper class with options-based constructor
|
|
15
|
+
- `TowerStateReadout` core DOM renderer
|
|
16
|
+
- LED grid rendering with per-light effect labels (on, off, breathe, flicker, etc.)
|
|
17
|
+
- Drum position and calibration display with glyph lookup
|
|
18
|
+
- Audio sample name resolution via `TOWER_AUDIO_LIBRARY`
|
|
19
|
+
- Skull drop detection (beam count delta between consecutive states)
|
|
20
|
+
- LED sequence override labels via `TOWER_LIGHT_SEQUENCES`
|
|
21
|
+
- Volume description rendering
|
|
22
|
+
- Automatic CSS injection via `injectStyles()`
|
|
23
|
+
- Interactive example demo page
|
|
24
|
+
- TypeScript type exports (`TowerDisplayOptions`, `ITowerDisplay`)
|
|
25
|
+
- Dual ESM/CJS build via Vite library mode
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ChessMess
|
|
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
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# UltimateDarkTowerDisplay
|
|
2
|
+
|
|
3
|
+
DOM-based visual readout for decoded [Ultimate Dark Tower](https://github.com/ChessMess/ultimatedarktower) tower state.
|
|
4
|
+
|
|
5
|
+
This package renders a live tower dashboard into a DOM element. It is intended for tools that already know how to obtain or decode a `TowerState` and want a compact on-screen display of:
|
|
6
|
+
|
|
7
|
+
- LED layers and per-light effects
|
|
8
|
+
- Drum positions and calibration status
|
|
9
|
+
- Visible glyph on each calibrated drum
|
|
10
|
+
- Active audio sample, loop flag, and volume
|
|
11
|
+
- Beam/skull count and skull-drop transitions
|
|
12
|
+
- Active LED sequence override
|
|
13
|
+
|
|
14
|
+
## What This Package Does
|
|
15
|
+
|
|
16
|
+
`ultimatedarktowerdisplay` is a renderer. It does not talk to the physical tower, decode packets, or create `TowerState` objects on its own.
|
|
17
|
+
|
|
18
|
+
Use it alongside [`ultimatedarktower`](https://github.com/ChessMess/ultimatedarktower), which provides the `TowerState` type and helpers such as `createDefaultTowerState()`.
|
|
19
|
+
|
|
20
|
+
This package intentionally keeps a narrow API surface. It exports display components and display-specific types only. Import protocol constants such as `LIGHT_EFFECTS`, `TOWER_AUDIO_LIBRARY`, and `TOWER_LIGHT_SEQUENCES` from `ultimatedarktower`.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install ultimatedarktowerdisplay ultimatedarktower
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`ultimatedarktower` is a peer dependency and must be installed by the consuming app.
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { TowerDisplay } from "ultimatedarktowerdisplay";
|
|
34
|
+
import { createDefaultTowerState } from "ultimatedarktower";
|
|
35
|
+
|
|
36
|
+
const container = document.getElementById("tower");
|
|
37
|
+
|
|
38
|
+
if (!container) {
|
|
39
|
+
throw new Error("Missing #tower container");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const display = new TowerDisplay({ container });
|
|
43
|
+
const state = createDefaultTowerState();
|
|
44
|
+
|
|
45
|
+
display.applyState(state);
|
|
46
|
+
|
|
47
|
+
// Later, when the tower sends an updated decoded state:
|
|
48
|
+
// display.applyState(nextState);
|
|
49
|
+
|
|
50
|
+
// Reset to the idle placeholder.
|
|
51
|
+
display.showIdle();
|
|
52
|
+
|
|
53
|
+
// Remove rendered DOM when tearing down the view.
|
|
54
|
+
display.dispose();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Minimal HTML:
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<div id="tower"></div>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Typical Integration
|
|
64
|
+
|
|
65
|
+
In most applications the flow looks like this:
|
|
66
|
+
|
|
67
|
+
1. Use `ultimatedarktower` to create or decode a `TowerState`.
|
|
68
|
+
2. Create a `TowerDisplay` for a container element.
|
|
69
|
+
3. Call `applyState(state)` whenever a new decoded state arrives.
|
|
70
|
+
4. Call `dispose()` when removing the view.
|
|
71
|
+
|
|
72
|
+
Example with a manually adjusted state:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { TowerDisplay } from "ultimatedarktowerdisplay";
|
|
76
|
+
import {
|
|
77
|
+
createDefaultTowerState,
|
|
78
|
+
LIGHT_EFFECTS,
|
|
79
|
+
TOWER_AUDIO_LIBRARY,
|
|
80
|
+
} from "ultimatedarktower";
|
|
81
|
+
|
|
82
|
+
const container = document.getElementById("tower");
|
|
83
|
+
|
|
84
|
+
if (!container) {
|
|
85
|
+
throw new Error("Missing #tower container");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const display = new TowerDisplay({ container });
|
|
89
|
+
const state = createDefaultTowerState();
|
|
90
|
+
|
|
91
|
+
state.layer[0].light[0].effect = LIGHT_EFFECTS.on;
|
|
92
|
+
state.layer[0].light[1].effect = LIGHT_EFFECTS.breathe;
|
|
93
|
+
state.drum[0].position = 1;
|
|
94
|
+
state.drum[0].calibrated = true;
|
|
95
|
+
state.audio.sample = TOWER_AUDIO_LIBRARY.Ashstrider.value;
|
|
96
|
+
state.audio.loop = true;
|
|
97
|
+
state.beam.count = 2;
|
|
98
|
+
|
|
99
|
+
display.applyState(state);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Expected `TowerState` Shape
|
|
103
|
+
|
|
104
|
+
You usually do not construct `TowerState` by hand. Start from `createDefaultTowerState()` and mutate fields you care about.
|
|
105
|
+
|
|
106
|
+
Conceptually, the renderer expects a state shaped like this:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
type TowerState = {
|
|
110
|
+
drum: Array<{
|
|
111
|
+
calibrated: boolean;
|
|
112
|
+
position: number;
|
|
113
|
+
}>;
|
|
114
|
+
layer: Array<{
|
|
115
|
+
light: Array<{
|
|
116
|
+
effect: number;
|
|
117
|
+
loop: boolean;
|
|
118
|
+
}>;
|
|
119
|
+
}>;
|
|
120
|
+
audio: {
|
|
121
|
+
sample: number;
|
|
122
|
+
loop: boolean;
|
|
123
|
+
volume: number;
|
|
124
|
+
};
|
|
125
|
+
beam: {
|
|
126
|
+
count: number;
|
|
127
|
+
fault: boolean;
|
|
128
|
+
};
|
|
129
|
+
led_sequence: number;
|
|
130
|
+
};
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
For a valid starting point, prefer:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { createDefaultTowerState } from "ultimatedarktower";
|
|
137
|
+
|
|
138
|
+
const state = createDefaultTowerState();
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The example page in [example/index.html](./example/index.html) follows this pattern.
|
|
142
|
+
|
|
143
|
+
## Rendering Behavior
|
|
144
|
+
|
|
145
|
+
- The constructor immediately renders an idle message: `Waiting for tower state…`
|
|
146
|
+
- Styles are injected into `document.head` automatically on first use
|
|
147
|
+
- A skull-drop highlight appears only when `beam.count` increases between successive `applyState()` calls
|
|
148
|
+
- `dispose()` clears the container and resets internal state, including skull-drop tracking
|
|
149
|
+
|
|
150
|
+
## API
|
|
151
|
+
|
|
152
|
+
### `TowerDisplay`
|
|
153
|
+
|
|
154
|
+
Primary entry point. Wraps `TowerStateReadout` with an options object.
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
new TowerDisplay(options: TowerDisplayOptions)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
| Option | Type | Description |
|
|
161
|
+
| ----------- | ------------- | -------------------------------------------------- |
|
|
162
|
+
| `container` | `HTMLElement` | DOM element that will receive the rendered readout |
|
|
163
|
+
|
|
164
|
+
Methods:
|
|
165
|
+
|
|
166
|
+
- `applyState(state: TowerState): void` updates the readout with a decoded tower state
|
|
167
|
+
- `showIdle(): void` replaces the readout with the idle placeholder
|
|
168
|
+
- `dispose(): void` clears the container and resets internal state
|
|
169
|
+
|
|
170
|
+
### `TowerStateReadout`
|
|
171
|
+
|
|
172
|
+
Lower-level renderer for callers that want to pass the container directly.
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
new TowerStateReadout(container: HTMLElement)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
It exposes the same methods as `TowerDisplay`.
|
|
179
|
+
|
|
180
|
+
### Exported Types
|
|
181
|
+
|
|
182
|
+
- `ITowerDisplay` common interface implemented by both classes
|
|
183
|
+
- `TowerDisplayOptions` configuration object for `TowerDisplay`
|
|
184
|
+
|
|
185
|
+
`ultimatedarktowerdisplay` does not re-export tower protocol constants or helpers from `ultimatedarktower`.
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
Install dependencies:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
npm install
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Available commands:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
npm run typecheck
|
|
199
|
+
npm run lint
|
|
200
|
+
npm test
|
|
201
|
+
npm run test:coverage
|
|
202
|
+
npm run build
|
|
203
|
+
npm run dev
|
|
204
|
+
npm run dev:example
|
|
205
|
+
npm run ci
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`npm run dev:example` starts the Vite example page and opens [example/index.html](./example/index.html).
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TowerState } from 'ultimatedarktower';
|
|
2
|
+
import type { TowerDisplayOptions, ITowerDisplay } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* TowerDisplay renders decoded tower state into a DOM container.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const display = new TowerDisplay({
|
|
9
|
+
* container: document.getElementById('tower')!,
|
|
10
|
+
* });
|
|
11
|
+
* display.applyState(state);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare class TowerDisplay implements ITowerDisplay {
|
|
15
|
+
private readonly impl;
|
|
16
|
+
constructor(options: TowerDisplayOptions);
|
|
17
|
+
/** Update the display with a new decoded tower state. */
|
|
18
|
+
applyState(state: TowerState): void;
|
|
19
|
+
/** Reset the display to its idle/waiting state. */
|
|
20
|
+
showIdle(): void;
|
|
21
|
+
/** Remove all rendered DOM content and reset internal state. */
|
|
22
|
+
dispose(): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type TowerState } from 'ultimatedarktower';
|
|
2
|
+
import type { ITowerDisplay } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Core DOM renderer for tower state.
|
|
5
|
+
*
|
|
6
|
+
* Renders a live readout of LED grid, drum positions, audio state,
|
|
7
|
+
* skull drops, and LED sequence overrides.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const readout = new TowerStateReadout(document.getElementById('tower')!);
|
|
12
|
+
* readout.applyState(state);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class TowerStateReadout implements ITowerDisplay {
|
|
16
|
+
private readonly container;
|
|
17
|
+
private prevBeamCount;
|
|
18
|
+
constructor(container: HTMLElement);
|
|
19
|
+
/** Update the display with a new decoded tower state. */
|
|
20
|
+
applyState(state: TowerState): void;
|
|
21
|
+
/** Reset the display to its idle/waiting state. */
|
|
22
|
+
showIdle(): void;
|
|
23
|
+
/** Remove all rendered DOM content and reset internal state. */
|
|
24
|
+
dispose(): void;
|
|
25
|
+
private render;
|
|
26
|
+
/**
|
|
27
|
+
* Find the glyph name on the north-facing side of a drum, if any.
|
|
28
|
+
* Only valid when the drum is calibrated.
|
|
29
|
+
*/
|
|
30
|
+
private findGlyph;
|
|
31
|
+
/** Look up an audio sample name from TOWER_AUDIO_LIBRARY by value. */
|
|
32
|
+
private lookupAudio;
|
|
33
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("ultimatedarktower");let g=!1,f=null;const $=`
|
|
2
|
+
/* ── Tower Display Readout ── */
|
|
3
|
+
|
|
4
|
+
@keyframes tdr-breathe {
|
|
5
|
+
0%, 100% { opacity: 0.3; }
|
|
6
|
+
50% { opacity: 1; }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@keyframes tdr-flicker {
|
|
10
|
+
0%, 100% { opacity: 1; }
|
|
11
|
+
50% { opacity: 0.2; }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@keyframes tdr-skull-flash {
|
|
15
|
+
0% { transform: scale(1.3); }
|
|
16
|
+
100% { transform: scale(1); }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.tdr-idle {
|
|
20
|
+
font-size: 0.85rem;
|
|
21
|
+
color: #888;
|
|
22
|
+
font-style: italic;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.tdr-section h3 {
|
|
26
|
+
font-size: 0.65rem;
|
|
27
|
+
text-transform: uppercase;
|
|
28
|
+
letter-spacing: 0.08em;
|
|
29
|
+
color: #888;
|
|
30
|
+
margin: 0.6rem 0 0.3rem;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* ── LED Grid ── */
|
|
34
|
+
|
|
35
|
+
.tdr-layer {
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
gap: 0.4rem;
|
|
39
|
+
padding: 0.15rem 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.tdr-layer-label {
|
|
43
|
+
font-size: 0.65rem;
|
|
44
|
+
color: #888;
|
|
45
|
+
width: 7rem;
|
|
46
|
+
text-align: right;
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.tdr-led {
|
|
51
|
+
width: 20px;
|
|
52
|
+
height: 20px;
|
|
53
|
+
border-radius: 50%;
|
|
54
|
+
background: #333;
|
|
55
|
+
border: 1px solid #555;
|
|
56
|
+
display: inline-block;
|
|
57
|
+
transition: background 0.2s;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.tdr-led[data-effect="on"] {
|
|
61
|
+
background: #f0c040;
|
|
62
|
+
box-shadow: 0 0 6px rgba(240, 192, 64, 0.5);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.tdr-led[data-effect="breathe"] {
|
|
66
|
+
background: #80a0ff;
|
|
67
|
+
animation: tdr-breathe 2s ease-in-out infinite;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.tdr-led[data-effect="breathe-fast"] {
|
|
71
|
+
background: #80a0ff;
|
|
72
|
+
animation: tdr-breathe 0.8s ease-in-out infinite;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.tdr-led[data-effect="breathe-50"] {
|
|
76
|
+
background: #80a0ff;
|
|
77
|
+
animation: tdr-breathe 2s ease-in-out infinite;
|
|
78
|
+
opacity: 0.5;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.tdr-led[data-effect="flicker"] {
|
|
82
|
+
background: #ff6040;
|
|
83
|
+
animation: tdr-flicker 0.3s step-end infinite;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* ── Drums ── */
|
|
87
|
+
|
|
88
|
+
.tdr-drum {
|
|
89
|
+
display: inline-flex;
|
|
90
|
+
align-items: center;
|
|
91
|
+
gap: 0.5rem;
|
|
92
|
+
padding: 0.3rem 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.tdr-drum-name {
|
|
96
|
+
font-size: 0.75rem;
|
|
97
|
+
font-weight: 600;
|
|
98
|
+
color: #e8e8e8;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.tdr-drum-pos {
|
|
102
|
+
font-size: 0.85rem;
|
|
103
|
+
font-weight: 700;
|
|
104
|
+
color: #c0392b;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.tdr-drum-cal {
|
|
108
|
+
font-size: 0.75rem;
|
|
109
|
+
color: #888;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.tdr-glyph {
|
|
113
|
+
font-size: 0.7rem;
|
|
114
|
+
color: #f39c12;
|
|
115
|
+
font-style: italic;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* ── Audio ── */
|
|
119
|
+
|
|
120
|
+
.tdr-audio {
|
|
121
|
+
display: flex;
|
|
122
|
+
align-items: center;
|
|
123
|
+
gap: 0.5rem;
|
|
124
|
+
font-size: 0.8rem;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.tdr-audio-name {
|
|
128
|
+
color: #e8e8e8;
|
|
129
|
+
font-weight: 500;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.tdr-audio-loop {
|
|
133
|
+
font-size: 0.65rem;
|
|
134
|
+
color: #27ae60;
|
|
135
|
+
border: 1px solid #27ae60;
|
|
136
|
+
border-radius: 3px;
|
|
137
|
+
padding: 0 4px;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.tdr-audio-vol {
|
|
141
|
+
font-size: 0.65rem;
|
|
142
|
+
color: #888;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* ── Skull / Beam ── */
|
|
146
|
+
|
|
147
|
+
.tdr-skull-drop {
|
|
148
|
+
color: #e74c3c;
|
|
149
|
+
font-weight: 700;
|
|
150
|
+
font-size: 0.9rem;
|
|
151
|
+
margin-top: 0.5rem;
|
|
152
|
+
animation: tdr-skull-flash 0.6s ease-out;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.tdr-beam-count {
|
|
156
|
+
font-size: 0.8rem;
|
|
157
|
+
color: #888;
|
|
158
|
+
margin-top: 0.5rem;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* ── LED Sequence Override ── */
|
|
162
|
+
|
|
163
|
+
.tdr-led-seq {
|
|
164
|
+
font-size: 0.75rem;
|
|
165
|
+
color: #f39c12;
|
|
166
|
+
margin-top: 0.3rem;
|
|
167
|
+
}
|
|
168
|
+
`;function k(){g||(f=document.createElement("style"),f.textContent=$,document.head.appendChild(f),g=!0)}const _=["N","E","S","W"],w=["north","east","south","west"],C=["Top","Middle","Bottom"],I=["top","middle","bottom"];function r(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const O={[t.LIGHT_EFFECTS.off]:"off",[t.LIGHT_EFFECTS.on]:"on",[t.LIGHT_EFFECTS.breathe]:"breathe",[t.LIGHT_EFFECTS.breatheFast]:"breathe-fast",[t.LIGHT_EFFECTS.breathe50percent]:"breathe-50",[t.LIGHT_EFFECTS.flicker]:"flicker"},D=Object.fromEntries(Object.entries(t.TOWER_LIGHT_SEQUENCES).map(([o,e])=>[e,o])),x=new Map(Object.values(t.TOWER_AUDIO_LIBRARY).map(o=>[o.value,o.name]));class E{constructor(e){this.prevBeamCount=null,this.container=e,k(),this.showIdle()}applyState(e){const a=this.prevBeamCount!==null&&e.beam.count>this.prevBeamCount;this.prevBeamCount=e.beam.count,this.render(e,a)}showIdle(){this.container.innerHTML='<p class="tdr-idle">Waiting for tower state…</p>'}dispose(){this.container.innerHTML="",this.prevBeamCount=null}render(e,a){const c=e.layer.map((n,s)=>{const d=t.LAYER_TO_POSITION[s]??`L${s}`,m=n.light.map((l,h)=>{const b=O[l.effect]??"off",L=t.LIGHT_INDEX_TO_DIRECTION[h]??h;return`<span class="tdr-led" data-effect="${r(b)}" title="${r(`${d} ${L}: ${b}${l.loop?" (loop)":""}`)}"></span>`}).join("");return`<div class="tdr-layer"><span class="tdr-layer-label">${r(d)}</span>${m}</div>`}).join(""),p=e.drum.map((n,s)=>{const d=_[n.position]??"?",m=n.calibrated?"✓":"—",l=this.findGlyph(s,n.position,n.calibrated);return`<div class="tdr-drum">
|
|
169
|
+
<span class="tdr-drum-name">${r(C[s])}</span>
|
|
170
|
+
<span class="tdr-drum-pos">${r(d)}</span>
|
|
171
|
+
<span class="tdr-drum-cal" title="Calibrated: ${n.calibrated}">${m}</span>
|
|
172
|
+
${l?`<span class="tdr-glyph">${r(l)}</span>`:""}
|
|
173
|
+
</div>`}).join(""),u=this.lookupAudio(e.audio.sample,e.audio.loop),i=t.VOLUME_DESCRIPTIONS[e.audio.volume]??`Vol ${e.audio.volume}`,S=`<div class="tdr-audio">
|
|
174
|
+
<span class="tdr-audio-name">${r(u)}</span>
|
|
175
|
+
${e.audio.loop?'<span class="tdr-audio-loop">loop</span>':""}
|
|
176
|
+
<span class="tdr-audio-vol">${r(i)}</span>
|
|
177
|
+
</div>`,v=a?`<div class="tdr-skull-drop">💀 Skull Drop! (${e.beam.count})</div>`:`<div class="tdr-beam-count">Skulls: ${e.beam.count}${e.beam.fault?" ⚠ fault":""}</div>`,y=D[e.led_sequence]??`0x${e.led_sequence.toString(16).padStart(2,"0")}`,T=e.led_sequence!==0?`<div class="tdr-led-seq">LED Sequence: ${r(y)}</div>`:"";this.container.innerHTML=`
|
|
178
|
+
<div class="tdr-section tdr-leds"><h3>LEDs</h3>${c}</div>
|
|
179
|
+
<div class="tdr-section tdr-drums"><h3>Drums</h3>${p}</div>
|
|
180
|
+
<div class="tdr-section tdr-info">
|
|
181
|
+
${S}
|
|
182
|
+
${v}
|
|
183
|
+
${T}
|
|
184
|
+
</div>
|
|
185
|
+
`}findGlyph(e,a,c){if(!c)return null;const p=I[e],u=w[a];for(const i of Object.values(t.GLYPHS))if(i.level===p&&i.side===u)return i.name;return null}lookupAudio(e,a){return e===0&&!a?"Silence":x.get(e)??`Sample ${e}`}}class F{constructor(e){this.impl=new E(e.container)}applyState(e){this.impl.applyState(e)}showIdle(){this.impl.showIdle()}dispose(){this.impl.dispose()}}exports.TowerDisplay=F;exports.TowerStateReadout=E;
|
|
186
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/styles.ts","../src/TowerStateReadout.ts","../src/TowerDisplay.ts"],"sourcesContent":["let injected = false;\nlet styleElement: HTMLStyleElement | null = null;\n\nconst CSS = `\n/* ── Tower Display Readout ── */\n\n@keyframes tdr-breathe {\n 0%, 100% { opacity: 0.3; }\n 50% { opacity: 1; }\n}\n\n@keyframes tdr-flicker {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.2; }\n}\n\n@keyframes tdr-skull-flash {\n 0% { transform: scale(1.3); }\n 100% { transform: scale(1); }\n}\n\n.tdr-idle {\n font-size: 0.85rem;\n color: #888;\n font-style: italic;\n}\n\n.tdr-section h3 {\n font-size: 0.65rem;\n text-transform: uppercase;\n letter-spacing: 0.08em;\n color: #888;\n margin: 0.6rem 0 0.3rem;\n}\n\n/* ── LED Grid ── */\n\n.tdr-layer {\n display: flex;\n align-items: center;\n gap: 0.4rem;\n padding: 0.15rem 0;\n}\n\n.tdr-layer-label {\n font-size: 0.65rem;\n color: #888;\n width: 7rem;\n text-align: right;\n flex-shrink: 0;\n}\n\n.tdr-led {\n width: 20px;\n height: 20px;\n border-radius: 50%;\n background: #333;\n border: 1px solid #555;\n display: inline-block;\n transition: background 0.2s;\n}\n\n.tdr-led[data-effect=\"on\"] {\n background: #f0c040;\n box-shadow: 0 0 6px rgba(240, 192, 64, 0.5);\n}\n\n.tdr-led[data-effect=\"breathe\"] {\n background: #80a0ff;\n animation: tdr-breathe 2s ease-in-out infinite;\n}\n\n.tdr-led[data-effect=\"breathe-fast\"] {\n background: #80a0ff;\n animation: tdr-breathe 0.8s ease-in-out infinite;\n}\n\n.tdr-led[data-effect=\"breathe-50\"] {\n background: #80a0ff;\n animation: tdr-breathe 2s ease-in-out infinite;\n opacity: 0.5;\n}\n\n.tdr-led[data-effect=\"flicker\"] {\n background: #ff6040;\n animation: tdr-flicker 0.3s step-end infinite;\n}\n\n/* ── Drums ── */\n\n.tdr-drum {\n display: inline-flex;\n align-items: center;\n gap: 0.5rem;\n padding: 0.3rem 0;\n}\n\n.tdr-drum-name {\n font-size: 0.75rem;\n font-weight: 600;\n color: #e8e8e8;\n}\n\n.tdr-drum-pos {\n font-size: 0.85rem;\n font-weight: 700;\n color: #c0392b;\n}\n\n.tdr-drum-cal {\n font-size: 0.75rem;\n color: #888;\n}\n\n.tdr-glyph {\n font-size: 0.7rem;\n color: #f39c12;\n font-style: italic;\n}\n\n/* ── Audio ── */\n\n.tdr-audio {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n font-size: 0.8rem;\n}\n\n.tdr-audio-name {\n color: #e8e8e8;\n font-weight: 500;\n}\n\n.tdr-audio-loop {\n font-size: 0.65rem;\n color: #27ae60;\n border: 1px solid #27ae60;\n border-radius: 3px;\n padding: 0 4px;\n}\n\n.tdr-audio-vol {\n font-size: 0.65rem;\n color: #888;\n}\n\n/* ── Skull / Beam ── */\n\n.tdr-skull-drop {\n color: #e74c3c;\n font-weight: 700;\n font-size: 0.9rem;\n margin-top: 0.5rem;\n animation: tdr-skull-flash 0.6s ease-out;\n}\n\n.tdr-beam-count {\n font-size: 0.8rem;\n color: #888;\n margin-top: 0.5rem;\n}\n\n/* ── LED Sequence Override ── */\n\n.tdr-led-seq {\n font-size: 0.75rem;\n color: #f39c12;\n margin-top: 0.3rem;\n}\n`;\n\n/**\n * Injects the tower display readout stylesheet into `document.head`.\n * Safe to call multiple times — the `<style>` tag is only appended once.\n */\nexport function injectStyles(): void {\n if (injected) return;\n styleElement = document.createElement('style');\n styleElement.textContent = CSS;\n document.head.appendChild(styleElement);\n injected = true;\n}\n\n/**\n * Reset the injection guard (for testing only).\n * @internal\n */\nexport function _resetStyleInjection(): void {\n if (styleElement) {\n styleElement.remove();\n styleElement = null;\n }\n injected = false;\n}\n","import {\n type TowerState,\n GLYPHS,\n TOWER_AUDIO_LIBRARY,\n TOWER_LIGHT_SEQUENCES,\n VOLUME_DESCRIPTIONS,\n LAYER_TO_POSITION,\n LIGHT_INDEX_TO_DIRECTION,\n LIGHT_EFFECTS,\n} from 'ultimatedarktower';\nimport type { ITowerDisplay } from './types';\nimport { injectStyles } from './styles';\n\nconst COMPASS = ['N', 'E', 'S', 'W'] as const;\nconst COMPASS_FULL = ['north', 'east', 'south', 'west'] as const;\nconst DRUM_NAMES = ['Top', 'Middle', 'Bottom'] as const;\nconst DRUM_LEVELS = ['top', 'middle', 'bottom'] as const;\n\n/** Escape HTML special characters to prevent XSS when interpolating into innerHTML. */\nfunction esc(str: string): string {\n return str\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"');\n}\n\n// Build reverse lookup maps once at module level\nconst EFFECT_LABELS: Record<number, string> = {\n [LIGHT_EFFECTS.off]: 'off',\n [LIGHT_EFFECTS.on]: 'on',\n [LIGHT_EFFECTS.breathe]: 'breathe',\n [LIGHT_EFFECTS.breatheFast]: 'breathe-fast',\n [LIGHT_EFFECTS.breathe50percent]: 'breathe-50',\n [LIGHT_EFFECTS.flicker]: 'flicker',\n};\n\nconst SEQUENCE_LABELS: Record<number, string> = Object.fromEntries(\n Object.entries(TOWER_LIGHT_SEQUENCES).map(([name, val]) => [val, name]),\n);\n\nconst AUDIO_BY_VALUE: Map<number, string> = new Map(\n Object.values(TOWER_AUDIO_LIBRARY).map((entry) => [entry.value, entry.name]),\n);\n\n/**\n * Core DOM renderer for tower state.\n *\n * Renders a live readout of LED grid, drum positions, audio state,\n * skull drops, and LED sequence overrides.\n *\n * @example\n * ```ts\n * const readout = new TowerStateReadout(document.getElementById('tower')!);\n * readout.applyState(state);\n * ```\n */\nexport class TowerStateReadout implements ITowerDisplay {\n private readonly container: HTMLElement;\n private prevBeamCount: number | null = null;\n\n constructor(container: HTMLElement) {\n this.container = container;\n injectStyles();\n this.showIdle();\n }\n\n /** Update the display with a new decoded tower state. */\n applyState(state: TowerState): void {\n const skullDrop = this.prevBeamCount !== null && state.beam.count > this.prevBeamCount;\n this.prevBeamCount = state.beam.count;\n this.render(state, skullDrop);\n }\n\n /** Reset the display to its idle/waiting state. */\n showIdle(): void {\n this.container.innerHTML = '<p class=\"tdr-idle\">Waiting for tower state\\u2026</p>';\n }\n\n /** Remove all rendered DOM content and reset internal state. */\n dispose(): void {\n this.container.innerHTML = '';\n this.prevBeamCount = null;\n }\n\n private render(state: TowerState, skullDrop: boolean): void {\n // --- LEDs: 6 layers × 4 lights ---\n const ledRows = state.layer.map((layer, li) => {\n const layerName = LAYER_TO_POSITION[li as keyof typeof LAYER_TO_POSITION] ?? `L${li}`;\n const lights = layer.light.map((light, ji) => {\n const eff = EFFECT_LABELS[light.effect] ?? 'off';\n const dir = LIGHT_INDEX_TO_DIRECTION[ji as keyof typeof LIGHT_INDEX_TO_DIRECTION] ?? ji;\n return `<span class=\"tdr-led\" data-effect=\"${esc(eff)}\" title=\"${esc(`${layerName} ${dir}: ${eff}${light.loop ? ' (loop)' : ''}`)}\"></span>`;\n }).join('');\n return `<div class=\"tdr-layer\"><span class=\"tdr-layer-label\">${esc(layerName)}</span>${lights}</div>`;\n }).join('');\n\n // --- Drums ---\n const drumRows = state.drum.map((drum, di) => {\n const dir = COMPASS[drum.position] ?? '?';\n const cal = drum.calibrated ? '\\u2713' : '\\u2014';\n const activeGlyph = this.findGlyph(di, drum.position, drum.calibrated);\n return `<div class=\"tdr-drum\">\n <span class=\"tdr-drum-name\">${esc(DRUM_NAMES[di])}</span>\n <span class=\"tdr-drum-pos\">${esc(dir)}</span>\n <span class=\"tdr-drum-cal\" title=\"Calibrated: ${drum.calibrated}\">${cal}</span>\n ${activeGlyph ? `<span class=\"tdr-glyph\">${esc(activeGlyph)}</span>` : ''}\n </div>`;\n }).join('');\n\n // --- Audio ---\n const audioName = this.lookupAudio(state.audio.sample, state.audio.loop);\n const volLabel = VOLUME_DESCRIPTIONS[state.audio.volume as keyof typeof VOLUME_DESCRIPTIONS] ?? `Vol ${state.audio.volume}`;\n const audioHtml = `<div class=\"tdr-audio\">\n <span class=\"tdr-audio-name\">${esc(audioName)}</span>\n ${state.audio.loop ? '<span class=\"tdr-audio-loop\">loop</span>' : ''}\n <span class=\"tdr-audio-vol\">${esc(volLabel)}</span>\n </div>`;\n\n // --- Skull drop / beam ---\n const skullHtml = skullDrop\n ? `<div class=\"tdr-skull-drop\">\\uD83D\\uDC80 Skull Drop! (${state.beam.count})</div>`\n : `<div class=\"tdr-beam-count\">Skulls: ${state.beam.count}${state.beam.fault ? ' \\u26A0 fault' : ''}</div>`;\n\n // --- LED sequence override ---\n const seqLabel = SEQUENCE_LABELS[state.led_sequence] ?? `0x${state.led_sequence.toString(16).padStart(2, '0')}`;\n const seqHtml = state.led_sequence !== 0\n ? `<div class=\"tdr-led-seq\">LED Sequence: ${esc(seqLabel)}</div>`\n : '';\n\n this.container.innerHTML = `\n <div class=\"tdr-section tdr-leds\"><h3>LEDs</h3>${ledRows}</div>\n <div class=\"tdr-section tdr-drums\"><h3>Drums</h3>${drumRows}</div>\n <div class=\"tdr-section tdr-info\">\n ${audioHtml}\n ${skullHtml}\n ${seqHtml}\n </div>\n `;\n }\n\n /**\n * Find the glyph name on the north-facing side of a drum, if any.\n * Only valid when the drum is calibrated.\n */\n private findGlyph(drumIndex: number, position: number, calibrated: boolean): string | null {\n if (!calibrated) return null;\n const level = DRUM_LEVELS[drumIndex];\n const facing = COMPASS_FULL[position];\n for (const glyph of Object.values(GLYPHS)) {\n if (glyph.level === level && glyph.side === facing) {\n return glyph.name;\n }\n }\n return null;\n }\n\n /** Look up an audio sample name from TOWER_AUDIO_LIBRARY by value. */\n private lookupAudio(sample: number, loop: boolean): string {\n if (sample === 0 && !loop) return 'Silence';\n return AUDIO_BY_VALUE.get(sample) ?? `Sample ${sample}`;\n }\n}\n","import type { TowerState } from 'ultimatedarktower';\nimport type { TowerDisplayOptions, ITowerDisplay } from './types';\nimport { TowerStateReadout } from './TowerStateReadout';\n\n/**\n * TowerDisplay renders decoded tower state into a DOM container.\n *\n * @example\n * ```ts\n * const display = new TowerDisplay({\n * container: document.getElementById('tower')!,\n * });\n * display.applyState(state);\n * ```\n */\nexport class TowerDisplay implements ITowerDisplay {\n private readonly impl: TowerStateReadout;\n\n constructor(options: TowerDisplayOptions) {\n this.impl = new TowerStateReadout(options.container);\n }\n\n /** Update the display with a new decoded tower state. */\n applyState(state: TowerState): void {\n this.impl.applyState(state);\n }\n\n /** Reset the display to its idle/waiting state. */\n showIdle(): void {\n this.impl.showIdle();\n }\n\n /** Remove all rendered DOM content and reset internal state. */\n dispose(): void {\n this.impl.dispose();\n }\n}\n"],"names":["injected","styleElement","CSS","injectStyles","COMPASS","COMPASS_FULL","DRUM_NAMES","DRUM_LEVELS","esc","str","EFFECT_LABELS","LIGHT_EFFECTS","SEQUENCE_LABELS","TOWER_LIGHT_SEQUENCES","name","val","AUDIO_BY_VALUE","TOWER_AUDIO_LIBRARY","entry","TowerStateReadout","container","state","skullDrop","ledRows","layer","li","layerName","LAYER_TO_POSITION","lights","light","ji","eff","dir","LIGHT_INDEX_TO_DIRECTION","drumRows","drum","di","cal","activeGlyph","audioName","volLabel","VOLUME_DESCRIPTIONS","audioHtml","skullHtml","seqLabel","seqHtml","drumIndex","position","calibrated","level","facing","glyph","GLYPHS","sample","loop","TowerDisplay","options"],"mappings":"qHAAA,IAAIA,EAAW,GACXC,EAAwC,KAE5C,MAAMC,EAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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yDACLW,CAAQ;AAAA;AAAA,UAEvDQ,CAAS;AAAA,UACTC,CAAS;AAAA,UACTE,CAAO;AAAA;AAAA,KAGf,CAMQ,UAAUC,EAAmBC,EAAkBC,EAAoC,CACzF,GAAI,CAACA,EAAY,OAAO,KACxB,MAAMC,EAAQ1C,EAAYuC,CAAS,EAC7BI,EAAS7C,EAAa0C,CAAQ,EACpC,UAAWI,KAAS,OAAO,OAAOC,EAAAA,MAAM,EACtC,GAAID,EAAM,QAAUF,GAASE,EAAM,OAASD,EAC1C,OAAOC,EAAM,KAGjB,OAAO,IACT,CAGQ,YAAYE,EAAgBC,EAAuB,CACzD,OAAID,IAAW,GAAK,CAACC,EAAa,UAC3BtC,EAAe,IAAIqC,CAAM,GAAK,UAAUA,CAAM,EACvD,CACF,CCnJO,MAAME,CAAsC,CAGjD,YAAYC,EAA8B,CACxC,KAAK,KAAO,IAAIrC,EAAkBqC,EAAQ,SAAS,CACrD,CAGA,WAAWnC,EAAyB,CAClC,KAAK,KAAK,WAAWA,CAAK,CAC5B,CAGA,UAAiB,CACf,KAAK,KAAK,SAAA,CACZ,CAGA,SAAgB,CACd,KAAK,KAAK,QAAA,CACZ,CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { LIGHT_EFFECTS as n, TOWER_LIGHT_SEQUENCES as k, TOWER_AUDIO_LIBRARY as L, LAYER_TO_POSITION as _, LIGHT_INDEX_TO_DIRECTION as w, VOLUME_DESCRIPTIONS as T, GLYPHS as O } from "ultimatedarktower";
|
|
2
|
+
let g = !1, f = null;
|
|
3
|
+
const x = `
|
|
4
|
+
/* ── Tower Display Readout ── */
|
|
5
|
+
|
|
6
|
+
@keyframes tdr-breathe {
|
|
7
|
+
0%, 100% { opacity: 0.3; }
|
|
8
|
+
50% { opacity: 1; }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@keyframes tdr-flicker {
|
|
12
|
+
0%, 100% { opacity: 1; }
|
|
13
|
+
50% { opacity: 0.2; }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@keyframes tdr-skull-flash {
|
|
17
|
+
0% { transform: scale(1.3); }
|
|
18
|
+
100% { transform: scale(1); }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.tdr-idle {
|
|
22
|
+
font-size: 0.85rem;
|
|
23
|
+
color: #888;
|
|
24
|
+
font-style: italic;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.tdr-section h3 {
|
|
28
|
+
font-size: 0.65rem;
|
|
29
|
+
text-transform: uppercase;
|
|
30
|
+
letter-spacing: 0.08em;
|
|
31
|
+
color: #888;
|
|
32
|
+
margin: 0.6rem 0 0.3rem;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* ── LED Grid ── */
|
|
36
|
+
|
|
37
|
+
.tdr-layer {
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
gap: 0.4rem;
|
|
41
|
+
padding: 0.15rem 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.tdr-layer-label {
|
|
45
|
+
font-size: 0.65rem;
|
|
46
|
+
color: #888;
|
|
47
|
+
width: 7rem;
|
|
48
|
+
text-align: right;
|
|
49
|
+
flex-shrink: 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.tdr-led {
|
|
53
|
+
width: 20px;
|
|
54
|
+
height: 20px;
|
|
55
|
+
border-radius: 50%;
|
|
56
|
+
background: #333;
|
|
57
|
+
border: 1px solid #555;
|
|
58
|
+
display: inline-block;
|
|
59
|
+
transition: background 0.2s;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.tdr-led[data-effect="on"] {
|
|
63
|
+
background: #f0c040;
|
|
64
|
+
box-shadow: 0 0 6px rgba(240, 192, 64, 0.5);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.tdr-led[data-effect="breathe"] {
|
|
68
|
+
background: #80a0ff;
|
|
69
|
+
animation: tdr-breathe 2s ease-in-out infinite;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.tdr-led[data-effect="breathe-fast"] {
|
|
73
|
+
background: #80a0ff;
|
|
74
|
+
animation: tdr-breathe 0.8s ease-in-out infinite;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.tdr-led[data-effect="breathe-50"] {
|
|
78
|
+
background: #80a0ff;
|
|
79
|
+
animation: tdr-breathe 2s ease-in-out infinite;
|
|
80
|
+
opacity: 0.5;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.tdr-led[data-effect="flicker"] {
|
|
84
|
+
background: #ff6040;
|
|
85
|
+
animation: tdr-flicker 0.3s step-end infinite;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* ── Drums ── */
|
|
89
|
+
|
|
90
|
+
.tdr-drum {
|
|
91
|
+
display: inline-flex;
|
|
92
|
+
align-items: center;
|
|
93
|
+
gap: 0.5rem;
|
|
94
|
+
padding: 0.3rem 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.tdr-drum-name {
|
|
98
|
+
font-size: 0.75rem;
|
|
99
|
+
font-weight: 600;
|
|
100
|
+
color: #e8e8e8;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.tdr-drum-pos {
|
|
104
|
+
font-size: 0.85rem;
|
|
105
|
+
font-weight: 700;
|
|
106
|
+
color: #c0392b;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.tdr-drum-cal {
|
|
110
|
+
font-size: 0.75rem;
|
|
111
|
+
color: #888;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.tdr-glyph {
|
|
115
|
+
font-size: 0.7rem;
|
|
116
|
+
color: #f39c12;
|
|
117
|
+
font-style: italic;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* ── Audio ── */
|
|
121
|
+
|
|
122
|
+
.tdr-audio {
|
|
123
|
+
display: flex;
|
|
124
|
+
align-items: center;
|
|
125
|
+
gap: 0.5rem;
|
|
126
|
+
font-size: 0.8rem;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.tdr-audio-name {
|
|
130
|
+
color: #e8e8e8;
|
|
131
|
+
font-weight: 500;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.tdr-audio-loop {
|
|
135
|
+
font-size: 0.65rem;
|
|
136
|
+
color: #27ae60;
|
|
137
|
+
border: 1px solid #27ae60;
|
|
138
|
+
border-radius: 3px;
|
|
139
|
+
padding: 0 4px;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.tdr-audio-vol {
|
|
143
|
+
font-size: 0.65rem;
|
|
144
|
+
color: #888;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* ── Skull / Beam ── */
|
|
148
|
+
|
|
149
|
+
.tdr-skull-drop {
|
|
150
|
+
color: #e74c3c;
|
|
151
|
+
font-weight: 700;
|
|
152
|
+
font-size: 0.9rem;
|
|
153
|
+
margin-top: 0.5rem;
|
|
154
|
+
animation: tdr-skull-flash 0.6s ease-out;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.tdr-beam-count {
|
|
158
|
+
font-size: 0.8rem;
|
|
159
|
+
color: #888;
|
|
160
|
+
margin-top: 0.5rem;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* ── LED Sequence Override ── */
|
|
164
|
+
|
|
165
|
+
.tdr-led-seq {
|
|
166
|
+
font-size: 0.75rem;
|
|
167
|
+
color: #f39c12;
|
|
168
|
+
margin-top: 0.3rem;
|
|
169
|
+
}
|
|
170
|
+
`;
|
|
171
|
+
function C() {
|
|
172
|
+
g || (f = document.createElement("style"), f.textContent = x, document.head.appendChild(f), g = !0);
|
|
173
|
+
}
|
|
174
|
+
const D = ["N", "E", "S", "W"], I = ["north", "east", "south", "west"], z = ["Top", "Middle", "Bottom"], A = ["top", "middle", "bottom"];
|
|
175
|
+
function t(r) {
|
|
176
|
+
return r.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
177
|
+
}
|
|
178
|
+
const R = {
|
|
179
|
+
[n.off]: "off",
|
|
180
|
+
[n.on]: "on",
|
|
181
|
+
[n.breathe]: "breathe",
|
|
182
|
+
[n.breatheFast]: "breathe-fast",
|
|
183
|
+
[n.breathe50percent]: "breathe-50",
|
|
184
|
+
[n.flicker]: "flicker"
|
|
185
|
+
}, B = Object.fromEntries(
|
|
186
|
+
Object.entries(k).map(([r, e]) => [e, r])
|
|
187
|
+
), M = new Map(
|
|
188
|
+
Object.values(L).map((r) => [r.value, r.name])
|
|
189
|
+
);
|
|
190
|
+
class q {
|
|
191
|
+
constructor(e) {
|
|
192
|
+
this.prevBeamCount = null, this.container = e, C(), this.showIdle();
|
|
193
|
+
}
|
|
194
|
+
/** Update the display with a new decoded tower state. */
|
|
195
|
+
applyState(e) {
|
|
196
|
+
const o = this.prevBeamCount !== null && e.beam.count > this.prevBeamCount;
|
|
197
|
+
this.prevBeamCount = e.beam.count, this.render(e, o);
|
|
198
|
+
}
|
|
199
|
+
/** Reset the display to its idle/waiting state. */
|
|
200
|
+
showIdle() {
|
|
201
|
+
this.container.innerHTML = '<p class="tdr-idle">Waiting for tower state…</p>';
|
|
202
|
+
}
|
|
203
|
+
/** Remove all rendered DOM content and reset internal state. */
|
|
204
|
+
dispose() {
|
|
205
|
+
this.container.innerHTML = "", this.prevBeamCount = null;
|
|
206
|
+
}
|
|
207
|
+
render(e, o) {
|
|
208
|
+
const c = e.layer.map((a, s) => {
|
|
209
|
+
const d = _[s] ?? `L${s}`, m = a.light.map((l, h) => {
|
|
210
|
+
const b = R[l.effect] ?? "off", $ = w[h] ?? h;
|
|
211
|
+
return `<span class="tdr-led" data-effect="${t(b)}" title="${t(`${d} ${$}: ${b}${l.loop ? " (loop)" : ""}`)}"></span>`;
|
|
212
|
+
}).join("");
|
|
213
|
+
return `<div class="tdr-layer"><span class="tdr-layer-label">${t(d)}</span>${m}</div>`;
|
|
214
|
+
}).join(""), p = e.drum.map((a, s) => {
|
|
215
|
+
const d = D[a.position] ?? "?", m = a.calibrated ? "✓" : "—", l = this.findGlyph(s, a.position, a.calibrated);
|
|
216
|
+
return `<div class="tdr-drum">
|
|
217
|
+
<span class="tdr-drum-name">${t(z[s])}</span>
|
|
218
|
+
<span class="tdr-drum-pos">${t(d)}</span>
|
|
219
|
+
<span class="tdr-drum-cal" title="Calibrated: ${a.calibrated}">${m}</span>
|
|
220
|
+
${l ? `<span class="tdr-glyph">${t(l)}</span>` : ""}
|
|
221
|
+
</div>`;
|
|
222
|
+
}).join(""), u = this.lookupAudio(e.audio.sample, e.audio.loop), i = T[e.audio.volume] ?? `Vol ${e.audio.volume}`, v = `<div class="tdr-audio">
|
|
223
|
+
<span class="tdr-audio-name">${t(u)}</span>
|
|
224
|
+
${e.audio.loop ? '<span class="tdr-audio-loop">loop</span>' : ""}
|
|
225
|
+
<span class="tdr-audio-vol">${t(i)}</span>
|
|
226
|
+
</div>`, y = o ? `<div class="tdr-skull-drop">💀 Skull Drop! (${e.beam.count})</div>` : `<div class="tdr-beam-count">Skulls: ${e.beam.count}${e.beam.fault ? " ⚠ fault" : ""}</div>`, S = B[e.led_sequence] ?? `0x${e.led_sequence.toString(16).padStart(2, "0")}`, E = e.led_sequence !== 0 ? `<div class="tdr-led-seq">LED Sequence: ${t(S)}</div>` : "";
|
|
227
|
+
this.container.innerHTML = `
|
|
228
|
+
<div class="tdr-section tdr-leds"><h3>LEDs</h3>${c}</div>
|
|
229
|
+
<div class="tdr-section tdr-drums"><h3>Drums</h3>${p}</div>
|
|
230
|
+
<div class="tdr-section tdr-info">
|
|
231
|
+
${v}
|
|
232
|
+
${y}
|
|
233
|
+
${E}
|
|
234
|
+
</div>
|
|
235
|
+
`;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Find the glyph name on the north-facing side of a drum, if any.
|
|
239
|
+
* Only valid when the drum is calibrated.
|
|
240
|
+
*/
|
|
241
|
+
findGlyph(e, o, c) {
|
|
242
|
+
if (!c) return null;
|
|
243
|
+
const p = A[e], u = I[o];
|
|
244
|
+
for (const i of Object.values(O))
|
|
245
|
+
if (i.level === p && i.side === u)
|
|
246
|
+
return i.name;
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
/** Look up an audio sample name from TOWER_AUDIO_LIBRARY by value. */
|
|
250
|
+
lookupAudio(e, o) {
|
|
251
|
+
return e === 0 && !o ? "Silence" : M.get(e) ?? `Sample ${e}`;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
class N {
|
|
255
|
+
constructor(e) {
|
|
256
|
+
this.impl = new q(e.container);
|
|
257
|
+
}
|
|
258
|
+
/** Update the display with a new decoded tower state. */
|
|
259
|
+
applyState(e) {
|
|
260
|
+
this.impl.applyState(e);
|
|
261
|
+
}
|
|
262
|
+
/** Reset the display to its idle/waiting state. */
|
|
263
|
+
showIdle() {
|
|
264
|
+
this.impl.showIdle();
|
|
265
|
+
}
|
|
266
|
+
/** Remove all rendered DOM content and reset internal state. */
|
|
267
|
+
dispose() {
|
|
268
|
+
this.impl.dispose();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export {
|
|
272
|
+
N as TowerDisplay,
|
|
273
|
+
q as TowerStateReadout
|
|
274
|
+
};
|
|
275
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/styles.ts","../src/TowerStateReadout.ts","../src/TowerDisplay.ts"],"sourcesContent":["let injected = false;\nlet styleElement: HTMLStyleElement | null = null;\n\nconst CSS = `\n/* ── Tower Display Readout ── */\n\n@keyframes tdr-breathe {\n 0%, 100% { opacity: 0.3; }\n 50% { opacity: 1; }\n}\n\n@keyframes tdr-flicker {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.2; }\n}\n\n@keyframes tdr-skull-flash {\n 0% { transform: scale(1.3); }\n 100% { transform: scale(1); }\n}\n\n.tdr-idle {\n font-size: 0.85rem;\n color: #888;\n font-style: italic;\n}\n\n.tdr-section h3 {\n font-size: 0.65rem;\n text-transform: uppercase;\n letter-spacing: 0.08em;\n color: #888;\n margin: 0.6rem 0 0.3rem;\n}\n\n/* ── LED Grid ── */\n\n.tdr-layer {\n display: flex;\n align-items: center;\n gap: 0.4rem;\n padding: 0.15rem 0;\n}\n\n.tdr-layer-label {\n font-size: 0.65rem;\n color: #888;\n width: 7rem;\n text-align: right;\n flex-shrink: 0;\n}\n\n.tdr-led {\n width: 20px;\n height: 20px;\n border-radius: 50%;\n background: #333;\n border: 1px solid #555;\n display: inline-block;\n transition: background 0.2s;\n}\n\n.tdr-led[data-effect=\"on\"] {\n background: #f0c040;\n box-shadow: 0 0 6px rgba(240, 192, 64, 0.5);\n}\n\n.tdr-led[data-effect=\"breathe\"] {\n background: #80a0ff;\n animation: tdr-breathe 2s ease-in-out infinite;\n}\n\n.tdr-led[data-effect=\"breathe-fast\"] {\n background: #80a0ff;\n animation: tdr-breathe 0.8s ease-in-out infinite;\n}\n\n.tdr-led[data-effect=\"breathe-50\"] {\n background: #80a0ff;\n animation: tdr-breathe 2s ease-in-out infinite;\n opacity: 0.5;\n}\n\n.tdr-led[data-effect=\"flicker\"] {\n background: #ff6040;\n animation: tdr-flicker 0.3s step-end infinite;\n}\n\n/* ── Drums ── */\n\n.tdr-drum {\n display: inline-flex;\n align-items: center;\n gap: 0.5rem;\n padding: 0.3rem 0;\n}\n\n.tdr-drum-name {\n font-size: 0.75rem;\n font-weight: 600;\n color: #e8e8e8;\n}\n\n.tdr-drum-pos {\n font-size: 0.85rem;\n font-weight: 700;\n color: #c0392b;\n}\n\n.tdr-drum-cal {\n font-size: 0.75rem;\n color: #888;\n}\n\n.tdr-glyph {\n font-size: 0.7rem;\n color: #f39c12;\n font-style: italic;\n}\n\n/* ── Audio ── */\n\n.tdr-audio {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n font-size: 0.8rem;\n}\n\n.tdr-audio-name {\n color: #e8e8e8;\n font-weight: 500;\n}\n\n.tdr-audio-loop {\n font-size: 0.65rem;\n color: #27ae60;\n border: 1px solid #27ae60;\n border-radius: 3px;\n padding: 0 4px;\n}\n\n.tdr-audio-vol {\n font-size: 0.65rem;\n color: #888;\n}\n\n/* ── Skull / Beam ── */\n\n.tdr-skull-drop {\n color: #e74c3c;\n font-weight: 700;\n font-size: 0.9rem;\n margin-top: 0.5rem;\n animation: tdr-skull-flash 0.6s ease-out;\n}\n\n.tdr-beam-count {\n font-size: 0.8rem;\n color: #888;\n margin-top: 0.5rem;\n}\n\n/* ── LED Sequence Override ── */\n\n.tdr-led-seq {\n font-size: 0.75rem;\n color: #f39c12;\n margin-top: 0.3rem;\n}\n`;\n\n/**\n * Injects the tower display readout stylesheet into `document.head`.\n * Safe to call multiple times — the `<style>` tag is only appended once.\n */\nexport function injectStyles(): void {\n if (injected) return;\n styleElement = document.createElement('style');\n styleElement.textContent = CSS;\n document.head.appendChild(styleElement);\n injected = true;\n}\n\n/**\n * Reset the injection guard (for testing only).\n * @internal\n */\nexport function _resetStyleInjection(): void {\n if (styleElement) {\n styleElement.remove();\n styleElement = null;\n }\n injected = false;\n}\n","import {\n type TowerState,\n GLYPHS,\n TOWER_AUDIO_LIBRARY,\n TOWER_LIGHT_SEQUENCES,\n VOLUME_DESCRIPTIONS,\n LAYER_TO_POSITION,\n LIGHT_INDEX_TO_DIRECTION,\n LIGHT_EFFECTS,\n} from 'ultimatedarktower';\nimport type { ITowerDisplay } from './types';\nimport { injectStyles } from './styles';\n\nconst COMPASS = ['N', 'E', 'S', 'W'] as const;\nconst COMPASS_FULL = ['north', 'east', 'south', 'west'] as const;\nconst DRUM_NAMES = ['Top', 'Middle', 'Bottom'] as const;\nconst DRUM_LEVELS = ['top', 'middle', 'bottom'] as const;\n\n/** Escape HTML special characters to prevent XSS when interpolating into innerHTML. */\nfunction esc(str: string): string {\n return str\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"');\n}\n\n// Build reverse lookup maps once at module level\nconst EFFECT_LABELS: Record<number, string> = {\n [LIGHT_EFFECTS.off]: 'off',\n [LIGHT_EFFECTS.on]: 'on',\n [LIGHT_EFFECTS.breathe]: 'breathe',\n [LIGHT_EFFECTS.breatheFast]: 'breathe-fast',\n [LIGHT_EFFECTS.breathe50percent]: 'breathe-50',\n [LIGHT_EFFECTS.flicker]: 'flicker',\n};\n\nconst SEQUENCE_LABELS: Record<number, string> = Object.fromEntries(\n Object.entries(TOWER_LIGHT_SEQUENCES).map(([name, val]) => [val, name]),\n);\n\nconst AUDIO_BY_VALUE: Map<number, string> = new Map(\n Object.values(TOWER_AUDIO_LIBRARY).map((entry) => [entry.value, entry.name]),\n);\n\n/**\n * Core DOM renderer for tower state.\n *\n * Renders a live readout of LED grid, drum positions, audio state,\n * skull drops, and LED sequence overrides.\n *\n * @example\n * ```ts\n * const readout = new TowerStateReadout(document.getElementById('tower')!);\n * readout.applyState(state);\n * ```\n */\nexport class TowerStateReadout implements ITowerDisplay {\n private readonly container: HTMLElement;\n private prevBeamCount: number | null = null;\n\n constructor(container: HTMLElement) {\n this.container = container;\n injectStyles();\n this.showIdle();\n }\n\n /** Update the display with a new decoded tower state. */\n applyState(state: TowerState): void {\n const skullDrop = this.prevBeamCount !== null && state.beam.count > this.prevBeamCount;\n this.prevBeamCount = state.beam.count;\n this.render(state, skullDrop);\n }\n\n /** Reset the display to its idle/waiting state. */\n showIdle(): void {\n this.container.innerHTML = '<p class=\"tdr-idle\">Waiting for tower state\\u2026</p>';\n }\n\n /** Remove all rendered DOM content and reset internal state. */\n dispose(): void {\n this.container.innerHTML = '';\n this.prevBeamCount = null;\n }\n\n private render(state: TowerState, skullDrop: boolean): void {\n // --- LEDs: 6 layers × 4 lights ---\n const ledRows = state.layer.map((layer, li) => {\n const layerName = LAYER_TO_POSITION[li as keyof typeof LAYER_TO_POSITION] ?? `L${li}`;\n const lights = layer.light.map((light, ji) => {\n const eff = EFFECT_LABELS[light.effect] ?? 'off';\n const dir = LIGHT_INDEX_TO_DIRECTION[ji as keyof typeof LIGHT_INDEX_TO_DIRECTION] ?? ji;\n return `<span class=\"tdr-led\" data-effect=\"${esc(eff)}\" title=\"${esc(`${layerName} ${dir}: ${eff}${light.loop ? ' (loop)' : ''}`)}\"></span>`;\n }).join('');\n return `<div class=\"tdr-layer\"><span class=\"tdr-layer-label\">${esc(layerName)}</span>${lights}</div>`;\n }).join('');\n\n // --- Drums ---\n const drumRows = state.drum.map((drum, di) => {\n const dir = COMPASS[drum.position] ?? '?';\n const cal = drum.calibrated ? '\\u2713' : '\\u2014';\n const activeGlyph = this.findGlyph(di, drum.position, drum.calibrated);\n return `<div class=\"tdr-drum\">\n <span class=\"tdr-drum-name\">${esc(DRUM_NAMES[di])}</span>\n <span class=\"tdr-drum-pos\">${esc(dir)}</span>\n <span class=\"tdr-drum-cal\" title=\"Calibrated: ${drum.calibrated}\">${cal}</span>\n ${activeGlyph ? `<span class=\"tdr-glyph\">${esc(activeGlyph)}</span>` : ''}\n </div>`;\n }).join('');\n\n // --- Audio ---\n const audioName = this.lookupAudio(state.audio.sample, state.audio.loop);\n const volLabel = VOLUME_DESCRIPTIONS[state.audio.volume as keyof typeof VOLUME_DESCRIPTIONS] ?? `Vol ${state.audio.volume}`;\n const audioHtml = `<div class=\"tdr-audio\">\n <span class=\"tdr-audio-name\">${esc(audioName)}</span>\n ${state.audio.loop ? '<span class=\"tdr-audio-loop\">loop</span>' : ''}\n <span class=\"tdr-audio-vol\">${esc(volLabel)}</span>\n </div>`;\n\n // --- Skull drop / beam ---\n const skullHtml = skullDrop\n ? `<div class=\"tdr-skull-drop\">\\uD83D\\uDC80 Skull Drop! (${state.beam.count})</div>`\n : `<div class=\"tdr-beam-count\">Skulls: ${state.beam.count}${state.beam.fault ? ' \\u26A0 fault' : ''}</div>`;\n\n // --- LED sequence override ---\n const seqLabel = SEQUENCE_LABELS[state.led_sequence] ?? `0x${state.led_sequence.toString(16).padStart(2, '0')}`;\n const seqHtml = state.led_sequence !== 0\n ? `<div class=\"tdr-led-seq\">LED Sequence: ${esc(seqLabel)}</div>`\n : '';\n\n this.container.innerHTML = `\n <div class=\"tdr-section tdr-leds\"><h3>LEDs</h3>${ledRows}</div>\n <div class=\"tdr-section tdr-drums\"><h3>Drums</h3>${drumRows}</div>\n <div class=\"tdr-section tdr-info\">\n ${audioHtml}\n ${skullHtml}\n ${seqHtml}\n </div>\n `;\n }\n\n /**\n * Find the glyph name on the north-facing side of a drum, if any.\n * Only valid when the drum is calibrated.\n */\n private findGlyph(drumIndex: number, position: number, calibrated: boolean): string | null {\n if (!calibrated) return null;\n const level = DRUM_LEVELS[drumIndex];\n const facing = COMPASS_FULL[position];\n for (const glyph of Object.values(GLYPHS)) {\n if (glyph.level === level && glyph.side === facing) {\n return glyph.name;\n }\n }\n return null;\n }\n\n /** Look up an audio sample name from TOWER_AUDIO_LIBRARY by value. */\n private lookupAudio(sample: number, loop: boolean): string {\n if (sample === 0 && !loop) return 'Silence';\n return AUDIO_BY_VALUE.get(sample) ?? `Sample ${sample}`;\n }\n}\n","import type { TowerState } from 'ultimatedarktower';\nimport type { TowerDisplayOptions, ITowerDisplay } from './types';\nimport { TowerStateReadout } from './TowerStateReadout';\n\n/**\n * TowerDisplay renders decoded tower state into a DOM container.\n *\n * @example\n * ```ts\n * const display = new TowerDisplay({\n * container: document.getElementById('tower')!,\n * });\n * display.applyState(state);\n * ```\n */\nexport class TowerDisplay implements ITowerDisplay {\n private readonly impl: TowerStateReadout;\n\n constructor(options: TowerDisplayOptions) {\n this.impl = new TowerStateReadout(options.container);\n }\n\n /** Update the display with a new decoded tower state. */\n applyState(state: TowerState): void {\n this.impl.applyState(state);\n }\n\n /** Reset the display to its idle/waiting state. */\n showIdle(): void {\n this.impl.showIdle();\n }\n\n /** Remove all rendered DOM content and reset internal state. */\n dispose(): void {\n this.impl.dispose();\n }\n}\n"],"names":["injected","styleElement","CSS","injectStyles","COMPASS","COMPASS_FULL","DRUM_NAMES","DRUM_LEVELS","esc","str","EFFECT_LABELS","LIGHT_EFFECTS","SEQUENCE_LABELS","TOWER_LIGHT_SEQUENCES","name","val","AUDIO_BY_VALUE","TOWER_AUDIO_LIBRARY","entry","TowerStateReadout","container","state","skullDrop","ledRows","layer","li","layerName","LAYER_TO_POSITION","lights","light","ji","eff","dir","LIGHT_INDEX_TO_DIRECTION","drumRows","drum","di","cal","activeGlyph","audioName","volLabel","VOLUME_DESCRIPTIONS","audioHtml","skullHtml","seqLabel","seqHtml","drumIndex","position","calibrated","level","facing","glyph","GLYPHS","sample","loop","TowerDisplay","options"],"mappings":";AAAA,IAAIA,IAAW,IACXC,IAAwC;AAE5C,MAAMC,IAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,KAAK,CAACC,IAAa,YAC3BtC,EAAe,IAAIqC,CAAM,KAAK,UAAUA,CAAM;AAAA,EACvD;AACF;ACnJO,MAAME,EAAsC;AAAA,EAGjD,YAAYC,GAA8B;AACxC,SAAK,OAAO,IAAIrC,EAAkBqC,EAAQ,SAAS;AAAA,EACrD;AAAA;AAAA,EAGA,WAAWnC,GAAyB;AAClC,SAAK,KAAK,WAAWA,CAAK;AAAA,EAC5B;AAAA;AAAA,EAGA,WAAiB;AACf,SAAK,KAAK,SAAA;AAAA,EACZ;AAAA;AAAA,EAGA,UAAgB;AACd,SAAK,KAAK,QAAA;AAAA,EACZ;AACF;"}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injects the tower display readout stylesheet into `document.head`.
|
|
3
|
+
* Safe to call multiple times — the `<style>` tag is only appended once.
|
|
4
|
+
*/
|
|
5
|
+
export declare function injectStyles(): void;
|
|
6
|
+
/**
|
|
7
|
+
* Reset the injection guard (for testing only).
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function _resetStyleInjection(): void;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TowerState } from 'ultimatedarktower';
|
|
2
|
+
/** Configuration options for TowerDisplay. */
|
|
3
|
+
export interface TowerDisplayOptions {
|
|
4
|
+
/** DOM element to render into. */
|
|
5
|
+
container: HTMLElement;
|
|
6
|
+
}
|
|
7
|
+
/** Public interface for all display implementations. */
|
|
8
|
+
export interface ITowerDisplay {
|
|
9
|
+
/** Update the display with a new decoded tower state. */
|
|
10
|
+
applyState(state: TowerState): void;
|
|
11
|
+
/** Reset the display to its idle/waiting state. */
|
|
12
|
+
showIdle(): void;
|
|
13
|
+
/** Remove all rendered DOM content and reset internal state. */
|
|
14
|
+
dispose(): void;
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ultimatedarktowerdisplay",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "DOM-based state readout for the Ultimate Dark Tower board game.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs.js",
|
|
7
|
+
"module": "dist/index.esm.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.esm.js",
|
|
12
|
+
"require": "./dist/index.cjs.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"CHANGELOG.md"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vite build && tsc --emitDeclarationOnly",
|
|
25
|
+
"build:example": "vite build --config vite.config.example.ts",
|
|
26
|
+
"dev": "vite",
|
|
27
|
+
"dev:example": "vite --open /example/index.html",
|
|
28
|
+
"test": "jest --config jest.config.cjs",
|
|
29
|
+
"test:watch": "jest --config jest.config.cjs --watch",
|
|
30
|
+
"test:coverage": "jest --config jest.config.cjs --coverage",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"lint": "eslint 'src/**/*.ts' 'tests/**/*.ts'",
|
|
33
|
+
"lint:fix": "eslint 'src/**/*.ts' 'tests/**/*.ts' --fix",
|
|
34
|
+
"format": "prettier --write 'src/**/*.ts' 'tests/**/*.ts'",
|
|
35
|
+
"clean": "rm -rf dist dist-example coverage",
|
|
36
|
+
"ci": "npm run typecheck && npm run lint && npm test && npm run build"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"ultimatedarktower": "^2.1.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/jest": "^29.5.0",
|
|
43
|
+
"jest": "^29.7.0",
|
|
44
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
45
|
+
"ts-jest": "^29.1.0",
|
|
46
|
+
"typescript": "^5.4.0",
|
|
47
|
+
"vite": "^5.4.0",
|
|
48
|
+
"eslint": "^8.57.0",
|
|
49
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
51
|
+
"prettier": "^3.2.0",
|
|
52
|
+
"ultimatedarktower": "^2.1.0"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"ReturnToDarkTower",
|
|
56
|
+
"BoardGame",
|
|
57
|
+
"display",
|
|
58
|
+
"tower-state",
|
|
59
|
+
"DOM",
|
|
60
|
+
"UltimateDarkTower"
|
|
61
|
+
],
|
|
62
|
+
"author": "ChessMess",
|
|
63
|
+
"license": "MIT",
|
|
64
|
+
"repository": {
|
|
65
|
+
"type": "git",
|
|
66
|
+
"url": "https://github.com/ChessMess/UltimateDarkTowerDisplay.git"
|
|
67
|
+
},
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/ChessMess/UltimateDarkTowerDisplay/issues"
|
|
70
|
+
},
|
|
71
|
+
"homepage": "https://github.com/ChessMess/UltimateDarkTowerDisplay#readme",
|
|
72
|
+
"publishConfig": {
|
|
73
|
+
"access": "public"
|
|
74
|
+
},
|
|
75
|
+
"engines": {
|
|
76
|
+
"node": ">=18.0.0",
|
|
77
|
+
"npm": ">=7.0.0"
|
|
78
|
+
}
|
|
79
|
+
}
|