@liberation-data/desk 0.14.0 → 0.15.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.
Files changed (69) hide show
  1. package/README.md +70 -7
  2. package/dist/core/index.d.ts +2 -0
  3. package/dist/core/index.d.ts.map +1 -1
  4. package/dist/core/index.js +1 -0
  5. package/dist/core/index.js.map +1 -1
  6. package/dist/core/look.d.ts +12 -0
  7. package/dist/core/look.d.ts.map +1 -0
  8. package/dist/core/look.js +26 -0
  9. package/dist/core/look.js.map +1 -0
  10. package/dist/css/dock.css +123 -3
  11. package/dist/css/looks.css +258 -0
  12. package/dist/css/tokens.css +5 -1
  13. package/dist/desk.css +387 -4
  14. package/dist/fx/fx.d.ts +29 -0
  15. package/dist/fx/fx.d.ts.map +1 -0
  16. package/dist/fx/fx.js +119 -0
  17. package/dist/fx/fx.js.map +1 -0
  18. package/dist/fx/index.d.ts +7 -0
  19. package/dist/fx/index.d.ts.map +1 -0
  20. package/dist/fx/index.js +4 -0
  21. package/dist/fx/index.js.map +1 -0
  22. package/dist/fx/measure.d.ts +18 -0
  23. package/dist/fx/measure.d.ts.map +1 -0
  24. package/dist/fx/measure.js +37 -0
  25. package/dist/fx/measure.js.map +1 -0
  26. package/dist/fx/sounds.d.ts +108 -0
  27. package/dist/fx/sounds.d.ts.map +1 -0
  28. package/dist/fx/sounds.js +148 -0
  29. package/dist/fx/sounds.js.map +1 -0
  30. package/dist/react/Desktop.d.ts.map +1 -1
  31. package/dist/react/Desktop.js +44 -9
  32. package/dist/react/Desktop.js.map +1 -1
  33. package/dist/react/Dock.d.ts +11 -1
  34. package/dist/react/Dock.d.ts.map +1 -1
  35. package/dist/react/Dock.js +4 -3
  36. package/dist/react/Dock.js.map +1 -1
  37. package/dist/react/context.d.ts +9 -1
  38. package/dist/react/context.d.ts.map +1 -1
  39. package/dist/react/context.js +15 -3
  40. package/dist/react/context.js.map +1 -1
  41. package/dist/react/index.d.ts +4 -2
  42. package/dist/react/index.d.ts.map +1 -1
  43. package/dist/react/index.js +2 -1
  44. package/dist/react/index.js.map +1 -1
  45. package/dist/react/shell.d.ts +4 -1
  46. package/dist/react/shell.d.ts.map +1 -1
  47. package/dist/react/shell.js +2 -2
  48. package/dist/react/shell.js.map +1 -1
  49. package/dist/react/soundsToggle.d.ts +14 -0
  50. package/dist/react/soundsToggle.d.ts.map +1 -0
  51. package/dist/react/soundsToggle.js +12 -0
  52. package/dist/react/soundsToggle.js.map +1 -0
  53. package/llms.txt +44 -14
  54. package/package.json +7 -2
  55. package/src/core/index.ts +2 -0
  56. package/src/core/look.ts +43 -0
  57. package/src/css/dock.css +123 -3
  58. package/src/css/looks.css +257 -0
  59. package/src/css/tokens.css +5 -1
  60. package/src/fx/fx.ts +145 -0
  61. package/src/fx/index.ts +6 -0
  62. package/src/fx/measure.ts +70 -0
  63. package/src/fx/sounds.ts +213 -0
  64. package/src/react/Desktop.tsx +97 -29
  65. package/src/react/Dock.tsx +16 -3
  66. package/src/react/context.tsx +25 -3
  67. package/src/react/index.ts +4 -2
  68. package/src/react/shell.tsx +5 -2
  69. package/src/react/soundsToggle.tsx +19 -0
package/dist/desk.css CHANGED
@@ -47,11 +47,15 @@
47
47
  --desk-on-accent: #ffffff;
48
48
  --desk-ease: cubic-bezier(.32, .72, 0, 1);
49
49
  --desk-dock-size: 48px;
