aberdeen 1.6.0 → 1.7.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 +5 -11
- package/dist/aberdeen.d.ts +173 -129
- package/dist/aberdeen.js +181 -95
- package/dist/aberdeen.js.map +3 -3
- package/dist/dispatcher.d.ts +10 -7
- package/dist/dispatcher.js +11 -10
- package/dist/dispatcher.js.map +3 -3
- package/dist/route.d.ts +17 -0
- package/dist/route.js +62 -20
- package/dist/route.js.map +3 -3
- package/dist-min/aberdeen.js +9 -7
- package/dist-min/aberdeen.js.map +3 -3
- package/dist-min/dispatcher.js +2 -2
- package/dist-min/dispatcher.js.map +3 -3
- package/dist-min/route.js +2 -2
- package/dist-min/route.js.map +3 -3
- package/html-to-aberdeen +3 -6
- package/package.json +1 -1
- package/skill/SKILL.md +286 -76
- package/skill/aberdeen.md +219 -203
- package/skill/dispatcher.md +16 -13
- package/skill/prediction.md +3 -3
- package/skill/route.md +44 -16
- package/skill/transitions.md +3 -3
- package/src/aberdeen.ts +397 -237
- package/src/dispatcher.ts +16 -13
- package/src/route.ts +90 -19
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ $('h3', () => {
|
|
|
38
38
|
$('input placeholder=Question bind=', ref(state, 'question'))
|
|
39
39
|
|
|
40
40
|
// Allow state.answer to be modified using both an <input> and buttons
|
|
41
|
-
$('div.row
|
|
41
|
+
$('div.row margin-top:1em', () => {
|
|
42
42
|
$('button text=- click=', () => state.answer--);
|
|
43
43
|
$('input type=number bind=', ref(state, 'answer'))
|
|
44
44
|
$('button text=+ click=', () => state.answer++);
|
|
@@ -133,16 +133,10 @@ function drawItem(item) {
|
|
|
133
133
|
|
|
134
134
|
// Insert some component-local CSS, specific for this demo.
|
|
135
135
|
const todoItemStyle = insertCss({
|
|
136
|
-
|
|
137
|
-
".checkmark":
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
"&.done": {
|
|
141
|
-
textDecoration: "line-through",
|
|
142
|
-
".checkmark": {
|
|
143
|
-
opacity: 1,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
136
|
+
"&": "mb:0.5rem",
|
|
137
|
+
".checkmark": "opacity:0.2",
|
|
138
|
+
"&.done": "text-decoration:line-through",
|
|
139
|
+
"&.done .checkmark": "opacity:1"
|
|
146
140
|
});
|
|
147
141
|
|
|
148
142
|
// Go!
|
package/dist/aberdeen.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* ```typescript
|
|
17
17
|
* const data = proxy("before");
|
|
18
18
|
*
|
|
19
|
-
* $('#'
|
|
19
|
+
* $('#', data);
|
|
20
20
|
* console.log(1, document.body.innerHTML); // before
|
|
21
21
|
*
|
|
22
22
|
* // Make an update that should cause the DOM to change.
|
|
@@ -222,8 +222,6 @@ export declare function copy<T extends object>(dst: T, dstKey: keyof T, src: T[t
|
|
|
222
222
|
* Like {@link copy}, but uses merge semantics. Properties in `dst` not present in `src` are kept.
|
|
223
223
|
* `null`/`undefined` in `src` delete properties in `dst`.
|
|
224
224
|
*
|
|
225
|
-
* When the destination is an object and the source is an array, its keys are used as (sparse) array indices.
|
|
226
|
-
*
|
|
227
225
|
* @example Basic merge
|
|
228
226
|
* ```typescript
|
|
229
227
|
* const source = { b: { c: 99 }, d: undefined }; // d: undefined will delete
|
|
@@ -234,14 +232,6 @@ export declare function copy<T extends object>(dst: T, dstKey: keyof T, src: T[t
|
|
|
234
232
|
* console.log(dest); // proxy({ a: 1, b: { c: 99, x: 5, y: 6 }, c: { z: 7 } })
|
|
235
233
|
* ```
|
|
236
234
|
*
|
|
237
|
-
* @example Partial Array Merge
|
|
238
|
-
* ```typescript
|
|
239
|
-
* const messages = proxy(['msg1', 'msg2', 'msg3']);
|
|
240
|
-
* const update = { 1: 'updated msg2' }; // Update using object key as index
|
|
241
|
-
* merge(messages, update);
|
|
242
|
-
* console.log(messages); // proxy(['msg1', 'updated msg2', 'msg3'])
|
|
243
|
-
* ```
|
|
244
|
-
*
|
|
245
235
|
*/
|
|
246
236
|
export declare function merge<T extends object>(dst: T, value: Partial<T>): boolean;
|
|
247
237
|
export declare function merge<T extends object>(dst: T, dstKey: keyof T, value: Partial<T[typeof dstKey]>): boolean;
|
|
@@ -284,15 +274,16 @@ export declare const NO_COPY: unique symbol;
|
|
|
284
274
|
*/
|
|
285
275
|
export declare const cssVars: Record<string, string>;
|
|
286
276
|
/**
|
|
287
|
-
* Initializes `cssVars[
|
|
277
|
+
* Initializes `cssVars[0]` through `cssVars[12]` with an exponential spacing scale.
|
|
288
278
|
*
|
|
289
279
|
* The scale is calculated as `2^(n-3) * base`, providing values from `0.25 * base` to `512 * base`.
|
|
290
280
|
*
|
|
291
|
-
* @param base - The base size for the spacing scale
|
|
292
|
-
* @param unit - The CSS unit to use
|
|
281
|
+
* @param base - The base size for the spacing scale that will apply to `cssVars[3]`. Every step up the scale will double this, while every step down will halve it. Defaults to 1.
|
|
282
|
+
* @param unit - The CSS unit to use, like 'rem', 'em', or 'px'. Defaults to 'rem'.
|
|
293
283
|
*
|
|
294
284
|
* @example
|
|
295
285
|
* ```javascript
|
|
286
|
+
* import { setSpacingCssVars, cssVars, onEach, $} from 'aberdeen';
|
|
296
287
|
* // Use default scale (0.25rem to 512rem)
|
|
297
288
|
* setSpacingCssVars();
|
|
298
289
|
*
|
|
@@ -301,6 +292,11 @@ export declare const cssVars: Record<string, string>;
|
|
|
301
292
|
*
|
|
302
293
|
* // Use em units
|
|
303
294
|
* setSpacingCssVars(1, 'em'); // 0.25em to 512em
|
|
295
|
+
*
|
|
296
|
+
* // Show the last generated spacing values
|
|
297
|
+
* onEach(cssVars, (value, key) => {
|
|
298
|
+
* $(`div #${key} → ${value}`)
|
|
299
|
+
* }, (value, key) => parseInt(key)); // Numeric sort
|
|
304
300
|
* ```
|
|
305
301
|
*/
|
|
306
302
|
export declare function setSpacingCssVars(base?: number, unit?: string): void;
|
|
@@ -320,14 +316,11 @@ export declare function setSpacingCssVars(base?: number, unit?: string): void;
|
|
|
320
316
|
*
|
|
321
317
|
* // Reactively set colors based on browser preference
|
|
322
318
|
* $(() => {
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* cssVars.fg = '#e5e5e5';
|
|
326
|
-
* } else {
|
|
327
|
-
* cssVars.bg = '#ffffff';
|
|
328
|
-
* cssVars.fg = '#000000';
|
|
329
|
-
* }
|
|
319
|
+
* cssVars.bg = darkMode() ? '#1a1a1a' : '#ffffff';
|
|
320
|
+
* cssVars.fg = darkMode() ? '#e5e5e5' : '#000000';
|
|
330
321
|
* });
|
|
322
|
+
*
|
|
323
|
+
* $('div bg:$bg fg:$fg p:1rem #Colors change based on system dark mode preference');
|
|
331
324
|
* ```
|
|
332
325
|
*/
|
|
333
326
|
export declare function darkMode(): boolean;
|
|
@@ -375,38 +368,62 @@ export declare function ref<T extends TargetType, K extends keyof T>(target: T,
|
|
|
375
368
|
*
|
|
376
369
|
* @param {...(string | function | object | false | undefined | null)} args - Any number of arguments can be given. How they're interpreted depends on their types:
|
|
377
370
|
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
* -
|
|
387
|
-
*
|
|
388
|
-
* -
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
371
|
+
* ### String arguments
|
|
372
|
+
* Strings can be used to create and insert new elements, set classnames for the *current* element, and add text to the current element.
|
|
373
|
+
* The format of a string is: (**tag** | `.` **class** | **key**[=:]**val** | **key**[=:]"**val containing spaces**")* ('#' **text** | **key**[=:])?
|
|
374
|
+
*
|
|
375
|
+
* So a string may consist of any number of...
|
|
376
|
+
* - **tag** elements, like `h1` or `div`. These elements are created, added to the *current* element, and become the new *current* element for the rest of this `$` function execution.
|
|
377
|
+
* - CSS classes prefixed by `.` characters. These classes will be added to the *current* element. Optionally, CSS classes can be appended to a **tag** without a space. So both `div.myclass` and `div .myclass` are valid and do the same thing.
|
|
378
|
+
* - Property key/value pairs, like `type=password`, `placeholder="Your name"` or `data-id=123`. When the value contains spaces, it needs to be quoted with either "double quotes", 'single quotes' or \`backticks\`. Quotes within quoted values cannot be escaped (see the next rule for a solution). Key/value pairs will be handled according to *Property rules* below, but with the caveat that values can only be strings.
|
|
379
|
+
* - CSS key/value pairs using two syntaxes:
|
|
380
|
+
* - **Short form** `key:value` (no space after colon): The value ends at the next whitespace. Example: `m:$3 bg:red r:8px`
|
|
381
|
+
* - **Long form** `key: value;` (space after colon): The value continues until a semicolon. Example: `box-shadow: 2px 0 6px black; transition: all 0.3s ease;`
|
|
382
|
+
*
|
|
383
|
+
* Both forms support CSS shortcuts (see below). You can mix them: `m:$3 box-shadow: 0 2px 4px rgba(0,0,0,0.2); bg:$cardBg`
|
|
384
|
+
* The elements must be separated by spaces, except before a `.cssClass` if it is preceded by either **tag** or another CSS class.
|
|
385
|
+
*
|
|
386
|
+
* And a string may end in...
|
|
387
|
+
* - A '#' followed by text, which will be added as a `TextNode` to the *current* element. The text ranges til the end of the string, and may contain any characters, including spaces and quotes.
|
|
388
|
+
* - A key followed by an '=' character, in which case the value is expected as a separate argument. The key/value pair is set according to the *Property rules* below. This is useful when the value is not a string or contains spaces or user data. Example: `$('button text="Click me" click=', () => alert('Clicked!'))` or `$('input.value=', someUserData, "placeholder=", "Type your stuff")`. In case the value is a proxied object, its `.value` property will be applied reactively without needing to rerender the parent scope.
|
|
389
|
+
* - A key followed by a ':' character (with no value), in which case the value is expected as a separate argument. The value is treated as a CSS value to be set inline on the *current* element. Example: `$('div margin-top:', someValueInPx)`. In case the value is a proxied object, its `.value` property will be applied reactively without needing to rerender the parent scope.
|
|
390
|
+
*
|
|
391
|
+
* ### Function arguments
|
|
392
|
+
* When a function (without arguments nor a return value) is passed in, it will be reactively executed in its own observer scope, preserving the *current* element. So any `$()` invocations within this function will add child elements to or set properties on that element. If the function reads observable data, and that data is changed later on, the function we re-execute (after side effects, such as DOM modifications through `$`, have been cleaned - see also {@link clean}).
|
|
393
|
+
*
|
|
394
|
+
* ### Object arguments
|
|
395
|
+
* When an object is passed in, its key-value pairs are used to modify the *current* element according to the *Property rules* below, *unless* the key starts with a `$` character, in which case that character is stripped of and the key/value pair is treated as a CSS property, subject to the *CSS shortcuts* below. In case a value is a proxied object, its `.value` property will be applied reactively without needing to rerender the parent scope. In most cases, the string notation (`key=` and `key:`) is preferred over this object notation, for readability.
|
|
396
|
+
*
|
|
397
|
+
* ### DOM node arguments
|
|
398
|
+
* When a DOM Node (Element or TextNode) is passed in, it is added as a child to the *current* element. If the Node is an Element, it becomes the new *current* element for the rest of this `$` function execution.
|
|
399
|
+
*
|
|
400
|
+
* ### Property rules
|
|
401
|
+
* - **Attribute:** The common case is setting the value as an HTML attribute named key. For example `$('input placeholder=Name')` results in `<input placeholder="Name">`.
|
|
402
|
+
* - **Event listener:** If the value is a `function` it is set as an event listener for the event with the name given by the key. For example: $('button text=Press! click=', () => alert('Clicked!'))`. The event listener will be removed when the current scope is destroyed.
|
|
403
|
+
* - **DOM property:** When the value is a boolean, or the key is `"value"` or `"selectedIndex"`, it is set on the `current` element as a DOM property instead of an HTML attribute. For example `$('checked=', true)` would do `el.checked = true` for the *current* element.
|
|
404
|
+
* - **Conditional CSS class:** If the key starts with a `.` character, its either added to or removed from the *current* element as a CSS class, based on the truthiness of the value. So `$('.hidden=', isHidden)` would toggle the `hidden` CSS class. This only works if the `=` is the last character of the string, and the next argument is the value. Its common for the value to be a proxied object, in which case its `.value` is reactively applied without needing to rerender the parent scope.
|
|
405
|
+
* - **Create transition:** When the key is `"create"`, the value will be added as a CSS class to the *current* element immediately, and then removed right after the browser has finished doing a layout pass. This behavior only triggers when the scope setting the `create` is the top-level scope being (re-)run. This allows for creation transitions, without triggering the transitions for deeply nested elements being drawn as part of a larger component. The string may also contain multiple dot-separated CSS classes, such as `.fade.grow`. The initial dot is optional. Alternatively, to allow for more complex transitions, the value may be a function that receives the `HTMLElement` being created as its only argument. It is *only* called if this is the top-level element being created in this scope run. See `transitions.ts` in the Aberdeen source code for some examples.
|
|
406
|
+
* - **Destroy transition:** When the key is `"destroy"` the value will be used to apply a CSS transition if the *current* element is later on removed from the DOM and is the top-level element to be removed. This happens as follows: actual removal from the DOM is delayed by 2 seconds, and in the mean-time the value string is added as a CSS class to the element, allowing for a deletion transition. The string may also contain multiple dot-separated CSS classes, such as `.fade.shrink`. The initial dot is optional. Alternatively, to allow for more complex transitions, the value may be a function that receives the `HTMLElement` to be removed from the DOM as its only argument. This function may perform any transitions and is then itself responsible for eventually removing the element from the DOM. See `transitions.ts` in the Aberdeen source code for some examples.
|
|
407
|
+
* - **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`.
|
|
408
|
+
* - **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)`.
|
|
409
|
+
* - **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.
|
|
410
|
+
*
|
|
411
|
+
* ### CSS shortcuts
|
|
412
|
+
* For conciseness, Aberdeen supports some CSS shortcuts when setting CSS properties.
|
|
413
|
+
* | Shortcut | Expands to |
|
|
414
|
+
* |----------|------------|
|
|
415
|
+
* | `m`, `mt`, `mb`, `ml`, `mr` | `margin`, `margin-top`, `margin-bottom`, `margin-left`, `margin-right` |
|
|
416
|
+
* | `mv`, `mh` | Vertical (top+bottom) or horizontal (left+right) margins |
|
|
417
|
+
* | `p`, `pt`, `pb`, `pl`, `pr` | `padding`, `padding-top`, `padding-bottom`, `padding-left`, `padding-right` |
|
|
418
|
+
* | `pv`, `ph` | Vertical or horizontal padding |
|
|
419
|
+
* | `w`, `h` | `width`, `height` |
|
|
420
|
+
* | `bg` | `background` |
|
|
421
|
+
* | `fg` | `color` |
|
|
422
|
+
* | `r` | `border-radius` |
|
|
423
|
+
*
|
|
424
|
+
* Also, when the value is a string starting with `$`, it is treated as a reference to a CSS variable, expanding to `var(--variableName)`. For numeric variable names (which can't be used directly as CSS custom property names), Aberdeen prefixes them with `m`, so `$3` expands to `var(--m3)`. This is primarily intended for use with {@link setSpacingCssVars}, which initializes spacing variables named `0` through `12` with an exponential spacing scale.
|
|
425
|
+
*
|
|
426
|
+
* @returns The most inner DOM element that was created (not counting text nodes nor elements created by content functions), or the current element if no new element was created. You should normally not need to use the return value - use this function's DOM manipulation abilities instead. One valid use case is when integrating with non-Aberdeen code that requires a reference to a DOM element.
|
|
410
427
|
*
|
|
411
428
|
* @example Create Element
|
|
412
429
|
* ```typescript
|
|
@@ -453,71 +470,130 @@ export declare function ref<T extends TargetType, K extends keyof T>(target: T,
|
|
|
453
470
|
* }
|
|
454
471
|
* });
|
|
455
472
|
* ```
|
|
473
|
+
*
|
|
474
|
+
* @example Proxied objects as values
|
|
475
|
+
* ```typescript
|
|
476
|
+
* const myColor = proxy('red');
|
|
477
|
+
* $('p text="The color is " text=', myColor, 'click=', () => myColor.value = 'yellow')
|
|
478
|
+
* // Clicking the text will cause it to change color without recreating the <p> itself
|
|
479
|
+
* ```
|
|
480
|
+
* This is often used together with {@link ref}, in order to use properties other than `.value`.
|
|
456
481
|
*/
|
|
457
482
|
export declare function $(...args: any[]): undefined | Element;
|
|
458
483
|
/**
|
|
459
484
|
* Inserts CSS rules into the document, scoping them with a unique class name.
|
|
460
485
|
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
486
|
+
* The `style` parameter can be either:
|
|
487
|
+
* - A **concise style string** (for rules applying to the root class).
|
|
488
|
+
* - An **object** where keys are selectors (with `&` representing the root class)
|
|
489
|
+
* and values are concise style strings or nested objects. When the key does not contain `&`,
|
|
490
|
+
* it is treated as a descendant selector. So `{p: "color:red"}` becomes `".AbdStlX p { color: red; }"` with `AbdStlX` being the generated class name.
|
|
491
|
+
*
|
|
492
|
+
* ### Concise Style Strings
|
|
493
|
+
*
|
|
494
|
+
* Concise style strings use two syntaxes (same as inline CSS in {@link $}):
|
|
495
|
+
* - **Short form** `key:value` (no space after colon): The value ends at the next whitespace.
|
|
496
|
+
* Example: `'m:$3 bg:red r:8px'`
|
|
497
|
+
* - **Long form** `key: value;` (space after colon): The value continues until a semicolon.
|
|
498
|
+
* Example: `'box-shadow: 2px 0 6px black; transition: all 0.3s ease;'`
|
|
499
|
+
*
|
|
500
|
+
* Both forms can be mixed: `'m:$3 box-shadow: 0 2px 4px rgba(0,0,0,0.2); bg:$cardBg'`
|
|
463
501
|
*
|
|
464
|
-
*
|
|
465
|
-
* CSS properties or nested rule objects.
|
|
466
|
-
* - Selectors are usually combined as a descendant-relationship (meaning just a space character) with their parent selector.
|
|
467
|
-
* - In case a selector contains a `&`, that character will be replaced by the parent selector.
|
|
468
|
-
* - Selectors will be split on `,` characters, each combining with the parent selector with *or* semantics.
|
|
469
|
-
* - Selector starting with `'@'` define at-rules like media queries. They may be nested within regular selectors.
|
|
470
|
-
* @param global - Deprecated! Use {@link insertGlobalCss} instead.
|
|
471
|
-
* @returns The unique class name prefix used for scoping (e.g., `.AbdStl1`). Use this
|
|
472
|
-
* prefix with {@link $} to apply the styles.
|
|
502
|
+
* Supports the same CSS shortcuts as {@link $} and CSS variable references with `$` (e.g., `$primary`, `$3`).
|
|
473
503
|
*
|
|
474
|
-
* @
|
|
504
|
+
* @param style - A concise style string or a style object.
|
|
505
|
+
* @returns The unique class name prefix used for scoping (e.g., `.AbdStl1`).
|
|
506
|
+
* Use this prefix with {@link $} to apply the styles.
|
|
507
|
+
*
|
|
508
|
+
* @example Basic Usage with Shortcuts and CSS Variables
|
|
475
509
|
* ```typescript
|
|
476
|
-
* const
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
* '
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
510
|
+
* const cardClass = insertCss({
|
|
511
|
+
* '&': 'bg:white p:$4 r:8px transition: background-color 0.3s;',
|
|
512
|
+
* '&:hover': 'bg:#f5f5f5',
|
|
513
|
+
* });
|
|
514
|
+
*
|
|
515
|
+
* $('section', cardClass, () => {
|
|
516
|
+
* $('p#Card content');
|
|
517
|
+
* });
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
520
|
+
* @example Nested Selectors and Media Queries
|
|
521
|
+
* ```typescript
|
|
522
|
+
* const formClass = insertCss({
|
|
523
|
+
* '&': 'bg:#0004 p:$3 r:$2',
|
|
524
|
+
* button: {
|
|
525
|
+
* '&': 'bg:$primary fg:white p:$2 r:4px cursor:pointer',
|
|
526
|
+
* '&:hover': 'bg:$primaryHover',
|
|
527
|
+
* '&:disabled': 'bg:#ccc cursor:not-allowed',
|
|
528
|
+
* '.icon': 'display:inline-block mr:$1',
|
|
529
|
+
* '@media (max-width: 600px)': 'p:$1 font-size:14px'
|
|
487
530
|
* }
|
|
488
531
|
* });
|
|
489
|
-
* // scopeClass might be ".AbdStl1"
|
|
490
532
|
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
533
|
+
* $('form', formClass, () => {
|
|
534
|
+
* $('button', () => {
|
|
535
|
+
* $('span.icon text=🔥');
|
|
536
|
+
* $('#Click Me');
|
|
537
|
+
* });
|
|
495
538
|
* });
|
|
496
539
|
* ```
|
|
540
|
+
*
|
|
541
|
+
* @example Complex CSS Values
|
|
542
|
+
* ```typescript
|
|
543
|
+
* const badge = insertCss({
|
|
544
|
+
* '&::before': 'content: "★"; color:gold mr:$1',
|
|
545
|
+
* '&': 'position:relative box-shadow: 0 2px 8px rgba(0,0,0,0.15);'
|
|
546
|
+
* });
|
|
547
|
+
*
|
|
548
|
+
* $(badge + ' span#Product Name');
|
|
549
|
+
* ```
|
|
497
550
|
*/
|
|
498
|
-
export declare function insertCss(style:
|
|
551
|
+
export declare function insertCss(style: string | object): string;
|
|
499
552
|
/**
|
|
500
|
-
* Inserts CSS rules globally.
|
|
553
|
+
* Inserts CSS rules globally (unscoped).
|
|
501
554
|
*
|
|
502
555
|
* Works exactly like {@link insertCss}, but without prefixing selectors with a unique class name.
|
|
556
|
+
* This is useful for global resets, base styles, or styles that need to apply to the entire document.
|
|
557
|
+
*
|
|
558
|
+
* Accepts the same concise style string syntax and CSS shortcuts as {@link insertCss}.
|
|
559
|
+
* See {@link insertCss} for detailed documentation on syntax and shortcuts.
|
|
560
|
+
*
|
|
561
|
+
* @param style - Object with selectors as keys and concise CSS strings as values.
|
|
562
|
+
*
|
|
563
|
+
* @example Global Reset and Base Styles
|
|
564
|
+
* ```typescript
|
|
565
|
+
* // Set up global styles using CSS shortcuts
|
|
566
|
+
* insertGlobalCss({
|
|
567
|
+
* "*": "m:0 p:0 box-sizing:border-box",
|
|
568
|
+
* "body": "font-family: system-ui, sans-serif; m:0 p:$3 bg:#434 fg:#d0dafa",
|
|
569
|
+
* "a": "text-decoration:none fg:#57f",
|
|
570
|
+
* "a:hover": "text-decoration:underline",
|
|
571
|
+
* "code": "font-family:monospace bg:#222 fg:#afc p:4px r:3px"
|
|
572
|
+
* });
|
|
503
573
|
*
|
|
504
|
-
*
|
|
574
|
+
* $('h2#Title without margins');
|
|
575
|
+
* $('a#This is a link');
|
|
576
|
+
* $('code#const x = 42;');
|
|
577
|
+
* ```
|
|
578
|
+
*
|
|
579
|
+
* @example Responsive Global Styles
|
|
505
580
|
* ```typescript
|
|
506
581
|
* insertGlobalCss({
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
582
|
+
* "html": "font-size:16px",
|
|
583
|
+
* "body": "line-height:1.6",
|
|
584
|
+
* "h1, h2, h3": "font-weight:600 mt:$4 mb:$2",
|
|
585
|
+
* "@media (max-width: 768px)": {
|
|
586
|
+
* "html": "font-size:14px",
|
|
587
|
+
* "body": "p:$2"
|
|
510
588
|
* },
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
589
|
+
* "@media (prefers-color-scheme: dark)": {
|
|
590
|
+
* "body": "bg:#1a1a1a fg:#e5e5e5",
|
|
591
|
+
* "code": "bg:#2a2a2a"
|
|
514
592
|
* }
|
|
515
593
|
* });
|
|
516
|
-
*
|
|
517
|
-
* $('a#Styled link');
|
|
518
594
|
* ```
|
|
519
595
|
*/
|
|
520
|
-
export declare function insertGlobalCss(style: object):
|
|
596
|
+
export declare function insertGlobalCss(style: object): void;
|
|
521
597
|
/**
|
|
522
598
|
* Sets a custom error handler function for errors that occur asynchronously
|
|
523
599
|
* within reactive scopes (e.g., during updates triggered by proxy changes in
|
|
@@ -542,7 +618,7 @@ export declare function insertGlobalCss(style: object): string;
|
|
|
542
618
|
*
|
|
543
619
|
* try {
|
|
544
620
|
* // Attempt to show a custom message in the UI
|
|
545
|
-
* $('div
|
|
621
|
+
* $('div#Oops, something went wrong!', errorClass);
|
|
546
622
|
* } catch (e) {
|
|
547
623
|
* // Ignore errors during error handling itself
|
|
548
624
|
* }
|
|
@@ -551,15 +627,7 @@ export declare function insertGlobalCss(style: object): string;
|
|
|
551
627
|
* });
|
|
552
628
|
*
|
|
553
629
|
* // Styling for our custom error message
|
|
554
|
-
* insertCss(
|
|
555
|
-
* '.error-message': {
|
|
556
|
-
* backgroundColor: '#e31f00',
|
|
557
|
-
* display: 'inline-block',
|
|
558
|
-
* color: 'white',
|
|
559
|
-
* borderRadius: '3px',
|
|
560
|
-
* padding: '2px 4px',
|
|
561
|
-
* }
|
|
562
|
-
* }, true); // global style
|
|
630
|
+
* const errorClass = insertCss('background-color:#e31f00 display:inline-block color:white r:3px padding: 2px 4px;');
|
|
563
631
|
*
|
|
564
632
|
* // Cause an error within a render scope.
|
|
565
633
|
* $('div.box', () => {
|
|
@@ -569,31 +637,6 @@ export declare function insertGlobalCss(style: object): string;
|
|
|
569
637
|
* ```
|
|
570
638
|
*/
|
|
571
639
|
export declare function setErrorHandler(handler?: (error: Error) => boolean | undefined): void;
|
|
572
|
-
/**
|
|
573
|
-
* Gets the parent DOM `Element` where nodes created by {@link $} would currently be inserted.
|
|
574
|
-
*
|
|
575
|
-
* This is context-dependent based on the current reactive scope (e.g., inside a {@link mount}
|
|
576
|
-
* call or a {@link $} element's render function).
|
|
577
|
-
*
|
|
578
|
-
* **Note:** While this provides access to the DOM element, directly manipulating it outside
|
|
579
|
-
* of Aberdeen's control is generally discouraged. Prefer reactive updates using {@link $}.
|
|
580
|
-
*
|
|
581
|
-
* @returns The current parent `Element` for DOM insertion.
|
|
582
|
-
*
|
|
583
|
-
* @example Get parent for attaching a third-party library
|
|
584
|
-
* ```typescript
|
|
585
|
-
* function thirdPartyLibInit(parentElement) {
|
|
586
|
-
* parentElement.innerHTML = "This element is managed by a <em>third party</em> lib."
|
|
587
|
-
* }
|
|
588
|
-
*
|
|
589
|
-
* $('div.box', () => {
|
|
590
|
-
* // Get the div.box element just created
|
|
591
|
-
* const containerElement = getParentElement();
|
|
592
|
-
* thirdPartyLibInit(containerElement);
|
|
593
|
-
* });
|
|
594
|
-
* ```
|
|
595
|
-
*/
|
|
596
|
-
export declare function getParentElement(): Element;
|
|
597
640
|
/**
|
|
598
641
|
* Registers a cleanup function to be executed just before the current reactive scope
|
|
599
642
|
* is destroyed or redraws.
|
|
@@ -728,7 +771,8 @@ export declare function mount(parentElement: Element, func: () => void): void;
|
|
|
728
771
|
* Removes all Aberdeen-managed DOM nodes and stops all active reactive scopes
|
|
729
772
|
* (created by {@link mount}, {@link derive}, {@link $} with functions, etc.).
|
|
730
773
|
*
|
|
731
|
-
* This effectively cleans up the entire Aberdeen application state.
|
|
774
|
+
* This effectively cleans up the entire Aberdeen application state. Aside from in
|
|
775
|
+
* automated tests, there should probably be little reason to call this function.
|
|
732
776
|
*/
|
|
733
777
|
export declare function unmountAll(): void;
|
|
734
778
|
/**
|