@tamagui/web 3.0.5 → 3.0.7

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 (40) hide show
  1. package/dist/cjs/_withNativeStyle.cjs +37 -20
  2. package/dist/cjs/_withNativeStyle.native.cjs +37 -20
  3. package/dist/cjs/_withNativeStyle.native.js +37 -20
  4. package/dist/cjs/_withNativeStyle.native.js.map +1 -1
  5. package/dist/cjs/createComponent.native.cjs +1 -0
  6. package/dist/cjs/createComponent.native.js +1 -0
  7. package/dist/cjs/createComponent.native.js.map +1 -1
  8. package/dist/cjs/helpers/getSplitStyles.cjs +2 -1
  9. package/dist/cjs/helpers/getSplitStyles.native.cjs +2 -1
  10. package/dist/cjs/helpers/getSplitStyles.native.js +2 -1
  11. package/dist/cjs/helpers/getSplitStyles.native.js.map +1 -1
  12. package/dist/cjs/helpers/nativeStyleEngine.cjs +80 -122
  13. package/dist/cjs/helpers/nativeStyleEngine.native.cjs +81 -161
  14. package/dist/cjs/helpers/nativeStyleEngine.native.js +81 -161
  15. package/dist/cjs/helpers/nativeStyleEngine.native.js.map +1 -1
  16. package/dist/esm/_withNativeStyle.mjs +38 -21
  17. package/dist/esm/_withNativeStyle.mjs.map +1 -1
  18. package/dist/esm/_withNativeStyle.native.js +38 -21
  19. package/dist/esm/_withNativeStyle.native.js.map +1 -1
  20. package/dist/esm/createComponent.native.js +2 -1
  21. package/dist/esm/createComponent.native.js.map +1 -1
  22. package/dist/esm/helpers/getSplitStyles.mjs +2 -1
  23. package/dist/esm/helpers/getSplitStyles.mjs.map +1 -1
  24. package/dist/esm/helpers/getSplitStyles.native.js +2 -1
  25. package/dist/esm/helpers/getSplitStyles.native.js.map +1 -1
  26. package/dist/esm/helpers/nativeStyleEngine.mjs +78 -122
  27. package/dist/esm/helpers/nativeStyleEngine.mjs.map +1 -1
  28. package/dist/esm/helpers/nativeStyleEngine.native.js +79 -161
  29. package/dist/esm/helpers/nativeStyleEngine.native.js.map +1 -1
  30. package/package.json +17 -17
  31. package/src/_withNativeStyle.tsx +67 -31
  32. package/src/createComponent.tsx +6 -1
  33. package/src/helpers/getSplitStyles.tsx +3 -0
  34. package/src/helpers/nativeStyleEngine.ts +118 -163
  35. package/types/_withNativeStyle.d.ts +4 -3
  36. package/types/_withNativeStyle.d.ts.map +1 -1
  37. package/types/createComponent.d.ts.map +1 -1
  38. package/types/helpers/getSplitStyles.d.ts.map +1 -1
  39. package/types/helpers/nativeStyleEngine.d.ts +26 -6
  40. package/types/helpers/nativeStyleEngine.d.ts.map +1 -1