50
+ /* How far an overlay dock stands off the edge of the desk. */
51
+ --desk-dock-offset: 12px;
52
+ /* The room an overlay dock takes from the stage beside it: the offset, the dock, its border and padding. */
53
+ --desk-dock-room: calc(var(--desk-dock-offset) + var(--desk-dock-size) + 16px);
50
54
  --desk-dock-glass: rgb(255 255 255 / 72%);
51
55
  --desk-dock-icon: linear-gradient(160deg, #ffffff, #eceff5);
52
56
  --desk-badge: #ef4444;
53
57
  --desk-badge-ink: #ffffff;
54
- /* Room the stage leaves at the bottom for an overlay dock. */
58
+ /* Room the stage leaves at the bottom for something of the app's own. An overlay dock makes its own. */
55
59
  --desk-inset-bottom: 0px;
56
60
  }
57
61
 
@@ -468,12 +472,56 @@
468
472
 
469
473
  .desk-dock[data-placement="overlay"] {
470
474
  position: absolute;
471
- left: 50%;
472
- bottom: 12px;
473
475
  z-index: 1000;
476
+ }
477
+
478
+ .desk-dock[data-placement="overlay"][data-side="bottom"] {
479
+ left: 50%;
480
+ bottom: var(--desk-dock-offset);
474
481
  transform: translateX(-50%);
475
482
  }
476
483
 
484
+ .desk-dock[data-placement="overlay"]:not([data-side="bottom"]) {
485
+ top: 50%;
486
+ transform: translateY(-50%);
487
+ }
488
+
489
+ .desk-dock[data-placement="overlay"][data-side="left"] {
490
+ left: var(--desk-dock-offset);
491
+ }
492
+
493
+ .desk-dock[data-placement="overlay"][data-side="right"] {
494
+ right: var(--desk-dock-offset);
495
+ }
496
+
497
+ /* Standing in a column: items top to bottom, and never taller than the room it stands in. */
498
+ .desk-dock:not([data-side="bottom"]) {
499
+ flex-direction: column;
500
+ align-items: center;
501
+ max-width: none;
502
+ max-height: calc(100% - 2 * var(--desk-dock-offset));
503
+ /* The same thickness standing up as lying down, so --desk-dock-room holds on every side. */
504
+ padding: 9px 7px;
505
+ }
506
+
507
+ /*
508
+ * An overlay dock makes its own room. The stage beside it starts where the dock ends — a margin, not
509
+ * padding, because windows are placed from the stage's own corner: padding would keep filled windows
510
+ * clear and still open every free one underneath the dock.
511
+ */
512
+ :has(> .desk-dock[data-placement="overlay"][data-side="left"]) > .desk-stage {
513
+ margin-left: var(--desk-dock-room);
514
+ }
515
+
516
+ :has(> .desk-dock[data-placement="overlay"][data-side="right"]) > .desk-stage {
517
+ margin-right: var(--desk-dock-room);
518
+ }
519
+
520
+ :has(> .desk-dock[data-placement="overlay"][data-side="bottom"]) > .desk-stage {
521
+ /* The stage is `height: 100%`, so a margin would push it past its parent rather than shorten it. */
522
+ height: calc(100% - var(--desk-dock-room));
523
+ }
524
+
477
525
  .desk-dock-separator {
478
526
  flex: none;
479
527
  align-self: stretch;
@@ -482,6 +530,12 @@
482
530
  background: var(--desk-rule);
483
531
  }
484
532
 
533
+ .desk-dock:not([data-side="bottom"]) .desk-dock-separator {
534
+ width: auto;
535
+ height: 1px;
536
+ margin: 4px 6px;
537
+ }
538
+
485
539
  .desk-dock-slot {
486
540
  position: relative;
487
541
  display: flex;
@@ -515,11 +569,22 @@
515
569
  outline-offset: 2px;
516
570
  }
517
571
 
