@microsoft/fast-element 1.10.2 → 2.0.0-beta.3

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 (104) hide show
  1. package/.eslintrc.json +1 -12
  2. package/CHANGELOG.json +387 -1
  3. package/CHANGELOG.md +74 -2
  4. package/README.md +2 -2
  5. package/dist/dts/components/attributes.d.ts +4 -1
  6. package/dist/dts/components/controller.d.ts +12 -11
  7. package/dist/dts/components/fast-definitions.d.ts +10 -2
  8. package/dist/dts/components/fast-element.d.ts +12 -5
  9. package/dist/dts/context.d.ts +157 -0
  10. package/dist/dts/debug.d.ts +1 -0
  11. package/dist/dts/hooks.d.ts +20 -0
  12. package/dist/dts/index.d.ts +16 -15
  13. package/dist/dts/index.debug.d.ts +2 -0
  14. package/dist/dts/index.rollup.d.ts +2 -0
  15. package/dist/dts/index.rollup.debug.d.ts +3 -0
  16. package/dist/dts/interfaces.d.ts +145 -0
  17. package/dist/dts/metadata.d.ts +25 -0
  18. package/dist/dts/observation/arrays.d.ts +207 -0
  19. package/dist/dts/observation/behavior.d.ts +4 -4
  20. package/dist/dts/observation/notifier.d.ts +18 -18
  21. package/dist/dts/observation/observable.d.ts +56 -18
  22. package/dist/dts/observation/splice-strategies.d.ts +13 -0
  23. package/dist/dts/observation/update-queue.d.ts +40 -0
  24. package/dist/dts/platform.d.ts +18 -67
  25. package/dist/dts/polyfills.d.ts +8 -0
  26. package/dist/dts/styles/css-directive.d.ts +43 -5
  27. package/dist/dts/styles/css.d.ts +19 -3
  28. package/dist/dts/styles/element-styles.d.ts +42 -62
  29. package/dist/dts/templating/binding-signal.d.ts +38 -0
  30. package/dist/dts/templating/binding-two-way.d.ts +56 -0
  31. package/dist/dts/templating/binding.d.ts +233 -65
  32. package/dist/dts/templating/children.d.ts +18 -15
  33. package/dist/dts/templating/compiler.d.ts +46 -28
  34. package/dist/dts/templating/dom.d.ts +41 -0
  35. package/dist/dts/templating/html-directive.d.ts +181 -43
  36. package/dist/dts/templating/markup.d.ts +48 -0
  37. package/dist/dts/templating/node-observation.d.ts +45 -29
  38. package/dist/dts/templating/ref.d.ts +6 -12
  39. package/dist/dts/templating/repeat.d.ts +26 -14
  40. package/dist/dts/templating/slotted.d.ts +13 -14
  41. package/dist/dts/templating/template.d.ts +27 -21
  42. package/dist/dts/templating/view.d.ts +15 -22
  43. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
  44. package/dist/dts/utilities.d.ts +40 -0
  45. package/dist/esm/components/attributes.js +25 -24
  46. package/dist/esm/components/controller.js +77 -57
  47. package/dist/esm/components/fast-definitions.js +16 -22
  48. package/dist/esm/components/fast-element.js +10 -2
  49. package/dist/esm/context.js +159 -0
  50. package/dist/esm/debug.js +30 -0
  51. package/dist/esm/hooks.js +32 -0
  52. package/dist/esm/index.debug.js +2 -0
  53. package/dist/esm/index.js +19 -14
  54. package/dist/esm/index.rollup.debug.js +3 -0
  55. package/dist/esm/index.rollup.js +2 -0
  56. package/dist/esm/interfaces.js +8 -1
  57. package/dist/esm/metadata.js +60 -0
  58. package/dist/esm/observation/arrays.js +269 -0
  59. package/dist/esm/observation/notifier.js +27 -35
  60. package/dist/esm/observation/observable.js +93 -68
  61. package/dist/esm/observation/{array-change-records.js → splice-strategies.js} +136 -62
  62. package/dist/esm/observation/update-queue.js +67 -0
  63. package/dist/esm/platform.js +36 -42
  64. package/dist/esm/polyfills.js +85 -0
  65. package/dist/esm/styles/css-directive.js +29 -13
  66. package/dist/esm/styles/css.js +27 -40
  67. package/dist/esm/styles/element-styles.js +65 -104
  68. package/dist/esm/templating/binding-signal.js +84 -0
  69. package/dist/esm/templating/binding-two-way.js +82 -0
  70. package/dist/esm/templating/binding.js +306 -153
  71. package/dist/esm/templating/children.js +33 -23
  72. package/dist/esm/templating/compiler.js +236 -152
  73. package/dist/esm/templating/dom.js +49 -0
  74. package/dist/esm/templating/html-directive.js +128 -40
  75. package/dist/esm/templating/markup.js +75 -0
  76. package/dist/esm/templating/node-observation.js +50 -45
  77. package/dist/esm/templating/ref.js +7 -16
  78. package/dist/esm/templating/repeat.js +39 -36
  79. package/dist/esm/templating/slotted.js +23 -20
  80. package/dist/esm/templating/template.js +51 -95
  81. package/dist/esm/templating/view.js +44 -43
  82. package/dist/esm/templating/when.js +2 -1
  83. package/dist/esm/utilities.js +139 -0
  84. package/dist/fast-element.api.json +11789 -5377
  85. package/dist/fast-element.d.ts +1178 -530
  86. package/dist/fast-element.debug.js +3722 -0
  87. package/dist/fast-element.debug.min.js +1 -0
  88. package/dist/fast-element.js +3484 -4033
  89. package/dist/fast-element.min.js +1 -1
  90. package/dist/fast-element.untrimmed.d.ts +2699 -0
  91. package/docs/api-report.md +472 -219
  92. package/docs/fast-element-2-changes.md +15 -0
  93. package/docs/guide/declaring-templates.md +4 -4
  94. package/docs/guide/defining-elements.md +2 -2
  95. package/docs/guide/next-steps.md +2 -2
  96. package/docs/guide/observables-and-state.md +1 -1
  97. package/docs/guide/using-directives.md +1 -1
  98. package/karma.conf.cjs +6 -17
  99. package/package.json +63 -15
  100. package/dist/dts/dom.d.ts +0 -112
  101. package/dist/dts/observation/array-change-records.d.ts +0 -48
  102. package/dist/dts/observation/array-observer.d.ts +0 -9
  103. package/dist/esm/dom.js +0 -207
  104. package/dist/esm/observation/array-observer.js +0 -177
