(
/** @description The DOM node which will serve as the root for this tree. */
target: HTMLElement | HTMLCanvasElement,
/** @description Options to configure the tree. */
options: CreateRootOptions = {},
)
| 15 | |
| 16 | /** Creates a new root for a Pixi React app. */ |
| 17 | export function createRoot( |
| 18 | /** @description The DOM node which will serve as the root for this tree. */ |
| 19 | target: HTMLElement | HTMLCanvasElement, |
| 20 | |
| 21 | /** @description Options to configure the tree. */ |
| 22 | options: CreateRootOptions = {}, |
| 23 | ) |
| 24 | { |
| 25 | // Check against mistaken use of createRoot |
| 26 | let root = roots.get(target); |
| 27 | let applicationState = (root?.applicationState ?? { |
| 28 | isInitialised: false, |
| 29 | isInitialising: false, |
| 30 | }) as ApplicationState; |
| 31 | |
| 32 | const internalState = root?.internalState ?? {} as InternalState; |
| 33 | |
| 34 | if (root) |
| 35 | { |
| 36 | log('warn', 'createRoot should only be called once!'); |
| 37 | } |
| 38 | else |
| 39 | { |
| 40 | applicationState.app = new Application(); |
| 41 | internalState.rootContainer = prepareInstance(applicationState.app.stage) as HostConfig['containerInstance']; |
| 42 | } |
| 43 | |
| 44 | const fiber = root?.fiber ?? (reconciler as any).createContainer( |
| 45 | internalState.rootContainer, // container |
| 46 | ConcurrentRoot, // tag |
| 47 | null, // hydration callbacks |
| 48 | false, // isStrictMode |
| 49 | null, // concurrentUpdatesByDefaultOverride |
| 50 | '', // identifierPrefix |
| 51 | console.error, // onUncaughtError |
| 52 | console.error, // onCaughtError |
| 53 | console.error, // onRecoverableError |
| 54 | null, // transitionCallbacks |
| 55 | ); |
| 56 | |
| 57 | if (!root) |
| 58 | { |
| 59 | let canvas; |
| 60 | |
| 61 | if (target instanceof HTMLCanvasElement) |
| 62 | { |
| 63 | canvas = target; |
| 64 | } |
| 65 | |
| 66 | if (!canvas) |
| 67 | { |
| 68 | canvas = document.createElement('canvas'); |
| 69 | target.innerHTML = ''; |
| 70 | target.appendChild(canvas); |
| 71 | } |
| 72 | |
| 73 | internalState.canvas = canvas; |
| 74 |
no test coverage detected