@designfever/web-review-kit 0.4.1 → 0.5.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/index.cjs CHANGED
@@ -558,6 +558,20 @@ function getDomAnchorFromPoint(point, configuredAttribute = "data-qa-id", enviro
558
558
  source: getDomSourceHint(target)
559
559
  };
560
560
  }
561
+ function getDomAnchorFromElement(target, configuredAttribute = "data-qa-id", environment) {
562
+ if (target.ownerDocument !== environment.document) return void 0;
563
+ const candidates = createAnchorCandidates(target, configuredAttribute);
564
+ const primary = candidates[0];
565
+ if (!primary) return void 0;
566
+ return {
567
+ ...primary,
568
+ candidates,
569
+ htmlSnippet: getElementHtmlSnippet(
570
+ getAnchorSourceElement(target, primary, configuredAttribute) ?? target
571
+ ),
572
+ source: getDomSourceHint(target)
573
+ };
574
+ }
561
575
  function getElementViewportSelection(anchor, environment, preferredSelection) {
562
576
  const element = getAnchorElement(anchor, environment, preferredSelection);
563
577
  if (!element) return void 0;
@@ -2090,6 +2104,12 @@ function createStyleElement() {
2090
2104
  outline-offset: 1px;
2091
2105
  }
2092
2106
 
2107
+ @media (hover: none) and (pointer: coarse) {
2108
+ .dfwr-textarea {
2109
+ font-size: 16px;
2110
+ }
2111
+ }
2112
+
2093
2113
  .dfwr-adjust-panel {
2094
2114
  display: grid;
2095
2115
  gap: 4px;
@@ -3796,6 +3816,7 @@ function createWebReviewKit(options) {
3796
3816
  close: () => app.close(),
3797
3817
  toggle: () => app.toggle(),
3798
3818
  setMode: (mode) => app.setMode(mode),
3819
+ startElementReview: (element, comment) => app.startElementReview(element, comment),
3799
3820
  getMode: () => app.getMode(),
3800
3821
  highlightItem: (itemId) => app.highlightItem(itemId),
3801
3822
  setHiddenItemIds: (itemIds) => app.setHiddenItemIds(itemIds),
@@ -3926,6 +3947,16 @@ var WebReviewKitApp = class {
3926
3947
  this.areaDraft = void 0;
3927
3948
  this.render();
3928
3949
  }
3950
+ async startElementReview(element, comment) {
3951
+ if (!this.isOpen) {
3952
+ this.isOpen = true;
3953
+ }
3954
+ this.setModeState("element");
3955
+ this.noteDraft = void 0;
3956
+ this.areaDraft = void 0;
3957
+ this.isSelectingArea = false;
3958
+ await this.bindElementDraftToElement(element, comment);
3959
+ }
3929
3960
  getMode() {
3930
3961
  return this.mode;
3931
3962
  }
@@ -4134,6 +4165,47 @@ var WebReviewKitApp = class {
4134
4165
  this.noteDraft = draft;
4135
4166
  this.render();
4136
4167
  }
4168
+ async bindElementDraftToElement(element, comment) {
4169
+ const environment = this.getEnvironment();
4170
+ if (!environment || element.ownerDocument !== environment.document) return;
4171
+ const viewport = getViewportSize(environment);
4172
+ const draft = await this.withOverlayHidden(() => {
4173
+ const rect = element.getBoundingClientRect();
4174
+ if (rect.width <= 0 || rect.height <= 0) return void 0;
4175
+ const selection = {
4176
+ left: rect.left,
4177
+ top: rect.top,
4178
+ width: rect.width,
4179
+ height: rect.height
4180
+ };
4181
+ const anchor = getDomAnchorFromElement(
4182
+ element,
4183
+ this.options.anchors?.attribute,
4184
+ environment
4185
+ );
4186
+ const markerPoint = { x: selection.left, y: selection.top };
4187
+ const marker = {
4188
+ viewport: roundPoint(markerPoint),
4189
+ relative: anchor ? getRelativePoint(markerPoint, anchor, environment) : void 0
4190
+ };
4191
+ const reviewSelection = {
4192
+ viewport: toPublicSelection(selection),
4193
+ relative: anchor ? getRelativeSelection(selection, anchor, environment) : void 0
4194
+ };
4195
+ const previewElement = "style" in element ? element : void 0;
4196
+ return {
4197
+ viewport,
4198
+ anchor,
4199
+ marker,
4200
+ selection: reviewSelection,
4201
+ comment,
4202
+ previewElement
4203
+ };
4204
+ });
4205
+ if (!draft) return;
4206
+ this.noteDraft = draft;
4207
+ this.render();
4208
+ }
4137
4209
  async createAreaDraft(selection) {
4138
4210
  const environment = this.getEnvironment();
4139
4211
  if (!environment) return;
@@ -4238,6 +4310,8 @@ function createNoopController() {
4238
4310
  },
4239
4311
  setMode() {
4240
4312
  },
4313
+ async startElementReview() {
4314
+ },
4241
4315
  getMode() {
4242
4316
  return "idle";
4243
4317
  },