@internetarchive/histogram-date-range 0.1.1-alpha → 0.1.2-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ import { x, b } from './lit-html-1d707ff6.js';
2
+
3
+ /**
4
+ * @license
5
+ * Copyright 2019 Google LLC
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ */
8
+ const t=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,e=Symbol(),n=new Map;class s{constructor(t,n){if(this._$cssResult$=!0,n!==e)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t;}get styleSheet(){let e=n.get(this.cssText);return t&&void 0===e&&(n.set(this.cssText,e=new CSSStyleSheet),e.replaceSync(this.cssText)),e}toString(){return this.cssText}}const o=t=>new s("string"==typeof t?t:t+"",e),r=(t,...n)=>{const o=1===t.length?t[0]:n.reduce(((e,n,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[s+1]),t[0]);return new s(o,e)},i=(e,n)=>{t?e.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((t=>{const n=document.createElement("style"),s=window.litNonce;void 0!==s&&n.setAttribute("nonce",s),n.textContent=t.cssText,e.appendChild(n);}));},S=t?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return o(e)})(t):t;
9
+
10
+ /**
11
+ * @license
12
+ * Copyright 2017 Google LLC
13
+ * SPDX-License-Identifier: BSD-3-Clause
14
+ */var s$1;const e$1=window.trustedTypes,r$1=e$1?e$1.emptyScript:"",h=window.reactiveElementPolyfillSupport,o$1={toAttribute(t,i){switch(i){case Boolean:t=t?r$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,i){let s=t;switch(i){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t);}catch(t){s=null;}}return s}},n$1=(t,i)=>i!==t&&(i==i||t==t),l={attribute:!0,type:String,converter:o$1,reflect:!1,hasChanged:n$1};class a extends HTMLElement{constructor(){super(),this._$Et=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Ei=null,this.o();}static addInitializer(t){var i;null!==(i=this.l)&&void 0!==i||(this.l=[]),this.l.push(t);}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((i,s)=>{const e=this._$Eh(s,i);void 0!==e&&(this._$Eu.set(e,s),t.push(e));})),t}static createProperty(t,i=l){if(i.state&&(i.attribute=!1),this.finalize(),this.elementProperties.set(t,i),!i.noAccessor&&!this.prototype.hasOwnProperty(t)){const s="symbol"==typeof t?Symbol():"__"+t,e=this.getPropertyDescriptor(t,s,i);void 0!==e&&Object.defineProperty(this.prototype,t,e);}}static getPropertyDescriptor(t,i,s){return {get(){return this[i]},set(e){const r=this[t];this[i]=e,this.requestUpdate(t,r,s);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||l}static finalize(){if(this.hasOwnProperty("finalized"))return !1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Eu=new Map,this.hasOwnProperty("properties")){const t=this.properties,i=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const s of i)this.createProperty(s,t[s]);}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(i){const s=[];if(Array.isArray(i)){const e=new Set(i.flat(1/0).reverse());for(const i of e)s.unshift(S(i));}else void 0!==i&&s.push(S(i));return s}static _$Eh(t,i){const s=i.attribute;return !1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}o(){var t;this._$Ep=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Em(),this.requestUpdate(),null===(t=this.constructor.l)||void 0===t||t.forEach((t=>t(this)));}addController(t){var i,s;(null!==(i=this._$Eg)&&void 0!==i?i:this._$Eg=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(s=t.hostConnected)||void 0===s||s.call(t));}removeController(t){var i;null===(i=this._$Eg)||void 0===i||i.splice(this._$Eg.indexOf(t)>>>0,1);}_$Em(){this.constructor.elementProperties.forEach(((t,i)=>{this.hasOwnProperty(i)&&(this._$Et.set(i,this[i]),delete this[i]);}));}createRenderRoot(){var t;const s=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return i(s,this.constructor.elementStyles),s}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostConnected)||void 0===i?void 0:i.call(t)}));}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostDisconnected)||void 0===i?void 0:i.call(t)}));}attributeChangedCallback(t,i,s){this._$AK(t,s);}_$ES(t,i,s=l){var e,r;const h=this.constructor._$Eh(t,s);if(void 0!==h&&!0===s.reflect){const n=(null!==(r=null===(e=s.converter)||void 0===e?void 0:e.toAttribute)&&void 0!==r?r:o$1.toAttribute)(i,s.type);this._$Ei=t,null==n?this.removeAttribute(h):this.setAttribute(h,n),this._$Ei=null;}}_$AK(t,i){var s,e,r;const h=this.constructor,n=h._$Eu.get(t);if(void 0!==n&&this._$Ei!==n){const t=h.getPropertyOptions(n),l=t.converter,a=null!==(r=null!==(e=null===(s=l)||void 0===s?void 0:s.fromAttribute)&&void 0!==e?e:"function"==typeof l?l:null)&&void 0!==r?r:o$1.fromAttribute;this._$Ei=n,this[n]=a(i,t.type),this._$Ei=null;}}requestUpdate(t,i,s){let e=!0;void 0!==t&&(((s=s||this.constructor.getPropertyOptions(t)).hasChanged||n$1)(this[t],i)?(this._$AL.has(t)||this._$AL.set(t,i),!0===s.reflect&&this._$Ei!==t&&(void 0===this._$E_&&(this._$E_=new Map),this._$E_.set(t,s))):e=!1),!this.isUpdatePending&&e&&(this._$Ep=this._$EC());}async _$EC(){this.isUpdatePending=!0;try{await this._$Ep;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Et&&(this._$Et.forEach(((t,i)=>this[i]=t)),this._$Et=void 0);let i=!1;const s=this._$AL;try{i=this.shouldUpdate(s),i?(this.willUpdate(s),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostUpdate)||void 0===i?void 0:i.call(t)})),this.update(s)):this._$EU();}catch(t){throw i=!1,this._$EU(),t}i&&this._$AE(s);}willUpdate(t){}_$AE(t){var i;null===(i=this._$Eg)||void 0===i||i.forEach((t=>{var i;return null===(i=t.hostUpdated)||void 0===i?void 0:i.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t);}_$EU(){this._$AL=new Map,this.isUpdatePending=!1;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Ep}shouldUpdate(t){return !0}update(t){void 0!==this._$E_&&(this._$E_.forEach(((t,i)=>this._$ES(i,this[i],t))),this._$E_=void 0),this._$EU();}updated(t){}firstUpdated(t){}}a.finalized=!0,a.elementProperties=new Map,a.elementStyles=[],a.shadowRootOptions={mode:"open"},null==h||h({ReactiveElement:a}),(null!==(s$1=globalThis.reactiveElementVersions)&&void 0!==s$1?s$1:globalThis.reactiveElementVersions=[]).push("1.1.2");
15
+
16
+ /**
17
+ * @license
18
+ * Copyright 2017 Google LLC
19
+ * SPDX-License-Identifier: BSD-3-Clause
20
+ */var l$1,o$2;class s$2 extends a{constructor(){super(...arguments),this.renderOptions={host:this},this._$Dt=void 0;}createRenderRoot(){var t,e;const i=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=i.firstChild),i}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Dt=x(i,this.renderRoot,this.renderOptions);}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!0);}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!1);}render(){return b}}s$2.finalized=!0,s$2._$litElement$=!0,null===(l$1=globalThis.litElementHydrateSupport)||void 0===l$1||l$1.call(globalThis,{LitElement:s$2});const n$2=globalThis.litElementPolyfillSupport;null==n$2||n$2({LitElement:s$2});(null!==(o$2=globalThis.litElementVersions)&&void 0!==o$2?o$2:globalThis.litElementVersions=[]).push("3.1.1");
21
+
22
+ export { r, s$2 as s };
@@ -21,7 +21,7 @@ var DATE = 'date';
21
21
  var FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ';
