@open-slide/core 2.1.0 → 2.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.
Files changed (33) hide show
  1. package/dist/{build-COxfoC_P.js → build-DTmKJyjX.js} +1 -1
  2. package/dist/cli/bin.js +3 -3
  3. package/dist/{config-CNhYSo4C.js → config-Ces2X_3T.js} +103 -14
  4. package/dist/{config-DHPbCCnt.d.ts → config-CpmGqpQi.d.ts} +1 -1
  5. package/dist/{dev-CujpTS3T.js → dev-ldYag-pR.js} +1 -1
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +1 -1
  8. package/dist/locale/index.d.ts +1 -1
  9. package/dist/locale/index.js +1 -1
  10. package/dist/{preview-kU5R6QXJ.js → preview-GYMbZvvk.js} +1 -1
  11. package/dist/{types-BGUi9COY.d.ts → types-CvAqFqsY.d.ts} +9 -4
  12. package/dist/vite/index.d.ts +1 -1
  13. package/dist/vite/index.js +1 -1
  14. package/dist/{zh-tw-BbFb4PZW.js → zh-tw-B7_Oqv2q.js} +35 -20
  15. package/package.json +1 -1
  16. package/skills/apply-comments/SKILL.md +9 -6
  17. package/src/app/components/icon-switcher-indicator.tsx +1 -1
  18. package/src/app/components/inspector/comment-layer.tsx +992 -0
  19. package/src/app/components/inspector/inspect-overlay.tsx +2 -39
  20. package/src/app/components/inspector/inspector-panel.tsx +9 -92
  21. package/src/app/components/inspector/inspector-provider.tsx +120 -46
  22. package/src/app/components/thumbnail-rail.tsx +39 -1
  23. package/src/app/lib/inspector/freeze-motion.ts +61 -0
  24. package/src/app/lib/inspector/use-comments.ts +32 -3
  25. package/src/app/routes/slide.tsx +6 -5
  26. package/src/app/styles.css +64 -80
  27. package/src/locale/en.ts +7 -4
  28. package/src/locale/es.ts +7 -5
  29. package/src/locale/ja.ts +7 -5
  30. package/src/locale/types.ts +9 -4
  31. package/src/locale/zh-cn.ts +7 -4
  32. package/src/locale/zh-tw.ts +7 -4
  33. package/src/app/components/inspector/comment-widget.tsx +0 -119
@@ -1,5 +1,5 @@
1
1
  import { r as printHeader, t as createCliLogger } from "./cli/bin.js";
2
- import { t as createViteConfig } from "./config-CNhYSo4C.js";
2
+ import { t as createViteConfig } from "./config-Ces2X_3T.js";
3
3
  import path from "node:path";
4
4
  import { build as build$1, mergeConfig } from "vite";
5
5
  //#region src/cli/build.ts
package/dist/cli/bin.js CHANGED
@@ -453,17 +453,17 @@ async function run(argv) {
453
453
  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").option("--no-skills-check", "skip the built-in skills drift check").action(async (flags) => {
454
454
  if (flags.skillsCheck !== false) await runSkillsDriftCheck(resolveBuiltinSkillsDir());
455
455
  await assertViteResolvesToCore();
456
- const { dev } = await import("../dev-CujpTS3T.js");
456
+ const { dev } = await import("../dev-ldYag-pR.js");
457
457
  await dev(flags);
458
458
  });
459
459
  program.command("build").description("Build a static site").option("--out-dir <dir>", "output directory (defaults to `dist`)").action(async (flags) => {
460
460
  await assertViteResolvesToCore();
461
- const { build } = await import("../build-COxfoC_P.js");
461
+ const { build } = await import("../build-DTmKJyjX.js");
462
462
  await build(flags);
463
463
  });
464
464
  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) => {
465
465
  await assertViteResolvesToCore();
466
- const { preview } = await import("../preview-kU5R6QXJ.js");
466
+ const { preview } = await import("../preview-GYMbZvvk.js");
467
467
  await preview(flags);
468
468
  });
