function noop() { } function assign(tar, src) { // @ts-ignore for (const k in src) tar[k] = src[k]; return tar; } function run(fn) { return fn(); } function blank_object() { return Object.create(null); } function run_all(fns) { fns.forEach(run); } function is_function(thing) { return typeof thing === 'function'; } function safe_not_equal(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function is_empty(obj) { return Object.keys(obj).length === 0; } function create_slot(definition, ctx, $$scope, fn) { if (definition) { const slot_ctx = get_slot_context(definition, ctx, $$scope, fn); return definition[0](slot_ctx); } } function get_slot_context(definition, ctx, $$scope, fn) { return definition[1] && fn ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) : $$scope.ctx; } function get_slot_changes(definition, $$scope, dirty, fn) { if (definition[2] && fn) { const lets = definition[2](fn(dirty)); if ($$scope.dirty === undefined) { return lets; } if (typeof lets === 'object') { const merged = []; const len = Math.max($$scope.dirty.length, lets.length); for (let i = 0; i < len; i += 1) { merged[i] = $$scope.dirty[i] | lets[i]; } return merged; } return $$scope.dirty | lets; } return $$scope.dirty; } function update_slot(slot, slot_definition, ctx, $$scope, dirty, get_slot_changes_fn, get_slot_context_fn) { const slot_changes = get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn); if (slot_changes) { const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn); slot.p(slot_context, slot_changes); } } function exclude_internal_props(props) { const result = {}; for (const k in props) if (k[0] !== '$') result[k] = props[k]; return result; } function compute_rest_props(props, keys) { const rest = {}; keys = new Set(keys); for (const k in props) if (!keys.has(k) && k[0] !== '$') rest[k] = props[k]; return rest; } function append(target, node) { target.appendChild(node); } function insert(target, node, anchor) { target.insertBefore(node, anchor || null); } function detach(node) { node.parentNode.removeChild(node); } function element(name) { return document.createElement(name); } function text(data) { return document.createTextNode(data); } function space() { return text(' '); } function listen(node, event, handler, options) { node.addEventListener(event, handler, options); return () => node.removeEventListener(event, handler, options); } function prevent_default(fn) { return function (event) { event.preventDefault(); // @ts-ignore return fn.call(this, event); }; } function attr(node, attribute, value) { if (value == null) node.removeAttribute(attribute); else if (node.getAttribute(attribute) !== value) node.setAttribute(attribute, value); } function set_attributes(node, attributes) { // @ts-ignore const descriptors = Object.getOwnPropertyDescriptors(node.__proto__); for (const key in attributes) { if (attributes[key] == null) { node.removeAttribute(key); } else if (key === 'style') { node.style.cssText = attributes[key]; } else if (key === '__value') { node.value = node[key] = attributes[key]; } else if (descriptors[key] && descriptors[key].set) { node[key] = attributes[key]; } else { attr(node, key, attributes[key]); } } } function children(element) { return Array.from(element.childNodes); } function set_data(text, data) { data = '' + data; if (text.wholeText !== data) text.data = data; } function set_input_value(input, value) { input.value = value == null ? '' : value; } function toggle_class(element, name, toggle) { element.classList[toggle ? 'add' : 'remove'](name); } function custom_event(type, detail) { const e = document.createEvent('CustomEvent'); e.initCustomEvent(type, false, false, detail); return e; } 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 afterUpdate(fn) { get_current_component().$$.after_update.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) { callbacks.slice().forEach(fn => fn(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 add_render_callback(fn) { render_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 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 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 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, 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(parent_component ? parent_component.$$.context : []), // everything else callbacks: blank_object(), dirty, skip_bound: false }; 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; } } } /* src/Search.svelte generated by Svelte v3.35.0 */ function add_css() { var style = element("style"); style.id = "svelte-5m0wg6-style"; style.textContent = ".hide-label.svelte-5m0wg6{position:absolute;height:1px;width:1px;overflow:hidden;clip:rect(1px 1px 1px 1px);clip:rect(1px, 1px, 1px, 1px);white-space:nowrap}"; append(document.head, style); } const get_label_slot_changes = dirty => ({}); const get_label_slot_context = ctx => ({}); // (60:23) {label} function fallback_block(ctx) { let t; return { c() { t = text(/*label*/ ctx[2]); }, m(target, anchor) { insert(target, t, anchor); }, p(ctx, dirty) { if (dirty & /*label*/ 4) set_data(t, /*label*/ ctx[2]); }, d(detaching) { if (detaching) detach(t); } }; } function create_fragment(ctx) { let form; let label_1; let label_1_id_value; let t; let input; let form_role_value; let form_aria_labelledby_value; let current; let mounted; let dispose; const label_slot_template = /*#slots*/ ctx[10].label; const label_slot = create_slot(label_slot_template, ctx, /*$$scope*/ ctx[9], get_label_slot_context); const label_slot_or_fallback = label_slot || fallback_block(ctx); let input_levels = [ { name: "search" }, { type: "search" }, { placeholder: "Search..." }, { autocomplete: "off" }, { spellcheck: "false" }, /*$$restProps*/ ctx[6], { id: /*id*/ ctx[4] } ]; let input_data = {}; for (let i = 0; i < input_levels.length; i += 1) { input_data = assign(input_data, input_levels[i]); } return { c() { form = element("form"); label_1 = element("label"); if (label_slot_or_fallback) label_slot_or_fallback.c(); t = space(); input = element("input"); attr(label_1, "id", label_1_id_value = "" + (/*id*/ ctx[4] + "-label")); attr(label_1, "for", /*id*/ ctx[4]); attr(label_1, "class", "svelte-5m0wg6"); toggle_class(label_1, "hide-label", /*hideLabel*/ ctx[3]); set_attributes(input, input_data); toggle_class(input, "svelte-5m0wg6", true); attr(form, "data-svelte-search", ""); attr(form, "role", form_role_value = /*removeFormAriaAttributes*/ ctx[5] ? null : "search"); attr(form, "aria-labelledby", form_aria_labelledby_value = /*removeFormAriaAttributes*/ ctx[5] ? null : /*id*/ ctx[4]); }, m(target, anchor) { insert(target, form, anchor); append(form, label_1); if (label_slot_or_fallback) { label_slot_or_fallback.m(label_1, null); } append(form, t); append(form, input); /*input_binding*/ ctx[17](input); set_input_value(input, /*value*/ ctx[0]); current = true; if (!mounted) { dispose = [ listen(input, "input", /*input_input_handler*/ ctx[18]), listen(input, "input", /*input_handler*/ ctx[12]), listen(input, "change", /*change_handler*/ ctx[13]), listen(input, "focus", /*focus_handler*/ ctx[14]), listen(input, "blur", /*blur_handler*/ ctx[15]), listen(input, "keydown", /*keydown_handler*/ ctx[16]), listen(form, "submit", prevent_default(/*submit_handler*/ ctx[11])) ]; mounted = true; } }, p(ctx, [dirty]) { if (label_slot) { if (label_slot.p && dirty & /*$$scope*/ 512) { update_slot(label_slot, label_slot_template, ctx, /*$$scope*/ ctx[9], dirty, get_label_slot_changes, get_label_slot_context); } } else { if (label_slot_or_fallback && label_slot_or_fallback.p && dirty & /*label*/ 4) { label_slot_or_fallback.p(ctx, dirty); } } if (!current || dirty & /*id*/ 16 && label_1_id_value !== (label_1_id_value = "" + (/*id*/ ctx[4] + "-label"))) { attr(label_1, "id", label_1_id_value); } if (!current || dirty & /*id*/ 16) { attr(label_1, "for", /*id*/ ctx[4]); } if (dirty & /*hideLabel*/ 8) { toggle_class(label_1, "hide-label", /*hideLabel*/ ctx[3]); } set_attributes(input, input_data = get_spread_update(input_levels, [ { name: "search" }, { type: "search" }, { placeholder: "Search..." }, { autocomplete: "off" }, { spellcheck: "false" }, dirty & /*$$restProps*/ 64 && /*$$restProps*/ ctx[6], (!current || dirty & /*id*/ 16) && { id: /*id*/ ctx[4] } ])); if (dirty & /*value*/ 1) { set_input_value(input, /*value*/ ctx[0]); } toggle_class(input, "svelte-5m0wg6", true); if (!current || dirty & /*removeFormAriaAttributes*/ 32 && form_role_value !== (form_role_value = /*removeFormAriaAttributes*/ ctx[5] ? null : "search")) { attr(form, "role", form_role_value); } if (!current || dirty & /*removeFormAriaAttributes, id*/ 48 && form_aria_labelledby_value !== (form_aria_labelledby_value = /*removeFormAriaAttributes*/ ctx[5] ? null : /*id*/ ctx[4])) { attr(form, "aria-labelledby", form_aria_labelledby_value); } }, i(local) { if (current) return; transition_in(label_slot_or_fallback, local); current = true; }, o(local) { transition_out(label_slot_or_fallback, local); current = false; }, d(detaching) { if (detaching) detach(form); if (label_slot_or_fallback) label_slot_or_fallback.d(detaching); /*input_binding*/ ctx[17](null); mounted = false; run_all(dispose); } }; } function instance($$self, $$props, $$invalidate) { const omit_props_names = [ "value","autofocus","debounce","label","hideLabel","id","ref","removeFormAriaAttributes" ]; let $$restProps = compute_rest_props($$props, omit_props_names); let { $$slots: slots = {}, $$scope } = $$props; let { value = "" } = $$props; let { autofocus = false } = $$props; let { debounce = 0 } = $$props; let { label = "Label" } = $$props; let { hideLabel = false } = $$props; let { id = "search" + Math.random().toString(36) } = $$props; let { ref = null } = $$props; let { removeFormAriaAttributes = false } = $$props; const dispatch = createEventDispatcher(); let prevValue = value; let timeout = undefined; let calling = false; function debounced(cb) { if (calling) return; calling = true; timeout = setTimeout( () => { cb(); calling = false; }, debounce ); } onMount(() => { if (autofocus) window.requestAnimationFrame(() => ref.focus()); return () => clearTimeout(timeout); }); afterUpdate(() => { if (value.length > 0 && value !== prevValue) { if (debounce > 0) { debounced(() => dispatch("type", value)); } else { dispatch("type", value); } } if (value.length === 0 && prevValue.length > 0) dispatch("clear"); prevValue = value; }); function submit_handler(event) { bubble($$self, event); } function input_handler(event) { bubble($$self, event); } function change_handler(event) { bubble($$self, event); } function focus_handler(event) { bubble($$self, event); } function blur_handler(event) { bubble($$self, event); } function keydown_handler(event) { bubble($$self, event); } function input_binding($$value) { binding_callbacks[$$value ? "unshift" : "push"](() => { ref = $$value; $$invalidate(1, ref); }); } function input_input_handler() { value = this.value; $$invalidate(0, value); } $$self.$$set = $$new_props => { $$props = assign(assign({}, $$props), exclude_internal_props($$new_props)); $$invalidate(6, $$restProps = compute_rest_props($$props, omit_props_names)); if ("value" in $$new_props) $$invalidate(0, value = $$new_props.value); if ("autofocus" in $$new_props) $$invalidate(7, autofocus = $$new_props.autofocus); if ("debounce" in $$new_props) $$invalidate(8, debounce = $$new_props.debounce); if ("label" in $$new_props) $$invalidate(2, label = $$new_props.label); if ("hideLabel" in $$new_props) $$invalidate(3, hideLabel = $$new_props.hideLabel); if ("id" in $$new_props) $$invalidate(4, id = $$new_props.id); if ("ref" in $$new_props) $$invalidate(1, ref = $$new_props.ref); if ("removeFormAriaAttributes" in $$new_props) $$invalidate(5, removeFormAriaAttributes = $$new_props.removeFormAriaAttributes); if ("$$scope" in $$new_props) $$invalidate(9, $$scope = $$new_props.$$scope); }; return [ value, ref, label, hideLabel, id, removeFormAriaAttributes, $$restProps, autofocus, debounce, $$scope, slots, submit_handler, input_handler, change_handler, focus_handler, blur_handler, keydown_handler, input_binding, input_input_handler ]; } class Search extends SvelteComponent { constructor(options) { super(); if (!document.getElementById("svelte-5m0wg6-style")) add_css(); init(this, options, instance, create_fragment, safe_not_equal, { value: 0, autofocus: 7, debounce: 8, label: 2, hideLabel: 3, id: 4, ref: 1, removeFormAriaAttributes: 5 }); } } export default Search;