@nectary/components 0.42.0 → 0.43.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 (68) hide show
  1. package/action-menu/index.js +1 -2
  2. package/card-container/index.js +1 -1
  3. package/color-menu/index.d.ts +3 -3
  4. package/color-menu/index.js +1 -2
  5. package/color-menu/types.d.ts +2 -2
  6. package/dialog/index.js +2 -2
  7. package/emoji/index.d.ts +11 -0
  8. package/emoji/index.js +47 -0
  9. package/emoji/types.d.ts +11 -0
  10. package/emoji/types.js +1 -0
  11. package/emoji/utils.d.ts +1 -0
  12. package/emoji/utils.js +46 -0
  13. package/emoji-picker/index.d.ts +28 -0
  14. package/emoji-picker/index.js +319 -0
  15. package/emoji-picker/types.d.ts +25 -0
  16. package/emoji-picker/types.js +1 -0
  17. package/icon/index.d.ts +11 -0
  18. package/icon/index.js +32 -0
  19. package/icon/types.d.ts +11 -0
  20. package/icon/types.js +1 -0
  21. package/icon-button/index.js +1 -1
  22. package/package.json +3 -1
  23. package/pop/index.js +1 -2
  24. package/popover/index.js +1 -2
  25. package/segment/index.js +1 -1
  26. package/select-menu/index.js +1 -2
  27. package/tabs/index.js +24 -76
  28. package/tabs/types.d.ts +9 -2
  29. package/tabs-icon-option/index.d.ts +11 -0
  30. package/tabs-icon-option/index.js +75 -0
  31. package/tabs-icon-option/types.d.ts +19 -0
  32. package/tabs-icon-option/types.js +1 -0
  33. package/tabs-option/index.d.ts +1 -0
  34. package/tabs-option/index.js +8 -15
  35. package/tabs-option/types.d.ts +13 -5
  36. package/theme/avatar.css +25 -0
  37. package/theme/badge.css +15 -0
  38. package/theme/chip.css +53 -0
  39. package/theme/color-swatch.css +65 -0
  40. package/theme/elevation.css +7 -0
  41. package/theme/emoji.css +6 -0
  42. package/theme/fonts.css +85 -0
  43. package/theme/fonts.json +88 -0
  44. package/theme/icon.css +7 -0
  45. package/theme/palette.css +90 -0
  46. package/theme/shapes.css +7 -0
  47. package/theme/tag.css +53 -0
  48. package/theme/typography.css +16 -0
  49. package/theme.css +2 -0
  50. package/tooltip/index.js +78 -31
  51. package/utils/csv.d.ts +3 -0
  52. package/utils/csv.js +21 -0
  53. package/utils/dom.d.ts +30 -0
  54. package/utils/dom.js +143 -0
  55. package/utils/element.d.ts +12 -0
  56. package/utils/element.js +38 -0
  57. package/utils/get-react-event-handler.d.ts +1 -0
  58. package/utils/get-react-event-handler.js +8 -0
  59. package/utils/index.d.ts +8 -57
  60. package/utils/index.js +8 -301
  61. package/utils/rect.d.ts +4 -0
  62. package/utils/rect.js +29 -0
  63. package/utils/slot.d.ts +4 -0
  64. package/utils/slot.js +38 -0
  65. package/utils/throttle.d.ts +4 -0
  66. package/utils/throttle.js +25 -0
  67. /package/{utils/animation.d.ts → tooltip/tooltip-state.d.ts} +0 -0
  68. /package/{utils/animation.js → tooltip/tooltip-state.js} +0 -0