22
22
  var INVALID_DATE_STRING = 'Invalid Date'; // regex
23
23
 
24
- var REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d+)?$/;
24
+ var REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/;
25
25
  var REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
26
26
 
27
27
  // English [en]
@@ -372,10 +372,10 @@ var Dayjs = /*#__PURE__*/function () {
372
372
  _proto.format = function format(formatStr) {
373
373
  var _this3 = this;
374
374
 
375
- if (!this.isValid()) return INVALID_DATE_STRING;
375
+ var locale = this.$locale();
376
+ if (!this.isValid()) return locale.invalidDate || INVALID_DATE_STRING;
376
377
  var str = formatStr || FORMAT_DEFAULT;
377
378
  var zoneStr = Utils.z(this);
378
- var locale = this.$locale();
379
379
  var $H = this.$H,
380
380
  $m = this.$m,
381
381
  $M = this.$M;
@@ -32,14 +32,20 @@ var match1to2 = /\d\d?/; // 0 - 99
32
32
 
33
33
  var matchSigned = /[+-]?\d+/; // -inf - inf
34
34
 
35
- var matchOffset = /[+-]\d\d:?(\d\d)?/; // +00:00 -00:00 +0000 or -0000 +00
35
+ var matchOffset = /[+-]\d\d:?(\d\d)?|Z/; // +00:00 -00:00 +0000 or -0000 +00 or Z
36
36
 
37
- var matchWord = /\d*[^\s\d-:/()]+/; // Word
37
+ var matchWord = /\d*[^\s\d-_:/()]+/; // Word
38
38
 
39
- var locale;
39
+ var locale = {};
40
+
41
+ var parseTwoDigitYear = function parseTwoDigitYear(input) {
42
+ input = +input;
43
+ return input + (input > 68 ? 1900 : 2000);
44
+ };
40
45
 
41
46
  function offsetFromString(string) {
42
47
  if (!string) return 0;
48
+ if (string === 'Z') return 0;
43
49
  var parts = string.match(/([+-]|\d\d)/g);
44
50
  var minutes = +(parts[1] * 60) + (+parts[2] || 0);
45
51
  return minutes === 0 ? 0 : parts[0] === '+' ? -minutes : minutes; // eslint-disable-line no-nested-ternary
@@ -149,8 +155,7 @@ var expressions = {
149
155
  }],
150
156
  Y: [matchSigned, addInput('year')],
151
157
  YY: [match2, function (input) {
152
- input = +input;
153
- this.year = input + (input > 68 ? 1900 : 2000);
158
+ this.year = parseTwoDigitYear(input);
154
159
  }],
155
160
  YYYY: [match4, addInput('year')],
156
161
  Z: zoneExpressions,
@@ -226,6 +231,7 @@ function makeParser(format) {
226
231
 
227
232
  var parseFormattedInput = function parseFormattedInput(input, format, utc) {
228
233
  try {
234
+ if (['x', 'X'].indexOf(format) > -1) return new Date((format === 'X' ? 1000 : 1) * input);
229
235
  var parser = makeParser(format);
230
236
 
231
237
  var _parser2 = parser(input),
@@ -268,6 +274,11 @@ var parseFormattedInput = function parseFormattedInput(input, format, utc) {
268
274
 
269
275
  var __pika_web_default_export_for_treeshaking__ = (function (o, C, d) {
270
276
  d.p.customParseFormat = true;
277
+
278
+ if (o && o.parseTwoDigitYear) {
279
+ parseTwoDigitYear = o.parseTwoDigitYear;
280
+ }
281
+
271
282
  var proto = C.prototype;
272
283
  var oldParse = proto.parse;
273
284
 
@@ -288,20 +299,24 @@ var __pika_web_default_export_for_treeshaking__ = (function (o, C, d) {
288
299
  pl = args[2];
289
300
  }
290
301
 
291
- if (!isStrictWithoutLocale) {
292
- locale = pl ? d.Ls[pl] : this.$locale();
302
+ locale = this.$locale();
303
+
304
+ if (!isStrictWithoutLocale && pl) {
305
+ locale = d.Ls[pl];
293
306
  }
294
307
 
295
308
  this.$d = parseFormattedInput(date, format, utc);
296
309
  this.init();
297
- if (pl && pl !== true) this.$L = this.locale(pl).$L;
310
+ if (pl && pl !== true) this.$L = this.locale(pl).$L; // use != to treat
311
+ // input number 1410715640579 and format string '1410715640579' equal
312
+ // eslint-disable-next-line eqeqeq
298
313
 
299
- if (isStrict && date !== this.format(format)) {
314
+ if (isStrict && date != this.format(format)) {
300
315
  this.$d = new Date('');
301
316
  } // reset global locale to make parallel unit test
302
317
 
303
318
 
304
- locale = undefined;
319
+ locale = {};
305
320
  } else if (format instanceof Array) {
306
321
  var len = format.length;
307
322
 
@@ -1,4 +1,4 @@
1
- import { b, w } from '../../common/lit-html-bb3fcd20.js';
1
+ import { b, w } from '../../common/lit-html-1d707ff6.js';
2
2
 
3
3
  /**
4
4
  * @license
@@ -1,23 +1,2 @@
1
- import { x, b } from './common/lit-html-bb3fcd20.js';
2
- export { $ as html, w as nothing, y as svg } from './common/lit-html-bb3fcd20.js';
3
-
4
- /**
5
- * @license
6
- * Copyright 2019 Google LLC
7
- * SPDX-License-Identifier: BSD-3-Clause
8
- */
9
- const t=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,e=Symbol(),n=new Map;class s{constructor(t,n){if(this._$cssResult$=!0,n!==e)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t;}get styleSheet(){let e=n.get(this.cssText);return t&&void 0===e&&(n.set(this.cssText,e=new CSSStyleSheet),e.replaceSync(this.cssText)),e}toString(){return this.cssText}}const o=t=>new s("string"==typeof t?t:t+"",e),r=(t,...n)=>{const o=1===t.length?t[0]:n.reduce(((e,n,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[s+1]),t[0]);return new s(o,e)},i=(e,n)=>{t?e.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((t=>{const n=document.createElement("style"),s=window.litNonce;void 0!==s&&n.setAttribute("nonce",s),n.textContent=t.cssText,e.appendChild(n);}));},S=t?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return o(e)})(t):t;
10
-
11
- /**
12
- * @license
13
- * Copyright 2017 Google LLC
14
- * SPDX-License-Identifier: BSD-3-Clause
15
- */var s$1;const e$1=window.trustedTypes,r$1=e$1?e$1.emptyScript:"",h=window.reactiveElementPolyfillSupport,o$1={toAttribute(t,i){switch(i){case Boolean:t=t?r$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,i){let s=t;switch(i){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t);}catch(t){s=null;}}return s}},n$1=(t,i)=>i!==t&&(i==i||t==t),l={attribute:!0,type:String,converter:o$1,reflect:!1,hasChanged:n$1};class a extends HTMLElement{constructor(){super(),this._$Et=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Ei=null,this.o();}static addInitializer(t){var i;null!==(i=this.l)&&void 0!==i||(this.l=[]),this.l.push(t);}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((i,s)=>{const e=this._$Eh(s,i);void 0!==e&&(this._$Eu.set(e,s),t.push(e));})),t}static createProperty(t,i=l){if(i.state&&(i.attribute=!1),this.finalize(),this.elementProperties.set(t,i),!i.noAccessor&&!this.prototype.hasOwnProperty(t)){const s="symbol"==typeof t?Symbol():"__"+t,e=this.getPropertyDescriptor(t,s,i);void 0!==e&&Object.defineProperty(this.prototype,t,e);}}static getPropertyDescriptor(t,i,s){return {get(){return this[i]},set(e){const r=this[t];this[i]=e,this.requestUpdate(t,r,s);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||l}static finalize(){if(this.hasOwnProperty("finalized"))return !1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Eu=new Map,this.hasOwnProperty("properties")){const t=this.properties,i=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const s of i)this.createProperty(s,t[s]);}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(i){const s=[];if(Array.isArray(i)){const e=new Set(i.flat(1/0).reverse());for(const i of e)s.unshift(S(i));}else void 0!==i&&s.push(S(i));return s}static _$Eh(t,i){const s=i.attribute;return !1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}o(){var t;this._$Ep=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Em(),this.requestUpdate(),null===(t=this.constructor.l)||void 0===t||t.forEach((t=>t(this)));}addController(t){var i,s;(null!==(i=this._$Eg)&&void 0!==i?i:this._$Eg=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(s=t.hostConnected)||void 0===s||s.call(t));}removeController(t){var i;null===(i=this._$Eg)||void 0===i||i.splice(this._$Eg.indexOf(t)>>>0,1);}_$Em(){this.constructor.elementProperties.forEach(((t,i)=>{this.hasOwnProperty(i)&&(this._$Et.set(i,this[i]),delete this[i]);}));}createRenderRoot(){var t;const s=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return i(s,this.constructor.elementStyles),s}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostConnected)||void 0===i?void 0:i.call(t)}));}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostDisconnected)||void 0===i?void 0:i.call(t)}));}attributeChangedCallback(t,i,s){this._$AK(t,s);}_$ES(t,i,s=l){var e,r;const h=this.constructor._$Eh(t,s);if(void 0!==h&&!0===s.reflect){const n=(null!==(r=null===(e=s.converter)||void 0===e?void 0:e.toAttribute)&&void 0!==r?r:o$1.toAttribute)(i,s.type);this._$Ei=t,null==n?this.removeAttribute(h):this.setAttribute(h,n),this._$Ei=null;}}_$AK(t,i){var s,e,r;const h=this.constructor,n=h._$Eu.get(t);if(void 0!==n&&this._$Ei!==n){const t=h.getPropertyOptions(n),l=t.converter,a=null!==(r=null!==(e=null===(s=l)||void 0===s?void 0:s.fromAttribute)&&void 0!==e?e:"function"==typeof l?l:null)&&void 0!==r?r:o$1.fromAttribute;this._$Ei=n,this[n]=a(i,t.type),this._$Ei=null;}}requestUpdate(t,i,s){let e=!0;void 0!==t&&(((s=s||this.constructor.getPropertyOptions(t)).hasChanged||n$1)(this[t],i)?(this._$AL.has(t)||this._$AL.set(t,i),!0===s.reflect&&this._$Ei!==t&&(void 0===this._$E_&&(this._$E_=new Map),this._$E_.set(t,s))):e=!1),!this.isUpdatePending&&e&&(this._$Ep=this._$EC());}async _$EC(){this.isUpdatePending=!0;try{await this._$Ep;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Et&&(this._$Et.forEach(((t,i)=>this[i]=t)),this._$Et=void 0);let i=!1;const s=this._$AL;try{i=this.shouldUpdate(s),i?(this.willUpdate(s),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostUpdate)||void 0===i?void 0:i.call(t)})),this.update(s)):this._$EU();}catch(t){throw i=!1,this._$EU(),t}i&&this._$AE(s);}willUpdate(t){}_$AE(t){var i;null===(i=this._$Eg)||void 0===i||i.forEach((t=>{var i;return null===(i=t.hostUpdated)||void 0===i?void 0:i.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t);}_$EU(){this._$AL=new Map,this.isUpdatePending=!1;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Ep}shouldUpdate(t){return !0}update(t){void 0!==this._$E_&&(this._$E_.forEach(((t,i)=>this._$ES(i,this[i],t))),this._$E_=void 0),this._$EU();}updated(t){}firstUpdated(t){}}a.finalized=!0,a.elementProperties=new Map,a.elementStyles=[],a.shadowRootOptions={mode:"open"},null==h||h({ReactiveElement:a}),(null!==(s$1=globalThis.reactiveElementVersions)&&void 0!==s$1?s$1:globalThis.reactiveElementVersions=[]).push("1.1.2");
16
-
17
- /**
18
- * @license
19
- * Copyright 2017 Google LLC
20
- * SPDX-License-Identifier: BSD-3-Clause
21
- */var l$1,o$2;class s$2 extends a{constructor(){super(...arguments),this.renderOptions={host:this},this._$Dt=void 0;}createRenderRoot(){var t,e;const i=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=i.firstChild),i}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Dt=x(i,this.renderRoot,this.renderOptions);}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!0);}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!1);}render(){return b}}s$2.finalized=!0,s$2._$litElement$=!0,null===(l$1=globalThis.litElementHydrateSupport)||void 0===l$1||l$1.call(globalThis,{LitElement:s$2});const n$2=globalThis.litElementPolyfillSupport;null==n$2||n$2({LitElement:s$2});(null!==(o$2=globalThis.litElementVersions)&&void 0!==o$2?o$2:globalThis.litElementVersions=[]).push("3.1.1");
22
-
23
- export { s$2 as LitElement, r as css };
1
+ export { s as LitElement, r as css } from './common/lit-element-3254fb50.js';
2
+ export { $ as html, w as nothing, y as svg } from './common/lit-html-1d707ff6.js';
@@ -120,7 +120,7 @@
120
120
  });
