diff --git a/.gitignore b/.gitignore index 7cff648e4a..3b7c9023b4 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ bundle.* *.js *.d.ts *.bak* -*.zip \ No newline at end of file +*.zip +/.gtm/ diff --git a/examples/README.md b/examples/README.md index e18bb82346..6a8699dc3e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -16,18 +16,19 @@ If you want to [contribute](../CONTRIBUTING.md) an example, please get in touch | 8 | [hdom-basics](./hdom-basics) | Hello world | hdom, hiccup | basic | | 9 | [hdom-benchmark](./hdom-benchmark) | hdom rendering perf / stress test, FPS counter | hdom, rstream, transducers | intermediate | | 10 | [hdom-theme-adr-0003](./hdom-theme-adr-0003) | hdom themed components proposal | hdom | intermediate | -| 11 | [hydrate-basics](./hydrate-basics) | hiccup / hdom DOM hydration | hiccup, hdom | intermediate | -| 12 | [interceptor-basics](./interceptor-basics) | Event handling w/ interceptors and side effects | atom, hdom, interceptors | intermediate | -| 13 | [json-components](./json-components) | JSON->component transformation, live editor | hdom, transducers | intermediate | -| 14 | [login-form](./login-form) | Basic SPA without router | atom, hdom | intermediate | -| 15 | [pointfree-svg](./pointfree-svg) | Generate SVG using pointfree DSL | hiccup, hiccup-svg, pointfree-lang | intermediate | -| 16 | [router-basics](./router-basics) | Complete mini SPA | atom, hdom, interceptors, router | advanced | -| 17 | [rstream-dataflow](./rstream-dataflow) | Dataflow graph | atom, hdom, rstream, rstream-gestures, rstream-graph, transducers | intermediate | -| 18 | [rstream-grid](./rstream-grid) | Dataflow graph SVG grid | atom, hdom, hiccup-svg, interceptors, rstream-graph, transducers | advanced | -| 19 | [rstream-hdom](./rstream-hdom) | rstream based UI updates & state handling | hdom, rstream, transducers | intermediate | -| 20 | [svg-particles](./svg-particles) | hdom SVG generation / animation | hdom, transducers | basic | -| 21 | [svg-waveform](./svg-waveform) | hdom SVG generation / undo history | atom, hdom, hiccup-svg, interceptors, iterators | intermediate | -| 22 | [todo-list](./todo-list) | Canonical Todo list with undo/redo | atom, hdom, transducers | intermediate | -| 23 | [transducers-hdom](./transducers-hdom) | Transducer & rstream based hdom UI updates | hdom, rstream, transducers-hdom | basic | -| 24 | [triple-query](./triple-query) | Triple store query results & sortable table | atom, hdom, hdom-components, rstream-query, transducers | intermediate | -| 25 | [webgl](./webgl) | Canvas component handling | hdom, hdom-components | basic | \ No newline at end of file +| 11 | [hmr-basics](./hmr-basics) | hdom & webpack hot module replacement | hdom, memoize | basic | +| 12 | [hydrate-basics](./hydrate-basics) | hiccup / hdom DOM hydration | hiccup, hdom | intermediate | +| 13 | [interceptor-basics](./interceptor-basics) | Event handling w/ interceptors and side effects | atom, hdom, interceptors | intermediate | +| 14 | [json-components](./json-components) | JSON->component transformation, live editor | hdom, transducers | intermediate | +| 15 | [login-form](./login-form) | Basic SPA without router | atom, hdom | intermediate | +| 16 | [pointfree-svg](./pointfree-svg) | Generate SVG using pointfree DSL | hiccup, hiccup-svg, pointfree-lang | intermediate | +| 17 | [router-basics](./router-basics) | Complete mini SPA | atom, hdom, interceptors, router | advanced | +| 18 | [rstream-dataflow](./rstream-dataflow) | Dataflow graph | atom, hdom, rstream, rstream-gestures, rstream-graph, transducers | intermediate | +| 19 | [rstream-grid](./rstream-grid) | Dataflow graph SVG grid | atom, hdom, hiccup-svg, interceptors, rstream-graph, transducers | advanced | +| 20 | [rstream-hdom](./rstream-hdom) | rstream based UI updates & state handling | hdom, rstream, transducers | intermediate | +| 21 | [svg-particles](./svg-particles) | hdom SVG generation / animation | hdom, transducers | basic | +| 22 | [svg-waveform](./svg-waveform) | hdom SVG generation / undo history | atom, hdom, hiccup-svg, interceptors, iterators | intermediate | +| 23 | [todo-list](./todo-list) | Canonical Todo list with undo/redo | atom, hdom, transducers | intermediate | +| 24 | [transducers-hdom](./transducers-hdom) | Transducer & rstream based hdom UI updates | hdom, rstream, transducers-hdom | basic | +| 25 | [triple-query](./triple-query) | Triple store query results & sortable table | atom, hdom, hdom-components, rstream-query, transducers | intermediate | +| 26 | [webgl](./webgl) | Canvas component handling | hdom, hdom-components | basic | \ No newline at end of file diff --git a/examples/hmr-basics/.gitignore b/examples/hmr-basics/.gitignore new file mode 100644 index 0000000000..9c418ce79f --- /dev/null +++ b/examples/hmr-basics/.gitignore @@ -0,0 +1,3 @@ +node_modules +yarn.lock +*.js diff --git a/examples/hmr-basics/README.md b/examples/hmr-basics/README.md new file mode 100644 index 0000000000..0a0d7f0ebd --- /dev/null +++ b/examples/hmr-basics/README.md @@ -0,0 +1,22 @@ +# hmr-basics + +[Live demo](http://demo.thi.ng/umbrella/hmr-basics/) + +Minimal example demonstrating the combined usage of @thi.ng/memoize's +[`defonce`](https://github.com/thi-ng/umbrella/tree/master/packages/memoize/src/defonce.ts) +and webpack's [Hot Module Replacement API](https://webpack.js.org/api/hot-module-replacement/). + +```bash +git clone https://github.com/thi-ng/umbrella.git +cd umbrella/examples/hmr-basics +yarn install +yarn start +``` + +## Authors + +- Karsten Schmidt + +## License + +© 2018 Karsten Schmidt // Apache Software License 2.0 diff --git a/examples/hmr-basics/index.html b/examples/hmr-basics/index.html new file mode 100644 index 0000000000..90602064ed --- /dev/null +++ b/examples/hmr-basics/index.html @@ -0,0 +1,19 @@ + + + + + + + + hmr-basics + + + + + +
+ + + + \ No newline at end of file diff --git a/examples/hmr-basics/package.json b/examples/hmr-basics/package.json new file mode 100644 index 0000000000..96eb8851cd --- /dev/null +++ b/examples/hmr-basics/package.json @@ -0,0 +1,25 @@ +{ + "name": "hmr-basics", + "version": "0.0.1", + "repository": "https://github.com/thi-ng/umbrella", + "author": "Karsten Schmidt ", + "license": "Apache-2.0", + "scripts": { + "build": "webpack --mode production --display-reasons --display-modules", + "start": "webpack-dev-server --open --mode development --devtool inline-source-map --hot-only" + }, + "devDependencies": { + "ts-loader": "^4.4.2", + "typescript": "^3.0.1", + "webpack": "^4.16.3", + "webpack-cli": "^3.1.0", + "webpack-dev-server": "^3.1.5" + }, + "dependencies": { + "@thi.ng/atom": "latest", + "@thi.ng/memoize": "latest", + "@thi.ng/rstream": "latest", + "@thi.ng/transducers": "latest", + "@thi.ng/transducers-hdom": "latest" + } +} \ No newline at end of file diff --git a/examples/hmr-basics/src/app.ts b/examples/hmr-basics/src/app.ts new file mode 100644 index 0000000000..d9cf7a8186 --- /dev/null +++ b/examples/hmr-basics/src/app.ts @@ -0,0 +1,27 @@ +// edit this file after launching the webpack-dev-server (`yarn start`) +// to see hot module replacement in action: +// the `state.launched` and `state.seed` values should remain constant +// when this module is being replaced via HMR + +// root component function +export const app = ({ now, state }) => + ["div.pa2.sans-serif.f6.bg-light-yellow", + ["h1.pa0.ma0.bb", "State"], + ["ul.ma0.pv3.bb", + [item, "Now:", now], + [item, "Launched at:", state.launched], + [item, "Seed:", state.seed], + ], + ["div.mt3", + "Edit ", + [repoLink, "src/app.ts"], + " to see hot module replacement in action."] + ]; + +const item = (_, label, value) => + ["li", ["span.dib.b.w4", label], value]; + +const repoLink = (_, file) => + ["a.pa1.link.black.bg-light-gray", + { href: `https://github.com/thi-ng/umbrella/tree/master/examples/hmr-basics/${file}` }, + file]; diff --git a/examples/hmr-basics/src/index.ts b/examples/hmr-basics/src/index.ts new file mode 100644 index 0000000000..acdf6e0553 --- /dev/null +++ b/examples/hmr-basics/src/index.ts @@ -0,0 +1,28 @@ +import { fromAtom } from "@thi.ng/rstream/from/atom"; +import { fromInterval } from "@thi.ng/rstream/from/interval"; +import { sync } from "@thi.ng/rstream/stream-sync"; +import { updateDOM } from "@thi.ng/transducers-hdom"; +import { map } from "@thi.ng/transducers/xform/map"; +import { app } from "./app"; +import { state } from "./state"; + +// combine streams of atom values & timer +const ui = sync({ + src: { + state: fromAtom(state), + now: fromInterval(1000).transform(map((_) => new Date())) + } +}); +// then transform using root component function +// and hdom differential DOM updater +ui.transform(map(app), updateDOM()); + +// webpack HMR handling +const hot = (module).hot; +if (hot) { + // terminate existing UI stream before applying updated module + hot.dispose(() => ui.unsubscribe()); + // accept hot updates for app.ts & self + hot.accept('./app.ts'); + hot.accept(); +} diff --git a/examples/hmr-basics/src/state.ts b/examples/hmr-basics/src/state.ts new file mode 100644 index 0000000000..be31ba6a61 --- /dev/null +++ b/examples/hmr-basics/src/state.ts @@ -0,0 +1,12 @@ +import { Atom } from "@thi.ng/atom/atom"; +import { defonce } from "@thi.ng/memoize/defonce"; + +// `defonce` is used here to protect the app stat atom from +// re-initializing during hot module replacement. +// in other words, the atom is *only* initialized once when the +// application first loads / reloads +export const state = defonce("umbrella.example.hmr", () => + new Atom({ + launched: new Date(), + seed: (Math.random() * 100) | 0, + })); diff --git a/examples/hmr-basics/tsconfig.json b/examples/hmr-basics/tsconfig.json new file mode 100644 index 0000000000..051329da52 --- /dev/null +++ b/examples/hmr-basics/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": ".", + "noUnusedLocals": false, + "noUnusedParameters": false + }, + "include": [ + "./src/**/*.ts" + ] +} \ No newline at end of file diff --git a/examples/hmr-basics/webpack.config.js b/examples/hmr-basics/webpack.config.js new file mode 100644 index 0000000000..76771ce959 --- /dev/null +++ b/examples/hmr-basics/webpack.config.js @@ -0,0 +1,24 @@ +const webpack = require("webpack"); + +module.exports = { + entry: "./src/index.ts", + output: { + path: __dirname, + filename: "bundle.js", + }, + resolve: { + extensions: [".ts", ".js"] + }, + module: { + rules: [ + { test: /\.ts$/, use: "ts-loader" } + ] + }, + plugins: [ + new webpack.HotModuleReplacementPlugin() + ], + devServer: { + contentBase: ".", + hot: true + } +}; diff --git a/packages/associative/CHANGELOG.md b/packages/associative/CHANGELOG.md index aaf690c667..10a8d8b92d 100644 --- a/packages/associative/CHANGELOG.md +++ b/packages/associative/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.6.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/associative@0.6.3...@thi.ng/associative@0.6.4) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/associative + ## [0.6.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/associative@0.6.2...@thi.ng/associative@0.6.3) (2018-09-03) diff --git a/packages/associative/package.json b/packages/associative/package.json index 7898ce6d8d..844fdd76d0 100644 --- a/packages/associative/package.json +++ b/packages/associative/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/associative", - "version": "0.6.3", + "version": "0.6.4", "description": "Alternative Set & Map data type implementations with customizable equality semantics & supporting operations", "main": "./index.js", "typings": "./index.d.ts", @@ -31,10 +31,10 @@ "@thi.ng/api": "^4.1.0", "@thi.ng/checks": "^1.5.7", "@thi.ng/compare": "^0.1.6", - "@thi.ng/dcons": "^1.1.3", + "@thi.ng/dcons": "^1.1.4", "@thi.ng/equiv": "^0.1.7", "@thi.ng/errors": "^0.1.6", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "data structures", diff --git a/packages/cache/CHANGELOG.md b/packages/cache/CHANGELOG.md index a55ce61c14..44ff493431 100644 --- a/packages/cache/CHANGELOG.md +++ b/packages/cache/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.2.21](https://github.com/thi-ng/umbrella/compare/@thi.ng/cache@0.2.20...@thi.ng/cache@0.2.21) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/cache + ## [0.2.20](https://github.com/thi-ng/umbrella/compare/@thi.ng/cache@0.2.19...@thi.ng/cache@0.2.20) (2018-09-03) diff --git a/packages/cache/package.json b/packages/cache/package.json index 027d967060..681845be3b 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/cache", - "version": "0.2.20", + "version": "0.2.21", "description": "In-memory cache implementations with ES6 Map-like API and different eviction strategies", "main": "./index.js", "typings": "./index.d.ts", @@ -29,8 +29,8 @@ }, "dependencies": { "@thi.ng/api": "^4.1.0", - "@thi.ng/dcons": "^1.1.3", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/dcons": "^1.1.4", + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "cache", diff --git a/packages/csp/CHANGELOG.md b/packages/csp/CHANGELOG.md index a0f29314ca..b6821b51e1 100644 --- a/packages/csp/CHANGELOG.md +++ b/packages/csp/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.3.60](https://github.com/thi-ng/umbrella/compare/@thi.ng/csp@0.3.59...@thi.ng/csp@0.3.60) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/csp + ## [0.3.59](https://github.com/thi-ng/umbrella/compare/@thi.ng/csp@0.3.58...@thi.ng/csp@0.3.59) (2018-09-03) diff --git a/packages/csp/package.json b/packages/csp/package.json index 0491fd556b..b5a52b4e6e 100644 --- a/packages/csp/package.json +++ b/packages/csp/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/csp", - "version": "0.3.59", + "version": "0.3.60", "description": "ES6 promise based CSP implementation", "main": "./index.js", "typings": "./index.d.ts", @@ -34,9 +34,9 @@ "dependencies": { "@thi.ng/api": "^4.1.0", "@thi.ng/checks": "^1.5.7", - "@thi.ng/dcons": "^1.1.3", + "@thi.ng/dcons": "^1.1.4", "@thi.ng/errors": "^0.1.6", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "async", diff --git a/packages/dcons/CHANGELOG.md b/packages/dcons/CHANGELOG.md index dc8ec3084b..1b15a91e9b 100644 --- a/packages/dcons/CHANGELOG.md +++ b/packages/dcons/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.1.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/dcons@1.1.3...@thi.ng/dcons@1.1.4) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/dcons + ## [1.1.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/dcons@1.1.2...@thi.ng/dcons@1.1.3) (2018-09-03) diff --git a/packages/dcons/package.json b/packages/dcons/package.json index 56878db9f1..71d2473f97 100644 --- a/packages/dcons/package.json +++ b/packages/dcons/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/dcons", - "version": "1.1.3", + "version": "1.1.4", "description": "Comprehensive doubly linked list structure w/ iterator support", "main": "./index.js", "typings": "./index.d.ts", @@ -33,7 +33,7 @@ "@thi.ng/compare": "^0.1.6", "@thi.ng/equiv": "^0.1.7", "@thi.ng/errors": "^0.1.6", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "datastructure", diff --git a/packages/dgraph/CHANGELOG.md b/packages/dgraph/CHANGELOG.md index b092392b18..dbbd718511 100644 --- a/packages/dgraph/CHANGELOG.md +++ b/packages/dgraph/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.2.16](https://github.com/thi-ng/umbrella/compare/@thi.ng/dgraph@0.2.15...@thi.ng/dgraph@0.2.16) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/dgraph + ## [0.2.15](https://github.com/thi-ng/umbrella/compare/@thi.ng/dgraph@0.2.14...@thi.ng/dgraph@0.2.15) (2018-09-03) diff --git a/packages/dgraph/package.json b/packages/dgraph/package.json index 704963f7ef..1b2ce6de74 100644 --- a/packages/dgraph/package.json +++ b/packages/dgraph/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/dgraph", - "version": "0.2.15", + "version": "0.2.16", "description": "Type-agnostic directed acyclic graph (DAG) & graph operations", "main": "./index.js", "typings": "./index.d.ts", @@ -29,10 +29,10 @@ }, "dependencies": { "@thi.ng/api": "^4.1.0", - "@thi.ng/associative": "^0.6.3", + "@thi.ng/associative": "^0.6.4", "@thi.ng/equiv": "^0.1.7", "@thi.ng/errors": "^0.1.6", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "data structure", diff --git a/packages/hdom-components/CHANGELOG.md b/packages/hdom-components/CHANGELOG.md index a117d898d4..b0bfa4da5d 100644 --- a/packages/hdom-components/CHANGELOG.md +++ b/packages/hdom-components/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [2.2.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/hdom-components@2.2.2...@thi.ng/hdom-components@2.2.3) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/hdom-components + ## [2.2.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/hdom-components@2.2.1...@thi.ng/hdom-components@2.2.2) (2018-09-03) diff --git a/packages/hdom-components/package.json b/packages/hdom-components/package.json index 6bec9a440f..ea14e8c951 100644 --- a/packages/hdom-components/package.json +++ b/packages/hdom-components/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/hdom-components", - "version": "2.2.2", + "version": "2.2.3", "description": "Raw, skinnable UI & SVG components for @thi.ng/hdom", "main": "./index.js", "typings": "./index.d.ts", @@ -30,7 +30,7 @@ "dependencies": { "@thi.ng/api": "^4.1.0", "@thi.ng/checks": "^1.5.7", - "@thi.ng/transducers": "^2.0.3", + "@thi.ng/transducers": "^2.0.4", "@types/webgl2": "^0.0.4" }, "keywords": [ diff --git a/packages/hiccup-css/CHANGELOG.md b/packages/hiccup-css/CHANGELOG.md index f5bc7378d0..6ab50c8969 100644 --- a/packages/hiccup-css/CHANGELOG.md +++ b/packages/hiccup-css/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.2.19](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup-css@0.2.18...@thi.ng/hiccup-css@0.2.19) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/hiccup-css + ## [0.2.18](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup-css@0.2.17...@thi.ng/hiccup-css@0.2.18) (2018-09-03) diff --git a/packages/hiccup-css/package.json b/packages/hiccup-css/package.json index d3e18fb28c..5bf048a5f8 100644 --- a/packages/hiccup-css/package.json +++ b/packages/hiccup-css/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/hiccup-css", - "version": "0.2.18", + "version": "0.2.19", "description": "CSS from nested JS data structures", "main": "./index.js", "typings": "./index.d.ts", @@ -31,7 +31,7 @@ "@thi.ng/api": "^4.1.0", "@thi.ng/checks": "^1.5.7", "@thi.ng/errors": "^0.1.6", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "clojure", diff --git a/packages/iges/CHANGELOG.md b/packages/iges/CHANGELOG.md index 8bef935a3f..df5bfdd713 100644 --- a/packages/iges/CHANGELOG.md +++ b/packages/iges/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.2.9](https://github.com/thi-ng/umbrella/compare/@thi.ng/iges@0.2.8...@thi.ng/iges@0.2.9) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/iges + ## [0.2.8](https://github.com/thi-ng/umbrella/compare/@thi.ng/iges@0.2.7...@thi.ng/iges@0.2.8) (2018-09-03) diff --git a/packages/iges/package.json b/packages/iges/package.json index 0252b55538..d7f3ba5897 100644 --- a/packages/iges/package.json +++ b/packages/iges/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/iges", - "version": "0.2.8", + "version": "0.2.9", "description": "IGES 5.3 serializer for (currently only) polygonal geometry, both open & closed", "main": "./index.js", "typings": "./index.d.ts", @@ -30,8 +30,8 @@ "dependencies": { "@thi.ng/api": "^4.1.0", "@thi.ng/defmulti": "^0.3.8", - "@thi.ng/strings": "^0.3.1", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/strings": "^0.3.2", + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "CAD", diff --git a/packages/iterators/CHANGELOG.md b/packages/iterators/CHANGELOG.md index 58f335d247..d6638f4737 100644 --- a/packages/iterators/CHANGELOG.md +++ b/packages/iterators/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [4.1.25](https://github.com/thi-ng/umbrella/compare/@thi.ng/iterators@4.1.24...@thi.ng/iterators@4.1.25) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/iterators + ## [4.1.24](https://github.com/thi-ng/umbrella/compare/@thi.ng/iterators@4.1.23...@thi.ng/iterators@4.1.24) (2018-09-03) diff --git a/packages/iterators/package.json b/packages/iterators/package.json index 4cfbfc137c..0b3a0ddf38 100644 --- a/packages/iterators/package.json +++ b/packages/iterators/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/iterators", - "version": "4.1.24", + "version": "4.1.25", "description": "clojure.core inspired, composable ES6 iterators & generators", "main": "./index.js", "typings": "./index.d.ts", @@ -29,7 +29,7 @@ }, "dependencies": { "@thi.ng/api": "^4.1.0", - "@thi.ng/dcons": "^1.1.3", + "@thi.ng/dcons": "^1.1.4", "@thi.ng/errors": "^0.1.6" }, "keywords": [ diff --git a/packages/memoize/CHANGELOG.md b/packages/memoize/CHANGELOG.md index 432ab995d3..92cd3e297d 100644 --- a/packages/memoize/CHANGELOG.md +++ b/packages/memoize/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +# [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/memoize@0.1.2...@thi.ng/memoize@0.2.0) (2018-09-06) + + +### Features + +* **memoize:** add defonce() ([61bed88](https://github.com/thi-ng/umbrella/commit/61bed88)) + + + + ## [0.1.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/memoize@0.1.1...@thi.ng/memoize@0.1.2) (2018-09-01) diff --git a/packages/memoize/package.json b/packages/memoize/package.json index a2bbbbd396..4d5d726525 100644 --- a/packages/memoize/package.json +++ b/packages/memoize/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/memoize", - "version": "0.1.2", + "version": "0.2.0", "description": "Function memoization with configurable caches", "main": "./index.js", "typings": "./index.d.ts", diff --git a/packages/memoize/src/api.ts b/packages/memoize/src/api.ts index fadebca20c..0b193fac5e 100644 --- a/packages/memoize/src/api.ts +++ b/packages/memoize/src/api.ts @@ -1,3 +1,4 @@ +export type Fn0 = () => T; export type Fn1 = (a: A) => B; export type Fn2 = (a: A, b: B) => C; export type Fn3 = (a: A, b: B, c: C) => D; diff --git a/packages/memoize/src/defonce.ts b/packages/memoize/src/defonce.ts new file mode 100644 index 0000000000..3546379952 --- /dev/null +++ b/packages/memoize/src/defonce.ts @@ -0,0 +1,23 @@ +import { Fn0 } from "@thi.ng/memoize/src/api"; + +const cache: any = {}; + +/** + * Lightweight named singleton factory, intended for hot-module + * replacement situations. Takes a (preferably globally unique) `id` and + * `factory` function. If there's no value defined for `id` yet, calls + * `factory` to produce the singleton value and caches it. Returns + * singleton value. + * + * Note: All created values will remain in the private cache until the + * JS process terminates or this module itself has been reloaded (though + * the latter shouldn't happen in an HMR workflow). + * + * @param id + * @param factory + */ +export function defonce(id: string, factory: Fn0): T { + return cache.hasOwnProperty(id) ? + cache[id] : + (cache[id] = factory()); +} diff --git a/packages/memoize/src/index.ts b/packages/memoize/src/index.ts index c5efad54c6..feb4b21ac6 100644 --- a/packages/memoize/src/index.ts +++ b/packages/memoize/src/index.ts @@ -1,4 +1,5 @@ export * from "./api"; +export * from "./defonce"; export * from "./memoize"; export * from "./memoize1"; export * from "./memoizej"; diff --git a/packages/range-coder/CHANGELOG.md b/packages/range-coder/CHANGELOG.md index 2f1c7cfa16..185e50a38e 100644 --- a/packages/range-coder/CHANGELOG.md +++ b/packages/range-coder/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.1.9](https://github.com/thi-ng/umbrella/compare/@thi.ng/range-coder@0.1.8...@thi.ng/range-coder@0.1.9) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/range-coder + ## [0.1.8](https://github.com/thi-ng/umbrella/compare/@thi.ng/range-coder@0.1.7...@thi.ng/range-coder@0.1.8) (2018-09-03) diff --git a/packages/range-coder/package.json b/packages/range-coder/package.json index b740d72ca8..8bade77962 100644 --- a/packages/range-coder/package.json +++ b/packages/range-coder/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/range-coder", - "version": "0.1.8", + "version": "0.1.9", "description": "Binary data range encoder / decoder", "main": "./index.js", "typings": "./index.d.ts", @@ -20,7 +20,7 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@thi.ng/transducers": "^2.0.3", + "@thi.ng/transducers": "^2.0.4", "@types/mocha": "^5.2.5", "@types/node": "^10.5.5", "mocha": "^5.2.0", diff --git a/packages/rstream-csp/CHANGELOG.md b/packages/rstream-csp/CHANGELOG.md index 81b3d6a13a..d172029ec8 100644 --- a/packages/rstream-csp/CHANGELOG.md +++ b/packages/rstream-csp/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.1.104](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-csp@0.1.103...@thi.ng/rstream-csp@0.1.104) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/rstream-csp + ## [0.1.103](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-csp@0.1.102...@thi.ng/rstream-csp@0.1.103) (2018-09-03) diff --git a/packages/rstream-csp/package.json b/packages/rstream-csp/package.json index 41df01e799..810b5a3124 100644 --- a/packages/rstream-csp/package.json +++ b/packages/rstream-csp/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/rstream-csp", - "version": "0.1.103", + "version": "0.1.104", "description": "@thi.ng/csp bridge module for @thi.ng/rstream", "main": "./index.js", "typings": "./index.d.ts", @@ -28,8 +28,8 @@ "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/csp": "^0.3.59", - "@thi.ng/rstream": "^1.11.9" + "@thi.ng/csp": "^0.3.60", + "@thi.ng/rstream": "^1.11.10" }, "keywords": [ "bridge", diff --git a/packages/rstream-dot/CHANGELOG.md b/packages/rstream-dot/CHANGELOG.md index 3ee9a67ff1..6c1aab9c7b 100644 --- a/packages/rstream-dot/CHANGELOG.md +++ b/packages/rstream-dot/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.2.43](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-dot@0.2.42...@thi.ng/rstream-dot@0.2.43) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/rstream-dot + ## [0.2.42](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-dot@0.2.41...@thi.ng/rstream-dot@0.2.42) (2018-09-03) diff --git a/packages/rstream-dot/package.json b/packages/rstream-dot/package.json index 7689a5beda..bf8b275723 100644 --- a/packages/rstream-dot/package.json +++ b/packages/rstream-dot/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/rstream-dot", - "version": "0.2.42", + "version": "0.2.43", "description": "Graphviz DOT conversion of @thi.ng/rstream dataflow graph topologies", "main": "./index.js", "typings": "./index.d.ts", @@ -28,7 +28,7 @@ "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/rstream": "^1.11.9" + "@thi.ng/rstream": "^1.11.10" }, "keywords": [ "conversion", diff --git a/packages/rstream-gestures/CHANGELOG.md b/packages/rstream-gestures/CHANGELOG.md index a78589c4fe..2f49744860 100644 --- a/packages/rstream-gestures/CHANGELOG.md +++ b/packages/rstream-gestures/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.5.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-gestures@0.5.4...@thi.ng/rstream-gestures@0.5.5) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/rstream-gestures + ## [0.5.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-gestures@0.5.3...@thi.ng/rstream-gestures@0.5.4) (2018-09-03) diff --git a/packages/rstream-gestures/package.json b/packages/rstream-gestures/package.json index 203e43fc17..6fb6310ef3 100644 --- a/packages/rstream-gestures/package.json +++ b/packages/rstream-gestures/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/rstream-gestures", - "version": "0.5.4", + "version": "0.5.5", "description": "Unified mouse, mouse wheel & single-touch event stream abstraction", "main": "./index.js", "typings": "./index.d.ts", @@ -29,8 +29,8 @@ }, "dependencies": { "@thi.ng/api": "^4.1.0", - "@thi.ng/rstream": "^1.11.9", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/rstream": "^1.11.10", + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "dataflow", diff --git a/packages/rstream-graph/CHANGELOG.md b/packages/rstream-graph/CHANGELOG.md index 17bdcf76b7..1f22797ccc 100644 --- a/packages/rstream-graph/CHANGELOG.md +++ b/packages/rstream-graph/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [2.1.29](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-graph@2.1.28...@thi.ng/rstream-graph@2.1.29) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/rstream-graph + ## [2.1.28](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-graph@2.1.27...@thi.ng/rstream-graph@2.1.28) (2018-09-03) diff --git a/packages/rstream-graph/package.json b/packages/rstream-graph/package.json index b590bde038..4cbdcd60d6 100644 --- a/packages/rstream-graph/package.json +++ b/packages/rstream-graph/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/rstream-graph", - "version": "2.1.28", + "version": "2.1.29", "description": "Declarative dataflow graph construction for @thi.ng/rstream", "main": "./index.js", "typings": "./index.d.ts", @@ -33,8 +33,8 @@ "@thi.ng/errors": "^0.1.6", "@thi.ng/paths": "^1.6.0", "@thi.ng/resolve-map": "^3.0.10", - "@thi.ng/rstream": "^1.11.9", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/rstream": "^1.11.10", + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "compute", diff --git a/packages/rstream-log/CHANGELOG.md b/packages/rstream-log/CHANGELOG.md index e09080ba8b..8dff0415ab 100644 --- a/packages/rstream-log/CHANGELOG.md +++ b/packages/rstream-log/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.0.55](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-log@1.0.54...@thi.ng/rstream-log@1.0.55) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/rstream-log + ## [1.0.54](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-log@1.0.53...@thi.ng/rstream-log@1.0.54) (2018-09-03) diff --git a/packages/rstream-log/package.json b/packages/rstream-log/package.json index 51f20c47cb..bf664711e1 100644 --- a/packages/rstream-log/package.json +++ b/packages/rstream-log/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/rstream-log", - "version": "1.0.54", + "version": "1.0.55", "description": "Structured, multilevel & hierarchical loggers based on @thi.ng/rstream", "main": "./index.js", "typings": "./index.d.ts", @@ -31,8 +31,8 @@ "@thi.ng/api": "^4.1.0", "@thi.ng/checks": "^1.5.7", "@thi.ng/errors": "^0.1.6", - "@thi.ng/rstream": "^1.11.9", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/rstream": "^1.11.10", + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "ES6", diff --git a/packages/rstream-query/CHANGELOG.md b/packages/rstream-query/CHANGELOG.md index b85239d74d..f904ca4b8d 100644 --- a/packages/rstream-query/CHANGELOG.md +++ b/packages/rstream-query/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.3.42](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-query@0.3.41...@thi.ng/rstream-query@0.3.42) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/rstream-query + ## [0.3.41](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-query@0.3.40...@thi.ng/rstream-query@0.3.41) (2018-09-03) diff --git a/packages/rstream-query/package.json b/packages/rstream-query/package.json index 085fd14620..68cc7489bf 100644 --- a/packages/rstream-query/package.json +++ b/packages/rstream-query/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/rstream-query", - "version": "0.3.41", + "version": "0.3.42", "description": "@thi.ng/rstream based triple store & reactive query engine", "main": "./index.js", "typings": "./index.d.ts", @@ -29,13 +29,13 @@ }, "dependencies": { "@thi.ng/api": "^4.1.0", - "@thi.ng/associative": "^0.6.3", + "@thi.ng/associative": "^0.6.4", "@thi.ng/checks": "^1.5.7", "@thi.ng/equiv": "^0.1.7", "@thi.ng/errors": "^0.1.6", - "@thi.ng/rstream": "^1.11.9", - "@thi.ng/rstream-dot": "^0.2.42", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/rstream": "^1.11.10", + "@thi.ng/rstream-dot": "^0.2.43", + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "dataflow", diff --git a/packages/rstream/CHANGELOG.md b/packages/rstream/CHANGELOG.md index 66d35873e0..6f75f12d00 100644 --- a/packages/rstream/CHANGELOG.md +++ b/packages/rstream/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.11.10](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream@1.11.9...@thi.ng/rstream@1.11.10) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/rstream + ## [1.11.9](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream@1.11.8...@thi.ng/rstream@1.11.9) (2018-09-03) diff --git a/packages/rstream/package.json b/packages/rstream/package.json index c531a16a3e..f3115aba19 100644 --- a/packages/rstream/package.json +++ b/packages/rstream/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/rstream", - "version": "1.11.9", + "version": "1.11.10", "description": "Reactive multi-tap streams, dataflow & transformation pipeline constructs", "main": "./index.js", "typings": "./index.d.ts", @@ -29,12 +29,12 @@ }, "dependencies": { "@thi.ng/api": "^4.1.0", - "@thi.ng/associative": "^0.6.3", + "@thi.ng/associative": "^0.6.4", "@thi.ng/atom": "^1.5.1", "@thi.ng/checks": "^1.5.7", "@thi.ng/errors": "^0.1.6", "@thi.ng/paths": "^1.6.0", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "datastructure", diff --git a/packages/sax/CHANGELOG.md b/packages/sax/CHANGELOG.md index bcca7da1b3..3dbc254a9e 100644 --- a/packages/sax/CHANGELOG.md +++ b/packages/sax/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.3.18](https://github.com/thi-ng/umbrella/compare/@thi.ng/sax@0.3.17...@thi.ng/sax@0.3.18) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/sax + ## [0.3.17](https://github.com/thi-ng/umbrella/compare/@thi.ng/sax@0.3.16...@thi.ng/sax@0.3.17) (2018-09-03) diff --git a/packages/sax/package.json b/packages/sax/package.json index beffe800f9..bcfda1f96b 100644 --- a/packages/sax/package.json +++ b/packages/sax/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/sax", - "version": "0.3.17", + "version": "0.3.18", "description": "Transducer-based, SAX-like, non-validating, speedy & tiny XML parser", "main": "./index.js", "typings": "./index.d.ts", @@ -29,8 +29,8 @@ }, "dependencies": { "@thi.ng/api": "^4.1.0", - "@thi.ng/transducers": "^2.0.3", - "@thi.ng/transducers-fsm": "^0.2.16" + "@thi.ng/transducers": "^2.0.4", + "@thi.ng/transducers-fsm": "^0.2.17" }, "keywords": [ "ES6", diff --git a/packages/strings/CHANGELOG.md b/packages/strings/CHANGELOG.md index ff8ce77449..a5ddcb1b47 100644 --- a/packages/strings/CHANGELOG.md +++ b/packages/strings/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.3.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@0.3.1...@thi.ng/strings@0.3.2) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/strings + ## [0.3.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@0.3.0...@thi.ng/strings@0.3.1) (2018-09-01) diff --git a/packages/strings/package.json b/packages/strings/package.json index 93b848ff0d..659ca6c45d 100644 --- a/packages/strings/package.json +++ b/packages/strings/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/strings", - "version": "0.3.1", + "version": "0.3.2", "description": "Various string formatting & utility functions", "main": "./index.js", "typings": "./index.d.ts", @@ -28,7 +28,7 @@ "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/memoize": "^0.1.2" + "@thi.ng/memoize": "^0.2.0" }, "keywords": [ "ES6", diff --git a/packages/transducers-fsm/CHANGELOG.md b/packages/transducers-fsm/CHANGELOG.md index 04031cad38..8055a42bde 100644 --- a/packages/transducers-fsm/CHANGELOG.md +++ b/packages/transducers-fsm/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.2.17](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-fsm@0.2.16...@thi.ng/transducers-fsm@0.2.17) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/transducers-fsm + ## [0.2.16](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-fsm@0.2.15...@thi.ng/transducers-fsm@0.2.16) (2018-09-03) diff --git a/packages/transducers-fsm/package.json b/packages/transducers-fsm/package.json index b35d3bbaf1..a6cd9a559d 100644 --- a/packages/transducers-fsm/package.json +++ b/packages/transducers-fsm/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/transducers-fsm", - "version": "0.2.16", + "version": "0.2.17", "description": "Transducer-based Finite State Machine transformer", "main": "./index.js", "typings": "./index.d.ts", @@ -29,7 +29,7 @@ }, "dependencies": { "@thi.ng/api": "^4.1.0", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "ES6", diff --git a/packages/transducers-hdom/CHANGELOG.md b/packages/transducers-hdom/CHANGELOG.md index 363df31ee0..108e7f93ef 100644 --- a/packages/transducers-hdom/CHANGELOG.md +++ b/packages/transducers-hdom/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.0.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-hdom@1.0.4...@thi.ng/transducers-hdom@1.0.5) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/transducers-hdom + ## [1.0.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-hdom@1.0.3...@thi.ng/transducers-hdom@1.0.4) (2018-09-03) diff --git a/packages/transducers-hdom/package.json b/packages/transducers-hdom/package.json index 3109452eb3..3d22b86fe1 100644 --- a/packages/transducers-hdom/package.json +++ b/packages/transducers-hdom/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/transducers-hdom", - "version": "1.0.4", + "version": "1.0.5", "description": "Transducer based UI updater for @thi.ng/hdom", "main": "./index.js", "typings": "./index.d.ts", @@ -30,7 +30,7 @@ "dependencies": { "@thi.ng/checks": "^1.5.7", "@thi.ng/hdom": "^4.0.4", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "diff", diff --git a/packages/transducers-stats/CHANGELOG.md b/packages/transducers-stats/CHANGELOG.md index 9e2bc7d65f..9f5dbe17cb 100644 --- a/packages/transducers-stats/CHANGELOG.md +++ b/packages/transducers-stats/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.4.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-stats@0.4.3...@thi.ng/transducers-stats@0.4.4) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/transducers-stats + ## [0.4.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-stats@0.4.2...@thi.ng/transducers-stats@0.4.3) (2018-09-03) diff --git a/packages/transducers-stats/package.json b/packages/transducers-stats/package.json index fda9e456c6..8ccf6bcc5c 100644 --- a/packages/transducers-stats/package.json +++ b/packages/transducers-stats/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/transducers-stats", - "version": "0.4.3", + "version": "0.4.4", "description": "Transducers for statistical / technical analysis", "main": "./index.js", "typings": "./index.d.ts", @@ -28,9 +28,9 @@ "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/dcons": "^1.1.3", + "@thi.ng/dcons": "^1.1.4", "@thi.ng/errors": "^0.1.6", - "@thi.ng/transducers": "^2.0.3" + "@thi.ng/transducers": "^2.0.4" }, "keywords": [ "ES6", diff --git a/packages/transducers/CHANGELOG.md b/packages/transducers/CHANGELOG.md index a70491f8a0..fd675814fc 100644 --- a/packages/transducers/CHANGELOG.md +++ b/packages/transducers/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [2.0.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers@2.0.3...@thi.ng/transducers@2.0.4) (2018-09-06) + + + + +**Note:** Version bump only for package @thi.ng/transducers + ## [2.0.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers@2.0.2...@thi.ng/transducers@2.0.3) (2018-09-03) diff --git a/packages/transducers/package.json b/packages/transducers/package.json index 81db01b1da..5ebe9ad017 100644 --- a/packages/transducers/package.json +++ b/packages/transducers/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/transducers", - "version": "2.0.3", + "version": "2.0.4", "description": "Lightweight transducer implementations for ES6 / TypeScript", "main": "./index.js", "typings": "./index.d.ts", @@ -34,7 +34,7 @@ "@thi.ng/compose": "^0.1.1", "@thi.ng/equiv": "^0.1.7", "@thi.ng/errors": "^0.1.6", - "@thi.ng/strings": "^0.3.1" + "@thi.ng/strings": "^0.3.2" }, "keywords": [ "ES6", diff --git a/packages/vectors/CHANGELOG.md b/packages/vectors/CHANGELOG.md index 8ba0863472..20ed2169a7 100644 --- a/packages/vectors/CHANGELOG.md +++ b/packages/vectors/CHANGELOG.md @@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +# [1.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@0.6.0...@thi.ng/vectors@1.0.0) (2018-09-05) + + +### Features + +* **vectors:** add immutable vec2/3/4 ops ([a3c0407](https://github.com/thi-ng/umbrella/commit/a3c0407)) +* **vectors:** add/update transformVectors*(), update types ([2eec700](https://github.com/thi-ng/umbrella/commit/2eec700)) + + +### BREAKING CHANGES + +* **vectors:** update transformVectors1/2() arg order + + + + # [0.6.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@0.5.3...@thi.ng/vectors@0.6.0) (2018-09-03) diff --git a/packages/vectors/README.md b/packages/vectors/README.md index ab0a2432f7..c866fa23b0 100644 --- a/packages/vectors/README.md +++ b/packages/vectors/README.md @@ -88,6 +88,15 @@ zero-copy vector operations on sections of larger buffers. The default start index is 0, default stride 1. See examples below and [tests](https://github.com/thi-ng/umbrella/tree/master/packages/vectors/test/). +Naming conventions (suffixes): + +- `N` = uniform: 2nd or 3rd arg is a scalar which will be used for all + vector components, e.g. `setN3([], 0) => [0, 0, 0]` +- `S` = scalar: args are individual scalar values, + e.g. `setS3([], 10, 20, 30) => [10, 20, 30]` +- `o` = output: operation writes to separate output vector (1st arg), e.g. + `add2o([], [1,2], [10, 20])` + | Operation | Generic | 2D | 3D | 4D | |---------------------------------|--------------|-----------------------|---------------------|------------------| | Get vector (dense copy) | `get` | `get2` | `get3` | `get4` | @@ -98,18 +107,28 @@ start index is 0, default stride 1. See examples below and | Swap vectors | | `swap2` | `swap3` | `swap4` | | Equality (w/ epsilon) | `eqDelta` | `eqDelta2` | `eqDelta3` | `eqDelta4` | | Vector addition | `add` | `add2` | `add3` | `add4` | +| | | `add2o` | `add3o` | `add4o` | | Vector subtraction | `sub` | `sub2` | `sub3` | `sub4` | +| | | `sub2o` | `sub3o` | `sub4o` | | Vector multiplication | `mul` | `mul2` | `mul3` | `mul4` | +| | | `mul2o` | `mul3o` | `mul4o` | | Vector division | `div` | `div2` | `div3` | `div4` | +| | | `div2o` | `div3o` | `div4o` | | Uniform scalar addition | `addN` | `addN2` | `addN3` | `addN4` | +| | | `addN2o` | `addN3o` | `addN4o` | | Uniform scalar subtraction | `subN` | `subN2` | `subN3` | `subN4` | +| | | `subN2o` | `subN3o` | `subN4o` | | Uniform scalar multiply | `mulN` | `mulN2` | `mulN3` | `mulN4` | +| | | `mulN2o` | `mulN3o` | `mulN4o` | | Uniform scalar multiply | `divN` | `divN2` | `divN3` | `divN4` | +| | | `divN2o` | `divN3o` | `divN4o` | | Vector negation | `neg` | `neg2` | `neg3` | `neg4` | | Multiply-add vectors | `madd` | `madd2` | `madd3` | `madd4` | | Multiply-add scalar | `maddN` | `maddN2` | `maddN3` | `maddN4` | | Linear interpolation (vector) | `mix` | `mix2` | `mix3` | `mix4` | +| | | `mix2o` | `mix3o` | `mix4o` | | Linear interpolation (uniform) | `mixN` | `mixN2` | `mixN3` | `mixN4` | +| | | `mixN2o` | `mixN3o` | `mixN4o` | | Bilinear interpolation* | | `mixBilinear2` | `mixBilinear3` | `mixBilinear4` | | Dot product | `dot` | `dot2` | `dot3` | `dot4` | | Cross product | | `cross2` | `cross3` | | diff --git a/packages/vectors/bench/index.js b/packages/vectors/bench/index.js new file mode 100644 index 0000000000..94fafa9a84 --- /dev/null +++ b/packages/vectors/bench/index.js @@ -0,0 +1,56 @@ +const Benchmark = require("benchmark"); +const vec = require("../index"); + +const setS2Lib = (buf, n) => { + n *= 2; + for (let i = 0; i < n; i += 2) { + vec.setS2(buf, i, i + 1, i); + } + return buf; +}; + +const setS2Plain = (n) => { + const res = new Array(n); + for (let i = 0; i < n; i++) { + res[i] = [i, i + 1]; + } + return res; +}; + +const op2Lib = (buf, n, op, v) => + vec.transformVectors1(op, setS2Lib(buf, n), v, n, 0, 0, 1, 1, 2); + +const op2Plain = (n, op, v) => { + const res = setS2Plain(n); + for (let i = 0; i < n; i++) { + op(res[i], v); + } + return res; +}; + +const add2 = (a, b) => ( + a[0] += b[0], + a[1] += b[1], + a +); + +new Benchmark.Suite() + .add({ name: "set2 1k (lib, array)", fn: () => setS2Lib(new Array(2 * 1024), 1024) }) + .add({ name: "set2 1k (vanilla)", fn: () => setS2Plain(1024) }) + .add({ name: "set2 4k (lib, array)", fn: () => setS2Lib(new Array(2 * 4 * 1024), 4 * 1024) }) + .add({ name: "set2 4k (vanilla)", fn: () => setS2Plain(4 * 1024) }) + .add({ name: "add2 1k (lib, array)", fn: () => op2Lib(new Array(2 * 1024), 1024, vec.add2, [10, 20]) }) + .add({ name: "add2 1k (lib, f32)", fn: () => op2Lib(new Float32Array(2 * 1024), 1024, vec.add2, [10, 20]) }) + .add({ name: "add2 1k (lib, f64)", fn: () => op2Lib(new Float64Array(2 * 1024), 1024, vec.add2, [10, 20]) }) + .add({ name: "add2 1k (vanilla)", fn: () => op2Plain(1024, add2, [10, 20]) }) + .add({ name: "add2 4k (lib, array)", fn: () => op2Lib(new Array(2 * 4 * 1024), 4 * 1024, vec.add2, [10, 20]) }) + .add({ name: "add2 4k (lib, f32)", fn: () => op2Lib(new Float32Array(2 * 4 * 1024), 4 * 1024, vec.add2, [10, 20]) }) + .add({ name: "add2 4k (lib, f64)", fn: () => op2Lib(new Float64Array(2 * 4 * 1024), 4 * 1024, vec.add2, [10, 20]) }) + .add({ name: "add2 4k (vanilla)", fn: () => op2Plain(4 * 1024, add2, [10, 20]) }) + .on("cycle", (event) => + console.log( + event.target.toString(), + `mean: ${(event.target.stats.mean * 1e3).toFixed(5)}sec` + ) + ) + .run({ "async": false }); \ No newline at end of file diff --git a/packages/vectors/package.json b/packages/vectors/package.json index eae6af4ca3..9c39e2abab 100644 --- a/packages/vectors/package.json +++ b/packages/vectors/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/vectors", - "version": "0.6.0", + "version": "1.0.0", "description": "Vector algebra for fixed & variable sizes, memory mapped, flexible layouts", "main": "./index.js", "typings": "./index.d.ts", @@ -22,6 +22,7 @@ "devDependencies": { "@types/mocha": "^5.2.5", "@types/node": "^10.5.5", + "benchmark": "^2.1.4", "mocha": "^5.2.0", "nyc": "^12.0.2", "typedoc": "^0.11.1", diff --git a/packages/vectors/src/api.ts b/packages/vectors/src/api.ts index 9b0f209618..1cb3389c74 100644 --- a/packages/vectors/src/api.ts +++ b/packages/vectors/src/api.ts @@ -10,23 +10,29 @@ export type ReadonlyMat = ArrayLike & Iterable; * A vector operation involving only a single vector. The vector might * be modified. */ -export type VecOp1 = (v: Vec, i: number, s?: number) => T; +export type VecOp1 = (v: Vec, i?: number, s?: number) => T; /** * A vector operation involving two vectors. The first vector might be * modified. */ -export type VecOp2 = (a: Vec, b: ReadonlyVec, ia: number, ib: number, sa?: number, sb?: number) => T; +export type VecOp2 = (a: Vec, b: ReadonlyVec, ia?: number, ib?: number, sa?: number, sb?: number) => T; + +/** + * A vector operation involving input readonly two vectors and writing + * result to an output vector `out`. + */ +export type VecOp2o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io?: number, ia?: number, ib?: number, so?: number, sa?: number, sb?: number) => T; /** * A readonly vector operation involving only a single vector. */ -export type ReadonlyVecOp1 = (v: ReadonlyVec, i: number, s?: number) => T; +export type ReadonlyVecOp1 = (v: ReadonlyVec, i?: number, s?: number) => T; /** * A readonly vector operation involving two vectors. */ -export type ReadonlyVecOp2 = (a: ReadonlyVec, b: ReadonlyVec, ia: number, ib: number, sa?: number, sb?: number) => T; +export type ReadonlyVecOp2 = (a: ReadonlyVec, b: ReadonlyVec, ia?: number, ib?: number, sa?: number, sb?: number) => T; export interface IVec { buf: Vec; diff --git a/packages/vectors/src/common.ts b/packages/vectors/src/common.ts index ac4a879b65..ee99b81761 100644 --- a/packages/vectors/src/common.ts +++ b/packages/vectors/src/common.ts @@ -1,10 +1,10 @@ -import { ReadonlyVec, Vec, VecOp2 } from "./api"; +import { ReadonlyVec, Vec, VecOp2, VecOp2o, ReadonlyVecOp1 } from "./api"; import { EPS, eqDelta1 } from "./math"; -export const x = (v: ReadonlyVec, i = 0, _?: number) => v[i]; -export const y = (v: ReadonlyVec, i = 0, s = 1) => v[i + s]; -export const z = (v: ReadonlyVec, i = 0, s = 1) => v[i + 2 * s]; -export const w = (v: ReadonlyVec, i = 0, s = 1) => v[i + 3 * s]; +export const x: ReadonlyVecOp1 = (v: ReadonlyVec, i = 0) => v[i]; +export const y: ReadonlyVecOp1 = (v: ReadonlyVec, i = 0, s = 1) => v[i + s]; +export const z: ReadonlyVecOp1 = (v: ReadonlyVec, i = 0, s = 1) => v[i + 2 * s]; +export const w: ReadonlyVecOp1 = (v: ReadonlyVec, i = 0, s = 1) => v[i + 3 * s]; /** * Applies vector op `fn` to all raw vectors in array `a`, using the @@ -25,23 +25,53 @@ export const w = (v: ReadonlyVec, i = 0, s = 1) => v[i + 3 * s]; * @param a vector array to process * @param b vector operand * @param num num elements + * @param esa element stride `a` * @param ia start index `a` * @param ib start index `b` * @param csa component stride `a` * @param csb component stride `b` - * @param esa element stride `a` */ export const transformVectors1 = ( fn: VecOp2, a: Vec, b: ReadonlyVec, num: number, - ia: number, ib: number, - csa: number, csb: number, - esa: number) => { + esa: number, + ia = 0, ib = 0, + csa = 1, csb = 1) => { for (; num > 0; num-- , ia += esa) { fn(a, b, ia, ib, csa, csb); } return a; }; +/** + * Similar to `transformVectors1`, but for ops which don't modify `a` or + * `b` and instead write result into given `out` vector, which is then + * also returned. + * + * @param fn + * @param out + * @param a + * @param b + * @param num + * @param eso + * @param esa + * @param io + * @param ia + * @param ib + * @param cso + * @param csa + * @param csb + */ +export const transformVectors1o = ( + fn: VecOp2o, out: Vec, a: ReadonlyVec, b: ReadonlyVec, num: number, + eso: number, esa: number, + io = 0, ia = 0, ib = 0, + cso = 1, csa = 1, csb = 1) => { + for (; num > 0; num-- , io += eso, ia += esa) { + fn(out, a, b, io, ia, ib, cso, csa, csb); + } + return out; +}; + /** * Similar to `transformVectors1` but also traverses vector `b` array, * i.e. applies `fn` to 1st vector of `a` and `b`, then to 2nd `a` and @@ -51,24 +81,55 @@ export const transformVectors1 = ( * @param a * @param b * @param n + * @param esa + * @param esb * @param ia * @param ib * @param csa * @param csb - * @param esa - * @param esb */ export const transformVectors2 = ( fn: VecOp2, a: Vec, b: ReadonlyVec, n: number, - ia: number, ib: number, - csa: number, csb: number, - esa: number, esb: number) => { + esa: number, esb: number, + ia = 0, ib = 0, + csa = 1, csb = 1) => { for (; n > 0; n-- , ia += esa, ib += esb) { fn(a, b, ia, ib, csa, csb); } return a; }; +/** + * Similar to `transformVectors2`, but for ops which don't modify `a` or + * `b` and instead write result into given `out` vector, which is then + * also returned. + * + * @param fn + * @param out + * @param a + * @param b + * @param n + * @param eso + * @param esa + * @param esb + * @param io + * @param ia + * @param ib + * @param cso + * @param csa + * @param csb + */ +export const transformVectors2o = ( + fn: VecOp2o, out: Vec, a: ReadonlyVec, b: ReadonlyVec, n: number, + eso: number, esa: number, esb: number, + io = 0, ia = 0, ib = 0, + cso = 1, csa = 1, csb = 1) => { + for (; n > 0; n-- , io += eso, ia += esa, ib += esb) { + fn(out, a, b, io, ia, ib, cso, csa, csb); + } + return out; +}; + /** * Takes 2 vectors `a` and `b`, their offsets and strides, returns true * if the first `n` elements are equal. diff --git a/packages/vectors/src/vec2.ts b/packages/vectors/src/vec2.ts index 83d86eb605..321a08eeb9 100644 --- a/packages/vectors/src/vec2.ts +++ b/packages/vectors/src/vec2.ts @@ -77,15 +77,27 @@ export const eqDelta2 = (a: ReadonlyVec, b: ReadonlyVec, eps = EPS, ia = 0, ib = export const add2 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => (a[ia] += b[ib], a[ia + sa] += b[ib + sb], a); -export const mul2 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => - (a[ia] *= b[ib], a[ia + sa] *= b[ib + sb], a); - export const sub2 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => (a[ia] -= b[ib], a[ia + sa] -= b[ib + sb], a); +export const mul2 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + (a[ia] *= b[ib], a[ia + sa] *= b[ib + sb], a); + export const div2 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => (a[ia] /= b[ib], a[ia + sa] /= b[ib + sb], a); +export const add2o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => + (out[io] = a[ia] + b[ib], out[io + so] = a[ia + sa] + b[ib + sb], out); + +export const sub2o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => + (out[io] = a[ia] - b[ib], out[io + so] = a[ia + sa] - b[ib + sb], out); + +export const mul2o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => + (out[io] = a[ia] * b[ib], out[io + so] = a[ia + sa] * b[ib + sb], out); + +export const div2o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => + (out[io] = a[ia] / b[ib], out[io + so] = a[ia + sa] / b[ib + sb], out); + export const addN2 = (a: Vec, n: number, ia = 0, sa = 1) => (a[ia] += n, a[ia + sa] += n, a); @@ -98,6 +110,18 @@ export const mulN2 = (a: Vec, n: number, ia = 0, sa = 1) => export const divN2 = (a: Vec, n: number, ia = 0, sa = 1) => (a[ia] /= n, a[ia + sa] /= n, a); +export const addN2o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => + (out[io] = a[ia] + n, out[io + so] = a[ia + sa] + n, out); + +export const subN2o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => + (out[io] = a[ia] - n, out[io + so] = a[ia + sa] - n, out); + +export const mulN2o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => + (out[io] = a[ia] * n, out[io + so] = a[ia + sa] * n, out); + +export const divN2o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => + (out[io] = a[ia] / n, out[io + so] = a[ia + sa] / n, out); + export const neg2 = (a: Vec, ia = 0, sa = 1) => mulN2(a, -1, ia, sa); @@ -167,6 +191,18 @@ export const mixN2 = (a: Vec, b: ReadonlyVec, n: number, ia = 0, ib = 0, sa = 1, a ); +export const mix2o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, t: ReadonlyVec, io = 0, ia = 0, ib = 0, it = 0, so = 1, sa = 1, sb = 1, st = 1) => ( + out[io] = a[ia] + (b[ib] - a[ia]) * t[it], + out[io + so] = a[ia + sa] + (b[ib + sb] - a[ia + sa]) * t[it + st], + out +); + +export const mixN2o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, n: number, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] + (b[ib] - a[ia]) * n, + out[io + so] = a[ia + sa] + (b[ib + sb] - a[ia + sa]) * n, + out +); + export const mixBilinear2 = ( a: Vec, b: ReadonlyVec, c: ReadonlyVec, d: ReadonlyVec, u: number, v: number, ia = 0, ib = 0, ic = 0, id = 0, @@ -363,6 +399,66 @@ export class Vec2 implements ); } + static add(a: Readonly, b: Readonly, out?: Vec2) { + !out && (out = new Vec2([])); + add2o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static sub(a: Readonly, b: Readonly, out?: Vec2) { + !out && (out = new Vec2([])); + sub2o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static mul(a: Readonly, b: Readonly, out?: Vec2) { + !out && (out = new Vec2([])); + mul2o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static div(a: Readonly, b: Readonly, out?: Vec2) { + !out && (out = new Vec2([])); + div2o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static addN(a: Readonly, n: number, out?: Vec2) { + !out && (out = new Vec2([])); + addN2o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static subN(a: Readonly, n: number, out?: Vec2) { + !out && (out = new Vec2([])); + subN2o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static mulN(a: Readonly, n: number, out?: Vec2) { + !out && (out = new Vec2([])); + mulN2o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static divN(a: Readonly, n: number, out?: Vec2) { + !out && (out = new Vec2([])); + divN2o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static mix(a: Readonly, b: Readonly, t: Readonly, out?: Vec2) { + !out && (out = new Vec2([])); + mix2o(out.buf, a.buf, b.buf, t.buf, out.i, a.i, b.i, t.i, out.s, a.s, b.s, t.s); + return out; + } + + static mixN(a: Readonly, b: Readonly, t: number, out?: Vec2) { + !out && (out = new Vec2([])); + mixN2o(out.buf, a.buf, b.buf, t, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + static readonly ZERO = Object.freeze(new Vec2(ZERO4)); static readonly ONE = Object.freeze(new Vec2(ONE4)); static readonly MIN = Object.freeze(new Vec2(MIN4)); diff --git a/packages/vectors/src/vec3.ts b/packages/vectors/src/vec3.ts index 512388dc71..582e468eb3 100644 --- a/packages/vectors/src/vec3.ts +++ b/packages/vectors/src/vec3.ts @@ -126,6 +126,34 @@ export const div3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => a ); +export const add3o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] + b[ib], + out[io + so] = a[ia + sa] + b[ib + sb], + out[io + 2 * so] = a[ia + 2 * sa] + b[ib + 2 * sb], + out +); + +export const sub3o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] - b[ib], + out[io + so] = a[ia + sa] - b[ib + sb], + out[io + 2 * so] = a[ia + 2 * sa] - b[ib + 2 * sb], + out +); + +export const mul3o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] * b[ib], + out[io + so] = a[ia + sa] * b[ib + sb], + out[io + 2 * so] = a[ia + 2 * sa] * b[ib + 2 * sb], + out +); + +export const div3o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] / b[ib], + out[io + so] = a[ia + sa] / b[ib + sb], + out[io + 2 * so] = a[ia + 2 * sa] / b[ib + 2 * sb], + out +); + export const addN3 = (a: Vec, n: number, ia = 0, sa = 1) => (a[ia] += n, a[ia + sa] += n, a[ia + 2 * sa] += n, a); @@ -138,6 +166,34 @@ export const mulN3 = (a: Vec, n: number, ia = 0, sa = 1) => export const divN3 = (a: Vec, n: number, ia = 0, sa = 1) => (a[ia] /= n, a[ia + sa] /= n, a[ia + 2 * sa] /= n, a); +export const addN3o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => ( + out[io] = a[ia] + n, + out[io + so] = a[ia + sa] + n, + out[io + 2 * so] = a[ia + 2 * sa] + n, + out +); + +export const subN3o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => ( + out[io] = a[ia] - n, + out[io + so] = a[ia + sa] - n, + out[io + 2 * so] = a[ia + 2 * sa] - n, + out +); + +export const mulN3o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => ( + out[io] = a[ia] * n, + out[io + so] = a[ia + sa] * n, + out[io + 2 * so] = a[ia + 2 * sa] * n, + out +); + +export const divN3o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => ( + out[io] = a[ia] / n, + out[io + so] = a[ia + sa] / n, + out[io + 2 * so] = a[ia + 2 * sa] / n, + out +); + export const neg3 = (a: Vec, ia = 0, sa = 1) => mulN3(a, -1, ia, sa); @@ -237,6 +293,20 @@ export const mixN3 = (a: Vec, b: ReadonlyVec, n: number, ia = 0, ib = 0, sa = 1, a ); +export const mix3o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, t: ReadonlyVec, io = 0, ia = 0, ib = 0, it = 0, so = 1, sa = 1, sb = 1, st = 1) => ( + out[io] = a[ia] + (b[ib] - a[ia]) * t[it], + out[io + so] = a[ia + sa] + (b[ib + sb] - a[ia + sa]) * t[it + st], + out[io + 2 * so] = a[ia + 2 * sa] + (b[ib + 2 * sb] - a[ia + 2 * sa]) * t[it + 2 * st], + out +); + +export const mixN3o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, n: number, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] + (b[ib] - a[ia]) * n, + out[io + so] = a[ia + sa] + (b[ib + sb] - a[ia + sa]) * n, + out[io + 2 * so] = a[ia + 2 * sa] + (b[ib + 2 * sb] - a[ia + 2 * sa]) * n, + out +); + export const mixBilinear3 = ( a: Vec, b: ReadonlyVec, c: ReadonlyVec, d: ReadonlyVec, u: number, v: number, ia = 0, ib = 0, ic = 0, id = 0, @@ -464,6 +534,66 @@ export class Vec3 implements return new Vec3(orthoNormal3(a.buf, b.buf, c.buf, a.i, b.i, c.i, a.s, b.s, c.s)); } + static add(a: Readonly, b: Readonly, out?: Vec3) { + !out && (out = new Vec3([])); + add3o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static sub(a: Readonly, b: Readonly, out?: Vec3) { + !out && (out = new Vec3([])); + sub3o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static mul(a: Readonly, b: Readonly, out?: Vec3) { + !out && (out = new Vec3([])); + mul3o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static div(a: Readonly, b: Readonly, out?: Vec3) { + !out && (out = new Vec3([])); + div3o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static addN(a: Readonly, n: number, out?: Vec3) { + !out && (out = new Vec3([])); + addN3o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static subN(a: Readonly, n: number, out?: Vec3) { + !out && (out = new Vec3([])); + subN3o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static mulN(a: Readonly, n: number, out?: Vec3) { + !out && (out = new Vec3([])); + mulN3o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static divN(a: Readonly, n: number, out?: Vec3) { + !out && (out = new Vec3([])); + divN3o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static mix(a: Readonly, b: Readonly, t: Readonly, out?: Vec3) { + !out && (out = new Vec3([])); + mix3o(out.buf, a.buf, b.buf, t.buf, out.i, a.i, b.i, t.i, out.s, a.s, b.s, t.s); + return out; + } + + static mixN(a: Readonly, b: Readonly, t: number, out?: Vec3) { + !out && (out = new Vec3([])); + mixN3o(out.buf, a.buf, b.buf, t, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + static readonly ZERO = Object.freeze(new Vec3(ZERO4)); static readonly ONE = Object.freeze(new Vec3(ONE4)); static readonly MIN = Object.freeze(new Vec3(MIN4)); diff --git a/packages/vectors/src/vec4.ts b/packages/vectors/src/vec4.ts index 8f33d8115a..d9c3387a75 100644 --- a/packages/vectors/src/vec4.ts +++ b/packages/vectors/src/vec4.ts @@ -137,6 +137,38 @@ export const div4 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => a ); +export const add4o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] + b[ib], + out[io + so] = a[ia + sa] + b[ib + sb], + out[io + 2 * so] = a[ia + 2 * sa] + b[ib + 2 * sb], + out[io + 3 * so] = a[ia + 3 * sa] + b[ib + 3 * sb], + out +); + +export const sub4o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] - b[ib], + out[io + so] = a[ia + sa] - b[ib + sb], + out[io + 2 * so] = a[ia + 2 * sa] - b[ib + 2 * sb], + out[io + 3 * so] = a[ia + 3 * sa] - b[ib + 3 * sb], + out +); + +export const mul4o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] * b[ib], + out[io + so] = a[ia + sa] * b[ib + sb], + out[io + 2 * so] = a[ia + 2 * sa] * b[ib + 2 * sb], + out[io + 3 * so] = a[ia + 3 * sa] * b[ib + 3 * sb], + out +); + +export const div4o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] / b[ib], + out[io + so] = a[ia + sa] / b[ib + sb], + out[io + 2 * so] = a[ia + 2 * sa] / b[ib + 2 * sb], + out[io + 3 * so] = a[ia + 3 * sa] / b[ib + 3 * sb], + out +); + export const addN4 = (a: Vec, n: number, ia = 0, sa = 1) => (a[ia] += n, a[ia + sa] += n, a[ia + 2 * sa] += n, a[ia + 3 * sa] += n, a); @@ -149,6 +181,38 @@ export const mulN4 = (a: Vec, n: number, ia = 0, sa = 1) => export const divN4 = (a: Vec, n: number, ia = 0, sa = 1) => (a[ia] /= n, a[ia + sa] /= n, a[ia + 2 * sa] /= n, a[ia + 3 * sa] /= n, a); +export const addN4o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => ( + out[io] = a[ia] + n, + out[io + so] = a[ia + sa] + n, + out[io + 2 * so] = a[ia + 2 * sa] + n, + out[io + 3 * so] = a[ia + 3 * sa] + n, + out +); + +export const subN4o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => ( + out[io] = a[ia] - n, + out[io + so] = a[ia + sa] - n, + out[io + 2 * so] = a[ia + 2 * sa] - n, + out[io + 3 * so] = a[ia + 3 * sa] - n, + out +); + +export const mulN4o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => ( + out[io] = a[ia] * n, + out[io + so] = a[ia + sa] * n, + out[io + 2 * so] = a[ia + 2 * sa] * n, + out[io + 3 * so] = a[ia + 3 * sa] * n, + out +); + +export const divN4o = (out: Vec, a: ReadonlyVec, n: number, io = 0, ia = 0, so = 1, sa = 1) => ( + out[io] = a[ia] / n, + out[io + so] = a[ia + sa] / n, + out[io + 2 * so] = a[ia + 2 * sa] / n, + out[io + 3 * so] = a[ia + 3 * sa] / n, + out +); + export const neg4 = (a: Vec, ia = 0, sa = 1) => mulN4(a, -1, ia, sa); @@ -236,6 +300,22 @@ export const mixN4 = (a: Vec, b: ReadonlyVec, n: number, ia = 0, ib = 0, sa = 1, a ); +export const mix4o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, t: ReadonlyVec, io = 0, ia = 0, ib = 0, it = 0, so = 1, sa = 1, sb = 1, st = 1) => ( + out[io] = a[ia] + (b[ib] - a[ia]) * t[it], + out[io + so] = a[ia + sa] + (b[ib + sb] - a[ia + sa]) * t[it + st], + out[io + 2 * so] = a[ia + 2 * sa] + (b[ib + 2 * sb] - a[ia + 2 * sa]) * t[it + 2 * st], + out[io + 3 * so] = a[ia + 3 * sa] + (b[ib + 3 * sb] - a[ia + 3 * sa]) * t[it + 3 * st], + out +); + +export const mixN4o = (out: Vec, a: ReadonlyVec, b: ReadonlyVec, n: number, io = 0, ia = 0, ib = 0, so = 1, sa = 1, sb = 1) => ( + out[io] = a[ia] + (b[ib] - a[ia]) * n, + out[io + so] = a[ia + sa] + (b[ib + sb] - a[ia + sa]) * n, + out[io + 2 * so] = a[ia + 2 * sa] + (b[ib + 2 * sb] - a[ia + 2 * sa]) * n, + out[io + 3 * so] = a[ia + 3 * sa] + (b[ib + 3 * sb] - a[ia + 3 * sa]) * n, + out +); + export const mixBilinear4 = ( a: Vec, b: ReadonlyVec, c: ReadonlyVec, d: ReadonlyVec, u: number, v: number, ia = 0, ib = 0, ic = 0, id = 0, @@ -389,6 +469,66 @@ export class Vec4 implements ); } + static add(a: Readonly, b: Readonly, out?: Vec4) { + !out && (out = new Vec4([])); + add4o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static sub(a: Readonly, b: Readonly, out?: Vec4) { + !out && (out = new Vec4([])); + sub4o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static mul(a: Readonly, b: Readonly, out?: Vec4) { + !out && (out = new Vec4([])); + mul4o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static div(a: Readonly, b: Readonly, out?: Vec4) { + !out && (out = new Vec4([])); + div4o(out.buf, a.buf, b.buf, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + + static addN(a: Readonly, n: number, out?: Vec4) { + !out && (out = new Vec4([])); + addN4o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static subN(a: Readonly, n: number, out?: Vec4) { + !out && (out = new Vec4([])); + subN4o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static mulN(a: Readonly, n: number, out?: Vec4) { + !out && (out = new Vec4([])); + mulN4o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static divN(a: Readonly, n: number, out?: Vec4) { + !out && (out = new Vec4([])); + divN4o(out.buf, a.buf, n, out.i, a.i, out.s, a.s); + return out; + } + + static mix(a: Readonly, b: Readonly, t: Readonly, out?: Vec4) { + !out && (out = new Vec4([])); + mix4o(out.buf, a.buf, b.buf, t.buf, out.i, a.i, b.i, t.i, out.s, a.s, b.s, t.s); + return out; + } + + static mixN(a: Readonly, b: Readonly, t: number, out?: Vec4) { + !out && (out = new Vec4([])); + mixN4o(out.buf, a.buf, b.buf, t, out.i, a.i, b.i, out.s, a.s, b.s); + return out; + } + static readonly ZERO = Object.freeze(new Vec4(ZERO4)); static readonly ONE = Object.freeze(new Vec4(ONE4)); static readonly MIN = Object.freeze(new Vec4(MIN4));