package/utils/dom.js ADDED
@@ -0,0 +1,143 @@
1
+ export const updateExplicitBooleanAttribute = ($element, attrName, attrValue) => {
2
+ $element.setAttribute(attrName, attrValue === true ? 'true' : 'false');
3
+ };
4
+ export const isAttrTrue = attrValue => {
5
+ return attrValue === '' || attrValue !== 'false' && attrValue !== null;
6
+ };
7
+ export const getBooleanAttribute = ($element, attrName) => {
8
+ return isAttrTrue($element.getAttribute(attrName));
9
+ };
10
+ export const updateBooleanAttribute = ($element, attrName, attrValue) => {
11
+ const currentAttrValue = $element.getAttribute(attrName);
12
+ if (attrValue === true) {
13
+ if (!isAttrTrue(currentAttrValue)) {
14
+ $element.setAttribute(attrName, '');
15
+ }
16
+ } else if (currentAttrValue !== null) {
17
+ $element.removeAttribute(attrName);
18
+ }
19
+ };
20
+ export const updateAttribute = ($element, attrName, attrValue) => {
21
+ if (attrValue != null) {
22
+ $element.setAttribute(attrName, String(attrValue));
23
+ } else {
24
+ $element.removeAttribute(attrName);
25
+ }
26
+ };
27
+ export function getAttribute($element, attrName) {
28
+ let defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
29
+ return $element.getAttribute(attrName) ?? defaultValue;
30
+ }
31
+ export const isLiteralValue = (literals, value) => {
32
+ return value != null && literals.includes(value);
33
+ };
34
+ export const updateLiteralAttribute = ($element, literals, attrName, attrValue) => {
35
+ if (isLiteralValue(literals, attrValue)) {
36
+ $element.setAttribute(attrName, attrValue);
37
+ } else {
38
+ $element.removeAttribute(attrName);
39
+ }
40
+ };
41
+ export function getLiteralAttribute($element, literals, attrName, defaultValue) {
42
+ const attrValue = $element.getAttribute(attrName);
43
+ if (isLiteralValue(literals, attrValue)) {
44
+ return attrValue;
45
+ }
46
+ if (typeof defaultValue === 'undefined') {
47
+ throw new Error(`Invalid attribute value: ${attrName} = ${attrValue}`);
48
+ }
49
+ return defaultValue;
50
+ }
51
+ export const clampNumber = (value, min, max) => {
52
+ return Math.min(max, Math.max(min, value));
53
+ };
54
+ const DEFAULT_INTEGER_OPTIONS = {
55
+ itemSizeMultiplier: 1,
56
+ itemSpaceBetween: 0,
57
+ defaultValue: null
58
+ };
59
+ const applyRange = (value, _ref) => {
60
+ let {
61
+ min,
62
+ max
63
+ } = _ref;
64
+ let result = value;
65
+ if (min != null) {
66
+ result = Math.max(min, result);
67
+ }
68
+ if (max != null) {
69
+ result = Math.min(max, result);
70
+ }
71
+ return result;
72
+ };
73
+ export const attrValueToInteger = function (value) {
74
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
75
+ const {
76
+ defaultValue = null,
77
+ itemSizeMultiplier = 1,
78
+ itemSpaceBetween = 0
79
+ } = options;
80
+ let intValue = defaultValue;
81
+ if (value !== null) {
82
+ const int = parseInt(value);
83
+ if (Number.isInteger(int)) {
84
+ intValue = applyRange(int, options);
85
+ }
86
+ }
87
+ if (intValue !== null) {
88
+ return intValue * itemSizeMultiplier + Math.max(intValue - 1, 0) * itemSpaceBetween;
89
+ }
90
+ return null;
91
+ };
92
+ export const attrValueToPixels = function (value) {
93
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
94
+ const int = attrValueToInteger(value, options);
95
+ return int === null ? 'unset' : `${int}px`;
96
+ };
97
+ export const updateIntegerAttribute = function ($element, attrName, attrValue) {
98
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_INTEGER_OPTIONS;
99
+ const {
100
+ defaultValue = null,
101
+ itemSizeMultiplier: multiplier = 1
102
+ } = options;
103
+ let intValue = null;
104
+ if (typeof attrValue === 'string') {
105
+ intValue = attrValueToInteger(attrValue, options);
106
+ } else if (typeof attrValue === 'number') {
107
+ intValue = applyRange(attrValue, options) * multiplier;
108
+ } else {
109
+ intValue = defaultValue;
110
+ }
111
+ if (intValue === null) {
112
+ $element.removeAttribute(attrName);
113
+ } else {
114
+ $element.setAttribute(attrName, intValue.toFixed(0));
115
+ }
116
+ };
117
+ export function getIntegerAttribute($element, attrName, defaultValue) {
118
+ return attrValueToInteger($element.getAttribute(attrName)) ?? defaultValue;
119
+ }
120
+ export const setClass = (elem, name, isSet) => {
121
+ isSet ? elem.classList.add(name) : elem.classList.remove(name);
122
+ };
123
+ export const getCssVar = (element, variableName) => {
124
+ const result = getComputedStyle(element).getPropertyValue(variableName);
125
+ return result === '' ? null : result;
126
+ };
127
+ export const cloneNode = (el, deep) => {
128
+ const root = el.getRootNode();
129
+ if (root !== document && Reflect.has(root, 'createElement')) {
130
+ const cloned = root.createElement(el.tagName.toLowerCase());
131
+ for (const attr of el.getAttributeNames()) {
132
+ cloned.setAttribute(attr, el.getAttribute(attr));
133
+ }
134
+ if (deep) {
135
+ for (let i = 0; i < el.children.length; i++) {
136
+ const clonedChild = cloneNode(el.children[i], deep);
137
+ cloned.appendChild(clonedChild);
138
+ }
139
+ }
140
+ return cloned;
141
+ }
142
+ return el.cloneNode(deep);
143
+ };
@@ -0,0 +1,12 @@
1
+ export declare const defineCustomElement: (name: string, constructor: CustomElementConstructor) => void;
2
+ export declare const setNectaryRegistry: (registry: CustomElementRegistry) => void;
3
+ declare global {
4
+ interface ShadowRootInit {
5
+ customElements?: CustomElementRegistry;
6
+ }
7
+ }
8
+ export declare class NectaryElement extends HTMLElement {
9
+ attachShadow(options?: Partial<ShadowRootInit>): ShadowRoot;
10
+ version: string;
11
+ get focusable(): boolean;
12
+ }
@@ -0,0 +1,38 @@
1
+ import pkg from '../package.json';
2
+ const nectaryDefinitions = new Map();
3
+ let nectaryRegistry = null;
4
+ export const defineCustomElement = (name, constructor) => {
5
+ if (nectaryRegistry !== null) {
6
+ if (nectaryRegistry.get(name) == null) {
7
+ nectaryRegistry.define(name, constructor);
8
+ }
9
+ return;
10
+ }
11
+ nectaryDefinitions.set(name, constructor);
12
+ };
13
+ export const setNectaryRegistry = registry => {
14
+ if (nectaryRegistry !== null) {
15
+ throw new Error('Nectary elements already registered');
16
+ }
17
+ nectaryRegistry = registry;
18
+ for (const [name, ctor] of nectaryDefinitions.entries()) {
19
+ if (nectaryRegistry.get(name) == null) {
20
+ nectaryRegistry.define(name, ctor);
21
+ }
22
+ }
23
+ nectaryDefinitions.clear();
24
+ };
25
+ export class NectaryElement extends HTMLElement {
26
+ attachShadow(options) {
27
+ return super.attachShadow({
28
+ mode: 'closed',
29
+ delegatesFocus: false,
30
+ customElements: nectaryRegistry,
31
+ ...options
32
+ });
33
+ }
34
+ version = pkg.version;
35
+ get focusable() {
36
+ return false;
37
+ }
38
+ }
@@ -0,0 +1 @@
1
+ export declare const getReactEventHandler: ($element: HTMLElement, handlerName: string) => ((arg?: any) => void) | null;
@@ -0,0 +1,8 @@
1
+ export const getReactEventHandler = ($element, handlerName) => {
2
+ for (const key in $element) {
3
+ if (key.startsWith('__reactProps$')) {
4
+ return $element[key][handlerName];
5
+ }
6
+ }
7
+ return null;
8
+ };
package/utils/index.d.ts CHANGED
@@ -1,57 +1,8 @@
1
- import type { TRect } from '../types';
2
- export declare const defineCustomElement: (name: string, constructor: CustomElementConstructor) => void;
3
- export declare const setNectaryRegistry: (registry: CustomElementRegistry) => void;
4
- declare global {
5
- interface ShadowRootInit {
6
- customElements?: CustomElementRegistry;
7
- }
8
- }
9
- export declare class NectaryElement extends HTMLElement {
10
- attachShadow(options?: Partial<ShadowRootInit>): ShadowRoot;
11
- version: string;
12
- get focusable(): boolean;
13
- }
14
- export declare const getReactEventHandler: ($element: HTMLElement, handlerName: string) => ((arg?: any) => void) | null;
15
- export declare const updateExplicitBooleanAttribute: ($element: Element, attrName: string, attrValue: boolean | null | undefined) => void;
16
- export declare const isAttrTrue: (attrValue: string | null) => boolean;
17
- export declare const getBooleanAttribute: ($element: Element, attrName: string) => boolean;
18
- export declare const updateBooleanAttribute: ($element: Element, attrName: string, attrValue: boolean | null | undefined) => void;
19
- export declare const updateAttribute: ($element: Element, attrName: string, attrValue: string | number | boolean | null | undefined) => void;
20
- export declare function getAttribute($element: Element, attrName: string): string | null;
21
- export declare function getAttribute($element: Element, attrName: string, defaultValue: string): string;
22
- export declare const isLiteralValue: <T extends readonly string[]>(literals: T, value: string | null | undefined) => value is T[number];
23
- export declare const updateLiteralAttribute: <T extends readonly string[]>($element: Element, literals: T, attrName: string, attrValue: string | null | undefined) => void;
24
- export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string): T[number];
25
- export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: null): T[number] | null;
26
- export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: T[number]): T[number];
27
- export declare const clampNumber: (value: number, min: number, max: number) => number;
28
- declare type IntegerOptions = {
29
- min?: number;
30
- max?: number;
31
- defaultValue?: number | null;
32
- itemSizeMultiplier?: number;
33
- itemSpaceBetween?: number;
34
- };
35
- export declare const attrValueToInteger: (value: string | null, options?: IntegerOptions) => number | null;
36
- export declare const attrValueToPixels: (value: string | null, options?: IntegerOptions) => string;
37
- export declare const updateIntegerAttribute: ($element: Element, attrName: string, attrValue: string | number | null | undefined, options?: IntegerOptions) => void;
38
- export declare function getIntegerAttribute($element: Element, attrName: string): number | undefined;
39
- export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: null): number | null;
40
- export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: number): number;
41
- export declare const getCsvSet: (acc: string) => Set<string>;
42
- export declare const updateCsv: (acc: string, value: string, setActive: boolean) => string;
43
- export declare const getFirstCsvValue: (acc: string) => string | null;
44
- export declare const getRect: (el: Element) => TRect;
45
- export declare const setClass: (elem: Element, name: string, isSet: boolean) => void;
46
- export declare const getCssVar: (element: Element, variableName: string) => string | null;
47
- export declare const throttleAnimationFrame: (cb: (...args: any[]) => void) => {
48
- fn: (...args: any[]) => void;
49
- cancel: () => void;
50
- };
51
- export declare const getFirstSlotElement: (root: HTMLSlotElement, isDeep?: boolean) => HTMLElement | null;
52
- export declare const getFirstFocusableElement: (root: Element) => NectaryElement | null;
53
- export declare const cloneNode: (el: Element, deep: boolean) => Element;
54
- export declare const isElementFocused: ($el: Element | null) => boolean;
55
- export declare const rectOverlap: (targetRect: TRect, contentRect: TRect) => boolean;
56
- export declare const getTargetRect: (slot: HTMLSlotElement) => TRect | null;
57
- export {};
1
+ export * from './context';
2
+ export * from './csv';
3
+ export * from './dom';
4
+ export * from './element';
5
+ export * from './rect';
6
+ export * from './slot';
7
+ export * from './throttle';
8
+ export * from './get-react-event-handler';
package/utils/index.js CHANGED
@@ -1,301 +1,8 @@
1
- import pkg from '../package.json';
2
- const nectaryDefinitions = new Map();
3
- let nectaryRegistry = null;
4
- export const defineCustomElement = (name, constructor) => {
5
- if (nectaryRegistry !== null) {
6
- if (nectaryRegistry.get(name) == null) {
7
- nectaryRegistry.define(name, constructor);
8
- }
9
- return;
10
- }
11
- nectaryDefinitions.set(name, constructor);
12
- };
13
- export const setNectaryRegistry = registry => {
14
- if (nectaryRegistry !== null) {
15
- throw new Error('Nectary elements already registered');
16
- }
17
- nectaryRegistry = registry;
18
- for (const [name, ctor] of nectaryDefinitions.entries()) {
19
- if (nectaryRegistry.get(name) == null) {
20
- nectaryRegistry.define(name, ctor);
21
- }
22
- }
23
- nectaryDefinitions.clear();
24
- };
25
- export class NectaryElement extends HTMLElement {
26
- attachShadow(options) {
27
- return super.attachShadow({
28
- mode: 'closed',
29
- delegatesFocus: false,
30
- customElements: nectaryRegistry,
31
- ...options
32
- });
33
- }
34
- version = pkg.version;
35
- get focusable() {
36
- return false;
37
- }
38
- }
39
- export const getReactEventHandler = ($element, handlerName) => {
40
- for (const key in $element) {
41
- if (key.startsWith('__reactProps$')) {
42
- return $element[key][handlerName];
43
- }
44
- }
45
- return null;
46
- };
47
- export const updateExplicitBooleanAttribute = ($element, attrName, attrValue) => {
48
- $element.setAttribute(attrName, attrValue === true ? 'true' : 'false');
49
- };
50
- export const isAttrTrue = attrValue => {
51
- return attrValue === '' || attrValue !== 'false' && attrValue !== null;
52
- };
53
- export const getBooleanAttribute = ($element, attrName) => {
54
- return isAttrTrue($element.getAttribute(attrName));
55
- };
56
- export const updateBooleanAttribute = ($element, attrName, attrValue) => {
57
- const currentAttrValue = $element.getAttribute(attrName);
58
- if (attrValue === true) {
59
- if (!isAttrTrue(currentAttrValue)) {
60
- $element.setAttribute(attrName, '');
61
- }
62
- } else if (currentAttrValue !== null) {
63
- $element.removeAttribute(attrName);
64
- }
65
- };
66
- export const updateAttribute = ($element, attrName, attrValue) => {
67
- if (attrValue != null) {
68
- $element.setAttribute(attrName, String(attrValue));
69
- } else {
70
- $element.removeAttribute(attrName);
71
- }
72
- };
73
- export function getAttribute($element, attrName) {
74
- let defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
75
- return $element.getAttribute(attrName) ?? defaultValue;
76
- }
77
- export const isLiteralValue = (literals, value) => {
78
- return value != null && literals.includes(value);
79
- };
80
- export const updateLiteralAttribute = ($element, literals, attrName, attrValue) => {
81
- if (isLiteralValue(literals, attrValue)) {
82
- $element.setAttribute(attrName, attrValue);
83
- } else {
84
- $element.removeAttribute(attrName);
85
- }
86
- };
87
- export function getLiteralAttribute($element, literals, attrName, defaultValue) {
88
- const attrValue = $element.getAttribute(attrName);
89
- if (isLiteralValue(literals, attrValue)) {
90
- return attrValue;
91
- }
92
- if (typeof defaultValue === 'undefined') {
93
- throw new Error(`Invalid attribute value: ${attrName} = ${attrValue}`);
94
- }
95
- return defaultValue;
96
- }
97
- export const clampNumber = (value, min, max) => {
98
- return Math.min(max, Math.max(min, value));
99
- };
100
- const DEFAULT_INTEGER_OPTIONS = {
101
- itemSizeMultiplier: 1,
102
- itemSpaceBetween: 0,
103
- defaultValue: null
104
- };
105
- const applyRange = (value, _ref) => {
106
- let {
107
- min,
108
- max
109
- } = _ref;
110
- let result = value;
111
- if (min != null) {
112
- result = Math.max(min, result);
113
- }
114
- if (max != null) {
115
- result = Math.min(max, result);
116
- }
117
- return result;
118
- };
119
- export const attrValueToInteger = function (value) {
120
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
121
- const {
122
- defaultValue = null,
123
- itemSizeMultiplier = 1,
124
- itemSpaceBetween = 0
125
- } = options;
126
- let intValue = defaultValue;
127
- if (value !== null) {
128
- const int = parseInt(value);
129
- if (Number.isInteger(int)) {
130
- intValue = applyRange(int, options);
131
- }
132
- }
133
- if (intValue !== null) {
134
- return intValue * itemSizeMultiplier + Math.max(intValue - 1, 0) * itemSpaceBetween;
135
- }
136
- return null;
137
- };
138
- export const attrValueToPixels = function (value) {
139
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
140
- const int = attrValueToInteger(value, options);
141
- return int === null ? 'unset' : `${int}px`;
142
- };
143
- export const updateIntegerAttribute = function ($element, attrName, attrValue) {
144
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_INTEGER_OPTIONS;
145
- const {
146
- defaultValue = null,
147
- itemSizeMultiplier: multiplier = 1
148
- } = options;
149
- let intValue = null;
150
- if (typeof attrValue === 'string') {
151
- intValue = attrValueToInteger(attrValue, options);
152
- } else if (typeof attrValue === 'number') {
153
- intValue = applyRange(attrValue, options) * multiplier;
154
- } else {
155
- intValue = defaultValue;
156
- }
157
- if (intValue === null) {
158
- $element.removeAttribute(attrName);
159
- } else {
160
- $element.setAttribute(attrName, intValue.toFixed(0));
161
- }
162
- };
163
- export function getIntegerAttribute($element, attrName, defaultValue) {
164
- return attrValueToInteger($element.getAttribute(attrName)) ?? defaultValue;
165
- }
166
- const unpackCsv = csv => {
167
- return csv === '' ? [] : csv.split(',');
168
- };
169
- const packCsv = values => {
170
- return Array.from(values).join(',');
171
- };
172
- export const getCsvSet = acc => {
173
- return new Set(unpackCsv(acc));
174
- };
175
- export const updateCsv = (acc, value, setActive) => {
176
- const values = getCsvSet(acc);
177
- if (setActive) {
178
- values.add(value);
179
- } else {
180
- values.delete(value);
181
- }
182
- return packCsv(values);
183
- };
184
- export const getFirstCsvValue = acc => {
185
- return acc === '' ? null : unpackCsv(acc)[0];
186
- };
187
- export const getRect = el => {
188
- const {
189
- x,
190
- y,
191
- width,
192
- height
193
- } = el.getBoundingClientRect();
194
- return {
195
- x,
196
- y,
197
- width,
198
- height
199
- };
200
- };
201
- export const setClass = (elem, name, isSet) => {
202
- isSet ? elem.classList.add(name) : elem.classList.remove(name);
203
- };
204
- export const getCssVar = (element, variableName) => {
205
- const result = getComputedStyle(element).getPropertyValue(variableName);
206
- return result === '' ? null : result;
207
- };
208
- const throttle = (delayFn, cancelFn) => cb => {
209
- let id = null;
210
- let fnArgs;
211
- const delayCallback = () => {
212
- id = null;
213
- cb(fnArgs);
214
- };
215
- return {
216
- fn: function () {
217
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
218
- args[_key] = arguments[_key];
219
- }
220
- fnArgs = args;
221
- if (id === null) {
222
- id = delayFn(delayCallback);
223
- }
224
- },
225
- cancel: () => {
226
- if (id !== null) {
227
- cancelFn(id);
228
- }
229
- }
230
- };
231
- };
232
- export const throttleAnimationFrame = throttle(global.requestAnimationFrame, global.cancelAnimationFrame);
233
- const isSlotElement = el => {
234
- return el.tagName === 'SLOT';
235
- };
236
- export const getFirstSlotElement = function (root) {
237
- let isDeep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
238
- const el = root.assignedElements()[0];
239
- if (el == null) {
240
- return null;
241
- }
242
- if (isDeep && isSlotElement(el)) {
243
- return getFirstSlotElement(el, isDeep);
244
- }
245
- return el;
246
- };
247
- const getChildren = root => {
248
- if (isSlotElement(root)) {
249
- return root.assignedElements();
250
- }
251
- return Array.from(root.children);
252
- };
253
- const isFocusable = el => {
254
- return el.focusable === true;
255
- };
256
- export const getFirstFocusableElement = root => {
257
- for (const child of getChildren(root)) {
258
- if (isFocusable(child)) {
259
- return child;
260
- }
261
- const resultEl = getFirstFocusableElement(child);
262
- if (resultEl !== null) {
263
- return resultEl;
264
- }
265
- }
266
- return null;
267
- };
268
- export const cloneNode = (el, deep) => {
269
- const root = el.getRootNode();
270
- if (root !== document && Reflect.has(root, 'createElement')) {
271
- const cloned = root.createElement(el.tagName.toLowerCase());
272
- for (const attr of el.getAttributeNames()) {
273
- cloned.setAttribute(attr, el.getAttribute(attr));
274
- }
275
- if (deep) {
276
- for (let i = 0; i < el.children.length; i++) {
277
- const clonedChild = cloneNode(el.children[i], deep);
278
- cloned.appendChild(clonedChild);
279
- }
280
- }
281
- return cloned;
282
- }
283
- return el.cloneNode(deep);
284
- };
285
- export const isElementFocused = $el => {
286
- return $el !== null && $el === $el.getRootNode().activeElement;
287
- };
288
- export const rectOverlap = (targetRect, contentRect) => {
289
- return targetRect.x < contentRect.x + contentRect.width && targetRect.x + targetRect.width > contentRect.x && targetRect.y < contentRect.y + contentRect.height && targetRect.y + targetRect.height > contentRect.y;
290
- };
291
-
292
- export const getTargetRect = slot => {
293
- const item = getFirstSlotElement(slot, true);
294
- if (item === null) {
295
- return null;
296
- }
297
- if (Reflect.has(item, 'footprintRect')) {
298
- return item.footprintRect;
299
- }
300
- return getRect(item);
301
- };
1
+ export * from './context';
2
+ export * from './csv';
3
+ export * from './dom';
4
+ export * from './element';
5
+ export * from './rect';
6
+ export * from './slot';
7
+ export * from './throttle';
8
+ export * from './get-react-event-handler';
@@ -0,0 +1,4 @@
1
+ import type { TRect } from '../types';
2
+ export declare const getRect: (el: Element) => TRect;
3
+ export declare const rectOverlap: (targetRect: TRect, contentRect: TRect) => boolean;
4
+ export declare const getTargetRect: (slot: HTMLSlotElement) => TRect | null;
package/utils/rect.js ADDED
@@ -0,0 +1,29 @@
1
+ import { getFirstSlotElement } from './slot';
2
+ export const getRect = el => {
3
+ const {
4
+ x,
5
+ y,
6
+ width,
7
+ height
8
+ } = el.getBoundingClientRect();
9
+ return {
10
+ x,
11
+ y,
12
+ width,
13
+ height
14
+ };
15
+ };
16
+ export const rectOverlap = (targetRect, contentRect) => {
17
+ return targetRect.x < contentRect.x + contentRect.width && targetRect.x + targetRect.width > contentRect.x && targetRect.y < contentRect.y + contentRect.height && targetRect.y + targetRect.height > contentRect.y;
18
+ };
19
+
20
+ export const getTargetRect = slot => {
21
+ const item = getFirstSlotElement(slot, true);
22
+ if (item === null) {
23
+ return null;
24
+ }
25
+ if (Reflect.has(item, 'footprintRect')) {
26
+ return item.footprintRect;
27
+ }
28
+ return getRect(item);
29
+ };
@@ -0,0 +1,4 @@
1
+ import type { NectaryElement } from './element';
2
+ export declare const getFirstSlotElement: (root: HTMLSlotElement, isDeep?: boolean) => HTMLElement | null;
3
+ export declare const getFirstFocusableElement: (root: Element) => NectaryElement | null;
4
+ export declare const isElementFocused: ($el: Element | null) => boolean;
package/utils/slot.js ADDED
@@ -0,0 +1,38 @@
1
+ const isSlotElement = el => {
2
+ return el.tagName === 'SLOT';
3
+ };
4
+ export const getFirstSlotElement = function (root) {
5
+ let isDeep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
6
+ const el = root.assignedElements()[0];
7
+ if (el == null) {
8
+ return null;
9
+ }
10
+ if (isDeep && isSlotElement(el)) {
11
+ return getFirstSlotElement(el, isDeep);
12
+ }
13
+ return el;
14
+ };
15
+ const getChildren = root => {
16
+ if (isSlotElement(root)) {
17
+ return root.assignedElements();
18
+ }
19
+ return Array.from(root.children);
20
+ };
21
+ const isFocusable = el => {
22
+ return el.focusable === true;
23
+ };
24
+ export const getFirstFocusableElement = root => {
25
+ for (const child of getChildren(root)) {
26
+ if (isFocusable(child)) {
27
+ return child;
28
+ }
29
+ const resultEl = getFirstFocusableElement(child);
30
+ if (resultEl !== null) {
31
+ return resultEl;
32
+ }
33
+ }
34
+ return null;
35
+ };
36
+ export const isElementFocused = $el => {
37
+ return $el !== null && $el === $el.getRootNode().activeElement;
38
+ };
@@ -0,0 +1,4 @@
1
+ export declare const throttleAnimationFrame: (cb: (...args: any[]) => void) => {
2
+ fn: (...args: any[]) => void;
3
+ cancel: () => void;
4
+ };