@nectary/components 0.8.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 (132) hide show
  1. package/accordion/index.d.ts +21 -0
  2. package/accordion/index.js +118 -0
  3. package/accordion-item/index.d.ts +33 -0
  4. package/accordion-item/index.js +139 -0
  5. package/alert/index.d.ts +26 -0
  6. package/alert/index.js +91 -0
  7. package/alert-button/index.d.ts +23 -0
  8. package/alert-button/index.js +62 -0
  9. package/alert-close/index.d.ts +22 -0
  10. package/alert-close/index.js +41 -0
  11. package/button/index.d.ts +32 -0
  12. package/button/index.js +100 -0
  13. package/checkbox/index.d.ts +29 -0
  14. package/checkbox/index.js +134 -0
  15. package/help-tooltip/index.d.ts +15 -0
  16. package/help-tooltip/index.js +80 -0
  17. package/icon/cancel/index.d.ts +11 -0
  18. package/icon/cancel/index.js +4 -0
  19. package/icon/close/index.d.ts +11 -0
  20. package/icon/close/index.js +4 -0
  21. package/icon/create-icon-class.d.ts +308 -0
  22. package/icon/create-icon-class.js +53 -0
  23. package/icon/east/index.d.ts +11 -0
  24. package/icon/east/index.js +4 -0
  25. package/icon/help-outline/index.d.ts +11 -0
  26. package/icon/help-outline/index.js +4 -0
  27. package/icon/more-horiz/index.d.ts +11 -0
  28. package/icon/more-horiz/index.js +4 -0
  29. package/icon/more-vert/index.d.ts +11 -0
  30. package/icon/more-vert/index.js +4 -0
  31. package/icon/north/index.d.ts +11 -0
  32. package/icon/north/index.js +4 -0
  33. package/icon/north-east/index.d.ts +11 -0
  34. package/icon/north-east/index.js +4 -0
  35. package/icon/north-west/index.d.ts +11 -0
  36. package/icon/north-west/index.js +4 -0
  37. package/icon/open-in-new/index.d.ts +11 -0
  38. package/icon/open-in-new/index.js +4 -0
  39. package/icon/south/index.d.ts +11 -0
  40. package/icon/south/index.js +4 -0
  41. package/icon/south-east/index.d.ts +11 -0
  42. package/icon/south-east/index.js +4 -0
  43. package/icon/south-west/index.d.ts +11 -0
  44. package/icon/south-west/index.js +4 -0
  45. package/icon/types.d.ts +7 -0
  46. package/icon/types.js +1 -0
  47. package/icon/west/index.d.ts +11 -0
  48. package/icon/west/index.js +4 -0
  49. package/icon-branded/barchart-down/index.d.ts +11 -0
  50. package/icon-branded/barchart-down/index.js +4 -0
  51. package/icon-branded/barchart-up/index.d.ts +11 -0
  52. package/icon-branded/barchart-up/index.js +4 -0
  53. package/icon-branded/campaigns/index.d.ts +11 -0
  54. package/icon-branded/campaigns/index.js +4 -0
  55. package/icon-branded/chatbot/index.d.ts +11 -0
  56. package/icon-branded/chatbot/index.js +4 -0
  57. package/icon-branded/contact/index.d.ts +11 -0
  58. package/icon-branded/contact/index.js +4 -0
  59. package/icon-branded/create-icon-class.d.ts +309 -0
  60. package/icon-branded/create-icon-class.js +61 -0
  61. package/icon-branded/home/index.d.ts +11 -0
  62. package/icon-branded/home/index.js +4 -0
  63. package/icon-branded/multiple-channels/index.d.ts +11 -0
  64. package/icon-branded/multiple-channels/index.js +4 -0
  65. package/icon-branded/rocket/index.d.ts +11 -0
  66. package/icon-branded/rocket/index.js +4 -0
  67. package/icon-branded/settings/index.d.ts +11 -0
  68. package/icon-branded/settings/index.js +4 -0
  69. package/icon-branded/types.d.ts +9 -0
  70. package/icon-branded/types.js +1 -0
  71. package/icon-branded/user/index.d.ts +11 -0
  72. package/icon-branded/user/index.js +4 -0
  73. package/icon-branded/users/index.d.ts +11 -0
  74. package/icon-branded/users/index.js +4 -0
  75. package/index.d.ts +56 -0
  76. package/index.js +56 -0
  77. package/input/index.d.ts +35 -0
  78. package/input/index.js +203 -0
  79. package/link/index.d.ts +30 -0
  80. package/link/index.js +118 -0
  81. package/logo/create-logo-class.d.ts +309 -0
  82. package/logo/create-logo-class.js +63 -0
  83. package/logo/sinch-icon/index.d.ts +11 -0
  84. package/logo/sinch-icon/index.js +4 -0
  85. package/logo/sinch-icon-wordmark/index.d.ts +11 -0
  86. package/logo/sinch-icon-wordmark/index.js +4 -0
  87. package/logo/types.d.ts +9 -0
  88. package/logo/types.js +1 -0
  89. package/package.json +34 -0
  90. package/radio/index.d.ts +19 -0
  91. package/radio/index.js +185 -0
  92. package/radio-option/index.d.ts +28 -0
  93. package/radio-option/index.js +134 -0
  94. package/readme.md +172 -0
  95. package/select/index.d.ts +37 -0
  96. package/select/index.js +492 -0
  97. package/select-option/index.d.ts +27 -0
  98. package/select-option/index.js +107 -0
  99. package/spinner/index.d.ts +21 -0
  100. package/spinner/index.js +23 -0
  101. package/table/index.d.ts +13 -0
  102. package/table/index.js +18 -0
  103. package/table-body/index.d.ts +13 -0
  104. package/table-body/index.js +18 -0
  105. package/table-cell/index.d.ts +20 -0
  106. package/table-cell/index.js +27 -0
  107. package/table-head/index.d.ts +13 -0
  108. package/table-head/index.js +18 -0
  109. package/table-head-cell/index.d.ts +24 -0
  110. package/table-head-cell/index.js +74 -0
  111. package/table-head-sort/index.d.ts +25 -0
  112. package/table-head-sort/index.js +92 -0
  113. package/table-row/index.d.ts +17 -0
  114. package/table-row/index.js +26 -0
  115. package/tabs/index.d.ts +19 -0
  116. package/tabs/index.js +181 -0
  117. package/tabs-option/index.d.ts +28 -0
  118. package/tabs-option/index.js +129 -0
  119. package/tag/index.d.ts +27 -0
  120. package/tag/index.js +79 -0
  121. package/tag-close/index.d.ts +24 -0
  122. package/tag-close/index.js +70 -0
  123. package/textarea/index.d.ts +35 -0
  124. package/textarea/index.js +201 -0
  125. package/theme.css +112 -0
  126. package/toggle/index.d.ts +31 -0
  127. package/toggle/index.js +144 -0
  128. package/tooltip/index.d.ts +26 -0
  129. package/tooltip/index.js +68 -0
  130. package/types.d.ts +3 -0
  131. package/utils.d.ts +31 -0
  132. package/utils.js +146 -0
