@ruinosus/dna-render 0.1.0 → 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/README.md +36 -8
- package/dist/demo.html +25 -0
- package/dist/dna-render.global.js +116 -93
- package/index.mjs +233 -7
- package/package.json +1 -1
- package/play.html +118 -94
package/README.md
CHANGED
|
@@ -4,26 +4,54 @@ Reads a DNA file, checks it against its Kind and draws it — like Mermaid in ho
|
|
|
4
4
|
drawing; a broken one says its line), without using Mermaid. The Kinds come from packs, such as
|
|
5
5
|
[@ruinosus/keepforge-kinds](../keepforge-kinds/README.md).
|
|
6
6
|
|
|
7
|
+
## In a page, like Mermaid
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<pre class="dna" data-present>
|
|
11
|
+
apiVersion: github.com/ruinosus/keepforge/v1
|
|
12
|
+
kind: Fluxo
|
|
13
|
+
…
|
|
14
|
+
</pre>
|
|
15
|
+
<script src="dna-render.global.js"></script>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The global script (`dist/dna-render.global.js`: `window.DNA`, with the YAML reader and the keepforge Kinds inside, no
|
|
19
|
+
network) draws every `<pre class="dna">` and `<code class="language-dna">` (a ```` ```dna ```` fence) once the page has
|
|
20
|
+
loaded. `window.DNA_AUTORUN = false` (before the script) or `data-autorun="false"` on the script turns that off;
|
|
21
|
+
`DNA.run()` draws what comes later. `data-present` on a block adds a **▶ Present** button. `dist/demo.html` is exactly
|
|
22
|
+
this: one script tag and one block.
|
|
23
|
+
|
|
24
|
+
## Present
|
|
25
|
+
|
|
26
|
+
`DNA.present(el | text | [{ title, text }])` shows a block full screen as slides: the whole drawing, then one Fluxo
|
|
27
|
+
phase, Quest step, Album page, Pesca rarity or Gdd system at a time, lit and told below. ← → (space, PageUp/PageDown)
|
|
28
|
+
move, **Esc** closes, **F** is full screen, a swipe moves on a phone. It returns `{ show(n), update(blocks), close() }`
|
|
29
|
+
— `update` follows an edit. `DNA.slides(blocks)` builds the same slides without a page, and `DNA.paint(el, slide)`
|
|
30
|
+
draws one into your own frame (the VS Code extension's panel).
|
|
31
|
+
|
|
32
|
+
## In code
|
|
33
|
+
|
|
7
34
|
```js
|
|
8
|
-
import { use, check, render, toMermaid } from '@ruinosus/dna-render'
|
|
35
|
+
import { use, check, checkPack, render, toMermaid, exportDoc, exportPack, slides } from '@ruinosus/dna-render'
|
|
9
36
|
import keepforge from '@ruinosus/keepforge-kinds'
|
|
10
37
|
|
|
11
38
|
use(keepforge)
|
|
12
39
|
check(text, { file: 'pescaria.fluxo.dna.yaml' }) // { doc, kind, errors: [{ line, msg }] } — every error at once
|
|
13
40
|
render(text) // { ok, kind, html, errors } — in a page it also adds its CSS, once
|
|
14
41
|
toMermaid(text) // Mermaid text (Fluxo → stateDiagram-v2, Quest → flowchart), or null
|
|
42
|
+
checkPack([{ file, text }, …]) // { files, errors: [{ file, line, msg }], manifest } — files against each other
|
|
43
|
+
exportDoc(text, { format: 'luau', shape }) // { data, text } — a file as a game's data
|
|
44
|
+
exportPack(files, { file: 'Quest/*', format }) // one export of dna-pack.yaml
|
|
15
45
|
```
|
|
16
46
|
|
|
17
|
-
- `register(kind, { apiVersion, schema, rules?, draw?, mermaid
|
|
18
|
-
|
|
19
|
-
|
|
47
|
+
- `register(kind, { apiVersion, schema, rules?, refs?, ids?, packRules?, draw?, mermaid?, present?, export?, exportAll? })`
|
|
48
|
+
adds a Kind; `use(pack)` adds a pack's Kinds. `refs` and `ids` are what a file says of the others in a pack.
|
|
49
|
+
- The core has one Kind of its own: `Pack` (`dna-pack.yaml`, `github.com/ruinosus/dna/v1`), a pack's manifest.
|
|
20
50
|
- `css` is the drawings' style, for a page made outside a browser.
|
|
21
|
-
- **`dist/dna-render.global.js`**: one script for a page (`window.DNA`, the same API), with the YAML reader and the
|
|
22
|
-
keepforge Kinds inside — no network, no module loader. It is what the VS Code extension's preview loads.
|
|
23
51
|
- **`play.html`**: paste and see, offline — edit on the left, the drawing and its errors on the right, the Mermaid
|
|
24
|
-
below,
|
|
52
|
+
below, a link that keeps the text, and ▶ Present.
|
|
25
53
|
|
|
26
54
|
The drawings keep their classes for whoever builds on them: a Fluxo phase is a `.dna-node` (`.dna-start`,
|
|
27
|
-
`.dna-end`), a Quest step a `.dna-steps li`.
|
|
55
|
+
`.dna-end`), a Quest step a `.dna-steps li`; the lit item of a slide gets `.dna-lit` inside `.dna-stepping`.
|
|
28
56
|
|
|
29
57
|
Built by `npm run assets -w dev/dna-notation/tools` (and by `prepack`).
|
package/dist/demo.html
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
3
|
+
<title>DNA in a page</title></head>
|
|
4
|
+
<body style="font:16px/1.5 system-ui,sans-serif;max-width:900px;margin:0 auto;padding:24px 16px">
|
|
5
|
+
<h1>DNA in a page</h1>
|
|
6
|
+
<p>One script tag and one block, like Mermaid: the block is drawn when the page loads. <code>data-present</code> adds a ▶ button that presents it, one phase per slide (← →, Esc, F).</p>
|
|
7
|
+
|
|
8
|
+
<pre class="dna" data-present>apiVersion: github.com/ruinosus/keepforge/v1
|
|
9
|
+
kind: Fluxo
|
|
10
|
+
metadata:
|
|
11
|
+
name: pescaria
|
|
12
|
+
spec:
|
|
13
|
+
title: Pescaria
|
|
14
|
+
start: lancar
|
|
15
|
+
phases:
|
|
16
|
+
- {id: lancar, secs: 0.8, input: segurar, camera: {shot: ombro, fov: 70}, next: [espera]}
|
|
17
|
+
- {id: espera, secs: "3-9", camera: {shot: aberto, fov: 80}, next: [fisgada]}
|
|
18
|
+
- {id: fisgada, secs: 1.2, input: tocar, camera: {shot: close, fov: 50}, next: [puxar, escapa]}
|
|
19
|
+
- {id: puxar, secs: "2-6", input: segurar, camera: {shot: close, fov: 50}, next: [captura, escapa]}
|
|
20
|
+
- {id: captura, secs: 1.5, camera: {shot: aberto, fov: 70}, end: true}
|
|
21
|
+
- {id: escapa, secs: 1, end: true}
|
|
22
|
+
</pre>
|
|
23
|
+
|
|
24
|
+
<script src="dna-render.global.js"></script>
|
|
25
|
+
</body></html>
|