@fluentui/react-positioning 0.0.0-nightlyfe9829e48120211112.1 → 0.0.0-nightlyff78d1e27a20220217.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. package/CHANGELOG.json +173 -8
  2. package/CHANGELOG.md +49 -7
  3. package/dist/react-positioning.d.ts +113 -35
  4. package/lib/createArrowStyles.d.ts +64 -0
  5. package/lib/createArrowStyles.js +87 -0
  6. package/lib/createArrowStyles.js.map +1 -0
  7. package/lib/createVirtualElementFromClick.js +17 -15
  8. package/lib/createVirtualElementFromClick.js.map +1 -1
  9. package/lib/index.d.ts +2 -1
  10. package/lib/index.js +2 -1
  11. package/lib/index.js.map +1 -1
  12. package/lib/types.d.ts +28 -7
  13. package/lib/types.js.map +1 -1
  14. package/lib/usePopper.d.ts +2 -14
  15. package/lib/usePopper.js +367 -311
  16. package/lib/usePopper.js.map +1 -1
  17. package/lib/usePopperMouseTarget.js +28 -22
  18. package/lib/usePopperMouseTarget.js.map +1 -1
  19. package/lib/utils/getBasePlacement.js +1 -1
  20. package/lib/utils/getBasePlacement.js.map +1 -1
  21. package/lib/utils/getBoundary.js +15 -10
  22. package/lib/utils/getBoundary.js.map +1 -1
  23. package/lib/utils/getReactFiberFromNode.js +39 -35
  24. package/lib/utils/getReactFiberFromNode.js.map +1 -1
  25. package/lib/utils/getScrollParent.js +46 -32
  26. package/lib/utils/getScrollParent.js.map +1 -1
  27. package/lib/utils/index.js.map +1 -1
  28. package/lib/utils/mergeArrowOffset.js +29 -24
  29. package/lib/utils/mergeArrowOffset.js.map +1 -1
  30. package/lib/utils/positioningHelper.d.ts +2 -2
  31. package/lib/utils/positioningHelper.js +38 -30
  32. package/lib/utils/positioningHelper.js.map +1 -1
  33. package/lib/utils/resolvePositioningShorthand.js +57 -19
  34. package/lib/utils/resolvePositioningShorthand.js.map +1 -1
  35. package/lib/utils/useCallbackRef.js +35 -29
  36. package/lib/utils/useCallbackRef.js.map +1 -1
  37. package/lib-commonjs/createArrowStyles.d.ts +64 -0
  38. package/lib-commonjs/createArrowStyles.js +100 -0
  39. package/lib-commonjs/createArrowStyles.js.map +1 -0
  40. package/lib-commonjs/createVirtualElementFromClick.js +23 -16
  41. package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
  42. package/lib-commonjs/index.d.ts +2 -1
  43. package/lib-commonjs/index.js +28 -6
  44. package/lib-commonjs/index.js.map +1 -1
  45. package/lib-commonjs/types.d.ts +28 -7
  46. package/lib-commonjs/types.js +4 -1
  47. package/lib-commonjs/types.js.map +1 -1
  48. package/lib-commonjs/usePopper.d.ts +2 -14
  49. package/lib-commonjs/usePopper.js +382 -316
  50. package/lib-commonjs/usePopper.js.map +1 -1
  51. package/lib-commonjs/usePopperMouseTarget.js +38 -25
  52. package/lib-commonjs/usePopperMouseTarget.js.map +1 -1
  53. package/lib-commonjs/utils/getBasePlacement.js +7 -2
  54. package/lib-commonjs/utils/getBasePlacement.js.map +1 -1
  55. package/lib-commonjs/utils/getBoundary.js +23 -12
  56. package/lib-commonjs/utils/getBoundary.js.map +1 -1
  57. package/lib-commonjs/utils/getReactFiberFromNode.js +44 -36
  58. package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
  59. package/lib-commonjs/utils/getScrollParent.js +53 -33
  60. package/lib-commonjs/utils/getScrollParent.js.map +1 -1
  61. package/lib-commonjs/utils/index.js +14 -2
  62. package/lib-commonjs/utils/index.js.map +1 -1
  63. package/lib-commonjs/utils/mergeArrowOffset.js +35 -25
  64. package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
  65. package/lib-commonjs/utils/positioningHelper.d.ts +2 -2
  66. package/lib-commonjs/utils/positioningHelper.js +46 -31
  67. package/lib-commonjs/utils/positioningHelper.js.map +1 -1
  68. package/lib-commonjs/utils/resolvePositioningShorthand.js +65 -22
  69. package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
  70. package/lib-commonjs/utils/useCallbackRef.js +45 -32
  71. package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
  72. package/package.json +7 -8
