magic-pill 9.3.0 → 9.4.0-next.2

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +114 -3
  3. package/dist/MagicPill/MagicPill.d.mts +51 -1
  4. package/dist/MagicPill/MagicPill.d.ts +51 -1
  5. package/dist/MagicPill/MagicPill.js +53 -4
  6. package/dist/MagicPill/MagicPill.mjs +55 -6
  7. package/dist/MagicPill/flag.js +1 -59
  8. package/dist/MagicPill/flag.mjs +1 -58
  9. package/dist/Pill/PillProgress.d.mts +12 -0
  10. package/dist/Pill/PillProgress.d.ts +12 -0
  11. package/dist/Pill/PillProgress.js +42 -0
  12. package/dist/Pill/PillProgress.mjs +42 -0
  13. package/dist/Pill/goo.js +576 -0
  14. package/dist/Pill/goo.mjs +566 -0
  15. package/dist/Pill/morph.js +11 -4
  16. package/dist/Pill/morph.mjs +10 -5
  17. package/dist/PillNavbar/PillNavbar.d.mts +8 -0
  18. package/dist/PillNavbar/PillNavbar.d.ts +8 -0
  19. package/dist/PillNavbar/PillNavbar.js +3 -2
  20. package/dist/PillNavbar/PillNavbar.mjs +3 -2
  21. package/dist/PillNavbar/room.d.mts +3 -0
  22. package/dist/PillNavbar/room.d.ts +2 -0
  23. package/dist/PillNavbar/room.js +89 -17
  24. package/dist/PillNavbar/room.mjs +89 -18
  25. package/dist/index.d.mts +3 -2
  26. package/dist/index.d.ts +3 -2
  27. package/dist/index.js +2 -0
  28. package/dist/index.mjs +2 -1
  29. package/dist/satellites/Actions.d.mts +12 -0
  30. package/dist/satellites/Actions.d.ts +11 -0
  31. package/dist/satellites/Actions.js +181 -0
  32. package/dist/satellites/Actions.mjs +177 -0
  33. package/dist/satellites/Orbitals.js +585 -0
  34. package/dist/satellites/Orbitals.mjs +585 -0
  35. package/dist/satellites/Satellites.js +634 -0
  36. package/dist/satellites/Satellites.mjs +634 -0
  37. package/dist/satellites/layout.js +209 -0
  38. package/dist/satellites/layout.mjs +209 -0
  39. package/dist/satellites/measure.js +25 -0
  40. package/dist/satellites/measure.mjs +24 -0
  41. package/dist/satellites/orbits.js +139 -0
  42. package/dist/satellites/orbits.mjs +136 -0
  43. package/dist/satellites/types.d.mts +58 -0
  44. package/dist/satellites/types.d.ts +58 -0
  45. package/dist/satellites.d.mts +5 -0
  46. package/dist/satellites.d.ts +5 -0
  47. package/dist/satellites.js +14 -0
  48. package/dist/satellites.mjs +12 -0
  49. package/dist/store/store.d.mts +103 -0
  50. package/dist/store/store.d.ts +103 -0
  51. package/dist/store/store.js +52 -1
  52. package/dist/store/store.mjs +52 -2
  53. package/dist/styles.css +322 -8
  54. package/package.json +11 -1
@@ -1,6 +1,7 @@
1
1
  import { devWarn } from "../utils/react.mjs";
2
2
 
3
3
  // src/store/store.ts
