@vinena/knobs 0.5.1 → 0.5.3
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/CHANGELOG.md +29 -0
- package/README.md +7 -0
- package/dist/early.global.js +6 -6
- package/dist/{elementsview-tf4qzmtw.js → elementsview-1wsxcdtj.js} +4 -4
- package/dist/{elementsview-jnkbhzkj.js → elementsview-3kv34jfx.js} +4 -4
- package/dist/engine/browserdraw.d.ts +29 -2
- package/dist/engine/browserkit.d.ts +20 -1
- package/dist/engine/browserui.d.ts +162 -22
- package/dist/engine/devices.d.ts +3 -2
- package/dist/engine/devicon.d.ts +59 -0
- package/dist/engine/fit.d.ts +4 -3
- package/dist/engine/foldflip.d.ts +40 -0
- package/dist/engine/frames.d.ts +1 -0
- package/dist/engine/identity.d.ts +12 -5
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/mock.d.ts +14 -0
- package/dist/engine/mockdata.d.ts +5 -1
- package/dist/engine/morphrun.d.ts +4 -0
- package/dist/engine/native.d.ts +31 -3
- package/dist/engine/notice.d.ts +1 -2
- package/dist/engine/pageshot.d.ts +5 -2
- package/dist/engine/safaridraw.d.ts +162 -10
- package/dist/engine/screen.d.ts +24 -0
- package/dist/engine/store.d.ts +2 -1
- package/dist/engine/tabicon.d.ts +43 -0
- package/dist/engine/toplayer.d.ts +62 -0
- package/dist/engine/touchpointer.d.ts +0 -21
- package/dist/engine/underbar.d.ts +61 -0
- package/dist/engine/width.d.ts +3 -0
- package/dist/{framekit-3n7p79ht.js → framekit-cjz0e4y8.js} +2492 -1587
- package/dist/{framekit-g96t6nmq.js → framekit-yk1jxjv7.js} +2492 -1587
- package/dist/host.d.ts +51 -0
- package/dist/{index-33x9hxe3.js → index-6wbgqkdz.js} +626 -189
- package/dist/{index-2d6wvs8h.js → index-9jhatmky.js} +4 -4
- package/dist/{index-zvze25nf.js → index-begsqdm0.js} +1 -1
- package/dist/{index-peh33xjv.js → index-j1h13ahg.js} +1 -1
- package/dist/{index-5baxvd3v.js → index-p57fdttx.js} +307 -129
- package/dist/{index-dvr4x91q.js → index-prjpx67p.js} +20 -8
- package/dist/{index-d0cjxjsm.js → index-q73py563.js} +1 -1
- package/dist/{index-ke6v7919.js → index-sn2y6j09.js} +20 -8
- package/dist/{index-0casarhy.js → index-vgfn2n1h.js} +1 -1
- package/dist/{index-k015tb6c.js → index-zt3rheck.js} +4 -4
- package/dist/index.d.ts +26 -1
- package/dist/index.global.js +299 -176
- package/dist/index.js +424 -124
- package/dist/instance.d.ts +23 -4
- package/dist/{react-qv0nykcv.js → react-3rhdj2k1.js} +623 -186
- package/dist/{react-carf84xv.js → react-6tss0r9f.js} +307 -129
- package/dist/{react-eygws6cx.js → react-7vjfsh40.js} +4 -4
- package/dist/{react-71a9ypex.js → react-806qmkyz.js} +4 -4
- package/dist/{react-65tgdbs8.js → react-gefkdkdz.js} +1 -1
- package/dist/{react-sq9pkw4k.js → react-mmq2zya3.js} +1 -1
- package/dist/{react-xxfpfddf.js → react-qfpg79hs.js} +1 -1
- package/dist/{react-pdvseef0.js → react-qgz9afa2.js} +1 -1
- package/dist/react.js +420 -123
- package/dist/{storageview-sb23henh.js → storageview-7cv0vpdm.js} +4 -4
- package/dist/{storageview-vf8v8q8j.js → storageview-dyhpgt8f.js} +4 -4
- package/dist/types.d.ts +14 -0
- package/dist/ui/footer.d.ts +9 -2
- package/dist/ui/panel.d.ts +16 -2
- package/dist/ui/settings.d.ts +25 -1
- package/dist/version.d.ts +2 -0
- package/package.json +3 -2
- package/skills/devknobs/SKILL.md +1 -1
- package/dist/engine/endroom.d.ts +0 -21
|
@@ -29,12 +29,12 @@ import {
|
|
|
29
29
|
turnOf,
|
|
30
30
|
turnedPose,
|
|
31
31
|
windowRect
|
|
32
|
-
} from "./react-
|
|
32
|
+
} from "./react-qfpg79hs.js";
|
|
33
33
|
import {
|
|
34
34
|
hush,
|
|
35
35
|
hushOnce,
|
|
36
36
|
quietFetch
|
|
37
|
-
} from "./react-
|
|
37
|
+
} from "./react-gefkdkdz.js";
|
|
38
38
|
import {
|
|
39
39
|
copyText
|
|
40
40
|
} from "./react-h9w04skh.js";
|
|
@@ -49,13 +49,16 @@ import {
|
|
|
49
49
|
MAT_COLOR_NAMES,
|
|
50
50
|
SAFARI_TEXT,
|
|
51
51
|
UNFRAMED,
|
|
52
|
+
ZOOM_MAX,
|
|
52
53
|
ZOOM_PRESETS,
|
|
53
54
|
Z_INDEX,
|
|
54
55
|
__export,
|
|
55
56
|
addStyle,
|
|
56
57
|
adoptEarly,
|
|
58
|
+
alphaAt,
|
|
57
59
|
anchorScroll,
|
|
58
60
|
apply3 as apply,
|
|
61
|
+
apply4 as apply2,
|
|
59
62
|
barsOf,
|
|
60
63
|
barsStep,
|
|
61
64
|
baseMatchMedia,
|
|
@@ -64,11 +67,9 @@ import {
|
|
|
64
67
|
coarse,
|
|
65
68
|
deviceOf,
|
|
66
69
|
dropEarly,
|
|
67
|
-
endRoom,
|
|
68
70
|
ensureStyle,
|
|
69
71
|
equip,
|
|
70
72
|
equip1 as equip2,
|
|
71
|
-
findStyle,
|
|
72
73
|
follow,
|
|
73
74
|
formId,
|
|
74
75
|
formOf,
|
|
@@ -76,6 +77,7 @@ import {
|
|
|
76
77
|
handing,
|
|
77
78
|
handsSchemeDown,
|
|
78
79
|
hasTouch,
|
|
80
|
+
islandOf,
|
|
79
81
|
keep,
|
|
80
82
|
keepDrawing,
|
|
81
83
|
layoutOf,
|
|
@@ -89,6 +91,7 @@ import {
|
|
|
89
91
|
openOf,
|
|
90
92
|
ownReload,
|
|
91
93
|
parseColor,
|
|
94
|
+
parseHex,
|
|
92
95
|
percent,
|
|
93
96
|
placeIn,
|
|
94
97
|
plainFrame,
|
|
@@ -98,7 +101,10 @@ import {
|
|
|
98
101
|
readMessage,
|
|
99
102
|
readSnapshot,
|
|
100
103
|
removeStyle,
|
|
104
|
+
round,
|
|
105
|
+
runsUnderBars,
|
|
101
106
|
screenOf,
|
|
107
|
+
screenSizeOf,
|
|
102
108
|
settles,
|
|
103
109
|
snapshotKey,
|
|
104
110
|
stepZoom,
|
|
@@ -107,12 +113,13 @@ import {
|
|
|
107
113
|
styleNode,
|
|
108
114
|
turn,
|
|
109
115
|
turnRadius,
|
|
116
|
+
turnRect,
|
|
110
117
|
turnSides,
|
|
111
118
|
uaPreset,
|
|
112
119
|
userAgentOf,
|
|
113
120
|
viewportOf,
|
|
114
121
|
wheelZoom
|
|
115
|
-
} from "./react-
|
|
122
|
+
} from "./react-6tss0r9f.js";
|
|
116
123
|
|
|
117
124
|
// src/engine/width.ts
|
|
118
125
|
var exports_width = {};
|
|
@@ -124,6 +131,7 @@ __export(exports_width, {
|
|
|
124
131
|
origin: () => origin,
|
|
125
132
|
onZoom: () => onZoom,
|
|
126
133
|
onRefused: () => onRefused,
|
|
134
|
+
onLoader: () => onLoader,
|
|
127
135
|
onFramed: () => onFramed,
|
|
128
136
|
onExit: () => onExit,
|
|
129
137
|
label: () => label,
|
|
@@ -131,19 +139,20 @@ __export(exports_width, {
|
|
|
131
139
|
frameWindow: () => frameWindow,
|
|
132
140
|
foldDevice: () => foldDevice2,
|
|
133
141
|
fit: () => fit,
|
|
134
|
-
apply: () =>
|
|
142
|
+
apply: () => apply3,
|
|
135
143
|
STRIP: () => STRIP,
|
|
136
144
|
RIDE_SLOW: () => RIDE_SLOW,
|
|
137
|
-
FRAME_API_WAIT: () => FRAME_API_WAIT
|
|
145
|
+
FRAME_API_WAIT: () => FRAME_API_WAIT,
|
|
146
|
+
COVER_CAP: () => COVER_CAP
|
|
138
147
|
});
|
|
139
148
|
|
|
140
149
|
// src/engine/identity.ts
|
|
141
150
|
function identityOf(state) {
|
|
142
151
|
const agent = uaPreset(state.ua.preset) ? state.ua.preset : userAgentOf(state.ua);
|
|
143
|
-
return { agent, touch: hasTouch(state.device), dpr: state.dpr };
|
|
152
|
+
return { agent, touch: hasTouch(state.device), dpr: state.dpr, ...state.panel?.realPhone ? { served: true } : {} };
|
|
144
153
|
}
|
|
145
154
|
function stale(loaded, next) {
|
|
146
|
-
return loaded !== null && (loaded.agent !== next.agent || loaded.touch !== next.touch || loaded.dpr !== next.dpr);
|
|
155
|
+
return loaded !== null && (loaded.agent !== next.agent || loaded.touch !== next.touch || loaded.dpr !== next.dpr || (loaded.served ?? false) !== (next.served ?? false));
|
|
147
156
|
}
|
|
148
157
|
var PATCHED = Symbol.for("devknobs.identity");
|
|
149
158
|
function isIdentity(value) {
|
|
@@ -160,6 +169,7 @@ function patchWindow(view, state) {
|
|
|
160
169
|
const identity = identityOf(state);
|
|
161
170
|
Reflect.set(view, PATCHED, identity);
|
|
162
171
|
apply(state.ua, view);
|
|
172
|
+
apply2(screenSizeOf(state), view);
|
|
163
173
|
if (identity.touch) {
|
|
164
174
|
equip2(view, uaPreset(state.ua.preset) === undefined);
|
|
165
175
|
coarse(view);
|
|
@@ -2971,7 +2981,7 @@ var BEZELS = {
|
|
|
2971
2981
|
opening: [60, 72, 1260, 2736],
|
|
2972
2982
|
body: [6, 26, 1375, 2854],
|
|
2973
2983
|
cutout: [503.25, 133.05, 373.76, 107.91],
|
|
2974
|
-
radius:
|
|
2984
|
+
radius: 65
|
|
2975
2985
|
}
|
|
2976
2986
|
},
|
|
2977
2987
|
"iphone-17": {
|
|
@@ -3156,6 +3166,7 @@ function bezelMock(id, orientation) {
|
|
|
3156
3166
|
const own = orientation === "landscape" ? found.landscape : undefined;
|
|
3157
3167
|
const bezel = own ?? found.portrait;
|
|
3158
3168
|
const turned = orientation === "landscape" && !own;
|
|
3169
|
+
const clockwise = turned && device.clockwise === true;
|
|
3159
3170
|
const screen = turn(device, own ? "landscape" : "portrait");
|
|
3160
3171
|
const scale = density(screen, bezel);
|
|
3161
3172
|
const [x, y, w, h] = bezel.opening;
|
|
@@ -3172,22 +3183,26 @@ function bezelMock(id, orientation) {
|
|
|
3172
3183
|
};
|
|
3173
3184
|
const width = (right - left) / scale;
|
|
3174
3185
|
const height = (bottom - top) / scale;
|
|
3175
|
-
const sides = turned ? turnSides(inset) : inset;
|
|
3186
|
+
const sides = turned ? turnSides(inset, clockwise) : inset;
|
|
3176
3187
|
const size = turned ? { width: height, height: width } : { width, height };
|
|
3188
|
+
const island = islandOf(id);
|
|
3189
|
+
const flat = island && round("sensor", { ...island, x: inset.left + island.x, y: inset.top + island.y });
|
|
3190
|
+
const parts = flat ? [turned ? turnRect(flat, width, height, clockwise) : flat] : [];
|
|
3177
3191
|
return {
|
|
3178
3192
|
...size,
|
|
3179
3193
|
inset: sides,
|
|
3180
3194
|
body: { x: 0, y: 0, ...size },
|
|
3181
|
-
screenRadius: turned ? turnRadius(bezel.radius) : bezel.radius,
|
|
3195
|
+
screenRadius: turned ? turnRadius(bezel.radius, clockwise) : bezel.radius,
|
|
3182
3196
|
bodyRadius: 0,
|
|
3183
|
-
parts
|
|
3197
|
+
parts,
|
|
3184
3198
|
image: {
|
|
3185
3199
|
file: bezel.file,
|
|
3186
3200
|
x: -left / scale,
|
|
3187
3201
|
y: -top / scale,
|
|
3188
3202
|
width: bezel.size[0] / scale,
|
|
3189
3203
|
height: bezel.size[1] / scale,
|
|
3190
|
-
turn: turned ? width : null
|
|
3204
|
+
turn: turned ? clockwise ? height : width : null,
|
|
3205
|
+
...clockwise ? { clockwise } : {}
|
|
3191
3206
|
}
|
|
3192
3207
|
};
|
|
3193
3208
|
}
|
|
@@ -3560,8 +3575,7 @@ var GLYPHS = {
|
|
|
3560
3575
|
bookmarks: () => [],
|
|
3561
3576
|
tabs: () => [],
|
|
3562
3577
|
reload: () => [],
|
|
3563
|
-
page: () => []
|
|
3564
|
-
more: () => []
|
|
3578
|
+
page: () => []
|
|
3565
3579
|
};
|
|
3566
3580
|
function box(className, rect) {
|
|
3567
3581
|
const node = el("div", className);
|
|
@@ -3647,32 +3661,8 @@ function buildChrome(full, mini, look) {
|
|
|
3647
3661
|
};
|
|
3648
3662
|
}
|
|
3649
3663
|
|
|
3650
|
-
// src/engine/endroom.ts
|
|
3651
|
-
var NAME = "endroom";
|
|
3652
|
-
var VARIABLE = "--devknobs-end-room";
|
|
3653
|
-
var CSS = `:root{${VARIABLE}:0px}html{margin-bottom:var(${VARIABLE})!important}`;
|
|
3654
|
-
function holder(style) {
|
|
3655
|
-
const rule = style.sheet?.cssRules[0];
|
|
3656
|
-
return rule?.style ?? null;
|
|
3657
|
-
}
|
|
3658
|
-
function give(doc, room) {
|
|
3659
|
-
const existing = findStyle(NAME, doc);
|
|
3660
|
-
const held = existing ? holder(existing) : null;
|
|
3661
|
-
const had = Number.parseFloat(held?.getPropertyValue(VARIABLE) ?? "") || 0;
|
|
3662
|
-
if (room <= 0) {
|
|
3663
|
-
existing?.remove();
|
|
3664
|
-
return had;
|
|
3665
|
-
}
|
|
3666
|
-
if (had === room)
|
|
3667
|
-
return had;
|
|
3668
|
-
const style = existing ?? ensureStyle(NAME, doc);
|
|
3669
|
-
if (!existing)
|
|
3670
|
-
style.textContent = CSS;
|
|
3671
|
-
holder(style)?.setProperty(VARIABLE, `${room}px`);
|
|
3672
|
-
return had;
|
|
3673
|
-
}
|
|
3674
|
-
|
|
3675
3664
|
// src/engine/safaridraw.ts
|
|
3665
|
+
var DOMAIN_WEIGHT = 500;
|
|
3676
3666
|
var SAFARI_CSS = `
|
|
3677
3667
|
.safari {
|
|
3678
3668
|
color: #000;
|
|
@@ -3694,27 +3684,37 @@ var SAFARI_CSS = `
|
|
|
3694
3684
|
}
|
|
3695
3685
|
.safari.dark { color: #f3f3f8; }
|
|
3696
3686
|
.safari .surface > *, .safari .side > *, .safari .field > * { position: absolute; }
|
|
3697
|
-
/* Glass over the page: a fill the page shows faintly through, blurred. */
|
|
3698
|
-
.safari .capsule, .safari .
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
}
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3687
|
+
/* Glass over the page: a fill in the tone of the page under it, which shows faintly through, blurred. */
|
|
3688
|
+
.safari .capsule, .safari .surface {
|
|
3689
|
+
-webkit-backdrop-filter: blur(10px);
|
|
3690
|
+
backdrop-filter: blur(10px);
|
|
3691
|
+
}
|
|
3692
|
+
.safari [data-tone="light"] { color: #000; }
|
|
3693
|
+
.safari [data-tone="dark"] { color: #fff; }
|
|
3694
|
+
/* Light glass: a thin darker ring outside (#c8c8c8 on white), a white highlight inside, a soft wide shadow. */
|
|
3695
|
+
.safari [data-rim="none"] {
|
|
3696
|
+
box-shadow:
|
|
3697
|
+
0 0 0 0.67px rgba(0, 0, 0, 0.215),
|
|
3698
|
+
inset 0 0 0 1px rgba(255, 255, 255, 0.6),
|
|
3699
|
+
0 6px 24px rgba(0, 0, 0, 0.065);
|
|
3700
|
+
}
|
|
3701
|
+
/* Glass in a page's hue: a lighter rim of its own color inside, iOS 27's darker ring outside. */
|
|
3702
|
+
.safari [data-rim="tint"] {
|
|
3703
|
+
box-shadow:
|
|
3704
|
+
0 0 0 0.67px rgba(0, 0, 0, 0.215),
|
|
3705
|
+
inset 0 0 0 1px rgba(255, 255, 255, 0.22),
|
|
3706
|
+
0 6px 24px rgba(0, 0, 0, 0.1);
|
|
3707
|
+
}
|
|
3708
|
+
/* Dark glass: a rim as bright at the bottom as at the top (#585858 fading to #2b2b2b on #222), the darker ring outside, and no shadow. */
|
|
3709
|
+
.safari [data-rim="highlight"] {
|
|
3710
|
+
box-shadow:
|
|
3711
|
+
0 0 0 0.67px rgba(0, 0, 0, 0.215),
|
|
3712
|
+
inset 0 0 0 1px rgba(255, 255, 255, 0.24),
|
|
3713
|
+
inset 0 0 1.5px 1.5px rgba(255, 255, 255, 0.04);
|
|
3714
|
+
}
|
|
3715
|
+
/* Bottom's field: toward #ddd in light (#fcfcfc to #f2f2f2, #888 to #a3a3a3), toward #1f1f1f in dark. */
|
|
3716
|
+
.safari .field { background: rgba(221, 221, 221, 0.32); }
|
|
3717
|
+
.safari [data-tone="dark"] .field { background: rgba(31, 31, 31, 0.73); }
|
|
3718
3718
|
.safari .glyph {
|
|
3719
3719
|
fill: none;
|
|
3720
3720
|
stroke: currentColor;
|
|
@@ -3722,13 +3722,13 @@ var SAFARI_CSS = `
|
|
|
3722
3722
|
stroke-linecap: round;
|
|
3723
3723
|
stroke-linejoin: round;
|
|
3724
3724
|
}
|
|
3725
|
-
.safari .glyph .solid { fill: currentColor; stroke: none; }
|
|
3726
3725
|
/* Reload and stop are a shade lighter than the other glyphs and thinner, as measured. */
|
|
3727
3726
|
.safari .glyph .reload { stroke-width: 1.6; }
|
|
3728
3727
|
.safari .glyph .stop { stroke-width: 1.82; }
|
|
3729
|
-
.safari
|
|
3730
|
-
.safari .glyph.
|
|
3731
|
-
|
|
3728
|
+
.safari .glyph .page { stroke-width: 2; }
|
|
3729
|
+
.safari [data-tone="light"] .glyph .reload, .safari [data-tone="light"] .glyph .stop { stroke: #191919; }
|
|
3730
|
+
/* A button that does nothing: its glyph at 30%, #babac7 on white glass, #58585b on dark. */
|
|
3731
|
+
.safari .glyph.off { stroke-opacity: 0.3; fill-opacity: 0.3; }
|
|
3732
3732
|
.safari .domain {
|
|
3733
3733
|
left: 50%;
|
|
3734
3734
|
white-space: nowrap;
|
|
@@ -3736,14 +3736,14 @@ var SAFARI_CSS = `
|
|
|
3736
3736
|
text-overflow: ellipsis;
|
|
3737
3737
|
text-align: center;
|
|
3738
3738
|
font-size: ${SAFARI_TEXT.field}px;
|
|
3739
|
-
font-weight:
|
|
3740
|
-
letter-spacing: -0.2px;
|
|
3739
|
+
font-weight: ${DOMAIN_WEIGHT};
|
|
3741
3740
|
transform: translate(-50%, -50%);
|
|
3742
3741
|
}
|
|
3743
|
-
.safari .time { font-weight: 600;
|
|
3742
|
+
.safari .time { font-weight: 600; transform: translate(-50%, -50%); }
|
|
3744
3743
|
.safari .status { fill: currentColor; }
|
|
3745
|
-
|
|
3746
|
-
.safari.
|
|
3744
|
+
/* The battery's uncharged rest: #b2b2b2 on white, #808080 on black. */
|
|
3745
|
+
.safari .status .rest { fill-opacity: 0.3; }
|
|
3746
|
+
.safari.dark .status .rest { fill-opacity: 0.5; }
|
|
3747
3747
|
/* One surface morphs: its box, corners and color, and the domain glides in it. */
|
|
3748
3748
|
.safari .surface {
|
|
3749
3749
|
overflow: hidden;
|
|
@@ -3756,7 +3756,10 @@ var SAFARI_CSS = `
|
|
|
3756
3756
|
background-color var(--main) ${MORPH.ease},
|
|
3757
3757
|
box-shadow var(--main) ${MORPH.ease};
|
|
3758
3758
|
}
|
|
3759
|
-
|
|
3759
|
+
/* A minimized Safari's wash under the status bar comes and goes with the bars. */
|
|
3760
|
+
.safari .scrim { left: 0; right: 0; opacity: 0; transition: opacity var(--main) ${MORPH.ease}; }
|
|
3761
|
+
.safari[data-state="min"] .scrim[data-on="true"] { opacity: 1; }
|
|
3762
|
+
.safari .domain {
|
|
3760
3763
|
transition:
|
|
3761
3764
|
top var(--main) ${MORPH.ease},
|
|
3762
3765
|
height var(--main) ${MORPH.ease},
|
|
@@ -3831,11 +3834,7 @@ var GLYPHS2 = {
|
|
|
3831
3834
|
path2("M6.66 0.92A6.59 6.59 0 1 1 2.93 -5.02", "reload"),
|
|
3832
3835
|
path2("M-0.15 -8.89L3.26 -5.33L-0.16 -1.93", "reload")
|
|
3833
3836
|
],
|
|
3834
|
-
page: () => [
|
|
3835
|
-
svgNode("rect", { x: -6.8, y: -8.1, width: 13.6, height: 8.6, rx: 2.4 }),
|
|
3836
|
-
path2("M-6.8 4.2H6.8M-6.8 8.1H2.6")
|
|
3837
|
-
],
|
|
3838
|
-
more: () => [-7.8, 0, 7.8].map((x) => svgNode("circle", { cx: x, cy: 0, r: 2, class: "solid" })),
|
|
3837
|
+
page: () => [path2("M-6.3 -5.1H8M-6.3 0H8M-6.3 5.1H3", "page")],
|
|
3839
3838
|
plus: () => [path2("M0 -8.5V8.5M-8.5 0H8.5")],
|
|
3840
3839
|
home: () => [],
|
|
3841
3840
|
tune: () => [],
|
|
@@ -3845,65 +3844,183 @@ var GLYPHS2 = {
|
|
|
3845
3844
|
function stopGlyph() {
|
|
3846
3845
|
return [path2("M-5.66 -5.54L5.88 6M5.88 -5.54L-5.66 6", "stop")];
|
|
3847
3846
|
}
|
|
3847
|
+
var STATUS_GLYPHS = {
|
|
3848
|
+
regular: {
|
|
3849
|
+
time: { size: 18, spacing: -0.09, drop: 0.33 },
|
|
3850
|
+
gap: 8.5,
|
|
3851
|
+
signal: { width: 3.33, pitch: 5.67, heights: [6.33, 8.67, 11, 13.67], radius: 1.1, drop: 7.67 },
|
|
3852
|
+
wifi: {
|
|
3853
|
+
width: 18.67,
|
|
3854
|
+
height: 13.67,
|
|
3855
|
+
bands: [0, 3.14, 6.09, 7.83, 10.78, 12.57],
|
|
3856
|
+
angle: 45.4,
|
|
3857
|
+
round: 1.1,
|
|
3858
|
+
drop: 7.33
|
|
3859
|
+
},
|
|
3860
|
+
battery: { width: 26.33, height: 13.67, radius: 4.67, gap: 0.67, cap: [2, 5], drop: -0.5 }
|
|
3861
|
+
},
|
|
3862
|
+
large: {
|
|
3863
|
+
time: { size: 19, spacing: -0.09, drop: 0.5 },
|
|
3864
|
+
gap: 8.67,
|
|
3865
|
+
signal: { width: 3.67, pitch: 6.11, heights: [7, 9.33, 12, 15], radius: 1.2, drop: 8.33 },
|
|
3866
|
+
wifi: {
|
|
3867
|
+
width: 20.33,
|
|
3868
|
+
height: 15,
|
|
3869
|
+
bands: [0, 3.45, 6.68, 8.59, 11.83, 13.79],
|
|
3870
|
+
angle: 45,
|
|
3871
|
+
round: 1.2,
|
|
3872
|
+
drop: 8
|
|
3873
|
+
},
|
|
3874
|
+
battery: { width: 29.33, height: 15, radius: 5, gap: 1, cap: [2, 5], drop: -0.5 }
|
|
3875
|
+
}
|
|
3876
|
+
};
|
|
3848
3877
|
function fan(from, to, angle) {
|
|
3849
3878
|
const rad = angle * Math.PI / 180;
|
|
3850
3879
|
const at = (r, side) => `${(side * r * Math.sin(rad)).toFixed(2)} ${(-r * Math.cos(rad)).toFixed(2)}`;
|
|
3851
3880
|
const inner = from > 0 ? `L${at(from, 1)}A${from} ${from} 0 0 0 ${at(from, -1)}Z` : "L0 0Z";
|
|
3852
3881
|
return `M${at(to, -1)}A${to} ${to} 0 0 1 ${at(to, 1)}${inner}`;
|
|
3853
3882
|
}
|
|
3854
|
-
function wifi(x,
|
|
3855
|
-
const
|
|
3856
|
-
|
|
3857
|
-
svg
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3883
|
+
function wifi(x, bottom, size) {
|
|
3884
|
+
const { width, height, bands, angle, round: round2 } = size;
|
|
3885
|
+
const viewBox = `${-width / 2} ${round2 / 2 - height} ${width} ${height}`;
|
|
3886
|
+
const svg = svgNode("svg", { class: "status", viewBox });
|
|
3887
|
+
place(svg, x, bottom - height, width, height);
|
|
3888
|
+
const stroke = { "stroke-linejoin": "round", stroke: "currentColor", "stroke-width": round2 };
|
|
3889
|
+
const pairs = [0, 2, 4].map((at) => fan(bands[at] ?? 0, bands[at + 1] ?? 0, angle));
|
|
3890
|
+
svg.append(...pairs.map((d) => svgNode("path", { d, ...stroke })));
|
|
3861
3891
|
return svg;
|
|
3862
3892
|
}
|
|
3863
|
-
function signal(x,
|
|
3864
|
-
const
|
|
3865
|
-
|
|
3866
|
-
|
|
3893
|
+
function signal(x, bottom, size) {
|
|
3894
|
+
const { width, pitch, heights, radius } = size;
|
|
3895
|
+
const tall = Math.max(...heights);
|
|
3896
|
+
const wide = pitch * (heights.length - 1) + width;
|
|
3897
|
+
const svg = svgNode("svg", { class: "status", viewBox: `0 0 ${wide} ${tall}` });
|
|
3898
|
+
place(svg, x, bottom - tall, wide, tall);
|
|
3899
|
+
svg.append(...heights.map((height, at) => svgNode("rect", { x: at * pitch, y: tall - height, width, height, rx: radius })));
|
|
3867
3900
|
return svg;
|
|
3868
3901
|
}
|
|
3869
|
-
function
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3902
|
+
function batteryWidth(size) {
|
|
3903
|
+
return size.width + size.gap + size.cap[0];
|
|
3904
|
+
}
|
|
3905
|
+
function chargedPath(width, height, radius, level) {
|
|
3906
|
+
const r = Math.min(radius, height / 2, width / 2);
|
|
3907
|
+
const x = Math.max(0, Math.min(width, level));
|
|
3908
|
+
const inset = (along) => r - Math.sqrt(Math.max(0, r * r - (r - along) ** 2));
|
|
3909
|
+
const f = (n) => Number(n.toFixed(3));
|
|
3910
|
+
if (x <= r) {
|
|
3911
|
+
const y2 = inset(x);
|
|
3912
|
+
return `M${f(x)} ${f(y2)}A${r} ${r} 0 0 0 0 ${r}V${f(height - r)}A${r} ${r} 0 0 0 ${f(x)} ${f(height - y2)}Z`;
|
|
3913
|
+
}
|
|
3914
|
+
const left = `H${r}A${r} ${r} 0 0 0 0 ${r}V${f(height - r)}A${r} ${r} 0 0 0 ${r} ${height}`;
|
|
3915
|
+
if (x < width - r)
|
|
3916
|
+
return `M${f(x)} 0${left}H${f(x)}Z`;
|
|
3917
|
+
const y = inset(width - x);
|
|
3918
|
+
return `M${f(x)} ${f(y)}A${r} ${r} 0 0 0 ${f(width - r)} 0${left}` + `H${f(width - r)}A${r} ${r} 0 0 0 ${f(x)} ${f(height - y)}Z`;
|
|
3919
|
+
}
|
|
3920
|
+
function batteryParts(size, charge) {
|
|
3921
|
+
const { width, height, radius, gap, cap } = size;
|
|
3922
|
+
const [capWidth, capHeight] = cap;
|
|
3923
|
+
return {
|
|
3924
|
+
body: { x: 0, y: 0, width, height, rx: radius },
|
|
3925
|
+
level: { d: chargedPath(width, height, radius, width * charge / 100) },
|
|
3926
|
+
cap: { x: width + gap, y: (height - capHeight) / 2, width: capWidth, height: capHeight }
|
|
3927
|
+
};
|
|
3928
|
+
}
|
|
3929
|
+
function battery(x, middle, size) {
|
|
3930
|
+
const wide = batteryWidth(size);
|
|
3931
|
+
const svg = svgNode("svg", { class: "status", viewBox: `0 0 ${wide} ${size.height}` });
|
|
3932
|
+
place(svg, x, middle - size.height / 2, wide, size.height);
|
|
3933
|
+
const { body, level, cap } = batteryParts(size, CHARGE);
|
|
3934
|
+
const r = Math.min(cap.width, cap.height / 2);
|
|
3935
|
+
const end = cap.x + cap.width;
|
|
3936
|
+
const bottom = cap.y + cap.height;
|
|
3937
|
+
svg.append(svgNode("rect", { ...body, class: "rest" }), svgNode("path", level), svgNode("path", {
|
|
3938
|
+
d: `M${cap.x} ${cap.y}H${end - r}A${r} ${r} 0 0 1 ${end} ${cap.y + r}` + `V${bottom - r}A${r} ${r} 0 0 1 ${end - r} ${bottom}H${cap.x}Z`,
|
|
3939
|
+
class: "rest"
|
|
3884
3940
|
}));
|
|
3885
3941
|
return svg;
|
|
3886
3942
|
}
|
|
3887
3943
|
function statusBar(status) {
|
|
3944
|
+
const glyphs = status.large ? STATUS_GLYPHS.large : STATUS_GLYPHS.regular;
|
|
3888
3945
|
const time = el("div", "time", "04:20");
|
|
3889
3946
|
time.style.left = `${status.time.x}px`;
|
|
3890
|
-
time.style.top = `${status.time.y}px`;
|
|
3947
|
+
time.style.top = `${status.time.y + glyphs.time.drop}px`;
|
|
3891
3948
|
time.style.fontSize = `${status.time.size}px`;
|
|
3949
|
+
time.style.letterSpacing = `${glyphs.time.spacing}px`;
|
|
3892
3950
|
const { icons } = status;
|
|
3951
|
+
const { signal: bars, wifi: air, battery: cell } = glyphs;
|
|
3893
3952
|
if (icons.align === "start") {
|
|
3894
3953
|
const end = status.battery ?? { x: icons.x, y: icons.y };
|
|
3954
|
+
const bottom = icons.y + Math.max(...bars.heights) / 2;
|
|
3895
3955
|
const nodes = [
|
|
3896
|
-
signal(icons.x,
|
|
3897
|
-
wifi(icons.x + 23, icons.y),
|
|
3898
|
-
battery(end.x -
|
|
3956
|
+
signal(icons.x, bottom, bars),
|
|
3957
|
+
wifi(icons.x + 23, icons.y + air.height / 2, air),
|
|
3958
|
+
battery(end.x - batteryWidth(cell), end.y, cell)
|
|
3899
3959
|
];
|
|
3900
3960
|
for (const node of nodes)
|
|
3901
3961
|
node.style.transform = "scale(0.85)";
|
|
3902
3962
|
return [time, ...nodes];
|
|
3903
3963
|
}
|
|
3904
|
-
const
|
|
3905
|
-
const
|
|
3906
|
-
|
|
3964
|
+
const right = icons.x - batteryWidth(cell);
|
|
3965
|
+
const middle = right - glyphs.gap - air.width;
|
|
3966
|
+
const left = middle - glyphs.gap - (bars.pitch * (bars.heights.length - 1) + bars.width);
|
|
3967
|
+
return [
|
|
3968
|
+
time,
|
|
3969
|
+
signal(left, icons.y + bars.drop, bars),
|
|
3970
|
+
wifi(middle, icons.y + air.drop, air),
|
|
3971
|
+
battery(right, icons.y + cell.drop, cell)
|
|
3972
|
+
];
|
|
3973
|
+
}
|
|
3974
|
+
var DUO_GLYPHS = {
|
|
3975
|
+
time: { spacing: 0, drop: 0.8 },
|
|
3976
|
+
ends: 55,
|
|
3977
|
+
dots: [-30.5, -10, 10, 30.5],
|
|
3978
|
+
dot: 2,
|
|
3979
|
+
rest: 0.35,
|
|
3980
|
+
wifi: {
|
|
3981
|
+
width: 18.2,
|
|
3982
|
+
height: 13.33,
|
|
3983
|
+
bands: [0, 3.06, 5.94, 7.64, 10.51, 12.26],
|
|
3984
|
+
angle: 45.4,
|
|
3985
|
+
round: 1.1,
|
|
3986
|
+
drop: 0
|
|
3987
|
+
}
|
|
3988
|
+
};
|
|
3989
|
+
function onCircle(r, angle) {
|
|
3990
|
+
const rad = angle * Math.PI / 180;
|
|
3991
|
+
return `${(r * Math.cos(rad)).toFixed(2)} ${(r * Math.sin(rad)).toFixed(2)}`;
|
|
3992
|
+
}
|
|
3993
|
+
function arc(r, from, to) {
|
|
3994
|
+
const large = to - from > 180 ? 1 : 0;
|
|
3995
|
+
return `M${onCircle(r, from)}A${r} ${r} 0 ${large} 1 ${onCircle(r, to)}`;
|
|
3996
|
+
}
|
|
3997
|
+
function ring(x, y, size) {
|
|
3998
|
+
const { radius, stroke } = size;
|
|
3999
|
+
const reach = radius + stroke;
|
|
4000
|
+
const svg = svgNode("svg", { class: "status ring", viewBox: `${-reach} ${-reach} ${2 * reach} ${2 * reach}` });
|
|
4001
|
+
place(svg, x - reach, y - reach, 2 * reach, 2 * reach);
|
|
4002
|
+
const from = 90 + DUO_GLYPHS.ends;
|
|
4003
|
+
const to = 450 - DUO_GLYPHS.ends;
|
|
4004
|
+
const charged = from + (to - from) * CHARGE / 100;
|
|
4005
|
+
const line = { fill: "none", stroke: "currentColor", "stroke-width": stroke, "stroke-linecap": "round" };
|
|
4006
|
+
svg.append(svgNode("path", { d: arc(radius, charged, to), ...line, "stroke-opacity": DUO_GLYPHS.rest }), svgNode("path", { d: arc(radius, from, charged), ...line }), ...DUO_GLYPHS.dots.map((angle) => {
|
|
4007
|
+
const rad = (90 + angle) * Math.PI / 180;
|
|
4008
|
+
return svgNode("circle", { cx: radius * Math.cos(rad), cy: radius * Math.sin(rad), r: DUO_GLYPHS.dot });
|
|
4009
|
+
}));
|
|
4010
|
+
return svg;
|
|
4011
|
+
}
|
|
4012
|
+
function statusColumn(column) {
|
|
4013
|
+
const time = el("div", "time", "04:20");
|
|
4014
|
+
time.style.left = `${column.time.x}px`;
|
|
4015
|
+
time.style.top = `${column.time.y + DUO_GLYPHS.time.drop}px`;
|
|
4016
|
+
time.style.fontSize = `${column.time.size}px`;
|
|
4017
|
+
time.style.letterSpacing = `${DUO_GLYPHS.time.spacing}px`;
|
|
4018
|
+
const air = DUO_GLYPHS.wifi;
|
|
4019
|
+
return [
|
|
4020
|
+
time,
|
|
4021
|
+
ring(column.x, column.ring.y, column.ring),
|
|
4022
|
+
wifi(column.x - air.width / 2, column.ring.y + air.height / 2, air)
|
|
4023
|
+
];
|
|
3907
4024
|
}
|
|
3908
4025
|
function pressOf(glyph, actions) {
|
|
3909
4026
|
if (glyph === "back")
|
|
@@ -3920,33 +4037,135 @@ function glyphIn(mark, origin, className, actions) {
|
|
|
3920
4037
|
svg.style.top = `${mark.y - origin.y - 15}px`;
|
|
3921
4038
|
return svg;
|
|
3922
4039
|
}
|
|
4040
|
+
function domainOf(host) {
|
|
4041
|
+
return host.replace(/:\d+$/, "");
|
|
4042
|
+
}
|
|
3923
4043
|
function pillBox(pill, host) {
|
|
3924
|
-
const
|
|
4044
|
+
const size = pill.text?.size ?? SAFARI_TEXT.pill;
|
|
4045
|
+
const width = Math.round(textWidth(domainOf(host), size, DOMAIN_WEIGHT)) + (pill.text?.pad ?? 0);
|
|
3925
4046
|
return { x: pill.x - width / 2, y: pill.y, width, height: pill.height };
|
|
3926
4047
|
}
|
|
4048
|
+
function hslOf({ red, green, blue }) {
|
|
4049
|
+
const [r, g, b] = [red / 255, green / 255, blue / 255];
|
|
4050
|
+
const high = Math.max(r, g, b);
|
|
4051
|
+
const low = Math.min(r, g, b);
|
|
4052
|
+
const lightness = (high + low) / 2;
|
|
4053
|
+
const span = high - low;
|
|
4054
|
+
if (span === 0)
|
|
4055
|
+
return [0, 0, lightness];
|
|
4056
|
+
const saturation = span / (1 - Math.abs(2 * lightness - 1));
|
|
4057
|
+
const hue = high === r ? (g - b) / span + 6 : high === g ? (b - r) / span + 2 : (r - g) / span + 4;
|
|
4058
|
+
return [hue * 60 % 360, saturation, lightness];
|
|
4059
|
+
}
|
|
4060
|
+
function fromHsl(hue, saturation, lightness) {
|
|
4061
|
+
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
|
4062
|
+
const at = (hue % 360 + 360) % 360 / 60;
|
|
4063
|
+
const second = chroma * (1 - Math.abs(at % 2 - 1));
|
|
4064
|
+
const sectors = [
|
|
4065
|
+
[chroma, second, 0],
|
|
4066
|
+
[second, chroma, 0],
|
|
4067
|
+
[0, chroma, second],
|
|
4068
|
+
[0, second, chroma],
|
|
4069
|
+
[second, 0, chroma],
|
|
4070
|
+
[chroma, 0, second]
|
|
4071
|
+
];
|
|
4072
|
+
const [r = 0, g = 0, b = 0] = sectors[Math.floor(at) % 6] ?? [];
|
|
4073
|
+
const m = lightness - chroma / 2;
|
|
4074
|
+
return { red: (r + m) * 255, green: (g + m) * 255, blue: (b + m) * 255, alpha: 1 };
|
|
4075
|
+
}
|
|
4076
|
+
function hexOf({ red, green, blue }) {
|
|
4077
|
+
const pair = (channel) => Math.min(255, Math.max(0, Math.round(channel))).toString(16).padStart(2, "0");
|
|
4078
|
+
return `#${pair(red)}${pair(green)}${pair(blue)}`;
|
|
4079
|
+
}
|
|
4080
|
+
var GLASS_GRAY = { light: [137, 248], dark: [34, 179] };
|
|
4081
|
+
function glassTint(under, scheme) {
|
|
4082
|
+
const [hue, saturation, lightness] = hslOf(under);
|
|
4083
|
+
const [low, high] = GLASS_GRAY[scheme];
|
|
4084
|
+
const gray = low + (high - low) * lightness;
|
|
4085
|
+
const neutral = { red: gray, green: gray, blue: gray, alpha: 1 };
|
|
4086
|
+
const light = scheme === "light";
|
|
4087
|
+
const hued = light ? fromHsl(hue - 4, Math.min(1, saturation * 1.3 + 0.05), Math.min(0.9, lightness + 0.26)) : fromHsl(hue, Math.min(1, saturation + 0.15), Math.min(0.9, lightness * 1.4 - 0.1));
|
|
4088
|
+
const chroma = saturation * (1 - Math.abs(2 * lightness - 1));
|
|
4089
|
+
const share = Math.min(1, chroma / (light ? 0.8 : 0.7));
|
|
4090
|
+
const mix = (a, b) => a + (b - a) * share;
|
|
4091
|
+
const fill = {
|
|
4092
|
+
red: mix(neutral.red, hued.red),
|
|
4093
|
+
green: mix(neutral.green, hued.green),
|
|
4094
|
+
blue: mix(neutral.blue, hued.blue),
|
|
4095
|
+
alpha: 1
|
|
4096
|
+
};
|
|
4097
|
+
const glyph = light ? "dark" : "light";
|
|
4098
|
+
const rim = share > 0.3 ? "tint" : light ? "none" : "highlight";
|
|
4099
|
+
return { fill: hexOf(fill), glyph, rim };
|
|
4100
|
+
}
|
|
4101
|
+
var GLASS_ALPHA = 0.9;
|
|
4102
|
+
function glassFill(fill, under) {
|
|
4103
|
+
const own = (want, page) => Math.min(255, Math.max(0, Math.round((want - (1 - GLASS_ALPHA) * page) / GLASS_ALPHA)));
|
|
4104
|
+
const [r, g, b] = [
|
|
4105
|
+
own(fill.red, under.red),
|
|
4106
|
+
own(fill.green, under.green),
|
|
4107
|
+
own(fill.blue, under.blue)
|
|
4108
|
+
];
|
|
4109
|
+
return `rgba(${r}, ${g}, ${b}, ${GLASS_ALPHA})`;
|
|
4110
|
+
}
|
|
4111
|
+
var WHITE = { red: 255, green: 255, blue: 255, alpha: 1 };
|
|
4112
|
+
function underAt(look, x, y) {
|
|
4113
|
+
let best = null;
|
|
4114
|
+
let far = Infinity;
|
|
4115
|
+
for (const sample of look.under) {
|
|
4116
|
+
const distance = Math.hypot(sample.x - x, sample.y - y);
|
|
4117
|
+
if (distance < far) {
|
|
4118
|
+
far = distance;
|
|
4119
|
+
best = sample.color;
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
return parseColor(best ?? look.background) ?? WHITE;
|
|
4123
|
+
}
|
|
4124
|
+
function tintGlass(node, box2, look) {
|
|
4125
|
+
const under = underAt(look, box2.x + box2.width / 2, box2.y + box2.height / 2);
|
|
4126
|
+
const tint = glassTint(under, look.scheme);
|
|
4127
|
+
node.style.backgroundColor = glassFill(parseHex(tint.fill) ?? WHITE, under);
|
|
4128
|
+
node.dataset.tone = tint.glyph === "dark" ? "light" : "dark";
|
|
4129
|
+
node.dataset.rim = tint.rim;
|
|
4130
|
+
return under;
|
|
4131
|
+
}
|
|
3927
4132
|
function placeBox(node, box2, radius) {
|
|
3928
4133
|
place(node, box2.x, box2.y, box2.width, box2.height);
|
|
3929
4134
|
node.style.borderRadius = `${radius}px`;
|
|
3930
4135
|
}
|
|
3931
|
-
function
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
4136
|
+
function over(top, under, alpha) {
|
|
4137
|
+
const mix = (a, b) => a * alpha + b * (1 - alpha);
|
|
4138
|
+
return {
|
|
4139
|
+
red: mix(top.red, under.red),
|
|
4140
|
+
green: mix(top.green, under.green),
|
|
4141
|
+
blue: mix(top.blue, under.blue),
|
|
4142
|
+
alpha: 1
|
|
4143
|
+
};
|
|
4144
|
+
}
|
|
4145
|
+
function scrimOver(node, mini, look) {
|
|
4146
|
+
const { scrim, status } = mini;
|
|
4147
|
+
const held = look.top !== look.background;
|
|
4148
|
+
node.dataset.on = String(scrim !== null && !held);
|
|
4149
|
+
if (!scrim || held)
|
|
4150
|
+
return null;
|
|
4151
|
+
const page = parseColor(look.background) ?? WHITE;
|
|
4152
|
+
const { red, green, blue } = page;
|
|
4153
|
+
node.style.top = `${scrim.y}px`;
|
|
4154
|
+
node.style.height = `${scrim.height}px`;
|
|
4155
|
+
const stops = scrim.stops.map(({ at, alpha }) => `rgba(${red}, ${green}, ${blue}, ${alpha}) ${at}px`);
|
|
3939
4156
|
node.style.background = `linear-gradient(to bottom, ${stops.join(", ")})`;
|
|
4157
|
+
const content = underAt(look, scrim.at.x, scrim.at.y);
|
|
4158
|
+
return over(page, content, alphaAt(scrim, status?.time.y ?? 0));
|
|
3940
4159
|
}
|
|
3941
4160
|
function buildSafari(full, mini, look, actions) {
|
|
3942
4161
|
const root = el("div", "safari");
|
|
3943
4162
|
root.style.inset = "0";
|
|
3944
|
-
const
|
|
3945
|
-
|
|
3946
|
-
fade.style.right = "0";
|
|
3947
|
-
root.append(fade);
|
|
4163
|
+
const scrim = el("div", "scrim");
|
|
4164
|
+
root.append(scrim);
|
|
3948
4165
|
if (full.status)
|
|
3949
4166
|
root.append(...statusBar(full.status));
|
|
4167
|
+
const column = full.column ? statusColumn(full.column) : [];
|
|
4168
|
+
root.append(...column);
|
|
3950
4169
|
const pill = mini.shapes.find((shape) => shape.kind === "pill") ?? null;
|
|
3951
4170
|
const main = pill ? full.shapes.find((shape) => shape.kind === "card") ?? full.shapes.find((shape) => shape.text !== undefined) ?? null : null;
|
|
3952
4171
|
let surface = null;
|
|
@@ -3996,11 +4215,13 @@ function buildSafari(full, mini, look, actions) {
|
|
|
3996
4215
|
progress.hidden = true;
|
|
3997
4216
|
surface?.append(progress);
|
|
3998
4217
|
let loads3 = 0;
|
|
4218
|
+
const sides = [];
|
|
3999
4219
|
for (const shape of full.shapes) {
|
|
4000
4220
|
if (shape === main || shape.kind === "field")
|
|
4001
4221
|
continue;
|
|
4002
4222
|
const side = el("div", "side capsule");
|
|
4003
4223
|
placeBox(side, shape, shape.radius);
|
|
4224
|
+
sides.push({ node: side, box: shape });
|
|
4004
4225
|
const middle = shape.x + shape.width / 2;
|
|
4005
4226
|
const across = full.orientation === "landscape";
|
|
4006
4227
|
const toward = main ? main.x + main.width / 2 : middle;
|
|
@@ -4022,11 +4243,18 @@ function buildSafari(full, mini, look, actions) {
|
|
|
4022
4243
|
root,
|
|
4023
4244
|
apply(minimized, sight) {
|
|
4024
4245
|
root.dataset.state = minimized ? "min" : "max";
|
|
4025
|
-
|
|
4026
|
-
|
|
4246
|
+
const behind = scrimOver(scrim, mini, sight);
|
|
4247
|
+
const own = full.column && !full.column.strip ? sight.background : sight.top;
|
|
4248
|
+
const strip = (minimized ? behind : null) ?? parseColor(own) ?? WHITE;
|
|
4249
|
+
const darkStrip = luminance(strip.red, strip.green, strip.blue) < 0.4;
|
|
4250
|
+
root.className = darkStrip ? "safari dark" : "safari light";
|
|
4251
|
+
for (const node of column)
|
|
4252
|
+
node.style.display = minimized && !mini.column ? "none" : "";
|
|
4027
4253
|
for (const text of Array.from(root.querySelectorAll(".domain"))) {
|
|
4028
|
-
text.textContent = sight.host;
|
|
4254
|
+
text.textContent = domainOf(sight.host);
|
|
4029
4255
|
}
|
|
4256
|
+
for (const { node, box: box2 } of sides)
|
|
4257
|
+
tintGlass(node, box2, sight);
|
|
4030
4258
|
for (const { node, glyph } of glyphs) {
|
|
4031
4259
|
const off = glyph === "back" && !sight.canBack || glyph === "forward" && !sight.canForward;
|
|
4032
4260
|
node.classList.toggle("off", off);
|
|
@@ -4035,9 +4263,10 @@ function buildSafari(full, mini, look, actions) {
|
|
|
4035
4263
|
if (surface && domain && main && pill) {
|
|
4036
4264
|
const box2 = minimized ? pillBox(pill, sight.host) : main;
|
|
4037
4265
|
placeBox(surface, box2, minimized ? pill.radius : main.radius);
|
|
4266
|
+
tintGlass(surface, box2, sight);
|
|
4038
4267
|
const top = minimized ? pill.height / 2 : Number(domain.dataset.top);
|
|
4039
4268
|
domain.style.top = `${top}px`;
|
|
4040
|
-
const scale = minimized ? SAFARI_TEXT.pill / SAFARI_TEXT.field : 1;
|
|
4269
|
+
const scale = minimized ? (pill.text?.size ?? SAFARI_TEXT.pill) / SAFARI_TEXT.field : 1;
|
|
4041
4270
|
domain.style.transform = `translate(-50%, -50%) scale(${scale})`;
|
|
4042
4271
|
}
|
|
4043
4272
|
},
|
|
@@ -4075,1534 +4304,2044 @@ function buildSafari(full, mini, look, actions) {
|
|
|
4075
4304
|
duration: PROGRESS.finish,
|
|
4076
4305
|
easing: "ease-out"
|
|
4077
4306
|
});
|
|
4078
|
-
const
|
|
4307
|
+
const fade = progress.animate([{ opacity: 1 }, { opacity: 0 }], {
|
|
4079
4308
|
delay: PROGRESS.finish,
|
|
4080
4309
|
duration: PROGRESS.fade,
|
|
4081
4310
|
easing: "ease-out",
|
|
4082
4311
|
fill: "forwards"
|
|
4083
4312
|
});
|
|
4084
|
-
|
|
4313
|
+
fade.finished.then(() => {
|
|
4085
4314
|
if (load !== loads3)
|
|
4086
4315
|
return;
|
|
4087
4316
|
progress.hidden = true;
|
|
4088
|
-
|
|
4317
|
+
fade.cancel();
|
|
4089
4318
|
}, () => {});
|
|
4090
4319
|
}
|
|
4091
4320
|
};
|
|
4092
4321
|
}
|
|
4093
4322
|
|
|
4094
|
-
// src/engine/
|
|
4095
|
-
var
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
.
|
|
4114
|
-
|
|
4115
|
-
box-sizing: border-box;
|
|
4323
|
+
// src/engine/objectfit.ts
|
|
4324
|
+
var MIDDLE = { share: 0.5, px: 0 };
|
|
4325
|
+
function words(text) {
|
|
4326
|
+
const parts = [];
|
|
4327
|
+
let depth = 0;
|
|
4328
|
+
let word = "";
|
|
4329
|
+
for (const char of text.trim()) {
|
|
4330
|
+
if (char === "(")
|
|
4331
|
+
depth++;
|
|
4332
|
+
if (char === ")")
|
|
4333
|
+
depth--;
|
|
4334
|
+
if (/\s/.test(char) && depth === 0) {
|
|
4335
|
+
if (word)
|
|
4336
|
+
parts.push(word);
|
|
4337
|
+
word = "";
|
|
4338
|
+
} else
|
|
4339
|
+
word += char;
|
|
4340
|
+
}
|
|
4341
|
+
if (word)
|
|
4342
|
+
parts.push(word);
|
|
4343
|
+
return parts;
|
|
4116
4344
|
}
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
${CHROME_CSS}
|
|
4121
|
-
`;
|
|
4122
|
-
var BUILDERS = { safari: buildSafari, chrome: buildChrome };
|
|
4123
|
-
function toRgb(color) {
|
|
4124
|
-
const parsed = parseColor(color);
|
|
4125
|
-
if (parsed)
|
|
4126
|
-
return parsed;
|
|
4127
|
-
try {
|
|
4128
|
-
const canvas = document.createElement("canvas");
|
|
4129
|
-
canvas.width = 1;
|
|
4130
|
-
canvas.height = 1;
|
|
4131
|
-
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
4132
|
-
if (!context)
|
|
4133
|
-
return null;
|
|
4134
|
-
context.fillStyle = color;
|
|
4135
|
-
context.fillRect(0, 0, 1, 1);
|
|
4136
|
-
const [r = 0, g = 0, b = 0, a = 0] = context.getImageData(0, 0, 1, 1).data;
|
|
4137
|
-
return { red: r, green: g, blue: b, alpha: a / 255 };
|
|
4138
|
-
} catch {
|
|
4345
|
+
function offsetOf(word) {
|
|
4346
|
+
const terms = Array.from(word.matchAll(/([+-])?\s*(\d*\.?\d+(?:e[+-]?\d+)?)(%|px)?/gi));
|
|
4347
|
+
if (terms.length === 0 || !/^(calc\(.*\)|[+-]?[\d.]+(e[+-]?\d+)?(%|px)?)$/i.test(word))
|
|
4139
4348
|
return null;
|
|
4349
|
+
const offset = { share: 0, px: 0 };
|
|
4350
|
+
for (const [, sign, digits = "0", unit] of terms) {
|
|
4351
|
+
const value = Number(digits) * (sign === "-" ? -1 : 1);
|
|
4352
|
+
if (unit === "%")
|
|
4353
|
+
offset.share += value / 100;
|
|
4354
|
+
else
|
|
4355
|
+
offset.px += value;
|
|
4140
4356
|
}
|
|
4357
|
+
return offset;
|
|
4141
4358
|
}
|
|
4142
|
-
function
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
let
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
const
|
|
4153
|
-
const [
|
|
4154
|
-
|
|
4155
|
-
|
|
4359
|
+
function fromFar(offset) {
|
|
4360
|
+
return { share: 1 - offset.share, px: 0 - offset.px };
|
|
4361
|
+
}
|
|
4362
|
+
function objectPosition(position) {
|
|
4363
|
+
let x = null;
|
|
4364
|
+
let y = null;
|
|
4365
|
+
const plain = [];
|
|
4366
|
+
const list = words(position.toLowerCase());
|
|
4367
|
+
const counted = list.length > 2;
|
|
4368
|
+
for (let at = 0;at < list.length; at++) {
|
|
4369
|
+
const word = list[at] ?? "";
|
|
4370
|
+
const next = offsetOf(list[at + 1] ?? "");
|
|
4371
|
+
if (word === "left" || word === "right" || word === "top" || word === "bottom") {
|
|
4372
|
+
const far = word === "right" || word === "bottom";
|
|
4373
|
+
const edge = counted && next || { share: 0, px: 0 };
|
|
4374
|
+
if (counted && next)
|
|
4375
|
+
at++;
|
|
4376
|
+
const offset = far ? fromFar(edge) : edge;
|
|
4377
|
+
if (word === "left" || word === "right")
|
|
4378
|
+
x = offset;
|
|
4379
|
+
else
|
|
4380
|
+
y = offset;
|
|
4381
|
+
} else if (word === "center")
|
|
4382
|
+
plain.push(MIDDLE);
|
|
4383
|
+
else {
|
|
4384
|
+
const offset = offsetOf(word);
|
|
4385
|
+
if (offset)
|
|
4386
|
+
plain.push(offset);
|
|
4387
|
+
}
|
|
4156
4388
|
}
|
|
4157
|
-
|
|
4389
|
+
for (const offset of plain) {
|
|
4390
|
+
if (!x)
|
|
4391
|
+
x = offset;
|
|
4392
|
+
else if (!y)
|
|
4393
|
+
y = offset;
|
|
4394
|
+
}
|
|
4395
|
+
return [x ?? MIDDLE, y ?? MIDDLE];
|
|
4158
4396
|
}
|
|
4159
|
-
function
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4397
|
+
function objectPlace(fit, position, natural, box2) {
|
|
4398
|
+
if (!(natural.width > 0 && natural.height > 0 && box2.width > 0 && box2.height > 0))
|
|
4399
|
+
return null;
|
|
4400
|
+
const across = box2.width / natural.width;
|
|
4401
|
+
const down = box2.height / natural.height;
|
|
4402
|
+
const whole = Math.min(across, down);
|
|
4403
|
+
let size = { width: box2.width, height: box2.height };
|
|
4404
|
+
const scaled = (scale) => ({ width: natural.width * scale, height: natural.height * scale });
|
|
4405
|
+
if (fit === "contain")
|
|
4406
|
+
size = scaled(whole);
|
|
4407
|
+
else if (fit === "cover")
|
|
4408
|
+
size = scaled(Math.max(across, down));
|
|
4409
|
+
else if (fit === "none")
|
|
4410
|
+
size = scaled(1);
|
|
4411
|
+
else if (fit === "scale-down")
|
|
4412
|
+
size = scaled(Math.min(1, whole));
|
|
4413
|
+
const [x, y] = objectPosition(position);
|
|
4414
|
+
const left = box2.x + (box2.width - size.width) * x.share + x.px;
|
|
4415
|
+
const top = box2.y + (box2.height - size.height) * y.share + y.px;
|
|
4416
|
+
const to = {
|
|
4417
|
+
x: Math.max(left, box2.x),
|
|
4418
|
+
y: Math.max(top, box2.y),
|
|
4419
|
+
width: Math.min(left + size.width, box2.x + box2.width) - Math.max(left, box2.x),
|
|
4420
|
+
height: Math.min(top + size.height, box2.y + box2.height) - Math.max(top, box2.y)
|
|
4421
|
+
};
|
|
4422
|
+
if (!(to.width > 0 && to.height > 0))
|
|
4423
|
+
return null;
|
|
4424
|
+
const wide = natural.width / size.width;
|
|
4425
|
+
const tall = natural.height / size.height;
|
|
4426
|
+
return {
|
|
4427
|
+
from: { x: (to.x - left) * wide, y: (to.y - top) * tall, width: to.width * wide, height: to.height * tall },
|
|
4428
|
+
to
|
|
4167
4429
|
};
|
|
4168
|
-
try {
|
|
4169
|
-
const view = frame2.contentWindow;
|
|
4170
|
-
const doc = frame2.contentDocument;
|
|
4171
|
-
if (!view || !doc?.documentElement)
|
|
4172
|
-
return fallback;
|
|
4173
|
-
const scheme = view.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
4174
|
-
const [r, g, b] = backgroundOf(doc, view, scheme === "dark");
|
|
4175
|
-
const navigation = navigationOf(view);
|
|
4176
|
-
const can = (key) => {
|
|
4177
|
-
const value = navigation && Reflect.get(navigation, key);
|
|
4178
|
-
return typeof value === "boolean" ? value : null;
|
|
4179
|
-
};
|
|
4180
|
-
return {
|
|
4181
|
-
background: `rgb(${r}, ${g}, ${b})`,
|
|
4182
|
-
dark: luminance(r, g, b) < 0.4,
|
|
4183
|
-
scheme,
|
|
4184
|
-
host: view.location.host,
|
|
4185
|
-
canBack: can("canGoBack") ?? view.history.length > 1,
|
|
4186
|
-
canForward: can("canGoForward") ?? false
|
|
4187
|
-
};
|
|
4188
|
-
} catch {
|
|
4189
|
-
return fallback;
|
|
4190
|
-
}
|
|
4191
4430
|
}
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4431
|
+
|
|
4432
|
+
// src/engine/pagefonts.ts
|
|
4433
|
+
var kept2 = null;
|
|
4434
|
+
var READ = /^(woff2?|truetype|opentype|collection)(-variations)?$/;
|
|
4435
|
+
var URL_OF = /^url\(\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([^)]*))\s*\)/i;
|
|
4436
|
+
var CHUNK = 32768;
|
|
4437
|
+
function cut(text, mark) {
|
|
4438
|
+
const parts = [];
|
|
4439
|
+
let depth = 0;
|
|
4440
|
+
let quote = "";
|
|
4441
|
+
let from = 0;
|
|
4442
|
+
for (let at = 0;at < text.length; at++) {
|
|
4443
|
+
const char = text[at];
|
|
4444
|
+
if (char === "\\")
|
|
4445
|
+
at++;
|
|
4446
|
+
else if (quote)
|
|
4447
|
+
quote = char === quote ? "" : quote;
|
|
4448
|
+
else if (char === '"' || char === "'")
|
|
4449
|
+
quote = char;
|
|
4450
|
+
else if (char === "(")
|
|
4451
|
+
depth++;
|
|
4452
|
+
else if (char === ")")
|
|
4453
|
+
depth--;
|
|
4454
|
+
else if (char === mark && depth === 0) {
|
|
4455
|
+
parts.push(text.slice(from, at));
|
|
4456
|
+
from = at + 1;
|
|
4457
|
+
}
|
|
4197
4458
|
}
|
|
4459
|
+
parts.push(text.slice(from));
|
|
4460
|
+
return parts;
|
|
4198
4461
|
}
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4462
|
+
function faceKey(family, weight, style, range) {
|
|
4463
|
+
const name = family.trim().replace(/^(["'])(.*)\1$/, "$2").toLowerCase();
|
|
4464
|
+
const plain = (value) => value.trim().toLowerCase().replace(/\s+/g, " ") || "normal";
|
|
4465
|
+
const heavy = plain(weight).replace(/\bnormal\b/g, "400").replace(/\bbold\b/g, "700");
|
|
4466
|
+
const chars = (range.trim() || "U+0-10FFFF").toLowerCase().split(",").map((part) => part.trim().replace(/^u\+/, "").split("-").map((end) => end.replace(/^0+(?=.)/, "")).join("-")).join(",");
|
|
4467
|
+
return [name, heavy, plain(style), chars].join("|");
|
|
4203
4468
|
}
|
|
4204
|
-
function
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
let applied = null;
|
|
4215
|
-
let shrinking = 0;
|
|
4216
|
-
let later = 0;
|
|
4217
|
-
let query = null;
|
|
4218
|
-
let watched = null;
|
|
4219
|
-
let href = "";
|
|
4220
|
-
let motion = BARS_START;
|
|
4221
|
-
let busy = false;
|
|
4222
|
-
let loadWait = 0;
|
|
4223
|
-
const still2 = () => baseMatchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
4224
|
-
const step = (event) => {
|
|
4225
|
-
const before = motion.minimized;
|
|
4226
|
-
motion = barsStep(motion, event);
|
|
4227
|
-
if (motion.minimized !== before)
|
|
4228
|
-
queueMicrotask(onChange);
|
|
4229
|
-
};
|
|
4230
|
-
const onScroll = () => {
|
|
4231
|
-
const page = frame2.contentWindow;
|
|
4232
|
-
if (page)
|
|
4233
|
-
step({ type: "scroll", y: page.scrollY, time: performance.now() });
|
|
4234
|
-
};
|
|
4235
|
-
const actions = {
|
|
4236
|
-
back: () => frame2.contentWindow?.history.back(),
|
|
4237
|
-
forward: () => frame2.contentWindow?.history.forward(),
|
|
4238
|
-
reload: () => {
|
|
4239
|
-
if (busy) {
|
|
4240
|
-
frame2.contentWindow?.stop();
|
|
4241
|
-
stopLoading();
|
|
4242
|
-
return;
|
|
4243
|
-
}
|
|
4244
|
-
onReload();
|
|
4245
|
-
keep(frame2.contentWindow, "frame");
|
|
4246
|
-
frame2.contentWindow?.location.reload();
|
|
4247
|
-
},
|
|
4248
|
-
expand: () => step({ type: "tap" })
|
|
4249
|
-
};
|
|
4250
|
-
const roomFrame = () => {
|
|
4251
|
-
const bars = view?.bars ?? null;
|
|
4252
|
-
try {
|
|
4253
|
-
const page = frame2.contentWindow;
|
|
4254
|
-
const doc = frame2.contentDocument;
|
|
4255
|
-
if (!page || !doc?.documentElement)
|
|
4256
|
-
return;
|
|
4257
|
-
const room = bars ? endRoom(bars.screen, bars.orientation, bars.layout, bars.minimized, bars.edge) : 0;
|
|
4258
|
-
const had = give(doc, room);
|
|
4259
|
-
if (had === room)
|
|
4260
|
-
return;
|
|
4261
|
-
step({ type: "resize", time: performance.now() });
|
|
4262
|
-
const end = doc.documentElement.scrollHeight - page.innerHeight;
|
|
4263
|
-
if (room < had || page.scrollY <= 1 || page.scrollY < end - (room - had) - 1)
|
|
4264
|
-
return;
|
|
4265
|
-
page.scrollTo({ top: end, behavior: still2() ? "instant" : "smooth" });
|
|
4266
|
-
} catch {}
|
|
4267
|
-
};
|
|
4268
|
-
const sizeFrame = () => {
|
|
4269
|
-
if (!view)
|
|
4270
|
-
return;
|
|
4271
|
-
view.sizeFrame();
|
|
4272
|
-
if (!same(view.page, applied))
|
|
4273
|
-
step({ type: "resize", time: performance.now() });
|
|
4274
|
-
applied = view.page;
|
|
4275
|
-
roomFrame();
|
|
4276
|
-
};
|
|
4277
|
-
const placeFrame = (instant) => {
|
|
4278
|
-
const page = view?.page ?? null;
|
|
4279
|
-
const shrinks = !instant && page && applied && page.height < applied.height;
|
|
4280
|
-
clearTimeout(shrinking);
|
|
4281
|
-
if (!shrinks) {
|
|
4282
|
-
sizeFrame();
|
|
4283
|
-
return;
|
|
4284
|
-
}
|
|
4285
|
-
shrinking = window.setTimeout(() => {
|
|
4286
|
-
if (same(view?.page ?? null, page))
|
|
4287
|
-
sizeFrame();
|
|
4288
|
-
}, MORPH.expand);
|
|
4289
|
-
};
|
|
4290
|
-
const back = () => {
|
|
4291
|
-
frame2.style.background = reaches(frame2) ? (look ??= readLook(frame2)).background : "";
|
|
4292
|
-
};
|
|
4293
|
-
const draw = () => {
|
|
4294
|
-
const bars = view?.bars ?? null;
|
|
4295
|
-
if (!view || !bars) {
|
|
4296
|
-
clearTimeout(shrinking);
|
|
4297
|
-
layer.replaceChildren();
|
|
4298
|
-
glass.style.background = "";
|
|
4299
|
-
back();
|
|
4300
|
-
painted = null;
|
|
4301
|
-
built = "";
|
|
4302
|
-
if (view)
|
|
4303
|
-
sizeFrame();
|
|
4304
|
-
return;
|
|
4305
|
-
}
|
|
4306
|
-
look ??= readLook(frame2);
|
|
4307
|
-
glass.style.background = look.background;
|
|
4308
|
-
back();
|
|
4309
|
-
const { platform, layout, screen, orientation, edge } = bars;
|
|
4310
|
-
const base = JSON.stringify([platform, layout, screen, orientation, edge, view.follow]);
|
|
4311
|
-
const fresh2 = base !== built || !painted;
|
|
4312
|
-
const instant = fresh2 || still2();
|
|
4313
|
-
if (fresh2) {
|
|
4314
|
-
const other = barsOf(screen, orientation, layout, !bars.minimized, edge);
|
|
4315
|
-
const full = bars.minimized ? other : bars;
|
|
4316
|
-
const mini = bars.minimized ? bars : other;
|
|
4317
|
-
const shown2 = { ...actions, expand: view.follow ? actions.expand : undefined };
|
|
4318
|
-
if (!full || !mini)
|
|
4319
|
-
return;
|
|
4320
|
-
painted = BUILDERS[bars.platform](full, mini, look, shown2);
|
|
4321
|
-
layer.replaceChildren(painted.root);
|
|
4322
|
-
built = base;
|
|
4323
|
-
if (busy)
|
|
4324
|
-
painted.loading?.(true, true);
|
|
4325
|
-
}
|
|
4326
|
-
if (instant)
|
|
4327
|
-
layer.setAttribute("data-instant", "");
|
|
4328
|
-
painted?.apply(bars.minimized, look);
|
|
4329
|
-
if (instant) {
|
|
4330
|
-
layer.offsetWidth;
|
|
4331
|
-
layer.removeAttribute("data-instant");
|
|
4332
|
-
}
|
|
4333
|
-
placeFrame(instant);
|
|
4334
|
-
};
|
|
4335
|
-
const pageOf = () => {
|
|
4336
|
-
try {
|
|
4337
|
-
return frame2.contentDocument;
|
|
4338
|
-
} catch {
|
|
4339
|
-
return null;
|
|
4340
|
-
}
|
|
4341
|
-
};
|
|
4342
|
-
const showLoading = (on, seed) => {
|
|
4343
|
-
busy = on;
|
|
4344
|
-
if (seed) {
|
|
4345
|
-
look = seed;
|
|
4346
|
-
draw();
|
|
4347
|
-
}
|
|
4348
|
-
painted?.loading?.(on, still2());
|
|
4349
|
-
if (!on)
|
|
4350
|
-
browser.refresh();
|
|
4351
|
-
};
|
|
4352
|
-
const stopLoading = () => {
|
|
4353
|
-
if (loadWait)
|
|
4354
|
-
window.cancelAnimationFrame(loadWait);
|
|
4355
|
-
loadWait = 0;
|
|
4356
|
-
if (!busy)
|
|
4469
|
+
function base64(bytes) {
|
|
4470
|
+
let text = "";
|
|
4471
|
+
for (let at = 0;at < bytes.length; at += CHUNK)
|
|
4472
|
+
text += String.fromCharCode(...bytes.subarray(at, at + CHUNK));
|
|
4473
|
+
return btoa(text);
|
|
4474
|
+
}
|
|
4475
|
+
function fetchFont(url, fonts) {
|
|
4476
|
+
fonts.set(url, null);
|
|
4477
|
+
quietFetch(url).then(async (response) => {
|
|
4478
|
+
if (!response.ok)
|
|
4357
4479
|
return;
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
if (next && ready() || performance.now() >= end)
|
|
4373
|
-
stopLoading();
|
|
4374
|
-
else
|
|
4375
|
-
loadWait = window.requestAnimationFrame(check);
|
|
4376
|
-
};
|
|
4377
|
-
loadWait = window.requestAnimationFrame(check);
|
|
4480
|
+
const type = /^[\w.+-]+\/[\w.+-]+/.exec(response.headers.get("content-type") ?? "")?.[0];
|
|
4481
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
4482
|
+
fonts.set(url, `data:${type ?? "application/octet-stream"};base64,${base64(bytes)}`);
|
|
4483
|
+
}).catch(() => {});
|
|
4484
|
+
}
|
|
4485
|
+
function faceWith(css, base, used, fonts) {
|
|
4486
|
+
const open = css.indexOf("{");
|
|
4487
|
+
const close = css.lastIndexOf("}");
|
|
4488
|
+
if (open < 0 || close < open)
|
|
4489
|
+
return css;
|
|
4490
|
+
const parts = cut(css.slice(open + 1, close), ";");
|
|
4491
|
+
const named = (name) => {
|
|
4492
|
+
const part = parts.find((part2) => part2.split(":")[0]?.trim().toLowerCase() === name);
|
|
4493
|
+
return part ? part.slice(part.indexOf(":") + 1).trim() : "";
|
|
4378
4494
|
};
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4495
|
+
if (!used.has(faceKey(named("font-family"), named("font-weight"), named("font-style"), named("unicode-range")))) {
|
|
4496
|
+
return css;
|
|
4497
|
+
}
|
|
4498
|
+
const sources = cut(named("src"), ",").map((source2) => source2.trim());
|
|
4499
|
+
const at = sources.findIndex((source2) => {
|
|
4500
|
+
const format = /format\(\s*["']?([\w-]+)["']?\s*\)/i.exec(source2)?.[1];
|
|
4501
|
+
return URL_OF.test(source2) && (!format || READ.test(format.toLowerCase()));
|
|
4502
|
+
});
|
|
4503
|
+
const source = sources[at];
|
|
4504
|
+
const found = source ? URL_OF.exec(source) : null;
|
|
4505
|
+
if (!source || !found)
|
|
4506
|
+
return css;
|
|
4507
|
+
const address = (found[1] ?? found[2] ?? found[3] ?? "").trim().replace(/\\(.)/g, "$1");
|
|
4508
|
+
if (/^data:/i.test(address))
|
|
4509
|
+
return css;
|
|
4510
|
+
let url;
|
|
4511
|
+
try {
|
|
4512
|
+
url = new URL(address, base).href;
|
|
4513
|
+
} catch {
|
|
4514
|
+
return css;
|
|
4515
|
+
}
|
|
4516
|
+
const data = fonts.get(url);
|
|
4517
|
+
if (data === undefined)
|
|
4518
|
+
fetchFont(url, fonts);
|
|
4519
|
+
if (!data)
|
|
4520
|
+
return css;
|
|
4521
|
+
const locals = sources.slice(0, at).filter((source2) => /^local\(/i.test(source2));
|
|
4522
|
+
const src = [...locals, `url("${data}")${source.slice(found[0].length)}`].join(", ");
|
|
4523
|
+
const next = parts.map((part) => part.split(":")[0]?.trim().toLowerCase() === "src" ? ` src: ${src}` : part);
|
|
4524
|
+
return `${css.slice(0, open + 1)}${next.join(";")}${css.slice(close)}`;
|
|
4525
|
+
}
|
|
4526
|
+
function holdsRules(rule) {
|
|
4527
|
+
return "cssRules" in rule;
|
|
4528
|
+
}
|
|
4529
|
+
function keptFor(doc) {
|
|
4530
|
+
if (kept2?.doc === doc)
|
|
4531
|
+
return kept2.fonts;
|
|
4532
|
+
forgetFonts();
|
|
4533
|
+
const set = doc.fonts;
|
|
4534
|
+
const again = () => fetchFonts(doc);
|
|
4535
|
+
set?.addEventListener("loadingdone", again);
|
|
4536
|
+
kept2 = { doc, fonts: new Map, stop: () => set?.removeEventListener("loadingdone", again) };
|
|
4537
|
+
return kept2.fonts;
|
|
4538
|
+
}
|
|
4539
|
+
function embedFonts(doc) {
|
|
4540
|
+
const fonts = keptFor(doc);
|
|
4541
|
+
const used = new Set;
|
|
4542
|
+
const set = doc.fonts;
|
|
4543
|
+
if (set) {
|
|
4544
|
+
for (const face of set) {
|
|
4545
|
+
if (face.status === "loaded")
|
|
4546
|
+
used.add(faceKey(face.family, face.weight, face.style, face.unicodeRange));
|
|
4397
4547
|
}
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
glass.append(layer);
|
|
4407
|
-
if (!next.bars)
|
|
4408
|
-
layer.remove();
|
|
4409
|
-
place(layer, 0, 0, next.size.width, next.size.height);
|
|
4410
|
-
layer.style.transform = next.zoom === 1 ? "" : `scale(${next.zoom})`;
|
|
4411
|
-
draw();
|
|
4412
|
-
},
|
|
4413
|
-
refresh() {
|
|
4414
|
-
if (!view)
|
|
4415
|
-
return;
|
|
4416
|
-
const again = view.bars ? read : () => {
|
|
4417
|
-
if (!busy || !look)
|
|
4418
|
-
look = readLook(frame2);
|
|
4419
|
-
back();
|
|
4420
|
-
};
|
|
4421
|
-
again();
|
|
4422
|
-
clearTimeout(later);
|
|
4423
|
-
later = window.setTimeout(again, RESTYLE);
|
|
4424
|
-
},
|
|
4425
|
-
minimized: () => motion.minimized,
|
|
4426
|
-
page: () => applied,
|
|
4427
|
-
startLoading,
|
|
4428
|
-
stopLoading,
|
|
4429
|
-
look: () => look,
|
|
4430
|
-
remove() {
|
|
4431
|
-
clearTimeout(later);
|
|
4432
|
-
if (loadWait)
|
|
4433
|
-
window.cancelAnimationFrame(loadWait);
|
|
4434
|
-
loadWait = 0;
|
|
4435
|
-
clearTimeout(shrinking);
|
|
4436
|
-
query?.removeEventListener("change", read);
|
|
4437
|
-
try {
|
|
4438
|
-
frame2.contentWindow?.removeEventListener("scroll", onScroll);
|
|
4439
|
-
} catch {}
|
|
4440
|
-
query = null;
|
|
4441
|
-
watched = null;
|
|
4442
|
-
layer.remove();
|
|
4443
|
-
blank.remove();
|
|
4548
|
+
}
|
|
4549
|
+
const embed = (rule) => {
|
|
4550
|
+
let css = rule.cssText;
|
|
4551
|
+
if (used.size === 0 || !css.includes("@font-face"))
|
|
4552
|
+
return css;
|
|
4553
|
+
if (!holdsRules(rule)) {
|
|
4554
|
+
const base = rule.parentStyleSheet?.href ?? doc.baseURI;
|
|
4555
|
+
return css.startsWith("@font-face") ? faceWith(css, base, used, fonts) : css;
|
|
4444
4556
|
}
|
|
4557
|
+
for (const inner of rule.cssRules) {
|
|
4558
|
+
const next = embed(inner);
|
|
4559
|
+
if (next !== inner.cssText)
|
|
4560
|
+
css = css.split(inner.cssText).join(next);
|
|
4561
|
+
}
|
|
4562
|
+
return css;
|
|
4445
4563
|
};
|
|
4446
|
-
return
|
|
4564
|
+
return embed;
|
|
4565
|
+
}
|
|
4566
|
+
function fetchFonts(doc) {
|
|
4567
|
+
const embed = embedFonts(doc);
|
|
4568
|
+
for (const sheet of doc.styleSheets) {
|
|
4569
|
+
try {
|
|
4570
|
+
for (const rule of sheet.cssRules)
|
|
4571
|
+
embed(rule);
|
|
4572
|
+
} catch {}
|
|
4573
|
+
}
|
|
4574
|
+
}
|
|
4575
|
+
function warmFonts(doc) {
|
|
4576
|
+
if (kept2?.doc !== doc)
|
|
4577
|
+
fetchFonts(doc);
|
|
4578
|
+
}
|
|
4579
|
+
function forgetFonts() {
|
|
4580
|
+
kept2?.stop();
|
|
4581
|
+
kept2 = null;
|
|
4447
4582
|
}
|
|
4448
4583
|
|
|
4449
|
-
// src/engine/
|
|
4450
|
-
var
|
|
4451
|
-
var
|
|
4452
|
-
var
|
|
4453
|
-
var
|
|
4454
|
-
function
|
|
4455
|
-
const
|
|
4456
|
-
|
|
4584
|
+
// src/engine/pageshot.ts
|
|
4585
|
+
var RES = 0.25;
|
|
4586
|
+
var MOST = 1500;
|
|
4587
|
+
var BUDGET = 6;
|
|
4588
|
+
var INK = 0.4;
|
|
4589
|
+
function canvasOf(width, height) {
|
|
4590
|
+
const canvas = document.createElement("canvas");
|
|
4591
|
+
canvas.width = Math.max(1, Math.round(width));
|
|
4592
|
+
canvas.height = Math.max(1, Math.round(height));
|
|
4593
|
+
const pen = canvas.getContext("2d");
|
|
4594
|
+
return pen ? { canvas, pen } : null;
|
|
4457
4595
|
}
|
|
4458
|
-
function
|
|
4459
|
-
return
|
|
4596
|
+
function clear(color) {
|
|
4597
|
+
return color === "" || color === "transparent" || /^rgba\(.*,\s*0\)$/.test(color);
|
|
4460
4598
|
}
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
}
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
const across = width > 0 && room.width > 0 ? (room.width - 2 * x) / (width + sides.width) : 1;
|
|
4473
|
-
const tall = typeof knobs2.height === "number" && knobs2.height > 0 && room.height > 0;
|
|
4474
|
-
const upright = (room.height - 2 * y) / (Number(knobs2.height) + sides.height);
|
|
4475
|
-
const whole = Math.min(1, across, tall ? upright : 1);
|
|
4476
|
-
const height = typeof knobs2.height === "number" ? knobs2.height : room.height / whole;
|
|
4477
|
-
const outer = { width: width + sides.width, height: height + sides.height };
|
|
4478
|
-
const covered = sized && aside > 0 && aside <= room.width / 2 && (room.width + outer.width * whole) / 2 + x > room.width - aside;
|
|
4479
|
-
const fitted = covered ? Math.min(whole, (room.width - aside - 2 * x) / outer.width) : whole;
|
|
4480
|
-
const scale = knobs2.zoom === "fit" ? fitted : knobs2.zoom;
|
|
4481
|
-
const beside = knobs2.zoom === "fit" && covered ? aside : 0;
|
|
4482
|
-
const before = side === "left" ? beside : 0;
|
|
4483
|
-
return {
|
|
4484
|
-
width,
|
|
4485
|
-
height,
|
|
4486
|
-
zoom: frameZoom,
|
|
4487
|
-
scale,
|
|
4488
|
-
fit: fitted,
|
|
4489
|
-
transform: scale / frameZoom,
|
|
4490
|
-
box: { width: outer.width * scale + 2 * x + beside, height: outer.height * scale + 2 * y },
|
|
4491
|
-
left: x + mock.left * scale + before,
|
|
4492
|
-
top: y + mock.top * scale
|
|
4493
|
-
};
|
|
4599
|
+
var MEDIA = "img, video, canvas";
|
|
4600
|
+
function mediaOf(node) {
|
|
4601
|
+
if ("naturalWidth" in node) {
|
|
4602
|
+
const loaded = node.complete && node.naturalWidth > 0 && node.naturalHeight > 0;
|
|
4603
|
+
return loaded ? { source: node, width: node.naturalWidth, height: node.naturalHeight } : null;
|
|
4604
|
+
}
|
|
4605
|
+
if ("videoWidth" in node) {
|
|
4606
|
+
const playing = node.readyState >= 2 && node.videoWidth > 0 && node.videoHeight > 0;
|
|
4607
|
+
return playing ? { source: node, width: node.videoWidth, height: node.videoHeight } : null;
|
|
4608
|
+
}
|
|
4609
|
+
return node.width > 0 && node.height > 0 ? { source: node, width: node.width, height: node.height } : null;
|
|
4494
4610
|
}
|
|
4495
|
-
function
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4611
|
+
function radiusOf(value, wide, tall) {
|
|
4612
|
+
const [across = "0", down = across] = value.trim().split(/\s+/);
|
|
4613
|
+
const px = (text, of) => (text.endsWith("%") ? Number.parseFloat(text) / 100 * of : Number.parseFloat(text)) || 0;
|
|
4614
|
+
return { x: px(across, wide), y: px(down, tall) };
|
|
4615
|
+
}
|
|
4616
|
+
function drawMedia(pen, media, rect, style) {
|
|
4617
|
+
const px = (value) => Number.parseFloat(value) || 0;
|
|
4618
|
+
const left = px(style.borderLeftWidth) + px(style.paddingLeft);
|
|
4619
|
+
const right = px(style.borderRightWidth) + px(style.paddingRight);
|
|
4620
|
+
const top = px(style.borderTopWidth) + px(style.paddingTop);
|
|
4621
|
+
const bottom = px(style.borderBottomWidth) + px(style.paddingBottom);
|
|
4622
|
+
const box2 = { x: rect.left + left, y: rect.top + top, width: rect.width - left - right, height: rect.height - top - bottom };
|
|
4623
|
+
const placed = objectPlace(style.objectFit, style.objectPosition, media, box2);
|
|
4624
|
+
if (!placed)
|
|
4625
|
+
return;
|
|
4626
|
+
const corner = (value, across, down) => {
|
|
4627
|
+
const radius = radiusOf(value, rect.width, rect.height);
|
|
4628
|
+
return { x: Math.max(0, radius.x - across), y: Math.max(0, radius.y - down) };
|
|
4499
4629
|
};
|
|
4630
|
+
const corners = [
|
|
4631
|
+
corner(style.borderTopLeftRadius, left, top),
|
|
4632
|
+
corner(style.borderTopRightRadius, right, top),
|
|
4633
|
+
corner(style.borderBottomRightRadius, right, bottom),
|
|
4634
|
+
corner(style.borderBottomLeftRadius, left, bottom)
|
|
4635
|
+
];
|
|
4636
|
+
const { from, to } = placed;
|
|
4637
|
+
pen.save();
|
|
4638
|
+
if (corners.some((radius) => radius.x > 0 && radius.y > 0)) {
|
|
4639
|
+
pen.beginPath();
|
|
4640
|
+
pen.roundRect(box2.x, box2.y, box2.width, box2.height, corners);
|
|
4641
|
+
pen.clip();
|
|
4642
|
+
}
|
|
4643
|
+
if (style.imageRendering === "pixelated" || style.imageRendering === "crisp-edges")
|
|
4644
|
+
pen.imageSmoothingEnabled = false;
|
|
4645
|
+
pen.drawImage(media.source, from.x, from.y, from.width, from.height, to.x, to.y, to.width, to.height);
|
|
4646
|
+
pen.restore();
|
|
4500
4647
|
}
|
|
4501
|
-
function
|
|
4502
|
-
const
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4648
|
+
function picturesKey(doc) {
|
|
4649
|
+
const parts = [];
|
|
4650
|
+
for (const node of doc.querySelectorAll(MEDIA)) {
|
|
4651
|
+
if (!("naturalWidth" in node))
|
|
4652
|
+
return null;
|
|
4653
|
+
const address = node.currentSrc;
|
|
4654
|
+
parts.push(`${address.length}:${address.slice(-64)}@${node.naturalWidth}x${node.naturalHeight}`);
|
|
4655
|
+
}
|
|
4656
|
+
return parts.join(" ");
|
|
4657
|
+
}
|
|
4658
|
+
function shotKey(at) {
|
|
4659
|
+
const { size, frame: frame2, view, scroll } = at;
|
|
4660
|
+
return JSON.stringify([
|
|
4661
|
+
[size.width, size.height, at.color, at.layout],
|
|
4662
|
+
[frame2.x, frame2.y, frame2.width],
|
|
4663
|
+
[view.width, view.height, scroll.x, scroll.y],
|
|
4664
|
+
[at.dpr, at.text, at.pictures]
|
|
4665
|
+
]);
|
|
4666
|
+
}
|
|
4667
|
+
function shootPage(frame2, glass, size, color, layout = "") {
|
|
4668
|
+
const doc = frame2.contentDocument;
|
|
4669
|
+
const view = frame2.contentWindow;
|
|
4670
|
+
const screen = glass.getBoundingClientRect();
|
|
4671
|
+
const box2 = frame2.getBoundingClientRect();
|
|
4672
|
+
if (!doc?.body || !view || screen.width <= 0 || view.innerWidth <= 0)
|
|
4673
|
+
return null;
|
|
4674
|
+
const shown2 = picturesKey(doc);
|
|
4675
|
+
const css = size.width / screen.width;
|
|
4676
|
+
const near = (value) => Math.round(value * css * 1000) / 1000;
|
|
4677
|
+
const key = shotKey({
|
|
4678
|
+
size,
|
|
4679
|
+
color,
|
|
4680
|
+
layout,
|
|
4681
|
+
frame: { x: near(box2.left - screen.left), y: near(box2.top - screen.top), width: near(box2.width) },
|
|
4682
|
+
view: { width: view.innerWidth, height: view.innerHeight },
|
|
4683
|
+
scroll: { x: view.scrollX, y: view.scrollY },
|
|
4684
|
+
dpr: view.devicePixelRatio,
|
|
4685
|
+
text: view.getComputedStyle(doc.documentElement).fontSize,
|
|
4686
|
+
pictures: shown2 ?? ""
|
|
4687
|
+
});
|
|
4688
|
+
const kept3 = shown2 === null || !unchanged(doc) ? null : shots.get(doc)?.get(key);
|
|
4689
|
+
if (kept3)
|
|
4690
|
+
return kept3;
|
|
4691
|
+
const drawn = canvasOf(size.width * RES, size.height * RES);
|
|
4692
|
+
if (!drawn)
|
|
4693
|
+
return null;
|
|
4694
|
+
const { canvas, pen } = drawn;
|
|
4695
|
+
pen.fillStyle = color;
|
|
4696
|
+
pen.fillRect(0, 0, canvas.width, canvas.height);
|
|
4697
|
+
const scale = box2.width * css / view.innerWidth;
|
|
4698
|
+
pen.setTransform(RES * scale, 0, 0, RES * scale, RES * (box2.left - screen.left) * css, RES * (box2.top - screen.top) * css);
|
|
4699
|
+
pen.beginPath();
|
|
4700
|
+
pen.rect(0, 0, view.innerWidth, view.innerHeight);
|
|
4701
|
+
pen.clip();
|
|
4702
|
+
const pictures = new Map;
|
|
4703
|
+
for (const node of doc.querySelectorAll(MEDIA)) {
|
|
4704
|
+
const media = mediaOf(node);
|
|
4705
|
+
if (media)
|
|
4706
|
+
pictures.set(node, media);
|
|
4707
|
+
}
|
|
4708
|
+
const range = doc.createRange();
|
|
4709
|
+
const tall = view.innerHeight;
|
|
4710
|
+
let seen = 0;
|
|
4711
|
+
const pinned = [];
|
|
4712
|
+
const deadline = performance.now() + BUDGET;
|
|
4713
|
+
const draw = (node, alpha, lifted) => {
|
|
4714
|
+
if (seen++ > MOST || seen % 50 === 0 && performance.now() > deadline)
|
|
4715
|
+
return;
|
|
4716
|
+
if (node.hasAttribute("data-devknobs"))
|
|
4717
|
+
return;
|
|
4718
|
+
const style = view.getComputedStyle(node);
|
|
4719
|
+
if (style.display === "none")
|
|
4720
|
+
return;
|
|
4721
|
+
if (!lifted && (style.position === "fixed" || style.position === "sticky")) {
|
|
4722
|
+
pinned.push([node, alpha]);
|
|
4723
|
+
return;
|
|
4724
|
+
}
|
|
4725
|
+
const rect = node.getBoundingClientRect();
|
|
4726
|
+
const area = rect.width > 0 && rect.height > 0;
|
|
4727
|
+
if (area && (rect.bottom < 0 || rect.top > tall))
|
|
4728
|
+
return;
|
|
4729
|
+
const shown3 = alpha * (Number.parseFloat(style.opacity) || 0);
|
|
4730
|
+
if (shown3 <= 0)
|
|
4731
|
+
return;
|
|
4732
|
+
if (area && style.visibility !== "hidden") {
|
|
4733
|
+
pen.globalAlpha = shown3;
|
|
4734
|
+
if (!clear(style.backgroundColor)) {
|
|
4735
|
+
pen.fillStyle = style.backgroundColor;
|
|
4736
|
+
pen.beginPath();
|
|
4737
|
+
pen.roundRect(rect.left, rect.top, rect.width, rect.height, Number.parseFloat(style.borderTopLeftRadius) || 0);
|
|
4738
|
+
pen.fill();
|
|
4739
|
+
}
|
|
4740
|
+
const picture = pictures.get(node);
|
|
4741
|
+
if (picture)
|
|
4742
|
+
drawMedia(pen, picture, rect, style);
|
|
4743
|
+
pen.fillStyle = style.color;
|
|
4744
|
+
pen.globalAlpha = shown3 * INK;
|
|
4745
|
+
for (const text of node.childNodes) {
|
|
4746
|
+
if (text.nodeType !== Node.TEXT_NODE || !text.textContent?.trim())
|
|
4747
|
+
continue;
|
|
4748
|
+
range.selectNodeContents(text);
|
|
4749
|
+
for (const line of range.getClientRects())
|
|
4750
|
+
pen.fillRect(line.left, line.top, line.width, line.height);
|
|
4751
|
+
}
|
|
4752
|
+
}
|
|
4753
|
+
for (const child of node.children)
|
|
4754
|
+
draw(child, shown3, lifted);
|
|
4755
|
+
};
|
|
4756
|
+
for (const child of doc.body.children)
|
|
4757
|
+
draw(child, 1, false);
|
|
4758
|
+
for (const [node, alpha] of pinned)
|
|
4759
|
+
draw(node, alpha, true);
|
|
4760
|
+
if (shown2 !== null)
|
|
4761
|
+
keepShot(doc, key, canvas);
|
|
4762
|
+
return canvas;
|
|
4509
4763
|
}
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
function
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
`);
|
|
4764
|
+
var shots = new WeakMap;
|
|
4765
|
+
var watched = null;
|
|
4766
|
+
function forgetShots() {
|
|
4767
|
+
watched?.observer.disconnect();
|
|
4768
|
+
watched = null;
|
|
4769
|
+
shots = new WeakMap;
|
|
4770
|
+
forgetFonts();
|
|
4518
4771
|
}
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
width: 100%;
|
|
4526
|
-
height: 100%;
|
|
4527
|
-
pointer-events: none;
|
|
4528
|
-
fill: var(--mat-line);
|
|
4772
|
+
function unchanged(doc) {
|
|
4773
|
+
if (watched?.doc !== doc)
|
|
4774
|
+
return false;
|
|
4775
|
+
if (watched.observer.takeRecords().length > 0)
|
|
4776
|
+
watched.changed = true;
|
|
4777
|
+
return !watched.changed;
|
|
4529
4778
|
}
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
.
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
var ANGLES = [15, 30, 45, 60, 75];
|
|
4545
|
-
var GUIDE = { line: 0.15, half: 0.22 };
|
|
4546
|
-
var ARC = 40;
|
|
4547
|
-
var LABEL = { radius: 240, off: 3, top: 40, room: 24 };
|
|
4548
|
-
var FOOT = 30;
|
|
4549
|
-
var NUMBER = 24;
|
|
4550
|
-
function ticks(length) {
|
|
4551
|
-
const out = [];
|
|
4552
|
-
for (let at = CELL;at < length; at += CELL) {
|
|
4553
|
-
const size = at % SPAN === 0 ? TICK.span : at % MAJOR === 0 ? TICK.major : TICK.cell;
|
|
4554
|
-
out.push({ at, size });
|
|
4779
|
+
function keepShot(doc, key, canvas) {
|
|
4780
|
+
if (!unchanged(doc)) {
|
|
4781
|
+
watched?.observer.disconnect();
|
|
4782
|
+
shots = new WeakMap;
|
|
4783
|
+
const Observer = doc.defaultView?.MutationObserver;
|
|
4784
|
+
if (!Observer)
|
|
4785
|
+
return;
|
|
4786
|
+
const observer = new Observer(() => {
|
|
4787
|
+
if (watched?.observer === observer)
|
|
4788
|
+
watched.changed = true;
|
|
4789
|
+
observer.disconnect();
|
|
4790
|
+
});
|
|
4791
|
+
observer.observe(doc, { subtree: true, childList: true, attributes: true, characterData: true });
|
|
4792
|
+
watched = { doc, changed: false, observer };
|
|
4555
4793
|
}
|
|
4556
|
-
|
|
4794
|
+
const kept3 = shots.get(doc) ?? new Map;
|
|
4795
|
+
kept3.set(key, canvas);
|
|
4796
|
+
shots.set(doc, kept3);
|
|
4557
4797
|
}
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4798
|
+
var KEPT = 8;
|
|
4799
|
+
function blurPictures(shot, width, across, widths = blurWidths().slice(1)) {
|
|
4800
|
+
const length = across ? shot.height : shot.width;
|
|
4801
|
+
return widths.map((wide) => {
|
|
4802
|
+
const coarse2 = Math.max(1, wide * shot.width / width);
|
|
4803
|
+
const margin = blurMargin(coarse2);
|
|
4804
|
+
const padded = canvasOf(shot.width + (across ? 0 : 2 * margin), shot.height + (across ? 2 * margin : 0));
|
|
4805
|
+
if (!padded)
|
|
4806
|
+
return { canvas: blurPicture(shot, coarse2), long: length };
|
|
4807
|
+
padded.pen.fillStyle = "#000";
|
|
4808
|
+
padded.pen.fillRect(0, 0, padded.canvas.width, padded.canvas.height);
|
|
4809
|
+
padded.pen.drawImage(shot, across ? 0 : margin, across ? margin : 0);
|
|
4810
|
+
const canvas = blurPicture(padded.canvas, coarse2);
|
|
4811
|
+
if (canvas !== padded.canvas)
|
|
4812
|
+
spend(padded.canvas);
|
|
4813
|
+
return { canvas, long: length + 2 * margin };
|
|
4814
|
+
});
|
|
4566
4815
|
}
|
|
4567
|
-
function
|
|
4568
|
-
return
|
|
4816
|
+
function blurMargin(coarse2) {
|
|
4817
|
+
return Math.ceil(2 * coarse2);
|
|
4569
4818
|
}
|
|
4570
|
-
function
|
|
4571
|
-
const
|
|
4572
|
-
return
|
|
4819
|
+
function marginPlace(shot, padded) {
|
|
4820
|
+
const exact = (value) => Math.round(value * 1e4) / 1e4;
|
|
4821
|
+
return { start: exact((shot - padded) / 2 / shot * 100), size: exact(padded / shot * 100) };
|
|
4573
4822
|
}
|
|
4574
|
-
function
|
|
4575
|
-
|
|
4576
|
-
|
|
4823
|
+
function spend(canvas) {
|
|
4824
|
+
canvas.width = 0;
|
|
4825
|
+
canvas.height = 0;
|
|
4577
4826
|
}
|
|
4578
|
-
function
|
|
4579
|
-
const
|
|
4580
|
-
const
|
|
4581
|
-
const
|
|
4582
|
-
|
|
4583
|
-
return
|
|
4584
|
-
|
|
4827
|
+
function blurPicture(shot, coarse2) {
|
|
4828
|
+
const halvings = Math.ceil(Math.log2(coarse2) - 0.000000001);
|
|
4829
|
+
const { width, height } = shot;
|
|
4830
|
+
const sized = (level) => {
|
|
4831
|
+
const scale = Math.min(1, 2 ** level / coarse2);
|
|
4832
|
+
return canvasOf(width * scale, height * scale);
|
|
4833
|
+
};
|
|
4834
|
+
let at = shot;
|
|
4835
|
+
const step = (level, smooth) => {
|
|
4836
|
+
const next = sized(level);
|
|
4837
|
+
if (!next)
|
|
4838
|
+
return false;
|
|
4839
|
+
if (smooth)
|
|
4840
|
+
next.pen.imageSmoothingQuality = "high";
|
|
4841
|
+
next.pen.drawImage(at, 0, 0, next.canvas.width, next.canvas.height);
|
|
4842
|
+
if (at !== shot)
|
|
4843
|
+
spend(at);
|
|
4844
|
+
at = next.canvas;
|
|
4845
|
+
return true;
|
|
4846
|
+
};
|
|
4847
|
+
for (let level = halvings - 1;level >= 0; level--)
|
|
4848
|
+
if (!step(level, false))
|
|
4849
|
+
return at;
|
|
4850
|
+
for (let level = 1;level <= Math.min(Math.log2(KEPT), halvings); level++)
|
|
4851
|
+
if (!step(level, true))
|
|
4852
|
+
return at;
|
|
4853
|
+
return at;
|
|
4585
4854
|
}
|
|
4586
|
-
function
|
|
4587
|
-
|
|
4588
|
-
return { x: from.x + radius * step.x + off * step.y, y: from.y + radius * step.y - off * step.x };
|
|
4855
|
+
function blankUrl(width, height) {
|
|
4856
|
+
return svgUrl(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}"/>`);
|
|
4589
4857
|
}
|
|
4590
|
-
function
|
|
4591
|
-
const
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
width: SPAN,
|
|
4604
|
-
height: SPAN,
|
|
4605
|
-
patternUnits: "userSpaceOnUse"
|
|
4858
|
+
function blankPictures(live, copy) {
|
|
4859
|
+
const shown2 = live.querySelectorAll("img");
|
|
4860
|
+
copy.querySelectorAll("img").forEach((image, index) => {
|
|
4861
|
+
const from = shown2[index];
|
|
4862
|
+
if (!from || !from.complete || !(from.naturalWidth > 0 && from.naturalHeight > 0))
|
|
4863
|
+
return;
|
|
4864
|
+
for (const name of ["srcset", "sizes", "loading"])
|
|
4865
|
+
image.removeAttribute(name);
|
|
4866
|
+
const holder = image.parentElement;
|
|
4867
|
+
if (holder?.localName === "picture")
|
|
4868
|
+
for (const source of holder.querySelectorAll("source"))
|
|
4869
|
+
source.remove();
|
|
4870
|
+
image.setAttribute("src", blankUrl(from.naturalWidth, from.naturalHeight));
|
|
4606
4871
|
});
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
const
|
|
4614
|
-
const
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
const
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4872
|
+
}
|
|
4873
|
+
function copyPage(frame2, leave) {
|
|
4874
|
+
const doc = frame2.contentDocument;
|
|
4875
|
+
if (!doc?.documentElement)
|
|
4876
|
+
return null;
|
|
4877
|
+
const rules = [];
|
|
4878
|
+
const written2 = embedFonts(doc);
|
|
4879
|
+
for (const sheet of [...doc.styleSheets, ...doc.adoptedStyleSheets ?? []]) {
|
|
4880
|
+
try {
|
|
4881
|
+
for (const rule of sheet.cssRules)
|
|
4882
|
+
rules.push(written2(rule));
|
|
4883
|
+
} catch {}
|
|
4884
|
+
}
|
|
4885
|
+
const inert = doc.implementation.createHTMLDocument("");
|
|
4886
|
+
const root = inert.importNode(doc.documentElement, true);
|
|
4887
|
+
if (leave) {
|
|
4888
|
+
const live = doc.documentElement.getElementsByTagName("*");
|
|
4889
|
+
const copied = root.getElementsByTagName("*");
|
|
4890
|
+
for (let index = 0;index < live.length; index++) {
|
|
4891
|
+
const node = live[index];
|
|
4892
|
+
if (node && leave(node))
|
|
4893
|
+
copied[index]?.setAttribute("data-devknobs", "");
|
|
4894
|
+
}
|
|
4895
|
+
}
|
|
4896
|
+
blankPictures(doc.documentElement, root);
|
|
4897
|
+
for (const node of root.querySelectorAll("script, link, style, noscript, [data-devknobs]"))
|
|
4898
|
+
node.remove();
|
|
4899
|
+
const style = inert.createElement("style");
|
|
4900
|
+
style.textContent = rules.join(`
|
|
4901
|
+
`);
|
|
4902
|
+
(root.querySelector("head") ?? root).append(style);
|
|
4903
|
+
return root;
|
|
4904
|
+
}
|
|
4905
|
+
var LONE_HALF = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
4906
|
+
function svgUrl(svg) {
|
|
4907
|
+
const whole = typeof svg.toWellFormed === "function" ? svg.toWellFormed() : svg.replace(LONE_HALF, "�");
|
|
4908
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(whole)}`;
|
|
4909
|
+
}
|
|
4910
|
+
function rootSize(doc, view) {
|
|
4911
|
+
const size = view.getComputedStyle(doc.documentElement).fontSize;
|
|
4912
|
+
return size ? `font-size:${size} !important` : "";
|
|
4913
|
+
}
|
|
4914
|
+
async function paintPage(frame2, glass, size, color, copy) {
|
|
4915
|
+
const doc = frame2.contentDocument;
|
|
4916
|
+
const view = frame2.contentWindow;
|
|
4917
|
+
const screen = glass.getBoundingClientRect();
|
|
4918
|
+
const box2 = frame2.getBoundingClientRect();
|
|
4919
|
+
if (!doc || !view || screen.width <= 0 || view.innerWidth <= 0)
|
|
4920
|
+
return null;
|
|
4921
|
+
const { innerWidth: width, innerHeight: height, scrollX, scrollY } = view;
|
|
4922
|
+
const css = size.width / screen.width;
|
|
4923
|
+
const scale = box2.width * css / width;
|
|
4924
|
+
const at = { x: (box2.left - screen.left) * css, y: (box2.top - screen.top) * css };
|
|
4925
|
+
let over2 = null;
|
|
4926
|
+
for (const node of doc.querySelectorAll(MEDIA)) {
|
|
4927
|
+
const media = node.closest("[data-devknobs]") ? null : mediaOf(node);
|
|
4928
|
+
const rect = node.getBoundingClientRect();
|
|
4929
|
+
if (!media || rect.bottom <= 0 || rect.top >= height || rect.width <= 0)
|
|
4930
|
+
continue;
|
|
4931
|
+
if (!over2) {
|
|
4932
|
+
over2 = canvasOf(size.width, size.height);
|
|
4933
|
+
over2?.pen.setTransform(scale, 0, 0, scale, at.x, at.y);
|
|
4654
4934
|
}
|
|
4935
|
+
try {
|
|
4936
|
+
if (over2)
|
|
4937
|
+
drawMedia(over2.pen, media, rect, view.getComputedStyle(node));
|
|
4938
|
+
} catch {}
|
|
4655
4939
|
}
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4940
|
+
const root = copy.cloneNode(true);
|
|
4941
|
+
const scrolled = `position:relative;left:${-scrollX}px;top:${-scrollY}px`;
|
|
4942
|
+
const sized = rootSize(doc, view);
|
|
4943
|
+
root.setAttribute("style", `${root.getAttribute("style") ?? ""};${sized};${scrolled}`);
|
|
4944
|
+
const markup = new XMLSerializer().serializeToString(root);
|
|
4945
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" style="${sized}">` + `<foreignObject width="100%" height="100%">${markup}</foreignObject></svg>`;
|
|
4946
|
+
const image = new Image;
|
|
4947
|
+
try {
|
|
4948
|
+
image.src = svgUrl(svg);
|
|
4949
|
+
await image.decode();
|
|
4950
|
+
} catch {
|
|
4951
|
+
if (over2)
|
|
4952
|
+
spend(over2.canvas);
|
|
4953
|
+
return null;
|
|
4660
4954
|
}
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4955
|
+
const drawn = canvasOf(size.width, size.height);
|
|
4956
|
+
if (!drawn)
|
|
4957
|
+
return null;
|
|
4958
|
+
const { canvas, pen } = drawn;
|
|
4959
|
+
pen.fillStyle = color;
|
|
4960
|
+
pen.fillRect(0, 0, canvas.width, canvas.height);
|
|
4961
|
+
pen.setTransform(scale, 0, 0, scale, at.x, at.y);
|
|
4962
|
+
pen.drawImage(image, 0, 0, width, height);
|
|
4963
|
+
if (over2) {
|
|
4964
|
+
pen.setTransform(1, 0, 0, 1, 0, 0);
|
|
4965
|
+
pen.drawImage(over2.canvas, 0, 0);
|
|
4966
|
+
spend(over2.canvas);
|
|
4665
4967
|
}
|
|
4666
|
-
return
|
|
4968
|
+
return canvas;
|
|
4667
4969
|
}
|
|
4668
4970
|
|
|
4669
|
-
// src/engine/
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
free,
|
|
4677
|
-
dark: shadesOn() ? freeDepth(open) : 0,
|
|
4678
|
-
lit: [wipe, area, far]
|
|
4679
|
-
};
|
|
4971
|
+
// src/engine/underbar.ts
|
|
4972
|
+
var UNDERBAR_CSS = `
|
|
4973
|
+
.underbar {
|
|
4974
|
+
position: absolute;
|
|
4975
|
+
overflow: hidden;
|
|
4976
|
+
pointer-events: none;
|
|
4977
|
+
transform-origin: 0 0;
|
|
4680
4978
|
}
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4979
|
+
.underbar[hidden] { display: none; }
|
|
4980
|
+
.underbar > img {
|
|
4981
|
+
position: absolute;
|
|
4982
|
+
left: 0;
|
|
4983
|
+
top: 0;
|
|
4984
|
+
max-width: none;
|
|
4985
|
+
will-change: transform;
|
|
4685
4986
|
}
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4987
|
+
`;
|
|
4988
|
+
var GAP = 250;
|
|
4989
|
+
var SHARE = 10;
|
|
4990
|
+
function bandRect(page, height) {
|
|
4991
|
+
if (!page)
|
|
4992
|
+
return null;
|
|
4993
|
+
const top = page.y + page.height;
|
|
4994
|
+
const tall = height - top;
|
|
4995
|
+
return tall >= 0.5 ? { x: page.x, y: top, width: page.width, height: tall } : null;
|
|
4692
4996
|
}
|
|
4693
|
-
function
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
continue;
|
|
4698
|
-
const quad = shotQuad(shot, pane);
|
|
4699
|
-
const picture = shotPicture(shots, pane, quad);
|
|
4700
|
-
most = Math.max(most, wedgeOf(shotWindow(quad, pane, picture), pane, picture, 1));
|
|
4701
|
-
}
|
|
4702
|
-
return most;
|
|
4997
|
+
function showsBand(bars, look) {
|
|
4998
|
+
if (!bars || bars.platform !== "safari" || !bars.status && !bars.column)
|
|
4999
|
+
return false;
|
|
5000
|
+
return !!look && !look.footer;
|
|
4703
5001
|
}
|
|
4704
|
-
function
|
|
4705
|
-
|
|
4706
|
-
return across ? { x: part.x, y: -margin2, width: part.width, height: stage.height + 2 * margin2 } : { x: -margin2, y: part.y, width: stage.width + 2 * margin2, height: part.height };
|
|
5002
|
+
function bandShift(scrollY, innerHeight, scale) {
|
|
5003
|
+
return -(scrollY + innerHeight) * scale;
|
|
4707
5004
|
}
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
return pane === "inner" ? [-1 / width, 0, (x + width) / width] : [1 / width, 0, -x / width];
|
|
4712
|
-
return pane === "inner" ? [0, 1 / height, -y / height] : [0, -1 / height, (y + height) / height];
|
|
5005
|
+
var VH = /(-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)[sld]?vh\b/gi;
|
|
5006
|
+
function viewportUnits(css, height) {
|
|
5007
|
+
return css.replace(VH, (_, amount) => `${Math.round(Number(amount) * height) / 100}px`);
|
|
4713
5008
|
}
|
|
4714
|
-
function
|
|
4715
|
-
|
|
5009
|
+
function pictureOf(frame2) {
|
|
5010
|
+
const doc = frame2.contentDocument;
|
|
5011
|
+
const view = frame2.contentWindow;
|
|
5012
|
+
if (!doc?.documentElement || !view || view.innerWidth <= 0)
|
|
4716
5013
|
return null;
|
|
4717
|
-
const
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
5014
|
+
const { innerWidth: width, innerHeight: tall } = view;
|
|
5015
|
+
const copy = copyPage(frame2, (node) => view.getComputedStyle(node).position === "fixed");
|
|
5016
|
+
if (!copy)
|
|
5017
|
+
return null;
|
|
5018
|
+
for (const style of copy.querySelectorAll("style")) {
|
|
5019
|
+
style.textContent = viewportUnits(style.textContent ?? "", tall);
|
|
5020
|
+
}
|
|
5021
|
+
for (const node of copy.querySelectorAll("[style]")) {
|
|
5022
|
+
node.setAttribute("style", viewportUnits(node.getAttribute("style") ?? "", tall));
|
|
5023
|
+
}
|
|
5024
|
+
const full = Math.max(doc.documentElement.scrollHeight, tall);
|
|
5025
|
+
const root = doc.documentElement.getBoundingClientRect().height;
|
|
5026
|
+
const sized = rootSize(doc, view);
|
|
5027
|
+
copy.setAttribute("style", `${copy.getAttribute("style") ?? ""};${sized};height:${root}px !important`);
|
|
5028
|
+
const markup = new XMLSerializer().serializeToString(copy);
|
|
5029
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${full}" style="${sized}">` + `<foreignObject width="100%" height="100%">${markup}</foreignObject></svg>`;
|
|
5030
|
+
return { src: svgUrl(svg), width, height: full };
|
|
5031
|
+
}
|
|
5032
|
+
function createUnderbar(glass, frame2) {
|
|
5033
|
+
const band = el("div", "underbar");
|
|
5034
|
+
band.setAttribute("aria-hidden", "true");
|
|
5035
|
+
band.hidden = true;
|
|
5036
|
+
glass.append(band);
|
|
5037
|
+
let image = null;
|
|
5038
|
+
let picture = null;
|
|
5039
|
+
let taken = "";
|
|
5040
|
+
let watched2 = null;
|
|
5041
|
+
let observer = null;
|
|
5042
|
+
let changed = true;
|
|
5043
|
+
let waiting = 0;
|
|
5044
|
+
let painting = false;
|
|
5045
|
+
let last = 0;
|
|
5046
|
+
let cost = 0;
|
|
5047
|
+
let wide = 0;
|
|
5048
|
+
const keyOf = () => {
|
|
5049
|
+
try {
|
|
5050
|
+
const doc = frame2.contentDocument;
|
|
5051
|
+
const view = frame2.contentWindow;
|
|
5052
|
+
if (!doc?.documentElement || !view)
|
|
5053
|
+
return null;
|
|
5054
|
+
if (doc !== watched2) {
|
|
5055
|
+
observer?.disconnect();
|
|
5056
|
+
const next = new MutationObserver(() => {
|
|
5057
|
+
changed = true;
|
|
5058
|
+
soon();
|
|
5059
|
+
});
|
|
5060
|
+
next.observe(doc, { subtree: true, childList: true, attributes: true, characterData: true });
|
|
5061
|
+
observer = next;
|
|
5062
|
+
watched2 = doc;
|
|
5063
|
+
changed = true;
|
|
5064
|
+
image?.remove();
|
|
5065
|
+
image = null;
|
|
5066
|
+
picture = null;
|
|
5067
|
+
taken = "";
|
|
5068
|
+
}
|
|
5069
|
+
return `${view.innerWidth}|${view.innerHeight}|${doc.documentElement.scrollHeight}`;
|
|
5070
|
+
} catch {
|
|
5071
|
+
return null;
|
|
5072
|
+
}
|
|
5073
|
+
};
|
|
5074
|
+
const move = () => {
|
|
5075
|
+
if (band.hidden || !image || !picture)
|
|
5076
|
+
return;
|
|
5077
|
+
try {
|
|
5078
|
+
const view = frame2.contentWindow;
|
|
5079
|
+
if (!view)
|
|
5080
|
+
return;
|
|
5081
|
+
const shift = bandShift(view.scrollY, view.innerHeight, wide / picture.width);
|
|
5082
|
+
image.style.transform = `translate3d(0, ${shift}px, 0)`;
|
|
5083
|
+
} catch {}
|
|
5084
|
+
};
|
|
5085
|
+
const paint = async () => {
|
|
5086
|
+
waiting = 0;
|
|
5087
|
+
if (band.hidden || painting)
|
|
5088
|
+
return;
|
|
5089
|
+
const key = keyOf();
|
|
5090
|
+
if (key === null) {
|
|
5091
|
+
image?.remove();
|
|
5092
|
+
image = null;
|
|
5093
|
+
picture = null;
|
|
5094
|
+
return;
|
|
5095
|
+
}
|
|
5096
|
+
if (!changed && key === taken)
|
|
5097
|
+
return;
|
|
5098
|
+
painting = true;
|
|
5099
|
+
changed = false;
|
|
5100
|
+
const start = performance.now();
|
|
5101
|
+
let next = null;
|
|
5102
|
+
try {
|
|
5103
|
+
next = pictureOf(frame2);
|
|
5104
|
+
} catch {
|
|
5105
|
+
next = null;
|
|
5106
|
+
}
|
|
5107
|
+
const fresh2 = new Image;
|
|
5108
|
+
let drawn = false;
|
|
5109
|
+
if (next) {
|
|
5110
|
+
fresh2.src = next.src;
|
|
5111
|
+
drawn = await fresh2.decode().then(() => true, () => false);
|
|
5112
|
+
}
|
|
5113
|
+
cost = performance.now() - start;
|
|
5114
|
+
last = performance.now();
|
|
5115
|
+
performance.measure("devknobs underbar picture", { start, duration: cost });
|
|
5116
|
+
painting = false;
|
|
5117
|
+
if (!next || !drawn)
|
|
5118
|
+
return;
|
|
5119
|
+
fresh2.alt = "";
|
|
5120
|
+
if (image)
|
|
5121
|
+
image.replaceWith(fresh2);
|
|
5122
|
+
else
|
|
5123
|
+
band.append(fresh2);
|
|
5124
|
+
image = fresh2;
|
|
5125
|
+
picture = next;
|
|
5126
|
+
taken = key;
|
|
5127
|
+
fit();
|
|
5128
|
+
if (changed)
|
|
5129
|
+
soon();
|
|
5130
|
+
};
|
|
5131
|
+
function soon() {
|
|
5132
|
+
if (waiting || band.hidden)
|
|
5133
|
+
return;
|
|
5134
|
+
const wait = Math.max(0, last + Math.max(GAP, cost * SHARE) - performance.now());
|
|
5135
|
+
waiting = window.setTimeout(() => void paint(), wait);
|
|
5136
|
+
}
|
|
5137
|
+
function fit() {
|
|
5138
|
+
if (!image || !picture)
|
|
5139
|
+
return;
|
|
5140
|
+
image.style.width = `${wide}px`;
|
|
5141
|
+
image.style.height = `${picture.height * wide / picture.width}px`;
|
|
5142
|
+
move();
|
|
5143
|
+
}
|
|
5144
|
+
return {
|
|
5145
|
+
show(rect, zoom, look) {
|
|
5146
|
+
const on = rect !== null && look !== null;
|
|
5147
|
+
band.hidden = !on;
|
|
5148
|
+
if (!rect || !look) {
|
|
5149
|
+
clearTimeout(waiting);
|
|
5150
|
+
waiting = 0;
|
|
5151
|
+
return;
|
|
5152
|
+
}
|
|
5153
|
+
place(band, rect.x * zoom, rect.y * zoom, rect.width, rect.height);
|
|
5154
|
+
wide = rect.width;
|
|
5155
|
+
band.style.transform = zoom === 1 ? "" : `scale(${zoom})`;
|
|
5156
|
+
band.style.background = look.background;
|
|
5157
|
+
const key = keyOf();
|
|
5158
|
+
if (key !== taken || changed)
|
|
5159
|
+
soon();
|
|
5160
|
+
fit();
|
|
5161
|
+
},
|
|
5162
|
+
move,
|
|
5163
|
+
refresh() {
|
|
5164
|
+
changed = true;
|
|
5165
|
+
soon();
|
|
5166
|
+
},
|
|
5167
|
+
remove() {
|
|
5168
|
+
clearTimeout(waiting);
|
|
5169
|
+
observer?.disconnect();
|
|
5170
|
+
observer = null;
|
|
5171
|
+
watched2 = null;
|
|
5172
|
+
band.remove();
|
|
5173
|
+
}
|
|
5174
|
+
};
|
|
4726
5175
|
}
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
uniform float dark;
|
|
4745
|
-
uniform vec2 shape;
|
|
4746
|
-
uniform vec2 rimmed;
|
|
4747
|
-
uniform vec3 band;
|
|
4748
|
-
uniform vec3 lit;
|
|
4749
|
-
uniform vec2 run;
|
|
4750
|
-
uniform vec3 wiped;
|
|
4751
|
-
uniform vec2 soften;
|
|
4752
|
-
uniform float grain;
|
|
4753
|
-
uniform float px;
|
|
4754
|
-
in vec2 pos;
|
|
4755
|
-
out vec4 color;
|
|
4756
|
-
const float WEIGHTS[3] = float[3](${WEIGHTS.join(", ")});
|
|
4757
|
-
float cover(float at, float span, float soft) {
|
|
4758
|
-
return smoothstep(-soft, soft, at) * (1.0 - smoothstep(span - soft, span + soft, at));
|
|
5176
|
+
|
|
5177
|
+
// src/engine/browserdraw.ts
|
|
5178
|
+
var BARS_CSS = `
|
|
5179
|
+
.browser {
|
|
5180
|
+
position: absolute;
|
|
5181
|
+
top: 0;
|
|
5182
|
+
left: 0;
|
|
5183
|
+
overflow: hidden;
|
|
5184
|
+
transform-origin: 0 0;
|
|
5185
|
+
pointer-events: none;
|
|
5186
|
+
cursor: default;
|
|
5187
|
+
user-select: none;
|
|
5188
|
+
-webkit-user-select: none;
|
|
5189
|
+
font-family: ${FONT};
|
|
5190
|
+
font-weight: 400;
|
|
5191
|
+
-webkit-font-smoothing: antialiased;
|
|
5192
|
+
line-height: 1;
|
|
4759
5193
|
}
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
5194
|
+
.browser > *,
|
|
5195
|
+
.browser > * > *,
|
|
5196
|
+
.browser .group > * {
|
|
5197
|
+
position: absolute;
|
|
5198
|
+
box-sizing: border-box;
|
|
4765
5199
|
}
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
5200
|
+
.browser svg { overflow: visible; }
|
|
5201
|
+
.browser .press { pointer-events: auto; cursor: default; }
|
|
5202
|
+
${SAFARI_CSS}
|
|
5203
|
+
${CHROME_CSS}
|
|
5204
|
+
${UNDERBAR_CSS}
|
|
5205
|
+
`;
|
|
5206
|
+
var BUILDERS = { safari: buildSafari, chrome: buildChrome };
|
|
5207
|
+
function toRgb(color) {
|
|
5208
|
+
const parsed = parseColor(color);
|
|
5209
|
+
if (parsed)
|
|
5210
|
+
return parsed;
|
|
5211
|
+
try {
|
|
5212
|
+
const canvas = document.createElement("canvas");
|
|
5213
|
+
canvas.width = 1;
|
|
5214
|
+
canvas.height = 1;
|
|
5215
|
+
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
5216
|
+
if (!context)
|
|
5217
|
+
return null;
|
|
5218
|
+
context.fillStyle = color;
|
|
5219
|
+
context.fillRect(0, 0, 1, 1);
|
|
5220
|
+
const [r = 0, g = 0, b = 0, a = 0] = context.getImageData(0, 0, 1, 1).data;
|
|
5221
|
+
return { red: r, green: g, blue: b, alpha: a / 255 };
|
|
5222
|
+
} catch {
|
|
5223
|
+
return null;
|
|
5224
|
+
}
|
|
4774
5225
|
}
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
5226
|
+
function backgroundOf(doc, view, dark) {
|
|
5227
|
+
const root = view.getComputedStyle(doc.documentElement);
|
|
5228
|
+
const schemes = root.colorScheme ?? "";
|
|
5229
|
+
const canvasDark = schemes.includes("dark") && (dark || !schemes.includes("light"));
|
|
5230
|
+
let base = canvasDark ? [18, 18, 18] : [255, 255, 255];
|
|
5231
|
+
const layers = [doc.documentElement, doc.body].filter((node) => !!node);
|
|
5232
|
+
for (const node of layers) {
|
|
5233
|
+
const color = toRgb(view.getComputedStyle(node).backgroundColor);
|
|
5234
|
+
if (!color || color.alpha === 0)
|
|
5235
|
+
continue;
|
|
5236
|
+
const { red, green, blue, alpha } = color;
|
|
5237
|
+
const [r, g, b] = base;
|
|
5238
|
+
const over2 = (top, under) => Math.round(top * alpha + under * (1 - alpha));
|
|
5239
|
+
base = [over2(red, r), over2(green, g), over2(blue, b)];
|
|
4779
5240
|
}
|
|
4780
|
-
return
|
|
5241
|
+
return base;
|
|
4781
5242
|
}
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
return cover(dot(along, at), dot(along, stage), soft) * (1.0 - smoothstep(free - reach, free + reach, dot(line.xy, at) + line.z));
|
|
5243
|
+
function rgbOf(color) {
|
|
5244
|
+
return `rgb(${Math.round(color.red)}, ${Math.round(color.green)}, ${Math.round(color.blue)})`;
|
|
4785
5245
|
}
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
vec2 down = dFdy(pos) * texels;
|
|
4790
|
-
float sharp = 0.5 * log2(max(1.0, max(dot(right, right), dot(down, down))));
|
|
4791
|
-
float t = clamp(dot(line.xy, pos) + line.z, 0.0, 1.0);
|
|
4792
|
-
float span = dot(along, stage);
|
|
4793
|
-
float at = dot(along, pos);
|
|
4794
|
-
float across = free > 0.0 ? min(1.0, t / free) : 1.0;
|
|
4795
|
-
float wide = peak * (shape.x + (1.0 - shape.x) * pow(across, shape.y));
|
|
4796
|
-
float rim = mix(edge.x, edge.y, t);
|
|
4797
|
-
if (rim > 0.0) wide = max(wide, rim * (1.0 - smoothstep(0.0, rimmed.x * rim, min(at, span - at))));
|
|
4798
|
-
float gap = rimmed.y * wide;
|
|
4799
|
-
float soft = max(0.5 * px, 0.75 * gap);
|
|
4800
|
-
float lod = max(sharp, log2(max(1.0, gap * max(texels.x, texels.y))));
|
|
4801
|
-
vec3 sum = vec3(0.0);
|
|
4802
|
-
if (peak + edge.x + edge.y <= 0.0) {
|
|
4803
|
-
sum = textureLod(page, pos / stage, lod).rgb * seen(pos, soft);
|
|
4804
|
-
} else {
|
|
4805
|
-
for (int y = -2; y <= 2; y++) {
|
|
4806
|
-
for (int x = -2; x <= 2; x++) {
|
|
4807
|
-
vec2 tap = pos + vec2(float(x), float(y)) * gap;
|
|
4808
|
-
float weight = WEIGHTS[abs(x)] * WEIGHTS[abs(y)];
|
|
4809
|
-
sum += textureLod(page, tap / stage, lod).rgb * seen(tap, soft) * weight;
|
|
4810
|
-
}
|
|
4811
|
-
}
|
|
4812
|
-
}
|
|
4813
|
-
color = shaded(sum, t);
|
|
4814
|
-
}`;
|
|
4815
|
-
function compile(gl, kind, source) {
|
|
4816
|
-
const shader = gl.createShader(kind);
|
|
4817
|
-
if (!shader)
|
|
4818
|
-
return null;
|
|
4819
|
-
gl.shaderSource(shader, source);
|
|
4820
|
-
gl.compileShader(shader);
|
|
4821
|
-
return shader;
|
|
5246
|
+
function blend({ red, green, blue, alpha }, [r, g, b]) {
|
|
5247
|
+
const over2 = (top, below) => Math.round(top * alpha + below * (1 - alpha));
|
|
5248
|
+
return [over2(red, r), over2(green, g), over2(blue, b)];
|
|
4822
5249
|
}
|
|
4823
|
-
function
|
|
4824
|
-
return
|
|
4825
|
-
`)[0]?.trim() || otherwise;
|
|
5250
|
+
function rgbText([r, g, b]) {
|
|
5251
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
4826
5252
|
}
|
|
4827
|
-
function
|
|
4828
|
-
const
|
|
4829
|
-
|
|
4830
|
-
return `the picture could not be uploaded: ${name}${name === "SecurityError" ? `, ${tainted}` : ""}`;
|
|
5253
|
+
function paintOf(view, node) {
|
|
5254
|
+
const color = toRgb(view.getComputedStyle(node).backgroundColor);
|
|
5255
|
+
return color && color.alpha > 0 ? color : null;
|
|
4831
5256
|
}
|
|
4832
|
-
function
|
|
4833
|
-
const
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
5257
|
+
function solidOf(view, node) {
|
|
5258
|
+
const color = paintOf(view, node);
|
|
5259
|
+
return color && color.alpha >= 0.5 ? color : null;
|
|
5260
|
+
}
|
|
5261
|
+
function barAt(doc, view, x, y, edge, base) {
|
|
5262
|
+
let paint = null;
|
|
5263
|
+
for (let node = doc.elementFromPoint(x, y);node; node = node.parentElement) {
|
|
5264
|
+
if (node === doc.body || node === doc.documentElement)
|
|
5265
|
+
return null;
|
|
5266
|
+
paint ??= solidOf(view, node);
|
|
5267
|
+
const { position } = view.getComputedStyle(node);
|
|
5268
|
+
if (position !== "fixed" && position !== "sticky")
|
|
5269
|
+
continue;
|
|
5270
|
+
const box2 = node.getBoundingClientRect();
|
|
5271
|
+
const touches = edge === "top" ? box2.top <= 0.5 : box2.bottom >= view.innerHeight - 0.5;
|
|
5272
|
+
return touches && paint ? rgbText(blend(paint, base)) : null;
|
|
4838
5273
|
}
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
const
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
gl.deleteShader(vertex2);
|
|
4860
|
-
gl.deleteShader(fragment);
|
|
4861
|
-
gl.getExtension("WEBGL_lose_context")?.loseContext();
|
|
4862
|
-
canvas.remove();
|
|
4863
|
-
};
|
|
4864
|
-
if (!vertex2 || !fragment || !program || !corners || !texture) {
|
|
4865
|
-
const why = gl.isContextLost() ? "the WebGL2 context was lost as it was made" : "WebGL2 made no shader, program, buffer or texture";
|
|
4866
|
-
free();
|
|
4867
|
-
refused(why, null);
|
|
4868
|
-
return null;
|
|
5274
|
+
return null;
|
|
5275
|
+
}
|
|
5276
|
+
function edgeBar(doc, view, edge, base) {
|
|
5277
|
+
const width = view.innerWidth;
|
|
5278
|
+
const y = edge === "top" ? 0.5 : view.innerHeight - 1;
|
|
5279
|
+
const colors = [width / 2, 1, width - 1].map((x) => barAt(doc, view, x, y, edge, base));
|
|
5280
|
+
const [middle = null] = colors;
|
|
5281
|
+
return colors.every((color) => color !== null) ? middle : null;
|
|
5282
|
+
}
|
|
5283
|
+
function colorAt(doc, view, x, y, base) {
|
|
5284
|
+
const layers = [];
|
|
5285
|
+
for (const node of doc.elementsFromPoint(x, y)) {
|
|
5286
|
+
if (node === doc.body || node === doc.documentElement)
|
|
5287
|
+
break;
|
|
5288
|
+
const color = layers.length === 0 ? solidOf(view, node) : paintOf(view, node);
|
|
5289
|
+
if (!color)
|
|
5290
|
+
continue;
|
|
5291
|
+
layers.push(color);
|
|
5292
|
+
if (color.alpha >= 1)
|
|
5293
|
+
break;
|
|
4869
5294
|
}
|
|
4870
|
-
|
|
4871
|
-
gl.attachShader(program, fragment);
|
|
4872
|
-
gl.linkProgram(program);
|
|
4873
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
4874
|
-
const log = [vertex2, fragment].map((shader) => gl.getShaderInfoLog(shader)).find((said) => said?.trim()) ?? gl.getProgramInfoLog(program);
|
|
4875
|
-
const lost = gl.isContextLost();
|
|
4876
|
-
free();
|
|
4877
|
-
refused(lost ? "the WebGL2 context was lost as it was made" : `the shader did not compile or link: ${firstLine(log, "no reason given")}`, null);
|
|
5295
|
+
if (layers.length === 0)
|
|
4878
5296
|
return null;
|
|
5297
|
+
return rgbText(layers.reduceRight((under, color) => blend(color, under), base));
|
|
5298
|
+
}
|
|
5299
|
+
function readLook(frame2, probe = null) {
|
|
5300
|
+
const white = "rgb(255, 255, 255)";
|
|
5301
|
+
const fallback = {
|
|
5302
|
+
background: white,
|
|
5303
|
+
top: white,
|
|
5304
|
+
bottom: white,
|
|
5305
|
+
header: false,
|
|
5306
|
+
footer: false,
|
|
5307
|
+
under: [],
|
|
5308
|
+
dark: false,
|
|
5309
|
+
scheme: "light",
|
|
5310
|
+
host: "",
|
|
5311
|
+
canBack: false,
|
|
5312
|
+
canForward: false
|
|
5313
|
+
};
|
|
5314
|
+
try {
|
|
5315
|
+
const view = frame2.contentWindow;
|
|
5316
|
+
const doc = frame2.contentDocument;
|
|
5317
|
+
if (!view || !doc?.documentElement)
|
|
5318
|
+
return fallback;
|
|
5319
|
+
const scheme = view.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
5320
|
+
const base = backgroundOf(doc, view, scheme === "dark");
|
|
5321
|
+
const [r, g, b] = base;
|
|
5322
|
+
const background = rgbText(base);
|
|
5323
|
+
const header = edgeBar(doc, view, "top", base);
|
|
5324
|
+
const top = header ?? background;
|
|
5325
|
+
const last = () => colorAt(doc, view, view.innerWidth / 2, view.innerHeight - 1, base);
|
|
5326
|
+
const footer = edgeBar(doc, view, "bottom", base);
|
|
5327
|
+
const bottom = footer ?? last() ?? background;
|
|
5328
|
+
const under = (probe?.points ?? []).map(({ x, y }) => {
|
|
5329
|
+
const { page } = probe ?? { page: { x: 0, y: 0, width: 0, height: 0 } };
|
|
5330
|
+
const inside = { x: x - page.x, y: y - page.y };
|
|
5331
|
+
if (inside.y < 0)
|
|
5332
|
+
return { x, y, color: top };
|
|
5333
|
+
if (inside.x < 0 || inside.x >= page.width)
|
|
5334
|
+
return { x, y, color: background };
|
|
5335
|
+
if (inside.y >= page.height)
|
|
5336
|
+
return { x, y, color: bottom };
|
|
5337
|
+
const across = Math.min(Math.max(inside.x, 0), page.width - 1);
|
|
5338
|
+
return { x, y, color: colorAt(doc, view, across, inside.y, base) ?? background };
|
|
5339
|
+
});
|
|
5340
|
+
const navigation = navigationOf(view);
|
|
5341
|
+
const can = (key) => {
|
|
5342
|
+
const value = navigation && Reflect.get(navigation, key);
|
|
5343
|
+
return typeof value === "boolean" ? value : null;
|
|
5344
|
+
};
|
|
5345
|
+
return {
|
|
5346
|
+
background,
|
|
5347
|
+
top,
|
|
5348
|
+
bottom,
|
|
5349
|
+
header: header !== null,
|
|
5350
|
+
footer: footer !== null,
|
|
5351
|
+
under,
|
|
5352
|
+
dark: luminance(r, g, b) < 0.4,
|
|
5353
|
+
scheme,
|
|
5354
|
+
host: view.location.host,
|
|
5355
|
+
canBack: can("canGoBack") ?? view.history.length > 1,
|
|
5356
|
+
canForward: can("canGoForward") ?? false
|
|
5357
|
+
};
|
|
5358
|
+
} catch {
|
|
5359
|
+
return fallback;
|
|
4879
5360
|
}
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
const
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
const
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
5361
|
+
}
|
|
5362
|
+
function screenFill(look, bars, page, height) {
|
|
5363
|
+
const strip = bars.status || bars.column || !runsUnderBars(bars.screen.id);
|
|
5364
|
+
if (bars.platform !== "safari" || !strip || !page)
|
|
5365
|
+
return look.background;
|
|
5366
|
+
const held = look.top !== look.background;
|
|
5367
|
+
const top = bars.scrim && !held ? rgbOf(underAt(look, bars.scrim.at.x, bars.scrim.at.y)) : look.top;
|
|
5368
|
+
if (top === look.background && look.bottom === look.background)
|
|
5369
|
+
return look.background;
|
|
5370
|
+
const start = page.y / height * 100;
|
|
5371
|
+
const end = (page.y + page.height) / height * 100;
|
|
5372
|
+
const { background: middle, bottom } = look;
|
|
5373
|
+
const strips = `linear-gradient(to bottom, ${top} ${start}%, ${middle} ${start}%, ${middle} ${end}%, ${bottom} ${end}%)`;
|
|
5374
|
+
const W = turn(bars.screen, bars.orientation).width;
|
|
5375
|
+
const [left, right] = [page.x / W * 100, (page.x + page.width) / W * 100];
|
|
5376
|
+
if (left <= 0 && right >= 100)
|
|
5377
|
+
return strips;
|
|
5378
|
+
const column = `linear-gradient(to right, ${middle} ${left}%, transparent ${left}%, transparent ${right}%, ${middle} ${right}%)`;
|
|
5379
|
+
return `${column}, ${strips}`;
|
|
5380
|
+
}
|
|
5381
|
+
function reaches(frame2) {
|
|
5382
|
+
try {
|
|
5383
|
+
return !!frame2.contentDocument?.documentElement;
|
|
5384
|
+
} catch {
|
|
5385
|
+
return false;
|
|
5386
|
+
}
|
|
5387
|
+
}
|
|
5388
|
+
var RESTYLE = 120;
|
|
5389
|
+
var LOAD_WAIT = 5000;
|
|
5390
|
+
function same(a, b) {
|
|
5391
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
5392
|
+
}
|
|
5393
|
+
function createBrowser(glass, frame2, onChange, onReload = () => {}, ready = () => true) {
|
|
5394
|
+
const blank = el("div", "screenblank");
|
|
5395
|
+
blank.hidden = true;
|
|
5396
|
+
glass.append(blank);
|
|
5397
|
+
const band = createUnderbar(glass, frame2);
|
|
5398
|
+
const layer = el("div", "browser");
|
|
5399
|
+
layer.setAttribute("aria-hidden", "true");
|
|
5400
|
+
const seams = [el("div", "seam"), el("div", "seam")];
|
|
5401
|
+
for (const seam of seams) {
|
|
5402
|
+
seam.setAttribute("aria-hidden", "true");
|
|
5403
|
+
seam.style.cssText = "position:absolute;pointer-events:none";
|
|
5404
|
+
seam.hidden = true;
|
|
5405
|
+
}
|
|
5406
|
+
let view = null;
|
|
4907
5407
|
let look = null;
|
|
4908
|
-
let
|
|
4909
|
-
|
|
5408
|
+
let painted = null;
|
|
5409
|
+
let built = "";
|
|
5410
|
+
let applied = null;
|
|
5411
|
+
let shrinking = 0;
|
|
5412
|
+
let shrinkTo = null;
|
|
5413
|
+
let later = 0;
|
|
5414
|
+
let query = null;
|
|
5415
|
+
let watched2 = null;
|
|
5416
|
+
let href = "";
|
|
5417
|
+
let motion = BARS_START;
|
|
5418
|
+
let landed = false;
|
|
5419
|
+
let busy = false;
|
|
5420
|
+
let loadWait = 0;
|
|
5421
|
+
let sampling = 0;
|
|
5422
|
+
const still2 = () => baseMatchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
5423
|
+
const step = (event) => {
|
|
5424
|
+
const before = motion.minimized;
|
|
5425
|
+
motion = barsStep(motion, event);
|
|
5426
|
+
if (motion.minimized !== before)
|
|
5427
|
+
queueMicrotask(onChange);
|
|
5428
|
+
};
|
|
5429
|
+
const probe = () => {
|
|
5430
|
+
const bars = view?.bars ?? null;
|
|
5431
|
+
if (!view || !bars || bars.platform !== "safari")
|
|
5432
|
+
return null;
|
|
5433
|
+
const { screen, orientation, layout, minimized, edge } = bars;
|
|
5434
|
+
const other = barsOf(screen, orientation, layout, !minimized, edge);
|
|
5435
|
+
const shapes = [...bars.shapes, ...other?.shapes ?? []];
|
|
5436
|
+
const points = shapes.map((shape) => ({
|
|
5437
|
+
x: shape.x + shape.width / 2,
|
|
5438
|
+
y: shape.y + shape.height / 2
|
|
5439
|
+
}));
|
|
5440
|
+
const scrim = bars.scrim ?? other?.scrim;
|
|
5441
|
+
if (scrim)
|
|
5442
|
+
points.push(scrim.at);
|
|
5443
|
+
return { page: view.page ?? { x: 0, y: 0, ...view.size }, points };
|
|
5444
|
+
};
|
|
5445
|
+
const lookNow = () => readLook(frame2, probe());
|
|
5446
|
+
const placeBand = () => {
|
|
5447
|
+
const bars = view?.bars ?? null;
|
|
5448
|
+
const shown2 = view && showsBand(bars, look) && reaches(frame2) ? bandRect(applied, view.size.height) : null;
|
|
5449
|
+
band.show(shown2, view?.zoom ?? 1, look);
|
|
5450
|
+
placeSeams();
|
|
5451
|
+
};
|
|
5452
|
+
const placeSeams = () => {
|
|
5453
|
+
const ratio = glass.offsetWidth > 0 ? glass.getBoundingClientRect().width / glass.offsetWidth : 1;
|
|
5454
|
+
const unit = 1 / ((window.devicePixelRatio || 1) * (ratio || 1));
|
|
5455
|
+
const rects = look && reaches(frame2) ? seamRects(applied, view?.zoom ?? 1, unit, look) : { top: null, bottom: null };
|
|
5456
|
+
const colors = [look?.top ?? "", look?.bottom ?? ""];
|
|
5457
|
+
[rects.top, rects.bottom].forEach((rect, index) => {
|
|
5458
|
+
const seam = seams[index];
|
|
5459
|
+
if (!seam)
|
|
5460
|
+
return;
|
|
5461
|
+
seam.hidden = rect === null;
|
|
5462
|
+
if (!rect)
|
|
5463
|
+
return;
|
|
5464
|
+
if (!seam.isConnected)
|
|
5465
|
+
glass.insertBefore(seam, layer.isConnected ? layer : null);
|
|
5466
|
+
place(seam, rect.x, rect.y, rect.width, rect.height);
|
|
5467
|
+
seam.style.background = colors[index] ?? "";
|
|
5468
|
+
});
|
|
5469
|
+
};
|
|
5470
|
+
const resample = () => {
|
|
5471
|
+
sampling = 0;
|
|
5472
|
+
const bars = view?.bars;
|
|
5473
|
+
if (busy || !look || !view || !bars || bars.platform !== "safari")
|
|
5474
|
+
return;
|
|
5475
|
+
const next = lookNow();
|
|
5476
|
+
if (JSON.stringify(next) === JSON.stringify(look))
|
|
5477
|
+
return;
|
|
4910
5478
|
look = next;
|
|
4911
|
-
|
|
5479
|
+
glass.style.background = screenFill(look, bars, view.page, view.size.height);
|
|
5480
|
+
back();
|
|
5481
|
+
placeBand();
|
|
5482
|
+
painted?.apply(bars.minimized, look);
|
|
5483
|
+
};
|
|
5484
|
+
const growth = () => {
|
|
5485
|
+
const bars = view?.bars;
|
|
5486
|
+
if (!bars)
|
|
5487
|
+
return { room: 0, grow: 0 };
|
|
5488
|
+
const { screen, orientation, layout, edge } = bars;
|
|
5489
|
+
const [full, mini] = [false, true].map((minimized) => viewportOf(screen, orientation, layout, minimized, edge));
|
|
5490
|
+
if (!full || !mini)
|
|
5491
|
+
return { room: 0, grow: 0 };
|
|
5492
|
+
return { room: Math.max(0, full.y - mini.y), grow: Math.max(0, mini.height - full.height) };
|
|
5493
|
+
};
|
|
5494
|
+
const onScroll = () => {
|
|
5495
|
+
band.move();
|
|
5496
|
+
landed = false;
|
|
5497
|
+
const page = frame2.contentWindow;
|
|
5498
|
+
if (page) {
|
|
5499
|
+
const { room, grow } = growth();
|
|
5500
|
+
const tall = frame2.contentDocument?.documentElement?.scrollHeight;
|
|
5501
|
+
const rest = typeof tall === "number" ? tall - page.innerHeight - grow : Number.POSITIVE_INFINITY;
|
|
5502
|
+
step({ type: "scroll", y: page.scrollY, time: performance.now(), room, rest });
|
|
5503
|
+
}
|
|
5504
|
+
if (!sampling)
|
|
5505
|
+
sampling = window.requestAnimationFrame(resample);
|
|
5506
|
+
};
|
|
5507
|
+
const actions = {
|
|
5508
|
+
back: () => frame2.contentWindow?.history.back(),
|
|
5509
|
+
forward: () => frame2.contentWindow?.history.forward(),
|
|
5510
|
+
reload: () => {
|
|
5511
|
+
if (busy) {
|
|
5512
|
+
frame2.contentWindow?.stop();
|
|
5513
|
+
stopLoading();
|
|
5514
|
+
return;
|
|
5515
|
+
}
|
|
5516
|
+
onReload();
|
|
5517
|
+
keep(frame2.contentWindow, "frame");
|
|
5518
|
+
frame2.contentWindow?.location.reload();
|
|
5519
|
+
},
|
|
5520
|
+
expand: () => step({ type: "tap" })
|
|
5521
|
+
};
|
|
5522
|
+
const sizeFrame = () => {
|
|
5523
|
+
if (!view)
|
|
5524
|
+
return;
|
|
5525
|
+
const before = applied;
|
|
5526
|
+
view.sizeFrame();
|
|
5527
|
+
const page = view.page;
|
|
5528
|
+
if (!same(page, applied))
|
|
5529
|
+
step({ type: "resize", time: performance.now() });
|
|
5530
|
+
applied = page;
|
|
5531
|
+
const moved2 = before && page && before.y !== page.y && before.x === page.x && before.width === page.width;
|
|
5532
|
+
if (moved2) {
|
|
5533
|
+
const fresh2 = landed;
|
|
5534
|
+
landed = false;
|
|
5535
|
+
try {
|
|
5536
|
+
if (!fresh2)
|
|
5537
|
+
frame2.contentWindow?.scrollBy({ top: page.y - before.y, behavior: "instant" });
|
|
5538
|
+
} catch {}
|
|
5539
|
+
}
|
|
5540
|
+
placeBand();
|
|
5541
|
+
};
|
|
5542
|
+
const stopShrink = () => {
|
|
5543
|
+
clearTimeout(shrinking);
|
|
5544
|
+
shrinking = 0;
|
|
5545
|
+
shrinkTo = null;
|
|
5546
|
+
};
|
|
5547
|
+
const placeFrame = (instant) => {
|
|
5548
|
+
const page = view?.page ?? null;
|
|
5549
|
+
const shrinks = !instant && page && applied && page.height < applied.height && page.y === applied.y;
|
|
5550
|
+
if (shrinks && shrinking && same(page, shrinkTo))
|
|
5551
|
+
return;
|
|
5552
|
+
stopShrink();
|
|
5553
|
+
if (!shrinks) {
|
|
5554
|
+
sizeFrame();
|
|
5555
|
+
return;
|
|
5556
|
+
}
|
|
5557
|
+
shrinkTo = page;
|
|
5558
|
+
shrinking = window.setTimeout(() => {
|
|
5559
|
+
shrinking = 0;
|
|
5560
|
+
shrinkTo = null;
|
|
5561
|
+
if (same(view?.page ?? null, page))
|
|
5562
|
+
sizeFrame();
|
|
5563
|
+
}, MORPH.expand);
|
|
5564
|
+
};
|
|
5565
|
+
const back = () => {
|
|
5566
|
+
frame2.style.background = reaches(frame2) ? (look ??= lookNow()).background : "";
|
|
5567
|
+
};
|
|
5568
|
+
const draw = () => {
|
|
5569
|
+
const bars = view?.bars ?? null;
|
|
5570
|
+
if (!view || !bars) {
|
|
5571
|
+
stopShrink();
|
|
5572
|
+
layer.replaceChildren();
|
|
5573
|
+
glass.style.background = "";
|
|
5574
|
+
back();
|
|
5575
|
+
painted = null;
|
|
5576
|
+
built = "";
|
|
5577
|
+
if (view)
|
|
5578
|
+
sizeFrame();
|
|
5579
|
+
placeBand();
|
|
4912
5580
|
return;
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
5581
|
+
}
|
|
5582
|
+
look ??= lookNow();
|
|
5583
|
+
glass.style.background = screenFill(look, bars, view.page, view.size.height);
|
|
5584
|
+
back();
|
|
5585
|
+
placeBand();
|
|
5586
|
+
const { platform, layout, screen, orientation, edge } = bars;
|
|
5587
|
+
const base = JSON.stringify([platform, layout, screen, orientation, edge, view.follow]);
|
|
5588
|
+
const fresh2 = base !== built || !painted;
|
|
5589
|
+
const instant = fresh2 || still2();
|
|
5590
|
+
if (fresh2) {
|
|
5591
|
+
const other = barsOf(screen, orientation, layout, !bars.minimized, edge);
|
|
5592
|
+
const full = bars.minimized ? other : bars;
|
|
5593
|
+
const mini = bars.minimized ? bars : other;
|
|
5594
|
+
const shown2 = { ...actions, expand: view.follow ? actions.expand : undefined };
|
|
5595
|
+
if (!full || !mini)
|
|
5596
|
+
return;
|
|
5597
|
+
painted = BUILDERS[bars.platform](full, mini, look, shown2);
|
|
5598
|
+
layer.replaceChildren(painted.root);
|
|
5599
|
+
built = base;
|
|
5600
|
+
if (busy)
|
|
5601
|
+
painted.loading?.(true, true);
|
|
5602
|
+
}
|
|
5603
|
+
if (instant)
|
|
5604
|
+
layer.setAttribute("data-instant", "");
|
|
5605
|
+
painted?.apply(bars.minimized, look);
|
|
5606
|
+
if (instant) {
|
|
5607
|
+
layer.offsetWidth;
|
|
5608
|
+
layer.removeAttribute("data-instant");
|
|
5609
|
+
}
|
|
5610
|
+
placeFrame(instant);
|
|
4923
5611
|
};
|
|
4924
|
-
|
|
4925
|
-
|
|
5612
|
+
const pageOf = () => {
|
|
5613
|
+
try {
|
|
5614
|
+
return frame2.contentDocument;
|
|
5615
|
+
} catch {
|
|
5616
|
+
return null;
|
|
5617
|
+
}
|
|
5618
|
+
};
|
|
5619
|
+
const showLoading = (on, seed) => {
|
|
5620
|
+
busy = on;
|
|
5621
|
+
if (seed) {
|
|
5622
|
+
look = seed;
|
|
5623
|
+
draw();
|
|
5624
|
+
}
|
|
5625
|
+
painted?.loading?.(on, still2());
|
|
5626
|
+
if (!on)
|
|
5627
|
+
browser.refresh();
|
|
5628
|
+
};
|
|
5629
|
+
const stopLoading = () => {
|
|
5630
|
+
if (loadWait)
|
|
5631
|
+
window.cancelAnimationFrame(loadWait);
|
|
5632
|
+
loadWait = 0;
|
|
5633
|
+
if (!busy)
|
|
4926
5634
|
return;
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
refused("the WebGL2 context was lost", shot);
|
|
4930
|
-
});
|
|
4931
|
-
const refuse = (why, next) => {
|
|
4932
|
-
if (!gone)
|
|
4933
|
-
free();
|
|
4934
|
-
gone = true;
|
|
4935
|
-
refused(why, next);
|
|
5635
|
+
blank.hidden = true;
|
|
5636
|
+
showLoading(false, null);
|
|
4936
5637
|
};
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
5638
|
+
const startLoading = (seed) => {
|
|
5639
|
+
blank.style.background = (seed ?? look ?? lookNow()).background;
|
|
5640
|
+
blank.hidden = false;
|
|
5641
|
+
showLoading(true, seed);
|
|
5642
|
+
if (loadWait)
|
|
5643
|
+
window.cancelAnimationFrame(loadWait);
|
|
5644
|
+
const end = performance.now() + LOAD_WAIT;
|
|
5645
|
+
const gone = pageOf();
|
|
5646
|
+
const check = () => {
|
|
5647
|
+
loadWait = 0;
|
|
5648
|
+
const next = gone === null || pageOf() !== gone;
|
|
5649
|
+
if (next && ready() || performance.now() >= end)
|
|
5650
|
+
stopLoading();
|
|
5651
|
+
else
|
|
5652
|
+
loadWait = window.requestAnimationFrame(check);
|
|
5653
|
+
};
|
|
5654
|
+
loadWait = window.requestAnimationFrame(check);
|
|
5655
|
+
};
|
|
5656
|
+
const read = () => {
|
|
5657
|
+
try {
|
|
5658
|
+
const page = frame2.contentWindow;
|
|
5659
|
+
const doc = frame2.contentDocument;
|
|
5660
|
+
const arrived = doc !== watched2;
|
|
5661
|
+
if (page && doc && doc !== watched2) {
|
|
5662
|
+
query?.removeEventListener("change", read);
|
|
5663
|
+
query = page.matchMedia("(prefers-color-scheme: dark)");
|
|
5664
|
+
query.addEventListener("change", read);
|
|
5665
|
+
page.addEventListener("scroll", onScroll, { passive: true });
|
|
5666
|
+
watched2 = doc;
|
|
4944
5667
|
}
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
5668
|
+
const now = page?.location.href ?? "";
|
|
5669
|
+
if (now !== href) {
|
|
5670
|
+
href = now;
|
|
5671
|
+
landed = arrived;
|
|
5672
|
+
step({ type: "navigate" });
|
|
4950
5673
|
}
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
return refuse(`the picture could not be uploaded: WebGL2 error 0x${failed.toString(16)}`, next);
|
|
4954
|
-
gl.generateMipmap(gl.TEXTURE_2D);
|
|
4955
|
-
shot = next;
|
|
4956
|
-
if (look)
|
|
4957
|
-
draw(look);
|
|
4958
|
-
},
|
|
4959
|
-
draw,
|
|
4960
|
-
release() {
|
|
4961
|
-
if (gone)
|
|
4962
|
-
return;
|
|
4963
|
-
gone = true;
|
|
4964
|
-
free();
|
|
5674
|
+
} catch {
|
|
5675
|
+
query = null;
|
|
4965
5676
|
}
|
|
5677
|
+
if (!busy || !look)
|
|
5678
|
+
look = lookNow();
|
|
5679
|
+
draw();
|
|
4966
5680
|
};
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
if (counted && next)
|
|
5021
|
-
at++;
|
|
5022
|
-
const offset = far ? fromFar(edge) : edge;
|
|
5023
|
-
if (word === "left" || word === "right")
|
|
5024
|
-
x = offset;
|
|
5025
|
-
else
|
|
5026
|
-
y = offset;
|
|
5027
|
-
} else if (word === "center")
|
|
5028
|
-
plain.push(MIDDLE);
|
|
5029
|
-
else {
|
|
5030
|
-
const offset = offsetOf(word);
|
|
5031
|
-
if (offset)
|
|
5032
|
-
plain.push(offset);
|
|
5033
|
-
}
|
|
5034
|
-
}
|
|
5035
|
-
for (const offset of plain) {
|
|
5036
|
-
if (!x)
|
|
5037
|
-
x = offset;
|
|
5038
|
-
else if (!y)
|
|
5039
|
-
y = offset;
|
|
5040
|
-
}
|
|
5041
|
-
return [x ?? MIDDLE, y ?? MIDDLE];
|
|
5042
|
-
}
|
|
5043
|
-
function objectPlace(fit2, position, natural, box2) {
|
|
5044
|
-
if (!(natural.width > 0 && natural.height > 0 && box2.width > 0 && box2.height > 0))
|
|
5045
|
-
return null;
|
|
5046
|
-
const across = box2.width / natural.width;
|
|
5047
|
-
const down = box2.height / natural.height;
|
|
5048
|
-
const whole = Math.min(across, down);
|
|
5049
|
-
let size = { width: box2.width, height: box2.height };
|
|
5050
|
-
const scaled = (scale) => ({ width: natural.width * scale, height: natural.height * scale });
|
|
5051
|
-
if (fit2 === "contain")
|
|
5052
|
-
size = scaled(whole);
|
|
5053
|
-
else if (fit2 === "cover")
|
|
5054
|
-
size = scaled(Math.max(across, down));
|
|
5055
|
-
else if (fit2 === "none")
|
|
5056
|
-
size = scaled(1);
|
|
5057
|
-
else if (fit2 === "scale-down")
|
|
5058
|
-
size = scaled(Math.min(1, whole));
|
|
5059
|
-
const [x, y] = objectPosition(position);
|
|
5060
|
-
const left = box2.x + (box2.width - size.width) * x.share + x.px;
|
|
5061
|
-
const top = box2.y + (box2.height - size.height) * y.share + y.px;
|
|
5062
|
-
const to = {
|
|
5063
|
-
x: Math.max(left, box2.x),
|
|
5064
|
-
y: Math.max(top, box2.y),
|
|
5065
|
-
width: Math.min(left + size.width, box2.x + box2.width) - Math.max(left, box2.x),
|
|
5066
|
-
height: Math.min(top + size.height, box2.y + box2.height) - Math.max(top, box2.y)
|
|
5681
|
+
const browser = {
|
|
5682
|
+
show(next) {
|
|
5683
|
+
view = next;
|
|
5684
|
+
if (next.bars && !layer.isConnected)
|
|
5685
|
+
glass.append(layer);
|
|
5686
|
+
for (const seam of seams)
|
|
5687
|
+
if (seam.isConnected)
|
|
5688
|
+
glass.insertBefore(seam, layer.isConnected ? layer : null);
|
|
5689
|
+
if (!next.bars)
|
|
5690
|
+
layer.remove();
|
|
5691
|
+
place(layer, 0, 0, next.size.width, next.size.height);
|
|
5692
|
+
layer.style.transform = next.zoom === 1 ? "" : `scale(${next.zoom})`;
|
|
5693
|
+
draw();
|
|
5694
|
+
},
|
|
5695
|
+
refresh() {
|
|
5696
|
+
if (!view)
|
|
5697
|
+
return;
|
|
5698
|
+
const again = view.bars ? read : () => {
|
|
5699
|
+
if (!busy || !look)
|
|
5700
|
+
look = lookNow();
|
|
5701
|
+
back();
|
|
5702
|
+
};
|
|
5703
|
+
again();
|
|
5704
|
+
band.refresh();
|
|
5705
|
+
clearTimeout(later);
|
|
5706
|
+
later = window.setTimeout(again, RESTYLE);
|
|
5707
|
+
},
|
|
5708
|
+
minimized: () => motion.minimized,
|
|
5709
|
+
page: () => applied,
|
|
5710
|
+
startLoading,
|
|
5711
|
+
stopLoading,
|
|
5712
|
+
look: () => look,
|
|
5713
|
+
remove() {
|
|
5714
|
+
clearTimeout(later);
|
|
5715
|
+
if (sampling)
|
|
5716
|
+
window.cancelAnimationFrame(sampling);
|
|
5717
|
+
sampling = 0;
|
|
5718
|
+
if (loadWait)
|
|
5719
|
+
window.cancelAnimationFrame(loadWait);
|
|
5720
|
+
loadWait = 0;
|
|
5721
|
+
stopShrink();
|
|
5722
|
+
query?.removeEventListener("change", read);
|
|
5723
|
+
try {
|
|
5724
|
+
frame2.contentWindow?.removeEventListener("scroll", onScroll);
|
|
5725
|
+
} catch {}
|
|
5726
|
+
query = null;
|
|
5727
|
+
watched2 = null;
|
|
5728
|
+
layer.remove();
|
|
5729
|
+
for (const seam of seams)
|
|
5730
|
+
seam.remove();
|
|
5731
|
+
blank.remove();
|
|
5732
|
+
band.remove();
|
|
5733
|
+
}
|
|
5067
5734
|
};
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5735
|
+
return browser;
|
|
5736
|
+
}
|
|
5737
|
+
function seamRects(page, zoom, unit, look) {
|
|
5738
|
+
if (!page)
|
|
5739
|
+
return { top: null, bottom: null };
|
|
5740
|
+
const x = page.x * zoom;
|
|
5741
|
+
const width = page.width * zoom;
|
|
5742
|
+
const edge = (y) => ({ x, y: y - 2 * unit, width, height: 4 * unit });
|
|
5072
5743
|
return {
|
|
5073
|
-
|
|
5074
|
-
|
|
5744
|
+
top: look.header ? edge(page.y * zoom) : null,
|
|
5745
|
+
bottom: look.footer ? edge((page.y + page.height) * zoom) : null
|
|
5075
5746
|
};
|
|
5076
5747
|
}
|
|
5077
5748
|
|
|
5078
|
-
// src/engine/
|
|
5079
|
-
var
|
|
5080
|
-
var
|
|
5081
|
-
var
|
|
5082
|
-
var
|
|
5083
|
-
function
|
|
5084
|
-
const
|
|
5085
|
-
|
|
5086
|
-
let quote = "";
|
|
5087
|
-
let from = 0;
|
|
5088
|
-
for (let at = 0;at < text.length; at++) {
|
|
5089
|
-
const char = text[at];
|
|
5090
|
-
if (char === "\\")
|
|
5091
|
-
at++;
|
|
5092
|
-
else if (quote)
|
|
5093
|
-
quote = char === quote ? "" : quote;
|
|
5094
|
-
else if (char === '"' || char === "'")
|
|
5095
|
-
quote = char;
|
|
5096
|
-
else if (char === "(")
|
|
5097
|
-
depth++;
|
|
5098
|
-
else if (char === ")")
|
|
5099
|
-
depth--;
|
|
5100
|
-
else if (char === mark && depth === 0) {
|
|
5101
|
-
parts.push(text.slice(from, at));
|
|
5102
|
-
from = at + 1;
|
|
5103
|
-
}
|
|
5104
|
-
}
|
|
5105
|
-
parts.push(text.slice(from));
|
|
5106
|
-
return parts;
|
|
5107
|
-
}
|
|
5108
|
-
function faceKey(family, weight, style, range) {
|
|
5109
|
-
const name = family.trim().replace(/^(["'])(.*)\1$/, "$2").toLowerCase();
|
|
5110
|
-
const plain = (value) => value.trim().toLowerCase().replace(/\s+/g, " ") || "normal";
|
|
5111
|
-
const heavy = plain(weight).replace(/\bnormal\b/g, "400").replace(/\bbold\b/g, "700");
|
|
5112
|
-
const chars = (range.trim() || "U+0-10FFFF").toLowerCase().split(",").map((part) => part.trim().replace(/^u\+/, "").split("-").map((end) => end.replace(/^0+(?=.)/, "")).join("-")).join(",");
|
|
5113
|
-
return [name, heavy, plain(style), chars].join("|");
|
|
5114
|
-
}
|
|
5115
|
-
function base64(bytes) {
|
|
5116
|
-
let text = "";
|
|
5117
|
-
for (let at = 0;at < bytes.length; at += CHUNK)
|
|
5118
|
-
text += String.fromCharCode(...bytes.subarray(at, at + CHUNK));
|
|
5119
|
-
return btoa(text);
|
|
5749
|
+
// src/engine/fit.ts
|
|
5750
|
+
var STRIP_TOP = 8;
|
|
5751
|
+
var STRIP = 24 + STRIP_TOP;
|
|
5752
|
+
var MARGIN = 24;
|
|
5753
|
+
var BARE = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
5754
|
+
function hasStrip(knobs2) {
|
|
5755
|
+
const sized = typeof knobs2.width === "number" || typeof knobs2.height === "number";
|
|
5756
|
+
return sized || knobs2.zoom !== "fit";
|
|
5120
5757
|
}
|
|
5121
|
-
function
|
|
5122
|
-
|
|
5123
|
-
quietFetch(url).then(async (response) => {
|
|
5124
|
-
if (!response.ok)
|
|
5125
|
-
return;
|
|
5126
|
-
const type = /^[\w.+-]+\/[\w.+-]+/.exec(response.headers.get("content-type") ?? "")?.[0];
|
|
5127
|
-
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
5128
|
-
fonts.set(url, `data:${type ?? "application/octet-stream"};base64,${base64(bytes)}`);
|
|
5129
|
-
}).catch(() => {});
|
|
5758
|
+
function margin(size) {
|
|
5759
|
+
return Math.min(MARGIN, size / 4);
|
|
5130
5760
|
}
|
|
5131
|
-
function
|
|
5132
|
-
const
|
|
5133
|
-
const
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
const parts = cut(css.slice(open + 1, close), ";");
|
|
5137
|
-
const named = (name) => {
|
|
5138
|
-
const part = parts.find((part2) => part2.split(":")[0]?.trim().toLowerCase() === name);
|
|
5139
|
-
return part ? part.slice(part.indexOf(":") + 1).trim() : "";
|
|
5761
|
+
function fit(knobs2, size, options = {}) {
|
|
5762
|
+
const { frameZoom = 1, aside = 0, side = "right", mock = BARE } = options;
|
|
5763
|
+
const room = {
|
|
5764
|
+
width: size.width,
|
|
5765
|
+
height: Math.max(0, size.height - (hasStrip(knobs2) ? STRIP : 0))
|
|
5140
5766
|
};
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
const
|
|
5145
|
-
const
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
const
|
|
5150
|
-
const
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
const
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
const locals = sources.slice(0, at).filter((source2) => /^local\(/i.test(source2));
|
|
5168
|
-
const src = [...locals, `url("${data}")${source.slice(found[0].length)}`].join(", ");
|
|
5169
|
-
const next = parts.map((part) => part.split(":")[0]?.trim().toLowerCase() === "src" ? ` src: ${src}` : part);
|
|
5170
|
-
return `${css.slice(0, open + 1)}${next.join(";")}${css.slice(close)}`;
|
|
5171
|
-
}
|
|
5172
|
-
function holdsRules(rule) {
|
|
5173
|
-
return "cssRules" in rule;
|
|
5174
|
-
}
|
|
5175
|
-
function keptFor(doc) {
|
|
5176
|
-
if (kept2?.doc === doc)
|
|
5177
|
-
return kept2.fonts;
|
|
5178
|
-
forgetFonts();
|
|
5179
|
-
const set = doc.fonts;
|
|
5180
|
-
const again = () => fetchFonts(doc);
|
|
5181
|
-
set?.addEventListener("loadingdone", again);
|
|
5182
|
-
kept2 = { doc, fonts: new Map, stop: () => set?.removeEventListener("loadingdone", again) };
|
|
5183
|
-
return kept2.fonts;
|
|
5184
|
-
}
|
|
5185
|
-
function embedFonts(doc) {
|
|
5186
|
-
const fonts = keptFor(doc);
|
|
5187
|
-
const used = new Set;
|
|
5188
|
-
const set = doc.fonts;
|
|
5189
|
-
if (set) {
|
|
5190
|
-
for (const face of set) {
|
|
5191
|
-
if (face.status === "loaded")
|
|
5192
|
-
used.add(faceKey(face.family, face.weight, face.style, face.unicodeRange));
|
|
5193
|
-
}
|
|
5194
|
-
}
|
|
5195
|
-
const embed = (rule) => {
|
|
5196
|
-
let css = rule.cssText;
|
|
5197
|
-
if (used.size === 0 || !css.includes("@font-face"))
|
|
5198
|
-
return css;
|
|
5199
|
-
if (!holdsRules(rule)) {
|
|
5200
|
-
const base = rule.parentStyleSheet?.href ?? doc.baseURI;
|
|
5201
|
-
return css.startsWith("@font-face") ? faceWith(css, base, used, fonts) : css;
|
|
5202
|
-
}
|
|
5203
|
-
for (const inner of rule.cssRules) {
|
|
5204
|
-
const next = embed(inner);
|
|
5205
|
-
if (next !== inner.cssText)
|
|
5206
|
-
css = css.split(inner.cssText).join(next);
|
|
5207
|
-
}
|
|
5208
|
-
return css;
|
|
5767
|
+
const sized = typeof knobs2.width === "number";
|
|
5768
|
+
const width = typeof knobs2.width === "number" ? knobs2.width : room.width;
|
|
5769
|
+
const x = sized ? margin(room.width) : 0;
|
|
5770
|
+
const y = typeof knobs2.height === "number" ? margin(room.height) : 0;
|
|
5771
|
+
const sides = { width: mock.left + mock.right, height: mock.top + mock.bottom };
|
|
5772
|
+
const across = width > 0 && room.width > 0 ? (room.width - 2 * x) / (width + sides.width) : 1;
|
|
5773
|
+
const tall = typeof knobs2.height === "number" && knobs2.height > 0 && room.height > 0;
|
|
5774
|
+
const upright = (room.height - 2 * y) / (Number(knobs2.height) + sides.height);
|
|
5775
|
+
const whole = Math.min(sized && tall ? ZOOM_MAX : 1, across, tall ? upright : 1);
|
|
5776
|
+
const height = typeof knobs2.height === "number" ? knobs2.height : room.height / whole;
|
|
5777
|
+
const outer = { width: width + sides.width, height: height + sides.height };
|
|
5778
|
+
const covered = sized && aside > 0 && aside <= room.width / 2 && (room.width + outer.width * whole) / 2 + x > room.width - aside;
|
|
5779
|
+
const fitted = covered ? Math.min(whole, (room.width - aside - 2 * x) / outer.width) : whole;
|
|
5780
|
+
const scale = knobs2.zoom === "fit" ? fitted : knobs2.zoom;
|
|
5781
|
+
const beside = knobs2.zoom === "fit" && covered ? aside : 0;
|
|
5782
|
+
const before = side === "left" ? beside : 0;
|
|
5783
|
+
return {
|
|
5784
|
+
width,
|
|
5785
|
+
height,
|
|
5786
|
+
zoom: frameZoom,
|
|
5787
|
+
scale,
|
|
5788
|
+
fit: fitted,
|
|
5789
|
+
transform: scale / frameZoom,
|
|
5790
|
+
box: { width: outer.width * scale + 2 * x + beside, height: outer.height * scale + 2 * y },
|
|
5791
|
+
left: x + mock.left * scale + before,
|
|
5792
|
+
top: y + mock.top * scale
|
|
5209
5793
|
};
|
|
5210
|
-
return embed;
|
|
5211
|
-
}
|
|
5212
|
-
function fetchFonts(doc) {
|
|
5213
|
-
const embed = embedFonts(doc);
|
|
5214
|
-
for (const sheet of doc.styleSheets) {
|
|
5215
|
-
try {
|
|
5216
|
-
for (const rule of sheet.cssRules)
|
|
5217
|
-
embed(rule);
|
|
5218
|
-
} catch {}
|
|
5219
|
-
}
|
|
5220
5794
|
}
|
|
5221
|
-
function
|
|
5222
|
-
|
|
5223
|
-
|
|
5795
|
+
function origin(place2, room) {
|
|
5796
|
+
return {
|
|
5797
|
+
x: Math.max(0, (room.width - place2.box.width) / 2) + place2.left,
|
|
5798
|
+
y: Math.max(0, (room.height - place2.box.height) / 2) + place2.top
|
|
5799
|
+
};
|
|
5224
5800
|
}
|
|
5225
|
-
function
|
|
5226
|
-
|
|
5227
|
-
|
|
5801
|
+
function label(place2, knobs2, page = place2) {
|
|
5802
|
+
const name = formOf(knobs2.device, knobs2.posture)?.label;
|
|
5803
|
+
let text = name ? `${name} · ${page.width}` : String(page.width);
|
|
5804
|
+
if (typeof knobs2.height === "number")
|
|
5805
|
+
text += ` × ${page.height}`;
|
|
5806
|
+
if (typeof knobs2.dpr === "number")
|
|
5807
|
+
text += ` · ${knobs2.dpr}x`;
|
|
5808
|
+
return text;
|
|
5228
5809
|
}
|
|
5229
5810
|
|
|
5230
|
-
// src/engine/
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
canvas.width = Math.max(1, Math.round(width));
|
|
5238
|
-
canvas.height = Math.max(1, Math.round(height));
|
|
5239
|
-
const pen = canvas.getContext("2d");
|
|
5240
|
-
return pen ? { canvas, pen } : null;
|
|
5811
|
+
// src/engine/mat.ts
|
|
5812
|
+
function colorRules() {
|
|
5813
|
+
return MAT_COLOR_NAMES.map((name) => {
|
|
5814
|
+
const paint = MAT_COLORS[name];
|
|
5815
|
+
return `[data-mat="${name}"] { --mat: ${matGradient(paint.srgb)}; --mat-p3: ${matGradient(paint.p3)}; --mat-line: ${paint.line}; }`;
|
|
5816
|
+
}).join(`
|
|
5817
|
+
`);
|
|
5241
5818
|
}
|
|
5242
|
-
|
|
5243
|
-
|
|
5819
|
+
var MAT_CSS = `
|
|
5820
|
+
${colorRules()}
|
|
5821
|
+
.mat {
|
|
5822
|
+
position: absolute;
|
|
5823
|
+
top: 0;
|
|
5824
|
+
left: 0;
|
|
5825
|
+
width: 100%;
|
|
5826
|
+
height: 100%;
|
|
5827
|
+
pointer-events: none;
|
|
5828
|
+
fill: var(--mat-line);
|
|
5244
5829
|
}
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5830
|
+
.mat .cell { opacity: 0.07; }
|
|
5831
|
+
.mat .major { opacity: 0.14; }
|
|
5832
|
+
.mat .span { opacity: 0.26; }
|
|
5833
|
+
.mat .angle { fill: none; stroke: var(--mat-line); }
|
|
5834
|
+
.mat .mark, .mat .tick { opacity: 0.55; }
|
|
5835
|
+
.mat text {
|
|
5836
|
+
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
5837
|
+
font-variant-numeric: tabular-nums;
|
|
5838
|
+
opacity: 0.5;
|
|
5839
|
+
}`;
|
|
5840
|
+
var CELL = 10;
|
|
5841
|
+
var MAJOR = 50;
|
|
5842
|
+
var SPAN = 100;
|
|
5843
|
+
var TICK = { cell: 3, major: 5, span: 9 };
|
|
5844
|
+
var ANGLES = [15, 30, 45, 60, 75];
|
|
5845
|
+
var GUIDE = { line: 0.15, half: 0.22 };
|
|
5846
|
+
var ARC = 40;
|
|
5847
|
+
var LABEL = { radius: 240, off: 3, top: 40, room: 24 };
|
|
5848
|
+
var FOOT = 30;
|
|
5849
|
+
var NUMBER = 24;
|
|
5850
|
+
function ticks(length) {
|
|
5851
|
+
const out = [];
|
|
5852
|
+
for (let at = CELL;at < length; at += CELL) {
|
|
5853
|
+
const size = at % SPAN === 0 ? TICK.span : at % MAJOR === 0 ? TICK.major : TICK.cell;
|
|
5854
|
+
out.push({ at, size });
|
|
5250
5855
|
}
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5856
|
+
return out;
|
|
5857
|
+
}
|
|
5858
|
+
function numbers(length, avoid) {
|
|
5859
|
+
const out = [];
|
|
5860
|
+
for (let at = SPAN;at + NUMBER <= length; at += SPAN) {
|
|
5861
|
+
if (avoid && at + NUMBER > avoid.from && at < avoid.to)
|
|
5862
|
+
continue;
|
|
5863
|
+
out.push(at);
|
|
5254
5864
|
}
|
|
5255
|
-
return
|
|
5865
|
+
return out;
|
|
5256
5866
|
}
|
|
5257
|
-
function
|
|
5258
|
-
|
|
5259
|
-
const px = (text, of) => (text.endsWith("%") ? Number.parseFloat(text) / 100 * of : Number.parseFloat(text)) || 0;
|
|
5260
|
-
return { x: px(across, wide), y: px(down, tall) };
|
|
5867
|
+
function lines(across, length, hair) {
|
|
5868
|
+
return across.map((at) => `M${at} 0h${hair}v${length}h${-hair}ZM0 ${at}h${length}v${hair}h${-length}Z`).join("");
|
|
5261
5869
|
}
|
|
5262
|
-
function
|
|
5263
|
-
const
|
|
5264
|
-
|
|
5265
|
-
const right = px(style.borderRightWidth) + px(style.paddingRight);
|
|
5266
|
-
const top = px(style.borderTopWidth) + px(style.paddingTop);
|
|
5267
|
-
const bottom = px(style.borderBottomWidth) + px(style.paddingBottom);
|
|
5268
|
-
const box2 = { x: rect.left + left, y: rect.top + top, width: rect.width - left - right, height: rect.height - top - bottom };
|
|
5269
|
-
const placed = objectPlace(style.objectFit, style.objectPosition, media, box2);
|
|
5270
|
-
if (!placed)
|
|
5271
|
-
return;
|
|
5272
|
-
const corner = (value, across, down) => {
|
|
5273
|
-
const radius = radiusOf(value, rect.width, rect.height);
|
|
5274
|
-
return { x: Math.max(0, radius.x - across), y: Math.max(0, radius.y - down) };
|
|
5275
|
-
};
|
|
5276
|
-
const corners = [
|
|
5277
|
-
corner(style.borderTopLeftRadius, left, top),
|
|
5278
|
-
corner(style.borderTopRightRadius, right, top),
|
|
5279
|
-
corner(style.borderBottomRightRadius, right, bottom),
|
|
5280
|
-
corner(style.borderBottomLeftRadius, left, bottom)
|
|
5281
|
-
];
|
|
5282
|
-
const { from, to } = placed;
|
|
5283
|
-
pen.save();
|
|
5284
|
-
if (corners.some((radius) => radius.x > 0 && radius.y > 0)) {
|
|
5285
|
-
pen.beginPath();
|
|
5286
|
-
pen.roundRect(box2.x, box2.y, box2.width, box2.height, corners);
|
|
5287
|
-
pen.clip();
|
|
5288
|
-
}
|
|
5289
|
-
if (style.imageRendering === "pixelated" || style.imageRendering === "crisp-edges")
|
|
5290
|
-
pen.imageSmoothingEnabled = false;
|
|
5291
|
-
pen.drawImage(media.source, from.x, from.y, from.width, from.height, to.x, to.y, to.width, to.height);
|
|
5292
|
-
pen.restore();
|
|
5870
|
+
function vertex(height) {
|
|
5871
|
+
const y = Math.floor((height - FOOT) / SPAN) * SPAN;
|
|
5872
|
+
return y > 0 ? { x: 0, y } : null;
|
|
5293
5873
|
}
|
|
5294
|
-
function
|
|
5295
|
-
const
|
|
5296
|
-
|
|
5297
|
-
if (!("naturalWidth" in node))
|
|
5298
|
-
return null;
|
|
5299
|
-
const address = node.currentSrc;
|
|
5300
|
-
parts.push(`${address.length}:${address.slice(-64)}@${node.naturalWidth}x${node.naturalHeight}`);
|
|
5301
|
-
}
|
|
5302
|
-
return parts.join(" ");
|
|
5874
|
+
function direction(angle) {
|
|
5875
|
+
const turn2 = angle * Math.PI / 180;
|
|
5876
|
+
return { x: Math.cos(turn2), y: -Math.sin(turn2) };
|
|
5303
5877
|
}
|
|
5304
|
-
function
|
|
5305
|
-
const
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
]);
|
|
5878
|
+
function exit(from, angle, size) {
|
|
5879
|
+
const step = direction(angle);
|
|
5880
|
+
const toTop = step.y < 0 ? from.y / -step.y : Infinity;
|
|
5881
|
+
const toRight = step.x > 0 ? (size.width - from.x) / step.x : Infinity;
|
|
5882
|
+
if (toTop <= toRight)
|
|
5883
|
+
return { x: from.x + toTop * step.x, y: 0 };
|
|
5884
|
+
return { x: size.width, y: from.y + toRight * step.y };
|
|
5312
5885
|
}
|
|
5313
|
-
function
|
|
5314
|
-
const
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
const
|
|
5321
|
-
const
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5886
|
+
function along(from, angle, radius, off = 0) {
|
|
5887
|
+
const step = direction(angle);
|
|
5888
|
+
return { x: from.x + radius * step.x + off * step.y, y: from.y + radius * step.y - off * step.x };
|
|
5889
|
+
}
|
|
5890
|
+
function drawMat(size, hair, avoid, bleed = { left: 0, right: 0 }) {
|
|
5891
|
+
const svg = svgNode("svg", { class: "mat", "aria-hidden": "true" });
|
|
5892
|
+
const sheet = svgNode("g", { transform: `translate(${bleed.left} 0)` });
|
|
5893
|
+
const half = SPAN / 2;
|
|
5894
|
+
const minor = [];
|
|
5895
|
+
for (let at = CELL;at < SPAN; at += CELL)
|
|
5896
|
+
if (at !== half)
|
|
5897
|
+
minor.push(at);
|
|
5898
|
+
const arm = 6;
|
|
5899
|
+
const pattern = svgNode("pattern", {
|
|
5900
|
+
id: "mat-grid",
|
|
5901
|
+
x: -half,
|
|
5902
|
+
y: -half,
|
|
5903
|
+
width: SPAN,
|
|
5904
|
+
height: SPAN,
|
|
5905
|
+
patternUnits: "userSpaceOnUse"
|
|
5333
5906
|
});
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
const
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
pen.fillStyle = style.backgroundColor;
|
|
5382
|
-
pen.beginPath();
|
|
5383
|
-
pen.roundRect(rect.left, rect.top, rect.width, rect.height, Number.parseFloat(style.borderTopLeftRadius) || 0);
|
|
5384
|
-
pen.fill();
|
|
5385
|
-
}
|
|
5386
|
-
const picture = pictures.get(node);
|
|
5387
|
-
if (picture)
|
|
5388
|
-
drawMedia(pen, picture, rect, style);
|
|
5389
|
-
pen.fillStyle = style.color;
|
|
5390
|
-
pen.globalAlpha = shown3 * INK;
|
|
5391
|
-
for (const text of node.childNodes) {
|
|
5392
|
-
if (text.nodeType !== Node.TEXT_NODE || !text.textContent?.trim())
|
|
5393
|
-
continue;
|
|
5394
|
-
range.selectNodeContents(text);
|
|
5395
|
-
for (const line of range.getClientRects())
|
|
5396
|
-
pen.fillRect(line.left, line.top, line.width, line.height);
|
|
5397
|
-
}
|
|
5907
|
+
pattern.append(svgNode("path", { class: "cell", d: lines(minor, SPAN, hair) }), svgNode("path", { class: "major", d: lines([0], SPAN, hair) }), svgNode("path", { class: "span", d: lines([half], SPAN, hair) }), svgNode("path", {
|
|
5908
|
+
class: "mark",
|
|
5909
|
+
d: `M${half - arm} ${half}h${2 * arm + hair}v${hair}h${-2 * arm - hair}Z` + `M${half} ${half - arm}h${hair}v${2 * arm + hair}h${-hair}Z`
|
|
5910
|
+
}));
|
|
5911
|
+
const defs = svgNode("defs", {});
|
|
5912
|
+
defs.append(pattern);
|
|
5913
|
+
const top = ticks(size.width).map((tick) => `M${tick.at} 0h${hair}v${tick.size}h${-hair}Z`).join("");
|
|
5914
|
+
const left = ticks(size.height).map((tick) => `M0 ${tick.at}h${tick.size}v${hair}h${-tick.size}Z`).join("");
|
|
5915
|
+
sheet.append(svgNode("rect", {
|
|
5916
|
+
x: -bleed.left,
|
|
5917
|
+
width: bleed.left + size.width + bleed.right,
|
|
5918
|
+
height: "100%",
|
|
5919
|
+
fill: "url(#mat-grid)"
|
|
5920
|
+
}), svgNode("path", { class: "tick", d: top + left }));
|
|
5921
|
+
svg.append(defs, sheet);
|
|
5922
|
+
const origin2 = vertex(size.height);
|
|
5923
|
+
if (origin2) {
|
|
5924
|
+
const base = along(origin2, 0, ARC);
|
|
5925
|
+
const rim = { x: origin2.x, y: origin2.y - ARC };
|
|
5926
|
+
const arc2 = svgNode("path", {
|
|
5927
|
+
class: "angle",
|
|
5928
|
+
d: `M${base.x} ${base.y}A${ARC} ${ARC} 0 0 0 ${rim.x} ${rim.y}`,
|
|
5929
|
+
"stroke-width": hair
|
|
5930
|
+
});
|
|
5931
|
+
arc2.style.opacity = String(GUIDE.line);
|
|
5932
|
+
sheet.append(arc2);
|
|
5933
|
+
for (const angle of ANGLES) {
|
|
5934
|
+
const start = along(origin2, angle, ARC);
|
|
5935
|
+
const end = exit(origin2, angle, size);
|
|
5936
|
+
const line = svgNode("path", {
|
|
5937
|
+
class: "angle",
|
|
5938
|
+
d: `M${start.x} ${start.y}L${end.x} ${end.y}`,
|
|
5939
|
+
"stroke-width": hair
|
|
5940
|
+
});
|
|
5941
|
+
line.style.opacity = String(angle === 45 ? GUIDE.half : GUIDE.line);
|
|
5942
|
+
sheet.append(line);
|
|
5943
|
+
const reach = Math.hypot(end.x - origin2.x, end.y - origin2.y);
|
|
5944
|
+
const at = along(origin2, angle, LABEL.radius, LABEL.off);
|
|
5945
|
+
if (reach < LABEL.radius + LABEL.room || at.y < LABEL.top)
|
|
5946
|
+
continue;
|
|
5947
|
+
const text = svgNode("text", {
|
|
5948
|
+
x: at.x,
|
|
5949
|
+
y: at.y,
|
|
5950
|
+
transform: `rotate(${-angle} ${at.x} ${at.y})`
|
|
5951
|
+
});
|
|
5952
|
+
text.textContent = `${angle}°`;
|
|
5953
|
+
sheet.append(text);
|
|
5398
5954
|
}
|
|
5399
|
-
|
|
5400
|
-
|
|
5955
|
+
}
|
|
5956
|
+
for (const at of numbers(size.width, avoid)) {
|
|
5957
|
+
const text = svgNode("text", { x: at + 3, y: TICK.span + 1 });
|
|
5958
|
+
text.textContent = String(at);
|
|
5959
|
+
sheet.append(text);
|
|
5960
|
+
}
|
|
5961
|
+
for (const at of numbers(size.height)) {
|
|
5962
|
+
const text = svgNode("text", { x: TICK.span + 2, y: at, "dominant-baseline": "middle" });
|
|
5963
|
+
text.textContent = String(at);
|
|
5964
|
+
sheet.append(text);
|
|
5965
|
+
}
|
|
5966
|
+
return svg;
|
|
5967
|
+
}
|
|
5968
|
+
|
|
5969
|
+
// src/engine/foldflip.ts
|
|
5970
|
+
function flipRect(rect, room) {
|
|
5971
|
+
return { ...rect, x: room.width - rect.x - rect.width, y: room.height - rect.y - rect.height };
|
|
5972
|
+
}
|
|
5973
|
+
function flipRadius(radius) {
|
|
5974
|
+
if (typeof radius === "number")
|
|
5975
|
+
return radius;
|
|
5976
|
+
const [topLeft, topRight, bottomRight, bottomLeft] = radius;
|
|
5977
|
+
return [bottomRight, bottomLeft, topLeft, topRight];
|
|
5978
|
+
}
|
|
5979
|
+
function flipMock(mock) {
|
|
5980
|
+
const room = { width: mock.width, height: mock.height };
|
|
5981
|
+
const { top, right, bottom, left } = mock.inset;
|
|
5982
|
+
const flipped = {
|
|
5983
|
+
...mock,
|
|
5984
|
+
inset: { top: bottom, right: left, bottom: top, left: right },
|
|
5985
|
+
body: flipRect(mock.body, room),
|
|
5986
|
+
screenRadius: flipRadius(mock.screenRadius),
|
|
5987
|
+
bodyRadius: flipRadius(mock.bodyRadius),
|
|
5988
|
+
parts: mock.parts.map((part) => flipRect(part, room))
|
|
5401
5989
|
};
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5990
|
+
if (!mock.image)
|
|
5991
|
+
return flipped;
|
|
5992
|
+
if (mock.image.turn === null) {
|
|
5993
|
+
const { over: over2, ...still2 } = mock.image;
|
|
5994
|
+
return { ...flipped, image: over2 ? still2 : { ...still2, over: true } };
|
|
5995
|
+
}
|
|
5996
|
+
const { clockwise, ...image } = mock.image;
|
|
5997
|
+
return { ...flipped, image: clockwise ? { ...image, turn: mock.height } : { ...image, turn: mock.width, clockwise: true } };
|
|
5409
5998
|
}
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
watched?.observer.disconnect();
|
|
5414
|
-
watched = null;
|
|
5415
|
-
shots = new WeakMap;
|
|
5416
|
-
forgetFonts();
|
|
5999
|
+
function coverAcross(shape) {
|
|
6000
|
+
const [device = "", held, posture] = shape.split("|");
|
|
6001
|
+
return held === "landscape" && posture === "closed" && formOf(device, "closed")?.clockwise === true;
|
|
5417
6002
|
}
|
|
5418
|
-
function
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
if (watched.observer.takeRecords().length > 0)
|
|
5422
|
-
watched.changed = true;
|
|
5423
|
-
return !watched.changed;
|
|
6003
|
+
function openUpright(shape) {
|
|
6004
|
+
const [device = "", held, posture] = shape.split("|");
|
|
6005
|
+
return held === "portrait" && posture === "open" && formOf(device, "closed")?.clockwise === true;
|
|
5424
6006
|
}
|
|
5425
|
-
function
|
|
5426
|
-
if (
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
6007
|
+
function caseOver(from, to, over2) {
|
|
6008
|
+
if (coverAcross(to))
|
|
6009
|
+
return true;
|
|
6010
|
+
if (!openUpright(to))
|
|
6011
|
+
return false;
|
|
6012
|
+
return coverAcross(from) || from === to && over2;
|
|
6013
|
+
}
|
|
6014
|
+
function flipFace(face, room) {
|
|
6015
|
+
return { ...face, body: face.body && flipMock(face.body), screen: flipRect(face.screen, room) };
|
|
6016
|
+
}
|
|
6017
|
+
var turnedOver = new WeakMap;
|
|
6018
|
+
function flipCanvas(canvas) {
|
|
6019
|
+
const known = turnedOver.get(canvas);
|
|
6020
|
+
if (known)
|
|
6021
|
+
return known;
|
|
6022
|
+
const turned = document.createElement("canvas");
|
|
6023
|
+
turned.width = canvas.width;
|
|
6024
|
+
turned.height = canvas.height;
|
|
6025
|
+
const pen = turned.getContext("2d");
|
|
6026
|
+
if (pen) {
|
|
6027
|
+
pen.translate(canvas.width, canvas.height);
|
|
6028
|
+
pen.rotate(Math.PI);
|
|
6029
|
+
pen.drawImage(canvas, 0, 0);
|
|
6030
|
+
}
|
|
6031
|
+
turnedOver.set(canvas, turned);
|
|
6032
|
+
return turned;
|
|
6033
|
+
}
|
|
6034
|
+
function flipPicture(picture, size) {
|
|
6035
|
+
const { bars } = picture;
|
|
6036
|
+
if (bars) {
|
|
6037
|
+
bars.style.transformOrigin = "0 0";
|
|
6038
|
+
bars.style.transform = `translate(${size.width}px, ${size.height}px) rotate(180deg)`;
|
|
5439
6039
|
}
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
6040
|
+
return {
|
|
6041
|
+
shot: picture.shot && flipCanvas(picture.shot),
|
|
6042
|
+
painted: picture.painted?.then((drawn) => drawn && { ...drawn, shot: flipCanvas(drawn.shot) }) ?? null,
|
|
6043
|
+
bars
|
|
6044
|
+
};
|
|
5443
6045
|
}
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
const canvas = blurPicture(padded.canvas, coarse2);
|
|
5457
|
-
if (canvas !== padded.canvas)
|
|
5458
|
-
spend(padded.canvas);
|
|
5459
|
-
return { canvas, long: length + 2 * margin2 };
|
|
5460
|
-
});
|
|
6046
|
+
|
|
6047
|
+
// src/engine/foldgl.ts
|
|
6048
|
+
function screenLook(open, wedge, free = 1, shaded = null, pane = shaded ?? "inner") {
|
|
6049
|
+
const blurred = blurOn();
|
|
6050
|
+
const [, wipe, area, far] = shaded ? shadeOf(shaded, open, free) : [1, 0, 0, 0];
|
|
6051
|
+
return {
|
|
6052
|
+
peak: blurred ? turnBlur(open, pane) : 0,
|
|
6053
|
+
edge: blurred ? [tune.edgeHinge * wedge, tune.edgeFree * wedge] : [0, 0],
|
|
6054
|
+
free,
|
|
6055
|
+
dark: shadesOn() ? freeDepth(open) : 0,
|
|
6056
|
+
lit: [wipe, area, far]
|
|
6057
|
+
};
|
|
5461
6058
|
}
|
|
5462
|
-
|
|
5463
|
-
|
|
6059
|
+
var WEIGHTS = [0.375, 0.25, 0.0625];
|
|
6060
|
+
function wedgeOf(window2, pane, picture, span) {
|
|
6061
|
+
const { top, bottom } = darkAt(window2, pane, picture);
|
|
6062
|
+
return picture.height > 0 ? Math.max(top, bottom) * span / picture.height : 0;
|
|
5464
6063
|
}
|
|
5465
|
-
function
|
|
5466
|
-
|
|
5467
|
-
|
|
6064
|
+
function freeOf(window2, pane, picture) {
|
|
6065
|
+
if (picture.width <= 0)
|
|
6066
|
+
return 1;
|
|
6067
|
+
const [a, b, c, d] = window2;
|
|
6068
|
+
const seen = pane === "inner" ? picture.x + picture.width - (a[0] + d[0]) / 2 : (b[0] + c[0]) / 2 - picture.x;
|
|
6069
|
+
return Math.min(1, Math.max(0, seen / picture.width));
|
|
5468
6070
|
}
|
|
5469
|
-
function
|
|
5470
|
-
|
|
5471
|
-
|
|
6071
|
+
function reachOf(shots2, pane) {
|
|
6072
|
+
let most = 0;
|
|
6073
|
+
for (const shot of shots2.frames) {
|
|
6074
|
+
if (shotPane(shots2, shot) !== pane)
|
|
6075
|
+
continue;
|
|
6076
|
+
const quad = shotQuad(shot, pane);
|
|
6077
|
+
const picture = shotPicture(shots2, pane, quad);
|
|
6078
|
+
most = Math.max(most, wedgeOf(shotWindow(quad, pane, picture), pane, picture, 1));
|
|
6079
|
+
}
|
|
6080
|
+
return most;
|
|
5472
6081
|
}
|
|
5473
|
-
function
|
|
5474
|
-
const
|
|
5475
|
-
|
|
5476
|
-
const sized = (level) => {
|
|
5477
|
-
const scale = Math.min(1, 2 ** level / coarse2);
|
|
5478
|
-
return canvasOf(width * scale, height * scale);
|
|
5479
|
-
};
|
|
5480
|
-
let at = shot;
|
|
5481
|
-
const step = (level, smooth) => {
|
|
5482
|
-
const next = sized(level);
|
|
5483
|
-
if (!next)
|
|
5484
|
-
return false;
|
|
5485
|
-
if (smooth)
|
|
5486
|
-
next.pen.imageSmoothingQuality = "high";
|
|
5487
|
-
next.pen.drawImage(at, 0, 0, next.canvas.width, next.canvas.height);
|
|
5488
|
-
if (at !== shot)
|
|
5489
|
-
spend(at);
|
|
5490
|
-
at = next.canvas;
|
|
5491
|
-
return true;
|
|
5492
|
-
};
|
|
5493
|
-
for (let level = halvings - 1;level >= 0; level--)
|
|
5494
|
-
if (!step(level, false))
|
|
5495
|
-
return at;
|
|
5496
|
-
for (let level = 1;level <= Math.min(Math.log2(KEPT), halvings); level++)
|
|
5497
|
-
if (!step(level, true))
|
|
5498
|
-
return at;
|
|
5499
|
-
return at;
|
|
6082
|
+
function canvasRect(place2) {
|
|
6083
|
+
const { across, part, stage, margin: margin2 } = place2;
|
|
6084
|
+
return across ? { x: part.x, y: -margin2, width: part.width, height: stage.height + 2 * margin2 } : { x: -margin2, y: part.y, width: stage.width + 2 * margin2, height: part.height };
|
|
5500
6085
|
}
|
|
5501
|
-
function
|
|
5502
|
-
|
|
6086
|
+
function hingeLine(pane, across, part) {
|
|
6087
|
+
const { x, y, width, height } = part;
|
|
6088
|
+
if (across)
|
|
6089
|
+
return pane === "inner" ? [-1 / width, 0, (x + width) / width] : [1 / width, 0, -x / width];
|
|
6090
|
+
return pane === "inner" ? [0, 1 / height, -y / height] : [0, -1 / height, (y + height) / height];
|
|
5503
6091
|
}
|
|
5504
|
-
function
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
for (const source of holder2.querySelectorAll("source"))
|
|
5515
|
-
source.remove();
|
|
5516
|
-
image.setAttribute("src", blankUrl(from.naturalWidth, from.naturalHeight));
|
|
6092
|
+
function contextOf(canvas) {
|
|
6093
|
+
if (typeof WebGL2RenderingContext === "undefined")
|
|
6094
|
+
return null;
|
|
6095
|
+
const gl = canvas.getContext("webgl2", {
|
|
6096
|
+
alpha: false,
|
|
6097
|
+
antialias: false,
|
|
6098
|
+
depth: false,
|
|
6099
|
+
stencil: false,
|
|
6100
|
+
premultipliedAlpha: false,
|
|
6101
|
+
powerPreference: "low-power"
|
|
5517
6102
|
});
|
|
6103
|
+
return gl instanceof WebGL2RenderingContext ? gl : null;
|
|
5518
6104
|
}
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
6105
|
+
var VERTEX = `#version 300 es
|
|
6106
|
+
in vec2 corner;
|
|
6107
|
+
uniform vec4 view;
|
|
6108
|
+
out vec2 pos;
|
|
6109
|
+
void main() {
|
|
6110
|
+
pos = view.xy + corner * view.zw;
|
|
6111
|
+
gl_Position = vec4(corner.x * 2.0 - 1.0, 1.0 - corner.y * 2.0, 0.0, 1.0);
|
|
6112
|
+
}`;
|
|
6113
|
+
var FRAGMENT = `#version 300 es
|
|
6114
|
+
precision highp float;
|
|
6115
|
+
uniform sampler2D page;
|
|
6116
|
+
uniform vec2 stage;
|
|
6117
|
+
uniform vec2 along;
|
|
6118
|
+
uniform vec3 line;
|
|
6119
|
+
uniform float peak;
|
|
6120
|
+
uniform vec2 edge;
|
|
6121
|
+
uniform float free;
|
|
6122
|
+
uniform float dark;
|
|
6123
|
+
uniform vec2 shape;
|
|
6124
|
+
uniform vec2 rimmed;
|
|
6125
|
+
uniform vec3 band;
|
|
6126
|
+
uniform vec3 lit;
|
|
6127
|
+
uniform vec2 run;
|
|
6128
|
+
uniform vec3 wiped;
|
|
6129
|
+
uniform vec2 soften;
|
|
6130
|
+
uniform float grain;
|
|
6131
|
+
uniform float px;
|
|
6132
|
+
in vec2 pos;
|
|
6133
|
+
out vec4 color;
|
|
6134
|
+
const float WEIGHTS[3] = float[3](${WEIGHTS.join(", ")});
|
|
6135
|
+
float cover(float at, float span, float soft) {
|
|
6136
|
+
return smoothstep(-soft, soft, at) * (1.0 - smoothstep(span - soft, span + soft, at));
|
|
6137
|
+
}
|
|
6138
|
+
float shadow(float t) {
|
|
6139
|
+
if (dark <= 0.0) return 1.0;
|
|
6140
|
+
float across = t / max(free, 0.001);
|
|
6141
|
+
float deep = band.z * smoothstep(band.x, 1.0, across) + (1.0 - band.z) * smoothstep(1.0 - band.y, 1.0, across);
|
|
6142
|
+
return 1.0 - dark * deep;
|
|
6143
|
+
}
|
|
6144
|
+
float shade(float t) {
|
|
6145
|
+
if (lit.x + lit.y + lit.z <= 0.0) return 1.0;
|
|
6146
|
+
float uv = run.x + run.y * t;
|
|
6147
|
+
float off = abs(uv - wiped.x);
|
|
6148
|
+
float wipe = 1.0 - clamp(smoothstep(wiped.y, wiped.z, off) * lit.x, 0.0, 1.0);
|
|
6149
|
+
float soft = 1.0 - smoothstep(0.9, 1.3, clamp((off - soften.x) / (soften.y - soften.x) * lit.y, 0.0, 4.0 / 3.0));
|
|
6150
|
+
float away = mix(1.0, smoothstep(0.05, 0.5, uv), lit.z);
|
|
6151
|
+
return pow(clamp(wipe * soft * soft * away, 0.0, 1.0), 1.0 / 2.2);
|
|
6152
|
+
}
|
|
6153
|
+
vec4 shaded(vec3 rgb, float t) {
|
|
6154
|
+
float speck = 0.0;
|
|
6155
|
+
if (grain > 0.0 && dark + lit.x + lit.y + lit.z > 0.0) {
|
|
6156
|
+
speck = (fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715)))) - 0.5) * grain / 255.0;
|
|
6157
|
+
}
|
|
6158
|
+
return vec4(rgb * shadow(t) * shade(min(t, free)) + speck, 1.0);
|
|
6159
|
+
}
|
|
6160
|
+
float seen(vec2 at, float soft) {
|
|
6161
|
+
float reach = soft * length(line.xy);
|
|
6162
|
+
return cover(dot(along, at), dot(along, stage), soft) * (1.0 - smoothstep(free - reach, free + reach, dot(line.xy, at) + line.z));
|
|
6163
|
+
}
|
|
6164
|
+
void main() {
|
|
6165
|
+
vec2 texels = vec2(textureSize(page, 0)) / stage;
|
|
6166
|
+
vec2 right = dFdx(pos) * texels;
|
|
6167
|
+
vec2 down = dFdy(pos) * texels;
|
|
6168
|
+
float sharp = 0.5 * log2(max(1.0, max(dot(right, right), dot(down, down))));
|
|
6169
|
+
float t = clamp(dot(line.xy, pos) + line.z, 0.0, 1.0);
|
|
6170
|
+
float span = dot(along, stage);
|
|
6171
|
+
float at = dot(along, pos);
|
|
6172
|
+
float across = free > 0.0 ? min(1.0, t / free) : 1.0;
|
|
6173
|
+
float wide = peak * (shape.x + (1.0 - shape.x) * pow(across, shape.y));
|
|
6174
|
+
float rim = mix(edge.x, edge.y, t);
|
|
6175
|
+
if (rim > 0.0) wide = max(wide, rim * (1.0 - smoothstep(0.0, rimmed.x * rim, min(at, span - at))));
|
|
6176
|
+
float gap = rimmed.y * wide;
|
|
6177
|
+
float soft = max(0.5 * px, 0.75 * gap);
|
|
6178
|
+
float lod = max(sharp, log2(max(1.0, gap * max(texels.x, texels.y))));
|
|
6179
|
+
vec3 sum = vec3(0.0);
|
|
6180
|
+
if (peak + edge.x + edge.y <= 0.0) {
|
|
6181
|
+
sum = textureLod(page, pos / stage, lod).rgb * seen(pos, soft);
|
|
6182
|
+
} else {
|
|
6183
|
+
for (int y = -2; y <= 2; y++) {
|
|
6184
|
+
for (int x = -2; x <= 2; x++) {
|
|
6185
|
+
vec2 tap = pos + vec2(float(x), float(y)) * gap;
|
|
6186
|
+
float weight = WEIGHTS[abs(x)] * WEIGHTS[abs(y)];
|
|
6187
|
+
sum += textureLod(page, tap / stage, lod).rgb * seen(tap, soft) * weight;
|
|
6188
|
+
}
|
|
6189
|
+
}
|
|
5530
6190
|
}
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
return root;
|
|
6191
|
+
color = shaded(sum, t);
|
|
6192
|
+
}`;
|
|
6193
|
+
function compile(gl, kind, source) {
|
|
6194
|
+
const shader = gl.createShader(kind);
|
|
6195
|
+
if (!shader)
|
|
6196
|
+
return null;
|
|
6197
|
+
gl.shaderSource(shader, source);
|
|
6198
|
+
gl.compileShader(shader);
|
|
6199
|
+
return shader;
|
|
5541
6200
|
}
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(whole)}`;
|
|
6201
|
+
function firstLine(log, otherwise) {
|
|
6202
|
+
return log?.trim().split(`
|
|
6203
|
+
`)[0]?.trim() || otherwise;
|
|
5546
6204
|
}
|
|
5547
|
-
function
|
|
5548
|
-
const
|
|
5549
|
-
|
|
6205
|
+
function uploadWhy(error) {
|
|
6206
|
+
const name = error instanceof Error ? error.name : String(error);
|
|
6207
|
+
const tainted = "the browser holds the picture as another origin's, as one with a picture, video or canvas from another origin drawn in, or a drawing of the page this browser does not trust";
|
|
6208
|
+
return `the picture could not be uploaded: ${name}${name === "SecurityError" ? `, ${tainted}` : ""}`;
|
|
5550
6209
|
}
|
|
5551
|
-
|
|
5552
|
-
const
|
|
5553
|
-
const
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
if (!doc || !view || screen.width <= 0 || view.innerWidth <= 0)
|
|
6210
|
+
function screenGl(place2, refused) {
|
|
6211
|
+
const canvas = document.createElement("canvas");
|
|
6212
|
+
const gl = contextOf(canvas);
|
|
6213
|
+
if (!gl) {
|
|
6214
|
+
refused(typeof WebGL2RenderingContext === "undefined" ? "this browser has no WebGL2" : "the canvas gave no WebGL2 context", null);
|
|
5557
6215
|
return null;
|
|
5558
|
-
const { innerWidth: width, innerHeight: height, scrollX, scrollY } = view;
|
|
5559
|
-
const css = size.width / screen.width;
|
|
5560
|
-
const scale = box2.width * css / width;
|
|
5561
|
-
const at = { x: (box2.left - screen.left) * css, y: (box2.top - screen.top) * css };
|
|
5562
|
-
let over = null;
|
|
5563
|
-
for (const node of doc.querySelectorAll(MEDIA)) {
|
|
5564
|
-
const media = node.closest("[data-devknobs]") ? null : mediaOf(node);
|
|
5565
|
-
const rect = node.getBoundingClientRect();
|
|
5566
|
-
if (!media || rect.bottom <= 0 || rect.top >= height || rect.width <= 0)
|
|
5567
|
-
continue;
|
|
5568
|
-
if (!over) {
|
|
5569
|
-
over = canvasOf(size.width, size.height);
|
|
5570
|
-
over?.pen.setTransform(scale, 0, 0, scale, at.x, at.y);
|
|
5571
|
-
}
|
|
5572
|
-
try {
|
|
5573
|
-
if (over)
|
|
5574
|
-
drawMedia(over.pen, media, rect, view.getComputedStyle(node));
|
|
5575
|
-
} catch {}
|
|
5576
6216
|
}
|
|
5577
|
-
const
|
|
5578
|
-
const
|
|
5579
|
-
const
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
6217
|
+
const rect = canvasRect(place2);
|
|
6218
|
+
const most = Math.max(1, gl.getParameter(gl.MAX_RENDERBUFFER_SIZE) || 4096);
|
|
6219
|
+
const density2 = Math.min(place2.density, most / rect.width, most / rect.height);
|
|
6220
|
+
canvas.width = Math.max(1, Math.round(rect.width * density2));
|
|
6221
|
+
canvas.height = Math.max(1, Math.round(rect.height * density2));
|
|
6222
|
+
canvas.style.position = "absolute";
|
|
6223
|
+
canvas.style.display = "block";
|
|
6224
|
+
canvas.style.left = `${rect.x}px`;
|
|
6225
|
+
canvas.style.top = `${rect.y}px`;
|
|
6226
|
+
canvas.style.width = `${rect.width}px`;
|
|
6227
|
+
canvas.style.height = `${rect.height}px`;
|
|
6228
|
+
const vertex2 = compile(gl, gl.VERTEX_SHADER, VERTEX);
|
|
6229
|
+
const fragment = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT);
|
|
6230
|
+
const program = gl.createProgram();
|
|
6231
|
+
const corners = gl.createBuffer();
|
|
6232
|
+
const texture = gl.createTexture();
|
|
6233
|
+
const free = () => {
|
|
6234
|
+
gl.deleteTexture(texture);
|
|
6235
|
+
gl.deleteBuffer(corners);
|
|
6236
|
+
gl.deleteProgram(program);
|
|
6237
|
+
gl.deleteShader(vertex2);
|
|
6238
|
+
gl.deleteShader(fragment);
|
|
6239
|
+
gl.getExtension("WEBGL_lose_context")?.loseContext();
|
|
6240
|
+
canvas.remove();
|
|
6241
|
+
};
|
|
6242
|
+
if (!vertex2 || !fragment || !program || !corners || !texture) {
|
|
6243
|
+
const why = gl.isContextLost() ? "the WebGL2 context was lost as it was made" : "WebGL2 made no shader, program, buffer or texture";
|
|
6244
|
+
free();
|
|
6245
|
+
refused(why, null);
|
|
5590
6246
|
return null;
|
|
5591
6247
|
}
|
|
5592
|
-
|
|
5593
|
-
|
|
6248
|
+
gl.attachShader(program, vertex2);
|
|
6249
|
+
gl.attachShader(program, fragment);
|
|
6250
|
+
gl.linkProgram(program);
|
|
6251
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
6252
|
+
const log = [vertex2, fragment].map((shader) => gl.getShaderInfoLog(shader)).find((said) => said?.trim()) ?? gl.getProgramInfoLog(program);
|
|
6253
|
+
const lost = gl.isContextLost();
|
|
6254
|
+
free();
|
|
6255
|
+
refused(lost ? "the WebGL2 context was lost as it was made" : `the shader did not compile or link: ${firstLine(log, "no reason given")}`, null);
|
|
5594
6256
|
return null;
|
|
5595
|
-
const { canvas, pen } = drawn;
|
|
5596
|
-
pen.fillStyle = color;
|
|
5597
|
-
pen.fillRect(0, 0, canvas.width, canvas.height);
|
|
5598
|
-
pen.setTransform(scale, 0, 0, scale, at.x, at.y);
|
|
5599
|
-
pen.drawImage(image, 0, 0, width, height);
|
|
5600
|
-
if (over) {
|
|
5601
|
-
pen.setTransform(1, 0, 0, 1, 0, 0);
|
|
5602
|
-
pen.drawImage(over.canvas, 0, 0);
|
|
5603
|
-
spend(over.canvas);
|
|
5604
6257
|
}
|
|
5605
|
-
|
|
6258
|
+
gl.useProgram(program);
|
|
6259
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, corners);
|
|
6260
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]), gl.STATIC_DRAW);
|
|
6261
|
+
const corner = gl.getAttribLocation(program, "corner");
|
|
6262
|
+
gl.enableVertexAttribArray(corner);
|
|
6263
|
+
gl.vertexAttribPointer(corner, 2, gl.FLOAT, false, 0, 0);
|
|
6264
|
+
const at = (name) => gl.getUniformLocation(program, name);
|
|
6265
|
+
const { stage } = place2;
|
|
6266
|
+
gl.uniform4f(at("view"), rect.x, rect.y, rect.width, rect.height);
|
|
6267
|
+
gl.uniform2f(at("stage"), stage.width, stage.height);
|
|
6268
|
+
gl.uniform2f(at("along"), place2.across ? 0 : 1, place2.across ? 1 : 0);
|
|
6269
|
+
gl.uniform3f(at("line"), ...hingeLine(place2.pane, place2.across, place2.part));
|
|
6270
|
+
gl.uniform1f(at("px"), canvas.width > 0 ? rect.width / canvas.width : 1);
|
|
6271
|
+
gl.uniform1i(at("page"), 0);
|
|
6272
|
+
const wipe = WIPE[place2.pane];
|
|
6273
|
+
gl.uniform2f(at("run"), uvOf(place2.pane, 0), uvOf(place2.pane, 1) - uvOf(place2.pane, 0));
|
|
6274
|
+
gl.uniform3f(at("wiped"), wipe.at, wipe.shade[0], wipe.shade[1]);
|
|
6275
|
+
gl.uniform2f(at("soften"), wipe.blur[0], wipe.blur[1]);
|
|
6276
|
+
const uniforms = { peak: at("peak"), edge: at("edge"), free: at("free"), dark: at("dark"), shape: at("shape"), rimmed: at("rimmed"), band: at("band"), lit: at("lit"), grain: at("grain") };
|
|
6277
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
6278
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
6279
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
6280
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
6281
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
6282
|
+
gl.viewport(0, 0, canvas.width, canvas.height);
|
|
6283
|
+
const widest = gl.getParameter(gl.MAX_TEXTURE_SIZE) || 2048;
|
|
6284
|
+
let shot = null;
|
|
6285
|
+
let look = null;
|
|
6286
|
+
let gone = false;
|
|
6287
|
+
const draw = (next) => {
|
|
6288
|
+
look = next;
|
|
6289
|
+
if (gone || !shot)
|
|
6290
|
+
return;
|
|
6291
|
+
gl.uniform1f(uniforms.peak, next.peak);
|
|
6292
|
+
gl.uniform2f(uniforms.edge, ...next.edge);
|
|
6293
|
+
gl.uniform1f(uniforms.free, next.free);
|
|
6294
|
+
gl.uniform1f(uniforms.dark, next.dark);
|
|
6295
|
+
gl.uniform2f(uniforms.shape, tune.blurHinge, tune.blurRise);
|
|
6296
|
+
gl.uniform2f(uniforms.rimmed, tune.edgeReach, tune.blurSpread);
|
|
6297
|
+
gl.uniform3f(uniforms.band, tune.darkFrom, tune.darkBand, tune.darkBroad);
|
|
6298
|
+
gl.uniform3f(uniforms.lit, ...next.lit);
|
|
6299
|
+
gl.uniform1f(uniforms.grain, tune.grain);
|
|
6300
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
6301
|
+
};
|
|
6302
|
+
canvas.addEventListener("webglcontextlost", () => {
|
|
6303
|
+
if (gone)
|
|
6304
|
+
return;
|
|
6305
|
+
gone = true;
|
|
6306
|
+
canvas.remove();
|
|
6307
|
+
refused("the WebGL2 context was lost", shot);
|
|
6308
|
+
});
|
|
6309
|
+
const refuse = (why, next) => {
|
|
6310
|
+
if (!gone)
|
|
6311
|
+
free();
|
|
6312
|
+
gone = true;
|
|
6313
|
+
refused(why, next);
|
|
6314
|
+
};
|
|
6315
|
+
return {
|
|
6316
|
+
canvas,
|
|
6317
|
+
paint(next) {
|
|
6318
|
+
if (gone)
|
|
6319
|
+
return refuse("the WebGL2 context is gone", next);
|
|
6320
|
+
if (Math.max(next.width, next.height) > widest) {
|
|
6321
|
+
return refuse(`the picture, ${next.width} by ${next.height} px, is larger than MAX_TEXTURE_SIZE, ${widest}`, next);
|
|
6322
|
+
}
|
|
6323
|
+
gl.getError();
|
|
6324
|
+
try {
|
|
6325
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, next);
|
|
6326
|
+
} catch (error) {
|
|
6327
|
+
return refuse(uploadWhy(error), next);
|
|
6328
|
+
}
|
|
6329
|
+
const failed = gl.getError();
|
|
6330
|
+
if (failed !== gl.NO_ERROR)
|
|
6331
|
+
return refuse(`the picture could not be uploaded: WebGL2 error 0x${failed.toString(16)}`, next);
|
|
6332
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
6333
|
+
shot = next;
|
|
6334
|
+
if (look)
|
|
6335
|
+
draw(look);
|
|
6336
|
+
},
|
|
6337
|
+
draw,
|
|
6338
|
+
release() {
|
|
6339
|
+
if (gone)
|
|
6340
|
+
return;
|
|
6341
|
+
gone = true;
|
|
6342
|
+
free();
|
|
6343
|
+
}
|
|
6344
|
+
};
|
|
5606
6345
|
}
|
|
5607
6346
|
|
|
5608
6347
|
// src/engine/barshot.ts
|
|
@@ -5721,12 +6460,12 @@ function corners(radius, by = 0) {
|
|
|
5721
6460
|
function roundRect(rect, radius) {
|
|
5722
6461
|
const { x, y, width, height } = rect;
|
|
5723
6462
|
const [a, b, c, d] = corners(radius).map((r) => Math.max(0, Math.min(r, width / 2, height / 2)));
|
|
5724
|
-
const
|
|
6463
|
+
const arc2 = (r = 0) => `A${r} ${r} 0 0 1`;
|
|
5725
6464
|
return [
|
|
5726
|
-
`M${x + a} ${y}H${x + width - b}${
|
|
5727
|
-
`V${y + height - c}${
|
|
5728
|
-
`H${x + d}${
|
|
5729
|
-
`V${y + a}${
|
|
6465
|
+
`M${x + a} ${y}H${x + width - b}${arc2(b)} ${x + width} ${y + b}`,
|
|
6466
|
+
`V${y + height - c}${arc2(c)} ${x + width - c} ${y + height}`,
|
|
6467
|
+
`H${x + d}${arc2(d)} ${x} ${y + height - d}`,
|
|
6468
|
+
`V${y + a}${arc2(a)} ${x + a} ${y}Z`
|
|
5730
6469
|
].join("");
|
|
5731
6470
|
}
|
|
5732
6471
|
function drawMock(mock, screenSize, href) {
|
|
@@ -5735,14 +6474,6 @@ function drawMock(mock, screenSize, href) {
|
|
|
5735
6474
|
viewBox: `0 0 ${mock.width} ${mock.height}`,
|
|
5736
6475
|
"aria-hidden": "true"
|
|
5737
6476
|
});
|
|
5738
|
-
if (mock.image && href) {
|
|
5739
|
-
const { x: x2, y: y2, width: width2, height: height2, turn: turn2 } = mock.image;
|
|
5740
|
-
const image = svgNode("image", { href, x: x2, y: y2, width: width2, height: height2 });
|
|
5741
|
-
if (turn2 !== null)
|
|
5742
|
-
image.setAttribute("transform", `matrix(0 -1 1 0 0 ${turn2})`);
|
|
5743
|
-
svg.append(image);
|
|
5744
|
-
return svg;
|
|
5745
|
-
}
|
|
5746
6477
|
const part = (shape) => svgNode("rect", {
|
|
5747
6478
|
class: shape.kind,
|
|
5748
6479
|
x: shape.x,
|
|
@@ -5751,6 +6482,16 @@ function drawMock(mock, screenSize, href) {
|
|
|
5751
6482
|
height: shape.height,
|
|
5752
6483
|
rx: shape.radius
|
|
5753
6484
|
});
|
|
6485
|
+
if (mock.image && href) {
|
|
6486
|
+
const { x: x2, y: y2, width: width2, height: height2, turn: turn2, clockwise, over: over2 } = mock.image;
|
|
6487
|
+
const image = svgNode("image", { href, x: x2, y: y2, width: width2, height: height2 });
|
|
6488
|
+
if (turn2 !== null) {
|
|
6489
|
+
image.setAttribute("transform", clockwise ? `matrix(0 1 -1 0 ${turn2} 0)` : `matrix(0 -1 1 0 0 ${turn2})`);
|
|
6490
|
+
} else if (over2)
|
|
6491
|
+
image.setAttribute("transform", `matrix(-1 0 0 -1 ${mock.width} ${mock.height})`);
|
|
6492
|
+
svg.append(image, ...mock.parts.map(part));
|
|
6493
|
+
return svg;
|
|
6494
|
+
}
|
|
5754
6495
|
const opening = { x: mock.inset.left, y: mock.inset.top, ...screenSize };
|
|
5755
6496
|
const { x, y, width, height } = mock.body;
|
|
5756
6497
|
const front = { x: x + BAND, y: y + BAND, width: width - 2 * BAND, height: height - 2 * BAND };
|
|
@@ -5765,7 +6506,7 @@ function div(className) {
|
|
|
5765
6506
|
node.className = className;
|
|
5766
6507
|
return node;
|
|
5767
6508
|
}
|
|
5768
|
-
function
|
|
6509
|
+
function round2(radii) {
|
|
5769
6510
|
return radii.map((radius) => `${radius}px`).join(" ");
|
|
5770
6511
|
}
|
|
5771
6512
|
function fill(node) {
|
|
@@ -5843,7 +6584,7 @@ function roughOf(frame2, glass, value, size, color) {
|
|
|
5843
6584
|
const { device, posture, orientation, browser, edgeToEdge } = value;
|
|
5844
6585
|
return shootPage(frame2, glass, size, color, [device, posture, orientation, browser, edgeToEdge].join(" "));
|
|
5845
6586
|
}
|
|
5846
|
-
function
|
|
6587
|
+
function pictureOf2(frame2, glass, value, size, color, copy) {
|
|
5847
6588
|
const shown2 = glass.querySelector(":scope > .browser");
|
|
5848
6589
|
const bars = shown2 ? document.importNode(shown2, true) : null;
|
|
5849
6590
|
if (bars)
|
|
@@ -6051,8 +6792,8 @@ function pose(turning, layout, open, shown2, still2) {
|
|
|
6051
6792
|
const fade = (value) => value >= 1 ? "" : String(Math.round(Math.max(0, value) * 1000) / 1000);
|
|
6052
6793
|
model.style.opacity = fade(shown2);
|
|
6053
6794
|
turning.still.canvas.style.opacity = fade(still2);
|
|
6054
|
-
const
|
|
6055
|
-
const by = [turning.inner.gl, turning.inner.pictures, turning.outer.gl, turning.outer.pictures, 0, ...
|
|
6795
|
+
const over2 = [turning.inner.stage.lastElementChild, turning.outer.stage.lastElementChild];
|
|
6796
|
+
const by = [turning.inner.gl, turning.inner.pictures, turning.outer.gl, turning.outer.pictures, 0, ...over2];
|
|
6056
6797
|
const { lit } = turning;
|
|
6057
6798
|
if (lit && lit.shot === shot && lit.by.every((one, index) => one === by[index]))
|
|
6058
6799
|
return;
|
|
@@ -6192,9 +6933,9 @@ function turnTo(turn2, to, done) {
|
|
|
6192
6933
|
if (spin)
|
|
6193
6934
|
window.cancelAnimationFrame(spin.frame);
|
|
6194
6935
|
const time = MORPH_TIME.turn * Math.abs(to.angle - from.angle) / 90;
|
|
6195
|
-
const
|
|
6936
|
+
const over2 = cover?.share ?? 0;
|
|
6196
6937
|
const across = to.angle === 0 ? 0 : 1;
|
|
6197
|
-
coverTo(turn2.cover,
|
|
6938
|
+
coverTo(turn2.cover, over2);
|
|
6198
6939
|
const going = { spin: turn2, pose: from, frame: 0, done };
|
|
6199
6940
|
spin = going;
|
|
6200
6941
|
let begin = null;
|
|
@@ -6203,7 +6944,7 @@ function turnTo(turn2, to, done) {
|
|
|
6203
6944
|
const elapsed = now - begin;
|
|
6204
6945
|
going.pose = poseAt(from, to, elapsed, time);
|
|
6205
6946
|
stand(turn2, going.pose);
|
|
6206
|
-
coverTo(turn2.cover, coverAt(
|
|
6947
|
+
coverTo(turn2.cover, coverAt(over2, across, elapsed, time));
|
|
6207
6948
|
if (elapsed < time) {
|
|
6208
6949
|
going.frame = window.requestAnimationFrame(step);
|
|
6209
6950
|
return;
|
|
@@ -6293,7 +7034,7 @@ function leafOf(side, picture, turning2, across) {
|
|
|
6293
7034
|
const { rect } = turning2;
|
|
6294
7035
|
const screen = placeAt(div(""), whole);
|
|
6295
7036
|
screen.style.background = "#000";
|
|
6296
|
-
screen.style.borderRadius =
|
|
7037
|
+
screen.style.borderRadius = round2(radii);
|
|
6297
7038
|
if (href)
|
|
6298
7039
|
screen.style.boxShadow = `0 0 0 ${UNDER}px #000`;
|
|
6299
7040
|
node.append(screen);
|
|
@@ -6309,7 +7050,7 @@ function leafOf(side, picture, turning2, across) {
|
|
|
6309
7050
|
dark.style.inset = "-100%";
|
|
6310
7051
|
dark.style.background = "#000";
|
|
6311
7052
|
const stage = placeAt(div(""), { ...whole, x: whole.x - rect.x, y: whole.y - rect.y });
|
|
6312
|
-
stage.style.borderRadius =
|
|
7053
|
+
stage.style.borderRadius = round2(radii);
|
|
6313
7054
|
stage.style.overflow = "hidden";
|
|
6314
7055
|
if (picture.bars)
|
|
6315
7056
|
stage.append(picture.bars);
|
|
@@ -6323,9 +7064,9 @@ function leafOf(side, picture, turning2, across) {
|
|
|
6323
7064
|
veil.style.width = node.style.width;
|
|
6324
7065
|
veil.style.height = node.style.height;
|
|
6325
7066
|
const shade = placeAt(div(""), rect);
|
|
6326
|
-
shade.style.borderRadius =
|
|
7067
|
+
shade.style.borderRadius = round2(turning2.radii);
|
|
6327
7068
|
const freeEdge = placeAt(div(""), rect);
|
|
6328
|
-
freeEdge.style.borderRadius =
|
|
7069
|
+
freeEdge.style.borderRadius = round2(turning2.radii);
|
|
6329
7070
|
veil.append(shade, freeEdge);
|
|
6330
7071
|
const leaf = {
|
|
6331
7072
|
pane: turning2.pane,
|
|
@@ -6379,8 +7120,10 @@ function copiesOf(layout, open, closed, pictures) {
|
|
|
6379
7120
|
inner.screen.style.clipPath = layout.across ? `inset(${-far}px ${short(whole.x + whole.width - layout.hinge)}px ${-far}px ${-far}px)` : `inset(${short(layout.hinge - whole.y)}px ${-far}px ${-far}px ${-far}px)`;
|
|
6380
7121
|
return { inner, outer };
|
|
6381
7122
|
}
|
|
6382
|
-
function build(scene, layout, open, closed, pictures, found) {
|
|
7123
|
+
function build(scene, layout, open, closed, pictures, found, flip) {
|
|
6383
7124
|
const layer = div("fold");
|
|
7125
|
+
if (flip)
|
|
7126
|
+
layer.style.transform = "rotate(180deg)";
|
|
6384
7127
|
const place2 = div("");
|
|
6385
7128
|
let turning2;
|
|
6386
7129
|
const shots2 = found && shotsOf(layout, open, closed, pictures, found);
|
|
@@ -6423,9 +7166,11 @@ function retake(going) {
|
|
|
6423
7166
|
const { size } = going.faces.open;
|
|
6424
7167
|
const color = scene.background();
|
|
6425
7168
|
const last = going.pictures.open;
|
|
6426
|
-
|
|
7169
|
+
const rough = roughOf(scene.frame, scene.glass, values.open, size, color);
|
|
7170
|
+
if ((going.flip && rough ? flipPicture({ shot: rough, painted: null, bars: null }, size).shot : rough) === last.shot)
|
|
6427
7171
|
return;
|
|
6428
|
-
const
|
|
7172
|
+
const taken = pictureOf2(scene.frame, scene.glass, values.open, size, color, copyPage(scene.frame));
|
|
7173
|
+
const next = going.flip ? flipPicture(taken, size) : taken;
|
|
6429
7174
|
going.pictures = { ...going.pictures, open: next };
|
|
6430
7175
|
const put = (shot) => {
|
|
6431
7176
|
if (fold !== going || going.pictures.open !== next)
|
|
@@ -6436,18 +7181,18 @@ function retake(going) {
|
|
|
6436
7181
|
else
|
|
6437
7182
|
paintLeaf(turning2.inner, shot);
|
|
6438
7183
|
};
|
|
6439
|
-
const
|
|
7184
|
+
const roughly = () => {
|
|
6440
7185
|
if (next.shot)
|
|
6441
7186
|
put(next.shot);
|
|
6442
7187
|
};
|
|
6443
7188
|
if (!next.painted)
|
|
6444
|
-
|
|
7189
|
+
roughly();
|
|
6445
7190
|
else {
|
|
6446
7191
|
next.painted.then((drawn) => {
|
|
6447
7192
|
if (drawn)
|
|
6448
7193
|
paintDrawn(next, drawn, put);
|
|
6449
7194
|
else
|
|
6450
|
-
|
|
7195
|
+
roughly();
|
|
6451
7196
|
});
|
|
6452
7197
|
}
|
|
6453
7198
|
}
|
|
@@ -6491,7 +7236,7 @@ function show(going) {
|
|
|
6491
7236
|
going.waiting = false;
|
|
6492
7237
|
const { open: open2, closed } = going.faces;
|
|
6493
7238
|
drop(going.parts);
|
|
6494
|
-
going.parts = build(going.scene, going.layout, open2, closed, going.pictures, found);
|
|
7239
|
+
going.parts = build(going.scene, going.layout, open2, closed, going.pictures, found, going.flip);
|
|
6495
7240
|
going.drawn = "";
|
|
6496
7241
|
}
|
|
6497
7242
|
const { layout, parts } = going;
|
|
@@ -6524,8 +7269,14 @@ function show(going) {
|
|
|
6524
7269
|
const opened = unit.posture === "open";
|
|
6525
7270
|
const own = opened ? layout.unfolded.scale : layout.folded.scale;
|
|
6526
7271
|
const drift = shots2 ? shotsDrift(shots2.shots, layout, shots2.inside, shots2.outside, open, unit.posture) : { wide: 1, tall: 1, x: 0, y: 0 };
|
|
6527
|
-
const body = opened ? { x: 0, y: 0 } : layout.shut;
|
|
6528
|
-
const
|
|
7272
|
+
const body = opened ? { x: 0, y: 0, ...layout.open } : layout.shut;
|
|
7273
|
+
const laid = {
|
|
7274
|
+
x: x + (drift.wide * body.x + drift.x) * scale,
|
|
7275
|
+
y: y + (drift.tall * body.y + drift.y) * scale,
|
|
7276
|
+
width: body.width * drift.wide * scale,
|
|
7277
|
+
height: body.height * drift.tall * scale
|
|
7278
|
+
};
|
|
7279
|
+
const to = going.flip ? flipRect(laid, going.flip) : laid;
|
|
6529
7280
|
const by = { x: to.x - unit.corner.x, y: to.y - unit.corner.y };
|
|
6530
7281
|
const size = unit.base * scale / own;
|
|
6531
7282
|
scene.unit.style.transform = `translate(${by.x}px, ${by.y}px) scale(${size * drift.wide}, ${size * drift.tall})`;
|
|
@@ -6543,7 +7294,9 @@ function stillClip(going, shots2, inside, own) {
|
|
|
6543
7294
|
const under = inside ? 1 + 2 * (shots2?.inner.over ?? 0) : 0;
|
|
6544
7295
|
const hinge = at(layout.hinge + (layout.across ? -under : under));
|
|
6545
7296
|
const far = 1e5;
|
|
6546
|
-
const
|
|
7297
|
+
const { width, height } = layout.open;
|
|
7298
|
+
const placed = ([px, py]) => going.flip ? [at(width) - px, at(height) - py] : [px, py];
|
|
7299
|
+
const points = (corners2) => `polygon(${corners2.map(placed).map(([px, py]) => `${px}px ${py}px`).join(", ")})`;
|
|
6547
7300
|
if (!shots2 || going.still < 1) {
|
|
6548
7301
|
return layout.across ? points([[hinge, -far], [far, -far], [far, far], [hinge, far]]) : points([[-far, -far], [far, -far], [far, hinge], [-far, hinge]]);
|
|
6549
7302
|
}
|
|
@@ -6710,14 +7463,18 @@ function foldDevice(from, value, scene, draw, held = false) {
|
|
|
6710
7463
|
coverTo(scene.cover, 0);
|
|
6711
7464
|
scene.glass.append(scene.cover);
|
|
6712
7465
|
const color = scene.background();
|
|
6713
|
-
const now = sideOf(scene, from, scene.screenRect());
|
|
6714
|
-
const next = sideOf(scene, value, to);
|
|
6715
7466
|
const opening = value.posture === "open";
|
|
6716
7467
|
const across = (opening ? value : from).orientation === "landscape";
|
|
7468
|
+
const { letterbox } = scene;
|
|
7469
|
+
const flip = !across && formOf(from.device, "closed")?.clockwise === true ? { width: letterbox.clientWidth, height: letterbox.clientHeight } : null;
|
|
7470
|
+
const turn2 = (face) => flip ? flipFace(face, flip) : face;
|
|
7471
|
+
const now = turn2(sideOf(scene, from, scene.screenRect()));
|
|
7472
|
+
const next = turn2(sideOf(scene, value, to));
|
|
6717
7473
|
const copy = copyPage(scene.frame);
|
|
6718
|
-
const
|
|
7474
|
+
const turnPicture = (picture, size) => flip ? flipPicture(picture, size) : picture;
|
|
7475
|
+
const before = turnPicture(pictureOf2(scene.frame, scene.glass, from, now.size, color, copy), now.size);
|
|
6719
7476
|
draw(value);
|
|
6720
|
-
const after =
|
|
7477
|
+
const after = turnPicture(pictureOf2(scene.frame, scene.glass, value, next.size, color, copy), next.size);
|
|
6721
7478
|
draw(from);
|
|
6722
7479
|
const closed = opening ? now : next;
|
|
6723
7480
|
const open = opening ? next : now;
|
|
@@ -6729,7 +7486,7 @@ function foldDevice(from, value, scene, draw, held = false) {
|
|
|
6729
7486
|
const target = openOf((held ? from : value).posture);
|
|
6730
7487
|
if (duo)
|
|
6731
7488
|
decodeFoldShots(start, Math.sign(start - target));
|
|
6732
|
-
const parts = build(scene, layout, open, closed, pictures, duo ? foldShots() : null);
|
|
7489
|
+
const parts = build(scene, layout, open, closed, pictures, duo ? foldShots() : null, flip);
|
|
6733
7490
|
const wait = held ? null : { since: null, painted: !before.painted && !after.painted };
|
|
6734
7491
|
if (wait && !wait.painted) {
|
|
6735
7492
|
Promise.all([before.painted, after.painted]).then(() => {
|
|
@@ -6757,6 +7514,7 @@ function foldDevice(from, value, scene, draw, held = false) {
|
|
|
6757
7514
|
wait,
|
|
6758
7515
|
parts,
|
|
6759
7516
|
unit: measure2(scene, from.posture),
|
|
7517
|
+
flip,
|
|
6760
7518
|
fresh: null,
|
|
6761
7519
|
still: 0,
|
|
6762
7520
|
out: 1,
|
|
@@ -6871,12 +7629,22 @@ function clear3(color) {
|
|
|
6871
7629
|
return color === "" || color === "transparent" || /[,/]\s*0\)$/.test(color);
|
|
6872
7630
|
}
|
|
6873
7631
|
function paintVeil(veil) {
|
|
7632
|
+
veil.className = "veil";
|
|
6874
7633
|
const root = getComputedStyle(document.documentElement);
|
|
6875
7634
|
const body = document.body ? getComputedStyle(document.body).backgroundColor : "";
|
|
6876
7635
|
const color = [root.backgroundColor, body].find((value) => !clear3(value));
|
|
6877
7636
|
veil.style.background = color ?? "Canvas";
|
|
6878
7637
|
veil.style.colorScheme = root.colorScheme || "normal";
|
|
6879
7638
|
}
|
|
7639
|
+
function paintCover(scene) {
|
|
7640
|
+
scene.veil.className = "veil loading";
|
|
7641
|
+
scene.veil.style.background = "";
|
|
7642
|
+
scene.veil.style.colorScheme = scene.scheme();
|
|
7643
|
+
}
|
|
7644
|
+
function evenHole(hole) {
|
|
7645
|
+
const round3 = Math.max(...hole.radius);
|
|
7646
|
+
return { ...hole, radius: [round3, round3, round3, round3] };
|
|
7647
|
+
}
|
|
6880
7648
|
function openVeiled(scene, share) {
|
|
6881
7649
|
seen = { veil: share, content: 0, hole: scene.fullRect() };
|
|
6882
7650
|
paintVeil(scene.veil);
|
|
@@ -6958,6 +7726,8 @@ function moveHole(scene, to, time) {
|
|
|
6958
7726
|
}
|
|
6959
7727
|
function placeHole(scene, hole) {
|
|
6960
7728
|
seen.hole = hole;
|
|
7729
|
+
scene.veil.style.setProperty("--dot-x", `${hole.x + hole.width / 2}px`);
|
|
7730
|
+
scene.veil.style.setProperty("--dot-y", `${hole.y + hole.height / 2}px`);
|
|
6961
7731
|
const path3 = holePath(hole);
|
|
6962
7732
|
if (path3 === cut2)
|
|
6963
7733
|
return;
|
|
@@ -6969,7 +7739,7 @@ function track2(scene) {
|
|
|
6969
7739
|
const step = () => {
|
|
6970
7740
|
if (tracking !== frame2)
|
|
6971
7741
|
return;
|
|
6972
|
-
placeHole(scene, scene.screenRect());
|
|
7742
|
+
placeHole(scene, evenHole(scene.screenRect()));
|
|
6973
7743
|
frame2 = window.requestAnimationFrame(step);
|
|
6974
7744
|
tracking = frame2;
|
|
6975
7745
|
};
|
|
@@ -7019,7 +7789,7 @@ async function perform(scene, step, target, instant) {
|
|
|
7019
7789
|
} else if (step.kind === "layout") {
|
|
7020
7790
|
scene.layout();
|
|
7021
7791
|
} else if (step.kind === "mat") {
|
|
7022
|
-
const to = step.to === "screen" ? scene.screenRect : step.to === "round" ? () => rounded(scene.fullRect()) : scene.fullRect;
|
|
7792
|
+
const to = step.to === "screen" ? () => evenHole(scene.screenRect()) : step.to === "round" ? () => rounded(scene.fullRect()) : scene.fullRect;
|
|
7023
7793
|
const going = run;
|
|
7024
7794
|
await moveHole(scene, to, instant ? 0 : step.time);
|
|
7025
7795
|
if (step.to === "screen" && !instant && going?.live())
|
|
@@ -7036,13 +7806,16 @@ async function perform(scene, step, target, instant) {
|
|
|
7036
7806
|
}
|
|
7037
7807
|
function start(scene, target) {
|
|
7038
7808
|
if (!clipped) {
|
|
7039
|
-
seen = { veil: 1, content: 1, hole: scene.screenRect() };
|
|
7040
|
-
|
|
7809
|
+
seen = { veil: 1, content: 1, hole: evenHole(scene.screenRect()) };
|
|
7810
|
+
if (target === "closed")
|
|
7811
|
+
paintVeil(scene.veil);
|
|
7041
7812
|
scene.veil.style.opacity = "1";
|
|
7042
7813
|
cut2 = "";
|
|
7043
7814
|
placeHole(scene, seen.hole);
|
|
7044
7815
|
clipped = true;
|
|
7045
7816
|
}
|
|
7817
|
+
if (target === "open")
|
|
7818
|
+
paintCover(scene);
|
|
7046
7819
|
const shown3 = { ...seen, covered: scene.covered(), open: sameHole(seen.hole, scene.fullRect()) };
|
|
7047
7820
|
const next = sequence(plan(shown3, target), target);
|
|
7048
7821
|
run = next;
|
|
@@ -7168,7 +7941,7 @@ function rimsAt(splash, plan2, time) {
|
|
|
7168
7941
|
}
|
|
7169
7942
|
return rims;
|
|
7170
7943
|
}
|
|
7171
|
-
function
|
|
7944
|
+
function round3(value) {
|
|
7172
7945
|
return Math.round(value * 10) / 10;
|
|
7173
7946
|
}
|
|
7174
7947
|
function pathOf(rims) {
|
|
@@ -7177,8 +7950,8 @@ function pathOf(rims) {
|
|
|
7177
7950
|
const [first] = curve;
|
|
7178
7951
|
if (!first)
|
|
7179
7952
|
return "";
|
|
7180
|
-
const start2 = `M${
|
|
7181
|
-
const rest3 = curve.map(([, c1, c2, end]) => `C${
|
|
7953
|
+
const start2 = `M${round3(first[0].x)} ${round3(first[0].y)}`;
|
|
7954
|
+
const rest3 = curve.map(([, c1, c2, end]) => `C${round3(c1.x)} ${round3(c1.y)} ${round3(c2.x)} ${round3(c2.y)} ${round3(end.x)} ${round3(end.y)}`);
|
|
7182
7955
|
return `${start2}${rest3.join("")}Z`;
|
|
7183
7956
|
}).join("");
|
|
7184
7957
|
}
|
|
@@ -7320,8 +8093,6 @@ function explain(box2, refusal, again) {
|
|
|
7320
8093
|
};
|
|
7321
8094
|
button.addEventListener("click", run2);
|
|
7322
8095
|
why.append(button);
|
|
7323
|
-
if (retry.now)
|
|
7324
|
-
run2();
|
|
7325
8096
|
}
|
|
7326
8097
|
}
|
|
7327
8098
|
|
|
@@ -7712,8 +8483,45 @@ var VIEWPORT_CSS = `
|
|
|
7712
8483
|
top: 0;
|
|
7713
8484
|
left: 0;
|
|
7714
8485
|
}
|
|
8486
|
+
/* Holds the cover over the frame. */
|
|
8487
|
+
.page { position: relative; }
|
|
7715
8488
|
/* Where a phone's browser leaves the page in its screen. */
|
|
7716
8489
|
.page.placed { position: absolute; }
|
|
8490
|
+
/* Over the frame while its page loads or a host loads it again, so a browser's
|
|
8491
|
+
error page never flashes: the frame's own canvas, a dot that breathes. */
|
|
8492
|
+
.loading {
|
|
8493
|
+
position: absolute;
|
|
8494
|
+
inset: 0;
|
|
8495
|
+
display: flex;
|
|
8496
|
+
align-items: center;
|
|
8497
|
+
justify-content: center;
|
|
8498
|
+
background: Canvas;
|
|
8499
|
+
color: CanvasText;
|
|
8500
|
+
/* The user's own scheme, unless the knob forces one. */
|
|
8501
|
+
color-scheme: light dark;
|
|
8502
|
+
pointer-events: none;
|
|
8503
|
+
}
|
|
8504
|
+
.loading[hidden] { display: none; }
|
|
8505
|
+
/* The veil wears the cover between two devices, its dot in the mat's opening. */
|
|
8506
|
+
.veil.loading::after {
|
|
8507
|
+
position: absolute;
|
|
8508
|
+
left: var(--dot-x, 50%);
|
|
8509
|
+
top: var(--dot-y, 50%);
|
|
8510
|
+
translate: -50% -50%;
|
|
8511
|
+
}
|
|
8512
|
+
.loading::after {
|
|
8513
|
+
content: "";
|
|
8514
|
+
width: 6px;
|
|
8515
|
+
height: 6px;
|
|
8516
|
+
border-radius: 50%;
|
|
8517
|
+
background: currentColor;
|
|
8518
|
+
opacity: 0.25;
|
|
8519
|
+
animation: devknobs-breathe 1.2s ease-in-out infinite alternate;
|
|
8520
|
+
}
|
|
8521
|
+
@keyframes devknobs-breathe { to { opacity: 0.08; } }
|
|
8522
|
+
@media (prefers-reduced-motion: reduce) {
|
|
8523
|
+
.loading::after { animation: none; }
|
|
8524
|
+
}
|
|
7717
8525
|
iframe {
|
|
7718
8526
|
display: block;
|
|
7719
8527
|
border: 0;
|
|
@@ -7800,7 +8608,7 @@ function visionFilter(value) {
|
|
|
7800
8608
|
}
|
|
7801
8609
|
|
|
7802
8610
|
// src/engine/width.ts
|
|
7803
|
-
var
|
|
8611
|
+
var NAME = "width";
|
|
7804
8612
|
var RIDE_SLOW = 50;
|
|
7805
8613
|
var FRAME_API_WAIT = 1500;
|
|
7806
8614
|
var ZOOM_SETTLE = 200;
|
|
@@ -7849,7 +8657,14 @@ var notice = null;
|
|
|
7849
8657
|
var exit2 = null;
|
|
7850
8658
|
var askWhy = null;
|
|
7851
8659
|
var framed = null;
|
|
8660
|
+
var loader = null;
|
|
8661
|
+
var ANSWER_WAIT = 6000;
|
|
7852
8662
|
var refusals = 0;
|
|
8663
|
+
var loadCover = null;
|
|
8664
|
+
var coverPoll = 0;
|
|
8665
|
+
var coverCap = 0;
|
|
8666
|
+
var COVER_POLL = 50;
|
|
8667
|
+
var COVER_CAP = ANSWER_WAIT + 2000;
|
|
7853
8668
|
var current = {
|
|
7854
8669
|
...UNFRAMED,
|
|
7855
8670
|
scheme: "system",
|
|
@@ -7908,16 +8723,78 @@ function onRefused(handler) {
|
|
|
7908
8723
|
function onFramed(handler) {
|
|
7909
8724
|
framed = handler;
|
|
7910
8725
|
}
|
|
8726
|
+
function onLoader(handler) {
|
|
8727
|
+
loader = handler;
|
|
8728
|
+
}
|
|
8729
|
+
function navigate(target, url) {
|
|
8730
|
+
if (!loader?.(target, url))
|
|
8731
|
+
target.src = url;
|
|
8732
|
+
}
|
|
7911
8733
|
function whyRefused() {
|
|
7912
8734
|
const box2 = notice;
|
|
7913
8735
|
const turn2 = ++refusals;
|
|
7914
8736
|
if (!box2)
|
|
7915
8737
|
return;
|
|
7916
8738
|
explain(box2, null, loadAgain);
|
|
7917
|
-
askWhy
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
8739
|
+
if (!askWhy) {
|
|
8740
|
+
hideCover();
|
|
8741
|
+
box2.hidden = false;
|
|
8742
|
+
return;
|
|
8743
|
+
}
|
|
8744
|
+
showCover();
|
|
8745
|
+
const still2 = () => turn2 === refusals && notice === box2;
|
|
8746
|
+
let answered = false;
|
|
8747
|
+
const show2 = (refusal) => {
|
|
8748
|
+
if (!still2())
|
|
8749
|
+
return;
|
|
8750
|
+
hideCover();
|
|
8751
|
+
box2.hidden = false;
|
|
8752
|
+
explain(box2, refusal, loadAgain);
|
|
8753
|
+
};
|
|
8754
|
+
window.setTimeout(() => {
|
|
8755
|
+
if (!answered)
|
|
8756
|
+
show2(null);
|
|
8757
|
+
}, ANSWER_WAIT);
|
|
8758
|
+
askWhy(frameUrl).then((refusal) => {
|
|
8759
|
+
answered = true;
|
|
8760
|
+
const retry = refusal?.retry;
|
|
8761
|
+
if (!retry?.now) {
|
|
8762
|
+
show2(refusal);
|
|
8763
|
+
return;
|
|
8764
|
+
}
|
|
8765
|
+
retry.run().then(() => {
|
|
8766
|
+
if (still2())
|
|
8767
|
+
loadAgain();
|
|
8768
|
+
}, (error) => show2({ why: error instanceof Error ? error.message : String(error) }));
|
|
8769
|
+
}, () => {
|
|
8770
|
+
answered = true;
|
|
8771
|
+
show2(null);
|
|
8772
|
+
});
|
|
8773
|
+
}
|
|
8774
|
+
function readable() {
|
|
8775
|
+
const doc = frameDocument();
|
|
8776
|
+
return doc !== null && doc.URL !== "about:blank" && doc.readyState !== "loading";
|
|
8777
|
+
}
|
|
8778
|
+
function showCover() {
|
|
8779
|
+
if (!loadCover)
|
|
8780
|
+
return;
|
|
8781
|
+
clearTimeout(coverPoll);
|
|
8782
|
+
clearTimeout(coverCap);
|
|
8783
|
+
loadCover.hidden = false;
|
|
8784
|
+
const look = () => {
|
|
8785
|
+
if (readable())
|
|
8786
|
+
hideCover();
|
|
8787
|
+
else
|
|
8788
|
+
coverPoll = window.setTimeout(look, COVER_POLL);
|
|
8789
|
+
};
|
|
8790
|
+
coverPoll = window.setTimeout(look, COVER_POLL);
|
|
8791
|
+
coverCap = window.setTimeout(hideCover, COVER_CAP);
|
|
8792
|
+
}
|
|
8793
|
+
function hideCover() {
|
|
8794
|
+
clearTimeout(coverPoll);
|
|
8795
|
+
clearTimeout(coverCap);
|
|
8796
|
+
if (loadCover)
|
|
8797
|
+
loadCover.hidden = true;
|
|
7921
8798
|
}
|
|
7922
8799
|
function loadAgain() {
|
|
7923
8800
|
if (!frame3)
|
|
@@ -7927,7 +8804,8 @@ function loadAgain() {
|
|
|
7927
8804
|
refusals += 1;
|
|
7928
8805
|
if (notice)
|
|
7929
8806
|
notice.hidden = true;
|
|
7930
|
-
|
|
8807
|
+
showCover();
|
|
8808
|
+
navigate(frame3, frameUrl);
|
|
7931
8809
|
}
|
|
7932
8810
|
function onZoom(handler) {
|
|
7933
8811
|
zoomTo = handler;
|
|
@@ -7949,9 +8827,13 @@ function onLoad() {
|
|
|
7949
8827
|
loadedAt = performance.now();
|
|
7950
8828
|
const doc = frameDocument();
|
|
7951
8829
|
if (notice)
|
|
7952
|
-
notice.hidden =
|
|
8830
|
+
notice.hidden = true;
|
|
7953
8831
|
if (doc === null)
|
|
7954
8832
|
whyRefused();
|
|
8833
|
+
else {
|
|
8834
|
+
refusals += 1;
|
|
8835
|
+
hideCover();
|
|
8836
|
+
}
|
|
7955
8837
|
locate();
|
|
7956
8838
|
const view = frameWindow();
|
|
7957
8839
|
if (view && doc) {
|
|
@@ -8142,8 +9024,8 @@ function showMock(mock, place2) {
|
|
|
8142
9024
|
const zoom = place2.zoom;
|
|
8143
9025
|
glass.style.left = mock ? `${mock.inset.left * zoom}px` : "";
|
|
8144
9026
|
glass.style.top = mock ? `${mock.inset.top * zoom}px` : "";
|
|
8145
|
-
const
|
|
8146
|
-
glass.style.borderRadius =
|
|
9027
|
+
const round4 = mock ? corners(mock.screenRadius).map((radius) => `${radius * zoom}px`) : [];
|
|
9028
|
+
glass.style.borderRadius = round4.join(" ");
|
|
8147
9029
|
glass.style.boxShadow = href ? `0 0 0 ${UNDER * zoom}px #000` : "";
|
|
8148
9030
|
if (mock && mockDrawing) {
|
|
8149
9031
|
mockDrawing.style.width = `${mock.width * zoom}px`;
|
|
@@ -8186,8 +9068,10 @@ function showMat(size) {
|
|
|
8186
9068
|
mat = next;
|
|
8187
9069
|
}
|
|
8188
9070
|
function bodyFor(value) {
|
|
8189
|
-
|
|
9071
|
+
const body = bodyOf(value, resize);
|
|
9072
|
+
return body && over2 && openUpright(shapeOf(value)) ? flipMock(body) : body;
|
|
8190
9073
|
}
|
|
9074
|
+
var over2 = false;
|
|
8191
9075
|
function resize() {
|
|
8192
9076
|
if (!frame3 || !letterbox || !stage || !drawing || !screen || !readout || !caption)
|
|
8193
9077
|
return;
|
|
@@ -8233,6 +9117,10 @@ function resize() {
|
|
|
8233
9117
|
frame3.style.colorScheme = current.scheme;
|
|
8234
9118
|
else
|
|
8235
9119
|
frame3.style.removeProperty("color-scheme");
|
|
9120
|
+
if (loadCover)
|
|
9121
|
+
loadCover.style.colorScheme = coverScheme();
|
|
9122
|
+
if (veil?.className === "veil loading")
|
|
9123
|
+
veil.style.colorScheme = coverScheme();
|
|
8236
9124
|
frame3.style.filter = visionFilter(current.vision);
|
|
8237
9125
|
checkZoom();
|
|
8238
9126
|
warmFold();
|
|
@@ -8381,6 +9269,7 @@ foldableShown(() => {
|
|
|
8381
9269
|
return scene && { scene, value: current };
|
|
8382
9270
|
});
|
|
8383
9271
|
function foldDevice2(value, held2 = false) {
|
|
9272
|
+
over2 = caseOver(shapeOf(current), shapeOf(value), over2);
|
|
8384
9273
|
landGlide();
|
|
8385
9274
|
touchDot?.rest();
|
|
8386
9275
|
return foldDevice(current, value, foldScene(), draw, held2);
|
|
@@ -8391,7 +9280,7 @@ function hidePage() {
|
|
|
8391
9280
|
return;
|
|
8392
9281
|
covered = true;
|
|
8393
9282
|
cover2(body);
|
|
8394
|
-
const style = ensureStyle(
|
|
9283
|
+
const style = ensureStyle(NAME);
|
|
8395
9284
|
style.textContent = "html{overflow:hidden!important}:popover-open:not([data-devknobs]){display:none!important}";
|
|
8396
9285
|
const node = styleNode(style);
|
|
8397
9286
|
if (node)
|
|
@@ -8404,7 +9293,7 @@ function showPage() {
|
|
|
8404
9293
|
stopKeepingStyle?.();
|
|
8405
9294
|
stopKeepingStyle = null;
|
|
8406
9295
|
uncover2();
|
|
8407
|
-
removeStyle(
|
|
9296
|
+
removeStyle(NAME);
|
|
8408
9297
|
}
|
|
8409
9298
|
function remounted() {
|
|
8410
9299
|
if (covered) {
|
|
@@ -8464,6 +9353,9 @@ function handBack() {
|
|
|
8464
9353
|
showPage();
|
|
8465
9354
|
window.scrollTo({ left: scroll.x, top: scroll.y, behavior: "instant" });
|
|
8466
9355
|
}
|
|
9356
|
+
function coverScheme() {
|
|
9357
|
+
return current.scheme === "system" ? "" : current.scheme;
|
|
9358
|
+
}
|
|
8467
9359
|
function scene() {
|
|
8468
9360
|
if (!host || !back || !veil)
|
|
8469
9361
|
return null;
|
|
@@ -8473,6 +9365,7 @@ function scene() {
|
|
|
8473
9365
|
content: contentNodes,
|
|
8474
9366
|
screenRect,
|
|
8475
9367
|
fullRect,
|
|
9368
|
+
scheme: coverScheme,
|
|
8476
9369
|
covered: () => covered,
|
|
8477
9370
|
hidePage,
|
|
8478
9371
|
painted,
|
|
@@ -8563,12 +9456,12 @@ function open(veiled, first) {
|
|
|
8563
9456
|
waiting2.then(() => {
|
|
8564
9457
|
if (frame3 !== opened)
|
|
8565
9458
|
return;
|
|
8566
|
-
opened.src = frameUrl;
|
|
8567
9459
|
opened.addEventListener("load", onLoad);
|
|
9460
|
+
navigate(opened, frameUrl);
|
|
8568
9461
|
});
|
|
8569
|
-
} else {
|
|
8570
|
-
frame3.src = frameUrl;
|
|
9462
|
+
} else if (!loader) {
|
|
8571
9463
|
frame3.addEventListener("load", onLoad);
|
|
9464
|
+
navigate(frame3, frameUrl);
|
|
8572
9465
|
}
|
|
8573
9466
|
track({
|
|
8574
9467
|
view: frameWindow,
|
|
@@ -8579,7 +9472,11 @@ function open(veiled, first) {
|
|
|
8579
9472
|
notice = createNotice(() => exit2?.());
|
|
8580
9473
|
pageBox = document.createElement("div");
|
|
8581
9474
|
pageBox.className = "page";
|
|
8582
|
-
|
|
9475
|
+
loadCover = document.createElement("div");
|
|
9476
|
+
loadCover.className = "loading";
|
|
9477
|
+
loadCover.setAttribute("aria-hidden", "true");
|
|
9478
|
+
pageBox.append(frame3, loadCover);
|
|
9479
|
+
showCover();
|
|
8583
9480
|
glass.append(pageBox);
|
|
8584
9481
|
browser = createBrowser(glass, frame3, resize, onReloading, painted);
|
|
8585
9482
|
touchDot = createTouchDot({
|
|
@@ -8604,6 +9501,10 @@ function open(veiled, first) {
|
|
|
8604
9501
|
window.addEventListener("resize", resize);
|
|
8605
9502
|
window.addEventListener("pagehide", keep2);
|
|
8606
9503
|
body.append(host);
|
|
9504
|
+
if (!waiting2 && loader) {
|
|
9505
|
+
frame3.addEventListener("load", onLoad);
|
|
9506
|
+
navigate(frame3, frameUrl);
|
|
9507
|
+
}
|
|
8607
9508
|
stopKeeping = keepMounted(host, { restored: remounted });
|
|
8608
9509
|
const now = scene();
|
|
8609
9510
|
if (veiled !== null && now)
|
|
@@ -8666,6 +9567,8 @@ function teardown() {
|
|
|
8666
9567
|
mockDrawing = null;
|
|
8667
9568
|
mockKey = "";
|
|
8668
9569
|
frame3 = null;
|
|
9570
|
+
hideCover();
|
|
9571
|
+
loadCover = null;
|
|
8669
9572
|
notice = null;
|
|
8670
9573
|
readout = null;
|
|
8671
9574
|
caption = null;
|
|
@@ -8708,9 +9611,10 @@ function close(follow5) {
|
|
|
8708
9611
|
else
|
|
8709
9612
|
window.scrollTo({ left: scroll.x, top: scroll.y, behavior: "instant" });
|
|
8710
9613
|
}
|
|
8711
|
-
function
|
|
9614
|
+
function apply3(value) {
|
|
8712
9615
|
const shape = shapeOf(value);
|
|
8713
9616
|
const from = heading;
|
|
9617
|
+
over2 = caseOver(from, shape, over2);
|
|
8714
9618
|
heading = shape;
|
|
8715
9619
|
const first = !settled;
|
|
8716
9620
|
settled = true;
|
|
@@ -8812,6 +9716,7 @@ function apply2(value) {
|
|
|
8812
9716
|
function reset() {
|
|
8813
9717
|
close(false);
|
|
8814
9718
|
heading = "closed";
|
|
9719
|
+
over2 = false;
|
|
8815
9720
|
settled = false;
|
|
8816
9721
|
}
|
|
8817
9722
|
// src/engine/foldhand.ts
|