| [e4c61dd] | 1 | // https://d3js.org/d3-dispatch/ v3.0.1 Copyright 2010-2021 Mike Bostock
|
|---|
| 2 | (function (global, factory) {
|
|---|
| 3 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|---|
| 4 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|---|
| 5 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
|
|---|
| 6 | }(this, (function (exports) { 'use strict';
|
|---|
| 7 |
|
|---|
| 8 | var noop = {value: () => {}};
|
|---|
| 9 |
|
|---|
| 10 | function dispatch() {
|
|---|
| 11 | for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
|
|---|
| 12 | if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
|
|---|
| 13 | _[t] = [];
|
|---|
| 14 | }
|
|---|
| 15 | return new Dispatch(_);
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | function Dispatch(_) {
|
|---|
| 19 | this._ = _;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | function parseTypenames(typenames, types) {
|
|---|
| 23 | return typenames.trim().split(/^|\s+/).map(function(t) {
|
|---|
| 24 | var name = "", i = t.indexOf(".");
|
|---|
| 25 | if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
|---|
| 26 | if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
|
|---|
| 27 | return {type: t, name: name};
|
|---|
| 28 | });
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | Dispatch.prototype = dispatch.prototype = {
|
|---|
| 32 | constructor: Dispatch,
|
|---|
| 33 | on: function(typename, callback) {
|
|---|
| 34 | var _ = this._,
|
|---|
| 35 | T = parseTypenames(typename + "", _),
|
|---|
| 36 | t,
|
|---|
| 37 | i = -1,
|
|---|
| 38 | n = T.length;
|
|---|
| 39 |
|
|---|
| 40 | // If no callback was specified, return the callback of the given type and name.
|
|---|
| 41 | if (arguments.length < 2) {
|
|---|
| 42 | while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
|
|---|
| 43 | return;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | // If a type was specified, set the callback for the given type and name.
|
|---|
| 47 | // Otherwise, if a null callback was specified, remove callbacks of the given name.
|
|---|
| 48 | if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
|
|---|
| 49 | while (++i < n) {
|
|---|
| 50 | if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
|
|---|
| 51 | else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | return this;
|
|---|
| 55 | },
|
|---|
| 56 | copy: function() {
|
|---|
| 57 | var copy = {}, _ = this._;
|
|---|
| 58 | for (var t in _) copy[t] = _[t].slice();
|
|---|
| 59 | return new Dispatch(copy);
|
|---|
| 60 | },
|
|---|
| 61 | call: function(type, that) {
|
|---|
| 62 | if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
|
|---|
| 63 | if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
|---|
| 64 | for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
|---|
| 65 | },
|
|---|
| 66 | apply: function(type, that, args) {
|
|---|
| 67 | if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
|---|
| 68 | for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
|---|
| 69 | }
|
|---|
| 70 | };
|
|---|
| 71 |
|
|---|
| 72 | function get(type, name) {
|
|---|
| 73 | for (var i = 0, n = type.length, c; i < n; ++i) {
|
|---|
| 74 | if ((c = type[i]).name === name) {
|
|---|
| 75 | return c.value;
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | function set(type, name, callback) {
|
|---|
| 81 | for (var i = 0, n = type.length; i < n; ++i) {
|
|---|
| 82 | if (type[i].name === name) {
|
|---|
| 83 | type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
|
|---|
| 84 | break;
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 | if (callback != null) type.push({name: name, value: callback});
|
|---|
| 88 | return type;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | exports.dispatch = dispatch;
|
|---|
| 92 |
|
|---|
| 93 | Object.defineProperty(exports, '__esModule', { value: true });
|
|---|
| 94 |
|
|---|
| 95 | })));
|
|---|