@neovici/cosmoz-utils 4.0.0-beta.2 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/array.d.ts +1 -0
  2. package/dist/array.js +24 -0
  3. package/dist/date.d.ts +39 -0
  4. package/dist/date.js +147 -0
  5. package/dist/directives/lazy-until.d.ts +43 -0
  6. package/dist/directives/lazy-until.js +142 -0
  7. package/dist/directives/measure.d.ts +12 -0
  8. package/dist/directives/measure.js +24 -0
  9. package/dist/directives/portal.d.ts +15 -0
  10. package/dist/directives/portal.js +58 -0
  11. package/dist/directives/spread-props.d.ts +9 -0
  12. package/dist/directives/spread-props.js +22 -0
  13. package/dist/elements/cz-icon.d.ts +8 -0
  14. package/dist/elements/cz-icon.js +15 -0
  15. package/dist/elements/cz-spinner.d.ts +1 -0
  16. package/dist/elements/cz-spinner.js +22 -0
  17. package/dist/elements/index.d.ts +2 -0
  18. package/dist/elements/index.js +2 -0
  19. package/dist/function.d.ts +5 -0
  20. package/dist/function.js +4 -0
  21. package/dist/haunted-polymer.d.ts +341 -0
  22. package/dist/haunted-polymer.js +83 -0
  23. package/dist/hooks/use-debounce-raf.d.ts +16 -0
  24. package/dist/hooks/use-debounce-raf.js +36 -0
  25. package/dist/hooks/use-dropped-files.d.ts +1 -0
  26. package/dist/hooks/use-dropped-files.js +7 -0
  27. package/dist/hooks/use-handle-drop.d.ts +1 -0
  28. package/dist/hooks/use-handle-drop.js +18 -0
  29. package/dist/hooks/use-host-bounds.d.ts +2 -0
  30. package/dist/hooks/use-host-bounds.js +12 -0
  31. package/dist/hooks/use-host.d.ts +3 -0
  32. package/dist/hooks/use-host.js +6 -0
  33. package/dist/hooks/use-imperative-api.d.ts +1 -0
  34. package/dist/hooks/use-imperative-api.js +18 -0
  35. package/dist/hooks/use-meta.d.ts +8 -0
  36. package/{lib → dist}/hooks/use-meta.js +3 -5
  37. package/dist/hooks/use-notify-property.d.ts +2 -0
  38. package/dist/hooks/use-notify-property.js +19 -0
  39. package/dist/hooks/use-promise.d.ts +1 -0
  40. package/dist/hooks/use-promise.js +42 -0
  41. package/dist/index.d.ts +26 -0
  42. package/{index.js → dist/index.js} +14 -24
  43. package/dist/money.d.ts +47 -0
  44. package/dist/money.js +86 -0
  45. package/dist/object.d.ts +21 -0
  46. package/dist/object.js +56 -0
  47. package/dist/promise.d.ts +10 -0
  48. package/dist/promise.js +66 -0
  49. package/dist/reduce/action.d.ts +13 -0
  50. package/dist/reduce/action.js +10 -0
  51. package/{lib/reduce/index.js → dist/reduce/index.d.ts} +0 -0
  52. package/dist/reduce/index.js +2 -0
  53. package/dist/reduce/reduce.d.ts +1 -0
  54. package/dist/reduce/reduce.js +12 -0
  55. package/dist/tag.d.ts +23 -0
  56. package/dist/tag.js +28 -0
  57. package/dist/tagged.d.ts +1 -0
  58. package/{lib → dist}/tagged.js +0 -0
  59. package/dist/template.d.ts +47 -0
  60. package/dist/template.js +66 -0
  61. package/package.json +20 -6
  62. package/lib/array.js +0 -27
  63. package/lib/date.js +0 -176
  64. package/lib/directives/lazy-until.js +0 -163
  65. package/lib/directives/measure.js +0 -32
  66. package/lib/directives/portal.js +0 -65
  67. package/lib/directives/spread-props.js +0 -31
  68. package/lib/function.js +0 -21
  69. package/lib/haunted-polymer.js +0 -93
  70. package/lib/hooks/use-debounce-raf.js +0 -49
  71. package/lib/hooks/use-dropped-files.js +0 -12
  72. package/lib/hooks/use-handle-drop.js +0 -22
  73. package/lib/hooks/use-host-bounds.js +0 -21
  74. package/lib/hooks/use-host.js +0 -9
  75. package/lib/hooks/use-imperative-api.js +0 -22
  76. package/lib/hooks/use-notify-property.js +0 -26
  77. package/lib/hooks/use-promise.js +0 -74
  78. package/lib/money.js +0 -105
  79. package/lib/object.js +0 -26
  80. package/lib/promise.js +0 -88
  81. package/lib/reduce/action.js +0 -16
  82. package/lib/reduce/reduce.js +0 -16
  83. package/lib/tag.js +0 -34
  84. package/lib/template.js +0 -89
