@plurid/plurid-engine 0.0.0-18 → 0.0.0-19

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 (59) hide show
  1. package/distribution/index.d.mts +744 -0
  2. package/distribution/index.d.ts +744 -2
  3. package/distribution/index.js +3319 -2730
  4. package/distribution/index.js.map +1 -1
  5. package/distribution/index.mjs +3432 -0
  6. package/distribution/index.mjs.map +1 -0
  7. package/package.json +71 -78
  8. package/distribution/functions/index.d.ts +0 -2
  9. package/distribution/functions/navigate/index.d.ts +0 -1
  10. package/distribution/functions/template/index.d.ts +0 -1
  11. package/distribution/index.es.js +0 -2829
  12. package/distribution/index.es.js.map +0 -1
  13. package/distribution/modules/general/configuration/index.d.ts +0 -2
  14. package/distribution/modules/general/index.d.ts +0 -3
  15. package/distribution/modules/general/tree/index.d.ts +0 -5
  16. package/distribution/modules/index.d.ts +0 -9
  17. package/distribution/modules/interaction/direction/index.d.ts +0 -2
  18. package/distribution/modules/interaction/index.d.ts +0 -5
  19. package/distribution/modules/interaction/mathematics/matrix/index.d.ts +0 -31
  20. package/distribution/modules/interaction/mathematics/quaternion/index.d.ts +0 -78
  21. package/distribution/modules/interaction/mathematics/transform/general/index.d.ts +0 -37
  22. package/distribution/modules/interaction/mathematics/transform/index.d.ts +0 -3
  23. package/distribution/modules/interaction/mathematics/transform/matrix3d/index.d.ts +0 -68
  24. package/distribution/modules/internationalization/index.d.ts +0 -3
  25. package/distribution/modules/planes/index.d.ts +0 -2
  26. package/distribution/modules/planes/logic/index.d.ts +0 -4
  27. package/distribution/modules/planes/registrar/index.d.ts +0 -3
  28. package/distribution/modules/planes/registrar/object.d.ts +0 -14
  29. package/distribution/modules/planes/registrar/utilities.d.ts +0 -6
  30. package/distribution/modules/routing/IsoMatcher/index.d.ts +0 -44
  31. package/distribution/modules/routing/Parser/index.d.ts +0 -21
  32. package/distribution/modules/routing/Parser/interfaces.d.ts +0 -31
  33. package/distribution/modules/routing/Parser/logic.d.ts +0 -68
  34. package/distribution/modules/routing/index.d.ts +0 -6
  35. package/distribution/modules/routing/logic/general/index.d.ts +0 -8
  36. package/distribution/modules/routing/logic/index.d.ts +0 -3
  37. package/distribution/modules/routing/logic/utilities/index.d.ts +0 -29
  38. package/distribution/modules/routing/logic/validity/index.d.ts +0 -3
  39. package/distribution/modules/space/index.d.ts +0 -6
  40. package/distribution/modules/space/layout/column.d.ts +0 -3
  41. package/distribution/modules/space/layout/faceToFace.d.ts +0 -3
  42. package/distribution/modules/space/layout/index.d.ts +0 -6
  43. package/distribution/modules/space/layout/row.d.ts +0 -3
  44. package/distribution/modules/space/layout/sheaves.d.ts +0 -3
  45. package/distribution/modules/space/layout/zigZag.d.ts +0 -3
  46. package/distribution/modules/space/location/index.d.ts +0 -2
  47. package/distribution/modules/space/location/logic.d.ts +0 -22
  48. package/distribution/modules/space/tree/index.d.ts +0 -3
  49. package/distribution/modules/space/tree/logic.d.ts +0 -44
  50. package/distribution/modules/space/tree/object.d.ts +0 -16
  51. package/distribution/modules/space/utilities/index.d.ts +0 -16
  52. package/distribution/modules/space/view/index.d.ts +0 -2
  53. package/distribution/modules/space/view/logic.d.ts +0 -13
  54. package/distribution/modules/state/compute/index.d.ts +0 -3
  55. package/distribution/modules/state/compute/space/index.d.ts +0 -3
  56. package/distribution/modules/state/compute/themes/index.d.ts +0 -3
  57. package/distribution/modules/state/index.d.ts +0 -3
  58. package/distribution/modules/state/local/index.d.ts +0 -3
  59. package/distribution/modules/utilities/index.d.ts +0 -1
