sketchmark 1.3.1 → 1.3.4

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.js CHANGED
@@ -12667,7 +12667,6 @@ const EMBED_CSS = `
12667
12667
  top: 0;
12668
12668
  left: 0;
12669
12669
  transform-origin: 0 0;
12670
- will-change: transform;
12671
12670
  }
12672
12671
 
12673
12672
  .skm-embed__error {
@@ -12788,7 +12787,6 @@ class SketchmarkEmbed {
12788
12787
  this.offsetX = 0;
12789
12788
  this.offsetY = 0;
12790
12789
  this.autoFitEnabled = true;
12791
- this.autoFocusEnabled = true;
12792
12790
  this.motionFrame = null;
12793
12791
  this.resizeObserver = null;
12794
12792
  this.isPanning = false;
@@ -12826,7 +12824,6 @@ class SketchmarkEmbed {
12826
12824
  if (this.panMoved) {
12827
12825
  this.stopMotion();
12828
12826
  this.autoFitEnabled = false;
12829
- this.autoFocusEnabled = false;
12830
12827
  this.offsetX += dx;
12831
12828
  this.offsetY += dy;
12832
12829
  this.applyTransform();
@@ -12994,7 +12991,6 @@ class SketchmarkEmbed {
12994
12991
  this.instance?.anim?.destroy();
12995
12992
  this.instance = null;
12996
12993
  this.autoFitEnabled = true;
12997
- this.autoFocusEnabled = true;
12998
12994
  this.zoom = 1;
12999
12995
  this.offsetX = 0;
13000
12996
  this.offsetY = 0;
@@ -13021,9 +13017,9 @@ class SketchmarkEmbed {
13021
13017
  this.animUnsub = instance.anim.on((event) => {
13022
13018
  this.syncControls();
13023
13019
  if (event.type === "step-change") {
13024
- if (this.options.autoFocusOnStep !== false) {
13020
+ if (this.options.autoFocus !== false && this.options.autoFocusOnStep !== false) {
13025
13021
  requestAnimationFrame(() => {
13026
- window.setTimeout(() => this.positionViewport(true), 40);
13022
+ window.setTimeout(() => this.focusCurrentStep(true), 40);
13027
13023
  });
13028
13024
  }
13029
13025
  this.emitter.emit("stepchange", {
@@ -13067,27 +13063,29 @@ class SketchmarkEmbed {
13067
13063
  return;
13068
13064
  this.instance.anim.next();
13069
13065
  this.syncControls();
13070
- this.positionViewport(true);
13066
+ if (this.options.autoFocus !== false && this.options.autoFocusOnStep !== false) {
13067
+ this.focusCurrentStep(true);
13068
+ }
13071
13069
  }
13072
13070
  prevStep() {
13073
13071
  if (!this.instance)
13074
13072
  return;
13075
13073
  this.instance.anim.prev();
13076
13074
  this.syncControls();
13077
- this.positionViewport(true);
13075
+ if (this.options.autoFocus !== false && this.options.autoFocusOnStep !== false) {
13076
+ this.focusCurrentStep(true);
13077
+ }
13078
13078
  }
13079
13079
  resetAnimation() {
13080
13080
  if (!this.instance)
13081
13081
  return;
13082
13082
  this.instance.anim.reset();
13083
13083
  this.syncControls();
13084
- this.positionViewport(true);
13085
13084
  }
13086
13085
  fitToViewport(animated = false) {
13087
13086
  if (!this.instance?.svg)
13088
13087
  return;
13089
13088
  this.autoFitEnabled = true;
13090
- this.autoFocusEnabled = true;
13091
13089
  this.positionViewport(animated);
13092
13090
  }
13093
13091
  resetView(animated = false) {
@@ -13177,10 +13175,13 @@ class SketchmarkEmbed {
13177
13175
  const focusTarget = this.getFocusTarget();
13178
13176
  const sceneIsLarge = scaledWidth > viewWidth || scaledHeight > viewHeight;
13179
13177
  const shouldFocus = sceneIsLarge &&
13180
- this.autoFocusEnabled &&
13181
13178
  this.options.autoFocus !== false &&
13182
13179
  !!focusTarget;
13183
13180
  if (!shouldFocus) {
13181
+ if (!this.autoFitEnabled) {
13182
+ this.applyTransform();
13183
+ return;
13184
+ }
13184
13185
  this.animateTo(scaledWidth <= viewWidth ? (viewWidth - scaledWidth) / 2 : 0, scaledHeight <= viewHeight ? (viewHeight - scaledHeight) / 2 : 0, animated);
13185
13186
  return;
13186
13187
  }
@@ -13287,13 +13288,62 @@ class SketchmarkEmbed {
13287
13288
  }
13288
13289
  this.stopMotion();
13289
13290
  this.autoFitEnabled = false;
13290
- this.autoFocusEnabled = false;
13291
13291
  this.offsetX = pivotX - (pivotX - this.offsetX) * ratio;
13292
13292
  this.offsetY = pivotY - (pivotY - this.offsetY) * ratio;
13293
13293
  this.zoom = clampedZoom;
13294
13294
  this.applyTransform();
13295
13295
  this.syncViewControls();
13296
13296
  }
13297
+ focusCurrentStep(animated) {
13298
+ const anim = this.instance?.anim;
13299
+ if (!anim || anim.currentStep < 0 || anim.currentStep >= anim.total)
13300
+ return;
13301
+ const targetId = this.getStepTarget(anim.steps[anim.currentStep]);
13302
+ if (targetId)
13303
+ this.focusTarget(targetId, animated);
13304
+ }
13305
+ focusTarget(targetId, animated) {
13306
+ const size = this.getContentSize();
13307
+ if (!size)
13308
+ return;
13309
+ const viewportRect = this.viewport.getBoundingClientRect();
13310
+ const viewWidth = viewportRect.width || this.viewport.clientWidth;
13311
+ const viewHeight = viewportRect.height || this.viewport.clientHeight;
13312
+ if (!viewWidth || !viewHeight)
13313
+ return;
13314
+ const target = this.findTargetElement(targetId);
13315
+ if (!target)
13316
+ return;
13317
+ const targetBox = this.getTargetBox(target, viewportRect);
13318
+ if (!targetBox)
13319
+ return;
13320
+ const centerX = this.offsetX + targetBox.centerX;
13321
+ const centerY = this.offsetY + targetBox.centerY;
13322
+ const padding = this.options.focusPadding ?? 24;
13323
+ if (centerX >= padding &&
13324
+ centerX <= viewWidth - padding &&
13325
+ centerY >= padding &&
13326
+ centerY <= viewHeight - padding) {
13327
+ return;
13328
+ }
13329
+ const scaledWidth = size.width * this.zoom;
13330
+ const scaledHeight = size.height * this.zoom;
13331
+ let nextX = viewWidth / 2 - targetBox.centerX;
13332
+ let nextY = viewHeight / 2 - targetBox.centerY;
13333
+ if (scaledWidth <= viewWidth) {
13334
+ nextX = (viewWidth - scaledWidth) / 2;
13335
+ }
13336
+ else {
13337
+ nextX = clamp(nextX, viewWidth - scaledWidth - padding, padding);
13338
+ }
13339
+ if (scaledHeight <= viewHeight) {
13340
+ nextY = (viewHeight - scaledHeight) / 2;
13341
+ }
13342
+ else {
13343
+ nextY = clamp(nextY, viewHeight - scaledHeight - padding, padding);
13344
+ }
13345
+ this.animateTo(nextX, nextY, animated);
13346
+ }
13297
13347
  applyCaptionVisibility(instance) {
13298
13348
  const caption = instance?.anim.captionElement;
13299
13349
  if (!caption)