@open-slide/core 0.0.4 → 0.0.6

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.
@@ -0,0 +1,16 @@
1
+ import { createViteConfig } from "./config-DF58h0l4.js";
2
+ import path from "node:path";
3
+ import { build as build$1, mergeConfig } from "vite";
4
+
5
+ //#region src/cli/build.ts
6
+ async function build(opts = {}) {
7
+ const base = await createViteConfig({
8
+ userCwd: process.cwd(),
9
+ mode: "build"
10
+ });
11
+ const config = mergeConfig(base, { build: { ...opts.outDir !== void 0 ? { outDir: path.resolve(process.cwd(), opts.outDir) } : {} } });
12
+ await build$1(config);
13
+ }
14
+
15
+ //#endregion
16
+ export { build };
package/dist/cli/bin.js CHANGED
@@ -1,57 +1,46 @@
1
1
  #!/usr/bin/env node
2
+ import chalk from "chalk";
2
3
  import { readFile } from "node:fs/promises";
3
4
  import path from "node:path";
4
5
  import { fileURLToPath } from "node:url";
6
+ import { Command, Option } from "commander";
5
7
 
6
8
  //#region src/cli/run.ts
7
- const HELP = `open-slide — author slides, we handle the Vite/React stack
8
-
9
- Usage:
10
- open-slide dev Start dev server
11
- open-slide build Build a static site
12
- open-slide preview Preview the production build
13
- open-slide --help Show this message
14
- open-slide --version Print version
15
- `;
16
9
  async function readVersion() {
17
10
  const here = path.dirname(fileURLToPath(import.meta.url));
18
11
  const pkgPath = path.resolve(here, "..", "..", "package.json");
19
12
  const raw = await readFile(pkgPath, "utf8");
20
13
  return JSON.parse(raw).version;
21
14
  }
15
+ function parsePort(value) {
16
+ const n = Number(value);
17
+ if (!Number.isInteger(n) || n < 0 || n > 65535) throw new Error(`Invalid port: ${value}`);
18
+ return n;
19
+ }
22
20
  async function run(argv) {
23
- const [cmd] = argv;
24
- if (!cmd || cmd === "--help" || cmd === "-h" || cmd === "help") {
25
- process.stdout.write(HELP);
26
- return;
27
- }
28
- if (cmd === "--version" || cmd === "-v") {
29
- process.stdout.write(`${await readVersion()}\n`);
30
- return;
31
- }
32
- if (cmd === "dev") {
33
- const { dev } = await import("../dev-rlOZacWo.js");
34
- await dev();
35
- return;
36
- }
37
- if (cmd === "build") {
38
- const { build } = await import("../build-CuoESF2g.js");
39
- await build();
40
- return;
41
- }
42
- if (cmd === "preview") {
43
- const { preview } = await import("../preview-DCrD9X36.js");
44
- await preview();
45
- return;
46
- }
47
- process.stderr.write(`Unknown command: ${cmd}\n\n${HELP}`);
48
- process.exit(1);
21
+ const version = await readVersion();
22
+ const program = new Command();
23
+ program.name("open-slide").description("Author slides — we handle the Vite/React stack.").version(version, "-v, --version", "print version").helpOption("-h, --help", "show help").showHelpAfterError(chalk.dim("(run `open-slide --help` for usage)"));
24
+ program.command("dev").description("Start the dev server").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").action(async (flags) => {
25
+ const { dev } = await import("../dev-h-rxb3xY.js");
26
+ await dev(flags);
27
+ });
28
+ program.command("build").description("Build a static site").option("--out-dir <dir>", "output directory (defaults to `dist`)").action(async (flags) => {
29
+ const { build } = await import("../build-BCORlVF3.js");
30
+ await build(flags);
31
+ });
32
+ program.command("preview").description("Preview the production build").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").action(async (flags) => {
33
+ const { preview } = await import("../preview-lskE0s8A.js");
34
+ await preview(flags);
35
+ });
36
+ await program.parseAsync(argv, { from: "user" });
49
37
  }
50
38
 
51
39
  //#endregion
52
40
  //#region src/cli/bin.ts
53
41
  run(process.argv.slice(2)).catch((err) => {
54
- process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
42
+ const message = err instanceof Error ? err.message : String(err);
43
+ process.stderr.write(`${chalk.red("error:")} ${message}\n`);
55
44
  process.exit(1);
56
45
  });