@@ -0,0 +1,15 @@
1
+ # Changes in FASTElement 2.0
2
+
3
+ ## Breaking Changes
4
+
5
+ * `HTMLDirective` - The `targetIndex: number` property has been replaced by a `targetId: string` property. The `createBehavior` method no longer takes a target `Node` but instead takes a `BehaviorTargets` instance. The actual target can be looked up on the `BehaviorTargets` instance by indexing with the `targetId` property.
6
+ * `compileTemplate()` - Internals have been significantly changed. The implementation no longer uses a TreeWalker. The return type has change to an `HTMLTemplateCompilationResult` with different properties.
7
+ * `View` and `HTMLView` - Type parameters added to enable strongly typed views based on their data source. The constructor of `HTMLView` has a new signature based on changes to the compiler's output. Internals have been cleaned up and no longer rely on the Range type.
8
+ * `ElementViewTemplate`, `SyntheticViewTemplate`, and `ViewTemplate` - Added type parameters throughout. Logic to instantiate and apply behaviors moved out of the template and into the view where it can be lazily executed. Removed the ability of the `render` method to take a string id of the node to render to. You must provide a node.
9
+ * `DOM` - Tree Walker methods are no longer used and are thus removed. The API for removing child nodes has been removed as well since it was only used in one place and could be inlined. The helper `createCustomAttributePlaceholder()` no longer requires an attribute name. It will be uniquely generated internally.
10
+ * `class` - Bindings to `class` are now more nuanced. Binding directly to `class` will simply set the `className` property. If you need to bind to `class` knowing that manual JS will also manipulate the `classList` in addition to the binding, then you should now bind to `:classList` instead. This allows for performance optimizations in the simple, most common case.
11
+ * `Behavior` and `ViewBehavior` - `Behavior` now requires an `ExecutionContext` for `unbind`. Behaviors can be used for elements or views. `ViewBehavior` has been introduced for use exclusively with views, and provides some optimization opportunities.
12
+ * `RefBehavior` has been replaced with `RefDirective`. The directive also implements `ViewBehavior` allowing a single directive instance to be shared across all template instances that use the ref.
13
+ * Removed `SlottedBehavior` and `ChildrenBehavior` have been replaced with `SlottedDirective` and `ChildrenDirective`. These directives allow a single directive instance to be shared across all template instances that use the ref.
14
+ * Removed `AttachedBehaviorHTMLDirective` and `AttachedBehaviorType` since they are no longer used in the new directive/behavior architecture for ref, slotted, and children.
15
+ * Renamed `Notifier#source` to `Notifier#subject` to align with other observable terminology and prevent name clashes with `BindingObserver` properties.
@@ -144,7 +144,7 @@ When binding to `class`, the underlying engine will not over-write classes added
144
144
 
145
145
  **Example: Nullish value**
146
146
 
147
- Some cases may occur where an attribute needs to have a value when used however not present if unused. These are different than boolean attributes by where their presence alone triggers their effect. In this situation a nullish value (`null` or `undefined`) may be provided so the attribute won't exist in that condition.
147
+ Some cases may occur where an attribute needs to have a value when used however not present if unused. These are different than boolean attributes by where their presence alone triggers their effect. In this situation, a nullish value (`null` or `undefined`) may be provided so the attribute won't exist in that condition.
148
148
 