@@ -0,0 +1,31 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ import type { FocusEvent, SyntheticEvent } from 'react';
3
+ export declare type TSinchToggleElement = HTMLElement & {
4
+ checked: boolean;
5
+ small: boolean;
6
+ labeled: boolean;
7
+ disabled: boolean;
8
+ text: string | null;
9
+ focus(): void;
10
+ blur(): void;
11
+ };
12
+ export declare type TSinchToggleReact = TSinchElementReact<TSinchToggleElement> & {
13
+ checked?: boolean;
14
+ small?: boolean;
15
+ labeled?: boolean;
16
+ disabled?: boolean;
17
+ text?: string;
18
+ onChange: (e: SyntheticEvent<TSinchToggleElement, CustomEvent<boolean>>) => void;
19
+ onFocus?: (e: FocusEvent<TSinchToggleElement>) => void;
20
+ onBlur?: (e: FocusEvent<TSinchToggleElement>) => void;
21
+ };
22
+ declare global {
23
+ namespace JSX {
24
+ interface IntrinsicElements {
25
+ 'sinch-toggle': TSinchToggleReact;
26
+ }
27
+ }
28
+ interface HTMLElementTagNameMap {
29
+ 'sinch-toggle': TSinchToggleElement;
30
+ }
31
+ }
@@ -0,0 +1,144 @@
1
+ import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
2
+ import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
3
+
4
+ var _$input, _$label, _onInput;
5
+
6
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
7
+
8
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
9
+
10
+ import { defineCustomElement, getAttribute, getBooleanAttribute, isAttrTrue, updateAttribute, updateBooleanAttribute } from '../utils';
11
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;flex-direction:row;box-sizing:border-box;width:100%;height:32px;font:var(--sinch-font-body);text-align:initial}:host([small]:not([small=false])) #wrapper{font:var(--sinch-font-small-text)}#checkbox{all:initial;display:block;position:absolute;left:0;top:0;width:40px;height:20px;cursor:pointer;pointer-events:initial}#checkbox:disabled{cursor:initial}#knob-container{position:relative;box-sizing:border-box;align-self:center;width:40px;height:20px;border-radius:10px;pointer-events:none;padding:2px;background-color:var(--sinch-color-stormy-100);overflow:hidden}:host([checked]:not([checked=false])) #knob-container{background-color:var(--sinch-color-tropical-500)}:host([small]:not([small=false])) #knob-container{width:32px;height:16px;border-radius:8px}#knob{position:relative;box-sizing:border-box;width:16px;height:16px;border-radius:50%;background-color:var(--sinch-color-snow-100);transform:translateX(0);transition:transform .1s ease-in-out}:host([checked]:not([checked=false])) #knob{transform:translateX(20px)}:host([small]:not([small=false])) #knob{width:12px;height:12px}:host([small]:not([small=false])[checked]:not([checked=false])) #knob{transform:translateX(16px)}#knob::after,#knob::before{color:var(--sinch-color-snow-100);text-transform:uppercase;font-size:8px;line-height:16px;display:none;position:absolute;top:0;padding:0 3px}#knob::before{content:"on";right:100%}#knob::after{content:"off";left:100%}:host([labeled]:not([labeled=false]):is(:not([small]),[small=false])) #knob::after,:host([labeled]:not([labeled=false]):is(:not([small]),[small=false])) #knob::before{display:block}@media (prefers-reduced-motion){#knob{transition:none}}#label{display:none;flex:1;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;padding-left:8px}:host([text]:not([text=""])) #label{display:block}:host([disabled]:not([disabled=false])) #label{color:var(--sinch-color-stormy-200)}:host([disabled]:not([disabled=false])) #knob-container{background-color:var(--sinch-color-snow-700)}:host([checked]:not([checked=false])[disabled]:not([disabled=false])) #knob-container{background-color:var(--sinch-color-tropical-100)}</style><div id="wrapper"><div id="knob-container"><div id="knob"></div><input id="checkbox" type="checkbox"></div><label for="checkbox" id="label"></label></div>';
12
+ const template = document.createElement('template');
13
+ template.innerHTML = templateHTML;
14
+ defineCustomElement('sinch-toggle', (_$input = new WeakMap(), _$label = new WeakMap(), _onInput = new WeakMap(), class extends HTMLElement {
15
+ constructor() {
16
+ super();
17
+
18
+ _classPrivateFieldInitSpec(this, _$input, {
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+
23
+ _classPrivateFieldInitSpec(this, _$label, {
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+
28
+ _classPrivateFieldInitSpec(this, _onInput, {
29
+ writable: true,
30
+ value: e => {
31
+ e.stopPropagation();
32
+
33
+ const isChecked = _classPrivateFieldGet(this, _$input).checked;
34
+
35
+ _classPrivateFieldGet(this, _$input).checked = this.checked;
36
+ this.dispatchEvent(new CustomEvent('change', {
37
+ detail: isChecked,
38
+ bubbles: true
39
+ }));
40
+ }
41
+ });
42
+
43
+ const shadowRoot = this.attachShadow({
44
+ mode: 'production' === 'development' ? 'open' : 'closed',
45
+ delegatesFocus: true
46
+ });
47
+ shadowRoot.appendChild(template.content.cloneNode(true));
48
+
49
+ _classPrivateFieldSet(this, _$input, shadowRoot.querySelector('input'));
50
+
51
+ _classPrivateFieldSet(this, _$label, shadowRoot.querySelector('label'));
52
+ }
53
+
54
+ connectedCallback() {
55
+ _classPrivateFieldGet(this, _$input).addEventListener('input', _classPrivateFieldGet(this, _onInput));
56
+ }
57
+
58
+ disconnectedCallback() {
59
+ _classPrivateFieldGet(this, _$input).removeEventListener('input', _classPrivateFieldGet(this, _onInput));
60
+ }
61
+
62
+ static get observedAttributes() {
63
+ return ['checked', 'disabled', 'text'];
64
+ }
65
+
66
+ get type() {
67
+ return 'text';
68
+ }
69
+
70
+ get nodeName() {
71
+ return 'input';
72
+ }
73
+
74
+ set checked(isChecked) {
75
+ updateBooleanAttribute(this, 'checked', isChecked);
76
+ }
77
+
78
+ get checked() {
79
+ return getBooleanAttribute(this, 'checked');
80
+ }
81
+
82
+ set small(isSmall) {
83
+ updateBooleanAttribute(this, 'small', isSmall);
84
+ }
85
+
86
+ get small() {
87
+ return getBooleanAttribute(this, 'small');
88
+ }
89
+
90
+ set labeled(isLabeled) {
91
+ updateBooleanAttribute(this, 'labeled', isLabeled);
92
+ }
93
+
94
+ get labeled() {
95
+ return getBooleanAttribute(this, 'labeled');
96
+ }
97
+
98
+ set disabled(isDisabled) {
99
+ updateBooleanAttribute(this, 'disabled', isDisabled);
100
+ }
101
+
102
+ get disabled() {
103
+ return getBooleanAttribute(this, 'disabled');
104
+ }
105
+
106
+ set text(value) {
107
+ updateAttribute(this, 'text', value);
108
+ }
109
+
110
+ get text() {
111
+ return getAttribute(this, 'text', null);
112
+ }
113
+
114
+ attributeChangedCallback(name, _, newVal) {
115
+ switch (name) {
116
+ case 'text':
117
+ {
118
+ _classPrivateFieldGet(this, _$label).textContent = newVal;
119
+ break;
120
+ }
121
+
122
+ case 'checked':
123
+ {
124
+ _classPrivateFieldGet(this, _$input).checked = isAttrTrue(newVal);
125
+ break;
126
+ }
127
+
128
+ case 'disabled':
129
+ {
130
+ _classPrivateFieldGet(this, _$input).disabled = isAttrTrue(newVal);
131
+ break;
132
+ }
133
+ }
134
+ }
135
+
136
+ focus() {
137
+ _classPrivateFieldGet(this, _$input).focus();
138
+ }
139
+
140
+ blur() {
141
+ _classPrivateFieldGet(this, _$input).blur();
142
+ }
143
+
144
+ }));
@@ -0,0 +1,26 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ declare const orientationValues: readonly ["top", "bottom", "left", "right", "top-left", "top-right", "bottom-left", "bottom-right"];
3
+ export declare type TSinchTooltipOrientation = typeof orientationValues[number];
4
+ export declare type TSinchTooltipElement = HTMLElement & {
5
+ text: string;
6
+ width: number | null;
7
+ inverted: boolean;
8
+ orientation: TSinchTooltipOrientation;
9
+ };
10
+ export declare type TSinchTooltipReact = TSinchElementReact<TSinchTooltipElement> & {
11
+ text: string;
12
+ width?: number;
13
+ inverted?: boolean;
14
+ orientation?: TSinchTooltipOrientation;
15
+ };
16
+ declare global {
17
+ namespace JSX {
18
+ interface IntrinsicElements {
19
+ 'sinch-tooltip': TSinchTooltipReact;
20
+ }
21
+ }
22
+ interface HTMLElementTagNameMap {
23
+ 'sinch-tooltip': TSinchTooltipElement;
24
+ }
25
+ }
26
+ export {};
@@ -0,0 +1,68 @@
1
+ import { attrValueToPixels, defineCustomElement, getBooleanAttribute, getIntegerAttribute, getAttribute, getLiteralAttribute, updateBooleanAttribute, updateAttribute, updateLiteralAttribute } from '../utils';
2
+ const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#wrapper{position:relative;display:block}#tooltip{position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none;opacity:0%;transition:opacity .2s linear .2s}@media (prefers-reduced-motion){#tooltip{transition:none}}:host(:hover) #tooltip{opacity:100%}#text{position:absolute;padding:2px 6px;font:var(--sinch-font-extra-small-text);color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-600);width:max-content;border-radius:2px;top:-8px;left:50%;transform:translateX(-50%) translateY(-100%)}#arrow{position:absolute;top:-8px;left:50%;transform:translateX(-50%);fill:var(--sinch-color-snow-600)}:host([orientation=top-left]) #text{transform:translateX(-80%) translateY(-100%)}:host([orientation=top-right]) #text{transform:translateX(-20%) translateY(-100%)}:host([orientation=bottom-right]) #text{top:calc(100% + 8px);transform:translateX(-20%)}:host([orientation=bottom-left]) #text{top:calc(100% + 8px);transform:translateX(-80%)}:host([orientation=bottom]) #text{top:calc(100% + 8px);transform:translateX(-50%)}:host([orientation^=bottom]) #arrow{top:calc(100% + 4px);transform:translateX(-50%) rotate(180deg)}:host([orientation=left]) #text{left:unset;right:calc(100% + 8px);top:50%;transform:translateY(-50%)}:host([orientation=left]) #arrow{left:-11px;top:50%;transform:translateY(-50%) rotate(270deg)}:host([orientation=right]) #text{left:calc(100% + 8px);top:50%;transform:translateY(-50%)}:host([orientation=right]) #arrow{top:50%;left:calc(100% + 2px);transform:translateY(-50%) rotate(90deg)}:host([inverted]:not([inverted=false])) #text{color:var(--sinch-color-text-inverted);background-color:var(--sinch-color-stormy-500)}:host([inverted]:not([inverted=false])) #arrow{fill:var(--sinch-color-stormy-500)}::slotted(*){display:block}</style><div id="wrapper"><slot></slot><div id="tooltip"><div id="text"></div><svg id="arrow" width="9" height="4"><path d="m4.5 4 4-4h-8l4 4Z"/></svg></div></div>';
3
+ const orientationValues = ['top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right'];
4
+ const template = document.createElement('template');
5
+ template.innerHTML = templateHTML;
6
+ defineCustomElement('sinch-tooltip', class extends HTMLElement {
7
+ constructor() {
8
+ super();
9
+ const shadowRoot = this.attachShadow({
10
+ mode: 'production' === 'development' ? 'open' : 'closed'
11
+ });
12
+ shadowRoot.appendChild(template.content.cloneNode(true));
13
+ this.$tooltipText = shadowRoot.querySelector('#text');
14
+ }
15
+
16
+ static get observedAttributes() {
17
+ return ['text', 'width'];
18
+ }
19
+
20
+ get text() {
21
+ return getAttribute(this, 'text', '');
22
+ }
23
+
24
+ set text(value) {
25
+ updateAttribute(this, 'text', value);
26
+ }
27
+
28
+ get width() {
29
+ return getIntegerAttribute(this, 'width', null);
30
+ }
31
+
32
+ set width(value) {
33
+ updateAttribute(this, 'width', value);
34
+ }
35
+
36
+ get inverted() {
37
+ return getBooleanAttribute(this, 'inverted');
38
+ }
39
+
40
+ set inverted(isInverted) {
41
+ updateBooleanAttribute(this, 'inverted', isInverted);
42
+ }
43
+
44
+ get orientation() {
45
+ return getLiteralAttribute(this, orientationValues, 'orientation', 'top');
46
+ }
47
+
48
+ set orientation(value) {
49
+ updateLiteralAttribute(this, orientationValues, 'orientation', value);
50
+ }
51
+
52
+ attributeChangedCallback(name, _, newVal) {
53
+ switch (name) {
54
+ case 'text':
55
+ {
56
+ this.$tooltipText.textContent = newVal;
57
+ break;
58
+ }
59
+
60
+ case 'width':
61
+ {
62
+ this.$tooltipText.style.maxWidth = attrValueToPixels(newVal);
63
+ break;
64
+ }
65
+ }
66
+ }
67
+
68
+ });
package/types.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { ClassAttributes, HTMLAttributes } from 'react'
2
+
3
+ export type TSinchElementReact<TElementProperties> = Pick<HTMLAttributes<HTMLElement>, 'id' | 'className' | 'style' | 'slot' | 'children'> & ClassAttributes<TElementProperties> & { class?: string }
package/utils.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ export declare const defineCustomElement: (name: string, constructor: CustomElementConstructor) => void;
2
+ export declare const defineNectaryElements: (registry: CustomElementRegistry) => void;
3
+ export declare type TEventHandler = (arg?: any) => void;
4
+ export declare const updateBooleanAttribute: ($element: Element, attrName: string, attrValue: boolean | null | undefined) => void;
5
+ export declare const isAttrTrue: (attrValue: string | null) => boolean;
6
+ export declare const getBooleanAttribute: ($element: Element, attrName: string) => boolean;
7
+ export declare const updateAttribute: ($element: Element, attrName: string, attrValue: string | number | boolean | null | undefined) => void;
8
+ export declare function getAttribute($element: Element, attrName: string): string | undefined;
9
+ export declare function getAttribute($element: Element, attrName: string, defaultValue: null): string | null;
10
+ export declare function getAttribute($element: Element, attrName: string, defaultValue: string): string;
11
+ export declare const isLiteralValue: <T extends readonly string[]>(literals: T, value: string | null | undefined) => value is T[number];
12
+ export declare const updateLiteralAttribute: <T extends readonly string[]>($element: Element, literals: T, attrName: string, attrValue: T[number] | null | undefined) => void;
13
+ export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string): T[number] | undefined;
14
+ export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: null): T[number] | null;
15
+ export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: T[number]): T[number];
16
+ declare type TRange = {
17
+ min?: number;
18
+ max?: number;
19
+ };
20
+ export declare const attrValueToInteger: (value: string | null, range?: TRange) => number | null;
21
+ export declare const attrValueToPixels: (value: string | null, options?: TRange & {
22
+ multiplier?: number;
23
+ }) => string;
24
+ export declare const updateIntegerAttribute: ($element: Element, attrName: string, attrValue: string | number | null | undefined, range?: TRange) => void;
25
+ export declare function getIntegerAttribute($element: Element, attrName: string): number | undefined;
26
+ export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: null): number | null;
27
+ export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: number): number;
28
+ export declare const updateCSV: (acc: string, value: string, setActive: boolean) => string;
29
+ export declare const getCSVSet: (acc: string) => Set<string>;
30
+ export declare const getFirstCSValue: (acc: string) => string;
31
+ export {};
package/utils.js ADDED
@@ -0,0 +1,146 @@
1
+ const nectaryDefinitions = new Map();
2
+ let nectaryRegistry = null;
3
+ export const defineCustomElement = (name, constructor) => {
4
+ if (nectaryRegistry !== null) {
5
+ if (nectaryRegistry.get(name) == null) {
6
+ nectaryRegistry.define(name, constructor);
7
+ }
8
+
9
+ return;
10
+ }
11
+
12
+ nectaryDefinitions.set(name, constructor);
13
+
14
+ if (customElements.get(name) == null) {
15
+ customElements.define(name, constructor);
16
+ }
17
+ };
18
+ export const defineNectaryElements = registry => {
19
+ if (nectaryRegistry !== null) {
20
+ throw new Error('Nectary elements already registered');
21
+ }
22
+
23
+ nectaryRegistry = registry;
24
+
25
+ for (const [name, ctor] of nectaryDefinitions.entries()) {
26
+ if (nectaryRegistry.get(name) == null) {
27
+ nectaryRegistry.define(name, ctor);
28
+ }
29
+ }
30
+ };
31
+ export const updateBooleanAttribute = ($element, attrName, attrValue) => {
32
+ if (attrValue === true) {
33
+ $element.setAttribute(attrName, '');
34
+ } else {
35
+ $element.removeAttribute(attrName);
36
+ }
37
+ };
38
+ export const isAttrTrue = attrValue => {
39
+ return attrValue === '' || attrValue !== 'false' && attrValue !== null;
40
+ };
41
+ export const getBooleanAttribute = ($element, attrName) => {
42
+ return isAttrTrue($element.getAttribute(attrName));
43
+ };
44
+ export const updateAttribute = ($element, attrName, attrValue) => {
45
+ if (attrValue != null) {
46
+ $element.setAttribute(attrName, String(attrValue));
47
+ } else {
48
+ $element.removeAttribute(attrName);
49
+ }
50
+ };
51
+ export function getAttribute($element, attrName, defaultValue) {
52
+ return $element.getAttribute(attrName) ?? defaultValue;
53
+ }
54
+ export const isLiteralValue = (literals, value) => {
55
+ return value != null && literals.includes(value);
56
+ };
57
+ export const updateLiteralAttribute = ($element, literals, attrName, attrValue) => {
58
+ if (isLiteralValue(literals, attrValue)) {
59
+ $element.setAttribute(attrName, attrValue);
60
+ } else {
61
+ $element.removeAttribute(attrName);
62
+ }
63
+ };
64
+ export function getLiteralAttribute($element, literals, attrName, defaultValue) {
65
+ const attrValue = $element.getAttribute(attrName);
66
+ return isLiteralValue(literals, attrValue) ? attrValue : defaultValue;
67
+ }
68
+
69
+ const applyRange = (value, range) => {
70
+ let result = value;
71
+
72
+ if (typeof range.min === 'number') {
73
+ result = Math.max(range.min, result);
74
+ }
75
+
76
+ if (typeof range.max === 'number') {
77
+ result = Math.min(range.max, result);
78
+ }
79
+
80
+ return result;
81
+ };
82
+
83
+ export const attrValueToInteger = function (value) {
84
+ let range = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
85
+
86
+ if (value === null) {
87
+ return null;
88
+ }
89
+
90
+ const int = parseInt(value);
91
+
92
+ if (!Number.isInteger(int)) {
93
+ return null;
94
+ }
95
+
96
+ return applyRange(int, range);
97
+ };
98
+ export const attrValueToPixels = function (value) {
99
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
100
+ const int = attrValueToInteger(value, {
101
+ min: options.min ?? 0,
102
+ max: options.max
103
+ });
104
+ return int === null ? 'unset' : `${int * (options.multiplier ?? 1)}px`;
105
+ };
106
+ export const updateIntegerAttribute = function ($element, attrName, attrValue) {
107
+ let range = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
108
+
109
+ if (attrValue == null) {
110
+ $element.removeAttribute(attrName);
111
+ return;
112
+ }
113
+
114
+ const intValue = typeof attrValue === 'string' ? attrValueToInteger(attrValue, range) : applyRange(attrValue, range);
115
+
116
+ if (intValue === null) {
117
+ return;
118
+ }
119
+
120
+ $element.setAttribute(attrName, intValue.toFixed(0));
121
+ };
122
+ export function getIntegerAttribute($element, attrName, defaultValue) {
123
+ return attrValueToInteger($element.getAttribute(attrName)) ?? defaultValue;
124
+ }
125
+ export const updateCSV = (acc, value, setActive) => {
126
+ const values = acc === '' ? [] : acc.split(',');
127
+ const i = values.indexOf(value);
128
+
129
+ if (setActive) {
130
+ i === -1 && values.push(value);
131
+ } else {
132
+ i >= 0 && values.splice(i, 1);
133
+ }
134
+
135
+ return values.join(',');
136
+ };
137
+ export const getCSVSet = acc => {
138
+ if (acc === '') {
139
+ return new Set();
140
+ }
141
+
142
+ return new Set(acc.split(','));
143
+ };
144
+ export const getFirstCSValue = acc => {
145
+ return acc.split(',')[0];
146
+ };