diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000000000000000000000000000000000000..7521eb073cf5f1559c71f275079a8100e2d48e58 --- /dev/null +++ b/.babelrc @@ -0,0 +1,7 @@ +{ + "env": { + "test": { + "plugins": ["@babel/plugin-transform-modules-commonjs"] + } + } +} diff --git a/__tests__/erasure.test.js b/__tests__/erasure.test.js index 60841887b1606aed105f42559c0947361f62bf2e..49584da67404d8777ea00e8b5bb535ee71e849ca 100644 --- a/__tests__/erasure.test.js +++ b/__tests__/erasure.test.js @@ -1,7 +1,7 @@ -const { +import { computeErasureIntervals, combineErasureIntervals, -} = require("../src/erasure") +} from "../src/erasure.js" describe("erasure intervals", () => { it("computes simple erasure intervals", () => { diff --git a/package-lock.json b/package-lock.json index c3564ceb23bcbcedc3de1e9fc7d7cdddd8f6aaf4..6e9d29fb5a58712a7a6764d441c07aac4809a737 100644 --- a/package-lock.json +++ b/package-lock.json @@ -104,12 +104,45 @@ "@babel/types": "^7.0.0" } }, + "@babel/helper-module-imports": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.0.0.tgz", + "integrity": "sha512-aP/hlLq01DWNEiDg4Jn23i+CXxW/owM4WpDLFUbpjxe4NS3BhLVZQ5i7E0ZrxuQ/vwekIeciyamgB1UIYxxM6A==", + "dev": true, + "requires": { + "@babel/types": "^7.0.0" + } + }, + "@babel/helper-module-transforms": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.5.5.tgz", + "integrity": "sha512-jBeCvETKuJqeiaCdyaheF40aXnnU1+wkSiUs/IQg3tB85up1LyL8x77ClY8qJpuRJUcXQo+ZtdNESmZl4j56Pw==", + "dev": true, + "requires": { + "@babel/helper-module-imports": "^7.0.0", + "@babel/helper-simple-access": "^7.1.0", + "@babel/helper-split-export-declaration": "^7.4.4", + "@babel/template": "^7.4.4", + "@babel/types": "^7.5.5", + "lodash": "^4.17.13" + } + }, "@babel/helper-plugin-utils": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz", "integrity": "sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA==", "dev": true }, + "@babel/helper-simple-access": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.1.0.tgz", + "integrity": "sha512-Vk+78hNjRbsiu49zAPALxTb+JUQCz1aolpd8osOF16BGnLtseD21nbHgLPGUwrXEurZgiCOUmvs3ExTu4F5x6w==", + "dev": true, + "requires": { + "@babel/template": "^7.1.0", + "@babel/types": "^7.0.0" + } + }, "@babel/helper-split-export-declaration": { "version": "7.4.4", "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.4.4.tgz", @@ -156,6 +189,18 @@ "@babel/helper-plugin-utils": "^7.0.0" } }, + "@babel/plugin-transform-modules-commonjs": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.6.0.tgz", + "integrity": "sha512-Ma93Ix95PNSEngqomy5LSBMAQvYKVe3dy+JlVJSHEXZR5ASL9lQBedMiCyVtmTLraIDVRE3ZjTZvmXXD2Ozw3g==", + "dev": true, + "requires": { + "@babel/helper-module-transforms": "^7.4.4", + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-simple-access": "^7.1.0", + "babel-plugin-dynamic-import-node": "^2.3.0" + } + }, "@babel/template": { "version": "7.6.0", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.6.0.tgz", @@ -980,6 +1025,15 @@ "slash": "^2.0.0" } }, + "babel-plugin-dynamic-import-node": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz", + "integrity": "sha512-o6qFkpeQEBxcqt0XYlWzAVxNCSCZdUgcR8IRlhD/8DylxjjO4foPcvTW0GGKa/cVt3rvxZ7o5ippJ+/0nvLhlQ==", + "dev": true, + "requires": { + "object.assign": "^4.1.0" + } + }, "babel-plugin-istanbul": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-5.2.0.tgz", @@ -5509,6 +5563,18 @@ "isobject": "^3.0.0" } }, + "object.assign": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", + "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", + "dev": true, + "requires": { + "define-properties": "^1.1.2", + "function-bind": "^1.1.1", + "has-symbols": "^1.0.0", + "object-keys": "^1.0.11" + } + }, "object.getownpropertydescriptors": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz", diff --git a/package.json b/package.json index 21bd2440a14d89b76244588458a3cbf2b2f4c630..79966736740510c71a3274e2775e03d1d36ef7ff 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "yjs": "file:src/yjs" }, "devDependencies": { + "@babel/plugin-transform-modules-commonjs": "^7.6.0", "eslint": "^6.5.1", "jest": "^24.9.0", "prettier": "^1.18.2", diff --git a/src/app.js b/src/app.js index d5996939e62ba72da0a7e0f07c3c7b30242d47e5..d40a51b977fc8a95f864b48857a63e3f8f21f21b 100644 --- a/src/app.js +++ b/src/app.js @@ -4,15 +4,11 @@ import * as canvas from "./canvas.js" import * as HTML from "./elements.js" +import { computeErasureIntervals, combineErasureIntervals } from "./erasure.js" import { connect } from "./room.js" const TEST_ROOM = "imperial" -const { - computeErasureIntervals, - combineErasureIntervals, -} = require("./erasure") - const ERASER_RADIUS = 20 let room = null diff --git a/src/erasure.js b/src/erasure.js index 0968dd8ad7da8be35b4a98e1f8e8766ffa123fe0..6347634f4f44e5d8674cbc7ba9c9fcd51c9ea33a 100644 --- a/src/erasure.js +++ b/src/erasure.js @@ -74,7 +74,7 @@ function erasureInterval(lineStart, lineEnd, erasureCenter, erasureRadius) { ] } -function computeErasureIntervals(points, erasureCenter, erasureRadius) { +export function computeErasureIntervals(points, erasureCenter, erasureRadius) { return points .map((point, i) => ({ point, i })) .reduce((acc, { point, i }) => { @@ -112,7 +112,7 @@ function mergeIntervals(...intervals) { return stack } -function combineErasureIntervals(i1, i2) { +export function combineErasureIntervals(i1, i2) { const _i1 = { ...i1 } Object.keys(i1).forEach((key) => { if (i2[key]) { @@ -121,8 +121,3 @@ function combineErasureIntervals(i1, i2) { }) return { ...i2, ..._i1 } } - -module.exports = { - computeErasureIntervals, - combineErasureIntervals, -}