149
149
  ```html
150
150
  <div aria-hidden="${x => x.isViewable ? 'true' : null}"></div>
@@ -218,13 +218,13 @@ The second example demonstrates an important characteristic of the templating en
218
218
  It is during the `connectedCallback` phase of the Custom Element lifecycle that `FASTElement` creates templates and binds the resulting view. The creation of the template only occurs the first time the element is connected, while binding happens every time the element is connected (with unbinding happening during the `disconnectedCallback` for symmetry).
219
219
 
220
220
  :::note
221
- In the future we're planning new optimizations that will enable us to safely determine when we do not need to unbind/rebind certain views.
221
+ In the future, we're planning new optimizations that will enable us to safely determine when we do not need to unbind/rebind certain views.
222
222
  :::
223
223
 
224
224
  In most cases, the template that `FASTElement` renders is determined by the `template` property of the Custom Element's configuration. However, you can also implement a method on your Custom Element class named `resolveTemplate()` that returns a template instance. If this method is present, it will be called during `connectedCallback` to obtain the template to use. This allows the element author to dynamically select completely different templates based on the state of the element at the time of connection.
225
225
 
226
- In addition to dynamic template selection during the `connectedCallback`, the `$fastController` property of `FASTElement` enables dynamically changing the template at any time through setting the controller's `template` property to any valid template.
226
+ In addition to dynamic template selection during the `connectedCallback`, the `$fastController` property of `FASTElement` enables dynamically changing the template at any time by setting the controller's `template` property to any valid template.
227
227
 
228
228
  :::tip
229
- Check out [our Cheat Sheet](/docs/resources/cheat-sheet#bindings) for a quick guide on bindings.
229
+ Check out [our Cheat Sheet](../resources/cheat-sheet.md#bindings) for a quick guide on bindings.
230
230
  :::
@@ -58,7 +58,7 @@ export class NameTag extends FASTElement {
58
58
  To add attributes to your HTML element, create properties decorated by the `@attr` decorator. All attributes defined this way will be automatically registered with the platform so that they can be updated through the browser's native `setAttribute` API as well as the property. You can optionally add a method with the naming convention *propertyName*Changed to your class (e.g. `greeting` and `greetingChanged()`), and this method will be called whenever your property changes, whether it changes through the property or the attribute API.
59
59
 
60
60
  :::note
61
- All properties decorated with `@attr` are also *observable*. See [observables and state](./observables-and-state) for information about how observables enable efficient rendering.
61
+ All properties decorated with `@attr` are also *observable*. See [observables and state](./observables-and-state.md) for information about how observables enable efficient rendering.
62
62
  :::
63
63
 
64
64
  By default, anything extending from `FASTElement` will automatically have a `ShadowRoot` attached in order to enable encapsulated rendering.
@@ -142,7 +142,7 @@ export class MyCounter extends FASTElement {
142
142
 
143
143
  ## The element lifecycle
144
144
 
145
- All Web Components support a series of lifecycle events that you can tap into to execute custom code at specific points in time. `FASTElement` implements several of these callbacks automatically in order to enable features of its templating engine (described in [declaring templates](./declaring-templates)). However, you can override them to provide your own code. Here's an example of how you would execute custom code when your element is inserted into the DOM.
145
+ All Web Components support a series of lifecycle events that you can tap into to execute custom code at specific points in time. `FASTElement` implements several of these callbacks automatically in order to enable features of its templating engine (described in [declaring templates](./declaring-templates.md)). However, you can override them to provide your own code. Here's an example of how you would execute custom code when your element is inserted into the DOM.
146
146
 
147
147
  **Example: Tapping into the Custom Element Lifecycle**
148
148
 
@@ -8,6 +8,6 @@ description: Now that you're familiar with the robust and powerful features of F
8
8
 
9
9
  We've seen how to use `FASTElement` to declaratively build Web Components. In addition to the basics of element and attribute definition, `FASTElement` also provides a way to declare templates capable of high-performance rendering, and efficient, incremental batched updates. Finally, CSS can easily be associated with an element in a way that leverages core platform optimizations for performance and low memory allocation.
10
10
 
11
- Now that you're familiar with the robust and powerful features of `FASTElement`, you're ready to build your own components and apps. But you don't have to start from scratch there either! If you haven't already explored them, check out our [FAST Components](../components/getting-started), which provide all the basic UI building-blocks you'd expect in a modern component library. You can also leverage the same adaptive design system that our own components use to enable robust theming throughout all you create. Read more on that in [Styling Components](/docs/design-systems/fast-frame#configuring-components). Finally, you'll want to take advantage of a modern toolset by installing [a powerful editor and plugins](../tools/vscode).
11
+ Now that you're familiar with the robust and powerful features of `FASTElement`, you're ready to build your own components and apps. But you don't have to start from scratch there either! If you haven't already explored them, check out our [FAST Components](../components/getting-started.md), which provide all the basic UI building-blocks you'd expect in a modern component library. You can also leverage the same adaptive design system that our own components use to enable robust theming throughout all you create. Read more on that in [Styling Components](../design-systems/fast-frame.md#configuring-components). Finally, you'll want to take advantage of a modern toolset by installing [a powerful editor and plugins](../tools/vscode.md).
12
12
 
13
- For a quick reference, check out [our Cheat Sheet](/docs/resources/cheat-sheet).
13
+ For a quick reference, check out [our Cheat Sheet](../resources/cheat-sheet.md).
@@ -123,7 +123,7 @@ export class Person {
123
123
 
124
124
  ### External observation
125
125
 
126
- Decorated properties can be subscribed to, to receive notification of changes in the property value. The templating engine uses this, but you can also directly subscribe as well. Here's how you would subscribe to changes in the `name` property of a `Person` class:
126
+ Decorated properties can be subscribed to, to receive notification of changes in the property value. The templating engine uses this, but you can also directly subscribe. Here's how you would subscribe to changes in the `name` property of a `Person` class:
127
127
 
128
128
  **Example: Subscribing to an Observable**
129
129
 
@@ -509,7 +509,7 @@ If using the `subtree` option for `children` then a `selector` is *required* in
509
509
 
510
510
  ### The `slotted` directive
511
511
 
512
- Sometimes you may want references to all nodes that are assigned to a particular slot. To accomplish this, use the `slotted` directive. (For more on slots, see [Working with Shadow DOM](./working-with-shadow-dom).)
512
+ Sometimes you may want references to all nodes that are assigned to a particular slot. To accomplish this, use the `slotted` directive. (For more on slots, see [Working with Shadow DOM](./working-with-shadow-dom.md).)
513
513
 
514
514
  ```ts
