dispersa 0.2.0 → 0.3.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/README.md +44 -18
- package/dist/builders.cjs +119 -12
- package/dist/builders.cjs.map +1 -1
- package/dist/builders.d.cts +5 -5
- package/dist/builders.d.ts +5 -5
- package/dist/builders.js +119 -12
- package/dist/builders.js.map +1 -1
- package/dist/filters.cjs.map +1 -1
- package/dist/filters.d.cts +13 -16
- package/dist/filters.d.ts +13 -16
- package/dist/filters.js.map +1 -1
- package/dist/{index-CePv_bgv.d.cts → index-BkvV7Z54.d.cts} +4 -4
- package/dist/{index-BP52gB00.d.ts → index-DJ_UHSQG.d.ts} +4 -4
- package/dist/index.cjs +119 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +119 -12
- package/dist/index.js.map +1 -1
- package/dist/preprocessors.d.cts +2 -2
- package/dist/preprocessors.d.ts +2 -2
- package/dist/renderers.d.cts +6 -6
- package/dist/renderers.d.ts +6 -6
- package/dist/transforms.d.cts +2 -2
- package/dist/transforms.d.ts +2 -2
- package/dist/{types-DM5faYUn.d.cts → types-BAv39mum.d.cts} +1 -1
- package/dist/{types-C1GpiJ6q.d.ts → types-Bc0kA7De.d.cts} +10 -10
- package/dist/{types-C1GpiJ6q.d.cts → types-Bc0kA7De.d.ts} +10 -10
- package/dist/{types-Cl-1UYGD.d.ts → types-BzNcG-rI.d.ts} +1 -1
- package/dist/{types-DJH6_4U9.d.ts → types-CZb19kiq.d.ts} +1 -1
- package/dist/{types-DbufGPrb.d.cts → types-CussyWwe.d.cts} +1 -1
- package/dist/{types-DdPWYkgh.d.ts → types-CzHa7YkW.d.ts} +1 -1
- package/dist/{types-BDY1xBmD.d.cts → types-DWKq-eJj.d.cts} +1 -1
- package/package.json +1 -1
package/dist/builders.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { M as ModifierInputs, L as LifecycleHooks, C as CssRendererOptions, O as OutputConfig, T as TailwindRendererOptions, I as IosRendererOptions, A as AndroidRendererOptions } from './index-
|
|
2
|
-
import { F as Filter } from './types-
|
|
3
|
-
import { T as Transform } from './types-
|
|
4
|
-
import { a as JsonRendererOptions, J as JsModuleRendererOptions } from './types-
|
|
5
|
-
import './types-
|
|
1
|
+
import { M as ModifierInputs, L as LifecycleHooks, C as CssRendererOptions, O as OutputConfig, T as TailwindRendererOptions, I as IosRendererOptions, A as AndroidRendererOptions } from './index-BkvV7Z54.cjs';
|
|
2
|
+
import { F as Filter } from './types-DWKq-eJj.cjs';
|
|
3
|
+
import { T as Transform } from './types-BAv39mum.cjs';
|
|
4
|
+
import { a as JsonRendererOptions, J as JsModuleRendererOptions } from './types-CussyWwe.cjs';
|
|
5
|
+
import './types-Bc0kA7De.cjs';
|
|
6
6
|
import 'json-schema-to-ts';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/builders.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { M as ModifierInputs, L as LifecycleHooks, C as CssRendererOptions, O as OutputConfig, T as TailwindRendererOptions, I as IosRendererOptions, A as AndroidRendererOptions } from './index-
|
|
2
|
-
import { F as Filter } from './types-
|
|
3
|
-
import { T as Transform } from './types-
|
|
4
|
-
import { a as JsonRendererOptions, J as JsModuleRendererOptions } from './types-
|
|
5
|
-
import './types-
|
|
1
|
+
import { M as ModifierInputs, L as LifecycleHooks, C as CssRendererOptions, O as OutputConfig, T as TailwindRendererOptions, I as IosRendererOptions, A as AndroidRendererOptions } from './index-DJ_UHSQG.js';
|
|
2
|
+
import { F as Filter } from './types-BzNcG-rI.js';
|
|
3
|
+
import { T as Transform } from './types-CzHa7YkW.js';
|
|
4
|
+
import { a as JsonRendererOptions, J as JsModuleRendererOptions } from './types-CZb19kiq.js';
|
|
5
|
+
import './types-Bc0kA7De.js';
|
|
6
6
|
import 'json-schema-to-ts';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/builders.js
CHANGED
|
@@ -204,32 +204,55 @@ function filterTokensBySource(tokens, expectedSource) {
|
|
|
204
204
|
}
|
|
205
205
|
return filtered;
|
|
206
206
|
}
|
|
207
|
-
function
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
function filterTokensFromSets(tokens) {
|
|
208
|
+
const filtered = {};
|
|
209
|
+
for (const [name, token] of Object.entries(tokens)) {
|
|
210
|
+
const hasModifierSource = typeof token._sourceModifier === "string" && token._sourceModifier !== "";
|
|
211
|
+
if (!hasModifierSource) {
|
|
212
|
+
filtered[name] = token;
|
|
213
|
+
}
|
|
211
214
|
}
|
|
212
|
-
|
|
213
|
-
|
|
215
|
+
return filtered;
|
|
216
|
+
}
|
|
217
|
+
function resolveBaseFileName(fileName, defaults) {
|
|
218
|
+
if (typeof fileName === "function") {
|
|
219
|
+
return fileName({ ...defaults, _base: "true" });
|
|
220
|
+
}
|
|
221
|
+
if (/\{.+?\}/.test(fileName)) {
|
|
222
|
+
const baseInputs = Object.fromEntries(Object.keys(defaults).map((k) => [k, "base"]));
|
|
223
|
+
return collapseBaseSegments(interpolatePattern(fileName, baseInputs));
|
|
224
|
+
}
|
|
225
|
+
const extMatch = fileName.match(/(\.[^.]+)$/);
|
|
226
|
+
const extension = extMatch ? extMatch[1] : "";
|
|
227
|
+
const baseName = extension ? fileName.slice(0, -extension.length) : fileName;
|
|
228
|
+
return `${baseName}-base${extension}`;
|
|
229
|
+
}
|
|
230
|
+
function collapseBaseSegments(value) {
|
|
231
|
+
let result = value;
|
|
232
|
+
let previous = "";
|
|
233
|
+
while (result !== previous) {
|
|
234
|
+
previous = result;
|
|
235
|
+
result = result.replace(/\bbase([/-])base\b/, "base");
|
|
214
236
|
}
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
function interpolatePattern(pattern, modifierInputs) {
|
|
240
|
+
let result = pattern;
|
|
215
241
|
for (const [key, value] of Object.entries(modifierInputs)) {
|
|
216
242
|
result = result.replaceAll(`{${key}}`, value);
|
|
217
243
|
}
|
|
218
244
|
return result;
|
|
219
245
|
}
|
|
220
|
-
function resolveFileName(fileName, modifierInputs
|
|
246
|
+
function resolveFileName(fileName, modifierInputs) {
|
|
221
247
|
if (typeof fileName === "function") {
|
|
222
248
|
return fileName(modifierInputs);
|
|
223
249
|
}
|
|
224
250
|
if (/\{.+?\}/.test(fileName)) {
|
|
225
|
-
return interpolatePattern(fileName, modifierInputs
|
|
251
|
+
return interpolatePattern(fileName, modifierInputs);
|
|
226
252
|
}
|
|
227
253
|
const extMatch = fileName.match(/(\.[^.]+)$/);
|
|
228
254
|
const extension = extMatch ? extMatch[1] : "";
|
|
229
255
|
const baseName = extension ? fileName.slice(0, -extension.length) : fileName;
|
|
230
|
-
if (modifierName !== void 0 && context !== void 0) {
|
|
231
|
-
return `${baseName}-${modifierName}-${context}${extension}`;
|
|
232
|
-
}
|
|
233
256
|
const modifierSuffix = Object.entries(modifierInputs).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)).map(([key, value]) => `${key}-${value}`).join("-");
|
|
234
257
|
if (modifierSuffix) {
|
|
235
258
|
return `${baseName}-${modifierSuffix}${extension}`;
|
|
@@ -1344,6 +1367,33 @@ function collectRemainder(tokens, included) {
|
|
|
1344
1367
|
}
|
|
1345
1368
|
return result;
|
|
1346
1369
|
}
|
|
1370
|
+
function buildSetLayerBlocks(tokens, resolver) {
|
|
1371
|
+
const blocks = [];
|
|
1372
|
+
const included = /* @__PURE__ */ new Set();
|
|
1373
|
+
const addBlock = (key, blockTokens, description) => {
|
|
1374
|
+
if (Object.keys(blockTokens).length === 0) {
|
|
1375
|
+
return;
|
|
1376
|
+
}
|
|
1377
|
+
for (const k of Object.keys(blockTokens)) {
|
|
1378
|
+
included.add(k);
|
|
1379
|
+
}
|
|
1380
|
+
blocks.push({ key, description, tokens: blockTokens });
|
|
1381
|
+
};
|
|
1382
|
+
for (const item of resolver.resolutionOrder) {
|
|
1383
|
+
const ref = item.$ref;
|
|
1384
|
+
if (typeof ref !== "string" || !ref.startsWith("#/sets/")) {
|
|
1385
|
+
continue;
|
|
1386
|
+
}
|
|
1387
|
+
const setName = ref.slice("#/sets/".length);
|
|
1388
|
+
addBlock(
|
|
1389
|
+
`Set: ${setName}`,
|
|
1390
|
+
collectSetTokens(tokens, setName, included),
|
|
1391
|
+
resolver.sets?.[setName]?.description
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
addBlock("Unattributed", collectRemainder(tokens, included));
|
|
1395
|
+
return blocks;
|
|
1396
|
+
}
|
|
1347
1397
|
function buildDefaultLayerBlocks(tokens, baseModifierInputs, resolver) {
|
|
1348
1398
|
const blocks = [];
|
|
1349
1399
|
const included = /* @__PURE__ */ new Set();
|
|
@@ -2064,6 +2114,10 @@ var CssRenderer = class _CssRenderer {
|
|
|
2064
2114
|
throw new ConfigurationError("Modifier preset requires modifiers to be defined in resolver");
|
|
2065
2115
|
}
|
|
2066
2116
|
const files = {};
|
|
2117
|
+
const baseResult = await this.buildModifierBaseFile(context, options);
|
|
2118
|
+
if (baseResult) {
|
|
2119
|
+
files[baseResult.fileName] = baseResult.content;
|
|
2120
|
+
}
|
|
2067
2121
|
for (const [modifierName, modifierDef] of Object.entries(context.resolver.modifiers)) {
|
|
2068
2122
|
for (const contextValue of Object.keys(modifierDef.contexts)) {
|
|
2069
2123
|
const result = await this.buildModifierContextFile(
|
|
@@ -2079,6 +2133,59 @@ var CssRenderer = class _CssRenderer {
|
|
|
2079
2133
|
}
|
|
2080
2134
|
return { kind: "outputTree", files };
|
|
2081
2135
|
}
|
|
2136
|
+
async buildModifierBaseFile(context, options) {
|
|
2137
|
+
const basePermutation = context.permutations.find(
|
|
2138
|
+
({ modifierInputs }) => this.isBasePermutation(modifierInputs, context.meta.defaults)
|
|
2139
|
+
);
|
|
2140
|
+
if (!basePermutation) {
|
|
2141
|
+
return void 0;
|
|
2142
|
+
}
|
|
2143
|
+
const setTokens = filterTokensFromSets(basePermutation.tokens);
|
|
2144
|
+
if (Object.keys(setTokens).length === 0) {
|
|
2145
|
+
return void 0;
|
|
2146
|
+
}
|
|
2147
|
+
const setBlocks = buildSetLayerBlocks(setTokens, context.resolver);
|
|
2148
|
+
if (setBlocks.length === 0) {
|
|
2149
|
+
return void 0;
|
|
2150
|
+
}
|
|
2151
|
+
const modifiers = context.resolver.modifiers;
|
|
2152
|
+
const firstModifierName = Object.keys(modifiers)[0] ?? "";
|
|
2153
|
+
const firstModifierContext = context.meta.defaults[firstModifierName] ?? "";
|
|
2154
|
+
const baseModifierInputs = { ...context.meta.defaults };
|
|
2155
|
+
const selector = resolveSelector(
|
|
2156
|
+
options.selector,
|
|
2157
|
+
firstModifierName,
|
|
2158
|
+
firstModifierContext,
|
|
2159
|
+
true,
|
|
2160
|
+
baseModifierInputs
|
|
2161
|
+
);
|
|
2162
|
+
const mediaQuery = resolveMediaQuery(
|
|
2163
|
+
options.mediaQuery,
|
|
2164
|
+
firstModifierName,
|
|
2165
|
+
firstModifierContext,
|
|
2166
|
+
true,
|
|
2167
|
+
baseModifierInputs
|
|
2168
|
+
);
|
|
2169
|
+
const referenceTokens = basePermutation.tokens;
|
|
2170
|
+
const cssBlocks = [];
|
|
2171
|
+
for (const block of setBlocks) {
|
|
2172
|
+
const cleanTokens = stripInternalMetadata(block.tokens);
|
|
2173
|
+
const css2 = await this.formatTokens(cleanTokens, {
|
|
2174
|
+
selector,
|
|
2175
|
+
mediaQuery,
|
|
2176
|
+
minify: options.minify ?? false,
|
|
2177
|
+
preserveReferences: options.preserveReferences ?? false,
|
|
2178
|
+
referenceTokens
|
|
2179
|
+
});
|
|
2180
|
+
const header = block.description ? `/* ${block.key} */
|
|
2181
|
+
/* ${block.description} */` : `/* ${block.key} */`;
|
|
2182
|
+
cssBlocks.push(`${header}
|
|
2183
|
+
${css2}`);
|
|
2184
|
+
}
|
|
2185
|
+
const content = cssBlocks.join("\n");
|
|
2186
|
+
const fileName = context.output.file ? resolveBaseFileName(context.output.file, context.meta.defaults) : `${context.output.name}-base.css`;
|
|
2187
|
+
return { fileName, content };
|
|
2188
|
+
}
|
|
2082
2189
|
collectTokensForModifierContext(modifierName, contextValue, permutations) {
|
|
2083
2190
|
const expectedSource = `${modifierName}-${contextValue}`;
|
|
2084
2191
|
let tokensFromSource = {};
|
|
@@ -2125,7 +2232,7 @@ var CssRenderer = class _CssRenderer {
|
|
|
2125
2232
|
preserveReferences: options.preserveReferences ?? false,
|
|
2126
2233
|
referenceTokens
|
|
2127
2234
|
});
|
|
2128
|
-
const fileName = context.output.file ? resolveFileName(context.output.file, modifierInputs
|
|
2235
|
+
const fileName = context.output.file ? resolveFileName(context.output.file, modifierInputs) : buildInMemoryOutputKey({
|
|
2129
2236
|
outputName: context.output.name,
|
|
2130
2237
|
extension: "css",
|
|
2131
2238
|
modifierInputs,
|