@tachui/primitives 0.8.15 → 0.8.17
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/ScrollView-D9G6WDwr.js +833 -0
- package/dist/display/Image.d.ts +7 -0
- package/dist/display/Image.d.ts.map +1 -1
- package/dist/display/index.js +1 -1
- package/dist/index.js +2 -2
- package/package.json +3 -3
- package/dist/ScrollView-CC8g8Lq2.js +0 -719
|
@@ -1,719 +0,0 @@
|
|
|
1
|
-
import { withModifiers as f, ComponentWithCSSClasses as z, processElementOverride as H, createSignal as E, useLifecycle as $, registerComponentWithLifecycleHooks as M, h as S, createEffect as b, ConcatenatedComponent as O, text as W, isSignal as v } from "@tachui/core";
|
|
2
|
-
import { aspectRatio as x } from "@tachui/modifiers";
|
|
3
|
-
var Y = Object.defineProperty, V = (e, t, s) => t in e ? Y(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, g = (e, t, s) => V(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
-
function L(e) {
|
|
5
|
-
return typeof e == "object" && e !== null && typeof e.resolve == "function";
|
|
6
|
-
}
|
|
7
|
-
function D(e) {
|
|
8
|
-
return e && (L(e) ? e.resolve() : e);
|
|
9
|
-
}
|
|
10
|
-
class F extends z {
|
|
11
|
-
constructor(t) {
|
|
12
|
-
super(), this.props = t, g(this, "type", "component"), g(this, "id"), g(this, "mounted", !1), g(this, "cleanup", []), g(this, "effectiveTag"), g(this, "validationResult"), g(this, "loadingStateSignal"), g(this, "setLoadingState"), this.id = `image-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
13
|
-
const s = H("Image", "img", this.props.element);
|
|
14
|
-
this.effectiveTag = s.tag, this.validationResult = s.validation;
|
|
15
|
-
const n = this.props.src ? "idle" : "error", [o, i] = E(n);
|
|
16
|
-
this.loadingStateSignal = o, this.setLoadingState = i, $(this, {
|
|
17
|
-
onDOMReady: (l, u) => {
|
|
18
|
-
L(this.props.src) && u instanceof HTMLImageElement && this.setupImageAssetReactivityForDOMElement(
|
|
19
|
-
this.props.src,
|
|
20
|
-
u
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
}), M(this);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Set loading state and notify callback
|
|
27
|
-
*/
|
|
28
|
-
setLoadingStateWithCallback(t) {
|
|
29
|
-
this.setLoadingState(t), this.props.onLoadingStateChange && this.props.onLoadingStateChange(t);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Render the image component with reactive content handling
|
|
33
|
-
*/
|
|
34
|
-
render() {
|
|
35
|
-
const t = this.loadingStateSignal();
|
|
36
|
-
if (t === "loading" && this.props.placeholder) {
|
|
37
|
-
if (typeof this.props.placeholder == "string")
|
|
38
|
-
return [S("img", {
|
|
39
|
-
class: "tachui-image-placeholder",
|
|
40
|
-
src: this.props.placeholder,
|
|
41
|
-
alt: "Loading..."
|
|
42
|
-
})];
|
|
43
|
-
if (this.props.placeholder && typeof this.props.placeholder == "object")
|
|
44
|
-
return this.props.placeholder.render();
|
|
45
|
-
}
|
|
46
|
-
if (t === "error" && this.props.errorPlaceholder) {
|
|
47
|
-
if (typeof this.props.errorPlaceholder == "string")
|
|
48
|
-
return [S("img", {
|
|
49
|
-
class: "tachui-image-error",
|
|
50
|
-
src: this.props.errorPlaceholder,
|
|
51
|
-
alt: "Error loading image"
|
|
52
|
-
})];
|
|
53
|
-
if (this.props.errorPlaceholder && typeof this.props.errorPlaceholder == "object")
|
|
54
|
-
return this.props.errorPlaceholder.render();
|
|
55
|
-
}
|
|
56
|
-
const s = D(this.props.src), n = ["tachui-image"], o = this.createClassString(this.props, n), i = S(this.effectiveTag, {
|
|
57
|
-
className: o,
|
|
58
|
-
src: s,
|
|
59
|
-
// Pass resolved src for initial render
|
|
60
|
-
alt: this.props.alt,
|
|
61
|
-
// Pass reactive alt directly
|
|
62
|
-
loading: this.props.loadingStrategy || "lazy",
|
|
63
|
-
crossorigin: this.props.crossOrigin,
|
|
64
|
-
decoding: this.props.decoding || "async",
|
|
65
|
-
fetchpriority: this.props.fetchPriority
|
|
66
|
-
});
|
|
67
|
-
return i.componentMetadata = {
|
|
68
|
-
id: this.id,
|
|
69
|
-
type: "Image",
|
|
70
|
-
originalType: "Image",
|
|
71
|
-
overriddenTo: this.effectiveTag !== "img" ? this.effectiveTag : void 0,
|
|
72
|
-
validationResult: this.validationResult
|
|
73
|
-
}, [i];
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Set up ImageAsset reactivity for a real DOM element (called from onDOMReady)
|
|
77
|
-
*/
|
|
78
|
-
setupImageAssetReactivityForDOMElement(t, s) {
|
|
79
|
-
const n = b(() => {
|
|
80
|
-
const o = t.resolve();
|
|
81
|
-
s.src = o, this.setLoadingStateWithCallback("loading");
|
|
82
|
-
});
|
|
83
|
-
this.cleanup.push(() => n.dispose());
|
|
84
|
-
}
|
|
85
|
-
// ============================================================================
|
|
86
|
-
// Concatenation Support (Phase 3.1)
|
|
87
|
-
// ============================================================================
|
|
88
|
-
/**
|
|
89
|
-
* Concatenate this image with another concatenatable component
|
|
90
|
-
*/
|
|
91
|
-
concat(t) {
|
|
92
|
-
const s = this.toSegment(), n = t.toSegment(), o = {
|
|
93
|
-
totalSegments: t instanceof O ? t.segments.length + 1 : 2,
|
|
94
|
-
accessibilityRole: t instanceof O ? this.mergeAccessibilityRoles(
|
|
95
|
-
"group",
|
|
96
|
-
t.metadata.accessibilityRole
|
|
97
|
-
) : this.determineAccessibilityRole(t),
|
|
98
|
-
semanticStructure: "inline"
|
|
99
|
-
// Images are typically inline in concatenation
|
|
100
|
-
};
|
|
101
|
-
return new O([s, n], o);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Convert this image to a segment for concatenation
|
|
105
|
-
*/
|
|
106
|
-
toSegment() {
|
|
107
|
-
return {
|
|
108
|
-
id: this.id,
|
|
109
|
-
component: this,
|
|
110
|
-
modifiers: [],
|
|
111
|
-
// Images don't typically have concatenation-specific modifiers
|
|
112
|
-
render: () => {
|
|
113
|
-
const t = this.render();
|
|
114
|
-
return Array.isArray(t) ? t[0] : t;
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Check if this component supports concatenation
|
|
120
|
-
*/
|
|
121
|
-
isConcatenatable() {
|
|
122
|
-
return !0;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Determine accessibility role for concatenation
|
|
126
|
-
*/
|
|
127
|
-
determineAccessibilityRole(t) {
|
|
128
|
-
switch (t.constructor.name) {
|
|
129
|
-
case "EnhancedText":
|
|
130
|
-
return "group";
|
|
131
|
-
// Image + Text = group
|
|
132
|
-
case "EnhancedImage":
|
|
133
|
-
return "group";
|
|
134
|
-
// Image + Image = group
|
|
135
|
-
case "EnhancedButton":
|
|
136
|
-
case "EnhancedLink":
|
|
137
|
-
return "composite";
|
|
138
|
-
// Image + Interactive = composite
|
|
139
|
-
default:
|
|
140
|
-
return "composite";
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Merge accessibility roles when combining components
|
|
145
|
-
*/
|
|
146
|
-
mergeAccessibilityRoles(t, s) {
|
|
147
|
-
return t === "composite" || s === "composite" ? "composite" : "group";
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function I(e, t = {}) {
|
|
151
|
-
const s = { ...t, src: e }, n = new F(s), o = f(n), i = (l) => {
|
|
152
|
-
if (l && Array.isArray(l.modifiers))
|
|
153
|
-
return l;
|
|
154
|
-
if (l?._modifiableComponent && Array.isArray(l._modifiableComponent.modifiers))
|
|
155
|
-
return l._modifiableComponent;
|
|
156
|
-
if (Array.isArray(o?.modifiers))
|
|
157
|
-
return o;
|
|
158
|
-
if (o?._modifiableComponent && Array.isArray(o._modifiableComponent.modifiers))
|
|
159
|
-
return o._modifiableComponent;
|
|
160
|
-
throw new Error("Image shorthand target is not modifiable");
|
|
161
|
-
};
|
|
162
|
-
return o.scaledToFit = function() {
|
|
163
|
-
return i(this).modifiers.push(x(void 0, "fit")), o;
|
|
164
|
-
}, o.scaledToFill = function() {
|
|
165
|
-
return i(this).modifiers.push(x(void 0, "fill")), o;
|
|
166
|
-
}, o;
|
|
167
|
-
}
|
|
168
|
-
const J = {
|
|
169
|
-
idle: "idle",
|
|
170
|
-
loading: "loading",
|
|
171
|
-
loaded: "loaded",
|
|
172
|
-
error: "error"
|
|
173
|
-
}, K = {
|
|
174
|
-
fit: "fit",
|
|
175
|
-
fill: "fill",
|
|
176
|
-
stretch: "stretch",
|
|
177
|
-
center: "center",
|
|
178
|
-
scaleDown: "scaleDown"
|
|
179
|
-
}, Z = {
|
|
180
|
-
/**
|
|
181
|
-
* Create a responsive image with multiple sources
|
|
182
|
-
*/
|
|
183
|
-
responsive(e, t, s = {}) {
|
|
184
|
-
const n = e.map((o) => {
|
|
185
|
-
const i = [o.src];
|
|
186
|
-
return o.width && i.push(`${o.width}w`), i.join(" ");
|
|
187
|
-
}).join(", ");
|
|
188
|
-
return I(t, { ...s, srcSet: n });
|
|
189
|
-
},
|
|
190
|
-
/**
|
|
191
|
-
* Create an image with progressive loading
|
|
192
|
-
*/
|
|
193
|
-
progressive(e, t, s = {}) {
|
|
194
|
-
return I(e, {
|
|
195
|
-
...s,
|
|
196
|
-
lowQualitySrc: e,
|
|
197
|
-
highQualitySrc: t
|
|
198
|
-
});
|
|
199
|
-
},
|
|
200
|
-
/**
|
|
201
|
-
* Create an image with loading placeholder
|
|
202
|
-
*/
|
|
203
|
-
withPlaceholder(e, t, s = {}) {
|
|
204
|
-
return I(e, {
|
|
205
|
-
...s,
|
|
206
|
-
placeholder: t
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
var B = Object.defineProperty, N = (e, t, s) => t in e ? B(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, C = (e, t, s) => N(e, typeof t != "symbol" ? t + "" : t, s);
|
|
211
|
-
class m {
|
|
212
|
-
constructor(t, s, n, o = {}) {
|
|
213
|
-
this.props = t, this.tag = s, this.content = n, this.attributes = o, C(this, "type", "component"), C(this, "id"), C(this, "mounted", !1), C(this, "cleanup", []), this.id = `element-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
214
|
-
}
|
|
215
|
-
render() {
|
|
216
|
-
return [
|
|
217
|
-
S(this.tag, this.attributes, this.content ? W(this.content) : "")
|
|
218
|
-
];
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
const y = {
|
|
222
|
-
/**
|
|
223
|
-
* Create a div element with modifier support
|
|
224
|
-
*/
|
|
225
|
-
div: (e = {}) => {
|
|
226
|
-
const t = new m(
|
|
227
|
-
e,
|
|
228
|
-
"div",
|
|
229
|
-
e.children ? String(e.children) : void 0
|
|
230
|
-
);
|
|
231
|
-
return f(t);
|
|
232
|
-
},
|
|
233
|
-
/**
|
|
234
|
-
* Create a span element with modifier support
|
|
235
|
-
*/
|
|
236
|
-
span: (e = {}) => {
|
|
237
|
-
const t = new m(
|
|
238
|
-
e,
|
|
239
|
-
"span",
|
|
240
|
-
e.children ? String(e.children) : void 0
|
|
241
|
-
);
|
|
242
|
-
return f(t);
|
|
243
|
-
},
|
|
244
|
-
/**
|
|
245
|
-
* Create an anchor element with modifier support
|
|
246
|
-
*/
|
|
247
|
-
a: (e = {}) => {
|
|
248
|
-
const t = new m(
|
|
249
|
-
e,
|
|
250
|
-
"a",
|
|
251
|
-
e.children ? String(e.children) : void 0,
|
|
252
|
-
{
|
|
253
|
-
href: e.href,
|
|
254
|
-
onclick: e.onClick
|
|
255
|
-
}
|
|
256
|
-
);
|
|
257
|
-
return f(t);
|
|
258
|
-
},
|
|
259
|
-
/**
|
|
260
|
-
* Create a paragraph element with modifier support
|
|
261
|
-
*/
|
|
262
|
-
p: (e = {}) => {
|
|
263
|
-
const t = new m(
|
|
264
|
-
e,
|
|
265
|
-
"p",
|
|
266
|
-
e.children ? String(e.children) : void 0
|
|
267
|
-
);
|
|
268
|
-
return f(t);
|
|
269
|
-
},
|
|
270
|
-
/**
|
|
271
|
-
* Create a button element with modifier support
|
|
272
|
-
*
|
|
273
|
-
* Note: For enhanced button features (press states, variants, accessibility),
|
|
274
|
-
* use the main Button component instead.
|
|
275
|
-
*/
|
|
276
|
-
button: (e = {}) => {
|
|
277
|
-
const t = new m(
|
|
278
|
-
e,
|
|
279
|
-
"button",
|
|
280
|
-
e.children ? String(e.children) : void 0,
|
|
281
|
-
{
|
|
282
|
-
onclick: e.onClick
|
|
283
|
-
}
|
|
284
|
-
);
|
|
285
|
-
return process.env.NODE_ENV === "test" && (t.props || (t.props = {}), t.props.tabIndex = 0), f(t);
|
|
286
|
-
},
|
|
287
|
-
/**
|
|
288
|
-
* Create an input element with modifier support
|
|
289
|
-
*/
|
|
290
|
-
input: (e = {}) => {
|
|
291
|
-
const t = new m(e, "input", void 0, {
|
|
292
|
-
type: e.type || "text",
|
|
293
|
-
value: e.value || "",
|
|
294
|
-
placeholder: e.placeholder || "",
|
|
295
|
-
oninput: (s) => {
|
|
296
|
-
const n = s.target;
|
|
297
|
-
e.onChange?.(n.value);
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
return f(t);
|
|
301
|
-
},
|
|
302
|
-
/**
|
|
303
|
-
* Create an image element with modifier support
|
|
304
|
-
*
|
|
305
|
-
* Note: For enhanced image features (loading states, content modes, progressive loading),
|
|
306
|
-
* use the main Image component instead.
|
|
307
|
-
*/
|
|
308
|
-
img: (e) => {
|
|
309
|
-
const t = new m(e, "img", void 0, {
|
|
310
|
-
src: e.src,
|
|
311
|
-
alt: e.alt || "",
|
|
312
|
-
width: e.width,
|
|
313
|
-
height: e.height
|
|
314
|
-
});
|
|
315
|
-
return f(t);
|
|
316
|
-
},
|
|
317
|
-
/**
|
|
318
|
-
* Create a heading element with modifier support
|
|
319
|
-
*/
|
|
320
|
-
heading: (e) => (t = {}) => {
|
|
321
|
-
const s = new m(
|
|
322
|
-
t,
|
|
323
|
-
`h${e}`,
|
|
324
|
-
t.children ? String(t.children) : void 0
|
|
325
|
-
);
|
|
326
|
-
return f(s);
|
|
327
|
-
}
|
|
328
|
-
}, Q = y.heading(1), tt = y.heading(2), et = y.heading(3), st = y.heading(4), ot = y.heading(5), nt = y.heading(6);
|
|
329
|
-
var X = Object.defineProperty, k = (e, t, s) => t in e ? X(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, r = (e, t, s) => k(e, typeof t != "symbol" ? t + "" : t, s);
|
|
330
|
-
class j {
|
|
331
|
-
constructor(t) {
|
|
332
|
-
this.props = t, r(this, "type", "component"), r(this, "id"), r(this, "mounted", !1), r(this, "cleanup", []), r(this, "scrollElement", null), r(this, "contentOffsetSignal"), r(this, "setContentOffset"), r(this, "contentSizeSignal"), r(this, "setContentSize"), r(this, "setIsScrolling"), r(this, "pullToRefreshStateSignal"), r(this, "setPullToRefreshState"), r(this, "scrollEventThrottle"), r(this, "lastScrollTime", 0), r(this, "scrollVelocity", { x: 0, y: 0 }), r(this, "lastScrollOffset", { x: 0, y: 0 }), r(this, "pullStartY", 0), r(this, "isPulling", !1), r(this, "handleScroll", (h) => {
|
|
333
|
-
if (!this.scrollElement) return;
|
|
334
|
-
const p = performance.now(), c = p - this.lastScrollTime;
|
|
335
|
-
if (c < this.scrollEventThrottle) return;
|
|
336
|
-
const d = {
|
|
337
|
-
x: this.scrollElement.scrollLeft,
|
|
338
|
-
y: this.scrollElement.scrollTop
|
|
339
|
-
};
|
|
340
|
-
this.scrollVelocity = this.calculateVelocity(d, c), this.setContentOffset(d), this.setContentSize({
|
|
341
|
-
width: this.scrollElement.scrollWidth,
|
|
342
|
-
height: this.scrollElement.scrollHeight
|
|
343
|
-
});
|
|
344
|
-
const a = this.detectScrollEdges(), w = {
|
|
345
|
-
offset: d,
|
|
346
|
-
velocity: this.scrollVelocity,
|
|
347
|
-
contentSize: {
|
|
348
|
-
width: this.scrollElement.scrollWidth,
|
|
349
|
-
height: this.scrollElement.scrollHeight
|
|
350
|
-
},
|
|
351
|
-
containerSize: {
|
|
352
|
-
width: this.scrollElement.clientWidth,
|
|
353
|
-
height: this.scrollElement.clientHeight
|
|
354
|
-
},
|
|
355
|
-
edges: a
|
|
356
|
-
};
|
|
357
|
-
this.props.onScroll && this.props.onScroll(w), a.top && this.props.onReachTop && this.props.onReachTop(), a.bottom && this.props.onReachBottom && this.props.onReachBottom(), a.left && this.props.onReachLeft && this.props.onReachLeft(), a.right && this.props.onReachRight && this.props.onReachRight(), this.lastScrollOffset = d, this.lastScrollTime = p;
|
|
358
|
-
}), r(this, "handleScrollStart", () => {
|
|
359
|
-
this.setIsScrolling(!0), this.props.onScrollBegin && this.props.onScrollBegin();
|
|
360
|
-
}), r(this, "handleScrollEnd", () => {
|
|
361
|
-
this.setIsScrolling(!1), this.props.onScrollEnd && this.props.onScrollEnd();
|
|
362
|
-
}), r(this, "handleTouchStart", (h) => {
|
|
363
|
-
this.props.refreshControl?.enabled && (this.pullStartY = h.touches[0].clientY, this.isPulling = !1);
|
|
364
|
-
}), r(this, "handleTouchMove", (h) => {
|
|
365
|
-
if (!this.props.refreshControl?.enabled || !this.scrollElement) return;
|
|
366
|
-
const c = h.touches[0].clientY - this.pullStartY, d = this.props.refreshControl.threshold || 80;
|
|
367
|
-
this.scrollElement.scrollTop <= 0 && c > 0 && (this.isPulling = !0, c > d ? this.setPullToRefreshState("ready") : this.setPullToRefreshState("pulling"));
|
|
368
|
-
}), r(this, "handleTouchEnd", async () => {
|
|
369
|
-
if (!this.props.refreshControl?.enabled || !this.isPulling) return;
|
|
370
|
-
if (this.pullToRefreshStateSignal() === "ready") {
|
|
371
|
-
this.setPullToRefreshState("refreshing");
|
|
372
|
-
try {
|
|
373
|
-
await this.props.refreshControl.onRefresh();
|
|
374
|
-
} catch (p) {
|
|
375
|
-
console.error("Pull to refresh error:", p);
|
|
376
|
-
} finally {
|
|
377
|
-
this.setPullToRefreshState("idle");
|
|
378
|
-
}
|
|
379
|
-
} else
|
|
380
|
-
this.setPullToRefreshState("idle");
|
|
381
|
-
this.isPulling = !1;
|
|
382
|
-
}), this.id = `scrollview-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, this.scrollEventThrottle = t.scrollEventThrottle || 16;
|
|
383
|
-
const [s, n] = E(
|
|
384
|
-
{ x: 0, y: 0 }
|
|
385
|
-
);
|
|
386
|
-
this.contentOffsetSignal = s, this.setContentOffset = n;
|
|
387
|
-
const [o, i] = E({
|
|
388
|
-
width: 0,
|
|
389
|
-
height: 0
|
|
390
|
-
});
|
|
391
|
-
this.contentSizeSignal = o, this.setContentSize = i;
|
|
392
|
-
const [, l] = E(!1);
|
|
393
|
-
this.setIsScrolling = l;
|
|
394
|
-
const [u, R] = E("idle");
|
|
395
|
-
if (this.pullToRefreshStateSignal = u, this.setPullToRefreshState = R, t.contentOffset && v(t.contentOffset)) {
|
|
396
|
-
this.setContentOffset(t.contentOffset());
|
|
397
|
-
const h = b(() => {
|
|
398
|
-
t.contentOffset && v(t.contentOffset) && this.setContentOffset(t.contentOffset());
|
|
399
|
-
});
|
|
400
|
-
this.cleanup.push(() => h.dispose());
|
|
401
|
-
}
|
|
402
|
-
if (t.contentSize && v(t.contentSize)) {
|
|
403
|
-
this.setContentSize(t.contentSize());
|
|
404
|
-
const h = b(() => {
|
|
405
|
-
t.contentSize && v(t.contentSize) && this.setContentSize(t.contentSize());
|
|
406
|
-
});
|
|
407
|
-
this.cleanup.push(() => h.dispose());
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Calculate scroll velocity
|
|
412
|
-
*/
|
|
413
|
-
calculateVelocity(t, s) {
|
|
414
|
-
const n = t.x - this.lastScrollOffset.x, o = t.y - this.lastScrollOffset.y;
|
|
415
|
-
return {
|
|
416
|
-
x: s > 0 ? n / s : 0,
|
|
417
|
-
y: s > 0 ? o / s : 0
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Detect scroll edges
|
|
422
|
-
*/
|
|
423
|
-
detectScrollEdges() {
|
|
424
|
-
if (!this.scrollElement)
|
|
425
|
-
return { top: !1, bottom: !1, left: !1, right: !1 };
|
|
426
|
-
const {
|
|
427
|
-
scrollTop: t,
|
|
428
|
-
scrollLeft: s,
|
|
429
|
-
scrollHeight: n,
|
|
430
|
-
scrollWidth: o,
|
|
431
|
-
clientHeight: i,
|
|
432
|
-
clientWidth: l
|
|
433
|
-
} = this.scrollElement;
|
|
434
|
-
return {
|
|
435
|
-
top: t <= 0,
|
|
436
|
-
bottom: t + i >= n - 1,
|
|
437
|
-
left: s <= 0,
|
|
438
|
-
right: s + l >= o - 1
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Set up scroll event handlers
|
|
443
|
-
*/
|
|
444
|
-
setupScrollHandlers(t) {
|
|
445
|
-
let s;
|
|
446
|
-
const n = () => {
|
|
447
|
-
clearTimeout(s), this.handleScrollStart();
|
|
448
|
-
}, o = () => {
|
|
449
|
-
clearTimeout(s), s = setTimeout(() => {
|
|
450
|
-
this.handleScrollEnd();
|
|
451
|
-
}, 150);
|
|
452
|
-
}, i = (l) => {
|
|
453
|
-
n(), this.handleScroll(l), o();
|
|
454
|
-
};
|
|
455
|
-
t.addEventListener("scroll", i, { passive: !0 }), t.addEventListener("touchstart", this.handleTouchStart, {
|
|
456
|
-
passive: !0
|
|
457
|
-
}), t.addEventListener("touchmove", this.handleTouchMove, {
|
|
458
|
-
passive: !1
|
|
459
|
-
}), t.addEventListener("touchend", this.handleTouchEnd, { passive: !0 }), this.cleanup.push(() => {
|
|
460
|
-
t.removeEventListener("scroll", i), t.removeEventListener("touchstart", this.handleTouchStart), t.removeEventListener("touchmove", this.handleTouchMove), t.removeEventListener("touchend", this.handleTouchEnd), clearTimeout(s);
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
|
-
* Get overflow styles based on direction
|
|
465
|
-
*/
|
|
466
|
-
getOverflowStyles(t) {
|
|
467
|
-
switch (t) {
|
|
468
|
-
case "vertical":
|
|
469
|
-
return {
|
|
470
|
-
overflowX: "hidden",
|
|
471
|
-
overflowY: "auto"
|
|
472
|
-
};
|
|
473
|
-
case "horizontal":
|
|
474
|
-
return {
|
|
475
|
-
overflowX: "auto",
|
|
476
|
-
overflowY: "hidden"
|
|
477
|
-
};
|
|
478
|
-
case "both":
|
|
479
|
-
return {
|
|
480
|
-
overflow: "auto"
|
|
481
|
-
};
|
|
482
|
-
default:
|
|
483
|
-
return {
|
|
484
|
-
overflowX: "hidden",
|
|
485
|
-
overflowY: "auto"
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Apply additional scroll view styling (position and overflow already set in initial render)
|
|
491
|
-
*/
|
|
492
|
-
applyScrollViewStyles(t) {
|
|
493
|
-
const { showsScrollIndicator: s = !0, bounces: n = !0 } = this.props;
|
|
494
|
-
if (!s) {
|
|
495
|
-
t.style.scrollbarWidth = "none", t.style.msOverflowStyle = "none";
|
|
496
|
-
const o = document.createElement("style");
|
|
497
|
-
o.textContent = `
|
|
498
|
-
#${t.id}::-webkit-scrollbar {
|
|
499
|
-
display: none;
|
|
500
|
-
}
|
|
501
|
-
`, document.head.appendChild(o), this.cleanup.push(() => {
|
|
502
|
-
document.head.removeChild(o);
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
n ? t.style.webkitOverflowScrolling = "touch" : t.style.overscrollBehavior = "none", t.style.scrollBehavior = "smooth";
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* Apply content insets
|
|
509
|
-
*/
|
|
510
|
-
applyContentInsets(t) {
|
|
511
|
-
const { contentInset: s } = this.props;
|
|
512
|
-
if (s) {
|
|
513
|
-
const { top: n = 0, bottom: o = 0, left: i = 0, right: l = 0 } = s;
|
|
514
|
-
t.style.padding = `${n}px ${l}px ${o}px ${i}px`;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Create pull to refresh indicator
|
|
519
|
-
*/
|
|
520
|
-
createPullToRefreshIndicator() {
|
|
521
|
-
if (!this.props.refreshControl?.enabled) return null;
|
|
522
|
-
const t = this.pullToRefreshStateSignal(), s = this.props.refreshControl.tintColor || "#007AFF";
|
|
523
|
-
let n = "";
|
|
524
|
-
switch (t) {
|
|
525
|
-
case "pulling":
|
|
526
|
-
n = "↓ Pull to refresh";
|
|
527
|
-
break;
|
|
528
|
-
case "ready":
|
|
529
|
-
n = "↑ Release to refresh";
|
|
530
|
-
break;
|
|
531
|
-
case "refreshing":
|
|
532
|
-
n = "⟳ Refreshing...";
|
|
533
|
-
break;
|
|
534
|
-
default:
|
|
535
|
-
n = "";
|
|
536
|
-
}
|
|
537
|
-
return n ? {
|
|
538
|
-
type: "component",
|
|
539
|
-
id: `${this.id}-refresh`,
|
|
540
|
-
mounted: !1,
|
|
541
|
-
cleanup: [],
|
|
542
|
-
props: {},
|
|
543
|
-
render: () => [
|
|
544
|
-
S(
|
|
545
|
-
"div",
|
|
546
|
-
{
|
|
547
|
-
style: {
|
|
548
|
-
position: "absolute",
|
|
549
|
-
top: "-60px",
|
|
550
|
-
left: "50%",
|
|
551
|
-
transform: "translateX(-50%)",
|
|
552
|
-
padding: "10px 20px",
|
|
553
|
-
backgroundColor: "#f8f9fa",
|
|
554
|
-
borderRadius: "20px",
|
|
555
|
-
color: s,
|
|
556
|
-
fontSize: "14px",
|
|
557
|
-
fontWeight: "500",
|
|
558
|
-
textAlign: "center",
|
|
559
|
-
zIndex: 1e3,
|
|
560
|
-
transition: "all 0.3s ease",
|
|
561
|
-
opacity: t === "idle" ? 0 : 1
|
|
562
|
-
}
|
|
563
|
-
},
|
|
564
|
-
n
|
|
565
|
-
)
|
|
566
|
-
]
|
|
567
|
-
} : null;
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* Scroll to specific position
|
|
571
|
-
*/
|
|
572
|
-
scrollTo(t, s = "smooth") {
|
|
573
|
-
if (!this.scrollElement) return;
|
|
574
|
-
const n = { behavior: s };
|
|
575
|
-
t.x !== void 0 && (n.left = t.x), t.y !== void 0 && (n.top = t.y), this.scrollElement.scrollTo(n);
|
|
576
|
-
}
|
|
577
|
-
/**
|
|
578
|
-
* Scroll to top
|
|
579
|
-
*/
|
|
580
|
-
scrollToTop(t = "smooth") {
|
|
581
|
-
this.scrollTo({ x: 0, y: 0 }, t);
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Scroll to bottom
|
|
585
|
-
*/
|
|
586
|
-
scrollToBottom(t = "smooth") {
|
|
587
|
-
this.scrollElement && this.scrollTo(
|
|
588
|
-
{
|
|
589
|
-
x: 0,
|
|
590
|
-
y: this.scrollElement.scrollHeight - this.scrollElement.clientHeight
|
|
591
|
-
},
|
|
592
|
-
t
|
|
593
|
-
);
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Render the scroll view component
|
|
597
|
-
*/
|
|
598
|
-
render() {
|
|
599
|
-
const { children: t = [], scrollEnabled: s = !0 } = this.props;
|
|
600
|
-
let n = [];
|
|
601
|
-
const o = t;
|
|
602
|
-
if (typeof o == "function") {
|
|
603
|
-
const c = o();
|
|
604
|
-
n = Array.isArray(c) ? c : [];
|
|
605
|
-
} else Array.isArray(t) && (n = t);
|
|
606
|
-
const i = S(
|
|
607
|
-
"div",
|
|
608
|
-
{
|
|
609
|
-
class: "tachui-scrollview-content",
|
|
610
|
-
style: {
|
|
611
|
-
minHeight: "100%",
|
|
612
|
-
minWidth: "100%"
|
|
613
|
-
}
|
|
614
|
-
},
|
|
615
|
-
...n.flatMap((c) => c.render())
|
|
616
|
-
), l = this.createPullToRefreshIndicator(), u = [];
|
|
617
|
-
if (l) {
|
|
618
|
-
const c = l.render(), d = Array.isArray(c) ? c : [c];
|
|
619
|
-
u.push(...d.filter((a) => a));
|
|
620
|
-
}
|
|
621
|
-
u.push(i);
|
|
622
|
-
const { direction: R = "vertical" } = this.props, h = this.getOverflowStyles(R), p = S(
|
|
623
|
-
"div",
|
|
624
|
-
{
|
|
625
|
-
id: this.id,
|
|
626
|
-
class: "tachui-scrollview",
|
|
627
|
-
style: {
|
|
628
|
-
height: "100%",
|
|
629
|
-
width: "100%",
|
|
630
|
-
position: "relative",
|
|
631
|
-
...h
|
|
632
|
-
}
|
|
633
|
-
},
|
|
634
|
-
...u
|
|
635
|
-
);
|
|
636
|
-
if (p.element) {
|
|
637
|
-
const c = p.element;
|
|
638
|
-
this.scrollElement = c, this.applyScrollViewStyles(c), this.setupScrollHandlers(c), i.element && this.applyContentInsets(i.element);
|
|
639
|
-
const d = () => {
|
|
640
|
-
const a = v(s) ? s() : s;
|
|
641
|
-
c.style.overflow = a ? "auto" : "hidden", c.style.pointerEvents = a ? "auto" : "none";
|
|
642
|
-
};
|
|
643
|
-
if (v(s)) {
|
|
644
|
-
const a = b(d);
|
|
645
|
-
this.cleanup.push(() => a.dispose());
|
|
646
|
-
} else
|
|
647
|
-
d();
|
|
648
|
-
if (typeof o == "function") {
|
|
649
|
-
const a = b(() => {
|
|
650
|
-
const w = o(), _ = (Array.isArray(w) ? w : []).flatMap((T) => T.render());
|
|
651
|
-
if (i.element) {
|
|
652
|
-
const T = i.element;
|
|
653
|
-
T.innerHTML = "", _.forEach((P) => {
|
|
654
|
-
P && P.element && T.appendChild(P.element);
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
this.cleanup.push(() => a.dispose());
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
return [p];
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
function A(e = {}) {
|
|
665
|
-
const t = new j(e);
|
|
666
|
-
return f(t);
|
|
667
|
-
}
|
|
668
|
-
const it = {
|
|
669
|
-
/**
|
|
670
|
-
* Create a scroll view with pull to refresh
|
|
671
|
-
*/
|
|
672
|
-
withRefresh(e, t, s = {}) {
|
|
673
|
-
return A({
|
|
674
|
-
children: e,
|
|
675
|
-
refreshControl: {
|
|
676
|
-
enabled: !0,
|
|
677
|
-
onRefresh: t,
|
|
678
|
-
...s
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
},
|
|
682
|
-
/**
|
|
683
|
-
* Create a horizontal scroll view
|
|
684
|
-
*/
|
|
685
|
-
horizontal(e, t = {}) {
|
|
686
|
-
return A({
|
|
687
|
-
...t,
|
|
688
|
-
children: e,
|
|
689
|
-
direction: "horizontal"
|
|
690
|
-
});
|
|
691
|
-
},
|
|
692
|
-
/**
|
|
693
|
-
* Create a paged scroll view
|
|
694
|
-
*/
|
|
695
|
-
paged(e, t = {}) {
|
|
696
|
-
return A({
|
|
697
|
-
...t,
|
|
698
|
-
children: e,
|
|
699
|
-
pagingEnabled: !0
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
};
|
|
703
|
-
export {
|
|
704
|
-
F as E,
|
|
705
|
-
y as H,
|
|
706
|
-
I,
|
|
707
|
-
A as S,
|
|
708
|
-
J as a,
|
|
709
|
-
K as b,
|
|
710
|
-
Z as c,
|
|
711
|
-
Q as d,
|
|
712
|
-
tt as e,
|
|
713
|
-
et as f,
|
|
714
|
-
st as g,
|
|
715
|
-
ot as h,
|
|
716
|
-
nt as i,
|
|
717
|
-
j,
|
|
718
|
-
it as k
|
|
719
|
-
};
|