515
515
  import { FASTElement, customElement, html, slotted } from '@microsoft/fast-element';
package/karma.conf.cjs CHANGED
@@ -1,5 +1,4 @@
1
1
  const path = require("path");
2
-
3
2
  const basePath = path.resolve(__dirname);
4
3
 
5
4
  const commonChromeFlags = [
@@ -44,9 +43,9 @@ module.exports = function (config) {
44
43
  require("karma-chrome-launcher"),
45
44
  require("karma-firefox-launcher"),
46
45
  ],
47
- files: [`dist/esm/__test__/${setup}.js`],
46
+ files: [`dist/esm/__test__/${setup}.cjs`],
48
47
  preprocessors: {
49
- [`dist/esm/__test__/${setup}.js`]: ["webpack", "sourcemap"],
48
+ [`dist/esm/__test__/${setup}.cjs`]: ["webpack", "sourcemap"],
50
49
  },
51
50
  webpackMiddleware: {
52
51
  // webpack-dev-middleware configuration
@@ -54,7 +53,7 @@ module.exports = function (config) {
54
53
  stats: "errors-only",
55
54
  },
56
55
  webpack: {
57
- mode: "none",
56
+ mode: "development",
58
57
  resolve: {
59
58
  extensions: [".js"],
60
59
  modules: ["dist", "node_modules"],
@@ -65,12 +64,8 @@ module.exports = function (config) {
65
64
  hints: false,
66
65
  },
67
66
  optimization: {
68
- namedModules: false,
69
- namedChunks: false,
70
- nodeEnv: false,
71
67
  usedExports: true,
72
68
  flagIncludedChunks: false,
73
- occurrenceOrder: false,
74
69
  sideEffects: true,
75
70
  concatenateModules: true,
76
71
  splitChunks: {
@@ -89,14 +84,8 @@ module.exports = function (config) {
89
84
  },
90
85
  {
91
86
  test: /\.js$/,
92
- use: [
93
- {
94
- loader: "source-map-loader",
95
- options: {
96
- enforce: "pre",
97
- },
98
- },
99
- ],
87
+ use: ["source-map-loader"],
88
+ enforce: "pre",
100
89
  },
101
90
  ],
102
91
  },
@@ -125,7 +114,7 @@ module.exports = function (config) {
125
114
  timeout: 5000,
126
115
  },
127
116
  },
128
- logLevel: config.LOG_ERROR, // to disable the WARN 404 for image requests
117
+ logLevel: config.LOG_ERROR, // to disable the WARN 404 for image requests,
129
118
  };
130
119
 
131
120
  if (config.coverage) {
package/package.json CHANGED
@@ -1,24 +1,73 @@
1
1
  {
2
2
  "name": "@microsoft/fast-element",
3
3
  "description": "A library for constructing Web Components",
4
- "sideEffects": false,
5
- "version": "1.10.2",
4
+ "version": "2.0.0-beta.3",
6
5
  "author": {
7
6
  "name": "Microsoft",
8
7
  "url": "https://discord.gg/FcSNfg4"
9
8
  },
9
+ "homepage": "https://www.fast.design/",
10
10
  "license": "MIT",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/Microsoft/fast.git"
13
+ "url": "git+https://github.com/Microsoft/fast.git",
14
+ "directory": "packages/web-components/fast-element"
14
15
  },
15
16
  "bugs": {
16
17
  "url": "https://github.com/Microsoft/fast/issues/new/choose"
17
18
  },
18
- "main": "dist/esm/index.js",
19
- "types": "dist/fast-element.d.ts",
20
19
  "type": "module",
20
+ "main": "dist/esm/index.js",
21
+ "types": "dist/dts/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/dts/index.d.ts",
25
+ "production": "./dist/esm/index.js",
26
+ "development": "./dist/esm/index.debug.js",
27
+ "default": "./dist/esm/index.js"
28
+ },
29
+ "./polyfills": {
30
+ "types": "./dist/dts/polyfills.d.ts",
31
+ "default": "./dist/esm/polyfills.js"
32
+ },
33
+ "./debug": {
34
+ "types": "./dist/dts/debug.d.ts",
35
+ "default": "./dist/esm/debug.js"
36
+ },
37
+ "./observation/splice-strategies": {
38
+ "types": "./dist/dts/observation/splice-strategies.d.ts",
39
+ "default": "./dist/esm/observation/splice-strategies.js"
40
+ },
41
+ "./binding/two-way": {
42
+ "types": "./dist/dts/templating/binding-two-way.d.ts",
43
+ "default": "./dist/esm/templating/binding-two-way.js"
44
+ },
45
+ "./binding/signal": {
46
+ "types": "./dist/dts/templating/binding-signal.d.ts",
47
+ "default": "./dist/esm/templating/binding-signal.js"
48
+ },
49
+ "./utilities": {
50
+ "types": "./dist/dts/utilities.d.ts",
51
+ "default": "./dist/esm/utilities.js"
52
+ },
53
+ "./hooks": {
54
+ "types": "./dist/dts/hooks.d.ts",
55
+ "default": "./dist/esm/hooks.js"
56
+ },
57
+ "./context": {
58
+ "types": "./dist/dts/context.d.ts",
59
+ "default": "./dist/esm/context.js"
60
+ },
61
+ "./metadata": {
62
+ "types": "./dist/dts/metadata.d.ts",
63
+ "default": "./dist/esm/metadata.js"
64
+ }
65
+ },
21
66
  "unpkg": "dist/fast-element.min.js",
67
+ "sideEffects": [
68
+ "./dist/esm/debug.js",
69
+ "./dist/esm/polyfills.js"
70
+ ],
22
71
  "scripts": {
23
72
  "clean:dist": "node ../../../build/clean.js dist",
24
73
  "doc": "api-extractor run --local",
@@ -46,13 +95,12 @@
46
95
  "test-firefox:verbose": "karma start karma.conf.cjs --browsers=FirefoxHeadless --single-run --coverage --reporter=mocha"
47
96
  },
48
97
  "devDependencies": {
49
- "@microsoft/api-extractor": "7.23.1",
98
+ "@microsoft/api-extractor": "7.24.2",
50
99
  "@types/chai": "^4.2.11",
51
100
  "@types/chai-spies": "^1.0.3",
52
101
  "@types/karma": "^5.0.0",
53
102
  "@types/mocha": "^7.0.2",
54
103
  "@types/webpack-env": "^1.15.2",
55
- "@types/web-ie11": "^0.0.0",
56
104
  "chai": "^4.2.0",
57
105
  "chai-spies": "^1.0.0",
58
106
  "esm": "^3.2.25",
@@ -70,21 +118,21 @@
70
118
  "karma-mocha-reporter": "^2.2.5",
71
119
  "karma-source-map-support": "^1.4.0",
72
120
  "karma-sourcemap-loader": "^0.3.7",
73
- "karma-webpack": "^4.0.2",
121
+ "karma-webpack": "^5.0.0",
74
122
  "mocha": "^7.1.2",
75
123
  "prettier": "2.0.2",
76
- "rollup": "^2.7.6",
124
+ "rollup": "^2.71.1",
77
125
  "rollup-plugin-filesize": "^9.1.2",
78
- "rollup-plugin-terser": "^5.3.0",
79
- "rollup-plugin-transform-tagged-template": "^0.0.3",
80
- "rollup-plugin-typescript2": "^0.27.0",
126
+ "rollup-plugin-terser": "^7.0.2",
127
+ "@rollup/plugin-typescript": "^8.3.2",
81
128
  "source-map": "^0.7.3",
82
129
  "source-map-loader": "^0.2.4",
83
130
  "ts-loader": "^7.0.2",
84
131
  "ts-node": "^8.9.1",
85
132
  "tsconfig-paths": "^3.9.0",
86
- "tslib": "^1.11.1",
87
- "typescript": "^4.6.2",
88
- "webpack": "^4.44.0"
133
+ "tslib": "^2.4.0",
134
+ "typescript": "^4.7.0",
135
+ "webpack": "^5.72.0",
136
+ "webpack-cli": "^4.9.2"
89
137
  }
90
138
  }
