aberdeen 1.7.0 → 1.7.2

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
@@ -1,23 +1,29 @@
1
1
  # [Aberdeen](https://aberdeenjs.org/) [![](https://img.shields.io/badge/license-ISC-blue.svg)](https://github.com/vanviegen/aberdeen/blob/master/LICENSE.txt) [![](https://badge.fury.io/js/aberdeen.svg)](https://badge.fury.io/js/aberdeen) ![](https://img.shields.io/bundlejs/size/aberdeen) [![](https://img.shields.io/github/last-commit/vanviegen/aberdeen)](https://github.com/vanviegen/aberdeen)
2
2
 
3
- Build fast reactive UIs in pure TypeScript/JavaScript without a virtual DOM.
3
+ Reactive UIs in plain TypeScript. Simple to learn, fast to ship.
4
4
 
5
- Aberdeen's approach is refreshingly simple:
6
-
7
- > Use many small anonymous functions for emitting DOM elements, and automatically rerun them when their underlying data changes. JavaScript `Proxy` is used to track reads and updates to this data, which can consist of anything, from simple values to complex, typed, and deeply nested data structures.
5
+ Aberdeen wraps your state in ES6 `Proxy` objects for fine-grained property access tracking, then automatically re-executes only the DOM-building closures that depend on changed data. So we get precise DOM updates with neither virtual DOM diffing nor compiler magic.
8
6
 
9
7
  ## Why use Aberdeen?
10
8
 
11
- - 🎩 **Simple:** Express UIs naturally in JavaScript/TypeScript, without build steps or JSX, and with a minimal amount of concepts you need to learn.
12
- - **Fast:** No virtual DOM. Aberdeen intelligently updates only the minimal, necessary parts of your UI when proxied data changes.
13
- - 👥 **Awesome lists**: It's very easy and performant to reactively display data sorted by whatever you like.
14
- - 🔬 **Tiny:** Around 6KB (minimized and gzipped) for the core system. Zero runtime dependencies.
15
- - 🔋 **Batteries included**: Comes with browser history management, routing, revertible patches for optimistic user-interface updates, component-local CSS, SVG support, helper functions for transforming reactive data (mapping, partitioning, filtering, etc) and hide/unhide transition effects. No bikeshedding required!
9
+ - **Simple:** Express UIs naturally in JavaScript/TypeScript, without requiring build steps or JSX, and with a minimal amount of concepts you need to learn.
10
+ - **Type-safe:** Your reactive state can be regular TypeScript objects and arrays, with full type safety and autocompletion.
11
+ - **Fast:** No virtual DOM. Aberdeen intelligently updates only the minimal, necessary parts of your UI when proxied data changes.
12
+ - **Awesome lists**: It's very easy and performant to reactively display data sorted by whatever you like.
13
+ - **Tiny:** Around 7KB (minimized and gzipped) for the core system. Zero runtime dependencies.
14
+ - **Batteries included**: Comes with...
15
+ - Browser history management
16
+ - Routing
17
+ - Revertible patches for optimistic user-interface updates
18
+ - Component-local CSS with Tailwind-like shorthands
19
+ - SVG support
20
+ - Helper functions for transforming reactive data (mapping, partitioning, filtering, etc)
21
+ - Hide/unhide transition effects
16
22
 
17
23
  ## Why *not* use Aberdeen?
18
24
 
19
- - 🤷 **Lack of community:** There are not many of us -Aberdeen developers- yet, so don't expect terribly helpful Stack Overflow/AI answers.
20
- - 📚 **Lack of ecosystem:** You'd have to code things yourself, instead of duct-taping together a gazillion React ecosystem libraries.
25
+ - **Lack of community:** There are not many of us -Aberdeen developers- yet, so don't expect terribly helpful Stack Overflow/AI answers.
26
+ - **Lack of ecosystem:** You'd have to code things yourself, instead of duct-taping together a gazillion React ecosystem libraries.
21
27
 
22
28
  ## Examples
23
29
 
package/dist/aberdeen.js CHANGED
@@ -1107,7 +1107,7 @@ function setSpacingCssVars(base = 1, unit = "rem") {
1107
1107
  cssVars[i] = 2 ** (i - 3) * base + unit;
1108
1108
  }
1109
1109
  }
1110
- var CSS_VAR_PATTERN = /(\([^)]*\))|("[^"]*")|(^| )\$(\w+)/g;
1110
+ var CSS_VAR_PATTERN = /(\burl\([^)]*\))|("[^"]*")|(^| )\$(\w+)/g;
1111
1111
  var DIGIT_FIRST = /^\d/;
1112
1112
  function cssVarRef(value) {
1113
1113
  if (value.indexOf("$") < 0)
@@ -1119,27 +1119,6 @@ function cssVarRef(value) {
1119
1119
  return `${prefix}var(--${varName})`;
1120
1120
  });
1121
1121
  }
