@pibbl/core 0.0.2 → 0.0.3-alpha.85.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/THIRD_PARTY_NOTICES.txt +81 -0
  2. package/dist/features/textures/index.d.ts +12 -2
  3. package/dist/features/textures/index.js +33 -1
  4. package/dist/features/textures/index.js.map +2 -2
  5. package/dist/features/textures/lib/chemical-field.d.ts +56 -0
  6. package/dist/features/textures/lib/chemical-field.js +154 -0
  7. package/dist/features/textures/lib/chemical-field.js.map +7 -0
  8. package/dist/features/textures/lib/chemical-recipes.d.ts +119 -0
  9. package/dist/features/textures/lib/chemical-recipes.js +275 -0
  10. package/dist/features/textures/lib/chemical-recipes.js.map +7 -0
  11. package/dist/features/textures/lib/definitions.d.ts +3 -18
  12. package/dist/features/textures/lib/definitions.js +15 -20
  13. package/dist/features/textures/lib/definitions.js.map +2 -2
  14. package/dist/features/textures/lib/geometric-patterns.d.ts +149 -0
  15. package/dist/features/textures/lib/geometric-patterns.js +305 -0
  16. package/dist/features/textures/lib/geometric-patterns.js.map +7 -0
  17. package/dist/features/textures/lib/gray-scott.d.ts +55 -0
  18. package/dist/features/textures/lib/gray-scott.js +39 -0
  19. package/dist/features/textures/lib/gray-scott.js.map +7 -0
  20. package/dist/features/textures/lib/patterns.d.ts +123 -0
  21. package/dist/features/textures/lib/patterns.js +344 -0
  22. package/dist/features/textures/lib/patterns.js.map +7 -0
  23. package/dist/features/textures/lib/reaction-diffusion.d.ts +3 -2
  24. package/dist/features/textures/lib/reaction-diffusion.js +9 -20
  25. package/dist/features/textures/lib/reaction-diffusion.js.map +2 -2
  26. package/dist/features/textures/lib/simulation.d.ts +10 -4
  27. package/dist/features/textures/lib/simulation.js +23 -13
  28. package/dist/features/textures/lib/simulation.js.map +2 -2
  29. package/dist/features/viz/index.d.ts +55 -6
  30. package/dist/features/viz/index.js +107 -2
  31. package/dist/features/viz/index.js.map +2 -2
  32. package/dist/features/viz/inspection/bar.d.ts +79 -0
  33. package/dist/features/viz/inspection/bar.js +49 -0
  34. package/dist/features/viz/inspection/bar.js.map +7 -0
  35. package/dist/features/viz/inspection/candle.d.ts +156 -0
  36. package/dist/features/viz/inspection/candle.js +120 -0
  37. package/dist/features/viz/inspection/candle.js.map +7 -0
  38. package/dist/features/viz/inspection/capture-types.d.ts +65 -0
  39. package/dist/features/viz/inspection/capture.d.ts +16 -0
  40. package/dist/features/viz/inspection/capture.js +49 -0
  41. package/dist/features/viz/inspection/capture.js.map +7 -0
  42. package/dist/features/viz/inspection/handler.d.ts +36 -0
  43. package/dist/features/viz/inspection/handler.js +91 -0
  44. package/dist/features/viz/inspection/handler.js.map +7 -0
  45. package/dist/features/viz/inspection/ohlc-bar.d.ts +132 -0
  46. package/dist/features/viz/inspection/ohlc-bar.js +118 -0
  47. package/dist/features/viz/inspection/ohlc-bar.js.map +7 -0
  48. package/dist/features/viz/inspection/owned-ref.d.ts +16 -0
  49. package/dist/features/viz/inspection/owned-ref.js +99 -0
  50. package/dist/features/viz/inspection/owned-ref.js.map +7 -0
  51. package/dist/features/viz/inspection/painted-point.d.ts +22 -0
  52. package/dist/features/viz/inspection/painted-point.js +29 -0
  53. package/dist/features/viz/inspection/painted-point.js.map +7 -0
  54. package/dist/features/viz/inspection/queries.d.ts +100 -0
  55. package/dist/features/viz/inspection/queries.js +192 -0
  56. package/dist/features/viz/inspection/queries.js.map +7 -0
  57. package/dist/features/viz/inspection/query-types.d.ts +177 -0
  58. package/dist/features/viz/inspection/volume.d.ts +104 -0
  59. package/dist/features/viz/inspection/volume.js +95 -0
  60. package/dist/features/viz/inspection/volume.js.map +7 -0
  61. package/dist/features/viz/inspection.d.ts +19 -0
  62. package/dist/features/viz/inspection.js +54 -0
  63. package/dist/features/viz/inspection.js.map +7 -0
  64. package/dist/features/viz/inspection.mjs +1 -0
  65. package/dist/features/viz/lib/area-series.d.ts +62 -0
  66. package/dist/features/viz/lib/area-series.js +120 -0
  67. package/dist/features/viz/lib/area-series.js.map +7 -0
  68. package/dist/features/viz/lib/axis.js +1 -1
  69. package/dist/features/viz/lib/axis.js.map +2 -2
  70. package/dist/features/viz/lib/bar-series.d.ts +3 -1
  71. package/dist/features/viz/lib/bar-series.js +16 -1
  72. package/dist/features/viz/lib/bar-series.js.map +2 -2
  73. package/dist/features/viz/lib/baseline-series.d.ts +55 -0
  74. package/dist/features/viz/lib/baseline-series.js +136 -0
  75. package/dist/features/viz/lib/baseline-series.js.map +7 -0
  76. package/dist/features/viz/lib/candlestick-series.d.ts +62 -0
  77. package/dist/features/viz/lib/candlestick-series.js +150 -0
  78. package/dist/features/viz/lib/candlestick-series.js.map +7 -0
  79. package/dist/features/viz/lib/censored-point-series.d.ts +71 -0
  80. package/dist/features/viz/lib/censored-point-series.js +129 -0
  81. package/dist/features/viz/lib/censored-point-series.js.map +7 -0
  82. package/dist/features/viz/lib/color-context.d.ts +4 -0
  83. package/dist/features/viz/lib/color-context.js +41 -0
  84. package/dist/features/viz/lib/color-context.js.map +7 -0
  85. package/dist/features/viz/lib/color-math.d.ts +4 -0
  86. package/dist/features/viz/lib/color-math.js +31 -0
  87. package/dist/features/viz/lib/color-math.js.map +7 -0
  88. package/dist/features/viz/lib/color-types.d.ts +53 -0
  89. package/dist/features/viz/lib/curve-definition.d.ts +49 -0
  90. package/dist/features/viz/lib/curve-definition.js +148 -0
  91. package/dist/features/viz/lib/curve-definition.js.map +7 -0
  92. package/dist/features/viz/lib/diverging-color-scale.d.ts +11 -0
  93. package/dist/features/viz/lib/diverging-color-scale.js +51 -0
  94. package/dist/features/viz/lib/diverging-color-scale.js.map +7 -0
  95. package/dist/features/viz/lib/domain-navigation.d.ts +40 -0
  96. package/dist/features/viz/lib/domain-navigation.js +77 -0
  97. package/dist/features/viz/lib/domain-navigation.js.map +7 -0
  98. package/dist/features/viz/lib/editable-chart-elements.d.ts +178 -0
  99. package/dist/features/viz/lib/editable-chart-elements.js +733 -0
  100. package/dist/features/viz/lib/editable-chart-elements.js.map +7 -0
  101. package/dist/features/viz/lib/financial-aggregation.d.ts +127 -0
  102. package/dist/features/viz/lib/financial-aggregation.js +116 -0
  103. package/dist/features/viz/lib/financial-aggregation.js.map +7 -0
  104. package/dist/features/viz/lib/financial-autoscale.d.ts +64 -0
  105. package/dist/features/viz/lib/financial-autoscale.js +61 -0
  106. package/dist/features/viz/lib/financial-autoscale.js.map +7 -0
  107. package/dist/features/viz/lib/financial-comparison.d.ts +62 -0
  108. package/dist/features/viz/lib/financial-comparison.js +98 -0
  109. package/dist/features/viz/lib/financial-comparison.js.map +7 -0
  110. package/dist/features/viz/lib/financial-geometry.d.ts +77 -0
  111. package/dist/features/viz/lib/financial-geometry.js +67 -0
  112. package/dist/features/viz/lib/financial-geometry.js.map +7 -0
  113. package/dist/features/viz/lib/financial-indicators.d.ts +114 -0
  114. package/dist/features/viz/lib/financial-indicators.js +135 -0
  115. package/dist/features/viz/lib/financial-indicators.js.map +7 -0
  116. package/dist/features/viz/lib/financial-oscillators.d.ts +171 -0
  117. package/dist/features/viz/lib/financial-oscillators.js +265 -0
  118. package/dist/features/viz/lib/financial-oscillators.js.map +7 -0
  119. package/dist/features/viz/lib/hover-data.d.ts +1 -1
  120. package/dist/features/viz/lib/hover-data.js +5 -2
  121. package/dist/features/viz/lib/hover-data.js.map +2 -2
  122. package/dist/features/viz/lib/interval-band-series.d.ts +49 -0
  123. package/dist/features/viz/lib/interval-band-series.js +136 -0
  124. package/dist/features/viz/lib/interval-band-series.js.map +7 -0
  125. package/dist/features/viz/lib/interval-diamond-series.d.ts +43 -0
  126. package/dist/features/viz/lib/interval-diamond-series.js +124 -0
  127. package/dist/features/viz/lib/interval-diamond-series.js.map +7 -0
  128. package/dist/features/viz/lib/interval-series.d.ts +79 -0
  129. package/dist/features/viz/lib/interval-series.js +158 -0
  130. package/dist/features/viz/lib/interval-series.js.map +7 -0
  131. package/dist/features/viz/lib/line-series.d.ts +1 -1
  132. package/dist/features/viz/lib/line-series.js +47 -28
  133. package/dist/features/viz/lib/line-series.js.map +2 -2
  134. package/dist/features/viz/lib/linear-scale.js +1 -1
  135. package/dist/features/viz/lib/linear-scale.js.map +2 -2
  136. package/dist/features/viz/lib/monotone-curve.d.ts +11 -0
  137. package/dist/features/viz/lib/monotone-curve.js +63 -0
  138. package/dist/features/viz/lib/monotone-curve.js.map +7 -0
  139. package/dist/features/viz/lib/numeric-range-interpolation.d.ts +15 -0
  140. package/dist/features/viz/lib/numeric-range-interpolation.js +36 -0
  141. package/dist/features/viz/lib/numeric-range-interpolation.js.map +7 -0
  142. package/dist/features/viz/lib/ohlc-bar-series.d.ts +55 -0
  143. package/dist/features/viz/lib/ohlc-bar-series.js +168 -0
  144. package/dist/features/viz/lib/ohlc-bar-series.js.map +7 -0
  145. package/dist/features/viz/lib/paired-series.d.ts +44 -0
  146. package/dist/features/viz/lib/paired-series.js +93 -0
  147. package/dist/features/viz/lib/paired-series.js.map +7 -0
  148. package/dist/features/viz/lib/plot-series.js +11 -6
  149. package/dist/features/viz/lib/plot-series.js.map +2 -2
  150. package/dist/features/viz/lib/plot-types.d.ts +4 -3
  151. package/dist/features/viz/lib/point-series.d.ts +1 -1
  152. package/dist/features/viz/lib/point-series.js +36 -9
  153. package/dist/features/viz/lib/point-series.js.map +2 -2
  154. package/dist/features/viz/lib/point-types.d.ts +5 -2
  155. package/dist/features/viz/lib/scale-context.d.ts +1 -1
  156. package/dist/features/viz/lib/scale-ticks.js +21 -6
  157. package/dist/features/viz/lib/scale-ticks.js.map +2 -2
  158. package/dist/features/viz/lib/sequential-color-scale.d.ts +11 -0
  159. package/dist/features/viz/lib/sequential-color-scale.js +49 -0
  160. package/dist/features/viz/lib/sequential-color-scale.js.map +7 -0
  161. package/dist/features/viz/lib/series-position.d.ts +12 -0
  162. package/dist/features/viz/lib/series-position.js +44 -0
  163. package/dist/features/viz/lib/series-position.js.map +7 -0
  164. package/dist/features/viz/lib/step-curves.d.ts +19 -0
  165. package/dist/features/viz/lib/step-curves.js +53 -0
  166. package/dist/features/viz/lib/step-curves.js.map +7 -0
  167. package/dist/features/viz/lib/threshold-color-scale.d.ts +43 -0
  168. package/dist/features/viz/lib/threshold-color-scale.js +59 -0
  169. package/dist/features/viz/lib/threshold-color-scale.js.map +7 -0
  170. package/dist/features/viz/lib/trading-time-mapping.d.ts +32 -0
  171. package/dist/features/viz/lib/trading-time-mapping.js +89 -0
  172. package/dist/features/viz/lib/trading-time-mapping.js.map +7 -0
  173. package/dist/features/viz/lib/trading-time-scale.d.ts +83 -0
  174. package/dist/features/viz/lib/trading-time-scale.js +96 -0
  175. package/dist/features/viz/lib/trading-time-scale.js.map +7 -0
  176. package/dist/features/viz/lib/trajectory-series.d.ts +71 -0
  177. package/dist/features/viz/lib/trajectory-series.js +111 -0
  178. package/dist/features/viz/lib/trajectory-series.js.map +7 -0
  179. package/dist/features/viz/lib/types.d.ts +20 -4
  180. package/dist/features/viz/lib/use-continuous-scale.js +6 -1
  181. package/dist/features/viz/lib/use-continuous-scale.js.map +2 -2
  182. package/dist/features/viz/lib/volume-series.d.ts +59 -0
  183. package/dist/features/viz/lib/volume-series.js +117 -0
  184. package/dist/features/viz/lib/volume-series.js.map +7 -0
  185. package/dist/features/viz/lib/weighted-point-series.d.ts +71 -0
  186. package/dist/features/viz/lib/weighted-point-series.js +169 -0
  187. package/dist/features/viz/lib/weighted-point-series.js.map +7 -0
  188. package/dist/filters/emboss-gpu.d.ts +4 -0
  189. package/dist/filters/emboss-gpu.js +39 -0
  190. package/dist/filters/emboss-gpu.js.map +7 -0
  191. package/dist/filters/emboss.d.ts +32 -0
  192. package/dist/filters/emboss.js +106 -0
  193. package/dist/filters/emboss.js.map +7 -0
  194. package/dist/filters/reflection-gpu.d.ts +3 -1
  195. package/dist/filters/reflection-gpu.js +5 -2
  196. package/dist/filters/reflection-gpu.js.map +2 -2
  197. package/dist/filters/render-emboss-boundary.d.ts +13 -0
  198. package/dist/filters/render-emboss-boundary.js +131 -0
  199. package/dist/filters/render-emboss-boundary.js.map +7 -0
  200. package/dist/filters.d.ts +2 -0
  201. package/dist/filters.js +2 -0
  202. package/dist/filters.js.map +2 -2
  203. package/dist/index.d.ts +2 -0
  204. package/dist/index.js +3 -0
  205. package/dist/index.js.map +2 -2
  206. package/dist/internal.d.ts +2 -0
  207. package/dist/internal.js +4 -0
  208. package/dist/internal.js.map +2 -2
  209. package/dist/lib/events/event-facade.d.ts +13 -0
  210. package/dist/lib/events/event-facade.js +23 -0
  211. package/dist/lib/events/event-facade.js.map +2 -2
  212. package/dist/lib/events/propagation.js +19 -14
  213. package/dist/lib/events/propagation.js.map +2 -2
  214. package/dist/lib/execute-render.js +13 -0
  215. package/dist/lib/execute-render.js.map +2 -2
  216. package/dist/lib/recording/recording.d.ts +43 -0
  217. package/dist/lib/recording/recording.js +555 -0
  218. package/dist/lib/recording/recording.js.map +7 -0
  219. package/dist/lib/recording/types.d.ts +118 -0
  220. package/dist/lib/recording/wasm-bytes.d.ts +1 -0
  221. package/dist/lib/recording/wasm-bytes.js +5 -0
  222. package/dist/lib/recording/wasm-bytes.js.map +7 -0
  223. package/dist/lib/recording/worker-source.d.ts +1 -0
  224. package/dist/lib/recording/worker-source.js +5 -0
  225. package/dist/lib/recording/worker-source.js.map +7 -0
  226. package/dist/lib/render-transaction.d.ts +5 -2
  227. package/dist/lib/render-transaction.js +23 -1
  228. package/dist/lib/render-transaction.js.map +2 -2
  229. package/dist/lib/series-inspection-frame.d.ts +18 -0
  230. package/dist/lib/series-inspection-frame.js +70 -0
  231. package/dist/lib/series-inspection-frame.js.map +7 -0
  232. package/dist/lib/types.d.ts +6 -0
  233. package/package.json +10 -2
