skydancer 2.12.0 → 2.14.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 +27 -0
- package/README.md +24 -0
- package/package.json +1 -1
- package/skydancer.d.ts +26 -0
- package/skydancer.js +90 -12
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,33 @@ Embeds point at `@2`, which follows the newest `v2.x.x` tag, so everything
|
|
|
4
4
|
below reaches an existing embed as soon as it is tagged. This is the place to
|
|
5
5
|
look when a dancer starts looking different.
|
|
6
6
|
|
|
7
|
+
## v2.14.0 — 2026-11-23
|
|
8
|
+
|
|
9
|
+
- A dancer tells the page two things: `poke` when a reader pokes it, carrying
|
|
10
|
+
the word it blurted, and `arrive` once it has come into view and finished
|
|
11
|
+
filling with air. Both bubble and cross a shadow boundary, so one listener
|
|
12
|
+
on the section it sits in catches it. A page's own `cheer()` fires no
|
|
13
|
+
`poke`: it already knows it asked.
|
|
14
|
+
- **Fixed:** a dancer whose canvas lost its drawing context -- a driver
|
|
15
|
+
reset, or a phone short of memory with the tab in the background -- stayed
|
|
16
|
+
blank or came back at the wrong size. It asks for the context back now and
|
|
17
|
+
repaints when it has it.
|
|
18
|
+
- Customizer: a link to the repository, in the title row.
|
|
19
|
+
- Customizer: the script box offers the npm form as well as the CDN one. The
|
|
20
|
+
package has been installable since v2.11 and the page still only knew about
|
|
21
|
+
the script tag.
|
|
22
|
+
|
|
23
|
+
## v2.13.0 — 2026-11-23
|
|
24
|
+
|
|
25
|
+
- `link-label` and `poke-label` say the two bits of wording a reader meets
|
|
26
|
+
rather than sees. They were English only, which on a page in another
|
|
27
|
+
language was the only English a screen reader hit.
|
|
28
|
+
- **Fixed:** a negative `girth` asked the canvas for a negative radius and
|
|
29
|
+
threw on every frame, leaving nothing on screen; an enormous one left
|
|
30
|
+
nothing on screen either. Numbers that have a sensible range are held to
|
|
31
|
+
it now, since a dancer's settings can arrive from a page's templating or
|
|
32
|
+
a shared link rather than from someone watching the result.
|
|
33
|
+
|
|
7
34
|
## v2.12.0 — 2026-11-20
|
|
8
35
|
|
|
9
36
|
- Pushing a version tag publishes to npm, with provenance, instead of it
|
package/README.md
CHANGED
|
@@ -56,6 +56,8 @@ The widget is 400px tall by default and crops to the dancer: its width follows i
|
|
|
56
56
|
| `speed` | `1` | animation speed |
|
|
57
57
|
| `wildness` | `1` | how much it flails |
|
|
58
58
|
| `wind` | `1` | wind strength; `0` is calm. Scales the gusts, the pointer, and the page scrolling past |
|
|
59
|
+
| `link-label` | none | what the link is called when the sign says nothing; English `Find out more` otherwise |
|
|
60
|
+
| `poke-label` | none | what the poke button is called; English `Poke the dancer` otherwise |
|
|
59
61
|
| `hours` | none | when it is worth dancing, as `9-17`; `22-6` runs through midnight. Outside them the air is out and the dancer lies flat |
|
|
60
62
|
| `face` | `happy` | `happy`, `surprised`, `cool`, `wink`, `joy`, `sleepy` or `angry` |
|
|
61
63
|
| `pattern` | `none` | markings on the body: `none`, `rings` or `spiral` |
|
|
@@ -127,6 +129,28 @@ document.querySelector('sky-dancer').hide();
|
|
|
127
129
|
|
|
128
130
|
A hidden dancer stops animating and costs nothing until it is shown again.
|
|
129
131
|
|
|
132
|
+
### Events
|
|
133
|
+
|
|
134
|
+
A dancer says two things, both bubbling and both crossing a shadow boundary,
|
|
135
|
+
so one listener on the section it sits in is enough:
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
document.addEventListener('poke', e => {
|
|
139
|
+
console.log('poked, and it said', e.detail.shout); // '' when it has no shout
|
|
140
|
+
});
|
|
141
|
+
document.addEventListener('arrive', () => { /* it is up */ });
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
`poke` is a reader poking it, by pointer or by the poke button. Your own
|
|
145
|
+
`cheer()` does not fire one — the page already knows it asked — and neither
|
|
146
|
+
does a poke that lands on a dancer holding a still pose, since nothing
|
|
147
|
+
happened.
|
|
148
|
+
|
|
149
|
+
`arrive` fires once each time a dancer comes into view, as soon as the air
|
|
150
|
+
has settled. The fill takes the best part of a second, which is what makes it
|
|
151
|
+
worth waiting for; on a held pose, or on one deliberately deflated, there is
|
|
152
|
+
nothing to fill and it fires straight away.
|
|
153
|
+
|
|
130
154
|
Poking a dancer knocks the air out of it. Where the viewer's system asks for reduced motion, it holds a still pose instead of animating.
|
|
131
155
|
|
|
132
156
|
## Customizer
|
package/package.json
CHANGED
package/skydancer.d.ts
CHANGED
|
@@ -14,6 +14,20 @@ export type SkyDancerPattern = 'none' | 'rings' | 'spiral';
|
|
|
14
14
|
/** The shape of the speech balloon. */
|
|
15
15
|
export type SkyDancerBubble = 'drawn' | 'box' | 'burst';
|
|
16
16
|
|
|
17
|
+
/** What a dancer blurted, along with the poke that got it out of it. */
|
|
18
|
+
export interface SkyDancerPokeDetail {
|
|
19
|
+
/** The phrase it shouted, or `''` when it has no `shout` to give. */
|
|
20
|
+
shout: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The events a dancer fires. Both bubble and cross a shadow boundary. */
|
|
24
|
+
export interface SkyDancerEventMap {
|
|
25
|
+
/** A reader poked it. `cheer()` does not fire this. */
|
|
26
|
+
poke: CustomEvent<SkyDancerPokeDetail>;
|
|
27
|
+
/** It has come into view and finished filling with air. */
|
|
28
|
+
arrive: CustomEvent<null>;
|
|
29
|
+
}
|
|
30
|
+
|
|
17
31
|
/**
|
|
18
32
|
* The element itself. Every setting is an attribute, so the methods below are
|
|
19
33
|
* the whole of the interface.
|
|
@@ -79,6 +93,12 @@ export interface SkyDancerAttributes {
|
|
|
79
93
|
sign?: string;
|
|
80
94
|
/** The balloon's shape. Default `drawn`. */
|
|
81
95
|
bubble?: SkyDancerBubble;
|
|
96
|
+
/** What the link is called when the sign says nothing. English `Find out
|
|
97
|
+
* more` when unset. */
|
|
98
|
+
'link-label'?: string;
|
|
99
|
+
/** What the poke button is called. English `Poke the dancer` when
|
|
100
|
+
* unset. */
|
|
101
|
+
'poke-label'?: string;
|
|
82
102
|
/** When it is worth dancing, as `9-17`; `22-6` runs through midnight.
|
|
83
103
|
* Outside them the air is out and it lies flat. Read from the reader's own
|
|
84
104
|
* clock. Empty means always. */
|
|
@@ -90,6 +110,12 @@ declare global {
|
|
|
90
110
|
interface HTMLElementTagNameMap {
|
|
91
111
|
'sky-dancer': SkyDancerElement;
|
|
92
112
|
}
|
|
113
|
+
|
|
114
|
+
// Both events bubble, so they really can arrive at any element or at the
|
|
115
|
+
// document, and listening on a container is the usual way round. Declaring
|
|
116
|
+
// them on the dancer alone would leave the common case untyped, which is
|
|
117
|
+
// why this goes on the map every target shares.
|
|
118
|
+
interface GlobalEventHandlersEventMap extends SkyDancerEventMap {}
|
|
93
119
|
}
|
|
94
120
|
|
|
95
121
|
// No JSX declaration here on purpose: typing an intrinsic element means
|
package/skydancer.js
CHANGED
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
sign: '', // words in a speech bubble by the dancer; empty for none
|
|
35
35
|
bubble: 'drawn', // drawn | box | burst
|
|
36
36
|
hours: '', // when it is worth dancing, as `9-17`; empty for always
|
|
37
|
+
// The two bits of wording a reader meets rather than sees. They are in
|
|
38
|
+
// English because something has to be; a page in another language can
|
|
39
|
+
// say them its own way.
|
|
40
|
+
linkLabel: '', // what the link is called when the sign says nothing
|
|
41
|
+
pokeLabel: '', // what the poke button is called
|
|
37
42
|
};
|
|
38
43
|
|
|
39
44
|
const OFF = ['false', '0', 'no', 'off'];
|
|
@@ -52,6 +57,20 @@
|
|
|
52
57
|
return from < to ? h >= from && h < to : h >= from || h < to;
|
|
53
58
|
}
|
|
54
59
|
|
|
60
|
+
// What a number may be, when being outside it is worse than useless. A
|
|
61
|
+
// dancer's settings can arrive from a page's own templating or from a
|
|
62
|
+
// shared link, so they are not always written by someone watching the
|
|
63
|
+
// result: a negative girth asked the canvas for a negative radius and threw
|
|
64
|
+
// on every frame, and a girth of 100000 left nothing on screen at all.
|
|
65
|
+
// Outside these a dancer is still a dancer, just a silly one.
|
|
66
|
+
const LIMITS = {
|
|
67
|
+
girth: [1, 400],
|
|
68
|
+
armLength: [0, 3],
|
|
69
|
+
speed: [0, 20],
|
|
70
|
+
wildness: [0, 10],
|
|
71
|
+
wind: [0, 10],
|
|
72
|
+
};
|
|
73
|
+
|
|
55
74
|
const attrName = key => key.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
|
|
56
75
|
const KEYS = Object.keys(DEFAULTS);
|
|
57
76
|
|
|
@@ -61,7 +80,9 @@
|
|
|
61
80
|
if (typeof DEFAULTS[key] === 'number') {
|
|
62
81
|
// Number, not parseFloat: height="500px" should fall back, not mean 500x the canvas
|
|
63
82
|
const n = value.trim() === '' ? NaN : Number(value);
|
|
64
|
-
|
|
83
|
+
if (!Number.isFinite(n)) return DEFAULTS[key];
|
|
84
|
+
const bounds = LIMITS[key];
|
|
85
|
+
return bounds ? Math.min(bounds[1], Math.max(bounds[0], n)) : n;
|
|
65
86
|
}
|
|
66
87
|
return value;
|
|
67
88
|
}
|
|
@@ -408,6 +429,15 @@
|
|
|
408
429
|
observer.observe(canvas);
|
|
409
430
|
resize();
|
|
410
431
|
|
|
432
|
+
// A 2D context can be taken away -- a driver reset, or a phone short of
|
|
433
|
+
// memory while the tab is in the background. Nothing says so: the dancer
|
|
434
|
+
// simply stops being painted, and a held pose never paints again at all.
|
|
435
|
+
// Cancelling the loss is what asks for it back, and a context comes back
|
|
436
|
+
// with its size and its scale cleared, which is exactly what a resize
|
|
437
|
+
// puts right.
|
|
438
|
+
canvas.addEventListener('contextlost', e => e.preventDefault(), { signal: events.signal });
|
|
439
|
+
canvas.addEventListener('contextrestored', resize, { signal: events.signal });
|
|
440
|
+
|
|
411
441
|
// ---- simulation ----
|
|
412
442
|
// Everything is a chain of segments. Each segment adds a small bend to the
|
|
413
443
|
// running angle (0 = straight up, positive = leaning right), so travelling
|
|
@@ -494,6 +524,14 @@
|
|
|
494
524
|
const leadsTo = root.querySelector('.go');
|
|
495
525
|
const pokeButton = root.querySelector('.poke');
|
|
496
526
|
|
|
527
|
+
// What the page can hear. A dancer is mostly decoration, but a poke is a
|
|
528
|
+
// reader doing something and an arrival is a moment the page cannot see
|
|
529
|
+
// for itself. Both bubble and cross a shadow boundary, so one listener on
|
|
530
|
+
// the section a dancer sits in catches it however deeply it is nested.
|
|
531
|
+
function tell(name, detail = null) {
|
|
532
|
+
root.host.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));
|
|
533
|
+
}
|
|
534
|
+
|
|
497
535
|
// Somewhere a link may actually go. `javascript:` is the one that matters:
|
|
498
536
|
// the destination can reach this widget from a page's own templating or
|
|
499
537
|
// from the customizer's shareable link, so it is not always written by
|
|
@@ -530,7 +568,7 @@
|
|
|
530
568
|
let labelled = null;
|
|
531
569
|
|
|
532
570
|
function labelLink(sign) {
|
|
533
|
-
const label = sign || 'Find out more';
|
|
571
|
+
const label = sign || cfg.linkLabel.trim() || 'Find out more';
|
|
534
572
|
if (!aimed || label === labelled) return;
|
|
535
573
|
labelled = label;
|
|
536
574
|
leadsTo.textContent = label;
|
|
@@ -567,53 +605,62 @@
|
|
|
567
605
|
let lastTurn = 0;
|
|
568
606
|
let lastShout = -1; // which word the last poke took
|
|
569
607
|
|
|
570
|
-
function burst() {
|
|
608
|
+
function burst(byReader) {
|
|
571
609
|
// without a running loop nothing would decay the punch, so it would be
|
|
572
610
|
// saved up and spent the moment the dancer came back into view
|
|
573
611
|
if (held() || !visible) return;
|
|
574
612
|
// A poke takes one of them, never the one it took last: a flurry of
|
|
575
613
|
// pokes should be a flurry of different words.
|
|
576
614
|
const choices = phrasesOf(cfg.shout);
|
|
615
|
+
let said = ''; // what it blurted, which the page is told along with the poke
|
|
577
616
|
if (choices.length && lastChest) {
|
|
578
617
|
if (choices.length > 1) {
|
|
579
618
|
let pick = lastShout;
|
|
580
619
|
while (pick === lastShout) pick = Math.floor(Math.random() * choices.length);
|
|
581
620
|
lastShout = pick;
|
|
582
621
|
} else lastShout = 0;
|
|
583
|
-
|
|
622
|
+
said = choices[lastShout];
|
|
584
623
|
// at least a third of the way round from the last one, so two in a
|
|
585
624
|
// row never land on top of each other
|
|
586
625
|
lastTurn += Math.PI * (0.7 + Math.random() * 0.6);
|
|
587
626
|
const reach = cfg.girth * (1.5 + Math.random());
|
|
588
627
|
shouts.push({
|
|
589
|
-
words,
|
|
628
|
+
words: said,
|
|
590
629
|
x: lastChest.x + Math.cos(lastTurn) * reach,
|
|
591
630
|
y: lastChest.y + Math.sin(lastTurn) * reach * 0.7,
|
|
592
631
|
at: wall,
|
|
593
632
|
tilt: (Math.random() - 0.5) * 0.45,
|
|
594
633
|
});
|
|
595
634
|
if (shouts.length > SHOUTS) shouts.shift();
|
|
596
|
-
blurted.textContent =
|
|
635
|
+
blurted.textContent = said;
|
|
597
636
|
}
|
|
598
637
|
punch = 1;
|
|
599
638
|
kink = { start: t, dur: 0.9, dir: Math.random() < 0.5 ? -1 : 1, mag: 0.45 };
|
|
639
|
+
if (byReader) tell('poke', { shout: said });
|
|
600
640
|
}
|
|
601
641
|
|
|
602
|
-
|
|
603
|
-
|
|
642
|
+
// A reader's poke is worth telling the page about. The page's own cheer()
|
|
643
|
+
// is not: it already knows that it asked.
|
|
644
|
+
const poked = () => burst(true);
|
|
645
|
+
canvas.addEventListener('pointerdown', poked, { signal: events.signal });
|
|
646
|
+
pokeButton.addEventListener('click', poked, { signal: events.signal });
|
|
604
647
|
|
|
605
648
|
// Only offered when a poke has something to say, and when a poke would do
|
|
606
649
|
// anything at all. A dancer is decoration, and a decorative one that is
|
|
607
650
|
// merely wiggled has nothing to report to a reader who cannot see it -- so
|
|
608
651
|
// it stays out of the page's tab order rather than costing a stop per
|
|
609
652
|
// embed for a flourish. A held pose swallows a poke, so it offers none.
|
|
610
|
-
let offering = null;
|
|
653
|
+
let offering = null, offeredAs = null;
|
|
611
654
|
function offerPoke() {
|
|
612
655
|
const worth = phrasesOf(cfg.shout).length > 0 && !held();
|
|
613
|
-
|
|
656
|
+
const label = cfg.pokeLabel.trim() || 'Poke the dancer';
|
|
657
|
+
// the wording is watched as well as the offer, or renaming the button
|
|
658
|
+
// while it is already showing would not reach it
|
|
659
|
+
if (worth === offering && label === offeredAs) return;
|
|
614
660
|
offering = worth;
|
|
661
|
+
offeredAs = label;
|
|
615
662
|
pokeButton.hidden = !worth;
|
|
616
|
-
if (worth) pokeButton.textContent =
|
|
663
|
+
if (worth) pokeButton.textContent = label;
|
|
617
664
|
}
|
|
618
665
|
|
|
619
666
|
// A page can theme the dancer in CSS rather than in attributes, which is
|
|
@@ -710,6 +757,19 @@
|
|
|
710
757
|
air = { from, to, start: wall, dur };
|
|
711
758
|
}
|
|
712
759
|
|
|
760
|
+
// An arrival takes the best part of a second to fill, and a page watching
|
|
761
|
+
// for the dancer to be up cannot see the air going in. The telling waits
|
|
762
|
+
// for the stack to empty, since a breath lands in the middle of drawing a
|
|
763
|
+
// frame and a listener that poked the dancer back would reach it there.
|
|
764
|
+
let arriving = false;
|
|
765
|
+
function landed() {
|
|
766
|
+
if (!arriving) return;
|
|
767
|
+
arriving = false;
|
|
768
|
+
// Not if the dancer has gone in the meantime: stop() drops the flag, so
|
|
769
|
+
// a widget torn down in the same tick says nothing on its way out.
|
|
770
|
+
queueMicrotask(() => { if (visible) tell('arrive'); });
|
|
771
|
+
}
|
|
772
|
+
|
|
713
773
|
// how far the air has got, 0 flat to 1 full
|
|
714
774
|
function pressure() {
|
|
715
775
|
if (!air) return resting; // not 1: a dancer let down stays down
|
|
@@ -717,6 +777,7 @@
|
|
|
717
777
|
if (p >= 1) {
|
|
718
778
|
resting = air.to;
|
|
719
779
|
air = null;
|
|
780
|
+
landed();
|
|
720
781
|
return resting;
|
|
721
782
|
}
|
|
722
783
|
// eased, so it leaves and arrives without a jolt
|
|
@@ -746,6 +807,7 @@
|
|
|
746
807
|
if (!air) return;
|
|
747
808
|
resting = filled = air.to;
|
|
748
809
|
air = null;
|
|
810
|
+
landed();
|
|
749
811
|
}
|
|
750
812
|
|
|
751
813
|
// bend that swings a loose chain (arm, hair) round to point downwind
|
|
@@ -1499,8 +1561,19 @@
|
|
|
1499
1561
|
// A held pose has no clock to fill by, so it just stands there. One
|
|
1500
1562
|
// already part way in or out carries on from where it stopped: starting
|
|
1501
1563
|
// over would snap it flat.
|
|
1502
|
-
if (coming && !held()
|
|
1564
|
+
if (coming && !held()) {
|
|
1565
|
+
// Air already moving is this arrival, whichever way it is going.
|
|
1566
|
+
// Otherwise it fills -- unless it is meant to be lying flat, which is
|
|
1567
|
+
// nothing to wait for and was a breath that changed nothing.
|
|
1568
|
+
if (!air && resting > 0) breathe(0, resting, FILL);
|
|
1569
|
+
arriving = !!air;
|
|
1570
|
+
}
|
|
1571
|
+
// Nothing moving means it has settled already, so the arrival is now. A
|
|
1572
|
+
// breath still going says so itself when it lands. Asked before start(),
|
|
1573
|
+
// which is where a held pose finishes one, or that would be told twice.
|
|
1574
|
+
const settled = coming && !arriving;
|
|
1503
1575
|
start();
|
|
1576
|
+
if (settled) tell('arrive');
|
|
1504
1577
|
});
|
|
1505
1578
|
visibility.observe(canvas);
|
|
1506
1579
|
reduced.addEventListener('change', start, { signal: events.signal });
|
|
@@ -1525,6 +1598,11 @@
|
|
|
1525
1598
|
pump(to) {
|
|
1526
1599
|
if (held()) { // no frames to breathe with, so it lands at once
|
|
1527
1600
|
air = null;
|
|
1601
|
+
// Whatever was breathing has just landed, arrival included. Without
|
|
1602
|
+
// this an arrival interrupted off screen and then pumped while held
|
|
1603
|
+
// -- the hours tick does it every minute -- would be left pending
|
|
1604
|
+
// with no breath to ever finish it, and never told at all.
|
|
1605
|
+
landed();
|
|
1528
1606
|
resting = to;
|
|
1529
1607
|
updateLift(t);
|
|
1530
1608
|
return render();
|