@swiftwc/ui 0.0.0-dev.95 → 0.0.0-dev.96

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.
Files changed (45) hide show
  1. package/generated/client/index.js +7 -7
  2. package/generated/components/alert-dialog.d.ts +1 -1
  3. package/generated/components/alert-dialog.js +1 -1
  4. package/generated/components/content-unavailable.js +11 -11
  5. package/generated/components/date-picker.js +15 -15
  6. package/generated/components/fine-tooltip.js +2 -1
  7. package/generated/components/image-view.js +3 -2
  8. package/generated/components/label-view.d.ts +4 -0
  9. package/generated/components/label-view.js +11 -7
  10. package/generated/components/labeled-content.d.ts +5 -0
  11. package/generated/components/labeled-content.js +18 -12
  12. package/generated/components/menu-view.js +12 -12
  13. package/generated/components/navigation-title.js +2 -1
  14. package/generated/components/picker-view.d.ts +1 -1
  15. package/generated/components/picker-view.js +51 -50
  16. package/generated/components/progress-view.js +20 -19
  17. package/generated/components/scroll-view.js +14 -14
  18. package/generated/components/section-view.js +11 -11
  19. package/generated/components/table-view.js +34 -34
  20. package/generated/components/text-field.d.ts +2 -0
  21. package/generated/components/text-field.js +13 -11
  22. package/generated/components/toggle-view.js +30 -13
  23. package/generated/components/tool-bar.js +27 -27
  24. package/generated/internal/utils/cash/index.d.ts +4 -3
  25. package/generated/internal/utils/cash/index.js +4 -2
  26. package/generated/internal/utils/ensure-placeholder.js +2 -1
  27. package/generated/morphdom/index.d.ts +4 -2
  28. package/generated/morphdom/index.js +4 -2
  29. package/generated/morphdom/morph.d.ts +2 -2
  30. package/generated/morphdom/morph.js +3 -2
  31. package/generated/morphdom/query-morph.d.ts +2 -2
  32. package/generated/morphdom/query-morph.js +1 -1
  33. package/generated/morphdom/render-to-string.d.ts +12 -0
  34. package/generated/morphdom/render-to-string.js +48 -0
  35. package/generated/morphdom/unsafe-html.d.ts +2 -0
  36. package/generated/morphdom/unsafe-html.js +4 -0
  37. package/generated/tpl/html.js +4 -0
  38. package/generated/tpl/index.d.ts +2 -0
  39. package/generated/tpl/index.js +2 -0
  40. package/generated/tpl/is-template-result.d.ts +3 -0
  41. package/generated/tpl/is-template-result.js +1 -0
  42. package/package.json +1 -1
  43. package/web-components.html-data/en.json +64 -116
  44. package/generated/morphdom/html.d.ts +0 -8
  45. package/generated/morphdom/html.js +0 -37
@@ -2,8 +2,9 @@ var _a;
2
2
  import { CleanupRegistry } from '../internal/class/cleanup-registry';
3
3
  import { CSSStyleObserver } from '../internal/class/css-style-observer';
4
4
  import { $, devFlags } from '../internal/utils';
5
- import { html, queryMorph } from '../morphdom';
5
+ import { queryMorph } from '../morphdom';
6
6
  import { Snapshot } from '../snapshot';
7
+ import { html } from '../tpl';
7
8
  const progressViewStyles = ['circular', 'linear'];
