Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cosmograph/ui

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cosmograph/ui - npm Package Compare versions

Comparing version 0.0.3-beta.1 to 0.0.3-beta.2

2

index.js

@@ -1,2 +0,2 @@

export{Timeline}from"./modules/timeline/index.js";export{Histogram}from"./modules/histogram/index.js";export{Search}from"./modules/search/index.js";export{Config,merge}from"./utils.js";export{TimelineConfig}from"./modules/timeline/config.js";export{HistogramConfig}from"./modules/histogram/config.js";export{SearchConfig}from"./modules/search/config.js";
export{Timeline}from"./modules/timeline/index.js";export{Histogram}from"./modules/histogram/index.js";export{Search}from"./modules/search/index.js";export{Config,merge}from"./utils.js";export{TimelineConfig}from"./modules/timeline/config.js";export{HistogramConfig}from"./modules/histogram/config.js";
//# sourceMappingURL=index.js.map

@@ -6,2 +6,3 @@ import { HistogramConfig, type HistogramConfigInterface, type HistogramEvents } from './config';

private _containerNode;
private _noDataDiv;
private _resizeObserver;

@@ -11,2 +12,3 @@ private _axisGroup;

private _brushGroup;
private _firstRender;
private _formatter;

@@ -43,3 +45,3 @@ private _height;

setHistogramData(data: number[] | undefined, customExtent?: [number, number]): void;
/** `setBrush`: Set the selected range on a `Histogram`. Takes a numeric selection range in the X axis units as a parameter. */
/** `setBrush`: Set the selected range on a `Histogram`. Takes a numeric selection range in the X axis u nits as a parameter. */
setBrush(selection?: [number, number]): void;

@@ -46,0 +48,0 @@ /** `resize`: Resizes `Histogram` according to the parent node attributes. */

@@ -1,2 +0,2 @@

