Skip to content

Conversation

GoodBoyDigital
Copy link
Member

@GoodBoyDigital GoodBoyDigital commented Mar 19, 2025

Description of change

DOM Container Support

This PR adds support for integrating DOM elements within the PixiJS scene graph, allowing HTML elements to be positioned and transformed alongside other PixiJS objects.

Features

  • New DOMContainer class for wrapping HTML elements
  • New DOMPipe for managing DOM elements in the scene
  • Proper transform support (position, scale, rotation, skew)
  • Anchor point support
  • Opacity/visibility handling
  • Automatic cleanup on destroy

Performance Considerations

  • Uses CSS transforms instead of top/left for better performance
  • Efficiently handles DOM element positioning using translate
  • Minimal DOM operations by tracking element state

Example Usage

import 'pixi.js/dom'

// Create a DOM element
const element = document.createElement('div');
element.innerHTML = 'Hello World!';

// Create a DOM container
const domContainer = new DOMContainer({ element });

// Add it to your scene
app.stage.addChild(domContainer);

// Position and transform like any other DisplayObject
domContainer.x = 100;
domContainer.y = 100;
domContainer.rotation = 0.5;
domContainer.anchor.set(0.5);

Notes

  • DOM elements are rendered in a separate layer above the canvas
  • Elements maintain proper stacking order and transforms
  • Full support for PixiJS transform hierarchy
  • Handles window resize and canvas position changes

Open questions

  • Is DOMContainer the best name?
  • @Zyie , will this PR cause issues with offscreen canvas or other things that don't have access to the dom?
  • should this be imported - or included by default?
Pre-Merge Checklist
  • Tests and/or benchmarks are included
  • Documentation is changed or added
  • Lint process passed (npm run lint)
  • Tests passed (npm run test)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR title doesn't match the required format. The title should be in this format:

chore: update Text docs
fix: text not rendering
feat: add new feature to Text
breaking: remove Text#resolution 

@GoodBoyDigital GoodBoyDigital changed the title New Feature: Dom Container feat: Dom Container Mar 19, 2025
Copy link

codesandbox-ci bot commented Mar 19, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 4ef48c1:

Sandbox Source
pixi.js-sandbox Configuration

@Zyie Zyie changed the title feat: Dom Container feat: DOMContainer Mar 20, 2025
Copy link
Member

@bigtimebuddy bigtimebuddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great just nit feedback.

Zyie and others added 2 commits March 20, 2025 16:00
Co-authored-by: Matt Karl <matt@mattkarl.com>
@Zyie Zyie added the ✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t label Mar 20, 2025
@Zyie Zyie added this pull request to the merge queue Mar 20, 2025
Merged via the queue into dev with commit 4aff90a Mar 20, 2025
5 checks passed
@Zyie Zyie deleted the feat/domcontainer branch March 20, 2025 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants