@embedpdf/plugin-annotation 2.14.0 → 2.14.2
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.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +73 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/annotation-plugin.d.ts +25 -0
- package/dist/lib/helpers.d.ts +8 -0
- package/dist/lib/types.d.ts +21 -2
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +27 -18
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +27 -18
- package/dist/react/index.js.map +1 -1
- package/dist/shared/components/annotation-container.d.ts +13 -1
- package/dist/shared/components/types.d.ts +12 -0
- package/dist/shared-preact/components/annotation-container.d.ts +13 -1
- package/dist/shared-preact/components/types.d.ts +12 -0
- package/dist/shared-react/components/annotation-container.d.ts +13 -1
- package/dist/shared-react/components/types.d.ts +12 -0
- package/dist/svelte/components/types.d.ts +12 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +31 -20
- package/dist/svelte/index.js.map +1 -1
- package/dist/svelte/types.d.ts +12 -0
- package/dist/vue/components/annotation-container.vue.d.ts +12 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +57 -41
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/types.d.ts +12 -0
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -207,6 +207,22 @@ function hasLockedFlag(annotation) {
|
|
|
207
207
|
var _a;
|
|
208
208
|
return ((_a = annotation.flags) == null ? void 0 : _a.includes("locked")) ?? false;
|
|
209
209
|
}
|
|
210
|
+
function hasNoViewFlag(annotation) {
|
|
211
|
+
var _a;
|
|
212
|
+
return ((_a = annotation.flags) == null ? void 0 : _a.includes("noView")) ?? false;
|
|
213
|
+
}
|
|
214
|
+
function hasHiddenFlag(annotation) {
|
|
215
|
+
var _a;
|
|
216
|
+
return ((_a = annotation.flags) == null ? void 0 : _a.includes("hidden")) ?? false;
|
|
217
|
+
}
|
|
218
|
+
function hasReadOnlyFlag(annotation) {
|
|
219
|
+
var _a;
|
|
220
|
+
return ((_a = annotation.flags) == null ? void 0 : _a.includes("readOnly")) ?? false;
|
|
221
|
+
}
|
|
222
|
+
function hasLockedContentsFlag(annotation) {
|
|
223
|
+
var _a;
|
|
224
|
+
return ((_a = annotation.flags) == null ? void 0 : _a.includes("lockedContents")) ?? false;
|
|
225
|
+
}
|
|
210
226
|
const getAnnotationsByPageIndex = (s, page) => (s.pages[page] ?? []).map((uid) => s.byUid[uid]);
|
|
211
227
|
const getAnnotations = (s) => {
|
|
212
228
|
const out = {};
|
|
@@ -4749,7 +4765,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
4749
4765
|
const docState = this.state.documents[documentId];
|
|
4750
4766
|
if (!docState) return;
|
|
4751
4767
|
const pageAnnotations = (docState.pages[pageIndex] ?? []).map((uid) => docState.byUid[uid]).filter((ta) => ta !== void 0).filter((ta) => isSelectableAnnotation(ta));
|
|
4752
|
-
const selectedIds = pageAnnotations.filter((ta) => rectsIntersect(rect, ta.object.rect)).filter((ta) =>
|
|
4768
|
+
const selectedIds = pageAnnotations.filter((ta) => rectsIntersect(rect, ta.object.rect)).filter((ta) => this.isAnnotationSelectable(ta.object, documentId)).map((ta) => ta.object.id);
|
|
4753
4769
|
if (selectedIds.length > 0) {
|
|
4754
4770
|
const expandedIds = /* @__PURE__ */ new Set();
|
|
4755
4771
|
for (const id of selectedIds) {
|
|
@@ -4848,6 +4864,9 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
4848
4864
|
setLocked: (mode, documentId) => this.setLocked(mode, documentId),
|
|
4849
4865
|
getLocked: (documentId) => this.getLocked(documentId),
|
|
4850
4866
|
isAnnotationLocked: (annotation, documentId) => this.isAnnotationLocked(annotation, documentId),
|
|
4867
|
+
isAnnotationInteractive: (annotation, documentId) => this.isAnnotationInteractive(annotation, documentId),
|
|
4868
|
+
isAnnotationStructurallyLocked: (annotation, documentId) => this.isAnnotationStructurallyLocked(annotation, documentId),
|
|
4869
|
+
isAnnotationContentLocked: (annotation, documentId) => this.isAnnotationContentLocked(annotation, documentId),
|
|
4851
4870
|
isCategoryLocked: (category, documentId) => this.isCategoryLockedMethod(category, documentId),
|
|
4852
4871
|
isToolLocked: (toolId, documentId) => this.isToolLockedMethod(toolId, documentId),
|
|
4853
4872
|
// Sync (lightweight state update without commit)
|
|
@@ -4922,6 +4941,9 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
4922
4941
|
setLocked: (mode) => this.setLocked(mode, documentId),
|
|
4923
4942
|
getLocked: () => this.getLocked(documentId),
|
|
4924
4943
|
isAnnotationLocked: (annotation) => this.isAnnotationLocked(annotation, documentId),
|
|
4944
|
+
isAnnotationInteractive: (annotation) => this.isAnnotationInteractive(annotation, documentId),
|
|
4945
|
+
isAnnotationStructurallyLocked: (annotation) => this.isAnnotationStructurallyLocked(annotation, documentId),
|
|
4946
|
+
isAnnotationContentLocked: (annotation) => this.isAnnotationContentLocked(annotation, documentId),
|
|
4925
4947
|
isCategoryLocked: (category) => this.isCategoryLockedMethod(category, documentId),
|
|
4926
4948
|
isToolLocked: (toolId) => this.isToolLockedMethod(toolId, documentId),
|
|
4927
4949
|
syncAnnotationObject: (id, patch) => this.syncAnnotationObject(id, patch, documentId),
|
|
@@ -5464,7 +5486,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
5464
5486
|
selectAnnotation(pageIndex, id, documentId) {
|
|
5465
5487
|
const docId = documentId ?? this.getActiveDocumentId();
|
|
5466
5488
|
const ta = this.getAnnotationById(id, docId);
|
|
5467
|
-
if (ta && this.
|
|
5489
|
+
if (ta && !this.isAnnotationSelectable(ta.object, docId)) return;
|
|
5468
5490
|
if (this.isInGroupMethod(id, docId)) {
|
|
5469
5491
|
const members = this.getGroupMembersMethod(id, docId);
|
|
5470
5492
|
const memberIds = members.map((m) => m.object.id);
|
|
@@ -5510,7 +5532,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
5510
5532
|
toggleSelectionMethod(pageIndex, id, documentId) {
|
|
5511
5533
|
const docId = documentId ?? this.getActiveDocumentId();
|
|
5512
5534
|
const ta = this.getAnnotationById(id, docId);
|
|
5513
|
-
if (ta && this.
|
|
5535
|
+
if (ta && !this.isAnnotationSelectable(ta.object, docId)) return;
|
|
5514
5536
|
const docState = this.getDocumentState(docId);
|
|
5515
5537
|
if (docState.selectedUids.includes(id)) {
|
|
5516
5538
|
this.dispatch(removeFromSelection(docId, id));
|
|
@@ -5530,7 +5552,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
5530
5552
|
addToSelectionMethod(pageIndex, id, documentId) {
|
|
5531
5553
|
const docId = documentId ?? this.getActiveDocumentId();
|
|
5532
5554
|
const ta = this.getAnnotationById(id, docId);
|
|
5533
|
-
if (ta && this.
|
|
5555
|
+
if (ta && !this.isAnnotationInteractive(ta.object, docId)) return;
|
|
5534
5556
|
this.dispatch(addToSelection(docId, pageIndex, id));
|
|
5535
5557
|
}
|
|
5536
5558
|
removeFromSelectionMethod(id, documentId) {
|
|
@@ -5542,7 +5564,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
5542
5564
|
const docState = this.getDocumentState(docId);
|
|
5543
5565
|
const filtered = ids.filter((id) => {
|
|
5544
5566
|
const ta = docState.byUid[id];
|
|
5545
|
-
return !ta ||
|
|
5567
|
+
return !ta || this.isAnnotationInteractive(ta.object, docId);
|
|
5546
5568
|
});
|
|
5547
5569
|
this.dispatch(setSelection(docId, filtered));
|
|
5548
5570
|
}
|
|
@@ -6530,7 +6552,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
6530
6552
|
const lockedSelected = updatedDocState.selectedUids.filter((uid) => {
|
|
6531
6553
|
const ta = updatedDocState.byUid[uid];
|
|
6532
6554
|
if (!ta) return false;
|
|
6533
|
-
return this.
|
|
6555
|
+
return !this.isAnnotationInteractive(ta.object, docId);
|
|
6534
6556
|
});
|
|
6535
6557
|
if (lockedSelected.length > 0) {
|
|
6536
6558
|
const remaining = updatedDocState.selectedUids.filter((uid) => !lockedSelected.includes(uid));
|
|
@@ -6546,6 +6568,47 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
|
|
|
6546
6568
|
const categories = getAnnotationCategories(tool);
|
|
6547
6569
|
return isCategoryLocked(categories, this.getLocked(documentId));
|
|
6548
6570
|
}
|
|
6571
|
+
/**
|
|
6572
|
+
* Whether the annotation can be interacted with at all (selected, edited, menu shown).
|
|
6573
|
+
* Returns false for `noView`, `hidden`, `readOnly`, or category-locked annotations.
|
|
6574
|
+
* This is the spec-compliant "can the user do anything with this?" predicate.
|
|
6575
|
+
*/
|
|
6576
|
+
isAnnotationInteractive(annotation, documentId) {
|
|
6577
|
+
if (hasNoViewFlag(annotation)) return false;
|
|
6578
|
+
if (hasHiddenFlag(annotation)) return false;
|
|
6579
|
+
if (hasReadOnlyFlag(annotation)) return false;
|
|
6580
|
+
const tool = this.findToolForAnnotation(annotation);
|
|
6581
|
+
const categories = getAnnotationCategories(tool);
|
|
6582
|
+
if (isCategoryLocked(categories, this.getLocked(documentId))) return false;
|
|
6583
|
+
return true;
|
|
6584
|
+
}
|
|
6585
|
+
/**
|
|
6586
|
+
* Whether the annotation's structure (position, size, rotation, vertices) is locked.
|
|
6587
|
+
* Non-interactive annotations are treated as structurally locked. PDF `locked` flag
|
|
6588
|
+
* makes an otherwise-interactive annotation structurally locked while still selectable.
|
|
6589
|
+
*/
|
|
6590
|
+
isAnnotationStructurallyLocked(annotation, documentId) {
|
|
6591
|
+
if (!this.isAnnotationInteractive(annotation, documentId)) return true;
|
|
6592
|
+
return hasLockedFlag(annotation);
|
|
6593
|
+
}
|
|
6594
|
+
/**
|
|
6595
|
+
* Whether the annotation's content (e.g. FreeText text) is locked.
|
|
6596
|
+
* Non-interactive annotations are treated as content-locked. PDF `lockedContents`
|
|
6597
|
+
* flag blocks content edits while still allowing move/resize.
|
|
6598
|
+
*/
|
|
6599
|
+
isAnnotationContentLocked(annotation, documentId) {
|
|
6600
|
+
if (!this.isAnnotationInteractive(annotation, documentId)) return true;
|
|
6601
|
+
return hasLockedContentsFlag(annotation);
|
|
6602
|
+
}
|
|
6603
|
+
/**
|
|
6604
|
+
* Whether a specific annotation is eligible to be added to the selection store.
|
|
6605
|
+
* Differs from the subtype-based `isSelectableAnnotation` helper: that answers
|
|
6606
|
+
* "is this subtype ever selectable?", while this answers "is this specific
|
|
6607
|
+
* annotation selectable right now given its flags and document lock state?".
|
|
6608
|
+
*/
|
|
6609
|
+
isAnnotationSelectable(annotation, documentId) {
|
|
6610
|
+
return this.isAnnotationInteractive(annotation, documentId);
|
|
6611
|
+
}
|
|
6549
6612
|
isCategoryLockedMethod(category, documentId) {
|
|
6550
6613
|
return isCategoryLocked([category], this.getLocked(documentId));
|
|
6551
6614
|
}
|
|
@@ -6878,9 +6941,13 @@ export {
|
|
|
6878
6941
|
getSidebarAnnotationsWithRepliesGroupedByPage,
|
|
6879
6942
|
getToolDefaultsById,
|
|
6880
6943
|
hasAttachedLinks,
|
|
6944
|
+
hasHiddenFlag,
|
|
6881
6945
|
hasIRTChildren,
|
|
6946
|
+
hasLockedContentsFlag,
|
|
6882
6947
|
hasLockedFlag,
|
|
6883
6948
|
hasMultipleSelected,
|
|
6949
|
+
hasNoViewFlag,
|
|
6950
|
+
hasReadOnlyFlag,
|
|
6884
6951
|
inferRotationCenterFromRects2 as inferRotationCenterFromRects,
|
|
6885
6952
|
initialDocumentState,
|
|
6886
6953
|
initialState,
|