@open-slide/core 2.0.0-beta.2 → 2.0.0-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-slide/core",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.3",
4
4
  "description": "Runtime and CLI for open-slide — write slides in slides/, we handle the rest.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -67,7 +67,7 @@
67
67
  "@dnd-kit/utilities": "^3.2.2",
68
68
  "@fontsource-variable/geist": "^5.2.8",
69
69
  "@tailwindcss/vite": "^4.3.3",
70
- "@vitejs/plugin-react": "^6.1.0",
70
+ "@vitejs/plugin-react": "^6.1.1",
71
71
  "chalk": "^6.0.0",
72
72
  "class-variance-authority": "^0.7.1",
73
73
  "clsx": "^2.1.1",
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
2
2
  import {
3
3
  applyTextTransform,
4
4
  decompose,
5
+ geometryFor,
5
6
  gradientLineLength,
6
7
  multiply,
7
8
  normalizeRadii,
@@ -170,3 +171,35 @@ describe('misc', () => {
170
171
  expect(applyTextTransform('Hello', 'none')).toBe('Hello');
171
172
  });
172
173
  });
174
+
175
+ describe('geometryFor', () => {
176
+ const uniform = (x: number, y = x): Parameters<typeof geometryFor>[0] => [
177
+ { x, y },
178
+ { x, y },
179
+ { x, y },
180
+ { x, y },
181
+ ];
182
+ it('keeps a pill as a rounded rectangle', () => {
183
+ const radii = normalizeRadii(uniform(9999), 540, 56);
184
+ expect(geometryFor(radii, 540, 56)).toEqual({ kind: 'roundRect', radius: 28 });
185
+ });
186
+ it('treats a fully rounded square as an ellipse', () => {
187
+ const radii = normalizeRadii(uniform(9999), 64, 64);
188
+ expect(geometryFor(radii, 64, 64)).toEqual({ kind: 'ellipse' });
189
+ });
190
+ it('treats 50% corners on a wide box as an ellipse', () => {
191
+ expect(geometryFor(uniform(100, 30), 200, 60)).toEqual({ kind: 'ellipse' });
192
+ });
193
+ it('maps small uniform corners to a rounded rectangle', () => {
194
+ expect(geometryFor(uniform(12), 300, 80)).toEqual({ kind: 'roundRect', radius: 12 });
195
+ });
196
+ it('falls back to a custom path for mixed or elliptical corners', () => {
197
+ const mixed = uniform(12);
198
+ mixed[2] = { x: 0, y: 0 };
199
+ expect(geometryFor(mixed, 300, 80).kind).toBe('custom');
200
+ expect(geometryFor(uniform(40, 10), 300, 80).kind).toBe('custom');
201
+ });
202
+ it('maps no radius to a plain rectangle', () => {
203
+ expect(geometryFor(uniform(0), 300, 80)).toEqual({ kind: 'rect' });
204
+ });
205
+ });
@@ -1,3 +1,5 @@
1
+ import type { Geometry } from './scene';
2
+
1
3
  export type Rgba = { r: number; g: number; b: number; a: number };
2
4
  export type ColorParser = (value: string) => Rgba | null;
3
5
 
@@ -430,6 +432,16 @@ export function hasRadius(radii: Radii): boolean {
430
432
  return radii.some((c) => c.x > 0.01 && c.y > 0.01);
431
433
  }
432
434
 