@@ -1,2829 +0,0 @@
1
- import { defaultConfiguration, protocols, HTTPS_PROTOCOL, HTTP_PROTOCOL, compareTypes, internationalization, ROOTS_GAP, LAYOUT_TYPES, PLANE_DEFAULT_ANGLE, PLURID_ROUTER_LOCATION_CHANGED } from "@plurid/plurid-data";
2
-
3
- import { objects, mathematics, uuid } from "@plurid/plurid-functions";
4
-
5
- import themes, { THEME_NAMES } from "@plurid/plurid-themes";
6
-
7
- const resolveTheme = (theme, type) => {
8
- if (!theme) {
9
- return "plurid";
10
- }
11
- if (typeof theme === "string") {
12
- return theme;
13
- }
14
- if (typeof theme !== "object") {
15
- return "plurid";
16
- }
17
- const {general: general, interaction: interaction} = theme;
18
- if (type === "general" && general) {
19
- return general;
20
- }
21
- if (type === "interaction" && interaction) {
22
- return interaction;
23
- }
24
- return "plurid";
25
- };
26
-
27
- const merge = (configuration, target) => {
28
- const targetConfiguration = Object.assign(Object.assign({}, objects.clone(defaultConfiguration)), objects.clone(target || {}));
29
- if (!configuration) {
30
- return targetConfiguration;
31
- }
32
- const mergedConfiguration = objects.merge(targetConfiguration, configuration, {
33
- "global.theme": () => {
34
- var _a, _b;
35
- return {
36
- general: resolveTheme((_a = configuration.global) === null || _a === void 0 ? void 0 : _a.theme, "general"),
37
- interaction: resolveTheme((_b = configuration.global) === null || _b === void 0 ? void 0 : _b.theme, "interaction")
38
- };
39
- }
40
- });
41
- return mergedConfiguration;
42
- };
43
-
44
- var index$k = Object.freeze({
45
- __proto__: null,
46
- merge: merge
47
- });
48
-
49
- const extractPathname = location => {
50
- const queryIndex = location.indexOf("?");
51
- const noQueryPath = queryIndex === -1 ? location : location.substring(0, queryIndex);
52
- const fragmentIndex = noQueryPath.indexOf("#:~:");
53
- const noFragmentPath = fragmentIndex === -1 ? noQueryPath : noQueryPath.substring(0, fragmentIndex);
54
- return noFragmentPath;
55
- };
56
-
57
- const extractParametersAndMatch = (location, route) => {
58
- const routeElements = splitPath(route);
59
- const parameters = [];
60
- routeElements.forEach((routeElement => {
61
- if (routeElement[0] === ":") {
62
- parameters.push(routeElement);
63
- } else {
64
- parameters.push("");
65
- }
66
- }));
67
- const {locationElements: locationElements, comparingPath: comparingPath} = computeComparingPath(location, parameters);
68
- if (comparingPath !== route) {
69
- return {
70
- match: false,
71
- parameters: {},
72
- elements: locationElements
73
- };
74
- }
75
- const parametersValues = extractParametersValues(parameters, locationElements);
76
- return {
77
- match: true,
78
- parameters: parametersValues,
79
- elements: locationElements
80
- };
81
- };
82
-
83
- const extractParametersValues = (parameters, pathElements) => {
84
- const parametersValues = {};
85
- parameters.forEach(((parameter, index) => {
86
- if (parameter) {
87
- const parameterKey = parameter.slice(1);
88
- parametersValues[parameterKey] = pathElements[index];
89
- }
90
- }));
91
- return parametersValues;
92
- };
93
-
94
- const computeComparingPath = (path, parameters) => {
95
- const pathname = extractPathname(path);
96
- const locationElements = splitPath(pathname);
97
- const comparingPathElements = [ ...locationElements ];
98
- for (const index of locationElements.keys()) {
99
- if (parameters[index]) {
100
- comparingPathElements[index] = parameters[index];
101
- }
102
- }
103
- const comparingPath = comparingPathElements.join("/");
104
- return {
105
- locationElements: locationElements,
106
- comparingPath: comparingPath
107
- };
108
- };
109
-
110
- const splitPath = path => path.split("/").filter((i => i !== ""));
111
-
112
- const extractQuery = path => {
113
- const fragmentIndex = path.indexOf("#:~:");
114
- const noFragmentPath = fragmentIndex === -1 ? path : path.substring(0, fragmentIndex);
115
- const querySplit = noFragmentPath.split("?");
116
- if (querySplit.length === 2) {
117
- const queryValues = {};
118
- const query = querySplit[1];
119
- const queryItems = query.split("&");
120
- for (const item of queryItems) {
121
- const queryValue = item.split("=");
122
- const id = queryValue[0];
123
- const value = decodeURIComponent(queryValue[1]);
124
- queryValues[id] = value;
125
- }
126
- return queryValues;
127
- } else {
128
- return {};
129
- }
130
- };
131
-
132
- const extractFragments = location => {
133
- if (!location) {
134
- return {
135
- texts: [],
136
- elements: []
137
- };
138
- }
139
- const split = location.split("#:~:");
140
- const fragmentsValues = split[1];
141
- if (!fragmentsValues) {
142
- return {
143
- texts: [],
144
- elements: []
145
- };
146
- }
147
- const fragmentItems = fragmentsValues.split("&");
148
- const textFragments = [];
149
- const elementFragments = [];
150
- for (const item of fragmentItems) {
151
- const parsedFragment = parseFragment(item);
152
- if (parsedFragment) {
153
- switch (parsedFragment.type) {
154
- case "text":
155
- textFragments.push(parsedFragment);
156
- break;
157
-
158
- case "element":
159
- elementFragments.push(parsedFragment);
160
- break;
161
- }
162
- }
163
- }
164
- return {
165
- texts: textFragments,
166
- elements: elementFragments
167
- };
168
- };
169
-
170
- const parseFragment = fragment => {
171
- const fragmentData = fragment.split("=");
172
- const fragmentType = fragmentData[0];
173
- const fragmentValues = fragmentData[1];
174
- switch (fragmentType.toLowerCase()) {
175
- case "text":
176
- {
177
- const textValues = fragmentValues.split(",");
178
- const textStart = textValues[0];
179
- const textEnd = textValues[1];
180
- const textOccurence = extractOccurence(textValues[2]);
181
- if (!textStart) {
182
- return;
183
- }
184
- return {
185
- type: "text",
186
- start: textStart,
187
- end: textEnd || "",
188
- occurence: textOccurence
189
- };
190
- }
191
-
192
- case "element":
193
- {
194
- const elementValues = fragmentValues.split(",");
195
- const elementID = elementValues[0];
196
- const elementOccurence = extractOccurence(elementValues[1]);
197
- if (!elementID) {
198
- return;
199
- }
200
- return {
201
- type: "element",
202
- id: elementID,
203
- occurence: elementOccurence
204
- };
205
- }
206
- }
207
- return undefined;
208
- };
209
-
210
- const extractOccurence = occurence => {
211
- if (!occurence) {
212
- return 0;
213
- }
214
- const occurenceMatch = occurence.match(/\[(\d*)\]/);
215
- const occurenceValue = occurenceMatch ? parseInt(occurenceMatch[1]) : 0;
216
- return occurenceValue;
217
- };
218
-
219
- const stringInsertInitial = (value, insert) => {
220
- if (!value.startsWith(insert)) {
221
- value = insert + value;
222
- }
223
- return value;
224
- };
225
-
226
- const stringRemoveTrailing = (value, trail) => {
227
- if (value.endsWith(trail)) {
228
- value = value.slice(0, value.length - trail.length);
229
- }
230
- return value;
231
- };
232
-
233
- const PATH_SEPARATOR = "/";
234
-
235
- const cleanupPath = value => {
236
- value = stringInsertInitial(value, PATH_SEPARATOR);
237
- value = stringRemoveTrailing(value, PATH_SEPARATOR);
238
- return value;
239
- };
240
-
241
- const computePlaneAddress = (plane, route, origin = "origin") => {
242
- if (origin === "origin" && typeof location !== "undefined" && location.host) {
243
- origin = location.host;
244
- }
245
- const cleanPlane = extractPathname(plane);
246
- const planeAddressType = checkPlaneAddressType(cleanPlane);
247
- switch (planeAddressType) {
248
- case "http":
249
- case "https":
250
- case "pttp":
251
- return cleanPlane;
252
- }
253
- origin = stringRemoveTrailing(origin, "/");
254
- const absolutePlane = isAbsolutePlane(plane);
255
- const path = route && route !== "/" ? absolutePlane ? cleanupPath(cleanPlane) : cleanupPath(route) + cleanupPath(cleanPlane) : cleanupPath(cleanPlane);
256
- const planeAddress = protocols.plurid + origin + path;
257
- return planeAddress;
258
- };
259
-
260
- const isAbsolutePlane = value => value[0] === "/";
261
-
262
- const checkPlaneAddressType = value => {
263
- value = value.toLowerCase().trim();
264
- if (value.startsWith(protocols.plurid)) {
265
- return "pttp";
266
- }
267
- if (value.startsWith(protocols.https)) {
268
- return HTTPS_PROTOCOL;
269
- }
270
- if (value.startsWith(protocols.http)) {
271
- return HTTP_PROTOCOL;
272
- }
273
- return "relative";
274
- };
275
-
276
- const removeTrailingSlash = value => {
277
- if (value.endsWith("/") && value.length > 1) {
278
- return value.slice(0, value.length - 1);
279
- }
280
- return value;
281
- };
282
-
283
- const cleanPathValue = value => {
284
- const queryStart = value.indexOf("?");
285
- if (queryStart < 0) {
286
- return removeTrailingSlash(value);
287
- }
288
- return removeTrailingSlash(value.substring(0, queryStart));
289
- };
290
-
291
- const checkParameterLength = (parameter, length, compareType) => {
292
- const parameterLength = parameter.length;
293
- switch (compareType) {
294
- case compareTypes.equal:
295
- return parameterLength === length;
296
-
297
- case compareTypes.equalLessThan:
298
- return parameterLength <= length;
299
-
300
- case compareTypes.lessThan:
301
- return parameterLength < length;
302
-
303
- case compareTypes.equalGreaterThan:
304
- return parameterLength >= length;
305
-
306
- case compareTypes.greaterThan:
307
- return parameterLength > length;
308
-
309
- default:
310
- return parameterLength <= length;
311
- }
312
- };
313
-
314
- const checkValidPath = (validationParameters, parameters) => {
315
- if (validationParameters) {
316
- for (const [parameterKey, parameterData] of Object.entries(validationParameters)) {
317
- const {length: length, lengthType: lengthType, startsWith: startsWith, endsWith: endsWith, includes: includes} = parameterData;
318
- const paramaterValue = parameters[parameterKey];
319
- if (!paramaterValue) {
320
- return false;
321
- }
322
- if (startsWith && !paramaterValue.startsWith(startsWith)) {
323
- return false;
324
- }
325
- if (endsWith && !paramaterValue.endsWith(endsWith)) {
326
- return false;
327
- }
328
- if (includes && !includes.includes(paramaterValue)) {
329
- return false;
330
- }
331
- if (length) {
332
- const validLength = checkParameterLength(paramaterValue, length, lengthType);
333
- return validLength;
334
- }
335
- }
336
- }
337
- return true;
338
- };
339
-
340
- const cleanPathElement = path => {
341
- if (path[0] === "/") {
342
- return path.slice(1);
343
- }
344
- return path;
345
- };
346
-
347
- var index$j = Object.freeze({
348
- __proto__: null,
349
- cleanPathElement: cleanPathElement
350
- });
351
-
352
- const mapPathsToRoutes = (paths, view) => {
353
- const routes = [];
354
- for (const [key, path] of Object.entries(paths)) {
355
- const pathView = view[key];
356
- if (pathView) {
357
- const route = {
358
- value: ""
359
- };
360
- routes.push(route);
361
- }
362
- }
363
- return routes;
364
- };
365
-
366
- const pluridLinkPathDivider = route => {
367
- const windowProtocol = typeof window === "undefined" ? "http" : window.location.protocol.replace(":", "");
368
- const windowHost = typeof window === "undefined" ? "localhost:63000" : window.location.host;
369
- const split = route.split("://").filter((value => value !== "")).map((value => cleanPathElement(value)));
370
- let protocol = windowProtocol;
371
- const host = {
372
- value: windowHost,
373
- controlled: false
374
- };
375
- const path = {
376
- value: "",
377
- parameters: {},
378
- query: {}
379
- };
380
- const space = {
381
- value: "",
382
- parameters: {},
383
- query: {}
384
- };
385
- const universe = {
386
- value: "",
387
- parameters: {},
388
- query: {}
389
- };
390
- const cluster = {
391
- value: "",
392
- parameters: {},
393
- query: {}
394
- };
395
- const plane = {
396
- value: "",
397
- parameters: {},
398
- query: {},
399
- fragments: {
400
- texts: [],
401
- elements: []
402
- }
403
- };
404
- const valid = false;
405
- if (split.length === 0 || split.length > 7) {
406
- const url = {
407
- protocol: {
408
- value: protocol,
409
- secure: true
410
- },
411
- host: host,
412
- path: path,
413
- space: space,
414
- universe: universe,
415
- cluster: cluster,
416
- plane: plane,
417
- valid: valid
418
- };
419
- return url;
420
- }
421
- if (route.startsWith("/://")) {
422
- const routeSplit = split.slice(1);
423
- switch (routeSplit.length) {
424
- case 1:
425
- path.value = routeSplit[0];
426
- break;
427
-
428
- case 5:
429
- path.value = routeSplit[0];
430
- space.value = routeSplit[1];
431
- universe.value = routeSplit[2];
432
- cluster.value = routeSplit[3];
433
- plane.value = routeSplit[4];
434
- break;
435
- }
436
- const url = {
437
- protocol: {
438
- value: protocol,
439
- secure: true
440
- },
441
- host: host,
442
- path: path,
443
- space: space,
444
- universe: universe,
445
- cluster: cluster,
446
- plane: plane,
447
- valid: true
448
- };
449
- return url;
450
- }
451
- if (split[0] !== "http" && split[0] !== "https" && split[0] !== "chrome-extension") {
452
- switch (split.length) {
453
- case 1:
454
- plane.value = split[0];
455
- break;
456
-
457
- case 2:
458
- cluster.value = split[0];
459
- plane.value = split[1];
460
- break;
461
-
462
- case 3:
463
- universe.value = split[0];
464
- cluster.value = split[1];
465
- plane.value = split[2];
466
- break;
467
-
468
- case 4:
469
- space.value = split[0];
470
- universe.value = split[1];
471
- cluster.value = split[2];
472
- plane.value = split[3];
473
- break;
474
-
475
- case 5:
476
- path.value = split[0];
477
- space.value = split[1];
478
- universe.value = split[2];
479
- cluster.value = split[3];
480
- plane.value = split[4];
481
- break;
482
-
483
- case 6:
484
- host.value = split[0];
485
- path.value = split[1];
486
- space.value = split[2];
487
- universe.value = split[3];
488
- cluster.value = split[4];
489
- plane.value = split[5];
490
- break;
491
-
492
- default:
493
- const url = {
494
- protocol: {
495
- value: protocol,
496
- secure: true
497
- },
498
- host: host,
499
- path: path,
500
- space: space,
501
- universe: universe,
502
- cluster: cluster,
503
- plane: plane,
504
- valid: valid
505
- };
506
- return url;
507
- }
508
- } else {
509
- switch (split.length) {
510
- case 3:
511
- protocol = split[0];
512
- host.value = split[1];
513
- path.value = split[2];
514
- break;
515
-
516
- case 7:
517
- protocol = split[0];
518
- host.value = split[1];
519
- path.value = split[2];
520
- space.value = split[3];
521
- universe.value = split[4];
522
- cluster.value = split[5];
523
- plane.value = split[6];
524
- break;
525
-
526
- default:
527
- const url = {
528
- protocol: {
529
- value: protocol,
530
- secure: true
531
- },
532
- host: host,
533
- path: path,
534
- space: space,
535
- universe: universe,
536
- cluster: cluster,
537
- plane: plane,
538
- valid: valid
539
- };
540
- return url;
541
- }
542
- }
543
- const url = {
544
- protocol: {
545
- value: protocol,
546
- secure: true
547
- },
548
- host: host,
549
- path: path,
550
- space: space,
551
- universe: universe,
552
- cluster: cluster,
553
- plane: plane,
554
- valid: true
555
- };
556
- return url;
557
- };
558
-
559
- const resolveRoute = (route, protocol, host) => {
560
- const windowProtocol = typeof window === "undefined" ? protocol || "http" : window.location.protocol.replace(":", "");
561
- const windowHost = typeof window === "undefined" ? host || "localhost:63000" : window.location.host;
562
- const divisions = pluridLinkPathDivider(route);
563
- const defaultPathname = typeof window !== "undefined" ? window.location.pathname === "/" ? "p" : window.location.pathname.slice(1) : divisions.path.value ? divisions.path.value : "p";
564
- const protocolDivision = divisions.protocol.value || windowProtocol;
565
- const hostDivision = divisions.host.value ? divisions.host : {
566
- value: windowHost,
567
- controlled: true
568
- };
569
- const path = divisions.path.value ? divisions.path : {
570
- value: defaultPathname,
571
- parameters: {},
572
- query: {}
573
- };
574
- const space = divisions.space.value ? divisions.space : {
575
- value: "s",
576
- parameters: {},
577
- query: {}
578
- };
579
- const universe = divisions.universe.value ? divisions.universe : {
580
- value: "u",
581
- parameters: {},
582
- query: {}
583
- };
584
- const cluster = divisions.cluster.value ? divisions.cluster : {
585
- value: "c",
586
- parameters: {},
587
- query: {}
588
- };
589
- const plane = divisions.plane;
590
- const separator = "://";
591
- if (!plane.value && route !== "/") {
592
- const resolvers = [ protocolDivision, hostDivision.value, path.value ];
593
- const absoluteRoute = resolvers.join(separator);
594
- return {
595
- protocol: protocolDivision,
596
- host: hostDivision,
597
- path: path,
598
- space: space,
599
- universe: universe,
600
- cluster: cluster,
601
- plane: plane,
602
- route: absoluteRoute
603
- };
604
- }
605
- [ protocolDivision, hostDivision.value, path.value, space.value, universe.value, cluster.value, cleanPathElement(plane.value) ];
606
- return {
607
- protocol: "",
608
- host: "",
609
- path: path,
610
- space: "",
611
- universe: "",
612
- cluster: "",
613
- plane: "",
614
- route: route
615
- };
616
- };
617
-
618
- const updateTreePlane$1 = (tree, page) => {
619
- const updatedTree = tree.map((treePlane => {
620
- if (treePlane.planeID === page.planeID) {
621
- return Object.assign({}, page);
622
- }
623
- if (treePlane.children) {
624
- return Object.assign(Object.assign({}, treePlane), {
625
- children: updateTreePlane$1(treePlane.children, page)
626
- });
627
- }
628
- return treePlane;
629
- }));
630
- return updatedTree;
631
- };
632
-
633
- const updateTreeByPlaneIDWithLinkCoordinates = (tree, planeID, linkCoordinates) => {
634
- const updatedTree = tree.map((treePlane => {
635
- if (treePlane.planeID === planeID) {
636
- const updatedPlane = Object.assign(Object.assign({}, treePlane), {
637
- linkCoordinates: linkCoordinates
638
- });
639
- return updatedPlane;
640
- }
641
- if (treePlane.children) {
642
- const updatedChildren = updateTreeByPlaneIDWithLinkCoordinates(treePlane.children, planeID, linkCoordinates);
643
- const updatedPlane = Object.assign(Object.assign({}, treePlane), {
644
- children: updatedChildren
645
- });
646
- return updatedPlane;
647
- }
648
- return treePlane;
649
- }));
650
- return updatedTree;
651
- };
652
-
653
- var index$i = Object.freeze({
654
- __proto__: null,
655
- updateTreePlane: updateTreePlane$1,
656
- updateTreeByPlaneIDWithLinkCoordinates: updateTreeByPlaneIDWithLinkCoordinates
657
- });
658
-
659
- var index$h = Object.freeze({
660
- __proto__: null,
661
- configuration: index$k,
662
- tree: index$i
663
- });
664
-
665
- const getWheelDirection = (deltas, ABSTHRESHOLD = 10, THRESHOLD = 0) => {
666
- let direction = "left";
667
- const wheelDeltaX = deltas.deltaX;
668
- const wheelDeltaY = deltas.deltaY;
669
- const absWheelDeltaX = Math.abs(wheelDeltaX);
670
- const absWheelDeltaY = Math.abs(wheelDeltaY);
671
- if (wheelDeltaX > THRESHOLD && absWheelDeltaY < ABSTHRESHOLD && absWheelDeltaX > absWheelDeltaY) {
672
- direction = "left";
673
- }
674
- if (wheelDeltaX < THRESHOLD && absWheelDeltaY < ABSTHRESHOLD && absWheelDeltaX > absWheelDeltaY) {
675
- direction = "right";
676
- }
677
- if (wheelDeltaY > THRESHOLD && absWheelDeltaX < ABSTHRESHOLD && absWheelDeltaY > absWheelDeltaX) {
678
- direction = "up";
679
- }
680
- if (wheelDeltaY < THRESHOLD && absWheelDeltaX < ABSTHRESHOLD && absWheelDeltaY > absWheelDeltaX) {
681
- direction = "down";
682
- }
683
- return direction;
684
- };
685
-
686
- var index$g = Object.freeze({
687
- __proto__: null,
688
- getWheelDirection: getWheelDirection
689
- });
690
-
691
- const degToRad = deg => deg * .01745329252;
692
-
693
- const radToDeg = rad => rad * 57.2957795131;
694
-
695
- const makeQuaternion = (x, y, z, w) => ({
696
- x: x,
697
- y: y,
698
- z: z,
699
- w: w
700
- });
701
-
702
- const zeroQuaternion = () => makeQuaternion(0, 0, 0, 0);
703
-
704
- function inverseQuaternion(quaternion) {
705
- return makeQuaternion(quaternion.x, quaternion.y, quaternion.z, -quaternion.w);
706
- }
707
-
708
- function conjugateQuaternion(quaternion) {
709
- return makeQuaternion(-quaternion.x, -quaternion.y, -quaternion.z, quaternion.w);
710
- }
711
-
712
- function computeQuaternionFromEulers(alpha, beta, gamma, radians = true) {
713
- const x = radians ? beta : degToRad(beta);
714
- const y = radians ? gamma : degToRad(gamma);
715
- const z = radians ? alpha : degToRad(alpha);
716
- const cX = Math.cos(x / 2);
717
- const cY = Math.cos(y / 2);
718
- const cZ = Math.cos(z / 2);
719
- const sX = Math.sin(x / 2);
720
- const sY = Math.sin(y / 2);
721
- const sZ = Math.sin(z / 2);
722
- const xQ = sX * cY * cZ - cX * sY * sZ;
723
- const yQ = cX * sY * cZ + sX * cY * sZ;
724
- const zQ = cX * cY * sZ + sX * sY * cZ;
725
- const wQ = cX * cY * cZ - sX * sY * sZ;
726
- return makeQuaternion(xQ, yQ, zQ, wQ);
727
- }
728
-
729
- function quaternionFromAxisAngle(x, y, z, angle) {
730
- const q = zeroQuaternion();
731
- const halfAngle = angle / 2;
732
- const sine = Math.sin(halfAngle);
733
- q.x = x * sine;
734
- q.y = y * sine;
735
- q.z = z * sine;
736
- q.w = Math.cos(halfAngle);
737
- return q;
738
- }
739
-
740
- function quaternionMultiply(quaternionArray) {
741
- const firstQuaternion = quaternionArray[0];
742
- const valueQuaternion = Object.assign({}, firstQuaternion);
743
- for (let i = 1; i < quaternionArray.length; i++) {
744
- const nextQuaternion = quaternionArray[i];
745
- const w = valueQuaternion.w * nextQuaternion.w - valueQuaternion.x * nextQuaternion.x - valueQuaternion.y * nextQuaternion.y - valueQuaternion.z * nextQuaternion.z;
746
- const x = valueQuaternion.x * nextQuaternion.w + valueQuaternion.w * nextQuaternion.x + valueQuaternion.y * nextQuaternion.z - valueQuaternion.z * nextQuaternion.y;
747
- const y = valueQuaternion.y * nextQuaternion.w + valueQuaternion.w * nextQuaternion.y + valueQuaternion.z * nextQuaternion.x - valueQuaternion.x * nextQuaternion.z;
748
- const z = valueQuaternion.z * nextQuaternion.w + valueQuaternion.w * nextQuaternion.z + valueQuaternion.x * nextQuaternion.y - valueQuaternion.y * nextQuaternion.x;
749
- valueQuaternion.x = x;
750
- valueQuaternion.y = y;
751
- valueQuaternion.z = z;
752
- valueQuaternion.w = w;
753
- }
754
- return valueQuaternion;
755
- }
756
-
757
- function rotatePointViaQuaternion(pointRotate, quaternion) {
758
- const temporaryQuaternion = {
759
- x: pointRotate[0],
760
- y: pointRotate[1],
761
- z: pointRotate[2],
762
- w: 0
763
- };
764
- const rotatedPointQuaternion = quaternionMultiply([ quaternion, temporaryQuaternion, conjugateQuaternion(quaternion) ]);
765
- return rotatedPointQuaternion;
766
- }
767
-
768
- function makeRotationMatrixFromQuaternion(quaternion) {
769
- const num = quaternion.x * 2;
770
- const num2 = quaternion.y * 2;
771
- const num3 = quaternion.z * 2;
772
- const num4 = quaternion.x * num;
773
- const num5 = quaternion.y * num2;
774
- const num6 = quaternion.z * num3;
775
- const num7 = quaternion.x * num2;
776
- const num8 = quaternion.x * num3;
777
- const num9 = quaternion.y * num3;
778
- const num10 = quaternion.w * num;
779
- const num11 = quaternion.w * num2;
780
- const num12 = quaternion.w * num3;
781
- return [ 1 - (num5 + num6), num7 - num12, num8 + num11, 0, num7 + num12, 1 - (num4 + num6), num9 - num10, 0, num8 - num11, num9 + num10, 1 - (num4 + num5), 0, 0, 0, 0, 1 ];
782
- }
783
-
784
- var index$f = Object.freeze({
785
- __proto__: null,
786
- degToRad: degToRad,
787
- radToDeg: radToDeg,
788
- makeQuaternion: makeQuaternion,
789
- zeroQuaternion: zeroQuaternion,
790
- inverseQuaternion: inverseQuaternion,
791
- conjugateQuaternion: conjugateQuaternion,
792
- computeQuaternionFromEulers: computeQuaternionFromEulers,
793
- quaternionFromAxisAngle: quaternionFromAxisAngle,
794
- quaternionMultiply: quaternionMultiply,
795
- rotatePointViaQuaternion: rotatePointViaQuaternion,
796
- makeRotationMatrixFromQuaternion: makeRotationMatrixFromQuaternion
797
- });
798
-
799
- function rotateMatrix(xAngle, yAngle, zAngle = 0) {
800
- const xQuaternion = computeQuaternionFromEulers(0, xAngle, 0);
801
- const yQuaternion = computeQuaternionFromEulers(0, 0, yAngle);
802
- const zQuaternion = computeQuaternionFromEulers(zAngle, 0, 0);
803
- const quartenionMultiplication = quaternionMultiply([ yQuaternion, xQuaternion, zQuaternion ]);
804
- const rotationMatrix = makeRotationMatrixFromQuaternion(quartenionMultiplication);
805
- return rotationMatrix;
806
- }
807
-
808
- function translateMatrix$1(x, y, z) {
809
- return [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 ];
810
- }
811
-
812
- function scaleMatrix$1(s) {
813
- return [ s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, 1 ];
814
- }
815
-
816
- function multiplyMatrices$1(matrixA, matrixB) {
817
- const result = [];
818
- const a00 = matrixA[0];
819
- const a01 = matrixA[1];
820
- const a02 = matrixA[2];
821
- const a03 = matrixA[3];
822
- const a10 = matrixA[4];
823
- const a11 = matrixA[5];
824
- const a12 = matrixA[6];
825
- const a13 = matrixA[7];
826
- const a20 = matrixA[8];
827
- const a21 = matrixA[9];
828
- const a22 = matrixA[10];
829
- const a23 = matrixA[11];
830
- const a30 = matrixA[12];
831
- const a31 = matrixA[13];
832
- const a32 = matrixA[14];
833
- const a33 = matrixA[15];
834
- let b0 = matrixB[0];
835
- let b1 = matrixB[1];
836
- let b2 = matrixB[2];
837
- let b3 = matrixB[3];
838
- result[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
839
- result[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
840
- result[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
841
- result[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
842
- b0 = matrixB[4];
843
- b1 = matrixB[5];
844
- b2 = matrixB[6];
845
- b3 = matrixB[7];
846
- result[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
847
- result[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
848
- result[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
849
- result[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
850
- b0 = matrixB[8];
851
- b1 = matrixB[9];
852
- b2 = matrixB[10];
853
- b3 = matrixB[11];
854
- result[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
855
- result[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
856
- result[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
857
- result[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
858
- b0 = matrixB[12];
859
- b1 = matrixB[13];
860
- b2 = matrixB[14];
861
- b3 = matrixB[15];
862
- result[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
863
- result[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
864
- result[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
865
- result[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
866
- return result;
867
- }
868
-
869
- function multiplyArrayOfMatrices(matrices) {
870
- let inputMatrix = matrices[0];
871
- for (let i = 1; i < matrices.length; i++) {
872
- inputMatrix = multiplyMatrices$1(inputMatrix, matrices[i]);
873
- }
874
- return inputMatrix;
875
- }
876
-
877
- function matrixArrayToCSSMatrix(array) {
878
- return "matrix3d(" + array.join(",") + ")";
879
- }
880
-
881
- var index$e = Object.freeze({
882
- __proto__: null,
883
- rotateMatrix: rotateMatrix,
884
- translateMatrix: translateMatrix$1,
885
- scaleMatrix: scaleMatrix$1,
886
- multiplyMatrices: multiplyMatrices$1,
887
- multiplyArrayOfMatrices: multiplyArrayOfMatrices,
888
- matrixArrayToCSSMatrix: matrixArrayToCSSMatrix
889
- });
890
-
891
- const getInitialMatrix = () => {
892
- const matrix = [ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ];
893
- return matrix;
894
- };
895
-
896
- const multiplyMatrices = (m1, m2) => {
897
- const result = [];
898
- for (let i = 0; i < m1.length; i++) {
899
- result[i] = [];
900
- for (let j = 0; j < m2[0].length; j++) {
901
- let sum = 0;
902
- for (let k = 0; k < m1[0].length; k++) {
903
- sum += m1[i][k] * m2[k][j];
904
- }
905
- result[i][j] = sum;
906
- }
907
- }
908
- return result;
909
- };
910
-
911
- const multiplyMatricesArray = matrices => {
912
- if (matrices.length < 2) {
913
- throw new Error("invalid number of matrices");
914
- }
915
- const first = matrices[0];
916
- let result = first;
917
- for (const [index, matrix] of matrices.entries()) {
918
- if (index === 0) {
919
- continue;
920
- }
921
- result = multiplyMatrices(result, matrix);
922
- }
923
- return result;
924
- };
925
-
926
- const arrayToMatrix = array => {
927
- const matrix = [];
928
- for (let i = 0; i < array.length; i += 4) {
929
- const row = [];
930
- row.push(array[i]);
931
- row.push(array[i + 1]);
932
- row.push(array[i + 2]);
933
- row.push(array[i + 3]);
934
- matrix.push(row);
935
- }
936
- return matrix;
937
- };
938
-
939
- const matrixToArray = matrix => matrix.flat();
940
-
941
- const matrix3DToMatrix = value => {
942
- const values = value.replace("matrix3d(", "").replace(")", "").split(",").map((val => parseFloat(val)));
943
- return arrayToMatrix(values);
944
- };
945
-
946
- const printMatrix = (matrix, name) => {
947
- const normalize = value => {
948
- if (value === 1 || value === 0) {
949
- return value + " ";
950
- }
951
- if (value > 0) {
952
- return value.toFixed(2) + " ";
953
- }
954
- return value.toFixed(2) + " ";
955
- };
956
- console.log("matrix", name + ":");
957
- for (const row of matrix) {
958
- console.log(normalize(row[0]), normalize(row[1]), normalize(row[2]), normalize(row[3]));
959
- }
960
- console.log(`matrix3d(${matrix.flat().join(",")})`);
961
- console.log();
962
- };
963
-
964
- const rotateXMatrix = angle => {
965
- const x = Math.cos(angle);
966
- const y = -1 * Math.sin(angle);
967
- const z = Math.sin(angle);
968
- const m = [ [ 1, 0, 0, 0 ], [ 0, x, y, 0 ], [ 0, z, x, 0 ], [ 0, 0, 0, 1 ] ];
969
- return m;
970
- };
971
-
972
- const rotateYMatrix = angle => {
973
- const x = Math.cos(angle);
974
- const y = -1 * Math.sin(angle);
975
- const z = Math.sin(angle);
976
- const m = [ [ x, 0, z, 0 ], [ 0, 1, 0, 0 ], [ y, 0, x, 0 ], [ 0, 0, 0, 1 ] ];
977
- return m;
978
- };
979
-
980
- const rotateZMatrix = angle => {
981
- const x = Math.cos(angle);
982
- const y = -1 * Math.sin(angle);
983
- const z = Math.sin(angle);
984
- const m = [ [ x, y, 0, 0 ], [ z, x, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ];
985
- return m;
986
- };
987
-
988
- const translateMatrix = (x = 0, y = 0, z = 0) => {
989
- const m = [ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ x, y, z, 1 ] ];
990
- return m;
991
- };
992
-
993
- const scaleMatrix = s => [ [ s, 0, 0, 0 ], [ 0, s, 0, 0 ], [ 0, 0, s, 0 ], [ 0, 0, 0, 1 ] ];
994
-
995
- function rotationMatrixFromQuaternion(quaternion) {
996
- const num = quaternion.x * 2;
997
- const num2 = quaternion.y * 2;
998
- const num3 = quaternion.z * 2;
999
- const num4 = quaternion.x * num;
1000
- const num5 = quaternion.y * num2;
1001
- const num6 = quaternion.z * num3;
1002
- const num7 = quaternion.x * num2;
1003
- const num8 = quaternion.x * num3;
1004
- const num9 = quaternion.y * num3;
1005
- const num10 = quaternion.w * num;
1006
- const num11 = quaternion.w * num2;
1007
- const num12 = quaternion.w * num3;
1008
- return [ [ 1 - (num5 + num6), num7 - num12, num8 + num11, 0 ], [ num7 + num12, 1 - (num4 + num6), num9 - num10, 0 ], [ num8 - num11, num9 + num10, 1 - (num4 + num5), 0 ], [ 0, 0, 0, 1 ] ];
1009
- }
1010
-
1011
- const matrixToCSSMatrix = matrix => {
1012
- const value = matrix.flat().join(",");
1013
- return `matrix3d(${value})`;
1014
- };
1015
-
1016
- const identityMatrix = () => {
1017
- const matrix = [ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ];
1018
- return matrix;
1019
- };
1020
-
1021
- const inverseMatrix = matrix => {
1022
- const cols = 4;
1023
- const rows = 4;
1024
- const A = [ ...matrix ];
1025
- const B = identityMatrix();
1026
- let r;
1027
- let s;
1028
- let f;
1029
- let temp;
1030
- for (let c = 0; c < cols; c++) {
1031
- let ABig = Math.abs(A[c][c]);
1032
- let rBig = c;
1033
- r = c + 1;
1034
- while (r < rows) {
1035
- if (Math.abs(A[r][c]) > ABig) {
1036
- ABig = Math.abs(A[r][c]);
1037
- rBig = r;
1038
- }
1039
- r++;
1040
- }
1041
- if (ABig === 0) {
1042
- throw Error("Cannot calculate inverse, determinant is zero");
1043
- }
1044
- r = rBig;
1045
- if (r !== c) {
1046
- temp = A[c];
1047
- A[c] = A[r];
1048
- A[r] = temp;
1049
- temp = B[c];
1050
- B[c] = B[r];
1051
- B[r] = temp;
1052
- }
1053
- const Ac = A[c];
1054
- const Bc = B[c];
1055
- for (r = 0; r < rows; r++) {
1056
- const Ar = A[r];
1057
- const Br = B[r];
1058
- if (r !== c) {
1059
- if (Ar[c] !== 0) {
1060
- f = -Ar[c] / Ac[c];
1061
- for (s = c; s < cols; s++) {
1062
- Ar[s] = Ar[s] + f * Ac[s];
1063
- }
1064
- for (s = 0; s < cols; s++) {
1065
- Br[s] = Br[s] + f * Bc[s];
1066
- }
1067
- }
1068
- } else {
1069
- f = Ac[c];
1070
- for (s = c; s < cols; s++) {
1071
- Ar[s] = Ar[s] / f;
1072
- }
1073
- for (s = 0; s < cols; s++) {
1074
- Br[s] = Br[s] / f;
1075
- }
1076
- }
1077
- }
1078
- }
1079
- return B;
1080
- };
1081
-
1082
- var index$d = Object.freeze({
1083
- __proto__: null,
1084
- getInitialMatrix: getInitialMatrix,
1085
- multiplyMatrices: multiplyMatrices,
1086
- multiplyMatricesArray: multiplyMatricesArray,
1087
- arrayToMatrix: arrayToMatrix,
1088
- matrixToArray: matrixToArray,
1089
- matrix3DToMatrix: matrix3DToMatrix,
1090
- printMatrix: printMatrix,
1091
- rotateXMatrix: rotateXMatrix,
1092
- rotateYMatrix: rotateYMatrix,
1093
- rotateZMatrix: rotateZMatrix,
1094
- translateMatrix: translateMatrix,
1095
- scaleMatrix: scaleMatrix,
1096
- rotationMatrixFromQuaternion: rotationMatrixFromQuaternion,
1097
- matrixToCSSMatrix: matrixToCSSMatrix,
1098
- identityMatrix: identityMatrix,
1099
- inverseMatrix: inverseMatrix
1100
- });
1101
-
1102
- function getMatrixValues(matrix3d) {
1103
- const matrixValues = matrix3d.split("(")[1].split(")")[0].split(",");
1104
- const matrixValuesInt = [];
1105
- for (let i = 0; i < matrixValues.length; i++) {
1106
- matrixValuesInt[i] = parseFloat(matrixValues[i]);
1107
- }
1108
- return matrixValuesInt;
1109
- }
1110
-
1111
- function getRotationMatrix(matrix3d) {
1112
- const valuesMatrix = getMatrixValues(matrix3d);
1113
- const scale = getScalationValue(matrix3d);
1114
- if (valuesMatrix.length === 16) {
1115
- for (let i = 0; i < 11; i++) {
1116
- valuesMatrix[i] /= scale;
1117
- }
1118
- } else if (valuesMatrix.length === 6) {
1119
- for (let i = 0; i < 4; i++) {
1120
- valuesMatrix[i] /= scale;
1121
- }
1122
- }
1123
- const rotationMatrix = valuesMatrix;
1124
- return rotationMatrix;
1125
- }
1126
-
1127
- function getTranslationMatrix(matrix3d) {
1128
- const valuesMatrix = getMatrixValues(matrix3d);
1129
- let translationMatrix;
1130
- if (valuesMatrix.length === 16) {
1131
- translationMatrix = getMatrixValues(matrix3d).slice(12, 15);
1132
- } else if (valuesMatrix.length === 6) {
1133
- translationMatrix = getMatrixValues(matrix3d).slice(4);
1134
- }
1135
- return translationMatrix;
1136
- }
1137
-
1138
- function getScalationValue(matrix3d) {
1139
- const valuesMatrix = getMatrixValues(matrix3d);
1140
- let temp = 0;
1141
- let scale;
1142
- if (valuesMatrix.length === 16) {
1143
- const scaleMatrix = getMatrixValues(matrix3d).slice(0, 4);
1144
- scale = 0;
1145
- for (const el of scaleMatrix) {
1146
- scale += parseFloat(el) * parseFloat(el);
1147
- }
1148
- scale = parseFloat(Math.sqrt(scale).toPrecision(4));
1149
- } else if (valuesMatrix.length === 6) {
1150
- temp = valuesMatrix[0] * valuesMatrix[0] + valuesMatrix[1] * valuesMatrix[1];
1151
- scale = parseFloat(Math.sqrt(temp).toPrecision(4));
1152
- }
1153
- return scale;
1154
- }
1155
-
1156
- function setTransform(rotationMatrix, translationMatrix, scalationMatrix) {
1157
- const transformMatrix = multiplyArrayOfMatrices([ translationMatrix, rotationMatrix, scalationMatrix ]);
1158
- return matrixArrayToCSSMatrix(transformMatrix);
1159
- }
1160
-
1161
- function getTransformRotate(matrix3d) {
1162
- const pi = Math.PI;
1163
- const values = getRotationMatrix(matrix3d);
1164
- let rotateX = 0;
1165
- let rotateY = 0;
1166
- if (values.length === 6) {
1167
- const cosa = values[0];
1168
- const sina = values[1];
1169
- if (cosa === 1 && sina === 0) {
1170
- rotateX = Math.asin(sina);
1171
- rotateY = Math.acos(cosa);
1172
- }
1173
- }
1174
- if (values.length === 16) {
1175
- const cosaX1 = values[5];
1176
- const sinaX3 = values[9];
1177
- if (sinaX3 <= 0) {
1178
- rotateX = Math.acos(cosaX1);
1179
- }
1180
- if (sinaX3 > 0) {
1181
- rotateX = 2 * pi - Math.acos(cosaX1);
1182
- }
1183
- const cosaY1 = values[0];
1184
- const sinaY2 = values[2];
1185
- if (sinaY2 <= 0) {
1186
- rotateY = Math.acos(cosaY1);
1187
- }
1188
- if (sinaY2 > 0) {
1189
- rotateY = 2 * pi - Math.acos(cosaY1);
1190
- }
1191
- rotateX = Math.atan2(values[9], values[5]);
1192
- rotateY = Math.atan2(values[2], values[0]);
1193
- }
1194
- return {
1195
- rotateX: rotateX,
1196
- rotateY: rotateY,
1197
- rotateZ: 0
1198
- };
1199
- }
1200
-
1201
- function getTransformTranslate(matrix3d) {
1202
- const values = getTranslationMatrix(matrix3d);
1203
- const translateX = values[0];
1204
- const translateY = values[1];
1205
- const translateZ = values[2];
1206
- return {
1207
- translateX: translateX,
1208
- translateY: translateY,
1209
- translateZ: translateZ
1210
- };
1211
- }
1212
-
1213
- function getTransformScale(matrix3d) {
1214
- const scale = getScalationValue(matrix3d);
1215
- return {
1216
- scale: scale
1217
- };
1218
- }
1219
-
1220
- function rotatePlurid(matrix3d, direction = "", angleIncrement = .07) {
1221
- const transformRotate = getTransformRotate(matrix3d);
1222
- const rotateX = transformRotate.rotateX;
1223
- let rotateY = transformRotate.rotateY;
1224
- const rotateZ = transformRotate.rotateZ;
1225
- const transformTranslate = getTransformTranslate(matrix3d);
1226
- const translateX = transformTranslate.translateX;
1227
- const translateY = transformTranslate.translateY;
1228
- const translateZ = transformTranslate.translateZ;
1229
- const scale = getTransformScale(matrix3d).scale;
1230
- let valRotationMatrix = rotateMatrix(rotateX, rotateY, rotateZ);
1231
- const valTranslationMatrix = translateMatrix$1(translateX, translateY, translateZ);
1232
- const valScalationMatrix = scaleMatrix$1(scale);
1233
- if (direction === "left") {
1234
- rotateY -= angleIncrement;
1235
- valRotationMatrix = rotateMatrix(rotateX, rotateY);
1236
- }
1237
- if (direction === "right") {
1238
- rotateY += angleIncrement;
1239
- valRotationMatrix = rotateMatrix(rotateX, rotateY);
1240
- }
1241
- if (direction === "up") {
1242
- rotateY -= angleIncrement;
1243
- valRotationMatrix = rotateMatrix(rotateX, rotateY);
1244
- }
1245
- if (direction === "down") {
1246
- rotateY += angleIncrement;
1247
- valRotationMatrix = rotateMatrix(rotateX, rotateY);
1248
- }
1249
- const transformedMatrix3d = setTransform(valRotationMatrix, valTranslationMatrix, valScalationMatrix);
1250
- return transformedMatrix3d;
1251
- }
1252
-
1253
- function translatePlurid(matrix3d, direction = "", linearIncrement = 50) {
1254
- const transformRotate = getTransformRotate(matrix3d);
1255
- const rotateX = transformRotate.rotateX;
1256
- const rotateY = transformRotate.rotateY;
1257
- const rotateZ = transformRotate.rotateZ;
1258
- const transformTranslate = getTransformTranslate(matrix3d);
1259
- let translateX = transformTranslate.translateX;
1260
- let translateY = transformTranslate.translateY;
1261
- const translateZ = transformTranslate.translateZ;
1262
- const scale = getTransformScale(matrix3d).scale;
1263
- const valRotationMatrix = rotateMatrix(rotateX, rotateY, rotateZ);
1264
- let valTranslationMatrix = translateMatrix$1(translateX, translateY, translateZ);
1265
- const valScalationMatrix = scaleMatrix$1(scale);
1266
- scale < .5 ? linearIncrement = 50 : linearIncrement = 30;
1267
- if (direction === "left") {
1268
- translateX += linearIncrement;
1269
- valTranslationMatrix = translateMatrix$1(translateX, translateY, translateZ);
1270
- }
1271
- if (direction === "right") {
1272
- translateX -= linearIncrement;
1273
- valTranslationMatrix = translateMatrix$1(translateX, translateY, translateZ);
1274
- }
1275
- if (direction === "up") {
1276
- translateY += linearIncrement;
1277
- valTranslationMatrix = translateMatrix$1(translateX, translateY, translateZ);
1278
- }
1279
- if (direction === "down") {
1280
- translateY -= linearIncrement;
1281
- valTranslationMatrix = translateMatrix$1(translateX, translateY, translateZ);
1282
- }
1283
- const transformedMatrix3d = setTransform(valRotationMatrix, valTranslationMatrix, valScalationMatrix);
1284
- return transformedMatrix3d;
1285
- }
1286
-
1287
- function scalePlurid(matrix3d, direction = "", scaleIncrement = .05) {
1288
- const transformRotate = getTransformRotate(matrix3d);
1289
- const rotateX = transformRotate.rotateX;
1290
- const rotateY = transformRotate.rotateY;
1291
- const rotateZ = transformRotate.rotateZ;
1292
- const transformTranslate = getTransformTranslate(matrix3d);
1293
- const translateX = transformTranslate.translateX;
1294
- const translateY = transformTranslate.translateY;
1295
- const translateZ = transformTranslate.translateZ;
1296
- let scale = getTransformScale(matrix3d).scale;
1297
- const valRotationMatrix = rotateMatrix(rotateX, rotateY, rotateZ);
1298
- const valTranslationMatrix = translateMatrix$1(translateX, translateY, translateZ);
1299
- let valScalationMatrix = scaleMatrix$1(scale);
1300
- if (direction === "up") {
1301
- scale -= scaleIncrement;
1302
- if (scale < .1) {
1303
- scale = .1;
1304
- }
1305
- valScalationMatrix = scaleMatrix$1(scale);
1306
- }
1307
- if (direction === "down") {
1308
- scale += scaleIncrement;
1309
- if (scale > 4) {
1310
- scale = 4;
1311
- }
1312
- valScalationMatrix = scaleMatrix$1(scale);
1313
- }
1314
- const transformedMatrix3d = setTransform(valRotationMatrix, valTranslationMatrix, valScalationMatrix);
1315
- return transformedMatrix3d;
1316
- }
1317
-
1318
- var index$c = Object.freeze({
1319
- __proto__: null,
1320
- getMatrixValues: getMatrixValues,
1321
- getRotationMatrix: getRotationMatrix,
1322
- getTranslationMatrix: getTranslationMatrix,
1323
- getScalationValue: getScalationValue,
1324
- setTransform: setTransform,
1325
- getTransformRotate: getTransformRotate,
1326
- getTransformTranslate: getTransformTranslate,
1327
- getTransformScale: getTransformScale,
1328
- rotatePlurid: rotatePlurid,
1329
- translatePlurid: translatePlurid,
1330
- scalePlurid: scalePlurid
1331
- });
1332
-
1333
- var index$b = Object.freeze({
1334
- __proto__: null,
1335
- general: index$d,
1336
- matrix3d: index$c
1337
- });
1338
-
1339
- var index$a = Object.freeze({
1340
- __proto__: null,
1341
- direction: index$g,
1342
- matrix: index$e,
1343
- quaternion: index$f,
1344
- transform: index$b
1345
- });
1346
-
1347
- const internatiolate = (lamguage, field) => internationalization[lamguage][field];
1348
-
1349
- const resolvePluridPlaneData = plane => {
1350
- if (Array.isArray(plane)) {
1351
- const [route, component, options] = plane;
1352
- return Object.assign({
1353
- route: route,
1354
- component: component
1355
- }, options);
1356
- }
1357
- return plane;
1358
- };
1359
-
1360
- const resolvePluridRoutePlaneData = plane => {
1361
- if (Array.isArray(plane)) {
1362
- const [value, component, options] = plane;
1363
- return Object.assign({
1364
- value: value,
1365
- component: component
1366
- }, options);
1367
- }
1368
- return plane;
1369
- };
1370
-
1371
- const getPluridPlaneIDByData = element => {
1372
- if (!element) {
1373
- return "";
1374
- }
1375
- const parent = element.parentElement;
1376
- if (parent && parent.dataset.pluridPlane) {
1377
- return parent.dataset.pluridPlane;
1378
- }
1379
- return getPluridPlaneIDByData(parent);
1380
- };
1381
-
1382
- class IsoMatcher {
1383
- constructor(data, origin = "origin") {
1384
- this.routesIndex = new Map;
1385
- this.planesIndex = new Map;
1386
- this.routesKeys = [];
1387
- this.planesKeys = [];
1388
- if (origin === "origin" && typeof location !== "undefined" && location.host) {
1389
- this.origin = location.host;
1390
- } else {
1391
- this.origin = origin;
1392
- }
1393
- this.updateIndexes(data.routes || [], data.routePlanes || [], data.planes || []);
1394
- }
1395
- match(path, context = "plane") {
1396
- switch (context) {
1397
- case "plane":
1398
- return this.matchPlane(path);
1399
-
1400
- case "route":
1401
- return this.matchRoute(path);
1402
- }
1403
- }
1404
- index(data) {
1405
- this.updateIndexes(data.routes || [], data.routePlanes || [], data.planes || []);
1406
- }
1407
- clear() {
1408
- this.routesIndex = new Map;
1409
- this.planesIndex = new Map;
1410
- this.routesKeys = [];
1411
- this.planesKeys = [];
1412
- }
1413
- getPlanesIndex() {
1414
- return this.planesIndex;
1415
- }
1416
- updateIndexes(routes, routePlanes, planes) {
1417
- this.indexPlanes(planes, "Plane");
1418
- this.indexPlanes(routePlanes, "RoutePlane");
1419
- for (const route of routes) {
1420
- if (route.planes) {
1421
- this.indexPlanes(route.planes, "RoutePlane", route.value);
1422
- }
1423
- this.routesIndex.set(route.value, {
1424
- data: Object.assign({}, route)
1425
- });
1426
- }
1427
- this.routesKeys = Array.from(this.routesIndex.keys());
1428
- this.planesKeys = Array.from(this.planesIndex.keys());
1429
- }
1430
- indexPlanes(planes, kind, parent) {
1431
- for (const plane of planes) {
1432
- const planeData = kind === "Plane" ? resolvePluridPlaneData(plane) : resolvePluridRoutePlaneData(plane);
1433
- const address = computePlaneAddress(kind === "Plane" ? planeData.route : planeData.value, parent, this.origin);
1434
- const indexedPlane = {
1435
- kind: kind,
1436
- data: Object.assign({}, planeData)
1437
- };
1438
- if (parent) {
1439
- indexedPlane["parent"] = parent;
1440
- }
1441
- this.planesIndex.set(address, indexedPlane);
1442
- }
1443
- }
1444
- matchPlane(value) {
1445
- const planeAddress = computePlaneAddress(value, undefined, this.origin);
1446
- const plane = this.planesIndex.get(planeAddress);
1447
- if (plane) {
1448
- const query = extractQuery(value);
1449
- const fragments = extractFragments(value);
1450
- const match = {
1451
- value: planeAddress,
1452
- fragments: fragments,
1453
- query: query,
1454
- parameters: {}
1455
- };
1456
- if (plane.kind === "Plane") {
1457
- const {kind: kind, data: data, parent: parent} = plane;
1458
- const result = {
1459
- kind: kind,
1460
- data: data,
1461
- parent: parent,
1462
- match: match
1463
- };
1464
- return result;
1465
- }
1466
- if (plane.kind === "RoutePlane") {
1467
- const {kind: kind, data: data, parent: parent} = plane;
1468
- const result = {
1469
- kind: kind,
1470
- data: data,
1471
- parent: parent,
1472
- match: match
1473
- };
1474
- return result;
1475
- }
1476
- }
1477
- for (const planePath of this.planesKeys) {
1478
- const normalizedPlanePath = planePath.replace(protocols.plurid, "");
1479
- const normalizedPlaneAddress = planeAddress.replace(protocols.plurid, "");
1480
- const planePathSplit = normalizedPlanePath.split("/");
1481
- const planeAddressSplit = normalizedPlaneAddress.split("/");
1482
- if (planePathSplit[0] !== planeAddressSplit[0]) {
1483
- continue;
1484
- }
1485
- if (planePathSplit.length !== planeAddressSplit.length) {
1486
- continue;
1487
- }
1488
- const parametersAndMatch = extractParametersAndMatch(normalizedPlaneAddress, normalizedPlanePath);
1489
- if (parametersAndMatch.match) {
1490
- const plane = this.planesIndex.get(planePath);
1491
- if (!plane) {
1492
- return;
1493
- }
1494
- const {parameters: parameters} = parametersAndMatch;
1495
- const validPath = checkValidPath(plane.data.parameters, parameters);
1496
- if (!validPath) {
1497
- return;
1498
- }
1499
- const query = extractQuery(value);
1500
- const fragments = extractFragments(value);
1501
- const match = {
1502
- value: planeAddress,
1503
- fragments: fragments,
1504
- query: query,
1505
- parameters: parameters
1506
- };
1507
- if (plane.kind === "Plane") {
1508
- const {kind: kind, data: data, parent: parent} = plane;
1509
- const result = {
1510
- kind: kind,
1511
- data: data,
1512
- parent: parent,
1513
- match: match
1514
- };
1515
- return result;
1516
- }
1517
- if (plane.kind === "RoutePlane") {
1518
- const {kind: kind, data: data, parent: parent} = plane;
1519
- const result = {
1520
- kind: kind,
1521
- data: data,
1522
- parent: parent,
1523
- match: match
1524
- };
1525
- return result;
1526
- }
1527
- }
1528
- }
1529
- return;
1530
- }
1531
- matchRoute(value) {
1532
- const routeValue = cleanPathValue(value);
1533
- const route = this.routesIndex.get(routeValue);
1534
- if (route) {
1535
- const query = extractQuery(value);
1536
- const result = {
1537
- kind: "Route",
1538
- data: route.data,
1539
- match: {
1540
- value: routeValue,
1541
- query: query,
1542
- parameters: {}
1543
- }
1544
- };
1545
- return result;
1546
- }
1547
- for (const routePath of this.routesKeys) {
1548
- const routeSplit = routePath.split("/");
1549
- const valueSplit = routeValue.split("/");
1550
- if (routeSplit.length !== valueSplit.length) {
1551
- continue;
1552
- }
1553
- const parametersAndMatch = extractParametersAndMatch(routeValue.slice(1), routePath.slice(1));
1554
- if (parametersAndMatch.match) {
1555
- const route = this.routesIndex.get(routePath);
1556
- if (!route) {
1557
- return;
1558
- }
1559
- const {parameters: parameters} = parametersAndMatch;
1560
- const validPath = checkValidPath(route.data.parameters, parameters);
1561
- if (!validPath) {
1562
- return;
1563
- }
1564
- const query = extractQuery(routeValue);
1565
- const match = {
1566
- value: routeValue,
1567
- query: query,
1568
- parameters: parameters
1569
- };
1570
- if (route) {
1571
- const result = {
1572
- kind: "Route",
1573
- data: route.data,
1574
- match: match
1575
- };
1576
- return result;
1577
- }
1578
- }
1579
- }
1580
- const routePlane = this.matchPlane(routeValue);
1581
- if (routePlane) {
1582
- const result = {
1583
- kind: "RoutePlane",
1584
- data: routePlane.data,
1585
- match: {
1586
- value: routeValue,
1587
- query: routePlane.match.query,
1588
- parameters: routePlane.match.parameters
1589
- }
1590
- };
1591
- return result;
1592
- }
1593
- return;
1594
- }
1595
- }
1596
-
1597
- class Parser {
1598
- constructor(location, path, options) {
1599
- this.location = location;
1600
- this.path = path;
1601
- this.options = this.handleOptions(options);
1602
- }
1603
- handleOptions(options) {
1604
- const parserOptions = {
1605
- fragment: (options === null || options === void 0 ? void 0 : options.fragment) || true
1606
- };
1607
- return parserOptions;
1608
- }
1609
- extractPathname() {
1610
- const pathname = extractPathname(this.location);
1611
- return pathname;
1612
- }
1613
- extractParametersAndMatch() {
1614
- const parametersAndMatch = extractParametersAndMatch(this.location, this.path.value);
1615
- return parametersAndMatch;
1616
- }
1617
- extractQuery() {
1618
- const query = extractQuery(this.location);
1619
- return query;
1620
- }
1621
- extractFragments() {
1622
- const fragments = this.options.fragment ? extractFragments(this.location) : extractFragments();
1623
- return fragments;
1624
- }
1625
- extract() {
1626
- const pathname = this.extractPathname();
1627
- const {match: match, parameters: parameters, elements: elements} = this.extractParametersAndMatch();
1628
- const query = this.extractQuery();
1629
- const queryData = Object.entries(query).map((([key, value]) => key + "=" + value)).join("&");
1630
- const queryString = queryData ? "?" + queryData : "";
1631
- const fragments = this.extractFragments();
1632
- const parserResponse = {
1633
- path: this.path,
1634
- pathname: pathname,
1635
- elements: elements,
1636
- match: match,
1637
- parameters: parameters,
1638
- query: query,
1639
- fragments: fragments,
1640
- route: pathname + queryString
1641
- };
1642
- return parserResponse;
1643
- }
1644
- }
1645
-
1646
- var index$9 = Object.freeze({
1647
- __proto__: null,
1648
- IsoMatcher: IsoMatcher,
1649
- RouteParser: Parser,
1650
- extractQuery: extractQuery,
1651
- stringInsertInitial: stringInsertInitial,
1652
- stringRemoveTrailing: stringRemoveTrailing,
1653
- cleanupPath: cleanupPath,
1654
- computePlaneAddress: computePlaneAddress,
1655
- isAbsolutePlane: isAbsolutePlane,
1656
- checkPlaneAddressType: checkPlaneAddressType,
1657
- removeTrailingSlash: removeTrailingSlash,
1658
- cleanPathValue: cleanPathValue,
1659
- checkParameterLength: checkParameterLength,
1660
- checkValidPath: checkValidPath,
1661
- mapPathsToRoutes: mapPathsToRoutes,
1662
- pluridLinkPathDivider: pluridLinkPathDivider,
1663
- resolveRoute: resolveRoute
1664
- });
1665
-
1666
- class PluridPlanesRegistrar {
1667
- constructor(planes, origin = "origin") {
1668
- this.isoMatcher = new IsoMatcher({
1669
- planes: planes
1670
- }, origin);
1671
- }
1672
- register(planes) {
1673
- this.isoMatcher.index({
1674
- planes: planes
1675
- });
1676
- }
1677
- identify() {
1678
- const planes = this.isoMatcher.getPlanesIndex();
1679
- return [ ...planes.keys() ];
1680
- }
1681
- get(route) {
1682
- const match = this.isoMatcher.match(route);
1683
- if (match) {
1684
- const absoluteRoute = match.kind === "Plane" ? match.data.route : match.data.value;
1685
- const registeredPlane = {
1686
- route: {
1687
- absolute: absoluteRoute,
1688
- fragments: match.match.fragments,
1689
- parameters: match.match.parameters,
1690
- query: match.match.query
1691
- },
1692
- component: match.data.component
1693
- };
1694
- return registeredPlane;
1695
- }
1696
- return;
1697
- }
1698
- getAll() {
1699
- const planes = this.isoMatcher.getPlanesIndex();
1700
- const all = new Map;
1701
- for (const [path, plane] of planes) {
1702
- const absoluteRoute = plane.kind === "Plane" ? plane.data.route : plane.data.value;
1703
- const registeredPlane = {
1704
- route: {
1705
- absolute: absoluteRoute,
1706
- fragments: {
1707
- elements: [],
1708
- texts: []
1709
- },
1710
- parameters: {},
1711
- query: {}
1712
- },
1713
- component: plane.data.component
1714
- };
1715
- all.set(path, registeredPlane);
1716
- }
1717
- return all;
1718
- }
1719
- }
1720
-
1721
- const registerPlanes = (planes, planesRegistrar, origin = "origin") => {
1722
- if (!planes) {
1723
- return;
1724
- }
1725
- if (planesRegistrar) {
1726
- planesRegistrar.register(planes);
1727
- return;
1728
- }
1729
- if (typeof window === "undefined") {
1730
- return;
1731
- }
1732
- if (typeof window.__pluridPlanesRegistrar__ === "undefined") {
1733
- const pluridPlanesRegistrar = new PluridPlanesRegistrar([], origin);
1734
- window.__pluridPlanesRegistrar__ = pluridPlanesRegistrar;
1735
- window.__pluridPlanesRegistrar__.register(planes);
1736
- return;
1737
- }
1738
- window.__pluridPlanesRegistrar__.register(planes);
1739
- return;
1740
- };
1741
-
1742
- const getPlanesRegistrar = planesRegistrar => {
1743
- if (planesRegistrar) {
1744
- return planesRegistrar;
1745
- }
1746
- if (typeof window !== "undefined") {
1747
- if (window.__pluridPlanesRegistrar__ !== undefined) {
1748
- return window.__pluridPlanesRegistrar__;
1749
- }
1750
- }
1751
- return;
1752
- };
1753
-
1754
- const getRegisteredPlanes = planesRegistrar => {
1755
- if (planesRegistrar) {
1756
- return planesRegistrar.getAll();
1757
- }
1758
- if (typeof window !== "undefined") {
1759
- if (window.__pluridPlanesRegistrar__ !== undefined) {
1760
- return window.__pluridPlanesRegistrar__.getAll();
1761
- }
1762
- }
1763
- return new Map;
1764
- };
1765
-
1766
- const getRegisteredPlane = (route, planesRegistrar) => {
1767
- if (planesRegistrar) {
1768
- return planesRegistrar.get(route);
1769
- }
1770
- if (typeof window !== "undefined") {
1771
- if (window.__pluridPlanesRegistrar__ !== undefined) {
1772
- return window.__pluridPlanesRegistrar__.get(route);
1773
- }
1774
- }
1775
- return;
1776
- };
1777
-
1778
- var index$8 = Object.freeze({
1779
- __proto__: null,
1780
- resolvePluridPlaneData: resolvePluridPlaneData,
1781
- resolvePluridRoutePlaneData: resolvePluridRoutePlaneData,
1782
- getPluridPlaneIDByData: getPluridPlaneIDByData,
1783
- registerPlanes: registerPlanes,
1784
- getPlanesRegistrar: getPlanesRegistrar,
1785
- getRegisteredPlanes: getRegisteredPlanes,
1786
- getRegisteredPlane: getRegisteredPlane,
1787
- Registrar: PluridPlanesRegistrar
1788
- });
1789
-
1790
- const computeSpaceSize = tree => {
1791
- let width = 0;
1792
- let height = 0;
1793
- let depth = 0;
1794
- const topCorner = {
1795
- x: 0,
1796
- y: 0,
1797
- z: 0
1798
- };
1799
- tree.map((treePage => {
1800
- const spaceWidth = treePage.location.translateX + treePage.width;
1801
- if (spaceWidth > width) {
1802
- width = spaceWidth;
1803
- }
1804
- const spaceHeight = treePage.location.translateY + treePage.height;
1805
- if (spaceHeight > height) {
1806
- height = spaceHeight;
1807
- }
1808
- const spaceDepth = treePage.location.translateZ;
1809
- if (spaceDepth > depth) {
1810
- depth = spaceDepth;
1811
- }
1812
- }));
1813
- return {
1814
- width: width,
1815
- height: height,
1816
- depth: depth,
1817
- topCorner: topCorner
1818
- };
1819
- };
1820
-
1821
- const findPage = (view, pages) => {
1822
- for (const page of pages) {
1823
- if (page.route === view) {
1824
- return page;
1825
- }
1826
- }
1827
- return;
1828
- };
1829
-
1830
- const splitIntoGroups = (data, length) => {
1831
- const initialArray = [ ...data ];
1832
- const groups = [];
1833
- while (initialArray.length) {
1834
- const group = initialArray.splice(0, length);
1835
- groups.push(group);
1836
- }
1837
- return groups;
1838
- };
1839
-
1840
- const getTreePlaneByPlaneID = (tree, planeID) => {
1841
- let _page = null;
1842
- for (const page of tree) {
1843
- if (page.planeID === planeID) {
1844
- _page = page;
1845
- }
1846
- if (page.children && !_page) {
1847
- _page = getTreePlaneByPlaneID(page.children, planeID);
1848
- }
1849
- if (_page) {
1850
- break;
1851
- }
1852
- }
1853
- return _page;
1854
- };
1855
-
1856
- var index$7 = Object.freeze({
1857
- __proto__: null,
1858
- computeSpaceSize: computeSpaceSize,
1859
- findPage: findPage,
1860
- splitIntoGroups: splitIntoGroups,
1861
- getTreePlaneByPlaneID: getTreePlaneByPlaneID
1862
- });
1863
-
1864
- const toRadians$1 = mathematics.geometry.toRadians;
1865
-
1866
- const computePath = (tree, planeID) => {
1867
- const path = [];
1868
- const page = getTreePlaneByPlaneID(tree, planeID);
1869
- if (page) {
1870
- path.push(Object.assign({}, page));
1871
- let parentID = page.parentPlaneID;
1872
- if (!parentID) {
1873
- return path;
1874
- }
1875
- while (parentID) {
1876
- const parentPage = getTreePlaneByPlaneID(tree, parentID);
1877
- if (parentPage) {
1878
- const page = Object.assign({}, parentPage);
1879
- page.children = [];
1880
- path.push(page);
1881
- parentID = parentPage.parentPlaneID;
1882
- }
1883
- }
1884
- }
1885
- return path.reverse();
1886
- };
1887
-
1888
- const computePluridPlaneLocation = (linkCoordinates, treePageParent, bridgeLength = 100, linkPlaneAngle = 90) => {
1889
- const parentAngleRadians = toRadians$1(treePageParent.location.rotateY);
1890
- const linkPoint = {
1891
- x: treePageParent.location.translateX + linkCoordinates.x * Math.cos(parentAngleRadians),
1892
- z: treePageParent.location.translateZ - linkCoordinates.x * Math.sin(parentAngleRadians)
1893
- };
1894
- const linkAngleRadians = toRadians$1(linkPlaneAngle + treePageParent.location.rotateY);
1895
- const x = linkPoint.x + bridgeLength * Math.cos(linkAngleRadians);
1896
- const z = linkPoint.z - bridgeLength * Math.sin(linkAngleRadians);
1897
- const y = treePageParent.location.translateY + linkCoordinates.y;
1898
- const locationCoordinates = {
1899
- x: x,
1900
- y: y,
1901
- z: z
1902
- };
1903
- return locationCoordinates;
1904
- };
1905
-
1906
- const recomputeChildrenLocation = page => {
1907
- if (!page.children) {
1908
- return [];
1909
- }
1910
- const updatedChildren = [];
1911
- for (const child of page.children) {
1912
- if (child.linkCoordinates) {
1913
- const location = computePluridPlaneLocation(child.linkCoordinates, page, child.bridgeLength, child.planeAngle);
1914
- const updatedChild = Object.assign(Object.assign({}, child), {
1915
- location: Object.assign(Object.assign({}, child.location), {
1916
- translateX: location.x,
1917
- translateY: location.y,
1918
- translateZ: location.z
1919
- })
1920
- });
1921
- const children = updatedChild.children ? recomputeChildrenLocation(updatedChild) : [];
1922
- const updatedChildWithChildren = Object.assign(Object.assign({}, updatedChild), {
1923
- children: children
1924
- });
1925
- updatedChildren.push(updatedChildWithChildren);
1926
- }
1927
- }
1928
- return updatedChildren;
1929
- };
1930
-
1931
- var index$6 = Object.freeze({
1932
- __proto__: null,
1933
- computePath: computePath,
1934
- computePluridPlaneLocation: computePluridPlaneLocation,
1935
- recomputeChildrenLocation: recomputeChildrenLocation
1936
- });
1937
-
1938
- const computeColumnLayout = (roots, columns = 1, columnLength, gap = ROOTS_GAP, configuration = defaultConfiguration) => {
1939
- const windowInnerWidth = typeof window === "undefined" ? 1440 : window.innerWidth;
1940
- const windowInnerHeight = typeof window === "undefined" ? 840 : window.innerHeight;
1941
- const tree = [];
1942
- const configurationWidth = configuration.elements.plane.width;
1943
- const width = mathematics.numbers.checkIntegerNonUnit(configurationWidth) ? configurationWidth : configurationWidth * windowInnerWidth;
1944
- const height = windowInnerHeight;
1945
- const gapValue = mathematics.numbers.checkIntegerNonUnit(gap) ? gap : gap * width;
1946
- const length = columnLength || Math.ceil(roots.length / columns);
1947
- for (const [index, root] of roots.entries()) {
1948
- const rowIndex = index % length;
1949
- const columnIndex = Math.floor(index / length);
1950
- const translateX = columnIndex * (width + gapValue);
1951
- const translateY = rowIndex * (height + gapValue);
1952
- const treePage = Object.assign(Object.assign({}, root), {
1953
- location: {
1954
- translateX: translateX,
1955
- translateY: translateY,
1956
- translateZ: 0,
1957
- rotateX: 0,
1958
- rotateY: 0
1959
- }
1960
- });
1961
- const children = recomputeChildrenLocation(treePage);
1962
- const treePageWithChildren = Object.assign(Object.assign({}, treePage), {
1963
- children: children
1964
- });
1965
- tree.push(treePageWithChildren);
1966
- }
1967
- return tree;
1968
- };
1969
-
1970
- const computeRowLayout = (roots, rows = 1, rowLength, gap = ROOTS_GAP, configuration = defaultConfiguration) => {
1971
- const windowInnerWidth = typeof window === "undefined" ? 1440 : window.innerWidth;
1972
- const windowInnerHeight = typeof window === "undefined" ? 840 : window.innerHeight;
1973
- const tree = [];
1974
- const configurationWidth = configuration.elements.plane.width;
1975
- const width = mathematics.numbers.checkIntegerNonUnit(configurationWidth) ? configurationWidth : configurationWidth * windowInnerWidth;
1976
- const height = windowInnerHeight;
1977
- const gapValue = mathematics.numbers.checkIntegerNonUnit(gap) ? gap : gap * width;
1978
- const length = rowLength || Math.ceil(roots.length / rows);
1979
- for (const [index, root] of roots.entries()) {
1980
- const rowIndex = Math.floor(index / length);
1981
- const columnIndex = index % length;
1982
- const translateX = columnIndex * (width + gapValue);
1983
- const translateY = rowIndex * (height + gapValue);
1984
- const treePage = Object.assign(Object.assign({}, root), {
1985
- location: {
1986
- translateX: translateX,
1987
- translateY: translateY,
1988
- translateZ: 0,
1989
- rotateX: 0,
1990
- rotateY: 0
1991
- }
1992
- });
1993
- const children = recomputeChildrenLocation(treePage);
1994
- const treePageWithChildren = Object.assign(Object.assign({}, treePage), {
1995
- children: children
1996
- });
1997
- tree.push(treePageWithChildren);
1998
- }
1999
- return tree;
2000
- };
2001
-
2002
- const toRadians = mathematics.geometry.toRadians;
2003
-
2004
- const computeFaceToFaceTranslateZ = (width, angle, first) => {
2005
- if (first) {
2006
- return width * Math.sin(toRadians(angle));
2007
- }
2008
- return 0;
2009
- };
2010
-
2011
- const computeFaceToFaceTranslateX = (width, angle, gap, first, index) => {
2012
- const firstTranslateX = width * Math.cos(toRadians(angle));
2013
- if (first) {
2014
- return firstTranslateX;
2015
- }
2016
- const value = width * (index - 1) + 2 * firstTranslateX + gap * index;
2017
- return value;
2018
- };
2019
-
2020
- const computeFaceToFaceRotateY = (angle, first, last) => {
2021
- const rotateY = first ? angle : last ? -angle : 0;
2022
- return rotateY;
2023
- };
2024
-
2025
- const computeFaceToFaceLayout = (roots, angle = 45, gap = 0, middle = 0, configuration = defaultConfiguration) => {
2026
- const windowInnerWidth = typeof window === "undefined" ? 1440 : window.innerWidth;
2027
- const windowInnerHeight = typeof window === "undefined" ? 840 : window.innerHeight;
2028
- const tree = [];
2029
- const width = mathematics.numbers.checkIntegerNonUnit(configuration.elements.plane.width) ? configuration.elements.plane.width : configuration.elements.plane.width * windowInnerWidth;
2030
- const height = windowInnerHeight;
2031
- const planeAngle = 90 - angle / 2;
2032
- const columns = 2 + middle;
2033
- const rows = splitIntoGroups(roots, columns);
2034
- const gapValue = Number.isInteger(gap) ? gap : gap * width;
2035
- for (const [index, row] of rows.entries()) {
2036
- const translateY = index * height;
2037
- for (const [index, page] of row.entries()) {
2038
- const first = index === 0;
2039
- const last = index === columns - 1;
2040
- const translateZ = computeFaceToFaceTranslateZ(width, planeAngle, first);
2041
- const translateX = computeFaceToFaceTranslateX(width, planeAngle, gapValue, first, index);
2042
- const rotateY = computeFaceToFaceRotateY(planeAngle, first, last);
2043
- const treePage = Object.assign(Object.assign({}, page), {
2044
- location: {
2045
- translateX: translateX,
2046
- translateY: translateY,
2047
- translateZ: translateZ,
2048
- rotateX: 0,
2049
- rotateY: rotateY
2050
- }
2051
- });
2052
- const children = recomputeChildrenLocation(treePage);
2053
- const treePageWithChildren = Object.assign(Object.assign({}, treePage), {
2054
- children: children
2055
- });
2056
- tree.push(treePageWithChildren);
2057
- }
2058
- }
2059
- return tree;
2060
- };
2061
-
2062
- const computeSheavesLayout = (roots, depth = .3, offsetX = 0, offsetY = 0, configuration = defaultConfiguration) => {
2063
- const windowInnerWidth = typeof window === "undefined" ? 1440 : window.innerWidth;
2064
- const tree = [];
2065
- mathematics.numbers.checkIntegerNonUnit(configuration.elements.plane.width) ? configuration.elements.plane.width : configuration.elements.plane.width * windowInnerWidth;
2066
- for (const [index, page] of roots.entries()) {
2067
- const translateX = 0;
2068
- const translateY = 0;
2069
- const treePage = Object.assign(Object.assign({}, page), {
2070
- location: {
2071
- translateX: translateX,
2072
- translateY: translateY,
2073
- translateZ: 0,
2074
- rotateX: 0,
2075
- rotateY: 0
2076
- }
2077
- });
2078
- const children = recomputeChildrenLocation(treePage);
2079
- const treePageWithChildren = Object.assign(Object.assign({}, treePage), {
2080
- children: children
2081
- });
2082
- tree.push(treePageWithChildren);
2083
- }
2084
- return tree;
2085
- };
2086
-
2087
- const computeZigZagLayout = (pages, angle = 45, configuration = defaultConfiguration) => {
2088
- const tree = [];
2089
- const singleColumnedRoots = computeColumnLayout(pages, 1);
2090
- for (const [index, page] of singleColumnedRoots.entries()) {
2091
- const value = index % 2 === 0 ? 1 : -1;
2092
- page.location.rotateY = value * angle;
2093
- const children = recomputeChildrenLocation(page);
2094
- const treePageWithChildren = Object.assign(Object.assign({}, page), {
2095
- children: children
2096
- });
2097
- tree.push(Object.assign({}, treePageWithChildren));
2098
- }
2099
- return tree;
2100
- };
2101
-
2102
- var index$5 = Object.freeze({
2103
- __proto__: null,
2104
- computeColumnLayout: computeColumnLayout,
2105
- computeRowLayout: computeRowLayout,
2106
- computeFaceToFaceLayout: computeFaceToFaceLayout,
2107
- computeSheavesLayout: computeSheavesLayout,
2108
- computeZigZagLayout: computeZigZagLayout
2109
- });
2110
-
2111
- const resolveViewItem = (planes, view, configuration, origin = "origin", getCount) => {
2112
- const {protocol: protocol, host: host} = configuration.network;
2113
- const viewData = typeof view === "string" ? view : view.plane;
2114
- const viewAddress = computePlaneAddress(viewData, undefined, origin);
2115
- const iPlanes = planes.values();
2116
- const pluridPlanes = [];
2117
- for (const iPlane of iPlanes) {
2118
- const plane = {
2119
- route: iPlane.route.absolute,
2120
- component: iPlane.component
2121
- };
2122
- pluridPlanes.push(plane);
2123
- }
2124
- const isoMatcher = new IsoMatcher({
2125
- planes: pluridPlanes
2126
- }, origin);
2127
- const match = isoMatcher.match(viewData);
2128
- if (match) {
2129
- const route = match.match.value;
2130
- const count = getCount ? getCount() : uuid.generate();
2131
- const planeID = route + "@" + count;
2132
- const treePlane = {
2133
- sourceID: route,
2134
- planeID: planeID,
2135
- route: viewAddress,
2136
- routeDivisions: {
2137
- protocol: {
2138
- value: "",
2139
- secure: false
2140
- },
2141
- host: {
2142
- value: host,
2143
- controlled: true
2144
- },
2145
- path: {
2146
- parameters: {},
2147
- query: {},
2148
- value: ""
2149
- },
2150
- space: {
2151
- parameters: {},
2152
- query: {},
2153
- value: ""
2154
- },
2155
- universe: {
2156
- parameters: {},
2157
- query: {},
2158
- value: ""
2159
- },
2160
- cluster: {
2161
- parameters: {},
2162
- query: {},
2163
- value: ""
2164
- },
2165
- plane: {
2166
- parameters: {},
2167
- fragments: {
2168
- elements: [],
2169
- texts: []
2170
- },
2171
- query: {},
2172
- value: ""
2173
- },
2174
- valid: true
2175
- },
2176
- height: 0,
2177
- width: 0,
2178
- location: {
2179
- translateX: 0,
2180
- translateY: 0,
2181
- translateZ: 0,
2182
- rotateX: 0,
2183
- rotateY: 0
2184
- },
2185
- show: true
2186
- };
2187
- return treePlane;
2188
- }
2189
- return;
2190
- };
2191
-
2192
- const computeSpaceTree = (planes, view, configuration, layout, origin = "origin", getCount) => {
2193
- const treePlanes = [];
2194
- for (const viewItem of view) {
2195
- const treePlane = resolveViewItem(planes, viewItem, configuration, origin, getCount);
2196
- if (treePlane) {
2197
- treePlanes.push(treePlane);
2198
- }
2199
- }
2200
- if (!layout) {
2201
- const layoutlessTreePlanes = treePlanes.map((plane => Object.assign(Object.assign({}, plane), {
2202
- location: {
2203
- rotateX: 0,
2204
- rotateY: 0,
2205
- translateX: 0,
2206
- translateY: 0,
2207
- translateZ: 0
2208
- }
2209
- })));
2210
- return layoutlessTreePlanes;
2211
- }
2212
- switch (configuration.space.layout.type) {
2213
- case LAYOUT_TYPES.COLUMNS:
2214
- {
2215
- const {columns: columns, columnLength: columnLength, gap: gap} = configuration.space.layout;
2216
- const columnLayoutTree = computeColumnLayout(treePlanes, columns, columnLength, gap, configuration);
2217
- return columnLayoutTree;
2218
- }
2219
-
2220
- case LAYOUT_TYPES.ROWS:
2221
- {
2222
- const {rows: rows, rowLength: rowLength, gap: gap} = configuration.space.layout;
2223
- const rowLayoutTree = computeRowLayout(treePlanes, rows, rowLength, gap, configuration);
2224
- return rowLayoutTree;
2225
- }
2226
-
2227
- case LAYOUT_TYPES.ZIG_ZAG:
2228
- {
2229
- const {angle: angle} = configuration.space.layout;
2230
- const zigzagLayoutTree = computeZigZagLayout(treePlanes, angle, configuration);
2231
- return zigzagLayoutTree;
2232
- }
2233
-
2234
- case LAYOUT_TYPES.FACE_TO_FACE:
2235
- {
2236
- const {angle: angle, gap: gap, middle: middle} = configuration.space.layout;
2237
- const faceToFaceLayoutTree = computeFaceToFaceLayout(treePlanes, angle, gap, middle, configuration);
2238
- return faceToFaceLayoutTree;
2239
- }
2240
-
2241
- case LAYOUT_TYPES.SHEAVES:
2242
- {
2243
- const {depth: depth, offsetX: offsetX, offsetY: offsetY} = configuration.space.layout;
2244
- const sheavesLayoutTree = computeSheavesLayout(treePlanes, depth, offsetX, offsetY, configuration);
2245
- return sheavesLayoutTree;
2246
- }
2247
-
2248
- case LAYOUT_TYPES.META:
2249
- {
2250
- return [];
2251
- }
2252
-
2253
- default:
2254
- return [];
2255
- }
2256
- };
2257
-
2258
- const isParametric = (viewRoute, planeRoute) => true;
2259
-
2260
- const matchForParameters = (viewRoute, planeRoute) => {
2261
- const splitViewRoute = viewRoute.split("://");
2262
- const splitPlaneRoute = planeRoute.split("://");
2263
- splitViewRoute[2];
2264
- splitPlaneRoute[2];
2265
- };
2266
-
2267
- const assignPagesFromView = (planes, view) => {
2268
- if (!view) {
2269
- return planes;
2270
- }
2271
- const tree = [];
2272
- for (const viewPlane of view) {
2273
- if (typeof viewPlane === "string") {
2274
- for (const plane of planes) {
2275
- if (viewPlane === plane.sourceID) {
2276
- tree.push(plane);
2277
- }
2278
- if (isParametric(viewPlane, plane.sourceID)) {
2279
- const parametricPlane = Object.assign({}, plane);
2280
- parametricPlane.routeDivisions.plane.parameters.id = "one";
2281
- parametricPlane.routeDivisions.plane.value = "one";
2282
- parametricPlane.route = viewPlane;
2283
- tree.push(parametricPlane);
2284
- }
2285
- }
2286
- }
2287
- }
2288
- return tree;
2289
- };
2290
-
2291
- const updateTreePlane = (tree, updatedPlane) => {
2292
- const updatedTree = tree.map((treePlane => {
2293
- if (treePlane.planeID === updatedPlane.planeID) {
2294
- return updatedPlane;
2295
- }
2296
- if (treePlane.children) {
2297
- const children = updateTreePlane(treePlane.children, updatedPlane);
2298
- treePlane.children = children;
2299
- return treePlane;
2300
- }
2301
- return treePlane;
2302
- }));
2303
- return updatedTree;
2304
- };
2305
-
2306
- const updateTreeWithNewPlane = (planeRoute, parentPlaneID, linkCoordinates, tree, planesRegistry, configuration, hostname = "origin") => {
2307
- const parentPlane = getTreePlaneByPlaneID(tree, parentPlaneID);
2308
- if (!parentPlane) {
2309
- return {
2310
- pluridPlaneID: "",
2311
- updatedTree: tree
2312
- };
2313
- }
2314
- const location = computePluridPlaneLocation(linkCoordinates, parentPlane);
2315
- const treePlane = resolveViewItem(planesRegistry, planeRoute, configuration, hostname);
2316
- if (!treePlane) {
2317
- return {
2318
- pluridPlaneID: "",
2319
- updatedTree: tree
2320
- };
2321
- }
2322
- const updatedTreePlane = Object.assign(Object.assign({}, treePlane), {
2323
- parentPlaneID: parentPlaneID,
2324
- location: {
2325
- translateX: location.x,
2326
- translateY: location.y,
2327
- translateZ: location.z,
2328
- rotateX: 0,
2329
- rotateY: parentPlane.location.rotateY + PLANE_DEFAULT_ANGLE
2330
- },
2331
- bridgeLength: 100,
2332
- planeAngle: 90,
2333
- linkCoordinates: linkCoordinates
2334
- });
2335
- const updatedParentPlane = Object.assign({}, parentPlane);
2336
- if (updatedParentPlane.children) {
2337
- updatedParentPlane.children.push(updatedTreePlane);
2338
- } else {
2339
- updatedParentPlane.children = [ updatedTreePlane ];
2340
- }
2341
- const updatedTree = updateTreePlane(tree, updatedParentPlane);
2342
- return {
2343
- pluridPlaneID: updatedTreePlane.planeID,
2344
- updatedTree: updatedTree,
2345
- updatedTreePlane: updatedTreePlane
2346
- };
2347
- };
2348
-
2349
- const updatePlaneLocation = (tree, parentPlaneID, planeID, linkCoordinates) => {
2350
- const parentPlane = getTreePlaneByPlaneID(tree, parentPlaneID);
2351
- const plane = getTreePlaneByPlaneID(tree, planeID);
2352
- if (!parentPlane || !plane) {
2353
- return tree;
2354
- }
2355
- const location = computePluridPlaneLocation(linkCoordinates, parentPlane);
2356
- plane.location = {
2357
- translateX: location.x,
2358
- translateY: location.y,
2359
- translateZ: location.z,
2360
- rotateX: 0,
2361
- rotateY: parentPlane.location.rotateY + PLANE_DEFAULT_ANGLE
2362
- };
2363
- const updatedTree = updateTreePlane(tree, plane);
2364
- return updatedTree;
2365
- };
2366
-
2367
- const updateTreeWithNewPage = (tree, treePageParentPlaneID, pagePath, pageID, linkCoordinates, parameters) => {
2368
- const treePageParent = getTreePlaneByPlaneID(tree, treePageParentPlaneID);
2369
- if (treePageParent) {
2370
- const location = computePluridPlaneLocation(linkCoordinates, treePageParent);
2371
- const planeID = uuid.generate();
2372
- const newTreePlane = {
2373
- sourceID: pageID,
2374
- route: pagePath,
2375
- routeDivisions: {
2376
- protocol: {
2377
- value: "",
2378
- secure: false
2379
- },
2380
- host: {
2381
- value: "",
2382
- controlled: false
2383
- },
2384
- path: {
2385
- value: "",
2386
- parameters: {},
2387
- query: {}
2388
- },
2389
- space: {
2390
- value: "",
2391
- parameters: {},
2392
- query: {}
2393
- },
2394
- universe: {
2395
- value: "",
2396
- parameters: {},
2397
- query: {}
2398
- },
2399
- cluster: {
2400
- value: "",
2401
- parameters: {},
2402
- query: {}
2403
- },
2404
- plane: {
2405
- value: "",
2406
- parameters: {},
2407
- query: {},
2408
- fragments: {
2409
- texts: [],
2410
- elements: []
2411
- }
2412
- },
2413
- valid: false
2414
- },
2415
- planeID: planeID,
2416
- width: 0,
2417
- height: 0,
2418
- parentPlaneID: treePageParentPlaneID,
2419
- location: {
2420
- translateX: location.x,
2421
- translateY: location.y,
2422
- translateZ: location.z,
2423
- rotateX: 0,
2424
- rotateY: treePageParent.location.rotateY + PLANE_DEFAULT_ANGLE
2425
- },
2426
- show: true,
2427
- bridgeLength: 100,
2428
- planeAngle: 90,
2429
- linkCoordinates: linkCoordinates
2430
- };
2431
- const updatedTreePlaneParent = Object.assign({}, treePageParent);
2432
- if (updatedTreePlaneParent.children) {
2433
- updatedTreePlaneParent.children.push(newTreePlane);
2434
- } else {
2435
- updatedTreePlaneParent.children = [ newTreePlane ];
2436
- }
2437
- const updatedTree = updateTreePlane(tree, updatedTreePlaneParent);
2438
- return {
2439
- pluridPlaneID: planeID,
2440
- updatedTree: updatedTree
2441
- };
2442
- }
2443
- return {
2444
- pluridPlaneID: "",
2445
- updatedTree: tree
2446
- };
2447
- };
2448
-
2449
- const removePageFromTree = (tree, pluridPlaneID) => {
2450
- const updatedTree = tree.filter((page => {
2451
- if (page.planeID === pluridPlaneID) {
2452
- return false;
2453
- }
2454
- if (page.children) {
2455
- const pageTree = removePageFromTree(page.children, pluridPlaneID);
2456
- page.children = pageTree;
2457
- return page;
2458
- }
2459
- return page;
2460
- }));
2461
- return updatedTree;
2462
- };
2463
-
2464
- const toggleChildren = children => {
2465
- const updatedChildren = children.map((child => {
2466
- if (child.children) {
2467
- const updatedChild = Object.assign(Object.assign({}, child), {
2468
- show: !child.show,
2469
- children: toggleChildren(child.children)
2470
- });
2471
- return updatedChild;
2472
- }
2473
- const updatedChild = Object.assign(Object.assign({}, child), {
2474
- show: !child.show
2475
- });
2476
- return updatedChild;
2477
- }));
2478
- return updatedChildren;
2479
- };
2480
-
2481
- const toggleAllChildren = (tree, show) => {
2482
- for (const plane of tree) {
2483
- if (plane.children) {
2484
- plane.children = toggleAllChildren(plane.children, show);
2485
- }
2486
- plane.show = show;
2487
- }
2488
- return tree;
2489
- };
2490
-
2491
- const togglePlaneFromTree = (tree, pluridPlaneID, forceShow) => {
2492
- const updatedTree = [];
2493
- let updatedPlane;
2494
- for (const plane of tree) {
2495
- if (plane.planeID === pluridPlaneID) {
2496
- const show = forceShow !== null && forceShow !== void 0 ? forceShow : !plane.show;
2497
- const treeUpdatedPlane = Object.assign(Object.assign({}, plane), {
2498
- show: show
2499
- });
2500
- if (treeUpdatedPlane.children) {
2501
- const children = toggleAllChildren(treeUpdatedPlane.children, show);
2502
- treeUpdatedPlane.children = children;
2503
- }
2504
- updatedTree.push(treeUpdatedPlane);
2505
- updatedPlane = Object.assign({}, treeUpdatedPlane);
2506
- continue;
2507
- }
2508
- if (plane.children) {
2509
- const {updatedTree: childrenUpdatedTree, updatedPlane: childrenUpdatedPlane} = togglePlaneFromTree(plane.children, pluridPlaneID, forceShow);
2510
- plane.children = [ ...childrenUpdatedTree ];
2511
- updatedTree.push(plane);
2512
- if (childrenUpdatedPlane) {
2513
- updatedPlane = Object.assign({}, childrenUpdatedPlane);
2514
- }
2515
- continue;
2516
- }
2517
- updatedTree.push(plane);
2518
- }
2519
- return {
2520
- updatedTree: updatedTree,
2521
- updatedPlane: updatedPlane
2522
- };
2523
- };
2524
-
2525
- const getTreePlaneByID = (stateTree, id) => {
2526
- if (!id) {
2527
- return;
2528
- }
2529
- for (const plane of stateTree) {
2530
- if (plane.planeID === id) {
2531
- return plane;
2532
- }
2533
- if (plane.children) {
2534
- const found = getTreePlaneByID(plane.children, id);
2535
- if (found) {
2536
- return found;
2537
- }
2538
- }
2539
- }
2540
- return;
2541
- };
2542
-
2543
- const removeRootFromTree = (tree, pluridPlaneID) => {
2544
- const updatedTree = tree.filter((plane => plane.planeID !== pluridPlaneID));
2545
- return {
2546
- updatedTree: updatedTree
2547
- };
2548
- };
2549
-
2550
- const removePlaneFromTree = (tree, pluridPlaneID) => {
2551
- const updatedTree = [];
2552
- for (const plane of tree) {
2553
- if (plane.planeID === pluridPlaneID) {
2554
- continue;
2555
- }
2556
- if (plane.children) {
2557
- const children = removePlaneFromTree(plane.children, pluridPlaneID);
2558
- plane.children = children;
2559
- }
2560
- updatedTree.push(plane);
2561
- }
2562
- return updatedTree;
2563
- };
2564
-
2565
- var logic = Object.freeze({
2566
- __proto__: null,
2567
- resolveViewItem: resolveViewItem,
2568
- computeSpaceTree: computeSpaceTree,
2569
- isParametric: isParametric,
2570
- matchForParameters: matchForParameters,
2571
- assignPagesFromView: assignPagesFromView,
2572
- updateTreePlane: updateTreePlane,
2573
- updateTreeWithNewPlane: updateTreeWithNewPlane,
2574
- updatePlaneLocation: updatePlaneLocation,
2575
- updateTreeWithNewPage: updateTreeWithNewPage,
2576
- removePageFromTree: removePageFromTree,
2577
- toggleChildren: toggleChildren,
2578
- toggleAllChildren: toggleAllChildren,
2579
- togglePlaneFromTree: togglePlaneFromTree,
2580
- getTreePlaneByID: getTreePlaneByID,
2581
- removeRootFromTree: removeRootFromTree,
2582
- removePlaneFromTree: removePlaneFromTree
2583
- });
2584
-
2585
- class Tree {
2586
- constructor(data, origin = "origin") {
2587
- this.count = 0;
2588
- this.data = data;
2589
- this.origin = origin;
2590
- }
2591
- compute() {
2592
- const {planes: planes, view: view, configuration: configuration, layout: layout} = this.data;
2593
- return computeSpaceTree(planes, view, configuration, layout, this.origin, this.getCount.bind(this));
2594
- }
2595
- getCount() {
2596
- return this.count++;
2597
- }
2598
- }
2599
-
2600
- var index$4 = Object.freeze({
2601
- __proto__: null,
2602
- Tree: Tree,
2603
- logic: logic
2604
- });
2605
-
2606
- const computeViewTree = (pages, view) => {
2607
- const viewTree = [];
2608
- for (const pageView of view) {
2609
- const page = pages.find((p => p.route === pageView));
2610
- if (page) {
2611
- viewTree.push(page);
2612
- }
2613
- }
2614
- return viewTree;
2615
- };
2616
-
2617
- const computeCulledView = (pages, view, location, radius = 8e3) => {
2618
- const culledView = [];
2619
- for (const viewPage of view) {
2620
- const path = typeof viewPage === "string" ? viewPage : viewPage.plane;
2621
- const page = findPage(path, pages);
2622
- if (!page) {
2623
- return;
2624
- }
2625
- const pageInView = checkPageInView(page, location, radius);
2626
- if (pageInView) {
2627
- culledView.push(page.route);
2628
- }
2629
- }
2630
- return culledView;
2631
- };
2632
-
2633
- const checkPageInView = (page, location, radius) => {
2634
- const radiusLeft = location.translationX < 0 ? Math.abs(location.translationX) - radius : -1 * location.translationX - radius;
2635
- const radiusRight = location.translationX < 0 ? Math.abs(location.translationX) + radius : -1 * location.translationX + radius;
2636
- const locationX = page.location.translateX;
2637
- const radiusTop = location.translationY < 0 ? Math.abs(location.translationY) - radius : -1 * location.translationY - radius;
2638
- const radiusBottom = location.translationY < 0 ? Math.abs(location.translationY) + radius : -1 * location.translationY + radius;
2639
- const locationY = page.location.translateY;
2640
- const inViewOnX = radiusLeft <= locationX && locationX <= radiusRight;
2641
- const inViewOnY = radiusTop <= locationY && locationY <= radiusBottom;
2642
- if (inViewOnX && inViewOnY) {
2643
- return true;
2644
- }
2645
- return false;
2646
- };
2647
-
2648
- var index$3 = Object.freeze({
2649
- __proto__: null,
2650
- computeViewTree: computeViewTree,
2651
- computeCulledView: computeCulledView,
2652
- checkPageInView: checkPageInView
2653
- });
2654
-
2655
- var index$2 = Object.freeze({
2656
- __proto__: null,
2657
- layout: index$5,
2658
- location: index$6,
2659
- tree: index$4,
2660
- utilities: index$7,
2661
- view: index$3
2662
- });
2663
-
2664
- const resolveSpace = (view, configuration, planesRegistrar, currentState, localState, precomputedState, contextState, hostname = "origin") => {
2665
- const registeredPlanes = getRegisteredPlanes(planesRegistrar);
2666
- const spaceTree = new Tree({
2667
- planes: registeredPlanes,
2668
- configuration: configuration,
2669
- view: view
2670
- }, hostname);
2671
- const computedTree = spaceTree.compute();
2672
- const stateSpace = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({
2673
- loading: true,
2674
- resolvedLayout: false,
2675
- animatedTransform: false,
2676
- transformTime: 450,
2677
- scale: 1,
2678
- rotationX: 0,
2679
- rotationY: 0,
2680
- translationX: 0,
2681
- translationY: 0,
2682
- translationZ: 0,
2683
- transform: "matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)",
2684
- activeUniverseID: "",
2685
- camera: {
2686
- x: 0,
2687
- y: 0,
2688
- z: 0
2689
- },
2690
- viewSize: {
2691
- width: 771,
2692
- height: 764
2693
- },
2694
- spaceSize: {
2695
- width: 771,
2696
- height: 764,
2697
- depth: 0,
2698
- topCorner: {
2699
- x: 0,
2700
- y: 0,
2701
- z: 0
2702
- }
2703
- },
2704
- culledView: [],
2705
- activePlaneID: "",
2706
- isolatePlane: "",
2707
- lastClosedPlane: "",
2708
- tree: computedTree
2709
- }, precomputedState === null || precomputedState === void 0 ? void 0 : precomputedState.space), contextState === null || contextState === void 0 ? void 0 : contextState.space), localState === null || localState === void 0 ? void 0 : localState.space), currentState === null || currentState === void 0 ? void 0 : currentState.space), {
2710
- view: view
2711
- });
2712
- if (currentState) {
2713
- stateSpace.translationX = currentState.space.translationX;
2714
- stateSpace.translationY = currentState.space.translationY;
2715
- stateSpace.translationZ = currentState.space.translationZ;
2716
- stateSpace.rotationX = currentState.space.rotationX;
2717
- stateSpace.rotationY = currentState.space.rotationY;
2718
- stateSpace.scale = currentState.space.scale;
2719
- }
2720
- if (localState && !currentState) {
2721
- stateSpace.translationX = localState.space.translationX;
2722
- stateSpace.translationY = localState.space.translationY;
2723
- stateSpace.translationZ = localState.space.translationZ;
2724
- stateSpace.rotationX = localState.space.rotationX;
2725
- stateSpace.rotationY = localState.space.rotationY;
2726
- stateSpace.scale = localState.space.scale;
2727
- }
2728
- return stateSpace;
2729
- };
2730
-
2731
- const resolveThemes = (configuration, precomputedState) => {
2732
- let generalTheme;
2733
- let interactionTheme;
2734
- if (typeof configuration.global.theme === "object") {
2735
- const {general: general, interaction: interaction} = configuration.global.theme;
2736
- if (typeof general === "string") {
2737
- if (Object.keys(THEME_NAMES).includes(general)) {
2738
- generalTheme = themes[general];
2739
- }
2740
- }
2741
- if (typeof interaction === "string") {
2742
- if (Object.keys(THEME_NAMES).includes(interaction)) {
2743
- interactionTheme = themes[interaction];
2744
- }
2745
- }
2746
- } else {
2747
- if (Object.keys(THEME_NAMES).includes(configuration.global.theme)) {
2748
- generalTheme = themes[configuration.global.theme];
2749
- interactionTheme = themes[configuration.global.theme];
2750
- }
2751
- }
2752
- const stateThemes = Object.assign({
2753
- general: generalTheme || themes.plurid,
2754
- interaction: interactionTheme || themes.plurid
2755
- }, precomputedState === null || precomputedState === void 0 ? void 0 : precomputedState.themes);
2756
- return stateThemes;
2757
- };
2758
-
2759
- const compute = (view, configuration, planesRegistrar, currentState, localState, precomputedState, contextState, hostname = "origin") => {
2760
- let stateConfiguration = merge(configuration);
2761
- const configurations = [ precomputedState === null || precomputedState === void 0 ? void 0 : precomputedState.configuration, contextState === null || contextState === void 0 ? void 0 : contextState.configuration, localState === null || localState === void 0 ? void 0 : localState.configuration, currentState === null || currentState === void 0 ? void 0 : currentState.configuration ];
2762
- for (const configuration of configurations) {
2763
- if (configuration) {
2764
- stateConfiguration = merge(configuration);
2765
- }
2766
- }
2767
- const stateSpace = resolveSpace(view, stateConfiguration, planesRegistrar, currentState, localState, precomputedState, contextState, hostname);
2768
- const stateThemes = resolveThemes(stateConfiguration, precomputedState);
2769
- const state = {
2770
- configuration: Object.assign({}, stateConfiguration),
2771
- shortcuts: Object.assign({
2772
- global: true
2773
- }, precomputedState === null || precomputedState === void 0 ? void 0 : precomputedState.shortcuts),
2774
- space: Object.assign({}, stateSpace),
2775
- themes: Object.assign({}, stateThemes),
2776
- ui: Object.assign(Object.assign({
2777
- toolbarScrollPosition: 0
2778
- }, precomputedState === null || precomputedState === void 0 ? void 0 : precomputedState.ui), contextState === null || contextState === void 0 ? void 0 : contextState.ui)
2779
- };
2780
- return state;
2781
- };
2782
-
2783
- const load = (id, useLocalStorage) => {
2784
- if (!useLocalStorage) {
2785
- return;
2786
- }
2787
- if (typeof localStorage === "undefined") {
2788
- return;
2789
- }
2790
- try {
2791
- const stateID = id || "default";
2792
- const stateData = localStorage.getItem("pluridState-" + stateID);
2793
- if (!stateData) {
2794
- return;
2795
- }
2796
- const state = JSON.parse(stateData);
2797
- return state;
2798
- } catch (error) {
2799
- return;
2800
- }
2801
- };
2802
-
2803
- var index$1 = Object.freeze({
2804
- __proto__: null,
2805
- load: load
2806
- });
2807
-
2808
- var index = Object.freeze({
2809
- __proto__: null,
2810
- compute: compute,
2811
- local: index$1
2812
- });
2813
-
2814
- const cleanTemplate = template => template.replace(/(?:\r\n|\r|\n)/g, " ").replace(/ +/g, " ").trim();
2815
-
2816
- const pluridRouterNavigate = path => {
2817
- if (!CustomEvent || !window) {
2818
- return;
2819
- }
2820
- const event = new CustomEvent(PLURID_ROUTER_LOCATION_CHANGED, {
2821
- detail: {
2822
- path: path
2823
- }
2824
- });
2825
- window.dispatchEvent(event);
2826
- };
2827
-
2828
- export { cleanTemplate, index$h as general, index$a as interaction, internatiolate, index$8 as planes, pluridRouterNavigate, index$9 as routing, index$2 as space, index as state, index$j as utilities };
2829
- //# sourceMappingURL=index.es.js.map