paseo-plugin-genui 0.1.7 → 0.2.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/OVERVIEW.md +3 -3
- package/README.md +1 -1
- package/client/components/content.tsx +62 -3
- package/client/components/data.tsx +26 -17
- package/client/components/dev.tsx +2 -1
- package/client/components/image-lightbox.tsx +153 -33
- package/client/components/inputs.tsx +3 -2
- package/client/components/media.tsx +37 -24
- package/client/components/project.tsx +24 -1
- package/client/components/widgets.tsx +2 -2
- package/client/live-ui.tsx +7 -2
- package/client/markdown.tsx +20 -1
- package/client/render.tsx +2 -0
- package/client/settings.tsx +22 -1
- package/gallery/Draft-long.ui +1 -0
- package/gallery/Draft.ui +1 -0
- package/index.server.ts +10 -4
- package/package.json +2 -2
- package/paseo-plugin.json +1 -1
- package/server/data-source.ts +20 -4
- package/server/project.test.ts +81 -0
- package/server/project.ts +51 -12
- package/shared/core/catalog.ts +5 -0
- package/shared/core/markdown.ts +5 -0
- package/shared/diagram/markdown.test.ts +28 -0
- package/shared/diagram/markdown.ts +12 -2
- package/shared/genui.test.ts +53 -1
- package/shared/instructions.ts +4 -2
- package/shared/logic/lightbox.test.ts +32 -0
- package/shared/logic/lightbox.ts +27 -0
- package/shared/settings.ts +8 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { clampZoom, MAX_ZOOM, wheelFactor, zoomAt } from "./lightbox";
|
|
3
|
+
|
|
4
|
+
describe("lightbox zoom", () => {
|
|
5
|
+
it("keeps the point under the cursor still", () => {
|
|
6
|
+
const next = zoomAt({ zoom: 1, x: 0, y: 0 }, 2, { x: 100, y: -50 }, 0.5);
|
|
7
|
+
// image point under the cursor was (100, -50) / 1; after zoom it must map back to the cursor
|
|
8
|
+
expect((100 - next!.x) / next!.zoom).toBeCloseTo(100);
|
|
9
|
+
expect((-50 - next!.y) / next!.zoom).toBeCloseTo(-50);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns to fit (null) rather than a fixed zoom, so a later resize refits", () => {
|
|
13
|
+
expect(zoomAt({ zoom: 1, x: 40, y: 40 }, 0.1, { x: 0, y: 0 }, 0.5)).toBeNull();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("clamps between fit (or 100% for small images) and the max", () => {
|
|
17
|
+
expect(clampZoom(0.1, 0.4)).toBe(0.4);
|
|
18
|
+
expect(clampZoom(0.1, 1)).toBe(1);
|
|
19
|
+
expect(clampZoom(50, 0.4)).toBe(MAX_ZOOM);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("wheel up zooms in, wheel down zooms out", () => {
|
|
23
|
+
expect(wheelFactor(-100, false)).toBeGreaterThan(1);
|
|
24
|
+
expect(wheelFactor(100, false)).toBeLessThan(1);
|
|
25
|
+
expect(wheelFactor(-10, true)).toBeGreaterThan(wheelFactor(-10, false));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("treats line and page wheel deltas like their pixel size", () => {
|
|
29
|
+
expect(wheelFactor(-3, false, 1)).toBeCloseTo(wheelFactor(-48, false, 0));
|
|
30
|
+
expect(wheelFactor(-1, false, 2)).toBeCloseTo(wheelFactor(-800, false, 0));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type LightboxView = { readonly zoom: number; readonly x: number; readonly y: number };
|
|
2
|
+
|
|
3
|
+
export const MAX_ZOOM = 8;
|
|
4
|
+
|
|
5
|
+
const LINE_PX = 16;
|
|
6
|
+
const PAGE_PX = 800;
|
|
7
|
+
|
|
8
|
+
export function clampZoom(zoom: number, fit: number): number {
|
|
9
|
+
return Math.min(MAX_ZOOM, Math.max(Math.min(fit, 1), zoom));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Zooms by `factor` keeping the image point under `at` still; `at` and x/y are offsets from the stage centre.
|
|
14
|
+
* Returns null at fit so the view follows the stage when it is resized.
|
|
15
|
+
*/
|
|
16
|
+
export function zoomAt(view: LightboxView, factor: number, at: { x: number; y: number }, fit: number): LightboxView | null {
|
|
17
|
+
const zoom = clampZoom(view.zoom * factor, fit);
|
|
18
|
+
if (zoom <= fit) return null;
|
|
19
|
+
const ratio = zoom / view.zoom;
|
|
20
|
+
return { zoom, x: at.x - (at.x - view.x) * ratio, y: at.y - (at.y - view.y) * ratio };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Wheel delta to zoom factor; trackpad pinch arrives as a ctrl+wheel with small deltas. `deltaMode` 1 = lines, 2 = pages. */
|
|
24
|
+
export function wheelFactor(deltaY: number, pinch: boolean, deltaMode = 0): number {
|
|
25
|
+
const px = deltaY * (deltaMode === 1 ? LINE_PX : deltaMode === 2 ? PAGE_PX : 1);
|
|
26
|
+
return Math.exp(-px * (pinch ? 0.01 : 0.0015));
|
|
27
|
+
}
|
package/shared/settings.ts
CHANGED
|
@@ -8,5 +8,13 @@ export const genuiSettings = defineSettings({
|
|
|
8
8
|
schema: z.object({
|
|
9
9
|
autoInstructions: z.boolean().default(true),
|
|
10
10
|
webLookups: z.boolean().default(true),
|
|
11
|
+
extraFolders: z.string().default(""),
|
|
11
12
|
}),
|
|
12
13
|
});
|
|
14
|
+
|
|
15
|
+
export function parseFolders(value: string): string[] {
|
|
16
|
+
return value
|
|
17
|
+
.split(/[,\n]/)
|
|
18
|
+
.map((folder) => folder.trim())
|
|
19
|
+
.filter((folder) => folder !== "");
|
|
20
|
+
}
|