package/dist/dts/dom.d.ts DELETED
@@ -1,112 +0,0 @@
1
- import type { Callable } from "./interfaces.js";
2
- import { TrustedTypesPolicy } from "./platform.js";
3
- /** @internal */
4
- export declare const _interpolationStart: string;
5
- /** @internal */
6
- export declare const _interpolationEnd: string;
7
- /**
8
- * Common DOM APIs.
9
- * @public
10
- */
11
- export declare const DOM: Readonly<{
12
- /**
13
- * Indicates whether the DOM supports the adoptedStyleSheets feature.
14
- */
15
- supportsAdoptedStyleSheets: boolean;
16
- /**
17
- * Sets the HTML trusted types policy used by the templating engine.
18
- * @param policy - The policy to set for HTML.
19
- * @remarks
20
- * This API can only be called once, for security reasons. It should be
21
- * called by the application developer at the start of their program.
22
- */
23
- setHTMLPolicy(policy: TrustedTypesPolicy): void;
24
- /**
25
- * Turns a string into trusted HTML using the configured trusted types policy.
26
- * @param html - The string to turn into trusted HTML.
27
- * @remarks
28
- * Used internally by the template engine when creating templates
29
- * and setting innerHTML.
30
- */
31
- createHTML(html: string): string;
32
- /**
33
- * Determines if the provided node is a template marker used by the runtime.
34
- * @param node - The node to test.
35
- */
36
- isMarker(node: Node): node is Comment;
37
- /**
38
- * Given a marker node, extract the {@link HTMLDirective} index from the placeholder.
39
- * @param node - The marker node to extract the index from.
40
- */
41
- extractDirectiveIndexFromMarker(node: Comment): number;
42
- /**
43
- * Creates a placeholder string suitable for marking out a location *within*
44
- * an attribute value or HTML content.
45
- * @param index - The directive index to create the placeholder for.
46
- * @remarks
47
- * Used internally by binding directives.
48
- */
49
- createInterpolationPlaceholder(index: number): string;
50
- /**
51
- * Creates a placeholder that manifests itself as an attribute on an
52
- * element.
53
- * @param attributeName - The name of the custom attribute.
54
- * @param index - The directive index to create the placeholder for.
55
- * @remarks
56
- * Used internally by attribute directives such as `ref`, `slotted`, and `children`.
57
- */
58
- createCustomAttributePlaceholder(attributeName: string, index: number): string;
59
- /**
60
- * Creates a placeholder that manifests itself as a marker within the DOM structure.
61
- * @param index - The directive index to create the placeholder for.
62
- * @remarks
63
- * Used internally by structural directives such as `repeat`.
64
- */
65
- createBlockPlaceholder(index: number): string;
66
- /**
67
- * Schedules DOM update work in the next async batch.
68
- * @param callable - The callable function or object to queue.
69
- */
70
- queueUpdate: (callable: Callable) => void;
71
- /**
72
- * Immediately processes all work previously scheduled
73
- * through queueUpdate.
74
- * @remarks
75
- * This also forces nextUpdate promises
76
- * to resolve.
77
- */
78
- processUpdates: () => void;
79
- /**
80
- * Resolves with the next DOM update.
81
- */
82
- nextUpdate(): Promise<void>;
83
- /**
84
- * Sets an attribute value on an element.
85
- * @param element - The element to set the attribute value on.
86
- * @param attributeName - The attribute name to set.
87
- * @param value - The value of the attribute to set.
88
- * @remarks
89
- * If the value is `null` or `undefined`, the attribute is removed, otherwise
90
- * it is set to the provided value using the standard `setAttribute` API.
91
- */
92
- setAttribute(element: HTMLElement, attributeName: string, value: any): void;
93
- /**
94
- * Sets a boolean attribute value.
95
- * @param element - The element to set the boolean attribute value on.
96
- * @param attributeName - The attribute name to set.
97
- * @param value - The value of the attribute to set.
98
- * @remarks
99
- * If the value is true, the attribute is added; otherwise it is removed.
100
- */
101
- setBooleanAttribute(element: HTMLElement, attributeName: string, value: boolean): void;
102
- /**
103
- * Removes all the child nodes of the provided parent node.
104
- * @param parent - The node to remove the children from.
105
- */
106
- removeChildNodes(parent: Node): void;
107
- /**
108
- * Creates a TreeWalker configured to walk a template fragment.
109
- * @param fragment - The fragment to walk.
110
- */
111
- createTemplateWalker(fragment: DocumentFragment): TreeWalker;
112
- }>;
@@ -1,48 +0,0 @@
1
- /**
2
- * Represents a set of splice-based changes against an Array.
3
- * @public
4
- */
5
- export interface Splice {
6
- /**
7
- * The index that the splice occurs at.
8
- */
9
- index: number;
10
- /**
11
- * The items that were removed.
12
- */
13
- removed: any[];
14
- /**
15
- * The number of items that were added.
16
- */
17
- addedCount: number;
18
- }
19
- /** @internal */
20
- export declare function newSplice(index: number, removed: any[], addedCount: number): Splice;
21
- /**
22
- * Splice Projection functions:
23
- *
24
- * A splice map is a representation of how a previous array of items
25
- * was transformed into a new array of items. Conceptually it is a list of
26
- * tuples of
27
- *
28
- * <index, removed, addedCount>
29
- *
30
- * which are kept in ascending index order of. The tuple represents that at
31
- * the |index|, |removed| sequence of items were removed, and counting forward
32
- * from |index|, |addedCount| items were added.
33
- */
34
- /**
35
- * @internal
36
- * @remarks
37
- * Lacking individual splice mutation information, the minimal set of
38
- * splices can be synthesized given the previous state and final state of an
39
- * array. The basic approach is to calculate the edit distance matrix and
40
- * choose the shortest path through it.
41
- *
42
- * Complexity: O(l * p)
43
- * l: The length of the current array
44
- * p: The length of the old array
45
- */
46
- export declare function calcSplices(current: any[], currentStart: number, currentEnd: number, old: any[], oldStart: number, oldEnd: number): ReadonlyArray<never> | Splice[];
47
- /** @internal */
48
- export declare function projectArraySplices(array: any[], changeRecords: any[]): Splice[];
@@ -1,9 +0,0 @@
1
- /**
2
- * Enables the array observation mechanism.
3
- * @remarks
4
- * Array observation is enabled automatically when using the
5
- * {@link RepeatDirective}, so calling this API manually is
6
- * not typically necessary.
7
- * @public
8
- */
9
- export declare function enableArrayObservation(): void;
package/dist/esm/dom.js DELETED
@@ -1,207 +0,0 @@
1
- import { $global } from "./platform.js";
2
- const updateQueue = $global.FAST.getById(1 /* updateQueue */, () => {
3
- const tasks = [];
4
- const pendingErrors = [];
5
- function throwFirstError() {
6
- if (pendingErrors.length) {
7
- throw pendingErrors.shift();
8
- }
9
- }
10
- function tryRunTask(task) {
11
- try {
12
- task.call();
13
- }
14
- catch (error) {
15
- pendingErrors.push(error);
16
- setTimeout(throwFirstError, 0);
17
- }
18
- }
19
- function process() {
20
- const capacity = 1024;
21
- let index = 0;
22
- while (index < tasks.length) {
23
- tryRunTask(tasks[index]);
24
- index++;
25
- // Prevent leaking memory for long chains of recursive calls to `DOM.queueUpdate`.
26
- // If we call `DOM.queueUpdate` within a task scheduled by `DOM.queueUpdate`, the queue will
27
- // grow, but to avoid an O(n) walk for every task we execute, we don't
28
- // shift tasks off the queue after they have been executed.
29
- // Instead, we periodically shift 1024 tasks off the queue.
30
- if (index > capacity) {
31
- // Manually shift all values starting at the index back to the
32
- // beginning of the queue.
33
- for (let scan = 0, newLength = tasks.length - index; scan < newLength; scan++) {
34
- tasks[scan] = tasks[scan + index];
35
- }
36
- tasks.length -= index;
37
- index = 0;
38
- }
39
- }
40
- tasks.length = 0;
41
- }
42
- function enqueue(callable) {
43
- if (tasks.length < 1) {
44
- $global.requestAnimationFrame(process);
45
- }
46
- tasks.push(callable);
47
- }
48
- return Object.freeze({
49
- enqueue,
50
- process,
51
- });
52
- });
53
- /* eslint-disable */
54
- const fastHTMLPolicy = $global.trustedTypes.createPolicy("fast-html", {
55
- createHTML: html => html,
56
- });
57
- /* eslint-enable */
58
- let htmlPolicy = fastHTMLPolicy;
59
- const marker = `fast-${Math.random().toString(36).substring(2, 8)}`;
60
- /** @internal */
61
- export const _interpolationStart = `${marker}{`;
62
- /** @internal */
63
- export const _interpolationEnd = `}${marker}`;
64
- /**
65
- * Common DOM APIs.
66
- * @public
67
- */
68
- export const DOM = Object.freeze({
69
- /**
70
- * Indicates whether the DOM supports the adoptedStyleSheets feature.
71
- */
72
- supportsAdoptedStyleSheets: Array.isArray(document.adoptedStyleSheets) &&
73
- "replace" in CSSStyleSheet.prototype,
74
- /**
75
- * Sets the HTML trusted types policy used by the templating engine.
76
- * @param policy - The policy to set for HTML.
77
- * @remarks
78
- * This API can only be called once, for security reasons. It should be
79
- * called by the application developer at the start of their program.
80
- */
81
- setHTMLPolicy(policy) {
82
- if (htmlPolicy !== fastHTMLPolicy) {
83
- throw new Error("The HTML policy can only be set once.");
84
- }
85
- htmlPolicy = policy;
86
- },
87
- /**
88
- * Turns a string into trusted HTML using the configured trusted types policy.
89
- * @param html - The string to turn into trusted HTML.
90
- * @remarks
91
- * Used internally by the template engine when creating templates
92
- * and setting innerHTML.
93
- */
94
- createHTML(html) {
95
- return htmlPolicy.createHTML(html);
96
- },
97
- /**
98
- * Determines if the provided node is a template marker used by the runtime.
99
- * @param node - The node to test.
100
- */
101
- isMarker(node) {
102
- return node && node.nodeType === 8 && node.data.startsWith(marker);
103
- },
104
- /**
105
- * Given a marker node, extract the {@link HTMLDirective} index from the placeholder.
106
- * @param node - The marker node to extract the index from.
107
- */
108
- extractDirectiveIndexFromMarker(node) {
109
- return parseInt(node.data.replace(`${marker}:`, ""));
110
- },
111
- /**
112
- * Creates a placeholder string suitable for marking out a location *within*
113
- * an attribute value or HTML content.
114
- * @param index - The directive index to create the placeholder for.
115
- * @remarks
116
- * Used internally by binding directives.
117
- */
118
- createInterpolationPlaceholder(index) {
119
- return `${_interpolationStart}${index}${_interpolationEnd}`;
120
- },
121
- /**
122
- * Creates a placeholder that manifests itself as an attribute on an
123
- * element.
124
- * @param attributeName - The name of the custom attribute.
125
- * @param index - The directive index to create the placeholder for.
126
- * @remarks
127
- * Used internally by attribute directives such as `ref`, `slotted`, and `children`.
128
- */
129
- createCustomAttributePlaceholder(attributeName, index) {
130
- return `${attributeName}="${this.createInterpolationPlaceholder(index)}"`;
131
- },
132
- /**
133
- * Creates a placeholder that manifests itself as a marker within the DOM structure.
134
- * @param index - The directive index to create the placeholder for.
135
- * @remarks
136
- * Used internally by structural directives such as `repeat`.
137
- */
138
- createBlockPlaceholder(index) {
139
- return `<!--${marker}:${index}-->`;
140
- },
141
- /**
142
- * Schedules DOM update work in the next async batch.
143
- * @param callable - The callable function or object to queue.
144
- */
145
- queueUpdate: updateQueue.enqueue,
146
- /**
147
- * Immediately processes all work previously scheduled
148
- * through queueUpdate.
149
- * @remarks
150
- * This also forces nextUpdate promises
151
- * to resolve.
152
- */
153
- processUpdates: updateQueue.process,
154
- /**
155
- * Resolves with the next DOM update.
156
- */
157
- nextUpdate() {
158
- return new Promise(updateQueue.enqueue);
159
- },
160
- /**
161
- * Sets an attribute value on an element.
162
- * @param element - The element to set the attribute value on.
163
- * @param attributeName - The attribute name to set.
164
- * @param value - The value of the attribute to set.
165
- * @remarks
166
- * If the value is `null` or `undefined`, the attribute is removed, otherwise
167
- * it is set to the provided value using the standard `setAttribute` API.
168
- */
169
- setAttribute(element, attributeName, value) {
170
- if (value === null || value === undefined) {
171
- element.removeAttribute(attributeName);
172
- }
173
- else {
174
- element.setAttribute(attributeName, value);
175
- }
176
- },
177
- /**
178
- * Sets a boolean attribute value.
179
- * @param element - The element to set the boolean attribute value on.
180
- * @param attributeName - The attribute name to set.
181
- * @param value - The value of the attribute to set.
182
- * @remarks
183
- * If the value is true, the attribute is added; otherwise it is removed.
184
- */
185
- setBooleanAttribute(element, attributeName, value) {
186
- value
187
- ? element.setAttribute(attributeName, "")
188
- : element.removeAttribute(attributeName);
189
- },
190
- /**
191
- * Removes all the child nodes of the provided parent node.
192
- * @param parent - The node to remove the children from.
193
- */
194
- removeChildNodes(parent) {
195
- for (let child = parent.firstChild; child !== null; child = parent.firstChild) {
196
- parent.removeChild(child);
197
- }
198
- },
199
- /**
200
- * Creates a TreeWalker configured to walk a template fragment.
201
- * @param fragment - The fragment to walk.
202
- */
203
- createTemplateWalker(fragment) {
204
- return document.createTreeWalker(fragment, 133, // element, text, comment
205
- null, false);
206
- },
207
- });