@arcgis/lumina 4.32.0-next.1 → 4.32.0-next.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,32 +1,48 @@
1
1
  import {
2
- defaultEventBubbles,
3
- defaultEventCancelable,
4
- defaultEventComposed,
5
- lazyMetaGroupJoiner,
6
- lazyMetaItemJoiner,
7
- lazyMetaSubItemJoiner
8
- } from "./chunk-CH52Q2MB.js";
2
+ attachToAncestor,
3
+ makeDefineCustomElements,
4
+ noShadowRoot
5
+ } from "./chunk-6HCCSL5F.js";
6
+ import "./chunk-PGHUBTOM.js";
7
+
8
+ // src/context.ts
9
+ import { retrieveComponent } from "@arcgis/components-controllers";
10
+ import { ContextConsumer, ContextProvider } from "@lit/context";
11
+ function useContextProvider(options) {
12
+ const component = retrieveComponent();
13
+ const controller = new ContextProvider(component.el, options);
14
+ component.addController(controller);
15
+ return controller;
16
+ }
17
+ function useContextConsumer(options) {
18
+ const component = retrieveComponent();
19
+ const controller = new ContextConsumer(component.el, options);
20
+ component.addController(controller);
21
+ return controller;
22
+ }
9
23
 
10
24
  // src/createEvent.ts
