@configura/babylon-view 1.4.0-alpha.4 → 1.4.0

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 (125) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +1 -1
  3. package/dist/animation/AnimatableObject.d.ts +8 -8
  4. package/dist/animation/AnimatableObject.js +3 -3
  5. package/dist/animation/animator/Animator.d.ts +33 -33
  6. package/dist/animation/animator/Animator.js +58 -58
  7. package/dist/animation/animator/AnimatorEasing.d.ts +16 -16
  8. package/dist/animation/animator/AnimatorEasing.js +31 -31
  9. package/dist/animation/animator/AnimatorEasingMatrix.d.ts +14 -14
  10. package/dist/animation/animator/AnimatorEasingMatrix.js +16 -16
  11. package/dist/animation/animator/AnimatorHighlight.d.ts +16 -16
  12. package/dist/animation/animator/AnimatorHighlight.js +32 -32
  13. package/dist/animation/animator/AnimatorPointToPoint.d.ts +8 -8
  14. package/dist/animation/animator/AnimatorPointToPoint.js +14 -14
  15. package/dist/animation/animator/AnimatorQueue.d.ts +13 -13
  16. package/dist/animation/animator/AnimatorQueue.js +57 -57
  17. package/dist/animation/animator/AnimatorScale.d.ts +8 -8
  18. package/dist/animation/animator/AnimatorScale.js +13 -13
  19. package/dist/animation/animator/AnimatorSpin.d.ts +10 -10
  20. package/dist/animation/animator/AnimatorSpin.js +13 -13
  21. package/dist/animation/animator/EasingFunctions.d.ts +35 -35
  22. package/dist/animation/animator/EasingFunctions.js +137 -137
  23. package/dist/animation/coordinator/Coordinator.d.ts +28 -28
  24. package/dist/animation/coordinator/Coordinator.js +47 -47
  25. package/dist/animation/coordinator/CoordinatorDropAndSpin.d.ts +22 -22
  26. package/dist/animation/coordinator/CoordinatorDropAndSpin.js +133 -133
  27. package/dist/animation/coordinator/CoordinatorIdentity.d.ts +11 -11
  28. package/dist/animation/coordinator/CoordinatorIdentity.js +12 -12
  29. package/dist/animation/coordinator/CoordinatorNodeQueues.d.ts +18 -18
  30. package/dist/animation/coordinator/CoordinatorNodeQueues.js +50 -50
  31. package/dist/animation/coordinator/CoordinatorPulse.d.ts +21 -21
  32. package/dist/animation/coordinator/CoordinatorPulse.js +47 -47
  33. package/dist/animation/coordinator/CoordinatorPulseBounce.d.ts +14 -14
  34. package/dist/animation/coordinator/CoordinatorPulseBounce.js +40 -40
  35. package/dist/animation/coordinator/CoordinatorPulseHighlight.d.ts +13 -13
  36. package/dist/animation/coordinator/CoordinatorPulseHighlight.js +34 -34
  37. package/dist/animation/coordinator/CoordinatorPulseInflate.d.ts +14 -14
  38. package/dist/animation/coordinator/CoordinatorPulseInflate.js +30 -30
  39. package/dist/camera/CameraCreator.d.ts +5 -5
  40. package/dist/camera/CameraCreator.js +4 -4
  41. package/dist/camera/CfgArcRotateCameraPointersInput.d.ts +26 -26
  42. package/dist/camera/CfgArcRotateCameraPointersInput.js +264 -264
  43. package/dist/camera/CfgOrbitalCamera.d.ts +68 -68
  44. package/dist/camera/CfgOrbitalCamera.js +250 -250
  45. package/dist/camera/CfgOrbitalCameraControlProps.d.ts +6 -6
  46. package/dist/camera/CfgOrbitalCameraControlProps.js +3 -3
  47. package/dist/camera/GradingApplier.d.ts +3 -3
  48. package/dist/camera/GradingApplier.js +48 -48
  49. package/dist/engine/EngineCreator.d.ts +3 -3
  50. package/dist/engine/EngineCreator.js +10 -10
  51. package/dist/geometry/CfgGeometry.d.ts +29 -29
  52. package/dist/geometry/CfgGeometry.js +146 -146
  53. package/dist/geometry/CfgMesh.d.ts +10 -10
  54. package/dist/geometry/CfgMesh.js +38 -38
  55. package/dist/geometry/geoSplitter.d.ts +8 -8
  56. package/dist/geometry/geoSplitter.js +192 -192
  57. package/dist/geometry/stretch/CfgMorphTarget.d.ts +15 -15
  58. package/dist/geometry/stretch/CfgMorphTarget.js +65 -65
  59. package/dist/geometry/stretch/CfgStretchData.d.ts +114 -114
  60. package/dist/geometry/stretch/CfgStretchData.js +340 -340
  61. package/dist/geometry/stretch/CfgStretchMorphGeometry.d.ts +16 -16
  62. package/dist/geometry/stretch/CfgStretchMorphGeometry.js +95 -95
  63. package/dist/index.d.ts +13 -13
  64. package/dist/index.js +13 -13
  65. package/dist/light/CfgDirectionalLight.d.ts +8 -8
  66. package/dist/light/CfgDirectionalLight.js +18 -18
  67. package/dist/light/CfgHemisphericLight.d.ts +7 -7
  68. package/dist/light/CfgHemisphericLight.js +17 -17
  69. package/dist/light/CfgPointLight.d.ts +8 -8
  70. package/dist/light/CfgPointLight.js +18 -18
  71. package/dist/light/DefaultLightRig.d.ts +19 -19
  72. package/dist/light/DefaultLightRig.js +77 -77
  73. package/dist/light/LightRigCreator.d.ts +9 -9
  74. package/dist/light/LightRigCreator.js +3 -3
  75. package/dist/material/CfgMaterial.d.ts +68 -68
  76. package/dist/material/CfgMaterial.js +482 -482
  77. package/dist/material/DummyMaterialCreator.d.ts +4 -4
  78. package/dist/material/DummyMaterialCreator.js +15 -15
  79. package/dist/material/material.d.ts +18 -18
  80. package/dist/material/material.js +128 -128
  81. package/dist/material/texture.d.ts +14 -14
  82. package/dist/material/texture.js +306 -306
  83. package/dist/nodes/CfgContentRootNode.d.ts +19 -19
  84. package/dist/nodes/CfgContentRootNode.js +75 -75
  85. package/dist/nodes/CfgDeferredMeshNode.d.ts +55 -55
  86. package/dist/nodes/CfgDeferredMeshNode.js +377 -377
  87. package/dist/nodes/CfgProductNode.d.ts +126 -126
  88. package/dist/nodes/CfgProductNode.js +578 -578
  89. package/dist/nodes/CfgSymNode.d.ts +50 -50
  90. package/dist/nodes/CfgSymNode.js +249 -249
  91. package/dist/nodes/CfgSymRootNode.d.ts +45 -45
  92. package/dist/nodes/CfgSymRootNode.js +220 -220
  93. package/dist/nodes/CfgTransformNode.d.ts +33 -33
  94. package/dist/nodes/CfgTransformNode.js +83 -83
  95. package/dist/scene/SceneCreator.d.ts +6 -6
  96. package/dist/scene/SceneCreator.js +22 -22
  97. package/dist/utilities/CfgBoundingBox.d.ts +21 -21
  98. package/dist/utilities/CfgBoundingBox.js +81 -81
  99. package/dist/utilities/anchor/anchor.d.ts +51 -51
  100. package/dist/utilities/anchor/anchor.js +136 -136
  101. package/dist/utilities/anchor/anchorMap.d.ts +20 -20
  102. package/dist/utilities/anchor/anchorMap.js +111 -111
  103. package/dist/utilities/utilities3D.d.ts +70 -70
  104. package/dist/utilities/utilities3D.js +265 -265
  105. package/dist/utilities/utilitiesColor.d.ts +18 -18
  106. package/dist/utilities/utilitiesColor.js +48 -48
  107. package/dist/utilities/utilitiesImage.d.ts +6 -6
  108. package/dist/utilities/utilitiesImage.js +107 -107
  109. package/dist/utilities/utilitiesSymRootIdentifier.d.ts +7 -7
  110. package/dist/utilities/utilitiesSymRootIdentifier.js +26 -26
  111. package/dist/view/BaseView.d.ts +78 -78
  112. package/dist/view/BaseView.js +297 -297
  113. package/dist/view/BaseViewConfiguration.d.ts +32 -32
  114. package/dist/view/BaseViewConfiguration.js +8 -8
  115. package/dist/view/RenderEnv.d.ts +43 -43
  116. package/dist/view/RenderEnv.js +7 -7
  117. package/dist/view/SingleProductDefaultCameraView.d.ts +33 -33
  118. package/dist/view/SingleProductDefaultCameraView.js +141 -141
  119. package/dist/view/SingleProductDefaultCameraViewConfiguration.d.ts +46 -46
  120. package/dist/view/SingleProductDefaultCameraViewConfiguration.js +11 -11
  121. package/dist/view/SingleProductView.d.ts +42 -42
  122. package/dist/view/SingleProductView.js +206 -206
  123. package/dist/view/SingleProductViewConfiguration.d.ts +32 -32
  124. package/dist/view/SingleProductViewConfiguration.js +19 -19
  125. package/package.json +5 -5
