@neovici/cosmoz-utils 4.0.0-beta.1 → 5.0.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 (83) 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 +46 -0
  6. package/dist/directives/lazy-until.js +143 -0
  7. package/dist/directives/measure.d.ts +9 -0
  8. package/dist/directives/measure.js +23 -0
  9. package/dist/directives/portal.d.ts +12 -0
  10. package/dist/directives/portal.js +51 -0
  11. package/dist/directives/spread-props.d.ts +8 -0
  12. package/dist/directives/spread-props.js +21 -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 +17 -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 +17 -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 +8 -0
  50. package/dist/reduce/action.js +10 -0
  51. package/dist/reduce/index.d.ts +2 -0
  52. package/{lib → dist}/reduce/index.js +0 -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/function.js +0 -21
  68. package/lib/haunted-polymer.js +0 -93
  69. package/lib/hooks/use-debounce-raf.js +0 -49
  70. package/lib/hooks/use-dropped-files.js +0 -12
  71. package/lib/hooks/use-handle-drop.js +0 -22
  72. package/lib/hooks/use-host-bounds.js +0 -21
  73. package/lib/hooks/use-host.js +0 -9
  74. package/lib/hooks/use-imperative-api.js +0 -22
  75. package/lib/hooks/use-notify-property.js +0 -26
  76. package/lib/hooks/use-promise.js +0 -74
  77. package/lib/money.js +0 -105
  78. package/lib/object.js +0 -26
  79. package/lib/promise.js +0 -88
  80. package/lib/reduce/action.js +0 -16
  81. package/lib/reduce/reduce.js +0 -16
  82. package/lib/tag.js +0 -34
  83. 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,46 @@
