1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 |
|
---|
8 | var _path = _interopRequireDefault(require("path"));
|
---|
9 |
|
---|
10 | var _utils = require("./utils");
|
---|
11 |
|
---|
12 | var _options = _interopRequireDefault(require("./options.json"));
|
---|
13 |
|
---|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
15 |
|
---|
16 | const loaderAPI = () => {};
|
---|
17 |
|
---|
18 | loaderAPI.pitch = function loader(request) {
|
---|
19 | const options = this.getOptions(_options.default);
|
---|
20 | const injectType = options.injectType || "styleTag";
|
---|
21 | const esModule = typeof options.esModule !== "undefined" ? options.esModule : true;
|
---|
22 | const runtimeOptions = {};
|
---|
23 |
|
---|
24 | if (options.attributes) {
|
---|
25 | runtimeOptions.attributes = options.attributes;
|
---|
26 | }
|
---|
27 |
|
---|
28 | if (options.base) {
|
---|
29 | runtimeOptions.base = options.base;
|
---|
30 | }
|
---|
31 |
|
---|
32 | const insertType = typeof options.insert === "function" ? "function" : options.insert && _path.default.isAbsolute(options.insert) ? "module-path" : "selector";
|
---|
33 | const styleTagTransformType = typeof options.styleTagTransform === "function" ? "function" : options.styleTagTransform && _path.default.isAbsolute(options.styleTagTransform) ? "module-path" : "default";
|
---|
34 |
|
---|
35 | switch (injectType) {
|
---|
36 | case "linkTag":
|
---|
37 | {
|
---|
38 | const hmrCode = this.hot ? (0, _utils.getLinkHmrCode)(esModule, this, request) : "";
|
---|
39 | return `
|
---|
40 | ${(0, _utils.getImportLinkAPICode)(esModule, this)}
|
---|
41 | ${(0, _utils.getImportInsertBySelectorCode)(esModule, this, insertType, options)}
|
---|
42 | ${(0, _utils.getImportLinkContentCode)(esModule, this, request)}
|
---|
43 | ${esModule ? "" : `content = content.__esModule ? content.default : content;`}
|
---|
44 |
|
---|
45 | var options = ${JSON.stringify(runtimeOptions)};
|
---|
46 |
|
---|
47 | ${(0, _utils.getInsertOptionCode)(insertType, options)}
|
---|
48 |
|
---|
49 | var update = API(content, options);
|
---|
50 |
|
---|
51 | ${hmrCode}
|
---|
52 |
|
---|
53 | ${esModule ? "export default {}" : ""}`;
|
---|
54 | }
|
---|
55 |
|
---|
56 | case "lazyStyleTag":
|
---|
57 | case "lazyAutoStyleTag":
|
---|
58 | case "lazySingletonStyleTag":
|
---|
59 | {
|
---|
60 | const isSingleton = injectType === "lazySingletonStyleTag";
|
---|
61 | const isAuto = injectType === "lazyAutoStyleTag";
|
---|
62 | const hmrCode = this.hot ? (0, _utils.getStyleHmrCode)(esModule, this, request, true) : "";
|
---|
63 | return `
|
---|
64 | var exported = {};
|
---|
65 |
|
---|
66 | ${(0, _utils.getImportStyleAPICode)(esModule, this)}
|
---|
67 | ${(0, _utils.getImportStyleDomAPICode)(esModule, this, isSingleton, isAuto)}
|
---|
68 | ${(0, _utils.getImportInsertBySelectorCode)(esModule, this, insertType, options)}
|
---|
69 | ${(0, _utils.getSetAttributesCode)(esModule, this, options)}
|
---|
70 | ${(0, _utils.getImportInsertStyleElementCode)(esModule, this)}
|
---|
71 | ${(0, _utils.getStyleTagTransformFnCode)(esModule, this, options, isSingleton, styleTagTransformType)}
|
---|
72 | ${(0, _utils.getImportStyleContentCode)(esModule, this, request)}
|
---|
73 | ${isAuto ? (0, _utils.getImportIsOldIECode)(esModule, this) : ""}
|
---|
74 | ${esModule ? `if (content && content.locals) {
|
---|
75 | exported.locals = content.locals;
|
---|
76 | }
|
---|
77 | ` : `content = content.__esModule ? content.default : content;
|
---|
78 |
|
---|
79 | exported.locals = content.locals || {};`}
|
---|
80 |
|
---|
81 | var refs = 0;
|
---|
82 | var update;
|
---|
83 | var options = ${JSON.stringify(runtimeOptions)};
|
---|
84 |
|
---|
85 | ${(0, _utils.getStyleTagTransformFn)(options, isSingleton)};
|
---|
86 | options.setAttributes = setAttributes;
|
---|
87 | ${(0, _utils.getInsertOptionCode)(insertType, options)}
|
---|
88 | options.domAPI = ${(0, _utils.getdomAPI)(isAuto)};
|
---|
89 | options.insertStyleElement = insertStyleElement;
|
---|
90 |
|
---|
91 | exported.use = function() {
|
---|
92 | if (!(refs++)) {
|
---|
93 | update = API(content, options);
|
---|
94 | }
|
---|
95 |
|
---|
96 | return exported;
|
---|
97 | };
|
---|
98 | exported.unuse = function() {
|
---|
99 | if (refs > 0 && !--refs) {
|
---|
100 | update();
|
---|
101 | update = null;
|
---|
102 | }
|
---|
103 | };
|
---|
104 |
|
---|
105 | ${hmrCode}
|
---|
106 |
|
---|
107 | ${(0, _utils.getExportLazyStyleCode)(esModule, this, request)}
|
---|
108 | `;
|
---|
109 | }
|
---|
110 |
|
---|
111 | case "styleTag":
|
---|
112 | case "autoStyleTag":
|
---|
113 | case "singletonStyleTag":
|
---|
114 | default:
|
---|
115 | {
|
---|
116 | const isSingleton = injectType === "singletonStyleTag";
|
---|
117 | const isAuto = injectType === "autoStyleTag";
|
---|
118 | const hmrCode = this.hot ? (0, _utils.getStyleHmrCode)(esModule, this, request, false) : "";
|
---|
119 | return `
|
---|
120 | ${(0, _utils.getImportStyleAPICode)(esModule, this)}
|
---|
121 | ${(0, _utils.getImportStyleDomAPICode)(esModule, this, isSingleton, isAuto)}
|
---|
122 | ${(0, _utils.getImportInsertBySelectorCode)(esModule, this, insertType, options)}
|
---|
123 | ${(0, _utils.getSetAttributesCode)(esModule, this, options)}
|
---|
124 | ${(0, _utils.getImportInsertStyleElementCode)(esModule, this)}
|
---|
125 | ${(0, _utils.getStyleTagTransformFnCode)(esModule, this, options, isSingleton, styleTagTransformType)}
|
---|
126 | ${(0, _utils.getImportStyleContentCode)(esModule, this, request)}
|
---|
127 | ${isAuto ? (0, _utils.getImportIsOldIECode)(esModule, this) : ""}
|
---|
128 | ${esModule ? "" : `content = content.__esModule ? content.default : content;`}
|
---|
129 |
|
---|
130 | var options = ${JSON.stringify(runtimeOptions)};
|
---|
131 |
|
---|
132 | ${(0, _utils.getStyleTagTransformFn)(options, isSingleton)};
|
---|
133 | options.setAttributes = setAttributes;
|
---|
134 | ${(0, _utils.getInsertOptionCode)(insertType, options)}
|
---|
135 | options.domAPI = ${(0, _utils.getdomAPI)(isAuto)};
|
---|
136 | options.insertStyleElement = insertStyleElement;
|
---|
137 |
|
---|
138 | var update = API(content, options);
|
---|
139 |
|
---|
140 | ${hmrCode}
|
---|
141 |
|
---|
142 | ${(0, _utils.getExportStyleCode)(esModule, this, request)}
|
---|
143 | `;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | };
|
---|
147 |
|
---|
148 | var _default = loaderAPI;
|
---|
149 | exports.default = _default; |
---|