frameboard 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -9075,7 +9075,9 @@ const layoutEntrySchema = looseObject({
9075
9075
  height: int$1().min(1),
9076
9076
  order: int$1().min(0),
9077
9077
  hidden: boolean$1().optional(),
9078
- locked: boolean$1().optional()
9078
+ locked: boolean$1().optional(),
9079
+ hugWidth: boolean$1().optional(),
9080
+ hugHeight: boolean$1().optional()
9079
9081
  });
9080
9082
  const layoutFileSchema = looseObject({
9081
9083
  version: literal(1),
@@ -9177,6 +9179,8 @@ function placeFrames(frames, names) {
9177
9179
  order: entry.order,
9178
9180
  hidden: entry.hidden ?? false,
9179
9181
  locked: entry.locked ?? false,
9182
+ hugWidth: entry.hugWidth ?? false,
9183
+ hugHeight: entry.hugHeight ?? false,
9180
9184
  placed: true
9181
9185
  });
9182
9186
  }
@@ -9205,6 +9209,8 @@ function placeNext(placed) {
9205
9209
  order,
9206
9210
  hidden: false,
9207
9211
  locked: false,
9212
+ hugWidth: false,
9213
+ hugHeight: false,
9208
9214
  placed: false
9209
9215
  };
9210
9216
  }
@@ -9224,9 +9230,9 @@ async function scanProject(root, name) {
9224
9230
  const { pages: order, createdAt, error } = await readPageOrder(path);
9225
9231
  const pages = await Promise.all(order.map((page, index) => scanPage(root, name, page, index)));
9226
9232
  const times = await Promise.all([
9227
- mtimeOf(join(path, PROJECT_FILE)),
9228
- mtimeOf(path),
9229
- ...pages.flatMap((page) => [mtimeOf(join(page.path, LAYOUT_FILE)), ...page.frames.map((frame) => Date.parse(frame.modifiedAt))])
9233
+ mtimeOf$1(join(path, PROJECT_FILE)),
9234
+ mtimeOf$1(path),
9235
+ ...pages.flatMap((page) => [mtimeOf$1(join(page.path, LAYOUT_FILE)), ...page.frames.map((frame) => Date.parse(frame.modifiedAt))])
9230
9236
  ]);
9231
9237
  return {
9232
9238
  name,
@@ -9263,7 +9269,7 @@ async function scanPage(root, project, name, index) {
9263
9269
  name: frame,
9264
9270
  path: framePath,
9265
9271
  ...placement,
9266
- modifiedAt: new Date(await mtimeOf(framePath)).toISOString()
9272
+ modifiedAt: new Date(await mtimeOf$1(framePath)).toISOString()
9267
9273
  };
9268
9274
  }));
