Utility Functions
WakaPAC provides built-in utility functions for data formatting, HTML sanitization, element positioning, and component communication. These are accessible via this within component methods.
Container Lookup
getContainerByPacId(pacId)
Resolves a WakaPAC container's DOM element by its data-pac-id value. Returns null with a console warning if the container is not found.
| Parameter | Type | Description |
|---|---|---|
pacId | string | The data-pac-id value to look up |
Returns Element | null | The container element, or null if not found | |
const container = wakaPAC.getContainerByPacId(targetPacId);
if (container) {
const rect = container.getBoundingClientRect();
}
Container Visibility
Static functions on wakaPAC for showing and hiding containers. Both are no-ops if the target container does not exist.
showContainer(pacId)
Makes a hidden container visible by removing its hidden attribute. Has no effect if the container is already visible.
| Parameter | Type | Description |
|---|---|---|
pacId | string | The data-pac-id of the target container |
wakaPAC.showContainer('my-panel');
hideContainer(pacId)
Hides a container by setting its hidden attribute. Has no effect if the container is already hidden.
| Parameter | Type | Description |
|---|---|---|
pacId | string | The data-pac-id of the target container |
wakaPAC.hideContainer('my-panel');
Coordinate Extraction
Static functions on wakaPAC for extracting mouse coordinates from lParam in msgProc. Coordinates are relative to the container's top-left corner.
MAKEPOINTS(lParam)
Extracts both X and Y coordinates from a packed lParam value.
| Parameter | Type | Description |
|---|---|---|
lParam | number | Packed coordinate value from event.lParam |
Returns { x, y } | Container-relative coordinates | |
const pos = wakaPAC.MAKEPOINTS(event.lParam);
console.log(pos.x, pos.y);
LOWORD(lParam)
Extracts the low 16 bits from lParam (X coordinate for mouse events).
| Parameter | Type | Description |
|---|---|---|
lParam | number | Packed coordinate value |
Returns number | X coordinate | |
const x = wakaPAC.LOWORD(event.lParam);
HIWORD(lParam)
Extracts the high 16 bits from lParam (Y coordinate for mouse events).
| Parameter | Type | Description |
|---|---|---|
lParam | number | Packed coordinate value |
Returns number | Y coordinate | |
const y = wakaPAC.HIWORD(event.lParam);
Coordinate Conversion
Instance methods called via this for converting between container-relative and viewport-absolute coordinate spaces.
containerToViewport(x, y)
Converts container-relative coordinates to viewport-absolute coordinates. Use this before passing lParam coordinates to hit-testing functions.
| Parameter | Type | Description |
|---|---|---|
x | number | Container-relative X coordinate |
y | number | Container-relative Y coordinate |
Returns { x, y } | Viewport-absolute coordinates | |
const pos = wakaPAC.MAKEPOINTS(event.lParam);
const viewport = wakaPAC.containerToViewport(pos.x, pos.y);
const element = wakaPAC.elementFromPoint(viewport.x, viewport.y);
viewportToContainer(x, y)
Converts viewport-absolute coordinates to container-relative coordinates. Use this when you have coordinates from event.originalEvent.clientX/clientY and need them in container space.
| Parameter | Type | Description |
|---|---|---|
x | number | Viewport-absolute X coordinate |
y | number | Viewport-absolute Y coordinate |
Returns { x, y } | Container-relative coordinates | |
const containerPos = wakaPAC.viewportToContainer(10, 20);
Hit Testing
Static functions on wakaPAC for determining what lies under a given screen coordinate. All coordinates are in viewport (client) space — convert container-relative coordinates with wakaPAC.containerToViewport() first.
ptInElement(x, y, element)
Tests whether a point lies within an element's bounding rectangle. Returns false if element is null.
| Parameter | Type | Description |
|---|---|---|
x | number | Viewport X coordinate |
y | number | Viewport Y coordinate |
element | Element | DOM element to test against |
Returns boolean | true if the point is within the element's bounding rectangle | |
const viewport = wakaPAC.containerToViewport(pos.x, pos.y);
const dropZone = document.getElementById('drop-target');
this.overTarget = wakaPAC.ptInElement(viewport.x, viewport.y, dropZone);
elementFromPoint(x, y)
Returns the topmost DOM element at the given viewport coordinates. Thin wrapper around document.elementFromPoint() for a consistent API.
| Parameter | Type | Description |
|---|---|---|
x | number | Viewport X coordinate |
y | number | Viewport Y coordinate |
Returns Element | null | Topmost element at the given coordinates | |
const element = wakaPAC.elementFromPoint(viewport.x, viewport.y);
if (element?.classList.contains('droppable')) { ... }
containerFromPoint(x, y)
Returns the nearest WakaPAC container element at the given viewport coordinates, or null if the point is not over any container. Internally calls elementFromPoint() and walks up the DOM with closest('[data-pac-id]').
| Parameter | Type | Description |
|---|---|---|
x | number | Viewport X coordinate |
y | number | Viewport Y coordinate |
Returns Element | null | Nearest WakaPAC container at the given coordinates, or null | |
const target = wakaPAC.containerFromPoint(viewport.x, viewport.y);
if (target && target !== this.container) {
this.dropTargetId = target.getAttribute('data-pac-id');
}
ptInElement, elementFromPoint, containerFromPoint) expect viewport coordinates, not container-relative coordinates. Convert with wakaPAC.containerToViewport() before passing lParam coordinates to these functions.