@stnd/lab 1.1.0 → 1.3.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
@@ -1,5 +1,27 @@
1
1
  # @stnd/lab
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Auto-bumped @stnd/lab due to modified code.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @stnd/ui@0.11.0
13
+
14
+ ## 1.2.0
15
+
16
+ ### Minor Changes
17
+
18
+ - Auto-bumped @stnd/lab due to modified code.
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies
23
+ - @stnd/ui@0.10.0
24
+
3
25
  ## 1.1.0
4
26
 
5
27
  ### Minor Changes
package/Lab.svelte CHANGED
@@ -40,6 +40,17 @@
40
40
  // =========================================================================
41
41
  // STATE
42
42
  // =========================================================================
43
+ // Props. `open` opens the panel on mount and `pin` keeps it open: the Studio
44
+ // page embeds the Lab that way, so it works in production too.
45
+ let { open = false, pin = false } = $props();
46
+
47
+ // One Lab per page. The dev module mounts it on every page and the Studio
48
+ // mounts its own; whichever comes second renders nothing and asks the first
49
+ // one to do what it was asked for. Decided at creation, before any effect runs.
50
+ const duplicate =
51
+ typeof window !== "undefined" && window.__stndLabClaimed === true;
52
+ if (typeof window !== "undefined" && !duplicate) window.__stndLabClaimed = true;
53
+
43
54
  let view = $state("dormant"); // dormant | open
44
55
  let closeTimer;
45
56
  let isScrolling = $state(false);
@@ -149,6 +160,7 @@
149
160
  let scheme = $derived(userScheme === "auto" ? systemScheme : userScheme);
150
161
 
151
162
  $effect(() => {
163
+ if (duplicate) return;
152
164
  if (typeof sessionStorage !== "undefined") {
153
165
  sessionStorage.setItem("stnd-scheme", userScheme);
154
166
  sessionStorage.setItem("stnd-pinned", String(pinned));
@@ -438,6 +450,19 @@
438
450
  // LIFECYCLE
439
451
  // =========================================================================
440
452
  onMount(() => {
453
+ if (duplicate) {
454
+ let tries = 0;
455
+ const relay = setInterval(() => {
456
+ const first = window.StandardLab;
457
+ if (first) {
458
+ if (open) first.open();
459
+ if (pin) first.pin();
460
+ clearInterval(relay);
461
+ } else if (++tries > 40) clearInterval(relay);
462
+ }, 50);
463
+ return () => clearInterval(relay);
464
+ }
465
+
441
466
  version = document.documentElement.dataset.standardVersion || "";
442
467
  viewportW = window.innerWidth;
443
468
 
@@ -573,6 +598,8 @@
573
598
  };
574
599
 
575
600
  restoreLabState();
601
+ if (open) view = "open";
602
+ if (pin) pinned = true;
576
603
  document.addEventListener("astro:after-swap", restoreLabState);
577
604
 
578
605
  // Global API for dev toolbar compatibility
@@ -589,6 +616,12 @@
589
616
  toggle() {
590
617
  view = view === "dormant" ? "open" : "dormant";
591
618
  },
619
+ pin() {
620
+ pinned = true;
621
+ },
622
+ unpin() {
623
+ pinned = false;
624
+ },
592
625
  refresh: syncFromDOM,
593
626
  };
594
627
 
@@ -659,6 +692,7 @@
659
692
  window.removeEventListener("scroll", onScroll);
660
693
  mql.removeEventListener("change", onSchemeChange);
661
694
  delete window.StandardLab;
695
+ delete window.__stndLabClaimed;
662
696
  };
663
697
  });
664
698
 
@@ -669,6 +703,7 @@
669
703
  // Persist panel state + dispatch event for dev toolbar
670
704
  // Shrink the page when the sidebar is open (like DevTools)
