@progress/kendo-pdfviewer-common 0.4.2-develop.1 → 0.5.0-develop.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.
Files changed (48) hide show
  1. package/dist/es/annotations/annotation-editor-layer-builder.js +6 -1
  2. package/dist/es/annotations/annotation-editor-ui-manager.js +25 -0
  3. package/dist/es/annotations/annotation-layer-builder.js +14 -4
  4. package/dist/es/annotations/annotation-layer.js +358 -337
  5. package/dist/es/annotations/draw-layer-builder.js +5 -1
  6. package/dist/es/annotations/helpers/annotation-storage.js +14 -0
  7. package/dist/es/annotations/helpers/text-accessibility-manager.js +5 -0
  8. package/dist/es/annotations/shared/event_utils.js +6 -0
  9. package/dist/es/text/text-layer-builder.js +13 -1
  10. package/dist/es/utils.js +3 -2
  11. package/dist/es/widget/page.js +22 -0
  12. package/dist/es/widget/pdfviewer.js +24 -13
  13. package/dist/es2015/annotations/annotation-editor-layer-builder.js +6 -1
  14. package/dist/es2015/annotations/annotation-editor-ui-manager.js +25 -0
  15. package/dist/es2015/annotations/annotation-layer-builder.js +14 -4
  16. package/dist/es2015/annotations/annotation-layer.js +358 -337
  17. package/dist/es2015/annotations/draw-layer-builder.js +5 -1
  18. package/dist/es2015/annotations/helpers/annotation-storage.js +14 -0
  19. package/dist/es2015/annotations/helpers/text-accessibility-manager.js +5 -0
  20. package/dist/es2015/annotations/shared/event_utils.js +6 -0
  21. package/dist/es2015/text/text-layer-builder.js +13 -1
  22. package/dist/es2015/utils.js +3 -2
  23. package/dist/es2015/widget/page.js +22 -0
  24. package/dist/es2015/widget/pdfviewer.js +24 -13
  25. package/dist/npm/annotations/annotation-editor-layer-builder.d.ts +3 -1
  26. package/dist/npm/annotations/annotation-editor-layer-builder.js +6 -1
  27. package/dist/npm/annotations/annotation-editor-ui-manager.d.ts +3 -0
  28. package/dist/npm/annotations/annotation-editor-ui-manager.js +25 -0
  29. package/dist/npm/annotations/annotation-layer-builder.d.ts +3 -1
  30. package/dist/npm/annotations/annotation-layer-builder.js +14 -4
  31. package/dist/npm/annotations/annotation-layer.d.ts +3 -1
  32. package/dist/npm/annotations/annotation-layer.js +358 -337
  33. package/dist/npm/annotations/draw-layer-builder.d.ts +3 -1
  34. package/dist/npm/annotations/draw-layer-builder.js +5 -1
  35. package/dist/npm/annotations/helpers/annotation-storage.d.ts +10 -0
  36. package/dist/npm/annotations/helpers/annotation-storage.js +14 -0
  37. package/dist/npm/annotations/helpers/text-accessibility-manager.d.ts +1 -0
  38. package/dist/npm/annotations/helpers/text-accessibility-manager.js +5 -0
  39. package/dist/npm/annotations/shared/event_utils.d.ts +4 -0
  40. package/dist/npm/annotations/shared/event_utils.js +6 -0
  41. package/dist/npm/text/text-layer-builder.d.ts +3 -1
  42. package/dist/npm/text/text-layer-builder.js +13 -1
  43. package/dist/npm/utils.d.ts +1 -0
  44. package/dist/npm/utils.js +5 -3
  45. package/dist/npm/widget/page.js +22 -0
  46. package/dist/npm/widget/pdfviewer.d.ts +1 -0
  47. package/dist/npm/widget/pdfviewer.js +23 -12
  48. package/package.json +1 -1
@@ -20,8 +20,7 @@ const tslib_1 = require("tslib");
20
20
  const pdf_mjs_1 = require("pdfjs-dist/legacy/build/pdf.mjs");
21
21
  const utils_1 = require("./shared/utils");
22
22
  const scripting_utils_1 = require("./shared/scripting_utils");
23
- // import { AnnotationStorage } from "pdfjs-dist/types/src/display/annotation_storage";
24
- // import { AnnotationStorage } from "pdfjs-dist/types/src/display/annotation_storage";
23
+ const annotation_storage_1 = require("./helpers/annotation-storage");
25
24
  // const DEFAULT_TAB_INDEX = 1000;
26
25
  // it is unclear why the value 1000 is chosen by pdf.js