@@ -1,41 +1,49 @@
1
- const getPositionMap = (rtl) => ({
2
- above: 'top',
3
- below: 'bottom',
4
- before: rtl ? 'right' : 'left',
5
- after: rtl ? 'left' : 'right',
1
+ const getPositionMap = rtl => ({
2
+ above: 'top',
3
+ below: 'bottom',
4
+ before: rtl ? 'right' : 'left',
5
+ after: rtl ? 'left' : 'right'
6
6
  });
7
- const getAlignmentMap = (rtl) => ({
8
- start: rtl ? 'end' : 'start',
9
- end: rtl ? 'start' : 'end',
10
- top: 'start',
11
- bottom: 'end',
12
- center: '',
7
+
8
+ const getAlignmentMap = rtl => ({
9
+ start: rtl ? 'end' : 'start',
10
+ end: rtl ? 'start' : 'end',
11
+ top: 'start',
12
+ bottom: 'end',
13
+ center: ''
13
14
  });
15
+
14
16
  const shouldAlignToCenter = (p, a) => {
15
- const positionedVertically = p === 'above' || p === 'below';
16
- const alignedVertically = a === 'top' || a === 'bottom';
17
- return (positionedVertically && alignedVertically) || (!positionedVertically && !alignedVertically);
17
+ const positionedVertically = p === 'above' || p === 'below';
18
+ const alignedVertically = a === 'top' || a === 'bottom';
19
+ return positionedVertically && alignedVertically || !positionedVertically && !alignedVertically;
18
20
  };
19
21
  /**
20
22
  * @see positioninHelper.test.ts for expected placement values
21
23
  */
24
+
25
+
22
26
  export const getPlacement = (align, position, rtl) => {
23
- const alignment = shouldAlignToCenter(position, align) ? 'center' : align;
24
- const computedPosition = position && getPositionMap(rtl)[position];
25
- const computedAlignmnent = alignment && getAlignmentMap(rtl)[alignment];
26
- if (computedPosition && computedAlignmnent) {
27
- return `${computedPosition}-${computedAlignmnent}`;
28
- }
29
- return computedPosition || 'auto';
27
+ const alignment = shouldAlignToCenter(position, align) ? 'center' : align;
28
+ const computedPosition = position && getPositionMap(rtl)[position];
29
+ const computedAlignmnent = alignment && getAlignmentMap(rtl)[alignment];
30
+
31
+ if (computedPosition && computedAlignmnent) {
32
+ return `${computedPosition}-${computedAlignmnent}`;
33
+ }
34
+
35
+ return computedPosition || 'auto';
30
36
  };
31
- export const applyRtlToOffset = (offset) => {
32
- if (typeof offset === 'undefined') {
33
- return undefined;
34
- }
35
- if (Array.isArray(offset)) {
36
- offset[0] = offset[0] * -1;
37
- return offset;
38
- }
39
- return ((param) => applyRtlToOffset(offset(param)));
37
+ export const applyRtlToOffset = offset => {
38
+ if (typeof offset === 'undefined') {
39
+ return undefined;
40
+ }
41
+
42
+ if (Array.isArray(offset)) {
43
+ offset[0] = offset[0] * -1;
44
+ return offset;
45
+ }
46
+
47
+ return param => applyRtlToOffset(offset(param));
40
48
  };
41
49
  //# sourceMappingURL=positioningHelper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"positioningHelper.js","sourceRoot":"","sources":["../../src/utils/positioningHelper.ts"],"names":[],"mappings":"AAMA,MAAM,cAAc,GAAG,CAAC,GAAa,EAAuC,EAAE,CAAC,CAAC;IAC9E,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;IAC9B,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;CAC9B,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,CAAC,GAAa,EAAqC,EAAE,CAAC,CAAC;IAC7E,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO;IAC5B,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;IAC1B,GAAG,EAAE,OAAO;IACZ,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,EAAE;CACX,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG,CAAC,CAAY,EAAE,CAAa,EAAW,EAAE;IACnE,MAAM,oBAAoB,GAAG,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,OAAO,CAAC;IAC5D,MAAM,iBAAiB,GAAG,CAAC,KAAK,KAAK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OAAO,MAAM,gBAAgB,GAAI,MAAD,IAAmD;AACjF,MAAI,OAAO,MAAP,KAAkB,WAAtB,EAAmC;AACjC,WAAO,SAAP;AACD;;AAED,MAAI,KAAK,CAAC,OAAN,CAAc,MAAd,CAAJ,EAA2B;AACzB,IAAA,MAAM,CAAC,CAAD,CAAN,GAAY,MAAM,CAAC,CAAD,CAAN,GAAa,CAAC,CAA1B;AAEA,WAAO,MAAP;AACD;;AAED,SAAS,KAAD,IAAgC,gBAAgB,CAAC,MAAM,CAAC,KAAD,CAAP,CAAxD;AACD,CAZM","sourcesContent":["import * as PopperJs from '@popperjs/core';\nimport type { Alignment, Offset, OffsetFunction, OffsetFunctionParam, Position } from '../types';\n\ntype PlacementPosition = 'top' | 'bottom' | 'left' | 'right';\ntype PlacementAlign = 'start' | 'end' | ''; // '' represents center\n\nconst getPositionMap = (rtl?: boolean): Record<Position, PlacementPosition> => ({\n above: 'top',\n below: 'bottom',\n before: rtl ? 'right' : 'left',\n after: rtl ? 'left' : 'right',\n});\n\nconst getAlignmentMap = (rtl?: boolean): Record<Alignment, PlacementAlign> => ({\n start: rtl ? 'end' : 'start',\n end: rtl ? 'start' : 'end',\n top: 'start',\n bottom: 'end',\n center: '',\n});\n\nconst shouldAlignToCenter = (p?: Position, a?: Alignment): boolean => {\n const positionedVertically = p === 'above' || p === 'below';\n const alignedVertically = a === 'top' || a === 'bottom';\n\n return (positionedVertically && alignedVertically) || (!positionedVertically && !alignedVertically);\n};\n\n/**\n * @see positioninHelper.test.ts for expected placement values\n */\nexport const getPlacement = (align?: Alignment, position?: Position, rtl?: boolean): PopperJs.Placement => {\n const alignment = shouldAlignToCenter(position, align) ? 'center' : align;\n\n const computedPosition = position && getPositionMap(rtl)[position];\n const computedAlignmnent = alignment && getAlignmentMap(rtl)[alignment];\n\n if (computedPosition && computedAlignmnent) {\n return `${computedPosition}-${computedAlignmnent}` as PopperJs.Placement;\n }\n\n return computedPosition || ('auto' as PopperJs.Placement);\n};\n\nexport const applyRtlToOffset = (offset: Offset | undefined): Offset | undefined => {\n if (typeof offset === 'undefined') {\n return undefined;\n }\n\n if (Array.isArray(offset)) {\n offset[0] = offset[0]! * -1;\n\n return offset;\n }\n\n return ((param: OffsetFunctionParam) => applyRtlToOffset(offset(param))) as OffsetFunction;\n};\n"],"sourceRoot":"../src/"}
@@ -1,25 +1,63 @@
1
1
  // Look up table for shorthand to avoid parsing strings
2
2
  const shorthandLookup = {
3
- above: { position: 'above', align: 'center' },
4
- 'above-start': { position: 'above', align: 'start' },
5
- 'above-end': { position: 'above', align: 'end' },
6
- below: { position: 'below', align: 'center' },
7
- 'below-start': { position: 'below', align: 'start' },
8
- 'below-end': { position: 'below', align: 'end' },
9
- before: { position: 'before', align: 'center' },
10
- 'before-top': { position: 'before', align: 'top' },
11
- 'before-bottom': { position: 'before', align: 'bottom' },
12
- after: { position: 'after', align: 'center' },
13
- 'after-top': { position: 'after', align: 'top' },
14
- 'after-bottom': { position: 'after', align: 'bottom' },
3
+ above: {
4
+ position: 'above',
5
+ align: 'center'
6
+ },
7
+ 'above-start': {
8
+ position: 'above',
9
+ align: 'start'
10
+ },
11
+ 'above-end': {
12
+ position: 'above',
13
+ align: 'end'
14
+ },
15
+ below: {
16
+ position: 'below',
17
+ align: 'center'
18
+ },
19
+ 'below-start': {
20
+ position: 'below',
21
+ align: 'start'
22
+ },
23
+ 'below-end': {
24
+ position: 'below',
25
+ align: 'end'
26
+ },
27
+ before: {
28
+ position: 'before',
29
+ align: 'center'
30
+ },
31
+ 'before-top': {
32
+ position: 'before',
33
+ align: 'top'
34
+ },
35
+ 'before-bottom': {
36
+ position: 'before',
37
+ align: 'bottom'
38
+ },
39
+ after: {
40
+ position: 'after',
41
+ align: 'center'
42
+ },
43
+ 'after-top': {
44
+ position: 'after',
45
+ align: 'top'
46
+ },
47
+ 'after-bottom': {
48
+ position: 'after',
49
+ align: 'bottom'
50
+ }
15
51
  };
16
52
  export function resolvePositioningShorthand(shorthand) {
17
- if (shorthand === undefined || shorthand === null) {
18
- return {};
19
- }
20
- if (typeof shorthand === 'string') {
21
- return shorthandLookup[shorthand];
22
- }
23
- return shorthand;
53
+ if (shorthand === undefined || shorthand === null) {
54
+ return {};
55
+ }
56
+
57
+ if (typeof shorthand === 'string') {
58
+ return shorthandLookup[shorthand];
59
+ }
60
+
61
+ return shorthand;
24
62
  }
25
63
  //# sourceMappingURL=resolvePositioningShorthand.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolvePositioningShorthand.js","sourceRoot":"","sources":["../../src/utils/resolvePositioningShorthand.ts"],"names":[],"mappings":"AAEA,uDAAuD;AACvD,MAAM,eAAe,GAAoF;IACvG,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE;IAC7C,aAAa,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IACpD,WAAW,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;IAChD,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE;IAC7C,aAAa,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IACpD,WAAW,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;IAChD,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;IAC/C,YAAY,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE;IAClD,eAAe,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;IACxD,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE;IAC7C,WAAW,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;IACh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vG,EAAA,KAAK,EAAE;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B,GAVgG;AAWvG,eAAa;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B,GAX0F;AAYvG,kBAAgB;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B;AAZuF,CAAzG;AAeA,OAAM,SAAU,2BAAV,CACJ,SADI,EAC8C;AAElD,MAAI,SAAS,KAAK,SAAd,IAA2B,SAAS,KAAK,IAA7C,EAAmD;AACjD,WAAO,EAAP;AACD;;AAED,MAAI,OAAO,SAAP,KAAqB,QAAzB,EAAmC;AACjC,WAAO,eAAe,CAAC,SAAD,CAAtB;AACD;;AAED,SAAO,SAAP;AACD","sourcesContent":["import type { PositioningShorthand, PositioningShorthandValue, PositioningProps } from '../types';\n\n// Look up table for shorthand to avoid parsing strings\nconst shorthandLookup: Record<PositioningShorthandValue, Pick<PositioningProps, 'position' | 'align'>> = {\n above: { position: 'above', align: 'center' },\n 'above-start': { position: 'above', align: 'start' },\n 'above-end': { position: 'above', align: 'end' },\n below: { position: 'below', align: 'center' },\n 'below-start': { position: 'below', align: 'start' },\n 'below-end': { position: 'below', align: 'end' },\n before: { position: 'before', align: 'center' },\n 'before-top': { position: 'before', align: 'top' },\n 'before-bottom': { position: 'before', align: 'bottom' },\n after: { position: 'after', align: 'center' },\n 'after-top': { position: 'after', align: 'top' },\n 'after-bottom': { position: 'after', align: 'bottom' },\n};\n\nexport function resolvePositioningShorthand(\n shorthand: PositioningShorthand | undefined | null,\n): Readonly<PositioningProps> {\n if (shorthand === undefined || shorthand === null) {\n return {};\n }\n\n if (typeof shorthand === 'string') {\n return shorthandLookup[shorthand];\n }\n\n return shorthand as Readonly<PositioningProps>;\n}\n"],"sourceRoot":"../src/"}
@@ -17,35 +17,41 @@ import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
17
17
  * ref.current = 1;
18
18
  * // prints 0 -> 1
19
19
  */
20
+
20
21
  export function useCallbackRef(initialValue, callback, skipInitialResolve) {
21
- const isFirst = React.useRef(true);
22
- const [ref] = React.useState(() => ({
23
- // value
24
- value: initialValue,
25
- // last callback
26
- callback,
27
- // "memoized" public interface
28
- facade: {
29
- get current() {
30
- return ref.value;
31
- },
32
- set current(value) {
33
- const last = ref.value;
34
- if (last !== value) {
35
- ref.value = value;
36
- if (skipInitialResolve && isFirst.current) {
37
- return;
38
- }
39
- ref.callback(value, last);
40
- }
41
- },
42
- },
43
- }));
44
- useIsomorphicLayoutEffect(() => {
45
- isFirst.current = false;
46
- }, []);
47
- // update callback
48
- ref.callback = callback;
49
- return ref.facade;
22
+ const isFirst = React.useRef(true);
23
+ const [ref] = React.useState(() => ({
24
+ // value
25
+ value: initialValue,
26
+ // last callback
27
+ callback,
28
+ // "memoized" public interface
29
+ facade: {
30
+ get current() {
31
+ return ref.value;
32
+ },
33
+
34
+ set current(value) {
35
+ const last = ref.value;
36
+
37
+ if (last !== value) {
38
+ ref.value = value;
39
+
40
+ if (skipInitialResolve && isFirst.current) {
41
+ return;
42
+ }
43
+
44
+ ref.callback(value, last);
45
+ }
46
+ }
47
+
48
+ }
49
+ }));
50
+ useIsomorphicLayoutEffect(() => {
51
+ isFirst.current = false;
52
+ }, []); // update callback
53
+
54
+ ref.callback = callback;
55
+ return ref.facade;
50
56
  }
51
57
  //# sourceMappingURL=useCallbackRef.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCallbackRef.js","sourceRoot":"","sources":["../../src/utils/useCallbackRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAEtE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,cAAc,CAC5B,YAAsB,EACtB,QAA2D,EAC3D,kBAA4B;IAE5B,MAAM,OAAO,GAAG,KAA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GlC;AACA,IAAA,QAJkC;AAKlC;AACA,IAAA,MAAM,EAAE;AACN,UAAI,OAAJ,GAAW;AACT,eAAO,GAAG,CAAC,KAAX;AACD,OAHK;;AAIN,UAAI,OAAJ,CAAY,KAAZ,EAAiB;AACf,cAAM,IAAI,GAAG,GAAG,CAAC,KAAjB;;AAEA,YAAI,IAAI,KAAK,KAAb,EAAoB;AAClB,UAAA,GAAG,CAAC,KAAJ,GAAY,KAAZ;;AAEA,cAAI,kBAAkB,IAAI,OAAO,CAAC,OAAlC,EAA2C;AACzC;AACD;;AAED,UAAA,GAAG,CAAC,QAAJ,CAAa,KAAb,EAAoB,IAApB;AACD;AACF;;AAhBK;AAN0B,GAAP,CAAf,CAAd;AA0BA,EAAA,yBAAyB,CAAC,MAAK;AAC7B,IAAA,OAAO,CAAC,OAAR,GAAkB,KAAlB;AACD,GAFwB,EAEtB,EAFsB,CAAzB,CA7B4B,CAiC5B;;AACA,EAAA,GAAG,CAAC,QAAJ,GAAe,QAAf;AAEA,SAAO,GAAG,CAAC,MAAX;AACD","sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\n\n/**\n * Creates a MutableRef with ref change callback. Is useful as React.useRef() doesn't notify you when its content\n * changes and mutating the .current property doesn't cause a re-render. An opt-out will be use a callback ref via\n * React.useState(), but it will cause re-renders always.\n *\n * https://reactjs.org/docs/hooks-reference.html#useref\n * https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref\n *\n * @param initialValue - initial ref value\n * @param callback - a callback to run when value changes\n * @param skipInitialResolve - a flag to skip an initial ref report\n *\n * @example\n * const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);\n * ref.current = 1;\n * // prints 0 -> 1\n */\nexport function useCallbackRef<T>(\n initialValue: T | null,\n callback: (newValue: T | null, lastValue: T | null) => void,\n skipInitialResolve?: boolean,\n): React.MutableRefObject<T | null> {\n const isFirst = React.useRef(true);\n const [ref] = React.useState(() => ({\n // value\n value: initialValue,\n // last callback\n callback,\n // \"memoized\" public interface\n facade: {\n get current() {\n return ref.value;\n },\n set current(value) {\n const last = ref.value;\n\n if (last !== value) {\n ref.value = value;\n\n if (skipInitialResolve && isFirst.current) {\n return;\n }\n\n ref.callback(value, last);\n }\n },\n },\n }));\n\n useIsomorphicLayoutEffect(() => {\n isFirst.current = false;\n }, []);\n\n // update callback\n ref.callback = callback;\n\n return ref.facade;\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,64 @@
1
+ import type { GriffelStyle } from '@griffel/react';
2
+ /**
3
+ * Options parameter for the createArrowStyles function
4
+ */
5
+ export declare type CreateArrowStylesOptions = {
6
+ /**
7
+ * The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.
8
+ *
9
+ * This can be undefined to leave out the arrow size styles. You must then add styles created by
10
+ * createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.
11
+ */
12
+ arrowHeight: number | undefined;
13
+ /**
14
+ * The borderWidth of the arrow. Should be the same borderWidth as the parent element.
15
+ *
16
+ * @defaultvalue 1px
17
+ */
18
+ borderWidth?: GriffelStyle['borderBottomWidth'];
19
+ /**
20
+ * The borderStyle for the arrow. Should be the same borderStyle as the parent element.
21
+ *
22
+ * @defaultvalue solid
23
+ */
24
+ borderStyle?: GriffelStyle['borderBottomStyle'];
25
+ /**
26
+ * The borderColor of the arrow. Should be the same borderColor as the parent element.
27
+ *
28
+ * @defaultvalue tokens.colorTransparentStroke
29
+ */
30
+ borderColor?: GriffelStyle['borderBottomColor'];
31
+ };
32
+ /**
33
+ * Helper that creates a makeStyles rule for an arrow element.
34
+ * For runtime arrow size toggling simply create extra classnames to apply to the arrow element
35
+ *
36
+ * ```ts
37
+ * makeStyles({
38
+ * arrowWithSize: createArrowStyles({ arrowHeight: 6 }),
39
+ *
40
+ * arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),
41
+ * mediumArrow: createArrowHeightStyles(4),
42
+ * smallArrow: createArrowHeightStyles(2),
43
+ * })
44
+ * ...
45
+ *
46
+ * state.arrowWithSize.className = styles.arrowWithSize;
47
+ * state.arrowWithoutSize.className = mergeClasses(
48
+ * styles.arrowWithoutSize,
49
+ * state.smallArrow && styles.smallArrow,
50
+ * state.mediumArrow && styles.mediumArrow,
51
+ * )
52
+ * ```
53
+ */
54
+ export declare function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle;
55
+ /**
56
+ * Creates CSS styles to size the arrow created by createArrowStyles to the given height.
57
+ *
58
+ * Use this when you need to create classes for several different arrow sizes. If you only need a
59
+ * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.
60
+ */
61
+ export declare function createArrowHeightStyles(arrowHeight: number): {
62
+ width: string;
63
+ height: string;
64
+ };
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createArrowHeightStyles = exports.createArrowStyles = void 0;
7
+
8
+ const react_1 = /*#__PURE__*/require("@griffel/react");
9
+
10
+ const react_theme_1 = /*#__PURE__*/require("@fluentui/react-theme");
11
+ /**
12
+ * Helper that creates a makeStyles rule for an arrow element.
13
+ * For runtime arrow size toggling simply create extra classnames to apply to the arrow element
14
+ *
15
+ * ```ts
16
+ * makeStyles({
17
+ * arrowWithSize: createArrowStyles({ arrowHeight: 6 }),
18
+ *
19
+ * arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),
20
+ * mediumArrow: createArrowHeightStyles(4),
21
+ * smallArrow: createArrowHeightStyles(2),
22
+ * })
23
+ * ...
24
+ *
25
+ * state.arrowWithSize.className = styles.arrowWithSize;
26
+ * state.arrowWithoutSize.className = mergeClasses(
27
+ * styles.arrowWithoutSize,
28
+ * state.smallArrow && styles.smallArrow,
29
+ * state.mediumArrow && styles.mediumArrow,
30
+ * )
31
+ * ```
32
+ */
33
+
34
+
35
+ function createArrowStyles(options) {
36
+ const {
37
+ arrowHeight,
38
+ borderWidth = '1px',
39
+ borderStyle = 'solid',
40
+ borderColor = react_theme_1.tokens.colorTransparentStroke
41
+ } = options;
42
+ return {
43
+ position: 'absolute',
44
+ backgroundColor: 'inherit',
45
+ visibility: 'hidden',
46
+ zIndex: -1,
47
+ ...(arrowHeight && createArrowHeightStyles(arrowHeight)),
48
+ ':before': {
49
+ content: '""',
50
+ visibility: 'visible',
51
+ position: 'absolute',
52
+ boxSizing: 'border-box',
53
+ width: 'inherit',
54
+ height: 'inherit',
55
+ backgroundColor: 'inherit',
56
+ ...react_1.shorthands.borderRight(`${borderWidth} /* @noflip */`, `${borderStyle} /* @noflip */`, `${borderColor} /* @noflip */`),
57
+ ...react_1.shorthands.borderBottom(borderWidth, borderStyle, borderColor),
58
+ borderBottomRightRadius: react_theme_1.tokens.borderRadiusSmall,
59
+ transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)'
60
+ },
61
+ // Popper sets data-popper-placement on the root element, which is used to align the arrow
62
+ ':global([data-popper-placement^="top"])': {
63
+ bottom: `-${borderWidth}`,
64
+ '--angle': '0'
65
+ },
66
+ ':global([data-popper-placement^="right"])': {
67
+ left: `-${borderWidth} /* @noflip */`,
68
+ '--angle': '90deg'
69
+ },
70
+ ':global([data-popper-placement^="bottom"])': {
71
+ top: `-${borderWidth}`,
72
+ '--angle': '180deg'
73
+ },
74
+ ':global([data-popper-placement^="left"])': {
75
+ right: `-${borderWidth} /* @noflip */`,
76
+ '--angle': '270deg'
77
+ }
78
+ };
79
+ }
80
+
81
+ exports.createArrowStyles = createArrowStyles;
82
+ /**
83
+ * Creates CSS styles to size the arrow created by createArrowStyles to the given height.
84
+ *
85
+ * Use this when you need to create classes for several different arrow sizes. If you only need a
86
+ * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.
87
+ */
88
+
89
+ function createArrowHeightStyles(arrowHeight) {
90
+ // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.
91
+ // Multiply the triangle's height by sqrt(2) to get length of its edges.
92
+ const edgeLength = `${1.414 * arrowHeight}px`;
93
+ return {
94
+ width: edgeLength,
95
+ height: edgeLength
96
+ };
97
+ }
98
+
99
+ exports.createArrowHeightStyles = createArrowHeightStyles;
100
+ //# sourceMappingURL=createArrowStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["createArrowStyles.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,gBAAA,CAAA;;AACA,MAAA,aAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;AAqCA;;;;;;;;;;;;;;;;;;;;;AAqBG;;;AACH,SAAgB,iBAAhB,CAAkC,OAAlC,EAAmE;AACjE,QAAM;AACJ,IAAA,WADI;AAEJ,IAAA,WAAW,GAAG,KAFV;AAGJ,IAAA,WAAW,GAAG,OAHV;AAIJ,IAAA,WAAW,GAAG,aAAA,CAAA,MAAA,CAAO;AAJjB,MAKF,OALJ;AAOA,SAAO;AACL,IAAA,QAAQ,EAAE,UADL;AAEL,IAAA,eAAe,EAAE,SAFZ;AAGL,IAAA,UAAU,EAAE,QAHP;AAIL,IAAA,MAAM,EAAE,CAAC,CAJJ;AAML,QAAI,WAAW,IAAI,uBAAuB,CAAC,WAAD,CAA1C,CANK;AAQL,eAAW;AACT,MAAA,OAAO,EAAE,IADA;AAET,MAAA,UAAU,EAAE,SAFH;AAGT,MAAA,QAAQ,EAAE,UAHD;AAIT,MAAA,SAAS,EAAE,YAJF;AAKT,MAAA,KAAK,EAAE,SALE;AAMT,MAAA,MAAM,EAAE,SANC;AAOT,MAAA,eAAe,EAAE,SAPR;AAQT,SAAG,OAAA,CAAA,UAAA,CAAW,WAAX,CACD,GAAG,WAAW,gBADb,EAED,GAAG,WAAW,gBAFb,EAGD,GAAG,WAAW,gBAHb,CARM;AAaT,SAAG,OAAA,CAAA,UAAA,CAAW,YAAX,CAAwB,WAAxB,EAAqC,WAArC,EAAkD,WAAlD,CAbM;AAcT,MAAA,uBAAuB,EAAE,aAAA,CAAA,MAAA,CAAO,iBAdvB;AAeT,MAAA,SAAS,EAAE;AAfF,KARN;AA0BL;AACA,+CAA2C;AACzC,MAAA,MAAM,EAAE,IAAI,WAAW,EADkB;AAEzC,iBAAW;AAF8B,KA3BtC;AA+BL,iDAA6C;AAC3C,MAAA,IAAI,EAAE,IAAI,WAAW,gBADsB;AAE3C,iBAAW;AAFgC,KA/BxC;AAmCL,kDAA8C;AAC5C,MAAA,GAAG,EAAE,IAAI,WAAW,EADwB;AAE5C,iBAAW;AAFiC,KAnCzC;AAuCL,gDAA4C;AAC1C,MAAA,KAAK,EAAE,IAAI,WAAW,gBADoB;AAE1C,iBAAW;AAF+B;AAvCvC,GAAP;AA4CD;;AApDD,OAAA,CAAA,iBAAA,GAAA,iBAAA;AAsDA;;;;;AAKG;;AACH,SAAgB,uBAAhB,CAAwC,WAAxC,EAA2D;AACzD;AACA;AACA,QAAM,UAAU,GAAG,GAAG,QAAQ,WAAW,IAAzC;AACA,SAAO;AAAE,IAAA,KAAK,EAAE,UAAT;AAAqB,IAAA,MAAM,EAAE;AAA7B,GAAP;AACD;;AALD,OAAA,CAAA,uBAAA,GAAA,uBAAA","sourcesContent":["import { shorthands } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport type { GriffelStyle } from '@griffel/react';\n\n/**\n * Options parameter for the createArrowStyles function\n */\nexport type CreateArrowStylesOptions = {\n /**\n * The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.\n *\n * This can be undefined to leave out the arrow size styles. You must then add styles created by\n * createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.\n */\n arrowHeight: number | undefined;\n\n /**\n * The borderWidth of the arrow. Should be the same borderWidth as the parent element.\n *\n * @defaultvalue 1px\n */\n borderWidth?: GriffelStyle['borderBottomWidth'];\n\n /**\n * The borderStyle for the arrow. Should be the same borderStyle as the parent element.\n *\n * @defaultvalue solid\n */\n borderStyle?: GriffelStyle['borderBottomStyle'];\n\n /**\n * The borderColor of the arrow. Should be the same borderColor as the parent element.\n *\n * @defaultvalue tokens.colorTransparentStroke\n */\n borderColor?: GriffelStyle['borderBottomColor'];\n};\n\n/**\n * Helper that creates a makeStyles rule for an arrow element.\n * For runtime arrow size toggling simply create extra classnames to apply to the arrow element\n *\n * ```ts\n * makeStyles({\n * arrowWithSize: createArrowStyles({ arrowHeight: 6 }),\n *\n * arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),\n * mediumArrow: createArrowHeightStyles(4),\n * smallArrow: createArrowHeightStyles(2),\n * })\n * ...\n *\n * state.arrowWithSize.className = styles.arrowWithSize;\n * state.arrowWithoutSize.className = mergeClasses(\n * styles.arrowWithoutSize,\n * state.smallArrow && styles.smallArrow,\n * state.mediumArrow && styles.mediumArrow,\n * )\n * ```\n */\nexport function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle {\n const {\n arrowHeight,\n borderWidth = '1px',\n borderStyle = 'solid',\n borderColor = tokens.colorTransparentStroke,\n } = options;\n\n return {\n position: 'absolute',\n backgroundColor: 'inherit',\n visibility: 'hidden',\n zIndex: -1,\n\n ...(arrowHeight && createArrowHeightStyles(arrowHeight)),\n\n ':before': {\n content: '\"\"',\n visibility: 'visible',\n position: 'absolute',\n boxSizing: 'border-box',\n width: 'inherit',\n height: 'inherit',\n backgroundColor: 'inherit',\n ...shorthands.borderRight(\n `${borderWidth} /* @noflip */`,\n `${borderStyle} /* @noflip */`,\n `${borderColor} /* @noflip */`,\n ),\n ...shorthands.borderBottom(borderWidth, borderStyle, borderColor),\n borderBottomRightRadius: tokens.borderRadiusSmall,\n transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)',\n },\n\n // Popper sets data-popper-placement on the root element, which is used to align the arrow\n ':global([data-popper-placement^=\"top\"])': {\n bottom: `-${borderWidth}`,\n '--angle': '0',\n },\n ':global([data-popper-placement^=\"right\"])': {\n left: `-${borderWidth} /* @noflip */`,\n '--angle': '90deg',\n },\n ':global([data-popper-placement^=\"bottom\"])': {\n top: `-${borderWidth}`,\n '--angle': '180deg',\n },\n ':global([data-popper-placement^=\"left\"])': {\n right: `-${borderWidth} /* @noflip */`,\n '--angle': '270deg',\n },\n };\n}\n\n/**\n * Creates CSS styles to size the arrow created by createArrowStyles to the given height.\n *\n * Use this when you need to create classes for several different arrow sizes. If you only need a\n * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.\n */\nexport function createArrowHeightStyles(arrowHeight: number) {\n // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.\n // Multiply the triangle's height by sqrt(2) to get length of its edges.\n const edgeLength = `${1.414 * arrowHeight}px`;\n return { width: edgeLength, height: edgeLength };\n}\n"],"sourceRoot":"../src/"}
@@ -1,28 +1,35 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.createVirtualElementFromClick = void 0;
4
7
  /**
5
8
  * Creates a virtual element based on the position of a click event
6
9
  * Can be used as a target for popper in scenarios such as context menus
7
10
  */
11
+
8
12
  function createVirtualElementFromClick(nativeEvent) {
9
- const left = nativeEvent.clientX;
10
- const top = nativeEvent.clientY;
11
- const right = left + 1;
12
- const bottom = top + 1;
13
- function getBoundingClientRect() {
14
- return {
15
- left,
16
- top,
17
- right,
18
- bottom,
19
- height: 1,
20
- width: 1,
21
- };
22
- }
13
+ const left = nativeEvent.clientX;
14
+ const top = nativeEvent.clientY;
15
+ const right = left + 1;
16
+ const bottom = top + 1;
17
+
18
+ function getBoundingClientRect() {
23
19
  return {
24
- getBoundingClientRect,
20
+ left,
21
+ top,
22
+ right,
23
+ bottom,
24
+ height: 1,
25
+ width: 1
25
26
  };
27
+ }
28
+
29
+ return {
30
+ getBoundingClientRect
31
+ };
26
32
  }
33
+
27
34
  exports.createVirtualElementFromClick = createVirtualElementFromClick;
28
35
  //# sourceMappingURL=createVirtualElementFromClick.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createVirtualElementFromClick.js","sourceRoot":"","sources":["../src/createVirtualElementFromClick.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,SAAgB,6BAA6B,CAAC,WAAuB;IACnE,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC;IACjC,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;IACvB,MAAM,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC;IAEvB,SAAS,qBAAqB;QAC5B,OAAO;YACL,IAAI;YACJ,GAAG;YACH,KAAK;YACL,MAAM;YAEN,MAAM,EAAE,CAAC;YACT,KAAK,EAAE,CAAC;SACT,CAAC;IACJ,CAAC;IAED,OAAO;QACL,qBAAqB;KACtB,CAAC;AACJ,CAAC;AArBD,sEAqBC"}
1
+ {"version":3,"sources":["createVirtualElementFromClick.ts"],"names":[],"mappings":";;;;;;AAEA;;;AAGG;;AACH,SAAgB,6BAAhB,CAA8C,WAA9C,EAAqE;AACnE,QAAM,IAAI,GAAG,WAAW,CAAC,OAAzB;AACA,QAAM,GAAG,GAAG,WAAW,CAAC,OAAxB;AACA,QAAM,KAAK,GAAG,IAAI,GAAG,CAArB;AACA,QAAM,MAAM,GAAG,GAAG,GAAG,CAArB;;AAEA,WAAS,qBAAT,GAA8B;AAC5B,WAAO;AACL,MAAA,IADK;AAEL,MAAA,GAFK;AAGL,MAAA,KAHK;AAIL,MAAA,MAJK;AAML,MAAA,MAAM,EAAE,CANH;AAOL,MAAA,KAAK,EAAE;AAPF,KAAP;AASD;;AAED,SAAO;AACL,IAAA;AADK,GAAP;AAGD;;AArBD,OAAA,CAAA,6BAAA,GAAA,6BAAA","sourcesContent":["import type { PopperVirtualElement } from './types';\n\n/**\n * Creates a virtual element based on the position of a click event\n * Can be used as a target for popper in scenarios such as context menus\n */\nexport function createVirtualElementFromClick(nativeEvent: MouseEvent): PopperVirtualElement {\n const left = nativeEvent.clientX;\n const top = nativeEvent.clientY;\n const right = left + 1;\n const bottom = top + 1;\n\n function getBoundingClientRect(): ClientRect {\n return {\n left,\n top,\n right,\n bottom,\n\n height: 1,\n width: 1,\n };\n }\n\n return {\n getBoundingClientRect,\n };\n}\n"],"sourceRoot":"../src/"}
@@ -1,5 +1,6 @@
1
- export * from './usePopper';
2
1
  export * from './createVirtualElementFromClick';
2
+ export * from './createArrowStyles';
3
+ export * from './usePopper';
3
4
  export * from './usePopperMouseTarget';
4
5
  export { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';
5
6
  export * from './types';
@@ -1,12 +1,34 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.mergeArrowOffset = exports.resolvePositioningShorthand = void 0;
4
- const tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./usePopper"), exports);
7
+
8
+ const tslib_1 = /*#__PURE__*/require("tslib");
9
+
6
10
  tslib_1.__exportStar(require("./createVirtualElementFromClick"), exports);
11
+
12
+ tslib_1.__exportStar(require("./createArrowStyles"), exports);
13
+
14
+ tslib_1.__exportStar(require("./usePopper"), exports);
15
+
7
16
  tslib_1.__exportStar(require("./usePopperMouseTarget"), exports);
8
- var index_1 = require("./utils/index");
9
- Object.defineProperty(exports, "resolvePositioningShorthand", { enumerable: true, get: function () { return index_1.resolvePositioningShorthand; } });
10
- Object.defineProperty(exports, "mergeArrowOffset", { enumerable: true, get: function () { return index_1.mergeArrowOffset; } });
17
+
18
+ var index_1 = /*#__PURE__*/require("./utils/index");
19
+
20
+ Object.defineProperty(exports, "resolvePositioningShorthand", {
21
+ enumerable: true,
22
+ get: function () {
23
+ return index_1.resolvePositioningShorthand;
24
+ }
25
+ });
26
+ Object.defineProperty(exports, "mergeArrowOffset", {
27
+ enumerable: true,
28
+ get: function () {
29
+ return index_1.mergeArrowOffset;
30
+ }
31
+ });
32
+
11
33
  tslib_1.__exportStar(require("./types"), exports);
12
34
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,sDAA4B;AAC5B,0EAAgD;AAChD,iEAAuC;AACvC,uCAA8E;AAArE,oHAAA,2BAA2B,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AACtD,kDAAwB"}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iCAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,6BAAA,EAAA;AAAA,EAAA,UAAA,EAAA,IAAA;AAAA,EAAA,GAAA,EAAA,YAAA;AAAA,WAAA,OAAA,CAAA,2BAAA;AAA2B;AAA3B,CAAA;AAA6B,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,kBAAA,EAAA;AAAA,EAAA,UAAA,EAAA,IAAA;AAAA,EAAA,GAAA,EAAA,YAAA;AAAA,WAAA,OAAA,CAAA,gBAAA;AAAgB;AAAhB,CAAA;;AACtC,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './createVirtualElementFromClick';\nexport * from './createArrowStyles';\nexport * from './usePopper';\nexport * from './usePopperMouseTarget';\nexport { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';\nexport * from './types';\n"],"sourceRoot":"../src/"}