@govtechsg/sgds-web-component 2.0.0-rc.1 → 2.0.0-rc.2

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 (78) hide show
  1. package/components/Accordion/accordion.cjs.js +1 -1
  2. package/components/Accordion/accordion.js +1 -1
  3. package/components/Accordion/index.umd.js +1 -1
  4. package/components/ActionCard/index.umd.js +1938 -1836
  5. package/components/ActionCard/index.umd.js.map +1 -1
  6. package/components/ActionCard/sgds-action-card.cjs.js +2 -2
  7. package/components/ActionCard/sgds-action-card.cjs.js.map +1 -1
  8. package/components/ActionCard/sgds-action-card.d.ts +1 -1
  9. package/components/ActionCard/sgds-action-card.js +1 -1
  10. package/components/ActionCard/sgds-action-card.js.map +1 -1
  11. package/components/Alert/index.umd.js +200 -98
  12. package/components/Alert/index.umd.js.map +1 -1
  13. package/components/Alert/sgds-alert.cjs.js +2 -2
  14. package/components/Alert/sgds-alert.cjs.js.map +1 -1
  15. package/components/Alert/sgds-alert.d.ts +1 -1
  16. package/components/Alert/sgds-alert.js +1 -1
  17. package/components/Alert/sgds-alert.js.map +1 -1
  18. package/components/ComboBox/index.umd.js +229 -127
  19. package/components/ComboBox/index.umd.js.map +1 -1
  20. package/components/ComboBox/sgds-combo-box.cjs.js +2 -2
  21. package/components/ComboBox/sgds-combo-box.cjs.js.map +1 -1
  22. package/components/ComboBox/sgds-combo-box.d.ts +1 -1
  23. package/components/ComboBox/sgds-combo-box.js +1 -1
  24. package/components/ComboBox/sgds-combo-box.js.map +1 -1
  25. package/components/Datepicker/index.umd.js +7836 -7734
  26. package/components/Datepicker/index.umd.js.map +1 -1
  27. package/components/Datepicker/sgds-datepicker.cjs.js +2 -2
  28. package/components/Datepicker/sgds-datepicker.cjs.js.map +1 -1
  29. package/components/Datepicker/sgds-datepicker.d.ts +1 -1
  30. package/components/Datepicker/sgds-datepicker.js +1 -1
  31. package/components/Datepicker/sgds-datepicker.js.map +1 -1
  32. package/components/Drawer/index.umd.js +200 -98
  33. package/components/Drawer/index.umd.js.map +1 -1
  34. package/components/Drawer/sgds-drawer.cjs.js +2 -2
  35. package/components/Drawer/sgds-drawer.cjs.js.map +1 -1
  36. package/components/Drawer/sgds-drawer.d.ts +1 -1
  37. package/components/Drawer/sgds-drawer.js +1 -1
  38. package/components/Drawer/sgds-drawer.js.map +1 -1
  39. package/components/Dropdown/index.umd.js +229 -127
  40. package/components/Dropdown/index.umd.js.map +1 -1
  41. package/components/Dropdown/sgds-dropdown.cjs.js +2 -2
  42. package/components/Dropdown/sgds-dropdown.cjs.js.map +1 -1
  43. package/components/Dropdown/sgds-dropdown.d.ts +1 -1
  44. package/components/Dropdown/sgds-dropdown.js +1 -1
  45. package/components/Dropdown/sgds-dropdown.js.map +1 -1
  46. package/components/FileUpload/index.umd.js +229 -127
  47. package/components/FileUpload/index.umd.js.map +1 -1
  48. package/components/FileUpload/sgds-file-upload.cjs.js +2 -2
  49. package/components/FileUpload/sgds-file-upload.cjs.js.map +1 -1
  50. package/components/FileUpload/sgds-file-upload.d.ts +1 -1
  51. package/components/FileUpload/sgds-file-upload.js +1 -1
  52. package/components/FileUpload/sgds-file-upload.js.map +1 -1
  53. package/components/Modal/index.umd.js +200 -98
  54. package/components/Modal/index.umd.js.map +1 -1
  55. package/components/Modal/sgds-modal.cjs.js +2 -2
  56. package/components/Modal/sgds-modal.cjs.js.map +1 -1
  57. package/components/Modal/sgds-modal.d.ts +1 -1
  58. package/components/Modal/sgds-modal.js +1 -1
  59. package/components/Modal/sgds-modal.js.map +1 -1
  60. package/components/QuantityToggle/index.umd.js +200 -98
  61. package/components/QuantityToggle/index.umd.js.map +1 -1
  62. package/components/QuantityToggle/sgds-quantity-toggle.cjs.js +2 -2
  63. package/components/QuantityToggle/sgds-quantity-toggle.cjs.js.map +1 -1
  64. package/components/QuantityToggle/sgds-quantity-toggle.d.ts +1 -1
  65. package/components/QuantityToggle/sgds-quantity-toggle.js +1 -1
  66. package/components/QuantityToggle/sgds-quantity-toggle.js.map +1 -1
  67. package/components/Toast/index.umd.js +1938 -1836
  68. package/components/Toast/index.umd.js.map +1 -1
  69. package/components/Toast/sgds-toast.cjs.js +2 -2
  70. package/components/Toast/sgds-toast.cjs.js.map +1 -1
  71. package/components/Toast/sgds-toast.d.ts +1 -1
  72. package/components/Toast/sgds-toast.js +1 -1
  73. package/components/Toast/sgds-toast.js.map +1 -1
  74. package/components/index.umd.js +201 -99
  75. package/components/index.umd.js.map +1 -1
  76. package/index.umd.js +201 -99
  77. package/index.umd.js.map +1 -1
  78. package/package.json +2 -2