27
26
  // kendo a11y tests fail if this is not 0
@@ -51,15 +50,16 @@ class AnnotationElementFactory {
51
50
  switch (fieldType) {
52
51
  case "Tx":
53
52
  return new TextWidgetAnnotationElement(parameters);
54
- // case "Btn":
55
- // if (parameters.data.radioButton) {
56
- // return new RadioButtonWidgetAnnotationElement(parameters);
57
- // } else if (parameters.data.checkBox) {
58
- // return new CheckboxWidgetAnnotationElement(parameters);
59
- // }
60
- // return new PushButtonWidgetAnnotationElement(parameters);
61
- // case "Ch":
62
- // return new ChoiceWidgetAnnotationElement(parameters);
53
+ case "Btn":
54
+ if (parameters.data.radioButton) {
55
+ return new RadioButtonWidgetAnnotationElement(parameters);
56
+ }
57
+ else if (parameters.data.checkBox) {
58
+ return new CheckboxWidgetAnnotationElement(parameters);
59
+ }
60
+ return new PushButtonWidgetAnnotationElement(parameters);
61
+ case "Ch":
62
+ return new ChoiceWidgetAnnotationElement(parameters);
63
63
  // case "Sig":
64
64
  // return new SignatureWidgetAnnotationElement(parameters);
65
65
  default:
@@ -1385,89 +1385,107 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
1385
1385
  // super(parameters, { isRenderable: !!parameters.data.hasOwnCanvas });
1386
1386
  // }
1387
1387
  // }
1388
- // class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
1389
- // constructor(parameters) {
1390
- // super(parameters, { isRenderable: parameters.renderForms });
1391
- // }
1392
- // render() {
1393
- // const storage = this.annotationStorage;
1394
- // const data = this.data;
1395
- // const id = data.id;
1396
- // let value = storage.getValue(id, {
1397
- // value: data.exportValue === data.fieldValue,
1398
- // }).value;
1399
- // if (typeof value === "string") {
1400
- // // The value has been changed through js and set in annotationStorage.
1401
- // value = value !== "Off";
1402
- // storage.setValue(id, { value });
1403
- // }
1404
- // this.container.classList.add("buttonWidgetAnnotation", "checkBox");
1405
- // const element = document.createElement("input");
1406
- // GetElementsByNameSet.add(element);
1407
- // element.setAttribute("data-element-id", id);
1408
- // element.disabled = data.readOnly;
1409
- // this._setRequired(element, this.data.required);
1410
- // element.type = "checkbox";
1411
- // element.name = data.fieldName;
1412
- // if (value) {
1413
- // element.setAttribute("checked", (true).toString());
1414
- // }
1415
- // element.setAttribute("exportValue", data.exportValue);
1416
- // element.tabIndex = DEFAULT_TAB_INDEX;
1417
- // element.addEventListener("change", event => {
1418
- // const { name, checked } = event.target as any;
1419
- // for (const checkbox of this._getElementsByName(name, /* skipId = */ id)) {
1420
- // const curChecked = checked && checkbox.exportValue === data.exportValue;
1421
- // if (checkbox.domElement) {
1422
- // checkbox.domElement.checked = curChecked;
1423
- // }
1424
- // storage.setValue(checkbox.id, { value: curChecked });
1425
- // }
1426
- // storage.setValue(id, { value: checked });
1427
- // });
1428
- // element.addEventListener("resetform", event => {
1429
- // const defaultValue = data.defaultFieldValue || "Off";
1430
- // // @ts-expect-error(TS)
1431
- // event.target.checked = defaultValue === data.exportValue;
1432
- // });
1433
- // if (this.enableScripting && this.hasJSActions) {
1434
- // element.addEventListener("updatefromsandbox", jsEvent => {
1435
- // const actions = {
1436
- // value(event) {
1437
- // event.target.checked = event.detail.value !== "Off";
1438
- // storage.setValue(id, { value: event.target.checked });
1439
- // },
1440
- // };
1441
- // this._dispatchEventFromSandbox(actions, jsEvent);
1442
- // });
1443
- // this._setEventListeners(
1444
- // element,
1445
- // null,
1446
- // [
1447
- // ["change", "Validate"],
1448
- // ["change", "Action"],
1449
- // ["focus", "Focus"],
1450
- // ["blur", "Blur"],
1451
- // ["mousedown", "Mouse Down"],
1452
- // ["mouseenter", "Mouse Enter"],
1453
- // ["mouseleave", "Mouse Exit"],
1454
- // ["mouseup", "Mouse Up"],
1455
- // ],
1456
- // event => event.target.checked
1457
- // );
1458
- // }
1459
- // this._setBackgroundColor(element);
1460
- // this._setDefaultPropertiesFromJS(element);
1461
- // this.container.append(element);
1462
- // return this.container;
1463
- // }
1464
- // }
1388
+ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
1389
+ constructor(parameters) {
1390
+ super(parameters, { isRenderable: parameters.renderForms });
1391
+ }
1392
+ render() {
1393
+ const storage = this.annotationStorage;
1394
+ const data = this.data;
1395
+ const id = data.id;
1396
+ let value = storage.getValue(id, {
1397
+ value: data.exportValue === data.fieldValue
1398
+ }).value;
1399
+ if (typeof value === "string") {
1400
+ // The value has been changed through js and set in annotationStorage.
1401
+ value = value !== "Off";
1402
+ storage.setValue(id, { value });
1403
+ }
1404
+ // this.container.classList.add("buttonWidgetAnnotation", "checkBox");
1405
+ this.container.classList.add("k-button-widget-annotation", "k-checkbox-widget-annotation");
1406
+ const element = document.createElement("input");
1407
+ GetElementsByNameSet.add(element);
1408
+ element.setAttribute("data-element-id", id);
1409
+ element.disabled = data.readOnly;
1410
+ this._setRequired(element, this.data.required);
1411
+ element.type = "checkbox";
1412
+ element.name = data.fieldName;
1413
+ if (value) {
1414
+ element.setAttribute("checked", (true).toString());
1415
+ }
1416
+ element.setAttribute("exportValue", data.exportValue);
1417
+ element.tabIndex = DEFAULT_TAB_INDEX;
1418
+ element.addEventListener("change", event => {
1419
+ const { name, checked } = event.target;
1420
+ for (const checkbox of this._getElementsByName(name, /* skipId = */ id)) {
1421
+ const curChecked = checked && checkbox.exportValue === data.exportValue;
1422
+ if (checkbox.domElement) {
1423
+ checkbox.domElement.checked = curChecked;
1424
+ }
1425
+ storage.setValue(checkbox.id, { value: curChecked });
1426
+ }
1427
+ storage.setValue(id, { value: checked });
1428
+ });
1429
+ element.addEventListener("resetform", event => {
1430
+ const defaultValue = data.defaultFieldValue || "Off";
1431
+ // @ts-expect-error(TS)
1432
+ event.target.checked = defaultValue === data.exportValue;
1433
+ });
1434
+ if (this.enableScripting && this.hasJSActions) {
1435
+ element.addEventListener("updatefromsandbox", jsEvent => {
1436
+ const actions = {
1437
+ value(event) {
1438
+ event.target.checked = event.detail.value !== "Off";
1439
+ storage.setValue(id, { value: event.target.checked });
1440
+ }
1441
+ };
1442
+ this._dispatchEventFromSandbox(actions, jsEvent);
1443
+ });
1444
+ this._setEventListeners(element, null, [
1445
+ ["change", "Validate"],
1446
+ ["change", "Action"],
1447
+ ["focus", "Focus"],
1448
+ ["blur", "Blur"],
1449
+ ["mousedown", "Mouse Down"],
1450
+ ["mouseenter", "Mouse Enter"],
1451
+ ["mouseleave", "Mouse Exit"],
1452
+ ["mouseup", "Mouse Up"]
1453
+ ], event => event.target.checked);
1454
+ }
1455
+ if (this.enableScripting && this.hasJSActions) {
1456
+ element.addEventListener("updatefromsandbox", jsEvent => {
1457
+ const actions = {
1458
+ value(event) {
1459
+ event.target.checked = event.detail.value !== "Off";
1460
+ storage.setValue(id, { value: event.target.checked });
1461
+ }
1462
+ };
1463
+ this._dispatchEventFromSandbox(actions, jsEvent);
1464
+ });
1465
+ this._setEventListeners(element, null, [
1466
+ ["change", "Validate"],
1467
+ ["change", "Action"],
1468
+ ["focus", "Focus"],
1469
+ ["blur", "Blur"],
1470
+ ["mousedown", "Mouse Down"],
1471
+ ["mouseenter", "Mouse Enter"],
1472
+ ["mouseleave", "Mouse Exit"],
1473
+ ["mouseup", "Mouse Up"]
1474
+ ], event => event.target.checked);
1475
+ }
1476
+ this._setBackgroundColor(element);
1477
+ this._setDefaultPropertiesFromJS(element);
1478
+ this.container.append(element);
1479
+ return this.container;
1480
+ }
1481
+ }
1465
1482
  class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
1466
1483
  constructor(parameters) {
1467
1484
  super(parameters, { isRenderable: parameters.renderForms });
1468
1485
  }
1469
1486
  render() {
1470
- this.container.classList.add("buttonWidgetAnnotation", "radioButton");
1487
+ //this.container.classList.add("buttonWidgetAnnotation", "radioButton");
1488
+ this.container.classList.add("k-button-widget-annotation", "k-radio-button-widget-annotation");
1471
1489
  const storage = this.annotationStorage;
1472
1490
  const data = this.data;
1473
1491
  const id = data.id;
@@ -1551,253 +1569,250 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
1551
1569
  return this.container;
1552
1570
  }
1553
1571
  }
