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.

ParameterTypeDescription
pacIdstringThe data-pac-id value to look up
Returns Element | nullThe 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.

ParameterTypeDescription
pacIdstringThe 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.

ParameterTypeDescription
pacIdstringThe 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.

ParameterTypeDescription
lParamnumberPacked 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).

ParameterTypeDescription
lParamnumberPacked coordinate value
Returns numberX coordinate
const x = wakaPAC.LOWORD(event.lParam);

HIWORD(lParam)

Extracts the high 16 bits from lParam (Y coordinate for mouse events).

ParameterTypeDescription
lParamnumberPacked coordinate value
Returns numberY 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.

ParameterTypeDescription
xnumberContainer-relative X coordinate
ynumberContainer-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.

ParameterTypeDescription
xnumberViewport-absolute X coordinate
ynumberViewport-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.

ParameterTypeDescription
xnumberViewport X coordinate
ynumberViewport Y coordinate
elementElementDOM element to test against
Returns booleantrue 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.

ParameterTypeDescription
xnumberViewport X coordinate
ynumberViewport Y coordinate
Returns Element | nullTopmost 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]').

ParameterTypeDescription
xnumberViewport X coordinate
ynumberViewport Y coordinate
Returns Element | nullNearest 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');
}
Coordinate spaces: All hit-testing functions (ptInElement, elementFromPoint, containerFromPoint) expect viewport coordinates, not container-relative coordinates. Convert with wakaPAC.containerToViewport() before passing lParam coordinates to these functions.