@fullstackunicorn/webapp 0.0.0-stage → 1.0.0
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/imports/animated/Button.js +66 -0
- package/imports/animated/Crossfader.js +32 -0
- package/imports/animated/Fader.js +46 -0
- package/imports/animated/HoverCard.js +31 -0
- package/imports/animated/Layout.js +68 -0
- package/imports/animated/Layout.use.js +33 -0
- package/imports/animated/Layout.vars.js +20 -0
- package/imports/animated/Placeholder.js +4 -0
- package/imports/animated/Root.js +24 -0
- package/imports/animated/placeholder.css +12 -0
- package/imports/app.js +16 -0
- package/imports/cache.js +119 -0
- package/imports/client.js +272 -0
- package/imports/core/Ambient.js +9 -0
- package/imports/core/Ambient.pod.js +29 -0
- package/imports/core/Backdrop.js +21 -0
- package/imports/core/Background.js +21 -0
- package/imports/core/Background.pod.js +20 -0
- package/imports/core/Glass.js +12 -0
- package/imports/core/Glass.pod.js +31 -0
- package/imports/core/Href.js +22 -0
- package/imports/core/Iframe.js +13 -0
- package/imports/core/Img.js +135 -0
- package/imports/core/Img.pod.js +71 -0
- package/imports/core/InputFile.js +26 -0
- package/imports/core/InputTextItem.js +23 -0
- package/imports/core/InputTextarea.js +23 -0
- package/imports/core/InputTextline.js +23 -0
- package/imports/core/Json.js +19 -0
- package/imports/core/LegalDocument.js +13 -0
- package/imports/core/Link.js +111 -0
- package/imports/core/List.js +18 -0
- package/imports/core/Main.js +7 -0
- package/imports/core/Pressable.js +17 -0
- package/imports/core/Raised.js +13 -0
- package/imports/core/Raised.pod.js +20 -0
- package/imports/core/Rich.js +34 -0
- package/imports/core/Scrollable.js +41 -0
- package/imports/core/Svg.js +23 -0
- package/imports/core/Svg.pod.js +24 -0
- package/imports/core/Text.js +131 -0
- package/imports/core/View.js +13 -0
- package/imports/core/Viewport.js +29 -0
- package/imports/core/legal.css +16 -0
- package/imports/core/prose.css +16 -0
- package/imports/device.js +48 -0
- package/imports/fonts/tools.js +66 -0
- package/imports/fonts/use.js +56 -0
- package/imports/head/Head.js +29 -0
- package/imports/head/Metadata.js +25 -0
- package/imports/head/Page.js +8 -0
- package/imports/layout.js +28 -0
- package/imports/router.js +23 -0
- package/imports/scroll/@use.js +85 -0
- package/imports/scroll/scroll.js +33 -0
- package/imports/service.js +27 -0
- package/imports/serviceWorker.js +8 -0
- package/imports/storage.js +61 -0
- package/imports/use.js +146 -0
- package/imports/visibility.js +18 -0
- package/index.dep.js +44 -0
- package/index.js +58 -0
- package/load/Load.js +60 -0
- package/load/engine.js +107 -0
- package/load/priority.js +41 -0
- package/load/requests.js +40 -0
- package/load/resources.js +109 -0
- package/load/use.js +19 -0
- package/native/dependencies.json +5 -0
- package/native/imports/animated/Button.js +65 -0
- package/native/imports/animated/Crossfader.js +51 -0
- package/native/imports/animated/Fader.js +50 -0
- package/native/imports/animated/HoverCard.js +46 -0
- package/native/imports/animated/Layout.js +75 -0
- package/native/imports/animated/Layout.use.js +33 -0
- package/native/imports/animated/Layout.vars.js +20 -0
- package/native/imports/animated/Placeholder.js +26 -0
- package/native/imports/animated/Root.js +29 -0
- package/native/imports/app.js +1 -0
- package/native/imports/cache.js +124 -0
- package/native/imports/client.js +265 -0
- package/native/imports/core/Ambient.js +9 -0
- package/native/imports/core/Ambient.pod.js +13 -0
- package/native/imports/core/Backdrop.js +26 -0
- package/native/imports/core/Background.js +20 -0
- package/native/imports/core/Background.pod.js +15 -0
- package/native/imports/core/Glass.js +12 -0
- package/native/imports/core/Glass.pod.js +9 -0
- package/native/imports/core/Href.js +22 -0
- package/native/imports/core/Iframe.js +22 -0
- package/native/imports/core/Img.js +30 -0
- package/native/imports/core/Img.pod.js +58 -0
- package/native/imports/core/InputCheckbox.js +16 -0
- package/native/imports/core/InputFile.js +20 -0
- package/native/imports/core/InputTextItem.js +22 -0
- package/native/imports/core/InputTextarea.js +29 -0
- package/native/imports/core/InputTextline.js +41 -0
- package/native/imports/core/Json.js +22 -0
- package/native/imports/core/LegalDocument.js +32 -0
- package/native/imports/core/Link.js +53 -0
- package/native/imports/core/List.js +19 -0
- package/native/imports/core/Main.js +9 -0
- package/native/imports/core/Pressable.js +20 -0
- package/native/imports/core/Raised.js +13 -0
- package/native/imports/core/Raised.pod.js +12 -0
- package/native/imports/core/Rich.js +43 -0
- package/native/imports/core/Scrollable.js +81 -0
- package/native/imports/core/Svg.js +24 -0
- package/native/imports/core/Svg.pod.js +30 -0
- package/native/imports/core/Text.js +160 -0
- package/native/imports/core/View.js +25 -0
- package/native/imports/core/Viewport.js +22 -0
- package/native/imports/device.js +59 -0
- package/native/imports/fonts/tools.js +65 -0
- package/native/imports/fonts/use.js +51 -0
- package/native/imports/head/Head.js +2 -0
- package/native/imports/head/Metadata.js +2 -0
- package/native/imports/head/Page.js +2 -0
- package/native/imports/layout.js +28 -0
- package/native/imports/npm.js +33 -0
- package/native/imports/router.js +29 -0
- package/native/imports/scroll/@use.js +76 -0
- package/native/imports/scroll/scroll.js +32 -0
- package/native/imports/service.js +19 -0
- package/native/imports/serviceWorker.js +1 -0
- package/native/imports/storage.js +58 -0
- package/native/imports/use.js +100 -0
- package/native/imports/visibility.js +13 -0
- package/native/index.dep.js +41 -0
- package/native/index.js +53 -0
- package/package.json +75 -5
- package/package.md +9 -0
- package/README.md +0 -3
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useState, useEffect, useRef } from '#dep'
|
|
2
|
+
import { useStyle } from '#@/style/@use.js'
|
|
3
|
+
|
|
4
|
+
export const ControlButton = ({ onPress = () => { }, classes = [], children }) => {
|
|
5
|
+
|
|
6
|
+
const { s, c, f, t, F, B, S, I, H } = useStyle()
|
|
7
|
+
|
|
8
|
+
const [isPressed, setIsPressed] = useState(false)
|
|
9
|
+
const timeoutRef = useRef(null)
|
|
10
|
+
|
|
11
|
+
const handlePress = () => {
|
|
12
|
+
|
|
13
|
+
if (isPressed) return
|
|
14
|
+
|
|
15
|
+
setIsPressed(true)
|
|
16
|
+
onPress?.()
|
|
17
|
+
|
|
18
|
+
if (timeoutRef.current) {
|
|
19
|
+
clearTimeout(timeoutRef.current)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
timeoutRef.current = setTimeout(() => {
|
|
23
|
+
setIsPressed(false)
|
|
24
|
+
timeoutRef.current = null
|
|
25
|
+
}, 180)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const containerStyle = {
|
|
29
|
+
transform: isPressed ? 'scale(0.92)' : 'scale(1)',
|
|
30
|
+
opacity: isPressed ? 0.75 : 1,
|
|
31
|
+
transition: 'all 180ms cubic-bezier(0.34, 1.56, 0.64, 1)',
|
|
32
|
+
borderRadius: '50%',
|
|
33
|
+
display: 'flex',
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
cursor: 'pointer',
|
|
37
|
+
userSelect: 'none',
|
|
38
|
+
touchAction: 'manipulation'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const iconStyle = {
|
|
42
|
+
transform: isPressed ? 'scale(1.08)' : 'scale(1)',
|
|
43
|
+
transition: 'transform 180ms ease-out',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
return () => {
|
|
48
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current)
|
|
49
|
+
}
|
|
50
|
+
}, [])
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
onClick={handlePress}
|
|
55
|
+
onMouseDown={() => setIsPressed(true)}
|
|
56
|
+
onMouseUp={() => setIsPressed(false)}
|
|
57
|
+
onMouseLeave={() => setIsPressed(false)}
|
|
58
|
+
style={containerStyle}
|
|
59
|
+
className={[...classes, s.positionRelative].join(' ')}
|
|
60
|
+
>
|
|
61
|
+
<div className={[...classes, s.positionRelative].join(' ')} style={iconStyle}>
|
|
62
|
+
{children}
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useRef, useEffect } from '#dep'
|
|
2
|
+
import { useStyle } from '#@/style/@use.js'
|
|
3
|
+
import { useGetIsFrozen } from '#@/base/layout/menus/@use.js'
|
|
4
|
+
|
|
5
|
+
export const Crossfader = ({ isActive, children, transitionMs = 600, instantMount = false }) => {
|
|
6
|
+
|
|
7
|
+
const isFrozen = useGetIsFrozen()
|
|
8
|
+
const isFirstRender = useRef(true)
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
isFirstRender.current = false
|
|
12
|
+
}, [])
|
|
13
|
+
|
|
14
|
+
const { s, c, f, t, F, B, S, I, H } = useStyle()
|
|
15
|
+
|
|
16
|
+
S.box = [s.positionAbsolute, s.XY100p, s.noSelect]
|
|
17
|
+
|
|
18
|
+
I.box = {
|
|
19
|
+
width: '100%',
|
|
20
|
+
height: '100%',
|
|
21
|
+
opacity: isActive ? 1 : 0,
|
|
22
|
+
transition: isFrozen || (instantMount && isFirstRender.current) ? 'none' : `opacity ${transitionMs}ms ease-in-out`,
|
|
23
|
+
zIndex: isActive ? 2 : 1,
|
|
24
|
+
pointerEvents: isActive ? 'auto' : 'none'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className={S.box.join(' ')} style={I.box}>
|
|
29
|
+
{children}
|
|
30
|
+
</div>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from '#dep'
|
|
2
|
+
import { useUrl } from '#@/base/router/@use.js'
|
|
3
|
+
import { useGetIsFrozen } from '#@/base/layout/menus/@use.js'
|
|
4
|
+
|
|
5
|
+
const linkMs = 250
|
|
6
|
+
const menuMs = 300
|
|
7
|
+
|
|
8
|
+
const FaderInner = ({ classes = [], inline = {}, children, wasFrozen }) => {
|
|
9
|
+
|
|
10
|
+
const [visible, setVisible] = useState(false)
|
|
11
|
+
const ms = wasFrozen ? menuMs : linkMs
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const r1 = requestAnimationFrame(() => {
|
|
15
|
+
const r2 = requestAnimationFrame(() => setVisible(true))
|
|
16
|
+
return () => cancelAnimationFrame(r2)
|
|
17
|
+
})
|
|
18
|
+
return () => cancelAnimationFrame(r1)
|
|
19
|
+
}, [])
|
|
20
|
+
|
|
21
|
+
const style = {
|
|
22
|
+
...inline,
|
|
23
|
+
transition: `opacity ${ms}ms ease-in-out`,
|
|
24
|
+
opacity: visible ? 1 : 0,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className={classes.join(' ')} style={style}>
|
|
29
|
+
{children}
|
|
30
|
+
</div>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const Fader = ({ classes = [], inline = {}, children }) => {
|
|
35
|
+
|
|
36
|
+
const { url } = useUrl()
|
|
37
|
+
const isFrozen = useGetIsFrozen()
|
|
38
|
+
const frozenRef = useRef(isFrozen)
|
|
39
|
+
frozenRef.current = isFrozen
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<FaderInner key={url} classes={classes} inline={inline} wasFrozen={frozenRef.current}>
|
|
43
|
+
{children}
|
|
44
|
+
</FaderInner>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useState } from '#dep'
|
|
2
|
+
import { useStyle } from '#@/style/@use.js'
|
|
3
|
+
|
|
4
|
+
export const HoverCard = ({ children, classes = [] }) => {
|
|
5
|
+
|
|
6
|
+
const { s, c, f, t, F, B, S, I, H } = useStyle()
|
|
7
|
+
|
|
8
|
+
const [isHover, setIsHover] = useState(false)
|
|
9
|
+
|
|
10
|
+
S.box = [s.positionRelative, s.radius24, s.overflowHidden, ...classes]
|
|
11
|
+
|
|
12
|
+
I.box = {
|
|
13
|
+
transition: 'transform 240ms cubic-bezier(0.2, 0, 0, 1), box-shadow 240ms cubic-bezier(0.2, 0, 0, 1)',
|
|
14
|
+
boxShadow: isHover
|
|
15
|
+
? '0 6px 8px rgba(0, 0, 0, 0.12)'
|
|
16
|
+
: '0 2px 4px rgba(0, 0, 0, 0.06)',
|
|
17
|
+
transform: isHover ? 'translateY(-2px)' : 'translateY(0)',
|
|
18
|
+
willChange: 'transform, box-shadow',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div
|
|
23
|
+
className={S.box.join(' ')}
|
|
24
|
+
style={I.box}
|
|
25
|
+
onMouseEnter={() => setIsHover(true)}
|
|
26
|
+
onMouseLeave={() => setIsHover(false)}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useState, useEffect } from '#dep'
|
|
2
|
+
import { useStyle } from '#@/style/@use.js'
|
|
3
|
+
import { useGetIsSideTwoOn, useGetIsSideTwoExternal } from '#@/base/layout/sideTwo/@use.js'
|
|
4
|
+
import { useGetLanguage } from '#@/base/language/@use.js'
|
|
5
|
+
import { useAnimationSidebarExternal } from '#imports/animated/Layout.use.js'
|
|
6
|
+
|
|
7
|
+
export const SidebarExternal = ({ classes = [], inline = {}, children, isSidebarOne }) => {
|
|
8
|
+
|
|
9
|
+
const language = useGetLanguage()
|
|
10
|
+
const { duration, sidebarTwo } = useAnimationSidebarExternal()
|
|
11
|
+
|
|
12
|
+
const sidebar = sidebarTwo
|
|
13
|
+
const animated = isSidebarOne
|
|
14
|
+
? {}
|
|
15
|
+
: (language.isRTL ? { marginLeft: sidebar } : { marginRight: sidebar })
|
|
16
|
+
|
|
17
|
+
const style = { ...inline, ...animated, transition: `all ${duration * 0.96}ms ease` }
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div className={classes.join(' ')} style={style}>
|
|
21
|
+
{children}
|
|
22
|
+
</div>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Overlay = ({ classes = [], inline = {}, children, isClosed = true, duration = 250 }) => {
|
|
27
|
+
|
|
28
|
+
const { s, c, f, t, F, B, S, I, H } = useStyle()
|
|
29
|
+
|
|
30
|
+
const [isOff, setIsOff] = useState(true)
|
|
31
|
+
|
|
32
|
+
const style = { ...inline, transition: `all ${duration * 0.96}ms ease` }
|
|
33
|
+
|
|
34
|
+
const className = [...classes, isOff ? c.base_NN_B750_00 : c.base_NN_B750_40]
|
|
35
|
+
|
|
36
|
+
useEffect(() => setIsOff(isClosed), [isClosed])
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div className={className.join(' ')} style={{ ...style, ...inline }}>
|
|
40
|
+
{children}
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const Layout = ({ classes = [], inline = {}, children }) => {
|
|
46
|
+
|
|
47
|
+
const language = useGetLanguage()
|
|
48
|
+
|
|
49
|
+
const isSideTwoOn = useGetIsSideTwoOn()
|
|
50
|
+
const isSideTwoExternal = useGetIsSideTwoExternal()
|
|
51
|
+
|
|
52
|
+
const { duration, sideTwo } = useAnimationSidebarExternal()
|
|
53
|
+
|
|
54
|
+
let animated = {}
|
|
55
|
+
|
|
56
|
+
if (isSideTwoOn && isSideTwoExternal) {
|
|
57
|
+
animated = language.isRTL ? { marginRight: -sideTwo } : { marginLeft: sideTwo }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const style = { ...inline, ...animated, transition: `all ${duration * 0.96}ms ease` }
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div className={classes.join(' ')} style={style}>
|
|
64
|
+
{children}
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo } from '#dep'
|
|
2
|
+
import { vars } from '#imports/animated/Layout.vars.js'
|
|
3
|
+
import { useGetIsSideTwoClosed, useGetIsSideTwoExternal } from '#@/base/layout/sideTwo/@use.js'
|
|
4
|
+
|
|
5
|
+
export const useAnimationSidebarExternal = () => {
|
|
6
|
+
|
|
7
|
+
const { duration } = vars
|
|
8
|
+
const { sidebarFalse, sidebarTrue, sideTwoFalse, sideTwoTrue } = vars.external
|
|
9
|
+
|
|
10
|
+
const isSideTwoExternal = useGetIsSideTwoExternal()
|
|
11
|
+
const isSideTwoClosed = useGetIsSideTwoClosed()
|
|
12
|
+
|
|
13
|
+
const sideTwoVisible = isSideTwoExternal && !isSideTwoClosed
|
|
14
|
+
|
|
15
|
+
const sidebarTwoTarget = sideTwoVisible ? sidebarTrue : sidebarFalse
|
|
16
|
+
const sideTwoShiftTarget = sideTwoVisible ? sideTwoTrue : sideTwoFalse
|
|
17
|
+
|
|
18
|
+
const [sidebarTwo, setSidebarTwo] = useState(sidebarFalse)
|
|
19
|
+
const [sideTwo, setSideTwo] = useState(sideTwoFalse)
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
setSidebarTwo(sidebarTwoTarget)
|
|
23
|
+
}, [sidebarTwoTarget])
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
setSideTwo(sideTwoShiftTarget)
|
|
27
|
+
}, [sideTwoShiftTarget])
|
|
28
|
+
|
|
29
|
+
return useMemo(
|
|
30
|
+
() => ({ duration, sidebarTwo, sideTwo }),
|
|
31
|
+
[duration, sidebarTwo, sideTwo]
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const vars = {}
|
|
2
|
+
|
|
3
|
+
vars.duration = 150
|
|
4
|
+
vars.modalDuration = 250
|
|
5
|
+
|
|
6
|
+
vars.internal = {}
|
|
7
|
+
vars.internal.sidebarFalse = -328
|
|
8
|
+
vars.internal.sidebarTrue = 4
|
|
9
|
+
vars.internal.wingFalse = 0
|
|
10
|
+
vars.internal.wingTrue = 324
|
|
11
|
+
|
|
12
|
+
vars.external = {}
|
|
13
|
+
vars.external.sidebarFalse = -328
|
|
14
|
+
vars.external.sidebarTrue = 0
|
|
15
|
+
vars.external.sideOneFalse = 0
|
|
16
|
+
vars.external.sideOneTrue = 320
|
|
17
|
+
vars.external.sideTwoFalse = 0
|
|
18
|
+
vars.external.sideTwoTrue = -320
|
|
19
|
+
|
|
20
|
+
export { vars }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState, useEffect } from '#dep'
|
|
2
|
+
import { Viewport } from '#imports/core/Viewport.js'
|
|
3
|
+
|
|
4
|
+
export const Root = ({ children, isLoaded, immediate = false }) => {
|
|
5
|
+
|
|
6
|
+
const [isOff, setIsOff] = useState(true)
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!isLoaded || immediate) return
|
|
10
|
+
const timer = setTimeout(() => { setIsOff(false)}, 100)
|
|
11
|
+
return () => clearTimeout(timer)
|
|
12
|
+
}, [isLoaded, immediate])
|
|
13
|
+
|
|
14
|
+
const style = {
|
|
15
|
+
transition: immediate ? 'none' : 'opacity 0.4s ease-in-out',
|
|
16
|
+
opacity: immediate || !isOff ? 1 : 0,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Viewport inline={style}>
|
|
21
|
+
{children}
|
|
22
|
+
</Viewport>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
.initial-placeholder {
|
|
2
|
+
animation: initial-pulse 1.2s ease-in-out infinite;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
@keyframes initial-pulse {
|
|
6
|
+
0%, 100% { opacity: 0.4; }
|
|
7
|
+
50% { opacity: 1; }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@media (prefers-reduced-motion: reduce) {
|
|
11
|
+
.initial-placeholder { animation: none; opacity: 0.6; }
|
|
12
|
+
}
|
package/imports/app.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import '#@/style/@use.scss'
|
|
2
|
+
import { HelmetProvider } from '#dep'
|
|
3
|
+
import { ReactDOM } from '#dep'
|
|
4
|
+
import { RouterProvider } from '#imports/router.js'
|
|
5
|
+
import { Loader } from '#@/base/loader/Loader.js'
|
|
6
|
+
|
|
7
|
+
export const mount = () => {
|
|
8
|
+
const root = ReactDOM.createRoot(document.getElementById('root'))
|
|
9
|
+
root.render(
|
|
10
|
+
<HelmetProvider>
|
|
11
|
+
<RouterProvider>
|
|
12
|
+
<Loader />
|
|
13
|
+
</RouterProvider>
|
|
14
|
+
</HelmetProvider>
|
|
15
|
+
)
|
|
16
|
+
}
|
package/imports/cache.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { get, set, entries } from '#dep'
|
|
2
|
+
|
|
3
|
+
class Cache {
|
|
4
|
+
|
|
5
|
+
constructor() {
|
|
6
|
+
this.cachePreload = 'cache-preload'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
versions = new Map()
|
|
10
|
+
initialized = false
|
|
11
|
+
initialization = null
|
|
12
|
+
generation = 0
|
|
13
|
+
commits = new Map()
|
|
14
|
+
|
|
15
|
+
initialize = () => {
|
|
16
|
+
if (!this.initialization) this.initialization = entries().then(values => {
|
|
17
|
+
for (const [key, value] of values) if (typeof key === 'string' && key.startsWith('version:') && value) this.versions.set(key.slice(8), value)
|
|
18
|
+
this.initialized = true
|
|
19
|
+
}).catch(error => { this.initialization = null; throw error })
|
|
20
|
+
return this.initialization
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
version = key => this.initialized ? this.versions.get(key) : undefined
|
|
24
|
+
|
|
25
|
+
commit = (key, work) => {
|
|
26
|
+
const previous = this.commits.get(key) || Promise.resolve()
|
|
27
|
+
const current = previous.catch(() => {}).then(work)
|
|
28
|
+
this.commits.set(key, current)
|
|
29
|
+
return current.finally(() => { if (this.commits.get(key) === current) this.commits.delete(key) })
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
todayUTC = () => new Date().toISOString().slice(0, 10)
|
|
33
|
+
|
|
34
|
+
setPreload = async key => {
|
|
35
|
+
const store = await this.open(this.cachePreload)
|
|
36
|
+
const request = new Request(`preload:${key}`)
|
|
37
|
+
const response = new Response(this.todayUTC(), { headers: { 'Content-Type': 'text/plain' } })
|
|
38
|
+
await store.put(request, response)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
isPreload = async key => {
|
|
42
|
+
const store = await this.open(this.cachePreload)
|
|
43
|
+
const response = await store.match(`preload:${key}`)
|
|
44
|
+
if (!response) return true
|
|
45
|
+
const lastDay = (await response.text()).trim()
|
|
46
|
+
return lastDay < this.todayUTC()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
open = async (name) => await caches.open(name)
|
|
50
|
+
|
|
51
|
+
get = async (cache, key, isBlob) => {
|
|
52
|
+
const match = await cache.match(key)
|
|
53
|
+
if (!match) return null
|
|
54
|
+
return isBlob ? await match.blob() : await match.json()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
set = async (cache, key, value, isBlob, metadata = {}) => {
|
|
58
|
+
|
|
59
|
+
const headers = { headers: {'Content-Type': value?.type || 'application/octet-stream', 'X-Cache-Version': metadata.version || ''}}
|
|
60
|
+
const headersJson = { headers: { 'Content-Type': 'application/json' } }
|
|
61
|
+
|
|
62
|
+
const response = isBlob
|
|
63
|
+
? new Response(value, headers)
|
|
64
|
+
: new Response(JSON.stringify(value), headersJson)
|
|
65
|
+
|
|
66
|
+
await cache.put(key, response)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getMeta = async (key) => {
|
|
70
|
+
const etag = await get(`etag:${key}`)
|
|
71
|
+
const timestamp = (await get(`timestamp:${key}`)) || 0
|
|
72
|
+
return { etag, timestamp }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
setMeta = async (key, etag, version) => {
|
|
76
|
+
await this.initialize()
|
|
77
|
+
if (version !== undefined) {
|
|
78
|
+
await set(`version:${key}`, version)
|
|
79
|
+
if (version) this.versions.set(key, version)
|
|
80
|
+
else this.versions.delete(key)
|
|
81
|
+
}
|
|
82
|
+
if (etag) await set(`etag:${key}`, etag)
|
|
83
|
+
await set(`timestamp:${key}`, Date.now())
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
remove = async (cache, key) => {
|
|
87
|
+
await cache.delete(key)
|
|
88
|
+
await set(`etag:${key}`, undefined)
|
|
89
|
+
await set(`timestamp:${key}`, undefined)
|
|
90
|
+
await this.setMeta(key, undefined, null)
|
|
91
|
+
this.generation += 1
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
clear = async name => {
|
|
95
|
+
this.generation += 1
|
|
96
|
+
await this.initialize()
|
|
97
|
+
const store = await this.open(name)
|
|
98
|
+
for (const request of await store.keys()) await this.remove(store, request.url)
|
|
99
|
+
this.generation += 1
|
|
100
|
+
return caches.delete(name)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
preBlob = (data) => {
|
|
104
|
+
if (!data) return null
|
|
105
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data)
|
|
106
|
+
if (ArrayBuffer.isView(data)) return new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
|
|
107
|
+
try { return new Uint8Array(data) } catch { return null }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getBlob = (arrayBuffer, type) => {
|
|
111
|
+
const u8 = this.preBlob(arrayBuffer)
|
|
112
|
+
if (!u8) return null
|
|
113
|
+
const safeType = (type || 'application/octet-stream').split(';')[0].trim()
|
|
114
|
+
return new Blob([u8], { type: safeType })
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export const cache = new Cache()
|