import{axisBottom as t}from"d3-axis";import{ResizeObserver as i}from"@juggle/resize-observer";import{brushX as s}from"d3-brush";import{scaleSymlog as e,scaleLinear as r}from"d3-scale";import{select as a}from"d3-selection";import{extent as n,rollup as h,pairs as o}from"d3-array";import _ from"./style.module.css.js";import{HistogramConfig as c}from"./config.js";export{HistogramConfig}from"./config.js";import{getCountsInRange as l}from"../../utils.js";class g{constructor(s,n){var h;this._config=new c,this._barWidth=0,this._maxCount=0,this._barsData=[],this._histogramData=void 0,this._bandIntervals=[],this._yScale=e(),this._xScale=r(),this._axis=t(this._xScale),this._getClosestRange=(t,i)=>{var s;return null===(s=this._barsData)||void 0===s?void 0:s.reduce(((s,e)=>Math.abs(e[i?"rangeEnd":"rangeStart"]-t)<Math.abs(s[i?"rangeEnd":"rangeStart"]-t)?e:s))};const{offsetWidth:o,offsetHeight:l}=s;n&&this._config.init(n),this._containerNode=s,this._containerNode.classList.add(_.histogram),this._width=o,this._height=l,this._formatter=null!==(h=null==n?void 0:n.formatFunction)&&void 0!==h?h:void 0,this._histogramWidth=this._width-this._config.padding.left-this._config.padding.right,this._histogramHeight=this._height-this._config.padding.top-this._config.padding.bottom,this._svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._svg.classList.add(_.histogramSvg),this._containerNode.appendChild(this._svg),this._axisGroup=a(this._svg).append("g").attr("class",_.axis),this._barsGroup=a(this._svg).append("g").attr("class",_.bars),this._brushGroup=a(this._svg).append("g").attr("class",_.brush),this._axis.tickFormat((t=>this._formatter?this._formatter(t):t.toFixed(0))),this._resizeObserver=new i((()=>{this.resize()})),this._resizeObserver.observe(this._containerNode)}get _barPadding(){return this._barWidth*this._config.barPadding}get getCurrentSelection(){return this._currentSelection}get getCurrentSelectionInPixels(){var t;return null!==(t=this._currentSelectionInPixels)&&void 0!==t?t:[]}getBarWidth(){return this._barWidth-this._barPadding}getConfig(){return this._config}setConfig(t){var i,s,e,r;const a=JSON.parse(JSON.stringify(this._config));t?this._config.init(t):this._config=new c,this._config.enableBrush||this._disableBrush(),(null===(i=this._config)||void 0===i?void 0:i.dataStep)===(null===(s=a.config)||void 0===s?void 0:s.dataStep)&&(null===(e=this._config)||void 0===e?void 0:e.barCount)===(null===(r=a.config)||void 0===r?void 0:r.barCount)||this._updateHistogramData(),this.resize()}setHistogramData(t,i){var s,e,r;i&&i[1]<=i[0]||(this._histogramData=t,this._currentSelection=void 0,this._brushCurrentSelection(),null===(e=(s=this._config.events).onBrush)||void 0===e||e.call(s,this._currentSelection),(null===(r=this._histogramData)||void 0===r?void 0:r.length)&&(this._extent=i||n(this._histogramData),this._updateHistogramData(),this._updateScales(),this.render()))}setBrush(t){var i,s;if(t&&this._extent&&t[0]>this._extent[0]&&t[1]<this._extent[1]&&t[0]<t[1]){const i=t.map(this._xScale);this._mapSelection(i)}else this._currentSelection=void 0;this._brushCurrentSelection(),null===(s=(i=this._config.events).onBrush)||void 0===s||s.call(i,this._currentSelection)}resize(){const{offsetWidth:t,offsetHeight:i}=this._containerNode;this._width=t,this._height=i,this._histogramWidth=this._width-this._config.padding.left-this._config.padding.right,this._histogramHeight=this._height-this._config.padding.top-this._config.padding.bottom,this._histogramHeight>this._config.padding.top+this._config.padding.bottom&&(this._updateScales(),this._currentSelection&&this.setBrush(this._currentSelection),this.render())}render(){this._updateBrush(),this._updateBars(),this._updateAxis()}destroy(){this._containerNode.innerHTML=""}_updateAxis(){this._histogramData&&(this._axisGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top-this._config.brushPadding/2+1}px)`).call(this._axis).call((t=>t.select(".domain").remove())),this._axisGroup.selectAll(".tick").select("text").attr("class",_.axisTick).attr("y",0).attr("dy",0).attr("dx",this._config.labelSideMargin),this._axisGroup.selectAll(".tick:last-of-type text").attr("dx",-this._config.labelSideMargin).style("text-anchor","end"),this._axisGroup.selectAll("line").attr("y2",this._histogramHeight).attr("y1",0).attr("opacity",.1))}_updateBrush(){this._config.enableBrush&&(this._brushGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top}px)`),this._brushInstance=s().extent([[0,0],[this._histogramWidth,this._histogramHeight]]),this._brushInstance.on("end",(({selection:t,sourceEvent:i})=>{var s,e,r,a;i&&(t?(this._mapSelection(t),null===(e=(s=this._config.events).onBrush)||void 0===e||e.call(s,this._currentSelection)):(this._currentSelection=void 0,null===(a=(r=this._config.events).onBrush)||void 0===a||a.call(r,void 0)),this._brushCurrentSelection())})),this._brushGroup.call(this._brushInstance),this._brushGroup.select("rect.selection").classed(_.selection,!0).attr("rx",this._config.brushRadius).attr("ry",this._config.brushRadius))}_updateBars(){this._barsGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top-this._config.brushPadding/2}px)`);const t=this._barsGroup.selectAll(`.${_.bar}`).data(this._barsData).join("rect").attr("class",_.bar).attr("x",(t=>this._xScale(t.rangeStart)+this._barPadding/2)).attr("width",this.getBarWidth()).attr("rx",this._config.barRadius).attr("ry",this._config.barRadius).attr("y",-this._histogramHeight);this._config.events.onBarHover&&t.on("mouseover",this._config.events.onBarHover),t.transition().duration(300).attr("height",(t=>this._yScale(t.count))).style("opacity",(t=>this._yScale(t.count)===this._config.minBarHeight?.4:1))}_updateScales(){if(!this._extent||!this._barsData.length)return;const t=this._barsData[this._barsData.length-1],i=this._config.dataStep?[this._extent[0],t.rangeEnd]:this._extent;this._xScale.domain(i).range([0,this._histogramWidth]).clamp(!0),this._yScale.range([this._config.minBarHeight,this._histogramHeight-this._config.barTopMargin-this._config.brushPadding]).domain([0,this._maxCount]).clamp(!0),this._axis.tickValues(i),this._barWidth=this._xScale(t.rangeEnd)-this._xScale(t.rangeStart)}_disableBrush(){this._currentSelection=void 0,this._brushCurrentSelection(),this._brushGroup.selectAll("*").remove()}_updateHistogramData(){var t,i;if((null===(t=this._histogramData)||void 0===t?void 0:t.length)&&this._extent){const t=h(this._histogramData,(t=>t.length),(t=>t)),s=null!==(i=this._config.dataStep)&&void 0!==i?i:Math.abs(this._extent[1]-this._extent[0])/(this._config.barCount-1);if(0===s)return;if(this._bandIntervals=this._generateSequence(this._extent[0],this._extent[1],s),this._config.dataStep){const t=this._bandIntervals[this._bandIntervals.length-1];t<this._extent[1]&&this._bandIntervals.push(+t+s)}const e=o(this._bandIntervals);this._barsData=e.map((i=>({rangeStart:i[0],rangeEnd:i[1],count:l(t,i)}))),this._maxCount=Math.max(...this._barsData.map((t=>t.count)))}}_mapSelection(t){this._barsData.length&&(this._config.stickyBrush?(this._currentSelection=[this._getClosestRange(this._xScale.invert(t[0])).rangeStart,this._getClosestRange(this._xScale.invert(t[1]),!0).rangeEnd],this._currentSelection[0]===this._currentSelection[1]&&(this._currentSelection=void 0)):this._currentSelection=t.map(this._xScale.invert))}_brushCurrentSelection(){var t;this._currentSelection?(this._currentSelectionInPixels=this._currentSelection.map(this._xScale),this._brushInstance&&this._brushGroup.call(this._brushInstance.move,this._currentSelectionInPixels)):(this._currentSelectionInPixels=void 0,null===(t=this._brushInstance)||void 0===t||t.clear(this._brushGroup))}_generateSequence(t,i,s){const e=Math.round((i-t)/s)+1,r=new Array(e);for(let i=0;i<e;i++)r[i]=t+i*s;return r}}export{g as Histogram};
import{axisBottom as t}from"d3-axis";import{ResizeObserver as i}from"@juggle/resize-observer";import{brushX as s}from"d3-brush";import{scaleSymlog as e,scaleLinear as a}from"d3-scale";import{select as r}from"d3-selection";import{extent as n,rollup as h,pairs as o}from"d3-array";import _ from"./style.module.css.js";import{HistogramConfig as c}from"./config.js";export{HistogramConfig}from"./config.js";import{getCountsInRange as l}from"../../utils.js";class d{constructor(s,n){var h;this._config=new c,this._firstRender=!0,this._barWidth=0,this._maxCount=0,this._barsData=[],this._histogramData=void 0,this._bandIntervals=[],this._yScale=e(),this._xScale=a(),this._axis=t(this._xScale),this._getClosestRange=(t,i)=>{var s;return null===(s=this._barsData)||void 0===s?void 0:s.reduce(((s,e)=>Math.abs(e[i?"rangeEnd":"rangeStart"]-t)<Math.abs(s[i?"rangeEnd":"rangeStart"]-t)?e:s))};const{offsetWidth:o,offsetHeight:l}=s;n&&this._config.init(n),this._containerNode=s,this._containerNode.classList.add(_.histogram),this._width=o,this._height=l,this._formatter=null!==(h=null==n?void 0:n.formatFunction)&&void 0!==h?h:void 0,this._histogramWidth=this._width-this._config.padding.left-this._config.padding.right,this._histogramHeight=this._height-this._config.padding.top-this._config.padding.bottom,this._svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._svg.classList.add(_.histogramSvg),this._containerNode.appendChild(this._svg),this._noDataDiv=document.createElement("div"),r(this._noDataDiv).style("display","none").attr("class",_.noData).append("div").text("No histogram data"),this._containerNode.appendChild(this._noDataDiv),this._axisGroup=r(this._svg).append("g").attr("class",_.axis),this._barsGroup=r(this._svg).append("g").attr("class",_.bars),this._brushGroup=r(this._svg).append("g").attr("class",_.brush),this._axis.tickFormat((t=>this._formatter?this._formatter(t):t.toFixed(0))),this._resizeObserver=new i((()=>{this.resize()})),this._resizeObserver.observe(this._containerNode)}get _barPadding(){return this._barWidth*this._config.barPadding}get getCurrentSelection(){return this._currentSelection}get getCurrentSelectionInPixels(){var t;return null!==(t=this._currentSelectionInPixels)&&void 0!==t?t:[]}getBarWidth(){return this._barWidth-this._barPadding}getConfig(){return this._config}setConfig(t){var i,s,e,a;const r=JSON.parse(JSON.stringify(this._config));t?this._config.init(t):this._config=new c,this._config.enableBrush||this._disableBrush(),(null===(i=this._config)||void 0===i?void 0:i.dataStep)===(null===(s=r.config)||void 0===s?void 0:s.dataStep)&&(null===(e=this._config)||void 0===e?void 0:e.barCount)===(null===(a=r.config)||void 0===a?void 0:a.barCount)||this._updateHistogramData(),this.resize()}setHistogramData(t,i){var s,e,a;i&&i[1]<=i[0]||(this._histogramData=null==t?void 0:t.filter((t=>!isNaN(t)&&void 0!==t)),this._currentSelection=void 0,this._brushCurrentSelection(),null===(e=(s=this._config.events).onBrush)||void 0===e||e.call(s,this._currentSelection),r(this._noDataDiv).style("display","none"),(null===(a=this._histogramData)||void 0===a?void 0:a.length)?(this._extent=i||n(this._histogramData),this._firstRender=!0,this._updateHistogramData(),this._updateScales(),this.render()):r(this._noDataDiv).style("display","block"))}setBrush(t){if(t&&this._extent&&t[0]>this._extent[0]&&t[1]<this._extent[1]&&t[0]<t[1]){const i=t.map(this._xScale);this._mapSelection(i)}else this._currentSelection=void 0;this._brushCurrentSelection()}resize(){const{offsetWidth:t,offsetHeight:i}=this._containerNode;this._width=t,this._height=i,this._histogramWidth=this._width-this._config.padding.left-this._config.padding.right,this._histogramHeight=this._height-this._config.padding.top-this._config.padding.bottom,this._histogramHeight>this._config.padding.top+this._config.padding.bottom&&(this._updateScales(),this._currentSelection&&this.setBrush(this._currentSelection),this._firstRender||this.render())}render(){this._updateBrush(),this._updateBars(),this._updateAxis(),this._firstRender&&(this._firstRender=!1)}destroy(){this._containerNode.innerHTML=""}_updateAxis(){this._histogramData&&(this._axisGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top-this._config.brushPadding/2+1}px)`).call(this._axis).call((t=>t.select(".domain").remove())),this._axisGroup.selectAll(".tick").select("text").attr("class",_.axisTick).attr("y",0).attr("dy",0).attr("dx",this._config.labelSideMargin),this._axisGroup.selectAll(".tick:last-of-type text").attr("dx",-this._config.labelSideMargin).style("text-anchor","end"),this._axisGroup.selectAll("line").attr("y2",this._histogramHeight).attr("y1",0).attr("opacity",.1))}_updateBrush(){this._config.enableBrush&&(this._brushGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top}px)`),this._brushInstance=s().extent([[0,0],[this._histogramWidth,this._histogramHeight]]),this._brushInstance.on("end",(({selection:t,sourceEvent:i})=>{var s,e,a,r;i&&(t?(this._mapSelection(t),null===(e=(s=this._config.events).onBrush)||void 0===e||e.call(s,this._currentSelection)):(this._currentSelection=void 0,null===(r=(a=this._config.events).onBrush)||void 0===r||r.call(a,void 0)),this._brushCurrentSelection())})),this._brushGroup.call(this._brushInstance),this._brushGroup.select("rect.selection").classed(_.selection,!0).attr("rx",this._config.brushRadius).attr("ry",this._config.brushRadius))}_updateBars(){this._barsGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top-this._config.brushPadding/2}px)`);const t=this._barsGroup.selectAll(`.${_.bar}`).data(this._barsData).join("rect").attr("class",_.bar).attr("x",(t=>this._xScale(t.rangeStart)+this._barPadding/2)).attr("width",this.getBarWidth()).attr("rx",this._config.barRadius).attr("ry",this._config.barRadius).attr("y",-this._histogramHeight);this._config.events.onBarHover&&t.on("mouseover",this._config.events.onBarHover),t.transition().duration(300).attr("height",(t=>this._yScale(t.count))).style("opacity",(t=>this._yScale(t.count)===this._config.minBarHeight?.4:1))}_updateScales(){if(!this._extent||!this._barsData.length)return;const t=this._barsData[this._barsData.length-1],i=this._config.dataStep?[this._extent[0],t.rangeEnd]:this._extent;this._xScale.domain(i).range([0,this._histogramWidth]).clamp(!0),this._yScale.range([this._config.minBarHeight,this._histogramHeight-this._config.barTopMargin-this._config.brushPadding]).domain([0,this._maxCount]).clamp(!0),this._axis.tickValues(i),this._barWidth=this._xScale(t.rangeEnd)-this._xScale(t.rangeStart)}_disableBrush(){this._currentSelection=void 0,this._brushCurrentSelection(),this._brushGroup.selectAll("*").remove()}_updateHistogramData(){var t,i;if((null===(t=this._histogramData)||void 0===t?void 0:t.length)&&this._extent){const t=h(this._histogramData,(t=>t.length),(t=>t)),s=null!==(i=this._config.dataStep)&&void 0!==i?i:Math.abs(this._extent[1]-this._extent[0])/(this._config.barCount-1);if(0===s)return;if(this._bandIntervals=this._generateSequence(this._extent[0],this._extent[1],s),this._config.dataStep){const t=this._bandIntervals[this._bandIntervals.length-1];t<this._extent[1]&&this._bandIntervals.push(+t+s)}const e=o(this._bandIntervals);this._barsData=e.map((i=>({rangeStart:i[0],rangeEnd:i[1],count:l(t,i)}))),this._maxCount=Math.max(...this._barsData.map((t=>t.count)))}}_mapSelection(t){this._barsData.length&&(this._config.stickyBrush?(this._currentSelection=[this._getClosestRange(this._xScale.invert(t[0])).rangeStart,this._getClosestRange(this._xScale.invert(t[1]),!0).rangeEnd],this._currentSelection[0]===this._currentSelection[1]&&(this._currentSelection=void 0)):this._currentSelection=t.map(this._xScale.invert))}_brushCurrentSelection(){var t;this._currentSelection?(this._currentSelectionInPixels=this._currentSelection.map(this._xScale),this._brushInstance&&!this._firstRender&&this._brushGroup.call(this._brushInstance.move,this._currentSelectionInPixels)):(this._currentSelectionInPixels=void 0,null===(t=this._brushInstance)||void 0===t||t.clear(this._brushGroup))}_generateSequence(t,i,s){const e=Math.round((i-t)/s)+1,a=new Array(e);for(let i=0;i<e;i++)a[i]=t+i*s;return a}}export{d as Histogram};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import o from'./../../ext/rollup-plugin-styles/dist/runtime/inject-css.js';var e=":root{--cosmograph-histogram-text-color:#fff;--cosmograph-histogram-axis-color:#d7d7d7;--cosmograph-histogram-selection-color:#777;--cosmograph-histogram-selection-opacity:0.5;--cosmograph-histogram-bar-color:#7a7a7a;--cosmograph-histogram-font-family:inherit;--cosmograph-histogram-font-size:11px;--cosmograph-histogram-background:#222}.style_module_histogram__ca54899e{background:var(--cosmograph-histogram-background);display:flex;position:relative;width:100%}.style_module_histogramSvg__ca54899e{height:100%;position:relative;width:100%}.style_module_selection__ca54899e{fill:var(--cosmograph-histogram-selection-color);fill-opacity:var(--cosmograph-histogram-selection-opacity);stroke:none}.style_module_axisTick__ca54899e{alignment-baseline:text-before-edge;text-anchor:initial;font-size:var(--cosmograph-histogram-font-size);font-weight:400;opacity:1;user-select:none}.style_module_tick__ca54899e:last-child .style_module_axisTick__ca54899e{visibility:hidden}.style_module_bar__ca54899e{fill:var(--cosmograph-histogram-bar-color);transform:scaleY(-1)}.style_module_axis__ca54899e{color:var(--cosmograph-histogram-axis-color)}",a={histogram:"style_module_histogram__ca54899e",histogramSvg:"style_module_histogramSvg__ca54899e",selection:"style_module_selection__ca54899e",axisTick:"style_module_axisTick__ca54899e",tick:"style_module_tick__ca54899e",bar:"style_module_bar__ca54899e",axis:"style_module_axis__ca54899e",bars:"style_module_bars__ca54899e",brush:"style_module_brush__ca54899e"};o(e,{});export{e as css,a as default};
import o from'./../../ext/rollup-plugin-styles/dist/runtime/inject-css.js';var e=":root{--cosmograph-histogram-text-color:#fff;--cosmograph-histogram-axis-color:#d7d7d7;--cosmograph-histogram-selection-color:#777;--cosmograph-histogram-selection-opacity:0.5;--cosmograph-histogram-bar-color:#7a7a7a;--cosmograph-histogram-font-family:inherit;--cosmograph-histogram-font-size:11px;--cosmograph-histogram-background:#222}.style_module_histogram__ba90113e{background:var(--cosmograph-histogram-background);display:flex;position:relative;width:100%}.style_module_histogramSvg__ba90113e{height:100%;position:relative;width:100%}.style_module_selection__ba90113e{fill:var(--cosmograph-histogram-selection-color);fill-opacity:var(--cosmograph-histogram-selection-opacity);stroke:none}.style_module_axisTick__ba90113e{alignment-baseline:text-before-edge;text-anchor:initial;font-size:var(--cosmograph-histogram-font-size);font-weight:400;opacity:1;user-select:none}.style_module_tick__ba90113e:last-child .style_module_axisTick__ba90113e{visibility:hidden}.style_module_bar__ba90113e{fill:var(--cosmograph-histogram-bar-color);transform:scaleY(-1)}.style_module_axis__ba90113e{color:var(--cosmograph-histogram-axis-color)}.style_module_noData__ba90113e{height:100%;position:absolute;top:0;width:100%}.style_module_noData__ba90113e div{align-items:center;display:flex;font-size:calc(var(--cosmograph-histogram-font-size));font-weight:300;height:100%;justify-content:center;letter-spacing:1;opacity:.25;user-select:none}",a={histogram:"style_module_histogram__ba90113e",histogramSvg:"style_module_histogramSvg__ba90113e",selection:"style_module_selection__ba90113e",axisTick:"style_module_axisTick__ba90113e",tick:"style_module_tick__ba90113e",bar:"style_module_bar__ba90113e",axis:"style_module_axis__ba90113e",bars:"style_module_bars__ba90113e",brush:"style_module_brush__ba90113e",noData:"style_module_noData__ba90113e"};o(e,{});export{e as css,a as default};
//# sourceMappingURL=style.module.css.js.map

