@brightspace-ui/core 3.234.0 → 3.234.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -217,6 +217,10 @@ function formatCSSVariable([key, value]) {
217
217
  else return `${key}: ${value};`;
218
218
  }
219
219
 
220
+ function isCustomPropertyDefined(rule, name) {
221
+ return rule.style.getPropertyValue(name).trim() !== '';
222
+ }
223
+
220
224
  function resolvePrimitive(variableName, variables) {
221
225
  const value = variables.get(variableName);
222
226
  if (!value) return;
@@ -232,7 +236,7 @@ function replaceSemanticVariables(value, semanticVariables) {
232
236
  });
233
237
  }
234
238
 
235
- let style;
239
+ let style, lightRule, darkRule, osRule;
236
240
  if (globalThis.document !== undefined && !globalThis.document.head.querySelector('#d2l-colors')) {
237
241
  style = globalThis.document.createElement('style');
238
242
  style.id = 'd2l-colors';
@@ -248,9 +252,7 @@ if (globalThis.document !== undefined && !globalThis.document.head.querySelector
248
252
  /* primary accent */
249
253
  --d2l-color-primary-accent-action: var(--d2l-color-celestine);
250
254
  --d2l-color-primary-accent-indicator: var(--d2l-color-carnelian);
251
- }
252
255
 
253
- html {
254
256
  ${lightCSS}
255
257
  }
256
258
  html[data-color-mode="dark"] {
@@ -268,19 +270,24 @@ if (globalThis.document !== undefined && !globalThis.document.head.querySelector
268
270
  }
269
271
  `;
270
272
  globalThis.document.head.appendChild(style);
273
+
274
+ lightRule = style.sheet.cssRules[0];
275
+ darkRule = style.sheet.cssRules[1];
276
+ osRule = style.sheet.cssRules[2].cssRules[0];
271
277
  }
272
278
 
273
279
  export function registerSemanticVariableForSvgImageUrl(name, value) {
274
280
  if (!name || typeof value !== 'string') {
275
281
  throw new TypeError('registerSemanticVariableForSvgImageUrl requires both a name and value');
276
282
  }
283
+ if (isCustomPropertyDefined(lightRule, name)) {
284
+ console.warn(`registerSemanticVariableForSvgImageUrl called for ${name} but a custom property is already defined with this name`);
285
+ }
277
286
 
278
287
  const replacedLightValue = svgToCSS(replaceSemanticVariables(value, lightVariables));
279
- style.sheet.insertRule(`html { ${ name }: ${ replacedLightValue } }`, 0);
288
+ lightRule.style.setProperty(name, replacedLightValue);
280
289
 
281
290
  const replacedDarkValue = svgToCSS(replaceSemanticVariables(value, darkVariables));
282
- style.sheet.insertRule(`html[data-color-mode="dark"] { ${ name }: ${ replacedDarkValue } }`, 1);
283
- style.sheet.insertRule(`@media (prefers-color-scheme: dark) {
284
- html[data-color-mode="os"] { ${ name }: ${ replacedDarkValue } }
285
- }`, 2);
291
+ darkRule.style.setProperty(name, replacedDarkValue);
292
+ osRule.style.setProperty(name, replacedDarkValue);
286
293
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.234.0",
3
+ "version": "3.234.2",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",