435
+ export function geometryFor(radii: Radii, w: number, h: number): Geometry {
436
+ if (!hasRadius(radii)) return { kind: 'rect' };
437
+ const [tl, ...rest] = radii;
438
+ const uniform = rest.every((c) => Math.abs(c.x - tl.x) < 0.5 && Math.abs(c.y - tl.y) < 0.5);
439
+ if (!uniform) return { kind: 'custom', radii };
440
+ if (tl.x >= w / 2 - 0.5 && tl.y >= h / 2 - 0.5) return { kind: 'ellipse' };
441
+ if (Math.abs(tl.x - tl.y) < 0.5) return { kind: 'roundRect', radius: tl.x };
442
+ return { kind: 'custom', radii };
443
+ }
444
+
433
445
  export function parseBlurPx(filter: string): number {
434
446
  if (!filter || filter === 'none') return 0;
435
447
  let total = 0;
@@ -4,7 +4,7 @@ import {
4
4
  applyToPoint,
5
5
  type ColorParser,
6
6
  decompose,
7
- hasRadius,
7
+ geometryFor,
8
8
  IDENTITY,
9
9
  isIdentity,
10
10
  isVisibleColor,
@@ -605,24 +605,6 @@ function radiiOf(cs: CSSStyleDeclaration, w: number, h: number): Radii {
605
605
  );
606
606
  }
607
607
 
608
- function geometryFor(radii: Radii, w: number, h: number): Geometry {
609
- if (!hasRadius(radii)) return { kind: 'rect' };
610
- const [tl, tr, br, bl] = radii;
611
- const same =
612
- Math.abs(tl.x - tr.x) < 0.5 &&
613
- Math.abs(tl.x - br.x) < 0.5 &&
614
- Math.abs(tl.x - bl.x) < 0.5 &&
615
- Math.abs(tl.y - tr.y) < 0.5 &&
616
- Math.abs(tl.y - br.y) < 0.5 &&
617
- Math.abs(tl.y - bl.y) < 0.5;
618
- if (same && Math.abs(tl.x - tl.y) < 0.5) {
619
- if (tl.x >= Math.min(w, h) / 2 - 0.5) return { kind: 'ellipse' };
620
- return { kind: 'roundRect', radius: tl.x };
621
- }
622
- if (same && tl.x >= w / 2 - 0.5 && tl.y >= h / 2 - 0.5) return { kind: 'ellipse' };
623
- return { kind: 'custom', radii };
624
- }
625
-
626
608
  function shrinkRadii(radii: Radii, by: number): Radii {
627
609
  return radii.map((c) => ({ x: Math.max(0, c.x - by), y: Math.max(0, c.y - by) })) as Radii;
628
610
  }
@@ -0,0 +1,14 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { DEFAULT_DOCUMENT_TITLE, resolveDocumentTitle } from './use-document-title.ts';
3
+
4
+ describe('resolveDocumentTitle', () => {
5
+ it('uses the deck title', () => {
6
+ expect(resolveDocumentTitle('Quarterly Product Review')).toBe('Quarterly Product Review');
7
+ });
8
+
9
+ it('falls back when the deck has no title', () => {
10
+ expect(resolveDocumentTitle()).toBe(DEFAULT_DOCUMENT_TITLE);
11
+ expect(resolveDocumentTitle('')).toBe(DEFAULT_DOCUMENT_TITLE);
12
+ expect(resolveDocumentTitle(' ')).toBe(DEFAULT_DOCUMENT_TITLE);
13
+ });
14
+ });
@@ -0,0 +1,16 @@
1
+ import { useEffect } from 'react';
2
+
3
+ export const DEFAULT_DOCUMENT_TITLE = 'open-slide';
4
+
5
+ export function resolveDocumentTitle(title?: string): string {
6
+ return title?.trim() || DEFAULT_DOCUMENT_TITLE;
7
+ }
8
+
9
+ export function useDocumentTitle(title?: string) {
10
+ useEffect(() => {
11
+ document.title = resolveDocumentTitle(title);
12
+ return () => {
13
+ document.title = DEFAULT_DOCUMENT_TITLE;
14
+ };
15
+ }, [title]);
16
+ }
@@ -21,6 +21,7 @@ import { useNavigate, useParams } from 'react-router-dom';
21
21
  import { Button } from '@/components/ui/button';
22
22
  import { Dialog, DialogContent, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
23
23
  import { hasModifier, isBackwardKey, isForwardKey, isTypingTarget } from '@/lib/keys';
24
+ import { useDocumentTitle } from '@/lib/use-document-title';
24
25
  import { format, useLocale } from '@/lib/use-locale';
25
26
  import { cn, pad2 } from '@/lib/utils';
26
27
  import {
@@ -38,6 +39,7 @@ import { useSlideModule } from '../lib/use-slide-module';
38
39
  export function Presenter() {
39
40
  const { slideId = '' } = useParams();
40
41
  const { slide, error } = useSlideModule(slideId);
42
+ useDocumentTitle(slide?.meta?.title);
41
43
 
42
44
  // Presenter view is a passive mirror of the projection window. It only
43
45
  // tracks the index it last heard about; navigation buttons send commands
@@ -57,6 +57,7 @@ import { hasModifier, isBackwardKey, isForwardKey, isTypingTarget } from '@/lib/
57
57
  import { readLastHomeLocation } from '@/lib/last-home-location';
58
58
  import { useAgentSocketConnected } from '@/lib/use-agent-socket';
59
59
  import { useClickPageNavigation } from '@/lib/use-click-page-navigation';
60
+ import { useDocumentTitle } from '@/lib/use-document-title';
60
61
  import { useIsMobile } from '@/lib/use-is-mobile';
61
62
  import { format, useLocale } from '@/lib/use-locale';
62
63
  import { useWheelPageNavigation } from '@/lib/use-wheel-page-navigation';
@@ -101,6 +102,7 @@ export function Slide() {
101
102
  }
102
103
  }, [navigate]);
103
104
  const { slide, error } = useSlideModule(slideId);
105
+ useDocumentTitle(slide?.meta?.title);
104
106
  const [playMode, setPlayMode] = useState<'window' | 'fullscreen' | null>(null);
105
107
  // Last deck the Player showed. During a presenter-driven deck switch the
106
108
  // route's slideId changes while the new module loads and warms; rendering