@navita/engine 0.1.3 → 0.2.0
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.
- package/index.cjs +13 -3
- package/index.d.ts +3 -1
- package/index.mjs +13 -3
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -134,7 +134,7 @@ class Engine {
|
|
|
134
134
|
renderCssToString(options) {
|
|
135
135
|
const { filePaths , usedIds , opinionatedLayers =false } = options || {};
|
|
136
136
|
// We prioritize ids over filePaths. If neither are provided, we use all the used filePaths.
|
|
137
|
-
const { keyframes: keyframesCache , fontFace: fontFaceCache , static: staticCache , rule: ruleCache } = usedIds ?? this.
|
|
137
|
+
const { keyframes: keyframesCache , fontFace: fontFaceCache , static: staticCache , rule: ruleCache } = usedIds ?? this.getCacheIds(filePaths ?? Object.keys(this.usedIds));
|
|
138
138
|
const { atRules , lowPrioRules , rules } = helpers_splitStyleBlocks.splitStyleBlocks(this.caches.rule.items(ruleCache));
|
|
139
139
|
const keyFrameCss = printers_printKeyFrames.printKeyFrames(this.caches.keyframes.items(keyframesCache));
|
|
140
140
|
const fontFaceCss = printers_printFontFaces.printFontFaces(this.caches.fontFace.items(fontFaceCache));
|
|
@@ -160,7 +160,8 @@ class Engine {
|
|
|
160
160
|
return content;
|
|
161
161
|
}
|
|
162
162
|
serialize() {
|
|
163
|
-
const { caches , usedIds , identifierCount , sourceMapReferences } = this;
|
|
163
|
+
const { caches , usedIds , identifierCount , sourceMapReferences: sourceMapReferencesData } = this;
|
|
164
|
+
const sourceMapReferences = this.options.enableSourceMaps ? sourceMapReferencesData : undefined;
|
|
164
165
|
return JSON.stringify({
|
|
165
166
|
caches,
|
|
166
167
|
usedIds,
|
|
@@ -185,6 +186,15 @@ class Engine {
|
|
|
185
186
|
setFilePath(filePath) {
|
|
186
187
|
this.filePath = filePath;
|
|
187
188
|
}
|
|
189
|
+
getUsedFilePaths() {
|
|
190
|
+
return Object.keys(this.usedIds);
|
|
191
|
+
}
|
|
192
|
+
getItems(caches) {
|
|
193
|
+
return Object.keys(caches).reduce((acc, key)=>({
|
|
194
|
+
...acc,
|
|
195
|
+
[key]: this.caches[key].items(caches[key])
|
|
196
|
+
}), {});
|
|
197
|
+
}
|
|
188
198
|
clearUsedIds(filePath) {
|
|
189
199
|
if (filePath === undefined) {
|
|
190
200
|
return;
|
|
@@ -209,7 +219,7 @@ class Engine {
|
|
|
209
219
|
])
|
|
210
220
|
];
|
|
211
221
|
}
|
|
212
|
-
|
|
222
|
+
getCacheIds(filePaths = []) {
|
|
213
223
|
return filePaths.reduce((acc, filePath)=>({
|
|
214
224
|
...acc,
|
|
215
225
|
...Object.keys(this.usedIds[filePath] || []).reduce((cache, key)=>({
|
package/index.d.ts
CHANGED
|
@@ -46,9 +46,11 @@ declare class Engine {
|
|
|
46
46
|
serialize(): string;
|
|
47
47
|
deserialize(buffer: Buffer | string): Promise<void>;
|
|
48
48
|
setFilePath(filePath: string | undefined): void;
|
|
49
|
+
getUsedFilePaths(): string[];
|
|
50
|
+
getItems(caches: UsedIdCache): {};
|
|
49
51
|
clearUsedIds(filePath: string): void;
|
|
50
52
|
private addUsedIds;
|
|
51
|
-
|
|
53
|
+
getCacheIds(filePaths?: string[]): UsedIdCache;
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
export { ClassList, Engine, Options, Static, UsedIdCache };
|
package/index.mjs
CHANGED
|
@@ -132,7 +132,7 @@ class Engine {
|
|
|
132
132
|
renderCssToString(options) {
|
|
133
133
|
const { filePaths , usedIds , opinionatedLayers =false } = options || {};
|
|
134
134
|
// We prioritize ids over filePaths. If neither are provided, we use all the used filePaths.
|
|
135
|
-
const { keyframes: keyframesCache , fontFace: fontFaceCache , static: staticCache , rule: ruleCache } = usedIds ?? this.
|
|
135
|
+
const { keyframes: keyframesCache , fontFace: fontFaceCache , static: staticCache , rule: ruleCache } = usedIds ?? this.getCacheIds(filePaths ?? Object.keys(this.usedIds));
|
|
136
136
|
const { atRules , lowPrioRules , rules } = splitStyleBlocks(this.caches.rule.items(ruleCache));
|
|
137
137
|
const keyFrameCss = printKeyFrames(this.caches.keyframes.items(keyframesCache));
|
|
138
138
|
const fontFaceCss = printFontFaces(this.caches.fontFace.items(fontFaceCache));
|
|
@@ -158,7 +158,8 @@ class Engine {
|
|
|
158
158
|
return content;
|
|
159
159
|
}
|
|
160
160
|
serialize() {
|
|
161
|
-
const { caches , usedIds , identifierCount , sourceMapReferences } = this;
|
|
161
|
+
const { caches , usedIds , identifierCount , sourceMapReferences: sourceMapReferencesData } = this;
|
|
162
|
+
const sourceMapReferences = this.options.enableSourceMaps ? sourceMapReferencesData : undefined;
|
|
162
163
|
return JSON.stringify({
|
|
163
164
|
caches,
|
|
164
165
|
usedIds,
|
|
@@ -183,6 +184,15 @@ class Engine {
|
|
|
183
184
|
setFilePath(filePath) {
|
|
184
185
|
this.filePath = filePath;
|
|
185
186
|
}
|
|
187
|
+
getUsedFilePaths() {
|
|
188
|
+
return Object.keys(this.usedIds);
|
|
189
|
+
}
|
|
190
|
+
getItems(caches) {
|
|
191
|
+
return Object.keys(caches).reduce((acc, key)=>({
|
|
192
|
+
...acc,
|
|
193
|
+
[key]: this.caches[key].items(caches[key])
|
|
194
|
+
}), {});
|
|
195
|
+
}
|
|
186
196
|
clearUsedIds(filePath) {
|
|
187
197
|
if (filePath === undefined) {
|
|
188
198
|
return;
|
|
@@ -207,7 +217,7 @@ class Engine {
|
|
|
207
217
|
])
|
|
208
218
|
];
|
|
209
219
|
}
|
|
210
|
-
|
|
220
|
+
getCacheIds(filePaths = []) {
|
|
211
221
|
return filePaths.reduce((acc, filePath)=>({
|
|
212
222
|
...acc,
|
|
213
223
|
...Object.keys(this.usedIds[filePath] || []).reduce((cache, key)=>({
|