@konfuzio/document-validation-ui 0.1.1

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 (131) hide show
  1. package/.eslintrc.js +11 -0
  2. package/.prettierrc.json +1 -0
  3. package/LICENSE +21 -0
  4. package/README.md +13 -0
  5. package/dist/css/app.0c8973f8.css +1 -0
  6. package/dist/css/chunk-vendors.053b6b6e.css +5 -0
  7. package/dist/favicon.ico +0 -0
  8. package/dist/index.html +1 -0
  9. package/dist/js/app.17fe48c4.js +2 -0
  10. package/dist/js/app.17fe48c4.js.map +1 -0
  11. package/dist/js/chunk-vendors.a48fca3f.js +47 -0
  12. package/dist/js/chunk-vendors.a48fca3f.js.map +1 -0
  13. package/jest.config.js +4 -0
  14. package/package.json +60 -0
  15. package/src/.DS_Store +0 -0
  16. package/src/api.js +49 -0
  17. package/src/assets/images/AcceptedCheckMark.vue +8 -0
  18. package/src/assets/images/AcceptedUser.vue +8 -0
  19. package/src/assets/images/ActionIcon.vue +60 -0
  20. package/src/assets/images/ArrowDownKey.vue +11 -0
  21. package/src/assets/images/ArrowUpKey.vue +11 -0
  22. package/src/assets/images/CategoryIconImg.vue +13 -0
  23. package/src/assets/images/CheckMark.vue +8 -0
  24. package/src/assets/images/EditDocIcon.vue +12 -0
  25. package/src/assets/images/EmptyStateImg.vue +129 -0
  26. package/src/assets/images/ErrorIcon.vue +28 -0
  27. package/src/assets/images/EyeIcon.vue +11 -0
  28. package/src/assets/images/FileNameNotSavedImage.vue +26 -0
  29. package/src/assets/images/FileNameSavedImage.vue +14 -0
  30. package/src/assets/images/FitZoomIcon.vue +16 -0
  31. package/src/assets/images/KeyboardIcon.vue +16 -0
  32. package/src/assets/images/MinusIcon.vue +13 -0
  33. package/src/assets/images/NotOptimizedIllustration.vue +651 -0
  34. package/src/assets/images/PlusIcon.vue +13 -0
  35. package/src/assets/images/QuestionMark.vue +12 -0
  36. package/src/assets/images/ServerImage.vue +63 -0
  37. package/src/assets/images/SplitLines.vue +18 -0
  38. package/src/assets/images/SplitZigZag.vue +16 -0
  39. package/src/assets/images/StatusImg.vue +14 -0
  40. package/src/assets/images/UserIcon.vue +8 -0
  41. package/src/assets/scss/annotation_details.scss +126 -0
  42. package/src/assets/scss/categorize_modal.scss +42 -0
  43. package/src/assets/scss/choose_label_set_modal.scss +62 -0
  44. package/src/assets/scss/document_action_bar.scss +37 -0
  45. package/src/assets/scss/document_annotations.scss +472 -0
  46. package/src/assets/scss/document_category.scss +80 -0
  47. package/src/assets/scss/document_dashboard.scss +47 -0
  48. package/src/assets/scss/document_dataset_status.scss +46 -0
  49. package/src/assets/scss/document_edit.scss +431 -0
  50. package/src/assets/scss/document_error.scss +81 -0
  51. package/src/assets/scss/document_handover.scss +200 -0
  52. package/src/assets/scss/document_name.scss +62 -0
  53. package/src/assets/scss/document_page.scss +8 -0
  54. package/src/assets/scss/document_thumbnails.scss +41 -0
  55. package/src/assets/scss/document_toolbar.scss +89 -0
  56. package/src/assets/scss/document_top_bar.scss +139 -0
  57. package/src/assets/scss/document_viewport_modal.scss +25 -0
  58. package/src/assets/scss/documents_list.scss +130 -0
  59. package/src/assets/scss/empty_state.scss +34 -0
  60. package/src/assets/scss/extracting_data.scss +35 -0
  61. package/src/assets/scss/imports.scss +1 -0
  62. package/src/assets/scss/main.scss +24 -0
  63. package/src/assets/scss/multi_ann_table_popup.scss +12 -0
  64. package/src/assets/scss/new_annotation.scss +86 -0
  65. package/src/assets/scss/scrolling_document.scss +19 -0
  66. package/src/assets/scss/variables.scss +696 -0
  67. package/src/components/App.vue +112 -0
  68. package/src/components/DocumentAnnotations/ActionButtons.vue +237 -0
  69. package/src/components/DocumentAnnotations/AnnotationContent.vue +249 -0
  70. package/src/components/DocumentAnnotations/AnnotationDetails.vue +292 -0
  71. package/src/components/DocumentAnnotations/AnnotationRow.vue +616 -0
  72. package/src/components/DocumentAnnotations/CategorizeModal.vue +159 -0
  73. package/src/components/DocumentAnnotations/ChooseLabelSetModal.vue +155 -0
  74. package/src/components/DocumentAnnotations/DocumentAnnotations.vue +502 -0
  75. package/src/components/DocumentAnnotations/DocumentLabel.vue +148 -0
  76. package/src/components/DocumentAnnotations/EmptyAnnotation.vue +222 -0
  77. package/src/components/DocumentAnnotations/EmptyState.vue +21 -0
  78. package/src/components/DocumentAnnotations/ExtractingData.vue +29 -0
  79. package/src/components/DocumentAnnotations/LoadingAnnotations.vue +43 -0
  80. package/src/components/DocumentAnnotations/LoadingLabels.vue +43 -0
  81. package/src/components/DocumentAnnotations/RejectedLabels.vue +96 -0
  82. package/src/components/DocumentAnnotations/index.js +8 -0
  83. package/src/components/DocumentCategory.vue +156 -0
  84. package/src/components/DocumentDashboard.vue +159 -0
  85. package/src/components/DocumentEdit/DocumentEdit.vue +279 -0
  86. package/src/components/DocumentEdit/EditPages.vue +213 -0
  87. package/src/components/DocumentEdit/EditSidebar.vue +118 -0
  88. package/src/components/DocumentEdit/SplitOverview.vue +182 -0
  89. package/src/components/DocumentEdit/index.js +4 -0
  90. package/src/components/DocumentError.vue +53 -0
  91. package/src/components/DocumentPage/ActionBar.vue +48 -0
  92. package/src/components/DocumentPage/BoxSelection.vue +149 -0
  93. package/src/components/DocumentPage/DocumentPage.vue +517 -0
  94. package/src/components/DocumentPage/DocumentToolbar.vue +145 -0
  95. package/src/components/DocumentPage/DummyPage.vue +53 -0
  96. package/src/components/DocumentPage/MultiAnnSelection.vue +302 -0
  97. package/src/components/DocumentPage/MultiAnnotationTablePopup.vue +253 -0
  98. package/src/components/DocumentPage/NewAnnotation.vue +283 -0
  99. package/src/components/DocumentPage/ScrollingDocument.vue +108 -0
  100. package/src/components/DocumentPage/ScrollingPage.vue +184 -0
  101. package/src/components/DocumentPage/index.js +5 -0
  102. package/src/components/DocumentThumbnails/DocumentThumbnails.vue +92 -0
  103. package/src/components/DocumentThumbnails/LoadingThumbnail.vue +25 -0
  104. package/src/components/DocumentThumbnails/index.js +1 -0
  105. package/src/components/DocumentTopBar/DocumentDatasetStatus.vue +103 -0
  106. package/src/components/DocumentTopBar/DocumentHandover.vue +202 -0
  107. package/src/components/DocumentTopBar/DocumentName.vue +224 -0
  108. package/src/components/DocumentTopBar/DocumentTopBar.vue +144 -0
  109. package/src/components/DocumentTopBar/DocumentTopBarButtons.vue +148 -0
  110. package/src/components/DocumentTopBar/KeyboardActionsDescription.vue +71 -0
  111. package/src/components/DocumentTopBar/index.js +5 -0
  112. package/src/components/DocumentsList/DocumentsList.vue +126 -0
  113. package/src/components/DocumentsList/index.js +1 -0
  114. package/src/components/ErrorMessage.vue +40 -0
  115. package/src/components/NotOptimizedViewportModal.vue +54 -0
  116. package/src/constants.js +4 -0
  117. package/src/directives/scroll.js +28 -0
  118. package/src/i18n.js +23 -0
  119. package/src/locales/de.json +114 -0
  120. package/src/locales/en.json +114 -0
  121. package/src/locales/es.json +113 -0
  122. package/src/main.js +87 -0
  123. package/src/store/category.js +193 -0
  124. package/src/store/display.js +238 -0
  125. package/src/store/document.js +1057 -0
  126. package/src/store/edit.js +210 -0
  127. package/src/store/index.js +22 -0
  128. package/src/store/project.js +95 -0
  129. package/src/store/selection.js +179 -0
  130. package/src/utils/utils.js +3 -0
  131. package/vue.config.js +13 -0