57
46
 
@@ -0,0 +1,19 @@
1
+ import { createViteConfig } from "./config-DF58h0l4.js";
2
+ import { createServer, mergeConfig } from "vite";
3
+
4
+ //#region src/cli/dev.ts
5
+ async function dev(opts = {}) {
6
+ const base = await createViteConfig({ userCwd: process.cwd() });
7
+ const config = mergeConfig(base, { server: {
8
+ ...opts.port !== void 0 ? { port: opts.port } : {},
9
+ ...opts.host !== void 0 ? { host: opts.host } : {},
10
+ ...opts.open !== void 0 ? { open: opts.open } : {}
11
+ } });
12
+ const server = await createServer(config);
13
+ await server.listen();
14
+ server.printUrls();
15
+ server.bindCLIShortcuts({ print: true });
16
+ }
17
+
18
+ //#endregion
19
+ export { dev };
@@ -0,0 +1,17 @@
1
+ import { createViteConfig } from "./config-DF58h0l4.js";
2
+ import { mergeConfig, preview as preview$1 } from "vite";
3
+
4
+ //#region src/cli/preview.ts
5
+ async function preview(opts = {}) {
6
+ const base = await createViteConfig({ userCwd: process.cwd() });
7
+ const config = mergeConfig(base, { preview: {
8
+ ...opts.port !== void 0 ? { port: opts.port } : {},
9
+ ...opts.host !== void 0 ? { host: opts.host } : {},
10
+ ...opts.open !== void 0 ? { open: opts.open } : {}
11
+ } });
12
+ const server = await preview$1(config);
13
+ server.printUrls();
14
+ }
15
+
16
+ //#endregion
17
+ export { preview };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-slide/core",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Runtime and CLI for open-slide — write slides in slides/, we handle the rest.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -44,8 +44,10 @@
44
44
  "@fontsource-variable/geist": "^5.2.8",
45
45
  "@tailwindcss/vite": "^4.2.2",
46
46
  "@vitejs/plugin-react": "^4.3.3",
47
+ "chalk": "^5.3.0",
47
48
  "class-variance-authority": "^0.7.1",
48
49
  "clsx": "^2.1.1",
50
+ "commander": "^12.1.0",
49
51
  "emoji-picker-react": "^4.18.0",
50
52
  "fast-glob": "^3.3.2",
51
53
  "fflate": "^0.8.2",