@@ -37,12 +37,12 @@
37
37
  */
38
38
  const NODE_MODE = false;
39
39
  // Allows minifiers to rename references to globalThis
40
- const global$2 = globalThis;
40
+ const global$3 = globalThis;
41
41
  /**
42
42
  * Whether the current browser supports `adoptedStyleSheets`.
43
43
  */
44
- const supportsAdoptingStyleSheets = global$2.ShadowRoot &&
45
- (global$2.ShadyCSS === undefined || global$2.ShadyCSS.nativeShadow) &&
44
+ const supportsAdoptingStyleSheets$1 = global$3.ShadowRoot &&
45
+ (global$3.ShadyCSS === undefined || global$3.ShadyCSS.nativeShadow) &&
46
46
  'adoptedStyleSheets' in Document.prototype &&
47
47
  'replace' in CSSStyleSheet.prototype;
48
48
  const constructionToken = Symbol();
@@ -71,7 +71,7 @@
71
71
  // constructable.
72
72
  let styleSheet = this._styleSheet;
73
73
  const strings = this._strings;
74
- if (supportsAdoptingStyleSheets && styleSheet === undefined) {
74
+ if (supportsAdoptingStyleSheets$1 && styleSheet === undefined) {
75
75
  const cacheable = strings !== undefined && strings.length === 1;
76
76
  if (cacheable) {
77
77
  styleSheet = cssTagCache.get(strings);
@@ -134,15 +134,15 @@
134
134
  * will match spec behavior that gives adopted sheets precedence over styles in
135
135
  * shadowRoot.
136
136
  */
137
- const adoptStyles = (renderRoot, styles) => {
138
- if (supportsAdoptingStyleSheets) {
137
+ const adoptStyles$1 = (renderRoot, styles) => {
138
+ if (supportsAdoptingStyleSheets$1) {
139
139
  renderRoot.adoptedStyleSheets = styles.map((s) => s instanceof CSSStyleSheet ? s : s.styleSheet);
140
140
  }
141
141
  else {
142
142
  for (const s of styles) {
143
143
  const style = document.createElement('style');
144
144
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
- const nonce = global$2['litNonce'];
145
+ const nonce = global$3['litNonce'];
146
146
  if (nonce !== undefined) {
147
147
  style.setAttribute('nonce', nonce);
148
148
  }
@@ -158,7 +158,7 @@
158
158
  }
159
159
  return unsafeCSS(cssText);
160
160
  };
161
- const getCompatibleStyle = supportsAdoptingStyleSheets ||
161
+ const getCompatibleStyle = supportsAdoptingStyleSheets$1 ||
162
162
  (NODE_MODE )
163
163
  ? (s) => s
164
164
  : (s) => s instanceof CSSStyleSheet ? cssResultFromStyleSheet(s) : s;
@@ -171,9 +171,9 @@
171
171
  // TODO (justinfagnani): Add `hasOwn` here when we ship ES2022
172
172
  const { is, defineProperty, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, } = Object;
173
173
  // Lets a minifier replace globalThis references with a minified name
174
- const global$1 = globalThis;
174
+ const global$2 = globalThis;
175
175
  let issueWarning$4;
176
- const trustedTypes$1 = global$1
176
+ const trustedTypes$1 = global$2
177
177
  .trustedTypes;
178
178
  // Temporary workaround for https://crbug.com/993268
179
179
  // Currently, any attribute starting with "on" is considered to be a
@@ -182,12 +182,12 @@
182
182
  const emptyStringForBooleanAttribute = trustedTypes$1
183
183
  ? trustedTypes$1.emptyScript
184
184
  : '';
185
- const polyfillSupport$2 = global$1.reactiveElementPolyfillSupportDevMode
185
+ const polyfillSupport$2 = global$2.reactiveElementPolyfillSupportDevMode
186
186
  ;
187
187
  {
188
188
  // Ensure warnings are issued only 1x, even if multiple versions of Lit
189
189
  // are loaded.
190
- const issuedWarnings = (global$1.litIssuedWarnings ??=
190
+ const issuedWarnings = (global$2.litIssuedWarnings ??=
191
191
  new Set());
192
192
  // Issue a warning, if we haven't already.
193
193
  issueWarning$4 = (code, warning) => {
@@ -199,7 +199,7 @@
199
199
  };
200
200
  issueWarning$4('dev-mode', `Lit is in dev mode. Not recommended for production!`);
201
201
  // Issue polyfill support warning.
202
- if (global$1.ShadyDOM?.inUse && polyfillSupport$2 === undefined) {
202
+ if (global$2.ShadyDOM?.inUse && polyfillSupport$2 === undefined) {
203
203
  issueWarning$4('polyfill-support-missing', `Shadow DOM is being polyfilled via \`ShadyDOM\` but ` +
204
204
  `the \`polyfill-support\` module has not been loaded.`);
205
205
  }
@@ -210,12 +210,12 @@
210
210
  * Compiled out of prod mode builds.
211
211
  */
212
212
  const debugLogEvent$1 = (event) => {
213
- const shouldEmit = global$1
213
+ const shouldEmit = global$2
214
214
  .emitLitDebugLogEvents;
215
215
  if (!shouldEmit) {
216
216
  return;
217
217
  }
218
- global$1.dispatchEvent(new CustomEvent('lit-debug', {
218
+ global$2.dispatchEvent(new CustomEvent('lit-debug', {
219
219
  detail: event,
220
220
  }));
221
221
  }
@@ -287,7 +287,7 @@
287
287
  // Map from a class's metadata object to property options
288
288
  // Note that we must use nullish-coalescing assignment so that we only use one
289
289
  // map even if we load multiple version of this module.
290
- global$1.litPropertyMetadata ??= new WeakMap();
290
+ global$2.litPropertyMetadata ??= new WeakMap();
291
291
  /**
292
292
  * Base element class which manages element properties and attributes. When
293
293
  * properties change, the `update` method is asynchronously called. This method
@@ -707,7 +707,7 @@
707
707
  createRenderRoot() {
708
708
  const renderRoot = this.shadowRoot ??
709
709
  this.attachShadow(this.constructor.shadowRootOptions);
710
- adoptStyles(renderRoot, this.constructor.elementStyles);
710
+ adoptStyles$1(renderRoot, this.constructor.elementStyles);
711
711
  return renderRoot;
712
712
  }
713
713
  /**
@@ -1214,8 +1214,8 @@
1214
1214
  }
1215
1215
  // IMPORTANT: do not change the property name or the assignment expression.
1216
1216
  // This line will be used in regexes to search for ReactiveElement usage.
1217
- (global$1.reactiveElementVersions ??= []).push('2.0.4');
1218
- if (global$1.reactiveElementVersions.length > 1) {
1217
+ (global$2.reactiveElementVersions ??= []).push('2.0.4');
1218
+ if (global$2.reactiveElementVersions.length > 1) {
1219
1219
  issueWarning$4('multiple-versions', `Multiple versions of Lit loaded. Loading multiple versions ` +
1220
1220
  `is not recommended.`);
1221
1221
  }
@@ -1500,19 +1500,19 @@
1500
1500
  * SPDX-License-Identifier: BSD-3-Clause
1501
1501
  */
1502
1502
  // Allows minifiers to rename references to globalThis
1503
- const global = globalThis;
1503
+ const global$1 = globalThis;
1504
1504
  /**
1505
1505
  * Useful for visualizing and logging insights into what the Lit template system is doing.
1506
1506
  *
1507
1507
  * Compiled out of prod mode builds.
1508
1508
  */
1509
1509
  const debugLogEvent = (event) => {
1510
- const shouldEmit = global
1510
+ const shouldEmit = global$1
1511
1511
  .emitLitDebugLogEvents;
1512
1512
  if (!shouldEmit) {
1513
1513
  return;
1514
1514
  }
1515
- global.dispatchEvent(new CustomEvent('lit-debug', {
1515
+ global$1.dispatchEvent(new CustomEvent('lit-debug', {
1516
1516
  detail: event,
1517
1517
  }));
1518
1518
  }
@@ -1523,24 +1523,24 @@
1523
1523
  let debugLogRenderId = 0;
1524
1524
  let issueWarning$1;
1525
1525
  {
1526
- global.litIssuedWarnings ??= new Set();
1526
+ global$1.litIssuedWarnings ??= new Set();
1527
1527
  // Issue a warning, if we haven't already.
1528
1528
  issueWarning$1 = (code, warning) => {
1529
1529
  warning += code
1530
1530
  ? ` See https://lit.dev/msg/${code} for more information.`
1531
1531
  : '';
1532
- if (!global.litIssuedWarnings.has(warning)) {
1532
+ if (!global$1.litIssuedWarnings.has(warning)) {
1533
1533
  console.warn(warning);
1534
- global.litIssuedWarnings.add(warning);
1534
+ global$1.litIssuedWarnings.add(warning);
1535
1535
  }
1536
1536
  };
1537
1537
  issueWarning$1('dev-mode', `Lit is in dev mode. Not recommended for production!`);
1538
1538
  }
1539
- const wrap = global.ShadyDOM?.inUse &&
1540
- global.ShadyDOM?.noPatch === true
1541
- ? global.ShadyDOM.wrap
1539
+ const wrap = global$1.ShadyDOM?.inUse &&
1540
+ global$1.ShadyDOM?.noPatch === true
1541
+ ? global$1.ShadyDOM.wrap
1542
1542
  : (node) => node;
1543
- const trustedTypes = global.trustedTypes;
1543
+ const trustedTypes = global$1.trustedTypes;
1544
1544
  /**
1545
1545
  * Our TrustedTypePolicy for HTML which is declared using the html template
1546
1546
  * tag function.
@@ -2801,13 +2801,13 @@
2801
2801
  }
2802
2802
  }
2803
2803
  // Apply polyfills if available
2804
- const polyfillSupport$1 = global.litHtmlPolyfillSupportDevMode
2804
+ const polyfillSupport$1 = global$1.litHtmlPolyfillSupportDevMode
2805
2805
  ;
2806
2806
  polyfillSupport$1?.(Template, ChildPart);
2807
2807
  // IMPORTANT: do not change the property name or the assignment expression.
2808
2808
  // This line will be used in regexes to search for lit-html usage.
2809
- (global.litHtmlVersions ??= []).push('3.1.4');
2810
- if (global.litHtmlVersions.length > 1) {
2809
+ (global$1.litHtmlVersions ??= []).push('3.1.4');
2810
+ if (global$1.litHtmlVersions.length > 1) {
2811
2811
  issueWarning$1('multiple-versions', `Multiple versions of Lit loaded. ` +
2812
2812
  `Loading multiple versions is not recommended.`);
2813
2813
  }
@@ -3779,45 +3779,120 @@
3779
3779
  }
3780
3780
 
3781
3781
  /**
3782
- * @typedef {import('./types.js').ScopedElementsHost} ScopedElementsHost
3783
- * @typedef {import('./types.js').ScopedElementsMap} ScopedElementsMap
3782
+ * @license
3783
+ * Copyright 2019 Google LLC
3784
+ * SPDX-License-Identifier: BSD-3-Clause
3785
+ */
3786
+ const global = window;
3787
+ /**
3788
+ * Whether the current browser supports `adoptedStyleSheets`.
3789
+ */
3790
+ const supportsAdoptingStyleSheets = global.ShadowRoot &&
3791
+ (global.ShadyCSS === undefined || global.ShadyCSS.nativeShadow) &&
3792
+ 'adoptedStyleSheets' in Document.prototype &&
3793
+ 'replace' in CSSStyleSheet.prototype;
3794
+ /**
3795
+ * Applies the given styles to a `shadowRoot`. When Shadow DOM is
3796
+ * available but `adoptedStyleSheets` is not, styles are appended to the
3797
+ * `shadowRoot` to [mimic spec behavior](https://wicg.github.io/construct-stylesheets/#using-constructed-stylesheets).
3798
+ * Note, when shimming is used, any styles that are subsequently placed into
3799
+ * the shadowRoot should be placed *before* any shimmed adopted styles. This
3800
+ * will match spec behavior that gives adopted sheets precedence over styles in
3801
+ * shadowRoot.
3802
+ */
3803
+ const adoptStyles = (renderRoot, styles) => {
3804
+ if (supportsAdoptingStyleSheets) {
3805
+ renderRoot.adoptedStyleSheets = styles.map((s) => s instanceof CSSStyleSheet ? s : s.styleSheet);
3806
+ }
3807
+ else {
3808
+ styles.forEach((s) => {
3809
+ const style = document.createElement('style');
3810
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3811
+ const nonce = global['litNonce'];
3812
+ if (nonce !== undefined) {
3813
+ style.setAttribute('nonce', nonce);
3814
+ }
3815
+ style.textContent = s.cssText;
3816
+ renderRoot.appendChild(style);
3817
+ });
3818
+ }
3819
+ };
3820
+
3821
+ /**
3822
+ * @typedef {import('./types').RenderOptions} RenderOptions
3823
+ * @typedef {import('./types').ScopedElementsMixin} ScopedElementsMixin
3824
+ * @typedef {import('./types').ScopedElementsHost} ScopedElementsHost
3825
+ * @typedef {import('./types').ScopedElementsMap} ScopedElementsMap
3826
+ * @typedef {import('@lit/reactive-element').CSSResultOrNative} CSSResultOrNative
3784
3827
  */
3785
3828
 
3786
- const version = '3.0.0';
3787
- const versions = window.scopedElementsVersions || (window.scopedElementsVersions = []);
3788
- if (!versions.includes(version)) {
3789
- versions.push(version);
3790
- }
3829
+ // @ts-ignore
3830
+ const supportsScopedRegistry = !!ShadowRoot.prototype.createElement;
3791
3831
 
3792
3832
  /**
3793
- * @template {import('./types.js').Constructor<HTMLElement>} T
3833
+ * @template {import('./types').Constructor<HTMLElement>} T
3794
3834
  * @param {T} superclass
3795
- * @return {T & import('./types.js').Constructor<ScopedElementsHost>}
3835
+ * @return {T & import('./types').Constructor<ScopedElementsHost>}
3796
3836
  */
3797
- const ScopedElementsMixinImplementation$1 = superclass =>
3837
+ const ScopedElementsMixinImplementation = superclass =>
3798
3838
  /** @type {ScopedElementsHost} */
3799
3839
  class ScopedElementsHost extends superclass {
3800
3840
  /**
3801
3841
  * Obtains the scoped elements definitions map if specified.
3802
3842
  *
3803
- * @type {ScopedElementsMap=}
3843
+ * @returns {ScopedElementsMap}
3844
+ */
3845
+ static get scopedElements() {
3846
+ return {};
3847
+ }
3848
+
3849
+ /**
3850
+ * Obtains the ShadowRoot options.
3851
+ *
3852
+ * @type {ShadowRootInit}
3804
3853
  */
3805
- static scopedElements;
3854
+ static get shadowRootOptions() {
3855
+ return this.__shadowRootOptions;
3856
+ }
3806
3857
 
3807
- static get scopedElementsVersion() {
3808
- return version;
3858
+ /**
3859
+ * Set the shadowRoot options.
3860
+ *
3861
+ * @param {ShadowRootInit} value
3862
+ */
3863
+ static set shadowRootOptions(value) {
3864
+ this.__shadowRootOptions = value;
3809
3865
  }
3810
3866
 
3811
- /** @type {CustomElementRegistry=} */
3812
- static __registry;
3867
+ /**
3868
+ * Obtains the element styles.
3869
+ *
3870
+ * @returns {CSSResultOrNative[]}
3871
+ */
3872
+ static get elementStyles() {
3873
+ return this.__elementStyles;
3874
+ }
3875
+
3876
+ static set elementStyles(styles) {
3877
+ this.__elementStyles = styles;
3878
+ }
3879
+
3880
+ // either TS or ESLint will complain here
3881
+ // eslint-disable-next-line no-unused-vars
3882
+ constructor(..._args) {
3883
+ super();
3884
+ /** @type {RenderOptions} */
3885
+ this.renderOptions = this.renderOptions || undefined;
3886
+ }
3813
3887
 
3814
3888
  /**
3815
3889
  * Obtains the CustomElementRegistry associated to the ShadowRoot.
3816
3890
  *
3817
- * @returns {CustomElementRegistry=}
3891
+ * @returns {CustomElementRegistry}
3818
3892
  */
3819
3893
  get registry() {
3820
- return /** @type {typeof ScopedElementsHost} */ (this.constructor).__registry;
3894
+ // @ts-ignore
3895
+ return this.constructor.__registry;
3821
3896
  }
3822
3897
 
3823
3898
  /**
@@ -3826,15 +3901,13 @@
3826
3901
  * @param {CustomElementRegistry} registry
3827
3902
  */
3828
3903
  set registry(registry) {
3829
- /** @type {typeof ScopedElementsHost} */ (this.constructor).__registry = registry;
3904
+ // @ts-ignore
3905
+ this.constructor.__registry = registry;
3830
3906
  }
3831
3907
 
3832
- /**
3833
- * @param {ShadowRootInit} options
3834
- * @returns {ShadowRoot}
3835
- */
3836
- attachShadow(options) {
3837
- const { scopedElements } = /** @type {typeof ScopedElementsHost} */ (this.constructor);
3908
+ createRenderRoot() {
3909
+ const { scopedElements, shadowRootOptions, elementStyles } =
3910
+ /** @type {typeof ScopedElementsHost} */ (this.constructor);
3838
3911
 
3839
3912
  const shouldCreateRegistry =
3840
3913
  !this.registry ||
@@ -3846,60 +3919,89 @@
3846
3919
  * Create a new registry if:
3847
3920
  * - the registry is not defined
3848
3921
  * - this class doesn't have its own registry *AND* has no shared registry
3849
- * This is important specifically for superclasses/inheritance
3850
3922
  */
3851
3923
  if (shouldCreateRegistry) {
3852
- this.registry = new CustomElementRegistry();
3853
- for (const [tagName, klass] of Object.entries(scopedElements ?? {})) {
3854
- this.registry.define(tagName, klass);
3924
+ this.registry = supportsScopedRegistry ? new CustomElementRegistry() : customElements;
3925
+ for (const [tagName, klass] of Object.entries(scopedElements)) {
3926
+ this.defineScopedElement(tagName, klass);
3855
3927
  }
3856
3928
  }
3857
3929
 
3858
- return super.attachShadow({
3859
- ...options,
3860
- // The polyfill currently expects the registry to be passed as `customElements`
3930
+ /** @type {ShadowRootInit} */
3931
+ const options = {
3932
+ mode: 'open',
3933
+ ...shadowRootOptions,
3861
3934
  customElements: this.registry,
3862
- // But the proposal has moved forward, and renamed it to `registry`
3863
- // For backwards compatibility, we pass it as both
3864
- registry: this.registry,
3865
- });
3866
- }
3867
- };
3935
+ };
3868
3936
 
3869
- const ScopedElementsMixin$1 = dedupeMixin(ScopedElementsMixinImplementation$1);
3937
+ const createdRoot = this.attachShadow(options);
3938
+ if (supportsScopedRegistry) {
3939
+ this.renderOptions.creationScope = createdRoot;
3940
+ }
3870
3941
 
3871
- /**
3872
- * @typedef {import('./types.js').ScopedElementsHost} ScopedElementsHost
3873
- * @typedef {import('./types.js').ScopedElementsMap} ScopedElementsMap
3874
- * @typedef {import('lit').CSSResultOrNative} CSSResultOrNative
3875
- * @typedef {import('lit').LitElement} LitElement
3876
- * @typedef {typeof import('lit').LitElement} TypeofLitElement
3877
- * @typedef {import('@open-wc/dedupe-mixin').Constructor<LitElement>} LitElementConstructor
3878
- * @typedef {import('@open-wc/dedupe-mixin').Constructor<ScopedElementsHost>} ScopedElementsHostConstructor
3879
- */
3942
+ if (createdRoot instanceof ShadowRoot) {
3943
+ adoptStyles(createdRoot, elementStyles);
3944
+ this.renderOptions.renderBefore = this.renderOptions.renderBefore || createdRoot.firstChild;
3945
+ }
3880
3946
 
3881
- /**
3882
- * @template {LitElementConstructor} T
3883
- * @param {T} superclass
3884
- * @return {T & ScopedElementsHostConstructor}
3885
- */
3886
- const ScopedElementsMixinImplementation = superclass =>
3887
- /** @type {ScopedElementsHost} */
3888
- class ScopedElementsHost extends ScopedElementsMixin$1(superclass) {
3889
- createRenderRoot() {
3890
- const { shadowRootOptions, elementStyles } = /** @type {TypeofLitElement} */ (
3891
- this.constructor
3892
- );
3947
+ return createdRoot;
3948
+ }
3893
3949
 
3894
- const shadowRoot = this.attachShadow(shadowRootOptions);
3895
- // @ts-ignore
3896
- this.renderOptions.creationScope = shadowRoot;
3950
+ createScopedElement(tagName) {
3951
+ const root = supportsScopedRegistry ? this.shadowRoot : document;
3952
+ // @ts-ignore polyfill to support createElement on shadowRoot is loaded
3953
+ return root.createElement(tagName);
3954
+ }
3897
3955
 
3898
- adoptStyles(shadowRoot, elementStyles);
3956
+ /**
3957
+ * Defines a scoped element.
3958
+ *
3959
+ * @param {string} tagName
3960
+ * @param {typeof HTMLElement} klass
3961
+ */
3962
+ defineScopedElement(tagName, klass) {
3963
+ const registeredClass = this.registry.get(tagName);
3964
+ if (registeredClass && supportsScopedRegistry === false && registeredClass !== klass) {
3965
+ // eslint-disable-next-line no-console
3966
+ console.error(
3967
+ [
3968
+ `You are trying to re-register the "${tagName}" custom element with a different class via ScopedElementsMixin.`,
3969
+ 'This is only possible with a CustomElementRegistry.',
3970
+ 'Your browser does not support this feature so you will need to load a polyfill for it.',
3971
+ 'Load "@webcomponents/scoped-custom-element-registry" before you register ANY web component to the global customElements registry.',
3972
+ 'e.g. add "<script src="/node_modules/@webcomponents/scoped-custom-element-registry/scoped-custom-element-registry.min.js"></script>" as your first script tag.',
3973
+ 'For more details you can visit https://open-wc.org/docs/development/scoped-elements/',
3974
+ ].join('\n'),
3975
+ );
3976
+ }
3977
+ if (!registeredClass) {
3978
+ return this.registry.define(tagName, klass);
3979
+ }
3980
+ return this.registry.get(tagName);
3981
+ }
3899
3982
 
3900
- this.renderOptions.renderBefore ??= shadowRoot.firstChild;
3983
+ /**
3984
+ * @deprecated use the native el.tagName instead
3985
+ *
3986
+ * @param {string} tagName
3987
+ * @returns {string} the tag name
3988
+ */
3989
+ // eslint-disable-next-line class-methods-use-this
3990
+ getScopedTagName(tagName) {
3991
+ // @ts-ignore
3992
+ return this.constructor.getScopedTagName(tagName);
3993
+ }
3901
3994
 
3902
- return shadowRoot;
3995
+ /**
3996
+ * @deprecated use the native el.tagName instead
3997
+ *
3998
+ * @param {string} tagName
3999
+ * @returns {string} the tag name
4000
+ */
4001
+ // eslint-disable-next-line class-methods-use-this
4002
+ static getScopedTagName(tagName) {
4003
+ // @ts-ignore
4004
+ return this.__registry.get(tagName) ? tagName : undefined;
3903
4005
  }
3904
4006
  };
3905
4007