thursday-agent 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +3 -3
- package/.next/prerender-manifest.json +3 -3
- package/.next/server/app/_global-error/page.js.nft.json +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +2 -2
- package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/api/artifact/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/keep-working/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/memory/files/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/memory/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/thread/[id]/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/thread/route.js.nft.json +1 -1
- package/.next/server/app/api/config/route.js.nft.json +1 -1
- package/.next/server/app/api/events/route.js.nft.json +1 -1
- package/.next/server/app/api/favicon/[host]/route.js.nft.json +1 -1
- package/.next/server/app/api/file/[...path]/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/catalog/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/credits/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/subscription/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/[name]/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/oauth/callback/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/tools/route.js.nft.json +1 -1
- package/.next/server/app/api/memory/edit/route.js +1 -1
- package/.next/server/app/api/memory/edit/route.js.nft.json +1 -1
- package/.next/server/app/api/memory/route.js.nft.json +1 -1
- package/.next/server/app/api/probe/route.js.nft.json +1 -1
- package/.next/server/app/api/reach/route.js +11 -11
- package/.next/server/app/api/reach/route.js.nft.json +1 -1
- package/.next/server/app/api/routine/route.js +6 -6
- package/.next/server/app/api/routine/route.js.nft.json +1 -1
- package/.next/server/app/api/signins/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/[source]/[name]/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/call/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/skills/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/text/route.js +11 -11
- package/.next/server/app/api/thursday/text/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/tool-call/route.js +6 -6
- package/.next/server/app/api/thursday/tool-call/route.js.nft.json +1 -1
- package/.next/server/app/api/workspace/files/route.js.nft.json +1 -1
- package/.next/server/app/api/workspace/route.js.nft.json +1 -1
- package/.next/server/app/artifact/[...path]/page/server-reference-manifest.json +1 -1
- package/.next/server/app/artifact/[...path]/page.js.nft.json +1 -1
- package/.next/server/app/artifact/[...path]/page_client-reference-manifest.js +1 -1
- package/.next/server/app/favicon.ico/route.js.nft.json +1 -1
- package/.next/server/app/manifest.webmanifest/route.js.nft.json +1 -1
- package/.next/server/app/page/server-reference-manifest.json +56 -56
- package/.next/server/app/page.js +3 -3
- package/.next/server/app/page.js.nft.json +1 -1
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__012s2o8._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__04r4h-2._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0mrk2it._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0nmhgeo._.js +3 -0
- package/.next/server/chunks/[root-of-the-server]__1fy2g82._.js +3 -0
- package/.next/server/chunks/[root-of-the-server]__1ndi14y._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__1nmflqk._.js +3 -0
- package/.next/server/chunks/[root-of-the-server]__1v7-zke._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__1wnzmx9._.js +3 -0
- package/.next/server/chunks/[root-of-the-server]__1xv-5cq._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__1ygplx1._.js +1 -1
- package/.next/server/chunks/_05v8k21._.js +1 -1
- package/.next/server/chunks/_0awtznl._.js +4 -4
- package/.next/server/chunks/_0k6qjcf._.js +1 -1
- package/.next/server/chunks/_0na2fj1._.js +5 -5
- package/.next/server/chunks/_0x-ej3f._.js +21 -21
- package/.next/server/chunks/_1dc_d1q._.js +22 -20
- package/.next/server/chunks/_1jc5g4p._.js +2 -2
- package/.next/server/chunks/_1jn-aep._.js +50 -48
- package/.next/server/chunks/{_1u8ygbz._.js → _1m88lkh._.js} +7 -7
- package/.next/server/chunks/_1uuucy-._.js +4 -4
- package/.next/server/chunks/_1v9r2ke._.js +1 -1
- package/.next/server/chunks/ssr/{[root-of-the-server]__1h4bnrf._.js → [root-of-the-server]__0cxqzfc._.js} +2 -2
- package/.next/server/chunks/ssr/{[root-of-the-server]__1kyi568._.js → [root-of-the-server]__0tvavy9._.js} +1 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__0tzekbl._.js +1 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__1-d2tgh._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__1se25x0._.js +1 -1
- package/.next/server/chunks/ssr/{_1i3ddn7._.js → _05pl_u8._.js} +1 -1
- package/.next/server/chunks/ssr/_05rxyf9._.js +3 -0
- package/.next/server/chunks/ssr/_070nv1_._.js +3 -0
- package/.next/server/chunks/ssr/_097-ljd._.js +1 -1
- package/.next/server/chunks/ssr/{_10y6r1n._.js → _0bp-_fi._.js} +3 -3
- package/.next/server/chunks/ssr/_0fqhhwi._.js +1 -1
- package/.next/server/chunks/ssr/_0hlxij-._.js +3 -0
- package/.next/server/chunks/ssr/_0ld9_qq._.js +1 -1
- package/.next/server/chunks/ssr/{_0z8jpch._.js → _0p9pmxe._.js} +2 -2
- package/.next/server/chunks/ssr/{_1y-ea28._.js → _0s41irp._.js} +2 -2
- package/.next/server/chunks/ssr/_0tg0vf8._.js +164 -0
- package/.next/server/chunks/ssr/_0u5xv6g._.js +3 -0
- package/.next/server/chunks/ssr/{_1_rqu8x._.js → _12mijol._.js} +7 -7
- package/.next/server/chunks/ssr/_15zqt-t._.js +1 -1
- package/.next/server/chunks/ssr/{_1oijqjw._.js → _173siic._.js} +2 -2
- package/.next/server/chunks/ssr/_17v-33v._.js +20 -0
- package/.next/server/chunks/ssr/_184327j._.js +1 -1
- package/.next/server/chunks/ssr/{_1nod5hh._.js → _19n08g5._.js} +2 -2
- package/.next/server/chunks/ssr/_1alxym6._.js +3 -0
- package/.next/server/chunks/ssr/{_0hzz82u._.js → _1d423aj._.js} +25 -23
- package/.next/server/chunks/ssr/{_0ewory0._.js → _1doidrw._.js} +2 -2
- package/.next/server/chunks/ssr/{_0pm-2p-._.js → _1flsjeo._.js} +2 -2
- package/.next/server/chunks/ssr/_1mqn9mc._.js +1 -1
- package/.next/server/chunks/ssr/_1neoj22._.js +1 -1
- package/.next/server/chunks/ssr/_1ng831c._.js +3 -0
- package/.next/server/chunks/ssr/{_19g570d._.js → _1u2jw0i._.js} +3 -3
- package/.next/server/chunks/ssr/_1xoch6f._.js +1 -1
- package/.next/server/chunks/ssr/{_1u1mxu9._.js → _1yk6yak._.js} +2 -2
- package/.next/server/chunks/ssr/features_bot_1s_-2vj._.js +1 -1
- package/.next/server/chunks/ssr/features_bot_1yr-_pm._.js +3 -0
- package/.next/server/chunks/ssr/features_connectors_components_mcp-setting_tsx_0jmbgvp._.js +1 -1
- package/.next/server/chunks/ssr/features_memory_components_memory-setting_tsx_0oa43sw._.js +1 -1
- package/.next/server/chunks/ssr/features_routine_components_routine-setting_tsx_055fknz._.js +1 -1
- package/.next/server/chunks/ssr/{node_modules_1_8mv4v._.js → node_modules_048wmmj._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1p9rdsy._.js → node_modules_04t200t._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_03ptrl9._.js → node_modules_0511ha-._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_07ih6wb._.js → node_modules_08g12f-._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_01f8_se._.js → node_modules_0cdu6jq._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_111sh9o._.js → node_modules_0eb4rx7._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_10gbm2y._.js → node_modules_0f2k5l0._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1ix-g49._.js → node_modules_0piws2a._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0t-44lj._.js → node_modules_0pk6i-e._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0lg75qx._.js → node_modules_0s1lwc9._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1v9tc1c._.js → node_modules_0wq4-ts._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1m3gb16._.js → node_modules_0zjqwz7._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0b8df3s._.js → node_modules_11hbkuj._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_00jv9_3._.js → node_modules_18woe20._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1x825hz._.js → node_modules_1_afpz7._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0woscox._.js → node_modules_1_ban4u._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0gt-uw9._.js → node_modules_1cxc8kn._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_059vtf2._.js → node_modules_1dcbvfw._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1lsyy7k._.js → node_modules_1expacw._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1-7qawg._.js → node_modules_1ksh9gy._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_06w645b._.js → node_modules_1m2ho33._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0sz5yg1._.js → node_modules_1n0h9sf._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1teyzfa._.js → node_modules_1qehmwm._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0yv-re6._.js → node_modules_1xzo2wn._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_20xmwtu._.js → node_modules_1zf46lp._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0ii1l89._.js → node_modules_1zkpek5._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_@base-ui_react_0jne69c._.js → node_modules_@base-ui_react_0buz1-j._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_00q1oa3._.js → node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_0avl8-1._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_1-2_5z7._.js → node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_14oslro._.js} +1 -1
- package/.next/server/middleware-build-manifest.js +3 -3
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.js +1 -1
- package/.next/server/server-reference-manifest.json +57 -57
- package/.next/static/chunks/03kgfyrli_0gz.js +1 -0
- package/.next/static/chunks/{1e4yrzs5evq_r.js → 09120tms63y21.js} +1 -1
- package/.next/static/chunks/{2zhfdbq50ee5i.js → 0o980477kfqez.js} +1 -1
- package/.next/static/chunks/{1ocy4w0v20a3v.js → 0oz3rs47yy3p8.js} +2 -2
- package/.next/static/chunks/{2be08eqxsfc1y.js → 0w20wnnfrscq7.js} +1 -1
- package/.next/static/chunks/{09c13vnqy7al3.js → 19ojn4lomsk0r.js} +2 -2
- package/.next/static/chunks/{2om4lkg86feb4.js → 1mwee7xvitlp9.js} +1 -1
- package/.next/static/chunks/1p764d75_0lhv.js +18 -0
- package/.next/static/chunks/{0oz7a68qanm99.js → 1pjygp7hqib6j.js} +1 -1
- package/.next/static/chunks/22shnca_6zfzs.js +1 -0
- package/.next/static/chunks/{34s52v8f841zo.js → 24dst4mgurbsh.js} +1 -1
- package/.next/static/chunks/25zq8gzhbdsr7.js +1 -0
- package/.next/static/chunks/2d4z3er53ng8r.js +1 -0
- package/.next/static/chunks/{2d3yhjtafgmtw.js → 2ky81z-jgvasc.js} +1 -1
- package/.next/static/chunks/2m6jd3586ijb-.js +1 -0
- package/.next/static/chunks/{0k5tkt_qi52kb.js → 2ndw4w4u2x51r.js} +1 -1
- package/.next/static/chunks/2qod5tqlpz8b7.js +17 -0
- package/.next/static/chunks/{21gf2t_whhurc.js → 30skcjexa57zn.js} +2 -2
- package/.next/static/chunks/{2upc9mkcc3nlq.js → 35kwn237o4wdn.js} +1 -1
- package/.next/static/chunks/{2u9yjkpkoij75.js → 3exjsi8pfdvzj.js} +1 -1
- package/.next/static/chunks/3obf9n3cxj99k.js +1 -0
- package/.next/static/chunks/3qq4o8w2rv_e9.css +1 -0
- package/.next/static/chunks/{0g1p98s2pfx2w.js → 3vynnr71ghvom.js} +2 -2
- package/.next/static/chunks/{44kjmi5h_p8px.js → 42890jqk049q1.js} +1 -1
- package/README.md +35 -14
- package/bin/port.mjs +11 -7
- package/bin/thursday.mjs +1 -1
- package/components/ui/radio-group.tsx +1 -1
- package/components/ui/shiny-text.tsx +3 -22
- package/docs/how-it-works.md +11 -3
- package/docs/images/first-run.png +0 -0
- package/docs/images/keeps-going.png +0 -0
- package/docs/images/two-minds.png +0 -0
- package/features/ai/components/model-browser.tsx +1 -1
- package/features/ai/components/model-picker.tsx +1 -1
- package/features/ai/guide.ts +9 -4
- package/features/ai/prompts/bot.prompt.ts +4 -1
- package/features/ai/tools/routine.tool.ts +28 -16
- package/features/bot/bot.runner.ts +3 -1
- package/features/bot/components/bot-mark.tsx +6 -1
- package/features/bot/components/bot-setting.tsx +4 -6
- package/features/bot/components/bot-tool.tsx +2 -0
- package/features/bot/components/room-list.tsx +12 -3
- package/features/bot/components/room-pill.tsx +26 -19
- package/features/config/components/config-setting.tsx +17 -5
- package/features/config/components/voice-key.tsx +38 -18
- package/features/connectors/mcp.const.ts +90 -59
- package/features/intro/components/intro.tsx +50 -27
- package/features/routine/components/routine-mark.tsx +4 -6
- package/features/routine/components/routine-setting.tsx +332 -143
- package/features/routine/routine.query.ts +24 -3
- package/features/routine/routine.schema.ts +55 -4
- package/features/settings/components/install-app.tsx +1 -4
- package/features/settings/components/setting-ui.tsx +1 -1
- package/features/skills/skills.discover.ts +2 -1
- package/features/skills/skills.query.ts +5 -1
- package/features/skills/skills.schema.ts +2 -0
- package/features/thursday/components/ascii-orb.tsx +39 -10
- package/features/thursday/components/connect-wave.tsx +284 -0
- package/features/thursday/components/side-captions.tsx +29 -17
- package/features/thursday/components/thursday-setting.tsx +3 -3
- package/features/thursday/components/thursday.tsx +130 -58
- package/features/thursday/components/voice-picker.tsx +1 -1
- package/features/thursday/components/write-line.tsx +2 -2
- package/features/thursday/open-work.ts +11 -3
- package/features/thursday/tool-line.ts +94 -12
- package/features/thursday/use-text-call.ts +3 -2
- package/features/thursday/use-thursday.ts +5 -2
- package/features/workspace/components/artifact-view.tsx +129 -7
- package/guide/bots.md +17 -5
- package/guide/calls.md +15 -7
- package/guide/setup.md +10 -2
- package/knip.json +1 -0
- package/lib/desktop-notify.ts +3 -2
- package/package.json +1 -1
- package/scripts/bot-context.test.mts +1 -1
- package/seed-skills/analyst/README.md +19 -0
- package/seed-skills/analyst/data-report/SKILL.md +59 -0
- package/seed-skills/analyst/data-report/references/brief.md +31 -0
- package/seed-skills/analyst/data-report/references/company.md +41 -0
- package/seed-skills/analyst/data-report/references/comparison.md +42 -0
- package/seed-skills/analyst/data-report/references/decision.md +28 -0
- package/seed-skills/analyst/data-report/references/market-size.md +49 -0
- package/seed-skills/analyst/data-report/references/price-check.md +33 -0
- package/seed-skills/analyst/data-report/references/sources.md +51 -0
- package/seed-skills/analyst/data-report/references/trend.md +39 -0
- package/seed-skills/analyst/data-report/scripts/chart.mjs +679 -0
- package/seed-skills/analyst/data-report/scripts/fetch.mjs +521 -0
- package/seed-skills/insta/instagram/SKILL.md +33 -0
- package/seed-skills/insta/instagram/references/dm.md +49 -0
- package/seed-skills/insta/instagram/references/post.md +74 -0
- package/seed-skills/insta/instagram/scripts/compose.mjs +329 -0
- package/seed-skills/insta/instagram/scripts/image-size.mjs +30 -0
- package/seed-skills/insta/instagram/scripts/inbox.mjs +159 -0
- package/seed-skills/insta/instagram/scripts/lib.mjs +91 -0
- package/seed-skills/insta/instagram/scripts/media.mjs +104 -0
- package/seed-skills/insta/instagram/scripts/profile.mjs +139 -0
- package/seed-skills/insta/instagram/scripts/read.mjs +240 -0
- package/seed-skills/insta/instagram/scripts/render.mjs +126 -0
- package/seed-skills/insta/instagram/scripts/search.mjs +133 -0
- package/seed-skills/insta/instagram/scripts/selectors.mjs +56 -0
- package/seed-skills/insta/instagram/scripts/sheet.mjs +100 -0
- package/seed-skills/insta/instagram/scripts/webimage.mjs +105 -0
- package/seed-skills/insta/instagram/templates/carousel.html +62 -0
- package/seed-skills/mail/mail/SKILL.md +37 -0
- package/seed-skills/mail/mail/recipes/gmail.mjs +448 -0
- package/seed-skills/mail/mail/references/recipes.md +55 -0
- package/seed-skills/mail/mail/scripts/mail.mjs +202 -0
- package/seed-skills/marketer/README.md +6 -4
- package/seed-skills/marketer/copywriting/SKILL.md +1 -1
- package/seed-skills/marketer/emails/SKILL.md +1 -1
- package/seed-skills/marketer/launch/SKILL.md +1 -1
- package/seed-skills/marketer/product-marketing/SKILL.md +5 -5
- package/seed-skills/marketer/seo-audit/SKILL.md +1 -1
- package/seed-skills/marketer/social/SKILL.md +1 -1
- package/skills/computer/SKILL.md +1 -0
- package/skills/interactive-page/SKILL.md +4 -0
- package/.next/server/chunks/[root-of-the-server]__0n-l_n_._.js +0 -3
- package/.next/server/chunks/[root-of-the-server]__0wvo2of._.js +0 -3
- package/.next/server/chunks/[root-of-the-server]__1e6aut3._.js +0 -3
- package/.next/server/chunks/[root-of-the-server]__1ziojdq._.js +0 -3
- package/.next/server/chunks/ssr/[root-of-the-server]__1srp8l5._.js +0 -3
- package/.next/server/chunks/ssr/_0mes4s0._.js +0 -3
- package/.next/server/chunks/ssr/_0ya0cb0._.js +0 -3
- package/.next/server/chunks/ssr/_0yto5s7._.js +0 -20
- package/.next/server/chunks/ssr/_10dw2nv._.js +0 -3
- package/.next/server/chunks/ssr/_1p0gxeo._.js +0 -164
- package/.next/server/chunks/ssr/_1r41yvh._.js +0 -3
- package/.next/server/chunks/ssr/_1r79ksv._.js +0 -3
- package/.next/server/chunks/ssr/features_bot_1ogjt52._.js +0 -3
- package/.next/server/chunks/ssr/node_modules_@base-ui_react_0b3d4m9._.js +0 -3
- package/.next/static/chunks/03omwz_vi2ndg.js +0 -1
- package/.next/static/chunks/0_1bqgd6wt_og.js +0 -1
- package/.next/static/chunks/0abgkzikaznxc.js +0 -1
- package/.next/static/chunks/0bddkpash59-o.js +0 -17
- package/.next/static/chunks/0c2-bzhy3a0ib.js +0 -1
- package/.next/static/chunks/0iilfb1ocevnx.js +0 -1
- package/.next/static/chunks/0imbhx-j830a_.css +0 -1
- package/.next/static/chunks/24h1y9dhy3m_2.js +0 -1
- package/.next/static/chunks/2f_5saocsko_b.js +0 -1
- package/.next/static/chunks/2lwbr5vx0ixaj.js +0 -18
- /package/.next/static/{UiOMPYpQ4fqGyu5PzS-7j → Ar5V4kMdL4CE1trx8anrH}/_buildManifest.js +0 -0
- /package/.next/static/{UiOMPYpQ4fqGyu5PzS-7j → Ar5V4kMdL4CE1trx8anrH}/_clientMiddlewareManifest.js +0 -0
- /package/.next/static/{UiOMPYpQ4fqGyu5PzS-7j → Ar5V4kMdL4CE1trx8anrH}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Draws a CSV into a page as one figure: an inline SVG chart, its source, and the rows
|
|
3
|
+
// behind it with a CSV download. The page is a quick page (interactive-page `page.mjs
|
|
4
|
+
// quick`) or any HTML file; the figure takes the place of the element with the given id,
|
|
5
|
+
// or goes before </body> when there is none. Run it again and the same figure is replaced.
|
|
6
|
+
//
|
|
7
|
+
// node chart.mjs <page.html> <id> <data.csv> [options]
|
|
8
|
+
//
|
|
9
|
+
// --kind line|bar line when the first column is dates, bar otherwise
|
|
10
|
+
// --title "<text>" what the chart shows (default: the CSV's `# title:`)
|
|
11
|
+
// --columns a,b which value columns to draw (default: all)
|
|
12
|
+
// --from / --to a date range to draw, YYYY[-MM[-DD]]
|
|
13
|
+
// --index rebase every line to 100 at its first shared date
|
|
14
|
+
// --mark "2025-03=Rate cut" a dated event line; repeat for more
|
|
15
|
+
// --unit "%" --prefix "$" around every number shown
|
|
16
|
+
// --highlight "<label>" the one bar in the accent color; the rest go quiet
|
|
17
|
+
// --keep-order bars in the CSV's order instead of largest first
|
|
18
|
+
// --source "<url or text>" when the CSV has no `# source:` line
|
|
19
|
+
// --note "<text>" one line under the chart: an estimate, a gap, a break in the series
|
|
20
|
+
// --locale ko how numbers and dates are written (a BCP 47 tag)
|
|
21
|
+
//
|
|
22
|
+
// The figure carries no words of its own beyond what it is given, so it reads the same
|
|
23
|
+
// in any language: the site's name, a date, "CSV".
|
|
24
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
25
|
+
|
|
26
|
+
class Stop extends Error {}
|
|
27
|
+
|
|
28
|
+
/** The comment at the top of this file, which is its manual. */
|
|
29
|
+
const usage = () => {
|
|
30
|
+
const lines = readFileSync(new URL(import.meta.url), "utf8")
|
|
31
|
+
.split("\n")
|
|
32
|
+
.slice(1);
|
|
33
|
+
const end = lines.findIndex((line) => !line.startsWith("//"));
|
|
34
|
+
return lines
|
|
35
|
+
.slice(0, end)
|
|
36
|
+
.map((line) => line.replace(/^\/\/ ?/, ""))
|
|
37
|
+
.join("\n");
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function parseArgs(argv) {
|
|
41
|
+
const positional = [];
|
|
42
|
+
const flags = { mark: [] };
|
|
43
|
+
for (let i = 0; i < argv.length; i++) {
|
|
44
|
+
const arg = argv[i];
|
|
45
|
+
if (!arg.startsWith("--")) {
|
|
46
|
+
positional.push(arg);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const key = arg.slice(2);
|
|
50
|
+
const next = argv[i + 1];
|
|
51
|
+
const value =
|
|
52
|
+
next === undefined || next.startsWith("--") ? true : (i++, next);
|
|
53
|
+
if (key === "mark") flags.mark.push(value);
|
|
54
|
+
else flags[key] = value;
|
|
55
|
+
}
|
|
56
|
+
return { positional, flags };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ── CSV ────────────────────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
function splitLine(line) {
|
|
62
|
+
const cells = [];
|
|
63
|
+
let cur = "";
|
|
64
|
+
let quoted = false;
|
|
65
|
+
for (let i = 0; i < line.length; i++) {
|
|
66
|
+
const ch = line[i];
|
|
67
|
+
if (quoted) {
|
|
68
|
+
if (ch === '"' && line[i + 1] === '"') (cur += '"'), i++;
|
|
69
|
+
else if (ch === '"') quoted = false;
|
|
70
|
+
else cur += ch;
|
|
71
|
+
} else if (ch === '"') quoted = true;
|
|
72
|
+
else if (ch === ",") cells.push(cur), (cur = "");
|
|
73
|
+
else cur += ch;
|
|
74
|
+
}
|
|
75
|
+
cells.push(cur);
|
|
76
|
+
return cells.map((c) => c.trim());
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function readCsv(path) {
|
|
80
|
+
if (!existsSync(path)) throw new Stop(`No CSV at ${path}.`);
|
|
81
|
+
const text = readFileSync(path, "utf8").replace(/^\uFEFF/, "");
|
|
82
|
+
const meta = {};
|
|
83
|
+
const lines = [];
|
|
84
|
+
for (const line of text.split(/\r?\n/)) {
|
|
85
|
+
if (!line.trim()) continue;
|
|
86
|
+
const m = line.match(/^#\s*([\w-]+):\s*(.*)$/);
|
|
87
|
+
if (m) meta[m[1].toLowerCase()] = m[2];
|
|
88
|
+
else if (!line.startsWith("#")) lines.push(splitLine(line));
|
|
89
|
+
}
|
|
90
|
+
if (lines.length < 2) throw new Stop(`${path} has no rows under its header.`);
|
|
91
|
+
const [header, ...rows] = lines;
|
|
92
|
+
return { meta, header, rows, text };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const toNumber = (cell) => {
|
|
96
|
+
if (cell === undefined || cell === "") return null;
|
|
97
|
+
const n = Number(String(cell).replace(/[,\s%$₩€£¥]/g, ""));
|
|
98
|
+
return Number.isFinite(n) ? n : null;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** YYYY, YYYY-MM, YYYY-MM-DD, YYYY-Qn and YYYYQn as a UTC time; null when it is not a date. */
|
|
102
|
+
function toTime(cell) {
|
|
103
|
+
const s = String(cell).trim();
|
|
104
|
+
let m = s.match(/^(\d{4})(?:-(\d{1,2}))?(?:-(\d{1,2}))?(?:[T ].*)?$/);
|
|
105
|
+
if (m) return Date.UTC(+m[1], m[2] ? +m[2] - 1 : 0, m[3] ? +m[3] : 1);
|
|
106
|
+
m = s.match(/^(\d{4})-?Q([1-4])$/i);
|
|
107
|
+
if (m) return Date.UTC(+m[1], (+m[2] - 1) * 3, 1);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ── Numbers ────────────────────────────────────────────────────────────────
|
|
112
|
+
|
|
113
|
+
function formatter(locale, flags) {
|
|
114
|
+
const prefix = typeof flags.prefix === "string" ? flags.prefix : "";
|
|
115
|
+
const unit = typeof flags.unit === "string" ? flags.unit : "";
|
|
116
|
+
const wrap = (s) =>
|
|
117
|
+
`${prefix}${s}${unit && !unit.startsWith(" ") && unit.length > 1 ? " " : ""}${unit}`;
|
|
118
|
+
const compact = (v) =>
|
|
119
|
+
new Intl.NumberFormat(locale, {
|
|
120
|
+
notation: Math.abs(v) >= 10_000 ? "compact" : "standard",
|
|
121
|
+
maximumSignificantDigits: 3,
|
|
122
|
+
}).format(v);
|
|
123
|
+
// As published: the decimals the source gave, only grouped
|
|
124
|
+
const exact = (raw) => {
|
|
125
|
+
const v = toNumber(raw);
|
|
126
|
+
const decimals = (String(raw).split(".")[1] ?? "").replace(
|
|
127
|
+
/\D/g,
|
|
128
|
+
"",
|
|
129
|
+
).length;
|
|
130
|
+
return wrap(
|
|
131
|
+
new Intl.NumberFormat(locale, {
|
|
132
|
+
maximumFractionDigits: Math.min(decimals, 6),
|
|
133
|
+
}).format(v),
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
// A label on a point: up to two decimals below a million, compact past it
|
|
137
|
+
const label = (v) =>
|
|
138
|
+
wrap(
|
|
139
|
+
Math.abs(v) >= 1_000_000
|
|
140
|
+
? compact(v)
|
|
141
|
+
: new Intl.NumberFormat(locale, {
|
|
142
|
+
maximumFractionDigits: Math.abs(v) >= 1 ? 2 : 4,
|
|
143
|
+
}).format(v),
|
|
144
|
+
);
|
|
145
|
+
return { short: (v) => wrap(compact(v)), exact, label };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function niceTicks(min, max, count = 5) {
|
|
149
|
+
if (min === max) {
|
|
150
|
+
const pad = Math.abs(min) * 0.1 || 1;
|
|
151
|
+
min -= pad;
|
|
152
|
+
max += pad;
|
|
153
|
+
}
|
|
154
|
+
const raw = (max - min) / count;
|
|
155
|
+
const mag = 10 ** Math.floor(Math.log10(raw));
|
|
156
|
+
const step = [1, 2, 2.5, 5, 10].map((f) => f * mag).find((s) => s >= raw);
|
|
157
|
+
const lo = Math.floor(min / step) * step;
|
|
158
|
+
const hi = Math.ceil(max / step) * step;
|
|
159
|
+
const ticks = [];
|
|
160
|
+
for (let v = lo; v <= hi + step / 2; v += step)
|
|
161
|
+
ticks.push(+v.toPrecision(12));
|
|
162
|
+
return ticks;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function timeTicks(t0, t1, locale, most = 7) {
|
|
166
|
+
const DAY = 86_400_000;
|
|
167
|
+
const years = (t1 - t0) / (365.25 * DAY);
|
|
168
|
+
const ticks = [];
|
|
169
|
+
const d0 = new Date(t0);
|
|
170
|
+
if (years >= 3) {
|
|
171
|
+
const every = [1, 2, 5, 10, 20, 50].find((k) => years / k <= most);
|
|
172
|
+
for (
|
|
173
|
+
let y = Math.ceil(d0.getUTCFullYear() / every) * every;
|
|
174
|
+
Date.UTC(y, 0, 1) <= t1;
|
|
175
|
+
y += every
|
|
176
|
+
)
|
|
177
|
+
if (Date.UTC(y, 0, 1) >= t0)
|
|
178
|
+
ticks.push({ t: Date.UTC(y, 0, 1), label: String(y) });
|
|
179
|
+
return ticks;
|
|
180
|
+
}
|
|
181
|
+
const months = years * 12;
|
|
182
|
+
if (months >= 2) {
|
|
183
|
+
const every = [1, 2, 3, 6].find((k) => months / k <= most) ?? 12;
|
|
184
|
+
const month = new Intl.DateTimeFormat(locale, {
|
|
185
|
+
month: "short",
|
|
186
|
+
timeZone: "UTC",
|
|
187
|
+
});
|
|
188
|
+
let y = d0.getUTCFullYear();
|
|
189
|
+
let m = d0.getUTCMonth() + (d0.getUTCDate() > 1 ? 1 : 0);
|
|
190
|
+
m = Math.ceil(m / every) * every;
|
|
191
|
+
for (let first = true; ; m += every) {
|
|
192
|
+
const t = Date.UTC(y, m, 1);
|
|
193
|
+
if (t > t1) break;
|
|
194
|
+
const date = new Date(t);
|
|
195
|
+
const label =
|
|
196
|
+
first || date.getUTCMonth() === 0
|
|
197
|
+
? `${month.format(date)} ${date.getUTCFullYear()}`
|
|
198
|
+
: month.format(date);
|
|
199
|
+
ticks.push({ t, label });
|
|
200
|
+
first = false;
|
|
201
|
+
}
|
|
202
|
+
return ticks;
|
|
203
|
+
}
|
|
204
|
+
const dayFmt = new Intl.DateTimeFormat(locale, {
|
|
205
|
+
month: "short",
|
|
206
|
+
day: "numeric",
|
|
207
|
+
timeZone: "UTC",
|
|
208
|
+
});
|
|
209
|
+
const days = (t1 - t0) / DAY;
|
|
210
|
+
const every = [1, 2, 7, 14].find((k) => days / k <= most) ?? 14;
|
|
211
|
+
for (
|
|
212
|
+
let t = Date.UTC(d0.getUTCFullYear(), d0.getUTCMonth(), d0.getUTCDate());
|
|
213
|
+
t <= t1;
|
|
214
|
+
t += every * DAY
|
|
215
|
+
)
|
|
216
|
+
ticks.push({ t, label: dayFmt.format(new Date(t)) });
|
|
217
|
+
return ticks;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ── Drawing ────────────────────────────────────────────────────────────────
|
|
221
|
+
|
|
222
|
+
const esc = (s) =>
|
|
223
|
+
String(s).replace(
|
|
224
|
+
/[&<>"']/g,
|
|
225
|
+
(c) =>
|
|
226
|
+
({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[
|
|
227
|
+
c
|
|
228
|
+
],
|
|
229
|
+
);
|
|
230
|
+
/** A width for text that is only measured, never shown: about 0.58em a character, 1em for CJK. */
|
|
231
|
+
const textWidth = (s, size) =>
|
|
232
|
+
[...String(s)].reduce(
|
|
233
|
+
(w, ch) =>
|
|
234
|
+
w + (/[\u1100-\u11ff\u3000-\u9fff\uac00-\ud7af]/.test(ch) ? 1 : 0.58),
|
|
235
|
+
0,
|
|
236
|
+
) * size;
|
|
237
|
+
const FONT = 13;
|
|
238
|
+
// Every chart is drawn twice and CSS shows one: text in an SVG scales with it, so a
|
|
239
|
+
// wide drawing squeezed onto a phone would read at half size
|
|
240
|
+
const SIZES = {
|
|
241
|
+
wide: { W: 640, ticks: 7, endCap: 170, labelChars: 26, nameChars: 24 },
|
|
242
|
+
narrow: { W: 360, ticks: 4, endCap: 124, labelChars: 14, nameChars: 10 },
|
|
243
|
+
};
|
|
244
|
+
const cut = (s, n) =>
|
|
245
|
+
[...String(s)].length > n
|
|
246
|
+
? `${[...String(s)].slice(0, n - 1).join("")}…`
|
|
247
|
+
: String(s);
|
|
248
|
+
|
|
249
|
+
function lineChart({ xs, labels, series, fmt, marks, indexed, locale, size }) {
|
|
250
|
+
const { W } = size;
|
|
251
|
+
const H = size.W < 500 ? 260 : 320;
|
|
252
|
+
const all = series.flatMap((s) => s.values).filter((v) => v !== null);
|
|
253
|
+
const yTicks = niceTicks(
|
|
254
|
+
Math.min(...all),
|
|
255
|
+
Math.max(...all),
|
|
256
|
+
size.W < 500 ? 4 : 5,
|
|
257
|
+
);
|
|
258
|
+
const [yMin, yMax] = [yTicks[0], yTicks.at(-1)];
|
|
259
|
+
const lastOf = (s) => {
|
|
260
|
+
for (let i = s.values.length - 1; i >= 0; i--)
|
|
261
|
+
if (s.values[i] !== null) return i;
|
|
262
|
+
return -1;
|
|
263
|
+
};
|
|
264
|
+
const ends = series.map((s) => {
|
|
265
|
+
const i = lastOf(s);
|
|
266
|
+
const text = `${series.length > 1 ? `${cut(s.name, size.nameChars)} ` : ""}${fmt.label(s.values[i])}`;
|
|
267
|
+
return { s, i, text };
|
|
268
|
+
});
|
|
269
|
+
const left =
|
|
270
|
+
Math.max(...yTicks.map((v) => textWidth(fmt.short(v), FONT))) + 14;
|
|
271
|
+
const right = Math.min(
|
|
272
|
+
size.endCap,
|
|
273
|
+
Math.max(...ends.map((e) => textWidth(e.text, FONT))) + 16,
|
|
274
|
+
);
|
|
275
|
+
const top = marks.length ? 34 : 14;
|
|
276
|
+
const bottom = 30;
|
|
277
|
+
const [t0, t1] = [xs[0], xs.at(-1)];
|
|
278
|
+
const px = (t) => left + ((t - t0) / (t1 - t0 || 1)) * (W - left - right);
|
|
279
|
+
const py = (v) => top + (1 - (v - yMin) / (yMax - yMin)) * (H - top - bottom);
|
|
280
|
+
|
|
281
|
+
const parts = [];
|
|
282
|
+
for (const v of yTicks) {
|
|
283
|
+
parts.push(
|
|
284
|
+
`<line class="grid${indexed && v === 100 ? " base" : ""}" x1="${left}" x2="${W - right}" y1="${py(v)}" y2="${py(v)}"/>`,
|
|
285
|
+
);
|
|
286
|
+
parts.push(
|
|
287
|
+
`<text class="tick" x="${left - 8}" y="${py(v) + 4}" text-anchor="end">${esc(fmt.short(v))}</text>`,
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
for (const { t, label } of timeTicks(t0, t1, locale, size.ticks))
|
|
291
|
+
parts.push(
|
|
292
|
+
`<text class="tick" x="${px(t)}" y="${H - 8}" text-anchor="middle">${esc(label)}</text>`,
|
|
293
|
+
);
|
|
294
|
+
marks.forEach(({ t, text }, k) => {
|
|
295
|
+
if (t < t0 || t > t1) return;
|
|
296
|
+
const x = px(t);
|
|
297
|
+
const anchor = x > left + (W - left - right) * 0.7 ? "end" : "start";
|
|
298
|
+
parts.push(
|
|
299
|
+
`<line class="mark" x1="${x}" x2="${x}" y1="${top - 6}" y2="${H - bottom}"/>`,
|
|
300
|
+
);
|
|
301
|
+
parts.push(
|
|
302
|
+
`<text class="mark-label" x="${x + (anchor === "start" ? 4 : -4)}" y="${k % 2 ? top - 20 : top - 8}" text-anchor="${anchor}">${esc(cut(text, size.labelChars + 6))}</text>`,
|
|
303
|
+
);
|
|
304
|
+
});
|
|
305
|
+
series.forEach((s, n) => {
|
|
306
|
+
let d = "";
|
|
307
|
+
let pen = false;
|
|
308
|
+
// A series published less often than the others (weekly beside daily) is empty on most
|
|
309
|
+
// rows and joins across them; a denser one breaks its line where a value is missing
|
|
310
|
+
const sparse =
|
|
311
|
+
s.values.filter((v) => v !== null).length < s.values.length / 2;
|
|
312
|
+
s.values.forEach((v, i) => {
|
|
313
|
+
if (v === null) return void (pen = pen && sparse);
|
|
314
|
+
d += `${pen ? "L" : "M"}${px(xs[i]).toFixed(1)},${py(v).toFixed(1)}`;
|
|
315
|
+
pen = true;
|
|
316
|
+
});
|
|
317
|
+
parts.push(`<path class="line c${(n % 6) + 1}" d="${d}"/>`);
|
|
318
|
+
});
|
|
319
|
+
// End labels, pushed apart so two lines ending close together stay readable
|
|
320
|
+
const placed = ends
|
|
321
|
+
.filter((e) => e.i >= 0)
|
|
322
|
+
.map((e) => ({ ...e, y: py(e.s.values[e.i]) }))
|
|
323
|
+
.sort((a, b) => a.y - b.y);
|
|
324
|
+
for (let k = 1; k < placed.length; k++)
|
|
325
|
+
placed[k].y = Math.max(placed[k].y, placed[k - 1].y + 16);
|
|
326
|
+
for (const e of placed) {
|
|
327
|
+
const n = series.indexOf(e.s);
|
|
328
|
+
parts.push(
|
|
329
|
+
`<circle class="dot c${(n % 6) + 1}" cx="${px(xs[e.i])}" cy="${py(e.s.values[e.i])}" r="3.5"/>`,
|
|
330
|
+
);
|
|
331
|
+
parts.push(
|
|
332
|
+
`<text class="end c${(n % 6) + 1}" x="${W - right + 8}" y="${e.y + 4}">${esc(e.text)}</text>`,
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
const data = {
|
|
336
|
+
x: xs.map((t) => +px(t).toFixed(1)),
|
|
337
|
+
labels,
|
|
338
|
+
series: series.map((s) => ({
|
|
339
|
+
name: s.name,
|
|
340
|
+
values: s.values.map((v) => (v === null ? null : fmt.label(v))),
|
|
341
|
+
y: s.values.map((v) => (v === null ? null : +py(v).toFixed(1))),
|
|
342
|
+
})),
|
|
343
|
+
top,
|
|
344
|
+
bottom: H - bottom,
|
|
345
|
+
width: W,
|
|
346
|
+
};
|
|
347
|
+
return {
|
|
348
|
+
svg: `<svg class="chart-svg ${size.W < 500 ? "narrow" : "wide"}" viewBox="0 0 ${W} ${H}" role="img" data-chart='${esc(JSON.stringify(data))}'>${parts.join("")}<g class="hover"></g></svg>`,
|
|
349
|
+
axis: indexed ? `100 = ${indexed}` : null,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function barChart({ labels, series, fmt, highlight, size }) {
|
|
354
|
+
const { W } = size;
|
|
355
|
+
const groups = labels.length;
|
|
356
|
+
const per = series.length;
|
|
357
|
+
const barH = per > 1 ? 14 : 22;
|
|
358
|
+
const gap = per > 1 ? 14 : 10;
|
|
359
|
+
const legend = per > 1 ? 26 : 0;
|
|
360
|
+
const H = legend + groups * (per * barH + gap) + 8;
|
|
361
|
+
const all = series.flatMap((s) => s.values).filter((v) => v !== null);
|
|
362
|
+
const lo = Math.min(0, ...all);
|
|
363
|
+
const hi = Math.max(0, ...all);
|
|
364
|
+
const shownLabel = (l) => cut(l, size.labelChars);
|
|
365
|
+
const left = Math.min(
|
|
366
|
+
size.W < 500 ? 130 : 220,
|
|
367
|
+
Math.max(...labels.map((l) => textWidth(shownLabel(l), FONT))) + 14,
|
|
368
|
+
);
|
|
369
|
+
const valueRoom =
|
|
370
|
+
Math.max(...all.map((v) => textWidth(fmt.label(v), FONT))) + 12;
|
|
371
|
+
const span = W - left - valueRoom - (lo < 0 ? valueRoom : 0);
|
|
372
|
+
const px = (v) =>
|
|
373
|
+
left + (lo < 0 ? valueRoom : 0) + ((v - lo) / (hi - lo || 1)) * span;
|
|
374
|
+
const parts = [];
|
|
375
|
+
if (per > 1)
|
|
376
|
+
series.forEach((s, n) => {
|
|
377
|
+
const x = (size.W < 500 ? 0 : left) + n * (size.W < 500 ? 110 : 130);
|
|
378
|
+
parts.push(
|
|
379
|
+
`<rect class="bar c${(n % 6) + 1}" x="${x}" y="4" width="12" height="12" rx="2"/>`,
|
|
380
|
+
);
|
|
381
|
+
parts.push(
|
|
382
|
+
`<text class="tick" x="${x + 18}" y="14">${esc(cut(s.name, size.nameChars + 2))}</text>`,
|
|
383
|
+
);
|
|
384
|
+
});
|
|
385
|
+
labels.forEach((label, g) => {
|
|
386
|
+
const y0 = legend + g * (per * barH + gap);
|
|
387
|
+
const quiet = highlight && label !== highlight;
|
|
388
|
+
parts.push(
|
|
389
|
+
`<text class="label${quiet ? " quiet-text" : ""}" x="${left - 10}" y="${y0 + (per * barH) / 2 + 4}" text-anchor="end">${esc(shownLabel(label))}<title>${esc(label)}</title></text>`,
|
|
390
|
+
);
|
|
391
|
+
series.forEach((s, n) => {
|
|
392
|
+
const v = s.values[g];
|
|
393
|
+
if (v === null) return;
|
|
394
|
+
const [a, b] = [px(Math.min(0, v)), px(Math.max(0, v))];
|
|
395
|
+
const y = y0 + n * barH;
|
|
396
|
+
// One series: the highlighted bar takes the accent. Several: it keeps the legend's colors
|
|
397
|
+
const color = quiet
|
|
398
|
+
? "quiet"
|
|
399
|
+
: highlight && per === 1
|
|
400
|
+
? "c1"
|
|
401
|
+
: `c${(n % 6) + 1}`;
|
|
402
|
+
parts.push(
|
|
403
|
+
`<rect class="bar ${color}" x="${a}" y="${y + 1}" width="${Math.max(1, b - a)}" height="${barH - 2}" rx="3"><title>${esc(label)}${per > 1 ? ` — ${esc(s.name)}` : ""}: ${esc(fmt.label(v))}</title></rect>`,
|
|
404
|
+
);
|
|
405
|
+
const tx = v < 0 ? a - 6 : b + 6;
|
|
406
|
+
parts.push(
|
|
407
|
+
`<text class="value" x="${tx}" y="${y + barH / 2 + 4}" text-anchor="${v < 0 ? "end" : "start"}">${esc(fmt.label(v))}</text>`,
|
|
408
|
+
);
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
if (lo < 0)
|
|
412
|
+
parts.push(
|
|
413
|
+
`<line class="zero" x1="${px(0)}" x2="${px(0)}" y1="${legend}" y2="${H - 8}"/>`,
|
|
414
|
+
);
|
|
415
|
+
return {
|
|
416
|
+
svg: `<svg class="chart-svg ${size.W < 500 ? "narrow" : "wide"}" viewBox="0 0 ${W} ${H}" role="img">${parts.join("")}</svg>`,
|
|
417
|
+
axis: null,
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// ── The page ───────────────────────────────────────────────────────────────
|
|
422
|
+
|
|
423
|
+
const STYLE = `<style id="chart-style">
|
|
424
|
+
.chart{margin:1.5rem 0 2rem}
|
|
425
|
+
.chart-title{margin:0 0 .15rem;font-weight:600}
|
|
426
|
+
.chart-sub{margin:0 0 .6rem;font-size:.85rem;color:var(--muted,#71717a)}
|
|
427
|
+
.chart-svg{display:block;width:100%;height:auto;overflow:visible;border-radius:0;font:${FONT}px ui-sans-serif,system-ui,-apple-system,"Apple SD Gothic Neo","Noto Sans KR",sans-serif;font-variant-numeric:tabular-nums;touch-action:pan-y}
|
|
428
|
+
.chart-svg .grid{stroke:var(--line,#e4e4e7);stroke-width:1}
|
|
429
|
+
.chart-svg .grid.base,.chart-svg .zero{stroke:var(--muted,#71717a);stroke-dasharray:3 3}
|
|
430
|
+
.chart-svg .tick,.chart-svg .mark-label{fill:var(--muted,#71717a)}
|
|
431
|
+
.chart-svg .label,.chart-svg .value{fill:var(--fg,#18181b)}
|
|
432
|
+
.chart-svg .quiet-text{fill:var(--muted,#71717a)}
|
|
433
|
+
.chart-svg .mark{stroke:var(--muted,#71717a);stroke-dasharray:2 3}
|
|
434
|
+
.chart-svg .mark-label{font-size:11px}
|
|
435
|
+
.chart-svg .line{fill:none;stroke-width:2;stroke-linejoin:round;stroke-linecap:round}
|
|
436
|
+
.chart-svg .end{font-weight:600}
|
|
437
|
+
.chart-svg .c1{--c:#2563eb}.chart-svg .c2{--c:#d97706}.chart-svg .c3{--c:#059669}.chart-svg .c4{--c:#db2777}.chart-svg .c5{--c:#7c3aed}.chart-svg .c6{--c:#64748b}
|
|
438
|
+
.chart-svg .quiet{--c:color-mix(in srgb,var(--muted,#71717a) 45%,transparent)}
|
|
439
|
+
.chart-svg .line{stroke:var(--c)}.chart-svg .dot,.chart-svg .bar{fill:var(--c)}.chart-svg .end{fill:var(--c)}
|
|
440
|
+
.chart-svg .hover line{stroke:var(--muted,#71717a)}
|
|
441
|
+
.chart-svg .hover rect{fill:var(--bg,#fff);stroke:var(--line,#e4e4e7)}
|
|
442
|
+
.chart-svg .hover text{fill:var(--fg,#18181b);font-size:12px}
|
|
443
|
+
.chart-svg.narrow{display:none}
|
|
444
|
+
@media (max-width:560px){.chart-svg.wide{display:none}.chart-svg.narrow{display:block}}
|
|
445
|
+
.chart .source{margin:.4rem 0 .6rem;font-size:.85rem;color:var(--muted,#71717a)}
|
|
446
|
+
.chart details{margin:0;font-size:.9rem}
|
|
447
|
+
@media (prefers-color-scheme:dark){.chart-svg .c1{--c:#60a5fa}.chart-svg .c2{--c:#fbbf24}.chart-svg .c3{--c:#34d399}.chart-svg .c4{--c:#f472b6}.chart-svg .c5{--c:#a78bfa}.chart-svg .c6{--c:#94a3b8}}
|
|
448
|
+
</style>`;
|
|
449
|
+
|
|
450
|
+
// Reads every line chart's own data off its svg: a readout follows the pointer
|
|
451
|
+
const SCRIPT = `<script id="chart-script">
|
|
452
|
+
document.querySelectorAll("svg[data-chart]").forEach(function(svg){
|
|
453
|
+
var d=JSON.parse(svg.getAttribute("data-chart")),g=svg.querySelector(".hover"),NS="http://www.w3.org/2000/svg";
|
|
454
|
+
function el(n,a){var e=document.createElementNS(NS,n);for(var k in a)e.setAttribute(k,a[k]);g.appendChild(e);return e}
|
|
455
|
+
function show(ev){
|
|
456
|
+
var p=svg.createSVGPoint();p.x=ev.clientX;p.y=ev.clientY;var x=p.matrixTransform(svg.getScreenCTM().inverse()).x,i=0;
|
|
457
|
+
for(var k=1;k<d.x.length;k++)if(Math.abs(d.x[k]-x)<Math.abs(d.x[i]-x))i=k;
|
|
458
|
+
g.innerHTML="";el("line",{x1:d.x[i],x2:d.x[i],y1:d.top,y2:d.bottom});
|
|
459
|
+
var lines=[d.labels[i]].concat(d.series.filter(function(s){return s.values[i]!==null}).map(function(s){return(d.series.length>1?s.name+": ":"")+s.values[i]}));
|
|
460
|
+
d.series.forEach(function(s,n){if(s.y[i]!==null)el("circle",{cx:d.x[i],cy:s.y[i],r:4,"class":"dot c"+(n%6+1)})});
|
|
461
|
+
var w=Math.max.apply(null,lines.map(function(l){return l.length}))*7+16,h=lines.length*16+10,bx=d.x[i]+10+w>d.width?d.x[i]-10-w:d.x[i]+10;
|
|
462
|
+
el("rect",{x:bx,y:d.top,width:w,height:h,rx:6});
|
|
463
|
+
lines.forEach(function(l,n){var t=el("text",{x:bx+8,y:d.top+18+n*16});t.textContent=l;if(!n)t.setAttribute("font-weight","600")});
|
|
464
|
+
}
|
|
465
|
+
svg.addEventListener("pointermove",show);svg.addEventListener("pointerleave",function(){g.innerHTML=""});
|
|
466
|
+
});
|
|
467
|
+
</script>`;
|
|
468
|
+
|
|
469
|
+
function both(draw) {
|
|
470
|
+
const wide = draw(SIZES.wide);
|
|
471
|
+
return { svg: `${wide.svg}\n${draw(SIZES.narrow).svg}`, axis: wide.axis };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function sourceLinks(text) {
|
|
475
|
+
const hosts = new Set();
|
|
476
|
+
return String(text)
|
|
477
|
+
.split(/\s+/)
|
|
478
|
+
.filter(Boolean)
|
|
479
|
+
.map((part) => {
|
|
480
|
+
if (!/^https?:\/\//.test(part)) return esc(part);
|
|
481
|
+
const host = new URL(part).hostname.replace(/^www\./, "");
|
|
482
|
+
// One link a site: the CSV keeps every address
|
|
483
|
+
if (hosts.has(host)) return "";
|
|
484
|
+
hosts.add(host);
|
|
485
|
+
return `<a href="${esc(part)}">${esc(host)}</a>`;
|
|
486
|
+
})
|
|
487
|
+
.filter(Boolean)
|
|
488
|
+
.join(" ")
|
|
489
|
+
.replace(/(<\/a>) (<a )/g, "$1, $2");
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function main() {
|
|
493
|
+
const { positional, flags } = parseArgs(process.argv.slice(2));
|
|
494
|
+
const [pagePath, id, csvPath] = positional;
|
|
495
|
+
if (!pagePath || !id || !csvPath) throw new Stop(usage());
|
|
496
|
+
if (!/^[\w-]+$/.test(id))
|
|
497
|
+
throw new Stop(`"${id}" is not an id: letters, numbers, - and _ only.`);
|
|
498
|
+
if (!existsSync(pagePath))
|
|
499
|
+
throw new Stop(
|
|
500
|
+
`No page at ${pagePath}. Start one first: the interactive-page skill's quick page, or any HTML file.`,
|
|
501
|
+
);
|
|
502
|
+
const locale = typeof flags.locale === "string" ? flags.locale : "en";
|
|
503
|
+
const fmt = formatter(locale, flags);
|
|
504
|
+
|
|
505
|
+
const { meta, header, rows, text } = readCsv(csvPath);
|
|
506
|
+
const wanted =
|
|
507
|
+
typeof flags.columns === "string"
|
|
508
|
+
? flags.columns.split(",").map((c) => c.trim())
|
|
509
|
+
: header.slice(1);
|
|
510
|
+
const cols = wanted.map((name) => {
|
|
511
|
+
const at = header.indexOf(name);
|
|
512
|
+
if (at < 1)
|
|
513
|
+
throw new Stop(
|
|
514
|
+
`No column "${name}" in ${csvPath}; it has ${header.slice(1).join(", ")}.`,
|
|
515
|
+
);
|
|
516
|
+
return at;
|
|
517
|
+
});
|
|
518
|
+
const dated = rows.every((r) => toTime(r[0]) !== null);
|
|
519
|
+
const kind = flags.kind ?? (dated ? "line" : "bar");
|
|
520
|
+
if (kind === "line" && !dated)
|
|
521
|
+
throw new Stop(
|
|
522
|
+
"A line needs dates in the first column (YYYY, YYYY-MM, YYYY-MM-DD or YYYY-Qn); draw categories with --kind bar.",
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
let body = rows;
|
|
526
|
+
if (dated) {
|
|
527
|
+
const lo = flags.from ? toTime(flags.from) : null;
|
|
528
|
+
const hi = flags.to ? toTime(flags.to) : null;
|
|
529
|
+
body = rows
|
|
530
|
+
.map((r) => ({ r, t: toTime(r[0]) }))
|
|
531
|
+
.filter(({ t }) => (lo === null || t >= lo) && (hi === null || t <= hi))
|
|
532
|
+
.sort((a, b) => a.t - b.t)
|
|
533
|
+
.map(({ r }) => r);
|
|
534
|
+
}
|
|
535
|
+
if (!body.length) throw new Stop("No rows left to draw in that range.");
|
|
536
|
+
let series = cols.map((c) => ({
|
|
537
|
+
name: header[c],
|
|
538
|
+
values: body.map((r) => toNumber(r[c])),
|
|
539
|
+
}));
|
|
540
|
+
if (series.every((s) => s.values.every((v) => v === null)))
|
|
541
|
+
throw new Stop(`No numbers in ${wanted.join(", ")}.`);
|
|
542
|
+
|
|
543
|
+
let chart;
|
|
544
|
+
if (kind === "line") {
|
|
545
|
+
let indexed = null;
|
|
546
|
+
if (flags.index) {
|
|
547
|
+
const start = body.findIndex((_, i) =>
|
|
548
|
+
series.every((s) => s.values[i] !== null && s.values[i] !== 0),
|
|
549
|
+
);
|
|
550
|
+
if (start < 0)
|
|
551
|
+
throw new Stop(
|
|
552
|
+
"--index needs one date where every column has a value.",
|
|
553
|
+
);
|
|
554
|
+
indexed = body[start][0];
|
|
555
|
+
series = series.map((s) => ({
|
|
556
|
+
...s,
|
|
557
|
+
values: s.values.map((v, i) =>
|
|
558
|
+
v === null || i < start ? null : (v / s.values[start]) * 100,
|
|
559
|
+
),
|
|
560
|
+
}));
|
|
561
|
+
}
|
|
562
|
+
const marks = flags.mark.map((m) => {
|
|
563
|
+
const [date, ...label] = String(m).split("=");
|
|
564
|
+
const t = toTime(date);
|
|
565
|
+
if (t === null)
|
|
566
|
+
throw new Stop(
|
|
567
|
+
`--mark "${m}" needs a date first: --mark "2025-03=Rate cut".`,
|
|
568
|
+
);
|
|
569
|
+
return { t, text: label.join("=") || date };
|
|
570
|
+
});
|
|
571
|
+
const draw = (size) =>
|
|
572
|
+
lineChart({
|
|
573
|
+
xs: body.map((r) => toTime(r[0])),
|
|
574
|
+
labels: body.map((r) => r[0]),
|
|
575
|
+
series,
|
|
576
|
+
fmt: indexed ? formatter(locale, {}) : fmt,
|
|
577
|
+
marks,
|
|
578
|
+
indexed,
|
|
579
|
+
locale,
|
|
580
|
+
size,
|
|
581
|
+
});
|
|
582
|
+
chart = both(draw);
|
|
583
|
+
} else {
|
|
584
|
+
let order = body.map((_, i) => i);
|
|
585
|
+
if (!flags["keep-order"])
|
|
586
|
+
order.sort(
|
|
587
|
+
(a, b) =>
|
|
588
|
+
(series[0].values[b] ?? -Infinity) -
|
|
589
|
+
(series[0].values[a] ?? -Infinity),
|
|
590
|
+
);
|
|
591
|
+
chart = both((size) =>
|
|
592
|
+
barChart({
|
|
593
|
+
labels: order.map((i) => body[i][0]),
|
|
594
|
+
series: series.map((s) => ({
|
|
595
|
+
...s,
|
|
596
|
+
values: order.map((i) => s.values[i]),
|
|
597
|
+
})),
|
|
598
|
+
fmt,
|
|
599
|
+
highlight: typeof flags.highlight === "string" ? flags.highlight : null,
|
|
600
|
+
size,
|
|
601
|
+
}),
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
const title =
|
|
606
|
+
typeof flags.title === "string"
|
|
607
|
+
? flags.title
|
|
608
|
+
: (meta.title ?? header.slice(1).join(", "));
|
|
609
|
+
const sub = [
|
|
610
|
+
chart.axis,
|
|
611
|
+
meta.unit && !flags.unit && !flags.prefix && !chart.axis ? meta.unit : null,
|
|
612
|
+
]
|
|
613
|
+
.filter(Boolean)
|
|
614
|
+
.join(" ");
|
|
615
|
+
const source = typeof flags.source === "string" ? flags.source : meta.source;
|
|
616
|
+
// A note given here replaces the CSV's own, so it can be said in the page's language
|
|
617
|
+
const note = typeof flags.note === "string" ? flags.note : meta.note;
|
|
618
|
+
const said = [
|
|
619
|
+
source
|
|
620
|
+
? `${sourceLinks(source)}${meta.fetched ? ` (${esc(meta.fetched)})` : ""}`
|
|
621
|
+
: "",
|
|
622
|
+
note ? esc(note) : "",
|
|
623
|
+
].filter(Boolean);
|
|
624
|
+
const sourceLine = said.length
|
|
625
|
+
? `<p class="source">${said.join(". ")}</p>`
|
|
626
|
+
: "";
|
|
627
|
+
const table = `<table><thead><tr>${[header[0], ...cols.map((c) => header[c])].map((h, i) => `<th${i ? ' class="num"' : ""}>${esc(h)}</th>`).join("")}</tr></thead><tbody>${body
|
|
628
|
+
.map(
|
|
629
|
+
(r) =>
|
|
630
|
+
`<tr><td>${esc(r[0])}</td>${cols.map((c) => `<td class="num">${toNumber(r[c]) === null ? "—" : esc(fmt.exact(r[c]))}</td>`).join("")}</tr>`,
|
|
631
|
+
)
|
|
632
|
+
.join("")}</tbody></table>`;
|
|
633
|
+
const download = `data:text/csv;charset=utf-8,${encodeURIComponent(text)}`;
|
|
634
|
+
const figure = `<figure id="${id}" class="chart">
|
|
635
|
+
<p class="chart-title">${esc(title)}</p>${sub ? `\n<p class="chart-sub">${esc(sub)}</p>` : ""}
|
|
636
|
+
${chart.svg}
|
|
637
|
+
${sourceLine}
|
|
638
|
+
<details><summary>CSV (${body.length})</summary><div class="scroll">${table}</div><p><a download="${esc(id)}.csv" href="${download}">${esc(id)}.csv</a></p></details>
|
|
639
|
+
</figure>`;
|
|
640
|
+
|
|
641
|
+
let html = readFileSync(pagePath, "utf8");
|
|
642
|
+
const existing = new RegExp(
|
|
643
|
+
`<(figure|div|section|p)\\b[^>]*\\bid=["']${id}["'][^>]*>[\\s\\S]*?</\\1>`,
|
|
644
|
+
);
|
|
645
|
+
const selfClosed = new RegExp(
|
|
646
|
+
`<(figure|div|section|p)\\b[^>]*\\bid=["']${id}["'][^>]*/>`,
|
|
647
|
+
);
|
|
648
|
+
if (existing.test(html)) html = html.replace(existing, () => figure);
|
|
649
|
+
else if (selfClosed.test(html)) html = html.replace(selfClosed, () => figure);
|
|
650
|
+
else if (html.includes("</body>"))
|
|
651
|
+
html = html.replace("</body>", () => `${figure}\n</body>`);
|
|
652
|
+
else html += `\n${figure}\n`;
|
|
653
|
+
|
|
654
|
+
html = html.replace(/<style id="chart-style">[\s\S]*?<\/style>\s*/, "");
|
|
655
|
+
html = html.replace(/<script id="chart-script">[\s\S]*?<\/script>\s*/, "");
|
|
656
|
+
html = html.includes("</head>")
|
|
657
|
+
? html.replace("</head>", () => `${STYLE}\n</head>`)
|
|
658
|
+
: STYLE + html;
|
|
659
|
+
html = html.includes("</body>")
|
|
660
|
+
? html.replace("</body>", () => `${SCRIPT}\n</body>`)
|
|
661
|
+
: html + SCRIPT;
|
|
662
|
+
writeFileSync(pagePath, html);
|
|
663
|
+
|
|
664
|
+
const drawn = series.map((s) => {
|
|
665
|
+
const vals = s.values.filter((v) => v !== null);
|
|
666
|
+
return `${s.name} ${fmt.label(vals[0])} → ${fmt.label(vals.at(-1))}`;
|
|
667
|
+
});
|
|
668
|
+
console.log(
|
|
669
|
+
`Drew "${title}" (${kind}, ${body.length} rows) into ${pagePath} as #${id}. ${kind === "line" ? `First → last: ${drawn.join("; ")}.` : ""}`.trim(),
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
try {
|
|
674
|
+
main();
|
|
675
|
+
} catch (error) {
|
|
676
|
+
if (!(error instanceof Stop)) throw error;
|
|
677
|
+
console.error(error.message);
|
|
678
|
+
process.exitCode = 1;
|
|
679
|
+
}
|