@dioramajs/core 0.1.1 → 0.1.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.d.ts +23 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +106 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/web/follow.ts +109 -17
- package/src/web/stage.ts +43 -11
package/dist/index.d.ts
CHANGED
|
@@ -133,6 +133,8 @@ interface ScrollApi {
|
|
|
133
133
|
}
|
|
134
134
|
/** Tracks page scroll, its velocity and progress. Built in. */
|
|
135
135
|
export declare const scroll: Plugin<"scroll">;
|
|
136
|
+
/** A span of page scroll, px from the top, over which content on screen stands still. */
|
|
137
|
+
type ScrollSpan = readonly [start: number, end: number];
|
|
136
138
|
/** Options of the `stage` plugin. */
|
|
137
139
|
interface StageOptions {
|
|
138
140
|
/**
|
|
@@ -148,9 +150,9 @@ interface StageOptions {
|
|
|
148
150
|
* Keeps GL copies on their elements while the browser scrolls the page ahead of the next frame
|
|
149
151
|
* (keyboard, scrollbar, native wheel, touch). The created canvas moves with the page on the
|
|
150
152
|
* compositor until the frame lands, and GL content fixed to the viewport moves with it for that
|
|
151
|
-
* time.
|
|
152
|
-
*
|
|
153
|
-
* scroll-driven animations. Default true.
|
|
153
|
+
* time. Inside `stage.pin` spans (effects: a pinned sticky stage of a scroll section) and while
|
|
154
|
+
* a `stage.hold` predicate is true the canvas stays fixed to the viewport instead. Vertical page
|
|
155
|
+
* scroll only. Needs CSS scroll-driven animations. Default true.
|
|
154
156
|
*/
|
|
155
157
|
readonly followScroll: boolean;
|
|
156
158
|
}
|
|
@@ -158,9 +160,13 @@ interface StageOptions {
|
|
|
158
160
|
interface StageApi {
|
|
159
161
|
/** The page-wide canvas, created on first access. `undefined` without a DOM. */
|
|
160
162
|
readonly canvas: HTMLCanvasElement | undefined;
|
|
161
|
-
/** Viewport
|
|
163
|
+
/** Viewport width in CSS px, excluding scrollbars. */
|
|
162
164
|
readonly width: ReadonlySignal<number>;
|
|
163
|
-
/**
|
|
165
|
+
/**
|
|
166
|
+
* Viewport height in CSS px: the large viewport of CSS `100lvh` (`100vh`), so on phones the
|
|
167
|
+
* height with the browser toolbar hidden. It stays put while the toolbar slides, and the
|
|
168
|
+
* created canvas is that tall.
|
|
169
|
+
*/
|
|
164
170
|
readonly height: ReadonlySignal<number>;
|
|
165
171
|
/** Device pixel ratio, capped by `maxPixelRatio`. */
|
|
166
172
|
readonly pixelRatio: ReadonlySignal<number>;
|
|
@@ -168,11 +174,19 @@ interface StageApi {
|
|
|
168
174
|
readonly reducedMotion: ReadonlySignal<boolean>;
|
|
169
175
|
/**
|
|
170
176
|
* Keeps the created canvas from following scroll (`followScroll`) while `held()` is true:
|
|
171
|
-
* for content
|
|
172
|
-
*
|
|
173
|
-
*
|
|
177
|
+
* for content fixed to the viewport. Read once per frame after the frame is drawn; the switch
|
|
178
|
+
* lands with that frame. Returns a function that removes the predicate. Without following it
|
|
179
|
+
* does nothing.
|
|
174
180
|
*/
|
|
175
181
|
hold(held: () => boolean): Off;
|
|
182
|
+
/**
|
|
183
|
+
* Scroll spans, in page px from the top, over which content on screen stands still, such as a
|
|
184
|
+
* pinned sticky stage from where it sticks to where it lets go. The created canvas stops
|
|
185
|
+
* following inside them on the compositor, so it stops and starts where CSS sticky does, also
|
|
186
|
+
* between frames. Read once per frame after the frame is drawn. Returns a function that
|
|
187
|
+
* removes the source. Without following it does nothing.
|
|
188
|
+
*/
|
|
189
|
+
pin(spans: () => readonly ScrollSpan[]): Off;
|
|
176
190
|
}
|
|
177
191
|
/** One canvas for the whole site. It outlives page transitions. */
|
|
178
192
|
export declare const stage: Plugin<"stage", StageOptions>;
|
|
@@ -910,5 +924,5 @@ export declare const VERSION: string;
|
|
|
910
924
|
* run it.
|
|
911
925
|
*/
|
|
912
926
|
export declare function createApp<const P extends readonly PresetEntry[] = [], const E extends readonly PluginEntry[] = []>(options?: AppOptions<P, E>): App<ServicesOf<PresetPlugins<P[number]> | Extract<E[number], AnyPlugin>>>;
|
|
913
|
-
export type { Anchor, AnchorsApi, PointerApi, PointerState, ScrollApi, ScrollAxis, ScrollSample, ScrollSource, ScrollState, StageApi, StageOptions, TrackOptions, VisibilityApi, VisibilityOptions };
|
|
927
|
+
export type { Anchor, AnchorsApi, PointerApi, PointerState, ScrollApi, ScrollAxis, ScrollSample, ScrollSource, ScrollSpan, ScrollState, StageApi, StageOptions, TrackOptions, VisibilityApi, VisibilityOptions };
|
|
914
928
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/web/anchors.ts","../src/web/pointer.ts","../src/web/scroll.ts","../src/web/stage.ts","../src/web/visibility.ts","../src/kernel/errors.ts","../src/kernel/plugin.ts","../src/kernel/config.ts","../src/kernel/types.ts","../src/kernel/drivers.ts","../src/kernel/hooks.ts","../src/kernel/semver.ts","../src/kernel/signals.ts","../src/version.ts","../src/index.ts"],"mappings":";UAMiB;;WAEN,SAAS;;WAET;;WAEA;;WAEA;;WAEA;;WAEA;;;;;WAKA;;;;;;WAMA;;WAEA;;EAET;;;UAIe;;;;;WAKN;;;UAIM;;EAEf,MAAM,SAAS,SAAS,UAAU,eAAe;;EAEjD;;;;;;;;qBA8DW,SAAS;;;;;UCxGL;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN,OAAO;;;qBAIL,SAAS;;KC3BV;;UAGK;;WAEN;;WAEA;;;;;WAKA;;WAEA;;WAEA;;WAEA,MAAM;;;UAIA;;EAEf;;EAEA;;EAEA;;;UAIe;;WAEN;;WAEA,OAAO;;EAEhB,KAAK,KAAK;;EAEV;;;UAIe;;WAEN,OAAO;;EAEhB;;;;;EAKA,OAAO,QAAQ,eAAe;;;qBAOnB,QAAQ;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/web/anchors.ts","../src/web/pointer.ts","../src/web/scroll.ts","../src/web/follow.ts","../src/web/stage.ts","../src/web/visibility.ts","../src/kernel/errors.ts","../src/kernel/plugin.ts","../src/kernel/config.ts","../src/kernel/types.ts","../src/kernel/drivers.ts","../src/kernel/hooks.ts","../src/kernel/semver.ts","../src/kernel/signals.ts","../src/version.ts","../src/index.ts"],"mappings":";UAMiB;;WAEN,SAAS;;WAET;;WAEA;;WAEA;;WAEA;;WAEA;;;;;WAKA;;;;;;WAMA;;WAEA;;EAET;;;UAIe;;;;;WAKN;;;UAIM;;EAEf,MAAM,SAAS,SAAS,UAAU,eAAe;;EAEjD;;;;;;;;qBA8DW,SAAS;;;;;UCxGL;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN,OAAO;;;qBAIL,SAAS;;KC3BV;;UAGK;;WAEN;;WAEA;;;;;WAKA;;WAEA;;WAEA;;WAEA,MAAM;;;UAIA;;EAEf;;EAEA;;EAEA;;;UAIe;;WAEN;;WAEA,OAAO;;EAEhB,KAAK,KAAK;;EAEV;;;UAIe;;WAEN,OAAO;;EAEhB;;;;;EAKA,OAAO,QAAQ,eAAe;;;qBAOnB,QAAQ;;KCxDT,uBAAuB,eAAe;;UCAjC;;;;;WAKN,QAAQ;;WAER;;WAEA;;;;;;;;;WASA;;;UAIM;;WAEN,QAAQ;;WAER,OAAO;;;;;;WAMP,QAAQ;;WAER,YAAY;;WAEZ,eAAe;;;;;;;EAOxB,KAAK,sBAAsB;;;;;;;;EAQ3B,IAAI,sBAAsB,eAAe;;;qBA4B9B,OAAO,gBAAgB;;UCrFnB;;WAEN,SAAS;;;UAIH;;WAEN;;;qBAME,YAAY,qBAAqB;;qBCHjC,qBAAqB;;WAEvB,MAAM;;WAEN;;WAEA,mBAAmB;EAE5B,YAAY,MAAM,WAAW,iBAAiB,UAAS;;;wBAczC,eAAe,gBAAgB,OAAO,YAAY,SA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B;;EAExB,aAAa,UAAU,eAAe;;EAEtC,UAAU,QAAQ,cAAc;;EAEhC,QAAQ,UAAU,gBAAgB;;EAGlC,OAAO,IAAI,WAAW;;EAGtB,SAAS,SAAS,GAAG;;EAErB,UAAU,SAAS,UAAU;;WAEpB,aAAa;;WAGb,KAAK;;EAEd,OAAO,gBAAgB;;;YAIb,IAAI,mBAAmB,SAAS,QAAQ,WAAW,KAAK,cAAc,WAAW;;YAEjF,UAAU,mBAAmB,SAAS,QAAQ,SAAS,cAAc;;wBCp0BjE,aAAa;;wBAuBb,aAAa,UAAS,sBAA2B;;wBA8BjD,cAAc,SAAS,uBAAuB;;wBAyB9C,aACd,YAAY,OAAO,0BAA0B,KAC7C,UAAS,sBACR;;wBC5Ia,OAAO,kBAAkB;;wBAKzB,SAAS,iBAAiB,SAAS;;wBCWnC,UAAU,iBAAiB;;wBCuU3B,OAAO,GAAG,OAAO,GAAG,UAAU,cAAc,KAAK,OAAO;;;;;wBAQxD,SAAS,GAAG,eAAe,GAAG,UAAU,cAAc,KAAK,eAAe;;wBAY1E,OAAO,IAAI,WAAW;;wBAKtB,MAAM,GAAG,UAAU,IAAI;;wBAWvB,UAAU,GAAG,UAAU,IAAI;;qBClY9B;;;;;wBC+CG,gBACR,mBAAmB,0BACnB,mBAAmB,oBAEzB,UAAU,WAAW,GAAG,KACvB,IAAI,WAAW,cAAc,aAAa,QAAQ,WAAW"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { withDocs } from "./dev.js";
|
|
2
2
|
// src/version.ts
|
|
3
3
|
/** Version of @dioramajs/core. */
|
|
4
|
-
const VERSION = "0.1.
|
|
4
|
+
const VERSION = "0.1.2";
|
|
5
5
|
// src/kernel/errors.ts
|
|
6
6
|
const CODE_BY_SOURCE = {
|
|
7
7
|
config: "CONFIG_INVALID",
|
|
@@ -2808,22 +2808,28 @@ const scroll = /*#__PURE__*/ definePlugin({
|
|
|
2808
2808
|
const KEYFRAMES = "dio-stage-scroll";
|
|
2809
2809
|
/** Scroll covered by the follow animation, px. Past it the canvas stays put. */
|
|
2810
2810
|
const RANGE = 1e6;
|
|
2811
|
+
/** Spans that moved less than this, px, keep their keyframes. */
|
|
2812
|
+
const SPAN_TOLERANCE = .5;
|
|
2811
2813
|
let sheet;
|
|
2814
|
+
let instances = 0;
|
|
2812
2815
|
/**
|
|
2813
2816
|
* Lets a fixed canvas follow page scroll on the compositor. A scroll timeline applies
|
|
2814
2817
|
* `translateY(-scroll)` in every compositor frame, and each Diorama frame adds back, through
|
|
2815
2818
|
* `translate`, the scroll it drew at. Between frames the canvas moves with the page by the
|
|
2816
2819
|
* scroll the frame has not seen yet.
|
|
2817
2820
|
*
|
|
2818
|
-
* Content that stands still on screen
|
|
2819
|
-
*
|
|
2820
|
-
*
|
|
2821
|
-
* `
|
|
2822
|
-
*
|
|
2821
|
+
* Content that stands still on screen would ride that scroll and jump back when the frame lands.
|
|
2822
|
+
* `pin` spans (a pinned sticky stage) go into the keyframes: the timeline stops moving the canvas
|
|
2823
|
+
* inside them, so it stops and starts on the compositor where CSS sticky does, between frames.
|
|
2824
|
+
* A `hold` predicate (content fixed to the viewport) drops the animation while true, and frames
|
|
2825
|
+
* draw at scroll 0. Both are read in `afterRender`, after the frame's layout reads, and the
|
|
2826
|
+
* animation and the offset switch in that same frame. Needs a DOM.
|
|
2823
2827
|
*/
|
|
2824
2828
|
function followScroll(app) {
|
|
2825
2829
|
const root = document.documentElement;
|
|
2826
2830
|
const holds = /* @__PURE__ */ new Set();
|
|
2831
|
+
const pins = /* @__PURE__ */ new Set();
|
|
2832
|
+
const id = ++instances;
|
|
2827
2833
|
let followed;
|
|
2828
2834
|
/** The site's styles keep the animation. */
|
|
2829
2835
|
let animated = false;
|
|
@@ -2833,31 +2839,52 @@ function followScroll(app) {
|
|
|
2833
2839
|
let held = false;
|
|
2834
2840
|
/** The offset last written to `translate`. */
|
|
2835
2841
|
let written = 0;
|
|
2842
|
+
/** The spans in the keyframes and the animation name that carries them. */
|
|
2843
|
+
let spans = [];
|
|
2844
|
+
let name = KEYFRAMES;
|
|
2845
|
+
let version = 0;
|
|
2846
|
+
let own;
|
|
2836
2847
|
app.system("layout", () => {
|
|
2837
2848
|
if (!followed) return;
|
|
2838
|
-
adoptKeyframes();
|
|
2849
|
+
adoptKeyframes(own);
|
|
2839
2850
|
if (!held) {
|
|
2840
2851
|
const { animationName, animationTimeline } = followed.computed;
|
|
2841
|
-
animated = animationName
|
|
2852
|
+
animated = animationName.startsWith(KEYFRAMES) && animationTimeline?.startsWith("scroll(") !== false;
|
|
2842
2853
|
}
|
|
2843
|
-
const
|
|
2854
|
+
const viewport = window.visualViewport?.height ?? root.clientHeight;
|
|
2855
|
+
const max = root.scrollHeight - Math.max(viewport, 0);
|
|
2844
2856
|
drawnAt = animated ? Math.max(0, Math.min(window.scrollY, max, RANGE)) : 0;
|
|
2845
2857
|
}, { name: "stage" });
|
|
2846
2858
|
app.system("afterRender", () => {
|
|
2847
2859
|
if (!followed) return;
|
|
2860
|
+
const { canvas } = followed;
|
|
2848
2861
|
let hold = false;
|
|
2849
2862
|
if (animated) {
|
|
2850
2863
|
for (const predicate of holds) if (predicate()) hold = true;
|
|
2851
2864
|
}
|
|
2852
|
-
if (
|
|
2853
|
-
|
|
2854
|
-
|
|
2865
|
+
if (animated && !hold) {
|
|
2866
|
+
const next = collect(pins);
|
|
2867
|
+
if (!sameSpans(next, spans)) {
|
|
2868
|
+
spans = next;
|
|
2869
|
+
if (spans.length) {
|
|
2870
|
+
name = `${KEYFRAMES}-${id}-${++version % 2}`;
|
|
2871
|
+
own ??= new CSSStyleSheet();
|
|
2872
|
+
own.replaceSync(pinnedKeyframes(name, spans));
|
|
2873
|
+
adoptKeyframes(own);
|
|
2874
|
+
} else name = KEYFRAMES;
|
|
2875
|
+
}
|
|
2855
2876
|
}
|
|
2856
|
-
const
|
|
2877
|
+
const wanted = hold ? "none" : name;
|
|
2878
|
+
if (held !== hold || canvas.style.animationName !== wanted) canvas.style.animationName = wanted;
|
|
2879
|
+
held = hold;
|
|
2880
|
+
const offset = hold ? 0 : drawnAt - covered(spans, drawnAt);
|
|
2857
2881
|
if (offset === written) return;
|
|
2858
2882
|
written = offset;
|
|
2859
|
-
|
|
2883
|
+
canvas.style.translate = offset ? `0px ${offset}px` : "";
|
|
2860
2884
|
}, { name: "stage" });
|
|
2885
|
+
app.onDispose(() => {
|
|
2886
|
+
if (own) document.adoptedStyleSheets = document.adoptedStyleSheets.filter((s) => s !== own);
|
|
2887
|
+
});
|
|
2861
2888
|
const follow = ((canvas) => {
|
|
2862
2889
|
const computed = startAnimation(canvas);
|
|
2863
2890
|
if (computed) followed = {
|
|
@@ -2870,16 +2897,62 @@ function followScroll(app) {
|
|
|
2870
2897
|
holds.add(entry);
|
|
2871
2898
|
return () => void holds.delete(entry);
|
|
2872
2899
|
};
|
|
2900
|
+
follow.pin = (source) => {
|
|
2901
|
+
const entry = () => source();
|
|
2902
|
+
pins.add(entry);
|
|
2903
|
+
return () => void pins.delete(entry);
|
|
2904
|
+
};
|
|
2873
2905
|
return follow;
|
|
2874
2906
|
}
|
|
2907
|
+
/** All spans, clipped to the animation range, sorted, overlaps merged. */
|
|
2908
|
+
function collect(pins) {
|
|
2909
|
+
const all = [];
|
|
2910
|
+
for (const source of pins) for (const [start, end] of source()) {
|
|
2911
|
+
const from = Math.max(0, start);
|
|
2912
|
+
const to = Math.min(RANGE, end);
|
|
2913
|
+
if (to > from) all.push([from, to]);
|
|
2914
|
+
}
|
|
2915
|
+
all.sort((a, b) => a[0] - b[0]);
|
|
2916
|
+
const merged = [];
|
|
2917
|
+
for (const span of all) {
|
|
2918
|
+
const last = merged.at(-1);
|
|
2919
|
+
if (last && span[0] <= last[1]) last[1] = Math.max(last[1], span[1]);
|
|
2920
|
+
else merged.push(span);
|
|
2921
|
+
}
|
|
2922
|
+
return merged;
|
|
2923
|
+
}
|
|
2924
|
+
const sameSpans = (a, b) => a.length === b.length && a.every(([start, end], i) => {
|
|
2925
|
+
const [from, to] = b[i];
|
|
2926
|
+
return Math.abs(start - from) < SPAN_TOLERANCE && Math.abs(end - to) < SPAN_TOLERANCE;
|
|
2927
|
+
});
|
|
2928
|
+
/** Scroll below `at` that falls inside the spans. */
|
|
2929
|
+
function covered(spans, at) {
|
|
2930
|
+
let sum = 0;
|
|
2931
|
+
for (const [start, end] of spans) sum += Math.max(0, Math.min(at, end) - start);
|
|
2932
|
+
return sum;
|
|
2933
|
+
}
|
|
2934
|
+
/** Keyframes that move by the scroll outside the spans and stand still inside them. */
|
|
2935
|
+
function pinnedKeyframes(name, spans) {
|
|
2936
|
+
const frame = (at, by) => `${(at / RANGE * 100).toFixed(6)}%{transform:translateY(${-by}px)}`;
|
|
2937
|
+
const frames = [frame(0, 0)];
|
|
2938
|
+
let still = 0;
|
|
2939
|
+
for (const [start, end] of spans) {
|
|
2940
|
+
frames.push(frame(start, start - still));
|
|
2941
|
+
still += end - start;
|
|
2942
|
+
frames.push(frame(end, end - still));
|
|
2943
|
+
}
|
|
2944
|
+
frames.push(frame(RANGE, RANGE - still));
|
|
2945
|
+
return `@keyframes ${name}{${frames.join("")}}`;
|
|
2946
|
+
}
|
|
2875
2947
|
/** Adopts the keyframes, again if a site reassigns `document.adoptedStyleSheets`. */
|
|
2876
|
-
function adoptKeyframes() {
|
|
2948
|
+
function adoptKeyframes(own) {
|
|
2877
2949
|
if (!sheet) {
|
|
2878
2950
|
sheet = new CSSStyleSheet();
|
|
2879
2951
|
sheet.replaceSync(`@keyframes ${KEYFRAMES} { to { transform: translateY(-${RANGE}px) } }`);
|
|
2880
2952
|
}
|
|
2881
2953
|
const sheets = document.adoptedStyleSheets;
|
|
2882
|
-
|
|
2954
|
+
const missing = [sheet, own].filter((s) => !!s && !sheets.includes(s));
|
|
2955
|
+
if (missing.length) document.adoptedStyleSheets = [...sheets, ...missing];
|
|
2883
2956
|
}
|
|
2884
2957
|
/** Starts the scroll-timeline animation on `canvas`. `undefined` if the engine lacks it. */
|
|
2885
2958
|
function startAnimation(canvas) {
|
|
@@ -2895,6 +2968,17 @@ const defaults$1 = {
|
|
|
2895
2968
|
maxPixelRatio: 2,
|
|
2896
2969
|
followScroll: true
|
|
2897
2970
|
};
|
|
2971
|
+
/** The large viewport, with the fallback for engines without `lvh` first. */
|
|
2972
|
+
const LARGE = ["100vh", "100lvh"];
|
|
2973
|
+
/** Height of the large viewport in CSS px, 0 where it cannot be measured. */
|
|
2974
|
+
function largeViewport() {
|
|
2975
|
+
const probe = document.createElement("div");
|
|
2976
|
+
probe.style.cssText = `position:fixed;top:0;left:0;width:0;visibility:hidden;pointer-events:none;height:${LARGE[0]};height:${LARGE[1]}`;
|
|
2977
|
+
document.documentElement.append(probe);
|
|
2978
|
+
const { height } = probe.getBoundingClientRect();
|
|
2979
|
+
probe.remove();
|
|
2980
|
+
return height;
|
|
2981
|
+
}
|
|
2898
2982
|
/** Canvases created by live apps. Any other `canvas[data-dio-canvas]` is a stale clone. */
|
|
2899
2983
|
const liveCanvases = /* @__PURE__ */ new WeakSet();
|
|
2900
2984
|
/** One canvas for the whole site. It outlives page transitions. */
|
|
@@ -2912,14 +2996,15 @@ const stage = /*#__PURE__*/ definePlugin({
|
|
|
2912
2996
|
height,
|
|
2913
2997
|
pixelRatio,
|
|
2914
2998
|
reducedMotion,
|
|
2915
|
-
hold: () => noop
|
|
2999
|
+
hold: () => noop,
|
|
3000
|
+
pin: () => noop
|
|
2916
3001
|
};
|
|
2917
3002
|
if (typeof document === "undefined") return api;
|
|
2918
3003
|
const root = document.documentElement;
|
|
2919
3004
|
const measure = () => {
|
|
2920
3005
|
batch(() => {
|
|
2921
3006
|
width.value = root.clientWidth;
|
|
2922
|
-
height.value = root.clientHeight;
|
|
3007
|
+
height.value = Math.max(root.clientHeight, largeViewport());
|
|
2923
3008
|
pixelRatio.value = Math.min(window.devicePixelRatio || 1, options.maxPixelRatio);
|
|
2924
3009
|
});
|
|
2925
3010
|
app.invalidate();
|
|
@@ -2953,6 +3038,7 @@ const stage = /*#__PURE__*/ definePlugin({
|
|
|
2953
3038
|
return {
|
|
2954
3039
|
...api,
|
|
2955
3040
|
hold: follow.hold,
|
|
3041
|
+
pin: follow.pin,
|
|
2956
3042
|
get canvas() {
|
|
2957
3043
|
canvas ??= resolveCanvas(options, adopt);
|
|
2958
3044
|
return canvas;
|
|
@@ -2977,10 +3063,11 @@ function resolveCanvas(options, adopt) {
|
|
|
2977
3063
|
position: "fixed",
|
|
2978
3064
|
inset: "0",
|
|
2979
3065
|
width: "100%",
|
|
2980
|
-
height:
|
|
3066
|
+
height: LARGE[0],
|
|
2981
3067
|
pointerEvents: "none",
|
|
2982
3068
|
zIndex: String(options.zIndex)
|
|
2983
3069
|
});
|
|
3070
|
+
created.style.height = LARGE[1];
|
|
2984
3071
|
document.body.append(created);
|
|
2985
3072
|
adopt(created);
|
|
2986
3073
|
return created;
|