9269
9275
  return {
@@ -9279,7 +9285,7 @@ async function scanPage(root, project, name, index) {
9279
9285
  async function childFolders(dir) {
9280
9286
  return (await readdir(dir, { withFileTypes: true })).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name);
9281
9287
  }
9282
- async function mtimeOf(path) {
9288
+ async function mtimeOf$1(path) {
9283
9289
  try {
9284
9290
  return (await stat$1(path)).mtimeMs;
9285
9291
  } catch (error) {
@@ -9353,7 +9359,7 @@ async function isDirectory(path) {
9353
9359
  }
9354
9360
  //#endregion
9355
9361
  //#region package.json
9356
- var version$1 = "0.8.0";
9362
+ var version$1 = "0.9.0";
9357
9363
  var dependencies = { "playwright-core": "1.64.1" };
9358
9364
  //#endregion
9359
9365
  //#region src/shared/version.ts
@@ -9601,7 +9607,9 @@ async function framePathParts(root, ref, cwd) {
9601
9607
  /**
9602
9608
  * Places a frame on its page, writing a skeleton file only when none exists.
9603
9609
  * A file with no entry keeps its bytes and takes the box `list` showed for it
9604
- * unless a size or position is given.
9610
+ * unless a size or position is given. Every axis no size names hugs its
9611
+ * content, a preset fixing the width alone, and the box stands in until the
9612
+ * server measures.
9605
9613
  */
9606
9614
  async function addFrame(root, ref, options) {
9607
9615
  const { journal } = options;
@@ -9630,7 +9638,8 @@ async function addFrame(root, ref, options) {
9630
9638
  ...size,
9631
9639
  x: options.x ?? computed.box.x,
9632
9640
  y: options.y ?? computed.box.y
9633
- }
9641
+ },
9642
+ ...hugsOf(options)
9634
9643
  });
9635
9644
  layout.renumber();
9636
9645
  }, journal);
@@ -9638,9 +9647,11 @@ async function addFrame(root, ref, options) {
9638
9647
  }
9639
9648
  /**
9640
9649
  * Copies the frame's file byte for byte, into its own page beside the source
9641
- * or into `--to` at the source's box, on top of the target page.
9650
+ * or into `--to` at the source's box, on top of the target page. An `offset`
9651
+ * places the copy that far from the source's box instead, as an Alt-drag
9652
+ * drops it.
9642
9653
  */
9643
- async function duplicateFrame(root, ref, { to, name, journal, ...options }) {
9654
+ async function duplicateFrame(root, ref, { to, name, offset, journal, ...options }) {
9644
9655
  const source = await resolveFrameRef(root, ref, options);
9645
9656
  const target = to ? await resolvePageRef(root, to, options) : void 0;
9646
9657
  const from = pageDir(source);
@@ -9650,7 +9661,11 @@ async function duplicateFrame(root, ref, { to, name, journal, ...options }) {
9650
9661
  const targetLayout = layoutAt(layouts, into);
9651
9662
  const copyName = freeFrameName(targetLayout.names, source.name, name);
9652
9663
  const placement = sourceLayout.placement(source.name);
9653
- const box = into === from ? {
9664
+ const box = offset ? {
9665
+ ...placement.box,
9666
+ x: placement.box.x + offset.x,
9667
+ y: placement.box.y + offset.y
9668
+ } : into === from ? {
9654
9669
  ...placement.box,
9655
9670
  x: placement.box.x + placement.box.width + 80
9656
9671
  } : placement.box;
@@ -9733,10 +9748,55 @@ async function resizeFrame(root, ref, options) {
9733
9748
  box: {
9734
9749
  ...placement.box,
9735
9750
  ...size
9736
- }
9751
+ },
9752
+ hugWidth: placement.hugWidth && size.width === void 0,
9753
+ hugHeight: placement.hugHeight && size.height === void 0
9737
9754
  }));
9738
9755
  }
9739
9756
  /**
9757
+ * Sets a frame's height to its content's measured height and turns hugging
9758
+ * back on for that axis, the inverse of the resize that fixed it.
9759
+ */
9760
+ async function fitHeight(root, ref, height, options) {
9761
+ return updatePlacement(root, ref, options, (placement) => ({
9762
+ ...placement,
9763
+ box: {
9764
+ ...placement.box,
9765
+ height
9766
+ },
9767
+ hugHeight: true
9768
+ }));
9769
+ }
9770
+ /**
9771
+ * Writes the sizes the server measured, on the axes each frame's stored entry
9772
+ * hugs and nowhere else, under the page's lock. It sets no flag and takes no
9773
+ * journal, since the developer never set that size, and answers the names
9774
+ * whose entry changed, none when every size already stands.
9775
+ */
9776
+ async function setMeasured(root, pageRef, sizes, options) {
9777
+ const page = await resolvePageRef(root, pageRef, options);
9778
+ return withLayouts([page.path], async (layouts) => {
9779
+ const layout = layoutAt(layouts, page.path);
9780
+ const written = [];
9781
+ for (const [name, size] of Object.entries(sizes)) {
9782
+ if (!layout.hasEntry(name) || !layout.names.includes(name)) continue;
9783
+ const placement = layout.placement(name);
9784
+ const box = {
9785
+ ...placement.box,
9786
+ width: placement.hugWidth ? size.width : placement.box.width,
9787
+ height: placement.hugHeight ? size.height : placement.box.height
9788
+ };
9789
+ if (sameBox(box, placement.box)) continue;
9790
+ layout.set(name, {
9791
+ ...placement,
9792
+ box
9793
+ });
9794
+ written.push(name);
9795
+ }
9796
+ return written;
9797
+ });
9798
+ }
9799
+ /**
9740
9800
  * Sets the boxes of several frames on one page under one lock and one write,
9741
9801
  * the one path a hand move or resize takes. `expected` holds the boxes the
9742
9802
  * client started from, and a frame whose stored box differs from it refuses
@@ -9753,7 +9813,12 @@ async function setBoxes(root, pageRef, boxes, expected, options) {
9753
9813
  const placement = layout.placement(name);
9754
9814
  if (placement.locked) throw new FrameboardError("frame-locked", `${ref} is locked.`, { ref });
9755
9815
  const started = expected[name];
9756
- if (!started || !sameBox(started, placement.box)) throw new FrameboardError("stale-layout", `${ref} moved since this edit began, so nothing was written.`, {
9816
+ const box = boxes[name];
9817
+ const kept = box && started ? measuredAxes(placement, box, started) : {};
9818
+ if (!started || !sameBox({
9819
+ ...started,
9820
+ ...kept
9821
+ }, placement.box)) throw new FrameboardError("stale-layout", `${ref} moved since this edit began, so nothing was written.`, {
9757
9822
  ref,
9758
9823
  stored: placement.box,
9759
9824
  expected: started ?? null
@@ -9761,16 +9826,37 @@ async function setBoxes(root, pageRef, boxes, expected, options) {
9761
9826
  return {
9762
9827
  name,
9763
9828
  placement,
9764
- box: boxes[name]
9829
+ box,
9830
+ kept,
9831
+ started
9765
9832
  };
9766
9833
  });
9767
- for (const { name, placement, box } of placements) if (box) layout.set(name, {
9768
- ...placement,
9769
- box: { ...box }
9770
- });
9834
+ for (const { name, placement, box, kept, started } of placements) {
9835
+ if (!box || !started) continue;
9836
+ layout.set(name, {
9837
+ ...placement,
9838
+ box: {
9839
+ ...box,
9840
+ ...kept
9841
+ },
9842
+ hugWidth: placement.hugWidth && box.width === started.width,
9843
+ hugHeight: placement.hugHeight && box.height === started.height
9844
+ });
9845
+ }
9771
9846
  }, options.journal);
9772
9847
  return (await frameRecords(root, page.project, page.name)).filter((frame) => names.includes(frame.name));
9773
9848
  }
9849
+ /**
9850
+ * The stored size of each hugging axis a hand write leaves at the size it
9851
+ * started from, since the server may have measured that axis since and a move
9852
+ * never meant to set it.
9853
+ */
9854
+ function measuredAxes(placement, box, started) {
9855
+ return {
9856
+ ...placement.hugWidth && box.width === started.width ? { width: placement.box.width } : {},
9857
+ ...placement.hugHeight && box.height === started.height ? { height: placement.box.height } : {}
9858
+ };
9859
+ }
9774
9860
  function sameBox(a, b) {
9775
9861
  return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
9776
9862
  }
@@ -9817,6 +9903,13 @@ async function updatePlacement(root, ref, options, change) {
9817
9903
  }, options.journal);
