2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2022-02-01 19:48:57 +00:00
|
|
|
import Helper from '@ember/component/helper';
|
|
|
|
import { assert } from '@ember/debug';
|
|
|
|
import { adoptStyles } from '@lit/reactive-element';
|
|
|
|
|
|
|
|
export default class AdoptStylesHelper extends Helper {
|
|
|
|
/**
|
|
|
|
* Adopt/apply given styles to a `ShadowRoot` using constructable styleSheets if supported
|
|
|
|
*
|
2022-03-07 09:51:47 +00:00
|
|
|
* @param {[ShadowRoot, (CSSResultGroup | CSSResultGroup[])]} params
|
2022-02-01 19:48:57 +00:00
|
|
|
*/
|
|
|
|
compute([$shadow, styles], hash) {
|
|
|
|
assert(
|
|
|
|
'adopt-styles can only be used to apply styles to ShadowDOM elements',
|
|
|
|
$shadow instanceof ShadowRoot
|
|
|
|
);
|
2022-09-15 08:43:17 +00:00
|
|
|
if (!Array.isArray(styles)) {
|
2022-03-07 09:51:47 +00:00
|
|
|
styles = [styles];
|
|
|
|
}
|
|
|
|
adoptStyles($shadow, styles);
|
2022-02-01 19:48:57 +00:00
|
|
|
}
|
|
|
|
}
|