8
9
  /**
9
10
  * @summary A view that shows how far along a task is.
@@ -28,27 +29,27 @@ export class ProgressView extends HTMLElement {
28
29
  if (!_a.#templates.has(this.progressViewStyle))
29
30
  switch (this.progressViewStyle) {
30
31
  case 'linear':
31
- _a.#templates.set(this.progressViewStyle, $(String.raw `
32
- <slot></slot>
33
- <div part="root progress-control progress-line-control"></div>
34
- <slot name="current-value"></slot>
32
+ _a.#templates.set(this.progressViewStyle, $(html `
33
+ <slot></slot>
34
+ <div part="root progress-control progress-line-control"></div>
35
+ <slot name="current-value"></slot>
35
36
  `));
36
37
  break;
37
38
  case 'circular':
38
39
  default:
39
- _a.#templates.set(this.progressViewStyle, $(String.raw `
40
- <div part="root progress-control progress-circular-control">
41
- <div part="root progress-control progress-circular-blade progress-circular-blade-1"></div>
42
- <div part="root progress-control progress-circular-blade progress-circular-blade-2"></div>
43
- <div part="root progress-control progress-circular-blade progress-circular-blade-3"></div>
44
- <div part="root progress-control progress-circular-blade progress-circular-blade-4"></div>
45
- <div part="root progress-control progress-circular-blade progress-circular-blade-5"></div>
46
- <div part="root progress-control progress-circular-blade progress-circular-blade-6"></div>
47
- <div part="root progress-control progress-circular-blade progress-circular-blade-7"></div>
48
- <div part="root progress-control progress-circular-blade progress-circular-blade-8"></div>
49
- </div>
50
- <slot></slot>
51
- <slot name="current-value"></slot>
40
+ _a.#templates.set(this.progressViewStyle, $(html `
41
+ <div part="root progress-control progress-circular-control">
42
+ <div part="root progress-control progress-circular-blade progress-circular-blade-1"></div>
43
+ <div part="root progress-control progress-circular-blade progress-circular-blade-2"></div>
44
+ <div part="root progress-control progress-circular-blade progress-circular-blade-3"></div>
45
+ <div part="root progress-control progress-circular-blade progress-circular-blade-4"></div>
46
+ <div part="root progress-control progress-circular-blade progress-circular-blade-5"></div>
47
+ <div part="root progress-control progress-circular-blade progress-circular-blade-6"></div>
48
+ <div part="root progress-control progress-circular-blade progress-circular-blade-7"></div>
49
+ <div part="root progress-control progress-circular-blade progress-circular-blade-8"></div>
50
+ </div>
51
+ <slot></slot>
52
+ <slot name="current-value"></slot>
52
53
  `));
53
54
  break;
54
55
  }
@@ -63,7 +64,7 @@ export class ProgressView extends HTMLElement {
63
64
  console.debug(`${_a.name} ⚡️ attr-change [${name}] ("${oldValue}" → "${newValue}")`);
64
65
  switch (name) {
65
66
  case 'label': {
66
- const label = this.querySelector(':scope>label-view:not([slot])') ?? this.appendChild($(`<label-view foreground="secondary"></label-view>`, '>1'));
67
+ const label = this.querySelector(':scope>label-view:not([slot])') ?? this.appendChild($(html `<label-view foreground="secondary"></label-view>`, '>1'));
67
68
  if (newValue) {
68
69
  label.setAttribute('title', newValue);
69
70
  }
@@ -3,7 +3,8 @@ import { lifecycleObserver } from '../buses';
3
3
  import { CleanupRegistry } from '../internal/class/cleanup-registry';
4
4
  import { ResizeObserverSingleton } from '../internal/class/resize-observer-singleton';
5
5
  import { $, devFlags, frame, onoff, slowHideShow } from '../internal/utils';
6
- import { html, queryMorph } from '../morphdom';
6
+ import { queryMorph } from '../morphdom';
7
+ import { html } from '../tpl';
7
8
  const observers = new ResizeObserverSingleton();
8
9
  /**
9
10
  * @summary A view that scrolls its content when it doesn’t fit the screen.
@@ -27,18 +28,17 @@ export class ScrollView extends HTMLElement {
27
28
  }
28
29
  static #template;
29
30
  static get template() {
30
- return (this.#template ??= $(String.raw `
31
- <slot></slot>
32
- <div part="root scroll-view-navbar">
33
- <div part="root scroll-view-navbar-stack">
34
- <slot name="top-bar-principal"></slot>
35
- </div>
36
- </div>
37
- <div part="root scroll-view-toolbar">
38
- <div part="root scroll-view-toolbar-stack">
39
- <slot name="bottom-bar-principal"></slot>
40
- </div>
41
- </div>`));
31
+ return (this.#template ??= $(html `<slot></slot>
32
+ <div part="root scroll-view-navbar">
33
+ <div part="root scroll-view-navbar-stack">
34
+ <slot name="top-bar-principal"></slot>
35
+ </div>
36
+ </div>
37
+ <div part="root scroll-view-toolbar">
38
+ <div part="root scroll-view-toolbar-stack">
39
+ <slot name="bottom-bar-principal"></slot>
40
+ </div>
41
+ </div>`));
42
42
  }
43
43
  #shadowRoot;
44
44
  #slots = new Map();
@@ -230,7 +230,7 @@ export class ScrollView extends HTMLElement {
230
230
  // const container = ((vs = this.querySelector<HTMLElement>(':scope>v-stack') ?? (this.appendChild($(`<v-stack></v-stack>`, '>1')) as HTMLElement)) =>
231
231
  // vs.querySelector<HTMLElement>(':scope>navigation-title:not([slot])') ??
232
232
  // vs.appendChild($(html`<navigation-title value="${title}" subtitle="${subtitle}" system-image="${icon}" padding></navigation-title>`.toString(), '>1')))()
233
- const container = this.querySelector(':scope>v-stack') ?? this.appendChild($(`<v-stack></v-stack>`, '>1'));
233
+ const container = this.querySelector(':scope>v-stack') ?? this.appendChild($(html `<v-stack></v-stack>`, '>1'));
234
234
  queryMorph('navigation-title:not([slot])', html `<navigation-title value="${title}" subtitle="${subtitle}" system-image="${icon}" padding></navigation-title>`, container);
235
235
  };
236
236
  }
@@ -1,5 +1,6 @@
1
1
  import { $, devFlags } from '../internal/utils';
2
- import { html, queryMorph } from '../morphdom';
2
+ import { queryMorph } from '../morphdom';
3
+ import { html } from '../tpl';
3
4
  /**
4
5
  * @summary A container view that groups related content together.
5
6
  *
@@ -13,16 +14,15 @@ export class SectionView extends HTMLElement {
13
14
  }
14
15
  static #template;
15
16
  static get template() {
16
- return (this.#template ??= $(String.raw `
17
- <div part="root section-main-stack">
18
- <slot></slot>
19
- </div>
20
- <div part="root section-header-stack">
21
- <slot name="header"></slot>
22
- </div>
23
- <div part="root section-footer-stack">
24
- <slot name="footer"></slot>
25
- </div>`));
17
+ return (this.#template ??= $(html `<div part="root section-main-stack">
18
+ <slot></slot>
19
+ </div>
20
+ <div part="root section-header-stack">
21
+ <slot name="header"></slot>
22
+ </div>
23
+ <div part="root section-footer-stack">
24
+ <slot name="footer"></slot>
25
+ </div>`));
26
26
  // <div class="sticky-sentinel" style="grid-area:sentinel;inline-size:100%;block-size:0.1px;pointer-events:none;"></div>
27
27
  }
28
28
  #shadowRoot;
@@ -3,8 +3,9 @@ import { CleanupRegistry } from '../internal/class/cleanup-registry';
3
3
  import { CSSStyleObserver } from '../internal/class/css-style-observer';
4
4
  import { MutationObserverSet } from '../internal/class/mutation-observer-set';
5
5
  import { $, devFlags, listActive, onoff } from '../internal/utils';
6
- import { html, queryMorph } from '../morphdom';
6
+ import { queryMorph } from '../morphdom';
7
7
  import { Snapshot } from '../snapshot';
8
+ import { html } from '../tpl';
8
9
  /**
9
10
  * @summary A container view that arranges data in rows and columns, optionally letting the user select one or more of them.
10
11
  *
@@ -24,35 +25,34 @@ export class TableView extends HTMLElement {
24
25
  #compactToolbarItem;
25
26
  static #template;
26
27
  static get template() {
27
- return (this.#template ??= $(String.raw `
28
- <div part="root table-container">
29
- <div part="root table-header-stack">
30
- <div part="root table-header-leading-stack">
31
- <slot name="header-leading"></slot>
28
+ return (this.#template ??= $(html `<div part="root table-container">
29
+ <div part="root table-header-stack">
30
+ <div part="root table-header-leading-stack">
31
+ <slot name="header-leading"></slot>
32
+ </div>
33
+ <div part="root table-header-principal-stack">
34
+ <slot name="header-principal"></slot>
35
+ </div>
36
+ <div part="root table-header-trailing-stack">
37
+ <slot name="header-trailing"></slot>
38
+ </div>
32
39
  </div>
33
- <div part="root table-header-principal-stack">
34
- <slot name="header-principal"></slot>
40
+ <div part="root table-column-stack">
41
+ <slot name="column"></slot>
35
42
  </div>
36
- <div part="root table-header-trailing-stack">
37
- <slot name="header-trailing"></slot>
43
+ <slot><p>empty</p></slot>
44
+ <div part="root table-footer-stack">
45
+ <div part="root table-footer-leading-stack">
46
+ <slot name="footer-leading"></slot>
47
+ </div>
48
+ <div part="root table-footer-principal-stack">
49
+ <slot name="footer-principal"></slot>
50
+ </div>
51
+ <div part="root table-footer-trailing-stack">
52
+ <slot name="footer-trailing"></slot>
53
+ </div>
38
54
  </div>
39
- </div>
40
- <div part="root table-column-stack">
41
- <slot name="column"></slot>
42
- </div>
43
- <slot><p>empty</p></slot>
44
- <div part="root table-footer-stack">
45
- <div part="root table-footer-leading-stack">
46
- <slot name="footer-leading"></slot>
47
- </div>
48
- <div part="root table-footer-principal-stack">
49
- <slot name="footer-principal"></slot>
50
- </div>
51
- <div part="root table-footer-trailing-stack">
52
- <slot name="footer-trailing"></slot>
53
- </div>
54
- </div>
55
- </div>`));
55
+ </div>`));
56
56
  }
57
57
  #shadowRoot;
58
58
  #slots = new Map();
@@ -102,7 +102,7 @@ export class TableView extends HTMLElement {
102
102
  if (devFlags.debug)
103
103
  console.debug(`${_a.name} ⚡️ mutation`);
104
104
  if (!this.#compactToolbarItem) {
105
- this.#compactToolbarItem = $(`<menu-view tabindex="0" slot="header-trailing"></menu-view>`, '>1');
105
+ this.#compactToolbarItem = $(html `<menu-view tabindex="0" slot="header-trailing"></menu-view>`, '>1');
106
106
  CleanupRegistry.unregister(this, 'compact_toolbar');
107
107
  CleanupRegistry.register(this, onoff('click', this.#handleMenuClick, this.#compactToolbarItem).on(), 'compact_toolbar');
108
108
  }
@@ -110,12 +110,12 @@ export class TableView extends HTMLElement {
110
110
  for (const node of this.#slots?.get('column')?.assignedElements({ flatten: true }) ?? []) {
111
111
  if (!node.matches('[is=table-column]'))
112
112
  continue;
113
- const btn = $(`<button type="button" tabindex="0">
114
- <v-stack spacing="0" alignment="leading">
115
- <label-view></label-view>
116
- <label-view font="callout" foreground="secondary"></label-view>
117
- </v-stack>
118
- </button>`, '>1'), title = btn.querySelector('label-view:first-child') ?? undefined, subTitle = btn.querySelector('label-view:last-child') ?? undefined;
113
+ const btn = $(html `<button type="button" tabindex="0">
114
+ <v-stack spacing="0" alignment="leading">
115
+ <label-view></label-view>
116
+ <label-view font="callout" foreground="secondary"></label-view>
117
+ </v-stack>
118
+ </button>`, '>1'), title = btn.querySelector('label-view:first-child') ?? undefined, subTitle = btn.querySelector('label-view:last-child') ?? undefined;
119
119
  queryMorph(':not([slot])', html `<span>${node.textContent.trim()}</span>`, title, { removeIf: !node.textContent.trim() });
120
120
  queryMorph(':not([slot])', html `<span>${node.ariaSort ?? ''}</span>`, subTitle, { removeIf: !(node.ariaSort ?? '') });
121
121
  this.#compactToolbarItem.appendChild(btn);
@@ -4,6 +4,8 @@ export type KeyboardType = (typeof keyboardTypes)[number];
4
4
  /**
5
5
  * @summary A control that displays an editable text area.
6
6
  *
7
+ * @fires {{ detail: { text: string } }} commit — Triggered when user interacts with the input area
8
+ *
7
9
  * @slot label
8
10
  * @slot validity-options
9
11
  */
