mancha 0.6.6 → 0.7.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/README.md CHANGED
@@ -171,13 +171,15 @@ To use `mancha` on the client (browser), use the `mancha` bundled file available
171
171
  <span>Hello, {{ name }}!</span>
172
172
  </body>
173
173
 
174
- <script src="//unpkg.com/mancha" target="body" defer init></script>
174
+ <script src="//unpkg.com/mancha" target="body" css="basic+utils" defer init></script>
175
175
  ```
176
176
 
177
177
  Script tag attributes:
178
178
 
179
179
  - `init`: whether to automatically render upon script load
180
- - `target`: comma-separated document elements to render e.g. "body" or "head,body" (defaults to "body")
180
+ - `target`: document elements separated by `+` to render e.g. "body" or "head+body" (defaults to
181
+ "body")
182
+ - `css`: inject predefined CSS rules known to Mancha (experimental)
181
183
 
182
184
  For a more complete example, see [examples/browser](./examples/browser).
183
185
 
package/dist/browser.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { dirname, IRenderer } from "./core.js";
2
+ import basicCssRules from "./css_gen_basic.js";
3
+ import utilsCssRules from "./css_gen_utils.js";
2
4
  class Renderer extends IRenderer {
3
5
  dirpath = dirname(self.location.href);
4
6
  parseHTML(content, params = { rootDocument: false }) {
@@ -22,10 +24,11 @@ class Renderer extends IRenderer {
22
24
  const Mancha = new Renderer();
23
25
  self["Mancha"] = Mancha;
24
26
  const currentScript = self.document?.currentScript;
27
+ // If the init attribute is present, mount the content to the target element(s).
25
28
  if (self.document?.currentScript?.hasAttribute("init")) {
26
29
  const debug = currentScript?.hasAttribute("debug");
27
30
  const cachePolicy = currentScript?.getAttribute("cache");
28
- const targets = currentScript?.getAttribute("target")?.split(",") || ["body"];
31
+ const targets = currentScript?.getAttribute("target")?.split("+") || ["body"];
29
32
  window.addEventListener("load", () => {
30
33
  targets.map(async (target) => {
31
34
  const fragment = self.document.querySelector(target);
@@ -33,4 +36,23 @@ if (self.document?.currentScript?.hasAttribute("init")) {
33
36
  });
34
37
  });
35
38
  }
39
+ // If the css attribute is present, inject the specified CSS rules.
40
+ if (self.document?.currentScript?.hasAttribute("css")) {
41
+ const styleNames = currentScript?.getAttribute("css")?.split("+");
42
+ for (const styleName of styleNames) {
43
+ const style = document.createElement("style");
44
+ switch (styleName) {
45
+ case "basic":
46
+ style.textContent = basicCssRules();
47
+ break;
48
+ case "utils":
49
+ style.textContent = utilsCssRules();
50
+ break;
51
+ default:
52
+ console.error(`Unknown style name: "${styleName}"`);
53
+ break;
54
+ }
55
+ self.document.head.appendChild(style);
56
+ }
57
+ }
36
58
  export default Mancha;
package/dist/cli.js CHANGED
File without changes
@@ -0,0 +1 @@
1
+ export default function rules(): string;
@@ -0,0 +1,4 @@
1
+ import basic from "./css_raw_basic.css";
2
+ export default function rules() {
3
+ return basic;
4
+ }
@@ -0,0 +1 @@
1
+ export default function rules(): string;
@@ -0,0 +1,594 @@
1
+ const REM_UNIT = 0.25;
2
+ const UNITS_SM = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
3
+ const UNITS_LG = [16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60];
4
+ const UNITS_XL = [64, 72, 80, 96, 112, 128, 144, 160, 192, 224, 256, 288, 320, 384, 448, 512];
5
+ const UNITS_ALL = [...UNITS_SM, ...UNITS_LG, ...UNITS_XL];
6
+ const PERCENTS = [1, 2, 5, 10, 20, 25, 30, 40, 50, 60, 70, 75, 80, 90, 95, 98, 99, 100];
7
+ const PSEUDO_STATES = ["hover", "focus", "disabled", "focus", "active"];
8
+ const MEDIA_BREAKPOINTS = {
9
+ sm: 640,
10
+ md: 768,
11
+ lg: 1024,
12
+ xl: 1280,
13
+ };
14
+ const PROPS_SPACING = {
15
+ margin: "m",
16
+ padding: "p",
17
+ };
18
+ const PROPS_SIZING = {
19
+ width: "w",
20
+ height: "h",
21
+ };
22
+ const PROPS_POSITION = {
23
+ top: "top",
24
+ right: "right",
25
+ bottom: "bottom",
26
+ left: "left",
27
+ };
28
+ const PROPS_SIZING_MINMAX = {
29
+ "min-width": "min-w",
30
+ "min-height": "min-h",
31
+ "max-width": "max-w",
32
+ "max-height": "max-h",
33
+ };
34
+ const PROPS_CUSTOM = {
35
+ // Based on https://matcha.mizu.sh/@utilities.css.
36
+ // Text style.
37
+ bold: { "font-weight": "bold" },
38
+ semibold: { "font-weight": 600 },
39
+ italic: { "font-style": "italic" },
40
+ underline: { "text-decoration": "underline" },
41
+ "no-underline": { "text-decoration": "none" },
42
+ "decoration-none": { "text-decoration": "none" },
43
+ "line-through": { "text-decoration": "line-through" },
44
+ uppercase: { "text-transform": "uppercase" },
45
+ lowercase: { "text-transform": "lowercase" },
46
+ capitalize: { "text-transform": "capitalize" },
47
+ "font-mono": { "font-family": "ui-monospace, monospace" },
48
+ "font-sans": { "font-family": "ui-sans-serif, system-ui, sans-serif" },
49
+ "font-serif": { "font-family": "ui-serif, serif" },
50
+ // Text position.
51
+ "text-left": { "text-align": "left" },
52
+ "text-right": { "text-align": "right" },
53
+ "text-center": { "text-align": "center" },
54
+ "text-justify": { "text-align": "justify" },
55
+ // Font size.
56
+ "text-xs": { "font-size": ".75rem" },
57
+ "text-sm": { "font-size": ".875rem" },
58
+ "text-base": { "font-size": "1rem" },
59
+ "text-lg": { "font-size": "1.125rem" },
60
+ "text-xl": { "font-size": "1.25rem" },
61
+ // Position.
62
+ relative: { position: "relative" },
63
+ fixed: { position: "fixed" },
64
+ absolute: { position: "absolute" },
65
+ sticky: { position: "sticky" },
66
+ // Object fit.
67
+ "object-contain": { "object-fit": "contain" },
68
+ "object-cover": { "object-fit": "cover" },
69
+ "object-fill": { "object-fit": "fill" },
70
+ "object-none": { "object-fit": "none" },
71
+ // Display.
72
+ block: { display: "block" },
73
+ contents: { display: "contents" },
74
+ hidden: { display: "none" },
75
+ inline: { display: "inline" },
76
+ "inline-block": { display: "inline-block" },
77
+ // Flex.
78
+ flex: { display: "flex" },
79
+ "flex-1": { flex: "1 1 0%" },
80
+ "flex-inline": { display: "inline-flex" },
81
+ "flex-row": { "flex-direction": "row" },
82
+ "flex-col": { "flex-direction": "column" },
83
+ "flex-row-reverse": { "flex-direction": "row-reverse" },
84
+ "flex-col-reverse": { "flex-direction": "column-reverse" },
85
+ "flex-wrap": { "flex-wrap": "wrap" },
86
+ "flex-wrap-reverse": { "flex-wrap": "wrap-reverse" },
87
+ "flex-nowrap": { "flex-wrap": "nowrap" },
88
+ "justify-start": { "justify-content": "flex-start" },
89
+ "justify-end": { "justify-content": "flex-end" },
90
+ "justify-center": { "justify-content": "center" },
91
+ "justify-between": { "justify-content": "space-between" },
92
+ "justify-around": { "justify-content": "space-around" },
93
+ "justify-evenly": { "justify-content": "space-evenly" },
94
+ "justify-stretch": { "justify-content": "stretch" },
95
+ "items-start": { "align-items": "flex-start" },
96
+ "items-end": { "align-items": "flex-end" },
97
+ "items-center": { "align-items": "center" },
98
+ "items-stretch": { "align-items": "stretch" },
99
+ "flex-grow": { "flex-grow": 1 },
100
+ "flex-shrink": { "flex-shrink": 1 },
101
+ // Overflow.
102
+ "overflow-auto": { overflow: "auto" },
103
+ "overflow-x-auto": { "overflow-x": "auto" },
104
+ "overflow-y-auto": { "overflow-y": "auto" },
105
+ "overflow-hidden": { overflow: "hidden" },
106
+ "overflow-visible": { overflow: "visible" },
107
+ // Cursors.
108
+ "cursor-pointer": { cursor: "pointer" },
109
+ "cursor-wait": { cursor: "wait" },
110
+ "cursor-not-allowed": { cursor: "not-allowed" },
111
+ // User selection.
112
+ "select-none": { "user-select": "none" },
113
+ "select-all": { "user-select": "all" },
114
+ // Events.
115
+ "pointer-events-auto": { "pointer-events": "auto" },
116
+ "pointer-events-none": { "pointer-events": "none" },
117
+ // Sizing.
118
+ "box-border": { "box-sizing": "border-box" },
119
+ "box-content": { "box-sizing": "content-box" },
120
+ // Resizing.
121
+ resize: { resize: "both" },
122
+ "resize-x": { resize: "horizontal" },
123
+ "resize-y": { resize: "vertical" },
124
+ "resize-none": { resize: "none" },
125
+ // Borders.
126
+ border: { border: "1px solid" },
127
+ "border-none": { border: "none" },
128
+ "border-solid": { "border-style": "solid" },
129
+ "border-dashed": { "border-style": "dashed" },
130
+ "border-dotted": { "border-style": "dotted" },
131
+ // Radius.
132
+ "rounded-none": { "border-radius": "0" },
133
+ rounded: { "border-radius": ".25rem" },
134
+ "rounded-sm": { "border-radius": ".125rem" },
135
+ "rounded-md": { "border-radius": ".375rem" },
136
+ "rounded-lg": { "border-radius": ".5rem" },
137
+ "rounded-xl": { "border-radius": ".75rem" },
138
+ "rounded-full": { "border-radius": "9999px" },
139
+ // Transitions.
140
+ "transition-none": { transition: "none" },
141
+ transition: { transition: "all 150ms" },
142
+ // Animations.
143
+ "animate-none": { animation: "none" },
144
+ "animate-spin": { animation: "spin 1s linear infinite" },
145
+ "animate-ping": { animation: "ping 1s cubic-bezier(0, 0, 0.2, 1) infinite" },
146
+ "animate-pulse": { animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite" },
147
+ };
148
+ const PROPS_AS_IS = [
149
+ `@keyframes spin {
150
+ from { transform: rotate(0deg) }
151
+ to { transform: rotate(360deg) }
152
+ }`,
153
+ `@keyframes ping {
154
+ 75%, 100% {
155
+ transform: scale(2);
156
+ opacity: 0;
157
+ }
158
+ }`,
159
+ `@keyframes pulse {
160
+ 0%, 100% { opacity: 1 }
161
+ 50% { opacity: .5 }
162
+ }`,
163
+ ];
164
+ const PROPS_COLORS = {
165
+ red: {
166
+ 50: 0xffebee,
167
+ 100: 0xffcdd2,
168
+ 200: 0xef9a9a,
169
+ 300: 0xe57373,
170
+ 400: 0xef5350,
171
+ 500: 0xf44336,
172
+ 600: 0xe53935,
173
+ 700: 0xd32f2f,
174
+ 800: 0xc62828,
175
+ 900: 0xb71c1c,
176
+ },
177
+ pink: {
178
+ 50: 0xfce4ec,
179
+ 100: 0xf8bbd0,
180
+ 200: 0xf48fb1,
181
+ 300: 0xf06292,
182
+ 400: 0xec407a,
183
+ 500: 0xe91e63,
184
+ 600: 0xd81b60,
185
+ 700: 0xc2185b,
186
+ 800: 0xad1457,
187
+ 900: 0x880e4f,
188
+ },
189
+ purple: {
190
+ 50: 0xf3e5f5,
191
+ 100: 0xe1bee7,
192
+ 200: 0xce93d8,
193
+ 300: 0xba68c8,
194
+ 400: 0xab47bc,
195
+ 500: 0x9c27b0,
196
+ 600: 0x8e24aa,
197
+ 700: 0x7b1fa2,
198
+ 800: 0x6a1b9a,
199
+ 900: 0x4a148c,
200
+ },
201
+ "deep-purple": {
202
+ 50: 0xede7f6,
203
+ 100: 0xd1c4e9,
204
+ 200: 0xb39ddb,
205
+ 300: 0x9575cd,
206
+ 400: 0x7e57c2,
207
+ 500: 0x673ab7,
208
+ 600: 0x5e35b1,
209
+ 700: 0x512da8,
210
+ 800: 0x4527a0,
211
+ 900: 0x311b92,
212
+ },
213
+ indigo: {
214
+ 50: 0xe8eaf6,
215
+ 100: 0xc5cae9,
216
+ 200: 0x9fa8da,
217
+ 300: 0x7986cb,
218
+ 400: 0x5c6bc0,
219
+ 500: 0x3f51b5,
220
+ 600: 0x3949ab,
221
+ 700: 0x303f9f,
222
+ 800: 0x283593,
223
+ 900: 0x1a237e,
224
+ },
225
+ blue: {
226
+ 50: 0xe3f2fd,
227
+ 100: 0xbbdefb,
228
+ 200: 0x90caf9,
229
+ 300: 0x64b5f6,
230
+ 400: 0x42a5f5,
231
+ 500: 0x2196f3,
232
+ 600: 0x1e88e5,
233
+ 700: 0x1976d2,
234
+ 800: 0x1565c0,
235
+ 900: 0x0d47a1,
236
+ },
237
+ "light-blue": {
238
+ 50: 0xe1f5fe,
239
+ 100: 0xb3e5fc,
240
+ 200: 0x81d4fa,
241
+ 300: 0x4fc3f7,
242
+ 400: 0x29b6f6,
243
+ 500: 0x03a9f4,
244
+ 600: 0x039be5,
245
+ 700: 0x0288d1,
246
+ 800: 0x0277bd,
247
+ 900: 0x01579b,
248
+ },
249
+ cyan: {
250
+ 50: 0xe0f7fa,
251
+ 100: 0xb2ebf2,
252
+ 200: 0x80deea,
253
+ 300: 0x4dd0e1,
254
+ 400: 0x26c6da,
255
+ 500: 0x00bcd4,
256
+ 600: 0x00acc1,
257
+ 700: 0x0097a7,
258
+ 800: 0x00838f,
259
+ 900: 0x006064,
260
+ },
261
+ teal: {
262
+ 50: 0xe0f2f1,
263
+ 100: 0xb2dfdb,
264
+ 200: 0x80cbc4,
265
+ 300: 0x4db6ac,
266
+ 400: 0x26a69a,
267
+ 500: 0x009688,
268
+ 600: 0x00897b,
269
+ 700: 0x00796b,
270
+ 800: 0x00695c,
271
+ 900: 0x004d40,
272
+ },
273
+ green: {
274
+ 50: 0xe8f5e9,
275
+ 100: 0xc8e6c9,
276
+ 200: 0xa5d6a7,
277
+ 300: 0x81c784,
278
+ 400: 0x66bb6a,
279
+ 500: 0x4caf50,
280
+ 600: 0x43a047,
281
+ 700: 0x388e3c,
282
+ 800: 0x2e7d32,
283
+ 900: 0x1b5e20,
284
+ },
285
+ "light-green": {
286
+ 50: 0xf1f8e9,
287
+ 100: 0xdcedc8,
288
+ 200: 0xc5e1a5,
289
+ 300: 0xaed581,
290
+ 400: 0x9ccc65,
291
+ 500: 0x8bc34a,
292
+ 600: 0x7cb342,
293
+ 700: 0x689f38,
294
+ 800: 0x558b2f,
295
+ 900: 0x33691e,
296
+ },
297
+ lime: {
298
+ 50: 0xf9fbe7,
299
+ 100: 0xf0f4c3,
300
+ 200: 0xe6ee9c,
301
+ 300: 0xdce775,
302
+ 400: 0xd4e157,
303
+ 500: 0xcddc39,
304
+ 600: 0xc0ca33,
305
+ 700: 0xafb42b,
306
+ 800: 0x9e9d24,
307
+ 900: 0x827717,
308
+ },
309
+ yellow: {
310
+ 50: 0xfffde7,
311
+ 100: 0xfff9c4,
312
+ 200: 0xfff59d,
313
+ 300: 0xfff176,
314
+ 400: 0xffee58,
315
+ 500: 0xffeb3b,
316
+ 600: 0xfdd835,
317
+ 700: 0xfbc02d,
318
+ 800: 0xf9a825,
319
+ 900: 0xf57f17,
320
+ },
321
+ amber: {
322
+ 50: 0xfff8e1,
323
+ 100: 0xffecb3,
324
+ 200: 0xffe082,
325
+ 300: 0xffd54f,
326
+ 400: 0xffca28,
327
+ 500: 0xffc107,
328
+ 600: 0xffb300,
329
+ 700: 0xffa000,
330
+ 800: 0xff8f00,
331
+ 900: 0xff6f00,
332
+ },
333
+ orange: {
334
+ 50: 0xfff3e0,
335
+ 100: 0xffe0b2,
336
+ 200: 0xffcc80,
337
+ 300: 0xffb74d,
338
+ 400: 0xffa726,
339
+ 500: 0xff9800,
340
+ 600: 0xfb8c00,
341
+ 700: 0xf57c00,
342
+ 800: 0xef6c00,
343
+ 900: 0xe65100,
344
+ },
345
+ "deep-orange": {
346
+ 50: 0xfbe9e7,
347
+ 100: 0xffccbc,
348
+ 200: 0xffab91,
349
+ 300: 0xff8a65,
350
+ 400: 0xff7043,
351
+ 500: 0xff5722,
352
+ 600: 0xf4511e,
353
+ 700: 0xe64a19,
354
+ 800: 0xd84315,
355
+ 900: 0xbf360c,
356
+ },
357
+ brown: {
358
+ 50: 0xefebe9,
359
+ 100: 0xd7ccc8,
360
+ 200: 0xbcaaa4,
361
+ 300: 0xa1887f,
362
+ 400: 0x8d6e63,
363
+ 500: 0x795548,
364
+ 600: 0x6d4c41,
365
+ 700: 0x5d4037,
366
+ 800: 0x4e342e,
367
+ 900: 0x3e2723,
368
+ },
369
+ gray: {
370
+ 50: 0xfafafa,
371
+ 100: 0xf5f5f5,
372
+ 200: 0xeeeeee,
373
+ 300: 0xe0e0e0,
374
+ 400: 0xbdbdbd,
375
+ 500: 0x9e9e9e,
376
+ 600: 0x757575,
377
+ 700: 0x616161,
378
+ 800: 0x424242,
379
+ 900: 0x212121,
380
+ },
381
+ "blue-gray": {
382
+ 50: 0xeceff1,
383
+ 100: 0xcfd8dc,
384
+ 200: 0xb0bec5,
385
+ 300: 0x90a4ae,
386
+ 400: 0x78909c,
387
+ 500: 0x607d8b,
388
+ 600: 0x546e7a,
389
+ 700: 0x455a64,
390
+ 800: 0x37474f,
391
+ 900: 0x263238,
392
+ },
393
+ };
394
+ function wrapPseudoStates(klass) {
395
+ return PSEUDO_STATES.map((state) => `.${state}\\:${klass}:${state}`);
396
+ }
397
+ function wrapMediaQueries(klass, rule) {
398
+ return Object.entries(MEDIA_BREAKPOINTS).map(([bp, width]) => `@media (min-width: ${width}px) { .${bp}\\:${klass} { ${rule} } }`);
399
+ }
400
+ function posneg(props) {
401
+ return Object.entries(props).flatMap(([prop, klass]) => [
402
+ // Zero.
403
+ `.${klass}-0 { ${prop}: 0; }`,
404
+ // Screen.
405
+ `.${klass}-screen { ${prop}: 100vw; }`,
406
+ // Full.
407
+ `.${klass}-full { ${prop}: 100%; }`,
408
+ // Positive REM units.
409
+ ...UNITS_ALL.map((v) => `.${klass}-${v} { ${prop}: ${v * REM_UNIT}rem; }`),
410
+ // Negative REM units.
411
+ ...UNITS_ALL.map((v) => `.-${klass}-${v} { ${prop}: -${v * REM_UNIT}rem; }`),
412
+ // Positive PX units.
413
+ ...UNITS_ALL.map((v) => `.${klass}-${v}px { ${prop}: ${v}px; }`),
414
+ // Negative PX units.
415
+ ...UNITS_ALL.map((v) => `.-${klass}-${v}px { ${prop}: -${v}px; }`),
416
+ // Positive percent units.
417
+ ...PERCENTS.map((v) => `.${klass}-${v}% { ${prop}: ${v}%; }`),
418
+ // Negative percent units.
419
+ ...PERCENTS.map((v) => `.-${klass}-${v}% { ${prop}: -${v}%; }`),
420
+ ]);
421
+ }
422
+ function autoxy(props) {
423
+ return Object.entries(props).flatMap(([prop, klass]) => [
424
+ // Auto.
425
+ `.${klass}-auto { ${prop}: auto; }`,
426
+ // Auto x-axis.
427
+ `.${klass}x-auto { ${prop}-left: auto; ${prop}-right: auto; }`,
428
+ // Auto y-axis.
429
+ `.${klass}y-auto { ${prop}-top: auto; ${prop}-bottom: auto; }`,
430
+ // Positive REM units x-axis.
431
+ ...UNITS_ALL.map((v) => [v, v * REM_UNIT]).map(([k, v]) => `.${klass}x-${k} { ${prop}-left: ${v}rem; ${prop}-right: ${v}rem; }`),
432
+ // Positive REM units y-axis.
433
+ ...UNITS_ALL.map((v) => [v, v * REM_UNIT]).map(([k, v]) => `.${klass}y-${k} { ${prop}-top: ${v}rem; ${prop}-bottom: ${v}rem; }`),
434
+ // Positive PX units x-axis.
435
+ ...UNITS_ALL.map((v) => `.${klass}x-${v}px { ${prop}-left: ${v}px; ${prop}-right: ${v}px; }`),
436
+ // Positive PX units y-axis.
437
+ ...UNITS_ALL.map((v) => `.${klass}y-${v}px { ${prop}-top: ${v}px; ${prop}-bottom: ${v}px; }`),
438
+ // Positive percent units x-axis.
439
+ ...PERCENTS.map((v) => `.${klass}x-${v}% { ${prop}-left: ${v}%; ${prop}-right: ${v}%; }`),
440
+ // Positive percent units y-axis.
441
+ ...PERCENTS.map((v) => `.${klass}y-${v}% { ${prop}-top: ${v}%; ${prop}-bottom: ${v}%; }`),
442
+ ]);
443
+ }
444
+ function tblr(props) {
445
+ return Object.entries(props).flatMap(([prop, klass]) => [
446
+ // Auto top.
447
+ `.${klass}t-auto { ${prop}-top: auto }`,
448
+ // Auto bottom.
449
+ `.${klass}b-auto { ${prop}-bottom: auto }`,
450
+ // Auto left.
451
+ `.${klass}l-auto { ${prop}-left: auto }`,
452
+ // Auto right.
453
+ `.${klass}r-auto { ${prop}-right: auto }`,
454
+ // Positive REM units top.
455
+ ...UNITS_ALL.map((v) => [v, v * REM_UNIT]).map(([k, v]) => `.${klass}t-${k} { ${prop}-top: ${v}rem }`),
456
+ // Positive REM units bottom.
457
+ ...UNITS_ALL.map((v) => [v, v * REM_UNIT]).map(([k, v]) => `.${klass}b-${k} { ${prop}-bottom: ${v}rem }`),
458
+ // Positive REM units left.
459
+ ...UNITS_ALL.map((v) => [v, v * REM_UNIT]).map(([k, v]) => `.${klass}l-${k} { ${prop}-left: ${v}rem }`),
460
+ // Positive REM units right.
461
+ ...UNITS_ALL.map((v) => [v, v * REM_UNIT]).map(([k, v]) => `.${klass}r-${k} { ${prop}-right: ${v}rem }`),
462
+ // Positive PX units top.
463
+ ...UNITS_ALL.map((v) => `.${klass}t-${v}px { ${prop}-top: ${v}px }`),
464
+ // Positive PX units bottom.
465
+ ...UNITS_ALL.map((v) => `.${klass}t-${v}px { ${prop}-bottom: ${v}px }`),
466
+ // Positive PX units left.
467
+ ...UNITS_ALL.map((v) => `.${klass}t-${v}px { ${prop}-left: ${v}px }`),
468
+ // Positive PX units right.
469
+ ...UNITS_ALL.map((v) => `.${klass}t-${v}px { ${prop}-right: ${v}px }`),
470
+ // Positive percent units top.
471
+ ...PERCENTS.map((v) => `.${klass}y-${v}% { ${prop}-top: ${v}% }`),
472
+ // Positive percent units bottom.
473
+ ...PERCENTS.map((v) => `.${klass}y-${v}% { ${prop}-bottom: ${v}%; }`),
474
+ // Positive percent units left.
475
+ ...PERCENTS.map((v) => `.${klass}x-${v}% { ${prop}-left: ${v}% }`),
476
+ // Positive percent units right.
477
+ ...PERCENTS.map((v) => `.${klass}x-${v}% { ${prop}-right: ${v}% }`),
478
+ ]);
479
+ }
480
+ function border() {
481
+ return [
482
+ // Pixel units for border width.
483
+ ...UNITS_SM.map((v) => `.border-${v} { border-width: ${v}px; }`),
484
+ ];
485
+ }
486
+ function between() {
487
+ return [
488
+ // Zero for x margin.
489
+ `.space-x-0 > * { margin-left: 0; }`,
490
+ // Zero for y margin.
491
+ `.space-y-0 > * { margin-top: 0; }`,
492
+ // Positive REM units for x margin.
493
+ ...UNITS_ALL.map((v) => `.space-x-${v} > :not(:first-child) { margin-left: ${v * REM_UNIT}rem; }`),
494
+ // Positive REM units for y margin.
495
+ ...UNITS_ALL.map((v) => `.space-y-${v} > :not(:first-child) { margin-top: ${v * REM_UNIT}rem; }`),
496
+ // Positive PX units for x margin.
497
+ ...UNITS_ALL.map((v) => `.space-x-${v}px > :not(:first-child) { margin-left: ${v}px; }`),
498
+ // Positive PX units for y margin.
499
+ ...UNITS_ALL.map((v) => `.space-y-${v}px > :not(:first-child) { margin-top: ${v}px; }`),
500
+ // Zero for gap.
501
+ `.gap-0 { gap: 0; }`,
502
+ // Positive REM units for gap.
503
+ ...UNITS_ALL.map((v) => `.gap-${v} { gap: ${v * REM_UNIT}rem; }`),
504
+ // Positive PX units for gap.
505
+ ...UNITS_ALL.map((v) => `.gap-${v}px { gap: ${v}px; }`),
506
+ // Positive REM units for col gap.
507
+ ...UNITS_ALL.map((v) => `.gap-x-${v} { column-gap: ${v * REM_UNIT}rem; }`),
508
+ // Positive REM units for row gap.
509
+ ...UNITS_ALL.map((v) => `.gap-y-${v} { row-gap: ${v * REM_UNIT}rem; }`),
510
+ // Positive PX units for col gap.
511
+ ...UNITS_ALL.map((v) => `.gap-x-${v}px { column-gap: ${v}px; }`),
512
+ // Positive PX units for row gap.
513
+ ...UNITS_ALL.map((v) => `.gap-y-${v}px { row-gap: ${v}px; }`),
514
+ ];
515
+ }
516
+ function custom() {
517
+ return Object.entries(PROPS_CUSTOM).flatMap(([klass, props]) => Object.entries(props).flatMap(([propkey, propval]) => [
518
+ `.${klass} { ${propkey}: ${propval} }`,
519
+ `${wrapPseudoStates(klass).join(",")} { ${propkey}: ${propval} }`,
520
+ ...wrapMediaQueries(klass, `${propkey}: ${propval}`),
521
+ ]));
522
+ }
523
+ function colors() {
524
+ const bw = [
525
+ ["white", "#fff"],
526
+ ["black", "#000"],
527
+ ["transparent", "transparent"],
528
+ ].flatMap(([color, value]) => [
529
+ [`text-${color}`, `color: ${value}`],
530
+ [`fill-${color}`, `fill: ${value}`],
531
+ [`bg-${color}`, `background-color: ${value}`],
532
+ [`border-${color}`, `border-color: ${value}`],
533
+ ]);
534
+ const mains = Object.entries(PROPS_COLORS).flatMap(([color, shades]) => [
535
+ [`text-${color}`, `color: #${shades[500].toString(16)}`],
536
+ [`fill-${color}`, `fill: #${shades[500].toString(16)}`],
537
+ [`bg-${color}`, `background-color: #${shades[500].toString(16)}`],
538
+ [`border-${color}`, `border-color: #${shades[500].toString(16)}`],
539
+ ]);
540
+ const shades = Object.entries(PROPS_COLORS).flatMap(([color, shades]) => Object.entries(shades).flatMap(([shade, hex]) => [
541
+ [`text-${color}-${shade}`, `color: #${hex.toString(16)}`],
542
+ [`fill-${color}-${shade}`, `fill: #${hex.toString(16)}`],
543
+ [`bg-${color}-${shade}`, `background-color: #${hex.toString(16)}`],
544
+ [`border-${color}-${shade}`, `border-color: #${hex.toString(16)}`],
545
+ ]));
546
+ return []
547
+ .concat(bw)
548
+ .concat(mains)
549
+ .concat(shades)
550
+ .flatMap(([klass, rule]) => [
551
+ `.${klass} { ${rule} }`,
552
+ `${wrapPseudoStates(klass).join(",")} { ${rule} }`,
553
+ ...wrapMediaQueries(klass, rule),
554
+ ]);
555
+ }
556
+ function opacity() {
557
+ return [
558
+ // Zero for opacity.
559
+ `.opacity-0 { opacity: 0; }`,
560
+ // Positive percent units for opacity.
561
+ ...PERCENTS.map((v) => `.opacity-${v} { opacity: ${v / 100}; }`),
562
+ ].flatMap(([klass, rule]) => [
563
+ `.${klass} { ${rule} }`,
564
+ `${wrapPseudoStates(klass).join(",")} { ${rule} }`,
565
+ ...wrapMediaQueries(klass, rule),
566
+ ]);
567
+ }
568
+ export default function rules() {
569
+ return [
570
+ // As-is.
571
+ ...PROPS_AS_IS,
572
+ // Custom.
573
+ ...custom(),
574
+ // Colors.
575
+ ...colors(),
576
+ // Opacity.
577
+ ...opacity(),
578
+ // Sizing.
579
+ ...posneg(PROPS_SIZING),
580
+ ...autoxy(PROPS_SIZING),
581
+ // Position.
582
+ ...posneg(PROPS_POSITION),
583
+ ...autoxy(PROPS_POSITION),
584
+ // Spacing.
585
+ ...tblr(PROPS_SPACING),
586
+ ...posneg(PROPS_SPACING),
587
+ ...autoxy(PROPS_SPACING),
588
+ ...between(),
589
+ // Minmax.
590
+ ...posneg(PROPS_SIZING_MINMAX),
591
+ // Border.
592
+ ...border(),
593
+ ].join("\n");
594
+ }
@@ -0,0 +1 @@
1
+ html{max-width:70ch;padding:2em 1em;margin:auto;line-height:1.75;font-size:1.25em;font-family:sans-serif}h1,h2,h3,h4,h5,h6{margin:1em 0 .5em}ol,p,ul{margin-bottom:1em;color:#1d1d1d}