4
+ const NO_ELECTRONS = Object.freeze([]);
4
5
  const EMPTY_STATE = Object.freeze({
5
6
  current: null,
6
7
  queued: Object.freeze([])
@@ -11,7 +12,13 @@ function createStore(name) {
11
12
  let items = [];
12
13
  let state = EMPTY_STATE;
13
14
  let hosts = 0;
15
+ let electrons = NO_ELECTRONS;
16
+ let actions = null;
14
17
  const listeners = /* @__PURE__ */ new Set();
18
+ const setElectrons = (next) => {
19
+ electrons = next.length === 0 ? NO_ELECTRONS : next;
20
+ listeners.forEach((listener) => listener());
21
+ };
15
22
  const commit = (next) => {
16
23
  items = next;
17
24
  state = next.length === 0 ? EMPTY_STATE : {
@@ -62,6 +69,45 @@ function createStore(name) {
62
69
  commit([]);
63
70
  dismissed.forEach((item) => item.input.onDismiss?.(item.id, "cleared"));
64
71
  },
72
+ getElectrons: () => electrons,
73
+ electron(input) {
74
+ const id = input.id || `mp-${++lastId}`;
75
+ if (isServer()) {
76
+ devWarn(`pill("${name}").electron() was called on the server and does nothing: call it from client code.`);
77
+ return id;
78
+ }
79
+ const existing = electrons.find((electron) => electron.id === id);
80
+ if (existing) setElectrons(electrons.map((electron) => electron === existing ? {
81
+ ...existing,
82
+ input
83
+ } : electron));
84
+ else setElectrons([...electrons, {
85
+ id,
86
+ input,
87
+ origin: input.href ?? window.location.pathname
88
+ }]);
89
+ return id;
90
+ },
91
+ updateElectron(id, patch) {
92
+ const existing = electrons.find((electron) => electron.id === id);
93
+ if (existing) setElectrons(electrons.map((electron) => electron === existing ? {
94
+ ...existing,
95
+ input: {
96
+ ...existing.input,
97
+ ...patch
98
+ }
99
+ } : electron));
100
+ },
101
+ endElectron(id) {
102
+ if (electrons.some((electron) => electron.id === id)) setElectrons(electrons.filter((electron) => electron.id !== id));
103
+ },
104
+ getActions: () => actions,
105
+ setActions(items) {
106
+ const next = items && items.length > 0 ? items : null;
107
+ if (next === actions) return;
108
+ actions = next;
109
+ listeners.forEach((listener) => listener());
110
+ },
65
111
  registerHost() {
66
112
  hosts += 1;
67
113
  if (hosts > 1) devWarn(`Several <MagicPill name="${name}"> are mounted. Give each one its own name.`);
@@ -92,11 +138,15 @@ function pill(name = "main") {
92
138
  notify: (input) => store.notify(input),
93
139
  update: (id, patch) => store.update(id, patch),
94
140
  dismiss: (id) => store.dismiss(id, "dismissed"),
95
- clear: () => store.clear()
141
+ clear: () => store.clear(),
142
+ electron: (input) => store.electron(input),
143
+ updateElectron: (id, patch) => store.updateElectron(id, patch),
144
+ endElectron: (id) => store.endElectron(id),
145
+ setActions: (items) => store.setActions(items)
96
146
  });
97
147
  controllers.set(name, controller);
98
148
  }
99
149
  return controller;
100
150
  }
101
151
 
102
- export { EMPTY_STATE, getStore, pill };
152
+ export { EMPTY_STATE, NO_ELECTRONS, getStore, pill };
package/dist/styles.css CHANGED
@@ -47,6 +47,38 @@
47
47
  }
48
48
 
49
49
  @layer look {
50
+ /* How far a scrolling navbar's ends fade (see the navbars):
51
+ registered, so that a scroll-driven animation can move them */
52
+ @property --_mp-scroll-start {
53
+ syntax: "<length>";
54
+ inherits: false;
55
+ initial-value: 0px;
56
+ }
57
+
58
+ @property --_mp-scroll-end {
59
+ syntax: "<length>";
60
+ inherits: false;
61
+ initial-value: 0px;
62
+ }
63
+
64
+ /* A scrolling navbar's ends: no fade at the end it's at. Without anything
65
+ to scroll, the timeline is inactive and there's no fade at all */
66
+ @keyframes mp-scroll-ends {
67
+ 0% {
68
+ --_mp-scroll-start: 0px;
69
+ --_mp-scroll-end: 1.5rem;
70
+ }
71
+ 10%,
72
+ 90% {
73
+ --_mp-scroll-start: 1.5rem;
74
+ --_mp-scroll-end: 1.5rem;
75
+ }
76
+ 100% {
77
+ --_mp-scroll-start: 1.5rem;
78
+ --_mp-scroll-end: 0px;
79
+ }
80
+ }
81
+
50
82
  /* ─── Look ─────────────────────────────────────────────────────────────── */
51
83
 
52
84
  [data-mp="pill"]:not([data-unstyled]) {
@@ -262,13 +294,73 @@
262
294
  right: calc(var(--_mp-offset) + env(safe-area-inset-right, 0px) + var(--_mp-shift-x, 0px));
263
295
  }
264
296
 
265
- /* A sidebar's flag pops out of the sidebar's side, and scales back into it */
266
- &[data-layout="flag"][data-placement="left"] {
267
- transform-origin: var(--mp-scale-origin, left center);
297
+ /* A sidebar's flag and an electron (magic-pill/satellites) come out of
298
+ the pill's edge as a droplet and go back into it (goo.ts moves them),
299
+ so they don't scale in or out. Their entry and exit take the split's
300
+ and the join's durations */
301
+ &:is([data-layout="flag"], [data-satellite]) {
302
+ --_mp-enter: var(--mp-duration-split, var(--mp-duration-enter, 500ms));
303
+ --_mp-exit: var(--mp-duration-join, var(--mp-duration-exit, 300ms));
304
+ --_mp-exit-scale: 1;
305
+
306
+ &[data-presence="hidden"] {
307
+ scale: 1;
308
+ }
309
+ }
310
+
311
+ /* An electron's orbitals: small round pills, the size of an action. The
312
+ one under the finger, the pointer or the focus takes the actions'
313
+ colours and grows a little */
314
+ &[data-satellite="orbital"] {
315
+ --_mp-padding: 0px;
316
+ --_mp-change: 0ms;
317
+ --_mp-action-size: var(--mp-orbital-size, var(--mp-action-size, 2.75rem));
318
+
319
+ &:not([data-presence="hidden"]) {
320
+ transition:
321
+ scale 120ms ease-out,
322
+ background-color 120ms ease-out,
323
+ color 120ms ease-out,
324
+ var(--_mp-also, visibility 0s),
325
+ visibility 0s;
326
+ }
327
+
328
+ &[data-hot] {
329
+ scale: 1.12;
330
+ background-color: var(--_mp-action);
331
+ color: var(--_mp-on-action);
332
+ }
333
+ }
334
+
335
+ /* The label of the orbital under the finger: a small pill of the same
336
+ look (its theme, its colours), above the orbitals, there at once */
337
+ &[data-satellite="orbital-label"] {
338
+ --_mp-padding: 0.3rem;
339
+ --_mp-rest-size: calc(1lh + 0.6rem);
340
+ --_mp-change: 0ms;
341
+ --_mp-fade: 0ms;
342
+ z-index: calc(var(--mp-z-index, 50) + 1);
343
+ min-block-size: 0;
344
+ padding: 0.3rem 0.7rem;
345
+ font: 700 0.8125rem / 1.2 var(--mp-font-accent, inherit);
346
+ white-space: nowrap;
347
+ pointer-events: none;
348
+ transition: none;
349
+ }
350
+
351
+ /* An electron whose activity ends can pop away instead, like any pill leaving */
352
+ /* An electron and the page's actions never change size: they go back
353
+ into the pill once their content has faded, not after a size change */
354
+ &[data-satellite] {
355
+ --_mp-exit-wait: var(--_mp-fade);
268
356
  }
269
357
 
270
- &[data-layout="flag"][data-placement="right"] {
271
- transform-origin: var(--mp-scale-origin, right center);
358
+ &[data-satellite][data-ending="pop"] {
359
+ --_mp-exit-scale: 0;
360
+
361
+ &[data-presence="hidden"] {
362
+ scale: 0;
363
+ }
272
364
  }
273
365
 
274
366
  &[data-placement="overlay"] {
@@ -405,6 +497,56 @@
405
497
  align-items: var(--_mp-align);
406
498
  }
407
499
 
500
+ /* The page's actions cut short (actionsWheel, magic-pill/satellites):
501
+ what fits shows, the others turn in, each snapping into place; the
502
+ ends that hide some fade out, a cut that starts right at the divider */
503
+ & [data-mp="actions"][data-wheel] {
504
+ --_mp-wheel-fade: calc(var(--_mp-action-size) * 0.4);
505
+ --_mp-wheel-start: 0px;
506
+ --_mp-wheel-end: 0px;
507
+ max-inline-size: var(--_mp-wheel-length);
508
+ overflow: auto hidden;
509
+ overscroll-behavior: contain;
510
+ scroll-snap-type: x mandatory;
511
+ scrollbar-width: none;
512
+ mask-image: linear-gradient(
513
+ to var(--_mp-wheel-to, right),
514
+ rgb(0 0 0 / 0.2),
515
+ #000 var(--_mp-wheel-start),
516
+ #000 calc(100% - var(--_mp-wheel-end)),
517
+ rgb(0 0 0 / 0.2)
518
+ );
519
+
520
+ &::-webkit-scrollbar {
521
+ display: none;
522
+ }
523
+
524
+ & > * {
525
+ flex: none;
526
+ scroll-snap-align: start;
527
+ }
528
+
529
+ &[data-more-start] {
530
+ --_mp-wheel-start: var(--_mp-wheel-fade);
531
+ }
532
+
533
+ &[data-more-end] {
534
+ --_mp-wheel-end: var(--_mp-wheel-fade);
535
+ }
536
+
537
+ &:dir(rtl) {
538
+ --_mp-wheel-to: left;
539
+ }
540
+ }
541
+
542
+ &[data-orientation="vertical"] [data-mp="actions"][data-wheel] {
543
+ --_mp-wheel-to: bottom;
544
+ max-inline-size: none;
545
+ max-block-size: var(--_mp-wheel-length);
546
+ overflow: hidden auto;
547
+ scroll-snap-type: y mandatory;
548
+ }
549
+
408
550
  /* A notification in rows (layout="rows"): the message and the actions
409
551
  wrap in a body beside the icon. The actions stay on the message's
410
552
  line while they fit, go under it when it wraps (the body is as wide
@@ -490,6 +632,112 @@
490
632
  outline-offset: 2px;
491
633
  }
492
634
 
635
+ /* An electron: all of the circle is a link back to where it came from.
636
+ The circle's size, padding included, the same whatever box-sizing an
637
+ app's reset gives everything (its CSS beats these layers) */
638
+ & [data-mp="electron"] {
639
+ display: grid;
640
+ place-items: center;
641
+ box-sizing: border-box;
642
+ inline-size: var(--_mp-rest-size);
643
+ block-size: var(--_mp-rest-size);
644
+ margin: calc(var(--_mp-padding) * -1);
645
+ padding: var(--_mp-padding);
646
+ border: 0;
647
+ border-radius: 50%;
648
+ background: none;
649
+ color: inherit;
650
+ font: inherit;
651
+ text-decoration: none;
652
+ cursor: pointer;
653
+ -webkit-tap-highlight-color: transparent;
654
+ }
655
+
656
+ /* With orbitals: a long press opens them, with no scrolling or callout */
657
+ & [data-mp="electron"][aria-haspopup] {
658
+ touch-action: none;
659
+ -webkit-touch-callout: none;
660
+ user-select: none;
661
+ }
662
+
663
+ & [data-mp="orbital"] {
664
+ display: grid;
665
+ place-items: center;
666
+ inline-size: var(--_mp-action-size);
667
+ block-size: var(--_mp-action-size);
668
+ padding: 0;
669
+ border: 0;
670
+ border-radius: 50%;
671
+ background: none;
672
+ color: inherit;
673
+ font-size: 1.25rem;
674
+ cursor: pointer;
675
+ -webkit-tap-highlight-color: transparent;
676
+
677
+ & > :is(svg, img) {
678
+ inline-size: 1em;
679
+ block-size: 1em;
680
+ }
681
+ }
682
+
683
+ & [data-mp="orbital"]:focus-visible {
684
+ outline: 2px solid currentColor;
685
+ outline-offset: -4px;
686
+ }
687
+
688
+ & [data-mp="electron"]:focus-visible {
689
+ outline: 2px solid var(--_mp-on-surface);
690
+ outline-offset: -5px;
691
+ }
692
+
693
+ & [data-mp="electron-value"] {
694
+ font: 700 0.8125rem / 1 var(--mp-font-accent, inherit);
695
+ font-variant-numeric: tabular-nums;
696
+ }
697
+
698
+ /* The value alone, without a ring: larger */
699
+ & [data-mp="electron"] > [data-mp="electron-value"] {
700
+ font-size: 1rem;
701
+ }
702
+
703
+ & [data-mp="electron-icon"] {
704
+ display: grid;
705
+ font-size: 1.375rem;
706
+
707
+ & > :is(svg, img) {
708
+ inline-size: 1em;
709
+ block-size: 1em;
710
+ }
711
+ }
712
+
713
+ /* A progress ring around its content, in the text colour */
714
+ & [data-mp="progress"] {
715
+ position: relative;
716
+ display: grid;
717
+ place-items: center;
718
+ inline-size: var(--_mp-action-size);
719
+ block-size: var(--_mp-action-size);
720
+
721
+ & > svg {
722
+ position: absolute;
723
+ top: 50%;
724
+ left: 50%;
725
+ inline-size: var(--mp-progress-size, 3.375rem);
726
+ block-size: var(--mp-progress-size, 3.375rem);
727
+ translate: -50% -50%;
728
+ rotate: -90deg;
729
+ overflow: visible;
730
+ fill: none;
731
+ stroke: currentColor;
732
+ stroke-width: var(--mp-progress-width, 3.5);
733
+ stroke-linecap: round;
734
+ }
735
+ }
736
+
737
+ & [data-mp="progress-track"] {
738
+ opacity: 0.25;
739
+ }
740
+
493
741
  & [data-mp="action"][aria-disabled="true"] {
494
742
  cursor: not-allowed;
495
743
  opacity: 0.6;
@@ -619,10 +867,75 @@
619
867
  }
620
868
  }
621
869
 
870
+ /* A sidebar's navbar longer than the screen scrolls inside its pill
871
+ (the docs of an app with many sections, a short phone held
872
+ sideways). It reaches the pill's edges, so that what scrolls goes
873
+ under them, and where the browser can tell, the ends that hide some
874
+ fade out */
875
+ &[data-orientation="vertical"] [data-mp="navbar"] {
876
+ flex: 0 1 auto;
877
+ min-block-size: 0;
878
+ margin: calc(var(--_mp-padding) * -1);
879
+ padding: var(--_mp-padding);
880
+ overflow: hidden auto;
881
+ overscroll-behavior: contain;
882
+ scrollbar-width: none;
883
+
884
+ &::-webkit-scrollbar {
885
+ display: none;
886
+ }
887
+
888
+ @supports (animation-timeline: scroll()) {
889
+ mask-image: linear-gradient(
890
+ to bottom,
891
+ transparent,
892
+ #000 var(--_mp-scroll-start),
893
+ #000 calc(100% - var(--_mp-scroll-end)),
894
+ transparent
895
+ );
896
+ animation: mp-scroll-ends linear both;
897
+ animation-timeline: scroll(self block);
898
+ }
899
+ }
900
+
622
901
  /* A navbar stays in its pill: where it's too narrow, the open label is
623
- cut short, rather than the last items */
902
+ cut short, rather than the last items. With its labels folded and
903
+ still too long (many items, a narrow phone), it scrolls inside the
904
+ pill like a sidebar's, the ends that hide some fading out; it reaches
905
+ the pill's top and bottom, so that a focus ring isn't cut */
624
906
  &[data-orientation="horizontal"] [data-mp="navbar"] {
625
907
  min-inline-size: 0;
908
+ margin-block: calc(var(--_mp-padding) * -1);
909
+ padding-block: var(--_mp-padding);
910
+ overflow: auto hidden;
911
+ overscroll-behavior-x: contain;
912
+ scrollbar-width: none;
913
+
914
+ &::-webkit-scrollbar {
915
+ display: none;
916
+ }
917
+
918
+ @supports (animation-timeline: scroll()) {
919
+ mask-image: linear-gradient(
920
+ to right,
921
+ transparent,
922
+ #000 var(--_mp-scroll-start),
923
+ #000 calc(100% - var(--_mp-scroll-end)),
924
+ transparent
925
+ );
926
+ animation: mp-scroll-ends linear both;
927
+ animation-timeline: scroll(self inline);
928
+
929
+ &:dir(rtl) {
930
+ mask-image: linear-gradient(
931
+ to left,
932
+ transparent,
933
+ #000 var(--_mp-scroll-start),
934
+ #000 calc(100% - var(--_mp-scroll-end)),
935
+ transparent
936
+ );
937
+ }
938
+ }
626
939
 
627
940
  & [data-mp="action"] {
628
941
  flex: 0 1 auto;
@@ -639,8 +952,9 @@
639
952
  }
640
953
 
641
954
  /* No room for two labels (PillNavbar/room.ts): the one that was open
642
- folds while another is pointed at or focused */
643
- & [data-mp="navbar"][data-tight] [data-mp="action"]:not(:hover, :focus-visible) {
955
+ folds while another is pointed at or focused. Folded at rest too with
956
+ labels="closed", or "auto" while the current one has no room */
957
+ & [data-mp="navbar"]:is([data-tight], [data-folded]) [data-mp="action"]:not(:hover, :focus-visible) {
644
958
  & [data-mp="action-body"] {
645
959
  padding-inline-end: calc((var(--_mp-action-size) - 1.25rem) / 2);
646
960
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magic-pill",
3
- "version": "9.3.0",
3
+ "version": "9.4.0-next.2",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -16,6 +16,16 @@
16
16
  "default": "./dist/index.js"
17
17
  }
18
18
  },
19
+ "./satellites": {
20
+ "import": {
21
+ "types": "./dist/satellites.d.mts",
22
+ "default": "./dist/satellites.mjs"
23
+ },
24
+ "require": {
25
+ "types": "./dist/satellites.d.ts",
26
+ "default": "./dist/satellites.js"
27
+ }
28
+ },
19
29
  "./styles.css": "./dist/styles.css",
20
30
  "./themes.css": "./dist/themes.css",
21
31
  "./forms.css": "./dist/forms.css",