@fluentui/priority-overflow 0.0.0-nightly-20220519-0420.1 → 0.0.0-nightly-20220624-0419.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.json CHANGED
@@ -2,9 +2,24 @@
2
2
  "name": "@fluentui/priority-overflow",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 19 May 2022 04:30:55 GMT",
6
- "tag": "@fluentui/priority-overflow_v0.0.0-nightly-20220519-0420.1",
7
- "version": "0.0.0-nightly-20220519-0420.1",
5
+ "date": "Fri, 24 Jun 2022 04:33:29 GMT",
6
+ "tag": "@fluentui/priority-overflow_v0.0.0-nightly-20220624-0419.1",
7
+ "version": "0.0.0-nightly-20220624-0419.1",
8
+ "comments": {
9
+ "prerelease": [
10
+ {
11
+ "author": "lingfangao@hotmail.com",
12
+ "package": "@fluentui/priority-overflow",
13
+ "commit": "2da4428ae7d6e464c538b7ed10e425ce0e531144",
14
+ "comment": "chore: Mark internal APIs with @internal"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Mon, 23 May 2022 12:13:58 GMT",
21
+ "tag": "@fluentui/priority-overflow_v9.0.0-beta.1",
22
+ "version": "9.0.0-beta.1",
8
23
  "comments": {
9
24
  "prerelease": [
10
25
  {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,21 @@
1
1
  # Change Log - @fluentui/priority-overflow
2
2
 
3
- This log was last generated on Thu, 19 May 2022 04:30:55 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 24 Jun 2022 04:33:29 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly-20220519-0420.1](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v0.0.0-nightly-20220519-0420.1)
7
+ ## [0.0.0-nightly-20220624-0419.1](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v0.0.0-nightly-20220624-0419.1)
8
8
 
9
- Thu, 19 May 2022 04:30:55 GMT
9
+ Fri, 24 Jun 2022 04:33:29 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/priority-overflow_v9.0.0-beta.1..@fluentui/priority-overflow_v0.0.0-nightly-20220624-0419.1)
11
+
12
+ ### Changes
13
+
14
+ - chore: Mark internal APIs with @internal ([PR #23689](https://github.com/microsoft/fluentui/pull/23689) by lingfangao@hotmail.com)
15
+
16
+ ## [9.0.0-beta.1](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v9.0.0-beta.1)
17
+
18
+ Mon, 23 May 2022 12:13:58 GMT
10
19
 
11
20
  ### Changes
12
21
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * @internal
2
3
  * @returns overflow manager instance
3
4
  */
4
5
  export declare function createOverflowManager(): OverflowManager;
@@ -79,6 +80,9 @@ export declare interface OverflowItemEntry {
79
80
  groupId?: string;
80
81
  }
81
82
 
83
+ /**
84
+ * @internal
85
+ */
82
86
  export declare interface OverflowManager {
83
87
  /**
84
88
  * Starts observing the container and managing the overflow state
@@ -1 +1 @@
1
- {"version":3,"sources":["debounce.ts"],"names":[],"mappings":"AAAA;;;;;AAKG;AACH,OAAM,SAAU,QAAV,CAAmB,EAAnB,EAA+B;AACnC,MAAI,OAAJ;AACA,SAAO,MAAK;AACV,QAAI,CAAC,OAAL,EAAc;AACZ,MAAA,OAAO,GAAG,IAAV;AACA,MAAA,cAAc,CAAC,MAAK;AAClB;AACA;AACA,QAAA,OAAO,GAAG,KAAV;AACA,QAAA,EAAE;AACH,OALa,CAAd;AAMD;AACF,GAVD;AAWD","sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["debounce.ts"],"names":[],"mappings":"AAAA;;;;;AAKG;AACH,OAAM,SAAU,QAAV,CAAmB,EAAnB,EAA+B;EACnC,IAAI,OAAJ;EACA,OAAO,MAAK;IACV,IAAI,CAAC,OAAL,EAAc;MACZ,OAAO,GAAG,IAAV;MACA,cAAc,CAAC,MAAK;QAClB;QACA;QACA,OAAO,GAAG,KAAV;QACA,EAAE;MACH,CALa,CAAd;IAMD;EACF,CAVD;AAWD","sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"],"sourceRoot":"../src/"}
@@ -1,6 +1,7 @@
1
1
  import { debounce } from './debounce';
2
2
  import { createPriorityQueue } from './priorityQueue';
3
3
  /**
4
+ * @internal
4
5
  * @returns overflow manager instance
5
6
  */
6
7
 
@@ -1 +1 @@
1
- {"version":3,"sources":["overflowManager.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,QAAyB,YAAzB;AACA,SAAS,mBAAT,QAAoC,iBAApC;AAGA;;AAEG;;AACH,OAAM,SAAU,qBAAV,GAA+B;AACnC,MAAI,SAAJ;AACA,QAAM,OAAO,GAA6B;AACxC,IAAA,OAAO,EAAE,EAD+B;AAExC,IAAA,YAAY,EAAE,YAF0B;AAGxC,IAAA,iBAAiB,EAAE,KAHqB;AAIxC,IAAA,cAAc,EAAE,CAJwB;AAKxC,IAAA,sBAAsB,EAAE,MAAM,SALU;AAMxC,IAAA,gBAAgB,EAAE,MAAM;AANgB,GAA1C;AASA,QAAM,aAAa,GAAsC,EAAzD;AACA,QAAM,cAAc,GAAmF,EAAvG;AACA,QAAM,cAAc,G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,CAApB;AACA,IAAA,MAAM;AACP,GAZD;;AAcA,SAAO;AACL,IAAA,OADK;AAEL,IAAA,UAFK;AAGL,IAAA,WAHK;AAIL,IAAA,OAJK;AAKL,IAAA,UALK;AAML,IAAA;AANK,GAAP;AAQD","sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (availableSize: number) => {\n if (!container) {\n return;\n }\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n // Remove items until there's no more overlap\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() === options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n dispatchOverflowUpdate();\n }\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (!container) {\n return;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n processOverflowItems(availableSize);\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n overflowItems[item.id] = item;\n visibleItemQueue.enqueue(item.id);\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"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CAAC,OAAN,CAAd,CAA6B,cAA7B,CAA4C,MAA5C,CAAmD,IAAI,CAAC,EAAxD;MACA,cAAc,CAAC,IAAI,CAAC,OAAN,CAAd,CAA6B,gBAA7B,CAA8C,MAA9C,CAAqD,IAAI,CAAC,EAA1D;IACD;;IAED,OAAO,aAAa,CAAC,MAAD,CAApB;IACA,MAAM;EACP,CAZD;;EAcA,OAAO;IACL,OADK;IAEL,UAFK;IAGL,WAHK;IAIL,OAJK;IAKL,UALK;IAML;EANK,CAAP;AAQD","sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (availableSize: number) => {\n if (!container) {\n return;\n }\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n // Remove items until there's no more overlap\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() === options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n dispatchOverflowUpdate();\n }\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (!container) {\n return;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n processOverflowItems(availableSize);\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n overflowItems[item.id] = item;\n visibleItemQueue.enqueue(item.id);\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n };\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["priorityQueue.ts"],"names":[],"mappings":"AAaA;;;AAGG;AACH,OAAM,SAAU,mBAAV,CAAiC,OAAjC,EAAmE;AACvE,QAAM,GAAG,GAAQ,EAAjB;AACA,MAAI,IAAI,GAAG,CAAX;;AAEA,QAAM,IAAI,GAAI,CAAD,IAAc;AACzB,WAAO,IAAI,CAAJ,GAAQ,CAAf;AACD,GAFD;;AAIA,QAAM,KAAK,GAAI,CAAD,IAAc;AAC1B,WAAO,IAAI,CAAJ,GAAQ,CAAf;AACD,GAFD;;AAIA,QAAM,MAAM,GAAI,CAAD,IAAc;AAC3B,WAAO,IAAI,CAAC,KAAL,CAAW,CAAC,CAAC,GAAG,CAAL,IAAU,CAArB,CAAP;AACD,GAFD;;AAIA,QAAM,IAAI,GAAG,CAAC,CAAD,EAAY,CAAZ,KAAyB;AACpC,UAAM,GAAG,GAAG,GAAG,CAAC,CAAD,CAAf;AACA,IAAA,GAAG,CAAC,CAAD,CAAH,GAAS,GAAG,CAAC,CAAD,CAAZ;AACA,IAAA,GAAG,CAAC,CAAD,CAAH,GAAS,GAAT;AACD,GAJD;;AAMA,QAAM,OAAO,GAAI,CAAD,IAAc;AAC5B,QAAI,QAAQ,GAAG,CAAf;AACA,UAAM,CAAC,GAAG,IAAI,CAAC,CAAD,CAAd;AACA,UAAM,CAAC,GAAG,KAAK,CAAC,CAAD,CAAf;;AAEA,QAAI,CAAC,GAAG,IAAJ,IAAY,OAAO,CAAC,GAAG,CAAC,CAAD,CAAJ,EAAS,GAAG,CAAC,QAAD,CAAZ,CAAP,GAAiC,CAAjD,EAAoD;AAClD,MAAA,QAAQ,GAAG,CAAX;AACD;;AAED,QAAI,CAAC,GAAG,IAAJ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,CAAC,OAAJ,CAAY,IAAZ,KAAqB,CAA5B;AACD,GAFD;;AAIA,QAAM,MAAM,GAAI,IAAD,IAAY;AACzB,UAAM,CAAC,GAAG,GAAG,CAAC,OAAJ,CAAY,IAAZ,CAAV;;AAEA,QAAI,CAAC,KAAK,CAAC,CAAX,EAAc;AACZ;AACD;;AAED,IAAA,GAAG,CAAC,CAAD,CAAH,GAAS,GAAG,CAAC,EAAE,IAAH,CAAZ;AACA,IAAA,OAAO,CAAC,CAAD,CAAP;AACD,GATD;;AAWA,QAAM,KAAK,GAAG,MAAK;AACjB,IAAA,IAAI,GAAG,CAAP;AACD,GAFD;;AAIA,QAAM,GAAG,GAAG,MAAK;AACf,WAAO,GAAG,CAAC,KAAJ,CAAU,CAAV,EAAa,IAAb,CAAP;AACD,GAFD;;AAIA,SAAO;AACL,IAAA,GADK;AAEL,IAAA,KAFK;AAGL,IAAA,QAHK;AAIL,IAAA,OAJK;AAKL,IAAA,OALK;AAML,IAAA,IANK;AAOL,IAAA,MAPK;AAQL,IAAA,IAAI,EAAE,MAAM;AARP,GAAP;AAUD","sourcesContent":["export type PriorityQueueCompareFn<T> = (a: T, b: T) => number;\n\nexport interface PriorityQueue<T> {\n all: () => T[];\n clear: () => void;\n contains: (item: T) => boolean;\n dequeue: () => T;\n enqueue: (item: T) => void;\n peek: () => T | null;\n remove: (item: T) => void;\n size: () => number;\n}\n\n/**\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */\nexport function createPriorityQueue<T>(compare: PriorityQueueCompareFn<T>): PriorityQueue<T> {\n const arr: T[] = [];\n let size = 0;\n\n const left = (i: number) => {\n return 2 * i + 1;\n };\n\n const right = (i: number) => {\n return 2 * i + 2;\n };\n\n const parent = (i: number) => {\n return Math.floor((i - 1) / 2);\n };\n\n const swap = (a: number, b: number) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n\n const heapify = (i: number) => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n\n return res;\n };\n\n const peek = () => {\n if (size === 0) {\n return null;\n }\n\n return arr[0];\n };\n\n const enqueue = (item: T) => {\n arr[size++] = item;\n let i = size - 1;\n let p = parent(i);\n while (i > 0 && compare(arr[p], arr[i]) > 0) {\n swap(p, i);\n i = p;\n p = parent(i);\n }\n };\n\n const contains = (item: T) => {\n return arr.indexOf(item) >= 0;\n };\n\n const remove = (item: T) => {\n const i = arr.indexOf(item);\n\n if (i === -1) {\n return;\n }\n\n arr[i] = arr[--size];\n heapify(i);\n };\n\n const clear = () => {\n size = 0;\n };\n\n const all = () => {\n return arr.slice(0, size);\n };\n\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size,\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["priorityQueue.ts"],"names":[],"mappings":"AAaA;;;AAGG;AACH,OAAM,SAAU,mBAAV,CAAiC,OAAjC,EAAmE;EACvE,MAAM,GAAG,GAAQ,EAAjB;EACA,IAAI,IAAI,GAAG,CAAX;;EAEA,MAAM,IAAI,GAAI,CAAD,IAAc;IACzB,OAAO,IAAI,CAAJ,GAAQ,CAAf;EACD,CAFD;;EAIA,MAAM,KAAK,GAAI,CAAD,IAAc;IAC1B,OAAO,IAAI,CAAJ,GAAQ,CAAf;EACD,CAFD;;EAIA,MAAM,MAAM,GAAI,CAAD,IAAc;IAC3B,OAAO,IAAI,CAAC,KAAL,CAAW,CAAC,CAAC,GAAG,CAAL,IAAU,CAArB,CAAP;EACD,CAFD;;EAIA,MAAM,IAAI,GAAG,CAAC,CAAD,EAAY,CAAZ,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,GAAI,IAAD,IAAY;IAC1B,GAAG,CAAC,IAAI,EAAL,CAAH,GAAc,IAAd;IACA,IAAI,CAAC,GAAG,IAAI,GAAG,CAAf;IACA,IAAI,CAAC,GAAG,MAAM,CAAC,CAAD,CAAd;;IACA,OAAO,CAAC,GAAG,CAAJ,IAAS,OAAO,CAAC,GAAG,CAAC,CAAD,CAAJ,EAAS,GAAG,CAAC,CAAD,CAAZ,CAAP,GAA0B,CAA1C,EAA6C;MAC3C,IAAI,CAAC,CAAD,EAAI,CAAJ,CAAJ;MACA,CAAC,GAAG,CAAJ;MACA,CAAC,GAAG,MAAM,CAAC,CAAD,CAAV;IACD;EACF,CATD;;EAWA,MAAM,QAAQ,GAAI,IAAD,IAAY;IAC3B,OAAO,GAAG,CAAC,OAAJ,CAAY,IAAZ,KAAqB,CAA5B;EACD,CAFD;;EAIA,MAAM,MAAM,GAAI,IAAD,IAAY;IACzB,MAAM,CAAC,GAAG,GAAG,CAAC,OAAJ,CAAY,IAAZ,CAAV;;IAEA,IAAI,CAAC,KAAK,CAAC,CAAX,EAAc;MACZ;IACD;;IAED,GAAG,CAAC,CAAD,CAAH,GAAS,GAAG,CAAC,EAAE,IAAH,CAAZ;IACA,OAAO,CAAC,CAAD,CAAP;EACD,CATD;;EAWA,MAAM,KAAK,GAAG,MAAK;IACjB,IAAI,GAAG,CAAP;EACD,CAFD;;EAIA,MAAM,GAAG,GAAG,MAAK;IACf,OAAO,GAAG,CAAC,KAAJ,CAAU,CAAV,EAAa,IAAb,CAAP;EACD,CAFD;;EAIA,OAAO;IACL,GADK;IAEL,KAFK;IAGL,QAHK;IAIL,OAJK;IAKL,OALK;IAML,IANK;IAOL,MAPK;IAQL,IAAI,EAAE,MAAM;EARP,CAAP;AAUD","sourcesContent":["export type PriorityQueueCompareFn<T> = (a: T, b: T) => number;\n\nexport interface PriorityQueue<T> {\n all: () => T[];\n clear: () => void;\n contains: (item: T) => boolean;\n dequeue: () => T;\n enqueue: (item: T) => void;\n peek: () => T | null;\n remove: (item: T) => void;\n size: () => number;\n}\n\n/**\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */\nexport function createPriorityQueue<T>(compare: PriorityQueueCompareFn<T>): PriorityQueue<T> {\n const arr: T[] = [];\n let size = 0;\n\n const left = (i: number) => {\n return 2 * i + 1;\n };\n\n const right = (i: number) => {\n return 2 * i + 2;\n };\n\n const parent = (i: number) => {\n return Math.floor((i - 1) / 2);\n };\n\n const swap = (a: number, b: number) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n\n const heapify = (i: number) => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n\n return res;\n };\n\n const peek = () => {\n if (size === 0) {\n return null;\n }\n\n return arr[0];\n };\n\n const enqueue = (item: T) => {\n arr[size++] = item;\n let i = size - 1;\n let p = parent(i);\n while (i > 0 && compare(arr[p], arr[i]) > 0) {\n swap(p, i);\n i = p;\n p = parent(i);\n }\n };\n\n const contains = (item: T) => {\n return arr.indexOf(item) >= 0;\n };\n\n const remove = (item: T) => {\n const i = arr.indexOf(item);\n\n if (i === -1) {\n return;\n }\n\n arr[i] = arr[--size];\n heapify(i);\n };\n\n const clear = () => {\n size = 0;\n };\n\n const all = () => {\n return arr.slice(0, size);\n };\n\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size,\n };\n}\n"],"sourceRoot":"../src/"}
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["export type OverflowDirection = 'start' | 'end';\nexport type OverflowAxis = 'horizontal' | 'vertical';\nexport type OverflowGroupState = 'visible' | 'hidden' | 'overflow';\nexport interface OverflowItemEntry {\n /**\n * HTML element that will be disappear when overflowed\n */\n element: HTMLElement;\n /**\n * Lower priority items are invisible first when the container is overflowed\n * @default 0\n */\n priority: number;\n /**\n * Specific id, used to track visibility and provide updates to consumers\n */\n id: string;\n\n groupId?: string;\n}\n\n/**\n * signature similar to standard event listeners, but typed to handle the custom event\n */\nexport type OnUpdateOverflow = (data: OverflowEventPayload) => void;\n\nexport type OnUpdateItemVisibility = (data: OnUpdateItemVisibilityPayload) => void;\n\n/**\n * Payload of the custom DOM event for overflow updates\n */\nexport interface OverflowEventPayload {\n visibleItems: OverflowItemEntry[];\n invisibleItems: OverflowItemEntry[];\n groupVisibility: Record<string, OverflowGroupState>;\n}\n\nexport interface OnUpdateItemVisibilityPayload {\n item: OverflowItemEntry;\n visible: boolean;\n}\n\nexport interface ObserveOptions {\n /**\n * Padding (in px) at the end of the container before overflow occurs\n * Useful to account for extra elements (i.e. dropdown menu)\n * or to account for any kinds of margins between items which are hard to measure with JS\n * @default 10\n */\n padding?: number;\n /**\n * Direction where items are removed when overflow occurs\n * @default end\n */\n overflowDirection?: OverflowDirection;\n\n /**\n * Horizontal or vertical overflow\n * @default horizontal\n */\n overflowAxis?: OverflowAxis;\n\n /**\n * The minimum number of visible items\n */\n minimumVisible?: number;\n\n /**\n * Callback when item visibility is updated\n */\n onUpdateItemVisibility: OnUpdateItemVisibility;\n\n /**\n * Callback when item visibility is updated\n */\n onUpdateOverflow: OnUpdateOverflow;\n}\n\nexport interface OverflowManager {\n /**\n * Starts observing the container and managing the overflow state\n */\n observe: (container: HTMLElement, options: ObserveOptions) => void;\n /**\n * Stops observing the container\n */\n disconnect: () => void;\n /**\n * Add overflow items\n */\n addItem: (items: OverflowItemEntry) => void;\n /**\n * Remove overflow item\n */\n removeItem: (itemId: string) => void;\n /**\n * Manually update the overflow, updates are batched and async\n */\n update: () => void;\n /**\n * Manually update the overflow sync\n */\n forceUpdate: () => void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["export type OverflowDirection = 'start' | 'end';\nexport type OverflowAxis = 'horizontal' | 'vertical';\nexport type OverflowGroupState = 'visible' | 'hidden' | 'overflow';\nexport interface OverflowItemEntry {\n /**\n * HTML element that will be disappear when overflowed\n */\n element: HTMLElement;\n /**\n * Lower priority items are invisible first when the container is overflowed\n * @default 0\n */\n priority: number;\n /**\n * Specific id, used to track visibility and provide updates to consumers\n */\n id: string;\n\n groupId?: string;\n}\n\n/**\n * signature similar to standard event listeners, but typed to handle the custom event\n */\nexport type OnUpdateOverflow = (data: OverflowEventPayload) => void;\n\nexport type OnUpdateItemVisibility = (data: OnUpdateItemVisibilityPayload) => void;\n\n/**\n * Payload of the custom DOM event for overflow updates\n */\nexport interface OverflowEventPayload {\n visibleItems: OverflowItemEntry[];\n invisibleItems: OverflowItemEntry[];\n groupVisibility: Record<string, OverflowGroupState>;\n}\n\nexport interface OnUpdateItemVisibilityPayload {\n item: OverflowItemEntry;\n visible: boolean;\n}\n\nexport interface ObserveOptions {\n /**\n * Padding (in px) at the end of the container before overflow occurs\n * Useful to account for extra elements (i.e. dropdown menu)\n * or to account for any kinds of margins between items which are hard to measure with JS\n * @default 10\n */\n padding?: number;\n /**\n * Direction where items are removed when overflow occurs\n * @default end\n */\n overflowDirection?: OverflowDirection;\n\n /**\n * Horizontal or vertical overflow\n * @default horizontal\n */\n overflowAxis?: OverflowAxis;\n\n /**\n * The minimum number of visible items\n */\n minimumVisible?: number;\n\n /**\n * Callback when item visibility is updated\n */\n onUpdateItemVisibility: OnUpdateItemVisibility;\n\n /**\n * Callback when item visibility is updated\n */\n onUpdateOverflow: OnUpdateOverflow;\n}\n\n/**\n * @internal\n */\nexport interface OverflowManager {\n /**\n * Starts observing the container and managing the overflow state\n */\n observe: (container: HTMLElement, options: ObserveOptions) => void;\n /**\n * Stops observing the container\n */\n disconnect: () => void;\n /**\n * Add overflow items\n */\n addItem: (items: OverflowItemEntry) => void;\n /**\n * Remove overflow item\n */\n removeItem: (itemId: string) => void;\n /**\n * Manually update the overflow, updates are batched and async\n */\n update: () => void;\n /**\n * Manually update the overflow sync\n */\n forceUpdate: () => void;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["debounce.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;AAKG;;AACH,SAAgB,QAAhB,CAAyB,EAAzB,EAAqC;AACnC,MAAI,OAAJ;AACA,SAAO,MAAK;AACV,QAAI,CAAC,OAAL,EAAc;AACZ,MAAA,OAAO,GAAG,IAAV;AACA,MAAA,cAAc,CAAC,MAAK;AAClB;AACA;AACA,QAAA,OAAO,GAAG,KAAV;AACA,QAAA,EAAE;AACH,OALa,CAAd;AAMD;AACF,GAVD;AAWD;;AAbD,OAAA,CAAA,QAAA,GAAA,QAAA","sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["debounce.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;AAKG;;AACH,SAAgB,QAAhB,CAAyB,EAAzB,EAAqC;EACnC,IAAI,OAAJ;EACA,OAAO,MAAK;IACV,IAAI,CAAC,OAAL,EAAc;MACZ,OAAO,GAAG,IAAV;MACA,cAAc,CAAC,MAAK;QAClB;QACA;QACA,OAAO,GAAG,KAAV;QACA,EAAE;MACH,CALa,CAAd;IAMD;EACF,CAVD;AAWD;;AAbD,OAAA,CAAA,QAAA,GAAA,QAAA","sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,uBAAA,EAAA;AAAA,EAAA,UAAA,EAAA,IAAA;AAAA,EAAA,GAAA,EAAA,YAAA;AAAA,WAAA,iBAAA,CAAA,qBAAA;AAAqB;AAArB,CAAA","sourcesContent":["export { createOverflowManager } from './overflowManager';\nexport type {\n ObserveOptions,\n OnUpdateItemVisibility,\n OnUpdateItemVisibilityPayload,\n OnUpdateOverflow,\n OverflowAxis,\n OverflowDirection,\n OverflowEventPayload,\n OverflowGroupState,\n OverflowItemEntry,\n OverflowManager,\n} from './types';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,uBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,iBAAA,CAAA,qBAAA;EAAqB;AAArB,CAAA","sourcesContent":["export { createOverflowManager } from './overflowManager';\nexport type {\n ObserveOptions,\n OnUpdateItemVisibility,\n OnUpdateItemVisibilityPayload,\n OnUpdateOverflow,\n OverflowAxis,\n OverflowDirection,\n OverflowEventPayload,\n OverflowGroupState,\n OverflowItemEntry,\n OverflowManager,\n} from './types';\n"],"sourceRoot":"../src/"}
@@ -9,6 +9,7 @@ const debounce_1 = /*#__PURE__*/require("./debounce");
9
9
 
10
10
  const priorityQueue_1 = /*#__PURE__*/require("./priorityQueue");
11
11
  /**
12
+ * @internal
12
13
  * @returns overflow manager instance
13
14
  */
14
15
 
@@ -1 +1 @@
1
- {"version":3,"sources":["overflowManager.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;AAGA;;AAEG;;;AACH,SAAgB,qBAAhB,GAAqC;AACnC,MAAI,SAAJ;AACA,QAAM,OAAO,GAA6B;AACxC,IAAA,OAAO,EAAE,EAD+B;AAExC,IAAA,YAAY,EAAE,YAF0B;AAGxC,IAAA,iBAAiB,EAAE,KAHqB;AAIxC,IAAA,cAAc,EAAE,CAJwB;AAKxC,IAAA,sBAAsB,EAAE,MAAM,SALU;AAMxC,IAAA,gBAAgB,EAAE,MAAM;AANgB,GAA1C;AASA,QAAM,aAAa,GAAsC,EAAzD;AACA,QAAM,cAAc,GAAmF,EAAvG;AACA,QAAM,cAAc,GAAG,IAAI,cAAJ,CAAmB,OAAO,IAAG;AAClD,QAAI,CAAC,OAAO,CAAC,CAAD,CAAR,IAAe,CAAC,SAApB,EAA+B;AAC7B;AACD;;AAED,IAAA,MAAM;AACP,GANsB,CAAvB;AAQA,QAAM,kBAAkB,GAAG,eAAA,CAAA,mBAAA,CAA4B,CAAC,CAAD,EAAI,CAAJ,KAAS;AAC9D,UAAM,KAAK,GAAG,aAAa,CAAC,CAAD,CAA3B;AACA,UAAM,KAAK,GAAG,aAAa,CAAC,CAAD,CAA3B,CAF8D,CAG9D;;AACA,UAAM,QAAQ,GAAG,KAAK,CAAC,QAAN,GAAiB,KAAK,CAAC,QAAxC;;AACA,QAAI,QAAQ,KAAK,CAAjB,EAAoB;AAClB,aAAO,QAAP;AACD;;AAED,UAAM,iBAAiB,GACrB,OAAO,CAAC,iBA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Ac,CAAC,IAAI,CAAC,OAAN,CAAd,GAA+B;AAC7B,UAAA,cAAc,EAAE,IAAI,GAAJ,EADa;AAE7B,UAAA,gBAAgB,EAAE,IAAI,GAAJ;AAFW,SAA/B;AAID;;AAED,MAAA,cAAc,CAAC,IAAI,CAAC,OAAN,CAAd,CAA6B,cAA7B,CAA4C,GAA5C,CAAgD,IAAI,CAAC,EAArD;AACD;;AAED,IAAA,MAAM;AACP,GAhBD;;AAkBA,QAAM,UAAU,GAAkC,MAAM,IAAG;AACzD,UAAM,IAAI,GAAG,aAAa,CAAC,MAAD,CAA1B;AACA,IAAA,gBAAgB,CAAC,MAAjB,CAAwB,MAAxB;AACA,IAAA,kBAAkB,CAAC,MAAnB,CAA0B,MAA1B;;AAEA,QAAI,IAAI,CAAC,OAAT,EAAkB;AAChB,MAAA,cAAc,CAAC,IAAI,CAAC,OAAN,CAAd,CAA6B,cAA7B,CAA4C,MAA5C,CAAmD,IAAI,CAAC,EAAxD;AACA,MAAA,cAAc,CAAC,IAAI,CAAC,OAAN,CAAd,CAA6B,gBAA7B,CAA8C,MAA9C,CAAqD,IAAI,CAAC,EAA1D;AACD;;AAED,WAAO,aAAa,CAAC,MAAD,CAApB;AACA,IAAA,MAAM;AACP,GAZD;;AAcA,SAAO;AACL,IAAA,OADK;AAEL,IAAA,UAFK;AAGL,IAAA,WAHK;AAIL,IAAA,OAJK;AAKL,IAAA,UALK;AAML,IAAA;AANK,GAAP;AAQD;;AA5MD,OAAA,CAAA,qBAAA,GAAA,qBAAA","sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (availableSize: number) => {\n if (!container) {\n return;\n }\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n // Remove items until there's no more overlap\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() === options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n dispatchOverflowUpdate();\n }\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (!container) {\n return;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n processOverflowItems(availableSize);\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n overflowItems[item.id] = item;\n visibleItemQueue.enqueue(item.id);\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["overflowManager.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;AAGA;;;AAGG;;;AACH,SAAgB,qBAAhB,GAAqC;EACnC,IAAI,SAAJ;EACA,MAAM,OAAO,GAA6B;IACxC,OAAO,EAAE,EAD+B;IAExC,YAAY,EAAE,YAF0B;IAGxC,iBAAiB,EAAE,KAHqB;IAIxC,cAAc,EAAE,CAJwB;IAKxC,sBAAsB,EAAE,MAAM,SALU;IAMxC,gBAAgB,EAAE,MAAM;EANgB,CAA1C;EASA,MAAM,aAAa,GAAsC,EAAzD;EACA,MAAM,cA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["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (availableSize: number) => {\n if (!container) {\n return;\n }\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n // Remove items until there's no more overlap\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() === options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n dispatchOverflowUpdate();\n }\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (!container) {\n return;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n processOverflowItems(availableSize);\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n overflowItems[item.id] = item;\n visibleItemQueue.enqueue(item.id);\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n };\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["priorityQueue.ts"],"names":[],"mappings":";;;;;;AAaA;;;AAGG;;AACH,SAAgB,mBAAhB,CAAuC,OAAvC,EAAyE;AACvE,QAAM,GAAG,GAAQ,EAAjB;AACA,MAAI,IAAI,GAAG,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A,QAAM,KAAK,GAAG,MAAK;AACjB,IAAA,IAAI,GAAG,CAAP;AACD,GAFD;;AAIA,QAAM,GAAG,GAAG,MAAK;AACf,WAAO,GAAG,CAAC,KAAJ,CAAU,CAAV,EAAa,IAAb,CAAP;AACD,GAFD;;AAIA,SAAO;AACL,IAAA,GADK;AAEL,IAAA,KAFK;AAGL,IAAA,QAHK;AAIL,IAAA,OAJK;AAKL,IAAA,OALK;AAML,IAAA,IANK;AAOL,IAAA,MAPK;AAQL,IAAA,IAAI,EAAE,MAAM;AARP,GAAP;AAUD;;AAzGD,OAAA,CAAA,mBAAA,GAAA,mBAAA","sourcesContent":["export type PriorityQueueCompareFn<T> = (a: T, b: T) => number;\n\nexport interface PriorityQueue<T> {\n all: () => T[];\n clear: () => void;\n contains: (item: T) => boolean;\n dequeue: () => T;\n enqueue: (item: T) => void;\n peek: () => T | null;\n remove: (item: T) => void;\n size: () => number;\n}\n\n/**\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */\nexport function createPriorityQueue<T>(compare: PriorityQueueCompareFn<T>): PriorityQueue<T> {\n const arr: T[] = [];\n let size = 0;\n\n const left = (i: number) => {\n return 2 * i + 1;\n };\n\n const right = (i: number) => {\n return 2 * i + 2;\n };\n\n const parent = (i: number) => {\n return Math.floor((i - 1) / 2);\n };\n\n const swap = (a: number, b: number) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n\n const heapify = (i: number) => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n\n return res;\n };\n\n const peek = () => {\n if (size === 0) {\n return null;\n }\n\n return arr[0];\n };\n\n const enqueue = (item: T) => {\n arr[size++] = item;\n let i = size - 1;\n let p = parent(i);\n while (i > 0 && compare(arr[p], arr[i]) > 0) {\n swap(p, i);\n i = p;\n p = parent(i);\n }\n };\n\n const contains = (item: T) => {\n return arr.indexOf(item) >= 0;\n };\n\n const remove = (item: T) => {\n const i = arr.indexOf(item);\n\n if (i === -1) {\n return;\n }\n\n arr[i] = arr[--size];\n heapify(i);\n };\n\n const clear = () => {\n size = 0;\n };\n\n const all = () => {\n return arr.slice(0, size);\n };\n\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size,\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["priorityQueue.ts"],"names":[],"mappings":";;;;;;AAaA;;;AAGG;;AACH,SAAgB,mBAAhB,CAAuC,OAAvC,EAAyE;EACvE,MAAM,GAAG,GAAQ,EAAjB;EACA,IAAI,IAAI,GAAG,CAAX;;EAEA,MAAM,IAAI,GAAI,CAAD,IAAc;IACzB,OAAO,IAAI,CAAJ,GAAQ,CAAf;EACD,CAFD;;EAIA,MAAM,KAAK,GAAI,CAAD,IAAc;IAC1B,OAAO,IAAI,CAAJ,GAAQ,CAAf;EACD,CAFD;;EAIA,MAAM,MAAM,GAAI,CAAD,IAAc;IAC3B,OAAO,IAAI,CAAC,KAAL,CAAW,CAAC,CAAC,GAAG,CAAL,IAAU,CAArB,CAAP;EACD,CAFD;;EAIA,MAAM,IAAI,GAAG,CAAC,CAAD,EAAY,CAAZ,KAAyB;IACpC,MAAM,GAAG,GAAG,GAAG,CAAC,CAAD,CAAf;IACA,GAAG,CAAC,CAAD,CAAH,GAAS,GAAG,CAAC,CAAD,CAAZ;IACA,GAAG,CAAC,CAAD,CAAH,GAAS,GAAT;EACD,CAJD;;EAMA,MAAM,OAAO,GAAI,CAAD,IAAc;IAC5B,IAAI,QAAQ,GAAG,CAAf;IACA,MAAM,CAAC,GAAG,IAAI,CAAC,CAAD,CAAd;I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A6C;MAC3C,IAAI,CAAC,CAAD,EAAI,CAAJ,CAAJ;MACA,CAAC,GAAG,CAAJ;MACA,CAAC,GAAG,MAAM,CAAC,CAAD,CAAV;IACD;EACF,CATD;;EAWA,MAAM,QAAQ,GAAI,IAAD,IAAY;IAC3B,OAAO,GAAG,CAAC,OAAJ,CAAY,IAAZ,KAAqB,CAA5B;EACD,CAFD;;EAIA,MAAM,MAAM,GAAI,IAAD,IAAY;IACzB,MAAM,CAAC,GAAG,GAAG,CAAC,OAAJ,CAAY,IAAZ,CAAV;;IAEA,IAAI,CAAC,KAAK,CAAC,CAAX,EAAc;MACZ;IACD;;IAED,GAAG,CAAC,CAAD,CAAH,GAAS,GAAG,CAAC,EAAE,IAAH,CAAZ;IACA,OAAO,CAAC,CAAD,CAAP;EACD,CATD;;EAWA,MAAM,KAAK,GAAG,MAAK;IACjB,IAAI,GAAG,CAAP;EACD,CAFD;;EAIA,MAAM,GAAG,GAAG,MAAK;IACf,OAAO,GAAG,CAAC,KAAJ,CAAU,CAAV,EAAa,IAAb,CAAP;EACD,CAFD;;EAIA,OAAO;IACL,GADK;IAEL,KAFK;IAGL,QAHK;IAIL,OAJK;IAKL,OALK;IAML,IANK;IAOL,MAPK;IAQL,IAAI,EAAE,MAAM;EARP,CAAP;AAUD;;AAzGD,OAAA,CAAA,mBAAA,GAAA,mBAAA","sourcesContent":["export type PriorityQueueCompareFn<T> = (a: T, b: T) => number;\n\nexport interface PriorityQueue<T> {\n all: () => T[];\n clear: () => void;\n contains: (item: T) => boolean;\n dequeue: () => T;\n enqueue: (item: T) => void;\n peek: () => T | null;\n remove: (item: T) => void;\n size: () => number;\n}\n\n/**\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */\nexport function createPriorityQueue<T>(compare: PriorityQueueCompareFn<T>): PriorityQueue<T> {\n const arr: T[] = [];\n let size = 0;\n\n const left = (i: number) => {\n return 2 * i + 1;\n };\n\n const right = (i: number) => {\n return 2 * i + 2;\n };\n\n const parent = (i: number) => {\n return Math.floor((i - 1) / 2);\n };\n\n const swap = (a: number, b: number) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n\n const heapify = (i: number) => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n\n return res;\n };\n\n const peek = () => {\n if (size === 0) {\n return null;\n }\n\n return arr[0];\n };\n\n const enqueue = (item: T) => {\n arr[size++] = item;\n let i = size - 1;\n let p = parent(i);\n while (i > 0 && compare(arr[p], arr[i]) > 0) {\n swap(p, i);\n i = p;\n p = parent(i);\n }\n };\n\n const contains = (item: T) => {\n return arr.indexOf(item) >= 0;\n };\n\n const remove = (item: T) => {\n const i = arr.indexOf(item);\n\n if (i === -1) {\n return;\n }\n\n arr[i] = arr[--size];\n heapify(i);\n };\n\n const clear = () => {\n size = 0;\n };\n\n const all = () => {\n return arr.slice(0, size);\n };\n\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size,\n };\n}\n"],"sourceRoot":"../src/"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/priority-overflow",
3
- "version": "0.0.0-nightly-20220519-0420.1",
3
+ "version": "0.0.0-nightly-20220624-0419.1",
4
4
  "description": "Vanilla JS utilities to implement overflow menus",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",