tempo-sdk 0.0.81 → 0.0.87

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 (50) hide show
  1. package/dist/astro.js +3 -3
  2. package/dist/canvas/astro.js +2 -2
  3. package/dist/canvas/index.d.ts +7 -0
  4. package/dist/canvas/index.js +4 -3
  5. package/dist/canvas/index.js.map +1 -1
  6. package/dist/canvas/interact-projection.js +2 -2
  7. package/dist/canvas/svelte.js +2 -2
  8. package/dist/canvas/vue.js +2 -2
  9. package/dist/{chunk-XFPFWTWX.js → chunk-2ZQMVAFM.js} +4 -1
  10. package/dist/{chunk-XFPFWTWX.js.map → chunk-2ZQMVAFM.js.map} +1 -1
  11. package/dist/{chunk-PRVU3F6M.js → chunk-AUG3ZWTR.js} +2 -2
  12. package/dist/{chunk-PRVU3F6M.js.map → chunk-AUG3ZWTR.js.map} +1 -1
  13. package/dist/{chunk-4XKABOQR.js → chunk-CXGAJRK7.js} +4 -3
  14. package/dist/{chunk-4XKABOQR.js.map → chunk-CXGAJRK7.js.map} +1 -1
  15. package/dist/{chunk-UBTL6JUF.js → chunk-DMT5MRMS.js} +4 -1
  16. package/dist/chunk-DMT5MRMS.js.map +1 -0
  17. package/dist/{chunk-VUCDEJ4Q.js → chunk-DNERBE7A.js} +68 -23
  18. package/dist/chunk-DNERBE7A.js.map +1 -0
  19. package/dist/{chunk-AFA3RUX4.js → chunk-GVH7HUMT.js} +2 -2
  20. package/dist/{chunk-AFA3RUX4.js.map → chunk-GVH7HUMT.js.map} +1 -1
  21. package/dist/{chunk-6SCRM7WZ.js → chunk-PPIIUCX5.js} +2 -2
  22. package/dist/{chunk-D6LZ7Z3W.js → chunk-PTL3UFIF.js} +2 -2
  23. package/dist/{chunk-D6LZ7Z3W.js.map → chunk-PTL3UFIF.js.map} +1 -1
  24. package/dist/{chunk-WNQ7HYZN.js → chunk-RQ54RXOY.js} +109 -57
  25. package/dist/chunk-RQ54RXOY.js.map +1 -0
  26. package/dist/expo/plugin.cjs +3 -0
  27. package/dist/expo/plugin.cjs.map +1 -1
  28. package/dist/expo/plugin.js +1 -1
  29. package/dist/expo-babel-plugin.cjs +3 -0
  30. package/dist/expo-babel-plugin.cjs.map +1 -1
  31. package/dist/expo-babel-plugin.js +1 -1
  32. package/dist/index.js +3 -3
  33. package/dist/nextjs/plugin.cjs +1 -1
  34. package/dist/nextjs/plugin.cjs.map +1 -1
  35. package/dist/nextjs/plugin.js +1 -1
  36. package/dist/nextjs-loader.cjs +4 -1
  37. package/dist/nextjs-loader.cjs.map +1 -1
  38. package/dist/nextjs.cjs +1 -1
  39. package/dist/nextjs.cjs.map +1 -1
  40. package/dist/nextjs.js +1 -1
  41. package/dist/nuxt/runtime/identity.js +1 -1
  42. package/dist/nuxt.js +5 -1
  43. package/dist/nuxt.js.map +1 -1
  44. package/dist/svelte.js +1 -1
  45. package/dist/vue.js +2 -2
  46. package/package.json +1 -1
  47. package/dist/chunk-UBTL6JUF.js.map +0 -1
  48. package/dist/chunk-VUCDEJ4Q.js.map +0 -1
  49. package/dist/chunk-WNQ7HYZN.js.map +0 -1
  50. /package/dist/{chunk-6SCRM7WZ.js.map → chunk-PPIIUCX5.js.map} +0 -0
