rift-ds 1.25.0 → 1.26.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 (34) hide show
  1. package/README.md +1 -0
  2. package/chat/ChatThreads.d.ts +3 -1
  3. package/chat/ChatThreads.js +3 -1
  4. package/chat/ChatWidget.css +166 -15
  5. package/chat/ChatWidget.d.ts +1 -1
  6. package/chat/ChatWidget.js +5 -2
  7. package/components/ActionCard/ActionCard.d.ts +1 -1
  8. package/components/ContextMenu/ContextMenu.css +11 -0
  9. package/components/ContextMenu/ContextMenu.d.ts +1 -1
  10. package/components/ContextMenu/ContextMenu.js +3 -1
  11. package/components/DropdownMenu/DropdownMenu.css +38 -0
  12. package/components/DropdownMenu/DropdownMenu.d.ts +4 -0
  13. package/components/DropdownMenu/DropdownMenu.js +11 -5
  14. package/components/DropdownMenu/ShortcutHint.d.ts +9 -0
  15. package/components/DropdownMenu/ShortcutHint.js +6 -0
  16. package/components/InterruptCard/InterruptCard.d.ts +1 -1
  17. package/components/MessageCard/MessageCard.css +17 -6
  18. package/components/MessageCard/MessageCard.d.ts +1 -1
  19. package/components/ShaderScene/ShaderScene.d.ts +5 -5
  20. package/components/ShaderScene/ShaderScene.js +33 -10
  21. package/components/ShaderScene/assemble.js +2 -0
  22. package/components/ShaderScene/renderer.d.ts +5 -1
  23. package/components/ShaderScene/renderer.js +46 -1
  24. package/components/ShaderScene/scenes.d.ts +56 -0
  25. package/components/ShaderScene/scenes.js +570 -2
  26. package/components/ShaderScene/types.d.ts +13 -0
  27. package/components/ThreadPanel/ThreadPanel.css +29 -0
  28. package/components/ThreadPanel/ThreadPanel.d.ts +2 -0
  29. package/components/ThreadPanel/ThreadPanel.js +13 -2
  30. package/components/registry.json +1 -1
  31. package/components/registry.json.d.ts +1 -1
  32. package/components/registry.json.js +1 -1
  33. package/index.js +2 -1
  34. package/package.json +1 -1
@@ -3,11 +3,13 @@ import { jsx } from "react/jsx-runtime";
3
3
  import React from "react";
4
4
  import { MOTION_RENDERER_WATCHDOG_MS } from "../../tokens/motion.js";
5
5
  import { PASSES } from "./passes.js";
6
- import { createRenderer, coloursFor } from "./renderer.js";
6
+ import { createRenderer, glyphFontFor, coloursFor } from "./renderer.js";
7
7
  import { bakeThumbnails } from "./renderer.js";
8
8
  import { SCENES } from "./scenes.js";
9
9
  import { defaultsFor } from "./types.js";
10
10
  import "./ShaderScene.css";
11
+ const MAX_PIXEL_RATIO = 1;
12
+ const FRAME_MS = 1e3 / 30;
11
13
  const DEFAULT_SPEED = 1.6;
