@gadxr/ui 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/Avatar.svelte +136 -0
- package/dist/Avatar.svelte.d.ts +13 -0
- package/dist/Button.svelte +29 -0
- package/dist/Button.svelte.d.ts +4 -0
- package/dist/Button2D.svelte +77 -0
- package/dist/Button2D.svelte.d.ts +4 -0
- package/dist/Button3D.svelte +98 -0
- package/dist/Button3D.svelte.d.ts +4 -0
- package/dist/ButtonGroup.svelte +59 -0
- package/dist/ButtonGroup.svelte.d.ts +17 -0
- package/dist/Checkbox.svelte +209 -0
- package/dist/Checkbox.svelte.d.ts +14 -0
- package/dist/DimensionScope.svelte +7 -0
- package/dist/DimensionScope.svelte.d.ts +9 -0
- package/dist/Input.svelte +293 -0
- package/dist/Input.svelte.d.ts +23 -0
- package/dist/Key3D.svelte +67 -0
- package/dist/Key3D.svelte.d.ts +13 -0
- package/dist/Keyboard.svelte +167 -0
- package/dist/Keyboard.svelte.d.ts +9 -0
- package/dist/Menu.svelte +193 -0
- package/dist/Menu.svelte.d.ts +23 -0
- package/dist/Modal.svelte +103 -0
- package/dist/Modal.svelte.d.ts +16 -0
- package/dist/Panel.svelte +132 -0
- package/dist/Panel.svelte.d.ts +19 -0
- package/dist/Pressable3D.svelte +82 -0
- package/dist/Pressable3D.svelte.d.ts +28 -0
- package/dist/ProgressBar.svelte +153 -0
- package/dist/ProgressBar.svelte.d.ts +16 -0
- package/dist/RadialMenu.svelte +322 -0
- package/dist/RadialMenu.svelte.d.ts +28 -0
- package/dist/Rule3D.svelte +17 -0
- package/dist/Rule3D.svelte.d.ts +9 -0
- package/dist/Scene3D.svelte +24 -0
- package/dist/Scene3D.svelte.d.ts +11 -0
- package/dist/Slider.svelte +209 -0
- package/dist/Slider.svelte.d.ts +17 -0
- package/dist/Space3D.svelte +6 -0
- package/dist/Space3D.svelte.d.ts +7 -0
- package/dist/Spinner.svelte +64 -0
- package/dist/Spinner.svelte.d.ts +10 -0
- package/dist/Stack.svelte +41 -0
- package/dist/Stack.svelte.d.ts +15 -0
- package/dist/StackScope.svelte +7 -0
- package/dist/StackScope.svelte.d.ts +9 -0
- package/dist/Surface.svelte +152 -0
- package/dist/Surface.svelte.d.ts +30 -0
- package/dist/Tab.svelte +40 -0
- package/dist/Tab.svelte.d.ts +10 -0
- package/dist/Tabs.svelte +145 -0
- package/dist/Tabs.svelte.d.ts +13 -0
- package/dist/Tag.svelte +71 -0
- package/dist/Tag.svelte.d.ts +12 -0
- package/dist/Text.svelte +75 -0
- package/dist/Text.svelte.d.ts +4 -0
- package/dist/TextLine3D.svelte +84 -0
- package/dist/TextLine3D.svelte.d.ts +19 -0
- package/dist/ThemeProvider.svelte +7 -0
- package/dist/ThemeProvider.svelte.d.ts +9 -0
- package/dist/Toaster.svelte +104 -0
- package/dist/Toaster.svelte.d.ts +11 -0
- package/dist/Tooltip.svelte +174 -0
- package/dist/Tooltip.svelte.d.ts +14 -0
- package/dist/aframe/frame.d.ts +1 -0
- package/dist/aframe/frame.js +37 -0
- package/dist/aframe/index.d.ts +1 -0
- package/dist/aframe/index.js +19 -0
- package/dist/aframe/measure.d.ts +3 -0
- package/dist/aframe/measure.js +42 -0
- package/dist/aframe/placement.d.ts +88 -0
- package/dist/aframe/placement.js +163 -0
- package/dist/aframe/rounded.d.ts +61 -0
- package/dist/aframe/rounded.js +121 -0
- package/dist/aframe/scene.d.ts +9 -0
- package/dist/aframe/scene.js +101 -0
- package/dist/assets/Geist-OFL.txt +93 -0
- package/dist/assets/Geist-Regular.ttf +0 -0
- package/dist/button-style.d.ts +22 -0
- package/dist/button-style.js +34 -0
- package/dist/component-style.d.ts +79 -0
- package/dist/component-style.js +129 -0
- package/dist/context.d.ts +16 -0
- package/dist/context.js +26 -0
- package/dist/fonts.css +7 -0
- package/dist/fonts.d.ts +2 -0
- package/dist/fonts.js +7 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +40 -0
- package/dist/keyboard-layout.d.ts +28 -0
- package/dist/keyboard-layout.js +77 -0
- package/dist/layout-math.d.ts +20 -0
- package/dist/layout-math.js +22 -0
- package/dist/layout.svelte.d.ts +17 -0
- package/dist/layout.svelte.js +58 -0
- package/dist/radial-math.d.ts +33 -0
- package/dist/radial-math.js +90 -0
- package/dist/tabs-context.d.ts +13 -0
- package/dist/tabs-context.js +6 -0
- package/dist/text-edit.d.ts +46 -0
- package/dist/text-edit.js +133 -0
- package/dist/text-focus.svelte.d.ts +24 -0
- package/dist/text-focus.svelte.js +102 -0
- package/dist/theme.d.ts +335 -0
- package/dist/theme.js +312 -0
- package/dist/toast.svelte.d.ts +24 -0
- package/dist/toast.svelte.js +30 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.js +1 -0
- package/dist/xr.svelte.d.ts +9 -0
- package/dist/xr.svelte.js +24 -0
- package/package.json +44 -3
- package/README.md +0 -3
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// `rounded` A-Frame component (and <a-rounded> primitive): a rounded-rectangle slab,
|
|
2
|
+
// solid or glass. Owned by the design system and registered on first use, so apps
|
|
3
|
+
// don't need a <script> tag for it. Uses A-Frame's own three.js (AFRAME.THREE).
|
|
4
|
+
// Erasable TypeScript only — tests import it with Node's type stripping.
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
|
+
const glassMaterial = (THREE) => new THREE.MeshPhysicalMaterial({
|
|
7
|
+
roughness: 0.5,
|
|
8
|
+
transmission: 1,
|
|
9
|
+
thickness: 0.7,
|
|
10
|
+
clearcoat: 0.61,
|
|
11
|
+
clearcoatRoughness: 0.39,
|
|
12
|
+
});
|
|
13
|
+
// The component definition, built against a given three.js (tests pass their own).
|
|
14
|
+
export function roundedComponent(THREE) {
|
|
15
|
+
return {
|
|
16
|
+
schema: {
|
|
17
|
+
enabled: { default: true },
|
|
18
|
+
width: { type: 'number', default: 1 },
|
|
19
|
+
height: { type: 'number', default: 1 },
|
|
20
|
+
// Extrude thickness; ignored when `flat`.
|
|
21
|
+
depth: { type: 'number', default: 0.05 },
|
|
22
|
+
radius: { type: 'number', default: 0.3 },
|
|
23
|
+
topLeftRadius: { type: 'number', default: -1 },
|
|
24
|
+
topRightRadius: { type: 'number', default: -1 },
|
|
25
|
+
bottomLeftRadius: { type: 'number', default: -1 },
|
|
26
|
+
bottomRightRadius: { type: 'number', default: -1 },
|
|
27
|
+
color: { type: 'color', default: '#F0F0F0' },
|
|
28
|
+
opacity: { type: 'number', default: 1 },
|
|
29
|
+
glass: { type: 'boolean', default: false },
|
|
30
|
+
flat: { type: 'boolean', default: false },
|
|
31
|
+
},
|
|
32
|
+
init() {
|
|
33
|
+
// update() picks the material (glass or solid) right after init.
|
|
34
|
+
this.rounded = new THREE.Mesh(this.draw(), new THREE.MeshPhongMaterial({ color: new THREE.Color(this.data.color), side: THREE.DoubleSide }));
|
|
35
|
+
this.updateOpacity();
|
|
36
|
+
this.el.setObject3D('mesh', this.rounded);
|
|
37
|
+
},
|
|
38
|
+
update() {
|
|
39
|
+
if (!this.rounded)
|
|
40
|
+
return;
|
|
41
|
+
this.rounded.visible = this.data.enabled;
|
|
42
|
+
if (!this.data.enabled)
|
|
43
|
+
return;
|
|
44
|
+
this.rounded.geometry.dispose();
|
|
45
|
+
this.rounded.geometry = this.draw();
|
|
46
|
+
// Swap materials only when `glass` changes, so frequent updates (hover colors, resizing)
|
|
47
|
+
// don't leak materials, and turning glass off goes back to a solid slab.
|
|
48
|
+
if (this.data.glass !== !!this.rounded.material.isMeshPhysicalMaterial) {
|
|
49
|
+
this.rounded.material.dispose();
|
|
50
|
+
this.rounded.material = this.data.glass
|
|
51
|
+
? glassMaterial(THREE)
|
|
52
|
+
: new THREE.MeshPhongMaterial({ side: THREE.DoubleSide });
|
|
53
|
+
}
|
|
54
|
+
// Glass stays clear; `color` only tints solid slabs.
|
|
55
|
+
if (!this.data.glass)
|
|
56
|
+
this.rounded.material.color.set(this.data.color);
|
|
57
|
+
this.updateOpacity();
|
|
58
|
+
},
|
|
59
|
+
updateOpacity() {
|
|
60
|
+
const opacity = Math.min(1, Math.max(0, this.data.opacity));
|
|
61
|
+
this.rounded.material.transparent = opacity < 1;
|
|
62
|
+
this.rounded.material.opacity = opacity;
|
|
63
|
+
},
|
|
64
|
+
remove() {
|
|
65
|
+
if (!this.rounded)
|
|
66
|
+
return;
|
|
67
|
+
this.el.removeObject3D('mesh');
|
|
68
|
+
this.rounded.geometry.dispose();
|
|
69
|
+
this.rounded.material.dispose();
|
|
70
|
+
this.rounded = null;
|
|
71
|
+
},
|
|
72
|
+
draw() {
|
|
73
|
+
const d = this.data;
|
|
74
|
+
const corner = (value) => (value !== -1 ? value : d.radius) || 0.00001;
|
|
75
|
+
const tl = corner(d.topLeftRadius);
|
|
76
|
+
const tr = corner(d.topRightRadius);
|
|
77
|
+
const bl = corner(d.bottomLeftRadius);
|
|
78
|
+
const br = corner(d.bottomRightRadius);
|
|
79
|
+
const w = d.width;
|
|
80
|
+
const h = d.height;
|
|
81
|
+
const shape = new THREE.Shape();
|
|
82
|
+
shape.moveTo(0, tl);
|
|
83
|
+
shape.lineTo(0, h - tl);
|
|
84
|
+
shape.quadraticCurveTo(0, h, tl, h);
|
|
85
|
+
shape.lineTo(w - tr, h);
|
|
86
|
+
shape.quadraticCurveTo(w, h, w, h - tr);
|
|
87
|
+
shape.lineTo(w, br);
|
|
88
|
+
shape.quadraticCurveTo(w, 0, w - br, 0);
|
|
89
|
+
shape.lineTo(bl, 0);
|
|
90
|
+
shape.quadraticCurveTo(0, 0, 0, bl);
|
|
91
|
+
return d.flat
|
|
92
|
+
? new THREE.ShapeGeometry(shape)
|
|
93
|
+
: new THREE.ExtrudeGeometry(shape, { bevelEnabled: false, depth: d.depth });
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// Registers `rounded` and <a-rounded> with the page's A-Frame, once.
|
|
98
|
+
export function registerRounded(AFRAME = globalThis.AFRAME) {
|
|
99
|
+
if (!AFRAME)
|
|
100
|
+
throw new Error('gadxr ui: A-Frame must be loaded before 3D components are used');
|
|
101
|
+
if (!AFRAME.components.rounded)
|
|
102
|
+
AFRAME.registerComponent('rounded', roundedComponent(AFRAME.THREE));
|
|
103
|
+
if (!AFRAME.primitives.primitives['a-rounded']) {
|
|
104
|
+
AFRAME.registerPrimitive('a-rounded', {
|
|
105
|
+
defaultComponents: { rounded: {} },
|
|
106
|
+
mappings: {
|
|
107
|
+
enabled: 'rounded.enabled',
|
|
108
|
+
width: 'rounded.width',
|
|
109
|
+
height: 'rounded.height',
|
|
110
|
+
depth: 'rounded.depth',
|
|
111
|
+
radius: 'rounded.radius',
|
|
112
|
+
'top-left-radius': 'rounded.topLeftRadius',
|
|
113
|
+
'top-right-radius': 'rounded.topRightRadius',
|
|
114
|
+
'bottom-left-radius': 'rounded.bottomLeftRadius',
|
|
115
|
+
'bottom-right-radius': 'rounded.bottomRightRadius',
|
|
116
|
+
color: 'rounded.color',
|
|
117
|
+
opacity: 'rounded.opacity',
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const RAYCASTABLE = "raycastable";
|
|
2
|
+
export declare const MOUSE_CURSOR = "rayOrigin: mouse; fuse: false";
|
|
3
|
+
export declare const TROIKA_SCRIPT = "https://unpkg.com/aframe-troika-text@0.14.0/dist/aframe-troika-text.min.js";
|
|
4
|
+
export type SceneOptions = {
|
|
5
|
+
cursor?: string;
|
|
6
|
+
mouseCursorInVR?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function setupScene(scene: any, { cursor, mouseCursorInVR }?: SceneOptions): () => void;
|
|
9
|
+
export declare function loadTroika(): Promise<void> | null;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// What <Scene3D> does to its <a-scene>, kept free of Svelte so it's tested in Node: the
|
|
2
|
+
// mouse cursor and lasers aim at `.raycastable`, the mouse cursor is removed in VR, and
|
|
3
|
+
// troika-text (3D labels) is loaded if the page didn't load it.
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
// Cursors only hit entities with this class (on an entity that owns a mesh).
|
|
6
|
+
export const RAYCASTABLE = 'raycastable';
|
|
7
|
+
export const MOUSE_CURSOR = 'rayOrigin: mouse; fuse: false';
|
|
8
|
+
export const TROIKA_SCRIPT = 'https://unpkg.com/aframe-troika-text@0.14.0/dist/aframe-troika-text.min.js';
|
|
9
|
+
// Returns a function that undoes it.
|
|
10
|
+
export function setupScene(scene, { cursor = MOUSE_CURSOR, mouseCursorInVR = false } = {}) {
|
|
11
|
+
const cleanups = [];
|
|
12
|
+
// Lasers: aim at `.raycastable` like the mouse, keeping the rest of their raycaster (far).
|
|
13
|
+
// Set once the entity has loaded, so a raycaster written in its markup is set up first.
|
|
14
|
+
const lasers = new WeakSet();
|
|
15
|
+
const aim = (el) => el.setAttribute('raycaster', 'objects', `.${RAYCASTABLE}`);
|
|
16
|
+
const watchLaser = (el) => {
|
|
17
|
+
if (lasers.has(el))
|
|
18
|
+
return;
|
|
19
|
+
lasers.add(el);
|
|
20
|
+
if (el.hasLoaded)
|
|
21
|
+
return aim(el);
|
|
22
|
+
const onLoaded = (event) => {
|
|
23
|
+
if (event.target !== el)
|
|
24
|
+
return;
|
|
25
|
+
el.removeEventListener('loaded', onLoaded);
|
|
26
|
+
aim(el);
|
|
27
|
+
};
|
|
28
|
+
el.addEventListener('loaded', onLoaded);
|
|
29
|
+
cleanups.push(() => el.removeEventListener('loaded', onLoaded));
|
|
30
|
+
};
|
|
31
|
+
const findLasers = (node) => {
|
|
32
|
+
if (node.nodeType !== 1)
|
|
33
|
+
return;
|
|
34
|
+
if (node.hasAttribute('laser-controls'))
|
|
35
|
+
watchLaser(node);
|
|
36
|
+
node.querySelectorAll('[laser-controls]').forEach(watchLaser);
|
|
37
|
+
};
|
|
38
|
+
findLasers(scene);
|
|
39
|
+
// Hands mounted later (e.g. inside an {#if}) or given laser-controls later.
|
|
40
|
+
const observer = new MutationObserver((records) => {
|
|
41
|
+
for (const record of records) {
|
|
42
|
+
if (record.type === 'attributes')
|
|
43
|
+
findLasers(record.target);
|
|
44
|
+
else
|
|
45
|
+
record.addedNodes.forEach(findLasers);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
observer.observe(scene, { childList: true, subtree: true, attributes: true, attributeFilter: ['laser-controls'] });
|
|
49
|
+
cleanups.push(() => observer.disconnect());
|
|
50
|
+
// The mouse cursor is unused in a headset, but still hovers UI: it keeps casting along
|
|
51
|
+
// its last mouse ray, and it hears the lasers' raycaster events (they bubble to the
|
|
52
|
+
// scene), so its mouseleaves un-hover buttons a laser is still on. Remove it in VR
|
|
53
|
+
// (raycaster off first, which sends the leaves for anything it hovers); restore it after.
|
|
54
|
+
// enter-vr also fires for non-immersive fullscreen; only a real XR session counts.
|
|
55
|
+
if (!mouseCursorInVR) {
|
|
56
|
+
let removed = false;
|
|
57
|
+
const onVR = (event) => {
|
|
58
|
+
const vr = event.type === 'enter-vr' && !!scene.xrSession;
|
|
59
|
+
if (vr === removed)
|
|
60
|
+
return;
|
|
61
|
+
removed = vr;
|
|
62
|
+
scene.setAttribute('raycaster', 'enabled', !vr);
|
|
63
|
+
if (vr)
|
|
64
|
+
scene.removeAttribute('cursor');
|
|
65
|
+
else
|
|
66
|
+
scene.setAttribute('cursor', cursor);
|
|
67
|
+
};
|
|
68
|
+
scene.addEventListener('enter-vr', onVR);
|
|
69
|
+
scene.addEventListener('exit-vr', onVR);
|
|
70
|
+
cleanups.push(() => {
|
|
71
|
+
scene.removeEventListener('enter-vr', onVR);
|
|
72
|
+
scene.removeEventListener('exit-vr', onVR);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return () => cleanups.splice(0).forEach((cleanup) => cleanup());
|
|
76
|
+
}
|
|
77
|
+
let troika;
|
|
78
|
+
// Resolves once A-Frame has `troika-text`, adding the pinned script if it isn't registered
|
|
79
|
+
// (or being loaded) yet; null when it's already there, so a page that loads it needn't wait.
|
|
80
|
+
// A script that fails to load is logged and still resolves: the scene shows, without labels.
|
|
81
|
+
export function loadTroika() {
|
|
82
|
+
if (globalThis.AFRAME.components['troika-text'])
|
|
83
|
+
return null;
|
|
84
|
+
troika ??= new Promise((resolve) => {
|
|
85
|
+
const existing = document.querySelector(`script[src="${TROIKA_SCRIPT}"]`);
|
|
86
|
+
const script = existing ?? document.createElement('script');
|
|
87
|
+
const done = () => {
|
|
88
|
+
if (!globalThis.AFRAME.components['troika-text']) {
|
|
89
|
+
console.error(`gadxr ui: couldn't load troika-text from ${TROIKA_SCRIPT}; 3D labels won't show.`);
|
|
90
|
+
}
|
|
91
|
+
resolve();
|
|
92
|
+
};
|
|
93
|
+
script.addEventListener('load', done, { once: true });
|
|
94
|
+
script.addEventListener('error', done, { once: true });
|
|
95
|
+
if (!existing) {
|
|
96
|
+
script.src = TROIKA_SCRIPT;
|
|
97
|
+
document.head.appendChild(script);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return troika;
|
|
101
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2024 The Geist Project Authors (https://github.com/vercel/geist-font)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
https://openfontlicense.org
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ButtonKind, ButtonShape, ButtonSize, Font, Material3D, Theme } from './theme';
|
|
2
|
+
export type ButtonStyleInput = {
|
|
3
|
+
kind?: ButtonKind;
|
|
4
|
+
size?: ButtonSize;
|
|
5
|
+
shape?: ButtonShape;
|
|
6
|
+
selected?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type ButtonStyle = {
|
|
10
|
+
height: number;
|
|
11
|
+
paddingX: number;
|
|
12
|
+
radius: number;
|
|
13
|
+
square: boolean;
|
|
14
|
+
font: Font;
|
|
15
|
+
fill: string;
|
|
16
|
+
hoverFill: string;
|
|
17
|
+
activeFill: string;
|
|
18
|
+
text: string;
|
|
19
|
+
material: Material3D;
|
|
20
|
+
text3d: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function resolveButtonStyle(theme: Theme, input?: ButtonStyleInput): ButtonStyle;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function resolveButtonStyle(theme, input = {}) {
|
|
2
|
+
const { kind = 'primary', size = 'default', shape = 'default', selected = false, disabled = false } = input;
|
|
3
|
+
const sizeTokens = theme.button.sizes[size];
|
|
4
|
+
const height = sizeTokens.height;
|
|
5
|
+
const square = shape === 'round' || shape === 'circle' || shape === 'square';
|
|
6
|
+
const fullyRounded = shape === 'pill' || shape === 'round' || shape === 'circle';
|
|
7
|
+
const radius = fullyRounded ? height / 2 : Math.min(theme.borders.buttonBorderRadius, height / 2);
|
|
8
|
+
const base = {
|
|
9
|
+
height,
|
|
10
|
+
paddingX: square ? 0 : sizeTokens.paddingX,
|
|
11
|
+
radius,
|
|
12
|
+
square,
|
|
13
|
+
font: theme.typography[sizeTokens.typography],
|
|
14
|
+
};
|
|
15
|
+
if (disabled) {
|
|
16
|
+
const c = theme.colors;
|
|
17
|
+
return { ...base, fill: c.buttonDisabledFill, hoverFill: c.buttonDisabledFill, activeFill: c.buttonDisabledFill, text: c.buttonDisabledText, material: 'solid', text3d: c.buttonDisabledText };
|
|
18
|
+
}
|
|
19
|
+
const colors = theme.colors.button[kind];
|
|
20
|
+
if (selected) {
|
|
21
|
+
return { ...base, fill: colors.selectedFill, hoverFill: colors.selectedFill, activeFill: colors.active, text: colors.selectedText, material: 'solid', text3d: colors.selectedText };
|
|
22
|
+
}
|
|
23
|
+
const material = theme.space3d.material[kind];
|
|
24
|
+
return {
|
|
25
|
+
...base,
|
|
26
|
+
fill: colors.fill,
|
|
27
|
+
hoverFill: colors.hover,
|
|
28
|
+
activeFill: colors.active,
|
|
29
|
+
text: colors.text,
|
|
30
|
+
material,
|
|
31
|
+
// Glass ignores the fill color, so it gets its own label color.
|
|
32
|
+
text3d: material === 'glass' ? theme.space3d.glassText : colors.text,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Font, TagKind, TagSize, TagVariant, Theme, TooltipPlacement } from './theme';
|
|
2
|
+
export type CheckboxType = 'checkbox' | 'toggle';
|
|
3
|
+
export type CheckboxStyle = {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
radius: number;
|
|
7
|
+
fill: string;
|
|
8
|
+
fill3d: string;
|
|
9
|
+
border: string;
|
|
10
|
+
mark: string;
|
|
11
|
+
knob: number;
|
|
12
|
+
knobColor: string;
|
|
13
|
+
labelColor: string;
|
|
14
|
+
font: Font;
|
|
15
|
+
};
|
|
16
|
+
export declare function resolveCheckboxStyle(theme: Theme, { type, checked, disabled }?: {
|
|
17
|
+
type?: CheckboxType;
|
|
18
|
+
checked?: boolean;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
}): CheckboxStyle;
|
|
21
|
+
export declare function sliderFraction(value: number, min: number, max: number): number;
|
|
22
|
+
export declare function sliderValueAt(fraction: number, min: number, max: number, step?: number): number;
|
|
23
|
+
export type TagStyle = {
|
|
24
|
+
height: number;
|
|
25
|
+
paddingX: number;
|
|
26
|
+
radius: number;
|
|
27
|
+
fill: string;
|
|
28
|
+
text: string;
|
|
29
|
+
font: Font;
|
|
30
|
+
};
|
|
31
|
+
export declare function resolveTagStyle(theme: Theme, { kind, variant, size }?: {
|
|
32
|
+
kind?: TagKind;
|
|
33
|
+
variant?: TagVariant;
|
|
34
|
+
size?: TagSize;
|
|
35
|
+
}): TagStyle;
|
|
36
|
+
export declare function nextIndex(usable: boolean[], from: number, direction: 1 | -1, wrap?: boolean): number;
|
|
37
|
+
export type InputStyle = {
|
|
38
|
+
height: number;
|
|
39
|
+
paddingX: number;
|
|
40
|
+
radius: number;
|
|
41
|
+
border: number;
|
|
42
|
+
fill: string;
|
|
43
|
+
borderColor: string;
|
|
44
|
+
text: string;
|
|
45
|
+
placeholder: string;
|
|
46
|
+
caret: string;
|
|
47
|
+
labelColor: string;
|
|
48
|
+
captionColor: string;
|
|
49
|
+
font: Font;
|
|
50
|
+
labelFont: Font;
|
|
51
|
+
captionFont: Font;
|
|
52
|
+
};
|
|
53
|
+
export declare function resolveInputStyle(theme: Theme, { focused, hovered, error, disabled }?: {
|
|
54
|
+
focused?: boolean;
|
|
55
|
+
hovered?: boolean;
|
|
56
|
+
error?: boolean;
|
|
57
|
+
disabled?: boolean;
|
|
58
|
+
}): InputStyle;
|
|
59
|
+
export declare function resolveKeyStyle(theme: Theme, { kind, hovered, pressed, on }?: {
|
|
60
|
+
kind?: 'char' | 'special' | 'accent';
|
|
61
|
+
hovered?: boolean;
|
|
62
|
+
pressed?: boolean;
|
|
63
|
+
on?: boolean;
|
|
64
|
+
}): {
|
|
65
|
+
fill: string;
|
|
66
|
+
text: string;
|
|
67
|
+
};
|
|
68
|
+
export declare function initials(name: string): string;
|
|
69
|
+
export declare function avatarColor(name: string, palette: string[]): string;
|
|
70
|
+
export declare function tooltipOffset(placement: TooltipPlacement, trigger: {
|
|
71
|
+
width: number;
|
|
72
|
+
height: number;
|
|
73
|
+
}, bubble: {
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
}, gap: number): {
|
|
77
|
+
x: number;
|
|
78
|
+
y: number;
|
|
79
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export function resolveCheckboxStyle(theme, { type = 'checkbox', checked = false, disabled = false } = {}) {
|
|
2
|
+
const t = theme.checkbox;
|
|
3
|
+
const c = theme.colors.checkbox;
|
|
4
|
+
const toggle = type === 'toggle';
|
|
5
|
+
const on = toggle ? c.toggleTrackChecked : c.fillChecked;
|
|
6
|
+
const off = toggle ? c.toggleTrack : 'transparent';
|
|
7
|
+
const fill = disabled ? theme.colors.buttonDisabledFill : checked ? on : off;
|
|
8
|
+
return {
|
|
9
|
+
width: toggle ? t.trackWidth : t.box,
|
|
10
|
+
height: toggle ? t.trackHeight : t.box,
|
|
11
|
+
radius: toggle ? t.trackHeight / 2 : t.boxRadius,
|
|
12
|
+
fill,
|
|
13
|
+
fill3d: fill === 'transparent' ? c.fill3d : fill,
|
|
14
|
+
border: disabled ? theme.colors.buttonDisabledFill : checked || toggle ? fill : c.border,
|
|
15
|
+
mark: disabled ? theme.colors.buttonDisabledText : c.mark,
|
|
16
|
+
knob: t.knob,
|
|
17
|
+
knobColor: disabled ? theme.colors.buttonDisabledText : c.toggleKnob,
|
|
18
|
+
labelColor: disabled ? theme.colors.buttonDisabledText : theme.colors.contentPrimary,
|
|
19
|
+
font: theme.typography[t.typography],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
// Slider value <-> position along the track (0 = min end, 1 = max end).
|
|
23
|
+
export function sliderFraction(value, min, max) {
|
|
24
|
+
if (max <= min)
|
|
25
|
+
return 0;
|
|
26
|
+
return Math.min(1, Math.max(0, (value - min) / (max - min)));
|
|
27
|
+
}
|
|
28
|
+
export function sliderValueAt(fraction, min, max, step = 1) {
|
|
29
|
+
const clamped = Math.min(1, Math.max(0, fraction));
|
|
30
|
+
const raw = min + clamped * (max - min);
|
|
31
|
+
if (!(step > 0))
|
|
32
|
+
return raw;
|
|
33
|
+
const snapped = min + Math.round((raw - min) / step) * step;
|
|
34
|
+
// Round off float noise (0.1 + 0.2) to the step's precision, and stay in range.
|
|
35
|
+
const decimals = (String(step).split('.')[1] ?? '').length;
|
|
36
|
+
return Math.min(max, Math.max(min, Number(snapped.toFixed(decimals))));
|
|
37
|
+
}
|
|
38
|
+
export function resolveTagStyle(theme, { kind = 'neutral', variant = 'light', size = 'small' } = {}) {
|
|
39
|
+
const sizeTokens = theme.tag.sizes[size];
|
|
40
|
+
const c = theme.colors.tag[kind];
|
|
41
|
+
return {
|
|
42
|
+
height: sizeTokens.height,
|
|
43
|
+
paddingX: sizeTokens.paddingX,
|
|
44
|
+
radius: Math.min(theme.tag.radius, sizeTokens.height / 2),
|
|
45
|
+
fill: variant === 'solid' ? c.solidFill : c.lightFill,
|
|
46
|
+
text: variant === 'solid' ? c.solidText : c.lightText,
|
|
47
|
+
font: theme.typography[sizeTokens.typography],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Keyboard navigation over a list where some entries can't take focus (disabled
|
|
51
|
+
// items, dividers). Returns the next usable index in `direction`, or `from` if none.
|
|
52
|
+
export function nextIndex(usable, from, direction, wrap = true) {
|
|
53
|
+
const n = usable.length;
|
|
54
|
+
for (let step = 1; step <= n; step++) {
|
|
55
|
+
let i = from + direction * step;
|
|
56
|
+
if (wrap)
|
|
57
|
+
i = ((i % n) + n) % n;
|
|
58
|
+
else if (i < 0 || i >= n)
|
|
59
|
+
return from;
|
|
60
|
+
if (usable[i])
|
|
61
|
+
return i;
|
|
62
|
+
}
|
|
63
|
+
return from;
|
|
64
|
+
}
|
|
65
|
+
// Input field colors: the border shows hover, focus (accent) and error (wins over focus).
|
|
66
|
+
export function resolveInputStyle(theme, { focused = false, hovered = false, error = false, disabled = false } = {}) {
|
|
67
|
+
const t = theme.input;
|
|
68
|
+
const c = theme.colors.input;
|
|
69
|
+
const fill = disabled ? theme.colors.buttonDisabledFill : c.fill;
|
|
70
|
+
return {
|
|
71
|
+
height: t.height,
|
|
72
|
+
paddingX: t.paddingX,
|
|
73
|
+
radius: t.radius,
|
|
74
|
+
border: t.border,
|
|
75
|
+
fill,
|
|
76
|
+
borderColor: disabled ? fill : error ? c.error : focused ? c.focus : hovered ? c.hover : c.border,
|
|
77
|
+
text: disabled ? theme.colors.buttonDisabledText : c.text,
|
|
78
|
+
placeholder: disabled ? theme.colors.buttonDisabledText : c.placeholder,
|
|
79
|
+
caret: c.caret,
|
|
80
|
+
labelColor: disabled ? theme.colors.buttonDisabledText : c.label,
|
|
81
|
+
captionColor: error ? c.errorText : c.caption,
|
|
82
|
+
font: theme.typography[t.typography],
|
|
83
|
+
labelFont: theme.typography[t.labelTypography],
|
|
84
|
+
captionFont: theme.typography[t.captionTypography],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// VR keyboard keys: letters, special keys (shift, backspace, pages…) and the accent
|
|
88
|
+
// enter key. Pressed flips to white so a laser press is unmistakable; `on` is a latched
|
|
89
|
+
// shift / caps.
|
|
90
|
+
export function resolveKeyStyle(theme, { kind = 'char', hovered = false, pressed = false, on = false } = {}) {
|
|
91
|
+
const c = theme.colors.keyboard;
|
|
92
|
+
if (pressed)
|
|
93
|
+
return { fill: c.pressed, text: c.pressedText };
|
|
94
|
+
if (on)
|
|
95
|
+
return { fill: c.on, text: c.onText };
|
|
96
|
+
const [fill, hover] = kind === 'accent' ? [c.accent, c.accentHover] : kind === 'special' ? [c.special, c.specialHover] : [c.key, c.keyHover];
|
|
97
|
+
return { fill: hovered ? hover : fill, text: c.text };
|
|
98
|
+
}
|
|
99
|
+
// Avatar initials: first letters of the first and last words ("Ada Lovelace" → "AL",
|
|
100
|
+
// "rhys" → "R"). Whole characters, so an emoji name keeps its emoji.
|
|
101
|
+
export function initials(name) {
|
|
102
|
+
const words = name.trim().split(/\s+/).filter(Boolean);
|
|
103
|
+
if (!words.length)
|
|
104
|
+
return '';
|
|
105
|
+
const first = [...words[0]][0];
|
|
106
|
+
const last = words.length > 1 ? [...words[words.length - 1]][0] : '';
|
|
107
|
+
return (first + last).toUpperCase();
|
|
108
|
+
}
|
|
109
|
+
// A stable color per name, so the same player looks the same everywhere.
|
|
110
|
+
export function avatarColor(name, palette) {
|
|
111
|
+
let hash = 0;
|
|
112
|
+
for (const ch of name.trim().toLowerCase())
|
|
113
|
+
hash = (hash * 31 + ch.codePointAt(0)) >>> 0;
|
|
114
|
+
return palette[hash % palette.length];
|
|
115
|
+
}
|
|
116
|
+
// Where a tooltip bubble's center goes relative to its trigger's center (3D, y up):
|
|
117
|
+
// `gap` clear of the trigger's edge on the `placement` side.
|
|
118
|
+
export function tooltipOffset(placement, trigger, bubble, gap) {
|
|
119
|
+
switch (placement) {
|
|
120
|
+
case 'bottom':
|
|
121
|
+
return { x: 0, y: -(trigger.height / 2 + gap + bubble.height / 2) };
|
|
122
|
+
case 'left':
|
|
123
|
+
return { x: -(trigger.width / 2 + gap + bubble.width / 2), y: 0 };
|
|
124
|
+
case 'right':
|
|
125
|
+
return { x: trigger.width / 2 + gap + bubble.width / 2, y: 0 };
|
|
126
|
+
default:
|
|
127
|
+
return { x: 0, y: trigger.height / 2 + gap + bubble.height / 2 };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ButtonKind, ButtonShape, ButtonSize, Dimension, Theme } from './theme';
|
|
2
|
+
export declare function setTheme(get: () => Theme): void;
|
|
3
|
+
export declare function getTheme(): () => Theme;
|
|
4
|
+
export declare function setDimension(dimension: Dimension): void;
|
|
5
|
+
export declare function getDimension(): Dimension;
|
|
6
|
+
export type ButtonGroupContext = {
|
|
7
|
+
readonly kind?: ButtonKind;
|
|
8
|
+
readonly size?: ButtonSize;
|
|
9
|
+
readonly shape?: ButtonShape;
|
|
10
|
+
readonly disabled: boolean;
|
|
11
|
+
register(): number;
|
|
12
|
+
isSelected(index: number): boolean | undefined;
|
|
13
|
+
select(index: number): void;
|
|
14
|
+
};
|
|
15
|
+
export declare function setButtonGroup(group: ButtonGroupContext): void;
|
|
16
|
+
export declare function getButtonGroup(): ButtonGroupContext | undefined;
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Svelte context for the design system: the active theme, whether a subtree
|
|
2
|
+
// renders as HTML or A-Frame, and the ButtonGroup a Button belongs to.
|
|
3
|
+
import { getContext, setContext } from 'svelte';
|
|
4
|
+
import { defaultTheme } from './theme';
|
|
5
|
+
const THEME = Symbol('ui-theme');
|
|
6
|
+
const DIMENSION = Symbol('ui-dimension');
|
|
7
|
+
const GROUP = Symbol('ui-button-group');
|
|
8
|
+
// Contexts hold getters so a ThemeProvider whose `theme` prop changes updates its children.
|
|
9
|
+
export function setTheme(get) {
|
|
10
|
+
setContext(THEME, get);
|
|
11
|
+
}
|
|
12
|
+
export function getTheme() {
|
|
13
|
+
return getContext(THEME) ?? (() => defaultTheme);
|
|
14
|
+
}
|
|
15
|
+
export function setDimension(dimension) {
|
|
16
|
+
setContext(DIMENSION, dimension);
|
|
17
|
+
}
|
|
18
|
+
export function getDimension() {
|
|
19
|
+
return getContext(DIMENSION) ?? '2d';
|
|
20
|
+
}
|
|
21
|
+
export function setButtonGroup(group) {
|
|
22
|
+
setContext(GROUP, group);
|
|
23
|
+
}
|
|
24
|
+
export function getButtonGroup() {
|
|
25
|
+
return getContext(GROUP);
|
|
26
|
+
}
|
package/dist/fonts.css
ADDED
package/dist/fonts.d.ts
ADDED
package/dist/fonts.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The library's own copy of Geist (OFL, see assets/Geist-OFL.txt), so 3D text
|
|
2
|
+
// doesn't depend on files the app serves.
|
|
3
|
+
import geistUrl from './assets/Geist-Regular.ttf?url';
|
|
4
|
+
// troika loads fonts by URL; an empty `typography.font3d` means the bundled Geist.
|
|
5
|
+
export function font3d(theme) {
|
|
6
|
+
return theme.typography.font3d || geistUrl;
|
|
7
|
+
}
|