Skip to content

Commit e85ee24

Browse files
committed
add warning when using the legacy api
1 parent 0914b90 commit e85ee24

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

internal/animate/interpolate.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@ export const interpolateBetween = (percentage: number, a: Shape, b: Shape): Shap
4747
// Interpolates between shapes a and b while applying a smoothing effect. Smoothing effect's
4848
// strength is relative to how far away the percentage is from either 0 or 1. It is strongest in the
4949
// middle of the animation (percentage = 0.5) or when bounds are exceeded (percentage = 1.8).
50-
export const interpolateBetweenSmooth = (strength: number, percentage: number, a: Shape, b: Shape): Shape => {
50+
export const interpolateBetweenSmooth = (
51+
strength: number,
52+
percentage: number,
53+
a: Shape,
54+
b: Shape,
55+
): Shape => {
5156
strength *= Math.min(1, Math.min(Math.abs(0 - percentage), Math.abs(1 - percentage)));
5257
const interpolated = interpolateBetween(percentage, a, b);
53-
const smoothed = smooth(interpolated, Math.sqrt(strength + 0.25)/3);
58+
const smoothed = smooth(interpolated, Math.sqrt(strength + 0.25) / 3);
5459
return mapShape(interpolated, ({index, curr}) => {
5560
const sp = smoothed[index];
5661
curr.handleIn.angle = interpolateAngle(strength, curr.handleIn.angle, sp.handleIn.angle);

internal/animate/prepare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const optimizeOrder = (a: Shape, b: Shape): Shape => {
2424
for (let i = 0; i < count; i++) {
2525
let sum = 0;
2626
for (let j = 0; j < count; j++) {
27-
sum += distance(a[j], shape[mod(j + i, count)]);
27+
sum += (100 * distance(a[j], shape[mod(j + i, count)])) ** 1 / 2;
2828
if (sum > minSum) break;
2929
}
3030
if (sum <= minSum) {

internal/animate/testing/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<body>
2121
<button id="toggle">TOGGLE<br>DEBUG</button>
2222
<script src="./script.ts"></script>
23+
<script src="../../../legacy/blobs.ts"></script>
2324
</body>
2425

2526
</html>

legacy/blobs.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import {XmlElement} from "../editable";
66
import {genBlob} from "../internal/blobs";
77
import {mapShape} from "../internal/util";
88

9+
const isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
10+
const isLocalhost = () => location.hostname === "localhost" || location.hostname === "127.0.0.1";
11+
if (!isBrowser() || (isBrowser() && isLocalhost())) {
12+
console.warn("You are using the legacy blobs API!\nPlease use TODO instead.");
13+
}
14+
915
export interface PathOptions {
1016
// Bounding box dimensions.
1117
size: number;

rollup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import typescript from "rollup-plugin-typescript2";
22
import {uglify} from "rollup-plugin-uglify";
33

44
export default {
5-
input: "./index.ts",
5+
input: "./legacy/blobs.ts",
66
output: {
77
file: "index.js",
88
format: "umd",

0 commit comments

Comments
 (0)