text-guitar-chart 0.1.0 → 0.1.1

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/docs/bundle.js CHANGED
@@ -8035,56 +8035,77 @@ var EditableSVGuitarChord = class {
8035
8035
  this.positionOpenStringDialog();
8036
8036
  }
8037
8037
  /**
8038
- * Position dialog relative to the clicked element
8038
+ * Calculate absolute position for a dialog relative to a reference element
8039
+ * @param {HTMLElement} dialog - The dialog element to position
8040
+ * @param {Element} referenceElement - The element to position relative to
8041
+ * @param {object} options - Positioning options
8042
+ * @param {'beside'|'below'} [options.placement] - Whether to place beside or below the reference
8043
+ * @param {number} [options.offset] - Distance from reference element
8044
+ * @returns {{x: number, y: number, arrowSide: string, elementCenterY: number}}
8039
8045
  */
8040
- positionDialog() {
8041
- if (!this.currentEditElement || !this.dialog) return;
8042
- const elementRect = this.currentEditElement.getBoundingClientRect();
8043
- const dialogRect = this.dialog.getBoundingClientRect();
8046
+ calculateDialogPosition(dialog, referenceElement, options = {}) {
8047
+ const { placement = "beside", offset = 20 } = options;
8048
+ const elementRect = referenceElement.getBoundingClientRect();
8049
+ const dialogRect = dialog.getBoundingClientRect();
8044
8050
  const elementCenterX = elementRect.left + elementRect.width / 2;
8045
8051
  const elementCenterY = elementRect.top + elementRect.height / 2;
8046
- let dialogX = elementCenterX + 20;
8047
- let dialogY = elementCenterY - dialogRect.height / 2;
8052
+ let dialogX, dialogY;
8053
+ let arrowSide = "left";
8048
8054
  const padding = 10;
8049
8055
  const maxX = window.innerWidth - dialogRect.width - padding;
8050
8056
  const maxY = window.innerHeight - dialogRect.height - padding;
8051
- let arrowSide = "left";
8052
- if (dialogX > maxX) {
8053
- dialogX = elementCenterX - dialogRect.width - 20;
8054
- arrowSide = "right";
8057
+ if (placement === "beside") {
8058
+ dialogX = elementCenterX + offset;
8059
+ dialogY = elementCenterY - dialogRect.height / 2;
8060
+ if (dialogX > maxX) {
8061
+ dialogX = elementCenterX - dialogRect.width - offset;
8062
+ arrowSide = "right";
8063
+ }
8064
+ } else if (placement === "below") {
8065
+ dialogX = elementRect.left;
8066
+ dialogY = elementRect.bottom + offset;
8067
+ if (dialogY > maxY) {
8068
+ dialogY = elementRect.top - dialogRect.height - offset;
8069
+ }
8055
8070
  }
8056
8071
  if (dialogX < padding) dialogX = padding;
8072
+ if (dialogX > maxX) dialogX = maxX;
8057
8073
  if (dialogY < padding) dialogY = padding;
8058
8074
  if (dialogY > maxY) dialogY = maxY;
8059
- this.dialog.style.left = `${dialogX}px`;
8060
- this.dialog.style.top = `${dialogY}px`;
8061
- this.addArrowCSS(arrowSide, elementCenterY, dialogY, dialogRect.height);
8075
+ return {
8076
+ x: dialogX + window.scrollX,
8077
+ y: dialogY + window.scrollY,
8078
+ arrowSide,
8079
+ elementCenterY
8080
+ };
8081
+ }
8082
+ /**
8083
+ * Position dialog relative to the clicked element
8084
+ */
8085
+ positionDialog() {
8086
+ if (!this.currentEditElement || !this.dialog) return;
8087
+ const position2 = this.calculateDialogPosition(this.dialog, this.currentEditElement, {
8088
+ placement: "beside",
8089
+ offset: 20
8090
+ });
8091
+ this.dialog.style.left = `${position2.x}px`;
8092
+ this.dialog.style.top = `${position2.y}px`;
8093
+ const dialogRect = this.dialog.getBoundingClientRect();
8094
+ this.addArrowCSS(position2.arrowSide, position2.elementCenterY, position2.y - window.scrollY, dialogRect.height);
8062
8095
  }
8063
8096
  /**
8064
8097
  * Position the open string dialog
8065
8098
  */
8066
8099
  positionOpenStringDialog() {
8067
8100
  if (!this.currentEditElement || !this.openStringDialog) return;
8068
- const elementRect = this.currentEditElement.getBoundingClientRect();
8101
+ const position2 = this.calculateDialogPosition(this.openStringDialog, this.currentEditElement, {
8102
+ placement: "beside",
8103
+ offset: 20
8104
+ });
8105
+ this.openStringDialog.style.left = `${position2.x}px`;
8106
+ this.openStringDialog.style.top = `${position2.y}px`;
8069
8107
  const dialogRect = this.openStringDialog.getBoundingClientRect();
8070
- const elementCenterX = elementRect.left + elementRect.width / 2;
8071
- const elementCenterY = elementRect.top + elementRect.height / 2;
8072
- let dialogX = elementCenterX + 20;
8073
- let dialogY = elementCenterY - dialogRect.height / 2;
8074
- const padding = 10;
8075
- const maxX = window.innerWidth - dialogRect.width - padding;
8076
- const maxY = window.innerHeight - dialogRect.height - padding;
8077
- let arrowSide = "left";
8078
- if (dialogX > maxX) {
8079
- dialogX = elementCenterX - dialogRect.width - 20;
8080
- arrowSide = "right";
8081
- }
8082
- if (dialogX < padding) dialogX = padding;
8083
- if (dialogY < padding) dialogY = padding;
8084
- if (dialogY > maxY) dialogY = maxY;
8085
- this.openStringDialog.style.left = `${dialogX}px`;
8086
- this.openStringDialog.style.top = `${dialogY}px`;
8087
- this.addOpenStringArrowCSS(arrowSide, elementCenterY, dialogY, dialogRect.height);
8108
+ this.addOpenStringArrowCSS(position2.arrowSide, position2.elementCenterY, position2.y - window.scrollY, dialogRect.height);
8088
8109
  }
8089
8110
  /**
8090
8111
  * Add CSS arrow using ::after pseudo-element
@@ -8357,19 +8378,12 @@ var EditableSVGuitarChord = class {
8357
8378
  */
8358
8379
  positionSettingsDialog() {
8359
8380
  if (!this.settingsButton || !this.settingsDialog) return;
8360
- const buttonRect = this.settingsButton.getBoundingClientRect();
8361
- const dialogRect = this.settingsDialog.getBoundingClientRect();
8362
- let dialogX = buttonRect.left;
8363
- let dialogY = buttonRect.bottom + 5;
8364
- const padding = 10;
8365
- const maxX = window.innerWidth - dialogRect.width - padding;
8366
- const maxY = window.innerHeight - dialogRect.height - padding;
8367
- if (dialogX > maxX) dialogX = maxX;
8368
- if (dialogX < padding) dialogX = padding;
8369
- if (dialogY > maxY) dialogY = buttonRect.top - dialogRect.height - 5;
8370
- if (dialogY < padding) dialogY = padding;
8371
- this.settingsDialog.style.left = `${dialogX}px`;
8372
- this.settingsDialog.style.top = `${dialogY}px`;
8381
+ const position2 = this.calculateDialogPosition(this.settingsDialog, this.settingsButton, {
8382
+ placement: "below",
8383
+ offset: 5
8384
+ });
8385
+ this.settingsDialog.style.left = `${position2.x}px`;
8386
+ this.settingsDialog.style.top = `${position2.y}px`;
8373
8387
  }
8374
8388
  /**
8375
8389
  * Close the settings dialog