ducjs 3.5.0 → 3.5.1

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.
Binary file
@@ -82,7 +82,7 @@ const restoreElementWithProperties = (element, extra, localState, globalState) =
82
82
  return Object.assign(Object.assign(Object.assign(Object.assign({}, _element), base), normalized), { type: _element.type });
83
83
  };
84
84
  const restoreElement = (element, currentScope, restoredBlocks, localState, globalState) => {
85
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
85
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
86
86
  // Migration: convert deprecated 'diamond' to 'polygon' with 4 sides
87
87
  if (element.type === "diamond") {
88
88
  const migrated = Object.assign(Object.assign({}, element), { type: "polygon", sides: 4 });
@@ -322,10 +322,28 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
322
322
  }
323
323
  case "doc": {
324
324
  const docElement = element;
325
+ // Migration: old format stored the compiled PDF on fileId and the Typst
326
+ // source in referencedFileIds. New format stores the Typst source on
327
+ // fileId and the PDF cache in referencedFileIds with a doc_pdf_cache_ prefix.
328
+ let migratedFileId = isValidString(docElement.fileId) || null;
329
+ let migratedReferencedFileIds = (_l = docElement.referencedFileIds) !== null && _l !== void 0 ? _l : [];
330
+ if (migratedFileId && typeof migratedFileId === "string" && migratedFileId.startsWith("doc_pdf_")) {
331
+ const typstSourceId = migratedReferencedFileIds.find((rid) => typeof rid === "string" && rid.startsWith("doc_typst_source_"));
332
+ if (typstSourceId) {
333
+ // Move old PDF cache to referencedFileIds with new prefix
334
+ const elementId = (_m = docElement.id) !== null && _m !== void 0 ? _m : "";
335
+ const newCacheId = `doc_pdf_cache_${elementId}`;
336
+ migratedReferencedFileIds = migratedReferencedFileIds.filter((rid) => rid !== typstSourceId);
337
+ if (!migratedReferencedFileIds.includes(newCacheId)) {
338
+ migratedReferencedFileIds = [...migratedReferencedFileIds, newCacheId];
339
+ }
340
+ migratedFileId = typstSourceId;
341
+ }
342
+ }
325
343
  return restoreElementWithProperties(element, {
326
344
  text: isValidString(docElement.text),
327
- fileId: isValidString(docElement.fileId) || null,
328
- referencedFileIds: docElement.referencedFileIds || [],
345
+ fileId: migratedFileId,
346
+ referencedFileIds: migratedReferencedFileIds,
329
347
  gridConfig: restoreDocumentGridConfig(docElement.gridConfig),
330
348
  }, localState);
331
349
  }
@@ -1,12 +1,13 @@
1
1
  import type { ElementOrToolType } from "..";
2
2
  import { Bounds, LineSegment, TuplePoint } from "../geometry.types";
3
3
  import type { MarkNonNullable } from "../utility.types";
4
- import type { DucArrowElement, DucBindableElement, DucDocElement, DucElbowArrowElement, DucElement, DucElementType, DucEllipseElement, DucEmbeddableElement, DucFlowchartNodeElement, DucFrameElement, DucFrameLikeElement, DucFreeDrawElement, DucIframeLikeElement, DucImageElement, DucLinearElement, DucNonSelectionElement, DucPdfElement, DucPlotElement, DucPointBinding, DucPolygonElement, DucTableElement, DucTextContainer, DucTextElement, DucTextElementWithContainer, FixedPointBinding, InitializedDucImageElement, NonDeleted } from "./";
4
+ import type { DucArrowElement, DucBindableElement, DucDocElement, DucElbowArrowElement, DucElement, DucElementType, DucEllipseElement, DucEmbeddableElement, DucFlowchartNodeElement, DucFrameElement, DucFrameLikeElement, DucFreeDrawElement, DucIframeLikeElement, DucImageElement, DucLinearElement, DucNonSelectionElement, DucPdfElement, DucPlotElement, DucPointBinding, DucPolygonElement, DucTableElement, DucTextContainer, DucTextElement, DucTextElementWithContainer, ExternalFileId, FixedPointBinding, InitializedDucImageElement, NonDeleted } from "./";
5
5
  export declare const isInitializedImageElement: (element: DucElement | null) => element is InitializedDucImageElement;
6
6
  export declare const isImageElement: (element: DucElement | null) => element is DucImageElement;
7
7
  export declare const isPdfElement: (element: DucElement | null) => element is DucPdfElement;
8
8
  export type DucPdfLikeElement = DucPdfElement | DucDocElement;
9
9
  export declare const isPdfLikeElement: (element: DucElement | null) => element is DucPdfLikeElement;
10
+ export declare const getRenderablePdfFileId: (element: DucElement) => ExternalFileId | null;
10
11
  export declare const isEmbeddableElement: (element: DucElement | null | undefined) => element is DucEmbeddableElement;
11
12
  export declare const isTableElement: (element: DucElement | null) => element is DucTableElement;
12
13
  export declare const isIframeLikeElement: (element: DucElement | null) => element is DucIframeLikeElement;
@@ -11,6 +11,32 @@ export const isPdfElement = (element) => {
11
11
  export const isPdfLikeElement = (element) => {
12
12
  return !!element && (element.type === "pdf" || element.type === "doc");
13
13
  };
14
+ /**
15
+ * Resolves the file ID used for rendering a PDF-like element.
16
+ *
17
+ * For `pdf` elements, this is simply `element.fileId`.
18
+ * For `doc` elements, the `fileId` holds the Typst source file, and the
19
+ * compiled PDF cache is stored in `referencedFileIds` with a
20
+ * `doc_pdf_cache_` prefix. This function returns that cache file ID, or
21
+ * falls back to `element.fileId` for backward compatibility with older
22
+ * drawings where `fileId` was the PDF itself.
23
+ */
24
+ const DOC_PDF_CACHE_FILE_ID_PREFIX = "doc_pdf_cache_";
25
+ export const getRenderablePdfFileId = (element) => {
26
+ var _a;
27
+ if (element.type === "pdf") {
28
+ return element.fileId;
29
+ }
30
+ if (element.type === "doc") {
31
+ const cacheId = `${DOC_PDF_CACHE_FILE_ID_PREFIX}${element.id}`;
32
+ if ((_a = element.referencedFileIds) === null || _a === void 0 ? void 0 : _a.includes(cacheId)) {
33
+ return cacheId;
34
+ }
35
+ // Fallback for legacy drawings where fileId was the PDF
36
+ return element.fileId;
37
+ }
38
+ return null;
39
+ };
14
40
  export const isEmbeddableElement = (element) => {
15
41
  return !!element && element.type === "embeddable";
16
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ducjs",
3
- "version": "3.5.0",
3
+ "version": "3.5.1",
4
4
  "description": "The duc 2D CAD file format is a cornerstone of our advanced design system, conceived to cater to professionals seeking precision and efficiency in their design work.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",