sh3-core 0.17.0 → 0.17.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.
- package/dist/Sh3.svelte +48 -35
- package/dist/__screenshots__/handheld.browser.test.ts/handheld-viewport-flip-e2e-viewport-override-flips-chrome-and-body-branches-1.png +0 -0
- package/dist/actions/listActionsFromEntries.test.js +29 -0
- package/dist/actions/listActive.js +2 -0
- package/dist/actions/listeners.js +4 -0
- package/dist/actions/programmatic-dispatch.svelte.test.js +9 -2
- package/dist/actions/types.d.ts +8 -0
- package/dist/api.d.ts +4 -1
- package/dist/chrome/CompactChrome.svelte +96 -0
- package/dist/chrome/CompactChrome.svelte.d.ts +3 -0
- package/dist/chrome/CompactChrome.svelte.test.d.ts +1 -0
- package/dist/chrome/CompactChrome.svelte.test.js +67 -0
- package/dist/chrome/MenuSheet.svelte +224 -0
- package/dist/chrome/MenuSheet.svelte.d.ts +7 -0
- package/dist/chrome/MenuSheet.svelte.test.d.ts +1 -0
- package/dist/chrome/MenuSheet.svelte.test.js +46 -0
- package/dist/handheld.browser.test.d.ts +1 -0
- package/dist/handheld.browser.test.js +90 -0
- package/dist/layout/LayoutRenderer.svelte +12 -1
- package/dist/layout/LayoutRenderer.svelte.d.ts +2 -1
- package/dist/layout/compact/CompactRenderer.svelte +53 -0
- package/dist/layout/compact/CompactRenderer.svelte.d.ts +3 -0
- package/dist/layout/compact/CompactRenderer.svelte.test.d.ts +1 -0
- package/dist/layout/compact/CompactRenderer.svelte.test.js +76 -0
- package/dist/layout/compact/derive.d.ts +3 -0
- package/dist/layout/compact/derive.js +155 -0
- package/dist/layout/compact/derive.test.d.ts +1 -0
- package/dist/layout/compact/derive.test.js +160 -0
- package/dist/layout/compact/drawerStore.svelte.d.ts +21 -0
- package/dist/layout/compact/drawerStore.svelte.js +75 -0
- package/dist/layout/compact/drawerStore.svelte.test.d.ts +1 -0
- package/dist/layout/compact/drawerStore.svelte.test.js +43 -0
- package/dist/layout/compact/resolveRole.d.ts +6 -0
- package/dist/layout/compact/resolveRole.js +13 -0
- package/dist/layout/compact/resolveRole.test.d.ts +1 -0
- package/dist/layout/compact/resolveRole.test.js +18 -0
- package/dist/layout/compact/types.d.ts +27 -0
- package/dist/layout/compact/types.js +15 -0
- package/dist/layout/presets.compactVariant.test.d.ts +1 -0
- package/dist/layout/presets.compactVariant.test.js +27 -0
- package/dist/layout/presets.d.ts +12 -0
- package/dist/layout/presets.js +16 -0
- package/dist/layout/store.drawers.svelte.test.d.ts +1 -0
- package/dist/layout/store.drawers.svelte.test.js +49 -0
- package/dist/layout/store.schemaVersion.test.d.ts +1 -0
- package/dist/layout/store.schemaVersion.test.js +35 -0
- package/dist/layout/store.svelte.js +52 -2
- package/dist/layout/types.d.ts +43 -1
- package/dist/layout/types.js +1 -1
- package/dist/overlays/DrawerSurface.svelte +141 -0
- package/dist/overlays/DrawerSurface.svelte.d.ts +12 -0
- package/dist/overlays/DrawerSurface.svelte.test.d.ts +1 -0
- package/dist/overlays/DrawerSurface.svelte.test.js +67 -0
- package/dist/overlays/OverlayRoots.svelte +12 -9
- package/dist/overlays/types.d.ts +1 -1
- package/dist/sh3Api/headless.js +9 -1
- package/dist/sh3Api/headless.svelte.test.js +45 -1
- package/dist/sh3Runtime.svelte.d.ts +36 -0
- package/dist/sh3Runtime.svelte.js +33 -0
- package/dist/shards/types.d.ts +9 -1
- package/dist/tokens.css +3 -2
- package/dist/verbs/types.d.ts +5 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/viewport/classify.d.ts +8 -0
- package/dist/viewport/classify.js +20 -0
- package/dist/viewport/classify.test.d.ts +1 -0
- package/dist/viewport/classify.test.js +32 -0
- package/dist/viewport/store.browser.test.d.ts +1 -0
- package/dist/viewport/store.browser.test.js +33 -0
- package/dist/viewport/store.svelte.d.ts +9 -0
- package/dist/viewport/store.svelte.js +71 -0
- package/dist/viewport/store.svelte.test.d.ts +1 -0
- package/dist/viewport/store.svelte.test.js +54 -0
- package/dist/viewport/types.d.ts +9 -0
- package/dist/viewport/types.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* viewport store — reactive ViewportInfo with subscribe + override.
|
|
3
|
+
*
|
|
4
|
+
* Subscribes to window.resize, screen.orientation.change, and matchMedia
|
|
5
|
+
* change events for `pointer: coarse` / `hover: none`. Re-runs classify(),
|
|
6
|
+
* notifies subscribers only on class change (not every resize tick).
|
|
7
|
+
*
|
|
8
|
+
* Module is loaded eagerly by createShell, but the listener-wiring branch
|
|
9
|
+
* is gated on `typeof window` so node-only test runs don't crash.
|
|
10
|
+
*/
|
|
11
|
+
import { classify } from './classify';
|
|
12
|
+
let pinnedClass = $state(null);
|
|
13
|
+
const subscribers = new Set();
|
|
14
|
+
function read() {
|
|
15
|
+
if (typeof window === 'undefined') {
|
|
16
|
+
return { class: 'desktop', width: 1920, height: 1080, coarsePointer: false, noHover: false, dpr: 1 };
|
|
17
|
+
}
|
|
18
|
+
const width = window.innerWidth;
|
|
19
|
+
const height = window.innerHeight;
|
|
20
|
+
const coarsePointer = window.matchMedia('(pointer: coarse)').matches;
|
|
21
|
+
const noHover = window.matchMedia('(hover: none)').matches;
|
|
22
|
+
const dpr = window.devicePixelRatio;
|
|
23
|
+
const cls = pinnedClass !== null && pinnedClass !== void 0 ? pinnedClass : classify({ width, coarsePointer, noHover, dpr });
|
|
24
|
+
return { class: cls, width, height, coarsePointer, noHover, dpr };
|
|
25
|
+
}
|
|
26
|
+
let cached = $state(read());
|
|
27
|
+
function recompute() {
|
|
28
|
+
const next = read();
|
|
29
|
+
const prevClass = cached.class;
|
|
30
|
+
cached = next;
|
|
31
|
+
if (next.class !== prevClass) {
|
|
32
|
+
for (const cb of subscribers)
|
|
33
|
+
cb(next);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (typeof window !== 'undefined') {
|
|
37
|
+
window.addEventListener('resize', recompute);
|
|
38
|
+
window.matchMedia('(pointer: coarse)').addEventListener('change', recompute);
|
|
39
|
+
window.matchMedia('(hover: none)').addEventListener('change', recompute);
|
|
40
|
+
if (typeof screen !== 'undefined' && screen.orientation) {
|
|
41
|
+
screen.orientation.addEventListener('change', recompute);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export const viewportStore = {
|
|
45
|
+
get current() {
|
|
46
|
+
return cached;
|
|
47
|
+
},
|
|
48
|
+
subscribe(cb) {
|
|
49
|
+
subscribers.add(cb);
|
|
50
|
+
return () => { subscribers.delete(cb); };
|
|
51
|
+
},
|
|
52
|
+
override(cls) {
|
|
53
|
+
if (pinnedClass === cls)
|
|
54
|
+
return;
|
|
55
|
+
pinnedClass = cls;
|
|
56
|
+
recompute();
|
|
57
|
+
// recompute only fires subscribers on class change. If override pins
|
|
58
|
+
// to the same class as the auto-derived one, the visible class doesn't
|
|
59
|
+
// change. Force-fire so consumers re-read the override state.
|
|
60
|
+
for (const cb of subscribers)
|
|
61
|
+
cb(cached);
|
|
62
|
+
},
|
|
63
|
+
get pinned() {
|
|
64
|
+
return pinnedClass;
|
|
65
|
+
},
|
|
66
|
+
/** Test-only reset hook. Not exported from index.ts. */
|
|
67
|
+
__reset() {
|
|
68
|
+
pinnedClass = null;
|
|
69
|
+
subscribers.clear();
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* DOM tests for the viewport store. happy-dom's matchMedia stub returns
|
|
3
|
+
* { matches: false, addEventListener, removeEventListener } so we can
|
|
4
|
+
* verify the wiring without driving the real browser engine.
|
|
5
|
+
*
|
|
6
|
+
* These tests intentionally use the store's __reset hook between cases
|
|
7
|
+
* to isolate subscriber state.
|
|
8
|
+
*/
|
|
9
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
10
|
+
import { viewportStore } from './store.svelte';
|
|
11
|
+
describe('viewport store (dom)', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
viewportStore.__reset();
|
|
14
|
+
});
|
|
15
|
+
it('current returns a ViewportInfo with shape', () => {
|
|
16
|
+
const info = viewportStore.current;
|
|
17
|
+
expect(info.class).toMatch(/desktop|compact/);
|
|
18
|
+
expect(typeof info.width).toBe('number');
|
|
19
|
+
expect(typeof info.height).toBe('number');
|
|
20
|
+
});
|
|
21
|
+
it('override(compact) flips class to compact', () => {
|
|
22
|
+
viewportStore.override('compact');
|
|
23
|
+
expect(viewportStore.current.class).toBe('compact');
|
|
24
|
+
expect(viewportStore.pinned).toBe('compact');
|
|
25
|
+
});
|
|
26
|
+
it('override(null) restores pinned to null', () => {
|
|
27
|
+
viewportStore.override('compact');
|
|
28
|
+
viewportStore.override(null);
|
|
29
|
+
expect(viewportStore.pinned).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
it('subscribers fire on class change via override', () => {
|
|
32
|
+
const fires = [];
|
|
33
|
+
const unsub = viewportStore.subscribe((i) => fires.push(i.class));
|
|
34
|
+
viewportStore.override('compact');
|
|
35
|
+
expect(fires).toContain('compact');
|
|
36
|
+
unsub();
|
|
37
|
+
});
|
|
38
|
+
it('subscribers fire on override even when class does not change', () => {
|
|
39
|
+
// Auto-class on happy-dom is desktop (default width 1024 + fine pointer).
|
|
40
|
+
// override('desktop') should still fire so consumers see pin state change.
|
|
41
|
+
const fires = [];
|
|
42
|
+
const unsub = viewportStore.subscribe((i) => fires.push(i.class));
|
|
43
|
+
viewportStore.override('desktop');
|
|
44
|
+
expect(fires.length).toBeGreaterThan(0);
|
|
45
|
+
unsub();
|
|
46
|
+
});
|
|
47
|
+
it('unsubscribe stops further notifications', () => {
|
|
48
|
+
const fires = [];
|
|
49
|
+
const unsub = viewportStore.subscribe((i) => fires.push(i.class));
|
|
50
|
+
unsub();
|
|
51
|
+
viewportStore.override('compact');
|
|
52
|
+
expect(fires).toEqual([]);
|
|
53
|
+
});
|
|
54
|
+
});
|