@knk1313/plain-ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +102 -2
- package/dist/components/accordion/Accordion.d.ts +27 -0
- package/dist/components/accordion/Accordion.js +18 -0
- package/dist/components/accordion/index.d.ts +1 -0
- package/dist/components/accordion/index.js +1 -0
- package/dist/components/agent-form/AgentForm.d.ts +40 -0
- package/dist/components/agent-form/AgentForm.js +100 -0
- package/dist/components/agent-form/index.d.ts +1 -0
- package/dist/components/agent-form/index.js +1 -0
- package/dist/components/agent-steps/AgentSteps.d.ts +21 -0
- package/dist/components/agent-steps/AgentSteps.js +42 -0
- package/dist/components/agent-steps/index.d.ts +1 -0
- package/dist/components/agent-steps/index.js +1 -0
- package/dist/components/agent-thinking/AgentThinking.d.ts +12 -0
- package/dist/components/agent-thinking/AgentThinking.js +18 -0
- package/dist/components/agent-thinking/index.d.ts +1 -0
- package/dist/components/agent-thinking/index.js +1 -0
- package/dist/components/area-chart/AreaChart.d.ts +10 -0
- package/dist/components/area-chart/AreaChart.js +83 -0
- package/dist/components/area-chart/index.d.ts +1 -0
- package/dist/components/area-chart/index.js +1 -0
- package/dist/components/auth-card/AuthCard.d.ts +14 -0
- package/dist/components/auth-card/AuthCard.js +9 -0
- package/dist/components/auth-card/PasswordInput.d.ts +13 -0
- package/dist/components/auth-card/PasswordInput.js +26 -0
- package/dist/components/auth-card/index.d.ts +2 -0
- package/dist/components/auth-card/index.js +2 -0
- package/dist/components/avatar/Avatar.d.ts +14 -0
- package/dist/components/avatar/Avatar.js +42 -0
- package/dist/components/avatar/index.d.ts +1 -0
- package/dist/components/avatar/index.js +1 -0
- package/dist/components/badge/Badge.d.ts +9 -0
- package/dist/components/badge/Badge.js +15 -0
- package/dist/components/badge/index.d.ts +1 -0
- package/dist/components/badge/index.js +1 -0
- package/dist/components/banner/Banner.d.ts +9 -0
- package/dist/components/banner/Banner.js +36 -0
- package/dist/components/banner/index.d.ts +1 -0
- package/dist/components/banner/index.js +1 -0
- package/dist/components/bar-chart/BarChart.d.ts +3 -0
- package/dist/components/bar-chart/BarChart.js +47 -0
- package/dist/components/bar-chart/index.d.ts +1 -0
- package/dist/components/bar-chart/index.js +1 -0
- package/dist/components/bar-list/BarList.d.ts +26 -0
- package/dist/components/bar-list/BarList.js +24 -0
- package/dist/components/bar-list/index.d.ts +1 -0
- package/dist/components/bar-list/index.js +1 -0
- package/dist/components/breadcrumb/Breadcrumb.d.ts +12 -0
- package/dist/components/breadcrumb/Breadcrumb.js +9 -0
- package/dist/components/breadcrumb/index.d.ts +1 -0
- package/dist/components/breadcrumb/index.js +1 -0
- package/dist/components/button/Button.d.ts +24 -0
- package/dist/components/button/Button.js +31 -0
- package/dist/components/button/buttonStyle.d.ts +9 -0
- package/dist/components/button/buttonStyle.js +41 -0
- package/dist/components/button/index.d.ts +1 -0
- package/dist/components/button/index.js +1 -0
- package/dist/components/button-group/ButtonGroup.d.ts +18 -0
- package/dist/components/button-group/ButtonGroup.js +26 -0
- package/dist/components/button-group/index.d.ts +1 -0
- package/dist/components/button-group/index.js +1 -0
- package/dist/components/calendar/Calendar.d.ts +20 -0
- package/dist/components/calendar/Calendar.js +98 -0
- package/dist/components/calendar/index.d.ts +1 -0
- package/dist/components/calendar/index.js +1 -0
- package/dist/components/calendar-view/CalendarView.d.ts +34 -0
- package/dist/components/calendar-view/CalendarView.js +111 -0
- package/dist/components/calendar-view/index.d.ts +1 -0
- package/dist/components/calendar-view/index.js +1 -0
- package/dist/components/card/Card.d.ts +6 -0
- package/dist/components/card/Card.js +6 -0
- package/dist/components/card/index.d.ts +1 -0
- package/dist/components/card/index.js +1 -0
- package/dist/components/carousel/Carousel.d.ts +18 -0
- package/dist/components/carousel/Carousel.js +58 -0
- package/dist/components/carousel/index.d.ts +1 -0
- package/dist/components/carousel/index.js +1 -0
- package/dist/components/chart/Axis.d.ts +51 -0
- package/dist/components/chart/Axis.js +127 -0
- package/dist/components/chart/ChartFrame.d.ts +79 -0
- package/dist/components/chart/ChartFrame.js +80 -0
- package/dist/components/chart/ChartTooltip.d.ts +12 -0
- package/dist/components/chart/ChartTooltip.js +57 -0
- package/dist/components/chart/Legend.d.ts +11 -0
- package/dist/components/chart/Legend.js +6 -0
- package/dist/components/chart/Sparkline.d.ts +5 -0
- package/dist/components/chart/Sparkline.js +20 -0
- package/dist/components/chart/format.d.ts +2 -0
- package/dist/components/chart/format.js +17 -0
- package/dist/components/chart/heatmap.d.ts +18 -0
- package/dist/components/chart/heatmap.js +47 -0
- package/dist/components/chart/index.d.ts +1 -0
- package/dist/components/chart/index.js +1 -0
- package/dist/components/chart/line.d.ts +1 -0
- package/dist/components/chart/line.js +15 -0
- package/dist/components/chart/scale.d.ts +15 -0
- package/dist/components/chart/scale.js +100 -0
- package/dist/components/chart/series.d.ts +44 -0
- package/dist/components/chart/series.js +86 -0
- package/dist/components/chart/spacing.d.ts +29 -0
- package/dist/components/chart/spacing.js +34 -0
- package/dist/components/chart/types.d.ts +29 -0
- package/dist/components/chart/types.js +2 -0
- package/dist/components/chart/useChartHover.d.ts +34 -0
- package/dist/components/chart/useChartHover.js +97 -0
- package/dist/components/checkbox/Checkbox.d.ts +10 -0
- package/dist/components/checkbox/Checkbox.js +38 -0
- package/dist/components/checkbox/index.d.ts +1 -0
- package/dist/components/checkbox/index.js +1 -0
- package/dist/components/chip/Chip.d.ts +21 -0
- package/dist/components/chip/Chip.js +10 -0
- package/dist/components/chip/index.d.ts +1 -0
- package/dist/components/chip/index.js +1 -0
- package/dist/components/close-button/CloseButton.d.ts +14 -0
- package/dist/components/close-button/CloseButton.js +9 -0
- package/dist/components/close-button/index.d.ts +1 -0
- package/dist/components/close-button/index.js +1 -0
- package/dist/components/color-picker/ColorPicker.d.ts +21 -0
- package/dist/components/color-picker/ColorPicker.js +20 -0
- package/dist/components/color-picker/index.d.ts +1 -0
- package/dist/components/color-picker/index.js +1 -0
- package/dist/components/combo-chart/ComboChart.d.ts +12 -0
- package/dist/components/combo-chart/ComboChart.js +84 -0
- package/dist/components/combo-chart/index.d.ts +1 -0
- package/dist/components/combo-chart/index.js +1 -0
- package/dist/components/combobox/Combobox.d.ts +33 -0
- package/dist/components/combobox/Combobox.js +246 -0
- package/dist/components/combobox/index.d.ts +1 -0
- package/dist/components/combobox/index.js +1 -0
- package/dist/components/command-palette/CommandPalette.d.ts +36 -0
- package/dist/components/command-palette/CommandPalette.js +156 -0
- package/dist/components/command-palette/index.d.ts +1 -0
- package/dist/components/command-palette/index.js +1 -0
- package/dist/components/composer/Composer.d.ts +32 -0
- package/dist/components/composer/Composer.js +101 -0
- package/dist/components/composer/index.d.ts +1 -0
- package/dist/components/composer/index.js +1 -0
- package/dist/components/composer-attachments/ComposerAttachments.d.ts +25 -0
- package/dist/components/composer-attachments/ComposerAttachments.js +52 -0
- package/dist/components/composer-attachments/index.d.ts +1 -0
- package/dist/components/composer-attachments/index.js +1 -0
- package/dist/components/composer-panel/ComposerPanel.d.ts +26 -0
- package/dist/components/composer-panel/ComposerPanel.js +154 -0
- package/dist/components/composer-panel/index.d.ts +1 -0
- package/dist/components/composer-panel/index.js +1 -0
- package/dist/components/contribution-chart/ContributionChart.d.ts +25 -0
- package/dist/components/contribution-chart/ContributionChart.js +127 -0
- package/dist/components/contribution-chart/index.d.ts +1 -0
- package/dist/components/contribution-chart/index.js +1 -0
- package/dist/components/data-grid/DataGrid.d.ts +40 -0
- package/dist/components/data-grid/DataGrid.js +157 -0
- package/dist/components/data-grid/index.d.ts +1 -0
- package/dist/components/data-grid/index.js +1 -0
- package/dist/components/data-table/DataTable.d.ts +87 -0
- package/dist/components/data-table/DataTable.js +150 -0
- package/dist/components/data-table/index.d.ts +2 -0
- package/dist/components/data-table/index.js +2 -0
- package/dist/components/data-table/query.d.ts +54 -0
- package/dist/components/data-table/query.js +70 -0
- package/dist/components/date-picker/DatePicker.d.ts +25 -0
- package/dist/components/date-picker/DatePicker.js +154 -0
- package/dist/components/date-picker/index.d.ts +1 -0
- package/dist/components/date-picker/index.js +1 -0
- package/dist/components/dialog/ConfirmDialog.d.ts +25 -0
- package/dist/components/dialog/ConfirmDialog.js +69 -0
- package/dist/components/dialog/Dialog.d.ts +25 -0
- package/dist/components/dialog/Dialog.js +11 -0
- package/dist/components/dialog/DialogFrame.d.ts +22 -0
- package/dist/components/dialog/DialogFrame.js +21 -0
- package/dist/components/dialog/DiscardChangesDialog.d.ts +10 -0
- package/dist/components/dialog/DiscardChangesDialog.js +10 -0
- package/dist/components/dialog/index.d.ts +2 -0
- package/dist/components/dialog/index.js +2 -0
- package/dist/components/dialog/useDiscardOnClose.d.ts +20 -0
- package/dist/components/dialog/useDiscardOnClose.js +26 -0
- package/dist/components/dialog/useModalDialog.d.ts +20 -0
- package/dist/components/dialog/useModalDialog.js +85 -0
- package/dist/components/drawer/Drawer.d.ts +14 -0
- package/dist/components/drawer/Drawer.js +22 -0
- package/dist/components/drawer/index.d.ts +1 -0
- package/dist/components/drawer/index.js +1 -0
- package/dist/components/empty-state/EmptyState.d.ts +11 -0
- package/dist/components/empty-state/EmptyState.js +7 -0
- package/dist/components/empty-state/index.d.ts +1 -0
- package/dist/components/empty-state/index.js +1 -0
- package/dist/components/error-state/ErrorState.d.ts +8 -0
- package/dist/components/error-state/ErrorState.js +7 -0
- package/dist/components/error-state/index.d.ts +1 -0
- package/dist/components/error-state/index.js +1 -0
- package/dist/components/error-summary/ErrorSummary.d.ts +21 -0
- package/dist/components/error-summary/ErrorSummary.js +16 -0
- package/dist/components/error-summary/index.d.ts +1 -0
- package/dist/components/error-summary/index.js +1 -0
- package/dist/components/field/Field.d.ts +23 -0
- package/dist/components/field/Field.js +20 -0
- package/dist/components/field/index.d.ts +1 -0
- package/dist/components/field/index.js +1 -0
- package/dist/components/field-error/FieldError.d.ts +10 -0
- package/dist/components/field-error/FieldError.js +52 -0
- package/dist/components/field-error/index.d.ts +1 -0
- package/dist/components/field-error/index.js +1 -0
- package/dist/components/file-upload/FileUpload.d.ts +50 -0
- package/dist/components/file-upload/FileUpload.js +169 -0
- package/dist/components/file-upload/fileSize.d.ts +1 -0
- package/dist/components/file-upload/fileSize.js +13 -0
- package/dist/components/file-upload/index.d.ts +1 -0
- package/dist/components/file-upload/index.js +1 -0
- package/dist/components/form-section/FormSection.d.ts +16 -0
- package/dist/components/form-section/FormSection.js +14 -0
- package/dist/components/form-section/index.d.ts +1 -0
- package/dist/components/form-section/index.js +1 -0
- package/dist/components/form-steps/FormSteps.d.ts +18 -0
- package/dist/components/form-steps/FormSteps.js +26 -0
- package/dist/components/form-steps/index.d.ts +1 -0
- package/dist/components/form-steps/index.js +1 -0
- package/dist/components/funnel-chart/FunnelChart.d.ts +12 -0
- package/dist/components/funnel-chart/FunnelChart.js +69 -0
- package/dist/components/funnel-chart/index.d.ts +1 -0
- package/dist/components/funnel-chart/index.js +1 -0
- package/dist/components/header/Header.d.ts +14 -0
- package/dist/components/header/Header.js +31 -0
- package/dist/components/header/index.d.ts +1 -0
- package/dist/components/header/index.js +1 -0
- package/dist/components/heatmap-chart/HeatmapChart.d.ts +10 -0
- package/dist/components/heatmap-chart/HeatmapChart.js +76 -0
- package/dist/components/heatmap-chart/index.d.ts +1 -0
- package/dist/components/heatmap-chart/index.js +1 -0
- package/dist/components/image-error/ImageError.d.ts +11 -0
- package/dist/components/image-error/ImageError.js +16 -0
- package/dist/components/image-error/index.d.ts +1 -0
- package/dist/components/image-error/index.js +1 -0
- package/dist/components/image-loader/ImageLoader.d.ts +9 -0
- package/dist/components/image-loader/ImageLoader.js +10 -0
- package/dist/components/image-loader/index.d.ts +1 -0
- package/dist/components/image-loader/index.js +1 -0
- package/dist/components/index.d.ts +98 -0
- package/dist/components/index.js +97 -0
- package/dist/components/input/Input.d.ts +6 -0
- package/dist/components/input/Input.js +8 -0
- package/dist/components/input/index.d.ts +1 -0
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/inputStyle.d.ts +14 -0
- package/dist/components/input/inputStyle.js +35 -0
- package/dist/components/item-range/ItemRange.d.ts +11 -0
- package/dist/components/item-range/ItemRange.js +13 -0
- package/dist/components/item-range/index.d.ts +1 -0
- package/dist/components/item-range/index.js +1 -0
- package/dist/components/label/Label.d.ts +8 -0
- package/dist/components/label/Label.js +5 -0
- package/dist/components/label/index.d.ts +1 -0
- package/dist/components/label/index.js +1 -0
- package/dist/components/line-chart/LineChart.d.ts +10 -0
- package/dist/components/line-chart/LineChart.js +29 -0
- package/dist/components/line-chart/index.d.ts +1 -0
- package/dist/components/line-chart/index.js +1 -0
- package/dist/components/link-button/LinkButton.d.ts +29 -0
- package/dist/components/link-button/LinkButton.js +15 -0
- package/dist/components/link-button/index.d.ts +1 -0
- package/dist/components/link-button/index.js +1 -0
- package/dist/components/menu/Menu.d.ts +33 -0
- package/dist/components/menu/Menu.js +113 -0
- package/dist/components/menu/index.d.ts +1 -0
- package/dist/components/menu/index.js +1 -0
- package/dist/components/meter/Meter.d.ts +24 -0
- package/dist/components/meter/Meter.js +65 -0
- package/dist/components/meter/index.d.ts +1 -0
- package/dist/components/meter/index.js +1 -0
- package/dist/components/nav-group/NavGroup.d.ts +24 -0
- package/dist/components/nav-group/NavGroup.js +23 -0
- package/dist/components/nav-group/index.d.ts +1 -0
- package/dist/components/nav-group/index.js +1 -0
- package/dist/components/notification/Notification.d.ts +25 -0
- package/dist/components/notification/Notification.js +13 -0
- package/dist/components/notification/index.d.ts +1 -0
- package/dist/components/notification/index.js +1 -0
- package/dist/components/notification-center/NotificationCenter.d.ts +33 -0
- package/dist/components/notification-center/NotificationCenter.js +29 -0
- package/dist/components/notification-center/index.d.ts +1 -0
- package/dist/components/notification-center/index.js +1 -0
- package/dist/components/number-field/NumberField.d.ts +28 -0
- package/dist/components/number-field/NumberField.js +155 -0
- package/dist/components/number-field/index.d.ts +1 -0
- package/dist/components/number-field/index.js +1 -0
- package/dist/components/otp-input/OtpInput.d.ts +14 -0
- package/dist/components/otp-input/OtpInput.js +70 -0
- package/dist/components/otp-input/index.d.ts +1 -0
- package/dist/components/otp-input/index.js +1 -0
- package/dist/components/pagination/Pagination.d.ts +21 -0
- package/dist/components/pagination/Pagination.js +51 -0
- package/dist/components/pagination/index.d.ts +1 -0
- package/dist/components/pagination/index.js +1 -0
- package/dist/components/popover/Popover.d.ts +23 -0
- package/dist/components/popover/Popover.js +83 -0
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover/index.js +1 -0
- package/dist/components/progress/Progress.d.ts +12 -0
- package/dist/components/progress/Progress.js +30 -0
- package/dist/components/progress/index.d.ts +1 -0
- package/dist/components/progress/index.js +1 -0
- package/dist/components/question-form/QuestionForm.d.ts +59 -0
- package/dist/components/question-form/QuestionForm.js +128 -0
- package/dist/components/question-form/index.d.ts +1 -0
- package/dist/components/question-form/index.js +1 -0
- package/dist/components/radar-chart/RadarChart.d.ts +3 -0
- package/dist/components/radar-chart/RadarChart.js +72 -0
- package/dist/components/radar-chart/geometry.d.ts +16 -0
- package/dist/components/radar-chart/geometry.js +56 -0
- package/dist/components/radar-chart/index.d.ts +1 -0
- package/dist/components/radar-chart/index.js +1 -0
- package/dist/components/radial-chart/RadialChart.d.ts +39 -0
- package/dist/components/radial-chart/RadialChart.js +135 -0
- package/dist/components/radial-chart/index.d.ts +1 -0
- package/dist/components/radial-chart/index.js +1 -0
- package/dist/components/radio/Radio.d.ts +31 -0
- package/dist/components/radio/Radio.js +24 -0
- package/dist/components/radio/index.d.ts +1 -0
- package/dist/components/radio/index.js +1 -0
- package/dist/components/reply-loader/ReplyLoader.d.ts +10 -0
- package/dist/components/reply-loader/ReplyLoader.js +9 -0
- package/dist/components/reply-loader/index.d.ts +1 -0
- package/dist/components/reply-loader/index.js +1 -0
- package/dist/components/sankey-chart/SankeyChart.d.ts +35 -0
- package/dist/components/sankey-chart/SankeyChart.js +218 -0
- package/dist/components/sankey-chart/index.d.ts +1 -0
- package/dist/components/sankey-chart/index.js +1 -0
- package/dist/components/scatter-chart/ScatterChart.d.ts +38 -0
- package/dist/components/scatter-chart/ScatterChart.js +69 -0
- package/dist/components/scatter-chart/index.d.ts +1 -0
- package/dist/components/scatter-chart/index.js +1 -0
- package/dist/components/search-field/SearchField.d.ts +17 -0
- package/dist/components/search-field/SearchField.js +92 -0
- package/dist/components/search-field/index.d.ts +1 -0
- package/dist/components/search-field/index.js +1 -0
- package/dist/components/segmented-control/SegmentedControl.d.ts +26 -0
- package/dist/components/segmented-control/SegmentedControl.js +38 -0
- package/dist/components/segmented-control/index.d.ts +1 -0
- package/dist/components/segmented-control/index.js +1 -0
- package/dist/components/select/Select.d.ts +11 -0
- package/dist/components/select/Select.js +30 -0
- package/dist/components/select/index.d.ts +1 -0
- package/dist/components/select/index.js +1 -0
- package/dist/components/separator/Separator.d.ts +14 -0
- package/dist/components/separator/Separator.js +12 -0
- package/dist/components/separator/index.d.ts +1 -0
- package/dist/components/separator/index.js +1 -0
- package/dist/components/settings-modal/SettingsModal.d.ts +35 -0
- package/dist/components/settings-modal/SettingsModal.js +120 -0
- package/dist/components/settings-modal/index.d.ts +1 -0
- package/dist/components/settings-modal/index.js +1 -0
- package/dist/components/sidebar/Sidebar.d.ts +30 -0
- package/dist/components/sidebar/Sidebar.js +30 -0
- package/dist/components/sidebar/index.d.ts +1 -0
- package/dist/components/sidebar/index.js +1 -0
- package/dist/components/skeleton/Skeleton.d.ts +6 -0
- package/dist/components/skeleton/Skeleton.js +6 -0
- package/dist/components/skeleton/index.d.ts +1 -0
- package/dist/components/skeleton/index.js +1 -0
- package/dist/components/skip-link/SkipLink.d.ts +8 -0
- package/dist/components/skip-link/SkipLink.js +10 -0
- package/dist/components/skip-link/index.d.ts +1 -0
- package/dist/components/skip-link/index.js +1 -0
- package/dist/components/slider/Slider.d.ts +19 -0
- package/dist/components/slider/Slider.js +49 -0
- package/dist/components/slider/index.d.ts +1 -0
- package/dist/components/slider/index.js +1 -0
- package/dist/components/spinner/Spinner.d.ts +5 -0
- package/dist/components/spinner/Spinner.js +7 -0
- package/dist/components/spinner/index.d.ts +1 -0
- package/dist/components/spinner/index.js +1 -0
- package/dist/components/stacked-bar/StackedBar.d.ts +29 -0
- package/dist/components/stacked-bar/StackedBar.js +77 -0
- package/dist/components/stacked-bar/index.d.ts +1 -0
- package/dist/components/stacked-bar/index.js +1 -0
- package/dist/components/stat-card/StatCard.d.ts +19 -0
- package/dist/components/stat-card/StatCard.js +32 -0
- package/dist/components/stat-card/index.d.ts +1 -0
- package/dist/components/stat-card/index.js +1 -0
- package/dist/components/switch/Switch.d.ts +10 -0
- package/dist/components/switch/Switch.js +22 -0
- package/dist/components/switch/index.d.ts +1 -0
- package/dist/components/switch/index.js +1 -0
- package/dist/components/table/SortableHeader.d.ts +12 -0
- package/dist/components/table/SortableHeader.js +11 -0
- package/dist/components/table/Table.d.ts +15 -0
- package/dist/components/table/Table.js +26 -0
- package/dist/components/table/align.d.ts +1 -0
- package/dist/components/table/align.js +5 -0
- package/dist/components/table/index.d.ts +4 -0
- package/dist/components/table/index.js +2 -0
- package/dist/components/tabs/Tabs.d.ts +38 -0
- package/dist/components/tabs/Tabs.js +137 -0
- package/dist/components/tabs/fitTabs.d.ts +18 -0
- package/dist/components/tabs/fitTabs.js +46 -0
- package/dist/components/tabs/index.d.ts +1 -0
- package/dist/components/tabs/index.js +1 -0
- package/dist/components/tag-group/TagGroup.d.ts +29 -0
- package/dist/components/tag-group/TagGroup.js +82 -0
- package/dist/components/tag-group/index.d.ts +1 -0
- package/dist/components/tag-group/index.js +1 -0
- package/dist/components/task-list/TaskList.d.ts +46 -0
- package/dist/components/task-list/TaskList.js +30 -0
- package/dist/components/task-list/index.d.ts +1 -0
- package/dist/components/task-list/index.js +1 -0
- package/dist/components/text-link/TextLink.d.ts +27 -0
- package/dist/components/text-link/TextLink.js +22 -0
- package/dist/components/text-link/index.d.ts +1 -0
- package/dist/components/text-link/index.js +1 -0
- package/dist/components/textarea/Textarea.d.ts +6 -0
- package/dist/components/textarea/Textarea.js +9 -0
- package/dist/components/textarea/index.d.ts +1 -0
- package/dist/components/textarea/index.js +1 -0
- package/dist/components/time-field/TimeField.d.ts +6 -0
- package/dist/components/time-field/TimeField.js +9 -0
- package/dist/components/time-field/index.d.ts +1 -0
- package/dist/components/time-field/index.js +1 -0
- package/dist/components/toast/Toast.d.ts +19 -0
- package/dist/components/toast/Toast.js +190 -0
- package/dist/components/toast/index.d.ts +1 -0
- package/dist/components/toast/index.js +1 -0
- package/dist/components/token-input/TokenInput.d.ts +27 -0
- package/dist/components/token-input/TokenInput.js +153 -0
- package/dist/components/token-input/index.d.ts +1 -0
- package/dist/components/token-input/index.js +1 -0
- package/dist/components/tooltip/Tooltip.d.ts +17 -0
- package/dist/components/tooltip/Tooltip.js +144 -0
- package/dist/components/tooltip/index.d.ts +1 -0
- package/dist/components/tooltip/index.js +1 -0
- package/dist/components/tree-view/TreeView.d.ts +29 -0
- package/dist/components/tree-view/TreeView.js +140 -0
- package/dist/components/tree-view/index.d.ts +1 -0
- package/dist/components/tree-view/index.js +1 -0
- package/dist/components/unsaved-changes/index.d.ts +1 -0
- package/dist/components/unsaved-changes/index.js +1 -0
- package/dist/components/unsaved-changes/useUnsavedChanges.d.ts +12 -0
- package/dist/components/unsaved-changes/useUnsavedChanges.js +45 -0
- package/dist/components/usage-limit/UsageLimit.d.ts +15 -0
- package/dist/components/usage-limit/UsageLimit.js +21 -0
- package/dist/components/usage-limit/index.d.ts +1 -0
- package/dist/components/usage-limit/index.js +1 -0
- package/dist/components/web-search-results/WebSearchResults.d.ts +21 -0
- package/dist/components/web-search-results/WebSearchResults.js +17 -0
- package/dist/components/web-search-results/index.d.ts +1 -0
- package/dist/components/web-search-results/index.js +1 -0
- package/dist/lib/anchor.d.ts +21 -0
- package/dist/lib/anchor.js +50 -0
- package/dist/lib/cn.d.ts +1 -0
- package/dist/lib/cn.js +5 -0
- package/dist/lib/date.d.ts +77 -0
- package/dist/lib/date.js +165 -0
- package/dist/lib/icon-message.d.ts +16 -0
- package/dist/lib/icon-message.js +7 -0
- package/dist/lib/number.d.ts +1 -0
- package/dist/lib/number.js +5 -0
- package/dist/lib/slot.d.ts +8 -0
- package/dist/lib/slot.js +53 -0
- package/dist/lib/variant.d.ts +1 -0
- package/dist/lib/variant.js +1 -0
- package/docs/a11y.md +320 -0
- package/docs/chart/axis.md +82 -0
- package/docs/chart/color.md +120 -0
- package/docs/chart/drawing.md +283 -0
- package/docs/chart/reading.md +79 -0
- package/docs/chart/size-and-spacing.md +85 -0
- package/docs/chart.md +47 -0
- package/docs/color/contrast.md +80 -0
- package/docs/color/data-viz.md +66 -0
- package/docs/color/foundation.md +91 -0
- package/docs/color/neutral.md +88 -0
- package/docs/color/state.md +111 -0
- package/docs/color.md +22 -0
- package/docs/components/accordion.md +51 -0
- package/docs/components/agent-form.md +56 -0
- package/docs/components/agent-steps.md +75 -0
- package/docs/components/agent-thinking.md +70 -0
- package/docs/components/area-chart.md +55 -0
- package/docs/components/auth-card.md +126 -0
- package/docs/components/avatar.md +38 -0
- package/docs/components/badge.md +28 -0
- package/docs/components/banner.md +19 -0
- package/docs/components/bar-list.md +77 -0
- package/docs/components/button-group.md +74 -0
- package/docs/components/button.md +49 -0
- package/docs/components/calendar-view.md +106 -0
- package/docs/components/calendar.md +44 -0
- package/docs/components/carousel.md +81 -0
- package/docs/components/chart.md +45 -0
- package/docs/components/chat-message.md +199 -0
- package/docs/components/checkbox.md +27 -0
- package/docs/components/chip.md +34 -0
- package/docs/components/choosing.md +26 -0
- package/docs/components/close-button.md +17 -0
- package/docs/components/color-picker.md +52 -0
- package/docs/components/combo-chart.md +74 -0
- package/docs/components/combobox.md +60 -0
- package/docs/components/command-palette.md +151 -0
- package/docs/components/composer-attachments.md +116 -0
- package/docs/components/composer-panel.md +106 -0
- package/docs/components/composer.md +163 -0
- package/docs/components/contribution-chart.md +70 -0
- package/docs/components/data-grid.md +132 -0
- package/docs/components/data-table.md +165 -0
- package/docs/components/date-picker.md +120 -0
- package/docs/components/dialog.md +211 -0
- package/docs/components/drawer.md +38 -0
- package/docs/components/empty-state.md +17 -0
- package/docs/components/error-state.md +13 -0
- package/docs/components/error-summary.md +49 -0
- package/docs/components/field.md +84 -0
- package/docs/components/file-upload.md +161 -0
- package/docs/components/focus.md +25 -0
- package/docs/components/form-section.md +49 -0
- package/docs/components/form-steps.md +63 -0
- package/docs/components/funnel-chart.md +49 -0
- package/docs/components/heatmap-chart.md +64 -0
- package/docs/components/image-error.md +73 -0
- package/docs/components/image-loader.md +53 -0
- package/docs/components/input.md +21 -0
- package/docs/components/item-range.md +10 -0
- package/docs/components/link-button.md +16 -0
- package/docs/components/menu.md +115 -0
- package/docs/components/meter.md +83 -0
- package/docs/components/nav-group.md +33 -0
- package/docs/components/notification-center.md +100 -0
- package/docs/components/notification.md +127 -0
- package/docs/components/number-field.md +128 -0
- package/docs/components/otp-input.md +86 -0
- package/docs/components/pagination.md +29 -0
- package/docs/components/popover.md +43 -0
- package/docs/components/progress.md +25 -0
- package/docs/components/prohibitions.md +58 -0
- package/docs/components/props.md +20 -0
- package/docs/components/question-form.md +125 -0
- package/docs/components/radar-chart.md +61 -0
- package/docs/components/radial-chart.md +74 -0
- package/docs/components/radio.md +24 -0
- package/docs/components/reply-loader.md +80 -0
- package/docs/components/sankey-chart.md +71 -0
- package/docs/components/scatter-chart.md +61 -0
- package/docs/components/search-field.md +44 -0
- package/docs/components/segmented-control.md +35 -0
- package/docs/components/select.md +28 -0
- package/docs/components/separator.md +23 -0
- package/docs/components/settings-modal.md +128 -0
- package/docs/components/sidebar.md +145 -0
- package/docs/components/skeleton.md +27 -0
- package/docs/components/skip-link.md +17 -0
- package/docs/components/slider.md +82 -0
- package/docs/components/spinner.md +8 -0
- package/docs/components/stacked-bar.md +66 -0
- package/docs/components/stat-card.md +78 -0
- package/docs/components/switch.md +61 -0
- package/docs/components/table.md +43 -0
- package/docs/components/tabs.md +104 -0
- package/docs/components/tag-group.md +115 -0
- package/docs/components/task-list.md +99 -0
- package/docs/components/text-link.md +17 -0
- package/docs/components/textarea.md +27 -0
- package/docs/components/time-field.md +97 -0
- package/docs/components/toast.md +73 -0
- package/docs/components/token-input.md +135 -0
- package/docs/components/tooltip.md +41 -0
- package/docs/components/tree-view.md +71 -0
- package/docs/components/usage-limit.md +47 -0
- package/docs/components/web-search-results.md +60 -0
- package/docs/components.md +234 -0
- package/docs/design.md +31 -0
- package/docs/form/clearing-errors.md +28 -0
- package/docs/form/error-announcement.md +69 -0
- package/docs/form/long-forms.md +103 -0
- package/docs/form/placeholder.md +40 -0
- package/docs/form/submit-errors.md +102 -0
- package/docs/form/submitting.md +72 -0
- package/docs/form/unsaved-changes.md +146 -0
- package/docs/form/validation-timing.md +44 -0
- package/docs/form.md +39 -0
- package/docs/glossary.md +169 -0
- package/docs/icon.md +245 -0
- package/docs/interaction/before.md +64 -0
- package/docs/interaction/motion.md +38 -0
- package/docs/interaction/pending.md +38 -0
- package/docs/interaction/permissions.md +133 -0
- package/docs/interaction/result.md +38 -0
- package/docs/interaction/states.md +159 -0
- package/docs/interaction.md +31 -0
- package/docs/layout/alignment.md +145 -0
- package/docs/layout/hit-area.md +58 -0
- package/docs/layout/mobile.md +200 -0
- package/docs/layout/responsive.md +73 -0
- package/docs/layout/scroll.md +51 -0
- package/docs/layout/surface.md +110 -0
- package/docs/layout.md +31 -0
- package/docs/list/board.md +85 -0
- package/docs/list/paging.md +146 -0
- package/docs/list/search.md +98 -0
- package/docs/list/toolbar.md +91 -0
- package/docs/list.md +39 -0
- package/docs/log.md +94 -0
- package/docs/manual.md +152 -0
- package/docs/navigation/header-and-transition.md +82 -0
- package/docs/navigation/location.md +68 -0
- package/docs/navigation/menu-items.md +152 -0
- package/docs/navigation/menu-structure.md +68 -0
- package/docs/navigation.md +23 -0
- package/docs/rules.md +246 -0
- package/docs/scenario.md +218 -0
- package/docs/spacing/placement.md +219 -0
- package/docs/spacing/radius.md +45 -0
- package/docs/spacing/scale.md +91 -0
- package/docs/spacing.md +17 -0
- package/docs/typography.md +233 -0
- package/docs/writing/date-and-number.md +25 -0
- package/docs/writing/error-and-empty.md +58 -0
- package/docs/writing/label-and-button.md +124 -0
- package/docs/writing/tone.md +156 -0
- package/docs/writing.md +27 -0
- package/icons/index.d.ts +1 -0
- package/icons/index.js +3 -0
- package/package.json +115 -4
- package/scripts/lint/colors.mjs +103 -0
- package/scripts/lint/deps.mjs +33 -0
- package/scripts/lint/icons.mjs +177 -0
- package/scripts/lint/interaction.mjs +163 -0
- package/scripts/lint/layout.mjs +103 -0
- package/scripts/lint/markup.mjs +271 -0
- package/scripts/lint/shared.mjs +340 -0
- package/scripts/lint/spacing.mjs +70 -0
- package/scripts/lint/typography.mjs +141 -0
- package/scripts/lint/writing.mjs +107 -0
- package/scripts/lint.mjs +166 -0
- package/scripts/plain-ui-lint.mjs +33 -0
- package/tokens/tokens.css +482 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// マークアップの決まり(docs/a11y.md、docs/components/、docs/form/unsaved-changes.md、docs/chart/axis.md)。
|
|
2
|
+
// JSX の開きタグの名前と属性を読んで調べる。構文木は作らないので、属性の値が式のときは、値が文字で決まる形だけを見る。
|
|
3
|
+
// 調べるファイルは、ことわりのない限り、部品、ストーリー、見本のページのすべて(sets.code)。
|
|
4
|
+
// ストーリーも部品の使い方の見本なので、使う側と同じ決まりを守る
|
|
5
|
+
|
|
6
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { classes, consumer, jsxAttrs, jsxChildrenText, jsxLiteral, jsxTags, lineAt, read, root, sets, splitClass, strings, stripComments } from "./shared.mjs";
|
|
9
|
+
|
|
10
|
+
// 属性の値が文字か文字だけの式なら、その文字にする("number"、{"number"}、{1})
|
|
11
|
+
const literal = jsxLiteral;
|
|
12
|
+
// 属性の値が式なら、{ } の中の式を返す
|
|
13
|
+
const expression = value => (typeof value === "string" && value.startsWith("{") ? value.slice(1, -1).trim() : null);
|
|
14
|
+
|
|
15
|
+
// 小文字で始まる名前は HTML と SVG の要素、大文字で始まる名前は部品
|
|
16
|
+
const isIntrinsic = name => /^[a-z]/.test(name);
|
|
17
|
+
|
|
18
|
+
// 開きタグをすべて回し、fn が返した説明を、決まりから外れた所にする
|
|
19
|
+
const eachTag = (files, fn) =>
|
|
20
|
+
files.flatMap(file =>
|
|
21
|
+
jsxTags(file).flatMap(tag => {
|
|
22
|
+
const detail = fn(tag, jsxAttrs(tag.attrs), file);
|
|
23
|
+
return detail ? [{ file, line: tag.line, detail }] : [];
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// 式の中の、関数の本体を返す(e => e.preventDefault() の右側、function () { … } の中)。同じファイルの名前の付いた関数も引く
|
|
28
|
+
function handlerBody(text, expr) {
|
|
29
|
+
if (/=>|function\b/.test(expr)) return expr;
|
|
30
|
+
const name = expr.match(/^[A-Za-z_$][\w$]*$/)?.[0];
|
|
31
|
+
if (!name) return null;
|
|
32
|
+
// 名前の $ を、正規表現の記号と読まないように逃がす
|
|
33
|
+
const esc = name.replace(/\$/g, "\\$");
|
|
34
|
+
// const handlePaste: React.ClipboardEventHandler = e => { … } のように、型を付けた形も見る
|
|
35
|
+
const head = new RegExp(`(?:function\\s+${esc}\\s*\\(|(?:const|let|var)\\s+${esc}\\b[^=;]*=(?![=>]))`).exec(text);
|
|
36
|
+
if (!head) return null;
|
|
37
|
+
let open;
|
|
38
|
+
if (head[0].startsWith("function")) {
|
|
39
|
+
// 引数の ( ) を数えて閉じた後の {
|
|
40
|
+
let depth = 1;
|
|
41
|
+
let i = head.index + head[0].length;
|
|
42
|
+
for (; i < text.length && depth > 0; i++) {
|
|
43
|
+
if (text[i] === "(") depth++;
|
|
44
|
+
else if (text[i] === ")") depth--;
|
|
45
|
+
}
|
|
46
|
+
open = text.indexOf("{", i);
|
|
47
|
+
} else {
|
|
48
|
+
// => の後ろ。{ がなければ、式の本体(その行の終わりまで)を返す
|
|
49
|
+
const arrow = text.indexOf("=>", head.index + head[0].length);
|
|
50
|
+
if (arrow < 0) return null;
|
|
51
|
+
let k = arrow + 2;
|
|
52
|
+
while (/\s/.test(text[k] ?? "")) k++;
|
|
53
|
+
if (text[k] !== "{") {
|
|
54
|
+
const end = text.indexOf("\n", k);
|
|
55
|
+
return text.slice(head.index, end < 0 ? text.length : end);
|
|
56
|
+
}
|
|
57
|
+
open = k;
|
|
58
|
+
}
|
|
59
|
+
if (open < 0) return null;
|
|
60
|
+
let depth = 0;
|
|
61
|
+
for (let i = open; i < text.length; i++) {
|
|
62
|
+
if (text[i] === "{") depth++;
|
|
63
|
+
else if (text[i] === "}" && --depth === 0) return text.slice(head.index, i + 1);
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 見本のページと Storybook の HTML(viewport の設定を書く所)。テストの fixture は入れない。使う側では、調べるフォルダの中の HTML
|
|
69
|
+
const htmlFiles = consumer
|
|
70
|
+
? sets.html
|
|
71
|
+
: [
|
|
72
|
+
...readdirSync(join(root, "playground"), { withFileTypes: true })
|
|
73
|
+
.filter(e => e.isDirectory())
|
|
74
|
+
.map(e => join(root, "playground", e.name, "index.html")),
|
|
75
|
+
...(existsSync(join(root, ".storybook")) ? readdirSync(join(root, ".storybook")).filter(n => n.endsWith(".html")).map(n => join(root, ".storybook", n)) : []),
|
|
76
|
+
].filter(existsSync);
|
|
77
|
+
|
|
78
|
+
// グラフの部品のファイル(components/chart/ と components/<名前>-chart/)
|
|
79
|
+
const chartFiles = sets.components.filter(p => /\/components\/(chart|[\w-]+-chart)\//.test(p));
|
|
80
|
+
|
|
81
|
+
// 項目の軸の名前を回す書き方:rotate の変形、rotate の属性、縦書き
|
|
82
|
+
const rotates = value => typeof value === "string" && /rotate\s*\(|\brotate[XYZ]?\s*:|writing-?mode|writingMode|vertical-(?:rl|lr)/i.test(value);
|
|
83
|
+
const rotateClass = value =>
|
|
84
|
+
typeof value === "string" &&
|
|
85
|
+
value.split(/[\s"'`]+/).some(token => {
|
|
86
|
+
const { utility } = splitClass(token);
|
|
87
|
+
return /^rotate-(?!0$)|^\[writing-mode:vertical/.test(utility);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export const rules = [
|
|
91
|
+
{
|
|
92
|
+
// アイコンだけのボタンに、読み上げの名前(aria-label か aria-labelledby)がある。
|
|
93
|
+
// アイコンだけのボタンは、次の2つの形で見つける。
|
|
94
|
+
// a. Button と LinkButton の size が "icon" か "icon-sm"(docs/components.md:アイコンだけのボタンは size="icon")
|
|
95
|
+
// b. button、Button、LinkButton、a の中身が、アイコン(〜Icon か svg)の要素だけで、文字も式もない
|
|
96
|
+
// 名前のないボタンでも、{...props} を広げているものは、名前が呼ぶ側から渡るので除く。
|
|
97
|
+
// 中に、見えない文字(sr-only)で名前を書いたものも、読み上げの名前があるので除く
|
|
98
|
+
id: "A11Y-007",
|
|
99
|
+
check: () =>
|
|
100
|
+
eachTag(sets.code, (tag, attrs, file) => {
|
|
101
|
+
if (!["button", "Button", "LinkButton"].includes(tag.name)) return null;
|
|
102
|
+
if (attrs.has("aria-label") || attrs.has("aria-labelledby")) return null;
|
|
103
|
+
if (/\{\s*\.\.\./.test(tag.attrs)) return null;
|
|
104
|
+
const size = literal(attrs.get("size"));
|
|
105
|
+
const byAttr = tag.name !== "button" && (size === "icon" || size === "icon-sm");
|
|
106
|
+
const text = read(file);
|
|
107
|
+
const close = text.indexOf(`</${tag.name}>`, tag.end);
|
|
108
|
+
const inner = close < 0 || text[tag.end - 1] === "/" ? "" : stripComments(text).slice(tag.end + 1, close);
|
|
109
|
+
if (/sr-only/.test(inner)) return null;
|
|
110
|
+
const byContent = inner.trim() !== "" && /^(?:\s*(?:<[A-Z]\w*Icon\b[^<>]*\/>|<svg\b[\s\S]*?<\/svg>))+\s*$/.test(inner);
|
|
111
|
+
if (!byAttr && !byContent) return null;
|
|
112
|
+
const hasText = byAttr && (jsxChildrenText(file, tag) ?? "") !== "";
|
|
113
|
+
return hasText ? null : `<${tag.name}${size ? ` size="${size}"` : ""}>:アイコンだけのボタンに、aria-label で名前を付ける`;
|
|
114
|
+
}),
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
// tabIndex={2}、tabIndex="1"、cond ? 1 : -1 の正の数。要素の .tabIndex = 1 と setAttribute("tabindex", "1") も見る
|
|
118
|
+
id: "A11Y-004",
|
|
119
|
+
check: () => {
|
|
120
|
+
const positive = n => n !== undefined && /^\d+$/.test(n) && Number(n) > 0;
|
|
121
|
+
const fromTags = eachTag(sets.code, (tag, attrs) => {
|
|
122
|
+
const raw = attrs.get("tabIndex") ?? attrs.get("tabindex");
|
|
123
|
+
const value = literal(raw) ?? expression(raw);
|
|
124
|
+
if (typeof value !== "string") return null;
|
|
125
|
+
const ternary = value.match(/\?\s*(-?\d+)\s*:\s*(-?\d+)\s*$/);
|
|
126
|
+
const values = ternary ? [ternary[1], ternary[2]] : [value.trim()];
|
|
127
|
+
return values.some(positive) ? `<${tag.name} tabIndex={${value}}>:正の tabIndex で移動の順を変えない` : null;
|
|
128
|
+
});
|
|
129
|
+
const fromCode = sets.code.flatMap(file => {
|
|
130
|
+
const text = stripComments(read(file));
|
|
131
|
+
return [...text.matchAll(/\.tabIndex\s*=\s*([1-9]\d*)\b|setAttribute\(\s*["']tabindex["']\s*,\s*["']?([1-9]\d*)/g)].map(m => ({
|
|
132
|
+
file,
|
|
133
|
+
line: lineAt(text, m.index),
|
|
134
|
+
detail: `${m[0]}:正の tabIndex で移動の順を変えない`,
|
|
135
|
+
}));
|
|
136
|
+
});
|
|
137
|
+
return [...fromTags, ...fromCode];
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
// onPaste と addEventListener("paste") の処理が、preventDefault() で貼り付けを止め、貼り付けた文字(clipboardData)を読まないもの。
|
|
142
|
+
// TokenInput のように、貼り付けた文字を読んで自分で入れる処理は、貼り付けを禁止していないので除く
|
|
143
|
+
id: "A11Y-012",
|
|
144
|
+
check: () =>
|
|
145
|
+
sets.code.flatMap(file => {
|
|
146
|
+
const text = stripComments(read(file));
|
|
147
|
+
const blocks = body => body && /preventDefault\s*\(|return\s+false\b/.test(body) && !/clipboardData|getData\s*\(/.test(body);
|
|
148
|
+
const found = eachTag([file], (tag, attrs) => {
|
|
149
|
+
const value = expression(attrs.get("onPaste"));
|
|
150
|
+
return typeof value === "string" && blocks(handlerBody(text, value)) ? `<${tag.name} onPaste={${value}}>:貼り付けを禁止しない` : null;
|
|
151
|
+
});
|
|
152
|
+
for (const m of text.matchAll(/addEventListener\(\s*["']paste["']\s*,\s*([^,)]+(?:\([^)]*\)\s*=>[^)]*\))?)/g)) {
|
|
153
|
+
const expr = m[1].trim();
|
|
154
|
+
if (blocks(handlerBody(text, expr))) found.push({ file, line: lineAt(text, m.index), detail: `addEventListener("paste", …):貼り付けを禁止しない` });
|
|
155
|
+
}
|
|
156
|
+
return found;
|
|
157
|
+
}),
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
// viewport の設定の user-scalable=no(0)と maximum-scale=1 以下。HTML(見本のページと Storybook)と、コードの文字列を見る
|
|
161
|
+
id: "A11Y-014",
|
|
162
|
+
check: () => {
|
|
163
|
+
const bad = /user-scalable\s*=\s*(?:no|0)\b|maximum-scale\s*=\s*(?:0*\.\d+|0*1(?:\.0*)?)(?![\d.])/i;
|
|
164
|
+
const fromHtml = htmlFiles.flatMap(file =>
|
|
165
|
+
read(file)
|
|
166
|
+
.split("\n")
|
|
167
|
+
.flatMap((line, i) => (/name=["']viewport["']/i.test(line) && bad.test(line) ? [{ file, line: i + 1, detail: `${line.match(bad)[0]}:拡大を禁止しない` }] : [])),
|
|
168
|
+
);
|
|
169
|
+
const fromCode = sets.code.flatMap(file => strings(file).flatMap(({ value, line }) => (bad.test(value) ? [{ file, line, detail: `${value.match(bad)[0]}:拡大を禁止しない` }] : [])));
|
|
170
|
+
return [...fromHtml, ...fromCode];
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
// ボタンの役割を持たない要素(div、span と、それに近い入れ物)に onClick を付けたもの。button と a 以外の要素に role="button" を付けたもの。
|
|
175
|
+
// 次の onClick は、ボタンの代わりではないので除く:
|
|
176
|
+
// - role の付いた要素(listbox の option など):WAI-ARIA のパターンどおり、キーボードの操作を入れ物の側で作っている
|
|
177
|
+
// - 押された要素を event.target で調べる処理:中のリンクの押下を、入れ物でまとめて受けている(Drawer の中の nav など)
|
|
178
|
+
id: "COMPONENTS-002",
|
|
179
|
+
check: () => {
|
|
180
|
+
const containers = new Set(["div", "span", "p", "li", "section", "article", "td", "th", "tr", "img"]);
|
|
181
|
+
return eachTag(sets.code, (tag, attrs) => {
|
|
182
|
+
if (!isIntrinsic(tag.name)) return null;
|
|
183
|
+
const role = literal(attrs.get("role"));
|
|
184
|
+
const onClick = attrs.get("onClick");
|
|
185
|
+
if (containers.has(tag.name) && onClick !== undefined && (!attrs.has("role") || role === "button") && !/\.target\b/.test(String(onClick)))
|
|
186
|
+
return `<${tag.name} onClick>:div をボタンにしない。Button を使う`;
|
|
187
|
+
if (literal(attrs.get("role")) === "button" && tag.name !== "button") return `<${tag.name} role="button">:div をボタンにしない。Button を使う`;
|
|
188
|
+
return null;
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
// 1行おきに背景の色を変えるクラス(odd:bg-*、even:bg-*、[&:nth-child(even)]:bg-* など)と、CSS の :nth-child(odd/even/2n) の背景。
|
|
194
|
+
// クラスの文字列からは表の行かを見分けられないので、1行おきの背景の色はすべて見る
|
|
195
|
+
id: "COMPONENTS-018",
|
|
196
|
+
check: () => {
|
|
197
|
+
const striped = v => /^(?:odd|even|nth-|\*:odd|\*:even)|nth-(?:child|of-type)\((?:odd|even|2n)/.test(v);
|
|
198
|
+
const fromClasses = sets.code.flatMap(file =>
|
|
199
|
+
classes(file).flatMap(({ token, line }) => {
|
|
200
|
+
const { variants, utility } = splitClass(token);
|
|
201
|
+
return /^bg-/.test(utility) && variants.some(striped) ? [{ file, line, detail: `${token}:表に縞模様を付けない。行の区切りは border-b の線で示す` }] : [];
|
|
202
|
+
}),
|
|
203
|
+
);
|
|
204
|
+
const fromCss = sets.css.flatMap(file => {
|
|
205
|
+
const text = read(file);
|
|
206
|
+
return [...text.matchAll(/([^{}]*:nth-(?:child|of-type)\(\s*(?:odd|even|2n[^)]*)\)[^{}]*)\{([^}]*)\}/g)]
|
|
207
|
+
.filter(m => /background/.test(m[2]))
|
|
208
|
+
.map(m => ({ file, line: lineAt(text, m.index + m[0].indexOf(":nth-")), detail: `${m[1].trim()}:表に縞模様を付けない` }));
|
|
209
|
+
});
|
|
210
|
+
// 行の番号の偶奇で bg-* を切り替える式(i % 2 === 0 ? "bg-muted" : "")。同じ行に % 2 と bg-* の文字列があるもの
|
|
211
|
+
const fromParity = sets.code.flatMap(file =>
|
|
212
|
+
stripComments(read(file))
|
|
213
|
+
.split("\n")
|
|
214
|
+
.flatMap((text, i) => (/%\s*2\b.*["'`][^"'`]*(?<![\w-])bg-/.test(text) ? [{ file, line: i + 1, detail: `${text.trim()}:表に縞模様を付けない` }] : [])),
|
|
215
|
+
);
|
|
216
|
+
return [...fromClasses, ...fromCss, ...fromParity];
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
// <dialog> でない HTML の要素に、role="dialog" か role="alertdialog" を付けたもの。
|
|
221
|
+
// popover の属性を持つ要素は除く:Popover API で開く、モーダルでない小さな面で、docs/components/popover.md が role="dialog" を付けると決めている
|
|
222
|
+
id: "COMPONENTS-020",
|
|
223
|
+
check: () =>
|
|
224
|
+
eachTag(sets.code, (tag, attrs) => {
|
|
225
|
+
const role = literal(attrs.get("role"));
|
|
226
|
+
if (!isIntrinsic(tag.name) || tag.name === "dialog" || !/^(?:alert)?dialog$/.test(role ?? "")) return null;
|
|
227
|
+
if (attrs.has("popover")) return null;
|
|
228
|
+
return `<${tag.name} role="${role}">:div でダイアログを作らない。<dialog> を showModal() で開く`;
|
|
229
|
+
}),
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
// type="number" の入力欄(<input> と、属性を input に渡す部品)
|
|
233
|
+
id: "COMPONENTS-029",
|
|
234
|
+
check: () =>
|
|
235
|
+
eachTag(sets.code, (tag, attrs) =>
|
|
236
|
+
literal(attrs.get("type")) === "number" && (tag.name === "input" || /Input$|Field$/.test(tag.name)) ? `<${tag.name} type="number">:量を入れる欄は NumberField を使う` : null,
|
|
237
|
+
),
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
// window.confirm(…) と、同じファイルに confirm という名前の関数がないときの confirm(…)。globalThis.confirm と self.confirm も見る
|
|
241
|
+
id: "FORM-014",
|
|
242
|
+
check: () =>
|
|
243
|
+
sets.code.flatMap(file => {
|
|
244
|
+
const text = stripComments(read(file));
|
|
245
|
+
// 同じファイルで confirm という名前を決めているか:宣言、分割代入、引数((confirm) => …、function f(confirm))
|
|
246
|
+
const local = /(?:function\s+confirm\b|(?:const|let|var)\s+confirm\b|[{,]\s*confirm\s*[,}:]|[(,]\s*confirm\s*[,):=])/.test(text);
|
|
247
|
+
return [...text.matchAll(/(?:\b(?:window|globalThis|self)\s*\.\s*|(?<![\w$.]))confirm\s*\(/g)]
|
|
248
|
+
.filter(m => !(local && !/\./.test(m[0])))
|
|
249
|
+
.filter(m => !/function\s+$/.test(text.slice(Math.max(0, m.index - 20), m.index)))
|
|
250
|
+
.map(m => ({ file, line: lineAt(text, m.index), detail: `${m[0].replace(/\s+/g, "")}…):移動の確認は confirmLeave で出す` }));
|
|
251
|
+
}),
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
// 文字の要素(<text>、<tspan>)を回すもの:transform の rotate(…)、rotate の属性、style の rotate と縦書き、rotate-* のクラス。
|
|
255
|
+
// グラフの部品(components/chart/ と components/*-chart/)では、ほかの HTML の要素に付けた rotate も見る(HTML で書いた軸の名前)。
|
|
256
|
+
// 模様の patternTransform="rotate(45)" は、文字ではないので見ない
|
|
257
|
+
id: "CHART-006",
|
|
258
|
+
check: () =>
|
|
259
|
+
eachTag(sets.code, (tag, attrs, file) => {
|
|
260
|
+
const isText = tag.name === "text" || tag.name === "tspan";
|
|
261
|
+
if (!isText && !(chartFiles.includes(file) && isIntrinsic(tag.name) && tag.name !== "pattern")) return null;
|
|
262
|
+
const hit =
|
|
263
|
+
rotates(attrs.get("transform")) ||
|
|
264
|
+
(isText && attrs.has("rotate")) ||
|
|
265
|
+
rotates(attrs.get("style")) ||
|
|
266
|
+
rotateClass(attrs.get("className")) ||
|
|
267
|
+
rotateClass(attrs.get("class"));
|
|
268
|
+
return hit ? `<${tag.name}> を回している:項目の軸の名前を斜めにしない。間引きと切り詰めにする` : null;
|
|
269
|
+
}),
|
|
270
|
+
},
|
|
271
|
+
];
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// リント(scripts/lint.mjs)の分野ごとのルールが使う、共通の道具。
|
|
2
|
+
// 依存パッケージを使わず、Node.js に入っているモジュールだけで読む(RULES-004)。
|
|
3
|
+
// ソースの構文木は作らず、文字列とクラスの並びを、行の番号つきで取り出して調べる。
|
|
4
|
+
|
|
5
|
+
import { readFileSync, readdirSync, existsSync, statSync } from "node:fs";
|
|
6
|
+
import { basename, dirname, join, relative } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
// パッケージの場所。決まりのドキュメント(docs/)と tokens/tokens.css は、ここから読む
|
|
10
|
+
export const packageRoot = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
11
|
+
// 使う側のプロジェクトを調べるとき(scripts/plain-ui-lint.mjs)は、調べるフォルダの一覧が PLAIN_UI_LINT_TARGETS に入る
|
|
12
|
+
const targets = process.env.PLAIN_UI_LINT_TARGETS ? JSON.parse(process.env.PLAIN_UI_LINT_TARGETS) : null;
|
|
13
|
+
export const consumer = targets !== null;
|
|
14
|
+
// 調べるコードの場所。package.json もここから読む。使う側では、コマンドを実行したフォルダにする
|
|
15
|
+
export const root = consumer ? process.cwd() : packageRoot;
|
|
16
|
+
export const rel = path => relative(root, path);
|
|
17
|
+
|
|
18
|
+
// 使う側では、ビルドの出力と、. で始まるフォルダ(.git、.next など)も読まない
|
|
19
|
+
const skipped = name => ["node_modules", "dist", "storybook-static"].includes(name) || (consumer && (["build", "out", "coverage"].includes(name) || name.startsWith(".")));
|
|
20
|
+
function walk(dir, test) {
|
|
21
|
+
if (!existsSync(dir)) return [];
|
|
22
|
+
if (!statSync(dir).isDirectory()) return test(basename(dir)) ? [dir] : [];
|
|
23
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap(entry => {
|
|
24
|
+
const path = join(dir, entry.name);
|
|
25
|
+
if (entry.isDirectory()) return skipped(entry.name) ? [] : walk(path, test);
|
|
26
|
+
return test(entry.name) ? [path] : [];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 使う側では、.js と .jsx のコードも読む。設定のファイル(vite.config.ts など)は、画面を描くコードではないので読まない
|
|
31
|
+
const isSource = name =>
|
|
32
|
+
(consumer ? /\.(tsx?|jsx?|mjs)$/.test(name) && !/\.config\.[cm]?[jt]s$/.test(name) : /\.(tsx?|mjs)$/.test(name)) && !name.endsWith(".d.ts");
|
|
33
|
+
const isTest = path => (consumer ? /\.(test|spec)\.[jt]sx?$/ : /\.test\.tsx?$/).test(path);
|
|
34
|
+
const isStory = path => (consumer ? /\.stories\.[jt]sx?$/ : /\.stories\.tsx?$/).test(path);
|
|
35
|
+
|
|
36
|
+
// 使う側の組。部品の本体はないので、ストーリーのほかは、すべて画面を描くコードとして調べる
|
|
37
|
+
function consumerSets() {
|
|
38
|
+
const files = targets.flatMap(dir => walk(dir, name => isSource(name) || name.endsWith(".css") || name.endsWith(".html")));
|
|
39
|
+
const code = files.filter(p => isSource(basename(p)) && !isTest(p));
|
|
40
|
+
return {
|
|
41
|
+
components: [],
|
|
42
|
+
stories: code.filter(isStory),
|
|
43
|
+
playground: code.filter(p => !isStory(p)),
|
|
44
|
+
css: files.filter(p => p.endsWith(".css")),
|
|
45
|
+
html: files.filter(p => p.endsWith(".html")),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 調べるファイルの組。テストは、わざと決まりから外れた形を描いて確かめることがあるので、どの組にも入れない
|
|
50
|
+
export const sets = consumer
|
|
51
|
+
? consumerSets()
|
|
52
|
+
: {
|
|
53
|
+
// 部品の本体(components/ と lib/)。配る部品なので、決まりをいちばん強く守る
|
|
54
|
+
components: [...walk(join(root, "components"), isSource), ...walk(join(root, "lib"), isSource)].filter(p => !isTest(p) && !isStory(p)),
|
|
55
|
+
// ストーリー。部品の使い方の見本なので、使う側と同じ決まりを守る
|
|
56
|
+
stories: [...walk(join(root, "components"), isSource), ...walk(join(root, "playground"), isSource)].filter(isStory),
|
|
57
|
+
// 見本のページ(playground/*/src)
|
|
58
|
+
playground: walk(join(root, "playground"), isSource).filter(p => /\/src\//.test(p) && !isTest(p)),
|
|
59
|
+
// CSS(部品のスタイルと、見本のページと Storybook のスタイル)。tokens.css は生成物なので入れない
|
|
60
|
+
css: [...walk(join(root, "playground"), n => n.endsWith(".css")), ...walk(join(root, ".storybook"), n => n.endsWith(".css")), ...walk(join(root, "components"), n => n.endsWith(".css"))],
|
|
61
|
+
};
|
|
62
|
+
// 画面を描くコードのすべて(部品、ストーリー、見本のページ)
|
|
63
|
+
sets.code = [...sets.components, ...sets.stories, ...sets.playground];
|
|
64
|
+
|
|
65
|
+
const textCache = new Map();
|
|
66
|
+
export function read(path) {
|
|
67
|
+
if (!textCache.has(path)) textCache.set(path, readFileSync(path, "utf8"));
|
|
68
|
+
return textCache.get(path);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 位置(文字の番号)から行の番号(1から)を返す
|
|
72
|
+
export function lineAt(text, index) {
|
|
73
|
+
let line = 1;
|
|
74
|
+
for (let i = 0; i < index; i++) if (text.charCodeAt(i) === 10) line++;
|
|
75
|
+
return line;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// コメントを、同じ長さの空白に置き換える(行の番号を変えない)。文字列の中の // や /* は残す。
|
|
79
|
+
// ' と " の文字列は、改行で終える。JSX の文の中の「Don't」や、正規表現の中の引用符を文字列の始まりと読んでも、
|
|
80
|
+
// 読み違いをその行だけにとどめる(` のテンプレートは、改行をまたげる)
|
|
81
|
+
export function stripComments(text) {
|
|
82
|
+
let out = "";
|
|
83
|
+
let i = 0;
|
|
84
|
+
let quote = null;
|
|
85
|
+
while (i < text.length) {
|
|
86
|
+
const c = text[i];
|
|
87
|
+
const next = text[i + 1];
|
|
88
|
+
if (quote) {
|
|
89
|
+
out += c;
|
|
90
|
+
if (c === "\\") {
|
|
91
|
+
out += next ?? "";
|
|
92
|
+
i += 2;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (c === quote || (c === "\n" && quote !== "`")) quote = null;
|
|
96
|
+
i++;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
100
|
+
quote = c;
|
|
101
|
+
out += c;
|
|
102
|
+
i++;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (c === "/" && next === "/") {
|
|
106
|
+
while (i < text.length && text[i] !== "\n") {
|
|
107
|
+
out += " ";
|
|
108
|
+
i++;
|
|
109
|
+
}
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (c === "/" && next === "*") {
|
|
113
|
+
const end = text.indexOf("*/", i + 2);
|
|
114
|
+
const stop = end < 0 ? text.length : end + 2;
|
|
115
|
+
for (; i < stop; i++) out += text[i] === "\n" ? "\n" : " ";
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
out += c;
|
|
119
|
+
i++;
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 文字列の値を、行の番号つきで返す("…"、'…'、`…` の固定の部分)。コメントの中は見ない。
|
|
125
|
+
// テンプレートの ${…} の中は、空白に置き換えて、前後の固定の部分だけを1つの文字列として返す。
|
|
126
|
+
// index は、ファイルの中の開きの引用符の位置(文字の番号)。jsxTags の index と end と比べて、どの要素の中かを調べられる
|
|
127
|
+
export function strings(path) {
|
|
128
|
+
const text = stripComments(read(path));
|
|
129
|
+
const result = [];
|
|
130
|
+
const re = /"((?:[^"\\\n]|\\.)*)"|'((?:[^'\\\n]|\\.)*)'|`((?:[^`\\]|\\.)*)`/gs;
|
|
131
|
+
for (const m of text.matchAll(re)) {
|
|
132
|
+
const value = (m[1] ?? m[2] ?? m[3]).replace(/\$\{[^}]*\}/g, " ");
|
|
133
|
+
result.push({ value, line: lineAt(text, m.index), quote: m[0][0], index: m.index });
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Tailwind のクラスの形の語を、行の番号つきで返す。文字列を空白で区切り、クラスの形のものだけを残す。
|
|
139
|
+
// 画面の文言のような、クラスでない文字列も混ざるので、各ルールは、決まった形(bg-blue-500 など)だけを探す。
|
|
140
|
+
// 既定では、- も : も [ もない語(italic、uppercase など)は、英語の文言と見分けられないので返さない。
|
|
141
|
+
// そうした語を名指しで探すルールは、{ bare: true } で、その語も返させる。
|
|
142
|
+
// そのときも、- のない語は、クラスを書く場所(className の値と、cn、clsx、cva、twMerge の引数)の中の文字列だけから返す。
|
|
143
|
+
// 説明の文(description="Use rounded corners")の英語の語を、クラスと読まないため。変数に入れたクラスの - のない語は見ない
|
|
144
|
+
function classSites(text) {
|
|
145
|
+
const sites = [];
|
|
146
|
+
for (const m of text.matchAll(/\bclassName\s*=\s*|\b(?:cn|clsx|cva|twMerge)\s*\(/g)) {
|
|
147
|
+
let i = m.index + m[0].length;
|
|
148
|
+
const open = m[0].endsWith("(") ? "(" : text[i];
|
|
149
|
+
if (open === '"' || open === "'") {
|
|
150
|
+
const end = text.indexOf(open, i + 1);
|
|
151
|
+
sites.push([i, end < 0 ? i : end]);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const close = open === "(" ? ")" : open === "{" ? "}" : null;
|
|
155
|
+
if (!close) continue;
|
|
156
|
+
if (open === "{") i++;
|
|
157
|
+
let depth = 1;
|
|
158
|
+
let quote = null;
|
|
159
|
+
const start = i;
|
|
160
|
+
for (; i < text.length && depth > 0; i++) {
|
|
161
|
+
const c = text[i];
|
|
162
|
+
if (quote) {
|
|
163
|
+
if (c === "\\") i++;
|
|
164
|
+
else if (c === quote) quote = null;
|
|
165
|
+
} else if (c === '"' || c === "'" || c === "`") quote = c;
|
|
166
|
+
else if (c === open) depth++;
|
|
167
|
+
else if (c === close) depth--;
|
|
168
|
+
}
|
|
169
|
+
sites.push([start, i]);
|
|
170
|
+
}
|
|
171
|
+
return sites;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const classShape = /^!?-?(?:[a-z0-9@*[\]]+[a-z0-9@*[\]().%#/_,='"&>~+-]*:)*!?-?[a-z@[][a-z0-9[\]().%#/_,:='"&>~+-]*$/;
|
|
175
|
+
export function classes(path, { bare = false } = {}) {
|
|
176
|
+
const result = [];
|
|
177
|
+
const sites = bare ? classSites(stripComments(read(path))) : [];
|
|
178
|
+
for (const { value, line, index } of strings(path)) {
|
|
179
|
+
const inSite = bare && sites.some(([a, b]) => index >= a && index <= b);
|
|
180
|
+
for (const token of value.split(/\s+/)) {
|
|
181
|
+
if (!token || !classShape.test(token)) continue;
|
|
182
|
+
if (/[-:[]/.test(token) || inSite) result.push({ token, line });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// クラスを、条件(hover:、md: など)と本体に分ける。[&_svg]:size-4、supports-[display:grid]:grid のような角括弧の条件も1つの条件として扱う。
|
|
189
|
+
// has-[input:focus-visible]: や has-[input[aria-invalid=true]]: のような、名前の後ろの角括弧(1段の入れ子まで)も条件に含める。
|
|
190
|
+
// text-(length:--x) のような丸括弧の中の : は、条件の区切りではない
|
|
191
|
+
export function splitClass(token) {
|
|
192
|
+
const variants = [];
|
|
193
|
+
let rest = token;
|
|
194
|
+
for (;;) {
|
|
195
|
+
const m = rest.match(/^((?:\[(?:[^[\]]|\[[^\]]*\])*\]|\([^)]*\)|[^:[\]()])+):(.*)$/);
|
|
196
|
+
if (!m) break;
|
|
197
|
+
variants.push(m[1]);
|
|
198
|
+
rest = m[2];
|
|
199
|
+
}
|
|
200
|
+
const important = rest.startsWith("!");
|
|
201
|
+
if (important) rest = rest.slice(1);
|
|
202
|
+
const negative = rest.startsWith("-");
|
|
203
|
+
if (negative) rest = rest.slice(1);
|
|
204
|
+
return { variants, utility: rest, important, negative };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// JSX の要素の開きタグを、行の番号つきで返す(<div className="…" onClick={…}> の名前と属性の文字列)。
|
|
208
|
+
// 属性の中の { } は入れ子を数えて読み飛ばす。完全な構文解析ではないので、ルールは名前と属性の有無だけを見る。
|
|
209
|
+
// index は < の位置、end は閉じの > の位置(文字の番号)
|
|
210
|
+
export function jsxTags(path) {
|
|
211
|
+
const text = stripComments(read(path));
|
|
212
|
+
const result = [];
|
|
213
|
+
const re = /<([A-Za-z][\w.]*)(?=[\s/>])/g;
|
|
214
|
+
for (const m of text.matchAll(re)) {
|
|
215
|
+
// 型の引数(Array<string>)や比較(a < b)を除く:直前が識別子なら JSX ではない
|
|
216
|
+
const before = text.slice(Math.max(0, m.index - 1), m.index);
|
|
217
|
+
if (/[\w)\]]/.test(before)) continue;
|
|
218
|
+
let i = m.index + m[0].length;
|
|
219
|
+
let depth = 0;
|
|
220
|
+
let quote = null;
|
|
221
|
+
for (; i < text.length; i++) {
|
|
222
|
+
const c = text[i];
|
|
223
|
+
if (quote) {
|
|
224
|
+
if (c === "\\") i++;
|
|
225
|
+
else if (c === quote || (c === "\n" && quote !== "`")) quote = null;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (c === '"' || c === "'" || c === "`") quote = c;
|
|
229
|
+
else if (c === "{") depth++;
|
|
230
|
+
else if (c === "}") depth--;
|
|
231
|
+
else if (c === ">" && depth === 0) break;
|
|
232
|
+
}
|
|
233
|
+
// index は < の位置、end は開きタグを閉じる > の位置(コメントを空白にした文字列の上の位置。read(path) と同じ位置になる)
|
|
234
|
+
result.push({ name: m[1], attrs: text.slice(m.index + m[0].length, i), line: lineAt(text, m.index), index: m.index, end: i });
|
|
235
|
+
}
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 開きタグの属性の文字列(jsxTags の attrs)を、名前 -> 値の Map にする。値は、"…" と '…' なら中の文字、
|
|
240
|
+
// {…} なら { } ごとの式(入れ子を数える)、値のない属性(disabled)なら true。{...props} は読み飛ばす。
|
|
241
|
+
// 値が文字だけの式({"number"})かを知るには、jsxLiteral を使う
|
|
242
|
+
export function jsxAttrs(attrs) {
|
|
243
|
+
const result = new Map();
|
|
244
|
+
let i = 0;
|
|
245
|
+
// { … } の終わりの位置を返す。中の文字列の { } は数えない
|
|
246
|
+
const skipBraces = from => {
|
|
247
|
+
let d = 0;
|
|
248
|
+
let quote = null;
|
|
249
|
+
for (let j = from; j < attrs.length; j++) {
|
|
250
|
+
const c = attrs[j];
|
|
251
|
+
if (quote) {
|
|
252
|
+
if (c === "\\") j++;
|
|
253
|
+
else if (c === quote) quote = null;
|
|
254
|
+
} else if (c === '"' || c === "'" || c === "`") quote = c;
|
|
255
|
+
else if (c === "{") d++;
|
|
256
|
+
else if (c === "}" && --d === 0) return j;
|
|
257
|
+
}
|
|
258
|
+
return attrs.length;
|
|
259
|
+
};
|
|
260
|
+
while (i < attrs.length) {
|
|
261
|
+
const c = attrs[i];
|
|
262
|
+
if (/[\s/]/.test(c)) {
|
|
263
|
+
i++;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (c === "{") {
|
|
267
|
+
i = skipBraces(i) + 1;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const m = attrs.slice(i).match(/^[\w:.-]+/);
|
|
271
|
+
if (!m) {
|
|
272
|
+
i++;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const key = m[0];
|
|
276
|
+
i += key.length;
|
|
277
|
+
while (/\s/.test(attrs[i] ?? "")) i++;
|
|
278
|
+
if (attrs[i] !== "=") {
|
|
279
|
+
result.set(key, true);
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
i++;
|
|
283
|
+
while (/\s/.test(attrs[i] ?? "")) i++;
|
|
284
|
+
const q = attrs[i];
|
|
285
|
+
if (q === '"' || q === "'") {
|
|
286
|
+
const close = attrs.indexOf(q, i + 1);
|
|
287
|
+
result.set(key, attrs.slice(i + 1, close < 0 ? attrs.length : close));
|
|
288
|
+
i = close < 0 ? attrs.length : close + 1;
|
|
289
|
+
} else if (q === "{") {
|
|
290
|
+
const close = skipBraces(i);
|
|
291
|
+
result.set(key, `{${attrs.slice(i + 1, close).trim()}}`);
|
|
292
|
+
i = close + 1;
|
|
293
|
+
} else i++;
|
|
294
|
+
}
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// 属性の値が文字("…")か、文字だけの式({"…"}、{`…`}、{1})なら、その文字を返す。ほかの式と値のない属性は null
|
|
299
|
+
export function jsxLiteral(value) {
|
|
300
|
+
if (typeof value !== "string") return null;
|
|
301
|
+
if (!value.startsWith("{")) return value;
|
|
302
|
+
const inner = value.slice(1, -1).trim();
|
|
303
|
+
const m = inner.match(/^(["'`])((?:(?!\1)[^\\$]|\\.)*)\1$/s) ?? inner.match(/^()(-?\d+(?:\.\d+)?)$/);
|
|
304
|
+
return m ? m[2] : null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// 要素の中の文言を返す(開きタグの後から、同じ名前の閉じタグまで)。中のタグは消し、{"…"} の文字列は中の文字にし、
|
|
308
|
+
// ほかの {…} の式は消す。自分で閉じるタグ(<Button />)は null。入れ子の同じ名前の要素は数えない
|
|
309
|
+
export function jsxChildrenText(path, tag) {
|
|
310
|
+
const text = stripComments(read(path));
|
|
311
|
+
if (text[tag.end - 1] === "/") return null;
|
|
312
|
+
const close = text.indexOf(`</${tag.name}>`, tag.end);
|
|
313
|
+
if (close < 0) return null;
|
|
314
|
+
let inner = text
|
|
315
|
+
.slice(tag.end + 1, close)
|
|
316
|
+
.replace(/\{\s*(["'`])((?:(?!\1)[^\\$]|\\.)*)\1\s*\}/g, "$2")
|
|
317
|
+
.replace(/<[^>]*>/g, " ");
|
|
318
|
+
// 入れ子の式({open && (<p>{text}</p>)})は、内側から消す
|
|
319
|
+
for (let prev = ""; prev !== inner; ) [prev, inner] = [inner, inner.replace(/\{[^{}]*\}/g, " ")];
|
|
320
|
+
return inner.replace(/\s+/g, " ").trim();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// JSX の要素の中の文言(> と < の間で、{ } の外の文字)を、行の番号つきで返す
|
|
324
|
+
export function jsxTexts(path) {
|
|
325
|
+
const text = stripComments(read(path));
|
|
326
|
+
const result = [];
|
|
327
|
+
for (const m of text.matchAll(/>([^<>{}]*[^\s<>{}][^<>{}]*)</g)) {
|
|
328
|
+
const value = m[1].trim();
|
|
329
|
+
// 型の引数や比較の式の一部(a > b && c < d)を除く:日本語か、英字の語を含むものだけ
|
|
330
|
+
if (!/[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]|[A-Za-z]{2,}/u.test(value)) continue;
|
|
331
|
+
if (/[;=&|]/.test(value)) continue;
|
|
332
|
+
result.push({ value, line: lineAt(text, m.index + 1) });
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// package.json
|
|
338
|
+
// 使う側で package.json のないフォルダを調べるときは、依存パッケージの決まりを調べない
|
|
339
|
+
export const pkg = existsSync(join(root, "package.json")) ? JSON.parse(readFileSync(join(root, "package.json"), "utf8")) : {};
|
|
340
|
+
export const allDependencies = { ...pkg.dependencies, ...pkg.devDependencies, ...pkg.peerDependencies };
|