469
469
  program.command("sync:skills").description("Sync built-in skills from @open-slide/core into this workspace").option("--dry-run", "show what would change without writing").action(async (flags) => {
@@ -1495,6 +1495,24 @@ function b64urlDecode(s) {
1495
1495
  const pad = s.length % 4 === 0 ? "" : "=".repeat(4 - s.length % 4);
1496
1496
  return Buffer.from(s.replace(/-/g, "+").replace(/_/g, "/") + pad, "base64").toString("utf8");
1497
1497
  }
1498
+ function isFiniteNumber(value) {
1499
+ return typeof value === "number" && Number.isFinite(value);
1500
+ }
1501
+ function parseCommentRect(value) {
1502
+ if (!value || typeof value !== "object") return void 0;
1503
+ const { x, y, w, h } = value;
1504
+ if (!isFiniteNumber(x) || !isFiniteNumber(y) || !isFiniteNumber(w) || !isFiniteNumber(h)) return void 0;
1505
+ if (w <= 0 || h <= 0) return void 0;
1506
+ return {
1507
+ x: Math.round(x),
1508
+ y: Math.round(y),
1509
+ w: Math.round(w),
1510
+ h: Math.round(h)
1511
+ };
1512
+ }
1513
+ function parseCommentPage(value) {
1514
+ return isFiniteNumber(value) && value >= 0 ? Math.floor(value) : void 0;
1515
+ }
1498
1516
  function parseMarkers(source) {
1499
1517
  const comments = [];
1500
1518
  const lines = source.split("\n");
@@ -1509,12 +1527,36 @@ function parseMarkers(source) {
1509
1527
  line: i + 1,
1510
1528
  ts,
1511
1529
  note: payload.note,
1512
- hint: payload.hint
1530
+ hint: payload.hint,
1531
+ rect: parseCommentRect(payload.rect),
1532
+ page: parseCommentPage(payload.page)
1513
1533
  });
1514
1534
  } catch {}
1515
1535
  }
1516
1536
  return comments;
1517
1537
  }
