react-pdf-editor-1 1.2.36

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 (133) hide show
  1. package/.babelrc +3 -0
  2. package/LICENSE +2 -0
  3. package/README.md +315 -0
  4. package/dist/index.js +526 -0
  5. package/package.json +33 -0
  6. package/public/01fd34b01abf8d0a1fdb3c10f95146cd.svg +7 -0
  7. package/public/025954f8cad47e40240e15487d1e396c.svg +17 -0
  8. package/public/105d10237b3dddb56304b2af06fab51c.svg +8 -0
  9. package/public/10879587954149cc5fd694c7785e9d3a.svg +8 -0
  10. package/public/15cba32d3c729060a92912d969d1cc2c.svg +17 -0
  11. package/public/1964539986cd6aea3baee0f32a61923e.svg +4 -0
  12. package/public/1c0b882b730b22fbd7d42b68bd0a970e.svg +2 -0
  13. package/public/1d66d40875fa58261ff4b850e8cba7cc.svg +5 -0
  14. package/public/22b31630cb8b4b2ad58da61bb133ab1f.svg +8 -0
  15. package/public/2d62d3d287fbc3c497dddab32168f325.svg +4 -0
  16. package/public/31f31a1074e7f19fde072c1158a8e6a0.svg +14 -0
  17. package/public/3659a716673b2dd214d961c5feb3caa6.svg +4 -0
  18. package/public/3bc689e0aff9db355266a7b3be92e9d0.svg +4 -0
  19. package/public/3eb1d80899f968c9398d1c08a5350b2d.svg +4 -0
  20. package/public/4c63cae958b5685dfd85cda1b06787fe.svg +17 -0
  21. package/public/50842dfca45fc95070e4fdd2259db45c.svg +4 -0
  22. package/public/536890911d2db783d87b77a39b74f396.svg +4 -0
  23. package/public/71edf29951e1e0d3b50d9562bc7a5049.svg +14 -0
  24. package/public/79ee5b45e590be841daeba9d60e7db6e.svg +5 -0
  25. package/public/839d642763fa2703bfa92fcdbaa0397c.svg +17 -0
  26. package/public/8639ab06d026e5d60849b007b6f432b6.svg +14 -0
  27. package/public/9209f692646c3a0d4fb372037a3d7237.svg +4 -0
  28. package/public/96ba4601cfdb560093692ac2d34260dd.svg +8 -0
  29. package/public/9c36754c195ca83d24a39e75ef3821c0.svg +4 -0
  30. package/public/9f41f6f39d1736d2782a934fea979c01.svg +4 -0
  31. package/public/a24af8321bcb23961c196b0b4fce89c7.svg +17 -0
  32. package/public/a3f2a45a2d94e515bc17ea9740631aa0.svg +6 -0
  33. package/public/a51521eadbd56edc63eb19bc5a41a598.svg +5 -0
  34. package/public/a7a14359ef6035eb03282f98500c02f3.svg +17 -0
  35. package/public/b4d7375b688647fc2e477f9d911f1e2e.svg +17 -0
  36. package/public/b947e1da1eac39e0ff7f9b7c1f944f52.svg +17 -0
  37. package/public/bundle.js +2 -0
  38. package/public/bundle.js.LICENSE.txt +32 -0
  39. package/public/c0ab9ce68d42392fb8fc13f7089c9518.svg +5 -0
  40. package/public/c69a80a1cc748b27d5ee83d3951bc956.svg +4 -0
  41. package/public/c6ac6e95ae6fe2f0391da8fa2e9c8554.svg +14 -0
  42. package/public/d538166f1033a89b5d2735aecea91c62.svg +5 -0
  43. package/public/d84737c082efeea55189a8196ac9236c.svg +17 -0
  44. package/public/e19e4765f223f61db42d28f92ddbcd4e.svg +5 -0
  45. package/public/e80893668bffe9e8e3c09306c073cf30.svg +2 -0
  46. package/public/eb7981a1b3a89b6cfce8722d72214fde.svg +17 -0
  47. package/public/eccb83ba375a1929a3f18ba30694c231.svg +5 -0
  48. package/public/ee12777ac448b2018f768c80fb248e9c.svg +4 -0
  49. package/public/f646afcaa121a7b8d388826e30f410c1.svg +4 -0
  50. package/public/ff2dfa442d903d9d5e30.gif +0 -0
  51. package/public/index.html +1 -0
  52. package/public/pdf-ui/033ea05cff39966fc00030593f62d81f.svg +5 -0
  53. package/public/pdf-ui/0353d3a6acc37ec6b16e6bf353926342.svg +15 -0
  54. package/public/pdf-ui/045352e9aa7d98994484ffb8ec3dbe38.svg +4 -0
  55. package/public/pdf-ui/067c6de2adec31f57b18.gif +1 -0
  56. package/public/pdf-ui/088c54c203716cb1be7190bb6075efb6.png +0 -0
  57. package/public/pdf-ui/0d18d81ca415c6007655b836f84e4219.svg +8 -0
  58. package/public/pdf-ui/15cba32d3c729060a92912d969d1cc2c.svg +17 -0
  59. package/public/pdf-ui/1c0b882b730b22fbd7d42b68bd0a970e.svg +2 -0
  60. package/public/pdf-ui/1c5917d73900d5039cd8.gif +1 -0
  61. package/public/pdf-ui/1d66d40875fa58261ff4b850e8cba7cc.svg +5 -0
  62. package/public/pdf-ui/1ec9099f99fb29fd2f6862878724a0a3.svg +5 -0
  63. package/public/pdf-ui/22b31630cb8b4b2ad58da61bb133ab1f.svg +8 -0
  64. package/public/pdf-ui/2a087ab7d6db0961c9a3.gif +1 -0
  65. package/public/pdf-ui/2c98033a3b632f65d3ec.wasm +0 -0
  66. package/public/pdf-ui/2d857cb345dc7c8dbece3d62a20f09bd.svg +5 -0
  67. package/public/pdf-ui/325f20a2786a21caee0f924078e07d71.svg +2 -0
  68. package/public/pdf-ui/35d6b608bc295d96f7fd45b93b27706c.svg +8 -0
  69. package/public/pdf-ui/3659a716673b2dd214d961c5feb3caa6.svg +4 -0
  70. package/public/pdf-ui/3bc689e0aff9db355266a7b3be92e9d0.svg +4 -0
  71. package/public/pdf-ui/3e8dbb8345f70b7b4c36bb1ad05dfe7e.svg +4 -0
  72. package/public/pdf-ui/3eb1d80899f968c9398d1c08a5350b2d.svg +4 -0
  73. package/public/pdf-ui/4ab3dd8677ef3699fc53c7328a3ae1c6.svg +2 -0
  74. package/public/pdf-ui/4c63cae958b5685dfd85cda1b06787fe.svg +17 -0
  75. package/public/pdf-ui/4dc3c7d029346b6ca3318f0e60ccfe87.svg +4 -0
  76. package/public/pdf-ui/4e9b9c2bcbd6c3737c340cd5bebefd8c.svg +6 -0
  77. package/public/pdf-ui/4ebd2633a2d5debf8a4e568b7985be7e.svg +4 -0
  78. package/public/pdf-ui/50842dfca45fc95070e4fdd2259db45c.svg +4 -0
  79. package/public/pdf-ui/5087ceef6868b5ab32a1.svg +1 -0
  80. package/public/pdf-ui/536890911d2db783d87b77a39b74f396.svg +4 -0
  81. package/public/pdf-ui/53f17281bc4dffa3a650442bfb07d321.svg +4 -0
  82. package/public/pdf-ui/586876b8baad663cfcb1.svg +1 -0
  83. package/public/pdf-ui/59fe962b3e6bd8bfdda7a104ebfba9e9.svg +3 -0
  84. package/public/pdf-ui/5a84e180ec596169981c831f0288374a.svg +19 -0
  85. package/public/pdf-ui/5e9941f27dabbef172bdaf2deccb70f6.svg +11 -0
  86. package/public/pdf-ui/5ea0869845becef03a065090fee2a9a5.svg +4 -0
  87. package/public/pdf-ui/6529e96a9906058150e3de021602f1d9.svg +4 -0
  88. package/public/pdf-ui/65c76ef6e36e34a13364a8127e57b18e.svg +4 -0
  89. package/public/pdf-ui/79edeed2414d6ac5ec44.svg +1 -0
  90. package/public/pdf-ui/79ee5b45e590be841daeba9d60e7db6e.svg +5 -0
  91. package/public/pdf-ui/80a30e134dde30c967de.svg +1 -0
  92. package/public/pdf-ui/854c025f76bbfdf1a6c3db5a8db6abb4.svg +11 -0
  93. package/public/pdf-ui/8be7b158d340ed4fd589.svg +1 -0
  94. package/public/pdf-ui/8d64a1271d5126b8cb78.svg +1 -0
  95. package/public/pdf-ui/9c36754c195ca83d24a39e75ef3821c0.svg +4 -0
  96. package/public/pdf-ui/9fb032a1799ca2a1c7518895c7533af2.svg +3 -0
  97. package/public/pdf-ui/a64081b14b23b34ed10bb1183be53747.png +0 -0
  98. package/public/pdf-ui/ac0f6afbea0be2b67f8b2dc2f40fdf4b.svg +4 -0
  99. package/public/pdf-ui/assets/blue-bg-5-2.png +0 -0
  100. package/public/pdf-ui/assets/blue-bg-500-150.png +0 -0
  101. package/public/pdf-ui/assets/color-wheel.png +0 -0
  102. package/public/pdf-ui/assets/signature-bg.png +0 -0
  103. package/public/pdf-ui/assets/signature-icon.png +0 -0
  104. package/public/pdf-ui/assets/yellow-bg-5-4.png +0 -0
  105. package/public/pdf-ui/assets/yellow-bg-500-150.png +0 -0
  106. package/public/pdf-ui/b1db19c0847c6c911193d6b9b48ae9df.svg +2 -0
  107. package/public/pdf-ui/b722fb1fa619a347bb3fe0e24b0c40cc.png +0 -0
  108. package/public/pdf-ui/bb72d81b39be40898db21e81272dbf39.svg +3 -0
  109. package/public/pdf-ui/bundle.js +3 -0
  110. package/public/pdf-ui/bundle.js.LICENSE.txt +74 -0
  111. package/public/pdf-ui/bundle.js.map +1 -0
  112. package/public/pdf-ui/c69a80a1cc748b27d5ee83d3951bc956.svg +4 -0
  113. package/public/pdf-ui/c6a3cd10a29122c87d0aff12229e1539.svg +4 -0
  114. package/public/pdf-ui/c6ac6e95ae6fe2f0391da8fa2e9c8554.svg +14 -0
  115. package/public/pdf-ui/c85c0ff9534eda6ec97b1f5c7c80d994.svg +4 -0
  116. package/public/pdf-ui/ccb5b2b4f2a6efbac0194acb7dd27875.svg +4 -0
  117. package/public/pdf-ui/d4a0946ca523e1a07119c30351cdc625.svg +8 -0
  118. package/public/pdf-ui/de62f36b83bb7ae79e7f4499387ee87e.svg +4 -0
  119. package/public/pdf-ui/e19e4765f223f61db42d28f92ddbcd4e.svg +5 -0
  120. package/public/pdf-ui/e80893668bffe9e8e3c09306c073cf30.svg +2 -0
  121. package/public/pdf-ui/f20333b6d7b1530454d1ea949f337c4d.svg +5 -0
  122. package/public/pdf-ui/f8f9feb56bfaf57527c21e854ad43533.svg +5 -0
  123. package/public/pdf-ui/ff2dfa442d903d9d5e30.gif +0 -0
  124. package/public/pdf-ui/ff2dfa442d903d9d5e303345b82e5415.gif +0 -0
  125. package/public/pdf-ui/index.html +1 -0
  126. package/public/pdf-ui/lib/pdf.worker.js +2 -0
  127. package/public/pdf-ui/lib/pdf.worker.js.LICENSE.txt +21 -0
  128. package/public/pdf-ui/lib/pdf_wasm_project.js +1 -0
  129. package/public/pdf-ui/lib/pdf_wasm_project_bg.wasm +0 -0
  130. package/public/pdf-ui/node_modules/alien35-pf/web/images/loading-icon.gif +0 -0
  131. package/public/pdf-ui/node_modules/pdfjs-dist/web/images/loading-icon.gif +0 -0
  132. package/src/index.d.ts +33 -0
  133. package/src/index.js +374 -0
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @licstart The following is the entire license notice for the
3
+ * JavaScript code in this page
4
+ *
5
+ * Copyright 2023 Mozilla Foundation
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * @licend The above is the entire license notice for the
20
+ * JavaScript code in this page
21
+ */
@@ -0,0 +1 @@
1
+ let wasm;const cachedTextDecoder="undefined"!=typeof TextDecoder?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):{decode:()=>{throw Error("TextDecoder not available")}};"undefined"!=typeof TextDecoder&&cachedTextDecoder.decode();let cachedUint8Memory0=null;function getUint8Memory0(){return null!==cachedUint8Memory0&&0!==cachedUint8Memory0.byteLength||(cachedUint8Memory0=new Uint8Array(wasm.memory.buffer)),cachedUint8Memory0}function getStringFromWasm0(e,t){return e>>>=0,cachedTextDecoder.decode(getUint8Memory0().subarray(e,e+t))}const heap=new Array(128).fill(void 0);heap.push(void 0,null,!0,!1);let heap_next=heap.length;function addHeapObject(e){heap_next===heap.length&&heap.push(heap.length+1);const t=heap_next;return heap_next=heap[t],heap[t]=e,t}function getObject(e){return heap[e]}function dropObject(e){e<132||(heap[e]=heap_next,heap_next=e)}function takeObject(e){const t=getObject(e);return dropObject(e),t}let WASM_VECTOR_LEN=0;const cachedTextEncoder="undefined"!=typeof TextEncoder?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},encodeString="function"==typeof cachedTextEncoder.encodeInto?function(e,t){return cachedTextEncoder.encodeInto(e,t)}:function(e,t){const n=cachedTextEncoder.encode(e);return t.set(n),{read:e.length,written:n.length}};function passStringToWasm0(e,t,n){if(void 0===n){const n=cachedTextEncoder.encode(e),r=t(n.length,1)>>>0;return getUint8Memory0().subarray(r,r+n.length).set(n),WASM_VECTOR_LEN=n.length,r}let r=e.length,o=t(r,1)>>>0;const a=getUint8Memory0();let _=0;for(;_<r;_++){const t=e.charCodeAt(_);if(t>127)break;a[o+_]=t}if(_!==r){0!==_&&(e=e.slice(_)),o=n(o,r,r=_+3*e.length,1)>>>0;const t=getUint8Memory0().subarray(o+_,o+r);_+=encodeString(e,t).written}return WASM_VECTOR_LEN=_,o}let cachedInt32Memory0=null;function getInt32Memory0(){return null!==cachedInt32Memory0&&0!==cachedInt32Memory0.byteLength||(cachedInt32Memory0=new Int32Array(wasm.memory.buffer)),cachedInt32Memory0}export function start(){wasm.start()}function passArray8ToWasm0(e,t){const n=t(1*e.length,1)>>>0;return getUint8Memory0().set(e,n/1),WASM_VECTOR_LEN=e.length,n}let cachedUint32Memory0=null;function getUint32Memory0(){return null!==cachedUint32Memory0&&0!==cachedUint32Memory0.byteLength||(cachedUint32Memory0=new Uint32Array(wasm.memory.buffer)),cachedUint32Memory0}function passArray32ToWasm0(e,t){const n=t(4*e.length,4)>>>0;return getUint32Memory0().set(e,n/4),WASM_VECTOR_LEN=e.length,n}function getArrayU8FromWasm0(e,t){return e>>>=0,getUint8Memory0().subarray(e/1,e/1+t)}export function remove_pages(e,t){try{const n=wasm.__wbindgen_add_to_stack_pointer(-16),r=passArray8ToWasm0(e,wasm.__wbindgen_malloc),o=WASM_VECTOR_LEN,a=passArray32ToWasm0(t,wasm.__wbindgen_malloc),_=WASM_VECTOR_LEN;wasm.remove_pages(n,r,o,a,_);let i=getInt32Memory0()[n/4+0],s=getInt32Memory0()[n/4+1],c=getInt32Memory0()[n/4+2];if(getInt32Memory0()[n/4+3])throw takeObject(c);let m=getArrayU8FromWasm0(i,s).slice();return wasm.__wbindgen_free(i,1*s),m}finally{wasm.__wbindgen_add_to_stack_pointer(16)}}export function move_pages(e,t){try{const n=wasm.__wbindgen_add_to_stack_pointer(-16),r=passArray8ToWasm0(e,wasm.__wbindgen_malloc),o=WASM_VECTOR_LEN,a=passArray32ToWasm0(t,wasm.__wbindgen_malloc),_=WASM_VECTOR_LEN;wasm.move_pages(n,r,o,a,_);let i=getInt32Memory0()[n/4+0],s=getInt32Memory0()[n/4+1],c=getInt32Memory0()[n/4+2];if(getInt32Memory0()[n/4+3])throw takeObject(c);let m=getArrayU8FromWasm0(i,s).slice();return wasm.__wbindgen_free(i,1*s),m}finally{wasm.__wbindgen_add_to_stack_pointer(16)}}export function move_page(e,t,n){try{const r=wasm.__wbindgen_add_to_stack_pointer(-16),o=passArray8ToWasm0(e,wasm.__wbindgen_malloc),a=WASM_VECTOR_LEN;wasm.move_page(r,o,a,t,n);let _=getInt32Memory0()[r/4+0],i=getInt32Memory0()[r/4+1],s=getInt32Memory0()[r/4+2];if(getInt32Memory0()[r/4+3])throw takeObject(s);let c=getArrayU8FromWasm0(_,i).slice();return wasm.__wbindgen_free(_,1*i),c}finally{wasm.__wbindgen_add_to_stack_pointer(16)}}export function rotate_pages(e,t,n){try{const r=wasm.__wbindgen_add_to_stack_pointer(-16),o=passArray8ToWasm0(e,wasm.__wbindgen_malloc),a=WASM_VECTOR_LEN,_=passArray32ToWasm0(t,wasm.__wbindgen_malloc),i=WASM_VECTOR_LEN;wasm.rotate_pages(r,o,a,_,i,n);let s=getInt32Memory0()[r/4+0],c=getInt32Memory0()[r/4+1],m=getInt32Memory0()[r/4+2];if(getInt32Memory0()[r/4+3])throw takeObject(m);let g=getArrayU8FromWasm0(s,c).slice();return wasm.__wbindgen_free(s,1*c),g}finally{wasm.__wbindgen_add_to_stack_pointer(16)}}let stack_pointer=128;function addBorrowedObject(e){if(1==stack_pointer)throw new Error("out of js stack");return heap[--stack_pointer]=e,stack_pointer}export function merge_pdfs(e){try{const t=wasm.__wbindgen_add_to_stack_pointer(-16);wasm.merge_pdfs(t,addBorrowedObject(e));let n=getInt32Memory0()[t/4+0],r=getInt32Memory0()[t/4+1],o=getInt32Memory0()[t/4+2];if(getInt32Memory0()[t/4+3])throw takeObject(o);let a=getArrayU8FromWasm0(n,r).slice();return wasm.__wbindgen_free(n,1*r),a}finally{wasm.__wbindgen_add_to_stack_pointer(16),heap[stack_pointer++]=void 0}}async function __wbg_load(e,t){if("function"==typeof Response&&e instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if("application/wasm"==e.headers.get("Content-Type"))throw t;console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t)}const n=await e.arrayBuffer();return await WebAssembly.instantiate(n,t)}const n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function __wbg_get_imports(){const e={wbg:{}};return e.wbg.__wbindgen_string_new=function(e,t){return addHeapObject(getStringFromWasm0(e,t))},e.wbg.__wbindgen_object_drop_ref=function(e){takeObject(e)},e.wbg.__wbindgen_json_serialize=function(e,t){const n=getObject(t),r=passStringToWasm0(JSON.stringify(void 0===n?null:n),wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),o=WASM_VECTOR_LEN;getInt32Memory0()[e/4+1]=o,getInt32Memory0()[e/4+0]=r},e.wbg.__wbg_new_abda76e883ba8a5f=function(){return addHeapObject(new Error)},e.wbg.__wbg_stack_658279fe44541cf6=function(e,t){const n=passStringToWasm0(getObject(t).stack,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),r=WASM_VECTOR_LEN;getInt32Memory0()[e/4+1]=r,getInt32Memory0()[e/4+0]=n},e.wbg.__wbg_error_f851667af71bcfc6=function(e,t){let n,r;try{n=e,r=t,console.error(getStringFromWasm0(e,t))}finally{wasm.__wbindgen_free(n,r,1)}},e.wbg.__wbindgen_throw=function(e,t){throw new Error(getStringFromWasm0(e,t))},e}function __wbg_init_memory(e,t){}function __wbg_finalize_init(e,t){return wasm=e.exports,__wbg_init.__wbindgen_wasm_module=t,cachedInt32Memory0=null,cachedUint32Memory0=null,cachedUint8Memory0=null,wasm.__wbindgen_start(),wasm}function initSync(e){if(void 0!==wasm)return wasm;const t=__wbg_get_imports();return __wbg_init_memory(t),e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e)),__wbg_finalize_init(new WebAssembly.Instance(e,t),e)}async function __wbg_init(e){if(void 0!==wasm)return wasm;void 0===e&&(e=new URL("pdf_wasm_project_bg.wasm",import.meta.url));const t=__wbg_get_imports();("string"==typeof e||"function"==typeof Request&&e instanceof Request||"function"==typeof URL&&e instanceof URL)&&(e=fetch(e)),__wbg_init_memory(t);const{instance:n,module:r}=await __wbg_load(await e,t);return __wbg_finalize_init(n,r)}export{initSync};export default __wbg_init;
package/src/index.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import * as React from 'react';
2
+
3
+ declare module 'pdf_editor_aleon35_react_plugin' {
4
+ export const useCreateIframeAndLoadViewer: (
5
+ props: {
6
+ files: {name: string, url: string}[];
7
+ uuid?: string;
8
+ licenseKey: string;
9
+ tools: {
10
+ thumbnails?: ("zoom" | "expand")[];
11
+ general?: ("zoom" | "search" | "download" | "thumbnails" | "panel-toggle")[];
12
+ editing?: ("remove" | "rotation" | "extract" | "move")[];
13
+ };
14
+ container: React.MutableRefObject<HTMLElement | null> | (HTMLElement | null);
15
+ locale?: "en" | "es" | "ru",
16
+ mode?: "split" | "regular",
17
+ fileName?: string;
18
+ onFileFailed?: (message: string) => void;
19
+ }
20
+ ) => {
21
+ combineFiles: () => void;
22
+ pagesLoaded: string;
23
+ download: () => void;
24
+ isReady: boolean;
25
+ toggleFullScreenThumbnails: (newValue?: boolean) => void;
26
+ setThumbnailZoom: (value: boolean) => void;
27
+ toggleSearchbar: (value: boolean) => void;
28
+ removeChatHistory: () => void;
29
+ splitPages: () => void;
30
+ extractPages: () => void;
31
+ selectedPages: number[];
32
+ };
33
+ }
package/src/index.js ADDED
@@ -0,0 +1,374 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+
3
+ export const useCreateIframeAndLoadViewer = ({
4
+ files,
5
+ authInfo,
6
+ fileName,
7
+ licenseKey,
8
+ customData,
9
+ uuid,
10
+ tools,
11
+ locale,
12
+ mode,
13
+ container,
14
+ iframeSrc,
15
+ onFileFailed,
16
+ defaultAnnotationEditorMode,
17
+ initialAnnotations,
18
+ initialSigners,
19
+ modifiedUiElements
20
+ }) => {
21
+ const [internalIsReady, setInternalIsReady] = useState(false); // Add this state variable
22
+ const [selectedPages, setSelectedPages] = useState([]);
23
+ const done = useRef(false);
24
+ const iframeLoadedSuccessfully = useRef(false); // Add this ref to keep track of iframe's load state
25
+ const [pagesLoaded, setPagesLoaded] = useState(null);
26
+ const [annotations, setAnnotations] = useState([]);
27
+ const [authTokens, setAuthTokens] = useState(null);
28
+ const [signatureModalOpen, setSignatureModalOpen] = useState(false);
29
+
30
+ const createIframe = () => {
31
+ const iframe = document.createElement('iframe');
32
+
33
+ iframe.src = iframeSrc || `/pdf-ui/index.html`;
34
+
35
+ iframe.id = "webviewer-1";
36
+ iframe.title = "webviewer";
37
+ iframe.frameBorder = "0";
38
+ iframe.width = "100%";
39
+ iframe.height = "100%";
40
+ iframe.style.margin = "0px";
41
+ iframe.style.padding = "0px";
42
+ iframe.style.display = "block";
43
+
44
+ iframe.allowFullscreen = true;
45
+ // @ts-ignore
46
+ iframe["webkitallowfullscreen"] = true;
47
+ // @ts-ignore
48
+ iframe["mozallowfullscreen"] = true;
49
+
50
+ // When the iframe is loaded, post the file to it
51
+ iframe.onload = function() {
52
+ const targetOrigin = window.location.origin;
53
+ const message = { files, fileName, tools, locale, licenseKey, mode, uuid, customData, initialAnnotations, initialSigners, modifiedUiElements, authInfo, defaultAnnotationEditorMode };
54
+
55
+ // Set up a function to send the message
56
+ const sendMessage = () => {
57
+ // @ts-ignore
58
+ iframe.contentWindow.postMessage(message, targetOrigin);
59
+ };
60
+
61
+ // Call the function immediately to send the first message
62
+ sendMessage();
63
+
64
+ // Set up an interval to send the message every 1000ms (1 second)
65
+ const interval = setInterval(sendMessage, 200);
66
+
67
+ // Set up an event listener to listen for a response from the iframe
68
+ window.parent.addEventListener('message', function(event) {
69
+ if (event.data.type === 'file-received' && event.data.success) {
70
+ // If the message was received successfully, clear the interval
71
+ clearInterval(interval);
72
+ }
73
+ if (event.data.type === 'file-failed' && event.data.message) {
74
+ // If the message was received successfully, clear the interval
75
+ onFileFailed(event.data.message);
76
+ }
77
+ if (event.data.type === 'multi-page-selection-change' && Array.isArray(event.data.message)) {
78
+ setSelectedPages(event.data.message);
79
+ }
80
+ if (event.data.type === "pages-loaded") {
81
+ setPagesLoaded(event.data.message);
82
+ }
83
+ if (event.data.type === "annotations-change") {
84
+ setAnnotations(event.data.message);
85
+ }
86
+ if (event.data.type === "annotation-modal-open-change") {
87
+ setSignatureModalOpen(event.data.message);
88
+ }
89
+ });
90
+ };
91
+
92
+ container.current.appendChild(iframe);
93
+ };
94
+
95
+ const handleIframeLoaded = (event) => {
96
+ if (event.data.type === 'iframe-loaded' && event.data.success) {
97
+ iframeLoadedSuccessfully.current = true;
98
+ setInternalIsReady(true);
99
+ }
100
+ // let's just lump more stuff in here
101
+ if (event.data.type === 'token-granted' && event.data.token) {
102
+ setAuthTokens(JSON.stringify({
103
+ token: event.data.token,
104
+ refreshToken: event.data.refreshToken
105
+ }));
106
+ }
107
+ if (event.data.type === 'token-removed') {
108
+ setAuthTokens(null);
109
+ }
110
+ if (event.data.type === 'request-token' && event.data.success) {
111
+ var iframeWin = document.getElementById('webviewer-1').contentWindow;
112
+ let parsedTokens = authTokens ? JSON.parse(authTokens) : null;
113
+ iframeWin?.postMessage({ authInfo: {
114
+ token: parsedTokens?.token,
115
+ refreshToken: parsedTokens?.refreshToken
116
+ } }, '*');
117
+ // I believe this is only for the chrome extension tabs learning from each other.
118
+ }
119
+ };
120
+
121
+ useEffect(() => {
122
+ window.parent.addEventListener('message', handleIframeLoaded);
123
+ return () => window.parent.removeEventListener('message', handleIframeLoaded);
124
+ }, []);
125
+
126
+ const [clickedTag, setClickedTag] = useState(null);
127
+
128
+ const handleTagClicked = (event) => {
129
+ if (event.data.type === 'click-tag') {
130
+ setClickedTag(event.data);
131
+ }
132
+ }
133
+ useEffect(() => {
134
+ window.parent.addEventListener('message', handleTagClicked);
135
+ return () => window.parent.removeEventListener('message', handleTagClicked);
136
+ }, []);
137
+
138
+ const handleVisibilityChange = () => {
139
+ if (!document.hidden && !iframeLoadedSuccessfully.current) {
140
+ const iframe = document.getElementById('webviewer-1');
141
+ if (iframe) {
142
+ iframe.remove();
143
+ }
144
+ createIframe();
145
+ }
146
+ };
147
+
148
+ useEffect(() => {
149
+ if (!container?.current) {
150
+ return;
151
+ }
152
+ if (done.current) {
153
+ return;
154
+ }
155
+ done.current = true;
156
+ createIframe();
157
+ }, [container, files]);
158
+
159
+ useEffect(() => {
160
+ document.addEventListener('click', function() {
161
+ // @ts-ignore
162
+ var iframeWin = document.getElementById('webviewer-1').contentWindow;
163
+ iframeWin.postMessage('clickedOutside', window.location.origin);
164
+ });
165
+ document.addEventListener('visibilitychange', handleVisibilityChange);
166
+ return () => {
167
+ document.removeEventListener('visibilitychange', handleVisibilityChange);
168
+ };
169
+ }, []);
170
+
171
+ const download = () => {
172
+ // @ts-ignore
173
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
174
+ iframeWin.postMessage({ type: 'download' }, window.location.origin);
175
+ };
176
+
177
+ const toggleFullScreenThumbnails = (enable) => {
178
+ // @ts-ignore
179
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
180
+ iframeWin.postMessage({ type: 'toggle-full-screen-thumbnails', enable }, window.location.origin);
181
+ };
182
+
183
+ const toggleSearchbar = (enable) => {
184
+ // @ts-ignore
185
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
186
+ iframeWin.postMessage({ type: 'toggle-searchbar', enable }, window.location.origin);
187
+ };
188
+
189
+ const requestBuffer = async (value) => {
190
+ return new Promise((resolve, reject) => {
191
+ const listener = (event) => {
192
+ if (event.data.type === 'request-buffer-completed') {
193
+ resolve(event.data.message); // Resolve the promise with the result
194
+ window.removeEventListener('message', listener); // Remove the listener to clean up
195
+ }
196
+ else if (event.data.type === 'request-buffer-failed') {
197
+ reject(new Error(event.data.message)); // Reject the promise with the error message
198
+ window.removeEventListener('message', listener); // Remove the listener to clean up
199
+ }
200
+ };
201
+
202
+ // Adding the event listener before sending the postMessage
203
+ window.addEventListener('message', listener);
204
+
205
+ // @ts-ignore
206
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
207
+
208
+ // Sending the extract-pages message to the iframe
209
+ iframeWin.postMessage({ type: 'request-buffer', value }, window.location.origin);
210
+ });
211
+ };
212
+
213
+ const toggleSignatureModal = (enable) => {
214
+ // @ts-ignore
215
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
216
+ iframeWin.postMessage({ type: 'toggle-signature-modal', enable }, window.location.origin);
217
+ };
218
+
219
+ const setThumbnailZoom = (value) => {
220
+ // @ts-ignore
221
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
222
+ iframeWin.postMessage({ type: 'set-thumbnail-zoom', value }, window.location.origin);
223
+ };
224
+
225
+ const setAuthInfo = ({token, refreshToken}) => {
226
+ // @ts-ignore
227
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
228
+ iframeWin?.postMessage({ type: 'set-auth-info', authInfo: {
229
+ token,
230
+ refreshToken
231
+ } }, window.location.origin);
232
+ };
233
+
234
+ const splitPages = async () => {
235
+ return new Promise((resolve, reject) => {
236
+ const listener = (event) => {
237
+ if (event.data.type === 'split-pages-completed' && event.data.success) {
238
+ resolve(event.data.message); // Resolve the promise with the result
239
+ window.removeEventListener('message', listener); // Remove the listener to clean up
240
+ }
241
+ else if (event.data.type === 'split-pages-failed') {
242
+ reject(new Error(event.data.message)); // Reject the promise with the error message
243
+ window.removeEventListener('message', listener); // Remove the listener to clean up
244
+ }
245
+ };
246
+
247
+ // Adding the event listener before sending the postMessage
248
+ window.addEventListener('message', listener);
249
+
250
+ // @ts-ignore
251
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
252
+
253
+ // Sending the extract-pages message to the iframe
254
+ iframeWin.postMessage({ type: 'split-pages' }, window.location.origin);
255
+ });
256
+ }
257
+
258
+ const mergeFiles = async (value) => {
259
+ return new Promise((resolve, reject) => {
260
+ const listener = (event) => {
261
+ if (event.data.type === 'merge-files-completed' && event.data.success) {
262
+ resolve(event.data.message); // Resolve the promise with the result
263
+ window.removeEventListener('message', listener); // Remove the listener to clean up
264
+ }
265
+ else if (event.data.type === 'merge-files-failed') {
266
+ reject(new Error(event.data.message)); // Reject the promise with the error message
267
+ window.removeEventListener('message', listener); // Remove the listener to clean up
268
+ }
269
+ };
270
+
271
+ // Adding the event listener before sending the postMessage
272
+ window.addEventListener('message', listener);
273
+
274
+ // @ts-ignore
275
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
276
+
277
+ // Sending the extract-pages message to the iframe
278
+ iframeWin.postMessage({ type: 'merge-files', value }, window.location.origin);
279
+ });
280
+ };
281
+
282
+ const removeChatHistory = async () => {
283
+ return new Promise((resolve, reject) => {
284
+ const listener = (event) => {
285
+ if (event.data.type === 'remove-chat-history-completed' && event.data.success) {
286
+ resolve(event.data.message); // Resolve the promise with the result
287
+ window.removeEventListener('message', listener); // Remove the listener to clean up
288
+ }
289
+ else if (event.data.type === 'remove-chat-history-failed') {
290
+ reject(new Error(event.data.message)); // Reject the promise with the error message
291
+ window.removeEventListener('message', listener); // Remove the listener to clean up
292
+ }
293
+ };
294
+
295
+ // Adding the event listener before sending the postMessage
296
+ window.addEventListener('message', listener);
297
+
298
+ // @ts-ignore
299
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
300
+
301
+ // Sending the extract-pages message to the iframe
302
+ iframeWin.postMessage({ type: 'remove-chat-history' }, window.location.origin);
303
+ });
304
+ };
305
+
306
+ const combineFiles = async (value) => {
307
+ return new Promise((resolve, reject) => {
308
+ const listener = (event) => {
309
+ if (event.data.type === 'combine-files-completed' && event.data.success) {
310
+ resolve(event.data.message); // Resolve the promise with the result
311
+ window.removeEventListener('message', listener); // Remove the listener to clean up
312
+ }
313
+ else if (event.data.type === 'combine-files-failed') {
314
+ reject(new Error(event.data.message)); // Reject the promise with the error message
315
+ window.removeEventListener('message', listener); // Remove the listener to clean up
316
+ }
317
+ };
318
+
319
+ // Adding the event listener before sending the postMessage
320
+ window.addEventListener('message', listener);
321
+
322
+ // @ts-ignore
323
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
324
+
325
+ // Sending the extract-pages message to the iframe
326
+ iframeWin.postMessage({ type: 'combine-files', value }, window.location.origin);
327
+ });
328
+ };
329
+
330
+ const extractPages = async (value) => {
331
+ return new Promise((resolve, reject) => {
332
+ const listener = (event) => {
333
+ if (event.data.type === 'extract-pages-completed' && event.data.success) {
334
+ resolve(event.data.result); // Resolve the promise with the result
335
+ window.removeEventListener('message', listener); // Remove the listener to clean up
336
+ }
337
+ else if (event.data.type === 'extract-pages-failed') {
338
+ reject(new Error(event.data.message)); // Reject the promise with the error message
339
+ window.removeEventListener('message', listener); // Remove the listener to clean up
340
+ }
341
+ };
342
+
343
+ // Adding the event listener before sending the postMessage
344
+ window.addEventListener('message', listener);
345
+
346
+ // @ts-ignore
347
+ var iframeWin = document?.getElementById('webviewer-1')?.contentWindow;
348
+
349
+ // Sending the extract-pages message to the iframe
350
+ iframeWin.postMessage({ type: 'extract-pages', value }, window.location.origin);
351
+ });
352
+ };
353
+
354
+ return {
355
+ requestBuffer,
356
+ removeChatHistory,
357
+ setAuthInfo,
358
+ splitPages,
359
+ combineFiles,
360
+ mergeFiles,
361
+ pagesLoaded,
362
+ clickedTag,
363
+ extractPages, download,
364
+ toggleSearchbar,
365
+ toggleSignatureModal,
366
+ toggleFullScreenThumbnails,
367
+ isReady: internalIsReady,
368
+ setThumbnailZoom,
369
+ selectedPages,
370
+ annotations,
371
+ authTokens,
372
+ signatureModalOpen
373
+ };
374
+ };