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