572
+ /* Magnified toward the desk, whichever side that is. */
518
573
  @media (hover: hover) and (pointer: fine) {
519
- .desk-dock-item:hover:not(:disabled) {
574
+ .desk-dock[data-side="bottom"] .desk-dock-item:hover:not(:disabled) {
520
575
  transform: translateY(-8px) scale(1.14);
521
576
  margin: 0 5px;
522
577
  }
578
+
579
+ .desk-dock[data-side="left"] .desk-dock-item:hover:not(:disabled) {
580
+ transform: translateX(8px) scale(1.14);
581
+ margin: 5px 0;
582
+ }
583
+
584
+ .desk-dock[data-side="right"] .desk-dock-item:hover:not(:disabled) {
585
+ transform: translateX(-8px) scale(1.14);
586
+ margin: 5px 0;
587
+ }
523
588
  }
524
589
 
525
590
  .desk-dock-icon {
@@ -575,6 +640,22 @@
575
640
  background: var(--desk-muted);
576
641
  }
577
642
 
643
+ /* On a dock at the side the dot sits between the item and the edge of the screen, as it does under a bottom one. */
644
+ .desk-dock:not([data-side="bottom"]) .desk-dock-item[data-running]::after {
645
+ top: 50%;
646
+ bottom: auto;
647
+ margin: -2px 0 0;
648
+ }
649
+
650
+ .desk-dock[data-side="left"] .desk-dock-item[data-running]::after {
651
+ left: -6px;
652
+ }
653
+
654
+ .desk-dock[data-side="right"] .desk-dock-item[data-running]::after {
655
+ left: auto;
656
+ right: -6px;
657
+ }
658
+
578
659
  .desk-dock-item[data-focused]::after {
579
660
  background: var(--desk-accent);
580
661
  }
@@ -622,6 +703,21 @@
622
703
  transition: opacity .12s;
623
704
  }
624
705
 
706
+ .desk-dock:not([data-side="bottom"]) .desk-dock-tip {
707
+ bottom: auto;
708
+ top: 50%;
709
+ transform: translateY(-50%);
710
+ }
711
+
712
+ .desk-dock[data-side="left"] .desk-dock-tip {
713
+ left: calc(100% + 14px);
714
+ }
715
+
716
+ .desk-dock[data-side="right"] .desk-dock-tip {
717
+ left: auto;
718
+ right: calc(100% + 14px);
719
+ }
720
+
625
721
  .desk-dock-item:hover .desk-dock-tip,
626
722
  .desk-dock-item:focus-visible .desk-dock-tip {
627
723
  opacity: 1;
@@ -659,6 +755,30 @@
659
755
  }
660
756
  }
661
757
 
758
+ /* Beside a dock at the side, level with the stack it came from, opening toward the desk. */
759
+ .desk-dock:not([data-side="bottom"]) .desk-stack {
760
+ bottom: auto;
761
+ top: 0;
762
+ transform: none;
763
+ animation-name: desk-pop-aside;
764
+ }
765
+
766
+ .desk-dock[data-side="left"] .desk-stack {
767
+ left: calc(100% + 18px);
768
+ }
769
+
770
+ .desk-dock[data-side="right"] .desk-stack {
771
+ left: auto;
772
+ right: calc(100% + 18px);
773
+ }
774
+
775
+ @keyframes desk-pop-aside {
776
+ from {
777
+ opacity: 0;
778
+ scale: .98;
779
+ }
780
+ }
781
+
662
782
  .desk-stack-title {
663
783
  margin: 0 0 8px 4px;
664
784
  font-size: 11px;
@@ -725,6 +845,10 @@
725
845
  box-shadow: -6px 0 0 -2px var(--desk-accent);
726
846
  }
727
847
 
848
+ .desk-dock:not([data-side="bottom"]) .desk-dock-item[data-desk-drop][data-over] {
849
+ box-shadow: 0 -6px 0 -2px var(--desk-accent);
850
+ }
851
+
728
852
  /* @liberation-data/desk — menus.css */
729
853
  /* ── Menu bar ── */
730
854
 
@@ -3008,3 +3132,262 @@
3008
3132
  border: 0;
3009
3133
  background: var(--desk-surface);
3010
3134
  }
