@panoramax/web-viewer 5.0.0-develop-d26305dd → 5.0.0-develop-be5ba1a7

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 (153) hide show
  1. package/build/cjs/index.js +1 -1
  2. package/build/cjs/index_photoviewer.js +1 -1
  3. package/build/esm/components/core/Basic.js +1 -1
  4. package/build/esm/translations/el.json +92 -1
  5. package/package.json +1 -1
  6. package/build/bundle.cjs +0 -3399
  7. package/build/bundle.cjs.map +0 -1
  8. package/build/bundle_photoviewer.cjs +0 -2510
  9. package/build/bundle_photoviewer.cjs.map +0 -1
  10. package/build/components/core/Basic.css +0 -56
  11. package/build/components/core/Basic.js +0 -378
  12. package/build/components/core/CoverageMap.css +0 -10
  13. package/build/components/core/CoverageMap.js +0 -169
  14. package/build/components/core/Editor.css +0 -33
  15. package/build/components/core/Editor.js +0 -398
  16. package/build/components/core/PhotoViewer.css +0 -70
  17. package/build/components/core/PhotoViewer.js +0 -650
  18. package/build/components/core/Viewer.css +0 -130
  19. package/build/components/core/Viewer.js +0 -711
  20. package/build/components/core/index.js +0 -10
  21. package/build/components/index.js +0 -11
  22. package/build/components/index_photoviewer.js +0 -6
  23. package/build/components/layout/BottomDrawer.js +0 -258
  24. package/build/components/layout/CorneredGrid.js +0 -143
  25. package/build/components/layout/Mini.js +0 -121
  26. package/build/components/layout/Tabs.js +0 -140
  27. package/build/components/layout/index.js +0 -9
  28. package/build/components/menus/LocationPrecisionDoc.js +0 -42
  29. package/build/components/menus/MapBackground.js +0 -110
  30. package/build/components/menus/MapFilters.js +0 -567
  31. package/build/components/menus/MapLayers.js +0 -238
  32. package/build/components/menus/MapLegend.js +0 -68
  33. package/build/components/menus/MiniPictureLegend.js +0 -73
  34. package/build/components/menus/PictureLegend.js +0 -379
  35. package/build/components/menus/PictureMetadata.js +0 -380
  36. package/build/components/menus/PlayerOptions.js +0 -93
  37. package/build/components/menus/QualityScoreDoc.js +0 -42
  38. package/build/components/menus/ReportForm.js +0 -132
  39. package/build/components/menus/SemanticsDoc.js +0 -38
  40. package/build/components/menus/SemanticsDownload.js +0 -33
  41. package/build/components/menus/SemanticsFilters.js +0 -153
  42. package/build/components/menus/SemanticsList.js +0 -413
  43. package/build/components/menus/SemanticsMetadata.js +0 -368
  44. package/build/components/menus/Share.js +0 -105
  45. package/build/components/menus/index.js +0 -22
  46. package/build/components/menus/index_photoviewer.js +0 -11
  47. package/build/components/styles.js +0 -557
  48. package/build/components/ui/AnnotationsSwitch.js +0 -159
  49. package/build/components/ui/Button.js +0 -77
  50. package/build/components/ui/ButtonGroup.css +0 -59
  51. package/build/components/ui/ButtonGroup.js +0 -69
  52. package/build/components/ui/CopyButton.js +0 -110
  53. package/build/components/ui/Grade.js +0 -54
  54. package/build/components/ui/GradeFilter.js +0 -122
  55. package/build/components/ui/IconSwitch.js +0 -193
  56. package/build/components/ui/LinkButton.js +0 -67
  57. package/build/components/ui/ListGroup.js +0 -66
  58. package/build/components/ui/ListItem.js +0 -90
  59. package/build/components/ui/Loader.js +0 -203
  60. package/build/components/ui/Map.css +0 -63
  61. package/build/components/ui/Map.js +0 -853
  62. package/build/components/ui/MapMore.js +0 -175
  63. package/build/components/ui/Photo.css +0 -50
  64. package/build/components/ui/Photo.js +0 -1502
  65. package/build/components/ui/Popup.js +0 -145
  66. package/build/components/ui/ProgressBar.js +0 -104
  67. package/build/components/ui/QualityScore.js +0 -147
  68. package/build/components/ui/SearchBar.js +0 -374
  69. package/build/components/ui/SemanticsEditor.js +0 -191
  70. package/build/components/ui/SemanticsTable.js +0 -88
  71. package/build/components/ui/Switch.js +0 -139
  72. package/build/components/ui/TogglableGroup.js +0 -157
  73. package/build/components/ui/index.js +0 -29
  74. package/build/components/ui/index_photoviewer.js +0 -21
  75. package/build/components/ui/widgets/CopyCoordinates.js +0 -75
  76. package/build/components/ui/widgets/GeoSearch.css +0 -21
  77. package/build/components/ui/widgets/GeoSearch.js +0 -150
  78. package/build/components/ui/widgets/Legend.js +0 -190
  79. package/build/components/ui/widgets/LevelSelect.css +0 -51
  80. package/build/components/ui/widgets/LevelSelect.js +0 -143
  81. package/build/components/ui/widgets/MapFiltersButton.js +0 -114
  82. package/build/components/ui/widgets/MapLayersButton.js +0 -79
  83. package/build/components/ui/widgets/OSMEditors.js +0 -155
  84. package/build/components/ui/widgets/PictureLegendActions.js +0 -99
  85. package/build/components/ui/widgets/Player.css +0 -7
  86. package/build/components/ui/widgets/Player.js +0 -154
  87. package/build/components/ui/widgets/SemanticsFiltersButton.js +0 -65
  88. package/build/components/ui/widgets/Zoom.js +0 -84
  89. package/build/components/ui/widgets/index.js +0 -16
  90. package/build/components/ui/widgets/index_photoviewer.js +0 -7
  91. package/build/img/arrow_360.svg +0 -14
  92. package/build/img/arrow_flat.svg +0 -11
  93. package/build/img/arrow_triangle.svg +0 -9
  94. package/build/img/arrow_turn.svg +0 -8
  95. package/build/img/bg_aerial.jpg +0 -0
  96. package/build/img/bg_streets.jpg +0 -0
  97. package/build/img/loader_base.jpg +0 -0
  98. package/build/img/logo_dead.svg +0 -91
  99. package/build/img/marker.svg +0 -17
  100. package/build/img/marker_blue.svg +0 -20
  101. package/build/img/osm.svg +0 -49
  102. package/build/img/panoramax.svg +0 -13
  103. package/build/img/switch_big.svg +0 -54
  104. package/build/img/switch_mini.svg +0 -48
  105. package/build/img/wd.svg +0 -1
  106. package/build/index_photoviewer.js +0 -4
  107. package/build/package.json +0 -148
  108. package/build/servers.js +0 -14
  109. package/build/translations/ar.json +0 -1
  110. package/build/translations/be.json +0 -257
  111. package/build/translations/br.json +0 -81
  112. package/build/translations/cy.json +0 -117
  113. package/build/translations/da.json +0 -300
  114. package/build/translations/de.json +0 -309
  115. package/build/translations/en.json +0 -294
  116. package/build/translations/eo.json +0 -235
  117. package/build/translations/es.json +0 -292
  118. package/build/translations/fi.json +0 -1
  119. package/build/translations/fr.json +0 -294
  120. package/build/translations/hr.json +0 -294
  121. package/build/translations/hu.json +0 -294
  122. package/build/translations/it.json +0 -306
  123. package/build/translations/ja.json +0 -182
  124. package/build/translations/ko.json +0 -1
  125. package/build/translations/nl.json +0 -305
  126. package/build/translations/nn.json +0 -1
  127. package/build/translations/pl.json +0 -169
  128. package/build/translations/pt.json +0 -296
  129. package/build/translations/pt_BR.json +0 -304
  130. package/build/translations/sv.json +0 -182
  131. package/build/translations/ti.json +0 -9
  132. package/build/translations/tr.json +0 -297
  133. package/build/translations/uk.json +0 -268
  134. package/build/translations/zh_Hant.json +0 -309
  135. package/build/utils/API.js +0 -928
  136. package/build/utils/InitParameters.js +0 -521
  137. package/build/utils/MapStyleComposer.js +0 -889
  138. package/build/utils/PanoraMapProtocol.js +0 -49
  139. package/build/utils/PhotoAdapter.js +0 -49
  140. package/build/utils/PresetsManager.js +0 -148
  141. package/build/utils/SemanticsMapProtocol.js +0 -144
  142. package/build/utils/URLHandler.js +0 -426
  143. package/build/utils/geocoder.js +0 -203
  144. package/build/utils/i18n.js +0 -128
  145. package/build/utils/index.js +0 -17
  146. package/build/utils/index_photoviewer.js +0 -14
  147. package/build/utils/indoor.js +0 -200
  148. package/build/utils/map.js +0 -788
  149. package/build/utils/picture.js +0 -507
  150. package/build/utils/semantics.js +0 -321
  151. package/build/utils/services.js +0 -148
  152. package/build/utils/utils.js +0 -433
  153. package/build/utils/widgets.js +0 -110
