hostlet 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +233 -2
- package/bin/hostlet.js +61 -0
- package/console/app/api.js +1223 -0
- package/console/app/boot.js +165 -0
- package/console/app/cards.js +222 -0
- package/console/app/compose-quote.js +127 -0
- package/console/app/config-form.js +727 -0
- package/console/app/document-drafts.js +62 -0
- package/console/app/document-tools.mjs +67 -0
- package/console/app/documents.js +106 -0
- package/console/app/pages.js +6483 -0
- package/console/app/plugins.js +509 -0
- package/console/app/preview-tools.js +172 -0
- package/console/app/reference-labels.js +118 -0
- package/console/app/selection.js +372 -0
- package/console/app/store.js +57 -0
- package/console/app/text-anchor.js +26 -0
- package/console/app/topic-local.js +322 -0
- package/console/app/topic-nav.js +414 -0
- package/console/app/topic-status.js +109 -0
- package/console/app/views.js +43 -0
- package/console/apple-touch-icon.png +0 -0
- package/console/avatars/agy.svg +34 -0
- package/console/avatars/alhena.svg +36 -0
- package/console/avatars/castor.svg +38 -0
- package/console/avatars/claude.svg +34 -0
- package/console/avatars/codex.svg +34 -0
- package/console/avatars/devin.svg +34 -0
- package/console/avatars/echo.svg +34 -0
- package/console/avatars/kimi.svg +33 -0
- package/console/avatars/opencode.svg +33 -0
- package/console/avatars/pinion.svg +34 -0
- package/console/avatars/sprocket.svg +34 -0
- package/console/avatars/vela.svg +44 -0
- package/console/avatars/wasat.svg +38 -0
- package/console/clients/agy.svg +1 -0
- package/console/clients/claude.svg +1 -0
- package/console/clients/codex.svg +1 -0
- package/console/clients/devin.svg +1 -0
- package/console/clients/kimi.svg +1 -0
- package/console/clients/opencode.svg +1 -0
- package/console/favicon.ico +0 -0
- package/console/favicon.svg +16 -0
- package/console/index.html +99 -0
- package/console/pdl/engine/README.md +13 -0
- package/console/pdl/engine/anchor.js +195 -0
- package/console/pdl/engine/core.js +1340 -0
- package/console/pdl/engine/frame.js +1252 -0
- package/console/pdl/engine/i18n.js +67 -0
- package/console/pdl/engine/pdl-check.js +102 -0
- package/console/pdl/engine/pdl-doc.js +353 -0
- package/console/pdl/engine/pdl-view.js +280 -0
- package/console/pdl/engine/pdl.js +1064 -0
- package/console/pdl/engine/platform.js +18 -0
- package/console/pdl/engine/proj.js +279 -0
- package/console/pdl/engine/theme.js +176 -0
- package/console/pdl/engine/tree.js +171 -0
- package/console/pdl/engine/units.js +546 -0
- package/console/pdl/library/README.md +28 -0
- package/console/pdl/library/blocks.js +1512 -0
- package/console/pdl/library/buttons.js +86 -0
- package/console/pdl/library/capsules.js +130 -0
- package/console/pdl/library/charts.js +287 -0
- package/console/pdl/library/code.js +98 -0
- package/console/pdl/library/css/base.css +12 -0
- package/console/pdl/library/css/blocks.css +98 -0
- package/console/pdl/library/css/capsules.css +42 -0
- package/console/pdl/library/css/catalog-page.css +24 -0
- package/console/pdl/library/css/chat.css +100 -0
- package/console/pdl/library/css/composer-top.css +145 -0
- package/console/pdl/library/css/controls.css +195 -0
- package/console/pdl/library/css/drag.css +29 -0
- package/console/pdl/library/css/edit-layout.css +93 -0
- package/console/pdl/library/css/floating-window.css +30 -0
- package/console/pdl/library/css/hover.css +50 -0
- package/console/pdl/library/css/label-search.css +37 -0
- package/console/pdl/library/css/layers.css +43 -0
- package/console/pdl/library/css/library-parts.css +33 -0
- package/console/pdl/library/css/library.css +117 -0
- package/console/pdl/library/css/member-select.css +34 -0
- package/console/pdl/library/css/message.css +72 -0
- package/console/pdl/library/css/page.css +104 -0
- package/console/pdl/library/css/parts.css +338 -0
- package/console/pdl/library/css/responsive.css +40 -0
- package/console/pdl/library/css/roles.css +28 -0
- package/console/pdl/library/css/rows.css +231 -0
- package/console/pdl/library/css/settings-rows.css +37 -0
- package/console/pdl/library/css/shell.css +59 -0
- package/console/pdl/library/css/stream.css +296 -0
- package/console/pdl/library/css/theme-calculator.css +18 -0
- package/console/pdl/library/css/thumb-choice.css +69 -0
- package/console/pdl/library/css/tweaks.css +16 -0
- package/console/pdl/library/css/widgets.css +211 -0
- package/console/pdl/library/css/workbench.css +59 -0
- package/console/pdl/library/feedback.js +83 -0
- package/console/pdl/library/floating-window.mjs +100 -0
- package/console/pdl/library/fold.js +238 -0
- package/console/pdl/library/format.js +53 -0
- package/console/pdl/library/frames.js +123 -0
- package/console/pdl/library/icons.js +165 -0
- package/console/pdl/library/identity.js +149 -0
- package/console/pdl/library/inputs.js +801 -0
- package/console/pdl/library/label-search.js +214 -0
- package/console/pdl/library/markdown-text.js +115 -0
- package/console/pdl/library/markdown.js +150 -0
- package/console/pdl/library/media-viewer.js +293 -0
- package/console/pdl/library/member-select.mjs +32 -0
- package/console/pdl/library/message.js +105 -0
- package/console/pdl/library/motion.js +56 -0
- package/console/pdl/library/overlays.js +165 -0
- package/console/pdl/library/page.js +142 -0
- package/console/pdl/library/plugin-form.js +154 -0
- package/console/pdl/library/registry.js +198 -0
- package/console/pdl/library/rows.js +523 -0
- package/console/pdl/library/shell.js +151 -0
- package/console/pdl/library/stream.js +58 -0
- package/console/pdl/library/tabs.js +259 -0
- package/console/pdl/library/theme-calculator.js +300 -0
- package/console/pdl/library/widgets.js +114 -0
- package/console/pdl/load-order.json +74 -0
- package/console/pdl/platform/README.md +3 -0
- package/console/pdl/platform/rich-markdown.mjs +17 -0
- package/console/pdl/platform/web-links.js +26 -0
- package/console/pdl/platform/web.js +80 -0
- package/console/sdk-browser/mentions.d.mts +16 -0
- package/console/sdk-browser/mentions.mjs +84 -0
- package/console/theme/assets.js +21 -0
- package/console/theme/theme.json +9417 -0
- package/console/theme/tokens.json +444 -0
- package/dist/core/a2a.d.ts +288 -0
- package/dist/core/a2a.js +2197 -0
- package/dist/core/address.d.ts +34 -0
- package/dist/core/address.js +33 -0
- package/dist/core/approval-inputs.d.ts +17 -0
- package/dist/core/approval-inputs.js +70 -0
- package/dist/core/archive.d.ts +19 -0
- package/dist/core/archive.js +135 -0
- package/dist/core/attachments.d.ts +17 -0
- package/dist/core/attachments.js +143 -0
- package/dist/core/blocked-handoffs.d.ts +132 -0
- package/dist/core/blocked-handoffs.js +349 -0
- package/dist/core/config-schema.d.ts +124 -0
- package/dist/core/config-schema.js +192 -0
- package/dist/core/config.d.ts +117 -0
- package/dist/core/config.js +638 -0
- package/dist/core/disk-usage.d.ts +26 -0
- package/dist/core/disk-usage.js +83 -0
- package/dist/core/documents.d.ts +9 -0
- package/dist/core/documents.js +48 -0
- package/dist/core/entry.d.ts +316 -0
- package/dist/core/entry.js +711 -0
- package/dist/core/home.d.ts +76 -0
- package/dist/core/home.js +449 -0
- package/dist/core/i18n.d.ts +36 -0
- package/dist/core/i18n.js +458 -0
- package/dist/core/instances.d.ts +224 -0
- package/dist/core/instances.js +1272 -0
- package/dist/core/members.d.ts +190 -0
- package/dist/core/members.js +358 -0
- package/dist/core/mentions.d.ts +12 -0
- package/dist/core/mentions.js +49 -0
- package/dist/core/messages.d.ts +876 -0
- package/dist/core/messages.js +916 -0
- package/dist/core/notices.d.ts +88 -0
- package/dist/core/notices.js +54 -0
- package/dist/core/ops.d.ts +117 -0
- package/dist/core/ops.js +146 -0
- package/dist/core/package.d.ts +2 -0
- package/dist/core/package.js +14 -0
- package/dist/core/parts.d.ts +25 -0
- package/dist/core/parts.js +119 -0
- package/dist/core/plugins/catalog.d.ts +14 -0
- package/dist/core/plugins/catalog.js +54 -0
- package/dist/core/plugins/external.d.ts +7 -0
- package/dist/core/plugins/external.js +921 -0
- package/dist/core/plugins/index.d.ts +5 -0
- package/dist/core/plugins/index.js +51 -0
- package/dist/core/plugins/npm.d.ts +12 -0
- package/dist/core/plugins/npm.js +99 -0
- package/dist/core/plugins/plugin-manifest.d.ts +12 -0
- package/dist/core/plugins/plugin-manifest.js +231 -0
- package/dist/core/push.d.ts +22 -0
- package/dist/core/push.js +63 -0
- package/dist/core/resource.d.ts +77 -0
- package/dist/core/resource.js +48 -0
- package/dist/core/spawn.d.ts +12 -0
- package/dist/core/spawn.js +30 -0
- package/dist/core/storage-inventory.d.ts +118 -0
- package/dist/core/storage-inventory.js +279 -0
- package/dist/core/storage.d.ts +45 -0
- package/dist/core/storage.js +602 -0
- package/dist/core/store.d.ts +15 -0
- package/dist/core/store.js +33 -0
- package/dist/core/topic-index.d.ts +19 -0
- package/dist/core/topic-index.js +70 -0
- package/dist/core/topic-ops.d.ts +139 -0
- package/dist/core/topic-ops.js +507 -0
- package/dist/core/topic-status.d.ts +32 -0
- package/dist/core/topic-status.js +105 -0
- package/dist/core/topics.d.ts +327 -0
- package/dist/core/topics.js +786 -0
- package/dist/core/turn-clients.d.ts +1 -0
- package/dist/core/turn-clients.js +5 -0
- package/dist/core/types.d.ts +2866 -0
- package/dist/core/types.js +166 -0
- package/dist/core/util.d.ts +10 -0
- package/dist/core/util.js +47 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +82 -0
- package/dist/plugins/adapter-acp/index.d.ts +3 -0
- package/dist/plugins/adapter-acp/index.js +57 -0
- package/dist/plugins/adapter-acp/plugin.yaml +100 -0
- package/dist/plugins/adapter-agy/command.d.ts +9 -0
- package/dist/plugins/adapter-agy/command.js +34 -0
- package/dist/plugins/adapter-agy/index.d.ts +5 -0
- package/dist/plugins/adapter-agy/index.js +65 -0
- package/dist/plugins/adapter-agy/quota.d.ts +2 -0
- package/dist/plugins/adapter-agy/quota.js +155 -0
- package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
- package/dist/plugins/adapter-agy/terminal.js +132 -0
- package/dist/plugins/adapter-agy/version.d.ts +9 -0
- package/dist/plugins/adapter-agy/version.js +17 -0
- package/dist/plugins/adapter-claude/index.d.ts +43 -0
- package/dist/plugins/adapter-claude/index.js +412 -0
- package/dist/plugins/adapter-claude/quota.d.ts +14 -0
- package/dist/plugins/adapter-claude/quota.js +103 -0
- package/dist/plugins/adapter-codex/index.d.ts +4 -0
- package/dist/plugins/adapter-codex/index.js +688 -0
- package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
- package/dist/plugins/adapter-codex/responses-model.js +82 -0
- package/dist/plugins/adapter-kimi/index.d.ts +4 -0
- package/dist/plugins/adapter-kimi/index.js +51 -0
- package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
- package/dist/plugins/adapter-kimi/quota.js +171 -0
- package/dist/plugins/adapter-opencode/index.d.ts +12 -0
- package/dist/plugins/adapter-opencode/index.js +64 -0
- package/dist/plugins/annotations/console/cards.css +189 -0
- package/dist/plugins/annotations/console/cards.mjs +439 -0
- package/dist/plugins/annotations/console/pdl.json +52 -0
- package/dist/plugins/annotations/console/view.mjs +241 -0
- package/dist/plugins/annotations/console/window.mjs +219 -0
- package/dist/plugins/annotations/followups.d.ts +51 -0
- package/dist/plugins/annotations/followups.js +112 -0
- package/dist/plugins/annotations/index.d.ts +3 -0
- package/dist/plugins/annotations/index.js +298 -0
- package/dist/plugins/annotations/plugin.yaml +3 -0
- package/dist/plugins/ask-choice/index.d.ts +9 -0
- package/dist/plugins/ask-choice/index.js +24 -0
- package/dist/plugins/ask-choice/plugin.yaml +2 -0
- package/dist/plugins/background/index.d.ts +2 -0
- package/dist/plugins/background/index.js +398 -0
- package/dist/plugins/background/plugin.yaml +7 -0
- package/dist/plugins/builtin.json +37 -0
- package/dist/plugins/cards/console/pdl.json +516 -0
- package/dist/plugins/cards/console/view.mjs +67 -0
- package/dist/plugins/cards/index.d.ts +8 -0
- package/dist/plugins/cards/index.js +627 -0
- package/dist/plugins/cards/plugin.yaml +3 -0
- package/dist/plugins/console/browser.d.ts +2 -0
- package/dist/plugins/console/browser.js +115 -0
- package/dist/plugins/console/console/pdl.json +38 -0
- package/dist/plugins/console/console/view.mjs +26 -0
- package/dist/plugins/console/index.d.ts +4 -0
- package/dist/plugins/console/index.js +94 -0
- package/dist/plugins/console/picker.d.ts +2 -0
- package/dist/plugins/console/picker.js +48 -0
- package/dist/plugins/console/plugin.yaml +3 -0
- package/dist/plugins/console/topic-view.d.ts +3 -0
- package/dist/plugins/console/topic-view.js +388 -0
- package/dist/plugins/handoff/index.d.ts +2 -0
- package/dist/plugins/handoff/index.js +147 -0
- package/dist/plugins/handoff/plugin.yaml +8 -0
- package/dist/plugins/host-api/index.d.ts +7 -0
- package/dist/plugins/host-api/index.js +310 -0
- package/dist/plugins/host-api/plugin.yaml +2 -0
- package/dist/plugins/host-api/signing.d.ts +63 -0
- package/dist/plugins/host-api/signing.js +427 -0
- package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
- package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
- package/dist/plugins/inbox/index.d.ts +15 -0
- package/dist/plugins/inbox/index.js +161 -0
- package/dist/plugins/inbox/plugin.yaml +2 -0
- package/dist/plugins/keys/account-directories.d.ts +18 -0
- package/dist/plugins/keys/account-directories.js +86 -0
- package/dist/plugins/keys/account-storage.d.ts +18 -0
- package/dist/plugins/keys/account-storage.js +112 -0
- package/dist/plugins/keys/console/pdl.json +710 -0
- package/dist/plugins/keys/console/view.mjs +619 -0
- package/dist/plugins/keys/index.d.ts +7 -0
- package/dist/plugins/keys/index.js +842 -0
- package/dist/plugins/keys/login-link.d.ts +2 -0
- package/dist/plugins/keys/login-link.js +15 -0
- package/dist/plugins/keys/plugin.yaml +3 -0
- package/dist/plugins/keys/quota-history.d.ts +91 -0
- package/dist/plugins/keys/quota-history.js +420 -0
- package/dist/plugins/mcp/console/pdl.json +412 -0
- package/dist/plugins/mcp/console/view.mjs +207 -0
- package/dist/plugins/mcp/index.d.ts +7 -0
- package/dist/plugins/mcp/index.js +494 -0
- package/dist/plugins/mcp/plugin.yaml +3 -0
- package/dist/plugins/member-health/index.d.ts +2 -0
- package/dist/plugins/member-health/index.js +478 -0
- package/dist/plugins/member-health/plugin.yaml +2 -0
- package/dist/plugins/memory/capabilities.d.ts +10 -0
- package/dist/plugins/memory/capabilities.js +70 -0
- package/dist/plugins/memory/console/pdl.json +459 -0
- package/dist/plugins/memory/console/view.mjs +254 -0
- package/dist/plugins/memory/corpus.d.ts +60 -0
- package/dist/plugins/memory/corpus.js +521 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
- package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
- package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
- package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
- package/dist/plugins/memory/engines/fts-tree.js +387 -0
- package/dist/plugins/memory/engines/search.d.ts +9 -0
- package/dist/plugins/memory/engines/search.js +35 -0
- package/dist/plugins/memory/index.d.ts +3 -0
- package/dist/plugins/memory/index.js +465 -0
- package/dist/plugins/memory/notes.d.ts +22 -0
- package/dist/plugins/memory/notes.js +140 -0
- package/dist/plugins/memory/plugin.yaml +23 -0
- package/dist/plugins/model-profiles/index.d.ts +2 -0
- package/dist/plugins/model-profiles/index.js +916 -0
- package/dist/plugins/model-profiles/plugin.yaml +13 -0
- package/dist/plugins/model-profiles/review-source.d.ts +11 -0
- package/dist/plugins/model-profiles/review-source.js +640 -0
- package/dist/plugins/model-profiles/rules.d.ts +130 -0
- package/dist/plugins/model-profiles/rules.js +729 -0
- package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +59 -0
- package/dist/plugins/model-profiles/sources.d.ts +61 -0
- package/dist/plugins/model-profiles/sources.js +375 -0
- package/dist/plugins/model-profiles/storage.d.ts +84 -0
- package/dist/plugins/model-profiles/storage.js +315 -0
- package/dist/plugins/model-profiles/types.d.ts +179 -0
- package/dist/plugins/model-profiles/types.js +12 -0
- package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
- package/dist/plugins/model-profiles/wakeup.js +390 -0
- package/dist/plugins/models/index.d.ts +2 -0
- package/dist/plugins/models/index.js +63 -0
- package/dist/plugins/models/plugin.yaml +8 -0
- package/dist/plugins/ops/collector.d.ts +22 -0
- package/dist/plugins/ops/collector.js +48 -0
- package/dist/plugins/ops/config.d.ts +11 -0
- package/dist/plugins/ops/config.js +13 -0
- package/dist/plugins/ops/console/pdl.json +676 -0
- package/dist/plugins/ops/console/view.mjs +700 -0
- package/dist/plugins/ops/index.d.ts +3 -0
- package/dist/plugins/ops/index.js +20 -0
- package/dist/plugins/ops/journal.d.ts +7 -0
- package/dist/plugins/ops/journal.js +109 -0
- package/dist/plugins/ops/metrics.d.ts +3 -0
- package/dist/plugins/ops/metrics.js +81 -0
- package/dist/plugins/ops/plugin.yaml +63 -0
- package/dist/plugins/ops/samples.d.ts +54 -0
- package/dist/plugins/ops/samples.js +100 -0
- package/dist/plugins/ops/trace.d.ts +3 -0
- package/dist/plugins/ops/trace.js +104 -0
- package/dist/plugins/ops/usage.d.ts +2 -0
- package/dist/plugins/ops/usage.js +152 -0
- package/dist/plugins/plans/acceptance.d.ts +284 -0
- package/dist/plugins/plans/acceptance.js +247 -0
- package/dist/plugins/plans/blocked.d.ts +25 -0
- package/dist/plugins/plans/blocked.js +66 -0
- package/dist/plugins/plans/console/pdl.json +639 -0
- package/dist/plugins/plans/console/view.d.mts +2 -0
- package/dist/plugins/plans/console/view.mjs +855 -0
- package/dist/plugins/plans/dependencies.d.ts +5 -0
- package/dist/plugins/plans/dependencies.js +21 -0
- package/dist/plugins/plans/index.d.ts +72 -0
- package/dist/plugins/plans/index.js +2057 -0
- package/dist/plugins/plans/plugin.yaml +44 -0
- package/dist/plugins/plans/progress.d.ts +82 -0
- package/dist/plugins/plans/progress.js +516 -0
- package/dist/plugins/prompt/index.d.ts +8 -0
- package/dist/plugins/prompt/index.js +361 -0
- package/dist/plugins/prompt/plugin.yaml +2 -0
- package/dist/plugins/recovery/console/pdl.json +50 -0
- package/dist/plugins/recovery/console/view.mjs +46 -0
- package/dist/plugins/recovery/index.d.ts +9 -0
- package/dist/plugins/recovery/index.js +454 -0
- package/dist/plugins/recovery/plugin.yaml +9 -0
- package/dist/plugins/recovery/probe.d.ts +11 -0
- package/dist/plugins/recovery/probe.js +128 -0
- package/dist/plugins/restart/console/pdl.json +112 -0
- package/dist/plugins/restart/console/view.mjs +85 -0
- package/dist/plugins/restart/index.d.ts +10 -0
- package/dist/plugins/restart/index.js +669 -0
- package/dist/plugins/restart/plugin.yaml +9 -0
- package/dist/plugins/restart/scope.d.ts +6 -0
- package/dist/plugins/restart/scope.js +44 -0
- package/dist/plugins/schedule/console/pdl.json +696 -0
- package/dist/plugins/schedule/console/view.mjs +398 -0
- package/dist/plugins/schedule/events.d.ts +76 -0
- package/dist/plugins/schedule/events.js +158 -0
- package/dist/plugins/schedule/index.d.ts +32 -0
- package/dist/plugins/schedule/index.js +1199 -0
- package/dist/plugins/schedule/plugin.yaml +26 -0
- package/dist/plugins/schedule/when.d.ts +14 -0
- package/dist/plugins/schedule/when.js +83 -0
- package/dist/plugins/sessions/console/pdl.json +259 -0
- package/dist/plugins/sessions/console/view.mjs +355 -0
- package/dist/plugins/sessions/index.d.ts +3 -0
- package/dist/plugins/sessions/index.js +126 -0
- package/dist/plugins/sessions/participants.d.ts +28 -0
- package/dist/plugins/sessions/participants.js +83 -0
- package/dist/plugins/sessions/plugin.yaml +3 -0
- package/dist/plugins/signals/console/pdl.json +802 -0
- package/dist/plugins/signals/console/view.mjs +284 -0
- package/dist/plugins/signals/content.d.ts +31 -0
- package/dist/plugins/signals/content.js +151 -0
- package/dist/plugins/signals/index.d.ts +2 -0
- package/dist/plugins/signals/index.js +601 -0
- package/dist/plugins/signals/plugin.yaml +32 -0
- package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
- package/dist/plugins/skills/console/pdl.json +254 -0
- package/dist/plugins/skills/console/view.mjs +204 -0
- package/dist/plugins/skills/index.d.ts +11 -0
- package/dist/plugins/skills/index.js +567 -0
- package/dist/plugins/skills/install.d.ts +69 -0
- package/dist/plugins/skills/install.js +265 -0
- package/dist/plugins/skills/plugin.yaml +24 -0
- package/dist/plugins/skills/safety-scan.d.ts +17 -0
- package/dist/plugins/skills/safety-scan.js +78 -0
- package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
- package/dist/plugins/terminal/console/pdl.json +115 -0
- package/dist/plugins/terminal/console/view.mjs +178 -0
- package/dist/plugins/terminal/index.d.ts +3 -0
- package/dist/plugins/terminal/index.js +204 -0
- package/dist/plugins/terminal/plugin.yaml +2 -0
- package/dist/plugins/tools/index.d.ts +3 -0
- package/dist/plugins/tools/index.js +455 -0
- package/dist/plugins/tools/plugin.yaml +2 -0
- package/dist/plugins/tools/token.d.ts +61 -0
- package/dist/plugins/tools/token.js +179 -0
- package/dist/plugins/topic-tools/index.d.ts +9 -0
- package/dist/plugins/topic-tools/index.js +29 -0
- package/dist/plugins/topic-tools/plugin.yaml +2 -0
- package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
- package/dist/plugins/works/console/pdl.json +120 -0
- package/dist/plugins/works/console/view.mjs +91 -0
- package/dist/plugins/works/document-words.d.ts +50 -0
- package/dist/plugins/works/document-words.js +27 -0
- package/dist/plugins/works/editors.d.ts +3 -0
- package/dist/plugins/works/editors.js +162 -0
- package/dist/plugins/works/events.d.ts +58 -0
- package/dist/plugins/works/events.js +82 -0
- package/dist/plugins/works/files.d.ts +23 -0
- package/dist/plugins/works/files.js +53 -0
- package/dist/plugins/works/index.d.ts +9 -0
- package/dist/plugins/works/index.js +1088 -0
- package/dist/plugins/works/plugin.yaml +9 -0
- package/dist/plugins/works/preview.d.ts +10 -0
- package/dist/plugins/works/preview.js +30 -0
- package/dist/plugins/works/project.d.ts +3 -0
- package/dist/plugins/works/project.js +245 -0
- package/dist/plugins/works/resource.d.ts +28 -0
- package/dist/plugins/works/resource.js +71 -0
- package/dist/plugins/works/retention.d.ts +36 -0
- package/dist/plugins/works/retention.js +295 -0
- package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
- package/dist/plugins/works/viewers.d.ts +13 -0
- package/dist/plugins/works/viewers.js +87 -0
- package/dist/plugins/works/web/anchors.js +94 -0
- package/dist/plugins/works/web/document-edit.js +245 -0
- package/dist/plugins/works/web/preview-bridge.js +142 -0
- package/dist/plugins/works/web/reading-position.js +74 -0
- package/dist/plugins/works/web/view.html +1118 -0
- package/dist/runtime/runtime.d.ts +210 -0
- package/dist/runtime/runtime.js +338 -0
- package/dist/sdk/adapter-kit.d.ts +1 -0
- package/dist/sdk/adapter-kit.js +1 -0
- package/dist/sdk/client.d.ts +163 -0
- package/dist/sdk/client.js +43 -0
- package/dist/sdk/contracts.d.ts +1263 -0
- package/dist/sdk/contracts.js +1 -0
- package/dist/sdk/index.d.ts +57 -0
- package/dist/sdk/index.js +27 -0
- package/dist/sdk/source-choice.d.ts +40 -0
- package/dist/sdk/source-choice.js +217 -0
- package/dist/sdk/topic-text.d.ts +5 -0
- package/dist/sdk/topic-text.js +26 -0
- package/dist/sdk/transport.d.ts +12 -0
- package/dist/sdk/transport.js +34 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
- package/node_modules/@hostlet/adapter-kit/package.json +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.js +270 -0
- package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
- package/node_modules/@hostlet/platform/dist/files.js +113 -0
- package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
- package/node_modules/@hostlet/platform/dist/index.js +4 -0
- package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
- package/node_modules/@hostlet/platform/dist/paths.js +9 -0
- package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
- package/node_modules/@hostlet/platform/dist/process.js +297 -0
- package/node_modules/@hostlet/platform/package.json +14 -0
- package/package.json +60 -4
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* 边界:引擎只放机制与时机,不认任何具体名字、不为单个位置打补丁 */
|
|
2
|
+
/* 平台口(引擎):引擎要用到的平台能力只经这里——网页 / 安装包(桌面)只换平台这一层(platform/)。
|
|
3
|
+
平台层加载时登记自己的实现:platformProvide({ … });没登记的能力是空操作。
|
|
4
|
+
clipboard(文字) 写进剪贴板(不可用时静默)
|
|
5
|
+
download(文件名, 文字或 {url}, 类型) 下载文件或生成文本文件(网页:浏览器下载)
|
|
6
|
+
pickFile(accept, fn) 选一个文件(网页:文件选择器;fn(File))
|
|
7
|
+
pickFiles(accept, fn) 选多个文件(fn(File[]))
|
|
8
|
+
selectFiles({accept, multiple}) 选择浏览器上的文件,返回 Promise<File[]>,取消时为空数组
|
|
9
|
+
assets.get(id) / assets.put(id, descriptor) / assets.remove(id) 本地用户素材的异步读写及删除(src 为可直接使用的短 URL)
|
|
10
|
+
notify(标题, 正文) 系统通知
|
|
11
|
+
richRender(kind, 源文本, inline) 正文里的公式(math)/ Mermaid 图(mermaid)画成 HTML,返回 Promise(没登记时拒绝:正文显示源文本)
|
|
12
|
+
terminal(节点, 选项) 在节点里开一个终端(终端仿真由平台的终端库做),返回 Promise<终端>:write(数据) / reset() / set(选项) / fit() → {cols, rows} / focus() / onData(fn) / onResize(fn) / dispose()(没登记时拒绝)
|
|
13
|
+
uuid() 一个 UUIDv4(网页:用 HTTP 局域网地址打开时也能生成)
|
|
14
|
+
window(动作) 窗口(安装包:最小化、全屏……;网页:无)
|
|
15
|
+
*/
|
|
16
|
+
'use strict';
|
|
17
|
+
const PLATFORM = { clipboard: function () {}, clipboardImage: function () { return Promise.reject(); }, download: function () {}, pickFile: function () {}, pickFiles: function () {}, selectFiles: function () { return Promise.resolve([]); }, notify: function () {}, window: function () {}, richRender: function () { return Promise.reject(); }, terminal: function () { return Promise.reject(); } };
|
|
18
|
+
function platformProvide(impl) { Object.assign(PLATFORM, impl); }
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/* 边界:引擎只放机制与时机,不认任何具体名字、不为单个位置打补丁 */
|
|
2
|
+
/* 投影引擎:运行时状态、三个动作、生效目标、覆盖层级、被盖住的层。这里只有状态和规则,没有画法(画在 frame.js 的 render)。
|
|
3
|
+
三样东西分开:
|
|
4
|
+
- PDL:静态的完整描述——容器树(pdlTree,主题文档里)和哪种内容开到哪个容器;
|
|
5
|
+
- 运行时状态:一个小的、可序列化的对象 NAV——每个容器一栈 { f 帧, a 参数 }、弹窗栈、焦点;
|
|
6
|
+
- 数据:store / 接口。
|
|
7
|
+
渲染 = project(PDL, NAV, 数据):每个容器画它栈顶的那一层。被盖住的层留在 DOM 里(content-visibility: hidden + inert),DOM 就是缓存;
|
|
8
|
+
数据变了它们记成过期,重新露出来时重画一次;出栈的层销毁;每栈最多 NAV_CAP 层,超出时最早被盖住的那层被逐出。
|
|
9
|
+
从外面切换一个容器(换空间、窄栏 / 侧栏里的页面入口)是隐藏不是销毁:切走的栈是兄弟(NAV.kept),切回来原样回来。
|
|
10
|
+
引擎不认容器、页面、面板的名字:容器的角色都是容器树上的声明(pages / space / tabs / cover)。 */
|
|
11
|
+
'use strict';
|
|
12
|
+
const NAV = pdlTrack({ st: {}, fwd: {}, tabs: {}, pop: [], focus: null, seq: 0, kept: {}, spLast: {}, on: {} }, 'NAV'); /* on[容器]:和它的孩子并排打开的节点(beside) */ /* 导航也是界面状态:读过它的块在它变了时重画 */ /* kept[容器]:被切走的兄弟(从外面切换掉的栈,留着);spLast[空间]:离开这个空间时它的页面(回来时回到这里) */
|
|
13
|
+
const NAV_CAP = 5;
|
|
14
|
+
let DATA_VER = 0;
|
|
15
|
+
const LAYER_DOM = {}; /* 层 id → 它在 DOM 里的元素(缓存,不进状态) */
|
|
16
|
+
let NAV_CTX = null; /* 正在画的那一层(S.route / S.param 在画它时读它的帧和参数) */
|
|
17
|
+
|
|
18
|
+
/* ───────── 容器树(PDL 的声明) ───────── */
|
|
19
|
+
function ctNodes() { const out = {}; const walk = function (n, p) { out[n.key] = { n: n, p: p }; (n.kids || []).forEach(function (k) { walk(k, n.key); }); }; walk(pdlTree(), null); return out; }
|
|
20
|
+
function ctNode(k) { const x = ctNodes()[k]; return x ? x.n : null; }
|
|
21
|
+
function ctParent(k) { const x = ctNodes()[k]; return x ? x.p : null; }
|
|
22
|
+
/* 从 k 往上到根(含 k 本身) */
|
|
23
|
+
function ctAnc(k) { const all = ctNodes(), out = []; for (let c = k; c && all[c]; c = all[c].p) out.push(c); return out; }
|
|
24
|
+
/* 按声明找角色:页面容器(空间的页面在它的栈里)、空间容器(第二栏)、标签式容器 */
|
|
25
|
+
function ctRole(prop) { const all = ctNodes(); return Object.keys(all).find(function (k) { return !!all[k].n[prop]; }) || null; }
|
|
26
|
+
function ctPages() { return ctRole('pages'); }
|
|
27
|
+
function ctSpaceC() { return ctRole('space'); }
|
|
28
|
+
/* 能被覆盖的容器 = 有子容器的容器:它的底层是“画它的子容器”('@'),覆盖它的内容压在上面 */
|
|
29
|
+
function ctCoverable(k) { const n = ctNode(k); return !!(n && n.kids && n.kids.length); }
|
|
30
|
+
/* 覆盖层级:容器树上的容器键(由内到外)。默认层级是容器声明的 cover(主题 PDL 里的属性,比如身体容器 cover: 身体) */
|
|
31
|
+
function ctLevels() { const all = ctNodes(); return Object.keys(all).filter(function (k) { return ctCoverable(k) || all[k].n.pages; }); }
|
|
32
|
+
|
|
33
|
+
/* ───────── 栈 ───────── */
|
|
34
|
+
function navId() { NAV.seq += 1; return 'L' + NAV.seq; }
|
|
35
|
+
function navLayer(f, a) { return { id: navId(), f: f, a: a || {} }; }
|
|
36
|
+
function navBase(c) {
|
|
37
|
+
if (ctCoverable(c)) return navLayer('@');
|
|
38
|
+
if (c === ctPages()) return navLayer(startRoute());
|
|
39
|
+
if (c === ctSpaceC()) return navLayer(routeSpace(startRoute()));
|
|
40
|
+
const r = navTabOf(c); if (r) return navLayer(r.k);
|
|
41
|
+
const n = ctNode(c); if (n && n.tabs) return navLayer(rtHome(c));
|
|
42
|
+
return navLayer('@');
|
|
43
|
+
}
|
|
44
|
+
function navStack(c) { if (!NAV.st[c] || !NAV.st[c].length) NAV.st[c] = [navBase(c)]; return NAV.st[c]; }
|
|
45
|
+
function navTop(c) { const s = navStack(c); return s[s.length - 1]; }
|
|
46
|
+
function navDepth(c) { return navStack(c).length; }
|
|
47
|
+
/* 标签式容器里一项的栈键:容器 + '/' + 项 */
|
|
48
|
+
function navTabKey(r, k) { return r + '/' + k; }
|
|
49
|
+
function navTabOf(c) { const i = String(c).indexOf('/'); return i > 0 ? { r: c.slice(0, i), k: c.slice(i + 1) } : null; }
|
|
50
|
+
/* 一层开的是哪个节点(node:<id>,视图或独立页面);页面层不是 */
|
|
51
|
+
function navNodeOf(l) { return l && String(l.f).indexOf('node:') === 0 ? PDL_VIEWS[l.f.slice(5)] || null : null; }
|
|
52
|
+
/* 一层是不是页面(帧是路由),开的是节点时取它声明的路由 */
|
|
53
|
+
function navRouteOf(l) {
|
|
54
|
+
if (!l || l.f === '@') return null;
|
|
55
|
+
if (String(l.f).indexOf('node:') === 0) { const nd = navNodeOf(l); return nd && nd.route ? nd.route : null; }
|
|
56
|
+
return PAGES[l.f] ? l.f : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* ───────── 焦点:最外面一个盖着的投影层;没有就是页面容器的栈顶。S.route / S.param 读它(画某一层时读那一层) ───────── */
|
|
60
|
+
function navCovers() { return ctLevels().filter(ctCoverable).sort(function (a, b) { return ctAnc(a).length - ctAnc(b).length; }); } /* 由外到内 */
|
|
61
|
+
function navFocusC() {
|
|
62
|
+
const cs = navCovers();
|
|
63
|
+
for (let i = 0; i < cs.length; i++) if (navTop(cs[i]).f !== '@') return cs[i];
|
|
64
|
+
return ctPages();
|
|
65
|
+
}
|
|
66
|
+
/* 正在画的那一层是页面就读它;标签式容器里的层是容器的项(键可能和某个页面同名,比如工作台的 home),不是页面 */
|
|
67
|
+
function navRouteLayer() { if (NAV_CTX && navRouteOf(NAV_CTX.l) && !(String(NAV_CTX.c).split('/')[0] in REGION_TABS)) return NAV_CTX.l; return navTop(navFocusC()); }
|
|
68
|
+
Object.defineProperty(S, 'route', { configurable: true, get: function () { return navRouteOf(navRouteLayer()); }, set: function () {} });
|
|
69
|
+
Object.defineProperty(S, 'param', { configurable: true, get: function () { const l = navRouteLayer(); return l && l.a.p != null ? l.a.p : null; }, set: function () {} });
|
|
70
|
+
Object.defineProperty(S, 'space', { configurable: true, get: function () { return ctSpaceC() ? navTop(ctSpaceC()).f : null; }, set: function (v) { if (v && ctSpaceC()) { const t = navTop(ctSpaceC()); if (t.f !== v) { const b = (NAV.st[ctPages()] || [])[0]; if (b) NAV.spLast[t.f] = { f: b.f, a: b.a }; NAV.st[ctSpaceC()] = [navLayer(v)]; } } } }); /* 换空间:记下离开的空间停在哪一页(它的层留着,见 navHide) */
|
|
71
|
+
Object.defineProperty(S, 'popOrder', { configurable: true, get: function () { return NAV.pop; }, set: function (v) { NAV.pop = v; } });
|
|
72
|
+
/* 画一层时:把它设成当前的那一层(页面读 S.route / S.param / navArg) */
|
|
73
|
+
function navWith(c, l, fn) { const prev = NAV_CTX; NAV_CTX = { c: c, l: l }; try { return fn(); } finally { NAV_CTX = prev; } }
|
|
74
|
+
/* 当前这一层的参数(视图模型读它:下钻到哪一项、分视图是哪个)。不在画的时候,读焦点那一层 */
|
|
75
|
+
function navArg(k, c) { const l = c ? navTop(c) : NAV_CTX ? NAV_CTX.l : navTop(navFocusC()); return l && l.a ? l.a[k] : undefined; }
|
|
76
|
+
|
|
77
|
+
/* ───────── 触发元素的容器链(从 DOM 读:层 data-lc、容器 data-c、视图里的分栏 data-ct),再接上容器树的祖先 ───────── */
|
|
78
|
+
function popTrig(t) { const host = t && t.closest && t.closest('.pop-host[data-pop]'), o = host && anchorEl(POP_TRIG[host.dataset.pop]); return o && o !== t ? popTrig(o) : t; }
|
|
79
|
+
function trigChain(t) {
|
|
80
|
+
const inner = []; let c0 = null, lc = null;
|
|
81
|
+
for (let e = t && t.closest ? t : null; e && e !== document.body; e = e.parentElement) {
|
|
82
|
+
const d = e.dataset || {};
|
|
83
|
+
if (d.ct && !lc) inner.push(d.ct);
|
|
84
|
+
if (d.lc && !lc) { lc = d.lc; inner.push(d.lc); }
|
|
85
|
+
if (d.c) { c0 = d.c; break; }
|
|
86
|
+
}
|
|
87
|
+
if (!c0 && t && t.closest && t.closest('.pop-host[data-pop]')) { const k = t.closest('.pop-host[data-pop]').dataset.pop, o = anchorEl(POP_TRIG[k]); if (o && o !== t) return trigChain(o); } /* 弹窗里的触发:按打开这个弹窗的元素算 */
|
|
88
|
+
const tab = lc && navTabOf(lc);
|
|
89
|
+
const tree = ctAnc(tab ? tab.r : c0 || '');
|
|
90
|
+
return { inner: inner, lc: lc, chain: inner.concat(tree.filter(function (x) { return inner.indexOf(x) < 0; })) };
|
|
91
|
+
}
|
|
92
|
+
/* 默认层级:从触发处往外,第一个声明了 cover 的容器给出的层级 */
|
|
93
|
+
/* 从内容里打开、没说开到哪:触发处往外第一个声明了 opens 的容器(容器的默认去处) */
|
|
94
|
+
function navCoverDefault(chain) { for (let i = 0; i < chain.length; i++) { const n = ctNode(chain[i]); if (n && n.opens && n.opens.as !== 'beside') return pdlOpenTarget(n.opens); } return null; }
|
|
95
|
+
/* 生效目标:声明的容器看得见就是它,看不见就是最近的看得见的祖先(窄屏收起、工作台收起、主题里没有这个容器) */
|
|
96
|
+
let CT_SHOWN = {}; /* 上一次投影画出来(看得见)的容器:由 render 记下,不量 DOM */
|
|
97
|
+
function ctVisible(k) { return !!CT_SHOWN[k]; }
|
|
98
|
+
function navEffective(k) { let c = k; while (c && ctNode(c) && !ctVisible(c)) c = ctParent(c); return c || pdlTree().key; }
|
|
99
|
+
|
|
100
|
+
/* ───────── 数据变了:被盖住的层记成过期(露出来时重画一次) ───────── */
|
|
101
|
+
function navStale() { DATA_VER += 1; }
|
|
102
|
+
|
|
103
|
+
/* ───────── 离开(容器层的唯一一处,frame.js 的 leave):要被盖住 / 出栈 / 换掉的层 ───────── */
|
|
104
|
+
function navEls(ids) { const out = []; ids.forEach(function (id) { document.querySelectorAll('[data-layer="' + id + '"]').forEach(function (el) { out.push(el); }); }); return out; }
|
|
105
|
+
/* 一个栈从下标 i 起往上的层(离开时要检查的) */
|
|
106
|
+
function navIdsFrom(c, i) { return navStack(c).slice(i).map(function (l) { return l.id; }); }
|
|
107
|
+
/* 盖住 c 的那些层(c 的祖先上压着的投影):打开 / 切换到 c 时它们都离开 */
|
|
108
|
+
/* 盖着 c 的层:祖先里能覆盖的容器,栈里不是“画子容器”('@')的那些——从外面切换进来时底层本身就是内容 */
|
|
109
|
+
function navCoverFrom(a) { return navStack(a)[0].f === '@' ? 1 : 0; }
|
|
110
|
+
function navCoveringIds(c) { const out = []; ctAnc(ctParent(c) || '').forEach(function (a) { if (ctCoverable(a)) out.push.apply(out, navIdsFrom(a, navCoverFrom(a))); }); return out; }
|
|
111
|
+
function navUncover(c) { ctAnc(ctParent(c) || '').forEach(function (a) { if (!ctCoverable(a) || navDepth(a) <= navCoverFrom(a)) return; navDrop(navStack(a).slice(navCoverFrom(a))); NAV.st[a] = [navCoverFrom(a) ? navStack(a)[0] : navLayer('@')]; }); }
|
|
112
|
+
function navDrop(ls) { ls.forEach(function (l) { (LAYER_DOM[l.id] || []).forEach(function (el) { el.remove(); }); delete LAYER_DOM[l.id]; }); }
|
|
113
|
+
|
|
114
|
+
/* ───────── 三个动作 ─────────
|
|
115
|
+
open:压进生效目标的栈(目标是触发元素的容器或它的祖先 ⇔ 盖住了触发处 ⇔ 有返回);目标不在祖先链上 = 从外面切换这个容器(换掉它的栈,没有返回)。
|
|
116
|
+
back / close:出栈。switch:换掉栈顶(不出返回)。被另一层投影盖住 = 离开,先过未保存确认;被弹窗盖住不算离开。 */
|
|
117
|
+
function navPushRaw(c, f, a, title, exit) {
|
|
118
|
+
const s = navStack(c), top = s[s.length - 1], l = navLayer(f, a);
|
|
119
|
+
top.t = title != null ? title : top.t; top.v = DATA_VER;
|
|
120
|
+
if (exit && exit.length) l.exit = exit;
|
|
121
|
+
s.push(l); NAV.fwd[c] = [];
|
|
122
|
+
while (s.length > NAV_CAP) { const i = ctCoverable(c) || !ctNode(c) ? 1 : 0, ev = s.splice(i, 1); navDrop(ev); } /* 逐出最早被盖住的一层(结构底层不逐出);它从不带未保存的修改:盖住它时已经确认过 */
|
|
123
|
+
return l;
|
|
124
|
+
}
|
|
125
|
+
function navOpen(o, from) {
|
|
126
|
+
const t = from === undefined ? ACT_FROM : from, tc0 = t ? trigChain(t) : { inner: [], lc: navFocusC(), chain: ctAnc(navFocusC()) }, chain = tc0.chain; /* 程序打开(没有触发元素):按在焦点那一层里打开算 */
|
|
127
|
+
let want = o.into === '.' ? tc0.lc || ctPages() : o.into || navCoverDefault(chain) || (o.exit && navCoverDefault(ctAnc(ctPages()))) || ctPages();
|
|
128
|
+
const T = navEffective(want);
|
|
129
|
+
const host = T, push = !!o.push || !!(o.exit && o.exit.length) || chain.indexOf(T) >= 0 || o.into === '.';
|
|
130
|
+
const title = o.title != null ? o.title : navTitleAt(popTrig(t)); /* 弹窗里的触发按打开它的元素取标题 */
|
|
131
|
+
const tn = ctNode(T);
|
|
132
|
+
if (tn && tn.tabs) { navLeave(navCoveringIds(T), function () { navUncover(T); rtOpenContent(T, o, t); navAfter(); if (o.after) o.after(); }); return T; } /* 开进标签式容器:变成它的一项(绑定方说是哪一项) */
|
|
133
|
+
if (push) {
|
|
134
|
+
navLeave(navIdsFrom(host, navDepth(host) - 1).concat(navCoveringIds(host)), function () { navUncover(host); navPushRaw(host, o.f, o.a, title, o.exit); navAfter(); if (o.after) o.after(); });
|
|
135
|
+
return host;
|
|
136
|
+
}
|
|
137
|
+
navSwitchC(host, o.f, o.a, { after: o.after });
|
|
138
|
+
return host;
|
|
139
|
+
}
|
|
140
|
+
/* 页面 / 帧声明了 keep:被别的页面从外面盖住时它留在下面,盖上来的那层有返回回到它(对话被入口打开的记忆盖住);入口之间仍是切换,只换它上面那一层 */
|
|
141
|
+
function navKeptLayer(f) { f = String(f); return !!(f.indexOf('node:') === 0 ? PDL_VIEWS[f.slice(5)] || {} : PDL_PAGES[f] || {}).keep; }
|
|
142
|
+
/* 留在下面的那一层:c 自己栈里的,或者 c 包着页面容器、页面容器现在显示的是它(窄栏入口盖住外壳);返回的是 c 里它之上的那些层被换掉的位置 */
|
|
143
|
+
function navKeptAt(c, f) {
|
|
144
|
+
if (navKeptLayer(f)) return -1;
|
|
145
|
+
const s = navStack(c); for (let i = s.length - 1; i >= 0; i--) if (navKeptLayer(s[i].f)) return i;
|
|
146
|
+
return c !== ctPages() && ctAnc(ctPages()).indexOf(c) >= 0 && navCoverFrom(c) && navKeptLayer(navTop(ctPages()).f) ? 0 : -1;
|
|
147
|
+
}
|
|
148
|
+
function navCoverKept(c, k, f, a, then) {
|
|
149
|
+
const s = navStack(c), kept = navKeptLayer(s[k].f) ? s[k] : navTop(ctPages()), ly = document.querySelector('[data-layer~="' + kept.id + '"]');
|
|
150
|
+
navLeave(navIdsFrom(c, k + 1).concat(navCoveringIds(c)), function () { navUncover(c); navDrop(s.splice(k + 1)); navPushRaw(c, f, a, ly ? navTitleAt(ly) : navTitleNow()); navAfter(); if (then) then(); });
|
|
151
|
+
}
|
|
152
|
+
/* 从外面切换容器 c:c 的栈换成这一层;盖着 c 的层离开。
|
|
153
|
+
切走的栈是兄弟,不销毁(navHide):隐藏 + inert 留在 DOM 里,数据变了记成过期,再切回来(同一个底层)时原样回来——滚动位置、展开状态、输入框里的东西都在。
|
|
154
|
+
能覆盖的容器底层也被换掉(再关就回到底层),它的栈不留。按完整地址直接露出目的页的底层。 */
|
|
155
|
+
function navSwitchC(c, f, a, o) {
|
|
156
|
+
const { after, force, space: nextSpace, address } = o || {};
|
|
157
|
+
const k = force || nextSpace || address ? -1 : navKeptAt(c, f);
|
|
158
|
+
if (k >= 0) { navCoverKept(c, k, f, a, after); return; }
|
|
159
|
+
const own = navIdsFrom(c, 0), dirty = !force && navEls(own).some(leaveDirty);
|
|
160
|
+
(force ? function (ids, fn) { fn(); } : navLeave)(own.concat(navCoveringIds(c)), function () { /* force:程序里的切换(没有触发元素,比如保存之后跳转),不问 */
|
|
161
|
+
if (nextSpace) S.space = nextSpace;
|
|
162
|
+
navUncover(c);
|
|
163
|
+
const s = navStack(c), k = navKey(f, a);
|
|
164
|
+
if (navKey(s[0].f, s[0].a) === k && !ctCoverable(c)) { navDrop(s.slice(1)); NAV.st[c] = [s[0]]; } /* 切到自己的底层:上面的层出栈,底层露出来 */
|
|
165
|
+
else {
|
|
166
|
+
navHide(c, dirty);
|
|
167
|
+
const back = navKeptTake(c, k);
|
|
168
|
+
if (address && back) navDrop(back.st.splice(1));
|
|
169
|
+
NAV.st[c] = back ? back.st : [navLayer(f, a)];
|
|
170
|
+
NAV.fwd[c] = back ? back.fwd : [];
|
|
171
|
+
}
|
|
172
|
+
if (address) NAV.fwd[c] = [];
|
|
173
|
+
navAfter(); if (after) after();
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/* 哪些容器留切走的兄弟:不能覆盖、不是标签式的容器(页面容器) */
|
|
177
|
+
function navKeeps(c) { const n = ctNode(c); return !!n && !ctCoverable(c) && !n.tabs; }
|
|
178
|
+
/* 兄弟栈按底层认(帧 + 参数) */
|
|
179
|
+
function navKey(f, a) { return f + '|' + JSON.stringify(a || {}); }
|
|
180
|
+
/* 切走一个栈:留着(栈顶记下现在的数据版本,离开时放弃过修改的整栈记成过期);能覆盖的容器不留。
|
|
181
|
+
上限和栈一样是 NAV_CAP:所有留着的兄弟一共超过 NAV_CAP 层时,最久没看的那个整栈逐出(它们都过了离开检查,没有未保存的修改,逐出是安全的) */
|
|
182
|
+
function navHide(c, stale) {
|
|
183
|
+
const s = NAV.st[c] || []; if (!s.length) return;
|
|
184
|
+
if (!navKeeps(c)) { navDrop(s); return; }
|
|
185
|
+
s[s.length - 1].v = DATA_VER; if (stale) s.forEach(function (l) { l.v = -1; });
|
|
186
|
+
const k = navKey(s[0].f, s[0].a), kept = NAV.kept[c] = (NAV.kept[c] || []).filter(function (x) { if (navKey(x.st[0].f, x.st[0].a) !== k) return true; navDrop(x.st); return false; });
|
|
187
|
+
kept.push({ st: s, fwd: NAV.fwd[c] || [] });
|
|
188
|
+
const n = function () { return kept.reduce(function (m, x) { return m + x.st.length; }, 0); };
|
|
189
|
+
while (kept.length > 1 && n() > NAV_CAP) navDrop(kept.shift().st);
|
|
190
|
+
}
|
|
191
|
+
function navKeptTake(c, k) { const kept = NAV.kept[c] || [], i = kept.findIndex(function (x) { return navKey(x.st[0].f, x.st[0].a) === k; }); return i < 0 ? null : kept.splice(i, 1)[0]; }
|
|
192
|
+
/* 容器 c 留着的兄弟的层(画的时候放在 c 里,隐藏) */
|
|
193
|
+
function navKeptLayers(c) { return [].concat.apply([], (NAV.kept[c] || []).map(function (x) { return x.st; })); }
|
|
194
|
+
/* 切到空间 v:回到它上次停的那一页(那一页的栈留着就原样回来),没去过就是它的主页 */
|
|
195
|
+
function navSpaceTarget(v) { const l = NAV.spLast[v], home = (PDL_SPACES[v] || {}).home; return l && PAGES[l.f] ? l : home ? { f: home, a: {} } : null; }
|
|
196
|
+
/* 换掉栈顶(同一个容器里的切换:分栏里选另一项、工具里的分视图):不改深度、不出返回 */
|
|
197
|
+
function navReplace(c, f, a) { const top = navTop(c); if (f != null) top.f = f; top.a = a || {}; delete top.t; } /* 同一层换内容:层不变(滚动由通常的重画规则保持) */
|
|
198
|
+
function navBack(c, layer) {
|
|
199
|
+
const s = navStack(c), top = s[s.length - 1], i = layer ? s.findIndex(function (l) { return l.id === layer; }) : s.length - 2;
|
|
200
|
+
if (i < 0 || i >= s.length - 1) return false;
|
|
201
|
+
navLeave(navIdsFrom(c, i + 1), function () {
|
|
202
|
+
if (navTop(c).id !== top.id) return;
|
|
203
|
+
const gone = s.splice(i + 1);
|
|
204
|
+
navDrop(gone);
|
|
205
|
+
const forward = NAV.fwd[c] || (NAV.fwd[c] = []);
|
|
206
|
+
gone.reverse().forEach(function (l) { forward.push({ f: l.f, a: l.a, t: l.t, exit: l.exit }); });
|
|
207
|
+
navAfter();
|
|
208
|
+
});
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
function navForward(c) {
|
|
212
|
+
const fw = NAV.fwd[c]; if (!fw || !fw.length) return false;
|
|
213
|
+
navLeave([navTop(c).id], function () { const x = fw.pop(), keep = fw.slice(); navPushRaw(c, x.f, x.a, undefined, x.exit).t = x.t; NAV.fwd[c] = keep; navAfter(); });
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
/* 关掉容器 c 里换上来的内容(入口再点一下):回到底层 */
|
|
217
|
+
function navClose(c) { navLeave(navIdsFrom(c, 0), function () { navDrop(navStack(c)); NAV.st[c] = [navBase(c)]; navAfter(); }); }
|
|
218
|
+
/* 导航的收尾(登记的钩子):换地方时,旧地方弹出来的东西收起——引擎自己的菜单,加上各层登记在 NAV_RESET 里的(浮窗、抽屉……)。
|
|
219
|
+
o.popupsOnly:导航刚开始(还要过离开检查),只收弹出的东西;抽屉这类布局状态等导航真正完成(navAfter)才收 */
|
|
220
|
+
const NAV_RESET = [];
|
|
221
|
+
function navReset(o) { S.menu = null; NAV_RESET.forEach(function (f) { f(o || {}); }); }
|
|
222
|
+
/* 动作结束后:收起菜单和抽屉(navReset)、写地址(core.js 的 navHash)、重画 */
|
|
223
|
+
function navAfter() { navReset(); navHash(); render(true); }
|
|
224
|
+
/* 离开:要离开的层里有改过没存的表单,先确认 */
|
|
225
|
+
function navLeave(ids, then) { const els = navEls(ids); if (!els.length) { then(); return; } leave(els, bindSpan(then)); }
|
|
226
|
+
/* 压栈时记下被盖住那一层的名字(返回的提示):触发处所在的分栏标题,或者那一层自己的标题 */
|
|
227
|
+
function navTitleAt(t) {
|
|
228
|
+
const pane = t && t.closest && t.closest('[data-ct^="pane"]'), ph = pane && pane.querySelector('h1, h2'); if (ph) return navText(ph);
|
|
229
|
+
const ly = t && t.closest && t.closest('[data-layer]'), ttl = ly && ly.querySelector('[data-title]');
|
|
230
|
+
if (ttl) return navText(ttl);
|
|
231
|
+
const ct = t && t.closest && t.closest('[data-c]'), top = ct && navTop(ct.dataset.c), e = top && pdlEntry(top.f); /* 所在容器没有标题元素:用打开它当前这一层的入口的名字(设置菜单 = 「设置」) */
|
|
232
|
+
if (e && e.title) return e.title;
|
|
233
|
+
return navTitleNow();
|
|
234
|
+
}
|
|
235
|
+
/* 焦点那一层现在的名字:它自己的标题元素,或者功能模块登记的名字(对话页 = 对话名),或者路由的标题。
|
|
236
|
+
标题元素是组件自己声明的标题位(data-title:页头的标题、对话页头的标题),引擎不认组件的类名 */
|
|
237
|
+
function navTitleNow() {
|
|
238
|
+
const ly = document.querySelector('[data-layer~="' + navTop(navFocusC()).id + '"]'), ttl = ly && ly.querySelector('[data-title]');
|
|
239
|
+
return ttl ? navText(ttl) : (NAV_TITLE && NAV_TITLE()) || pdlText(TITLES[S.route] || '');
|
|
240
|
+
}
|
|
241
|
+
/* 标题的文字:不含标题里的图形(名字后的 ?、图标这类 role=img / aria-hidden 的东西) */
|
|
242
|
+
function navText(el) { const c = el.cloneNode(true); c.querySelectorAll('[role="img"], [aria-hidden="true"]').forEach(function (x) { x.remove(); }); return c.textContent.trim(); }
|
|
243
|
+
let NAV_TITLE = null; /* 没有标题元素时的名字(对话页 = 对话名):功能模块登记 */
|
|
244
|
+
function navPageLabel(route) { return pdlText(PDL_PAGES[route]?.label || TITLES[route] || ''); }
|
|
245
|
+
/* 返回槽只收当前栈的名称和目的地;完整地址没有来路时,页面可声明自己的上一级。 */
|
|
246
|
+
function navBackOf(c, rootLabel) {
|
|
247
|
+
const s = navStack(c), b = s[s.length - 1];
|
|
248
|
+
if ((b.exit || []).indexOf('x') >= 0) return null;
|
|
249
|
+
if (s.length === 1) {
|
|
250
|
+
const route = navRouteOf(b), parent = PDL_PAGES[route]?.backTo;
|
|
251
|
+
if (!parent || c !== ctPages()) return null;
|
|
252
|
+
const back = { label: navPageLabel(parent), act: 'open', data: argAttrs({ page: parent, address: true }) };
|
|
253
|
+
return Object.assign({ role: 'page', path: [back, { label: navPageLabel(route) }] }, back);
|
|
254
|
+
}
|
|
255
|
+
const path = s.map(function (l, i) {
|
|
256
|
+
const r = navRouteOf(l), label = REGION_TABS[c]?.title(l.f) || pdlText(PDL_PAGES[r]?.label) || l.t ||
|
|
257
|
+
(i === 0 ? rootLabel : '') || pdlText(navNodeOf(l)?.title) || navPageLabel(r);
|
|
258
|
+
return i === s.length - 1 ? { label: label } : { label: label, act: 'back', data: argAttrs({ c: c, toLayer: l.id }) };
|
|
259
|
+
});
|
|
260
|
+
const a = s[s.length - 2];
|
|
261
|
+
return Object.assign({ role: a.f === b.f ? 'detail' : 'page', path: path }, path[path.length - 2]);
|
|
262
|
+
}
|
|
263
|
+
/* 在某个帧打开着吗(入口的当前项、入口再点一下关掉) */
|
|
264
|
+
function navFrameAt(f) { return Object.keys(NAV.st).find(function (c) { const s = NAV.st[c]; return s.length && s[s.length - 1].f === f; }) || null; }
|
|
265
|
+
|
|
266
|
+
/* ───────── 标签式容器:一组打开的项,一次显示一项;每项一栈(自己的返回 / 前进);会话状态只存一份 ─────────
|
|
267
|
+
NAV.tabs[r] = { list: [{ k, pin, preview }], open, closed, split }(组件可以在上面记自己的界面状态,比如全部标签开没开);当前项是容器 r 自己那一栈的栈顶(从别的项里点过来 = 压栈,有返回)。 */
|
|
268
|
+
function navTabs(r) { if (!NAV.tabs[r]) NAV.tabs[r] = { list: [], open: false }; return NAV.tabs[r]; }
|
|
269
|
+
function navTabCur(r) { const s = NAV.st[r]; return s && s.length ? s[s.length - 1].f : null; }
|
|
270
|
+
|
|
271
|
+
/* ───────── 快照 / 恢复(检查和代理用):整个运行时状态就是一个 JSON ───────── */
|
|
272
|
+
function navSnapshot() { return JSON.parse(JSON.stringify(Object.assign({ st: NAV.st, fwd: NAV.fwd, tabs: NAV.tabs, kept: NAV.kept, spLast: NAV.spLast, pop: NAV.pop, focus: navFocusC(), seq: NAV.seq }, ENGINE_PARTS.navState()))); }
|
|
273
|
+
function navRestore(o) {
|
|
274
|
+
Object.keys(LAYER_DOM).forEach(function (id) { navDrop([{ id: id }]); });
|
|
275
|
+
const x = JSON.parse(JSON.stringify(o));
|
|
276
|
+
NAV.st = x.st || {}; NAV.fwd = x.fwd || {}; NAV.tabs = x.tabs || {}; NAV.kept = x.kept || {}; NAV.spLast = x.spLast || {}; NAV.pop = []; NAV.seq = x.seq || NAV.seq; NAV.focus = x.focus; /* 弹窗用完即弃:恢复时不恢复弹窗 */
|
|
277
|
+
ENGINE_PARTS.navRestore(x);
|
|
278
|
+
navAfter();
|
|
279
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/* 边界:引擎只放机制与时机,不认任何具体名字、不为单个位置打补丁 */
|
|
2
|
+
/* 主题的应用(引擎):当前主题文档里的配色值、字体 / 字号 / 圆角 / 动态效果、背景图、素材,落到根元素上(token 变量、data-theme / data-skin)。
|
|
3
|
+
主题自己的声明(系统主题、配色、素材)在 theme/<主题>/;主题插件带来的配色、自建配色由应用登记来源(THEME_SRC)。 */
|
|
4
|
+
'use strict';
|
|
5
|
+
/* ───────────── 外观与语言:主题 = 给 core.css 顶部那组语义变量一套值 ───────────── */
|
|
6
|
+
/* 主题能设的语义变量(组件库登记:组件库的样式读哪些变量,它就列哪些)。LAYER_DERIVED:其中由层级推导的那几个(叠在所在层上的墨色),主题只给叠多深 d-*;主题包里如果还带着这些的绝对值,不让它们覆盖推导 */
|
|
7
|
+
const TOKENS = [];
|
|
8
|
+
const LAYER_DERIVED = [];
|
|
9
|
+
/* 主题包的 palettes 声明内置主题色。CSS 用 data-skin 选择主题色,默认色直接使用基础变量。 */
|
|
10
|
+
const BUILTIN_PALETTES = [];
|
|
11
|
+
/* 配色的来源(应用登记):packs() 主题插件带来的配色 [{ id, values, … }];own() 旧的自建配色 [{ id, values }](改它自己);saveOwn() 存旧的自建配色 */
|
|
12
|
+
const THEME_SRC = { packs: function () { return []; }, own: function () { return []; }, saveOwn: function () {} };
|
|
13
|
+
function defaultPalette() { return BUILTIN_PALETTES.find(function (x) { return x.default; }).id; }
|
|
14
|
+
/* 一套配色落到页面上的 data-skin:内置的非默认配色用自己的 id,其余(默认、插件带的、自定义的)没有 */
|
|
15
|
+
function paletteAttr(id) { const b = BUILTIN_PALETTES.find(function (x) { return x.id === id; }); return b && !b.default ? b.id : null; }
|
|
16
|
+
function stIsDark() { return S.tweaks.theme === 'dark' || (S.tweaks.theme === 'system' && matchMedia('(prefers-color-scheme: dark)').matches); }
|
|
17
|
+
function stMode() { return stIsDark() ? 'dark' : 'light'; }
|
|
18
|
+
/* 一套配色的值:插件带的配色 = 插件的值 + 当前主题文档里的改动;旧的自建配色 = 它自己的值;内置配色 = 文档里的改动 */
|
|
19
|
+
function themeVals(id) {
|
|
20
|
+
const ov = ((S.pdlDoc && S.pdlDoc.full.tokens) || {})[id] || {}, p = THEME_SRC.packs().find(function (t) { return t.id === id; });
|
|
21
|
+
if (p) return { light: Object.assign({}, p.values.light || {}, ov.light || {}), dark: Object.assign({}, p.values.dark || {}, ov.dark || {}) };
|
|
22
|
+
const c = THEME_SRC.own().find(function (t) { return t.id === id; }); if (c) return c.values;
|
|
23
|
+
return pdlClone(Object.keys(ov).length ? ov : { light: {}, dark: {} });
|
|
24
|
+
}
|
|
25
|
+
/* 改某套配色的值:旧的自建配色直接改它自己;插件带的配色和内置配色(系统主题的一部分,不可改)的改动写进当前主题文档的 tokens——
|
|
26
|
+
当前是系统主题时,pdlDocEdit 先复制出一个自定义主题(带撤销提示),改动落在副本上 */
|
|
27
|
+
function themeValsEdit(id, fn) {
|
|
28
|
+
const own = THEME_SRC.own().find(function (t) { return t.id === id; }); /* 插件带的配色是只读的:改动和内置配色一样进当前主题文档(只读主题上先自动复制出自定义主题) */
|
|
29
|
+
if (own) { own.values.light = own.values.light || {}; own.values.dark = own.values.dark || {}; fn(own.values); THEME_SRC.saveOwn(); return; }
|
|
30
|
+
pdlDocEdit(function (full) { const all = full.tokens = full.tokens || {}, v = all[id] = all[id] || { light: {}, dark: {} }; fn(v); });
|
|
31
|
+
}
|
|
32
|
+
function snapTokens(palette, mode) {
|
|
33
|
+
const de = document.documentElement, sv = { t: de.getAttribute('data-theme'), s: de.getAttribute('data-skin'), st: de.getAttribute('style') };
|
|
34
|
+
de.removeAttribute('style'); de.setAttribute('data-theme', mode); rootAttr('data-skin', paletteAttr(palette));
|
|
35
|
+
const cs = getComputedStyle(de), out = {}; TOKENS.forEach(function (t) { out[t] = cs.getPropertyValue('--' + t).trim(); });
|
|
36
|
+
if (sv.t == null) de.removeAttribute('data-theme'); else de.setAttribute('data-theme', sv.t);
|
|
37
|
+
if (sv.s == null) de.removeAttribute('data-skin'); else de.setAttribute('data-skin', sv.s);
|
|
38
|
+
if (sv.st == null) de.removeAttribute('style'); else de.setAttribute('style', sv.st);
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
function applyThemeVals() {
|
|
42
|
+
const de = document.documentElement; TOKENS.forEach(function (t) { de.style.removeProperty('--' + t); });
|
|
43
|
+
const v = themeVals(S.pdlPalette)[stMode()] || {}; Object.keys(v).forEach(function (k) { if (LAYER_DERIVED.indexOf(k) < 0) de.style.setProperty('--' + k, v[k]); });
|
|
44
|
+
applyStyle(); /* 字体、圆角、缩放在主题值之上(主题值里可能带 font-display) */
|
|
45
|
+
if (typeof applyAssets === 'function') applyAssets(); /* 换皮肤可能换素材 */
|
|
46
|
+
}
|
|
47
|
+
PDL_THEME_SYNC.push(applyTheme, applyThemeVals);
|
|
48
|
+
function toHex(c) { if (/^#[0-9a-f]{6}$/i.test(c)) return c; if (/^#[0-9a-f]{3}$/i.test(c)) return '#' + c.slice(1).split('').map(function (x) { return x + x; }).join(''); const m = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(c); return m ? '#' + [m[1], m[2], m[3]].map(function (x) { return (+x).toString(16).padStart(2, '0'); }).join('') : '#000000'; }
|
|
49
|
+
/* ───────── 字体、字号、圆角、密度 ───────── */
|
|
50
|
+
/* 字体组:[名字, 正文, 标题, 等宽];空 = 用系统那一组。bundled 用内置字体素材(font.inter / font.sc / font.mono,见 font-assets.js),是默认;
|
|
51
|
+
字体栈最后都是系统字体:内置字体加载失败、或者某个字不在子集里,就落到系统字体 */
|
|
52
|
+
const SYS_MONO = 'ui-monospace, "SF Mono", Menlo, Consolas, monospace';
|
|
53
|
+
const FONT_SETS = {
|
|
54
|
+
bundled: [tc('theme.fontOptions.bundled'), '"Inter", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif', null, '"JetBrains Mono", ' + SYS_MONO],
|
|
55
|
+
system: [tc('theme.fontOptions.system'), '-apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif', null, SYS_MONO]
|
|
56
|
+
};
|
|
57
|
+
const RADIUS_SETS = { tight: [tc('theme.compact'), [4, 6, 8, 10]], normal: [tc('theme.radiusOptions.normal'), [6, 8, 12, 16]], round: [tc('theme.radiusOptions.round'), [8, 10, 16, 20]] };
|
|
58
|
+
const STYLE_DEFAULT = { font: 'bundled', readSize: '15', uiScale: '1', radius: 'normal', motion: 'system' };
|
|
59
|
+
/* 字体、字号、圆角、动态效果是主题的一部分:存在当前主题文档的 style 里(系统主题就是默认值)。
|
|
60
|
+
读:S.style 由主题文档推出来;改:styleSet——在系统主题上会先复制出自定义主题(和编辑布局、配色同一套) */
|
|
61
|
+
Object.defineProperty(S, 'style', { configurable: true, get: function () { return Object.assign({}, STYLE_DEFAULT, (S.pdlDoc && S.pdlDoc.full.style) || {}); } });
|
|
62
|
+
function styleSet(patch) { pdlDocEdit(function (full) { full.style = patch ? Object.assign({}, full.style || {}, patch) : {}; }); applyStyle(); render(true); }
|
|
63
|
+
/* 文字大小:用户层的 token 覆盖——正文字号直接给阅读那一档(--fs-read → --fs-xl),界面字号是其余各档和展示字号的倍数(--fs-scale);控件高度、间距不跟着变 */
|
|
64
|
+
const READ_SIZES = ['14', '15', '16', '17', '18'], UI_SCALES = [['0.93', tc('theme.scale.text')], ['1', tc('theme.scale.standard')], ['1.07', tc('theme.scale.large')]];
|
|
65
|
+
function applyStyle() {
|
|
66
|
+
const de = document.documentElement, st = S.style, f = FONT_SETS[st.font] || FONT_SETS[STYLE_DEFAULT.font], base = FONT_SETS.system[1];
|
|
67
|
+
de.style.setProperty('--font-text', f[1] || base);
|
|
68
|
+
de.style.setProperty('--font-display', f[2] || f[1] || base);
|
|
69
|
+
de.style.setProperty('--font-mono', f[3] || FONT_SETS.system[3]);
|
|
70
|
+
de.style.setProperty('--fs-read', (READ_SIZES.indexOf(st.readSize) >= 0 ? st.readSize : '15') + 'px');
|
|
71
|
+
de.style.setProperty('--fs-scale', UI_SCALES.some(function (x) { return x[0] === st.uiScale; }) ? st.uiScale : '1');
|
|
72
|
+
const r = (RADIUS_SETS[st.radius] || RADIUS_SETS.normal)[1];
|
|
73
|
+
['--r-s', '--r-m', '--r-l', '--r-xl'].forEach(function (k, i) { de.style.setProperty(k, r[i] + 'px'); });
|
|
74
|
+
/* 动态效果:跟随系统(prefers-reduced-motion)/ 减少 / 正常。减少 = 时长 token 归零(见 core.css),状态信号不受影响 */
|
|
75
|
+
const sys = matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
76
|
+
de.dataset.motion = st.motion === 'reduce' || (st.motion !== 'normal' && sys) ? 'reduce' : 'normal';
|
|
77
|
+
if (typeof MS_CACHE !== 'undefined') Object.keys(MS_CACHE).forEach(function (k) { delete MS_CACHE[k]; });
|
|
78
|
+
}
|
|
79
|
+
/* 背景是用户外观偏好:图片引用、个人素材目录、默认底面值独立保存;主题切换和导出不包含个人照片。 */
|
|
80
|
+
function bgDefault() { return { home: PDL_LAYOUT.background.image, homeTr: PDL_LAYOUT.background.veil, images: [] }; } /* 缺省的全局素材和窗口底面不透明度由主题布局声明(PDL_LAYOUT.background);自定义素材目录是个人偏好 */
|
|
81
|
+
let BG_LIVE = null; /* 正在拖的底面参数;个人背景写偏好,容器参数写主题结构。 */
|
|
82
|
+
Object.defineProperty(S, 'bg', { configurable: true, enumerable: true, get: function () { return Object.assign(bgDefault(), store.get('background-v1', {}), BG_LIVE || {}); } });
|
|
83
|
+
function bgSet(patch) {
|
|
84
|
+
store.set('background-v1', Object.assign({}, S.bg, patch));
|
|
85
|
+
}
|
|
86
|
+
function bgUrl(kind) {
|
|
87
|
+
if (kind === 'none' || !kind) return '';
|
|
88
|
+
return asset(kind); /* 内置图和自定义图都是素材,不跟随浅深配色自动切换。 */
|
|
89
|
+
}
|
|
90
|
+
/* 容器按父子关系推导不透明度;绝对值截断父级影响,未声明为相对叠加 0%。 */
|
|
91
|
+
function bgState(key) {
|
|
92
|
+
const shell = bgUrl(S.bg.home), planes = {}, defaults = {};
|
|
93
|
+
pdlTreeWalk(PDL_LAYOUT.tree, function (n) { if (n.surface) defaults[n.key] = n.surface; });
|
|
94
|
+
pdlTreeWalk(pdlTree(), function (n, p) {
|
|
95
|
+
const surface = Object.assign({ mode: 'relative', opacity: 0, blur: 0 }, defaults[n.key] || {}, n.surface || {}, BG_LIVE && BG_LIVE.container && BG_LIVE.container.key === n.key ? BG_LIVE.container.surface : {});
|
|
96
|
+
const parent = p ? planes[p.key].value : S.bg.homeTr;
|
|
97
|
+
const value = !p ? S.bg.homeTr : surface.mode === 'absolute' ? surface.opacity : Math.round(100 - (100 - parent) * (100 - surface.opacity) / 100);
|
|
98
|
+
planes[n.key] = { mode: surface.mode, opacity: surface.opacity, blur: surface.blur, value: value };
|
|
99
|
+
});
|
|
100
|
+
return { shell: shell, g: shell ? S.bg.homeTr : 100, veil: shell ? planes[key || ctPages()].value : 100, planes: planes };
|
|
101
|
+
}
|
|
102
|
+
/* 根上的属性只在值变了时写(每次重画都会走到这里;写同样的值也会让浏览器把整页样式重算一遍) */
|
|
103
|
+
function rootAttr(name, v) { const de = document.documentElement; if (de.getAttribute(name) === v) return; if (v == null) de.removeAttribute(name); else de.setAttribute(name, v); }
|
|
104
|
+
function applyTheme() {
|
|
105
|
+
const t = S.tweaks;
|
|
106
|
+
rootAttr('data-theme', t.theme === 'system' ? null : t.theme);
|
|
107
|
+
rootAttr('data-skin', paletteAttr(S.pdlPalette));
|
|
108
|
+
}
|
|
109
|
+
const ASSETS = {}; /* 素材登记(id → { type, mime, src, … }):主题登记自己的素材(theme/<主题>/assets.js),组件和 CSS 只按 id 取 */
|
|
110
|
+
const ASSET_LAYERS = { skins: {}, user: {} }; /* skins[皮肤] / user(当前自定义主题选的素材):{ id: 素材 } */
|
|
111
|
+
function assetSkin() { return typeof S !== 'undefined' && S.pdlSkin ? S.pdlSkin : 'default'; }
|
|
112
|
+
function assetRaw(id) {
|
|
113
|
+
const u = ASSET_LAYERS.user[id]; if (u) return u;
|
|
114
|
+
const sk = ASSET_LAYERS.skins[assetSkin()]; if (sk && sk[id]) return sk[id];
|
|
115
|
+
return ASSETS[id] || null;
|
|
116
|
+
}
|
|
117
|
+
/* 取一个素材的地址(没有就是空串) */
|
|
118
|
+
function asset(id) { const a = assetRaw(id); return a ? a.src : ''; }
|
|
119
|
+
/* 把素材交给 CSS:每个 id 一个变量 --asset-<id 里的点换成横线>,值是 url(…) */
|
|
120
|
+
/* 字体素材(type: 'font')登记成文档字体:同一个家族名只注册一次;加载失败就不管它——字体栈后面是系统字体,自然落过去。
|
|
121
|
+
没写家族名(family)的字体素材不登记:那是主题包自己的组件样式按地址引用的文件 */
|
|
122
|
+
const FONT_DONE = {};
|
|
123
|
+
function applyFonts() {
|
|
124
|
+
if (typeof FontFace === 'undefined' || !document.fonts) return;
|
|
125
|
+
Object.keys(ASSETS).forEach(function (id) {
|
|
126
|
+
const a = assetRaw(id); if (!a || a.type !== 'font' || !a.family || FONT_DONE[a.family + a.src.length]) return;
|
|
127
|
+
FONT_DONE[a.family + a.src.length] = true;
|
|
128
|
+
try { const f = new FontFace(a.family, 'url("' + a.src + '")', { weight: a.weight || 'normal', display: 'swap' }); document.fonts.add(f); f.load().catch(function () { /* 落到系统字体 */ }); } catch (e) { /* 落到系统字体 */ }
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function applyAssets() {
|
|
132
|
+
const de = document.documentElement;
|
|
133
|
+
applyFonts();
|
|
134
|
+
Object.keys(ASSETS).forEach(function (id) { if (ASSETS[id].type === 'font') return; const v = asset(id); de.style.setProperty('--asset-' + id.replace(/\./g, '-'), v ? 'url("' + v + '")' : 'none'); });
|
|
135
|
+
/* 浏览器标签页的图标也是品牌标志这一个素材 */
|
|
136
|
+
let ic = document.querySelector('link[rel="icon"]'); if (!ic) { ic = document.createElement('link'); ic.rel = 'icon'; document.head.appendChild(ic); }
|
|
137
|
+
ic.href = asset('brand.logo');
|
|
138
|
+
}
|
|
139
|
+
/* 颜色按层级推导(主题计算器算的就是这些):
|
|
140
|
+
表面是绝对的几层:窄栏 → 二级栏 → 页面 → 分组 → 浮层(主题计算器给出各层明度)。
|
|
141
|
+
其它都是“叠在所在那层上的墨色”,只有一个透明度:
|
|
142
|
+
悬停 --bg-hover、选中 --bg-selected、内嵌(输入框、选择框这类凹进去的)--bg-field、行内代码 --bg-code、分隔线 --line / --line-strong
|
|
143
|
+
墨色 = 最强的文字色。浅色主题里叠上去就深一档,深色主题里就浅一档;叠在背景图的半透明层上也成立。
|
|
144
|
+
所以一个元素放在哪一层,它的悬停 / 选中自动是那一层的深一档,不需要为某个位置单独配色。 */
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
/* ── OKLCH ⇄ sRGB ── */
|
|
148
|
+
function okToRgb(L, C, H) {
|
|
149
|
+
const hr = H * Math.PI / 180, a = C * Math.cos(hr), b = C * Math.sin(hr);
|
|
150
|
+
const l = Math.pow(L + 0.3963377774 * a + 0.2158037573 * b, 3), m = Math.pow(L - 0.1055613458 * a - 0.0638541728 * b, 3), s = Math.pow(L - 0.0894841775 * a - 1.2914855480 * b, 3);
|
|
151
|
+
return [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s];
|
|
152
|
+
}
|
|
153
|
+
function lin2srgb(x) { x = Math.min(1, Math.max(0, x)); return x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055; }
|
|
154
|
+
function srgb2lin(x) { return x <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4); }
|
|
155
|
+
function okHex(L, C, H) { return '#' + okToRgb(L, C, H).map(function (v) { return ('0' + Math.round(lin2srgb(v) * 255).toString(16)).slice(-2); }).join(''); }
|
|
156
|
+
function hexOk(hex) {
|
|
157
|
+
hex = toHex(hex || '#000000'); const r = srgb2lin(parseInt(hex.slice(1, 3), 16) / 255), g = srgb2lin(parseInt(hex.slice(3, 5), 16) / 255), b = srgb2lin(parseInt(hex.slice(5, 7), 16) / 255);
|
|
158
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b), m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b), s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
159
|
+
const L = 0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s, A = 1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s, B = 0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s;
|
|
160
|
+
let H = Math.atan2(B, A) * 180 / Math.PI; if (H < 0) H += 360;
|
|
161
|
+
return { L: L, C: Math.sqrt(A * A + B * B), H: H };
|
|
162
|
+
}
|
|
163
|
+
function lum(hex) { hex = toHex(hex); return [1, 3, 5].map(function (i) { return srgb2lin(parseInt(hex.slice(i, i + 2), 16) / 255); }).reduce(function (a, v, i) { return a + v * [0.2126, 0.7152, 0.0722][i]; }, 0); }
|
|
164
|
+
function contrast(a, b) { const x = lum(a), y = lum(b); return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); }
|
|
165
|
+
|
|
166
|
+
/* 主题的 token(主题包 pdl.json 的 tokens)写成样式:lengths 登记成长度(读出来是算好的像素);base 是根上的值,queries 按窗口宽度覆盖;
|
|
167
|
+
dark 在跟随系统的深色和手动深色下都生效;skins 是各个配色的浅色 / 深色值(data-skin) */
|
|
168
|
+
function themeTokens(t) {
|
|
169
|
+
const block = function (sel, vars) { const ks = Object.keys(vars || {}); return ks.length ? sel + ' { ' + ks.map(function (k) { return k + ': ' + vars[k]; }).join('; ') + '; }\n' : ''; };
|
|
170
|
+
const dark = function (sel, vars) { return Object.keys(vars || {}).length ? '@media (prefers-color-scheme: dark) { ' + block(sel + ':not([data-theme="light"])', vars) + '}\n' + block(sel + '[data-theme="dark"]', vars) : ''; };
|
|
171
|
+
let css = (t.lengths || []).map(function (n) { return '@property ' + n + " { syntax: '<length>'; inherits: true; initial-value: 0px; }\n"; }).join('') + block(':root', t.base);
|
|
172
|
+
(t.queries || []).forEach(function (q) { css += '@media ' + q.media + ' { ' + block(':root', q.vars) + '}\n'; });
|
|
173
|
+
css += dark(':root', t.dark);
|
|
174
|
+
Object.keys(t.skins || {}).forEach(function (s) { const sel = ':root[data-skin="' + s + '"]'; css += block(sel, t.skins[s].light) + dark(sel, t.skins[s].dark); });
|
|
175
|
+
const el = document.createElement('style'); el.setAttribute('data-theme-tokens', ''); el.textContent = css; document.head.appendChild(el); /* 每次加载一张:主题包的在默认主题之后,同名的盖过默认的 */
|
|
176
|
+
}
|