From 57ab1a1e0f65a9edc74098a8f600d314a6322a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sko=C4=8D=C3=ADk?= Date: Sun, 14 Nov 2021 12:58:39 +0100 Subject: [PATCH] v3.3.3 --- dist/svelecte-element.js | 2 +- dist/svelecte.css | 4 +- dist/svelecte.mjs | 2 +- docs/build/app.css | 4 +- docs/build/app.js | 10217 ++++++++++++++++++++++++++++- docs/src/10-custom-remote.svelte | 5 + package.json | 2 +- 7 files changed, 10228 insertions(+), 8 deletions(-) diff --git a/dist/svelecte-element.js b/dist/svelecte-element.js index 8cde94d..6153ce9 100644 --- a/dist/svelecte-element.js +++ b/dist/svelecte-element.js @@ -1 +1 @@ -var Svelecte=function(e){"use strict";function t(){}const n=e=>e;function i(e){return e()}function l(){return Object.create(null)}function r(e){e.forEach(i)}function s(e){return"function"==typeof e}function o(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}function a(e,...n){if(null==e)return t;const i=e.subscribe(...n);return i.unsubscribe?()=>i.unsubscribe():i}function c(e,t,n){e.$$.on_destroy.push(a(t,n))}function d(e,t,n,i){if(e){const l=u(e,t,n,i);return e[0](l)}}function u(e,t,n,i){return e[1]&&i?function(e,t){for(const n in t)e[n]=t[n];return e}(n.ctx.slice(),e[1](i(t))):n.ctx}function h(e,t,n,i){if(e[2]&&i){const l=e[2](i(n));if(void 0===t.dirty)return l;if("object"==typeof l){const e=[],n=Math.max(t.dirty.length,l.length);for(let i=0;i32){const t=[],n=e.ctx.length/32;for(let e=0;ewindow.performance.now():()=>Date.now(),x=b?e=>requestAnimationFrame(e):t;const y=new Set;function w(e){y.forEach((t=>{t.c(e)||(y.delete(t),t.f())})),0!==y.size&&x(w)}function S(e,t){e.appendChild(t)}function A(e,t,n){const i=z(e);if(!i.getElementById(t)){const e=O("style");e.id=t,e.textContent=n,k(i,e)}}function z(e){if(!e)return document;const t=e.getRootNode?e.getRootNode():e.ownerDocument;return t&&t.host?t:e.ownerDocument}function k(e,t){S(e.head||e,t)}function I(e,t,n){e.insertBefore(t,n||null)}function C(e){e.parentNode.removeChild(e)}function q(e,t){for(let n=0;ne.removeEventListener(t,n,i)}function M(e){return function(t){return t.preventDefault(),e.call(this,t)}}function _(e,t,n){null==n?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function H(e,t){t=""+t,e.wholeText!==t&&(e.data=t)}function P(e,t){e.value=null==t?"":t}let L;function R(){if(void 0===L){L=!1;try{"undefined"!=typeof window&&window.parent&&window.parent.document}catch(e){L=!0}}return L}function V(e,t,n){e.classList[n?"add":"remove"](t)}class N{constructor(){this.e=this.n=null}c(e){this.h(e)}m(e,t,n=null){this.e||(this.e=O(t.nodeName),this.t=t,this.c(e)),this.i(n)}h(e){this.e.innerHTML=e,this.n=Array.from(this.e.childNodes)}i(e){for(let t=0;t>>0}(d)}_${o}`,h=z(e);j.add(h);const p=h.__svelte_stylesheet||(h.__svelte_stylesheet=function(e){const t=O("style");return k(z(e),t),t}(e).sheet),f=h.__svelte_rules||(h.__svelte_rules={});f[u]||(f[u]=!0,p.insertRule(`@keyframes ${u} ${d}`,p.cssRules.length));const m=e.style.animation||"";return e.style.animation=`${m?`${m}, `:""}${u} ${i}ms linear ${l}ms 1 both`,G+=1,u}function K(e,t){const n=(e.style.animation||"").split(", "),i=n.filter(t?e=>e.indexOf(t)<0:e=>-1===e.indexOf("__svelte")),l=n.length-i.length;l&&(e.style.animation=i.join(", "),G-=l,G||x((()=>{G||(j.forEach((e=>{const t=e.__svelte_stylesheet;let n=t.cssRules.length;for(;n--;)t.deleteRule(n);e.__svelte_rules={}})),j.clear())})))}function Q(e,i,l,r){if(!i)return t;const s=e.getBoundingClientRect();if(i.left===s.left&&i.right===s.right&&i.top===s.top&&i.bottom===s.bottom)return t;const{delay:o=0,duration:a=300,easing:c=n,start:d=$()+o,end:u=d+a,tick:h=t,css:p}=l(e,{from:i,to:s},r);let f,m=!0,g=!1;function v(){p&&K(e,f),m=!1}return function(e){let t;0===y.size&&x(w),new Promise((n=>{y.add(t={c:e,f:n})}))}((e=>{if(!g&&e>=d&&(g=!0),g&&e>=u&&(h(1,0),v()),!m)return!1;if(g){const t=0+1*c((e-d)/a);h(t,1-t)}return!0})),p&&(f=W(e,0,1,a,o,c,p)),o||(g=!0),h(0,1),v}function U(e){const t=getComputedStyle(e);if("absolute"!==t.position&&"fixed"!==t.position){const{width:n,height:i}=t,l=e.getBoundingClientRect();e.style.position="absolute",e.style.width=n,e.style.height=i,function(e,t){const n=e.getBoundingClientRect();if(t.left!==n.left||t.top!==n.top){const i=getComputedStyle(e),l="none"===i.transform?"":i.transform;e.style.transform=`${l} translate(${t.left-n.left}px, ${t.top-n.top}px)`}}(e,l)}}function J(e){B=e}function X(){if(!B)throw new Error("Function called outside component initialization");return B}function Z(e){X().$$.on_mount.push(e)}function Y(e){X().$$.on_destroy.push(e)}function ee(){const e=X();return(t,n)=>{const i=e.$$.callbacks[t];if(i){const l=function(e,t,n=!1){const i=document.createEvent("CustomEvent");return i.initCustomEvent(e,n,!1,t),i}(t,n);i.slice().forEach((t=>{t.call(e,l)}))}}}function te(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach((e=>e.call(this,t)))}const ne=[],ie=[],le=[],re=[],se=Promise.resolve();let oe=!1;function ae(){oe||(oe=!0,se.then(pe))}function ce(){return ae(),se}function de(e){le.push(e)}let ue=!1;const he=new Set;function pe(){if(!ue){ue=!0;do{for(let e=0;e{me.delete(e),i&&(n&&e.d(1),i())})),e.o(t)}}function ye(e,t){xe(e,1,1,(()=>{t.delete(e.key)}))}function we(e,t){e.f(),ye(e,t)}function Se(e,t,n,i,l,r,s,o,a,c,d,u){let h=e.length,p=r.length,f=h;const m={};for(;f--;)m[e[f].key]=f;const g=[],v=new Map,b=new Map;for(f=p;f--;){const e=u(l,r,f),o=n(e);let a=s.get(o);a?i&&a.p(e,t):(a=c(o,e),a.c()),v.set(o,g[f]=a),o in m&&b.set(o,Math.abs(f-m[o]))}const $=new Set,x=new Set;function y(e){$e(e,1),e.m(o,d),s.set(e.key,e),d=e.first,p--}for(;h&&p;){const t=g[p-1],n=e[h-1],i=t.key,l=n.key;t===n?(d=t.first,h--,p--):v.has(l)?!s.has(i)||$.has(i)?y(t):x.has(l)?h--:b.get(i)>b.get(l)?(x.add(i),y(t)):($.add(l),h--):(a(n,s),h--)}for(;h--;){const t=e[h];v.has(t.key)||a(t,s)}for(;p;)y(g[p-1]);return g}function Ae(e){e&&e.c()}function ze(e,t,n,l){const{fragment:o,on_mount:a,on_destroy:c,after_update:d}=e.$$;o&&o.m(t,n),l||de((()=>{const t=a.map(i).filter(s);c?c.push(...t):r(t),e.$$.on_mount=[]})),d.forEach(de)}function ke(e,t){const n=e.$$;null!==n.fragment&&(r(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Ie(e,n,i,s,o,a,c,d=[-1]){const u=B;J(e);const h=e.$$={fragment:null,ctx:null,props:a,update:t,not_equal:o,bound:l(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(n.context||(u?u.$$.context:[])),callbacks:l(),dirty:d,skip_bound:!1,root:n.target||u.$$.root};c&&c(h.root);let p=!1;if(h.ctx=i?i(e,n.props||{},((t,n,...i)=>{const l=i.length?i[0]:n;return h.ctx&&o(h.ctx[t],h.ctx[t]=l)&&(!h.skip_bound&&h.bound[t]&&h.bound[t](l),p&&function(e,t){-1===e.$$.dirty[0]&&(ne.push(e),ae(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<{const e=n.indexOf(t);-1!==e&&n.splice(e,1)}}$set(e){var t;this.$$set&&(t=e,0!==Object.keys(t).length)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}var qe=function(e,t){this.items=e,this.settings=t||{diacritics:!0}};qe.prototype.tokenize=function(e,t){if(!(e=De(String(e||"").toLowerCase()))||!e.length)return[];var n,i,l,r,s=[],o=e.split(/ +/);for(n=0,i=o.length;n0)&&i.items.push({score:n,id:l})})):s.iterator(s.items,(function(e,t){i.items.push({score:1,id:t})})),(l=s.getSortFunction(i,t))&&i.items.sort(l),i.total=i.items.length,"number"==typeof t.limit&&(i.items=i.items.slice(0,t.limit)),i};var Oe=function(e,t){return"number"==typeof e&&"number"==typeof t?e>t?1:e(t=_e(String(t||"")))?1:t>e?-1:0},Ee=function(e,t){var n,i,l,r;for(n=1,i=arguments.length;n'+r+"";Pe||(Pe=document.createElement("div"),Pe.className="sv-item-content"),Pe.innerHTML=r;return _e(n).split(" ").filter((e=>e)).forEach((e=>{Ve(Pe,e)})),Pe.outerHTML}const Ve=function(e,t){let n=0;if(3===e.nodeType){const i=_e(e.data);let l=i.indexOf(t);if(l-=i.substr(0,l).toUpperCase().length-i.substr(0,l).length,l>=0){const i=document.createElement("span");i.className="highlight";const r=e.splitText(l);r.splitText(t.length);const s=r.cloneNode(!0);i.appendChild(s),r.parentNode.replaceChild(i,r),n=1}}else if(1===e.nodeType&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&("highlight"!==e.className||"SPAN"!==e.tagName))for(var i=0;ir.includes(e))).concat([Object.keys(e)[n]]).shift()}return l}const je={disabled:!1,valueField:null,labelField:null,disabledField:"$disabled",placeholder:"Select",valueAsObject:!1,searchable:!0,clearable:!1,selectOnTab:!1,resetOnBlur:!0,fetchResetOnBlur:!0,multiple:!1,max:0,collapseSelection:!1,creatable:!1,creatablePrefix:"*",keepCreated:!0,allowEditing:!1,delimiter:",",fetchCallback:null,minQuery:1,lazyDropdown:!0,virtualList:!1,vlItemSize:null,vlHeight:null,i18n:{empty:"No options",nomatch:"No matching options",max:e=>`Maximum items ${e} selected`,fetchBefore:"Type to start searching",fetchQuery:(e,t)=>`Type ${e>1&&e>t?`at least ${e-t} characters `:""}to start searching`,fetchEmpty:"No data related to your search",collapsedSelection:e=>`${e} selected`,createRowLabel:e=>`Create '${e}'`},collapseSelectionFn:function(e,t){return je.i18n.collapsedSelection(e)}},Be=[];function Ge(e,n=t){let i;const l=new Set;function r(t){if(o(e,t)&&(e=t,i)){const t=!Be.length;for(const t of l)t[1](),Be.push(t,e);if(t){for(let e=0;e{l.delete(a),0===l.size&&(i(),i=null)}}}}function We(e,t,n){if(e&&!t){const t=Array.isArray(e)?e:[e];return this.reduce(((e,i)=>(t.includes(i[n])&&e.push(i),e)),[])}return t&&e?Array.isArray(e)?e:[e]:[]}function Ke(e,t){const n=e.reduce(((e,n,i)=>t.isOptionArray?(e.push({[t.valueField]:i,[t.labelField]:n}),e):n.options&&n.options.length?(t.optionsWithGroups=!0,e.push({label:n.label,$isGroupHeader:!0}),e.push(...n.options.map((e=>(e.$isGroupItem=!0,e)))),e):(e.push(n),e)),[]);return function(e,t){t.isOptionArray&&(t.optionProps||(t.optionProps=["value","label"]));e.some((e=>!e.$isGroupHeader&&(t.optionProps=Qe(e),!0)))}(n,t),n}function Qe(e){e.options&&(e=e.options[0]);const t=["$disabled","$isGroupHeader","$isGroupItem"];return Object.keys(e).filter((e=>!t.includes(e)))}function Ue(e){const t=e-1;return t*t*t+1}function Je(e,{from:t,to:n},i={}){const l=getComputedStyle(e),r="none"===l.transform?"":l.transform,[o,a]=l.transformOrigin.split(" ").map(parseFloat),c=t.left+t.width*o/n.width-(n.left+o),d=t.top+t.height*a/n.height-(n.top+a),{delay:u=0,duration:h=(e=>120*Math.sqrt(e)),easing:p=Ue}=i;return{delay:u,duration:s(h)?h(Math.sqrt(c*c+d*d)):h,easing:p,css:(e,i)=>{const l=i*c,s=i*d,o=e+i*t.width/n.width,a=e+i*t.height/n.height;return`transform: ${r} translate(${l}px, ${s}px) scale(${o}, ${a});`}}}function Xe(e){A(e,"svelte-x1t6fd",".inputBox.svelte-x1t6fd{box-sizing:content-box;width:19px;background:rgba(0, 0, 0, 0) none repeat scroll 0px center;border:0px none;font-size:inherit;font-family:inherit;opacity:1;outline:currentcolor none 0px;padding:0px;color:inherit;margin:-2px 0 0;height:20px}.inputBox.svelte-x1t6fd::placeholder{color:var(--sv-placeholder-color, #ccccd6)}.inputBox.svelte-x1t6fd:read-only{width:100%}.shadow-text.svelte-x1t6fd{opacity:0;position:absolute;left:100%;z-index:-100;min-width:24px;white-space:nowrap;top:0;left:0}")}function Ze(e){let n,i,l,s,o,a,c,d;return{c(){n=O("input"),l=F(),s=O("div"),o=E(e[9]),_(n,"type","text"),_(n,"class","inputBox svelte-x1t6fd"),n.disabled=e[1],n.readOnly=i=!e[0],_(n,"style",e[8]),_(n,"placeholder",e[5]),_(s,"class","shadow-text svelte-x1t6fd"),de((()=>e[24].call(s)))},m(t,i){var r;I(t,n,i),e[22](n),P(n,e[6]),I(t,l,i),I(t,s,i),S(s,o),a=function(e,t){"static"===getComputedStyle(e).position&&(e.style.position="relative");const n=O("iframe");n.setAttribute("style","display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; border: 0; opacity: 0; pointer-events: none; z-index: -1;"),n.setAttribute("aria-hidden","true"),n.tabIndex=-1;const i=R();let l;return i?(n.src="data:text/html,"; + unsubscribe = listen(window, 'message', (event) => { + if (event.source === iframe.contentWindow) + fn(); + }); + } + else { + iframe.src = 'about:blank'; + iframe.onload = () => { + unsubscribe = listen(iframe.contentWindow, 'resize', fn); + }; + } + append(node, iframe); + return () => { + if (crossorigin) { + unsubscribe(); + } + else if (unsubscribe && iframe.contentWindow) { + unsubscribe(); + } + detach(iframe); + }; + } + function toggle_class(element, name, toggle) { + element.classList[toggle ? 'add' : 'remove'](name); + } + function custom_event(type, detail, bubbles = false) { + const e = document.createEvent('CustomEvent'); + e.initCustomEvent(type, bubbles, false, detail); + return e; + } + class HtmlTag { + constructor() { + this.e = this.n = null; + } + c(html) { + this.h(html); + } + m(html, target, anchor = null) { + if (!this.e) { + this.e = element(target.nodeName); + this.t = target; + this.c(html); + } + this.i(anchor); + } + h(html) { + this.e.innerHTML = html; + this.n = Array.from(this.e.childNodes); + } + i(anchor) { + for (let i = 0; i < this.n.length; i += 1) { + insert(this.t, this.n[i], anchor); + } + } + p(html) { + this.d(); + this.h(html); + this.i(this.a); + } + d() { + this.n.forEach(detach); + } + } + + const active_docs = new Set(); + let active = 0; + // https://github.com/darkskyapp/string-hash/blob/master/index.js + function hash(str) { + let hash = 5381; + let i = str.length; + while (i--) + hash = ((hash << 5) - hash) ^ str.charCodeAt(i); + return hash >>> 0; + } + function create_rule(node, a, b, duration, delay, ease, fn, uid = 0) { + const step = 16.666 / duration; + let keyframes = '{\n'; + for (let p = 0; p <= 1; p += step) { + const t = a + (b - a) * ease(p); + keyframes += p * 100 + `%{${fn(t, 1 - t)}}\n`; + } + const rule = keyframes + `100% {${fn(b, 1 - b)}}\n}`; + const name = `__svelte_${hash(rule)}_${uid}`; + const doc = get_root_for_style(node); + active_docs.add(doc); + const stylesheet = doc.__svelte_stylesheet || (doc.__svelte_stylesheet = append_empty_stylesheet(node).sheet); + const current_rules = doc.__svelte_rules || (doc.__svelte_rules = {}); + if (!current_rules[name]) { + current_rules[name] = true; + stylesheet.insertRule(`@keyframes ${name} ${rule}`, stylesheet.cssRules.length); + } + const animation = node.style.animation || ''; + node.style.animation = `${animation ? `${animation}, ` : ''}${name} ${duration}ms linear ${delay}ms 1 both`; + active += 1; + return name; + } + function delete_rule(node, name) { + const previous = (node.style.animation || '').split(', '); + const next = previous.filter(name + ? anim => anim.indexOf(name) < 0 // remove specific animation + : anim => anim.indexOf('__svelte') === -1 // remove all Svelte animations + ); + const deleted = previous.length - next.length; + if (deleted) { + node.style.animation = next.join(', '); + active -= deleted; + if (!active) + clear_rules(); + } + } + function clear_rules() { + raf(() => { + if (active) + return; + active_docs.forEach(doc => { + const stylesheet = doc.__svelte_stylesheet; + let i = stylesheet.cssRules.length; + while (i--) + stylesheet.deleteRule(i); + doc.__svelte_rules = {}; + }); + active_docs.clear(); + }); + } + + function create_animation(node, from, fn, params) { + if (!from) + return noop; + const to = node.getBoundingClientRect(); + if (from.left === to.left && from.right === to.right && from.top === to.top && from.bottom === to.bottom) + return noop; + const { delay = 0, duration = 300, easing = identity, + // @ts-ignore todo: should this be separated from destructuring? Or start/end added to public api and documentation? + start: start_time = now() + delay, + // @ts-ignore todo: + end = start_time + duration, tick = noop, css } = fn(node, { from, to }, params); + let running = true; + let started = false; + let name; + function start() { + if (css) { + name = create_rule(node, 0, 1, duration, delay, easing, css); + } + if (!delay) { + started = true; + } + } + function stop() { + if (css) + delete_rule(node, name); + running = false; + } + loop(now => { + if (!started && now >= start_time) { + started = true; + } + if (started && now >= end) { + tick(1, 0); + stop(); + } + if (!running) { + return false; + } + if (started) { + const p = now - start_time; + const t = 0 + 1 * easing(p / duration); + tick(t, 1 - t); + } + return true; + }); + start(); + tick(0, 1); + return stop; + } + function fix_position(node) { + const style = getComputedStyle(node); + if (style.position !== 'absolute' && style.position !== 'fixed') { + const { width, height } = style; + const a = node.getBoundingClientRect(); + node.style.position = 'absolute'; + node.style.width = width; + node.style.height = height; + add_transform(node, a); + } + } + function add_transform(node, a) { + const b = node.getBoundingClientRect(); + if (a.left !== b.left || a.top !== b.top) { + const style = getComputedStyle(node); + const transform = style.transform === 'none' ? '' : style.transform; + node.style.transform = `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`; + } + } + + let current_component; + function set_current_component(component) { + current_component = component; + } + function get_current_component() { + if (!current_component) + throw new Error('Function called outside component initialization'); + return current_component; + } + function onMount(fn) { + get_current_component().$$.on_mount.push(fn); + } + function onDestroy(fn) { + get_current_component().$$.on_destroy.push(fn); + } + function createEventDispatcher() { + const component = get_current_component(); + return (type, detail) => { + const callbacks = component.$$.callbacks[type]; + if (callbacks) { + // TODO are there situations where events could be dispatched + // in a server (non-DOM) environment? + const event = custom_event(type, detail); + callbacks.slice().forEach(fn => { + fn.call(component, event); + }); + } + }; + } + // TODO figure out if we still want to support + // shorthand events, or if we want to implement + // a real bubbling mechanism + function bubble(component, event) { + const callbacks = component.$$.callbacks[event.type]; + if (callbacks) { + // @ts-ignore + callbacks.slice().forEach(fn => fn.call(this, event)); + } + } + + const dirty_components = []; + const binding_callbacks = []; + const render_callbacks = []; + const flush_callbacks = []; + const resolved_promise = Promise.resolve(); + let update_scheduled = false; + function schedule_update() { + if (!update_scheduled) { + update_scheduled = true; + resolved_promise.then(flush); + } + } + function tick() { + schedule_update(); + return resolved_promise; + } + function add_render_callback(fn) { + render_callbacks.push(fn); + } + function add_flush_callback(fn) { + flush_callbacks.push(fn); + } + let flushing = false; + const seen_callbacks = new Set(); + function flush() { + if (flushing) + return; + flushing = true; + do { + // first, call beforeUpdate functions + // and update components + for (let i = 0; i < dirty_components.length; i += 1) { + const component = dirty_components[i]; + set_current_component(component); + update(component.$$); + } + set_current_component(null); + dirty_components.length = 0; + while (binding_callbacks.length) + binding_callbacks.pop()(); + // then, once components are updated, call + // afterUpdate functions. This may cause + // subsequent updates... + for (let i = 0; i < render_callbacks.length; i += 1) { + const callback = render_callbacks[i]; + if (!seen_callbacks.has(callback)) { + // ...so guard against infinite loops + seen_callbacks.add(callback); + callback(); + } + } + render_callbacks.length = 0; + } while (dirty_components.length); + while (flush_callbacks.length) { + flush_callbacks.pop()(); + } + update_scheduled = false; + flushing = false; + seen_callbacks.clear(); + } + function update($$) { + if ($$.fragment !== null) { + $$.update(); + run_all($$.before_update); + const dirty = $$.dirty; + $$.dirty = [-1]; + $$.fragment && $$.fragment.p($$.ctx, dirty); + $$.after_update.forEach(add_render_callback); + } + } + const outroing = new Set(); + let outros; + function group_outros() { + outros = { + r: 0, + c: [], + p: outros // parent group + }; + } + function check_outros() { + if (!outros.r) { + run_all(outros.c); + } + outros = outros.p; + } + function transition_in(block, local) { + if (block && block.i) { + outroing.delete(block); + block.i(local); + } + } + function transition_out(block, local, detach, callback) { + if (block && block.o) { + if (outroing.has(block)) + return; + outroing.add(block); + outros.c.push(() => { + outroing.delete(block); + if (callback) { + if (detach) + block.d(1); + callback(); + } + }); + block.o(local); + } + } + function outro_and_destroy_block(block, lookup) { + transition_out(block, 1, 1, () => { + lookup.delete(block.key); + }); + } + function fix_and_outro_and_destroy_block(block, lookup) { + block.f(); + outro_and_destroy_block(block, lookup); + } + function update_keyed_each(old_blocks, dirty, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, next, get_context) { + let o = old_blocks.length; + let n = list.length; + let i = o; + const old_indexes = {}; + while (i--) + old_indexes[old_blocks[i].key] = i; + const new_blocks = []; + const new_lookup = new Map(); + const deltas = new Map(); + i = n; + while (i--) { + const child_ctx = get_context(ctx, list, i); + const key = get_key(child_ctx); + let block = lookup.get(key); + if (!block) { + block = create_each_block(key, child_ctx); + block.c(); + } + else if (dynamic) { + block.p(child_ctx, dirty); + } + new_lookup.set(key, new_blocks[i] = block); + if (key in old_indexes) + deltas.set(key, Math.abs(i - old_indexes[key])); + } + const will_move = new Set(); + const did_move = new Set(); + function insert(block) { + transition_in(block, 1); + block.m(node, next); + lookup.set(block.key, block); + next = block.first; + n--; + } + while (o && n) { + const new_block = new_blocks[n - 1]; + const old_block = old_blocks[o - 1]; + const new_key = new_block.key; + const old_key = old_block.key; + if (new_block === old_block) { + // do nothing + next = new_block.first; + o--; + n--; + } + else if (!new_lookup.has(old_key)) { + // remove old block + destroy(old_block, lookup); + o--; + } + else if (!lookup.has(new_key) || will_move.has(new_key)) { + insert(new_block); + } + else if (did_move.has(old_key)) { + o--; + } + else if (deltas.get(new_key) > deltas.get(old_key)) { + did_move.add(new_key); + insert(new_block); + } + else { + will_move.add(old_key); + o--; + } + } + while (o--) { + const old_block = old_blocks[o]; + if (!new_lookup.has(old_block.key)) + destroy(old_block, lookup); + } + while (n) + insert(new_blocks[n - 1]); + return new_blocks; + } + + function get_spread_update(levels, updates) { + const update = {}; + const to_null_out = {}; + const accounted_for = { $$scope: 1 }; + let i = levels.length; + while (i--) { + const o = levels[i]; + const n = updates[i]; + if (n) { + for (const key in o) { + if (!(key in n)) + to_null_out[key] = 1; + } + for (const key in n) { + if (!accounted_for[key]) { + update[key] = n[key]; + accounted_for[key] = 1; + } + } + levels[i] = n; + } + else { + for (const key in o) { + accounted_for[key] = 1; + } + } + } + for (const key in to_null_out) { + if (!(key in update)) + update[key] = undefined; + } + return update; + } + function get_spread_object(spread_props) { + return typeof spread_props === 'object' && spread_props !== null ? spread_props : {}; + } + + function bind(component, name, callback) { + const index = component.$$.props[name]; + if (index !== undefined) { + component.$$.bound[index] = callback; + callback(component.$$.ctx[index]); + } + } + function create_component(block) { + block && block.c(); + } + function mount_component(component, target, anchor, customElement) { + const { fragment, on_mount, on_destroy, after_update } = component.$$; + fragment && fragment.m(target, anchor); + if (!customElement) { + // onMount happens before the initial afterUpdate + add_render_callback(() => { + const new_on_destroy = on_mount.map(run).filter(is_function); + if (on_destroy) { + on_destroy.push(...new_on_destroy); + } + else { + // Edge case - component was destroyed immediately, + // most likely as a result of a binding initialising + run_all(new_on_destroy); + } + component.$$.on_mount = []; + }); + } + after_update.forEach(add_render_callback); + } + function destroy_component(component, detaching) { + const $$ = component.$$; + if ($$.fragment !== null) { + run_all($$.on_destroy); + $$.fragment && $$.fragment.d(detaching); + // TODO null out other refs, including component.$$ (but need to + // preserve final state?) + $$.on_destroy = $$.fragment = null; + $$.ctx = []; + } + } + function make_dirty(component, i) { + if (component.$$.dirty[0] === -1) { + dirty_components.push(component); + schedule_update(); + component.$$.dirty.fill(0); + } + component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); + } + function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) { + const parent_component = current_component; + set_current_component(component); + const $$ = component.$$ = { + fragment: null, + ctx: null, + // state + props, + update: noop, + not_equal, + bound: blank_object(), + // lifecycle + on_mount: [], + on_destroy: [], + on_disconnect: [], + before_update: [], + after_update: [], + context: new Map(options.context || (parent_component ? parent_component.$$.context : [])), + // everything else + callbacks: blank_object(), + dirty, + skip_bound: false, + root: options.target || parent_component.$$.root + }; + append_styles && append_styles($$.root); + let ready = false; + $$.ctx = instance + ? instance(component, options.props || {}, (i, ret, ...rest) => { + const value = rest.length ? rest[0] : ret; + if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { + if (!$$.skip_bound && $$.bound[i]) + $$.bound[i](value); + if (ready) + make_dirty(component, i); + } + return ret; + }) + : []; + $$.update(); + ready = true; + run_all($$.before_update); + // `false` as a special case of no DOM component + $$.fragment = create_fragment ? create_fragment($$.ctx) : false; + if (options.target) { + if (options.hydrate) { + const nodes = children(options.target); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + $$.fragment && $$.fragment.l(nodes); + nodes.forEach(detach); + } + else { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + $$.fragment && $$.fragment.c(); + } + if (options.intro) + transition_in(component.$$.fragment); + mount_component(component, options.target, options.anchor, options.customElement); + flush(); + } + set_current_component(parent_component); + } + /** + * Base class for Svelte components. Used when dev=false. + */ + class SvelteComponent { + $destroy() { + destroy_component(this, 1); + this.$destroy = noop; + } + $on(type, callback) { + const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); + callbacks.push(callback); + return () => { + const index = callbacks.indexOf(callback); + if (index !== -1) + callbacks.splice(index, 1); + }; + } + $set($$props) { + if (this.$$set && !is_empty($$props)) { + this.$$.skip_bound = true; + this.$$set($$props); + this.$$.skip_bound = false; + } + } + } + + /** + * sifter.js + * Copyright (c) 2013–2020 Brian Reavis & contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy of the License at: + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF + * ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + * + * @author Brian Reavis + */ + + /** + * Textually searches arrays and hashes of objects + * by property (or multiple properties). Designed + * specifically for autocomplete. + * + * @constructor + * @param {array|object} items + * @param {object} items + */ + var Sifter = function(items, settings) { + this.items = items; + this.settings = settings || {diacritics: true}; + }; + + /** + * Splits a search string into an array of individual + * regexps to be used to match results. + * + * @param {string} query + * @returns {array} + */ + Sifter.prototype.tokenize = function(query, respect_word_boundaries) { + query = trim(String(query || '').toLowerCase()); + if (!query || !query.length) return []; + + var i, n, regex, letter; + var tokens = []; + var words = query.split(/ +/); + + for (i = 0, n = words.length; i < n; i++) { + regex = escape_regex(words[i]); + if (this.settings.diacritics) { + for (letter in DIACRITICS) { + if (DIACRITICS.hasOwnProperty(letter)) { + regex = regex.replace(new RegExp(letter, 'g'), DIACRITICS[letter]); + } + } + } + if (respect_word_boundaries) regex = "\\b"+regex; + tokens.push({ + string : words[i], + regex : new RegExp(regex, 'i') + }); + } + + return tokens; + }; + + /** + * Iterates over arrays and hashes. + * + * ``` + * this.iterator(this.items, function(item, id) { + * // invoked for each item + * }); + * ``` + * + * @param {array|object} object + */ + Sifter.prototype.iterator = function(object, callback) { + var iterator; + if (Array.isArray(object)) { + iterator = Array.prototype.forEach || function(callback) { + for (var i = 0, n = this.length; i < n; i++) { + callback(this[i], i, this); + } + }; + } else { + iterator = function(callback) { + for (var key in this) { + if (this.hasOwnProperty(key)) { + callback(this[key], key, this); + } + } + }; + } + + iterator.apply(object, [callback]); + }; + + /** + * Returns a function to be used to score individual results. + * + * Good matches will have a higher score than poor matches. + * If an item is not a match, 0 will be returned by the function. + * + * @param {object|string} search + * @param {object} options (optional) + * @returns {function} + */ + Sifter.prototype.getScoreFunction = function(search, options) { + var self, fields, tokens, token_count, nesting; + + self = this; + search = self.prepareSearch(search, options); + tokens = search.tokens; + fields = search.options.fields; + token_count = tokens.length; + nesting = search.options.nesting; + + /** + * Calculates how close of a match the + * given value is against a search token. + * + * @param {string | number} value + * @param {object} token + * @return {number} + */ + var scoreValue = function(value, token) { + var score, pos; + + if (!value) return 0; + value = String(value || ''); + pos = value.search(token.regex); + if (pos === -1) return 0; + score = token.string.length / value.length; + if (pos === 0) score += 0.5; + return score; + }; + + /** + * Calculates the score of an object + * against the search query. + * + * @param {object} token + * @param {object} data + * @return {number} + */ + var scoreObject = (function() { + var field_count = fields.length; + if (!field_count) { + return function() { return 0; }; + } + if (field_count === 1) { + return function(token, data) { + return scoreValue(getattr(data, fields[0], nesting), token); + }; + } + return function(token, data) { + for (var i = 0, sum = 0; i < field_count; i++) { + sum += scoreValue(getattr(data, fields[i], nesting), token); + } + return sum / field_count; + }; + })(); + + if (!token_count) { + return function() { return 0; }; + } + if (token_count === 1) { + return function(data) { + return scoreObject(tokens[0], data); + }; + } + + if (search.options.conjunction === 'and') { + return function(data) { + var score; + for (var i = 0, sum = 0; i < token_count; i++) { + score = scoreObject(tokens[i], data); + if (score <= 0) return 0; + sum += score; + } + return sum / token_count; + }; + } else { + return function(data) { + for (var i = 0, sum = 0; i < token_count; i++) { + sum += scoreObject(tokens[i], data); + } + return sum / token_count; + }; + } + }; + + /** + * Returns a function that can be used to compare two + * results, for sorting purposes. If no sorting should + * be performed, `null` will be returned. + * + * @param {string|object} search + * @param {object} options + * @return function(a,b) + */ + Sifter.prototype.getSortFunction = function(search, options) { + var i, n, self, field, fields, fields_count, multiplier, multipliers, get_field, implicit_score, sort; + + self = this; + search = self.prepareSearch(search, options); + sort = (!search.query && options.sort_empty) || options.sort; + + /** + * Fetches the specified sort field value + * from a search result item. + * + * @param {string} name + * @param {object} result + */ + get_field = function(name, result) { + if (name === '$score') return result.score; + return getattr(self.items[result.id], name, options.nesting); + }; + + // parse options + fields = []; + if (sort) { + for (i = 0, n = sort.length; i < n; i++) { + if (search.query || sort[i].field !== '$score') { + fields.push(sort[i]); + } + } + } + + // the "$score" field is implied to be the primary + // sort field, unless it's manually specified + if (search.query) { + implicit_score = true; + for (i = 0, n = fields.length; i < n; i++) { + if (fields[i].field === '$score') { + implicit_score = false; + break; + } + } + if (implicit_score) { + fields.unshift({field: '$score', direction: 'desc'}); + } + } else { + for (i = 0, n = fields.length; i < n; i++) { + if (fields[i].field === '$score') { + fields.splice(i, 1); + break; + } + } + } + + multipliers = []; + for (i = 0, n = fields.length; i < n; i++) { + multipliers.push(fields[i].direction === 'desc' ? -1 : 1); + } + + // build function + fields_count = fields.length; + if (!fields_count) { + return null; + } else if (fields_count === 1) { + field = fields[0].field; + multiplier = multipliers[0]; + return function(a, b) { + return multiplier * cmp( + get_field(field, a), + get_field(field, b) + ); + }; + } else { + return function(a, b) { + var i, result, field; + for (i = 0; i < fields_count; i++) { + field = fields[i].field; + result = multipliers[i] * cmp( + get_field(field, a), + get_field(field, b) + ); + if (result) return result; + } + return 0; + }; + } + }; + + /** + * Parses a search query and returns an object + * with tokens and fields ready to be populated + * with results. + * + * @param {string} query + * @param {object} options + * @returns {object} + */ + Sifter.prototype.prepareSearch = function(query, options) { + if (typeof query === 'object') return query; + + options = extend({}, options); + + var option_fields = options.fields; + var option_sort = options.sort; + var option_sort_empty = options.sort_empty; + + if (option_fields && !Array.isArray(option_fields)) options.fields = [option_fields]; + if (option_sort && !Array.isArray(option_sort)) options.sort = [option_sort]; + if (option_sort_empty && !Array.isArray(option_sort_empty)) options.sort_empty = [option_sort_empty]; + + return { + options : options, + query : String(query || '').toLowerCase(), + tokens : this.tokenize(query, options.respect_word_boundaries), + total : 0, + items : [] + }; + }; + + /** + * Searches through all items and returns a sorted array of matches. + * + * The `options` parameter can contain: + * + * - fields {string|array} + * - sort {array} + * - score {function} + * - filter {bool} + * - limit {integer} + * + * Returns an object containing: + * + * - options {object} + * - query {string} + * - tokens {array} + * - total {int} + * - items {array} + * + * @param {string} query + * @param {object} options + * @returns {object} + */ + Sifter.prototype.search = function(query, options) { + var self = this, score, search; + var fn_sort; + var fn_score; + + search = this.prepareSearch(query, options); + options = search.options; + query = search.query; + + // generate result scoring function + fn_score = options.score || self.getScoreFunction(search); + + // perform search and sort + if (query.length) { + self.iterator(self.items, function(item, id) { + score = fn_score(item); + if (options.filter === false || score > 0) { + search.items.push({'score': score, 'id': id}); + } + }); + } else { + self.iterator(self.items, function(item, id) { + search.items.push({'score': 1, 'id': id}); + }); + } + + fn_sort = self.getSortFunction(search, options); + if (fn_sort) search.items.sort(fn_sort); + + // apply limits + search.total = search.items.length; + if (typeof options.limit === 'number') { + search.items = search.items.slice(0, options.limit); + } + + return search; + }; + + // utilities + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + var cmp = function(a, b) { + if (typeof a === 'number' && typeof b === 'number') { + return a > b ? 1 : (a < b ? -1 : 0); + } + a = asciifold(String(a || '')); + b = asciifold(String(b || '')); + if (a > b) return 1; + if (b > a) return -1; + return 0; + }; + + var extend = function(a, b) { + var i, n, k, object; + for (i = 1, n = arguments.length; i < n; i++) { + object = arguments[i]; + if (!object) continue; + for (k in object) { + if (object.hasOwnProperty(k)) { + a[k] = object[k]; + } + } + } + return a; + }; + + /** + * A property getter resolving dot-notation + * @param {Object} obj The root object to fetch property on + * @param {String} name The optionally dotted property name to fetch + * @param {Boolean} nesting Handle nesting or not + * @return {Object} The resolved property value + */ + var getattr = function(obj, name, nesting) { + if (!obj || !name) return; + if (!nesting) return obj[name]; + var names = name.split("."); + while(names.length && (obj = obj[names.shift()])); + return obj; + }; + + var trim = function(str) { + return (str + '').replace(/^\s+|\s+$|/g, ''); + }; + + var escape_regex = function(str) { + return (str + '').replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); + }; + + var DIACRITICS = { + 'a': '[aḀḁĂăÂâǍǎȺⱥȦȧẠạÄäÀàÁáĀāÃãÅåąĄÃąĄ]', + 'b': '[b␢βΒB฿𐌁ᛒ]', + 'c': '[cĆćĈĉČčĊċC̄c̄ÇçḈḉȻȼƇƈɕᴄCc]', + 'd': '[dĎďḊḋḐḑḌḍḒḓḎḏĐđD̦d̦ƉɖƊɗƋƌᵭᶁᶑȡᴅDdð]', + 'e': '[eÉéÈèÊêḘḙĚěĔĕẼẽḚḛẺẻĖėËëĒēȨȩĘęᶒɆɇȄȅẾếỀềỄễỂểḜḝḖḗḔḕȆȇẸẹỆệⱸᴇEeɘǝƏƐε]', + 'f': '[fƑƒḞḟ]', + 'g': '[gɢ₲ǤǥĜĝĞğĢģƓɠĠġ]', + 'h': '[hĤĥĦħḨḩẖẖḤḥḢḣɦʰǶƕ]', + 'i': '[iÍíÌìĬĭÎîǏǐÏïḮḯĨĩĮįĪīỈỉȈȉȊȋỊịḬḭƗɨɨ̆ᵻᶖİiIıɪIi]', + 'j': '[jȷĴĵɈɉʝɟʲ]', + 'k': '[kƘƙꝀꝁḰḱǨǩḲḳḴḵκϰ₭]', + 'l': '[lŁłĽľĻļĹĺḶḷḸḹḼḽḺḻĿŀȽƚⱠⱡⱢɫɬᶅɭȴʟLl]', + 'n': '[nŃńǸǹŇňÑñṄṅŅņṆṇṊṋṈṉN̈n̈ƝɲȠƞᵰᶇɳȵɴNnŊŋ]', + 'o': '[oØøÖöÓóÒòÔôǑǒŐőŎŏȮȯỌọƟɵƠơỎỏŌōÕõǪǫȌȍՕօ]', + 'p': '[pṔṕṖṗⱣᵽƤƥᵱ]', + 'q': '[qꝖꝗʠɊɋꝘꝙq̃]', + 'r': '[rŔŕɌɍŘřŖŗṘṙȐȑȒȓṚṛⱤɽ]', + 's': '[sŚśṠṡṢṣꞨꞩŜŝŠšŞşȘșS̈s̈]', + 't': '[tŤťṪṫŢţṬṭƮʈȚțṰṱṮṯƬƭ]', + 'u': '[uŬŭɄʉỤụÜüÚúÙùÛûǓǔŰűŬŭƯưỦủŪūŨũŲųȔȕ∪]', + 'v': '[vṼṽṾṿƲʋꝞꝟⱱʋ]', + 'w': '[wẂẃẀẁŴŵẄẅẆẇẈẉ]', + 'x': '[xẌẍẊẋχ]', + 'y': '[yÝýỲỳŶŷŸÿỸỹẎẏỴỵɎɏƳƴ]', + 'z': '[zŹźẐẑŽžŻżẒẓẔẕƵƶ]' + }; + + const asciifold = (function() { + var i, n, k, chunk; + var foreignletters = ''; + var lookup = {}; + for (k in DIACRITICS) { + if (DIACRITICS.hasOwnProperty(k)) { + chunk = DIACRITICS[k].substring(2, DIACRITICS[k].length - 1); + foreignletters += chunk; + for (i = 0, n = chunk.length; i < n; i++) { + lookup[chunk.charAt(i)] = k; + } + } + } + var regexp = new RegExp('[' + foreignletters + ']', 'g'); + return function(str) { + return str.replace(regexp, function(foreignletter) { + return lookup[foreignletter]; + }).toLowerCase(); + }; + })(); + + // source: https://github.com/rob-balfre/svelte-select/blob/master/src/utils/isOutOfViewport.js + function isOutOfViewport(elem) { + if (!elem) return false; + const bounding = elem.getBoundingClientRect(); + const out = {}; + + out.top = bounding.top < 0 || bounding.top - bounding.height < 0; + out.left = bounding.left < 0; + out.bottom = bounding.bottom > (window.innerHeight || document.documentElement.clientHeight); + out.right = bounding.right > (window.innerWidth || document.documentElement.clientWidth); + out.any = out.top || out.left || out.bottom || out.right; + + return out; + } + let xhr = null; + + function fetchRemote(url) { + return function(query, cb) { + return new Promise((resolve, reject) => { + xhr = new XMLHttpRequest(); + xhr.open('GET', `${url.replace('[query]', encodeURIComponent(query))}`); + xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + xhr.send(); + + xhr.onreadystatechange = () => { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + const resp = JSON.parse(xhr.response); + resolve(cb ? cb(resp) : resp.data || resp.items || resp.options || resp); + } else { + reject(); + } + } + }; + }); + } + } + + let timeout; + function debounce(fn, delay) { + return function() { + const self = this; + const args = arguments; + clearTimeout(timeout); + timeout = setTimeout(function() { + fn.apply(self, args); + }, delay); + }; + } + let itemHtml; + + function highlightSearch(item, isSelected, $inputValue, formatter, disableHighlight) { + const itemHtmlText = formatter ? formatter(item, isSelected, $inputValue) : item; + + if ($inputValue == '' || item.isSelected || disableHighlight) { + return '
' + itemHtmlText + '
'; + } + + if (!itemHtml) { + itemHtml = document.createElement('div'); + itemHtml.className = 'sv-item-content'; + } + itemHtml.innerHTML = itemHtmlText; + + // const regex = new RegExp(`(${asciifold($inputValue)})`, 'ig'); + const pattern = asciifold($inputValue); + pattern.split(' ').filter(e => e).forEach(pat => { + highlight(itemHtml, pat); + }); + + return itemHtml.outerHTML; + } + + /** + * highlight function code from selectize itself. We pass raw html through @html svelte tag + * base from https://github.com/selectize/selectize.js/blob/master/src/contrib/highlight.js & edited + */ + const highlight = function(node, regex) { + let skip = 0; + // Wrap matching part of text node with highlighting , e.g. + // Soccer -> Soccer for pattern 'soc' + if (node.nodeType === 3) { + const folded = asciifold(node.data); + let pos = folded.indexOf(regex); + pos -= (folded.substr(0, pos).toUpperCase().length - folded.substr(0, pos).length); + if (pos >= 0 ) { + const spannode = document.createElement('span'); + spannode.className = 'highlight'; + const middlebit = node.splitText(pos); + middlebit.splitText(regex.length); + const middleclone = middlebit.cloneNode(true); + spannode.appendChild(middleclone); + middlebit.parentNode.replaceChild(spannode, middlebit); + skip = 1; + } + } + // Recurse element node, looking for child text nodes to highlight, unless element + // is childless,