@@ -1,136 +1,136 @@
1
- import { Matrix, Vector3 } from "@babylonjs/core";
2
- import { toStretchedPoint } from "../../geometry/stretch/CfgStretchData.js";
3
- import { identifierIsUri } from "../utilitiesSymRootIdentifier.js";
4
- /*
5
- * MeasurePriorityNodeReferences only uses the url of a Model as identifier. Therefore it
6
- * can not differentiate between the same Model/CfgSymRootNode used multiple time in the same
7
- * Product. Future development in Catalogues might make this change.
8
- */
9
- export function nodeEqualsMeasurePriorityNodeReference(node, ref) {
10
- const nodeIdentifier = node._identifier;
11
- // The identifier is made from URL when the node was made from an URL
12
- if (!identifierIsUri(nodeIdentifier)) {
13
- return false;
14
- }
15
- // The last segment of the URL is the Windows-style formatted relative file path to the model
16
- const pathFromIdentifier = decodeURIComponent(nodeIdentifier.substr(nodeIdentifier.lastIndexOf("/") + 1));
17
- return pathFromIdentifier === ref.modelLocalFilePath;
18
- }
19
- /**
20
- * The measureParamCode points to Measures inside Models. A Model can be used multiple times in a Product.
21
- * More than one Model can use the same measureParamCode. Therefore what Measure an AnchorRef points to
22
- * can be ambiguous. To help resolve the ambiguities, an anchorRef can have measurePriorities that
23
- * governs which target it prefers to be anchored to.
24
- *
25
- * This method sorts the targets so that the highest priority (lowest index) one is first.
26
- * Sorting is done in place on the original array.
27
- */
28
- export const getAnchorTargetPriorityComparer = (measureDefinitions) => (measureParamCode, l, r) => {
29
- const measureDefinition = measureDefinitions.find((m) => m.measureParamCode === measureParamCode);
30
- if (measureDefinition === undefined) {
31
- return 0;
32
- }
33
- const measurePriorities = measureDefinition.measurePriorities;
34
- const lP = measurePriorities.find((m) => nodeEqualsMeasurePriorityNodeReference(l, m));
35
- const rP = measurePriorities.find((m) => nodeEqualsMeasurePriorityNodeReference(r, m));
36
- const lIndex = lP === undefined ? Number.POSITIVE_INFINITY : lP.index;
37
- const rIndex = rP === undefined ? Number.POSITIVE_INFINITY : rP.index;
38
- const prioDiff = lIndex - rIndex;
39
- if (prioDiff !== 0) {
40
- return prioDiff;
41
- }
42
- return l._identifier.localeCompare(r._identifier);
43
- };
44
- /**
45
- * It might be possible in the future to anchor to other things than Measures (which are primarily)
46
- * used for stretch, but for now we can only support anchoring to the ends of a Measure.
47
- * toSp means anchor to start point, else end point.
48
- * The MeasureParam class is used in several different contexts. To make the intent inside Stage
49
- * clear CfgAnchorRef exists, which including only what is relevant for when used for anchoring.
50
- */
51
- export class CfgAnchorRef {
52
- constructor(measureParamCode, toSp) {
53
- this.measureParamCode = measureParamCode;
54
- this.toSp = toSp;
55
- }
56
- static make(m) {
57
- if (m === undefined) {
58
- return undefined;
59
- }
60
- const { anchorPoint, code } = m;
61
- if (anchorPoint === undefined) {
62
- console.error("No anchorPoint for measureParam intended to be used as anchorRef");
63
- return undefined;
64
- }
65
- const isSp = anchorPoint === "sp";
66
- const isEp = anchorPoint === "ep";
67
- if (!isSp && !isEp) {
68
- console.error("AnchorPoint is neither sp nor ep");
69
- return undefined;
70
- }
71
- return new CfgAnchorRef(code, isSp);
72
- }
73
- equal(other) {
74
- return this.measureParamCode === other.measureParamCode && this.toSp === other.toSp;
75
- }
76
- }
77
- /** Gets the coordinates of the anchor point relative the anchor target. */
78
- export function getRawAnchorPoint(anchorTarget, anchorRef) {
79
- if (anchorTarget === undefined) {
80
- return undefined;
81
- }
82
- if (anchorRef === undefined) {
83
- throw new Error("AnchorTo not set even though we got an anchorTarget");
84
- }
85
- const { measureParamCode, toSp } = anchorRef;
86
- const { stretchDatas } = anchorTarget;
87
- const targetStretchData = stretchDatas.find((stretchData) => measureParamCode === stretchData.measureParam);
88
- if (targetStretchData === undefined) {
89
- throw new Error("No target stretch data for measureParamCode found");
90
- }
91
- return toSp ? targetStretchData.sp : targetStretchData.ep;
92
- }
93
- /**
94
- * Calculate a matrix which is the translation that makes a point move as if it was a child of
95
- * anchorTarget and then moved to the end of the anchorPoint.
96
- *
97
- * It is assumed that all anchoring happens on symRoot/additionalProduct-level and therefore all anchorees are
98
- * siblings to the anchorers.
99
- *
100
- * Application of anchoring happens from anchor tree root and out, so that originalMatrix of
101
- * anchorTarget will already have any anchoring and stretch applied.
102
- *
103
- * @param ignoreTargetTransformation If true, ignore anchorTarget's originalMatrix. This is a
104
- * workaround for that CET (as of this writing) somewhat unexpectedly mostly does not apply the
105
- * transformation when anchoring Additional Products. We have noticed some cases when it actually
106
- * apply the transform as you would expect. When the bug is solved this should be removed.
107
- */
108
- export function getStretchedAnchorPointMatrix(anchorRef, anchorTarget, ignoreTargetTransformation) {
109
- const rawAnchorPoint = getRawAnchorPoint(anchorTarget, anchorRef);
110
- if (rawAnchorPoint === undefined || anchorTarget === undefined) {
111
- return undefined;
112
- }
113
- // Apply current stretch to the anchor point
114
- const stretchedAnchorPoint = toStretchedPoint(rawAnchorPoint, anchorTarget.stretchDatas, anchorTarget.cfgProductNode.product.configuration._internal
115
- .stretchReferenceLengthsByMeasureParamCode);
116
- // Sometimes, apply the anchorTarget matrix, as if the point was a child to the anchorTarget.
117
- const anchorTargetMatrixApplied = ignoreTargetTransformation
118
- ? stretchedAnchorPoint
119
- : Vector3.TransformCoordinates(stretchedAnchorPoint, anchorTarget.originalMatrix);
120
- // We use translation as when we anchor things we do not change their orientation,
121
- // we only move them to snap to this point
122
- return Matrix.Identity().setTranslation(anchorTargetMatrixApplied);
123
- }
124
- export function updatedStretchedAnchorPointMatrix(anchorRef, anchorTarget, currentStretchedAnchorPointMatrix, ignoreTargetTransformation) {
125
- const stretchedAnchorPointMatrix = getStretchedAnchorPointMatrix(anchorRef, anchorTarget, ignoreTargetTransformation);
126
- if (currentStretchedAnchorPointMatrix === undefined &&
127
- stretchedAnchorPointMatrix === undefined) {
128
- return undefined;
129
- }
130
- if (currentStretchedAnchorPointMatrix !== undefined &&
131
- stretchedAnchorPointMatrix !== undefined &&
132
- stretchedAnchorPointMatrix.equals(currentStretchedAnchorPointMatrix)) {
133
- return undefined;
134
- }
135
- return stretchedAnchorPointMatrix;
136
- }
1
+ import { Matrix, Vector3 } from "@babylonjs/core";
2
+ import { toStretchedPoint } from "../../geometry/stretch/CfgStretchData.js";
3
+ import { identifierIsUri } from "../utilitiesSymRootIdentifier.js";
4
+ /*
5
+ * MeasurePriorityNodeReferences only uses the url of a Model as identifier. Therefore it
6
+ * can not differentiate between the same Model/CfgSymRootNode used multiple time in the same
7
+ * Product. Future development in Catalogues might make this change.
8
+ */
9
+ export function nodeEqualsMeasurePriorityNodeReference(node, ref) {
10
+ const nodeIdentifier = node._identifier;
11
+ // The identifier is made from URL when the node was made from an URL
12
+ if (!identifierIsUri(nodeIdentifier)) {
13
+ return false;
14
+ }
15
+ // The last segment of the URL is the Windows-style formatted relative file path to the model
16
+ const pathFromIdentifier = decodeURIComponent(nodeIdentifier.substr(nodeIdentifier.lastIndexOf("/") + 1));
17
+ return pathFromIdentifier === ref.modelLocalFilePath;
18
+ }
19
+ /**
20
+ * The measureParamCode points to Measures inside Models. A Model can be used multiple times in a Product.
21
+ * More than one Model can use the same measureParamCode. Therefore what Measure an AnchorRef points to
22
+ * can be ambiguous. To help resolve the ambiguities, an anchorRef can have measurePriorities that
23
+ * governs which target it prefers to be anchored to.
24
+ *
25
+ * This method sorts the targets so that the highest priority (lowest index) one is first.
26
+ * Sorting is done in place on the original array.
27
+ */
28
+ export const getAnchorTargetPriorityComparer = (measureDefinitions) => (measureParamCode, l, r) => {
29
+ const measureDefinition = measureDefinitions.find((m) => m.measureParamCode === measureParamCode);
30
+ if (measureDefinition === undefined) {
31
+ return 0;
32
+ }
33
+ const measurePriorities = measureDefinition.measurePriorities;
34
+ const lP = measurePriorities.find((m) => nodeEqualsMeasurePriorityNodeReference(l, m));
35
+ const rP = measurePriorities.find((m) => nodeEqualsMeasurePriorityNodeReference(r, m));
36
+ const lIndex = lP === undefined ? Number.POSITIVE_INFINITY : lP.index;
37
+ const rIndex = rP === undefined ? Number.POSITIVE_INFINITY : rP.index;
38
+ const prioDiff = lIndex - rIndex;
39
+ if (prioDiff !== 0) {
40
+ return prioDiff;
41
+ }
42
+ return l._identifier.localeCompare(r._identifier);
43
+ };
44
+ /**
45
+ * It might be possible in the future to anchor to other things than Measures (which are primarily)
46
+ * used for stretch, but for now we can only support anchoring to the ends of a Measure.
47
+ * toSp means anchor to start point, else end point.
48
+ * The MeasureParam class is used in several different contexts. To make the intent inside Stage
49
+ * clear CfgAnchorRef exists, which including only what is relevant for when used for anchoring.
50
+ */
51
+ export class CfgAnchorRef {
52
+ constructor(measureParamCode, toSp) {
53
+ this.measureParamCode = measureParamCode;
54
+ this.toSp = toSp;
55
+ }
56
+ static make(m) {
57
+ if (m === undefined) {
58
+ return undefined;
59
+ }
60
+ const { anchorPoint, code } = m;
61
+ if (anchorPoint === undefined) {
62
+ console.error("No anchorPoint for measureParam intended to be used as anchorRef");
63
+ return undefined;
64
+ }
65
+ const isSp = anchorPoint === "sp";
66
+ const isEp = anchorPoint === "ep";
67
+ if (!isSp && !isEp) {
68
+ console.error("AnchorPoint is neither sp nor ep");
69
+ return undefined;
70
+ }
71
+ return new CfgAnchorRef(code, isSp);
72
+ }
73
+ equal(other) {
74
+ return this.measureParamCode === other.measureParamCode && this.toSp === other.toSp;
75
+ }
76
+ }
77
+ /** Gets the coordinates of the anchor point relative the anchor target. */
78
+ export function getRawAnchorPoint(anchorTarget, anchorRef) {
79
+ if (anchorTarget === undefined) {
80
+ return undefined;
81
+ }
82
+ if (anchorRef === undefined) {
83
+ throw new Error("AnchorTo not set even though we got an anchorTarget");
84
+ }
85
+ const { measureParamCode, toSp } = anchorRef;
86
+ const { stretchDatas } = anchorTarget;
87
+ const targetStretchData = stretchDatas.find((stretchData) => measureParamCode === stretchData.measureParam);
88
+ if (targetStretchData === undefined) {
89
+ throw new Error("No target stretch data for measureParamCode found");
90
+ }
91
+ return toSp ? targetStretchData.sp : targetStretchData.ep;
92
+ }
93
+ /**
94
+ * Calculate a matrix which is the translation that makes a point move as if it was a child of
95
+ * anchorTarget and then moved to the end of the anchorPoint.
96
+ *
97
+ * It is assumed that all anchoring happens on symRoot/additionalProduct-level and therefore all anchorees are
98
+ * siblings to the anchorers.
99
+ *
100
+ * Application of anchoring happens from anchor tree root and out, so that originalMatrix of
101
+ * anchorTarget will already have any anchoring and stretch applied.
102
+ *
103
+ * @param ignoreTargetTransformation If true, ignore anchorTarget's originalMatrix. This is a
104
+ * workaround for that CET (as of this writing) somewhat unexpectedly mostly does not apply the
105
+ * transformation when anchoring Additional Products. We have noticed some cases when it actually
106
+ * apply the transform as you would expect. When the bug is solved this should be removed.
107
+ */
108
+ export function getStretchedAnchorPointMatrix(anchorRef, anchorTarget, ignoreTargetTransformation) {
109
+ const rawAnchorPoint = getRawAnchorPoint(anchorTarget, anchorRef);
110
+ if (rawAnchorPoint === undefined || anchorTarget === undefined) {
111
+ return undefined;
112
+ }
113
+ // Apply current stretch to the anchor point
114
+ const stretchedAnchorPoint = toStretchedPoint(rawAnchorPoint, anchorTarget.stretchDatas, anchorTarget.cfgProductNode.product.configuration._internal
115
+ .stretchReferenceLengthsByMeasureParamCode);
116
+ // Sometimes, apply the anchorTarget matrix, as if the point was a child to the anchorTarget.
117
+ const anchorTargetMatrixApplied = ignoreTargetTransformation
118
+ ? stretchedAnchorPoint
119
+ : Vector3.TransformCoordinates(stretchedAnchorPoint, anchorTarget.originalMatrix);
120
+ // We use translation as when we anchor things we do not change their orientation,
121
+ // we only move them to snap to this point
122
+ return Matrix.Identity().setTranslation(anchorTargetMatrixApplied);
123
+ }
124
+ export function updatedStretchedAnchorPointMatrix(anchorRef, anchorTarget, currentStretchedAnchorPointMatrix, ignoreTargetTransformation) {
125
+ const stretchedAnchorPointMatrix = getStretchedAnchorPointMatrix(anchorRef, anchorTarget, ignoreTargetTransformation);
126
+ if (currentStretchedAnchorPointMatrix === undefined &&
127
+ stretchedAnchorPointMatrix === undefined) {
128
+ return undefined;
129
+ }
130
+ if (currentStretchedAnchorPointMatrix !== undefined &&
131
+ stretchedAnchorPointMatrix !== undefined &&
132
+ stretchedAnchorPointMatrix.equals(currentStretchedAnchorPointMatrix)) {
133
+ return undefined;
134
+ }
135
+ return stretchedAnchorPointMatrix;
136
+ }
@@ -1,21 +1,21 @@
1
- /**
2
- * Returns a map from child to parent guaranteed to be loop free.
3
- * The anchor children (keys in the map) will all have a "anchorRef" and there is what
4
- * measureParam they are linked on is found.
5
- * Sorted so that parents are always before their children
6
- * This function is a bit of a "best effort". These things are not well defined in CET - you
7
- * can anchor A on B and B on A at the same time for example. You can also anchor B to A
8
- * while there exists multiple A:s. The code below is a naive implementation as in it will
9
- * not make the solution which allows the most things to be linked. But that is fine as you
10
- * should never create a catalogue with strange anchoring anyhow.
11
- */
12
- export declare function makeAnchoredToAnchorMap<A extends {
13
- anchorRef: {
14
- measureParamCode: string;
15
- } | undefined;
16
- }, T extends {
17
- stretchDatas: {
18
- measureParam: string;
19
- }[];
20
- }>(nodes: (A | T)[], targetCandidateComparer: (measureParamCode: string, l: T, r: T) => number): Map<A, T>;
1
+ /**
2
+ * Returns a map from child to parent guaranteed to be loop free.
3
+ * The anchor children (keys in the map) will all have a "anchorRef" and there is what
4
+ * measureParam they are linked on is found.
5
+ * Sorted so that parents are always before their children
6
+ * This function is a bit of a "best effort". These things are not well defined in CET - you
7
+ * can anchor A on B and B on A at the same time for example. You can also anchor B to A
8
+ * while there exists multiple A:s. The code below is a naive implementation as in it will
9
+ * not make the solution which allows the most things to be linked. But that is fine as you
10
+ * should never create a catalogue with strange anchoring anyhow.
11
+ */
12
+ export declare function makeAnchoredToAnchorMap<A extends {
13
+ anchorRef: {
14
+ measureParamCode: string;
15
+ } | undefined;
16
+ }, T extends {
17
+ stretchDatas: {
18
+ measureParam: string;
19
+ }[];
20
+ }>(nodes: (A | T)[], targetCandidateComparer: (measureParamCode: string, l: T, r: T) => number): Map<A, T>;
21
21
  //# sourceMappingURL=anchorMap.d.ts.map