121
121
  </script>
122
122
 
123
- <!-- <div class="container">
123
+ <div class="container">
124
124
  <div class="description">
125
125
  single bin
126
126
  </div>
@@ -131,7 +131,7 @@
131
131
  <div class="container">
132
132
  <div class="description">empty data</div>
133
133
  <histogram-date-range missingDataMessage="no data..."></histoghistogram-date-range>
134
- </div> -->
134
+ </div>
135
135
 
136
136
  </body>
137
137
  </html>
@@ -146,6 +146,12 @@ export let HistogramDateRange = class extends LitElement {
146
146
  }
147
147
  return this.bins.length;
148
148
  }
149
+ get histogramLeftEdgeX() {
150
+ return this.sliderWidth;
151
+ }
152
+ get histogramRightEdgeX() {
153
+ return this.width - this.sliderWidth;
154
+ }
149
155
  get loading() {
150
156
  return this._isLoading;
151
157
  }
@@ -161,10 +167,11 @@ export let HistogramDateRange = class extends LitElement {
161
167
  this._minSelectedDate = rawDate;
162
168
  return;
163
169
  }
164
- let ms = this.getMSFromString(rawDate);
165
- if (!Number.isNaN(ms)) {
166
- ms = Math.min(ms, this.getMSFromString(this._maxSelectedDate));
167
- this._minSelectedDate = this.formatDate(ms);
170
+ const proposedDateMS = this.getMSFromString(rawDate);
171
+ const isValidDate = !Number.isNaN(proposedDateMS);
172
+ const isNotTooRecent = proposedDateMS <= this.getMSFromString(this.maxSelectedDate);
173
+ if (isValidDate && isNotTooRecent) {
174
+ this._minSelectedDate = this.formatDate(proposedDateMS);
168
175
  }
169
176
  this.requestUpdate();
170
177
  }