1
+ export class UntilDirective extends AsyncDirective {
2
+ __lastRenderedIndex: number;
3
+ __values: any[];
4
+ __weakThis: PseudoWeakRef;
5
+ __pauser: Pauser;
6
+ render(...args: any[]): any;
7
+ update(_part: any, args: any): any;
8
+ }
9
+ /**
10
+ * Renders one of a series of values, including Promises, to a Part.
11
+ *
12
+ * Values are rendered in priority order, with the first argument having the
13
+ * highest priority and the last argument having the lowest priority. If a
14
+ * value is a Promise, low-priority values will be rendered until it resolves.
15
+ *
16
+ * The priority of values can be used to create placeholder content for async
17
+ * data. For example, a Promise with pending content can be the first,
18
+ * highest-priority, argument, and a non_promise loading indicator template can
19
+ * be used as the second, lower-priority, argument. The loading indicator will
20
+ * render immediately, and the primary content will render when the Promise
21
+ * resolves.
22
+ *
23
+ * Example:
24
+ *
25
+ * ```js
26
+ * const content = fetch('./content.txt').then(r => r.text());
27
+ * html`${until(content, html`<span>Loading...</span>`)}`
28
+ * ```
29
+ */
30
+ export const lazyUntil: (...values: any[]) => import("lit-html/directive.js").DirectiveResult<typeof UntilDirective>;
31
+ import { AsyncDirective } from "lit-html/async-directive.js";
32
+ declare class PseudoWeakRef {
33
+ constructor(ref: any);
34
+ _ref: any;
35
+ disconnect(): void;
36
+ reconnect(ref: any): void;
37
+ deref(): any;
38
+ }
39
+ declare class Pauser {
40
+ _promise: undefined;
41
+ _resolve: undefined;
42
+ get(): undefined;
43
+ pause(): void;
44
+ resume(): void;
45
+ }
46
+ export {};
@@ -0,0 +1,143 @@
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
+ constructor(ref) {
13
+ this._ref = ref;
14
+ }
15
+ disconnect() {
16
+ this._ref = undefined;
17
+ }
18
+ reconnect(ref) {
19
+ this._ref = ref;
20
+ }
21
+ deref() {
22
+ return this._ref;
23
+ }
24
+ }
25
+ class Pauser {
26
+ _promise = undefined;
27
+ _resolve = undefined;
28
+ get() {
29
+ return this._promise;
30
+ }
31
+ pause() {
32
+ this._promise ??= new Promise((resolve) => (this._resolve = resolve));
33
+ }
34
+ resume() {
35
+ this._resolve?.();
36
+ this._promise = this._resolve = undefined;
37
+ }
38
+ }
39
+ const isPromise = (x) => {
40
+ return !isPrimitive(x) && typeof x.then === 'function';
41
+ },
42
+ // Effectively infinity, but a SMI.
43
+ _infinity = 0x3fffffff;
44
+ export class UntilDirective extends AsyncDirective {
45
+ __lastRenderedIndex = _infinity;
46
+ __values = [];
47
+ __weakThis = new PseudoWeakRef(this);
48
+ __pauser = new Pauser();
49
+ render(...args) {
50
+ return args.find((x) => !isPromise(x)) ?? noChange;
51
+ }
52
+ // eslint-disable-next-line max-statements
53
+ update(_part, args) {
54
+ const previousValues = this.__values, previousLength = previousValues.length;
55
+ this.__values = args;
56
+ const weakThis = this.__weakThis, pauser = this.__pauser;
57
+ // If our initial render occurs while disconnected, ensure that the pauser
58
+ // and weakThis are in the disconnected state
59
+ if (!this.isConnected) {
60
+ this.disconnected();
61
+ }
62
+ for (let i = 0; i < args.length; i++) {
63
+ // If we've rendered a higher-priority value already, stop.
64
+ if (i > this.__lastRenderedIndex) {
65
+ break;
66
+ }
67
+ const value = args[i];
68
+ // Render non-Promise values immediately
69
+ if (!isPromise(value)) {
70
+ this.__lastRenderedIndex = i;
71
+ // Since a lower-priority value will never overwrite a higher-priority
72
+ // synchronous value, we can stop processing now.
73
+ return value;
74
+ }
75
+ // If this is a Promise we've already handled, skip it.
76
+ if (i < previousLength && value === previousValues[i]) {
77
+ continue;
78
+ }
79
+ // Note, the callback avoids closing over `this` so that the directive
80
+ // can be gc'ed before the promise resolves; instead `this` is retrieved
81
+ // from `weakThis`, which can break the hard reference in the closure when
82
+ // the directive disconnects
83
+ Promise.resolve(value).then(async (result) => {
84
+ // If we're disconnected, wait until we're (maybe) reconnected
85
+ // The while loop here handles the case that the connection state
86
+ // thrashes, causing the pauser to resume and then get re-paused
87
+ while (pauser.get()) {
88
+ await pauser.get();
89
+ }
90
+ // If the callback gets here and there is no `this`, it means that the
91
+ // directive has been disconnected and garbage collected and we don't
92
+ // need to do anything else
93
+ const _this = weakThis.deref();
94
+ if (_this !== undefined) {
95
+ const index = _this.__values.indexOf(value);
96
+ // If state.values doesn't contain the value, we've re-rendered without
97
+ // the value, so don't render it. Then, only render if the value is
98
+ // higher-priority than what's already been rendered.
99
+ if (index > -1 && index <= _this.__lastRenderedIndex) {
100
+ _this.__lastRenderedIndex = index;
101
+ _this.setValue(result);
102
+ }
103
+ }
104
+ });
105
+ }
106
+ return noChange;
107
+ }
108
+ disconnected() {
109
+ this.__weakThis.disconnect();
110
+ this.__pauser.pause();
111
+ }
112
+ reconnected() {
113
+ this.__weakThis.reconnect(this);
114
+ this.__pauser.resume();
115
+ }
116
+ }
117
+ /**
118
+ * Renders one of a series of values, including Promises, to a Part.
119
+ *
120
+ * Values are rendered in priority order, with the first argument having the
121
+ * highest priority and the last argument having the lowest priority. If a
122
+ * value is a Promise, low-priority values will be rendered until it resolves.
123
+ *
124
+ * The priority of values can be used to create placeholder content for async
125
+ * data. For example, a Promise with pending content can be the first,
126
+ * highest-priority, argument, and a non_promise loading indicator template can
127
+ * be used as the second, lower-priority, argument. The loading indicator will
128
+ * render immediately, and the primary content will render when the Promise
129
+ * resolves.
130
+ *
131
+ * Example:
132
+ *
133
+ * ```js
134
+ * const content = fetch('./content.txt').then(r => r.text());
135
+ * html`${until(content, html`<span>Loading...</span>`)}`
136
+ * ```
137
+ */
138
+ export const lazyUntil = directive(UntilDirective);
139
+ /**
140
+ * The type of the class that powers this directive. Necessary for naming the
141
+ * directive's return type.
142
+ */
143
+ // export type {UntilDirective};
@@ -0,0 +1,9 @@
1
+ export const measure: () => import("lit-html/directive.js").DirectiveResult<typeof MeasureDirective>;
2
+ declare class MeasureDirective extends Directive {
3
+ render(): symbol;
4
+ update(part: any, [select, onMeasure]: [any, any]): symbol;
5
+ measure(element: any, select: any, onMeasure: any): symbol;
6
+ _observer: ResizeObserver | undefined;
7
+ }
8
+ import { Directive } from "lit-html/directive.js";
9
+ export {};
@@ -0,0 +1,23 @@
1
+ import { nothing } from 'lit-html';
2
+ import { Directive, directive } from 'lit-html/directive.js';
3
+ import { array } from '../array';
4
+ class MeasureDirective extends Directive {
5
+ render() {
6
+ return nothing;
7
+ }
8
+ update(part, [select, onMeasure]) {
9
+ this.measure(part.element, select, onMeasure);
10
+ return nothing;
11
+ }
12
+ measure(element, select, onMeasure) {
13
+ this._observer?.disconnect();
14
+ const elements = array(select(element)), observer = (this._observer = new ResizeObserver((entries) => {
15
+ onMeasure(entries
16
+ .sort((a, b) => elements.indexOf(a.target) - elements.indexOf(b.target))
17
+ .map((e) => e.contentRect));
18
+ }));
19
+ elements.forEach((el) => observer.observe(el));
20
+ return nothing;
21
+ }
22
+ }
23
+ export const measure = directive(MeasureDirective);
@@ -0,0 +1,12 @@
1
+ export const portal: () => import("lit-html/directive").DirectiveResult<typeof PortalDirective>;
2
+ declare class PortalDirective extends AsyncDirective {
3
+ render(): import("lit-html").TemplateResult<1>;
4
+ update(part: any, [content, outlet]: [any, (HTMLElement | undefined)?]): import("lit-html").TemplateResult<1>;
5
+ updateOutlet(outlet: any, content: any): void;
6
+ _outlet: any;
7
+ content: any;
8
+ clearOutlet(): void;
9
+ _op: any;
10
+ }
11
+ import { AsyncDirective } from "lit-html/async-directive.js";
12
+ export {};
@@ -0,0 +1,51 @@
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(''), ChildPart = render(nothing, new DocumentFragment()).constructor;
5
+ /**
6
+ * Helper element with a customizable disconnect behavior.
7
+ */
8
+ class DisconnectObserver extends HTMLElement {
9
+ disconnectedCallback() {
10
+ this.onDisconnect();
11
+ }
12
+ }
13
+ customElements.define('disconnect-observer', DisconnectObserver);
14
+ class PortalDirective extends AsyncDirective {
15
+ render() {
16
+ return html `<disconnect-observer
17
+ .onDisconnect=${() => {
18
+ this.isConnected = false;
19
+ this.disconnected();
20
+ }}
21
+ ></disconnect-observer>`;
22
+ }
23
+ update(part, [content, outlet = document.body]) {
24
+ this.updateOutlet(outlet, content);
25
+ return this.render();
26
+ }
27
+ updateOutlet(outlet, content) {
28
+ if (this._outlet !== outlet) {
29
+ this.clearOutlet();
30
+ }
31
+ this._outlet = outlet;
32
+ const part = (this._op ??= new ChildPart(outlet.appendChild(createMarker()), outlet.appendChild(createMarker())));
33
+ setChildPartValue(part, (this.content = content));
34
+ }
35
+ clearOutlet() {
36
+ const part = this._op;
37
+ if (!part) {
38
+ return;
39
+ }
40
+ clearPart(part);
41
+ removePart(part);
42
+ this._op = undefined;
43
+ }
44
+ disconnected() {
45
+ this.clearOutlet();
46
+ }
47
+ reconnected() {
48
+ this.updateOutlet(this._outlet, this._content);
49
+ }
50
+ }
51
+ export const portal = directive(PortalDirective);
@@ -0,0 +1,8 @@
1
+ export const spreadProps: () => import("lit-html/directive.js").DirectiveResult<typeof SpreadPropsDirective>;
2
+ declare class SpreadPropsDirective extends Directive {
3
+ render(): symbol;
4
+ update(part: any, [props]: [any]): symbol;
5
+ _props: any;
6
+ }
7
+ import { Directive } from "lit-html/directive.js";
8
+ export {};
@@ -0,0 +1,21 @@
1
+ import { nothing } 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
+ render() {
12
+ return nothing;
13
+ }
14
+ update(part, [props]) {
15
+ if (this._props !== props) {
16
+ Object.assign(part.element, undefs(this._props, props), (this._props = props));
17
+ }
18
+ return nothing;
19
+ }
20
+ }
21
+ 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
+ };