@@ -1,111 +1,111 @@
1
- // Tests do not work if we have Babylon-imports in the same file, so this has to be a separate file
2
- /**
3
- * Returns a map from child to parent guaranteed to be loop free.
4
- * The anchor children (keys in the map) will all have a "anchorRef" and there is what
5
- * measureParam they are linked on is found.
6
- * Sorted so that parents are always before their children
7
- * This function is a bit of a "best effort". These things are not well defined in CET - you
8
- * can anchor A on B and B on A at the same time for example. You can also anchor B to A
9
- * while there exists multiple A:s. The code below is a naive implementation as in it will
10
- * not make the solution which allows the most things to be linked. But that is fine as you
11
- * should never create a catalogue with strange anchoring anyhow.
12
- */
13
- export function makeAnchoredToAnchorMap(nodes, targetCandidateComparer) {
14
- function isAnchoree(n) {
15
- return "anchorRef" in n;
16
- }
17
- function isTarget(n) {
18
- return "stretchDatas" in n;
19
- }
20
- const anchoredToAnchorMap = new Map();
21
- // Step 1: build a legal tree
22
- for (const node of nodes) {
23
- if (!isAnchoree(node)) {
24
- continue;
25
- }
26
- const anchorRef = node.anchorRef;
27
- if (anchorRef === undefined) {
28
- continue;
29
- }
30
- const measureParam = anchorRef.measureParamCode;
31
- const targetCandidates = nodes
32
- .filter((n) => {
33
- // Ignore self
34
- if (node === n) {
35
- return false;
36
- }
37
- if (!isTarget(n)) {
38
- return false;
39
- }
40
- // Can we anchor to this node?
41
- return n.stretchDatas.some((stretchData) => measureParam === stretchData.measureParam);
42
- })
43
- .map((t, i) => ({ t, i }))
44
- .sort((l, r) => {
45
- // As sort is not stable in JS-versions older than EcmaScript 2019 we add the
46
- // array original index to have as a fallback when there is a draw
47
- const comp = targetCandidateComparer(anchorRef.measureParamCode, l.t, r.t);
48
- if (comp === 0) {
49
- return l.i - r.i;
50
- }
51
- return comp;
52
- })
53
- .map((tt) => tt.t);
54
- let okay = true;
55
- for (const otherNode of targetCandidates) {
56
- okay = true;
57
- // Loop control, the candidate can not be a child, then we would get a loop
58
- let loopCandidate = otherNode;
59
- while (loopCandidate !== undefined) {
60
- if (!isAnchoree(loopCandidate)) {
61
- break;
62
- }
63
- loopCandidate = anchoredToAnchorMap.get(loopCandidate);
64
- if (loopCandidate === node) {
65
- okay = false;
66
- break;
67
- }
68
- }
69
- if (okay) {
70
- anchoredToAnchorMap.set(node, otherNode);
71
- break;
72
- }
73
- }
74
- if (!okay) {
75
- console.warn("No SymRootNode to anchor to found.");
76
- }
77
- }
78
- // From anchored to anchor
79
- const unplaced = Array.from(anchoredToAnchorMap);
80
- // Step 2: Build a sorted map so that parents are before their children
81
- const result = [];
82
- while (true) {
83
- const candidate = unplaced.pop();
84
- if (candidate === undefined) {
85
- //done
86
- break;
87
- }
88
- const parent = candidate[1];
89
- const indexInResult = result.findIndex((otherAnchoredToAnchor) => parent === otherAnchoredToAnchor[0]);
90
- if (indexInResult === -1) {
91
- // Candidates parent is not in the result, see if it in those waiting
92
- const indexInUnplaced = unplaced.findIndex((item) => item[0] === parent);
93
- if (indexInUnplaced === -1) {
94
- // The parent was not part of the original nodes, so we just add this node.
95
- result.push(candidate);
96
- }
97
- else {
98
- const toMoveUp = unplaced.splice(indexInUnplaced, 1)[0];
99
- // Put back to candidate
100
- unplaced.push(candidate);
101
- // Move up the parent
102
- unplaced.push(toMoveUp);
103
- }
104
- }
105
- else {
106
- // Parent is in result
107
- result.splice(indexInResult + 1, 0, candidate);
108
- }
109
- }
110
- return new Map(result);
111
- }
1
+ // Tests do not work if we have Babylon-imports in the same file, so this has to be a separate file
2
+ /**
3
+ * Returns a map from child to parent guaranteed to be loop free.
4
+ * The anchor children (keys in the map) will all have a "anchorRef" and there is what
5
+ * measureParam they are linked on is found.
6
+ * Sorted so that parents are always before their children
7
+ * This function is a bit of a "best effort". These things are not well defined in CET - you
8
+ * can anchor A on B and B on A at the same time for example. You can also anchor B to A
9
+ * while there exists multiple A:s. The code below is a naive implementation as in it will
10
+ * not make the solution which allows the most things to be linked. But that is fine as you
11
+ * should never create a catalogue with strange anchoring anyhow.
12
+ */
13
+ export function makeAnchoredToAnchorMap(nodes, targetCandidateComparer) {
14
+ function isAnchoree(n) {
15
+ return "anchorRef" in n;
16
+ }
17
+ function isTarget(n) {
18
+ return "stretchDatas" in n;
19
+ }
20
+ const anchoredToAnchorMap = new Map();
21
+ // Step 1: build a legal tree
22
+ for (const node of nodes) {
23
+ if (!isAnchoree(node)) {
24
+ continue;
25
+ }
26
+ const anchorRef = node.anchorRef;
27
+ if (anchorRef === undefined) {
28
+ continue;
29
+ }
30
+ const measureParam = anchorRef.measureParamCode;
31
+ const targetCandidates = nodes
32
+ .filter((n) => {
33
+ // Ignore self
34
+ if (node === n) {
35
+ return false;
36
+ }
37
+ if (!isTarget(n)) {
38
+ return false;
39
+ }
40
+ // Can we anchor to this node?
41
+ return n.stretchDatas.some((stretchData) => measureParam === stretchData.measureParam);
42
+ })
43
+ .map((t, i) => ({ t, i }))
44
+ .sort((l, r) => {
45
+ // As sort is not stable in JS-versions older than EcmaScript 2019 we add the
46
+ // array original index to have as a fallback when there is a draw
47
+ const comp = targetCandidateComparer(anchorRef.measureParamCode, l.t, r.t);
48
+ if (comp === 0) {
49
+ return l.i - r.i;
50
+ }
51
+ return comp;
52
+ })
53
+ .map((tt) => tt.t);
54
+ let okay = true;
55
+ for (const otherNode of targetCandidates) {
56
+ okay = true;
57
+ // Loop control, the candidate can not be a child, then we would get a loop
58
+ let loopCandidate = otherNode;
59
+ while (loopCandidate !== undefined) {
60
+ if (!isAnchoree(loopCandidate)) {
61
+ break;
62
+ }
63
+ loopCandidate = anchoredToAnchorMap.get(loopCandidate);
64
+ if (loopCandidate === node) {
65
+ okay = false;
66
+ break;
67
+ }
68
+ }
69
+ if (okay) {
70
+ anchoredToAnchorMap.set(node, otherNode);
71
+ break;
72
+ }
73
+ }
74
+ if (!okay) {
75
+ console.warn("No SymRootNode to anchor to found.");
76
+ }
77
+ }
78
+ // From anchored to anchor
79
+ const unplaced = Array.from(anchoredToAnchorMap);
80
+ // Step 2: Build a sorted map so that parents are before their children
81
+ const result = [];
82
+ while (true) {
83
+ const candidate = unplaced.pop();
84
+ if (candidate === undefined) {
85
+ //done
86
+ break;
87
+ }
88
+ const parent = candidate[1];
89
+ const indexInResult = result.findIndex((otherAnchoredToAnchor) => parent === otherAnchoredToAnchor[0]);
90
+ if (indexInResult === -1) {
91
+ // Candidates parent is not in the result, see if it in those waiting
92
+ const indexInUnplaced = unplaced.findIndex((item) => item[0] === parent);
93
+ if (indexInUnplaced === -1) {
94
+ // The parent was not part of the original nodes, so we just add this node.
95
+ result.push(candidate);
96
+ }
97
+ else {
98
+ const toMoveUp = unplaced.splice(indexInUnplaced, 1)[0];
99
+ // Put back to candidate
100
+ unplaced.push(candidate);
101
+ // Move up the parent
102
+ unplaced.push(toMoveUp);
103
+ }
104
+ }
105
+ else {
106
+ // Parent is in result
107
+ result.splice(indexInResult + 1, 0, candidate);
108
+ }
109
+ }
110
+ return new Map(result);
111
+ }