@rokkit/actions 1.2.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/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { pannable } from "./pannable.svelte.js";
6
6
  export { swipeable } from "./swipeable.svelte.js";
7
7
  export { themable } from "./themable.svelte.js";
8
8
  export { skinnable } from "./skinnable.svelte.js";
9
+ export { lockMode } from "./lock-mode.svelte.js";
9
10
  export { dismissable } from "./dismissable.svelte.js";
10
11
  export { fillable } from "./fillable.svelte.js";
11
12
  export { delegateKeyboardEvents } from "./delegate.svelte.js";
@@ -0,0 +1 @@
1
+ export function lockMode(node: any, mode: any): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/actions",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Contains generic actions that can be used in various components.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.js CHANGED
@@ -8,6 +8,7 @@ export { pannable } from './pannable.svelte.js'
8
8
  export { swipeable } from './swipeable.svelte.js'
9
9
  export { themable } from './themable.svelte.js'
10
10
  export { skinnable } from './skinnable.svelte.js'
11
+ export { lockMode } from './lock-mode.svelte.js'
11
12
  export { dismissable } from './dismissable.svelte.js'
12
13
  export { fillable } from './fillable.svelte.js'
13
14
  export { delegateKeyboardEvents } from './delegate.svelte.js'
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Lock a subtree to a fixed color mode, regardless of the document mode.
3
+ *
4
+ * Makes the element a theme context identical to the document root, but with
5
+ * `mode` forced: it mirrors the root's `data-style` / `data-skin` /
6
+ * `data-density` (the attributes `themable` writes — see themable.svelte.js)
7
+ * onto the element and sets `data-mode` to the locked value. It follows runtime
8
+ * style/skin/density changes via a MutationObserver on the document root; only
9
+ * `mode` stays pinned.
10
+ *
11
+ * Note: the locked mode is fixed at mount — to change it, re-mount the element
12
+ * (e.g. via a Svelte {#key} block).
13
+ *
14
+ * @param {HTMLElement} node
15
+ * @param {'dark'|'light'} mode
16
+ */
17
+
18
+ const MIRRORED = ['style', 'skin', 'density']
19
+
20
+ function syncFromRoot(node, mode) {
21
+ const root = document.documentElement
22
+ for (const key of MIRRORED) {
23
+ const value = root.dataset[key]
24
+ // dataset values are `string | undefined` (never null) — absent attr → delete
25
+ if (value === undefined) delete node.dataset[key]
26
+ else node.dataset[key] = value
27
+ }
28
+ node.dataset.mode = mode
29
+ }
30
+
31
+ export function lockMode(node, mode) {
32
+ $effect(() => {
33
+ if (typeof document === 'undefined') return
34
+ syncFromRoot(node, mode)
35
+ const observer = new MutationObserver(() => syncFromRoot(node, mode))
36
+ observer.observe(document.documentElement, {
37
+ attributes: true,
38
+ attributeFilter: ['data-style', 'data-skin', 'data-density']
39
+ })
40
+ // Mirrored attrs are intentionally NOT removed on disconnect — the
41
+ // wrapper element is orphaned on unmount.
42
+ return () => observer.disconnect()
43
+ })
44
+ }