@@ -20,10 +20,11 @@ var __copyProps = (to, from, except, desc) => {
20
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
21
  var nativeStyleEngine_exports = {};
22
22
  __export(nativeStyleEngine_exports, {
23
+ createNativeStyleLinkState: () => createNativeStyleLinkState,
23
24
  flushNativeStyleLinks: () => flushNativeStyleLinks,
24
25
  getNativeStyleEngine: () => getNativeStyleEngine,
25
26
  getNativeStyleEngineCacheStats: () => getNativeStyleEngineCacheStats,
26
- linkNativeStyleMapping: () => linkNativeStyleMapping,
27
+ linkNativeStyleHost: () => linkNativeStyleHost,
27
28
  nativeTextInputColorProps: () => nativeTextInputColorProps,
28
29
  normalizeNativeStyle: () => normalizeNativeStyle,
29
30
  queueNativeViewState: () => queueNativeViewState,
@@ -31,6 +32,7 @@ __export(nativeStyleEngine_exports, {
31
32
  resolveNativeStyleMapping: () => resolveNativeStyleMapping,
32
33
  setNativeStyleEngine: () => setNativeStyleEngine,
33
34
  setNativeStyleEngineFlushListener: () => setNativeStyleEngineFlushListener,
35
+ supersedeNativeViewStates: () => supersedeNativeViewStates,
34
36
  updateNativeStyleLink: () => updateNativeStyleLink,
35
37
  updateNativeStyleScope: () => updateNativeStyleScope
36
38
  });
@@ -137,11 +139,10 @@ function syncTableState(compiled, stateName, theme) {
137
139
  }
138
140
  function setNativeStyleEngine(next) {
139
141
  if (engine !== next) {
140
- settleReleases();
141
142
  compiledMappings.clear();
142
143
  scopeMappings.clear();
143
- pendingLinks = [];
144
- unlinkedPending = 0;
144
+ pendingHosts = [];
145
+ pendingStates = [];
145
146
  }
146
147
  engine = next;
147
148
  if (next) {
@@ -164,7 +165,7 @@ function updateNativeStyleScope(scopeId, stateName, theme) {
164
165
  if (engine) {
165
166
  const linked = scopeMappings.get(scopeId);
166
167
  if (linked) {
167
- for (const compiled of linked.keys()) {
168
+ for (const compiled of linked) {
168
169
  syncTableState(compiled, stateName, theme);
169
170
  }
170
171
  }
@@ -173,137 +174,83 @@ function updateNativeStyleScope(scopeId, stateName, theme) {
173
174
  }
174
175
  function removeNativeStyleScope(scopeId) {
175
176
  if (!scopeStates.delete(scopeId)) return;
177
+ queueMicrotask(() => {
178
+ if (!scopeStates.has(scopeId)) scopeMappings.delete(scopeId);
179
+ });
176
180
  engine?.removeScope(scopeId);
177
181
  }
178
182
  function resolveNativeStyleMapping(mapping, stateName, theme) {
179
183
  return resolveCompiledMapping(getCompiledMapping(mapping), stateName, theme).renderProps;
180
184
  }
181
- let pendingLinks = [];
182
- let unlinkedPending = 0;
183
- function trackScopeMapping(link, delta) {
184
- let linked = scopeMappings.get(link.scopeId);
185
- if (!linked) scopeMappings.set(link.scopeId, linked = /* @__PURE__ */ new Map());
186
- const count = (linked.get(link.compiled) ?? 0) + delta;
187
- if (count) {
188
- linked.set(link.compiled, count);
189
- } else {
190
- linked.delete(link.compiled);
191
- if (!linked.size) scopeMappings.delete(link.scopeId);
192
- }
185
+ function createNativeStyleLinkState(mapping, scopeId, stateName, theme) {
186
+ return {
187
+ mapping,
188
+ scopeId,
189
+ stateName,
190
+ theme
191
+ };
192
+ }
193
+ let pendingHosts = [];
194
+ let pendingStates = [];
195
+ const maxPendingHosts = 4096;
196
+ let idleFlushQueued = false;
197
+ function idleFlush() {
198
+ idleFlushQueued = false;
199
+ flushNativeStyleLinks();
200
+ }
201
+ function addScopeMapping(scopeId, compiled) {
202
+ let linked = scopeMappings.get(scopeId);
203
+ if (!linked) scopeMappings.set(scopeId, linked = /* @__PURE__ */ new Set());
204
+ linked.add(compiled);
193
205
  }
194
206
  function flushNativeStyleLinks() {
195
- settleReleases();
196
- if (!pendingLinks.length) return;
197
- const links = pendingLinks;
198
- pendingLinks = [];
199
- unlinkedPending = 0;
207
+ if (!pendingHosts.length) return;
208
+ const hosts = pendingHosts;
209
+ const states = pendingStates;
210
+ pendingHosts = [];
211
+ pendingStates = [];
200
212
  if (!engine) return;
201
- const live = links.filter((link) => link.id === 0);
202
- if (!live.length) return;
203
- const refs = [];
204
- const tableIds = [];
205
- const scopeIndexes = [];
213
+ const tableIds = new Array(hosts.length);
214
+ const scopeIndexes = new Array(hosts.length);
206
215
  const scopes = [];
207
- for (const link of live) {
208
- let scopeIndex = scopes.indexOf(link.scopeId);
209
- if (scopeIndex === -1) scopeIndex = scopes.push(link.scopeId) - 1;
210
- refs.push(link.ref);
211
- tableIds.push(link.compiled.tableId);
212
- scopeIndexes.push(scopeIndex);
213
- }
214
- const firstId = engine.linkTables(refs, tableIds, scopeIndexes, scopes);
215
- for (let i = 0; i < live.length; i++) {
216
- const link = live[i];
217
- link.id = firstId + i;
218
- link.owner = engine;
219
- link.ref = null;
220
- trackScopeMapping(link, 1);
221
- }
222
- }
223
- const releases = /* @__PURE__ */ new Map();
224
- let settleQueued = false;
225
- function settleReleases() {
226
- settleQueued = false;
227
- if (!releases.size) return;
228
- const settling = [...releases.values()];
229
- releases.clear();
230
- for (const release of settling) release.settle();
231
- }
232
- function releasable(ref, compiled, scopeId, id, settle) {
233
- const handle = {
234
- id,
235
- unlink: () => {
236
- const prior = releases.get(ref);
237
- if (prior && prior.handle !== handle) prior.settle();
238
- releases.set(ref, {
239
- compiled,
240
- scopeId,
241
- handle,
242
- settle
243
- });
244
- if (!settleQueued) {
245
- settleQueued = true;
246
- queueMicrotask(settleReleases);
247
- }
216
+ let last;
217
+ let tableId = 0;
218
+ let scopeIndex = 0;
219
+ for (let i = 0; i < hosts.length; i++) {
220
+ const state = states[i];
221
+ if (state !== last) {
222
+ last = state;
223
+ const compiled = getCompiledMapping(state.mapping);
224
+ syncTableState(compiled, state.stateName, state.theme);
225
+ addScopeMapping(state.scopeId, compiled);
226
+ tableId = compiled.tableId;
227
+ scopeIndex = scopes.indexOf(state.scopeId);
228
+ if (scopeIndex === -1) scopeIndex = scopes.push(state.scopeId) - 1;
248
229
  }
249
- };
250
- return handle;
230
+ tableIds[i] = tableId;
231
+ scopeIndexes[i] = scopeIndex;
232
+ }
233
+ engine.linkTables(hosts, tableIds, scopeIndexes, scopes);
251
234
  }
252
- function linkNativeStyleMapping(ref, mapping, scopeId, stateName, theme) {
253
- if (!engine) return null;
254
- const compiled = getCompiledMapping(mapping);
255
- const scopeState = scopeStates.get(scopeId);
256
- const stale = scopeState && (scopeState.name !== stateName || scopeState.theme !== theme);
257
- const kept = releases.get(ref);
258
- if (kept) {
259
- releases.delete(ref);
260
- if (!stale && kept.compiled === compiled && kept.scopeId === scopeId) return kept.handle;
261
- kept.settle();
235
+ function linkNativeStyleHost(host, state) {
236
+ if (!engine) return;
237
+ const live = scopeStates.get(state.scopeId);
238
+ if (live && (live.name !== state.stateName || live.theme !== state.theme)) {
239
+ const compiled = getCompiledMapping(state.mapping);
240
+ syncTableState(compiled, live.name, live.theme);
241
+ addScopeMapping(state.scopeId, compiled);
242
+ engine.link(host, compiled.tableId, state.scopeId, true);
243
+ return;
262
244
  }
263
- if (stale) {
264
- syncTableState(compiled, scopeState.name, scopeState.theme);
265
- const handle = engine.link(ref, compiled.tableId, scopeId, true);
266
- if (!handle) return null;
267
- const link2 = {
268
- ref: null,
269
- compiled,
270
- scopeId,
271
- id: handle.id,
272
- owner: engine
273
- };
274
- trackScopeMapping(link2, 1);
275
- return releasable(ref, compiled, scopeId, handle.id, () => {
276
- if (link2.id === -1) return;
277
- link2.id = -1;
278
- if (link2.owner === engine) trackScopeMapping(link2, -1);
279
- handle.unlink();
280
- });
245
+ pendingHosts.push(host);
246
+ pendingStates.push(state);
247
+ if (pendingHosts.length >= maxPendingHosts && !idleFlushQueued) {
248
+ idleFlushQueued = true;
249
+ requestIdleCallback(idleFlush);
281
250
  }
282
- syncTableState(compiled, stateName, theme);
283
- const link = {
284
- ref,
285
- compiled,
286
- scopeId,
287
- id: 0,
288
- owner: null
289
- };
290
- pendingLinks.push(link);
291
- return releasable(ref, compiled, scopeId, 0, () => {
292
- const id = link.id;
293
- if (id === -1) return;
294
- link.id = -1;
295
- link.ref = null;
296
- if (id > 0) {
297
- if (link.owner === engine) trackScopeMapping(link, -1);
298
- link.owner.unlink(id);
299
- } else if (++unlinkedPending > 512 && unlinkedPending * 2 > pendingLinks.length) {
300
- pendingLinks = pendingLinks.filter((pending2) => pending2.id === 0);
301
- unlinkedPending = 0;
302
- }
303
- });
304
251
  }
305
252
  const getNativeStyleEngineCacheStats = () => {
306
- const active = new Set([...scopeMappings.values()].flatMap((linked) => [...linked.keys()]));
253
+ const active = new Set([...scopeMappings.values()].flatMap((linked) => [...linked]));
307
254
  return {
308
255
  mappings: compiledMappings.size,
309
256
  activeMappings: active.size,
@@ -325,16 +272,27 @@ function updateNativeStyleLink(ref, host) {
325
272
  ref.nativeLink = engine.link(host, {});
326
273
  }
327
274
  }
275
+ let superseded = null;
328
276
  function queueNativeViewState(entry) {
329
277
  if (!engine) return;
330
278
  if (!pending) {
331
279
  pending = [];
332
280
  queueMicrotask(() => {
333
- const entries = pending;
281
+ let entries = pending;
282
+ const dropped = superseded;
334
283
  pending = null;
284
+ superseded = null;
285
+ if (dropped) {
286
+ entries = entries.filter((queued, index) => index >= (dropped.get(queued.id) ?? 0));
287
+ }
288
+ if (!entries.length) return;
335
289
  engine?.applyViewStates(entries);
336
290
  flushListener?.(entries);
337
291
  });
338
292
  }
339
293
  pending.push(entry);
340
294
  }
295
+ function supersedeNativeViewStates(id) {
296
+ if (!pending) return;
297
+ (superseded ||= /* @__PURE__ */ new Map()).set(id, pending.length);
298
+ }
@@ -22,10 +22,11 @@ var __copyProps = (to, from, except, desc) => {
22
22
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
23
  var nativeStyleEngine_exports = {};
24
24
  __export(nativeStyleEngine_exports, {
25
+ createNativeStyleLinkState: () => createNativeStyleLinkState,
25
26
  flushNativeStyleLinks: () => flushNativeStyleLinks,
26
27
  getNativeStyleEngine: () => getNativeStyleEngine,
27
28
  getNativeStyleEngineCacheStats: () => getNativeStyleEngineCacheStats,
28
- linkNativeStyleMapping: () => linkNativeStyleMapping,
29
+ linkNativeStyleHost: () => linkNativeStyleHost,
29
30
  nativeTextInputColorProps: () => nativeTextInputColorProps,
30
31
  normalizeNativeStyle: () => normalizeNativeStyle,
31
32
  queueNativeViewState: () => queueNativeViewState,
@@ -33,6 +34,7 @@ __export(nativeStyleEngine_exports, {
33
34
  resolveNativeStyleMapping: () => resolveNativeStyleMapping,
34
35
  setNativeStyleEngine: () => setNativeStyleEngine,
35
36
  setNativeStyleEngineFlushListener: () => setNativeStyleEngineFlushListener,
37
+ supersedeNativeViewStates: () => supersedeNativeViewStates,
36
38
  updateNativeStyleLink: () => updateNativeStyleLink,
37
39
  updateNativeStyleScope: () => updateNativeStyleScope
38
40
  });
@@ -177,11 +179,10 @@ function syncTableState(compiled, stateName, theme) {
177
179
  }
178
180
  function setNativeStyleEngine(next) {
179
181
  if (engine !== next) {
180
- settleReleases();
181
182
  compiledMappings.clear();
182
183
  scopeMappings.clear();
183
- pendingLinks = [];
184
- unlinkedPending = 0;
184
+ pendingHosts = [];
185
+ pendingStates = [];
185
186
  }
186
187
  engine = next;
187
188
  if (next) {
@@ -223,7 +224,7 @@ function updateNativeStyleScope(scopeId, stateName, theme) {
223
224
  if (linked) {
224
225
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
225
226
  try {
226
- for (var _iterator = linked.keys()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
227
+ for (var _iterator = linked[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
227
228
  var compiled = _step.value;
228
229
  syncTableState(compiled, stateName, theme);
229
230
  }
@@ -247,179 +248,84 @@ function updateNativeStyleScope(scopeId, stateName, theme) {
247
248
  }
248
249
  function removeNativeStyleScope(scopeId) {
249
250
  if (!scopeStates.delete(scopeId)) return;
251
+ queueMicrotask(function() {
252
+ if (!scopeStates.has(scopeId)) scopeMappings.delete(scopeId);
253
+ });
250
254
  engine === null || engine === void 0 ? void 0 : engine.removeScope(scopeId);
251
255
  }
252
256
  function resolveNativeStyleMapping(mapping, stateName, theme) {
253
257
  return resolveCompiledMapping(getCompiledMapping(mapping), stateName, theme).renderProps;
254
258
  }
255
- var pendingLinks = [];
256
- var unlinkedPending = 0;
257
- function trackScopeMapping(link, delta) {
258
- var linked = scopeMappings.get(link.scopeId);
259
- if (!linked) scopeMappings.set(link.scopeId, linked = /* @__PURE__ */ new Map());
260
- var _linked_get;
261
- var count = ((_linked_get = linked.get(link.compiled)) !== null && _linked_get !== void 0 ? _linked_get : 0) + delta;
262
- if (count) {
263
- linked.set(link.compiled, count);
264
- } else {
265
- linked.delete(link.compiled);
266
- if (!linked.size) scopeMappings.delete(link.scopeId);
267
- }
259
+ function createNativeStyleLinkState(mapping, scopeId, stateName, theme) {
260
+ return {
261
+ mapping,
262
+ scopeId,
263
+ stateName,
264
+ theme
265
+ };
266
+ }
267
+ var pendingHosts = [];
268
+ var pendingStates = [];
269
+ var maxPendingHosts = 4096;
270
+ var idleFlushQueued = false;
271
+ function idleFlush() {
272
+ idleFlushQueued = false;
273
+ flushNativeStyleLinks();
274
+ }
275
+ function addScopeMapping(scopeId, compiled) {
276
+ var linked = scopeMappings.get(scopeId);
277
+ if (!linked) scopeMappings.set(scopeId, linked = /* @__PURE__ */ new Set());
278
+ linked.add(compiled);
268
279
  }
269
280
  function flushNativeStyleLinks() {
270
- settleReleases();
271
- if (!pendingLinks.length) return;
272
- var links = pendingLinks;
273
- pendingLinks = [];
274
- unlinkedPending = 0;
281
+ if (!pendingHosts.length) return;
282
+ var hosts = pendingHosts;
283
+ var states = pendingStates;
284
+ pendingHosts = [];
285
+ pendingStates = [];
275
286
  if (!engine) return;
276
- var live = links.filter(function(link2) {
277
- return link2.id === 0;
278
- });
279
- if (!live.length) return;
280
- var refs = [];
281
- var tableIds = [];
282
- var scopeIndexes = [];
287
+ var tableIds = new Array(hosts.length);
288
+ var scopeIndexes = new Array(hosts.length);
283
289
  var scopes = [];
284
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
285
- try {
286
- for (var _iterator = live[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
287
- var link = _step.value;
288
- var scopeIndex = scopes.indexOf(link.scopeId);
289
- if (scopeIndex === -1) scopeIndex = scopes.push(link.scopeId) - 1;
290
- refs.push(link.ref);
291
- tableIds.push(link.compiled.tableId);
292
- scopeIndexes.push(scopeIndex);
290
+ var last;
291
+ var tableId = 0;
292
+ var scopeIndex = 0;
293
+ for (var i = 0; i < hosts.length; i++) {
294
+ var state = states[i];
295
+ if (state !== last) {
296
+ last = state;
297
+ var compiled = getCompiledMapping(state.mapping);
298
+ syncTableState(compiled, state.stateName, state.theme);
299
+ addScopeMapping(state.scopeId, compiled);
300
+ tableId = compiled.tableId;
301
+ scopeIndex = scopes.indexOf(state.scopeId);
302
+ if (scopeIndex === -1) scopeIndex = scopes.push(state.scopeId) - 1;
293
303
  }
294
- } catch (err) {
295
- _didIteratorError = true;
296
- _iteratorError = err;
297
- } finally {
298
- try {
299
- if (!_iteratorNormalCompletion && _iterator.return != null) {
300
- _iterator.return();
301
- }
302
- } finally {
303
- if (_didIteratorError) {
304
- throw _iteratorError;
305
- }
306
- }
307
- }
308
- var firstId = engine.linkTables(refs, tableIds, scopeIndexes, scopes);
309
- for (var i = 0; i < live.length; i++) {
310
- var link1 = live[i];
311
- link1.id = firstId + i;
312
- link1.owner = engine;
313
- link1.ref = null;
314
- trackScopeMapping(link1, 1);
304
+ tableIds[i] = tableId;
305
+ scopeIndexes[i] = scopeIndex;
315
306
  }
307
+ engine.linkTables(hosts, tableIds, scopeIndexes, scopes);
316
308
  }
317
- var releases = /* @__PURE__ */ new Map();
318
- var settleQueued = false;
319
- function settleReleases() {
320
- settleQueued = false;
321
- if (!releases.size) return;
322
- var settling = [...releases.values()];
323
- releases.clear();
324
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
325
- try {
326
- for (var _iterator = settling[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
327
- var release = _step.value;
328
- release.settle();
329
- }
330
- } catch (err) {
331
- _didIteratorError = true;
332
- _iteratorError = err;
333
- } finally {
334
- try {
335
- if (!_iteratorNormalCompletion && _iterator.return != null) {
336
- _iterator.return();
337
- }
338
- } finally {
339
- if (_didIteratorError) {
340
- throw _iteratorError;
341
- }
342
- }
343
- }
344
- }
345
- function releasable(ref, compiled, scopeId, id, settle) {
346
- var handle = {
347
- id,
348
- unlink: function() {
349
- var prior = releases.get(ref);
350
- if (prior && prior.handle !== handle) prior.settle();
351
- releases.set(ref, {
352
- compiled,
353
- scopeId,
354
- handle,
355
- settle
356
- });
357
- if (!settleQueued) {
358
- settleQueued = true;
359
- queueMicrotask(settleReleases);
360
- }
361
- }
362
- };
363
- return handle;
364
- }
365
- function linkNativeStyleMapping(ref, mapping, scopeId, stateName, theme) {
366
- if (!engine) return null;
367
- var compiled = getCompiledMapping(mapping);
368
- var scopeState = scopeStates.get(scopeId);
369
- var stale = scopeState && (scopeState.name !== stateName || scopeState.theme !== theme);
370
- var kept = releases.get(ref);
371
- if (kept) {
372
- releases.delete(ref);
373
- if (!stale && kept.compiled === compiled && kept.scopeId === scopeId) return kept.handle;
374
- kept.settle();
309
+ function linkNativeStyleHost(host, state) {
310
+ if (!engine) return;
311
+ var live = scopeStates.get(state.scopeId);
312
+ if (live && (live.name !== state.stateName || live.theme !== state.theme)) {
313
+ var compiled = getCompiledMapping(state.mapping);
314
+ syncTableState(compiled, live.name, live.theme);
315
+ addScopeMapping(state.scopeId, compiled);
316
+ engine.link(host, compiled.tableId, state.scopeId, true);
317
+ return;
375
318
  }
376
- if (stale) {
377
- syncTableState(compiled, scopeState.name, scopeState.theme);
378
- var handle = engine.link(ref, compiled.tableId, scopeId, true);
379
- if (!handle) return null;
380
- var link = {
381
- ref: null,
382
- compiled,
383
- scopeId,
384
- id: handle.id,
385
- owner: engine
386
- };
387
- trackScopeMapping(link, 1);
388
- return releasable(ref, compiled, scopeId, handle.id, function() {
389
- if (link.id === -1) return;
390
- link.id = -1;
391
- if (link.owner === engine) trackScopeMapping(link, -1);
392
- handle.unlink();
393
- });
319
+ pendingHosts.push(host);
320
+ pendingStates.push(state);
321
+ if (pendingHosts.length >= maxPendingHosts && !idleFlushQueued) {
322
+ idleFlushQueued = true;
323
+ requestIdleCallback(idleFlush);
394
324
  }
395
- syncTableState(compiled, stateName, theme);
396
- var link1 = {
397
- ref,
398
- compiled,
399
- scopeId,
400
- id: 0,
401
- owner: null
402
- };
403
- pendingLinks.push(link1);
404
- return releasable(ref, compiled, scopeId, 0, function() {
405
- var id = link1.id;
406
- if (id === -1) return;
407
- link1.id = -1;
408
- link1.ref = null;
409
- if (id > 0) {
410
- if (link1.owner === engine) trackScopeMapping(link1, -1);
411
- link1.owner.unlink(id);
412
- } else if (++unlinkedPending > 512 && unlinkedPending * 2 > pendingLinks.length) {
413
- pendingLinks = pendingLinks.filter(function(pending2) {
414
- return pending2.id === 0;
415
- });
416
- unlinkedPending = 0;
417
- }
418
- });
419
325
  }
420
326
  var getNativeStyleEngineCacheStats = function() {
421
327
  var active = new Set([...scopeMappings.values()].flatMap(function(linked) {
422
- return [...linked.keys()];
328
+ return [...linked];
423
329
  }));
424
330
  return {
425
331
  mappings: compiledMappings.size,
@@ -444,16 +350,30 @@ function updateNativeStyleLink(ref, host) {
444
350
  ref.nativeLink = engine.link(host, {});
445
351
  }
446
352
  }
353
+ var superseded = null;
447
354
  function queueNativeViewState(entry) {
448
355
  if (!engine) return;
449
356
  if (!pending) {
450
357
  pending = [];
451
358
  queueMicrotask(function() {
452
359
  var entries = pending;
360
+ var dropped = superseded;
453
361
  pending = null;
362
+ superseded = null;
363
+ if (dropped) {
364
+ entries = entries.filter(function(queued, index) {
365
+ var _dropped_get;
366
+ return index >= ((_dropped_get = dropped.get(queued.id)) !== null && _dropped_get !== void 0 ? _dropped_get : 0);
367
+ });
368
+ }
369
+ if (!entries.length) return;
454
370
  engine === null || engine === void 0 ? void 0 : engine.applyViewStates(entries);
455
371
  flushListener === null || flushListener === void 0 ? void 0 : flushListener(entries);
456
372
  });
457
373
  }
458
374
  pending.push(entry);
459
375
  }
376
+ function supersedeNativeViewStates(id) {
377
+ if (!pending) return;
378
+ (superseded || (superseded = /* @__PURE__ */ new Map())).set(id, pending.length);
379
+ }