victory-core 36.9.2 → 37.0.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.
- package/CHANGELOG.md +6 -0
- package/dist/victory-core.js +4371 -5749
- package/dist/victory-core.min.js +1 -1
- package/es/victory-accessible-group/victory-accessible-group.js +9 -15
- package/es/victory-animation/util.js +28 -47
- package/es/victory-animation/victory-animation.js +51 -67
- package/es/victory-clip-container/victory-clip-container.js +153 -229
- package/es/victory-container/victory-container.js +157 -216
- package/es/victory-label/victory-label.js +246 -323
- package/es/victory-portal/portal-context.js +1 -2
- package/es/victory-portal/portal.js +30 -76
- package/es/victory-portal/victory-portal.js +47 -104
- package/es/victory-primitives/arc.js +44 -47
- package/es/victory-primitives/background.js +14 -17
- package/es/victory-primitives/border.js +20 -24
- package/es/victory-primitives/circle.js +13 -27
- package/es/victory-primitives/clip-path.js +3 -7
- package/es/victory-primitives/line-segment.js +20 -24
- package/es/victory-primitives/line.js +13 -27
- package/es/victory-primitives/path.js +13 -27
- package/es/victory-primitives/point.js +36 -40
- package/es/victory-primitives/rect.js +13 -27
- package/es/victory-primitives/text.js +15 -28
- package/es/victory-primitives/tspan.js +13 -26
- package/es/victory-primitives/whisker.js +43 -47
- package/es/victory-theme/grayscale.js +22 -22
- package/es/victory-theme/material.js +46 -46
- package/es/victory-theme/victory-theme.js +3 -3
- package/es/victory-transition/victory-transition.js +126 -206
- package/es/victory-util/add-events.js +263 -374
- package/es/victory-util/axis.js +126 -222
- package/es/victory-util/collection.js +13 -41
- package/es/victory-util/data.js +159 -214
- package/es/victory-util/default-transitions.js +33 -51
- package/es/victory-util/domain.js +122 -171
- package/es/victory-util/events.js +168 -258
- package/es/victory-util/helpers.js +153 -178
- package/es/victory-util/hooks/use-animation-state.js +61 -99
- package/es/victory-util/hooks/use-previous-props.js +2 -2
- package/es/victory-util/immutable.js +6 -8
- package/es/victory-util/label-helpers.js +128 -130
- package/es/victory-util/line-helpers.js +29 -41
- package/es/victory-util/log.js +1 -1
- package/es/victory-util/point-path-helpers.js +89 -49
- package/es/victory-util/scale.js +24 -42
- package/es/victory-util/selection.js +39 -40
- package/es/victory-util/style.js +8 -13
- package/es/victory-util/textsize.js +80 -154
- package/es/victory-util/timer-context.js +2 -2
- package/es/victory-util/timer.js +40 -76
- package/es/victory-util/transitions.js +110 -150
- package/es/victory-util/type-helpers.js +2 -3
- package/es/victory-util/user-props.js +24 -49
- package/es/victory-util/wrapper.js +184 -247
- package/lib/index.js +0 -30
- package/lib/victory-accessible-group/victory-accessible-group.js +9 -19
- package/lib/victory-animation/util.js +28 -63
- package/lib/victory-animation/victory-animation.js +54 -83
- package/lib/victory-clip-container/victory-clip-container.js +156 -243
- package/lib/victory-container/victory-container.js +160 -232
- package/lib/victory-label/victory-label.js +248 -344
- package/lib/victory-portal/portal-context.js +1 -6
- package/lib/victory-portal/portal.js +31 -81
- package/lib/victory-portal/victory-portal.js +50 -116
- package/lib/victory-primitives/arc.js +48 -57
- package/lib/victory-primitives/background.js +16 -28
- package/lib/victory-primitives/border.js +22 -34
- package/lib/victory-primitives/circle.js +16 -36
- package/lib/victory-primitives/clip-path.js +3 -11
- package/lib/victory-primitives/index.js +0 -28
- package/lib/victory-primitives/line-segment.js +22 -34
- package/lib/victory-primitives/line.js +16 -36
- package/lib/victory-primitives/path.js +16 -36
- package/lib/victory-primitives/point.js +38 -52
- package/lib/victory-primitives/rect.js +16 -36
- package/lib/victory-primitives/text.js +15 -33
- package/lib/victory-primitives/tspan.js +13 -31
- package/lib/victory-primitives/whisker.js +45 -57
- package/lib/victory-theme/grayscale.js +23 -24
- package/lib/victory-theme/material.js +47 -48
- package/lib/victory-theme/victory-theme.js +2 -7
- package/lib/victory-transition/victory-transition.js +129 -224
- package/lib/victory-util/add-events.js +263 -380
- package/lib/victory-util/axis.js +128 -241
- package/lib/victory-util/collection.js +13 -50
- package/lib/victory-util/data.js +160 -239
- package/lib/victory-util/default-transitions.js +33 -54
- package/lib/victory-util/domain.js +123 -193
- package/lib/victory-util/events.js +167 -274
- package/lib/victory-util/helpers.js +156 -207
- package/lib/victory-util/hooks/index.js +0 -2
- package/lib/victory-util/hooks/use-animation-state.js +63 -113
- package/lib/victory-util/hooks/use-previous-props.js +2 -7
- package/lib/victory-util/immutable.js +6 -18
- package/lib/victory-util/index.js +2 -51
- package/lib/victory-util/label-helpers.js +130 -141
- package/lib/victory-util/line-helpers.js +31 -49
- package/lib/victory-util/log.js +1 -2
- package/lib/victory-util/point-path-helpers.js +91 -63
- package/lib/victory-util/scale.js +26 -57
- package/lib/victory-util/selection.js +41 -49
- package/lib/victory-util/style.js +8 -16
- package/lib/victory-util/textsize.js +80 -157
- package/lib/victory-util/timer-context.js +2 -8
- package/lib/victory-util/timer.js +40 -76
- package/lib/victory-util/transitions.js +110 -152
- package/lib/victory-util/type-helpers.js +2 -9
- package/lib/victory-util/user-props.js +25 -59
- package/lib/victory-util/wrapper.js +186 -281
- package/package.json +2 -2
|
@@ -4,37 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.convertLengthToPixels = exports.approximateTextSize = exports._approximateTextSizeInternal = void 0;
|
|
7
|
-
|
|
8
7
|
var _memoize2 = _interopRequireDefault(require("lodash/memoize"));
|
|
9
|
-
|
|
10
8
|
var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
|
-
|
|
18
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
19
|
-
|
|
20
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
-
|
|
22
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
23
|
-
|
|
24
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
25
|
-
|
|
26
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
|
-
|
|
28
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
29
|
-
|
|
30
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
31
|
-
|
|
32
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
10
|
+
// http://www.pearsonified.com/2012/01/characters-per-line.php
|
|
11
|
+
/* eslint-disable no-magic-numbers */
|
|
33
12
|
|
|
34
13
|
// Based on measuring specific character widths
|
|
35
14
|
// as in the following example https://bl.ocks.org/tophtucker/62f93a4658387bb61e4510c37e2e97cf
|
|
36
15
|
// prettier-ignore
|
|
37
|
-
|
|
16
|
+
const fonts = {
|
|
38
17
|
"American Typewriter": {
|
|
39
18
|
widths: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.4203125, 0.3296875, 0.6, 0.6375, 0.8015625, 0.8203125, 0.1875, 0.45625, 0.45625, 0.6375, 0.5, 0.2734375, 0.309375, 0.2734375, 0.4390625, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.6375, 0.2734375, 0.2734375, 0.5, 0.5, 0.5, 0.6, 0.6921875, 0.7640625, 0.6921875, 0.6375, 0.728125, 0.6734375, 0.6203125, 0.7109375, 0.784375, 0.3828125, 0.6421875, 0.7859375, 0.6375, 0.9484375, 0.7640625, 0.65625, 0.6375, 0.65625, 0.7296875, 0.6203125, 0.6375, 0.7109375, 0.740625, 0.940625, 0.784375, 0.7578125, 0.6203125, 0.4375, 0.5, 0.4375, 0.5, 0.5, 0.4921875, 0.5734375, 0.5890625, 0.5109375, 0.6, 0.528125, 0.43125, 0.5578125, 0.6375, 0.3109375, 0.40625, 0.6234375, 0.309375, 0.928125, 0.6375, 0.546875, 0.6, 0.58125, 0.4921875, 0.4921875, 0.4, 0.6203125, 0.625, 0.825, 0.6375, 0.640625, 0.528125, 0.5, 0.5, 0.5, 0.6671875],
|
|
40
19
|
avg: 0.5793421052631578
|
|
@@ -139,10 +118,11 @@ var fonts = {
|
|
|
139
118
|
widths: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.35, 0.39375, 0.459375, 0.81875, 0.6359375, 1.0765625, 0.759375, 0.26875, 0.4546875, 0.4546875, 0.6359375, 0.81875, 0.3640625, 0.4546875, 0.3640625, 0.4703125, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.6359375, 0.4546875, 0.4546875, 0.81875, 0.81875, 0.81875, 0.546875, 1, 0.684375, 0.6859375, 0.6984375, 0.771875, 0.6328125, 0.575, 0.7765625, 0.7515625, 0.421875, 0.4546875, 0.69375, 0.5578125, 0.84375, 0.7484375, 0.7875, 0.603125, 0.7875, 0.7, 0.684375, 0.6171875, 0.7328125, 0.684375, 0.9890625, 0.6859375, 0.615625, 0.6859375, 0.4546875, 0.46875, 0.4546875, 0.81875, 0.6421875, 0.6359375, 0.6015625, 0.6234375, 0.521875, 0.6234375, 0.596875, 0.384375, 0.6234375, 0.6328125, 0.275, 0.3765625, 0.5921875, 0.275, 0.9734375, 0.6328125, 0.6078125, 0.6234375, 0.6234375, 0.43125, 0.521875, 0.3953125, 0.6328125, 0.5921875, 0.81875, 0.5921875, 0.5921875, 0.5265625, 0.6359375, 0.4546875, 0.6359375, 0.81875],
|
|
140
119
|
avg: 0.6171875000000003
|
|
141
120
|
}
|
|
142
|
-
};
|
|
143
|
-
// Absolute sizes in pixels for obsolete measurement units.
|
|
121
|
+
};
|
|
144
122
|
|
|
145
|
-
|
|
123
|
+
// https://developer.mozilla.org/en/docs/Web/CSS/length
|
|
124
|
+
// Absolute sizes in pixels for obsolete measurement units.
|
|
125
|
+
const absoluteMeasurementUnitsToPixels = {
|
|
146
126
|
mm: 3.8,
|
|
147
127
|
sm: 38,
|
|
148
128
|
pt: 1.33,
|
|
@@ -150,62 +130,46 @@ var absoluteMeasurementUnitsToPixels = {
|
|
|
150
130
|
in: 96,
|
|
151
131
|
px: 1
|
|
152
132
|
};
|
|
153
|
-
|
|
133
|
+
const relativeMeasurementUnitsCoef = {
|
|
154
134
|
em: 1,
|
|
155
135
|
ex: 0.5
|
|
156
136
|
};
|
|
157
|
-
|
|
137
|
+
const coefficients = {
|
|
158
138
|
heightOverlapCoef: 1.05,
|
|
159
139
|
// Coefficient for height value to prevent overlap.
|
|
160
140
|
lineCapitalCoef: 1.15 // Coefficient for height value. Reserve space for capital chars.
|
|
161
|
-
|
|
162
141
|
};
|
|
163
|
-
|
|
142
|
+
const defaultStyle = {
|
|
164
143
|
lineHeight: 1,
|
|
165
144
|
letterSpacing: "0px",
|
|
166
145
|
fontSize: 0,
|
|
167
146
|
angle: 0,
|
|
168
147
|
fontFamily: ""
|
|
169
148
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
var _getFontData = function (fontFamily) {
|
|
176
|
-
var possibleFonts = fontFamily.split(",").map(function (f) {
|
|
177
|
-
return f.replace(/'|"/g, "");
|
|
178
|
-
});
|
|
179
|
-
var fontMatch = possibleFonts.find(function (f) {
|
|
180
|
-
return fonts[f];
|
|
181
|
-
}) || "Helvetica";
|
|
149
|
+
const _degreeToRadian = angle => angle * Math.PI / 180;
|
|
150
|
+
const _getFontData = fontFamily => {
|
|
151
|
+
const possibleFonts = fontFamily.split(",").map(f => f.replace(/'|"/g, ""));
|
|
152
|
+
const fontMatch = possibleFonts.find(f => fonts[f]) || "Helvetica";
|
|
182
153
|
return fonts[fontMatch];
|
|
183
154
|
};
|
|
184
|
-
|
|
185
|
-
var _splitToLines = function (text) {
|
|
155
|
+
const _splitToLines = text => {
|
|
186
156
|
return Array.isArray(text) ? text : text.toString().split(/\r\n|\r|\n/g);
|
|
187
157
|
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
var angleInRadian = _degreeToRadian(angle);
|
|
191
|
-
|
|
158
|
+
const _getSizeWithRotate = (axisSize, dependentSize, angle) => {
|
|
159
|
+
const angleInRadian = _degreeToRadian(angle);
|
|
192
160
|
return Math.abs(Math.cos(angleInRadian) * axisSize) + Math.abs(Math.sin(angleInRadian) * dependentSize);
|
|
193
161
|
};
|
|
162
|
+
|
|
194
163
|
/**
|
|
195
164
|
* Convert length-type parameters from specific measurement units to pixels
|
|
196
165
|
* @param {string} length Css length string value.
|
|
197
166
|
* @param {number} fontSize Current text font-size.
|
|
198
167
|
* @returns {number} Approximate Css length in pixels.
|
|
199
168
|
*/
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
var attribute = (_length$match = length.match(/[a-zA-Z%]+/)) === null || _length$match === void 0 ? void 0 : _length$match[0];
|
|
206
|
-
var value = Number(length.match(/[0-9.,]+/));
|
|
207
|
-
var result;
|
|
208
|
-
|
|
169
|
+
const convertLengthToPixels = (length, fontSize) => {
|
|
170
|
+
const attribute = length.match(/[a-zA-Z%]+/)?.[0];
|
|
171
|
+
const value = Number(length.match(/[0-9.,]+/));
|
|
172
|
+
let result;
|
|
209
173
|
if (!attribute) {
|
|
210
174
|
result = value || 0;
|
|
211
175
|
} else if (absoluteMeasurementUnitsToPixels.hasOwnProperty(attribute)) {
|
|
@@ -215,85 +179,67 @@ var convertLengthToPixels = function (length, fontSize) {
|
|
|
215
179
|
} else {
|
|
216
180
|
result = value;
|
|
217
181
|
}
|
|
218
|
-
|
|
219
182
|
return result;
|
|
220
183
|
};
|
|
221
|
-
|
|
222
184
|
exports.convertLengthToPixels = convertLengthToPixels;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
var style = (0, _defaults2.default)({}, lineStyle, defaultStyle);
|
|
185
|
+
const _prepareParams = (inputStyle, index) => {
|
|
186
|
+
const lineStyle = Array.isArray(inputStyle) ? inputStyle[index] : inputStyle;
|
|
187
|
+
const style = (0, _defaults2.default)({}, lineStyle, defaultStyle);
|
|
227
188
|
return Object.assign({}, style, {
|
|
228
189
|
fontFamily: style.fontFamily,
|
|
229
190
|
letterSpacing: typeof style.letterSpacing === "number" ? style.letterSpacing : convertLengthToPixels(String(style.letterSpacing), style.fontSize),
|
|
230
191
|
fontSize: typeof style.fontSize === "number" ? style.fontSize : convertLengthToPixels(String(style.fontSize))
|
|
231
192
|
});
|
|
232
193
|
};
|
|
233
|
-
|
|
234
|
-
var _approximateTextWidthInternal = function (text, style) {
|
|
194
|
+
const _approximateTextWidthInternal = (text, style) => {
|
|
235
195
|
if (text === undefined || text === "" || text === null) {
|
|
236
196
|
return 0;
|
|
237
197
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
var fontData = _getFontData(fontFamily);
|
|
248
|
-
|
|
249
|
-
var width = line.toString().split("").map(function (c) {
|
|
198
|
+
const widths = _splitToLines(text).map((line, index) => {
|
|
199
|
+
const len = line.toString().length;
|
|
200
|
+
const {
|
|
201
|
+
fontSize,
|
|
202
|
+
letterSpacing,
|
|
203
|
+
fontFamily
|
|
204
|
+
} = _prepareParams(style, index);
|
|
205
|
+
const fontData = _getFontData(fontFamily);
|
|
206
|
+
const width = line.toString().split("").map(c => {
|
|
250
207
|
return c.charCodeAt(0) < fontData.widths.length ? fontData.widths[c.charCodeAt(0)] : fontData.avg;
|
|
251
|
-
}).reduce(
|
|
252
|
-
return acc + cur;
|
|
253
|
-
}, 0) * fontSize;
|
|
208
|
+
}).reduce((cur, acc) => acc + cur, 0) * fontSize;
|
|
254
209
|
return width + letterSpacing * Math.max(len - 1, 0);
|
|
255
210
|
});
|
|
256
|
-
|
|
257
|
-
return Math.max.apply(Math, _toConsumableArray(widths));
|
|
211
|
+
return Math.max(...widths);
|
|
258
212
|
};
|
|
259
|
-
|
|
260
|
-
var _approximateTextHeightInternal = function (text, style) {
|
|
213
|
+
const _approximateTextHeightInternal = (text, style) => {
|
|
261
214
|
if (text === undefined || text === "" || text === null) {
|
|
262
215
|
return 0;
|
|
263
216
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
var containsCaps = line.toString().match(/[(A-Z)(0-9)]/);
|
|
269
|
-
var height = containsCaps ? lineStyle.fontSize * coefficients.lineCapitalCoef : lineStyle.fontSize;
|
|
217
|
+
return _splitToLines(text).reduce((total, line, index) => {
|
|
218
|
+
const lineStyle = _prepareParams(style, index);
|
|
219
|
+
const containsCaps = line.toString().match(/[(A-Z)(0-9)]/);
|
|
220
|
+
const height = containsCaps ? lineStyle.fontSize * coefficients.lineCapitalCoef : lineStyle.fontSize;
|
|
270
221
|
return total + lineStyle.lineHeight * height;
|
|
271
222
|
}, 0);
|
|
272
223
|
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
var width = _approximateTextWidthInternal(text, style);
|
|
280
|
-
|
|
281
|
-
var widthWithRotate = angle ? _getSizeWithRotate(width, height, angle) : width;
|
|
282
|
-
var heightWithRotate = angle ? _getSizeWithRotate(height, width, angle) : height;
|
|
224
|
+
const _approximateDimensionsInternal = (text, style) => {
|
|
225
|
+
const angle = Array.isArray(style) ? style[0] && style[0].angle : style && style.angle;
|
|
226
|
+
const height = _approximateTextHeightInternal(text, style);
|
|
227
|
+
const width = _approximateTextWidthInternal(text, style);
|
|
228
|
+
const widthWithRotate = angle ? _getSizeWithRotate(width, height, angle) : width;
|
|
229
|
+
const heightWithRotate = angle ? _getSizeWithRotate(height, width, angle) : height;
|
|
283
230
|
return {
|
|
284
231
|
width: widthWithRotate,
|
|
285
232
|
height: heightWithRotate * coefficients.heightOverlapCoef
|
|
286
233
|
};
|
|
287
234
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
var element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
235
|
+
const _getMeasurementContainer = (0, _memoize2.default)(() => {
|
|
236
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
291
237
|
element.setAttribute("xlink", "http://www.w3.org/1999/xlink");
|
|
292
238
|
element.setAttribute("width", "300");
|
|
293
239
|
element.setAttribute("height", "300");
|
|
294
240
|
element.setAttribute("viewBox", "0 0 300 300");
|
|
295
241
|
element.setAttribute("aria-hidden", "true");
|
|
296
|
-
|
|
242
|
+
const containerElement = document.createElementNS("http://www.w3.org/2000/svg", "text");
|
|
297
243
|
element.appendChild(containerElement);
|
|
298
244
|
element.style.position = "fixed";
|
|
299
245
|
element.style.top = "-9999px";
|
|
@@ -301,80 +247,63 @@ var _getMeasurementContainer = (0, _memoize2.default)(function () {
|
|
|
301
247
|
document.body.appendChild(element);
|
|
302
248
|
return containerElement;
|
|
303
249
|
});
|
|
304
|
-
|
|
305
|
-
var styleToKeyComponent = function (style) {
|
|
250
|
+
const styleToKeyComponent = style => {
|
|
306
251
|
if (!style) {
|
|
307
252
|
return "null";
|
|
308
253
|
}
|
|
309
|
-
|
|
310
|
-
return "".concat(style.angle, ":").concat(style.fontFamily, ":").concat(style.fontSize, ":").concat(style.letterSpacing, ":").concat(style.lineHeight);
|
|
254
|
+
return `${style.angle}:${style.fontFamily}:${style.fontSize}:${style.letterSpacing}:${style.lineHeight}`;
|
|
311
255
|
};
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
var containerElement = _getMeasurementContainer();
|
|
315
|
-
|
|
256
|
+
const _measureDimensionsInternal = (0, _memoize2.default)((text, style) => {
|
|
257
|
+
let containerElement = _getMeasurementContainer();
|
|
316
258
|
if (!containerElement.isConnected) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
(_getMeasurementContai = (_getMeasurementContai2 = _getMeasurementContainer.cache).clear) === null || _getMeasurementContai === void 0 ? void 0 : _getMeasurementContai.call(_getMeasurementContai2);
|
|
259
|
+
_getMeasurementContainer.cache.clear?.();
|
|
320
260
|
containerElement = _getMeasurementContainer();
|
|
321
261
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
for (var _ref of lines.entries()) {
|
|
328
|
-
var _ref2 = _slicedToArray(_ref, 2);
|
|
329
|
-
|
|
330
|
-
var i = _ref2[0];
|
|
331
|
-
var line = _ref2[1];
|
|
332
|
-
var textElement = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
|
|
333
|
-
|
|
334
|
-
var params = _prepareParams(style, i);
|
|
335
|
-
|
|
262
|
+
const lines = _splitToLines(text);
|
|
263
|
+
let heightAcc = 0;
|
|
264
|
+
for (const [i, line] of lines.entries()) {
|
|
265
|
+
const textElement = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
|
|
266
|
+
const params = _prepareParams(style, i);
|
|
336
267
|
textElement.style.fontFamily = params.fontFamily;
|
|
337
|
-
textElement.style.fontSize =
|
|
268
|
+
textElement.style.fontSize = `${params.fontSize}px`;
|
|
338
269
|
textElement.style.lineHeight = params.lineHeight;
|
|
339
270
|
textElement.style.fontFamily = params.fontFamily;
|
|
340
271
|
textElement.style.letterSpacing = params.letterSpacing;
|
|
341
272
|
textElement.textContent = line;
|
|
342
273
|
textElement.setAttribute("x", "0");
|
|
343
|
-
textElement.setAttribute("y",
|
|
274
|
+
textElement.setAttribute("y", `${heightAcc}`);
|
|
344
275
|
containerElement.appendChild(textElement);
|
|
345
276
|
heightAcc += params.lineHeight * textElement.getBoundingClientRect().height;
|
|
346
277
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
278
|
+
const {
|
|
279
|
+
width
|
|
280
|
+
} = containerElement.getBoundingClientRect();
|
|
351
281
|
containerElement.innerHTML = "";
|
|
352
282
|
return {
|
|
353
|
-
width: style
|
|
354
|
-
height: style
|
|
283
|
+
width: style?.angle ? _getSizeWithRotate(width, heightAcc, style?.angle) : width,
|
|
284
|
+
height: style?.angle ? _getSizeWithRotate(heightAcc, width, style?.angle) : heightAcc
|
|
355
285
|
};
|
|
356
|
-
},
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
return
|
|
286
|
+
}, (text, style) => {
|
|
287
|
+
const totalText = Array.isArray(text) ? text.join() : text;
|
|
288
|
+
const totalStyle = Array.isArray(style) ? style.map(styleToKeyComponent).join() : styleToKeyComponent(style);
|
|
289
|
+
return `${totalText}::${totalStyle}`;
|
|
360
290
|
});
|
|
361
|
-
|
|
362
291
|
// Stubbable implementation.
|
|
363
|
-
|
|
364
|
-
impl: function (text, style) {
|
|
365
|
-
|
|
366
|
-
|
|
292
|
+
const _approximateTextSizeInternal = exports._approximateTextSizeInternal = {
|
|
293
|
+
impl: function (text, style, __debugForceApproximate) {
|
|
294
|
+
if (__debugForceApproximate === void 0) {
|
|
295
|
+
__debugForceApproximate = false;
|
|
296
|
+
}
|
|
367
297
|
// Attempt to first measure the element in DOM. If there is no DOM, fallback
|
|
368
298
|
// to the less accurate approximation algorithm.
|
|
369
|
-
|
|
370
|
-
|
|
299
|
+
const isClient = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
371
300
|
if (!isClient || __debugForceApproximate) {
|
|
372
301
|
return _approximateDimensionsInternal(text, style);
|
|
373
302
|
}
|
|
374
|
-
|
|
375
303
|
return _measureDimensionsInternal(text, style);
|
|
376
304
|
}
|
|
377
305
|
};
|
|
306
|
+
|
|
378
307
|
/**
|
|
379
308
|
* Predict text size by font params.
|
|
380
309
|
* @param {string|string[]} text Content for width calculation.
|
|
@@ -386,11 +315,5 @@ var _approximateTextSizeInternal = {
|
|
|
386
315
|
* @param {number} style.lineHeight Line height coefficient.
|
|
387
316
|
* @returns {number} Approximate text label height.
|
|
388
317
|
*/
|
|
389
|
-
|
|
390
|
-
exports._approximateTextSizeInternal = _approximateTextSizeInternal;
|
|
391
|
-
|
|
392
|
-
var approximateTextSize = function (text, style) {
|
|
393
|
-
return _approximateTextSizeInternal.impl(text, style);
|
|
394
|
-
};
|
|
395
|
-
|
|
318
|
+
const approximateTextSize = (text, style) => _approximateTextSizeInternal.impl(text, style);
|
|
396
319
|
exports.approximateTextSize = approximateTextSize;
|
|
@@ -4,22 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
8
|
var _timer = _interopRequireDefault(require("./timer"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* The React context object consumers may use to access or override the global
|
|
16
12
|
* timer.
|
|
17
13
|
*/
|
|
18
|
-
|
|
14
|
+
const TimerContext = /*#__PURE__*/_react.default.createContext({
|
|
19
15
|
transitionTimer: new _timer.default(),
|
|
20
16
|
animationTimer: new _timer.default()
|
|
21
17
|
});
|
|
22
|
-
|
|
23
18
|
TimerContext.displayName = "TimerContext";
|
|
24
|
-
var _default = TimerContext;
|
|
25
|
-
exports.default = _default;
|
|
19
|
+
var _default = exports.default = TimerContext;
|
|
@@ -4,90 +4,54 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _d3Timer = require("victory-vendor/d3-timer");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
13
|
-
|
|
14
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
-
|
|
16
|
-
var Timer = /*#__PURE__*/function () {
|
|
17
|
-
function Timer() {
|
|
18
|
-
var _this = this;
|
|
19
|
-
|
|
20
|
-
_classCallCheck(this, Timer);
|
|
21
|
-
|
|
22
|
-
this.shouldAnimate = void 0;
|
|
23
|
-
this.subscribers = void 0;
|
|
24
|
-
this.activeSubscriptions = void 0;
|
|
25
|
-
this.timer = void 0;
|
|
26
|
-
|
|
27
|
-
this.loop = function () {
|
|
28
|
-
_this.subscribers.forEach(function (s) {
|
|
29
|
-
s.callback((0, _d3Timer.now)() - s.startTime, s.duration);
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
8
|
+
class Timer {
|
|
9
|
+
constructor() {
|
|
33
10
|
this.shouldAnimate = true;
|
|
34
11
|
this.subscribers = [];
|
|
35
12
|
this.timer = null;
|
|
36
13
|
this.activeSubscriptions = 0;
|
|
37
14
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (!this.timer) {
|
|
53
|
-
this.timer = (0, _d3Timer.timer)(this.loop);
|
|
54
|
-
}
|
|
15
|
+
bypassAnimation() {
|
|
16
|
+
this.shouldAnimate = false;
|
|
17
|
+
}
|
|
18
|
+
resumeAnimation() {
|
|
19
|
+
this.shouldAnimate = true;
|
|
20
|
+
}
|
|
21
|
+
loop = () => {
|
|
22
|
+
this.subscribers.forEach(s => {
|
|
23
|
+
s.callback((0, _d3Timer.now)() - s.startTime, s.duration);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
start() {
|
|
27
|
+
if (!this.timer) {
|
|
28
|
+
this.timer = (0, _d3Timer.timer)(this.loop);
|
|
55
29
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.timer = null;
|
|
62
|
-
}
|
|
30
|
+
}
|
|
31
|
+
stop() {
|
|
32
|
+
if (this.timer) {
|
|
33
|
+
this.timer.stop();
|
|
34
|
+
this.timer = null;
|
|
63
35
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
36
|
+
}
|
|
37
|
+
subscribe(callback, duration) {
|
|
38
|
+
const subscriptionID = this.subscribers.push({
|
|
39
|
+
startTime: (0, _d3Timer.now)(),
|
|
40
|
+
callback,
|
|
41
|
+
duration: this.shouldAnimate ? duration : 0
|
|
42
|
+
});
|
|
43
|
+
this.activeSubscriptions++;
|
|
44
|
+
this.start();
|
|
45
|
+
return subscriptionID;
|
|
46
|
+
}
|
|
47
|
+
unsubscribe(id) {
|
|
48
|
+
if (id !== null && this.subscribers[id - 1]) {
|
|
49
|
+
delete this.subscribers[id - 1];
|
|
50
|
+
this.activeSubscriptions--;
|
|
75
51
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
value: function unsubscribe(id) {
|
|
79
|
-
if (id !== null && this.subscribers[id - 1]) {
|
|
80
|
-
delete this.subscribers[id - 1];
|
|
81
|
-
this.activeSubscriptions--;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (this.activeSubscriptions === 0) {
|
|
85
|
-
this.stop();
|
|
86
|
-
}
|
|
52
|
+
if (this.activeSubscriptions === 0) {
|
|
53
|
+
this.stop();
|
|
87
54
|
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return Timer;
|
|
91
|
-
}();
|
|
92
|
-
|
|
55
|
+
}
|
|
56
|
+
}
|
|
93
57
|
exports.default = Timer;
|