@threadlabs/looma 0.47.5 → 0.49.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/README.md +39 -16
- package/components/shared/input-modality.d.ts +2 -0
- package/components/shared/input-modality.js +2 -0
- package/components/shared/overlay.js +9 -0
- package/components/ui-card/ui-card.html +8 -0
- package/components/ui-compact-content/ui-compact-content.html +8 -0
- package/components/ui-compact-content/ui-compact-content.js +1 -0
- package/components/ui-compact-editor/ui-compact-editor.css +39 -0
- package/components/ui-compact-editor/ui-compact-editor.html +22 -0
- package/components/ui-compact-editor/ui-compact-editor.js +30 -0
- package/components/ui-compact-mark/ui-compact-mark.html +26 -0
- package/components/ui-compact-node/ui-compact-node.html +14 -0
- package/components/ui-dialog/ui-dialog.html +4 -1
- package/components/ui-editor/ui-editor.css +531 -0
- package/components/ui-editor/ui-editor.html +399 -0
- package/components/ui-editor/ui-editor.js +87 -0
- package/components/ui-editor-chip-editor/ui-editor-chip-editor.html +2 -1
- package/components/ui-editor-chip-editor/ui-editor-chip-editor.js +6 -0
- package/components/ui-editor-formatting-tools/ui-editor-formatting-tools.html +59 -0
- package/components/ui-editor-formatting-tools/ui-editor-formatting-tools.js +44 -0
- package/components/ui-editor-link-form/ui-editor-link-form.html +1 -0
- package/components/ui-editor-link-form/ui-editor-link-form.js +7 -0
- package/components/ui-editor-surface/ui-editor-surface.css +109 -0
- package/components/ui-editor-table-context-menu/ui-editor-table-context-menu.html +1 -1
- package/components/ui-editor-table-toolbar/ui-editor-table-toolbar.js +7 -4
- package/components/ui-menu/ui-menu.html +4 -1
- package/components/ui-meter/ui-meter.html +7 -7
- package/components/ui-popover/ui-popover.html +4 -1
- package/components/ui-radio-group/ui-radio-group.html +3 -1
- package/components/ui-radio-group/ui-radio-group.js +5 -0
- package/dist/index.js +57 -53
- package/docs/README.md +5 -7
- package/docs/catalog.json +945 -86
- package/docs/catalog.mjs +2 -2
- package/docs/framework-examples.d.mts +7 -0
- package/docs/framework-examples.mjs +89 -0
- package/docs/index.d.ts +1 -1
- package/docs/render.mjs +3 -40
- package/editor/chunks/content.js +29 -0
- package/{vue/chunks/compact.js → editor/chunks/dist.js} +103 -230
- package/editor/chunks/expressmark.js +1 -24
- package/editor/chunks/extensions.js +63 -455
- package/editor/chunks/session.js +61 -0
- package/editor/chunks/{ui.js → table-overlay.js} +51 -1
- package/editor/compact.d.ts +22 -0
- package/editor/compact.js +63 -0
- package/editor/components.css +3699 -0
- package/editor/document-session.d.ts +274 -0
- package/editor/extensions/index.js +2 -2
- package/editor/index.d.ts +4 -0
- package/editor/index.js +15578 -4
- package/editor/session.d.ts +1 -1
- package/editor/toolbar-tooltip.d.ts +5 -1
- package/editor/ui.js +1 -2
- package/package.json +31 -46
- package/styles/ui-action-bar.css +1 -1
- package/styles/ui-affordance-scope.css +1 -1
- package/styles/ui-avatar-group.css +1 -1
- package/styles/ui-avatar.css +1 -1
- package/styles/ui-badge.css +1 -1
- package/styles/ui-breadcrumb-item.css +1 -1
- package/styles/ui-breadcrumbs.css +1 -1
- package/styles/ui-button.css +1 -1
- package/styles/ui-callout.css +1 -1
- package/styles/ui-card-group.css +1 -1
- package/styles/ui-card.css +9 -1
- package/styles/ui-checkbox.css +1 -1
- package/styles/ui-cluster.css +1 -1
- package/styles/ui-color-picker.css +1 -1
- package/styles/ui-combobox.css +1 -1
- package/styles/ui-compact-content.css +1 -0
- package/styles/ui-compact-editor.css +1 -0
- package/styles/ui-compact-mark.css +1 -0
- package/styles/ui-compact-node.css +1 -0
- package/styles/ui-container.css +1 -1
- package/styles/ui-context-menu.css +1 -1
- package/styles/ui-cover.css +1 -1
- package/styles/ui-curve-editor.css +1 -1
- package/styles/ui-cycle-button.css +1 -1
- package/styles/ui-description-item.css +1 -1
- package/styles/ui-description-list.css +1 -1
- package/styles/ui-dialog.css +9 -3
- package/styles/ui-disclosure.css +1 -1
- package/styles/ui-editable.css +1 -1
- package/styles/ui-editor-block-actions.css +1 -1
- package/styles/ui-editor-chip-editor.css +1 -1
- package/styles/ui-editor-code-language.css +1 -1
- package/styles/ui-editor-footnote-editor.css +1 -1
- package/styles/ui-editor-formatting-tools.css +1 -0
- package/styles/ui-editor-image-toolbar.css +1 -1
- package/styles/ui-editor-insert-table-grid.css +1 -1
- package/styles/ui-editor-link-card.css +1 -1
- package/styles/ui-editor-link-form.css +1 -1
- package/styles/ui-editor-mention-menu-item.css +1 -1
- package/styles/ui-editor-mention-menu.css +1 -1
- package/styles/ui-editor-slash-menu-group.css +1 -1
- package/styles/ui-editor-slash-menu-item.css +1 -1
- package/styles/ui-editor-slash-menu.css +1 -1
- package/styles/ui-editor-surface.css +1 -1
- package/styles/ui-editor-table-context-menu.css +1 -1
- package/styles/ui-editor-table-overlay.css +1 -1
- package/styles/ui-editor-table-toolbar.css +1 -1
- package/styles/ui-editor-toolbar.css +1 -1
- package/styles/ui-editor.css +1 -0
- package/styles/ui-floating-action-button.css +1 -1
- package/styles/ui-form-field.css +1 -1
- package/styles/ui-grid.css +1 -1
- package/styles/ui-icon-button.css +1 -1
- package/styles/ui-icon.css +1 -1
- package/styles/ui-image.css +1 -1
- package/styles/ui-input-group.css +1 -1
- package/styles/ui-input.css +1 -1
- package/styles/ui-light-editor.css +1 -1
- package/styles/ui-list-item.css +1 -1
- package/styles/ui-list.css +1 -1
- package/styles/ui-listbox.css +1 -1
- package/styles/ui-menu-group.css +1 -1
- package/styles/ui-menu-item.css +1 -1
- package/styles/ui-menu.css +5 -2
- package/styles/ui-meter.css +8 -8
- package/styles/ui-nav-item.css +1 -1
- package/styles/ui-number-input.css +1 -1
- package/styles/ui-page-header.css +1 -1
- package/styles/ui-pagination.css +1 -1
- package/styles/ui-popover.css +5 -2
- package/styles/ui-radio-group.css +1 -1
- package/styles/ui-radio.css +1 -1
- package/styles/ui-reel.css +1 -1
- package/styles/ui-scroll-area.css +1 -1
- package/styles/ui-search-result-row.css +1 -1
- package/styles/ui-search-shell.css +1 -1
- package/styles/ui-section.css +1 -1
- package/styles/ui-select.css +1 -1
- package/styles/ui-separator.css +1 -1
- package/styles/ui-sidebar.css +1 -1
- package/styles/ui-site-header.css +1 -1
- package/styles/ui-skeleton.css +1 -1
- package/styles/ui-slider.css +1 -1
- package/styles/ui-spinner.css +1 -1
- package/styles/ui-stack.css +1 -1
- package/styles/ui-status-message.css +1 -1
- package/styles/ui-swatch.css +1 -1
- package/styles/ui-switch.css +1 -1
- package/styles/ui-switcher.css +1 -1
- package/styles/ui-table.css +1 -1
- package/styles/ui-tabs.css +1 -1
- package/styles/ui-text.css +1 -1
- package/styles/ui-textarea.css +1 -1
- package/styles/ui-toast-region.css +1 -1
- package/styles/ui-toast.css +1 -1
- package/styles/ui-tooltip.css +1 -1
- package/styles/ui-top-bar.css +1 -1
- package/styles/ui-tree-item.css +1 -1
- package/styles/ui-tree.css +1 -1
- package/vanilla/UiActionBar.d.ts +1 -1
- package/vanilla/UiActionBar.js +1 -1
- package/vanilla/UiAffordanceScope.d.ts +1 -1
- package/vanilla/UiAffordanceScope.js +1 -1
- package/vanilla/UiAvatar.d.ts +1 -1
- package/vanilla/UiAvatar.js +1 -1
- package/vanilla/UiAvatarGroup.d.ts +1 -1
- package/vanilla/UiAvatarGroup.js +1 -1
- package/vanilla/UiBadge.d.ts +1 -1
- package/vanilla/UiBadge.js +1 -1
- package/vanilla/UiBreadcrumbItem.d.ts +1 -1
- package/vanilla/UiBreadcrumbItem.js +1 -1
- package/vanilla/UiBreadcrumbs.d.ts +1 -1
- package/vanilla/UiBreadcrumbs.js +1 -1
- package/vanilla/UiButton.d.ts +1 -1
- package/vanilla/UiButton.js +1 -1
- package/vanilla/UiCallout.d.ts +1 -1
- package/vanilla/UiCallout.js +1 -1
- package/vanilla/UiCard.d.ts +1 -1
- package/vanilla/UiCard.js +1 -1
- package/vanilla/UiCardGroup.d.ts +1 -1
- package/vanilla/UiCardGroup.js +1 -1
- package/vanilla/UiCheckbox.d.ts +1 -1
- package/vanilla/UiCheckbox.js +1 -1
- package/vanilla/UiCluster.d.ts +1 -1
- package/vanilla/UiCluster.js +1 -1
- package/vanilla/UiColorPicker.d.ts +1 -1
- package/vanilla/UiColorPicker.js +1 -1
- package/vanilla/UiCombobox.d.ts +1 -1
- package/vanilla/UiCombobox.js +1 -1
- package/vanilla/UiCompactContent.d.ts +23 -0
- package/vanilla/UiCompactContent.js +51 -0
- package/vanilla/UiCompactEditor.d.ts +29 -0
- package/vanilla/UiCompactEditor.js +59 -0
- package/vanilla/UiCompactMark.d.ts +25 -0
- package/vanilla/UiCompactMark.js +206 -0
- package/vanilla/UiCompactNode.d.ts +23 -0
- package/vanilla/UiCompactNode.js +156 -0
- package/vanilla/UiContainer.d.ts +1 -1
- package/vanilla/UiContainer.js +1 -1
- package/vanilla/UiContextMenu.d.ts +1 -1
- package/vanilla/UiContextMenu.js +1 -1
- package/vanilla/UiCover.d.ts +1 -1
- package/vanilla/UiCover.js +1 -1
- package/vanilla/UiCurveEditor.d.ts +1 -1
- package/vanilla/UiCurveEditor.js +1 -1
- package/vanilla/UiCycleButton.d.ts +1 -1
- package/vanilla/UiCycleButton.js +1 -1
- package/vanilla/UiDescriptionItem.d.ts +1 -1
- package/vanilla/UiDescriptionItem.js +1 -1
- package/vanilla/UiDescriptionList.d.ts +1 -1
- package/vanilla/UiDescriptionList.js +1 -1
- package/vanilla/UiDialog.d.ts +1 -1
- package/vanilla/UiDialog.js +1 -1
- package/vanilla/UiDisclosure.d.ts +1 -1
- package/vanilla/UiDisclosure.js +1 -1
- package/vanilla/UiEditable.d.ts +1 -1
- package/vanilla/UiEditable.js +1 -1
- package/vanilla/UiEditor.d.ts +57 -0
- package/vanilla/UiEditor.js +1067 -0
- package/vanilla/UiEditorBlockActions.d.ts +1 -1
- package/vanilla/UiEditorBlockActions.js +1 -1
- package/vanilla/UiEditorChipEditor.d.ts +2 -1
- package/vanilla/UiEditorChipEditor.js +10 -10
- package/vanilla/UiEditorCodeLanguage.d.ts +1 -1
- package/vanilla/UiEditorCodeLanguage.js +1 -1
- package/vanilla/UiEditorFootnoteEditor.d.ts +1 -1
- package/vanilla/UiEditorFootnoteEditor.js +1 -1
- package/vanilla/UiEditorFormattingTools.d.ts +27 -0
- package/vanilla/UiEditorFormattingTools.js +188 -0
- package/vanilla/UiEditorImageToolbar.d.ts +1 -1
- package/vanilla/UiEditorImageToolbar.js +1 -1
- package/vanilla/UiEditorInsertTableGrid.d.ts +1 -1
- package/vanilla/UiEditorInsertTableGrid.js +1 -1
- package/vanilla/UiEditorLinkCard.d.ts +1 -1
- package/vanilla/UiEditorLinkCard.js +1 -1
- package/vanilla/UiEditorLinkForm.d.ts +2 -1
- package/vanilla/UiEditorLinkForm.js +41 -41
- package/vanilla/UiEditorMentionMenu.d.ts +1 -1
- package/vanilla/UiEditorMentionMenu.js +1 -1
- package/vanilla/UiEditorMentionMenuItem.d.ts +1 -1
- package/vanilla/UiEditorMentionMenuItem.js +1 -1
- package/vanilla/UiEditorSlashMenu.d.ts +1 -1
- package/vanilla/UiEditorSlashMenu.js +1 -1
- package/vanilla/UiEditorSlashMenuGroup.d.ts +1 -1
- package/vanilla/UiEditorSlashMenuGroup.js +1 -1
- package/vanilla/UiEditorSlashMenuItem.d.ts +1 -1
- package/vanilla/UiEditorSlashMenuItem.js +1 -1
- package/vanilla/UiEditorSurface.d.ts +1 -1
- package/vanilla/UiEditorSurface.js +1 -1
- package/vanilla/UiEditorTableContextMenu.d.ts +1 -1
- package/vanilla/UiEditorTableContextMenu.js +10 -5
- package/vanilla/UiEditorTableOverlay.d.ts +1 -1
- package/vanilla/UiEditorTableOverlay.js +1 -1
- package/vanilla/UiEditorTableToolbar.d.ts +1 -1
- package/vanilla/UiEditorTableToolbar.js +1 -1
- package/vanilla/UiEditorToolbar.d.ts +1 -1
- package/vanilla/UiEditorToolbar.js +1 -1
- package/vanilla/UiFloatingActionButton.d.ts +1 -1
- package/vanilla/UiFloatingActionButton.js +1 -1
- package/vanilla/UiFormField.d.ts +1 -1
- package/vanilla/UiFormField.js +1 -1
- package/vanilla/UiGrid.d.ts +1 -1
- package/vanilla/UiGrid.js +1 -1
- package/vanilla/UiIcon.d.ts +1 -1
- package/vanilla/UiIcon.js +1 -1
- package/vanilla/UiIconButton.d.ts +1 -1
- package/vanilla/UiIconButton.js +1 -1
- package/vanilla/UiImage.d.ts +1 -1
- package/vanilla/UiImage.js +1 -1
- package/vanilla/UiInput.d.ts +1 -1
- package/vanilla/UiInput.js +1 -1
- package/vanilla/UiInputGroup.d.ts +1 -1
- package/vanilla/UiInputGroup.js +1 -1
- package/vanilla/UiLightEditor.d.ts +1 -1
- package/vanilla/UiLightEditor.js +1 -1
- package/vanilla/UiList.d.ts +1 -1
- package/vanilla/UiList.js +1 -1
- package/vanilla/UiListItem.d.ts +1 -1
- package/vanilla/UiListItem.js +1 -1
- package/vanilla/UiListbox.d.ts +1 -1
- package/vanilla/UiListbox.js +1 -1
- package/vanilla/UiMenu.d.ts +1 -1
- package/vanilla/UiMenu.js +1 -1
- package/vanilla/UiMenuGroup.d.ts +1 -1
- package/vanilla/UiMenuGroup.js +1 -1
- package/vanilla/UiMenuItem.d.ts +1 -1
- package/vanilla/UiMenuItem.js +1 -1
- package/vanilla/UiMeter.d.ts +1 -1
- package/vanilla/UiMeter.js +1 -1
- package/vanilla/UiNavItem.d.ts +1 -1
- package/vanilla/UiNavItem.js +1 -1
- package/vanilla/UiNumberInput.d.ts +1 -1
- package/vanilla/UiNumberInput.js +1 -1
- package/vanilla/UiPageHeader.d.ts +1 -1
- package/vanilla/UiPageHeader.js +1 -1
- package/vanilla/UiPagination.d.ts +1 -1
- package/vanilla/UiPagination.js +1 -1
- package/vanilla/UiPopover.d.ts +1 -1
- package/vanilla/UiPopover.js +1 -1
- package/vanilla/UiRadio.d.ts +1 -1
- package/vanilla/UiRadio.js +1 -1
- package/vanilla/UiRadioGroup.d.ts +2 -1
- package/vanilla/UiRadioGroup.js +33 -28
- package/vanilla/UiReel.d.ts +1 -1
- package/vanilla/UiReel.js +1 -1
- package/vanilla/UiScrollArea.d.ts +1 -1
- package/vanilla/UiScrollArea.js +1 -1
- package/vanilla/UiSearchResultRow.d.ts +1 -1
- package/vanilla/UiSearchResultRow.js +1 -1
- package/vanilla/UiSearchShell.d.ts +1 -1
- package/vanilla/UiSearchShell.js +1 -1
- package/vanilla/UiSection.d.ts +1 -1
- package/vanilla/UiSection.js +1 -1
- package/vanilla/UiSelect.d.ts +1 -1
- package/vanilla/UiSelect.js +1 -1
- package/vanilla/UiSeparator.d.ts +1 -1
- package/vanilla/UiSeparator.js +1 -1
- package/vanilla/UiSidebar.d.ts +1 -1
- package/vanilla/UiSidebar.js +1 -1
- package/vanilla/UiSiteHeader.d.ts +1 -1
- package/vanilla/UiSiteHeader.js +1 -1
- package/vanilla/UiSkeleton.d.ts +1 -1
- package/vanilla/UiSkeleton.js +1 -1
- package/vanilla/UiSlider.d.ts +1 -1
- package/vanilla/UiSlider.js +1 -1
- package/vanilla/UiSpinner.d.ts +1 -1
- package/vanilla/UiSpinner.js +1 -1
- package/vanilla/UiStack.d.ts +1 -1
- package/vanilla/UiStack.js +1 -1
- package/vanilla/UiStatusMessage.d.ts +1 -1
- package/vanilla/UiStatusMessage.js +1 -1
- package/vanilla/UiSwatch.d.ts +1 -1
- package/vanilla/UiSwatch.js +1 -1
- package/vanilla/UiSwitch.d.ts +1 -1
- package/vanilla/UiSwitch.js +1 -1
- package/vanilla/UiSwitcher.d.ts +1 -1
- package/vanilla/UiSwitcher.js +1 -1
- package/vanilla/UiTable.d.ts +1 -1
- package/vanilla/UiTable.js +1 -1
- package/vanilla/UiTabs.d.ts +1 -1
- package/vanilla/UiTabs.js +1 -1
- package/vanilla/UiText.d.ts +1 -1
- package/vanilla/UiText.js +1 -1
- package/vanilla/UiTextarea.d.ts +1 -1
- package/vanilla/UiTextarea.js +1 -1
- package/vanilla/UiToast.d.ts +1 -1
- package/vanilla/UiToast.js +1 -1
- package/vanilla/UiToastRegion.d.ts +1 -1
- package/vanilla/UiToastRegion.js +1 -1
- package/vanilla/UiTooltip.d.ts +1 -1
- package/vanilla/UiTooltip.js +1 -1
- package/vanilla/UiTopBar.d.ts +1 -1
- package/vanilla/UiTopBar.js +1 -1
- package/vanilla/UiTree.d.ts +1 -1
- package/vanilla/UiTree.js +1 -1
- package/vanilla/UiTreeItem.d.ts +1 -1
- package/vanilla/UiTreeItem.js +1 -1
- package/vanilla/index.js +6 -0
- package/editor/chunks/table-backgrounds.js +0 -51
- package/vue/UiActionBar.d.ts +0 -19
- package/vue/UiActionBar.js +0 -2
- package/vue/UiActionBar.vue +0 -90
- package/vue/UiAffordanceScope.d.ts +0 -35
- package/vue/UiAffordanceScope.js +0 -2
- package/vue/UiAffordanceScope.vue +0 -182
- package/vue/UiAvatar.d.ts +0 -71
- package/vue/UiAvatar.js +0 -2
- package/vue/UiAvatar.vue +0 -394
- package/vue/UiAvatarGroup.d.ts +0 -53
- package/vue/UiAvatarGroup.js +0 -2
- package/vue/UiAvatarGroup.vue +0 -305
- package/vue/UiBadge.d.ts +0 -49
- package/vue/UiBadge.js +0 -2
- package/vue/UiBadge.vue +0 -810
- package/vue/UiBreadcrumbItem.d.ts +0 -29
- package/vue/UiBreadcrumbItem.js +0 -2
- package/vue/UiBreadcrumbItem.vue +0 -192
- package/vue/UiBreadcrumbs.d.ts +0 -29
- package/vue/UiBreadcrumbs.js +0 -2
- package/vue/UiBreadcrumbs.vue +0 -117
- package/vue/UiButton.d.ts +0 -131
- package/vue/UiButton.js +0 -2
- package/vue/UiButton.vue +0 -1609
- package/vue/UiCallout.d.ts +0 -35
- package/vue/UiCallout.js +0 -2
- package/vue/UiCallout.vue +0 -418
- package/vue/UiCard.d.ts +0 -81
- package/vue/UiCard.js +0 -2
- package/vue/UiCard.vue +0 -522
- package/vue/UiCardGroup.d.ts +0 -41
- package/vue/UiCardGroup.js +0 -2
- package/vue/UiCardGroup.vue +0 -168
- package/vue/UiCheckbox.d.ts +0 -95
- package/vue/UiCheckbox.js +0 -2
- package/vue/UiCheckbox.vue +0 -601
- package/vue/UiCluster.d.ts +0 -65
- package/vue/UiCluster.js +0 -2
- package/vue/UiCluster.vue +0 -304
- package/vue/UiColorPicker.d.ts +0 -71
- package/vue/UiColorPicker.js +0 -2
- package/vue/UiColorPicker.vue +0 -563
- package/vue/UiCombobox.d.ts +0 -538
- package/vue/UiCombobox.js +0 -2
- package/vue/UiCombobox.vue +0 -2894
- package/vue/UiContainer.d.ts +0 -41
- package/vue/UiContainer.js +0 -2
- package/vue/UiContainer.vue +0 -177
- package/vue/UiContextMenu.d.ts +0 -69
- package/vue/UiContextMenu.js +0 -2
- package/vue/UiContextMenu.vue +0 -289
- package/vue/UiCover.d.ts +0 -29
- package/vue/UiCover.js +0 -2
- package/vue/UiCover.vue +0 -127
- package/vue/UiCurveEditor.d.ts +0 -59
- package/vue/UiCurveEditor.js +0 -2
- package/vue/UiCurveEditor.vue +0 -429
- package/vue/UiCycleButton.d.ts +0 -69
- package/vue/UiCycleButton.js +0 -2
- package/vue/UiCycleButton.vue +0 -403
- package/vue/UiDescriptionItem.d.ts +0 -29
- package/vue/UiDescriptionItem.js +0 -2
- package/vue/UiDescriptionItem.vue +0 -124
- package/vue/UiDescriptionList.d.ts +0 -41
- package/vue/UiDescriptionList.js +0 -2
- package/vue/UiDescriptionList.vue +0 -217
- package/vue/UiDialog.d.ts +0 -97
- package/vue/UiDialog.js +0 -2
- package/vue/UiDialog.vue +0 -817
- package/vue/UiDisclosure.d.ts +0 -107
- package/vue/UiDisclosure.js +0 -2
- package/vue/UiDisclosure.vue +0 -605
- package/vue/UiEditable.d.ts +0 -113
- package/vue/UiEditable.js +0 -2
- package/vue/UiEditable.vue +0 -582
- package/vue/UiEditorBlockActions.d.ts +0 -33
- package/vue/UiEditorBlockActions.js +0 -2
- package/vue/UiEditorBlockActions.vue +0 -163
- package/vue/UiEditorChipEditor.d.ts +0 -45
- package/vue/UiEditorChipEditor.js +0 -2
- package/vue/UiEditorChipEditor.vue +0 -208
- package/vue/UiEditorCodeLanguage.d.ts +0 -41
- package/vue/UiEditorCodeLanguage.js +0 -2
- package/vue/UiEditorCodeLanguage.vue +0 -200
- package/vue/UiEditorFootnoteEditor.d.ts +0 -39
- package/vue/UiEditorFootnoteEditor.js +0 -2
- package/vue/UiEditorFootnoteEditor.vue +0 -152
- package/vue/UiEditorImageToolbar.d.ts +0 -51
- package/vue/UiEditorImageToolbar.js +0 -2
- package/vue/UiEditorImageToolbar.vue +0 -446
- package/vue/UiEditorInsertTableGrid.d.ts +0 -49
- package/vue/UiEditorInsertTableGrid.js +0 -2
- package/vue/UiEditorInsertTableGrid.vue +0 -367
- package/vue/UiEditorLinkCard.d.ts +0 -49
- package/vue/UiEditorLinkCard.js +0 -2
- package/vue/UiEditorLinkCard.vue +0 -385
- package/vue/UiEditorLinkForm.d.ts +0 -131
- package/vue/UiEditorLinkForm.js +0 -2
- package/vue/UiEditorLinkForm.vue +0 -664
- package/vue/UiEditorMentionMenu.d.ts +0 -121
- package/vue/UiEditorMentionMenu.js +0 -2
- package/vue/UiEditorMentionMenu.vue +0 -596
- package/vue/UiEditorMentionMenuItem.d.ts +0 -43
- package/vue/UiEditorMentionMenuItem.js +0 -2
- package/vue/UiEditorMentionMenuItem.vue +0 -205
- package/vue/UiEditorSlashMenu.d.ts +0 -111
- package/vue/UiEditorSlashMenu.js +0 -2
- package/vue/UiEditorSlashMenu.vue +0 -549
- package/vue/UiEditorSlashMenuGroup.d.ts +0 -29
- package/vue/UiEditorSlashMenuGroup.js +0 -2
- package/vue/UiEditorSlashMenuGroup.vue +0 -113
- package/vue/UiEditorSlashMenuItem.d.ts +0 -53
- package/vue/UiEditorSlashMenuItem.js +0 -2
- package/vue/UiEditorSlashMenuItem.vue +0 -249
- package/vue/UiEditorSurface.d.ts +0 -29
- package/vue/UiEditorSurface.js +0 -2
- package/vue/UiEditorSurface.vue +0 -117
- package/vue/UiEditorTableContextMenu.d.ts +0 -57
- package/vue/UiEditorTableContextMenu.js +0 -2
- package/vue/UiEditorTableContextMenu.vue +0 -694
- package/vue/UiEditorTableOverlay.d.ts +0 -191
- package/vue/UiEditorTableOverlay.js +0 -2
- package/vue/UiEditorTableOverlay.vue +0 -1099
- package/vue/UiEditorTableToolbar.d.ts +0 -57
- package/vue/UiEditorTableToolbar.js +0 -2
- package/vue/UiEditorTableToolbar.vue +0 -834
- package/vue/UiEditorToolbar.d.ts +0 -29
- package/vue/UiEditorToolbar.js +0 -2
- package/vue/UiEditorToolbar.vue +0 -296
- package/vue/UiFloatingActionButton.d.ts +0 -41
- package/vue/UiFloatingActionButton.js +0 -2
- package/vue/UiFloatingActionButton.vue +0 -201
- package/vue/UiFormField.d.ts +0 -49
- package/vue/UiFormField.js +0 -2
- package/vue/UiFormField.vue +0 -256
- package/vue/UiGrid.d.ts +0 -41
- package/vue/UiGrid.js +0 -2
- package/vue/UiGrid.vue +0 -190
- package/vue/UiIcon.d.ts +0 -25
- package/vue/UiIcon.js +0 -2
- package/vue/UiIcon.vue +0 -612
- package/vue/UiIconButton.d.ts +0 -101
- package/vue/UiIconButton.js +0 -2
- package/vue/UiIconButton.vue +0 -1141
- package/vue/UiImage.d.ts +0 -85
- package/vue/UiImage.js +0 -2
- package/vue/UiImage.vue +0 -462
- package/vue/UiInput.d.ts +0 -50
- package/vue/UiInput.js +0 -2
- package/vue/UiInput.vue +0 -671
- package/vue/UiInputGroup.d.ts +0 -59
- package/vue/UiInputGroup.js +0 -2
- package/vue/UiInputGroup.vue +0 -447
- package/vue/UiLightEditor.d.ts +0 -83
- package/vue/UiLightEditor.js +0 -2
- package/vue/UiLightEditor.vue +0 -537
- package/vue/UiList.d.ts +0 -49
- package/vue/UiList.js +0 -2
- package/vue/UiList.vue +0 -260
- package/vue/UiListItem.d.ts +0 -65
- package/vue/UiListItem.js +0 -2
- package/vue/UiListItem.vue +0 -407
- package/vue/UiListbox.d.ts +0 -87
- package/vue/UiListbox.js +0 -2
- package/vue/UiListbox.vue +0 -554
- package/vue/UiMenu.d.ts +0 -99
- package/vue/UiMenu.js +0 -2
- package/vue/UiMenu.vue +0 -541
- package/vue/UiMenuGroup.d.ts +0 -29
- package/vue/UiMenuGroup.js +0 -2
- package/vue/UiMenuGroup.vue +0 -105
- package/vue/UiMenuItem.d.ts +0 -89
- package/vue/UiMenuItem.js +0 -2
- package/vue/UiMenuItem.vue +0 -532
- package/vue/UiMeter.d.ts +0 -73
- package/vue/UiMeter.js +0 -2
- package/vue/UiMeter.vue +0 -1112
- package/vue/UiNavItem.d.ts +0 -79
- package/vue/UiNavItem.js +0 -2
- package/vue/UiNavItem.vue +0 -493
- package/vue/UiNumberInput.d.ts +0 -89
- package/vue/UiNumberInput.js +0 -2
- package/vue/UiNumberInput.vue +0 -445
- package/vue/UiPageHeader.d.ts +0 -37
- package/vue/UiPageHeader.js +0 -2
- package/vue/UiPageHeader.vue +0 -192
- package/vue/UiPagination.d.ts +0 -115
- package/vue/UiPagination.js +0 -2
- package/vue/UiPagination.vue +0 -596
- package/vue/UiPopover.d.ts +0 -77
- package/vue/UiPopover.js +0 -2
- package/vue/UiPopover.vue +0 -495
- package/vue/UiRadio.d.ts +0 -77
- package/vue/UiRadio.js +0 -2
- package/vue/UiRadio.vue +0 -475
- package/vue/UiRadioGroup.d.ts +0 -95
- package/vue/UiRadioGroup.js +0 -2
- package/vue/UiRadioGroup.vue +0 -393
- package/vue/UiReel.d.ts +0 -41
- package/vue/UiReel.js +0 -2
- package/vue/UiReel.vue +0 -223
- package/vue/UiScrollArea.d.ts +0 -53
- package/vue/UiScrollArea.js +0 -2
- package/vue/UiScrollArea.vue +0 -307
- package/vue/UiSearchResultRow.d.ts +0 -49
- package/vue/UiSearchResultRow.js +0 -2
- package/vue/UiSearchResultRow.vue +0 -268
- package/vue/UiSearchShell.d.ts +0 -67
- package/vue/UiSearchShell.js +0 -2
- package/vue/UiSearchShell.vue +0 -391
- package/vue/UiSection.d.ts +0 -51
- package/vue/UiSection.js +0 -2
- package/vue/UiSection.vue +0 -331
- package/vue/UiSelect.d.ts +0 -69
- package/vue/UiSelect.js +0 -2
- package/vue/UiSelect.vue +0 -391
- package/vue/UiSeparator.d.ts +0 -37
- package/vue/UiSeparator.js +0 -2
- package/vue/UiSeparator.vue +0 -199
- package/vue/UiSidebar.d.ts +0 -99
- package/vue/UiSidebar.js +0 -2
- package/vue/UiSidebar.vue +0 -579
- package/vue/UiSiteHeader.d.ts +0 -59
- package/vue/UiSiteHeader.js +0 -2
- package/vue/UiSiteHeader.vue +0 -904
- package/vue/UiSkeleton.d.ts +0 -37
- package/vue/UiSkeleton.js +0 -2
- package/vue/UiSkeleton.vue +0 -287
- package/vue/UiSlider.d.ts +0 -89
- package/vue/UiSlider.js +0 -2
- package/vue/UiSlider.vue +0 -448
- package/vue/UiSpinner.d.ts +0 -25
- package/vue/UiSpinner.js +0 -2
- package/vue/UiSpinner.vue +0 -330
- package/vue/UiStack.d.ts +0 -53
- package/vue/UiStack.js +0 -2
- package/vue/UiStack.vue +0 -247
- package/vue/UiStatusMessage.d.ts +0 -43
- package/vue/UiStatusMessage.js +0 -2
- package/vue/UiStatusMessage.vue +0 -239
- package/vue/UiSwatch.d.ts +0 -19
- package/vue/UiSwatch.js +0 -2
- package/vue/UiSwatch.vue +0 -188
- package/vue/UiSwitch.d.ts +0 -77
- package/vue/UiSwitch.js +0 -2
- package/vue/UiSwitch.vue +0 -478
- package/vue/UiSwitcher.d.ts +0 -47
- package/vue/UiSwitcher.js +0 -2
- package/vue/UiSwitcher.vue +0 -258
- package/vue/UiTable.d.ts +0 -35
- package/vue/UiTable.js +0 -2
- package/vue/UiTable.vue +0 -280
- package/vue/UiTabs.d.ts +0 -81
- package/vue/UiTabs.js +0 -2
- package/vue/UiTabs.vue +0 -493
- package/vue/UiText.d.ts +0 -111
- package/vue/UiText.js +0 -2
- package/vue/UiText.vue +0 -836
- package/vue/UiTextarea.d.ts +0 -77
- package/vue/UiTextarea.js +0 -2
- package/vue/UiTextarea.vue +0 -477
- package/vue/UiToast.d.ts +0 -49
- package/vue/UiToast.js +0 -2
- package/vue/UiToast.vue +0 -337
- package/vue/UiToastRegion.d.ts +0 -61
- package/vue/UiToastRegion.js +0 -2
- package/vue/UiToastRegion.vue +0 -631
- package/vue/UiTooltip.d.ts +0 -93
- package/vue/UiTooltip.js +0 -2
- package/vue/UiTooltip.vue +0 -627
- package/vue/UiTopBar.d.ts +0 -35
- package/vue/UiTopBar.js +0 -2
- package/vue/UiTopBar.vue +0 -240
- package/vue/UiTree.d.ts +0 -123
- package/vue/UiTree.js +0 -2
- package/vue/UiTree.vue +0 -419
- package/vue/UiTreeItem.d.ts +0 -133
- package/vue/UiTreeItem.js +0 -2
- package/vue/UiTreeItem.vue +0 -1962
- package/vue/chunks/UiActionBar.js +0 -42
- package/vue/chunks/UiAffordanceScope.js +0 -136
- package/vue/chunks/UiAvatar.js +0 -341
- package/vue/chunks/UiAvatarGroup.js +0 -234
- package/vue/chunks/UiBadge.js +0 -188
- package/vue/chunks/UiBreadcrumbItem.js +0 -104
- package/vue/chunks/UiBreadcrumbs.js +0 -67
- package/vue/chunks/UiButton.js +0 -881
- package/vue/chunks/UiCallout.js +0 -302
- package/vue/chunks/UiCard.js +0 -369
- package/vue/chunks/UiCardGroup.js +0 -153
- package/vue/chunks/UiCheckbox.js +0 -361
- package/vue/chunks/UiCluster.js +0 -236
- package/vue/chunks/UiColorPicker.js +0 -375
- package/vue/chunks/UiCombobox.js +0 -2186
- package/vue/chunks/UiContainer.js +0 -122
- package/vue/chunks/UiContextMenu.js +0 -157
- package/vue/chunks/UiCover.js +0 -66
- package/vue/chunks/UiCurveEditor.js +0 -415
- package/vue/chunks/UiCycleButton.js +0 -352
- package/vue/chunks/UiDescriptionItem.js +0 -64
- package/vue/chunks/UiDescriptionList.js +0 -133
- package/vue/chunks/UiDialog.js +0 -367
- package/vue/chunks/UiDisclosure.js +0 -403
- package/vue/chunks/UiEditable.js +0 -436
- package/vue/chunks/UiEditorBlockActions.js +0 -157
- package/vue/chunks/UiEditorChipEditor.js +0 -191
- package/vue/chunks/UiEditorCodeLanguage.js +0 -181
- package/vue/chunks/UiEditorFootnoteEditor.js +0 -114
- package/vue/chunks/UiEditorImageToolbar.js +0 -531
- package/vue/chunks/UiEditorInsertTableGrid.js +0 -325
- package/vue/chunks/UiEditorLinkCard.js +0 -391
- package/vue/chunks/UiEditorLinkForm.js +0 -711
- package/vue/chunks/UiEditorMentionMenu.js +0 -618
- package/vue/chunks/UiEditorMentionMenuItem.js +0 -140
- package/vue/chunks/UiEditorSlashMenu.js +0 -555
- package/vue/chunks/UiEditorSlashMenuGroup.js +0 -78
- package/vue/chunks/UiEditorSlashMenuItem.js +0 -197
- package/vue/chunks/UiEditorSurface.js +0 -66
- package/vue/chunks/UiEditorTableContextMenu.js +0 -500
- package/vue/chunks/UiEditorTableOverlay.js +0 -987
- package/vue/chunks/UiEditorTableToolbar.js +0 -707
- package/vue/chunks/UiEditorToolbar.js +0 -103
- package/vue/chunks/UiFloatingActionButton.js +0 -123
- package/vue/chunks/UiFormField.js +0 -172
- package/vue/chunks/UiGrid.js +0 -127
- package/vue/chunks/UiIcon.js +0 -1361
- package/vue/chunks/UiIconButton.js +0 -469
- package/vue/chunks/UiImage.js +0 -312
- package/vue/chunks/UiInput.js +0 -709
- package/vue/chunks/UiInputGroup.js +0 -225
- package/vue/chunks/UiLightEditor.js +0 -365
- package/vue/chunks/UiList.js +0 -178
- package/vue/chunks/UiListItem.js +0 -219
- package/vue/chunks/UiListbox.js +0 -489
- package/vue/chunks/UiMenu.js +0 -286
- package/vue/chunks/UiMenuGroup.js +0 -75
- package/vue/chunks/UiMenuItem.js +0 -374
- package/vue/chunks/UiMeter.js +0 -540
- package/vue/chunks/UiNavItem.js +0 -380
- package/vue/chunks/UiNumberInput.js +0 -432
- package/vue/chunks/UiPageHeader.js +0 -100
- package/vue/chunks/UiPagination.js +0 -537
- package/vue/chunks/UiPopover.js +0 -243
- package/vue/chunks/UiRadio.js +0 -291
- package/vue/chunks/UiRadioGroup.js +0 -300
- package/vue/chunks/UiReel.js +0 -133
- package/vue/chunks/UiScrollArea.js +0 -219
- package/vue/chunks/UiSearchResultRow.js +0 -164
- package/vue/chunks/UiSearchShell.js +0 -215
- package/vue/chunks/UiSection.js +0 -228
- package/vue/chunks/UiSelect.js +0 -251
- package/vue/chunks/UiSeparator.js +0 -144
- package/vue/chunks/UiSidebar.js +0 -358
- package/vue/chunks/UiSiteHeader.js +0 -335
- package/vue/chunks/UiSkeleton.js +0 -183
- package/vue/chunks/UiSlider.js +0 -427
- package/vue/chunks/UiSpinner.js +0 -181
- package/vue/chunks/UiStack.js +0 -177
- package/vue/chunks/UiStatusMessage.js +0 -176
- package/vue/chunks/UiSwatch.js +0 -93
- package/vue/chunks/UiSwitch.js +0 -292
- package/vue/chunks/UiSwitcher.js +0 -194
- package/vue/chunks/UiTable.js +0 -128
- package/vue/chunks/UiTabs.js +0 -334
- package/vue/chunks/UiText.js +0 -747
- package/vue/chunks/UiTextarea.js +0 -313
- package/vue/chunks/UiToast.js +0 -174
- package/vue/chunks/UiToastRegion.js +0 -275
- package/vue/chunks/UiTooltip.js +0 -297
- package/vue/chunks/UiTopBar.js +0 -129
- package/vue/chunks/UiTree.js +0 -282
- package/vue/chunks/UiTreeItem.js +0 -699
- package/vue/chunks/_plugin-vue_export-helper.js +0 -1265
- package/vue/chunks/control.js +0 -214
- package/vue/chunks/props.js +0 -1228
- package/vue/components.css +0 -17539
- package/vue/editor/LoomaEditor.d.ts +0 -433
- package/vue/editor/compact/index.d.ts +0 -84
- package/vue/editor/compact/index.js +0 -2
- package/vue/editor/index.d.ts +0 -5
- package/vue/editor/index.js +0 -17281
- package/vue/editor/primitives.d.ts +0 -120
- package/vue/host.ts +0 -2272
- package/vue/index.d.ts +0 -94
- package/vue/index.js +0 -95
- package/vue/props.d.ts +0 -272
- /package/{vue → editor}/chunks/1c.js +0 -0
- /package/{vue → editor}/chunks/abnf.js +0 -0
- /package/{vue → editor}/chunks/accesslog.js +0 -0
- /package/{vue → editor}/chunks/actionscript.js +0 -0
- /package/{vue → editor}/chunks/ada.js +0 -0
- /package/{vue → editor}/chunks/angelscript.js +0 -0
- /package/{vue → editor}/chunks/apache.js +0 -0
- /package/{vue → editor}/chunks/applescript.js +0 -0
- /package/{vue → editor}/chunks/arcade.js +0 -0
- /package/{vue → editor}/chunks/arduino.js +0 -0
- /package/{vue → editor}/chunks/armasm.js +0 -0
- /package/{vue → editor}/chunks/asciidoc.js +0 -0
- /package/{vue → editor}/chunks/aspectj.js +0 -0
- /package/{vue → editor}/chunks/autohotkey.js +0 -0
- /package/{vue → editor}/chunks/autoit.js +0 -0
- /package/{vue → editor}/chunks/avrasm.js +0 -0
- /package/{vue → editor}/chunks/awk.js +0 -0
- /package/{vue → editor}/chunks/axapta.js +0 -0
- /package/{vue → editor}/chunks/bash.js +0 -0
- /package/{vue → editor}/chunks/basic.js +0 -0
- /package/{vue → editor}/chunks/bnf.js +0 -0
- /package/{vue → editor}/chunks/brainfuck.js +0 -0
- /package/{vue → editor}/chunks/c.js +0 -0
- /package/{vue → editor}/chunks/cal.js +0 -0
- /package/{vue → editor}/chunks/capnproto.js +0 -0
- /package/{vue → editor}/chunks/ceylon.js +0 -0
- /package/{vue → editor}/chunks/clean.js +0 -0
- /package/{vue → editor}/chunks/clojure-repl.js +0 -0
- /package/{vue → editor}/chunks/clojure.js +0 -0
- /package/{vue → editor}/chunks/cmake.js +0 -0
- /package/{vue → editor}/chunks/coffeescript.js +0 -0
- /package/{vue → editor}/chunks/coq.js +0 -0
- /package/{vue → editor}/chunks/cos.js +0 -0
- /package/{vue → editor}/chunks/cpp.js +0 -0
- /package/{vue → editor}/chunks/crmsh.js +0 -0
- /package/{vue → editor}/chunks/crystal.js +0 -0
- /package/{vue → editor}/chunks/csharp.js +0 -0
- /package/{vue → editor}/chunks/csp.js +0 -0
- /package/{vue → editor}/chunks/css.js +0 -0
- /package/{vue → editor}/chunks/d.js +0 -0
- /package/{vue → editor}/chunks/dart.js +0 -0
- /package/{vue → editor}/chunks/delphi.js +0 -0
- /package/{vue → editor}/chunks/diff.js +0 -0
- /package/{vue → editor}/chunks/django.js +0 -0
- /package/{vue → editor}/chunks/dns.js +0 -0
- /package/{vue → editor}/chunks/dockerfile.js +0 -0
- /package/{vue → editor}/chunks/dos.js +0 -0
- /package/{vue → editor}/chunks/dsconfig.js +0 -0
- /package/{vue → editor}/chunks/dts.js +0 -0
- /package/{vue → editor}/chunks/dust.js +0 -0
- /package/{vue → editor}/chunks/ebnf.js +0 -0
- /package/{vue → editor}/chunks/elixir.js +0 -0
- /package/{vue → editor}/chunks/elm.js +0 -0
- /package/{vue → editor}/chunks/erb.js +0 -0
- /package/{vue → editor}/chunks/erlang-repl.js +0 -0
- /package/{vue → editor}/chunks/erlang.js +0 -0
- /package/{vue → editor}/chunks/excel.js +0 -0
- /package/{vue → editor}/chunks/fix.js +0 -0
- /package/{vue → editor}/chunks/flix.js +0 -0
- /package/{vue → editor}/chunks/fortran.js +0 -0
- /package/{vue → editor}/chunks/fsharp.js +0 -0
- /package/{vue → editor}/chunks/gams.js +0 -0
- /package/{vue → editor}/chunks/gauss.js +0 -0
- /package/{vue → editor}/chunks/gcode.js +0 -0
- /package/{vue → editor}/chunks/gherkin.js +0 -0
- /package/{vue → editor}/chunks/glsl.js +0 -0
- /package/{vue → editor}/chunks/gml.js +0 -0
- /package/{vue → editor}/chunks/go.js +0 -0
- /package/{vue → editor}/chunks/golo.js +0 -0
- /package/{vue → editor}/chunks/gradle.js +0 -0
- /package/{vue → editor}/chunks/graphql.js +0 -0
- /package/{vue → editor}/chunks/groovy.js +0 -0
- /package/{vue → editor}/chunks/haml.js +0 -0
- /package/{vue → editor}/chunks/handlebars.js +0 -0
- /package/{vue → editor}/chunks/haskell.js +0 -0
- /package/{vue → editor}/chunks/haxe.js +0 -0
- /package/{vue → editor}/chunks/hsp.js +0 -0
- /package/{vue → editor}/chunks/http.js +0 -0
- /package/{vue → editor}/chunks/hy.js +0 -0
- /package/{vue → editor}/chunks/inform7.js +0 -0
- /package/{vue → editor}/chunks/ini.js +0 -0
- /package/{vue → editor}/chunks/irpf90.js +0 -0
- /package/{vue → editor}/chunks/isbl.js +0 -0
- /package/{vue → editor}/chunks/java.js +0 -0
- /package/{vue → editor}/chunks/javascript.js +0 -0
- /package/{vue → editor}/chunks/jboss-cli.js +0 -0
- /package/{vue → editor}/chunks/json.js +0 -0
- /package/{vue → editor}/chunks/julia-repl.js +0 -0
- /package/{vue → editor}/chunks/julia.js +0 -0
- /package/{vue → editor}/chunks/kotlin.js +0 -0
- /package/{vue → editor}/chunks/lasso.js +0 -0
- /package/{vue → editor}/chunks/latex.js +0 -0
- /package/{vue → editor}/chunks/ldif.js +0 -0
- /package/{vue → editor}/chunks/leaf.js +0 -0
- /package/{vue → editor}/chunks/less.js +0 -0
- /package/{vue → editor}/chunks/lisp.js +0 -0
- /package/{vue → editor}/chunks/livecodeserver.js +0 -0
- /package/{vue → editor}/chunks/livescript.js +0 -0
- /package/{vue → editor}/chunks/llvm.js +0 -0
- /package/{vue → editor}/chunks/lsl.js +0 -0
- /package/{vue → editor}/chunks/lua.js +0 -0
- /package/{vue → editor}/chunks/makefile.js +0 -0
- /package/{vue → editor}/chunks/markdown.js +0 -0
- /package/{vue → editor}/chunks/mathematica.js +0 -0
- /package/{vue → editor}/chunks/matlab.js +0 -0
- /package/{vue → editor}/chunks/maxima.js +0 -0
- /package/{vue → editor}/chunks/mel.js +0 -0
- /package/{vue → editor}/chunks/mercury.js +0 -0
- /package/{vue → editor}/chunks/mipsasm.js +0 -0
- /package/{vue → editor}/chunks/mizar.js +0 -0
- /package/{vue → editor}/chunks/mojolicious.js +0 -0
- /package/{vue → editor}/chunks/monkey.js +0 -0
- /package/{vue → editor}/chunks/moonscript.js +0 -0
- /package/{vue → editor}/chunks/n1ql.js +0 -0
- /package/{vue → editor}/chunks/nestedtext.js +0 -0
- /package/{vue → editor}/chunks/nginx.js +0 -0
- /package/{vue → editor}/chunks/nim.js +0 -0
- /package/{vue → editor}/chunks/nix.js +0 -0
- /package/{vue → editor}/chunks/node-repl.js +0 -0
- /package/{vue → editor}/chunks/nsis.js +0 -0
- /package/{vue → editor}/chunks/objectivec.js +0 -0
- /package/{vue → editor}/chunks/ocaml.js +0 -0
- /package/{vue → editor}/chunks/openscad.js +0 -0
- /package/{vue → editor}/chunks/oxygene.js +0 -0
- /package/{vue → editor}/chunks/parser3.js +0 -0
- /package/{vue → editor}/chunks/perl.js +0 -0
- /package/{vue → editor}/chunks/pf.js +0 -0
- /package/{vue → editor}/chunks/pgsql.js +0 -0
- /package/{vue → editor}/chunks/php-template.js +0 -0
- /package/{vue → editor}/chunks/php.js +0 -0
- /package/{vue → editor}/chunks/plaintext.js +0 -0
- /package/{vue → editor}/chunks/pony.js +0 -0
- /package/{vue → editor}/chunks/powershell.js +0 -0
- /package/{vue → editor}/chunks/processing.js +0 -0
- /package/{vue → editor}/chunks/profile.js +0 -0
- /package/{vue → editor}/chunks/prolog.js +0 -0
- /package/{vue → editor}/chunks/properties.js +0 -0
- /package/{vue → editor}/chunks/protobuf.js +0 -0
- /package/{vue → editor}/chunks/puppet.js +0 -0
- /package/{vue → editor}/chunks/purebasic.js +0 -0
- /package/{vue → editor}/chunks/python-repl.js +0 -0
- /package/{vue → editor}/chunks/python.js +0 -0
- /package/{vue → editor}/chunks/q.js +0 -0
- /package/{vue → editor}/chunks/qml.js +0 -0
- /package/{vue → editor}/chunks/r.js +0 -0
- /package/{vue → editor}/chunks/reasonml.js +0 -0
- /package/{vue → editor}/chunks/rib.js +0 -0
- /package/{vue → editor}/chunks/roboconf.js +0 -0
- /package/{vue → editor}/chunks/routeros.js +0 -0
- /package/{vue → editor}/chunks/rsl.js +0 -0
- /package/{vue → editor}/chunks/ruby.js +0 -0
- /package/{vue → editor}/chunks/ruleslanguage.js +0 -0
- /package/{vue → editor}/chunks/rust.js +0 -0
- /package/{vue → editor}/chunks/sas.js +0 -0
- /package/{vue → editor}/chunks/scala.js +0 -0
- /package/{vue → editor}/chunks/scheme.js +0 -0
- /package/{vue → editor}/chunks/scilab.js +0 -0
- /package/{vue → editor}/chunks/scss.js +0 -0
- /package/{vue → editor}/chunks/shell.js +0 -0
- /package/{vue → editor}/chunks/smali.js +0 -0
- /package/{vue → editor}/chunks/smalltalk.js +0 -0
- /package/{vue → editor}/chunks/sml.js +0 -0
- /package/{vue → editor}/chunks/sqf.js +0 -0
- /package/{vue → editor}/chunks/sql.js +0 -0
- /package/{vue → editor}/chunks/stan.js +0 -0
- /package/{vue → editor}/chunks/stata.js +0 -0
- /package/{vue → editor}/chunks/step21.js +0 -0
- /package/{vue → editor}/chunks/stylus.js +0 -0
- /package/{vue → editor}/chunks/subunit.js +0 -0
- /package/{vue → editor}/chunks/swift.js +0 -0
- /package/{vue → editor}/chunks/taggerscript.js +0 -0
- /package/{vue → editor}/chunks/tap.js +0 -0
- /package/{vue → editor}/chunks/tcl.js +0 -0
- /package/{vue → editor}/chunks/thrift.js +0 -0
- /package/{vue → editor}/chunks/tp.js +0 -0
- /package/{vue → editor}/chunks/twig.js +0 -0
- /package/{vue → editor}/chunks/typescript.js +0 -0
- /package/{vue → editor}/chunks/vala.js +0 -0
- /package/{vue → editor}/chunks/vbnet.js +0 -0
- /package/{vue → editor}/chunks/vbscript-html.js +0 -0
- /package/{vue → editor}/chunks/vbscript.js +0 -0
- /package/{vue → editor}/chunks/verilog.js +0 -0
- /package/{vue → editor}/chunks/vhdl.js +0 -0
- /package/{vue → editor}/chunks/vim.js +0 -0
- /package/{vue → editor}/chunks/wasm.js +0 -0
- /package/{vue → editor}/chunks/wren.js +0 -0
- /package/{vue → editor}/chunks/x86asm.js +0 -0
- /package/{vue → editor}/chunks/xl.js +0 -0
- /package/{vue → editor}/chunks/xml.js +0 -0
- /package/{vue → editor}/chunks/xquery.js +0 -0
- /package/{vue → editor}/chunks/yaml.js +0 -0
- /package/{vue → editor}/chunks/zephir.js +0 -0
- /package/{vue/editor/compact/extensions.d.ts → editor/compact-extensions.d.ts} +0 -0
package/vue/host.ts
DELETED
|
@@ -1,2272 +0,0 @@
|
|
|
1
|
-
// Generated by HTML Next 1.0.0-alpha.69 for Vue 3.5. Do not edit.
|
|
2
|
-
import {
|
|
3
|
-
computed,
|
|
4
|
-
createTextVNode,
|
|
5
|
-
customRef,
|
|
6
|
-
defineComponent,
|
|
7
|
-
Fragment,
|
|
8
|
-
getCurrentInstance,
|
|
9
|
-
h,
|
|
10
|
-
inject,
|
|
11
|
-
onBeforeUnmount,
|
|
12
|
-
onBeforeUpdate,
|
|
13
|
-
onMounted,
|
|
14
|
-
onUpdated,
|
|
15
|
-
ref,
|
|
16
|
-
shallowRef,
|
|
17
|
-
useSlots,
|
|
18
|
-
watch,
|
|
19
|
-
watchEffect,
|
|
20
|
-
} from 'vue'
|
|
21
|
-
import type { PropType, Ref, VNode } from 'vue'
|
|
22
|
-
/** The public failure a template may read; stacks and producer capabilities stay with their owner. */
|
|
23
|
-
interface InputFailure {
|
|
24
|
-
readonly name: string
|
|
25
|
-
readonly message: string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Availability is independent of the declared value's type, truthiness and input ownership. */
|
|
29
|
-
interface InputStatus {
|
|
30
|
-
readonly ready: boolean
|
|
31
|
-
readonly pending: boolean
|
|
32
|
-
readonly error: InputFailure | null
|
|
33
|
-
readonly stale: boolean
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const READY_INPUT: InputStatus = { ready: true, pending: false, error: null, stale: false }
|
|
37
|
-
|
|
38
|
-
/** Browser activation shared by live, native-compiled and framework component hosts. */
|
|
39
|
-
export interface ConnectionContext {
|
|
40
|
-
readonly signal: AbortSignal
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type Connect<H> = (
|
|
44
|
-
host: H,
|
|
45
|
-
context: ConnectionContext,
|
|
46
|
-
) => void | (() => void) | Promise<void | (() => void)>
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Each call owns a fresh native cancellation signal. The facade also owns subscriptions created
|
|
50
|
-
* through host.on/effect after an await: retaining a stale host cannot start a new subscription.
|
|
51
|
-
* It shares the instance's state, props, refs and other capabilities rather than copying them.
|
|
52
|
-
*/
|
|
53
|
-
export function activateModule<H extends object>(
|
|
54
|
-
module: { readonly connect?: Connect<H> | undefined },
|
|
55
|
-
host: H,
|
|
56
|
-
report: (error: unknown) => void = error => {
|
|
57
|
-
queueMicrotask(() => {
|
|
58
|
-
throw error
|
|
59
|
-
})
|
|
60
|
-
},
|
|
61
|
-
): () => void {
|
|
62
|
-
const controller = new AbortController()
|
|
63
|
-
const owned = new Set<() => void>()
|
|
64
|
-
let cleanup: (() => void) | undefined
|
|
65
|
-
const dispose = (stop: () => void): void => {
|
|
66
|
-
try {
|
|
67
|
-
stop()
|
|
68
|
-
} catch (error) {
|
|
69
|
-
report(error)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const scoped = Object.create(host) as H
|
|
73
|
-
const stop = (): void => {
|
|
74
|
-
if (controller.signal.aborted) return
|
|
75
|
-
controller.abort()
|
|
76
|
-
for (const release of owned) release()
|
|
77
|
-
const release = cleanup
|
|
78
|
-
cleanup = undefined
|
|
79
|
-
if (release !== undefined) dispose(release)
|
|
80
|
-
}
|
|
81
|
-
const failed = (error: unknown): void => {
|
|
82
|
-
const cancelled = controller.signal.aborted
|
|
83
|
-
&& (error as { name?: string } | null)?.name === 'AbortError'
|
|
84
|
-
stop()
|
|
85
|
-
if (!cancelled) report(error)
|
|
86
|
-
}
|
|
87
|
-
const own = (stop: () => void): () => void => {
|
|
88
|
-
let stopped = false
|
|
89
|
-
const release = (): void => {
|
|
90
|
-
if (stopped) return
|
|
91
|
-
stopped = true
|
|
92
|
-
owned.delete(release)
|
|
93
|
-
dispose(stop)
|
|
94
|
-
}
|
|
95
|
-
if (controller.signal.aborted) release()
|
|
96
|
-
else owned.add(release)
|
|
97
|
-
return release
|
|
98
|
-
}
|
|
99
|
-
for (const name of ['on', 'effect', 'computed'] as const) {
|
|
100
|
-
const method: unknown = Reflect.get(host, name)
|
|
101
|
-
if (typeof method !== 'function') continue
|
|
102
|
-
Object.defineProperty(scoped, name, {
|
|
103
|
-
value: (...args: unknown[]) => {
|
|
104
|
-
if (controller.signal.aborted) {
|
|
105
|
-
if (name === 'computed') {
|
|
106
|
-
return {
|
|
107
|
-
get: () => {
|
|
108
|
-
throw controller.signal.reason
|
|
109
|
-
},
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return () => {}
|
|
113
|
-
}
|
|
114
|
-
const result: unknown = Reflect.apply(method, host, args)
|
|
115
|
-
const stop = name === 'computed'
|
|
116
|
-
? (result as { stop?: () => void }).stop?.bind(result)
|
|
117
|
-
: result as () => void
|
|
118
|
-
if (stop === undefined) return result
|
|
119
|
-
const release = own(stop)
|
|
120
|
-
return name === 'computed' ? result : release
|
|
121
|
-
},
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
// A connection owns its input subscriptions and source capabilities. Disposal releases
|
|
125
|
-
// eligibility for a later activation without disposing the instance's input port or values.
|
|
126
|
-
const inputKey = Symbol.for('@nextwebwg/html-next.inputs.v1')
|
|
127
|
-
const inputs: unknown = Reflect.get(host, inputKey)
|
|
128
|
-
if (inputs !== undefined) {
|
|
129
|
-
const port = Object.create(inputs as object) as {
|
|
130
|
-
watch(run: () => void | (() => void)): () => void
|
|
131
|
-
}
|
|
132
|
-
Object.defineProperty(port, 'watch', {
|
|
133
|
-
value: (run: () => void | (() => void)) =>
|
|
134
|
-
controller.signal.aborted ? () => {} : own((inputs as typeof port).watch(run)),
|
|
135
|
-
})
|
|
136
|
-
const source: unknown = Reflect.get(inputs as object, 'source')
|
|
137
|
-
if (typeof source === 'function') {
|
|
138
|
-
Object.defineProperty(port, 'source', {
|
|
139
|
-
value: (...args: unknown[]) => {
|
|
140
|
-
if (controller.signal.aborted) throw controller.signal.reason
|
|
141
|
-
const result = Reflect.apply(source, inputs, args) as { dispose(): void }
|
|
142
|
-
const capability = Object.create(result) as typeof result
|
|
143
|
-
Object.defineProperty(capability, 'dispose', { value: own(() => result.dispose()) })
|
|
144
|
-
return capability
|
|
145
|
-
},
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
Object.defineProperty(scoped, inputKey, { value: port })
|
|
149
|
-
}
|
|
150
|
-
const accept = (result: void | (() => void)): void => {
|
|
151
|
-
if (result === undefined) return
|
|
152
|
-
if (typeof result !== 'function') {
|
|
153
|
-
failed(new TypeError('A component connect export must return cleanup or undefined.'))
|
|
154
|
-
return
|
|
155
|
-
}
|
|
156
|
-
if (controller.signal.aborted) dispose(result)
|
|
157
|
-
else cleanup = result
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
const result = module.connect?.(scoped, { signal: controller.signal })
|
|
161
|
-
if (result !== undefined && typeof result !== 'function') {
|
|
162
|
-
void Promise.resolve(result).then(accept, failed)
|
|
163
|
-
} else accept(result)
|
|
164
|
-
} catch (error) {
|
|
165
|
-
failed(error)
|
|
166
|
-
}
|
|
167
|
-
return stop
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** A fresh copy of a state's declared value at `keys`, or null where it has none. */
|
|
171
|
-
function initialAt(initial: unknown, keys: readonly PropertyKey[]): unknown {
|
|
172
|
-
let value = initial
|
|
173
|
-
for (const key of keys) {
|
|
174
|
-
if (value === null || typeof value !== 'object' || !Object.hasOwn(value, key)) return null
|
|
175
|
-
value = (value as Record<PropertyKey, unknown>)[key]
|
|
176
|
-
}
|
|
177
|
-
return value === undefined
|
|
178
|
-
? null
|
|
179
|
-
: value !== null && typeof value === 'object'
|
|
180
|
-
? structuredClone(value)
|
|
181
|
-
: value
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
interface ControllerStateAccess {
|
|
185
|
-
readonly get: () => unknown
|
|
186
|
-
readonly set: (value: unknown) => void
|
|
187
|
-
}
|
|
188
|
-
interface ControllerNamespaces {
|
|
189
|
-
readonly state: Readonly<Record<string, ControllerStateAccess>>
|
|
190
|
-
readonly computed: Readonly<Record<string, () => unknown>>
|
|
191
|
-
readonly data?: Readonly<Record<string, () => unknown>>
|
|
192
|
-
readonly acceptsState?: (name: string, keys: readonly string[], value: unknown) => boolean
|
|
193
|
-
/** Each state's declared `value`, which a null write and `host.reset` restore; a state without one has none. */
|
|
194
|
-
readonly initials?: Readonly<Record<string, unknown>>
|
|
195
|
-
/** A read below a state root, by its path from the root. */
|
|
196
|
-
readonly read?: (name: string, keys: readonly string[]) => void
|
|
197
|
-
/** A write below a state root changed the value at this path from the root. */
|
|
198
|
-
readonly changed?: (name: string, keys: readonly string[]) => void
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function controllerNamespaces(options: ControllerNamespaces, source: string): {
|
|
202
|
-
state: Record<string, unknown>
|
|
203
|
-
data: Readonly<Record<string, unknown>>
|
|
204
|
-
reset: (name?: string) => void
|
|
205
|
-
} {
|
|
206
|
-
const reported = new Set<string>()
|
|
207
|
-
const nested = new WeakMap<object, Map<string, object>>()
|
|
208
|
-
const eventType = typeof Event === 'undefined'
|
|
209
|
-
? undefined
|
|
210
|
-
: Object.getOwnPropertyDescriptor(Event.prototype, 'type')!.get!
|
|
211
|
-
const eventBrands = new WeakMap<object, boolean>()
|
|
212
|
-
const nativeEvent = (value: object): boolean => {
|
|
213
|
-
if (!('type' in value) || eventType === undefined) return false
|
|
214
|
-
const known = eventBrands.get(value)
|
|
215
|
-
if (known !== undefined) return known
|
|
216
|
-
let accepted = false
|
|
217
|
-
try {
|
|
218
|
-
eventType.call(value)
|
|
219
|
-
accepted = true
|
|
220
|
-
} catch {}
|
|
221
|
-
eventBrands.set(value, accepted)
|
|
222
|
-
return accepted
|
|
223
|
-
}
|
|
224
|
-
const warn = (path: string, readonly: boolean): void => {
|
|
225
|
-
if (reported.has(path)) return
|
|
226
|
-
reported.add(path)
|
|
227
|
-
console.warn(
|
|
228
|
-
source + ': HR007: Destination ' + path
|
|
229
|
-
+ (readonly ? ' is read-only.' : ' does not satisfy its declared type.'),
|
|
230
|
-
)
|
|
231
|
-
}
|
|
232
|
-
const write = (
|
|
233
|
-
name: string,
|
|
234
|
-
keys: readonly string[],
|
|
235
|
-
value: unknown,
|
|
236
|
-
readonly: boolean,
|
|
237
|
-
apply: () => void,
|
|
238
|
-
): boolean => {
|
|
239
|
-
if (readonly || options.acceptsState?.(name, keys, value) === false) {
|
|
240
|
-
warn([name, ...keys].join('.'), readonly)
|
|
241
|
-
} else apply()
|
|
242
|
-
return true
|
|
243
|
-
}
|
|
244
|
-
// Each proxy's own object: a value read through host.state and written back is the same value.
|
|
245
|
-
const plain = new WeakMap<object, unknown>()
|
|
246
|
-
const unwrap = (value: unknown): unknown =>
|
|
247
|
-
typeof value === 'object' && value !== null && plain.has(value) ? plain.get(value) : value
|
|
248
|
-
const wrap = (
|
|
249
|
-
value: unknown,
|
|
250
|
-
name: string,
|
|
251
|
-
keys: readonly string[],
|
|
252
|
-
readonly: boolean,
|
|
253
|
-
): unknown => {
|
|
254
|
-
if (value === null || typeof value !== 'object' || nativeEvent(value)) return value
|
|
255
|
-
const path = [name, ...keys].join('.')
|
|
256
|
-
let paths = nested.get(value)
|
|
257
|
-
if (paths === undefined) nested.set(value, paths = new Map())
|
|
258
|
-
const known = paths.get(path)
|
|
259
|
-
if (known !== undefined) return known
|
|
260
|
-
// A readonly facade avoids Proxy invariants on frozen source properties.
|
|
261
|
-
const surface = readonly
|
|
262
|
-
? (Array.isArray(value) ? [] : Object.create(Object.getPrototypeOf(value)))
|
|
263
|
-
: value
|
|
264
|
-
if (readonly && Array.isArray(value)) surface.length = value.length
|
|
265
|
-
const proxy = new Proxy(surface, {
|
|
266
|
-
get: (_target, key) => {
|
|
267
|
-
if (!readonly) options.read?.(name, [...keys, String(key)])
|
|
268
|
-
return wrap(Reflect.get(value, key), name, [...keys, String(key)], readonly)
|
|
269
|
-
},
|
|
270
|
-
set: (_target, key, written) => {
|
|
271
|
-
// A null or undefined field goes back to its value in the state's declared value.
|
|
272
|
-
const next = unwrap(written)
|
|
273
|
-
?? initialAt(options.initials?.[name] ?? null, [...keys, String(key)])
|
|
274
|
-
return write(name, [...keys, String(key)], next, readonly, () => {
|
|
275
|
-
const previous = Reflect.get(value, key)
|
|
276
|
-
const length = Array.isArray(value) ? value.length : undefined
|
|
277
|
-
if (Reflect.set(value, key, next) && !Object.is(previous, next)) {
|
|
278
|
-
options.changed?.(name, [...keys, String(key)])
|
|
279
|
-
}
|
|
280
|
-
// Setting an index past the end extends the list before any write of its length.
|
|
281
|
-
if (length !== undefined && length !== (value as unknown[]).length && key !== 'length') {
|
|
282
|
-
options.changed?.(name, [...keys, 'length'])
|
|
283
|
-
}
|
|
284
|
-
})
|
|
285
|
-
},
|
|
286
|
-
has: (_target, key) => Reflect.has(value, key),
|
|
287
|
-
ownKeys: () => Reflect.ownKeys(value),
|
|
288
|
-
getOwnPropertyDescriptor: (_target, key) => {
|
|
289
|
-
if (readonly && Array.isArray(value) && key === 'length') {
|
|
290
|
-
surface.length = value.length
|
|
291
|
-
return Reflect.getOwnPropertyDescriptor(surface, key)
|
|
292
|
-
}
|
|
293
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(value, key)
|
|
294
|
-
return descriptor === undefined
|
|
295
|
-
? undefined
|
|
296
|
-
: readonly
|
|
297
|
-
? { ...descriptor, configurable: true }
|
|
298
|
-
: descriptor
|
|
299
|
-
},
|
|
300
|
-
deleteProperty: (_target, key) =>
|
|
301
|
-
write(name, [...keys, String(key)], undefined, readonly, () => {
|
|
302
|
-
if (Reflect.has(value, key) && Reflect.deleteProperty(value, key)) {
|
|
303
|
-
options.changed?.(name, [...keys, String(key)])
|
|
304
|
-
}
|
|
305
|
-
}),
|
|
306
|
-
defineProperty: (_target, key, descriptor) => {
|
|
307
|
-
if (
|
|
308
|
-
readonly || !('value' in descriptor)
|
|
309
|
-
|| options.acceptsState?.(name, [...keys, String(key)], descriptor.value) === false
|
|
310
|
-
) {
|
|
311
|
-
warn([name, ...keys, String(key)].join('.'), readonly)
|
|
312
|
-
return false
|
|
313
|
-
}
|
|
314
|
-
const changed = Reflect.defineProperty(value, key, descriptor)
|
|
315
|
-
if (changed) options.changed?.(name, [...keys, String(key)])
|
|
316
|
-
return changed
|
|
317
|
-
},
|
|
318
|
-
})
|
|
319
|
-
paths.set(path, proxy)
|
|
320
|
-
plain.set(proxy, value)
|
|
321
|
-
return proxy
|
|
322
|
-
}
|
|
323
|
-
const state = new Proxy({} as Record<string, unknown>, {
|
|
324
|
-
get: (_target, name) => {
|
|
325
|
-
if (typeof name !== 'string') return undefined
|
|
326
|
-
if (Object.hasOwn(options.state, name)) {
|
|
327
|
-
return wrap(options.state[name]!.get(), name, [], false)
|
|
328
|
-
}
|
|
329
|
-
if (Object.hasOwn(options.computed, name)) {
|
|
330
|
-
return wrap(options.computed[name]!(), name, [], true)
|
|
331
|
-
}
|
|
332
|
-
return undefined
|
|
333
|
-
},
|
|
334
|
-
set: (_target, name, value) =>
|
|
335
|
-
write(
|
|
336
|
-
String(name),
|
|
337
|
-
[],
|
|
338
|
-
unwrap(value),
|
|
339
|
-
typeof name !== 'string' || !Object.hasOwn(options.state, name),
|
|
340
|
-
() =>
|
|
341
|
-
options.state[String(name)]!.set(
|
|
342
|
-
unwrap(value) ?? initialAt(options.initials?.[String(name)] ?? null, []),
|
|
343
|
-
),
|
|
344
|
-
),
|
|
345
|
-
deleteProperty: (_target, name) => {
|
|
346
|
-
warn(String(name), true)
|
|
347
|
-
return true
|
|
348
|
-
},
|
|
349
|
-
defineProperty: (_target, name) => {
|
|
350
|
-
warn(String(name), true)
|
|
351
|
-
return false
|
|
352
|
-
},
|
|
353
|
-
has: (_target, name) =>
|
|
354
|
-
typeof name === 'string'
|
|
355
|
-
&& (Object.hasOwn(options.state, name) || Object.hasOwn(options.computed, name)),
|
|
356
|
-
})
|
|
357
|
-
const data = new Proxy({} as Record<string, unknown>, {
|
|
358
|
-
get: (_target, name) =>
|
|
359
|
-
typeof name === 'string' && Object.hasOwn(options.data ?? {}, name)
|
|
360
|
-
? wrap(options.data![name]!(), 'data.' + name, [], true)
|
|
361
|
-
: undefined,
|
|
362
|
-
set: (_target, name, value) => write('data.' + String(name), [], value, true, () => {}),
|
|
363
|
-
deleteProperty: (_target, name) => {
|
|
364
|
-
warn('data.' + String(name), true)
|
|
365
|
-
return true
|
|
366
|
-
},
|
|
367
|
-
defineProperty: (_target, name) => {
|
|
368
|
-
warn('data.' + String(name), true)
|
|
369
|
-
return false
|
|
370
|
-
},
|
|
371
|
-
has: (_target, name) => typeof name === 'string' && Object.hasOwn(options.data ?? {}, name),
|
|
372
|
-
})
|
|
373
|
-
// Returns one state, or every state, to its declared value: a fresh copy, or null without one.
|
|
374
|
-
const reset = (name?: string): void => {
|
|
375
|
-
if (name !== undefined && !Object.hasOwn(options.state, name)) {
|
|
376
|
-
throw new TypeError('`' + String(name) + '` is not a state of ' + source + '.')
|
|
377
|
-
}
|
|
378
|
-
for (const each of name === undefined ? Object.keys(options.state) : [name]) {
|
|
379
|
-
options.state[each]!.set(initialAt(options.initials?.[each] ?? null, []))
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
return { state, data, reset }
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const requestStateKey = Symbol.for('@nextwebwg/html-next.runtime.v1')
|
|
386
|
-
type DocumentRecord = {
|
|
387
|
-
requests?: { readonly g: WeakMap<Node, Promise<void>> }
|
|
388
|
-
relay?: (from: Node, name: string) => void
|
|
389
|
-
k?: WeakMap<EventTarget, string[]>
|
|
390
|
-
w?: Set<(name: string) => void>
|
|
391
|
-
}
|
|
392
|
-
const documentRecord = (root: Element): DocumentRecord =>
|
|
393
|
-
(root.ownerDocument as unknown as Record<symbol, DocumentRecord>)[requestStateKey] ??= {}
|
|
394
|
-
|
|
395
|
-
/** Requests from inside root wait until its controller has run; the returned release ends the wait. */
|
|
396
|
-
function holdController(root: Element): () => void {
|
|
397
|
-
const { g: gates } = documentRecord(root).requests ??= { g: new WeakMap() }
|
|
398
|
-
let release!: () => void
|
|
399
|
-
const gate = new Promise<void>((resolve) => {
|
|
400
|
-
release = resolve
|
|
401
|
-
})
|
|
402
|
-
gates.set(root, gate)
|
|
403
|
-
return () => {
|
|
404
|
-
if (gates.get(root) === gate) gates.delete(root)
|
|
405
|
-
release()
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/** A responder registered on root relays to the requests inside it that went unanswered, once a page asks. */
|
|
410
|
-
function relayResponders(root: Element, name: string): void {
|
|
411
|
-
documentRecord(root).relay?.(root, name)
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/** Records a responder hasResponder can see on root until the returned function runs; own lists its controller's. */
|
|
415
|
-
function knownResponder(root: Element, name: string, own?: string[]): () => void {
|
|
416
|
-
const record = documentRecord(root)
|
|
417
|
-
const known = record.k ??= new WeakMap()
|
|
418
|
-
const names = known.get(root) ?? known.set(root, []).get(root)!
|
|
419
|
-
const change = (add: boolean): void => {
|
|
420
|
-
for (const list of own === undefined ? [names] : [names, own]) {
|
|
421
|
-
if (add) list.push(name)
|
|
422
|
-
else list.splice(list.indexOf(name), 1)
|
|
423
|
-
}
|
|
424
|
-
record.w?.forEach((changed) => changed(name))
|
|
425
|
-
}
|
|
426
|
-
change(true)
|
|
427
|
-
let held = true
|
|
428
|
-
return () => {
|
|
429
|
-
if (held) {
|
|
430
|
-
held = false
|
|
431
|
-
change(false)
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/** For a component that asks: a responder announcement reaches its controller only as the relay to its root, which does not bubble. */
|
|
437
|
-
function hostListener(type: string, callback: (event: Event) => unknown): (event: Event) => void {
|
|
438
|
-
return (event) => {
|
|
439
|
-
if (type !== 'responder' || !event.bubbles) callback(event)
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/** The connection signal requests use: it aborts when the component disconnects. */
|
|
444
|
-
function requestConnection(): {
|
|
445
|
-
readonly signal: (connected: boolean) => AbortSignal
|
|
446
|
-
readonly end: () => void
|
|
447
|
-
} {
|
|
448
|
-
let current: AbortController | undefined
|
|
449
|
-
return {
|
|
450
|
-
signal: (connected) =>
|
|
451
|
-
connected
|
|
452
|
-
? (current ??= new AbortController()).signal
|
|
453
|
-
: AbortSignal.abort(new DOMException('The component is not connected.', 'AbortError')),
|
|
454
|
-
end: () => {
|
|
455
|
-
current?.abort()
|
|
456
|
-
current = undefined
|
|
457
|
-
},
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
export function dispatchToTargets(recorded: unknown, send: (target: Element) => void): void {
|
|
462
|
-
const refs = recorded instanceof Set
|
|
463
|
-
? [...recorded]
|
|
464
|
-
: Array.isArray(recorded)
|
|
465
|
-
? [...recorded]
|
|
466
|
-
: [recorded]
|
|
467
|
-
const targets = refs.map((ref: any) => ref?.nodeType === 1 ? ref : ref?.$el)
|
|
468
|
-
.filter((element): element is Element => element?.nodeType === 1 && element.isConnected)
|
|
469
|
-
.sort((a, b) => a === b ? 0 : a.compareDocumentPosition(b) & 4 ? -1 : 1)
|
|
470
|
-
for (const target of targets) {
|
|
471
|
-
if (target.isConnected) send(target)
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
interface DataReadOptions {
|
|
476
|
-
readonly source: string
|
|
477
|
-
readonly definition: string
|
|
478
|
-
readonly type?: string
|
|
479
|
-
readonly debounce?: number
|
|
480
|
-
readonly poll?: number
|
|
481
|
-
readonly sources: () => readonly unknown[]
|
|
482
|
-
readonly parameters: () => Readonly<Record<string, unknown>>
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
function dataURL(
|
|
486
|
-
source: string,
|
|
487
|
-
baseURL: string,
|
|
488
|
-
parameters: Readonly<Record<string, unknown>>,
|
|
489
|
-
): string {
|
|
490
|
-
const used = new Set<string>()
|
|
491
|
-
const expanded = source.replace(/\{([A-Za-z_$][A-Za-z0-9_$-]*)\}/g, (_match, name: string) => {
|
|
492
|
-
used.add(name)
|
|
493
|
-
const value = parameters[name]
|
|
494
|
-
return value == null ? '' : encodeURIComponent(String(value))
|
|
495
|
-
})
|
|
496
|
-
const url = new URL(expanded, baseURL)
|
|
497
|
-
for (const [name, value] of Object.entries(parameters)) {
|
|
498
|
-
if (used.has(name) || value == null) continue
|
|
499
|
-
if (Array.isArray(value)) {
|
|
500
|
-
for (const item of value) url.searchParams.append(name, String(item))
|
|
501
|
-
} else url.searchParams.set(name, String(value))
|
|
502
|
-
}
|
|
503
|
-
return url.href
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/** What the from-parameters send, as dataURL writes them: an equal key requests nothing new. */
|
|
507
|
-
function dataKey(values: readonly unknown[]): string {
|
|
508
|
-
return JSON.stringify(
|
|
509
|
-
values.map((value) =>
|
|
510
|
-
value == null ? null : Array.isArray(value) ? value.map(String) : String(value)
|
|
511
|
-
),
|
|
512
|
-
)
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
/** A Vue-owned declared read; no request is made during SSR. */
|
|
516
|
-
export function useDataRead(state: { value: any }, options: DataReadOptions): void {
|
|
517
|
-
let value: unknown = null
|
|
518
|
-
const acceptedParameters: Record<string, unknown> = {}
|
|
519
|
-
let abort: AbortController | undefined
|
|
520
|
-
let timer: ReturnType<typeof setTimeout> | undefined
|
|
521
|
-
let generation = 0
|
|
522
|
-
let connected = false
|
|
523
|
-
let stop: (() => void) | undefined
|
|
524
|
-
const cancel = (): void => {
|
|
525
|
-
abort?.abort()
|
|
526
|
-
abort = undefined
|
|
527
|
-
if (timer !== undefined) clearTimeout(timer)
|
|
528
|
-
timer = undefined
|
|
529
|
-
}
|
|
530
|
-
const stale = (current: number): boolean => !connected || current !== generation
|
|
531
|
-
const request = async (current: number): Promise<void> => {
|
|
532
|
-
if (stale(current)) return
|
|
533
|
-
const controller = new AbortController()
|
|
534
|
-
abort = controller
|
|
535
|
-
state.value = { pending: true, value, error: null, ok: false }
|
|
536
|
-
try {
|
|
537
|
-
const definition = (() => {
|
|
538
|
-
try {
|
|
539
|
-
return new URL(options.definition, document.baseURI).href
|
|
540
|
-
} catch {
|
|
541
|
-
return document.baseURI
|
|
542
|
-
}
|
|
543
|
-
})()
|
|
544
|
-
const sampled = options.parameters()
|
|
545
|
-
const parameters = Object.fromEntries(
|
|
546
|
-
Object.entries(sampled).map(([name, input]) => {
|
|
547
|
-
if (input === Symbol.for('html-next.invalid-result')) {
|
|
548
|
-
return [name, acceptedParameters[name] ?? null]
|
|
549
|
-
}
|
|
550
|
-
acceptedParameters[name] = input
|
|
551
|
-
return [name, input]
|
|
552
|
-
}),
|
|
553
|
-
)
|
|
554
|
-
const response = await fetch(dataURL(options.source, definition, parameters), {
|
|
555
|
-
signal: controller.signal,
|
|
556
|
-
})
|
|
557
|
-
if (!response.ok) throw new TypeError(`Request failed with ${response.status}.`)
|
|
558
|
-
const next = options.type === 'text' || options.type === 'string'
|
|
559
|
-
? await response.text()
|
|
560
|
-
: await response.json()
|
|
561
|
-
if (stale(current)) return
|
|
562
|
-
value = next
|
|
563
|
-
state.value = { pending: false, value, error: null, ok: true }
|
|
564
|
-
} catch (error) {
|
|
565
|
-
if (controller.signal.aborted || stale(current)) return
|
|
566
|
-
state.value = { pending: false, value, error, ok: false }
|
|
567
|
-
} finally {
|
|
568
|
-
if (abort === controller) abort = undefined
|
|
569
|
-
if (!stale(current) && (options.poll ?? 0) > 0) {
|
|
570
|
-
timer = setTimeout(() => {
|
|
571
|
-
void request(current)
|
|
572
|
-
}, options.poll)
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
let requested: string | undefined
|
|
577
|
-
const update = (sources: readonly unknown[]): void => {
|
|
578
|
-
if (sources.includes(Symbol.for('html-next.invalid-result'))) return
|
|
579
|
-
// A deep watch fires on any write it reaches; only changed parameters request again.
|
|
580
|
-
const key = dataKey(sources)
|
|
581
|
-
if (connected && key === requested) return
|
|
582
|
-
requested = key
|
|
583
|
-
connected = true
|
|
584
|
-
cancel()
|
|
585
|
-
const current = ++generation
|
|
586
|
-
if ((options.debounce ?? 0) > 0) {
|
|
587
|
-
timer = setTimeout(() => {
|
|
588
|
-
void request(current)
|
|
589
|
-
}, options.debounce)
|
|
590
|
-
} else void request(current)
|
|
591
|
-
}
|
|
592
|
-
onMounted(() => {
|
|
593
|
-
stop = watch(options.sources, update, { immediate: true, deep: true })
|
|
594
|
-
})
|
|
595
|
-
onBeforeUnmount(() => {
|
|
596
|
-
stop?.()
|
|
597
|
-
connected = false
|
|
598
|
-
generation += 1
|
|
599
|
-
cancel()
|
|
600
|
-
})
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/** A reactive value the host reads: Vue's ref, shallowRef, computed, and useTemplateRef all match. */
|
|
604
|
-
export interface Readable<T> {
|
|
605
|
-
readonly value: T
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
/** Vue refs a component invocation as its public instance; the ref is the root element it lowered to. */
|
|
609
|
-
function refElement(ref: any): Element {
|
|
610
|
-
return ref == null || ref.nodeType === 1 ? ref : ref.$el
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
/** The root ref as an element: a delegating component's root ref holds the invoked component. */
|
|
614
|
-
function rootElement<T extends Element>(root: Readable<T | null>): Readable<T | null> {
|
|
615
|
-
return {
|
|
616
|
-
get value() {
|
|
617
|
-
return refElement(root.value) as T | null
|
|
618
|
-
},
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
type DocumentMutationSubscriber = (mutations: readonly MutationRecord[]) => void
|
|
623
|
-
interface DocumentMutationHub {
|
|
624
|
-
readonly observer: MutationObserver
|
|
625
|
-
readonly subscribers: Set<DocumentMutationSubscriber>
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
const runtimeKey = Symbol.for('@nextwebwg/html-next.runtime.v1')
|
|
629
|
-
|
|
630
|
-
function observeConnection(element: Element, check: () => void): () => void {
|
|
631
|
-
const document = element.ownerDocument
|
|
632
|
-
const state =
|
|
633
|
-
((document as unknown as Record<symbol, { mutationHub?: DocumentMutationHub }>)[runtimeKey] ??=
|
|
634
|
-
{})
|
|
635
|
-
let hub = state.mutationHub
|
|
636
|
-
if (hub === undefined) {
|
|
637
|
-
const Observer = document.defaultView?.MutationObserver ?? MutationObserver
|
|
638
|
-
const subscribers = new Set<DocumentMutationSubscriber>()
|
|
639
|
-
const observer = new Observer((mutations) => {
|
|
640
|
-
for (const notify of Array.from(subscribers)) notify(mutations)
|
|
641
|
-
})
|
|
642
|
-
hub = { observer, subscribers }
|
|
643
|
-
state.mutationHub = hub
|
|
644
|
-
observer.observe(document, { childList: true, subtree: true })
|
|
645
|
-
}
|
|
646
|
-
const shared = hub
|
|
647
|
-
const subscriber: DocumentMutationSubscriber = () => check()
|
|
648
|
-
shared.subscribers.add(subscriber)
|
|
649
|
-
return () => {
|
|
650
|
-
shared.subscribers.delete(subscriber)
|
|
651
|
-
if (shared.subscribers.size === 0 && state.mutationHub === shared) {
|
|
652
|
-
shared.observer.disconnect()
|
|
653
|
-
delete state.mutationHub
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* Runs the root's on:connect and on:disconnect handlers each time it joins and leaves a document.
|
|
660
|
-
* Vue hooks cover mount and unmount; the shared native observer sees the root detached and
|
|
661
|
-
* reinserted outside Vue.
|
|
662
|
-
*/
|
|
663
|
-
export function useLifecycle(
|
|
664
|
-
componentRoot: Readable<Element | null>,
|
|
665
|
-
connect?: () => void,
|
|
666
|
-
disconnect?: () => void,
|
|
667
|
-
): void {
|
|
668
|
-
const root = rootElement(componentRoot)
|
|
669
|
-
let connected = false
|
|
670
|
-
let stop: (() => void) | undefined
|
|
671
|
-
const synchronize = (): void => {
|
|
672
|
-
if ((root.value?.isConnected === true) === connected) return
|
|
673
|
-
connected = !connected
|
|
674
|
-
;(connected ? connect : disconnect)?.()
|
|
675
|
-
}
|
|
676
|
-
onMounted(() => {
|
|
677
|
-
if (root.value !== null) stop = observeConnection(root.value, synchronize)
|
|
678
|
-
synchronize()
|
|
679
|
-
})
|
|
680
|
-
onBeforeUnmount(() => {
|
|
681
|
-
stop?.()
|
|
682
|
-
if (connected) {
|
|
683
|
-
connected = false
|
|
684
|
-
disconnect?.()
|
|
685
|
-
}
|
|
686
|
-
})
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
/** Keep native focus on the corresponding control when a root-level $match replaces its element. */
|
|
690
|
-
export function preserveRootFocus(componentRoot: Readable<Element | null>): void {
|
|
691
|
-
const root = rootElement(componentRoot)
|
|
692
|
-
const focusable =
|
|
693
|
-
'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]'
|
|
694
|
-
let previous: Element | null = null
|
|
695
|
-
let active: Element | null = null
|
|
696
|
-
let focusIndex = -1
|
|
697
|
-
onBeforeUpdate(() => {
|
|
698
|
-
previous = root.value
|
|
699
|
-
active = previous?.ownerDocument.activeElement ?? null
|
|
700
|
-
focusIndex =
|
|
701
|
-
previous !== null && active !== null && active !== previous && previous.contains(active)
|
|
702
|
-
? Array.from(previous.querySelectorAll(focusable)).indexOf(active)
|
|
703
|
-
: -1
|
|
704
|
-
})
|
|
705
|
-
onUpdated(() => {
|
|
706
|
-
const next = root.value
|
|
707
|
-
if (previous === null || next === null || previous === next) return
|
|
708
|
-
const target = active === previous
|
|
709
|
-
? next
|
|
710
|
-
: active?.isConnected === true && next.contains(active)
|
|
711
|
-
? active
|
|
712
|
-
: focusIndex >= 0
|
|
713
|
-
? next.querySelectorAll(focusable)[focusIndex]
|
|
714
|
-
: undefined
|
|
715
|
-
;(target as HTMLElement | undefined)?.focus?.({ preventScroll: true })
|
|
716
|
-
})
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
export interface ComponentHostOptions {
|
|
720
|
-
readonly inputs?: {
|
|
721
|
-
port(reactions: {
|
|
722
|
-
readonly declarations?: Readonly<
|
|
723
|
-
Record<string, { readonly read: () => unknown; readonly status: () => InputStatus }>
|
|
724
|
-
>
|
|
725
|
-
track(name: string, kind: 'value' | 'status' | 'supplied'): void
|
|
726
|
-
watch(run: () => void | (() => void)): () => void
|
|
727
|
-
untracked<T>(run: () => T): T
|
|
728
|
-
}): unknown
|
|
729
|
-
}
|
|
730
|
-
readonly availability?: Readonly<Record<string, () => InputStatus>>
|
|
731
|
-
readonly inputTracking?: {
|
|
732
|
-
track(name: string, kind: 'value' | 'status' | 'supplied'): void
|
|
733
|
-
untracked<T>(run: () => T): T
|
|
734
|
-
}
|
|
735
|
-
/** The component's root element. */
|
|
736
|
-
readonly root: Readable<HTMLElement | null>
|
|
737
|
-
/** Dispatches a declared component event. */
|
|
738
|
-
readonly dispatch: (name: string, detail?: unknown) => boolean
|
|
739
|
-
/** The authored controller edge, retained for the live loader's module diagnostic. */
|
|
740
|
-
readonly module?: boolean
|
|
741
|
-
readonly controllerSource?: { readonly specifier: string; readonly definition: string }
|
|
742
|
-
/** Accepted component props, which a controller reads through `host.props`. */
|
|
743
|
-
readonly props?: Readable<Readonly<Record<string, unknown>>>
|
|
744
|
-
/** Raw Vue prop inputs before the declared type is applied. */
|
|
745
|
-
readonly propInputs?: (name: string) => unknown
|
|
746
|
-
readonly propNames?: readonly string[]
|
|
747
|
-
readonly propValidity?: (name: string) => Readonly<Record<string, unknown>>
|
|
748
|
-
/** Template refs, by the ref name the component declared. Vue collects a `v-for` ref into an array. */
|
|
749
|
-
readonly refs?: Readonly<Record<string, Readable<HTMLElement | HTMLElement[] | null>>>
|
|
750
|
-
/** Declared state, which a controller reads and writes. */
|
|
751
|
-
readonly state?: Readonly<Record<string, { value: any }>>
|
|
752
|
-
/** Declared computed values, which a controller reads. */
|
|
753
|
-
readonly computed?: Readonly<Record<string, Readable<unknown>>>
|
|
754
|
-
/** Declared data resources, which a controller reads. */
|
|
755
|
-
readonly data?: Readonly<Record<string, Readable<unknown>>>
|
|
756
|
-
/** Values inherited through declared context, which a controller reads. */
|
|
757
|
-
readonly context?: Readonly<Record<string, Readable<unknown>>>
|
|
758
|
-
/** Each named declared script, which a controller reads as `host.scripts`. */
|
|
759
|
-
readonly scripts?: Readonly<Record<string, unknown>>
|
|
760
|
-
readonly acceptsState?: (name: string, keys: readonly string[], value: unknown) => boolean
|
|
761
|
-
readonly initials?: Readonly<Record<string, unknown>>
|
|
762
|
-
/** Asks one of the component's declared requests; its `has` builds `host.hasResponder`. */
|
|
763
|
-
readonly request?:
|
|
764
|
-
& ((
|
|
765
|
-
root: Element,
|
|
766
|
-
connection: AbortSignal,
|
|
767
|
-
name: string,
|
|
768
|
-
detail?: unknown,
|
|
769
|
-
options?: any,
|
|
770
|
-
) => Promise<unknown>)
|
|
771
|
-
& { readonly has?: (host: any, own: string[]) => (name: string) => boolean }
|
|
772
|
-
/** Each declared request's responder, from its function prop or event form, read when the request arrives. */
|
|
773
|
-
readonly responders?: Readonly<Record<string, () => ((event: Event) => void) | undefined>>
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
/** Vue does not promise a `v-for` ref array in source order, and the host does. */
|
|
777
|
-
function inDocumentOrder(elements: readonly Element[]): Element[] {
|
|
778
|
-
return [...elements].sort((a, b) => (a.compareDocumentPosition(b) & 4) !== 0 ? -1 : 1)
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
/** Slot content flattened to the elements Vue mounted for it, descending through fragments. */
|
|
782
|
-
function slottedElements(nodes: readonly any[]): Element[] {
|
|
783
|
-
const elements: Element[] = []
|
|
784
|
-
for (const node of nodes) {
|
|
785
|
-
if (node.type === Fragment && Array.isArray(node.children)) {
|
|
786
|
-
elements.push(...slottedElements(node.children))
|
|
787
|
-
} else if (node.el instanceof Element) elements.push(node.el)
|
|
788
|
-
}
|
|
789
|
-
return elements
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
/**
|
|
793
|
-
* The controller host, built from Vue refs, effects, and lifecycle. Reads and writes reach the
|
|
794
|
-
* component's own refs, so a controller's change renders as any other Vue change does. Vue
|
|
795
|
-
* hooks cover mount/unmount; a shared native observer also detects external root detachment
|
|
796
|
-
* and reinsertion without treating an in-tree move as a new connection.
|
|
797
|
-
*/
|
|
798
|
-
export function useComponentHost(
|
|
799
|
-
controllerLoader: () => Promise<unknown>,
|
|
800
|
-
options: ComponentHostOptions,
|
|
801
|
-
) {
|
|
802
|
-
const root = rootElement(options.root)
|
|
803
|
-
const {
|
|
804
|
-
dispatch,
|
|
805
|
-
props,
|
|
806
|
-
propInputs = () => null,
|
|
807
|
-
propNames = [],
|
|
808
|
-
refs = {},
|
|
809
|
-
state = {},
|
|
810
|
-
computed: computedValues = {},
|
|
811
|
-
data = {},
|
|
812
|
-
context = {},
|
|
813
|
-
} = options
|
|
814
|
-
const vueSlots = useSlots()
|
|
815
|
-
const component = getCurrentInstance()
|
|
816
|
-
const report = (error: unknown): void => {
|
|
817
|
-
const handler = component?.appContext.config.errorHandler
|
|
818
|
-
if (handler === undefined) {
|
|
819
|
-
queueMicrotask(() => {
|
|
820
|
-
throw error
|
|
821
|
-
})
|
|
822
|
-
} else handler(error, component?.proxy ?? null, 'HTML Next controller')
|
|
823
|
-
}
|
|
824
|
-
const controllerDiagnostic = (code: 'HJ001' | 'HJ002', reason?: unknown): Error => {
|
|
825
|
-
const edge = options.controllerSource
|
|
826
|
-
const source = edge?.definition ? new URL(edge.definition, document.baseURI).href : undefined
|
|
827
|
-
const url = new URL(edge?.specifier ?? '', source ?? document.baseURI).href
|
|
828
|
-
const tick = String.fromCharCode(96)
|
|
829
|
-
const message = code === 'HJ002'
|
|
830
|
-
? options.module
|
|
831
|
-
? 'Component module ' + tick + url + tick + ' export connect must be a function.'
|
|
832
|
-
: 'Controller module ' + tick + url + tick + ' must default-export a function.'
|
|
833
|
-
: 'Controller module ' + tick + url + tick + ' failed to load: '
|
|
834
|
-
+ (reason instanceof Error ? reason.message : String(reason)) + '.'
|
|
835
|
-
return Object.assign(
|
|
836
|
-
new Error((source === undefined ? '' : source + ': ') + code + ': ' + message),
|
|
837
|
-
{
|
|
838
|
-
name: 'HtmlDiagnosticError',
|
|
839
|
-
diagnostic: Object.freeze({ code, message, ...(source === undefined ? {} : { source }) }),
|
|
840
|
-
},
|
|
841
|
-
)
|
|
842
|
-
}
|
|
843
|
-
type ControllerModule = Record<string, unknown> & {
|
|
844
|
-
readonly default: (host: unknown) => unknown
|
|
845
|
-
readonly connect?: Connect<object>
|
|
846
|
-
}
|
|
847
|
-
let controllerModule: Promise<ControllerModule> | undefined
|
|
848
|
-
const loadControllerModule = (): Promise<ControllerModule> =>
|
|
849
|
-
controllerModule ??= Promise.resolve()
|
|
850
|
-
.then(controllerLoader)
|
|
851
|
-
.then((candidate) => {
|
|
852
|
-
const loaded = candidate as
|
|
853
|
-
| { readonly default?: unknown; readonly connect?: unknown }
|
|
854
|
-
| null
|
|
855
|
-
if (
|
|
856
|
-
options.module
|
|
857
|
-
? loaded === null || typeof loaded !== 'object'
|
|
858
|
-
|| loaded.connect !== undefined && typeof loaded.connect !== 'function'
|
|
859
|
-
: typeof loaded?.default !== 'function'
|
|
860
|
-
) throw controllerDiagnostic('HJ002')
|
|
861
|
-
return candidate as ControllerModule
|
|
862
|
-
})
|
|
863
|
-
.catch((error: unknown) => {
|
|
864
|
-
if (error instanceof Error && 'diagnostic' in error) throw error
|
|
865
|
-
throw controllerDiagnostic('HJ001', error)
|
|
866
|
-
})
|
|
867
|
-
const stops: Array<() => void> = []
|
|
868
|
-
const connected = shallowRef(false)
|
|
869
|
-
const pauses = new Map<() => void, () => void>()
|
|
870
|
-
// A subscription's known responder (k), and for a request's function prop or event form whether one is set (r).
|
|
871
|
-
const subscriptions = new Set<{
|
|
872
|
-
type: string
|
|
873
|
-
callback: (event: Event) => void | (() => void)
|
|
874
|
-
target?: Element | undefined
|
|
875
|
-
cleanup?: void | (() => void)
|
|
876
|
-
k?: (() => void) | undefined
|
|
877
|
-
r?: () => boolean
|
|
878
|
-
}>()
|
|
879
|
-
type Subscription = typeof subscriptions extends Set<infer S> ? S : never
|
|
880
|
-
// How many known responders the controller's host.on keeps on its own root, by name.
|
|
881
|
-
const own: string[] = []
|
|
882
|
-
const track = (entry: Subscription): void => {
|
|
883
|
-
entry.k?.()
|
|
884
|
-
entry.k = entry.target === undefined || entry.r?.() === false
|
|
885
|
-
? undefined
|
|
886
|
-
: knownResponder(entry.target, entry.type, entry.r ? undefined : own)
|
|
887
|
-
}
|
|
888
|
-
const activate = (entry: Subscription): void => {
|
|
889
|
-
if (entry.type === 'connect') entry.cleanup = entry.callback(new Event('connect'))
|
|
890
|
-
else if (entry.type !== 'disconnect') {
|
|
891
|
-
entry.target = root.value ?? undefined
|
|
892
|
-
entry.target?.addEventListener(entry.type, entry.callback as EventListener)
|
|
893
|
-
track(entry)
|
|
894
|
-
// A responder registered after a request went unanswered tells the asker to ask again.
|
|
895
|
-
if (entry.target !== undefined) relayResponders(entry.target, entry.type)
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
const deactivate = (entry: Subscription, disconnecting: boolean): void => {
|
|
899
|
-
entry.target?.removeEventListener(entry.type, entry.callback as EventListener)
|
|
900
|
-
entry.target = undefined
|
|
901
|
-
track(entry)
|
|
902
|
-
const cleanup = entry.cleanup
|
|
903
|
-
entry.cleanup = undefined
|
|
904
|
-
cleanup?.()
|
|
905
|
-
if (disconnecting && entry.type === 'disconnect') entry.callback(new Event('disconnect'))
|
|
906
|
-
}
|
|
907
|
-
const propHandles = Object.create(null) as Record<string, unknown>
|
|
908
|
-
for (const name of propNames) {
|
|
909
|
-
const validity = () => options.propValidity?.(name)
|
|
910
|
-
// One computed per prop: a reader of this prop does not run again when another prop changes.
|
|
911
|
-
const value = computed(() => props?.value[name])
|
|
912
|
-
propHandles[name] = Object.freeze({
|
|
913
|
-
get value() {
|
|
914
|
-
return value.value
|
|
915
|
-
},
|
|
916
|
-
get inputValue() {
|
|
917
|
-
return propInputs(name)
|
|
918
|
-
},
|
|
919
|
-
get validity() {
|
|
920
|
-
return validity()
|
|
921
|
-
},
|
|
922
|
-
validate: validity,
|
|
923
|
-
})
|
|
924
|
-
}
|
|
925
|
-
// Vue clears a template ref when it removes the element, as when a failed render replaces the
|
|
926
|
-
// root, so cleanup that runs after that still reads the root that disconnected.
|
|
927
|
-
let lastRoot: Element | null = null
|
|
928
|
-
const host = {
|
|
929
|
-
get [Symbol.for('@nextwebwg/html-next.inputs.v1')](): unknown {
|
|
930
|
-
return options.inputs?.port({
|
|
931
|
-
declarations: Object.fromEntries(
|
|
932
|
-
[...Object.keys(state), ...Object.keys(computedValues), ...Object.keys(context)].map(
|
|
933
|
-
name => [name, {
|
|
934
|
-
read: () => host.state[name],
|
|
935
|
-
status: () => options.availability?.[name]?.() ?? READY_INPUT,
|
|
936
|
-
}]
|
|
937
|
-
),
|
|
938
|
-
),
|
|
939
|
-
track: (name, kind) => options.inputTracking!.track(name, kind),
|
|
940
|
-
watch: run => host.effect(run),
|
|
941
|
-
untracked: run => options.inputTracking!.untracked(run),
|
|
942
|
-
})
|
|
943
|
-
},
|
|
944
|
-
get element(): Element {
|
|
945
|
-
return (root.value ?? lastRoot) as Element
|
|
946
|
-
},
|
|
947
|
-
get root(): Element {
|
|
948
|
-
return (root.value ?? lastRoot) as Element
|
|
949
|
-
},
|
|
950
|
-
...controllerNamespaces({
|
|
951
|
-
state: Object.fromEntries(
|
|
952
|
-
Object.entries(state).map(([name, value]) => [name, {
|
|
953
|
-
get: () => value.value,
|
|
954
|
-
set: (next: unknown) => {
|
|
955
|
-
value.value = next
|
|
956
|
-
},
|
|
957
|
-
}]),
|
|
958
|
-
),
|
|
959
|
-
computed: Object.fromEntries(
|
|
960
|
-
[...Object.entries(computedValues), ...Object.entries(context)].map((
|
|
961
|
-
[name, value],
|
|
962
|
-
) => [name, () => value.value]),
|
|
963
|
-
),
|
|
964
|
-
data: Object.fromEntries(
|
|
965
|
-
Object.entries(data).map(([name, value]) => [name, () => value.value]),
|
|
966
|
-
),
|
|
967
|
-
...(options.acceptsState === undefined ? {} : { acceptsState: options.acceptsState }),
|
|
968
|
-
...(options.initials === undefined ? {} : { initials: options.initials }),
|
|
969
|
-
}, options.controllerSource?.definition ?? '<component>'),
|
|
970
|
-
scripts: options.scripts ?? Object.freeze({}),
|
|
971
|
-
on(type: string, callback: (event: Event) => void | (() => void)): () => void {
|
|
972
|
-
return listen(type, callback)
|
|
973
|
-
},
|
|
974
|
-
props: Object.freeze(propHandles),
|
|
975
|
-
refs: Object.defineProperties(
|
|
976
|
-
{},
|
|
977
|
-
Object.fromEntries(
|
|
978
|
-
Object.entries(refs).map(([name, ref]) => [name, {
|
|
979
|
-
enumerable: true,
|
|
980
|
-
get: () =>
|
|
981
|
-
Array.isArray(ref.value)
|
|
982
|
-
? inDocumentOrder(ref.value.map(refElement))
|
|
983
|
-
: refElement(ref.value),
|
|
984
|
-
}]),
|
|
985
|
-
),
|
|
986
|
-
) as Readonly<Record<string, Element | readonly Element[]>>,
|
|
987
|
-
slots: new Proxy({} as Record<string, readonly Element[]>, {
|
|
988
|
-
get: (_target, name) => {
|
|
989
|
-
if (typeof name !== 'string') return undefined
|
|
990
|
-
const render = vueSlots[name]
|
|
991
|
-
return render === undefined ? [] : slottedElements(render())
|
|
992
|
-
},
|
|
993
|
-
has: (_target, name) => typeof name === 'string' && vueSlots[name] !== undefined,
|
|
994
|
-
}),
|
|
995
|
-
signal<T>(initialValue: T) {
|
|
996
|
-
// shallowRef holds the controller's own value and notifies only when it changes.
|
|
997
|
-
const value = shallowRef(initialValue)
|
|
998
|
-
return {
|
|
999
|
-
get: (): T => value.value,
|
|
1000
|
-
set: (next: T): void => {
|
|
1001
|
-
value.value = next
|
|
1002
|
-
},
|
|
1003
|
-
update: (next: (current: T) => T): void => {
|
|
1004
|
-
value.value = next(value.value)
|
|
1005
|
-
},
|
|
1006
|
-
}
|
|
1007
|
-
},
|
|
1008
|
-
computed<T>(compute: () => T) {
|
|
1009
|
-
const value = computed(compute)
|
|
1010
|
-
return { get: (): T => value.value }
|
|
1011
|
-
},
|
|
1012
|
-
effect(run: () => void | (() => void)): () => void {
|
|
1013
|
-
let cleanup: void | (() => void)
|
|
1014
|
-
const pause = (): void => {
|
|
1015
|
-
const previous = cleanup
|
|
1016
|
-
cleanup = undefined
|
|
1017
|
-
previous?.()
|
|
1018
|
-
}
|
|
1019
|
-
const stop = watchEffect(() => {
|
|
1020
|
-
pause()
|
|
1021
|
-
if (connected.value) cleanup = run()
|
|
1022
|
-
}, { flush: 'post' })
|
|
1023
|
-
const dispose = (): void => {
|
|
1024
|
-
stop()
|
|
1025
|
-
pause()
|
|
1026
|
-
pauses.delete(dispose)
|
|
1027
|
-
const index = stops.indexOf(dispose)
|
|
1028
|
-
if (index >= 0) stops.splice(index, 1)
|
|
1029
|
-
}
|
|
1030
|
-
pauses.set(dispose, pause)
|
|
1031
|
-
stops.push(dispose)
|
|
1032
|
-
return dispose
|
|
1033
|
-
},
|
|
1034
|
-
dispatch,
|
|
1035
|
-
// A component that declares requests also has host.request.
|
|
1036
|
-
...(options.request === undefined ? {} : {
|
|
1037
|
-
request: (name: string, detail?: unknown, requestOptions?: unknown): Promise<unknown> =>
|
|
1038
|
-
options.request!(
|
|
1039
|
-
root.value as Element,
|
|
1040
|
-
requests.signal(connected.value),
|
|
1041
|
-
name,
|
|
1042
|
-
detail,
|
|
1043
|
-
requestOptions,
|
|
1044
|
-
),
|
|
1045
|
-
}),
|
|
1046
|
-
}
|
|
1047
|
-
function listen(
|
|
1048
|
-
type: string,
|
|
1049
|
-
callback: (event: Event) => void | (() => void),
|
|
1050
|
-
set?: () => boolean,
|
|
1051
|
-
): () => void {
|
|
1052
|
-
const entry: Subscription = {
|
|
1053
|
-
type,
|
|
1054
|
-
callback: type === 'connect' || type === 'disconnect' || options.request === undefined
|
|
1055
|
-
? callback
|
|
1056
|
-
: hostListener(type, callback),
|
|
1057
|
-
}
|
|
1058
|
-
if (set !== undefined) entry.r = set
|
|
1059
|
-
subscriptions.add(entry)
|
|
1060
|
-
if (connected.value) activate(entry)
|
|
1061
|
-
return () => {
|
|
1062
|
-
if (subscriptions.delete(entry)) deactivate(entry, false)
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
if (options.request?.has !== undefined) {
|
|
1066
|
-
Object.assign(host, { hasResponder: options.request.has(host, own) })
|
|
1067
|
-
}
|
|
1068
|
-
const requests = requestConnection()
|
|
1069
|
-
// Each request's responder listens on the root from its first connection, before the controller runs.
|
|
1070
|
-
const responders = Object.entries(options.responders ?? {})
|
|
1071
|
-
for (const [name, read] of responders) {
|
|
1072
|
-
listen(name, (event) =>
|
|
1073
|
-
read()?.(event), () =>
|
|
1074
|
-
read() !== undefined)
|
|
1075
|
-
}
|
|
1076
|
-
// A function prop or event form set later is a known responder, and relays for its request, as a late host.on does.
|
|
1077
|
-
if (responders.length > 0) {
|
|
1078
|
-
watch(() => responders.map(([, read]) => read() !== undefined), (now, before) => {
|
|
1079
|
-
for (const entry of subscriptions) if (entry.r !== undefined) track(entry)
|
|
1080
|
-
const element = root.value
|
|
1081
|
-
if (element === null || !connected.value) return
|
|
1082
|
-
now.forEach((set, index) => {
|
|
1083
|
-
if (set && !before[index]) relayResponders(element, responders[index]![0])
|
|
1084
|
-
})
|
|
1085
|
-
})
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
let cleanup: void | (() => void)
|
|
1089
|
-
let started: Promise<ControllerModule> | undefined
|
|
1090
|
-
let stopObserving: (() => void) | undefined
|
|
1091
|
-
let connection = 0
|
|
1092
|
-
let initialized = false
|
|
1093
|
-
let unmounted = false
|
|
1094
|
-
let releaseController: (() => void) | undefined
|
|
1095
|
-
const disconnect = (): void => {
|
|
1096
|
-
if (!connected.value) return
|
|
1097
|
-
connected.value = false
|
|
1098
|
-
connection += 1
|
|
1099
|
-
requests.end()
|
|
1100
|
-
releaseController?.()
|
|
1101
|
-
for (const pause of pauses.values()) pause()
|
|
1102
|
-
for (const entry of subscriptions) deactivate(entry, true)
|
|
1103
|
-
cleanup?.()
|
|
1104
|
-
cleanup = undefined
|
|
1105
|
-
}
|
|
1106
|
-
const synchronize = (): void => {
|
|
1107
|
-
if (unmounted) return
|
|
1108
|
-
lastRoot = root.value ?? lastRoot
|
|
1109
|
-
if (root.value?.isConnected !== true) {
|
|
1110
|
-
disconnect()
|
|
1111
|
-
return
|
|
1112
|
-
}
|
|
1113
|
-
if (connected.value) {
|
|
1114
|
-
for (const entry of subscriptions) {
|
|
1115
|
-
if (
|
|
1116
|
-
entry.type !== 'connect' && entry.type !== 'disconnect' && entry.target !== root.value
|
|
1117
|
-
) {
|
|
1118
|
-
deactivate(entry, false)
|
|
1119
|
-
activate(entry)
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
return
|
|
1123
|
-
}
|
|
1124
|
-
connected.value = true
|
|
1125
|
-
for (const entry of subscriptions) activate(entry)
|
|
1126
|
-
if (initialized && !options.module) return
|
|
1127
|
-
const current = ++connection
|
|
1128
|
-
// Requests from inside this root wait until the controller has run, or failed to load.
|
|
1129
|
-
const release = releaseController = holdController(root.value!)
|
|
1130
|
-
started = loadControllerModule().then(async (loaded) => {
|
|
1131
|
-
if (!connected.value || current !== connection || initialized && !options.module) {
|
|
1132
|
-
return loaded
|
|
1133
|
-
}
|
|
1134
|
-
initialized = true
|
|
1135
|
-
if (options.module) {
|
|
1136
|
-
try {
|
|
1137
|
-
cleanup = activateModule(loaded, host, report)
|
|
1138
|
-
} finally {
|
|
1139
|
-
release()
|
|
1140
|
-
}
|
|
1141
|
-
return loaded
|
|
1142
|
-
}
|
|
1143
|
-
let invoked: unknown
|
|
1144
|
-
try {
|
|
1145
|
-
invoked = loaded.default(host as never)
|
|
1146
|
-
} finally {
|
|
1147
|
-
release()
|
|
1148
|
-
}
|
|
1149
|
-
const result = await invoked
|
|
1150
|
-
if (typeof result === 'function') {
|
|
1151
|
-
if (!connected.value || current !== connection) result()
|
|
1152
|
-
else cleanup = result as () => void
|
|
1153
|
-
}
|
|
1154
|
-
return loaded
|
|
1155
|
-
})
|
|
1156
|
-
void started.catch(report).finally(release)
|
|
1157
|
-
}
|
|
1158
|
-
onMounted(() => {
|
|
1159
|
-
if (root.value === null) return
|
|
1160
|
-
stopObserving = observeConnection(root.value, () => {
|
|
1161
|
-
try {
|
|
1162
|
-
synchronize()
|
|
1163
|
-
} catch (error) {
|
|
1164
|
-
report(error)
|
|
1165
|
-
}
|
|
1166
|
-
})
|
|
1167
|
-
synchronize()
|
|
1168
|
-
})
|
|
1169
|
-
onUpdated(synchronize)
|
|
1170
|
-
onBeforeUnmount(() => {
|
|
1171
|
-
unmounted = true
|
|
1172
|
-
stopObserving?.()
|
|
1173
|
-
disconnect()
|
|
1174
|
-
for (const stop of stops.splice(0)) stop()
|
|
1175
|
-
subscriptions.clear()
|
|
1176
|
-
})
|
|
1177
|
-
return host
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
export interface DispatchOptions {
|
|
1181
|
-
/** Each declared event's bubbles, composed, and cancelable. */
|
|
1182
|
-
readonly declared?: Readonly<Record<string, EventInit>>
|
|
1183
|
-
/** Each declared event's detail check, from its declared type. */
|
|
1184
|
-
readonly checks?: Readonly<Record<string, (detail: unknown) => boolean>>
|
|
1185
|
-
/** Props an event's detail reports, which also emit `update:<prop>` for `v-model:<prop>`. */
|
|
1186
|
-
readonly modeled?: readonly string[]
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
class HtmlDiagnosticError extends Error {
|
|
1190
|
-
readonly diagnostic: Readonly<{ code: string; message: string }>
|
|
1191
|
-
|
|
1192
|
-
constructor(code: string, message: string) {
|
|
1193
|
-
super(code + ': ' + message)
|
|
1194
|
-
this.name = 'HtmlDiagnosticError'
|
|
1195
|
-
this.diagnostic = Object.freeze({ code, message })
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
/** Apply HTML Next's event filters before propagation/cancellation actions on the original DOM event. */
|
|
1200
|
-
export function runFilteredEvent(
|
|
1201
|
-
event: Event,
|
|
1202
|
-
modifiers: readonly string[],
|
|
1203
|
-
handler: () => void,
|
|
1204
|
-
): void {
|
|
1205
|
-
if (modifiers.includes('self') && event.target !== event.currentTarget) return
|
|
1206
|
-
if (event instanceof MouseEvent) {
|
|
1207
|
-
const buttons: Record<string, number> = { left: 0, middle: 1, right: 2 }
|
|
1208
|
-
const filters = modifiers.filter((modifier) => modifier in buttons)
|
|
1209
|
-
if (filters.length > 0 && !filters.some((filter) => event.button === buttons[filter])) return
|
|
1210
|
-
}
|
|
1211
|
-
const systemKeys = ['ctrl', 'shift', 'alt', 'meta'] as const
|
|
1212
|
-
for (const key of systemKeys) {
|
|
1213
|
-
if (modifiers.includes(key) && !(event as unknown as Record<string, boolean>)[key + 'Key']) {
|
|
1214
|
-
return
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
if (
|
|
1218
|
-
modifiers.includes('exact') && systemKeys.some((key) =>
|
|
1219
|
-
!modifiers.includes(key) && (event as unknown as Record<string, boolean>)[key + 'Key']
|
|
1220
|
-
)
|
|
1221
|
-
) return
|
|
1222
|
-
if (event instanceof KeyboardEvent) {
|
|
1223
|
-
const names: Record<string, string> = {
|
|
1224
|
-
enter: 'Enter',
|
|
1225
|
-
escape: 'Escape',
|
|
1226
|
-
space: ' ',
|
|
1227
|
-
tab: 'Tab',
|
|
1228
|
-
up: 'ArrowUp',
|
|
1229
|
-
down: 'ArrowDown',
|
|
1230
|
-
left: 'ArrowLeft',
|
|
1231
|
-
right: 'ArrowRight',
|
|
1232
|
-
}
|
|
1233
|
-
const filters = modifiers.filter((modifier) => modifier in names)
|
|
1234
|
-
if (filters.length > 0 && !filters.some((filter) => event.key === names[filter])) return
|
|
1235
|
-
}
|
|
1236
|
-
if (modifiers.includes('prevent')) event.preventDefault()
|
|
1237
|
-
if (modifiers.includes('stop')) event.stopPropagation()
|
|
1238
|
-
handler()
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
/** Reports declared CustomEvents to Vue and dispatches them through the DOM. */
|
|
1242
|
-
export function createDispatch(
|
|
1243
|
-
componentRoot: Readable<HTMLElement | null>,
|
|
1244
|
-
emit?: (name: string, detail: unknown) => void,
|
|
1245
|
-
options: DispatchOptions = {},
|
|
1246
|
-
): (name: string, detail?: unknown, targets?: unknown) => boolean {
|
|
1247
|
-
const root = rootElement(componentRoot)
|
|
1248
|
-
const { declared = {}, checks = {}, modeled = [] } = options
|
|
1249
|
-
// One change can be reported by more than one event — a choice is both a select and a change —
|
|
1250
|
-
// and each carries the new value. The prop updates once per change: a value already reported in
|
|
1251
|
-
// this turn of the event loop is not reported again.
|
|
1252
|
-
const reported = new Map<string, unknown>()
|
|
1253
|
-
return (name, detail, targets) => {
|
|
1254
|
-
const check = checks[name]
|
|
1255
|
-
if (detail !== undefined && check !== undefined && !check(detail)) {
|
|
1256
|
-
throw new HtmlDiagnosticError(
|
|
1257
|
-
'HR002',
|
|
1258
|
-
`Event \`${name}\` detail does not satisfy its declared type.`,
|
|
1259
|
-
)
|
|
1260
|
-
}
|
|
1261
|
-
if (targets !== undefined) {
|
|
1262
|
-
let accepted = true
|
|
1263
|
-
dispatchToTargets(targets, target => {
|
|
1264
|
-
if (
|
|
1265
|
-
!target.dispatchEvent(
|
|
1266
|
-
new CustomEvent(name, { bubbles: true, composed: true, ...declared[name], detail }),
|
|
1267
|
-
)
|
|
1268
|
-
) accepted = false
|
|
1269
|
-
})
|
|
1270
|
-
return accepted
|
|
1271
|
-
}
|
|
1272
|
-
if (detail !== null && typeof detail === 'object') {
|
|
1273
|
-
for (const prop of modeled) {
|
|
1274
|
-
if (!(prop in detail)) continue
|
|
1275
|
-
const value = (detail as Record<string, unknown>)[prop]
|
|
1276
|
-
if (reported.has(prop) && Object.is(reported.get(prop), value)) continue
|
|
1277
|
-
if (reported.size === 0) queueMicrotask(() => reported.clear())
|
|
1278
|
-
reported.set(prop, value)
|
|
1279
|
-
emit?.(`update:${prop}`, value)
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
const event = new CustomEvent(name, {
|
|
1283
|
-
bubbles: true,
|
|
1284
|
-
composed: true,
|
|
1285
|
-
...declared[name],
|
|
1286
|
-
detail,
|
|
1287
|
-
})
|
|
1288
|
-
if (check !== undefined) emit?.(name, event)
|
|
1289
|
-
return root.value?.dispatchEvent(event) ?? true
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
/**
|
|
1294
|
-
* A consumer's attributes for the root. Vue sets a name that is also an object property, such as
|
|
1295
|
-
* `constructor`, as a DOM property; capitalized, it stays an attribute, which HTML lowercases.
|
|
1296
|
-
*/
|
|
1297
|
-
export function nativeAttrs(attrs: Record<string, unknown>): Record<string, unknown> {
|
|
1298
|
-
const names = Object.keys(attrs)
|
|
1299
|
-
if (!names.some((name) => Object.hasOwn(Object.prototype, name))) return attrs
|
|
1300
|
-
return Object.fromEntries(names.map((name) => [
|
|
1301
|
-
Object.hasOwn(Object.prototype, name)
|
|
1302
|
-
? name === '__proto__' ? '__Proto__' : name[0]!.toUpperCase() + name.slice(1)
|
|
1303
|
-
: name,
|
|
1304
|
-
attrs[name],
|
|
1305
|
-
]))
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
/** Hydrating server markup needs its root to be the element this component renders. */
|
|
1309
|
-
export function checkHydratedRoot(expected: string | undefined, tag: string): void {
|
|
1310
|
-
const node = getCurrentInstance()?.vnode.el
|
|
1311
|
-
if (
|
|
1312
|
-
typeof window === 'undefined' || node == null
|
|
1313
|
-
|| node instanceof Element && node.localName === expected
|
|
1314
|
-
) return
|
|
1315
|
-
const message = `Server markup for <${tag}> has an incompatible root.`
|
|
1316
|
-
throw Object.assign(new Error(`HR005: ${message}`), {
|
|
1317
|
-
name: 'HtmlDiagnosticError',
|
|
1318
|
-
diagnostic: Object.freeze({ code: 'HR005', message }),
|
|
1319
|
-
})
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
function diagnostic(code: string, message: string): Error {
|
|
1323
|
-
return Object.assign(new Error(`${code}: ${message}`), {
|
|
1324
|
-
name: 'HtmlDiagnosticError',
|
|
1325
|
-
diagnostic: Object.freeze({ code, message }),
|
|
1326
|
-
})
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
/** A component's context value from the ancestor that provides it; a missing provider is an error. */
|
|
1330
|
-
export function injectContext(tag: string, from: string, name: string): any {
|
|
1331
|
-
const value = inject<any>(`html-next:${from}:${name}`)
|
|
1332
|
-
if (value === undefined) {
|
|
1333
|
-
throw diagnostic('HR009', `<${tag}> requires context \`${name}\` from <${from}>.`)
|
|
1334
|
-
}
|
|
1335
|
-
return value
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
/** Vue may return an in-progress computed value on a cyclic read; guard the public value access instead. */
|
|
1339
|
-
export function cycleCheckedComputed<T>(evaluate: () => T) {
|
|
1340
|
-
const value = computed(evaluate)
|
|
1341
|
-
let reading = false
|
|
1342
|
-
return new Proxy(value, {
|
|
1343
|
-
get(target, property) {
|
|
1344
|
-
if (property !== 'value') return Reflect.get(target, property)
|
|
1345
|
-
if (reading) throw diagnostic('HR006', 'A reactive computed value depends on itself.')
|
|
1346
|
-
reading = true
|
|
1347
|
-
try {
|
|
1348
|
-
return target.value
|
|
1349
|
-
} finally {
|
|
1350
|
-
reading = false
|
|
1351
|
-
}
|
|
1352
|
-
},
|
|
1353
|
-
})
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
/** A Vue state cell owns its first usable seed or an earlier accepted edit, including equal writes. */
|
|
1357
|
-
export function initializedState<T>(
|
|
1358
|
-
evaluate: () => { value: unknown; status: InputStatus },
|
|
1359
|
-
accepts: (value: unknown) => boolean,
|
|
1360
|
-
copy: <V>(value: V) => V,
|
|
1361
|
-
warn: () => void,
|
|
1362
|
-
): Ref<T | null | undefined> & { status(): InputStatus; start(): void } {
|
|
1363
|
-
const cell = ref<T>() as Ref<T | null | undefined>
|
|
1364
|
-
let seed: ReturnType<typeof cycleCheckedComputed<ReturnType<typeof evaluate>>> | undefined =
|
|
1365
|
-
cycleCheckedComputed(evaluate)
|
|
1366
|
-
let initialized = false
|
|
1367
|
-
let stop: (() => void) | undefined
|
|
1368
|
-
let notify = () => {}
|
|
1369
|
-
const claim = (): void => {
|
|
1370
|
-
if (initialized) return
|
|
1371
|
-
initialized = true
|
|
1372
|
-
seed = undefined
|
|
1373
|
-
// A claim can happen inside the seed watcher's read; release after Vue finishes tracking it.
|
|
1374
|
-
if (stop !== undefined) queueMicrotask(stop)
|
|
1375
|
-
}
|
|
1376
|
-
const initialize = (): void => {
|
|
1377
|
-
if (initialized) return
|
|
1378
|
-
const next = seed!.value
|
|
1379
|
-
if (!next.status.ready || next.status.stale || next.value === undefined) return
|
|
1380
|
-
if (!accepts(next.value)) {
|
|
1381
|
-
warn()
|
|
1382
|
-
return
|
|
1383
|
-
}
|
|
1384
|
-
claim()
|
|
1385
|
-
cell.value = copy(next.value) as T
|
|
1386
|
-
notify()
|
|
1387
|
-
}
|
|
1388
|
-
const state = customRef<T | null | undefined>((track, trigger) => {
|
|
1389
|
-
notify = trigger
|
|
1390
|
-
return {
|
|
1391
|
-
get() {
|
|
1392
|
-
track()
|
|
1393
|
-
initialize()
|
|
1394
|
-
return cell.value
|
|
1395
|
-
},
|
|
1396
|
-
set(value) {
|
|
1397
|
-
if (value != null && !accepts(value)) {
|
|
1398
|
-
warn()
|
|
1399
|
-
return
|
|
1400
|
-
}
|
|
1401
|
-
const first = !initialized
|
|
1402
|
-
claim()
|
|
1403
|
-
cell.value = value ?? null
|
|
1404
|
-
if (first) trigger()
|
|
1405
|
-
},
|
|
1406
|
-
}
|
|
1407
|
-
})
|
|
1408
|
-
return Object.assign(state, {
|
|
1409
|
-
status(): InputStatus {
|
|
1410
|
-
void state.value
|
|
1411
|
-
return initialized
|
|
1412
|
-
? cell.value === undefined ? { ...READY_INPUT, ready: false } : READY_INPUT
|
|
1413
|
-
: { ...seed!.value.status, ready: false, stale: false }
|
|
1414
|
-
},
|
|
1415
|
-
start() {
|
|
1416
|
-
if (initialized) return
|
|
1417
|
-
stop = watchEffect(() => {
|
|
1418
|
-
void state.value
|
|
1419
|
-
})
|
|
1420
|
-
if (initialized) stop()
|
|
1421
|
-
},
|
|
1422
|
-
})
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
/**
|
|
1426
|
-
* A declared prop's reflected root attribute: the authored literal until the consumer passes the
|
|
1427
|
-
* prop, then its value as text, absent for null.
|
|
1428
|
-
*/
|
|
1429
|
-
export function useReflectedProp() {
|
|
1430
|
-
const instance = getCurrentInstance()
|
|
1431
|
-
return (
|
|
1432
|
-
name: string,
|
|
1433
|
-
kebab: string,
|
|
1434
|
-
value: unknown,
|
|
1435
|
-
fallback: string | undefined,
|
|
1436
|
-
bound: boolean,
|
|
1437
|
-
separator?: string,
|
|
1438
|
-
): string | undefined => {
|
|
1439
|
-
const incoming = instance?.vnode.props
|
|
1440
|
-
if (
|
|
1441
|
-
!bound
|
|
1442
|
-
&& (incoming === null || incoming === undefined
|
|
1443
|
-
|| (!Object.hasOwn(incoming, name) && !Object.hasOwn(incoming, kebab)))
|
|
1444
|
-
) return fallback
|
|
1445
|
-
if (value === null || value === undefined) return undefined
|
|
1446
|
-
return Array.isArray(value) && separator !== undefined
|
|
1447
|
-
? value.join(separator)
|
|
1448
|
-
: typeof value === 'object'
|
|
1449
|
-
? JSON.stringify(value)
|
|
1450
|
-
: String(value)
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
/** A scoped slot's name, which the consumer must fill with a `<template slot>` rather than plain children. */
|
|
1455
|
-
export function useScopedSlotName() {
|
|
1456
|
-
const slots = useSlots()
|
|
1457
|
-
// A slot's name is a literal, so the outlet keeps its literal type, as declared slots type it.
|
|
1458
|
-
return <Name extends string>(name: Name): Name => {
|
|
1459
|
-
if (slots[name] === undefined && slots.default?.().some((node) => node.props?.slot === name)) {
|
|
1460
|
-
throw diagnostic(
|
|
1461
|
-
'HR007',
|
|
1462
|
-
'Scoped slot `' + name + '` requires a consumer <template slot="' + name + '">.',
|
|
1463
|
-
)
|
|
1464
|
-
}
|
|
1465
|
-
return name
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
/** An inline text part that keeps its last accepted text while its value is invalid. */
|
|
1470
|
-
export type InlineTextSegment = {
|
|
1471
|
-
readonly value: unknown
|
|
1472
|
-
readonly text: string
|
|
1473
|
-
readonly accepted: boolean
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
export function inlineTextSegment(
|
|
1477
|
-
value: unknown,
|
|
1478
|
-
accepted: boolean,
|
|
1479
|
-
text: (value: any) => string,
|
|
1480
|
-
): InlineTextSegment {
|
|
1481
|
-
return {
|
|
1482
|
-
value,
|
|
1483
|
-
accepted,
|
|
1484
|
-
text: accepted && value !== Symbol.for('html-next.invalid-result') ? text(value) ?? '' : '',
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
export const RetainedInlineText = /* @__PURE__ */ defineComponent({
|
|
1489
|
-
props: { segments: { type: Array as PropType<InlineTextSegment[]>, required: true } },
|
|
1490
|
-
setup(props) {
|
|
1491
|
-
const previous: string[] = []
|
|
1492
|
-
return () =>
|
|
1493
|
-
createTextVNode(
|
|
1494
|
-
props.segments.map((segment, index) => {
|
|
1495
|
-
if (
|
|
1496
|
-
segment.accepted && segment.value !== Symbol.for('html-next.invalid-result')
|
|
1497
|
-
) previous[index] = segment.text
|
|
1498
|
-
return previous[index] ?? ''
|
|
1499
|
-
}).join(''),
|
|
1500
|
-
)
|
|
1501
|
-
},
|
|
1502
|
-
})
|
|
1503
|
-
|
|
1504
|
-
const KeyedFailure = /* @__PURE__ */ defineComponent({
|
|
1505
|
-
props: { error: { type: null, required: true } },
|
|
1506
|
-
setup(props) {
|
|
1507
|
-
return () => {
|
|
1508
|
-
throw props.error
|
|
1509
|
-
}
|
|
1510
|
-
},
|
|
1511
|
-
})
|
|
1512
|
-
|
|
1513
|
-
/** A keyed list that produces a duplicate key keeps its last rows and reports the error in the browser. */
|
|
1514
|
-
export const KeyedBoundary = /* @__PURE__ */ defineComponent({
|
|
1515
|
-
setup(_props, { slots }) {
|
|
1516
|
-
let last: VNode[] = []
|
|
1517
|
-
return () => {
|
|
1518
|
-
try {
|
|
1519
|
-
last = slots.default?.() ?? []
|
|
1520
|
-
return last
|
|
1521
|
-
} catch (error) {
|
|
1522
|
-
if (
|
|
1523
|
-
!(error instanceof Error)
|
|
1524
|
-
|| (error as Error & { diagnostic?: { code?: string } }).diagnostic?.code !== 'HR004'
|
|
1525
|
-
) throw error
|
|
1526
|
-
if (typeof window === 'undefined') throw error
|
|
1527
|
-
return [...last, h(KeyedFailure, { error })]
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
},
|
|
1531
|
-
})
|
|
1532
|
-
|
|
1533
|
-
const warned = new Set<string>()
|
|
1534
|
-
/** An authored value's check: false warns once per authored location. */
|
|
1535
|
-
export function warnUnless(accepted: boolean, location: string, message: string): boolean {
|
|
1536
|
-
if (!accepted && !warned.has(location)) {
|
|
1537
|
-
warned.add(location)
|
|
1538
|
-
console.warn(message)
|
|
1539
|
-
}
|
|
1540
|
-
return accepted
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
|
-
/**
|
|
1544
|
-
* A handler's checked write to a ref or through a setter. An invalid result, such as a number that
|
|
1545
|
-
* is not finite, writes nothing. A value neither null, absent nor of the destination's type warns once for
|
|
1546
|
-
* its authored write (the state `path` in `file`'s `handler`), as the live runtime does, and
|
|
1547
|
-
* leaves the destination as it was.
|
|
1548
|
-
*/
|
|
1549
|
-
export function write(
|
|
1550
|
-
to: { value: unknown } | ((value: any) => void),
|
|
1551
|
-
value: unknown,
|
|
1552
|
-
check?: (value: any) => boolean,
|
|
1553
|
-
file?: string,
|
|
1554
|
-
handler?: string,
|
|
1555
|
-
path?: string,
|
|
1556
|
-
): void {
|
|
1557
|
-
if (
|
|
1558
|
-
value === Symbol.for('html-next.invalid-result')
|
|
1559
|
-
|| (typeof value === 'number' && !Number.isFinite(value))
|
|
1560
|
-
) return
|
|
1561
|
-
if (check !== undefined && value != null && !check(value)) {
|
|
1562
|
-
warnUnless(
|
|
1563
|
-
false,
|
|
1564
|
-
`${file}#${handler}:${path}`,
|
|
1565
|
-
`${file}: HR007: State \`${path}\` does not satisfy its declared type.`,
|
|
1566
|
-
)
|
|
1567
|
-
} else if (typeof to === 'function') to(value ?? null)
|
|
1568
|
-
else to.value = value ?? null
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
export const isString = (value: unknown): value is string => typeof value === 'string'
|
|
1572
|
-
export const isNumber = (value: unknown): value is number =>
|
|
1573
|
-
typeof value === 'number' && Number.isFinite(value)
|
|
1574
|
-
export const isInteger = (value: unknown): value is number => Number.isInteger(value)
|
|
1575
|
-
export const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean'
|
|
1576
|
-
|
|
1577
|
-
export function truthy(value: unknown): boolean {
|
|
1578
|
-
if (Array.isArray(value)) return value.length > 0
|
|
1579
|
-
if (value instanceof Error) return true
|
|
1580
|
-
if (value !== null && typeof value === 'object') {
|
|
1581
|
-
if (typeof Event !== 'undefined' && 'type' in value) {
|
|
1582
|
-
try {
|
|
1583
|
-
Object.getOwnPropertyDescriptor(Event.prototype, 'type')!.get!.call(value)
|
|
1584
|
-
return true
|
|
1585
|
-
} catch { /* ordinary objects use their fields */ }
|
|
1586
|
-
}
|
|
1587
|
-
return Object.keys(value).length > 0
|
|
1588
|
-
}
|
|
1589
|
-
return Boolean(value)
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
export function text(value: unknown): string {
|
|
1593
|
-
if (Array.isArray(value)) return value.map(text).join(' ')
|
|
1594
|
-
return value === null || value === undefined || typeof value === 'object' ? '' : String(value)
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
export function attribute(value: unknown): any {
|
|
1598
|
-
if (
|
|
1599
|
-
value === null || value === undefined || value === false
|
|
1600
|
-
|| (typeof value === 'object' && !Array.isArray(value))
|
|
1601
|
-
) return undefined
|
|
1602
|
-
return value === true ? '' : text(value)
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
export function list(value: unknown): any[] {
|
|
1606
|
-
return Array.isArray(value) ? value : []
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
export function number(value: unknown): number | undefined {
|
|
1610
|
-
return typeof value === 'number' && !Number.isNaN(value) ? value : undefined
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
// A nonempty scalar call cannot produce the invalid-result sentinel.
|
|
1614
|
-
export type ConcatResult<T extends unknown[]> = T extends
|
|
1615
|
-
[
|
|
1616
|
-
string | number | boolean | null | undefined,
|
|
1617
|
-
...(string | number | boolean | null | undefined)[],
|
|
1618
|
-
] ? string | undefined
|
|
1619
|
-
: string | symbol | undefined
|
|
1620
|
-
export function concat<T extends unknown[]>(...values: T): ConcatResult<T> {
|
|
1621
|
-
if (values.some(value => value === Symbol.for('html-next.invalid-result'))) {
|
|
1622
|
-
return Symbol.for('html-next.invalid-result') as ConcatResult<T>
|
|
1623
|
-
}
|
|
1624
|
-
if (values.some(value => value === undefined)) return undefined as ConcatResult<T>
|
|
1625
|
-
if (values.length === 0 || values.some(value => typeof value === 'object' && value !== null)) {
|
|
1626
|
-
return Symbol.for('html-next.invalid-result') as ConcatResult<T>
|
|
1627
|
-
}
|
|
1628
|
-
return values.map(value => value === null ? '' : String(value)).join('') as ConcatResult<T>
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
export function join(...values: unknown[]): string | symbol | undefined {
|
|
1632
|
-
if (values.some(value => value === Symbol.for('html-next.invalid-result'))) {
|
|
1633
|
-
return Symbol.for('html-next.invalid-result')
|
|
1634
|
-
}
|
|
1635
|
-
if (values.some(value => value === undefined)) return undefined
|
|
1636
|
-
if (values.length !== 2) return Symbol.for('html-next.invalid-result')
|
|
1637
|
-
const [items, separator] = values
|
|
1638
|
-
if (!Array.isArray(items) || typeof separator !== 'string') {
|
|
1639
|
-
return Symbol.for('html-next.invalid-result')
|
|
1640
|
-
}
|
|
1641
|
-
if (items.some(value => value === Symbol.for('html-next.invalid-result'))) {
|
|
1642
|
-
return Symbol.for('html-next.invalid-result')
|
|
1643
|
-
}
|
|
1644
|
-
if (items.some(value => value === undefined)) return undefined
|
|
1645
|
-
if (items.some(value => typeof value === 'object' && value !== null)) {
|
|
1646
|
-
return Symbol.for('html-next.invalid-result')
|
|
1647
|
-
}
|
|
1648
|
-
if (new Set(items.filter(value => value !== null).map(value => typeof value)).size > 1) {
|
|
1649
|
-
return Symbol.for('html-next.invalid-result')
|
|
1650
|
-
}
|
|
1651
|
-
return items.map(value => value === null ? '' : String(value)).join(separator)
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
export function math(
|
|
1655
|
-
fn: string,
|
|
1656
|
-
kinds: readonly string[],
|
|
1657
|
-
values: readonly unknown[],
|
|
1658
|
-
): number | string | symbol | undefined {
|
|
1659
|
-
if (values.includes(Symbol.for('html-next.invalid-result'))) {
|
|
1660
|
-
return Symbol.for('html-next.invalid-result')
|
|
1661
|
-
}
|
|
1662
|
-
if (values.some(value => value === undefined || value === null)) return undefined
|
|
1663
|
-
if (
|
|
1664
|
-
(fn === 'abs' || fn === 'negate') && values.length !== 1
|
|
1665
|
-
|| fn === 'round' && (values.length < 1 || values.length > 2)
|
|
1666
|
-
|| (fn === 'min' || fn === 'max') && values.length === 0
|
|
1667
|
-
|| fn === 'clamp' && values.length !== 3
|
|
1668
|
-
) return Symbol.for('html-next.invalid-result')
|
|
1669
|
-
const kind = kinds[0]
|
|
1670
|
-
const dimensional = kind === 'length' || kind === 'percentage' || kind === 'duration'
|
|
1671
|
-
if (!dimensional && kind !== 'number') return Symbol.for('html-next.invalid-result')
|
|
1672
|
-
let unit: string | undefined
|
|
1673
|
-
const numbers: number[] = []
|
|
1674
|
-
for (let index = 0; index < values.length; index++) {
|
|
1675
|
-
if (kinds[index] !== kind) return Symbol.for('html-next.invalid-result')
|
|
1676
|
-
const value = values[index]
|
|
1677
|
-
if (!dimensional) {
|
|
1678
|
-
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
1679
|
-
return Symbol.for('html-next.invalid-result')
|
|
1680
|
-
}
|
|
1681
|
-
numbers.push(value)
|
|
1682
|
-
continue
|
|
1683
|
-
}
|
|
1684
|
-
if (typeof value !== 'string') return Symbol.for('html-next.invalid-result')
|
|
1685
|
-
const match =
|
|
1686
|
-
/^(-?(?:\d+(?:\.\d+)?|\.\d+))(vmin|vmax|rem|px|em|vw|vh|ch|ex|cm|mm|in|pt|pc|q|ms|s|%)$/.exec(
|
|
1687
|
-
value,
|
|
1688
|
-
)
|
|
1689
|
-
if (match === null || unit !== undefined && match[2] !== unit) {
|
|
1690
|
-
return Symbol.for('html-next.invalid-result')
|
|
1691
|
-
}
|
|
1692
|
-
unit = match[2]
|
|
1693
|
-
if (
|
|
1694
|
-
(unit === '%' ? 'percentage' : unit === 'ms' || unit === 's' ? 'duration' : 'length') !== kind
|
|
1695
|
-
) return Symbol.for('html-next.invalid-result')
|
|
1696
|
-
const number = Number(match[1])
|
|
1697
|
-
if (!Number.isFinite(number)) return Symbol.for('html-next.invalid-result')
|
|
1698
|
-
numbers.push(number)
|
|
1699
|
-
}
|
|
1700
|
-
let result: number
|
|
1701
|
-
switch (fn) {
|
|
1702
|
-
case 'abs':
|
|
1703
|
-
result = Math.abs(numbers[0]!)
|
|
1704
|
-
break
|
|
1705
|
-
case 'negate':
|
|
1706
|
-
result = -numbers[0]!
|
|
1707
|
-
break
|
|
1708
|
-
case 'round': {
|
|
1709
|
-
const step = Math.abs(numbers[1] ?? 1)
|
|
1710
|
-
if (step === 0) return Symbol.for('html-next.invalid-result')
|
|
1711
|
-
result = Math.round(numbers[0]! / step) * step
|
|
1712
|
-
break
|
|
1713
|
-
}
|
|
1714
|
-
case 'min':
|
|
1715
|
-
result = Math.min(...numbers)
|
|
1716
|
-
break
|
|
1717
|
-
case 'max':
|
|
1718
|
-
result = Math.max(...numbers)
|
|
1719
|
-
break
|
|
1720
|
-
case 'clamp':
|
|
1721
|
-
result = Math.max(numbers[0]!, Math.min(numbers[1]!, numbers[2]!))
|
|
1722
|
-
break
|
|
1723
|
-
default:
|
|
1724
|
-
return Symbol.for('html-next.invalid-result')
|
|
1725
|
-
}
|
|
1726
|
-
return !Number.isFinite(result)
|
|
1727
|
-
? Symbol.for('html-next.invalid-result')
|
|
1728
|
-
: unit === undefined
|
|
1729
|
-
? result
|
|
1730
|
-
: String(result) + unit
|
|
1731
|
-
}
|
|
1732
|
-
|
|
1733
|
-
export function arithmetic(
|
|
1734
|
-
op: string,
|
|
1735
|
-
leftKind: string,
|
|
1736
|
-
rightKind: string,
|
|
1737
|
-
left: unknown,
|
|
1738
|
-
right: unknown,
|
|
1739
|
-
operate: (a: number, b: number) => number,
|
|
1740
|
-
): string | symbol | undefined {
|
|
1741
|
-
const invalid = Symbol.for('html-next.invalid-result')
|
|
1742
|
-
if (left === invalid || right === invalid) return invalid
|
|
1743
|
-
if (left === null || left === undefined || right === null || right === undefined) return undefined
|
|
1744
|
-
const isDimension = (kind: string): boolean =>
|
|
1745
|
-
kind === 'length' || kind === 'percentage' || kind === 'duration'
|
|
1746
|
-
const parse = (value: unknown, kind: string): { number: number; unit: string } | undefined => {
|
|
1747
|
-
if (typeof value !== 'string' || !isDimension(kind)) return undefined
|
|
1748
|
-
const match =
|
|
1749
|
-
/^(-?(?:\d+(?:\.\d+)?|\.\d+))(vmin|vmax|rem|px|em|vw|vh|ch|ex|cm|mm|in|pt|pc|q|ms|s|%)$/.exec(
|
|
1750
|
-
value,
|
|
1751
|
-
)
|
|
1752
|
-
if (match === null) return undefined
|
|
1753
|
-
const unit = match[2]!
|
|
1754
|
-
if (
|
|
1755
|
-
(unit === '%' ? 'percentage' : unit === 'ms' || unit === 's' ? 'duration' : 'length') !== kind
|
|
1756
|
-
) return undefined
|
|
1757
|
-
const number = Number(match[1])
|
|
1758
|
-
return Number.isFinite(number) ? { number, unit } : undefined
|
|
1759
|
-
}
|
|
1760
|
-
const x = parse(left, leftKind), y = parse(right, rightKind)
|
|
1761
|
-
if (isDimension(leftKind) && x === undefined || isDimension(rightKind) && y === undefined) {
|
|
1762
|
-
return invalid
|
|
1763
|
-
}
|
|
1764
|
-
let value: number, unit: string
|
|
1765
|
-
if (op === '+' || op === '-') {
|
|
1766
|
-
if (x === undefined || y === undefined || leftKind !== rightKind || x.unit !== y.unit) {
|
|
1767
|
-
return invalid
|
|
1768
|
-
}
|
|
1769
|
-
value = operate(x.number, y.number)
|
|
1770
|
-
unit = x.unit
|
|
1771
|
-
} else if (op === '*') {
|
|
1772
|
-
const quantity = x ?? y
|
|
1773
|
-
const factor = x === undefined ? left : right
|
|
1774
|
-
if (
|
|
1775
|
-
quantity === undefined || x !== undefined && y !== undefined || typeof factor !== 'number'
|
|
1776
|
-
|| !Number.isFinite(factor)
|
|
1777
|
-
) return invalid
|
|
1778
|
-
value = operate(quantity.number, factor)
|
|
1779
|
-
unit = quantity.unit
|
|
1780
|
-
} else {
|
|
1781
|
-
if (
|
|
1782
|
-
op !== '/' || x === undefined || y !== undefined || typeof right !== 'number'
|
|
1783
|
-
|| !Number.isFinite(right) || right === 0
|
|
1784
|
-
) return invalid
|
|
1785
|
-
value = operate(x.number, right)
|
|
1786
|
-
unit = x.unit
|
|
1787
|
-
}
|
|
1788
|
-
return Number.isFinite(value) ? String(value) + unit : invalid
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
export function sortBy(items: any[], keys: readonly string[]): any[] {
|
|
1792
|
-
const field = (item: any, path: string): unknown =>
|
|
1793
|
-
path !== '' && item !== null && typeof item === 'object' && !Array.isArray(item)
|
|
1794
|
-
? path.split('.').reduce((value, key) => value?.[key], item)
|
|
1795
|
-
: item
|
|
1796
|
-
return items.slice().sort((a, b) => {
|
|
1797
|
-
for (const key of keys) {
|
|
1798
|
-
const descending = key.startsWith('-')
|
|
1799
|
-
const path = descending ? key.slice(1) : key
|
|
1800
|
-
const x = field(a, path), y = field(b, path)
|
|
1801
|
-
const order = typeof x === 'number' && typeof y === 'number'
|
|
1802
|
-
? x - y
|
|
1803
|
-
: text(x).localeCompare(text(y))
|
|
1804
|
-
if (order !== 0) return descending ? -order : order
|
|
1805
|
-
}
|
|
1806
|
-
return 0
|
|
1807
|
-
})
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
export function eachRows<T>(
|
|
1811
|
-
items: readonly T[],
|
|
1812
|
-
): {
|
|
1813
|
-
item: T
|
|
1814
|
-
index: number
|
|
1815
|
-
loop: { index: number; first: boolean; last: boolean; count: number }
|
|
1816
|
-
}[] {
|
|
1817
|
-
return items.map((item, index) => ({
|
|
1818
|
-
item,
|
|
1819
|
-
index,
|
|
1820
|
-
loop: { index, first: index === 0, last: index === items.length - 1, count: items.length },
|
|
1821
|
-
}))
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
|
-
export function uniqueKeys<T>(
|
|
1825
|
-
items: readonly T[],
|
|
1826
|
-
keyOf: (
|
|
1827
|
-
item: T,
|
|
1828
|
-
index: number,
|
|
1829
|
-
loop: { index: number; first: boolean; last: boolean; count: number },
|
|
1830
|
-
) => unknown,
|
|
1831
|
-
): readonly T[] {
|
|
1832
|
-
const seen = new Set<unknown>()
|
|
1833
|
-
for (let index = 0; index < items.length; index += 1) {
|
|
1834
|
-
const key = keyOf(items[index]!, index, {
|
|
1835
|
-
index,
|
|
1836
|
-
first: index === 0,
|
|
1837
|
-
last: index === items.length - 1,
|
|
1838
|
-
count: items.length,
|
|
1839
|
-
})
|
|
1840
|
-
if (seen.has(key)) {
|
|
1841
|
-
const message = `A keyed list produced duplicate key \`${text(key)}\`.`
|
|
1842
|
-
throw Object.assign(new Error(`HR004: ${message}`), {
|
|
1843
|
-
name: 'HtmlDiagnosticError',
|
|
1844
|
-
diagnostic: Object.freeze({ code: 'HR004', message }),
|
|
1845
|
-
})
|
|
1846
|
-
}
|
|
1847
|
-
seen.add(key)
|
|
1848
|
-
}
|
|
1849
|
-
return items
|
|
1850
|
-
}
|
|
1851
|
-
|
|
1852
|
-
/**
|
|
1853
|
-
* Digits after the point in `value`'s shortest round-trip text, as `Number#toString` writes it:
|
|
1854
|
-
* 2 for 1.25, 7 for 1e-7, and 0 for an integer, 1e21, NaN or Infinity. Writing that text made an
|
|
1855
|
-
* addition about ten times slower (200 ns against 20 ns), so up to 22 places, where 10^places is
|
|
1856
|
-
* exact, the fewest places at which `value` survives rounding stand in for it. That count is never
|
|
1857
|
-
* below the text's, and differs only for a value of more than 15 significant digits, which
|
|
1858
|
-
* `decimalResult` leaves as a double either way.
|
|
1859
|
-
*/
|
|
1860
|
-
export function decimalPlaces(value: number): number {
|
|
1861
|
-
if (Number.isInteger(value)) return 0
|
|
1862
|
-
for (let places = 1; places <= 22; places += 1) {
|
|
1863
|
-
if (Math.round(value * 10 ** places) / 10 ** places === value) return places
|
|
1864
|
-
}
|
|
1865
|
-
const [digits, exponent] = String(value).split('e')
|
|
1866
|
-
const point = digits!.indexOf('.')
|
|
1867
|
-
return Math.max(0, (point < 0 ? 0 : digits!.length - point - 1) - Number(exponent ?? 0))
|
|
1868
|
-
}
|
|
1869
|
-
|
|
1870
|
-
/**
|
|
1871
|
-
* The double nearest the exact decimal result: `a` and `b` become integers at `left` and `right`
|
|
1872
|
-
* places, `combine` joins them, and the integer is read back at `places`. Every step is exact while
|
|
1873
|
-
* the operands and `result` stay below 10^15 at `places`, the 15 significant digits a double always
|
|
1874
|
-
* holds; past that (or for a non-finite value, or with no places) the double `result` stands.
|
|
1875
|
-
* Dividing by 10^places is exact only up to 10^22, so past 22 places a nonzero integer is read back
|
|
1876
|
-
* by parsing its decimal text, which rounds exactly too. A zero divides, keeping its sign.
|
|
1877
|
-
*/
|
|
1878
|
-
export function decimalResult(
|
|
1879
|
-
result: number,
|
|
1880
|
-
a: number,
|
|
1881
|
-
b: number,
|
|
1882
|
-
left: number,
|
|
1883
|
-
right: number,
|
|
1884
|
-
places: number,
|
|
1885
|
-
combine: (a: number, b: number) => number,
|
|
1886
|
-
): number {
|
|
1887
|
-
if (!(places > 0 && Math.max(Math.abs(a), Math.abs(b), Math.abs(result)) * 10 ** places < 1e15)) {
|
|
1888
|
-
return result
|
|
1889
|
-
}
|
|
1890
|
-
const integer = combine(Math.round(a * 10 ** left), Math.round(b * 10 ** right))
|
|
1891
|
-
return places > 22 && integer !== 0 ? Number(`${integer}e-${places}`) : integer / 10 ** places
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
|
-
/** `a + b` at the larger operand's decimal places: `decimalAdd(0.1, 0.2)` is 0.3. */
|
|
1895
|
-
export function decimalAdd(a: number, b: number): number {
|
|
1896
|
-
const places = Math.max(decimalPlaces(a), decimalPlaces(b))
|
|
1897
|
-
return decimalResult(a + b, a, b, places, places, places, (x, y) => x + y)
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1900
|
-
/** `a - b` at the larger operand's decimal places: `decimalSubtract(0.3, 0.1)` is 0.2. */
|
|
1901
|
-
export function decimalSubtract(a: number, b: number): number {
|
|
1902
|
-
const places = Math.max(decimalPlaces(a), decimalPlaces(b))
|
|
1903
|
-
return decimalResult(a - b, a, b, places, places, places, (x, y) => x - y)
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
/** `a * b` at the sum of the operands' decimal places: `decimalMultiply(0.1, 0.2)` is 0.02. */
|
|
1907
|
-
export function decimalMultiply(a: number, b: number): number {
|
|
1908
|
-
const left = decimalPlaces(a)
|
|
1909
|
-
const right = decimalPlaces(b)
|
|
1910
|
-
return decimalResult(a * b, a, b, left, right, left + right, (x, y) => x * y)
|
|
1911
|
-
}
|
|
1912
|
-
|
|
1913
|
-
/** `a / b` at full double precision: `decimalDivide(1, 3)` is 0.3333333333333333 and `decimalDivide(1, 0)` is Infinity. */
|
|
1914
|
-
export function decimalDivide(a: number, b: number): number {
|
|
1915
|
-
return a / b
|
|
1916
|
-
}
|
|
1917
|
-
|
|
1918
|
-
/**
|
|
1919
|
-
* `a % b` at the larger operand's decimal places, with the dividend's sign as JavaScript's `%`:
|
|
1920
|
-
* `decimalRemainder(0.3, 0.1)` is 0, where JavaScript gives 0.09999999999999998.
|
|
1921
|
-
*/
|
|
1922
|
-
export function decimalRemainder(a: number, b: number): number {
|
|
1923
|
-
const places = Math.max(decimalPlaces(a), decimalPlaces(b))
|
|
1924
|
-
return decimalResult(a % b, a, b, places, places, places, (x, y) => x % y)
|
|
1925
|
-
}
|
|
1926
|
-
|
|
1927
|
-
export function createFormatValue(): any {
|
|
1928
|
-
// FIFO bounds native instances and retained keys; only constructor inputs, never values, are cached.
|
|
1929
|
-
const cache = new Map()
|
|
1930
|
-
function formatterFor(name: any, locale: any, options: any) {
|
|
1931
|
-
const constructor = Reflect.get(Intl, name)
|
|
1932
|
-
// There is no cheap native query for changes to the default time zone. Keep native lookup for
|
|
1933
|
-
// instants without an explicit zone; civil HTML values already supply their fixed UTC anchor.
|
|
1934
|
-
if (name === 'DateTimeFormat' && options.timeZone === undefined) {
|
|
1935
|
-
return new constructor(locale, options)
|
|
1936
|
-
}
|
|
1937
|
-
const entries = []
|
|
1938
|
-
for (const key of Object.keys(options).sort()) {
|
|
1939
|
-
const value = options[key]
|
|
1940
|
-
if (value === undefined) {
|
|
1941
|
-
continue
|
|
1942
|
-
}
|
|
1943
|
-
// Native option coercion can observe mutable objects. Bypass caching rather than stringify
|
|
1944
|
-
// them or collapse NaN/infinity into null, which would change validation and side effects.
|
|
1945
|
-
if (
|
|
1946
|
-
value !== null && typeof value !== 'string' && typeof value !== 'boolean'
|
|
1947
|
-
&& typeof value !== 'number'
|
|
1948
|
-
|| typeof value === 'number' && !Number.isFinite(value)
|
|
1949
|
-
) {
|
|
1950
|
-
return new constructor(locale, options)
|
|
1951
|
-
}
|
|
1952
|
-
entries.push([key, typeof value, Object.is(value, -0) ? '-0' : value])
|
|
1953
|
-
}
|
|
1954
|
-
const language = locale === undefined && typeof navigator !== 'undefined'
|
|
1955
|
-
? navigator.language
|
|
1956
|
-
: undefined
|
|
1957
|
-
const key = JSON.stringify([name, locale, language, entries])
|
|
1958
|
-
if (key.length > 4096) {
|
|
1959
|
-
return new constructor(locale, options)
|
|
1960
|
-
}
|
|
1961
|
-
const cached = cache.get(key)
|
|
1962
|
-
if (cached !== undefined && cached.constructor === constructor) {
|
|
1963
|
-
return cached.value
|
|
1964
|
-
}
|
|
1965
|
-
const value = new constructor(locale, options)
|
|
1966
|
-
if (cache.size >= 128 && !cache.has(key)) {
|
|
1967
|
-
cache.delete(cache.keys().next().value)
|
|
1968
|
-
}
|
|
1969
|
-
cache.set(key, { constructor, value })
|
|
1970
|
-
return value
|
|
1971
|
-
}
|
|
1972
|
-
/**
|
|
1973
|
-
* The native Intl adapter. Self-contained so converters emit this same implementation only when
|
|
1974
|
-
* authored expressions use formatting, without importing the live parser or interpreter.
|
|
1975
|
-
* undefined is absence; the shared invalid-result symbol tells each target to retain its output.
|
|
1976
|
-
*/
|
|
1977
|
-
return function formatValue(value: any, inputType: any, operation: any, ...args: any[]) {
|
|
1978
|
-
const invalid = Symbol.for('html-next.invalid-result')
|
|
1979
|
-
if (value === invalid || args.includes(invalid)) {
|
|
1980
|
-
return invalid
|
|
1981
|
-
}
|
|
1982
|
-
if (value === undefined || value === null || args.some((arg: any) => arg === undefined)) {
|
|
1983
|
-
return undefined
|
|
1984
|
-
}
|
|
1985
|
-
const end = operation === 'formatRange' ? args.shift() : undefined
|
|
1986
|
-
if (operation === 'formatRange' && (end === null || end === undefined)) {
|
|
1987
|
-
return undefined
|
|
1988
|
-
}
|
|
1989
|
-
const explicit = typeof args[0] === 'string'
|
|
1990
|
-
const defaults = {
|
|
1991
|
-
number: 'number',
|
|
1992
|
-
integer: 'number',
|
|
1993
|
-
percentage: 'percent',
|
|
1994
|
-
date: 'date',
|
|
1995
|
-
time: 'time',
|
|
1996
|
-
datetime: 'dateTime',
|
|
1997
|
-
'datetime-local': 'dateTime',
|
|
1998
|
-
duration: 'duration',
|
|
1999
|
-
list: 'list',
|
|
2000
|
-
}
|
|
2001
|
-
const format = explicit ? args.shift() : Reflect.get(defaults, inputType ?? '')
|
|
2002
|
-
const options = args.length > 0 ? args.shift() : {}
|
|
2003
|
-
const locale = args.shift()
|
|
2004
|
-
if (
|
|
2005
|
-
args.length > 0 || !format || options === null || typeof options !== 'object'
|
|
2006
|
-
|| Array.isArray(options) || locale !== undefined && typeof locale !== 'string'
|
|
2007
|
-
) {
|
|
2008
|
-
return invalid
|
|
2009
|
-
}
|
|
2010
|
-
try {
|
|
2011
|
-
const durationFields = [
|
|
2012
|
-
'years',
|
|
2013
|
-
'months',
|
|
2014
|
-
'weeks',
|
|
2015
|
-
'days',
|
|
2016
|
-
'hours',
|
|
2017
|
-
'minutes',
|
|
2018
|
-
'seconds',
|
|
2019
|
-
'milliseconds',
|
|
2020
|
-
'microseconds',
|
|
2021
|
-
'nanoseconds',
|
|
2022
|
-
]
|
|
2023
|
-
const settings = { ...options }
|
|
2024
|
-
let formatter
|
|
2025
|
-
let input = value
|
|
2026
|
-
let last = end
|
|
2027
|
-
let zoneFree = false
|
|
2028
|
-
if (['number', 'currency', 'percent', 'unit'].includes(format)) {
|
|
2029
|
-
if (format !== 'number') {
|
|
2030
|
-
if (settings.style !== undefined && settings.style !== format) {
|
|
2031
|
-
return invalid
|
|
2032
|
-
}
|
|
2033
|
-
settings.style = format
|
|
2034
|
-
}
|
|
2035
|
-
const quantity = (candidate: any) => {
|
|
2036
|
-
if (
|
|
2037
|
-
inputType === 'percentage' && typeof candidate === 'string'
|
|
2038
|
-
&& /^-?(?:\d+(?:\.\d+)?|\.\d+)%$/.test(candidate)
|
|
2039
|
-
) {
|
|
2040
|
-
return Number(candidate.slice(0, -1)) / 100
|
|
2041
|
-
}
|
|
2042
|
-
return candidate
|
|
2043
|
-
}
|
|
2044
|
-
input = quantity(input)
|
|
2045
|
-
last = quantity(last)
|
|
2046
|
-
if (
|
|
2047
|
-
typeof input !== 'number' || !Number.isFinite(input)
|
|
2048
|
-
|| operation === 'formatRange' && (typeof last !== 'number' || !Number.isFinite(last))
|
|
2049
|
-
) {
|
|
2050
|
-
return invalid
|
|
2051
|
-
}
|
|
2052
|
-
formatter = formatterFor('NumberFormat', locale, settings)
|
|
2053
|
-
} else if (['date', 'time', 'dateTime'].includes(format)) {
|
|
2054
|
-
const civil = inputType === 'date' || inputType === 'time' || inputType === 'datetime-local'
|
|
2055
|
-
|| typeof input === 'string' && !/(?:Z|[+-]\d\d:\d\d)$/.test(input)
|
|
2056
|
-
zoneFree = civil
|
|
2057
|
-
if (civil && (settings.timeZone !== undefined || settings.timeZoneName !== undefined)) {
|
|
2058
|
-
return invalid
|
|
2059
|
-
}
|
|
2060
|
-
if (
|
|
2061
|
-
format === 'date'
|
|
2062
|
-
&& (settings.timeStyle !== undefined
|
|
2063
|
-
|| ['hour', 'minute', 'second', 'dayPeriod', 'fractionalSecondDigits'].some((
|
|
2064
|
-
key: any,
|
|
2065
|
-
) => settings[key] !== undefined))
|
|
2066
|
-
|| format === 'time'
|
|
2067
|
-
&& (settings.dateStyle !== undefined
|
|
2068
|
-
|| ['year', 'month', 'day', 'weekday', 'era'].some((key: any) =>
|
|
2069
|
-
settings[key] !== undefined
|
|
2070
|
-
))
|
|
2071
|
-
) {
|
|
2072
|
-
return invalid
|
|
2073
|
-
}
|
|
2074
|
-
const fields = [
|
|
2075
|
-
'year',
|
|
2076
|
-
'month',
|
|
2077
|
-
'day',
|
|
2078
|
-
'weekday',
|
|
2079
|
-
'era',
|
|
2080
|
-
'hour',
|
|
2081
|
-
'minute',
|
|
2082
|
-
'second',
|
|
2083
|
-
'dayPeriod',
|
|
2084
|
-
'fractionalSecondDigits',
|
|
2085
|
-
]
|
|
2086
|
-
if (
|
|
2087
|
-
settings.dateStyle === undefined && settings.timeStyle === undefined
|
|
2088
|
-
&& !fields.some((key: any) => settings[key] !== undefined)
|
|
2089
|
-
) {
|
|
2090
|
-
if (format !== 'time') {
|
|
2091
|
-
settings.dateStyle = 'medium'
|
|
2092
|
-
}
|
|
2093
|
-
if (format !== 'date') {
|
|
2094
|
-
settings.timeStyle = 'medium'
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
if (civil) {
|
|
2098
|
-
settings.timeZone = 'UTC'
|
|
2099
|
-
}
|
|
2100
|
-
const asDate = (candidate: any) => {
|
|
2101
|
-
if (typeof candidate === 'number' && Number.isFinite(candidate)) {
|
|
2102
|
-
return new Date(candidate)
|
|
2103
|
-
}
|
|
2104
|
-
if (typeof candidate !== 'string') {
|
|
2105
|
-
return undefined
|
|
2106
|
-
}
|
|
2107
|
-
let written = candidate.replace(' ', 'T')
|
|
2108
|
-
if (/^\d\d:\d\d(?::\d\d(?:\.\d{1,3})?)?$/.test(written)) {
|
|
2109
|
-
if (format !== 'time') {
|
|
2110
|
-
return undefined
|
|
2111
|
-
}
|
|
2112
|
-
written = '1970-01-01T' + written + 'Z'
|
|
2113
|
-
} else if (/^\d{4,}-\d\d-\d\d$/.test(written)) {
|
|
2114
|
-
if (format !== 'date') {
|
|
2115
|
-
return undefined
|
|
2116
|
-
}
|
|
2117
|
-
written += 'T00:00:00Z'
|
|
2118
|
-
} else if (/^\d{4,}-\d\d-\d\dT\d\d:\d\d(?::\d\d(?:\.\d{1,3})?)?$/.test(written)) {
|
|
2119
|
-
written += 'Z'
|
|
2120
|
-
} else if (
|
|
2121
|
-
!/^\d{4,}-\d\d-\d\dT\d\d:\d\d(?::\d\d(?:\.\d{1,3})?)?(?:Z|[+-]\d\d:\d\d)$/.test(written)
|
|
2122
|
-
) {
|
|
2123
|
-
return undefined
|
|
2124
|
-
}
|
|
2125
|
-
const date = new Date(
|
|
2126
|
-
written.replace(/^(\d{5,})-/, (_match: any, year: any) =>
|
|
2127
|
-
'+' + year.padStart(6, '0') + '-'),
|
|
2128
|
-
)
|
|
2129
|
-
if (!Number.isFinite(date.getTime())) {
|
|
2130
|
-
return undefined
|
|
2131
|
-
}
|
|
2132
|
-
// Native Date normalizes invalid days; authored HTML dates must not roll into another day.
|
|
2133
|
-
const match = /^(\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d)(?::(\d\d))?/.exec(written)
|
|
2134
|
-
if (!match) {
|
|
2135
|
-
return undefined
|
|
2136
|
-
}
|
|
2137
|
-
const probe = new Date(0)
|
|
2138
|
-
probe.setUTCFullYear(Number(match[1]), Number(match[2]) - 1, Number(match[3]))
|
|
2139
|
-
if (
|
|
2140
|
-
Number(match[1]) === 0 || probe.getUTCMonth() !== Number(match[2]) - 1
|
|
2141
|
-
|| probe.getUTCDate() !== Number(match[3]) || Number(match[4]) > 23
|
|
2142
|
-
|| Number(match[5]) > 59 || Number(match[6] ?? 0) > 59
|
|
2143
|
-
) {
|
|
2144
|
-
return undefined
|
|
2145
|
-
}
|
|
2146
|
-
return date
|
|
2147
|
-
}
|
|
2148
|
-
input = asDate(input)
|
|
2149
|
-
last = operation === 'formatRange' ? asDate(last) : undefined
|
|
2150
|
-
if (!input || operation === 'formatRange' && !last) {
|
|
2151
|
-
return invalid
|
|
2152
|
-
}
|
|
2153
|
-
formatter = formatterFor('DateTimeFormat', locale, settings)
|
|
2154
|
-
} else {
|
|
2155
|
-
if (operation === 'formatRange') {
|
|
2156
|
-
return invalid
|
|
2157
|
-
}
|
|
2158
|
-
if (format === 'relativeTime') {
|
|
2159
|
-
if (
|
|
2160
|
-
typeof input !== 'number' || !Number.isFinite(input)
|
|
2161
|
-
|| typeof settings.unit !== 'string'
|
|
2162
|
-
) {
|
|
2163
|
-
return invalid
|
|
2164
|
-
}
|
|
2165
|
-
const unit = settings.unit
|
|
2166
|
-
delete settings.unit
|
|
2167
|
-
formatter = formatterFor('RelativeTimeFormat', locale, settings)
|
|
2168
|
-
return operation === 'formatParts'
|
|
2169
|
-
? formatter.formatToParts(input, unit)
|
|
2170
|
-
: formatter.format(input, unit)
|
|
2171
|
-
}
|
|
2172
|
-
if (format === 'list') {
|
|
2173
|
-
if (!Array.isArray(input) || input.some((item: any) => typeof item !== 'string')) {
|
|
2174
|
-
return invalid
|
|
2175
|
-
}
|
|
2176
|
-
formatter = formatterFor('ListFormat', locale, settings)
|
|
2177
|
-
} else if (format === 'duration') {
|
|
2178
|
-
if (inputType === 'duration' && typeof input === 'string') {
|
|
2179
|
-
const match = /^(-?(?:\d+(?:\.\d+)?|\.\d+))(ms|s)$/.exec(input)
|
|
2180
|
-
if (!match) {
|
|
2181
|
-
return invalid
|
|
2182
|
-
}
|
|
2183
|
-
const milliseconds = Number(match[1]) * (match[2] === 's' ? 1000 : 1)
|
|
2184
|
-
if (!Number.isFinite(milliseconds)) {
|
|
2185
|
-
return invalid
|
|
2186
|
-
}
|
|
2187
|
-
const hours = Math.trunc(milliseconds / 3600000)
|
|
2188
|
-
const minutes = Math.trunc((milliseconds % 3600000) / 60000)
|
|
2189
|
-
const seconds = Math.trunc((milliseconds % 60000) / 1000)
|
|
2190
|
-
input = {
|
|
2191
|
-
hours,
|
|
2192
|
-
minutes,
|
|
2193
|
-
seconds,
|
|
2194
|
-
milliseconds: Math.trunc(milliseconds % 1000),
|
|
2195
|
-
microseconds: Math.trunc((milliseconds - Math.trunc(milliseconds)) * 1000),
|
|
2196
|
-
nanoseconds: Math.round(
|
|
2197
|
-
(milliseconds * 1000 - Math.trunc(milliseconds * 1000)) * 1000,
|
|
2198
|
-
),
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
if (
|
|
2202
|
-
input === null || typeof input !== 'object' || Array.isArray(input)
|
|
2203
|
-
|| Object.keys(input).some((key: any) => !durationFields.includes(key))
|
|
2204
|
-
) {
|
|
2205
|
-
return invalid
|
|
2206
|
-
}
|
|
2207
|
-
const DurationFormat = Reflect.get(Intl, 'DurationFormat')
|
|
2208
|
-
if (!DurationFormat) {
|
|
2209
|
-
return invalid
|
|
2210
|
-
}
|
|
2211
|
-
formatter = formatterFor('DurationFormat', locale, settings)
|
|
2212
|
-
} else if (format === 'displayName') {
|
|
2213
|
-
if (typeof input !== 'string' || operation === 'formatParts') {
|
|
2214
|
-
return invalid
|
|
2215
|
-
}
|
|
2216
|
-
return formatterFor('DisplayNames', locale, settings).of(input)
|
|
2217
|
-
} else if (format === 'plural') {
|
|
2218
|
-
if (typeof input !== 'number' || !Number.isFinite(input) || operation === 'formatParts') {
|
|
2219
|
-
return invalid
|
|
2220
|
-
}
|
|
2221
|
-
const forms = settings.forms
|
|
2222
|
-
if (
|
|
2223
|
-
!forms || typeof forms !== 'object' || Array.isArray(forms)
|
|
2224
|
-
|| typeof forms.other !== 'string' || Object.entries(forms).some(([key, entry]: any) =>
|
|
2225
|
-
!['zero', 'one', 'two', 'few', 'many', 'other'].includes(key)
|
|
2226
|
-
|| typeof entry !== 'string'
|
|
2227
|
-
)
|
|
2228
|
-
) {
|
|
2229
|
-
return invalid
|
|
2230
|
-
}
|
|
2231
|
-
delete settings.forms
|
|
2232
|
-
const category = formatterFor('PluralRules', locale, settings).select(input)
|
|
2233
|
-
const message = forms[category] ?? forms.other
|
|
2234
|
-
const numberOptions = { ...settings }
|
|
2235
|
-
delete numberOptions.type
|
|
2236
|
-
delete numberOptions.forms
|
|
2237
|
-
const number = formatterFor('NumberFormat', locale, numberOptions).format(input)
|
|
2238
|
-
return message.replace(/#/g, () => number)
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
if (!zoneFree && operation !== 'formatParts') {
|
|
2242
|
-
return operation === 'formatRange'
|
|
2243
|
-
? formatter.formatRange(input, last)
|
|
2244
|
-
: formatter.format(input)
|
|
2245
|
-
}
|
|
2246
|
-
const parts = operation === 'formatRange'
|
|
2247
|
-
? formatter.formatRangeToParts(input, last)
|
|
2248
|
-
: formatter.formatToParts(input)
|
|
2249
|
-
if (
|
|
2250
|
-
zoneFree && operation !== 'formatParts'
|
|
2251
|
-
&& !parts.some((part: any) => part.type === 'timeZoneName')
|
|
2252
|
-
) {
|
|
2253
|
-
return operation === 'formatRange'
|
|
2254
|
-
? formatter.formatRange(input, last)
|
|
2255
|
-
: formatter.format(input)
|
|
2256
|
-
}
|
|
2257
|
-
const visible = zoneFree
|
|
2258
|
-
? parts.filter((part: any, index: any) =>
|
|
2259
|
-
part.type !== 'timeZoneName'
|
|
2260
|
-
&& !(part.type === 'literal' && /^[\s(),]*$/.test(part.value)
|
|
2261
|
-
&& (parts[index - 1]?.type === 'timeZoneName'
|
|
2262
|
-
|| parts[index + 1]?.type === 'timeZoneName'))
|
|
2263
|
-
)
|
|
2264
|
-
: parts
|
|
2265
|
-
return operation === 'formatParts' ? visible : visible.map((part: any) => part.value).join('')
|
|
2266
|
-
} catch {
|
|
2267
|
-
return invalid
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
}
|
|
2271
|
-
|
|
2272
|
-
export const formatValue = /* @__PURE__ */ createFormatValue()
|