microui-wc 0.1.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/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +33 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +28 -0
- package/.github/workflows/ci.yml +42 -0
- package/.github/workflows/deploy-pages.yml +112 -0
- package/AGENTS.md +2366 -0
- package/CHANGELOG.md +47 -0
- package/CODE_OF_CONDUCT.md +59 -0
- package/CONTRIBUTING.md +156 -0
- package/LICENSE +190 -0
- package/README.md +254 -0
- package/SECURITY.md +58 -0
- package/app/.generated/routes/alerts.js +8 -0
- package/app/.generated/routes/avatars.js +8 -0
- package/app/.generated/routes/badges.js +8 -0
- package/app/.generated/routes/buttons.js +10 -0
- package/app/.generated/routes/cards.js +10 -0
- package/app/.generated/routes/checkboxes.js +9 -0
- package/app/.generated/routes/chips.js +8 -0
- package/app/.generated/routes/dropdowns.js +9 -0
- package/app/.generated/routes/home.js +7 -0
- package/app/.generated/routes/icons.js +9 -0
- package/app/.generated/routes/inputs.js +10 -0
- package/app/.generated/routes/installation.js +7 -0
- package/app/.generated/routes/layout.js +9 -0
- package/app/.generated/routes/modals.js +9 -0
- package/app/.generated/routes/navbar.js +7 -0
- package/app/.generated/routes/progress.js +9 -0
- package/app/.generated/routes/radios.js +9 -0
- package/app/.generated/routes/switches.js +9 -0
- package/app/.generated/routes/tabs.js +8 -0
- package/app/.generated/routes/toasts.js +9 -0
- package/app/index.html +67 -0
- package/app/pages/alerts.html +23 -0
- package/app/pages/avatars.html +22 -0
- package/app/pages/badges.html +22 -0
- package/app/pages/buttons.html +71 -0
- package/app/pages/cards.html +54 -0
- package/app/pages/checkboxes.html +39 -0
- package/app/pages/chips.html +23 -0
- package/app/pages/dropdowns.html +41 -0
- package/app/pages/home.html +59 -0
- package/app/pages/icons.html +29 -0
- package/app/pages/inputs.html +66 -0
- package/app/pages/installation.html +34 -0
- package/app/pages/layout.html +30 -0
- package/app/pages/modals.html +21 -0
- package/app/pages/navbar.html +22 -0
- package/app/pages/progress.html +35 -0
- package/app/pages/radios.html +40 -0
- package/app/pages/switches.html +39 -0
- package/app/pages/tabs.html +30 -0
- package/app/pages/toasts.html +22 -0
- package/app-dist/index.html +67 -0
- package/app-dist/pages/alerts.html +23 -0
- package/app-dist/pages/avatars.html +22 -0
- package/app-dist/pages/badges.html +22 -0
- package/app-dist/pages/buttons.html +71 -0
- package/app-dist/pages/cards.html +54 -0
- package/app-dist/pages/checkboxes.html +39 -0
- package/app-dist/pages/chips.html +23 -0
- package/app-dist/pages/dropdowns.html +41 -0
- package/app-dist/pages/home.html +59 -0
- package/app-dist/pages/icons.html +29 -0
- package/app-dist/pages/inputs.html +66 -0
- package/app-dist/pages/installation.html +34 -0
- package/app-dist/pages/layout.html +30 -0
- package/app-dist/pages/modals.html +21 -0
- package/app-dist/pages/navbar.html +22 -0
- package/app-dist/pages/progress.html +35 -0
- package/app-dist/pages/radios.html +40 -0
- package/app-dist/pages/switches.html +39 -0
- package/app-dist/pages/tabs.html +30 -0
- package/app-dist/pages/toasts.html +22 -0
- package/app-dist/pages.json +217 -0
- package/app-dist/routes/alerts.js +5 -0
- package/app-dist/routes/avatars.js +1 -0
- package/app-dist/routes/badges.js +1 -0
- package/app-dist/routes/buttons.js +1 -0
- package/app-dist/routes/cards.js +1 -0
- package/app-dist/routes/checkboxes.js +9 -0
- package/app-dist/routes/chips.js +4 -0
- package/app-dist/routes/chunk-019e5e2f.js +5 -0
- package/app-dist/routes/chunk-0m4j19yd.js +2 -0
- package/app-dist/routes/chunk-0tmmp5q0.js +1 -0
- package/app-dist/routes/chunk-10xn709r.js +1 -0
- package/app-dist/routes/chunk-15m2qcda.js +2 -0
- package/app-dist/routes/chunk-1bh8g23n.js +1 -0
- package/app-dist/routes/chunk-1vg0v937.js +1 -0
- package/app-dist/routes/chunk-1zvcgy3j.js +1 -0
- package/app-dist/routes/chunk-2afb0861.js +1 -0
- package/app-dist/routes/chunk-2c6ttpzt.js +5 -0
- package/app-dist/routes/chunk-3dy30fhs.js +1 -0
- package/app-dist/routes/chunk-426dnces.js +13 -0
- package/app-dist/routes/chunk-44kgxery.js +1 -0
- package/app-dist/routes/chunk-47fdnejd.js +33 -0
- package/app-dist/routes/chunk-49a6t2vq.js +1 -0
- package/app-dist/routes/chunk-4fe1rm5b.js +1 -0
- package/app-dist/routes/chunk-4ggmvkta.js +33 -0
- package/app-dist/routes/chunk-4vkz81q7.js +33 -0
- package/app-dist/routes/chunk-4w4tmj8f.js +31 -0
- package/app-dist/routes/chunk-532s62kr.js +31 -0
- package/app-dist/routes/chunk-5hm3bssy.js +33 -0
- package/app-dist/routes/chunk-5vrh24hc.js +1 -0
- package/app-dist/routes/chunk-61pcg25a.js +1 -0
- package/app-dist/routes/chunk-6nfhygvf.js +1 -0
- package/app-dist/routes/chunk-700e7je6.js +33 -0
- package/app-dist/routes/chunk-7fsn17kg.js +1 -0
- package/app-dist/routes/chunk-7k789b32.js +1 -0
- package/app-dist/routes/chunk-7r46q0ys.js +36 -0
- package/app-dist/routes/chunk-86fmc1fr.js +5 -0
- package/app-dist/routes/chunk-8qth37vw.js +1 -0
- package/app-dist/routes/chunk-924wv8n0.js +1 -0
- package/app-dist/routes/chunk-9mbhgxk9.js +1 -0
- package/app-dist/routes/chunk-a216hyd9.js +1 -0
- package/app-dist/routes/chunk-akzxykh9.js +33 -0
- package/app-dist/routes/chunk-b3dcvy8c.js +1 -0
- package/app-dist/routes/chunk-b74zahz5.js +31 -0
- package/app-dist/routes/chunk-bftj53p2.js +5 -0
- package/app-dist/routes/chunk-c01hnz3e.js +1 -0
- package/app-dist/routes/chunk-d8pvv5km.js +1 -0
- package/app-dist/routes/chunk-dev0aezr.js +2 -0
- package/app-dist/routes/chunk-dh6vnv0e.js +1 -0
- package/app-dist/routes/chunk-dn2cbpva.js +36 -0
- package/app-dist/routes/chunk-dvn0my90.js +1 -0
- package/app-dist/routes/chunk-dvq8mnve.js +36 -0
- package/app-dist/routes/chunk-e8c2gc4d.js +5 -0
- package/app-dist/routes/chunk-ejf9ak2x.js +1 -0
- package/app-dist/routes/chunk-f083m55s.js +1 -0
- package/app-dist/routes/chunk-fnrj28s1.js +31 -0
- package/app-dist/routes/chunk-fvg3yjdp.js +31 -0
- package/app-dist/routes/chunk-g7k381n1.js +1 -0
- package/app-dist/routes/chunk-h01kq2ae.js +13 -0
- package/app-dist/routes/chunk-h4dk761v.js +5 -0
- package/app-dist/routes/chunk-hmx91z2x.js +5 -0
- package/app-dist/routes/chunk-hxbg4m42.js +36 -0
- package/app-dist/routes/chunk-jbjnfp2b.js +2 -0
- package/app-dist/routes/chunk-jxtz5vv6.js +36 -0
- package/app-dist/routes/chunk-jxzcs0ey.js +36 -0
- package/app-dist/routes/chunk-kt7wwhcx.js +1 -0
- package/app-dist/routes/chunk-kzptszyc.js +33 -0
- package/app-dist/routes/chunk-mhgca4w4.js +2 -0
- package/app-dist/routes/chunk-mhswxa20.js +1 -0
- package/app-dist/routes/chunk-n8zfeex6.js +1 -0
- package/app-dist/routes/chunk-pee47b2r.js +1 -0
- package/app-dist/routes/chunk-pesmw829.js +1 -0
- package/app-dist/routes/chunk-pgc4c6f3.js +36 -0
- package/app-dist/routes/chunk-q8egegm1.js +1 -0
- package/app-dist/routes/chunk-q9mn2qyq.js +36 -0
- package/app-dist/routes/chunk-qh0rtaf3.js +5 -0
- package/app-dist/routes/chunk-qqhmk6ye.js +2 -0
- package/app-dist/routes/chunk-qrxygmf7.js +33 -0
- package/app-dist/routes/chunk-r46yzksx.js +36 -0
- package/app-dist/routes/chunk-rgpbw2w0.js +5 -0
- package/app-dist/routes/chunk-rnpzv3d8.js +2 -0
- package/app-dist/routes/chunk-s5v8cv05.js +2 -0
- package/app-dist/routes/chunk-sbwn5bpc.js +1 -0
- package/app-dist/routes/chunk-sqbg8jbt.js +33 -0
- package/app-dist/routes/chunk-sv8dqnf7.js +1 -0
- package/app-dist/routes/chunk-t67sw3za.js +1 -0
- package/app-dist/routes/chunk-tjdpqwdf.js +31 -0
- package/app-dist/routes/chunk-tq2mfghg.js +1 -0
- package/app-dist/routes/chunk-ttn10vt6.js +1 -0
- package/app-dist/routes/chunk-v2hzpjxr.js +1 -0
- package/app-dist/routes/chunk-wfjjkw9y.js +1 -0
- package/app-dist/routes/chunk-wt8cxzmf.js +31 -0
- package/app-dist/routes/chunk-x45d372k.js +5 -0
- package/app-dist/routes/chunk-y3wsazkt.js +1 -0
- package/app-dist/routes/chunk-y7pmgc7t.js +33 -0
- package/app-dist/routes/chunk-zefdt2q3.js +31 -0
- package/app-dist/routes/dropdowns.js +6 -0
- package/app-dist/routes/home.js +1 -0
- package/app-dist/routes/icons.js +1 -0
- package/app-dist/routes/inputs.js +12 -0
- package/app-dist/routes/installation.js +1 -0
- package/app-dist/routes/layout.js +1 -0
- package/app-dist/routes/modals.js +7 -0
- package/app-dist/routes/navbar.js +1 -0
- package/app-dist/routes/progress.js +1 -0
- package/app-dist/routes/radios.js +6 -0
- package/app-dist/routes/switches.js +6 -0
- package/app-dist/routes/tabs.js +1 -0
- package/app-dist/routes/toasts.js +16 -0
- package/assets/fonts/material-symbols-mini.woff2 +0 -0
- package/assets/fonts/material-symbols.woff2 +0 -0
- package/assets/fonts/roboto-400.woff2 +0 -0
- package/assets/fonts/roboto-500.woff2 +0 -0
- package/assets/fonts/roboto-700.woff2 +0 -0
- package/assets/logo-banner-400.jpg +0 -0
- package/assets/logo-banner-400.webp +0 -0
- package/assets/logo-banner-800.webp +0 -0
- package/assets/logo-banner.jpg +0 -0
- package/assets/logo-icon-64.jpg +0 -0
- package/assets/logo-icon-64.webp +0 -0
- package/assets/logo-icon.jpg +0 -0
- package/assets/logo-square.jpg +0 -0
- package/bun.lock +312 -0
- package/bunfig.toml +4 -0
- package/custom-elements.json +1916 -0
- package/demo/api/sample-data.json +38 -0
- package/demo/content/alerts.html +115 -0
- package/demo/content/avatars.html +70 -0
- package/demo/content/badges.html +65 -0
- package/demo/content/buttons.html +188 -0
- package/demo/content/callouts.html +91 -0
- package/demo/content/cards.html +121 -0
- package/demo/content/checkboxes.html +178 -0
- package/demo/content/chips.html +67 -0
- package/demo/content/codeblocks.html +101 -0
- package/demo/content/confirms.html +115 -0
- package/demo/content/datatables.html +149 -0
- package/demo/content/dividers.html +119 -0
- package/demo/content/dropdowns.html +89 -0
- package/demo/content/enterprise.html +252 -0
- package/demo/content/home.html +149 -0
- package/demo/content/icons.html +89 -0
- package/demo/content/inputs.html +135 -0
- package/demo/content/installation.html +16 -0
- package/demo/content/layout.html +136 -0
- package/demo/content/modals.html +141 -0
- package/demo/content/navbar.html +70 -0
- package/demo/content/progress.html +119 -0
- package/demo/content/radios.html +88 -0
- package/demo/content/skeletons.html +109 -0
- package/demo/content/spinners.html +96 -0
- package/demo/content/switches.html +84 -0
- package/demo/content/tables.html +124 -0
- package/demo/content/tabs.html +85 -0
- package/demo/content/toasts.html +116 -0
- package/demo/content/tooltips.html +107 -0
- package/demo/content/virtual-lists.html +233 -0
- package/demo/favicon.ico +0 -0
- package/demo/favicon.png +0 -0
- package/demo/full.html +52 -0
- package/demo/iife.html +46 -0
- package/demo/manifest.json +34 -0
- package/demo/pages/datatable-demo.html +237 -0
- package/demo/pages/prompt-ui-demo.html +218 -0
- package/demo/pages/responsive-demo.html +122 -0
- package/demo/pages/schema-form-demo.html +270 -0
- package/demo/robots.txt +6 -0
- package/demo/shell.html +712 -0
- package/demo/sw.js +387 -0
- package/dist/AGENTS.md +2366 -0
- package/dist/README.md +254 -0
- package/dist/chunks/advanced.js +174 -0
- package/dist/chunks/chunk-1nhr1wrq.js +14 -0
- package/dist/chunks/chunk-hssyjbr0.js +2 -0
- package/dist/chunks/chunk-k8etzx0z.js +2 -0
- package/dist/chunks/chunk-rr1et8fg.js +2 -0
- package/dist/chunks/chunk-sjcx4fd5.js +6 -0
- package/dist/chunks/chunk-v1c777xh.js +5 -0
- package/dist/chunks/chunk-w5k5vwjd.js +13 -0
- package/dist/chunks/core.js +10 -0
- package/dist/chunks/display.js +17 -0
- package/dist/chunks/feedback.js +15 -0
- package/dist/chunks/forms.js +48 -0
- package/dist/chunks/layout.js +9 -0
- package/dist/components/chunk-4tezav8r.js +2 -0
- package/dist/components/chunk-fqyb2pms.js +2 -0
- package/dist/components/chunk-h7cdbhxw.js +13 -0
- package/dist/components/chunk-mzd8jwrs.js +2 -0
- package/dist/components/chunk-qwmxyn8e.js +2 -0
- package/dist/components/chunk-redtk47a.js +14 -0
- package/dist/components/mu-alert.js +5 -0
- package/dist/components/mu-api-table.js +33 -0
- package/dist/components/mu-avatar.js +1 -0
- package/dist/components/mu-badge.js +1 -0
- package/dist/components/mu-bottom-nav.js +1 -0
- package/dist/components/mu-button.js +1 -0
- package/dist/components/mu-callout.js +1 -0
- package/dist/components/mu-card.js +1 -0
- package/dist/components/mu-checkbox.js +9 -0
- package/dist/components/mu-chip.js +4 -0
- package/dist/components/mu-code.js +48 -0
- package/dist/components/mu-confirm.js +10 -0
- package/dist/components/mu-container.js +1 -0
- package/dist/components/mu-datatable.js +96 -0
- package/dist/components/mu-divider.js +1 -0
- package/dist/components/mu-doc-page.js +26 -0
- package/dist/components/mu-drawer-item.js +9 -0
- package/dist/components/mu-drawer.js +1 -0
- package/dist/components/mu-dropdown.js +6 -0
- package/dist/components/mu-error-boundary.js +10 -0
- package/dist/components/mu-example.js +38 -0
- package/dist/components/mu-fetch.js +1 -0
- package/dist/components/mu-form.js +1 -0
- package/dist/components/mu-grid.js +1 -0
- package/dist/components/mu-icon.js +5 -0
- package/dist/components/mu-input.js +12 -0
- package/dist/components/mu-layout.js +1 -0
- package/dist/components/mu-lazy.js +1 -0
- package/dist/components/mu-modal.js +7 -0
- package/dist/components/mu-navbar.js +1 -0
- package/dist/components/mu-page.js +1 -0
- package/dist/components/mu-progress.js +1 -0
- package/dist/components/mu-prompt-ui.js +20 -0
- package/dist/components/mu-radio.js +6 -0
- package/dist/components/mu-repeat.js +1 -0
- package/dist/components/mu-router.js +6 -0
- package/dist/components/mu-schema-form.js +76 -0
- package/dist/components/mu-sidebar.js +1 -0
- package/dist/components/mu-skeleton.js +13 -0
- package/dist/components/mu-spinner.js +1 -0
- package/dist/components/mu-stack.js +1 -0
- package/dist/components/mu-switch.js +6 -0
- package/dist/components/mu-table.js +1 -0
- package/dist/components/mu-tabs.js +1 -0
- package/dist/components/mu-textarea.js +11 -0
- package/dist/components/mu-theme-toggle.js +5 -0
- package/dist/components/mu-toast.js +4 -0
- package/dist/components/mu-tooltip.js +10 -0
- package/dist/components/mu-virtual-list.js +33 -0
- package/dist/components.css +1 -0
- package/dist/microui.css +1 -0
- package/dist/microui.d.ts +234 -0
- package/dist/microui.esm.js +549 -0
- package/dist/microui.esm.js.map +79 -0
- package/dist/microui.min.js +549 -0
- package/dist/microui.min.js.map +79 -0
- package/dist/routes/alerts.js +1 -0
- package/dist/routes/avatars.js +1 -0
- package/dist/routes/badges.js +1 -0
- package/dist/routes/buttons.js +1 -0
- package/dist/routes/callouts.js +1 -0
- package/dist/routes/cards.js +1 -0
- package/dist/routes/checkboxes.js +9 -0
- package/dist/routes/chips.js +4 -0
- package/dist/routes/chunk-19wgcncm.js +2 -0
- package/dist/routes/chunk-1khyr3v1.js +33 -0
- package/dist/routes/chunk-4rhxe97g.js +1 -0
- package/dist/routes/chunk-5qah04bh.js +2 -0
- package/dist/routes/chunk-7gfxy70n.js +5 -0
- package/dist/routes/chunk-e86zbeta.js +1 -0
- package/dist/routes/chunk-fagt36h6.js +2 -0
- package/dist/routes/chunk-fed7zr7m.js +1 -0
- package/dist/routes/chunk-hwj7pfwp.js +1 -0
- package/dist/routes/chunk-mhvcs2f8.js +5 -0
- package/dist/routes/chunk-nv3bddmj.js +13 -0
- package/dist/routes/chunk-q3f2aeqe.js +7 -0
- package/dist/routes/chunk-qxxa8trk.js +1 -0
- package/dist/routes/chunk-rw15y9zh.js +1 -0
- package/dist/routes/chunk-sfb7x11v.js +5 -0
- package/dist/routes/chunk-swyhghrm.js +48 -0
- package/dist/routes/chunk-sxddjs2d.js +2 -0
- package/dist/routes/chunk-vby0zg5w.js +17 -0
- package/dist/routes/chunk-w6zqjqqs.js +9 -0
- package/dist/routes/chunk-z960rexd.js +38 -0
- package/dist/routes/codeblocks.js +1 -0
- package/dist/routes/confirms.js +10 -0
- package/dist/routes/datatables.js +96 -0
- package/dist/routes/dividers.js +1 -0
- package/dist/routes/dropdowns.js +6 -0
- package/dist/routes/enterprise.js +15 -0
- package/dist/routes/home.js +1 -0
- package/dist/routes/icons.js +1 -0
- package/dist/routes/inputs.js +22 -0
- package/dist/routes/installation.js +1 -0
- package/dist/routes/layout.js +1 -0
- package/dist/routes/modals.js +1 -0
- package/dist/routes/navbar.js +1 -0
- package/dist/routes/page-components.json +316 -0
- package/dist/routes/progress.js +1 -0
- package/dist/routes/radios.js +6 -0
- package/dist/routes/route-deps.json +156 -0
- package/dist/routes/shell-critical.js +1 -0
- package/dist/routes/shell-deferred.js +1 -0
- package/dist/routes/shell.js +20 -0
- package/dist/routes/skeletons.js +13 -0
- package/dist/routes/spinners.js +1 -0
- package/dist/routes/src/chunks/core.js +36 -0
- package/dist/routes/switches.js +6 -0
- package/dist/routes/tables.js +1 -0
- package/dist/routes/tabs.js +1 -0
- package/dist/routes/toasts.js +1 -0
- package/dist/routes/tooltips.js +10 -0
- package/dist/routes/virtual-lists.js +33 -0
- package/dist/styles/common.css +1 -0
- package/dist/styles/components/animations.css +1 -0
- package/dist/styles/components/avatar.css +1 -0
- package/dist/styles/components/badge.css +1 -0
- package/dist/styles/components/bottom-nav.css +1 -0
- package/dist/styles/components/button.css +1 -0
- package/dist/styles/components/card.css +1 -0
- package/dist/styles/components/checkbox.css +1 -0
- package/dist/styles/components/chip.css +1 -0
- package/dist/styles/components/datatable.css +1 -0
- package/dist/styles/components/divider.css +1 -0
- package/dist/styles/components/drawer-item.css +1 -0
- package/dist/styles/components/drawer.css +1 -0
- package/dist/styles/components/grid.css +1 -0
- package/dist/styles/components/icon.css +1 -0
- package/dist/styles/components/input.css +1 -0
- package/dist/styles/components/layout.css +1 -0
- package/dist/styles/components/navbar.css +1 -0
- package/dist/styles/components/overlays.css +1 -0
- package/dist/styles/components/progress.css +1 -0
- package/dist/styles/components/prompt-ui.css +1 -0
- package/dist/styles/components/radio.css +1 -0
- package/dist/styles/components/schema-form.css +1 -0
- package/dist/styles/components/switch.css +1 -0
- package/dist/styles/components/tabs.css +1 -0
- package/dist/styles/components/tooltip.css +1 -0
- package/dist/styles/components/virtual-list.css +1 -0
- package/dist/tokens.css +1 -0
- package/docs/api-reference.md +175 -0
- package/docs/component-schema.md +231 -0
- package/docs/components.md +269 -0
- package/docs/design-system.md +183 -0
- package/docs/getting-started.md +198 -0
- package/docs/message-protocol.md +262 -0
- package/docs/utility-classes.md +205 -0
- package/lighthouse-audit.mjs +113 -0
- package/package.json +45 -0
- package/scripts/analyze-components.js +105 -0
- package/scripts/build-app.js +193 -0
- package/scripts/build-framework.js +444 -0
- package/scripts/build-utils.js +101 -0
- package/scripts/test-isolated.js +151 -0
- package/server.js +256 -0
- package/src/chunks/advanced.js +27 -0
- package/src/chunks/core.js +61 -0
- package/src/chunks/display.js +25 -0
- package/src/chunks/feedback.js +15 -0
- package/src/chunks/forms.js +25 -0
- package/src/chunks/layout.js +27 -0
- package/src/components/mu-alert.js +96 -0
- package/src/components/mu-api-table.js +167 -0
- package/src/components/mu-avatar.js +94 -0
- package/src/components/mu-badge.js +32 -0
- package/src/components/mu-bottom-nav.js +115 -0
- package/src/components/mu-button.js +61 -0
- package/src/components/mu-callout.js +71 -0
- package/src/components/mu-card.js +36 -0
- package/src/components/mu-checkbox.js +186 -0
- package/src/components/mu-chip.js +125 -0
- package/src/components/mu-code.js +534 -0
- package/src/components/mu-confirm.js +268 -0
- package/src/components/mu-container.js +53 -0
- package/src/components/mu-datatable.js +517 -0
- package/src/components/mu-divider.js +40 -0
- package/src/components/mu-doc-page.js +100 -0
- package/src/components/mu-drawer-item.js +158 -0
- package/src/components/mu-drawer.js +305 -0
- package/src/components/mu-dropdown.js +239 -0
- package/src/components/mu-error-boundary.js +191 -0
- package/src/components/mu-example.js +335 -0
- package/src/components/mu-fetch.js +256 -0
- package/src/components/mu-form.js +133 -0
- package/src/components/mu-grid.js +63 -0
- package/src/components/mu-icon.js +211 -0
- package/src/components/mu-input.js +142 -0
- package/src/components/mu-layout.js +129 -0
- package/src/components/mu-lazy.js +94 -0
- package/src/components/mu-modal.js +160 -0
- package/src/components/mu-navbar.js +71 -0
- package/src/components/mu-page.js +77 -0
- package/src/components/mu-progress.js +54 -0
- package/src/components/mu-prompt-ui.js +382 -0
- package/src/components/mu-radio.js +200 -0
- package/src/components/mu-repeat.js +135 -0
- package/src/components/mu-router.js +169 -0
- package/src/components/mu-schema-form.js +441 -0
- package/src/components/mu-sidebar.js +81 -0
- package/src/components/mu-skeleton.js +69 -0
- package/src/components/mu-spinner.js +30 -0
- package/src/components/mu-stack.js +59 -0
- package/src/components/mu-switch.js +150 -0
- package/src/components/mu-table.js +80 -0
- package/src/components/mu-tabs.js +112 -0
- package/src/components/mu-textarea.js +96 -0
- package/src/components/mu-theme-toggle.js +52 -0
- package/src/components/mu-toast.js +151 -0
- package/src/components/mu-tooltip.js +182 -0
- package/src/components/mu-virtual-list.js +184 -0
- package/src/core/MuElement.js +562 -0
- package/src/core/agent-api.js +771 -0
- package/src/core/breakpoints.js +195 -0
- package/src/core/bus.js +378 -0
- package/src/core/component-schema.js +287 -0
- package/src/core/feature-registry.js +241 -0
- package/src/core/form-state.js +252 -0
- package/src/core/http.js +104 -0
- package/src/core/keyboard.js +105 -0
- package/src/core/layers.js +71 -0
- package/src/core/render.js +201 -0
- package/src/core/ripple.js +158 -0
- package/src/core/router.js +100 -0
- package/src/core/scheduler.js +109 -0
- package/src/core/signals.js +164 -0
- package/src/core/store.js +268 -0
- package/src/core/theme.js +68 -0
- package/src/core/transitions.js +72 -0
- package/src/core/utils.js +30 -0
- package/src/index.d.ts +234 -0
- package/src/index.js +308 -0
- package/src/styles/animations.css +252 -0
- package/src/styles/common.css +82 -0
- package/src/styles/components/animations.css +129 -0
- package/src/styles/components/avatar.css +83 -0
- package/src/styles/components/badge.css +80 -0
- package/src/styles/components/bottom-nav.css +37 -0
- package/src/styles/components/button.css +348 -0
- package/src/styles/components/card.css +138 -0
- package/src/styles/components/checkbox.css +201 -0
- package/src/styles/components/chip.css +93 -0
- package/src/styles/components/datatable.css +180 -0
- package/src/styles/components/divider.css +49 -0
- package/src/styles/components/drawer-item.css +123 -0
- package/src/styles/components/drawer.css +273 -0
- package/src/styles/components/grid.css +189 -0
- package/src/styles/components/icon.css +40 -0
- package/src/styles/components/input.css +203 -0
- package/src/styles/components/layout.css +121 -0
- package/src/styles/components/navbar.css +91 -0
- package/src/styles/components/overlays.css +329 -0
- package/src/styles/components/progress.css +79 -0
- package/src/styles/components/prompt-ui.css +286 -0
- package/src/styles/components/radio.css +17 -0
- package/src/styles/components/schema-form.css +85 -0
- package/src/styles/components/switch.css +69 -0
- package/src/styles/components/tabs.css +145 -0
- package/src/styles/components/tooltip.css +93 -0
- package/src/styles/components/virtual-list.css +36 -0
- package/src/styles/components.css +3677 -0
- package/src/styles/routes/home.css +97 -0
- package/src/styles/tokens.css +675 -0
- package/tests/agents/agent-integration.test.js +76 -0
- package/tests/benchmark.html +296 -0
- package/tests/build/scan-components.test.js +173 -0
- package/tests/components/all-components.test.js +245 -0
- package/tests/components/all-missing-components.test.js +574 -0
- package/tests/components/mu-alert.test.js +113 -0
- package/tests/components/mu-avatar.test.js +148 -0
- package/tests/components/mu-badge.test.js +92 -0
- package/tests/components/mu-button.test.js +112 -0
- package/tests/components/mu-card.test.js +89 -0
- package/tests/components/mu-checkbox.test.js +158 -0
- package/tests/components/mu-chip.test.js +118 -0
- package/tests/components/mu-container.test.js +120 -0
- package/tests/components/mu-divider.test.js +98 -0
- package/tests/components/mu-drawer-item.test.js +199 -0
- package/tests/components/mu-drawer.test.js +96 -0
- package/tests/components/mu-dropdown.test.js +125 -0
- package/tests/components/mu-form.test.js +138 -0
- package/tests/components/mu-grid.test.js +135 -0
- package/tests/components/mu-icon.test.js +110 -0
- package/tests/components/mu-input.test.js +131 -0
- package/tests/components/mu-lazy.test.js +103 -0
- package/tests/components/mu-modal.test.js +275 -0
- package/tests/components/mu-navbar.test.js +101 -0
- package/tests/components/mu-progress.test.js +115 -0
- package/tests/components/mu-radio.test.js +114 -0
- package/tests/components/mu-repeat.test.js +106 -0
- package/tests/components/mu-sidebar.test.js +126 -0
- package/tests/components/mu-skeleton.test.js +162 -0
- package/tests/components/mu-stack.test.js +143 -0
- package/tests/components/mu-switch.test.js +292 -0
- package/tests/components/mu-table.test.js +124 -0
- package/tests/components/mu-tabs.test.js +104 -0
- package/tests/components/mu-textarea.test.js +115 -0
- package/tests/components/mu-toast.test.js +321 -0
- package/tests/components/mu-tooltip.test.js +133 -0
- package/tests/components/mu-virtual-list.test.js +109 -0
- package/tests/core/MuElement.test.js +120 -0
- package/tests/core/agent-api.test.js +125 -0
- package/tests/core/all-core-modules.test.js +442 -0
- package/tests/core/bus.test.js +364 -0
- package/tests/core/component-schema.test.js +160 -0
- package/tests/core/feature-registry.test.js +198 -0
- package/tests/core/form-state.test.js +167 -0
- package/tests/core/http.test.js +119 -0
- package/tests/core/keyboard.test.js +319 -0
- package/tests/core/layers.test.js +129 -0
- package/tests/core/namespaced-stores.test.js +114 -0
- package/tests/core/render.test.js +121 -0
- package/tests/core/ripple.test.js +131 -0
- package/tests/core/router.test.js +89 -0
- package/tests/core/scheduler.test.js +121 -0
- package/tests/core/signals.test.js +128 -0
- package/tests/core/store.test.js +171 -0
- package/tests/core/transitions.test.js +82 -0
- package/tests/e2e/accessibility-harness.html +58 -0
- package/tests/e2e/accessibility.test.js +401 -0
- package/tests/e2e/agent-features.test.js +372 -0
- package/tests/e2e/card-spacing.test.js +287 -0
- package/tests/e2e/components.test.js +439 -0
- package/tests/e2e/demo-routes.test.js +478 -0
- package/tests/e2e/layout-css-fallback.test.js +334 -0
- package/tests/e2e/mu-alert.e2e.test.js +111 -0
- package/tests/e2e/mu-checkbox.test.js +489 -0
- package/tests/e2e/mu-chip.test.js +347 -0
- package/tests/e2e/mu-form.test.js +499 -0
- package/tests/e2e/mu-icon.test.js +114 -0
- package/tests/e2e/mu-radio.test.js +113 -0
- package/tests/e2e/mu-skeleton.test.js +140 -0
- package/tests/e2e/mu-switch.test.js +415 -0
- package/tests/e2e/mu-tabs.test.js +494 -0
- package/tests/e2e/mu-textarea.test.js +242 -0
- package/tests/e2e/mu-virtual-list.test.js +427 -0
- package/tests/e2e/perf-memory.test.js +161 -0
- package/tests/e2e/puppeteer-helper.js +137 -0
- package/tests/e2e/puppeteer.test.js +226 -0
- package/tests/e2e/pwa.test.js +261 -0
- package/tests/e2e/test-harness.html +319 -0
- package/tests/manual/test-components.html +120 -0
- package/tests/memory-test.html +309 -0
- package/tests/setup-dom.js +93 -0
- package/tests/visual-test.html +301 -0
package/dist/README.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="demo/icons/icon-192x192.png" alt="microUI" width="80">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">microUI</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>The AI-First Web Components Framework</strong><br>
|
|
9
|
+
<sub>49 Components • 808 Tests Passing • 100% Lighthouse • Zero Config</sub>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
<img src="https://img.shields.io/badge/tests-808%20passing-brightgreen" alt="808 tests">
|
|
14
|
+
<img src="https://img.shields.io/badge/lighthouse-100%25-brightgreen" alt="100% Lighthouse">
|
|
15
|
+
<img src="https://img.shields.io/badge/security-Grade%20A-brightgreen" alt="Security Grade A">
|
|
16
|
+
<img src="https://img.shields.io/badge/bundle-8KB%20initial-blue" alt="8KB initial">
|
|
17
|
+
<img src="https://img.shields.io/badge/license-Apache--2.0-blue" alt="Apache 2.0">
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Why microUI?
|
|
23
|
+
|
|
24
|
+
| Feature | microUI | React | Vue | Svelte |
|
|
25
|
+
|---------|:-------:|:-----:|:---:|:------:|
|
|
26
|
+
| Zero dependencies | ✅ | ❌ | ❌ | ❌ |
|
|
27
|
+
| Native Web Components | ✅ | ❌ | ❌ | ❌ |
|
|
28
|
+
| AI Agent optimized | ✅ | ❌ | ❌ | ❌ |
|
|
29
|
+
| Config required | None | Babel, Webpack | Vite/CLI | Rollup |
|
|
30
|
+
| Initial bundle | **8 KB** | ~45 KB | ~35 KB | ~15 KB |
|
|
31
|
+
| Learning curve | HTML | JSX + Hooks | SFC + Composition | Runes |
|
|
32
|
+
|
|
33
|
+
> **Stop reinventing the wheel.** microUI gives you production-ready components with Material Design 3, full accessibility, and perfect Lighthouse scores—out of the box.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## ⚡ From Zero to UI in 30 Seconds
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<!DOCTYPE html>
|
|
41
|
+
<html lang="en">
|
|
42
|
+
<head>
|
|
43
|
+
<link rel="stylesheet" href="https://unpkg.com/microui/dist/microui.css">
|
|
44
|
+
</head>
|
|
45
|
+
<body>
|
|
46
|
+
<mu-card variant="elevated">
|
|
47
|
+
<h2>Hello microUI! 👋</h2>
|
|
48
|
+
<mu-button variant="filled">Get Started</mu-button>
|
|
49
|
+
</mu-card>
|
|
50
|
+
<script type="module" src="https://unpkg.com/microui/dist/microui.esm.js"></script>
|
|
51
|
+
</body>
|
|
52
|
+
</html>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**That's it.** No npm. No config. No build step. Just works.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 🎯 49 Production-Ready Components
|
|
60
|
+
|
|
61
|
+
<table>
|
|
62
|
+
<tr>
|
|
63
|
+
<td width="25%">
|
|
64
|
+
|
|
65
|
+
**📐 Layout (8)**
|
|
66
|
+
- `mu-stack`
|
|
67
|
+
- `mu-grid`
|
|
68
|
+
- `mu-container`
|
|
69
|
+
- `mu-navbar`
|
|
70
|
+
- `mu-sidebar`
|
|
71
|
+
- `mu-drawer`
|
|
72
|
+
- `mu-bottom-nav`
|
|
73
|
+
- `mu-divider`
|
|
74
|
+
|
|
75
|
+
</td>
|
|
76
|
+
<td width="25%">
|
|
77
|
+
|
|
78
|
+
**📝 Forms (10)**
|
|
79
|
+
- `mu-button`
|
|
80
|
+
- `mu-input`
|
|
81
|
+
- `mu-textarea`
|
|
82
|
+
- `mu-checkbox`
|
|
83
|
+
- `mu-switch`
|
|
84
|
+
- `mu-radio`
|
|
85
|
+
- `mu-dropdown`
|
|
86
|
+
- `mu-form`
|
|
87
|
+
- `mu-chip`
|
|
88
|
+
- `mu-slider`
|
|
89
|
+
|
|
90
|
+
</td>
|
|
91
|
+
<td width="25%">
|
|
92
|
+
|
|
93
|
+
**🎨 Display (12)**
|
|
94
|
+
- `mu-card`
|
|
95
|
+
- `mu-tabs`
|
|
96
|
+
- `mu-avatar`
|
|
97
|
+
- `mu-badge`
|
|
98
|
+
- `mu-icon`
|
|
99
|
+
- `mu-table`
|
|
100
|
+
- `mu-skeleton`
|
|
101
|
+
- `mu-tooltip`
|
|
102
|
+
- `mu-lazy`
|
|
103
|
+
- `mu-repeat`
|
|
104
|
+
- `mu-virtual-list`
|
|
105
|
+
- `mu-image`
|
|
106
|
+
|
|
107
|
+
</td>
|
|
108
|
+
<td width="25%">
|
|
109
|
+
|
|
110
|
+
**💬 Feedback (6)**
|
|
111
|
+
- `mu-alert`
|
|
112
|
+
- `mu-modal`
|
|
113
|
+
- `mu-toast`
|
|
114
|
+
- `mu-progress`
|
|
115
|
+
- `mu-spinner`
|
|
116
|
+
- `mu-dialog`
|
|
117
|
+
|
|
118
|
+
</td>
|
|
119
|
+
</tr>
|
|
120
|
+
</table>
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 🤖 Built for AI Agents
|
|
125
|
+
|
|
126
|
+
microUI is the **only framework designed specifically for AI coding agents**:
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
// Agent SDK - Query components semantically
|
|
130
|
+
import { findByLabel, findByRole } from 'microui/agent-api';
|
|
131
|
+
|
|
132
|
+
const submitBtn = findByLabel('Submit')[0];
|
|
133
|
+
const allInputs = findByRole('textbox');
|
|
134
|
+
|
|
135
|
+
// MCP Protocol support for multi-agent orchestration
|
|
136
|
+
import { registerWithCrossBus } from 'microui';
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Features for AI:**
|
|
140
|
+
- 🔍 **Semantic queries** - Find elements by label, role, or state
|
|
141
|
+
- 📡 **CrossBus integration** - Cross-context messaging for multi-agent apps
|
|
142
|
+
- 🧩 **Declarative HTML** - AI-friendly, no JSX/TSX complexity
|
|
143
|
+
- 📄 **Agent documentation** - See [AGENTS.md](./AGENTS.md)
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## 📱 MD3 Responsive Breakpoints
|
|
148
|
+
|
|
149
|
+
microUI follows **Material Design 3 Window Size Classes** for adaptive layouts:
|
|
150
|
+
|
|
151
|
+
| Class | Width | Behavior |
|
|
152
|
+
|-------|-------|----------|
|
|
153
|
+
| **Compact** | < 600px | Mobile: single column, bottom nav |
|
|
154
|
+
| **Medium** | 600-839px | Tablet: rail navigation |
|
|
155
|
+
| **Expanded** | ≥ 840px | Desktop: full sidebar |
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
// Import the centralized breakpoints utility
|
|
159
|
+
import { breakpoints } from 'microui/core/breakpoints';
|
|
160
|
+
|
|
161
|
+
// Reactive subscriptions
|
|
162
|
+
breakpoints.subscribe((size) => {
|
|
163
|
+
console.log(`Now in ${size} mode`); // 'compact', 'medium', 'expanded'
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Direct checks (live queries)
|
|
167
|
+
if (breakpoints.isCompact) {
|
|
168
|
+
// Mobile-specific logic
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Automatic Grid Collapse**: `<mu-grid cols="3">` automatically collapses to 1 column on mobile.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 📊 Battle-Tested
|
|
177
|
+
|
|
178
|
+
| Metric | Value |
|
|
179
|
+
|--------|-------|
|
|
180
|
+
| Unit tests | **808 passing** |
|
|
181
|
+
| Test coverage | Components: 100% |
|
|
182
|
+
| Lighthouse Performance | **100** |
|
|
183
|
+
| Lighthouse Accessibility | **100** |
|
|
184
|
+
| Lighthouse Best Practices | **100** |
|
|
185
|
+
| Lighthouse SEO | **100** |
|
|
186
|
+
| Security audit | **Grade A** (Low Risk) |
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## 📦 Installation
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
# npm
|
|
194
|
+
npm install microui
|
|
195
|
+
|
|
196
|
+
# bun (recommended)
|
|
197
|
+
bun add microui
|
|
198
|
+
|
|
199
|
+
# CDN (no install)
|
|
200
|
+
<script type="module" src="https://unpkg.com/microui"></script>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 🛠️ Building Apps
|
|
206
|
+
|
|
207
|
+
Create pages in `app/pages/`:
|
|
208
|
+
|
|
209
|
+
```html
|
|
210
|
+
<!-- app/pages/dashboard.html -->
|
|
211
|
+
<mu-page route="dashboard" title="Dashboard">
|
|
212
|
+
<script type="x-dependencies">mu-card, mu-grid</script>
|
|
213
|
+
<template>
|
|
214
|
+
<h1>Dashboard</h1>
|
|
215
|
+
<mu-grid cols="3" gap="md">
|
|
216
|
+
<mu-card>Widget 1</mu-card>
|
|
217
|
+
<mu-card>Widget 2</mu-card>
|
|
218
|
+
</mu-grid>
|
|
219
|
+
</template>
|
|
220
|
+
</mu-page>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
bun run build # Builds framework + app with route-based code splitting
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## 📚 Documentation
|
|
230
|
+
|
|
231
|
+
| Document | Description |
|
|
232
|
+
|----------|-------------|
|
|
233
|
+
| [Getting Started](./docs/getting-started.md) | Installation and first steps |
|
|
234
|
+
| [Components](./docs/components.md) | Full component reference |
|
|
235
|
+
| [Design System](./docs/design-system.md) | MD3 tokens and theming |
|
|
236
|
+
| [Agent Guide](./AGENTS.md) | For AI coding agents |
|
|
237
|
+
| [Security](./SECURITY.md) | Security policy and audit |
|
|
238
|
+
| [API Reference](./docs/api-reference.md) | Complete API docs |
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## 🤝 Join the Community
|
|
243
|
+
|
|
244
|
+
- ⭐ **Star this repo** to show support
|
|
245
|
+
- 🐛 **Report issues** on GitHub
|
|
246
|
+
- 💡 **Suggest features** in Discussions
|
|
247
|
+
- 🤖 **Built with microUI?** Let us know!
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
<p align="center">
|
|
252
|
+
<sub>Apache-2.0 © 2026 Giuseppe Scotto Lavina</sub><br>
|
|
253
|
+
<sub>Made with ❤️ for developers and AI agents alike</sub>
|
|
254
|
+
</p>
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import{s as N,v as T}from"./chunk-hssyjbr0.js";import{z as F}from"./chunk-k8etzx0z.js";import{A as z,B as Z}from"./chunk-rr1et8fg.js";class L extends z{static baseClass="mu-virtual-list";static cssFile="virtual-list";static observedAttributes=["item-height","buffer"];#Q=[];#W=(Y)=>`<div>${Y}</div>`;#Y=0;#X=0;#$=0;#G=null;#U=null;set items(Y){this.#Q=Y||[],this.#J()}get items(){return this.#Q}set renderItem(Y){this.#W=Y,this.#J()}connectedCallback(){super.connectedCallback()}render(){let Y=parseInt(this.attr("item-height","50"));this.innerHTML=`
|
|
2
|
+
<div class="mu-virtual-list__viewport" style="
|
|
3
|
+
height: 100%;
|
|
4
|
+
overflow-y: auto;
|
|
5
|
+
position: relative;
|
|
6
|
+
">
|
|
7
|
+
<div class="mu-virtual-list__content" style="
|
|
8
|
+
position: relative;
|
|
9
|
+
">
|
|
10
|
+
<div class="mu-virtual-list__items"></div>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
`,this.#G=this.querySelector(".mu-virtual-list__viewport"),this.#U=this.querySelector(".mu-virtual-list__content");let W=T(()=>{this.#Y=this.#G.scrollTop,this.#J()},16);this.listen(this.#G,"scroll",W),this.style.display="block",this.style.height="400px",this.style.overflow="hidden",this.#J()}#J(){if(!this.#G||!this.#Q.length)return;let Y=parseInt(this.attr("item-height","50")),W=parseInt(this.attr("buffer","5")),G=this.#G.clientHeight,$=this.#Q.length*Y;this.#U.style.height=`${$}px`;let J=Math.max(0,Math.floor(this.#Y/Y)-W),Q=Math.ceil(G/Y)+W*2,X=Math.min(this.#Q.length,J+Q);if(J!==this.#X||X!==this.#$)this.#X=J,this.#$=X,this.#K()}async#K(){let Y=parseInt(this.attr("item-height","50")),W=this.querySelector(".mu-virtual-list__items");if(!W)return;let G=this.#Q.slice(this.#X,this.#$),$=50;if(G.length>$&&"scheduler"in window){let Q=[];for(let X=0;X<G.length;X+=$){let U=G.slice(X,X+$);if(Q.push(...U.map((O,K)=>{let q=this.#X+X+K;return`
|
|
14
|
+
<div class="mu-virtual-list__item" style="
|
|
15
|
+
position: absolute;
|
|
16
|
+
top: ${q*Y}px;
|
|
17
|
+
left: 0;
|
|
18
|
+
right: 0;
|
|
19
|
+
height: ${Y}px;
|
|
20
|
+
" data-index="${q}" data-mu-state="visible">
|
|
21
|
+
${this.#W(O,q)}
|
|
22
|
+
</div>
|
|
23
|
+
`})),X+$<G.length)await scheduler.yield()}W.innerHTML=Q.join("")}else W.innerHTML=G.map((Q,X)=>{let U=this.#X+X;return`
|
|
24
|
+
<div class="mu-virtual-list__item" style="
|
|
25
|
+
position: absolute;
|
|
26
|
+
top: ${U*Y}px;
|
|
27
|
+
left: 0;
|
|
28
|
+
right: 0;
|
|
29
|
+
height: ${Y}px;
|
|
30
|
+
" data-index="${U}" data-mu-state="visible">
|
|
31
|
+
${this.#W(Q,U)}
|
|
32
|
+
</div>
|
|
33
|
+
`}).join("")}scrollToIndex(Y){let W=parseInt(this.attr("item-height","50"));this.#G.scrollTop=Y*W}}Z("mu-virtual-list",L);class D extends z{static baseClass="mu-lazy";static observedAttributes=["root-margin","threshold"];#Q=null;#W=!1;connectedCallback(){super.connectedCallback();let Y=this.attr("root-margin","200px"),W=parseFloat(this.attr("threshold","0"));this.#Q=new IntersectionObserver((G)=>{if(G[0].isIntersecting&&!this.#W)this.#Y()},{rootMargin:Y,threshold:W}),this.#Q.observe(this)}disconnectedCallback(){super.disconnectedCallback(),this.#Q?.disconnect()}render(){let Y=this.querySelector('[slot="placeholder"]');if(Y)Y.style.display="block";let W=this.querySelector("template");if(W)W.style.display="none"}#Y(){this.#W=!0,this.#Q?.disconnect();let Y=this.querySelector("template"),W=this.querySelector('[slot="placeholder"]');if(Y){let G=Y.content.cloneNode(!0);this.appendChild(G),Y.remove()}if(W)W.remove();this.emit("mu-loaded"),this.classList.add("is-loaded")}load(){if(!this.#W)this.#Y()}}Z("mu-lazy",D);class j extends z{static baseClass="mu-repeat";static observedAttributes=[];#Q=[];#W=(Y,W)=>W;#Y=(Y)=>`<div>${JSON.stringify(Y)}</div>`;#X=new Map;set items(Y){let W=this.#Q;this.#Q=Y||[],N.schedule(()=>this.#$(W))}get items(){return this.#Q}set keyFn(Y){this.#W=Y}set renderItem(Y){this.#Y=Y}render(){this.style.display="contents"}#$(Y){let W=new Set,G=document.createDocumentFragment();for(let J=0;J<this.#Q.length;J++){let Q=this.#W(this.#Q[J],J);W.add(Q)}for(let[J,Q]of this.#X)if(!W.has(J))Q.remove(),this.#X.delete(J);let $=null;for(let J=0;J<this.#Q.length;J++){let Q=this.#Q[J],X=this.#W(Q,J),U=this.#X.get(X);if(!U){let O=document.createElement("div");O.innerHTML=this.#Y(Q,J),U=O.firstElementChild||O,U.dataset.muKey=X,this.#X.set(X,U)}else{let O=this.#Y(Q,J);if(U.outerHTML!==O){let K=document.createElement("div");K.innerHTML=O;let q=K.firstElementChild||K;q.dataset.muKey=X,U.replaceWith(q),this.#X.set(X,q),U=q}}if($){if(U.previousElementSibling!==$)$.after(U)}else if(this.firstElementChild!==U)this.prepend(U);$=U}}getElement(Y){return this.#X.get(Y)}refresh(){this.#X.clear(),this.innerHTML="",N.schedule(()=>this.#$([]))}}Z("mu-repeat",j);class x extends z{static baseClass="mu-code";static observedAttributes=["language"];#Q=null;connectedCallback(){if(super.connectedCallback(),!this.#Q&&!this.querySelector(".mu-code__content"))this.#Q=this.textContent}render(){if(this.querySelector(".mu-code__content"))return;let Y=this.attr("language","html"),W=this.#Q||this.innerHTML,G=document.createElement("div");G.innerHTML=W;let $=G.textContent,J=this.#Y($),Q=this.#X(J,Y),X=Q,U=Q.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),O=this.#W(U,Y);this.innerHTML=`
|
|
34
|
+
<div class="mu-code__header">
|
|
35
|
+
<span class="mu-code__language">${Y.toUpperCase()}</span>
|
|
36
|
+
<button class="mu-code__copy" title="Copy code">
|
|
37
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
38
|
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
|
|
39
|
+
<path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/>
|
|
40
|
+
</svg>
|
|
41
|
+
</button>
|
|
42
|
+
</div>
|
|
43
|
+
<pre class="mu-code__pre"><code class="mu-code__content">${O}</code></pre>
|
|
44
|
+
`,this.#$(),this.#G(X)}#W(Y,W){let G=()=>{let $=[],J=0;return{addMarker:(U,O)=>{let K=J++,q=String.fromCharCode(57600+K),P=String.fromCharCode(57344),A=String.fromCharCode(57345),V=P+q+A;return $.push({marker:V,content:U,className:O}),V},resolveMarkers:(U)=>{for(let{marker:O,content:K,className:q}of $)U=U.replace(O,`<span class="${q}">${K}</span>`);return U}}};if(W==="html"||W==="xml"){let{addMarker:$,resolveMarkers:J}=G(),Q=Y;return Q=Q.replace(/(<!--[\s\S]*?-->)/g,(X)=>$(X,"mu-code__comment")),Q=Q.replace(/(<!DOCTYPE[^&]*>)/gi,(X)=>$(X,"mu-code__keyword")),Q=Q.replace(/("[^"]*")/g,(X)=>$(X,"mu-code__string")),Q=Q.replace(/(\s)([\w-]+)(=)/g,(X,U,O,K)=>`${U}${$(O,"mu-code__attr")}${K}`),Q=Q.replace(/(<\/?)([\w-]+)/g,(X,U,O)=>`${U}${$(O,"mu-code__tag")}`),J(Q)}if(W==="javascript"||W==="js"||W==="typescript"||W==="ts"){let{addMarker:$,resolveMarkers:J}=G(),Q=Y;return Q=Q.replace(/(\/\*[\s\S]*?\*\/)/g,(X)=>$(X,"mu-code__comment")),Q=Q.replace(/(\/\/.*)/g,(X)=>$(X,"mu-code__comment")),Q=Q.replace(/(`[^`]*`)/g,(X)=>$(X,"mu-code__string")),Q=Q.replace(/('[^']*'|"[^"]*")/g,(X)=>$(X,"mu-code__string")),Q=Q.replace(/\b(\d+\.?\d*(?:e[+-]?\d+)?)\b/gi,(X)=>$(X,"mu-code__number")),Q=Q.replace(/\b(const|let|var|function|return|if|else|for|while|do|switch|case|break|continue|class|extends|import|export|from|default|async|await|new|this|super|typeof|instanceof|in|of|try|catch|finally|throw|yield|static|get|set)\b/g,(X)=>$(X,"mu-code__keyword")),Q=Q.replace(/\b(true|false|null|undefined|NaN|Infinity)\b/g,(X)=>$(X,"mu-code__builtin")),Q=Q.replace(/\b([a-zA-Z_]\w*)\s*(?=\()/g,(X,U)=>$(U,"mu-code__function")),J(Q)}if(W==="css"||W==="scss"||W==="sass"){let{addMarker:$,resolveMarkers:J}=G(),Q=Y;return Q=Q.replace(/(\/\*[\s\S]*?\*\/)/g,(X)=>$(X,"mu-code__comment")),Q=Q.replace(/('[^']*'|"[^"]*")/g,(X)=>$(X,"mu-code__string")),Q=Q.replace(/(@[\w-]+)/g,(X)=>$(X,"mu-code__keyword")),Q=Q.replace(/\b(\d+\.?\d*)(px|em|rem|%|vh|vw|s|ms|deg|fr)\b/g,(X,U,O)=>`${$(U,"mu-code__number")}${$(O,"mu-code__builtin")}`),Q=Q.replace(/\b(\d+\.?\d*)\b/g,(X)=>$(X,"mu-code__number")),Q=Q.replace(/(#[0-9a-fA-F]{3,8})\b/g,(X)=>$(X,"mu-code__string")),Q=Q.replace(/\b([\w-]+)\s*:/g,(X,U)=>`${$(U,"mu-code__attr")}:`),Q=Q.replace(/(^|[{,\s])([.#]?[\w-]+)(?=\s*[{,])/gm,(X,U,O)=>`${U}${$(O,"mu-code__tag")}`),J(Q)}if(W==="json"){let{addMarker:$,resolveMarkers:J}=G(),Q=Y;return Q=Q.replace(/("[^"]*")\s*:/g,(X,U)=>`${$(U,"mu-code__attr")}:`),Q=Q.replace(/:\s*("[^"]*")/g,(X,U)=>`: ${$(U,"mu-code__string")}`),Q=Q.replace(/:\s*(-?\d+\.?\d*)/g,(X,U)=>`: ${$(U,"mu-code__number")}`),Q=Q.replace(/\b(true|false|null)\b/g,(X)=>$(X,"mu-code__builtin")),J(Q)}if(W==="bash"||W==="sh"||W==="shell"){let{addMarker:$,resolveMarkers:J}=G(),Q=Y;return Q=Q.replace(/(#.*)/g,(X)=>$(X,"mu-code__comment")),Q=Q.replace(/('[^']*'|"[^"]*")/g,(X)=>$(X,"mu-code__string")),Q=Q.replace(/(\$\{?\w+\}?)/g,(X)=>$(X,"mu-code__attr")),Q=Q.replace(/\b(cd|ls|echo|cat|grep|find|sudo|npm|npx|bun|node|git|curl|wget|mkdir|rm|cp|mv|chmod|chown)\b/g,(X)=>$(X,"mu-code__keyword")),Q=Q.replace(/(\s)(--?[\w-]+)/g,(X,U,O)=>`${U}${$(O,"mu-code__builtin")}`),J(Q)}return Y}#Y(Y){let W=Y.split(`
|
|
45
|
+
`);while(W.length>0&&W[0].trim()==="")W.shift();while(W.length>0&&W[W.length-1].trim()==="")W.pop();if(W.length===0)return"";let G=1/0;for(let $ of W){if($.trim()==="")continue;let J=$.match(/^(\s*)/),Q=J?J[1].length:0;G=Math.min(G,Q)}if(G===1/0||G===0)return W.join(`
|
|
46
|
+
`);return W.map(($)=>{if($.trim()==="")return"";return $.slice(G)}).join(`
|
|
47
|
+
`)}#X(Y,W){let $=Y.split(`
|
|
48
|
+
`),J=[],Q=0;for(let X=0;X<$.length;X++){let U=$[X].trim();if(U===""){J.push("");continue}let O=0,K=0;if(W==="html"){let P=(U.match(/<[a-zA-Z][^>]*(?<!\/)\s*>/g)||[]).length,A=(U.match(/<\/[^>]+>/g)||[]).length,V=(U.match(/<[^>]+\/>/g)||[]).length;O=P-V,K=A}else{let P=!1,A="";for(let V=0;V<U.length;V++){let _=U[V],w=V>0?U[V-1]:"";if((_==='"'||_==="'"||_==="`")&&w!=="\\"){if(!P)P=!0,A=_;else if(_===A)P=!1}if(!P){if(_==="{"||_==="["||_==="(")O++;if(_==="}"||_==="]"||_===")")K++}}}if((W==="html"?U.startsWith("</"):/^[}\]\)]/.test(U))&&K>0)Q=Math.max(0,Q-1),K--;J.push(" ".repeat(Q)+U),Q=Math.max(0,Q+O-K)}return J.join(`
|
|
49
|
+
`)}#$(){if(this.style.display="block",this.style.background="var(--md-sys-color-surface-container-highest)",this.closest("mu-example"))this.style.borderTopLeftRadius="0",this.style.borderTopRightRadius="0",this.style.borderBottomLeftRadius="var(--md-sys-shape-corner-medium)",this.style.borderBottomRightRadius="var(--md-sys-shape-corner-medium)";else this.style.borderRadius="var(--md-sys-shape-corner-medium)";this.style.overflow="hidden",this.style.fontFamily="'Fira Code', 'Consolas', monospace",this.style.fontSize="13px";let W=this.querySelector(".mu-code__header");if(W)W.style.display="flex",W.style.justifyContent="space-between",W.style.alignItems="center",W.style.padding="8px 16px",W.style.background="var(--md-sys-color-surface-container)",W.style.borderBottom="1px solid var(--md-sys-color-outline-variant)";let G=this.querySelector(".mu-code__language");if(G)G.style.fontSize="11px",G.style.fontWeight="600",G.style.color="var(--md-sys-color-primary)",G.style.letterSpacing="0.5px";let $=this.querySelector(".mu-code__copy");if($)$.style.background="transparent",$.style.border="none",$.style.cursor="pointer",$.style.color="var(--md-sys-color-on-surface-variant)",$.style.padding="4px",$.style.borderRadius="4px",$.style.display="flex",$.style.transition="all 0.2s ease";let J=this.querySelector(".mu-code__pre");if(J)J.style.margin="0",J.style.padding="16px",J.style.overflow="auto",J.style.maxHeight="400px";let Q=this.querySelector(".mu-code__content");if(Q)Q.style.color="var(--md-sys-color-on-surface)";let X=document.createElement("style");X.textContent=`
|
|
50
|
+
.mu-code__tag { color: var(--md-sys-color-primary); }
|
|
51
|
+
.mu-code__attr { color: var(--md-sys-color-tertiary); }
|
|
52
|
+
.mu-code__string { color: var(--md-sys-color-secondary); }
|
|
53
|
+
.mu-code__keyword { color: var(--md-sys-color-primary); font-weight: 500; }
|
|
54
|
+
.mu-code__comment { color: var(--md-sys-color-outline); font-style: italic; }
|
|
55
|
+
.mu-code__number { color: var(--md-sys-color-error); }
|
|
56
|
+
.mu-code__function { color: var(--md-sys-color-tertiary); }
|
|
57
|
+
.mu-code__builtin { color: var(--md-sys-color-primary); font-weight: 500; }
|
|
58
|
+
.mu-code__copy:hover {
|
|
59
|
+
background: var(--md-sys-color-primary-container) !important;
|
|
60
|
+
color: var(--md-sys-color-on-primary-container) !important;
|
|
61
|
+
}
|
|
62
|
+
.mu-code__copy:active {
|
|
63
|
+
background: var(--md-sys-color-primary) !important;
|
|
64
|
+
color: var(--md-sys-color-on-primary) !important;
|
|
65
|
+
transform: scale(0.95);
|
|
66
|
+
}
|
|
67
|
+
.mu-code__copy.copied {
|
|
68
|
+
background: #c8e6c9 !important;
|
|
69
|
+
color: #1b5e20 !important;
|
|
70
|
+
}
|
|
71
|
+
`;let U=document.getElementById("mu-code-styles");if(U)U.remove();X.id="mu-code-styles",document.head.appendChild(X)}#G(Y){let W=this.querySelector(".mu-code__copy");if(W)this.listen(W,"click",async()=>{try{await navigator.clipboard.writeText(Y.trim()),W.classList.add("copied"),W.innerHTML=`
|
|
72
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
73
|
+
<polyline points="20 6 9 17 4 12"/>
|
|
74
|
+
</svg>
|
|
75
|
+
`,this.setTimeout(()=>{W.classList.remove("copied"),W.innerHTML=`
|
|
76
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
77
|
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
|
|
78
|
+
<path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/>
|
|
79
|
+
</svg>
|
|
80
|
+
`},2000)}catch(G){console.error("Copy failed:",G)}})}}Z("mu-code",x);class B extends z{static baseClass="mu-api-table";static observedAttributes=["type"];render(){let Y=this.attr("type","attributes"),W=Array.from(this.querySelectorAll("mu-api-row")),G={attributes:["Name","Type","Default","Description"],properties:["Name","Type","Description"],methods:["Name","Signature","Description"],events:["Name","Detail","Description"],tokens:["Token","Default","Description"]},$=G[Y]||G.attributes,J=W.map((Q)=>({name:Q.getAttribute("name")||"",type:Q.getAttribute("type")||"",default:Q.getAttribute("default")||"-",signature:Q.getAttribute("signature")||"",detail:Q.getAttribute("detail")||"",description:Q.textContent.trim()}));this.innerHTML=`
|
|
81
|
+
<table class="mu-api-table__table">
|
|
82
|
+
<thead>
|
|
83
|
+
<tr>
|
|
84
|
+
${$.map((Q)=>`<th>${Q}</th>`).join("")}
|
|
85
|
+
</tr>
|
|
86
|
+
</thead>
|
|
87
|
+
<tbody>
|
|
88
|
+
${J.map((Q)=>this.#Q(Y,Q)).join("")}
|
|
89
|
+
</tbody>
|
|
90
|
+
</table>
|
|
91
|
+
`,this.#W()}#Q(Y,W){let G={name:F(W.name),type:F(W.type),default:F(W.default),signature:F(W.signature),detail:F(W.detail),description:F(W.description)};switch(Y){case"attributes":return`<tr>
|
|
92
|
+
<td><code>${G.name}</code></td>
|
|
93
|
+
<td><code class="type">${G.type}</code></td>
|
|
94
|
+
<td><code class="default">${G.default}</code></td>
|
|
95
|
+
<td>${G.description}</td>
|
|
96
|
+
</tr>`;case"properties":return`<tr>
|
|
97
|
+
<td><code>${G.name}</code></td>
|
|
98
|
+
<td><code class="type">${G.type}</code></td>
|
|
99
|
+
<td>${G.description}</td>
|
|
100
|
+
</tr>`;case"methods":return`<tr>
|
|
101
|
+
<td><code>${G.name}</code></td>
|
|
102
|
+
<td><code class="signature">${G.signature}</code></td>
|
|
103
|
+
<td>${G.description}</td>
|
|
104
|
+
</tr>`;case"events":return`<tr>
|
|
105
|
+
<td><code>${G.name}</code></td>
|
|
106
|
+
<td><code class="detail">${G.detail}</code></td>
|
|
107
|
+
<td>${G.description}</td>
|
|
108
|
+
</tr>`;case"tokens":return`<tr>
|
|
109
|
+
<td><code>${G.name}</code></td>
|
|
110
|
+
<td><code class="default">${G.default}</code></td>
|
|
111
|
+
<td>${G.description}</td>
|
|
112
|
+
</tr>`;default:return""}}#W(){this.style.display="block",this.style.overflowX="auto",this.style.marginBottom="24px";let Y=this.querySelector(".mu-api-table__table");if(Y)Y.style.width="100%",Y.style.borderCollapse="collapse",Y.style.fontSize="var(--md-sys-typescale-body-medium-size)";this.querySelectorAll("th").forEach((X)=>{X.style.textAlign="left",X.style.padding="16px",X.style.height="56px",X.style.background="var(--md-sys-color-surface-container)",X.style.fontWeight="500",X.style.color="var(--md-sys-color-on-surface)",X.style.borderBottom="1px solid var(--md-sys-color-outline-variant)"}),this.querySelectorAll("td").forEach((X)=>{X.style.padding="16px",X.style.minHeight="52px",X.style.borderBottom="1px solid var(--md-sys-color-outline-variant)",X.style.verticalAlign="middle",X.style.lineHeight="1.5"}),this.querySelectorAll("code").forEach((X)=>{X.style.fontFamily="'Fira Code', monospace",X.style.fontSize="13px",X.style.padding="2px 6px",X.style.borderRadius="4px",X.style.background="var(--md-sys-color-surface-container-highest)"}),this.querySelectorAll("code.type, code.detail").forEach((X)=>{X.style.color="var(--md-sys-color-primary)"}),this.querySelectorAll("code.default").forEach((X)=>{X.style.color="var(--md-sys-color-secondary)"})}}class H extends z{static baseClass="mu-api-row";static observedAttributes=["name","type","default","signature","detail"];render(){}}Z("mu-api-table",B);Z("mu-api-row",H);class I extends z{static baseClass="mu-example";static observedAttributes=["title"];#Q=!1;render(){let Y=this.attr("title","Example"),W=this.querySelector('[slot="demo"]'),G=this.querySelector('[slot="code"]'),$=W?W.innerHTML:"",J=G?G.textContent:W?W.innerHTML:"";if(W)W.remove();if(G)G.remove();let Q=this.#W(J),X=F(Q);this.innerHTML=`
|
|
113
|
+
<div class="mu-example__card">
|
|
114
|
+
<div class="mu-example__header">
|
|
115
|
+
<span class="mu-example__title">${Y}</span>
|
|
116
|
+
<div class="mu-example__actions">
|
|
117
|
+
<button class="mu-example__btn" data-action="link" title="Copy link">
|
|
118
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
119
|
+
<path d="M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71"/>
|
|
120
|
+
<path d="M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71"/>
|
|
121
|
+
</svg>
|
|
122
|
+
</button>
|
|
123
|
+
<button class="mu-example__btn" data-action="code" title="View source">
|
|
124
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
125
|
+
<polyline points="16 18 22 12 16 6"/>
|
|
126
|
+
<polyline points="8 6 2 12 8 18"/>
|
|
127
|
+
</svg>
|
|
128
|
+
</button>
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
<div class="mu-example__demo">
|
|
132
|
+
${$}
|
|
133
|
+
</div>
|
|
134
|
+
<div class="mu-example__code" style="display: none;">
|
|
135
|
+
<mu-code language="html">${X}</mu-code>
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
`,this.#Y()}#W(Y){let W=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),G=new Set(["a","abbr","b","bdo","br","cite","code","dfn","em","i","kbd","q","s","samp","small","span","strong","sub","sup","u","var"]),$="",J=0,Q=" ",U=Y.replace(/>\s+</g,"><").replace(/\s+/g," ").trim().split(/(<[^>]+>)/g).filter((O)=>O.trim());for(let O=0;O<U.length;O++){let K=U[O].trim();if(!K)continue;let q=K.startsWith("<"),P=K.startsWith("</"),A=K.endsWith("/>")||q&&W.has(K.match(/<\/?(\w+)/)?.[1]?.toLowerCase());if(P)J=Math.max(0,J-1);let V=q?K.match(/<\/?(\w+)/)?.[1]?.toLowerCase():null,_=V&&G.has(V);if(q)if(!_||P){if($&&!$.endsWith(`
|
|
139
|
+
`))$+=`
|
|
140
|
+
`;$+=Q.repeat(J)+K}else $+=K;else $+=K;if(q&&!P&&!A&&!_)J++}return $.trim()}#Y(){this.style.display="block",this.style.marginBottom="24px";let Y=this.querySelector(".mu-example__card");if(Y)Y.style.background="var(--md-sys-color-surface)",Y.style.border="1px solid var(--md-sys-color-outline-variant)",Y.style.borderRadius="var(--md-sys-shape-corner-large)";let W=this.querySelector(".mu-example__header");if(W)W.style.display="flex",W.style.justifyContent="space-between",W.style.alignItems="center",W.style.padding="12px 16px",W.style.borderBottom="1px solid var(--md-sys-color-outline-variant)",W.style.background="var(--md-sys-color-surface-container-low)",W.style.borderRadius="var(--md-sys-shape-corner-large) var(--md-sys-shape-corner-large) 0 0";let G=this.querySelector(".mu-example__title");if(G)G.style.fontWeight="500",G.style.fontSize="var(--md-sys-typescale-title-small-size)",G.style.color="var(--md-sys-color-on-surface)",G.style.minWidth="0",G.style.overflow="hidden",G.style.textOverflow="ellipsis",G.style.whiteSpace="nowrap";let $=this.querySelector(".mu-example__actions");if($)$.style.display="flex",$.style.gap="4px";this.querySelectorAll(".mu-example__btn").forEach((K)=>{K.style.background="transparent",K.style.border="none",K.style.cursor="pointer",K.style.padding="8px",K.style.borderRadius="50%",K.style.color="var(--md-sys-color-on-surface-variant)",K.style.display="flex",K.style.alignItems="center",K.style.justifyContent="center",K.style.transition="all 0.2s ease"});let Q=this.querySelector(".mu-example__demo");if(Q){Q.style.boxSizing="border-box",Q.style.width="100%",Q.style.maxWidth="100%",Q.style.padding="24px",Q.style.display="flex",Q.style.flexWrap="wrap",Q.style.gap="16px",Q.style.alignItems="center",Q.style.justifyContent="flex-start";let K=new Set(["MU-STACK","MU-GRID","MU-LAYOUT"]);Array.from(Q.children).forEach((q)=>{if(!K.has(q.tagName))q.style.flexShrink="0"})}let X=this.querySelector(".mu-example__code");if(X)X.style.borderTop="1px solid var(--md-sys-color-outline-variant)";let U=this.querySelector(".mu-example__code mu-code");if(U){U.style.borderTopLeftRadius="0",U.style.borderTopRightRadius="0",U.style.maxHeight="400px",U.style.overflow="auto";let K=U.querySelector(".mu-code__header");if(K)K.style.borderRadius="0"}let O=document.createElement("style");if(O.textContent=`
|
|
141
|
+
.mu-example__btn:hover {
|
|
142
|
+
background: var(--md-sys-color-surface-container-high) !important;
|
|
143
|
+
color: var(--md-sys-color-primary) !important;
|
|
144
|
+
}
|
|
145
|
+
.mu-example__btn.active {
|
|
146
|
+
background: var(--md-sys-color-primary-container) !important;
|
|
147
|
+
color: var(--md-sys-color-on-primary-container) !important;
|
|
148
|
+
}
|
|
149
|
+
`,!document.querySelector("#mu-example-styles"))O.id="mu-example-styles",document.head.appendChild(O)}handleAction(Y,W,G){if(Y==="code"){let $=this.querySelector(".mu-example__code");if($){if(this.#Q=!this.#Q,$.style.display=this.#Q?"block":"none",W.classList.toggle("active",this.#Q),this.#Q)requestAnimationFrame(()=>{requestAnimationFrame(()=>{let J=this.closest(".mu-layout-main")||document.querySelector(".mu-layout-main")||document.documentElement,Q=$.getBoundingClientRect(),X=J.getBoundingClientRect?.()||{top:0,bottom:window.innerHeight};if(Q.bottom>X.bottom){let U=Q.bottom-X.bottom+20;J.scrollBy({top:U,behavior:"smooth"})}})})}}else if(Y==="link")this.#X(W)}async#X(Y){let W=window.location.href;try{await navigator.clipboard.writeText(W),Y.style.color="var(--md-sys-color-primary)",this.setTimeout(()=>{Y.style.color=""},2000)}catch(G){console.error("Copy failed:",G)}}}Z("mu-example",I);class E extends z{static baseClass="mu-doc-page";static observedAttributes=["title","selector","description"];#Q=0;connectedCallback(){super.connectedCallback(),requestAnimationFrame(()=>this.#W())}render(){let Y=this.attr("title","Component"),W=this.attr("selector",""),G=this.attr("description",""),$=this.querySelector('[slot="overview"]'),J=this.querySelector('[slot="api"]'),Q=this.querySelector('[slot="styling"]'),X=this.querySelector('[slot="examples"]'),U=$?$.innerHTML:"",O=J?J.innerHTML:"",K=Q?Q.innerHTML:"",q=X?X.innerHTML:"";this.innerHTML=`
|
|
150
|
+
<h1 class="page-title">${Y}</h1>
|
|
151
|
+
<p class="page-subtitle">
|
|
152
|
+
${W?`<code><${W}></code> `:""}${G}
|
|
153
|
+
</p>
|
|
154
|
+
|
|
155
|
+
<mu-tabs active="0" class="mu-doc-page__tabs" style="margin-bottom: 24px;">
|
|
156
|
+
<mu-tab>OVERVIEW</mu-tab>
|
|
157
|
+
<mu-tab>API</mu-tab>
|
|
158
|
+
<mu-tab>STYLING</mu-tab>
|
|
159
|
+
<mu-tab>EXAMPLES</mu-tab>
|
|
160
|
+
</mu-tabs>
|
|
161
|
+
|
|
162
|
+
<div class="mu-doc-page__content mu-doc-page__overview">
|
|
163
|
+
${U}
|
|
164
|
+
</div>
|
|
165
|
+
<div class="mu-doc-page__content mu-doc-page__api" style="display: none;">
|
|
166
|
+
${O}
|
|
167
|
+
</div>
|
|
168
|
+
<div class="mu-doc-page__content mu-doc-page__styling" style="display: none;">
|
|
169
|
+
${K}
|
|
170
|
+
</div>
|
|
171
|
+
<div class="mu-doc-page__content mu-doc-page__examples" style="display: none;">
|
|
172
|
+
${q}
|
|
173
|
+
</div>
|
|
174
|
+
`,this.style.display="block"}#W(){let Y=this.querySelector(".mu-doc-page__tabs"),W=this.querySelectorAll(".mu-doc-page__content");if(Y)this.listen(Y,"mu-tab-change",(G)=>{this.#Q=G.detail.index,W.forEach(($,J)=>{$.style.display=J===this.#Q?"block":"none"})})}}Z("mu-doc-page",E);class S{#Q=[];#W=null;#Y="";on(Y,W){let G=Y.replace(/:[a-zA-Z]+/g,"([^/]+)").replace(/\//g,"\\/"),$=(Y.match(/:[a-zA-Z]+/g)||[]).map((J)=>J.slice(1));return this.#Q.push({path:Y,pattern:new RegExp(`^${G}$`),paramNames:$,handler:W}),this}notFound(Y){return this.#W=Y,this}navigate(Y){window.location.hash=Y}get current(){return this.#Y}start(){let Y=()=>{let W=window.location.hash.slice(1)||"/";this.#Y=W;for(let G of this.#Q){let $=W.match(G.pattern);if($){let J={};G.paramNames.forEach((Q,X)=>{J[Q]=$[X+1]}),G.handler(J);return}}if(this.#W)this.#W(W)};return window.addEventListener("hashchange",Y),Y(),this}}var v=new S;var f={baseURL:"",headers:{"Content-Type":"application/json"},setBaseURL(Y){this.baseURL=Y},setHeader(Y,W){this.headers[Y]=W},async get(Y,W={}){return this.request(Y,{...W,method:"GET"})},async post(Y,W,G={}){return this.request(Y,{...G,method:"POST",body:W})},async put(Y,W,G={}){return this.request(Y,{...G,method:"PUT",body:W})},async delete(Y,W={}){return this.request(Y,{...W,method:"DELETE"})},async request(Y,W={}){let G=this.baseURL+Y,$={method:W.method||"GET",headers:{...this.headers,...W.headers}};if(W.body)$.body=JSON.stringify(W.body);try{let J=await fetch(G,$);if(!J.ok)throw new R(J.status,J.statusText,await J.text());if(J.headers.get("content-type")?.includes("application/json"))return J.json();return J.text()}catch(J){if(J instanceof R)throw J;throw new R(0,"Network Error",J.message)}}};class R extends Error{constructor(Y,W,G){super(`HTTP ${Y}: ${W}`);this.status=Y,this.statusText=W,this.body=G}}export{f as http,v as Router,L as MuVirtualList,j as MuRepeat,D as MuLazy,I as MuExample,E as MuDocPage,x as MuCode,B as MuApiTable,R as HttpError};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var V=Symbol("listeners"),u=Symbol("subCounter"),P=Symbol("maxListeners"),A=Symbol("fastCache");var T=Object.freeze({peerId:"self",origin:typeof globalThis.location<"u"?globalThis.location.origin:"unknown",type:"local"});class b{constructor(){this[V]=new Map,this[u]=0,this[P]=10,this[A]=Object.create(null)}setMaxListeners(Z){return this[P]=Z,this}getMaxListeners(){return this[P]}on(Z,$,X={}){if(typeof Z!=="string")throw TypeError("Signal name must be a string");if(typeof $!=="function")throw TypeError("Handler must be a function");let J=`sub_${++this[u]}`,G={id:J,handler:$,priority:X.priority??0,mode:X.mode??"async",once:X.once??!1,signal:X.signal??null};if(!this[V].has(Z))this[V].set(Z,[]);let Q=this[V].get(Z);if(Q.length===0||G.priority<=Q[Q.length-1].priority)Q.push(G);else{let z=0,w=Q.length;while(z<w){let M=z+w>>>1;if(Q[M].priority>=G.priority)z=M+1;else w=M}Q.splice(z,0,G)}this[A][Z]=Q.map((z)=>z.handler);let K=this[P];if(K>0&&Q.length>K)console.warn(`[CrossBus] Possible memory leak: ${Q.length} listeners for "${Z}". Use setMaxListeners(n) to increase limit.`);let D=!0,U={id:J,signalName:Z,get active(){return D},unsubscribe:()=>{if(D)this.#$(Z,J),D=!1}};if(G.signal)if(G.signal.aborted)this.#$(Z,J),D=!1;else G.signal.addEventListener("abort",()=>{U.unsubscribe()},{once:!0});return U}once(Z,$,X={}){return this.on(Z,$,{...X,once:!0})}onFast(Z,$){return(this[A][Z]||=[]).push($),()=>{this[A][Z]=this[A][Z]?.filter((X)=>X!==$)}}offFast(Z,$){let X=this[A][Z];if(X){let G=X.indexOf($);if(G!==-1)X.splice(G,1)}let J=this[V].get(Z);if(J){let G=J.findIndex((Q)=>Q.handler===$);if(G!==-1)J.splice(G,1)}}off(Z,$){if(typeof Z!=="string")throw TypeError("Signal name must be a string");let X=this[V].get(Z);if(!X||X.length===0)return{success:!1,removedCount:0,remainingCount:0};let J=0;if($===void 0)J=X.length,this[V].delete(Z),delete this[A][Z];else{let Q=X.length,K=X.filter((D)=>D.handler!==$);if(J=Q-K.length,K.length===0)this[V].delete(Z),delete this[A][Z];else this[V].set(Z,K),this[A][Z]=K.map((D)=>D.handler)}let G=this[V].get(Z)?.length??0;return{success:J>0,removedCount:J,remainingCount:G}}emitSync(Z,$){let X=this[A][Z];if(!X)return 0;let J=X.length;if(J===1)return X[0]($),1;if(J===2)return X[0]($),X[1]($),2;if(J===3)return X[0]($),X[1]($),X[2]($),3;if(J===4)return X[0]($),X[1]($),X[2]($),X[3]($),4;for(let G=0;G<J;G++)X[G]($);return J}async emit(Z,$,X){if(typeof Z!=="string")throw TypeError("Signal name must be a string");let J=this[V].get(Z),G=this[V].has("*");if(J?.length===1&&!G&&!X){let U=J[0],z={name:Z,data:$,messageId:crypto.randomUUID(),timestamp:Date.now(),source:T};try{if(U.mode==="sync")await U.handler(z);else Promise.resolve().then(()=>U.handler(z))}catch(w){console.error(`[CrossBus] Handler error for "${Z}":`,w)}if(U.once)this.#$(Z,U.id);return 1}let Q={name:Z,data:$,messageId:crypto.randomUUID(),timestamp:Date.now(),source:X?{...T,...X}:T},K=this.#Z(Z),D=[];for(let{signalName:U,entry:z}of K){try{if(z.mode==="sync")await z.handler(Q);else Promise.resolve().then(()=>z.handler(Q))}catch(w){console.error(`[CrossBus] Handler error for "${Z}":`,w)}if(z.once)D.push({signalName:U,id:z.id})}for(let{signalName:U,id:z}of D)this.#$(U,z);return K.length}hasListeners(Z){let $=this[V].get(Z);return $!==void 0&&$.length>0}listenerCount(Z){return this[V].get(Z)?.length??0}getSignalNames(){return Array.from(this[V].keys())}clear(){this[V].clear();for(let Z in this[A])delete this[A][Z]}#Z(Z){let $=this[V].get(Z),X=this[V].get("*"),J=null,G=Z.indexOf(":");if(G>0){let D=Z.slice(0,G+1)+"*";J=this[V].get(D)}if($&&!X&&!J)return $.map((D)=>({signalName:Z,entry:D}));let Q=[$&&{signalName:Z,entries:$},X&&{signalName:"*",entries:X},J&&{signalName:Z.slice(0,G+1)+"*",entries:J}].filter(Boolean);if(Q.length===0)return[];if(Q.length===1)return Q[0].entries.map((D)=>({signalName:Q[0].signalName,entry:D}));let K=[];for(let{signalName:D,entries:U}of Q)for(let z of U)K.push({signalName:D,entry:z});return K.sort((D,U)=>U.entry.priority-D.entry.priority),K}#$(Z,$){let X=this[V].get(Z);if(!X)return;let J=X.filter((G)=>G.id!==$);if(J.length===0)this[V].delete(Z),delete this[A][Z];else this[V].set(Z,J),this[A][Z]=J.map((G)=>G.handler)}}var F="_cb",x=1,j=Object.freeze({SIGNAL:"sig",REQUEST:"req",RESPONSE:"res",ACK:"ack",HANDSHAKE:"hsk",HANDSHAKE_INIT:"hsk_init",HANDSHAKE_ACK:"hsk_ack",HANDSHAKE_COMPLETE:"hsk_done",PING:"png",PONG:"pog",BYE:"bye",BROADCAST:"bc"}),v=Object.freeze({INIT:"init",INIT_SENT:"init_sent",ACK:"ack",ACK_SENT:"ack_sent",DONE:"done"}),y=Object.freeze({CONNECTING:"connecting",CONNECTED:"connected",DISCONNECTED:"disconnected",RECONNECTING:"reconnecting",FAILED:"failed"}),VZ=Object.freeze({IFRAME:"iframe",WORKER:"worker",SERVICE_WORKER:"sw",WINDOW:"window",PORT:"port"}),wZ=Object.freeze({LOCAL:"local",SENT:"sent",ACKED:"acked",QUEUED:"queued",TIMEOUT:"timeout",FAILED:"failed"});function H(Z){return Z!==null&&typeof Z==="object"&&Z[F]===x&&typeof Z.id==="string"&&(typeof Z.type==="string"||typeof Z.t==="string")}function r(Z){if(Z instanceof ArrayBuffer)return!0;if(Z instanceof MessagePort)return!0;if(typeof ImageBitmap<"u"&&Z instanceof ImageBitmap)return!0;if(typeof OffscreenCanvas<"u"&&Z instanceof OffscreenCanvas)return!0;if(typeof ReadableStream<"u"&&Z instanceof ReadableStream)return!0;if(typeof WritableStream<"u"&&Z instanceof WritableStream)return!0;if(typeof TransformStream<"u"&&Z instanceof TransformStream)return!0;return!1}function f(Z,$=new Set){if(Z===null||Z===void 0)return Array.from($);if(r(Z))return $.add(Z),Array.from($);if(Array.isArray(Z))for(let X of Z)f(X,$);else if(typeof Z==="object")for(let X of Object.keys(Z))f(Z[X],$);return Array.from($)}function h(Z,$,X={},J=null){return Object.freeze({[F]:x,version:x,id:J||crypto.randomUUID(),type:Z,timestamp:Date.now(),payload:Object.freeze({...$}),meta:Object.freeze({...X})})}function e(Z,$,X,J=null){return h(j.SIGNAL,{name:Z,data:$,source:X,dest:J})}function ZZ(Z,$,X,J,G=null){return h(j.REQUEST,{name:Z,data:$,source:X,dest:J},{},G)}function N(Z,$,X,J=!0,G=null){return h(j.RESPONSE,{requestId:Z,data:$,source:X,success:J,error:G})}var Y=Object.freeze({HANDSHAKE_TIMEOUT:"ERR_HANDSHAKE_TIMEOUT",HANDSHAKE_REJECTED:"ERR_HANDSHAKE_REJECTED",ORIGIN_FORBIDDEN:"ERR_ORIGIN_FORBIDDEN",PEER_EXISTS:"ERR_PEER_EXISTS",PEER_NOT_FOUND:"ERR_PEER_NOT_FOUND",PEER_DISCONNECTED:"ERR_PEER_DISCONNECTED",RECONNECT_FAILED:"ERR_RECONNECT_FAILED",UNSUPPORTED:"ERR_UNSUPPORTED",NOT_CONNECTED:"ERR_NOT_CONNECTED",ACK_TIMEOUT:"ERR_ACK_TIMEOUT",RESPONSE_TIMEOUT:"ERR_RESPONSE_TIMEOUT",QUEUE_FULL:"ERR_QUEUE_FULL",INVALID_MESSAGE:"ERR_INVALID_MESSAGE",VERSION_MISMATCH:"ERR_VERSION_MISMATCH",CLONE_ERROR:"ERR_CLONE_ERROR",TRANSFER_ERROR:"ERR_TRANSFER_ERROR",MESSAGE_TOO_LARGE:"ERR_MESSAGE_TOO_LARGE",UNREACHABLE:"ERR_UNREACHABLE",TTL_EXCEEDED:"ERR_TTL_EXCEEDED",NO_ROUTE:"ERR_NO_ROUTE",NO_HANDLER:"ERR_NO_HANDLER",HANDLER_ERROR:"ERR_HANDLER_ERROR",HANDLER_TIMEOUT:"ERR_HANDLER_TIMEOUT",HANDLER_EXISTS:"ERR_HANDLER_EXISTS",SEND_FAILED:"ERR_SEND_FAILED",CHANNEL_FAILED:"ERR_CHANNEL_FAILED",CHANNEL_CLOSED:"ERR_CHANNEL_CLOSED",MAX_PEERS:"ERR_MAX_PEERS",MAX_PENDING:"ERR_MAX_PENDING",DESTROYED:"ERR_DESTROYED",CIRCUIT_OPEN:"ERR_CIRCUIT_OPEN",PAYLOAD_TOO_LARGE:"ERR_PAYLOAD_TOO_LARGE",RATE_LIMITED:"ERR_RATE_LIMITED",UNAUTHORIZED:"ERR_UNAUTHORIZED",INVALID_PAYLOAD:"ERR_INVALID_PAYLOAD"}),$Z=Object.freeze({[Y.HANDSHAKE_TIMEOUT]:{message:"Handshake timed out",retryable:!0,suggestion:"Increase timeout or check if target is loaded. Use iframe.onload before connecting."},[Y.HANDSHAKE_REJECTED]:{message:"Handshake rejected by peer",retryable:!1,suggestion:"Check targetOrigin matches the peer's origin. Verify peer allows your origin."},[Y.ORIGIN_FORBIDDEN]:{message:"Origin not in allowed origins list",retryable:!1,suggestion:'Add your origin to allowedOrigins option or use targetOrigin: "*" for development.'},[Y.PEER_EXISTS]:{message:"Peer with this ID already exists",retryable:!1,suggestion:"Use unique peerId for each context. Try: peerId: `agent-${Date.now()}`"},[Y.PEER_NOT_FOUND]:{message:"Peer not found",retryable:!1,suggestion:"Check if peer is connected using bus.peers. Wait for peer connection before request."},[Y.PEER_DISCONNECTED]:{message:"Peer is disconnected",retryable:!0,suggestion:'Wait for peer to reconnect. Listen for "peer:join" event before retry.'},[Y.RECONNECT_FAILED]:{message:"Max reconnection attempts reached",retryable:!1,suggestion:"Check network connectivity. Consider increasing maxRetries option."},[Y.UNSUPPORTED]:{message:"Operation not supported by this environment",retryable:!1,suggestion:"This feature requires a browser environment. Check for feature availability first."},[Y.NOT_CONNECTED]:{message:"Transport is not connected",retryable:!0,suggestion:"Call addTransport() and wait for connection before sending messages."},[Y.ACK_TIMEOUT]:{message:"ACK not received within timeout",retryable:!0,suggestion:"Increase ackTimeout option or check peer availability."},[Y.RESPONSE_TIMEOUT]:{message:"Response not received within timeout",retryable:!0,suggestion:"Increase timeout in request options: { timeout: 10000 }. Check if handler exists on peer."},[Y.QUEUE_FULL]:{message:"Message queue is full",retryable:!1,suggestion:"Increase maxQueueSize or wait for queue to drain. Consider using batching plugin."},[Y.INVALID_MESSAGE]:{message:"Invalid message format",retryable:!1,suggestion:"Ensure message data is JSON-serializable. Avoid DOM nodes and functions."},[Y.VERSION_MISMATCH]:{message:"Protocol version mismatch",retryable:!1,suggestion:"Update CrossBus to same version on both sides."},[Y.CLONE_ERROR]:{message:"Data cannot be cloned (contains functions or DOM nodes)",retryable:!1,suggestion:"Remove functions, DOM nodes, and circular references from message data."},[Y.TRANSFER_ERROR]:{message:"Failed to transfer object ownership",retryable:!1,suggestion:"Ensure ArrayBuffers are not detached. Each buffer can only be transferred once."},[Y.MESSAGE_TOO_LARGE]:{message:"Message exceeds maximum size",retryable:!1,suggestion:"Use streaming for large payloads or increase maxMessageSize option."},[Y.UNREACHABLE]:{message:"Destination peer is unreachable",retryable:!0,suggestion:"Check if peer is still connected. Use bus.peers to list available peers."},[Y.TTL_EXCEEDED]:{message:"Message TTL exceeded (possible routing loop)",retryable:!1,suggestion:"Check for circular transport configurations. Increase maxTTL if needed."},[Y.NO_ROUTE]:{message:"No route to destination",retryable:!1,suggestion:"Add transport connecting to target peer. Set isHub: true on orchestrator."},[Y.NO_HANDLER]:{message:"No handler registered for this request",retryable:!1,suggestion:'Register handler on target: bus.handle("handlerName", fn). Check handler name spelling.'},[Y.HANDLER_ERROR]:{message:"Handler threw an exception",retryable:!1,suggestion:"Check target peer logs for error. Wrap handler in try/catch."},[Y.HANDLER_TIMEOUT]:{message:"Handler did not respond within timeout",retryable:!0,suggestion:"Handler is slow. Increase timeout or optimize handler performance."},[Y.HANDLER_EXISTS]:{message:"Handler already registered with this name",retryable:!1,suggestion:"Use different handler name or call bus.removeHandler() first."},[Y.SEND_FAILED]:{message:"Failed to send message to peer",retryable:!0,suggestion:"Check transport status. Target window may be closed or blocked."},[Y.CHANNEL_FAILED]:{message:"Failed to create direct channel",retryable:!0,suggestion:"Check browser support for MessageChannel. Retry after short delay."},[Y.CHANNEL_CLOSED]:{message:"Channel was closed unexpectedly",retryable:!1,suggestion:"Target context was destroyed. Check if iframe/worker still exists."},[Y.MAX_PEERS]:{message:"Maximum number of peers reached",retryable:!1,suggestion:"Increase maxPeers option or disconnect unused peers first."},[Y.MAX_PENDING]:{message:"Maximum pending requests reached",retryable:!1,suggestion:"Wait for pending requests to complete. Increase maxPendingRequests option."},[Y.DESTROYED]:{message:"CrossBus instance has been destroyed",retryable:!1,suggestion:"Create new CrossBus instance. Do not use bus after calling destroy()."},[Y.CIRCUIT_OPEN]:{message:"Circuit breaker is open",retryable:!1,suggestion:"Too many failures. Wait for circuit to reset or call circuit.reset()."},[Y.PAYLOAD_TOO_LARGE]:{message:"Payload exceeds maximum allowed size",retryable:!1,suggestion:"Reduce payload size or increase maxPayloadSize option. Consider using streaming for large data."},[Y.RATE_LIMITED]:{message:"Request rate limit exceeded",retryable:!0,suggestion:"Wait before retrying. Consider adding delay or using exponential backoff."},[Y.UNAUTHORIZED]:{message:"Peer is not authorized to call this handler",retryable:!1,suggestion:"Add peer to handler allowedPeers list or remove peer restrictions."},[Y.INVALID_PAYLOAD]:{message:"Payload validation failed",retryable:!1,suggestion:"Check payload structure against handler requirements."}});class W extends Error{code;details;retryable;cause;timestamp;constructor(Z,$,X={}){let J=$Z[Z]??{message:"Unknown error",retryable:!1};super($??J.message);if(this.name="CrossBusError",this.code=Z,this.details=X.details??{},this.retryable=X.retryable??J.retryable,this.cause=X.cause,this.timestamp=Date.now(),Error.captureStackTrace)Error.captureStackTrace(this,W)}static from(Z,$={}){return new W(Z,void 0,{details:$})}static wrap(Z,$,X={}){return new W(Z,$.message,{cause:$,details:X})}toJSON(){return{name:this.name,code:this.code,message:this.message,details:this.details,retryable:this.retryable,timestamp:this.timestamp}}toString(){return`${this.name} [${this.code}]: ${this.message}`}}function q(){if(typeof crypto<"u"&&crypto.randomUUID)return crypto.randomUUID();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(Z)=>{let $=Math.random()*16|0;return(Z==="x"?$:$&3|8).toString(16)})}function c(){if(typeof Promise.withResolvers==="function")return Promise.withResolvers();let Z,$;return{promise:new Promise((J,G)=>{Z=J,$=G}),resolve:Z,reject:$}}function g(Z,$,X="Operation timed out"){return Promise.race([Z,new Promise((J,G)=>{setTimeout(()=>G(Error(X)),$)})])}class m extends b{#Z=new Map;#$=0;#X=new Map;#G=Object.create(null);#J=Object.create(null);#Q=[];constructor(){super()}addPeer(Z,$,X={}){if(this.#Z.has(Z))throw W.from(Y.PEER_EXISTS,{peerId:Z});if(typeof $!=="function")throw TypeError("sendFn must be a function");let J={peerId:Z,sendFn:$,meta:X.meta??{},origin:X.origin??"unknown",status:y.CONNECTED,connectedAt:Date.now()};this.#Z.set(Z,J),this.#X.set(Z,0),this.#G[Z]=J,this.#J[Z]=$,this.#Q.push(Z),this.emit("peer:added",{peerId:Z,meta:J.meta})}removePeer(Z){let $=this.#G[Z];if(!$)return!1;this.#Z.delete(Z),this.#X.delete(Z),delete this.#G[Z],delete this.#J[Z];let X=this.#Q.indexOf(Z);if(X!==-1)this.#Q.splice(X,1);return this.emit("peer:removed",{peerId:Z,meta:$.meta}),!0}getPeer(Z){return this.#G[Z]}getPeerIds(){return this.#Q.slice()}get peerCount(){return this.#Z.size}route(Z,$={}){let{target:X,payload:J}=Z;if(X)return this.#Y(X,J);else{let G=$.exclude,Q=G?.length?new Set(G):null;return this.#K(J,Q)}}broadcast(Z,$={}){let X=$.exclude,J=X?.length?new Set(X):null,G=$.include,Q=G?.length?new Set(G):null,K=0,D=[];for(let[U,z]of this.#Z){if(J?.has(U))continue;if(Q&&!Q.has(U))continue;if(z.status!==y.CONNECTED)continue;try{let w=this.#D(U,Z,j.BROADCAST);z.sendFn(w),K++}catch(w){console.error(`[Router] Failed to send to ${U}:`,w),D.push(U)}}return{success:D.length===0,delivered:K,failed:D}}getSequence(Z){return this.#X.get(Z)??0}setPeerStatus(Z,$){let X=this.#G[Z];if(X)X.status=$,this.emit("peer:status",{peerId:Z,status:$})}clearPeers(){let Z=this.#Q.slice();for(let $ of Z)this.removePeer($)}#Y(Z,$){let X=this.#G[Z];if(!X)return{success:!1,delivered:0,failed:[Z],error:Y.PEER_NOT_FOUND};if(X.status!==y.CONNECTED)return{success:!1,delivered:0,failed:[Z],error:Y.PEER_DISCONNECTED};try{let J=$&&$._cb?$:this.#D(Z,$,j.SIGNAL);return X.sendFn(J),{success:!0,delivered:1,failed:[]}}catch(J){return console.error(`[Router] Failed to send to ${Z}:`,J),{success:!1,delivered:0,failed:[Z]}}}#K(Z,$){return this.broadcast(Z,$?{exclude:Array.from($)}:{})}#D(Z,$,X){let J=(this.#X.get(Z)??0)+1;return this.#X.set(Z,J),{id:`msg_${++this.#$}`,t:X,ts:Date.now(),seq:J,p:$}}}class l{#Z=new Map;#$=Object.create(null);#X=0;#G;#J;constructor(Z={}){this.#G=Z.defaultTimeout??30000,this.#J=Z.maxPending??1000}create(Z,$,X={}){if(this.#J>0&&this.#Z.size>=this.#J)throw W.from(Y.MAX_PENDING,{current:this.#Z.size,max:this.#J,targetPeer:Z,handlerName:$});let J=Date.now(),G=`req_${++this.#X}_${J}`,Q=X.timeout??this.#G,{promise:K,resolve:D,reject:U}=c(),z={id:G,targetPeer:Z,handlerName:$,createdAt:J,timeout:Q,resolve:D,reject:U,defaultValue:X.defaultValue};this.#Z.set(G,z),this.#$[G]=z;let w=g(K,Q).catch((M)=>{if(G in this.#$){if(this.#Z.delete(G),delete this.#$[G],"defaultValue"in X)return X.defaultValue;throw W.from(Y.RESPONSE_TIMEOUT,{requestId:G,targetPeer:Z,handlerName:$,timeout:Q})}throw M});return{requestId:G,promise:w}}resolve(Z,$){let X=this.#$[Z];if(!X)return!1;if(this.#Z.delete(Z),delete this.#$[Z],$.success)X.resolve($.data);else{let J=W.from($.error?.code??Y.HANDLER_ERROR,{requestId:Z,targetPeer:X.targetPeer,handlerName:X.handlerName,originalError:$.error});J.message=$.error?.message??"Handler error",X.reject(J)}return!0}reject(Z,$){let X=this.#$[Z];if(!X)return!1;this.#Z.delete(Z),delete this.#$[Z];let J=$ instanceof Error?$:Error($);return X.reject(J),!0}cancel(Z){let $=this.#$[Z];if(!$)return!1;return this.#Z.delete(Z),delete this.#$[Z],$.reject(Error("Request cancelled")),!0}cancelForPeer(Z){let $=0;for(let[X,J]of this.#Z)if(J.targetPeer===Z)this.#Z.delete(X),delete this.#$[X],J.reject(W.from(Y.PEER_DISCONNECTED,{peerId:Z,requestId:X})),$++;return $}cancelAll(){let Z=this.#Z.size;for(let[$,X]of this.#Z)X.reject(Error("All requests cancelled"));this.#Z.clear();for(let $ in this.#$)delete this.#$[$];return Z}has(Z){return Z in this.#$}get(Z){return this.#$[Z]}get size(){return this.#Z.size}getRequestIds(){return Array.from(this.#Z.keys())}getForPeer(Z){let $=[];for(let X of this.#Z.values())if(X.targetPeer===Z)$.push(X);return $}}class p{#Z;#$;#X;#G;#J=new Map;constructor(Z={}){this.#Z=Z.peerId??q(),this.#$=Z.meta??{},this.#X=Z.capabilities??[],this.#G=Z.timeout??1e4}get peerId(){return this.#Z}createInitMessage(){return{type:j.HANDSHAKE_INIT,handshakeId:q(),peerId:this.#Z,meta:this.#$,capabilities:this.#X,timestamp:Date.now()}}createAckMessage(Z,$,X){return{type:j.HANDSHAKE_ACK,handshakeId:Z.handshakeId,peerId:this.#Z,meta:this.#$,capabilities:this.#X,accept:$,reason:$?void 0:X,timestamp:Date.now()}}createCompleteMessage(Z){return{type:j.HANDSHAKE_COMPLETE,handshakeId:Z,confirmed:!0,timestamp:Date.now()}}async initiate(Z){let $=this.createInitMessage(),{promise:X,resolve:J,reject:G}=c();this.#J.set($.handshakeId,{phase:v.INIT_SENT,resolve:J,reject:G,initMsg:$,startTime:Date.now()}),Z($);try{return await g(X,this.#G)}catch(Q){if(this.#J.delete($.handshakeId),Q.code===Y.HANDSHAKE_TIMEOUT)return{success:!1,error:Y.HANDSHAKE_TIMEOUT,reason:`Handshake timeout after ${this.#G}ms`};return{success:!1,error:Y.HANDSHAKE_REJECTED,reason:Q.message}}}handleMessage(Z,$,X,J){switch(Z.type){case j.HANDSHAKE_INIT:return this.#Q(Z,$,X,J);case j.HANDSHAKE_ACK:return this.#Y(Z,$,X);case j.HANDSHAKE_COMPLETE:return this.#K(Z,$);default:return null}}hasPending(Z){return this.#J.has(Z)}cancel(Z){let $=this.#J.get(Z);if($)$.reject(Error("Handshake cancelled")),this.#J.delete(Z)}cancelAll(){for(let[Z,$]of this.#J)$.reject(Error("All handshakes cancelled"));this.#J.clear()}#Q(Z,$,X,J){if(J&&!J(Z,$)){let Q=this.createAckMessage(Z,!1,"Validation failed");return X(Q),null}let G=this.createAckMessage(Z,!0);return X(G),this.#J.set(Z.handshakeId,{phase:v.ACK_SENT,remotePeer:{peerId:Z.peerId,origin:$,meta:Z.meta,capabilities:Z.capabilities}}),null}#Y(Z,$,X){let J=this.#J.get(Z.handshakeId);if(!J)return null;if(!Z.accept)return J.reject(Error(Z.reason||"Connection rejected")),this.#J.delete(Z.handshakeId),null;let G=this.createCompleteMessage(Z.handshakeId);X(G);let Q={peerId:Z.peerId,origin:$,meta:Z.meta,capabilities:Z.capabilities,type:"unknown",connectedAt:Date.now()};return J.resolve({success:!0,peer:Q}),this.#J.delete(Z.handshakeId),Q}#K(Z,$){let X=this.#J.get(Z.handshakeId);if(!X||X.phase!==v.ACK_SENT)return null;if(!Z.confirmed)return this.#J.delete(Z.handshakeId),null;let J={...X.remotePeer,connectedAt:Date.now()};return this.#J.delete(Z.handshakeId),J}}class i{#Z=new Set;#$=[];#X=!1;#G;constructor(Z={}){if(this.#X=Z.allowAll??!1,this.#G=globalThis.location?.origin,Z.allowed)for(let $ of Z.allowed)this.#J($)}isAllowed(Z){if(this.#X)return!0;if(Z==="null"||Z===null)return this.#Z.has("null");if(this.#Z.size===0&&this.#$.length===0)return Z===this.#G;if(this.#Z.has(Z))return!0;for(let $ of this.#$)if($.test(Z))return!0;return!1}allow(Z){return this.#J(Z),this}disallow(Z){if(this.#Z.has(Z))return this.#Z.delete(Z),!0;return!1}getAllowed(){return Array.from(this.#Z)}clear(){this.#Z.clear(),this.#$=[]}get selfOrigin(){return this.#G}#J(Z){if(typeof Z!=="string")throw TypeError("Origin must be a string");if(Z==="*"){this.#X=!0;return}if(Z.includes("*")){let $=this.#Q(Z);this.#$.push($)}else this.#Z.add(Z)}#Q(Z){let $=Z.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,"[a-zA-Z0-9.-]{0,253}");return new RegExp(`^${$}$`)}}class k extends b{#Z;#$;#X;#G;#J;#Q;#Y;#K=new Map;#D=[];#U=[];#j;#V;#W;#w;#z;#A;#F=new Map;#_=new Map;#q=!1;#L="[CrossBus]";#H;#x=!1;constructor(Z={}){super();if(this.#Z=Z.peerId??q(),this.#$=Z.isHub??!1,this.#j=Z.meta??{},this.#V=Z.capabilities??[],this.#W=Z.requestTimeout??30000,this.#X=new m,this.#G=new l({defaultTimeout:this.#W}),this.#J=new p({peerId:this.#Z,meta:this.#j,capabilities:this.#V,timeout:Z.handshakeTimeout??1e4}),this.#Q=new i({allowed:Z.allowedOrigins??[]}),this.#Y=Z.contentType??"application/json",this.#w=Z.maxPayloadSize??1048576,this.#z=Z.maxPendingRequests??100,this.#A=Z.strictMode??!1,this.#q=Z.debug??!1,this.#L=Z.debugPrefix??"[CrossBus]",this.#H=Date.now(),this.#O(Z),this.#V.push(`serializer:${this.#Y}`),this.#X.on("peer:added",($)=>{this.emit("peer:connected",$.data)}),this.#X.on("peer:removed",($)=>{this.emit("peer:disconnected",$.data)}),this.#X.on("peer:status",($)=>{this.emit("peer:status",$.data)}),this.#q)this.#P("info",`Initialized (isHub: ${this.#$})`)}get peerId(){return this.#Z}get isHub(){return this.#$}get peerCount(){return this.#X.peerCount}get peers(){return this.#X.getPeerIds()}getPeer(Z){return this.#X.getPeer(Z)}async signal(Z,$,X={}){this.#M();let J=await this.#B(this.#U,$,{type:"signal",direction:"outbound"}),G=e(Z,J,this.#Z),Q=await this.#X.broadcast(G,X);return this.#P("out",`SIGNAL "${Z}" to ${Q.delivered} peers`),Q}async request(Z,$,X,J={}){if(this.#M(),this.#P("out",`REQUEST "${$}" to ${Z}`),!this.#X.getPeer(Z))throw W.from(Y.PEER_NOT_FOUND,{peerId:Z});let{requestId:Q,promise:K}=this.#G.create(Z,$,{timeout:J.timeout??this.#W}),D=await this.#B(this.#U,X,{type:"request",peerId:Z,handlerName:$,direction:"outbound"}),U=ZZ($,D,this.#Z,Z,Q);if(!this.#X.route({target:Z,payload:U}).success)throw this.#G.cancel(Q),W.from(Y.SEND_FAILED,{peerId:Z});return K}async broadcastRequest(Z,$,X={}){this.#M();let J=X.timeout??this.#W,G=X.ignoreErrors??!0,Q=new Set(X.exclude??[]),K=new Map,D=[];for(let U of this.#X.getPeerIds()){if(Q.has(U))continue;let z=this.request(U,Z,$,{timeout:J}).then((w)=>{K.set(U,{success:!0,data:w})}).catch((w)=>{if(G)K.set(U,{success:!1,error:w.message});else throw w});D.push(z)}return await Promise.all(D),K}handle(Z,$,X={}){if(this.#K.has(Z))throw W.from(Y.HANDLER_EXISTS,{handlerName:Z});if(X.allowedPeers||X.rateLimit||X.validatePayload)this.#_.set(Z,X);return this.#K.set(Z,$),()=>{this.#K.delete(Z),this.#_.delete(Z)}}unhandle(Z){return this.#K.delete(Z)}hasHandler(Z){return this.#K.has(Z)}addInboundHook(Z,$=10){if(typeof Z!=="function")throw TypeError("hookFn must be a function");let X={fn:Z,priority:$};return this.#D.push(X),this.#D.sort((J,G)=>J.priority-G.priority),()=>this.removeInboundHook(Z)}addOutboundHook(Z,$=10){if(typeof Z!=="function")throw TypeError("hookFn must be a function");let X={fn:Z,priority:$};return this.#U.push(X),this.#U.sort((J,G)=>J.priority-G.priority),()=>this.removeOutboundHook(Z)}removeInboundHook(Z){let $=this.#D.findIndex((X)=>X.fn===Z);if($!==-1)return this.#D.splice($,1),!0;return!1}removeOutboundHook(Z){let $=this.#U.findIndex((X)=>X.fn===Z);if($!==-1)return this.#U.splice($,1),!0;return!1}addPeer(Z,$,X={}){this.#M(),this.#X.addPeer(Z,$,X)}removePeer(Z){return this.#G.cancelForPeer(Z),this.#X.removePeer(Z)}addTransport(Z,$={}){if(this.#M(),!Z||typeof Z.send!=="function")throw TypeError("Transport must have a send() method");let X=$.peerId||Z.peerId||`transport-${q()}`,J=$.origin||"*";if(typeof Z.onMessage==="function")Z.onMessage((G)=>{this.handleMessage(G,J,X)});return this.addPeer(X,(G)=>{Z.send(G)},$),()=>{if(this.removePeer(X),typeof Z.destroy==="function")Z.destroy()}}async handleMessage(Z,$,X,J){if(this.#x)return;if(!this.#Q.isAllowed($)){console.warn(`[CrossBus] Blocked message from unauthorized origin: ${$}`);return}let G=Z.payload??Z.data??Z.p,Q=Z.type??Z.t,K=Z.handler??Z.name,D=G;if(Z.payload&&typeof Z.payload==="object"&&!Z.p){if(Q===j.SIGNAL||Q===j.BROADCAST)K=Z.payload.name,D=Z.payload.data;else if(Q===j.REQUEST)K=Z.payload.name,D=Z.payload.data;else if(Q===j.RESPONSE)D=Z.payload.data}else if(Z.t&&!Z.type&&Z.p&&typeof Z.p==="object"&&Z.p.payload){let U=Z.p;K=U.payload.name??U.name,D=U.payload.data??U.data}if(D!==void 0){let U={type:Q===j.SIGNAL?"signal":Q===j.REQUEST?"request":"response",peerId:X,handlerName:K,direction:"inbound"};D=await this.#B(this.#D,D,U)}switch(Q){case j.BROADCAST:case j.SIGNAL:if(typeof K!=="string"){console.warn("[CrossBus] Invalid signal name type");return}await this.#N(K,D,X);break;case j.REQUEST:if(typeof K!=="string"){console.warn("[CrossBus] Invalid handler name type");return}await this.#f(Z.id,K,D,X,J);break;case j.RESPONSE:{let{success:U,error:z}=Z;if(Z.payload&&Z.payload.success!==void 0)U=Z.payload.success,z=Z.payload.error;this.#R(Z.payload?.requestId??Z.id,U,D,z);break}case j.HANDSHAKE_INIT:case j.HANDSHAKE_ACK:case j.HANDSHAKE_COMPLETE:this.#J.handleMessage(Z,$,J);break;default:console.warn(`[CrossBus] Unknown message type: ${Q}`)}}destroy(){if(this.#x)return;this.#x=!0,this.#G.cancelAll(),this.#K.clear(),this.#X.clearPeers(),this.clear(),this.emit("destroyed",{})}get isDestroyed(){return this.#x}async#N(Z,$,X){await this.emit(Z,{payload:$,source:X})}async#f(Z,$,X,J,G){let Q=this.#K.get($),K;if(!Q)K=N(Z,null,this.#Z,!1,{code:Y.NO_HANDLER,message:"Handler not found"});else{let D=this.#b($,J,X);if(!D.allowed)K=N(Z,null,this.#Z,!1,{code:D.error?.code??Y.UNAUTHORIZED,message:D.error?.message??"Security check failed"});else try{let U=await Q(X,{peerId:J,requestId:Z,handlerName:$}),z=await this.#B(this.#U,U,{type:"response",peerId:J,handlerName:$,direction:"outbound"});K=N(Z,z,this.#Z,!0)}catch(U){K=N(Z,null,this.#Z,!1,{code:U.code??Y.HANDLER_ERROR,message:U.message})}}if(G)G(K);else if(J)this.#X.route({target:J,payload:K})}#R(Z,$,X,J){this.#G.resolve(Z,{requestId:Z,success:$,data:X,error:J})}#M(){if(this.#x)throw W.from(Y.DESTROYED,{context:"CrossBus operation"})}async#B(Z,$,X){let J=$;for(let{fn:G}of Z)try{J=await G(J,X)}catch(Q){console.error("[CrossBus] Hook error:",Q)}return J}#O(Z){if(!(typeof process<"u"?process.env?.NODE_ENV!=="production":typeof window<"u"&&window.location?.hostname==="localhost"))return;if(!Z.allowedOrigins||Z.allowedOrigins.length===0)console.warn(`[CrossBus Security] ⚠️ No allowedOrigins specified.
|
|
2
|
+
`+`This bus will REJECT all incoming messages from transports.
|
|
3
|
+
To receive messages, specify allowed origins:
|
|
4
|
+
allowedOrigins: ["https://trusted-domain.com"]
|
|
5
|
+
For development only: allowedOrigins: ["*"]`);if(Z.allowedOrigins?.includes("*")){if(console.warn(`[CrossBus Security] ⚠️ allowedOrigins: ["*"] accepts messages from ANY origin.
|
|
6
|
+
`+`This is INSECURE in production. Use specific origins instead:
|
|
7
|
+
allowedOrigins: ["https://trusted-domain.com"]
|
|
8
|
+
For production, use:
|
|
9
|
+
CrossBus.createSecure({ allowedOrigins: ["https://..."] })
|
|
10
|
+
Suppress this warning with NODE_ENV=production`),this.#A)throw Error('strictMode: allowedOrigins: ["*"] is not allowed. Use specific origins for security.')}}#b(Z,$,X){let J=this.#_.get(Z);if(!J)return{allowed:!0};if(J.allowedPeers&&!J.allowedPeers.includes($))return{allowed:!1,error:W.from(Y.UNAUTHORIZED,{handler:Z,peer:$,allowedPeers:J.allowedPeers})};if(J.rateLimit){let G=`${Z}:${$}`;if(!this.#k(G,J.rateLimit))return{allowed:!1,error:W.from(Y.RATE_LIMITED,{handler:Z,peer:$,limit:J.rateLimit})}}if(J.validatePayload)try{if(!J.validatePayload(X))return{allowed:!1,error:W.from(Y.INVALID_PAYLOAD,{handler:Z})}}catch(G){return{allowed:!1,error:W.from(Y.INVALID_PAYLOAD,{handler:Z,reason:G?.message??"Validation error"})}}return{allowed:!0}}#k(Z,$){let X=Date.now(),J=this.#F.get(Z);if(!J||X>=J.resetAt)return this.#F.set(Z,{count:1,resetAt:X+1000}),!0;if(J.count>=$)return!1;return J.count++,!0}get maxPayloadSize(){return this.#w}get strictMode(){return this.#A}get debug(){return this.#q}get uptime(){return Date.now()-this.#H}#P(Z,$){if(!this.#q)return;let X=Z==="out"?"→":Z==="in"?"←":Z==="warn"?"⚠️":Z==="error"?"❌":"ℹ️";console.log(`${this.#L} ${X} ${$}`)}healthCheck(){let Z=this.#X.getPeerIds(),$=Z.length,X="healthy";if(this.#x)X="unhealthy";else if($===0&&this.#$)X="degraded";let J;if(typeof process<"u"&&process.memoryUsage)try{let G=process.memoryUsage();J={heapUsed:G.heapUsed,heapTotal:G.heapTotal,rss:G.rss}}catch{}return{status:X,peerId:this.#Z,isHub:this.#$,uptime:this.uptime,peers:{total:$,ids:Z},handlers:Array.from(this.#K.keys()),pendingRequests:this.#G.size??0,destroyed:this.#x,...J&&{memory:J}}}static createSecure(Z={}){if(!Z.allowedOrigins||Z.allowedOrigins.length===0)throw Error('createSecure() requires allowedOrigins to be specified. For development, use: new CrossBus({ allowedOrigins: ["*"] })');if(Z.allowedOrigins.includes("*"))throw Error('createSecure() does not allow wildcard origins. Specify exact origins: allowedOrigins: ["https://example.com"]');return new k({strictMode:!0,maxPayloadSize:1048576,maxPendingRequests:100,requestTimeout:30000,...Z})}diagnose(){let Z=[],$=[],X=[];if(this.#x)return Z.push("Instance is destroyed"),$.push("Create a new CrossBus instance"),{status:"error",issues:Z,suggestions:$,warnings:X};let J=this.#X.getPeerIds().length;if(J===0)if(this.#$)X.push("Hub has no connected peers"),$.push("Add transports with addTransport() or wait for agents to connect");else Z.push("Agent has no connected peers"),$.push('Add a transport to connect to hub: bus.addTransport(transport, {peerId: "hub"})');let G=this.#K.size;if(this.#$&&G===0)X.push("Hub has no registered handlers"),$.push('Register handlers with bus.handle("name", fn)');let Q=this.#G.size??0;if(Q>this.#z*0.8)X.push(`High pending request count: ${Q}/${this.#z}`),$.push("Consider increasing maxPendingRequests or check for slow handlers");if(!this.#A)X.push("strictMode is disabled"),$.push("For production, use CrossBus.createSecure() or set strictMode: true");let K="healthy";if(Z.length>0)K="error";else if(X.length>0)K="warning";return{status:K,peerId:this.#Z,isHub:this.#$,peerCount:J,handlerCount:G,pendingRequests:Q,uptime:this.uptime,issues:Z,warnings:X,suggestions:$}}}class d{#Z;#$;#X;#G;#J=0;#Q=!1;#Y=!1;#K;constructor(Z,$,X={}){this.#Z=q(),this.#$=$,this.#X=Z,this.#G=X.chunkSize??64000,this.#K=X.meta??{}}get streamId(){return this.#Z}get name(){return this.#$}async open(Z){if(this.#Y)return;this.#Y=!0,await this.#D({st:"open",name:this.#$,meta:{...this.#K,...Z}})}async write(Z){if(this.#Q)throw Error("Stream already ended");if(!this.#Y)await this.open();let $,X=!1;if(Z instanceof ArrayBuffer)$=this.#j(new Uint8Array(Z)),X=!0;else if(Z instanceof Uint8Array)$=this.#j(Z),X=!0;else if(typeof Z==="string"){let J=this.#U(Z,this.#G);for(let G of J)await this.#D({st:"data",seq:this.#J++,d:G,b64:!1});return}else $=JSON.stringify(Z);if(X){let J=this.#U($,this.#G);for(let G of J)await this.#D({st:"data",seq:this.#J++,d:G,b64:!0})}else await this.#D({st:"data",seq:this.#J++,d:$,b64:!1})}async end(Z){if(this.#Q)return;this.#Q=!0,await this.#D({st:"end",seq:this.#J,meta:Z})}async abort(Z){if(this.#Q)return;this.#Q=!0,await this.#D({st:"error",reason:Z??"Stream aborted"})}async#D(Z){let $={[F]:x,t:"stream",sid:this.#Z,...Z};await this.#X($)}#U(Z,$){let X=[];for(let J=0;J<Z.length;J+=$)X.push(Z.slice(J,J+$));return X}#j(Z){let $="";for(let X=0;X<Z.length;X++)$+=String.fromCharCode(Z[X]);return btoa($)}}class o{#Z;#$;#X;#G=[];#J=null;#Q=!1;#Y=null;constructor(Z,$,X={}){this.#Z=Z,this.#$=$,this.#X=X}get streamId(){return this.#Z}get name(){return this.#$}get meta(){return this.#X}get ended(){return this.#Q}push(Z){if(this.#Q)return;let $=Z.d;if(Z.b64)$=this.#K($);if(this.#G.push($),this.#J){let X=this.#J;this.#J=null,X()}}end(Z){if(this.#Q=!0,Z)this.#X={...this.#X,...Z};if(this.#J){let $=this.#J;this.#J=null,$()}}error(Z){if(this.#Q=!0,this.#Y=Error(Z),this.#J){let $=this.#J;this.#J=null,$()}}async*[Symbol.asyncIterator](){while(!0){while(this.#G.length>0)yield this.#G.shift();if(this.#Q){if(this.#Y)throw this.#Y;return}await new Promise((Z)=>{this.#J=Z})}}async collect(){let Z=[],$=!1;for await(let X of this)if(Z.push(X),X instanceof Uint8Array)$=!0;if($){let X=Z.reduce((Q,K)=>Q+K.length,0),J=new Uint8Array(X),G=0;for(let Q of Z)J.set(Q,G),G+=Q.length;return J}else return Z.join("")}#K(Z){let $=atob(Z),X=new Uint8Array($.length);for(let J=0;J<$.length;J++)X[J]=$.charCodeAt(J);return X}}class XZ{#Z=new Map;#$=new Map;#X;constructor(Z){this.#X=Z}createStream(Z,$,X={}){return new d(async(G)=>{await this.#X($,G)},Z,X)}onStream(Z,$){return this.#$.set(Z,$),()=>this.#$.delete(Z)}handleMessage(Z,$){if(Z.t!=="stream")return;let X=Z.sid;switch(Z.st){case"open":this.#G(X,Z,$);break;case"data":this.#J(X,Z);break;case"end":this.#Q(X,Z);break;case"error":this.#Y(X,Z);break}}#G(Z,$,X){let J=this.#$.get($.name);if(!J){console.warn(`[CrossBus] No handler for stream: ${$.name}`);return}let G=new o(Z,$.name,$.meta);this.#Z.set(Z,G),J(G).catch((Q)=>{console.error("[CrossBus] Stream handler error:",Q)})}#J(Z,$){let X=this.#Z.get(Z);if(!X)return;X.push($)}#Q(Z,$){let X=this.#Z.get(Z);if(!X)return;X.end($.meta),this.#Z.delete(Z)}#Y(Z,$){let X=this.#Z.get(Z);if(!X)return;X.error($.reason),this.#Z.delete(Z)}get activeStreamCount(){return this.#Z.size}}class JZ extends b{#Z;#$;#X=new Map;#G;#J;#Q=null;#Y=null;#K=!1;#D="online";#U={};constructor(Z,$){super();if(!$.peerId)throw Error("peerId is required");if(this.#Z=$.peerId,this.#$=Z,this.#G=$.heartbeatInterval??15000,this.#J=$.timeout??45000,$.autoStart!==!1)this.start()}get peerId(){return this.#Z}get status(){return this.#D}get onlineCount(){let Z=0;for(let $ of this.#X.values())if($.status!=="offline")Z++;return Z}start(){if(this.#Q)return;this.#z("join"),this.#Q=setInterval(()=>{this.#z("heartbeat")},this.#G),this.#Y=setInterval(()=>{this.#w()},this.#G)}stop(){if(this.#Q)clearInterval(this.#Q),this.#Q=null;if(this.#Y)clearInterval(this.#Y),this.#Y=null;this.#z("leave")}setStatus(Z,$){if(this.#D=Z,$)this.#U={...this.#U,...$};this.#z("update")}setMeta(Z){this.#U={...this.#U,...Z},this.#z("update")}getOnlinePeers(){let Z=[];for(let[$,X]of this.#X)if(X.status!=="offline")Z.push($);return Z}getAllPeers(){return Array.from(this.#X.values())}getPeer(Z){return this.#X.get(Z)}isOnline(Z){let $=this.#X.get(Z);return $?$.status!=="offline":!1}handleMessage(Z,$){if(Z.t!=="presence")return;if($===this.#Z)return;let{pt:X,status:J,meta:G}=Z,Q=Date.now();switch(X){case"join":this.#j($,J,G,Q),this.#z("heartbeat");break;case"leave":this.#V($);break;case"heartbeat":case"update":this.#W($,J,G,Q);break}}#j(Z,$,X,J){let G=!this.#X.has(Z);if(this.#X.set(Z,{peerId:Z,status:$??"online",lastSeen:J,meta:X??{}}),G)this.emitSync("join",{peerId:Z,meta:X})}#V(Z){let $=this.#X.get(Z);if(!$)return;$.status="offline",this.#X.delete(Z),this.emitSync("leave",{peerId:Z})}#W(Z,$,X,J){let G=this.#X.get(Z),Q=!G||G.status==="offline";if(!G)G={peerId:Z,status:$??"online",lastSeen:J,meta:X??{}},this.#X.set(Z,G);else{if(G.lastSeen=J,$)G.status=$;if(X)G.meta={...G.meta,...X}}if(Q&&G.status!=="offline")this.emitSync("join",{peerId:Z,meta:G.meta});else this.emitSync("update",{peerId:Z,peer:G})}#w(){let $=Date.now()-this.#J;for(let[X,J]of this.#X)if(J.lastSeen<$&&J.status!=="offline")J.status="offline",this.#X.delete(X),this.emitSync("leave",{peerId:X})}async#z(Z){if(this.#K)return;let $={[F]:x,t:"presence",pt:Z,peerId:this.#Z,status:this.#D,meta:this.#U,ts:Date.now()};try{await this.#$($)}catch(X){console.error("[CrossBus] Failed to send presence:",X)}}destroy(){if(this.#K)return;this.#K=!0,this.stop(),this.#X.clear()}get isDestroyed(){return this.#K}}var R={contentType:"application/json",serialize:(Z)=>JSON.stringify(Z),deserialize:(Z)=>JSON.parse(Z)},t=new Map;t.set(R.contentType,R);function O(Z){return t.get(Z)||R}class GZ{#Z=null;#$;#X;#G;#J;#Q;#Y=null;#K=null;#D=!1;static isSupported(){return typeof globalThis.postMessage==="function"||typeof Window<"u"}constructor(Z,$={}){if(!this.#V(Z))throw TypeError("Target must support postMessage");if(this.#Z=Z,this.#$=$.targetOrigin??"*",this.#X=new Set($.allowedOrigins??[]),this.#G=$.autoTransfer??!1,this.#Q=$.contentType??"application/json",this.#J=O(this.#Q),(typeof process<"u"?process.env?.NODE_ENV!=="production":typeof window<"u"&&window.location?.hostname==="localhost")&&this.#$==="*")console.warn(`[CrossBus Security] ⚠️ targetOrigin: "*" broadcasts to ANY window.
|
|
11
|
+
`+`This is INSECURE in production. Use specific origin:
|
|
12
|
+
targetOrigin: "https://iframe-domain.com"
|
|
13
|
+
Suppress this warning with NODE_ENV=production`);this.#K=this.#U.bind(this),this.#z().addEventListener("message",this.#K)}send(Z,$){if(this.#D)throw W.from(Y.DESTROYED,{context:"PostMessageTransport.send"});if(this.#w())throw W.from(Y.PEER_DISCONNECTED,{reason:"Target window is closed"});let X={[F]:x,...Z},J=X;if(this.#Q!=="application/json")J=this.#J.serialize(X);let G=$;if(this.#G&&!$){if(G=f(Z),G.length===0)G=void 0}if(this.#W())this.#Z.postMessage(J,G);else this.#Z.postMessage(X,this.#$,G)}onMessage(Z){if(typeof Z!=="function")throw TypeError("Handler must be a function");this.#Y=Z}offMessage(){this.#Y=null}destroy(){if(this.#D)return;if(this.#D=!0,this.#Y=null,this.#K)this.#z().removeEventListener("message",this.#K),this.#K=null}get isDestroyed(){return this.#D}get targetOrigin(){return this.#$}#U(Z){if(!this.#Y)return;let $=Z.data;if(!H($))return;if(Z.origin&&!this.#j(Z.origin)){console.warn(`[CrossBus] Blocked message from unauthorized origin: ${Z.origin}`);return}if(this.#Z&&"postMessage"in this.#Z&&!this.#W()){if(Z.source!==this.#Z)return}try{this.#Y($,{origin:Z.origin??"worker",source:Z.source??Z.currentTarget})}catch(X){console.error("[CrossBus] Message handler error:",X)}}#j(Z){if(this.#X.size===0)return Z===globalThis.location?.origin;if(this.#X.has("*"))return!0;if(this.#X.has(Z))return!0;for(let $ of this.#X)if($.includes("*")){if(new RegExp("^"+$.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\\\*/g,"[a-zA-Z0-9.-]{0,253}")+"$").test(Z))return!0}return!1}#V(Z){if(!Z)return!1;return typeof Z.postMessage==="function"}#W(){if(typeof Worker<"u"&&this.#Z instanceof Worker)return!0;if(typeof ServiceWorker<"u"&&this.#Z instanceof ServiceWorker)return!0;if(typeof MessagePort<"u"&&this.#Z instanceof MessagePort)return!0;return!1}#w(){if(this.#W())return!1;return this.#Z.closed===!0}#z(){if(typeof DedicatedWorkerGlobalScope<"u"&&globalThis instanceof DedicatedWorkerGlobalScope)return globalThis;if(this.#W())return this.#Z;if(typeof window<"u")return window;return globalThis}}class n{#Z;#$;#X;#G;#J=null;#Q=!1;static isSupported(){return typeof BroadcastChannel<"u"}constructor(Z={}){if(!n.isSupported())throw W.from(Y.UNSUPPORTED,{api:"BroadcastChannel"});this.#$=Z.channelName??"crossbus:default",this.#Z=new BroadcastChannel(this.#$),this.#G=Z.contentType??"application/json",this.#X=O(this.#G),this.#Z.onmessage=this.#Y.bind(this),this.#Z.onmessageerror=this.#K.bind(this)}send(Z){if(this.#Q)throw W.from(Y.DESTROYED,{context:"BroadcastChannelTransport.send"});let $={[F]:x,...Z},X=$;if(this.#G!=="application/json")X=this.#X.serialize($);this.#Z.postMessage(X)}onMessage(Z){if(typeof Z!=="function")throw TypeError("Handler must be a function");this.#J=Z}offMessage(){this.#J=null}destroy(){if(this.#Q)return;if(this.#Q=!0,this.#J=null,this.#Z)this.#Z.close(),this.#Z=null}get channelName(){return this.#$}get isDestroyed(){return this.#Q}#Y(Z){if(!this.#J)return;let $=Z.data;if($ instanceof ArrayBuffer||$ instanceof Uint8Array)try{let X=new TextDecoder().decode($ instanceof ArrayBuffer?new Uint8Array($):$);$=R.deserialize(X)}catch(X){console.warn("[CrossBus] Failed to deserialize binary message",X);return}if(!H($))return;try{this.#J($,{origin:"broadcast"})}catch(X){console.error("[CrossBus] BroadcastChannel handler error:",X)}}#K(Z){console.error("[CrossBus] BroadcastChannel message error:",Z)}}class E{#Z;#$;#X;#G;#J;#Q=null;#Y=!1;#K;static isSupported(){return typeof MessageChannel<"u"}static fromPort(Z,$={}){if(!(Z instanceof MessagePort))throw TypeError("Port must be a MessagePort");let X=Object.create(E.prototype);return X.#Z=Z,X.#$=null,X.#X=$.autoTransfer??!1,X.#J=$.contentType??"application/json",X.#G=O(X.#J),X.#Y=!1,X.#K=!1,X.#Q=null,X.#Z.onmessage=X.#D.bind(X),X.#Z.onmessageerror=X.#U.bind(X),X}constructor(Z={}){if(!E.isSupported())throw W.from(Y.UNSUPPORTED,{api:"MessageChannel"});let $=new MessageChannel;this.#Z=$.port1,this.#$=$.port2,this.#X=Z.autoTransfer??!1,this.#J=Z.contentType??"application/json",this.#G=O(this.#J),this.#K=!0,this.#Z.onmessage=this.#D.bind(this),this.#Z.onmessageerror=this.#U.bind(this)}get remotePort(){return this.#$}markRemoteTransferred(){this.#$=null}get isInitiator(){return this.#K}send(Z,$){if(this.#Y)throw W.from(Y.DESTROYED,{context:"MessageChannelTransport.send"});let X={[F]:x,...Z},J=X;if(this.#J!=="application/json")J=this.#G.serialize(X);let G=$;if(this.#X&&!$){if(G=f(Z),G.length===0)G=void 0}this.#Z.postMessage(J,G)}onMessage(Z){if(typeof Z!=="function")throw TypeError("Handler must be a function");this.#Q=Z}offMessage(){this.#Q=null}destroy(){if(this.#Y)return;if(this.#Y=!0,this.#Q=null,this.#Z)this.#Z.close(),this.#Z=null;if(this.#$)this.#$.close(),this.#$=null}get isDestroyed(){return this.#Y}#D(Z){if(!this.#Q)return;let $=Z.data;if(!H($))return;try{this.#Q($,{origin:"channel"})}catch(X){console.error("[CrossBus] MessageChannel handler error:",X)}}#U(Z){console.error("[CrossBus] MessageChannel error:",Z)}}class a{#Z=null;#$=null;#X;#G=null;#J=!1;static isSupported(){return typeof SharedWorker<"u"}constructor(Z={}){if(!a.isSupported())throw W.from(Y.UNSUPPORTED,{api:"SharedWorker"});this.#X=Z.workerUrl??"/crossbus-shared-worker.js",this.#Z=new SharedWorker(this.#X,Z.name),this.#$=this.#Z.port,this.#$.onmessage=this.#Q.bind(this),this.#$.onmessageerror=this.#Y.bind(this),this.#Z.onerror=this.#K.bind(this),this.#$.start()}send(Z,$){if(this.#J)throw W.from(Y.DESTROYED,{context:"SharedWorkerTransport.send"});let X={[F]:x,...Z};if(!this.#$)return;if($&&$.length>0)this.#$.postMessage(X,$);else this.#$.postMessage(X)}onMessage(Z){if(typeof Z!=="function")throw TypeError("Handler must be a function");this.#G=Z}offMessage(){this.#G=null}destroy(){if(this.#J)return;if(this.#J=!0,this.#G=null,this.#$)this.#$.close(),this.#$=null;this.#Z=null}get workerUrl(){return this.#X}get isDestroyed(){return this.#J}#Q(Z){if(!this.#G)return;if(!H(Z.data))return;try{this.#G(Z.data,{origin:"sharedworker"})}catch($){console.error("[CrossBus] SharedWorker handler error:",$)}}#Y(Z){console.error("[CrossBus] SharedWorker message error:",Z)}#K(Z){console.error("[CrossBus] SharedWorker error:",Z.message)}}class s{#Z=null;#$=null;#X=!1;#G;#J=null;static isSupported(){return typeof navigator<"u"&&"serviceWorker"in navigator}constructor(Z={}){if(!s.isSupported())throw W.from(Y.UNSUPPORTED,{api:"ServiceWorker"});this.#G=this.#Q()}get ready(){return this.#G}async#Q(){let Z=await navigator.serviceWorker.ready;this.#Z=Z.active||navigator.serviceWorker.controller,this.#J=this.#Y.bind(this),navigator.serviceWorker.addEventListener("message",this.#J)}send(Z,$){if(this.#X)throw W.from(Y.DESTROYED,{context:"ServiceWorkerTransport.send"});if(!this.#Z)throw W.from(Y.NOT_CONNECTED,{context:"ServiceWorkerTransport.send",reason:"No active ServiceWorker"});let X={[F]:x,...Z};if($&&$.length>0)this.#Z.postMessage(X,$);else this.#Z.postMessage(X)}onMessage(Z){if(typeof Z!=="function")throw TypeError("Handler must be a function");this.#$=Z}offMessage(){this.#$=null}destroy(){if(this.#X)return;if(this.#X=!0,this.#$=null,this.#J)navigator.serviceWorker.removeEventListener("message",this.#J),this.#J=null;this.#Z=null}get isDestroyed(){return this.#X}#Y(Z){if(!this.#$)return;if(!H(Z.data))return;try{this.#$(Z.data,{origin:"serviceworker"})}catch($){console.error("[CrossBus] ServiceWorker handler error:",$)}}}class C{#Z="none";#$;#X;#G=null;#J=!1;#Q=!1;#Y=[];#K;#D=null;#U;#j;#V;static detectBridge(){if(globalThis.CrossBus&&typeof globalThis.CrossBus.postMessage==="function")return"android";if(globalThis.AndroidBridge&&typeof globalThis.AndroidBridge.postMessage==="function")return"android";if(globalThis.webkit?.messageHandlers?.crossbus)return"ios";return"none"}static isSupported(){return C.detectBridge()!=="none"}constructor(Z={}){this.#$=Z.androidInterface??"CrossBus",this.#X=Z.iosHandler??"crossbus",this.#K=Z.queueWhileInit??!0,this.#U=Z.heartbeatInterval??30000,this.#j=new Promise(($)=>{this.#V=$}),this.#W(Z.initTimeout??5000)}async#W(Z){let $=Date.now(),X=()=>{if(this.#Z=C.detectBridge(),this.#Z!=="none"){this.#w();return}if(Date.now()-$<Z)setTimeout(X,50);else console.warn("[CrossBus] No native bridge detected after timeout"),this.#Q=!0,this.#V?.()};X(),this.#z()}#w(){if(this.#Q=!0,this.#V?.(),this.#F(),this.#U>0)this.#_()}#z(){globalThis.__crossbus_receive__=($)=>{if(this.#J||!this.#G)return;try{let X=typeof $==="string"?JSON.parse($):$;if(!H(X))return;this.#G(X,{bridgeType:this.#Z})}catch(X){console.error("[CrossBus] Failed to parse native message:",X)}}}send(Z){if(this.#J)throw W.from(Y.DESTROYED,{context:"NativeBridgeTransport.send"});let $={[F]:x,...Z};if(!this.#Q&&this.#K){this.#Y.push($);return}this.#A($)}#A(Z){let $=JSON.stringify(Z);try{if(this.#Z==="android"){let X=globalThis[this.#$]||globalThis.AndroidBridge;if(X?.postMessage)X.postMessage($)}else if(this.#Z==="ios"){let X=globalThis.webkit?.messageHandlers?.[this.#X];if(X?.postMessage)X.postMessage(Z)}}catch(X){console.error("[CrossBus] Failed to send to native:",X)}}#F(){while(this.#Y.length>0){let Z=this.#Y.shift();this.#A(Z)}}#_(){this.#D=setInterval(()=>{if(this.#J)return;this.#A({[F]:x,t:"hb",ts:Date.now()})},this.#U)}onMessage(Z){if(typeof Z!=="function")throw TypeError("Handler must be a function");this.#G=Z}offMessage(){this.#G=null}destroy(){if(this.#J)return;if(this.#J=!0,this.#G=null,this.#Y=[],this.#D)clearInterval(this.#D),this.#D=null;delete globalThis.__crossbus_receive__}get isDestroyed(){return this.#J}get bridgeType(){return this.#Z}get isReady(){return this.#Q}get ready(){return this.#j}}class QZ{#Z;#$;#X=null;#G;#J;#Q;#Y;#K;#D=null;#U=null;#j=null;#V=null;#W="disconnected";#w=[];#z=!1;constructor(Z){this.#Z=Z.url,this.#$=Z.peerId??q(),this.#G=Z.autoReconnect??!0,this.#J=Z.reconnectDelayMs??1000,this.#Q=Z.maxReconnectDelayMs??30000,this.#Y=this.#J,this.#K=Z.heartbeatIntervalMs??30000}get peerId(){return this.#$}get state(){return this.#W}get isConnected(){return this.#W==="connected"&&this.#X?.readyState===WebSocket.OPEN}async connect(){if(this.#X&&this.#X.readyState===WebSocket.OPEN)return;return this.#z=!1,this.#_("connecting"),new Promise((Z,$)=>{try{this.#X=new WebSocket(this.#Z),this.#X.onopen=()=>{this.#_("connected"),this.#Y=this.#J,this.#F(),this.#q(),Z()},this.#X.onmessage=(X)=>{this.#A(X)},this.#X.onclose=(X)=>{if(this.#L(),this.#_("disconnected"),!this.#z&&this.#G)this.#H()},this.#X.onerror=(X)=>{if(this.#_("error"),this.#W==="connecting")$(Error("WebSocket connection failed"))}}catch(X){this.#_("error"),$(X)}})}disconnect(){if(this.#z=!0,this.#L(),this.#U)clearTimeout(this.#U),this.#U=null;if(this.#X)this.#X.close(1000,"Client disconnect"),this.#X=null;this.#_("disconnected")}send(Z){let $={_cb:x,_m:F,id:q(),from:this.#$,timestamp:Date.now(),...Z};if(this.isConnected&&this.#X)return this.#X.send(JSON.stringify($)),!0;else return this.#w.push($),!1}onMessage(Z){this.#j=Z}onStateChange(Z){this.#V=Z}#A(Z){try{let $=JSON.parse(Z.data);if($.type==="pong")return;if(this.#j)this.#j($)}catch($){console.error("[WebSocketTransport] Failed to parse message:",$)}}#F(){while(this.#w.length>0&&this.isConnected&&this.#X){let Z=this.#w.shift();if(Z)this.#X.send(JSON.stringify(Z))}}#_(Z){if(this.#W!==Z){if(this.#W=Z,this.#V)this.#V(Z)}}#q(){if(this.#K<=0)return;this.#D=setInterval(()=>{if(this.isConnected&&this.#X)this.#X.send(JSON.stringify({type:"ping",from:this.#$}))},this.#K)}#L(){if(this.#D)clearInterval(this.#D),this.#D=null}#H(){if(this.#U)return;this.#U=setTimeout(async()=>{this.#U=null;try{await this.connect()}catch{if(this.#Y=Math.min(this.#Y*2,this.#Q),this.#G&&!this.#z)this.#H()}},this.#Y)}destroy(){this.disconnect(),this.#j=null,this.#V=null,this.#w=[]}}class B{#Z;#$;constructor(Z,$={}){if(this.#Z=Z,this.#$=new Map(Object.entries($)),!this.#$.has(Z))this.#$.set(Z,0)}get ownId(){return this.#Z}get(Z){return this.#$.get(Z)??0}tick(){let $=this.get(this.#Z)+1;return this.#$.set(this.#Z,$),$}update(Z){for(let[$,X]of Z.#$){let J=this.get($);if(X>J)this.#$.set($,X)}}happenedBefore(Z){let $=!1,X=new Set([...this.#$.keys(),...Z.#$.keys()]);for(let J of X){let G=this.get(J),Q=Z.get(J);if(G>Q)return!1;if(G<Q)$=!0}return $}isConcurrentWith(Z){return!this.happenedBefore(Z)&&!Z.happenedBefore(this)&&!this.equals(Z)}equals(Z){let $=new Set([...this.#$.keys(),...Z.#$.keys()]);for(let X of $)if(this.get(X)!==Z.get(X))return!1;return!0}canDeliver(Z,$){let X=Z.get($),J=this.get($);if(X!==J+1)return!1;for(let[G,Q]of Z.#$){if(G===$)continue;if(Q>this.get(G))return!1}return!0}clone(){let Z=Object.fromEntries(this.#$);return new B(this.#Z,Z)}toJSON(){return{ownId:this.#Z,counters:Object.fromEntries(this.#$)}}static fromJSON(Z){return new B(Z.ownId,Z.counters)}toString(){let Z=[...this.#$.entries()].map(([$,X])=>`${$}:${X}`).join(", ");return`VectorClock(${this.#Z}){${Z}}`}}class YZ{#Z;#$;#X;#G;#J;#Q;constructor(Z,$={}){this.#Z=Z,this.#$=new B(Z),this.#X=[],this.#G=$.onDeliver||(()=>{}),this.#J=$.maxBufferSize??1000,this.#Q=$.onBufferOverflow||null}get ownId(){return this.#Z}get bufferSize(){return this.#X.length}receive(Z,$){let X=B.fromJSON($.clock);if(this.#$.canDeliver(X,Z))this.#Y(Z,$,X),this.#D();else this.#K(Z,$,X)}#Y(Z,$,X){this.#$.update(X),this.#G($)}#K(Z,$,X){if(this.#X.length>=this.#J){if(this.#Q)this.#Q({senderId:Z,message:$,bufferSize:this.#X.length});return}this.#X.push({senderId:Z,message:$,clock:X})}#D(){let Z=!0;while(Z){Z=!1;for(let $=this.#X.length-1;$>=0;$--){let{senderId:X,message:J,clock:G}=this.#X[$];if(this.#$.canDeliver(G,X))this.#X.splice($,1),this.#Y(X,J,G),Z=!0}}}tick(){return this.#$.tick(),this.#$.clone()}getVectorClock(){return this.#$.clone()}clear(){this.#X=[]}}var KZ="0.1.0",S="__MICROUI_CROSSBUS__",L=typeof window<"u"?window:globalThis,DZ=["ui:toast","ui:modal","ui:theme","ui:tabs","ui:dropdown","ui:form","ui:grid","ui:stack","ui:virtual-list"],UZ={type:"ui-framework",version:KZ,description:"AI-Optimized UI Framework - Web Components Edition"};if(!L[S])L[S]=new k({peerId:"microui",isHub:!0,requestTimeout:5000,capabilities:DZ,meta:UZ}),L[S].setMaxListeners(100);var _=L[S],I="__MICROUI_COMPONENT_REGISTRY__";if(!L[I])L[I]=new Map;var zZ=L[I],WZ={on(Z,$){let X=_.on(Z,(J)=>{$(J.data??J)});return()=>X.unsubscribe()},once(Z,$){let X=this.on(Z,(J)=>{X(),$(J)})},off(Z,$){_.off(Z,$)},emit(Z,$){return _.emitSync(Z,$)},async emitAsync(Z,$){return _.emit(Z,$)},signal(Z,$){_.signal(Z,$)},async request(Z,$,X){return _.request(Z,$,X)},async broadcastRequest(Z,$){return _.broadcastRequest(Z,$)},handle(Z,$){return _.handle(Z,$)},unhandle(Z){_.unhandle(Z)},destroy(){_.destroy()},setMaxListeners(Z){_.setMaxListeners(Z)},get peerId(){return _.peerId},get peers(){return _.peers},get peerCount(){return _.peerCount},hasListeners(Z){return _.hasListeners(Z)},get raw(){return _}},jZ={TOAST_SHOW:"ui:toast:show",TOAST_DISMISS:"ui:toast:dismiss",MODAL_OPEN:"ui:modal:open",MODAL_CLOSE:"ui:modal:close",THEME_CHANGE:"ui:theme:change",TAB_CHANGE:"ui:tab:change",DROPDOWN_SELECT:"ui:dropdown:select",FORM_SUBMIT:"ui:form:submit",FORM_VALIDATE:"ui:form:validate"},xZ=(Z,$={})=>{WZ.emit(jZ.TOAST_SHOW,{message:Z,...$})};var FZ=(Z,$)=>{zZ.set(Z,{...$,registeredAt:Date.now()})};
|
|
14
|
+
export{WZ as o,jZ as p,xZ as q,FZ as r};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
class H{#j=[];#x=!1;schedule(j){if(this.#j.push(j),!this.#x)this.#x=!0,requestAnimationFrame(()=>this.#A())}#A(){let j=this.#j.slice();this.#j=[],this.#x=!1;for(let C of j)try{C()}catch(x){console.error("[RenderScheduler] Error:",x)}}}var J=new H;function K(j,C=JSON.stringify){let x=new Map;return(...A)=>{let E=C(A);if(x.has(E))return x.get(E);let G=j(...A);return x.set(E,G),G}}function L(j,C=100){let x=null;return(...A)=>{if(x)clearTimeout(x);x=setTimeout(()=>j(...A),C)}}function M(j,C=100){let x=!1;return(...A)=>{if(!x)j(...A),x=!0,setTimeout(()=>x=!1,C)}}function N(j,C={}){let x=new IntersectionObserver((A)=>{for(let E of A)if(E.isIntersecting)j(E.target),x.unobserve(E.target)},{rootMargin:"100px",threshold:0,...C});return{observe:(A)=>x.observe(A),disconnect:()=>x.disconnect()}}class I{#j=[];#x=[];#A=!1;read(j){this.#j.push(j),this.#C()}write(j){this.#x.push(j),this.#C()}#C(){if(!this.#A)this.#A=!0,requestAnimationFrame(()=>this.#E())}#E(){let j;while(j=this.#j.shift())try{j()}catch(C){console.error(C)}while(j=this.#x.shift())try{j()}catch(C){console.error(C)}if(this.#A=!1,this.#j.length||this.#x.length)this.#C()}}var O=new I;async function P(j,C,x=100){for(let A=0;A<j.length;A+=x){let E=j.slice(A,A+x);for(let G of E)C(G,A);await new Promise((G)=>setTimeout(G,0))}}
|
|
2
|
+
export{J as s,K as t,L as u,M as v,N as w,O as x,P as y};
|