@microsoft/webui-framework 0.0.25 → 0.0.26

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 (53) hide show
  1. package/README.md +209 -53
  2. package/dist/component-asset/asset.d.ts +4 -2
  3. package/dist/component-asset/asset.js +19 -3
  4. package/dist/component-asset/generated-manifest.d.ts +1 -0
  5. package/dist/component-asset/generated-manifest.js +32 -0
  6. package/dist/component-asset/loader.d.ts +2 -1
  7. package/dist/component-asset/loader.js +98 -22
  8. package/dist/component-asset/manifest.d.ts +2 -1
  9. package/dist/component-asset.d.ts +1 -1
  10. package/dist/component-asset.js +12 -2
  11. package/dist/element/link-styles.d.ts +20 -0
  12. package/dist/element/link-styles.js +1030 -0
  13. package/dist/element/markers.d.ts +4 -0
  14. package/dist/element/markers.js +60 -5
  15. package/dist/element/styles.d.ts +39 -1
  16. package/dist/element/styles.js +623 -13
  17. package/dist/element/types.d.ts +5 -3
  18. package/dist/element.js +9 -1
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +1 -0
  21. package/dist/interaction-hydration.d.ts +8 -0
  22. package/dist/interaction-hydration.js +167 -0
  23. package/dist/static-host.js +43 -1
  24. package/dist/streaming-activation.d.ts +2 -2
  25. package/dist/streaming-activation.js +4 -2
  26. package/dist/streaming-bootstrap.d.ts +2 -2
  27. package/dist/streaming-bootstrap.js +7 -1
  28. package/dist/streaming-cleanup.d.ts +1 -0
  29. package/dist/streaming-cleanup.js +66 -14
  30. package/dist/streaming-coordinator.d.ts +3 -2
  31. package/dist/streaming-coordinator.js +107 -47
  32. package/dist/streaming-deferred.d.ts +14 -4
  33. package/dist/streaming-deferred.js +200 -87
  34. package/dist/streaming-dom.d.ts +12 -3
  35. package/dist/streaming-dom.js +41 -27
  36. package/dist/streaming-mode.d.ts +5 -0
  37. package/dist/streaming-mode.js +4 -0
  38. package/dist/streaming-protocol.d.ts +19 -3
  39. package/dist/streaming-protocol.js +4 -3
  40. package/dist/streaming-spans.d.ts +9 -0
  41. package/dist/streaming-spans.js +200 -0
  42. package/dist/template-content.d.ts +17 -0
  43. package/dist/template-content.js +106 -0
  44. package/dist/template-element.d.ts +17 -2
  45. package/dist/template-element.js +493 -177
  46. package/dist/template-events.d.ts +7 -0
  47. package/dist/template-events.js +7 -1
  48. package/dist/template-types.d.ts +1 -2
  49. package/dist/template.d.ts +7 -1
  50. package/dist/template.js +79 -16
  51. package/package.json +9 -3
  52. package/dist/component-asset/resources.d.ts +0 -4
  53. package/dist/component-asset/resources.js +0 -83
@@ -2,6 +2,9 @@ export declare const MARKER_REPEAT_START = "wr";
2
2
  export declare const MARKER_REPEAT_END = "/wr";
3
3
  export declare const MARKER_COND_START = "wc";
4
4
  export declare const MARKER_COND_END = "/wc";
