proto-autos-wc 0.1.118 → 0.1.119

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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-DblfkAfB.js');
3
+ var index = require('./index-CHtgcRuD.js');
4
4
  var appGlobals = require('./app-globals-V2Kpy_OQ.js');
5
5
 
6
6
  const defineCustomElements = async (win, options) => {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-DblfkAfB.js');
3
+ var index = require('./index-CHtgcRuD.js');
4
4
  var appGlobals = require('./app-globals-V2Kpy_OQ.js');
5
5
 
6
6
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
@@ -9,13 +9,40 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
9
9
  */
10
10
 
11
11
  var patchBrowser = () => {
12
+ if (index.BUILD.isDev && !index.BUILD.isTesting) {
13
+ index.consoleDevInfo("Running in development mode.");
14
+ }
15
+ if (index.BUILD.cloneNodeFix) {
16
+ patchCloneNodeFix(index.H.prototype);
17
+ }
18
+ const scriptElm = index.BUILD.scriptDataOpts ? index.win.document && Array.from(index.win.document.querySelectorAll("script")).find(
19
+ (s) => new RegExp(`/${index.NAMESPACE}(\\.esm)?\\.js($|\\?|#)`).test(s.src) || s.getAttribute("data-stencil-namespace") === index.NAMESPACE
20
+ ) : null;
12
21
  const importMeta = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('proto-autos-wc.cjs.js', document.baseURI).href));
13
- const opts = {};
22
+ const opts = index.BUILD.scriptDataOpts ? (scriptElm || {})["data-opts"] || {} : {};
14
23
  if (importMeta !== "") {
15
24
  opts.resourcesUrl = new URL(".", importMeta).href;
16
25
  }
17
26
  return index.promiseResolve(opts);
18
27
  };
28
+ var patchCloneNodeFix = (HTMLElementPrototype) => {
29
+ const nativeCloneNodeFn = HTMLElementPrototype.cloneNode;
30
+ HTMLElementPrototype.cloneNode = function(deep) {
31
+ if (this.nodeName === "TEMPLATE") {
32
+ return nativeCloneNodeFn.call(this, deep);
33
+ }
34
+ const clonedNode = nativeCloneNodeFn.call(this, false);
35
+ const srcChildNodes = this.childNodes;
36
+ if (deep) {
37
+ for (let i = 0; i < srcChildNodes.length; i++) {
38
+ if (srcChildNodes[i].nodeType !== 2) {
39
+ clonedNode.appendChild(srcChildNodes[i].cloneNode(true));
40
+ }
41
+ }
42
+ }
43
+ return clonedNode;
44
+ };
45
+ };
19
46
 