1538
+ function markerColumn(source, line) {
1539
+ const index = (source.split("\n")[line - 1] ?? "").search(/\{\/\*\s*@slide-comment/);
1540
+ return index === -1 ? 0 : index;
1541
+ }
1542
+ function resolveTargets(source, comments) {
1543
+ const ast = parseSource(source);
1544
+ return comments.map((comment) => {
1545
+ if (!ast) return {
1546
+ ...comment,
1547
+ target: null
1548
+ };
1549
+ const column = markerColumn(source, comment.line);
1550
+ const start = findJsxAncestors(ast, comment.line, column).find((node) => t.isJSXElement(node))?.loc?.start;
1551
+ return {
1552
+ ...comment,
1553
+ target: start ? {
1554
+ line: start.line,
1555
+ column: start.column
1556
+ } : null
1557
+ };
1558
+ });
1559
+ }
1518
1560
  function newCommentId() {
1519
1561
  return shortId("c");
1520
1562
  }
@@ -1536,11 +1578,43 @@ function lineIndent(source, lineNumber) {
1536
1578
  }
1537
1579
  function planInsertion(source, target) {
1538
1580
  if (t.isJSXElement(target) && target.openingElement.selfClosing) return null;
1581
+ const offset = (t.isJSXFragment(target) ? target.openingFragment : target.openingElement).end ?? 0;
1539
1582
  return {
1540
- offset: (t.isJSXFragment(target) ? target.openingFragment : target.openingElement).end ?? 0,
1541
- indent: `${lineIndent(source, target.loc?.start.line ?? 1)} `
1583
+ offset,
1584
+ indent: `${lineIndent(source, target.loc?.start.line ?? 1)} `,
1585
+ breakAfter: !/^[ \t]*\r?\n/.test(source.slice(offset))
1542
1586
  };
1543
1587
  }
1588
+ function buildMarker(plan, id, ts, encodedText) {
1589
+ const marker = `\n${plan.indent}{/* @slide-comment id="${id}" ts="${ts}" text="${encodedText}" */}`;
1590
+ return plan.breakAfter ? `${marker}\n${plan.indent}` : marker;
1591
+ }
1592
+ function updateMarkerNote(source, id, note) {
1593
+ const re = new RegExp(`(\\{\\/\\*\\s*@slide-comment\\s+id="${id}"\\s+ts="[^"]+"\\s+text=")([A-Za-z0-9_\\-]+={0,2})("\\s*\\*\\/\\})`);
1594
+ const m = source.match(re);
1595
+ if (!m) return null;
1596
+ let payload;
1597
+ try {
1598
+ payload = JSON.parse(b64urlDecode(m[2]));
1599
+ } catch {
1600
+ return null;
1601
+ }
1602
+ const encoded = b64urlEncode(JSON.stringify({
1603
+ ...payload,
1604
+ note
1605
+ }));
1606
+ return source.replace(re, `$1${encoded}$3`);
1607
+ }
1608
+ function removeMarker(source, id) {
1609
+ const lines = source.split("\n");
1610
+ const idRe = markerDeleteRegex(id);
1611
+ const hit = lines.findIndex((line) => idRe.test(line));
1612
+ if (hit === -1) return null;
1613
+ const stripped = lines[hit].replace(idRe, "");
1614
+ if (stripped.trim() === "") lines.splice(hit, 1);
1615
+ else lines[hit] = stripped;
1616
+ return lines.join("\n");
1617
+ }
1544
1618
  function findInsertion(source, line, column) {
1545
1619
  const ast = parseSource(source);
1546
1620
  if (!ast) return null;
@@ -1567,7 +1641,7 @@ function registerCommentRoutes(server, ctx) {
1567
1641
  if (!file) return json(res, 400, { error: "invalid slideId" });
1568
1642
  const source = await readSlideSource(file);
1569
1643
  if (source === null) return json(res, 404, { error: "slide not found" });
1570
- return json(res, 200, { comments: parseMarkers(source) });
1644
+ return json(res, 200, { comments: resolveTargets(source, parseMarkers(source)) });
1571
1645
  }
1572
1646
  if (method === "POST" && url.pathname === "/add") {
1573
1647
  const requestCheck = validateMutationRequest(req, { requireJsonBody: true });
@@ -1584,11 +1658,13 @@ function registerCommentRoutes(server, ctx) {
1584
1658
  if (!plan) return json(res, 422, { error: `could not find a JSX container around line ${body.line}. Try clicking a different element.` });
1585
1659
  const id = newCommentId();
1586
1660
  const ts = (/* @__PURE__ */ new Date()).toISOString();
1587
- const payload = b64urlEncode(JSON.stringify({
1661
+ const payload = {
1588
1662
  note: body.text,
1589
- hint: body.hint
1590
- }));
1591
- const marker = `\n${plan.indent}{/* @slide-comment id="${id}" ts="${ts}" text="${payload}" */}`;
1663
+ hint: body.hint,
1664
+ rect: parseCommentRect(body.rect),
1665
+ page: parseCommentPage(body.page)
1666
+ };
1667
+ const marker = buildMarker(plan, id, ts, b64urlEncode(JSON.stringify(payload)));
1592
1668
  const next = source.slice(0, plan.offset) + marker + source.slice(plan.offset);
1593
1669
  await fs.writeFile(file, next, "utf8");
1594
1670
  const markerLine = offsetToLine(next, plan.offset + 1);
@@ -1597,6 +1673,22 @@ function registerCommentRoutes(server, ctx) {
1597
1673
  line: markerLine
1598
1674
  });
1599
1675
  }
1676
+ if (method === "PUT" && url.pathname.startsWith("/")) {
1677
+ const requestCheck = validateMutationRequest(req, { requireJsonBody: true });
1678
+ if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
1679
+ const id = url.pathname.slice(1);
1680
+ if (!/^c-[a-f0-9]+$/.test(id)) return json(res, 400, { error: "invalid id" });
1681
+ const body = await readBody(req);
1682
+ const file = resolveSlideEntryPath(ctx, body.slideId ?? "");
1683
+ if (!file) return json(res, 400, { error: "invalid slideId" });
1684
+ if (!body.text || typeof body.text !== "string") return json(res, 400, { error: "missing text" });
1685
+ const source = await readSlideSource(file);
1686
+ if (source === null) return json(res, 404, { error: "slide not found" });
1687
+ const next = updateMarkerNote(source, id, body.text);
1688
+ if (next === null) return json(res, 404, { error: "marker not found" });
1689
+ await fs.writeFile(file, next, "utf8");
1690
+ return json(res, 200, { ok: true });
1691
+ }
1600
1692
  if (method === "DELETE" && url.pathname.startsWith("/")) {
1601
1693
  const requestCheck = validateMutationRequest(req);
1602
1694
  if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
@@ -1607,12 +1699,9 @@ function registerCommentRoutes(server, ctx) {
1607
1699
  if (!file) return json(res, 400, { error: "invalid slideId" });
1608
1700
  const source = await readSlideSource(file);
1609
1701
  if (source === null) return json(res, 404, { error: "slide not found" });
1610
- const lines = source.split("\n");
1611
- const idRe = markerDeleteRegex(id);
1612
- const hit = lines.findIndex((l) => idRe.test(l));
1613
- if (hit === -1) return json(res, 404, { error: "marker not found" });
1614
- lines.splice(hit, 1);
1615
- await fs.writeFile(file, lines.join("\n"), "utf8");
1702
+ const next = removeMarker(source, id);
1703
+ if (next === null) return json(res, 404, { error: "marker not found" });
1704
+ await fs.writeFile(file, next, "utf8");
1616
1705
  return json(res, 200, { ok: true });
1617
1706
  }
1618
1707
  next();
@@ -1,4 +1,4 @@
1
- import { t as Locale } from "./types-BGUi9COY.js";
1
+ import { t as Locale } from "./types-CvAqFqsY.js";
2
2
  //#region src/config.d.ts
3
3
  type OpenSlideBuildConfig = {
4
4
  showSlideBrowser?: boolean;
@@ -1,5 +1,5 @@
1
1
  import { a as printUrls, i as printShortcutsHint, n as formatError, o as shortcutsEnabled, r as printHeader, s as startupDuration, t as createCliLogger } from "./cli/bin.js";
2
- import { n as DEV_SUPERVISED_ENV, t as createViteConfig } from "./config-CNhYSo4C.js";
2
+ import { n as DEV_SUPERVISED_ENV, t as createViteConfig } from "./config-Ces2X_3T.js";
3
3
  import path from "node:path";
4
4
  import { existsSync } from "node:fs";
5
5
  import { fork } from "node:child_process";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { n as Plural, t as Locale } from "./types-BGUi9COY.js";
2
- import { t as OpenSlideConfig } from "./config-DHPbCCnt.js";
1
+ import { n as Plural, t as Locale } from "./types-CvAqFqsY.js";
2
+ import { t as OpenSlideConfig } from "./config-CpmGqpQi.js";
3
3
  import { CSSProperties, ComponentType, HTMLAttributes, PropsWithChildren, ReactNode } from "react";
4
4
  //#region src/app/components/image-placeholder.d.ts
5
5
  type ImagePlaceholderProps = {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as en, i as es, n as zhCN, r as ja, t as zhTW } from "./zh-tw-BbFb4PZW.js";
1
+ import { a as en, i as es, n as zhCN, r as ja, t as zhTW } from "./zh-tw-B7_Oqv2q.js";
2
2
  import { n as defaultDesign, r as designToCssVars, t as cssVarsToString } from "./design-Cpqx7SJs.js";
3
3
  import { Children, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
4
4
  import { toast } from "sonner";
@@ -1,4 +1,4 @@
1
- import { n as Plural, t as Locale } from "../types-BGUi9COY.js";
1
+ import { n as Plural, t as Locale } from "../types-CvAqFqsY.js";
2
2
  //#region src/locale/en.d.ts
3
3
  declare const en: Locale;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { a as en, i as es, n as zhCN, r as ja, t as zhTW } from "../zh-tw-BbFb4PZW.js";
1
+ import { a as en, i as es, n as zhCN, r as ja, t as zhTW } from "../zh-tw-B7_Oqv2q.js";
2
2
  //#region src/locale/format.ts
3
3
  function format(template, vars) {
4
4
  return template.replace(/\{(\w+)\}/g, (m, key) => {
@@ -1,5 +1,5 @@
1
1
  import { a as printUrls, i as printShortcutsHint, o as shortcutsEnabled, r as printHeader, s as startupDuration, t as createCliLogger } from "./cli/bin.js";
2
- import { t as createViteConfig } from "./config-CNhYSo4C.js";
2
+ import { t as createViteConfig } from "./config-Ces2X_3T.js";
3
3
  import { mergeConfig, preview as preview$1 } from "vite";
4
4
  //#region src/cli/preview.ts
5
5
  async function preview(opts = {}) {
@@ -283,20 +283,25 @@ type Locale = {
283
283
  cropFitCover: string;
284
284
  cropFitContain: string;
285
285
  cropApply: string;
286
- leaveComment: string;
286
+ commentMode: string;
287
287
  commentPlaceholder: string;
288
- commentShortcutHint: string;
289
- addComment: string;
288
+ commentPost: string;
290
289
  /** templates: "{count} unsaved change" / "{count} unsaved changes" */
291
290
  unsavedChanges: Plural;
292
291
  /** templates: "{count} comment" / "{count} comments" */
293
292
  commentsCount: Plural;
294
293
  /** template: "line {n}" */
295
294
  commentLineLabel: string;
296
- commentsEmpty: string;
295
+ commentRegionLabel: string;
296
+ commentEmptyHint: string;
297
297
  commentsApplyHintPrefix: string;
298
298
  commentsApplyHintSuffix: string;
299
299
  commentDeleteAria: string;
300
+ /** Prefix for the toast shown when a comment edit fails to write to disk. */
301
+ commentUpdateFailed: string;
302
+ /** Prefix for the toast shown when a comment fails to write to disk. */
303
+ commentAddFailed: string;
304
+ commentRegionNoTarget: string;
300
305
  /** Prefix for the toast shown when one or more buffered edits fail to write to disk. */
301
306
  saveFailed: string;
302
307
  decreaseFontSize: string;
@@ -1,4 +1,4 @@
1
- import { t as OpenSlideConfig } from "../config-DHPbCCnt.js";
1
+ import { t as OpenSlideConfig } from "../config-CpmGqpQi.js";
2
2
  import { InlineConfig } from "vite";
3
3
  //#region src/vite/config.d.ts
4
4
  type CreateViteConfigOptions = {
@@ -1,2 +1,2 @@
1
- import { t as createViteConfig } from "../config-CNhYSo4C.js";
1
+ import { t as createViteConfig } from "../config-Ces2X_3T.js";
2
2
  export { createViteConfig };
@@ -272,10 +272,9 @@ const en = {
272
272
  cropFitCover: "Fill",
273
273
  cropFitContain: "Fit",
274
274
  cropApply: "Apply",
275
- leaveComment: "Comment",
275
+ commentMode: "Comment",
276
276
  commentPlaceholder: "Describe a change for the agent…",
277
- commentShortcutHint: "⌘/ to focus · ⌘↵ to add",
278
- addComment: "Add comment",
277
+ commentPost: "Post",
279
278
  unsavedChanges: {
280
279
  one: "{count} unsaved change",
281
280
  other: "{count} unsaved changes"
@@ -285,10 +284,14 @@ const en = {
285
284
  other: "{count} comments"
286
285
  },
287
286
  commentLineLabel: "line {n}",
288
- commentsEmpty: "No comments yet. Select an object and open Comment in the Format panel.",
287
+ commentRegionLabel: "region",
288
+ commentEmptyHint: "Click an element or drag across a region to leave a comment.",
289
289
  commentsApplyHintPrefix: "Run ",
290
290
  commentsApplyHintSuffix: " in your agent to apply these.",
291
291
  commentDeleteAria: "Delete",
292
+ commentUpdateFailed: "Couldn't update comment:",
293
+ commentAddFailed: "Couldn't add comment:",
294
+ commentRegionNoTarget: "Couldn't find an element to attach this region to.",
292
295
  saveFailed: "Couldn't save:",
293
296
  decreaseFontSize: "Decrease font size",
294
297
  increaseFontSize: "Increase font size"
@@ -790,10 +793,9 @@ const es = {
790
793
  cropFitCover: "Rellenar",
791
794
  cropFitContain: "Ajustar",
792
795
  cropApply: "Aplicar",
793
- leaveComment: "Comentar",
796
+ commentMode: "Comentar",
794
797
  commentPlaceholder: "Describe un cambio para el agente…",
795
- commentShortcutHint: "⌘/ para enfocar · ⌘↵ para añadir",
796
- addComment: "Añadir comentario",
798
+ commentPost: "Publicar",
797
799
  unsavedChanges: {
798
800
  one: "{count} cambio sin guardar",
799
801
  other: "{count} cambios sin guardar"
@@ -803,10 +805,14 @@ const es = {
803
805
  other: "{count} comentarios"
804
806
  },
805
807
  commentLineLabel: "línea {n}",
806
- commentsEmpty: "Aún no hay comentarios. Selecciona un objeto y abre Comentar en el panel de formato.",
808
+ commentRegionLabel: "zona",
809
+ commentEmptyHint: "Haz clic en un elemento o arrastra sobre una zona para dejar un comentario.",
807
810
  commentsApplyHintPrefix: "Ejecuta ",
808
811
  commentsApplyHintSuffix: " en tu agente para aplicarlos.",
809
812
  commentDeleteAria: "Eliminar",
813
+ commentUpdateFailed: "No se pudo actualizar el comentario:",
814
+ commentAddFailed: "No se pudo añadir el comentario:",
815
+ commentRegionNoTarget: "No se encontró un elemento al que asociar esta zona.",
810
816
  saveFailed: "No se pudo guardar:",
811
817
  decreaseFontSize: "Reducir tamaño de fuente",
812
818
  increaseFontSize: "Aumentar tamaño de fuente"
@@ -1308,10 +1314,9 @@ const ja = {
1308
1314
  agentWatchingTooltip: "選択中の要素はエージェントにリアルタイムで同期されています。",
1309
1315
  agentNotWatching: "エージェント未接続",
1310
1316
  agentNotWatchingTooltip: "dev server との接続が切れたため、選択中の要素がエージェントに見えなくなっています。dev server を再起動して接続を復旧してください。",
1311
- leaveComment: "コメント",
1317
+ commentMode: "コメント",
1312
1318
  commentPlaceholder: "エージェントに依頼する変更を記述…",
1313
- commentShortcutHint: "⌘/ でフォーカス · ⌘↵ で追加",
1314
- addComment: "コメントを追加",
1319
+ commentPost: "投稿",
1315
1320
  unsavedChanges: {
1316
1321
  one: "未保存の変更 {count} 件",
1317
1322
  other: "未保存の変更 {count} 件"
@@ -1321,10 +1326,14 @@ const ja = {
1321
1326
  other: "コメント {count} 件"
1322
1327
  },
1323
1328
  commentLineLabel: "行 {n}",
1324
- commentsEmpty: "まだコメントはありません。インスペクトを有効にしてスライド要素をクリックしてください。",
1329
+ commentRegionLabel: "範囲",
1330
+ commentEmptyHint: "要素をクリックするか、範囲をドラッグしてコメントを残せます。",
1325
1331
  commentsApplyHintPrefix: "エージェントで ",
1326
1332
  commentsApplyHintSuffix: " を実行して適用してください。",
1327
1333
  commentDeleteAria: "削除",
1334
+ commentUpdateFailed: "コメントを更新できませんでした:",
1335
+ commentAddFailed: "コメントを追加できませんでした:",
1336
+ commentRegionNoTarget: "この範囲を付けられる要素が見つかりませんでした。",
1328
1337
  saveFailed: "保存に失敗しました:",
1329
1338
  decreaseFontSize: "フォントサイズを縮小",
1330
1339
  increaseFontSize: "フォントサイズを拡大"
@@ -1826,10 +1835,9 @@ const zhCN = {
1826
1835
  agentWatchingTooltip: "选取的元素会即时同步给 agent。",
1827
1836
  agentNotWatching: "Agent 没在关注",
1828
1837
  agentNotWatchingTooltip: "已和 dev server 断开连接,agent 看不到你选的元素了。请重新启动 dev server 来恢复连接。",
1829
- leaveComment: "评论",
1838
+ commentMode: "评论",
1830
1839
  commentPlaceholder: "描述你希望代理执行的更改…",
1831
- commentShortcutHint: "⌘/ 聚焦 · ⌘↵ 添加",
1832
- addComment: "添加 comment",
1840
+ commentPost: "发送",
1833
1841
  unsavedChanges: {
1834
1842
  one: "{count} 项未保存的更改",
1835
1843
  other: "{count} 项未保存的更改"
@@ -1839,10 +1847,14 @@ const zhCN = {
1839
1847
  other: "{count} 条评论"
1840
1848
  },
1841
1849
  commentLineLabel: "第 {n} 行",
1842
- commentsEmpty: "还没有评论。选中对象后,在格式面板中打开“评论”。",
1850
+ commentRegionLabel: "区域",
1851
+ commentEmptyHint: "点击元素或拖拽框选一个区域来评论。",
1843
1852
  commentsApplyHintPrefix: "在你的代理中运行 ",
1844
1853
  commentsApplyHintSuffix: " 以应用这些更改。",
1845
1854
  commentDeleteAria: "删除",
1855
+ commentUpdateFailed: "无法更新评论:",
1856
+ commentAddFailed: "无法添加评论:",
1857
+ commentRegionNoTarget: "找不到可以附加该区域的元素。",
1846
1858
  saveFailed: "保存失败:",
1847
1859
  decreaseFontSize: "缩小字号",
1848
1860
  increaseFontSize: "放大字号"
@@ -2344,10 +2356,9 @@ const zhTW = {
2344
2356
  agentWatchingTooltip: "選取的元素會即時同步給 agent。",
2345
2357
  agentNotWatching: "Agent 沒在關注",
2346
2358
  agentNotWatchingTooltip: "已和 dev server 斷線,agent 看不到你選的元素了。請重新啟動 dev server 來恢復連線。",
2347
- leaveComment: "留言",
2359
+ commentMode: "留言",
2348
2360
  commentPlaceholder: "描述你希望代理進行的修改…",
2349
- commentShortcutHint: "⌘/ 聚焦 · ⌘↵ 新增",
2350
- addComment: "新增 comment",
2361
+ commentPost: "送出",
2351
2362
  unsavedChanges: {
2352
2363
  one: "{count} 項未儲存的變更",
2353
2364
  other: "{count} 項未儲存的變更"
@@ -2357,10 +2368,14 @@ const zhTW = {
2357
2368
  other: "{count} 則留言"
2358
2369
  },
2359
2370
  commentLineLabel: "第 {n} 行",
2360
- commentsEmpty: "還沒有留言。選取物件後,在格式面板中開啟「留言」。",
2371
+ commentRegionLabel: "範圍",
2372
+ commentEmptyHint: "點選元件或拖曳框選一個範圍來留言。",
2361
2373
  commentsApplyHintPrefix: "在你的代理中執行 ",
2362
2374
  commentsApplyHintSuffix: " 以套用這些變更。",
2363
2375
  commentDeleteAria: "刪除",
2376
+ commentUpdateFailed: "無法更新留言:",
2377
+ commentAddFailed: "無法新增留言:",
2378
+ commentRegionNoTarget: "找不到可以附加這個範圍的元件。",
2364
2379
  saveFailed: "儲存失敗:",
2365
2380
  decreaseFontSize: "縮小字級",
2366
2381
  increaseFontSize: "放大字級"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-slide/core",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Runtime and CLI for open-slide — write slides in slides/, we handle the rest.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -5,7 +5,7 @@ description: Apply pending @slide-comment markers written by the open-slide insp
5
5
 
6
6
  # Apply slide comments
7
7
 
8
- The open-slide editor has an inspector tool that lets the user click on a rendered page element and attach a textual comment (e.g. *"make this red"*, *"change to 'Open Slide Rocks'"*). Each comment is persisted as an in-source JSX marker inside `slides/<slideId>/index.tsx`.
8
+ The open-slide editor has a comment mode that lets the user click a rendered page element, or drag across a region of the page, and attach a textual comment (e.g. *"make this red"*, *"change to 'Open Slide Rocks'"*). Each comment is persisted as an in-source JSX marker inside `slides/<slideId>/index.tsx`.
9
9
 
10
10
  Your job: read those markers, perform the described edits, and delete the markers.
11
11
 
@@ -17,8 +17,10 @@ Your job: read those markers, perform the described edits, and delete the marker
17
17
  {/* @slide-comment id="c-<8hex>" ts="<ISO>" text="<base64url(JSON)>" */}
18
18
  ```
19
19
 
20
- - Always sits on its own line as the **first child inside** the JSX element it refers to (i.e. between that element's opening `>` and its other children). The marker is dropped *into* its target, not floated above it.
21
- - `text` is base64url-encoded JSON: `{"note": "...", "hint"?: "..."}`.
20
+ - Sits as the **first child inside** the JSX element it refers to (i.e. between that element's opening `>` and its other children). The marker is dropped *into* its target, not floated above it. Newly written markers get a line of their own; older ones may share a line with the content that follows them.
21
+ - `text` is base64url-encoded JSON: `{"note": "...", "hint"?: "...", "rect"?: {"x", "y", "w", "h"}, "page"?: n}`.
22
+ - `rect` is present when the comment was left on a dragged region rather than on an element. Values are pixels on the 1920×1080 page canvas, measured from the page's top-left corner. The marker still sits inside the deepest element that contains the region, but the note refers to what is *inside* that region — possibly several children, or only part of the enclosing element.
23
+ - `page` is the 0-based index (into the default export array) of the page the comment was left on.
22
24
  - Detection regex (authoritative — use exactly this):
23
25
 
24
26
  ```
@@ -33,13 +35,14 @@ Your job: read those markers, perform the described edits, and delete the marker
33
35
 
34
36
  2. **Read the file and find all markers.**
35
37
  - Run the regex above against the whole file.
36
- - For each match, base64url-decode `text` and `JSON.parse` it to get `{ note, hint? }`.
37
- - Record each hit as `{ id, lineIndex (0-based), note, hint }`.
38
+ - For each match, base64url-decode `text` and `JSON.parse` it to get `{ note, hint?, rect?, page? }`.
39
+ - Record each hit as `{ id, lineIndex (0-based), note, hint, rect, page }`.
38
40
  - If there are no markers, tell the user and stop.
39
41
 
40
42
  3. **Understand each comment in context.**
41
43
  - The targeted JSX element is the **enclosing** element of the marker — i.e. read upward from the marker line until you reach the unclosed JSX opening tag whose body the marker lives in. That element is the target. (For self-closing elements like `<img />`, the inspector hoists the marker to the nearest non-self-closing ancestor; in that case the comment usually refers to a child of the enclosing element rather than the enclosing element itself — use the `note` text to disambiguate.)
42
44
  - Read enough surrounding code (parent element, sibling elements, inline styles) to apply the change faithfully. A comment inside a `<div>` with an inline `background` style usually refers to that element's styling, for example.
45
+ - When the payload has a `rect`, work out which children of the enclosing element fall inside that region (compare their positions and sizes against the rect on the 1920×1080 canvas) and apply the note to those — not to the whole enclosing element.
43
46
  - If the `note` is ambiguous, do the smallest reasonable interpretation and mention the assumption in your summary.
44
47
 
45
48
  4. **Apply edits in reverse line order.**
@@ -47,7 +50,7 @@ Your job: read those markers, perform the described edits, and delete the marker
47
50
  - Processing top-down would invalidate line numbers for later markers as the file shrinks/grows.
48
51
 
49
52
  5. **Remove each marker after applying its edit.**
50
- - Delete the entire marker line including its trailing `\n`.
53
+ - Delete the marker token. If nothing else is left on that line, delete the whole line including its trailing `\n`; if content shares the line, keep that content.
51
54
  - Never leave a marker behind for an edit you applied — that signals a failure. Markers deliberately skipped per the edge cases below stay in place.
52
55
 
53
56
  6. **Verify.**
@@ -1,4 +1,4 @@
1
- export function IconSwitcherIndicator({ index }: { index: 0 | 1 }) {
1
+ export function IconSwitcherIndicator({ index }: { index: number }) {
2
2
  return (
3
3
  <span
4
4
  aria-hidden