@@ -81,7 +81,7 @@ import {
81
81
  watchDom,
82
82
  watchPortal,
83
83
  watchState
84
- } from "./chunk-VUCDEJ4Q.js";
84
+ } from "./chunk-DNERBE7A.js";
85
85
  import {
86
86
  captureAttributes,
87
87
  captureWithSupplementalRoots,
@@ -156,13 +156,14 @@ var browserClock = () => ({
156
156
  function createWorkScheduler(options = {}) {
157
157
  const clock = options.clock ?? browserClock();
158
158
  const budget = options.budgetMs ?? 2;
159
- const foregroundBudget = options.foregroundBudgetMs ?? budget;
159
+ const priorityBudget = options.priorityBudgetMs ?? budget;
160
160
  const timeout = options.timeoutMs ?? 50;
161
+ const highPriorityAgeMs = 500;
161
162
  const continuationTicks = 32;
162
163
  if (!(budget > 0 && Number.isFinite(budget)))
163
164
  throw new RangeError("budgetMs must be finite and positive");
164
- if (!(foregroundBudget > 0 && Number.isFinite(foregroundBudget)))
165
- throw new RangeError("foregroundBudgetMs must be finite and positive");
165
+ if (!(priorityBudget > 0 && Number.isFinite(priorityBudget)))
166
+ throw new RangeError("priorityBudgetMs must be finite and positive");
166
167
  const queues = {
167
168
  visible: /* @__PURE__ */ new Set(),
168
169
  background: /* @__PURE__ */ new Set(),
@@ -170,8 +171,22 @@ function createWorkScheduler(options = {}) {
170
171
  input: /* @__PURE__ */ new Set()
171
172
  };
172
173
  const interactive = /* @__PURE__ */ new Set();
173
- const foreground = /* @__PURE__ */ new Set();
174
- const foregroundListeners = /* @__PURE__ */ new Set();
174
+ const priorities = /* @__PURE__ */ new Map();
175
+ let highPriorityKeys = 0;
176
+ const rank = { low: 0, normal: 1, high: 2 };
177
+ const getPriority = (key) => {
178
+ if (key === void 0) return "normal";
179
+ if (typeof key === "symbol") return priorities.get(key) ?? "normal";
180
+ let result = key.length ? "low" : "normal";
181
+ for (const owner of key) {
182
+ const priority = priorities.get(owner) ?? "normal";
183
+ if (rank[priority] > rank[result]) result = priority;
184
+ }
185
+ return result;
186
+ };
187
+ const priorityOf = (job) => job.foreground?.() ? "high" : getPriority(job.key);
188
+ const high = (job) => job !== void 0 && priorityOf(job) === "high";
189
+ const paintWaits = /* @__PURE__ */ new Set();
175
190
  let frame = null;
176
191
  let idle = null;
177
192
  let taskPending = false;
@@ -185,7 +200,7 @@ function createWorkScheduler(options = {}) {
185
200
  let slices = 0, overruns = 0, maxSliceMs = 0;
186
201
  const count = () => queues.visible.size + queues.background.size + queues.frame.size + queues.input.size;
187
202
  const first = (queue) => queue.values().next().value;
188
- const frameBudget = () => foreground.size ? foregroundBudget : budget;
203
+ const frameBudget = () => highPriorityKeys ? priorityBudget : budget;
189
204
  const allowance = () => blockedUntilFrame ? 0 : Math.min(
190
205
  frameBudget() - spent,
191
206
  frameAt === null ? frameBudget() - spent : frameAt + interval - Math.max(2, interval * 0.35) - clock.now()
@@ -194,20 +209,19 @@ function createWorkScheduler(options = {}) {
194
209
  queues[job.priority].delete(job);
195
210
  job.signal?.removeEventListener("abort", job.abort);
196
211
  };
197
- const eligible = (job) => !foreground.size || job.foreground?.() === true;
198
212
  const candidate = (queue) => {
199
- let ordinary;
213
+ const oldest = first(queue);
214
+ let best = oldest;
200
215
  for (const job of queue) {
201
- if (job.foreground?.()) return job;
202
- if (!ordinary && eligible(job)) ordinary = job;
216
+ if (!best || rank[priorityOf(job)] > rank[priorityOf(best)]) best = job;
203
217
  }
204
- return ordinary;
218
+ return best;
205
219
  };
206
220
  const choose = (kind) => {
207
221
  if (kind === "frame" && interactive.size && queues.input.size)
208
222
  return first(queues.input);
209
223
  const urgentInput = candidate(queues.input);
210
- if (urgentInput?.foreground?.()) return urgentInput;
224
+ if (high(urgentInput)) return urgentInput;
211
225
  if (kind === "frame" && queues.input.size) return first(queues.input);
212
226
  if (interactive.size) return void 0;
213
227
  const candidates = [
@@ -215,9 +229,9 @@ function createWorkScheduler(options = {}) {
215
229
  candidate(queues.background),
216
230
  ...kind === "frame" ? [candidate(queues.frame)] : []
217
231
  ].filter((job) => !!job);
218
- const urgent = candidates.find((job) => job.foreground?.());
219
- if (urgent) return urgent;
220
- return candidates.filter((job) => clock.now() - job.at >= timeout).sort((a, b) => a.at - b.at)[0] ?? (kind === "frame" ? candidate(queues.frame) : void 0) ?? candidate(queues.visible) ?? candidate(queues.background);
232
+ return candidates.filter((job) => high(job) && clock.now() - job.at >= highPriorityAgeMs).sort((a, b) => a.at - b.at)[0] ?? candidates.sort(
233
+ (a, b) => rank[priorityOf(b)] - rank[priorityOf(a)] || (a.priority === "frame" ? -1 : b.priority === "frame" ? 1 : 0) || a.at - b.at
234
+ )[0];
221
235
  };
222
236
  async function pump(kind, deadline) {
223
237
  if (disposed || draining) return;
@@ -248,7 +262,7 @@ function createWorkScheduler(options = {}) {
248
262
  const current = job;
249
263
  job.run({
250
264
  hasTime,
251
- canContinue: () => active && eligible(current) && (!interactive.size || current.priority === "input") && hasTime() && choose(kind) === void 0
265
+ canContinue: () => active && (!interactive.size || current.priority === "input") && hasTime() && choose(kind) === void 0
252
266
  });
253
267
  runningInput = false;
254
268
  served = true;
@@ -268,8 +282,6 @@ function createWorkScheduler(options = {}) {
268
282
  function request() {
269
283
  if (disposed || draining || !count()) return;
270
284
  if (interactive.size && !queues.input.size) return;
271
- if (foreground.size && !queues.input.size && !Object.values(queues).some((queue) => candidate(queue)))
272
- return;
273
285
  if (frame === null)
274
286
  frame = clock.requestFrame((time) => {
275
287
  frame = null;
@@ -281,16 +293,16 @@ function createWorkScheduler(options = {}) {
281
293
  frameAt = time;
282
294
  spent = 0;
283
295
  blockedUntilFrame = false;
284
- if (queues.input.size || queues.frame.size || candidate(queues.visible)?.foreground?.() === true || candidate(queues.background)?.foreground?.() === true || [first(queues.visible), first(queues.background)].some(
296
+ if (queues.input.size || queues.frame.size || high(candidate(queues.visible)) || high(candidate(queues.background)) || [first(queues.visible), first(queues.background)].some(
285
297
  (job) => job && clock.now() - job.at >= timeout
286
298
  ))
287
299
  void pump("frame");
288
300
  request();
289
301
  });
290
302
  if (allowance() <= 0) return;
291
- const urgentInput = candidate(queues.input)?.foreground?.() === true;
303
+ const urgentInput = high(candidate(queues.input));
292
304
  if (interactive.size && !urgentInput) return;
293
- if ((urgentInput || candidate(queues.visible) || candidate(queues.background)?.foreground?.()) && !taskPending) {
305
+ if ((urgentInput || candidate(queues.visible) || high(candidate(queues.background))) && !taskPending) {
294
306
  taskPending = true;
295
307
  clock.task(() => {
296
308
  taskPending = false;
@@ -314,8 +326,36 @@ function createWorkScheduler(options = {}) {
314
326
  }
315
327
  }
316
328
  }
329
+ function afterPaint(signal) {
330
+ return new Promise((resolve, reject) => {
331
+ if (disposed || signal?.aborted) {
332
+ reject(signal?.reason ?? new Error("Work scheduler disposed"));
333
+ return;
334
+ }
335
+ let settled = false;
336
+ const frame2 = clock.requestFrame(() => {
337
+ clock.task(() => finish());
338
+ });
339
+ function finish(error) {
340
+ if (settled) return;
341
+ settled = true;
342
+ clock.cancelFrame(frame2);
343
+ paintWaits.delete(abort);
344
+ signal?.removeEventListener("abort", abort);
345
+ if (error) reject(error);
346
+ else resolve();
347
+ }
348
+ function abort() {
349
+ finish(signal?.reason ?? new Error("Work scheduler disposed"));
350
+ }
351
+ paintWaits.add(abort);
352
+ signal?.addEventListener("abort", abort, { once: true });
353
+ });
354
+ }
317
355
  const scheduler = {
318
356
  async run(steps, settings = {}) {
357
+ if (settings.afterPaint) await afterPaint(settings.signal);
358
+ const execution = settings.afterPaint ? { ...settings, afterPaint: false } : settings;
319
359
  for (; ; ) {
320
360
  const next = await scheduler.schedule((slice) => {
321
361
  let next2;
@@ -323,13 +363,17 @@ function createWorkScheduler(options = {}) {
323
363
  next2 = steps.next();
324
364
  } while (!next2.done && slice.hasTime());
325
365
  return next2;
326
- }, settings);
366
+ }, execution);
327
367
  if (disposed || settings.signal?.aborted)
328
368
  throw settings.signal?.reason ?? new Error("Work scheduler disposed");
329
369
  if (next.done) return next.value;
330
370
  }
331
371
  },
332
372
  schedule(work, settings = {}) {
373
+ if (settings.afterPaint)
374
+ return afterPaint(settings.signal).then(
375
+ () => scheduler.schedule(work, { ...settings, afterPaint: false })
376
+ );
333
377
  if (disposed || settings.signal?.aborted)
334
378
  return Promise.reject(
335
379
  settings.signal?.reason ?? new Error("Work scheduler disposed")
@@ -339,6 +383,7 @@ function createWorkScheduler(options = {}) {
339
383
  at: clock.now(),
340
384
  priority: settings.priority ?? "visible",
341
385
  signal: settings.signal,
386
+ key: settings.key,
342
387
  foreground: settings.foreground,
343
388
  abort() {
344
389
  remove(job);
@@ -362,25 +407,37 @@ function createWorkScheduler(options = {}) {
362
407
  request();
363
408
  });
364
409
  },
365
- hasForeground: () => foreground.size > 0,
366
- subscribeForeground(listener) {
367
- foregroundListeners.add(listener);
368
- return () => {
369
- foregroundListeners.delete(listener);
410
+ forKey(key) {
411
+ const withOwner = (settings = {}) => ({
412
+ ...settings,
413
+ key: settings.key === void 0 ? key : [
414
+ ...typeof key === "symbol" ? [key] : key,
415
+ ...typeof settings.key === "symbol" ? [settings.key] : settings.key
416
+ ]
417
+ });
418
+ return {
419
+ schedule: (work, settings) => scheduler.schedule(work, withOwner(settings)),
420
+ run: (steps, settings) => scheduler.run(steps, withOwner(settings))
370
421
  };
371
422
  },
372
- claimForeground() {
373
- const token = {};
374
- foreground.add(token);
375
- if (foreground.size === 1)
376
- for (const listener of foregroundListeners) listener();
423
+ promote(signal) {
424
+ for (const job of queues.background) {
425
+ if (job.signal !== signal) continue;
426
+ queues.background.delete(job);
427
+ job.priority = "visible";
428
+ queues.visible.add(job);
429
+ }
430
+ request();
431
+ },
432
+ getPriority,
433
+ setPriority(key, priority) {
434
+ const before = getPriority(key);
435
+ if (disposed || before === priority) return;
436
+ if (before === "high") highPriorityKeys--;
437
+ if (priority === "high") highPriorityKeys++;
438
+ if (priority === "normal") priorities.delete(key);
439
+ else priorities.set(key, priority);
377
440
  request();
378
- return () => {
379
- if (!foreground.delete(token)) return;
380
- if (foreground.size === 0)
381
- for (const listener of foregroundListeners) listener();
382
- request();
383
- };
384
441
  },
385
442
  claimInteractive() {
386
443
  const token = {};
@@ -392,23 +449,11 @@ function createWorkScheduler(options = {}) {
392
449
  request();
393
450
  };
394
451
  },
395
- promote(signal) {
396
- for (const job of queues.background) {
397
- if (job.signal !== signal) continue;
398
- queues.background.delete(job);
399
- job.priority = "visible";
400
- queues.visible.add(job);
401
- }
402
- request();
403
- },
404
452
  get diagnostics() {
405
453
  return {
406
454
  interactiveClaims: interactive.size,
407
- foregroundClaims: foreground.size,
408
- eligibleJobs: Object.values(queues).reduce(
409
- (total, queue) => total + [...queue].filter(eligible).length,
410
- 0
411
- ),
455
+ highPriorityKeys,
456
+ eligibleJobs: count(),
412
457
  queued: count(),
413
458
  oldestMs: Math.max(
414
459
  0,
@@ -424,6 +469,9 @@ function createWorkScheduler(options = {}) {
424
469
  },
425
470
  dispose() {
426
471
  disposed = true;
472
+ priorities.clear();
473
+ highPriorityKeys = 0;
474
+ for (const abort of paintWaits) abort();
427
475
  if (frame !== null) clock.cancelFrame(frame);
428
476
  if (idle !== null) clock.cancelIdle?.(idle);
429
477
  for (const queue of Object.values(queues))
@@ -841,8 +889,12 @@ function observeDocumentAssets(doc, listener) {
841
889
  if (!observer) {
842
890
  const listeners = /* @__PURE__ */ new Set();
843
891
  let active = true;
844
- const notify = (target) => {
845
- if (active) for (const callback of listeners) callback(target);
892
+ const notify = (target, kind) => {
893
+ if (active)
894
+ for (const callback of listeners) {
895
+ if (kind) callback(target, kind);
896
+ else callback(target);
897
+ }
846
898
  };
847
899
  const onResource = (event) => {
848
900
  const target = event.target;
@@ -851,7 +903,7 @@ function observeDocumentAssets(doc, listener) {
851
903
  else if (target?.localName === "link" && target.relList.contains("stylesheet"))
852
904
  notify(null);
853
905
  };
854
- const onFonts = () => notify(null);
906
+ const onFonts = () => notify(null, "font");
855
907
  doc.addEventListener("load", onResource, true);
856
908
  doc.addEventListener("error", onResource, true);
857
909
  for (const type of ["loading", "loadingdone", "loadingerror"])
@@ -8190,4 +8242,4 @@ function installTempoInteractProjectionSource() {
8190
8242
  export {
8191
8243
  installTempoInteractProjectionSource
8192
8244
  };
8193
- //# sourceMappingURL=chunk-WNQ7HYZN.js.map
8245
+ //# sourceMappingURL=chunk-RQ54RXOY.js.map