1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.DecorationStyle = void 0;
|
19 | var DecorationStyle;
|
20 | (function (DecorationStyle) {
|
21 | function createStyleElement(styleId, container = document.head) {
|
22 | const style = document.createElement('style');
|
23 | style.id = styleId;
|
24 | style.type = 'text/css';
|
25 | style.media = 'screen';
|
26 | style.appendChild(document.createTextNode(''));
|
27 | container.appendChild(style);
|
28 | return style;
|
29 | }
|
30 | DecorationStyle.createStyleElement = createStyleElement;
|
31 | function createStyleSheet(styleId, container) {
|
32 | return createStyleElement(styleId, container).sheet;
|
33 | }
|
34 | DecorationStyle.createStyleSheet = createStyleSheet;
|
35 | function getRuleIndex(selector, styleSheet) {
|
36 | return Array.from(styleSheet.cssRules || styleSheet.rules).findIndex(rule => rule.type === CSSRule.STYLE_RULE && rule.selectorText === selector);
|
37 | }
|
38 | function getOrCreateStyleRule(selector, styleSheet) {
|
39 | let index = getRuleIndex(selector, styleSheet);
|
40 | if (index === -1) {
|
41 |
|
42 | index = styleSheet.insertRule(selector + '{}', 0);
|
43 | }
|
44 | const rules = styleSheet.cssRules || styleSheet.rules;
|
45 | const rule = rules[index];
|
46 | if (rule && rule.type === CSSRule.STYLE_RULE) {
|
47 | return rule;
|
48 | }
|
49 | styleSheet.deleteRule(index);
|
50 | throw new Error('This function is only for CSS style rules. Other types of CSS rules are not allowed.');
|
51 | }
|
52 | DecorationStyle.getOrCreateStyleRule = getOrCreateStyleRule;
|
53 | function deleteStyleRule(selector, styleSheet) {
|
54 | if (!styleSheet) {
|
55 | return;
|
56 | }
|
57 |
|
58 | const index = getRuleIndex(selector, styleSheet);
|
59 | if (index !== -1) {
|
60 | styleSheet.deleteRule(index);
|
61 | }
|
62 | }
|
63 | DecorationStyle.deleteStyleRule = deleteStyleRule;
|
64 | })(DecorationStyle = exports.DecorationStyle || (exports.DecorationStyle = {}));
|
65 |
|
\ | No newline at end of file |