Skip to content

Commit

Permalink
add options
Browse files Browse the repository at this point in the history
  • Loading branch information
riknoll committed Oct 22, 2024
1 parent 3df1407 commit dabdc53
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions pxtblocks/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
// all options default to true
interface CheckVisibilityOptions {
contentVisibilityAuto?: boolean;
opacityProperty?: boolean;
visibilityProperty?: boolean;
checkOpacity?: boolean;
checkVisibilityCSS?: boolean;
}

export function applyPolyfills() {
if (!(Element.prototype as any).checkVisibility) {
(Element.prototype as any).checkVisibility = function checkVisibility(this: Element): boolean {
(Element.prototype as any).checkVisibility = function checkVisibility(this: Element, options: CheckVisibilityOptions = {}): boolean {
let checkOpacity = true;

if (options.opacityProperty != undefined || options.checkOpacity != undefined) {
checkOpacity = !!(options.opacityProperty || options.checkOpacity);
}

let checkVisibility = true;

if (options.visibilityProperty != undefined || options.checkVisibilityCSS != undefined) {
checkVisibility = !!(options.visibilityProperty || options.checkVisibilityCSS);
}

let checkContentVisibility = true;

if (options.contentVisibilityAuto != undefined) {
checkContentVisibility = !!options.contentVisibilityAuto;
}

Check failure on line 30 in pxtblocks/polyfills.ts

View workflow job for this annotation

GitHub Actions / buildpush

Trailing spaces not allowed

Check failure on line 30 in pxtblocks/polyfills.ts

View workflow job for this annotation

GitHub Actions / buildpr

Trailing spaces not allowed
const computedStyle = getComputedStyle(this);

// technically, this should also check for contentVisibility === "auto" and then
// traverse the ancestors of this node to see if any have contentVisibility set
// to "hidden", but Blockly doesn't use content-visibility AFAIK
if (
computedStyle.opacity === "0" ||
computedStyle.visibility === "hidden" ||
computedStyle.display === "none" ||
(computedStyle as any).contentVisibility === "hidden"
(checkOpacity && computedStyle.opacity === "0") ||
(checkVisibility && computedStyle.visibility === "hidden") ||
(checkContentVisibility && (computedStyle as any).contentVisibility === "hidden")
) {
return false;
}
Expand Down

0 comments on commit dabdc53

Please sign in to comment.