@@ -59,7 +59,10 @@ export function Player({ pages, index, onIndexChange, onExit }: Props) {
59
59
  const PageComp = pages[index];
60
60
 
61
61
  return (
62
- <div ref={rootRef} className="relative flex h-screen w-screen items-center justify-center bg-black">
62
+ <div
63
+ ref={rootRef}
64
+ className="relative flex h-screen w-screen items-center justify-center bg-black"
65
+ >
63
66
  <SlideCanvas flat>{PageComp ? <PageComp /> : null}</SlideCanvas>
64
67
  <button
65
68
  type="button"
@@ -1,3 +1,4 @@
1
+ import { useEffect, useRef } from 'react';
1
2
  import { cn } from '@/lib/utils';
2
3
  import { ScrollArea } from '@/components/ui/scroll-area';
3
4
  import type { Page } from '../lib/sdk';
@@ -15,6 +16,12 @@ const THUMB_SCALE = THUMB_WIDTH / CANVAS_WIDTH;
15
16
  const THUMB_HEIGHT = CANVAS_HEIGHT * THUMB_SCALE;
16
17
 
17
18
  export function ThumbnailRail({ pages, current, onSelect }: Props) {
19
+ const activeRef = useRef<HTMLButtonElement | null>(null);
20
+
21
+ useEffect(() => {
22
+ activeRef.current?.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
23
+ }, [current]);
24
+
18
25
  return (
19
26
  <ScrollArea className="h-full border-r bg-card">
20
27
  <aside className="flex flex-col gap-2.5 p-3">
@@ -23,6 +30,7 @@ export function ThumbnailRail({ pages, current, onSelect }: Props) {
23
30
  return (
24
31
  <button
25
32
  key={i}
33
+ ref={active ? activeRef : undefined}
26
34
  onClick={() => onSelect(i)}
27
35
  aria-label={`Go to page ${i + 1}`}
28
36
  aria-current={active ? 'true' : undefined}
@@ -42,14 +42,15 @@ export function InspectOverlay() {
42
42
  if (!hit) return;
43
43
  e.preventDefault();
44
44
  e.stopPropagation();
45
+ const anchorRect = hit.anchor.getBoundingClientRect();
45
46
  setPending({
46
47
  line: hit.line,
47
48
  column: hit.column,
48
- anchorRect: hit.anchor.getBoundingClientRect(),
49
+ anchorRect,
49
50
  clickX: e.clientX,
50
51
  clickY: e.clientY,
51
52
  });
52
- setHover(null);
53
+ setHover({ rect: anchorRect, hit });
53
54
  };
54
55
 
55
56
  window.addEventListener('pointermove', onMove, true);
@@ -9,7 +9,8 @@ import type { SlideModule } from './sdk';
9
9
 
10
10
  type AssetEntry = { name: string; bytes: Uint8Array };
11
11
 
12
- const ASSET_EXT_RE = /\.(?:png|jpe?g|gif|svg|webp|avif|mp4|webm|mov|woff2?|ttf|otf|mp3|wav|ogg)(?:\?[^#]*)?(?:#.*)?$/i;
12
+ const ASSET_EXT_RE =
13
+ /\.(?:png|jpe?g|gif|svg|webp|avif|mp4|webm|mov|woff2?|ttf|otf|mp3|wav|ogg)(?:\?[^#]*)?(?:#.*)?$/i;
13
14
 
14
15
  export async function exportSlideAsHtml(slide: SlideModule, slideId: string): Promise<void> {
15
16
  const pages = slide.default ?? [];
@@ -218,7 +219,11 @@ function shortHash(input: string): string {
218
219
  return (h >>> 0).toString(36).slice(0, 6);
219
220
  }
220
221
 
221
- function rewriteUrls(source: string, assets: Map<string, AssetEntry>, kind: 'html' | 'css'): string {
222
+ function rewriteUrls(
223
+ source: string,
224
+ assets: Map<string, AssetEntry>,
225
+ kind: 'html' | 'css',
226
+ ): string {
222
227
  let out = source;
223
228
  for (const [orig, { name }] of assets) {
224
229
  const replacement = kind === 'css' ? `./assets/${name}` : `assets/${name}`;
@@ -234,7 +239,9 @@ function buildHtml(opts: {
234
239
  externalLinks: string;
235
240
  }): string {
236
241
  const pagesMarkup = opts.pagesHtml
237
- .map((page, i) => `<div class="os-page" data-idx="${i}"${i === 0 ? '' : ' hidden'}>${page}</div>`)
242
+ .map(
243
+ (page, i) => `<div class="os-page" data-idx="${i}"${i === 0 ? '' : ' hidden'}>${page}</div>`,
244
+ )
238
245
  .join('');
239
246
 
240
247
  return `<!doctype html>
@@ -1,14 +0,0 @@
1
- import { createViteConfig } from "./config-DF58h0l4.js";
2
- import { build as build$1 } from "vite";
3
-
4
- //#region src/cli/build.ts
5
- async function build() {
6
- const config = await createViteConfig({
7
- userCwd: process.cwd(),
8
- mode: "build"
9
- });
10
- await build$1(config);
11
- }
12
-
13
- //#endregion
14
- export { build };
@@ -1,14 +0,0 @@
1
- import { createViteConfig } from "./config-DF58h0l4.js";
2
- import { createServer } from "vite";
3
-
4
- //#region src/cli/dev.ts
5
- async function dev() {
6
- const config = await createViteConfig({ userCwd: process.cwd() });
7
- const server = await createServer(config);
8
- await server.listen();
9
- server.printUrls();
10
- server.bindCLIShortcuts({ print: true });
11
- }
12
-
13
- //#endregion
14
- export { dev };
@@ -1,12 +0,0 @@
1
- import { createViteConfig } from "./config-DF58h0l4.js";
2
- import { preview as preview$1 } from "vite";
3
-
4
- //#region src/cli/preview.ts
5
- async function preview() {
6
- const config = await createViteConfig({ userCwd: process.cwd() });
7
- const server = await preview$1(config);
8
- server.printUrls();
9
- }
10
-
11
- //#endregion
12
- export { preview };