@@ -1,14 +0,3 @@

import { Config } from '../../utils';
import type { SearchData, SearchDataRecord } from './types';
export declare class SearchConfig<T extends SearchDataRecord = SearchDataRecord> extends Config implements SearchConfigInterface {
isDisabled: boolean;
minMatch: number;
limitSuggestions: undefined;
maxVisibleItems: number;
openListUpwards: boolean;
placeholder: string;
accessor: undefined;
events: SearchEvents<T> & SearchEvents<SearchDataRecord>;
}
export interface SearchConfigInterface<T extends SearchDataRecord = SearchDataRecord> {
import type { SearchData } from './types';
export type SearchConfigInterface<T extends SearchData = SearchData> = {
/** `isDisabled`: Makes `Search` component inactive. Default: `false` */

@@ -27,10 +16,11 @@ isDisabled?: boolean;

/** `accessor`: Specifies the property of the `SearchData` that should be used as the value to search when input is performed. Default: `undefined` */
accessor?: string;
accessor?: (d: T) => string;
events?: SearchEvents<T>;
}
export interface SearchEvents<T extends SearchDataRecord = SearchDataRecord> {
};
export declare const defaultSearchConfig: SearchConfigInterface<SearchData>;
export interface SearchEvents<T extends SearchData = SearchData> {
/** `onSelect`: Function that will be called when the user selects an item from the suggestions list. Provides selected item as argument. */
onSelect?: (foundMatch: SearchData<T>) => void;
onSelect?: (foundMatch: T) => void;
/** `onSearch`: Function that will be called when the user inputs a search term. Provides an array of `SearchData` items that match current search term as argument. */
onSearch?: (foundMatches?: SearchData<T>[]) => void;
onSearch?: (foundMatches?: T[]) => void;
}

@@ -1,2 +0,2 @@

import{Config as s}from"../../utils.js";class i extends s{constructor(){super(...arguments),this.isDisabled=!1,this.minMatch=2,this.limitSuggestions=void 0,this.maxVisibleItems=10,this.openListUpwards=!1,this.placeholder="Search",this.accessor=void 0,this.events={onSelect:void 0,onSearch:void 0}}}export{i as SearchConfig};
const e={isDisabled:!1,minMatch:2,limitSuggestions:void 0,maxVisibleItems:10,openListUpwards:!1,placeholder:"Search",accessor:e=>e.id,events:{onSelect:void 0,onSearch:void 0}};export{e as defaultSearchConfig};
//# sourceMappingURL=config.js.map

@@ -1,4 +0,4 @@

import type { SearchData, SearchDataRecord } from './types';
import { type SearchConfigInterface, SearchConfig } from './config';
export declare class Search<T extends SearchDataRecord = SearchDataRecord> {
import type { SearchData } from './types';
import { type SearchConfigInterface, type SearchEvents } from './config';
export declare class Search<T extends SearchData> {
private _search;

@@ -8,10 +8,9 @@ private _containerNode;

constructor(containerNode: HTMLElement, config?: SearchConfigInterface<T>);
setData(data: SearchData<T>[]): void;
setData(data: T[]): void;
setConfig(config?: SearchConfigInterface<T>): void;
clearInput(): void;
/** `getConfig`: Returns current `Search` configuration */
getConfig(): SearchConfig<T>;
getConfig(): SearchConfigInterface<T>;
destroy(): void;
}
export { SearchConfig };
export type { SearchData, SearchConfigInterface };
export type { SearchData, SearchConfigInterface, SearchEvents };

@@ -1,2 +0,2 @@

import{SearchConfig as t}from"./config.js";export{SearchConfig}from"./config.js";import{Events as i}from"./types.js";import e from"./search.svelte.js";class n{constructor(n,s){this._config=new t,s&&this._config.init(s),this._containerNode=n,this._search=new e({target:n,props:{config:this._config}}),this._search.$on(i.Input,(({detail:t})=>{var i,e;return null===(e=(i=this._config.events).onSearch)||void 0===e?void 0:e.call(i,t)})),this._search.$on(i.Select,(({detail:t})=>{var i,e;return null===(e=(i=this._config.events).onSelect)||void 0===e?void 0:e.call(i,t)}))}setData(t){this._search.$set({data:t,textInput:""})}setConfig(i){i?this._config.init(i):this._config=new t,this._search.$set({config:this._config,textInput:""})}clearInput(){this._search.$set({textInput:""})}getConfig(){return this._config}destroy(){this._containerNode.innerHTML=""}}export{n as Search};
import{defaultSearchConfig as t}from"./config.js";import{Events as i}from"./types.js";import e from"./search.svelte.js";import{merge as o}from"../../utils.js";class s{constructor(s,n){this._config={},this._containerNode=s,this._config=o(t,null!=n?n:{}),this._search=new e({target:s,props:{config:this._config}}),this._search.$on(i.Input,(({detail:t})=>{var i,e;return null===(e=null===(i=this._config.events)||void 0===i?void 0:i.onSearch)||void 0===e?void 0:e.call(i,t)})),this._search.$on(i.Select,(({detail:t})=>{var i,e;return null===(e=null===(i=this._config.events)||void 0===i?void 0:i.onSelect)||void 0===e?void 0:e.call(i,t)}))}setData(t){this._search.$set({data:t,textInput:""})}setConfig(i){this._config=o(t,null!=i?i:{}),this._search.$set({config:this._config,textInput:""})}clearInput(){this._search.$set({textInput:""})}getConfig(){return this._config}destroy(){this._containerNode.innerHTML=""}}export{s as Search};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import{SvelteComponent as t,init as e,flush as s,safe_not_equal as n,binding_callbacks as o,bind as i,element as l,create_component as r,space as c,set_style as m,attr as $,toggle_class as d,insert as u,mount_component as a,append as p,add_flush_callback as f,transition_in as g,transition_out as x,detach as h,destroy_component as v,createEventDispatcher as j,noop as y,empty as b,group_outros as w,check_outros as _,destroy_each as I,is_function as S,text as D,set_data as L}from'./../../ext/svelte/internal/index.mjs.js';import O from"escape-string-regexp";import T from'./../../ext/@smui/list/dist/List.svelte.js';import U from'./../../ext/@smui/list/dist/Item.svelte.js';import z from'./../../ext/@smui/list/dist/Text.js';import'./../../ext/@smui/list/dist/PrimaryText.js';import'./../../ext/@smui/list/dist/SecondaryText.js';import'./../../ext/@smui/list/dist/Meta.js';import'./../../ext/@smui/list/dist/Group.js';import'./../../ext/@smui/list/dist/Subheader.js';import E from'./../../ext/@smui/textfield/dist/Textfield.svelte.js';import'./../../ext/@smui/textfield/dist/Prefix.js';import'./../../ext/@smui/textfield/dist/Suffix.js';import'./../../ext/@smui/textfield/dist/HelperLine.js';import M from'./../../ext/@smui/textfield/dist/icon/Icon.svelte.js';import N from'./../../ext/@smui/menu/dist/Menu.svelte.js';import'./../../ext/@smui/menu/dist/SelectionGroupIcon.js';import C from"./search-svg.svelte.js";import{SearchConfig as G}from"./config.js";import{Events as P}from"./types.js";import"./smui.css.js";import"../../scrollbar.css.js";import"./search.css.js";function V(t,e,s){const n=t.slice();return n[13]=e[s],n}function k(t){let e,s,n;return s=new C({}),{c(){e=l("div"),r(s.$$.fragment),$(e,"class","search-icon svelte-6buz5x")},m(t,o){u(t,e,o),a(s,e,null),n=!0},p:y,i(t){n||(g(s.$$.fragment,t),n=!0)},o(t){x(s.$$.fragment,t),n=!1},d(t){t&&h(e),v(s)}}}function q(t){let e,s;return e=new M({props:{slot:"trailingIcon",$$slots:{default:[k]},$$scope:{ctx:t}}}),{c(){r(e.$$.fragment)},m(t,n){a(e,t,n),s=!0},p(t,s){const n={};65536&s&&(n.$$scope={dirty:s,ctx:t}),e.$set(n)},i(t){s||(g(e.$$.fragment,t),s=!0)},o(t){x(e.$$.fragment,t),s=!1},d(t){v(e,t)}}}function B(t){let e,s;return e=new U({props:{$$slots:{default:[R]},$$scope:{ctx:t}}}),{c(){r(e.$$.fragment)},m(t,n){a(e,t,n),s=!0},p(t,s){const n={};65536&s&&(n.$$scope={dirty:s,ctx:t}),e.$set(n)},i(t){s||(g(e.$$.fragment,t),s=!0)},o(t){x(e.$$.fragment,t),s=!1},d(t){v(e,t)}}}function H(t){let e,s,n=t[2],o=[];for(let e=0;e<n.length;e+=1)o[e]=J(V(t,n,e));const i=t=>x(o[t],1,1,(()=>{o[t]=null}));return{c(){for(let t=0;t<o.length;t+=1)o[t].c();e=b()},m(t,n){for(let e=0;e<o.length;e+=1)o[e]&&o[e].m(t,n);u(t,e,n),s=!0},p(t,s){if(84&s){let l;for(n=t[2],l=0;l<n.length;l+=1){const i=V(t,n,l);o[l]?(o[l].p(i,s),g(o[l],1)):(o[l]=J(i),o[l].c(),g(o[l],1),o[l].m(e.parentNode,e))}for(w(),l=n.length;l<o.length;l+=1)i(l);_()}},i(t){if(!s){for(let t=0;t<n.length;t+=1)g(o[t]);s=!0}},o(t){o=o.filter(Boolean);for(let t=0;t<o.length;t+=1)x(o[t]);s=!1},d(t){I(o,t),t&&h(e)}}}function K(t){let e;return{c(){e=D("No matches found")},m(t,s){u(t,e,s)},d(t){t&&h(e)}}}function R(t){let e,s;return e=new z({props:{$$slots:{default:[K]},$$scope:{ctx:t}}}),{c(){r(e.$$.fragment)},m(t,n){a(e,t,n),s=!0},p(t,s){const n={};65536&s&&(n.$$scope={dirty:s,ctx:t}),e.$set(n)},i(t){s||(g(e.$$.fragment,t),s=!0)},o(t){x(e.$$.fragment,t),s=!1},d(t){v(e,t)}}}function A(t){let e,s=t[4](t[13])+"";return{c(){e=D(s)},m(t,s){u(t,e,s)},p(t,n){4&n&&s!==(s=t[4](t[13])+"")&&L(e,s)},d(t){t&&h(e)}}}function F(t){let e,s,n;return e=new z({props:{$$slots:{default:[A]},$$scope:{ctx:t}}}),{c(){r(e.$$.fragment),s=c()},m(t,o){a(e,t,o),u(t,s,o),n=!0},p(t,s){const n={};65540&s&&(n.$$scope={dirty:s,ctx:t}),e.$set(n)},i(t){n||(g(e.$$.fragment,t),n=!0)},o(t){x(e.$$.fragment,t),n=!1},d(t){v(e,t),t&&h(s)}}}function J(t){let e,s;return e=new U({props:{$$slots:{default:[F]},$$scope:{ctx:t}}}),e.$on("click",(function(){S(t[6](t[13]))&&t[6](t[13]).apply(this,arguments)})),{c(){r(e.$$.fragment)},m(t,n){a(e,t,n),s=!0},p(s,n){t=s;const o={};65540&n&&(o.$$scope={dirty:n,ctx:t}),e.$set(o)},i(t){s||(g(e.$$.fragment,t),s=!0)},o(t){x(e.$$.fragment,t),s=!1},d(t){v(e,t)}}}function Q(t){let e,s,n,o;const i=[H,B],l=[];function r(t,e){return t[2].length?0:1}return e=r(t),s=l[e]=i[e](t),{c(){s.c(),n=b()},m(t,s){l[e].m(t,s),u(t,n,s),o=!0},p(t,o){let c=e;e=r(t),e===c?l[e].p(t,o):(w(),x(l[c],1,1,(()=>{l[c]=null})),_(),s=l[e],s?s.p(t,o):(s=l[e]=i[e](t),s.c()),g(s,1),s.m(n.parentNode,n))},i(t){o||(g(s),o=!0)},o(t){x(s),o=!1},d(t){l[e].d(t),t&&h(n)}}}function W(t){let e,s;return e=new T({props:{style:"max-height: calc("+t[0].maxVisibleItems+" * 30px)",$$slots:{default:[Q]},$$scope:{ctx:t}}}),{c(){r(e.$$.fragment)},m(t,n){a(e,t,n),s=!0},p(t,s){const n={};1&s&&(n.style="max-height: calc("+t[0].maxVisibleItems+" * 30px)"),65540&s&&(n.$$scope={dirty:s,ctx:t}),e.$set(n)},i(t){s||(g(e.$$.fragment,t),s=!0)},o(t){x(e.$$.fragment,t),s=!1},d(t){v(e,t)}}}function X(t){let e,s,n,j,y,b,w,_;function I(e){t[8](e)}function S(e){t[9](e)}let D={style:"opacity: "+(t[0].isDisabled?.5:1),label:t[0].placeholder,$$slots:{trailingIcon:[q]},$$scope:{ctx:t}};return void 0!==t[0].isDisabled&&(D.disabled=t[0].isDisabled),void 0!==t[1]&&(D.value=t[1]),s=new E({props:D}),o.push((()=>i(s,"disabled",I))),o.push((()=>i(s,"value",S))),s.$on("input",t[5]),w=new N({props:{style:"width: 100%; bottom: initial;",$$slots:{default:[W]},$$scope:{ctx:t}}}),t[10](w),{c(){e=l("div"),r(s.$$.fragment),y=c(),b=l("div"),r(w.$$.fragment),m(b,"position","relative"),$(b,"class","svelte-6buz5x"),d(b,"openListUpwards",t[0].openListUpwards),$(e,"class","search svelte-6buz5x")},m(t,n){u(t,e,n),a(s,e,null),p(e,y),p(e,b),a(w,b,null),_=!0},p(t,[e]){const o={};1&e&&(o.style="opacity: "+(t[0].isDisabled?.5:1)),1&e&&(o.label=t[0].placeholder),65536&e&&(o.$$scope={dirty:e,ctx:t}),!n&&1&e&&(n=!0,o.disabled=t[0].isDisabled,f((()=>n=!1))),!j&&2&e&&(j=!0,o.value=t[1],f((()=>j=!1))),s.$set(o);const i={};65541&e&&(i.$$scope={dirty:e,ctx:t}),w.$set(i),(!_||1&e)&&d(b,"openListUpwards",t[0].openListUpwards)},i(t){_||(g(s.$$.fragment,t),g(w.$$.fragment,t),_=!0)},o(t){x(s.$$.fragment,t),x(w.$$.fragment,t),_=!1},d(n){n&&h(e),v(s),t[10](null),v(w)}}}function Y(t,e,s){const n=j();let i,{config:l=new G}=e,{data:r=[]}=e,{textInput:c=""}=e,m=[];const $=t=>"string"!=typeof t?l.accessor?`${t[l.accessor]}`:"":t.toString(),d=t=>{if(r){const e=r[0];l.accessor&&"string"!=typeof e&&(e[l.accessor]||console.warn(`Key '${l.accessor}' was not found in the passed SearchData`)),s(2,m=null==r?void 0:r.filter((e=>$(e).match(new RegExp(O(t.toString()),"i"))))),l.limitSuggestions&&s(2,m=m.slice(0,l.limitSuggestions)),null==m||m.sort(((e,s)=>$(e).toLowerCase().indexOf(t)<$(s).toLowerCase().indexOf(t)?-1:1))}n(P.Input,m)};return t.$$set=t=>{"config"in t&&s(0,l=t.config),"data"in t&&s(7,r=t.data),"textInput"in t&&s(1,c=t.textInput)},[l,c,m,i,$,t=>{const e=null==t?void 0:t.target;e.value.length<l.minMatch?null==i||i.setOpen(!1):(null==i||i.setOpen(!0),d(e.value))},t=>{null!==document.activeElement&&document.activeElement.blur(),n(P.Select,t)},r,function(e){t.$$.not_equal(l.isDisabled,e)&&(l.isDisabled=e,s(0,l))},function(t){c=t,s(1,c)},function(t){o[t?"unshift":"push"]((()=>{i=t,s(3,i)}))}]}class Z extends t{constructor(t){super(),e(this,t,Y,X,n,{config:0,data:7,textInput:1})}get config(){return this.$$.ctx[0]}set config(t){this.$$set({config:t}),s()}get data(){return this.$$.ctx[7]}set data(t){this.$$set({data:t}),s()}get textInput(){return this.$$.ctx[1]}set textInput(t){this.$$set({textInput:t}),s()}}export{Z as default};
import{SvelteComponent as t,init as e,flush as s,safe_not_equal as n,binding_callbacks as o,bind as i,element as l,create_component as r,space as c,set_style as u,attr as d,toggle_class as $,insert as m,mount_component as a,append as p,add_flush_callback as f,transition_in as g,transition_out as x,detach as h,destroy_component as v,createEventDispatcher as j,noop as b,empty as y,group_outros as w,check_outros as _,destroy_each as I,is_function as S,text as D,set_data as L}from'./../../ext/svelte/internal/index.mjs.js';import O from"escape-string-regexp";import T from'./../../ext/@smui/list/dist/List.svelte.js';import U from'./../../ext/@smui/list/dist/Item.svelte.js';import z from'./../../ext/@smui/list/dist/Text.js';import'./../../ext/@smui/list/dist/PrimaryText.js';import'./../../ext/@smui/list/dist/SecondaryText.js';import'./../../ext/@smui/list/dist/Meta.js';import'./../../ext/@smui/list/dist/Group.js';import'./../../ext/@smui/list/dist/Subheader.js';import C from'./../../ext/@smui/textfield/dist/Textfield.svelte.js';import'./../../ext/@smui/textfield/dist/Prefix.js';import'./../../ext/@smui/textfield/dist/Suffix.js';import'./../../ext/@smui/textfield/dist/HelperLine.js';import E from'./../../ext/@smui/textfield/dist/icon/Icon.svelte.js';import M from'./../../ext/@smui/menu/dist/Menu.svelte.js';import'./../../ext/@smui/menu/dist/SelectionGroupIcon.js';import N from"./search-svg.svelte.js";import{Events as G}from"./types.js";import"./smui.css.js";import"../../scrollbar.css.js";import"./search.css.js";function P(t,e,s){const n=t.slice();return n[13]=e[s],n}function V(t){let e,s,n;return s=new N({}),{c(){e=l("div"),r(s.$$.fragment),d(e,"class","search-icon svelte-6buz5x")},m(t,o){m(t,e,o),a(s,e,null),n=!0},p:b,i(t){n||(g(s.$$.fragment,t),n=!0)},o(t){x(s.$$.fragment,t),n=!1},d(t){t&&h(e),v(s)}}}function k(t){let e,s;return e=new E({props:{slot:"trailingIcon",$$slots:{default:[V]},$$scope:{ctx:t}}}),{c(){r(e.$$.fragment)},m(t,n){a(e,t,n),s=!0},p(t,s){const n={};65536&s&&(n.$$scope={dirty:s,ctx:t}),e.$set(n)},i(t){s||(g(e.$$.fragment,t),s=!0)},o(t){x(e.$$.fragment,t),s=!1},d(t){v(e,t)}}}function q(t){let e,s;return e=new U({props:{$$slots:{default:[R]},$$scope:{ctx:t}}}),{c(){r(e.$$.fragment)},m(t,n){a(e,t,n),s=!0},p(t,s){const n={};65536&s&&(n.$$scope={dirty:s,ctx:t}),e.$set(n)},i(t){s||(g(e.$$.fragment,t),s=!0)},o(t){x(e.$$.fragment,t),s=!1},d(t){v(e,t)}}}function B(t){let e,s,n=t[2],o=[];for(let e=0;e<n.length;e+=1)o[e]=J(P(t,n,e));const i=t=>x(o[t],1,1,(()=>{o[t]=null}));return{c(){for(let t=0;t<o.length;t+=1)o[t].c();e=y()},m(t,n){for(let e=0;e<o.length;e+=1)o[e]&&o[e].m(t,n);m(t,e,n),s=!0},p(t,s){if(84&s){let l;for(n=t[2],l=0;l<n.length;l+=1){const i=P(t,n,l);o[l]?(o[l].p(i,s),g(o[l],1)):(o[l]=J(i),o[l].c(),g(o[l],1),o[l].m(e.parentNode,e))}for(w(),l=n.length;l<o.length;l+=1)i(l);_()}},i(t){if(!s){for(let t=0;t<n.length;t+=1)g(o[t]);s=!0}},o(t){o=o.filter(Boolean);for(let t=0;t<o.length;t+=1)x(o[t]);s=!1},d(t){I(o,t),t&&h(e)}}}function H(t){let e;return{c(){e=D("No matches found")},m(t,s){m(t,e,s)},d(t){t&&h(e)}}}function R(t){let e,s;return e=new z({props:{$$slots:{default:[H]},$$scope:{ctx:t}}}),{c(){r(e.$$.fragment)},m(t,n){a(e,t,n),s=!0},p(t,s){const n={};65536&s&&(n.$$scope={dirty:s,ctx:t}),e.$set(n)},i(t){s||(g(e.$$.fragment,t),s=!0)},o(t){x(e.$$.fragment,t),s=!1},d(t){v(e,t)}}}function A(t){let e,s=t[4](t[13])+"";return{c(){e=D(s)},m(t,s){m(t,e,s)},p(t,n){4&n&&s!==(s=t[4](t[13])+"")&&L(e,s)},d(t){t&&h(e)}}}function F(t){let e,s,n;return e=new z({props:{$$slots:{default:[A]},$$scope:{ctx:t}}}),{c(){r(e.$$.fragment),s=c()},m(t,o){a(e,t,o),m(t,s,o),n=!0},p(t,s){const n={};65540&s&&(n.$$scope={dirty:s,ctx:t}),e.$set(n)},i(t){n||(g(e.$$.fragment,t),n=!0)},o(t){x(e.$$.fragment,t),n=!1},d(t){v(e,t),t&&h(s)}}}function J(t){let e,s;return e=new U({props:{$$slots:{default:[F]},$$scope:{ctx:t}}}),e.$on("click",(function(){S(t[6](t[13]))&&t[6](t[13]).apply(this,arguments)})),{c(){r(e.$$.fragment)},m(t,n){a(e,t,n),s=!0},p(s,n){t=s;const o={};65540&n&&(o.$$scope={dirty:n,ctx:t}),e.$set(o)},i(t){s||(g(e.$$.fragment,t),s=!0)},o(t){x(e.$$.fragment,t),s=!1},d(t){v(e,t)}}}function K(t){let e,s,n,o;const i=[B,q],l=[];function r(t,e){return t[2].length?0:1}return e=r(t),s=l[e]=i[e](t),{c(){s.c(),n=y()},m(t,s){l[e].m(t,s),m(t,n,s),o=!0},p(t,o){let c=e;e=r(t),e===c?l[e].p(t,o):(w(),x(l[c],1,1,(()=>{l[c]=null})),_(),s=l[e],s?s.p(t,o):(s=l[e]=i[e](t),s.c()),g(s,1),s.m(n.parentNode,n))},i(t){o||(g(s),o=!0)},o(t){x(s),o=!1},d(t){l[e].d(t),t&&h(n)}}}function Q(t){let e,s;return e=new T({props:{style:"max-height: calc("+t[0].maxVisibleItems+" * 30px)",$$slots:{default:[K]},$$scope:{ctx:t}}}),{c(){r(e.$$.fragment)},m(t,n){a(e,t,n),s=!0},p(t,s){const n={};1&s&&(n.style="max-height: calc("+t[0].maxVisibleItems+" * 30px)"),65540&s&&(n.$$scope={dirty:s,ctx:t}),e.$set(n)},i(t){s||(g(e.$$.fragment,t),s=!0)},o(t){x(e.$$.fragment,t),s=!1},d(t){v(e,t)}}}function W(t){let e,s,n,j,b,y,w,_;function I(e){t[8](e)}function S(e){t[9](e)}let D={style:"opacity: "+(t[0].isDisabled?.5:1),label:t[0].placeholder,$$slots:{trailingIcon:[k]},$$scope:{ctx:t}};return void 0!==t[0].isDisabled&&(D.disabled=t[0].isDisabled),void 0!==t[1]&&(D.value=t[1]),s=new C({props:D}),o.push((()=>i(s,"disabled",I))),o.push((()=>i(s,"value",S))),s.$on("input",t[5]),w=new M({props:{style:"width: 100%; bottom: initial;",$$slots:{default:[Q]},$$scope:{ctx:t}}}),t[10](w),{c(){e=l("div"),r(s.$$.fragment),b=c(),y=l("div"),r(w.$$.fragment),u(y,"position","relative"),d(y,"class","svelte-6buz5x"),$(y,"openListUpwards",t[0].openListUpwards),d(e,"class","search svelte-6buz5x")},m(t,n){m(t,e,n),a(s,e,null),p(e,b),p(e,y),a(w,y,null),_=!0},p(t,[e]){const o={};1&e&&(o.style="opacity: "+(t[0].isDisabled?.5:1)),1&e&&(o.label=t[0].placeholder),65536&e&&(o.$$scope={dirty:e,ctx:t}),!n&&1&e&&(n=!0,o.disabled=t[0].isDisabled,f((()=>n=!1))),!j&&2&e&&(j=!0,o.value=t[1],f((()=>j=!1))),s.$set(o);const i={};65541&e&&(i.$$scope={dirty:e,ctx:t}),w.$set(i),(!_||1&e)&&$(y,"openListUpwards",t[0].openListUpwards)},i(t){_||(g(s.$$.fragment,t),g(w.$$.fragment,t),_=!0)},o(t){x(s.$$.fragment,t),x(w.$$.fragment,t),_=!1},d(n){n&&h(e),v(s),t[10](null),v(w)}}}function X(t,e,s){const n=j();let i,{config:l}=e,{data:r=[]}=e,{textInput:c=""}=e,u=[];const d=t=>"string"!=typeof t?l.accessor?`${l.accessor(t)}`:"":t.toString(),$=t=>{if(r){const e=r[0];l.accessor&&"string"!=typeof e&&(l.accessor(e)||console.warn("Current `accessor` was not found in the passed SearchData")),s(2,u=null==r?void 0:r.filter((e=>d(e).match(new RegExp(O(t.toString()),"i"))))),l.limitSuggestions&&s(2,u=u.slice(0,l.limitSuggestions)),null==u||u.sort(((e,s)=>d(e).toLowerCase().indexOf(t)<d(s).toLowerCase().indexOf(t)?-1:1))}n(G.Input,u)};return t.$$set=t=>{"config"in t&&s(0,l=t.config),"data"in t&&s(7,r=t.data),"textInput"in t&&s(1,c=t.textInput)},[l,c,u,i,d,t=>{const e=null==t?void 0:t.target;e.value.length<(null==l?void 0:l.minMatch)?null==i||i.setOpen(!1):(null==i||i.setOpen(!0),$(e.value))},t=>{null!==document.activeElement&&document.activeElement.blur(),n(G.Select,t)},r,function(e){t.$$.not_equal(l.isDisabled,e)&&(l.isDisabled=e,s(0,l))},function(t){c=t,s(1,c)},function(t){o[t?"unshift":"push"]((()=>{i=t,s(3,i)}))}]}class Y extends t{constructor(t){super(),e(this,t,X,W,n,{config:0,data:7,textInput:1})}get config(){return this.$$.ctx[0]}set config(t){this.$$set({config:t}),s()}get data(){return this.$$.ctx[7]}set data(t){this.$$set({data:t}),s()}get textInput(){return this.$$.ctx[1]}set textInput(t){this.$$set({textInput:t}),s()}}export{Y as default};
//# sourceMappingURL=search.svelte.js.map

@@ -5,9 +5,9 @@ export declare enum Events {

}
export type SearchDataRecord = {
export type SearchData = {
[key: string]: unknown;
id: string;
};
export type SearchData<T extends SearchDataRecord = SearchDataRecord> = SearchDataRecord & T | string;
export interface SearchEvents<T extends SearchDataRecord = SearchDataRecord> {
[Events.Input]: SearchData<T>[];
[Events.Select]: SearchData<T>;
export interface SearchEvents<T extends SearchData> {
[Events.Input]: T;
[Events.Select]: T;
}
import 'd3-transition';
import { TimelineConfig, type TimelineConfigInterface } from './config';
import { TimelineConfig, type TimelineEvents, type TimelineConfigInterface } from './config';
import type { TimelineData } from './types';

@@ -85,2 +85,2 @@ export declare class Timeline {

export { TimelineConfig };
export type { TimelineData, TimelineConfigInterface };
export type { TimelineData, TimelineConfigInterface, TimelineEvents };

@@ -1,2 +0,2 @@

import"d3-transition";import{ResizeObserver as i}from"@juggle/resize-observer";import{axisBottom as t}from"d3-axis";import{brushX as s}from"d3-brush";import{scaleSymlog as n,scaleTime as e,scaleLinear as a}from"d3-scale";import{select as o}from"d3-selection";import{extent as h,rollup as r,range as l,pairs as _}from"d3-array";import{play as c,pause as d}from"./assets.js";import{TimelineConfig as u}from"./config.js";export{TimelineConfig}from"./config.js";import v from"./style.module.css.js";import{getCountsInRange as m,getInnerDimensions as g}from"../../utils.js";class p{constructor(s,h){var r;if(this._isAnimationRunning=!1,this._svgParser=new DOMParser,this._height=0,this._width=0,this._timelineWidth=0,this._timelineHeight=0,this._config=new u,this._barWidth=0,this._maxCount=0,this._barsData=[],this._timeData=void 0,this._bandIntervals=[],this._isNumericTimeline=!1,this._firstRender=!0,this._yScale=n(),this._timeScale=e(),this._numScale=a(),this._activeAxisScale=this._timeScale,this._timeAxis=t(this._timeScale),this._numAxis=t(this._numScale),this._toggleAnimation=()=>{this._isAnimationRunning?this.pauseAnimation():this.playAnimation()},this._disableAnimation=()=>{var i,t;this.pauseAnimation(),null===(i=this._animationControlDiv)||void 0===i||i.removeEventListener("click",this._toggleAnimation),null===(t=this._animationControlDiv)||void 0===t||t.remove()},this.playAnimation=()=>{var i,t,s,n;clearInterval(this._animationInterval),this._currentSelectionInPixels&&(this._animationInterval=setInterval(this._animateSelection,this._config.animationSpeed),this._isAnimationRunning=!0,null===(t=(i=this._config.events).onAnimationPlay)||void 0===t||t.call(i,this._isAnimationRunning,this._currentSelection)),null===(s=this._pauseButtonSvg)||void 0===s||s.classList.remove(v.hidden),null===(n=this._playButtonSvg)||void 0===n||n.classList.add(v.hidden)},this.pauseAnimation=()=>{var i,t,s,n;clearInterval(this._animationInterval),this._isAnimationRunning=!1,null===(t=(i=this._config.events).onAnimationPause)||void 0===t||t.call(i,this._isAnimationRunning,this._currentSelection),null===(s=this._pauseButtonSvg)||void 0===s||s.classList.add(v.hidden),null===(n=this._playButtonSvg)||void 0===n||n.classList.remove(v.hidden)},this.stopAnimation=()=>{var i,t;this.pauseAnimation(),this.setBrush(void 0),null===(t=(i=this._config.events).onBrush)||void 0===t||t.call(i,void 0)},this._animateSelection=()=>{var i,t;const s=this._currentSelectionInPixels;s&&void 0!==s[0]&&void 0!==s[1]&&(this.setBrushInPixels([s[0]+this._barWidth,s[1]+this._barWidth]),s[1]!==(null===(i=this._currentSelectionInPixels)||void 0===i?void 0:i[1])&&void 0!==(null===(t=this._currentSelectionInPixels)||void 0===t?void 0:t[1])||this.stopAnimation())},this._checkLastTickPosition=()=>{var i;const t=this._axisGroup.selectAll(".tick:last-of-type").nodes();if(null==t?void 0:t.length){const s=t[0],n=null==s?void 0:s.getBoundingClientRect().right,e=null===(i=this._svg)||void 0===i?void 0:i.getBoundingClientRect().right;s.style.display=n>=e?"none":"inherit"}},this.destroy=()=>{clearInterval(this._animationInterval)},h&&this._config.init(h),this._containerNode=s,this._svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._svg.classList.add(v.timelineSvg),this._animationControlDiv=document.createElement("div"),this._animationControlDiv.classList.add(v.animationControl),this._containerNode.classList.add(v.timeline),this._containerNode.appendChild(this._svg),this._noDataDiv=document.createElement("div"),o(this._noDataDiv).style("display","none").attr("class",v.noData).append("div").text("No timeline data"),this._containerNode.appendChild(this._noDataDiv),null===(r=this._config)||void 0===r?void 0:r.showAnimationControl){const i=setInterval((()=>{null!==this._containerNode&&(this._initAnimationControls(),clearInterval(i))}),100)}this._barsGroup=o(this._svg).append("g").attr("class",v.bars),this._axisGroup=o(this._svg).append("g").attr("class",v.axis),this._brushGroup=o(this._svg).append("g").attr("class",v.brush),this._timeAxis.tickFormat(this._config.dateFormat),this._numAxis.tickFormat(this._config.numFormat),this._resizeObserver=new i((i=>{window.requestAnimationFrame((()=>{Array.isArray(i)&&i.length&&this.resize()}))})),this._resizeObserver=new i((()=>{this.resize()})),this._resizeObserver.observe(this._containerNode)}get _barPadding(){return this._barWidth*this._config.barPadding}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInPixels(){return this._currentSelectionInPixels}getBarWidth(){return this._barWidth-this._barPadding}getConfig(){return this._config}getIsAnimationRunning(){return this._isAnimationRunning}setConfig(i){var t,s,n,e,a,o;const h=JSON.parse(JSON.stringify(this._config));i?this._config.init(i):this._config=new u,(null===(t=this._config)||void 0===t?void 0:t.showAnimationControl)?(null===(s=this._animationControlDiv)||void 0===s?void 0:s.isConnected)||this._initAnimationControls():this._animationControlDiv&&this._disableAnimation(),this._config.enableBrush||this._disableBrush(),(null===(n=this._config)||void 0===n?void 0:n.dataStep)===(null===(e=h.config)||void 0===e?void 0:e.dataStep)&&(null===(a=this._config)||void 0===a?void 0:a.barCount)===(null===(o=h.config)||void 0===o?void 0:o.barCount)||this._updateTimelineData(),this.resize()}setTimeData(i){var t,s,n;this._timeData=i,this._currentSelection=void 0,null===(s=(t=this._config.events).onBrush)||void 0===s||s.call(t,this._currentSelection),this._updateScales(),o(this._noDataDiv).style("display","none"),(null===(n=this._timeData)||void 0===n?void 0:n.length)?(this._dateExtent=h(this._timeData),this._updateTimelineData()):(this._barsData=[],this._axisGroup.selectAll("*").remove(),this._barsGroup.selectAll("*").remove(),this._brushGroup.selectAll("*").remove(),o(this._noDataDiv).style("display","block"),this._firstRender=!0)}_getBarsData(i,t){var s,n;if(!(i[1]<=i[0])&&(null===(s=this._timeData)||void 0===s?void 0:s.length)&&this._dateExtent){const s=r(this._timeData,(i=>i.length),(i=>i)),e=null!==(n=this._config.dataStep)&&void 0!==n?n:(i[1]-i[0])/(this._config.barCount-1);if(0===e)return;this._bandIntervals=l(+i[0],+i[1],e);const a=this._bandIntervals[this._bandIntervals.length-1];let o=this._config.dataStep?+a+e:i[1];t&&(this._bandIntervals=this._bandIntervals.map((i=>new Date(i))),o=new Date(o)),a<i[1]&&this._bandIntervals.push(o);const h=_(this._bandIntervals);this._barsData=h.map((i=>({rangeStart:i[0],rangeEnd:i[1],count:m(s,i)})))}}_updateTimelineData(){var i;if((null===(i=this._timeData)||void 0===i?void 0:i.length)&&this._dateExtent){if(this._isNumericTimeline=!(this._timeData[0]instanceof Date),this._isNumericTimeline)this._getBarsData(this._dateExtent);else{this._timeData=this._timeData.map((i=>new Date(i)));const i=this._dateExtent.map((i=>{var t;return null!==(t=i.getTime())&&void 0!==t?t:0}));this._getBarsData(i)}this._maxCount=Math.max(...this._barsData.map((i=>i.count)))}}setBrush(i){var t,s;i&&this._dateExtent&&i[0]>this._dateExtent[0]&&i[1]<this._dateExtent[1]&&i[0]<i[1]?(this._currentSelection=i,this._currentSelectionInPixels=this._currentSelection.map(this._activeAxisScale),null===(t=this._animationControlDiv)||void 0===t||t.classList.remove(v.disabled)):(this._currentSelection=void 0,this._currentSelectionInPixels=void 0,null===(s=this._animationControlDiv)||void 0===s||s.classList.add(v.disabled)),this._brushInstance&&!this._firstRender&&this._brushGroup.call(this._brushInstance.move,this._currentSelectionInPixels)}setBrushInPixels(i){var t,s,n,e,a;i&&i[0]>0&&i[1]<this._timelineWidth&&i[0]<i[1]?(this._currentSelection=i.map((i=>this._activeAxisScale.invert(i))),this._currentSelectionInPixels=null===(t=this._currentSelection)||void 0===t?void 0:t.map(this._activeAxisScale),null===(s=this._animationControlDiv)||void 0===s||s.classList.remove(v.disabled)):(this._currentSelection=void 0,this._currentSelectionInPixels=void 0,null===(n=this._animationControlDiv)||void 0===n||n.classList.add(v.disabled)),this._brushInstance&&!this._firstRender&&this._brushGroup.call(this._brushInstance.move,this._currentSelectionInPixels),null===(a=(e=this._config.events).onBrush)||void 0===a||a.call(e,this._currentSelection)}resize(){const{height:i,width:t}=g(this._containerNode),{offsetWidth:s}=this._animationControlDiv;this._width=t,this._height=i,this._timelineWidth=this._width-this._config.padding.left-this._config.padding.right-s,this._timelineHeight=this._height-this._config.padding.top-this._config.padding.bottom,this._timelineHeight>this._config.padding.top+this._config.padding.bottom&&(this._updateScales(),this._checkLastTickPosition(),this._currentSelection&&this.setBrush(this._currentSelection),this.render())}render(){this._updateBrush(),this._updateBars(),this._updateAxis(),this._firstRender&&(this._firstRender=!1)}_updateAxis(){this._timeData&&(this._axisGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top+this._config.axisTickHeight+1+this._config.brushPadding/2}px)`).call(this._isNumericTimeline?this._numAxis:this._timeAxis).call((i=>i.select(".domain").remove())),this._axisGroup.selectAll(".tick").select("text").attr("class",v.axisTick).attr("y",0).attr("dy",-this._config.axisTickHeight).attr("dx","5px"),this._axisGroup.selectAll("line").attr("class",v.axisLine).attr("y2",-this._config.axisTickHeight))}_updateBrush(){var i;this._config.enableBrush&&(this._brushGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top}px)`),this._brushInstance=s().extent([[0,0],[this._timelineWidth,this._timelineHeight]]),this._brushInstance.on("end",(({selection:i,sourceEvent:t})=>{var s,n,e,a,o,h,r;t&&(i?(this._currentSelection=i.map((i=>this._activeAxisScale.invert(i))),this._currentSelectionInPixels=null===(s=this._currentSelection)||void 0===s?void 0:s.map(this._activeAxisScale),null===(n=this._animationControlDiv)||void 0===n||n.classList.remove(v.disabled),null===(a=(e=this._config.events).onBrush)||void 0===a||a.call(e,this._currentSelection)):(this._currentSelection=void 0,this._currentSelectionInPixels=void 0,null===(h=(o=this._config.events).onBrush)||void 0===h||h.call(o,void 0),null===(r=this._animationControlDiv)||void 0===r||r.classList.add(v.disabled)))})),this._brushGroup.call(this._brushInstance),this._currentSelection?(this._currentSelectionInPixels=this._currentSelection.map(this._activeAxisScale),this._brushGroup.call(this._brushInstance.move,this._currentSelectionInPixels)):null===(i=this._brushInstance)||void 0===i||i.clear(this._brushGroup),this._brushGroup.select("rect.selection").classed(v.selection,!0).attr("rx",this._config.brushRadius).attr("ry",this._config.brushRadius))}_updateBars(){this._barsGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top-this._config.brushPadding/2}px)`);const i=this._barsGroup.selectAll(`.${v.bar}`).data(this._barsData).join("rect").attr("class",v.bar).attr("x",(i=>this._activeAxisScale(+i.rangeStart)+this._barPadding/2)).attr("width",this.getBarWidth()).attr("rx",this._config.barRadius).attr("ry",this._config.barRadius).attr("y",-this._timelineHeight);this._config.events.onBarHover&&i.on("mouseover",this._config.events.onBarHover),i.transition().duration(300).attr("height",(i=>this._yScale(i.count))).style("opacity",(i=>this._yScale(i.count)===this._config.minBarHeight?.25:1))}_updateScales(){if(!this._dateExtent||!this._barsData.length)return;const i=this._barsData[this._barsData.length-1];if(this._config.tickStep){const i=l(+this._dateExtent[0],+this._dateExtent[1],this._config.tickStep);this._isNumericTimeline?this._numAxis.tickValues(i):this._timeAxis.tickValues(i.map((i=>new Date(i))))}this._yScale.range([this._config.minBarHeight,this._timelineHeight-this._config.barTopMargin-this._config.brushPadding]).domain([0,this._maxCount]).clamp(!0),this._isNumericTimeline?(this._numScale.domain([this._dateExtent[0],i.rangeEnd]).range([0,this._timelineWidth]).clamp(!0),this._activeAxisScale=this._numScale):(this._timeScale.domain([this._dateExtent[0],i.rangeEnd]).range([0,this._timelineWidth]).clamp(!0),this._activeAxisScale=this._timeScale);const t=this._barsData[0],s=this._activeAxisScale(t.rangeEnd)-this._activeAxisScale(t.rangeStart);this._barWidth=s}_disableBrush(){var i,t;null===(i=this._brushInstance)||void 0===i||i.clear(this._brushGroup),this._currentSelectionInPixels=void 0,this._currentSelection=void 0,this.pauseAnimation(),this._brushGroup.selectAll("*").remove(),this._config.showAnimationControl&&(null===(t=this._animationControlDiv)||void 0===t||t.classList.add(v.disabled))}async _initAnimationControls(){this._containerNode.insertBefore(this._animationControlDiv,this._svg);await(async()=>{var i,t;if(!this._animationControlDiv.firstChild){const s=this._svgParser.parseFromString(c,"image/svg+xml").firstChild,n=this._svgParser.parseFromString(d,"image/svg+xml").firstChild;this._pauseButtonSvg=null===(i=this._animationControlDiv)||void 0===i?void 0:i.appendChild(n),this._playButtonSvg=null===(t=this._animationControlDiv)||void 0===t?void 0:t.appendChild(s)}})().then((()=>{var i,t,s,n,e;this._isAnimationRunning?(null===(s=this._playButtonSvg)||void 0===s||s.classList.add(v.playAnimation,v.hidden),null===(n=this._pauseButtonSvg)||void 0===n||n.classList.add(v.pauseAnimation)):(null===(i=this._playButtonSvg)||void 0===i||i.classList.add(v.playAnimation),null===(t=this._pauseButtonSvg)||void 0===t||t.classList.add(v.pauseAnimation,v.hidden)),this._currentSelection||null===(e=this._animationControlDiv)||void 0===e||e.classList.add(v.disabled),this._animationControlDiv.addEventListener("click",(()=>this._toggleAnimation()))}))}}export{p as Timeline};
import"d3-transition";import{ResizeObserver as i}from"@juggle/resize-observer";import{axisBottom as t}from"d3-axis";import{brushX as s}from"d3-brush";import{scaleSymlog as n,scaleTime as e,scaleLinear as a}from"d3-scale";import{select as o}from"d3-selection";import{extent as h,rollup as r,range as l,pairs as _}from"d3-array";import{play as c,pause as d}from"./assets.js";import{TimelineConfig as u}from"./config.js";export{TimelineConfig}from"./config.js";import v from"./style.module.css.js";import{getCountsInRange as m,getInnerDimensions as g}from"../../utils.js";class p{constructor(s,h){var r;if(this._isAnimationRunning=!1,this._svgParser=new DOMParser,this._height=0,this._width=0,this._timelineWidth=0,this._timelineHeight=0,this._config=new u,this._barWidth=0,this._maxCount=0,this._barsData=[],this._timeData=void 0,this._bandIntervals=[],this._isNumericTimeline=!1,this._firstRender=!0,this._yScale=n(),this._timeScale=e(),this._numScale=a(),this._activeAxisScale=this._timeScale,this._timeAxis=t(this._timeScale),this._numAxis=t(this._numScale),this._toggleAnimation=()=>{this._isAnimationRunning?this.pauseAnimation():this.playAnimation()},this._disableAnimation=()=>{var i,t;this.pauseAnimation(),null===(i=this._animationControlDiv)||void 0===i||i.removeEventListener("click",this._toggleAnimation),null===(t=this._animationControlDiv)||void 0===t||t.remove()},this.playAnimation=()=>{var i,t,s,n;clearInterval(this._animationInterval),this._currentSelectionInPixels&&(this._animationInterval=setInterval(this._animateSelection,this._config.animationSpeed),this._isAnimationRunning=!0,null===(t=(i=this._config.events).onAnimationPlay)||void 0===t||t.call(i,this._isAnimationRunning,this._currentSelection)),null===(s=this._pauseButtonSvg)||void 0===s||s.classList.remove(v.hidden),null===(n=this._playButtonSvg)||void 0===n||n.classList.add(v.hidden)},this.pauseAnimation=()=>{var i,t,s,n;clearInterval(this._animationInterval),this._isAnimationRunning=!1,null===(t=(i=this._config.events).onAnimationPause)||void 0===t||t.call(i,this._isAnimationRunning,this._currentSelection),null===(s=this._pauseButtonSvg)||void 0===s||s.classList.add(v.hidden),null===(n=this._playButtonSvg)||void 0===n||n.classList.remove(v.hidden)},this.stopAnimation=()=>{var i,t;this.pauseAnimation(),this.setBrush(void 0),null===(t=(i=this._config.events).onBrush)||void 0===t||t.call(i,void 0)},this._animateSelection=()=>{var i,t;const s=this._currentSelectionInPixels;s&&void 0!==s[0]&&void 0!==s[1]&&(this.setBrushInPixels([s[0]+this._barWidth,s[1]+this._barWidth]),s[1]!==(null===(i=this._currentSelectionInPixels)||void 0===i?void 0:i[1])&&void 0!==(null===(t=this._currentSelectionInPixels)||void 0===t?void 0:t[1])||this.stopAnimation())},this._checkLastTickPosition=()=>{var i;const t=this._axisGroup.selectAll(".tick:last-of-type").nodes();if(null==t?void 0:t.length){const s=t[0],n=null==s?void 0:s.getBoundingClientRect().right,e=null===(i=this._svg)||void 0===i?void 0:i.getBoundingClientRect().right;s.style.display=n>=e?"none":"inherit"}},this.destroy=()=>{this._containerNode.innerHTML="",clearInterval(this._animationInterval)},h&&this._config.init(h),this._containerNode=s,this._svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._svg.classList.add(v.timelineSvg),this._animationControlDiv=document.createElement("div"),this._animationControlDiv.classList.add(v.animationControl),this._containerNode.classList.add(v.timeline),this._containerNode.appendChild(this._svg),this._noDataDiv=document.createElement("div"),o(this._noDataDiv).style("display","none").attr("class",v.noData).append("div").text("No timeline data"),this._containerNode.appendChild(this._noDataDiv),null===(r=this._config)||void 0===r?void 0:r.showAnimationControl){const i=setInterval((()=>{null!==this._containerNode&&(this._initAnimationControls(),clearInterval(i))}),100)}this._barsGroup=o(this._svg).append("g").attr("class",v.bars),this._axisGroup=o(this._svg).append("g").attr("class",v.axis),this._brushGroup=o(this._svg).append("g").attr("class",v.brush),this._timeAxis.tickFormat(this._config.dateFormat),this._numAxis.tickFormat(this._config.numFormat),this._resizeObserver=new i((i=>{window.requestAnimationFrame((()=>{Array.isArray(i)&&i.length&&this.resize()}))})),this._resizeObserver=new i((()=>{this.resize()})),this._resizeObserver.observe(this._containerNode)}get _barPadding(){return this._barWidth*this._config.barPadding}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInPixels(){return this._currentSelectionInPixels}getBarWidth(){return this._barWidth-this._barPadding}getConfig(){return this._config}getIsAnimationRunning(){return this._isAnimationRunning}setConfig(i){var t,s,n,e,a,o;const h=JSON.parse(JSON.stringify(this._config));i?this._config.init(i):this._config=new u,(null===(t=this._config)||void 0===t?void 0:t.showAnimationControl)?(null===(s=this._animationControlDiv)||void 0===s?void 0:s.isConnected)||this._initAnimationControls():this._animationControlDiv&&this._disableAnimation(),this._config.enableBrush||this._disableBrush(),(null===(n=this._config)||void 0===n?void 0:n.dataStep)===(null===(e=h.config)||void 0===e?void 0:e.dataStep)&&(null===(a=this._config)||void 0===a?void 0:a.barCount)===(null===(o=h.config)||void 0===o?void 0:o.barCount)||this._updateTimelineData(),this.resize()}setTimeData(i){var t,s,n;this._timeData=null==i?void 0:i.filter((i=>!isNaN(+i)&&void 0!==i)),this._currentSelection=void 0,null===(s=(t=this._config.events).onBrush)||void 0===s||s.call(t,this._currentSelection),this._updateScales(),o(this._noDataDiv).style("display","none"),(null===(n=this._timeData)||void 0===n?void 0:n.length)?(this._dateExtent=h(this._timeData),this._updateTimelineData()):(this._barsData=[],this._axisGroup.selectAll("*").remove(),this._barsGroup.selectAll("*").remove(),this._brushGroup.selectAll("*").remove(),o(this._noDataDiv).style("display","block"),this._firstRender=!0)}_getBarsData(i,t){var s,n;if(!(i[1]<=i[0])&&(null===(s=this._timeData)||void 0===s?void 0:s.length)&&this._dateExtent){const s=r(this._timeData,(i=>i.length),(i=>i)),e=null!==(n=this._config.dataStep)&&void 0!==n?n:(i[1]-i[0])/(this._config.barCount-1);if(0===e)return;this._bandIntervals=l(+i[0],+i[1],e);const a=this._bandIntervals[this._bandIntervals.length-1];let o=this._config.dataStep?+a+e:i[1];t&&(this._bandIntervals=this._bandIntervals.map((i=>new Date(i))),o=new Date(o)),a<i[1]&&this._bandIntervals.push(o);const h=_(this._bandIntervals);this._barsData=h.map((i=>({rangeStart:i[0],rangeEnd:i[1],count:m(s,i)})))}}_updateTimelineData(){var i;if((null===(i=this._timeData)||void 0===i?void 0:i.length)&&this._dateExtent){if(this._isNumericTimeline=!(this._timeData[0]instanceof Date),this._isNumericTimeline)this._getBarsData(this._dateExtent);else{this._timeData=this._timeData.map((i=>new Date(i)));const i=this._dateExtent.map((i=>{var t;return null!==(t=i.getTime())&&void 0!==t?t:0}));this._getBarsData(i)}this._maxCount=Math.max(...this._barsData.map((i=>i.count)))}}setBrush(i){var t,s;i&&this._dateExtent&&i[0]>this._dateExtent[0]&&i[1]<this._dateExtent[1]&&i[0]<i[1]?(this._currentSelection=i,this._currentSelectionInPixels=this._currentSelection.map(this._activeAxisScale),null===(t=this._animationControlDiv)||void 0===t||t.classList.remove(v.disabled)):(this._currentSelection=void 0,this._currentSelectionInPixels=void 0,null===(s=this._animationControlDiv)||void 0===s||s.classList.add(v.disabled)),this._brushInstance&&!this._firstRender&&this._brushGroup.call(this._brushInstance.move,this._currentSelectionInPixels)}setBrushInPixels(i){var t,s,n;i&&i[0]>0&&i[1]<this._timelineWidth&&i[0]<i[1]?(this._currentSelection=i.map((i=>this._activeAxisScale.invert(i))),this._currentSelectionInPixels=null===(t=this._currentSelection)||void 0===t?void 0:t.map(this._activeAxisScale),null===(s=this._animationControlDiv)||void 0===s||s.classList.remove(v.disabled)):(this._currentSelection=void 0,this._currentSelectionInPixels=void 0,null===(n=this._animationControlDiv)||void 0===n||n.classList.add(v.disabled)),this._brushInstance&&!this._firstRender&&this._brushGroup.call(this._brushInstance.move,this._currentSelectionInPixels)}resize(){const{height:i,width:t}=g(this._containerNode),{offsetWidth:s}=this._animationControlDiv;this._width=t,this._height=i,this._timelineWidth=this._width-this._config.padding.left-this._config.padding.right-s,this._timelineHeight=this._height-this._config.padding.top-this._config.padding.bottom,this._timelineHeight>this._config.padding.top+this._config.padding.bottom&&(this._updateScales(),this._checkLastTickPosition(),this._currentSelection&&this.setBrush(this._currentSelection),this.render())}render(){this._updateBrush(),this._updateBars(),this._updateAxis(),this._firstRender&&(this._firstRender=!1)}_updateAxis(){this._timeData&&(this._axisGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top+this._config.axisTickHeight+1+this._config.brushPadding/2}px)`).call(this._isNumericTimeline?this._numAxis:this._timeAxis).call((i=>i.select(".domain").remove())),this._axisGroup.selectAll(".tick").select("text").attr("class",v.axisTick).attr("y",0).attr("dy",-this._config.axisTickHeight).attr("dx","5px"),this._axisGroup.selectAll("line").attr("class",v.axisLine).attr("y2",-this._config.axisTickHeight))}_updateBrush(){var i;this._config.enableBrush&&(this._brushGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top}px)`),this._brushInstance=s().extent([[0,0],[this._timelineWidth,this._timelineHeight]]),this._brushInstance.on("end",(({selection:i,sourceEvent:t})=>{var s,n,e,a,o,h,r;t&&(i?(this._currentSelection=i.map((i=>this._activeAxisScale.invert(i))),this._currentSelectionInPixels=null===(s=this._currentSelection)||void 0===s?void 0:s.map(this._activeAxisScale),null===(n=this._animationControlDiv)||void 0===n||n.classList.remove(v.disabled),null===(a=(e=this._config.events).onBrush)||void 0===a||a.call(e,this._currentSelection)):(this._currentSelection=void 0,this._currentSelectionInPixels=void 0,null===(h=(o=this._config.events).onBrush)||void 0===h||h.call(o,void 0),null===(r=this._animationControlDiv)||void 0===r||r.classList.add(v.disabled)))})),this._brushGroup.call(this._brushInstance),this._currentSelection?(this._currentSelectionInPixels=this._currentSelection.map(this._activeAxisScale),this._brushGroup.call(this._brushInstance.move,this._currentSelectionInPixels)):null===(i=this._brushInstance)||void 0===i||i.clear(this._brushGroup),this._brushGroup.select("rect.selection").classed(v.selection,!0).attr("rx",this._config.brushRadius).attr("ry",this._config.brushRadius))}_updateBars(){this._barsGroup.style("transform",`translate(${this._config.padding.left}px, ${this._config.padding.top-this._config.brushPadding/2}px)`);const i=this._barsGroup.selectAll(`.${v.bar}`).data(this._barsData).join("rect").attr("class",v.bar).attr("x",(i=>this._activeAxisScale(+i.rangeStart)+this._barPadding/2)).attr("width",this.getBarWidth()).attr("rx",this._config.barRadius).attr("ry",this._config.barRadius).attr("y",-this._timelineHeight);this._config.events.onBarHover&&i.on("mouseover",this._config.events.onBarHover),i.transition().duration(300).attr("height",(i=>this._yScale(i.count))).style("opacity",(i=>this._yScale(i.count)===this._config.minBarHeight?.25:1))}_updateScales(){if(!this._dateExtent||!this._barsData.length)return;const i=this._barsData[this._barsData.length-1];if(this._config.tickStep){const i=l(+this._dateExtent[0],+this._dateExtent[1],this._config.tickStep);this._isNumericTimeline?this._numAxis.tickValues(i):this._timeAxis.tickValues(i.map((i=>new Date(i))))}this._yScale.range([this._config.minBarHeight,this._timelineHeight-this._config.barTopMargin-this._config.brushPadding]).domain([0,this._maxCount]).clamp(!0),this._isNumericTimeline?(this._numScale.domain([this._dateExtent[0],i.rangeEnd]).range([0,this._timelineWidth]).clamp(!0),this._activeAxisScale=this._numScale):(this._timeScale.domain([this._dateExtent[0],i.rangeEnd]).range([0,this._timelineWidth]).clamp(!0),this._activeAxisScale=this._timeScale);const t=this._barsData[0],s=this._activeAxisScale(t.rangeEnd)-this._activeAxisScale(t.rangeStart);this._barWidth=s}_disableBrush(){var i,t;null===(i=this._brushInstance)||void 0===i||i.clear(this._brushGroup),this._currentSelectionInPixels=void 0,this._currentSelection=void 0,this.pauseAnimation(),this._brushGroup.selectAll("*").remove(),this._config.showAnimationControl&&(null===(t=this._animationControlDiv)||void 0===t||t.classList.add(v.disabled))}async _initAnimationControls(){this._containerNode.insertBefore(this._animationControlDiv,this._svg);await(async()=>{var i,t;if(!this._animationControlDiv.firstChild){const s=this._svgParser.parseFromString(c,"image/svg+xml").firstChild,n=this._svgParser.parseFromString(d,"image/svg+xml").firstChild;this._pauseButtonSvg=null===(i=this._animationControlDiv)||void 0===i?void 0:i.appendChild(n),this._playButtonSvg=null===(t=this._animationControlDiv)||void 0===t?void 0:t.appendChild(s)}})().then((()=>{var i,t,s,n,e;this._isAnimationRunning?(null===(s=this._playButtonSvg)||void 0===s||s.classList.add(v.playAnimation,v.hidden),null===(n=this._pauseButtonSvg)||void 0===n||n.classList.add(v.pauseAnimation)):(null===(i=this._playButtonSvg)||void 0===i||i.classList.add(v.playAnimation),null===(t=this._pauseButtonSvg)||void 0===t||t.classList.add(v.pauseAnimation,v.hidden)),this._currentSelection||null===(e=this._animationControlDiv)||void 0===e||e.classList.add(v.disabled),this._animationControlDiv.addEventListener("click",(()=>this._toggleAnimation()))}))}}export{p as Timeline};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import e from'./../../ext/rollup-plugin-styles/dist/runtime/inject-css.js';var o=":root{--cosmograph-timeline-text-color:#fff;--cosmograph-timeline-axis-color:#fff;--cosmograph-timeline-selection-color:#777;--cosmograph-timeline-selection-opacity:0.5;--cosmograph-timeline-bar-color:#7a7a7a;--cosmograph-timeline-font-family:inherit;--cosmograph-timeline-font-size:11px;--cosmograph-timeline-background:#222}.style_module_timeline__d5740de7{background:var(--cosmograph-timeline-background);display:flex;position:relative;width:100%}.style_module_timelineSvg__d5740de7{height:100%;position:relative;width:100%}.style_module_selection__d5740de7{fill:var(--cosmograph-timeline-selection-color);fill-opacity:var(--cosmograph-timeline-selection-opacity);stroke:none}.style_module_axisTick__d5740de7{text-anchor:initial;alignment-baseline:text-before-edge;color:var(--cosmograph-timeline-axis-color);font:var(--cosmograph-timeline-font-family);font-size:var(--cosmograph-timeline-font-size);font-weight:400;opacity:.7;user-select:none}.style_module_axisLine__d5740de7{color:var(--cosmograph-timeline-axis-color);opacity:.2}.style_module_bar__d5740de7{fill:var(--cosmograph-timeline-bar-color);opacity:0;transform:scaleY(-1)}.style_module_noData__d5740de7{height:100%;position:absolute;top:0;width:100%}.style_module_noData__d5740de7 div{align-items:center;display:flex;font-size:calc(var(--cosmograph-timeline-font-size) + 5px);font-weight:300;height:100%;justify-content:center;letter-spacing:1;opacity:.25;user-select:none}.style_module_animationControl__d5740de7{align-items:center;color:var(--cosmograph-timeline-axis-color);cursor:pointer;display:flex;height:100%;justify-content:center;max-width:30px;min-width:20px;opacity:.5;position:relative;user-select:none;width:6%}.style_module_animationControl__d5740de7>svg{max-height:20px;padding-right:2px;width:50%}.style_module_hidden__d5740de7{display:none}.style_module_disabled__d5740de7{opacity:.2;pointer-events:none}",i={timeline:"style_module_timeline__d5740de7",timelineSvg:"style_module_timelineSvg__d5740de7",selection:"style_module_selection__d5740de7",axisTick:"style_module_axisTick__d5740de7",axisLine:"style_module_axisLine__d5740de7",bar:"style_module_bar__d5740de7",noData:"style_module_noData__d5740de7",axis:"style_module_axis__d5740de7",bars:"style_module_bars__d5740de7",brush:"style_module_brush__d5740de7",animationControl:"style_module_animationControl__d5740de7",hidden:"style_module_hidden__d5740de7",disabled:"style_module_disabled__d5740de7",playAnimation:"style_module_playAnimation__d5740de7",pauseAnimation:"style_module_pauseAnimation__d5740de7"};e(o,{});export{o as css,i as default};
import e from'./../../ext/rollup-plugin-styles/dist/runtime/inject-css.js';var o=":root{--cosmograph-timeline-text-color:#fff;--cosmograph-timeline-axis-color:#fff;--cosmograph-timeline-selection-color:#777;--cosmograph-timeline-selection-opacity:0.5;--cosmograph-timeline-bar-color:#7a7a7a;--cosmograph-timeline-font-family:inherit;--cosmograph-timeline-font-size:11px;--cosmograph-timeline-background:#222}.style_module_timeline__f90332e1{background:var(--cosmograph-timeline-background);display:flex;overflow:hidden;position:relative;width:100%}.style_module_timelineSvg__f90332e1{height:100%;position:relative;width:100%}.style_module_selection__f90332e1{fill:var(--cosmograph-timeline-selection-color);fill-opacity:var(--cosmograph-timeline-selection-opacity);stroke:none}.style_module_axisTick__f90332e1{text-anchor:initial;alignment-baseline:text-before-edge;color:var(--cosmograph-timeline-axis-color);font:var(--cosmograph-timeline-font-family);font-size:var(--cosmograph-timeline-font-size);font-weight:400;opacity:.7;user-select:none}.style_module_axisLine__f90332e1{color:var(--cosmograph-timeline-axis-color);opacity:.2}.style_module_bar__f90332e1{fill:var(--cosmograph-timeline-bar-color);opacity:0;transform:scaleY(-1)}.style_module_noData__f90332e1{height:100%;position:absolute;top:0;width:100%}.style_module_noData__f90332e1 div{align-items:center;display:flex;font-size:calc(var(--cosmograph-timeline-font-size) + 5px);font-weight:300;height:100%;justify-content:center;letter-spacing:1;opacity:.25;user-select:none}.style_module_animationControl__f90332e1{align-items:center;color:var(--cosmograph-timeline-axis-color);cursor:pointer;display:flex;height:100%;justify-content:center;max-width:30px;min-width:20px;opacity:.5;position:relative;user-select:none;width:6%}.style_module_animationControl__f90332e1>svg{max-height:20px;padding-right:2px;width:50%}.style_module_hidden__f90332e1{display:none}.style_module_disabled__f90332e1{opacity:.2;pointer-events:none}",i={timeline:"style_module_timeline__f90332e1",timelineSvg:"style_module_timelineSvg__f90332e1",selection:"style_module_selection__f90332e1",axisTick:"style_module_axisTick__f90332e1",axisLine:"style_module_axisLine__f90332e1",bar:"style_module_bar__f90332e1",noData:"style_module_noData__f90332e1",axis:"style_module_axis__f90332e1",bars:"style_module_bars__f90332e1",brush:"style_module_brush__f90332e1",animationControl:"style_module_animationControl__f90332e1",hidden:"style_module_hidden__f90332e1",disabled:"style_module_disabled__f90332e1",playAnimation:"style_module_playAnimation__f90332e1",pauseAnimation:"style_module_pauseAnimation__f90332e1"};e(o,{});export{o as css,i as default};
//# sourceMappingURL=style.module.css.js.map
{
"name": "@cosmograph/ui",
"version": "0.0.3-beta.1",
"version": "0.0.3-beta.2",
"description": "Cosmograph UI Components",

@@ -5,0 +5,0 @@ "author": "cosmograph-org",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc