@navita/engine 0.1.3 → 0.2.1

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 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.getUsedCacheIds(filePaths ?? Object.keys(this.usedIds));
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
- getUsedCacheIds(filePaths = []) {
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
@@ -1,4 +1,26 @@
1
- import { StyleRule, FontFaceRule, CSSKeyframes } from '@navita/types';
1
+ import { CSSKeyframes, FontFaceRule, StyleRule } from '@navita/types';
2
+
3
+ interface StyleBlock {
4
+ type: 'rule' | 'static';
5
+ selector: string;
6
+ property: string;
7
+ value: string;
8
+ pseudo: string;
9
+ media: string;
10
+ support: string;
11
+ container: string;
12
+ id: string | number;
13
+ }
14
+ interface KeyframesBlock {
15
+ type: 'keyframes';
16
+ rule: CSSKeyframes;
17
+ id: string;
18
+ }
19
+ interface FontFaceBlock {
20
+ type: 'fontFace';
21
+ rule: FontFaceRule[];
22
+ id: string;
23
+ }
2
24
 
3
25
  declare class ClassList extends String {
4
26
  }
@@ -10,6 +32,10 @@ type CacheKeys = keyof Engine["caches"];
10
32
  type UsedIdCache = {
11
33
  [key in CacheKeys]?: (string | number)[];
12
34
  };
35
+ interface Identifier {
36
+ value: string;
37
+ id: string;
38
+ }
13
39
  type Options = {
14
40
  context?: string;
15
41
  enableSourceMaps?: boolean;
@@ -46,9 +72,27 @@ declare class Engine {
46
72
  serialize(): string;
47
73
  deserialize(buffer: Buffer | string): Promise<void>;
48
74
  setFilePath(filePath: string | undefined): void;
75
+ getUsedFilePaths(): string[];
76
+ getItems(caches: UsedIdCache): {
77
+ rule?: (StyleBlock & {
78
+ id: string | number;
79
+ })[];
80
+ static?: (StyleBlock & {
81
+ id: string | number;
82
+ })[];
83
+ keyframes?: (KeyframesBlock & {
84
+ id: string | number;
85
+ })[];
86
+ fontFace?: (FontFaceBlock & {
87
+ id: string | number;
88
+ })[];
89
+ identifiers?: (Identifier & {
90
+ id: string | number;
91
+ })[];
92
+ };
49
93
  clearUsedIds(filePath: string): void;
50
94
  private addUsedIds;
51
- getUsedCacheIds(filePaths?: string[]): UsedIdCache;
95
+ getCacheIds(filePaths?: string[]): UsedIdCache;
52
96
  }
53
97
 
54
98
  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.getUsedCacheIds(filePaths ?? Object.keys(this.usedIds));
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
- getUsedCacheIds(filePaths = []) {
220
+ getCacheIds(filePaths = []) {
211
221
  return filePaths.reduce((acc, filePath)=>({
212
222
  ...acc,
213
223
  ...Object.keys(this.usedIds[filePath] || []).reduce((cache, key)=>({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navita/engine",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "description": "Navitas CSS-in-JS engine",
5
5
  "keywords": [
6
6
  "css-in-js",