@@ -176,10 +183,11 @@ export let HistogramDateRange = class extends LitElement {
176
183
  this._maxSelectedDate = rawDate;
177
184
  return;
178
185
  }
179
- let ms = this.getMSFromString(rawDate);
180
- if (!Number.isNaN(ms)) {
181
- ms = Math.max(this.getMSFromString(this._minSelectedDate), ms);
182
- this._maxSelectedDate = this.formatDate(ms);
186
+ const proposedDateMS = this.getMSFromString(rawDate);
187
+ const isValidDate = !Number.isNaN(proposedDateMS);
188
+ const isNotTooOld = proposedDateMS >= this.getMSFromString(this.minSelectedDate);
189
+ if (isValidDate && isNotTooOld) {
190
+ this._maxSelectedDate = this.formatDate(proposedDateMS);
183
191
  }
184
192
  this.requestUpdate();
185
193
  }
@@ -215,16 +223,16 @@ export let HistogramDateRange = class extends LitElement {
215
223
  this._tooltipVisible = false;
216
224
  }
217
225
  validMinSliderX(newX) {
218
- if (Number.isNaN(newX)) {
219
- return this.sliderWidth;
220
- }
221
- return this.clamp(newX, this.sliderWidth, this.translateDateToPosition(this.maxSelectedDate));
226
+ const rightLimit = Math.min(this.translateDateToPosition(this.maxSelectedDate), this.histogramRightEdgeX);
227
+ newX = this.clamp(newX, this.histogramLeftEdgeX, rightLimit);
228
+ const isInvalid = Number.isNaN(newX) || rightLimit < this.histogramLeftEdgeX;
229
+ return isInvalid ? this.histogramLeftEdgeX : newX;
222
230
  }