3135
+
3136
+ /* @liberation-data/desk — looks.css */
3137
+ /*
3138
+ * Looks: the platform chrome, on `data-look` at the root. The rest of desk.css is the Mac look, so
3139
+ * this part only says how GNOME and Windows differ from it.
3140
+ *
3141
+ * A look changes chrome, never brand: nothing here sets --desk-accent or --desk-ground. Selectors
3142
+ * carry the look AND the base rule's own specificity, so they win by coming later, not by !important.
3143
+ */
3144
+
3145
+ /* ── GNOME (Adwaita) ── */
3146
+
3147
+ [data-look="gnome"] {
3148
+ --desk-font: Cantarell, "Adwaita Sans", system-ui, sans-serif;
3149
+ }
3150
+
3151
+ /*
3152
+ * Title and note stacked in the middle of the bar, centred on the bar and not on the space left over,
3153
+ * as a GNOME header bar does. The end of the bar keeps room for the controls and a little more.
3154
+ */
3155
+ [data-look="gnome"] .desk-titlebar {
3156
+ position: relative;
3157
+ min-height: 46px;
3158
+ padding: 0 11px;
3159
+ justify-content: flex-end;
3160
+ }
3161
+
3162
+ [data-look="gnome"] .desk-titlebar-heading {
3163
+ position: absolute;
3164
+ left: 50%;
3165
+ transform: translateX(-50%);
3166
+ max-width: calc(100% - 2 * 120px);
3167
+ display: flex;
3168
+ flex-direction: column;
3169
+ align-items: center;
3170
+ text-align: center;
3171
+ pointer-events: none;
3172
+ }
3173
+
3174
+ [data-look="gnome"] .desk-titlebar-heading > * {
3175
+ max-width: 100%;
3176
+ }
3177
+
3178
+ [data-look="gnome"] .desk-title {
3179
+ font-size: 13.5px;
3180
+ font-weight: 700;
3181
+ }
3182
+
3183
+ [data-look="gnome"] .desk-window-note {
3184
+ margin: 0;
3185
+ font-size: 11.5px;
3186
+ }
3187
+
3188
+ [data-look="gnome"] .desk-window .desk-controls {
3189
+ gap: 12px;
3190
+ }
3191
+
3192
+ [data-look="gnome"] .desk-window .desk-control[data-control] {
3193
+ width: 24px;
3194
+ height: 24px;
3195
+ background: color-mix(in srgb, var(--desk-ink) 10%, transparent);
3196
+ color: var(--desk-ink);
3197
+ }
3198
+
3199
+ [data-look="gnome"] .desk-window .desk-controls .desk-control[data-control]:hover {
3200
+ background: color-mix(in srgb, var(--desk-ink) 16%, transparent);
3201
+ }
3202
+
3203
+ [data-look="gnome"] .desk-window .desk-controls .desk-control[data-control]:active {
3204
+ background: color-mix(in srgb, var(--desk-ink) 26%, transparent);
3205
+ }
3206
+
3207
+ /* GNOME's marks are always there: symbolic icons, not colours. */
3208
+ [data-look="gnome"] .desk-window .desk-control-glyph {
3209
+ opacity: 1;
3210
+ color: currentColor;
3211
+ stroke-width: 1.3;
3212
+ }
3213
+
3214
+ /* The key window is told apart by its shadow and its title, not by an accent border. */
3215
+ [data-look="gnome"] .desk-window[data-focused] {
3216
+ border-color: var(--desk-rule);
3217
+ }
3218
+
3219
+ /* ── Windows 11 ── */
3220
+
3221
+ [data-look="windows"] {
3222
+ --desk-font: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
3223
+ --desk-radius: 8px;
3224
+ }
3225
+
3226
+ /* The controls run the full height of the bar, flush to its end. */
3227
+ [data-look="windows"] .desk-titlebar {
3228
+ min-height: 32px;
3229
+ padding: 0 0 0 12px;
3230
+ align-items: stretch;
3231
+ background: var(--desk-surface);
3232
+ }
3233
+
3234
+ [data-look="windows"] .desk-titlebar > * {
3235
+ align-self: center;
3236
+ }
3237
+
3238
+ [data-look="windows"] .desk-title {
3239
+ flex: 1 1 auto;
3240
+ font-size: 12px;
3241
+ font-weight: 400;
3242
+ }
3243
+
3244
+ [data-look="windows"] .desk-titlebar > .desk-controls {
3245
+ align-self: stretch;
3246
+ margin-left: var(--desk-space-2);
3247
+ gap: 0;
3248
+ }
3249
+
3250
+ [data-look="windows"] .desk-window .desk-control[data-control] {
3251
+ width: 46px;
3252
+ height: auto;
3253
+ border-radius: 0;
3254
+ background: transparent;
3255
+ color: var(--desk-ink);
3256
+ }
3257
+
3258
+ [data-look="windows"] .desk-window .desk-controls .desk-control[data-control]:hover {
3259
+ background: color-mix(in srgb, var(--desk-ink) 8%, transparent);
3260
+ }
3261
+
3262
+ [data-look="windows"] .desk-window .desk-controls .desk-control[data-control="close"]:hover {
3263
+ background: #c42b1c;
3264
+ color: #ffffff;
3265
+ }
3266
+
3267
+ [data-look="windows"] .desk-window .desk-control-glyph {
3268
+ width: 10px;
3269
+ height: 10px;
3270
+ opacity: 1;
3271
+ color: currentColor;
3272
+ stroke-width: 1;
3273
+ stroke-linecap: butt;
3274
+ }
3275
+
3276
+ [data-look="windows"] .desk-window:not([data-focused]) .desk-control-glyph {
3277
+ opacity: .45;
3278
+ }
3279
+
3280
+ [data-look="windows"] .desk-control:focus-visible {
3281
+ outline-offset: -2px;
3282
+ }
3283
+
3284
+ /*
3285
+ * ── GNOME shell: the top bar and the dash are dark in either theme, and so is what opens from them ──
3286
+ * The tokens are redefined on the bar and the dock themselves, so their menus and stacks, which sit
3287
+ * inside them, come out dark too — as the shell's own menus do.
3288
+ */
3289
+ [data-look="gnome"] .desk-menubar,
3290
+ [data-look="gnome"] .desk-dock {
3291
+ --desk-ink: #ffffff;
3292
+ --desk-muted: rgb(255 255 255 / 68%);
3293
+ --desk-surface: #2a2a2a;
3294
+ --desk-rule: rgb(255 255 255 / 10%);
3295
+ --desk-dock-icon: transparent;
3296
+ }
3297
+
3298
+ [data-look="gnome"] .desk-menubar {
3299
+ height: 32px;
3300
+ --desk-dock-glass: rgb(0 0 0 / 94%);
3301
+ border-bottom: 0;
3302
+ font-weight: 600;
3303
+ }
3304
+
3305
+ [data-look="gnome"] .desk-menubar-title {
3306
+ border-radius: 999px;
3307
+ }
3308
+
3309
+ [data-look="gnome"] .desk-menu {
3310
+ border-radius: 12px;
3311
+ padding: 6px;
3312
+ }
3313
+
3314
+ [data-look="gnome"] .desk-menu-item {
3315
+ border-radius: 6px;
3316
+ font-weight: 400;
3317
+ }
3318
+
3319
+ [data-look="gnome"] .desk-menu-item[data-active],
3320
+ [data-look="windows"] .desk-menu-item[data-active] {
3321
+ background: color-mix(in srgb, var(--desk-ink) 10%, transparent);
3322
+ color: var(--desk-ink);
3323
+ }
3324
+
3325
+ [data-look="gnome"] .desk-dock {
3326
+ --desk-dock-glass: rgb(24 24 24 / 86%);
3327
+ border-radius: 20px;
3328
+ }
3329
+
3330
+ [data-look="gnome"] .desk-dock .desk-dock-item {
3331
+ border: 0;
3332
+ border-radius: 12px;
3333
+ }
3334
+
3335
+ /* No magnification: GNOME's dash lights an item up rather than growing it. */
3336
+ [data-look="gnome"] .desk-dock .desk-dock-item:hover:not(:disabled),
3337
+ [data-look="windows"] .desk-dock .desk-dock-item:hover:not(:disabled) {
3338
+ transform: none;
3339
+ margin: 0;
3340
+ background: color-mix(in srgb, var(--desk-ink) 12%, transparent);
3341
+ }
3342
+
3343
+ /* ── Windows: a flat bar, taskbar tiles, and a pill that widens for the key window ── */
3344
+
3345
+ [data-look="windows"] .desk-menubar {
3346
+ background: var(--desk-surface);
3347
+ backdrop-filter: none;
3348
+ -webkit-backdrop-filter: none;
3349
+ }
3350
+
3351
+ [data-look="windows"] .desk-menubar-title,
3352
+ [data-look="windows"] .desk-menu-item {
3353
+ border-radius: 4px;
3354
+ }
3355
+
3356
+ [data-look="windows"] .desk-menu {
3357
+ border-radius: 8px;
3358
+ padding: 4px;
3359
+ }
3360
+
3361
+ [data-look="windows"] .desk-dock {
3362
+ border-radius: 8px;
3363
+ }
3364
+
3365
+ [data-look="windows"] .desk-dock .desk-dock-item {
3366
+ border: 0;
3367
+ border-radius: 4px;
3368
+ background: transparent;
3369
+ }
3370
+
3371
+ [data-look="windows"] .desk-dock .desk-dock-item[data-running]::after {
3372
+ width: 6px;
3373
+ height: 3px;
3374
+ margin-left: -3px;
3375
+ border-radius: 2px;
3376
+ bottom: -4px;
3377
+ }
3378
+
3379
+ [data-look="windows"] .desk-dock[data-side="bottom"] .desk-dock-item[data-focused]::after {
3380
+ width: 16px;
3381
+ margin-left: -8px;
3382
+ }
3383
+
3384
+ [data-look="windows"] .desk-dock:not([data-side="bottom"]) .desk-dock-item[data-running]::after {
3385
+ width: 3px;
3386
+ height: 6px;
3387
+ margin: -3px 0 0;
3388
+ }
3389
+
3390
+ [data-look="windows"] .desk-dock:not([data-side="bottom"]) .desk-dock-item[data-focused]::after {
3391
+ height: 16px;
3392
+ margin-top: -8px;
3393
+ }
@@ -0,0 +1,29 @@
1
+ import { type BuiltInSound, type Sound } from './sounds.js';
2
+ export interface FxOptions<Extra extends string> {
3
+ /** Sounds of the app's own, or replacements for the built-ins. */
4
+ readonly sounds?: Readonly<Record<Extra, Sound>>;
5
+ /** Where the mute is kept. Two apps on one origin that should not share a switch need two keys. */
6
+ readonly storageKey?: string;
7
+ /** A second request for the same sound inside this many milliseconds is the same event. */
8
+ readonly coalesceMs?: number;
9
+ /** Master gain over every sound. */
10
+ readonly volume?: number;
11
+ }
12
+ export interface Fx<Name extends string> {
13
+ /** Plays now if it can; whether it did. Silent when muted, repeated, or before any press. */
14
+ play(name: Name, nowMs?: number): boolean;
15
+ /**
16
+ * Opens audio on the first press. A browser refuses sound on a page nobody has touched, and a
17
+ * sound arrives unasked, long after the last click: the press has to be taken while it happens.
18
+ * Returns a teardown.
19
+ */
20
+ unlock(): () => void;
21
+ muted(): boolean;
22
+ setMuted(muted: boolean): void;
23
+ /** Told when the mute changes, here or in another tab. */
24
+ subscribe(listener: () => void): () => void;
25
+ /** Schedules a sound into any context, an offline one included, for measuring. */
26
+ render(ctx: BaseAudioContext, name: Name, out: AudioNode): void;
27
+ }
28
+ export declare function createFx<Extra extends string = never>(options?: FxOptions<Extra>): Fx<BuiltInSound | Extra>;
29
+ //# sourceMappingURL=fx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fx.d.ts","sourceRoot":"","sources":["../../src/fx/fx.ts"],"names":[],"mappings":"AAOA,OAAO,EAAkB,KAAK,YAAY,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAA;AAE3E,MAAM,WAAW,SAAS,CAAC,KAAK,SAAS,MAAM;IAC7C,kEAAkE;IAClE,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;IAChD,mGAAmG;IACnG,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,oCAAoC;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,EAAE,CAAC,IAAI,SAAS,MAAM;IACrC,6FAA6F;IAC7F,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACzC;;;;OAIG;IACH,MAAM,IAAI,MAAM,IAAI,CAAA;IACpB,KAAK,IAAI,OAAO,CAAA;IAChB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;IAC9B,0DAA0D;IAC1D,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;IAC3C,kFAAkF;IAClF,MAAM,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,GAAG,IAAI,CAAA;CAChE;AASD,wBAAgB,QAAQ,CAAC,KAAK,SAAS,MAAM,GAAG,KAAK,EACnD,OAAO,GAAE,SAAS,CAAC,KAAK,CAAM,GAC7B,EAAE,CAAC,YAAY,GAAG,KAAK,CAAC,CAkG1B"}
package/dist/fx/fx.js ADDED
@@ -0,0 +1,119 @@
1
+ /*
2
+ * Sounds for an app on the desk: `attention`, `ready` and `failed`, and any an app adds.
3
+ *
4
+ * WHEN to make one is the app's decision and the hard part; see HIG.md, "Sound". This is the
5
+ * instrument: one audio context, opened on the first press, a repeat of the same sound inside a
6
+ * short window heard once, and a mute this browser remembers.
7
+ */
8
+ import { SCORES, scored } from './sounds.js';
9
+ function audioContextClass() {
10
+ if (typeof window === 'undefined')
11
+ return null;
12
+ return window.AudioContext ?? window.webkitAudioContext ?? null;
13
+ }
14
+ export function createFx(options = {}) {
15
+ const { storageKey = 'desk-fx-muted', coalesceMs = 1500, volume = 0.8 } = options;
16
+ const builtIn = Object.fromEntries(Object.entries(SCORES).map(([name, score]) => [name, scored(score)]));
17
+ const sounds = { ...builtIn, ...options.sounds };
18
+ const lastPlayed = new Map();
19
+ const listeners = new Set();
20
+ let audio = null;
21
+ const context = () => {
22
+ if (audio)
23
+ return audio;
24
+ const Class = audioContextClass();
25
+ if (!Class)
26
+ return null;
27
+ try {
28
+ audio = new Class();
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ return audio;
34
+ };
35
+ const muted = () => {
36
+ try {
37
+ return localStorage.getItem(storageKey) === 'yes';
38
+ }
39
+ catch {
40
+ return false;
41
+ }
42
+ };
43
+ const render = (ctx, name, out) => {
44
+ const master = ctx.createGain();
45
+ const at = ctx.currentTime + 0.01;
46
+ master.gain.setValueAtTime(volume, at);
47
+ master.connect(out);
48
+ sounds[name](ctx, master, at);
49
+ };
50
+ return {
51
+ play(name, nowMs = Date.now()) {
52
+ if (muted())
53
+ return false;
54
+ const previous = lastPlayed.get(name);
55
+ if (previous !== undefined && nowMs - previous < coalesceMs)
56
+ return false;
57
+ const ctx = context();
58
+ // Never resumed from here: outside a press the promise may never settle, and a sound that
59
+ // lands a click late belongs to the wrong moment.
60
+ if (!ctx || ctx.state !== 'running')
61
+ return false;
62
+ lastPlayed.set(name, nowMs);
63
+ try {
64
+ render(ctx, name, ctx.destination);
65
+ return true;
66
+ }
67
+ catch {
68
+ return false;
69
+ }
70
+ },
71
+ unlock() {
72
+ if (typeof window === 'undefined')
73
+ return () => undefined;
74
+ const stop = () => {
75
+ window.removeEventListener('pointerdown', open);
76
+ window.removeEventListener('keydown', open);
77
+ };
78
+ function open() {
79
+ stop();
80
+ const ctx = context();
81
+ // Inside the handler, where the browser is willing to listen.
82
+ if (ctx && ctx.state !== 'running')
83
+ void ctx.resume().catch(() => undefined);
84
+ }
85
+ window.addEventListener('pointerdown', open);
86
+ window.addEventListener('keydown', open);
87
+ return stop;
88
+ },
89
+ muted,
90
+ setMuted(next) {
91
+ try {
92
+ if (next)
93
+ localStorage.setItem(storageKey, 'yes');
94
+ else
95
+ localStorage.removeItem(storageKey);
96
+ }
97
+ catch {
98
+ // Blocked site data: sounds stay on, which is the default.
99
+ }
100
+ listeners.forEach((listener) => listener());
101
+ },
102
+ subscribe(listener) {
103
+ listeners.add(listener);
104
+ const fromAnotherTab = (event) => {
105
+ if (event.key === storageKey)
106
+ listener();
107
+ };
108
+ if (typeof window !== 'undefined')
109
+ window.addEventListener('storage', fromAnotherTab);
110
+ return () => {
111
+ listeners.delete(listener);
112
+ if (typeof window !== 'undefined')
113
+ window.removeEventListener('storage', fromAnotherTab);
114
+ };
115
+ },
116
+ render,
117
+ };
118
+ }
119
+ //# sourceMappingURL=fx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fx.js","sourceRoot":"","sources":["../../src/fx/fx.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAiC,MAAM,aAAa,CAAA;AAgC3E,SAAS,iBAAiB;IACxB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAA;IAC9C,OAAO,MAAM,CAAC,YAAY,IAAK,MAAwC,CAAC,kBAAkB,IAAI,IAAI,CAAA;AACpG,CAAC;AAED,MAAM,UAAU,QAAQ,CACtB,OAAO,GAAqB,EAAE;IAG9B,MAAM,EAAE,UAAU,GAAG,eAAe,EAAE,UAAU,GAAG,IAAI,EAAE,MAAM,GAAG,GAAG,EAAE,GAAG,OAAO,CAAA;IACjF,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACxG,MAAM,MAAM,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,EAAyB,CAAA;IACvE,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC5C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;IACvC,IAAI,KAAK,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,KAAK,CAAC,CAAA;;oBAC5C,YAAY,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;YAC1C,CAAC;YAAC,MAAM,CAAC;gBACP,2DAA2D;YAC7D,CAAC;YACD,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC7C,CAAC;QAED,SAAS,CAAC,QAAQ;YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvB,MAAM,cAAc,GAAG,CAAC,KAAmB,EAAQ,EAAE;gBACnD,IAAI,KAAK,CAAC,GAAG,KAAK,UAAU;oBAAE,QAAQ,EAAE,CAAA;YAC1C,CAAC,CAAA;YACD,IAAI,OAAO,MAAM,KAAK,WAAW;gBAAE,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;YACrF,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;gBAC1B,IAAI,OAAO,MAAM,KAAK,WAAW;oBAAE,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;YAC1F,CAAC,CAAA;QACH,CAAC;QAED,MAAM;KACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { createFx } from './fx.js';
2
+ export type { Fx, FxOptions } from './fx.js';
3
+ export { BELL, GROWL, SCORES, scored } from './sounds.js';
4
+ export type { BuiltInSound, Note, Overtone, Score, Sound, Voice } from './sounds.js';
5
+ export { measureLoudness } from './measure.js';
6
+ export type { Loudness, MeasureOptions } from './measure.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,YAAY,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzD,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { createFx } from './fx.js';
2
+ export { BELL, GROWL, SCORES, scored } from './sounds.js';
3
+ export { measureLoudness } from './measure.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,18 @@
1
+ import type { Fx } from './fx.js';
2
+ export interface Loudness {
3
+ /** Momentary loudness, LUFS. */
4
+ readonly lufs: number;
5
+ /** Sample peak before weighting, dBFS: how close it comes to clipping. */
6
+ readonly peakDb: number;
7
+ }
8
+ export interface MeasureOptions {
9
+ /**
10
+ * `laptop` adds a 4th-order high-pass at 200 Hz, about where small speakers give up. Level for
11
+ * that one: it is what most people have.
12
+ */
13
+ readonly speaker?: 'full' | 'laptop';
14
+ /** Seconds rendered; longer than the sound. */
15
+ readonly seconds?: number;
16
+ }
17
+ export declare function measureLoudness<Name extends string>(fx: Fx<Name>, name: Name, { speaker, seconds }?: MeasureOptions): Promise<Loudness>;
18
+ //# sourceMappingURL=measure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../src/fx/measure.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,WAAW,QAAQ;IACvB,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAA;IACpC,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B;AAOD,wBAAsB,eAAe,CAAC,IAAI,SAAS,MAAM,EACvD,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EACZ,IAAI,EAAE,IAAI,EACV,EAAE,OAAgB,EAAE,OAAW,EAAE,GAAE,cAAmB,GACrD,OAAO,CAAC,QAAQ,CAAC,CAqBnB"}