@@ -0,0 +1 @@
1
+ export declare const array: (arr: unknown) => any[], without: (exclude: unknown, predicate?: <T>(obj: T) => T) => (list: unknown) => any[];
package/dist/array.js ADDED
@@ -0,0 +1,24 @@
1
+ import { identity } from './function';
2
+ const isIterable = (x) => {
3
+ return typeof x === 'object' && x !== null && Symbol.iterator in x;
4
+ };
5
+ export const array = (arr) => {
6
+ if (arr == null) {
7
+ return [];
8
+ }
9
+ if (Array.isArray(arr)) {
10
+ return arr;
11
+ }
12
+ if (typeof arr === 'string') {
13
+ return [arr];
14
+ }
15
+ if (isIterable(arr)) {
16
+ return Array.from(arr);
17
+ }
18
+ return [arr];
19
+ },
20
+ // TODO: Improve definition
21
+ without = (exclude, predicate = identity) => (list) => {
22
+ const excludes = array(exclude).map(predicate);
23
+ return array(list).filter((value) => !excludes.includes(predicate(value)));
24
+ };
package/dist/date.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ declare const
2
+ /**
3
+ * Validate a Date object or date string.
4
+ * @param {date/string} date Date to check.
5
+ * @return {date} Validated date or undefined on failure.
6
+ */
7
+ ensureDate: <T>(date: T) => Date | undefined,
8
+ /**
9
+ * Format a date as an ISO-date - YYYY-MM-DD.
10
+ * @param {date/string} date Date to be ISO formatted.
11
+ * @return {string} ISO formatted date.
12
+ */
13
+ isoDate: <T>(date: T) => string,
14
+ /**
15
+ * Format a date with time as an ISO date with time - YYYY-MM-DD HH:mm:ss.
16
+ * @param {date/string} date Date to be ISO formatted.
17
+ * @return {string} ISO formatted date.
18
+ */
19
+ isoDT: <T>(date: T) => string,
20
+ /**
21
+ * Check if date is in the past.
22
+ * @param {date/string} date Date to check.
23
+ * @return {boolean} Whether the date is in the past or not.
24
+ */
25
+ pastDate: <T>(date: T) => boolean | undefined,
26
+ /**
27
+ * Get human readable string describing date's difference from now in the current locale language.
28
+ * @param {date/string} date Date to check.
29
+ * @param {string} locale Localized lang to return string in (undefined = browser)
30
+ * @return {string} Date representation string in the current locale language.
31
+ */
32
+ timeago: <T>(date: T, locale?: string) => string,
33
+ /**
34
+ * Alias for isoDate(date), format a date as an ISO-date - YYYY-MM-DD.
35
+ * @param {date/string} date Date to be formatted.
36
+ * @return {string} ISO formatted date.
37
+ */
38
+ renderDate: <T>(date: T) => string, pad: (number: number) => string | number, toLocalISOString: <T>(date: T) => string | null, parseDate: (str: string) => Date | undefined, inputDate: <T>(date: T) => string | undefined;
39
+ export { ensureDate, isoDate, isoDT, pad, pastDate, renderDate, toLocalISOString, timeago, parseDate, inputDate, };
package/dist/date.js ADDED
@@ -0,0 +1,147 @@
1
+ const getValUnitDiff = (date1, date2) => {
2
+ const msDiff = date1.getTime() - date2.getTime(), secDiff = msDiff / 1000, minDiff = secDiff / 60, hourDiff = minDiff / 60, dayDiff = hourDiff / 24, monthDiff = dayDiff / 30, yearDiff = monthDiff / 12;
3
+ if (Math.abs(yearDiff) >= 1) {
4
+ return [yearDiff, 'year'];
5
+ }
6
+ if (Math.abs(monthDiff) >= 1) {
7
+ return [monthDiff, 'month'];
8
+ }
9
+ if (Math.abs(dayDiff) >= 1) {
10
+ return [dayDiff, 'day'];
11
+ }
12
+ if (Math.abs(hourDiff) >= 1) {
13
+ return [hourDiff, 'hour'];
14
+ }
15
+ if (Math.abs(minDiff) >= 1) {
16
+ return [minDiff, 'minute'];
17
+ }
18
+ return [secDiff, 'second'];
19
+ }, rules = { isoBasic: /^\d{4}-\d{2}-\d{2}$/iu }, parse = (val) => {
20
+ if (typeof val === 'string' && rules.isoBasic.test(val)) {
21
+ return new Date(`${val}T00:00`);
22
+ }
23
+ return new Date(val);
24
+ },
25
+ /**
26
+ * Validate a Date object or date string.
27
+ * @param {date/string} date Date to check.
28
+ * @return {date} Validated date or undefined on failure.
29
+ */
30
+ ensureDate = (date) => {
31
+ if (date == null) {
32
+ return;
33
+ }
34
+ if (date instanceof Date && !isNaN(date.getTime())) {
35
+ return date;
36
+ }
37
+ if (!(typeof date === 'number' || typeof date === 'string')) {
38
+ return;
39
+ }
40
+ const ensuredDate = parse(date);
41
+ if (ensuredDate instanceof Date && isNaN(ensuredDate.getTime())) {
42
+ return;
43
+ }
44
+ return ensuredDate;
45
+ },
46
+ /**
47
+ * Format a date as an ISO-date - YYYY-MM-DD.
48
+ * @param {date/string} date Date to be ISO formatted.
49
+ * @return {string} ISO formatted date.
50
+ */
51
+ isoDate = (date) => {
52
+ const d = ensureDate(date);
53
+ if (d == null) {
54
+ return '';
55
+ }
56
+ // Sweden uses ISO8601 human-readable
57
+ return d.toLocaleDateString('sv', {
58
+ year: 'numeric',
59
+ month: 'numeric',
60
+ day: 'numeric',
61
+ });
62
+ },
63
+ /**
64
+ * Format a date with time as an ISO date with time - YYYY-MM-DD HH:mm:ss.
65
+ * @param {date/string} date Date to be ISO formatted.
66
+ * @return {string} ISO formatted date.
67
+ */
68
+ isoDT = (date) => {
69
+ const d = ensureDate(date);
70
+ if (d == null) {
71
+ return '';
72
+ }
73
+ // Sweden uses ISO8601 human-readable
74
+ return d.toLocaleDateString('sv', {
75
+ year: 'numeric',
76
+ month: 'numeric',
77
+ day: 'numeric',
78
+ hour: 'numeric',
79
+ minute: 'numeric',
80
+ second: 'numeric',
81
+ });
82
+ },
83
+ /**
84
+ * Check if date is in the past.
85
+ * @param {date/string} date Date to check.
86
+ * @return {boolean} Whether the date is in the past or not.
87
+ */
88
+ pastDate = (date) => {
89
+ const d = ensureDate(date);
90
+ if (d == null) {
91
+ return;
92
+ }
93
+ return d.getTime() < Date.now();
94
+ },
95
+ /**
96
+ * Get human readable string describing date's difference from now in the current locale language.
97
+ * @param {date/string} date Date to check.
98
+ * @param {string} locale Localized lang to return string in (undefined = browser)
99
+ * @return {string} Date representation string in the current locale language.
100
+ */
101
+ timeago = (date, locale) => {
102
+ const d = ensureDate(date);
103
+ if (d == null) {
104
+ return '';
105
+ }
106
+ return new Intl.RelativeTimeFormat(locale, {
107
+ localeMatcher: 'best fit',
108
+ numeric: 'auto',
109
+ style: 'long', // other values: "short" or "narrow"
110
+ }).format(...getValUnitDiff(d, new Date()));
111
+ },
112
+ /**
113
+ * Alias for isoDate(date), format a date as an ISO-date - YYYY-MM-DD.
114
+ * @param {date/string} date Date to be formatted.
115
+ * @return {string} ISO formatted date.
116
+ */
117
+ renderDate = isoDate, pad = (number) => (number < 10 ? '0' + number : number), toLocalISOString = (date) => {
118
+ if (!(date instanceof Date)) {
119
+ return null;
120
+ }
121
+ return (date.getFullYear() +
122
+ '-' +
123
+ pad(date.getMonth() + 1) +
124
+ '-' +
125
+ pad(date.getDate()) +
126
+ 'T' +
127
+ pad(date.getHours()) +
128
+ ':' +
129
+ pad(date.getMinutes()) +
130
+ ':' +
131
+ pad(date.getSeconds()) +
132
+ '.' +
133
+ (date.getMilliseconds() / 1000).toFixed(3).slice(2, 5));
134
+ }, parseDate = (str) => {
135
+ const ts = Date.parse(str);
136
+ if (isNaN(ts)) {
137
+ return;
138
+ }
139
+ return new Date(ts);
140
+ }, inputDate = (date) => {
141
+ const d = ensureDate(date);
142
+ if (d == null) {
143
+ return;
144
+ }
145
+ return (d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()));
146
+ };
147
+ export { ensureDate, isoDate, isoDT, pad, pastDate, renderDate, toLocalISOString, timeago, parseDate, inputDate, };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2017 Google LLC
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+ import { Part } from 'lit-html';
7
+ import { AsyncDirective } from 'lit-html/async-directive.js';
8
+ export declare class UntilDirective extends AsyncDirective {
9
+ private __lastRenderedIndex;
10
+ private __values;
11
+ private __weakThis;
12
+ private __pauser;
13
+ render(...args: Array<unknown>): unknown;
14
+ update(_part: Part, args: Array<unknown>): unknown;
15
+ disconnected(): void;
16
+ reconnected(): void;
17
+ }
18
+ /**
19
+ * Renders one of a series of values, including Promises, to a Part.
20
+ *
21
+ * Values are rendered in priority order, with the first argument having the
22
+ * highest priority and the last argument having the lowest priority. If a
23
+ * value is a Promise, low-priority values will be rendered until it resolves.
24
+ *
25
+ * The priority of values can be used to create placeholder content for async
26
+ * data. For example, a Promise with pending content can be the first,
27
+ * highest-priority, argument, and a non_promise loading indicator template can
28
+ * be used as the second, lower-priority, argument. The loading indicator will
29
+ * render immediately, and the primary content will render when the Promise
30
+ * resolves.
31
+ *
32
+ * Example:
33
+ *
34
+ * ```js
35
+ * const content = fetch('./content.txt').then(r => r.text());
36
+ * html`${until(content, html`<span>Loading...</span>`)}`
37
+ * ```
38
+ */
39
+ export declare const lazyUntil: (...values: unknown[]) => import("lit-html/directive.js").DirectiveResult<typeof UntilDirective>;
40
+ /**
41
+ * The type of the class that powers this directive. Necessary for naming the
42
+ * directive's return type.
43
+ */
@@ -0,0 +1,142 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2017 Google LLC
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+ /* eslint-disable import/group-exports */
7
+ import { noChange } from 'lit-html';
8
+ import { directive } from 'lit-html/directive.js';
9
+ import { isPrimitive } from 'lit-html/directive-helpers.js';
10
+ import { AsyncDirective } from 'lit-html/async-directive.js';
11
+ class PseudoWeakRef {
12
+ _ref;
13
+ constructor(ref) {
14
+ this._ref = ref;
15
+ }
16
+ disconnect() {
17
+ this._ref = undefined;
18
+ }
19
+ reconnect(ref) {
20
+ this._ref = ref;
21
+ }
22
+ deref() {
23
+ return this._ref;
24
+ }
25
+ }
26
+ class Pauser {
27
+ _promise = undefined;
28
+ _resolve = undefined;
29
+ get() {
30
+ return this._promise;
31
+ }
32
+ pause() {
33
+ this._promise ??= new Promise((resolve) => (this._resolve = resolve));
34
+ }
35
+ resume() {
36
+ this._resolve?.();
37
+ this._promise = this._resolve = undefined;
38
+ }
39
+ }
40
+ const isPromise = (x) => {
41
+ return (!isPrimitive(x) && typeof x.then === 'function');
42
+ }, _infinity = 0x3fffffff;
43
+ export class UntilDirective extends AsyncDirective {
44
+ __lastRenderedIndex = _infinity;
45
+ __values = [];
46
+ __weakThis = new PseudoWeakRef(this);
47
+ __pauser = new Pauser();
48
+ render(...args) {
49
+ return args.find((x) => !isPromise(x)) ?? noChange;
50
+ }
51
+ // eslint-disable-next-line max-statements
52
+ update(_part, args) {
53
+ const previousValues = this.__values, previousLength = previousValues.length;
54
+ this.__values = args;
55
+ const weakThis = this.__weakThis, pauser = this.__pauser;
56
+ // If our initial render occurs while disconnected, ensure that the pauser
57
+ // and weakThis are in the disconnected state
58
+ if (!this.isConnected) {
59
+ this.disconnected();
60
+ }
61
+ for (let i = 0; i < args.length; i++) {
62
+ // If we've rendered a higher-priority value already, stop.
63
+ if (i > this.__lastRenderedIndex) {
64
+ break;
65
+ }
66
+ const value = args[i];
67
+ // Render non-Promise values immediately
68
+ if (!isPromise(value)) {
69
+ this.__lastRenderedIndex = i;
70
+ // Since a lower-priority value will never overwrite a higher-priority
71
+ // synchronous value, we can stop processing now.
72
+ return value;
73
+ }
74
+ // If this is a Promise we've already handled, skip it.
75
+ if (i < previousLength && value === previousValues[i]) {
76
+ continue;
77
+ }
78
+ // Note, the callback avoids closing over `this` so that the directive
79
+ // can be gc'ed before the promise resolves; instead `this` is retrieved
80
+ // from `weakThis`, which can break the hard reference in the closure when
81
+ // the directive disconnects
82
+ Promise.resolve(value).then(async (result) => {
83
+ // If we're disconnected, wait until we're (maybe) reconnected
84
+ // The while loop here handles the case that the connection state
85
+ // thrashes, causing the pauser to resume and then get re-paused
86
+ while (pauser.get()) {
87
+ await pauser.get();
88
+ }
89
+ // If the callback gets here and there is no `this`, it means that the
90
+ // directive has been disconnected and garbage collected and we don't
91
+ // need to do anything else
92
+ const _this = weakThis.deref();
93
+ if (_this !== undefined) {
94
+ const index = _this.__values.indexOf(value);
95
+ // If state.values doesn't contain the value, we've re-rendered without
96
+ // the value, so don't render it. Then, only render if the value is
97
+ // higher-priority than what's already been rendered.
98
+ if (index > -1 && index <= _this.__lastRenderedIndex) {
99
+ _this.__lastRenderedIndex = index;
100
+ _this.setValue(result);
101
+ }
102
+ }
103
+ });
104
+ }
105
+ return noChange;
106
+ }
107
+ disconnected() {
108
+ this.__weakThis.disconnect();
109
+ this.__pauser.pause();
110
+ }
111
+ reconnected() {
112
+ this.__weakThis.reconnect(this);
113
+ this.__pauser.resume();
114
+ }
115
+ }
116
+ /**
117
+ * Renders one of a series of values, including Promises, to a Part.
118
+ *
119
+ * Values are rendered in priority order, with the first argument having the
120
+ * highest priority and the last argument having the lowest priority. If a
121
+ * value is a Promise, low-priority values will be rendered until it resolves.
122
+ *
123
+ * The priority of values can be used to create placeholder content for async
124
+ * data. For example, a Promise with pending content can be the first,
125
+ * highest-priority, argument, and a non_promise loading indicator template can
126
+ * be used as the second, lower-priority, argument. The loading indicator will
127
+ * render immediately, and the primary content will render when the Promise
128
+ * resolves.
129
+ *
130
+ * Example:
131
+ *
132
+ * ```js
133
+ * const content = fetch('./content.txt').then(r => r.text());
134
+ * html`${until(content, html`<span>Loading...</span>`)}`
135
+ * ```
136
+ */
137
+ export const lazyUntil = directive(UntilDirective);
138
+ /**
139
+ * The type of the class that powers this directive. Necessary for naming the
140
+ * directive's return type.
141
+ */
142
+ // export type {UntilDirective};
@@ -0,0 +1,12 @@
1
+ import { AttributePart } from 'lit-html';
2
+ import { Directive } from 'lit-html/directive.js';
3
+ declare type OnMeasure = (rects: DOMRectReadOnly[]) => void;
4
+ declare type Select = (el: HTMLElement) => HTMLElement[];
5
+ declare class MeasureDirective extends Directive {
6
+ _observer?: ResizeObserver;
7
+ render(): symbol;
8
+ update(part: AttributePart, [select, onMeasure]: [Select, OnMeasure]): symbol;
9
+ measure(element: HTMLElement, select: Select, onMeasure: OnMeasure): symbol;
10
+ }
11
+ export declare const measure: () => import("lit-html/directive.js").DirectiveResult<typeof MeasureDirective>;
12
+ export {};
@@ -0,0 +1,24 @@
1
+ import { noChange } from 'lit-html';
2
+ import { Directive, directive } from 'lit-html/directive.js';
3
+ import { array } from '../array';
4
+ class MeasureDirective extends Directive {
5
+ _observer;
6
+ render() {
7
+ return noChange;
8
+ }
9
+ update(part, [select, onMeasure]) {
10
+ this.measure(part.element, select, onMeasure);
11
+ return noChange;
12
+ }
13
+ measure(element, select, onMeasure) {
14
+ this._observer?.disconnect();
15
+ const elements = array(select(element)), observer = (this._observer = new ResizeObserver((entries) => {
16
+ onMeasure(entries
17
+ .sort((a, b) => elements.indexOf(a.target) - elements.indexOf(b.target))
18
+ .map((e) => e.contentRect));
19
+ }));
20
+ elements.forEach((el) => observer.observe(el));
21
+ return noChange;
22
+ }
23
+ }
24
+ export const measure = directive(MeasureDirective);
@@ -0,0 +1,15 @@
1
+ import { Part, ChildPart } from 'lit-html';
2
+ import { AsyncDirective } from 'lit-html/async-directive.js';
3
+ declare class PortalDirective extends AsyncDirective {
4
+ _op?: ChildPart;
5
+ _outlet?: HTMLElement;
6
+ _content?: Part;
7
+ render(): import("lit-html").TemplateResult<1>;
8
+ update(part: Part, [content, outlet]: [Part, HTMLElement]): import("lit-html").TemplateResult<1>;
9
+ updateOutlet(outlet: HTMLElement, content: Part): void;
10
+ clearOutlet(): void;
11
+ disconnected(): void;
12
+ reconnected(): void;
13
+ }
14
+ export declare const portal: () => import("lit-html/directive").DirectiveResult<typeof PortalDirective>;
15
+ export {};
@@ -0,0 +1,58 @@
1
+ import { html, nothing, render } from 'lit-html';
2
+ import { AsyncDirective, directive } from 'lit-html/async-directive.js';
3
+ import { setChildPartValue, clearPart, removePart, } from 'lit-html/directive-helpers.js';
4
+ const createMarker = () => document.createComment(''), ChildPartC = render(nothing, new DocumentFragment())
5
+ .constructor;
6
+ /**
7
+ * Helper element with a customizable disconnect behavior.
8
+ */
9
+ class DisconnectObserver extends HTMLElement {
10
+ onDisconnect;
11
+ disconnectedCallback() {
12
+ this.onDisconnect?.();
13
+ }
14
+ }
15
+ customElements.define('disconnect-observer', DisconnectObserver);
16
+ class PortalDirective extends AsyncDirective {
17
+ _op;
18
+ _outlet;
19
+ _content;
20
+ render() {
21
+ return html `<disconnect-observer
22
+ .onDisconnect=${() => {
23
+ this.isConnected = false;
24
+ this.disconnected();
25
+ }}
26
+ ></disconnect-observer>`;
27
+ }
28
+ update(part, [content, outlet = document.body]) {
29
+ this.updateOutlet(outlet, content);
30
+ return this.render();
31
+ }
32
+ updateOutlet(outlet, content) {
33
+ if (this._outlet !== outlet) {
34
+ this.clearOutlet();
35
+ }
36
+ this._outlet = outlet;
37
+ const part = (this._op ??= new ChildPartC(outlet.appendChild(createMarker()), outlet.appendChild(createMarker())));
38
+ setChildPartValue(part, (this._content = content));
39
+ }
40
+ clearOutlet() {
41
+ const part = this._op;
42
+ if (!part) {
43
+ return;
44
+ }
45
+ clearPart(part);
46
+ removePart(part);
47
+ this._op = undefined;
48
+ }
49
+ disconnected() {
50
+ this.clearOutlet();
51
+ }
52
+ reconnected() {
53
+ if (this._outlet && this._content) {
54
+ this.updateOutlet(this._outlet, this._content);
55
+ }
56
+ }
57
+ }
58
+ export const portal = directive(PortalDirective);
@@ -0,0 +1,9 @@
1
+ import { AttributePart } from 'lit-html';
2
+ import { Directive } from 'lit-html/directive.js';
3
+ declare class SpreadPropsDirective<T extends object> extends Directive {
4
+ _props?: T;
5
+ render(): symbol;
6
+ update(part: AttributePart, [props]: [T]): symbol;
7
+ }
8
+ export declare const spreadProps: () => import("lit-html/directive.js").DirectiveResult<typeof SpreadPropsDirective>;
9
+ export {};
@@ -0,0 +1,22 @@
1
+ import { noChange } from 'lit-html';
2
+ import { Directive, directive } from 'lit-html/directive.js';
3
+ const undefs = (prev, obj) => {
4
+ if (!prev || !obj) {
5
+ return;
6
+ }
7
+ const keys = Object.keys(obj);
8
+ return Object.fromEntries(Object.keys(prev).flatMap((k) => (keys.includes(k) ? [] : [[k, undefined]])));
9
+ };
10
+ class SpreadPropsDirective extends Directive {
11
+ _props;
12
+ render() {
13
+ return noChange;
14
+ }
15
+ update(part, [props]) {
16
+ if (this._props !== props) {
17
+ Object.assign(part.element, undefs(this._props, props), (this._props = props));
18
+ }
19
+ return noChange;
20
+ }
21
+ }
22
+ export const spreadProps = directive(SpreadPropsDirective);
@@ -0,0 +1,8 @@
1
+ import { svg } from 'lit-html';
2
+ interface Ico {
3
+ icon?: ReturnType<typeof svg>;
4
+ width?: number;
5
+ height?: number;
6
+ }
7
+ export declare const arrowDropDown: import("lit-html").TemplateResult<2>, cancel: import("lit-html").TemplateResult<2>, check: import("lit-html").TemplateResult<2>, clear: import("lit-html").TemplateResult<2>, warning: import("lit-html").TemplateResult<2>, undo: import("lit-html").TemplateResult<2>, edit: import("lit-html").TemplateResult<2>, rightArrow: import("lit-html").TemplateResult<2>, leftArrow: import("lit-html").TemplateResult<2>, download: import("lit-html").TemplateResult<2>, print: import("lit-html").TemplateResult<2>, renderIcon: ({ icon, width, height }?: Ico) => import("lit-html").TemplateResult<1>;
8
+ export {};
@@ -0,0 +1,15 @@
1
+ import { html, svg } from 'lit-html';
2
+ import { ifDefined } from 'lit-html/directives/if-defined';
3
+ import { component } from 'haunted';
4
+ export const arrowDropDown = svg `<path d="M7 10l5 5 5-5z"></path>`, cancel = svg `<path d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z"></path>`, check = svg `<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"></path>`, clear = svg `<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path>`, warning = svg `<path d="M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" fill="currentColor"></path>`, undo = svg `<path d="M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z"></path>`, edit = svg `<path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"></path>`, rightArrow = svg `<path d="M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z" fill="currentColor"></path>`, leftArrow = svg `<path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z" fill="currentColor"></path>`, download = svg `<path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z" fill="currentColor"></path>`, print = svg `<path d="M19 8H5c-1.66 0-3 1.34-3 3v6h4v4h12v-4h4v-6c0-1.66-1.34-3-3-3zm-3 11H8v-5h8v5zm3-7c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-1-9H6v4h12V3z" fill="currentColor"></path>`, renderIcon = ({ icon, width = 24, height } = {}) => html `<svg
5
+ viewBox="0 0 24 24"
6
+ preserveAspectRatio="xMidYMid meet"
7
+ focusable="false"
8
+ width=${width}
9
+ height=${ifDefined(height)}
10
+ >
11
+ ${icon}
12
+ </svg>`;
13
+ customElements.define('cz-icon', component(renderIcon, {
14
+ observedAttributes: ['width', 'height'],
15
+ }));
@@ -0,0 +1 @@
1
+ export declare const Spinner: () => import("lit-html").TemplateResult<1>;
@@ -0,0 +1,22 @@
1
+ import { component, html } from 'haunted';
2
+ export const Spinner = () => html `<style>
3
+ @keyframes rotating {
4
+ 100% {
5
+ transform: rotate(360deg);
6
+ }
7
+ }
8
+
9
+ :host {
10
+ display: inline-block;
11
+ vertical-align: middle;
12
+ border-radius: 50%;
13
+ width: 22px;
14
+ height: 22px;
15
+ border: 2px solid rgba(0, 0, 0, 0.1);
16
+ border-top: 2px solid #5f5a92;
17
+ animation: rotating 1.2s infinite cubic-bezier(0.785, 0.135, 0.15, 0.86);
18
+ box-sizing: border-box;
19
+ margin: 0 4px;
20
+ }
21
+ </style>`;
22
+ customElements.define('cz-spinner', component(Spinner));
@@ -0,0 +1,2 @@
1
+ export * from './cz-spinner';
2
+ export * from './cz-icon';
@@ -0,0 +1,2 @@
1
+ export * from './cz-spinner';
2
+ export * from './cz-icon';
@@ -0,0 +1,5 @@
1
+ declare type OrFn<T> = (...args: T[]) => boolean;
2
+ declare type OnceFn<A, R> = (...args: A[]) => R;
3
+ declare type OnceCheckFn<T> = (args: T[]) => boolean | undefined;
4
+ export declare const constant: <T>(v?: T | undefined) => () => T | undefined, constTrue: () => boolean | undefined, constUndefined: () => unknown, noop: () => unknown, identity: <T>(obj: T) => T, or: <A, F extends OrFn<A>>(...fns: F[]) => (...args: A[]) => boolean, once: <A, R, F extends OnceFn<A, R>>(fn: F, check?: OnceCheckFn<A>) => (...args: A[]) => any;
5
+ export {};
@@ -0,0 +1,4 @@
1
+ export const constant = (v) => () => v, constTrue = constant(true), constUndefined = constant(), noop = constUndefined, identity = (obj) => obj, or = (...fns) => (...args) => fns.reduce((res, fn) => res || fn(...args), false), once = (fn, check = constTrue) => {
2
+ let result;
3
+ return (...args) => (result ??= check(args) ? fn(...args) : undefined);
4
+ };