223
231
  validMaxSliderX(newX) {
224
- if (Number.isNaN(newX)) {
225
- return this.width - this.sliderWidth;
226
- }
227
- return this.clamp(newX, this.translateDateToPosition(this.minSelectedDate), this.width - this.sliderWidth);
232
+ const leftLimit = Math.max(this.histogramLeftEdgeX, this.translateDateToPosition(this.minSelectedDate));
233
+ newX = this.clamp(newX, leftLimit, this.histogramRightEdgeX);
234
+ const isInvalid = Number.isNaN(newX) || leftLimit > this.histogramRightEdgeX;
235
+ return isInvalid ? this.histogramRightEdgeX : newX;
228
236
  }
229
237
  addListeners() {
230
238
  window.addEventListener("pointermove", this.move);
@@ -310,8 +318,9 @@ export let HistogramDateRange = class extends LitElement {
310
318
  }
311
319
  handleBarClick(e) {
312
320
  const dataset = e.currentTarget.dataset;
313
- const distanceFromMinSlider = this.getMSFromString(dataset.binStart) - this.getMSFromString(this.minSelectedDate);
314
- const distanceFromMaxSlider = this.getMSFromString(this.maxSelectedDate) - this.getMSFromString(dataset.binEnd);
321
+ const clickPosition = (this.getMSFromString(dataset.binStart) + this.getMSFromString(dataset.binEnd)) / 2;
322
+ const distanceFromMinSlider = Math.abs(clickPosition - this.getMSFromString(this.minSelectedDate));
323
+ const distanceFromMaxSlider = Math.abs(clickPosition - this.getMSFromString(this.maxSelectedDate));
315
324
  if (distanceFromMinSlider < distanceFromMaxSlider) {
316
325
  this.minSelectedDate = dataset.binStart;
317
326
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/histogram-date-range",
3
- "version": "0.1.1-alpha",
3
+ "version": "0.1.2-alpha",
4
4
  "description": "Internet Archive histogram date range picker",
5
5
  "license": "AGPL-3.0-only",
6
6
  "main": "dist/index.js",
@@ -20,26 +20,27 @@
20
20
  "test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\""
21
21
  },
22
22
  "dependencies": {
23
- "dayjs": "^1.9.7",
23
+ "dayjs": "^1.10.7",
24
24
  "lit": "^2.1.1"
25
25
  },
26
26
  "devDependencies": {
27
- "@internetarchive/ia-activity-indicator": "^0.0.1",
28
- "@open-wc/eslint-config": "^4.2.0",
29
- "@open-wc/testing": "^2.0.0",
30
- "@typescript-eslint/eslint-plugin": "^2.20.0",
31
- "@typescript-eslint/parser": "^2.20.0",
32
- "@web/dev-server": "^0.1.1",
33
- "@web/test-runner": "^0.11.5",
34
- "concurrently": "^5.3.0",
35
- "eslint": "^6.1.0",
36
- "eslint-config-prettier": "^6.11.0",
37
- "husky": "^1.0.0",
38
- "lint-staged": "^10.0.0",
39
- "prettier": "^2.0.4",
40
- "snowpack": "^3.0.11",
41
- "tslib": "^2.0.3",
42
- "typescript": "^4.3"
27
+ "@internetarchive/ia-activity-indicator": "^0.0.2",
28
+ "@open-wc/eslint-config": "^7.0.0",
29
+ "@open-wc/testing": "^3.0.3",
30
+ "@typescript-eslint/eslint-plugin": "^5.10.0",
31
+ "@typescript-eslint/parser": "^5.10.0",
32
+ "@web/dev-server": "^0.1.29",
33
+ "@web/test-runner": "^0.13.25",
34
+ "concurrently": "^7.0.0",
35
+ "eslint": "^8.7.0",
36
+ "eslint-config-prettier": "^8.3.0",
37
+ "husky": "^4.3.8",
38
+ "lint-staged": "^12.2.2",
39
+ "lit-html": "^2.1.1",
40
+ "prettier": "^2.5.1",
41
+ "snowpack": "^3.8.8",
42
+ "tslib": "^2.3.1",
43
+ "typescript": "^4.5"
43
44
  },
44
45
  "eslintConfig": {
45
46
  "parser": "@typescript-eslint/parser",
@@ -174,6 +174,14 @@ export class HistogramDateRange extends LitElement {
174
174
  return this.bins.length;
175
175
  }
176
176
 
177
+ private get histogramLeftEdgeX(): number {
178
+ return this.sliderWidth;
179
+ }
180
+
181
+ private get histogramRightEdgeX(): number {
182
+ return this.width - this.sliderWidth;
183
+ }
184
+
177
185
  /** component's loading (and disabled) state */
178
186
  @property({ type: Boolean }) get loading(): boolean {
179
187
  return this._isLoading;
@@ -198,10 +206,12 @@ export class HistogramDateRange extends LitElement {
198
206
  this._minSelectedDate = rawDate;
199
207
  return;
200
208
  }
201
- let ms = this.getMSFromString(rawDate);
202
- if (!Number.isNaN(ms)) {
203
- ms = Math.min(ms, this.getMSFromString(this._maxSelectedDate));
204
- this._minSelectedDate = this.formatDate(ms);
209
+ const proposedDateMS = this.getMSFromString(rawDate);
210
+ const isValidDate = !Number.isNaN(proposedDateMS);
211
+ const isNotTooRecent =
212
+ proposedDateMS <= this.getMSFromString(this.maxSelectedDate);
213
+ if (isValidDate && isNotTooRecent) {
214
+ this._minSelectedDate = this.formatDate(proposedDateMS);
205
215
  }
206
216
  this.requestUpdate();
207
217
  }
@@ -220,24 +230,24 @@ export class HistogramDateRange extends LitElement {
220
230
  this._maxSelectedDate = rawDate;
221
231
  return;
222
232
  }
223
- let ms = this.getMSFromString(rawDate);
224
- if (!Number.isNaN(ms)) {
225
- ms = Math.max(this.getMSFromString(this._minSelectedDate), ms);
226
- this._maxSelectedDate = this.formatDate(ms);
233
+ const proposedDateMS = this.getMSFromString(rawDate);
234
+ const isValidDate = !Number.isNaN(proposedDateMS);
235
+ const isNotTooOld =
236
+ proposedDateMS >= this.getMSFromString(this.minSelectedDate);
237
+ if (isValidDate && isNotTooOld) {
238
+ this._maxSelectedDate = this.formatDate(proposedDateMS);
227
239
  }
228
240
  this.requestUpdate();
229
241
  }
230
242
 
231
243
  /** horizontal position of min date slider */
232
244
  get minSliderX(): number {
233
- // default to leftmost position if missing or invalid min position
234
245
  const x = this.translateDateToPosition(this.minSelectedDate);
235
246
  return this.validMinSliderX(x);
236
247
  }
237
248
 
238
249
  /** horizontal position of max date slider */
239
250
  get maxSliderX(): number {
240
- // default to rightmost position if missing or invalid max position
241
251
  const x = this.translateDateToPosition(this.maxSelectedDate);
242
252
  return this.validMaxSliderX(x);
243
253
  }
@@ -318,38 +328,42 @@ export class HistogramDateRange extends LitElement {
318
328
  * Constrain a proposed value for the minimum (left) slider
319
329
  *
320
330
  * If the value is less than the leftmost valid position, then set it to the
321
- * left edge of the widget (ie the slider width). If the value is greater than
322
- * the rightmost valid position (the position of the max slider), then set it
323
- * to the position of the max slider
331
+ * left edge of the histogram (ie the slider width). If the value is greater
332
+ * than the rightmost valid position (the position of the max slider), then
333
+ * set it to the position of the max slider
324
334
  */
325
335
  private validMinSliderX(newX: number): number {
326
- if (Number.isNaN(newX)) {
327
- return this.sliderWidth;
328
- }
329
- return this.clamp(
330
- newX,
331
- this.sliderWidth,
332
- this.translateDateToPosition(this.maxSelectedDate)
336
+ // allow the left slider to go right only to the right slider, even if the
337
+ // max selected date is out of range
338
+ const rightLimit = Math.min(
339
+ this.translateDateToPosition(this.maxSelectedDate),
340
+ this.histogramRightEdgeX
333
341
  );
342
+ newX = this.clamp(newX, this.histogramLeftEdgeX, rightLimit);
343
+ const isInvalid =
344
+ Number.isNaN(newX) || rightLimit < this.histogramLeftEdgeX;
345
+ return isInvalid ? this.histogramLeftEdgeX : newX;
334
346
  }
335
347
 
336
348
  /**
337
349
  * Constrain a proposed value for the maximum (right) slider
338
350
  *
339
351
  * If the value is greater than the rightmost valid position, then set it to
340
- * the right edge of the widget (ie widget width - slider width). If the value
341
- * is less than the leftmost valid position (the position of the min slider),
342
- * then set it to the position of the min slider
352
+ * the right edge of the histogram (ie histogram width - slider width). If the
353
+ * value is less than the leftmost valid position (the position of the min
354
+ * slider), then set it to the position of the min slider
343
355
  */
344
356
  private validMaxSliderX(newX: number): number {
345
- if (Number.isNaN(newX)) {
346
- return this.width - this.sliderWidth;
347
- }
348
- return this.clamp(
349
- newX,
350
- this.translateDateToPosition(this.minSelectedDate),
351
- this.width - this.sliderWidth
357
+ // allow the right slider to go left only to the left slider, even if the
358
+ // min selected date is out of range
359
+ const leftLimit = Math.max(
360
+ this.histogramLeftEdgeX,
361
+ this.translateDateToPosition(this.minSelectedDate)
352
362
  );
363
+ newX = this.clamp(newX, leftLimit, this.histogramRightEdgeX);
364
+ const isInvalid =
365
+ Number.isNaN(newX) || leftLimit > this.histogramRightEdgeX;
366
+ return isInvalid ? this.histogramRightEdgeX : newX;
353
367
  }
354
368
 
355
369
  private addListeners(): void {
@@ -431,8 +445,7 @@ export class HistogramDateRange extends LitElement {
431
445
  }
432
446
 
433
447
  /**
434
- * Returns slider x-position corresponding to given date (or null if invalid
435
- * date)
448
+ * Returns slider x-position corresponding to given date
436
449
  *
437
450
  * @param date
438
451
  * @returns x-position of slider
@@ -484,15 +497,25 @@ export class HistogramDateRange extends LitElement {
484
497
  return dayjs(date, [this.dateFormat, DATE_FORMAT]).valueOf();
485
498
  }
486
499
 
487
- private handleBarClick(e: InputEvent): void {
500
+ /**
501
+ * expand or narrow the selected range by moving the slider nearest the
502
+ * clicked bar to the outer edge of the clicked bar
503
+ *
504
+ * @param e Event click event from a histogram bar
505
+ */
506
+ private handleBarClick(e: Event): void {
488
507
  const dataset = (e.currentTarget as SVGRectElement).dataset as BarDataset;
489
- const distanceFromMinSlider =
490
- this.getMSFromString(dataset.binStart) -
491
- this.getMSFromString(this.minSelectedDate);
492
- const distanceFromMaxSlider =
493
- this.getMSFromString(this.maxSelectedDate) -
494
- this.getMSFromString(dataset.binEnd);
495
- // update the selection by moving the nearer slider
508
+ const clickPosition =
509
+ (this.getMSFromString(dataset.binStart) +
510
+ this.getMSFromString(dataset.binEnd)) /
511
+ 2;
512
+ const distanceFromMinSlider = Math.abs(
513
+ clickPosition - this.getMSFromString(this.minSelectedDate)
514
+ );
515
+ const distanceFromMaxSlider = Math.abs(
516
+ clickPosition - this.getMSFromString(this.maxSelectedDate)
517
+ );
518
+ // update the selected range by moving the nearer slider
496
519
  if (distanceFromMinSlider < distanceFromMaxSlider) {
497
520
  this.minSelectedDate = dataset.binStart;
498
521
  } else {
@@ -370,6 +370,8 @@ describe('HistogramDateRange', () => {
370
370
  )[1]; // click on second bar to the left
371
371
 
372
372
  leftBarToClick.dispatchEvent(new Event('click'));
373
+ await el.updateComplete;
374
+ debugger;
373
375
  expect(el.minSelectedDate).to.eq('1910'); // range was extended to left
374
376
 
375
377
  const rightBarToClick = Array.from(
@@ -380,6 +382,39 @@ describe('HistogramDateRange', () => {
380
382
  expect(el.maxSelectedDate).to.eq('1998'); // range was extended to right
381
383
  });
382
384
 
385
+ it('narrows the selected range when the histogram is clicked inside of the current range', async () => {
386
+ const el = await fixture<HistogramDateRange>(
387
+ html`
388
+ <histogram-date-range
389
+ minDate="1900"
390
+ maxDate="2020"
391
+ minSelectedDate="1900"
392
+ maxSelectedDate="2020"
393
+ bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
394
+ >
395
+ </histogram-date-range>
396
+ `
397
+ );
398
+
399
+ ///////////////////////////////////////////////
400
+ // NB: the slider nearest the clicked bar moves
401
+ ///////////////////////////////////////////////
402
+
403
+ const leftBarToClick = Array.from(
404
+ el.shadowRoot?.querySelectorAll('.bar') as NodeList
405
+ )[3]; // click on fourth bar to the left
406
+
407
+ leftBarToClick.dispatchEvent(new Event('click'));
408
+ expect(el.minSelectedDate).to.eq('1932'); // range was extended to the right
409
+
410
+ const rightBarToClick = Array.from(
411
+ el.shadowRoot?.querySelectorAll('.bar') as NodeList
412
+ )[8]; // click on second bar from the right
413
+
414
+ rightBarToClick.dispatchEvent(new Event('click'));
415
+ expect(el.maxSelectedDate).to.eq('1998'); // range was extended to the left
416
+ });
417
+
383
418
  it('handles invalid pre-selected range by defaulting to overall max and min', async () => {
384
419
  const el = await fixture<HistogramDateRange>(
385
420
  html`
@@ -435,7 +470,6 @@ describe('HistogramDateRange', () => {
435
470
  '.bar'
436
471
  ) as unknown) as SVGRectElement[];
437
472
  const heights = Array.from(bars).map(b => b.height.baseVal.value);
438
- debugger;
439
473
  expect(heights).to.eql([157]);
440
474
  });
441
475
 
@@ -1,3 +0,0 @@
1
- export const MODE = "production";
2
- export const NODE_ENV = "production";
3
- export const SSR = false;