1122
- if (typeof document !== "undefined") {
1123
- leakScope(() => {
1124
- $(() => {
1125
- if (!isEmpty(cssVars)) {
1126
- mount(document.head, () => {
1127
- $("style", () => {
1128
- let css = `:root {
1129
- `;
1130
- for (const [key, value] of Object.entries(cssVars)) {
1131
- const varName = DIGIT_FIRST.test(String(key)) ? `m${key}` : key;
1132
- css += ` --${varName}: ${value};
1133
- `;
1134
- }
1135
- css += "}";
1136
- $(`#${css}`);
1137
- });
1138
- });
1139
- }
1140
- });
1141
- });
1142
- }
1143
1122
  var darkModeState;
1144
1123
  function darkMode() {
1145
1124
  if (!darkModeState) {
@@ -1362,10 +1341,24 @@ var cssCount = 0;
1362
1341
  function insertCss(style) {
1363
1342
  const prefix = `.AbdStl${++cssCount}`;
1364
1343
  const css = typeof style === "string" ? styleStringToCss(style, prefix) : objectToCss(style, prefix);
1365
- if (css)
1366
- $(`style#${css}`);
1344
+ if (css) {
1345
+ let cnt = cssSnippetCount++;
1346
+ cssSnippets[cnt] = css;
1347
+ clean(() => delete cssSnippets[cnt]);
1348
+ }
1367
1349
  return prefix;
1368
1350
  }
1351
+ var cssSnippets = proxy({});
1352
+ var cssSnippetCount = 0;
1353
+ function combinePrefixSelector(prefix, key) {
1354
+ const sel = [];
1355
+ for (const p of prefix.split(",")) {
1356
+ for (const k of key.split(",")) {
1357
+ sel.push(k.includes("&") ? k.trim().replace(/&/g, p) : `${p} ${k.trim()}`.trim());
1358
+ }
1359
+ }
1360
+ return sel.join(",");
1361
+ }
1369
1362
  function objectToCss(style, prefix) {
1370
1363
  let css = "";
1371
1364
  for (const [key, val] of Object.entries(style)) {
@@ -1375,8 +1368,7 @@ function objectToCss(style, prefix) {
1375
1368
  ${objectToCss(val, prefix)}}
1376
1369
  `;
1377
1370
  } else {
1378
- const sel = key === "&" ? prefix : key.includes("&") ? key.replace(/&/g, prefix) : `${prefix} ${key}`.trim();
1379
- css += objectToCss(val, sel);
1371
+ css += objectToCss(val, combinePrefixSelector(prefix, key));
1380
1372
  }
1381
1373
  } else if (typeof val === "string") {
1382
1374
  if (key.startsWith("@")) {
@@ -1384,8 +1376,7 @@ ${objectToCss(val, prefix)}}
1384
1376
  ${styleStringToCss(val, prefix)}}
1385
1377
  `;
1386
1378
  } else {
1387
- const sel = key.includes("&") ? key.replace(/&/g, prefix) : `${prefix} ${key}`.trim();
1388
- css += styleStringToCss(val, sel);
1379
+ css += styleStringToCss(val, combinePrefixSelector(prefix, key));
1389
1380
  }
1390
1381
  }
1391
1382
  }
@@ -1427,8 +1418,11 @@ function styleStringToCss(styleStr, selector) {
1427
1418
  }
1428
1419
  function insertGlobalCss(style) {
1429
1420
  const css = objectToCss(style, "");
1430
- if (css)
1431
- $(`style#${css}`);
1421
+ if (css) {
1422
+ let cnt = cssSnippetCount++;
1423
+ cssSnippets[cnt] = css;
1424
+ clean(() => delete cssSnippets[cnt]);
1425
+ }
1432
1426
  }
1433
1427
  var CSS_SHORT = {
1434
1428
  m: "margin",
@@ -1632,6 +1626,33 @@ function withEmitHandler(handler, func) {
1632
1626
  emit = oldEmitHandler;
1633
1627
  }
1634
1628
  }
1629
+ if (typeof document !== "undefined") {
1630
+ leakScope(() => {
1631
+ $(() => {
1632
+ if (isEmpty(cssSnippets) && isEmpty(cssVars))
1633
+ return;
1634
+ mount(document.head, () => {
1635
+ $("style.abd", () => {
1636
+ onEach(cssSnippets, (value) => {
1637
+ $("#", value);
1638
+ });
1639
+ $(() => {
1640
+ if (isEmpty(cssVars))
1641
+ return;
1642
+ let css = ":root{";
1643
+ for (const [key, value] of Object.entries(cssVars)) {
1644
+ const varName = DIGIT_FIRST.test(String(key)) ? `m${key}` : key;
1645
+ css += `--${varName}:${value};`;
1646
+ }
1647
+ css += `}
1648
+ `;
1649
+ $("#", css);
1650
+ });
1651
+ });
1652
+ });
1653
+ });
1654
+ });
1655
+ }
1635
1656
  export {
1636
1657
  withEmitHandler,
1637
1658
  unproxy,
@@ -1666,5 +1687,5 @@ export {
1666
1687
  $
1667
1688
  };
1668
1689
 
1669
- //# debugId=77770EA398EEA24264756E2164756E21
1690
+ //# debugId=35DE752A41396D7264756E2164756E21
1670
1691
  //# sourceMappingURL=aberdeen.js.map