@stll/folio-core 0.74.0 → 0.75.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 (113) hide show
  1. package/dist/ai-edits/clean-text.d.ts +4 -1
  2. package/dist/ai-edits/clean-text.js +21 -7
  3. package/dist/ai-edits/headless.d.ts +5 -2
  4. package/dist/ai-edits/headless.js +18 -9
  5. package/dist/ai-edits/note-references.d.ts +1 -1
  6. package/dist/ai-edits/note-references.js +1 -1
  7. package/dist/ai-edits/pending-suggestions.d.ts +9 -7
  8. package/dist/ai-edits/pending-suggestions.js +134 -88
  9. package/dist/ai-edits/pendingJoin.d.ts +5 -1
  10. package/dist/ai-edits/pendingJoin.js +6 -2
  11. package/dist/ai-edits/retired-comment-receipts.d.ts +2 -2
  12. package/dist/ai-edits/retired-comment-receipts.js +3 -18
  13. package/dist/ai-edits/tracked-batch-fidelity.d.ts +6 -10
  14. package/dist/ai-edits/tracked-batch-fidelity.js +3 -182
  15. package/dist/canonical/canonicalBatchReview.d.ts +4 -1
  16. package/dist/canonical/canonicalBatchReview.js +32 -14
  17. package/dist/canonical/canonicalComments.d.ts +6 -2
  18. package/dist/canonical/canonicalComments.js +8 -4
  19. package/dist/canonical/canonicalPublicOperations.js +29 -9
  20. package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
  21. package/dist/canonical/canonicalRefusalGrounds.js +56 -0
  22. package/dist/canonical/canonicalSession.d.ts +12 -6
  23. package/dist/canonical/canonicalSession.js +116 -121
  24. package/dist/canonical/canonicalTrackedBatchFidelity.js +3 -3
  25. package/dist/compare/inline-atoms.d.ts +35 -41
  26. package/dist/compare/inline-atoms.js +2 -465
  27. package/dist/compare/section-boundary-properties.d.ts +3 -30
  28. package/dist/compare/section-boundary-properties.js +4 -72
  29. package/dist/controller/canonicalClipboard.js +43 -42
  30. package/dist/controller/canonicalComposition.d.ts +1 -1
  31. package/dist/controller/canonicalComposition.js +5 -5
  32. package/dist/controller/canonicalInput.d.ts +4 -2
  33. package/dist/controller/canonicalInput.js +33 -16
  34. package/dist/controller/canonicalStoryEditor.d.ts +2 -3
  35. package/dist/controller/canonicalStoryEditor.js +43 -25
  36. package/dist/controller/canonicalStructure.d.ts +19 -2
  37. package/dist/controller/canonicalStructure.js +139 -42
  38. package/dist/controller/deferredDisplayListPainter.d.ts +8 -0
  39. package/dist/controller/deferredDisplayListPainter.js +34 -0
  40. package/dist/controller/folioEditor.js +4 -2
  41. package/dist/controller/headerFooterEditorManager.js +3 -17
  42. package/dist/controller/hiddenEditorApi.d.ts +24 -3
  43. package/dist/controller/hiddenEditorApi.js +2 -0
  44. package/dist/controller/hiddenEditorManager.js +132 -189
  45. package/dist/controller/layoutPipeline.d.ts +4 -86
  46. package/dist/controller/layoutPipeline.js +8 -727
  47. package/dist/controller/layoutPipelineExecution.d.ts +94 -0
  48. package/dist/controller/layoutPipelineExecution.js +730 -0
  49. package/dist/controller/noteEditorManager.js +3 -16
  50. package/dist/docx/blockContentParser.d.ts +1 -3
  51. package/dist/docx/blockContentParser.js +3 -10
  52. package/dist/docx/canonicalSave.d.ts +4 -3
  53. package/dist/docx/canonicalSave.js +4 -3
  54. package/dist/docx/listMarkerComputation.d.ts +24 -17
  55. package/dist/docx/listMarkerComputation.js +31 -60
  56. package/dist/docx/listModelNormalization.js +8 -15
  57. package/dist/docx/rezip.d.ts +16 -3
  58. package/dist/docx/rezip.js +35 -9
  59. package/dist/docx/selectiveSave.js +13 -5
  60. package/dist/docx/server/templatePlan/apply.js +38 -3
  61. package/dist/docx/server/templatePlan/blocks.d.ts +16 -1
  62. package/dist/docx/server/templatePlan/blocks.js +93 -7
  63. package/dist/docx/server/templatePlan/builders.d.ts +37 -2
  64. package/dist/docx/server/templatePlan/builders.js +196 -5
  65. package/dist/docx/server/templatePlan/emit.d.ts +2 -0
  66. package/dist/docx/server/templatePlan/emit.js +2 -0
  67. package/dist/docx/server/templatePlan/inspect.js +19 -52
  68. package/dist/docx/server/templatePlan/labels.d.ts +7 -2
  69. package/dist/docx/server/templatePlan/labels.js +104 -22
  70. package/dist/docx/server/templatePlan/plan.d.ts +13 -1
  71. package/dist/docx/server/templatePlan/plan.js +22 -7
  72. package/dist/docx/server/templatePlan/planShape.js +31 -2
  73. package/dist/docx/server/templatePlan/story.d.ts +8 -0
  74. package/dist/docx/server/templatePlan/story.js +11 -1
  75. package/dist/docx/server/templatePlan/types.d.ts +138 -16
  76. package/dist/docx/server/templatePlan/verify.js +50 -9
  77. package/dist/i18n/messages/ar.gen.js +1 -0
  78. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  79. package/dist/i18n/messages/catalogs.gen.js +17 -0
  80. package/dist/i18n/messages/cs.gen.js +1 -0
  81. package/dist/i18n/messages/de.gen.js +1 -0
  82. package/dist/i18n/messages/en.gen.js +1 -0
  83. package/dist/i18n/messages/es.gen.js +1 -0
  84. package/dist/i18n/messages/et.gen.js +1 -0
  85. package/dist/i18n/messages/fr.gen.js +1 -0
  86. package/dist/i18n/messages/he.gen.js +1 -0
  87. package/dist/i18n/messages/hi.gen.js +1 -0
  88. package/dist/i18n/messages/hu.gen.js +1 -0
  89. package/dist/i18n/messages/lt.gen.js +1 -0
  90. package/dist/i18n/messages/lv.gen.js +1 -0
  91. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  92. package/dist/i18n/messages/pl.gen.js +1 -0
  93. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  94. package/dist/i18n/messages/sk.gen.js +1 -0
  95. package/dist/i18n/messages/tr.gen.js +1 -0
  96. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  97. package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
  98. package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
  99. package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
  100. package/dist/prosemirror/listMarker.d.ts +1 -6
  101. package/dist/prosemirror/listMarker.js +4 -56
  102. package/dist/server.d.ts +2 -2
  103. package/dist/types/canonicalCapabilities.d.ts +40 -45
  104. package/dist/types/canonicalCapabilities.js +51 -43
  105. package/dist/types/canonicalComments.d.ts +2 -2
  106. package/dist/types/canonicalSections.d.ts +2 -2
  107. package/dist/utils/clipboard.d.ts +2 -28
  108. package/dist/utils/clipboard.js +1 -96
  109. package/dist/utils/clipboardFiles.d.ts +27 -0
  110. package/dist/utils/clipboardFiles.js +98 -0
  111. package/dist/utils/rulerControl.d.ts +1 -0
  112. package/dist/utils/rulerControl.js +2 -1
  113. package/package.json +2 -2
