react-cheminfo 0.16.0 → 0.18.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 (170) hide show
  1. package/lib/parallel/core/index.d.ts +7 -5
  2. package/lib/parallel/core/index.d.ts.map +1 -1
  3. package/lib/parallel/core/index.js +5 -3
  4. package/lib/parallel/core/index.js.map +1 -1
  5. package/lib/parallel/core/parallelBrush.d.ts +22 -1
  6. package/lib/parallel/core/parallelBrush.d.ts.map +1 -1
  7. package/lib/parallel/core/parallelBrush.js +53 -3
  8. package/lib/parallel/core/parallelBrush.js.map +1 -1
  9. package/lib/parallel/core/parallelFilter.d.ts +14 -1
  10. package/lib/parallel/core/parallelFilter.d.ts.map +1 -1
  11. package/lib/parallel/core/parallelFilter.js +44 -11
  12. package/lib/parallel/core/parallelFilter.js.map +1 -1
  13. package/lib/parallel/core/parallelOrder.d.ts +36 -0
  14. package/lib/parallel/core/parallelOrder.d.ts.map +1 -0
  15. package/lib/parallel/core/parallelOrder.js +65 -0
  16. package/lib/parallel/core/parallelOrder.js.map +1 -0
  17. package/lib/parallel/core/parallelPaint.d.ts +4 -0
  18. package/lib/parallel/core/parallelPaint.d.ts.map +1 -1
  19. package/lib/parallel/core/parallelPaint.js +15 -6
  20. package/lib/parallel/core/parallelPaint.js.map +1 -1
  21. package/lib/parallel/core/parallelPalette.d.ts +10 -1
  22. package/lib/parallel/core/parallelPalette.d.ts.map +1 -1
  23. package/lib/parallel/core/parallelPalette.js +14 -1
  24. package/lib/parallel/core/parallelPalette.js.map +1 -1
  25. package/lib/parallel/core/parallelSelection.d.ts +43 -0
  26. package/lib/parallel/core/parallelSelection.d.ts.map +1 -0
  27. package/lib/parallel/core/parallelSelection.js +87 -0
  28. package/lib/parallel/core/parallelSelection.js.map +1 -0
  29. package/lib/parallel/core/parallelTicks.d.ts.map +1 -1
  30. package/lib/parallel/core/parallelTicks.js +7 -4
  31. package/lib/parallel/core/parallelTicks.js.map +1 -1
  32. package/lib/parallel/core/parallelTypes.d.ts +12 -1
  33. package/lib/parallel/core/parallelTypes.d.ts.map +1 -1
  34. package/lib/parallel/core/parallelTypes.js.map +1 -1
  35. package/lib/parallel/ui/ParallelAxesLayer.d.ts +2 -2
  36. package/lib/parallel/ui/ParallelAxesLayer.d.ts.map +1 -1
  37. package/lib/parallel/ui/ParallelAxesLayer.js +2 -2
  38. package/lib/parallel/ui/ParallelAxesLayer.js.map +1 -1
  39. package/lib/parallel/ui/ParallelCoordinates.d.ts.map +1 -1
  40. package/lib/parallel/ui/ParallelCoordinates.js +10 -5
  41. package/lib/parallel/ui/ParallelCoordinates.js.map +1 -1
  42. package/lib/parallel/ui/ParallelLabels.d.ts +6 -0
  43. package/lib/parallel/ui/ParallelLabels.d.ts.map +1 -1
  44. package/lib/parallel/ui/ParallelLabels.js +14 -2
  45. package/lib/parallel/ui/ParallelLabels.js.map +1 -1
  46. package/lib/parallel/ui/index.d.ts +4 -0
  47. package/lib/parallel/ui/index.d.ts.map +1 -1
  48. package/lib/parallel/ui/index.js +2 -0
  49. package/lib/parallel/ui/index.js.map +1 -1
  50. package/lib/parallel/ui/parallelCoordinatesProps.d.ts +26 -8
  51. package/lib/parallel/ui/parallelCoordinatesProps.d.ts.map +1 -1
  52. package/lib/parallel/ui/parallelGestureModel.d.ts +37 -6
  53. package/lib/parallel/ui/parallelGestureModel.d.ts.map +1 -1
  54. package/lib/parallel/ui/parallelGestureModel.js +42 -12
  55. package/lib/parallel/ui/parallelGestureModel.js.map +1 -1
  56. package/lib/parallel/ui/parallelPlotModel.d.ts +1 -1
  57. package/lib/parallel/ui/parallelPlotModel.d.ts.map +1 -1
  58. package/lib/parallel/ui/parallelPlotModel.js +3 -3
  59. package/lib/parallel/ui/parallelPlotModel.js.map +1 -1
  60. package/lib/parallel/ui/parallelStyles.d.ts +26 -3
  61. package/lib/parallel/ui/parallelStyles.d.ts.map +1 -1
  62. package/lib/parallel/ui/parallelStyles.js +26 -4
  63. package/lib/parallel/ui/parallelStyles.js.map +1 -1
  64. package/lib/parallel/ui/useParallelAxisDrag.d.ts +60 -0
  65. package/lib/parallel/ui/useParallelAxisDrag.d.ts.map +1 -0
  66. package/lib/parallel/ui/useParallelAxisDrag.js +96 -0
  67. package/lib/parallel/ui/useParallelAxisDrag.js.map +1 -0
  68. package/lib/parallel/ui/useParallelGesture.d.ts +10 -5
  69. package/lib/parallel/ui/useParallelGesture.d.ts.map +1 -1
  70. package/lib/parallel/ui/useParallelGesture.js +46 -21
  71. package/lib/parallel/ui/useParallelGesture.js.map +1 -1
  72. package/lib/structure/core/editorGuide.d.ts +69 -0
  73. package/lib/structure/core/editorGuide.d.ts.map +1 -0
  74. package/lib/structure/core/editorGuide.js +162 -0
  75. package/lib/structure/core/editorGuide.js.map +1 -0
  76. package/lib/structure/core/editorToolbar.d.ts +45 -0
  77. package/lib/structure/core/editorToolbar.d.ts.map +1 -0
  78. package/lib/structure/core/editorToolbar.js +132 -0
  79. package/lib/structure/core/editorToolbar.js.map +1 -0
  80. package/lib/structure/core/editorToolbarGeometry.d.ts +36 -0
  81. package/lib/structure/core/editorToolbarGeometry.d.ts.map +1 -0
  82. package/lib/structure/core/editorToolbarGeometry.js +61 -0
  83. package/lib/structure/core/editorToolbarGeometry.js.map +1 -0
  84. package/lib/structure/core/index.d.ts +6 -0
  85. package/lib/structure/core/index.d.ts.map +1 -1
  86. package/lib/structure/core/index.js +3 -0
  87. package/lib/structure/core/index.js.map +1 -1
  88. package/lib/structure/core/pendingCall.d.ts +21 -0
  89. package/lib/structure/core/pendingCall.d.ts.map +1 -0
  90. package/lib/structure/core/pendingCall.js +37 -0
  91. package/lib/structure/core/pendingCall.js.map +1 -0
  92. package/lib/structure/ui/EditorCanvas.d.ts +1 -16
  93. package/lib/structure/ui/EditorCanvas.d.ts.map +1 -1
  94. package/lib/structure/ui/EditorCanvas.js +5 -18
  95. package/lib/structure/ui/EditorCanvas.js.map +1 -1
  96. package/lib/structure/ui/EditorHelpButton.d.ts +22 -0
  97. package/lib/structure/ui/EditorHelpButton.d.ts.map +1 -0
  98. package/lib/structure/ui/EditorHelpButton.js +38 -0
  99. package/lib/structure/ui/EditorHelpButton.js.map +1 -0
  100. package/lib/structure/ui/KeyCaps.d.ts +12 -0
  101. package/lib/structure/ui/KeyCaps.d.ts.map +1 -0
  102. package/lib/structure/ui/KeyCaps.js +29 -0
  103. package/lib/structure/ui/KeyCaps.js.map +1 -0
  104. package/lib/structure/ui/StructureEditor.d.ts +9 -2
  105. package/lib/structure/ui/StructureEditor.d.ts.map +1 -1
  106. package/lib/structure/ui/StructureEditor.js +17 -24
  107. package/lib/structure/ui/StructureEditor.js.map +1 -1
  108. package/lib/structure/ui/StructureEditorHelp.d.ts +18 -0
  109. package/lib/structure/ui/StructureEditorHelp.d.ts.map +1 -0
  110. package/lib/structure/ui/StructureEditorHelp.js +68 -0
  111. package/lib/structure/ui/StructureEditorHelp.js.map +1 -0
  112. package/lib/structure/ui/ToolbarTooltip.d.ts +20 -0
  113. package/lib/structure/ui/ToolbarTooltip.d.ts.map +1 -0
  114. package/lib/structure/ui/ToolbarTooltip.js +49 -0
  115. package/lib/structure/ui/ToolbarTooltip.js.map +1 -0
  116. package/lib/structure/ui/editorChange.d.ts +52 -0
  117. package/lib/structure/ui/editorChange.d.ts.map +1 -0
  118. package/lib/structure/ui/editorChange.js +34 -0
  119. package/lib/structure/ui/editorChange.js.map +1 -0
  120. package/lib/structure/ui/index.d.ts +3 -1
  121. package/lib/structure/ui/index.d.ts.map +1 -1
  122. package/lib/structure/ui/index.js +1 -0
  123. package/lib/structure/ui/index.js.map +1 -1
  124. package/lib/structure/ui/useToolbarFloor.d.ts.map +1 -1
  125. package/lib/structure/ui/useToolbarFloor.js +6 -45
  126. package/lib/structure/ui/useToolbarFloor.js.map +1 -1
  127. package/lib/structure/ui/useToolbarHover.d.ts +28 -0
  128. package/lib/structure/ui/useToolbarHover.d.ts.map +1 -0
  129. package/lib/structure/ui/useToolbarHover.js +96 -0
  130. package/lib/structure/ui/useToolbarHover.js.map +1 -0
  131. package/lib/structure/ui/watchToolbar.d.ts +17 -0
  132. package/lib/structure/ui/watchToolbar.d.ts.map +1 -0
  133. package/lib/structure/ui/watchToolbar.js +56 -0
  134. package/lib/structure/ui/watchToolbar.js.map +1 -0
  135. package/package.json +1 -1
  136. package/src/parallel/core/index.ts +16 -0
  137. package/src/parallel/core/parallelBrush.ts +69 -3
  138. package/src/parallel/core/parallelFilter.ts +52 -15
  139. package/src/parallel/core/parallelOrder.ts +73 -0
  140. package/src/parallel/core/parallelPaint.ts +16 -5
  141. package/src/parallel/core/parallelPalette.ts +14 -1
  142. package/src/parallel/core/parallelSelection.ts +99 -0
  143. package/src/parallel/core/parallelTicks.ts +7 -3
  144. package/src/parallel/core/parallelTypes.ts +13 -1
  145. package/src/parallel/ui/ParallelAxesLayer.tsx +10 -4
  146. package/src/parallel/ui/ParallelCoordinates.tsx +22 -3
  147. package/src/parallel/ui/ParallelLabels.tsx +23 -2
  148. package/src/parallel/ui/index.ts +15 -0
  149. package/src/parallel/ui/parallelCoordinatesProps.ts +26 -8
  150. package/src/parallel/ui/parallelGestureModel.ts +63 -13
  151. package/src/parallel/ui/parallelPlotModel.ts +3 -3
  152. package/src/parallel/ui/parallelStyles.ts +46 -4
  153. package/src/parallel/ui/useParallelAxisDrag.ts +147 -0
  154. package/src/parallel/ui/useParallelGesture.ts +61 -28
  155. package/src/structure/core/editorGuide.ts +221 -0
  156. package/src/structure/core/editorToolbar.ts +175 -0
  157. package/src/structure/core/editorToolbarGeometry.ts +80 -0
  158. package/src/structure/core/index.ts +29 -0
  159. package/src/structure/core/pendingCall.ts +59 -0
  160. package/src/structure/ui/EditorCanvas.tsx +9 -35
  161. package/src/structure/ui/EditorHelpButton.tsx +70 -0
  162. package/src/structure/ui/KeyCaps.tsx +40 -0
  163. package/src/structure/ui/StructureEditor.tsx +39 -21
  164. package/src/structure/ui/StructureEditorHelp.tsx +136 -0
  165. package/src/structure/ui/ToolbarTooltip.tsx +95 -0
  166. package/src/structure/ui/editorChange.ts +81 -0
  167. package/src/structure/ui/index.ts +5 -1
  168. package/src/structure/ui/useToolbarFloor.ts +7 -46
  169. package/src/structure/ui/useToolbarHover.ts +134 -0
  170. package/src/structure/ui/watchToolbar.ts +59 -0
