mirror of
https://github.com/google/blockly.git
synced 2025-12-16 06:10:12 +01:00
fix: stop using is3dSupported (#6400)
* fix: remove prefix checks from is3dSupported * fix: stop using is3dSupported * chore: mark is3dSupported deprecated * chore: fix lint
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user