@inkbar/core 0.2.0 → 0.3.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-BftlPZKU.d.mts","names":[],"sources":["../src/model/geometry.ts","../src/pdfjs/types.ts","../src/model/pages.ts","../src/model/readable.ts","../src/model/annotations/types.ts","../src/model/annotations/defaults.ts","../src/model/annotations/embedded.ts","../src/model/annotations/store.ts","../src/model/annotations/history.ts","../src/model/annotations/json.ts","../src/model/errors.ts","../src/model/source.ts","../src/model/text.ts","../src/model/document.ts"],"mappings":";;;;;;;UAIiB;EACf;EACA;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;EACf,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;;;KAIM;iBAEI,YAAY,WAAW,WAAW;iBAIlC,eAAe,GAAG,OAAO,GAAG,QAAQ;iBAMpC,aAAa,GAAG,OAAO;iBAQvB,aAAa,GAAG,OAAO;iBAWvB,WAAW,gBAAgB,SAAS;iBAepC,eAAe,GAAG,MAAM,GAAG;iBAS3B,kBAAkB,GAAG,MAAM,GAAG;iBAI9B,cAAc,GAAG,MAAM,YAAY,aAAa;iBAIhD,cAAc,GAAG,MAAM,YAAY,aAAa;iBAKhD,YAAY,GAAG,QAAQ,GAAG,QAAQ;iBAIlC,aAAa,GAAG,SAAS;;iBAczB,eAAe,GAAG,QAAQ,GAAG,SAAS;iBAWtC,eAAe,MAAM,oBAAoB;;iBAOzC,cAAc,MAAM,oBAAoB;;;KChI5C,qBAAqB;KAErB,gBAAgB,MAAM;KACtB,YAAY,MAAM;;UAOb;EACf;EACA;EACA;EACA;EACA,aAAa;EACb,QAAQ;EACR,gBAAgB;EAChB;EACA;IAAgB;IAAa;;EAC7B;IAAa;IAAa;;EAC1B;EACA;EACA;EACA;EACA;EACA;IAAgB;;EAChB;EACA,WAAW;EACX,WAAW,MAAM;EACjB;;EAEA;EACA;IACE;IACA;I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;;WAEb,mBAAmB;WACnB,SAAS;;EAElB,kBAAkB,iBAAiB;;EAEnC,kBAAkB,MAAM,6BAA6B,OAAO,gBAAgB;;EAE5E,QAAQ,QAAQ;EAChB;;WAES;IACP,QAAQ;IACR,OAAO;IACP,QAAQ,gBAAgB,QAAQ;;;;;;;;iBAed,aACpB,QAAQ,gBACR,SAAS,cACR,QAAQ"}
package/dist/dom.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as NoteAnnotation, Ct as Matrix, Et as Rect, L as Annotation, M as cssVariableDefaults, St as PdfAssets, Tt as Quad, W as ConfidenceBucket, a as OpenOptions, b as AnnotationStore, bt as PageInfo, ht as Readable, i as InkStatus, j as AnnotationDefaults, l as DocumentSource, ot as RedactAnnotation, r as InkDocument, u as InkError, ut as Suggestion, wt as Point } from "./document-Cywnv8Sz.mjs";
1
+ import { Dt as Quad, Et as Point, L as Annotation, M as cssVariableDefaults, Ot as Rect, St as PageInfo, Tt as Matrix, W as ConfidenceBucket, _t as Readable, a as OpenOptions, b as AnnotationStore, ct as RedactAnnotation, ft as Suggestion, i as InkStatus, j as AnnotationDefaults, l as DocumentSource, r as InkDocument, tt as NoteAnnotation, u as InkError, wt as PdfAssets } from "./document-BftlPZKU.mjs";
2
2
  import { IconNode } from "@inkbar/icons";
3
3
  //#region src/dom/transform.d.ts
4
4
  type ViewRotation = 0 | 90 | 180 | 270;
package/dist/dom.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { B as mergeLineRects, F as confidenceBucket, H as readonly, K as invertMatrix, L as cssVariableDefaults, Q as rectFromPoints, U as writable, W as applyMatrix, a as acceptSuggestion, at as InkError, et as rectsIntersect, i as threadRoot, nt as translateRect, o as openDocument, ot as isInkError, r as threadOf, t as isAbandonedNote, tt as translateQuad } from "./threads-BtvtrAhL.mjs";
1
+ import { $ as rectFromPoints, G as applyMatrix, I as confidenceBucket, R as cssVariableDefaults, U as readonly, V as mergeLineRects, W as writable, a as acceptSuggestion, i as threadRoot, nt as translateQuad, o as openDocument, ot as InkError, q as invertMatrix, r as threadOf, rt as translateRect, st as isInkError, t as isAbandonedNote, tt as rectsIntersect } from "./threads-2USvyGpX.mjs";
2
2
  import { ChevronLeft, ChevronRight, Hand, Highlighter, ICON_ATTRIBUTES, MessageSquare, MousePointer2, Redo2, Square, Undo2, ZoomIn, ZoomOut } from "@inkbar/icons";
