Skip to content

Commit

Permalink
Update support Firefox compatibility (#19)
Browse files Browse the repository at this point in the history
* refactor: updated support firefox compatibility

* chore: added changelog
  • Loading branch information
oknoorap committed Aug 28, 2023
1 parent 2fe153b commit 594960f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-foxes-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@realmorg/realm": patch
---

Update refactor `styleMap` compat in firefox
11 changes: 7 additions & 4 deletions packages/realm/src/utils/cssom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const setStyleProperty = (
propValue: string
) => style.setProperty(propName, propValue);

const getStyleProperty = (style: CSSStyleDeclaration, propName: string) =>
style.getPropertyValue(propName);

const forEachCSSRules = (
sheets: CSSStyleSheet[],
callback: (rule: CSSStyleRule) => void
Expand All @@ -75,7 +78,7 @@ export const _CSSvar = (
const style = getStyle(rule);
if (!style) return varName;

const getProperty = () => style.getPropertyValue(varName);
const getProperty = () => getStyleProperty(style, varName);
if (value === undefined) return getProperty();

const setProperty = () => setStyleProperty(style, varName, `${value}`);
Expand Down Expand Up @@ -188,9 +191,9 @@ export const _setCSSProperty =
(selector: string, name: string, value: string | null) =>
forEachCSSRules($adoptedStyleSheets(self), (rule: CSSStyleRule) => {
if (selectorText(rule) !== selector) return;
// @ts-ignore rule.styleMap is detected as error when build
const styleMap = rule.styleMap;
if (styleMap.get(name) !== value) styleMap.set(name, value);
const style = rule.style;
if (getStyleProperty(style, name) !== value)
setStyleProperty(style, name, value);
});

const updateRuleProperty =
Expand Down

0 comments on commit 594960f

Please sign in to comment.