ruscus 0.0.1 → 0.0.3
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 +6 -1
- package/dist/index.mjs +45 -39
- package/dist/vite.mjs +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="./assets/logo.svg" width="
|
|
2
|
+
<img src="./assets/logo.svg" width="500" alt="Ruscus">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<br>
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
+
[](https://github.com/justinlocsei/ruscus/actions/workflows/verify.yml)
|
|
14
|
+
[](https://www.npmjs.com/package/ruscus)
|
|
15
|
+
[](https://github.com/justinlocsei/ruscus/blob/main/LICENSE)
|
|
16
|
+
|
|
17
|
+
|
|
13
18
|
<!-- <toc> -->
|
|
14
19
|
- [Installation](#installation)
|
|
15
20
|
- [Getting Started](#getting-started)
|
package/dist/index.mjs
CHANGED
|
@@ -67,49 +67,13 @@ function createVariantProjector(anchor, format, name) {
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
//#endregion
|
|
70
|
-
//#region src/styles.ts
|
|
71
|
-
/**
|
|
72
|
-
* Convert a camel-cased value to kebab case
|
|
73
|
-
*/
|
|
74
|
-
function camelToKebab(camel) {
|
|
75
|
-
return camel.replace(/[A-Z]/g, (l) => `-${l.toLowerCase()}`);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Merge multiple styles on top of a base
|
|
79
|
-
*/
|
|
80
|
-
function mergeStyles(base, ...others) {
|
|
81
|
-
const merged = { ...base };
|
|
82
|
-
for (const other of others) Object.assign(merged, other);
|
|
83
|
-
return merged;
|
|
84
|
-
}
|
|
85
|
-
var PropertyProjector = class {
|
|
86
|
-
names;
|
|
87
|
-
/**
|
|
88
|
-
* Create a mapper of camel-cased values to CSS properties
|
|
89
|
-
*/
|
|
90
|
-
constructor() {
|
|
91
|
-
this.names = /* @__PURE__ */ new Map();
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Project a camel-cased value as a CSS property
|
|
95
|
-
*/
|
|
96
|
-
project(camel) {
|
|
97
|
-
let prop = this.names.get(camel);
|
|
98
|
-
if (prop === void 0) {
|
|
99
|
-
prop = camelToKebab(camel);
|
|
100
|
-
this.names.set(camel, prop);
|
|
101
|
-
}
|
|
102
|
-
return prop;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
//#endregion
|
|
106
70
|
//#region src/projection/identifiers.ts
|
|
107
71
|
/**
|
|
108
72
|
* Project a component's identifiers as a map of labels to values
|
|
109
73
|
*/
|
|
110
74
|
function projectIdentifiers(component) {
|
|
111
75
|
return Object.fromEntries(Object.entries(component.identifiers).map(([key, type]) => {
|
|
112
|
-
const scoped = `${component.id}--${
|
|
76
|
+
const scoped = `${component.id}--${key}`;
|
|
113
77
|
return [key, type === "variable" ? `--${scoped}` : scoped];
|
|
114
78
|
}));
|
|
115
79
|
}
|
|
@@ -260,6 +224,42 @@ function useNaming(component, scheme = "verbose") {
|
|
|
260
224
|
return scheme === "compact" ? new CompactNaming(component) : new VerboseNaming(component);
|
|
261
225
|
}
|
|
262
226
|
//#endregion
|
|
227
|
+
//#region src/styles.ts
|
|
228
|
+
/**
|
|
229
|
+
* Convert a camel-cased value to kebab case
|
|
230
|
+
*/
|
|
231
|
+
function camelToKebab(camel) {
|
|
232
|
+
return camel.replace(/[A-Z]/g, (l) => `-${l.toLowerCase()}`);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Merge multiple styles on top of a base
|
|
236
|
+
*/
|
|
237
|
+
function mergeStyles(base, ...others) {
|
|
238
|
+
const merged = { ...base };
|
|
239
|
+
for (const other of others) Object.assign(merged, other);
|
|
240
|
+
return merged;
|
|
241
|
+
}
|
|
242
|
+
var PropertyProjector = class {
|
|
243
|
+
names;
|
|
244
|
+
/**
|
|
245
|
+
* Create a mapper of camel-cased values to CSS properties
|
|
246
|
+
*/
|
|
247
|
+
constructor() {
|
|
248
|
+
this.names = /* @__PURE__ */ new Map();
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Project a camel-cased value as a CSS property
|
|
252
|
+
*/
|
|
253
|
+
project(camel) {
|
|
254
|
+
let prop = this.names.get(camel);
|
|
255
|
+
if (prop === void 0) {
|
|
256
|
+
prop = camelToKebab(camel);
|
|
257
|
+
this.names.set(camel, prop);
|
|
258
|
+
}
|
|
259
|
+
return prop;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
//#endregion
|
|
263
263
|
//#region src/compilation.ts
|
|
264
264
|
/**
|
|
265
265
|
* Generate CSS for a component's styles
|
|
@@ -344,7 +344,7 @@ var ComponentCompiler = class {
|
|
|
344
344
|
const declarations = this.formatDeclarations(styles);
|
|
345
345
|
if (declarations) inner.push(declarations);
|
|
346
346
|
for (const [key, child] of nestedEntries) {
|
|
347
|
-
const rule = this.formatFragmentRules(key.
|
|
347
|
+
const rule = this.formatFragmentRules(key.includes("&") ? this.expandSelectorAnchor(parentSelector, key) : key, child);
|
|
348
348
|
if (rule) inner.push(rule);
|
|
349
349
|
}
|
|
350
350
|
if (!inner.length) return null;
|
|
@@ -367,10 +367,16 @@ var ComponentCompiler = class {
|
|
|
367
367
|
return `${selector} {\n${inner.map((rule) => rule.split("\n").map((line) => `${indent}${line}`).join("\n")).join("\n\n")}\n}`;
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
|
+
* Replace every & in a nested key with the anchor selector
|
|
371
|
+
*/
|
|
372
|
+
expandSelectorAnchor(anchor, key) {
|
|
373
|
+
return key.replaceAll("&", anchor);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
370
376
|
* Build a selector for a nested rule key
|
|
371
377
|
*/
|
|
372
378
|
buildNestedSelector(anchor, key) {
|
|
373
|
-
if (key.
|
|
379
|
+
if (key.includes("&")) return this.expandSelectorAnchor(anchor, key);
|
|
374
380
|
else if (key === anchor) return anchor;
|
|
375
381
|
else return `${anchor} ${key}`;
|
|
376
382
|
}
|
package/dist/vite.mjs
CHANGED
|
Binary file
|