Skip to content

Commit

Permalink
fix(core): CanvasContext node fixes (#2259)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Sep 20, 2024
1 parent 93f2e54 commit 1a5bbbd
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "9.1.0-beta.2",
"version": "9.2.0-alpha.0",
"npmClient": "yarn",
"exact": true,
"packages": [
Expand Down
2 changes: 1 addition & 1 deletion modules/constants/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luma.gl/constants",
"version": "9.1.0-beta.2",
"version": "9.2.0-alpha.0",
"description": "WebGL2 constants",
"type": "module",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion modules/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luma.gl/core",
"version": "9.1.0-beta.2",
"version": "9.2.0-alpha.0",
"description": "The luma.gl core Device API",
"license": "MIT",
"type": "module",
Expand Down
18 changes: 13 additions & 5 deletions modules/core/src/adapter/canvas-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export type CanvasContextProps = {
* @todo transferControlToOffscreen: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/transferControlToOffscreen
*/
export abstract class CanvasContext {
static isHTMLCanvas(canvas: unknown): canvas is HTMLCanvasElement {
return canvas instanceof HTMLCanvasElement;
}

static isOffscreenCanvas(canvas: unknown): canvas is OffscreenCanvas {
return typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas;
}

static defaultProps: Required<CanvasContextProps> = {
id: undefined!,
canvas: null,
Expand Down Expand Up @@ -116,11 +124,11 @@ export abstract class CanvasContext {
this.canvas = props.canvas;
}

if (this.canvas instanceof HTMLCanvasElement) {
if (CanvasContext.isHTMLCanvas(this.canvas)) {
this.id = props.id || this.canvas.id;
this.type = 'html-canvas';
this.htmlCanvas = this.canvas;
} else if (this.canvas instanceof OffscreenCanvas) {
} else if (CanvasContext.isOffscreenCanvas(this.canvas)) {
this.id = props.id || 'offscreen-canvas';
this.type = 'offscreen-canvas';
this.offscreenCanvas = this.canvas;
Expand All @@ -137,7 +145,7 @@ export abstract class CanvasContext {
this.drawingBufferHeight = this.canvas.height;
this.devicePixelRatio = globalThis.devicePixelRatio || 1;

if (this.canvas instanceof HTMLCanvasElement) {
if (CanvasContext.isHTMLCanvas(this.canvas)) {
// Track visibility changes
this._intersectionObserver = new IntersectionObserver(entries =>
this._handleIntersection(entries)
Expand Down Expand Up @@ -172,7 +180,7 @@ export abstract class CanvasContext {
* @note This is independent of the canvas' internal drawing buffer size (.width, .height).
*/
getCSSSize(): [number, number] {
if (this.canvas instanceof HTMLCanvasElement) {
if (CanvasContext.isHTMLCanvas(this.canvas)) {
return [this.canvas.clientWidth, this.canvas.clientHeight];
}
return [this.pixelWidth, this.pixelHeight];
Expand Down Expand Up @@ -219,7 +227,7 @@ export abstract class CanvasContext {
* @note This function handles the non-HTML canvas cases
*/
getDevicePixelRatio(useDevicePixels?: boolean | number): number {
if (typeof OffscreenCanvas !== 'undefined' && this.canvas instanceof OffscreenCanvas) {
if (CanvasContext.isOffscreenCanvas(this.canvas)) {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/effects/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luma.gl/effects",
"version": "9.1.0-beta.2",
"version": "9.2.0-alpha.0",
"description": "Post-processing effects for luma.gl",
"type": "module",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion modules/engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luma.gl/engine",
"version": "9.1.0-beta.2",
"version": "9.2.0-alpha.0",
"description": "3D Engine Components for luma.gl",
"type": "module",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion modules/gltf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luma.gl/gltf",
"version": "9.1.0-beta.2",
"version": "9.2.0-alpha.0",
"description": "glTF support for luma.gl",
"type": "module",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion modules/shadertools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luma.gl/shadertools",
"version": "9.1.0-beta.2",
"version": "9.2.0-alpha.0",
"description": "Shader module system for luma.gl",
"type": "module",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion modules/test-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luma.gl/test-utils",
"version": "9.1.0-beta.2",
"version": "9.2.0-alpha.0",
"description": "Automated WebGL testing utilities with Puppeteer and image diffing",
"type": "module",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions modules/webgl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luma.gl/webgl",
"version": "9.1.0-beta.2",
"version": "9.2.0-alpha.0",
"description": "WebGL2 adapter for the luma.gl core API",
"type": "module",
"license": "MIT",
Expand Down Expand Up @@ -43,7 +43,7 @@
"@luma.gl/core": "9.2.0-alpha.0"
},
"dependencies": {
"@luma.gl/constants": "9.1.0-beta.2",
"@luma.gl/constants": "^9.2.0-alpha.0",
"@math.gl/types": "^4.1.0",
"@probe.gl/env": "^4.0.8"
},
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -986,19 +986,19 @@ __metadata:
languageName: node
linkType: hard

"@luma.gl/constants@npm:9.1.0-beta.2, @luma.gl/constants@workspace:modules/constants":
version: 0.0.0-use.local
resolution: "@luma.gl/constants@workspace:modules/constants"
languageName: unknown
linkType: soft

"@luma.gl/constants@npm:^9.0.0":
version: 9.0.25
resolution: "@luma.gl/constants@npm:9.0.25"
checksum: 10c0/8715ba786e1a0b94e1650fa90a2121029587756cb6eb7a9bf3c65f8ecd9d25a54473a209e715bdf0dda707e0faa8607fafcc959321d98f0261e17349e0daf59e
languageName: node
linkType: hard

"@luma.gl/constants@npm:^9.2.0-alpha.0, @luma.gl/constants@workspace:modules/constants":
version: 0.0.0-use.local
resolution: "@luma.gl/constants@workspace:modules/constants"
languageName: unknown
linkType: soft

"@luma.gl/core@workspace:modules/core":
version: 0.0.0-use.local
resolution: "@luma.gl/core@workspace:modules/core"
Expand Down Expand Up @@ -1082,7 +1082,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@luma.gl/webgl@workspace:modules/webgl"
dependencies:
"@luma.gl/constants": "npm:9.1.0-beta.2"
"@luma.gl/constants": "npm:^9.2.0-alpha.0"
"@math.gl/types": "npm:^4.1.0"
"@probe.gl/env": "npm:^4.0.8"
peerDependencies:
Expand Down

0 comments on commit 1a5bbbd

Please sign in to comment.