@enmaq/mdgl 0.3.1 → 0.4.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/README.md +63 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +10 -0
- package/dist/browser.mjs +1489 -0
- package/dist/dom.d.ts +25 -0
- package/dist/dom.js +206 -0
- package/dist/index.js +1 -1
- package/dist/parse.js +2 -1
- package/dist/player.d.ts +2 -0
- package/dist/player.js +77 -0
- package/mdgl.css +52 -0
- package/package.json +23 -6
package/README.md
CHANGED
|
@@ -81,6 +81,69 @@ Limits: the terminal must be at least as wide and tall as the scene (no resize h
|
|
|
81
81
|
Library: `play(scene, {write, clock, onWriteError?, onInterrupt?})` returns `{done, stop}` and does no I/O itself;
|
|
82
82
|
`examples/play.mjs` shows the wiring, and `plainFallback(scene)` gives the redirected-output text.
|
|
83
83
|
|
|
84
|
+
## Browser player (0.4.0)
|
|
85
|
+
|
|
86
|
+
The browser API reuses the same terminal-cell evaluator. Separate subpath imports
|
|
87
|
+
keep DOM types out of the Node-only entry:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { renderToElement } from '@enmaq/mdgl/dom';
|
|
91
|
+
import '@enmaq/mdgl/mdgl.css';
|
|
92
|
+
const player = renderToElement(document.getElementById('scene')!, source, {
|
|
93
|
+
maxCells: 12000, maxFps: 30,
|
|
94
|
+
palette: { accent: '#2563eb' },
|
|
95
|
+
onError: message => console.warn(message),
|
|
96
|
+
});
|
|
97
|
+
// Viewport owners can call player.pause() / player.play().
|
|
98
|
+
// On unmount: player.destroy(), or stop() to retain the final frame.
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`renderToElement(element, source, options?)` replaces the contents with one `<pre>`
|
|
102
|
+
containing adjacent color runs. Invalid scenes/options show literal source plus
|
|
103
|
+
a diagnostic, set `player.error`, and call `onError` if supplied. Source is never
|
|
104
|
+
interpreted as HTML. Replacing a player stops the previous one. `stop()` is
|
|
105
|
+
permanent; `pause()`/`play()` preserve elapsed scene time. `autoplay: false`
|
|
106
|
+
starts paused on the declared fallback; first `play()` starts at time zero.
|
|
107
|
+
Finite scenes finish automatically. RAF uses monotonic elapsed
|
|
108
|
+
time and drops late frames. The scene fps and `maxFps` both apply; defaults are
|
|
109
|
+
30 fps and 12000 cells, with hard ceilings of 60 fps and 12000 cells. Larger
|
|
110
|
+
stages are rejected, not cropped. Existing checker source limits still apply.
|
|
111
|
+
|
|
112
|
+
Omitting `reducedMotion` follows live `prefers-reduced-motion` changes. `true`
|
|
113
|
+
shows the scene's declared fallback without animation; `false` explicitly
|
|
114
|
+
enables motion. A nonvisual document without RAF also displays the fallback.
|
|
115
|
+
Author `fallback=end` for a meaningful reduced-motion end state.
|
|
116
|
+
|
|
117
|
+
For a plain page, copy built `dist/browser.mjs` and `mdgl.css` alongside it:
|
|
118
|
+
|
|
119
|
+
```html
|
|
120
|
+
<link rel="stylesheet" href="./mdgl.css">
|
|
121
|
+
<script type="module" src="./browser.mjs"></script>
|
|
122
|
+
<mdgl-player>
|
|
123
|
+
scene width=24 height=2 fallback=end
|
|
124
|
+
actor greeting = text("Hello") at (1,0) color=accent
|
|
125
|
+
@0: greeting.type(per_char=0.15)
|
|
126
|
+
</mdgl-player>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The browser module exports the API and registers `<mdgl-player>` once. Bundlers
|
|
130
|
+
may instead call `registerMDGLPlayer()` from `@enmaq/mdgl/player`. The element
|
|
131
|
+
accepts inline text or `src="scene.mdgl"` (HTTP(S), normal CORS rules), plus
|
|
132
|
+
`max-cells`, `max-fps`, and `reduced-motion` attributes. Use its `source` property
|
|
133
|
+
for later inline-source updates. Removing the element cancels animation and
|
|
134
|
+
pending fetches; reconnecting reuses its source. `src` takes precedence over
|
|
135
|
+
inline source. Fetch failures show literal diagnostics; superseded responses
|
|
136
|
+
cannot overwrite newer scenes. Inline markup characters must be HTML-escaped
|
|
137
|
+
or assigned through `source`.
|
|
138
|
+
|
|
139
|
+
The stylesheet provides light/dark defaults for all ten `--mdgl-COLOR` variables
|
|
140
|
+
and `--mdgl-background`. Override them on the host for an application's theme,
|
|
141
|
+
or use the `palette` option for named foreground colors. Evaluator-generated
|
|
142
|
+
fade RGB values remain exact, including terminal black-background blending.
|
|
143
|
+
This is a monospace cell renderer, not WebGL.
|
|
144
|
+
|
|
145
|
+
`npm run test:dom` runs targeted DOM fixture parity and lifecycle regressions.
|
|
146
|
+
|
|
84
147
|
## Development
|
|
85
148
|
|
|
86
149
|
`npm test` builds, type-checks `test/consumer/consumer.ts` and runs the tests,
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerMDGLPlayer = exports.MDGL_COLORS = exports.renderToElement = void 0;
|
|
4
|
+
var dom_1 = require("./dom");
|
|
5
|
+
Object.defineProperty(exports, "renderToElement", { enumerable: true, get: function () { return dom_1.renderToElement; } });
|
|
6
|
+
Object.defineProperty(exports, "MDGL_COLORS", { enumerable: true, get: function () { return dom_1.MDGL_COLORS; } });
|
|
7
|
+
var player_1 = require("./player");
|
|
8
|
+
Object.defineProperty(exports, "registerMDGLPlayer", { enumerable: true, get: function () { return player_1.registerMDGLPlayer; } });
|
|
9
|
+
const player_2 = require("./player");
|
|
10
|
+
(0, player_2.registerMDGLPlayer)();
|