sketchmark 1.3.1 → 1.3.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.
- package/dist/index.cjs +62 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +62 -11
- package/dist/index.js.map +1 -1
- package/dist/sketchmark.iife.js +62 -11
- package/dist/ui/embed.d.ts +2 -1
- package/dist/ui/embed.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -12790,7 +12790,6 @@ class SketchmarkEmbed {
|
|
|
12790
12790
|
this.offsetX = 0;
|
|
12791
12791
|
this.offsetY = 0;
|
|
12792
12792
|
this.autoFitEnabled = true;
|
|
12793
|
-
this.autoFocusEnabled = true;
|
|
12794
12793
|
this.motionFrame = null;
|
|
12795
12794
|
this.resizeObserver = null;
|
|
12796
12795
|
this.isPanning = false;
|
|
@@ -12828,7 +12827,6 @@ class SketchmarkEmbed {
|
|
|
12828
12827
|
if (this.panMoved) {
|
|
12829
12828
|
this.stopMotion();
|
|
12830
12829
|
this.autoFitEnabled = false;
|
|
12831
|
-
this.autoFocusEnabled = false;
|
|
12832
12830
|
this.offsetX += dx;
|
|
12833
12831
|
this.offsetY += dy;
|
|
12834
12832
|
this.applyTransform();
|
|
@@ -12996,7 +12994,6 @@ class SketchmarkEmbed {
|
|
|
12996
12994
|
this.instance?.anim?.destroy();
|
|
12997
12995
|
this.instance = null;
|
|
12998
12996
|
this.autoFitEnabled = true;
|
|
12999
|
-
this.autoFocusEnabled = true;
|
|
13000
12997
|
this.zoom = 1;
|
|
13001
12998
|
this.offsetX = 0;
|
|
13002
12999
|
this.offsetY = 0;
|
|
@@ -13023,9 +13020,9 @@ class SketchmarkEmbed {
|
|
|
13023
13020
|
this.animUnsub = instance.anim.on((event) => {
|
|
13024
13021
|
this.syncControls();
|
|
13025
13022
|
if (event.type === "step-change") {
|
|
13026
|
-
if (this.options.autoFocusOnStep !== false) {
|
|
13023
|
+
if (this.options.autoFocus !== false && this.options.autoFocusOnStep !== false) {
|
|
13027
13024
|
requestAnimationFrame(() => {
|
|
13028
|
-
window.setTimeout(() => this.
|
|
13025
|
+
window.setTimeout(() => this.focusCurrentStep(true), 40);
|
|
13029
13026
|
});
|
|
13030
13027
|
}
|
|
13031
13028
|
this.emitter.emit("stepchange", {
|
|
@@ -13069,27 +13066,29 @@ class SketchmarkEmbed {
|
|
|
13069
13066
|
return;
|
|
13070
13067
|
this.instance.anim.next();
|
|
13071
13068
|
this.syncControls();
|
|
13072
|
-
this.
|
|
13069
|
+
if (this.options.autoFocus !== false && this.options.autoFocusOnStep !== false) {
|
|
13070
|
+
this.focusCurrentStep(true);
|
|
13071
|
+
}
|
|
13073
13072
|
}
|
|
13074
13073
|
prevStep() {
|
|
13075
13074
|
if (!this.instance)
|
|
13076
13075
|
return;
|
|
13077
13076
|
this.instance.anim.prev();
|
|
13078
13077
|
this.syncControls();
|
|
13079
|
-
this.
|
|
13078
|
+
if (this.options.autoFocus !== false && this.options.autoFocusOnStep !== false) {
|
|
13079
|
+
this.focusCurrentStep(true);
|
|
13080
|
+
}
|
|
13080
13081
|
}
|
|
13081
13082
|
resetAnimation() {
|
|
13082
13083
|
if (!this.instance)
|
|
13083
13084
|
return;
|
|
13084
13085
|
this.instance.anim.reset();
|
|
13085
13086
|
this.syncControls();
|
|
13086
|
-
this.positionViewport(true);
|
|
13087
13087
|
}
|
|
13088
13088
|
fitToViewport(animated = false) {
|
|
13089
13089
|
if (!this.instance?.svg)
|
|
13090
13090
|
return;
|
|
13091
13091
|
this.autoFitEnabled = true;
|
|
13092
|
-
this.autoFocusEnabled = true;
|
|
13093
13092
|
this.positionViewport(animated);
|
|
13094
13093
|
}
|
|
13095
13094
|
resetView(animated = false) {
|
|
@@ -13179,10 +13178,13 @@ class SketchmarkEmbed {
|
|
|
13179
13178
|
const focusTarget = this.getFocusTarget();
|
|
13180
13179
|
const sceneIsLarge = scaledWidth > viewWidth || scaledHeight > viewHeight;
|
|
13181
13180
|
const shouldFocus = sceneIsLarge &&
|
|
13182
|
-
this.autoFocusEnabled &&
|
|
13183
13181
|
this.options.autoFocus !== false &&
|
|
13184
13182
|
!!focusTarget;
|
|
13185
13183
|
if (!shouldFocus) {
|
|
13184
|
+
if (!this.autoFitEnabled) {
|
|
13185
|
+
this.applyTransform();
|
|
13186
|
+
return;
|
|
13187
|
+
}
|
|
13186
13188
|
this.animateTo(scaledWidth <= viewWidth ? (viewWidth - scaledWidth) / 2 : 0, scaledHeight <= viewHeight ? (viewHeight - scaledHeight) / 2 : 0, animated);
|
|
13187
13189
|
return;
|
|
13188
13190
|
}
|
|
@@ -13289,13 +13291,62 @@ class SketchmarkEmbed {
|
|
|
13289
13291
|
}
|
|
13290
13292
|
this.stopMotion();
|
|
13291
13293
|
this.autoFitEnabled = false;
|
|
13292
|
-
this.autoFocusEnabled = false;
|
|
13293
13294
|
this.offsetX = pivotX - (pivotX - this.offsetX) * ratio;
|
|
13294
13295
|
this.offsetY = pivotY - (pivotY - this.offsetY) * ratio;
|
|
13295
13296
|
this.zoom = clampedZoom;
|
|
13296
13297
|
this.applyTransform();
|
|
13297
13298
|
this.syncViewControls();
|
|
13298
13299
|
}
|
|
13300
|
+
focusCurrentStep(animated) {
|
|
13301
|
+
const anim = this.instance?.anim;
|
|
13302
|
+
if (!anim || anim.currentStep < 0 || anim.currentStep >= anim.total)
|
|
13303
|
+
return;
|
|
13304
|
+
const targetId = this.getStepTarget(anim.steps[anim.currentStep]);
|
|
13305
|
+
if (targetId)
|
|
13306
|
+
this.focusTarget(targetId, animated);
|
|
13307
|
+
}
|
|
13308
|
+
focusTarget(targetId, animated) {
|
|
13309
|
+
const size = this.getContentSize();
|
|
13310
|
+
if (!size)
|
|
13311
|
+
return;
|
|
13312
|
+
const viewportRect = this.viewport.getBoundingClientRect();
|
|
13313
|
+
const viewWidth = viewportRect.width || this.viewport.clientWidth;
|
|
13314
|
+
const viewHeight = viewportRect.height || this.viewport.clientHeight;
|
|
13315
|
+
if (!viewWidth || !viewHeight)
|
|
13316
|
+
return;
|
|
13317
|
+
const target = this.findTargetElement(targetId);
|
|
13318
|
+
if (!target)
|
|
13319
|
+
return;
|
|
13320
|
+
const targetBox = this.getTargetBox(target, viewportRect);
|
|
13321
|
+
if (!targetBox)
|
|
13322
|
+
return;
|
|
13323
|
+
const centerX = this.offsetX + targetBox.centerX;
|
|
13324
|
+
const centerY = this.offsetY + targetBox.centerY;
|
|
13325
|
+
const padding = this.options.focusPadding ?? 24;
|
|
13326
|
+
if (centerX >= padding &&
|
|
13327
|
+
centerX <= viewWidth - padding &&
|
|
13328
|
+
centerY >= padding &&
|
|
13329
|
+
centerY <= viewHeight - padding) {
|
|
13330
|
+
return;
|
|
13331
|
+
}
|
|
13332
|
+
const scaledWidth = size.width * this.zoom;
|
|
13333
|
+
const scaledHeight = size.height * this.zoom;
|
|
13334
|
+
let nextX = viewWidth / 2 - targetBox.centerX;
|
|
13335
|
+
let nextY = viewHeight / 2 - targetBox.centerY;
|
|
13336
|
+
if (scaledWidth <= viewWidth) {
|
|
13337
|
+
nextX = (viewWidth - scaledWidth) / 2;
|
|
13338
|
+
}
|
|
13339
|
+
else {
|
|
13340
|
+
nextX = clamp(nextX, viewWidth - scaledWidth - padding, padding);
|
|
13341
|
+
}
|
|
13342
|
+
if (scaledHeight <= viewHeight) {
|
|
13343
|
+
nextY = (viewHeight - scaledHeight) / 2;
|
|
13344
|
+
}
|
|
13345
|
+
else {
|
|
13346
|
+
nextY = clamp(nextY, viewHeight - scaledHeight - padding, padding);
|
|
13347
|
+
}
|
|
13348
|
+
this.animateTo(nextX, nextY, animated);
|
|
13349
|
+
}
|
|
13299
13350
|
applyCaptionVisibility(instance) {
|
|
13300
13351
|
const caption = instance?.anim.captionElement;
|
|
13301
13352
|
if (!caption)
|