Skip to content

Conversation

Zyie
Copy link
Member

@Zyie Zyie commented Jul 18, 2025

Fixes: #11545

Ensures image creation uses the environment adapter. This change standardizes image creation across different environments (browser, web worker, node) by using the adapter pattern

Fixes: #11545

Ensures image creation uses the environment adapter. This change standardizes image creation across different environments (browser, web worker, node) by using the adapter pattern
@Zyie Zyie requested a review from bigtimebuddy July 18, 2025 14:25
@Zyie Zyie changed the title fix: use DomAdapter for new Image feat: use DomAdapter for new Image Jul 18, 2025
Copy link

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 bb039f1:

Sandbox Source
pixi.js-sandbox Configuration

@UlyssesZh
Copy link
Contributor

/**
 * Interface for HTMLImageElement.
 * @category environment
 * @advanced
 */
export interface IImage extends EventTarget
{
    /** Whether or not the image has completely loaded. */
    readonly complete: boolean;

    /** The Cross-Origin Resource Sharing (CORS) setting to use when retrieving the image. */
    crossOrigin: string | null;

    /** The URL of the image which is currently presented in the <img> element it represents. */
    readonly currentSrc: string;

    /** The width. */
    width: number;

    /** The height. */
    height: number;

    /** The address or URL of the a media resource that is to be considered. */
    src: string;

    /** Returns a Promise that resolves once the image is decoded. */
    decode(): Promise<void>;

    onload: ((this: GlobalEventHandlers, ev: Event) => any) | null;
    onerror: ((this: GlobalEventHandlers, ev: Event) => any) | null;
}

Copy link

pkg-pr-new bot commented Jul 24, 2025

pixi.js-basepixi.js-bunny-mark

npm i https://pkg.pr.new/pixijs/pixijs/pixi.js@11565

commit: 8167823

@Zyie Zyie requested a review from bigtimebuddy July 24, 2025 10:18
@Zyie
Copy link
Member Author

Zyie commented Jul 24, 2025

@UlyssesZh Thanks for providing the IImage abstraction!

@UlyssesZh
Copy link
Contributor

UlyssesZh commented Jul 24, 2025

I think some types also needs to be changed from HTMLImageElement to IImage. For example, in ICanvasRenderingContext2D.createPattern and ICanvasRenderingContext2D.drawImage, change the type of image argument to CanvasImageSource | ICanvas | IImage; in ExtractSystem.image, change the return type to Promise<IImage>. Type casting as HTMLImageElement is then unnecessary. Some documentation needs to be changed accordingly.

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.

Very helpful. The double-I bothers me, but I don't have anything better to offer for names.

One thing that might be worth considering in a follow up is disallowing except in DOMAdpater things like document.createElement or new Image with some lint rules. This is an easy thing to regress and we don't have a good tests it.

@Zyie
Copy link
Member Author

Zyie commented Jul 28, 2025

The double-I bothers me, but I don't have anything better to offer for names.

I also don't like the double-I
What about any of these?:

IWebImage
IHTMLImage
IHTMLImageElement

@bigtimebuddy
Copy link
Member

ImageLike? More like PointLike but less like ICanvas

Updates the image interface to a more generic `ImageLike`
@Zyie
Copy link
Member Author

Zyie commented Jul 29, 2025

ImageLike? More like PointLike but less like ICanvas

I like ImageLike, should we also consider deprecating ICanvas for CanvasLike?
I can do a follow up PR for that if so

@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 Jul 29, 2025
@bigtimebuddy
Copy link
Member

Yeah, good call on CanvasLike

@Zyie Zyie added this pull request to the merge queue Jul 29, 2025
Merged via the queue into dev with commit ca6420d Jul 29, 2025
7 checks passed
@Zyie Zyie deleted the feat/adapter-image branch July 29, 2025 12:25
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.

Feature Request: Use DOMAdapter.get().Image instead of globalThis.Image
3 participants