aberdeen 1.7.5 → 1.9.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.
@@ -419,6 +419,7 @@ export declare function disableCreateDestroy(): void;
419
419
  * - **Two-way data binding:** When the key is `"bind"` a two-way binding between the `.value` property of the given proxied object, and the *current* input element (`<input>`, `<select>` or `<textarea>`) is created. This is often used together with {@link ref}, in order to use properties other than `.value`.
420
420
  * - **Text:**: If the key is `"text"`, the value will be appended as a `TextNode` to the *current* element. The same can also be done with the `#` syntax in string arguments, though `text=` allows additional properties to come after in the same string: `$('button text=Hello click=', alert)`.
421
421
  * - **Unsafe HTML:** When the key is `"html"`, the value will be added as HTML to the *current* element. This should only be used in exceptional situations. Beware of XSS! Never use this with untrusted user data.
422
+ * - **Rich text:** When the key is `"rich"`, the value is parsed as simple markdown-like syntax and rendered as inline elements. Supports `*italic*`, `**bold**`, `` `code` ``, and `[link text](/path)`. All text content is safely escaped, making it suitable for user data (though links should be validated if untrusted). Example: `$('p rich="Click *here* for **more** info")`.
422
423
  *
423
424
  * ### CSS shortcuts
424
425
  * For conciseness, Aberdeen supports some CSS shortcuts when setting CSS properties.
package/dist/aberdeen.js CHANGED
@@ -105,7 +105,7 @@ var topRedrawScope;
105
105
  function queue(runner) {
106
106
  if (!sortedQueue) {
107
107
  sortedQueue = new ReverseSortedSet("prio");
108
- setTimeout(runQueue, 0);
108
+ queueMicrotask(runQueue);
109
109
  } else if (!(runQueueDepth & 1)) {
110
110
  runQueueDepth++;
111
111
  if (runQueueDepth > 98) {
@@ -1225,6 +1225,7 @@ function applyBind(el, target) {
1225
1225
  el.removeEventListener("input", onInputChange);
1226
1226
  });
1227
1227
  }
1228
+ var RICH_PATTERN = /\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`|\[(.+?)\]\((.+?)\)/g;
1228
1229
  var SPECIAL_PROPS = {
1229
1230
  create: (el, value) => {
1230
1231
  if (currentScope !== topRedrawScope)
@@ -1251,6 +1252,38 @@ var SPECIAL_PROPS = {
1251
1252
  },
1252
1253
  text: (el, value) => {
1253
1254
  addNode(el, document.createTextNode(value));
1255
+ },
1256
+ rich: (el, value) => {
1257
+ let lastIndex = 0;
1258
+ let match;
1259
+ const str = String(value);
1260
+ RICH_PATTERN.lastIndex = 0;
1261
+ while ((match = RICH_PATTERN.exec(str)) !== null) {
1262
+ if (match.index > lastIndex) {
1263
+ addNode(el, document.createTextNode(str.slice(lastIndex, match.index)));
1264
+ }
1265
+ let node;
1266
+ if (match[1] !== undefined) {
1267
+ node = document.createElement("strong");
1268
+ node.textContent = match[1];
1269
+ } else if (match[2] !== undefined) {
1270
+ node = document.createElement("em");
1271
+ node.textContent = match[2];
1272
+ } else if (match[3] !== undefined) {
1273
+ node = document.createElement("code");
1274
+ node.textContent = match[3];
1275
+ } else {
1276
+ const a = document.createElement("a");
1277
+ a.textContent = match[4];
1278
+ a.href = match[5];
1279
+ node = a;
1280
+ }
1281
+ addNode(el, node);
1282
+ lastIndex = RICH_PATTERN.lastIndex;
1283
+ }
1284
+ if (lastIndex < str.length) {
1285
+ addNode(el, document.createTextNode(str.slice(lastIndex)));
1286
+ }
1254
1287
  }
1255
1288
  };
1256
1289
  function disableCreateDestroy() {
@@ -1718,5 +1751,5 @@ export {
1718
1751
  $
1719
1752
  };
1720
1753
 
1721
- //# debugId=FDDA844AB902255064756E2164756E21
1754
+ //# debugId=4395666872F3B8E864756E2164756E21
1722
1755
  //# sourceMappingURL=aberdeen.js.map