11
- import { retrieveComponent, trackPropertyKey } from "@arcgis/components-controllers";
12
- var createEventFactory = (eventName = "", options = {}, component = retrieveComponent()) => {
25
+ import { retrieveComponent as retrieveComponent2, keyTrackResolve, trackKey } from "@arcgis/components-controllers";
26
+ import { isEsriInternalEnv } from "@arcgis/components-utils";
27
+ var createEventFactory = (eventName = "", options = {}, component = retrieveComponent2()) => {
13
28
  const emitter = {
14
29
  emit: (payload) => {
15
- if (process.env.NODE_ENV !== "production") {
16
- if (eventName === "") {
30
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && !component.el.isConnected) {
31
+ console.warn(
32
+ `Trying to emit an ${eventName} event on a disconnected element ${component.el.tagName.toLowerCase()}`
33
+ );
34
+ }
35
+ if (eventName === "") {
36
+ keyTrackResolve();
37
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && eventName === "") {
17
38
  throw new Error("Unable to resolve event name from property name");
18
39
  }
19
- if (!component.el.isConnected) {
20
- console.warn(
21
- `Trying to emit an ${eventName} event on a disconnected element ${component.el.tagName.toLowerCase()}`
22
- );
23
- }
24
40
  }
25
41
  const event = new CustomEvent(eventName, {
26
42
  detail: payload,
27
- cancelable: defaultEventCancelable,
28
- bubbles: defaultEventBubbles,
29
- composed: defaultEventComposed,
43
+ cancelable: true,
44
+ bubbles: true,
45
+ composed: true,
30
46
  ...options
31
47
  });
32
48
  component.el.dispatchEvent(event);
@@ -34,13 +50,13 @@ var createEventFactory = (eventName = "", options = {}, component = retrieveComp
34
50
  }
35
51
  };
36
52
  if (eventName === "") {
37
- trackPropertyKey(
38
- component,
39
- (key) => {
40
- if (process.env.NODE_ENV !== "production" && key === void 0) {
53
+ trackKey(
54
+ void 0,
55
+ (resolution) => {
56
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && resolution === void 0) {
41
57
  throw new Error(`createEvent must be called in property default value only`);
42
58
  }
43
- eventName = key;
59
+ eventName = resolution.key;
44
60
  },
45
61
  emitter
46
62
  );
@@ -55,491 +71,8 @@ import { property as litProperty } from "@lit/reactive-element/decorators/proper
55
71
  var property = litProperty;
56
72
  var method = void 0;
57
73
 
58
- // src/lazyLoad.ts
59
- import { Deferred, camelToKebab } from "@arcgis/components-utils";
60
-
61
- // src/devOnlyDetectIncorrectLazyUsages.ts
62
- function devOnlyDetectIncorrectLazyUsages(LitClass) {
63
- const genericPrototype = LitClass.prototype;
64
- const descriptor = Object.getOwnPropertyDescriptor(genericPrototype, "innerText");
65
- if (descriptor !== void 0 && descriptor.get === descriptor.set) {
66
- return;
67
- }
68
- const allowList = /* @__PURE__ */ new Set([
69
- // We shouldn't be overwriting this property
70
- "constructor",
71
- // Called by Lit - we proxy it to this.el in ProxyComponent
72
- "setAttribute",
73
- // Called by Lit SSR - we proxy it to this.el in ProxyComponent
74
- "removeAttribute",
75
- // Called by Lit - we proxy it to this.el in ProxyComponent
76
- "isConnected",
77
- // Called by Lit, but only in dev mode for warnings, so we don't have to proxy.
78
- "localName"
79
- ]);
80
- const customErrorMessages = {
81
- addEventListener: "use this.listen() or this.el.addEventListener()"
82
- };
83
- Object.entries({
84
- ...Object.getOwnPropertyDescriptors(HTMLElement.prototype),
85
- ...Object.getOwnPropertyDescriptors(Element.prototype),
86
- ...Object.getOwnPropertyDescriptors(Node.prototype),
87
- ...Object.getOwnPropertyDescriptors(EventTarget.prototype)
88
- }).forEach(([key, value]) => {
89
- if (allowList.has(key)) {
90
- return;
91
- }
92
- const callback = (...args) => {
93
- if (key === "hasAttribute" && args[0] === "defer-hydration") {
94
- return false;
95
- }
96
- throw new Error(
97
- `You should not be trying to access this.${key} directly as it won't work correctly in lazy-builds. Instead, ${customErrorMessages[key] ?? `use this.el.${key}`}`
98
- );
99
- };
100
- if (typeof value.value === "function") {
101
- genericPrototype[key] = callback;
102
- } else {
103
- Object.defineProperty(genericPrototype, key, { get: callback, set: callback });
104
- }
105
- });
106
- }
107
-
108
- // src/lifecycleSupport.ts
109
- function attachToAncestor(child) {
110
- let ancestor = child;
111
- while (ancestor = ancestor.parentNode ?? ancestor.host) {
112
- if (ancestor?.constructor?.lumina) {
113
- const litParent = ancestor;
114
- if (!litParent.manager?.loadedCalled) {
115
- litParent._offspring.push(child);
116
- }
117
- return litParent._postLoad.promise;
118
- }
119
- }
120
- return false;
121
- }
122
-
123
- // src/utils.ts
124
- var noShadowRoot = {};
125
-
126
- // src/lazyLoad.ts
127
- var makeDefineCustomElements = (runtime, structure) => function defineCustomElements(windowOrOptions, options) {
128
- if (!globalThis.customElements) {
129
- return;
130
- }
131
- const resolvedOptions = options ?? windowOrOptions ?? {};
132
- const resourcesUrl = resolvedOptions.resourcesUrl;
133
- if (resourcesUrl) {
134
- runtime.setAssetPath(resourcesUrl);
135
- }
136
- Object.entries(structure).forEach(createLazyElement);
137
- };
138
- function createLazyElement([tagName, [load, compactMeta = ""]]) {
139
- if (customElements.get(tagName)) {
140
- return;
141
- }
142
- const [compactObservedProps, compactAsyncMethods, compactSyncMethods] = compactMeta.split(lazyMetaGroupJoiner);
143
- const observedProps = compactObservedProps ? compactObservedProps?.split(lazyMetaItemJoiner).map(parseCondensedProp) : void 0;
144
- const observedProperties = observedProps?.map(([property2]) => property2);
145
- const ProxyClass = class extends ProxyComponent {
146
- static {
147
- this.observedAttributes = observedProps?.map(([, attribute]) => attribute).filter((attribute) => attribute !== "");
148
- }
149
- static {
150
- this._properties = observedProperties;
151
- }
152
- static {
153
- this._asyncMethods = compactAsyncMethods ? compactAsyncMethods?.split(lazyMetaItemJoiner) : void 0;
154
- }
155
- static {
156
- this._syncMethods = compactSyncMethods?.split(lazyMetaItemJoiner);
157
- }
158
- static {
159
- this._name = tagName;
160
- }
161
- constructor() {
162
- const isFirstInstanceOfType = !ProxyClass._loadPromise;
163
- if (isFirstInstanceOfType) {
164
- ProxyClass._loadPromise = load();
165
- ProxyClass._initializePrototype();
166
- }
167
- super();
168
- }
169
- };
170
- customElements.define(tagName, ProxyClass);
171
- }
172
- var defineProperty = Object.defineProperty;
173
- function parseCondensedProp(propAndAttribute) {
174
- const name = propAndAttribute.split(lazyMetaSubItemJoiner);
175
- return name.length === 1 ? [name[0], camelToKebab(name[0])] : name;
176
- }
177
- var HtmlElement = globalThis.HTMLElement ?? parseCondensedProp;
178
- var ProxyComponent = class extends HtmlElement {
179
- constructor() {
180
- super();
181
- /** @internal */
182
- this._store = {};
183
- /**
184
- * If attributeChangedCallback() is called before the LitElement is loaded,
185
- * store the attributes here, and replay later
186
- */
187
- this._pendingAttributes = [];
188
- /**
189
- * Resolved once LitElement's load() is complete.
190
- * Not read inside of this class, but needed for LitElement to determine if
191
- * it's closest ancestor finished load()
192
- */
193
- this._postLoad = new Deferred();
194
- /**
195
- * Resolved once LitElement's loaded() is complete
196
- */
197
- this._postLoaded = new Deferred();
198
- /**
199
- * Direct offspring that should be awaited before loaded() is emitted
200
- */
201
- this._offspring = [];
202
- if (process.env.NODE_ENV !== "production") {
203
- this._hmrSetProps = /* @__PURE__ */ new Set();
204
- this._hmrSetAttributes = /* @__PURE__ */ new Set();
205
- globalThis.devOnly$createdElements ??= [];
206
- globalThis.devOnly$createdElements.push(new WeakRef(this));
207
- }
208
- this._saveInstanceProperties();
209
- const ProxyClass = this.constructor;
210
- if (ProxyClass._LitConstructor) {
211
- this._initializeComponent({ a: ProxyClass._LitConstructor });
212
- } else {
213
- void ProxyClass._loadPromise.then(this._initializeComponent.bind(this)).catch((error) => {
214
- console.error(error);
215
- this._postLoaded.reject(error);
216
- });
217
- }
218
- if (process.env.NODE_ENV !== "production") {
219
- ProxyClass._hmrInstances ??= [];
220
- ProxyClass._hmrInstances.push(new WeakRef(this));
221
- Object.defineProperty(this, "_store", {
222
- value: this._store,
223
- enumerable: false,
224
- configurable: true
225
- });
226
- }
227
- }
228
- static {
229
- this.lumina = true;
230
- }
231
- /** @internal */
232
- static _initializePrototype() {
233
- this._properties?.forEach(this._bindProp, this);
234
- this._asyncMethods?.forEach(this._bindAsync, this);
235
- this._syncMethods?.forEach(this._bindSync, this);
236
- }
237
- static _bindProp(propName) {
238
- defineProperty(this.prototype, propName, {
239
- configurable: true,
240
- enumerable: true,
241
- get() {
242
- return this._store[propName];
243
- },
244
- set(value) {
245
- this._store[propName] = value;
246
- if (process.env.NODE_ENV !== "production") {
247
- this._hmrSetProps.add(propName);
248
- }
249
- }
250
- });
251
- }
252
- static _bindAsync(methodName) {
253
- defineProperty(this.prototype, methodName, {
254
- async value(...args) {
255
- if (!this._litElement) {
256
- await this._postLoaded.promise;
257
- }
258
- const genericLitElement = this._litElement;
259
- return await genericLitElement[methodName](...args);
260
- },
261
- configurable: true
262
- });
263
- }
264
- static _bindSync(methodName) {
265
- defineProperty(this.prototype, methodName, {
266
- value(...args) {
267
- if (process.env.NODE_ENV === "development" && !this._litElement) {
268
- const ProxyClass = this.constructor;
269
- throw new Error(
270
- `Tried to call method ${methodName}() on <${ProxyClass._name}> component before it's fully loaded. Please do 'await component.componentOnReady();' before calling this method.`
271
- );
272
- }
273
- const genericLitElement = this._litElement;
274
- return genericLitElement[methodName](...args);
275
- },
276
- configurable: true
277
- });
278
- }
279
- get manager() {
280
- return this._litElement?.manager;
281
- }
282
- /**
283
- * Until the custom element is registered on the page, an instance of that
284
- * element can be constructed and some properties on that instance set.
285
- *
286
- * These properties are set before the element prototype is set to this proxy
287
- * class and thus none of our getters/setters are yet registered - such
288
- * properties will be set by JavaScript on the instance directly.
289
- *
290
- * Once element is registered, the properties set in the meanwhile will shadow
291
- * the getter/setters, and thus break reactivity. The fix is to delete these
292
- * properties from the instance, and re-apply them once accessors are set.
293
- *
294
- * @example
295
- * ```ts
296
- * import { defineCustomElements } from '@arcgis/map-components';
297
- * const map = document.createElement('arcgis-map');
298
- * // This will shadow the getter/setters
299
- * map.itemId = '...';
300
- * // This finally defines the custom elements and sets the property accessors
301
- * defineCustomElements();
302
- * ```
303
- *
304
- * @remarks
305
- * This is an equivalent of the __saveInstanceProperties method in Lit's
306
- * ReactiveElement. Lit takes care of this on LitElement, but we have to take
307
- * care of this on the lazy proxy
308
- */
309
- _saveInstanceProperties() {
310
- const ProxyClass = this.constructor;
311
- const genericThis = this;
312
- ProxyClass._properties?.forEach((propName) => {
313
- if (Object.hasOwn(this, propName)) {
314
- this._store[propName] = genericThis[propName];
315
- delete genericThis[propName];
316
- }
317
- });
318
- }
319
- /*
320
- * This method must be statically present rather than added later, or else,
321
- * browsers won't call it. Same for connected and disconnected callbacks.
322
- */
323
- attributeChangedCallback(name, oldValue, newValue) {
324
- this._litElement?.attributeChangedCallback(name, oldValue, newValue);
325
- if (!this._litElement) {
326
- this._pendingAttributes.push(name);
327
- }
328
- if (process.env.NODE_ENV !== "production") {
329
- this._hmrSetAttributes.add(name);
330
- }
331
- }
332
- connectedCallback() {
333
- if (this._litElement) {
334
- this._litElement.connectedCallback();
335
- } else {
336
- queueMicrotask(() => {
337
- this._ancestorLoad = attachToAncestor(this);
338
- });
339
- }
340
- }
341
- disconnectedCallback() {
342
- this._litElement?.disconnectedCallback();
343
- }
344
- /**
345
- * Create a promise that resolves once component is fully loaded
346
- */
347
- async componentOnReady() {
348
- await this._postLoaded.promise;
349
- return this._litElement;
350
- }
351
- /** @internal */
352
- _initializeComponent(module) {
353
- const ProxyClass = this.constructor;
354
- const tagName = ProxyClass._name;
355
- if (process.env.NODE_ENV !== "production") {
356
- Object.entries(module).forEach(([name, LitConstructor2]) => {
357
- if (name !== "exportsForTests" && typeof LitConstructor2 !== "function" || typeof LitConstructor2.tagName !== "string") {
358
- console.warn(
359
- `Found non-component export "${name}" in the file for the "${tagName}" component. This will interfere with hot module replacement. Please move "${name}" into a separate file.`
360
- );
361
- }
362
- });
363
- }
364
- const LitConstructor = Object.values(module).find(
365
- (LitConstructor2) => LitConstructor2.tagName === tagName
366
- );
367
- if (process.env.NODE_ENV !== "production" && !LitConstructor) {
368
- throw new Error(
369
- `Unable to find the LitElement class for the "${tagName}" custom element in the lazy-loaded module`
370
- );
371
- }
372
- const lazyTagName = process.env.NODE_ENV === "production" ? `${tagName}--lazy` : (ProxyClass._hmrIndex ?? 0) === 0 ? `${tagName}--lazy` : `${tagName}--lazy-${ProxyClass._hmrIndex}`;
373
- const isFirstInitialization = !ProxyClass._LitConstructor;
374
- if (isFirstInitialization) {
375
- ProxyClass._LitConstructor = LitConstructor;
376
- LitConstructor.prototype.removeAttribute = function(qualifiedName) {
377
- HTMLElement.prototype.removeAttribute.call(this.el, qualifiedName);
378
- };
379
- LitConstructor.prototype.setAttribute = function(qualifiedName, value) {
380
- HTMLElement.prototype.setAttribute.call(this.el, qualifiedName, value);
381
- };
382
- defineProperty(LitConstructor.prototype, "isConnected", {
383
- get() {
384
- return this.el.isConnected;
385
- }
386
- });
387
- if (process.env.NODE_ENV !== "production" && LitConstructor.shadowRootOptions !== noShadowRoot) {
388
- let prototype = LitConstructor;
389
- while (prototype && !Object.hasOwn(prototype, "lumina")) {
390
- prototype = Object.getPrototypeOf(prototype);
391
- }
392
- devOnlyDetectIncorrectLazyUsages(prototype);
393
- }
394
- customElements.define(lazyTagName, LitConstructor);
395
- }
396
- LitConstructor.lazy = this;
397
- const litElement = document.createElement(lazyTagName);
398
- LitConstructor.lazy = void 0;
399
- if (process.env.NODE_ENV !== "production") {
400
- Object.defineProperty(this, "_litElement", {
401
- value: litElement,
402
- configurable: true,
403
- enumerable: false
404
- });
405
- } else {
406
- this._litElement = litElement;
407
- }
408
- this._pendingAttributes.forEach((name) => {
409
- const value = this.getAttribute(name);
410
- litElement.attributeChangedCallback(
411
- name,
412
- // Lit doesn't look at this value, thus even if attribute already exists, that's ok
413
- null,
414
- value
415
- );
416
- });
417
- Object.entries(this._store).forEach(syncLitElement, litElement);
418
- this._store = litElement;
419
- if (process.env.NODE_ENV !== "production") {
420
- const litObserved = LitConstructor.observedAttributes ?? [];
421
- const lazyObserved = ProxyClass.observedAttributes ?? [];
422
- const missingFromLazy = litObserved.filter((attribute) => !lazyObserved.includes(attribute));
423
- const missingFromLit = lazyObserved.filter((attribute) => !litObserved.includes(attribute));
424
- if (missingFromLazy.length > 0) {
425
- console.warn(
426
- `The following attributes on <${ProxyClass._name}> are present on the Lit element, but are missing from the lazy proxy component: ${missingFromLazy.join(", ")}. This either indicates a bug in Lumina, or you are creating the attribute dynamically in a way that compiler cannot infer statically. For these attributes, lazy-loading version of your component won't work correctly, thus this must be resolved`
427
- );
428
- }
429
- if (missingFromLit.length > 0) {
430
- console.warn(
431
- `The following attributes on <${ProxyClass._name}> are defined on the lazy proxy component, but not on the actual Lit element: ${missingFromLit.join(", ")}. This either indicates a bug in Lumina, or you are creating the attribute dynamically in a way that compiler cannot infer statically. This is a non-critical issue, but does indicate that something is going wrong and should be fixed`
432
- );
433
- }
434
- }
435
- const isStillConnected = this.isConnected;
436
- if (isStillConnected || this._ancestorLoad) {
437
- litElement.connectedCallback?.();
438
- if (!isStillConnected) {
439
- litElement.disconnectedCallback();
440
- }
441
- }
442
- }
443
- };
444
- function syncLitElement([key, value]) {
445
- this[key] = value;
446
- }
447
-
448
- // src/hmrSupport.ts
449
- import { camelToKebab as camelToKebab2 } from "@arcgis/components-utils";
450
- function handleHmrUpdate(newModules) {
451
- newModules.forEach((newModule) => {
452
- if (newModule === void 0) {
453
- return;
454
- }
455
- Object.values(newModule).forEach((exported) => {
456
- if (typeof exported !== "function" || typeof exported.tagName !== "string") {
457
- return;
458
- }
459
- const LitConstructor = exported;
460
- const ProxyClass = customElements.get(LitConstructor.tagName);
461
- if (ProxyClass === void 0) {
462
- throw new Error(`Failed to find custom element proxy for tag name: ${LitConstructor.tagName}`);
463
- }
464
- ProxyClass._LitConstructor = void 0;
465
- ProxyClass._loadPromise = void 0;
466
- ProxyClass._hmrIndex ??= 0;
467
- ProxyClass._hmrIndex += 1;
468
- ProxyClass._initializePrototype();
469
- ProxyClass._hmrInstances?.forEach((instanceWeakRef) => {
470
- const instance = instanceWeakRef.deref();
471
- if (instance === void 0) {
472
- return;
473
- }
474
- if (instance._litElement === void 0) {
475
- void ProxyClass._loadPromise.then(() => reInitialize(instance, newModule));
476
- } else {
477
- reInitialize(instance, newModule);
478
- }
479
- });
480
- return;
481
- });
482
- });
483
- }
484
- function reInitialize(instance, newModule) {
485
- const PreviousLitConstructor = instance._litElement.constructor;
486
- const properties = PreviousLitConstructor.elementProperties;
487
- const preservedProperties = Array.from(properties.entries()).filter(
488
- ([propertyName, descriptor]) => typeof propertyName === "string" && (instance._hmrSetProps.has(propertyName) || typeof descriptor.attribute === "string" && instance._hmrSetAttributes.has(descriptor.attribute))
489
- ).map(([key]) => [key, instance[key]]);
490
- instance._store = Object.fromEntries(preservedProperties);
491
- const isConnected = instance.isConnected;
492
- if (isConnected) {
493
- instance._litElement.disconnectedCallback();
494
- }
495
- instance._initializeComponent(newModule);
496
- }
497
- function handleComponentMetaUpdate(meta) {
498
- const ProxyClass = customElements.get(meta.tagName);
499
- if (ProxyClass === void 0) {
500
- return;
501
- }
502
- const attributes = meta.properties.map(([property2, attribute]) => attribute ?? camelToKebab2(property2)).filter(Boolean);
503
- observedAttributes[meta.tagName] ??= {};
504
- observedAttributes[meta.tagName].original ??= new Set(ProxyClass.observedAttributes);
505
- const originallyObserved = observedAttributes[meta.tagName].original;
506
- observedAttributes[meta.tagName].manuallyObserved ??= new Set(
507
- /**
508
- * Never manually observe attributes that were in the original
509
- * observedAttributes as those would be observed by the browser
510
- */
511
- attributes.filter((attribute) => !originallyObserved.has(attribute))
512
- );
513
- ProxyClass._asyncMethods = meta.asyncMethods;
514
- ProxyClass._syncMethods = meta.syncMethods;
515
- ProxyClass._properties = meta.properties.map(([name]) => name);
516
- ProxyClass.observedAttributes = attributes;
517
- }
518
- var observedAttributesSymbol = Symbol.for("@arcgis/lumina:observedAttributes");
519
- var globalThisWithObservedAttributes = globalThis;
520
- var alreadyHadObservers = observedAttributesSymbol in globalThisWithObservedAttributes;
521
- globalThisWithObservedAttributes[observedAttributesSymbol] ??= {};
522
- var observedAttributes = globalThisWithObservedAttributes[observedAttributesSymbol];
523
- if (!alreadyHadObservers) {
524
- const makeObserver = (original) => function observeAttributes(qualifiedName, ...rest) {
525
- const observed = observedAttributes[this.tagName.toLowerCase()]?.manuallyObserved;
526
- if (observed?.has(qualifiedName)) {
527
- const oldValue = this.getAttribute(qualifiedName);
528
- const returns = original.call(this, qualifiedName, ...rest);
529
- const newValue = this.getAttribute(qualifiedName);
530
- this.attributeChangedCallback(qualifiedName, oldValue, newValue);
531
- return returns;
532
- } else {
533
- return original.call(this, qualifiedName, ...rest);
534
- }
535
- };
536
- ProxyComponent.prototype.setAttribute = makeObserver(ProxyComponent.prototype.setAttribute);
537
- ProxyComponent.prototype.toggleAttribute = makeObserver(ProxyComponent.prototype.toggleAttribute);
538
- ProxyComponent.prototype.removeAttribute = makeObserver(ProxyComponent.prototype.removeAttribute);
539
- }
540
-
541
74
  // src/LitElement.ts
542
- import { Deferred as Deferred2, camelToKebab as camelToKebab3 } from "@arcgis/components-utils";
75
+ import { Deferred, camelToKebab, isEsriInternalEnv as isEsriInternalEnv2 } from "@arcgis/components-utils";
543
76
  import { LitElement as OriginalLitElement, isServer } from "lit";
544
77
  import { useControllerManager } from "@arcgis/components-controllers";
545
78
  var emptyFunction = () => void 0;
@@ -573,7 +106,7 @@ var LitElement = class _LitElement extends OriginalLitElement {
573
106
  */
574
107
  this.manager = useControllerManager(this);
575
108
  /** @internal */
576
- this._postLoad = this.constructor.lazy?._postLoad ?? new Deferred2();
109
+ this._postLoad = this.constructor.lazy?._postLoad ?? new Deferred();
577
110
  /**
578
111
  * Direct offspring that should be awaited before loaded() is emitted.
579
112
  *
@@ -582,7 +115,7 @@ var LitElement = class _LitElement extends OriginalLitElement {
582
115
  * @internal
583
116
  */
584
117
  this._offspring = this.constructor.lazy?._offspring ?? [];
585
- this._postLoaded = this.constructor.lazy?._postLoaded ?? new Deferred2();
118
+ this._postLoaded = this.constructor.lazy?._postLoaded ?? new Deferred();
586
119
  this._enableUpdating = this.enableUpdating;
587
120
  this.enableUpdating = emptyFunction;
588
121
  const ourShouldUpdate = _LitElement.prototype.shouldUpdate;
@@ -591,19 +124,31 @@ var LitElement = class _LitElement extends OriginalLitElement {
591
124
  this.shouldUpdate = ourShouldUpdate;
592
125
  }
593
126
  if (process.env.NODE_ENV !== "production") {
594
- globalThis.devOnly$luminaComponentRefCallback?.(this);
127
+ const isOwnComponent = globalThis.devOnly$ownTagNames?.has(
128
+ this.el.tagName.toLowerCase()
129
+ );
130
+ const constructor = this.constructor;
131
+ const warningsWereCustomized = constructor.enabledWarnings !== OriginalLitElement.enabledWarnings;
132
+ if (!isOwnComponent && !warningsWereCustomized) {
133
+ constructor.disableWarning?.("change-in-update");
134
+ }
135
+ if (isEsriInternalEnv2()) {
136
+ globalThis.devOnly$luminaComponentRefCallback?.(this);
137
+ }
595
138
  }
596
139
  if (isServer) {
597
140
  this.el.setAttribute(this.constructor.runtime.hydratedAttribute, "");
598
141
  }
599
142
  }
143
+ /**
144
+ * Customize Lit's default style handling to support non-shadow-root styles
145
+ */
600
146
  static finalizeStyles(styles) {
601
147
  if (process.env.NODE_ENV === "test" && Array.isArray(styles)) {
602
148
  styles = styles.filter(Boolean);
603
149
  }
604
150
  const finalizedStyles = super.finalizeStyles(styles);
605
- const options = this.constructor.shadowRootOptions;
606
- const useLightDom = options === noShadowRoot;
151
+ const useLightDom = this.shadowRootOptions === noShadowRoot;
607
152
  return this.runtime?.commonStyles === void 0 || useLightDom ? finalizedStyles : [this.runtime.commonStyles, ...finalizedStyles];
608
153
  }
609
154
  static createProperty(name, options) {
@@ -626,7 +171,7 @@ var LitElement = class _LitElement extends OriginalLitElement {
626
171
  *
627
172
  * Thus, overwriting Lit's default behavior to use kebab-case:
628
173
  */
629
- attribute: !!(flags & 1 /* ATTRIBUTE */) && typeof name === "string" ? camelToKebab3(name) : false,
174
+ attribute: !!(flags & 1 /* ATTRIBUTE */) && typeof name === "string" ? camelToKebab(name) : false,
630
175
  reflect: !!(flags & 2 /* REFLECT */),
631
176
  type: flags & 4 /* BOOLEAN */ ? Boolean : flags & 8 /* NUMBER */ ? Number : void 0,
632
177
  /**
@@ -654,8 +199,10 @@ var LitElement = class _LitElement extends OriginalLitElement {
654
199
  queueMicrotask(
655
200
  // eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/promise-function-async
656
201
  () => this._load().catch((error) => {
657
- console.error(error);
658
202
  this._postLoaded.reject(error);
203
+ setTimeout(() => {
204
+ throw error;
205
+ });
659
206
  })
660
207
  );
661
208
  }
@@ -682,11 +229,13 @@ var LitElement = class _LitElement extends OriginalLitElement {
682
229
  }
683
230
  return existingShadowRoot;
684
231
  }
685
- const domRoot = renderRoot.getRootNode();
686
- domRoot.adoptedStyleSheets = [
687
- ...domRoot.adoptedStyleSheets,
688
- ...Class.elementStyles.map((stylesheet) => "styleSheet" in stylesheet ? stylesheet.styleSheet : stylesheet)
689
- ];
232
+ if (this.isConnected) {
233
+ const domRoot = renderRoot.getRootNode();
234
+ domRoot.adoptedStyleSheets = [
235
+ ...domRoot.adoptedStyleSheets,
236
+ ...Class.elementStyles.map((stylesheet) => "styleSheet" in stylesheet ? stylesheet.styleSheet : stylesheet)
237
+ ];
238
+ }
690
239
  return renderRoot;
691
240
  }
692
241
  /** Do asynchronous component load */
@@ -747,7 +296,7 @@ var LitElement = class _LitElement extends OriginalLitElement {
747
296
  }
748
297
  };
749
298
  LitElement.$createEvent = createEventFactory;
750
- if (process.env.NODE_ENV !== "production") {
299
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv2()) {
751
300
  const globalWithLit = globalThis;
752
301
  globalWithLit.litIssuedWarnings ??= /* @__PURE__ */ new Set();
753
302
  globalWithLit.litIssuedWarnings.add(
@@ -756,10 +305,31 @@ if (process.env.NODE_ENV !== "production") {
756
305
  }
757
306
 
758
307
  // src/runtime.ts
308
+ import { isEsriInternalEnv as isEsriInternalEnv3 } from "@arcgis/components-utils";
759
309
  function makeRuntime(options) {
760
310
  let assetPath;
761
311
  const setAssetPath = (path) => {
762
- assetPath = new URL(path, globalThis.location?.href).href;
312
+ assetPath = new URL(
313
+ path,
314
+ /**
315
+ * setAssetPath() is called in global scope whenever Lumina runtime is
316
+ * imported. Thus we need to carefully handle different environments.
317
+ *
318
+ * Need `|| undefined` because Stencil's unit tests mock-dock defines
319
+ * `location.href` as empty string, which crashes `new URL()`. Stencil's
320
+ * test environment does not define `NODE_ENV` by default, so we have to
321
+ * add a few bytes to production.
322
+ *
323
+ * For happy-dom and jsdom, we are assuming that `NODE_ENV` is set.
324
+ * Depending on configuration, `location?.href` is either undefined (not
325
+ * an exception) or `about:blank` (an exception - thus handling that case
326
+ * explicitly).
327
+ *
328
+ * For Node.js without a DOM environment, `location?.href` is undefined so
329
+ * all is good.
330
+ */
331
+ process.env.NODE_ENV === "test" ? globalThis.location?.href === "about:blank" ? void 0 : globalThis.location?.href || void 0 : globalThis.location?.href || void 0
332
+ ).href;
763
333
  };
764
334
  const runtime = {
765
335
  ...options,
@@ -778,13 +348,13 @@ function makeRuntime(options) {
778
348
  }
779
349
  };
780
350
  setAssetPath(options.defaultAssetPath);
781
- if (process.env.NODE_ENV !== "production") {
351
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv3()) {
782
352
  globalThis.devOnly$luminaRuntime = runtime;
783
353
  }
784
354
  return runtime;
785
355
  }
786
356
 
787
- // src/jsx/jsx.ts
357
+ // src/jsx/types.ts
788
358
  var Fragment = void 0;
789
359
  var bindAttribute = void 0;
790
360
  var bindBooleanAttribute = void 0;
@@ -794,47 +364,11 @@ var bindEvent = void 0;
794
364
  // src/jsx/directives.ts
795
365
  import { classMap } from "lit-html/directives/class-map.js";
796
366
  import { styleMap } from "lit/directives/style-map.js";
797
- import { Directive } from "lit-html/directive.js";
798
367
  import { directive as litDirective } from "lit-html/directive.js";
799
368
  import { live as litLive } from "lit-html/directives/live.js";
800
369
  var safeClassMap = (parameters) => typeof parameters === "object" && parameters != null ? classMap(parameters) : parameters;
801
370
  var safeStyleMap = (parameters) => typeof parameters === "object" && parameters != null ? styleMap(parameters) : parameters;
802
371
  var directive = litDirective;
803
- var DynamicHtmlValueDirective = class extends Directive {
804
- update(part, [prop, value]) {
805
- if (process.env.NODE_ENV !== "production") {
806
- if (part.type !== 6) {
807
- throw new Error("DynamicHtmlValueDirective can only be used in the element part position");
808
- }
809
- if (prop !== "value" && prop !== "defaultValue") {
810
- throw new Error('Expected the first argument to DynamicHtmlValueDirective to be "value" or "defaultValue"');
811
- }
812
- if (typeof value === "object" && value != null) {
813
- if ("_$litDirective$" in value) {
814
- throw new Error(
815
- "Directive is not supported as a value for the `value` or `defaultValue` prop when the tag name is dynamic."
816
- );
817
- } else {
818
- throw new Error(
819
- `Tried to set an object as the value/defaultValue prop in a <${part.element.tagName}> element.`
820
- );
821
- }
822
- }
823
- }
824
- const element = part.element;
825
- const tagName = element.tagName;
826
- if (prop === "value" ? tagName === "INPUT" : tagName === "BUTTON" || tagName === "DATA") {
827
- if (element[prop] !== value) {
828
- element[prop] = value;
829
- }
830
- } else if (value != null) {
831
- element.setAttribute("value", value);
832
- } else {
833
- element.removeAttribute("value");
834
- }
835
- }
836
- };
837
- var dynamicValueDirective = directive(DynamicHtmlValueDirective);
838
372
  var live = litLive;
839
373
 
840
374
  // src/jsx/utils.ts
@@ -853,24 +387,46 @@ var stringOrBoolean = {
853
387
  };
854
388
 
855
389
  // src/wrappersUtils.ts
856
- function createPrototypeProxy(tagName) {
857
- const customElement = {
390
+ var emptyObject = {};
391
+ var makeReactWrapperFactory = (react, createComponent) => (options) => {
392
+ const tagName = options.tagName;
393
+ let customElementPrototype = emptyObject;
394
+ const elementClass = {
858
395
  name: tagName,
396
+ /**
397
+ * Lit's createComponent tries to access the elementClass.prototype in
398
+ * global scope (in development mode). The elementClass may not be defined
399
+ * yet (because we are in a lazy loading build, or because current app
400
+ * doesn't import a given custom element as it doesn't use it).
401
+ *
402
+ * Thus, we return an empty object as a fake prototype.
403
+ *
404
+ * Right after the call to `createComponent`, we set to
405
+ * customElementPrototype undefined so that the next access of
406
+ * `.prototype` tries to get the real prototype.
407
+ * `createPrototypeProxy()` is called, this small proxy delays retrieving the custom
408
+ * element prototype until it is actually needed, and caches the result for future calls.
409
+ */
859
410
  get prototype() {
860
- const customElementPrototype = customElements.get(tagName)?.prototype;
861
- if (!customElementPrototype) {
862
- if (process.env.NODE_ENV === "production") {
411
+ if (customElementPrototype === void 0) {
412
+ customElementPrototype = customElements.get(tagName)?.prototype;
413
+ if (!customElementPrototype) {
863
414
  throw new Error(`Custom element "${tagName}" not found`);
864
- } else {
865
- return Object.create(HTMLElement.prototype);
866
415
  }
416
+ Object.defineProperty(elementClass, "prototype", { value: customElementPrototype });
867
417
  }
868
- Object.defineProperty(customElement, "prototype", customElementPrototype);
869
418
  return customElementPrototype;
870
419
  }
871
420
  };
872
- return customElement;
873
- }
421
+ const result = createComponent({
422
+ ...options,
423
+ react,
424
+ elementClass
425
+ });
426
+ customElementPrototype = void 0;
427
+ return result;
428
+ };
429
+ var getReactWrapperOptions = (tagNameAndElement, events) => ({ tagName: tagNameAndElement, events });
874
430
  export {
875
431
  Fragment,
876
432
  LitElement,
@@ -879,13 +435,11 @@ export {
879
435
  bindEvent,
880
436
  bindProperty,
881
437
  createEvent,
882
- createPrototypeProxy,
883
438
  directive,
884
- dynamicValueDirective,
885
- handleComponentMetaUpdate,
886
- handleHmrUpdate,
439
+ getReactWrapperOptions,
887
440
  live,
888
441
  makeDefineCustomElements,
442
+ makeReactWrapperFactory,
889
443
  makeRuntime,
890
444
  method,
891
445
  noChange,
@@ -896,5 +450,7 @@ export {
896
450
  safeStyleMap,
897
451
  setAttribute,
898
452
  state,
899
- stringOrBoolean
453
+ stringOrBoolean,
454
+ useContextConsumer,
455
+ useContextProvider
900
456
  };