12
14
  function ShaderScene({
13
15
  scene = "horizon",
@@ -77,11 +79,18 @@ function ShaderScene({
77
79
  const failed = requestAnimationFrame(() => setGl("failed"));
78
80
  return () => cancelAnimationFrame(failed);
79
81
  }
80
- const applyColours = () => renderer.setColours(coloursFor(host, definition));
81
- const resize = () => {
82
- const ratio = Math.min(2, window.devicePixelRatio || 1);
83
- canvas.width = Math.max(1, Math.round(host.clientWidth * ratio));
84
- canvas.height = Math.max(1, Math.round(host.clientHeight * ratio));
82
+ const applyColours = () => {
83
+ renderer.setColours(coloursFor(host, definition));
84
+ renderer.setGlyphs(glyphFontFor(host));
85
+ };
86
+ let ratio = 1;
87
+ const fit = () => {
88
+ ratio = Math.min(definition.pixelRatio ?? MAX_PIXEL_RATIO, window.devicePixelRatio || 1);
89
+ const width = Math.max(1, Math.round(host.clientWidth * ratio));
90
+ const height = Math.max(1, Math.round(host.clientHeight * ratio));
91
+ if (canvas.width === width && canvas.height === height) return;
92
+ canvas.width = width;
93
+ canvas.height = height;
85
94
  };
86
95
  const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
87
96
  let time = 20;
@@ -89,16 +98,18 @@ function ShaderScene({
89
98
  let frame = 0;
90
99
  let painted = false;
91
100
  const draw = (now) => {
101
+ frame = requestAnimationFrame(draw);
102
+ if (painted && now - last < FRAME_MS - 1) return;
92
103
  const values = liveRef?.current ?? mergedRef.current;
93
104
  const dt = Math.min(0.1, (now - last) / 1e3);
94
105
  last = now;
95
106
  if (!still) time += dt * values.speed;
96
- renderer.draw(values, time, canvas.width, canvas.height);
107
+ fit();
108
+ renderer.draw(values, time, canvas.width, canvas.height, ratio);
97
109
  if (!painted) {
98
110
  painted = true;
99
111
  setGl("painted");
100
112
  }
101
- frame = requestAnimationFrame(draw);
102
113
  };
103
114
  const start = () => {
104
115
  if (frame) return;
@@ -110,14 +121,25 @@ function ShaderScene({
110
121
  frame = 0;
111
122
  };
112
123
  applyColours();
113
- resize();
114
124
  start();
125
+ let mounted = true;
126
+ if (definition.glyphs) {
127
+ document.fonts?.ready.then(() => {
128
+ if (!mounted) return;
129
+ renderer.setGlyphs("");
130
+ renderer.setGlyphs(glyphFontFor(host));
131
+ });
132
+ }
115
133
  const visibilityObserver = typeof IntersectionObserver === "undefined" ? null : new IntersectionObserver(
116
134
  (entries) => entries[entries.length - 1].isIntersecting ? start() : stop(),
117
135
  { rootMargin: "200px 0px" }
118
136
  );
119
137
  visibilityObserver?.observe(host);
120
- const sizeObserver = new ResizeObserver(resize);
138
+ const sizeObserver = new ResizeObserver(() => {
139
+ if (frame) return;
140
+ fit();
141
+ renderer.draw(liveRef?.current ?? mergedRef.current, time, canvas.width, canvas.height, ratio);
142
+ });
121
143
  sizeObserver.observe(host);
122
144
  const themeObserver = new MutationObserver(applyColours);
123
145
  themeObserver.observe(document.documentElement, {
@@ -125,6 +147,7 @@ function ShaderScene({
125
147
  attributeFilter: ["data-theme", "data-brand", "style"]
126
148
  });
127
149
  return () => {
150
+ mounted = false;
128
151
  stop();
129
152
  visibilityObserver?.disconnect();
130
153
  sizeObserver.disconnect();
@@ -31,7 +31,9 @@ uniform float u_time;
31
31
  uniform vec3 u_ground; // the scene's ground: the page's, or a night scene's own
32
32
  uniform vec3 u_page; // the page's ground, which the passes fade to
33
33
  uniform float u_lightMode; // 1: a night scene laid onto a light page
34
+ uniform float u_ratio; // drawing-buffer pixels per CSS pixel
34
35
  uniform vec3 u_col[${MAX_COLOURS}];
36
+ ${scene.glyphs ? "uniform sampler2D u_glyphs;\nuniform float u_glyphCount;" : ""}
35
37
  ${floats}
36
38
 
37
39
  out vec4 outColor;
@@ -19,9 +19,13 @@ export declare function readColours(host: HTMLElement, tokens: string[]): Colour
19
19
  * light.
20
20
  */
21
21
  export declare function coloursFor(host: HTMLElement, scene: Scene): Colours;
22
+ /** The face a scene's type is drawn in: the theme's code face at `host`. */
23
+ export declare function glyphFontFor(host: HTMLElement): string;
22
24
  export declare function createRenderer(gl: WebGL2RenderingContext, scene: Scene, passes: Pass[]): {
23
25
  setColours({ ground, page, lightMode, colours }: Colours): void;
24
- draw(values: Values, time: number, width: number, height: number): void;
26
+ /** Draws a type scene's ramp in `font`; a scene without one ignores it. */
27
+ setGlyphs(font: string): void;
28
+ draw(values: Values, time: number, width: number, height: number, ratio?: number): void;
25
29
  dispose(): void;
26
30
  } | null;
27
31
  /**
@@ -33,6 +33,28 @@ function coloursFor(host, scene) {
33
33
  }
34
34
  return colours;
35
35
  }
36
+ function glyphFontFor(host) {
37
+ return getComputedStyle(host).getPropertyValue("--font-family-code").trim() || "monospace";
38
+ }
39
+ const GLYPH_W = 48;
40
+ const GLYPH_H = 80;
41
+ function drawGlyphs(ramp, font) {
42
+ const glyphs = [...ramp];
43
+ const strip = document.createElement("canvas");
44
+ strip.width = GLYPH_W * glyphs.length;
45
+ strip.height = GLYPH_H;
46
+ const ctx = strip.getContext("2d");
47
+ if (ctx) {
48
+ ctx.fillStyle = "#000";
49
+ ctx.fillRect(0, 0, strip.width, strip.height);
50
+ ctx.fillStyle = "#fff";
51
+ ctx.font = `700 ${GLYPH_H * 0.78}px ${font}`;
52
+ ctx.textAlign = "center";
53
+ ctx.textBaseline = "middle";
54
+ glyphs.forEach((glyph, i) => ctx.fillText(glyph, (i + 0.5) * GLYPH_W, GLYPH_H * 0.52));
55
+ }
56
+ return { strip, count: glyphs.length };
57
+ }
36
58
  function compile(gl, type, source) {
37
59
  const shader = gl.createShader(type);
38
60
  if (!shader) return null;
@@ -74,7 +96,11 @@ function createRenderer(gl, scene, passes) {
74
96
  const uPage = at("u_page");
75
97
  const uLightMode = at("u_lightMode");
76
98
  const uCols = at("u_col");
99
+ const uRatio = at("u_ratio");
100
+ const uGlyphCount = at("u_glyphCount");
77
101
  const floats = uniformNames(scene, passes).map((name) => [name, at(name)]);
102
+ const glyphTexture = scene.glyphs ? gl.createTexture() : null;
103
+ let glyphFont = "";
78
104
  return {
79
105
  setColours({ ground, page, lightMode, colours }) {
80
106
  gl.uniform3fv(uGround, ground);
@@ -84,14 +110,31 @@ function createRenderer(gl, scene, passes) {
84
110
  colours.forEach((rgb, i) => flat.set(rgb, i * 3));
85
111
  gl.uniform3fv(uCols, flat);
86
112
  },
87
- draw(values, time, width, height) {
113
+ /** Draws a type scene's ramp in `font`; a scene without one ignores it. */
114
+ setGlyphs(font) {
115
+ if (!scene.glyphs || !glyphTexture || font === glyphFont) return;
116
+ glyphFont = font;
117
+ const { strip, count } = drawGlyphs(scene.glyphs, font);
118
+ gl.bindTexture(gl.TEXTURE_2D, glyphTexture);
119
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
120
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, strip);
121
+ gl.generateMipmap(gl.TEXTURE_2D);
122
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
123
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
124
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
125
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
126
+ gl.uniform1f(uGlyphCount, count);
127
+ },
128
+ draw(values, time, width, height, ratio = 1) {
88
129
  gl.viewport(0, 0, width, height);
89
130
  gl.uniform2f(uSize, width, height);
131
+ gl.uniform1f(uRatio, ratio);
90
132
  gl.uniform1f(uTime, time);
91
133
  for (const [name, location] of floats) gl.uniform1f(location, valueOf(values, passes, name));
92
134
  gl.drawArrays(gl.TRIANGLES, 0, 3);
93
135
  },
94
136
  dispose() {
137
+ gl.deleteTexture(glyphTexture);
95
138
  gl.deleteVertexArray(vao);
96
139
  gl.deleteProgram(program);
97
140
  gl.deleteShader(vs);
@@ -109,6 +152,7 @@ function bakeThumbnails(host, jobs, passes, width, height) {
109
152
  const renderer = createRenderer(gl, scene, passes);
110
153
  if (!renderer) return "";
111
154
  renderer.setColours(coloursFor(host, scene));
155
+ renderer.setGlyphs(glyphFontFor(host));
112
156
  renderer.draw(values, 20, width, height);
113
157
  const url = canvas.toDataURL("image/jpeg", 0.85);
114
158
  renderer.dispose();
@@ -121,5 +165,6 @@ export {
121
165
  bakeThumbnails,
122
166
  coloursFor,
123
167
  createRenderer,
168
+ glyphFontFor,
124
169
  readColours
125
170
  };
@@ -16,5 +16,61 @@ export declare const horizon: Scene;
16
16
  * the top to another at the bottom, the rift lab's own pair.
17
17
  */
18
18
  export declare const rift: Scene;
19
+ /**
20
+ * The glyph field: soft light printed in type.
21
+ * Two layers in one pass. Six stretched Gaussian lights (a wide haze, a
22
+ * bloom, a white-hot core, one long thin streak and two blooms below) are
23
+ * added over the ground and tone-mapped, so where colours stack the core
24
+ * burns to white; they drift, breathe and roll on slow travelling swells.
25
+ * Then the screen is cut into character cells: each cell reads the light at
26
+ * its centre and prints a glyph from the ramp that thickens with the
27
+ * brightness, lighter than what is under it. Below a floor nothing prints,
28
+ * so the type gathers on the light and scatters to dots at its edge.
29
+ * Nothing snaps: the scatter eases from one roll to the next, and a cell
30
+ * crossing a step of the ramp dissolves between the two glyphs.
31
+ */
32
+ export declare const glyphs: Scene;
33
+ /**
34
+ * The prism: light through a cut stone. A handful of beams leave the
35
+ * facets of something above the stage, and no two alike: each has its own
36
+ * facet to leave from, its own angle, width and strength, so the light is
37
+ * uneven the way a diamond's is, a few strong beams among faint ones. The
38
+ * beams themselves are true: each runs dead straight, opens as it travels
39
+ * and thins as it opens, and each colour role leaves at a slightly
40
+ * different angle, so a beam is white where its colours still overlap and
41
+ * breaks into the theme's spectrum at its edges, more the further it runs.
42
+ * The stone turns slowly, so beams swing a little and come and go.
43
+ */
44
+ export declare const prism: Scene;
45
+ /**
46
+ * Meteors: a shower over a planet's edge. Stars hold a dark sky; meteors
47
+ * fall across it in lanes at one angle, three depths of them, each a white
48
+ * head with a tail that cools through the theme's colours as it thins; and
49
+ * a planet's limb crosses the foot of the scene, lit to a crescent by a sun
50
+ * that flares where it clears the edge. The limb hides what falls behind it.
51
+ * It is soft by default: the streaks, the crescent and the flare are all
52
+ * blurred, and the sky between them is left all but black.
53
+ */
54
+ export declare const meteors: Scene;
55
+ /**
56
+ * Waves: a sea drawn in points, seen from above it. A plane of dots runs off
57
+ * into the dark and rolls in slow swells, each dot a round point that grows and brightens on a
58
+ * crest and all but goes out in a trough, over a glow that lies in the
59
+ * water under them. The surface is found by marching the eye's ray through
60
+ * the slab the swells can occupy, in steps too short to pass through a
61
+ * crest, so a near crest hides the trough behind it and nothing flickers; each dot is then drawn round on the screen from its own place on the
62
+ * surface. Far off, where the dots would be finer than a pixel, they melt
63
+ * into the glow rather than shimmer.
64
+ */
65
+ export declare const waves: Scene;
66
+ /**
67
+ * The aurora: silk in colour, the one scene with no dark in its middle.
68
+ * A plane is folded over itself by slow sine warps, each fold feeding the
69
+ * next, and the folded plane picks the theme's tones in wide soft ribbons:
70
+ * a base tone, three more laid through it, a pale bloom where two ribbons
71
+ * cross, and a void, one deep pool the ground shows through, which is what
72
+ * gives the colour its depth. Nothing in it has an edge.
73
+ */
74
+ export declare const aurora: Scene;
19
75
  /** Every scene, in picker order. */
20
76
  export declare const SCENES: Scene[];