@arcgis/lumina 4.32.0-next.4 → 4.32.0-next.41

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,33 +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-DNENDZQM.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, keyTrackResolve } from "@arcgis/components-controllers";
12
- var createEventFactory = (eventName = "", options = {}, component = retrieveComponent()) => {
25
+ import { retrieveComponent as retrieveComponent2, trackPropertyKey, keyTrackResolve } 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" && !component.el.isConnected) {
30
+ if (typeof process === "object" && process.env.NODE_ENV !== "production" && isEsriInternalEnv() && !component.el.isConnected) {
16
31
  console.warn(
17
32
  `Trying to emit an ${eventName} event on a disconnected element ${component.el.tagName.toLowerCase()}`
18
33
  );
19
34
  }
20
35
  if (eventName === "") {
21
36
  keyTrackResolve();
22
- if (process.env.NODE_ENV !== "production" && eventName === "") {
37
+ if (typeof process === "object" && process.env.NODE_ENV !== "production" && isEsriInternalEnv() && eventName === "") {
23
38
  throw new Error("Unable to resolve event name from property name");
24
39
  }
25
40
  }
26
41
  const event = new CustomEvent(eventName, {
27
42
  detail: payload,
28
- cancelable: defaultEventCancelable,
29
- bubbles: defaultEventBubbles,
30
- composed: defaultEventComposed,
43
+ cancelable: true,
44
+ bubbles: true,
45
+ composed: true,
31
46
  ...options
32
47
  });
33
48
  component.el.dispatchEvent(event);
@@ -38,7 +53,7 @@ var createEventFactory = (eventName = "", options = {}, component = retrieveComp
38
53
  trackPropertyKey(
39
54
  component,
40
55
  (key) => {
41
- if (process.env.NODE_ENV !== "production" && key === void 0) {
56
+ if (typeof process === "object" && process.env.NODE_ENV !== "production" && isEsriInternalEnv() && key === void 0) {
42
57
  throw new Error(`createEvent must be called in property default value only`);
43
58
  }
44
59
  eventName = key;
@@ -56,493 +71,8 @@ import { property as litProperty } from "@lit/reactive-element/decorators/proper
56
71
  var property = litProperty;
57
72
  var method = void 0;
58
73
 
59
- // src/lazyLoad.ts
60
- import { Deferred, camelToKebab } from "@arcgis/components-utils";
61
-
62
- // src/devOnlyDetectIncorrectLazyUsages.ts
63
- function devOnlyDetectIncorrectLazyUsages(LitClass) {
64
- const genericPrototype = LitClass.prototype;
65
- const descriptor = Object.getOwnPropertyDescriptor(genericPrototype, "innerText");
66
- if (descriptor !== void 0 && descriptor.get === descriptor.set) {
67
- return;
68
- }
69
- const allowList = /* @__PURE__ */ new Set([
70
- // We shouldn't be overwriting this property
71
- "constructor",
72
- // Called by Lit - we proxy it to this.el in ProxyComponent
73
- "setAttribute",
74
- // Called by Lit SSR - we proxy it to this.el in ProxyComponent
75
- "removeAttribute",
76
- // Called by Lit - we proxy it to this.el in ProxyComponent
77
- "isConnected",
78
- // Called by Lit, but only in dev mode for warnings, so we don't have to proxy.
79
- "localName"
80
- ]);
81
- const customErrorMessages = {
82
- addEventListener: "use this.listen() or this.el.addEventListener()"
83
- };
84
- Object.entries({
85
- ...Object.getOwnPropertyDescriptors(HTMLElement.prototype),
86
- ...Object.getOwnPropertyDescriptors(Element.prototype),
87
- ...Object.getOwnPropertyDescriptors(Node.prototype),
88
- ...Object.getOwnPropertyDescriptors(EventTarget.prototype)
89
- }).forEach(([key, value]) => {
90
- if (allowList.has(key)) {
91
- return;
92
- }
93
- const callback = (...args) => {
94
- if (key === "hasAttribute" && args[0] === "defer-hydration") {
95
- return false;
96
- }
97
- throw new Error(
98
- `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}`}`
99
- );
100
- };
101
- if (typeof value.value === "function") {
102
- genericPrototype[key] = callback;
103
- } else {
104
- Object.defineProperty(genericPrototype, key, { get: callback, set: callback });
105
- }
106
- });
107
- }
108
-
109
- // src/lifecycleSupport.ts
110
- function attachToAncestor(child) {
111
- let ancestor = child;
112
- while (ancestor = ancestor.parentNode ?? ancestor.host) {
113
- if (ancestor?.constructor?.lumina) {
114
- const litParent = ancestor;
115
- if (!litParent.manager?.loadedCalled) {
116
- litParent._offspring.push(child);
117
- }
118
- return litParent._postLoad.promise;
119
- }
120
- }
121
- return false;
122
- }
123
-
124
- // src/utils.ts
125
- var noShadowRoot = {};
126
-
127
- // src/lazyLoad.ts
128
- var makeDefineCustomElements = (runtime, structure) => function defineCustomElements(windowOrOptions, options) {
129
- if (!globalThis.customElements) {
130
- return;
131
- }
132
- const resolvedOptions = options ?? windowOrOptions ?? {};
133
- const resourcesUrl = resolvedOptions.resourcesUrl;
134
- if (resourcesUrl) {
135
- runtime.setAssetPath(resourcesUrl);
136
- }
137
- Object.entries(structure).forEach(createLazyElement);
138
- };
139
- function createLazyElement([tagName, [load, compactMeta = ""]]) {
140
- if (customElements.get(tagName)) {
141
- return;
142
- }
143
- const [compactObservedProps, compactAsyncMethods, compactSyncMethods] = compactMeta.split(lazyMetaGroupJoiner);
144
- const observedProps = compactObservedProps ? compactObservedProps?.split(lazyMetaItemJoiner).map(parseCondensedProp) : void 0;
145
- const observedProperties = observedProps?.map(([property2]) => property2);
146
- const ProxyClass = class extends ProxyComponent {
147
- static {
148
- this.observedAttributes = observedProps?.map(([, attribute]) => attribute).filter((attribute) => attribute !== "");
149
- }
150
- static {
151
- this._properties = observedProperties;
152
- }
153
- static {
154
- this._asyncMethods = compactAsyncMethods ? compactAsyncMethods?.split(lazyMetaItemJoiner) : void 0;
155
- }
156
- static {
157
- this._syncMethods = compactSyncMethods?.split(lazyMetaItemJoiner);
158
- }
159
- static {
160
- this._name = tagName;
161
- }
162
- constructor() {
163
- const isFirstInstanceOfType = !ProxyClass._loadPromise;
164
- if (isFirstInstanceOfType) {
165
- ProxyClass._loadPromise = load();
166
- ProxyClass._initializePrototype();
167
- }
168
- super();
169
- }
170
- };
171
- customElements.define(tagName, ProxyClass);
172
- }
173
- var defineProperty = Object.defineProperty;
174
- function parseCondensedProp(propAndAttribute) {
175
- const name = propAndAttribute.split(lazyMetaSubItemJoiner);
176
- return name.length === 1 ? [name[0], camelToKebab(name[0])] : name;
177
- }
178
- var HtmlElement = globalThis.HTMLElement ?? parseCondensedProp;
179
- var ProxyComponent = class extends HtmlElement {
180
- constructor() {
181
- super();
182
- /** @internal */
183
- this._store = {};
184
- /**
185
- * If attributeChangedCallback() is called before the LitElement is loaded,
186
- * store the attributes here, and replay later
187
- */
188
- this._pendingAttributes = [];
189
- /**
190
- * Resolved once LitElement's load() is complete.
191
- * Not read inside of this class, but needed for LitElement to determine if
192
- * it's closest ancestor finished load()
193
- */
194
- this._postLoad = new Deferred();
195
- /**
196
- * Resolved once LitElement's loaded() is complete
197
- */
198
- this._postLoaded = new Deferred();
199
- /**
200
- * Direct offspring that should be awaited before loaded() is emitted
201
- */
202
- this._offspring = [];
203
- if (process.env.NODE_ENV !== "production") {
204
- this._hmrSetProps = /* @__PURE__ */ new Set();
205
- this._hmrSetAttributes = /* @__PURE__ */ new Set();
206
- globalThis.devOnly$createdElements ??= [];
207
- globalThis.devOnly$createdElements.push(new WeakRef(this));
208
- }
209
- this._saveInstanceProperties();
210
- const ProxyClass = this.constructor;
211
- if (ProxyClass._LitConstructor) {
212
- this._initializeComponent({ a: ProxyClass._LitConstructor });
213
- } else {
214
- void ProxyClass._loadPromise.then(this._initializeComponent.bind(this)).catch((error) => {
215
- this._postLoaded.reject(error);
216
- setTimeout(() => {
217
- throw error;
218
- });
219
- });
220
- }
221
- if (process.env.NODE_ENV !== "production") {
222
- ProxyClass._hmrInstances ??= [];
223
- ProxyClass._hmrInstances.push(new WeakRef(this));
224
- Object.defineProperty(this, "_store", {
225
- value: this._store,
226
- enumerable: false,
227
- configurable: true
228
- });
229
- }
230
- }
231
- static {
232
- this.lumina = true;
233
- }
234
- /** @internal */
235
- static _initializePrototype() {
236
- this._properties?.forEach(this._bindProp, this);
237
- this._asyncMethods?.forEach(this._bindAsync, this);
238
- this._syncMethods?.forEach(this._bindSync, this);
239
- }
240
- static _bindProp(propName) {
241
- defineProperty(this.prototype, propName, {
242
- configurable: true,
243
- enumerable: true,
244
- get() {
245
- return this._store[propName];
246
- },
247
- set(value) {
248
- this._store[propName] = value;
249
- if (process.env.NODE_ENV !== "production") {
250
- this._hmrSetProps.add(propName);
251
- }
252
- }
253
- });
254
- }
255
- static _bindAsync(methodName) {
256
- defineProperty(this.prototype, methodName, {
257
- async value(...args) {
258
- if (!this._litElement) {
259
- await this._postLoaded.promise;
260
- }
261
- const genericLitElement = this._litElement;
262
- return await genericLitElement[methodName](...args);
263
- },
264
- configurable: true
265
- });
266
- }
267
- static _bindSync(methodName) {
268
- defineProperty(this.prototype, methodName, {
269
- value(...args) {
270
- if (process.env.NODE_ENV === "development" && !this._litElement) {
271
- const ProxyClass = this.constructor;
272
- throw new Error(
273
- `Tried to call method ${methodName}() on <${ProxyClass._name}> component before it's fully loaded. Please do 'await component.componentOnReady();' before calling this method.`
274
- );
275
- }
276
- const genericLitElement = this._litElement;
277
- return genericLitElement[methodName](...args);
278
- },
279
- configurable: true
280
- });
281
- }
282
- get manager() {
283
- return this._litElement?.manager;
284
- }
285
- /**
286
- * Until the custom element is registered on the page, an instance of that
287
- * element can be constructed and some properties on that instance set.
288
- *
289
- * These properties are set before the element prototype is set to this proxy
290
- * class and thus none of our getters/setters are yet registered - such
291
- * properties will be set by JavaScript on the instance directly.
292
- *
293
- * Once element is registered, the properties set in the meanwhile will shadow
294
- * the getter/setters, and thus break reactivity. The fix is to delete these
295
- * properties from the instance, and re-apply them once accessors are set.
296
- *
297
- * @example
298
- * ```ts
299
- * import { defineCustomElements } from '@arcgis/map-components';
300
- * const map = document.createElement('arcgis-map');
301
- * // This will shadow the getter/setters
302
- * map.itemId = '...';
303
- * // This finally defines the custom elements and sets the property accessors
304
- * defineCustomElements();
305
- * ```
306
- *
307
- * @remarks
308
- * This is an equivalent of the __saveInstanceProperties method in Lit's
309
- * ReactiveElement. Lit takes care of this on LitElement, but we have to take
310
- * care of this on the lazy proxy
311
- */
312
- _saveInstanceProperties() {
313
- const ProxyClass = this.constructor;
314
- const genericThis = this;
315
- ProxyClass._properties?.forEach((propName) => {
316
- if (Object.hasOwn(this, propName)) {
317
- this._store[propName] = genericThis[propName];
318
- delete genericThis[propName];
319
- }
320
- });
321
- }
322
- /*
323
- * This method must be statically present rather than added later, or else,
324
- * browsers won't call it. Same for connected and disconnected callbacks.
325
- */
326
- attributeChangedCallback(name, oldValue, newValue) {
327
- this._litElement?.attributeChangedCallback(name, oldValue, newValue);
328
- if (!this._litElement) {
329
- this._pendingAttributes.push(name);
330
- }
331
- if (process.env.NODE_ENV !== "production") {
332
- this._hmrSetAttributes.add(name);
333
- }
334
- }
335
- connectedCallback() {
336
- if (this._litElement) {
337
- this._litElement.connectedCallback();
338
- } else {
339
- queueMicrotask(() => {
340
- this._ancestorLoad = attachToAncestor(this);
341
- });
342
- }
343
- }
344
- disconnectedCallback() {
345
- this._litElement?.disconnectedCallback();
346
- }
347
- /**
348
- * Create a promise that resolves once component is fully loaded
349
- */
350
- async componentOnReady() {
351
- await this._postLoaded.promise;
352
- return this._litElement;
353
- }
354
- /** @internal */
355
- _initializeComponent(module) {
356
- const ProxyClass = this.constructor;
357
- const tagName = ProxyClass._name;
358
- if (process.env.NODE_ENV !== "production") {
359
- Object.entries(module).forEach(([name, LitConstructor2]) => {
360
- if (name !== "exportsForTests" && typeof LitConstructor2 !== "function" || typeof LitConstructor2.tagName !== "string") {
361
- console.warn(
362
- `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.`
363
- );
364
- }
365
- });
366
- }
367
- const LitConstructor = Object.values(module).find(
368
- (LitConstructor2) => LitConstructor2.tagName === tagName
369
- );
370
- if (process.env.NODE_ENV !== "production" && !LitConstructor) {
371
- throw new Error(
372
- `Unable to find the LitElement class for the "${tagName}" custom element in the lazy-loaded module`
373
- );
374
- }
375
- const lazyTagName = process.env.NODE_ENV === "production" ? `${tagName}--lazy` : (ProxyClass._hmrIndex ?? 0) === 0 ? `${tagName}--lazy` : `${tagName}--lazy-${ProxyClass._hmrIndex}`;
376
- const isFirstInitialization = !ProxyClass._LitConstructor;
377
- if (isFirstInitialization) {
378
- ProxyClass._LitConstructor = LitConstructor;
379
- LitConstructor.prototype.removeAttribute = function(qualifiedName) {
380
- HTMLElement.prototype.removeAttribute.call(this.el, qualifiedName);
381
- };
382
- LitConstructor.prototype.setAttribute = function(qualifiedName, value) {
383
- HTMLElement.prototype.setAttribute.call(this.el, qualifiedName, value);
384
- };
385
- defineProperty(LitConstructor.prototype, "isConnected", {
386
- get() {
387
- return this.el.isConnected;
388
- }
389
- });
390
- if (process.env.NODE_ENV !== "production" && LitConstructor.shadowRootOptions !== noShadowRoot) {
391
- let prototype = LitConstructor;
392
- while (prototype && !Object.hasOwn(prototype, "lumina")) {
393
- prototype = Object.getPrototypeOf(prototype);
394
- }
395
- devOnlyDetectIncorrectLazyUsages(prototype);
396
- }
397
- customElements.define(lazyTagName, LitConstructor);
398
- }
399
- LitConstructor.lazy = this;
400
- const litElement = document.createElement(lazyTagName);
401
- LitConstructor.lazy = void 0;
402
- if (process.env.NODE_ENV !== "production") {
403
- Object.defineProperty(this, "_litElement", {
404
- value: litElement,
405
- configurable: true,
406
- enumerable: false
407
- });
408
- } else {
409
- this._litElement = litElement;
410
- }
411
- this._pendingAttributes.forEach((name) => {
412
- const value = this.getAttribute(name);
413
- litElement.attributeChangedCallback(
414
- name,
415
- // Lit doesn't look at this value, thus even if attribute already exists, that's ok
416
- null,
417
- value
418
- );
419
- });
420
- Object.entries(this._store).forEach(syncLitElement, litElement);
421
- this._store = litElement;
422
- if (process.env.NODE_ENV !== "production") {
423
- const litObserved = LitConstructor.observedAttributes ?? [];
424
- const lazyObserved = ProxyClass.observedAttributes ?? [];
425
- const missingFromLazy = litObserved.filter((attribute) => !lazyObserved.includes(attribute));
426
- const missingFromLit = lazyObserved.filter((attribute) => !litObserved.includes(attribute));
427
- if (missingFromLazy.length > 0) {
428
- console.warn(
429
- `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`
430
- );
431
- }
432
- if (missingFromLit.length > 0) {
433
- console.warn(
434
- `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`
435
- );
436
- }
437
- }
438
- const isStillConnected = this.isConnected;
439
- if (isStillConnected || this._ancestorLoad) {
440
- litElement.connectedCallback?.();
441
- if (!isStillConnected) {
442
- litElement.disconnectedCallback();
443
- }
444
- }
445
- }
446
- };
447
- function syncLitElement([key, value]) {
448
- this[key] = value;
449
- }
450
-
451
- // src/hmrSupport.ts
452
- import { camelToKebab as camelToKebab2 } from "@arcgis/components-utils";
453
- function handleHmrUpdate(newModules) {
454
- newModules.forEach((newModule) => {
455
- if (newModule === void 0) {
456
- return;
457
- }
458
- Object.values(newModule).forEach((exported) => {
459
- if (typeof exported !== "function" || typeof exported.tagName !== "string") {
460
- return;
461
- }
462
- const LitConstructor = exported;
463
- const ProxyClass = customElements.get(LitConstructor.tagName);
464
- if (ProxyClass === void 0) {
465
- throw new Error(`Failed to find custom element proxy for tag name: ${LitConstructor.tagName}`);
466
- }
467
- ProxyClass._LitConstructor = void 0;
468
- ProxyClass._loadPromise = void 0;
469
- ProxyClass._hmrIndex ??= 0;
470
- ProxyClass._hmrIndex += 1;
471
- ProxyClass._initializePrototype();
472
- ProxyClass._hmrInstances?.forEach((instanceWeakRef) => {
473
- const instance = instanceWeakRef.deref();
474
- if (instance === void 0) {
475
- return;
476
- }
477
- if (instance._litElement === void 0) {
478
- void ProxyClass._loadPromise.then(() => reInitialize(instance, newModule));
479
- } else {
480
- reInitialize(instance, newModule);
481
- }
482
- });
483
- return;
484
- });
485
- });
486
- }
487
- function reInitialize(instance, newModule) {
488
- const PreviousLitConstructor = instance._litElement.constructor;
489
- const properties = PreviousLitConstructor.elementProperties;
490
- const preservedProperties = Array.from(properties.entries()).filter(
491
- ([propertyName, descriptor]) => typeof propertyName === "string" && (instance._hmrSetProps.has(propertyName) || typeof descriptor.attribute === "string" && instance._hmrSetAttributes.has(descriptor.attribute))
492
- ).map(([key]) => [key, instance[key]]);
493
- instance._store = Object.fromEntries(preservedProperties);
494
- const isConnected = instance.isConnected;
495
- if (isConnected) {
496
- instance._litElement.disconnectedCallback();
497
- }
498
- instance._initializeComponent(newModule);
499
- }
500
- function handleComponentMetaUpdate(meta) {
501
- const ProxyClass = customElements.get(meta.tagName);
502
- if (ProxyClass === void 0) {
503
- return;
504
- }
505
- const attributes = meta.properties.map(([property2, attribute]) => attribute ?? camelToKebab2(property2)).filter(Boolean);
506
- observedAttributes[meta.tagName] ??= {};
507
- observedAttributes[meta.tagName].original ??= new Set(ProxyClass.observedAttributes);
508
- const originallyObserved = observedAttributes[meta.tagName].original;
509
- observedAttributes[meta.tagName].manuallyObserved ??= new Set(
510
- /**
511
- * Never manually observe attributes that were in the original
512
- * observedAttributes as those would be observed by the browser
513
- */
514
- attributes.filter((attribute) => !originallyObserved.has(attribute))
515
- );
516
- ProxyClass._asyncMethods = meta.asyncMethods;
517
- ProxyClass._syncMethods = meta.syncMethods;
518
- ProxyClass._properties = meta.properties.map(([name]) => name);
519
- ProxyClass.observedAttributes = attributes;
520
- }
521
- var observedAttributesSymbol = Symbol.for("@arcgis/lumina:observedAttributes");
522
- var globalThisWithObservedAttributes = globalThis;
523
- var alreadyHadObservers = observedAttributesSymbol in globalThisWithObservedAttributes;
524
- globalThisWithObservedAttributes[observedAttributesSymbol] ??= {};
525
- var observedAttributes = globalThisWithObservedAttributes[observedAttributesSymbol];
526
- if (!alreadyHadObservers) {
527
- const makeObserver = (original) => function observeAttributes(qualifiedName, ...rest) {
528
- const observed = observedAttributes[this.tagName.toLowerCase()]?.manuallyObserved;
529
- if (observed?.has(qualifiedName)) {
530
- const oldValue = this.getAttribute(qualifiedName);
531
- const returns = original.call(this, qualifiedName, ...rest);
532
- const newValue = this.getAttribute(qualifiedName);
533
- this.attributeChangedCallback(qualifiedName, oldValue, newValue);
534
- return returns;
535
- } else {
536
- return original.call(this, qualifiedName, ...rest);
537
- }
538
- };
539
- ProxyComponent.prototype.setAttribute = makeObserver(ProxyComponent.prototype.setAttribute);
540
- ProxyComponent.prototype.toggleAttribute = makeObserver(ProxyComponent.prototype.toggleAttribute);
541
- ProxyComponent.prototype.removeAttribute = makeObserver(ProxyComponent.prototype.removeAttribute);
542
- }
543
-
544
74
  // src/LitElement.ts
545
- import { Deferred as Deferred2, camelToKebab as camelToKebab3 } from "@arcgis/components-utils";
75
+ import { Deferred, camelToKebab, isEsriInternalEnv as isEsriInternalEnv2 } from "@arcgis/components-utils";
546
76
  import { LitElement as OriginalLitElement, isServer } from "lit";
547
77
  import { useControllerManager } from "@arcgis/components-controllers";
548
78
  var emptyFunction = () => void 0;
@@ -576,7 +106,7 @@ var LitElement = class _LitElement extends OriginalLitElement {
576
106
  */
577
107
  this.manager = useControllerManager(this);
578
108
  /** @internal */
579
- this._postLoad = this.constructor.lazy?._postLoad ?? new Deferred2();
109
+ this._postLoad = this.constructor.lazy?._postLoad ?? new Deferred();
580
110
  /**
581
111
  * Direct offspring that should be awaited before loaded() is emitted.
582
112
  *
@@ -585,7 +115,7 @@ var LitElement = class _LitElement extends OriginalLitElement {
585
115
  * @internal
586
116
  */
587
117
  this._offspring = this.constructor.lazy?._offspring ?? [];
588
- this._postLoaded = this.constructor.lazy?._postLoaded ?? new Deferred2();
118
+ this._postLoaded = this.constructor.lazy?._postLoaded ?? new Deferred();
589
119
  this._enableUpdating = this.enableUpdating;
590
120
  this.enableUpdating = emptyFunction;
591
121
  const ourShouldUpdate = _LitElement.prototype.shouldUpdate;
@@ -593,20 +123,22 @@ var LitElement = class _LitElement extends OriginalLitElement {
593
123
  this._originalShouldUpdate = this.shouldUpdate;
594
124
  this.shouldUpdate = ourShouldUpdate;
595
125
  }
596
- if (process.env.NODE_ENV !== "production") {
126
+ if (typeof process === "object" && process.env.NODE_ENV !== "production" && isEsriInternalEnv2()) {
597
127
  globalThis.devOnly$luminaComponentRefCallback?.(this);
598
128
  }
599
129
  if (isServer) {
600
130
  this.el.setAttribute(this.constructor.runtime.hydratedAttribute, "");
601
131
  }
602
132
  }
133
+ /**
134
+ * Customize Lit's default style handling to support non-shadow-root styles
135
+ */
603
136
  static finalizeStyles(styles) {
604
- if (process.env.NODE_ENV === "test" && Array.isArray(styles)) {
137
+ if (typeof process === "object" && process.env.NODE_ENV === "test" && Array.isArray(styles)) {
605
138
  styles = styles.filter(Boolean);
606
139
  }
607
140
  const finalizedStyles = super.finalizeStyles(styles);
608
- const options = this.constructor.shadowRootOptions;
609
- const useLightDom = options === noShadowRoot;
141
+ const useLightDom = this.shadowRootOptions === noShadowRoot;
610
142
  return this.runtime?.commonStyles === void 0 || useLightDom ? finalizedStyles : [this.runtime.commonStyles, ...finalizedStyles];
611
143
  }
612
144
  static createProperty(name, options) {
@@ -629,7 +161,7 @@ var LitElement = class _LitElement extends OriginalLitElement {
629
161
  *
630
162
  * Thus, overwriting Lit's default behavior to use kebab-case:
631
163
  */
632
- attribute: !!(flags & 1 /* ATTRIBUTE */) && typeof name === "string" ? camelToKebab3(name) : false,
164
+ attribute: !!(flags & 1 /* ATTRIBUTE */) && typeof name === "string" ? camelToKebab(name) : false,
633
165
  reflect: !!(flags & 2 /* REFLECT */),
634
166
  type: flags & 4 /* BOOLEAN */ ? Boolean : flags & 8 /* NUMBER */ ? Number : void 0,
635
167
  /**
@@ -682,7 +214,7 @@ var LitElement = class _LitElement extends OriginalLitElement {
682
214
  value: renderRoot
683
215
  });
684
216
  if (existingShadowRoot) {
685
- if (process.env.NODE_ENV === "production") {
217
+ if (typeof process !== "object" || process.env.NODE_ENV === "production") {
686
218
  OriginalLitElement.prototype.createRenderRoot.call(this);
687
219
  }
688
220
  return existingShadowRoot;
@@ -754,7 +286,7 @@ var LitElement = class _LitElement extends OriginalLitElement {
754
286
  }
755
287
  };
756
288
  LitElement.$createEvent = createEventFactory;
757
- if (process.env.NODE_ENV !== "production") {
289
+ if (typeof process === "object" && process.env.NODE_ENV !== "production" && isEsriInternalEnv2()) {
758
290
  const globalWithLit = globalThis;
759
291
  globalWithLit.litIssuedWarnings ??= /* @__PURE__ */ new Set();
760
292
  globalWithLit.litIssuedWarnings.add(
@@ -763,6 +295,7 @@ if (process.env.NODE_ENV !== "production") {
763
295
  }
764
296
 
765
297
  // src/runtime.ts
298
+ import { isEsriInternalEnv as isEsriInternalEnv3 } from "@arcgis/components-utils";
766
299
  function makeRuntime(options) {
767
300
  let assetPath;
768
301
  const setAssetPath = (path) => {
@@ -785,7 +318,7 @@ function makeRuntime(options) {
785
318
  }
786
319
  };
787
320
  setAssetPath(options.defaultAssetPath);
788
- if (process.env.NODE_ENV !== "production") {
321
+ if (typeof process === "object" && process.env.NODE_ENV !== "production" && isEsriInternalEnv3()) {
789
322
  globalThis.devOnly$luminaRuntime = runtime;
790
323
  }
791
324
  return runtime;
@@ -824,24 +357,46 @@ var stringOrBoolean = {
824
357
  };
825
358
 
826
359
  // src/wrappersUtils.ts
827
- function createPrototypeProxy(tagName) {
828
- const customElement = {
360
+ var emptyObject = {};
361
+ var makeReactWrapperFactory = (react, createComponent) => (options) => {
362
+ const tagName = options.tagName;
363
+ let customElementPrototype = emptyObject;
364
+ const elementClass = {
829
365
  name: tagName,
366
+ /**
367
+ * Lit's createComponent tries to access the elementClass.prototype in
368
+ * global scope (in development mode). The elementClass may not be defined
369
+ * yet (because we are in a lazy loading build, or because current app
370
+ * doesn't import a given custom element as it doesn't use it).
371
+ *
372
+ * Thus, we return an empty object as a fake prototype.
373
+ *
374
+ * Right after the call to `createComponent`, we set to
375
+ * customElementPrototype undefined so that the next access of
376
+ * `.prototype` tries to get the real prototype.
377
+ * `createPrototypeProxy()` is called, this small proxy delays retrieving the custom
378
+ * element prototype until it is actually needed, and caches the result for future calls.
379
+ */
830
380
  get prototype() {
831
- const customElementPrototype = customElements.get(tagName)?.prototype;
832
- if (!customElementPrototype) {
833
- if (process.env.NODE_ENV === "production") {
381
+ if (customElementPrototype === void 0) {
382
+ customElementPrototype = customElements.get(tagName)?.prototype;
383
+ if (!customElementPrototype) {
834
384
  throw new Error(`Custom element "${tagName}" not found`);
835
- } else {
836
- return Object.create(HTMLElement.prototype);
837
385
  }
386
+ Object.defineProperty(elementClass, "prototype", { value: customElementPrototype });
838
387
  }
839
- Object.defineProperty(customElement, "prototype", customElementPrototype);
840
388
  return customElementPrototype;
841
389
  }
842
390
  };
843
- return customElement;
844
- }
391
+ const result = createComponent({
392
+ ...options,
393
+ react,
394
+ elementClass
395
+ });
396
+ customElementPrototype = void 0;
397
+ return result;
398
+ };
399
+ var getReactWrapperOptions = (tagNameAndElement, events) => ({ tagName: tagNameAndElement, events });
845
400
  export {
846
401
  Fragment,
847
402
  LitElement,
@@ -850,12 +405,11 @@ export {
850
405
  bindEvent,
851
406
  bindProperty,
852
407
  createEvent,
853
- createPrototypeProxy,
854
408
  directive,
855
- handleComponentMetaUpdate,
856
- handleHmrUpdate,
409
+ getReactWrapperOptions,
857
410
  live,
858
411
  makeDefineCustomElements,
412
+ makeReactWrapperFactory,
859
413
  makeRuntime,
860
414
  method,
861
415
  noChange,
@@ -866,5 +420,7 @@ export {
866
420
  safeStyleMap,
867
421
  setAttribute,
868
422
  state,
869
- stringOrBoolean
423
+ stringOrBoolean,
424
+ useContextConsumer,
425
+ useContextProvider
870
426
  };