3
3
  //#region src/dom/transform.ts
4
4
  /** Folds any integer multiple of 90 onto 0, 90, 180 or 270. Throws `RangeError` otherwise. */
@@ -925,7 +925,7 @@ function translated(a, dx, dy) {
925
925
  case "polygon":
926
926
  patch.vertices = a.vertices.map((p) => shift(p, dx, dy));
927
927
  break;
928
- case "ink": patch.paths = a.paths.map((path) => path.map((p) => shift(p, dx, dy)));
928
+ case "ink": patch.inklist = a.inklist.map((path) => path.map((p) => shift(p, dx, dy)));
929
929
  }
930
930
  return patch;
931
931
  }
@@ -937,7 +937,7 @@ function translated(a, dx, dy) {
937
937
  function hasRectGeometry(a) {
938
938
  switch (a.type) {
939
939
  case "redact": return a.quads === void 0 || a.quads.length === 0;
940
- case "freeText":
940
+ case "freetext":
941
941
  case "square":
942
942
  case "circle": return true;
943
943
  default: return false;
@@ -971,10 +971,10 @@ const SVG$1 = "http://www.w3.org/2000/svg";
971
971
  * `toCssRect(a.rect)`.
972
972
  */
973
973
  function annotationBox(a, t) {
974
- const points = a.type === "line" ? [a.start, a.end] : a.type === "polyline" || a.type === "polygon" ? a.vertices : a.type === "ink" ? a.paths.flat() : void 0;
975
- if (!points || points.length === 0 || !("strokeWidth" in a)) return t.toCssRect(a.rect);
974
+ const points = a.type === "line" ? [a.start, a.end] : a.type === "polyline" || a.type === "polygon" ? a.vertices : a.type === "ink" ? a.inklist.flat() : void 0;
975
+ if (!points || points.length === 0 || !("width" in a)) return t.toCssRect(a.rect);
976
976
  const box = t.toCssRect(pointBounds(points));
977
- const pad = Math.max(t.toCssLength(a.strokeWidth), 1) / 2;
977
+ const pad = Math.max(t.toCssLength(a.width), 1) / 2;
978
978
  return {
979
979
  left: box.left - pad,
980
980
  top: box.top - pad,
@@ -1012,7 +1012,7 @@ function renderAnnotationContent(el, a, t) {
1012
1012
  for (const [k, v] of Object.entries(attrs)) n.setAttribute(k, String(v));
1013
1013
  return n;
1014
1014
  };
1015
- if (a.type === "note") {
1015
+ if (a.type === "text") {
1016
1016
  const svg = boxSvg(doc, box.width, box.height);
1017
1017
  const hit = node("rect", {
1018
1018
  x: 0,
@@ -1031,10 +1031,10 @@ function renderAnnotationContent(el, a, t) {
1031
1031
  el.append(svg, icon);
1032
1032
  return;
1033
1033
  }
1034
- if (a.type === "freeText") {
1034
+ if (a.type === "freetext") {
1035
1035
  const text = doc.createElement("div");
1036
1036
  text.className = "ink-free-text";
1037
- text.textContent = a.text;
1037
+ text.textContent = a.contents;
1038
1038
  text.dataset.align = a.align;
1039
1039
  text.style.setProperty("--ink-font-size", `${t.toCssLength(a.fontSize)}px`);
1040
1040
  text.style.setProperty("--ink-text-color", a.color);
@@ -1076,7 +1076,7 @@ function renderAnnotationContent(el, a, t) {
1076
1076
  height: box.height
1077
1077
  })];
1078
1078
  for (const s of shapes) {
1079
- s.setAttribute("fill", a.fill);
1079
+ s.setAttribute("fill", a.interiorColor);
1080
1080
  s.setAttribute("fill-opacity", "0.15");
1081
1081
  s.setAttribute("stroke", a.color);
1082
1082
  s.setAttribute("stroke-width", String(t.toCssLength(1)));
@@ -1087,7 +1087,7 @@ function renderAnnotationContent(el, a, t) {
1087
1087
  }
1088
1088
  case "square":
1089
1089
  case "circle": {
1090
- const sw = t.toCssLength(a.strokeWidth);
1090
+ const sw = t.toCssLength(a.width);
1091
1091
  const shape = a.type === "square" ? node("rect", {
1092
1092
  x: sw / 2,
1093
1093
  y: sw / 2,
@@ -1099,7 +1099,7 @@ function renderAnnotationContent(el, a, t) {
1099
1099
  rx: Math.max(0, box.width / 2 - sw / 2),
1100
1100
  ry: Math.max(0, box.height / 2 - sw / 2)
1101
1101
  });
1102
- shape.setAttribute("fill", a.fill ?? "none");
1102
+ shape.setAttribute("fill", a.interiorColor ?? "none");
1103
1103
  shape.setAttribute("stroke", a.color);
1104
1104
  shape.setAttribute("stroke-width", String(sw));
1105
1105
  svg.append(shape);
@@ -1112,20 +1112,20 @@ function renderAnnotationContent(el, a, t) {
1112
1112
  const pts = a.type === "line" ? [a.start, a.end] : a.vertices;
1113
1113
  svg.append(node(a.type === "polygon" ? "polygon" : "polyline", {
1114
1114
  points: pts.map(local).join(" "),
1115
- fill: a.type === "polygon" ? a.fill ?? "none" : "none",
1115
+ fill: a.type === "polygon" ? a.interiorColor ?? "none" : "none",
1116
1116
  stroke: a.color,
1117
- "stroke-width": t.toCssLength(a.strokeWidth),
1117
+ "stroke-width": t.toCssLength(a.width),
1118
1118
  "stroke-linejoin": "round"
1119
1119
  }));
1120
1120
  svg.setAttribute("opacity", String(a.opacity));
1121
1121
  break;
1122
1122
  }
1123
1123
  case "ink":
1124
- for (const path of a.paths) svg.append(node("polyline", {
1124
+ for (const path of a.inklist) svg.append(node("polyline", {
1125
1125
  points: path.map(local).join(" "),
1126
1126
  fill: "none",
1127
1127
  stroke: a.color,
1128
- "stroke-width": t.toCssLength(a.strokeWidth),
1128
+ "stroke-width": t.toCssLength(a.width),
1129
1129
  "stroke-linecap": "round",
1130
1130
  "stroke-linejoin": "round"
1131
1131
  }));
@@ -1258,8 +1258,8 @@ const LABELS = {
1258
1258
  underline: "Underline",
1259
1259
  strikeout: "Strikeout",
1260
1260
  squiggly: "Squiggly underline",
1261
- note: "Note",
1262
- freeText: "Text box",
1261
+ text: "Note",
1262
+ freetext: "Text box",
1263
1263
  square: "Rectangle",
1264
1264
  circle: "Ellipse",
1265
1265
  line: "Line",
@@ -1790,7 +1790,7 @@ function noteTool() {
1790
1790
  let down;
1791
1791
  const place = (c, page, at) => {
1792
1792
  const a = c.store.add({
1793
- type: "note",
1793
+ type: "text",
1794
1794
  page,
1795
1795
  rect: {
1796
1796
  x: at.x - SIZE / 2,
@@ -2655,13 +2655,13 @@ function createNotePopover(opts) {
2655
2655
  const dropped = /* @__PURE__ */ new Set();
2656
2656
  function shown() {
2657
2657
  const a = current ? store.get(current) : void 0;
2658
- return a?.type === "note" ? a : null;
2658
+ return a?.type === "text" ? a : null;
2659
2659
  }
2660
2660
  function target() {
2661
2661
  const list = store.list.get();
2662
2662
  const id = activated.get();
2663
2663
  const a = id === null ? void 0 : list.find((x) => x.id === id);
2664
- return a?.type === "note" ? threadRoot(list, a) : null;
2664
+ return a?.type === "text" ? threadRoot(list, a) : null;
2665
2665
  }
2666
2666
  const editingRoot = (n) => !n.locked && !n.contents?.trim();
2667
2667
  function isEmptyRoot(n) {
@@ -2717,7 +2717,7 @@ function createNotePopover(opts) {
2717
2717
  written.add(n.id);
2718
2718
  if (editingRoot(n)) store.update(n.id, { contents: text });
2719
2719
  else store.add({
2720
- type: "note",
2720
+ type: "text",
2721
2721
  page: n.page,
2722
2722
  rect: n.rect,
2723
2723
  contents: text,