@@ -1,433 +0,0 @@
1
- import { InternetFastTestFile, InternetFastThreshold } from "./services.js";
2
-
3
- export const DISABLE_ANNOTATIONS_PARAM = "pnx-disable-annotations";
4
- export const BASE_PANORAMA_ID = "geovisio-fake-id-0";
5
-
6
- export const COLORS = {
7
- BASE: "#FF6F00",
8
- SELECTED: "#1E88E5",
9
- HIDDEN: "#34495E",
10
- NEXT: "#ffab40",
11
-
12
- QUALI_1: "#00695C", // 360
13
- QUALI_2: "#fd8d3c", // Flat
14
-
15
- PALETTE_1: "#fecc5c", // Oldest
16
- PALETTE_2: "#fd8d3c",
17
- PALETTE_3: "#f03b20",
18
- PALETTE_4: "#bd0026" // Newest
19
- };
20
-
21
- export const COLORS_HEX = Object.fromEntries(Object.entries(COLORS).map(e => {
22
- e[1] = parseInt(e[1].slice(1), 16);
23
- return e;
24
- }));
25
-
26
- export const QUALITYSCORE_VALUES = [
27
- { color: "#007f4e", label: "A" },
28
- { color: "#72b043", label: "B" },
29
- { color: "#b5be2f", label: "C" },
30
- { color: "#f8cc1b", label: "D" },
31
- { color: "#f6a020", label: "E" },
32
- ];
33
-
34
- export const QUALITYSCORE_RES_FLAT_VALUES = [1, 10, 2, 15, 3, 30, 4]; // Grade, < Px/FOV value
35
- export const QUALITYSCORE_RES_360_VALUES = [3, 15, 4, 30, 5]; // Grade, < Px/FOV value
36
- export const QUALITYSCORE_GPS_VALUES = [5, 0.5, 4, 2.01, 3, 5.01, 2, 10.01, 1]; // Grade, < Meters value
37
- export const QUALITYSCORE_POND_RES = 4/5;
38
- export const QUALITYSCORE_POND_GPS = 1/5;
39
-
40
- export const GPS_VALUES = [
41
- { color: "#4A148C", label: `<= ${QUALITYSCORE_GPS_VALUES[1]} m` },
42
- { color: "#7B1FA2", label: `${Math.round(QUALITYSCORE_GPS_VALUES[1])} - ${Math.round(QUALITYSCORE_GPS_VALUES[3])} m` },
43
- { color: "#9C27B0", label: `${Math.round(QUALITYSCORE_GPS_VALUES[3])} - ${Math.round(QUALITYSCORE_GPS_VALUES[5])} m` },
44
- { color: "#BA68C8", label: `${Math.round(QUALITYSCORE_GPS_VALUES[5])} - ${Math.round(QUALITYSCORE_GPS_VALUES[7])} m` },
45
- { color: "#EA80FC", label: `> ${Math.round(QUALITYSCORE_GPS_VALUES[7])} m` },
46
- ];
47
-
48
-
49
- /**
50
- * Checks if a picture or sequence ID is kinda-null.
51
- * @param {string|null|undefined} id The ID to check
52
- * @returns True if null-like
53
- */
54
- export function isNullId(id) {
55
- return [null, undefined, "", BASE_PANORAMA_ID].includes(id);
56
- }
57
-
58
- /**
59
- * Find the grade associated to an input Quality Score definition.
60
- * @param {number[]} ranges The QUALITYSCORE_*_VALUES definition
61
- * @param {number} value The picture value
62
- * @return {number} The corresponding grade (1 to 5, or null if missing)
63
- * @private
64
- */
65
- export function getGrade(ranges, value) {
66
- if(value === null || value === undefined || value === "") { return null; }
67
-
68
- // Read each pair from table (grade, reference value)
69
- for(let i = 0; i < ranges.length; i += 2) {
70
- const grade = ranges[i];
71
- const limit = ranges[i+1];
72
-
73
- // Send grade if value is under limit
74
- if (value < limit) {
75
- return grade;
76
- }
77
- }
78
- // Otherwise, send last grade
79
- return ranges[ranges.length - 1];
80
- }
81
-
82
- /**
83
- * Get cartesian distance between two points
84
- * @param {number[]} from Start [x,y] coordinates
85
- * @param {number[]} to End [x,y] coordinates
86
- * @returns {number} The distance
87
- * @private
88
- */
89
- export function getDistance(from, to) {
90
- const dx = from[0] - to[0];
91
- const dy = from[1] - to[1];
92
- return Math.sqrt(dx*dx + dy*dy);
93
- }
94
-
95
- /**
96
- * Transforms an unknown SVG source into HTML Image
97
- * @param {object|string} svg The source SVG
98
- * @param {*} [img] HTML image to use (defaults to creating a new one)
99
- * @returns {HTMLImageElement} The HTML image showing the SVG
100
- * @private
101
- */
102
- export function svgToImg(svg, img = null) {
103
- if(svg.constructor.name === "HTMLImageElement") {
104
- if(img) {
105
- svg.width = img.width;
106
- svg.height = img.height;
107
- svg.onload = img.onload;
108
- }
109
- return svg;
110
- }
111
- else if(typeof svg === "string") {
112
- if(!img) {
113
- img = new Image();
114
- img.alt = "";
115
- }
116
- if(svg.startsWith("<?xml")) { svg = URL.createObjectURL(new Blob([svg], {type: 'image/svg+xml'})); }
117
- img.src = svg;
118
- return img;
119
- }
120
- }
121
-
122
- /**
123
- * Transforms a Base64 SVG string into a DOM img element.
124
- * @param {string} svg The SVG as Base64 string
125
- * @returns {Element} The DOM image element
126
- * @private
127
- */
128
- export function svgToPSVLink(svg, fillColor) {
129
- try {
130
- if(svg.startsWith("data:image/svg+xml,")) { svg = decodeURIComponent(svg.replace("data:image/svg+xml,", "")); }
131
- if(!svg.startsWith("<svg")) { throw new Error(); }
132
- const svgXml = (new DOMParser()).parseFromString(svg, "image/svg+xml").childNodes[0];
133
- const btn = document.createElement("button");
134
- btn.appendChild(svgXml);
135
- btn.classList.add("pnx-psv-tour-arrows", "pnx-print-hidden");
136
- btn.style.color = fillColor;
137
- return btn;
138
- }
139
-
140
- catch(e) {
141
- return svgToImg(svg);
142
- }
143
- }
144
-
145
- /**
146
- * Clones a model PSV link
147
- * @private
148
- */
149
- export function getArrow(a) {
150
- const d = a.cloneNode(true);
151
- d.addEventListener("pointerup", () => d.classList.add("pnx-clicked"));
152
- return d;
153
- }
154
-
155
- /**
156
- * Get direction based on angle
157
- * @param {number[]} from Start [x,y] coordinates
158
- * @param {number[]} to End [x,y] coordinates
159
- * @returns {number} The azimuth, from 0 to 360°
160
- * @private
161
- */
162
- export function getAzimuth(from, to) {
163
- return (Math.atan2(to[0] - from[0], to[1] - from[1]) * (180 / Math.PI) + 360) % 360;
164
- }
165
-
166
- /**
167
- * Computes absolute heading for the road around selected picture.
168
- * @param {*} m The picture metadata
169
- * @returns {number} The absolute heading of the road, or 0 if no road around
170
- * @private
171
- */
172
- export function getRoadAbsoluteHeading(m) {
173
- if(!m) { return 0; }
174
-
175
- let prevSegDir, nextSegDir;
176
-
177
- // Previous picture GPS coordinates
178
- if(m?.sequence?.prevPic) {
179
- const prevLink = m?.links?.find(l => l.nodeId === m.sequence.prevPic);
180
- if(prevLink) {
181
- prevSegDir = getAzimuth(prevLink.gps, m.gps);
182
- }
183
- }
184
-
185
- // Next picture GPS coordinates
186
- if(m?.sequence?.nextPic) {
187
- const nextLink = m?.links?.find(l => l.nodeId === m.sequence.nextPic);
188
- if(nextLink) {
189
- nextSegDir = getAzimuth(m.gps, nextLink.gps);
190
- }
191
- }
192
-
193
- if(prevSegDir !== undefined && nextSegDir !== undefined) {
194
- return ((prevSegDir + nextSegDir) / 2) % 360;
195
- }
196
- else if(prevSegDir !== undefined) {
197
- return prevSegDir;
198
- }
199
- else if(nextSegDir !== undefined) {
200
- return nextSegDir;
201
- }
202
- else {
203
- return 0;
204
- }
205
- }
206
-
207
- /**
208
- * Computes relative heading for a single picture, based on its metadata
209
- * @param {*} m The picture metadata
210
- * @returns {number} The relative heading
211
- * @private
212
- */
213
- export function getRelativeHeading(m) {
214
- if(!m) { throw new Error("No picture selected"); }
215
-
216
- let prevSegDir, nextSegDir;
217
- const currHeading = m.properties["view:azimuth"];
218
-
219
- // Previous picture GPS coordinates
220
- if(m?.sequence?.prevPic) {
221
- const prevLink = m?.links?.find(l => l.nodeId === m.sequence.prevPic);
222
- if(prevLink) {
223
- prevSegDir = (((currHeading - getAzimuth(prevLink.gps, m.gps)) + 180) % 360) - 180;
224
- }
225
- }
226
-
227
- // Next picture GPS coordinates
228
- if(m?.sequence?.nextPic) {
229
- const nextLink = m?.links?.find(l => l.nodeId === m.sequence.nextPic);
230
- if(nextLink) {
231
- nextSegDir = (((currHeading - getAzimuth(m.gps, nextLink.gps)) + 180) % 360) - 180;
232
- }
233
- }
234
-
235
- return prevSegDir !== undefined ? prevSegDir : (nextSegDir !== undefined ? nextSegDir : 0);
236
- }
237
-
238
- /**
239
- * Get direction based on angle
240
- * @param {number[]} from Start [x,y] coordinates
241
- * @param {number[]} to End [x,y] coordinates
242
- * @returns {string} Direction (N/ENE/ESE/S/WSW/WNW)
243
- * @private
244
- */
245
- export function getSimplifiedAngle(from, to) {
246
- const angle = Math.atan2(to[0] - from[0], to[1] - from[1]) * (180 / Math.PI); // -180 to 180°
247
-
248
- // 6 directions version
249
- if (Math.abs(angle) < 30) { return "N"; }
250
- else if (angle >= 30 && angle < 90) { return "ENE"; }
251
- else if (angle >= 90 && angle < 150) { return "ESE"; }
252
- else if (Math.abs(angle) >= 150) { return "S"; }
253
- else if (angle <= -30 && angle > -90) { return "WNW"; }
254
- else if (angle <= -90 && angle > -150) { return "WSW"; }
255
- }
256
-
257
- /**
258
- * Converts result from getPosition or position-updated event into x/y/z coordinates
259
- *
260
- * @param {object} pos pitch/yaw as given by PSV
261
- * @param {number} zoom zoom as given by PSV
262
- * @returns {object} Coordinates as x/y in degrees and zoom as given by PSV
263
- * @private
264
- */
265
- export function positionToXYZ(pos, zoom = undefined) {
266
- const res = {
267
- x: pos.yaw * (180/Math.PI),
268
- y: pos.pitch * (180/Math.PI)
269
- };
270
-
271
- if(zoom !== undefined) { res.z = zoom; }
272
- return res;
273
- }
274
-
275
- /**
276
- * Converts x/y/z coordinates into PSV position (lat/lon/zoom)
277
- *
278
- * @param {number} x The X coordinate (in degrees)
279
- * @param {number} y The Y coordinate (in degrees)
280
- * @param {number} z The zoom level (0-100)
281
- * @returns {object} Position coordinates as yaw/pitch/zoom
282
- * @private
283
- */
284
- export function xyzToPosition(x, y, z) {
285
- return {
286
- yaw: x / (180/Math.PI),
287
- pitch: y / (180/Math.PI),
288
- zoom: z
289
- };
290
- }
291
-
292
- /**
293
- * Transforms decimal degrees into degrees/minutes/seconds format.
294
- * @param {number} degrees The decimal degrees value
295
- * @returns {object} Coordinate as {d,m,s} object
296
- */
297
- export function degToDms(degrees) {
298
- const d = degrees < 0 ? Math.ceil(degrees) : Math.floor(degrees);
299
- const rm = Math.abs(degrees - d) * 60;
300
- const m = Math.floor(rm);
301
- const s = parseFloat(((rm - m) * 60).toFixed(3));
302
- return { d, m, s };
303
- }
304
-
305
- /**
306
- * Get the query string for JOSM to load current picture area
307
- * @returns {string} The query string, or null if not available
308
- * @private
309
- */
310
- export function josmBboxParameters(meta) {
311
- if(meta) {
312
- const coords = meta.gps;
313
- const heading = meta?.properties?.["view:azimuth"];
314
- const delta = 0.0002;
315
- const values = {
316
- left: coords[0] - (heading === null || heading >= 180 ? delta : 0),
317
- right: coords[0] + (heading === null || heading <= 180 ? delta : 0),
318
- top: coords[1] + (heading === null || heading <= 90 || heading >= 270 ? delta : 0),
319
- bottom: coords[1] - (heading === null || (heading >= 90 && heading <= 270) ? delta : 0),
320
- changeset_source: "Panoramax"
321
- };
322
- return Object.entries(values).map(e => e.join("=")).join("&");
323
- }
324
- else { return null; }
325
- }
326
-
327
- /**
328
- * Check if code runs in an iframe or in a classic page.
329
- * @returns {boolean} True if running in iframe
330
- * @private
331
- */
332
- export function isInIframe() {
333
- try {
334
- return window.self !== window.top;
335
-
336
- } catch(e) {
337
- return true;
338
- }
339
- }
340
-
341
-
342
- const INTERNET_FAST_STORAGE = "pnx-internet-fast";
343
-
344
- /**
345
- * Check if Internet connection is high-speed or not.
346
- * @returns {Promise} Resolves on true if high-speed.
347
- * @private
348
- */
349
- export function isInternetFast() {
350
- // Check if downlink property is available
351
- try {
352
- const speed = navigator.connection.downlink; // MBit/s
353
- return Promise.resolve(speed >= InternetFastThreshold());
354
- }
355
- // Fallback for other browsers
356
-
357
- catch(e) {
358
- try {
359
- // Check if test has been done before and stored
360
- const isFast = sessionStorage.getItem(INTERNET_FAST_STORAGE);
361
- if(["true", "false"].includes(isFast)) {
362
- return Promise.resolve(isFast === "true");
363
- }
364
-
365
- // Run download testing
366
- const startTime = (new Date()).getTime();
367
- return fetch(`${InternetFastTestFile()}?nocache=${startTime}`)
368
- .then(async res => [res, await res.blob()])
369
- .then(([res, blob]) => {
370
- const size = parseInt(res.headers.get("Content-Length") || blob.size); // Bytes
371
- const endTime = (new Date()).getTime();
372
- const duration = (endTime - startTime) / 1000; // Transfer time in seconds
373
- const speed = (size * 8 / 1024 / 1024) / duration; // MBits/s
374
- const isFast = speed >= InternetFastThreshold();
375
- sessionStorage.setItem(INTERNET_FAST_STORAGE, isFast ? "true" : "false");
376
- return isFast;
377
- })
378
- .catch(e => {
379
- console.warn("Failed to run speedtest", e);
380
- return false;
381
- });
382
- }
383
- // Fallback for browser blocking third-party downloads or sessionStorage
384
-
385
- catch(e) {
386
- return Promise.resolve(false);
387
- }
388
- }
389
- }
390
-
391
- /**
392
- * Get a cookie value
393
- * @param {str} name The cookie name
394
- * @returns {str} The cookie value, or null if not found
395
- * @private
396
- */
397
- export function getCookie(name) {
398
- const parts = document.cookie
399
- ?.split(";")
400
- ?.find((row) => row.trimStart().startsWith(`${name}=`))
401
- ?.split("=");
402
- if(!parts) { return undefined; }
403
- parts.shift();
404
- return parts.join("=");
405
- }
406
-
407
- /**
408
- * Checks if an user account exists
409
- * @returns {object} Object like {"id", "name"} or null if no authenticated account
410
- * @private
411
- */
412
- export function getUserAccount() {
413
- const session = getCookie("session");
414
- const user_id = getCookie("user_id");
415
- const user_name = getCookie("user_name");
416
-
417
- return (session && user_id && user_name) ? { id: user_id, name: user_name } : null;
418
- }
419
-
420
- /**
421
- * Sends a random value between min and max (inclusive)
422
- * @param {number} min Minimal value
423
- * @param {number} max Maximal value
424
- * @returns {number} Random value
425
- */
426
- export function inRangeRandom(min, max) {
427
- const randomBuffer = new Uint32Array(1);
428
- crypto.getRandomValues(randomBuffer);
429
- let randomNumber = randomBuffer[0] / (0xffffffff + 1);
430
- min = Math.ceil(min);
431
- max = Math.floor(max);
432
- return Math.floor(randomNumber * (max - min + 1)) + min;
433
- }
@@ -1,110 +0,0 @@
1
- import { icon } from "@fortawesome/fontawesome-svg-core";
2
- import { setCustomIconLoader } from "iconify-icon";
3
- import { TemakiIconURL } from "./services.js";
4
-
5
-
6
- /**
7
- * Transform Font Awesome icon definition into HTML element
8
- * @param {IconDefinition} i The icon to use
9
- * @param {object} [o] [FontAwesome icon parameters](https://origin.fontawesome.com/docs/apis/javascript/methods#icon-icondefinition-params)
10
- * @returns {Element} HTML element
11
- * @private
12
- */
13
- export function fa(i, o) {
14
- return icon(i, o).node[0];
15
- }
16
-
17
- /**
18
- * Register more icons providers for Iconify
19
- * @private
20
- */
21
- export function moreIcons() {
22
- setCustomIconLoader(async (name) => {
23
- const response = await fetch(TemakiIconURL(name));
24
- if (!response.ok) {
25
- return null;
26
- }
27
- return {
28
- body: await response.text()
29
- };
30
- }, "temaki");
31
- }
32
-
33
- /**
34
- * Create a web component with its initial properties
35
- * @private
36
- */
37
- export function createWebComp(tag, props = {}) {
38
- const wc = document.createElement(tag);
39
- Object.entries(props).forEach(([k,v]) => {
40
- if(k.startsWith("_")) { wc[k] = v; }
41
- else if(k.startsWith("fn")) { wc[k.substring(2)] = v; }
42
- else if(k.startsWith("on")) { wc.addEventListener(k.substring(2), v); }
43
- else if(v) { wc.setAttribute(k, v); }
44
- });
45
- return wc;
46
- }
47
-
48
- /**
49
- * Listen to parent events that may lead to a menu closure
50
- * @private
51
- */
52
- export function listenForMenuClosure(me, callback) {
53
- // Other menu opened
54
- me._parent?.addEventListener("menu-opened", e => {
55
- if(e.detail.menu !== me) { callback(); }
56
- });
57
-
58
- // Map click
59
- me._parent?.onceMapReady?.().then(() => {
60
- me._parent.map?.on?.("click", () => callback());
61
- });
62
-
63
- // Photo click
64
- me._parent?.oncePSVReady?.().then(() => {
65
- me._parent.psv.addEventListener("click", () => callback());
66
- });
67
-
68
- // Legend click
69
- me._parent?.onceReady?.().then(() => {
70
- me._parent.legend?.addEventListener("click", () => callback());
71
- });
72
- }
73
-
74
- /** @private */
75
- function lookForParent(comp) {
76
- if(comp._parent) {
77
- return comp._parent;
78
- }
79
- else if(comp === document.body) {
80
- return null;
81
- }
82
- else if(comp.parentNode) {
83
- return lookForParent(comp.parentNode);
84
- }
85
- else if(comp.host) {
86
- return lookForParent(comp.host);
87
- }
88
- }
89
-
90
- /**
91
- * Wait for parent availability
92
- * @private
93
- */
94
- export function onceParentAvailable(comp) {
95
- if(comp._parent) {
96
- return Promise.resolve(comp._parent);
97
- }
98
- else {
99
- return new Promise(resolve => {
100
- const itv = setInterval(() => {
101
- const p = lookForParent(comp);
102
- if(p) {
103
- comp._parent = p;
104
- clearInterval(itv);
105
- resolve(comp._parent);
106
- }
107
- }, 100);
108
- });
109
- }
110
- }