@vinena/knobs 0.7.1 → 0.7.2

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.
@@ -83,7 +83,7 @@ import {
83
83
  uaPreset,
84
84
  userAgentOf,
85
85
  viewportOf
86
- } from "./react-tet7swk2.js";
86
+ } from "./react-zj0dbpdg.js";
87
87
  import {
88
88
  FRAME_ATTRIBUTE,
89
89
  FRAME_NAME,
@@ -3678,6 +3678,7 @@ function buildChrome(full, mini, look) {
3678
3678
 
3679
3679
  // src/engine/safaridraw.ts
3680
3680
  var DOMAIN_WEIGHT = 500;
3681
+ var DOMAIN_PAD = 0.15;
3681
3682
  var SAFARI_CSS = `
3682
3683
  .safari {
3683
3684
  color: #000;
@@ -3746,14 +3747,27 @@ var SAFARI_CSS = `
3746
3747
  .safari .glyph.off { stroke-opacity: 0.3; fill-opacity: 0.3; }
3747
3748
  .safari .domain {
3748
3749
  left: 50%;
3750
+ /* A host that does not fit keeps its end and loses its start, never to an ellipsis. */
3751
+ display: flex;
3752
+ justify-content: flex-end;
3749
3753
  white-space: nowrap;
3750
3754
  overflow: hidden;
3751
- text-overflow: ellipsis;
3752
- text-align: center;
3753
3755
  font-size: ${SAFARI_TEXT.field}px;
3754
3756
  font-weight: ${DOMAIN_WEIGHT};
3757
+ /* Its box is one line high, less than the font's ascent and descent: padded the same above and below, a g's tail is drawn whole and the baseline stays. */
3758
+ padding-block: ${DOMAIN_PAD}em;
3755
3759
  transform: translate(-50%, -50%);
3756
- }
3760
+ /* Its start fades over 9 px where it is cut; where it fits, the fade slides out past the start. */
3761
+ -webkit-mask-image: linear-gradient(to right, transparent, #000 9px);
3762
+ mask-image: linear-gradient(to right, transparent, #000 9px);
3763
+ -webkit-mask-size: calc(100% + 9px) 100%;
3764
+ mask-size: calc(100% + 9px) 100%;
3765
+ -webkit-mask-repeat: no-repeat;
3766
+ mask-repeat: no-repeat;
3767
+ -webkit-mask-position: -9px 0;
3768
+ mask-position: -9px 0;
3769
+ }
3770
+ .safari .domain[data-cut="true"] { -webkit-mask-position: 0 0; mask-position: 0 0; }
3757
3771
  .safari .time { font-weight: 600; transform: translate(-50%, -50%); }
3758
3772
  .safari .status { fill: currentColor; }
3759
3773
  /* The battery's uncharged rest: #b2b2b2 on white, #808080 on black. */
@@ -3778,7 +3792,10 @@ var SAFARI_CSS = `
3778
3792
  transition:
3779
3793
  top var(--main) ${MORPH.ease},
3780
3794
  height var(--main) ${MORPH.ease},
3781
- transform var(--main) ${MORPH.ease};
3795
+ transform var(--main) ${MORPH.ease},
3796
+ max-width var(--main) ${MORPH.ease},
3797
+ -webkit-mask-position var(--main) ${MORPH.ease},
3798
+ mask-position var(--main) ${MORPH.ease};
3782
3799
  }
3783
3800
  /* The parts only the expanded bars have: an icon swap, out early, in late. */
3784
3801
  .safari .full {
@@ -4046,19 +4063,59 @@ function pressOf(glyph, actions) {
4046
4063
  return actions.reload;
4047
4064
  return;
4048
4065
  }
4066
+ var GLYPH_BOX = 30;
4049
4067
  function glyphIn(mark, origin, className, actions) {
4050
- const svg = glyphAt(mark, GLYPHS2, 30, className, pressOf(mark.glyph, actions));
4051
- svg.style.left = `${mark.x - origin.x - 15}px`;
4052
- svg.style.top = `${mark.y - origin.y - 15}px`;
4068
+ const svg = glyphAt(mark, GLYPHS2, GLYPH_BOX, className, pressOf(mark.glyph, actions));
4069
+ svg.style.left = `${mark.x - origin.x - GLYPH_BOX / 2}px`;
4070
+ svg.style.top = `${mark.y - origin.y - GLYPH_BOX / 2}px`;
4053
4071
  return svg;
4054
4072
  }
4055
4073
  function domainOf(host) {
4056
4074
  return host.replace(/:\d+$/, "");
4057
4075
  }
4058
- function pillBox(pill, host) {
4059
- const size = pill.text?.size ?? SAFARI_TEXT.pill;
4060
- const width = Math.round(textWidth(domainOf(host), size, DOMAIN_WEIGHT)) + (pill.text?.pad ?? 0);
4061
- return { x: pill.x - width / 2, y: pill.y, width, height: pill.height };
4076
+ var PILL_MARGIN = 16;
4077
+ var MARK_CLEAR = 21;
4078
+ var FIELD_LEAST = 13;
4079
+ var FIT_STEPS = 6;
4080
+ var FIT_SLACK = 0.5;
4081
+ function domainRoom(shape, host, width) {
4082
+ const middle = shape.text?.x ?? shape.x + shape.width / 2;
4083
+ if (shape.kind === "pill") {
4084
+ const text = Math.ceil(textWidth(domainOf(host), shape.text?.size ?? SAFARI_TEXT.pill, DOMAIN_WEIGHT));
4085
+ const most = 2 * (Math.min(middle, width - middle) - PILL_MARGIN) - (shape.text?.pad ?? 0);
4086
+ return Math.max(0, Math.min(text, most));
4087
+ }
4088
+ let half = shape.width / 2;
4089
+ for (const { x } of shape.marks) {
4090
+ half = Math.min(half, Math.abs(x - middle) - (shape.text?.clear ?? MARK_CLEAR));
4091
+ }
4092
+ return Math.max(0, 2 * half);
4093
+ }
4094
+ function domainFit(shape, host, width) {
4095
+ const room = domainRoom(shape, host, width);
4096
+ const text = domainOf(host);
4097
+ if (shape.kind === "pill") {
4098
+ const size2 = shape.text?.size ?? SAFARI_TEXT.pill;
4099
+ return { size: size2, room, cut: room < textWidth(text, size2, DOMAIN_WEIGHT) };
4100
+ }
4101
+ let size = shape.text?.size ?? SAFARI_TEXT.field;
4102
+ for (let step = 0;step < FIT_STEPS && size > FIELD_LEAST; step++) {
4103
+ const advance = textWidth(text, size, DOMAIN_WEIGHT);
4104
+ if (advance <= room + FIT_SLACK)
4105
+ break;
4106
+ size = Math.max(FIELD_LEAST, size * room / advance);
4107
+ }
4108
+ return { size, room, cut: textWidth(text, size, DOMAIN_WEIGHT) > room + FIT_SLACK };
4109
+ }
4110
+ function pillBox(pill, host, width) {
4111
+ const box2 = domainRoom(pill, host, width) + (pill.text?.pad ?? 0);
4112
+ return { x: pill.x - box2 / 2, y: pill.y, width: box2, height: pill.height };
4113
+ }
4114
+ function drawnScale(node) {
4115
+ if (typeof getComputedStyle !== "function")
4116
+ return 1;
4117
+ const scale = /^matrix\(([^,]+),/.exec(getComputedStyle(node).transform)?.[1];
4118
+ return Number(scale) || 1;
4062
4119
  }
4063
4120
  function hslOf({ red, green, blue }) {
4064
4121
  const [r, g, b] = [red / 255, green / 255, blue / 255];
@@ -4185,14 +4242,16 @@ function buildSafari(full, mini, look, actions) {
4185
4242
  const main = pill ? full.shapes.find((shape) => shape.kind === "card") ?? full.shapes.find((shape) => shape.text !== undefined) ?? null : null;
4186
4243
  let surface = null;
4187
4244
  let domain = null;
4245
+ const screen = turn(full.screen, full.orientation).width;
4246
+ const texts = [];
4188
4247
  const glyphs = [];
4189
4248
  const keep2 = (node, glyph) => {
4190
4249
  glyphs.push({ node, glyph });
4191
4250
  return node;
4192
4251
  };
4252
+ const field = full.shapes.find((shape) => shape.kind === "field");
4193
4253
  if (main && pill) {
4194
4254
  surface = el("div", main.kind === "card" ? "surface from-card" : "surface");
4195
- const field = full.shapes.find((shape) => shape.kind === "field");
4196
4255
  if (field) {
4197
4256
  const inner = el("div", "field full");
4198
4257
  placeBox(inner, { ...field, x: field.x - main.x, y: field.y - main.y }, field.radius);
@@ -4213,7 +4272,6 @@ function buildSafari(full, mini, look, actions) {
4213
4272
  }
4214
4273
  domain = el("div", "domain");
4215
4274
  const text = (field ?? main).text;
4216
- domain.style.maxWidth = `${(field ?? main).width - 96}px`;
4217
4275
  domain.dataset.top = String((text?.y ?? main.y) - main.y);
4218
4276
  surface.append(domain);
4219
4277
  const expand = actions.expand;
@@ -4249,7 +4307,7 @@ function buildSafari(full, mini, look, actions) {
4249
4307
  if (shape.text) {
4250
4308
  const text = el("div", "domain");
4251
4309
  text.style.top = `${shape.text.y - shape.y}px`;
4252
- text.style.maxWidth = `${shape.width - 96}px`;
4310
+ texts.push({ node: text, shape });
4253
4311
  side.append(text);
4254
4312
  }
4255
4313
  root.append(side);
@@ -4268,6 +4326,12 @@ function buildSafari(full, mini, look, actions) {
4268
4326
  for (const text of Array.from(root.querySelectorAll(".domain"))) {
4269
4327
  text.textContent = domainOf(sight.host);
4270
4328
  }
4329
+ for (const { node, shape } of texts) {
4330
+ const fit = domainFit(shape, sight.host, screen);
4331
+ node.style.fontSize = `${fit.size}px`;
4332
+ node.style.maxWidth = `${fit.room}px`;
4333
+ node.dataset.cut = String(fit.cut);
4334
+ }
4271
4335
  for (const { node, box: box2 } of sides)
4272
4336
  tintGlass(node, box2, sight);
4273
4337
  for (const { node, glyph } of glyphs) {
@@ -4276,13 +4340,33 @@ function buildSafari(full, mini, look, actions) {
4276
4340
  node.classList.toggle("press", !off && pressOf(glyph, actions) !== undefined);
4277
4341
  }
4278
4342
  if (surface && domain && main && pill) {
4279
- const box2 = minimized ? pillBox(pill, sight.host) : main;
4343
+ const box2 = minimized ? pillBox(pill, sight.host, screen) : main;
4280
4344
  placeBox(surface, box2, minimized ? pill.radius : main.radius);
4281
4345
  tintGlass(surface, box2, sight);
4346
+ const shown2 = minimized ? pill : field ?? main;
4347
+ const { size, room, cut } = domainFit(shown2, sight.host, screen);
4348
+ const was = Number(domain.dataset.size) || size;
4349
+ const turned = domain.dataset.min !== undefined && domain.dataset.min !== String(minimized);
4350
+ domain.dataset.size = String(size);
4351
+ domain.dataset.min = String(minimized);
4352
+ domain.dataset.cut = String(cut);
4353
+ if (turned && was !== size) {
4354
+ const seen = domain.getBoundingClientRect().width;
4355
+ const host = domainOf(sight.host);
4356
+ const advance = textWidth(host, was, DOMAIN_WEIGHT) / textWidth(host, size, DOMAIN_WEIGHT);
4357
+ const scale = drawnScale(domain) * (advance || was / size);
4358
+ domain.style.transitionProperty = "top, height, -webkit-mask-position, mask-position";
4359
+ domain.style.fontSize = `${size}px`;
4360
+ domain.style.transform = `translate(-50%, -50%) scale(${scale})`;
4361
+ domain.style.maxWidth = `${seen / scale}px`;
4362
+ domain.offsetWidth;
4363
+ domain.style.transitionProperty = "";
4364
+ }
4365
+ domain.style.fontSize = `${size}px`;
4366
+ domain.style.maxWidth = `${room}px`;
4282
4367
  const top = minimized ? pill.height / 2 : Number(domain.dataset.top);
4283
4368
  domain.style.top = `${top}px`;
4284
- const scale = minimized ? (pill.text?.size ?? SAFARI_TEXT.pill) / SAFARI_TEXT.field : 1;
4285
- domain.style.transform = `translate(-50%, -50%) scale(${scale})`;
4369
+ domain.style.transform = "translate(-50%, -50%)";
4286
4370
  }
4287
4371
  },
4288
4372
  loading(on, still2) {
@@ -4764,7 +4848,8 @@ function drawMedia(pen, media, rect, style) {
4764
4848
  }
4765
4849
  if (style.imageRendering === "pixelated" || style.imageRendering === "crisp-edges")
4766
4850
  pen.imageSmoothingEnabled = false;
4767
- pen.drawImage(media.source, from.x, from.y, from.width, from.height, to.x, to.y, to.width, to.height);
4851
+ const scale = media.scale ?? 1;
4852
+ pen.drawImage(media.source, from.x * scale, from.y * scale, from.width * scale, from.height * scale, to.x, to.y, to.width, to.height);
4768
4853
  pen.restore();
4769
4854
  }
4770
4855
  function picturesKey(doc) {
@@ -4992,7 +5077,19 @@ function blankPictures(live, copy) {
4992
5077
  image.setAttribute("src", blankUrl(from.naturalWidth, from.naturalHeight));
4993
5078
  });
4994
5079
  }
4995
- function copyPage(frame2, leave) {
5080
+ var NO_CONTROLS = "video::-webkit-media-controls { display: none !important; }";
5081
+ function cuts(overflow) {
5082
+ return overflow === "hidden" || overflow === "auto" || overflow === "scroll" || overflow === "clip";
5083
+ }
5084
+ function viewportOverflow(doc, view) {
5085
+ const root = doc.documentElement;
5086
+ const style = view.getComputedStyle(root);
5087
+ if (cuts(style.overflowX) || cuts(style.overflowY))
5088
+ return root;
5089
+ const { body } = doc;
5090
+ return body?.localName === "body" && body.parentElement === root ? body : null;
5091
+ }
5092
+ function copyPage(frame2, leave, each) {
4996
5093
  const doc = frame2.contentDocument;
4997
5094
  if (!doc?.documentElement)
4998
5095
  return null;
@@ -5032,7 +5129,7 @@ ${own.join(`
5032
5129
  const inert = doc.implementation.createHTMLDocument("");
5033
5130
  const root = inert.importNode(doc.documentElement, true);
5034
5131
  pin(doc.documentElement, root);
5035
- if (leave || pinned) {
5132
+ if (leave || pinned || each) {
5036
5133
  const live = doc.documentElement.getElementsByTagName("*");
5037
5134
  const copied = root.getElementsByTagName("*");
5038
5135
  for (let index = 0;index < live.length; index++) {
@@ -5043,15 +5140,25 @@ ${own.join(`
5043
5140
  if (leave?.(node))
5044
5141
  markOwn(copy);
5045
5142
  pin(node, copy);
5143
+ each?.(node, copy);
5046
5144
  }
5047
5145
  }
5048
5146
  blankPictures(doc.documentElement, root);
5147
+ const lifted = view ? viewportOverflow(doc, view) : null;
5148
+ const liftedCopy = lifted === doc.documentElement ? root : lifted ? root.querySelector("body") : null;
5149
+ const liftedStyle = lifted && view ? view.getComputedStyle(lifted) : null;
5150
+ if (liftedCopy && liftedStyle && (cuts(liftedStyle.overflowX) || cuts(liftedStyle.overflowY))) {
5151
+ const own = liftedCopy === root && liftedStyle.display === "block" ? ";display:flow-root !important" : "";
5152
+ liftedCopy.setAttribute("style", `${liftedCopy.getAttribute("style") ?? ""};overflow:visible !important${own}`);
5153
+ }
5049
5154
  for (const node of root.querySelectorAll(`script, link, style, noscript, ${ownSelector()}`))
5050
5155
  node.remove();
5156
+ const quiet = inert.createElement("style");
5157
+ quiet.textContent = NO_CONTROLS;
5051
5158
  const style = inert.createElement("style");
5052
5159
  style.textContent = frozen.rules.join(`
5053
5160
  `);
5054
- (root.querySelector("head") ?? root).append(style);
5161
+ (root.querySelector("head") ?? root).append(style, quiet);
5055
5162
  return root;
5056
5163
  }
5057
5164
  var LONE_HALF = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
@@ -5141,6 +5248,592 @@ async function paintPage(frame2, glass, size, color, copy) {
5141
5248
  return canvas;
5142
5249
  }
5143
5250
 
5251
+ // src/engine/bandmedia.ts
5252
+ var REACH = 1;
5253
+ var MOST2 = 20000;
5254
+ var LARGEST = 4000000;
5255
+ var SHARPEST = 3;
5256
+ var KEEP_LENGTH = 48000000;
5257
+ var REFUSALS = 2;
5258
+ var MOST_REFUSED = 5000;
5259
+ function bandSpan(scrollY, innerHeight, band) {
5260
+ const top = scrollY + innerHeight;
5261
+ const reach = innerHeight * REACH;
5262
+ return { top: Math.max(0, top - reach), bottom: top + band + reach };
5263
+ }
5264
+ function inSpan(span, scrollY, innerHeight, band) {
5265
+ const top = scrollY + innerHeight;
5266
+ return top >= span.top && top + band <= span.bottom;
5267
+ }
5268
+ function meets(rect, scrollY, span) {
5269
+ return rect.width > 0 && rect.height > 0 && rect.bottom + scrollY > span.top && rect.top + scrollY < span.bottom;
5270
+ }
5271
+ function readSize(media, wide, tall, ratio) {
5272
+ const shows = ratio * Math.max(wide / media.width, tall / media.height);
5273
+ const scale = Math.min(1, shows, Math.sqrt(LARGEST / (media.width * media.height)));
5274
+ return { width: Math.max(1, Math.round(media.width * scale)), height: Math.max(1, Math.round(media.height * scale)) };
5275
+ }
5276
+ function sizedPicture(data, width, height, rendering = "") {
5277
+ const crisp = rendering === "pixelated" || rendering === "crisp-edges" ? ` style="image-rendering:${rendering}"` : "";
5278
+ return svgUrl(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" preserveAspectRatio="none">` + `<image href="${data}" width="${width}" height="${height}" preserveAspectRatio="none"${crisp}/></svg>`);
5279
+ }
5280
+ function readPixels(source, size) {
5281
+ const canvas = document.createElement("canvas");
5282
+ canvas.width = size.width;
5283
+ canvas.height = size.height;
5284
+ try {
5285
+ const pen = canvas.getContext("2d");
5286
+ if (!pen)
5287
+ return null;
5288
+ pen.drawImage(source, 0, 0, size.width, size.height);
5289
+ return canvas.toDataURL("image/webp", 0.9);
5290
+ } catch {
5291
+ return null;
5292
+ } finally {
5293
+ canvas.width = 0;
5294
+ canvas.height = 0;
5295
+ }
5296
+ }
5297
+ var kept3 = new Map;
5298
+ var keptLength = 0;
5299
+ function keptPixels(key, read) {
5300
+ if (kept3.has(key)) {
5301
+ const data2 = kept3.get(key) ?? null;
5302
+ kept3.delete(key);
5303
+ kept3.set(key, data2);
5304
+ return data2;
5305
+ }
5306
+ const data = read();
5307
+ kept3.set(key, data);
5308
+ keptLength += key.length + (data?.length ?? 0);
5309
+ for (const [old, value] of kept3) {
5310
+ if (keptLength <= KEEP_LENGTH || old === key)
5311
+ break;
5312
+ kept3.delete(old);
5313
+ keptLength -= old.length + (value?.length ?? 0);
5314
+ }
5315
+ return data;
5316
+ }
5317
+ var probes = new Map;
5318
+ function forgetPixels() {
5319
+ kept3.clear();
5320
+ keptLength = 0;
5321
+ probes.clear();
5322
+ asking.clear();
5323
+ }
5324
+ var refused = new Set;
5325
+ var refusedOrigins = new Map;
5326
+ var allowed = new Set;
5327
+ var asking = new Map;
5328
+ function originOf(address) {
5329
+ try {
5330
+ return new URL(address).origin;
5331
+ } catch {
5332
+ return null;
5333
+ }
5334
+ }
5335
+ function sameOrigin(address, base, origin) {
5336
+ try {
5337
+ return new URL(address, base).origin === origin;
5338
+ } catch {
5339
+ return false;
5340
+ }
5341
+ }
5342
+ function refuse(address, origin, found) {
5343
+ if (refused.has(address))
5344
+ return;
5345
+ refused.add(address);
5346
+ if (refused.size > MOST_REFUSED) {
5347
+ const [oldest] = refused;
5348
+ if (oldest !== undefined)
5349
+ refused.delete(oldest);
5350
+ }
5351
+ if (origin !== null && found && !allowed.has(origin))
5352
+ refusedOrigins.set(origin, (refusedOrigins.get(origin) ?? 0) + 1);
5353
+ }
5354
+ function probeOf(doc, address, cors, loaded, used) {
5355
+ const known = used.get(address) ?? probes.get(address);
5356
+ if (known && known.ownerDocument === doc) {
5357
+ used.set(address, known);
5358
+ return known;
5359
+ }
5360
+ const origin = cors ? originOf(address) : null;
5361
+ const shut = () => refused.has(address) || origin !== null && !allowed.has(origin) && (refusedOrigins.get(origin) ?? 0) >= REFUSALS;
5362
+ if (shut())
5363
+ return null;
5364
+ const ask = (withCors2) => {
5365
+ const image = doc.createElement("img");
5366
+ if (withCors2)
5367
+ image.crossOrigin = "anonymous";
5368
+ image.src = address;
5369
+ return image;
5370
+ };
5371
+ if (origin === null || allowed.has(origin)) {
5372
+ const probe = ask(cors);
5373
+ if (!probe.complete) {
5374
+ probe.addEventListener("load", loaded, { once: true });
5375
+ probe.addEventListener("error", () => refuse(address, origin, false), { once: true });
5376
+ }
5377
+ used.set(address, probe);
5378
+ return probe;
5379
+ }
5380
+ const first = asking.get(origin);
5381
+ if (first && first.ownerDocument === doc && !first.complete)
5382
+ return null;
5383
+ const withCors = () => {
5384
+ const probe = ask(true);
5385
+ if (probe.complete) {
5386
+ if (probe.naturalWidth > 0)
5387
+ allowed.add(origin);
5388
+ else
5389
+ refuse(address, origin, true);
5390
+ return probe;
5391
+ }
5392
+ asking.set(origin, probe);
5393
+ const settle2 = (came) => {
5394
+ if (came)
5395
+ allowed.add(origin);
5396
+ else
5397
+ refuse(address, origin, true);
5398
+ if (asking.get(origin) === probe) {
5399
+ asking.delete(origin);
5400
+ loaded();
5401
+ }
5402
+ };
5403
+ probe.addEventListener("load", () => settle2(true), { once: true });
5404
+ probe.addEventListener("error", () => settle2(false), { once: true });
5405
+ return probe;
5406
+ };
5407
+ const plain = ask(false);
5408
+ if (plain.complete) {
5409
+ if (plain.naturalWidth === 0) {
5410
+ refuse(address, origin, false);
5411
+ return null;
5412
+ }
5413
+ const probe = withCors();
5414
+ used.set(address, probe);
5415
+ return probe;
5416
+ }
5417
+ asking.set(origin, plain);
5418
+ plain.addEventListener("load", () => {
5419
+ if (asking.get(origin) !== plain)
5420
+ return;
5421
+ asking.delete(origin);
5422
+ if (shut()) {
5423
+ loaded();
5424
+ return;
5425
+ }
5426
+ const probe = withCors();
5427
+ probes.set(address, probe);
5428
+ if (probe.complete)
5429
+ loaded();
5430
+ }, { once: true });
5431
+ plain.addEventListener("error", () => {
5432
+ refuse(address, origin, false);
5433
+ if (asking.get(origin) === plain) {
5434
+ asking.delete(origin);
5435
+ loaded();
5436
+ }
5437
+ }, { once: true });
5438
+ return null;
5439
+ }
5440
+ function plainOf(doc, address, loaded, used) {
5441
+ const key = `plain|${address}`;
5442
+ const known = used.get(key) ?? probes.get(key);
5443
+ if (known && known.ownerDocument === doc) {
5444
+ used.set(key, known);
5445
+ return known;
5446
+ }
5447
+ if (refused.has(key))
5448
+ return null;
5449
+ const image = doc.createElement("img");
5450
+ image.src = address;
5451
+ if (!image.complete) {
5452
+ image.addEventListener("load", loaded, { once: true });
5453
+ image.addEventListener("error", () => refuse(key, null, false), { once: true });
5454
+ }
5455
+ used.set(key, image);
5456
+ return image;
5457
+ }
5458
+ function showsPoster(video) {
5459
+ if (!video.poster)
5460
+ return false;
5461
+ return video.readyState < 2 || video.paused && video.played.length === 0 && video.currentTime === 0;
5462
+ }
5463
+ function layersOf(value) {
5464
+ const parts = [];
5465
+ let depth = 0;
5466
+ let part = "";
5467
+ for (const char of value) {
5468
+ if (char === "(")
5469
+ depth++;
5470
+ if (char === ")")
5471
+ depth--;
5472
+ if (char === "," && depth === 0) {
5473
+ parts.push(part.trim());
5474
+ part = "";
5475
+ } else
5476
+ part += char;
5477
+ }
5478
+ parts.push(part.trim());
5479
+ return parts;
5480
+ }
5481
+ function urlOf(layer) {
5482
+ const found = /^url\(\s*(["']?)(.*)\1\s*\)$/s.exec(layer);
5483
+ return found?.[2] ?? null;
5484
+ }
5485
+ function sizeOf(fit, media, wide, tall) {
5486
+ if (fit === "cover" || fit === "contain")
5487
+ return fit;
5488
+ if (fit === "none")
5489
+ return "auto";
5490
+ if (fit === "scale-down")
5491
+ return media.width > wide || media.height > tall ? "contain" : "auto";
5492
+ return "100% 100%";
5493
+ }
5494
+ function clipOf(node, doc, view, boxOf2) {
5495
+ for (let at = node.parentElement;at && at !== doc.body && at !== doc.documentElement; at = at.parentElement) {
5496
+ const style = view.getComputedStyle(at);
5497
+ if (style.overflowX === "visible" && style.overflowY === "visible")
5498
+ continue;
5499
+ return { rect: boxOf2(at.getBoundingClientRect()), radius: Number.parseFloat(style.borderTopLeftRadius) || 0 };
5500
+ }
5501
+ return;
5502
+ }
5503
+ function pinned(node, view) {
5504
+ for (let at = node;at; at = at.parentElement) {
5505
+ if (view.getComputedStyle(at).position === "fixed")
5506
+ return true;
5507
+ }
5508
+ return false;
5509
+ }
5510
+ function visible(node) {
5511
+ if (typeof node.checkVisibility !== "function")
5512
+ return true;
5513
+ return node.checkVisibility({ opacityProperty: true, visibilityProperty: true, checkOpacity: true, checkVisibilityCSS: true });
5514
+ }
5515
+ function overlap(a, b) {
5516
+ return Math.min(a.right, b.right) - Math.max(a.left, b.left) > 0.5 && Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top) > 0.5;
5517
+ }
5518
+ var STACKS_CHILDREN = new Set(["flex", "inline-flex", "grid", "inline-grid"]);
5519
+ var inEffect = (value, initial = "none") => (value || initial) !== initial;
5520
+ var names = (value, words2) => (value ?? "").split(/[\s,]+/).some((word) => words2.has(word));
5521
+ var CONTAINS = new Set(["paint", "layout", "strict", "content"]);
5522
+ var CHANGES = new Set(["transform", "opacity", "filter", "scale", "rotate", "translate", "isolation", "mix-blend-mode", "perspective", "clip-path", "mask", "contain", "backdrop-filter", "mask-image", "-webkit-mask-image", "position", "view-transition-name", "offset-path"]);
5523
+ function boxOf2(node, view) {
5524
+ for (let at = node.parentElement;at; at = at.parentElement) {
5525
+ const style = view.getComputedStyle(at);
5526
+ if (style.display !== "contents")
5527
+ return style;
5528
+ }
5529
+ return null;
5530
+ }
5531
+ function contextOf(style) {
5532
+ return style.position === "fixed" || style.position === "sticky" || inEffect(style.transform) || inEffect(style.scale) || inEffect(style.rotate) || inEffect(style.translate) || inEffect(style.filter) || inEffect(style.backdropFilter) || inEffect(style.perspective) || inEffect(style.clipPath) || inEffect(style.maskImage) || inEffect(style.webkitMaskImage) || inEffect(style.mixBlendMode, "normal") || Number.parseFloat(style.opacity) < 1 || style.isolation === "isolate" || names(style.contain, CONTAINS) || inEffect(style.viewTransitionName) || style.contentVisibility === "auto" || inEffect(style.offsetPath) || names(style.willChange, CHANGES);
5533
+ }
5534
+ function rankOf(node, top, view) {
5535
+ let rank = 0;
5536
+ for (let at = node;at && at !== top; at = at.parentElement) {
5537
+ const style = view.getComputedStyle(at);
5538
+ if (style.display === "contents")
5539
+ continue;
5540
+ const positioned = style.position !== "static";
5541
+ const holder = boxOf2(at, view)?.display;
5542
+ const z = positioned || holder && STACKS_CHILDREN.has(holder) ? Number.parseInt(style.zIndex, 10) : Number.NaN;
5543
+ if (Number.isFinite(z) || contextOf(style))
5544
+ rank = !Number.isFinite(z) || z === 0 ? 1 : z < 0 ? z : 1 + z;
5545
+ else if (positioned && rank === 0)
5546
+ rank = 1;
5547
+ }
5548
+ return rank;
5549
+ }
5550
+ function paintsOver(node, media, after, view) {
5551
+ let top = node.parentElement;
5552
+ while (top && !top.contains(media))
5553
+ top = top.parentElement;
5554
+ if (!top)
5555
+ return false;
5556
+ const rank = rankOf(node, top, view) - rankOf(media, top, view);
5557
+ return rank > 0 || rank === 0 && after;
5558
+ }
5559
+ function covered(doc, view, own, pending2) {
5560
+ const over2 = new Set;
5561
+ const above = new Set;
5562
+ const nodes = new Set(pending2.map((one) => one.node));
5563
+ const met = new Set;
5564
+ const all = doc.documentElement.getElementsByTagName("*");
5565
+ for (let index = 0;index < all.length && index < MOST2; index++) {
5566
+ const node = all[index];
5567
+ if (!node)
5568
+ continue;
5569
+ if (nodes.has(node))
5570
+ met.add(node);
5571
+ const rect = node.getBoundingClientRect();
5572
+ if (rect.width <= 0 || rect.height <= 0)
5573
+ continue;
5574
+ for (const one of pending2) {
5575
+ if (node === one.node || node.contains(one.node) || !overlap(rect, one.rect))
5576
+ continue;
5577
+ if (!visible(node) || node.closest(own) || pinned(node, view) || !paintsOver(node, one.node, met.has(one.node), view))
5578
+ continue;
5579
+ over2.add(one.node);
5580
+ above.add(node);
5581
+ }
5582
+ }
5583
+ return { over: over2, above };
5584
+ }
5585
+ function bandMedia(doc, view, span, loaded, scrollY = view.scrollY) {
5586
+ const fills = new Map;
5587
+ const pending2 = [];
5588
+ const used = new Map;
5589
+ const ratio = Math.min(SHARPEST, Math.max(1, view.devicePixelRatio || 1));
5590
+ const { scrollX } = view;
5591
+ const own = ownSelector();
5592
+ const origin = view.location.origin;
5593
+ const boxOf3 = (rect) => ({ left: rect.left + scrollX, top: rect.top + scrollY, width: rect.width, height: rect.height });
5594
+ const add = (node, put) => {
5595
+ const before = fills.get(node);
5596
+ fills.set(node, before ? (copy) => (before(copy), put(copy)) : put);
5597
+ };
5598
+ const restyle = (copy, css) => copy.setAttribute("style", `${copy.getAttribute("style") ?? ""};${css}`);
5599
+ const fill = (node, rect, style, media, data) => {
5600
+ const px = (value) => Number.parseFloat(value) || 0;
5601
+ const wide = rect.width - px(style.borderLeftWidth) - px(style.paddingLeft) - px(style.borderRightWidth) - px(style.paddingRight);
5602
+ const tall = rect.height - px(style.borderTopWidth) - px(style.paddingTop) - px(style.borderBottomWidth) - px(style.paddingBottom);
5603
+ const picture = sizedPicture(data, media.width, media.height, style.imageRendering);
5604
+ const size = "videoWidth" in node ? node.videoWidth > 0 ? { width: node.videoWidth, height: node.videoHeight } : media : null;
5605
+ add(node, (copy) => {
5606
+ if (size && !copy.hasAttribute("width") && !copy.hasAttribute("height")) {
5607
+ copy.setAttribute("width", String(size.width));
5608
+ copy.setAttribute("height", String(size.height));
5609
+ }
5610
+ restyle(copy, `background-image:url("${picture}") !important;background-size:${sizeOf(style.objectFit, media, wide, tall)} !important;` + `background-position:${style.objectPosition} !important;background-repeat:no-repeat !important;background-origin:content-box !important`);
5611
+ });
5612
+ };
5613
+ for (const node of doc.querySelectorAll(MEDIA)) {
5614
+ const rect = node.getBoundingClientRect();
5615
+ if (!meets(rect, scrollY, span) || node.closest(own))
5616
+ continue;
5617
+ if ("videoWidth" in node && showsPoster(node)) {
5618
+ if (pinned(node, view))
5619
+ continue;
5620
+ const address = node.poster;
5621
+ const style2 = view.getComputedStyle(node);
5622
+ const cors = !sameOrigin(address, doc.baseURI, origin);
5623
+ const probe = probeOf(doc, address, cors, loaded, used);
5624
+ const media2 = probe && mediaOf(probe);
5625
+ if (probe && media2) {
5626
+ const size2 = readSize(media2, rect.width, rect.height, ratio);
5627
+ const data2 = keptPixels(`${address}|${cors ? "cors|" : ""}${size2.width}x${size2.height}`, () => readPixels(probe, size2));
5628
+ if (data2 !== null) {
5629
+ fill(node, rect, style2, media2, data2);
5630
+ continue;
5631
+ }
5632
+ }
5633
+ const plain = visible(node) ? plainOf(doc, address, loaded, used) : null;
5634
+ const shown2 = plain && mediaOf(plain);
5635
+ if (shown2)
5636
+ pending2.push({ node, rect, draw: () => ({ media: shown2, rect: boxOf3(rect), style: style2, clip: clipOf(node, doc, view, boxOf3) }) });
5637
+ continue;
5638
+ }
5639
+ const media = mediaOf(node);
5640
+ if (!media || pinned(node, view))
5641
+ continue;
5642
+ const style = view.getComputedStyle(node);
5643
+ if ("naturalWidth" in node) {
5644
+ const address = node.currentSrc || node.src;
5645
+ if (address.startsWith("data:")) {
5646
+ add(node, (copy) => copy.setAttribute("src", address));
5647
+ continue;
5648
+ }
5649
+ const dense = node.srcset || node.parentElement?.localName === "picture" ? ratio : 1;
5650
+ const size2 = readSize({ width: media.width * dense, height: media.height * dense }, rect.width, rect.height, ratio);
5651
+ const sized = `${size2.width}x${size2.height}`;
5652
+ let data2 = keptPixels(`${address}|${sized}`, () => readPixels(node, size2));
5653
+ if (data2 === null) {
5654
+ const probe = probeOf(doc, address, true, loaded, used);
5655
+ if (probe && mediaOf(probe))
5656
+ data2 = keptPixels(`${address}|cors|${sized}`, () => readPixels(probe, size2));
5657
+ }
5658
+ if (data2 !== null) {
5659
+ const read = data2;
5660
+ add(node, (copy) => copy.setAttribute("src", sizedPicture(read, media.width, media.height, style.imageRendering)));
5661
+ continue;
5662
+ }
5663
+ if (!visible(node))
5664
+ continue;
5665
+ pending2.push({
5666
+ node,
5667
+ rect,
5668
+ draw: () => {
5669
+ const whole = document.createElement("canvas");
5670
+ whole.width = size2.width;
5671
+ whole.height = size2.height;
5672
+ try {
5673
+ whole.getContext("2d")?.drawImage(node, 0, 0, size2.width, size2.height);
5674
+ } catch {
5675
+ whole.width = 0;
5676
+ whole.height = 0;
5677
+ return null;
5678
+ }
5679
+ const drawn = { source: whole, width: media.width, height: media.height, scale: size2.width / media.width };
5680
+ return { media: drawn, rect: boxOf3(rect), style, made: whole, clip: clipOf(node, doc, view, boxOf3) };
5681
+ }
5682
+ });
5683
+ continue;
5684
+ }
5685
+ if ("videoWidth" in node && !node.paused) {
5686
+ if (visible(node))
5687
+ pending2.push({ node, rect, draw: () => ({ media, rect: boxOf3(rect), style, clip: clipOf(node, doc, view, boxOf3), live: node }) });
5688
+ continue;
5689
+ }
5690
+ const size = readSize(media, rect.width, rect.height, ratio);
5691
+ const data = readPixels(node, size);
5692
+ if (data === null) {
5693
+ if (visible(node))
5694
+ pending2.push({ node, rect, draw: () => ({ media, rect: boxOf3(rect), style, clip: clipOf(node, doc, view, boxOf3) }) });
5695
+ continue;
5696
+ }
5697
+ fill(node, rect, style, media, data);
5698
+ }
5699
+ const all = doc.documentElement.getElementsByTagName("*");
5700
+ for (let index = 0;index < all.length && index < MOST2; index++) {
5701
+ const node = all[index];
5702
+ if (!node)
5703
+ continue;
5704
+ const rect = node.getBoundingClientRect();
5705
+ if (!meets(rect, scrollY, span))
5706
+ continue;
5707
+ const style = view.getComputedStyle(node);
5708
+ const value = style.backgroundImage;
5709
+ if (!value?.includes("url(") || node.closest(own) || pinned(node, view))
5710
+ continue;
5711
+ let read = false;
5712
+ const shown2 = layersOf(value).map((layer) => {
5713
+ const address = urlOf(layer);
5714
+ if (address === null || address.startsWith("data:"))
5715
+ return layer;
5716
+ const cors = !sameOrigin(address, doc.baseURI, origin);
5717
+ const probe = probeOf(doc, address, cors, loaded, used);
5718
+ const media = probe && mediaOf(probe);
5719
+ if (!media)
5720
+ return layer;
5721
+ const size = readSize(media, rect.width, rect.height, ratio);
5722
+ const data = keptPixels(`${address}|${cors ? "cors|" : ""}${size.width}x${size.height}`, () => readPixels(probe, size));
5723
+ if (data === null)
5724
+ return layer;
5725
+ read = true;
5726
+ return `url("${sizedPicture(data, media.width, media.height, style.imageRendering)}")`;
5727
+ });
5728
+ if (read) {
5729
+ const css = `background-image:${shown2.join(", ")} !important`;
5730
+ add(node, (copy) => restyle(copy, css));
5731
+ }
5732
+ }
5733
+ probes = used;
5734
+ const { over: over2, above } = pending2.length > 0 ? covered(doc, view, own, pending2) : { over: new Set, above: new Set };
5735
+ const unread = [];
5736
+ for (const one of pending2) {
5737
+ const drawn = one.draw();
5738
+ if (drawn)
5739
+ unread.push(over2.has(one.node) ? { ...drawn, covered: true } : drawn);
5740
+ }
5741
+ return { fills, unread, above };
5742
+ }
5743
+ function clipTo(pen, one) {
5744
+ const { rect, clip } = one;
5745
+ if (clip) {
5746
+ pen.beginPath();
5747
+ pen.roundRect(clip.rect.left, clip.rect.top, clip.rect.width, clip.rect.height, clip.radius);
5748
+ pen.clip();
5749
+ }
5750
+ pen.beginPath();
5751
+ pen.rect(rect.left, rect.top, rect.width, rect.height);
5752
+ pen.clip();
5753
+ }
5754
+ function drawOne(pen, one) {
5755
+ pen.save();
5756
+ try {
5757
+ if (one.clip) {
5758
+ pen.beginPath();
5759
+ pen.roundRect(one.clip.rect.left, one.clip.rect.top, one.clip.rect.width, one.clip.rect.height, one.clip.radius);
5760
+ pen.clip();
5761
+ }
5762
+ drawMedia(pen, one.media, one.rect, one.style);
5763
+ } catch {}
5764
+ pen.restore();
5765
+ }
5766
+ function overlayOf(unread, span, width, ratio, above = null) {
5767
+ if (unread.length === 0)
5768
+ return null;
5769
+ const canvas = document.createElement("canvas");
5770
+ canvas.width = Math.max(1, Math.round(width * ratio));
5771
+ canvas.height = Math.max(1, Math.round((span.bottom - span.top) * ratio));
5772
+ const pen = canvas.getContext("2d");
5773
+ if (!pen)
5774
+ return null;
5775
+ pen.setTransform(ratio, 0, 0, ratio, 0, -span.top * ratio);
5776
+ for (const one of unread) {
5777
+ drawOne(pen, one);
5778
+ if (one.made) {
5779
+ one.made.width = 0;
5780
+ one.made.height = 0;
5781
+ }
5782
+ }
5783
+ const parts = unread.filter((one) => one.covered);
5784
+ return { canvas, span, width, ratio, live: unread.filter((one) => one.live), above: above && parts.length > 0 ? { src: above, parts } : null };
5785
+ }
5786
+ function raiseOf(overlay, image) {
5787
+ const { span, width, ratio } = overlay;
5788
+ const canvas = document.createElement("canvas");
5789
+ canvas.width = overlay.canvas.width;
5790
+ canvas.height = overlay.canvas.height;
5791
+ const pen = canvas.getContext("2d");
5792
+ if (!pen)
5793
+ return null;
5794
+ const tall = span.bottom - span.top;
5795
+ pen.setTransform(ratio, 0, 0, ratio, 0, -span.top * ratio);
5796
+ try {
5797
+ pen.drawImage(image, 0, span.top, width, tall, 0, span.top, width, tall);
5798
+ } catch {
5799
+ canvas.width = 0;
5800
+ canvas.height = 0;
5801
+ return null;
5802
+ }
5803
+ return canvas;
5804
+ }
5805
+ function drawAbove(overlay, raised, only) {
5806
+ const { canvas, span, width, ratio, above } = overlay;
5807
+ const pen = above && canvas.getContext("2d");
5808
+ if (!above || !pen)
5809
+ return;
5810
+ pen.setTransform(ratio, 0, 0, ratio, 0, -span.top * ratio);
5811
+ for (const part of above.parts) {
5812
+ if (only && part !== only)
5813
+ continue;
5814
+ pen.save();
5815
+ try {
5816
+ clipTo(pen, part);
5817
+ pen.drawImage(raised, 0, span.top, width, span.bottom - span.top);
5818
+ } catch {}
5819
+ pen.restore();
5820
+ }
5821
+ }
5822
+ function redrawLive(overlay, one, raised) {
5823
+ const { canvas, span, ratio } = overlay;
5824
+ const pen = canvas.getContext("2d");
5825
+ if (!pen)
5826
+ return;
5827
+ pen.setTransform(ratio, 0, 0, ratio, 0, -span.top * ratio);
5828
+ pen.save();
5829
+ clipTo(pen, one);
5830
+ pen.clearRect(one.rect.left, one.rect.top, one.rect.width, one.rect.height);
5831
+ pen.restore();
5832
+ drawOne(pen, one);
5833
+ if (raised && one.covered)
5834
+ drawAbove(overlay, raised, one);
5835
+ }
5836
+
5144
5837
  // src/engine/underbar.ts
5145
5838
  var UNDERBAR_CSS = `
5146
5839
  .underbar {
@@ -5150,7 +5843,8 @@ var UNDERBAR_CSS = `
5150
5843
  transform-origin: 0 0;
5151
5844
  }
5152
5845
  .underbar[hidden] { display: none; }
5153
- .underbar > img {
5846
+ .underbar > img,
5847
+ .underbar > canvas {
5154
5848
  position: absolute;
5155
5849
  left: 0;
5156
5850
  top: 0;
@@ -5158,6 +5852,7 @@ var UNDERBAR_CSS = `
5158
5852
  will-change: transform;
5159
5853
  }
5160
5854
  `;
5855
+ var LOADS = ["load", "loadeddata", "seeked", "playing"];
5161
5856
  var GAP = 250;
5162
5857
  var SHARE = 10;
5163
5858
  function bandRect(page, height) {
@@ -5179,13 +5874,54 @@ var VH = /(-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)[sld]?vh\b/gi;
5179
5874
  function viewportUnits(css, height) {
5180
5875
  return css.replace(VH, (_, amount) => `${Math.round(Number(amount) * height) / 100}px`);
5181
5876
  }
5182
- function pictureOf(frame2) {
5877
+ function bodyScroller(doc, view) {
5878
+ const { body } = doc;
5879
+ if (!body || viewportOverflow(doc, view) !== doc.documentElement)
5880
+ return null;
5881
+ const { overflowY } = view.getComputedStyle(body);
5882
+ return cuts(overflowY) && overflowY !== "clip" ? body : null;
5883
+ }
5884
+ function scrollOf(doc, view) {
5885
+ return view.scrollY + (bodyScroller(doc, view)?.scrollTop ?? 0);
5886
+ }
5887
+ function heightOf(doc, view) {
5888
+ const full = doc.documentElement.scrollHeight;
5889
+ const body = bodyScroller(doc, view);
5890
+ if (!body)
5891
+ return full;
5892
+ return Math.max(full, body.getBoundingClientRect().top + view.scrollY + body.clientTop + body.scrollHeight);
5893
+ }
5894
+ function unscroll(copy, body, view) {
5895
+ const style = view.getComputedStyle(body);
5896
+ const own = style.display === "block" ? ";display:flow-root !important" : "";
5897
+ copy.setAttribute("style", `${copy.getAttribute("style") ?? ""};overflow-x:clip !important;overflow-y:visible !important${own}`);
5898
+ }
5899
+ function isMedia(target) {
5900
+ return target !== null && "currentSrc" in target;
5901
+ }
5902
+ function nearLoad(target, scrollY, span) {
5903
+ if (!isMedia(target))
5904
+ return false;
5905
+ return meets(target.getBoundingClientRect(), scrollY, span);
5906
+ }
5907
+ function pictureOf(frame2, band = 0, loaded = () => {}) {
5183
5908
  const doc = frame2.contentDocument;
5184
5909
  const view = frame2.contentWindow;
5185
5910
  if (!doc?.documentElement || !view || view.innerWidth <= 0)
5186
5911
  return null;
5187
5912
  const { innerWidth: width, innerHeight: tall } = view;
5188
- const copy = copyPage(frame2, (node) => view.getComputedStyle(node).position === "fixed");
5913
+ const scrolled = scrollOf(doc, view);
5914
+ const span = bandSpan(scrolled, tall, band);
5915
+ const media = bandMedia(doc, view, span, loaded, scrolled);
5916
+ const puts = [];
5917
+ const above = [];
5918
+ const copy = copyPage(frame2, (node) => view.getComputedStyle(node).position === "fixed", (node, copied) => {
5919
+ const put = media.fills.get(node);
5920
+ if (put)
5921
+ puts.push(() => put(copied));
5922
+ if (media.above.has(node))
5923
+ above.push(copied);
5924
+ });
5189
5925
  if (!copy)
5190
5926
  return null;
5191
5927
  for (const style of copy.querySelectorAll("style")) {
@@ -5194,14 +5930,35 @@ function pictureOf(frame2) {
5194
5930
  for (const node of copy.querySelectorAll("[style]")) {
5195
5931
  node.setAttribute("style", viewportUnits(node.getAttribute("style") ?? "", tall));
5196
5932
  }
5197
- const full = Math.max(doc.documentElement.scrollHeight, tall);
5933
+ for (const put of puts)
5934
+ put();
5935
+ const scroller = bodyScroller(doc, view);
5936
+ const body = scroller ? copy.querySelector("body") : null;
5937
+ if (scroller && body)
5938
+ unscroll(body, scroller, view);
5939
+ const full = Math.max(heightOf(doc, view), tall);
5198
5940
  const root = doc.documentElement.getBoundingClientRect().height / ownZoom(doc, view);
5199
5941
  const sized = rootSize(doc, view);
5200
5942
  const zoom = layoutZoom(view);
5201
5943
  const zoomed = rootZoom(doc, view, zoom);
5202
5944
  copy.setAttribute("style", `${copy.getAttribute("style") ?? ""};${sized};height:${root}px !important${zoomed}`);
5203
5945
  const markup = new XMLSerializer().serializeToString(copy);
5204
- return { src: svgUrl(drawing(markup, width, full, sized, zoom)), width, height: full };
5946
+ const shows = doc.querySelector(MEDIA) !== null || /url\(\s*(?!["']?data:|&quot;data:)/i.test(markup);
5947
+ const ratio = Math.min(2, Math.max(1, window.devicePixelRatio || 1));
5948
+ return {
5949
+ src: svgUrl(drawing(markup, width, full, sized, zoom)),
5950
+ width,
5951
+ height: full,
5952
+ span: shows ? span : null,
5953
+ overlay: overlayOf(media.unread, span, width, ratio, above.length > 0 ? svgUrl(drawing(aboveOnly(copy, above), width, full, sized, zoom)) : null)
5954
+ };
5955
+ }
5956
+ function aboveOnly(copy, shown2) {
5957
+ const restyle = (node, css) => node.setAttribute("style", `${node.getAttribute("style") ?? ""};${css}`);
5958
+ restyle(copy, "visibility:hidden !important");
5959
+ for (const node of shown2)
5960
+ restyle(node, "visibility:visible !important");
5961
+ return new XMLSerializer().serializeToString(copy);
5205
5962
  }
5206
5963
  function createUnderbar(glass, frame2) {
5207
5964
  const band = el("div", "underbar");
@@ -5210,6 +5967,7 @@ function createUnderbar(glass, frame2) {
5210
5967
  glass.append(band);
5211
5968
  let image = null;
5212
5969
  let picture = null;
5970
+ let cover = null;
5213
5971
  let taken = "";
5214
5972
  let watched2 = null;
5215
5973
  let observer = null;
@@ -5219,6 +5977,68 @@ function createUnderbar(glass, frame2) {
5219
5977
  let last = 0;
5220
5978
  let cost = 0;
5221
5979
  let wide = 0;
5980
+ let high = 0;
5981
+ const again = () => {
5982
+ changed = true;
5983
+ soon();
5984
+ };
5985
+ const bandOf = (across) => wide > 0 ? high * across / wide : 0;
5986
+ const onLoad = (event) => {
5987
+ if (picture?.overlay?.live.some((one) => one.live === event.target))
5988
+ return;
5989
+ try {
5990
+ const view = frame2.contentWindow;
5991
+ const doc = frame2.contentDocument;
5992
+ if (!view || !doc || band.hidden)
5993
+ return;
5994
+ const scrolled = scrollOf(doc, view);
5995
+ const span = bandSpan(scrolled, view.innerHeight, bandOf(view.innerWidth));
5996
+ if (nearLoad(event.target, scrolled, span))
5997
+ again();
5998
+ } catch {}
5999
+ };
6000
+ const onScroll = (event) => {
6001
+ if (event.target === watched2?.body)
6002
+ move();
6003
+ };
6004
+ const spend2 = (canvas) => {
6005
+ if (!canvas)
6006
+ return;
6007
+ canvas.width = 0;
6008
+ canvas.height = 0;
6009
+ };
6010
+ let raised = null;
6011
+ const dropCover = () => {
6012
+ spend2(raised);
6013
+ raised = null;
6014
+ if (!cover)
6015
+ return;
6016
+ cover.remove();
6017
+ cover.width = 0;
6018
+ cover.height = 0;
6019
+ cover = null;
6020
+ };
6021
+ const follow4 = (overlay) => {
6022
+ for (const one of overlay.live) {
6023
+ const video = one.live;
6024
+ if (!video)
6025
+ continue;
6026
+ const ask = () => {
6027
+ if (typeof video.requestVideoFrameCallback === "function")
6028
+ video.requestVideoFrameCallback(step);
6029
+ else
6030
+ window.requestAnimationFrame(step);
6031
+ };
6032
+ const step = () => {
6033
+ if (cover !== overlay.canvas)
6034
+ return;
6035
+ if (!band.hidden)
6036
+ redrawLive(overlay, one, raised);
6037
+ ask();
6038
+ };
6039
+ ask();
6040
+ }
6041
+ };
5222
6042
  const keyOf = () => {
5223
6043
  try {
5224
6044
  const doc = frame2.contentDocument;
@@ -5227,20 +6047,24 @@ function createUnderbar(glass, frame2) {
5227
6047
  return null;
5228
6048
  if (doc !== watched2) {
5229
6049
  observer?.disconnect();
5230
- const next = new MutationObserver(() => {
5231
- changed = true;
5232
- soon();
5233
- });
6050
+ for (const type of LOADS)
6051
+ watched2?.removeEventListener(type, onLoad, true);
6052
+ watched2?.removeEventListener("scroll", onScroll, true);
6053
+ const next = new MutationObserver(again);
5234
6054
  next.observe(doc, { subtree: true, childList: true, attributes: true, characterData: true });
6055
+ for (const type of LOADS)
6056
+ doc.addEventListener(type, onLoad, true);
6057
+ doc.addEventListener("scroll", onScroll, true);
5235
6058
  observer = next;
5236
6059
  watched2 = doc;
5237
6060
  changed = true;
5238
6061
  image?.remove();
5239
6062
  image = null;
5240
6063
  picture = null;
6064
+ dropCover();
5241
6065
  taken = "";
5242
6066
  }
5243
- return `${view.innerWidth}|${view.innerHeight}|${doc.documentElement.scrollHeight}`;
6067
+ return `${view.innerWidth}|${view.innerHeight}|${heightOf(doc, view)}`;
5244
6068
  } catch {
5245
6069
  return null;
5246
6070
  }
@@ -5250,10 +6074,17 @@ function createUnderbar(glass, frame2) {
5250
6074
  return;
5251
6075
  try {
5252
6076
  const view = frame2.contentWindow;
5253
- if (!view)
6077
+ const doc = frame2.contentDocument;
6078
+ if (!view || !doc)
5254
6079
  return;
5255
- const shift = bandShift(view.scrollY, view.innerHeight, wide / picture.width);
6080
+ const scale = wide / picture.width;
6081
+ const scrolled = scrollOf(doc, view);
6082
+ const shift = bandShift(scrolled, view.innerHeight, scale);
5256
6083
  image.style.transform = `translate3d(0, ${shift}px, 0)`;
6084
+ if (cover && picture.overlay)
6085
+ cover.style.transform = `translate3d(0, ${shift + picture.overlay.span.top * scale}px, 0)`;
6086
+ if (picture.span && !inSpan(picture.span, scrolled, view.innerHeight, bandOf(picture.width)))
6087
+ again();
5257
6088
  } catch {}
5258
6089
  };
5259
6090
  const paint = async () => {
@@ -5265,6 +6096,7 @@ function createUnderbar(glass, frame2) {
5265
6096
  image?.remove();
5266
6097
  image = null;
5267
6098
  picture = null;
6099
+ dropCover();
5268
6100
  return;
5269
6101
  }
5270
6102
  if (!changed && key === taken)
@@ -5274,22 +6106,36 @@ function createUnderbar(glass, frame2) {
5274
6106
  const start = performance.now();
5275
6107
  let next = null;
5276
6108
  try {
5277
- next = pictureOf(frame2);
6109
+ next = pictureOf(frame2, bandOf(frame2.contentWindow?.innerWidth ?? 0), again);
5278
6110
  } catch {
5279
6111
  next = null;
5280
6112
  }
5281
6113
  const fresh2 = new Image;
5282
6114
  let drawn = false;
6115
+ let lifted = null;
5283
6116
  if (next) {
5284
6117
  fresh2.src = next.src;
5285
6118
  drawn = await fresh2.decode().then(() => true, () => false);
6119
+ const above = next.overlay?.above;
6120
+ if (drawn && next.overlay && above) {
6121
+ const over2 = new Image;
6122
+ over2.src = above.src;
6123
+ const decoded = await over2.decode().then(() => true, () => false);
6124
+ lifted = decoded ? raiseOf(next.overlay, over2) : null;
6125
+ if (lifted)
6126
+ drawAbove(next.overlay, lifted);
6127
+ }
5286
6128
  }
5287
6129
  cost = performance.now() - start;
5288
6130
  last = performance.now();
5289
6131
  performance.measure("devknobs underbar picture", { start, duration: cost });
5290
6132
  painting = false;
5291
- if (!next || !drawn)
6133
+ if (!next || !drawn) {
6134
+ if (next?.overlay)
6135
+ next.overlay.canvas.width = 0;
6136
+ spend2(lifted);
5292
6137
  return;
6138
+ }
5293
6139
  fresh2.alt = "";
5294
6140
  if (image)
5295
6141
  image.replaceWith(fresh2);
@@ -5297,6 +6143,16 @@ function createUnderbar(glass, frame2) {
5297
6143
  band.append(fresh2);
5298
6144
  image = fresh2;
5299
6145
  picture = next;
6146
+ dropCover();
6147
+ cover = next.overlay?.canvas ?? null;
6148
+ if (cover)
6149
+ band.append(cover);
6150
+ if (next.overlay?.live.length)
6151
+ raised = lifted;
6152
+ else
6153
+ spend2(lifted);
6154
+ if (next.overlay)
6155
+ follow4(next.overlay);
5300
6156
  taken = key;
5301
6157
  fit();
5302
6158
  if (changed)
@@ -5313,6 +6169,11 @@ function createUnderbar(glass, frame2) {
5313
6169
  return;
5314
6170
  image.style.width = `${wide}px`;
5315
6171
  image.style.height = `${picture.height * wide / picture.width}px`;
6172
+ if (cover && picture.overlay) {
6173
+ const { span } = picture.overlay;
6174
+ cover.style.width = `${wide}px`;
6175
+ cover.style.height = `${(span.bottom - span.top) * wide / picture.width}px`;
6176
+ }
5316
6177
  move();
5317
6178
  }
5318
6179
  return {
@@ -5326,8 +6187,9 @@ function createUnderbar(glass, frame2) {
5326
6187
  }
5327
6188
  place(band, rect.x * zoom, rect.y * zoom, rect.width, rect.height);
5328
6189
  wide = rect.width;
6190
+ high = rect.height;
5329
6191
  band.style.transform = zoom === 1 ? "" : `scale(${zoom})`;
5330
- band.style.background = look.background;
6192
+ band.style.background = `linear-gradient(${look.background}, ${look.background})`;
5331
6193
  const key = keyOf();
5332
6194
  if (key !== taken || changed)
5333
6195
  soon();
@@ -5342,7 +6204,12 @@ function createUnderbar(glass, frame2) {
5342
6204
  clearTimeout(waiting);
5343
6205
  observer?.disconnect();
5344
6206
  observer = null;
6207
+ for (const type of LOADS)
6208
+ watched2?.removeEventListener(type, onLoad, true);
6209
+ watched2?.removeEventListener("scroll", onScroll, true);
5345
6210
  watched2 = null;
6211
+ dropCover();
6212
+ forgetPixels();
5346
6213
  band.remove();
5347
6214
  }
5348
6215
  };
@@ -5949,11 +6816,11 @@ function fit(knobs2, size, options = {}) {
5949
6816
  const whole = Math.min(sized && tall ? ZOOM_MAX : 1, across, tall ? upright : 1);
5950
6817
  const height = typeof knobs2.height === "number" ? knobs2.height : room.height / whole;
5951
6818
  const outer = { width: width + sides.width, height: height + sides.height };
5952
- const covered = sized && aside > 0 && aside <= room.width / 2 && (room.width + outer.width * whole) / 2 + x > room.width - aside;
5953
- const loose = covered ? Math.min(whole, (room.width - aside - 2 * x) / outer.width) : whole;
6819
+ const covered2 = sized && aside > 0 && aside <= room.width / 2 && (room.width + outer.width * whole) / 2 + x > room.width - aside;
6820
+ const loose = covered2 ? Math.min(whole, (room.width - aside - 2 * x) / outer.width) : whole;
5954
6821
  const fitted = mock === BARE ? loose : snapScale(loose, height, ratio);
5955
6822
  const scale = knobs2.zoom === "fit" ? fitted : knobs2.zoom;
5956
- const beside = knobs2.zoom === "fit" && covered ? aside : 0;
6823
+ const beside = knobs2.zoom === "fit" && covered2 ? aside : 0;
5957
6824
  const before = side === "left" ? beside : 0;
5958
6825
  return {
5959
6826
  width,
@@ -6275,7 +7142,7 @@ function hingeLine(pane, across, part) {
6275
7142
  return pane === "inner" ? [-1 / width, 0, (x + width) / width] : [1 / width, 0, -x / width];
6276
7143
  return pane === "inner" ? [0, 1 / height, -y / height] : [0, -1 / height, (y + height) / height];
6277
7144
  }
6278
- function contextOf(canvas) {
7145
+ function contextOf2(canvas) {
6279
7146
  if (typeof WebGL2RenderingContext === "undefined")
6280
7147
  return null;
6281
7148
  const gl = canvas.getContext("webgl2", {
@@ -6393,11 +7260,11 @@ function uploadWhy(error) {
6393
7260
  const tainted = "the browser holds the picture as another origin's, as one with a picture, video or canvas from another origin drawn in, or a drawing of the page this browser does not trust";
6394
7261
  return `the picture could not be uploaded: ${name}${name === "SecurityError" ? `, ${tainted}` : ""}`;
6395
7262
  }
6396
- function screenGl(place2, refused) {
7263
+ function screenGl(place2, refused2) {
6397
7264
  const canvas = document.createElement("canvas");
6398
- const gl = contextOf(canvas);
7265
+ const gl = contextOf2(canvas);
6399
7266
  if (!gl) {
6400
- refused(typeof WebGL2RenderingContext === "undefined" ? "this browser has no WebGL2" : "the canvas gave no WebGL2 context", null);
7267
+ refused2(typeof WebGL2RenderingContext === "undefined" ? "this browser has no WebGL2" : "the canvas gave no WebGL2 context", null);
6401
7268
  return null;
6402
7269
  }
6403
7270
  const rect = canvasRect(place2);
@@ -6428,7 +7295,7 @@ function screenGl(place2, refused) {
6428
7295
  if (!vertex2 || !fragment || !program || !corners || !texture) {
6429
7296
  const why = gl.isContextLost() ? "the WebGL2 context was lost as it was made" : "WebGL2 made no shader, program, buffer or texture";
6430
7297
  free();
6431
- refused(why, null);
7298
+ refused2(why, null);
6432
7299
  return null;
6433
7300
  }
6434
7301
  gl.attachShader(program, vertex2);
@@ -6438,7 +7305,7 @@ function screenGl(place2, refused) {
6438
7305
  const log = [vertex2, fragment].map((shader) => gl.getShaderInfoLog(shader)).find((said) => said?.trim()) ?? gl.getProgramInfoLog(program);
6439
7306
  const lost = gl.isContextLost();
6440
7307
  free();
6441
- refused(lost ? "the WebGL2 context was lost as it was made" : `the shader did not compile or link: ${firstLine(log, "no reason given")}`, null);
7308
+ refused2(lost ? "the WebGL2 context was lost as it was made" : `the shader did not compile or link: ${firstLine(log, "no reason given")}`, null);
6442
7309
  return null;
6443
7310
  }
6444
7311
  gl.useProgram(program);
@@ -6490,31 +7357,31 @@ function screenGl(place2, refused) {
6490
7357
  return;
6491
7358
  gone = true;
6492
7359
  canvas.remove();
6493
- refused("the WebGL2 context was lost", shot);
7360
+ refused2("the WebGL2 context was lost", shot);
6494
7361
  });
6495
- const refuse = (why, next) => {
7362
+ const refuse2 = (why, next) => {
6496
7363
  if (!gone)
6497
7364
  free();
6498
7365
  gone = true;
6499
- refused(why, next);
7366
+ refused2(why, next);
6500
7367
  };
6501
7368
  return {
6502
7369
  canvas,
6503
7370
  paint(next) {
6504
7371
  if (gone)
6505
- return refuse("the WebGL2 context is gone", next);
7372
+ return refuse2("the WebGL2 context is gone", next);
6506
7373
  if (Math.max(next.width, next.height) > widest) {
6507
- return refuse(`the picture, ${next.width} by ${next.height} px, is larger than MAX_TEXTURE_SIZE, ${widest}`, next);
7374
+ return refuse2(`the picture, ${next.width} by ${next.height} px, is larger than MAX_TEXTURE_SIZE, ${widest}`, next);
6508
7375
  }
6509
7376
  gl.getError();
6510
7377
  try {
6511
7378
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, next);
6512
7379
  } catch (error) {
6513
- return refuse(uploadWhy(error), next);
7380
+ return refuse2(uploadWhy(error), next);
6514
7381
  }
6515
7382
  const failed = gl.getError();
6516
7383
  if (failed !== gl.NO_ERROR)
6517
- return refuse(`the picture could not be uploaded: WebGL2 error 0x${failed.toString(16)}`, next);
7384
+ return refuse2(`the picture could not be uploaded: WebGL2 error 0x${failed.toString(16)}`, next);
6518
7385
  gl.generateMipmap(gl.TEXTURE_2D);
6519
7386
  shot = next;
6520
7387
  if (look)
@@ -6532,7 +7399,7 @@ function screenGl(place2, refused) {
6532
7399
 
6533
7400
  // src/engine/barshot.ts
6534
7401
  var GLASS = "blur(10px) saturate(1.8)";
6535
- var REACH = 30;
7402
+ var REACH2 = 30;
6536
7403
  var STILL_CSS = `
6537
7404
  .browser { transform: none !important; }
6538
7405
  .browser, .browser * {
@@ -6554,7 +7421,7 @@ function glassOf(bars, host) {
6554
7421
  return bars.shapes.filter((shape) => shape.kind !== "field").map(({ x, y, width, height, radius }) => ({ rect: { x, y, width, height }, radius }));
6555
7422
  }
6556
7423
  const pill = bars.shapes.find((shape) => shape.kind === "pill");
6557
- return pill ? [{ rect: pillBox(pill, host), radius: pill.radius }] : [];
7424
+ return pill ? [{ rect: pillBox(pill, host, turn(bars.screen, bars.orientation).width), radius: pill.radius }] : [];
6558
7425
  }
6559
7426
  function copyBars(shown2, value, size) {
6560
7427
  const minimized = shown2.querySelector("[data-state]")?.getAttribute("data-state") === "min";
@@ -6592,8 +7459,8 @@ async function paintBars(shot, bars) {
6592
7459
  pen.roundRect(rect.x, rect.y, rect.width, rect.height, radius);
6593
7460
  pen.clip();
6594
7461
  pen.filter = GLASS;
6595
- const [x, y] = [rect.x - REACH, rect.y - REACH];
6596
- const [width, height] = [rect.width + 2 * REACH, rect.height + 2 * REACH];
7462
+ const [x, y] = [rect.x - REACH2, rect.y - REACH2];
7463
+ const [width, height] = [rect.width + 2 * REACH2, rect.height + 2 * REACH2];
6597
7464
  pen.drawImage(under, x * scale, y * scale, width * scale, height * scale, x, y, width, height);
6598
7465
  pen.restore();
6599
7466
  }
@@ -6970,12 +7837,12 @@ function pick(turning, open) {
6970
7837
  const { at } = shownAt(shots2, ready, open);
6971
7838
  const next = at === null ? null : shots2.frames[at];
6972
7839
  const bitmap = at === null ? null : ready[at];
6973
- const kept3 = next && shots2.stills[next.still];
7840
+ const kept4 = next && shots2.stills[next.still];
6974
7841
  const keptBitmap = next && found?.stills[next.still];
6975
7842
  if (next && bitmap && next !== plane.shot)
6976
7843
  drawOn(plane, next, bitmap, shots2.scale);
6977
- if (kept3 && keptBitmap && kept3 !== turning.still.shot)
6978
- drawOn(turning.still, kept3, keptBitmap, shots2.scale);
7844
+ if (kept4 && keptBitmap && kept4 !== turning.still.shot)
7845
+ drawOn(turning.still, kept4, keptBitmap, shots2.scale);
6979
7846
  return plane.shot ? shotOpen(plane.shot) : open;
6980
7847
  }
6981
7848
  function pose(turning, layout, open, shown2, still2) {
@@ -8884,7 +9751,7 @@ var latest2 = null;
8884
9751
  var heading = "closed";
8885
9752
  var settled = false;
8886
9753
  var pending2 = null;
8887
- var covered = false;
9754
+ var covered2 = false;
8888
9755
  var released = false;
8889
9756
  function frameWindow() {
8890
9757
  return frame3?.contentWindow ?? null;
@@ -9185,9 +10052,9 @@ function stageSize() {
9185
10052
  return { width: Math.max(0, width), height: letterbox?.clientHeight ?? 0 };
9186
10053
  }
9187
10054
  function panelSized(glide) {
9188
- const pinned = current.panel.docked;
10055
+ const pinned2 = current.panel.docked;
9189
10056
  if (!glide) {
9190
- if (!pinned)
10057
+ if (!pinned2)
9191
10058
  resize();
9192
10059
  else if (ride) {
9193
10060
  endRide();
@@ -9198,7 +10065,7 @@ function panelSized(glide) {
9198
10065
  if (following)
9199
10066
  window.cancelAnimationFrame(following);
9200
10067
  following = 0;
9201
- if (pinned)
10068
+ if (pinned2)
9202
10069
  follow4(resize);
9203
10070
  else
9204
10071
  glideFrame(screen, { first: false, from: current.panel, to: current.panel, sized: true }, resize);
@@ -9525,9 +10392,9 @@ function foldDevice2(value, held2 = false) {
9525
10392
  }
9526
10393
  function hidePage() {
9527
10394
  const body = document.body;
9528
- if (covered || !body)
10395
+ if (covered2 || !body)
9529
10396
  return;
9530
- covered = true;
10397
+ covered2 = true;
9531
10398
  cover2(body);
9532
10399
  const style = ensureStyle(NAME);
9533
10400
  style.textContent = `html{overflow:hidden!important}:popover-open:not(${ownSelector()}){display:none!important}`;
@@ -9536,16 +10403,16 @@ function hidePage() {
9536
10403
  stopKeepingStyle = keepMounted(node, { home: () => document.head ?? document.documentElement });
9537
10404
  }
9538
10405
  function showPage() {
9539
- if (!covered)
10406
+ if (!covered2)
9540
10407
  return;
9541
- covered = false;
10408
+ covered2 = false;
9542
10409
  stopKeepingStyle?.();
9543
10410
  stopKeepingStyle = null;
9544
10411
  uncover2();
9545
10412
  removeStyle(NAME);
9546
10413
  }
9547
10414
  function remounted() {
9548
- if (covered) {
10415
+ if (covered2) {
9549
10416
  showPage();
9550
10417
  hidePage();
9551
10418
  }
@@ -9615,7 +10482,7 @@ function scene() {
9615
10482
  screenRect,
9616
10483
  fullRect,
9617
10484
  scheme: coverScheme,
9618
- covered: () => covered,
10485
+ covered: () => covered2,
9619
10486
  hidePage,
9620
10487
  painted,
9621
10488
  layout,