@wordpress/grid 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -14
- package/build/dashboard-grid/grid-item.cjs +232 -295
- package/build/dashboard-grid/grid-item.cjs.map +1 -7
- package/build/dashboard-grid/index.cjs +525 -632
- package/build/dashboard-grid/index.cjs.map +1 -7
- package/build/dashboard-grid/resolve-fill-widths.cjs +159 -203
- package/build/dashboard-grid/resolve-fill-widths.cjs.map +1 -7
- package/build/dashboard-grid/types.cjs +4 -18
- package/build/dashboard-lanes/index.cjs +494 -576
- package/build/dashboard-lanes/index.cjs.map +1 -7
- package/build/dashboard-lanes/lane-placement.cjs +77 -100
- package/build/dashboard-lanes/lane-placement.cjs.map +1 -7
- package/build/dashboard-lanes/lanes-item.cjs +222 -278
- package/build/dashboard-lanes/lanes-item.cjs.map +1 -7
- package/build/dashboard-lanes/types.cjs +4 -18
- package/build/dashboard-lanes/use-lane-placement.cjs +172 -198
- package/build/dashboard-lanes/use-lane-placement.cjs.map +1 -7
- package/build/index.cjs +16 -31
- package/build/shared/array-move-with-pinned.cjs +29 -45
- package/build/shared/array-move-with-pinned.cjs.map +1 -7
- package/build/shared/column-policy.cjs +58 -0
- package/build/shared/column-policy.cjs.map +1 -0
- package/build/shared/drag-overlay-drop-animation.cjs +40 -66
- package/build/shared/drag-overlay-drop-animation.cjs.map +1 -7
- package/build/shared/grid-item-key.cjs +12 -29
- package/build/shared/grid-item-key.cjs.map +1 -7
- package/build/shared/grid-overlay.cjs +163 -164
- package/build/shared/grid-overlay.cjs.map +1 -7
- package/build/shared/item-exit-overlay.cjs +132 -134
- package/build/shared/item-exit-overlay.cjs.map +1 -7
- package/build/shared/resize-handle.cjs +213 -197
- package/build/shared/resize-handle.cjs.map +1 -7
- package/build/shared/resize-snap.cjs +116 -121
- package/build/shared/resize-snap.cjs.map +1 -7
- package/build/shared/types.cjs +4 -18
- package/build/shared/use-item-exit-animation.cjs +96 -143
- package/build/shared/use-item-exit-animation.cjs.map +1 -7
- package/build/shared/use-layout-shift-animation.cjs +121 -150
- package/build/shared/use-layout-shift-animation.cjs.map +1 -7
- package/build/shared/use-span-bounds.cjs +65 -79
- package/build/shared/use-span-bounds.cjs.map +1 -7
- package/build-module/dashboard-grid/grid-item.mjs +209 -265
- package/build-module/dashboard-grid/grid-item.mjs.map +1 -7
- package/build-module/dashboard-grid/index.mjs +502 -623
- package/build-module/dashboard-grid/index.mjs.map +1 -7
- package/build-module/dashboard-grid/resolve-fill-widths.mjs +155 -179
- package/build-module/dashboard-grid/resolve-fill-widths.mjs.map +1 -7
- package/build-module/dashboard-grid/types.mjs +0 -1
- package/build-module/dashboard-lanes/index.mjs +470 -567
- package/build-module/dashboard-lanes/index.mjs.map +1 -7
- package/build-module/dashboard-lanes/lane-placement.mjs +73 -76
- package/build-module/dashboard-lanes/lane-placement.mjs.map +1 -7
- package/build-module/dashboard-lanes/lanes-item.mjs +199 -248
- package/build-module/dashboard-lanes/lanes-item.mjs.map +1 -7
- package/build-module/dashboard-lanes/types.mjs +0 -1
- package/build-module/dashboard-lanes/use-lane-placement.mjs +167 -173
- package/build-module/dashboard-lanes/use-lane-placement.mjs.map +1 -7
- package/build-module/index.mjs +1 -6
- package/build-module/shared/array-move-with-pinned.mjs +25 -21
- package/build-module/shared/array-move-with-pinned.mjs.map +1 -7
- package/build-module/shared/column-policy.mjs +52 -0
- package/build-module/shared/column-policy.mjs.map +1 -0
- package/build-module/shared/drag-overlay-drop-animation.mjs +35 -44
- package/build-module/shared/drag-overlay-drop-animation.mjs.map +1 -7
- package/build-module/shared/grid-item-key.mjs +8 -5
- package/build-module/shared/grid-item-key.mjs.map +1 -7
- package/build-module/shared/grid-overlay.mjs +143 -136
- package/build-module/shared/grid-overlay.mjs.map +1 -7
- package/build-module/shared/item-exit-overlay.mjs +128 -110
- package/build-module/shared/item-exit-overlay.mjs.map +1 -7
- package/build-module/shared/resize-handle.mjs +191 -171
- package/build-module/shared/resize-handle.mjs.map +1 -7
- package/build-module/shared/resize-snap.mjs +108 -93
- package/build-module/shared/resize-snap.mjs.map +1 -7
- package/build-module/shared/types.mjs +0 -1
- package/build-module/shared/use-item-exit-animation.mjs +92 -124
- package/build-module/shared/use-item-exit-animation.mjs.map +1 -7
- package/build-module/shared/use-layout-shift-animation.mjs +114 -123
- package/build-module/shared/use-layout-shift-animation.mjs.map +1 -7
- package/build-module/shared/use-span-bounds.mjs +60 -57
- package/build-module/shared/use-span-bounds.mjs.map +1 -7
- package/build-types/dashboard-grid/index.d.ts.map +1 -1
- package/build-types/dashboard-grid/types.d.ts +9 -5
- package/build-types/dashboard-grid/types.d.ts.map +1 -1
- package/build-types/dashboard-lanes/index.d.ts.map +1 -1
- package/build-types/dashboard-lanes/types.d.ts +9 -5
- package/build-types/dashboard-lanes/types.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/shared/column-policy.d.ts +43 -0
- package/build-types/shared/column-policy.d.ts.map +1 -0
- package/package.json +11 -11
- package/src/dashboard-grid/grid-item.tsx +1 -1
- package/src/dashboard-grid/index.tsx +11 -12
- package/src/dashboard-grid/stories/index.story.tsx +129 -50
- package/src/dashboard-grid/test/item-interactions.browser.test.tsx +1 -1
- package/src/dashboard-grid/types.ts +9 -5
- package/src/dashboard-lanes/index.tsx +11 -11
- package/src/dashboard-lanes/lanes-item.tsx +1 -1
- package/src/dashboard-lanes/stories/index.story.tsx +124 -28
- package/src/dashboard-lanes/test/item-interactions.browser.test.tsx +1 -1
- package/src/dashboard-lanes/types.ts +9 -5
- package/src/index.ts +1 -0
- package/src/shared/column-policy.ts +100 -0
- package/src/shared/test/column-policy.test.ts +215 -0
- package/src/shared/test/sortable-semantics.browser.test.tsx +122 -0
- package/build/dashboard-grid/types.cjs.map +0 -7
- package/build/dashboard-lanes/types.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/shared/types.cjs.map +0 -7
- package/build-module/dashboard-grid/types.mjs.map +0 -7
- package/build-module/dashboard-lanes/types.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/shared/types.mjs.map +0 -7
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/dashboard-grid/resolve-fill-widths.ts"],
|
|
4
|
-
"sourcesContent": ["import type { DashboardGridLayoutItem } from './types';\n\n/**\n * Resolves items with `width: 'fill'` by computing how many columns they\n * should span. Simulates CSS Grid's row-sparse auto-flow placement so the\n * resolved span matches the free run that CSS Grid will actually use.\n *\n * Two paths:\n * - Fast path (no `height > 1` items): single-row column tracker, O(n).\n * Each fixed item between two fills is visited at most once by a fill's\n * look-ahead.\n * - Multi-row path (any item with `height > 1`): per-column skyline that\n * tracks shadow occupation of tall tiles. Placement scans rows in\n * row-major order, so worst-case cost depends on both columns and rows\n * scanned (rows bounded by the sum of item heights), not only on\n * `maxColumns`.\n *\n * Fill items honor per-item span bounds: the row plan reserves at least\n * the fill's minimum span (wrapping it to the next free run when the\n * current one is too narrow), and the resolved span never exceeds its\n * maximum. A `'full'` item capped below the column count places like a\n * fixed item of its capped width. Fixed-width items arrive already\n * bounded by the caller.\n *\n * @param sortedKeys - Item keys in display order.\n * @param layoutMap - Map of key to DashboardGridLayoutItem.\n * @param maxColumns - Total columns in the grid.\n * @param itemBounds - Optional per-key span bounds for fill and full items.\n * @return Map of fill item keys to their resolved column spans.\n */\nexport function resolveFillWidths(\n\tsortedKeys: string[],\n\tlayoutMap: Map< string, DashboardGridLayoutItem >,\n\tmaxColumns: number,\n\titemBounds?: ReadonlyMap< string, { minWidth: number; maxWidth: number } >\n): Map< string, number > {\n\tconst resolved = new Map< string, number >();\n\tconst n = sortedKeys.length;\n\n\t// Pre-extract items, clamp widths and heights, detect which path to take.\n\tconst items = new Array< DashboardGridLayoutItem | undefined >( n );\n\tconst kinds = new Array< 'fixed' | 'fill' | 'full' | undefined >( n );\n\tconst widths = new Array< number >( n );\n\tconst heights = new Array< number >( n );\n\tlet hasFill = false;\n\tlet hasMultiRow = false;\n\tlet totalRows = 0;\n\n\tfor ( let i = 0; i < n; i++ ) {\n\t\tconst item = layoutMap.get( sortedKeys[ i ] );\n\t\titems[ i ] = item;\n\t\tif ( ! item ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( item.width === 'fill' ) {\n\t\t\tkinds[ i ] = 'fill';\n\t\t\twidths[ i ] = 1;\n\t\t\thasFill = true;\n\t\t} else if ( item.width === 'full' ) {\n\t\t\tconst cap = Math.min(\n\t\t\t\titemBounds?.get( item.key )?.maxWidth ?? maxColumns,\n\t\t\t\tmaxColumns\n\t\t\t);\n\t\t\tkinds[ i ] = cap < maxColumns ? 'fixed' : 'full';\n\t\t\twidths[ i ] = cap;\n\t\t} else {\n\t\t\tkinds[ i ] = 'fixed';\n\t\t\twidths[ i ] =\n\t\t\t\ttypeof item.width === 'number'\n\t\t\t\t\t? Math.min( item.width, maxColumns )\n\t\t\t\t\t: 1;\n\t\t}\n\t\t// Clamp to a positive integer so `0`, fractional, or negative\n\t\t// values match the `|| 1` defaulting used in GridItem styles.\n\t\tconst h = Math.max( 1, Math.floor( item.height ?? 1 ) );\n\t\theights[ i ] = h;\n\t\tif ( h > 1 ) {\n\t\t\thasMultiRow = true;\n\t\t}\n\t\ttotalRows += h;\n\t}\n\n\tif ( ! hasFill ) {\n\t\treturn resolved;\n\t}\n\n\tif ( ! hasMultiRow ) {\n\t\tlet currentCol = 0;\n\n\t\tfor ( let i = 0; i < n; i++ ) {\n\t\t\tconst item = items[ i ];\n\t\t\tif ( ! item ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif ( kinds[ i ] === 'full' ) {\n\t\t\t\tcurrentCol = 0;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif ( kinds[ i ] === 'fill' ) {\n\t\t\t\tconst bounds = itemBounds?.get( item.key );\n\t\t\t\tconst minW = Math.min( bounds?.minWidth ?? 1, maxColumns );\n\t\t\t\tconst maxW = bounds?.maxWidth ?? maxColumns;\n\t\t\t\t// Wrap first when the row cannot host the fill's floor.\n\t\t\t\tif ( currentCol + minW > maxColumns ) {\n\t\t\t\t\tcurrentCol = 0;\n\t\t\t\t}\n\t\t\t\tlet reserved = 0;\n\t\t\t\tfor ( let j = i + 1; j < n; j++ ) {\n\t\t\t\t\tif ( kinds[ j ] !== 'fixed' ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst nextW = widths[ j ];\n\t\t\t\t\tif ( currentCol + minW + reserved + nextW <= maxColumns ) {\n\t\t\t\t\t\treserved += nextW;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst fillCols = Math.min(\n\t\t\t\t\tMath.max( minW, maxColumns - currentCol - reserved ),\n\t\t\t\t\tmaxW\n\t\t\t\t);\n\t\t\t\tresolved.set( item.key, fillCols );\n\t\t\t\tcurrentCol += fillCols;\n\t\t\t} else {\n\t\t\t\tconst w = widths[ i ];\n\t\t\t\tif ( currentCol + w > maxColumns ) {\n\t\t\t\t\tcurrentCol = 0;\n\t\t\t\t}\n\t\t\t\tcurrentCol += w;\n\t\t\t}\n\n\t\t\tif ( currentCol >= maxColumns ) {\n\t\t\t\tcurrentCol = 0;\n\t\t\t}\n\t\t}\n\n\t\treturn resolved;\n\t}\n\n\t// `rowOccupancy[ col ]` is the index of the next free row at that\n\t// column; rows below it are taken by previously placed items. This\n\t// captures the \"shadow\" of tall tiles into the rows they span.\n\tconst rowOccupancy = new Array< number >( maxColumns ).fill( 0 );\n\tlet cursorRow = 0;\n\tlet cursorCol = 0;\n\n\t// First row and column, in row-major order from the cursor, where\n\t// `w` consecutive columns are free.\n\tconst findFreeRun = ( w: number ): [ number, number ] => {\n\t\tlet r = cursorRow;\n\t\tlet c = cursorCol;\n\t\tplace: for ( ; r <= totalRows; r++ ) {\n\t\t\tc = r === cursorRow ? cursorCol : 0;\n\t\t\twhile ( c + w <= maxColumns ) {\n\t\t\t\tlet blocked = -1;\n\t\t\t\tfor ( let k = 0; k < w; k++ ) {\n\t\t\t\t\tif ( rowOccupancy[ c + k ] > r ) {\n\t\t\t\t\t\tblocked = c + k;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( blocked === -1 ) {\n\t\t\t\t\tbreak place;\n\t\t\t\t}\n\t\t\t\tc = blocked + 1;\n\t\t\t}\n\t\t}\n\t\treturn [ r, c ];\n\t};\n\n\tfor ( let i = 0; i < n; i++ ) {\n\t\tconst item = items[ i ];\n\t\tif ( ! item ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst h = heights[ i ];\n\n\t\tif ( kinds[ i ] === 'full' ) {\n\t\t\tlet r = cursorRow;\n\t\t\tfor ( let c = 0; c < maxColumns; c++ ) {\n\t\t\t\tif ( rowOccupancy[ c ] > r ) {\n\t\t\t\t\tr = rowOccupancy[ c ];\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor ( let c = 0; c < maxColumns; c++ ) {\n\t\t\t\trowOccupancy[ c ] = r + h;\n\t\t\t}\n\t\t\tcursorRow = r + h;\n\t\t\tcursorCol = 0;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( kinds[ i ] === 'fill' ) {\n\t\t\tconst bounds = itemBounds?.get( item.key );\n\t\t\tconst minW = Math.min( bounds?.minWidth ?? 1, maxColumns );\n\t\t\tconst maxW = bounds?.maxWidth ?? maxColumns;\n\t\t\tconst [ fillStartRow, fillStartCol ] = findFreeRun( minW );\n\t\t\tlet runLength = minW;\n\t\t\twhile (\n\t\t\t\tfillStartCol + runLength < maxColumns &&\n\t\t\t\trowOccupancy[ fillStartCol + runLength ] <= fillStartRow\n\t\t\t) {\n\t\t\t\trunLength++;\n\t\t\t}\n\t\t\tlet reserved = 0;\n\t\t\tfor ( let j = i + 1; j < n; j++ ) {\n\t\t\t\tif ( kinds[ j ] !== 'fixed' ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tconst nextW = widths[ j ];\n\t\t\t\tif ( minW + reserved + nextW <= runLength ) {\n\t\t\t\t\treserved += nextW;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst fillCols = Math.min(\n\t\t\t\tMath.max( minW, runLength - reserved ),\n\t\t\t\tmaxW\n\t\t\t);\n\t\t\tresolved.set( item.key, fillCols );\n\t\t\tfor ( let k = 0; k < fillCols; k++ ) {\n\t\t\t\trowOccupancy[ fillStartCol + k ] = fillStartRow + h;\n\t\t\t}\n\t\t\tcursorRow = fillStartRow;\n\t\t\tcursorCol = fillStartCol + fillCols;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst w = widths[ i ];\n\t\tconst [ r, c ] = findFreeRun( w );\n\t\tfor ( let k = 0; k < w; k++ ) {\n\t\t\trowOccupancy[ c + k ] = r + h;\n\t\t}\n\t\tcursorRow = r;\n\t\tcursorCol = c + w;\n\t}\n\n\treturn resolved;\n}\n"],
|
|
5
|
-
"mappings": ";AA8BO,SAAS,kBACf,YACA,WACA,YACA,YACwB;AACxB,QAAM,WAAW,oBAAI,IAAsB;AAC3C,QAAM,IAAI,WAAW;AAGrB,QAAM,QAAQ,IAAI,MAA8C,CAAE;AAClE,QAAM,QAAQ,IAAI,MAAgD,CAAE;AACpE,QAAM,SAAS,IAAI,MAAiB,CAAE;AACtC,QAAM,UAAU,IAAI,MAAiB,CAAE;AACvC,MAAI,UAAU;AACd,MAAI,cAAc;AAClB,MAAI,YAAY;AAEhB,WAAU,IAAI,GAAG,IAAI,GAAG,KAAM;AAC7B,UAAM,OAAO,UAAU,IAAK,WAAY,CAAE,CAAE;AAC5C,UAAO,CAAE,IAAI;AACb,QAAK,CAAE,MAAO;AACb;AAAA,IACD;AACA,QAAK,KAAK,UAAU,QAAS;AAC5B,YAAO,CAAE,IAAI;AACb,aAAQ,CAAE,IAAI;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
-
}
|
|
1
|
+
{"version":3,"file":"resolve-fill-widths.mjs","names":[],"sources":["../../src/dashboard-grid/resolve-fill-widths.ts"],"sourcesContent":["import type { DashboardGridLayoutItem } from './types';\n\n/**\n * Resolves items with `width: 'fill'` by computing how many columns they\n * should span. Simulates CSS Grid's row-sparse auto-flow placement so the\n * resolved span matches the free run that CSS Grid will actually use.\n *\n * Two paths:\n * - Fast path (no `height > 1` items): single-row column tracker, O(n).\n * Each fixed item between two fills is visited at most once by a fill's\n * look-ahead.\n * - Multi-row path (any item with `height > 1`): per-column skyline that\n * tracks shadow occupation of tall tiles. Placement scans rows in\n * row-major order, so worst-case cost depends on both columns and rows\n * scanned (rows bounded by the sum of item heights), not only on\n * `maxColumns`.\n *\n * Fill items honor per-item span bounds: the row plan reserves at least\n * the fill's minimum span (wrapping it to the next free run when the\n * current one is too narrow), and the resolved span never exceeds its\n * maximum. A `'full'` item capped below the column count places like a\n * fixed item of its capped width. Fixed-width items arrive already\n * bounded by the caller.\n *\n * @param sortedKeys - Item keys in display order.\n * @param layoutMap - Map of key to DashboardGridLayoutItem.\n * @param maxColumns - Total columns in the grid.\n * @param itemBounds - Optional per-key span bounds for fill and full items.\n * @return Map of fill item keys to their resolved column spans.\n */\nexport function resolveFillWidths(\n\tsortedKeys: string[],\n\tlayoutMap: Map< string, DashboardGridLayoutItem >,\n\tmaxColumns: number,\n\titemBounds?: ReadonlyMap< string, { minWidth: number; maxWidth: number } >\n): Map< string, number > {\n\tconst resolved = new Map< string, number >();\n\tconst n = sortedKeys.length;\n\n\t// Pre-extract items, clamp widths and heights, detect which path to take.\n\tconst items = new Array< DashboardGridLayoutItem | undefined >( n );\n\tconst kinds = new Array< 'fixed' | 'fill' | 'full' | undefined >( n );\n\tconst widths = new Array< number >( n );\n\tconst heights = new Array< number >( n );\n\tlet hasFill = false;\n\tlet hasMultiRow = false;\n\tlet totalRows = 0;\n\n\tfor ( let i = 0; i < n; i++ ) {\n\t\tconst item = layoutMap.get( sortedKeys[ i ] );\n\t\titems[ i ] = item;\n\t\tif ( ! item ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( item.width === 'fill' ) {\n\t\t\tkinds[ i ] = 'fill';\n\t\t\twidths[ i ] = 1;\n\t\t\thasFill = true;\n\t\t} else if ( item.width === 'full' ) {\n\t\t\tconst cap = Math.min(\n\t\t\t\titemBounds?.get( item.key )?.maxWidth ?? maxColumns,\n\t\t\t\tmaxColumns\n\t\t\t);\n\t\t\tkinds[ i ] = cap < maxColumns ? 'fixed' : 'full';\n\t\t\twidths[ i ] = cap;\n\t\t} else {\n\t\t\tkinds[ i ] = 'fixed';\n\t\t\twidths[ i ] =\n\t\t\t\ttypeof item.width === 'number'\n\t\t\t\t\t? Math.min( item.width, maxColumns )\n\t\t\t\t\t: 1;\n\t\t}\n\t\t// Clamp to a positive integer so `0`, fractional, or negative\n\t\t// values match the `|| 1` defaulting used in GridItem styles.\n\t\tconst h = Math.max( 1, Math.floor( item.height ?? 1 ) );\n\t\theights[ i ] = h;\n\t\tif ( h > 1 ) {\n\t\t\thasMultiRow = true;\n\t\t}\n\t\ttotalRows += h;\n\t}\n\n\tif ( ! hasFill ) {\n\t\treturn resolved;\n\t}\n\n\tif ( ! hasMultiRow ) {\n\t\tlet currentCol = 0;\n\n\t\tfor ( let i = 0; i < n; i++ ) {\n\t\t\tconst item = items[ i ];\n\t\t\tif ( ! item ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif ( kinds[ i ] === 'full' ) {\n\t\t\t\tcurrentCol = 0;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif ( kinds[ i ] === 'fill' ) {\n\t\t\t\tconst bounds = itemBounds?.get( item.key );\n\t\t\t\tconst minW = Math.min( bounds?.minWidth ?? 1, maxColumns );\n\t\t\t\tconst maxW = bounds?.maxWidth ?? maxColumns;\n\t\t\t\t// Wrap first when the row cannot host the fill's floor.\n\t\t\t\tif ( currentCol + minW > maxColumns ) {\n\t\t\t\t\tcurrentCol = 0;\n\t\t\t\t}\n\t\t\t\tlet reserved = 0;\n\t\t\t\tfor ( let j = i + 1; j < n; j++ ) {\n\t\t\t\t\tif ( kinds[ j ] !== 'fixed' ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst nextW = widths[ j ];\n\t\t\t\t\tif ( currentCol + minW + reserved + nextW <= maxColumns ) {\n\t\t\t\t\t\treserved += nextW;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst fillCols = Math.min(\n\t\t\t\t\tMath.max( minW, maxColumns - currentCol - reserved ),\n\t\t\t\t\tmaxW\n\t\t\t\t);\n\t\t\t\tresolved.set( item.key, fillCols );\n\t\t\t\tcurrentCol += fillCols;\n\t\t\t} else {\n\t\t\t\tconst w = widths[ i ];\n\t\t\t\tif ( currentCol + w > maxColumns ) {\n\t\t\t\t\tcurrentCol = 0;\n\t\t\t\t}\n\t\t\t\tcurrentCol += w;\n\t\t\t}\n\n\t\t\tif ( currentCol >= maxColumns ) {\n\t\t\t\tcurrentCol = 0;\n\t\t\t}\n\t\t}\n\n\t\treturn resolved;\n\t}\n\n\t// `rowOccupancy[ col ]` is the index of the next free row at that\n\t// column; rows below it are taken by previously placed items. This\n\t// captures the \"shadow\" of tall tiles into the rows they span.\n\tconst rowOccupancy = new Array< number >( maxColumns ).fill( 0 );\n\tlet cursorRow = 0;\n\tlet cursorCol = 0;\n\n\t// First row and column, in row-major order from the cursor, where\n\t// `w` consecutive columns are free.\n\tconst findFreeRun = ( w: number ): [ number, number ] => {\n\t\tlet r = cursorRow;\n\t\tlet c = cursorCol;\n\t\tplace: for ( ; r <= totalRows; r++ ) {\n\t\t\tc = r === cursorRow ? cursorCol : 0;\n\t\t\twhile ( c + w <= maxColumns ) {\n\t\t\t\tlet blocked = -1;\n\t\t\t\tfor ( let k = 0; k < w; k++ ) {\n\t\t\t\t\tif ( rowOccupancy[ c + k ] > r ) {\n\t\t\t\t\t\tblocked = c + k;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( blocked === -1 ) {\n\t\t\t\t\tbreak place;\n\t\t\t\t}\n\t\t\t\tc = blocked + 1;\n\t\t\t}\n\t\t}\n\t\treturn [ r, c ];\n\t};\n\n\tfor ( let i = 0; i < n; i++ ) {\n\t\tconst item = items[ i ];\n\t\tif ( ! item ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst h = heights[ i ];\n\n\t\tif ( kinds[ i ] === 'full' ) {\n\t\t\tlet r = cursorRow;\n\t\t\tfor ( let c = 0; c < maxColumns; c++ ) {\n\t\t\t\tif ( rowOccupancy[ c ] > r ) {\n\t\t\t\t\tr = rowOccupancy[ c ];\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor ( let c = 0; c < maxColumns; c++ ) {\n\t\t\t\trowOccupancy[ c ] = r + h;\n\t\t\t}\n\t\t\tcursorRow = r + h;\n\t\t\tcursorCol = 0;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( kinds[ i ] === 'fill' ) {\n\t\t\tconst bounds = itemBounds?.get( item.key );\n\t\t\tconst minW = Math.min( bounds?.minWidth ?? 1, maxColumns );\n\t\t\tconst maxW = bounds?.maxWidth ?? maxColumns;\n\t\t\tconst [ fillStartRow, fillStartCol ] = findFreeRun( minW );\n\t\t\tlet runLength = minW;\n\t\t\twhile (\n\t\t\t\tfillStartCol + runLength < maxColumns &&\n\t\t\t\trowOccupancy[ fillStartCol + runLength ] <= fillStartRow\n\t\t\t) {\n\t\t\t\trunLength++;\n\t\t\t}\n\t\t\tlet reserved = 0;\n\t\t\tfor ( let j = i + 1; j < n; j++ ) {\n\t\t\t\tif ( kinds[ j ] !== 'fixed' ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tconst nextW = widths[ j ];\n\t\t\t\tif ( minW + reserved + nextW <= runLength ) {\n\t\t\t\t\treserved += nextW;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst fillCols = Math.min(\n\t\t\t\tMath.max( minW, runLength - reserved ),\n\t\t\t\tmaxW\n\t\t\t);\n\t\t\tresolved.set( item.key, fillCols );\n\t\t\tfor ( let k = 0; k < fillCols; k++ ) {\n\t\t\t\trowOccupancy[ fillStartCol + k ] = fillStartRow + h;\n\t\t\t}\n\t\t\tcursorRow = fillStartRow;\n\t\t\tcursorCol = fillStartCol + fillCols;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst w = widths[ i ];\n\t\tconst [ r, c ] = findFreeRun( w );\n\t\tfor ( let k = 0; k < w; k++ ) {\n\t\t\trowOccupancy[ c + k ] = r + h;\n\t\t}\n\t\tcursorRow = r;\n\t\tcursorCol = c + w;\n\t}\n\n\treturn resolved;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,kBACf,YACA,WACA,YACA,YACwB;CACxB,MAAM,2BAAW,IAAI,IAAsB;CAC3C,MAAM,IAAI,WAAW;CAGrB,MAAM,QAAQ,IAAI,MAA8C,CAAE;CAClE,MAAM,QAAQ,IAAI,MAAgD,CAAE;CACpE,MAAM,SAAS,IAAI,MAAiB,CAAE;CACtC,MAAM,UAAU,IAAI,MAAiB,CAAE;CACvC,IAAI,UAAU;CACd,IAAI,cAAc;CAClB,IAAI,YAAY;CAEhB,KAAM,IAAI,IAAI,GAAG,IAAI,GAAG,KAAM;EAC7B,MAAM,OAAO,UAAU,IAAK,WAAY,EAAI;EAC5C,MAAO,KAAM;EACb,IAAK,CAAE,MACN;EAED,IAAK,KAAK,UAAU,QAAS;GAC5B,MAAO,KAAM;GACb,OAAQ,KAAM;GACd,UAAU;EACX,OAAO,IAAK,KAAK,UAAU,QAAS;GACnC,MAAM,MAAM,KAAK,IAChB,YAAY,IAAK,KAAK,GAAI,CAAC,EAAE,YAAY,YACzC,UACD;GACA,MAAO,KAAM,MAAM,aAAa,UAAU;GAC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