skydancer 2.13.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 CHANGED
@@ -4,6 +4,22 @@ 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
+
7
23
  ## v2.13.0 — 2026-11-23
8
24
 
9
25
  - `link-label` and `poke-label` say the two bits of wording a reader meets
package/README.md CHANGED
@@ -129,6 +129,28 @@ document.querySelector('sky-dancer').hide();
129
129
 
130
130
  A hidden dancer stops animating and costs nothing until it is shown again.
131
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
+
132
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.
133
155
 
134
156
  ## Customizer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skydancer",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
4
4
  "description": "An embeddable inflatable tube dancer, as a custom element. Vanilla canvas, no dependencies.",
5
5
  "keywords": [
6
6
  "custom-element",
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.
@@ -96,6 +110,12 @@ declare global {
96
110
  interface HTMLElementTagNameMap {
97
111
  'sky-dancer': SkyDancerElement;
98
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 {}
99
119
  }
100
120
 
101
121
  // No JSX declaration here on purpose: typing an intrinsic element means
package/skydancer.js CHANGED
@@ -429,6 +429,15 @@
429
429
  observer.observe(canvas);
430
430
  resize();
431
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
+
432
441
  // ---- simulation ----
433
442
  // Everything is a chain of segments. Each segment adds a small bend to the
434
443
  // running angle (0 = straight up, positive = leaning right), so travelling
@@ -515,6 +524,14 @@
515
524
  const leadsTo = root.querySelector('.go');
516
525
  const pokeButton = root.querySelector('.poke');
517
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
+
518
535
  // Somewhere a link may actually go. `javascript:` is the one that matters:
519
536
  // the destination can reach this widget from a page's own templating or
520
537
  // from the customizer's shareable link, so it is not always written by
@@ -588,40 +605,45 @@
588
605
  let lastTurn = 0;
589
606
  let lastShout = -1; // which word the last poke took
590
607
 
591
- function burst() {
608
+ function burst(byReader) {
592
609
  // without a running loop nothing would decay the punch, so it would be
593
610
  // saved up and spent the moment the dancer came back into view
594
611
  if (held() || !visible) return;
595
612
  // A poke takes one of them, never the one it took last: a flurry of
596
613
  // pokes should be a flurry of different words.
597
614
  const choices = phrasesOf(cfg.shout);
615
+ let said = ''; // what it blurted, which the page is told along with the poke
598
616
  if (choices.length && lastChest) {
599
617
  if (choices.length > 1) {
600
618
  let pick = lastShout;
601
619
  while (pick === lastShout) pick = Math.floor(Math.random() * choices.length);
602
620
  lastShout = pick;
603
621
  } else lastShout = 0;
604
- const words = choices[lastShout];
622
+ said = choices[lastShout];
605
623
  // at least a third of the way round from the last one, so two in a
606
624
  // row never land on top of each other
607
625
  lastTurn += Math.PI * (0.7 + Math.random() * 0.6);
608
626
  const reach = cfg.girth * (1.5 + Math.random());
609
627
  shouts.push({
610
- words,
628
+ words: said,
611
629
  x: lastChest.x + Math.cos(lastTurn) * reach,
612
630
  y: lastChest.y + Math.sin(lastTurn) * reach * 0.7,
613
631
  at: wall,
614
632
  tilt: (Math.random() - 0.5) * 0.45,
615
633
  });
616
634
  if (shouts.length > SHOUTS) shouts.shift();
617
- blurted.textContent = words;
635
+ blurted.textContent = said;
618
636
  }
619
637
  punch = 1;
620
638
  kink = { start: t, dur: 0.9, dir: Math.random() < 0.5 ? -1 : 1, mag: 0.45 };
639
+ if (byReader) tell('poke', { shout: said });
621
640
  }
622
641
 
623
- canvas.addEventListener('pointerdown', burst, { signal: events.signal });
624
- pokeButton.addEventListener('click', burst, { signal: events.signal });
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 });
625
647
 
626
648
  // Only offered when a poke has something to say, and when a poke would do
627
649
  // anything at all. A dancer is decoration, and a decorative one that is
@@ -735,6 +757,19 @@
735
757
  air = { from, to, start: wall, dur };
736
758
  }
737
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
+
738
773
  // how far the air has got, 0 flat to 1 full
739
774
  function pressure() {
740
775
  if (!air) return resting; // not 1: a dancer let down stays down
@@ -742,6 +777,7 @@
742
777
  if (p >= 1) {
743
778
  resting = air.to;
744
779
  air = null;
780
+ landed();
745
781
  return resting;
746
782
  }
747
783
  // eased, so it leaves and arrives without a jolt
@@ -771,6 +807,7 @@
771
807
  if (!air) return;
772
808
  resting = filled = air.to;
773
809
  air = null;
810
+ landed();
774
811
  }
775
812
 
776
813
  // bend that swings a loose chain (arm, hair) round to point downwind
@@ -1524,8 +1561,19 @@
1524
1561
  // A held pose has no clock to fill by, so it just stands there. One
1525
1562
  // already part way in or out carries on from where it stopped: starting
1526
1563
  // over would snap it flat.
1527
- if (coming && !held() && !air) breathe(0, resting, FILL);
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;
1528
1575
  start();
1576
+ if (settled) tell('arrive');
1529
1577
  });
1530
1578
  visibility.observe(canvas);
1531
1579
  reduced.addEventListener('change', start, { signal: events.signal });
@@ -1550,6 +1598,11 @@
1550
1598
  pump(to) {
1551
1599
  if (held()) { // no frames to breathe with, so it lands at once
1552
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();
1553
1606
  resting = to;
1554
1607
  updateLift(t);
1555
1608
  return render();