UNPKG

1.4 kBJavaScriptView Raw
1"use strict";
2
3require("core-js/modules/es.array.concat");
4
5require("core-js/modules/es.array.join");
6
7require("core-js/modules/es.array.map");
8
9var _global = require("global");
10
11var _addons = _interopRequireDefault(require("@storybook/addons"));
12
13var _coreEvents = require("@storybook/core-events");
14
15var _constants = require("./constants");
16
17var _highlight = require("./highlight");
18
19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
20
21if (module && module.hot && module.hot.decline) {
22 module.hot.decline();
23}
24
25var channel = _addons["default"].getChannel();
26
27var highlight = function highlight(infos) {
28 var id = _constants.HIGHLIGHT_STYLE_ID;
29 resetHighlight();
30
31 var sheet = _global.document.createElement('style');
32
33 sheet.setAttribute('id', id);
34 sheet.innerHTML = infos.elements.map(function (target) {
35 return "".concat(target, "{ \n ").concat((0, _highlight.higlightStyle)(infos.color), "\n }");
36 }).join(' ');
37
38 _global.document.head.appendChild(sheet);
39};
40
41var resetHighlight = function resetHighlight() {
42 var id = _constants.HIGHLIGHT_STYLE_ID;
43
44 var sheetToBeRemoved = _global.document.getElementById(id);
45
46 if (sheetToBeRemoved) {
47 sheetToBeRemoved.parentNode.removeChild(sheetToBeRemoved);
48 }
49};
50
51channel.on(_coreEvents.STORY_CHANGED, resetHighlight);
52channel.on(_constants.EVENTS.HIGHLIGHT, highlight);
\No newline at end of file