1554
- // class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
1555
- // constructor(parameters) {
1556
- // super(parameters, { ignoreBorder: parameters.data.hasAppearance });
1557
- // }
1558
- // render() {
1559
- // // The rendering and functionality of a push button widget annotation is
1560
- // // equal to that of a link annotation, but may have more functionality, such
1561
- // // as performing actions on form fields (resetting, submitting, et cetera).
1562
- // const container = super.render();
1563
- // container.classList.add("buttonWidgetAnnotation", "pushButton");
1564
- // const linkElement = container.lastChild;
1565
- // if (this.enableScripting && this.hasJSActions && linkElement) {
1566
- // this._setDefaultPropertiesFromJS(linkElement);
1567
- // linkElement.addEventListener("updatefromsandbox", jsEvent => {
1568
- // this._dispatchEventFromSandbox({}, jsEvent);
1569
- // });
1570
- // }
1571
- // return container;
1572
- // }
1573
- // }
1574
- // class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1575
- // constructor(parameters) {
1576
- // super(parameters, { isRenderable: parameters.renderForms });
1577
- // }
1578
- // render() {
1579
- // this.container.classList.add("choiceWidgetAnnotation");
1580
- // const storage = this.annotationStorage;
1581
- // const id = this.data.id;
1582
- // const storedData = storage.getValue(id, {
1583
- // value: this.data.fieldValue,
1584
- // });
1585
- // const selectElement = document.createElement("select");
1586
- // GetElementsByNameSet.add(selectElement);
1587
- // selectElement.setAttribute("data-element-id", id);
1588
- // selectElement.disabled = this.data.readOnly;
1589
- // this._setRequired(selectElement, this.data.required);
1590
- // selectElement.name = this.data.fieldName;
1591
- // selectElement.tabIndex = DEFAULT_TAB_INDEX;
1592
- // let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
1593
- // if (!this.data.combo) {
1594
- // // List boxes have a size and (optionally) multiple selection.
1595
- // selectElement.size = this.data.options.length;
1596
- // if (this.data.multiSelect) {
1597
- // selectElement.multiple = true;
1598
- // }
1599
- // }
1600
- // selectElement.addEventListener("resetform", () => {
1601
- // const defaultValue = this.data.defaultFieldValue;
1602
- // for (const option of (selectElement as any).options) {
1603
- // option.selected = option.value === defaultValue;
1604
- // }
1605
- // });
1606
- // // Insert the options into the choice field.
1607
- // for (const option of this.data.options) {
1608
- // const optionElement = document.createElement("option");
1609
- // optionElement.textContent = option.displayValue;
1610
- // optionElement.value = option.exportValue;
1611
- // if (storedData.value.includes(option.exportValue)) {
1612
- // optionElement.setAttribute("selected", (true).toString());
1613
- // addAnEmptyEntry = false;
1614
- // }
1615
- // selectElement.append(optionElement);
1616
- // }
1617
- // let removeEmptyEntry = null;
1618
- // if (addAnEmptyEntry) {
1619
- // const noneOptionElement = document.createElement("option");
1620
- // noneOptionElement.value = " ";
1621
- // noneOptionElement.setAttribute("hidden", (true).toString());
1622
- // noneOptionElement.setAttribute("selected", (true).toString());
1623
- // selectElement.prepend(noneOptionElement);
1624
- // removeEmptyEntry = () => {
1625
- // noneOptionElement.remove();
1626
- // selectElement.removeEventListener("input", removeEmptyEntry);
1627
- // removeEmptyEntry = null;
1628
- // };
1629
- // selectElement.addEventListener("input", removeEmptyEntry);
1630
- // }
1631
- // const getValue = isExport => {
1632
- // const name = isExport ? "value" : "textContent";
1633
- // const { options, multiple } = selectElement;
1634
- // if (!multiple) {
1635
- // return options.selectedIndex === -1
1636
- // ? null
1637
- // : options[options.selectedIndex][name];
1638
- // }
1639
- // return Array.prototype.filter
1640
- // .call(options, option => option.selected)
1641
- // .map(option => option[name]);
1642
- // };
1643
- // let selectedValues = getValue(/* isExport */ false);
1644
- // const getItems = event => {
1645
- // const options = event.target.options;
1646
- // return Array.prototype.map.call(options, option => ({
1647
- // displayValue: option.textContent,
1648
- // exportValue: option.value,
1649
- // }));
1650
- // };
1651
- // if (this.enableScripting && this.hasJSActions) {
1652
- // selectElement.addEventListener("updatefromsandbox", jsEvent => {
1653
- // const actions = {
1654
- // value(event) {
1655
- // removeEmptyEntry?.();
1656
- // const value = event.detail.value;
1657
- // const values = new Set(Array.isArray(value) ? value : [value]);
1658
- // for (const option of (selectElement as any).options) {
1659
- // option.selected = values.has(option.value);
1660
- // }
1661
- // storage.setValue(id, {
1662
- // value: getValue(/* isExport */ true),
1663
- // });
1664
- // selectedValues = getValue(/* isExport */ false);
1665
- // },
1666
- // multipleSelection() {
1667
- // selectElement.multiple = true;
1668
- // },
1669
- // remove(event) {
1670
- // const options = selectElement.options;
1671
- // const index = event.detail.remove;
1672
- // options[index].selected = false;
1673
- // selectElement.remove(index);
1674
- // if (options.length > 0) {
1675
- // const i = Array.prototype.findIndex.call(
1676
- // options,
1677
- // option => option.selected
1678
- // );
1679
- // if (i === -1) {
1680
- // options[0].selected = true;
1681
- // }
1682
- // }
1683
- // storage.setValue(id, {
1684
- // value: getValue(/* isExport */ true),
1685
- // items: getItems(event),
1686
- // });
1687
- // selectedValues = getValue(/* isExport */ false);
1688
- // },
1689
- // clear() {
1690
- // while (selectElement.length !== 0) {
1691
- // selectElement.remove(0);
1692
- // }
1693
- // storage.setValue(id, { value: null, items: [] });
1694
- // selectedValues = getValue(/* isExport */ false);
1695
- // },
1696
- // insert(event) {
1697
- // const { index, displayValue, exportValue } = event.detail.insert;
1698
- // const selectChild = selectElement.children[index];
1699
- // const optionElement = document.createElement("option");
1700
- // optionElement.textContent = displayValue;
1701
- // optionElement.value = exportValue;
1702
- // if (selectChild) {
1703
- // selectChild.before(optionElement);
1704
- // } else {
1705
- // selectElement.append(optionElement);
1706
- // }
1707
- // storage.setValue(id, {
1708
- // value: getValue(/* isExport */ true),
1709
- // items: getItems(event),
1710
- // });
1711
- // selectedValues = getValue(/* isExport */ false);
1712
- // },
1713
- // items(event) {
1714
- // const { items } = event.detail;
1715
- // while (selectElement.length !== 0) {
1716
- // selectElement.remove(0);
1717
- // }
1718
- // for (const item of items) {
1719
- // const { displayValue, exportValue } = item;
1720
- // const optionElement = document.createElement("option");
1721
- // optionElement.textContent = displayValue;
1722
- // optionElement.value = exportValue;
1723
- // selectElement.append(optionElement);
1724
- // }
1725
- // if (selectElement.options.length > 0) {
1726
- // selectElement.options[0].selected = true;
1727
- // }
1728
- // storage.setValue(id, {
1729
- // value: getValue(/* isExport */ true),
1730
- // items: getItems(event),
1731
- // });
1732
- // selectedValues = getValue(/* isExport */ false);
1733
- // },
1734
- // indices(event) {
1735
- // const indices = new Set(event.detail.indices);
1736
- // for (const option of event.target.options) {
1737
- // option.selected = indices.has(option.index);
1738
- // }
1739
- // storage.setValue(id, {
1740
- // value: getValue(/* isExport */ true),
1741
- // });
1742
- // selectedValues = getValue(/* isExport */ false);
1743
- // },
1744
- // editable(event) {
1745
- // event.target.disabled = !event.detail.editable;
1746
- // },
1747
- // };
1748
- // this._dispatchEventFromSandbox(actions, jsEvent);
1749
- // });
1750
- // selectElement.addEventListener("input", event => {
1751
- // const exportValue = getValue(/* isExport */ true);
1752
- // const change = getValue(/* isExport */ false);
1753
- // storage.setValue(id, { value: exportValue });
1754
- // event.preventDefault();
1755
- // this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
1756
- // source: this,
1757
- // detail: {
1758
- // id,
1759
- // name: "Keystroke",
1760
- // value: selectedValues,
1761
- // change,
1762
- // changeEx: exportValue,
1763
- // willCommit: false,
1764
- // commitKey: 1,
1765
- // keyDown: false,
1766
- // },
1767
- // });
1768
- // });
1769
- // this._setEventListeners(
1770
- // selectElement,
1771
- // null,
1772
- // [
1773
- // ["focus", "Focus"],
1774
- // ["blur", "Blur"],
1775
- // ["mousedown", "Mouse Down"],
1776
- // ["mouseenter", "Mouse Enter"],
1777
- // ["mouseleave", "Mouse Exit"],
1778
- // ["mouseup", "Mouse Up"],
1779
- // ["input", "Action"],
1780
- // ["input", "Validate"],
1781
- // ],
1782
- // event => event.target.value
1783
- // );
1784
- // } else {
1785
- // selectElement.addEventListener("input", function () {
1786
- // storage.setValue(id, { value: getValue(/* isExport */ true) });
1787
- // });
1788
- // }
1789
- // if (this.data.combo) {
1790
- // this._setTextStyle(selectElement);
1791
- // } else {
1792
- // // Just use the default font size...
1793
- // // it's a bit hard to guess what is a good size.
1794
- // }
1795
- // this._setBackgroundColor(selectElement);
1796
- // this._setDefaultPropertiesFromJS(selectElement);
1797
- // this.container.append(selectElement);
1798
- // return this.container;
1799
- // }
1800
- // }
1572
+ class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
1573
+ constructor(parameters) {
1574
+ super(parameters, { ignoreBorder: parameters.data.hasAppearance });
1575
+ }
1576
+ render() {
1577
+ // The rendering and functionality of a push button widget annotation is
1578
+ // equal to that of a link annotation, but may have more functionality, such
1579
+ // as performing actions on form fields (resetting, submitting, et cetera).
1580
+ const container = super.render();
1581
+ //container.classList.add("buttonWidgetAnnotation", "pushButton");
1582
+ this.container.classList.add("k-button-widget-annotation", "k-push-button-widget-annotation");
1583
+ const linkElement = container.lastChild;
1584
+ if (this.enableScripting && this.hasJSActions && linkElement) {
1585
+ this._setDefaultPropertiesFromJS(linkElement);
1586
+ linkElement.addEventListener("updatefromsandbox", jsEvent => {
1587
+ this._dispatchEventFromSandbox({}, jsEvent);
1588
+ });
1589
+ }
1590
+ return container;
1591
+ }
1592
+ }
1593
+ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1594
+ constructor(parameters) {
1595
+ super(parameters, { isRenderable: parameters.renderForms });
1596
+ }
1597
+ render() {
1598
+ this.container.classList.add("choiceWidgetAnnotation");
1599
+ const storage = this.annotationStorage;
1600
+ const id = this.data.id;
1601
+ const storedData = storage.getValue(id, {
1602
+ value: this.data.fieldValue
1603
+ });
1604
+ const selectElement = document.createElement("select");
1605
+ GetElementsByNameSet.add(selectElement);
1606
+ selectElement.setAttribute("data-element-id", id);
1607
+ selectElement.disabled = this.data.readOnly;
1608
+ this._setRequired(selectElement, this.data.required);
1609
+ selectElement.name = this.data.fieldName;
1610
+ selectElement.tabIndex = DEFAULT_TAB_INDEX;
1611
+ let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
1612
+ if (!this.data.combo) {
1613
+ // List boxes have a size and (optionally) multiple selection.
1614
+ selectElement.size = this.data.options.length;
1615
+ if (this.data.multiSelect) {
1616
+ selectElement.multiple = true;
1617
+ }
1618
+ }
1619
+ selectElement.addEventListener("resetform", () => {
1620
+ const defaultValue = this.data.defaultFieldValue;
1621
+ for (const option of selectElement.options) {
1622
+ option.selected = option.value === defaultValue;
1623
+ }
1624
+ });
1625
+ // Insert the options into the choice field.
1626
+ for (const option of this.data.options) {
1627
+ const optionElement = document.createElement("option");
1628
+ optionElement.textContent = option.displayValue;
1629
+ optionElement.value = option.exportValue;
1630
+ if (storedData.value.includes(option.exportValue)) {
1631
+ optionElement.setAttribute("selected", (true).toString());
1632
+ addAnEmptyEntry = false;
1633
+ }
1634
+ selectElement.append(optionElement);
1635
+ }
1636
+ let removeEmptyEntry = null;
1637
+ if (addAnEmptyEntry) {
1638
+ const noneOptionElement = document.createElement("option");
1639
+ noneOptionElement.value = " ";
1640
+ noneOptionElement.setAttribute("hidden", (true).toString());
1641
+ noneOptionElement.setAttribute("selected", (true).toString());
1642
+ selectElement.prepend(noneOptionElement);
1643
+ removeEmptyEntry = () => {
1644
+ noneOptionElement.remove();
1645
+ selectElement.removeEventListener("input", removeEmptyEntry);
1646
+ removeEmptyEntry = null;
1647
+ };
1648
+ selectElement.addEventListener("input", removeEmptyEntry);
1649
+ }
1650
+ const getValue = isExport => {
1651
+ const name = isExport ? "value" : "textContent";
1652
+ const { options, multiple } = selectElement;
1653
+ if (!multiple) {
1654
+ return options.selectedIndex === -1
1655
+ ? null
1656
+ : options[options.selectedIndex][name];
1657
+ }
1658
+ return Array.prototype.filter
1659
+ .call(options, option => option.selected)
1660
+ .map(option => option[name]);
1661
+ };
1662
+ let selectedValues = getValue(/* isExport */ false);
1663
+ const getItems = event => {
1664
+ const options = event.target.options;
1665
+ return Array.prototype.map.call(options, option => ({
1666
+ displayValue: option.textContent,
1667
+ exportValue: option.value
1668
+ }));
1669
+ };
1670
+ if (this.enableScripting && this.hasJSActions) {
1671
+ selectElement.addEventListener("updatefromsandbox", jsEvent => {
1672
+ const actions = {
1673
+ value(event) {
1674
+ removeEmptyEntry === null || removeEmptyEntry === void 0 ? void 0 : removeEmptyEntry();
1675
+ const value = event.detail.value;
1676
+ const values = new Set(Array.isArray(value) ? value : [value]);
1677
+ for (const option of selectElement.options) {
1678
+ option.selected = values.has(option.value);
1679
+ }
1680
+ storage.setValue(id, {
1681
+ value: getValue(/* isExport */ true)
1682
+ });
1683
+ selectedValues = getValue(/* isExport */ false);
1684
+ },
1685
+ multipleSelection() {
1686
+ selectElement.multiple = true;
1687
+ },
1688
+ remove(event) {
1689
+ const options = selectElement.options;
1690
+ const index = event.detail.remove;
1691
+ options[index].selected = false;
1692
+ selectElement.remove(index);
1693
+ if (options.length > 0) {
1694
+ const i = Array.prototype.findIndex.call(options, option => option.selected);
1695
+ if (i === -1) {
1696
+ options[0].selected = true;
1697
+ }
1698
+ }
1699
+ storage.setValue(id, {
1700
+ value: getValue(/* isExport */ true),
1701
+ items: getItems(event)
1702
+ });
1703
+ selectedValues = getValue(/* isExport */ false);
1704
+ },
1705
+ clear() {
1706
+ while (selectElement.length !== 0) {
1707
+ selectElement.remove(0);
1708
+ }
1709
+ storage.setValue(id, { value: null, items: [] });
1710
+ selectedValues = getValue(/* isExport */ false);
1711
+ },
1712
+ insert(event) {
1713
+ const { index, displayValue, exportValue } = event.detail.insert;
1714
+ const selectChild = selectElement.children[index];
1715
+ const optionElement = document.createElement("option");
1716
+ optionElement.textContent = displayValue;
1717
+ optionElement.value = exportValue;
1718
+ if (selectChild) {
1719
+ selectChild.before(optionElement);
1720
+ }
1721
+ else {
1722
+ selectElement.append(optionElement);
1723
+ }
1724
+ storage.setValue(id, {
1725
+ value: getValue(/* isExport */ true),
1726
+ items: getItems(event)
1727
+ });
1728
+ selectedValues = getValue(/* isExport */ false);
1729
+ },
1730
+ items(event) {
1731
+ const { items } = event.detail;
1732
+ while (selectElement.length !== 0) {
1733
+ selectElement.remove(0);
1734
+ }
1735
+ for (const item of items) {
1736
+ const { displayValue, exportValue } = item;
1737
+ const optionElement = document.createElement("option");
1738
+ optionElement.textContent = displayValue;
1739
+ optionElement.value = exportValue;
1740
+ selectElement.append(optionElement);
1741
+ }
1742
+ if (selectElement.options.length > 0) {
1743
+ selectElement.options[0].selected = true;
1744
+ }
1745
+ storage.setValue(id, {
1746
+ value: getValue(/* isExport */ true),
1747
+ items: getItems(event)
1748
+ });
1749
+ selectedValues = getValue(/* isExport */ false);
1750
+ },
1751
+ indices(event) {
1752
+ const indices = new Set(event.detail.indices);
1753
+ for (const option of event.target.options) {
1754
+ option.selected = indices.has(option.index);
1755
+ }
1756
+ storage.setValue(id, {
1757
+ value: getValue(/* isExport */ true)
1758
+ });
1759
+ selectedValues = getValue(/* isExport */ false);
1760
+ },
1761
+ editable(event) {
1762
+ event.target.disabled = !event.detail.editable;
1763
+ }
1764
+ };
1765
+ this._dispatchEventFromSandbox(actions, jsEvent);
1766
+ });
1767
+ selectElement.addEventListener("input", event => {
1768
+ var _a;
1769
+ const exportValue = getValue(/* isExport */ true);
1770
+ const change = getValue(/* isExport */ false);
1771
+ storage.setValue(id, { value: exportValue });
1772
+ event.preventDefault();
1773
+ (_a = this.linkService.eventBus) === null || _a === void 0 ? void 0 : _a.dispatch("dispatcheventinsandbox", {
1774
+ source: this,
1775
+ detail: {
1776
+ id,
1777
+ name: "Keystroke",
1778
+ value: selectedValues,
1779
+ change,
1780
+ changeEx: exportValue,
1781
+ willCommit: false,
1782
+ commitKey: 1,
1783
+ keyDown: false
1784
+ }
1785
+ });
1786
+ });
1787
+ this._setEventListeners(selectElement, null, [
1788
+ ["focus", "Focus"],
1789
+ ["blur", "Blur"],
1790
+ ["mousedown", "Mouse Down"],
1791
+ ["mouseenter", "Mouse Enter"],
1792
+ ["mouseleave", "Mouse Exit"],
1793
+ ["mouseup", "Mouse Up"],
1794
+ ["input", "Action"],
1795
+ ["input", "Validate"]
1796
+ ], event => event.target.value);
1797
+ }
1798
+ else {
1799
+ selectElement.addEventListener("input", function () {
1800
+ storage.setValue(id, { value: getValue(/* isExport */ true) });
1801
+ });
1802
+ }
1803
+ if (this.data.combo) {
1804
+ this._setTextStyle(selectElement);
1805
+ }
1806
+ else {
1807
+ // Just use the default font size...
1808
+ // it's a bit hard to guess what is a good size.
1809
+ }
1810
+ this._setBackgroundColor(selectElement);
1811
+ this._setDefaultPropertiesFromJS(selectElement);
1812
+ this.container.append(selectElement);
1813
+ return this.container;
1814
+ }
1815
+ }
1801
1816
  class PopupAnnotationElement extends AnnotationElement {
1802
1817
  // todo: props
1803
1818
  constructor(parameters) {
@@ -2683,7 +2698,7 @@ class AnnotationLayer {
2683
2698
  imageResourcesPath: params.imageResourcesPath || "",
2684
2699
  renderForms: params.renderForms !== false,
2685
2700
  svgFactory: new pdf_mjs_1.DOMSVGFactory(),
2686
- annotationStorage: params.annotationStorage,
2701
+ annotationStorage: params.annotationStorage || new annotation_storage_1.AnnotationStorage(),
2687
2702
  enableScripting: params.enableScripting === true,
2688
2703
  hasJSActions: params.hasJSActions,
2689
2704
  fieldObjects: params.fieldObjects,
@@ -2755,6 +2770,12 @@ class AnnotationLayer {
2755
2770
  getEditableAnnotation(id) {
2756
2771
  return tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_editableAnnotations, "f").get(id);
2757
2772
  }
2773
+ destroy() {
2774
+ var _a, _b;
2775
+ (_a = tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_annotationCanvasMap, "f")) === null || _a === void 0 ? void 0 : _a.clear();
2776
+ (_b = this.div) === null || _b === void 0 ? void 0 : _b.remove();
2777
+ this.div = null;
2778
+ }
2758
2779
  }
2759
2780
  exports.AnnotationLayer = AnnotationLayer;
2760
2781
  _AnnotationLayer_accessibilityManager = new WeakMap(), _AnnotationLayer_annotationCanvasMap = new WeakMap(), _AnnotationLayer_editableAnnotations = new WeakMap(), _AnnotationLayer_instances = new WeakSet(), _AnnotationLayer_appendElement = function _AnnotationLayer_appendElement(element, id) {