@d3fc/d3fc-element
Advanced tools
Comparing version 6.1.2 to 6.2.0
@@ -613,6 +613,20 @@ (function (factory) { | ||
customElements.define('d3fc-canvas', _default); | ||
customElements.define('d3fc-group', _default$1); | ||
customElements.define('d3fc-svg', Svg); | ||
var alreadyRegistered = []; | ||
var registerElement = function registerElement(name, element) { | ||
if (customElements.get(name)) { | ||
alreadyRegistered.push(name); | ||
} else { | ||
customElements.define(name, element); | ||
} | ||
}; | ||
registerElement('d3fc-canvas', _default); | ||
registerElement('d3fc-group', _default$1); | ||
registerElement('d3fc-svg', Svg); | ||
if (alreadyRegistered.length > 0) { | ||
console.warn("The d3fc components \"".concat(alreadyRegistered.join(', '), "\" is/are already registered on window. Be aware that this can create compatibility issues if different versions are used.")); | ||
} | ||
}))); |
@@ -1,1 +0,1 @@ | ||
(function(a){"function"==typeof define&&define.amd?define(a):a()})(function(){'use strict';function a(b){"@babel/helpers - typeof";return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},a(b)}function b(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function c(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function d(a,b,d){return b&&c(a.prototype,b),d&&c(a,d),a}function e(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&g(a,b)}function f(a){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},f(a)}function g(a,b){return g=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},g(a,b)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}function i(){return i=h()?Reflect.construct:function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&g(f,d.prototype),f},i.apply(null,arguments)}function j(a){return-1!==Function.toString.call(a).indexOf("[native code]")}function k(a){var b="function"==typeof Map?new Map:void 0;return k=function(a){function c(){return i(a,arguments,f(this).constructor)}if(null===a||!j(a))return a;if("function"!=typeof a)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof b){if(b.has(a))return b.get(a);b.set(a,c)}return c.prototype=Object.create(a.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),g(c,a)},k(a)}function l(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function m(a,b){return b&&("object"==typeof b||"function"==typeof b)?b:l(a)}function n(a){var b=h();return function(){var c,d=f(a);if(b){var e=f(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return m(this,c)}}function o(a){return r(a)||s(a)||t(a)||w()}function p(a){return q(a)||s(a)||t(a)||v()}function q(a){if(Array.isArray(a))return u(a)}function r(a){if(Array.isArray(a))return a}function s(a){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(a))return Array.from(a)}function t(a,b){if(a){if("string"==typeof a)return u(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?u(a,b):void 0}}function u(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function v(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function w(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var x=function(a){return a["__d3fc-elements__"]||{}},y=function(a,b){a["__d3fc-elements__"]=b},z=function(a){return delete a["__d3fc-elements__"]},A=function(a){return"D3FC-GROUP"===a.tagName?[a].concat(p(a.querySelectorAll("d3fc-canvas, d3fc-group, d3fc-svg"))):[a]},B=function(a){var b=x(a),c=b.width,d=b.height,e=a.useDevicePixelRatio&&null!=window.devicePixelRatio?window.devicePixelRatio:1,f=a.clientWidth*e,g=a.clientHeight*e,h=a.children[0];y(a,{pixelRatio:e,width:f,height:g,resized:f!==c||g!==d,child:h})};if("function"!=typeof CustomEvent)throw new Error("d3fc-element depends on CustomEvent. Make sure that you load a polyfill in older browsers. See README.");var C=function(a){var b=x(a),c=new CustomEvent("measure",{detail:b});a.dispatchEvent(c)},D=function(a){var b=x(a),c=new CustomEvent("draw",{detail:b});a.dispatchEvent(c)},E=function(a){var b=a.map(A).reduce(function(c,a){return c.concat(a)});b.forEach(B),b.forEach(C),b.forEach(D)},F=function(a){return x(a.ownerDocument).queue||[]},G=function(a,b){var c=x(a.ownerDocument),d=c.requestId;null==d&&(d=requestAnimationFrame(function(){var b=F(a);E(b),H(a)})),y(a.ownerDocument,{queue:b,requestId:d})},H=function(a){return z(a.ownerDocument)},I=function(a,b){var c=a;do if(c.parentNode===b)return!0;while(c=c.parentNode);return!1},J=function(a){var b=F(a),c=-1<b.indexOf(a);if(!c){var d=b.some(function(b){return I(a,b)});if(!d){var e=b.filter(function(b){return!I(b,a)});e.push(a),G(a,e)}}};if("function"!=typeof HTMLElement)throw new Error("d3fc-element depends on Custom Elements (v1). Make sure that you load a polyfill in older browsers. See README.");var K=function(a){null!=a.__measureListener__||(a.__measureListener__=function(b){return a.setMeasurements(b.detail)},a.addEventListener("measure",a.__measureListener__))},L=function(a){null==a.__measureListener__||(a.removeEventListener("measure",a.__measureListener__),a.__measureListener__=null)},M=function(a,c){return function(f){function g(){return b(this,g),h.apply(this,arguments)}e(g,f);var h=n(g);return d(g,[{key:"attributeChangedCallback",value:function(a){"use-device-pixel-ratio"===a?this.requestRedraw():void 0}},{key:"connectedCallback",value:function(){0===this.childNodes.length&&this.appendChild(a()),K(this)}},{key:"disconnectedCallback",value:function(){L(this)}},{key:"setMeasurements",value:function(a){var b=a.width,d=a.height,e=o(this.childNodes),f=e[0],g=e.slice(1);if(0<g.length)throw new Error("A d3fc-svg/canvas element must only contain a single svg/canvas element.");c(this,f,{width:b,height:d})}},{key:"requestRedraw",value:function(){J(this)}},{key:"useDevicePixelRatio",get:function(){return this.hasAttribute("use-device-pixel-ratio")&&"false"!==this.getAttribute("use-device-pixel-ratio")},set:function(a){a&&!this.useDevicePixelRatio?this.setAttribute("use-device-pixel-ratio",""):!a&&this.useDevicePixelRatio&&this.removeAttribute("use-device-pixel-ratio"),this.requestRedraw()}}],[{key:"observedAttributes",get:function(){return["use-device-pixel-ratio"]}}]),g}(k(HTMLElement))},N=function(a){function c(){return b(this,c),f.apply(this,arguments)}e(c,a);var f=n(c);return d(c,[{key:"setWebglViewport",get:function(){return this.hasAttribute("set-webgl-viewport")&&"false"!==this.getAttribute("set-webgl-viewport")},set:function(a){a&&!this.setWebglViewport?this.setAttribute("set-webgl-viewport",""):!a&&this.setWebglViewport&&this.removeAttribute("set-webgl-viewport"),this.requestRedraw()}}]),c}(M(function(){return document.createElement("canvas")},function(a,b,c){var d=c.width,e=c.height;if(b.setAttribute("width",d),b.setAttribute("height",e),a.setWebglViewport){var f=b.getContext("webgl");f.viewport(0,0,d,e)}})),O=function(a){a.autoResize?P(a):Q(a)},P=function(a){null!=a.__autoResizeListener__||(a.__autoResizeListener__=function(){return J(a)},addEventListener("resize",a.__autoResizeListener__))},Q=function(a){null==a.__autoResizeListener__||(removeEventListener("resize",a.__autoResizeListener__),a.__autoResizeListener__=null)},R=function(a){function c(){return b(this,c),f.apply(this,arguments)}e(c,a);var f=n(c);return d(c,[{key:"connectedCallback",value:function(){O(this)}},{key:"disconnectedCallback",value:function(){Q(this)}},{key:"requestRedraw",value:function(){J(this)}},{key:"attributeChangedCallback",value:function(a){"auto-resize"===a?O(this):void 0}},{key:"autoResize",get:function(){return this.hasAttribute("auto-resize")&&"false"!==this.getAttribute("auto-resize")},set:function(a){a&&!this.autoResize?this.setAttribute("auto-resize",""):!a&&this.autoResize&&this.removeAttribute("auto-resize"),O(this)}}],[{key:"observedAttributes",get:function(){return["auto-resize"]}}]),c}(k(HTMLElement)),S=M(function(){return document.createElementNS("http://www.w3.org/2000/svg","svg")},function(a,b,c){var d=c.width,e=c.height;b.setAttribute("viewBox","0 0 ".concat(d," ").concat(e))}),T="d3fc-canvas,d3fc-svg{position:relative;display:block}d3fc-canvas>canvas,d3fc-svg>svg{position:absolute;height:100%;width:100%}d3fc-svg>svg{overflow:visible}",U=document.createElement("style");if(U.setAttribute("type","text/css"),document.querySelector("head").appendChild(U),U.styleSheet?U.styleSheet.cssText+=T:U.textContent+=T,"object"!==("undefined"==typeof customElements?"undefined":a(customElements))||"function"!=typeof customElements.define)throw new Error("d3fc-element depends on Custom Elements (v1). Make sure that you load a polyfill in older browsers. See README.");customElements.define("d3fc-canvas",N),customElements.define("d3fc-group",R),customElements.define("d3fc-svg",S)}); | ||
(function(a){"function"==typeof define&&define.amd?define(a):a()})(function(){'use strict';function a(b){"@babel/helpers - typeof";return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},a(b)}function b(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function c(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function d(a,b,d){return b&&c(a.prototype,b),d&&c(a,d),a}function e(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&g(a,b)}function f(a){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},f(a)}function g(a,b){return g=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},g(a,b)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}function i(){return i=h()?Reflect.construct:function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&g(f,d.prototype),f},i.apply(null,arguments)}function j(a){return-1!==Function.toString.call(a).indexOf("[native code]")}function k(a){var b="function"==typeof Map?new Map:void 0;return k=function(a){function c(){return i(a,arguments,f(this).constructor)}if(null===a||!j(a))return a;if("function"!=typeof a)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof b){if(b.has(a))return b.get(a);b.set(a,c)}return c.prototype=Object.create(a.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),g(c,a)},k(a)}function l(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function m(a,b){return b&&("object"==typeof b||"function"==typeof b)?b:l(a)}function n(a){var b=h();return function(){var c,d=f(a);if(b){var e=f(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return m(this,c)}}function o(a){return r(a)||s(a)||t(a)||w()}function p(a){return q(a)||s(a)||t(a)||v()}function q(a){if(Array.isArray(a))return u(a)}function r(a){if(Array.isArray(a))return a}function s(a){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(a))return Array.from(a)}function t(a,b){if(a){if("string"==typeof a)return u(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?u(a,b):void 0}}function u(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function v(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function w(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var x=function(a){return a["__d3fc-elements__"]||{}},y=function(a,b){a["__d3fc-elements__"]=b},z=function(a){return delete a["__d3fc-elements__"]},A=function(a){return"D3FC-GROUP"===a.tagName?[a].concat(p(a.querySelectorAll("d3fc-canvas, d3fc-group, d3fc-svg"))):[a]},B=function(a){var b=x(a),c=b.width,d=b.height,e=a.useDevicePixelRatio&&null!=window.devicePixelRatio?window.devicePixelRatio:1,f=a.clientWidth*e,g=a.clientHeight*e,h=a.children[0];y(a,{pixelRatio:e,width:f,height:g,resized:f!==c||g!==d,child:h})};if("function"!=typeof CustomEvent)throw new Error("d3fc-element depends on CustomEvent. Make sure that you load a polyfill in older browsers. See README.");var C=function(a){var b=x(a),c=new CustomEvent("measure",{detail:b});a.dispatchEvent(c)},D=function(a){var b=x(a),c=new CustomEvent("draw",{detail:b});a.dispatchEvent(c)},E=function(a){var b=a.map(A).reduce(function(c,a){return c.concat(a)});b.forEach(B),b.forEach(C),b.forEach(D)},F=function(a){return x(a.ownerDocument).queue||[]},G=function(a,b){var c=x(a.ownerDocument),d=c.requestId;null==d&&(d=requestAnimationFrame(function(){var b=F(a);E(b),H(a)})),y(a.ownerDocument,{queue:b,requestId:d})},H=function(a){return z(a.ownerDocument)},I=function(a,b){var c=a;do if(c.parentNode===b)return!0;while(c=c.parentNode);return!1},J=function(a){var b=F(a),c=-1<b.indexOf(a);if(!c){var d=b.some(function(b){return I(a,b)});if(!d){var e=b.filter(function(b){return!I(b,a)});e.push(a),G(a,e)}}};if("function"!=typeof HTMLElement)throw new Error("d3fc-element depends on Custom Elements (v1). Make sure that you load a polyfill in older browsers. See README.");var K=function(a){null!=a.__measureListener__||(a.__measureListener__=function(b){return a.setMeasurements(b.detail)},a.addEventListener("measure",a.__measureListener__))},L=function(a){null==a.__measureListener__||(a.removeEventListener("measure",a.__measureListener__),a.__measureListener__=null)},M=function(a,c){return function(f){function g(){return b(this,g),h.apply(this,arguments)}e(g,f);var h=n(g);return d(g,[{key:"attributeChangedCallback",value:function(a){"use-device-pixel-ratio"===a?this.requestRedraw():void 0}},{key:"connectedCallback",value:function(){0===this.childNodes.length&&this.appendChild(a()),K(this)}},{key:"disconnectedCallback",value:function(){L(this)}},{key:"setMeasurements",value:function(a){var b=a.width,d=a.height,e=o(this.childNodes),f=e[0],g=e.slice(1);if(0<g.length)throw new Error("A d3fc-svg/canvas element must only contain a single svg/canvas element.");c(this,f,{width:b,height:d})}},{key:"requestRedraw",value:function(){J(this)}},{key:"useDevicePixelRatio",get:function(){return this.hasAttribute("use-device-pixel-ratio")&&"false"!==this.getAttribute("use-device-pixel-ratio")},set:function(a){a&&!this.useDevicePixelRatio?this.setAttribute("use-device-pixel-ratio",""):!a&&this.useDevicePixelRatio&&this.removeAttribute("use-device-pixel-ratio"),this.requestRedraw()}}],[{key:"observedAttributes",get:function(){return["use-device-pixel-ratio"]}}]),g}(k(HTMLElement))},N=function(a){function c(){return b(this,c),f.apply(this,arguments)}e(c,a);var f=n(c);return d(c,[{key:"setWebglViewport",get:function(){return this.hasAttribute("set-webgl-viewport")&&"false"!==this.getAttribute("set-webgl-viewport")},set:function(a){a&&!this.setWebglViewport?this.setAttribute("set-webgl-viewport",""):!a&&this.setWebglViewport&&this.removeAttribute("set-webgl-viewport"),this.requestRedraw()}}]),c}(M(function(){return document.createElement("canvas")},function(a,b,c){var d=c.width,e=c.height;if(b.setAttribute("width",d),b.setAttribute("height",e),a.setWebglViewport){var f=b.getContext("webgl");f.viewport(0,0,d,e)}})),O=function(a){a.autoResize?P(a):Q(a)},P=function(a){null!=a.__autoResizeListener__||(a.__autoResizeListener__=function(){return J(a)},addEventListener("resize",a.__autoResizeListener__))},Q=function(a){null==a.__autoResizeListener__||(removeEventListener("resize",a.__autoResizeListener__),a.__autoResizeListener__=null)},R=function(a){function c(){return b(this,c),f.apply(this,arguments)}e(c,a);var f=n(c);return d(c,[{key:"connectedCallback",value:function(){O(this)}},{key:"disconnectedCallback",value:function(){Q(this)}},{key:"requestRedraw",value:function(){J(this)}},{key:"attributeChangedCallback",value:function(a){"auto-resize"===a?O(this):void 0}},{key:"autoResize",get:function(){return this.hasAttribute("auto-resize")&&"false"!==this.getAttribute("auto-resize")},set:function(a){a&&!this.autoResize?this.setAttribute("auto-resize",""):!a&&this.autoResize&&this.removeAttribute("auto-resize"),O(this)}}],[{key:"observedAttributes",get:function(){return["auto-resize"]}}]),c}(k(HTMLElement)),S=M(function(){return document.createElementNS("http://www.w3.org/2000/svg","svg")},function(a,b,c){var d=c.width,e=c.height;b.setAttribute("viewBox","0 0 ".concat(d," ").concat(e))}),T="d3fc-canvas,d3fc-svg{position:relative;display:block}d3fc-canvas>canvas,d3fc-svg>svg{position:absolute;height:100%;width:100%}d3fc-svg>svg{overflow:visible}",U=document.createElement("style");if(U.setAttribute("type","text/css"),document.querySelector("head").appendChild(U),U.styleSheet?U.styleSheet.cssText+=T:U.textContent+=T,"object"!==("undefined"==typeof customElements?"undefined":a(customElements))||"function"!=typeof customElements.define)throw new Error("d3fc-element depends on Custom Elements (v1). Make sure that you load a polyfill in older browsers. See README.");var V=[],W=function(a,b){customElements.get(a)?V.push(a):customElements.define(a,b)};W("d3fc-canvas",N),W("d3fc-group",R),W("d3fc-svg",S),0<V.length&&console.warn("The d3fc components \"".concat(V.join(", "),"\" is/are already registered on window. Be aware that this can create compatibility issues if different versions are used."))}); |
@@ -6,2 +6,13 @@ # Change Log | ||
# [6.2.0](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-element@6.1.2...@d3fc/d3fc-element@6.2.0) (2021-08-02) | ||
### Features | ||
* prevent registering components multiple times ([43e35b7](https://github.com/d3fc/d3fc/commit/43e35b7)) | ||
## [6.1.2](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-element@6.1.1...@d3fc/d3fc-element@6.1.2) (2020-09-23) | ||
@@ -8,0 +19,0 @@ |
32
index.js
@@ -7,8 +7,30 @@ /* globals customElements */ | ||
if (typeof customElements !== 'object' || typeof customElements.define !== 'function') { | ||
throw new Error('d3fc-element depends on Custom Elements (v1). Make sure that you load a polyfill in older browsers. See README.'); | ||
if ( | ||
typeof customElements !== 'object' || | ||
typeof customElements.define !== 'function' | ||
) { | ||
throw new Error( | ||
'd3fc-element depends on Custom Elements (v1). Make sure that you load a polyfill in older browsers. See README.' | ||
); | ||
} | ||
customElements.define('d3fc-canvas', Canvas); | ||
customElements.define('d3fc-group', Group); | ||
customElements.define('d3fc-svg', Svg); | ||
const alreadyRegistered = []; | ||
const registerElement = (name, element) => { | ||
if (customElements.get(name)) { | ||
alreadyRegistered.push(name); | ||
} else { | ||
customElements.define(name, element); | ||
} | ||
}; | ||
registerElement('d3fc-canvas', Canvas); | ||
registerElement('d3fc-group', Group); | ||
registerElement('d3fc-svg', Svg); | ||
if (alreadyRegistered.length > 0) { | ||
console.warn( | ||
`The d3fc components "${alreadyRegistered.join( | ||
', ' | ||
)}" is/are already registered on window. Be aware that this can create compatibility issues if different versions are used.` | ||
); | ||
} |
{ | ||
"name": "@d3fc/d3fc-element", | ||
"version": "6.1.2", | ||
"version": "6.2.0", | ||
"description": "Custom HTML elements that make it easier to create responsive visualisations that integrate easily with other UI frameworks (e.g. React, Angular)", | ||
@@ -25,3 +25,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "a7f1db4d1fd44f696c7ead067284851953c18e6c" | ||
"gitHead": "4ca9aaf85f2a42b51787d3307fa5ec01c14abbfc" | ||
} |
65321
924