@designfever/web-review-kit 0.8.1 → 0.8.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.
@@ -1321,6 +1321,7 @@ var DraftPreviewController = class {
1321
1321
  };
1322
1322
  element.style.visibility = "hidden";
1323
1323
  }
1324
+ syncDraftPreviewCloneRect(this.snapshot.clone, element);
1324
1325
  const metrics = this.config.getMetrics(draft);
1325
1326
  const translate = `translate(${toCssNumber(metrics.cssX)}px, ${toCssNumber(
1326
1327
  metrics.cssY
@@ -1345,16 +1346,11 @@ var DraftPreviewController = class {
1345
1346
  }
1346
1347
  };
1347
1348
  function positionDraftPreviewClone(clone, element, computedStyle) {
1348
- const rect = element.getBoundingClientRect();
1349
1349
  clone.setAttribute("data-dfwr-adjust-preview", "true");
1350
1350
  clone.setAttribute("aria-hidden", "true");
1351
1351
  clone.style.position = "fixed";
1352
- clone.style.left = `${toCssNumber(rect.left)}px`;
1353
- clone.style.top = `${toCssNumber(rect.top)}px`;
1354
1352
  clone.style.right = "auto";
1355
1353
  clone.style.bottom = "auto";
1356
- clone.style.width = `${toCssNumber(rect.width)}px`;
1357
- clone.style.height = `${toCssNumber(rect.height)}px`;
1358
1354
  clone.style.maxWidth = "none";
1359
1355
  clone.style.maxHeight = "none";
1360
1356
  clone.style.margin = "0";
@@ -1366,6 +1362,14 @@ function positionDraftPreviewClone(clone, element, computedStyle) {
1366
1362
  clone.style.willChange = "transform";
1367
1363
  clone.style.transformOrigin = "top left";
1368
1364
  clone.style.transform = "none";
1365
+ syncDraftPreviewCloneRect(clone, element);
1366
+ }
1367
+ function syncDraftPreviewCloneRect(clone, element) {
1368
+ const rect = element.getBoundingClientRect();
1369
+ clone.style.left = `${toCssNumber(rect.left)}px`;
1370
+ clone.style.top = `${toCssNumber(rect.top)}px`;
1371
+ clone.style.width = `${toCssNumber(rect.width)}px`;
1372
+ clone.style.height = `${toCssNumber(rect.height)}px`;
1369
1373
  }
1370
1374
  function getDraftPreviewDisplay(display) {
1371
1375
  if (display === "inline" || display === "contents") return "inline-block";
@@ -1441,11 +1445,11 @@ function createStyleElement() {
1441
1445
  --df-review-color-text: #f7f7f2;
1442
1446
  --df-review-color-text-muted: rgba(247, 247, 242, 0.62);
1443
1447
  --df-review-color-text-subtle: rgba(247, 247, 242, 0.46);
1444
- --df-review-color-accent: #d7ff5f;
1448
+ --df-review-color-accent: #7cc7ff;
1445
1449
  --df-review-color-accent-contrast: #171b1e;
1446
- --df-review-color-accent-soft: rgba(215, 255, 95, 0.16);
1447
- --df-review-color-accent-ring: rgba(215, 255, 95, 0.6);
1448
- --df-review-color-area: #63d7c7;
1450
+ --df-review-color-accent-soft: rgba(124, 199, 255, 0.16);
1451
+ --df-review-color-accent-ring: rgba(124, 199, 255, 0.6);
1452
+ --df-review-color-area: #7cc7ff;
1449
1453
  --df-review-color-error: #ffb7a7;
1450
1454
  --df-review-shadow-panel: 0 18px 48px rgba(0, 0, 0, 0.34);
1451
1455
  --df-review-shadow-popover: 0 16px 38px rgba(0, 0, 0, 0.32);
@@ -1631,9 +1635,9 @@ function createStyleElement() {
1631
1635
  .dfwr-selection-highlight {
1632
1636
  position: fixed;
1633
1637
  z-index: 1;
1634
- border: 2px solid #d7ff5f;
1638
+ border: 2px solid #7cc7ff;
1635
1639
  border-radius: var(--df-review-radius-xs);
1636
- background: rgba(215, 255, 95, 0.08);
1640
+ background: rgba(124, 199, 255, 0.08);
1637
1641
  box-shadow:
1638
1642
  0 0 0 1px rgba(31, 36, 40, 0.72),
1639
1643
  0 0 0 9999px rgba(0, 0, 0, 0.12),
@@ -1642,8 +1646,8 @@ function createStyleElement() {
1642
1646
  }
1643
1647
 
1644
1648
  .dfwr-selection-highlight.is-draft {
1645
- border-color: #63d7c7;
1646
- background: rgba(99, 215, 199, 0.1);
1649
+ border-color: #7cc7ff;
1650
+ background: rgba(124, 199, 255, 0.1);
1647
1651
  box-shadow:
1648
1652
  0 0 0 1px rgba(31, 36, 40, 0.72),
1649
1653
  0 0 0 9999px rgba(0, 0, 0, 0.08),
@@ -1654,9 +1658,9 @@ function createStyleElement() {
1654
1658
  .dfwr-dom-hover {
1655
1659
  position: fixed;
1656
1660
  z-index: 2;
1657
- border: 1px solid #d7ff5f;
1661
+ border: 1px solid #7cc7ff;
1658
1662
  border-radius: var(--df-review-radius-xs);
1659
- background: rgba(215, 255, 95, 0.1);
1663
+ background: rgba(124, 199, 255, 0.1);
1660
1664
  box-shadow:
1661
1665
  0 0 0 1px rgba(31, 36, 40, 0.72),
1662
1666
  0 0 0 9999px rgba(0, 0, 0, 0.08);
@@ -1837,12 +1841,12 @@ function createStyleElement() {
1837
1841
  }
1838
1842
 
1839
1843
  .dfwr-area-preview-layer .dfwr-bound-marker {
1840
- border-color: #63d7c7;
1844
+ border-color: #7cc7ff;
1841
1845
  background: var(--df-review-color-panel);
1842
1846
  box-shadow:
1843
- 0 0 0 5px rgba(99, 215, 199, 0.2),
1847
+ 0 0 0 5px rgba(124, 199, 255, 0.2),
1844
1848
  0 12px 26px rgba(0, 0, 0, 0.3);
1845
- color: #63d7c7;
1849
+ color: #7cc7ff;
1846
1850
  }
1847
1851
 
1848
1852
  .dfwr-bound-marker-icon {
@@ -1925,7 +1929,7 @@ function createStyleElement() {
1925
1929
  border-radius: var(--df-review-radius-pill);
1926
1930
  background: var(--df-review-color-accent);
1927
1931
  box-shadow:
1928
- 0 0 0 4px rgba(215, 255, 95, 0.22),
1932
+ 0 0 0 4px rgba(124, 199, 255, 0.22),
1929
1933
  0 8px 18px rgba(0, 0, 0, 0.28);
1930
1934
  cursor: grab;
1931
1935
  pointer-events: auto;
@@ -1943,7 +1947,7 @@ function createStyleElement() {
1943
1947
  pointer-events: auto;
1944
1948
  color: var(--df-review-color-text);
1945
1949
  background: var(--df-review-color-panel);
1946
- border: 1px solid rgba(215, 255, 95, 0.56);
1950
+ border: 1px solid rgba(124, 199, 255, 0.56);
1947
1951
  border-radius: var(--df-review-radius-md);
1948
1952
  box-shadow: var(--df-review-shadow-popover);
1949
1953
  }
@@ -1952,7 +1956,7 @@ function createStyleElement() {
1952
1956
  .dfwr-area-draft.is-composer {
1953
1957
  max-height: min(360px, calc(100vh - 32px));
1954
1958
  overflow: auto;
1955
- border-color: rgba(99, 215, 199, 0.56);
1959
+ border-color: rgba(124, 199, 255, 0.56);
1956
1960
  }
1957
1961
 
1958
1962
  .dfwr-shell.is-docked-composer .dfwr-dom-popover.is-docked-composer,
@@ -1989,7 +1993,7 @@ function createStyleElement() {
1989
1993
 
1990
1994
  .dfwr-draft-drag-handle:hover,
1991
1995
  .dfwr-draft-drag-handle:focus-visible {
1992
- background: rgba(215, 255, 95, 0.62);
1996
+ background: rgba(124, 199, 255, 0.62);
1993
1997
  }
1994
1998
 
1995
1999
  .dfwr-draft-drag-handle:active {
@@ -2008,7 +2012,7 @@ function createStyleElement() {
2008
2012
  pointer-events: auto;
2009
2013
  color: var(--df-review-color-text);
2010
2014
  background: var(--df-review-color-panel);
2011
- border: 1px solid rgba(215, 255, 95, 0.56);
2015
+ border: 1px solid rgba(124, 199, 255, 0.56);
2012
2016
  border-radius: var(--df-review-radius-md);
2013
2017
  box-shadow: var(--df-review-shadow-popover);
2014
2018
  }
@@ -2227,7 +2231,7 @@ function createStyleElement() {
2227
2231
  }
2228
2232
 
2229
2233
  .dfwr-adjust-panel.is-active {
2230
- border-color: rgba(215, 255, 95, 0.5);
2234
+ border-color: rgba(124, 199, 255, 0.5);
2231
2235
  background: var(--df-review-color-accent-soft);
2232
2236
  }
2233
2237
 
@@ -2266,7 +2270,7 @@ function createStyleElement() {
2266
2270
  .dfwr-adjust-toggle:hover,
2267
2271
  .dfwr-adjust-toggle:focus-visible,
2268
2272
  .dfwr-adjust-toggle.is-active {
2269
- border-color: rgba(215, 255, 95, 0.68);
2273
+ border-color: rgba(124, 199, 255, 0.68);
2270
2274
  background: var(--df-review-color-accent-soft);
2271
2275
  outline: none;
2272
2276
  }
@@ -2329,7 +2333,7 @@ function createStyleElement() {
2329
2333
  }
2330
2334
 
2331
2335
  .dfwr-item:focus-visible {
2332
- outline: 2px solid rgba(215, 255, 95, 0.72);
2336
+ outline: 2px solid rgba(124, 199, 255, 0.72);
2333
2337
  outline-offset: 4px;
2334
2338
  }
2335
2339
 
@@ -2439,8 +2443,8 @@ function createStyleElement() {
2439
2443
  z-index: 2;
2440
2444
  width: 0;
2441
2445
  height: 0;
2442
- border: 1px solid #d7ff5f;
2443
- background: rgba(215, 255, 95, 0.16);
2446
+ border: 1px solid #7cc7ff;
2447
+ background: rgba(124, 199, 255, 0.16);
2444
2448
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.18);
2445
2449
  }
2446
2450
 
@@ -3517,6 +3521,12 @@ function createDomDraftLayer(context, draft, options = {}) {
3517
3521
  pin.setAttribute("aria-label", "Move DOM point");
3518
3522
  pin.style.left = `${hostPoint.x}px`;
3519
3523
  pin.style.top = `${hostPoint.y}px`;
3524
+ if (draft.isSelectionOnly) {
3525
+ pin.classList.add("is-selection-only");
3526
+ pin.tabIndex = -1;
3527
+ group.append(pin);
3528
+ return { layer: group, composer: void 0 };
3529
+ }
3520
3530
  const popover = document.createElement("div");
3521
3531
  const position = getPopoverPosition(hostPoint, environment);
3522
3532
  popover.className = [
@@ -3639,7 +3649,7 @@ function createDomDraftLayer(context, draft, options = {}) {
3639
3649
  attachments: currentDraft.attachments
3640
3650
  });
3641
3651
  };
3642
- const adjustmentControls = isElementDraft ? createAdjustmentControls(context, {
3652
+ const adjustmentControls = isElementDraft && !options.dockComposer ? createAdjustmentControls(context, {
3643
3653
  draft,
3644
3654
  pin,
3645
3655
  popover,
@@ -4285,7 +4295,7 @@ var WebReviewKitView = class {
4285
4295
  this.draftPreview = new DraftPreviewController({
4286
4296
  getEnvironment: () => this.config.getEnvironment(),
4287
4297
  getMetrics: (draft) => getDraftAdjustmentMetrics(draft, presets()),
4288
- hasAdjustment: (draft) => hasDraftAdjustment(draft, presets())
4298
+ hasAdjustment: (draft) => draft.adjustment?.preview !== false && hasDraftAdjustment(draft, presets())
4289
4299
  });
4290
4300
  this.draftContext = {
4291
4301
  config: this.config,
@@ -4306,8 +4316,11 @@ var WebReviewKitView = class {
4306
4316
  shadow.replaceChildren();
4307
4317
  shadow.append(createStyleElement());
4308
4318
  shadow.append(hiddenItemsStyle);
4309
- const hasDismissableDraft = Boolean(state.domDraft || state.areaDraft);
4310
- const shouldDockComposer = this.config.options.ui?.panel === false && hasDismissableDraft && Boolean(this.getShellComposerHost());
4319
+ const hasSelectionOnlyDraft = state.domDraft?.isSelectionOnly === true;
4320
+ const hasDismissableDraft = Boolean(
4321
+ state.domDraft && !hasSelectionOnlyDraft || state.areaDraft
4322
+ );
4323
+ const shouldDockComposer = this.config.options.ui?.panel === false && hasDismissableDraft && !hasSelectionOnlyDraft && Boolean(this.getShellComposerHost());
4311
4324
  let dockedComposer;
4312
4325
  const shell = document.createElement("div");
4313
4326
  shell.className = [
@@ -4429,6 +4442,7 @@ var WebReviewKitView = class {
4429
4442
 
4430
4443
  // src/core/web.review.kit.app.ts
4431
4444
  var ROOT_ID = "df-web-review-kit-root";
4445
+ var VIEWPORT_SCROLL_OPTIONS = { capture: true, passive: true };
4432
4446
  function isEditableEventTarget(event) {
4433
4447
  const path = event.composedPath?.() ?? [];
4434
4448
  const element = path[0] ?? event.target;
@@ -4448,6 +4462,8 @@ function createWebReviewKit(options) {
4448
4462
  toggle: () => app.toggle(),
4449
4463
  setMode: (mode) => app.setMode(mode),
4450
4464
  startElementReview: (element, comment) => app.startElementReview(element, comment),
4465
+ selectElement: (element) => app.selectElement(element),
4466
+ adjustElementSelection: (delta, adjustmentOptions) => app.adjustElementSelection(delta, adjustmentOptions),
4451
4467
  getMode: () => app.getMode(),
4452
4468
  highlightItem: (itemId) => app.highlightItem(itemId),
4453
4469
  setHiddenItemIds: (itemIds) => app.setHiddenItemIds(itemIds),
@@ -4468,6 +4484,12 @@ var WebReviewKitApp = class {
4468
4484
  this.isSelectingArea = false;
4469
4485
  this.handleKeyDown = (event) => {
4470
4486
  if (event.key === "Escape" && this.cancelMode()) {
4487
+ const activeElement = document.activeElement;
4488
+ if (activeElement instanceof HTMLButtonElement && activeElement.matches(
4489
+ ".df-review-mode-button, .df-review-section-outline-link.is-dom-select"
4490
+ )) {
4491
+ activeElement.blur();
4492
+ }
4471
4493
  event.preventDefault();
4472
4494
  event.stopPropagation();
4473
4495
  return;
@@ -4482,6 +4504,7 @@ var WebReviewKitApp = class {
4482
4504
  this.renderFrame = window.requestAnimationFrame(() => {
4483
4505
  this.renderFrame = void 0;
4484
4506
  if (this.isDraftComposerFocused()) return;
4507
+ this.syncDomDraftViewportGeometry();
4485
4508
  this.render();
4486
4509
  });
4487
4510
  };
@@ -4539,16 +4562,48 @@ var WebReviewKitApp = class {
4539
4562
  this.shadow = this.root.attachShadow({ mode: "open" });
4540
4563
  document.body.appendChild(this.root);
4541
4564
  document.addEventListener("keydown", this.handleKeyDown, true);
4542
- window.addEventListener("scroll", this.handleViewportChange, true);
4565
+ window.addEventListener(
4566
+ "scroll",
4567
+ this.handleViewportChange,
4568
+ VIEWPORT_SCROLL_OPTIONS
4569
+ );
4543
4570
  window.addEventListener("resize", this.handleViewportChange);
4571
+ this.targetViewportWindow = this.getEnvironment()?.window;
4572
+ if (this.targetViewportWindow && this.targetViewportWindow !== window) {
4573
+ this.targetViewportWindow.addEventListener(
4574
+ "scroll",
4575
+ this.handleViewportChange,
4576
+ VIEWPORT_SCROLL_OPTIONS
4577
+ );
4578
+ this.targetViewportWindow.addEventListener(
4579
+ "resize",
4580
+ this.handleViewportChange
4581
+ );
4582
+ }
4544
4583
  this.render();
4545
4584
  }
4546
4585
  destroy() {
4547
4586
  this.view.clearDraftPreview();
4548
4587
  this.clearDrafts();
4549
4588
  document.removeEventListener("keydown", this.handleKeyDown, true);
4550
- window.removeEventListener("scroll", this.handleViewportChange, true);
4589
+ window.removeEventListener(
4590
+ "scroll",
4591
+ this.handleViewportChange,
4592
+ VIEWPORT_SCROLL_OPTIONS
4593
+ );
4551
4594
  window.removeEventListener("resize", this.handleViewportChange);
4595
+ if (this.targetViewportWindow && this.targetViewportWindow !== window) {
4596
+ this.targetViewportWindow.removeEventListener(
4597
+ "scroll",
4598
+ this.handleViewportChange,
4599
+ VIEWPORT_SCROLL_OPTIONS
4600
+ );
4601
+ this.targetViewportWindow.removeEventListener(
4602
+ "resize",
4603
+ this.handleViewportChange
4604
+ );
4605
+ }
4606
+ this.targetViewportWindow = void 0;
4552
4607
  if (this.renderFrame) {
4553
4608
  window.cancelAnimationFrame(this.renderFrame);
4554
4609
  this.renderFrame = void 0;
@@ -4593,6 +4648,33 @@ var WebReviewKitApp = class {
4593
4648
  this.isSelectingArea = false;
4594
4649
  await this.bindElementDraftToElement(element, { comment });
4595
4650
  }
4651
+ async selectElement(element) {
4652
+ if (!this.isOpen) {
4653
+ this.isOpen = true;
4654
+ }
4655
+ this.setModeState("element");
4656
+ this.clearDrafts();
4657
+ this.isSelectingArea = false;
4658
+ await this.bindElementDraftToElement(element, {
4659
+ isSelectionOnly: true
4660
+ });
4661
+ }
4662
+ adjustElementSelection(delta, options) {
4663
+ if (!this.domDraft?.selection) return false;
4664
+ const current = this.domDraft.adjustment;
4665
+ this.domDraft = {
4666
+ ...this.domDraft,
4667
+ adjustment: {
4668
+ x: (current?.x ?? 0) + (delta.x ?? 0),
4669
+ y: (current?.y ?? 0) + (delta.y ?? 0),
4670
+ scale: (current?.scale ?? 0) + (delta.scale ?? 0),
4671
+ isActive: true,
4672
+ preview: options?.preview ?? current?.preview
4673
+ }
4674
+ };
4675
+ this.render();
4676
+ return true;
4677
+ }
4596
4678
  getMode() {
4597
4679
  return this.mode;
4598
4680
  }
@@ -4672,6 +4754,33 @@ var WebReviewKitApp = class {
4672
4754
  this.render();
4673
4755
  return true;
4674
4756
  }
4757
+ syncDomDraftViewportGeometry() {
4758
+ const draft = this.domDraft;
4759
+ const element = draft?.previewElement;
4760
+ const environment = this.getEnvironment();
4761
+ if (!draft?.selection || !element?.isConnected || !environment || element.ownerDocument !== environment.document) {
4762
+ return;
4763
+ }
4764
+ const rect = element.getBoundingClientRect();
4765
+ if (rect.width <= 0 || rect.height <= 0) return;
4766
+ const selection = {
4767
+ left: rect.left,
4768
+ top: rect.top,
4769
+ width: rect.width,
4770
+ height: rect.height
4771
+ };
4772
+ this.domDraft = {
4773
+ ...draft,
4774
+ marker: {
4775
+ ...draft.marker,
4776
+ viewport: roundPoint({ x: rect.left, y: rect.top })
4777
+ },
4778
+ selection: {
4779
+ ...draft.selection,
4780
+ viewport: toPublicSelection(selection)
4781
+ }
4782
+ };
4783
+ }
4675
4784
  isDraftComposerFocused() {
4676
4785
  if (!this.domDraft && !this.areaDraft) return false;
4677
4786
  const composerHost = this.getEnvironment()?.composerHost;
@@ -5143,6 +5252,11 @@ function createNoopController() {
5143
5252
  },
5144
5253
  async startElementReview() {
5145
5254
  },
5255
+ async selectElement() {
5256
+ },
5257
+ adjustElementSelection() {
5258
+ return false;
5259
+ },
5146
5260
  getMode() {
5147
5261
  return "idle";
5148
5262
  },
@@ -5181,7 +5295,8 @@ export {
5181
5295
  getItemHighlightSelection,
5182
5296
  shouldShowMarkerForScope,
5183
5297
  runWithAutoScrollBehavior,
5298
+ getDraftViewportScale,
5184
5299
  reviewTypographyTokens,
5185
5300
  createWebReviewKit
5186
5301
  };
5187
- //# sourceMappingURL=chunk-4ZP7B7R6.js.map
5302
+ //# sourceMappingURL=chunk-ZWJNUOYV.js.map