671
705
  $effect(() => {
706
+ if (duplicate) return;
672
707
  if (typeof document === "undefined") return;
673
708
  const el = document.documentElement;
674
709
  if (view === "open") {
@@ -679,6 +714,7 @@
679
714
  });
680
715
 
681
716
  $effect(() => {
717
+ if (duplicate) return;
682
718
  if (typeof window === "undefined") return;
683
719
  if (view === "dormant") {
684
720
  sessionStorage.removeItem("stnd-panel-state");
@@ -908,6 +944,7 @@
908
944
  let modCount = $derived(modified.size);
909
945
  </script>
910
946
 
947
+ {#if !duplicate}
911
948
  <!-- ======================================================================
912
949
  TRIGGER / HANDLER
913
950
  ====================================================================== -->
@@ -1394,6 +1431,7 @@
1394
1431
  </footer>
1395
1432
  </div>
1396
1433
  {/if}
1434
+ {/if}
1397
1435
 
1398
1436
  <!-- ======================================================================
1399
1437
  STYLES — Fully scoped, isolated from design tokens
@@ -1516,7 +1554,7 @@
1516
1554
  border-bottom: var(--border);
1517
1555
  flex-shrink: 0;
1518
1556
 
1519
- background: var(--color-surface-light-1);
1557
+ background: var(--color-surface-raised);
1520
1558
  }
1521
1559
  .lab-header-title {
1522
1560
  display: flex;
@@ -1710,7 +1748,7 @@
1710
1748
  padding: var(--space-half) var(--space);
1711
1749
  box-shadow: var(--shadow);
1712
1750
  flex-shrink: 0;
1713
- background: var(--color-surface-light-1);
1751
+ background: var(--color-surface-raised);
1714
1752
  }
1715
1753
 
1716
1754
  /* ═══════════ RESPONSIVE ═══════════ */
@@ -1728,26 +1766,10 @@
1728
1766
 
1729
1767
  /* ═══════════ GLOBAL SCHEME OVERRIDES ═══════════ */
1730
1768
  :global(:root[data-lab-scheme="dark"]) {
1731
- --color-background: var(--color-dark-background);
1732
- --color-foreground: var(--color-dark-foreground);
1733
- --color-accent: var(--color-dark-accent);
1734
- --color-header: var(--color-dark-header, var(--color-foreground));
1735
- --color-surface: color-mix(
1736
- in srgb,
1737
- var(--color-background) 100%,
1738
- transparent
1739
- );
1769
+ color-scheme: dark;
1740
1770
  }
1741
1771
  :global(:root[data-lab-scheme="light"]) {
1742
- --color-background: var(--color-light-background);
1743
- --color-foreground: var(--color-light-foreground);
1744
- --color-accent: var(--color-light-accent);
1745
- --color-header: var(--color-light-header, var(--color-foreground));
1746
- --color-surface: color-mix(
1747
- in srgb,
1748
- var(--color-background) 100%,
1749
- transparent
1750
- );
1772
+ color-scheme: light;
1751
1773
  }
1752
1774
  /* Combobox styles tuned for the Lab panel — make the combobox visually match lab inputs */
1753
1775
  :global(.lab-font-combobox .std-combobox-trigger) {
package/README.md CHANGED
@@ -62,6 +62,28 @@ The `Lab` component is typically injected automatically by the `@stnd/core` inte
62
62
  {/if}
63
63
  ```
64
64
 
65
+ ### In production: the Studio
66
+
67
+ The module that injects the Lab everywhere is dev-only, but a page can mount it on purpose. The
68
+ Studio (`apps/stnd.build`, `/studio`) does, in production too:
69
+
70
+ ```astro
71
+ ---
72
+ import Lab from "@stnd/lab/Lab.svelte";
73
+ ---
74
+ <Lab client:only="svelte" open pin />
75
+ ```
76
+
77
+ | Prop | Default | Effect |
78
+ |---|---|---|
79
+ | `open` | `false` | Opens the panel when it mounts |
80
+ | `pin` | `false` | Keeps it open (it does not close on a click outside or on mouse leave) |
81
+
82
+ There is one Lab per page. If the dev module has already mounted one, a second instance renders
83
+ nothing and asks the first to open or pin itself, so a page can ask for the Lab without caring who
84
+ got there first. `window.StandardLab` offers `open()`, `close()`, `toggle()`, `pin()`, `unpin()`
85
+ and `refresh()`.
86
+
65
87
  ## Shortcuts
66
88
  - `Cmd/Ctrl + S`: Toggle the Lab panel open/dormant (overrides the browser’s save dialog).
67
89
  - `Cmd/Ctrl + D`: Same toggle, alternate binding.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stnd/lab",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "svelte": "./Lab.svelte",
6
6
  "author": "Francis Fontaine",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "bezier-easing": "^3.0.1",
18
18
  "svelte": "5.57.2",
19
- "@stnd/ui": "0.9.0"
19
+ "@stnd/ui": "0.11.0"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "astro": ">=5.0.0"