Copies matrix/config, merges IConfig.state, runs GameGrid.render when container is passed, then dispatches gridEventsEnum.CREATED.
Logical matrix plus optional IConfig.options / IConfig.state.
Optionalcontainer: HTMLElementWhen provided, behaves like invoking GameGrid.render synchronously afterward.
Runtime toggles: input, collisions, middleware, callbacks, styling. Merged from ctor defaults and GameGrid.setOptions.
After GameGrid.render, hydrated rows/cells and container. Headless grids mirror cells onto the logical matrix until mount.
Detach listeners when rendered and clear injected structure; resets rendered in state.
Idempotent-friendly: always dispatches gridEventsEnum.DESTROYED whether or not DOM was present.
Hydrated cell at IState.activeCoords (refs.cells[y][x]); refs must cover those indices after render.
Accumulate every ICell.type matching type scanning row-major from GameGrid.getMatrix.
Logical cell from GameGrid.getMatrix: matrix[coords[1]][coords[0]] — raw matrix lookup (bounds unchecked).
[x, y].
Logical matrix backing the grid (matrix[row][column] ⇒ matrix[y][x]).
Snapshot merged IOptions — updates after GameGrid.setOptions.
Shallow-cloned cell snapshot for IState.prevCoords: refs.cells[prevCoords[1]][prevCoords[0]] after GameGrid.render.
Dispatches gridEventsEnum.MOVE_DOWN before GameGrid.setActiveCell.
Dispatches gridEventsEnum.MOVE_LEFT before GameGrid.setActiveCell.
Dispatches gridEventsEnum.MOVE_RIGHT before GameGrid.setActiveCell.
Directional move: invokes the onMove member of IOptions.callbacks → dispatches gridEventsEnum.MOVE_UP → GameGrid.setActiveCell.
Tear down handlers, wipe container, rebuild rows/cells from GameGrid.getMatrix, reattach handlers.
Does not dispatch gridEventsEnum.RENDERED; that event is emitted from GameGrid.render.
Mount markup into container, wire keyboard/pointer handlers, activate initial cell.
Clears/rebuilds refs for this mount. Prefer GameGrid.refresh after the first paint when rebuilding from the same host. Dispatches gridEventsEnum.RENDERED once the container is patched and listeners attach.
Move focus (x,y) when IOptions.blockOnType, IOptions.collideOnType, IOptions.moveOnType, and bounds/wrap rules allow.
Optionaldirection: stringDispatch order (subset may apply): gridEventsEnum.MOVE_BLOCKED if blocked; gridEventsEnum.MOVE_COLLISION / gridEventsEnum.MOVE_DETTACH for collide enter/exit; axis gridEventsEnum.WRAP_X / gridEventsEnum.WRAP_Y / gridEventsEnum.BOUNDARY_X / gridEventsEnum.BOUNDARY_Y; aggregate gridEventsEnum.WRAP / gridEventsEnum.BOUNDARY; finally gridEventsEnum.MOVE_LAND (pairs with the onLand member of IOptions.callbacks).
Replace logical matrix reference; callers must GameGrid.refresh or GameGrid.render to reconcile DOM when mounted.
Shallow-merge behaviours into IGameGrid.options without swapping the matrix snapshot.
Apply partial state with MiddlewareFn pre (mutate patch) → merge → post.
Stateful 2‑D lattice with collision rules and optional HTMLElement projection.
Remarks
[x,y](matrix[y][x]).CustomEvents; IGameGridEventDetail describesdetail. Event names live on gridEventsEnum.Example: Render + keyboard handlers
Example: Headless state machine without calling render