@@ -0,0 +1,733 @@
1
+ import { Fragment, jsx, jsxs } from "@pibbl/core/jsx-runtime";
2
+ import {
3
+ Line,
4
+ Rectangle,
5
+ definePrimitive,
6
+ resolveSignalValue,
7
+ useRef,
8
+ useSignal
9
+ } from "@pibbl/core";
10
+ import {
11
+ pibblInternalCurrentWorldTransform
12
+ } from "@pibbl/core/internal";
13
+ import { lookupScale } from "./scale-context.js";
14
+ const TransformCapture = definePrimitive(
15
+ function TransformCapture2(props) {
16
+ props.capture.current = pibblInternalCurrentWorldTransform();
17
+ return props.children;
18
+ },
19
+ { childInput: "structural" }
20
+ );
21
+ function pair(value, name) {
22
+ if (!Array.isArray(value) || value.length !== 2 || !value.every(Number.isFinite))
23
+ throw new RangeError(`${name} requires two finite values.`);
24
+ return value;
25
+ }
26
+ function positive(value, name) {
27
+ if (!Number.isFinite(value) || value <= 0)
28
+ throw new RangeError(`${name} must be finite and positive.`);
29
+ return value;
30
+ }
31
+ function nonnegative(value, name) {
32
+ if (!Number.isFinite(value) || value < 0)
33
+ throw new RangeError(`${name} must be finite and non-negative.`);
34
+ return value;
35
+ }
36
+ function clamp(value, values) {
37
+ return Math.max(Math.min(...values), Math.min(Math.max(...values), value));
38
+ }
39
+ function clip(value, scale2) {
40
+ return clamp(value, scale2.domain);
41
+ }
42
+ function range(first, second, viewport) {
43
+ const low = Math.max(Math.min(first, second), Math.min(...viewport)), high = Math.min(Math.max(first, second), Math.max(...viewport));
44
+ return high < low ? void 0 : [low, high];
45
+ }
46
+ function style(input) {
47
+ const source = resolveSignalValue(input ?? {});
48
+ const opacity = resolveSignalValue(source.opacity) ?? 1, strokeWidth = resolveSignalValue(source.strokeWidth) ?? 1.5, handleSize = resolveSignalValue(source.handleSize) ?? 8, hitSize = resolveSignalValue(source.hitSize) ?? 20;
49
+ if (!Number.isFinite(opacity) || opacity < 0 || opacity > 1)
50
+ throw new RangeError(
51
+ "Editable chart style opacity must be finite from zero through one."
52
+ );
53
+ positive(strokeWidth, "Editable chart style strokeWidth");
54
+ positive(handleSize, "Editable chart style handleSize");
55
+ positive(hitSize, "Editable chart style hitSize");
56
+ const fill = resolveSignalValue(source.fill) ?? "#2563eb", stroke = resolveSignalValue(source.stroke) ?? "#2563eb", handleFill = resolveSignalValue(source.handleFill) ?? fill, handleStroke = resolveSignalValue(source.handleStroke) ?? stroke;
57
+ for (const [name, value] of Object.entries({
58
+ fill,
59
+ stroke,
60
+ handleFill,
61
+ handleStroke
62
+ }))
63
+ if (typeof value !== "string")
64
+ throw new TypeError(`Editable chart style ${name} must be a string.`);
65
+ return {
66
+ fill,
67
+ stroke,
68
+ strokeWidth,
69
+ opacity,
70
+ handleFill,
71
+ handleStroke,
72
+ handleSize,
73
+ hitSize
74
+ };
75
+ }
76
+ function scale(id, receiver, options = {}) {
77
+ const source = lookupScale(id, receiver);
78
+ if (!source)
79
+ throw new TypeError(`${receiver} requires an ancestor scale ID.`);
80
+ const value = source.get();
81
+ if (value.type === "point" || value.type === "band")
82
+ throw new TypeError(`${receiver} requires a continuous scale.`);
83
+ if (value.type === "trading-time" && !options.allowTradingTime)
84
+ throw new TypeError(
85
+ `${receiver} requires an invertible numeric continuous scale, not TradingTimeScale.`
86
+ );
87
+ if (!Array.isArray(value.domain) || value.domain.length < 2 || !value.domain.every(Number.isFinite) || !Array.isArray(value.range) || value.range.length !== 2 || !value.range.every(Number.isFinite) || typeof value.map !== "function")
88
+ throw new TypeError(`${receiver} requires a finite numeric scale.`);
89
+ if (value.type !== "trading-time" && typeof value.invert !== "function")
90
+ throw new TypeError(`${receiver} requires an invertible continuous scale.`);
91
+ if (value.type === "trading-time" && (!value.nearestTimeAtPosition || !value.slotAtTime || !value.timeAtSlot))
92
+ throw new TypeError(`${receiver} requires a TradingTimeScale mapping.`);
93
+ return value;
94
+ }
95
+ function local(inverse, event) {
96
+ const point = inverse.transformPoint(new DOMPoint(event.x, event.y));
97
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y))
98
+ throw new RangeError(
99
+ "Editable chart interaction requires an invertible finite transform."
100
+ );
101
+ return point;
102
+ }
103
+ function begin(state, event, original, mode, world, scales) {
104
+ if (!world || state.get()) return;
105
+ const inverse = world.inverse(), draft = {
106
+ pointerId: event.pointerId,
107
+ target: event.currentTarget,
108
+ inverse,
109
+ start: local(inverse, event),
110
+ original,
111
+ last: original,
112
+ mode,
113
+ scales: [...scales]
114
+ };
115
+ state.set(draft);
116
+ event.currentTarget.setPointerCapture(event.pointerId);
117
+ event.stopPropagation();
118
+ }
119
+ function publish(state, active, next, onChange) {
120
+ onChange(next);
121
+ state.set({ ...active, last: next });
122
+ }
123
+ function release(state, active) {
124
+ state.set(null);
125
+ if (active.target.hasPointerCapture(active.pointerId))
126
+ active.target.releasePointerCapture(active.pointerId);
127
+ }
128
+ function keys(event, cancel, edit) {
129
+ if (event.key === "Escape") {
130
+ event.preventDefault();
131
+ cancel();
132
+ return;
133
+ }
134
+ const sign = event.key === "ArrowLeft" || event.key === "ArrowDown" ? -1 : event.key === "ArrowRight" || event.key === "ArrowUp" ? 1 : 0;
135
+ if (sign) {
136
+ event.preventDefault();
137
+ edit(sign);
138
+ }
139
+ }
140
+ function edge(values, which, value, minimum, source, bounded) {
141
+ const [first, second] = values;
142
+ const domainLow = Math.min(...source.domain), domainHigh = Math.max(...source.domain);
143
+ if (which === "first") {
144
+ const limit2 = first <= second ? second - minimum : second + minimum;
145
+ return [
146
+ first <= second ? bounded ? clamp(value, [domainLow, limit2]) : Math.min(value, limit2) : bounded ? clamp(value, [limit2, domainHigh]) : Math.max(value, limit2),
147
+ second
148
+ ];
149
+ }
150
+ const limit = first <= second ? first + minimum : first - minimum;
151
+ return [
152
+ first,
153
+ first <= second ? bounded ? clamp(value, [limit, domainHigh]) : Math.max(value, limit) : bounded ? clamp(value, [domainLow, limit]) : Math.min(value, limit)
154
+ ];
155
+ }
156
+ function pan(values, delta, source, bounded) {
157
+ if (!bounded) return [values[0] + delta, values[1] + delta];
158
+ const low = Math.min(...values), high = Math.max(...values), permitted = clamp(delta, [
159
+ Math.min(...source.domain) - low,
160
+ Math.max(...source.domain) - high
161
+ ]);
162
+ return [values[0] + permitted, values[1] + permitted];
163
+ }
164
+ function minimumMappedDelta(points, requested, source, minimum) {
165
+ if (!minimum) return requested;
166
+ const width = (delta) => Math.abs(
167
+ source.invert(points[1] + delta) - source.invert(points[0] + delta)
168
+ );
169
+ let previous = 0;
170
+ for (let index = 1; index <= 64; index++) {
171
+ const candidate = requested * index / 64;
172
+ if (width(candidate) >= minimum) {
173
+ previous = candidate;
174
+ continue;
175
+ }
176
+ let low = previous, high = candidate;
177
+ for (let iteration = 0; iteration < 40; iteration++) {
178
+ const middle = (low + high) / 2;
179
+ if (width(middle) >= minimum) low = middle;
180
+ else high = middle;
181
+ }
182
+ return low;
183
+ }
184
+ return requested;
185
+ }
186
+ function panMapped(values, requested, source, bounded, minimum) {
187
+ const positions = [source.map(values[0]), source.map(values[1])], viewportDelta = bounded ? sharedMappedDelta(positions, requested, source.range) : requested, delta = minimumMappedDelta(positions, viewportDelta, source, minimum);
188
+ if (bounded)
189
+ return [
190
+ clip(source.invert(positions[0] + delta), source),
191
+ clip(source.invert(positions[1] + delta), source)
192
+ ];
193
+ return [
194
+ source.invert(positions[0] + delta),
195
+ source.invert(positions[1] + delta)
196
+ ];
197
+ }
198
+ function navigatorInterval(values, minimum, source, receiver) {
199
+ const domainLow = Math.min(...source.domain), domainHigh = Math.max(...source.domain), domainSpan = domainHigh - domainLow;
200
+ if (minimum > domainSpan)
201
+ throw new RangeError(
202
+ `${receiver} minimumSpan cannot exceed its scale domain span.`
203
+ );
204
+ if (values.some((value) => value < domainLow || value > domainHigh))
205
+ throw new RangeError(
206
+ `${receiver} values must lie within its scale domain.`
207
+ );
208
+ if (Math.abs(values[1] - values[0]) < minimum)
209
+ throw new RangeError(`${receiver} values must meet minimumSpan.`);
210
+ }
211
+ function annotationInterval(values, minimum, receiver) {
212
+ if (Math.abs(values[1] - values[0]) < minimum)
213
+ throw new RangeError(`${receiver} values must meet minimumSpan.`);
214
+ }
215
+ function handle(x, y, paint, handlers) {
216
+ const visual = {
217
+ left: x - paint.handleSize / 2,
218
+ top: y - paint.handleSize / 2,
219
+ width: paint.handleSize,
220
+ height: paint.handleSize
221
+ }, hit = {
222
+ left: x - paint.hitSize / 2,
223
+ top: y - paint.hitSize / 2,
224
+ width: paint.hitSize,
225
+ height: paint.hitSize
226
+ };
227
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
228
+ /* @__PURE__ */ jsx(
229
+ Rectangle,
230
+ {
231
+ pointerEvents: "none",
232
+ style: {
233
+ ...visual,
234
+ fill: paint.handleFill,
235
+ stroke: paint.handleStroke,
236
+ strokeWidth: paint.strokeWidth,
237
+ opacity: 1
238
+ }
239
+ }
240
+ ),
241
+ /* @__PURE__ */ jsx(
242
+ Rectangle,
243
+ {
244
+ ...handlers,
245
+ keyboardFocusable: true,
246
+ style: { ...hit, fill: "rgba(0,0,0,0)", cursor: "grab" }
247
+ }
248
+ )
249
+ ] });
250
+ }
251
+ function sharedMappedDelta(points, requested, viewport) {
252
+ return clamp(requested, [
253
+ Math.min(...viewport) - Math.min(...points),
254
+ Math.max(...viewport) - Math.max(...points)
255
+ ]);
256
+ }
257
+ function RangeNavigator(props) {
258
+ const values = pair(
259
+ resolveSignalValue(props.values),
260
+ "RangeNavigator values"
261
+ ), span = pair(resolveSignalValue(props.span), "RangeNavigator span"), source = scale(props.scale, "RangeNavigator"), paint = style(props.style), minimum = nonnegative(props.minimumSpan ?? 0, "RangeNavigator minimumSpan"), draft = useSignal(null), transform = useRef();
262
+ navigatorInterval(values, minimum, source, "RangeNavigator");
263
+ const first = source.map(values[0]), second = source.map(values[1]), visible = range(first, second, source.range);
264
+ const cancel = () => {
265
+ const active = draft.get();
266
+ if (!active) return;
267
+ props.onChange(active.original);
268
+ release(draft, active);
269
+ props.onCancel?.();
270
+ };
271
+ const down = (mode) => (event) => begin(draft, event, values, mode, transform.current, [source]);
272
+ const move = (event) => {
273
+ const active = draft.get();
274
+ if (!active || active.pointerId !== event.pointerId) return;
275
+ const point = local(active.inverse, event), captured = active.scales[0], next = active.mode === "pan" ? panMapped(
276
+ active.original,
277
+ point.x - active.start.x,
278
+ captured,
279
+ true,
280
+ minimum
281
+ ) : edge(
282
+ active.original,
283
+ active.mode,
284
+ captured.invert(point.x),
285
+ minimum,
286
+ captured,
287
+ true
288
+ );
289
+ publish(draft, active, next, props.onChange);
290
+ event.stopPropagation();
291
+ };
292
+ const up = (event) => {
293
+ const active = draft.get();
294
+ if (!active || active.pointerId !== event.pointerId) return;
295
+ release(draft, active);
296
+ props.onCommit?.(active.last);
297
+ event.stopPropagation();
298
+ };
299
+ if (!visible) return null;
300
+ const top = Math.min(...span), height = Math.abs(span[1] - span[0]), center = top + height / 2;
301
+ const edit = (sign) => {
302
+ const keyboardStep = minimum || Math.abs(source.domain[1] - source.domain[0]) * 0.01, next = pan(values, sign * keyboardStep, source, true);
303
+ props.onChange(next);
304
+ props.onCommit?.(next);
305
+ };
306
+ const handleKeys = (event) => keys(event, cancel, edit);
307
+ return /* @__PURE__ */ jsxs(TransformCapture, { capture: transform, children: [
308
+ /* @__PURE__ */ jsx(
309
+ Rectangle,
310
+ {
311
+ keyboardFocusable: true,
312
+ onPointerDown: down("pan"),
313
+ onPointerMove: move,
314
+ onPointerUp: up,
315
+ onPointerCancel: cancel,
316
+ onLostPointerCapture: cancel,
317
+ onKeyDown: handleKeys,
318
+ style: {
319
+ left: visible[0],
320
+ top,
321
+ width: visible[1] - visible[0],
322
+ height,
323
+ fill: paint.fill,
324
+ stroke: paint.stroke,
325
+ strokeWidth: paint.strokeWidth,
326
+ opacity: paint.opacity,
327
+ cursor: "grab"
328
+ }
329
+ }
330
+ ),
331
+ handle(first, center, paint, {
332
+ onPointerDown: down("first"),
333
+ onPointerMove: move,
334
+ onPointerUp: up,
335
+ onPointerCancel: cancel,
336
+ onLostPointerCapture: cancel,
337
+ onKeyDown: handleKeys
338
+ }),
339
+ handle(second, center, paint, {
340
+ onPointerDown: down("second"),
341
+ onPointerMove: move,
342
+ onPointerUp: up,
343
+ onPointerCancel: cancel,
344
+ onLostPointerCapture: cancel,
345
+ onKeyDown: handleKeys
346
+ })
347
+ ] });
348
+ }
349
+ function EditableReferenceLine(props) {
350
+ if (props.direction !== "horizontal" && props.direction !== "vertical")
351
+ throw new TypeError(
352
+ "EditableReferenceLine direction must be horizontal or vertical."
353
+ );
354
+ const value = resolveSignalValue(props.value), span = pair(resolveSignalValue(props.span), "EditableReferenceLine span"), source = scale(props.scale, "EditableReferenceLine"), step = positive(props.keyboardStep, "EditableReferenceLine keyboardStep"), paint = style(props.style), selected = resolveSignalValue(props.selected ?? true), draft = useSignal(null), transform = useRef();
355
+ if (!Number.isFinite(value))
356
+ throw new RangeError("EditableReferenceLine value must be finite.");
357
+ const position = source.map(value), cancel = () => {
358
+ const active = draft.get();
359
+ if (!active) return;
360
+ props.onChange(active.original);
361
+ release(draft, active);
362
+ props.onCancel?.();
363
+ }, down = (event) => {
364
+ props.onSelect?.();
365
+ begin(draft, event, value, "line", transform.current, [source]);
366
+ };
367
+ const move = (event) => {
368
+ const active = draft.get();
369
+ if (!active || active.pointerId !== event.pointerId) return;
370
+ const point = local(active.inverse, event), captured = active.scales[0];
371
+ publish(
372
+ draft,
373
+ active,
374
+ captured.invert(props.direction === "horizontal" ? point.y : point.x),
375
+ props.onChange
376
+ );
377
+ event.stopPropagation();
378
+ }, up = (event) => {
379
+ const active = draft.get();
380
+ if (!active || active.pointerId !== event.pointerId) return;
381
+ release(draft, active);
382
+ props.onCommit?.(active.last);
383
+ event.stopPropagation();
384
+ };
385
+ if (!range(position, position, source.range)) return null;
386
+ const coords = props.direction === "horizontal" ? [
387
+ [span[0], position],
388
+ [span[1], position]
389
+ ] : [
390
+ [position, span[0]],
391
+ [position, span[1]]
392
+ ], x = props.direction === "horizontal" ? (span[0] + span[1]) / 2 : position, y = props.direction === "horizontal" ? position : (span[0] + span[1]) / 2;
393
+ const edit = (sign) => {
394
+ props.onSelect?.();
395
+ const next = value + sign * step;
396
+ props.onChange(next);
397
+ props.onCommit?.(next);
398
+ };
399
+ const handleKeys = (event) => keys(event, cancel, edit);
400
+ return /* @__PURE__ */ jsxs(TransformCapture, { capture: transform, children: [
401
+ /* @__PURE__ */ jsx(
402
+ Line,
403
+ {
404
+ keyboardFocusable: true,
405
+ onPointerDown: down,
406
+ onPointerMove: move,
407
+ onPointerUp: up,
408
+ onPointerCancel: cancel,
409
+ onLostPointerCapture: cancel,
410
+ onKeyDown: handleKeys,
411
+ style: {
412
+ coords,
413
+ stroke: paint.stroke,
414
+ strokeWidth: paint.strokeWidth,
415
+ opacity: paint.opacity,
416
+ lineInteractionWidth: paint.hitSize,
417
+ cursor: "grab"
418
+ }
419
+ }
420
+ ),
421
+ selected ? handle(x, y, paint, {
422
+ onPointerDown: down,
423
+ onPointerMove: move,
424
+ onPointerUp: up,
425
+ onPointerCancel: cancel,
426
+ onLostPointerCapture: cancel,
427
+ onKeyDown: handleKeys
428
+ }) : null
429
+ ] });
430
+ }
431
+ function EditableReferenceBand(props) {
432
+ if (props.direction !== "horizontal" && props.direction !== "vertical")
433
+ throw new TypeError(
434
+ "EditableReferenceBand direction must be horizontal or vertical."
435
+ );
436
+ const values = pair(
437
+ resolveSignalValue(props.values),
438
+ "EditableReferenceBand values"
439
+ ), span = pair(resolveSignalValue(props.span), "EditableReferenceBand span"), source = scale(props.scale, "EditableReferenceBand"), step = positive(props.keyboardStep, "EditableReferenceBand keyboardStep"), minimum = nonnegative(
440
+ props.minimumSpan ?? 0,
441
+ "EditableReferenceBand minimumSpan"
442
+ ), paint = style(props.style), selected = resolveSignalValue(props.selected ?? true), draft = useSignal(null), transform = useRef();
443
+ annotationInterval(values, minimum, "EditableReferenceBand");
444
+ const first = source.map(values[0]), second = source.map(values[1]), visible = range(first, second, source.range);
445
+ const cancel = () => {
446
+ const active = draft.get();
447
+ if (!active) return;
448
+ props.onChange(active.original);
449
+ release(draft, active);
450
+ props.onCancel?.();
451
+ };
452
+ const down = (mode) => (event) => {
453
+ props.onSelect?.();
454
+ begin(draft, event, values, mode, transform.current, [source]);
455
+ };
456
+ const move = (event) => {
457
+ const active = draft.get();
458
+ if (!active || active.pointerId !== event.pointerId) return;
459
+ const point = local(active.inverse, event), coordinate = props.direction === "horizontal" ? point.y : point.x, start = props.direction === "horizontal" ? active.start.y : active.start.x, captured = active.scales[0], next = active.mode === "pan" ? panMapped(
460
+ active.original,
461
+ coordinate - start,
462
+ captured,
463
+ false,
464
+ minimum
465
+ ) : edge(
466
+ active.original,
467
+ active.mode,
468
+ captured.invert(coordinate),
469
+ minimum,
470
+ captured,
471
+ false
472
+ );
473
+ publish(draft, active, next, props.onChange);
474
+ event.stopPropagation();
475
+ };
476
+ const up = (event) => {
477
+ const active = draft.get();
478
+ if (!active || active.pointerId !== event.pointerId) return;
479
+ release(draft, active);
480
+ props.onCommit?.(active.last);
481
+ event.stopPropagation();
482
+ };
483
+ const edit = (sign) => {
484
+ props.onSelect?.();
485
+ const next = pan(values, sign * step, source, false);
486
+ props.onChange(next);
487
+ props.onCommit?.(next);
488
+ };
489
+ if (!visible) return null;
490
+ const rect = props.direction === "horizontal" ? {
491
+ left: Math.min(...span),
492
+ top: visible[0],
493
+ width: Math.abs(span[1] - span[0]),
494
+ height: visible[1] - visible[0]
495
+ } : {
496
+ left: visible[0],
497
+ top: Math.min(...span),
498
+ width: visible[1] - visible[0],
499
+ height: Math.abs(span[1] - span[0])
500
+ };
501
+ const firstHandle = props.direction === "horizontal" ? [Math.min(...span), first] : [first, Math.min(...span)], secondHandle = props.direction === "horizontal" ? [Math.max(...span), second] : [second, Math.max(...span)];
502
+ const handleKeys = (event) => keys(event, cancel, edit);
503
+ return /* @__PURE__ */ jsxs(TransformCapture, { capture: transform, children: [
504
+ /* @__PURE__ */ jsx(
505
+ Rectangle,
506
+ {
507
+ keyboardFocusable: true,
508
+ onPointerDown: down("pan"),
509
+ onPointerMove: move,
510
+ onPointerUp: up,
511
+ onPointerCancel: cancel,
512
+ onLostPointerCapture: cancel,
513
+ onKeyDown: handleKeys,
514
+ style: {
515
+ ...rect,
516
+ fill: paint.fill,
517
+ stroke: paint.stroke,
518
+ strokeWidth: paint.strokeWidth,
519
+ opacity: paint.opacity,
520
+ cursor: "grab"
521
+ }
522
+ }
523
+ ),
524
+ selected ? /* @__PURE__ */ jsxs(Fragment, { children: [
525
+ handle(firstHandle[0], firstHandle[1], paint, {
526
+ onPointerDown: down("first"),
527
+ onPointerMove: move,
528
+ onPointerUp: up,
529
+ onPointerCancel: cancel,
530
+ onLostPointerCapture: cancel,
531
+ onKeyDown: handleKeys
532
+ }),
533
+ handle(secondHandle[0], secondHandle[1], paint, {
534
+ onPointerDown: down("second"),
535
+ onPointerMove: move,
536
+ onPointerUp: up,
537
+ onPointerCancel: cancel,
538
+ onLostPointerCapture: cancel,
539
+ onKeyDown: handleKeys
540
+ })
541
+ ] }) : null
542
+ ] });
543
+ }
544
+ function snap(source, position) {
545
+ const time = source.nearestTimeAtPosition?.(position);
546
+ if (time === void 0)
547
+ throw new RangeError(
548
+ "EditableTrendLine cannot edit an empty TradingTimeScale."
549
+ );
550
+ return time;
551
+ }
552
+ function mapped(source, position) {
553
+ return source.type === "trading-time" ? snap(source, position) : source.invert(position);
554
+ }
555
+ function advanceTradingTime(source, value, sign, step) {
556
+ const target = value + sign * step, candidates = source.domain.filter(
557
+ (candidate) => sign > 0 ? candidate >= target : candidate <= target
558
+ );
559
+ return sign > 0 ? candidates[0] ?? Math.max(...source.domain) : candidates[candidates.length - 1] ?? Math.min(...source.domain);
560
+ }
561
+ function translateTradingAnchors(source, anchors, sign, step) {
562
+ const slots = anchors.map((anchor) => source.slotAtTime(anchor.x));
563
+ const requested = source.slotAtTime(advanceTradingTime(source, anchors[0].x, sign, step)) - slots[0];
564
+ const delta = clamp(requested, [
565
+ -Math.min(...slots),
566
+ source.domain.length - 1 - Math.max(...slots)
567
+ ]);
568
+ return [
569
+ { ...anchors[0], x: source.timeAtSlot(slots[0] + delta) },
570
+ { ...anchors[1], x: source.timeAtSlot(slots[1] + delta) }
571
+ ];
572
+ }
573
+ function EditableTrendLine(props) {
574
+ const anchors = resolveSignalValue(props.anchors), x = scale(props.xScale, "EditableTrendLine xScale", {
575
+ allowTradingTime: true
576
+ }), y = scale(props.yScale, "EditableTrendLine yScale"), stepX = positive(props.keyboardStep.x, "EditableTrendLine keyboardStep.x"), stepY = positive(props.keyboardStep.y, "EditableTrendLine keyboardStep.y"), paint = style(props.style), selected = resolveSignalValue(props.selected ?? true), draft = useSignal(null), transform = useRef();
577
+ if (!Array.isArray(anchors) || anchors.length !== 2 || !anchors.every(
578
+ (anchor) => Number.isFinite(anchor.x) && Number.isFinite(anchor.y)
579
+ ))
580
+ throw new RangeError("EditableTrendLine requires two finite anchors.");
581
+ const positions = [
582
+ { x: x.map(anchors[0].x), y: y.map(anchors[0].y) },
583
+ { x: x.map(anchors[1].x), y: y.map(anchors[1].y) }
584
+ ];
585
+ const cancel = () => {
586
+ const active = draft.get();
587
+ if (!active) return;
588
+ props.onChange(active.original);
589
+ release(draft, active);
590
+ props.onCancel?.();
591
+ };
592
+ const down = (mode) => (event) => {
593
+ props.onSelect?.();
594
+ begin(
595
+ draft,
596
+ event,
597
+ anchors,
598
+ mode,
599
+ transform.current,
600
+ [x, y]
601
+ );
602
+ };
603
+ const move = (event) => {
604
+ const active = draft.get();
605
+ if (!active || active.pointerId !== event.pointerId) return;
606
+ const point = local(active.inverse, event), dragX = active.scales[0], dragY = active.scales[1];
607
+ let next;
608
+ if (active.mode === "line") {
609
+ const originalPositions = [
610
+ {
611
+ x: dragX.map(active.original[0].x),
612
+ y: dragY.map(active.original[0].y)
613
+ },
614
+ {
615
+ x: dragX.map(active.original[1].x),
616
+ y: dragY.map(active.original[1].y)
617
+ }
618
+ ];
619
+ const yDelta = point.y - active.start.y;
620
+ const slotDelta = dragX.type === "trading-time" ? clamp(
621
+ Math.round(
622
+ dragX.slotAtTime(snap(dragX, point.x)) - dragX.slotAtTime(snap(dragX, active.start.x))
623
+ ),
624
+ [
625
+ -Math.min(
626
+ dragX.slotAtTime(active.original[0].x),
627
+ dragX.slotAtTime(active.original[1].x)
628
+ ),
629
+ dragX.domain.length - 1 - Math.max(
630
+ dragX.slotAtTime(active.original[0].x),
631
+ dragX.slotAtTime(active.original[1].x)
632
+ )
633
+ ]
634
+ ) : 0;
635
+ const xDelta = dragX.type === "trading-time" ? 0 : point.x - active.start.x;
636
+ const translateX = (anchor, position) => dragX.type === "trading-time" ? dragX.timeAtSlot(dragX.slotAtTime(anchor.x) + slotDelta) : mapped(dragX, position.x + xDelta);
637
+ next = [
638
+ {
639
+ x: translateX(active.original[0], originalPositions[0]),
640
+ y: mapped(dragY, originalPositions[0].y + yDelta)
641
+ },
642
+ {
643
+ x: translateX(active.original[1], originalPositions[1]),
644
+ y: mapped(dragY, originalPositions[1].y + yDelta)
645
+ }
646
+ ];
647
+ } else {
648
+ const index = active.mode === "first" ? 0 : 1, changed = { x: mapped(dragX, point.x), y: mapped(dragY, point.y) };
649
+ next = index === 0 ? [changed, active.original[1]] : [active.original[0], changed];
650
+ }
651
+ publish(draft, active, next, props.onChange);
652
+ event.stopPropagation();
653
+ };
654
+ const up = (event) => {
655
+ const active = draft.get();
656
+ if (!active || active.pointerId !== event.pointerId) return;
657
+ release(draft, active);
658
+ props.onCommit?.(active.last);
659
+ event.stopPropagation();
660
+ };
661
+ const edit = (sign, axis) => {
662
+ props.onSelect?.();
663
+ const translated = axis === "y" ? anchors : x.type === "trading-time" ? translateTradingAnchors(x, anchors, sign, stepX) : [
664
+ { ...anchors[0], x: anchors[0].x + sign * stepX },
665
+ { ...anchors[1], x: anchors[1].x + sign * stepX }
666
+ ];
667
+ const next = [
668
+ { ...translated[0], y: anchors[0].y + (axis === "y" ? sign * stepY : 0) },
669
+ { ...translated[1], y: anchors[1].y + (axis === "y" ? sign * stepY : 0) }
670
+ ];
671
+ props.onChange(next);
672
+ props.onCommit?.(next);
673
+ };
674
+ const coords = positions.map((point) => [
675
+ point.x,
676
+ point.y
677
+ ]);
678
+ const handleKeys = (event) => keys(
679
+ event,
680
+ cancel,
681
+ (sign) => edit(
682
+ sign,
683
+ event.key === "ArrowLeft" || event.key === "ArrowRight" ? "x" : "y"
684
+ )
685
+ );
686
+ return /* @__PURE__ */ jsxs(TransformCapture, { capture: transform, children: [
687
+ /* @__PURE__ */ jsx(
688
+ Line,
689
+ {
690
+ keyboardFocusable: true,
691
+ onPointerDown: down("line"),
692
+ onPointerMove: move,
693
+ onPointerUp: up,
694
+ onPointerCancel: cancel,
695
+ onLostPointerCapture: cancel,
696
+ onKeyDown: handleKeys,
697
+ style: {
698
+ coords,
699
+ stroke: paint.stroke,
700
+ strokeWidth: paint.strokeWidth,
701
+ opacity: paint.opacity,
702
+ lineInteractionWidth: paint.hitSize,
703
+ cursor: "grab"
704
+ }
705
+ }
706
+ ),
707
+ selected ? /* @__PURE__ */ jsxs(Fragment, { children: [
708
+ handle(positions[0].x, positions[0].y, paint, {
709
+ onPointerDown: down("first"),
710
+ onPointerMove: move,
711
+ onPointerUp: up,
712
+ onPointerCancel: cancel,
713
+ onLostPointerCapture: cancel,
714
+ onKeyDown: handleKeys
715
+ }),
716
+ handle(positions[1].x, positions[1].y, paint, {
717
+ onPointerDown: down("second"),
718
+ onPointerMove: move,
719
+ onPointerUp: up,
720
+ onPointerCancel: cancel,
721
+ onLostPointerCapture: cancel,
722
+ onKeyDown: handleKeys
723
+ })
724
+ ] }) : null
725
+ ] });
726
+ }
727
+ export {
728
+ EditableReferenceBand,
729
+ EditableReferenceLine,
730
+ EditableTrendLine,
731
+ RangeNavigator
732
+ };
733
+ //# sourceMappingURL=editable-chart-elements.js.map