Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop using is3dSupported #6400

Merged
merged 4 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
* Whether to move the block to the drag surface when it is dragged.
* True if it should move, false if it should be translated directly.
*/
this.useDragSurface_ =
svgMath.is3dSupported() && !!workspace.getBlockDragSurface();
this.useDragSurface_ = !!workspace.getBlockDragSurface();

const svgPath = this.pathObject.svgPath;
(svgPath as AnyDuringMigration).tooltip = this;
Expand Down
6 changes: 1 addition & 5 deletions core/bubble_dragger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {IBubble} from './interfaces/i_bubble.js';
import type {IDeleteArea} from './interfaces/i_delete_area.js';
import type {IDragTarget} from './interfaces/i_drag_target.js';
import {Coordinate} from './utils/coordinate.js';
import * as svgMath from './utils/svg_math.js';
import {WorkspaceCommentSvg} from './workspace_comment_svg.js';
import type {WorkspaceSvg} from './workspace_svg.js';

Expand Down Expand Up @@ -56,10 +55,7 @@ export class BubbleDragger {
* The drag surface to move bubbles to during a drag, or null if none should
* be used. Block dragging and bubble dragging use the same surface.
*/
this.dragSurface_ =
svgMath.is3dSupported() && !!workspace.getBlockDragSurface() ?
workspace.getBlockDragSurface() :
null;
this.dragSurface_ = workspace.getBlockDragSurface();
}

/**
Expand Down
55 changes: 4 additions & 51 deletions core/utils/svg_math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,57 +117,10 @@ export function getInjectionDivXY(element: Element): Coordinate {
* @alias Blockly.utils.svgMath.is3dSupported
*/
export function is3dSupported(): boolean {
// AnyDuringMigration because: Property 'cached_' does not exist on type '()
// => boolean'.
if ((is3dSupported as AnyDuringMigration).cached_ !== undefined) {
// AnyDuringMigration because: Property 'cached_' does not exist on type
// '() => boolean'.
return (is3dSupported as AnyDuringMigration).cached_;
}
// CC-BY-SA Lorenzo Polidori
// stackoverflow.com/questions/5661671/detecting-transform-translate3d-support
if (!globalThis['getComputedStyle']) {
return false;
}

const el = document.createElement('p');
let has3d = 'none';
const transforms = {
'webkitTransform': '-webkit-transform',
'OTransform': '-o-transform',
'msTransform': '-ms-transform',
'MozTransform': '-moz-transform',
'transform': 'transform',
};

// Add it to the body to get the computed style.
document.body.insertBefore(el, null);

for (const t in transforms) {
if ((el.style as AnyDuringMigration)[t] !== undefined) {
(el.style as AnyDuringMigration)[t] = 'translate3d(1px,1px,1px)';
const computedStyle = globalThis['getComputedStyle'](el);
if (!computedStyle) {
// getComputedStyle in Firefox returns null when Blockly is loaded
// inside an iframe with display: none. Returning false and not
// caching is3dSupported means we try again later. This is most likely
// when users are interacting with blocks which should mean Blockly is
// visible again.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=548397
document.body.removeChild(el);
return false;
}
has3d =
computedStyle.getPropertyValue((transforms as AnyDuringMigration)[t]);
}
}
document.body.removeChild(el);
// AnyDuringMigration because: Property 'cached_' does not exist on type '()
// => boolean'.
(is3dSupported as AnyDuringMigration).cached_ = has3d !== 'none';
// AnyDuringMigration because: Property 'cached_' does not exist on type '()
// => boolean'.
return (is3dSupported as AnyDuringMigration).cached_;
// All browsers support translate3d in 2022.
deprecation.warn(
'Blockly.utils.svgMath.is3dSupported', 'version 9.0.0', 'version 10.0.0');
return true;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions core/workspace_comment_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements
* Whether to move the comment to the drag surface when it is dragged.
* True if it should move, false if it should be translated directly.
*/
this.useDragSurface_ =
svgMath.is3dSupported() && !!workspace.getBlockDragSurface();
this.useDragSurface_ = !!workspace.getBlockDragSurface();

this.render();
}
Expand Down
3 changes: 1 addition & 2 deletions core/workspace_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
this.workspaceDragSurface_ = opt_wsDragSurface;
}

this.useWorkspaceDragSurface_ =
!!this.workspaceDragSurface_ && svgMath.is3dSupported();
this.useWorkspaceDragSurface_ = !!this.workspaceDragSurface_;

/**
* Object in charge of loading, storing, and playing audio for a workspace.
Expand Down