@@ -0,0 +1,134 @@
1
+ import type { RefObject } from 'react';
2
+ import { useEffect, useState } from 'react';
3
+
4
+ import type { EditorToolbarButtonBox } from '../core/editorToolbarGeometry.ts';
5
+ import {
6
+ editorToolbarButtonAt,
7
+ editorToolbarButtonBox,
8
+ } from '../core/editorToolbarGeometry.ts';
9
+
10
+ import { watchToolbar } from './watchToolbar.ts';
11
+
12
+ /** The toolbar button the pointer rests on, or last rested on. */
13
+ export interface ToolbarHover {
14
+ /** The button's index in `EDITOR_TOOLBAR_BUTTONS`. */
15
+ button: number;
16
+ /** Where the button is drawn, relative to the container's padding box. */
17
+ box: EditorToolbarButtonBox;
18
+ /**
19
+ * Whether its tooltip is showing. The last button is kept after the pointer
20
+ * leaves, so a closing tooltip fades out with its text rather than empty.
21
+ */
22
+ open: boolean;
23
+ }
24
+
25
+ /**
26
+ * Follow the pointer over the editor's toolbar.
27
+ *
28
+ * The first button waits for the pointer to rest, so crossing the toolbar on
29
+ * the way to the drawing opens nothing; once one is showing, the next follows
30
+ * at once. Pressing a button hides its tooltip until the pointer moves on,
31
+ * since whoever pressed it no longer needs telling. Touch is ignored: a finger
32
+ * has no hover, and a tooltip opened by a tap would cover the canvas.
33
+ * @param containerRef - The element wrapping the editor, positioned so the
34
+ * returned box can be laid over the button.
35
+ * @returns The button under the pointer, or null before any has been hovered.
36
+ */
37
+ export function useToolbarHover(
38
+ containerRef: RefObject<HTMLElement | null>,
39
+ ): ToolbarHover | null {
40
+ const [hover, setHover] = useState<ToolbarHover | null>(null);
41
+
42
+ useEffect(() => {
43
+ const container = containerRef.current;
44
+ if (container === null) return;
45
+
46
+ let timer: ReturnType<typeof setTimeout> | undefined;
47
+ let current = -1;
48
+ let pressed = -1;
49
+ let open = false;
50
+
51
+ const show = (toolbar: HTMLCanvasElement, button: number): void => {
52
+ open = true;
53
+ setHover({ button, box: boxIn(container, toolbar, button), open });
54
+ };
55
+ const hide = (): void => {
56
+ clearTimeout(timer);
57
+ if (!open) return;
58
+ open = false;
59
+ setHover((previous) =>
60
+ previous === null ? null : { ...previous, open: false },
61
+ );
62
+ };
63
+
64
+ const onLeave = (): void => {
65
+ current = -1;
66
+ pressed = -1;
67
+ hide();
68
+ };
69
+ const onDown = (): void => {
70
+ pressed = current;
71
+ hide();
72
+ };
73
+
74
+ const stop = watchToolbar(container, (toolbar) => {
75
+ const onMove = (event: PointerEvent): void => {
76
+ if (event.pointerType === 'touch') return;
77
+ const button = editorToolbarButtonAt(
78
+ event.offsetX,
79
+ event.offsetY,
80
+ toolbar.offsetHeight,
81
+ );
82
+ if (button === current) return;
83
+ current = button;
84
+ if (button !== pressed) pressed = -1;
85
+ if (button === -1 || button === pressed) {
86
+ hide();
87
+ return;
88
+ }
89
+ clearTimeout(timer);
90
+ if (open) {
91
+ show(toolbar, button);
92
+ return;
93
+ }
94
+ timer = setTimeout(() => show(toolbar, button), OPEN_DELAY);
95
+ };
96
+
97
+ toolbar.addEventListener('pointermove', onMove);
98
+ toolbar.addEventListener('pointerleave', onLeave);
99
+ toolbar.addEventListener('pointerdown', onDown);
100
+ return () => {
101
+ toolbar.removeEventListener('pointermove', onMove);
102
+ toolbar.removeEventListener('pointerleave', onLeave);
103
+ toolbar.removeEventListener('pointerdown', onDown);
104
+ onLeave();
105
+ };
106
+ });
107
+
108
+ return () => {
109
+ stop();
110
+ clearTimeout(timer);
111
+ };
112
+ }, [containerRef]);
113
+
114
+ return hover;
115
+ }
116
+
117
+ // Long enough that sweeping the pointer across the toolbar opens nothing.
118
+ const OPEN_DELAY = 250;
119
+
120
+ function boxIn(
121
+ container: HTMLElement,
122
+ toolbar: HTMLCanvasElement,
123
+ button: number,
124
+ ): EditorToolbarButtonBox {
125
+ const box = editorToolbarButtonBox(button, toolbar.offsetHeight);
126
+ const toolbarRect = toolbar.getBoundingClientRect();
127
+ const containerRect = container.getBoundingClientRect();
128
+ return {
129
+ ...box,
130
+ left:
131
+ toolbarRect.left - containerRect.left - container.clientLeft + box.left,
132
+ top: toolbarRect.top - containerRect.top - container.clientTop + box.top,
133
+ };
134
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Run something against the editor's toolbar canvas as soon as it exists, and
3
+ * again against each new one the editor builds.
4
+ *
5
+ * The editor is imported lazily and builds itself asynchronously, so the
6
+ * toolbar is almost never there on the first look, and how long it takes is a
7
+ * cold module graph and a network away from anything this code can predict.
8
+ * So its arrival is watched for rather than waited out: a deadline that
9
+ * expires leaves whatever depends on the toolbar missing for the life of the
10
+ * page, with nothing on screen to say why.
11
+ * @param container - The element wrapping the editor.
12
+ * @param onToolbar - Called with each toolbar found; what it returns is called
13
+ * when that toolbar is replaced or the watch ends.
14
+ * @returns A function ending the watch.
15
+ */
16
+ export function watchToolbar(
17
+ container: HTMLElement,
18
+ onToolbar: (toolbar: HTMLCanvasElement) => () => void,
19
+ ): () => void {
20
+ let toolbar: HTMLCanvasElement | null = null;
21
+ let release: (() => void) | null = null;
22
+
23
+ const attach = (): void => {
24
+ const found = findToolbar(container);
25
+ if (found === null) return;
26
+ release?.();
27
+ toolbar = found;
28
+ release = onToolbar(found);
29
+ };
30
+
31
+ const arrivals = new MutationObserver(() => {
32
+ if (toolbar?.isConnected === true) return;
33
+ attach();
34
+ });
35
+ arrivals.observe(container, { childList: true, subtree: true });
36
+ attach();
37
+
38
+ return () => {
39
+ arrivals.disconnect();
40
+ release?.();
41
+ };
42
+ }
43
+
44
+ /**
45
+ * Find the toolbar canvas of the editor.
46
+ *
47
+ * The editor builds itself inside a shadow root and puts the toolbar there as
48
+ * a direct child, the drawing canvas being nested deeper.
49
+ * @param container - The element wrapping the editor.
50
+ * @returns The toolbar canvas, or null while the editor has not drawn one.
51
+ */
52
+ function findToolbar(container: HTMLElement): HTMLCanvasElement | null {
53
+ for (const element of container.querySelectorAll('*')) {
54
+ for (const child of element.shadowRoot?.children ?? []) {
55
+ if (child instanceof HTMLCanvasElement) return child;
56
+ }
57
+ }
58
+ return null;
59
+ }