5
+ export declare const MARKER_RAW_START = "w";
6
+ export declare const MARKER_RAW_END = "/w";
7
+ export declare function rawMarker(index: number, closing?: boolean): string;
5
8
  export declare function collectItemMarkers(repeatStart: Comment): {
6
9
  items: Comment[];
7
10
  end: Comment | null;
@@ -13,6 +16,7 @@ export interface SSRIndex {
13
16
  elements: Array<Node | undefined>;
14
17
  conds: Comment[];
15
18
  repeats: Comment[];
19
+ raws: Array<[Comment, Comment]>;
16
20
  }
17
21
  export declare function buildSSRIndex(tplRoot: Node, ssrRoot: Node, needMarkers: boolean, ssrIsSectionChild?: boolean): SSRIndex;
18
22
  export declare function findByOrdinal(parent: Node, nodeType: number, ordinal: number): Node | null;
@@ -1,8 +1,24 @@
1
+ import { isComponentStyleResourceMarker } from './styles.js';
1
2
  export const MARKER_REPEAT_START = 'wr';
2
3
  export const MARKER_REPEAT_END = '/wr';
3
4
  export const MARKER_COND_START = 'wc';
4
5
  export const MARKER_COND_END = '/wc';
6
+ export const MARKER_RAW_START = 'w';
7
+ export const MARKER_RAW_END = '/w';
5
8
  const MARKER_REPEAT_ITEM = 'wi';
9
+ export function rawMarker(index, closing = false) {
10
+ return `${closing ? MARKER_RAW_END : MARKER_RAW_START}${index}`;
11
+ }
12
+ function isRawStartMarker(data) {
13
+ if (data.length < 2 || data.charCodeAt(0) !== 119)
14
+ return false;
15
+ for (let i = 1; i < data.length; i++) {
16
+ const code = data.charCodeAt(i);
17
+ if (code < 48 || code > 57)
18
+ return false;
19
+ }
20
+ return true;
21
+ }
6
22
  export function collectItemMarkers(repeatStart) {
7
23
  const items = [];
8
24
  let end = null;
@@ -36,6 +52,10 @@ export function nextElement(marker) {
36
52
  return node;
37
53
  if (node.nodeType === 8) {
38
54
  const data = node.data;
55
+ if (isRawStartMarker(data)) {
56
+ node = skipBlockRange(node, data);
57
+ continue;
58
+ }
39
59
  if (data === MARKER_REPEAT_END || data === MARKER_REPEAT_ITEM || data === MARKER_COND_END)
40
60
  return null;
41
61
  }
@@ -44,7 +64,11 @@ export function nextElement(marker) {
44
64
  return null;
45
65
  }
46
66
  export function skipBlockRange(start, data) {
47
- const endTag = data === MARKER_COND_START ? MARKER_COND_END : MARKER_REPEAT_END;
67
+ const endTag = data === MARKER_COND_START
68
+ ? MARKER_COND_END
69
+ : isRawStartMarker(data)
70
+ ? `/${data}`
71
+ : MARKER_REPEAT_END;
48
72
  let depth = 1;
49
73
  let node = start.nextSibling;
50
74
  while (node && depth > 0) {
@@ -84,6 +108,7 @@ export function buildSSRIndex(tplRoot, ssrRoot, needMarkers, ssrIsSectionChild =
84
108
  const elements = [ssrIsSectionChild ? undefined : ssrRoot];
85
109
  const conds = [];
86
110
  const repeats = [];
111
+ const raws = [];
87
112
  const stack = [
88
113
  {
89
114
  t: tplRoot.firstChild,
@@ -109,9 +134,35 @@ export function buildSSRIndex(tplRoot, ssrRoot, needMarkers, ssrIsSectionChild =
109
134
  s = skipBlockRange(s, data);
110
135
  continue;
111
136
  }
137
+ if (isRawStartMarker(data)) {
138
+ const start = s;
139
+ let end = start.nextSibling;
140
+ let depth = 1;
141
+ const endMarker = `/${data}`;
142
+ while (end && depth > 0) {
143
+ if (end.nodeType === 8) {
144
+ const marker = end.data;
145
+ if (marker === data)
146
+ depth++;
147
+ else if (marker === endMarker)
148
+ depth--;
149
+ }
150
+ if (depth > 0)
151
+ end = end.nextSibling;
152
+ }
153
+ if (end) {
154
+ raws.push([start, end]);
155
+ s = end.nextSibling;
156
+ }
157
+ else {
158
+ s = null;
159
+ }
160
+ continue;
161
+ }
112
162
  }
113
163
  else if (type === 1) {
114
- break;
164
+ if (!isComponentStyleResourceMarker(s))
165
+ break;
115
166
  }
116
167
  s = s.nextSibling;
117
168
  }
@@ -135,7 +186,7 @@ export function buildSSRIndex(tplRoot, ssrRoot, needMarkers, ssrIsSectionChild =
135
186
  stack.push({ t: null, s: s.firstChild, solo: false });
136
187
  }
137
188
  }
138
- return { elements, conds, repeats };
189
+ return { elements, conds, repeats, raws };
139
190
  }
140
191
  export function findByOrdinal(parent, nodeType, ordinal) {
141
192
  let count = 0;
@@ -143,12 +194,16 @@ export function findByOrdinal(parent, nodeType, ordinal) {
143
194
  while (child) {
144
195
  if (child.nodeType === 8) {
145
196
  const data = child.data;
146
- if (data === MARKER_COND_START || data === MARKER_REPEAT_START) {
197
+ if (data === MARKER_COND_START
198
+ || data === MARKER_REPEAT_START
199
+ || isRawStartMarker(data)) {
147
200
  child = skipBlockRange(child, data);
148
201
  continue;
149
202
  }
150
203
  }
151
- if (child.nodeType === nodeType) {
204
+ const isStyleResource = child.nodeType === 1 &&
205
+ isComponentStyleResourceMarker(child);
206
+ if (child.nodeType === nodeType && !isStyleResource) {
152
207
  if (count === ordinal)
153
208
  return child;
154
209
  count++;
@@ -1 +1,39 @@
1
- export declare function injectModuleStyle(specifier: string, shadowRoot: ShadowRoot | null): void;
1
+ export type ComponentStyleResource = ({
2
+ kind: 'link';
3
+ href: string;
4
+ } | {
5
+ kind: 'style';
6
+ css: string;
7
+ } | {
8
+ kind: 'module';
9
+ specifier: string;
10
+ css: string;
11
+ }) & {
12
+ members?: string[];
13
+ };
14
+ export interface ComponentStyles {
15
+ version: 1;
16
+ strategy: 'link' | 'style' | 'module';
17
+ resources: Record<string, ComponentStyleResource>;
18
+ closures: Record<string, string[]>;
19
+ }
20
+ type StyleTarget = Document | ShadowRoot;
21
+ type CssModule = {
22
+ default: CSSStyleSheet;
23
+ };
24
+ type CssModuleLoader = (specifier: string) => Promise<CssModule>;
25
+ export declare function setCssModuleLoaderForTests(loader?: CssModuleLoader): void;
26
+ export declare function sameComponentStyleResource(current: ComponentStyleResource, next: ComponentStyleResource): boolean;
27
+ export declare function sameComponentStyleClosure(current: readonly string[], next: readonly string[]): boolean;
28
+ export declare function prepareComponentStyles(value: unknown): ComponentStyles | undefined;
29
+ export declare function requireComponentStyles(value: unknown): ComponentStyles;
30
+ export declare function validateComponentStylesRegistration(styles: ComponentStyles | undefined, document?: Document): void;
31
+ export declare function registerPreparedComponentStyles(styles: ComponentStyles, document?: Document): void;
32
+ export declare function registerComponentStyles(value: ComponentStyles | unknown, document?: Document): void;
33
+ export declare function hasRegisteredComponentStyleResource(id: string, document?: Document): boolean;
34
+ export declare function hasComponentStyleWork(rootId: string, document?: Document): boolean;
35
+ export declare function isComponentStyleMarker(element: Element): boolean;
36
+ export declare function isComponentStyleResourceMarker(element: Element): boolean;
37
+ export declare function claimSsrComponentStyles(source: Element, target: StyleTarget): void;
38
+ export declare function installComponentStyles(rootId: string, target: StyleTarget, host?: HTMLElement): Promise<void> | undefined;
39
+ export {};