20
47
  patchBrowser().then(async (options) => {
21
48
  await appGlobals.globalScripts();
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-DblfkAfB.js');
3
+ var index = require('./index-CHtgcRuD.js');
4
4
 
5
5
  const KEY = 'proto-autos';
6
6
  const DATA = 'data';
@@ -23,12 +23,13 @@ const bag = {
23
23
  };
24
24
 
25
25
  const appendToMap = (map, propName, value) => {
26
- const items = map.get(propName);
27
- if (!items) {
28
- map.set(propName, [value]);
26
+ let refs = map.get(propName);
27
+ if (!refs) {
28
+ refs = [];
29
+ map.set(propName, refs);
29
30
  }
30
- else if (!items.includes(value)) {
31
- items.push(value);
31
+ if (!refs.some((ref) => ref.deref() === value)) {
32
+ refs.push(new WeakRef(value));
32
33
  }
33
34
  };
34
35
  const debounce = (fn, ms) => {
@@ -56,33 +57,54 @@ const debounce = (fn, ms) => {
56
57
  const isConnected = (maybeElement) => !('isConnected' in maybeElement) || maybeElement.isConnected;
57
58
  const cleanupElements = debounce((map) => {
58
59
  for (let key of map.keys()) {
59
- map.set(key, map.get(key).filter(isConnected));
60
+ const refs = map.get(key).filter((ref) => {
61
+ const elm = ref.deref();
62
+ return elm && isConnected(elm);
63
+ });
64
+ map.set(key, refs);
60
65
  }
61
66
  }, 2_000);
67
+ const core = index.StencilCore;
68
+ const forceUpdate = core.forceUpdate;
69
+ const getRenderingRef = core.getRenderingRef;
62
70
  const stencilSubscription = () => {
63
- if (typeof index.getRenderingRef !== 'function') {
71
+ if (typeof getRenderingRef !== 'function' || typeof forceUpdate !== 'function') {
64
72
  // If we are not in a stencil project, we do nothing.
65
73
  // This function is not really exported by @stencil/core.
66
74
  return {};
67
75
  }
76
+ const ensureForceUpdate = forceUpdate;
77
+ const ensureGetRenderingRef = getRenderingRef;
68
78
  const elmsToUpdate = new Map();
69
79
  return {
70
80
  dispose: () => elmsToUpdate.clear(),
71
81
  get: (propName) => {
72
- const elm = index.getRenderingRef();
82
+ const elm = ensureGetRenderingRef();
73
83
  if (elm) {
74
84
  appendToMap(elmsToUpdate, propName, elm);
75
85
  }
76
86
  },
77
87
  set: (propName) => {
78
- const elements = elmsToUpdate.get(propName);
79
- if (elements) {
80
- elmsToUpdate.set(propName, elements.filter(index.forceUpdate));
88
+ const refs = elmsToUpdate.get(propName);
89
+ if (refs) {
90
+ const nextRefs = refs.filter((ref) => {
91
+ const elm = ref.deref();
92
+ if (!elm)
93
+ return false;
94
+ return ensureForceUpdate(elm);
95
+ });
96
+ elmsToUpdate.set(propName, nextRefs);
81
97
  }
82
98
  cleanupElements(elmsToUpdate);
83
99
  },
84
100
  reset: () => {
85
- elmsToUpdate.forEach((elms) => elms.forEach(index.forceUpdate));
101
+ elmsToUpdate.forEach((refs) => {
102
+ refs.forEach((ref) => {
103
+ const elm = ref.deref();
104
+ if (elm)
105
+ ensureForceUpdate(elm);
106
+ });
107
+ });
86
108
  cleanupElements(elmsToUpdate);
87
109
  },
88
110
  };
@@ -90,8 +112,11 @@ const stencilSubscription = () => {
90
112
 
91
113
  const unwrap = (val) => (typeof val === 'function' ? val() : val);
92
114
  const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
93
- const unwrappedState = unwrap(defaultState);
94
- let states = new Map(Object.entries(unwrappedState ?? {}));
115
+ const resolveDefaultState = () => (unwrap(defaultState) ?? {});
116
+ const initialState = resolveDefaultState();
117
+ let states = new Map(Object.entries(initialState));
118
+ const proxyAvailable = typeof Proxy !== 'undefined';
119
+ const plainState = proxyAvailable ? null : {};
95
120
  const handlers = {
96
121
  dispose: [],
97
122
  get: [],
@@ -103,7 +128,10 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
103
128
  const reset = () => {
104
129
  // When resetting the state, the default state may be a function - unwrap it to invoke it.
105
130
  // otherwise, the state won't be properly reset
106
- states = new Map(Object.entries(unwrap(defaultState) ?? {}));
131
+ states = new Map(Object.entries(resolveDefaultState()));
132
+ if (!proxyAvailable) {
133
+ syncPlainStateKeys();
134
+ }
107
135
  handlers.reset.forEach((cb) => cb());
108
136
  };
109
137
  const dispose = () => {
@@ -120,12 +148,14 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
120
148
  const oldValue = states.get(propName);
121
149
  if (shouldUpdate(value, oldValue, propName)) {
122
150
  states.set(propName, value);
151
+ if (!proxyAvailable) {
152
+ ensurePlainProperty(propName);
153
+ }
123
154
  handlers.set.forEach((cb) => cb(propName, value, oldValue));
124
155
  }
125
156
  };
126
- const state = (typeof Proxy === 'undefined'
127
- ? {}
128
- : new Proxy(unwrappedState, {
157
+ const state = (proxyAvailable
158
+ ? new Proxy(initialState, {
129
159
  get(_, propName) {
130
160
  return get(propName);
131
161
  },
@@ -145,7 +175,11 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
145
175
  set(propName, value);
146
176
  return true;
147
177
  },
148
- }));
178
+ })
179
+ : (() => {
180
+ syncPlainStateKeys();
181
+ return plainState;
182
+ })());
149
183
  const on = (eventName, callback) => {
150
184
  handlers[eventName].push(callback);
151
185
  return () => {
@@ -158,7 +192,10 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
158
192
  cb(newValue);
159
193
  }
160
194
  };
161
- const resetHandler = () => cb(unwrap(defaultState)[propName]);
195
+ const resetHandler = () => {
196
+ const snapshot = resolveDefaultState();
197
+ cb(snapshot[propName]);
198
+ };
162
199
  // Register the handlers
163
200
  const unSet = on('set', setHandler);
164
201
  const unReset = on('reset', resetHandler);
@@ -201,6 +238,38 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
201
238
  changeListeners.delete(listener);
202
239
  }
203
240
  };
241
+ function ensurePlainProperty(key) {
242
+ if (proxyAvailable || !plainState) {
243
+ return;
244
+ }
245
+ if (Object.prototype.hasOwnProperty.call(plainState, key)) {
246
+ return;
247
+ }
248
+ Object.defineProperty(plainState, key, {
249
+ configurable: true,
250
+ enumerable: true,
251
+ get() {
252
+ return get(key);
253
+ },
254
+ set(value) {
255
+ set(key, value);
256
+ },
257
+ });
258
+ }
259
+ function syncPlainStateKeys() {
260
+ if (proxyAvailable || !plainState) {
261
+ return;
262
+ }
263
+ const knownKeys = new Set(states.keys());
264
+ for (const key of Object.keys(plainState)) {
265
+ if (!knownKeys.has(key)) {
266
+ delete plainState[key];
267
+ }
268
+ }
269
+ for (const key of knownKeys) {
270
+ ensurePlainProperty(key);
271
+ }
272
+ }
204
273
  return {
205
274
  state,
206
275
  get,