diff --git a/README.md b/README.md index 5c974e4e04..a3eb0d9d9c 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ difficulties, many combining functionality from several packages) in the | [`@thi.ng/paths`](./packages/paths) | [![version](https://img.shields.io/npm/v/@thi.ng/paths.svg)](https://www.npmjs.com/package/@thi.ng/paths) | [changelog](./packages/paths/CHANGELOG.md) | Immutable nested object accessors | | [`@thi.ng/pointfree`](./packages/pointfree) | [![version](https://img.shields.io/npm/v/@thi.ng/pointfree.svg)](https://www.npmjs.com/package/@thi.ng/pointfree) | [changelog](./packages/pointfree/CHANGELOG.md) | stack-based DSL & functional composition | | [`@thi.ng/pointfree-lang`](./packages/pointfree-lang) | [![version](https://img.shields.io/npm/v/@thi.ng/pointfree-lang.svg)](https://www.npmjs.com/package/@thi.ng/pointfree-lang) | [changelog](./packages/pointfree-lang/CHANGELOG.md) | Forth-like syntax layer for @thi.ng/pointfree | +| [`@thi.ng/range-coder`](./packages/range-coder) | [![version](https://img.shields.io/npm/v/@thi.ng/range-coder.svg)](https://www.npmjs.com/package/@thi.ng/range-coder) | [changelog](./packages/range-coder/CHANGELOG.md) | Binary data Range encoder / decoder | | [`@thi.ng/rle-pack`](./packages/rle-pack) | [![version](https://img.shields.io/npm/v/@thi.ng/rle-pack.svg)](https://www.npmjs.com/package/@thi.ng/rle-pack) | [changelog](./packages/rle-pack/CHANGELOG.md) | Run-length encoding data compression | | [`@thi.ng/resolve-map`](./packages/resolve-map) | [![version](https://img.shields.io/npm/v/@thi.ng/resolve-map.svg)](https://www.npmjs.com/package/@thi.ng/resolve-map) | [changelog](./packages/resolve-map/CHANGELOG.md) | DAG computations & value resolution | | [`@thi.ng/router`](./packages/router) | [![version](https://img.shields.io/npm/v/@thi.ng/router.svg)](https://www.npmjs.com/package/@thi.ng/router) | [changelog](./packages/router/CHANGELOG.md) | Customizable browser & non-browser router | @@ -74,10 +75,11 @@ difficulties, many combining functionality from several packages) in the | [`@thi.ng/transducers-fsm`](./packages/transducers-fsm) | [![version](https://img.shields.io/npm/v/@thi.ng/transducers-fsm.svg)](https://www.npmjs.com/package/@thi.ng/transducers-fsm) | [changelog](./packages/transducers-fsm/CHANGELOG.md) | Finite State Machine | | [`@thi.ng/transducers-stats`](./packages/transducers-stats) | [![version](https://img.shields.io/npm/v/@thi.ng/transducers-stats.svg)](https://www.npmjs.com/package/@thi.ng/transducers-stats) | [changelog](./packages/transducers-stats/CHANGELOG.md) | Technical / statistical analysis | | [`@thi.ng/unionstruct`](./packages/unionstruct) | [![version](https://img.shields.io/npm/v/@thi.ng/unionstruct.svg)](https://www.npmjs.com/package/@thi.ng/unionstruct) | [changelog](./packages/unionstruct/CHANGELOG.md) | Wrapper for C-like structs / unions | +| [`@thi.ng/vectors`](./packages/vectors) | [![version](https://img.shields.io/npm/v/@thi.ng/vectors.svg)](https://www.npmjs.com/package/@thi.ng/vectors) | [changelog](./packages/vectors/CHANGELOG.md) | Memory-mapped vector & matrix operations | ## Building -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella yarn build @@ -85,7 +87,7 @@ yarn build ### Building example projects -``` +```bash # build all examples (from project root) yarn examples @@ -97,7 +99,7 @@ yarn dev (TODO most but not all packages have tests) -``` +```bash yarn test # or individually @@ -108,17 +110,16 @@ lerna run test --scope @thi.ng/rstream The resulting reports will be saved under `/packages/*/coverage/lcov-report/`. -``` +```bash yarn cover ``` - ### Documentation Autogenerated documentation (using [TypeDoc](https://github.com/TypeStrong/typedoc)) will be saved under `/packages/*/doc/` and is also available at [docs.thi.ng](http://docs.thi.ng). -``` +```bash yarn doc ``` diff --git a/assets/crypto-dflow.svg b/assets/crypto-dflow.svg index b223f6cdfc..65c6983b5e 100644 --- a/assets/crypto-dflow.svg +++ b/assets/crypto-dflow.svg @@ -4,153 +4,184 @@ - - + + g - + market - -market + +market - + -data - -data +response + +response - + -market->data - - +market->response + + - - -chart - -chart + + +data + +data - + -data->chart - - +response->data + + symbol - -symbol + +symbol - + -symbol->data - - +symbol->response + + - + ui - -ui + +ui - + symbol->ui - - + + period - -period + +period - + -period->data - - +period->response + + - + period->ui - - + + - + +avgmode + +avgmode + + + +avgmode->data + + + + + refresh - -refresh + +refresh - + -refresh->data - - -every 60 secs +refresh->response + + +every 60 secs + + + +chart + +chart + + + +data->chart + + - + chart->ui - - + + - + window - -window + +window - + window->chart - - -resize + + +resize - + theme - -theme + +theme - + theme->chart - - + + - + theme->ui - - + + - + ui->symbol - - -user + + +user - + ui->period - - -user + + +user + + + +ui->avgmode + + +user - + ui->theme - - -user + + +user diff --git a/examples/async-effect/README.md b/examples/async-effect/README.md index 0fb9fcf76b..2793114889 100644 --- a/examples/async-effect/README.md +++ b/examples/async-effect/README.md @@ -1,8 +1,8 @@ # async-effect -[Live demo](http://demo.thi.ng/umbrella/async-effect/) +[Live demo](https://demo.thi.ng/umbrella/async-effect/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/async-effect yarn install diff --git a/examples/async-effect/package.json b/examples/async-effect/package.json index a5d7dea08e..6e59c2c591 100644 --- a/examples/async-effect/package.json +++ b/examples/async-effect/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", diff --git a/examples/cellular-automata/README.md b/examples/cellular-automata/README.md index 92ebcdee71..8d0a4384d8 100644 --- a/examples/cellular-automata/README.md +++ b/examples/cellular-automata/README.md @@ -1,8 +1,8 @@ # Cellular automata -[Live demo](http://demo.thi.ng/umbrella/cellular-automata/) +[Live demo](https://demo.thi.ng/umbrella/cellular-automata/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/cellular-automata yarn install @@ -11,10 +11,10 @@ yarn start ## Example configurations -- [Conway (default)](http://demo.thi.ng/umbrella/cellular-automata/#000100000-001100000) -- [Maze](http://demo.thi.ng/umbrella/cellular-automata/#000100000-001110000) -- [Disappearing maze](http://demo.thi.ng/umbrella/cellular-automata/#000111111-000001111) -- [Blobs](http://demo.thi.ng/umbrella/cellular-automata/#000010000-000011111) -- [Dots](http://demo.thi.ng/umbrella/cellular-automata/#000001111-111111110) -- [Growth](http://demo.thi.ng/umbrella/cellular-automata/#000101111-000001111) -- [Noisy growth](http://demo.thi.ng/umbrella/cellular-automata/#100101000-000001111) +- [Conway (default)](https://demo.thi.ng/umbrella/cellular-automata/#000100000-001100000) +- [Maze](https://demo.thi.ng/umbrella/cellular-automata/#000100000-001110000) +- [Disappearing maze](https://demo.thi.ng/umbrella/cellular-automata/#000111111-000001111) +- [Blobs](https://demo.thi.ng/umbrella/cellular-automata/#000010000-000011111) +- [Dots](https://demo.thi.ng/umbrella/cellular-automata/#000001111-111111110) +- [Growth](https://demo.thi.ng/umbrella/cellular-automata/#000101111-000001111) +- [Noisy growth](https://demo.thi.ng/umbrella/cellular-automata/#100101000-000001111) diff --git a/examples/cellular-automata/package.json b/examples/cellular-automata/package.json index a0e2b2e3fa..b43772b764 100644 --- a/examples/cellular-automata/package.json +++ b/examples/cellular-automata/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", diff --git a/examples/crypto-chart/README.md b/examples/crypto-chart/README.md index 309ad56f07..34357ea635 100644 --- a/examples/crypto-chart/README.md +++ b/examples/crypto-chart/README.md @@ -10,9 +10,9 @@ This example demonstrates how to use [@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/master/packages/rstream) & [@thi.ng/transducer](https://github.com/thi-ng/umbrella/tree/master/packages/transducer) -constructs to create a basic crypto-currency candle chart. Unlike most -other examples in this repo, there's no additional state handling used -(e.g. via +constructs to create a basic crypto-currency candle chart with multiple +moving averages plots. Unlike most other examples in this repo, there's +no additional state handling used (e.g. via [@thi.ng/atom](https://github.com/thi-ng/umbrella/tree/master/packages/atom) constructs) and the entire app largely relies on various stream combinators & transformers. Furthermore, this approach only triggers UI diff --git a/examples/crypto-chart/package.json b/examples/crypto-chart/package.json index b4ed0dd73f..9b0b1996ef 100644 --- a/examples/crypto-chart/package.json +++ b/examples/crypto-chart/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", @@ -22,6 +22,7 @@ "@thi.ng/hiccup-svg": "latest", "@thi.ng/resolve-map": "latest", "@thi.ng/rstream": "latest", - "@thi.ng/transducers": "latest" + "@thi.ng/transducers": "latest", + "@thi.ng/transducers-stats": "latest" } } \ No newline at end of file diff --git a/examples/crypto-chart/src/index.ts b/examples/crypto-chart/src/index.ts index 96678ac71b..85b1b1f7af 100644 --- a/examples/crypto-chart/src/index.ts +++ b/examples/crypto-chart/src/index.ts @@ -15,6 +15,10 @@ import { Stream } from "@thi.ng/rstream/stream"; import { sync } from "@thi.ng/rstream/stream-sync"; import { resolve as resolvePromise } from "@thi.ng/rstream/subs/resolve"; import { trace } from "@thi.ng/rstream/subs/trace"; +import { ema } from "@thi.ng/transducers-stats/ema"; +import { hma } from "@thi.ng/transducers-stats/hma"; +import { sma } from "@thi.ng/transducers-stats/sma"; +import { wma } from "@thi.ng/transducers-stats/wma"; import { comp } from "@thi.ng/transducers/func/comp"; import { pairs } from "@thi.ng/transducers/iter/pairs"; import { range } from "@thi.ng/transducers/iter/range"; @@ -28,7 +32,6 @@ import { filter } from "@thi.ng/transducers/xform/filter"; import { map } from "@thi.ng/transducers/xform/map"; import { mapIndexed } from "@thi.ng/transducers/xform/map-indexed"; import { mapcat } from "@thi.ng/transducers/xform/mapcat"; -import { movingAverage } from "@thi.ng/transducers/xform/moving-average"; import { pluck } from "@thi.ng/transducers/xform/pluck"; import { scan } from "@thi.ng/transducers/xform/scan"; @@ -59,9 +62,16 @@ const SYMBOL_PAIRS: DropDownOption[] = [ ["XMRUSD", "XMR-USD"], ]; +const MA_MODES = { + ema: { fn: ema, label: "Exponential" }, + hma: { fn: hma, label: "Hull" }, + sma: { fn: sma, label: "Simple" }, + wma: { fn: wma, label: "Weighted" }, +}; + // chart settings const MARGIN_X = 80; -const MARGIN_Y = 50; +const MARGIN_Y = 60; const DAY = 60 * 60 * 24; const TIME_TICKS = { @@ -89,6 +99,7 @@ const TIME_FORMATS = { const THEMES = { light: { id: "light", + label: "Light", bg: "white", body: "black", chart: { @@ -107,6 +118,7 @@ const THEMES = { }, dark: { id: "dark", + label: "Dark", bg: "black", body: "white", chart: { @@ -144,13 +156,24 @@ const Z2 = padl(2, "0"); const emitOnStream = (stream) => (e) => stream.next(e.target.value); +const menu = (stream, title, items) => + map((x: any) => + dropdown( + null, + { class: "w-100", onchange: emitOnStream(stream) }, + [[, title, true], ...items], + String(x) + ) + ); + // stream definitions -const market = new Stream(); -const symbol = new Stream(); -const period = new Stream(); -const theme = new Stream().transform(map((id: string) => THEMES[id])); -const error = new Stream(); +const market = new Stream(); +const symbol = new Stream(); +const period = new Stream(); +const avgMode = new Stream(); +const theme = new Stream().transform(map((id) => THEMES[id])); +const error = new Stream(); // I/O error handler error.subscribe({ next: (e) => alert(`An error occurred:\n${e}`) }); @@ -159,8 +182,7 @@ error.subscribe({ next: (e) => alert(`An error occurred:\n${e}`) }); const refresh = fromInterval(60000).subscribe(trace("refresh")); // this stream combinator performs API requests to obtain OHLC data -// and if successful computes a number of statistics -const data = sync({ +const response = sync({ src: { market, symbol, period, refresh }, reset: false, xform: map((inst) => @@ -171,24 +193,39 @@ const data = sync({ ) .then((json) => ({ ...inst, ohlc: json ? json.Data : null })) ) -}) - .subscribe(resolvePromise({ fail: (e) => error.next(e.message) })) - .transform( - // bail if stream value has no OHLC data - filter((x) => !!x.ohlc), +}).subscribe( + resolvePromise({ fail: (e) => error.next(e.message) }) +); + +// this stream combinator computes a number of statistics on incoming OHLC data +// including calculation of moving averages (based on current mode selection) +const data = sync({ + src: { + response, + avg: avgMode.transform(map((id: string) => MA_MODES[id].fn)), + }, + xform: comp( + // bail if response value has no OHLC data + filter(({ response }) => !!response.ohlc), // use @thi.ng/resolve-map to compute bounds & moving averages - map((inst: any) => resolve({ - ...inst, + map(({ response, avg }: any) => resolve({ + ...response, min: ({ ohlc }) => transduce(pluck("low"), min(), ohlc), max: ({ ohlc }) => transduce(pluck("high"), max(), ohlc), tbounds: ({ ohlc }) => [ohlc[0].time, ohlc[ohlc.length - 1].time], - sma: ({ ohlc }) => transduce( - map((period: number) => [period, transduce(comp(pluck("close"), movingAverage(period)), push(), ohlc)]), - push(), - [12, 24, 50, 72] - ), + sma: ({ ohlc }) => + transduce( + map((period: number) => [ + period, + transduce(comp(pluck("close"), avg(period)), push(), ohlc) + ]), + push(), + [12, 24, 50, 72] + ), })) - ); + ), + reset: false, +}); // this stream combinator (re)computes the SVG chart // updates whenever data, theme or window size has changed @@ -210,9 +247,9 @@ const chart = sync({ const mapX = (x: number) => fit(x, 0, ohlc.length, MARGIN_X, width - MARGIN_X); const mapY = (y: number) => fit(y, data.min, data.max, by, MARGIN_Y); // helper fn for plotting moving averages - const sma = (data: number[], smaPeriod: number, col: string) => + const sma = (vals: number[], col: string) => polyline( - data.map((y, x) => [mapX(x + smaPeriod + 0.5), mapY(y)]), + vals.map((y, x) => [mapX(x + (ohlc.length - vals.length) + 0.5), mapY(y)]), { stroke: col, fill: "none" } ); @@ -266,7 +303,7 @@ const chart = sync({ ), // moving averages ...iterator( - map(([period, vals]) => sma(vals, period, theme.chart[`sma${period}`])), + map(([period, vals]) => sma(vals, theme.chart[`sma${period}`])), data.sma ), // candles @@ -293,7 +330,7 @@ const chart = sync({ ), // price line line([MARGIN_X, closeY], [closeX, closeY], { stroke: theme.chart.price }), - // tag + // closing price tag polygon( [[closeX, closeY], [closeX + 10, closeY - 8], [width, closeY - 8], [width, closeY + 8], [closeX + 10, closeY + 8]], { fill: theme.chart.price } @@ -308,64 +345,67 @@ sync({ src: { chart, theme, - // transform symbol stream into dropdown component - symbol: symbol.transform( - map((x: string) => - dropdown( - null, - { class: "w3 w4-ns mr2", onchange: emitOnStream(symbol) }, - SYMBOL_PAIRS, - x - ) - ) - ), - // transform period stream into dropdown component - period: period.transform( - map((x: string) => - dropdown( - null, - { class: "w3 w4-ns mr2", onchange: emitOnStream(period) }, - [...pairs(TIMEFRAMES)], - String(x) - ) + // the following input streams are each transformed + // into a dropdown component + symbol: symbol.transform(menu(symbol, "Symbol pair", SYMBOL_PAIRS)), + period: period.transform(menu(period, "Time frame", [...pairs(TIMEFRAMES)])), + avg: avgMode.transform( + menu(avgMode, "Moving average", + [...iterator( + map(([id, mode]) => [id, mode.label]), + pairs(MA_MODES))] ) ), themeSel: theme.transform( - map((sel) => - dropdown( - null, - { class: "w3 w4-ns", onchange: emitOnStream(theme) }, - Object.keys(THEMES).map((k) => [k, k]), - sel.id - ) + map((x) => x.id), + menu(theme, "Theme", + [...iterator( + map(([id, theme]) => [id, theme.label]), + pairs(THEMES))] ) ) }, reset: false, xform: comp( // combines all inputs into a single root component - map(({ theme, themeSel, chart, symbol, period }) => + map(({ theme, themeSel, chart, symbol, period, avg }) => ["div", - { class: `sans-serif bg-${theme.bg} ${theme.body}` }, + { class: `sans-serif f7 bg-${theme.bg} ${theme.body}` }, chart, - ["div.fixed.f7", - { style: { top: `10px`, right: `${MARGIN_X}px` } }, - ["span.dn.dib-l", - ["a", - { - class: `mr3 b link ${theme.body}`, - href: "https://min-api.cryptocompare.com/" - }, - "Data by cyptocompare.com"], - ["a", - { - class: `mr3 b link ${theme.body}`, - href: "https://github.com/thi-ng/umbrella/tree/master/examples/crypto-chart/" - }, "Source code"] - ], - symbol, - period, - themeSel, + ["div.fixed", + { + style: { + top: `1rem`, + right: `${MARGIN_X}px`, + width: `calc(100vw - 2 * ${MARGIN_X}px)` + } + }, + ["div.flex", + ...iterator( + map((x) => ["div.w-25.ph2", x]), + [symbol, period, avg, themeSel] + ), + ] + ], + ["div.fixed.tc", + { + style: { + bottom: `1rem`, + left: `${MARGIN_X}px`, + width: `calc(100vw - 2 * ${MARGIN_X}px)` + } + }, + ["a", + { + class: `mr3 b link ${theme.body}`, + href: "https://min-api.cryptocompare.com/" + }, + "Data by cyptocompare.com"], + ["a", + { + class: `mr3 b link ${theme.body}`, + href: "https://github.com/thi-ng/umbrella/tree/master/examples/crypto-chart/" + }, "Source code"] ] ] ), @@ -387,6 +427,7 @@ sync({ market.next("CCCAGG"); symbol.next("BTCUSD"); period.next(60); +avgMode.next("wma"); theme.next("dark"); window.dispatchEvent(new CustomEvent("resize")); diff --git a/examples/dashboard/README.md b/examples/dashboard/README.md index 375577204b..652fa64438 100644 --- a/examples/dashboard/README.md +++ b/examples/dashboard/README.md @@ -1,8 +1,8 @@ # @thi.ng/hdom dashboard example -[Live demo here](http://demo.thi.ng/umbrella/dashboard/) +[Live demo here](https://demo.thi.ng/umbrella/dashboard/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/dashboard yarn install diff --git a/examples/dashboard/package.json b/examples/dashboard/package.json index 12661c80a6..3081950e1d 100644 --- a/examples/dashboard/package.json +++ b/examples/dashboard/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/hdom": "latest" diff --git a/examples/devcards/README.md b/examples/devcards/README.md index 7f488eb0fd..1ac1638f32 100644 --- a/examples/devcards/README.md +++ b/examples/devcards/README.md @@ -1,8 +1,8 @@ # devcards -[Live demo](http://demo.thi.ng/umbrella/devcards/) +[Live demo](https://demo.thi.ng/umbrella/devcards/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/devcards yarn install diff --git a/examples/devcards/package.json b/examples/devcards/package.json index 26c0f78bde..2699aa48a9 100644 --- a/examples/devcards/package.json +++ b/examples/devcards/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", diff --git a/examples/hdom-basics/README.md b/examples/hdom-basics/README.md index d8cdf4c2ac..d3137177d5 100644 --- a/examples/hdom-basics/README.md +++ b/examples/hdom-basics/README.md @@ -1,8 +1,8 @@ # hdom-basics -[Live demo](http://demo.thi.ng/umbrella/hdom-basics/) +[Live demo](https://demo.thi.ng/umbrella/hdom-basics/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/hdom-basics yarn install diff --git a/examples/hdom-basics/package.json b/examples/hdom-basics/package.json index 6ebcb28e5a..d685cc062e 100644 --- a/examples/hdom-basics/package.json +++ b/examples/hdom-basics/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/hdom": "latest" diff --git a/examples/hdom-benchmark/README.md b/examples/hdom-benchmark/README.md index 43eaad0df3..14b269d669 100644 --- a/examples/hdom-benchmark/README.md +++ b/examples/hdom-benchmark/README.md @@ -1,8 +1,8 @@ # hdom-benchmark -[Live demo](http://demo.thi.ng/umbrella/hdom-benchmark/) +[Live demo](https://demo.thi.ng/umbrella/hdom-benchmark/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/hdom-benchmark yarn install diff --git a/examples/hdom-benchmark/package.json b/examples/hdom-benchmark/package.json index 4775c7f7ab..50a0ab2e65 100644 --- a/examples/hdom-benchmark/package.json +++ b/examples/hdom-benchmark/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", diff --git a/examples/hdom-dropdown-fuzzy/README.md b/examples/hdom-dropdown-fuzzy/README.md index 861253b871..fa2f87153f 100644 --- a/examples/hdom-dropdown-fuzzy/README.md +++ b/examples/hdom-dropdown-fuzzy/README.md @@ -1,11 +1,11 @@ # hdom-dropdown-fuzzy -[Live demo](http://demo.thi.ng/umbrella/hdom-dropdown-fuzzy/) +[Live demo](https://demo.thi.ng/umbrella/hdom-dropdown-fuzzy/) **This example is a work-in-progress trying out different ideas. Do not (yet) take as reference for your own projects.** -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/hdom-dropdown-fuzzy yarn install diff --git a/examples/hdom-dropdown-fuzzy/package.json b/examples/hdom-dropdown-fuzzy/package.json index 513d7f148b..22f13c87aa 100644 --- a/examples/hdom-dropdown-fuzzy/package.json +++ b/examples/hdom-dropdown-fuzzy/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", diff --git a/examples/hdom-dropdown/README.md b/examples/hdom-dropdown/README.md index ecccd0f6a3..c9c006e3ab 100644 --- a/examples/hdom-dropdown/README.md +++ b/examples/hdom-dropdown/README.md @@ -1,8 +1,8 @@ # hdom-dropdown -[Live demo](http://demo.thi.ng/umbrella/hdom-dropdown/) +[Live demo](https://demo.thi.ng/umbrella/hdom-dropdown/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/hdom-dropdown yarn install diff --git a/examples/hdom-dropdown/package.json b/examples/hdom-dropdown/package.json index 9aaf2adedc..c283b264fb 100644 --- a/examples/hdom-dropdown/package.json +++ b/examples/hdom-dropdown/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", diff --git a/examples/hdom-theme-adr-0003/README.md b/examples/hdom-theme-adr-0003/README.md index bd79eb22d5..7927f0a027 100644 --- a/examples/hdom-theme-adr-0003/README.md +++ b/examples/hdom-theme-adr-0003/README.md @@ -1,11 +1,11 @@ # hdom-theme-adr-0003 -[Live demo](http://demo.thi.ng/umbrella/hdom-theme-adr-0003/) +[Live demo](https://demo.thi.ng/umbrella/hdom-theme-adr-0003/) WIP demo of themed component proposal discussed in [ADR-0003](https://github.com/thi-ng/umbrella/blob/develop/packages/hdom-components/adr/0003-component-configuration-via-context.md). -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/hdom-theme-adr-0003 yarn install diff --git a/examples/hdom-theme-adr-0003/package.json b/examples/hdom-theme-adr-0003/package.json index cc21c4b9da..3fd865d407 100644 --- a/examples/hdom-theme-adr-0003/package.json +++ b/examples/hdom-theme-adr-0003/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", diff --git a/examples/interceptor-basics/README.md b/examples/interceptor-basics/README.md index 75e8dd7b3c..e8e4ec03df 100644 --- a/examples/interceptor-basics/README.md +++ b/examples/interceptor-basics/README.md @@ -1,8 +1,8 @@ # interceptor-basics -[Live demo](http://demo.thi.ng/umbrella/interceptor-basics/) +[Live demo](https://demo.thi.ng/umbrella/interceptor-basics/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/interceptor-basics yarn install diff --git a/examples/interceptor-basics/package.json b/examples/interceptor-basics/package.json index 900094ad34..12926d4f90 100644 --- a/examples/interceptor-basics/package.json +++ b/examples/interceptor-basics/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", diff --git a/examples/json-components/README.md b/examples/json-components/README.md index 19563e0437..ed374c29c4 100644 --- a/examples/json-components/README.md +++ b/examples/json-components/README.md @@ -1,8 +1,8 @@ # json-components -[Live demo](http://demo.thi.ng/umbrella/json-components/) +[Live demo](https://demo.thi.ng/umbrella/json-components/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/json-components yarn install diff --git a/examples/json-components/package.json b/examples/json-components/package.json index 56930a05b4..35369186e7 100644 --- a/examples/json-components/package.json +++ b/examples/json-components/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/hdom": "latest", diff --git a/examples/login-form/README.md b/examples/login-form/README.md index 397df15c6c..2ccd05549f 100644 --- a/examples/login-form/README.md +++ b/examples/login-form/README.md @@ -1,8 +1,8 @@ # login-form -[Live demo](http://demo.thi.ng/umbrella/login-form/) +[Live demo](https://demo.thi.ng/umbrella/login-form/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/login-form yarn install diff --git a/examples/login-form/package.json b/examples/login-form/package.json index 0b04f4ff7b..2e925a5f9c 100644 --- a/examples/login-form/package.json +++ b/examples/login-form/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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", diff --git a/examples/pointfree-svg/README.md b/examples/pointfree-svg/README.md index 39cd8fed4b..882b87d0f0 100644 --- a/examples/pointfree-svg/README.md +++ b/examples/pointfree-svg/README.md @@ -17,7 +17,7 @@ easily extend the language. The generated SVG file will be written in this example's directory... -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/pointfree-svg yarn build diff --git a/examples/pointfree-svg/package.json b/examples/pointfree-svg/package.json index 0b193d3e84..0ba4d62f0f 100644 --- a/examples/pointfree-svg/package.json +++ b/examples/pointfree-svg/package.json @@ -15,6 +15,6 @@ "@thi.ng/pointfree-lang": "latest" }, "devDependencies": { - "typescript": "^2.8.3" + "typescript": "^3.0.1" } } \ No newline at end of file diff --git a/examples/router-basics/README.md b/examples/router-basics/README.md index 6134b0f688..e664949824 100644 --- a/examples/router-basics/README.md +++ b/examples/router-basics/README.md @@ -1,8 +1,8 @@ # router-basics -[Live demo](http://demo.thi.ng/umbrella/router-basics/) +[Live demo](https://demo.thi.ng/umbrella/router-basics/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/router-basics yarn install @@ -30,7 +30,7 @@ Features covered: ### Production build -``` +```bash yarn build ``` diff --git a/examples/router-basics/package.json b/examples/router-basics/package.json index c0941760f6..33faf7f282 100644 --- a/examples/router-basics/package.json +++ b/examples/router-basics/package.json @@ -16,10 +16,10 @@ "@thi.ng/router": "latest" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "ts-loader": "^4.4.2", + "typescript": "^3.0.1", + "webpack": "^4.16.3", + "webpack-cli": "^3.1.0", + "webpack-dev-server": "^3.1.5" } } \ No newline at end of file diff --git a/examples/rstream-dataflow/README.md b/examples/rstream-dataflow/README.md index e4aeb62f89..41159d72c0 100644 --- a/examples/rstream-dataflow/README.md +++ b/examples/rstream-dataflow/README.md @@ -1,8 +1,8 @@ # rstream-dataflow -[Live demo](http://demo.thi.ng/umbrella/rstream-dataflow/) +[Live demo](https://demo.thi.ng/umbrella/rstream-dataflow/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/rstream-dataflow yarn install diff --git a/examples/rstream-dataflow/package.json b/examples/rstream-dataflow/package.json index 1b7c67a971..ac7e6d19db 100644 --- a/examples/rstream-dataflow/package.json +++ b/examples/rstream-dataflow/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", diff --git a/examples/rstream-grid/README.md b/examples/rstream-grid/README.md index 6468ec8eee..932c0d2704 100644 --- a/examples/rstream-grid/README.md +++ b/examples/rstream-grid/README.md @@ -2,7 +2,7 @@ ## About -[Live demo](http://demo.thi.ng/umbrella/rstream-grid/) +[Live demo](https://demo.thi.ng/umbrella/rstream-grid/) Interactive SVG grid pattern creator with undo, local file download and implemented as rstream dataflow graph, combined with interceptor event & @@ -23,7 +23,7 @@ template. ### Development -``` +```bash git clone https://github.com/thi-ng/umbrella/ cd umbrella/examples/rstream-grid yarn install @@ -35,7 +35,7 @@ in your browser. ### Production -``` +```bash yarn build ``` diff --git a/examples/rstream-grid/package.json b/examples/rstream-grid/package.json index d6a079a9ef..c796850189 100644 --- a/examples/rstream-grid/package.json +++ b/examples/rstream-grid/package.json @@ -19,10 +19,10 @@ }, "devDependencies": { "@types/node": "^9.6.2", - "typescript": "^2.8.3", - "ts-loader": "^4.3.0", - "webpack": "^4.5.0", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "typescript": "^3.0.1", + "ts-loader": "^4.4.2", + "webpack": "^4.16.3", + "webpack-cli": "^3.1.0", + "webpack-dev-server": "^3.1.5" } } \ No newline at end of file diff --git a/examples/rstream-hdom/README.md b/examples/rstream-hdom/README.md index 2b3cacb18e..23e391d662 100644 --- a/examples/rstream-hdom/README.md +++ b/examples/rstream-hdom/README.md @@ -1,6 +1,6 @@ # rstream-hdom -[Live demo](http://demo.thi.ng/umbrella/rstream-hdom/) +[Live demo](https://demo.thi.ng/umbrella/rstream-hdom/) This example shows how [@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/master/packages/rstream) @@ -8,7 +8,7 @@ constructs can be used for state handling and reactively trigger [@thi.ng/hdom](https://github.com/thi-ng/umbrella/tree/master/packages/hdom) updates only when any of the UI related streams have value changes. -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/rstream-hdom yarn install diff --git a/examples/rstream-hdom/package.json b/examples/rstream-hdom/package.json index e981dc73d7..19acacb477 100644 --- a/examples/rstream-hdom/package.json +++ b/examples/rstream-hdom/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/api": "latest", diff --git a/examples/svg-particles/README.md b/examples/svg-particles/README.md index dcf4ce21d4..096e45720e 100644 --- a/examples/svg-particles/README.md +++ b/examples/svg-particles/README.md @@ -1,8 +1,8 @@ # svg-particles -[Live demo](http://demo.thi.ng/umbrella/svg-particles/) +[Live demo](https://demo.thi.ng/umbrella/svg-particles/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/svg-particles yarn install diff --git a/examples/svg-particles/package.json b/examples/svg-particles/package.json index 7814835ba0..a6db945db8 100644 --- a/examples/svg-particles/package.json +++ b/examples/svg-particles/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/hdom": "latest", diff --git a/examples/svg-waveform/README.md b/examples/svg-waveform/README.md index 9841a18533..532aa5af7a 100644 --- a/examples/svg-waveform/README.md +++ b/examples/svg-waveform/README.md @@ -4,7 +4,7 @@ Interactive, additive waveform synthesis (no audio) and SVG waveform visualization. -[Live demo](http://demo.thi.ng/umbrella/svg-waveform/) +[Live demo](https://demo.thi.ng/umbrella/svg-waveform/) ## Building @@ -14,7 +14,7 @@ template. ### Development -``` +```bash git clone https://github.com/thi-ng/umbrella/ cd umbrella/examples/svg-waveform yarn install @@ -26,7 +26,7 @@ in your browser. ### Production -``` +```bash yarn build ``` diff --git a/examples/svg-waveform/package.json b/examples/svg-waveform/package.json index f6feb0980d..8bce0245da 100644 --- a/examples/svg-waveform/package.json +++ b/examples/svg-waveform/package.json @@ -18,10 +18,10 @@ }, "devDependencies": { "@types/node": "^9.6.2", - "typescript": "^2.8.3", - "ts-loader": "^4.3.0", - "webpack": "^4.5.0", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "typescript": "^3.0.1", + "ts-loader": "^4.4.2", + "webpack": "^4.16.3", + "webpack-cli": "^3.1.0", + "webpack-dev-server": "^3.1.5" } } \ No newline at end of file diff --git a/examples/todo-list/README.md b/examples/todo-list/README.md index 7f804669c0..df37f41c20 100644 --- a/examples/todo-list/README.md +++ b/examples/todo-list/README.md @@ -1,8 +1,8 @@ # @thi.ng/hdom todo list example -[Live demo here](http://demo.thi.ng/umbrella/todo-list/) +[Live demo here](https://demo.thi.ng/umbrella/todo-list/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/todo-list yarn install diff --git a/examples/todo-list/package.json b/examples/todo-list/package.json index 53a41fa5ce..44b2f5a52e 100644 --- a/examples/todo-list/package.json +++ b/examples/todo-list/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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", diff --git a/examples/triple-query/.gitignore b/examples/triple-query/.gitignore new file mode 100644 index 0000000000..9c418ce79f --- /dev/null +++ b/examples/triple-query/.gitignore @@ -0,0 +1,3 @@ +node_modules +yarn.lock +*.js diff --git a/examples/triple-query/README.md b/examples/triple-query/README.md new file mode 100644 index 0000000000..3aaddfe213 --- /dev/null +++ b/examples/triple-query/README.md @@ -0,0 +1,18 @@ +# triple-query + +[Live demo](https://demo.thi.ng/umbrella/triple-query/) + +```bash +git clone https://github.com/thi-ng/umbrella.git +cd umbrella/examples/triple-query +yarn install +yarn start +``` + +## Authors + +- Karsten Schmidt + +## License + +© 2018 Karsten Schmidt // Apache Software License 2.0 diff --git a/examples/triple-query/package.json b/examples/triple-query/package.json new file mode 100644 index 0000000000..a2fa025a8d --- /dev/null +++ b/examples/triple-query/package.json @@ -0,0 +1,24 @@ +{ + "name": "triple-query", + "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" + }, + "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/api": "latest", + "@thi.ng/hdom": "latest", + "@thi.ng/rstream-query": "latest", + "@thi.ng/transducers": "latest" + } +} \ No newline at end of file diff --git a/examples/triple-query/src/api.ts b/examples/triple-query/src/api.ts new file mode 100644 index 0000000000..bd8ae30379 --- /dev/null +++ b/examples/triple-query/src/api.ts @@ -0,0 +1,79 @@ +import { IObjectOf } from "@thi.ng/api/api"; +import { IView, ViewTransform } from "@thi.ng/atom/api"; +import { EffectDef, EventDef, InterceptorContext } from "@thi.ng/interceptors/api"; +import { EventBus } from "@thi.ng/interceptors/event-bus"; +import { TripleStore } from "@thi.ng/rstream-query/store"; +import { QuerySpec } from "@thi.ng/rstream-query/api"; + +/** + * Function signature for main app components. + */ +export type AppComponent = (ctx: AppContext, ...args: any[]) => any; + +/** + * Derived view configurations. + */ +export type ViewSpec = string | [string, ViewTransform]; + +/** + * Structure of the overall application config object. + * See `src/config.ts`. + */ +export interface AppConfig { + events: IObjectOf; + effects: IObjectOf; + domRoot: string | Element; + initialState: any; + rootComponent: AppComponent; + ui: UIAttribs; + views: Partial>; + data: { + cities: string[][]; + countries: string[][]; + regions: string[]; + queries: IObjectOf; + } +} + +/** + * Base structure of derived views exposed by the base app. + * Add more declarations here as needed. + */ +export interface AppViews extends Record> { + page: IView; + pagedTriples: IView; + cities: IView; + countries: IView; + sort: IView<[number, boolean]>; +} + +/** + * Helper interface to pre-declare keys of shared UI attributes for + * components and so enable autocomplete & type safety. + * + * See `AppConfig` above and its use in `src/config.ts` and various + * component functions. + */ +export interface UIAttribs { + button: any; + buttonDisabled: any; + buttongroup: any; + link: any; + root: any; + table: { root: any; head: any; headlink: any; row: any; cell: any }, + pager: { root: any; prev: any; pages: any; next: any; } +} + +/** + * Structure of the context object passed to all component functions + */ +export interface AppContext { + bus: EventBus; + views: AppViews; + ui: UIAttribs; + store: TripleStore; +} + +export interface AppInterceptorContext extends InterceptorContext { + store: TripleStore; +} diff --git a/examples/triple-query/src/app.ts b/examples/triple-query/src/app.ts new file mode 100644 index 0000000000..ddb20f3f2b --- /dev/null +++ b/examples/triple-query/src/app.ts @@ -0,0 +1,107 @@ +import { IObjectOf } from "@thi.ng/api/api"; +import { Atom } from "@thi.ng/atom/atom"; +import { isArray } from "@thi.ng/checks/is-array"; +import { start } from "@thi.ng/hdom"; +import { EV_SET_VALUE } from "@thi.ng/interceptors/api"; +import { EventBus } from "@thi.ng/interceptors/event-bus"; +import { TripleStore } from "@thi.ng/rstream-query/store"; + +import { + AppConfig, + AppContext, + AppViews, + ViewSpec +} from "./api"; +import * as ev from "./events"; + +/** + * Generic base app skeleton. You can use this as basis for your own + * apps. + * + * As is the app does not much more than: + * + * - initialize state and event bus + * - attach derived views + * - define root component wrapper + * - start hdom render & event bus loop + */ +export class App { + + config: AppConfig; + ctx: AppContext; + state: Atom; + + constructor(config: AppConfig) { + this.config = config; + this.state = new Atom(config.initialState || {}); + this.ctx = { + bus: new EventBus(this.state, config.events, config.effects), + store: new TripleStore(), + views: {}, + ui: config.ui, + }; + this.addViews(this.config.views); + } + + /** + * Initializes given derived view specs and attaches them to app + * state atom. + * + * @param specs + */ + addViews(specs: IObjectOf) { + const views = this.ctx.views; + for (let id in specs) { + const spec = specs[id]; + if (isArray(spec)) { + views[id] = this.state.addView(spec[0], spec[1]); + } else { + views[id] = this.state.addView(spec); + } + } + } + + /** + * Calls `init()` and kicks off hdom render loop, including batched + * event processing and fast fail check if DOM updates are necessary + * (assumes ALL state is held in the app state atom). So if there + * weren't any events causing a state change since last frame, + * re-rendering is skipped without even attempting to diff DOM + * tree). + */ + start() { + this.init(); + // assume main root component is a higher order function + // call it here to pre-initialize it + const root = this.config.rootComponent(this.ctx); + let firstFrame = true; + start( + this.config.domRoot, + () => { + if (this.ctx.bus.processQueue({ store: this.ctx.store }) || firstFrame) { + firstFrame = false; + return root(); + } + }, + this.ctx + ); + } + + /** + * User initialization hook. + * Automatically called from `start()` + */ + init() { + // ...add init tasks here + const conf = this.config.data; + const store = this.ctx.store; + conf.cities.forEach((x) => this.ctx.bus.dispatch([ev.ADD_CITY, x])); + conf.countries.forEach((x) => this.ctx.bus.dispatch([ev.ADD_COUNTRY, x])); + for (let q in conf.queries) { + store.addQueryFromSpec(conf.queries[q]) + .subscribe({ + next: (res) => this.ctx.bus.dispatch([EV_SET_VALUE, [["queries", q], res]]) + }); + } + } +} diff --git a/examples/triple-query/src/components/button-group.ts b/examples/triple-query/src/components/button-group.ts new file mode 100644 index 0000000000..3a40b736a1 --- /dev/null +++ b/examples/triple-query/src/components/button-group.ts @@ -0,0 +1,8 @@ +import { AppContext } from "../api"; +import { button } from "./button"; + +export function buttonGroup(ctx: AppContext, ...buttons) { + return ["section", ctx.ui.buttongroup, + buttons.map((bt) => [button, ...bt]) + ]; +} diff --git a/examples/triple-query/src/components/button.ts b/examples/triple-query/src/components/button.ts new file mode 100644 index 0000000000..7c6f2a33b8 --- /dev/null +++ b/examples/triple-query/src/components/button.ts @@ -0,0 +1,8 @@ +import { AppContext } from "../api"; +import { eventLink } from "./event-link"; + +export function button(ctx: AppContext, event: Event, label: string, disabled = false) { + return disabled ? + ["span", ctx.ui.buttonDisabled, label] : + [eventLink, ctx.ui.button, event, label]; +} diff --git a/examples/triple-query/src/components/event-link.ts b/examples/triple-query/src/components/event-link.ts new file mode 100644 index 0000000000..fce1ca8aa7 --- /dev/null +++ b/examples/triple-query/src/components/event-link.ts @@ -0,0 +1,24 @@ +import { Event } from "@thi.ng/interceptors/api"; + +import { AppContext } from "../api"; + +/** + * Customizable hyperlink component emitting given event on event bus + * when clicked. + * + * @param ctx + * @param event event tuple of `[event-id, payload]` + * @param attribs element attribs + * @param body link body + */ +export function eventLink(ctx: AppContext, attribs: any, event: Event, body: any) { + return ["a", + { + ...attribs, + onclick: (e) => { + e.preventDefault(); + ctx.bus.dispatch(event); + } + }, + body]; +} diff --git a/examples/triple-query/src/components/link.ts b/examples/triple-query/src/components/link.ts new file mode 100644 index 0000000000..4718784714 --- /dev/null +++ b/examples/triple-query/src/components/link.ts @@ -0,0 +1,5 @@ +import { AppContext } from "../api"; + +export function link(ctx: AppContext, href, ...body) { + return ["a", { ...ctx.ui.link, href }, ...body]; +} diff --git a/examples/triple-query/src/components/main.ts b/examples/triple-query/src/components/main.ts new file mode 100644 index 0000000000..dfe61c257e --- /dev/null +++ b/examples/triple-query/src/components/main.ts @@ -0,0 +1,13 @@ +import { AppContext } from "../api"; +import { queryResults } from "./query-results"; +import { tripleTable } from "./triple-table"; + +export function main(ctx: AppContext) { + const triples = tripleTable(); + return () => + ["div", ctx.ui.root, + [triples, ctx.views.pagedTriples.deref(), ctx.store.triples.length, ctx.views.page.deref()], + [queryResults, "Cities", ctx.views.cities.deref()], + [queryResults, "Countries", ctx.views.countries.deref()] + ]; +} diff --git a/examples/triple-query/src/components/query-results.ts b/examples/triple-query/src/components/query-results.ts new file mode 100644 index 0000000000..87b6b1041c --- /dev/null +++ b/examples/triple-query/src/components/query-results.ts @@ -0,0 +1,25 @@ +import { repeat } from "@thi.ng/transducers/iter/repeat"; +import { iterator } from "@thi.ng/transducers/iterator"; +import { map } from "@thi.ng/transducers/xform/map"; +import { mapIndexed } from "@thi.ng/transducers/xform/map-indexed"; + +import { AppContext } from "../api"; +import { section } from "./section"; +import { table } from "./table"; + +export const queryResults = (_: AppContext, title: string, results: Set) => { + if (results) { + const [first] = results; + const keys = Object.keys(first).sort(); + return [section, + title, ` (${results.size})`, + [table, + ["10%", ...repeat(`${(90 / keys.length) | 0}%`, keys.length)], + ["id", ...keys], + iterator( + mapIndexed((i, x) => [i + 1, ...iterator(map((k: string) => x[k]), keys)]), + results + )] + ]; + } +}; \ No newline at end of file diff --git a/examples/triple-query/src/components/section.ts b/examples/triple-query/src/components/section.ts new file mode 100644 index 0000000000..da0e102d10 --- /dev/null +++ b/examples/triple-query/src/components/section.ts @@ -0,0 +1,6 @@ +import { title } from "@thi.ng/hdom-components/title"; + +const h1 = title({ subAttribs: { class: "moon-gray" } }); + +export const section = (_, title, subtitle, ...body) => + ["section", [h1, title, subtitle], ...body]; diff --git a/examples/triple-query/src/components/table.ts b/examples/triple-query/src/components/table.ts new file mode 100644 index 0000000000..694b75ee33 --- /dev/null +++ b/examples/triple-query/src/components/table.ts @@ -0,0 +1,19 @@ +import { iterator } from "@thi.ng/transducers/iterator"; +import { map } from "@thi.ng/transducers/xform/map"; + +import { AppContext } from "../api"; + +const row = (ctx: AppContext, body: Iterable) => + ["tr", ctx.ui.table.row, ...body]; + +export const table = (ctx: AppContext, layout: any[], head: Iterable, body: Iterable>) => + ["table", ctx.ui.table.root, + ...(layout || []).map((x) => ["col", { style: { width: x } }]), + [row, iterator(map((x) => ["th", ctx.ui.table.head, x]), head)], + iterator( + map((cols: any) => + [row, iterator(map((x) => ["td", ctx.ui.table.cell, x]), cols)] + ), + body + ) + ]; diff --git a/examples/triple-query/src/components/triple-table.ts b/examples/triple-query/src/components/triple-table.ts new file mode 100644 index 0000000000..2107d1f3de --- /dev/null +++ b/examples/triple-query/src/components/triple-table.ts @@ -0,0 +1,39 @@ +import { pager } from "@thi.ng/hdom-components/pager"; + +import { AppContext } from "../api"; +import { SET_PAGE, SET_SORT } from "../events"; +import { PAGE_LEN } from "../handlers"; +import { button } from "./button"; +import { eventLink } from "./event-link"; +import { section } from "./section"; +import { table } from "./table"; + +export const tripleTable = () => { + const _pager = pager({ + root: (ctx, ...body) => ["div", ctx.ui.pager.root, ...body], + button: (i, _, __, label, disabled) => [button, [SET_PAGE, i], label, disabled], + groupPrev: (ctx, ...bts) => ["div", ctx.ui.pager.prev, ...bts], + groupNext: (ctx, ...bts) => ["div", ctx.ui.pager.next, ...bts], + groupPages: (ctx, bts) => ["div", ctx.ui.pager.pages, bts], + }); + return (ctx: AppContext, triples: any[], num: number, page: number) => { + const [sid, sdir] = ctx.views.sort.deref(); + const icon = sdir ? "🔼" : "🔽"; + return [section, + "All triples", ` (${ctx.store.triples.length})`, + [table, + ["10%", "30%", "30%", "30%"], + ["id", + ...["subject", "predicate", "object"].map( + (x, i) => [eventLink, + ctx.ui.table.headlink, + [SET_SORT, i], + `${x} ${sid === i ? icon : ""}` + ] + ) + ], + triples], + [_pager, page, num, PAGE_LEN, 5] + ]; + }; +}; diff --git a/examples/triple-query/src/config.ts b/examples/triple-query/src/config.ts new file mode 100644 index 0000000000..5f9c150f89 --- /dev/null +++ b/examples/triple-query/src/config.ts @@ -0,0 +1,139 @@ +import { AppConfig, AppInterceptorContext } from "./api"; +import { main } from "./components/main"; +import { EVENTS, EFFECTS } from "./handlers"; + +// main App configuration +export const CONFIG: AppConfig = { + + // event handlers events are queued and batch processed in app's RAF + // render loop event handlers can be single functions, interceptor + // objects with `pre`/`post` keys or arrays of either. + + // the event handlers' only task is to transform the event into a + // number of side effects. event handlers should be pure functions + // and only side effect functions execute any "real" work. + + // Docs here: + // https://github.com/thi-ng/umbrella/blob/master/packages/interceptors/src/event-bus.ts#L14 + + events: EVENTS, + + // custom side effects + effects: EFFECTS, + + // DOM root element (or ID) + domRoot: "app", + + // root component function used by the app + rootComponent: main, + + // initial app state + initialState: { + page: 0, + pagedTriples: [], + sort: [0, false] + }, + + // derived view declarations + // each key specifies the name of the view and each value is + // a state path or `[path, transformer]` tuple + // docs here: + // https://github.com/thi-ng/umbrella/tree/master/packages/atom#derived-views + // also see `app.ts` for view initialization + views: { + page: "page", + pagedTriples: "pagedTriples", + cities: "queries.cities", + countries: "queries.countries", + sort: "sort", + }, + + // component CSS class config using http://tachyons.io/ these + // attribs are made available to all components and allow for easy + // re-skinning of the whole app + ui: { + button: { class: "pointer bg-black hover-bg-blue bg-animate white pa2 mr1 w-100 ttu b tracked-tight noselect" }, + buttonDisabled: { class: "bg-gray white pa2 mr1 w-100 ttu b tracked-tight noselect" }, + buttongroup: { class: "flex mb2" }, + link: { class: "pointer link dim black b" }, + root: { class: "pa2 mw7-ns center f7 f6-m f5-ns" }, + table: { + root: { class: "w-100 collapse ba br2 b--black-10 pv2 ph3" }, + head: { class: "tl pv2 ph3 bg-black white" }, + headlink: { class: "pointer white" }, + row: { class: "striped--light-gray" }, + cell: { class: "pv2 ph3" } + }, + pager: { + root: { class: "w-100 mt3 f7 tc" }, + prev: { class: "fl mr3" }, + next: { class: "fr ml3" }, + pages: { class: "dib" } + } + }, + + data: { + cities: [ + ["accra", "gh"], + ["amsterdam", "nl"], + ["berlin", "de"], + ["dublin", "ie"], + ["johannesburg", "za"], + ["london", "uk"], + ["new york", "us"], + ["san francisco", "us"], + ["são paulo", "br"], + ["shanghai", "cn"], + ["tokyo", "jp"], + ["toronto", "ca"], + ], + countries: [ + ["au", "australia", "oceania"], + ["br", "brasil", "south-america"], + ["ca", "canada", "north-america"], + ["cn", "china", "asia"], + ["de", "germany", "europe"], + ["gh", "ghana", "africa"], + ["ie", "ireland", "europe"], + ["nl", "netherlands", "europe"], + ["jp", "japan", "asia"], + ["za", "south africa", "africa"], + ["nz", "new zealand", "oceania"], + ["us", "united states", "north-america"], + ], + regions: [ + "africa", + "asia", + "central-america", + "europe", + "middle-east", + "north-america", + "oceania", + "south-america", + "caribbean", + ], + queries: { + cities: { + q: [{ + where: [ + ["?city", "type", "city"], + ["?city", "locatedIn", "?cid"], + ["?cid", "type", "country"], + ["?cid", "name", "?country"], + ["?cid", "partOf", "?region"], + ] + }], + select: ["city", "country", "region"], + }, + countries: { + q: [{ + where: [ + ["?code", "type", "country"], + ["?code", "partOf", "?region"], + ["?region", "type", "region"], + ] + }] + } + } + } +}; diff --git a/examples/triple-query/src/effects.ts b/examples/triple-query/src/effects.ts new file mode 100644 index 0000000000..09f46e4691 --- /dev/null +++ b/examples/triple-query/src/effects.ts @@ -0,0 +1,7 @@ +// best practice tip: define event & effect names as consts or enums +// and avoid hardcoded strings for more safety and easier refactoring +// also see pre-defined event handlers & interceptors in @thi.ng/atom: +// https://github.com/thi-ng/umbrella/blob/master/packages/interceptors/src/api.ts#L14 + +export const ADD_TRIPLE = "add-triples"; +export const REMOVE_TRIPLE = "remove-triples"; diff --git a/examples/triple-query/src/events.ts b/examples/triple-query/src/events.ts new file mode 100644 index 0000000000..9cfa36deb4 --- /dev/null +++ b/examples/triple-query/src/events.ts @@ -0,0 +1,12 @@ +// best practice tip: define event & effect names as consts or enums +// and avoid hardcoded strings for more safety and easier refactoring +// also see pre-defined event handlers & interceptors in @thi.ng/atom: +// https://github.com/thi-ng/umbrella/blob/master/packages/interceptors/src/api.ts#L14 + +export const ADD_CITY = "add-city"; +export const ADD_COUNTRY = "add-country"; +export const SET_SORT = "set-sort"; +export const SET_PAGE = "set-page"; +export const SET_QUERY_RESULT = "set-result"; +export const UPDATE_PAGE = "update-page"; +export const UPDATE_UI = "update-ui"; diff --git a/examples/triple-query/src/handlers.ts b/examples/triple-query/src/handlers.ts new file mode 100644 index 0000000000..769f3b5633 --- /dev/null +++ b/examples/triple-query/src/handlers.ts @@ -0,0 +1,84 @@ +import { IObjectOf } from "@thi.ng/api/api"; +import { compare } from "@thi.ng/compare"; +import { FX_DISPATCH_NOW, FX_STATE } from "@thi.ng/interceptors/api"; +import { EffectDef, EventDef } from "@thi.ng/interceptors/api"; +import { dispatchNow, valueSetter } from "@thi.ng/interceptors/interceptors"; +import { getIn, setIn } from "@thi.ng/paths"; +import { Triple } from "@thi.ng/rstream-query/api"; +import { comp } from "@thi.ng/transducers/func/comp"; +import { repeat } from "@thi.ng/transducers/iter/repeat"; +import { iterator } from "@thi.ng/transducers/iterator"; +import { mapIndexed } from "@thi.ng/transducers/xform/map-indexed"; +import { padLast } from "@thi.ng/transducers/xform/pad-last"; +import { page } from "@thi.ng/transducers/xform/page"; + +import { AppInterceptorContext } from "./api"; +import * as fx from "./effects"; +import * as ev from "./events"; + +export const PAGE_LEN = 5; + +export const EVENTS: IObjectOf = { + + [ev.ADD_COUNTRY]: (_, [__, [id, name, region]]) => ({ + [fx.ADD_TRIPLE]: [ + [id, "type", "country"], + [id, "name", name], + [id, "partOf", region], + [region, "type", "region"] + ], + }), + + [ev.ADD_CITY]: (_, [__, [city, countryID]]) => ({ + [fx.ADD_TRIPLE]: [ + [city, "type", "city"], + [city, "locatedIn", countryID] + ], + }), + + [ev.SET_SORT]: (state, [_, i]) => { + const sort = getIn(state, "sort"); + return { + [FX_STATE]: setIn(state, "sort", [i, sort[0] === i ? !sort[1] : false]), + [FX_DISPATCH_NOW]: [ev.UPDATE_PAGE] + }; + }, + + [ev.SET_PAGE]: [valueSetter("page"), dispatchNow([ev.UPDATE_PAGE])], + + [ev.UPDATE_PAGE]: (state, _, __, ctx: AppInterceptorContext) => { + const maxPage = Math.floor(Math.max(0, ctx.store.triples.length - 1) / PAGE_LEN); + let curr = getIn(state, "page"); + let sort = getIn(state, "sort"); + if (curr > maxPage) { + state = setIn(state, "page", curr = maxPage); + } + return { + [FX_STATE]: + setIn(state, "pagedTriples", + [...iterator( + comp( + page(curr, PAGE_LEN), + mapIndexed((i, x: Triple) => [i + 1, ...x], curr * PAGE_LEN), + padLast(PAGE_LEN, [...repeat("\u00a0", 4)]), + ), + ctx.store.triples.slice().sort(comparator.apply(null, sort)))]) + }; + }, +}; + +export const EFFECTS: IObjectOf = { + [fx.ADD_TRIPLE]: (triple: Triple, bus, ctx: AppInterceptorContext) => { + ctx.store.add(triple); + bus.dispatch([ev.UPDATE_PAGE]); + }, + [fx.REMOVE_TRIPLE]: (triple: Triple, bus, ctx: AppInterceptorContext) => { + ctx.store.delete(triple); + bus.dispatch([ev.UPDATE_PAGE]); + }, +}; + +const comparator = (i: number, rev: boolean) => + rev ? + (a, b) => compare(b[i], a[i]) : + (a, b) => compare(a[i], b[i]); diff --git a/examples/triple-query/src/index.ts b/examples/triple-query/src/index.ts new file mode 100644 index 0000000000..3031006634 --- /dev/null +++ b/examples/triple-query/src/index.ts @@ -0,0 +1,12 @@ +import { App } from "./app"; +import { CONFIG } from "./config"; + +// export app to global var in dev mode +// (for interaction via browser dev tools) +if (process.env.NODE_ENV == "development") { + (window["APP"] = new App(CONFIG)).start(); +} else { + new App(CONFIG).start(); +} + +window["equiv"] = require("@thi.ng/equiv").equiv; \ No newline at end of file diff --git a/examples/triple-query/tsconfig.json b/examples/triple-query/tsconfig.json new file mode 100644 index 0000000000..d3db7c6a95 --- /dev/null +++ b/examples/triple-query/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noUnusedLocals": false, + "outDir": "." + }, + "include": [ + "./src/**/*.ts" + ] +} \ No newline at end of file diff --git a/examples/webgl/README.md b/examples/webgl/README.md index d9f9db79c3..baf68109e0 100644 --- a/examples/webgl/README.md +++ b/examples/webgl/README.md @@ -1,8 +1,8 @@ # webgl -[Live demo](http://demo.thi.ng/umbrella/webgl/) +[Live demo](https://demo.thi.ng/umbrella/webgl/) -``` +```bash git clone https://github.com/thi-ng/umbrella.git cd umbrella/examples/webgl yarn install diff --git a/examples/webgl/package.json b/examples/webgl/package.json index 734394df2e..8c3485eabf 100644 --- a/examples/webgl/package.json +++ b/examples/webgl/package.json @@ -9,11 +9,11 @@ "start": "webpack-dev-server --open --mode development --devtool inline-source-map" }, "devDependencies": { - "ts-loader": "^4.3.0", - "typescript": "^2.8.3", - "webpack": "^4.8.1", - "webpack-cli": "^2.1.3", - "webpack-dev-server": "^3.1.4" + "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/hdom": "latest", diff --git a/package.json b/package.json index 9146ee88dd..ae498a2c9e 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,17 @@ "packages/*" ], "devDependencies": { + "babel-minify": "^0.4.3", "benchmark": "^2.1.4", "lerna": "^2.11.0", - "mocha": "^5.1.1", - "nyc": "^11.7.2", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "ts-loader": "^4.4.2", - "tslint": "^5.10.0", - "typescript": "^2.8.3", - "webpack": "^4.16.0", - "webpack-cli": "^3.0.8", - "webpack-dev-server": "^3.1.4" + "tslint": "^5.11.0", + "typescript": "^3.0.1", + "webpack": "^4.16.3", + "webpack-cli": "^3.1.0", + "webpack-dev-server": "^3.1.5" }, "scripts": { "bootstrap": "lerna bootstrap", @@ -25,4 +26,4 @@ "pub": "lerna publish && yarn doc && scripts/upload-docs", "test": "yarn build && lerna run test" } -} +} \ No newline at end of file diff --git a/packages/api/CHANGELOG.md b/packages/api/CHANGELOG.md index cf04a72ca7..ead88af2e7 100644 --- a/packages/api/CHANGELOG.md +++ b/packages/api/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.0.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/api@4.0.5...@thi.ng/api@4.0.6) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/api + ## [4.0.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/api@4.0.4...@thi.ng/api@4.0.5) (2018-07-20) diff --git a/packages/api/package.json b/packages/api/package.json index 01145c4833..024abcf8d6 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/api", - "version": "4.0.5", + "version": "4.0.6", "description": "Common, generic types & interfaces for thi.ng projects", "main": "./index.js", "typings": "./index.d.ts", @@ -20,15 +20,15 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/errors": "^0.1.5" + "@thi.ng/errors": "^0.1.6" }, "keywords": [ "compare", diff --git a/packages/api/src/decorators/deprecated.ts b/packages/api/src/decorators/deprecated.ts index 463ed21a8a..e3a918bb37 100644 --- a/packages/api/src/decorators/deprecated.ts +++ b/packages/api/src/decorators/deprecated.ts @@ -10,7 +10,7 @@ import { illegalArgs } from "@thi.ng/errors"; */ export function deprecated(msg?: string, log = console.log): MethodDecorator { return function (target: any, prop: string | symbol, descriptor: PropertyDescriptor) { - const signature = `${target.constructor.name}#${prop}`; + const signature = `${target.constructor.name}#${prop.toString()}`; const fn = descriptor.value; if (typeof fn !== "function") { illegalArgs(`${signature} is not a function`); diff --git a/packages/api/src/mixin.ts b/packages/api/src/mixin.ts index d92d915617..c060776535 100644 --- a/packages/api/src/mixin.ts +++ b/packages/api/src/mixin.ts @@ -24,7 +24,7 @@ export function mixin(behaviour: any, sharedBehaviour = {}) { writable: true, }); } else { - console.log(`not patching: ${clazz.name}.${key}`); + console.log(`not patching: ${clazz.name}.${key.toString()}`); } } Object.defineProperty(clazz.prototype, typeTag, { value: true }); diff --git a/packages/associative/CHANGELOG.md b/packages/associative/CHANGELOG.md index 8d742e6368..6e45252bf5 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.5.11](https://github.com/thi-ng/umbrella/compare/@thi.ng/associative@0.5.10...@thi.ng/associative@0.5.11) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/associative + ## [0.5.10](https://github.com/thi-ng/umbrella/compare/@thi.ng/associative@0.5.9...@thi.ng/associative@0.5.10) (2018-07-20) diff --git a/packages/associative/package.json b/packages/associative/package.json index 253a64168f..958b896e81 100644 --- a/packages/associative/package.json +++ b/packages/associative/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/associative", - "version": "0.5.10", + "version": "0.5.11", "description": "Alternative Set & Map data type implementations with customizable equality semantics & supporting operations", "main": "./index.js", "typings": "./index.d.ts", @@ -20,21 +20,21 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/compare": "^0.1.5", - "@thi.ng/dcons": "^1.0.6", - "@thi.ng/equiv": "^0.1.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/iterators": "^4.1.19" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/compare": "^0.1.6", + "@thi.ng/dcons": "^1.0.7", + "@thi.ng/equiv": "^0.1.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/iterators": "^4.1.20" }, "keywords": [ "data structures", diff --git a/packages/associative/src/invert.ts b/packages/associative/src/invert.ts index ca4f249bfb..35ca6ca375 100644 --- a/packages/associative/src/invert.ts +++ b/packages/associative/src/invert.ts @@ -35,7 +35,7 @@ export function invertMap(src: Map) { export function invertObj(src: IObjectOf) { const dest: IObjectOf = {}; for (let k in src) { - dest[src[k]] = k; + dest[src[k]] = k; } return dest; } diff --git a/packages/associative/src/select-keys.ts b/packages/associative/src/select-keys.ts index eb6bf9111e..28c60f18ac 100644 --- a/packages/associative/src/select-keys.ts +++ b/packages/associative/src/select-keys.ts @@ -30,7 +30,7 @@ export function selectKeysObj(src: IObjectOf, ks: Iterable): const dest: IObjectOf = {}; for (let k of ks) { if (src.hasOwnProperty(k)) { - dest[k] = src[k]; + dest[k] = src[k]; } } return dest; diff --git a/packages/atom/CHANGELOG.md b/packages/atom/CHANGELOG.md index 7ca3cdaa34..7b8702dfd4 100644 --- a/packages/atom/CHANGELOG.md +++ b/packages/atom/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.4.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/atom@1.4.5...@thi.ng/atom@1.4.6) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/atom + ## [1.4.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/atom@1.4.4...@thi.ng/atom@1.4.5) (2018-07-20) diff --git a/packages/atom/README.md b/packages/atom/README.md index 476d91b3b0..9e891eb725 100644 --- a/packages/atom/README.md +++ b/packages/atom/README.md @@ -271,7 +271,7 @@ and bundled This example is also available in standalone form: -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/login-form) | [Live demo](http://demo.thi.ng/umbrella/login-form/) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/login-form) | [Live demo](https://demo.thi.ng/umbrella/login-form/) ```ts import { Atom, setIn } from "@thi.ng/atom"; diff --git a/packages/atom/package.json b/packages/atom/package.json index 03c2cc4bb6..fbaf257937 100644 --- a/packages/atom/package.json +++ b/packages/atom/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/atom", - "version": "1.4.5", + "version": "1.4.6", "description": "Mutable wrapper for immutable values", "main": "./index.js", "typings": "./index.d.ts", @@ -20,19 +20,19 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/equiv": "^0.1.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/paths": "^1.5.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/equiv": "^0.1.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/paths": "^1.5.2" }, "keywords": [ "cursor", diff --git a/packages/bench/CHANGELOG.md b/packages/bench/CHANGELOG.md index 9d51c79956..78a5a0e3e0 100644 --- a/packages/bench/CHANGELOG.md +++ b/packages/bench/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.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/bench@0.1.4...@thi.ng/bench@0.1.5) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/bench + ## [0.1.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/bench@0.1.3...@thi.ng/bench@0.1.4) (2018-07-20) diff --git a/packages/bench/package.json b/packages/bench/package.json index 156fd890dd..cfb9dabf21 100644 --- a/packages/bench/package.json +++ b/packages/bench/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/bench", - "version": "0.1.4", + "version": "0.1.5", "description": "Basic benchmarking helpers", "main": "./index.js", "typings": "./index.d.ts", @@ -20,12 +20,12 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "keywords": [ "benchmark", diff --git a/packages/bitstream/CHANGELOG.md b/packages/bitstream/CHANGELOG.md index 3c0b65227a..88d984da58 100644 --- a/packages/bitstream/CHANGELOG.md +++ b/packages/bitstream/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.15](https://github.com/thi-ng/umbrella/compare/@thi.ng/bitstream@0.4.14...@thi.ng/bitstream@0.4.15) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/bitstream + ## [0.4.14](https://github.com/thi-ng/umbrella/compare/@thi.ng/bitstream@0.4.13...@thi.ng/bitstream@0.4.14) (2018-07-20) diff --git a/packages/bitstream/package.json b/packages/bitstream/package.json index 7e777027ba..e75dfffdb1 100644 --- a/packages/bitstream/package.json +++ b/packages/bitstream/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/bitstream", - "version": "0.4.14", + "version": "0.4.15", "description": "ES6 iterator based read/write bit streams & support for variable word widths", "main": "./index.js", "typings": "./index.d.ts", @@ -20,15 +20,15 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "dependencies": { - "@thi.ng/errors": "^0.1.5" + "@thi.ng/errors": "^0.1.6" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "keywords": [ "binary", diff --git a/packages/cache/CHANGELOG.md b/packages/cache/CHANGELOG.md index e235b8c8f3..6731e904cf 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.15](https://github.com/thi-ng/umbrella/compare/@thi.ng/cache@0.2.14...@thi.ng/cache@0.2.15) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/cache + ## [0.2.14](https://github.com/thi-ng/umbrella/compare/@thi.ng/cache@0.2.13...@thi.ng/cache@0.2.14) (2018-07-20) diff --git a/packages/cache/package.json b/packages/cache/package.json index 2af2d3d517..d272a579f3 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/cache", - "version": "0.2.14", + "version": "0.2.15", "description": "In-memory cache implementations with ES6 Map-like API and different eviction strategies", "main": "./index.js", "typings": "./index.d.ts", @@ -20,17 +20,17 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/dcons": "^1.0.6", - "@thi.ng/iterators": "^4.1.19" + "@thi.ng/api": "^4.0.6", + "@thi.ng/dcons": "^1.0.7", + "@thi.ng/iterators": "^4.1.20" }, "keywords": [ "cache", diff --git a/packages/checks/CHANGELOG.md b/packages/checks/CHANGELOG.md index 3964def0e1..c9b6bd73c5 100644 --- a/packages/checks/CHANGELOG.md +++ b/packages/checks/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.5.7](https://github.com/thi-ng/umbrella/compare/@thi.ng/checks@1.5.6...@thi.ng/checks@1.5.7) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/checks + ## [1.5.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/checks@1.5.5...@thi.ng/checks@1.5.6) (2018-07-20) diff --git a/packages/checks/package.json b/packages/checks/package.json index d50dbcffa3..6112de0a0b 100644 --- a/packages/checks/package.json +++ b/packages/checks/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/checks", - "version": "1.5.6", + "version": "1.5.7", "description": "Single-function sub-modules for type, feature & value checks", "main": "./index.js", "typings": "./index.d.ts", @@ -20,12 +20,12 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "keywords": [ "check", diff --git a/packages/compare/CHANGELOG.md b/packages/compare/CHANGELOG.md index 88e9649d39..3f9e09fa66 100644 --- a/packages/compare/CHANGELOG.md +++ b/packages/compare/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.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/compare@0.1.5...@thi.ng/compare@0.1.6) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/compare + ## [0.1.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/compare@0.1.4...@thi.ng/compare@0.1.5) (2018-07-20) diff --git a/packages/compare/package.json b/packages/compare/package.json index 56c493a916..cb1da07e5f 100644 --- a/packages/compare/package.json +++ b/packages/compare/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/compare", - "version": "0.1.5", + "version": "0.1.6", "description": "Comparator with optional delegation for types implementing @thi.ng/api/ICompare interface", "main": "./index.js", "typings": "./index.d.ts", @@ -20,12 +20,12 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "keywords": [ "comparator", diff --git a/packages/csp/CHANGELOG.md b/packages/csp/CHANGELOG.md index 9088592841..f63c2630b3 100644 --- a/packages/csp/CHANGELOG.md +++ b/packages/csp/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.3.53](https://github.com/thi-ng/umbrella/compare/@thi.ng/csp@0.3.52...@thi.ng/csp@0.3.53) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/csp + + +## [0.3.52](https://github.com/thi-ng/umbrella/compare/@thi.ng/csp@0.3.51...@thi.ng/csp@0.3.52) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/csp + ## [0.3.51](https://github.com/thi-ng/umbrella/compare/@thi.ng/csp@0.3.50...@thi.ng/csp@0.3.51) (2018-07-20) diff --git a/packages/csp/package.json b/packages/csp/package.json index e70247b7bb..980f6b5072 100644 --- a/packages/csp/package.json +++ b/packages/csp/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/csp", - "version": "0.3.51", + "version": "0.3.53", "description": "ES6 promise based CSP implementation", "main": "./index.js", "typings": "./index.d.ts", @@ -24,19 +24,19 @@ "testnode": "tsc -p test && node build/test/node.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/dcons": "^1.0.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/transducers": "^1.14.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/dcons": "^1.0.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/transducers": "^1.14.3" }, "keywords": [ "async", diff --git a/packages/dcons/CHANGELOG.md b/packages/dcons/CHANGELOG.md index 8b675801fa..8e18faf440 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.0.7](https://github.com/thi-ng/umbrella/compare/@thi.ng/dcons@1.0.6...@thi.ng/dcons@1.0.7) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/dcons + ## [1.0.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/dcons@1.0.5...@thi.ng/dcons@1.0.6) (2018-07-20) diff --git a/packages/dcons/package.json b/packages/dcons/package.json index 37b26257eb..5042024642 100644 --- a/packages/dcons/package.json +++ b/packages/dcons/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/dcons", - "version": "1.0.6", + "version": "1.0.7", "description": "Comprehensive doubly linked list structure w/ iterator support", "main": "./index.js", "typings": "./index.d.ts", @@ -20,19 +20,19 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/compare": "^0.1.5", - "@thi.ng/equiv": "^0.1.6", - "@thi.ng/errors": "^0.1.5" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/compare": "^0.1.6", + "@thi.ng/equiv": "^0.1.7", + "@thi.ng/errors": "^0.1.6" }, "keywords": [ "datastructure", diff --git a/packages/defmulti/CHANGELOG.md b/packages/defmulti/CHANGELOG.md index 19993bd17a..46a627d3e5 100644 --- a/packages/defmulti/CHANGELOG.md +++ b/packages/defmulti/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.7](https://github.com/thi-ng/umbrella/compare/@thi.ng/defmulti@0.3.6...@thi.ng/defmulti@0.3.7) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/defmulti + ## [0.3.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/defmulti@0.3.5...@thi.ng/defmulti@0.3.6) (2018-07-20) diff --git a/packages/defmulti/package.json b/packages/defmulti/package.json index e771d0d0ec..b94ba10092 100644 --- a/packages/defmulti/package.json +++ b/packages/defmulti/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/defmulti", - "version": "0.3.6", + "version": "0.3.7", "description": "Dynamically extensible multiple dispatch via user supplied dispatch function.", "main": "./index.js", "typings": "./index.d.ts", @@ -20,16 +20,16 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/errors": "^0.1.5" + "@thi.ng/api": "^4.0.6", + "@thi.ng/errors": "^0.1.6" }, "keywords": [ "ES6", diff --git a/packages/defmulti/src/index.ts b/packages/defmulti/src/index.ts index 3ef35ca144..4971ec70ca 100644 --- a/packages/defmulti/src/index.ts +++ b/packages/defmulti/src/index.ts @@ -2,7 +2,7 @@ import { IObjectOf } from "@thi.ng/api/api"; import { illegalArgs } from "@thi.ng/errors/illegal-arguments"; import { illegalArity } from "@thi.ng/errors/illegal-arity"; -export const DEFAULT = Symbol("DEFAULT"); +export const DEFAULT: unique symbol = Symbol(); export type DispatchFn = (...args) => PropertyKey; export type DispatchFn1 = (a: A) => PropertyKey; @@ -101,17 +101,17 @@ export function defmulti(f: any): MultiFn { let impls: IObjectOf> = {}; let fn: any = (...args) => { const id = f(...args); - const g = impls[id] || impls[DEFAULT]; - return g ? g(...args) : illegalArgs(`missing implementation for: "${id}"`); + const g = impls[id] || impls[DEFAULT]; + return g ? g(...args) : illegalArgs(`missing implementation for: "${id.toString()}"`); }; fn.add = (id: PropertyKey, g: Implementation) => { - if (impls[id]) return false; - impls[id] = g; + if (impls[id]) return false; + impls[id] = g; return true; }; fn.remove = (id: PropertyKey) => { - if (!impls[id]) return false; - delete impls[id]; + if (!impls[id]) return false; + delete impls[id]; return true; }; return fn; diff --git a/packages/dgraph/CHANGELOG.md b/packages/dgraph/CHANGELOG.md index ecdeb2b6f5..659af61fec 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.11](https://github.com/thi-ng/umbrella/compare/@thi.ng/dgraph@0.2.10...@thi.ng/dgraph@0.2.11) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/dgraph + ## [0.2.10](https://github.com/thi-ng/umbrella/compare/@thi.ng/dgraph@0.2.9...@thi.ng/dgraph@0.2.10) (2018-07-20) diff --git a/packages/dgraph/package.json b/packages/dgraph/package.json index a9d30da391..29a14f542c 100644 --- a/packages/dgraph/package.json +++ b/packages/dgraph/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/dgraph", - "version": "0.2.10", + "version": "0.2.11", "description": "Type-agnostic directed acyclic graph (DAG) & graph operations", "main": "./index.js", "typings": "./index.d.ts", @@ -20,19 +20,19 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/associative": "^0.5.10", - "@thi.ng/equiv": "^0.1.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/iterators": "^4.1.19" + "@thi.ng/api": "^4.0.6", + "@thi.ng/associative": "^0.5.11", + "@thi.ng/equiv": "^0.1.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/iterators": "^4.1.20" }, "keywords": [ "data structure", diff --git a/packages/diff/CHANGELOG.md b/packages/diff/CHANGELOG.md index 8e377b5c8d..30f7d88f22 100644 --- a/packages/diff/CHANGELOG.md +++ b/packages/diff/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.21](https://github.com/thi-ng/umbrella/compare/@thi.ng/diff@1.0.20...@thi.ng/diff@1.0.21) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/diff + ## [1.0.20](https://github.com/thi-ng/umbrella/compare/@thi.ng/diff@1.0.19...@thi.ng/diff@1.0.20) (2018-07-20) diff --git a/packages/diff/package.json b/packages/diff/package.json index 2ec254ae78..1661e2bcc3 100644 --- a/packages/diff/package.json +++ b/packages/diff/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/diff", - "version": "1.0.20", + "version": "1.0.21", "description": "Array & object Diff", "main": "./index.js", "typings": "./index.d.ts", @@ -19,15 +19,15 @@ "test": "rm -rf build && tsc -p test && mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/equiv": "^0.1.6" + "@thi.ng/api": "^4.0.6", + "@thi.ng/equiv": "^0.1.7" }, "keywords": [ "array", diff --git a/packages/dot/CHANGELOG.md b/packages/dot/CHANGELOG.md index dafdccc373..d8d35c6599 100644 --- a/packages/dot/CHANGELOG.md +++ b/packages/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.1.10](https://github.com/thi-ng/umbrella/compare/@thi.ng/dot@0.1.9...@thi.ng/dot@0.1.10) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/dot + ## [0.1.9](https://github.com/thi-ng/umbrella/compare/@thi.ng/dot@0.1.8...@thi.ng/dot@0.1.9) (2018-07-20) diff --git a/packages/dot/package.json b/packages/dot/package.json index 36b554b5c9..790c4e0a68 100644 --- a/packages/dot/package.json +++ b/packages/dot/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/dot", - "version": "0.1.9", + "version": "0.1.10", "description": "Graphviz DOM abstraction as vanilla JS objects & serialization to DOT format", "main": "./index.js", "typings": "./index.d.ts", @@ -20,16 +20,16 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7" }, "keywords": [ "ES6", diff --git a/packages/equiv/CHANGELOG.md b/packages/equiv/CHANGELOG.md index bf4d8e9df4..69a0095075 100644 --- a/packages/equiv/CHANGELOG.md +++ b/packages/equiv/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.7](https://github.com/thi-ng/umbrella/compare/@thi.ng/equiv@0.1.6...@thi.ng/equiv@0.1.7) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/equiv + ## [0.1.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/equiv@0.1.5...@thi.ng/equiv@0.1.6) (2018-07-20) diff --git a/packages/equiv/package.json b/packages/equiv/package.json index c18eebb3f1..856aaec1e8 100644 --- a/packages/equiv/package.json +++ b/packages/equiv/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/equiv", - "version": "0.1.6", + "version": "0.1.7", "description": "Extensible deep equivalence checking for any data types", "main": "./index.js", "typings": "./index.d.ts", @@ -20,15 +20,15 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/checks": "^1.5.6" + "@thi.ng/checks": "^1.5.7" }, "keywords": [ "deep", diff --git a/packages/errors/CHANGELOG.md b/packages/errors/CHANGELOG.md index 069e5fc8f5..4ee4458684 100644 --- a/packages/errors/CHANGELOG.md +++ b/packages/errors/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.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/errors@0.1.5...@thi.ng/errors@0.1.6) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/errors + ## [0.1.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/errors@0.1.4...@thi.ng/errors@0.1.5) (2018-07-20) diff --git a/packages/errors/package.json b/packages/errors/package.json index b1ace1d876..81a79882b0 100644 --- a/packages/errors/package.json +++ b/packages/errors/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/errors", - "version": "0.1.5", + "version": "0.1.6", "description": "Custom error types and helper fns.", "main": "./index.js", "typings": "./index.d.ts", @@ -20,12 +20,12 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "keywords": [ "error", diff --git a/packages/hdom-components/CHANGELOG.md b/packages/hdom-components/CHANGELOG.md index cc344443ed..e2f773110d 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.1.11](https://github.com/thi-ng/umbrella/compare/@thi.ng/hdom-components@2.1.10...@thi.ng/hdom-components@2.1.11) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/hdom-components + ## [2.1.10](https://github.com/thi-ng/umbrella/compare/@thi.ng/hdom-components@2.1.9...@thi.ng/hdom-components@2.1.10) (2018-07-20) diff --git a/packages/hdom-components/adr/0003-component-configuration-via-context.md b/packages/hdom-components/adr/0003-component-configuration-via-context.md index 51cdac8021..0ba4c14cba 100644 --- a/packages/hdom-components/adr/0003-component-configuration-via-context.md +++ b/packages/hdom-components/adr/0003-component-configuration-via-context.md @@ -18,7 +18,7 @@ whereas the previous solution ignored the context object entirely. A live demo of the code discussed here is available at: -[demo.thi.ng/umbrella/hdom-theme-adr-0003](http://demo.thi.ng/umbrella/hdom-theme-adr-0003) +[demo.thi.ng/umbrella/hdom-theme-adr-0003](https://demo.thi.ng/umbrella/hdom-theme-adr-0003) ## Decision diff --git a/packages/hdom-components/package.json b/packages/hdom-components/package.json index b81debdcea..2b358d9e65 100644 --- a/packages/hdom-components/package.json +++ b/packages/hdom-components/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/hdom-components", - "version": "2.1.10", + "version": "2.1.11", "description": "Raw, skinnable UI & SVG components for @thi.ng/hdom", "main": "./index.js", "typings": "./index.d.ts", @@ -20,17 +20,17 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/iterators": "^4.1.19", + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/iterators": "^4.1.20", "@types/webgl2": "^0.0.4" }, "keywords": [ diff --git a/packages/hdom/CHANGELOG.md b/packages/hdom/CHANGELOG.md index d1afea2198..a1318e5e9a 100644 --- a/packages/hdom/CHANGELOG.md +++ b/packages/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. + +## [3.0.31](https://github.com/thi-ng/umbrella/compare/@thi.ng/hdom@3.0.30...@thi.ng/hdom@3.0.31) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/hdom + ## [3.0.30](https://github.com/thi-ng/umbrella/compare/@thi.ng/hdom@3.0.29...@thi.ng/hdom@3.0.30) (2018-07-20) diff --git a/packages/hdom/README.md b/packages/hdom/README.md index 45fb04810f..3564218db2 100644 --- a/packages/hdom/README.md +++ b/packages/hdom/README.md @@ -104,7 +104,7 @@ hdom.start(document.body, app()); hdom.createDOM(document.body, hdom.normalizeTree(app())); ``` -[Live demo](http://demo.thi.ng/umbrella/hdom-basics/) | +[Live demo](https://demo.thi.ng/umbrella/hdom-basics/) | [standalone example](https://github.com/thi-ng/umbrella/tree/master/examples/hdom-basics) Alternatively, use the same component function for browser or server @@ -461,12 +461,12 @@ Non-exhaustive list: ### Interactive SVG grid generator [Source](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-grid) | -[Live version](http://demo.thi.ng/umbrella/rstream-grid/) +[Live version](https://demo.thi.ng/umbrella/rstream-grid/) ### Interactive additive waveform visualization [Source](https://github.com/thi-ng/umbrella/tree/master/examples/svg-waveform) | -[Live version](http://demo.thi.ng/umbrella/svg-waveform/) +[Live version](https://demo.thi.ng/umbrella/svg-waveform/) ### Dataflow graph SVG components @@ -474,7 +474,7 @@ This is a preview of the upcoming [@thi.ng/estuary](https://github.com/thi-ng/umbrella/tree/feature/estuary/packages/estuary) package: -[Source](https://github.com/thi-ng/umbrella/tree/feature/estuary/packages/estuary) | [Live version](http://demo.thi.ng/umbrella/estuary/) +[Source](https://github.com/thi-ng/umbrella/tree/feature/estuary/packages/estuary) | [Live version](https://demo.thi.ng/umbrella/estuary/) ### SPA with router and event bus @@ -482,58 +482,58 @@ Based on the `create-hdom-app` project scaffolding, this is one of the more advanced demos, combining functionality of several other @thi.ng packages. -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/router-basics) | [Live version](http://demo.thi.ng/umbrella/router-basics/) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/router-basics) | [Live version](https://demo.thi.ng/umbrella/router-basics/) ### Additive waveform synthesis & SVG visualization -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/svg-waveform) | [Live version](http://demo.thi.ng/umbrella/svg-waveform/) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/svg-waveform) | [Live version](https://demo.thi.ng/umbrella/svg-waveform/) ### Multiple apps with & without shared state Devcards style BMI calculator(s) with basic SVG viz. -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/devcards) | [Live version](http://demo.thi.ng/umbrella/devcards/) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/devcards) | [Live version](https://demo.thi.ng/umbrella/devcards/) ### Interceptor based event handling -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/interceptor-basics) | [Live version](http://demo.thi.ng/umbrella/interceptor-basics/) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/interceptor-basics) | [Live version](https://demo.thi.ng/umbrella/interceptor-basics/) ### Todo list A fully documented, obligatory todo list app with undo / redo. -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/todo-list) | [Live version](http://demo.thi.ng/umbrella/todo-list/) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/todo-list) | [Live version](https://demo.thi.ng/umbrella/todo-list/) ### Cellular automata -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/cellular-automata) | [Live version](http://demo.thi.ng/umbrella/cellular-automata/) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/cellular-automata) | [Live version](https://demo.thi.ng/umbrella/cellular-automata/) ### SVG particles -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/svg-particles) | [Live version](http://demo.thi.ng/umbrella/svg-particles/) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/svg-particles) | [Live version](https://demo.thi.ng/umbrella/svg-particles/) ### JSON based components -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/json-components) | [Live version](http://demo.thi.ng/umbrella/json-components/) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/json-components) | [Live version](https://demo.thi.ng/umbrella/json-components/) ### @thi.ng/rstream dataflow graph A small, interactive dataflow graph example: -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-dataflow) | [Live version](http://demo.thi.ng/umbrella/rstream-dataflow) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-dataflow) | [Live version](https://demo.thi.ng/umbrella/rstream-dataflow) ### Basic usage patterns The code below is also available as standalone project in: [/examples/dashboard](https://github.com/thi-ng/umbrella/tree/master/examples/dashboard) -[Source](https://github.com/thi-ng/umbrella/tree/master/examples/dashboard) | [Live version](http://demo.thi.ng/umbrella/dashboard/) +[Source](https://github.com/thi-ng/umbrella/tree/master/examples/dashboard) | [Live version](https://demo.thi.ng/umbrella/dashboard/) ### Benchmark A stress test benchmark is here: [/examples/benchmark](https://github.com/thi-ng/umbrella/tree/master/examples/hdom-benchmark) -[Live version](http://demo.thi.ng/umbrella/hdom-benchmark/) +[Live version](https://demo.thi.ng/umbrella/hdom-benchmark/) Based on [user feedback collected via Twitter](https://twitter.com/toxi/status/959246871339454464), diff --git a/packages/hdom/package.json b/packages/hdom/package.json index 679dab0658..2c6cb2eb0b 100644 --- a/packages/hdom/package.json +++ b/packages/hdom/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/hdom", - "version": "3.0.30", + "version": "3.0.31", "description": "Lightweight vanilla ES6 UI component & virtual DOM system", "main": "./index.js", "typings": "./index.d.ts", @@ -20,21 +20,21 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@thi.ng/atom": "^1.4.5", - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@thi.ng/atom": "^1.4.6", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/diff": "^1.0.20", - "@thi.ng/equiv": "^0.1.6", - "@thi.ng/hiccup": "^2.0.8", - "@thi.ng/iterators": "^4.1.19" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/diff": "^1.0.21", + "@thi.ng/equiv": "^0.1.7", + "@thi.ng/hiccup": "^2.0.9", + "@thi.ng/iterators": "^4.1.20" }, "keywords": [ "browser", diff --git a/packages/heaps/CHANGELOG.md b/packages/heaps/CHANGELOG.md index be0712e474..3130dc8802 100644 --- a/packages/heaps/CHANGELOG.md +++ b/packages/heaps/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.15](https://github.com/thi-ng/umbrella/compare/@thi.ng/heaps@0.2.14...@thi.ng/heaps@0.2.15) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/heaps + ## [0.2.14](https://github.com/thi-ng/umbrella/compare/@thi.ng/heaps@0.2.13...@thi.ng/heaps@0.2.14) (2018-07-20) diff --git a/packages/heaps/package.json b/packages/heaps/package.json index 2fb3fc49e2..3ba0cc8e94 100644 --- a/packages/heaps/package.json +++ b/packages/heaps/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/heaps", - "version": "0.2.14", + "version": "0.2.15", "description": "Generic binary heap & d-ary heap implementations with customizable ordering", "main": "./index.js", "typings": "./index.d.ts", @@ -20,16 +20,16 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/compare": "^0.1.5" + "@thi.ng/api": "^4.0.6", + "@thi.ng/compare": "^0.1.6" }, "keywords": [ "data structure", diff --git a/packages/hiccup-css/CHANGELOG.md b/packages/hiccup-css/CHANGELOG.md index bf5f646b35..0557f41f0b 100644 --- a/packages/hiccup-css/CHANGELOG.md +++ b/packages/hiccup-css/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.2.12](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup-css@0.2.11...@thi.ng/hiccup-css@0.2.12) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/hiccup-css + + +## [0.2.11](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup-css@0.2.10...@thi.ng/hiccup-css@0.2.11) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/hiccup-css + ## [0.2.10](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup-css@0.2.9...@thi.ng/hiccup-css@0.2.10) (2018-07-20) diff --git a/packages/hiccup-css/package.json b/packages/hiccup-css/package.json index cf6b958406..eb7a3fe7ab 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.10", + "version": "0.2.12", "description": "CSS from nested JS data structures", "main": "./index.js", "typings": "./index.d.ts", @@ -20,18 +20,18 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/transducers": "^1.14.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/transducers": "^1.14.3" }, "keywords": [ "clojure", diff --git a/packages/hiccup-svg/CHANGELOG.md b/packages/hiccup-svg/CHANGELOG.md index 02e07e697a..dcfa3ad58b 100644 --- a/packages/hiccup-svg/CHANGELOG.md +++ b/packages/hiccup-svg/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.9](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup-svg@1.0.8...@thi.ng/hiccup-svg@1.0.9) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/hiccup-svg + ## [1.0.8](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup-svg@1.0.7...@thi.ng/hiccup-svg@1.0.8) (2018-07-20) diff --git a/packages/hiccup-svg/package.json b/packages/hiccup-svg/package.json index 2400a28c8a..fa4452163c 100644 --- a/packages/hiccup-svg/package.json +++ b/packages/hiccup-svg/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/hiccup-svg", - "version": "1.0.8", + "version": "1.0.9", "description": "SVG element functions for @thi.ng/hiccup & @thi.ng/hdom", "main": "./index.js", "typings": "./index.d.ts", @@ -20,15 +20,15 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/hiccup": "^2.0.8" + "@thi.ng/hiccup": "^2.0.9" }, "keywords": [ "components", diff --git a/packages/hiccup/CHANGELOG.md b/packages/hiccup/CHANGELOG.md index 50cde0906e..383ce77c95 100644 --- a/packages/hiccup/CHANGELOG.md +++ b/packages/hiccup/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.9](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup@2.0.8...@thi.ng/hiccup@2.0.9) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/hiccup + ## [2.0.8](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup@2.0.7...@thi.ng/hiccup@2.0.8) (2018-07-20) diff --git a/packages/hiccup/package.json b/packages/hiccup/package.json index abd1f1d761..e4481bcd3d 100644 --- a/packages/hiccup/package.json +++ b/packages/hiccup/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/hiccup", - "version": "2.0.8", + "version": "2.0.9", "description": "HTML/SVG/XML serialization of nested data structures, iterables & closures", "main": "./index.js", "typings": "./index.d.ts", @@ -20,17 +20,17 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@thi.ng/atom": "^1.4.5", - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@thi.ng/atom": "^1.4.6", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/checks": "^1.5.6", - "@thi.ng/errors": "^0.1.5" + "@thi.ng/checks": "^1.5.7", + "@thi.ng/errors": "^0.1.6" }, "keywords": [ "clojure", diff --git a/packages/iges/CHANGELOG.md b/packages/iges/CHANGELOG.md index b294fc783a..7de56bd5db 100644 --- a/packages/iges/CHANGELOG.md +++ b/packages/iges/CHANGELOG.md @@ -3,6 +3,25 @@ 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/iges@0.1.4...@thi.ng/iges@0.2.0) (2018-08-01) + + +### Features + +* **iges:** add PolylineMode enum, update addPolyline2d() ([f7a084a](https://github.com/thi-ng/umbrella/commit/f7a084a)) + + + + + +## [0.1.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/iges@0.1.3...@thi.ng/iges@0.1.4) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/iges + ## [0.1.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/iges@0.1.2...@thi.ng/iges@0.1.3) (2018-07-20) diff --git a/packages/iges/README.md b/packages/iges/README.md index f6b16ff3e3..109d22b29e 100644 --- a/packages/iges/README.md +++ b/packages/iges/README.md @@ -46,7 +46,7 @@ iges.addPolyline2d(doc, [ [0, 0], [100, 100], [100, 0] -], false); +]); console.log(iges.serialize(doc)); ``` diff --git a/packages/iges/package.json b/packages/iges/package.json index ab47db69ef..bfa2e01c00 100644 --- a/packages/iges/package.json +++ b/packages/iges/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/iges", - "version": "0.1.3", + "version": "0.2.0", "description": "IGES 5.3 serializer for (currently only) polygonal geometry, both open & closed", "main": "./index.js", "typings": "./index.d.ts", @@ -20,17 +20,17 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/defmulti": "^0.3.6", - "@thi.ng/transducers": "^1.14.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/defmulti": "^0.3.7", + "@thi.ng/transducers": "^1.14.3" }, "keywords": [ "CAD", diff --git a/packages/iges/src/api.ts b/packages/iges/src/api.ts index d46111357c..91fbecf800 100644 --- a/packages/iges/src/api.ts +++ b/packages/iges/src/api.ts @@ -87,6 +87,12 @@ export enum StatusHierarchy { USE_PROP } +export enum PolylineMode { + OPEN, + CLOSED, + FILLED +} + // spec page 24 (53) export interface DictEntry { type: number; @@ -176,4 +182,4 @@ export const DEFAULT_GLOBALS: Partial = { precision: 3, numLineWeights: 1, maxLineWeight: 0.254, -}; \ No newline at end of file +}; diff --git a/packages/iges/src/index.ts b/packages/iges/src/index.ts index ac6903c9dd..7376126bdc 100644 --- a/packages/iges/src/index.ts +++ b/packages/iges/src/index.ts @@ -20,6 +20,7 @@ import { GlobalParams, IGESDocument, Param, + PolylineMode, Type, Unit } from "./api"; @@ -54,7 +55,7 @@ const $DATE = (d: Date) => $Z2(d.getUTCSeconds()) ].join("")); -export const newDocument = (g?: Partial): IGESDocument => { +export const newDocument = (g?: Partial, start?: string[]): IGESDocument => { const globals = { ...DEFAULT_GLOBALS, ...g }; const $FF = ff(globals.precision); const $PARAM = defmulti((x) => x[1]); @@ -66,7 +67,7 @@ export const newDocument = (g?: Partial): IGESDocument => { return { globals, - start: ["Generated by @thi.ng/iges"], + start: start || [], dict: [], param: [], offsets: { @@ -213,8 +214,8 @@ const formatParams = (doc: IGESDocument, params: Param[], fmtBody: (body: string // type table: page 38 (67) -// page 77 (106) -export const addPolyline2d = (doc: IGESDocument, pts: number[][], closed = false) => { +// sec 4.7, page 77 (106) +export const addPolyline2d = (doc: IGESDocument, pts: number[][], form = PolylineMode.OPEN) => { const did = doc.offsets.D; const pid = doc.offsets.P; const params = formatParams( @@ -222,13 +223,15 @@ export const addPolyline2d = (doc: IGESDocument, pts: number[][], closed = false [ [106, Type.INT], [1, Type.INT], - [pts.length + (closed ? 1 : 0), Type.INT], + [pts.length + (form === PolylineMode.CLOSED ? 1 : 0), Type.INT], [0, Type.FLOAT], ...iterator( mapcat( ([x, y]) => [[x, Type.FLOAT], [y, Type.FLOAT]] ), - closed ? wrap(pts, 1, false, true) : pts + form === PolylineMode.CLOSED ? + wrap(pts, 1, false, true) : + pts ) ], formatParam(did, pid) @@ -237,7 +240,7 @@ export const addPolyline2d = (doc: IGESDocument, pts: number[][], closed = false doc.offsets.D += 2; doc.dict.push(...formatDictEntry({ type: 106, - form: 11, + form: form === PolylineMode.FILLED ? 63 : 11, param: pid, index: did, lineCount: params.length, @@ -246,4 +249,12 @@ export const addPolyline2d = (doc: IGESDocument, pts: number[][], closed = false return doc; }; +export const addPolygon2d = (doc: IGESDocument, pts: number[][]) => + addPolyline2d(doc, pts, PolylineMode.FILLED); + +// sec 4.23, page 123 (type 126) +// export const addNurbsCurve2d = (doc: IGESDocument, degree: number, pts: number[][], closed = false) => { +// doc; degree; pts; closed; +// }; + export * from "./api"; \ No newline at end of file diff --git a/packages/iges/test/index.ts b/packages/iges/test/index.ts index 32d5c2f60d..b8977f1f15 100644 --- a/packages/iges/test/index.ts +++ b/packages/iges/test/index.ts @@ -26,7 +26,7 @@ describe("iges", () => { [0, 0], [100, 100], [100, 0] - ], false); + ]); assert.equal( iges.serialize(doc), diff --git a/packages/interceptors/CHANGELOG.md b/packages/interceptors/CHANGELOG.md index 791ee802cd..9b0710c674 100644 --- a/packages/interceptors/CHANGELOG.md +++ b/packages/interceptors/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.8.9](https://github.com/thi-ng/umbrella/compare/@thi.ng/interceptors@1.8.8...@thi.ng/interceptors@1.8.9) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/interceptors + ## [1.8.8](https://github.com/thi-ng/umbrella/compare/@thi.ng/interceptors@1.8.7...@thi.ng/interceptors@1.8.8) (2018-07-20) diff --git a/packages/interceptors/README.md b/packages/interceptors/README.md index 941b8273d7..b0e6c566cb 100644 --- a/packages/interceptors/README.md +++ b/packages/interceptors/README.md @@ -38,15 +38,15 @@ and examples for now: Introductory: -- [/examples/interceptor-basics](https://github.com/thi-ng/umbrella/tree/master/examples/interceptor-basics) | [live demo](http://demo.thi.ng/umbrella/interceptor-basics) -- [/examples/async-effect](https://github.com/thi-ng/umbrella/tree/master/examples/async-effect) | [live demo](http://demo.thi.ng/umbrella/async-effect) +- [/examples/interceptor-basics](https://github.com/thi-ng/umbrella/tree/master/examples/interceptor-basics) | [live demo](https://demo.thi.ng/umbrella/interceptor-basics) +- [/examples/async-effect](https://github.com/thi-ng/umbrella/tree/master/examples/async-effect) | [live demo](https://demo.thi.ng/umbrella/async-effect) Advanced: -- [/examples/rstream-dataflow](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-dataflow) | [live demo](http://demo.thi.ng/umbrella/rstream-dataflow) -- [/examples/rstream-grid](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-grid) | [live demo](http://demo.thi.ng/umbrella/rstream-grid) -- [/examples/router-basics](https://github.com/thi-ng/umbrella/tree/master/examples/router-basics) | [live demo](http://demo.thi.ng/umbrella/router-basics) -- [/examples/svg-waveform](https://github.com/thi-ng/umbrella/tree/master/examples/svg-waveform) | [live demo](http://demo.thi.ng/umbrella/svg-waveform) +- [/examples/rstream-dataflow](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-dataflow) | [live demo](https://demo.thi.ng/umbrella/rstream-dataflow) +- [/examples/rstream-grid](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-grid) | [live demo](https://demo.thi.ng/umbrella/rstream-grid) +- [/examples/router-basics](https://github.com/thi-ng/umbrella/tree/master/examples/router-basics) | [live demo](https://demo.thi.ng/umbrella/router-basics) +- [/examples/svg-waveform](https://github.com/thi-ng/umbrella/tree/master/examples/svg-waveform) | [live demo](https://demo.thi.ng/umbrella/svg-waveform) - [create-hdom-app](https://github.com/thi-ng/create-hdom-app) Yarn project generator. Uses: @thi.ng/atom + hdom + interceptors + router diff --git a/packages/interceptors/package.json b/packages/interceptors/package.json index 8c212f3353..15fc5bffc4 100644 --- a/packages/interceptors/package.json +++ b/packages/interceptors/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/interceptors", - "version": "1.8.8", + "version": "1.8.9", "description": "Interceptor based event bus, side effect & immutable state handling", "main": "./index.js", "typings": "./index.d.ts", @@ -20,19 +20,19 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/atom": "^1.4.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/paths": "^1.5.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/atom": "^1.4.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/paths": "^1.5.2" }, "keywords": [ "ES6", diff --git a/packages/interceptors/src/event-bus.ts b/packages/interceptors/src/event-bus.ts index d729e01590..ce00512b2c 100644 --- a/packages/interceptors/src/event-bus.ts +++ b/packages/interceptors/src/event-bus.ts @@ -397,9 +397,9 @@ export class StatelessEventBus implements * @param e */ protected processEvent(ctx: api.InterceptorContext, e: api.Event) { - const iceps = this.handlers[e[0]]; + const iceps = this.handlers[e[0]]; if (!iceps) { - console.warn(`missing handler for event type: ${e[0]}`); + console.warn(`missing handler for event type: ${e[0].toString()}`); return; } const n = iceps.length - 1; diff --git a/packages/iterators/CHANGELOG.md b/packages/iterators/CHANGELOG.md index ae643a3760..5ff9e384ab 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.20](https://github.com/thi-ng/umbrella/compare/@thi.ng/iterators@4.1.19...@thi.ng/iterators@4.1.20) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/iterators + ## [4.1.19](https://github.com/thi-ng/umbrella/compare/@thi.ng/iterators@4.1.18...@thi.ng/iterators@4.1.19) (2018-07-20) diff --git a/packages/iterators/package.json b/packages/iterators/package.json index ffb253c3e3..846b311707 100644 --- a/packages/iterators/package.json +++ b/packages/iterators/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/iterators", - "version": "4.1.19", + "version": "4.1.20", "description": "clojure.core inspired, composable ES6 iterators & generators", "main": "./index.js", "typings": "./index.d.ts", @@ -20,17 +20,17 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/dcons": "^1.0.6", - "@thi.ng/errors": "^0.1.5" + "@thi.ng/api": "^4.0.6", + "@thi.ng/dcons": "^1.0.7", + "@thi.ng/errors": "^0.1.6" }, "keywords": [ "clojure", diff --git a/packages/paths/CHANGELOG.md b/packages/paths/CHANGELOG.md index 5f3e173392..4f33b006e1 100644 --- a/packages/paths/CHANGELOG.md +++ b/packages/paths/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.5.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/paths@1.5.1...@thi.ng/paths@1.5.2) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/paths + ## [1.5.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/paths@1.5.0...@thi.ng/paths@1.5.1) (2018-07-20) diff --git a/packages/paths/package.json b/packages/paths/package.json index 9bb1263963..37e6337056 100644 --- a/packages/paths/package.json +++ b/packages/paths/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/paths", - "version": "1.5.1", + "version": "1.5.2", "description": "immutable, optimized path-based object property / array accessors", "main": "./index.js", "typings": "./index.d.ts", @@ -20,16 +20,16 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/checks": "^1.5.6", - "@thi.ng/errors": "^0.1.5" + "@thi.ng/checks": "^1.5.7", + "@thi.ng/errors": "^0.1.6" }, "keywords": [ "accessors", diff --git a/packages/pointfree-lang/CHANGELOG.md b/packages/pointfree-lang/CHANGELOG.md index cf2d6e3157..9cb0492627 100644 --- a/packages/pointfree-lang/CHANGELOG.md +++ b/packages/pointfree-lang/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/pointfree-lang@0.2.16...@thi.ng/pointfree-lang@0.2.17) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/pointfree-lang + ## [0.2.16](https://github.com/thi-ng/umbrella/compare/@thi.ng/pointfree-lang@0.2.15...@thi.ng/pointfree-lang@0.2.16) (2018-07-20) diff --git a/packages/pointfree-lang/package.json b/packages/pointfree-lang/package.json index a7e04c1f4f..d8d144cb76 100644 --- a/packages/pointfree-lang/package.json +++ b/packages/pointfree-lang/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/pointfree-lang", - "version": "0.2.16", + "version": "0.2.17", "description": "Forth style syntax layer/compiler for the @thi.ng/pointfree DSL", "main": "./index.js", "typings": "./index.d.ts", @@ -22,17 +22,17 @@ "test": "rm -rf build && tsc -p test && yarn pegtest && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", "pegjs": "^0.10.0", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/pointfree": "^0.8.5" + "@thi.ng/api": "^4.0.6", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/pointfree": "^0.8.6" }, "keywords": [ "concatenative", diff --git a/packages/pointfree/CHANGELOG.md b/packages/pointfree/CHANGELOG.md index 56af56d1b4..ce3137f1c6 100644 --- a/packages/pointfree/CHANGELOG.md +++ b/packages/pointfree/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.8.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/pointfree@0.8.5...@thi.ng/pointfree@0.8.6) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/pointfree + ## [0.8.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/pointfree@0.8.4...@thi.ng/pointfree@0.8.5) (2018-07-20) diff --git a/packages/pointfree/package.json b/packages/pointfree/package.json index cdb6f7177a..408aab3f7a 100644 --- a/packages/pointfree/package.json +++ b/packages/pointfree/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/pointfree", - "version": "0.8.5", + "version": "0.8.6", "description": "Pointfree functional composition / Forth style stack execution engine", "main": "./index.js", "typings": "./index.d.ts", @@ -20,18 +20,18 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/equiv": "^0.1.6", - "@thi.ng/errors": "^0.1.5" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/equiv": "^0.1.7", + "@thi.ng/errors": "^0.1.6" }, "keywords": [ "composition", diff --git a/packages/pointfree/src/index.ts b/packages/pointfree/src/index.ts index 2f1fa66347..beb08673f9 100644 --- a/packages/pointfree/src/index.ts +++ b/packages/pointfree/src/index.ts @@ -1754,7 +1754,7 @@ export const store = (ctx: StackContext) => */ export const loadkey = (key: PropertyKey) => (ctx: StackContext) => { - !ctx[2].hasOwnProperty(key) && illegalArgs(`unknown var: ${key}`); + !ctx[2].hasOwnProperty(key) && illegalArgs(`unknown var: ${key.toString()}`); ctx[0].push(ctx[2][key]); return ctx; }; diff --git a/packages/range-coder/.npmignore b/packages/range-coder/.npmignore new file mode 100644 index 0000000000..538f8b608d --- /dev/null +++ b/packages/range-coder/.npmignore @@ -0,0 +1,14 @@ +bench/* +build/* +dev/* +node_modules +src* +test* +bundle.* +tsconfig.json +webpack.config.js +*.html +*.tgz +!doc/* +!*.d.ts +!*.js diff --git a/packages/range-coder/CHANGELOG.md b/packages/range-coder/CHANGELOG.md new file mode 100644 index 0000000000..e4dae9f758 --- /dev/null +++ b/packages/range-coder/CHANGELOG.md @@ -0,0 +1,28 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + + +## [0.1.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/range-coder@0.1.1...@thi.ng/range-coder@0.1.2) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/range-coder + + +## [0.1.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/range-coder@0.1.0...@thi.ng/range-coder@0.1.1) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/range-coder + + +# 0.1.0 (2018-07-21) + + +### Features + +* **range-coder:** re-import [@thi](https://github.com/thi).ng/range-coder package from MB2010 ([76dc450](https://github.com/thi-ng/umbrella/commit/76dc450)) diff --git a/packages/range-coder/README.md b/packages/range-coder/README.md new file mode 100644 index 0000000000..33d8b8f975 --- /dev/null +++ b/packages/range-coder/README.md @@ -0,0 +1,53 @@ +# @thi.ng/range-coder + +[![npm (scoped)](https://img.shields.io/npm/v/@thi.ng/range-coder.svg)](https://www.npmjs.com/package/@thi.ng/range-coder) + +This project is part of the +[@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo. + +## About + +Range encoder / decoder for binary data, based on [Java implementation +by Joe Halliwell](https://www.winterwell.com/software/compressor.php). + +## Installation + +```bash +yarn add @thi.ng/range-coder +``` + +## Dependencies + +- [@thi.ng/bitstream](https://github.com/thi-ng/umbrella/tree/master/packages/bitstream) + +## API + +```ts +import * as rc "@thi.ng/range-coder"; +``` + +```ts +// prepare dummy data +src = new Uint8Array(1024); +src.set([1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,4,4,3,3,3,2,2,2,2,1,1,1,1,1], 512); + +// pack data +packed = rc.encodeBytes(src); + +packed.length +// 146 + +packed.length/src.length +// 0.142578125 + +// unpack +dest = rc.decodeBytes(packed); +``` + +## Authors + +- Karsten Schmidt + +## License + +© 2017 Karsten Schmidt // Apache Software License 2.0 diff --git a/packages/range-coder/package.json b/packages/range-coder/package.json new file mode 100644 index 0000000000..7f6cdff99a --- /dev/null +++ b/packages/range-coder/package.json @@ -0,0 +1,45 @@ +{ + "name": "@thi.ng/range-coder", + "version": "0.1.2", + "description": "Binary data range encoder / decoder", + "main": "./index.js", + "typings": "./index.d.ts", + "repository": { + "type": "git", + "url": "https://github.com/thi-ng/umbrella.git" + }, + "homepage": "https://github.com/thi-ng/umbrella/tree/master/packages/rstream", + "author": "Karsten Schmidt ", + "license": "Apache-2.0", + "scripts": { + "build": "yarn clean && tsc --declaration", + "clean": "rm -rf *.js *.d.ts .nyc_output build coverage doc", + "cover": "yarn test && nyc report --reporter=lcov", + "doc": "node_modules/.bin/typedoc --mode modules --out doc src", + "pub": "yarn build && yarn publish --access public", + "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" + }, + "devDependencies": { + "@thi.ng/transducers": "^1.14.3", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", + "typedoc": "^0.11.1", + "typescript": "^3.0.1" + }, + "dependencies": { + "@thi.ng/bitstream": "^0.4.15" + }, + "keywords": [ + "ES6", + "binary", + "entropy", + "packer", + "range encoding", + "typescript" + ], + "publishConfig": { + "access": "public" + } +} diff --git a/packages/range-coder/src/index.ts b/packages/range-coder/src/index.ts new file mode 100644 index 0000000000..f80d5147c2 --- /dev/null +++ b/packages/range-coder/src/index.ts @@ -0,0 +1,135 @@ +import { BitInputStream, BitOutputStream } from "@thi.ng/bitstream"; + +const HIGH = 0x7fffff; +const HALF = 0x400000; +const QUARTER = 0x200000; +const THREE_QUARTER = 0x600000; +const INITIAL_READ = 23; +const FREQ = 257; + +export const encodeBytes = (src: Uint8Array) => { + const freq = new Uint32Array(FREQ).fill(1); + const out = new BitOutputStream(Math.max(src.length >> 1, 1)); + const len = src.length; + let total = FREQ; + let lo = 0; + let hi = HIGH; + let _lo = lo; + let _hi = hi; + let step; + let scale = 0; + let curr = 0; + let i, j; + + for (i = 0; i <= len; i++) { + if (i === len) { + lo = total - 1; + hi = total; + } else { + curr = src[i]; + lo = 0; + for (j = 0; j < curr; j++) { + lo += freq[j]; + } + hi = lo + freq[curr]; + } + + step = ((_hi - _lo + 1) / total) >>> 0; + _hi = _lo + step * hi - 1; + _lo += step * lo; + + while (true) { + if (_hi < HALF) { + out.writeBit(0); + _lo <<= 1; + _hi = (_hi << 1) + 1; + scale && out.write(HIGH, scale); + } else if (_lo >= HALF) { + out.writeBit(1); + _lo = (_lo - HALF) << 1; + _hi = ((_hi - HALF) << 1) + 1; + scale && out.write(0, scale); + } else { + break; + } + scale = 0; + } + + while (_lo > QUARTER && _hi < THREE_QUARTER) { + scale++; + _lo = (_lo - QUARTER) << 1; + _hi = ((_hi - QUARTER) << 1) + 1; + } + + freq[curr]++; + total++; + } + if (_lo < QUARTER) { + out.writeBit(0); + out.write(HIGH, scale + 1); + } else { + out.writeBit(1); + } + return out.bytes(); +}; + +export const decodeBytes = (src: Uint8Array) => { + const freq = new Uint32Array(FREQ).fill(1); + const input = new BitInputStream(src) + const nbits = input.length + const out = [] + let total = FREQ + let current = 0 + let lo = 0 + let hi = HIGH + let _lo = lo + let _hi = hi + let step = 0 + let buf = input.read(INITIAL_READ) + let val; + + const read = () => input.position < nbits ? input.readBit() : 0; + + while (true) { + step = ((_hi - _lo + 1) / total) >>> 0; + val = ((buf - _lo) / step) >>> 0; + lo = 0; + for (current = 0; current < 256 && lo + freq[current] <= val; current++) { + lo += freq[current]; + } + if (current === 256) break; + + out.push(current); + hi = lo + freq[current]; + + _hi = _lo + step * hi - 1; + _lo += step * lo; + + while (true) { + if (_hi < HALF) { + buf <<= 1; + _lo <<= 1; + _hi = (_hi << 1) + 1; + } else if (_lo >= HALF) { + buf = (buf - HALF) << 1; + _lo = (_lo - HALF) << 1; + _hi = ((_hi - HALF) << 1) + 1; + } else { + break; + } + buf += read(); + } + + while (_lo > QUARTER && _hi < THREE_QUARTER) { + _lo = (_lo - QUARTER) << 1; + _hi = ((_hi - QUARTER) << 1) + 1; + buf = (buf - QUARTER) << 1; + buf += read(); + } + + freq[current]++; + total++; + } + + return new Uint8Array(out); +}; diff --git a/packages/range-coder/test/index.ts b/packages/range-coder/test/index.ts new file mode 100644 index 0000000000..1c9d6abba8 --- /dev/null +++ b/packages/range-coder/test/index.ts @@ -0,0 +1,26 @@ +import { repeat, repeatedly } from "@thi.ng/transducers"; +import * as assert from "assert"; +import { decodeBytes, encodeBytes } from "../src"; + +describe("range-coder", () => { + + it("fixed", () => { + const src = new Uint8Array([10, 20, 30, 10, 10, 10]); + const dest = encodeBytes(src); + assert.deepEqual(dest, [10, 10, 224, 160, 49, 91, 88]); + assert.deepEqual(src, decodeBytes(dest)); + }); + + it("fuzz", () => { + for (let i = 0; i < 10; i++) { + const src = randomArray(640, 1024); + const dest = encodeBytes(src); + console.log(`${(dest.length / src.length * 100).toFixed(2)}%`); + assert.deepEqual(src, decodeBytes(dest)); + } + }); +}); + +function randomArray(n: number, len: number) { + return new Uint8Array([...repeatedly(() => ~~(Math.random() * 256), n), ...repeat(0, len - n)]); +} diff --git a/packages/range-coder/test/tsconfig.json b/packages/range-coder/test/tsconfig.json new file mode 100644 index 0000000000..13d45669e5 --- /dev/null +++ b/packages/range-coder/test/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "outDir": "../build" + }, + "include": [ + "./**/*.ts", + "../src/**/*.ts" + ] +} \ No newline at end of file diff --git a/packages/range-coder/tsconfig.json b/packages/range-coder/tsconfig.json new file mode 100644 index 0000000000..fe4ca75067 --- /dev/null +++ b/packages/range-coder/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "." + }, + "include": [ + "./src/**/*.ts", + ] +} \ No newline at end of file diff --git a/packages/resolve-map/CHANGELOG.md b/packages/resolve-map/CHANGELOG.md index d8d8970df4..2c428dc468 100644 --- a/packages/resolve-map/CHANGELOG.md +++ b/packages/resolve-map/CHANGELOG.md @@ -3,7 +3,15 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - + +## [3.0.7](https://github.com/thi-ng/umbrella/compare/@thi.ng/resolve-map@3.0.6...@thi.ng/resolve-map@3.0.7) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/resolve-map + + ## [3.0.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/resolve-map@3.0.5...@thi.ng/resolve-map@3.0.6) (2018-07-20) @@ -11,7 +19,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @thi.ng/resolve-map - + ## [3.0.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/resolve-map@3.0.4...@thi.ng/resolve-map@3.0.5) (2018-07-15) diff --git a/packages/resolve-map/package.json b/packages/resolve-map/package.json index 950d612f95..8a780a9a91 100644 --- a/packages/resolve-map/package.json +++ b/packages/resolve-map/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/resolve-map", - "version": "3.0.6", + "version": "3.0.7", "description": "DAG resolution of vanilla objects & arrays with internally linked values", "main": "./index.js", "typings": "./index.d.ts", @@ -19,16 +19,16 @@ "test": "rm -rf build && tsc -p test && mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/checks": "^1.5.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/paths": "^1.5.1" + "@thi.ng/checks": "^1.5.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/paths": "^1.5.2" }, "keywords": [ "configuration", diff --git a/packages/rle-pack/CHANGELOG.md b/packages/rle-pack/CHANGELOG.md index f811ee9b2e..febe8136f4 100644 --- a/packages/rle-pack/CHANGELOG.md +++ b/packages/rle-pack/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.24](https://github.com/thi-ng/umbrella/compare/@thi.ng/rle-pack@0.2.23...@thi.ng/rle-pack@0.2.24) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/rle-pack + ## [0.2.23](https://github.com/thi-ng/umbrella/compare/@thi.ng/rle-pack@0.2.22...@thi.ng/rle-pack@0.2.23) (2018-07-20) diff --git a/packages/rle-pack/package.json b/packages/rle-pack/package.json index 50139a3276..a25766fbba 100644 --- a/packages/rle-pack/package.json +++ b/packages/rle-pack/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/rle-pack", - "version": "0.2.23", + "version": "0.2.24", "description": "Binary run-length encoding packer w/ flexible repeat bit widths", "main": "./index.js", "typings": "./index.d.ts", @@ -20,16 +20,16 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", "benchmark": "^2.1.4", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/bitstream": "^0.4.14" + "@thi.ng/bitstream": "^0.4.15" }, "keywords": [ "binary", diff --git a/packages/router/CHANGELOG.md b/packages/router/CHANGELOG.md index 92318a7b9c..35c982107c 100644 --- a/packages/router/CHANGELOG.md +++ b/packages/router/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.20](https://github.com/thi-ng/umbrella/compare/@thi.ng/router@0.1.19...@thi.ng/router@0.1.20) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/router + ## [0.1.19](https://github.com/thi-ng/umbrella/compare/@thi.ng/router@0.1.18...@thi.ng/router@0.1.19) (2018-07-20) diff --git a/packages/router/README.md b/packages/router/README.md index 666fe37757..f3a5aab90f 100644 --- a/packages/router/README.md +++ b/packages/router/README.md @@ -50,7 +50,7 @@ yarn start A complete, full commented demo app is here: -[Source](https://github.com/thi-ng/umbrella/blob/master/examples/router-basics/) | [Live demo](http://demo.thi.ng/umbrella/router-basics/) +[Source](https://github.com/thi-ng/umbrella/blob/master/examples/router-basics/) | [Live demo](https://demo.thi.ng/umbrella/router-basics/) ```ts import * as r from "@thi.ng/router"; diff --git a/packages/router/package.json b/packages/router/package.json index d19ccae725..1583677f89 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/router", - "version": "0.1.19", + "version": "0.1.20", "description": "Generic router for browser & non-browser based applications", "main": "./index.js", "typings": "./index.d.ts", @@ -19,18 +19,18 @@ "test": "rm -rf build && tsc -p test && mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/equiv": "^0.1.6", - "@thi.ng/errors": "^0.1.5" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/equiv": "^0.1.7", + "@thi.ng/errors": "^0.1.6" }, "keywords": [ "declarative", diff --git a/packages/router/src/basic.ts b/packages/router/src/basic.ts index 2da88c3f25..1adea4593a 100644 --- a/packages/router/src/basic.ts +++ b/packages/router/src/basic.ts @@ -123,7 +123,7 @@ export class BasicRouter implements .map((x) => x.charAt(0) === "?" ? ((x = params[x.substr(1)]) != null ? x : "NULL") : x) .join(this.config.separator); } else { - illegalArgs(`invalid route ID: ${match.id}`); + illegalArgs(`invalid route ID: ${match.id.toString()}`); } } diff --git a/packages/rstream-csp/CHANGELOG.md b/packages/rstream-csp/CHANGELOG.md index 73f6c4ea44..18a0c8d2e3 100644 --- a/packages/rstream-csp/CHANGELOG.md +++ b/packages/rstream-csp/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.1.91](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-csp@0.1.90...@thi.ng/rstream-csp@0.1.91) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/rstream-csp + + +## [0.1.90](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-csp@0.1.89...@thi.ng/rstream-csp@0.1.90) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/rstream-csp + ## [0.1.89](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-csp@0.1.88...@thi.ng/rstream-csp@0.1.89) (2018-07-20) diff --git a/packages/rstream-csp/package.json b/packages/rstream-csp/package.json index b50f634cfa..9246e1bdf4 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.89", + "version": "0.1.91", "description": "@thi.ng/csp bridge module for @thi.ng/rstream", "main": "./index.js", "typings": "./index.d.ts", @@ -20,16 +20,16 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/csp": "^0.3.51", - "@thi.ng/rstream": "^1.10.0" + "@thi.ng/csp": "^0.3.53", + "@thi.ng/rstream": "^1.10.2" }, "keywords": [ "bridge", diff --git a/packages/rstream-dot/CHANGELOG.md b/packages/rstream-dot/CHANGELOG.md index 495813d010..a2c321f89a 100644 --- a/packages/rstream-dot/CHANGELOG.md +++ b/packages/rstream-dot/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.2.30](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-dot@0.2.29...@thi.ng/rstream-dot@0.2.30) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/rstream-dot + + +## [0.2.29](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-dot@0.2.28...@thi.ng/rstream-dot@0.2.29) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/rstream-dot + ## [0.2.28](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-dot@0.2.27...@thi.ng/rstream-dot@0.2.28) (2018-07-20) diff --git a/packages/rstream-dot/package.json b/packages/rstream-dot/package.json index 98d48cf873..82672cc847 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.28", + "version": "0.2.30", "description": "Graphviz DOT conversion of @thi.ng/rstream dataflow graph topologies", "main": "./index.js", "typings": "./index.d.ts", @@ -20,15 +20,15 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/rstream": "^1.10.0" + "@thi.ng/rstream": "^1.10.2" }, "keywords": [ "conversion", diff --git a/packages/rstream-gestures/CHANGELOG.md b/packages/rstream-gestures/CHANGELOG.md index 13ba21af2a..03ebeefde0 100644 --- a/packages/rstream-gestures/CHANGELOG.md +++ b/packages/rstream-gestures/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.4.11](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-gestures@0.4.10...@thi.ng/rstream-gestures@0.4.11) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/rstream-gestures + + +## [0.4.10](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-gestures@0.4.9...@thi.ng/rstream-gestures@0.4.10) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/rstream-gestures + ## [0.4.9](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-gestures@0.4.8...@thi.ng/rstream-gestures@0.4.9) (2018-07-20) diff --git a/packages/rstream-gestures/README.md b/packages/rstream-gestures/README.md index b2ddf2917e..4c9e4214fa 100644 --- a/packages/rstream-gestures/README.md +++ b/packages/rstream-gestures/README.md @@ -10,7 +10,7 @@ This project is part of the Unified mouse, mouse wheel & single-touch event stream abstraction. Stream emits tuples of: -``` +```ts [type, {pos, click?, delta?, zoom}] ``` @@ -39,7 +39,7 @@ yarn add @thi.ng/rstream-gestures A small, fully commented project can be found in the `/examples` folder: [Source](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-dataflow) | -[Live version](http://demo.thi.ng/umbrella/rstream-dataflow) +[Live version](https://demo.thi.ng/umbrella/rstream-dataflow) ### Basic usage diff --git a/packages/rstream-gestures/package.json b/packages/rstream-gestures/package.json index 6c2d268ae0..d9760f22ac 100644 --- a/packages/rstream-gestures/package.json +++ b/packages/rstream-gestures/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/rstream-gestures", - "version": "0.4.9", + "version": "0.4.11", "description": "Unified mouse, mouse wheel & single-touch event stream abstraction", "main": "./index.js", "typings": "./index.d.ts", @@ -20,17 +20,17 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/rstream": "^1.10.0", - "@thi.ng/transducers": "^1.14.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/rstream": "^1.10.2", + "@thi.ng/transducers": "^1.14.3" }, "keywords": [ "dataflow", diff --git a/packages/rstream-graph/CHANGELOG.md b/packages/rstream-graph/CHANGELOG.md index cf5b12a9b1..0420aab6c5 100644 --- a/packages/rstream-graph/CHANGELOG.md +++ b/packages/rstream-graph/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [2.1.15](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-graph@2.1.14...@thi.ng/rstream-graph@2.1.15) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/rstream-graph + + +## [2.1.14](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-graph@2.1.13...@thi.ng/rstream-graph@2.1.14) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/rstream-graph + ## [2.1.13](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-graph@2.1.12...@thi.ng/rstream-graph@2.1.13) (2018-07-20) diff --git a/packages/rstream-graph/README.md b/packages/rstream-graph/README.md index 76fd35d84a..32b69cd132 100644 --- a/packages/rstream-graph/README.md +++ b/packages/rstream-graph/README.md @@ -41,12 +41,12 @@ yarn add @thi.ng/rstream-graph Small(ish), fully commented projects can be found in the `/examples` folder: -* **SVG grid gen** - +- **SVG grid gen** - [Source](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-grid), - [Live version](http://demo.thi.ng/umbrella/rstream-grid) -* **Dataflow circles** - + [Live version](https://demo.thi.ng/umbrella/rstream-grid) +- **Dataflow circles** - [Source](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-dataflow), - [Live version](http://demo.thi.ng/umbrella/rstream-dataflow) + [Live version](https://demo.thi.ng/umbrella/rstream-dataflow) More basic: diff --git a/packages/rstream-graph/package.json b/packages/rstream-graph/package.json index 9fd58c0ef6..b79db42a69 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.13", + "version": "2.1.15", "description": "Declarative dataflow graph construction for @thi.ng/rstream", "main": "./index.js", "typings": "./index.d.ts", @@ -20,21 +20,21 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/paths": "^1.5.1", - "@thi.ng/resolve-map": "^3.0.6", - "@thi.ng/rstream": "^1.10.0", - "@thi.ng/transducers": "^1.14.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/paths": "^1.5.2", + "@thi.ng/resolve-map": "^3.0.7", + "@thi.ng/rstream": "^1.10.2", + "@thi.ng/transducers": "^1.14.3" }, "keywords": [ "compute", diff --git a/packages/rstream-log/CHANGELOG.md b/packages/rstream-log/CHANGELOG.md index a7bf0d0e93..099522e1fe 100644 --- a/packages/rstream-log/CHANGELOG.md +++ b/packages/rstream-log/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.0.42](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-log@1.0.41...@thi.ng/rstream-log@1.0.42) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/rstream-log + + +## [1.0.41](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-log@1.0.40...@thi.ng/rstream-log@1.0.41) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/rstream-log + ## [1.0.40](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-log@1.0.39...@thi.ng/rstream-log@1.0.40) (2018-07-20) diff --git a/packages/rstream-log/package.json b/packages/rstream-log/package.json index 8a56715bb0..32d63b4ef9 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.40", + "version": "1.0.42", "description": "Structured, multilevel & hierarchical loggers based on @thi.ng/rstream", "main": "./index.js", "typings": "./index.d.ts", @@ -20,19 +20,19 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/rstream": "^1.10.0", - "@thi.ng/transducers": "^1.14.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/rstream": "^1.10.2", + "@thi.ng/transducers": "^1.14.3" }, "keywords": [ "ES6", diff --git a/packages/rstream-query/CHANGELOG.md b/packages/rstream-query/CHANGELOG.md index f589ffa872..0f8c0cddba 100644 --- a/packages/rstream-query/CHANGELOG.md +++ b/packages/rstream-query/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.3.29](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-query@0.3.28...@thi.ng/rstream-query@0.3.29) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/rstream-query + + +## [0.3.28](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-query@0.3.27...@thi.ng/rstream-query@0.3.28) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/rstream-query + ## [0.3.27](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream-query@0.3.26...@thi.ng/rstream-query@0.3.27) (2018-07-20) diff --git a/packages/rstream-query/package.json b/packages/rstream-query/package.json index 8915efb355..e08f6f9c5b 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.27", + "version": "0.3.29", "description": "@thi.ng/rstream based triple store & reactive query engine", "main": "./index.js", "typings": "./index.d.ts", @@ -20,22 +20,22 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/associative": "^0.5.10", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/equiv": "^0.1.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/rstream": "^1.10.0", - "@thi.ng/rstream-dot": "^0.2.28", - "@thi.ng/transducers": "^1.14.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/associative": "^0.5.11", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/equiv": "^0.1.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/rstream": "^1.10.2", + "@thi.ng/rstream-dot": "^0.2.30", + "@thi.ng/transducers": "^1.14.3" }, "keywords": [ "dataflow", diff --git a/packages/rstream/CHANGELOG.md b/packages/rstream/CHANGELOG.md index adfaeede4f..41d423c2aa 100644 --- a/packages/rstream/CHANGELOG.md +++ b/packages/rstream/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.10.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream@1.10.1...@thi.ng/rstream@1.10.2) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/rstream + + +## [1.10.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream@1.10.0...@thi.ng/rstream@1.10.1) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/rstream + # [1.10.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/rstream@1.9.7...@thi.ng/rstream@1.10.0) (2018-07-20) diff --git a/packages/rstream/README.md b/packages/rstream/README.md index 44717f6d99..6a875f35d3 100644 --- a/packages/rstream/README.md +++ b/packages/rstream/README.md @@ -132,14 +132,14 @@ directory of this repo: Interactive demo is utilizing the [@thi.ng/rstream-graph](https://github.com/thi-ng/umbrella/tree/master/packages/rstream-graph) support package to compute a SVG grid. [Source](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-grid) -| [Live version](http://demo.thi.ng/umbrella/rstream-grid) +| [Live version](https://demo.thi.ng/umbrella/rstream-grid) ### Declarative dataflow graph This demo is utilizing the [@thi.ng/rstream-graph](https://github.com/thi-ng/umbrella/tree/master/packages/rstream-graph) support package. [Source](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-dataflow) -| [Live version](http://demo.thi.ng/umbrella/rstream-dataflow) +| [Live version](https://demo.thi.ng/umbrella/rstream-dataflow) ### @thi.ng/hdom benchmark @@ -147,7 +147,7 @@ The FPS counter canvas component used in this benchmark is driven by this package and based on the barebones version shown below. [Source](https://github.com/thi-ng/umbrella/tree/master/examples/hdom-benchmark) -| [Live version](http://demo.thi.ng/umbrella/hdom-benchmark/) +| [Live version](https://demo.thi.ng/umbrella/hdom-benchmark/) ### Basic usage patterns diff --git a/packages/rstream/package.json b/packages/rstream/package.json index a63ad261a5..138a3097e8 100644 --- a/packages/rstream/package.json +++ b/packages/rstream/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/rstream", - "version": "1.10.0", + "version": "1.10.2", "description": "Reactive multi-tap streams, dataflow & transformation pipeline constructs", "main": "./index.js", "typings": "./index.d.ts", @@ -20,21 +20,21 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/associative": "^0.5.10", - "@thi.ng/atom": "^1.4.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/paths": "^1.5.1", - "@thi.ng/transducers": "^1.14.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/associative": "^0.5.11", + "@thi.ng/atom": "^1.4.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/paths": "^1.5.2", + "@thi.ng/transducers": "^1.14.3" }, "keywords": [ "datastructure", diff --git a/packages/sax/CHANGELOG.md b/packages/sax/CHANGELOG.md index 52ee6a1694..29fec3cd9a 100644 --- a/packages/sax/CHANGELOG.md +++ b/packages/sax/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.3.11](https://github.com/thi-ng/umbrella/compare/@thi.ng/sax@0.3.10...@thi.ng/sax@0.3.11) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/sax + + +## [0.3.10](https://github.com/thi-ng/umbrella/compare/@thi.ng/sax@0.3.9...@thi.ng/sax@0.3.10) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/sax + ## [0.3.9](https://github.com/thi-ng/umbrella/compare/@thi.ng/sax@0.3.8...@thi.ng/sax@0.3.9) (2018-07-20) diff --git a/packages/sax/package.json b/packages/sax/package.json index ac1e519b78..ec5feb2cd6 100644 --- a/packages/sax/package.json +++ b/packages/sax/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/sax", - "version": "0.3.9", + "version": "0.3.11", "description": "Transducer-based, SAX-like, non-validating, speedy & tiny XML parser", "main": "./index.js", "typings": "./index.d.ts", @@ -20,17 +20,17 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/transducers": "^1.14.1", - "@thi.ng/transducers-fsm": "^0.2.8" + "@thi.ng/api": "^4.0.6", + "@thi.ng/transducers": "^1.14.3", + "@thi.ng/transducers-fsm": "^0.2.10" }, "keywords": [ "ES6", diff --git a/packages/transducers-fsm/CHANGELOG.md b/packages/transducers-fsm/CHANGELOG.md index 5b15435ab5..a8b01e01d5 100644 --- a/packages/transducers-fsm/CHANGELOG.md +++ b/packages/transducers-fsm/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.2.10](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-fsm@0.2.9...@thi.ng/transducers-fsm@0.2.10) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/transducers-fsm + + +## [0.2.9](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-fsm@0.2.8...@thi.ng/transducers-fsm@0.2.9) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/transducers-fsm + ## [0.2.8](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-fsm@0.2.7...@thi.ng/transducers-fsm@0.2.8) (2018-07-20) diff --git a/packages/transducers-fsm/package.json b/packages/transducers-fsm/package.json index b31cdf2ce6..ad6b02ae36 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.8", + "version": "0.2.10", "description": "Transducer-based Finite State Machine transformer", "main": "./index.js", "typings": "./index.d.ts", @@ -20,16 +20,16 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/transducers": "^1.14.1" + "@thi.ng/api": "^4.0.6", + "@thi.ng/transducers": "^1.14.3" }, "keywords": [ "ES6", diff --git a/packages/transducers-stats/CHANGELOG.md b/packages/transducers-stats/CHANGELOG.md index 44ce05a247..e20c24b6bd 100644 --- a/packages/transducers-stats/CHANGELOG.md +++ b/packages/transducers-stats/CHANGELOG.md @@ -3,6 +3,48 @@ 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/transducers-stats@0.3.1...@thi.ng/transducers-stats@0.3.2) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/transducers-stats + + +## [0.3.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-stats@0.3.0...@thi.ng/transducers-stats@0.3.1) (2018-07-25) + + +### Bug Fixes + +* **transducers-stats:** fix naming of MACD results ([#31](https://github.com/thi-ng/umbrella/issues/31)) ([a322e00](https://github.com/thi-ng/umbrella/commit/a322e00)) + + + + + +# [0.3.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-stats@0.2.0...@thi.ng/transducers-stats@0.3.0) (2018-07-25) + + +### Features + +* **transducers-stats:** add BollingerBand value interface ([c97cb75](https://github.com/thi-ng/umbrella/commit/c97cb75)) +* **transducers-stats:** add MACD (fixes [#31](https://github.com/thi-ng/umbrella/issues/31)) ([b92aaa5](https://github.com/thi-ng/umbrella/commit/b92aaa5)) + + + + + +# [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers-stats@0.1.0...@thi.ng/transducers-stats@0.2.0) (2018-07-21) + + +### Features + +* **transducers-stats:** add stochastic oscillator, refactor ([0b0a7ca](https://github.com/thi-ng/umbrella/commit/0b0a7ca)) + + + + # 0.1.0 (2018-07-20) diff --git a/packages/transducers-stats/README.md b/packages/transducers-stats/README.md index e216b424f2..06228f99e7 100644 --- a/packages/transducers-stats/README.md +++ b/packages/transducers-stats/README.md @@ -31,11 +31,13 @@ statistical analysis and replaces the older - [Donchian Channel](./src/donchian.ts) - [EMA (Exponential Moving Average)](./src/ema.ts) - [HMA (Hull Moving Average)](./src/hma.ts) +- [MACD (Moving Average Convergence/Divergence)](./src/macd.ts) - [Momentum](./src/momentum.ts) - [ROC (Rate of change)](./src/roc.ts) - [RSI (Relative Strength Index)](./src/rsi.ts) - [SD (Standard Deviation)](./src/sd.ts) - [SMA (Simple Moving Average)](./src/sma.ts) +- [Stochastic oscillator](./src/stochastic.ts) - [TRIX (Triple smoothed EMA)](./src/trix.ts) - [WMA (Weighted Moving Average)](./src/wma.ts) @@ -47,8 +49,44 @@ yarn add @thi.ng/transducers-stats ## Usage examples +For some realworld use, please see the [crypto +chart](https://github.com/thi-ng/umbrella/tree/master/examples/crypto-chart) +example. + ```ts +import * as tx from "@thi.ng/transducers"; import * as stats from "@thi.ng/transducers-stats"; + +// Simple moving average (SMA) (sliding window size 5) +[...tx.iterator(stats.sma(5), [1,2,3,4,5,10,11,12,13,14,9,8,7,6,5])] +// [ 3, 4.8, 6.6, 8.4, 10.2, 12, 11.8, 11.2, 10.2, 8.8, 7 ] + +// compute multiple stats at once +tx.transduce( + tx.comp( + tx.multiplexObj({ + sma: stats.sma(5), + ema: stats.ema(5), + wma: stats.wma(5) + }), + // ignore first `period-1` values + // (because MAs require at least `period` inputs to warm up) + tx.drop(4) + ), + tx.push(), + [1,2,3,4,5,10,11,12,13,14,9,8,7,6,5] +); +// [ { wma: 3.6666666666666665, ema: 3, sma: 3 }, +// { wma: 6, ema: 5.333333333333333, sma: 4.8 }, +// { wma: 8.066666666666666, ema: 7.222222222222221, sma: 6.6 }, +// { wma: 9.866666666666667, ema: 8.814814814814815, sma: 8.4 }, +// { wma: 11.4, ema: 10.209876543209877, sma: 10.2 }, +// { wma: 12.666666666666666, ema: 11.473251028806585, sma: 12 }, +// { wma: 11.666666666666666, ema: 10.64883401920439, sma: 11.8 }, +// { wma: 10.4, ema: 9.76588934613626, sma: 11.2 }, +// { wma: 9, ema: 8.843926230757507, sma: 10.2 }, +// { wma: 7.6, ema: 7.895950820505004, sma: 8.8 }, +// { wma: 6.333333333333333, ema: 6.93063388033667, sma: 7 } ] ``` ## Authors diff --git a/packages/transducers-stats/package.json b/packages/transducers-stats/package.json index 850af0ee78..87de325872 100644 --- a/packages/transducers-stats/package.json +++ b/packages/transducers-stats/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/transducers-stats", - "version": "0.1.0", + "version": "0.3.2", "description": "Transducers for statistical / technical analysis", "main": "./index.js", "typings": "./index.d.ts", @@ -20,17 +20,17 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/dcons": "^1.0.6", - "@thi.ng/errors": "^0.1.5", - "@thi.ng/transducers": "^1.14.1" + "@thi.ng/dcons": "^1.0.7", + "@thi.ng/errors": "^0.1.6", + "@thi.ng/transducers": "^1.14.3" }, "keywords": [ "ES6", diff --git a/packages/transducers-stats/src/bollinger.ts b/packages/transducers-stats/src/bollinger.ts index b5ef187b19..0be29805b4 100644 --- a/packages/transducers-stats/src/bollinger.ts +++ b/packages/transducers-stats/src/bollinger.ts @@ -8,18 +8,24 @@ import { partition } from "@thi.ng/transducers/xform/partition"; import { mse } from "./mse"; import { sma } from "./sma"; +export interface BollingerBand { + min: number; + max: number; + mean: number; + pb: number; +} + /** * Computes Bollinger bands using sliding window. * * https://en.wikipedia.org/wiki/Bollinger_Bands * * Note: the number of results will be `period-1` less than the - * number of processed inputs and no outputs will be produced if there - * were less than `period` input values. + * number of processed inputs. * * @param period */ -export function bollinger(period = 20, sd = 2): Transducer { +export function bollinger(period = 20, sd = 2): Transducer { return comp( multiplex(partition(period, 1), sma(period)), drop(period - 1), diff --git a/packages/transducers-stats/src/bounds.ts b/packages/transducers-stats/src/bounds.ts new file mode 100644 index 0000000000..3ea44f2743 --- /dev/null +++ b/packages/transducers-stats/src/bounds.ts @@ -0,0 +1,15 @@ +/** + * Computes min / max values of given array. + * + * @param window + */ +export const bounds = (window: number[]) => { + let min = window[0]; + let max = min; + for (let i = window.length - 1; i > 0; i--) { + const v = window[i]; + min = Math.min(min, v); + max = Math.max(max, v); + } + return [min, max]; +}; diff --git a/packages/transducers-stats/src/donchian.ts b/packages/transducers-stats/src/donchian.ts index 8004429f7d..5f432e1220 100644 --- a/packages/transducers-stats/src/donchian.ts +++ b/packages/transducers-stats/src/donchian.ts @@ -3,29 +3,18 @@ import { comp } from "@thi.ng/transducers/func/comp"; import { partition } from "@thi.ng/transducers/xform/partition"; import { map } from "@thi.ng/transducers/xform/map"; +import { bounds } from "./bounds"; + /** * Computes Donchian channel, i.e. min/max values for sliding window. * * https://en.wikipedia.org/wiki/Donchian_channel * * Note: the number of results will be `period-1` less than the - * number of processed inputs and no outputs will be produced if there - * were less than `period` input values. + * number of processed inputs. * * @param period */ export function donchian(period: number): Transducer { - return comp( - partition(period, 1), - map((window) => { - let min = window[0]; - let max = min; - for (let i = 1; i < period; i++) { - const v = window[i]; - min = Math.min(min, v); - max = Math.max(max, v); - } - return [min, max]; - }) - ); + return comp(partition(period, 1), map(bounds)); }; diff --git a/packages/transducers-stats/src/ema.ts b/packages/transducers-stats/src/ema.ts index a7c76661a5..bcb19446f6 100644 --- a/packages/transducers-stats/src/ema.ts +++ b/packages/transducers-stats/src/ema.ts @@ -6,8 +6,7 @@ import { compR } from "@thi.ng/transducers/func/compr"; * https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average * * Note: the number of results will be `period-1` less than the number - * of processed inputs and no outputs will be produced if there were - * less than `period` input values. + * of processed inputs. * * @param period */ diff --git a/packages/transducers-stats/src/hma.ts b/packages/transducers-stats/src/hma.ts index 4d468d0293..06d8ab069a 100644 --- a/packages/transducers-stats/src/hma.ts +++ b/packages/transducers-stats/src/hma.ts @@ -9,10 +9,7 @@ import { wma } from "./wma"; /** * https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/hull-moving-average * - * Note: the number of results will be: - * - * `period + floor(sqrt(period)) - 2` - * + * Note: the number of results will be `period + floor(sqrt(period)) - 2` * less than the number of processed inputs. * * @param weights period or array of weights diff --git a/packages/transducers-stats/src/index.ts b/packages/transducers-stats/src/index.ts index af012662cb..343daad1f5 100644 --- a/packages/transducers-stats/src/index.ts +++ b/packages/transducers-stats/src/index.ts @@ -2,13 +2,16 @@ export * from "./bollinger"; export * from "./donchian"; export * from "./ema"; export * from "./hma"; +export * from "./macd"; export * from "./momentum"; export * from "./roc"; export * from "./rsi"; export * from "./sd"; export * from "./sma"; +export * from "./stochastic"; export * from "./trix"; export * from "./wma"; +export * from "./bounds"; export * from "./dot"; export * from "./mse"; diff --git a/packages/transducers-stats/src/macd.ts b/packages/transducers-stats/src/macd.ts new file mode 100644 index 0000000000..f7003e97aa --- /dev/null +++ b/packages/transducers-stats/src/macd.ts @@ -0,0 +1,61 @@ +import { Reducer, Transducer } from "@thi.ng/transducers/api"; +import { compR } from "@thi.ng/transducers/func/compr"; +import { step } from "@thi.ng/transducers/step"; + +import { ema } from "./ema"; + +export interface MACD { + /** + * Main MACD value: `ema(fast) - ema(slow)` + */ + macd: number; + /** + * Smoothed MACD, i.e. EMA(smooth) of `macd` value + */ + signal: number; + /** + * Divergence (histogram), i.e. `macd - signal` + */ + div: number; + /** + * Fast EMA value + */ + fast: number; + /** + * Slow EMA value + */ + slow: number; +} + +/** + * Computes the Moving Average Convergence/Divergence (MACD) using given + * periods. + * + * Note: the number of results will be `slow + smooth - 2` less than the + * number of processed inputs. + * + * https://en.wikipedia.org/wiki/MACD + * + * @param fast fast EMA period + * @param slow slow EMA period + * @param smooth signal smoothing EMA period + */ +export const macd = (fast = 12, slow = 26, smooth = 9): Transducer => + (rfn: Reducer) => { + const reduce = rfn[2]; + const maFast = step(ema(fast)); + const maSlow = step(ema(slow)); + const maSmooth = step(ema(smooth)); + return compR( + rfn, + (acc, x) => { + const fast = maFast(x); + const slow = maSlow(x); + if (slow == null) return acc; + const macd = fast - slow; + const signal = maSmooth(macd); + if (signal == null) return acc; + return reduce(acc, { macd, signal, div: macd - signal, fast, slow }); + } + ); + }; diff --git a/packages/transducers-stats/src/momentum.ts b/packages/transducers-stats/src/momentum.ts index 5668ecf937..8cd9303baa 100644 --- a/packages/transducers-stats/src/momentum.ts +++ b/packages/transducers-stats/src/momentum.ts @@ -6,9 +6,8 @@ import { compR } from "@thi.ng/transducers/func/compr"; /** * https://en.wikipedia.org/wiki/Momentum_(technical_analysis) * - * Note: the number of results will be `period-1` less than the number - * of processed inputs and no outputs will be produced if there were - * less than `period` input values. + * Note: the number of results will be `period` less than the number + * of processed inputs. * * @param period */ diff --git a/packages/transducers-stats/src/roc.ts b/packages/transducers-stats/src/roc.ts index a674f5d6a4..4aef9476ea 100644 --- a/packages/transducers-stats/src/roc.ts +++ b/packages/transducers-stats/src/roc.ts @@ -8,7 +8,7 @@ import { compR } from "@thi.ng/transducers/func/compr"; * * https://en.wikipedia.org/wiki/Momentum_(technical_analysis) * - * Note: the number of results will be `period-1` less than the number + * Note: the number of results will be `period` less than the number * of processed inputs and no outputs will be produced if there were * less than `period` input values. * diff --git a/packages/transducers-stats/src/rsi.ts b/packages/transducers-stats/src/rsi.ts index 7956f3e852..83af4f0ce4 100644 --- a/packages/transducers-stats/src/rsi.ts +++ b/packages/transducers-stats/src/rsi.ts @@ -10,8 +10,7 @@ import { sma } from "./sma"; * https://en.wikipedia.org/wiki/Relative_strength_index * * Note: the number of results will be `period` less than the - * number of processed inputs and no outputs will be produced if there - * were less than `period` input values. + * number of processed inputs. * * @param period */ diff --git a/packages/transducers-stats/src/sd.ts b/packages/transducers-stats/src/sd.ts index 1b7ad8c934..c8c7861bc2 100644 --- a/packages/transducers-stats/src/sd.ts +++ b/packages/transducers-stats/src/sd.ts @@ -15,8 +15,7 @@ import { sma } from "./sma"; * https://en.wikipedia.org/wiki/Bollinger_Bands * * Note: the number of results will be `period-1` less than the number - * of processed inputs and no outputs will be produced if there were - * less than `period` input values. + * of processed inputs. * * @param period */ diff --git a/packages/transducers-stats/src/sma.ts b/packages/transducers-stats/src/sma.ts index 757f9fe0a8..bfefdf3381 100644 --- a/packages/transducers-stats/src/sma.ts +++ b/packages/transducers-stats/src/sma.ts @@ -8,8 +8,7 @@ import { compR } from "@thi.ng/transducers/func/compr"; * linked list as sliding window buffer. * * Note: the number of results will be `period-1` less than the number - * of processed inputs and no outputs will be produced if there were - * less than `period` input values. + * of processed inputs. * * @param period */ diff --git a/packages/transducers-stats/src/stochastic.ts b/packages/transducers-stats/src/stochastic.ts new file mode 100644 index 0000000000..306ff5589c --- /dev/null +++ b/packages/transducers-stats/src/stochastic.ts @@ -0,0 +1,41 @@ +import { Reducer, Transducer } from "@thi.ng/transducers/api"; +import { compR } from "@thi.ng/transducers/func/compr"; +import { step } from "@thi.ng/transducers/step"; + +import { donchian } from "./donchian"; +import { sma } from "./sma"; + +/** + * Stochastic oscillator. Yields tuples of `[%K, %D1, %D2]`, where: + * + * - %K = (curr - L5) / (H5 - L5) + * - %D1 = SMA(%K, periodD1) + * - %D2 = SMA(%D1, periodD2) + * + * https://en.wikipedia.org/wiki/Stochastic_oscillator + * + * @param periodK + * @param periodD1 + * @param periodD2 + */ +export function stochastic(periodK: number, periodD1: number, periodD2: number): Transducer { + return (rfn: Reducer) => { + const reduce = rfn[2]; + const xfD = step(donchian(periodK)); + const ma1 = step(sma(periodD1)); + const ma2 = step(sma(periodD2)); + return compR( + rfn, + (acc, x) => { + const b = xfD(x); + if (b == null) return acc; + const k = (x - b[0]) / (b[1] - b[0]); + const d1 = ma1(k); + if (d1 == null) return acc; + const d2 = ma2(d1); + if (d2 == null) return acc; + return reduce(acc, [k, d1, d2]); + } + ); + } +} diff --git a/packages/transducers-stats/src/trix.ts b/packages/transducers-stats/src/trix.ts index 6b157c0865..b87e139cc8 100644 --- a/packages/transducers-stats/src/trix.ts +++ b/packages/transducers-stats/src/trix.ts @@ -6,9 +6,8 @@ import { roc } from "./roc"; /** * https://en.wikipedia.org/wiki/Trix_(technical_analysis) * - * Note: the number of results will be `3 * (period - 1) + 1` less than the - * number of processed inputs and no outputs will be produced if there - * were less than `period` input values. + * Note: the number of results will be `3 * (period - 1) + 1` less than + * the number of processed inputs. * * @param period */ diff --git a/packages/transducers-stats/src/wma.ts b/packages/transducers-stats/src/wma.ts index 2f36e45213..c18acbd44b 100644 --- a/packages/transducers-stats/src/wma.ts +++ b/packages/transducers-stats/src/wma.ts @@ -11,8 +11,7 @@ import { dot } from "./dot"; * https://en.wikipedia.org/wiki/Moving_average#Weighted_moving_average * * Note: the number of results will be `period-1` less than the number - * of processed inputs and no outputs will be produced if there were - * less than `period` input values. + * of processed inputs. * * @param weights period or array of weights */ diff --git a/packages/transducers/CHANGELOG.md b/packages/transducers/CHANGELOG.md index f13846d314..d77ae1dcca 100644 --- a/packages/transducers/CHANGELOG.md +++ b/packages/transducers/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.14.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers@1.14.2...@thi.ng/transducers@1.14.3) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/transducers + + +## [1.14.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers@1.14.1...@thi.ng/transducers@1.14.2) (2018-07-25) + + + + +**Note:** Version bump only for package @thi.ng/transducers + ## [1.14.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers@1.14.0...@thi.ng/transducers@1.14.1) (2018-07-20) diff --git a/packages/transducers/README.md b/packages/transducers/README.md index d48c9336f4..707aff065e 100644 --- a/packages/transducers/README.md +++ b/packages/transducers/README.md @@ -29,20 +29,20 @@ though the implementation does heavily differ (also in contrast to some other JS based implementations) and dozens of less common, but generally highly useful operators have been added. See full list below. -### Related functionality / packages +### Related packages + +#### Extended functionality + +- [@thi.ng/transducers-fsm](https://github.com/thi-ng/umbrella/tree/master/packages/transducers-fsm) - Fine State Machine transducer +- [@thi.ng/transducers-stats](https://github.com/thi-ng/umbrella/tree/master/packages/transducers-stats) - Technical / statistical analysis transducers + +#### Packages utilizing transducers - [@thi.ng/csp](https://github.com/thi-ng/umbrella/tree/master/packages/csp) - [@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/master/packages/rstream) - [@thi.ng/rstream-graph](https://github.com/thi-ng/umbrella/tree/master/packages/rstream-graph) - [@thi.ng/rstream-log](https://github.com/thi-ng/umbrella/tree/master/packages/rstream-log) - [@thi.ng/sax](https://github.com/thi-ng/umbrella/tree/master/packages/sax) -- [@thi.ng/transducers-fsm](https://github.com/thi-ng/umbrella/tree/master/packages/transducers-fsm) - -Since 0.8.0 this project largely supersedes the -[@thi.ng/iterators](https://github.com/thi-ng/umbrella/tree/master/packages/iterators) -library for most use cases and offers are more powerful API and -potentially faster execution of composed transformations (due to lack of -ES generator overheads). ## Installation diff --git a/packages/transducers/package.json b/packages/transducers/package.json index e702578ae4..add7bea05b 100644 --- a/packages/transducers/package.json +++ b/packages/transducers/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/transducers", - "version": "1.14.1", + "version": "1.14.3", "description": "Lightweight transducer implementations for ES6 / TypeScript", "main": "./index.js", "typings": "./index.d.ts", @@ -20,19 +20,19 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "dependencies": { - "@thi.ng/api": "^4.0.5", - "@thi.ng/checks": "^1.5.6", - "@thi.ng/compare": "^0.1.5", - "@thi.ng/equiv": "^0.1.6", - "@thi.ng/errors": "^0.1.5" + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7", + "@thi.ng/compare": "^0.1.6", + "@thi.ng/equiv": "^0.1.7", + "@thi.ng/errors": "^0.1.6" }, "keywords": [ "ES6", diff --git a/packages/unionstruct/CHANGELOG.md b/packages/unionstruct/CHANGELOG.md index 7d58e13b07..e6f3a77cfd 100644 --- a/packages/unionstruct/CHANGELOG.md +++ b/packages/unionstruct/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.13](https://github.com/thi-ng/umbrella/compare/@thi.ng/unionstruct@0.1.12...@thi.ng/unionstruct@0.1.13) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/unionstruct + ## [0.1.12](https://github.com/thi-ng/umbrella/compare/@thi.ng/unionstruct@0.1.11...@thi.ng/unionstruct@0.1.12) (2018-07-20) diff --git a/packages/unionstruct/package.json b/packages/unionstruct/package.json index 5dfc24477b..6c80f202a5 100644 --- a/packages/unionstruct/package.json +++ b/packages/unionstruct/package.json @@ -1,6 +1,6 @@ { "name": "@thi.ng/unionstruct", - "version": "0.1.12", + "version": "0.1.13", "description": "C-style struct, union and bitfield views of ArrayBuffers", "main": "./index.js", "typings": "./index.d.ts", @@ -20,12 +20,12 @@ "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" }, "devDependencies": { - "@types/mocha": "^5.2.0", - "@types/node": "^10.0.6", - "mocha": "^5.1.1", - "nyc": "^11.7.1", + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "typedoc": "^0.11.1", - "typescript": "^2.8.3" + "typescript": "^3.0.1" }, "keywords": [ "align", diff --git a/packages/vectors/.npmignore b/packages/vectors/.npmignore new file mode 100644 index 0000000000..d703bda97a --- /dev/null +++ b/packages/vectors/.npmignore @@ -0,0 +1,10 @@ +build +coverage +dev +doc +src* +test +.nyc_output +tsconfig.json +*.tgz +*.html diff --git a/packages/vectors/CHANGELOG.md b/packages/vectors/CHANGELOG.md new file mode 100644 index 0000000000..1bf102b9dc --- /dev/null +++ b/packages/vectors/CHANGELOG.md @@ -0,0 +1,55 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + + +## [0.1.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@0.1.2...@thi.ng/vectors@0.1.3) (2018-08-01) + + + + +**Note:** Version bump only for package @thi.ng/vectors + + +## [0.1.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@0.1.1...@thi.ng/vectors@0.1.2) (2018-07-30) + + +### Bug Fixes + +* **vectors:** get*() return types, refactor using set*() ([3534274](https://github.com/thi-ng/umbrella/commit/3534274)) + + + + + +## [0.1.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/vectors@0.1.0...@thi.ng/vectors@0.1.1) (2018-07-29) + + +### Bug Fixes + +* **vectors:** naming convention, add function overview tables ([3de5cea](https://github.com/thi-ng/umbrella/commit/3de5cea)) + + + + + +# 0.1.0 (2018-07-29) + + +### Bug Fixes + +* **vectors:** copy/paste mistakes, add tests ([2a5a744](https://github.com/thi-ng/umbrella/commit/2a5a744)) + + +### Features + +* **vectors:** add generic vec fns & class wrapper ([e3c6167](https://github.com/thi-ng/umbrella/commit/e3c6167)) +* **vectors:** add minor/majorAxis(), minor/major2/3 ([35af6a5](https://github.com/thi-ng/umbrella/commit/35af6a5)) +* **vectors:** add swizzle fns, update/unify fn naming ([5bba592](https://github.com/thi-ng/umbrella/commit/5bba592)) +* **vectors:** add vec4 ops & class wrapper ([b59fadf](https://github.com/thi-ng/umbrella/commit/b59fadf)) +* **vectors:** re-add matrix class wrappers, update vec classes ([1ec75e6](https://github.com/thi-ng/umbrella/commit/1ec75e6)) +* **vectors:** re-import updated mat23/33/44 functions ([4fdda6a](https://github.com/thi-ng/umbrella/commit/4fdda6a)) +* **vectors:** re-import updated mat44, add orthoNormal3 ([21b04f0](https://github.com/thi-ng/umbrella/commit/21b04f0)) +* **vectors:** re-import vector types from old thi.ng/geom TS version ([d154153](https://github.com/thi-ng/umbrella/commit/d154153)) +* **vectors:** update get & copy fns to retain buffer types ([54b3db2](https://github.com/thi-ng/umbrella/commit/54b3db2)) diff --git a/packages/vectors/LICENSE b/packages/vectors/LICENSE new file mode 100644 index 0000000000..8dada3edaf --- /dev/null +++ b/packages/vectors/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/vectors/README.md b/packages/vectors/README.md new file mode 100644 index 0000000000..51a95c8ddc --- /dev/null +++ b/packages/vectors/README.md @@ -0,0 +1,274 @@ +# @thi.ng/vectors + +[![npm (scoped)](https://img.shields.io/npm/v/@thi.ng/vectors.svg)](https://www.npmjs.com/package/@thi.ng/vectors) + +This project is part of the +[@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo. + + + +- [About](#about) + - [Vectors](#vectors) + - [Matrices](#matrices) +- [Installation](#installation) +- [Usage examples](#usage-examples) + - [Basics](#basics) + - [Vector classes & interleaved vectors in large buffer](#vector-classes--interleaved-vectors-in-large-buffer) + - [Image RGB grayscale conversion](#image-rgb-grayscale-conversion) +- [Authors](#authors) +- [License](#license) + + + +## About + +This package provides vector and matrix operations as plain functions +and class wrappers with fluid interface. All functions support any array +/ typed array storage, incl. mapped views of larger buffers (e.g. for +WebGL / WASM interop, pixel buffers). Additionally, vectors support +flexible data layouts, incl. [AOS / +SOA](https://en.wikipedia.org/wiki/AOS_and_SOA), striped, interleaved, +aligned etc. + +### Vectors + +In addition to [arbitrary sized +vectors](https://github.com/thi-ng/umbrella/tree/master/packages/vectors/src/gvec.ts), +the library provides these optimized fixed-sized versions: + +- [Vec2](https://github.com/thi-ng/umbrella/tree/master/packages/vectors/src/vec2.ts) +- [Vec3](https://github.com/thi-ng/umbrella/tree/master/packages/vectors/src/vec3.ts) +- [Vec4](https://github.com/thi-ng/umbrella/tree/master/packages/vectors/src/vec4.ts) + +#### Supported operations + +Note: Most functions are provided in different (optimized) versions, +depending on vector size. E.g. `add` performs vector addition for +arbitrary sizes, `add2` for 2D vectors, `add3` for 3D, `add4` for 4D... + +All vector operations (regardless of size) operate on any array-like +buffer and accept optional start indices and component strides (number +of elements (+1) between individual vector components). This allows for +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/). + +| Operation | GVec | Vec2 | Vec3 | Vec4 | +|---------------------------------|--------------|------------------|------------------|------------------| +| Get vector (dense copy) | `get` | `get2` | `get3` | `get4` | +| Set vector components (vector) | `set` | `set2` | `set3` | `set4` | +| Set vector components (uniform) | `setN` | `setN2` | `setN3` | `setN4` | +| Set vector components (scalars) | | `setS2` | `setS3` | `setS4` | +| Swizzle vector components | | `swizzle2` | `swizzle3` | `swizzle4` | +| Equality (w/ epsilon) | `eqDelta` | `eqDelta2` | `eqDelta3` | `eqDelta4` | +| Vector addition | `add` | `add2` | `add3` | `add4` | +| Vector subtraction | `sub` | `sub2` | `sub3` | `sub4` | +| Vector multiplication | `mul` | `mul2` | `mul3` | `mul4` | +| Vector division | `div` | `div2` | `div3` | `div4` | +| Uniform scalar addition | `addN` | `addN2` | `addN3` | `addN4` | +| Uniform scalar subtraction | `subN` | `subN2` | `subN3` | `subN4` | +| Uniform scalar multiply | `mulN` | `mulN2` | `mulN3` | `mulN4` | +| Uniform scalar multiply | `divN` | `divN2` | `divN3` | `divN4` | +| 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` | +| Linear interpolation (uniform) | `mixN` | `mixN2` | `mixN3` | `mixN4` | +| Dot product | `dot` | `dot2` | `dot3` | `dot4` | +| Cross product | | `cross2` | `cross3` | | +| Magnitude | `mag` | `mag2` | `mag3` | `mag4` | +| Magnitude (squared) | `magSq` | `magSq2` | `magSq3` | `magSq4` | +| Normalize (w/ opt length) | `normalize` | `normalize2` | `normalize3` | `normalize4` | +| Limit to length | | `limit2` | `limit3` | `limit4` | +| Distance | `dist` | `dist2` | `dist3` | `dist4` | +| Distance (squared) | `distSq` | `distSq2` | `distSq3` | `distSq4` | +| Manhattan distance | | `distManhattan2` | `distManhattan3` | `distManhattan4` | +| Chebyshev distance | | `distChebyshev2` | `distChebyshev3` | `distChebyshev4` | +| Reflection | | `reflect2` | `reflect3` | `reflect4` | +| RotationX | | | `rotateX3` | | +| RotationY | | | `rotateY3` | | +| RotationZ | | `rotate2` | `rotateZ3` | | +| Heading XY | | `heading2` | `headingXY3` | | +| Heading XZ | | | `headingXZ3` | | +| Heading YZ | | | `headingYZ3` | | +| Cartesian -> Polar | | `toPolar2` | `toSpherical3` | | +| Polar -> Cartesian | | `toCartesian2` | `toCartesian3` | | +| Minor axis | | `minorAxis2` | `minorAxis3` | `minorAxis4` | +| Major axis | | `majorAxis2` | `majorAxis3` | `majorAxis4` | +| Minimum | `min` | `min2` | `min3` | `min4` | +| Maximum | `max` | `max2` | `max3` | `max4` | +| Range clamping | `clamp` | `clamp2` | `clamp3` | `clamp4` | +| Step (like GLSL) | `step` | `step2` | `step3` | `step4` | +| SmoothStep (like GLSL) | `smoothStep` | `smoothStep2` | `smoothStep3` | `smoothStep4` | +| Absolute value | `abs` | `abs2` | `abs3` | `abs4` | +| Sign (w/ opt epsilon) | `sign` | `sign2` | `sign3` | `sign4` | +| Round down | `floor` | `floor2` | `floor3` | `floor4` | +| Round up | `ceil` | `ceil2` | `ceil3` | `ceil4` | +| Square root | `sqrt` | `sqrt2` | `sqrt3` | `sqrt4` | +| Power (vector) | `pow` | `pow2` | `pow3` | `pow4` | +| Power (uniform) | `powN` | `powN2` | `powN3` | `powN4` | + +### Matrices + +All matrix types are in WebGL layout (column major) and densely packed (stride always 1). + +- [Mat23](https://github.com/thi-ng/umbrella/tree/master/packages/vectors/src/mat23.ts) +- [Mat33](https://github.com/thi-ng/umbrella/tree/master/packages/vectors/src/mat33.ts) +- [Mat44](https://github.com/thi-ng/umbrella/tree/master/packages/vectors/src/mat44.ts) + +| Operation | Mat23 | Mat33 | Mat44 | +|-------------------------------------|-------------------------|---------------|---------------------| +| Set identity | `identity23` | `identity33` | `identity44` | +| Get matrix components (dense copy) | `get23` | `get33` | `get44` | +| Set matrix components (matrix) | `set23` | `set33` | `set44` | +| Set matrix components (scalars) | `setS23` | `setS33` | `setS44` | +| Create rotation matrix | | `rotationX33` | `rotationX44` | +| | | `rotationY33` | `rotationY44` | +| | `rotation23` | `rotationZ33` | `rotationZ44` | +| | `rotationAroundPoint23` | | | +| Create scale matrix (vector) | `scaleV23` | `scaleV33` | `scaleV44` | +| Create scale matrix (uniform) | `scaleN23` | `scaleN33` | `scaleN44` | +| Create scale matrix (scalars) | `scaleS23` | `scaleS33` | `scaleS44` | +| | `scaleWithCenter23` | | `scaleWithCenter44` | +| Create translation matrix (vector) | `translationV23` | | `translationV44` | +| Create translation matrix (scalars) | `translationS23` | | `translationS44` | +| Create skew matrix | `skewX23` / `shearX23` | | | +| | `skewY23` / `shearY23` | | | +| Create projection matrix | | | `projection` | +| | | | `ortho` | +| | | | `frustum` | +| Create camera matrix | | | `lookAt` | +| Matrix multiply | `mul23` | `mul33` | `mul44` | +| Matrix concatenation (multiple) | `concat23` | `concat33` | `concat44` | +| Matrix vector multiply | `mulV23` | `mulV33` | `mulV44` (Vec4) | +| | | | `mulV344` (Vec3) | +| Determinant | `det23` | `det33` | `det44` | +| Matrix inversion | `invert23` | `invert33` | `invert44` | +| Matrix transpose | | `transpose33` | `transpose44` | + +## Installation + +```bash +yarn add @thi.ng/vectors +``` + +## Usage examples + +### Basics + +```ts +import * as v from "@thi.ng/vectors"; + +// raw vector addition +v.add4([1, 2, 3, 4], [10, 20, 30, 40]); +// [ 11, 22, 33, 44 ] + +// with custom layout +// here 3x 3D vectors in SOA layout: +// [x, x, x, y, y, y, z, z, z] +points = [1, 4, 7, 2, 5, 8, 3, 6, 9]; + +// specify start indices and stride lengths +// update 1st vector +v.add3(points, [100, 200, 300], 0, 0, 3, 1); +// [ 101, 4, 7, 202, 5, 8, 303, 6, 9 ] + +// update 2nd vector +v.add3(points, [100, 200, 300], 1, 0, 3, 1); +// [ 101, 104, 7, 202, 205, 8, 303, 306, 9 ] + +// update 3rd vector +v.add3(points, [100, 200, 300], 2, 0, 3, 1); +// [ 101, 104, 107, 202, 205, 208, 303, 306, 309 ] + +// add 1st and 3rd vector and extract result +v.get3(v.add3(points, points, 0, 2, 3, 3), 0, 3); +// [ 208, 410, 612 ] + +// re-arrange vector components into new vector +// the last 4 args define component order: + +// YXWZ +v.swizzle4([], [10, 20, 30, 40], 1, 0, 3, 2); +// [ 20, 10, 40, 30 ] + +// XXZZ +v.swizzle4([], [10, 20, 30, 40], 0, 0, 2, 2); +// [ 10, 10, 30, 30 ] + +// arbitrary length vectors +norm = v.normalize([1, 2, 3, 4, 5, 6, 7, 8, 6, 4]); +// [ 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.375, 0.25 ] + +v.mag(norm); +// 1 +``` + +### Vector classes & interleaved vectors in large buffer + +```ts +// element stride 3 + 2 + 4 = 9 +buf = [ + // pos uv color (rgba) + 0,0,0, 0,0, 1,0,0,1, + 100,0,0, 1,0, 1,1,0,1, + 100,100,0, 1,1, 1,0,1,1, + 0,100,0, 0,1, 0,1,1,1, +]; + +// create memory mapped vector instances (using Vec3 class) +pos = v.Vec3.mapBuffer(buf, 4, 0, 1, 9); // offset = 0 +uv = v.Vec2.mapBuffer(buf, 4, 3, 1, 9); // offset = 3 +col = v.Vec4.mapBuffer(buf, 4, 5, 1, 9); // offset = 5 + +console.log(`pos: ${pos[1]}, uv: ${uv[1]}, color: ${col[1]}`); +// pos: [100, 0, 0], uv: [1, 0], color: [1, 1, 0, 1] + +// compute centroid +centroid = pos.reduce((c, p) => c.add(p), v.vec3()).divN(pos.length); +// Vec3 { buf: [ 50, 50, 0 ], i: 0, s: 1 } + +// build matrix to transform geometry +tx = v.Mat44.concat( + v.Mat44.scale(0.01), + v.Mat44.translation(centroid.copy().neg()), + v.Mat44.rotationZ(v.rad(90)), +); + +// apply transform to all positions +pos.forEach((p) => tx.mulV3(p)); +``` + +### Image RGB grayscale conversion + +```ts +canvas = document.getElementById("main"); +img = canvas.getContext("2d").getImageData(0,0, canvas.width, canvas.height); + +v.transformVectors1( + // multiply each RGB vector w/ weights + // then use result for all 3 color channels + (a, b, ia, ib, sa, sb) => + v.setN3(a, v.dot3(a, b, ia, ib, sa, sb), ia, sa), + // pixel buffer + img, + // RGB weight coefficients + [0.29, 0.6, 0.11], + // num pixels (RGBA vectors) + canvas.width * canvas.height, + // start indices + 0, 0, + // component strides + 1, 1, + // pixel stride + 4 +); +``` + +## Authors + +- Karsten Schmidt + +## License + +© 2016 - 2018 Karsten Schmidt // Apache Software License 2.0 diff --git a/packages/vectors/package.json b/packages/vectors/package.json new file mode 100644 index 0000000000..4bc58973bf --- /dev/null +++ b/packages/vectors/package.json @@ -0,0 +1,46 @@ +{ + "name": "@thi.ng/vectors", + "version": "0.1.3", + "description": "Vector algebra for fixed & variable sizes, memory mapped, flexible layouts", + "main": "./index.js", + "typings": "./index.d.ts", + "repository": { + "type": "git", + "url": "https://github.com/thi-ng/umbrella.git" + }, + "homepage": "https://github.com/thi-ng/umbrella/tree/master/packages/vectors", + "author": "Karsten Schmidt ", + "license": "Apache-2.0", + "scripts": { + "build": "yarn run clean && tsc --declaration", + "clean": "rm -rf *.js *.d.ts .nyc_output build coverage doc", + "cover": "yarn test && nyc report --reporter=lcov", + "doc": "node_modules/.bin/typedoc --mode modules --out doc src", + "pub": "yarn run build && yarn publish --access public", + "test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" + }, + "devDependencies": { + "@types/mocha": "^5.2.5", + "@types/node": "^10.5.5", + "mocha": "^5.2.0", + "nyc": "^12.0.2", + "typedoc": "^0.11.1", + "typescript": "^3.0.1" + }, + "dependencies": { + "@thi.ng/api": "^4.0.6", + "@thi.ng/checks": "^1.5.7" + }, + "keywords": [ + "ES6", + "matrix", + "memory mapped", + "typescript", + "webgl", + "wasm", + "vector algebra" + ], + "publishConfig": { + "access": "public" + } +} diff --git a/packages/vectors/src/api.ts b/packages/vectors/src/api.ts new file mode 100644 index 0000000000..cddbc9d511 --- /dev/null +++ b/packages/vectors/src/api.ts @@ -0,0 +1,24 @@ +export type TypedArray = + Float32Array | + Float64Array | + Int8Array | + Int16Array | + Int32Array | + Uint8Array | + Uint8ClampedArray | + Uint16Array | + Uint32Array; + +export type Vec = number[] | TypedArray; +export type ReadonlyVec = ArrayLike; + +export type Mat = number[] | TypedArray; +export type ReadonlyMat = ArrayLike; + +export type VecOp = (a: Vec, b: ReadonlyVec, ia: number, ib: number, sa: number, sb: number) => Vec; + +export interface IVec { + buf: Vec; + i: number; + s: number; +} diff --git a/packages/vectors/src/common.ts b/packages/vectors/src/common.ts new file mode 100644 index 0000000000..5e408073dd --- /dev/null +++ b/packages/vectors/src/common.ts @@ -0,0 +1,68 @@ +import { ReadonlyVec, Vec, VecOp } from "./api"; +import { EPS, eqDelta1 } from "./math"; + +export const x = (v: ReadonlyVec, i = 0, _?) => 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]; + +/** + * Applies vector op `fn` to all raw vectors in array `a`, using raw + * vector `b` as 2nd argument for each iteration. Assumes `fn` writes + * results back into `a` and no copying is performed. + * + * ``` + * transformVectors1( + * v.add3, + * [1, 2, 3, 0, 4, 5, 6, 0], + * [10, 20, 30], + * 2, 0, 0, 1, 1, 4 + * ) + * // [ 11, 22, 33, 0, 14, 25, 36, 0 ] + * ``` + * + * @param fn op + * @param a array to process + * @param b vector operand + * @param num num elements + * @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: VecOp, a: Vec, b: ReadonlyVec, num: number, ia: number, ib: number, csa: number, csb: number, esa: number) => { + for (let i = ia; num > 0; num-- , i += esa) { + fn(a, b, i, ib, csa, csb); + } + return a; +}; + +/** + * @param fn + * @param a + * @param b + * @param n + * @param ia + * @param ib + * @param csa + * @param csb + * @param esa + * @param esb + */ +export const transformVectors2 = (fn: VecOp, a: Vec, b: ReadonlyVec, n: number, ia: number, ib: number, csa: number, csb: number, esa: number, esb: number) => { + for (let i = ia, j = ib; n > 0; n-- , i += esa, j += esb) { + fn(a, b, i, j, csa, csb); + } + return a; +}; + +export const eqDelta = (a: Vec, b: Vec, n: number, eps = EPS, ia = 0, ib = 0, sa = 1, sb = 1) => { + if (a === b) return true; + for (; --n >= 0; ia += sa, ib += sb) { + if (!eqDelta1(a[ia], b[ib], eps)) { + return false; + } + } + return true; +}; diff --git a/packages/vectors/src/gvec.ts b/packages/vectors/src/gvec.ts new file mode 100644 index 0000000000..f6e0cade16 --- /dev/null +++ b/packages/vectors/src/gvec.ts @@ -0,0 +1,347 @@ +import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; +import { IVec, ReadonlyVec, Vec } from "./api"; +import { eqDelta } from "./common"; +import { + clamp1, + EPS, + sign1, + smoothStep1, + step1 +} from "./math"; + +export const opg1 = (fn: (x: number) => number, a: Vec, num = a.length, i = 0, s = 1) => { + while (--num >= 0) { + a[i + num * s] = fn(a[i + num * s]); + } + return a; +}; + +export const opg2 = (fn: (x: number, y: number) => number, a: Vec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => { + while (--num >= 0) { + a[ia + num * sa] = fn(a[ia + num * sa], b[ib + num * sb]); + } + return a; +}; + +export const opg3 = (fn: (x: number, y: number, z: number) => number, a: Vec, b: ReadonlyVec, c: ReadonlyVec, num = a.length, ia = 0, ib = 0, ic = 0, sa = 1, sb = 1, sc = 1) => { + while (--num >= 0) { + a[ia + num * sa] = fn(a[ia + num * sa], b[ib + num * sb], c[ic + num * sc]); + } + return a; +}; + +export const get = (a: ReadonlyVec, num = a.length, i = 0, s = 1) => + set(new ((a.constructor))(num), a, 0, i, 1, s); + +export const set = (a: Vec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => { + while (--num >= 0) { + a[ia + num * sa] = b[ib + num * sb]; + } + return a; +}; + +export const setN = (a: Vec, n: number, num = a.length, ia = 0, sa = 1) => { + while (--num >= 0) { + a[ia + num * sa] = n; + } + return a; +}; + +export const add = (a: Vec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + opg2((x, y) => x + y, a, b, num, ia, ib, sa, sb); + +export const sub = (a: Vec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + opg2((x, y) => x - y, a, b, num, ia, ib, sa, sb); + +export const mul = (a: Vec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + opg2((x, y) => x * y, a, b, num, ia, ib, sa, sb); + +export const div = (a: Vec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + opg2((x, y) => x / y, a, b, num, ia, ib, sa, sb); + +export const addN = (a: Vec, n: number, num = a.length, i = 0, s = 1) => + opg1((x) => x + n, a, num, i, s); + +export const subN = (a: Vec, n: number, num = a.length, i = 0, s = 1) => + opg1((x) => x - n, a, num, i, s); + +export const mulN = (a: Vec, n: number, num = a.length, i = 0, s = 1) => + opg1((x) => x * n, a, num, i, s); + +export const divN = (a: Vec, n: number, num = a.length, i = 0, s = 1) => + opg1((x) => x / n, a, num, i, s); + +export const dot = (a: ReadonlyVec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => { + let res = 0; + while (--num >= 0) { + res += a[ia + num * sa] * b[ib + num * sb]; + } + return res; +}; + +export const madd = (a: Vec, b: ReadonlyVec, c: ReadonlyVec, num = a.length, ia = 0, ib = 0, ic = 0, sa = 1, sb = 1, sc = 1) => + opg3((x, y, z) => x + y * z, a, b, c, num, ia, ib, ic, sa, sb, sc); + +export const maddN = (a: Vec, b: ReadonlyVec, n: number, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + opg2((x, y) => x + y * n, a, b, num, ia, ib, sa, sb); + +export const mix = (a: Vec, b: ReadonlyVec, c: ReadonlyVec, num = a.length, ia = 0, ib = 0, ic = 0, sa = 1, sb = 1, sc = 1) => + opg3((x, y, z) => x + (y - x) * z, a, b, c, num, ia, ib, ic, sa, sb, sc); + +export const mixN = (a: Vec, b: ReadonlyVec, n: number, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + opg2((x, y) => x + (y - x) * n, a, b, num, ia, ib, sa, sb); + +export const magSq = (a: ReadonlyVec, num = a.length, i = 0, s = 1) => + dot(a, a, num, i, i, s, s); + +export const mag = (a: ReadonlyVec, num = a.length, i = 0, s = 1) => + Math.sqrt(magSq(a, num, i, s)); + +export const distSq = (a: ReadonlyVec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => { + let res = 0; + while (--num >= 0) { + res += Math.pow(a[ia + num * sa] - b[ib + num * sb], 2); + } + return res; +}; + +export const dist = (a: ReadonlyVec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + Math.sqrt(distSq(a, b, num, ia, ib, sa, sb)); + +export const normalize = (a: Vec, num = a.length, len = 1, i = 0, s = 1) => { + const m = mag(a, num, i, s); + m >= EPS && mulN(a, len / m, num, i, s); + return a; +}; + +export const neg = (a: Vec, num = a.length, i = 0, s = 1) => + mulN(a, -1, num, i, s); + +export const abs = (a: Vec, num = a.length, i = 0, s = 1) => + opg1(Math.abs, a, num, i, s); + +export const sign = (a: Vec, num = a.length, eps = EPS, i = 0, s = 1) => + opg1((x) => sign1(x, eps), a, num, i, s); + +export const floor = (a: Vec, num = a.length, i = 0, s = 1) => + opg1(Math.floor, a, num, i, s); + +export const ceil = (a: Vec, num = a.length, i = 0, s = 1) => + opg1(Math.ceil, a, num, i, s); + +export const sin = (a: Vec, num = a.length, i = 0, s = 1) => + opg1(Math.sin, a, num, i, s); + +export const cos = (a: Vec, num = a.length, i = 0, s = 1) => + opg1(Math.cos, a, num, i, s); + +export const sqrt = (a: Vec, num = a.length, i = 0, s = 1) => + opg1(Math.sqrt, a, num, i, s); + +export const pow = (a: Vec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + opg2(Math.pow, a, b, num, ia, ib, sa, sb); + +export const powN = (a: Vec, n: number, num = a.length, i = 0, s = 1) => + opg1((x) => Math.pow(x, n), a, num, i, s); + +export const min = (a: Vec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + opg2(Math.min, a, b, num, ia, ib, sa, sb); + +export const max = (a: Vec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + opg2(Math.max, a, b, num, ia, ib, sa, sb); + +export const clamp = (a: Vec, b: ReadonlyVec, c: ReadonlyVec, num = a.length, ia = 0, ib = 0, ic = 0, sa = 1, sb = 1, sc = 1) => + opg3(clamp1, a, b, c, num, ia, ib, ic, sa, sb, sc); + +export const step = (a: Vec, b: ReadonlyVec, num = a.length, ia = 0, ib = 0, sa = 1, sb = 1) => + opg2((x, e) => step1(e, x), a, b, num, ia, ib, sa, sb); + +export const smoothStep = (a: Vec, b: ReadonlyVec, c: ReadonlyVec, num = a.length, ia = 0, ib = 0, ic = 0, sa = 1, sb = 1, sc = 1) => + opg3((x, e1, e2) => smoothStep1(e1, e2, x), a, b, c, num, ia, ib, ic, sa, sb, sc); + +export class GVec implements + ICopy, + IEqualsDelta, + IVec { + + buf: Vec; + n: number; + i: number; + s: number; + + constructor(buf: Vec, n = buf.length, i = 0, s = 1) { + this.buf = buf; + this.n = n; + this.i = i; + this.s = s; + } + + copy() { + return new GVec(get(this.buf, this.n, this.i, this.s), this.n); + } + + eqDelta(v: GVec, eps = EPS) { + return this.n === v.n && eqDelta(this.buf, v.buf, this.n, eps, this.i, v.i, this.s, v.s); + } + + set(v: GVec) { + set(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s); + return this; + } + + setN(n: number) { + setN(this.buf, n, this.n, this.i, this.s); + return this; + } + + add(v: GVec) { + add(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s); + return this; + } + + sub(v: GVec) { + sub(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s); + return this; + } + + mul(v: GVec) { + mul(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s); + return this; + } + + div(v: GVec) { + div(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s); + return this; + } + + addN(n: number) { + addN(this.buf, n, this.n, this.i, this.s); + return this; + } + + subN(n: number) { + subN(this.buf, n, this.n, this.i, this.s); + return this; + } + + mulN(n: number) { + mulN(this.buf, n, this.n, this.i, this.s); + return this; + } + + divN(n: number) { + divN(this.buf, n, this.n, this.i, this.s); + return this; + } + + madd(b: Readonly, c: Readonly) { + madd(this.buf, b.buf, c.buf, this.n, this.i, b.i, c.i, this.s, b.s, c.s); + return this; + } + + maddN(b: Readonly, n: number) { + maddN(this.buf, b.buf, n, this.n, this.i, b.i, this.s, b.s); + return this; + } + + mix(b: Readonly, c: Readonly) { + mix(this.buf, b.buf, c.buf, this.n, this.i, b.i, c.i, this.s, b.s, c.s); + return this; + } + + mixN(b: Readonly, n: number) { + mixN(this.buf, b.buf, n, this.n, this.i, b.i, this.s, b.s); + return this; + } + + magSq() { + return magSq(this.buf, this.n, this.i, this.s); + } + + mag() { + return mag(this.buf, this.n, this.i, this.s); + } + + normalize(len = 1) { + normalize(this.buf, this.n, len, this.i, this.s); + return this; + } + + dot(v: GVec) { + return dot(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s); + } + + abs() { + abs(this.buf, this.n, this.i, this.s); + return this; + } + + sign() { + sign(this.buf, this.n, this.i, this.s); + return this; + } + + ceil() { + ceil(this.buf, this.n, this.i, this.s); + return this; + } + + floor() { + floor(this.buf, this.n, this.i, this.s); + return this; + } + + sin() { + sin(this.buf, this.n, this.i, this.s); + return this; + } + + cos() { + cos(this.buf, this.n, this.i, this.s); + return this; + } + + sqrt() { + sqrt(this.buf, this.n, this.i, this.s); + return this; + } + + pow(v: GVec) { + pow(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s); + return this; + } + + powN(n: number) { + powN(this.buf, n, this.n, this.i, this.s); + return this; + } + + min(v: Readonly) { + min(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s); + return this; + } + + max(v: Readonly) { + max(this.buf, v.buf, this.n, this.i, v.i, this.s, v.s); + return this; + } + + clamp(min: Readonly, max: Readonly) { + clamp(this.buf, min.buf, max.buf, this.n, this.i, min.i, max.i, this.s, min.s, max.s); + return this; + } + + step(e: Readonly) { + step(this.buf, e.buf, this.n, this.i, e.i, this.s, e.s); + return this; + } + + smoothStep(e1: Readonly, e2: Readonly) { + smoothStep(this.buf, e1.buf, e2.buf, this.n, this.i, e1.i, e2.i, this.s, e1.s, e2.s); + return this; + } + + toString() { + return `[${get(this.buf, this.n, this.i, this.s).join(", ")}]`; + } +} diff --git a/packages/vectors/src/index.ts b/packages/vectors/src/index.ts new file mode 100644 index 0000000000..5ffd20465f --- /dev/null +++ b/packages/vectors/src/index.ts @@ -0,0 +1,10 @@ +export * from "./api"; +export * from "./common"; +export * from "./mat23"; +export * from "./mat33"; +export * from "./mat44"; +export * from "./math"; +export * from "./gvec"; +export * from "./vec2"; +export * from "./vec3"; +export * from "./vec4"; diff --git a/packages/vectors/src/mat23.ts b/packages/vectors/src/mat23.ts new file mode 100644 index 0000000000..b8ea298e45 --- /dev/null +++ b/packages/vectors/src/mat23.ts @@ -0,0 +1,269 @@ +import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; +import { isArrayLike } from "@thi.ng/checks/is-arraylike"; +import { Mat, ReadonlyMat, Vec } from "./api"; +import { eqDelta } from "./common"; +import { EPS } from "./math"; +import { + cross2, + dot2, + setS2, + Vec2 +} from "./vec2"; + +export const get23 = (a: Mat, i = 0) => + set23(new ((a.constructor))(6), a, 0, i); + +export const set23 = (a: Mat, b: Mat, ia = 0, ib = 0) => ( + a[ia] = b[ib], + a[ia + 1] = b[ib + 1], + a[ia + 2] = b[ib + 2], + a[ia + 3] = b[ib + 3], + a[ia + 4] = b[ib + 4], + a[ia + 5] = b[ib + 5], + a +); + +/** + * ``` + * m00 m10 m20 + * m01 m11 m21 + * ``` + * + * @param m + * @param m00 + * @param m01 + * @param m10 + * @param m11 + * @param m20 + * @param m21 + * @param i + */ +export const setS23 = (m: Mat, m00: number, m01: number, m10: number, m11: number, m20: number, m21: number, i = 0) => ( + m[i] = m00, + m[i + 1] = m01, + m[i + 2] = m10, + m[i + 3] = m11, + m[i + 4] = m20, + m[i + 5] = m21, + m +); + +export const identity23 = (m?: Mat, i = 0) => + setS23(m || [], 1, 0, 0, 1, 0, 0, i); + +export const rotation23 = (m: Mat, theta: number, i = 0) => { + const s = Math.sin(theta); + const c = Math.cos(theta); + return setS23(m || [], c, s, -s, c, 0, 0, i); +}; + +export const rotationAroundPoint23 = (m: Mat, p: Vec, theta: number, im = 0, iv = 0, sv = 1) => + concat23( + translationV23(m || [], p, im, iv, sv), im, + rotation23([], theta), + translationS23([], -p[iv], -p[iv + sv]) + ); + +export const scaleV23 = (m: Mat, v: Vec, i = 0, iv = 0, sv = 1) => + scaleS23(m, v[iv], v[iv + sv], i); + +export const scaleN23 = (m: Mat, n: number, i = 0) => + scaleS23(m, n, n, i); + +export const scaleS23 = (m: Mat, sx: number, sy: number, i = 0) => + setS23(m || [], sx, 0, 0, sy, 0, 0, i); + +export const scaleWithCenter23 = (m: Mat, p: Vec, sx: number, sy: number, im = 0, iv = 0, sv = 1) => + concat23( + translationV23(m || [], p, im, iv, sv), im, + scaleS23([], sx, sy), + translationS23([], -p[iv], -p[iv + sv]) + ); + +export const translationV23 = (m: Mat, v: Vec, i = 0, iv = 0, sv = 1) => + translationS23(m, v[iv], v[iv + sv], i); + +export const translationS23 = (m: Mat, x: number, y: number, i = 0) => + setS23(m || [], 1, 0, 0, 1, x, y, i); + +export const shearX23 = (m: Mat, x: number, i = 0) => + setS23(m || [], 1, 0, x, 1, 0, 0, i); + +export const shearY23 = (m: Mat, y: number, i = 0) => + setS23(m || [], 1, y, 0, 1, 0, 0, i); + +export const skewX23 = (m: Mat, theta: number, i = 0) => + shearX23(m, Math.tan(theta), i); + +export const skewY23 = (m: Mat, theta: number, i = 0) => + shearY23(m, Math.tan(theta), i); + +export const mul23 = (a: Mat, b: ReadonlyMat, ia = 0, ib = 0) => + setS23( + a, + dot2(a, b, ia, ib, 2), + dot2(a, b, ia + 1, ib, 2), + dot2(a, b, ia, ib + 2, 2), + dot2(a, b, ia + 1, ib + 2, 2), + dot2(a, b, ia, ib + 4, 2) + a[ia + 4], + dot2(a, b, ia + 1, ib + 4, 2) + a[ia + 5], + ia + ); + +export const concat23 = (a: Mat, ia: number, ...xs: (ReadonlyMat | [ReadonlyMat, number])[]) => + xs.reduce( + (acc: Mat, x) => isArrayLike(x[0]) ? + mul23(acc, x[0], ia, x[1]) : + mul23(acc, x, ia), + a + ); + +export const mulV23 = (m: ReadonlyMat, v: Vec, im = 0, iv = 0, sv = 1) => + setS2( + v, + dot2(m, v, im, iv, 2, sv) + m[im + 4], + dot2(m, v, im + 1, iv, 2, sv) + m[im + 5], + iv, sv + ); + +export const det23 = (m: ReadonlyMat, i = 0) => + cross2(m, m, i, i + 1, 2, 2); + +export const invert23 = (m: Mat, i = 0) => { + const m00 = m[i]; + const m01 = m[i + 1]; + const m10 = m[i + 2]; + const m11 = m[i + 3]; + const m20 = m[i + 4]; + const m21 = m[i + 5]; + let det = m00 * m11 - m01 * m10; + if (!det) { + return; + } + det = 1.0 / det; + return setS23( + m, + m11 * det, + -m01 * det, + -m10 * det, + m00 * det, + (m10 * m21 - m11 * m20) * det, + (m01 * m20 - m00 * m21) * det, + i + ); +} + +export class Mat23 implements + ICopy, + IEqualsDelta { + + static rotation(theta: number) { + return new Mat23(rotation23([], theta)); + } + + static rotationAroundPoint(p: Vec2, theta: number) { + return new Mat23(rotationAroundPoint23([], p.buf, theta, 0, p.i, p.s)); + } + + static scale(v: Vec2): Mat23; + static scale(n: number): Mat23; + static scale(x: number, y: number): Mat23; + static scale(x: any, y = x) { + return new Mat23( + x instanceof Vec2 ? + scaleV23([], x.buf, 0, x.i, x.s) : + scaleS23([], x, y) + ); + } + + static scaleWithCenter(p: Vec2, sx: number, sy = sx) { + return new Mat23(scaleWithCenter23([], p.buf, sx, sy, p.i, p.s)); + } + + static translation(v: Vec2): Mat23; + static translation(x: number, y: number): Mat23; + static translation(x: any, y?: any) { + return new Mat23( + x instanceof Vec2 ? + translationV23([], x.buf, 0, x.i) : + translationS23([], x, y) + ); + } + + static skewX(x: number) { + return new Mat23(skewX23([], x)); + } + + static skewY(y: number) { + return new Mat23(skewY23([], y)); + } + + static shearX(theta: number) { + return new Mat23(shearX23([], theta)); + } + + static shearY(theta: number) { + return new Mat23(shearY23([], theta)); + } + + static concat(m: Mat23, ...xs: Readonly[]) { + concat23.apply(null, [m.buf, m.i, ...<[ReadonlyMat, number][]>xs.map((x) => [x.buf, x.i])]); + return m; + } + + buf: Mat; + i: number; + + constructor(buf: Mat, i = 0) { + this.buf = buf; + this.i = i; + } + + copy() { + return new Mat23(get23(this.buf, this.i)); + } + + eqDelta(m: Mat23, eps = EPS) { + return eqDelta(this.buf, m.buf, 6, eps, this.i, m.i); + } + + identity() { + identity23(this.buf, this.i); + return this; + } + + set(m: Readonly) { + set23(this.buf, m.buf, this.i, m.i); + return this; + } + + setS(m00: number, m01: number, m10: number, m11: number, m20: number, m21: number) { + setS23(this.buf, m00, m01, m10, m11, m20, m21, this.i); + return this; + } + + mul(m: Readonly) { + mul23(this.buf, m.buf, this.i, m.i); + return this; + } + + mulV(v: Vec2) { + mulV23(this.buf, v.buf, this.i, v.i, v.s); + return v; + } + + determinant() { + return det23(this.buf, this.i); + } + + invert() { + invert23(this.buf, this.i); + return this; + } + + toString() { + const b = this.buf; + const i = this.i; + return `${b[i]} ${b[i + 2]} ${b[i + 4]}\n${b[i + 1]} ${b[i + 3]} ${b[i + 5]}`; + } +} diff --git a/packages/vectors/src/mat33.ts b/packages/vectors/src/mat33.ts new file mode 100644 index 0000000000..75fe93863e --- /dev/null +++ b/packages/vectors/src/mat33.ts @@ -0,0 +1,308 @@ +import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; +import { isArrayLike } from "@thi.ng/checks/is-arraylike"; +import { Mat, ReadonlyMat, Vec } from "./api"; +import { eqDelta } from "./common"; +import { EPS } from "./math"; +import { + dot3, + set3, + setS3, + Vec3 +} from "./vec3"; +import { setS4 } from "./vec4"; + +export const get33 = (a: Mat, i = 0) => + set33(new ((a.constructor))(9), a, 0, i); + +export const set33 = (a: Mat, b: Mat, ia = 0, ib = 0) => ( + a[ia] = b[ib], + a[ia + 1] = b[ib + 1], + a[ia + 2] = b[ib + 2], + a[ia + 3] = b[ib + 3], + a[ia + 4] = b[ib + 4], + a[ia + 5] = b[ib + 5], + a[ia + 6] = b[ib + 6], + a[ia + 7] = b[ib + 7], + a[ia + 8] = b[ib + 8], + a +); + +/** + * ``` + * m00 m10 m20 + * m01 m11 m21 + * m02 m12 m22 + * ``` + * + * @param m + * @param m00 + * @param m01 + * @param m02 + * @param m10 + * @param m11 + * @param m12 + * @param m20 + * @param m21 + * @param m22 + * @param i + */ +export const setS33 = (m: Mat, m00: number, m01: number, m02: number, m10: number, m11: number, m12: number, m20: number, m21: number, m22: number, i = 0) => ( + m[i] = m00, + m[i + 1] = m01, + m[i + 2] = m02, + m[i + 3] = m10, + m[i + 4] = m11, + m[i + 5] = m12, + m[i + 6] = m20, + m[i + 7] = m21, + m[i + 8] = m22, + m +); + +export const identity33 = (m?: Mat, i = 0) => + setS33(m || [], + 1, 0, 0, + 0, 1, 0, + 0, 0, 1, + i + ); + +export const rotationX33 = (m: Mat, theta: number, i = 0) => { + const s = Math.sin(theta); + const c = Math.cos(theta); + return setS33(m || [], + 1, 0, 0, + 0, c, s, + 0, -s, c, + i + ); +}; + +export const rotationY33 = (m: Mat, theta: number, i = 0) => { + const s = Math.sin(theta); + const c = Math.cos(theta); + return setS33(m || [], + c, 0, -s, + 0, 1, 0, + s, 0, c, + i + ); +}; + +export const rotationZ33 = (m: Mat, theta: number, i = 0) => { + const s = Math.sin(theta); + const c = Math.cos(theta); + return setS33(m || [], + c, s, 0, + -s, c, 0, + 0, 0, 1, + i + ); +}; + +export const scaleV33 = (m: Mat, v: Vec, i = 0, iv = 0, sv = 1) => + scaleS33(m, v[iv], v[iv + sv], v[iv + 2 * sv], i); + +export const scaleN33 = (m: Mat, n: number, i = 0) => + scaleS33(m, n, n, n, i); + +export const scaleS33 = (m: Mat, sx: number, sy: number, sz: number, i = 0) => + setS33(m || [], + sx, 0, 0, + 0, sy, 0, + 0, 0, sz, + i + ); + +export const mul33 = (a: Mat, b: ReadonlyMat, ia = 0, ib = 0) => + setS33( + a, + dot3(a, b, ia, ib, 3), + dot3(a, b, ia + 1, ib, 3), + dot3(a, b, ia + 2, ib, 3), + dot3(a, b, ia, ib + 3, 3), + dot3(a, b, ia + 1, ib + 3, 3), + dot3(a, b, ia + 2, ib + 3, 3), + dot3(a, b, ia, ib + 6, 3), + dot3(a, b, ia + 1, ib + 6, 3), + dot3(a, b, ia + 2, ib + 6, 3), + ia + ); + +export const concat33 = (a: Mat, ia: number, ...xs: (ReadonlyMat | [ReadonlyMat, number])[]) => + xs.reduce( + (acc: Mat, x) => isArrayLike(x[0]) ? + mul33(acc, x[0], ia, x[1]) : + mul33(acc, x, ia), + a + ); + +export const mulV33 = (m: ReadonlyMat, v: Vec, im = 0, iv = 0, sv = 1) => + setS3( + v, + dot3(m, v, im, iv, 3, sv), + dot3(m, v, im + 1, iv, 3, sv), + dot3(m, v, im + 2, iv, 3, sv), + iv, sv + ); + +export const det33 = (m: ReadonlyMat, i = 0) => { + const m00 = m[i]; + const m01 = m[i + 1]; + const m02 = m[i + 2]; + const m10 = m[i + 3]; + const m11 = m[i + 4]; + const m12 = m[i + 5]; + const m20 = m[i + 6]; + const m21 = m[i + 7]; + const m22 = m[i + 8]; + const d01 = m22 * m11 - m12 * m21; + const d11 = -m22 * m10 + m12 * m20; + const d21 = m21 * m10 - m11 * m20; + return m00 * d01 + m01 * d11 + m02 * d21; +}; + +export const invert33 = (m: Mat, i = 0) => { + const m00 = m[i]; + const m01 = m[i + 1]; + const m02 = m[i + 2]; + const m10 = m[i + 3]; + const m11 = m[i + 4]; + const m12 = m[i + 5]; + const m20 = m[i + 6]; + const m21 = m[i + 7]; + const m22 = m[i + 8]; + const d01 = m22 * m11 - m12 * m21; + const d11 = -m22 * m10 + m12 * m20; + const d21 = m21 * m10 - m11 * m20; + let det = m00 * d01 + m01 * d11 + m02 * d21; + if (!det) { + return; + } + det = 1.0 / det; + return setS33( + m, + d01 * det, + (-m22 * m01 + m02 * m21) * det, + (m12 * m01 - m02 * m11) * det, + d11 * det, + (m22 * m00 - m02 * m20) * det, + (-m12 * m00 + m02 * m10) * det, + d21 * det, + (-m21 * m00 + m01 * m20) * det, + (m11 * m00 - m01 * m10) * det, + i + ); +} + +export const transpose33 = (m: Mat, i = 0) => + setS33( + m, + m[i], m[i + 3], m[i + 6], + m[i + 1], m[i + 4], m[i + 7], + m[i + 2], m[i + 5], m[i + 8], + i + ); + +export const mat33to44 = (m44: Mat, m33: Mat, ia = 0, ib = 0) => ( + set3(m44, m33, ia, ib), + set3(m44, m33, ia + 4, ib + 3), + set3(m44, m33, ia + 8, ib + 6), + setS3(m44, 0, 0, 0, ia + 12), + setS4(m44, 0, 0, 0, 1, ia + 3, 4), + m44 +); + +export class Mat33 implements + ICopy, + IEqualsDelta { + + static rotationX(theta: number) { + return new Mat33(rotationX33([], theta)); + } + + static rotationY(theta: number) { + return new Mat33(rotationY33([], theta)); + } + + static rotationZ(theta: number) { + return new Mat33(rotationZ33([], theta)); + } + + static scale(v: Vec3): Mat33; + static scale(n: number): Mat33; + static scale(x: number, y: number, z: number): Mat33; + static scale(x: any, y = x, z = x) { + return new Mat33( + x instanceof Vec3 ? + scaleV33([], x.buf, 0, x.i) : + scaleS33([], x, y, z) + ); + } + + static concat(m: Mat33, ...xs: Readonly[]) { + concat33.apply(null, [m.buf, m.i, ...<[ReadonlyMat, number][]>xs.map((x) => [x.buf, x.i])]); + return m; + } + + buf: Mat; + i: number; + + constructor(buf: Mat, i = 0) { + this.buf = buf; + this.i = i; + } + + copy() { + return new Mat33(get33(this.buf, this.i)); + } + + eqDelta(m: Mat33, eps = EPS) { + return eqDelta(this.buf, m.buf, 9, eps, this.i, m.i); + } + + identity() { + identity33(this.buf, this.i); + return this; + } + + set(m: Readonly) { + set33(this.buf, m.buf, this.i, m.i); + return this; + } + + setS(m00: number, m01: number, m02: number, m10: number, m11: number, m12: number, m20: number, m21: number, m22: number) { + setS33(this.buf, m00, m01, m02, m10, m11, m12, m20, m21, m22, this.i); + return this; + } + + mul(m: Readonly) { + mul33(this.buf, m.buf, this.i, m.i); + return this; + } + + mulV(v: Vec3) { + mulV33(this.buf, v.buf, this.i, v.i, v.s); + return v; + } + + determinant() { + return det33(this.buf, this.i); + } + + invert() { + invert33(this.buf, this.i); + return this; + } + + transpose() { + transpose33(this.buf, this.i); + return this; + } + + toString() { + const b = this.buf; + const i = this.i; + return `${b[i]} ${b[i + 3]} ${b[i + 6]}\n${b[i + 1]} ${b[i + 4]} ${b[i + 7]}\n${b[i + 2]} ${b[i + 5]} ${b[i + 8]}`; + } +} diff --git a/packages/vectors/src/mat44.ts b/packages/vectors/src/mat44.ts new file mode 100644 index 0000000000..0ef1aa0a31 --- /dev/null +++ b/packages/vectors/src/mat44.ts @@ -0,0 +1,518 @@ +import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; +import { isArrayLike } from "@thi.ng/checks/is-arraylike"; +import { Mat, ReadonlyMat, Vec } from "./api"; +import { eqDelta } from "./common"; +import { Mat33 } from "./mat33"; +import { EPS, rad } from "./math"; +import { + cross3, + dot3, + get3, + normalize3, + set3, + setS3, + sub3, + Vec3 +} from "./vec3"; +import { dot4, setS4, Vec4 } from "./vec4"; + +export const get44 = (a: Mat, i = 0) => + set44(new ((a.constructor))(16), a, 0, i); + +export const set44 = (a: Mat, b: Mat, ia = 0, ib = 0) => { + for (let i = 0; i < 16; i++) { + a[ia + i] = b[ib + i]; + } + return a; +}; + +/** + * ``` + * m00 m10 m20 m30 + * m01 m11 m21 m31 + * m02 m12 m22 m32 + * m03 m13 m23 m33 + * ``` + */ +export const setS44 = (m: Mat, m00: number, m01: number, m02: number, m03: number, + m10: number, m11: number, m12: number, m13: number, + m20: number, m21: number, m22: number, m23: number, + m30: number, m31: number, m32: number, m33: number, + i = 0) => ( + m[i] = m00, + m[i + 1] = m01, + m[i + 2] = m02, + m[i + 3] = m03, + m[i + 4] = m10, + m[i + 5] = m11, + m[i + 6] = m12, + m[i + 7] = m13, + m[i + 8] = m20, + m[i + 9] = m21, + m[i + 10] = m22, + m[i + 11] = m23, + m[i + 12] = m30, + m[i + 13] = m31, + m[i + 14] = m32, + m[i + 15] = m33, + m + ); + +export const identity44 = (m?: Mat, i = 0) => + setS44(m || [], + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1, + i + ); + +export const rotationX44 = (m: Mat, theta: number, i = 0) => { + const s = Math.sin(theta); + const c = Math.cos(theta); + return setS44(m || [], + 1, 0, 0, 0, + 0, c, s, 0, + 0, -s, c, 0, + 0, 0, 0, 1, + i + ); +}; + +export const rotationY44 = (m: Mat, theta: number, i = 0) => { + const s = Math.sin(theta); + const c = Math.cos(theta); + return setS44(m || [], + c, 0, -s, 0, + 0, 1, 0, 0, + s, 0, c, 0, + 0, 0, 0, 1, + i + ); +}; + +export const rotationZ44 = (m: Mat, theta: number, i = 0) => { + const s = Math.sin(theta); + const c = Math.cos(theta); + return setS44(m || [], + c, s, 0, 0, + -s, c, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1, + i + ); +}; + +export const scaleV44 = (m: Mat, v: Vec, i = 0, iv = 0, sv = 1) => + scaleS44(m, v[iv], v[iv + sv], v[iv + 2 * sv], i); + +export const scaleN44 = (m: Mat, n: number, i = 0) => + scaleS44(m, n, n, n, i); + +export const scaleS44 = (m: Mat, sx: number, sy: number, sz: number, i = 0) => + setS44(m || [], + sx, 0, 0, 0, + 0, sy, 0, 0, + 0, 0, sz, 0, + 0, 0, 0, 1, + i + ); + +export const scaleWithCenter44 = (m: Mat, p: Vec, sx: number, sy: number, sz: number, im = 0, iv = 0, sv = 1) => + concat44( + translationV44(m || [], p, im, iv, sv), im, + scaleS44([], sx, sy, sz), + translationS44([], -p[iv], -p[iv + sv], -p[iv + 2 * sv]) + ); + +export const translationV44 = (m: Mat, v: Vec, i = 0, iv = 0, sv = 1) => + translationS44(m, v[iv], v[iv + sv], v[iv + 2 * sv], i); + +export const translationS44 = (m: Mat, x: number, y: number, z: number, i = 0) => + setS44(m || [], + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + x, y, z, 1, + i + ); + +export const frustum = (m: Mat, left: number, right: number, bottom: number, top: number, near: number, far: number, i = 0) => { + const dx = 1 / (right - left); + const dy = 1 / (top - bottom); + const dz = 1 / (far - near); + return setS44(m || [], + near * 2 * dx, 0, 0, 0, + 0, near * 2 * dy, 0, 0, + (right + left) * dx, (top + bottom) * dy, -(far + near) * dz, -1, + 0, 0, -(far * near * 2) * dz, 0, + i + ); +}; + +export const frustumBounds = (fovy: number, aspect: number, near: number, far: number) => { + const top = near * Math.tan(rad(fovy) / 2); + const right = top * aspect; + return { + left: -right, + right, + bottom: -top, + top, + near, + far + }; +}; + +export const perspective = (m: Mat, fov: number, aspect: number, near: number, far: number, i = 0) => { + const f = frustumBounds(fov, aspect, near, far); + return frustum(m || [], f.left, f.right, f.bottom, f.top, f.near, f.far, i); +}; + +export const ortho = (m: Mat, left: number, right: number, bottom: number, top: number, near: number, far: number, i = 0) => { + const dx = 1 / (right - left); + const dy = 1 / (top - bottom); + const dz = 1 / (far - near); + return setS44(m || [], + 2 * dx, 0, 0, 0, + 0, 2 * dy, 0, 0, + 0, 0, -2 * dz, 0, + -(left + right) * dx, -(top + bottom) * dy, -(far + near) * dz, 1, + i + ); +}; + +export const lookAt = (m: Mat, eye: Vec, target: Vec, up: Vec, im = 0, ie = 0, it = 0, iu = 0, se = 1, st = 1, su = 1) => { + eye = get3(eye, ie, se); + target = get3(target, it, st); + up = get3(up, iu, su); + const z = normalize3(sub3([...eye], target)); + const x = normalize3(cross3(up, z)); + const y = normalize3(cross3([...z], x)); + return setS44(m || [], + x[0], y[0], z[0], 0, + x[1], y[1], z[1], 0, + x[2], y[2], z[2], 0, + -dot3(eye, x), -dot3(eye, y), -dot3(eye, z), 1, + im + ); +} + +export const mul44 = (a: Mat, b: ReadonlyMat, ia = 0, ib = 0) => + setS44( + a, + dot4(a, b, ia, ib, 4), + dot4(a, b, ia + 1, ib, 4), + dot4(a, b, ia + 2, ib, 4), + dot4(a, b, ia + 3, ib, 4), + dot4(a, b, ia, ib + 4, 4), + dot4(a, b, ia + 1, ib + 4, 4), + dot4(a, b, ia + 2, ib + 4, 4), + dot4(a, b, ia + 3, ib + 4, 4), + dot4(a, b, ia, ib + 8, 4), + dot4(a, b, ia + 1, ib + 8, 4), + dot4(a, b, ia + 2, ib + 8, 4), + dot4(a, b, ia + 3, ib + 8, 4), + dot4(a, b, ia, ib + 12, 4), + dot4(a, b, ia + 1, ib + 12, 4), + dot4(a, b, ia + 2, ib + 12, 4), + dot4(a, b, ia + 3, ib + 12, 4), + ia + ); + +export const concat44 = (a: Mat, ia: number, ...xs: (ReadonlyMat | [ReadonlyMat, number])[]) => + xs.reduce( + (acc: Mat, x) => isArrayLike(x[0]) ? + mul44(acc, x[0], ia, x[1]) : + mul44(acc, x, ia), + a + ); + +export const mulV344 = (m: ReadonlyMat, v: Vec, im = 0, iv = 0, sv = 1) => + setS3( + v, + dot3(m, v, im, iv, 4, sv) + m[12], + dot3(m, v, im + 1, iv, 4, sv) + m[13], + dot3(m, v, im + 2, iv, 4, sv) + m[14], + iv, sv + ); + +export const mulV44 = (m: ReadonlyMat, v: Vec, im = 0, iv = 0, sv = 1) => + setS4( + v, + dot4(m, v, im, iv, 4, sv), + dot4(m, v, im + 1, iv, 4, sv), + dot4(m, v, im + 2, iv, 4, sv), + dot4(m, v, im + 3, iv, 4, sv), + iv, sv + ); + +const detCoeffs44 = (m: ReadonlyMat, i = 0) => { + const m00 = m[i]; + const m01 = m[i + 1]; + const m02 = m[i + 2]; + const m03 = m[i + 3]; + const m10 = m[i + 4]; + const m11 = m[i + 5]; + const m12 = m[i + 6]; + const m13 = m[i + 7]; + const m20 = m[i + 8]; + const m21 = m[i + 9]; + const m22 = m[i + 10]; + const m23 = m[i + 11]; + const m30 = m[i + 12]; + const m31 = m[i + 13]; + const m32 = m[i + 14]; + const m33 = m[i + 15]; + return [ + m00 * m11 - m01 * m10, + m00 * m12 - m02 * m10, + m00 * m13 - m03 * m10, + m01 * m12 - m02 * m11, + m01 * m13 - m03 * m11, + m02 * m13 - m03 * m12, + m20 * m31 - m21 * m30, + m20 * m32 - m22 * m30, + m20 * m33 - m23 * m30, + m21 * m32 - m22 * m31, + m21 * m33 - m23 * m31, + m22 * m33 - m23 * m32, + ]; +}; + +export const det44 = (m: Mat, i = 0) => { + const d = detCoeffs44(m, i); + return d[0] * d[11] - d[1] * d[10] + d[2] * d[9] + + d[3] * d[8] - d[4] * d[7] + d[5] * d[6]; +}; + +export const invert44 = (m: Mat, i = 0) => { + const m00 = m[i]; + const m01 = m[i + 1]; + const m02 = m[i + 2]; + const m03 = m[i + 3]; + const m10 = m[i + 4]; + const m11 = m[i + 5]; + const m12 = m[i + 6]; + const m13 = m[i + 7]; + const m20 = m[i + 8]; + const m21 = m[i + 9]; + const m22 = m[i + 10]; + const m23 = m[i + 11]; + const m30 = m[i + 12]; + const m31 = m[i + 13]; + const m32 = m[i + 14]; + const m33 = m[i + 15]; + const d = detCoeffs44(m, i); + const d00 = d[0]; + const d01 = d[1]; + const d02 = d[2]; + const d03 = d[3]; + const d04 = d[4]; + const d05 = d[5]; + const d06 = d[6]; + const d07 = d[7]; + const d08 = d[8]; + const d09 = d[9]; + const d10 = d[10]; + const d11 = d[11]; + let det = (d00 * d11 - d01 * d10 + d02 * d09 + d03 * d08 - d04 * d07 + d05 * d06); + if (!det) { + return; + } + det = 1.0 / det; + return setS44( + m, + (m11 * d11 - m12 * d10 + m13 * d09) * det, + (-m01 * d11 + m02 * d10 - m03 * d09) * det, + (m31 * d05 - m32 * d04 + m33 * d03) * det, + (-m21 * d05 + m22 * d04 - m23 * d03) * det, + (-m10 * d11 + m12 * d08 - m13 * d07) * det, + (m00 * d11 - m02 * d08 + m03 * d07) * det, + (-m30 * d05 + m32 * d02 - m33 * d01) * det, + (m20 * d05 - m22 * d02 + m23 * d01) * det, + (m10 * d10 - m11 * d08 + m13 * d06) * det, + (-m00 * d10 + m01 * d08 - m03 * d06) * det, + (m30 * d04 - m31 * d02 + m33 * d00) * det, + (-m20 * d04 + m21 * d02 - m23 * d00) * det, + (-m10 * d09 + m11 * d07 - m12 * d06) * det, + (m00 * d09 - m01 * d07 + m02 * d06) * det, + (-m30 * d03 + m31 * d01 - m32 * d00) * det, + (m20 * d03 - m21 * d01 + m22 * d00) * det, + i + ); +} + +export const transpose44 = (m: Mat, i = 0) => + setS44( + m, + m[i], m[i + 4], m[i + 8], m[i + 12], + m[i + 1], m[i + 5], m[i + 9], m[i + 13], + m[i + 2], m[i + 6], m[i + 10], m[i + 14], + m[i + 3], m[i + 7], m[i + 11], m[i + 15], + i + ); + +export const normal44 = (a: Mat, b: Mat, ia = 0, ib = 0) => { + const m00 = b[ib]; + const m01 = b[ib + 1]; + const m02 = b[ib + 2]; + const m10 = b[ib + 4]; + const m11 = b[ib + 5]; + const m12 = b[ib + 6]; + const m20 = b[ib + 8]; + const m21 = b[ib + 9]; + const m22 = b[ib + 10]; + const d01 = m22 * m11 - m12 * m21; + const d11 = -m22 * m10 + m12 * m20; + const d21 = m21 * m10 - m11 * m20; + let det = m00 * d01 + m01 * d11 + m02 * d21; + if (!det) { + return; + } + det = 1.0 / det; + a[ia] = d01 * det; + a[ia + 1] = d11 * det; + a[ia + 2] = d21 * det; + a[ia + 3] = (-m22 * m01 + m02 * m21) * det; + a[ia + 4] = (m22 * m00 - m02 * m20) * det; + a[ia + 5] = (-m21 * m00 + m01 * m20) * det; + a[ia + 6] = (m12 * m01 - m02 * m11) * det; + a[ia + 7] = (-m12 * m00 + m02 * m10) * det; + a[ia + 8] = (m11 * m00 - m01 * m10) * det; + return a; +}; + +export const mat44to33 = (m33: Mat, m44: Mat, ia = 0, ib = 0) => ( + set3(m33, m44, ia, ib), + set3(m33, m44, ia + 3, ib + 4), + set3(m33, m44, ia + 6, ib + 8), + m33 +); + +export class Mat44 implements + ICopy, + IEqualsDelta { + + static rotationX(theta: number) { + return new Mat44(rotationX44([], theta)); + } + + static rotationY(theta: number) { + return new Mat44(rotationY44([], theta)); + } + + static rotationZ(theta: number) { + return new Mat44(rotationZ44([], theta)); + } + + static scale(v: Vec3): Mat44; + static scale(n: number): Mat44; + static scale(x: number, y: number, z: number): Mat44; + static scale(x: any, y = x, z = x) { + return new Mat44( + x instanceof Vec3 ? + scaleV44([], x.buf, 0, x.i) : + scaleS44([], x, y, z) + ); + } + + static scaleWithCenter(p: Vec3, sx: number, sy = sx, sz = sy) { + return new Mat44(scaleWithCenter44([], p.buf, sx, sy, sz, p.i, p.s)); + } + + static translation(v: Vec3): Mat44; + static translation(x: number, y: number, z: number): Mat44; + static translation(x: any, y?: any, z?: any) { + return new Mat44( + x instanceof Vec3 ? + translationV44([], x.buf, 0, x.i) : + translationS44([], x, y, z) + ); + } + + static concat(m: Mat44, ...xs: Readonly[]) { + concat44.apply(null, [m.buf, m.i, ...<[ReadonlyMat, number][]>xs.map((x) => [x.buf, x.i])]); + return m; + } + + buf: Mat; + i: number; + + constructor(buf: Mat, i = 0) { + this.buf = buf; + this.i = i; + } + + copy() { + return new Mat44(get44(this.buf, this.i)); + } + + eqDelta(m: Mat44, eps = EPS) { + return eqDelta(this.buf, m.buf, 16, eps, this.i, m.i); + } + + identity() { + identity44(this.buf, this.i); + return this; + } + + set(m: Readonly) { + set44(this.buf, m.buf, this.i, m.i); + return this; + } + + setS(m00: number, m01: number, m02: number, m03: number, + m10: number, m11: number, m12: number, m13: number, + m20: number, m21: number, m22: number, m23: number, + m30: number, m31: number, m32: number, m33: number) { + setS44(this.buf, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33, this.i); + return this; + } + + mul(m: Readonly) { + mul44(this.buf, m.buf, this.i, m.i); + return this; + } + + mulV3(v: Vec3) { + mulV344(this.buf, v.buf, this.i, v.i, v.s); + return v; + } + + mulV(v: Vec4) { + mulV44(this.buf, v.buf, this.i, v.i, v.s); + return v; + } + + determinant() { + return det44(this.buf, this.i); + } + + invert() { + invert44(this.buf, this.i); + return this; + } + + transpose() { + transpose44(this.buf, this.i); + return this; + } + + normalMat(m?: Mat33) { + !m && (m = new Mat33([])); + normal44(m.buf, this.buf, m.i, this.i); + return m; + } + + toMat33(m?: Mat33) { + !m && (m = new Mat33([])); + mat44to33(m.buf, this.buf, m.i, this.i); + return m; + } + + toString() { + const b = this.buf; + const i = this.i; + return `${b[i]} ${b[i + 4]} ${b[i + 8]} ${b[i + 12]}\n${b[i + 1]} ${b[i + 5]} ${b[i + 9]} ${b[i + 13]}\n${b[i + 2]} ${b[i + 6]} ${b[i + 10]} ${b[i + 14]}\n${b[i + 3]} ${b[i + 7]} ${b[i + 11]} ${b[i + 15]}`; + } +} diff --git a/packages/vectors/src/math.ts b/packages/vectors/src/math.ts new file mode 100644 index 0000000000..9f8d9fb182 --- /dev/null +++ b/packages/vectors/src/math.ts @@ -0,0 +1,150 @@ +export const PI = Math.PI; +export const TAU = PI * 2; +export const HALF_PI = PI / 2; +export const QUARTER_PI = PI / 2; + +export const DEG2RAD = PI / 180; +export const RAD2DEG = 180 / PI; + +export let EPS = 1e-6; + +export const absDiff = (x: number, y: number) => + Math.abs(x - y); + +export const atan2Abs = (y: number, x: number) => { + const theta = Math.atan2(y, x); + return theta < 0 ? TAU + theta : theta; +}; + +/** + * Converts angle to degrees. + * + * @param x angle in radians + */ +export const deg = (x: number) => x * RAD2DEG; + +/** + * Converts angle to radians. + * + * @param x angle in degrees + */ +export const rad = (x: number) => x * DEG2RAD; + +/** + * Checks if `|a - b| <= ε`. + * + * @param a left value + * @param b right value + * @param eps epsilon / tolerance + */ +export const eqDelta1 = (a: number, b: number, eps = EPS) => { + const d = a - b; + return (d < 0 ? -d : d) <= eps; +}; + +/** + * Returns `a - b * n` + * + * @param a + * @param b + */ +export const fmod1 = (a: number, b: number) => a - b * Math.floor(a / b); + +/** + * Step/threshold function. + * + * @param edge threshold + * @param x test value + * @returns 0, if `x < e`, else 1 + */ +export const step1 = (edge: number, x: number) => x < edge ? 0 : 1; + +/** + * GLSL-style smoothStep threshold function. + * + * @param edge lower threshold + * @param edge2 upper threshold + * @param x test value + * @returns 0, if `x < edge1`, 1 if `x > edge2`, else sigmoid interpolation + */ +export const smoothStep1 = (edge: number, edge2: number, x: number) => { + const t = clamp1((x - edge) / (edge2 - edge), 0, 1); + return (3 - 2 * t) * t * t; +}; + +export const min2id = (a, b) => a <= b ? 0 : 1; + +export const min3id = (a, b, c) => + (a <= b) ? + (a <= c ? 0 : 2) : + (b <= c ? 1 : 2); + +export const min4id = (a, b, c, d) => + a <= b ? + (a <= c ? + (a <= d ? 0 : 3) : + (c <= d ? 2 : 3)) : + (b <= c ? + (b <= d ? 1 : 3) : + (c <= d ? 2 : 3)); + +export const max2id = (a, b) => a >= b ? 0 : 1; + +export const max3id = (a, b, c) => + (a >= b) ? + (a >= c ? 0 : 2) : + (b >= c ? 1 : 2); + +export const max4id = (a, b, c, d) => + a >= b ? + (a >= c ? + (a >= d ? 0 : 3) : + (c >= d ? 2 : 3)) : + (b >= c ? + (b >= d ? 1 : 3) : + (c >= d ? 2 : 3)); + +/** + * Clamps value `x` to given closed interval. + * + * @param x value to clamp + * @param min lower bound + * @param max upper bound + */ +export const clamp1 = (x: number, min: number, max: number) => + x < min ? min : x > max ? max : x; + +export const fit1 = (x: number, a: number, b: number, c: number, d: number) => + c + (d - c) * (x - a) / (b - a); + +export const fitClamped1 = (x: number, a: number, b: number, c: number, d: number) => + c + (d - c) * clamp1((x - a) / (b - a), 0, 1); + +export const sign1 = (x: number, eps = EPS) => + x > eps ? 1 : x < -eps ? -1 : 0; + +export const trunc1 = (x: number) => + x < 0 ? Math.ceil(x) : Math.floor(x); + +export const roundTo1 = (x: number, prec = 1) => + Math.round(x / prec) * prec; + +/** + * Returns true iff `x` is in closed interval `[min .. max]` + * + * @param x + * @param min + * @param max + */ +export const inRange = (x: number, min: number, max: number) => + x >= min && x <= max; + +/** + * Returns true iff `x` is in open interval `(min .. max)` + * + * @param x + * @param min + * @param max + */ +export const inOpenRange = (x: number, min: number, max: number) => + x > min && x < max; diff --git a/packages/vectors/src/vec2.ts b/packages/vectors/src/vec2.ts new file mode 100644 index 0000000000..4c285d9864 --- /dev/null +++ b/packages/vectors/src/vec2.ts @@ -0,0 +1,528 @@ +import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; +import { IVec, ReadonlyVec, Vec } from "./api"; +import { + atan2Abs, + EPS, + eqDelta1, + max2id, + min2id, + smoothStep1, + step1 +} from "./math"; + +export const ZERO2 = Object.freeze([0, 0]); +export const ONE2 = Object.freeze([1, 1]); + +export const op2 = (fn: (x: number) => number, a: Vec, ia = 0, sa = 1) => + (a[ia] = fn(a[ia]), a[ia + sa] = fn(a[ia + sa]), a); + +export const op22 = (fn: (a: number, b: number) => number, a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] = fn(a[ia], b[ib]), + a[ia + sa] = fn(a[ia + sa], b[ib + sb]), + a +); + +export const get2 = (a: ReadonlyVec, ia = 0, sa = 1) => + set2(new ((a.constructor))(2), a, 0, ia, 1, sa); + +export const set2 = (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 setN2 = (a: Vec, n: number, ia = 0, sa = 1) => + (a[ia] = n, a[ia + sa] = n, a); + +export const setS2 = (a: Vec, x: number, y: number, ia = 0, sa = 1) => + (a[ia] = x, a[ia + sa] = y, a); + +export const swizzle2 = (a: Vec, b: Vec, x: number, y: number, ia = 0, ib = 0, sa = 1, sb = 1) => { + const xx = b[ib + x * sb]; + const yy = b[ib + y * sb]; + a[ia] = xx; + a[ia + sa] = yy; + return a; +}; + +export const eqDelta2 = (a: ReadonlyVec, b: ReadonlyVec, eps = EPS, ia = 0, ib = 0, sa = 1, sb = 1) => + eqDelta1(a[ia], b[ib], eps) && + eqDelta1(a[ia + sa], b[ib + sb], eps); + +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 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 addN2 = (a: Vec, n: number, ia = 0, sa = 1) => + (a[ia] += n, a[ia + sa] += n, a); + +export const subN2 = (a: Vec, n: number, ia = 0, sa = 1) => + (a[ia] -= n, a[ia + sa] -= n, a); + +export const mulN2 = (a: Vec, n: number, ia = 0, sa = 1) => + (a[ia] *= n, a[ia + sa] *= n, a); + +export const divN2 = (a: Vec, n: number, ia = 0, sa = 1) => + (a[ia] /= n, a[ia + sa] /= n, a); + +export const neg2 = (a: Vec, ia = 0, sa = 1) => + mulN2(a, -1, ia, sa); + +export const abs2 = (a: Vec, ia = 0, sa = 1) => + op2(Math.abs, a, ia, sa); + +export const sign2 = (a: Vec, ia = 0, sa = 1) => + op2(Math.sign, a, ia, sa); + +export const floor2 = (a: Vec, ia = 0, sa = 1) => + op2(Math.floor, a, ia, sa); + +export const ceil2 = (a: Vec, ia = 0, sa = 1) => + op2(Math.ceil, a, ia, sa); + +export const sin2 = (a: Vec, ia = 0, sa = 1) => + op2(Math.sin, a, ia, sa); + +export const cos2 = (a: Vec, ia = 0, sa = 1) => + op2(Math.cos, a, ia, sa); + +export const sqrt2 = (a: Vec, ia = 0, sa = 1) => + op2(Math.sqrt, a, ia, sa); + +export const pow2 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] = Math.pow(a[ia], b[ib]), + a[ia + sa] = Math.pow(a[ia + sa], b[ib + sb]), + a +); + +export const powN2 = (a: Vec, n: number, ia = 0, sa = 1) => ( + a[ia] = Math.pow(a[ia], n), + a[ia + sa] = Math.pow(a[ia + sa], n), + a +); + +export const madd2 = (a: Vec, b: ReadonlyVec, c: ReadonlyVec, ia = 0, ib = 0, ic = 0, sa = 1, sb = 1, sc = 1) => + (a[ia] += b[ib] * c[ic], a[ia + sa] += b[ib + sb] * c[ic + sc], a); + +export const maddN2 = (a: Vec, b: ReadonlyVec, c: number, ia = 0, ib = 0, sa = 1, sb = 1) => + (a[ia] += b[ib] * c, a[ia + sa] += b[ib + sb] * c, a); + +export const dot2 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + a[ia] * b[ib] + a[ia + sa] * b[ib + sb]; + +export const cross2 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + a[ia] * b[ib + sb] - a[ia + sa] * b[ib]; + +export const mix2 = (a: Vec, b: ReadonlyVec, t: ReadonlyVec, ia = 0, ib = 0, it = 0, sa = 1, sb = 1, st = 1) => ( + a[ia] += (b[ib] - a[ia]) * t[it], + a[ia + sa] += (b[ib + sb] - a[ia + sa]) * t[it + st], + a +); + +export const mixN2 = (a: Vec, b: ReadonlyVec, t: number, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] += (b[ib] - a[ia]) * t, + a[ia + sa] += (b[ib + sb] - a[ia + sa]) * t, + a +); + +export const min2 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + op22(Math.min, a, b, ia, ib, sa, sb); + +export const max2 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + op22(Math.max, a, b, ia, ib, sa, sb); + +export const clamp2 = (a: Vec, min: ReadonlyVec, max: ReadonlyVec, ia = 0, imin = 0, imax = 0, sa = 1, smin = 1, smax = 1) => + max2(min2(a, max, ia, imax, sa, smax), min, ia, imin, sa, smin); + +export const step2 = (a: Vec, e: ReadonlyVec, ia = 0, ie = 0, sa = 1, stridee = 1) => + (a[ia] = step1(e[ie], a[ia]), a[ia + sa] = step1(e[ie + stridee], a[ia + sa]), a); + +export const smoothStep2 = (a: Vec, e1: ReadonlyVec, e2: ReadonlyVec, ia = 0, ie1 = 0, ie2 = 0, sa = 1, se1 = 1, se2 = 1) => ( + a[ia] = smoothStep1(e1[ie1], e2[ie2], a[ia]), + a[ia + sa] = smoothStep1(e1[ie1 + se1], e2[ie2 + se2], a[ia + sa]), + a +); + +export const magSq2 = (a: ReadonlyVec, ia = 0, sa = 1) => { + const x = a[ia], y = a[ia + sa]; + return x * x + y * y; +}; + +export const mag2 = (a: ReadonlyVec, ia = 0, sa = 1) => + Math.sqrt(magSq2(a, ia, sa)); + +export const distSq2 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => { + const x = a[ia] - b[ib]; + const y = a[ia + sa] - b[ib + sb]; + return x * x + y * y; +}; + +export const dist2 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + Math.sqrt(distSq2(a, b, ia, ib, sa, sb)); + +export const distManhattan2 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => { + return Math.abs(a[ia] - b[ib]) + Math.abs(a[ia + sa] - b[ib + sb]) +}; + +export const distChebyshev2 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => { + return Math.max(Math.abs(a[ia] - b[ib]), Math.abs(a[ia + sa] - b[ib + sb])) +}; + +export const normalize2 = (a: Vec, n = 1, ia = 0, sa = 1) => { + const m = mag2(a, ia, sa); + m >= EPS && mulN2(a, n / m, ia, sa); + return a; +}; + +export const limit2 = (a: Vec, n: number, ia = 0, sa = 1) => { + const m = mag2(a, ia, sa); + m >= n && mulN2(a, n / m, ia, sa); + return a; +}; + +export const reflect2 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + maddN2(a, b, -2 * dot2(a, b, ia, ib, sa, sb), ia, ib, sa, sb); + +export const rotate2 = (a: Vec, theta: number, ia = 0, sa = 1) => { + const s = Math.sin(theta); + const c = Math.cos(theta); + const x = a[ia]; + const y = a[ia + sa]; + return setS2(a, x * c - y * s, x * s + y * c, ia, sa); +}; + +export const heading2 = (a: ReadonlyVec, ia = 0, sa = 1) => + atan2Abs(a[ia + sa], a[ia]); + +export const toPolar2 = (a: Vec, ia = 0, sa = 1) => { + const x = a[ia], y = a[ia + sa]; + return setS2(a, Math.sqrt(x * x + y * y), atan2Abs(y, x), ia, sa); +}; + +export const toCartesian2 = (a: Vec, b: ReadonlyVec = ZERO2, ia = 0, ib = 0, sa = 1, sb = 1) => { + const r = a[ia], theta = a[ia + sa]; + return setS2( + a, + r * Math.cos(theta) + b[ib], + r * Math.sin(theta) + b[ib + sb], + ia, sa + ); +}; + +export const minorAxis2 = (a: Vec, ia = 0, sa = 1) => + min2id(Math.abs(a[ia]), Math.abs(a[ia + sa])); + +export const majorAxis2 = (a: Vec, ia = 0, sa = 1) => + max2id(Math.abs(a[ia]), Math.abs(a[ia + sa])); + +export const vec2 = (x = 0, y = 0) => + new Vec2([x, y]); + +export class Vec2 implements + ICopy, + IEqualsDelta, + IVec { + + /** + * Returns array of memory mapped `Vec2` instances using given + * backing array and stride settings: The `cstride` is the step size + * between individual XYZ vector components. `estride` is the step + * size between successive vectors. This arrangement allows for + * different storage approaches, incl. SOA, AOS, striped / + * interleaved etc. + * + * @param buf backing array + * @param n num vectors + * @param start start index + * @param cstride component stride + * @param estride element stride + */ + static mapBuffer(buf: Vec, n: number, start = 0, cstride = 1, estride = 2) { + const res: Vec2[] = []; + while (--n >= 0) { + res.push(new Vec2(buf, start, cstride)); + start += estride; + } + return res; + } + + static ZERO = Object.freeze(new Vec2(ZERO2)); + static ONE = Object.freeze(new Vec2(ONE2)); + + buf: Vec; + i: number; + s: number; + + constructor(buf: Vec, index = 0, stride = 1) { + this.buf = buf; + this.i = index; + this.s = stride; + } + + *[Symbol.iterator]() { + yield this.x; + yield this.y; + } + + get x() { + return this.buf[this.i]; + } + + set x(x: number) { + this.buf[this.i] = x; + } + + get y() { + return this.buf[this.i + this.s]; + } + + set y(y: number) { + this.buf[this.i + this.s] = y; + } + + copy() { + return new Vec2(get2(this.buf, this.i, this.s)); + } + + eqDelta(v: Readonly, eps = EPS) { + return eqDelta2(this.buf, v.buf, eps, this.i, v.i, this.s, v.s); + } + + set(v: Readonly) { + set2(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + setN(n: number) { + setN2(this.buf, n, this.i, this.s); + return this; + } + + setS(x: number, y: number) { + setS2(this.buf, x, y, this.i, this.s); + return this; + } + + swizzle(v: IVec, x: number, y: number) { + swizzle2(this.buf, v.buf, x, y, this.i, v.i, this.s, v.s); + return this; + } + + add(v: Readonly) { + add2(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + sub(v: Readonly) { + sub2(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + mul(v: Readonly) { + mul2(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + div(v: Readonly) { + div2(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + addN(n: number) { + addN2(this.buf, n, this.i, this.s); + return this; + } + + subN(n: number) { + subN2(this.buf, n, this.i, this.s); + return this; + } + + mulN(n: number) { + mulN2(this.buf, n, this.i, this.s); + return this; + } + + divN(n: number) { + divN2(this.buf, n, this.i, this.s); + return this; + } + + neg() { + mulN2(this.buf, -1, this.i, this.s); + return this; + } + + abs() { + abs2(this.buf, this.i, this.s); + return this; + } + + sign() { + sign2(this.buf, this.i, this.s); + return this; + } + + floor() { + floor2(this.buf, this.i, this.s); + return this; + } + + ceil() { + ceil2(this.buf, this.i, this.s); + return this; + } + + sqrt() { + sqrt2(this.buf, this.i, this.s); + return this; + } + + pow(v: Readonly) { + pow2(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + powN(n: number) { + powN2(this.buf, n, this.i, this.s); + return this; + } + + sin() { + sin2(this.buf, this.i, this.s); + return this; + } + + cos() { + cos2(this.buf, this.i, this.s); + return this; + } + + madd(b: Readonly, c: Readonly) { + madd2(this.buf, b.buf, c.buf, this.i, b.i, c.i, this.s, b.s, c.s); + return this; + } + + maddN(b: Readonly, n: number) { + maddN2(this.buf, b.buf, n, this.i, b.i, this.s, b.s); + return this; + } + + mix(b: Readonly, c: Readonly) { + mix2(this.buf, b.buf, c.buf, this.i, b.i, c.i, this.s, b.s, c.s); + return this; + } + + mixN(b: Readonly, n: number) { + mixN2(this.buf, b.buf, n, this.i, b.i, this.s, b.s); + return this; + } + + min(v: Readonly) { + min2(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + max(v: Readonly) { + max2(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + clamp(min: Readonly, max: Readonly) { + clamp2(this.buf, min.buf, max.buf, this.i, min.i, max.i, this.s, min.s, max.s); + return this; + } + + minorAxis() { + return minorAxis2(this.buf, this.i, this.s); + } + + majorAxis() { + return majorAxis2(this.buf, this.i, this.s); + } + + step(e: Readonly) { + step2(this.buf, e.buf, this.i, e.i, this.s, e.s); + return this; + } + + smoothStep(e1: Readonly, e2: Readonly) { + smoothStep2(this.buf, e1.buf, e2.buf, this.i, e1.i, e2.i, this.s, e1.s, e2.s); + return this; + } + + dot(v: Readonly) { + return dot2(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + cross(v: Readonly) { + return cross2(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + mag() { + return mag2(this.buf, this.i, this.s); + } + + magSq() { + return magSq2(this.buf, this.i, this.s); + } + + dist(v: Readonly) { + return dist2(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + distSq(v: Readonly) { + return distSq2(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + distManhattan(v: Readonly) { + return distManhattan2(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + distChebyshev(v: Readonly) { + return distChebyshev2(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + normalize(len = 1) { + normalize2(this.buf, len, this.i, this.s); + return this; + } + + limit(len: number) { + limit2(this.buf, len, this.i, this.s); + return this; + } + + reflect(n: Readonly) { + reflect2(this.buf, n.buf, this.i, n.i, this.s, n.s); + return this; + } + + rotate(theta: number) { + rotate2(this.buf, theta, this.i, this.s); + return this; + } + + heading() { + return heading2(this.buf, this.i, this.s); + } + + toPolar() { + toPolar2(this.buf, this.i, this.s); + return this; + } + + toCartesian(o: Readonly = Vec2.ZERO) { + toCartesian2(this.buf, o.buf, this.i, o.i, this.s, o.s); + return this; + } + + toString() { + return `[${this.buf[this.i]}, ${this.buf[this.i + this.s]}]`; + } +} diff --git a/packages/vectors/src/vec3.ts b/packages/vectors/src/vec3.ts new file mode 100644 index 0000000000..5de10a42d2 --- /dev/null +++ b/packages/vectors/src/vec3.ts @@ -0,0 +1,643 @@ +import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; +import { IVec, ReadonlyVec, Vec } from "./api"; +import { + atan2Abs, + EPS, + eqDelta1, + max3id, + min3id, + sign1, + smoothStep1, + step1 +} from "./math"; +import { heading2, rotate2 } from "./vec2"; + +export const ZERO3 = Object.freeze([0, 0, 0]); +export const ONE3 = Object.freeze([1, 1, 1]); + +export const op3 = (fn: (x: number) => number, a: Vec, ia = 0, sa = 1) => ( + a[ia] = fn(a[ia]), + a[ia + sa] = fn(a[ia + sa]), + a[ia + 2 * sa] = fn(a[ia + 2 * sa]), + a +); + +export const op32 = (fn: (a: number, b: number) => number, a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] = fn(a[ia], b[ib]), + a[ia + sa] = fn(a[ia + sa], b[ib + sb]), + a[ia + 2 * sa] = fn(a[ia + 2 * sa], b[ib + 2 * sb]), + a +); + +export const get3 = (a: ReadonlyVec, ia = 0, sa = 1) => + set3(new ((a.constructor))(3), a, 0, ia, 1, sa); + +export const set3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] = b[ib], + a[ia + sa] = b[ib + sb], + a[ia + 2 * sa] = b[ib + 2 * sb], + a +); + +export const setN3 = (a: Vec, n: number, ia = 0, sa = 1) => ( + a[ia] = n, + a[ia + sa] = n, + a[ia + 2 * sa] = n, + a +); + +export const setS3 = (a: Vec, x: number, y: number, z: number, ia = 0, sa = 1) => + (a[ia] = x, a[ia + sa] = y, a[ia + 2 * sa] = z, a); + +export const swizzle3 = (a: Vec, b: Vec, x: number, y: number, z: number, ia = 0, ib = 0, sa = 1, sb = 1) => { + const xx = b[ib + x * sb]; + const yy = b[ib + y * sb]; + const zz = b[ib + z * sb]; + a[ia] = xx; + a[ia + sa] = yy; + a[ia + 2 * sa] = zz; + return a; +}; + +export const eqDelta3 = (a: ReadonlyVec, b: ReadonlyVec, eps = EPS, ia = 0, ib = 0, sa = 1, sb = 1) => + eqDelta1(a[ia], b[ib], eps) && + eqDelta1(a[ia + sa], b[ib + sb], eps) && + eqDelta1(a[ia + 2 * sa], b[ib + 2 * sb], eps); + +export const add3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] += b[ib], + a[ia + sa] += b[ib + sb], + a[ia + 2 * sa] += b[ib + 2 * sb], + a +); + +export const mul3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] *= b[ib], + a[ia + sa] *= b[ib + sb], + a[ia + 2 * sa] *= b[ib + 2 * sb], + a +); + +export const sub3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] -= b[ib], + a[ia + sa] -= b[ib + sb], + a[ia + 2 * sa] -= b[ib + 2 * sb], + a +); + +export const div3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] /= b[ib], + a[ia + sa] /= b[ib + sb], + a[ia + 2 * sa] /= b[ib + 2 * sb], + a +); + +export const addN3 = (a: Vec, n: number, ia = 0, sa = 1) => + (a[ia] += n, a[ia + sa] += n, a[ia + 2 * sa] += n, a); + +export const subN3 = (a: Vec, n: number, ia = 0, sa = 1) => + (a[ia] -= n, a[ia + sa] -= n, a[ia + 2 * sa] -= n, a); + +export const mulN3 = (a: Vec, n: number, ia = 0, sa = 1) => + (a[ia] *= n, a[ia + sa] *= n, a[ia + 2 * sa] *= n, a); + +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 neg3 = (a: Vec, ia = 0, sa = 1) => + mulN3(a, -1, ia, sa); + +export const abs3 = (a: Vec, ia = 0, sa = 1) => + op3(Math.abs, a, ia, sa); + +export const sign3 = (a: Vec, eps = EPS, ia = 0, sa = 1) => + op3((x) => sign1(x, eps), a, ia, sa); + +export const floor3 = (a: Vec, ia = 0, sa = 1) => + op3(Math.floor, a, ia, sa); + +export const ceil3 = (a: Vec, ia = 0, sa = 1) => + op3(Math.ceil, a, ia, sa); + +export const sin3 = (a: Vec, ia = 0, sa = 1) => + op3(Math.sin, a, ia, sa); + +export const cos3 = (a: Vec, ia = 0, sa = 1) => + op3(Math.cos, a, ia, sa); + +export const sqrt3 = (a: Vec, ia = 0, sa = 1) => + op3(Math.sqrt, a, ia, sa); + +export const pow3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + op32(Math.pow, a, b, ia, ib, sa, sb); + +export const powN3 = (a: Vec, n: number, ia = 0, sa = 1) => + op3((x) => Math.pow(x, n), a, ia, sa); + +export const madd3 = (a: Vec, b: ReadonlyVec, c: ReadonlyVec, ia = 0, ib = 0, ic = 0, sa = 1, sb = 1, sc = 1) => ( + a[ia] += b[ib] * c[ic], + a[ia + sa] += b[ib + sb] * c[ic + sc], + a[ia + 2 * sa] += b[ib + 2 * sb] * c[ic + 2 * sc], + a +); + +export const maddN3 = (a: Vec, b: ReadonlyVec, c: number, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] += b[ib] * c, + a[ia + sa] += b[ib + sb] * c, + a[ia + 2 * sa] += b[ib + 2 * sb] * c, + a +); + +export const dot3 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + a[ia] * b[ib] + + a[ia + sa] * b[ib + sb] + + a[ia + 2 * sa] * b[ib + 2 * sb]; + +export const cross3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => { + const iay = ia + sa; + const iaz = ia + 2 * sa; + const iby = ib + sb; + const ibz = ib + 2 * sb; + const x = a[iay] * b[ibz] - a[iaz] * b[iby]; + const y = a[iaz] * b[ib] - a[ia] * b[ibz]; + a[iaz] = a[ia] * b[iby] - a[iay] * b[ib]; + a[iay] = y; + a[ia] = x; + return a; +}; + +export const orthoNormal3 = (a: Vec, b: Vec, c: Vec, ia = 0, ib = 0, ic = 0, sa = 1, sb = 1, sc = 1) => + cross3( + sub3(get3(c, ic, sc), a, 0, ia, 1, sa), + sub3(get3(b, ib, sb), a, 0, ia, 1, sa) + ); + +export const mix3 = (a: Vec, b: ReadonlyVec, t: ReadonlyVec, ia = 0, ib = 0, it = 0, sa = 1, sb = 1, st = 1) => ( + a[ia] += (b[ib] - a[ia]) * t[it], + a[ia + sa] += (b[ib + sb] - a[ia + sa]) * t[it + st], + a[ia + 2 * sa] += (b[ib + 2 * sb] - a[ia + 2 * sa]) * t[it + 2 * st], + a +); + +export const mixN3 = (a: Vec, b: ReadonlyVec, t: number, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] += (b[ib] - a[ia]) * t, + a[ia + sa] += (b[ib + sb] - a[ia + sa]) * t, + a[ia + 2 * sa] += (b[ib + 2 * sb] - a[ia + 2 * sa]) * t, + a +); + +export const min3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + op32(Math.min, a, b, ia, ib, sa, sb); + +export const max3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + op32(Math.max, a, b, ia, ib, sa, sb); + +export const clamp3 = (a: Vec, min: ReadonlyVec, max: ReadonlyVec, ia = 0, imin = 0, imax = 0, sa = 1, smin = 1, smax = 1) => + max3(min3(a, max, ia, imax, sa, smax), min, ia, imin, sa, smin); + +export const step3 = (a: Vec, e: ReadonlyVec, ia = 0, ie = 0, sa = 1, se = 1) => ( + a[ia] = step1(e[ie], a[ia]), + a[ia + sa] = step1(e[ie + se], a[ia + sa]), + a[ia + 2 * sa] = step1(e[ie + 2 * se], a[ia + 2 * sa]), + a +); + +export const smoothStep3 = (a: Vec, e1: ReadonlyVec, e2: ReadonlyVec, ia = 0, ie1 = 0, ie2 = 0, sa = 1, se1 = 1, se2 = 1) => ( + a[ia] = smoothStep1(e1[ie1], e2[ie2], a[ia]), + a[ia + sa] = smoothStep1(e1[ie1 + se1], e2[ie2 + se2], a[ia + sa]), + a[ia + 2 * sa] = smoothStep1(e1[ie1 + 2 * se1], e2[ie2 + 2 * se2], a[ia + 2 * sa]), + a +); + +export const magSq3 = (a: ReadonlyVec, ia = 0, sa = 1) => { + const x = a[ia]; + const y = a[ia + sa]; + const z = a[ia + 2 * sa]; + return x * x + y * y + z * z; +}; + +export const mag3 = (a: ReadonlyVec, ia = 0, sa = 1) => + Math.sqrt(magSq3(a, ia, sa)); + +export const distSq3 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => { + const x = a[ia] - b[ib]; + const y = a[ia + sa] - b[ib + sb]; + const z = a[ia + 2 * sa] - b[ib + 2 * sb]; + return x * x + y * y + z * z; +}; + +export const dist3 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + Math.sqrt(distSq3(a, b, ia, ib, sa, sb)); + +export const distManhattan3 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + Math.abs(a[ia] - b[ib]) + + Math.abs(a[ia + sa] - b[ib + sb]) + + Math.abs(a[ia + 2 * sa] - b[ib + 2 * sb]); + +export const distChebyshev3 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + Math.max( + Math.abs(a[ia] - b[ib]), + Math.abs(a[ia + sa] - b[ib + sb]), + Math.abs(a[ia + 2 * sa] - b[ib + 2 * sb]) + ); + +export const normalize3 = (a: Vec, n = 1, ia = 0, sa = 1) => { + const m = mag3(a, ia, sa); + m >= EPS && mulN3(a, n / m, ia, sa); + return a; +}; + +export const limit3 = (a: Vec, n: number, ia = 0, sa = 1) => { + const m = mag3(a, ia, sa); + m >= n && mulN3(a, n / m, ia, sa); + return a; +}; + +export const reflect3 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + maddN3(a, b, -2 * dot3(a, b, ia, ib, sa, sb), ia, ib, sa, sb); + +export const rotateX3 = (a: Vec, theta: number, ia = 0, sa = 1) => + rotate2(a, theta, ia + sa, sa); + +export const rotateY3 = (a: Vec, theta: number, ia = 0, sa = 1) => + rotate2(a, theta, ia + 2 * sa, -2 * sa); + +export const rotateZ3 = rotate2; + +export const headingXY3 = heading2; + +export const headingXZ3 = (a: ReadonlyVec, ia = 0, sa = 1) => + atan2Abs(a[ia + 2 * sa], a[ia]); + +export const headingYZ3 = (a: ReadonlyVec, ia = 0, sa = 1) => + atan2Abs(a[ia + 2 * sa], a[ia + sa]); + +export const toSpherical3 = (a: Vec, ia = 0, sa = 1) => { + const x = a[ia]; + const y = a[ia + sa]; + const z = a[ia + 2 * sa]; + const r = Math.sqrt(x * x + y * y + z * z); + return setS3(a, r, Math.asin(z / r), atan2Abs(y, x), ia, sa); +}; + +export const toCartesian3 = (a: Vec, b: ReadonlyVec = ZERO3, ia = 0, ib = 0, sa = 1, sb = 1) => { + const r = a[ia]; + const theta = a[ia + sa]; + const phi = a[ia + 2 * sa]; + const ct = Math.cos(theta); + return setS3(a, + r * ct * Math.cos(phi) + b[ib], + r * ct * Math.sin(phi) + b[ib + sb], + r * Math.sin(theta) + b[ib + 2 * sb], + ia, sa + ); +}; + +export const minorAxis3 = (a: Vec, ia = 0, sa = 1) => + min3id(Math.abs(a[ia]), Math.abs(a[ia + sa]), Math.abs(a[ia + 2 * sa])); + +export const majorAxis3 = (a: Vec, ia = 0, sa = 1) => + max3id(Math.abs(a[ia]), Math.abs(a[ia + sa]), Math.abs(a[ia + 2 * sa])); + +export const vec3 = (x = 0, y = 0, z = 0) => + new Vec3([x, y, z]); + +export class Vec3 implements + ICopy, + IEqualsDelta, + IVec { + + /** + * Returns array of memory mapped `Vec3` instances using given + * backing array and stride settings: The `cstride` is the step size + * between individual XYZ vector components. `estride` is the step + * size between successive vectors. This arrangement allows for + * different storage approaches, incl. SOA, AOS, striped / + * interleaved etc. + * + * @param buf backing array + * @param n num vectors + * @param start start index + * @param cstride component stride + * @param estride element stride + */ + static mapBuffer(buf: Vec, n: number, start = 0, cstride = 1, estride = 3) { + const res: Vec3[] = []; + while (--n >= 0) { + res.push(new Vec3(buf, start, cstride)); + start += estride; + } + return res; + } + + static orthoNormal3(a: Readonly, b: Readonly, c: Readonly) { + return new Vec3(orthoNormal3(a.buf, b.buf, c.buf, a.i, b.i, c.i, a.s, b.s, c.s)); + } + + static ZERO = Object.freeze(new Vec3(ZERO3)); + static ONE = Object.freeze(new Vec3(ONE3)); + + buf: Vec; + i: number; + s: number; + + constructor(buf: Vec, index = 0, stride = 1) { + this.buf = buf; + this.i = index; + this.s = stride; + } + + *[Symbol.iterator]() { + yield this.x; + yield this.y; + yield this.z; + } + + get x() { + return this.buf[this.i]; + } + + set x(x: number) { + this.buf[this.i] = x; + } + + get y() { + return this.buf[this.i + this.s]; + } + + set y(y: number) { + this.buf[this.i + this.s] = y; + } + + get z() { + return this.buf[this.i + 2 * this.s]; + } + + set z(z: number) { + this.buf[this.i + 2 * this.s] = z; + } + + copy() { + return new Vec3(get3(this.buf, this.i, this.s)); + } + + eqDelta(v: Readonly, eps = EPS) { + return eqDelta3(this.buf, v.buf, eps, this.i, v.i, this.s, v.s); + } + + set(v: Readonly) { + set3(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + setN(n: number) { + setN3(this.buf, n, this.i, this.s); + return this; + } + + setS(x: number, y: number, z: number) { + setS3(this.buf, x, y, z, this.i, this.s); + return this; + } + + swizzle(v: IVec, x: number, y: number, z: number) { + swizzle3(this.buf, v.buf, x, y, z, this.i, v.i, this.s, v.s); + return this; + } + + add(v: Readonly) { + add3(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + sub(v: Readonly) { + sub3(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + mul(v: Readonly) { + mul3(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + div(v: Readonly) { + div3(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + addN(n: number) { + addN3(this.buf, n, this.i, this.s); + return this; + } + + subN(n: number) { + subN3(this.buf, n, this.i, this.s); + return this; + } + + mulN(n: number) { + mulN3(this.buf, n, this.i, this.s); + return this; + } + + divN(n: number) { + divN3(this.buf, n, this.i, this.s); + return this; + } + + neg() { + mulN3(this.buf, -1, this.i, this.s); + return this; + } + + abs() { + abs3(this.buf, this.i, this.s); + return this; + } + + sign() { + sign3(this.buf, this.i, this.s); + return this; + } + + floor() { + floor3(this.buf, this.i, this.s); + return this; + } + + ceil() { + ceil3(this.buf, this.i, this.s); + return this; + } + + sqrt() { + sqrt3(this.buf, this.i, this.s); + return this; + } + + pow(v: Readonly) { + pow3(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + powN(n: number) { + powN3(this.buf, n, this.i, this.s); + return this; + } + + sin() { + sin3(this.buf, this.i, this.s); + return this; + } + + cos() { + cos3(this.buf, this.i, this.s); + return this; + } + + madd(b: Readonly, c: Readonly) { + madd3(this.buf, b.buf, c.buf, this.i, b.i, c.i, this.s, b.s, c.s); + return this; + } + + maddN(b: Readonly, n: number) { + maddN3(this.buf, b.buf, n, this.i, b.i, this.s, b.s); + return this; + } + + mix(b: Readonly, c: Readonly) { + mix3(this.buf, b.buf, c.buf, this.i, b.i, c.i, this.s, b.s, c.s); + return this; + } + + mixN(b: Readonly, n: number) { + mixN3(this.buf, b.buf, n, this.i, b.i, this.s, b.s); + return this; + } + + min(v: Readonly) { + min3(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + max(v: Readonly) { + max3(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + clamp(min: Readonly, max: Readonly) { + clamp3(this.buf, min.buf, max.buf, this.i, min.i, max.i, this.s, min.s, max.s); + return this; + } + + minorAxis() { + return minorAxis3(this.buf, this.i, this.s); + } + + majorAxis() { + return majorAxis3(this.buf, this.i, this.s); + } + + step(e: Readonly) { + step3(this.buf, e.buf, this.i, e.i, this.s, e.s); + return this; + } + + smoothStep(e1: Readonly, e2: Readonly) { + smoothStep3(this.buf, e1.buf, e2.buf, this.i, e1.i, e2.i, this.s, e1.s, e2.s); + return this; + } + + dot(v: Readonly) { + return dot3(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + cross(v: Readonly) { + cross3(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + orthoNormal(v: Readonly) { + return this.cross(v).normalize(); + } + + mag() { + return mag3(this.buf, this.i, this.s); + } + + magSq() { + return magSq3(this.buf, this.i, this.s); + } + + dist(v: Readonly) { + return dist3(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + distSq(v: Readonly) { + return distSq3(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + distManhattan(v: Readonly) { + return distManhattan3(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + distChebyshev(v: Readonly) { + return distChebyshev3(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + normalize(len = 1) { + normalize3(this.buf, len, this.i, this.s); + return this; + } + + limit(len: number) { + limit3(this.buf, len, this.i, this.s); + return this; + } + + reflect(n: Readonly) { + reflect3(this.buf, n.buf, this.i, n.i, this.s, n.s); + return this; + } + + rotateX(theta: number) { + rotateX3(this.buf, theta, this.i, this.s); + return this; + } + + rotateY(theta: number) { + rotateY3(this.buf, theta, this.i, this.s); + return this; + } + + rotateZ(theta: number) { + rotateZ3(this.buf, theta, this.i, this.s); + return this; + } + + headingXY() { + return headingXY3(this.buf, this.i, this.s); + } + + headingXZ() { + return headingXZ3(this.buf, this.i, this.s); + } + + headingYZ() { + return headingYZ3(this.buf, this.i, this.s); + } + + toSpherical() { + toSpherical3(this.buf, this.i, this.s); + return this; + } + + toCartesian(o: Readonly = Vec3.ZERO) { + toCartesian3(this.buf, o.buf, this.i, o.i, this.s, o.s); + return this; + } + + toString() { + return `[${this.buf[this.i]}, ${this.buf[this.i + this.s]}, ${this.buf[this.i + 2 * this.s]}]`; + } +} diff --git a/packages/vectors/src/vec4.ts b/packages/vectors/src/vec4.ts new file mode 100644 index 0000000000..ec46993209 --- /dev/null +++ b/packages/vectors/src/vec4.ts @@ -0,0 +1,570 @@ +import { ICopy, IEqualsDelta } from "@thi.ng/api/api"; +import { IVec, ReadonlyVec, Vec } from "./api"; +import { + EPS, + eqDelta1, + max4id, + min4id, + smoothStep1, + step1 +} from "./math"; + +export const ZERO4 = Object.freeze([0, 0, 0, 0]); +export const ONE4 = Object.freeze([1, 1, 1, 1]); + +export const op4 = (fn: (x: number) => number, a: Vec, ia = 0, sa = 1) => ( + a[ia] = fn(a[ia]), + a[ia + sa] = fn(a[ia + sa]), + a[ia + 2 * sa] = fn(a[ia + 2 * sa]), + a[ia + 3 * sa] = fn(a[ia + 3 * sa]), + a +); + +export const op42 = (fn: (a: number, b: number) => number, a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] = fn(a[ia], b[ib]), + a[ia + sa] = fn(a[ia + sa], b[ib + sb]), + a[ia + 2 * sa] = fn(a[ia + 2 * sa], b[ib + 2 * sb]), + a[ia + 3 * sa] = fn(a[ia + 3 * sa], b[ib + 3 * sb]), + a +); + +export const get4 = (a: ReadonlyVec, ia = 0, sa = 1) => + set4(new ((a.constructor))(4), a, 0, ia, 1, sa); + +export const set4 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] = b[ib], + a[ia + sa] = b[ib + sb], + a[ia + 2 * sa] = b[ib + 2 * sb], + a[ia + 3 * sa] = b[ib + 3 * sb], + a +); + +export const setN4 = (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 setS4 = (a: Vec, x: number, y: number, z: number, w: number, ia = 0, sa = 1) => ( + a[ia] = x, + a[ia + sa] = y, + a[ia + 2 * sa] = z, + a[ia + 3 * sa] = w, + a +); + +export const swizzle4 = (a: Vec, b: Vec, x: number, y: number, z: number, w: number, ia = 0, ib = 0, sa = 1, sb = 1) => { + const xx = b[ib + x * sb]; + const yy = b[ib + y * sb]; + const zz = b[ib + z * sb]; + const ww = b[ib + w * sb]; + a[ia] = xx; + a[ia + sa] = yy; + a[ia + 2 * sa] = zz; + a[ia + 3 * sa] = ww; + return a; +}; + +export const eqDelta4 = (a: ReadonlyVec, b: ReadonlyVec, eps = EPS, ia = 0, ib = 0, sa = 1, sb = 1) => + eqDelta1(a[ia], b[ib], eps) && + eqDelta1(a[ia + sa], b[ib + sb], eps) && + eqDelta1(a[ia + 2 * sa], b[ib + 2 * sb], eps) && + eqDelta1(a[ia + 3 * sa], b[ib + 3 * sb], eps); + +export const add4 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] += b[ib], + a[ia + sa] += b[ib + sb], + a[ia + 2 * sa] += b[ib + 2 * sb], + a[ia + 3 * sa] += b[ib + 3 * sb], + a +); + +export const mul4 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] *= b[ib], + a[ia + sa] *= b[ib + sb], + a[ia + 2 * sa] *= b[ib + 2 * sb], + a[ia + 3 * sa] *= b[ib + 3 * sb], + a +); + +export const sub4 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] -= b[ib], + a[ia + sa] -= b[ib + sb], + a[ia + 2 * sa] -= b[ib + 2 * sb], + a[ia + 3 * sa] -= b[ib + 3 * sb], + a +); + +export const div4 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] /= b[ib], + a[ia + sa] /= b[ib + sb], + a[ia + 2 * sa] /= b[ib + 2 * sb], + a[ia + 3 * sa] /= b[ib + 3 * sb], + a +); + +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); + +export const subN4 = (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 mulN4 = (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 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 neg4 = (a: Vec, ia = 0, sa = 1) => + mulN4(a, -1, ia, sa); + +export const abs4 = (a: Vec, ia = 0, sa = 1) => + op4(Math.abs, a, ia, sa); + +export const sign4 = (a: Vec, ia = 0, sa = 1) => + op4(Math.sign, a, ia, sa); + +export const floor4 = (a: Vec, ia = 0, sa = 1) => + op4(Math.floor, a, ia, sa); + +export const ceil4 = (a: Vec, ia = 0, sa = 1) => + op4(Math.ceil, a, ia, sa); + +export const sin4 = (a: Vec, ia = 0, sa = 1) => + op4(Math.sin, a, ia, sa); + +export const cos4 = (a: Vec, ia = 0, sa = 1) => + op4(Math.cos, a, ia, sa); + +export const sqrt4 = (a: Vec, ia = 0, sa = 1) => + op4(Math.sqrt, a, ia, sa); + +export const pow4 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + op42(Math.pow, a, b, ia, ib, sa, sb); + +export const powN4 = (a: Vec, n: number, ia = 0, sa = 1) => + op4((x) => Math.pow(x, n), a, ia, sa); + +export const madd4 = (a: Vec, b: ReadonlyVec, c: ReadonlyVec, ia = 0, ib = 0, ic = 0, sa = 1, sb = 1, sc = 1) => ( + a[ia] += b[ib] * c[ic], + a[ia + sa] += b[ib + sb] * c[ic + sc], + a[ia + 2 * sa] += b[ib + 2 * sb] * c[ic + 2 * sc], + a[ia + 3 * sa] += b[ib + 3 * sb] * c[ic + 3 * sc], + a +); + +export const maddN4 = (a: Vec, b: ReadonlyVec, c: number, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] += b[ib] * c, + a[ia + sa] += b[ib + sb] * c, + a[ia + 2 * sa] += b[ib + 2 * sb] * c, + a[ia + 3 * sa] += b[ib + 3 * sb] * c, + a +); + +export const dot4 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + a[ia] * b[ib] + + a[ia + sa] * b[ib + sb] + + a[ia + 2 * sa] * b[ib + 2 * sb] + + a[ia + 3 * sa] * b[ib + 3 * sb]; + +export const mix4 = (a: Vec, b: ReadonlyVec, t: ReadonlyVec, ia = 0, ib = 0, it = 0, sa = 1, sb = 1, st = 1) => ( + a[ia] += (b[ib] - a[ia]) * t[it], + a[ia + sa] += (b[ib + sb] - a[ia + sa]) * t[it + st], + a[ia + 2 * sa] += (b[ib + 2 * sb] - a[ia + 2 * sa]) * t[it + 2 * st], + a[ia + 3 * sa] += (b[ib + 3 * sb] - a[ia + 3 * sa]) * t[it + 3 * st], + a +); + +export const mixN4 = (a: Vec, b: ReadonlyVec, t: number, ia = 0, ib = 0, sa = 1, sb = 1) => ( + a[ia] += (b[ib] - a[ia]) * t, + a[ia + sa] += (b[ib + sb] - a[ia + sa]) * t, + a[ia + 2 * sa] += (b[ib + 2 * sb] - a[ia + 2 * sa]) * t, + a[ia + 3 * sa] += (b[ib + 3 * sb] - a[ia + 3 * sa]) * t, + a +); + +export const min4 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + op42(Math.min, a, b, ia, ib, sa, sb); + +export const max4 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + op42(Math.max, a, b, ia, ib, sa, sb); + +export const clamp4 = (a: Vec, min: ReadonlyVec, max: ReadonlyVec, ia = 0, imin = 0, imax = 0, sa = 1, smin = 1, smax = 1) => + max4(min4(a, max, ia, imax, sa, smax), min, ia, imin, sa, smin); + +export const step4 = (a: Vec, e: ReadonlyVec, ia = 0, ie = 0, sa = 1, se = 1) => ( + a[ia] = step1(e[ie], a[ia]), + a[ia + sa] = step1(e[ie + se], a[ia + sa]), + a[ia + 2 * sa] = step1(e[ie + 2 * se], a[ia + 2 * sa]), + a[ia + 3 * sa] = step1(e[ie + 3 * se], a[ia + 3 * sa]), + a +); + +export const smoothStep4 = (a: Vec, e1: ReadonlyVec, e2: ReadonlyVec, ia = 0, ie1 = 0, ie2 = 0, sa = 1, se1 = 1, se2 = 1) => ( + a[ia] = smoothStep1(e1[ie1], e2[ie2], a[ia]), + a[ia + sa] = smoothStep1(e1[ie1 + se1], e2[ie2 + se2], a[ia + sa]), + a[ia + 2 * sa] = smoothStep1(e1[ie1 + 2 * se1], e2[ie2 + 2 * se2], a[ia + 2 * sa]), + a[ia + 3 * sa] = smoothStep1(e1[ie1 + 3 * se1], e2[ie2 + 2 * se2], a[ia + 3 * sa]), + a +); + +export const magSq4 = (a: ReadonlyVec, ia = 0, sa = 1) => { + const x = a[ia]; + const y = a[ia + sa]; + const z = a[ia + 2 * sa]; + const w = a[ia + 3 * sa]; + return x * x + y * y + z * z + w * w; +}; + +export const mag4 = (a: ReadonlyVec, ia = 0, sa = 1) => + Math.sqrt(magSq4(a, ia, sa)); + +export const distSq4 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => { + const x = a[ia] - b[ib]; + const y = a[ia + sa] - b[ib + sb]; + const z = a[ia + 2 * sa] - b[ib + 2 * sb]; + const w = a[ia + 3 * sa] - b[ib + 3 * sb]; + return x * x + y * y + z * z + w * w; +}; + +export const dist4 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + Math.sqrt(distSq4(a, b, ia, ib, sa, sb)); + +export const distManhattan4 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + Math.abs(a[ia] - b[ib]) + + Math.abs(a[ia + sa] - b[ib + sb]) + + Math.abs(a[ia + 2 * sa] - b[ib + 2 * sb]) + + Math.abs(a[ia + 3 * sa] - b[ib + 3 * sb]); + +export const distChebyshev4 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + Math.max( + Math.abs(a[ia] - b[ib]), + Math.abs(a[ia + sa] - b[ib + sb]), + Math.abs(a[ia + 2 * sa] - b[ib + 2 * sb]), + Math.abs(a[ia + 3 * sa] - b[ib + 3 * sb]) + ); + +export const normalize4 = (a: Vec, n = 1, ia = 0, sa = 1) => { + const m = mag4(a, ia, sa); + m >= EPS && mulN4(a, n / m, ia, sa); + return a; +}; + +export const limit4 = (a: Vec, n: number, ia = 0, sa = 1) => { + const m = mag4(a, ia, sa); + m >= n && mulN4(a, n / m, ia, sa); + return a; +}; + +export const reflect4 = (a: Vec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => + maddN4(a, b, -2 * dot4(a, b, ia, ib, sa, sb), ia, ib, sa, sb); + +export const minorAxis4 = (a: Vec, ia = 0, sa = 1) => + min4id(Math.abs(a[ia]), Math.abs(a[ia + sa]), Math.abs(a[ia + 2 * sa]), Math.abs(a[ia + 3 * sa])); + +export const majorAxis4 = (a: Vec, ia = 0, sa = 1) => + max4id(Math.abs(a[ia]), Math.abs(a[ia + sa]), Math.abs(a[ia + 2 * sa]), Math.abs(a[ia + 3 * sa])); + +export const vec4 = (x = 0, y = 0, z = 0, w = 0) => + new Vec4([x, y, z, w]); + +export class Vec4 implements + ICopy, + IEqualsDelta, + IVec { + + /** + * Returns array of memory mapped `Vec4` instances using given + * backing array and stride settings: The `cstride` is the step size + * between individual XYZ vector components. `estride` is the step + * size between successive vectors. This arrangement allows for + * different storage approaches, incl. SOA, AOS, striped / + * interleaved etc. + * + * @param buf backing array + * @param n num vectors + * @param start start index + * @param cstride component stride + * @param estride element stride + */ + static mapBuffer(buf: Vec, n: number, start = 0, cstride = 1, estride = 4) { + const res: Vec4[] = []; + while (--n >= 0) { + res.push(new Vec4(buf, start, cstride)); + start += estride; + } + return res; + } + + static ZERO = Object.freeze(new Vec4(ZERO4)); + static ONE = Object.freeze(new Vec4(ONE4)); + + buf: Vec; + i: number; + s: number; + + constructor(buf: Vec, index = 0, stride = 1) { + this.buf = buf; + this.i = index; + this.s = stride; + } + + *[Symbol.iterator]() { + yield this.x; + yield this.y; + yield this.z; + yield this.w; + } + + get x() { + return this.buf[this.i]; + } + + set x(x: number) { + this.buf[this.i] = x; + } + + get y() { + return this.buf[this.i + this.s]; + } + + set y(y: number) { + this.buf[this.i + this.s] = y; + } + + get z() { + return this.buf[this.i + 2 * this.s]; + } + + set z(z: number) { + this.buf[this.i + 2 * this.s] = z; + } + + get w() { + return this.buf[this.i + 3 * this.s]; + } + + set w(w: number) { + this.buf[this.i + 3 * this.s] = w; + } + + copy() { + return new Vec4(get4(this.buf, this.i, this.s)); + } + + eqDelta(v: Readonly, eps = EPS) { + return eqDelta4(this.buf, v.buf, eps, this.i, v.i, this.s, v.s); + } + + set(v: Readonly) { + set4(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + setN(n: number) { + setN4(this.buf, n, this.i, this.s); + return this; + } + + setS(x: number, y: number, z: number, w: number) { + setS4(this.buf, x, y, z, w, this.i, this.s); + return this; + } + + swizzle(v: IVec, x: number, y: number, z: number, w: number) { + swizzle4(this.buf, v.buf, x, y, z, w, this.i, v.i, this.s, v.s); + return this; + } + + add(v: Readonly) { + add4(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + sub(v: Readonly) { + sub4(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + mul(v: Readonly) { + mul4(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + div(v: Readonly) { + div4(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + addN(n: number) { + addN4(this.buf, n, this.i, this.s); + return this; + } + + subN(n: number) { + subN4(this.buf, n, this.i, this.s); + return this; + } + + mulN(n: number) { + mulN4(this.buf, n, this.i, this.s); + return this; + } + + divN(n: number) { + divN4(this.buf, n, this.i, this.s); + return this; + } + + neg() { + mulN4(this.buf, -1, this.i, this.s); + return this; + } + + abs() { + abs4(this.buf, this.i, this.s); + return this; + } + + sign() { + sign4(this.buf, this.i, this.s); + return this; + } + + floor() { + floor4(this.buf, this.i, this.s); + return this; + } + + ceil() { + ceil4(this.buf, this.i, this.s); + return this; + } + + sqrt() { + sqrt4(this.buf, this.i, this.s); + return this; + } + + pow(v: Readonly) { + pow4(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + powN(n: number) { + powN4(this.buf, n, this.i, this.s); + return this; + } + + sin() { + sin4(this.buf, this.i, this.s); + return this; + } + + cos() { + cos4(this.buf, this.i, this.s); + return this; + } + + madd(b: Readonly, c: Readonly) { + madd4(this.buf, b.buf, c.buf, this.i, b.i, c.i, this.s, b.s, c.s); + return this; + } + + maddN(b: Readonly, n: number) { + maddN4(this.buf, b.buf, n, this.i, b.i, this.s, b.s); + return this; + } + + mix(b: Readonly, c: Readonly) { + mix4(this.buf, b.buf, c.buf, this.i, b.i, c.i, this.s, b.s, c.s); + return this; + } + + mixN(b: Readonly, n: number) { + mixN4(this.buf, b.buf, n, this.i, b.i, this.s, b.s); + return this; + } + + min(v: Readonly) { + min4(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + max(v: Readonly) { + max4(this.buf, v.buf, this.i, v.i, this.s, v.s); + return this; + } + + clamp(min: Readonly, max: Readonly) { + clamp4(this.buf, min.buf, max.buf, this.i, min.i, max.i, this.s, min.s, max.s); + return this; + } + + minorAxis() { + return minorAxis4(this.buf, this.i, this.s); + } + + majorAxis() { + return majorAxis4(this.buf, this.i, this.s); + } + + step(e: Readonly) { + step4(this.buf, e.buf, this.i, e.i, this.s, e.s); + return this; + } + + smoothStep(e1: Readonly, e2: Readonly) { + smoothStep4(this.buf, e1.buf, e2.buf, this.i, e1.i, e2.i, this.s, e1.s, e2.s); + return this; + } + + dot(v: Readonly) { + return dot4(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + mag() { + return mag4(this.buf, this.i, this.s); + } + + magSq() { + return magSq4(this.buf, this.i, this.s); + } + + dist(v: Readonly) { + return dist4(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + distSq(v: Readonly) { + return distSq4(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + distManhattan(v: Readonly) { + return distManhattan4(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + distChebyshev(v: Readonly) { + return distChebyshev4(this.buf, v.buf, this.i, v.i, this.s, v.s); + } + + normalize(len = 1) { + normalize4(this.buf, len, this.i, this.s); + return this; + } + + limit(len: number) { + limit4(this.buf, len, this.i, this.s); + return this; + } + + reflect(n: Readonly) { + reflect4(this.buf, n.buf, this.i, n.i, this.s, n.s); + return this; + } + + toString() { + return `[${this.buf[this.i]}, ${this.buf[this.i + this.s]}, ${this.buf[this.i + 2 * this.s]}, ${this.buf[this.i + 3 * this.s]}]`; + } +} diff --git a/packages/vectors/test/gvec.ts b/packages/vectors/test/gvec.ts new file mode 100644 index 0000000000..5e78a3007a --- /dev/null +++ b/packages/vectors/test/gvec.ts @@ -0,0 +1,64 @@ +import * as assert from "assert"; +import * as v from "../src/index"; + +describe("gvec", () => { + + const op2 = (fn, x, y, z, w) => { + assert.deepEqual( + fn([1, 2, 3, 4], [10, 20, 30, 40], 4), + [x, y, z, w] + ); + assert.deepEqual( + fn([0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0], [0, 10, 0, 20, 0, 30, 0, 40, 0], 4, 1, 1, 4, 2), + [0, x, 0, 0, 0, y, 0, 0, 0, z, 0, 0, 0, w, 0, 0] + ); + }; + + const opn = (fn, x, y, z, w) => { + assert.deepEqual( + fn([1, 2, 3, 4], 10, 4), + [x, y, z, w] + ); + assert.deepEqual( + fn([0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0], 10, 4, 1, 4), + [0, x, 0, 0, 0, y, 0, 0, 0, z, 0, 0, 0, w, 0, 0] + ); + }; + + it("add", () => op2(v.add, 11, 22, 33, 44)); + it("sub", () => op2(v.sub, -9, -18, -27, -36)); + it("mul", () => op2(v.mul, 10, 40, 90, 160)); + it("div", () => op2(v.div, 0.1, 0.1, 0.1, 0.1)); + + it("addn", () => opn(v.addN, 11, 12, 13, 14)); + it("subn", () => opn(v.subN, -9, -8, -7, -6)); + it("muln", () => opn(v.mulN, 10, 20, 30, 40)); + it("divn", () => opn(v.divN, 0.1, 0.2, 0.3, 0.4)); + + it("madd", () => { + assert.deepEqual( + v.madd([1, 2, 3, 4], [10, 20, 30, 40], [0.5, 0.25, 0.75, 0.125], 4), + [1 + 10 * 0.5, 2 + 20 * 0.25, 3 + 30 * 0.75, 4 + 40 * 0.125] + ); + assert.deepEqual( + v.madd([1, 2, 3, 4], [10, 0, 20, 0, 30, 0, 40], [0.5, 0, 0, 0.25, 0, 0, 0.75, 0, 0, 0.125], 4, 0, 0, 0, 1, 2, 3), + [1 + 10 * 0.5, 2 + 20 * 0.25, 3 + 30 * 0.75, 4 + 40 * 0.125] + ); + }); + + it("maddn", () => { + assert.deepEqual( + v.maddN([1, 2, 3, 4], [10, 20, 30, 40], 0.5, 4), + [1 + 10 * 0.5, 2 + 20 * 0.5, 3 + 30 * 0.5, 4 + 40 * 0.5] + ); + assert.deepEqual( + v.maddN([1, 2, 3, 4], [10, 0, 20, 0, 30, 0, 40], 0.5, 4, 0, 0, 1, 2), + [1 + 10 * 0.5, 2 + 20 * 0.5, 3 + 30 * 0.5, 4 + 40 * 0.5] + ); + }); + + it("eqdelta", () => { + assert(v.eqDelta([0, 1.001, 0, 1.999, 0, 3.0099, 0, 3.991], [1, 2, 3, 4], 4, 0.01, 1, 0, 2, 1)); + assert(!v.eqDelta([0, 1.001, 0, 1.999, 0, 3.02, 0, 4], [1, 2, 3, 4], 4, 0.01, 1, 0, 2, 1)); + }); +}); diff --git a/packages/vectors/test/swizzle.ts b/packages/vectors/test/swizzle.ts new file mode 100644 index 0000000000..dbf85f9df9 --- /dev/null +++ b/packages/vectors/test/swizzle.ts @@ -0,0 +1,88 @@ +import * as assert from "assert"; +import { Vec2, swizzle2 } from "../src/vec2"; +import { Vec3, swizzle3 } from "../src/vec3"; +import { Vec4, swizzle4 } from "../src/vec4"; + +describe("swizzle", () => { + + it("vec2", () => { + assert.deepEqual( + swizzle2([], [10, 20], 1, 0), + [20, 10] + ); + assert.deepEqual( + swizzle2([], [10, 20], 1, 1), + [20, 20] + ); + assert.deepEqual( + swizzle2([0, 0, 0, 0], [10, 20], 1, 0, 1, 0, 2, 1), + [0, 20, 0, 10] + ); + assert.deepEqual( + swizzle2([], [0, 10, 0, 0, 0, 20], 1, 0, 0, 1, 1, 4), + [20, 10] + ); + assert.deepEqual( + new Vec2([]).swizzle(new Vec2([10, 0, 20, 0], 0, 2), 1, 0).buf, + [20, 10] + ); + assert.deepEqual( + new Vec2([0, 0, 0, 0, 0], 1, 2).swizzle(new Vec2([10, 0, 0, 0, 20, 0, 0, 0], 0, 4), 1, 0).buf, + [0, 20, 0, 10, 0] + ); + }); + + it("vec3", () => { + assert.deepEqual( + swizzle3([], [10, 20, 30], 2, 1, 0), + [30, 20, 10] + ); + assert.deepEqual( + swizzle3([], [10, 20, 30], 1, 1, 1), + [20, 20, 20] + ); + assert.deepEqual( + swizzle3([0, 0, 0, 0, 0, 0], [10, 20, 30], 2, 1, 0, 1, 0, 2, 1), + [0, 30, 0, 20, 0, 10] + ); + assert.deepEqual( + swizzle3([], [0, 10, 0, 0, 0, 20, 0, 0, 0, 30], 2, 1, 0, 0, 1, 1, 4), + [30, 20, 10] + ); + assert.deepEqual( + new Vec3([]).swizzle(new Vec3([10, 0, 20, 0, 30, 0], 0, 2), 2, 1, 0).buf, + [30, 20, 10] + ); + assert.deepEqual( + new Vec3([0, 0, 0, 0, 0, 0, 0], 1, 2).swizzle(new Vec2([10, 0, 0, 0, 20, 0, 0, 0], 0, 4), 1, 1, 0).buf, + [0, 20, 0, 20, 0, 10, 0] + ); + }); + + it("vec4", () => { + assert.deepEqual( + swizzle4([], [10, 20, 30, 40], 3, 2, 1, 0), + [40, 30, 20, 10] + ); + assert.deepEqual( + swizzle4([], [10, 20, 30, 40], 1, 1, 1, 1), + [20, 20, 20, 20] + ); + assert.deepEqual( + swizzle4([0, 0, 0, 0, 0, 0, 0, 0], [10, 20, 30, 40], 3, 2, 1, 0, 1, 0, 2, 1), + [0, 40, 0, 30, 0, 20, 0, 10] + ); + assert.deepEqual( + swizzle4([], [0, 10, 0, 0, 0, 20, 0, 0, 0, 30, 0, 0, 0, 40], 3, 2, 1, 0, 0, 1, 1, 4), + [40, 30, 20, 10] + ); + assert.deepEqual( + new Vec4([]).swizzle(new Vec4([10, 0, 20, 0, 30, 0, 40, 0], 0, 2), 3, 2, 1, 0).buf, + [40, 30, 20, 10] + ); + assert.deepEqual( + new Vec4([0, 0, 0, 0, 0, 0, 0, 0, 0], 1, 2).swizzle(new Vec2([10, 0, 0, 0, 20, 0, 0, 0], 0, 4), 1, 1, 0, 0).buf, + [0, 20, 0, 20, 0, 10, 0, 10, 0] + ); + }); +}); diff --git a/packages/vectors/test/tsconfig.json b/packages/vectors/test/tsconfig.json new file mode 100644 index 0000000000..bcf29ace54 --- /dev/null +++ b/packages/vectors/test/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "outDir": "../build" + }, + "include": [ + "./**/*.ts", + "../src/**/*.ts" + ] +} diff --git a/packages/vectors/test/vec2.ts b/packages/vectors/test/vec2.ts new file mode 100644 index 0000000000..5c6e1c15a9 --- /dev/null +++ b/packages/vectors/test/vec2.ts @@ -0,0 +1,65 @@ +import * as assert from "assert"; +import * as v from "../src/index"; + +describe("vec2", () => { + + const op2 = (fn, x, y) => { + assert.deepEqual( + fn([1, 2], [10, 20]), + [x, y] + ); + assert.deepEqual( + fn([0, 1, 0, 0, 0, 2, 0, 0], [0, 10, 0, 20, 0], 1, 1, 4, 2), + [0, x, 0, 0, 0, y, 0, 0] + ); + }; + + const opn = (fn, x, y) => { + assert.deepEqual( + fn([1, 2], 10), + [x, y] + ); + assert.deepEqual( + fn([0, 1, 0, 0, 0, 2, 0, 0], 10, 1, 4), + [0, x, 0, 0, 0, y, 0, 0] + ); + }; + + it("add", () => op2(v.add2, 11, 22)); + it("sub", () => op2(v.sub2, -9, -18)); + it("mul", () => op2(v.mul2, 10, 40)); + it("div", () => op2(v.div2, 0.1, 0.1)); + + it("addn", () => opn(v.addN2, 11, 12)); + it("subn", () => opn(v.subN2, -9, -8)); + it("muln", () => opn(v.mulN2, 10, 20)); + it("divn", () => opn(v.divN2, 0.1, 0.2)); + + it("madd", () => { + assert.deepEqual( + v.madd2([1, 2], [10, 20], [0.5, 0.25]), + [1 + 10 * 0.5, 2 + 20 * 0.25] + ); + assert.deepEqual( + v.madd2([1, 2], [10, 0, 20, 0], [0.5, 0, 0, 0.25], 0, 0, 0, 1, 2, 3), + [1 + 10 * 0.5, 2 + 20 * 0.25] + ); + }); + + it("maddn", () => { + assert.deepEqual( + v.maddN2([1, 2], [10, 20], 0.5), + [1 + 10 * 0.5, 2 + 20 * 0.5] + ); + assert.deepEqual( + v.maddN2([1, 2], [10, 0, 20, 0], 0.5, 0, 0, 1, 2), + [1 + 10 * 0.5, 2 + 20 * 0.5] + ); + }); + + + it("eqdelta", () => { + assert(v.eqDelta2([0, 1.001, 0, 1.999, 0], [1, 2], 0.01, 1, 0, 2, 1)); + assert(!v.eqDelta2([0, 1.001, 0, 1.989, 0], [1, 2], 0.01, 1, 0, 2, 1)); + }); +}); diff --git a/packages/vectors/test/vec3.ts b/packages/vectors/test/vec3.ts new file mode 100644 index 0000000000..c3e7528d2f --- /dev/null +++ b/packages/vectors/test/vec3.ts @@ -0,0 +1,64 @@ +import * as assert from "assert"; +import * as v from "../src/index"; + +describe("vec3", () => { + + const op2 = (fn, x, y, z) => { + assert.deepEqual( + fn([1, 2, 3], [10, 20, 30]), + [x, y, z] + ); + assert.deepEqual( + fn([0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0], [0, 10, 0, 20, 0, 30, 0], 1, 1, 4, 2), + [0, x, 0, 0, 0, y, 0, 0, 0, z, 0, 0] + ); + }; + + const opn = (fn, x, y, z) => { + assert.deepEqual( + fn([1, 2, 3], 10), + [x, y, z] + ); + assert.deepEqual( + fn([0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0], 10, 1, 4), + [0, x, 0, 0, 0, y, 0, 0, 0, z, 0, 0] + ); + }; + + it("add", () => op2(v.add3, 11, 22, 33)); + it("sub", () => op2(v.sub3, -9, -18, -27)); + it("mul", () => op2(v.mul3, 10, 40, 90)); + it("div", () => op2(v.div3, 0.1, 0.1, 0.1)); + + it("addn", () => opn(v.addN3, 11, 12, 13)); + it("subn", () => opn(v.subN3, -9, -8, -7)); + it("muln", () => opn(v.mulN3, 10, 20, 30)); + it("divn", () => opn(v.divN3, 0.1, 0.2, 0.3)); + + it("madd", () => { + assert.deepEqual( + v.madd3([1, 2, 3], [10, 20, 30], [0.5, 0.25, 0.75]), + [1 + 10 * 0.5, 2 + 20 * 0.25, 3 + 30 * 0.75] + ); + assert.deepEqual( + v.madd3([1, 2, 3], [10, 0, 20, 0, 30], [0.5, 0, 0, 0.25, 0, 0, 0.75], 0, 0, 0, 1, 2, 3), + [1 + 10 * 0.5, 2 + 20 * 0.25, 3 + 30 * 0.75] + ); + }); + + it("maddn", () => { + assert.deepEqual( + v.maddN3([1, 2, 3], [10, 20, 30], 0.5), + [1 + 10 * 0.5, 2 + 20 * 0.5, 3 + 30 * 0.5] + ); + assert.deepEqual( + v.maddN3([1, 2, 3], [10, 0, 20, 0, 30], 0.5, 0, 0, 1, 2), + [1 + 10 * 0.5, 2 + 20 * 0.5, 3 + 30 * 0.5] + ); + }); + + it("eqdelta", () => { + assert(v.eqDelta3([0, 1.001, 0, 1.999, 0, 3.0099], [1, 2, 3], 0.01, 1, 0, 2, 1)); + assert(!v.eqDelta3([0, 1.001, 0, 1.999, 0, 3.02], [1, 2, 3], 0.01, 1, 0, 2, 1)); + }); +}); diff --git a/packages/vectors/test/vec4.ts b/packages/vectors/test/vec4.ts new file mode 100644 index 0000000000..6fcc22aacd --- /dev/null +++ b/packages/vectors/test/vec4.ts @@ -0,0 +1,64 @@ +import * as assert from "assert"; +import * as v from "../src/index"; + +describe("vec4", () => { + + const op2 = (fn, x, y, z, w) => { + assert.deepEqual( + fn([1, 2, 3, 4], [10, 20, 30, 40]), + [x, y, z, w] + ); + assert.deepEqual( + fn([0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0], [0, 10, 0, 20, 0, 30, 0, 40, 0], 1, 1, 4, 2), + [0, x, 0, 0, 0, y, 0, 0, 0, z, 0, 0, 0, w, 0, 0] + ); + }; + + const opn = (fn, x, y, z, w) => { + assert.deepEqual( + fn([1, 2, 3, 4], 10), + [x, y, z, w] + ); + assert.deepEqual( + fn([0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0], 10, 1, 4), + [0, x, 0, 0, 0, y, 0, 0, 0, z, 0, 0, 0, w, 0, 0] + ); + }; + + it("add", () => op2(v.add4, 11, 22, 33, 44)); + it("sub", () => op2(v.sub4, -9, -18, -27, -36)); + it("mul", () => op2(v.mul4, 10, 40, 90, 160)); + it("div", () => op2(v.div4, 0.1, 0.1, 0.1, 0.1)); + + it("addn", () => opn(v.addN4, 11, 12, 13, 14)); + it("subn", () => opn(v.subN4, -9, -8, -7, -6)); + it("muln", () => opn(v.mulN4, 10, 20, 30, 40)); + it("divn", () => opn(v.divN4, 0.1, 0.2, 0.3, 0.4)); + + it("madd", () => { + assert.deepEqual( + v.madd4([1, 2, 3, 4], [10, 20, 30, 40], [0.5, 0.25, 0.75, 0.125]), + [1 + 10 * 0.5, 2 + 20 * 0.25, 3 + 30 * 0.75, 4 + 40 * 0.125] + ); + assert.deepEqual( + v.madd4([1, 2, 3, 4], [10, 0, 20, 0, 30, 0, 40], [0.5, 0, 0, 0.25, 0, 0, 0.75, 0, 0, 0.125], 0, 0, 0, 1, 2, 3), + [1 + 10 * 0.5, 2 + 20 * 0.25, 3 + 30 * 0.75, 4 + 40 * 0.125] + ); + }); + + it("maddn", () => { + assert.deepEqual( + v.maddN4([1, 2, 3, 4], [10, 20, 30, 40], 0.5), + [1 + 10 * 0.5, 2 + 20 * 0.5, 3 + 30 * 0.5, 4 + 40 * 0.5] + ); + assert.deepEqual( + v.maddN4([1, 2, 3, 4], [10, 0, 20, 0, 30, 0, 40], 0.5, 0, 0, 1, 2), + [1 + 10 * 0.5, 2 + 20 * 0.5, 3 + 30 * 0.5, 4 + 40 * 0.5] + ); + }); + + it("eqdelta", () => { + assert(v.eqDelta4([0, 1.001, 0, 1.999, 0, 3.0099, 0, 3.991], [1, 2, 3, 4], 0.01, 1, 0, 2, 1)); + assert(!v.eqDelta4([0, 1.001, 0, 1.999, 0, 3.02, 0, 4], [1, 2, 3, 4], 0.01, 1, 0, 2, 1)); + }); +}); diff --git a/packages/vectors/tsconfig.json b/packages/vectors/tsconfig.json new file mode 100644 index 0000000000..bd6481a5a6 --- /dev/null +++ b/packages/vectors/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "." + }, + "include": [ + "./src/**/*.ts" + ] +} diff --git a/yarn.lock b/yarn.lock index 609da9f564..686258ed99 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,192 @@ # yarn lockfile v1 +"@babel/code-frame@7.0.0-beta.51": + version "7.0.0-beta.51" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.51.tgz#bd71d9b192af978df915829d39d4094456439a0c" + dependencies: + "@babel/highlight" "7.0.0-beta.51" + +"@babel/code-frame@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.54.tgz#0024f96fdf7028a21d68e273afd4e953214a1ead" + dependencies: + "@babel/highlight" "7.0.0-beta.54" + +"@babel/core@^7.0.0-beta.46": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.0.0-beta.54.tgz#253c54d0095403a5cfa764e7d9b458194692d02b" + dependencies: + "@babel/code-frame" "7.0.0-beta.54" + "@babel/generator" "7.0.0-beta.54" + "@babel/helpers" "7.0.0-beta.54" + "@babel/parser" "7.0.0-beta.54" + "@babel/template" "7.0.0-beta.54" + "@babel/traverse" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + convert-source-map "^1.1.0" + debug "^3.1.0" + json5 "^0.5.0" + lodash "^4.17.5" + resolve "^1.3.2" + semver "^5.4.1" + source-map "^0.5.0" + +"@babel/generator@7.0.0-beta.51": + version "7.0.0-beta.51" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0-beta.51.tgz#6c7575ffde761d07485e04baedc0392c6d9e30f6" + dependencies: + "@babel/types" "7.0.0-beta.51" + jsesc "^2.5.1" + lodash "^4.17.5" + source-map "^0.5.0" + trim-right "^1.0.1" + +"@babel/generator@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0-beta.54.tgz#c043c7eebeebfd7e665d95c281a4aafc83d4e1c9" + dependencies: + "@babel/types" "7.0.0-beta.54" + jsesc "^2.5.1" + lodash "^4.17.5" + source-map "^0.5.0" + trim-right "^1.0.1" + +"@babel/helper-function-name@7.0.0-beta.51": + version "7.0.0-beta.51" + resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.51.tgz#21b4874a227cf99ecafcc30a90302da5a2640561" + dependencies: + "@babel/helper-get-function-arity" "7.0.0-beta.51" + "@babel/template" "7.0.0-beta.51" + "@babel/types" "7.0.0-beta.51" + +"@babel/helper-function-name@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.54.tgz#307875507a1eda2482a09a9a4df6a25632ffb34b" + dependencies: + "@babel/helper-get-function-arity" "7.0.0-beta.54" + "@babel/template" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-get-function-arity@7.0.0-beta.51": + version "7.0.0-beta.51" + resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.51.tgz#3281b2d045af95c172ce91b20825d85ea4676411" + dependencies: + "@babel/types" "7.0.0-beta.51" + +"@babel/helper-get-function-arity@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.54.tgz#757bd189b077074a004028cfde5f083c306cc6c4" + dependencies: + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-split-export-declaration@7.0.0-beta.51": + version "7.0.0-beta.51" + resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.51.tgz#8a6c3f66c4d265352fc077484f9f6e80a51ab978" + dependencies: + "@babel/types" "7.0.0-beta.51" + +"@babel/helper-split-export-declaration@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.54.tgz#89cd8833c95481a0827ac6a1bfccddb92b75a109" + dependencies: + "@babel/types" "7.0.0-beta.54" + +"@babel/helpers@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.0.0-beta.54.tgz#b86a99a80efd81668caef307610b961197446a74" + dependencies: + "@babel/template" "7.0.0-beta.54" + "@babel/traverse" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + +"@babel/highlight@7.0.0-beta.51": + version "7.0.0-beta.51" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0-beta.51.tgz#e8844ae25a1595ccfd42b89623b4376ca06d225d" + dependencies: + chalk "^2.0.0" + esutils "^2.0.2" + js-tokens "^3.0.0" + +"@babel/highlight@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0-beta.54.tgz#155d507358329b8e7068970017c3fd74a9b08584" + dependencies: + chalk "^2.0.0" + esutils "^2.0.2" + js-tokens "^3.0.0" + +"@babel/parser@7.0.0-beta.51": + version "7.0.0-beta.51" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.0.0-beta.51.tgz#27cec2df409df60af58270ed8f6aa55409ea86f6" + +"@babel/parser@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.0.0-beta.54.tgz#c01aa63b57c9c8dce8744796c81d9df121f20db4" + +"@babel/template@7.0.0-beta.51": + version "7.0.0-beta.51" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.51.tgz#9602a40aebcf357ae9677e2532ef5fc810f5fbff" + dependencies: + "@babel/code-frame" "7.0.0-beta.51" + "@babel/parser" "7.0.0-beta.51" + "@babel/types" "7.0.0-beta.51" + lodash "^4.17.5" + +"@babel/template@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.54.tgz#d5b0d2d2d55c0e78b048c61a058f36cfd7d91af3" + dependencies: + "@babel/code-frame" "7.0.0-beta.54" + "@babel/parser" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + lodash "^4.17.5" + +"@babel/traverse@7.0.0-beta.51": + version "7.0.0-beta.51" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.0.0-beta.51.tgz#981daf2cec347a6231d3aa1d9e1803b03aaaa4a8" + dependencies: + "@babel/code-frame" "7.0.0-beta.51" + "@babel/generator" "7.0.0-beta.51" + "@babel/helper-function-name" "7.0.0-beta.51" + "@babel/helper-split-export-declaration" "7.0.0-beta.51" + "@babel/parser" "7.0.0-beta.51" + "@babel/types" "7.0.0-beta.51" + debug "^3.1.0" + globals "^11.1.0" + invariant "^2.2.0" + lodash "^4.17.5" + +"@babel/traverse@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.0.0-beta.54.tgz#2c17f98dcdbf19aa918fde128f0e1a0bc089e05a" + dependencies: + "@babel/code-frame" "7.0.0-beta.54" + "@babel/generator" "7.0.0-beta.54" + "@babel/helper-function-name" "7.0.0-beta.54" + "@babel/helper-split-export-declaration" "7.0.0-beta.54" + "@babel/parser" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + debug "^3.1.0" + globals "^11.1.0" + lodash "^4.17.5" + +"@babel/types@7.0.0-beta.51": + version "7.0.0-beta.51" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.51.tgz#d802b7b543b5836c778aa691797abf00f3d97ea9" + dependencies: + esutils "^2.0.2" + lodash "^4.17.5" + to-fast-properties "^2.0.0" + +"@babel/types@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.54.tgz#025ad68492fed542c13f14c579a44c848e531063" + dependencies: + esutils "^2.0.2" + lodash "^4.17.5" + to-fast-properties "^2.0.0" + "@types/events@*": version "1.2.0" resolved "https://registry.yarnpkg.com/@types/events/-/events-1.2.0.tgz#81a6731ce4df43619e5c8c945383b3e62a89ea86" @@ -40,14 +226,18 @@ version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" -"@types/mocha@^5.2.0": - version "5.2.0" - resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.0.tgz#b3c8e69f038835db1a7fdc0b3d879fc50506e29e" +"@types/mocha@^5.2.5": + version "5.2.5" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.5.tgz#8a4accfc403c124a0bafe8a9fc61a05ec1032073" -"@types/node@*", "@types/node@^10.0.6": +"@types/node@*": version "10.0.6" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.0.6.tgz#c0bce8e539bf34c1b850c13ff46bead2fecc2e58" +"@types/node@^10.5.5": + version "10.5.5" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.5.tgz#8e84d24e896cd77b0d4f73df274027e3149ec2ba" + "@types/shelljs@0.7.8": version "0.7.8" resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.7.8.tgz#4b4d6ee7926e58d7bca448a50ba442fd9f6715bd" @@ -399,7 +589,7 @@ atob@^2.0.0: version "2.1.1" resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.1.tgz#ae2d5a729477f289d60dd7f96a6314a22dd6c22a" -babel-code-frame@^6.22.0, babel-code-frame@^6.26.0: +babel-code-frame@^6.22.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" dependencies: @@ -407,68 +597,185 @@ babel-code-frame@^6.22.0, babel-code-frame@^6.26.0: esutils "^2.0.2" js-tokens "^3.0.2" -babel-generator@^6.18.0: - version "6.26.1" - resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.26.1.tgz#1844408d3b8f0d35a404ea7ac180f087a601bd90" +babel-helper-evaluate-path@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-helper-evaluate-path/-/babel-helper-evaluate-path-0.4.3.tgz#0a89af702c06b217027fa371908dd4989d3e633f" + +babel-helper-flip-expressions@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-helper-flip-expressions/-/babel-helper-flip-expressions-0.4.3.tgz#3696736a128ac18bc25254b5f40a22ceb3c1d3fd" + +babel-helper-is-nodes-equiv@^0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/babel-helper-is-nodes-equiv/-/babel-helper-is-nodes-equiv-0.0.1.tgz#34e9b300b1479ddd98ec77ea0bbe9342dfe39684" + +babel-helper-is-void-0@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-helper-is-void-0/-/babel-helper-is-void-0-0.4.3.tgz#7d9c01b4561e7b95dbda0f6eee48f5b60e67313e" + +babel-helper-mark-eval-scopes@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-helper-mark-eval-scopes/-/babel-helper-mark-eval-scopes-0.4.3.tgz#d244a3bef9844872603ffb46e22ce8acdf551562" + +babel-helper-remove-or-void@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-helper-remove-or-void/-/babel-helper-remove-or-void-0.4.3.tgz#a4f03b40077a0ffe88e45d07010dee241ff5ae60" + +babel-helper-to-multiple-sequence-expressions@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-helper-to-multiple-sequence-expressions/-/babel-helper-to-multiple-sequence-expressions-0.4.3.tgz#5b518b1127f47b3038773386a1561a2b48e632b6" + +babel-minify@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-minify/-/babel-minify-0.4.3.tgz#d947e4ed6b626dc8c25687f242c25cbcf6f281a6" dependencies: - babel-messages "^6.23.0" - babel-runtime "^6.26.0" - babel-types "^6.26.0" - detect-indent "^4.0.0" - jsesc "^1.3.0" - lodash "^4.17.4" - source-map "^0.5.7" - trim-right "^1.0.1" + "@babel/core" "^7.0.0-beta.46" + babel-preset-minify "^0.4.3" + fs-readdir-recursive "^1.1.0" + mkdirp "^0.5.1" + util.promisify "^1.0.0" + yargs-parser "^10.0.0" -babel-messages@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e" +babel-plugin-minify-builtins@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-builtins/-/babel-plugin-minify-builtins-0.4.3.tgz#9ea3d59f4ac4a7bb958d712d29556a1f86f7f81e" dependencies: - babel-runtime "^6.22.0" + babel-helper-evaluate-path "^0.4.3" -babel-runtime@^6.22.0, babel-runtime@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" +babel-plugin-minify-constant-folding@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-constant-folding/-/babel-plugin-minify-constant-folding-0.4.3.tgz#300f9de8dda0844a176b193653960e24ad33e191" dependencies: - core-js "^2.4.0" - regenerator-runtime "^0.11.0" + babel-helper-evaluate-path "^0.4.3" -babel-template@^6.16.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02" +babel-plugin-minify-dead-code-elimination@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-dead-code-elimination/-/babel-plugin-minify-dead-code-elimination-0.4.3.tgz#73628265864f9008d0027506f58abeb3c1d02d98" dependencies: - babel-runtime "^6.26.0" - babel-traverse "^6.26.0" - babel-types "^6.26.0" - babylon "^6.18.0" - lodash "^4.17.4" + babel-helper-evaluate-path "^0.4.3" + babel-helper-mark-eval-scopes "^0.4.3" + babel-helper-remove-or-void "^0.4.3" + lodash.some "^4.6.0" -babel-traverse@^6.18.0, babel-traverse@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" +babel-plugin-minify-flip-comparisons@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-flip-comparisons/-/babel-plugin-minify-flip-comparisons-0.4.3.tgz#00ca870cb8f13b45c038b3c1ebc0f227293c965a" dependencies: - babel-code-frame "^6.26.0" - babel-messages "^6.23.0" - babel-runtime "^6.26.0" - babel-types "^6.26.0" - babylon "^6.18.0" - debug "^2.6.8" - globals "^9.18.0" - invariant "^2.2.2" - lodash "^4.17.4" + babel-helper-is-void-0 "^0.4.3" -babel-types@^6.18.0, babel-types@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497" +babel-plugin-minify-guarded-expressions@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-guarded-expressions/-/babel-plugin-minify-guarded-expressions-0.4.3.tgz#cc709b4453fd21b1f302877444c89f88427ce397" + dependencies: + babel-helper-flip-expressions "^0.4.3" + +babel-plugin-minify-infinity@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-infinity/-/babel-plugin-minify-infinity-0.4.3.tgz#dfb876a1b08a06576384ef3f92e653ba607b39ca" + +babel-plugin-minify-mangle-names@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-mangle-names/-/babel-plugin-minify-mangle-names-0.4.3.tgz#16f1bff74b7a7c93dfc241e7831dd5fb4b023ef7" + dependencies: + babel-helper-mark-eval-scopes "^0.4.3" + +babel-plugin-minify-numeric-literals@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-numeric-literals/-/babel-plugin-minify-numeric-literals-0.4.3.tgz#8e4fd561c79f7801286ff60e8c5fd9deee93c0bc" + +babel-plugin-minify-replace@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-replace/-/babel-plugin-minify-replace-0.4.3.tgz#9d289f4ba15d4e6011e8799fa5f1ba77ec81219d" + +babel-plugin-minify-simplify@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-simplify/-/babel-plugin-minify-simplify-0.4.3.tgz#37756d85c614464b4b0927f2b4e417191d55738a" + dependencies: + babel-helper-flip-expressions "^0.4.3" + babel-helper-is-nodes-equiv "^0.0.1" + babel-helper-to-multiple-sequence-expressions "^0.4.3" + +babel-plugin-minify-type-constructors@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-minify-type-constructors/-/babel-plugin-minify-type-constructors-0.4.3.tgz#1bc6f15b87f7ab1085d42b330b717657a2156500" + dependencies: + babel-helper-is-void-0 "^0.4.3" + +babel-plugin-transform-inline-consecutive-adds@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-inline-consecutive-adds/-/babel-plugin-transform-inline-consecutive-adds-0.4.3.tgz#323d47a3ea63a83a7ac3c811ae8e6941faf2b0d1" + +babel-plugin-transform-member-expression-literals@^6.9.4: + version "6.9.4" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-member-expression-literals/-/babel-plugin-transform-member-expression-literals-6.9.4.tgz#37039c9a0c3313a39495faac2ff3a6b5b9d038bf" + +babel-plugin-transform-merge-sibling-variables@^6.9.4: + version "6.9.4" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-merge-sibling-variables/-/babel-plugin-transform-merge-sibling-variables-6.9.4.tgz#85b422fc3377b449c9d1cde44087203532401dae" + +babel-plugin-transform-minify-booleans@^6.9.4: + version "6.9.4" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-minify-booleans/-/babel-plugin-transform-minify-booleans-6.9.4.tgz#acbb3e56a3555dd23928e4b582d285162dd2b198" + +babel-plugin-transform-property-literals@^6.9.4: + version "6.9.4" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-property-literals/-/babel-plugin-transform-property-literals-6.9.4.tgz#98c1d21e255736573f93ece54459f6ce24985d39" dependencies: - babel-runtime "^6.26.0" esutils "^2.0.2" - lodash "^4.17.4" - to-fast-properties "^1.0.3" -babylon@^6.18.0: - version "6.18.0" - resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" +babel-plugin-transform-regexp-constructors@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-regexp-constructors/-/babel-plugin-transform-regexp-constructors-0.4.3.tgz#58b7775b63afcf33328fae9a5f88fbd4fb0b4965" + +babel-plugin-transform-remove-console@^6.9.4: + version "6.9.4" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-remove-console/-/babel-plugin-transform-remove-console-6.9.4.tgz#b980360c067384e24b357a588d807d3c83527780" + +babel-plugin-transform-remove-debugger@^6.9.4: + version "6.9.4" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-remove-debugger/-/babel-plugin-transform-remove-debugger-6.9.4.tgz#42b727631c97978e1eb2d199a7aec84a18339ef2" + +babel-plugin-transform-remove-undefined@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-remove-undefined/-/babel-plugin-transform-remove-undefined-0.4.3.tgz#d40b0da7f91c08c06cc72b767474c01c4894de02" + dependencies: + babel-helper-evaluate-path "^0.4.3" + +babel-plugin-transform-simplify-comparison-operators@^6.9.4: + version "6.9.4" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-simplify-comparison-operators/-/babel-plugin-transform-simplify-comparison-operators-6.9.4.tgz#f62afe096cab0e1f68a2d753fdf283888471ceb9" + +babel-plugin-transform-undefined-to-void@^6.9.4: + version "6.9.4" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-undefined-to-void/-/babel-plugin-transform-undefined-to-void-6.9.4.tgz#be241ca81404030678b748717322b89d0c8fe280" + +babel-preset-minify@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/babel-preset-minify/-/babel-preset-minify-0.4.3.tgz#b29c3dd6918905384598f092b955152e26a1fe0f" + dependencies: + babel-plugin-minify-builtins "^0.4.3" + babel-plugin-minify-constant-folding "^0.4.3" + babel-plugin-minify-dead-code-elimination "^0.4.3" + babel-plugin-minify-flip-comparisons "^0.4.3" + babel-plugin-minify-guarded-expressions "^0.4.3" + babel-plugin-minify-infinity "^0.4.3" + babel-plugin-minify-mangle-names "^0.4.3" + babel-plugin-minify-numeric-literals "^0.4.3" + babel-plugin-minify-replace "^0.4.3" + babel-plugin-minify-simplify "^0.4.3" + babel-plugin-minify-type-constructors "^0.4.3" + babel-plugin-transform-inline-consecutive-adds "^0.4.3" + babel-plugin-transform-member-expression-literals "^6.9.4" + babel-plugin-transform-merge-sibling-variables "^6.9.4" + babel-plugin-transform-minify-booleans "^6.9.4" + babel-plugin-transform-property-literals "^6.9.4" + babel-plugin-transform-regexp-constructors "^0.4.3" + babel-plugin-transform-remove-console "^6.9.4" + babel-plugin-transform-remove-debugger "^6.9.4" + babel-plugin-transform-remove-undefined "^0.4.3" + babel-plugin-transform-simplify-comparison-operators "^6.9.4" + babel-plugin-transform-undefined-to-void "^6.9.4" + lodash.isplainobject "^4.0.6" balanced-match@^1.0.0: version "1.0.0" @@ -890,11 +1197,7 @@ command-join@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/command-join/-/command-join-2.0.0.tgz#52e8b984f4872d952ff1bdc8b98397d27c7144cf" -commander@2.11.0: - version "2.11.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563" - -commander@^2.12.1: +commander@2.15.1, commander@^2.12.1: version "2.15.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" @@ -1124,7 +1427,7 @@ conventional-recommended-bump@^1.2.1: meow "^3.3.0" object-assign "^4.0.1" -convert-source-map@^1.5.1: +convert-source-map@^1.1.0, convert-source-map@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.1.tgz#b8278097b9bc229365de5c62cf5fcaed8b5599e5" @@ -1151,10 +1454,6 @@ copy-descriptor@^0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" -core-js@^2.4.0: - version "2.5.6" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.6.tgz#0fe6d45bf3cac3ac364a9d72de7576f4eb221b9d" - core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" @@ -1291,6 +1590,12 @@ decamelize@^1.0.0, decamelize@^1.1.0, decamelize@^1.1.1, decamelize@^1.1.2: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" +decamelize@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-2.0.0.tgz#656d7bbc8094c4c788ea53c5840908c9c7d063c7" + dependencies: + xregexp "4.0.0" + decode-uri-component@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" @@ -1379,12 +1684,6 @@ destroy@~1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" -detect-indent@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-4.0.0.tgz#f76d064352cdf43a1cb6ce619c4ee3a9475de208" - dependencies: - repeating "^2.0.0" - detect-indent@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d" @@ -1511,6 +1810,16 @@ error-ex@^1.2.0, error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" +es-abstract@^1.5.1: + version "1.12.0" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.12.0.tgz#9dbbdd27c6856f0001421ca18782d786bf8a6165" + dependencies: + es-to-primitive "^1.1.1" + function-bind "^1.1.1" + has "^1.0.1" + is-callable "^1.1.3" + is-regex "^1.0.4" + es-abstract@^1.7.0: version "1.11.0" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.11.0.tgz#cce87d518f0496893b1a30cd8461835535480681" @@ -1560,9 +1869,9 @@ escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1 version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" -eslint-scope@^3.7.1: - version "3.7.1" - resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.1.tgz#3d63c3edfda02e06e01a452ad88caacc7cdcb6e8" +eslint-scope@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.0.tgz#50bf3071e9338bcdc43331794a0cb533f0136172" dependencies: esrecurse "^4.1.0" estraverse "^4.1.1" @@ -1799,6 +2108,12 @@ find-up@^2.0.0, find-up@^2.1.0: dependencies: locate-path "^2.0.0" +find-up@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73" + dependencies: + locate-path "^3.0.0" + flush-write-stream@^1.0.0: version "1.0.3" resolved "https://registry.yarnpkg.com/flush-write-stream/-/flush-write-stream-1.0.3.tgz#c5d586ef38af6097650b49bc41b55fabb19f35bd" @@ -1870,6 +2185,10 @@ fs-minipass@^1.2.5: dependencies: minipass "^2.2.1" +fs-readdir-recursive@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz#e32fc030a2ccee44a6b5371308da54be0b397d27" + fs-write-stream-atomic@^1.0.8: version "1.0.10" resolved "https://registry.yarnpkg.com/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz#b47df53493ef911df75731e70a9ded0189db40c9" @@ -1989,9 +2308,9 @@ global-modules-path@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/global-modules-path/-/global-modules-path-2.1.0.tgz#923ec524e8726bb0c1a4ed4b8e21e1ff80c88bbb" -globals@^9.18.0: - version "9.18.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" +globals@^11.1.0: + version "11.7.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-11.7.0.tgz#a583faa43055b1aca771914bf68258e2fc125673" globby@^6.1.0: version "6.1.0" @@ -2023,15 +2342,15 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" -growl@1.10.3: - version "1.10.3" - resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.3.tgz#1926ba90cf3edfe2adb4927f5880bc22c66c790f" +growl@1.10.5: + version "1.10.5" + resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e" handle-thing@^1.2.5: version "1.2.5" resolved "https://registry.yarnpkg.com/handle-thing/-/handle-thing-1.2.5.tgz#fd7aad726bf1a5fd16dfc29b2f7a6601d27139c4" -handlebars@^4.0.2, handlebars@^4.0.3, handlebars@^4.0.6: +handlebars@^4.0.11, handlebars@^4.0.2, handlebars@^4.0.6: version "4.0.11" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.11.tgz#630a35dfe0294bc281edae6ffc5d329fc7982dcc" dependencies: @@ -2051,10 +2370,6 @@ has-flag@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa" -has-flag@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51" - has-flag@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" @@ -2313,7 +2628,7 @@ interpret@^1.0.0, interpret@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614" -invariant@^2.2.2: +invariant@^2.2.0: version "2.2.4" resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6" dependencies: @@ -2563,23 +2878,27 @@ istanbul-lib-coverage@^1.1.2, istanbul-lib-coverage@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-1.2.0.tgz#f7d8f2e42b97e37fe796114cb0f9d68b5e3a4341" +istanbul-lib-coverage@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#2aee0e073ad8c5f6a0b00e0dfbf52b4667472eda" + istanbul-lib-hook@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/istanbul-lib-hook/-/istanbul-lib-hook-1.1.0.tgz#8538d970372cb3716d53e55523dd54b557a8d89b" dependencies: append-transform "^0.4.0" -istanbul-lib-instrument@^1.10.0: - version "1.10.1" - resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.10.1.tgz#724b4b6caceba8692d3f1f9d0727e279c401af7b" - dependencies: - babel-generator "^6.18.0" - babel-template "^6.16.0" - babel-traverse "^6.18.0" - babel-types "^6.18.0" - babylon "^6.18.0" - istanbul-lib-coverage "^1.2.0" - semver "^5.3.0" +istanbul-lib-instrument@^2.1.0: + version "2.3.2" + resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-2.3.2.tgz#b287cbae2b5f65f3567b05e2e29b275eaf92d25e" + dependencies: + "@babel/generator" "7.0.0-beta.51" + "@babel/parser" "7.0.0-beta.51" + "@babel/template" "7.0.0-beta.51" + "@babel/traverse" "7.0.0-beta.51" + "@babel/types" "7.0.0-beta.51" + istanbul-lib-coverage "^2.0.1" + semver "^5.5.0" istanbul-lib-report@^1.1.3: version "1.1.3" @@ -2590,21 +2909,21 @@ istanbul-lib-report@^1.1.3: path-parse "^1.0.5" supports-color "^3.1.2" -istanbul-lib-source-maps@^1.2.3: - version "1.2.3" - resolved "https://registry.yarnpkg.com/istanbul-lib-source-maps/-/istanbul-lib-source-maps-1.2.3.tgz#20fb54b14e14b3fb6edb6aca3571fd2143db44e6" +istanbul-lib-source-maps@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/istanbul-lib-source-maps/-/istanbul-lib-source-maps-1.2.5.tgz#ffe6be4e7ab86d3603e4290d54990b14506fc9b1" dependencies: debug "^3.1.0" - istanbul-lib-coverage "^1.1.2" + istanbul-lib-coverage "^1.2.0" mkdirp "^0.5.1" rimraf "^2.6.1" source-map "^0.5.3" -istanbul-reports@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/istanbul-reports/-/istanbul-reports-1.4.0.tgz#3d7b44b912ecbe7652a603662b962120739646a1" +istanbul-reports@^1.4.1: + version "1.5.0" + resolved "https://registry.yarnpkg.com/istanbul-reports/-/istanbul-reports-1.5.0.tgz#c6c2867fa65f59eb7dcedb7f845dfc76aaee70f9" dependencies: - handlebars "^4.0.3" + handlebars "^4.0.11" js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" @@ -2617,9 +2936,9 @@ js-yaml@^3.7.0: argparse "^1.0.7" esprima "^4.0.0" -jsesc@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b" +jsesc@^2.5.1: + version "2.5.1" + resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.1.tgz#e421a2a8e20d6b0819df28908f782526b96dd1fe" json-parse-better-errors@^1.0.1, json-parse-better-errors@^1.0.2: version "1.0.2" @@ -2776,10 +3095,25 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" +locate-path@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e" + dependencies: + p-locate "^3.0.0" + path-exists "^3.0.0" + lodash._reinterpolate@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" +lodash.isplainobject@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" + +lodash.some@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.some/-/lodash.some-4.6.0.tgz#1bb9f314ef6b8baded13b549169b2a945eb68e4d" + lodash.template@^4.0.2: version "4.4.0" resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0" @@ -3084,21 +3418,21 @@ mkdirp@0.5.1, mkdirp@0.5.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0: dependencies: minimist "0.0.8" -mocha@^5.1.1: - version "5.1.1" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.1.1.tgz#b774c75609dac05eb48f4d9ba1d827b97fde8a7b" +mocha@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.2.0.tgz#6d8ae508f59167f940f2b5b3c4a612ae50c90ae6" dependencies: browser-stdout "1.3.1" - commander "2.11.0" + commander "2.15.1" debug "3.1.0" diff "3.5.0" escape-string-regexp "1.0.5" glob "7.1.2" - growl "1.10.3" + growl "1.10.5" he "1.1.1" minimatch "3.0.4" mkdirp "0.5.1" - supports-color "4.4.0" + supports-color "5.4.0" modify-values@^1.0.0: version "1.0.1" @@ -3282,9 +3616,9 @@ number-is-nan@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" -nyc@^11.7.1, nyc@^11.7.2: - version "11.7.2" - resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.7.2.tgz#15e554f937c216cc91aa08f9a260256ed6fe44b8" +nyc@^12.0.2: + version "12.0.2" + resolved "https://registry.yarnpkg.com/nyc/-/nyc-12.0.2.tgz#8a4a4ed690966c11ec587ff87eea0c12c974ba99" dependencies: archy "^1.0.0" arrify "^1.0.1" @@ -3296,12 +3630,12 @@ nyc@^11.7.1, nyc@^11.7.2: find-up "^2.1.0" foreground-child "^1.5.3" glob "^7.0.6" - istanbul-lib-coverage "^1.1.2" + istanbul-lib-coverage "^1.2.0" istanbul-lib-hook "^1.1.0" - istanbul-lib-instrument "^1.10.0" + istanbul-lib-instrument "^2.1.0" istanbul-lib-report "^1.1.3" - istanbul-lib-source-maps "^1.2.3" - istanbul-reports "^1.4.0" + istanbul-lib-source-maps "^1.2.5" + istanbul-reports "^1.4.1" md5-hex "^1.2.0" merge-source-map "^1.1.0" micromatch "^3.1.10" @@ -3345,6 +3679,13 @@ object.assign@^4.1.0: has-symbols "^1.0.0" object-keys "^1.0.11" +object.getownpropertydescriptors@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz#8758c846f5b407adab0f236e0986f14b051caa16" + dependencies: + define-properties "^1.1.2" + es-abstract "^1.5.1" + object.pick@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/object.pick/-/object.pick-1.3.0.tgz#87a10ac4c1694bd2e1cbf53591a66141fb5dd747" @@ -3433,12 +3774,24 @@ p-limit@^1.1.0: dependencies: p-try "^1.0.0" +p-limit@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.0.0.tgz#e624ed54ee8c460a778b3c9f3670496ff8a57aec" + dependencies: + p-try "^2.0.0" + p-locate@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" dependencies: p-limit "^1.1.0" +p-locate@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4" + dependencies: + p-limit "^2.0.0" + p-map@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.2.0.tgz#e4e94f311eabbc8633a1e79908165fca26241b6b" @@ -3447,6 +3800,10 @@ p-try@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3" +p-try@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.0.0.tgz#85080bb87c64688fa47996fe8f7dfbe8211760b1" + package-json@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/package-json/-/package-json-4.0.1.tgz#8869a0401253661c4c4ca3da6c2121ed555f5eed" @@ -3848,10 +4205,6 @@ redent@^2.0.0: indent-string "^3.0.0" strip-indent "^2.0.0" -regenerator-runtime@^0.11.0: - version "0.11.1" - resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" - regex-not@^1.0.0, regex-not@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c" @@ -4172,9 +4525,9 @@ snapdragon@^0.8.1: source-map-resolve "^0.5.0" use "^3.1.0" -sockjs-client@1.1.4: - version "1.1.4" - resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.1.4.tgz#5babe386b775e4cf14e7520911452654016c8b12" +sockjs-client@1.1.5: + version "1.1.5" + resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.1.5.tgz#1bb7c0f7222c40f42adf14f4442cbd1269771a83" dependencies: debug "^2.6.6" eventsource "0.1.6" @@ -4220,7 +4573,7 @@ source-map@^0.4.4: dependencies: amdefine ">=0.0.4" -source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7, source-map@~0.5.1: +source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" @@ -4426,11 +4779,11 @@ strong-log-transformer@^1.0.6: moment "^2.6.0" through "^2.3.4" -supports-color@4.4.0: - version "4.4.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.4.0.tgz#883f7ddabc165142b2a61427f3352ded195d1a3e" +supports-color@5.4.0, supports-color@^5.1.0, supports-color@^5.3.0, supports-color@^5.4.0: + version "5.4.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54" dependencies: - has-flag "^2.0.0" + has-flag "^3.0.0" supports-color@^2.0.0: version "2.0.0" @@ -4442,12 +4795,6 @@ supports-color@^3.1.2: dependencies: has-flag "^1.0.0" -supports-color@^5.1.0, supports-color@^5.3.0, supports-color@^5.4.0: - version "5.4.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54" - dependencies: - has-flag "^3.0.0" - tapable@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.0.0.tgz#cbb639d9002eed9c6b5975eb20598d7936f1f9f2" @@ -4535,9 +4882,9 @@ to-arraybuffer@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43" -to-fast-properties@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" +to-fast-properties@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e" to-object-path@^0.3.0: version "0.3.0" @@ -4595,9 +4942,9 @@ tslib@^1.9.0: version "1.9.3" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286" -tslint@^5.10.0: - version "5.10.0" - resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.10.0.tgz#11e26bccb88afa02dd0d9956cae3d4540b5f54c3" +tslint@^5.11.0: + version "5.11.0" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.11.0.tgz#98f30c02eae3cde7006201e4c33cb08b48581eed" dependencies: babel-code-frame "^6.22.0" builtin-modules "^1.1.1" @@ -4610,11 +4957,11 @@ tslint@^5.10.0: resolve "^1.3.2" semver "^5.3.0" tslib "^1.8.0" - tsutils "^2.12.1" + tsutils "^2.27.2" -tsutils@^2.12.1: - version "2.26.2" - resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.26.2.tgz#a9f9f63434a456a5e0c95a45d9a59181cb32d3bf" +tsutils@^2.27.2: + version "2.29.0" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.29.0.tgz#32b488501467acbedd4b85498673a0812aca0b99" dependencies: tslib "^1.8.1" @@ -4663,9 +5010,9 @@ typescript@2.7.2: version "2.7.2" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836" -typescript@^2.8.3: - version "2.8.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170" +typescript@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb" uglify-es@^3.3.4: version "3.3.9" @@ -4795,6 +5142,13 @@ util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" +util.promisify@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/util.promisify/-/util.promisify-1.0.0.tgz#440f7165a459c9a16dc145eb8e72f35687097030" + dependencies: + define-properties "^1.1.2" + object.getownpropertydescriptors "^2.0.3" + util@0.10.3, util@^0.10.3: version "0.10.3" resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9" @@ -4854,9 +5208,9 @@ wcwidth@^1.0.0: dependencies: defaults "^1.0.3" -webpack-cli@^3.0.8: - version "3.0.8" - resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.0.8.tgz#90eddcf04a4bfc31aa8c0edc4c76785bc4f1ccd9" +webpack-cli@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.1.0.tgz#d71a83687dcfeb758fdceeb0fe042f96bcf62994" dependencies: chalk "^2.4.1" cross-spawn "^6.0.5" @@ -4868,7 +5222,7 @@ webpack-cli@^3.0.8: loader-utils "^1.1.0" supports-color "^5.4.0" v8-compile-cache "^2.0.0" - yargs "^11.1.0" + yargs "^12.0.1" webpack-dev-middleware@3.1.3: version "3.1.3" @@ -4882,9 +5236,9 @@ webpack-dev-middleware@3.1.3: url-join "^4.0.0" webpack-log "^1.0.1" -webpack-dev-server@^3.1.4: - version "3.1.4" - resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-3.1.4.tgz#9a08d13c4addd1e3b6d8ace116e86715094ad5b4" +webpack-dev-server@^3.1.5: + version "3.1.5" + resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-3.1.5.tgz#87477252e1ac6789303fb8cd3e585fa5d508a401" dependencies: ansi-html "0.0.7" array-includes "^3.0.3" @@ -4907,7 +5261,7 @@ webpack-dev-server@^3.1.4: selfsigned "^1.9.1" serve-index "^1.7.2" sockjs "0.3.19" - sockjs-client "1.1.4" + sockjs-client "1.1.5" spdy "^3.4.1" strip-ansi "^3.0.0" supports-color "^5.1.0" @@ -4931,9 +5285,9 @@ webpack-sources@^1.0.1, webpack-sources@^1.1.0: source-list-map "^2.0.0" source-map "~0.6.1" -webpack@^4.16.0: - version "4.16.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.16.0.tgz#660dae90890e55b8ed17c6f9d17bebb01dab5b4c" +webpack@^4.16.3: + version "4.16.3" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.16.3.tgz#861be3176d81e7e3d71c66c8acc9bba35588b525" dependencies: "@webassemblyjs/ast" "1.5.13" "@webassemblyjs/helper-module-context" "1.5.13" @@ -4946,7 +5300,7 @@ webpack@^4.16.0: ajv-keywords "^3.1.0" chrome-trace-event "^1.0.0" enhanced-resolve "^4.1.0" - eslint-scope "^3.7.1" + eslint-scope "^4.0.0" json-parse-better-errors "^1.0.2" loader-runner "^2.3.0" loader-utils "^1.1.0" @@ -5051,6 +5405,10 @@ write-pkg@^3.1.0: sort-keys "^2.0.0" write-json-file "^2.2.0" +xregexp@4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-4.0.0.tgz#e698189de49dd2a18cc5687b05e17c8e43943020" + xtend@^4.0.0, xtend@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" @@ -5059,7 +5417,7 @@ y18n@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41" -y18n@^4.0.0: +"y18n@^3.2.1 || ^4.0.0", y18n@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" @@ -5071,6 +5429,12 @@ yallist@^3.0.0, yallist@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.2.tgz#8452b4bb7e83c7c188d8041c1a837c773d6d8bb9" +yargs-parser@^10.0.0, yargs-parser@^10.1.0: + version "10.1.0" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-10.1.0.tgz#7202265b89f7e9e9f2e5765e0fe735a905edbaa8" + dependencies: + camelcase "^4.1.0" + yargs-parser@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-7.0.0.tgz#8d0ac42f16ea55debd332caf4c4038b3e3f5dfd9" @@ -5106,7 +5470,7 @@ yargs@11.0.0: y18n "^3.2.1" yargs-parser "^9.0.2" -yargs@11.1.0, yargs@^11.1.0: +yargs@11.1.0: version "11.1.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-11.1.0.tgz#90b869934ed6e871115ea2ff58b03f4724ed2d77" dependencies: @@ -5123,6 +5487,23 @@ yargs@11.1.0, yargs@^11.1.0: y18n "^3.2.1" yargs-parser "^9.0.2" +yargs@^12.0.1: + version "12.0.1" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-12.0.1.tgz#6432e56123bb4e7c3562115401e98374060261c2" + dependencies: + cliui "^4.0.0" + decamelize "^2.0.0" + find-up "^3.0.0" + get-caller-file "^1.0.1" + os-locale "^2.0.0" + require-directory "^2.1.1" + require-main-filename "^1.0.1" + set-blocking "^2.0.0" + string-width "^2.0.0" + which-module "^2.0.0" + y18n "^3.2.1 || ^4.0.0" + yargs-parser "^10.1.0" + yargs@^8.0.2: version "8.0.2" resolved "https://registry.yarnpkg.com/yargs/-/yargs-8.0.2.tgz#6299a9055b1cefc969ff7e79c1d918dceb22c360"