dsh-visualkit 0.0.0-stage → 0.0.1
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 +60 -0
- package/LICENSE +26 -0
- package/README.md +427 -2
- package/THIRD_PARTY.md +55 -0
- package/cordis.patch.yml +29 -0
- package/data/assets/README.md +38 -0
- package/data/assets/icons/brands/bilibili.svg +1 -0
- package/data/assets/icons/brands/discord.svg +1 -0
- package/data/assets/icons/brands/neteasecloudmusic.svg +1 -0
- package/data/assets/icons/brands/qq.svg +1 -0
- package/data/assets/icons/brands/sinaweibo.svg +1 -0
- package/data/assets/icons/brands/steam.svg +1 -0
- package/data/assets/icons/brands/telegram.svg +1 -0
- package/data/assets/icons/brands/tiktok.svg +1 -0
- package/data/assets/icons/brands/twitch.svg +1 -0
- package/data/assets/icons/brands/wechat.svg +1 -0
- package/data/assets/icons/brands/x.svg +1 -0
- package/data/assets/icons/brands/youtube.svg +1 -0
- package/data/assets/icons/lucide/bell.svg +1 -0
- package/data/assets/icons/lucide/calendar.svg +1 -0
- package/data/assets/icons/lucide/clock.svg +1 -0
- package/data/assets/icons/lucide/gamepad-2.svg +1 -0
- package/data/assets/icons/lucide/gift.svg +1 -0
- package/data/assets/icons/lucide/heart.svg +1 -0
- package/data/assets/icons/lucide/mic.svg +1 -0
- package/data/assets/icons/lucide/play.svg +1 -0
- package/data/assets/icons/lucide/star.svg +1 -0
- package/data/assets/icons/lucide/video.svg +1 -0
- package/data/assets/icons/phosphor/LICENSE +21 -0
- package/data/assets/icons/phosphor/atom-duotone.svg +1 -0
- package/data/assets/icons/phosphor/binary-duotone.svg +1 -0
- package/data/assets/icons/phosphor/blueprint-duotone.svg +1 -0
- package/data/assets/icons/phosphor/circuitry-duotone.svg +1 -0
- package/data/assets/icons/phosphor/cloud-arrow-up-duotone.svg +1 -0
- package/data/assets/icons/phosphor/code-duotone.svg +1 -0
- package/data/assets/icons/phosphor/compass-duotone.svg +1 -0
- package/data/assets/icons/phosphor/cpu-duotone.svg +1 -0
- package/data/assets/icons/phosphor/cube-duotone.svg +1 -0
- package/data/assets/icons/phosphor/database-duotone.svg +1 -0
- package/data/assets/icons/phosphor/flask-duotone.svg +1 -0
- package/data/assets/icons/phosphor/frame-corners-duotone.svg +1 -0
- package/data/assets/icons/phosphor/function-duotone.svg +1 -0
- package/data/assets/icons/phosphor/hard-drives-duotone.svg +1 -0
- package/data/assets/icons/phosphor/hexagon-duotone.svg +1 -0
- package/data/assets/icons/phosphor/infinity-duotone.svg +1 -0
- package/data/assets/icons/phosphor/lightning-duotone.svg +1 -0
- package/data/assets/icons/phosphor/magic-wand-duotone.svg +1 -0
- package/data/assets/icons/phosphor/moon-stars-duotone.svg +1 -0
- package/data/assets/icons/phosphor/paint-brush-duotone.svg +1 -0
- package/data/assets/icons/phosphor/pen-nib-duotone.svg +1 -0
- package/data/assets/icons/phosphor/planet-duotone.svg +1 -0
- package/data/assets/icons/phosphor/rocket-launch-duotone.svg +1 -0
- package/data/assets/icons/phosphor/ruler-duotone.svg +1 -0
- package/data/assets/icons/phosphor/selection-plus-duotone.svg +1 -0
- package/data/assets/icons/phosphor/shapes-duotone.svg +1 -0
- package/data/assets/icons/phosphor/sparkle-duotone.svg +1 -0
- package/data/assets/icons/phosphor/sun-horizon-duotone.svg +1 -0
- package/data/assets/icons/phosphor/terminal-window-duotone.svg +1 -0
- package/data/assets/icons/phosphor/triangle-duotone.svg +1 -0
- package/data/assets/icons/phosphor/waveform-duotone.svg +1 -0
- package/data/assets/icons/tabler/alarm.svg +1 -0
- package/data/assets/icons/tabler/badge-ad.svg +1 -0
- package/data/assets/icons/tabler/bell.svg +1 -0
- package/data/assets/icons/tabler/bolt.svg +1 -0
- package/data/assets/icons/tabler/brand-bilibili.svg +1 -0
- package/data/assets/icons/tabler/brand-discord.svg +1 -0
- package/data/assets/icons/tabler/brand-qq.svg +1 -0
- package/data/assets/icons/tabler/brand-twitch.svg +1 -0
- package/data/assets/icons/tabler/brand-wechat.svg +1 -0
- package/data/assets/icons/tabler/brand-weibo.svg +1 -0
- package/data/assets/icons/tabler/brand-youtube.svg +1 -0
- package/data/assets/icons/tabler/broadcast.svg +1 -0
- package/data/assets/icons/tabler/calendar-event.svg +1 -0
- package/data/assets/icons/tabler/calendar-week.svg +1 -0
- package/data/assets/icons/tabler/clock-hour-3.svg +1 -0
- package/data/assets/icons/tabler/coin.svg +1 -0
- package/data/assets/icons/tabler/crown.svg +1 -0
- package/data/assets/icons/tabler/currency-yen.svg +1 -0
- package/data/assets/icons/tabler/device-gamepad-2.svg +1 -0
- package/data/assets/icons/tabler/diamond.svg +1 -0
- package/data/assets/icons/tabler/flame.svg +1 -0
- package/data/assets/icons/tabler/gift.svg +1 -0
- package/data/assets/icons/tabler/headphones.svg +1 -0
- package/data/assets/icons/tabler/heart-filled.svg +1 -0
- package/data/assets/icons/tabler/heart.svg +1 -0
- package/data/assets/icons/tabler/live-view.svg +1 -0
- package/data/assets/icons/tabler/microphone.svg +1 -0
- package/data/assets/icons/tabler/mood-smile.svg +1 -0
- package/data/assets/icons/tabler/mood-tongue.svg +1 -0
- package/data/assets/icons/tabler/movie.svg +1 -0
- package/data/assets/icons/tabler/player-play.svg +1 -0
- package/data/assets/icons/tabler/playlist.svg +1 -0
- package/data/assets/icons/tabler/rocket.svg +1 -0
- package/data/assets/icons/tabler/sparkles.svg +1 -0
- package/data/assets/icons/tabler/star-filled.svg +1 -0
- package/data/assets/icons/tabler/star.svg +1 -0
- package/data/assets/icons/tabler/tag.svg +1 -0
- package/data/assets/icons/tabler/thumb-up.svg +1 -0
- package/data/assets/icons/tabler/ticket.svg +1 -0
- package/data/assets/icons/tabler/video.svg +1 -0
- package/data/assets/illustrations/openpeeps/LICENSE +8 -0
- package/data/assets/illustrations/openpeeps/peep-10.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-100.svg +32 -0
- package/data/assets/illustrations/openpeeps/peep-101.svg +25 -0
- package/data/assets/illustrations/openpeeps/peep-102.svg +28 -0
- package/data/assets/illustrations/openpeeps/peep-103.svg +32 -0
- package/data/assets/illustrations/openpeeps/peep-105.svg +25 -0
- package/data/assets/illustrations/openpeeps/peep-12.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-13.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-16.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-17.svg +31 -0
- package/data/assets/illustrations/openpeeps/peep-22.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-25.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-26.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-27.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-30.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-31.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-34.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-38.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-39.svg +31 -0
- package/data/assets/illustrations/openpeeps/peep-4.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-41.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-44.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-47.svg +26 -0
- package/data/assets/illustrations/openpeeps/peep-48.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-50.svg +31 -0
- package/data/assets/illustrations/openpeeps/peep-51.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-53.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-54.svg +26 -0
- package/data/assets/illustrations/openpeeps/peep-55.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-56.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-58.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-61.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-64.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-68.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-69.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-7.svg +31 -0
- package/data/assets/illustrations/openpeeps/peep-72.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-76.svg +31 -0
- package/data/assets/illustrations/openpeeps/peep-77.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-80.svg +27 -0
- package/data/assets/illustrations/openpeeps/peep-81.svg +29 -0
- package/data/assets/illustrations/openpeeps/peep-83.svg +29 -0
- package/data/assets/manifest.json +1 -0
- package/data/assets/parts//342/206/223/346/212/225/345/275/261.png +0 -0
- package/data/assets/parts//344/270/211/350/247/222/345/217/221/345/244/2711.png +0 -0
- package/data/assets/parts//344/270/211/350/247/222/345/217/221/345/244/2712.png +0 -0
- package/data/assets/parts//344/270/211/350/247/222/345/217/221/345/244/2713.png +0 -0
- package/data/assets/parts//344/270/211/350/247/222/345/217/221/345/244/2714.png +0 -0
- package/data/assets/parts//345/217/214/351/251/254/345/260/276.png +0 -0
- package/data/assets/parts//345/217/214/351/251/254/345/260/2761.png +0 -0
- package/data/assets/parts//345/217/2211.png +0 -0
- package/data/assets/parts//345/217/2212.png +0 -0
- package/data/assets/parts//345/217/2213.png +0 -0
- package/data/assets/parts//345/217/221/345/234/210.png +0 -0
- package/data/assets/parts//345/217/221/345/244/2711.png +0 -0
- package/data/assets/parts//345/217/221/345/244/2712.png +0 -0
- package/data/assets/parts//345/217/243/346/260/264/345/267/276/345/211/215.png +0 -0
- package/data/assets/parts//345/217/243/346/260/264/345/267/276/345/220/216.png +0 -0
- package/data/assets/parts//345/217/263/344/270/212/347/234/274/347/235/221.png +0 -0
- package/data/assets/parts//345/217/263/346/211/213.png +0 -0
- package/data/assets/parts//345/217/263/346/211/2131.png +0 -0
- package/data/assets/parts//345/217/263/347/234/274/347/220/203.png +0 -0
- package/data/assets/parts//345/217/263/347/234/274/347/231/275.png +0 -0
- package/data/assets/parts//345/217/263/350/205/277.png +0 -0
- package/data/assets/parts//345/221/206/346/257/233.png +0 -0
- package/data/assets/parts//345/230/264/345/267/264.png +0 -0
- package/data/assets/parts//345/260/276/345/267/264.png +0 -0
- package/data/assets/parts//345/267/246/344/270/212/347/234/274/347/235/221.png +0 -0
- package/data/assets/parts//345/267/246/345/217/214/347/234/274/347/232/256.png +0 -0
- package/data/assets/parts//345/267/246/346/211/213.png +0 -0
- package/data/assets/parts//345/267/246/346/211/2131.png +0 -0
- package/data/assets/parts//345/267/246/347/234/274/347/220/203.png +0 -0
- package/data/assets/parts//345/267/246/347/234/274/347/231/275.png +0 -0
- package/data/assets/parts//345/267/246/350/205/277.png +0 -0
- package/data/assets/parts//346/212/225/345/275/261.png +0 -0
- package/data/assets/parts//347/234/211/346/257/233.png +0 -0
- package/data/assets/parts//347/234/274/347/275/251.png +0 -0
- package/data/assets/parts//350/200/263/346/234/2651.png +0 -0
- package/data/assets/parts//350/200/263/346/234/2652.png +0 -0
- package/data/assets/parts//350/204/221/345/243/263.png +0 -0
- package/data/assets/parts//350/241/243/346/234/215/345/211/215.png +0 -0
- package/data/assets/parts//350/241/243/346/234/215/345/220/216.png +0 -0
- package/data/assets/parts//350/241/243/346/234/215/351/273/221.png +0 -0
- package/data/assets/parts//350/241/243/346/234/215/351/273/2211.png +0 -0
- package/data/assets/parts//350/272/253/344/275/223.png +0 -0
- package/data/assets/parts//351/223/201/346/235/277.png +0 -0
- package/data/assets/parts//351/273/221/347/234/274/345/234/210.png +0 -0
- package/data/assets/parts//351/273/221/347/234/274/345/234/2102.png +0 -0
- package/data/assets/patterns/checker.svg +1 -0
- package/data/assets/patterns/circles-overlap.svg +1 -0
- package/data/assets/patterns/crosshatch.svg +1 -0
- package/data/assets/patterns/diagonal.svg +1 -0
- package/data/assets/patterns/dots.svg +1 -0
- package/data/assets/patterns/grid.svg +1 -0
- package/data/assets/patterns/halftone.svg +1 -0
- package/data/assets/patterns/plus.svg +1 -0
- package/data/assets/patterns/scales.svg +1 -0
- package/data/assets/patterns/triangles.svg +1 -0
- package/data/assets/patterns/waves.svg +1 -0
- package/data/assets/patterns/zigzag.svg +1 -0
- package/data/assets/stickers/openmoji/1F375.svg +12 -0
- package/data/assets/stickers/openmoji/1F9E8.svg +21 -0
- package/data/assets/stickers/twemoji/1f389.svg +1 -0
- package/data/assets/stickers/twemoji/1f3a4.svg +1 -0
- package/data/assets/stickers/twemoji/1f3a7.svg +1 -0
- package/data/assets/stickers/twemoji/1f3ae.svg +1 -0
- package/data/assets/stickers/twemoji/1f44b.svg +1 -0
- package/data/assets/stickers/twemoji/1f44d.svg +1 -0
- package/data/assets/stickers/twemoji/1f494.svg +1 -0
- package/data/assets/stickers/twemoji/1f4a2.svg +1 -0
- package/data/assets/stickers/twemoji/1f4a8.svg +1 -0
- package/data/assets/stickers/twemoji/1f4b5.svg +1 -0
- package/data/assets/stickers/twemoji/1f4d6.svg +1 -0
- package/data/assets/stickers/twemoji/1f525.svg +1 -0
- package/data/assets/stickers/twemoji/1f600.svg +1 -0
- package/data/assets/stickers/twemoji/1f602.svg +1 -0
- package/data/assets/stickers/twemoji/1f60d.svg +1 -0
- package/data/assets/stickers/twemoji/1f62d.svg +1 -0
- package/data/assets/stickers/twemoji/1f680.svg +1 -0
- package/data/assets/stickers/twemoji/1f979.svg +1 -0
- package/data/assets/stickers/twemoji/1f97a.svg +1 -0
- package/data/assets/stickers/twemoji/26a1.svg +1 -0
- package/data/assets/stickers/twemoji/2705.svg +1 -0
- package/data/assets/stickers/twemoji/274c.svg +1 -0
- package/data/assets/stickers/twemoji/2764.svg +1 -0
- package/data/assets/stickers/twemoji/2b50.svg +1 -0
- package/data/assets/stickers/twemoji_1f525.svg +1 -0
- package/data/assets/stickers/twemoji_1f600.svg +1 -0
- package/data/assets/stickers/twemoji_1f979.svg +1 -0
- package/data/assets/stickers/twemoji_2764.svg +1 -0
- package/data/assets/textures/grain-dark.png +0 -0
- package/data/assets/textures/grain-light.png +0 -0
- package/data/assets/textures/grain-warm.png +0 -0
- package/data/lucide-icons.json +1 -0
- package/data/packs/tabler.icons.json +1 -0
- package/icon.svg +26 -0
- package/lib/assets.js +228 -0
- package/lib/audit.js +284 -0
- package/lib/contrast-render.js +213 -0
- package/lib/css-rewrite.js +379 -0
- package/lib/detect.js +701 -0
- package/lib/diff.js +153 -0
- package/lib/emit.js +557 -0
- package/lib/html-context.js +315 -0
- package/lib/icon-render.js +107 -0
- package/lib/icondb.js +402 -0
- package/lib/image-normalize.js +140 -0
- package/lib/index.js +1289 -0
- package/lib/layouts/common.js +48 -0
- package/lib/layouts/image.js +1010 -0
- package/lib/layouts/index.js +10 -0
- package/lib/layouts/intent.js +66 -0
- package/lib/layouts/metrics-text.js +91 -0
- package/lib/layouts/png.js +75 -0
- package/lib/layouts/rules-contrast.js +575 -0
- package/lib/layouts/rules-punct.js +486 -0
- package/lib/layouts/rules-structure.js +182 -0
- package/lib/layouts/source.js +1961 -0
- package/lib/layouts/svg.js +1204 -0
- package/lib/morphcore.js +139 -0
- package/lib/preview.js +225 -0
- package/lib/render-html.js +255 -0
- package/lib/render.js +486 -0
- package/lib/rules.js +267 -0
- package/lib/shadow.js +83 -0
- package/lib/skip.js +56 -0
- package/lib/style.js +688 -0
- package/lib/svg.js +729 -0
- package/lib/taste-image.js +323 -0
- package/lib/taste.js +219 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +92 -4
- package/vendor/morphicons-adapters.iife.js +903 -0
- package/vendor/morphicons.iife.js +2441 -0
- package/vendor/resvg/LICENSE +373 -0
- package/vendor/resvg/index.d.ts +98 -0
- package/vendor/resvg/index.js +23 -0
- package/vendor/resvg/js-binding.d.ts +52 -0
- package/vendor/resvg/js-binding.js +1 -0
- package/vendor/resvg/package.json +138 -0
- package/vendor/resvg/resvgjs.win32-x64-msvc.node +0 -0
|
@@ -0,0 +1,2441 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* morphicons v2.0.2 — SVG 图标形变动画库(https://www.morphicons.com/)
|
|
3
|
+
* License: MIT © Guillermo (guillermolg.com)
|
|
4
|
+
* 本文件是 vendored 产物(非手写,不参与 check/repolint 扫描):
|
|
5
|
+
* npm install --no-save morphicons@2.0.2 esbuild
|
|
6
|
+
* npx esbuild node_modules/morphicons/dist/dom.js --bundle --format=iife --global-name=MorphIcons --outfile=vendor/morphicons.iife.js
|
|
7
|
+
* 构建日期:2026-11-07(morphicons 2.0.2,与上游 v2.0.2 tag 一致)
|
|
8
|
+
*/
|
|
9
|
+
var MorphIcons = (() => {
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
+
var __esm = (fn, res, err) => function __init() {
|
|
16
|
+
if (err) throw err[0];
|
|
17
|
+
try {
|
|
18
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw err = [e], e;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
37
|
+
|
|
38
|
+
// node_modules/morphicons/dist/normalize-CYnN3Npw.js
|
|
39
|
+
function parsePath(d) {
|
|
40
|
+
const subs = [];
|
|
41
|
+
const n = d.length;
|
|
42
|
+
let i = 0;
|
|
43
|
+
let cx = 0;
|
|
44
|
+
let cy = 0;
|
|
45
|
+
let sx = 0;
|
|
46
|
+
let sy = 0;
|
|
47
|
+
let cur = null;
|
|
48
|
+
let cmd = "";
|
|
49
|
+
let px = 0;
|
|
50
|
+
let py = 0;
|
|
51
|
+
let prev = "";
|
|
52
|
+
let started = false;
|
|
53
|
+
const err = (msg) => {
|
|
54
|
+
throw new Error(`morphicons: ${msg} at d[${i}]`);
|
|
55
|
+
};
|
|
56
|
+
const isDigit = (c) => c >= 48 && c <= 57;
|
|
57
|
+
const skip = () => {
|
|
58
|
+
while (i < n) {
|
|
59
|
+
const c = d.charCodeAt(i);
|
|
60
|
+
if (c === 32 || c === 9 || c === 10 || c === 13 || c === 12 || c === 44) i++;
|
|
61
|
+
else break;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const num2 = () => {
|
|
65
|
+
skip();
|
|
66
|
+
const start = i;
|
|
67
|
+
if (i < n && (d[i] === "+" || d[i] === "-")) i++;
|
|
68
|
+
let dig = false;
|
|
69
|
+
while (i < n && isDigit(d.charCodeAt(i))) {
|
|
70
|
+
i++;
|
|
71
|
+
dig = true;
|
|
72
|
+
}
|
|
73
|
+
if (i < n && d[i] === ".") {
|
|
74
|
+
i++;
|
|
75
|
+
while (i < n && isDigit(d.charCodeAt(i))) {
|
|
76
|
+
i++;
|
|
77
|
+
dig = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!dig) err("expected number");
|
|
81
|
+
if (i < n && (d[i] === "e" || d[i] === "E")) {
|
|
82
|
+
const save = i;
|
|
83
|
+
i++;
|
|
84
|
+
if (i < n && (d[i] === "+" || d[i] === "-")) i++;
|
|
85
|
+
let ed = false;
|
|
86
|
+
while (i < n && isDigit(d.charCodeAt(i))) {
|
|
87
|
+
i++;
|
|
88
|
+
ed = true;
|
|
89
|
+
}
|
|
90
|
+
if (!ed) i = save;
|
|
91
|
+
}
|
|
92
|
+
return Number(d.slice(start, i));
|
|
93
|
+
};
|
|
94
|
+
const flag = () => {
|
|
95
|
+
skip();
|
|
96
|
+
const c = d[i];
|
|
97
|
+
if (c === "0" || c === "1") {
|
|
98
|
+
i++;
|
|
99
|
+
return c === "1" ? 1 : 0;
|
|
100
|
+
}
|
|
101
|
+
return err("expected arc flag (0|1)");
|
|
102
|
+
};
|
|
103
|
+
const open = () => {
|
|
104
|
+
if (!started) err("path must start with M/m");
|
|
105
|
+
if (!cur) {
|
|
106
|
+
cur = {
|
|
107
|
+
x0: cx,
|
|
108
|
+
y0: cy,
|
|
109
|
+
segs: [],
|
|
110
|
+
closed: false
|
|
111
|
+
};
|
|
112
|
+
subs.push(cur);
|
|
113
|
+
}
|
|
114
|
+
return cur;
|
|
115
|
+
};
|
|
116
|
+
let rel = false;
|
|
117
|
+
const nx = () => num2() + (rel ? cx : 0);
|
|
118
|
+
const ny = () => num2() + (rel ? cy : 0);
|
|
119
|
+
while (true) {
|
|
120
|
+
skip();
|
|
121
|
+
if (i >= n) break;
|
|
122
|
+
const ch = d[i];
|
|
123
|
+
if (COMMANDS.includes(ch)) {
|
|
124
|
+
cmd = ch;
|
|
125
|
+
i++;
|
|
126
|
+
} else if (cmd === "") err("path must start with M/m");
|
|
127
|
+
else if (cmd === "M") cmd = "L";
|
|
128
|
+
else if (cmd === "m") cmd = "l";
|
|
129
|
+
else if (cmd === "Z" || cmd === "z") err("stray data after Z");
|
|
130
|
+
rel = cmd >= "a";
|
|
131
|
+
switch (rel ? cmd.toUpperCase() : cmd) {
|
|
132
|
+
case "M": {
|
|
133
|
+
started = true;
|
|
134
|
+
const x = nx();
|
|
135
|
+
const y = ny();
|
|
136
|
+
cx = x;
|
|
137
|
+
cy = y;
|
|
138
|
+
sx = x;
|
|
139
|
+
sy = y;
|
|
140
|
+
cur = {
|
|
141
|
+
x0: x,
|
|
142
|
+
y0: y,
|
|
143
|
+
segs: [],
|
|
144
|
+
closed: false
|
|
145
|
+
};
|
|
146
|
+
subs.push(cur);
|
|
147
|
+
prev = "";
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case "L": {
|
|
151
|
+
const x = nx();
|
|
152
|
+
const y = ny();
|
|
153
|
+
open().segs.push([
|
|
154
|
+
"L",
|
|
155
|
+
x,
|
|
156
|
+
y
|
|
157
|
+
]);
|
|
158
|
+
cx = x;
|
|
159
|
+
cy = y;
|
|
160
|
+
prev = "";
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case "H": {
|
|
164
|
+
const x = nx();
|
|
165
|
+
open().segs.push([
|
|
166
|
+
"L",
|
|
167
|
+
x,
|
|
168
|
+
cy
|
|
169
|
+
]);
|
|
170
|
+
cx = x;
|
|
171
|
+
prev = "";
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case "V": {
|
|
175
|
+
const y = ny();
|
|
176
|
+
open().segs.push([
|
|
177
|
+
"L",
|
|
178
|
+
cx,
|
|
179
|
+
y
|
|
180
|
+
]);
|
|
181
|
+
cy = y;
|
|
182
|
+
prev = "";
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case "C":
|
|
186
|
+
case "S": {
|
|
187
|
+
let x1;
|
|
188
|
+
let y1;
|
|
189
|
+
if (cmd === "C" || cmd === "c") {
|
|
190
|
+
x1 = nx();
|
|
191
|
+
y1 = ny();
|
|
192
|
+
} else {
|
|
193
|
+
x1 = prev === "C" ? 2 * cx - px : cx;
|
|
194
|
+
y1 = prev === "C" ? 2 * cy - py : cy;
|
|
195
|
+
}
|
|
196
|
+
const x2 = nx();
|
|
197
|
+
const y2 = ny();
|
|
198
|
+
const x = nx();
|
|
199
|
+
const y = ny();
|
|
200
|
+
open().segs.push([
|
|
201
|
+
"C",
|
|
202
|
+
x1,
|
|
203
|
+
y1,
|
|
204
|
+
x2,
|
|
205
|
+
y2,
|
|
206
|
+
x,
|
|
207
|
+
y
|
|
208
|
+
]);
|
|
209
|
+
px = x2;
|
|
210
|
+
py = y2;
|
|
211
|
+
cx = x;
|
|
212
|
+
cy = y;
|
|
213
|
+
prev = "C";
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case "Q":
|
|
217
|
+
case "T": {
|
|
218
|
+
let x1;
|
|
219
|
+
let y1;
|
|
220
|
+
if (cmd === "Q" || cmd === "q") {
|
|
221
|
+
x1 = nx();
|
|
222
|
+
y1 = ny();
|
|
223
|
+
} else {
|
|
224
|
+
x1 = prev === "Q" ? 2 * cx - px : cx;
|
|
225
|
+
y1 = prev === "Q" ? 2 * cy - py : cy;
|
|
226
|
+
}
|
|
227
|
+
const x = nx();
|
|
228
|
+
const y = ny();
|
|
229
|
+
open().segs.push([
|
|
230
|
+
"Q",
|
|
231
|
+
x1,
|
|
232
|
+
y1,
|
|
233
|
+
x,
|
|
234
|
+
y
|
|
235
|
+
]);
|
|
236
|
+
px = x1;
|
|
237
|
+
py = y1;
|
|
238
|
+
cx = x;
|
|
239
|
+
cy = y;
|
|
240
|
+
prev = "Q";
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case "A": {
|
|
244
|
+
const rx = num2();
|
|
245
|
+
const ry = num2();
|
|
246
|
+
const rot = num2();
|
|
247
|
+
const large = flag();
|
|
248
|
+
const sweep = flag();
|
|
249
|
+
const x = nx();
|
|
250
|
+
const y = ny();
|
|
251
|
+
open().segs.push([
|
|
252
|
+
"A",
|
|
253
|
+
rx,
|
|
254
|
+
ry,
|
|
255
|
+
rot,
|
|
256
|
+
large,
|
|
257
|
+
sweep,
|
|
258
|
+
x,
|
|
259
|
+
y
|
|
260
|
+
]);
|
|
261
|
+
cx = x;
|
|
262
|
+
cy = y;
|
|
263
|
+
prev = "";
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
case "Z":
|
|
267
|
+
if (cur) {
|
|
268
|
+
cur.closed = true;
|
|
269
|
+
cur = null;
|
|
270
|
+
}
|
|
271
|
+
cx = sx;
|
|
272
|
+
cy = sy;
|
|
273
|
+
prev = "";
|
|
274
|
+
break;
|
|
275
|
+
default:
|
|
276
|
+
err(`unsupported command "${cmd}"`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return subs.filter((s) => s.segs.length > 0);
|
|
280
|
+
}
|
|
281
|
+
function fmt(v) {
|
|
282
|
+
return String(Math.round(v * 100) / 100);
|
|
283
|
+
}
|
|
284
|
+
function serialize(subs, closed) {
|
|
285
|
+
let d = "";
|
|
286
|
+
for (let k = 0; k < subs.length; k++) {
|
|
287
|
+
const o = subs[k];
|
|
288
|
+
const n = o.length / 2;
|
|
289
|
+
d += `M${fmt(o[0])} ${fmt(o[1])}`;
|
|
290
|
+
for (let i = 1; i < n; i++) d += `L${fmt(o[2 * i])} ${fmt(o[2 * i + 1])}`;
|
|
291
|
+
if (closed?.[k]) d += "Z";
|
|
292
|
+
}
|
|
293
|
+
return d;
|
|
294
|
+
}
|
|
295
|
+
function fmtCanon(v) {
|
|
296
|
+
return String(Math.round(v * 1e4) / 1e4);
|
|
297
|
+
}
|
|
298
|
+
function cubicsToPathD(paths) {
|
|
299
|
+
let d = "";
|
|
300
|
+
for (const { pts, closed } of paths) {
|
|
301
|
+
d += `M${fmtCanon(pts[0])} ${fmtCanon(pts[1])}`;
|
|
302
|
+
for (let i = 2; i < pts.length; i += 6) d += `C${fmtCanon(pts[i])} ${fmtCanon(pts[i + 1])} ${fmtCanon(pts[i + 2])} ${fmtCanon(pts[i + 3])} ${fmtCanon(pts[i + 4])} ${fmtCanon(pts[i + 5])}`;
|
|
303
|
+
if (closed) d += "Z";
|
|
304
|
+
}
|
|
305
|
+
return d;
|
|
306
|
+
}
|
|
307
|
+
function builder(x0, y0) {
|
|
308
|
+
const pts = [x0, y0];
|
|
309
|
+
let cx = x0;
|
|
310
|
+
let cy = y0;
|
|
311
|
+
const cubic = (x1, y1, x2, y2, x, y) => {
|
|
312
|
+
pts.push(x1, y1, x2, y2, x, y);
|
|
313
|
+
cx = x;
|
|
314
|
+
cy = y;
|
|
315
|
+
};
|
|
316
|
+
const line = (x, y) => {
|
|
317
|
+
if (Math.abs(x - cx) < 1e-12 && Math.abs(y - cy) < 1e-12) return;
|
|
318
|
+
cubic(cx + (x - cx) / 3, cy + (y - cy) / 3, cx + 2 * (x - cx) / 3, cy + 2 * (y - cy) / 3, x, y);
|
|
319
|
+
};
|
|
320
|
+
const quad = (x1, y1, x, y) => {
|
|
321
|
+
cubic(cx + 2 / 3 * (x1 - cx), cy + 2 / 3 * (y1 - cy), x + 2 / 3 * (x1 - x), y + 2 / 3 * (y1 - y), x, y);
|
|
322
|
+
};
|
|
323
|
+
const arc = (rx0, ry0, rotDeg, large, sweep, x, y) => {
|
|
324
|
+
const x1 = cx;
|
|
325
|
+
const y1 = cy;
|
|
326
|
+
if (Math.abs(x - x1) < 1e-12 && Math.abs(y - y1) < 1e-12) return;
|
|
327
|
+
let rx = Math.abs(rx0);
|
|
328
|
+
let ry = Math.abs(ry0);
|
|
329
|
+
if (rx < 1e-12 || ry < 1e-12) {
|
|
330
|
+
line(x, y);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const phi = rotDeg * Math.PI / 180;
|
|
334
|
+
const cosP = Math.cos(phi);
|
|
335
|
+
const sinP = Math.sin(phi);
|
|
336
|
+
const hx = (x1 - x) / 2;
|
|
337
|
+
const hy = (y1 - y) / 2;
|
|
338
|
+
const x1p = cosP * hx + sinP * hy;
|
|
339
|
+
const y1p = -sinP * hx + cosP * hy;
|
|
340
|
+
const lam = x1p * x1p / (rx * rx) + y1p * y1p / (ry * ry);
|
|
341
|
+
if (lam > 1) {
|
|
342
|
+
const s = Math.sqrt(lam);
|
|
343
|
+
rx *= s;
|
|
344
|
+
ry *= s;
|
|
345
|
+
}
|
|
346
|
+
const rx2 = rx * rx;
|
|
347
|
+
const ry2 = ry * ry;
|
|
348
|
+
const xp2 = x1p * x1p;
|
|
349
|
+
const yp2 = y1p * y1p;
|
|
350
|
+
let rad = (rx2 * ry2 - rx2 * yp2 - ry2 * xp2) / (rx2 * yp2 + ry2 * xp2);
|
|
351
|
+
if (rad < 0) rad = 0;
|
|
352
|
+
const co = (large === sweep ? -1 : 1) * Math.sqrt(rad);
|
|
353
|
+
const cxp = co * rx * y1p / ry;
|
|
354
|
+
const cyp = -co * ry * x1p / rx;
|
|
355
|
+
const ccx = cosP * cxp - sinP * cyp + (x1 + x) / 2;
|
|
356
|
+
const ccy = sinP * cxp + cosP * cyp + (y1 + y) / 2;
|
|
357
|
+
const th1 = Math.atan2((y1p - cyp) / ry, (x1p - cxp) / rx);
|
|
358
|
+
let dth = Math.atan2((-y1p - cyp) / ry, (-x1p - cxp) / rx) - th1;
|
|
359
|
+
if (sweep === 0 && dth > 0) dth -= TAU;
|
|
360
|
+
else if (sweep === 1 && dth < 0) dth += TAU;
|
|
361
|
+
const slices = Math.max(1, Math.ceil(Math.abs(dth) / (Math.PI / 2) - 1e-9));
|
|
362
|
+
const delta = dth / slices;
|
|
363
|
+
const alpha = 4 / 3 * Math.tan(delta / 4);
|
|
364
|
+
const ex = (t) => ccx + rx * Math.cos(t) * cosP - ry * Math.sin(t) * sinP;
|
|
365
|
+
const ey = (t) => ccy + rx * Math.cos(t) * sinP + ry * Math.sin(t) * cosP;
|
|
366
|
+
const dx = (t) => -rx * Math.sin(t) * cosP - ry * Math.cos(t) * sinP;
|
|
367
|
+
const dy = (t) => -rx * Math.sin(t) * sinP + ry * Math.cos(t) * cosP;
|
|
368
|
+
let t0 = th1;
|
|
369
|
+
let p0x = x1;
|
|
370
|
+
let p0y = y1;
|
|
371
|
+
for (let s = 1; s <= slices; s++) {
|
|
372
|
+
const t1 = th1 + delta * s;
|
|
373
|
+
const p1x = s === slices ? x : ex(t1);
|
|
374
|
+
const p1y = s === slices ? y : ey(t1);
|
|
375
|
+
cubic(p0x + alpha * dx(t0), p0y + alpha * dy(t0), p1x - alpha * dx(t1), p1y - alpha * dy(t1), p1x, p1y);
|
|
376
|
+
t0 = t1;
|
|
377
|
+
p0x = p1x;
|
|
378
|
+
p0y = p1y;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
const finish = (closed) => {
|
|
382
|
+
if (closed) line(pts[0], pts[1]);
|
|
383
|
+
if (pts.length < 8) return null;
|
|
384
|
+
return {
|
|
385
|
+
pts: Float64Array.from(pts),
|
|
386
|
+
closed
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
return [
|
|
390
|
+
cubic,
|
|
391
|
+
line,
|
|
392
|
+
quad,
|
|
393
|
+
arc,
|
|
394
|
+
finish
|
|
395
|
+
];
|
|
396
|
+
}
|
|
397
|
+
function lowerSubpath(raw) {
|
|
398
|
+
const [cubic, line, quad, arc, finish] = builder(raw.x0, raw.y0);
|
|
399
|
+
for (const s of raw.segs) switch (s[0]) {
|
|
400
|
+
case "L":
|
|
401
|
+
line(s[1], s[2]);
|
|
402
|
+
break;
|
|
403
|
+
case "C":
|
|
404
|
+
cubic(s[1], s[2], s[3], s[4], s[5], s[6]);
|
|
405
|
+
break;
|
|
406
|
+
case "Q":
|
|
407
|
+
quad(s[1], s[2], s[3], s[4]);
|
|
408
|
+
break;
|
|
409
|
+
case "A":
|
|
410
|
+
arc(s[1], s[2], s[3], s[4], s[5], s[6], s[7]);
|
|
411
|
+
}
|
|
412
|
+
return finish(raw.closed);
|
|
413
|
+
}
|
|
414
|
+
function attrNum(attrs, key, fallback = 0) {
|
|
415
|
+
const v = attrs[key];
|
|
416
|
+
if (v === void 0) return fallback;
|
|
417
|
+
const x = typeof v === "number" ? v : Number(v);
|
|
418
|
+
return Number.isFinite(x) ? x : fallback;
|
|
419
|
+
}
|
|
420
|
+
function parsePoints(v) {
|
|
421
|
+
const s = String(v ?? "").trim();
|
|
422
|
+
if (!s) return [];
|
|
423
|
+
const nums = s.split(/[\s,]+/).map(Number);
|
|
424
|
+
if (nums.some((x) => !Number.isFinite(x))) throw new Error(`morphicons: invalid points: "${s}"`);
|
|
425
|
+
return nums;
|
|
426
|
+
}
|
|
427
|
+
function polyPath(nums, closed) {
|
|
428
|
+
if (nums.length < 4) return null;
|
|
429
|
+
const [, line, , , finish] = builder(nums[0], nums[1]);
|
|
430
|
+
for (let i = 2; i + 1 < nums.length; i += 2) line(nums[i], nums[i + 1]);
|
|
431
|
+
return finish(closed);
|
|
432
|
+
}
|
|
433
|
+
function ellipsePath(cx, cy, rx, ry) {
|
|
434
|
+
if (rx < 1e-12 || ry < 1e-12) return null;
|
|
435
|
+
const kx = KAPPA * rx;
|
|
436
|
+
const ky = KAPPA * ry;
|
|
437
|
+
const e = cx + rx;
|
|
438
|
+
const w = cx - rx;
|
|
439
|
+
const s = cy + ry;
|
|
440
|
+
const n = cy - ry;
|
|
441
|
+
const [cubic, , , , finish] = builder(e, cy);
|
|
442
|
+
cubic(e, cy + ky, cx + kx, s, cx, s);
|
|
443
|
+
cubic(cx - kx, s, w, cy + ky, w, cy);
|
|
444
|
+
cubic(w, cy - ky, cx - kx, n, cx, n);
|
|
445
|
+
cubic(cx + kx, n, e, cy - ky, e, cy);
|
|
446
|
+
return finish(true);
|
|
447
|
+
}
|
|
448
|
+
function rectPath(attrs) {
|
|
449
|
+
const x = attrNum(attrs, "x");
|
|
450
|
+
const y = attrNum(attrs, "y");
|
|
451
|
+
const w = attrNum(attrs, "width");
|
|
452
|
+
const h = attrNum(attrs, "height");
|
|
453
|
+
if (w < 1e-12 || h < 1e-12) return null;
|
|
454
|
+
let rx = attrNum(attrs, "rx", NaN);
|
|
455
|
+
let ry = attrNum(attrs, "ry", NaN);
|
|
456
|
+
if (Number.isNaN(rx)) rx = Number.isNaN(ry) ? 0 : ry;
|
|
457
|
+
if (Number.isNaN(ry)) ry = rx;
|
|
458
|
+
rx = Math.min(Math.max(rx, 0), w / 2);
|
|
459
|
+
ry = Math.min(Math.max(ry, 0), h / 2);
|
|
460
|
+
if (rx < 1e-12 || ry < 1e-12) return polyPath([
|
|
461
|
+
x,
|
|
462
|
+
y,
|
|
463
|
+
x + w,
|
|
464
|
+
y,
|
|
465
|
+
x + w,
|
|
466
|
+
y + h,
|
|
467
|
+
x,
|
|
468
|
+
y + h
|
|
469
|
+
], true);
|
|
470
|
+
const xa = x + rx;
|
|
471
|
+
const xb = x + w - rx;
|
|
472
|
+
const xr = x + w;
|
|
473
|
+
const ya = y + ry;
|
|
474
|
+
const yb = y + h - ry;
|
|
475
|
+
const yd = y + h;
|
|
476
|
+
const kx = KAPPA * rx;
|
|
477
|
+
const ky = KAPPA * ry;
|
|
478
|
+
const [cubic, line, , , finish] = builder(xa, y);
|
|
479
|
+
line(xb, y);
|
|
480
|
+
cubic(xb + kx, y, xr, ya - ky, xr, ya);
|
|
481
|
+
line(xr, yb);
|
|
482
|
+
cubic(xr, yb + ky, xb + kx, yd, xb, yd);
|
|
483
|
+
line(xa, yd);
|
|
484
|
+
cubic(xa - kx, yd, x, yb + ky, x, yb);
|
|
485
|
+
line(x, ya);
|
|
486
|
+
cubic(x, ya - ky, xa - kx, y, xa, y);
|
|
487
|
+
return finish(true);
|
|
488
|
+
}
|
|
489
|
+
function iconToCubics(input) {
|
|
490
|
+
const out = [];
|
|
491
|
+
const push = (p) => {
|
|
492
|
+
if (p) out.push(p);
|
|
493
|
+
};
|
|
494
|
+
if (typeof input === "string") {
|
|
495
|
+
for (const s of parsePath(input)) push(lowerSubpath(s));
|
|
496
|
+
return out;
|
|
497
|
+
}
|
|
498
|
+
for (const [tag, attrs] of input) switch (tag) {
|
|
499
|
+
case "path":
|
|
500
|
+
for (const s of parsePath(String(attrs.d ?? ""))) push(lowerSubpath(s));
|
|
501
|
+
break;
|
|
502
|
+
case "line": {
|
|
503
|
+
const [, line, , , finish] = builder(attrNum(attrs, "x1"), attrNum(attrs, "y1"));
|
|
504
|
+
line(attrNum(attrs, "x2"), attrNum(attrs, "y2"));
|
|
505
|
+
push(finish(false));
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
case "circle": {
|
|
509
|
+
const r = attrNum(attrs, "r");
|
|
510
|
+
push(ellipsePath(attrNum(attrs, "cx"), attrNum(attrs, "cy"), r, r));
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
case "ellipse":
|
|
514
|
+
push(ellipsePath(attrNum(attrs, "cx"), attrNum(attrs, "cy"), attrNum(attrs, "rx"), attrNum(attrs, "ry")));
|
|
515
|
+
break;
|
|
516
|
+
case "rect":
|
|
517
|
+
push(rectPath(attrs));
|
|
518
|
+
break;
|
|
519
|
+
case "polyline":
|
|
520
|
+
push(polyPath(parsePoints(attrs.points), false));
|
|
521
|
+
break;
|
|
522
|
+
case "polygon":
|
|
523
|
+
push(polyPath(parsePoints(attrs.points), true));
|
|
524
|
+
break;
|
|
525
|
+
default:
|
|
526
|
+
throw new Error(`morphicons: unsupported tag <${tag}>`);
|
|
527
|
+
}
|
|
528
|
+
return out;
|
|
529
|
+
}
|
|
530
|
+
var COMMANDS, KAPPA, TAU;
|
|
531
|
+
var init_normalize_CYnN3Npw = __esm({
|
|
532
|
+
"node_modules/morphicons/dist/normalize-CYnN3Npw.js"() {
|
|
533
|
+
COMMANDS = "MmLlHhVvCcSsQqTtAaZz";
|
|
534
|
+
KAPPA = 4 / 3 * Math.tan(Math.PI / 8);
|
|
535
|
+
TAU = 2 * Math.PI;
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// node_modules/morphicons/dist/resample-CXlaZ5ZQ.js
|
|
540
|
+
function centroid(p) {
|
|
541
|
+
const n = p.length / 2;
|
|
542
|
+
let cx = 0;
|
|
543
|
+
let cy = 0;
|
|
544
|
+
for (let i = 0; i < n; i++) {
|
|
545
|
+
cx += p[2 * i];
|
|
546
|
+
cy += p[2 * i + 1];
|
|
547
|
+
}
|
|
548
|
+
return [cx / n, cy / n];
|
|
549
|
+
}
|
|
550
|
+
function polyLen(p) {
|
|
551
|
+
const n = p.length / 2;
|
|
552
|
+
let L = 0;
|
|
553
|
+
for (let i = 1; i < n; i++) L += Math.hypot(p[2 * i] - p[2 * i - 2], p[2 * i + 1] - p[2 * i - 1]);
|
|
554
|
+
return L;
|
|
555
|
+
}
|
|
556
|
+
function reversePts(p) {
|
|
557
|
+
const n = p.length / 2;
|
|
558
|
+
const out = new Float64Array(2 * n);
|
|
559
|
+
for (let i = 0; i < n; i++) {
|
|
560
|
+
out[2 * i] = p[2 * (n - 1 - i)];
|
|
561
|
+
out[2 * i + 1] = p[2 * (n - 1 - i) + 1];
|
|
562
|
+
}
|
|
563
|
+
return out;
|
|
564
|
+
}
|
|
565
|
+
function rotatePts(p, off) {
|
|
566
|
+
const n = p.length / 2;
|
|
567
|
+
const out = new Float64Array(2 * n);
|
|
568
|
+
for (let i = 0; i < n; i++) {
|
|
569
|
+
const j = (i + off) % n;
|
|
570
|
+
out[2 * i] = p[2 * j];
|
|
571
|
+
out[2 * i + 1] = p[2 * j + 1];
|
|
572
|
+
}
|
|
573
|
+
return out;
|
|
574
|
+
}
|
|
575
|
+
function procrustes(a, b, ca, cb) {
|
|
576
|
+
const n = a.length / 2;
|
|
577
|
+
let sxx = 0;
|
|
578
|
+
let sxy = 0;
|
|
579
|
+
let syx = 0;
|
|
580
|
+
let syy = 0;
|
|
581
|
+
let na = 0;
|
|
582
|
+
let nb = 0;
|
|
583
|
+
for (let i = 0; i < n; i++) {
|
|
584
|
+
const ax = a[2 * i] - ca[0];
|
|
585
|
+
const ay = a[2 * i + 1] - ca[1];
|
|
586
|
+
const bx = b[2 * i] - cb[0];
|
|
587
|
+
const by = b[2 * i + 1] - cb[1];
|
|
588
|
+
sxx += ax * bx;
|
|
589
|
+
syy += ay * by;
|
|
590
|
+
sxy += ax * by;
|
|
591
|
+
syx += ay * bx;
|
|
592
|
+
na += ax * ax + ay * ay;
|
|
593
|
+
nb += bx * bx + by * by;
|
|
594
|
+
}
|
|
595
|
+
const theta = Math.atan2(sxy - syx, sxx + syy);
|
|
596
|
+
const num2 = Math.cos(theta) * (sxx + syy) + Math.sin(theta) * (sxy - syx);
|
|
597
|
+
let sigma = na > 1e-12 ? num2 / na : 1;
|
|
598
|
+
if (!(sigma > 1e-6)) sigma = 1e-6;
|
|
599
|
+
const res2 = Math.max(0, sigma * sigma * na - 2 * sigma * num2 + nb);
|
|
600
|
+
const res = nb > 1e-12 ? Math.sqrt(res2 / nb) : 0;
|
|
601
|
+
return {
|
|
602
|
+
theta,
|
|
603
|
+
sigma,
|
|
604
|
+
res
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
function alignPair(aPts, bPts, aClosed = false, bClosed = false, allowReverse = true, lambda = LAMBDA) {
|
|
608
|
+
const ca = centroid(aPts);
|
|
609
|
+
const cb = centroid(bPts);
|
|
610
|
+
const varyA = aClosed && !bClosed;
|
|
611
|
+
const base = varyA ? aPts : bPts;
|
|
612
|
+
const offs = aClosed || bClosed ? base.length / 2 : 1;
|
|
613
|
+
let bestScore = Number.POSITIVE_INFINITY;
|
|
614
|
+
let best = base;
|
|
615
|
+
let sim = {
|
|
616
|
+
theta: 0,
|
|
617
|
+
sigma: 1,
|
|
618
|
+
res: 0
|
|
619
|
+
};
|
|
620
|
+
for (let dir = 0; dir < (allowReverse ? 2 : 1); dir++) {
|
|
621
|
+
const walk = dir ? reversePts(base) : base;
|
|
622
|
+
for (let off = 0; off < offs; off++) {
|
|
623
|
+
const cand = off ? rotatePts(walk, off) : walk;
|
|
624
|
+
const s = varyA ? procrustes(cand, bPts, ca, cb) : procrustes(aPts, cand, ca, cb);
|
|
625
|
+
const score = s.res + lambda * Math.abs(s.theta) / Math.PI;
|
|
626
|
+
if (score < bestScore) {
|
|
627
|
+
bestScore = score;
|
|
628
|
+
best = cand;
|
|
629
|
+
sim = s;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return varyA ? {
|
|
634
|
+
ca,
|
|
635
|
+
cb,
|
|
636
|
+
a: best,
|
|
637
|
+
b: bPts,
|
|
638
|
+
...sim
|
|
639
|
+
} : {
|
|
640
|
+
ca,
|
|
641
|
+
cb,
|
|
642
|
+
a: aPts,
|
|
643
|
+
b: best,
|
|
644
|
+
...sim
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
function costMatrix(A, B) {
|
|
648
|
+
const cbs = B.map(centroid);
|
|
649
|
+
const lbs = B.map(polyLen);
|
|
650
|
+
return A.map((a) => {
|
|
651
|
+
const ca = centroid(a);
|
|
652
|
+
const la = polyLen(a);
|
|
653
|
+
return cbs.map((cb, j) => Math.hypot(ca[0] - cb[0], ca[1] - cb[1]) + LEN_WEIGHT * Math.abs(la - lbs[j]));
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
function bestPermutation(C) {
|
|
657
|
+
const n = C.length;
|
|
658
|
+
if (n > PERM_MAX) {
|
|
659
|
+
const pairs = [];
|
|
660
|
+
for (let i = 0; i < n; i++) for (let j = 0; j < n; j++) pairs.push([
|
|
661
|
+
C[i][j],
|
|
662
|
+
i,
|
|
663
|
+
j
|
|
664
|
+
]);
|
|
665
|
+
pairs.sort((x, y) => x[0] - y[0]);
|
|
666
|
+
const out = new Array(n).fill(-1);
|
|
667
|
+
const used = new Array(n).fill(false);
|
|
668
|
+
for (const [, i, j] of pairs) if (out[i] < 0 && !used[j]) {
|
|
669
|
+
out[i] = j;
|
|
670
|
+
used[j] = true;
|
|
671
|
+
}
|
|
672
|
+
return out;
|
|
673
|
+
}
|
|
674
|
+
const idx = Array.from({ length: n }, (_, i) => i);
|
|
675
|
+
let best = idx.slice();
|
|
676
|
+
let bc = Number.POSITIVE_INFINITY;
|
|
677
|
+
const perm = (arr, k, acc) => {
|
|
678
|
+
if (acc >= bc) return;
|
|
679
|
+
if (k === n) {
|
|
680
|
+
bc = acc;
|
|
681
|
+
best = arr.slice();
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
for (let i = k; i < n; i++) {
|
|
685
|
+
[arr[k], arr[i]] = [arr[i], arr[k]];
|
|
686
|
+
perm(arr, k + 1, acc + C[k][arr[k]]);
|
|
687
|
+
[arr[k], arr[i]] = [arr[i], arr[k]];
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
perm(idx, 0, 0);
|
|
691
|
+
return best;
|
|
692
|
+
}
|
|
693
|
+
function bestSurjection(C) {
|
|
694
|
+
const B = C.length;
|
|
695
|
+
const S = C[0].length;
|
|
696
|
+
if (S ** B > 1e5) {
|
|
697
|
+
const f2 = C.map((row) => {
|
|
698
|
+
let m = 0;
|
|
699
|
+
for (let j = 1; j < row.length; j++) if (row[j] < row[m]) m = j;
|
|
700
|
+
return m;
|
|
701
|
+
});
|
|
702
|
+
const mult2 = new Array(S).fill(0);
|
|
703
|
+
for (const s of f2) mult2[s]++;
|
|
704
|
+
for (let s = 0; s < S; s++) {
|
|
705
|
+
if (mult2[s] > 0) continue;
|
|
706
|
+
let bi = -1;
|
|
707
|
+
let bc2 = Number.POSITIVE_INFINITY;
|
|
708
|
+
for (let i = 0; i < B; i++) {
|
|
709
|
+
if (mult2[f2[i]] < 2) continue;
|
|
710
|
+
const extra = C[i][s] - C[i][f2[i]];
|
|
711
|
+
if (extra < bc2) {
|
|
712
|
+
bc2 = extra;
|
|
713
|
+
bi = i;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
mult2[f2[bi]]--;
|
|
717
|
+
f2[bi] = s;
|
|
718
|
+
mult2[s]++;
|
|
719
|
+
}
|
|
720
|
+
return f2;
|
|
721
|
+
}
|
|
722
|
+
let best = null;
|
|
723
|
+
let bc = Number.POSITIVE_INFINITY;
|
|
724
|
+
const f = new Array(B);
|
|
725
|
+
const mult = new Array(S).fill(0);
|
|
726
|
+
const rec = (i, acc, covered) => {
|
|
727
|
+
if (acc >= bc || S - covered > B - i) return;
|
|
728
|
+
if (i === B) {
|
|
729
|
+
bc = acc;
|
|
730
|
+
best = f.slice();
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
for (let s = 0; s < S; s++) {
|
|
734
|
+
f[i] = s;
|
|
735
|
+
mult[s]++;
|
|
736
|
+
rec(i + 1, acc + C[i][s], covered + (mult[s] === 1 ? 1 : 0));
|
|
737
|
+
mult[s]--;
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
rec(0, 0, 0);
|
|
741
|
+
if (!best) throw new Error("morphicons: no valid surjection (B < S)");
|
|
742
|
+
return best;
|
|
743
|
+
}
|
|
744
|
+
function applyGlobal(items, n) {
|
|
745
|
+
const T = items.length * n;
|
|
746
|
+
const ga = new Float64Array(2 * T);
|
|
747
|
+
const gb = new Float64Array(2 * T);
|
|
748
|
+
items.forEach((it, k) => {
|
|
749
|
+
ga.set(it.a, 2 * n * k);
|
|
750
|
+
gb.set(it.bO, 2 * n * k);
|
|
751
|
+
});
|
|
752
|
+
const gca = centroid(ga);
|
|
753
|
+
const g = procrustes(ga, gb, gca, centroid(gb));
|
|
754
|
+
if (g.res >= GLOBAL_EPS) return;
|
|
755
|
+
const cos = Math.cos(-g.theta);
|
|
756
|
+
const sin = Math.sin(-g.theta);
|
|
757
|
+
const rc = Math.cos(g.theta);
|
|
758
|
+
const rs = Math.sin(g.theta);
|
|
759
|
+
for (const it of items) {
|
|
760
|
+
let e2 = 0;
|
|
761
|
+
let nb = 0;
|
|
762
|
+
for (let i = 0; i < n; i++) {
|
|
763
|
+
const bx = it.bO[2 * i] - it.cb[0];
|
|
764
|
+
const by = it.bO[2 * i + 1] - it.cb[1];
|
|
765
|
+
it.bT[2 * i] = (bx * cos - by * sin) / g.sigma;
|
|
766
|
+
it.bT[2 * i + 1] = (bx * sin + by * cos) / g.sigma;
|
|
767
|
+
const ex = g.sigma * (rc * it.aC[2 * i] - rs * it.aC[2 * i + 1]) - bx;
|
|
768
|
+
const ey = g.sigma * (rs * it.aC[2 * i] + rc * it.aC[2 * i + 1]) - by;
|
|
769
|
+
e2 += ex * ex + ey * ey;
|
|
770
|
+
nb += bx * bx + by * by;
|
|
771
|
+
}
|
|
772
|
+
it.theta = g.theta;
|
|
773
|
+
it.lnSigma = Math.log(g.sigma);
|
|
774
|
+
it.res = nb > 1e-12 ? Math.sqrt(e2 / nb) : 0;
|
|
775
|
+
const s1 = Math.exp(it.lnSigma);
|
|
776
|
+
const c1 = Math.cos(it.theta) * s1;
|
|
777
|
+
const n1 = Math.sin(it.theta) * s1;
|
|
778
|
+
const ox = it.ca[0] - gca[0];
|
|
779
|
+
const oy = it.ca[1] - gca[1];
|
|
780
|
+
const rx = ox * c1 - oy * n1 - ox;
|
|
781
|
+
const ry = ox * n1 + oy * c1 - oy;
|
|
782
|
+
it.block = {
|
|
783
|
+
off: [ox, oy],
|
|
784
|
+
drift: [it.cb[0] - it.ca[0] - rx, it.cb[1] - it.ca[1] - ry]
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
function pairUp(A, B) {
|
|
789
|
+
const p = A.length;
|
|
790
|
+
const q = B.length;
|
|
791
|
+
const pairs = [];
|
|
792
|
+
if (p === q) {
|
|
793
|
+
const perm = bestPermutation(costMatrix(A, B));
|
|
794
|
+
for (let i = 0; i < p; i++) pairs.push([i, perm[i]]);
|
|
795
|
+
} else if (p < q) {
|
|
796
|
+
const f = bestSurjection(costMatrix(B, A));
|
|
797
|
+
for (let j = 0; j < q; j++) pairs.push([f[j], j]);
|
|
798
|
+
} else {
|
|
799
|
+
const f = bestSurjection(costMatrix(A, B));
|
|
800
|
+
for (let i = 0; i < p; i++) pairs.push([i, f[i]]);
|
|
801
|
+
}
|
|
802
|
+
return pairs;
|
|
803
|
+
}
|
|
804
|
+
function makeItem(aPts, bPts, aClosed, bClosed, allowReverse, lambda) {
|
|
805
|
+
const n = aPts.length / 2;
|
|
806
|
+
const al = alignPair(aPts, bPts, aClosed, bClosed, allowReverse, lambda);
|
|
807
|
+
const a = al.a;
|
|
808
|
+
const aC = new Float64Array(2 * n);
|
|
809
|
+
const bT = new Float64Array(2 * n);
|
|
810
|
+
const bO = new Float64Array(2 * n);
|
|
811
|
+
const cos = Math.cos(-al.theta);
|
|
812
|
+
const sin = Math.sin(-al.theta);
|
|
813
|
+
for (let i = 0; i < n; i++) {
|
|
814
|
+
aC[2 * i] = a[2 * i] - al.ca[0];
|
|
815
|
+
aC[2 * i + 1] = a[2 * i + 1] - al.ca[1];
|
|
816
|
+
const bx = al.b[2 * i] - al.cb[0];
|
|
817
|
+
const by = al.b[2 * i + 1] - al.cb[1];
|
|
818
|
+
bT[2 * i] = (bx * cos - by * sin) / al.sigma;
|
|
819
|
+
bT[2 * i + 1] = (bx * sin + by * cos) / al.sigma;
|
|
820
|
+
bO[2 * i] = al.b[2 * i];
|
|
821
|
+
bO[2 * i + 1] = al.b[2 * i + 1];
|
|
822
|
+
}
|
|
823
|
+
return {
|
|
824
|
+
a,
|
|
825
|
+
aC,
|
|
826
|
+
bT,
|
|
827
|
+
bO,
|
|
828
|
+
ca: al.ca,
|
|
829
|
+
cb: al.cb,
|
|
830
|
+
theta: al.theta,
|
|
831
|
+
lnSigma: Math.log(al.sigma),
|
|
832
|
+
res: al.res,
|
|
833
|
+
closed: aClosed && bClosed,
|
|
834
|
+
block: null
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
function buildPlan(srcSubs, dstSubs) {
|
|
838
|
+
const p = srcSubs.length;
|
|
839
|
+
const q = dstSubs.length;
|
|
840
|
+
if (p === 0 || q === 0) throw new Error("morphicons: icon has no subpaths");
|
|
841
|
+
const A = srcSubs.map((s) => s.pts);
|
|
842
|
+
const B = dstSubs.map((s) => s.pts);
|
|
843
|
+
const items = pairUp(A, B).map(([si, di]) => makeItem(A[si], B[di], srcSubs[si].closed, dstSubs[di].closed, true));
|
|
844
|
+
if (items.length > 1) applyGlobal(items, A[0].length / 2);
|
|
845
|
+
return {
|
|
846
|
+
items,
|
|
847
|
+
n: A[0].length / 2
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
function speed(p, k, t) {
|
|
851
|
+
const i = 6 * k;
|
|
852
|
+
const u = 1 - t;
|
|
853
|
+
const c0 = 3 * u * u;
|
|
854
|
+
const c1 = 6 * u * t;
|
|
855
|
+
const c2 = 3 * t * t;
|
|
856
|
+
const dx = c0 * (p[i + 2] - p[i]) + c1 * (p[i + 4] - p[i + 2]) + c2 * (p[i + 6] - p[i + 4]);
|
|
857
|
+
const dy = c0 * (p[i + 3] - p[i + 1]) + c1 * (p[i + 5] - p[i + 3]) + c2 * (p[i + 7] - p[i + 5]);
|
|
858
|
+
return Math.hypot(dx, dy);
|
|
859
|
+
}
|
|
860
|
+
function segLen(p, k, t1 = 1) {
|
|
861
|
+
const half = t1 / 2;
|
|
862
|
+
let s = 0;
|
|
863
|
+
for (let j = 0; j < 4; j++) s += GW[j] * (speed(p, k, half + half * GX[j]) + speed(p, k, half - half * GX[j]));
|
|
864
|
+
return s * half;
|
|
865
|
+
}
|
|
866
|
+
function point(p, k, t, out, o) {
|
|
867
|
+
const i = 6 * k;
|
|
868
|
+
const u = 1 - t;
|
|
869
|
+
const b0 = u * u * u;
|
|
870
|
+
const b1 = 3 * u * u * t;
|
|
871
|
+
const b2 = 3 * u * t * t;
|
|
872
|
+
const b3 = t * t * t;
|
|
873
|
+
out[o] = b0 * p[i] + b1 * p[i + 2] + b2 * p[i + 4] + b3 * p[i + 6];
|
|
874
|
+
out[o + 1] = b0 * p[i + 1] + b1 * p[i + 3] + b2 * p[i + 5] + b3 * p[i + 7];
|
|
875
|
+
}
|
|
876
|
+
function tangent(p, k, atEnd) {
|
|
877
|
+
const i = 6 * k;
|
|
878
|
+
const b = atEnd ? i + 6 : i;
|
|
879
|
+
const s = atEnd ? -1 : 1;
|
|
880
|
+
for (const j of atEnd ? [
|
|
881
|
+
4,
|
|
882
|
+
2,
|
|
883
|
+
0
|
|
884
|
+
] : [
|
|
885
|
+
2,
|
|
886
|
+
4,
|
|
887
|
+
6
|
|
888
|
+
]) {
|
|
889
|
+
const dx = s * (p[i + j] - p[b]);
|
|
890
|
+
const dy = s * (p[i + j + 1] - p[b + 1]);
|
|
891
|
+
if (dx * dx + dy * dy > 1e-18) return [dx, dy];
|
|
892
|
+
}
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
function detectCorners(path, threshold = CORNER_THRESHOLD) {
|
|
896
|
+
const p = path.pts;
|
|
897
|
+
const m = (p.length / 2 - 1) / 3;
|
|
898
|
+
const active = [];
|
|
899
|
+
for (let k = 0; k < m; k++) if (segLen(p, k) > 1e-9) active.push(k);
|
|
900
|
+
if (active.length === 0) return [];
|
|
901
|
+
const corners = /* @__PURE__ */ new Set();
|
|
902
|
+
const test = (a, b) => {
|
|
903
|
+
const u = tangent(p, a, true);
|
|
904
|
+
const v = tangent(p, b, false);
|
|
905
|
+
if (!u || !v) return;
|
|
906
|
+
if (Math.abs(Math.atan2(u[0] * v[1] - u[1] * v[0], u[0] * v[0] + u[1] * v[1])) > threshold) corners.add(b);
|
|
907
|
+
};
|
|
908
|
+
for (let j = 0; j + 1 < active.length; j++) test(active[j], active[j + 1]);
|
|
909
|
+
if (path.closed && active.length > 1) test(active[active.length - 1], active[0]);
|
|
910
|
+
return [...corners].sort((a, b) => a - b);
|
|
911
|
+
}
|
|
912
|
+
function invert(p, k, s, ls) {
|
|
913
|
+
if (s <= 0) return 0;
|
|
914
|
+
if (s >= ls) return 1;
|
|
915
|
+
let lo = 0;
|
|
916
|
+
let hi = 1;
|
|
917
|
+
let t = s / ls;
|
|
918
|
+
for (let it = 0; it < 12; it++) {
|
|
919
|
+
const f = segLen(p, k, t) - s;
|
|
920
|
+
if (Math.abs(f) < 1e-10 * ls + 1e-14) break;
|
|
921
|
+
if (f > 0) hi = t;
|
|
922
|
+
else lo = t;
|
|
923
|
+
const sp = speed(p, k, t);
|
|
924
|
+
let nt = sp > 1e-12 ? t - f / sp : (lo + hi) / 2;
|
|
925
|
+
if (!(nt > lo && nt < hi)) nt = (lo + hi) / 2;
|
|
926
|
+
t = nt;
|
|
927
|
+
}
|
|
928
|
+
return t;
|
|
929
|
+
}
|
|
930
|
+
function resamplePath(path, N = 64, cornerThreshold = CORNER_THRESHOLD) {
|
|
931
|
+
const p = path.pts;
|
|
932
|
+
const m = (p.length / 2 - 1) / 3;
|
|
933
|
+
const out = new Float64Array(2 * N);
|
|
934
|
+
const fill = () => {
|
|
935
|
+
for (let i = 0; i < N; i++) {
|
|
936
|
+
out[2 * i] = p[0];
|
|
937
|
+
out[2 * i + 1] = p[1];
|
|
938
|
+
}
|
|
939
|
+
return out;
|
|
940
|
+
};
|
|
941
|
+
if (m < 1) return fill();
|
|
942
|
+
const lens = new Array(m);
|
|
943
|
+
let L = 0;
|
|
944
|
+
for (let k = 0; k < m; k++) {
|
|
945
|
+
lens[k] = segLen(p, k);
|
|
946
|
+
L += lens[k];
|
|
947
|
+
}
|
|
948
|
+
if (L < 1e-12) return fill();
|
|
949
|
+
const cs = detectCorners(path, cornerThreshold);
|
|
950
|
+
const anchors = path.closed ? cs.length > 0 ? cs : [0] : [.../* @__PURE__ */ new Set([
|
|
951
|
+
0,
|
|
952
|
+
...cs,
|
|
953
|
+
m
|
|
954
|
+
])].sort((a, b) => a - b);
|
|
955
|
+
const runs = [];
|
|
956
|
+
if (path.closed) for (let j = 0; j < anchors.length; j++) {
|
|
957
|
+
const a = anchors[j];
|
|
958
|
+
const b = j + 1 < anchors.length ? anchors[j + 1] : anchors[0] + m;
|
|
959
|
+
runs.push([a, b]);
|
|
960
|
+
}
|
|
961
|
+
else for (let j = 0; j + 1 < anchors.length; j++) runs.push([anchors[j], anchors[j + 1]]);
|
|
962
|
+
const rl = runs.map(([a, b]) => {
|
|
963
|
+
let s = 0;
|
|
964
|
+
for (let k = a; k < b; k++) s += lens[k % m];
|
|
965
|
+
return s;
|
|
966
|
+
});
|
|
967
|
+
const intervals = path.closed ? N : N - 1;
|
|
968
|
+
if (runs.length > intervals) throw new Error(`morphicons: N=${N} too small (${runs.length} runs)`);
|
|
969
|
+
const total = rl.reduce((a, b) => a + b, 0) || 1;
|
|
970
|
+
const ideal = rl.map((l) => intervals * l / total);
|
|
971
|
+
const counts = ideal.map((q) => Math.max(1, Math.floor(q)));
|
|
972
|
+
let R = intervals - counts.reduce((a, b) => a + b, 0);
|
|
973
|
+
if (R > 0) {
|
|
974
|
+
const order = ideal.map((q, idx) => [Math.round((q - Math.floor(q)) * 1e9), idx]).sort((a, b) => b[0] - a[0] || a[1] - b[1]);
|
|
975
|
+
for (let j = 0; j < R; j++) counts[order[j % counts.length][1]]++;
|
|
976
|
+
}
|
|
977
|
+
while (R < 0) {
|
|
978
|
+
let bi = 0;
|
|
979
|
+
for (let idx = 1; idx < counts.length; idx++) if (counts[idx] > counts[bi]) bi = idx;
|
|
980
|
+
if (counts[bi] <= 1) break;
|
|
981
|
+
counts[bi]--;
|
|
982
|
+
R++;
|
|
983
|
+
}
|
|
984
|
+
let w = 0;
|
|
985
|
+
for (let r = 0; r < runs.length; r++) {
|
|
986
|
+
const [k0, k1] = runs[r];
|
|
987
|
+
const cnt = counts[r];
|
|
988
|
+
const Lr = rl[r];
|
|
989
|
+
const vi = 6 * (k0 % m);
|
|
990
|
+
out[2 * w] = p[vi];
|
|
991
|
+
out[2 * w + 1] = p[vi + 1];
|
|
992
|
+
w++;
|
|
993
|
+
let seg = k0;
|
|
994
|
+
let acc = 0;
|
|
995
|
+
for (let j = 1; j < cnt; j++) {
|
|
996
|
+
const target = Lr * j / cnt;
|
|
997
|
+
while (seg < k1 - 1 && acc + lens[seg % m] < target) {
|
|
998
|
+
acc += lens[seg % m];
|
|
999
|
+
seg++;
|
|
1000
|
+
}
|
|
1001
|
+
const k = seg % m;
|
|
1002
|
+
const ls = lens[k];
|
|
1003
|
+
point(p, k, ls > 1e-12 ? invert(p, k, target - acc, ls) : 0, out, 2 * w);
|
|
1004
|
+
w++;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
if (!path.closed) {
|
|
1008
|
+
const vi = 6 * m;
|
|
1009
|
+
out[2 * w] = p[vi];
|
|
1010
|
+
out[2 * w + 1] = p[vi + 1];
|
|
1011
|
+
}
|
|
1012
|
+
return out;
|
|
1013
|
+
}
|
|
1014
|
+
function resampleIcon(input, N = 64) {
|
|
1015
|
+
return iconToCubics(input).map((path) => ({
|
|
1016
|
+
pts: resamplePath(path, N),
|
|
1017
|
+
closed: path.closed
|
|
1018
|
+
}));
|
|
1019
|
+
}
|
|
1020
|
+
var LEN_WEIGHT, LAMBDA, GLOBAL_EPS, PERM_MAX, CORNER_THRESHOLD, GX, GW;
|
|
1021
|
+
var init_resample_CXlaZ5ZQ = __esm({
|
|
1022
|
+
"node_modules/morphicons/dist/resample-CXlaZ5ZQ.js"() {
|
|
1023
|
+
init_normalize_CYnN3Npw();
|
|
1024
|
+
LEN_WEIGHT = 0.35;
|
|
1025
|
+
LAMBDA = 0.05;
|
|
1026
|
+
GLOBAL_EPS = 5e-3;
|
|
1027
|
+
PERM_MAX = 8;
|
|
1028
|
+
CORNER_THRESHOLD = Math.PI / 8;
|
|
1029
|
+
GX = [
|
|
1030
|
+
0.18343464249564978,
|
|
1031
|
+
0.525532409916329,
|
|
1032
|
+
0.7966664774136267,
|
|
1033
|
+
0.9602898564975363
|
|
1034
|
+
];
|
|
1035
|
+
GW = [
|
|
1036
|
+
0.362683783378362,
|
|
1037
|
+
0.31370664587788727,
|
|
1038
|
+
0.22238103445337448,
|
|
1039
|
+
0.10122853629037626
|
|
1040
|
+
];
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
|
|
1044
|
+
// node_modules/morphicons/dist/region-BjECuWZR.js
|
|
1045
|
+
function paintOf(icon) {
|
|
1046
|
+
if (typeof icon === "string") return "stroke";
|
|
1047
|
+
for (const [, a] of icon) if (painted(a.fill)) return "fill";
|
|
1048
|
+
return "stroke";
|
|
1049
|
+
}
|
|
1050
|
+
function solid(icon) {
|
|
1051
|
+
return typeof icon === "string" || paintOf(icon) === "stroke" ? icon : icon.filter(([, a]) => !translucent(a));
|
|
1052
|
+
}
|
|
1053
|
+
function isRegion(icon) {
|
|
1054
|
+
return typeof icon !== "string" && icon.length === 1 && "data-region" in icon[0][1];
|
|
1055
|
+
}
|
|
1056
|
+
function inside(px, py, p) {
|
|
1057
|
+
const n = p.length / 2;
|
|
1058
|
+
let c = false;
|
|
1059
|
+
for (let i = 0, j = n - 1; i < n; j = i++) {
|
|
1060
|
+
const yi = p[2 * i + 1];
|
|
1061
|
+
const yj = p[2 * j + 1];
|
|
1062
|
+
if (yi > py !== yj > py && px < (p[2 * j] - p[2 * i]) * (py - yi) / (yj - yi) + p[2 * i]) c = !c;
|
|
1063
|
+
}
|
|
1064
|
+
return c;
|
|
1065
|
+
}
|
|
1066
|
+
function distSeg(px, py, ax, ay, bx, by) {
|
|
1067
|
+
const dx = bx - ax;
|
|
1068
|
+
const dy = by - ay;
|
|
1069
|
+
const l2 = dx * dx + dy * dy;
|
|
1070
|
+
let t = l2 > 0 ? ((px - ax) * dx + (py - ay) * dy) / l2 : 0;
|
|
1071
|
+
t = t < 0 ? 0 : t > 1 ? 1 : t;
|
|
1072
|
+
const ex = px - ax - t * dx;
|
|
1073
|
+
const ey = py - ay - t * dy;
|
|
1074
|
+
return Math.sqrt(ex * ex + ey * ey);
|
|
1075
|
+
}
|
|
1076
|
+
function signedArea(p) {
|
|
1077
|
+
const n = p.length / 2;
|
|
1078
|
+
let a = 0;
|
|
1079
|
+
for (let i = 0, j = n - 1; i < n; j = i++) a += p[2 * j] * p[2 * i + 1] - p[2 * i] * p[2 * j + 1];
|
|
1080
|
+
return a / 2;
|
|
1081
|
+
}
|
|
1082
|
+
var REGION_ATTR, painted, translucent;
|
|
1083
|
+
var init_region_BjECuWZR = __esm({
|
|
1084
|
+
"node_modules/morphicons/dist/region-BjECuWZR.js"() {
|
|
1085
|
+
REGION_ATTR = "data-region";
|
|
1086
|
+
painted = (v) => v !== void 0 && String(v).trim().toLowerCase() !== "none";
|
|
1087
|
+
translucent = (a) => Number.parseFloat(String(a.opacity)) < 0.5 || Number.parseFloat(String(a["fill-opacity"])) < 0.5;
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
|
|
1091
|
+
// node_modules/morphicons/dist/region.js
|
|
1092
|
+
var region_exports = {};
|
|
1093
|
+
__export(region_exports, {
|
|
1094
|
+
buildRegionPlan: () => buildRegionPlan,
|
|
1095
|
+
isRegion: () => isRegion,
|
|
1096
|
+
paintOf: () => paintOf,
|
|
1097
|
+
regionContours: () => regionContours,
|
|
1098
|
+
regionOf: () => regionOf,
|
|
1099
|
+
regionPlan: () => regionPlan,
|
|
1100
|
+
regionPlanFrom: () => regionPlanFrom,
|
|
1101
|
+
resampleRegion: () => resampleRegion,
|
|
1102
|
+
toRegion: () => toRegion
|
|
1103
|
+
});
|
|
1104
|
+
function coarse(path, s) {
|
|
1105
|
+
const n = s.length / 2;
|
|
1106
|
+
let j = 0;
|
|
1107
|
+
for (let v = 0; v < path.length; v += 6) for (let k = 0; ; k++) {
|
|
1108
|
+
if (k === n) return true;
|
|
1109
|
+
const a = (j + k) % n;
|
|
1110
|
+
const b = (a + 1) % n;
|
|
1111
|
+
if (distSeg(path[v], path[v + 1], s[2 * a], s[2 * a + 1], s[2 * b], s[2 * b + 1]) <= FINE) {
|
|
1112
|
+
j = a;
|
|
1113
|
+
break;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
return false;
|
|
1117
|
+
}
|
|
1118
|
+
function resampleRegion(icon, N) {
|
|
1119
|
+
const paths = iconToCubics(icon);
|
|
1120
|
+
const at = (n) => paths.map((path) => {
|
|
1121
|
+
let pts;
|
|
1122
|
+
for (const th of REGION_THRESHOLDS) try {
|
|
1123
|
+
pts = resamplePath({
|
|
1124
|
+
pts: path.pts,
|
|
1125
|
+
closed: true
|
|
1126
|
+
}, n, th);
|
|
1127
|
+
break;
|
|
1128
|
+
} catch {
|
|
1129
|
+
}
|
|
1130
|
+
const s2 = pts;
|
|
1131
|
+
return {
|
|
1132
|
+
pts: s2,
|
|
1133
|
+
closed: true,
|
|
1134
|
+
hole: signedArea(s2) < 0
|
|
1135
|
+
};
|
|
1136
|
+
});
|
|
1137
|
+
const s = at(N ?? 64);
|
|
1138
|
+
return N || !paths.some((p, k) => coarse(p.pts, s[k].pts)) ? s : at(128);
|
|
1139
|
+
}
|
|
1140
|
+
function folds(a, b) {
|
|
1141
|
+
const L = a.length;
|
|
1142
|
+
const p = new Float64Array(L);
|
|
1143
|
+
for (let i = 0; i < L; i++) p[i] = (a[i] + b[i]) / 2;
|
|
1144
|
+
for (let i = 0; i < L; i += 2) {
|
|
1145
|
+
const ax = p[i];
|
|
1146
|
+
const ay = p[i + 1];
|
|
1147
|
+
const ux = p[(i + 2) % L] - ax;
|
|
1148
|
+
const uy = p[(i + 3) % L] - ay;
|
|
1149
|
+
for (let j = i + 4; j < L - (i ? 0 : 2); j += 2) {
|
|
1150
|
+
const cx = p[j];
|
|
1151
|
+
const cy = p[j + 1];
|
|
1152
|
+
const vx = p[(j + 2) % L] - cx;
|
|
1153
|
+
const vy = p[(j + 3) % L] - cy;
|
|
1154
|
+
if ((ux * (cy - ay) - uy * (cx - ax)) * (ux * (cy + vy - ay) - uy * (cx + vx - ax)) >= 0) continue;
|
|
1155
|
+
if ((vx * (ay - cy) - vy * (ax - cx)) * (vx * (ay + uy - cy) - vy * (ax + ux - cx)) < 0) return true;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
return false;
|
|
1159
|
+
}
|
|
1160
|
+
function outerItem(a, b) {
|
|
1161
|
+
const n = a.length / 2;
|
|
1162
|
+
const k = n > 64 ? 2 : 1;
|
|
1163
|
+
const half = (p, o) => k > 1 ? p.filter((_, i) => (i >> 1) % 2 === o) : p;
|
|
1164
|
+
const as = half(a, 0);
|
|
1165
|
+
const ca = centroid(as);
|
|
1166
|
+
const bs = [half(b, 0), half(b, 1)];
|
|
1167
|
+
const cbs = bs.map(centroid);
|
|
1168
|
+
const offs = [];
|
|
1169
|
+
for (let off = 0; off < n; off++) {
|
|
1170
|
+
const j = off % k;
|
|
1171
|
+
const s = procrustes(as, rotatePts(bs[j], (off - j) / k), ca, cbs[j]);
|
|
1172
|
+
offs.push([off, s.res + REGION_LAMBDA * Math.abs(s.theta) / Math.PI]);
|
|
1173
|
+
}
|
|
1174
|
+
offs.sort((x, y) => x[1] - y[1]);
|
|
1175
|
+
let best;
|
|
1176
|
+
for (const [off, score] of offs.slice(0, FOLD_TRIES)) {
|
|
1177
|
+
if (score > offs[0][1] + FOLD_SLACK) break;
|
|
1178
|
+
const it = makeItem(a, rotatePts(b, off), false, false, false, REGION_LAMBDA);
|
|
1179
|
+
it.closed = true;
|
|
1180
|
+
best ?? (best = it);
|
|
1181
|
+
if (!folds(half(it.aC, 0), half(it.bT, 0))) return it;
|
|
1182
|
+
}
|
|
1183
|
+
return best;
|
|
1184
|
+
}
|
|
1185
|
+
function parentOf(hole, subs) {
|
|
1186
|
+
const n = hole.length / 2;
|
|
1187
|
+
let best = -1;
|
|
1188
|
+
let bestArea = Infinity;
|
|
1189
|
+
subs.forEach((s, k) => {
|
|
1190
|
+
if (s.hole) return;
|
|
1191
|
+
let votes = 0;
|
|
1192
|
+
for (const v of [
|
|
1193
|
+
0,
|
|
1194
|
+
Math.floor(n / 3),
|
|
1195
|
+
Math.floor(2 * n / 3)
|
|
1196
|
+
]) if (inside(hole[2 * v], hole[2 * v + 1], s.pts)) votes++;
|
|
1197
|
+
if (votes < 2) return;
|
|
1198
|
+
const ar = Math.abs(signedArea(s.pts));
|
|
1199
|
+
if (ar < bestArea) {
|
|
1200
|
+
bestArea = ar;
|
|
1201
|
+
best = k;
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
return best;
|
|
1205
|
+
}
|
|
1206
|
+
function assign(C, skip, one, cover) {
|
|
1207
|
+
const L = C.length;
|
|
1208
|
+
const S = one.length;
|
|
1209
|
+
const f = new Array(L).fill(-1);
|
|
1210
|
+
const mult = new Array(S).fill(0);
|
|
1211
|
+
if ((S + 1) ** L > 1e5) {
|
|
1212
|
+
const pairs = [];
|
|
1213
|
+
for (let i = 0; i < L; i++) for (let j = 0; j < S; j++) if (C[i][j] < Infinity) pairs.push([
|
|
1214
|
+
C[i][j],
|
|
1215
|
+
i,
|
|
1216
|
+
j
|
|
1217
|
+
]);
|
|
1218
|
+
pairs.sort((x, y) => x[0] - y[0]);
|
|
1219
|
+
for (const [, i, j] of pairs) if (f[i] < 0 && !mult[j]) {
|
|
1220
|
+
f[i] = j;
|
|
1221
|
+
mult[j] = 1;
|
|
1222
|
+
}
|
|
1223
|
+
for (let i = 0; i < L; i++) {
|
|
1224
|
+
if (f[i] >= 0) continue;
|
|
1225
|
+
for (let j = 0; j < S; j++) if (!one[j] && (f[i] < 0 || C[i][j] < C[i][f[i]])) f[i] = j;
|
|
1226
|
+
}
|
|
1227
|
+
return f;
|
|
1228
|
+
}
|
|
1229
|
+
let best = f.slice();
|
|
1230
|
+
let bc = Infinity;
|
|
1231
|
+
const rec = (i, acc, covered) => {
|
|
1232
|
+
if (acc >= bc || cover && S - covered > L - i) return;
|
|
1233
|
+
if (i === L) {
|
|
1234
|
+
bc = acc;
|
|
1235
|
+
best = f.slice();
|
|
1236
|
+
return;
|
|
1237
|
+
}
|
|
1238
|
+
for (let j = 0; j < S; j++) {
|
|
1239
|
+
if (one[j] && mult[j] || !(C[i][j] < Infinity)) continue;
|
|
1240
|
+
f[i] = j;
|
|
1241
|
+
mult[j]++;
|
|
1242
|
+
rec(i + 1, acc + C[i][j], covered + (mult[j] === 1 ? 1 : 0));
|
|
1243
|
+
mult[j]--;
|
|
1244
|
+
}
|
|
1245
|
+
f[i] = -1;
|
|
1246
|
+
rec(i + 1, acc + skip[i], covered);
|
|
1247
|
+
};
|
|
1248
|
+
rec(0, 0, 0);
|
|
1249
|
+
return best;
|
|
1250
|
+
}
|
|
1251
|
+
function carry(x, y, from, to, theta, s) {
|
|
1252
|
+
const c = Math.cos(theta) * s;
|
|
1253
|
+
const n = Math.sin(theta) * s;
|
|
1254
|
+
const dx = x - from[0];
|
|
1255
|
+
const dy = y - from[1];
|
|
1256
|
+
return [to[0] + dx * c - dy * n, to[1] + dx * n + dy * c];
|
|
1257
|
+
}
|
|
1258
|
+
function dots(c, n) {
|
|
1259
|
+
const d = new Float64Array(2 * n);
|
|
1260
|
+
for (let i = 0; i < 2 * n; i += 2) {
|
|
1261
|
+
d[i] = c[0];
|
|
1262
|
+
d[i + 1] = c[1];
|
|
1263
|
+
}
|
|
1264
|
+
return d;
|
|
1265
|
+
}
|
|
1266
|
+
function inFrame(a, b, f, hole, half) {
|
|
1267
|
+
const n = a.length / 2;
|
|
1268
|
+
const s = Math.exp(f.lnSigma);
|
|
1269
|
+
const aC = new Float64Array(2 * n);
|
|
1270
|
+
const bt = new Float64Array(2 * n);
|
|
1271
|
+
let nb = 0;
|
|
1272
|
+
for (let i = 0; i < 2 * n; i += 2) {
|
|
1273
|
+
aC[i] = a[i] - f.ca[0];
|
|
1274
|
+
aC[i + 1] = a[i + 1] - f.ca[1];
|
|
1275
|
+
[bt[i], bt[i + 1]] = carry(b[i], b[i + 1], f.cb, [0, 0], -f.theta, 1 / s);
|
|
1276
|
+
nb += (b[i] - f.cb[0]) ** 2 + (b[i + 1] - f.cb[1]) ** 2;
|
|
1277
|
+
}
|
|
1278
|
+
let off = 0;
|
|
1279
|
+
let be = Infinity;
|
|
1280
|
+
for (let o = 0; o < n && be > 0; o++) {
|
|
1281
|
+
let e = 0;
|
|
1282
|
+
for (let i = 0; i < n && e < be; i++) {
|
|
1283
|
+
const j = (i + o) % n;
|
|
1284
|
+
e += (aC[2 * i] - bt[2 * j]) ** 2 + (aC[2 * i + 1] - bt[2 * j + 1]) ** 2;
|
|
1285
|
+
}
|
|
1286
|
+
if (e < be) {
|
|
1287
|
+
be = e;
|
|
1288
|
+
off = o;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
return {
|
|
1292
|
+
a,
|
|
1293
|
+
aC,
|
|
1294
|
+
bT: rotatePts(bt, off),
|
|
1295
|
+
bO: rotatePts(b, off),
|
|
1296
|
+
ca: f.ca,
|
|
1297
|
+
cb: f.cb,
|
|
1298
|
+
theta: f.theta,
|
|
1299
|
+
lnSigma: f.lnSigma,
|
|
1300
|
+
res: nb > 1e-12 ? Math.sqrt(s * s * be / nb) : 0,
|
|
1301
|
+
closed: true,
|
|
1302
|
+
hole,
|
|
1303
|
+
half,
|
|
1304
|
+
block: f.block
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
function vanishingHole(pts, outer, grow) {
|
|
1308
|
+
const s = Math.exp(outer.lnSigma);
|
|
1309
|
+
let [x, y] = centroid(pts);
|
|
1310
|
+
const { aC, bT } = outer;
|
|
1311
|
+
const near = grow ? outer.bO : outer.a;
|
|
1312
|
+
let w = 0;
|
|
1313
|
+
let dx = 0;
|
|
1314
|
+
let dy = 0;
|
|
1315
|
+
for (let i = 0; i < aC.length; i += 2) {
|
|
1316
|
+
const k = 1 / ((near[i] - x) ** 2 + (near[i + 1] - y) ** 2 + 1e-9);
|
|
1317
|
+
w += k;
|
|
1318
|
+
dx += k * (bT[i] - aC[i]);
|
|
1319
|
+
dy += k * (bT[i + 1] - aC[i + 1]);
|
|
1320
|
+
}
|
|
1321
|
+
w = (grow ? -0.5 : 0.5) / w;
|
|
1322
|
+
if (grow) [x, y] = carry(x, y, outer.cb, outer.ca, -outer.theta, 1 / s);
|
|
1323
|
+
x += w * dx;
|
|
1324
|
+
y += w * dy;
|
|
1325
|
+
const dot = dots(grow ? [x, y] : carry(x, y, outer.ca, outer.cb, outer.theta, s), pts.length / 2);
|
|
1326
|
+
return grow ? inFrame(dot, pts, outer, true, 1) : inFrame(pts, dot, outer, true, 0);
|
|
1327
|
+
}
|
|
1328
|
+
function strays(h, o, holes) {
|
|
1329
|
+
let k = 0;
|
|
1330
|
+
for (const t of [
|
|
1331
|
+
0.25,
|
|
1332
|
+
0.5,
|
|
1333
|
+
0.75
|
|
1334
|
+
]) {
|
|
1335
|
+
if (!(weight(h, t) % 1)) continue;
|
|
1336
|
+
const [H, O, ...G] = [
|
|
1337
|
+
h,
|
|
1338
|
+
o,
|
|
1339
|
+
...holes.filter((g) => g !== h)
|
|
1340
|
+
].map((it) => it.aC.map((v, i) => v + weight(it, t) * (it.bT[i] - v)));
|
|
1341
|
+
for (let i = 0; i < H.length; i += 2) if (!inside(H[i], H[i + 1], O) || G.some((p) => inside(H[i], H[i + 1], p))) k++;
|
|
1342
|
+
}
|
|
1343
|
+
return k;
|
|
1344
|
+
}
|
|
1345
|
+
function vanishingPiece(outer, holes, grow) {
|
|
1346
|
+
const c = centroid(outer);
|
|
1347
|
+
const f = {
|
|
1348
|
+
ca: c,
|
|
1349
|
+
cb: c,
|
|
1350
|
+
theta: 0,
|
|
1351
|
+
lnSigma: 0,
|
|
1352
|
+
block: null
|
|
1353
|
+
};
|
|
1354
|
+
const dot = dots(c, outer.length / 2);
|
|
1355
|
+
return [outer, ...holes].map((p, k) => grow ? inFrame(dot, p, f, k > 0) : inFrame(p, dot, f, k > 0));
|
|
1356
|
+
}
|
|
1357
|
+
function bbox(p) {
|
|
1358
|
+
const b = [
|
|
1359
|
+
p[0],
|
|
1360
|
+
p[1],
|
|
1361
|
+
p[0],
|
|
1362
|
+
p[1]
|
|
1363
|
+
];
|
|
1364
|
+
for (let i = 2; i < p.length; i += 2) {
|
|
1365
|
+
b[0] = Math.min(b[0], p[i]);
|
|
1366
|
+
b[1] = Math.min(b[1], p[i + 1]);
|
|
1367
|
+
b[2] = Math.max(b[2], p[i]);
|
|
1368
|
+
b[3] = Math.max(b[3], p[i + 1]);
|
|
1369
|
+
}
|
|
1370
|
+
return b;
|
|
1371
|
+
}
|
|
1372
|
+
function holeCosts(HA, HB, outer) {
|
|
1373
|
+
const s = Math.exp(outer.lnSigma);
|
|
1374
|
+
const C = costMatrix(HA, HB);
|
|
1375
|
+
const inA = HB.map((h) => {
|
|
1376
|
+
const q = new Float64Array(h.length);
|
|
1377
|
+
for (let i = 0; i < h.length; i += 2) [q[i], q[i + 1]] = carry(h[i], h[i + 1], outer.cb, outer.ca, -outer.theta, 1 / s);
|
|
1378
|
+
return bbox(q);
|
|
1379
|
+
});
|
|
1380
|
+
HA.forEach((h, i) => {
|
|
1381
|
+
const a = bbox(h);
|
|
1382
|
+
inA.forEach((b, j) => {
|
|
1383
|
+
const w = Math.min(a[2], b[2]) - Math.max(a[0], b[0]);
|
|
1384
|
+
const v = Math.min(a[3], b[3]) - Math.max(a[1], b[1]);
|
|
1385
|
+
const inter = w > 0 && v > 0 ? w * v : 0;
|
|
1386
|
+
const union = (a[2] - a[0]) * (a[3] - a[1]) + (b[2] - b[0]) * (b[3] - b[1]) - inter;
|
|
1387
|
+
if (!(inter >= HOLE_IOU * union)) C[i][j] = Infinity;
|
|
1388
|
+
});
|
|
1389
|
+
});
|
|
1390
|
+
return C;
|
|
1391
|
+
}
|
|
1392
|
+
function piecesOf(subs) {
|
|
1393
|
+
const idx = [];
|
|
1394
|
+
subs.forEach((s, k) => {
|
|
1395
|
+
if (!s.hole) idx.push(k);
|
|
1396
|
+
});
|
|
1397
|
+
const holes = idx.map(() => []);
|
|
1398
|
+
subs.forEach((s) => {
|
|
1399
|
+
if (!s.hole) return;
|
|
1400
|
+
let k = idx.indexOf(parentOf(s.pts, subs));
|
|
1401
|
+
if (k < 0) {
|
|
1402
|
+
const [hx, hy] = centroid(s.pts);
|
|
1403
|
+
let bd = Infinity;
|
|
1404
|
+
idx.forEach((o, m) => {
|
|
1405
|
+
const [ox, oy] = centroid(subs[o].pts);
|
|
1406
|
+
const d = Math.hypot(ox - hx, oy - hy);
|
|
1407
|
+
if (d < bd) {
|
|
1408
|
+
bd = d;
|
|
1409
|
+
k = m;
|
|
1410
|
+
}
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
holes[k].push(s.pts);
|
|
1414
|
+
});
|
|
1415
|
+
return {
|
|
1416
|
+
outers: idx.map((k) => subs[k].pts),
|
|
1417
|
+
holes
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
function doubled(p) {
|
|
1421
|
+
const m = p.length;
|
|
1422
|
+
const q = new Float64Array(2 * m);
|
|
1423
|
+
for (let i = 0; i < m; i += 2) {
|
|
1424
|
+
const j = (i + 2) % m;
|
|
1425
|
+
q[2 * i] = p[i];
|
|
1426
|
+
q[2 * i + 1] = p[i + 1];
|
|
1427
|
+
q[2 * i + 2] = (p[i] + p[j]) / 2;
|
|
1428
|
+
q[2 * i + 3] = (p[i + 1] + p[j + 1]) / 2;
|
|
1429
|
+
}
|
|
1430
|
+
return q;
|
|
1431
|
+
}
|
|
1432
|
+
function buildRegionPlan(srcSubs, dstSubs) {
|
|
1433
|
+
const n = Math.max(srcSubs[0].pts.length, dstSubs[0].pts.length) / 2;
|
|
1434
|
+
const fit = (s) => s[0].pts.length / 2 < n ? s.map((c) => ({
|
|
1435
|
+
...c,
|
|
1436
|
+
pts: doubled(c.pts)
|
|
1437
|
+
})) : s;
|
|
1438
|
+
const A = piecesOf(fit(srcSubs));
|
|
1439
|
+
const B = piecesOf(fit(dstSubs));
|
|
1440
|
+
if (A.outers.length === 0 || B.outers.length === 0) throw new Error("morphicons: region has no outer contour");
|
|
1441
|
+
let pairs;
|
|
1442
|
+
const p = A.outers.length;
|
|
1443
|
+
const q = B.outers.length;
|
|
1444
|
+
const [large, small] = p < q ? [B, A] : [A, B];
|
|
1445
|
+
if (p === q || small.holes.every((h) => h.length === 0)) pairs = pairUp(A.outers, B.outers);
|
|
1446
|
+
else pairs = assign(costMatrix(large.outers, small.outers), large.outers.map((o) => SKIP + vanishCost(o)), small.holes.map((h) => h.length > 0), true).map((s, l) => p < q ? [s, l] : [l, s]);
|
|
1447
|
+
const items = [];
|
|
1448
|
+
let partial = false;
|
|
1449
|
+
for (const [i, j] of pairs) {
|
|
1450
|
+
if (i < 0 || j < 0) {
|
|
1451
|
+
partial = true;
|
|
1452
|
+
items.push(...i < 0 ? vanishingPiece(B.outers[j], B.holes[j], true) : vanishingPiece(A.outers[i], A.holes[i], false));
|
|
1453
|
+
continue;
|
|
1454
|
+
}
|
|
1455
|
+
const it = outerItem(A.outers[i], B.outers[j]);
|
|
1456
|
+
it.hole = false;
|
|
1457
|
+
items.push(it);
|
|
1458
|
+
const HA = A.holes[i];
|
|
1459
|
+
const HB = B.holes[j];
|
|
1460
|
+
const f = assign(holeCosts(HA, HB, it), HA.map(() => SKIP), HB.map(() => true), false);
|
|
1461
|
+
const holes = HA.map((h, k) => f[k] < 0 ? vanishingHole(h, it, false) : inFrame(h, HB[f[k]], it, true));
|
|
1462
|
+
HB.forEach((h, k) => {
|
|
1463
|
+
if (!f.includes(k)) holes.push(vanishingHole(h, it, true));
|
|
1464
|
+
});
|
|
1465
|
+
for (let k = 0; k < holes.length; k++) {
|
|
1466
|
+
const h = holes[k];
|
|
1467
|
+
if (h.half !== void 0) {
|
|
1468
|
+
partial = true;
|
|
1469
|
+
continue;
|
|
1470
|
+
}
|
|
1471
|
+
const c = strays(h, it, holes);
|
|
1472
|
+
if (!c) continue;
|
|
1473
|
+
holes.splice(k, 1, vanishingHole(h.a, it, false), vanishingHole(h.bO, it, true));
|
|
1474
|
+
if (strays(holes[k], it, holes) + strays(holes[k + 1], it, holes) >= c) holes.splice(k, 2, h);
|
|
1475
|
+
}
|
|
1476
|
+
items.push(...holes);
|
|
1477
|
+
}
|
|
1478
|
+
if (items.length > 1 && !partial) applyGlobal(items, n);
|
|
1479
|
+
return {
|
|
1480
|
+
items,
|
|
1481
|
+
n
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
function flatten(input, tol) {
|
|
1485
|
+
const lines = [];
|
|
1486
|
+
const closed = [];
|
|
1487
|
+
for (const { pts, closed: c } of iconToCubics(input)) {
|
|
1488
|
+
const out = [pts[0], pts[1]];
|
|
1489
|
+
for (let i = 0; i + 7 < pts.length; i += 6) {
|
|
1490
|
+
const x0 = pts[i];
|
|
1491
|
+
const y0 = pts[i + 1];
|
|
1492
|
+
const x1 = pts[i + 2];
|
|
1493
|
+
const y1 = pts[i + 3];
|
|
1494
|
+
const x2 = pts[i + 4];
|
|
1495
|
+
const y2 = pts[i + 5];
|
|
1496
|
+
const x3 = pts[i + 6];
|
|
1497
|
+
const y3 = pts[i + 7];
|
|
1498
|
+
const dd = Math.max(Math.hypot(x0 - 2 * x1 + x2, y0 - 2 * y1 + y2), Math.hypot(x1 - 2 * x2 + x3, y1 - 2 * y2 + y3));
|
|
1499
|
+
const k = Math.min(128, Math.max(1, Math.ceil(Math.sqrt(6 * dd / (8 * tol)))));
|
|
1500
|
+
for (let s = 1; s <= k; s++) {
|
|
1501
|
+
const t = s / k;
|
|
1502
|
+
const u = 1 - t;
|
|
1503
|
+
out.push(u * u * u * x0 + 3 * u * u * t * x1 + 3 * u * t * t * x2 + t * t * t * x3, u * u * u * y0 + 3 * u * u * t * y1 + 3 * u * t * t * y2 + t * t * t * y3);
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
lines.push(Float64Array.from(out));
|
|
1507
|
+
closed.push(c);
|
|
1508
|
+
}
|
|
1509
|
+
return {
|
|
1510
|
+
lines,
|
|
1511
|
+
closed
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
function partsOf(input, width, tol) {
|
|
1515
|
+
if (typeof input === "string") return [{
|
|
1516
|
+
...flatten(input, tol),
|
|
1517
|
+
half: width / 2,
|
|
1518
|
+
fill: 0
|
|
1519
|
+
}];
|
|
1520
|
+
const fillIcon = paintOf(input) === "fill";
|
|
1521
|
+
const parts = [];
|
|
1522
|
+
for (const el of input) {
|
|
1523
|
+
const a = el[1];
|
|
1524
|
+
if (translucent(a)) continue;
|
|
1525
|
+
const strokeOn = fillIcon ? painted2(a.stroke) : a.stroke === void 0 || painted2(a.stroke);
|
|
1526
|
+
const fillOn = fillIcon && (painted2(a.fill) || a.fill === void 0 && !strokeOn);
|
|
1527
|
+
if (!strokeOn && !fillOn) continue;
|
|
1528
|
+
parts.push({
|
|
1529
|
+
...flatten([el], tol),
|
|
1530
|
+
half: strokeOn ? num(a["stroke-width"], width) / 2 : 0,
|
|
1531
|
+
fill: fillOn ? String(a["fill-rule"] ?? "").trim() === "evenodd" ? 2 : 1 : 0
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
return parts;
|
|
1535
|
+
}
|
|
1536
|
+
function eachNear(g, ax, ay, bx, by, r, fn) {
|
|
1537
|
+
const i0 = Math.max(0, Math.floor((Math.min(ax, bx) - r - g.x0) / g.h));
|
|
1538
|
+
const i1 = Math.min(g.nx - 1, Math.ceil((Math.max(ax, bx) + r - g.x0) / g.h));
|
|
1539
|
+
const j0 = Math.max(0, Math.floor((Math.min(ay, by) - r - g.y0) / g.h));
|
|
1540
|
+
const j1 = Math.min(g.ny - 1, Math.ceil((Math.max(ay, by) + r - g.y0) / g.h));
|
|
1541
|
+
for (let j = j0; j <= j1; j++) {
|
|
1542
|
+
const y = g.y0 + j * g.h;
|
|
1543
|
+
for (let i = i0; i <= i1; i++) fn(j * g.nx + i, g.x0 + i * g.h, y);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
function eachSeg(p, close, fn) {
|
|
1547
|
+
const n = p.length / 2;
|
|
1548
|
+
if (n === 1) fn(p[0], p[1], p[0], p[1]);
|
|
1549
|
+
for (let i = 0; i + 1 < n; i++) fn(p[2 * i], p[2 * i + 1], p[2 * i + 2], p[2 * i + 3]);
|
|
1550
|
+
if (close && n > 2) fn(p[2 * n - 2], p[2 * n - 1], p[0], p[1]);
|
|
1551
|
+
}
|
|
1552
|
+
function field(parts, g) {
|
|
1553
|
+
const F = new Float32Array(g.nx * g.ny).fill(BIG);
|
|
1554
|
+
const band = 2 * g.h;
|
|
1555
|
+
let D = null;
|
|
1556
|
+
for (const part of parts) {
|
|
1557
|
+
if (part.half > 0) {
|
|
1558
|
+
const r = part.half + band;
|
|
1559
|
+
part.lines.forEach((p, li) => {
|
|
1560
|
+
eachSeg(p, part.closed[li], (ax, ay, bx, by) => eachNear(g, ax, ay, bx, by, r, (k, x, y) => {
|
|
1561
|
+
const d = distSeg(x, y, ax, ay, bx, by) - part.half;
|
|
1562
|
+
if (d < F[k]) F[k] = d;
|
|
1563
|
+
}));
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
if (part.fill) {
|
|
1567
|
+
D ?? (D = new Float32Array(g.nx * g.ny));
|
|
1568
|
+
const Dm = D;
|
|
1569
|
+
Dm.fill(BIG);
|
|
1570
|
+
for (const p of part.lines) eachSeg(p, true, (ax, ay, bx, by) => eachNear(g, ax, ay, bx, by, band, (k, x, y) => {
|
|
1571
|
+
const d = distSeg(x, y, ax, ay, bx, by);
|
|
1572
|
+
if (d < Dm[k]) Dm[k] = d;
|
|
1573
|
+
}));
|
|
1574
|
+
const xs = [];
|
|
1575
|
+
const ws = [];
|
|
1576
|
+
for (let j = 0; j < g.ny; j++) {
|
|
1577
|
+
const y = g.y0 + j * g.h;
|
|
1578
|
+
const cross = [];
|
|
1579
|
+
for (const p of part.lines) eachSeg(p, true, (ax, ay, bx, by) => {
|
|
1580
|
+
if (ay <= y !== by <= y) cross.push([ax + (y - ay) * (bx - ax) / (by - ay), by > ay ? 1 : -1]);
|
|
1581
|
+
});
|
|
1582
|
+
cross.sort((u, v) => u[0] - v[0]);
|
|
1583
|
+
xs.length = 0;
|
|
1584
|
+
ws.length = 0;
|
|
1585
|
+
for (const [x, w] of cross) {
|
|
1586
|
+
xs.push(x);
|
|
1587
|
+
ws.push(w);
|
|
1588
|
+
}
|
|
1589
|
+
let c = 0;
|
|
1590
|
+
let wind = 0;
|
|
1591
|
+
for (let i = 0; i < g.nx; i++) {
|
|
1592
|
+
const x = g.x0 + i * g.h;
|
|
1593
|
+
while (c < xs.length && xs[c] < x) wind += ws[c++];
|
|
1594
|
+
const isIn = part.fill === 1 ? wind !== 0 : (wind & 1) === 1;
|
|
1595
|
+
const k = j * g.nx + i;
|
|
1596
|
+
const v = isIn ? -Dm[k] : Dm[k];
|
|
1597
|
+
if (v < F[k]) F[k] = v;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
return F;
|
|
1603
|
+
}
|
|
1604
|
+
function trace(F, g) {
|
|
1605
|
+
const { nx, ny, h, x0, y0 } = g;
|
|
1606
|
+
const pt = /* @__PURE__ */ new Map();
|
|
1607
|
+
const crossing = (key) => {
|
|
1608
|
+
if (pt.has(key)) return key;
|
|
1609
|
+
const node = key >> 1;
|
|
1610
|
+
const i = node % nx;
|
|
1611
|
+
const j = (node - i) / nx;
|
|
1612
|
+
const other = key & 1 ? node + nx : node + 1;
|
|
1613
|
+
const fa = F[node];
|
|
1614
|
+
const t = Math.min(Math.max(fa / (fa - F[other]), 1e-5), 0.99999);
|
|
1615
|
+
pt.set(key, key & 1 ? [x0 + i * h, y0 + (j + t) * h] : [x0 + (i + t) * h, y0 + j * h]);
|
|
1616
|
+
return key;
|
|
1617
|
+
};
|
|
1618
|
+
const adj = /* @__PURE__ */ new Map();
|
|
1619
|
+
const link = (a, b) => {
|
|
1620
|
+
const ka = crossing(a);
|
|
1621
|
+
const kb = crossing(b);
|
|
1622
|
+
const la = adj.get(ka);
|
|
1623
|
+
if (la) la.push(kb);
|
|
1624
|
+
else adj.set(ka, [kb]);
|
|
1625
|
+
const lb = adj.get(kb);
|
|
1626
|
+
if (lb) lb.push(ka);
|
|
1627
|
+
else adj.set(kb, [ka]);
|
|
1628
|
+
};
|
|
1629
|
+
for (let j = 0; j + 1 < ny; j++) for (let i = 0; i + 1 < nx; i++) {
|
|
1630
|
+
const a = j * nx + i;
|
|
1631
|
+
const b = a + 1;
|
|
1632
|
+
const c = a + nx + 1;
|
|
1633
|
+
const d = a + nx;
|
|
1634
|
+
const ia = F[a] < 0;
|
|
1635
|
+
const ib = F[b] < 0;
|
|
1636
|
+
const ic = F[c] < 0;
|
|
1637
|
+
const id = F[d] < 0;
|
|
1638
|
+
const top = 2 * a;
|
|
1639
|
+
const right = 2 * b + 1;
|
|
1640
|
+
const bottom = 2 * d;
|
|
1641
|
+
const left = 2 * a + 1;
|
|
1642
|
+
const edges = [];
|
|
1643
|
+
if (ia !== ib) edges.push(top);
|
|
1644
|
+
if (ib !== ic) edges.push(right);
|
|
1645
|
+
if (id !== ic) edges.push(bottom);
|
|
1646
|
+
if (ia !== id) edges.push(left);
|
|
1647
|
+
if (edges.length === 2) link(edges[0], edges[1]);
|
|
1648
|
+
else if (edges.length === 4) {
|
|
1649
|
+
if ((F[a] + F[b] + F[c] + F[d]) / 4 < 0 === ia) {
|
|
1650
|
+
link(top, right);
|
|
1651
|
+
link(bottom, left);
|
|
1652
|
+
} else {
|
|
1653
|
+
link(left, top);
|
|
1654
|
+
link(right, bottom);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
const loops = [];
|
|
1659
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1660
|
+
for (const start of adj.keys()) {
|
|
1661
|
+
if (seen.has(start)) continue;
|
|
1662
|
+
const ring = [];
|
|
1663
|
+
let prev = -1;
|
|
1664
|
+
let cur = start;
|
|
1665
|
+
while (!seen.has(cur)) {
|
|
1666
|
+
seen.add(cur);
|
|
1667
|
+
const p = pt.get(cur);
|
|
1668
|
+
ring.push(p[0], p[1]);
|
|
1669
|
+
const nb = adj.get(cur);
|
|
1670
|
+
const next = nb[0] !== prev ? nb[0] : nb[1];
|
|
1671
|
+
prev = cur;
|
|
1672
|
+
cur = next;
|
|
1673
|
+
}
|
|
1674
|
+
if (ring.length >= 6) loops.push(Float64Array.from(ring));
|
|
1675
|
+
}
|
|
1676
|
+
return loops;
|
|
1677
|
+
}
|
|
1678
|
+
function rdp(p, i0, i1, tol, keep) {
|
|
1679
|
+
const n = p.length / 2;
|
|
1680
|
+
const ax = p[2 * (i0 % n)];
|
|
1681
|
+
const ay = p[2 * (i0 % n) + 1];
|
|
1682
|
+
const bx = p[2 * (i1 % n)];
|
|
1683
|
+
const by = p[2 * (i1 % n) + 1];
|
|
1684
|
+
let worst = -1;
|
|
1685
|
+
let wd = tol;
|
|
1686
|
+
for (let i = i0 + 1; i < i1; i++) {
|
|
1687
|
+
const d = distSeg(p[2 * (i % n)], p[2 * (i % n) + 1], ax, ay, bx, by);
|
|
1688
|
+
if (d > wd) {
|
|
1689
|
+
wd = d;
|
|
1690
|
+
worst = i;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
if (worst < 0) return;
|
|
1694
|
+
keep[worst % n] = 1;
|
|
1695
|
+
rdp(p, i0, worst, tol, keep);
|
|
1696
|
+
rdp(p, worst, i1, tol, keep);
|
|
1697
|
+
}
|
|
1698
|
+
function simplify(p, tol) {
|
|
1699
|
+
const n = p.length / 2;
|
|
1700
|
+
if (n < 4) return p;
|
|
1701
|
+
let far = 0;
|
|
1702
|
+
let fd = -1;
|
|
1703
|
+
for (let i = 1; i < n; i++) {
|
|
1704
|
+
const d = Math.hypot(p[2 * i] - p[0], p[2 * i + 1] - p[1]);
|
|
1705
|
+
if (d > fd) {
|
|
1706
|
+
fd = d;
|
|
1707
|
+
far = i;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
const keep = new Uint8Array(n);
|
|
1711
|
+
keep[0] = 1;
|
|
1712
|
+
keep[far] = 1;
|
|
1713
|
+
rdp(p, 0, far, tol, keep);
|
|
1714
|
+
rdp(p, far, n, tol, keep);
|
|
1715
|
+
const out = [];
|
|
1716
|
+
for (let i = 0; i < n; i++) if (keep[i]) out.push(p[2 * i], p[2 * i + 1]);
|
|
1717
|
+
return Float64Array.from(out);
|
|
1718
|
+
}
|
|
1719
|
+
function recoverCorners(p, h) {
|
|
1720
|
+
const n = p.length / 2;
|
|
1721
|
+
if (n < 4) return p;
|
|
1722
|
+
const len = (k) => {
|
|
1723
|
+
const a = k % n;
|
|
1724
|
+
const b = (k + 1) % n;
|
|
1725
|
+
return Math.hypot(p[2 * b] - p[2 * a], p[2 * b + 1] - p[2 * a + 1]);
|
|
1726
|
+
};
|
|
1727
|
+
const long = [];
|
|
1728
|
+
for (let k = 0; k < n; k++) if (len(k) >= 2.5 * h) long.push(k);
|
|
1729
|
+
if (long.length < 2) return p;
|
|
1730
|
+
const drop = new Uint8Array(n);
|
|
1731
|
+
const moved = /* @__PURE__ */ new Map();
|
|
1732
|
+
for (let q = 0; q < long.length; q++) {
|
|
1733
|
+
const k1 = long[q];
|
|
1734
|
+
const k2 = long[(q + 1) % long.length];
|
|
1735
|
+
const gap = (k2 - k1 - 1 + n) % n;
|
|
1736
|
+
if (gap < 1 || gap > 3) continue;
|
|
1737
|
+
let gl = 0;
|
|
1738
|
+
for (let s = 1; s <= gap; s++) gl += len(k1 + s);
|
|
1739
|
+
if (gl > 3 * h) continue;
|
|
1740
|
+
const a0 = k1 % n;
|
|
1741
|
+
const a1 = (k1 + 1) % n;
|
|
1742
|
+
const b0 = k2 % n;
|
|
1743
|
+
const b1 = (k2 + 1) % n;
|
|
1744
|
+
const d1x = p[2 * a1] - p[2 * a0];
|
|
1745
|
+
const d1y = p[2 * a1 + 1] - p[2 * a0 + 1];
|
|
1746
|
+
const d2x = p[2 * b1] - p[2 * b0];
|
|
1747
|
+
const d2y = p[2 * b1 + 1] - p[2 * b0 + 1];
|
|
1748
|
+
const cr = d1x * d2y - d1y * d2x;
|
|
1749
|
+
if (Math.abs(Math.atan2(cr, d1x * d2x + d1y * d2y)) < Math.PI / 12) continue;
|
|
1750
|
+
const t = ((p[2 * b0] - p[2 * a0]) * d2y - (p[2 * b0 + 1] - p[2 * a0 + 1]) * d2x) / cr;
|
|
1751
|
+
const X = [p[2 * a0] + t * d1x, p[2 * a0 + 1] + t * d1y];
|
|
1752
|
+
const mx = (p[2 * a1] + p[2 * b0]) / 2;
|
|
1753
|
+
const my = (p[2 * a1 + 1] + p[2 * b0 + 1]) / 2;
|
|
1754
|
+
if (Math.hypot(X[0] - mx, X[1] - my) > 2 * h) continue;
|
|
1755
|
+
moved.set(a1, X);
|
|
1756
|
+
for (let s = 2; s <= gap + 1; s++) drop[(k1 + s) % n] = 1;
|
|
1757
|
+
}
|
|
1758
|
+
if (moved.size === 0) return p;
|
|
1759
|
+
const out = [];
|
|
1760
|
+
for (let i = 0; i < n; i++) {
|
|
1761
|
+
if (drop[i]) continue;
|
|
1762
|
+
const m = moved.get(i);
|
|
1763
|
+
if (m) out.push(m[0], m[1]);
|
|
1764
|
+
else out.push(p[2 * i], p[2 * i + 1]);
|
|
1765
|
+
}
|
|
1766
|
+
return Float64Array.from(out);
|
|
1767
|
+
}
|
|
1768
|
+
function regionContours(input, options) {
|
|
1769
|
+
const h = options?.cell ?? 0.125;
|
|
1770
|
+
const parts = partsOf(input, options?.strokeWidth ?? 2, 4e-3);
|
|
1771
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
1772
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
1773
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
1774
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
1775
|
+
let pad = 0;
|
|
1776
|
+
for (const part of parts) {
|
|
1777
|
+
pad = Math.max(pad, part.half);
|
|
1778
|
+
for (const p of part.lines) for (let i = 0; i < p.length; i += 2) {
|
|
1779
|
+
minX = Math.min(minX, p[i]);
|
|
1780
|
+
maxX = Math.max(maxX, p[i]);
|
|
1781
|
+
minY = Math.min(minY, p[i + 1]);
|
|
1782
|
+
maxY = Math.max(maxY, p[i + 1]);
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
if (!(maxX >= minX)) return [];
|
|
1786
|
+
pad += 3 * h;
|
|
1787
|
+
const g = {
|
|
1788
|
+
x0: minX - pad,
|
|
1789
|
+
y0: minY - pad,
|
|
1790
|
+
h,
|
|
1791
|
+
nx: Math.ceil((maxX - minX + 2 * pad) / h) + 1,
|
|
1792
|
+
ny: Math.ceil((maxY - minY + 2 * pad) / h) + 1
|
|
1793
|
+
};
|
|
1794
|
+
const loops = trace(field(parts, g), g).filter((l) => Math.abs(signedArea(l)) > 0.01);
|
|
1795
|
+
return loops.map((l) => {
|
|
1796
|
+
let depth = 0;
|
|
1797
|
+
for (const o of loops) if (o !== l && inside(l[0], l[1], o)) depth++;
|
|
1798
|
+
const hole = depth % 2 === 1;
|
|
1799
|
+
return recoverCorners(simplify(signedArea(l) > 0 === !hole ? l : reversePts(l), h * 0.08), h);
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
function toRegion(input, options) {
|
|
1803
|
+
if (isRegion(input)) return input;
|
|
1804
|
+
let d = "";
|
|
1805
|
+
for (const p of regionContours(input, options)) {
|
|
1806
|
+
d += `M${fmt2(p[0])} ${fmt2(p[1])}`;
|
|
1807
|
+
for (let i = 2; i < p.length; i += 2) d += `L${fmt2(p[i])} ${fmt2(p[i + 1])}`;
|
|
1808
|
+
d += "Z";
|
|
1809
|
+
}
|
|
1810
|
+
if (!d) throw new Error("morphicons: icon has no visible surface");
|
|
1811
|
+
return [["path", {
|
|
1812
|
+
d,
|
|
1813
|
+
fill: "currentColor",
|
|
1814
|
+
stroke: "none",
|
|
1815
|
+
"fill-rule": "nonzero",
|
|
1816
|
+
[REGION_ATTR]: "1"
|
|
1817
|
+
}]];
|
|
1818
|
+
}
|
|
1819
|
+
function regionOf(icon, strokeWidth) {
|
|
1820
|
+
if (isRegion(icon)) return icon;
|
|
1821
|
+
const width = paintOf(icon) === "fill" && !icon.some(([, a]) => painted2(a.stroke) && a["stroke-width"] === void 0) ? 0 : strokeWidth;
|
|
1822
|
+
let byWidth = typeof icon === "string" ? void 0 : forms.get(icon);
|
|
1823
|
+
let r = byWidth?.get(width);
|
|
1824
|
+
if (r) return r;
|
|
1825
|
+
const key = `${width}|${typeof icon === "string" ? icon : JSON.stringify(icon)}`;
|
|
1826
|
+
r = byContent.get(key);
|
|
1827
|
+
if (r) byContent.delete(key);
|
|
1828
|
+
else r = toRegion(icon, { strokeWidth });
|
|
1829
|
+
byContent.set(key, r);
|
|
1830
|
+
if (byContent.size > 64) byContent.delete(byContent.keys().next().value);
|
|
1831
|
+
if (typeof icon !== "string") {
|
|
1832
|
+
if (!byWidth) {
|
|
1833
|
+
byWidth = /* @__PURE__ */ new Map();
|
|
1834
|
+
forms.set(icon, byWidth);
|
|
1835
|
+
}
|
|
1836
|
+
byWidth.set(width, r);
|
|
1837
|
+
}
|
|
1838
|
+
return r;
|
|
1839
|
+
}
|
|
1840
|
+
function sampledOf(region) {
|
|
1841
|
+
let s = samples.get(region);
|
|
1842
|
+
if (!s) {
|
|
1843
|
+
s = resampleRegion(region);
|
|
1844
|
+
samples.set(region, s);
|
|
1845
|
+
}
|
|
1846
|
+
return s;
|
|
1847
|
+
}
|
|
1848
|
+
function regionPlan(src, dst, strokeWidth) {
|
|
1849
|
+
const a = regionOf(src, strokeWidth);
|
|
1850
|
+
const b = regionOf(dst, strokeWidth);
|
|
1851
|
+
let inner = plans.get(a);
|
|
1852
|
+
if (!inner) {
|
|
1853
|
+
inner = /* @__PURE__ */ new WeakMap();
|
|
1854
|
+
plans.set(a, inner);
|
|
1855
|
+
}
|
|
1856
|
+
let p = inner.get(b);
|
|
1857
|
+
if (!p) {
|
|
1858
|
+
p = buildRegionPlan(sampledOf(a), sampledOf(b));
|
|
1859
|
+
inner.set(b, p);
|
|
1860
|
+
}
|
|
1861
|
+
return p;
|
|
1862
|
+
}
|
|
1863
|
+
function regionPlanFrom(shape, dst, strokeWidth) {
|
|
1864
|
+
return buildRegionPlan(typeof shape === "string" ? resampleRegion(regionOf(shape, strokeWidth)) : shape, sampledOf(regionOf(dst, strokeWidth)));
|
|
1865
|
+
}
|
|
1866
|
+
var REGION_THRESHOLDS, FINE, REGION_LAMBDA, FOLD_SLACK, FOLD_TRIES, SKIP, weight, vanishCost, HOLE_IOU, BIG, painted2, num, fmt2, forms, byContent, samples, plans;
|
|
1867
|
+
var init_region = __esm({
|
|
1868
|
+
"node_modules/morphicons/dist/region.js"() {
|
|
1869
|
+
init_normalize_CYnN3Npw();
|
|
1870
|
+
init_resample_CXlaZ5ZQ();
|
|
1871
|
+
init_region_BjECuWZR();
|
|
1872
|
+
REGION_THRESHOLDS = [
|
|
1873
|
+
Math.PI / 4,
|
|
1874
|
+
Math.PI / 3,
|
|
1875
|
+
Math.PI / 2,
|
|
1876
|
+
Math.PI
|
|
1877
|
+
];
|
|
1878
|
+
FINE = 0.3;
|
|
1879
|
+
REGION_LAMBDA = 0.3;
|
|
1880
|
+
FOLD_SLACK = 0.1;
|
|
1881
|
+
FOLD_TRIES = 16;
|
|
1882
|
+
SKIP = 1e6;
|
|
1883
|
+
weight = (it, t) => Math.min(1, Math.max(0, 2 * t - (it.half ?? t)));
|
|
1884
|
+
vanishCost = (pts) => costMatrix([pts], [dots(centroid(pts), pts.length / 2)])[0][0];
|
|
1885
|
+
HOLE_IOU = 0.25;
|
|
1886
|
+
BIG = 1e9;
|
|
1887
|
+
painted2 = (v) => v !== void 0 && String(v).trim().toLowerCase() !== "none";
|
|
1888
|
+
num = (v, fallback) => {
|
|
1889
|
+
const x = typeof v === "number" ? v : Number.parseFloat(String(v ?? ""));
|
|
1890
|
+
return Number.isFinite(x) ? x : fallback;
|
|
1891
|
+
};
|
|
1892
|
+
fmt2 = (v) => String(Math.round(v * 1e3) / 1e3);
|
|
1893
|
+
forms = /* @__PURE__ */ new WeakMap();
|
|
1894
|
+
byContent = /* @__PURE__ */ new Map();
|
|
1895
|
+
samples = /* @__PURE__ */ new WeakMap();
|
|
1896
|
+
plans = /* @__PURE__ */ new WeakMap();
|
|
1897
|
+
globalThis[/* @__PURE__ */ Symbol.for("morphicons.region")] = {
|
|
1898
|
+
regionOf,
|
|
1899
|
+
regionPlan,
|
|
1900
|
+
regionPlanFrom
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
});
|
|
1904
|
+
|
|
1905
|
+
// node_modules/morphicons/dist/dom.js
|
|
1906
|
+
var dom_exports = {};
|
|
1907
|
+
__export(dom_exports, {
|
|
1908
|
+
canonicalD: () => canonicalD,
|
|
1909
|
+
createMorph: () => createMorph,
|
|
1910
|
+
preloadRegion: () => preloadRegion,
|
|
1911
|
+
restAttrs: () => restAttrs,
|
|
1912
|
+
setRegionLoader: () => setRegionLoader
|
|
1913
|
+
});
|
|
1914
|
+
|
|
1915
|
+
// node_modules/morphicons/dist/spring-B_P92nf6.js
|
|
1916
|
+
function allocOutputs(plan) {
|
|
1917
|
+
return plan.items.map(() => new Float64Array(2 * plan.n));
|
|
1918
|
+
}
|
|
1919
|
+
function interpPolar(plan, t, out) {
|
|
1920
|
+
for (let k = 0; k < plan.items.length; k++) {
|
|
1921
|
+
const it = plan.items[k];
|
|
1922
|
+
const o = out[k];
|
|
1923
|
+
const n = plan.n;
|
|
1924
|
+
const s = Math.exp(it.lnSigma * t);
|
|
1925
|
+
const ang = it.theta * t;
|
|
1926
|
+
const cos = Math.cos(ang) * s;
|
|
1927
|
+
const sin = Math.sin(ang) * s;
|
|
1928
|
+
let cx;
|
|
1929
|
+
let cy;
|
|
1930
|
+
if (it.block) {
|
|
1931
|
+
const [ox, oy] = it.block.off;
|
|
1932
|
+
const [dx, dy] = it.block.drift;
|
|
1933
|
+
cx = it.ca[0] + dx * t + (ox * cos - oy * sin - ox);
|
|
1934
|
+
cy = it.ca[1] + dy * t + (ox * sin + oy * cos - oy);
|
|
1935
|
+
} else {
|
|
1936
|
+
cx = it.ca[0] + (it.cb[0] - it.ca[0]) * t;
|
|
1937
|
+
cy = it.ca[1] + (it.cb[1] - it.ca[1]) * t;
|
|
1938
|
+
}
|
|
1939
|
+
const m = it.half === void 0 ? t : Math.min(1, Math.max(0, 2 * t - it.half));
|
|
1940
|
+
for (let i = 0; i < n; i++) {
|
|
1941
|
+
const px = it.aC[2 * i] + (it.bT[2 * i] - it.aC[2 * i]) * m;
|
|
1942
|
+
const py = it.aC[2 * i + 1] + (it.bT[2 * i + 1] - it.aC[2 * i + 1]) * m;
|
|
1943
|
+
o[2 * i] = cx + px * cos - py * sin;
|
|
1944
|
+
o[2 * i + 1] = cy + px * sin + py * cos;
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
var Spring = class {
|
|
1949
|
+
constructor() {
|
|
1950
|
+
__publicField(this, "x", 1);
|
|
1951
|
+
__publicField(this, "v", 0);
|
|
1952
|
+
__publicField(this, "k", 250);
|
|
1953
|
+
__publicField(this, "c", 24);
|
|
1954
|
+
}
|
|
1955
|
+
config(k, c) {
|
|
1956
|
+
this.k = k;
|
|
1957
|
+
this.c = c;
|
|
1958
|
+
}
|
|
1959
|
+
/** Starts (or restarts mid-flight) preserving velocity. */
|
|
1960
|
+
start() {
|
|
1961
|
+
this.x = 0;
|
|
1962
|
+
if (this.v > 14) this.v = 14;
|
|
1963
|
+
if (this.v < -14) this.v = -14;
|
|
1964
|
+
}
|
|
1965
|
+
/** Advances dt seconds. Returns true on settle (|1−x| < 0.001 ∧ |v| < 0.02). */
|
|
1966
|
+
step(dt) {
|
|
1967
|
+
const steps = Math.max(1, Math.min(16, Math.ceil(dt / (1 / 240))));
|
|
1968
|
+
const s = dt / steps;
|
|
1969
|
+
for (let i = 0; i < steps; i++) {
|
|
1970
|
+
const a = this.k * (1 - this.x) - this.c * this.v;
|
|
1971
|
+
this.v += a * s;
|
|
1972
|
+
this.x += this.v * s;
|
|
1973
|
+
}
|
|
1974
|
+
return Math.abs(1 - this.x) < 1e-3 && Math.abs(this.v) < 0.02;
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1977
|
+
var SPRING_PRESETS = {
|
|
1978
|
+
/** ζ = 1.00 — critically damped, no overshoot. */
|
|
1979
|
+
smooth: {
|
|
1980
|
+
k: 170,
|
|
1981
|
+
c: 26
|
|
1982
|
+
},
|
|
1983
|
+
/** ζ = 0.73 — fast, subtle overshoot. */
|
|
1984
|
+
snappy: {
|
|
1985
|
+
k: 420,
|
|
1986
|
+
c: 30
|
|
1987
|
+
},
|
|
1988
|
+
/** ζ = 0.40 — playful. */
|
|
1989
|
+
bouncy: {
|
|
1990
|
+
k: 300,
|
|
1991
|
+
c: 14
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1994
|
+
|
|
1995
|
+
// node_modules/morphicons/dist/dom.js
|
|
1996
|
+
init_normalize_CYnN3Npw();
|
|
1997
|
+
init_resample_CXlaZ5ZQ();
|
|
1998
|
+
init_region_BjECuWZR();
|
|
1999
|
+
var tickers = /* @__PURE__ */ new Set();
|
|
2000
|
+
var rafId = 0;
|
|
2001
|
+
var last = -1;
|
|
2002
|
+
function loop(ts) {
|
|
2003
|
+
const dt = last < 0 ? 0 : Math.min(Math.max((ts - last) / 1e3, 0), 0.1);
|
|
2004
|
+
last = ts;
|
|
2005
|
+
for (const tick of [...tickers]) tick(dt);
|
|
2006
|
+
if (tickers.size > 0) rafId = requestAnimationFrame(loop);
|
|
2007
|
+
else {
|
|
2008
|
+
rafId = 0;
|
|
2009
|
+
last = -1;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
function addTicker(tick) {
|
|
2013
|
+
tickers.add(tick);
|
|
2014
|
+
if (rafId === 0) {
|
|
2015
|
+
last = -1;
|
|
2016
|
+
rafId = requestAnimationFrame(loop);
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
function removeTicker(tick) {
|
|
2020
|
+
tickers.delete(tick);
|
|
2021
|
+
if (tickers.size === 0 && rafId !== 0) {
|
|
2022
|
+
cancelAnimationFrame(rafId);
|
|
2023
|
+
rafId = 0;
|
|
2024
|
+
last = -1;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
var samples2 = /* @__PURE__ */ new WeakMap();
|
|
2028
|
+
var canon = /* @__PURE__ */ new WeakMap();
|
|
2029
|
+
var plans2 = /* @__PURE__ */ new WeakMap();
|
|
2030
|
+
function cubicsOf(icon) {
|
|
2031
|
+
if (typeof icon === "string" || paintOf(icon) === "stroke") return iconToCubics(icon);
|
|
2032
|
+
return solid(icon).flatMap((el) => {
|
|
2033
|
+
const ps = iconToCubics([el]);
|
|
2034
|
+
const odd = String(el[1]["fill-rule"]).trim() === "evenodd";
|
|
2035
|
+
let sum = 0;
|
|
2036
|
+
for (const p of ps) sum += signedArea(p.pts);
|
|
2037
|
+
for (const p of ps) {
|
|
2038
|
+
let flip = sum < 0;
|
|
2039
|
+
if (odd) {
|
|
2040
|
+
let pos = true;
|
|
2041
|
+
for (const o of ps) if (o !== p && inside(p.pts[0], p.pts[1], o.pts)) pos = !pos;
|
|
2042
|
+
flip = signedArea(p.pts) > 0 !== pos;
|
|
2043
|
+
}
|
|
2044
|
+
if (flip) p.pts = reversePts(p.pts);
|
|
2045
|
+
}
|
|
2046
|
+
return ps;
|
|
2047
|
+
});
|
|
2048
|
+
}
|
|
2049
|
+
function sampledOf2(icon) {
|
|
2050
|
+
if (typeof icon === "string") return resampleIcon(icon);
|
|
2051
|
+
let s = samples2.get(icon);
|
|
2052
|
+
if (!s) {
|
|
2053
|
+
s = cubicsOf(icon).map((p) => ({
|
|
2054
|
+
pts: resamplePath(p, 64),
|
|
2055
|
+
closed: p.closed
|
|
2056
|
+
}));
|
|
2057
|
+
samples2.set(icon, s);
|
|
2058
|
+
}
|
|
2059
|
+
return s;
|
|
2060
|
+
}
|
|
2061
|
+
function canonicalD(icon) {
|
|
2062
|
+
if (typeof icon === "string") return icon;
|
|
2063
|
+
let d = canon.get(icon);
|
|
2064
|
+
if (!d) {
|
|
2065
|
+
d = cubicsToPathD(cubicsOf(icon));
|
|
2066
|
+
canon.set(icon, d);
|
|
2067
|
+
}
|
|
2068
|
+
return d;
|
|
2069
|
+
}
|
|
2070
|
+
function planBetween(src, dst) {
|
|
2071
|
+
if (typeof src === "string" || typeof dst === "string") return buildPlan(sampledOf2(src), sampledOf2(dst));
|
|
2072
|
+
let inner = plans2.get(src);
|
|
2073
|
+
if (!inner) {
|
|
2074
|
+
inner = /* @__PURE__ */ new WeakMap();
|
|
2075
|
+
plans2.set(src, inner);
|
|
2076
|
+
}
|
|
2077
|
+
let p = inner.get(dst);
|
|
2078
|
+
if (!p) {
|
|
2079
|
+
p = buildPlan(sampledOf2(src), sampledOf2(dst));
|
|
2080
|
+
inner.set(dst, p);
|
|
2081
|
+
}
|
|
2082
|
+
return p;
|
|
2083
|
+
}
|
|
2084
|
+
var regionMod = null;
|
|
2085
|
+
var regionLoading = null;
|
|
2086
|
+
var regionSince = 0;
|
|
2087
|
+
var regionFailed = false;
|
|
2088
|
+
var regionUrl;
|
|
2089
|
+
var regionGen = 0;
|
|
2090
|
+
var regionLoader = () => Promise.resolve().then(() => (init_region(), region_exports));
|
|
2091
|
+
function setRegionLoader(loader) {
|
|
2092
|
+
regionLoader = loader;
|
|
2093
|
+
regionGen++;
|
|
2094
|
+
regionLoading = null;
|
|
2095
|
+
regionMod = null;
|
|
2096
|
+
regionFailed = false;
|
|
2097
|
+
regionUrl = void 0;
|
|
2098
|
+
}
|
|
2099
|
+
var reload = (url) => new Promise((ok, ko) => {
|
|
2100
|
+
const s = document.createElement("script");
|
|
2101
|
+
s.type = "module";
|
|
2102
|
+
s.onload = s.onerror = () => {
|
|
2103
|
+
s.remove();
|
|
2104
|
+
const m = globalThis[/* @__PURE__ */ Symbol.for("morphicons.region")];
|
|
2105
|
+
m ? ok(m) : ko(new Error(url));
|
|
2106
|
+
};
|
|
2107
|
+
s.src = `${url}#${Date.now()}`;
|
|
2108
|
+
document.head.append(s);
|
|
2109
|
+
});
|
|
2110
|
+
var fromSource = () => {
|
|
2111
|
+
const spec = /import\(\s*["'`]([^"'`]+)/.exec(String(regionLoader))?.[1];
|
|
2112
|
+
const here = /\w+:\/\/[^\s)]+?(?=:\d+:\d+)/.exec(String((/* @__PURE__ */ new Error()).stack))?.[0];
|
|
2113
|
+
try {
|
|
2114
|
+
return spec && new URL(spec, here).href;
|
|
2115
|
+
} catch {
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
function preloadRegion() {
|
|
2119
|
+
if (regionMod) return Promise.resolve(regionMod);
|
|
2120
|
+
if (!regionLoading) {
|
|
2121
|
+
regionSince = Date.now();
|
|
2122
|
+
const url = regionUrl;
|
|
2123
|
+
const gen = regionGen;
|
|
2124
|
+
regionLoading = regionLoader().catch((e) => url ? reload(url) : Promise.reject(e)).then((m) => {
|
|
2125
|
+
if (gen === regionGen) regionMod = m;
|
|
2126
|
+
return m;
|
|
2127
|
+
}, (e) => {
|
|
2128
|
+
if (gen !== regionGen) throw e;
|
|
2129
|
+
regionLoading = null;
|
|
2130
|
+
regionFailed = true;
|
|
2131
|
+
regionUrl ?? (regionUrl = /dynamically imported module:?\s*(\S+)/i.exec(String(e?.message))?.[1] ?? fromSource());
|
|
2132
|
+
throw e;
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
return regionLoading;
|
|
2136
|
+
}
|
|
2137
|
+
var quietPreload = () => new Promise((ok, ko) => {
|
|
2138
|
+
if (typeof navigator === "undefined" ? false : navigator.connection?.saveData) return;
|
|
2139
|
+
const go = () => {
|
|
2140
|
+
regionFailed ? ko() : preloadRegion().then(ok, ko);
|
|
2141
|
+
};
|
|
2142
|
+
typeof requestIdleCallback === "function" ? requestIdleCallback(go, { timeout: 2e3 }) : setTimeout(go, 200);
|
|
2143
|
+
});
|
|
2144
|
+
var REGION_WAIT_MS = 100;
|
|
2145
|
+
var paintAttrs = (p) => p === "stroke" ? {
|
|
2146
|
+
fill: "none",
|
|
2147
|
+
stroke: "inherit"
|
|
2148
|
+
} : {
|
|
2149
|
+
fill: "currentColor",
|
|
2150
|
+
stroke: p === "fill" ? "none" : "inherit",
|
|
2151
|
+
"fill-rule": "nonzero"
|
|
2152
|
+
};
|
|
2153
|
+
var looks = /* @__PURE__ */ new WeakMap();
|
|
2154
|
+
var paintedEls = /* @__PURE__ */ new WeakSet();
|
|
2155
|
+
function restLook(icon) {
|
|
2156
|
+
if (typeof icon === "string" || paintOf(icon) === "stroke") return "stroke";
|
|
2157
|
+
let look = looks.get(icon);
|
|
2158
|
+
if (look) return look;
|
|
2159
|
+
let filled = 0;
|
|
2160
|
+
let enclosed = -1;
|
|
2161
|
+
look = "fill";
|
|
2162
|
+
for (const el of solid(icon)) {
|
|
2163
|
+
const s = painted(el[1].stroke);
|
|
2164
|
+
const f = painted(el[1].fill) || el[1].fill === void 0 && !s;
|
|
2165
|
+
if (s) look = "both";
|
|
2166
|
+
let a = 0;
|
|
2167
|
+
for (const p of iconToCubics([el])) a += Math.abs(signedArea(p.pts));
|
|
2168
|
+
if (f) filled += a;
|
|
2169
|
+
else if (s) enclosed = Math.max(enclosed, 0) + a;
|
|
2170
|
+
}
|
|
2171
|
+
if (enclosed > 1.5 * filled) look = "stroke";
|
|
2172
|
+
looks.set(icon, look);
|
|
2173
|
+
return look;
|
|
2174
|
+
}
|
|
2175
|
+
function restAttrs(icon) {
|
|
2176
|
+
if (icon === void 0 || paintOf(icon) === "stroke") return void 0;
|
|
2177
|
+
return paintAttrs(restLook(icon));
|
|
2178
|
+
}
|
|
2179
|
+
function popPlan(from, to) {
|
|
2180
|
+
const n = 64;
|
|
2181
|
+
const item = ({ pts, closed }, half) => {
|
|
2182
|
+
if (pts.length > 128) pts = pts.filter((_, i) => i % 4 < 2);
|
|
2183
|
+
const c = centroid(pts);
|
|
2184
|
+
const p = pts.map((v, i) => v - c[i & 1]);
|
|
2185
|
+
const z = /* @__PURE__ */ new Float64Array(128);
|
|
2186
|
+
return {
|
|
2187
|
+
aC: half ? z : p,
|
|
2188
|
+
bT: half ? p : z,
|
|
2189
|
+
ca: c,
|
|
2190
|
+
cb: c,
|
|
2191
|
+
theta: 0,
|
|
2192
|
+
lnSigma: 0,
|
|
2193
|
+
closed,
|
|
2194
|
+
half,
|
|
2195
|
+
block: null
|
|
2196
|
+
};
|
|
2197
|
+
};
|
|
2198
|
+
return {
|
|
2199
|
+
n,
|
|
2200
|
+
items: [...from.map((s) => item(s, 0)), ...to.map((s) => item(s, 1))]
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
function resolveSpring(s) {
|
|
2204
|
+
if (typeof s === "string") return SPRING_PRESETS[s];
|
|
2205
|
+
const d = SPRING_PRESETS.snappy;
|
|
2206
|
+
return {
|
|
2207
|
+
k: s?.stiffness ?? d.k,
|
|
2208
|
+
c: s?.damping ?? d.c
|
|
2209
|
+
};
|
|
2210
|
+
}
|
|
2211
|
+
function createMorph(el, icon, options) {
|
|
2212
|
+
const spring = new Spring();
|
|
2213
|
+
let reducedMotion = options?.reducedMotion ?? "never";
|
|
2214
|
+
let strokeWidth = options?.strokeWidth ?? 2;
|
|
2215
|
+
let target = icon;
|
|
2216
|
+
let rest = true;
|
|
2217
|
+
let plan = null;
|
|
2218
|
+
let out = null;
|
|
2219
|
+
let closed = null;
|
|
2220
|
+
let t = 1;
|
|
2221
|
+
let flying = false;
|
|
2222
|
+
let dead = false;
|
|
2223
|
+
let regionFlight = false;
|
|
2224
|
+
let drawn = false;
|
|
2225
|
+
let pending = null;
|
|
2226
|
+
let paint = "stroke";
|
|
2227
|
+
let known = !paintedEls.has(el);
|
|
2228
|
+
let split = 0;
|
|
2229
|
+
let popFrom = "stroke";
|
|
2230
|
+
let popBase = null;
|
|
2231
|
+
const paintAs = (p) => {
|
|
2232
|
+
if (p === paint && known) return;
|
|
2233
|
+
for (const [k, v] of Object.entries(paintAttrs(p))) el.setAttribute(k, v);
|
|
2234
|
+
paint = p;
|
|
2235
|
+
known = true;
|
|
2236
|
+
paintedEls.add(el);
|
|
2237
|
+
};
|
|
2238
|
+
const paintRest = (ic) => {
|
|
2239
|
+
const r = regionMod && paintOf(ic) === "fill" ? regionMod.regionOf(ic, strokeWidth) : ic;
|
|
2240
|
+
el.setAttribute("d", canonicalD(r));
|
|
2241
|
+
paintAs(restLook(r));
|
|
2242
|
+
};
|
|
2243
|
+
const upgrade = (load) => {
|
|
2244
|
+
const icon2 = target;
|
|
2245
|
+
load.then(() => {
|
|
2246
|
+
if (!dead && rest && target === icon2 && pending === null) paintRest(icon2);
|
|
2247
|
+
}, () => {
|
|
2248
|
+
});
|
|
2249
|
+
};
|
|
2250
|
+
paintRest(icon);
|
|
2251
|
+
if (paintOf(icon) === "fill" && !regionMod) upgrade(quietPreload());
|
|
2252
|
+
const shown = (tt) => !split ? [0, plan?.items.length ?? 0] : tt < 0.5 ? [0, split] : [split, plan?.items.length ?? 0];
|
|
2253
|
+
const render = (tt) => {
|
|
2254
|
+
const p = plan;
|
|
2255
|
+
const o = out;
|
|
2256
|
+
const cl = closed;
|
|
2257
|
+
if (!p || !o || !cl) return;
|
|
2258
|
+
t = tt;
|
|
2259
|
+
interpPolar(p, tt, o);
|
|
2260
|
+
drawn = true;
|
|
2261
|
+
const [lo, hi] = shown(tt);
|
|
2262
|
+
if (split) paintAs(tt < 0.5 ? popFrom : restLook(target));
|
|
2263
|
+
el.setAttribute("d", serialize(o.slice(lo, hi), cl.slice(lo, hi)));
|
|
2264
|
+
};
|
|
2265
|
+
const stop = () => {
|
|
2266
|
+
if (!flying) return;
|
|
2267
|
+
flying = false;
|
|
2268
|
+
removeTicker(tick);
|
|
2269
|
+
};
|
|
2270
|
+
const tick = (dt) => {
|
|
2271
|
+
const settled = spring.step(dt);
|
|
2272
|
+
render(spring.x);
|
|
2273
|
+
if (settled) {
|
|
2274
|
+
stop();
|
|
2275
|
+
settle();
|
|
2276
|
+
}
|
|
2277
|
+
};
|
|
2278
|
+
const settle = () => {
|
|
2279
|
+
rest = true;
|
|
2280
|
+
plan = null;
|
|
2281
|
+
out = null;
|
|
2282
|
+
closed = null;
|
|
2283
|
+
t = 1;
|
|
2284
|
+
spring.x = 1;
|
|
2285
|
+
spring.v = 0;
|
|
2286
|
+
regionFlight = false;
|
|
2287
|
+
split = 0;
|
|
2288
|
+
paintRest(target);
|
|
2289
|
+
if (paintOf(target) === "fill" && !regionMod && (regionLoading || !regionFailed)) upgrade(preloadRegion());
|
|
2290
|
+
};
|
|
2291
|
+
const snapshot = () => {
|
|
2292
|
+
const p = plan;
|
|
2293
|
+
const o = out;
|
|
2294
|
+
if (rest || !p || !o) return sampledOf2(target);
|
|
2295
|
+
const [lo, hi] = shown(t);
|
|
2296
|
+
return o.slice(lo, hi).map((buf, k) => ({
|
|
2297
|
+
pts: Float64Array.from(buf),
|
|
2298
|
+
closed: p.items[lo + k].closed,
|
|
2299
|
+
hole: p.items[lo + k].hole
|
|
2300
|
+
}));
|
|
2301
|
+
};
|
|
2302
|
+
const needsRegion = (icon2) => !rest && regionFlight || paintOf(icon2) === "fill" || paintOf(target) === "fill";
|
|
2303
|
+
const retarget = (icon2, pop) => {
|
|
2304
|
+
if (!rest && plan && out && !drawn) {
|
|
2305
|
+
t = 0;
|
|
2306
|
+
interpPolar(plan, 0, out);
|
|
2307
|
+
}
|
|
2308
|
+
if (pop || !rest && split) {
|
|
2309
|
+
const from = snapshot();
|
|
2310
|
+
popBase = rest ? target : null;
|
|
2311
|
+
popFrom = paint;
|
|
2312
|
+
plan = popPlan(from, sampledOf2(icon2));
|
|
2313
|
+
split = from.length;
|
|
2314
|
+
regionFlight = false;
|
|
2315
|
+
} else if (needsRegion(icon2)) {
|
|
2316
|
+
const mod = regionMod;
|
|
2317
|
+
plan = rest || !out ? mod.regionPlan(target, icon2, strokeWidth) : mod.regionPlanFrom(regionFlight ? snapshot() : serialize(out, closed ?? void 0), icon2, strokeWidth);
|
|
2318
|
+
regionFlight = true;
|
|
2319
|
+
split = 0;
|
|
2320
|
+
paintAs("fill");
|
|
2321
|
+
} else {
|
|
2322
|
+
plan = rest ? planBetween(target, icon2) : buildPlan(snapshot(), sampledOf2(icon2));
|
|
2323
|
+
regionFlight = false;
|
|
2324
|
+
}
|
|
2325
|
+
out = allocOutputs(plan);
|
|
2326
|
+
drawn = false;
|
|
2327
|
+
closed = plan.items.map((it) => it.closed);
|
|
2328
|
+
target = icon2;
|
|
2329
|
+
rest = false;
|
|
2330
|
+
};
|
|
2331
|
+
const whenRegion = (icon2, run, fallback) => {
|
|
2332
|
+
if (regionMod || !rest && split || !needsRegion(icon2)) return false;
|
|
2333
|
+
const req = {};
|
|
2334
|
+
pending = req;
|
|
2335
|
+
const give = () => {
|
|
2336
|
+
if (dead || pending !== req) return;
|
|
2337
|
+
pending = null;
|
|
2338
|
+
fallback();
|
|
2339
|
+
};
|
|
2340
|
+
const load = preloadRegion();
|
|
2341
|
+
if (Date.now() - regionSince > REGION_WAIT_MS) {
|
|
2342
|
+
give();
|
|
2343
|
+
return true;
|
|
2344
|
+
}
|
|
2345
|
+
const timer = setTimeout(give, REGION_WAIT_MS - (Date.now() - regionSince));
|
|
2346
|
+
load.then(() => {
|
|
2347
|
+
clearTimeout(timer);
|
|
2348
|
+
if (dead || pending !== req) return;
|
|
2349
|
+
pending = null;
|
|
2350
|
+
run();
|
|
2351
|
+
}, () => {
|
|
2352
|
+
clearTimeout(timer);
|
|
2353
|
+
give();
|
|
2354
|
+
});
|
|
2355
|
+
return true;
|
|
2356
|
+
};
|
|
2357
|
+
const setNow = (icon2) => {
|
|
2358
|
+
stop();
|
|
2359
|
+
pending = null;
|
|
2360
|
+
target = icon2;
|
|
2361
|
+
settle();
|
|
2362
|
+
};
|
|
2363
|
+
const motionOff = () => {
|
|
2364
|
+
if (reducedMotion === "always") return true;
|
|
2365
|
+
if (reducedMotion !== "user") return false;
|
|
2366
|
+
if (typeof matchMedia === "undefined") return false;
|
|
2367
|
+
return matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
|
|
2368
|
+
};
|
|
2369
|
+
const seek = (icon2, tt, pop = false) => {
|
|
2370
|
+
if (dead) return;
|
|
2371
|
+
if (!pop && whenRegion(icon2, () => seek(icon2, tt), () => seek(icon2, tt, true))) return;
|
|
2372
|
+
pending = null;
|
|
2373
|
+
let reuse = !rest && plan !== null && icon2 === target;
|
|
2374
|
+
if (reuse && split && regionMod && popBase !== null) {
|
|
2375
|
+
target = popBase;
|
|
2376
|
+
rest = true;
|
|
2377
|
+
reuse = false;
|
|
2378
|
+
}
|
|
2379
|
+
stop();
|
|
2380
|
+
spring.v = 0;
|
|
2381
|
+
if (!reuse) retarget(icon2, pop);
|
|
2382
|
+
render(tt);
|
|
2383
|
+
};
|
|
2384
|
+
const fly = (icon2, sp, pop) => {
|
|
2385
|
+
if (dead) return;
|
|
2386
|
+
if (icon2 === target && (rest || flying)) {
|
|
2387
|
+
pending = null;
|
|
2388
|
+
return;
|
|
2389
|
+
}
|
|
2390
|
+
if (motionOff()) {
|
|
2391
|
+
setNow(icon2);
|
|
2392
|
+
return;
|
|
2393
|
+
}
|
|
2394
|
+
if (!pop && whenRegion(icon2, () => fly(icon2, sp, false), () => fly(icon2, sp, true))) return;
|
|
2395
|
+
pending = null;
|
|
2396
|
+
const { k, c } = resolveSpring(sp);
|
|
2397
|
+
spring.config(k, c);
|
|
2398
|
+
retarget(icon2, pop);
|
|
2399
|
+
spring.start();
|
|
2400
|
+
if (!flying) {
|
|
2401
|
+
flying = true;
|
|
2402
|
+
addTicker(tick);
|
|
2403
|
+
}
|
|
2404
|
+
};
|
|
2405
|
+
return {
|
|
2406
|
+
morphTo: (icon2, sp) => fly(icon2, sp, false),
|
|
2407
|
+
set(icon2) {
|
|
2408
|
+
if (dead) return;
|
|
2409
|
+
setNow(icon2);
|
|
2410
|
+
},
|
|
2411
|
+
seek,
|
|
2412
|
+
get progress() {
|
|
2413
|
+
return rest ? 1 : t;
|
|
2414
|
+
},
|
|
2415
|
+
set progress(v) {
|
|
2416
|
+
if (!dead) seek(target, v);
|
|
2417
|
+
},
|
|
2418
|
+
get reducedMotion() {
|
|
2419
|
+
return reducedMotion;
|
|
2420
|
+
},
|
|
2421
|
+
set reducedMotion(v) {
|
|
2422
|
+
reducedMotion = v;
|
|
2423
|
+
},
|
|
2424
|
+
get strokeWidth() {
|
|
2425
|
+
return strokeWidth;
|
|
2426
|
+
},
|
|
2427
|
+
set strokeWidth(v) {
|
|
2428
|
+
strokeWidth = v;
|
|
2429
|
+
},
|
|
2430
|
+
destroy() {
|
|
2431
|
+
stop();
|
|
2432
|
+
dead = true;
|
|
2433
|
+
pending = null;
|
|
2434
|
+
plan = null;
|
|
2435
|
+
out = null;
|
|
2436
|
+
closed = null;
|
|
2437
|
+
}
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
return __toCommonJS(dom_exports);
|
|
2441
|
+
})();
|