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