Skip to content

Commit

Permalink
Merge release/10.4 into cascading/10.4.0-11.0.0-rc
Browse files Browse the repository at this point in the history
  • Loading branch information
otter-cascading[bot] authored Jul 16, 2024
2 parents 0ef7bcc + c110874 commit 501f850
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/@o3r/styling/builders/style-extractor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export default createBuilder(createBuilderWithMetricsIfInstalled<StyleExtractorB
cssVarList
.forEach((item) => {
acc.variables[item.name] = item;
delete (acc.variables[item.name] as any).name;
});
return acc;
}, previousMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

@each $key, $value in $meta-theme {
$new-key: if($root-name != '', '#{$root-name}-#{$key}', $key);
$new-value: _meta-theme-to-otter($value, $new-key);
// We do not extract the metadata as (variable, value) pair
$new-value: if($key != details, _meta-theme-to-otter($value, $new-key), $value);
$ret: map.merge($ret, ($key: $new-value));
}

Expand Down
4 changes: 4 additions & 0 deletions packages/@o3r/styling/scss/theming/otter-theme/_material.scss
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
@return $meta-theme;
}

@if (map.has-key($meta-theme, value) and map.has-key($meta-theme, details)) {
@return _meta-theme-to-material(map.get($meta-theme, value), $root-name, $enable-css-var);
}

@else {
$ret: $meta-theme;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ const isStylingMessage = (message: any): message is AvailableStylingMessageConte

const getCSSRulesAppliedOnRoot = () => Array.from(document.styleSheets)
.reverse()
.reduce((acc: CSSStyleRule[], styleSheet) => acc.concat(
Array.from(styleSheet.cssRules || styleSheet.rules)
.reverse()
.filter((rule): rule is CSSStyleRule => rule instanceof CSSStyleRule && /\b:root\b/.test(rule.selectorText))
), []);
.reduce((acc: CSSStyleRule[], styleSheet) => {
let rules;
try {
rules = styleSheet.cssRules || styleSheet.rules;
} catch (err) {
console.debug(`Could not access to stylesheet ${styleSheet.href}. This might be due to network issues, please check:
- network connectivity
- CORS setup
- granted access to the stylesheet`, err);
}

return acc.concat(
Array.from(rules || [])
.reverse()
.filter((rule): rule is CSSStyleRule => rule instanceof CSSStyleRule && /\b:root\b/.test(rule.selectorText))
);
}, []);

const getCSSVariableValueInCSSStyleDeclaration = (variableName: string, style: CSSStyleDeclaration) =>
style.getPropertyValue(variableName).trim();
Expand Down Expand Up @@ -65,9 +77,10 @@ export class StylingDevtoolsMessageService implements OnDestroy {

private async sendMetadata() {
const metadata = await this.stylingDevTools.getStylingMetadata(this.options.stylingMetadataPath);
const cssRules = getCSSRulesAppliedOnRoot();
const variables = Object.values(metadata.variables).map((variable) => ({
...variable,
runtimeValue: getCSSVariableValue(`--${variable.name}`, getCSSRulesAppliedOnRoot())
runtimeValue: getCSSVariableValue(`--${variable.name}`, cssRules)
}));
this.sendMessage('getStylingVariable', { variables });
}
Expand Down

0 comments on commit 501f850

Please sign in to comment.