@heyramzi/ui 2.9.0 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/helpers.js +52 -0
- package/dist/agents/index.js +3 -0
- package/dist/agents/page-state.js +65 -0
- package/dist/agents/types.js +1 -0
- package/dist/agents/vendor/color.js +149 -0
- package/dist/agents/vendor/draw.js +548 -0
- package/dist/agents/vendor/engine.js +632 -0
- package/dist/agents/vendor/mesh.js +727 -0
- package/dist/agents/vendor/plastic.js +3273 -0
- package/dist/agents/vendor/presets.js +171 -0
- package/dist/agents/vendor/shapes.js +24 -0
- package/dist/agents/vendor/ticker.js +56 -0
- package/dist/agents/vendor/types.js +0 -0
- package/dist/agents/vendor/wear.js +1525 -0
- package/dist/ai/ai-button/index.js +2 -0
- package/dist/ai/confirmation/confirmation-context.svelte.js +12 -0
- package/dist/ai/confirmation/index.js +9 -0
- package/dist/ai/generation-progress/index.js +2 -0
- package/dist/ai/index.js +11 -0
- package/dist/ai/loading-state/index.js +3 -0
- package/dist/ai/prompt-input/index.js +6 -0
- package/dist/ai/reasoning/index.js +4 -0
- package/dist/ai/reasoning/reasoning-context.svelte.js +12 -0
- package/dist/ai/response/index.js +3 -0
- package/dist/ai/suggestion/index.js +3 -0
- package/dist/ai/thinking-dots/index.js +3 -0
- package/dist/ai/typing-dots/index.js +2 -0
- package/dist/ai/voice-waveform/index.js +3 -0
- package/dist/animations/text-swap.js +30 -0
- package/dist/brand/index.js +65 -0
- package/dist/canvas/card/resize.js +10 -0
- package/dist/canvas/edges/edge-path.js +284 -0
- package/dist/canvas/editor/context-menu.js +42 -0
- package/dist/canvas/editor/dispatch.svelte.js +157 -0
- package/dist/canvas/editor/editor-context.js +8 -0
- package/dist/canvas/editor/editor-mode.js +0 -0
- package/dist/canvas/editor/frame.js +87 -0
- package/dist/canvas/editor/hand-context.js +8 -0
- package/dist/canvas/editor/history-core.js +221 -0
- package/dist/canvas/editor/keymap.js +193 -0
- package/dist/canvas/editor/layout-actions.js +170 -0
- package/dist/canvas/editor/lock.js +65 -0
- package/dist/canvas/editor/rebase.js +279 -0
- package/dist/canvas/editor/style.js +174 -0
- package/dist/canvas/editor/text-field-context.js +8 -0
- package/dist/canvas/editor/z-order.js +82 -0
- package/dist/canvas/headless/alignment.js +20 -0
- package/dist/canvas/headless/break-apart-find.js +324 -0
- package/dist/canvas/headless/break-apart-pieces.js +74 -0
- package/dist/canvas/headless/break-apart-plan.js +378 -0
- package/dist/canvas/headless/break-apart-style.js +93 -0
- package/dist/canvas/headless/break-apart.js +206 -0
- package/dist/canvas/headless/canvas-cleanup.js +70 -0
- package/dist/canvas/headless/edge-anchors.js +134 -0
- package/dist/canvas/headless/edge-memo.js +28 -0
- package/dist/canvas/headless/edge-serialization.js +31 -0
- package/dist/canvas/headless/figure-geometry.js +331 -0
- package/dist/canvas/headless/fit-viewport.js +82 -0
- package/dist/canvas/headless/grid.js +96 -0
- package/dist/canvas/headless/icon-node.js +45 -0
- package/dist/canvas/headless/index.js +1 -0
- package/dist/canvas/headless/linkify.js +25 -0
- package/dist/canvas/headless/pen-marks.js +115 -0
- package/dist/canvas/headless/sketch.js +250 -0
- package/dist/canvas/headless/snap-guides.js +100 -0
- package/dist/canvas/headless/svg-figure.js +137 -0
- package/dist/canvas/headless/table-layout.js +161 -0
- package/dist/canvas/index.js +25 -0
- package/dist/canvas/lod/lod-mode.svelte.js +22 -0
- package/dist/canvas/lod/render-all.svelte.js +45 -0
- package/dist/canvas/ops/arrange.js +83 -0
- package/dist/canvas/ops/ops.js +318 -0
- package/dist/canvas/pen/colors.js +41 -0
- package/dist/canvas/pen/eraser.js +35 -0
- package/dist/canvas/pen/geometry.js +143 -0
- package/dist/canvas/pen/index.js +9 -0
- package/dist/canvas/pen/ops.js +15 -0
- package/dist/canvas/pen/pen-session.js +171 -0
- package/dist/canvas/pen/plugin.js +129 -0
- package/dist/canvas/pen/shapes.js +80 -0
- package/dist/canvas/pen/stroke-path.js +37 -0
- package/dist/canvas/pen/types.js +30 -0
- package/dist/canvas/pen/ui.js +20 -0
- package/dist/canvas/plugin.js +51 -0
- package/dist/canvas/screen/glyphs.js +24 -0
- package/dist/canvas/screen/labels.js +24 -0
- package/dist/canvas/screen/parts.js +140 -0
- package/dist/canvas/screen/plugin.js +71 -0
- package/dist/canvas/screen/types.js +44 -0
- package/dist/canvas/screen/ui.js +13 -0
- package/dist/canvas/test-utils.js +18 -0
- package/dist/canvas/types.js +0 -0
- package/dist/canvas/ui/forward-wheel.js +27 -0
- package/dist/canvas/ui/icons.js +133 -0
- package/dist/canvas/ui/place-panel.js +57 -0
- package/dist/canvas/ui/shortcut-tip.js +18 -0
- package/dist/canvas/ui/tools.js +411 -0
- package/dist/charts/dashboard/chart.js +1 -0
- package/dist/charts/dashboard/data-table.js +7 -0
- package/dist/charts/dashboard/index.js +13 -0
- package/dist/charts/dashboard/windows.js +5 -0
- package/dist/charts/edge-fade.js +7 -0
- package/dist/charts/hover-band.js +13 -0
- package/dist/charts/index.js +19 -0
- package/dist/charts/motion.js +15 -0
- package/dist/charts/primitives/chart-utils.js +22 -0
- package/dist/charts/primitives/index.js +4 -0
- package/dist/components/copy/clipboard.js +38 -0
- package/dist/components/copy/copied.svelte.js +26 -0
- package/dist/components/copy/index.js +3 -0
- package/dist/components/data-table/data-table.js +55 -0
- package/dist/components/data-table/index.js +7 -0
- package/dist/components/docs/index.js +3 -0
- package/dist/components/docs/scroll-spy.svelte.js +71 -0
- package/dist/components/field-row/index.js +1 -0
- package/dist/components/hold-to-confirm/index.js +1 -0
- package/dist/components/icon/index.js +1 -0
- package/dist/components/language-flag/index.js +1 -0
- package/dist/components/list-page/filter-section.js +4 -0
- package/dist/components/list-page/index.js +25 -0
- package/dist/components/list-page/list-table.js +5 -0
- package/dist/components/list-page/queue-rail.js +3 -0
- package/dist/components/list-page/section-host.js +8 -0
- package/dist/components/list-page/step.js +5 -0
- package/dist/components/list-page/types.js +0 -0
- package/dist/components/locale-switch/index.js +1 -0
- package/dist/components/mark/index.js +1 -0
- package/dist/components/open-in/index.js +1 -0
- package/dist/components/picker/index.js +3 -0
- package/dist/components/picker/trigger.js +33 -0
- package/dist/components/picker/types.js +0 -0
- package/dist/components/section-card/index.js +1 -0
- package/dist/components/section-header/index.js +2 -0
- package/dist/components/segmented/collapse.js +32 -0
- package/dist/components/segmented/index.js +8 -0
- package/dist/components/segmented/segmented.js +50 -0
- package/dist/components/star-rating-input/index.js +2 -0
- package/dist/components/svg/index.js +1 -0
- package/dist/components/table-view/index.js +1 -0
- package/dist/components/table-view/types.js +0 -0
- package/dist/components/tags-input/index.js +2 -0
- package/dist/components/tags-input/tags.js +90 -0
- package/dist/components/theme/index.js +3 -0
- package/dist/components/toolbar/index.js +3 -0
- package/dist/components/toolbar/toolbar-trigger.js +4 -0
- package/dist/editor/anchors.js +17 -0
- package/dist/editor/block-id.js +62 -0
- package/dist/editor/block-ops.js +105 -0
- package/dist/editor/doc-blocks.js +181 -0
- package/dist/editor/extensions.js +200 -0
- package/dist/editor/index.js +4 -0
- package/dist/editor/markdown-test-helpers.js +6 -0
- package/dist/editor/markdown.js +486 -0
- package/dist/editor/serializer.js +268 -0
- package/dist/editor/slash-items.js +104 -0
- package/dist/editor/youtube-url.js +27 -0
- package/dist/effects/animated-beam/index.js +1 -0
- package/dist/effects/animated-beam/path-calculator.svelte.js +42 -0
- package/dist/effects/animated-beam/types.js +0 -0
- package/dist/effects/border-beam/css.js +420 -0
- package/dist/effects/border-beam/presets.js +1792 -0
- package/dist/effects/border-beam/register-properties.js +39 -0
- package/dist/effects/border-beam/types.js +0 -0
- package/dist/effects/image-comparison/compare.js +4 -0
- package/dist/effects/image-reveal/index.js +1 -0
- package/dist/effects/image-reveal/types.js +0 -0
- package/dist/effects/magnetic/magnetic.js +54 -0
- package/dist/effects/reveal/index.js +4 -0
- package/dist/effects/reveal/observe.js +43 -0
- package/dist/effects/reveal/types.js +0 -0
- package/dist/effects/shader-gradient/color.js +34 -0
- package/dist/effects/shader-gradient/index.js +1 -0
- package/dist/effects/shader-gradient/renderer.js +320 -0
- package/dist/effects/shader-gradient/shaders.js +280 -0
- package/dist/effects/shader-gradient/types.js +0 -0
- package/dist/icons/apple-symbol-exports.js +126 -0
- package/dist/icons/sf-symbols.js +465 -0
- package/dist/icons/trades.js +34 -0
- package/dist/inbox/index.js +4 -0
- package/dist/inbox/logic.js +156 -0
- package/dist/inbox/types.js +46 -0
- package/dist/index.js +18 -0
- package/dist/lib/arrive.js +13 -0
- package/dist/lib/icon-types.js +0 -0
- package/dist/lib/initials.js +17 -0
- package/dist/lib/layout.js +1 -0
- package/dist/lib/panel.js +3 -0
- package/dist/lib/result.js +26 -0
- package/dist/lib/sliding-pill.js +45 -0
- package/dist/lib/theme-transition.js +53 -0
- package/dist/lib/tone.js +32 -0
- package/dist/lib/utils.js +5 -0
- package/dist/onboarding/define-tours.js +28 -0
- package/dist/onboarding/index.js +4 -0
- package/dist/onboarding/onboarding.svelte.js +15 -0
- package/dist/onboarding/pick.js +16 -0
- package/dist/onboarding/stores.js +50 -0
- package/dist/onboarding/types.js +1 -0
- package/dist/onboarding/wait.js +25 -0
- package/dist/panel/index.js +1 -0
- package/dist/panel/side-panel-types.js +0 -0
- package/dist/record/demo-data.js +512 -0
- package/dist/record/fields.js +148 -0
- package/dist/record/format.js +97 -0
- package/dist/record/gutter.js +1 -0
- package/dist/record/index.js +15 -0
- package/dist/record/kinds.js +110 -0
- package/dist/record/logic.js +255 -0
- package/dist/record/types.js +52 -0
- package/dist/shadcn/accordion/index.js +5 -0
- package/dist/shadcn/alert/index.js +5 -0
- package/dist/shadcn/alert-dialog/index.js +12 -0
- package/dist/shadcn/attachment/index.js +10 -0
- package/dist/shadcn/avatar/index.js +7 -0
- package/dist/shadcn/badge/index.js +2 -0
- package/dist/shadcn/breadcrumb/index.js +8 -0
- package/dist/shadcn/bubble/index.js +5 -0
- package/dist/shadcn/button/index.js +2 -0
- package/dist/shadcn/calendar/index.js +19 -0
- package/dist/shadcn/card/index.js +8 -0
- package/dist/shadcn/checkbox/index.js +2 -0
- package/dist/shadcn/code-block/index.js +9 -0
- package/dist/shadcn/collapsible/index.js +4 -0
- package/dist/shadcn/command/index.js +13 -0
- package/dist/shadcn/context-menu/index.js +17 -0
- package/dist/shadcn/dialog/index.js +11 -0
- package/dist/shadcn/dropdown-menu/index.js +19 -0
- package/dist/shadcn/dropdown-menu/menu-item.js +23 -0
- package/dist/shadcn/empty/index.js +7 -0
- package/dist/shadcn/field/index.js +12 -0
- package/dist/shadcn/hooks/highlighter.js +92 -0
- package/dist/shadcn/hooks/is-mobile.svelte.js +7 -0
- package/dist/shadcn/hooks/use-highlighted-code.svelte.js +65 -0
- package/dist/shadcn/hover-card/index.js +5 -0
- package/dist/shadcn/input/index.js +3 -0
- package/dist/shadcn/input-otp/index.js +5 -0
- package/dist/shadcn/kbd/index.js +3 -0
- package/dist/shadcn/label/index.js +2 -0
- package/dist/shadcn/marker/index.js +4 -0
- package/dist/shadcn/message/index.js +7 -0
- package/dist/shadcn/message-scroller/index.js +8 -0
- package/dist/shadcn/popover/index.js +9 -0
- package/dist/shadcn/progress/index.js +2 -0
- package/dist/shadcn/progress/tone.js +11 -0
- package/dist/shadcn/radio-group/index.js +3 -0
- package/dist/shadcn/scroll-area/index.js +3 -0
- package/dist/shadcn/select/index.js +12 -0
- package/dist/shadcn/separator/index.js +2 -0
- package/dist/shadcn/sheet/index.js +11 -0
- package/dist/shadcn/sidebar/constants.js +6 -0
- package/dist/shadcn/sidebar/context.svelte.js +38 -0
- package/dist/shadcn/sidebar/index.js +25 -0
- package/dist/shadcn/skeleton/index.js +2 -0
- package/dist/shadcn/slider/index.js +2 -0
- package/dist/shadcn/sonner/index.js +1 -0
- package/dist/shadcn/spinner/index.js +1 -0
- package/dist/shadcn/switch/index.js +2 -0
- package/dist/shadcn/table/index.js +9 -0
- package/dist/shadcn/tabs/index.js +5 -0
- package/dist/shadcn/textarea/index.js +2 -0
- package/dist/shadcn/toggle/index.js +3 -0
- package/dist/shadcn/toggle-group/index.js +3 -0
- package/dist/shadcn/tooltip/context.js +8 -0
- package/dist/shadcn/tooltip/index.js +6 -0
- package/dist/shadcn/trace/index.js +9 -0
- package/dist/slides/bridges.js +66 -0
- package/dist/slides/deck-controller.svelte.js +221 -0
- package/dist/slides/export/capture.js +81 -0
- package/dist/slides/export/ffmpeg.js +85 -0
- package/dist/slides/export/index.js +4 -0
- package/dist/slides/export/launch.js +8 -0
- package/dist/slides/export/pdf.js +78 -0
- package/dist/slides/export/types.js +0 -0
- package/dist/slides/index.js +7 -0
- package/dist/slides/labels.js +26 -0
- package/dist/slides/layout.js +47 -0
- package/dist/slides/model.js +9 -0
- package/dist/slides/navigation.js +89 -0
- package/dist/slides/types.js +6 -0
- package/dist/status/define-statuses.js +16 -0
- package/dist/status/index.js +4 -0
- package/dist/status/status-types.js +0 -0
- package/dist/test-setup.js +26 -0
- package/dist/thread/index.js +3 -0
- package/dist/thread/logic.js +94 -0
- package/dist/thread/types.js +23 -0
- package/dist/work/board-order.js +109 -0
- package/dist/work/dates.js +19 -0
- package/dist/work/detail/detail-types.js +20 -0
- package/dist/work/docs/edited.js +39 -0
- package/dist/work/docs/index.js +7 -0
- package/dist/work/docs/labels.js +38 -0
- package/dist/work/docs/menu.js +121 -0
- package/dist/work/docs/outline.js +39 -0
- package/dist/work/gantt/logic.js +260 -0
- package/dist/work/inbox/inbox-logic.js +94 -0
- package/dist/work/inbox/inbox-statuses.js +86 -0
- package/dist/work/inbox/inbox-types.js +0 -0
- package/dist/work/inbox/index.js +1 -0
- package/dist/work/index.js +21 -0
- package/dist/work/kanban-drag.js +25 -0
- package/dist/work/kanban-types.js +0 -0
- package/dist/work/presets/sales.js +35 -0
- package/dist/work/reorder.js +10 -0
- package/dist/work/task-types.js +0 -0
- package/dist/work/time/duration.js +60 -0
- package/dist/work/time/time-types.js +25 -0
- package/dist/work/use-kanban-dnd.svelte.js +128 -0
- package/package.json +45 -3
- package/src/components/toolbar/toolbar-trigger.ts +8 -2
- package/src/record/demo-data.ts +4 -4
- package/src/record/record-demo.svelte +2 -2
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
import { shade } from "./color.js";
|
|
2
|
+
import { drawPlasticCap, mulAffine, surfaceAt } from "./plastic.js";
|
|
3
|
+
import { drawGlasses, drawWearBehind, drawWearFront } from "./wear.js";
|
|
4
|
+
export const OVERSCAN = 1.5;
|
|
5
|
+
export const RISE = 0.1;
|
|
6
|
+
const SLICES = 17;
|
|
7
|
+
const HALF_DEPTH = 15;
|
|
8
|
+
const CAP = 0.9;
|
|
9
|
+
const profile = (z, cap)=>cap + (1 - cap) * Math.sqrt(Math.max(0, 1 - z * z));
|
|
10
|
+
const EYE_GAP = 25;
|
|
11
|
+
const EYE_RX = 5.6;
|
|
12
|
+
const EYE_Y = {
|
|
13
|
+
eyes: 1,
|
|
14
|
+
mouth: -3.5
|
|
15
|
+
};
|
|
16
|
+
const paletteCache = new Map();
|
|
17
|
+
function palette(color, shadow, highlight) {
|
|
18
|
+
const key = `${color}|${shadow}|${highlight}`;
|
|
19
|
+
let p = paletteCache.get(key);
|
|
20
|
+
if (!p) {
|
|
21
|
+
const far = shade(color, -0.3 * shadow, 0.05 * shadow);
|
|
22
|
+
const near = shade(color, -0.12 * shadow, 0.03 * shadow);
|
|
23
|
+
const crispMix = [], smoothMix = [];
|
|
24
|
+
for(let j = 0; j < SLICES; j++){
|
|
25
|
+
const t = j / (SLICES - 1);
|
|
26
|
+
crispMix.push(t > 0.6 ? "" : mixCss(far, near, t / 0.6));
|
|
27
|
+
smoothMix.push(t >= 0.5 ? color : mixCss(far, color, t / 0.5));
|
|
28
|
+
}
|
|
29
|
+
p = {
|
|
30
|
+
base: color,
|
|
31
|
+
far,
|
|
32
|
+
near,
|
|
33
|
+
light: shade(color, 0.04 * highlight),
|
|
34
|
+
dark: shade(color, -0.3 * shadow, 0.05 * shadow),
|
|
35
|
+
capTop: shade(color, 0.035 * highlight),
|
|
36
|
+
capBottom: shade(color, -0.035 * shadow),
|
|
37
|
+
crispMix,
|
|
38
|
+
smoothMix,
|
|
39
|
+
grad: null
|
|
40
|
+
};
|
|
41
|
+
if (paletteCache.size > 200) paletteCache.clear();
|
|
42
|
+
paletteCache.set(key, p);
|
|
43
|
+
}
|
|
44
|
+
return p;
|
|
45
|
+
}
|
|
46
|
+
const hslNums = (c)=>(c.startsWith("hsl(") ? c : shade(c, 0)).match(/[\d.]+/g).map(Number);
|
|
47
|
+
function mixCss(a, b, t) {
|
|
48
|
+
const pa = hslNums(a);
|
|
49
|
+
const pb = hslNums(b);
|
|
50
|
+
const m = pa.map((v, i)=>v + (pb[i] - v) * t);
|
|
51
|
+
return `hsl(${m[0].toFixed(1)} ${m[1].toFixed(1)}% ${m[2].toFixed(1)}%)`;
|
|
52
|
+
}
|
|
53
|
+
const WHIRL_SEGMENTS = 34;
|
|
54
|
+
const WHIRL_SPAN = Math.PI * 1.55;
|
|
55
|
+
const WHIRL_RX = 57;
|
|
56
|
+
const WHIRL_RATIO = 0.4;
|
|
57
|
+
const WHIRL_TILT = -0.28;
|
|
58
|
+
const whirlInkCache = new Map();
|
|
59
|
+
function whirlInk(color) {
|
|
60
|
+
let w = whirlInkCache.get(color);
|
|
61
|
+
if (!w) {
|
|
62
|
+
w = {
|
|
63
|
+
base: shade(color, 0.1, 0.02),
|
|
64
|
+
light: shade(color, 0.3, 0.04),
|
|
65
|
+
dark: shade(color, -0.22, 0.08),
|
|
66
|
+
halo: shade(color, 0.2)
|
|
67
|
+
};
|
|
68
|
+
if (whirlInkCache.size > 200) whirlInkCache.clear();
|
|
69
|
+
whirlInkCache.set(color, w);
|
|
70
|
+
}
|
|
71
|
+
return w;
|
|
72
|
+
}
|
|
73
|
+
const withAlpha = (hsl, a)=>hsl.replace(")", ` / ${Math.max(0, Math.min(1, a)).toFixed(3)})`);
|
|
74
|
+
function drawWhirl(ctx, pose, color, lx, ly, near, knobs) {
|
|
75
|
+
const strength = knobs?.strength ?? 0;
|
|
76
|
+
const k = Math.min(1, pose.whirl * strength);
|
|
77
|
+
if (k <= 0.01) return;
|
|
78
|
+
const sizeK = knobs?.size ?? 1, widthK = knobs?.width ?? 1, lengthK = knobs?.length ?? 1, tiltK = knobs?.tilt ?? 1;
|
|
79
|
+
const span = WHIRL_SPAN * lengthK;
|
|
80
|
+
const ink = whirlInk(color);
|
|
81
|
+
const head = -pose.whirlAngle;
|
|
82
|
+
const rx = WHIRL_RX * sizeK;
|
|
83
|
+
const ry = rx * WHIRL_RATIO * tiltK * (near ? 1.14 : 0.86);
|
|
84
|
+
const lightA = Math.atan2(ly, lx) - WHIRL_TILT;
|
|
85
|
+
ctx.save();
|
|
86
|
+
ctx.rotate(WHIRL_TILT);
|
|
87
|
+
ctx.translate(0, 5);
|
|
88
|
+
ctx.lineCap = "butt";
|
|
89
|
+
const seg = (a0, a1, width, style, dy)=>{
|
|
90
|
+
ctx.strokeStyle = style;
|
|
91
|
+
ctx.lineWidth = width;
|
|
92
|
+
ctx.beginPath();
|
|
93
|
+
ctx.ellipse(0, dy, rx, ry, 0, a0, a1, false);
|
|
94
|
+
ctx.stroke();
|
|
95
|
+
};
|
|
96
|
+
if (near) {
|
|
97
|
+
for(let i = 0; i < WHIRL_SEGMENTS; i++){
|
|
98
|
+
const f = i / WHIRL_SEGMENTS;
|
|
99
|
+
const a1 = head + f * span, a0 = a1 + span / WHIRL_SEGMENTS + 0.012;
|
|
100
|
+
if (Math.sin((a0 + a1) / 2) <= 0) continue;
|
|
101
|
+
const fade = Math.pow(1 - f, 1.3);
|
|
102
|
+
seg(a1, a0, (2 + 8 * fade) * 1.5 * widthK, `rgba(0,0,0,${(0.2 * k * fade).toFixed(3)})`, 3.5);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
for(let i = 0; i < WHIRL_SEGMENTS; i++){
|
|
106
|
+
const f = i / WHIRL_SEGMENTS;
|
|
107
|
+
const a1 = head + f * span, a0 = a1 + span / WHIRL_SEGMENTS + 0.012;
|
|
108
|
+
const mid = (a0 + a1) / 2;
|
|
109
|
+
if (Math.sin(mid) > 0 !== near) continue;
|
|
110
|
+
const depth = 0.6 + 0.4 * Math.sin(mid);
|
|
111
|
+
const fade = Math.pow(1 - f, 1.3);
|
|
112
|
+
const puff = 1 + 0.18 * Math.sin(f * 9 + 1.2);
|
|
113
|
+
const width = (2 + 8 * fade) * depth * widthK * puff;
|
|
114
|
+
const a = k * (0.3 + 0.7 * fade) * depth;
|
|
115
|
+
const facing = 0.5 + 0.5 * Math.cos(mid - lightA);
|
|
116
|
+
seg(a1, a0, width * 2.6, withAlpha(ink.halo, a * 0.2), 0);
|
|
117
|
+
seg(a1, a0, width * 0.8, withAlpha(ink.dark, a * 0.45), width * 0.32);
|
|
118
|
+
seg(a1, a0, width, withAlpha(ink.base, a * 0.72), 0);
|
|
119
|
+
seg(a1, a0, width * 0.62, withAlpha(ink.light, a * 0.78 * (0.4 + 0.6 * facing)), -width * 0.16);
|
|
120
|
+
seg(a1, a0, width * 0.24, `rgba(255,255,255,${(a * 0.9 * (0.15 + 0.85 * facing * facing)).toFixed(3)})`, -width * 0.3);
|
|
121
|
+
}
|
|
122
|
+
ctx.restore();
|
|
123
|
+
}
|
|
124
|
+
const backOf = (deg)=>{
|
|
125
|
+
if (deg === undefined || !Number.isFinite(deg)) return {};
|
|
126
|
+
const a = deg * Math.PI / 180;
|
|
127
|
+
return {
|
|
128
|
+
bx: Math.sin(a),
|
|
129
|
+
by: -Math.cos(a)
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
export const LIGHT_DEFAULTS = {
|
|
133
|
+
fabric: {
|
|
134
|
+
shadow: 1.15,
|
|
135
|
+
highlight: 1.45,
|
|
136
|
+
light: 295,
|
|
137
|
+
rim: 0.6,
|
|
138
|
+
spread: 1.6
|
|
139
|
+
},
|
|
140
|
+
other: {
|
|
141
|
+
shadow: 0.35,
|
|
142
|
+
highlight: 1.3,
|
|
143
|
+
light: 300,
|
|
144
|
+
rim: 0.5,
|
|
145
|
+
spread: 1.55
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
export function draw(ctx, box, pose, cfg) {
|
|
149
|
+
const full = box * OVERSCAN;
|
|
150
|
+
ctx.clearRect(0, 0, full, full);
|
|
151
|
+
const S = box / 100;
|
|
152
|
+
let dpr, base;
|
|
153
|
+
if (cfg.dpr !== undefined) {
|
|
154
|
+
dpr = cfg.dpr;
|
|
155
|
+
base = [
|
|
156
|
+
dpr,
|
|
157
|
+
0,
|
|
158
|
+
0,
|
|
159
|
+
dpr,
|
|
160
|
+
0,
|
|
161
|
+
0
|
|
162
|
+
];
|
|
163
|
+
} else if (ctx.getTransform) {
|
|
164
|
+
const t = ctx.getTransform();
|
|
165
|
+
base = [
|
|
166
|
+
t.a,
|
|
167
|
+
t.b,
|
|
168
|
+
t.c,
|
|
169
|
+
t.d,
|
|
170
|
+
t.e,
|
|
171
|
+
t.f
|
|
172
|
+
];
|
|
173
|
+
dpr = t.a || 1;
|
|
174
|
+
} else {
|
|
175
|
+
dpr = 1;
|
|
176
|
+
base = [
|
|
177
|
+
1,
|
|
178
|
+
0,
|
|
179
|
+
0,
|
|
180
|
+
1,
|
|
181
|
+
0,
|
|
182
|
+
0
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
const lit = LIGHT_DEFAULTS[cfg.shading === "fabric" ? "fabric" : "other"];
|
|
186
|
+
const shadow = cfg.shadow ?? lit.shadow, highlight = cfg.highlight ?? lit.highlight;
|
|
187
|
+
const halfDepth = HALF_DEPTH * (cfg.depth ?? 0.65);
|
|
188
|
+
const rimK = cfg.rim ?? lit.rim;
|
|
189
|
+
const cap = 1 - (1 - CAP) * rimK;
|
|
190
|
+
const spread = cfg.spread ?? lit.spread;
|
|
191
|
+
const la = (cfg.light ?? lit.light) * Math.PI / 180;
|
|
192
|
+
const lx = Math.sin(la), ly = -Math.cos(la);
|
|
193
|
+
const pal = palette(cfg.color, shadow, highlight);
|
|
194
|
+
const cy0 = Math.cos(pose.yaw), sy = Math.sin(pose.yaw);
|
|
195
|
+
const cp0 = Math.cos(pose.pitch), sp = Math.sin(pose.pitch);
|
|
196
|
+
const facing = cy0 * cp0;
|
|
197
|
+
const floor = (v)=>Math.abs(v) < 0.22 ? v < 0 ? -0.22 : 0.22 : v;
|
|
198
|
+
const cy = floor(cy0), cp = floor(cp0);
|
|
199
|
+
const cr = Math.cos(pose.roll), sr = Math.sin(pose.roll), kx = pose.sx * S, ky = pose.sy * S;
|
|
200
|
+
const lift = 50 * (1 - pose.sy) * S;
|
|
201
|
+
const body = mulAffine(base, [
|
|
202
|
+
cr * kx,
|
|
203
|
+
sr * kx,
|
|
204
|
+
-sr * ky,
|
|
205
|
+
cr * ky,
|
|
206
|
+
full / 2 + pose.x * S - sr * lift,
|
|
207
|
+
full / 2 + RISE * box + pose.y * S + cr * lift
|
|
208
|
+
]);
|
|
209
|
+
ctx.save();
|
|
210
|
+
ctx.setTransform(body[0], body[1], body[2], body[3], body[4], body[5]);
|
|
211
|
+
ctx.lineCap = "round";
|
|
212
|
+
ctx.lineJoin = "round";
|
|
213
|
+
const mode = cfg.shading;
|
|
214
|
+
const drawSolid = (path, key, halfDepth, plush = true)=>{
|
|
215
|
+
let lit = pal.near;
|
|
216
|
+
let capFill = pal.base;
|
|
217
|
+
if (mode === "crisp") {
|
|
218
|
+
if (!pal.grad || pal.grad.lx !== lx || pal.grad.ly !== ly) {
|
|
219
|
+
const g = ctx.createLinearGradient(lx * 56, ly * 56, -lx * 56, -ly * 56);
|
|
220
|
+
g.addColorStop(0, pal.light);
|
|
221
|
+
g.addColorStop(0.45, pal.near);
|
|
222
|
+
g.addColorStop(1, pal.dark);
|
|
223
|
+
const c = ctx.createLinearGradient(lx * 46, ly * 46, -lx * 46, -ly * 46);
|
|
224
|
+
c.addColorStop(0, pal.capTop);
|
|
225
|
+
c.addColorStop(1, pal.capBottom);
|
|
226
|
+
pal.grad = {
|
|
227
|
+
lx,
|
|
228
|
+
ly,
|
|
229
|
+
lit: g,
|
|
230
|
+
cap: c
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
lit = pal.grad.lit;
|
|
234
|
+
capFill = pal.grad.cap;
|
|
235
|
+
}
|
|
236
|
+
let plasticDone = false;
|
|
237
|
+
if (mode === "plastic" || mode === "fabric") {
|
|
238
|
+
plasticDone = drawPlasticCap(ctx, {
|
|
239
|
+
...cfg,
|
|
240
|
+
path,
|
|
241
|
+
typeKey: key,
|
|
242
|
+
shading: plush ? mode : "plastic"
|
|
243
|
+
}, {
|
|
244
|
+
cy,
|
|
245
|
+
sy,
|
|
246
|
+
cp,
|
|
247
|
+
sp,
|
|
248
|
+
facing,
|
|
249
|
+
roll: pose.roll,
|
|
250
|
+
halfDepth,
|
|
251
|
+
cap,
|
|
252
|
+
lx,
|
|
253
|
+
ly,
|
|
254
|
+
...backOf(cfg.backLight),
|
|
255
|
+
dev: box * dpr,
|
|
256
|
+
ctm: body,
|
|
257
|
+
still: cfg.still,
|
|
258
|
+
round: cfg.roundness ?? 1
|
|
259
|
+
}, pal, null, {
|
|
260
|
+
shadow,
|
|
261
|
+
highlight,
|
|
262
|
+
spread,
|
|
263
|
+
rim: rimK,
|
|
264
|
+
vivid: cfg.vivid ?? 0,
|
|
265
|
+
front: Math.min(85, Math.max(0, cfg.lightFront ?? 32)) * Math.PI / 180,
|
|
266
|
+
shine: cfg.shine ?? 0,
|
|
267
|
+
sheen: cfg.sheen ?? 0,
|
|
268
|
+
backSoft: cfg.backSoftness ?? 1
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
const mode2 = (mode === "plastic" || mode === "fabric") && !plasticDone ? "smooth" : mode;
|
|
272
|
+
const soft = mode2 === "smooth";
|
|
273
|
+
const union = soft && typeof Path2D === "function" ? new Path2D() : null;
|
|
274
|
+
const order = facing >= 0 ? 1 : -1;
|
|
275
|
+
const [ca, cb, cc, cd, ce, cf] = body;
|
|
276
|
+
let fill = null;
|
|
277
|
+
let pa = 1, pb = 0, pc = 0, pd = 1, pe = 0, pf = 0;
|
|
278
|
+
for(let j = 0; j < SLICES && !plasticDone; j++){
|
|
279
|
+
const k = order > 0 ? j : SLICES - 1 - j;
|
|
280
|
+
const z = -1 + 2 * k / (SLICES - 1);
|
|
281
|
+
const s = profile(z, cap);
|
|
282
|
+
const near = j / (SLICES - 1);
|
|
283
|
+
const m0 = cy * s, m1 = sy * sp * s, m3 = cp * s;
|
|
284
|
+
const e = z * sy * halfDepth - 50 * m0, fo = -z * cy * sp * halfDepth - 50 * m1 - 50 * m3;
|
|
285
|
+
const det = pa * pd - pb * pc;
|
|
286
|
+
const ia = pd / det, ib = -pb / det, ic = -pc / det, id = pa / det, ie = (pc * pf - pd * pe) / det, jf = (pb * pe - pa * pf) / det;
|
|
287
|
+
ctx.transform(ia * m0 + ic * m1, ib * m0 + id * m1, ic * m3, id * m3, ia * e + ic * fo + ie, ib * e + id * fo + jf);
|
|
288
|
+
pa = m0;
|
|
289
|
+
pb = m1;
|
|
290
|
+
pc = 0;
|
|
291
|
+
pd = m3;
|
|
292
|
+
pe = e;
|
|
293
|
+
pf = fo;
|
|
294
|
+
let style;
|
|
295
|
+
if (soft) style = pal.smoothMix[j];
|
|
296
|
+
else if (j === SLICES - 1) style = capFill;
|
|
297
|
+
else if (near > 0.6) style = lit;
|
|
298
|
+
else style = pal.crispMix[j];
|
|
299
|
+
if (style !== fill) ctx.fillStyle = fill = style;
|
|
300
|
+
ctx.fill(path);
|
|
301
|
+
if (union) union.addPath(path, {
|
|
302
|
+
a: m0,
|
|
303
|
+
b: m1,
|
|
304
|
+
c: 0,
|
|
305
|
+
d: m3,
|
|
306
|
+
e,
|
|
307
|
+
f: fo
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
if (!plasticDone) ctx.setTransform(ca, cb, cc, cd, ce, cf);
|
|
311
|
+
if (union && mode2 === "smooth") {
|
|
312
|
+
ctx.save();
|
|
313
|
+
ctx.clip(union);
|
|
314
|
+
const sa = Math.min(1, 0.34 * shadow);
|
|
315
|
+
const sg = ctx.createRadialGradient(-lx * 45, -ly * 45, 4 * spread, -lx * 45, -ly * 45, 84 * spread);
|
|
316
|
+
sg.addColorStop(0, `rgba(0,0,0,${sa})`);
|
|
317
|
+
sg.addColorStop(0.5, `rgba(0,0,0,${sa * 0.35})`);
|
|
318
|
+
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
319
|
+
ctx.globalCompositeOperation = "multiply";
|
|
320
|
+
ctx.fillStyle = sg;
|
|
321
|
+
ctx.fillRect(-120, -120, 240, 240);
|
|
322
|
+
ctx.globalCompositeOperation = "source-over";
|
|
323
|
+
const ha = Math.min(1, 0.22 * highlight);
|
|
324
|
+
const hg = ctx.createRadialGradient(lx * 37, ly * 37, 0, lx * 37, ly * 37, 62 * spread);
|
|
325
|
+
hg.addColorStop(0, `rgba(255,255,255,${ha})`);
|
|
326
|
+
hg.addColorStop(0.6, `rgba(255,255,255,${ha * 0.23})`);
|
|
327
|
+
hg.addColorStop(1, "rgba(255,255,255,0)");
|
|
328
|
+
ctx.fillStyle = hg;
|
|
329
|
+
ctx.fillRect(-120, -120, 240, 240);
|
|
330
|
+
ctx.restore();
|
|
331
|
+
}
|
|
332
|
+
return plasticDone;
|
|
333
|
+
};
|
|
334
|
+
drawWhirl(ctx, pose, cfg.color, lx, ly, false, cfg.whirl);
|
|
335
|
+
const wear = cfg.wear;
|
|
336
|
+
const worn = !!wear && (wear.hat !== "none" || wear.glasses !== "none" || wear.headphones || wear.bowTie);
|
|
337
|
+
const wr = {
|
|
338
|
+
cy,
|
|
339
|
+
sy,
|
|
340
|
+
cp,
|
|
341
|
+
sp,
|
|
342
|
+
facing,
|
|
343
|
+
halfDepth,
|
|
344
|
+
lx,
|
|
345
|
+
ly
|
|
346
|
+
};
|
|
347
|
+
if (worn) drawWearBehind(ctx, cfg.path, wr, wear);
|
|
348
|
+
const key = cfg.typeKey ?? "custom";
|
|
349
|
+
const parts = cfg.parts ? Array.isArray(cfg.parts) ? cfg.parts : [
|
|
350
|
+
cfg.parts
|
|
351
|
+
] : [];
|
|
352
|
+
for(let i = 0; i < parts.length; i++)drawSolid(parts[i], Array.isArray(cfg.parts) ? `${key}:parts${i}/${parts.length}` : `${key}:parts`, halfDepth * (cfg.partsDepth ?? 0.4), false);
|
|
353
|
+
const plasticDone = drawSolid(cfg.path, key, halfDepth);
|
|
354
|
+
const zf = facing >= 0 ? 1 : -1;
|
|
355
|
+
const round = cfg.roundness ?? 1;
|
|
356
|
+
const cushion = plasticDone;
|
|
357
|
+
const sf = cushion ? 1 : profile(zf, cap);
|
|
358
|
+
const surface = (x, y)=>cushion ? surfaceAt(key, halfDepth, x, y, round) ?? 0.8 * halfDepth : halfDepth * sf;
|
|
359
|
+
const zFace = cushion ? 0.55 * surface(cfg.faceX, cfg.faceY) : halfDepth;
|
|
360
|
+
const fm0 = cy * sf, fm1 = sy * sp * sf, fm3 = cp * sf;
|
|
361
|
+
const fe = zf * sy * zFace - 50 * fm0;
|
|
362
|
+
const ffo = -zf * cy * sp * zFace - 50 * fm1 - 50 * fm3;
|
|
363
|
+
let frontClip = null;
|
|
364
|
+
if (worn && typeof Path2D === "function") {
|
|
365
|
+
frontClip = new Path2D();
|
|
366
|
+
frontClip.addPath(cfg.path, {
|
|
367
|
+
a: fm0,
|
|
368
|
+
b: fm1,
|
|
369
|
+
c: 0,
|
|
370
|
+
d: fm3,
|
|
371
|
+
e: fe,
|
|
372
|
+
f: ffo
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
if (facing > -0.2) {
|
|
376
|
+
ctx.save();
|
|
377
|
+
{
|
|
378
|
+
const [ca, cb, cc, cd, ce, cf] = body;
|
|
379
|
+
ctx.setTransform(ca * fm0 + cc * fm1, cb * fm0 + cd * fm1, cc * fm3, cd * fm3, ca * fe + cc * ffo + ce, cb * fe + cd * ffo + cf);
|
|
380
|
+
ctx.clip(cfg.path);
|
|
381
|
+
ctx.setTransform(ca, cb, cc, cd, ce, cf);
|
|
382
|
+
}
|
|
383
|
+
ctx.translate(cfg.faceX - 50, cfg.faceY - 50);
|
|
384
|
+
ctx.scale(cfg.faceScale, cfg.faceScale);
|
|
385
|
+
if (mode === "plastic" && plasticDone) ctx.globalAlpha = 0.93;
|
|
386
|
+
const eyes = drawFace(ctx, pose, cfg);
|
|
387
|
+
ctx.globalAlpha = 1;
|
|
388
|
+
const glasses = wear && wear.glasses !== "none" ? wear.glasses : null;
|
|
389
|
+
const turn = {
|
|
390
|
+
yaw: pose.yaw,
|
|
391
|
+
pitch: pose.pitch
|
|
392
|
+
};
|
|
393
|
+
if (glasses) drawGlasses(ctx, glasses, eyes, {
|
|
394
|
+
lx,
|
|
395
|
+
ly
|
|
396
|
+
}, "shadow", turn);
|
|
397
|
+
ctx.restore();
|
|
398
|
+
if (glasses) {
|
|
399
|
+
ctx.save();
|
|
400
|
+
ctx.translate(cfg.faceX - 50, cfg.faceY - 50);
|
|
401
|
+
ctx.scale(cfg.faceScale, cfg.faceScale);
|
|
402
|
+
drawGlasses(ctx, glasses, eyes, {
|
|
403
|
+
lx,
|
|
404
|
+
ly
|
|
405
|
+
}, "frame", turn);
|
|
406
|
+
ctx.restore();
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (worn) drawWearFront(ctx, cfg.path, wr, wear, frontClip, surface, {
|
|
410
|
+
y: cfg.faceY,
|
|
411
|
+
scale: cfg.faceScale
|
|
412
|
+
});
|
|
413
|
+
drawWhirl(ctx, pose, cfg.color, lx, ly, true, cfg.whirl);
|
|
414
|
+
ctx.restore();
|
|
415
|
+
}
|
|
416
|
+
const FACE_R = 30;
|
|
417
|
+
function onSphere(x, y, yaw, pitch) {
|
|
418
|
+
const lon = Math.asin(Math.max(-1, Math.min(1, x / FACE_R))) + yaw;
|
|
419
|
+
const lat = Math.asin(Math.max(-1, Math.min(1, -y / FACE_R))) + pitch;
|
|
420
|
+
const cl = Math.cos(lat);
|
|
421
|
+
return {
|
|
422
|
+
x: FACE_R * Math.sin(lon) * cl,
|
|
423
|
+
y: -FACE_R * Math.sin(lat),
|
|
424
|
+
sx: Math.cos(lon),
|
|
425
|
+
sy: cl,
|
|
426
|
+
z: Math.cos(lon) * cl
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
const EYE_STEPS = 8;
|
|
430
|
+
const eyePaths = new Map();
|
|
431
|
+
function eyePath(x0, y0, cy) {
|
|
432
|
+
const qx = Math.round(x0 * 50), qy = Math.round(y0 * 50), qc = Math.round(cy * 50);
|
|
433
|
+
const key = qx + 2000 * qy + 4e6 * qc;
|
|
434
|
+
let p = eyePaths.get(key);
|
|
435
|
+
if (!p) {
|
|
436
|
+
const ax = qx / 50, ay = qy / 50, ac = qc / 50;
|
|
437
|
+
let d = `M${-ax} ${ay}`;
|
|
438
|
+
for(let i = 1; i <= EYE_STEPS; i++){
|
|
439
|
+
const t = i / EYE_STEPS, mt = 1 - t;
|
|
440
|
+
d += ` L${(mt * mt * -ax + t * t * ax).toFixed(3)} ${((mt * mt + t * t) * ay + 2 * mt * t * ac).toFixed(3)}`;
|
|
441
|
+
}
|
|
442
|
+
p = new Path2D(d);
|
|
443
|
+
if (eyePaths.size > 256) eyePaths.clear();
|
|
444
|
+
eyePaths.set(key, p);
|
|
445
|
+
}
|
|
446
|
+
return p;
|
|
447
|
+
}
|
|
448
|
+
const MOUTH_SIN = Math.sin(0.684), MOUTH_COS = Math.cos(0.684);
|
|
449
|
+
const mouthPaths = new Map();
|
|
450
|
+
function mouthPath(m) {
|
|
451
|
+
const q = (v)=>Math.round(v * 50) / 50;
|
|
452
|
+
const hw = q(m.hw), t0 = q(m.t0), a = q(m.a), yt = q(m.yt), ab = q(m.ab), yb = q(m.yb);
|
|
453
|
+
const key = `${hw},${t0},${a},${yt},${ab},${yb}`;
|
|
454
|
+
let p = mouthPaths.get(key);
|
|
455
|
+
if (p) return p;
|
|
456
|
+
const f = (v)=>v.toFixed(3);
|
|
457
|
+
const nx = t0 * MOUTH_SIN, ny = t0 * MOUTH_COS;
|
|
458
|
+
const ltx = -hw + nx, lty = -ny, rtx = hw - nx, rty = -ny;
|
|
459
|
+
const lbx = -hw - nx, lby = ny, rbx = hw + nx, rby = ny;
|
|
460
|
+
const cx = 4 / 3 * t0 * MOUTH_COS, cy = 4 / 3 * t0 * MOUTH_SIN;
|
|
461
|
+
const d = `M${f(ltx)} ${f(lty)}` + `C${f(-hw + a * hw)} ${f(yt - t0)} ${f(hw - a * hw)} ${f(yt - t0)} ${f(rtx)} ${f(rty)}` + `C${f(rtx + cx)} ${f(rty - cy)} ${f(rbx + cx)} ${f(rby - cy)} ${f(rbx)} ${f(rby)}` + `C${f(hw - ab * hw)} ${f(yb + t0)} ${f(-hw + ab * hw)} ${f(yb + t0)} ${f(lbx)} ${f(lby)}` + `C${f(lbx - cx)} ${f(lby - cy)} ${f(ltx - cx)} ${f(lty - cy)} ${f(ltx)} ${f(lty)}Z`;
|
|
462
|
+
p = new Path2D(d);
|
|
463
|
+
if (mouthPaths.size > 256) mouthPaths.clear();
|
|
464
|
+
mouthPaths.set(key, p);
|
|
465
|
+
return p;
|
|
466
|
+
}
|
|
467
|
+
function drawFace(ctx, pose, cfg) {
|
|
468
|
+
const [wd, ww, ws] = pose.w;
|
|
469
|
+
const ink = cfg.ink;
|
|
470
|
+
const ey = EYE_Y[cfg.face];
|
|
471
|
+
const half = EYE_GAP / 2;
|
|
472
|
+
const lx = pose.lookX, ly = pose.lookY;
|
|
473
|
+
const { yaw, pitch } = pose;
|
|
474
|
+
const at = (x, y, fn, alpha = 1)=>{
|
|
475
|
+
const q = onSphere(x, y, yaw, pitch);
|
|
476
|
+
if (q.z <= 0.02 || alpha <= 0.01) return;
|
|
477
|
+
ctx.save();
|
|
478
|
+
ctx.globalAlpha = alpha * Math.min(1, q.z * 5);
|
|
479
|
+
ctx.translate(q.x, q.y);
|
|
480
|
+
ctx.scale(Math.max(0.02, q.sx), Math.max(0.02, q.sy));
|
|
481
|
+
fn();
|
|
482
|
+
ctx.restore();
|
|
483
|
+
};
|
|
484
|
+
const past = (v, d)=>Math.abs(v) <= d ? 0 : Math.sign(v) * (Math.abs(v) - d) / (1 - d);
|
|
485
|
+
const clamp1 = (v)=>Math.max(-1, Math.min(1, v));
|
|
486
|
+
const up = past(clamp1(-pose.pitch / 0.26 - pose.lookY / 7), 0.34);
|
|
487
|
+
const side = Math.abs(past(clamp1(pose.lookX / 4.5), 0.4));
|
|
488
|
+
const tall = Math.max(0.3, 1 + 0.55 * up - 0.1 * side);
|
|
489
|
+
const wide = 1 - 0.05 * up + 0.12 * side;
|
|
490
|
+
const open = wd + ww * (1 - pose.laugh);
|
|
491
|
+
const laugh = ww * pose.laugh;
|
|
492
|
+
const lift = Math.max(0, -pose.y) / 26;
|
|
493
|
+
const sag = 0.5 + 0.5 * pose.breath;
|
|
494
|
+
for (const side of [
|
|
495
|
+
-1,
|
|
496
|
+
1
|
|
497
|
+
]){
|
|
498
|
+
const lid = side < 0 ? pose.blinkL : pose.blinkR;
|
|
499
|
+
const e = Math.max(0, Math.min(1, pose.eyeOpen * (1 - lid)));
|
|
500
|
+
const kOpen = open * e, kShut = open * (1 - e), kLaugh = laugh, kSleep = ws;
|
|
501
|
+
const x0 = kOpen * 0.01 + kShut * 5.4 + kLaugh * 6.2 + kSleep * 6;
|
|
502
|
+
const y0 = kOpen * 2 * tall + kShut * 0.6 + kLaugh * (2.2 - lift * 1.5) + kSleep * (-1.4 + sag);
|
|
503
|
+
const cy = kOpen * -6 * tall + kShut * 0.6 + kLaugh * (-11.4 - 4 * lift) + kSleep * (5.4 + 2 * sag);
|
|
504
|
+
const w = kOpen * EYE_RX * 2 * wide + kShut * 2.8 + kLaugh * 4.4 + kSleep * 4;
|
|
505
|
+
const dx = lx * (kOpen + 0.5 * (kShut + kLaugh)), dy = ly * (kOpen + 0.5 * kShut);
|
|
506
|
+
at(side * half + dx, ey + dy, ()=>{
|
|
507
|
+
ctx.strokeStyle = ink;
|
|
508
|
+
ctx.lineWidth = w;
|
|
509
|
+
ctx.stroke(eyePath(x0, y0, cy));
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
if (cfg.face === "mouth") {
|
|
513
|
+
const mx = lx * 0.35;
|
|
514
|
+
const kd = (0.6 + 0.4 * wd) * (1 + 0.06 * pose.breath);
|
|
515
|
+
const kw = (0.6 + 0.4 * ww) * (1 + 0.25 * Math.max(0, -pose.y) / 26);
|
|
516
|
+
const r = 2.7 * ws * (1 + 0.25 * pose.breath);
|
|
517
|
+
const b = (d, w, s)=>wd * d + ww * w + ws * s;
|
|
518
|
+
const m = {
|
|
519
|
+
hw: b(6.5 * kd, 9.5 * kw, r),
|
|
520
|
+
t0: b(1.9, 0, 0),
|
|
521
|
+
a: b(2 / 3, 2 / 3, 0),
|
|
522
|
+
yt: b(3.53 * kd, 1.6 * kw, -4 * r / 3),
|
|
523
|
+
ab: b(2 / 3, 0, 0),
|
|
524
|
+
yb: b(3.53 * kd, 17.3 * kw, 4 * r / 3)
|
|
525
|
+
};
|
|
526
|
+
at(mx, b(12.5, 11.6, 15.5), ()=>{
|
|
527
|
+
ctx.fillStyle = ink;
|
|
528
|
+
ctx.fill(mouthPath(m));
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
const spot = (x)=>{
|
|
532
|
+
const q = onSphere(x, ey, yaw, pitch);
|
|
533
|
+
return {
|
|
534
|
+
x: q.x,
|
|
535
|
+
y: q.y,
|
|
536
|
+
sx: q.sx,
|
|
537
|
+
sy: q.sy,
|
|
538
|
+
z: q.z,
|
|
539
|
+
ox: x,
|
|
540
|
+
oy: ey,
|
|
541
|
+
fz: Math.sqrt(Math.max(0, FACE_R * FACE_R - x * x - ey * ey))
|
|
542
|
+
};
|
|
543
|
+
};
|
|
544
|
+
return [
|
|
545
|
+
spot(-half),
|
|
546
|
+
spot(half)
|
|
547
|
+
];
|
|
548
|
+
}
|