@@ -1,15 +1,10 @@
1
1
  // src/types/canonicalCapabilities.ts
2
2
  /** Remaining seams to retire before the canonical session becomes the only authority. */
3
3
  const CANONICAL_GAP = {
4
- authorityRouting: "authority-routing",
5
4
  commands: "command-descriptors",
6
5
  trackedTableStructure: "tracked-table-structure",
7
6
  storyContentProjection: "story-content-projection",
8
- comments: "comment-model-edits",
9
- modelEdits: "direct-model-edits",
10
- sectionProperties: "section-properties",
11
- dispatch: "unclassified-transactions",
12
- saveSerialization: "save-serialization",
7
+ trackedChangeRecords: "tracked-change-records",
13
8
  publicComments: "publicOps.comments",
14
9
  publicUnsupportedInline: "publicOps.unsupportedInline",
15
10
  commentReplacementAlignment: "comment-replacement-alignment",
@@ -36,24 +31,61 @@ const CANONICAL_RULE_MESSAGE_KEYS = {
36
31
  linkSuggestionShape: "editor.linkSuggestionUnavailable"
37
32
  };
38
33
  /**
34
+ * Conditions of the session or of the request, not of the document: the
35
+ * session holds the capability, but cannot make this change now or was not
36
+ * asked for one it can make. A refusal under one is correct and is never a gap
37
+ * to retire.
38
+ */
39
+ const CANONICAL_CONDITION = {
40
+ /** No session holds a document yet, or the editor showing it has closed. */
41
+ notReady: "notReady",
42
+ /** The editor is read-only. */
43
+ notEditable: "notEditable",
44
+ /** An input composition must finish first. */
45
+ composing: "composing",
46
+ /**
47
+ * The request names nothing in the document or describes no change the
48
+ * document allows, such as a reply to a missing comment.
49
+ */
50
+ invalidRequest: "invalidRequest",
51
+ /** No id is left to mint, in the document or in this author's lease. */
52
+ idSpace: "idSpace",
53
+ /** The projection, version or lease the change was prepared against moved on. */
54
+ stale: "stale",
55
+ /**
56
+ * A plugin or raw dispatch changed the document outside document
57
+ * operations; hosts express edits through `applyDocumentOperations`.
58
+ */
59
+ hostTransaction: "hostTransaction",
60
+ /**
61
+ * The session failed to project or stage the change: a defect to report,
62
+ * not a missing capability.
63
+ */
64
+ internal: "internal"
65
+ };
66
+ /**
39
67
  * The editor message, in the folio catalog, a host shows for a refusal under
40
68
  * any gap: the change cannot be made here yet.
41
69
  */
42
70
  const CANONICAL_GAP_MESSAGE_KEY = "editor.changeUnavailable";
43
71
  /**
72
+ * The editor message, in the folio catalog, a host shows for a refusal under
73
+ * any condition: the change was not made.
74
+ */
75
+ const CANONICAL_CONDITION_MESSAGE_KEY = "editor.changeNotApplied";
76
+ /**
44
77
  * What a host shows for a refusal, always from the folio catalog, which the
45
78
  * host translates: the editor's own message for a rule the document states,
46
- * and that the change cannot be made here yet for a gap. The session's own
47
- * message describes the refusal for logs and `onError`, never for the user.
79
+ * that the change was not made for a condition, and that the change cannot be
80
+ * made here yet for a gap. The session's own message describes the refusal
81
+ * for logs and `onError`, never for the user.
48
82
  */
49
- const canonicalRefusalNotice = (ground, translate) => translate(ground.rule === void 0 ? CANONICAL_GAP_MESSAGE_KEY : CANONICAL_RULE_MESSAGE_KEYS[ground.rule]);
83
+ const canonicalRefusalNotice = (ground, translate) => {
84
+ if (ground.rule !== void 0) return translate(CANONICAL_RULE_MESSAGE_KEYS[ground.rule]);
85
+ if (ground.condition !== void 0) return translate(CANONICAL_CONDITION_MESSAGE_KEY);
86
+ return translate(CANONICAL_GAP_MESSAGE_KEY);
87
+ };
50
88
  const CANONICAL_CAPABILITIES = {
51
- [CANONICAL_GAP.authorityRouting]: {
52
- owner: "controller",
53
- kind: "routing",
54
- adapters: ["react", "vue"],
55
- summary: "Explicit session selection and legacy authority routing."
56
- },
57
89
  [CANONICAL_GAP.commands]: {
58
90
  remainingCommands: { registry: "extension-commands" },
59
91
  owner: "controller",
@@ -73,35 +105,11 @@ const CANONICAL_CAPABILITIES = {
73
105
  adapters: ["react", "vue"],
74
106
  summary: "Unsupported inline, field and review content cannot be projected after canonical edits; pasted embedded blocks, comment and note references copied outside the editor, and compositions over such content refuse."
75
107
  },
76
- [CANONICAL_GAP.comments]: {
77
- owner: "adapters",
78
- kind: "routing",
79
- adapters: ["react", "vue"],
80
- summary: "Legacy sessions retain comment model edits; canonical comments use semantic operations."
81
- },
82
- [CANONICAL_GAP.modelEdits]: {
83
- owner: "adapters",
84
- kind: "refusal",
85
- adapters: ["react", "vue"],
86
- summary: "Direct model and pending-suggestion snapshots bypass the canonical journal."
87
- },
88
- [CANONICAL_GAP.sectionProperties]: {
89
- owner: "controller",
90
- kind: "routing",
91
- adapters: ["react", "vue"],
92
- summary: "The shared controller journals section properties; legacy sessions keep model changes."
93
- },
94
- [CANONICAL_GAP.dispatch]: {
95
- owner: "controller",
96
- kind: "refusal",
97
- adapters: ["react", "vue"],
98
- summary: "A host plugin or raw dispatch that changes the document is refused, naming the transaction's meta keys; hosts express edits as document operations (applyDocumentOperations)."
99
- },
100
- [CANONICAL_GAP.saveSerialization]: {
101
- owner: "controller",
108
+ [CANONICAL_GAP.trackedChangeRecords]: {
109
+ owner: "document-operations",
102
110
  kind: "refusal",
103
111
  adapters: ["react", "vue"],
104
- summary: "Canonical save waits for composition to finish and reports package serialization refusals and fidelity fallbacks."
112
+ summary: "A suggested change whose content the tracked-change records cannot express is refused: comment boundaries in a tracked range, paragraph-mark run properties, a join at a section break, a record inside a field."
105
113
  },
106
114
  [CANONICAL_GAP.publicComments]: {
107
115
  owner: "document-operations",
@@ -129,4 +137,4 @@ const CANONICAL_CAPABILITIES = {
129
137
  }
130
138
  };
131
139
  const canonicalRefusalMessage = (gap, message) => `[${gap}] ${message}`;
132
- export { CANONICAL_CAPABILITIES, CANONICAL_GAP, CANONICAL_GAP_MESSAGE_KEY, CANONICAL_RULE, CANONICAL_RULE_MESSAGE_KEYS, canonicalRefusalMessage, canonicalRefusalNotice };
140
+ export { CANONICAL_CAPABILITIES, CANONICAL_CONDITION, CANONICAL_CONDITION_MESSAGE_KEY, CANONICAL_GAP, CANONICAL_GAP_MESSAGE_KEY, CANONICAL_RULE, CANONICAL_RULE_MESSAGE_KEYS, canonicalRefusalMessage, canonicalRefusalNotice };
@@ -1,4 +1,4 @@
1
- import { CanonicalGap } from "./canonicalCapabilities.js";
1
+ import { CanonicalRefusalGround } from "./canonicalCapabilities.js";
2
2
  import { Comment } from "./content.js";
3
3
  import { OpStory } from "@stll/docx-core/ops";
4
4
  /** Requests name their anchor; comment metadata never creates an unanchored root. */
@@ -41,7 +41,7 @@ export type CanonicalCommentResult = {
41
41
  commentId?: number;
42
42
  } | {
43
43
  status: "refused";
44
- gap: CanonicalGap;
44
+ ground: CanonicalRefusalGround;
45
45
  message: string;
46
46
  /** Whether the same request can succeed once a pending composition settles. */
47
47
  retry: "afterComposition" | "never";
@@ -1,9 +1,9 @@
1
- import { CANONICAL_GAP } from "./canonicalCapabilities.js";
1
+ import { CanonicalRefusalGround } from "./canonicalCapabilities.js";
2
2
  export type CanonicalSectionPropertiesResult = {
3
3
  status: "applied";
4
4
  version: number;
5
5
  } | {
6
6
  status: "refused";
7
- gap: typeof CANONICAL_GAP.sectionProperties;
7
+ ground: CanonicalRefusalGround;
8
8
  message: string;
9
9
  };
@@ -1,4 +1,5 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
+ import { CLIPBOARD_TYPES, INTERNAL_CLIPBOARD_TYPE, getClipboardImageFiles, getStandaloneClipboardImageFiles } from "./clipboardFiles.js";
2
3
  /**
3
4
  * Clipboard content format
4
5
  */
@@ -34,33 +35,6 @@ export type ClipboardOptions = {
34
35
  /** Callback for handling errors */
35
36
  onError?: (error: Error) => void;
36
37
  };
37
- /**
38
- * Custom MIME type for internal clipboard format
39
- */
40
- export declare const INTERNAL_CLIPBOARD_TYPE = "application/x-stella-folio";
41
- /**
42
- * Standard clipboard MIME types
43
- */
44
- export declare const CLIPBOARD_TYPES: {
45
- readonly HTML: "text/html";
46
- readonly PLAIN: "text/plain";
47
- };
48
- /**
49
- * Extract image files from clipboard data (if present).
50
- */
51
- type ClipboardDataLike = {
52
- files?: FileList | readonly File[] | undefined;
53
- getData?: ((format: string) => string) | undefined;
54
- items?: DataTransferItemList | readonly DataTransferItem[] | undefined;
55
- types?: ArrayLike<string> | undefined;
56
- };
57
- export declare function getClipboardImageFiles(clipboardData: ClipboardDataLike | null): File[];
58
- /**
59
- * Return image files only when the clipboard has no readable editor content.
60
- * Rich HTML, internal payloads, and plain text must stay on the normal paste
61
- * path; some applications include a rendered image beside that content.
62
- */
63
- export declare function getStandaloneClipboardImageFiles(clipboardData: ClipboardDataLike | null): File[];
64
38
  /**
65
39
  * Copy runs to clipboard with formatting
66
40
  */
@@ -147,4 +121,4 @@ declare const _default_1: {
147
121
  isEditorHtml: typeof isEditorHtml;
148
122
  createClipboardHandlers: typeof createClipboardHandlers;
149
123
  };
150
- export { _default_1 as default };
124
+ export { CLIPBOARD_TYPES, INTERNAL_CLIPBOARD_TYPE, _default_1 as default, getClipboardImageFiles, getStandaloneClipboardImageFiles };
@@ -1,3 +1,4 @@
1
+ import { CLIPBOARD_TYPES, INTERNAL_CLIPBOARD_TYPE, getClipboardImageFiles, getStandaloneClipboardImageFiles } from "./clipboardFiles.js";
1
2
  import { htmlCommentEnd } from "./htmlComments.js";
2
3
  import { stripXmlDeclarations } from "./stripXmlDeclarations.js";
3
4
  import { encodeUtf8, readBlobText } from "./textEncoding.js";
@@ -15,17 +16,6 @@ import createDOMPurify from "dompurify";
15
16
  */
16
17
  let domPurify;
17
18
  const getDomPurify = () => domPurify ??= createDOMPurify(window);
18
- /**
19
- * Custom MIME type for internal clipboard format
20
- */
21
- const INTERNAL_CLIPBOARD_TYPE = "application/x-stella-folio";
22
- /**
23
- * Standard clipboard MIME types
24
- */
25
- const CLIPBOARD_TYPES = {
26
- HTML: "text/html",
27
- PLAIN: "text/plain"
28
- };
29
19
  const SKIPPED_CLIPBOARD_ELEMENTS = /* @__PURE__ */ new Set([
30
20
  "script",
31
21
  "style",
@@ -35,91 +25,6 @@ const SKIPPED_CLIPBOARD_ELEMENTS = /* @__PURE__ */ new Set([
35
25
  "svg",
36
26
  "math"
37
27
  ]);
38
- function getClipboardImageFiles(clipboardData) {
39
- if (!clipboardData) return [];
40
- const collectFromItems = () => {
41
- const items = clipboardData.items;
42
- if (!items || items.length === 0) return [];
43
- const files = [];
44
- for (const item of Array.from(items)) {
45
- if (item.kind !== "file") continue;
46
- if (!item.type.startsWith("image/")) continue;
47
- const file = item.getAsFile();
48
- if (file) files.push(file);
49
- }
50
- return files;
51
- };
52
- const collectFromFiles = () => {
53
- const clipboardFiles = clipboardData.files;
54
- if (!clipboardFiles || clipboardFiles.length === 0) return [];
55
- return Array.from(clipboardFiles).filter((file) => file.type.startsWith("image/"));
56
- };
57
- const candidates = collectFromItems();
58
- const files = candidates.length ? candidates : collectFromFiles();
59
- if (files.length <= 1) return files;
60
- const preferredTypes = [
61
- "image/png",
62
- "image/jpeg",
63
- "image/webp",
64
- "image/gif",
65
- "image/svg+xml",
66
- "image/bmp",
67
- "image/tiff"
68
- ];
69
- const pickBest = (group) => {
70
- let best = group[0];
71
- let bestRank = preferredTypes.indexOf(best.type);
72
- if (bestRank < 0) bestRank = Number.MAX_SAFE_INTEGER;
73
- for (const file of group.slice(1)) {
74
- let rank = preferredTypes.indexOf(file.type);
75
- if (rank < 0) rank = Number.MAX_SAFE_INTEGER;
76
- if (rank < bestRank) {
77
- best = file;
78
- bestRank = rank;
79
- continue;
80
- }
81
- if (rank === bestRank && file.size > best.size) best = file;
82
- }
83
- return best;
84
- };
85
- const groups = /* @__PURE__ */ new Map();
86
- for (const file of files) {
87
- const rawName = file.name.trim();
88
- const key = (rawName ? rawName.replace(/\.[^/.]+$/, "").toLowerCase() : "") || `size:${file.size}`;
89
- const bucket = groups.get(key);
90
- if (bucket) bucket.push(file);
91
- else groups.set(key, [file]);
92
- }
93
- const deduped = [];
94
- for (const group of groups.values()) deduped.push(pickBest(group));
95
- return deduped;
96
- }
97
- const ENGINE_CLIPBOARD_TYPES = [
98
- INTERNAL_CLIPBOARD_TYPE,
99
- CLIPBOARD_TYPES.HTML,
100
- CLIPBOARD_TYPES.PLAIN
101
- ];
102
- const hasEngineClipboardContent = (clipboardData) => {
103
- if (!clipboardData.types || !clipboardData.getData) return false;
104
- const availableTypes = new Set(Array.from(clipboardData.types));
105
- for (const type of ENGINE_CLIPBOARD_TYPES) {
106
- if (!availableTypes.has(type)) continue;
107
- try {
108
- if (clipboardData.getData(type) !== "") return true;
109
- } catch {}
110
- }
111
- return false;
112
- };
113
- /**
114
- * Return image files only when the clipboard has no readable editor content.
115
- * Rich HTML, internal payloads, and plain text must stay on the normal paste
116
- * path; some applications include a rendered image beside that content.
117
- */
118
- function getStandaloneClipboardImageFiles(clipboardData) {
119
- const imageFiles = getClipboardImageFiles(clipboardData);
120
- if (imageFiles.length === 0 || !clipboardData) return imageFiles;
121
- return hasEngineClipboardContent(clipboardData) ? [] : imageFiles;
122
- }
123
28
  /**
124
29
  * Copy runs to clipboard with formatting
125
30
  */
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Custom MIME type for internal clipboard format
3
+ */
4
+ export declare const INTERNAL_CLIPBOARD_TYPE = "application/x-stella-folio";
5
+ /**
6
+ * Standard clipboard MIME types
7
+ */
8
+ export declare const CLIPBOARD_TYPES: {
9
+ readonly HTML: "text/html";
10
+ readonly PLAIN: "text/plain";
11
+ };
12
+ /**
13
+ * Extract image files from clipboard data (if present).
14
+ */
15
+ export type ClipboardDataLike = {
16
+ files?: FileList | readonly File[] | undefined;
17
+ getData?: ((format: string) => string) | undefined;
18
+ items?: DataTransferItemList | readonly DataTransferItem[] | undefined;
19
+ types?: ArrayLike<string> | undefined;
20
+ };
21
+ export declare function getClipboardImageFiles(clipboardData: ClipboardDataLike | null): File[];
22
+ /**
23
+ * Return image files only when the clipboard has no readable editor content.
24
+ * Rich HTML, internal payloads, and plain text must stay on the normal paste
25
+ * path; some applications include a rendered image beside that content.
26
+ */
27
+ export declare function getStandaloneClipboardImageFiles(clipboardData: ClipboardDataLike | null): File[];
@@ -0,0 +1,98 @@
1
+ // src/utils/clipboardFiles.ts
2
+ /**
3
+ * Custom MIME type for internal clipboard format
4
+ */
5
+ const INTERNAL_CLIPBOARD_TYPE = "application/x-stella-folio";
6
+ /**
7
+ * Standard clipboard MIME types
8
+ */
9
+ const CLIPBOARD_TYPES = {
10
+ HTML: "text/html",
11
+ PLAIN: "text/plain"
12
+ };
13
+ function getClipboardImageFiles(clipboardData) {
14
+ if (!clipboardData) return [];
15
+ const collectFromItems = () => {
16
+ const items = clipboardData.items;
17
+ if (!items || items.length === 0) return [];
18
+ const files = [];
19
+ for (const item of Array.from(items)) {
20
+ if (item.kind !== "file") continue;
21
+ if (!item.type.startsWith("image/")) continue;
22
+ const file = item.getAsFile();
23
+ if (file) files.push(file);
24
+ }
25
+ return files;
26
+ };
27
+ const collectFromFiles = () => {
28
+ const clipboardFiles = clipboardData.files;
29
+ if (!clipboardFiles || clipboardFiles.length === 0) return [];
30
+ return Array.from(clipboardFiles).filter((file) => file.type.startsWith("image/"));
31
+ };
32
+ const candidates = collectFromItems();
33
+ const files = candidates.length ? candidates : collectFromFiles();
34
+ if (files.length <= 1) return files;
35
+ const preferredTypes = [
36
+ "image/png",
37
+ "image/jpeg",
38
+ "image/webp",
39
+ "image/gif",
40
+ "image/svg+xml",
41
+ "image/bmp",
42
+ "image/tiff"
43
+ ];
44
+ const pickBest = (group) => {
45
+ let best = group[0];
46
+ let bestRank = preferredTypes.indexOf(best.type);
47
+ if (bestRank < 0) bestRank = Number.MAX_SAFE_INTEGER;
48
+ for (const file of group.slice(1)) {
49
+ let rank = preferredTypes.indexOf(file.type);
50
+ if (rank < 0) rank = Number.MAX_SAFE_INTEGER;
51
+ if (rank < bestRank) {
52
+ best = file;
53
+ bestRank = rank;
54
+ continue;
55
+ }
56
+ if (rank === bestRank && file.size > best.size) best = file;
57
+ }
58
+ return best;
59
+ };
60
+ const groups = /* @__PURE__ */ new Map();
61
+ for (const file of files) {
62
+ const rawName = file.name.trim();
63
+ const key = (rawName ? rawName.replace(/\.[^/.]+$/, "").toLowerCase() : "") || `size:${file.size}`;
64
+ const bucket = groups.get(key);
65
+ if (bucket) bucket.push(file);
66
+ else groups.set(key, [file]);
67
+ }
68
+ const deduped = [];
69
+ for (const group of groups.values()) deduped.push(pickBest(group));
70
+ return deduped;
71
+ }
72
+ const ENGINE_CLIPBOARD_TYPES = [
73
+ INTERNAL_CLIPBOARD_TYPE,
74
+ CLIPBOARD_TYPES.HTML,
75
+ CLIPBOARD_TYPES.PLAIN
76
+ ];
77
+ const hasEngineClipboardContent = (clipboardData) => {
78
+ if (!clipboardData.types || !clipboardData.getData) return false;
79
+ const availableTypes = new Set(Array.from(clipboardData.types));
80
+ for (const type of ENGINE_CLIPBOARD_TYPES) {
81
+ if (!availableTypes.has(type)) continue;
82
+ try {
83
+ if (clipboardData.getData(type) !== "") return true;
84
+ } catch {}
85
+ }
86
+ return false;
87
+ };
88
+ /**
89
+ * Return image files only when the clipboard has no readable editor content.
90
+ * Rich HTML, internal payloads, and plain text must stay on the normal paste
91
+ * path; some applications include a rendered image beside that content.
92
+ */
93
+ function getStandaloneClipboardImageFiles(clipboardData) {
94
+ const imageFiles = getClipboardImageFiles(clipboardData);
95
+ if (imageFiles.length === 0 || !clipboardData) return imageFiles;
96
+ return hasEngineClipboardContent(clipboardData) ? [] : imageFiles;
97
+ }
98
+ export { CLIPBOARD_TYPES, INTERNAL_CLIPBOARD_TYPE, getClipboardImageFiles, getStandaloneClipboardImageFiles };
@@ -1,3 +1,4 @@
1
+ export declare const HORIZONTAL_RULER_HEIGHT_PX = 22;
1
2
  type RulerBounds = {
2
3
  min: number;
3
4
  max: number;
@@ -1,6 +1,7 @@
1
1
  import { TWIPS_PER_INCH } from "./units.js";
2
2
  // src/utils/rulerControl.ts
3
3
  const TWIPS_PER_CM = 567;
4
+ const HORIZONTAL_RULER_HEIGHT_PX = 22;
4
5
  const MIN_CONTENT_SIZE_TWIPS = 720;
5
6
  /** Existing pointer bounds, shared with the keyboard controls. */
6
7
  function getHorizontalRulerBounds({ pageWidth, leftMargin, rightMargin, leftIndent, rightIndent }) {
@@ -91,4 +92,4 @@ function createRulerControl({ value, min, max, unit, onChange }) {
91
92
  }
92
93
  };
93
94
  }
94
- export { clampRulerValue, createRulerControl, getHorizontalRulerBounds, getVerticalRulerBounds };
95
+ export { HORIZONTAL_RULER_HEIGHT_PX, clampRulerValue, createRulerControl, getHorizontalRulerBounds, getVerticalRulerBounds };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-core",
3
- "version": "0.74.0",
3
+ "version": "0.75.0",
4
4
  "description": "Headless DOCX engine: reads .docx into a typed OOXML model, applies every edit as a validated operation, paginates it, and writes .docx back with untouched parts byte for byte.",
5
5
  "keywords": [
6
6
  "document-model",
@@ -173,7 +173,7 @@
173
173
  "perf": "bun scripts/profile-editor.ts"
174
174
  },
175
175
  "dependencies": {
176
- "@stll/docx-core": "^0.45.1",
176
+ "@stll/docx-core": "^0.46.0",
177
177
  "@stll/template-conditions": "^0.7.0",
178
178
  "@stll/utf8-boundaries": "0.2.0",
179
179
  "better-result": "3.0.1",