9818
9904
  return frameRecord(root, frame.project, frame.page, frame.name);
9819
9905
  }
9906
+ /** Which axes `frame add` leaves hugging: every one no size option names, the height under a preset. */
9907
+ function hugsOf({ size, width, height }) {
9908
+ return {
9909
+ hugWidth: size === void 0 && width === void 0,
9910
+ hugHeight: height === void 0
9911
+ };
9912
+ }
9820
9913
  /** The size a verb sets, from a preset or from explicit width and height. */
9821
9914
  function sizeOf({ size, width, height }) {
9822
9915
  if (size !== void 0 && (width !== void 0 || height !== void 0)) throw new FrameboardError("usage", "Pass --size or --width and --height, not both.", {
@@ -9874,19 +9967,24 @@ var PageLayout = class {
9874
9967
  return Math.max(...this.names.map((name) => this.placement(name).order + 1), 0);
9875
9968
  }
9876
9969
  /**
9877
- * Writes all seven keys on the entry it creates or changes, after any key
9878
- * the entry already held, so unknown keys survive in place.
9970
+ * Writes the seven fixed keys on the entry it creates or changes, after any
9971
+ * key the entry already held, so unknown keys survive in place. A hug flag
9972
+ * is written on an entry it creates, once it is on, or when the entry holds
9973
+ * it, so a write to an entry from before the flags adds no key.
9879
9974
  */
9880
- set(name, { box, order, hidden, locked }) {
9975
+ set(name, { box, order, hidden, locked, hugWidth, hugHeight }) {
9976
+ const held = this.file.frames[name];
9881
9977
  this.file.frames[name] = {
9882
- ...this.file.frames[name],
9978
+ ...held,
9883
9979
  x: box.x,
9884
9980
  y: box.y,
9885
9981
  width: box.width,
9886
9982
  height: box.height,
9887
9983
  order,
9888
9984
  hidden,
9889
- locked
9985
+ locked,
9986
+ ...!held || hugWidth || held.hugWidth !== void 0 ? { hugWidth } : {},
9987
+ ...!held || hugHeight || held.hugHeight !== void 0 ? { hugHeight } : {}
9890
9988
  };
9891
9989
  this.changed = true;
9892
9990
  }
@@ -28494,7 +28592,29 @@ function swapSpan(source, span, side) {
28494
28592
  * does not keep overriding the value just set. A longhand write leaves its
28495
28593
  * shorthand alone, since the longhand comes later and already wins.
28496
28594
  */
28595
+ const BORDER_SIDES = [
28596
+ "top",
28597
+ "right",
28598
+ "bottom",
28599
+ "left"
28600
+ ];
28601
+ const BORDER_PARTS = [
28602
+ "color",
28603
+ "style",
28604
+ "width"
28605
+ ];
28497
28606
  const SHORTHAND_LONGHANDS = {
28607
+ background: [
28608
+ "background-attachment",
28609
+ "background-clip",
28610
+ "background-color",
28611
+ "background-image",
28612
+ "background-origin",
28613
+ "background-position",
28614
+ "background-repeat",
28615
+ "background-size"
28616
+ ],
28617
+ border: [...BORDER_PARTS.map((part) => `border-${part}`), ...BORDER_SIDES.flatMap((side) => [`border-${side}`, ...BORDER_PARTS.map((part) => `border-${side}-${part}`)])],
28498
28618
  "border-radius": [
28499
28619
  "border-top-left-radius",
28500
28620
  "border-top-right-radius",
@@ -28876,7 +28996,9 @@ const STATUS$3 = {
28876
28996
  "frame-locked": 423,
28877
28997
  "layout-invalid": 422,
28878
28998
  "project-file-invalid": 422,
28879
- "lock-timeout": 503
28999
+ "fit-unbounded": 422,
29000
+ "lock-timeout": 503,
29001
+ "browser-not-found": 503
28880
29002
  };
28881
29003
  /**
28882
29004
  * Answers a refusal in the CLI's `{ ok, error }` envelope, for a route
@@ -35713,6 +35835,14 @@ const frameAddSchema = object$1({
35713
35835
  y: coordinate.optional()
35714
35836
  });
35715
35837
  const framesSchema = object$1({ refs });
35838
+ const frameDuplicateSchema = object$1({
35839
+ refs,
35840
+ offset: object$1({
35841
+ x: coordinate,
35842
+ y: coordinate
35843
+ }).optional()
35844
+ });
35845
+ const frameSchema = object$1({ ref });
35716
35846
  const pasteSchema = object$1({
35717
35847
  ref,
35718
35848
  at: object$1({
@@ -35735,8 +35865,10 @@ const UNTITLED = "untitled";
35735
35865
  * Each write reports into its own journal and records one step, so the
35736
35866
  * developer can undo it, and names the page the board shows on either side
35737
35867
  * of it, so an undo can follow a page it brings back or renames.
35868
+ * `measure` reads a frame's content on the warm browser for a fit, which
35869
+ * refuses `browser-not-found` where none is given.
35738
35870
  */
35739
- function structureRoutes(root, access, history) {
35871
+ function structureRoutes(root, access, history, measure) {
35740
35872
  const app = new Hono();
35741
35873
  app.use("/api/page/*", requireWriter(access));
35742
35874
  app.use("/api/frame/*", requireWriter(access));
@@ -35894,10 +36026,11 @@ function structureRoutes(root, access, history) {
35894
36026
  });
35895
36027
  });
35896
36028
  app.post("/api/frame/duplicate", async (c) => {
35897
- const body = await parseBody$1(c.req.raw, framesSchema);
36029
+ const body = await parseBody$1(c.req.raw, frameDuplicateSchema);
35898
36030
  const copies = await eachFrame(body.refs, (frame, journal) => duplicateFrame(root, frame, {
35899
36031
  cwd,
35900
- journal
36032
+ journal,
36033
+ offset: body.offset
35901
36034
  }), (records) => records.map((record) => record.ref));
35902
36035
  return c.json({
35903
36036
  ok: true,
@@ -35940,6 +36073,32 @@ function structureRoutes(root, access, history) {
35940
36073
  data: frames
35941
36074
  });
35942
36075
  });
36076
+ /**
36077
+ * Sets one frame's height to its content's own and turns its height
36078
+ * hugging on, as `frame fit` does, refusing a frame whose content sizes
36079
+ * itself off the viewport. The width is reported, never changed.
36080
+ */
36081
+ app.post("/api/frame/fit", async (c) => {
36082
+ const body = await parseBody$1(c.req.raw, frameSchema);
36083
+ await refuseLocked([body.ref]);
36084
+ await refuseHeldFrames([body.ref]);
36085
+ if (!measure) throw new FrameboardError("browser-not-found", "Fit height needs the board server's browser, and none runs here.");
36086
+ const frame = await readFrame$1(root, body.ref, { cwd });
36087
+ const measured = await measure(frame);
36088
+ const fit = await recorded((journal) => fitHeight(root, frame.ref, measured.height, {
36089
+ cwd,
36090
+ journal
36091
+ }), (record) => onFrames([record.ref]));
36092
+ return c.json({
36093
+ ok: true,
36094
+ data: {
36095
+ frame: fit,
36096
+ contentHeight: measured.height,
36097
+ contentWidth: measured.contentWidth,
36098
+ tooWide: measured.contentWidth > fit.box.width
36099
+ }
36100
+ });
36101
+ });
35943
36102
  app.post("/api/frame/delete", async (c) => {
35944
36103
  const body = await parseBody$1(c.req.raw, framesSchema);
35945
36104
  await refuseLocked(body.refs);
@@ -36110,7 +36269,7 @@ function boardHostGuard(port) {
36110
36269
  await next();
36111
36270
  };
36112
36271
  }
36113
- function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails }) {
36272
+ function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails, measure }) {
36114
36273
  const app = new Hono();
36115
36274
  const given = tokens ?? null;
36116
36275
  app.use("*", async (c, next) => {
@@ -36129,7 +36288,7 @@ function createApp({ clientDir, root, port, actions, tickets, renderFrame, faces
36129
36288
  }));
36130
36289
  app.route("/", accessRoutes(actions.access, tickets));
36131
36290
  app.route("/", apiRoutes(root, actions, frames.look, history));
36132
- app.route("/", structureRoutes(root, actions.access, history));
36291
+ app.route("/", structureRoutes(root, actions.access, history, measure));
36133
36292
  app.route("/", historyRoutes(actions.access, history));
36134
36293
  app.route("/", notesRoutes(root, actions.access, delivery));
36135
36294
  app.route("/", assetsRoutes(root, actions.access));
@@ -37118,50 +37277,100 @@ function readTextSizes() {
37118
37277
  }
37119
37278
  //#endregion
37120
37279
  //#region src/server/capture/fit.ts
37121
- /**
37122
- * Sets a frame's height to its content's own height, measured at its layout
37123
- * width with a 1 px tall viewport and again at its current height. Readings
37124
- * that differ mean the content sizes itself off the viewport, which has no
37125
- * height of its own to fit, so that refuses `fit-unbounded` and writes
37126
- * nothing. The width is reported, never changed.
37127
- */
37128
- async function fitFrame(browser, { baseUrl, frame, ...options }) {
37129
- const { width, height } = frame.box;
37130
- const short = await measure(browser, baseUrl, frame.ref, {
37131
- width,
37132
- height: 1
37133
- });
37134
- const current = await measure(browser, baseUrl, frame.ref, {
37135
- width,
37136
- height
37137
- });
37138
- if (short.height !== current.height) throw new FrameboardError("fit-unbounded", `${frame.ref} grows with the viewport, measuring ${short.height} px in a 1 px viewport and ${current.height} px at its ${height} px height, so it has no content height to fit. Size it by hand with frame resize.`, {
37139
- ref: frame.ref,
37140
- heights: [short.height, current.height]
37141
- });
37142
- return {
37143
- frame: await resizeFrame(options.root, frame.ref, {
37144
- ...options,
37145
- height: short.height
37146
- }),
37147
- contentHeight: short.height,
37148
- contentWidth: current.width,
37149
- tooWide: current.width > width
37150
- };
37151
- }
37152
- async function measure(browser, baseUrl, ref, box) {
37280
+ /** The widest a hugging width grows, past which the layout check reports the content clipped. */
37281
+ const HUG_MAX_WIDTH = FRAME_SIZES.desktop.width;
37282
+ /**
37283
+ * Measures a frame's content the way `frame fit` and the server's hug step
37284
+ * both read it, in one page resized between readings. A hugging width takes
37285
+ * the content's `fit-content` width up to `HUG_MAX_WIDTH`, and the height is
37286
+ * read at that width with a 1 px tall viewport and again at the box's height.
37287
+ * Readings that differ mean the content sizes itself off the viewport, which
37288
+ * has no height of its own to fit, so that refuses `fit-unbounded`. Finite
37289
+ * animations finish before the first reading, so an entrance is read at its
37290
+ * settled size.
37291
+ */
37292
+ async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
37153
37293
  const opened = await openFrame(browser, {
37154
37294
  baseUrl,
37155
37295
  ref,
37156
37296
  box,
37157
- theme: "light"
37297
+ theme: "light",
37298
+ fonts
37158
37299
  });
37159
37300
  try {
37160
- return await opened.page.evaluate(readContentSize);
37301
+ const { page } = opened;
37302
+ await page.evaluate(finishAnimations);
37303
+ const empty = await page.evaluate(isBodyEmpty);
37304
+ let width = box.width;
37305
+ if (hugWidth && !empty) {
37306
+ await page.setViewportSize({
37307
+ width: HUG_MAX_WIDTH,
37308
+ height: box.height
37309
+ });
37310
+ width = Math.min(HUG_MAX_WIDTH, await page.evaluate(readFitWidth));
37311
+ }
37312
+ const short = await readAt(page, {
37313
+ width,
37314
+ height: 1
37315
+ });
37316
+ const current = await readAt(page, {
37317
+ width,
37318
+ height: box.height
37319
+ });
37320
+ if (short.height !== current.height) throw new FrameboardError("fit-unbounded", `${ref} grows with the viewport, measuring ${short.height} px in a 1 px viewport and ${current.height} px at its ${box.height} px height, so it has no content height to fit. Size it by hand with frame resize.`, {
37321
+ ref,
37322
+ heights: [short.height, current.height]
37323
+ });
37324
+ return {
37325
+ width,
37326
+ height: short.height,
37327
+ contentWidth: current.width,
37328
+ empty
37329
+ };
37161
37330
  } finally {
37162
37331
  await opened.close();
37163
37332
  }
37164
37333
  }
37334
+ /**
37335
+ * Sets a frame's height to its content's own height at its layout width and
37336
+ * turns its height hugging on. The width is reported, never changed.
37337
+ */
37338
+ async function fitFrame(browser, { baseUrl, frame, ...options }) {
37339
+ const measured = await measureContent(browser, {
37340
+ baseUrl,
37341
+ ref: frame.ref,
37342
+ box: frame.box,
37343
+ hugWidth: false
37344
+ });
37345
+ return {
37346
+ frame: await fitHeight(options.root, frame.ref, measured.height, options),
37347
+ contentHeight: measured.height,
37348
+ contentWidth: measured.contentWidth,
37349
+ tooWide: measured.contentWidth > frame.box.width
37350
+ };
37351
+ }
37352
+ async function readAt(page, viewport) {
37353
+ await page.setViewportSize(viewport);
37354
+ return page.evaluate(readContentSize);
37355
+ }
37356
+ function finishAnimations() {
37357
+ for (const animation of document.getAnimations()) {
37358
+ const end = animation.effect?.getComputedTiming().endTime;
37359
+ if (typeof end === "number" && Number.isFinite(end)) animation.finish();
37360
+ }
37361
+ }
37362
+ function isBodyEmpty() {
37363
+ const body = document.body;
37364
+ return body.children.length === 0 && (body.textContent ?? "").trim() === "";
37365
+ }
37366
+ function readFitWidth() {
37367
+ const root = document.documentElement;
37368
+ const before = root.style.width;
37369
+ root.style.width = "fit-content";
37370
+ const width = Math.ceil(root.getBoundingClientRect().width);
37371
+ root.style.width = before;
37372
+ return Math.max(1, width);
37373
+ }
37165
37374
  function readContentSize() {
37166
37375
  const root = document.documentElement;
37167
37376
  const crops = (element) => {
@@ -37583,6 +37792,9 @@ const frameRecordSchema = object$1({
37583
37792
  order: number(),
37584
37793
  hidden: boolean$1(),
37585
37794
  locked: boolean$1(),
37795
+ /** Whether each axis takes its size from the content rather than holding it. */
37796
+ hugWidth: boolean$1(),
37797
+ hugHeight: boolean$1(),
37586
37798
  placed: boolean$1(),
37587
37799
  modifiedAt: string$1()
37588
37800
  });
@@ -37994,7 +38206,9 @@ function contentFormat() {
37994
38206
  defaultFrameSize: DEFAULT_FRAME_SIZE,
37995
38207
  layout: [
37996
38208
  "x and y are integers, width and height integers of at least 1, and order an integer of at least 0, where a higher order draws on top.",
37997
- "hidden and locked read as false when absent.",
38209
+ "hidden, locked, hugWidth, and hugHeight read as false when absent, and an axis whose hug flag is false holds the size its entry states.",
38210
+ `An axis that hugs takes its size from the frame's content: a running serve measures it after each write to the frame file, its width at most ${FRAME_SIZES.desktop.width} px, and writes width and height alone, never a flag. Content sized off the viewport keeps the box it has.`,
38211
+ "frame add with no size hugs both axes, --size or --width fixes the width and hugs the height, and --height fixes the height alone, its box standing in until serve measures. frame resize and a hand resize fix each axis they set, and frame fit sets the height and turns hugHeight on.",
37998
38212
  "Frames sort by order, then name, and a write that changes order renumbers the page from 0.",
37999
38213
  `A frame file with no entry is unplaced: it reads at desktop size, y 0, 80 px past the right edge of every frame placed before it in name order, and frame add persists that box.`,
38000
38214
  "An entry with no frame file beside it is ignored on read and kept on write.",
@@ -38255,7 +38469,7 @@ function registerFrame(program, context) {
38255
38469
  data: record,
38256
38470
  human: `${what} ${record.ref}`
38257
38471
  });
38258
- act(withPosition(withSize(verb("add", "Place a frame, writing a skeleton file when none exists. Defaults to desktop size past every frame."))), context, async ([ref = ""], options) => done(await addFrame(await boardOf(options, io), ref, {
38472
+ act(withPosition(withSize(verb("add", "Place a frame past every frame, writing a skeleton file when none exists. Each axis no size names hugs its content, so a preset or --width fixes the width and the height hugs."))), context, async ([ref = ""], options) => done(await addFrame(await boardOf(options, io), ref, {
38259
38473
  ...options,
38260
38474
  cwd: io.cwd
38261
38475
  }), "Added"));
@@ -38267,11 +38481,11 @@ function registerFrame(program, context) {
38267
38481
  ...options,
38268
38482
  cwd: io.cwd
38269
38483
  }), "Moved to"));
38270
- act(withSize(verb("resize", "Set a frame size")), context, async ([ref = ""], options) => done(await resizeFrame(await boardOf(options, io), ref, {
38484
+ act(withSize(verb("resize", "Set a frame size, fixing each axis it sets")), context, async ([ref = ""], options) => done(await resizeFrame(await boardOf(options, io), ref, {
38271
38485
  ...options,
38272
38486
  cwd: io.cwd
38273
38487
  }), "Resized"));
38274
- act(verb("fit", "Set a frame height to its content's own height, reporting a width too wide for the frame"), context, async ([ref = ""], options) => {
38488
+ act(verb("fit", "Set a frame height to its content's own height and hug it from then on, reporting a width too wide for the frame"), context, async ([ref = ""], options) => {
38275
38489
  const root = await boardOf(options, io);
38276
38490
  const refOptions = {
38277
38491
  project: options.project,
@@ -42918,8 +43132,8 @@ const UNREADABLE = /* @__PURE__ */ new Set(["layout-invalid", "project-file-inva
42918
43132
  async function reads(change, side) {
42919
43133
  switch (change.kind) {
42920
43134
  case "entry": {
42921
- const file = await readRecord(change.layout, layoutSpec);
42922
- return isDeepStrictEqual(file.frames[change.frame], change[side]);
43135
+ const stored = (await readRecord(change.layout, layoutSpec)).frames[change.frame];
43136
+ return isDeepStrictEqual(stored, withMeasured(change[side], stored));
42923
43137
  }
42924
43138
  case "pages": {
42925
43139
  const file = await readRecord(change.file, {
@@ -42936,6 +43150,20 @@ async function reads(change, side) {
42936
43150
  case "element": return await exists(change.path) && holdsSpan(await readFile(change.path, "utf8"), change.span, side);
42937
43151
  }
42938
43152
  }
43153
+ /**
43154
+ * The entry a step holds, taking the stored size on each axis both it and the
43155
+ * stored entry hug, since the server measures that size and the developer
43156
+ * never set it, so a measure after a hand move neither overtakes the step nor
43157
+ * is reverted by it.
43158
+ */
43159
+ function withMeasured(entry, stored) {
43160
+ if (!entry || !stored) return entry;
43161
+ return {
43162
+ ...entry,
43163
+ ...entry.hugWidth && stored.hugWidth ? { width: stored.width } : {},
43164
+ ...entry.hugHeight && stored.hugHeight ? { height: stored.height } : {}
43165
+ };
43166
+ }
42939
43167
  const OTHER = {
42940
43168
  before: "after",
42941
43169
  after: "before"
@@ -42950,7 +43178,7 @@ async function restore(change, side) {
42950
43178
  case "entry": {
42951
43179
  const file = await readRecord(change.layout, layoutSpec);
42952
43180
  const frames = { ...file.frames };
42953
- const entry = change[side];
43181
+ const entry = withMeasured(change[side], frames[change.frame]);
42954
43182
  if (entry) frames[change.frame] = entry;
42955
43183
  else delete frames[change.frame];
42956
43184
  await writeRecord(change.layout, {
@@ -45229,6 +45457,90 @@ function send(socket, message) {
45229
45457
  if (socket.readyState === socket.OPEN) socket.send(JSON.stringify(message));
45230
45458
  }
45231
45459
  //#endregion
45460
+ //#region src/server/live/hug.ts
45461
+ /**
45462
+ * The server's hug step. A frame hugs when either flag is on, and its sizes
45463
+ * are written through `setMeasured`, which takes the page's lock, writes
45464
+ * only the axes the stored entry still hugs, and records no undo step. A
45465
+ * frame whose content sizes itself off the viewport, whose body is empty,
45466
+ * or that fails to load keeps its box, and a browser that cannot launch
45467
+ * writes nothing at all.
45468
+ */
45469
+ function createHug({ root, measure }) {
45470
+ let queue = Promise.resolve();
45471
+ let closed = false;
45472
+ const run = async (board, refs) => {
45473
+ const pages = /* @__PURE__ */ new Map();
45474
+ for (const frame of huggingFrames(board, refs)) {
45475
+ if (closed) return false;
45476
+ let size;
45477
+ try {
45478
+ size = await measure(frame);
45479
+ } catch (error) {
45480
+ if (error instanceof FrameboardError && error.code === "browser-not-found") break;
45481
+ continue;
45482
+ }
45483
+ if (size.empty) continue;
45484
+ const page = `${frame.project}/${frame.page}`;
45485
+ pages.set(page, {
45486
+ ...pages.get(page),
45487
+ [frame.name]: size
45488
+ });
45489
+ }
45490
+ let written = false;
45491
+ for (const [page, sizes] of pages) {
45492
+ if (closed) break;
45493
+ try {
45494
+ const names = await setMeasured(root, page, sizes, { cwd: root });
45495
+ written ||= names.length > 0;
45496
+ } catch (error) {
45497
+ if (!(error instanceof FrameboardError)) throw error;
45498
+ }
45499
+ }
45500
+ return written;
45501
+ };
45502
+ return {
45503
+ now: (board, refs) => run(board, refs),
45504
+ later: (board, refs) => {
45505
+ if (closed || huggingFrames(board, refs).length === 0) return;
45506
+ queue = queue.then(() => run(board, refs)).catch(() => {});
45507
+ },
45508
+ close: () => {
45509
+ closed = true;
45510
+ }
45511
+ };
45512
+ }
45513
+ function huggingFrames(board, refs) {
45514
+ const wanted = new Set(refs);
45515
+ return board.projects.flatMap((project) => project.pages).flatMap((page) => page.frames).filter((frame) => wanted.has(frame.ref) && frame.placed && (frame.hugWidth || frame.hugHeight));
45516
+ }
45517
+ /**
45518
+ * The hugging frames whose file was written after their page's `layout.json`,
45519
+ * as one edited while no server ran, which the start sweep measures before
45520
+ * the first board goes out. Every other frame's stored size already holds.
45521
+ */
45522
+ async function writtenSinceLayout(board) {
45523
+ const pages = board.projects.flatMap((project) => project.pages);
45524
+ return (await Promise.all(pages.map(async (page) => {
45525
+ const hugging = page.frames.filter((frame) => frame.placed && (frame.hugWidth || frame.hugHeight));
45526
+ if (hugging.length === 0) return [];
45527
+ const layout = await mtimeOf(join(page.path, LAYOUT_FILE));
45528
+ return hugging.filter((frame) => Date.parse(frame.modifiedAt) > layout).map((frame) => frame.ref);
45529
+ }))).flat();
45530
+ }
45531
+ async function mtimeOf(path) {
45532
+ try {
45533
+ return (await stat$1(path)).mtimeMs;
45534
+ } catch {
45535
+ return 0;
45536
+ }
45537
+ }
45538
+ /** The frames a batch reloads through their own file, as against an asset or a token sheet. */
45539
+ function ownFileRefs(board, paths) {
45540
+ const written = new Set(paths);
45541
+ return board.projects.flatMap((project) => project.pages).flatMap((page) => page.frames).filter((frame) => written.has(frame.path)).map((frame) => frame.ref);
45542
+ }
45543
+ //#endregion
45232
45544
  //#region src/server/live/rendered-findings.ts
45233
45545
  /**
45234
45546
  * The server's warm checker. Rechecks run one at a time on their own queue,
@@ -45271,7 +45583,7 @@ function createRenderedFindings({ check, onResult }) {
45271
45583
  check(frame).then((findings) => {
45272
45584
  const recovered = failure !== null;
45273
45585
  failure = null;
45274
- if (current()) onResult(ref, findings);
45586
+ if (findings && current()) onResult(ref, findings);
45275
45587
  if (!recovered) return;
45276
45588
  for (const [other, record] of known) if (other !== ref && !pending.has(other)) enqueue(other, record);
45277
45589
  }).catch((error) => {
@@ -45592,18 +45904,21 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45592
45904
  });
45593
45905
  await thumbnails.empty();
45594
45906
  const rendered = createRenderedFindings({
45595
- check: async (frame) => checkRendered(await browser.get(), {
45596
- baseUrl: baseUrl(),
45597
- frame: {
45598
- ref: frame.ref,
45599
- path: boardPath(root, frame.path),
45600
- box: {
45601
- width: frame.box.width,
45602
- height: frame.box.height
45603
- }
45604
- },
45605
- config: readConfig(root, frame.project)
45606
- }),
45907
+ check: async (frame) => {
45908
+ const list = await checkRendered(await browser.get(), {
45909
+ baseUrl: baseUrl(),
45910
+ frame: {
45911
+ ref: frame.ref,
45912
+ path: boardPath(root, frame.path),
45913
+ box: {
45914
+ width: frame.box.width,
45915
+ height: frame.box.height
45916
+ }
45917
+ },
45918
+ config: readConfig(root, frame.project)
45919
+ });
45920
+ return await modifiedAt(frame.path) === frame.modifiedAt ? list : null;
45921
+ },
45607
45922
  onResult: (ref, list) => {
45608
45923
  const before = findings.rendered([ref])[ref];
45609
45924
  if (JSON.stringify(before) === JSON.stringify(list)) return;
@@ -45614,6 +45929,17 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45614
45929
  });
45615
45930
  }
45616
45931
  });
45932
+ const measure = async (frame) => measureContent(await browser.get(), {
45933
+ baseUrl: baseUrl(),
45934
+ ref: frame.ref,
45935
+ box: frame.box,
45936
+ hugWidth: frame.hugWidth,
45937
+ fonts: "wait"
45938
+ });
45939
+ const hug = createHug({
45940
+ root,
45941
+ measure
45942
+ });
45617
45943
  const app = createApp({
45618
45944
  clientDir,
45619
45945
  facesDir,
@@ -45626,6 +45952,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45626
45952
  selection,
45627
45953
  renderFrame,
45628
45954
  thumbnails,
45955
+ measure,
45629
45956
  checks: {
45630
45957
  refresh: () => inTurn(async () => {
45631
45958
  try {
@@ -45666,10 +45993,13 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45666
45993
  });
45667
45994
  server.on("upgrade", hub.handleUpgrade);
45668
45995
  inTurn(async () => {
45669
- const board = await scanBoard(root);
45996
+ let board = await scanBoard(root);
45997
+ const stale = await writtenSinceLayout(board).catch(() => []);
45998
+ if (await hug.now(board, stale).catch(() => false)) board = await scanBoard(root);
45670
45999
  await tracker.prime(board);
45671
46000
  findings.update(board, "all");
45672
46001
  rendered.queue(board, []);
46002
+ hug.later(board, board.projects.flatMap((project) => project.pages.flatMap((page) => page.frames.map((frame) => frame.ref).filter((ref) => !stale.includes(ref)))));
45673
46003
  });
45674
46004
  claims.push();
45675
46005
  const watcher = await watchBoard(root, tokens ? [tokens] : []);
@@ -45685,6 +46015,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45685
46015
  tracker,
45686
46016
  claims,
45687
46017
  thumbnails,
46018
+ hug,
45688
46019
  settleLater
45689
46020
  }));
45690
46021
  });
@@ -45699,6 +46030,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45699
46030
  boardUrl,
45700
46031
  close: async () => {
45701
46032
  rendered.close();
46033
+ hug.close();
45702
46034
  claims.close();
45703
46035
  for (const timer of settling) clearTimeout(timer);
45704
46036
  await Promise.all([
@@ -45722,10 +46054,13 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45722
46054
  * notes or frames it touched, whose queue it offers to delivery. The frames
45723
46055
  * an agent changed wait out the grace before the board hears of them.
45724
46056
  */
45725
- async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, settleLater }) {
46057
+ async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, hug, settleLater }) {
45726
46058
  let board;
46059
+ let own;
45727
46060
  try {
45728
46061
  board = await scanBoard(root);
46062
+ own = ownFileRefs(board, paths);
46063
+ if (await hug.now(board, own).catch(() => false)) board = await scanBoard(root);
45729
46064
  } catch {
45730
46065
  return;
45731
46066
  }
@@ -45734,6 +46069,7 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
45734
46069
  data: board
45735
46070
  });
45736
46071
  const refs = reloadRefs(root, paths, board, tokens);
46072
+ hug.later(board, refs.filter((ref) => !own.includes(ref)));
45737
46073
  if (refs.length > 0) {
45738
46074
  hub.broadcast({
45739
46075
  type: "reload",
@@ -45757,6 +46093,13 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
45757
46093
  rendered.queue(board, recheckRefs(root, paths, board, tokens));
45758
46094
  await pushNotes(root, paths, hub, delivery);
45759
46095
  }
46096
+ async function modifiedAt(path) {
46097
+ try {
46098
+ return new Date((await stat$1(path)).mtimeMs).toISOString();
46099
+ } catch {
46100
+ return null;
46101
+ }
46102
+ }
45760
46103
  /**
45761
46104
  * A notes write changes its page's notes, and a frame write can lose an
45762
46105
  * element note its anchor, so both reread the page. A frame write on a page