@@ -0,0 +1,238 @@
1
+ import BigNumber from "bignumber.js";
2
+ import {
3
+ PIXEL_RATIO,
4
+ VIEWPORT_RATIO,
5
+ MINIMUM_APP_WIDTH,
6
+ MINIMUM_OPTIMIZED_APP_WIDTH,
7
+ } from "../constants";
8
+ const debounce = (cb, duration) => {
9
+ let timer;
10
+ return (...args) => {
11
+ clearTimeout(timer);
12
+ timer = setTimeout(() => {
13
+ cb(...args);
14
+ }, duration);
15
+ };
16
+ };
17
+
18
+ const floor = (value, precision) => {
19
+ const multiplier = Math.pow(10, precision || 0);
20
+ return Math.floor(value * multiplier) / multiplier;
21
+ };
22
+
23
+ const state = {
24
+ scale: undefined,
25
+ optimalScale: undefined,
26
+ fit: "width",
27
+ currentPage: 1,
28
+ optimalResolution: true,
29
+ interactionBlocked: false,
30
+ documentActionBar: null, // document action bar properties
31
+ };
32
+
33
+ const getters = {
34
+ isMinimumWidth: (state) => (width) => {
35
+ return width >= MINIMUM_APP_WIDTH;
36
+ },
37
+ pageWidthScale: (state) => (elementsWidth, clientWidth, viewportWidth) => {
38
+ return (
39
+ ((clientWidth - elementsWidth) * PIXEL_RATIO * VIEWPORT_RATIO) /
40
+ viewportWidth
41
+ );
42
+ },
43
+ pageHeightScale: (state) => (clientHeight, viewportHeight) => {
44
+ return (clientHeight * PIXEL_RATIO * VIEWPORT_RATIO) / viewportHeight;
45
+ },
46
+ visiblePageRange: (state, getters, rootState, rootGetters) => {
47
+ const pageCount = rootGetters.pageCount;
48
+ const previousPage = state.currentPage - 1 < 1 ? 1 : state.currentPage - 1;
49
+ const nextPage =
50
+ state.currentPage + 1 > pageCount ? pageCount : state.currentPage + 1;
51
+ return [previousPage, state.currentPage, nextPage];
52
+ },
53
+
54
+ /**
55
+ * The proportion between the original size of the page and the
56
+ * image rendering.
57
+ */
58
+ imageScale: (state) => (page) => {
59
+ return new BigNumber(page.size[0]).div(page.original_size[0]).toNumber();
60
+ },
61
+ bboxToRect:
62
+ (state, getters) =>
63
+ (page, bbox, hasOffset = false) => {
64
+ const imageScale = getters.imageScale(page);
65
+ const { x0, x1, y0, y1 } = bbox;
66
+ const pageHeight = new BigNumber(page.original_size[1]);
67
+ const rect = {
68
+ // left
69
+ x: new BigNumber(x0)
70
+ .minus(hasOffset ? 1 : 0)
71
+ .times(state.scale)
72
+ .times(imageScale)
73
+ .div(PIXEL_RATIO)
74
+ .toNumber(),
75
+ // top
76
+ y: pageHeight
77
+ .minus(new BigNumber(y1))
78
+ .minus(hasOffset ? 17.1 : 0)
79
+ .times(state.scale)
80
+ .times(imageScale)
81
+ .div(PIXEL_RATIO)
82
+ .toNumber(),
83
+ width: new BigNumber(x1)
84
+ .minus(x0)
85
+ .abs()
86
+ .times(state.scale)
87
+ .times(imageScale)
88
+ .div(PIXEL_RATIO)
89
+ .toNumber(),
90
+ height: new BigNumber(y1)
91
+ .minus(y0)
92
+ .times(state.scale)
93
+ .times(imageScale)
94
+ .div(PIXEL_RATIO)
95
+ .toNumber(),
96
+ };
97
+ return rect;
98
+ },
99
+ clientToBbox: (state, getters) => (page, start, end) => {
100
+ /**
101
+ * The backend bbox's `y0` and `y1` attributes depend on knowing the
102
+ * page's height.
103
+ */
104
+ const pageHeight = new BigNumber(page.original_size[1]);
105
+ const imageScale = getters.imageScale(page);
106
+
107
+ /**
108
+ * We use `Math.min` and `Math.max` because depending on how the area
109
+ * selection is made the `start` and `end` attributes might be reversed.
110
+ */
111
+ const x0 = new BigNumber(Math.min(start.x, end.x))
112
+ .div(state.scale)
113
+ .div(imageScale)
114
+ .times(PIXEL_RATIO)
115
+ .dp(3, BigNumber.ROUND_DOWN)
116
+ .toNumber();
117
+ const x1 = new BigNumber(Math.max(start.x, end.x))
118
+ .div(state.scale)
119
+ .div(imageScale)
120
+ .times(PIXEL_RATIO)
121
+ .dp(3, BigNumber.ROUND_UP)
122
+ .toNumber();
123
+ const top = new BigNumber(Math.min(start.y, end.y))
124
+ .div(state.scale)
125
+ .div(imageScale)
126
+ .times(PIXEL_RATIO)
127
+ .dp(3)
128
+ .toNumber();
129
+ const bottom = new BigNumber(Math.max(start.y, end.y))
130
+ .div(state.scale)
131
+ .div(imageScale)
132
+ .times(PIXEL_RATIO)
133
+ .dp(3)
134
+ .toNumber();
135
+ const y0 = pageHeight.minus(bottom).dp(3, BigNumber.ROUND_DOWN).toNumber();
136
+ const y1 = pageHeight.minus(top).dp(3, BigNumber.ROUND_UP).toNumber();
137
+
138
+ const bbox = {
139
+ x0,
140
+ x1,
141
+ y0,
142
+ y1,
143
+ page_index: page.number - 1,
144
+ };
145
+
146
+ return bbox;
147
+ },
148
+ };
149
+
150
+ const actions = {
151
+ updateScale({ commit, getters }, { elementsWidth, client, viewport, scale }) {
152
+ /**
153
+ * Determine an ideal scale using viewport of document's first page, the pixel ratio
154
+ * from the browser and a subjective scale factor based on the screen size.
155
+ */
156
+ switch (state.fit) {
157
+ case "width":
158
+ commit(
159
+ "SET_SCALE",
160
+ getters.pageWidthScale(elementsWidth, client.width, viewport.width)
161
+ );
162
+ break;
163
+ case "auto":
164
+ const pageWidthScale = getters.pageWidthScale(
165
+ elementsWidth,
166
+ client.width,
167
+ viewport.width
168
+ );
169
+ const pageHeightScale = getters.pageWidthScale(
170
+ client.height,
171
+ viewport.height
172
+ );
173
+ const autoScale = Math.min(pageWidthScale, pageHeightScale);
174
+ commit("SET_SCALE", autoScale);
175
+ break;
176
+ case "custom": {
177
+ if (scale) {
178
+ commit("SET_SCALE", scale);
179
+ }
180
+ break;
181
+ }
182
+ default:
183
+ console.log("No fit defined");
184
+ break;
185
+ }
186
+ },
187
+
188
+ updateFit({ commit }, fit) {
189
+ commit("SET_FIT", fit);
190
+ },
191
+
192
+ debounceUpdateCurrentPage: debounce(({ commit, dispatch }, pageNumber) => {
193
+ dispatch("updateCurrentPage", pageNumber);
194
+ }, 300),
195
+
196
+ updateCurrentPage({ commit }, pageNumber) {
197
+ commit("SET_CURRENT_PAGE", pageNumber);
198
+ },
199
+ updateOptimalResolution({ commit }, width) {
200
+ commit("SET_OPTIMAL_RESOLUTION", width >= MINIMUM_OPTIMIZED_APP_WIDTH);
201
+ },
202
+ showDocumentActionBar({ commit }, { icon, text, action, show, loading }) {
203
+ commit(
204
+ "SET_DOCUMENT_ACTION_BAR",
205
+ show ? { icon, text, action, loading } : null
206
+ );
207
+ },
208
+ };
209
+
210
+ const mutations = {
211
+ SET_SCALE: (state, scale) => {
212
+ state.scale = floor(scale, 2);
213
+ },
214
+
215
+ SET_FIT: (state, fit) => {
216
+ state.fit = fit;
217
+ },
218
+
219
+ SET_OPTIMAL_RESOLUTION: (state, isOptimal) => {
220
+ state.optimalResolution = isOptimal;
221
+ },
222
+
223
+ SET_CURRENT_PAGE: (state, currentPage) => {
224
+ state.currentPage = currentPage;
225
+ },
226
+
227
+ SET_DOCUMENT_ACTION_BAR: (state, actionBar) => {
228
+ state.documentActionBar = actionBar;
229
+ },
230
+ };
231
+
232
+ export default {
233
+ namespaced: true,
234
+ state,
235
+ getters,
236
+ actions,
237
+ mutations,
238
+ };