snice 7.8.0 → 7.9.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 +1 -1
- package/adapters/react/SniceProvider.js +1 -1
- package/adapters/react/SniceRouter.js +1 -1
- package/adapters/react/matchRoute.js +1 -1
- package/adapters/react/table.d.ts +1 -0
- package/adapters/react/table.d.ts.map +1 -1
- package/adapters/react/table.js +1 -1
- package/adapters/react/table.js.map +1 -1
- package/adapters/react/table.tsx +2 -1
- package/adapters/react/useRequestHandler.js +1 -1
- package/bin/analyzer-contracts.js +17 -1
- package/custom-elements.json +57 -3
- package/dist/cdn/accordion/snice-accordion.js +1 -1
- package/dist/cdn/action-bar/snice-action-bar.js +1 -1
- package/dist/cdn/activity-feed/snice-activity-feed.js +1 -1
- package/dist/cdn/alert/snice-alert.js +1 -1
- package/dist/cdn/app-tiles/snice-app-tiles.js +1 -1
- package/dist/cdn/approval-flow/snice-approval-flow.js +1 -1
- package/dist/cdn/audio-recorder/snice-audio-recorder.js +1 -1
- package/dist/cdn/availability/snice-availability.js +1 -1
- package/dist/cdn/avatar/snice-avatar.js +1 -1
- package/dist/cdn/avatar-group/snice-avatar-group.js +1 -1
- package/dist/cdn/badge/snice-badge.js +1 -1
- package/dist/cdn/banner/snice-banner.js +1 -1
- package/dist/cdn/binpack/snice-binpack.js +1 -1
- package/dist/cdn/book/snice-book.js +1 -1
- package/dist/cdn/booking/snice-booking.js +1 -1
- package/dist/cdn/breadcrumbs/snice-breadcrumbs.js +1 -1
- package/dist/cdn/button/snice-button.js +1 -1
- package/dist/cdn/calendar/README.md +2 -2
- package/dist/cdn/calendar/snice-calendar.js +537 -44
- package/dist/cdn/calendar/snice-calendar.js.map +1 -1
- package/dist/cdn/calendar/snice-calendar.min.js +2 -2
- package/dist/cdn/calendar/snice-calendar.min.js.map +1 -1
- package/dist/cdn/camera/snice-camera.js +1 -1
- package/dist/cdn/camera-annotate/snice-camera-annotate.js +1 -1
- package/dist/cdn/candlestick/snice-candlestick.js +1 -1
- package/dist/cdn/card/snice-card.js +1 -1
- package/dist/cdn/carousel/snice-carousel.js +1 -1
- package/dist/cdn/cart/snice-cart.js +1 -1
- package/dist/cdn/chart/snice-chart.js +1 -1
- package/dist/cdn/chat/snice-chat.js +1 -1
- package/dist/cdn/checkbox/snice-checkbox.js +1 -1
- package/dist/cdn/chip/snice-chip.js +1 -1
- package/dist/cdn/code-block/README.md +2 -2
- package/dist/cdn/code-block/snice-code-block.js +177 -167
- package/dist/cdn/code-block/snice-code-block.js.map +1 -1
- package/dist/cdn/code-block/snice-code-block.min.js +2 -2
- package/dist/cdn/code-block/snice-code-block.min.js.map +1 -1
- package/dist/cdn/color-display/snice-color-display.js +1 -1
- package/dist/cdn/color-picker/snice-color-picker.js +1 -1
- package/dist/cdn/command-palette/README.md +1 -1
- package/dist/cdn/command-palette/snice-command-palette.js +2 -2
- package/dist/cdn/command-palette/snice-command-palette.js.map +1 -1
- package/dist/cdn/command-palette/snice-command-palette.min.js +1 -1
- package/dist/cdn/command-palette/snice-command-palette.min.js.map +1 -1
- package/dist/cdn/comments/snice-comments.js +1 -1
- package/dist/cdn/countdown/snice-countdown.js +1 -1
- package/dist/cdn/cropper/snice-cropper.js +1 -1
- package/dist/cdn/data-card/snice-data-card.js +1 -1
- package/dist/cdn/date-picker/snice-date-picker.js +1 -1
- package/dist/cdn/date-range-picker/snice-date-range-picker.js +1 -1
- package/dist/cdn/date-time-picker/snice-date-time-picker.js +1 -1
- package/dist/cdn/diff/snice-diff.js +1 -1
- package/dist/cdn/divider/snice-divider.js +1 -1
- package/dist/cdn/doc/snice-doc.js +1 -1
- package/dist/cdn/draw/snice-draw.js +1 -1
- package/dist/cdn/drawer/snice-drawer.js +1 -1
- package/dist/cdn/empty-state/snice-empty-state.js +1 -1
- package/dist/cdn/estimate/snice-estimate.js +1 -1
- package/dist/cdn/file-gallery/snice-file-gallery.js +1 -1
- package/dist/cdn/file-upload/snice-file-upload.js +1 -1
- package/dist/cdn/flip-card/snice-flip-card.js +1 -1
- package/dist/cdn/flow/snice-flow.js +1 -1
- package/dist/cdn/form-layout/snice-form-layout.js +1 -1
- package/dist/cdn/funnel/snice-funnel.js +1 -1
- package/dist/cdn/gantt/snice-gantt.js +1 -1
- package/dist/cdn/gauge/snice-gauge.js +1 -1
- package/dist/cdn/grid/snice-grid.js +1 -1
- package/dist/cdn/heatmap/snice-heatmap.js +1 -1
- package/dist/cdn/image/snice-image.js +1 -1
- package/dist/cdn/input/snice-input.js +1 -1
- package/dist/cdn/invoice/snice-invoice.js +1 -1
- package/dist/cdn/kanban/snice-kanban.js +1 -1
- package/dist/cdn/key-value/snice-key-value.js +1 -1
- package/dist/cdn/kpi/snice-kpi.js +1 -1
- package/dist/cdn/layout/snice-layout.js +1 -1
- package/dist/cdn/leaderboard/snice-leaderboard.js +1 -1
- package/dist/cdn/link/snice-link.js +1 -1
- package/dist/cdn/link-preview/snice-link-preview.js +1 -1
- package/dist/cdn/list/snice-list.js +1 -1
- package/dist/cdn/location/snice-location.js +1 -1
- package/dist/cdn/login/snice-login.js +1 -1
- package/dist/cdn/map/snice-map.js +1 -1
- package/dist/cdn/markdown/snice-markdown.js +1 -1
- package/dist/cdn/masonry/snice-masonry.js +1 -1
- package/dist/cdn/menu/snice-menu.js +1 -1
- package/dist/cdn/message-strip/snice-message-strip.js +1 -1
- package/dist/cdn/modal/snice-modal.js +1 -1
- package/dist/cdn/music-player/snice-music-player.js +1 -1
- package/dist/cdn/nav/snice-nav.js +1 -1
- package/dist/cdn/network-graph/snice-network-graph.js +1 -1
- package/dist/cdn/notification-center/snice-notification-center.js +1 -1
- package/dist/cdn/order-tracker/snice-order-tracker.js +1 -1
- package/dist/cdn/org-chart/snice-org-chart.js +1 -1
- package/dist/cdn/pagination/snice-pagination.js +1 -1
- package/dist/cdn/paint/snice-paint.js +1 -1
- package/dist/cdn/pdf-viewer/snice-pdf-viewer.js +1 -1
- package/dist/cdn/permission-matrix/snice-permission-matrix.js +1 -1
- package/dist/cdn/podcast-player/snice-podcast-player.js +1 -1
- package/dist/cdn/popover/snice-popover.js +1 -1
- package/dist/cdn/pricing-table/snice-pricing-table.js +1 -1
- package/dist/cdn/product-card/snice-product-card.js +1 -1
- package/dist/cdn/progress/snice-progress.js +2 -2
- package/dist/cdn/progress/snice-progress.js.map +1 -1
- package/dist/cdn/progress/snice-progress.min.js +1 -1
- package/dist/cdn/progress/snice-progress.min.js.map +1 -1
- package/dist/cdn/progress-ring/snice-progress-ring.js +1 -1
- package/dist/cdn/qr-code/README.md +2 -2
- package/dist/cdn/qr-code/snice-qr-code.js +19 -3
- package/dist/cdn/qr-code/snice-qr-code.js.map +1 -1
- package/dist/cdn/qr-code/snice-qr-code.min.js +2 -2
- package/dist/cdn/qr-code/snice-qr-code.min.js.map +1 -1
- package/dist/cdn/qr-reader/snice-qr-reader.js +1 -1
- package/dist/cdn/radio/snice-radio.js +1 -1
- package/dist/cdn/range-slider/snice-range-slider.js +1 -1
- package/dist/cdn/rating/snice-rating.js +1 -1
- package/dist/cdn/receipt/snice-receipt.js +5 -2
- package/dist/cdn/receipt/snice-receipt.js.map +1 -1
- package/dist/cdn/receipt/snice-receipt.min.js +1 -1
- package/dist/cdn/receipt/snice-receipt.min.js.map +1 -1
- package/dist/cdn/recipe/snice-recipe.js +1 -1
- package/dist/cdn/runtime/snice-runtime.esm.js +4 -4
- package/dist/cdn/runtime/snice-runtime.esm.js.map +1 -1
- package/dist/cdn/runtime/snice-runtime.esm.min.js.map +1 -1
- package/dist/cdn/runtime/snice-runtime.js +4 -4
- package/dist/cdn/runtime/snice-runtime.js.map +1 -1
- package/dist/cdn/runtime/snice-runtime.min.js.map +1 -1
- package/dist/cdn/sankey/snice-sankey.js +1 -1
- package/dist/cdn/segmented-control/snice-segmented-control.js +1 -1
- package/dist/cdn/select/README.md +2 -2
- package/dist/cdn/select/snice-select.js +6 -9
- package/dist/cdn/select/snice-select.js.map +1 -1
- package/dist/cdn/select/snice-select.min.js +2 -2
- package/dist/cdn/select/snice-select.min.js.map +1 -1
- package/dist/cdn/skeleton/snice-skeleton.js +1 -1
- package/dist/cdn/slider/snice-slider.js +1 -1
- package/dist/cdn/sortable/snice-sortable.js +1 -1
- package/dist/cdn/sparkline/snice-sparkline.js +1 -1
- package/dist/cdn/spinner/snice-spinner.js +1 -1
- package/dist/cdn/split-button/snice-split-button.js +1 -1
- package/dist/cdn/split-pane/snice-split-pane.js +1 -1
- package/dist/cdn/spotlight/snice-spotlight.js +1 -1
- package/dist/cdn/stat-group/snice-stat-group.js +1 -1
- package/dist/cdn/step-input/snice-step-input.js +1 -1
- package/dist/cdn/stepper/snice-stepper.js +1 -1
- package/dist/cdn/switch/snice-switch.js +1 -1
- package/dist/cdn/table/README.md +2 -2
- package/dist/cdn/table/snice-table.esm.js +1940 -407
- package/dist/cdn/table/snice-table.esm.js.map +1 -1
- package/dist/cdn/table/snice-table.esm.min.js +242 -53
- package/dist/cdn/table/snice-table.esm.min.js.map +1 -1
- package/dist/cdn/table/snice-table.js +1940 -407
- package/dist/cdn/table/snice-table.js.map +1 -1
- package/dist/cdn/table/snice-table.min.js +234 -45
- package/dist/cdn/table/snice-table.min.js.map +1 -1
- package/dist/cdn/tabs/snice-tabs.js +1 -1
- package/dist/cdn/tag/snice-tag.js +1 -1
- package/dist/cdn/tag-input/snice-tag-input.js +1 -1
- package/dist/cdn/terminal/snice-terminal.js +1 -1
- package/dist/cdn/testimonial/snice-testimonial.js +1 -1
- package/dist/cdn/textarea/snice-textarea.js +1 -1
- package/dist/cdn/time-picker/snice-time-picker.js +1 -1
- package/dist/cdn/time-range-picker/snice-time-range-picker.js +1 -1
- package/dist/cdn/timeline/snice-timeline.js +1 -1
- package/dist/cdn/timer/snice-timer.js +1 -1
- package/dist/cdn/toast/snice-toast.js +1 -1
- package/dist/cdn/tooltip/snice-tooltip.js +1 -1
- package/dist/cdn/tree/snice-tree.js +1 -1
- package/dist/cdn/treemap/snice-treemap.js +1 -1
- package/dist/cdn/user-card/snice-user-card.js +1 -1
- package/dist/cdn/video-player/snice-video-player.js +1 -1
- package/dist/cdn/virtual-scroller/snice-virtual-scroller.js +1 -1
- package/dist/cdn/waterfall/snice-waterfall.js +1 -1
- package/dist/cdn/weather/snice-weather.js +1 -1
- package/dist/cdn/work-order/snice-work-order.js +1 -1
- package/dist/components/calendar/snice-calendar.d.ts +187 -5
- package/dist/components/calendar/snice-calendar.js +537 -44
- package/dist/components/calendar/snice-calendar.js.map +1 -1
- package/dist/components/calendar/snice-calendar.types.d.ts +2 -1
- package/dist/components/code-block/formatter.d.ts +6 -0
- package/dist/components/code-block/formatter.js +174 -164
- package/dist/components/code-block/formatter.js.map +1 -1
- package/dist/components/code-block/grammars/snice.json +1 -1
- package/dist/components/code-block/grammars/typescript.json +1 -1
- package/dist/components/command-palette/snice-command-palette.js +1 -1
- package/dist/components/command-palette/snice-command-palette.js.map +1 -1
- package/dist/components/progress/snice-progress.js +1 -1
- package/dist/components/progress/snice-progress.js.map +1 -1
- package/dist/components/qr-code/qrcode.d.ts +1 -1
- package/dist/components/qr-code/qrcode.js +18 -2
- package/dist/components/qr-code/qrcode.js.map +1 -1
- package/dist/components/receipt/snice-receipt.js +4 -1
- package/dist/components/receipt/snice-receipt.js.map +1 -1
- package/dist/components/select/snice-select.d.ts +1 -1
- package/dist/components/select/snice-select.js +5 -8
- package/dist/components/select/snice-select.js.map +1 -1
- package/dist/components/table/snice-cell-actions.js +1 -1
- package/dist/components/table/snice-cell-actions.js.map +1 -1
- package/dist/components/table/snice-cell-color.js +1 -1
- package/dist/components/table/snice-cell-color.js.map +1 -1
- package/dist/components/table/snice-cell-date.js +20 -8
- package/dist/components/table/snice-cell-date.js.map +1 -1
- package/dist/components/table/snice-cell-email.js +1 -1
- package/dist/components/table/snice-cell-email.js.map +1 -1
- package/dist/components/table/snice-cell-image.js +1 -1
- package/dist/components/table/snice-cell-image.js.map +1 -1
- package/dist/components/table/snice-cell-json.js +1 -1
- package/dist/components/table/snice-cell-json.js.map +1 -1
- package/dist/components/table/snice-cell-link.js +1 -1
- package/dist/components/table/snice-cell-link.js.map +1 -1
- package/dist/components/table/snice-cell-location.js +1 -1
- package/dist/components/table/snice-cell-location.js.map +1 -1
- package/dist/components/table/snice-cell-phone.js +1 -1
- package/dist/components/table/snice-cell-phone.js.map +1 -1
- package/dist/components/table/snice-cell-status.js +1 -1
- package/dist/components/table/snice-cell-status.js.map +1 -1
- package/dist/components/table/snice-cell.d.ts +10 -0
- package/dist/components/table/snice-cell.js +59 -13
- package/dist/components/table/snice-cell.js.map +1 -1
- package/dist/components/table/snice-row.d.ts +0 -1
- package/dist/components/table/snice-row.js +4 -10
- package/dist/components/table/snice-row.js.map +1 -1
- package/dist/components/table/snice-table.d.ts +170 -2
- package/dist/components/table/snice-table.js +868 -189
- package/dist/components/table/snice-table.js.map +1 -1
- package/dist/components/table/snice-table.types.d.ts +17 -0
- package/dist/components/table/table-cell-presentation.d.ts +17 -4
- package/dist/components/table/table-cell-presentation.js +37 -11
- package/dist/components/table/table-cell-presentation.js.map +1 -1
- package/dist/components/table/table-column-manager.d.ts +153 -2
- package/dist/components/table/table-column-manager.js +364 -43
- package/dist/components/table/table-column-manager.js.map +1 -1
- package/dist/components/table/table-date.d.ts +29 -0
- package/dist/components/table/table-date.js +78 -0
- package/dist/components/table/table-date.js.map +1 -0
- package/dist/components/table/table-export.js +6 -2
- package/dist/components/table/table-export.js.map +1 -1
- package/dist/components/table/table-filter-engine.d.ts +9 -0
- package/dist/components/table/table-filter-engine.js +58 -14
- package/dist/components/table/table-filter-engine.js.map +1 -1
- package/dist/components/table/table-keyboard.d.ts +8 -0
- package/dist/components/table/table-keyboard.js +14 -3
- package/dist/components/table/table-keyboard.js.map +1 -1
- package/dist/components/table/table-toolbar.js +1 -0
- package/dist/components/table/table-toolbar.js.map +1 -1
- package/dist/components/table/table-tree-data.d.ts +2 -0
- package/dist/components/table/table-tree-data.js +35 -9
- package/dist/components/table/table-tree-data.js.map +1 -1
- package/dist/components/table/table-virtualizer.d.ts +44 -7
- package/dist/components/table/table-virtualizer.js +101 -54
- package/dist/components/table/table-virtualizer.js.map +1 -1
- package/dist/components/theme/theme.css +9 -0
- package/dist/index.cjs +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/react/SniceProvider.js +1 -1
- package/dist/react/SniceRouter.js +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/matchRoute.js +1 -1
- package/dist/react/useRequestHandler.js +1 -1
- package/dist/symbols.cjs +1 -1
- package/dist/symbols.esm.js +1 -1
- package/dist/testing-dom.cjs +1 -1
- package/dist/testing-dom.esm.js +1 -1
- package/dist/transitions.cjs +1 -1
- package/dist/transitions.esm.js +1 -1
- package/docs/ai/DEVELOPMENT.md +93 -2
- package/docs/ai/components/calendar.md +113 -10
- package/docs/ai/components/code-block.md +4 -0
- package/docs/ai/components/doc.md +1 -1
- package/docs/ai/components/progress.md +1 -0
- package/docs/ai/components/receipt.md +1 -1
- package/docs/ai/components/table.md +29 -30
- package/docs/ai/components/theme.md +1 -0
- package/docs/ai/events.md +30 -0
- package/docs/ai/theme.md +1 -0
- package/docs/components/calendar.md +171 -11
- package/docs/components/code-block.md +2 -0
- package/docs/components/doc.md +1 -1
- package/docs/components/progress.md +13 -0
- package/docs/components/receipt.md +1 -0
- package/docs/components/table.md +274 -15
- package/docs/components/theme.md +5 -0
- package/docs/events.md +49 -0
- package/docs/plans/2026-03-06-date-range-picker-plan.md +4 -4
- package/docs/plans/2026-03-07-table-mui-parity-design.md +1 -1
- package/docs/plans/2026-03-09-action-bar-plan.md +11 -11
- package/docs/superpowers/specs/2026-07-09-table-incredible-design.md +1 -1
- package/docs/superpowers/specs/2026-07-09-table-phase0-implementation.md +2 -2
- package/package.json +3 -1
- package/vscode.html-custom-data.json +13 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* snice v7.
|
|
2
|
+
* snice v7.8.0
|
|
3
3
|
* A decorator-driven web component library with routing, controllers, daemons, and 130+ UI components. For better coding-agent results, run npx snice init-ai.
|
|
4
4
|
* (c) 2024
|
|
5
5
|
* Released under the MIT License.
|
|
@@ -245,6 +245,12 @@ var SniceCodeBlock = (function (exports, snice) {
|
|
|
245
245
|
* Rules are defined in grammar JSON files under "formatters" section.
|
|
246
246
|
* The engine scans code char by char, tracks string/comment context,
|
|
247
247
|
* and applies newline/space/indent rules based on regex char classes.
|
|
248
|
+
*
|
|
249
|
+
* Semantics: a code display formats authored code — it does not re-flow it.
|
|
250
|
+
* Author line breaks are preserved; rule-driven newlines fire only where
|
|
251
|
+
* they do not duplicate an author break and are suppressed inside
|
|
252
|
+
* parentheses/bracket depth. Leading indentation is renormalized from the
|
|
253
|
+
* indent/dedent char-class depth.
|
|
248
254
|
*/
|
|
249
255
|
/**
|
|
250
256
|
* Format code using declarative rules.
|
|
@@ -253,7 +259,6 @@ var SniceCodeBlock = (function (exports, snice) {
|
|
|
253
259
|
const tabSize = rules.tabSize ?? 2;
|
|
254
260
|
const useTabs = rules.useTabs ?? false;
|
|
255
261
|
const indentUnit = useTabs ? '\t' : ' '.repeat(tabSize);
|
|
256
|
-
const trimTrailing = rules.trimTrailing ?? true;
|
|
257
262
|
const skipStrings = rules.skipStrings ?? true;
|
|
258
263
|
const skipComments = rules.skipComments ?? true;
|
|
259
264
|
const newlineAfter = rules.newlineAfter ? new RegExp(rules.newlineAfter) : null;
|
|
@@ -263,206 +268,211 @@ var SniceCodeBlock = (function (exports, snice) {
|
|
|
263
268
|
const spaceAround = rules.spaceAround ? new RegExp(rules.spaceAround) : null;
|
|
264
269
|
const indentRe = rules.indent ? new RegExp(rules.indent) : null;
|
|
265
270
|
const dedentRe = rules.dedent ? new RegExp(rules.dedent) : null;
|
|
266
|
-
//
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
271
|
+
// Chars whose newline rules stay active inside […] depth: JSON-style
|
|
272
|
+
// structural brackets and separators must keep exploding one-liners.
|
|
273
|
+
const bracketExemptRe = /[[\],]/;
|
|
274
|
+
const lines = [];
|
|
275
|
+
let line = '';
|
|
276
|
+
let lineHasContent = false;
|
|
277
|
+
let needIndent = false;
|
|
278
|
+
// True while the current line begins inside a string/block comment: its
|
|
279
|
+
// content is emitted verbatim, never re-indented or rule-processed.
|
|
280
|
+
let inContinuation = false;
|
|
281
|
+
let pendingSpace = false;
|
|
270
282
|
let depth = 0;
|
|
271
|
-
let
|
|
283
|
+
let parenDepth = 0;
|
|
284
|
+
let bracketDepth = 0;
|
|
285
|
+
// One flag per open indent group: did a line break occur inside it? A
|
|
286
|
+
// closing char only starts its own line when the group it closes is
|
|
287
|
+
// multi-line, so `import { a } from 'x'` never breaks.
|
|
288
|
+
const brokenGroups = [];
|
|
272
289
|
let inString = null;
|
|
273
|
-
let
|
|
290
|
+
let inBlockComment = false;
|
|
274
291
|
let inLineComment = false;
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
292
|
+
/** Rule-driven newlines are suppressed inside () or (for non-bracket
|
|
293
|
+
* chars) inside [], so `({ ... })`, `f([a, b])` and `for (;;)` never
|
|
294
|
+
* explode. */
|
|
295
|
+
const newlineSuppressed = (ch) => {
|
|
296
|
+
if (parenDepth > 0)
|
|
297
|
+
return true;
|
|
298
|
+
if (bracketDepth > 0 && !bracketExemptRe.test(ch))
|
|
299
|
+
return true;
|
|
300
|
+
return false;
|
|
301
|
+
};
|
|
302
|
+
const beginLine = () => {
|
|
303
|
+
line = '';
|
|
304
|
+
lineHasContent = false;
|
|
305
|
+
needIndent = true;
|
|
306
|
+
pendingSpace = false;
|
|
307
|
+
inContinuation = inString !== null || inBlockComment;
|
|
308
|
+
if (brokenGroups.length > 0)
|
|
309
|
+
brokenGroups[brokenGroups.length - 1] = true;
|
|
310
|
+
};
|
|
311
|
+
const endLine = () => {
|
|
312
|
+
lines.push(line.replace(/[ \t]+$/, ''));
|
|
313
|
+
beginLine();
|
|
314
|
+
};
|
|
315
|
+
const appendContent = (ch) => {
|
|
316
|
+
if (needIndent) {
|
|
317
|
+
needIndent = false;
|
|
318
|
+
// Current depth, not a line-start snapshot: a dedent char re-indents
|
|
319
|
+
// its own line (the closing brace drops back before being written).
|
|
320
|
+
if (!inContinuation)
|
|
321
|
+
line += indentUnit.repeat(depth);
|
|
322
|
+
}
|
|
323
|
+
if (pendingSpace) {
|
|
324
|
+
line += ' ';
|
|
325
|
+
pendingSpace = false;
|
|
326
|
+
}
|
|
327
|
+
line += ch;
|
|
328
|
+
lineHasContent = true;
|
|
329
|
+
};
|
|
330
|
+
beginLine();
|
|
331
|
+
for (let i = 0; i < code.length; i++) {
|
|
332
|
+
const ch = code[i];
|
|
333
|
+
const next = i + 1 < code.length ? code[i + 1] : '';
|
|
334
|
+
// Line comment content: verbatim until the author newline
|
|
335
|
+
if (inLineComment) {
|
|
336
|
+
if (ch === '\n') {
|
|
337
|
+
inLineComment = false;
|
|
338
|
+
endLine();
|
|
287
339
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (lineStart) {
|
|
291
|
-
result += indentUnit.repeat(depth);
|
|
292
|
-
lineStart = false;
|
|
293
|
-
}
|
|
294
|
-
result += ch;
|
|
295
|
-
continue;
|
|
340
|
+
else {
|
|
341
|
+
appendContent(ch);
|
|
296
342
|
}
|
|
343
|
+
continue;
|
|
297
344
|
}
|
|
298
|
-
//
|
|
299
|
-
if (
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
if (ch === '\n') {
|
|
303
|
-
inLineComment = false;
|
|
304
|
-
lineStart = true;
|
|
305
|
-
}
|
|
345
|
+
// Block comment content: verbatim, may span lines
|
|
346
|
+
if (inBlockComment) {
|
|
347
|
+
if (ch === '\n') {
|
|
348
|
+
endLine();
|
|
306
349
|
continue;
|
|
307
350
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
351
|
+
appendContent(ch);
|
|
352
|
+
if (ch === '/' && code[i - 1] === '*')
|
|
353
|
+
inBlockComment = false;
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
// String content: verbatim, may span lines (template literals)
|
|
357
|
+
if (inString) {
|
|
358
|
+
if (ch === '\n') {
|
|
359
|
+
endLine();
|
|
313
360
|
continue;
|
|
314
361
|
}
|
|
362
|
+
appendContent(ch);
|
|
363
|
+
if (ch === inString && code[i - 1] !== '\\')
|
|
364
|
+
inString = null;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
// Entering a string
|
|
368
|
+
if (skipStrings && (ch === '"' || ch === "'" || ch === '`')) {
|
|
369
|
+
inString = ch;
|
|
370
|
+
appendContent(ch);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
// Entering a comment
|
|
374
|
+
if (skipComments) {
|
|
315
375
|
if (ch === '/' && next === '/') {
|
|
316
|
-
if (lineStart) {
|
|
317
|
-
result += indentUnit.repeat(depth);
|
|
318
|
-
lineStart = false;
|
|
319
|
-
}
|
|
320
376
|
inLineComment = true;
|
|
321
|
-
|
|
377
|
+
appendContent(ch);
|
|
322
378
|
continue;
|
|
323
379
|
}
|
|
324
380
|
if (ch === '/' && next === '*') {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
lineStart = false;
|
|
328
|
-
}
|
|
329
|
-
inComment = true;
|
|
330
|
-
result += ch;
|
|
381
|
+
inBlockComment = true;
|
|
382
|
+
appendContent(ch);
|
|
331
383
|
continue;
|
|
332
384
|
}
|
|
333
385
|
}
|
|
334
|
-
//
|
|
335
|
-
if (
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
// Newline before
|
|
339
|
-
if (newlineBefore && newlineBefore.test(ch)) {
|
|
340
|
-
if (!lineStart) {
|
|
341
|
-
result = trimTrailingSpaces(result);
|
|
342
|
-
result += '\n';
|
|
343
|
-
lineStart = true;
|
|
344
|
-
}
|
|
386
|
+
// Author newline: preserved
|
|
387
|
+
if (ch === '\n') {
|
|
388
|
+
endLine();
|
|
389
|
+
continue;
|
|
345
390
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
391
|
+
if (ch === '\r') {
|
|
392
|
+
if (next !== '\n')
|
|
393
|
+
endLine();
|
|
394
|
+
continue;
|
|
351
395
|
}
|
|
352
|
-
//
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
396
|
+
// Whitespace within a line: collapsed to a single pending space;
|
|
397
|
+
// leading indentation is dropped (renormalized from depth)
|
|
398
|
+
if (ch === ' ' || ch === '\t') {
|
|
399
|
+
if (lineHasContent)
|
|
400
|
+
pendingSpace = true;
|
|
401
|
+
continue;
|
|
356
402
|
}
|
|
357
|
-
|
|
403
|
+
// Bracket/paren depth (outside strings/comments)
|
|
404
|
+
if (ch === '(')
|
|
405
|
+
parenDepth++;
|
|
406
|
+
else if (ch === ')')
|
|
407
|
+
parenDepth = Math.max(0, parenDepth - 1);
|
|
408
|
+
else if (ch === '[')
|
|
409
|
+
bracketDepth++;
|
|
410
|
+
else if (ch === ']')
|
|
411
|
+
bracketDepth = Math.max(0, bracketDepth - 1);
|
|
412
|
+
// Dedent before the char; a closer pops its group's multi-line flag
|
|
413
|
+
let closesBrokenGroup = false;
|
|
414
|
+
if (dedentRe && dedentRe.test(ch)) {
|
|
415
|
+
depth = Math.max(0, depth - 1);
|
|
416
|
+
closesBrokenGroup = brokenGroups.pop() ?? false;
|
|
417
|
+
}
|
|
418
|
+
// Newline before (only where it does not duplicate an author break, and
|
|
419
|
+
// for closers only when the group being closed is multi-line)
|
|
420
|
+
if (newlineBefore && newlineBefore.test(ch) && lineHasContent &&
|
|
421
|
+
!newlineSuppressed(ch) && (!dedentRe || !dedentRe.test(ch) || closesBrokenGroup)) {
|
|
422
|
+
endLine();
|
|
423
|
+
}
|
|
424
|
+
// Space before (including spaceAround). A rule char glued to a
|
|
425
|
+
// preceding operator char is a compound operator (`+=`, `===`), not a
|
|
426
|
+
// fresh token — it keeps its left side.
|
|
427
|
+
const prevRaw = i > 0 ? code[i - 1] : '';
|
|
428
|
+
const partOfOperator = prevRaw !== '' && !/[ \t\n\r]/.test(prevRaw) && /[+\-*/%=<>!&|^~?:]/.test(prevRaw);
|
|
429
|
+
if (((spaceBefore && spaceBefore.test(ch)) || (spaceAround && spaceAround.test(ch))) &&
|
|
430
|
+
lineHasContent && !partOfOperator) {
|
|
431
|
+
pendingSpace = true;
|
|
432
|
+
}
|
|
433
|
+
appendContent(ch);
|
|
358
434
|
// Indent after the char
|
|
359
435
|
if (indentRe && indentRe.test(ch)) {
|
|
360
436
|
depth++;
|
|
437
|
+
brokenGroups.push(false);
|
|
361
438
|
}
|
|
362
|
-
// Space after (including spaceAround)
|
|
439
|
+
// Space after (including spaceAround). An `=` directly followed by
|
|
440
|
+
// another `=` is an equality chain and `=>` is an arrow — not two tokens.
|
|
363
441
|
if ((spaceAfter && spaceAfter.test(ch)) || (spaceAround && spaceAround.test(ch))) {
|
|
364
|
-
|
|
365
|
-
|
|
442
|
+
const continuesOperator = ch === '=' && (next === '=' || next === '>');
|
|
443
|
+
if (next && next !== ' ' && next !== '\t' && next !== '\n' && next !== '\r' && !continuesOperator) {
|
|
444
|
+
pendingSpace = true;
|
|
366
445
|
}
|
|
367
446
|
}
|
|
368
|
-
// Newline after
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
447
|
+
// Newline after: fires only where it does not duplicate an author
|
|
448
|
+
// break or detach a same-line trailing comment
|
|
449
|
+
if (newlineAfter && newlineAfter.test(ch) && !newlineSuppressed(ch)) {
|
|
450
|
+
let j = i + 1;
|
|
451
|
+
while (j < code.length && (code[j] === ' ' || code[j] === '\t'))
|
|
452
|
+
j++;
|
|
453
|
+
const ahead = j < code.length ? code[j] : '';
|
|
454
|
+
const atAuthorBreak = ahead === '' || ahead === '\n' || ahead === '\r';
|
|
455
|
+
const atTrailingComment = ahead === '/' && (code[j + 1] === '/' || code[j + 1] === '*');
|
|
456
|
+
if (!atAuthorBreak && !atTrailingComment) {
|
|
457
|
+
endLine();
|
|
458
|
+
}
|
|
373
459
|
}
|
|
374
460
|
}
|
|
461
|
+
lines.push(line.replace(/[ \t]+$/, ''));
|
|
375
462
|
// Post-processing
|
|
376
|
-
let
|
|
377
|
-
if (trimTrailing) {
|
|
378
|
-
|
|
463
|
+
let out = lines;
|
|
464
|
+
if (rules.trimTrailing ?? true) {
|
|
465
|
+
out = out.map(l => l.replace(/[ \t]+$/, ''));
|
|
379
466
|
}
|
|
380
467
|
if (rules.collapseBlankLines !== undefined) {
|
|
381
|
-
|
|
468
|
+
out = collapseBlankLinesArr(out, rules.collapseBlankLines);
|
|
382
469
|
}
|
|
383
470
|
// Trim leading/trailing blank lines
|
|
384
|
-
while (
|
|
385
|
-
|
|
386
|
-
while (
|
|
387
|
-
|
|
388
|
-
return
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Strip existing whitespace: replace runs of whitespace (outside strings/comments)
|
|
392
|
-
* with a single space, and remove all newlines.
|
|
393
|
-
*/
|
|
394
|
-
function stripWhitespace(code, skipStrings, skipComments) {
|
|
395
|
-
let result = '';
|
|
396
|
-
let inString = null;
|
|
397
|
-
let inComment = false;
|
|
398
|
-
let inLineComment = false;
|
|
399
|
-
for (let i = 0; i < code.length; i++) {
|
|
400
|
-
const ch = code[i];
|
|
401
|
-
const prev = i > 0 ? code[i - 1] : '';
|
|
402
|
-
const next = i + 1 < code.length ? code[i + 1] : '';
|
|
403
|
-
// Track strings
|
|
404
|
-
if (!inComment && !inLineComment && skipStrings) {
|
|
405
|
-
if (inString) {
|
|
406
|
-
result += ch;
|
|
407
|
-
if (ch === inString && prev !== '\\') {
|
|
408
|
-
inString = null;
|
|
409
|
-
}
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
if (ch === '"' || ch === "'" || ch === '`') {
|
|
413
|
-
inString = ch;
|
|
414
|
-
result += ch;
|
|
415
|
-
continue;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
// Track comments
|
|
419
|
-
if (skipComments) {
|
|
420
|
-
if (inLineComment) {
|
|
421
|
-
if (ch === '\n') {
|
|
422
|
-
inLineComment = false;
|
|
423
|
-
// Emit the newline so line comments stay separate
|
|
424
|
-
result += ch;
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
result += ch;
|
|
428
|
-
}
|
|
429
|
-
continue;
|
|
430
|
-
}
|
|
431
|
-
if (inComment) {
|
|
432
|
-
result += ch;
|
|
433
|
-
if (ch === '/' && prev === '*') {
|
|
434
|
-
inComment = false;
|
|
435
|
-
}
|
|
436
|
-
continue;
|
|
437
|
-
}
|
|
438
|
-
if (ch === '/' && next === '/') {
|
|
439
|
-
inLineComment = true;
|
|
440
|
-
result += ch;
|
|
441
|
-
continue;
|
|
442
|
-
}
|
|
443
|
-
if (ch === '/' && next === '*') {
|
|
444
|
-
inComment = true;
|
|
445
|
-
result += ch;
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
// Collapse whitespace
|
|
450
|
-
if (/\s/.test(ch)) {
|
|
451
|
-
if (result.length > 0 && !/\s/.test(result[result.length - 1])) {
|
|
452
|
-
result += ' ';
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
else {
|
|
456
|
-
result += ch;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
return result;
|
|
460
|
-
}
|
|
461
|
-
function trimTrailingSpaces(s) {
|
|
462
|
-
let end = s.length;
|
|
463
|
-
while (end > 0 && s[end - 1] === ' ')
|
|
464
|
-
end--;
|
|
465
|
-
return s.slice(0, end);
|
|
471
|
+
while (out.length > 0 && out[0].trim() === '')
|
|
472
|
+
out.shift();
|
|
473
|
+
while (out.length > 0 && out[out.length - 1].trim() === '')
|
|
474
|
+
out.pop();
|
|
475
|
+
return out.join('\n');
|
|
466
476
|
}
|
|
467
477
|
function collapseBlankLinesArr(lines, max) {
|
|
468
478
|
const result = [];
|