@@ -4,11 +4,14 @@ import { CleanupRegistry } from '../internal/class/cleanup-registry';
4
4
  import { FormAssociatedBase, getInternals } from '../internal/class/form-associated-base';
5
5
  import { MutationObserverSet } from '../internal/class/mutation-observer-set';
6
6
  import { $, compareBigDecimals, devFlags, kebabCase, onoff, set } from '../internal/utils';
7
- import { html, queryMorph } from '../morphdom';
7
+ import { queryMorph } from '../morphdom';
8
+ import { html } from '../tpl';
8
9
  const keyboardTypes = ['decimal-pad', 'number-pad', 'default'];
9
10
  /**
10
11
  * @summary A control that displays an editable text area.
11
12
  *
13
+ * @fires {{ detail: { text: string } }} commit — Triggered when user interacts with the input area
14
+ *
12
15
  * @slot label
13
16
  * @slot validity-options
14
17
  */
@@ -44,16 +47,15 @@ export class TextField extends FormAssociatedBase {
44
47
  }
45
48
  static #template;
46
49
  static get template() {
47
- return (this.#template ??= $(String.raw `
48
- <label part="root text-field-stack">
49
- <div part="root text-field-label-stack">
50
- <slot name="label"></slot>
51
- </div>
52
- <div part="root text-field-input-stack">
53
- <input type="text" part="root input text-field-form-input">
54
- </div>
55
- <slot name="validity-options" hidden></slot>
56
- </label>`));
50
+ return (this.#template ??= $(html `<label part="root text-field-stack">
51
+ <div part="root text-field-label-stack">
52
+ <slot name="label"></slot>
53
+ </div>
54
+ <div part="root text-field-input-stack">
55
+ <input type="text" part="root input text-field-form-input" />
56
+ </div>
57
+ <slot name="validity-options" hidden></slot>
58
+ </label>`));
57
59
  }
58
60
  #renderValidityMsgs = (entries) => {
59
61
  if (devFlags.debug)
@@ -3,7 +3,8 @@ import { CleanupRegistry } from '../internal/class/cleanup-registry';
3
3
  import { FormAssociatedBase, getInternals } from '../internal/class/form-associated-base';
4
4
  import { MutationObserverSet } from '../internal/class/mutation-observer-set';
5
5
  import { $, devFlags, kebabCase, onoff } from '../internal/utils';
6
- import { html, queryMorph } from '../morphdom';
6
+ import { queryMorph } from '../morphdom';
7
+ import { html } from '../tpl';
7
8
  const toggleStyles = ['switch', 'button'];
8
9
  /**
9
10
  * @summary A control that switches between on and off states.
@@ -15,21 +16,37 @@ const toggleStyles = ['switch', 'button'];
15
16
  */
16
17
  export class ToggleView extends FormAssociatedBase {
17
18
  static get observedAttributes() {
18
- return ['label', 'name', 'value', 'is-on', 'keyboard-type', 'required', 'disabled'];
19
+ return [
20
+ 'label',
21
+ 'name',
22
+ 'value',
23
+ /**
24
+ * @type {boolean}
25
+ */
26
+ 'is-on',
27
+ 'keyboard-type',
28
+ /**
29
+ * @type {boolean}
30
+ */
31
+ 'required',
32
+ /**
33
+ * @type {boolean}
34
+ */
35
+ 'disabled',
36
+ ];
19
37
  }
20
38
  static #template;
21
39
  static get template() {
22
- return (this.#template ??= $(String.raw `
23
- <label part="root toggle-stack">
24
- <div part="root toggle-label-stack">
25
- <slot name="label"></slot>
26
- </div>
27
- <div part="root toggle-input-stack">
28
- <!--<input type="checkbox" part="root input toggle-form-input">-->
29
- <div part="root toggle-form-input" tabindex="0"></div>
30
- </div>
31
- <slot name="validity-options" hidden></slot>
32
- </label>`));
40
+ return (this.#template ??= $(html `<label part="root toggle-stack">
41
+ <div part="root toggle-label-stack">
42
+ <slot name="label"></slot>
43
+ </div>
44
+ <div part="root toggle-input-stack">
45
+ <!--<input type="checkbox" part="root input toggle-form-input">-->
46
+ <div part="root toggle-form-input" tabindex="0"></div>
47
+ </div>
48
+ <slot name="validity-options" hidden></slot>
49
+ </label>`));
33
50
  }
34
51
  #renderValidityMsgs = (entries) => {
35
52
  if (devFlags.debug)
@@ -1,6 +1,7 @@
1
1
  var _a;
2
2
  import { ResizeObserverSingleton } from '../internal/class/resize-observer-singleton';
3
3
  import { $, devFlags } from '../internal/utils';
4
+ import { html } from '../tpl';
4
5
  const observers = new ResizeObserverSingleton();
5
6
  /**
6
7
  * @summary A list of items placed into the toolbar or navigation bar around your content.
@@ -20,33 +21,32 @@ export class ToolBar extends HTMLElement {
20
21
  static #template;
21
22
  static get template() {
22
23
  // <!--exportparts="toolbar-leading-stack,toolbar-principal-stack,toolbar-trailing-stack"-->
23
- return (this.#template ??= $(String.raw `
24
- <div part="root top-bar">
25
- <div part="root toolbar-leading-stack">
26
- <slot name="cancellation-action"></slot>
27
- <slot name="destructive-action"></slot>
28
- <slot name="top-bar-leading"></slot>
29
- </div>
30
- <div part="root toolbar-principal-stack">
31
- <slot name="top-bar-principal"></slot>
32
- </div>
33
- <div part="root toolbar-trailing-stack">
34
- <slot name="top-bar-trailing"></slot>
35
- <slot name="primary-action"></slot>
36
- <slot name="confirmation-action"></slot>
37
- </div>
38
- </div>
39
- <div part="root bottom-bar">
40
- <div part="root toolbar-leading-stack">
41
- <slot name="bottom-bar-leading"></slot>
42
- </div>
43
- <div part="root toolbar-principal-stack">
44
- <slot name="bottom-bar-principal"></slot>
45
- </div>
46
- <div part="root toolbar-trailing-stack">
47
- <slot name="bottom-bar-trailing"></slot>
48
- </div>
49
- </div>`));
24
+ return (this.#template ??= $(html `<div part="root top-bar">
25
+ <div part="root toolbar-leading-stack">
26
+ <slot name="cancellation-action"></slot>
27
+ <slot name="destructive-action"></slot>
28
+ <slot name="top-bar-leading"></slot>
29
+ </div>
30
+ <div part="root toolbar-principal-stack">
31
+ <slot name="top-bar-principal"></slot>
32
+ </div>
33
+ <div part="root toolbar-trailing-stack">
34
+ <slot name="top-bar-trailing"></slot>
35
+ <slot name="primary-action"></slot>
36
+ <slot name="confirmation-action"></slot>
37
+ </div>
38
+ </div>
39
+ <div part="root bottom-bar">
40
+ <div part="root toolbar-leading-stack">
41
+ <slot name="bottom-bar-leading"></slot>
42
+ </div>
43
+ <div part="root toolbar-principal-stack">
44
+ <slot name="bottom-bar-principal"></slot>
45
+ </div>
46
+ <div part="root toolbar-trailing-stack">
47
+ <slot name="bottom-bar-trailing"></slot>
48
+ </div>
49
+ </div>`));
50
50
  }
51
51
  #shadowRoot;
52
52
  get #scrollView() {
@@ -1,3 +1,4 @@
1
+ import { type TemplateResult } from '../../../tpl';
1
2
  import ancestors from './ancestors';
2
3
  import next from './next';
3
4
  import nextAll from './next-all';
@@ -7,9 +8,9 @@ import prop from './prop';
7
8
  import siblings from './siblings';
8
9
  declare const DEFAULT: ">1";
9
10
  interface CashFn {
10
- (innerHTML: string): DocumentFragment;
11
- <T extends Element = Element>(innerHTML: string, selector: typeof DEFAULT): T;
12
- <T extends Element = Element>(innerHTML: string, selector: string): T;
11
+ (markup: TemplateResult): DocumentFragment;
12
+ <T extends Element = Element>(markup: TemplateResult, selector: typeof DEFAULT): T;
13
+ <T extends Element = Element>(markup: TemplateResult, selector: string): T;
13
14
  prop: typeof prop;
14
15
  nextAll: typeof nextAll;
15
16
  prevAll: typeof prevAll;
@@ -1,3 +1,4 @@
1
+ import { renderToString } from '../../../morphdom';
1
2
  import ancestors from './ancestors';
2
3
  import next from './next';
3
4
  import nextAll from './next-all';
@@ -6,8 +7,9 @@ import prevAll from './prev-all';
6
7
  import prop from './prop';
7
8
  import siblings from './siblings';
8
9
  const DEFAULT = '>1';
9
- const cash = ((innerHTML, selector) => {
10
- const template = Object.assign(document.createElement('template'), { innerHTML });
10
+ const cash = ((markup, selector) => {
11
+ // NOTE: Use also runtime check isTemplateResult()??
12
+ const template = Object.assign(document.createElement('template'), { innerHTML: renderToString(markup).toString() });
11
13
  if (!selector)
12
14
  return template.content;
13
15
  if (selector === DEFAULT)
@@ -1,5 +1,6 @@
1
1
  import { I18n } from '../../i18n';
2
- import { html, queryMorph } from '../../morphdom';
2
+ import { queryMorph } from '../../morphdom';
3
+ import { html } from '../../tpl';
3
4
  export default function (target, role, titleKey, config) {
4
5
  if (!target)
5
6
  return;
@@ -1,6 +1,8 @@
1
- export { default as html } from './html';
2
- export * from './html';
3
1
  export { default as morph } from './morph';
4
2
  export * from './morph';
5
3
  export { default as queryMorph } from './query-morph';
6
4
  export * from './query-morph';
5
+ export { default as renderToString } from './render-to-string';
6
+ export * from './render-to-string';
7
+ export { default as unsafeHtml } from './unsafe-html';
8
+ export * from './unsafe-html';
@@ -1,6 +1,8 @@
1
- export { default as html } from './html';
2
- export * from './html';
3
1
  export { default as morph } from './morph';
4
2
  export * from './morph';
5
3
  export { default as queryMorph } from './query-morph';
6
4
  export * from './query-morph';
5
+ export { default as renderToString } from './render-to-string';
6
+ export * from './render-to-string';
7
+ export { default as unsafeHtml } from './unsafe-html';
8
+ export * from './unsafe-html';
@@ -1,4 +1,4 @@
1
- import type { TrustedMarkup } from './html';
2
- export default function (template: TrustedMarkup, fromEl?: Element, options?: {
1
+ import type { TemplateResult } from '../tpl';
2
+ export default function (markup: TemplateResult, fromEl?: Element, options?: {
3
3
  cb: () => void;
4
4
  }): void;
@@ -1,8 +1,9 @@
1
1
  import morphdom from '../internal/vendor/morphdom';
2
- export default function (template, fromEl, options) {
2
+ import renderToString from './render-to-string';
3
+ export default function (markup, fromEl, options) {
3
4
  if (!fromEl)
4
5
  return;
5
- morphdom(fromEl, template.toString(), {
6
+ morphdom(fromEl, renderToString(markup).toString(), {
6
7
  onBeforeElUpdated: (fromEl, toEl) => !fromEl.isEqualNode(toEl),
7
8
  onBeforeElChildrenUpdated: (fromEl, toEl) => !toEl.matches('image-view,navigation-title'), // NOTE: image-view will alter it's contents! This is required to not empty it up again!
8
9
  });
@@ -1,5 +1,5 @@
1
- import type { TrustedMarkup } from './html';
2
- export default function (scopedSelector: string, template: TrustedMarkup, container?: Element, options?: {
1
+ import type { TemplateResult } from '../tpl';
2
+ export default function (scopedSelector: string, template: TemplateResult, container?: Element, options?: {
3
3
  cb?: () => boolean;
4
4
  removeIf?: boolean;
5
5
  }): void;
@@ -5,7 +5,7 @@ export default function (scopedSelector, template, container, options) {
5
5
  return;
6
6
  if ('boolean' === typeof options?.removeIf && options?.removeIf)
7
7
  return container?.querySelector(`:scope>${scopedSelector}`)?.remove();
8
- const fromEl = container?.querySelector(`:scope>${scopedSelector}`) ?? container?.appendChild($(template.toString(), '>1'));
8
+ const fromEl = container?.querySelector(`:scope>${scopedSelector}`) ?? container?.appendChild($(template, '>1'));
9
9
  if (!fromEl)
10
10
  return;
11
11
  morph(template, fromEl);
@@ -0,0 +1,12 @@
1
+ import { type TemplateResult } from '../tpl';
2
+ export declare class TrustedMarkup {
3
+ readonly value: string;
4
+ constructor(value: string);
5
+ toString(): string;
6
+ }
7
+ /**
8
+ * Flatten a TemplateResult (from `html`) into an escaped TrustedMarkup
9
+ * string. Use this only at morph/queryMorph call sites — anywhere feeding
10
+ * `render()` should keep passing the raw TemplateResult straight through.
11
+ */
12
+ export default function renderToString(template: TemplateResult): TrustedMarkup;
@@ -0,0 +1,48 @@
1
+ import { isTemplateResult } from '../tpl';
2
+ // morph.ts and queryMorph.ts only need something with `.toString()` that
3
+ // yields a safe, escaped HTML string — this is that, built on top of the
4
+ // same TemplateResult instead of a separate tag function.
5
+ // values built via `raw` itself are trusted markup; wrap them so `stringify`
6
+ // knows to skip escaping — same idea as lit-html's `unsafeHTML`
7
+ export class TrustedMarkup {
8
+ value;
9
+ constructor(value) {
10
+ this.value = value;
11
+ }
12
+ toString() {
13
+ return this.value;
14
+ }
15
+ }
16
+ const ESCAPE_MAP = {
17
+ '&': '&amp;',
18
+ '<': '&lt;',
19
+ '>': '&gt;',
20
+ '"': '&quot;',
21
+ "'": '&#39;',
22
+ };
23
+ function escapeHtml(str) {
24
+ return str.replace(/[&<>"']/g, (ch) => ESCAPE_MAP[ch]);
25
+ }
26
+ function stringifyValue(value) {
27
+ if (value === null || value === undefined || value === false)
28
+ return '';
29
+ if (value instanceof TrustedMarkup)
30
+ return value.value;
31
+ if (isTemplateResult(value))
32
+ return renderToString(value).value;
33
+ if (Array.isArray(value))
34
+ return value.map(stringifyValue).join('');
35
+ return escapeHtml(String(value));
36
+ }
37
+ /**
38
+ * Flatten a TemplateResult (from `html`) into an escaped TrustedMarkup
39
+ * string. Use this only at morph/queryMorph call sites — anywhere feeding
40
+ * `render()` should keep passing the raw TemplateResult straight through.
41
+ */
42
+ export default function renderToString(template) {
43
+ let out = template.strings[0];
44
+ for (let i = 0; i < template.values.length; i++) {
45
+ out += stringifyValue(template.values[i]) + template.strings[i + 1];
46
+ }
47
+ return new TrustedMarkup(out.replace(/>\s+</g, '><').trim());
48
+ }
@@ -0,0 +1,2 @@
1
+ import { TrustedMarkup } from './render-to-string';
2
+ export default function (value: string): TrustedMarkup;
@@ -0,0 +1,4 @@
1
+ import { TrustedMarkup } from './render-to-string';
2
+ export default function (value) {
3
+ return new TrustedMarkup(value);
4
+ }
@@ -1,3 +1,7 @@
1
+ // Purely structural — captures strings/values as-is. render.ts relies on
2
+ // `strings` identity (TemplateStringsArray) for its template cache, so this
3
+ // must stay exactly this shape: no wrapping, no cloning, no new object
4
+ // allocation beyond the literal { strings, values }.
1
5
  export default function (strings, ...values) {
2
6
  return { strings, values };
3
7
  }