@heartlandone/vega 2.74.0-RTE-table-preview → 2.75.0-RTE-table-preview
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/dist/cjs/{app-globals-be2e868e.js → app-globals-6c9a0e62.js} +11 -10
- package/dist/cjs/{child-nodes-event-prevent-slimmer-536d29fc.js → child-nodes-event-prevent-slimmer-aca87dac.js} +1 -1
- package/dist/cjs/click-outside-only-to-dismiss-strategy-407f6d1e.js +32 -0
- package/dist/cjs/{code-block-22ee2550.js → code-block-d9001f03.js} +2 -2
- package/dist/cjs/{component-value-history-controller-slimmer.abstract-3486cbc0.js → component-value-history-controller-slimmer.abstract-b00e9f58.js} +4 -4
- package/dist/cjs/{content-state-0be6fda3.js → content-state-466f277f.js} +3 -3
- package/dist/cjs/{date-required-rule-99cca681.js → date-required-rule-30ee62d0.js} +1 -1
- package/dist/cjs/{design-token-505997df.js → design-token-a569577e.js} +2 -2
- package/dist/cjs/{dom-node-subject-observer-factory-1c8f7880.js → dom-node-subject-observer-factory-b5e71bf6.js} +4 -0
- package/dist/cjs/{element-appender-slimmer-26420c09.js → element-appender-slimmer-b7fdd82e.js} +160 -36
- package/dist/cjs/{event-emit-slimmer-6a591353.js → event-emit-slimmer-2dacabbd.js} +2 -2
- package/dist/cjs/{form-field-controller-slimmer-56c551ea.js → form-field-controller-slimmer-3ea2464a.js} +2 -2
- package/dist/cjs/{image-annotation-action-462fd073.js → image-annotation-action-4435d531.js} +3 -31
- package/dist/cjs/{index-fc538f17.js → index-19e5b936.js} +1 -1
- package/dist/cjs/index.cjs.js +22 -22
- package/dist/cjs/{inject-keyboard-manager-a6101379.js → inject-keyboard-manager-d21b4387.js} +1 -1
- package/dist/cjs/{internal-vega-event-manager-d587a33c.js → internal-vega-event-manager-6befeb34.js} +13 -2
- package/dist/cjs/{keyboard-manager-d8adb0ed.js → keyboard-manager-3dea6b28.js} +1 -1
- package/dist/cjs/{keyboard-manager-slimmer-15e65357.js → keyboard-manager-slimmer-0d45f944.js} +1 -1
- package/dist/cjs/{language-extension-414149c2.js → language-extension-26331915.js} +2 -2
- package/dist/cjs/loader.cjs.js +15 -15
- package/dist/cjs/{month-view-generator-706c5477.js → month-view-generator-49cc5fc2.js} +1 -1
- package/dist/cjs/{public-rules-2d18cf41.js → public-rules-942bd931.js} +7 -7
- package/dist/cjs/{range-439a0c0c.js → range-cafe69a9.js} +1 -1
- package/dist/cjs/{responsive-format-facade-0ececeb3.js → responsive-format-facade-6c22bbbd.js} +5 -4
- package/dist/cjs/{rich-text-editor-required-rule-5a4f3626.js → rich-text-editor-required-rule-0dcb08c8.js} +1 -1
- package/dist/cjs/sanitize-fb222510.js +131 -0
- package/dist/cjs/{styles.constants-3aff0b56.js → split-cell-operation-9930fde8.js} +1230 -403
- package/dist/cjs/{string-format-strategy.abstract-a8264fca.js → string-format-strategy.abstract-63514c60.js} +1 -1
- package/dist/cjs/{string-input-formatter-slimmer-a8f4a9b1.js → string-input-formatter-slimmer-655d0322.js} +3 -3
- package/dist/cjs/{string-mask-strategy-4e7d3780.js → string-mask-strategy-d23ac21a.js} +2 -2
- package/dist/cjs/{style-formatter-142500c0.js → style-formatter-0e0ae896.js} +2 -2
- package/dist/cjs/{sub-state-notify-slimmer-011866d9.js → sub-state-notify-slimmer-3fa87162.js} +1 -1
- package/dist/cjs/{sub-state-observer-slimmer-23d43f1e.js → sub-state-observer-slimmer-77deba40.js} +1 -1
- package/dist/cjs/{table-extension-2a20da57.js → table-extension-5f27207f.js} +676 -373
- package/dist/cjs/{time-required-rule-9d39a620.js → time-required-rule-c96ecdc9.js} +1 -1
- package/dist/cjs/{type-guard-69d2cf01.js → type-guard-a0f026d8.js} +12 -0
- package/dist/cjs/{valid-credit-card-number-rule-9f40d1d9.js → valid-credit-card-number-rule-c854bed9.js} +1 -1
- package/dist/cjs/vega-accordion.cjs.entry.js +12 -12
- package/dist/cjs/vega-app-header-button.cjs.entry.js +13 -13
- package/dist/cjs/vega-banner.cjs.entry.js +3 -3
- package/dist/cjs/vega-box.cjs.entry.js +12 -12
- package/dist/cjs/vega-breadcrumb.cjs.entry.js +4 -4
- package/dist/cjs/vega-button-circle.cjs.entry.js +12 -12
- package/dist/cjs/vega-button-group_2.cjs.entry.js +6 -6
- package/dist/cjs/vega-button-link.cjs.entry.js +4 -4
- package/dist/cjs/vega-button.cjs.entry.js +11 -11
- package/dist/cjs/vega-calendar_4.cjs.entry.js +8 -8
- package/dist/cjs/vega-card.cjs.entry.js +12 -12
- package/dist/cjs/vega-carousel.cjs.entry.js +11 -11
- package/dist/cjs/vega-checkbox_2.cjs.entry.js +6 -6
- package/dist/cjs/vega-chip.cjs.entry.js +13 -13
- package/dist/cjs/vega-code-block.cjs.entry.js +10 -10
- package/dist/cjs/vega-color-picker.cjs.entry.js +5 -5
- package/dist/cjs/vega-combo-box.cjs.entry.js +11 -10
- package/dist/cjs/vega-date-picker_2.cjs.entry.js +392 -345
- package/dist/cjs/vega-dialog_2.cjs.entry.js +14 -14
- package/dist/cjs/vega-divider.cjs.entry.js +13 -13
- package/dist/cjs/vega-dropdown_5.cjs.entry.js +40 -22
- package/dist/cjs/vega-env-manager-23b8b23c.js +2 -2
- package/dist/cjs/vega-field-label.cjs.entry.js +3 -3
- package/dist/cjs/vega-file-uploader.cjs.entry.js +5 -5
- package/dist/cjs/vega-flag-icon.cjs.entry.js +11 -11
- package/dist/cjs/vega-flex.cjs.entry.js +13 -13
- package/dist/cjs/vega-font.cjs.entry.js +12 -12
- package/dist/cjs/vega-form.cjs.entry.js +8 -8
- package/dist/cjs/vega-grid.cjs.entry.js +12 -12
- package/dist/cjs/vega-icon.cjs.entry.js +12 -12
- package/dist/cjs/vega-image-uploader.cjs.entry.js +14 -14
- package/dist/cjs/vega-input-credit-card.cjs.entry.js +10 -10
- package/dist/cjs/vega-input-numeric.cjs.entry.js +10 -10
- package/dist/cjs/vega-input-passcode.cjs.entry.js +9 -9
- package/dist/cjs/vega-input-phone-number.cjs.entry.js +14 -14
- package/dist/cjs/vega-input-range.cjs.entry.js +6 -6
- package/dist/cjs/vega-input-select.cjs.entry.js +21 -16
- package/dist/cjs/vega-input.cjs.entry.js +339 -98
- package/dist/cjs/vega-item-toggle.cjs.entry.js +3 -3
- package/dist/cjs/vega-left-nav_5.cjs.entry.js +12 -12
- package/dist/cjs/vega-loader-wrapper_2.cjs.entry.js +13 -13
- package/dist/cjs/vega-page-notification_2.cjs.entry.js +1 -1
- package/dist/cjs/vega-pagination-page-selector-mobile.cjs.entry.js +3 -3
- package/dist/cjs/vega-pagination-page-size-selector-mobile.cjs.entry.js +1 -1
- package/dist/cjs/vega-pagination.cjs.entry.js +13 -13
- package/dist/cjs/vega-popover_2.cjs.entry.js +15 -15
- package/dist/cjs/vega-progress-tracker_2.cjs.entry.js +12 -12
- package/dist/cjs/vega-radio_2.cjs.entry.js +9 -9
- package/dist/cjs/vega-rich-text-content.cjs.entry.js +13 -16
- package/dist/cjs/vega-rich-text-editor_4.cjs.entry.js +143 -194
- package/dist/cjs/vega-rich-text-table-properties_3.cjs.entry.js +312 -104
- package/dist/cjs/vega-segment-control.cjs.entry.js +3 -3
- package/dist/cjs/vega-selection-chip_2.cjs.entry.js +14 -14
- package/dist/cjs/vega-selection-tile_2.cjs.entry.js +7 -7
- package/dist/cjs/vega-sidenav_3.cjs.entry.js +15 -15
- package/dist/cjs/vega-signature-capture.cjs.entry.js +14 -14
- package/dist/cjs/vega-stepper.cjs.entry.js +6 -6
- package/dist/cjs/vega-tab-group_2.cjs.entry.js +4 -4
- package/dist/cjs/vega-table_11.cjs.entry.js +13 -13
- package/dist/cjs/vega-textarea.cjs.entry.js +6 -6
- package/dist/cjs/vega-time-picker_2.cjs.entry.js +19 -18
- package/dist/cjs/vega-toggle-switch.cjs.entry.js +5 -5
- package/dist/cjs/vega-tooltip_2.cjs.entry.js +14 -14
- package/dist/cjs/vega.cjs.js +15 -15
- package/dist/collection/components/vega-app-header-button/vega-app-header-button.js +1 -1
- package/dist/collection/components/vega-button-group/vega-button-group-item/vega-button-group-item.js +1 -1
- package/dist/collection/components/vega-calendar/vega-calendar.js +1 -1
- package/dist/collection/components/vega-combo-box/slimmers/renderers/vega-combo-box-dropdown-renderer.js +2 -1
- package/dist/collection/components/vega-date-picker/assets/icons.js +4 -1
- package/dist/collection/components/vega-date-picker/slimmers/controllers/vega-date-picker-calendar-open-state-controller.js +2 -1
- package/dist/collection/components/vega-date-picker/slimmers/renderers/vega-date-picker-calendar-renderer.js +2 -2
- package/dist/collection/components/vega-date-picker/vega-date-picker-calendar/slimmers/renderers/vega-date-picker-calendar-header-render.js +109 -0
- package/dist/collection/components/vega-date-picker/vega-date-picker-calendar/slimmers/renderers/vega-date-picker-calendar-renderer.js +4 -0
- package/dist/collection/components/vega-date-picker/vega-date-picker-calendar/slimmers/renderers/vega-date-picker-calendar-year-month-switcher-renderer.js +42 -70
- package/dist/collection/components/vega-date-picker/vega-date-picker-calendar/slimmers/renderers/vega-date-picker-month-item-renderer.js +12 -56
- package/dist/collection/components/vega-date-picker/vega-date-picker-calendar/vega-date-picker-calendar.css +435 -108
- package/dist/collection/components/vega-date-picker/vega-date-picker-calendar/vega-date-picker-calendar.js +5 -0
- package/dist/collection/components/vega-dropdown/slimmers/controllers/vega-dropdown-search-controller.js +5 -1
- package/dist/collection/components/vega-dropdown/slimmers/controllers/vega-dropdown-source-controller.js +7 -0
- package/dist/collection/components/vega-dropdown/vega-dropdown-item/slimmers/renderers/vega-dropdown-item-renderer.js +3 -2
- package/dist/collection/components/vega-dropdown/vega-dropdown.js +21 -6
- package/dist/collection/components/vega-field-label/vega-field-label.js +1 -1
- package/dist/collection/components/vega-input/slimmers/controllers/vega-input-render-mode-controller.js +51 -0
- package/dist/collection/components/vega-input/slimmers/renderers/vega-input-input-renderer.js +6 -0
- package/dist/collection/components/vega-input/slimmers/renderers/vega-input-input-suggestions-renderer.js +142 -0
- package/dist/collection/components/vega-input/slimmers/renderers/vega-input-renderer.js +12 -1
- package/dist/collection/components/vega-input/vega-input.js +200 -3
- package/dist/collection/components/vega-input-select/slimmers/renderers/vega-input-select-dropdown-renderer.js +8 -3
- package/dist/collection/components/vega-rich-text-content/vega-rich-text-content.js +9 -1
- package/dist/collection/components/vega-rich-text-editor/dto/renderers/nodes/text-node-renderer.js +0 -10
- package/dist/collection/components/vega-rich-text-editor/extensions/table/action-handler-strategies/insert-table-row-strategy.js +74 -28
- package/dist/collection/components/vega-rich-text-editor/extensions/table/action-handler-strategies/merge-cells-strategy.js +120 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/action-handler-strategies/split-cell-horizontally-strategy.js +143 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/action-handler-strategies/split-cell-vertically-strategy.js +80 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/action-handler-strategies/update-table-cell-properties-strategy.js +2 -1
- package/dist/collection/components/vega-rich-text-editor/extensions/table/action-handler-strategies/update-table-properties-strategy.js +2 -2
- package/dist/collection/components/vega-rich-text-editor/extensions/table/actions/merge-cells-action.js +17 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/actions/split-cell-horizontally-action.js +12 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/actions/split-cell-vertically-action.js +12 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/annotation-handler/table-annotation-handler-base.js +9 -30
- package/dist/collection/components/vega-rich-text-editor/extensions/table/annotation-handler/table-cell-annotation-handler.js +26 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/annotations/table-annotation.js +26 -11
- package/dist/collection/components/vega-rich-text-editor/extensions/table/annotations/table-cell-annotation.js +52 -12
- package/dist/collection/components/vega-rich-text-editor/extensions/table/annotations/table-color-annotation.js +66 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/annotations/table-head-cell-annotation.js +11 -6
- package/dist/collection/components/vega-rich-text-editor/extensions/table/constants/styles.constants.js +8 -8
- package/dist/collection/components/vega-rich-text-editor/extensions/table/dto/table-block.js +1 -1
- package/dist/collection/components/vega-rich-text-editor/extensions/table/dto/table-cell-block.js +32 -1
- package/dist/collection/components/vega-rich-text-editor/extensions/table/dto/table-head-cell-block.js +1 -1
- package/dist/collection/components/vega-rich-text-editor/extensions/table/element-to-dto-strategies/td-to-table-cell-block-strategy.js +1 -1
- package/dist/collection/components/vega-rich-text-editor/extensions/table/renderers/table-cell-renderer.js +3 -1
- package/dist/collection/components/vega-rich-text-editor/extensions/table/renderers/table-renderer.js +2 -9
- package/dist/collection/components/vega-rich-text-editor/extensions/table/renderers/table-setting-popover-renderer.js +4 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/setting-event-handlers/cell-properties.js +19 -15
- package/dist/collection/components/vega-rich-text-editor/extensions/table/setting-event-handlers/merge-cells-operation.js +100 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/setting-event-handlers/setting-event-handler.abstract.js +1 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/setting-event-handlers/split-cell-operation.js +57 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/table-extension.js +14 -2
- package/dist/collection/components/vega-rich-text-editor/extensions/table/table-selection.js +102 -13
- package/dist/collection/components/vega-rich-text-editor/extensions/table/utils/table-color-manager.js +51 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/utils/utils.js +253 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/controllers/vega-rich-text-table-properties-color-controller.js +33 -2
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/renderers/vega-rich-text-cell-properties-form-field-renderer.js +1 -1
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/renderers/vega-rich-text-table-properties-basic-form-field-renderer.abstract.js +38 -6
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/renderers/vega-rich-text-table-properties-form-field-renderer.js +1 -1
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/renderers/vega-rich-text-table-properties-form-renderer.js +20 -2
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/vega-rich-text-table-properties.css +1 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/vega-rich-text-table-properties.js +24 -14
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-selection-widget/vega-rich-text-table-selection-widget.js +2 -2
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/merge-cells-button-slimmer.js +117 -0
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/row-button-slimmer.js +6 -4
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/vega-rich-text-table-setting-renderer.js +6 -1
- package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/vega-rich-text-table-setting.js +15 -8
- package/dist/collection/components/vega-rich-text-editor/test/extensions/table/annotation-handler/table-annotation-handler.test.js +41 -46
- package/dist/collection/components/vega-rich-text-editor/test/extensions/table/annotation-handler/table-cell-annotation-handler.test.js +69 -48
- package/dist/collection/components/vega-rich-text-editor/test/extensions/table/annotation-handler/table-head-cell-annotation-handler.test.js +50 -54
- package/dist/collection/components/vega-rich-text-editor/test/extensions/table/table-annotation.test.js +106 -14
- package/dist/collection/components/vega-rich-text-editor/test/extensions/table/table-cell-annotation.test.js +204 -9
- package/dist/collection/components/vega-rich-text-editor/test/extensions/table/table-color-annotation.test.js +32 -0
- package/dist/collection/components/vega-rich-text-editor/test/extensions/table/table-dto.test.js +583 -6
- package/dist/collection/components/vega-rich-text-editor/test/extensions/table/table-element-to-dto-strategies.test.js +114 -25
- package/dist/collection/components/vega-rich-text-editor/vega-rich-text-editor.js +0 -5
- package/dist/collection/components/vega-selection-chip/vega-selection-chip.js +1 -1
- package/dist/collection/components/vega-time-picker/slimmers/controllers/vega-time-picker-range-dropdown-controller.js +2 -1
- package/dist/collection/components/vega-time-picker/slimmers/controllers/vega-time-picker-single-dropdown-controller.js +2 -1
- package/dist/collection/constants/ui.js +2 -0
- package/dist/collection/helpers/event-manager/event-id/component-event-id-map.js +13 -2
- package/dist/collection/helpers/event-manager/event-id/vega-event-id.js +2 -0
- package/dist/collection/helpers/event-manager/test/component-event-id-map.test.js +3 -1
- package/dist/collection/helpers/event-manager/test/vega-event-manager.test.js +3 -1
- package/dist/collection/helpers/slimmers/element-appender/element-appender-slimmer.js +60 -32
- package/dist/collection/helpers/slimmers/element-appender/test/element-appender-slimmer.test.js +3 -2
- package/dist/collection/helpers/slimmers/element-appender/trigger-strategies/click-outside-only-to-dismiss-strategy.js +28 -0
- package/dist/collection/helpers/slimmers/element-appender/trigger-strategies/click-trigger-strategy.js +33 -0
- package/dist/collection/helpers/slimmers/element-appender/trigger-strategies/hover-trigger-strategy.js +42 -0
- package/dist/collection/helpers/slimmers/element-appender/trigger-strategies/none-trigger-strategy.js +22 -0
- package/dist/collection/helpers/slimmers/element-appender/trigger-strategies/trigger-strategy.interface.js +1 -0
- package/dist/collection/types/test/type-guard.test.js +8 -1
- package/dist/collection/types/type-guard.js +11 -0
- package/dist/collection/utils/sanitize.js +126 -0
- package/dist/collection/utils/test/sanitize.test.js +65 -0
- package/dist/esm/{app-globals-8b873b6f.js → app-globals-4146c01c.js} +9 -8
- package/dist/esm/{child-nodes-event-prevent-slimmer-a6afdb1e.js → child-nodes-event-prevent-slimmer-225e7b58.js} +1 -1
- package/dist/esm/click-outside-only-to-dismiss-strategy-3d286c1b.js +30 -0
- package/dist/esm/{code-block-76b29be1.js → code-block-36393b45.js} +3 -3
- package/dist/esm/{component-value-history-controller-slimmer.abstract-e1b0e163.js → component-value-history-controller-slimmer.abstract-82339b2b.js} +4 -4
- package/dist/esm/{content-state-03f1d302.js → content-state-e8ef033a.js} +3 -3
- package/dist/esm/{date-required-rule-a9980386.js → date-required-rule-47ecc28f.js} +1 -1
- package/dist/esm/{design-token-8fedb532.js → design-token-c57a58b4.js} +2 -2
- package/dist/esm/{dom-node-subject-observer-factory-e998eba4.js → dom-node-subject-observer-factory-d4e16f66.js} +3 -1
- package/dist/esm/{element-appender-slimmer-7b9326e2.js → element-appender-slimmer-a7341fc1.js} +160 -36
- package/dist/esm/{event-emit-slimmer-bbf6668c.js → event-emit-slimmer-1bb4b533.js} +2 -2
- package/dist/esm/{form-field-controller-slimmer-a0cff4d3.js → form-field-controller-slimmer-907bf7c2.js} +2 -2
- package/dist/esm/{image-annotation-action-47cdc068.js → image-annotation-action-82cef6e4.js} +4 -31
- package/dist/esm/{index-da7e5fe5.js → index-2466b0c0.js} +1 -1
- package/dist/esm/index.js +21 -21
- package/dist/esm/{inject-keyboard-manager-9241968c.js → inject-keyboard-manager-83d76ff5.js} +1 -1
- package/dist/esm/{internal-vega-event-manager-e799c54a.js → internal-vega-event-manager-2cbb828a.js} +13 -2
- package/dist/esm/{keyboard-manager-89acac79.js → keyboard-manager-c92808d8.js} +1 -1
- package/dist/esm/{keyboard-manager-slimmer-e303cb7d.js → keyboard-manager-slimmer-79c78ce8.js} +1 -1
- package/dist/esm/{language-extension-de6e6caf.js → language-extension-dcc43702.js} +2 -2
- package/dist/esm/loader.js +15 -15
- package/dist/esm/{month-view-generator-4bec99fd.js → month-view-generator-16192182.js} +1 -1
- package/dist/esm/{public-rules-c48cc5c9.js → public-rules-b8ea651f.js} +7 -7
- package/dist/esm/{range-af6150a8.js → range-872aad9f.js} +1 -1
- package/dist/esm/{responsive-format-facade-16da4623.js → responsive-format-facade-9278eae4.js} +5 -4
- package/dist/esm/{rich-text-editor-required-rule-7255832e.js → rich-text-editor-required-rule-36dd4242.js} +1 -1
- package/dist/esm/sanitize-fd0cb40d.js +129 -0
- package/dist/esm/{styles.constants-0dd6f7fa.js → split-cell-operation-6749f654.js} +1218 -405
- package/dist/esm/{string-format-strategy.abstract-75540c16.js → string-format-strategy.abstract-fc60db79.js} +1 -1
- package/dist/esm/{string-input-formatter-slimmer-82f85b0b.js → string-input-formatter-slimmer-7a1e8754.js} +3 -3
- package/dist/esm/{string-mask-strategy-4a18ed1a.js → string-mask-strategy-0b0accaa.js} +2 -2
- package/dist/esm/{style-formatter-6ca58f6b.js → style-formatter-e937952a.js} +2 -2
- package/dist/esm/{sub-state-notify-slimmer-4060c333.js → sub-state-notify-slimmer-2ecdba12.js} +1 -1
- package/dist/esm/{sub-state-observer-slimmer-bfa5e63e.js → sub-state-observer-slimmer-2d5dba8d.js} +1 -1
- package/dist/esm/{table-extension-c83b7a56.js → table-extension-6b31754b.js} +587 -283
- package/dist/esm/{time-required-rule-8ec1faf5.js → time-required-rule-5fa43804.js} +1 -1
- package/dist/esm/{type-guard-b48aec98.js → type-guard-c65a227d.js} +12 -1
- package/dist/esm/{valid-credit-card-number-rule-96eaf9b1.js → valid-credit-card-number-rule-666c415d.js} +1 -1
- package/dist/esm/vega-accordion.entry.js +12 -12
- package/dist/esm/vega-app-header-button.entry.js +13 -13
- package/dist/esm/vega-banner.entry.js +3 -3
- package/dist/esm/vega-box.entry.js +12 -12
- package/dist/esm/vega-breadcrumb.entry.js +4 -4
- package/dist/esm/vega-button-circle.entry.js +12 -12
- package/dist/esm/vega-button-group_2.entry.js +6 -6
- package/dist/esm/vega-button-link.entry.js +4 -4
- package/dist/esm/vega-button.entry.js +11 -11
- package/dist/esm/vega-calendar_4.entry.js +8 -8
- package/dist/esm/vega-card.entry.js +12 -12
- package/dist/esm/vega-carousel.entry.js +11 -11
- package/dist/esm/vega-checkbox_2.entry.js +6 -6
- package/dist/esm/vega-chip.entry.js +13 -13
- package/dist/esm/vega-code-block.entry.js +10 -10
- package/dist/esm/vega-color-picker.entry.js +5 -5
- package/dist/esm/vega-combo-box.entry.js +11 -10
- package/dist/esm/vega-date-picker_2.entry.js +392 -345
- package/dist/esm/vega-dialog_2.entry.js +14 -14
- package/dist/esm/vega-divider.entry.js +13 -13
- package/dist/esm/vega-dropdown_5.entry.js +40 -22
- package/dist/esm/vega-env-manager-8f8dc473.js +2 -2
- package/dist/esm/vega-field-label.entry.js +3 -3
- package/dist/esm/vega-file-uploader.entry.js +5 -5
- package/dist/esm/vega-flag-icon.entry.js +11 -11
- package/dist/esm/vega-flex.entry.js +13 -13
- package/dist/esm/vega-font.entry.js +12 -12
- package/dist/esm/vega-form.entry.js +8 -8
- package/dist/esm/vega-grid.entry.js +12 -12
- package/dist/esm/vega-icon.entry.js +12 -12
- package/dist/esm/vega-image-uploader.entry.js +14 -14
- package/dist/esm/vega-input-credit-card.entry.js +10 -10
- package/dist/esm/vega-input-numeric.entry.js +10 -10
- package/dist/esm/vega-input-passcode.entry.js +9 -9
- package/dist/esm/vega-input-phone-number.entry.js +14 -14
- package/dist/esm/vega-input-range.entry.js +6 -6
- package/dist/esm/vega-input-select.entry.js +21 -16
- package/dist/esm/vega-input.entry.js +340 -99
- package/dist/esm/vega-item-toggle.entry.js +3 -3
- package/dist/esm/vega-left-nav_5.entry.js +12 -12
- package/dist/esm/vega-loader-wrapper_2.entry.js +13 -13
- package/dist/esm/vega-page-notification_2.entry.js +1 -1
- package/dist/esm/vega-pagination-page-selector-mobile.entry.js +3 -3
- package/dist/esm/vega-pagination-page-size-selector-mobile.entry.js +1 -1
- package/dist/esm/vega-pagination.entry.js +13 -13
- package/dist/esm/vega-popover_2.entry.js +15 -15
- package/dist/esm/vega-progress-tracker_2.entry.js +12 -12
- package/dist/esm/vega-radio_2.entry.js +9 -9
- package/dist/esm/vega-rich-text-content.entry.js +14 -17
- package/dist/esm/vega-rich-text-editor_4.entry.js +144 -195
- package/dist/esm/vega-rich-text-table-properties_3.entry.js +293 -85
- package/dist/esm/vega-segment-control.entry.js +3 -3
- package/dist/esm/vega-selection-chip_2.entry.js +14 -14
- package/dist/esm/vega-selection-tile_2.entry.js +7 -7
- package/dist/esm/vega-sidenav_3.entry.js +15 -15
- package/dist/esm/vega-signature-capture.entry.js +14 -14
- package/dist/esm/vega-stepper.entry.js +6 -6
- package/dist/esm/vega-tab-group_2.entry.js +4 -4
- package/dist/esm/vega-table_11.entry.js +13 -13
- package/dist/esm/vega-textarea.entry.js +6 -6
- package/dist/esm/vega-time-picker_2.entry.js +19 -18
- package/dist/esm/vega-toggle-switch.entry.js +5 -5
- package/dist/esm/vega-tooltip_2.entry.js +14 -14
- package/dist/esm/vega.js +15 -15
- package/dist/sri/vega-sri-manifest.json +339 -715
- package/dist/types/components/vega-date-picker/assets/icons.d.ts +1 -1
- package/dist/types/components/vega-date-picker/vega-date-picker-calendar/slimmers/renderers/vega-date-picker-calendar-header-render.d.ts +20 -0
- package/dist/types/components/vega-date-picker/vega-date-picker-calendar/slimmers/renderers/vega-date-picker-calendar-renderer.d.ts +1 -0
- package/dist/types/components/vega-date-picker/vega-date-picker-calendar/slimmers/renderers/vega-date-picker-calendar-year-month-switcher-renderer.d.ts +4 -11
- package/dist/types/components/vega-date-picker/vega-date-picker-calendar/slimmers/renderers/vega-date-picker-month-item-renderer.d.ts +4 -9
- package/dist/types/components/vega-date-picker/vega-date-picker-calendar/vega-date-picker-calendar.d.ts +2 -0
- package/dist/types/components/vega-dropdown/slimmers/controllers/vega-dropdown-source-controller.d.ts +2 -0
- package/dist/types/components/vega-dropdown/vega-dropdown.d.ts +9 -4
- package/dist/types/components/vega-input/slimmers/controllers/vega-input-render-mode-controller.d.ts +27 -0
- package/dist/types/components/vega-input/slimmers/renderers/vega-input-input-renderer.d.ts +1 -0
- package/dist/types/components/vega-input/slimmers/renderers/vega-input-input-suggestions-renderer.d.ts +40 -0
- package/dist/types/components/vega-input/slimmers/renderers/vega-input-renderer.d.ts +3 -0
- package/dist/types/components/vega-input/types.d.ts +4 -0
- package/dist/types/components/vega-input/vega-input.d.ts +55 -1
- package/dist/types/components/vega-rich-text-content/vega-rich-text-content.d.ts +3 -0
- package/dist/types/components/vega-rich-text-editor/dto/annotations/custom-attribute-annotation.d.ts +1 -1
- package/dist/types/components/vega-rich-text-editor/dto/renderers/nodes/text-node-renderer.d.ts +0 -2
- package/dist/types/components/vega-rich-text-editor/extensions/table/action-handler-strategies/insert-table-row-strategy.d.ts +17 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/action-handler-strategies/merge-cells-strategy.d.ts +38 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/action-handler-strategies/split-cell-horizontally-strategy.d.ts +43 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/action-handler-strategies/split-cell-vertically-strategy.d.ts +27 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/actions/merge-cells-action.d.ts +33 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/actions/split-cell-horizontally-action.d.ts +10 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/actions/split-cell-vertically-action.d.ts +10 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/annotation-handler/table-annotation-handler-base.d.ts +0 -7
- package/dist/types/components/vega-rich-text-editor/extensions/table/annotation-handler/table-cell-annotation-handler.d.ts +14 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/annotations/table-annotation.d.ts +15 -6
- package/dist/types/components/vega-rich-text-editor/extensions/table/annotations/table-cell-annotation.d.ts +11 -2
- package/dist/types/components/vega-rich-text-editor/extensions/table/annotations/table-color-annotation.d.ts +43 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/annotations/table-head-cell-annotation.d.ts +2 -2
- package/dist/types/components/vega-rich-text-editor/extensions/table/constants/styles.constants.d.ts +2 -2
- package/dist/types/components/vega-rich-text-editor/extensions/table/dto/table-cell-block.d.ts +19 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/renderers/table-dynamic-popover-renderer.d.ts +2 -2
- package/dist/types/components/vega-rich-text-editor/extensions/table/renderers/table-renderer.d.ts +1 -8
- package/dist/types/components/vega-rich-text-editor/extensions/table/setting-event-handlers/merge-cells-operation.d.ts +44 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/setting-event-handlers/setting-event-handler.abstract.d.ts +2 -1
- package/dist/types/components/vega-rich-text-editor/extensions/table/setting-event-handlers/split-cell-operation.d.ts +31 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/table-extension.d.ts +3 -3
- package/dist/types/components/vega-rich-text-editor/extensions/table/table-selection.d.ts +15 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/utils/table-color-manager.d.ts +26 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/utils/utils.d.ts +102 -2
- package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/controllers/vega-rich-text-table-properties-color-controller.d.ts +16 -1
- package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/renderers/vega-rich-text-table-properties-basic-form-field-renderer.abstract.d.ts +18 -6
- package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/renderers/vega-rich-text-table-properties-form-renderer.d.ts +7 -1
- package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/vega-rich-text-table-properties.d.ts +14 -11
- package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-selection-widget/vega-rich-text-table-selection-widget.d.ts +3 -3
- package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/merge-cells-button-slimmer.d.ts +23 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/vega-rich-text-table-setting-renderer.d.ts +1 -0
- package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/vega-rich-text-table-setting.d.ts +9 -6
- package/dist/types/components/vega-rich-text-editor/interface.d.ts +0 -5
- package/dist/types/components/vega-rich-text-editor/test/extensions/table/annotation-handler/table-cell-annotation-handler.test.d.ts +8 -1
- package/dist/types/components/vega-rich-text-editor/test/extensions/table/table-color-annotation.test.d.ts +1 -0
- package/dist/types/components/vega-rich-text-editor/vega-rich-text-editor.d.ts +0 -2
- package/dist/types/components.d.ts +72 -30
- package/dist/types/constants/ui.d.ts +1 -1
- package/dist/types/helpers/event-manager/event-id/vega-event-id.d.ts +2 -0
- package/dist/types/helpers/slimmers/element-appender/element-appender-slimmer.d.ts +4 -9
- package/dist/types/helpers/slimmers/element-appender/trigger-strategies/click-outside-only-to-dismiss-strategy.d.ts +21 -0
- package/dist/types/helpers/slimmers/element-appender/trigger-strategies/click-trigger-strategy.d.ts +21 -0
- package/dist/types/helpers/slimmers/element-appender/trigger-strategies/hover-trigger-strategy.d.ts +22 -0
- package/dist/types/helpers/slimmers/element-appender/trigger-strategies/none-trigger-strategy.d.ts +18 -0
- package/dist/types/helpers/slimmers/element-appender/trigger-strategies/trigger-strategy.interface.d.ts +37 -0
- package/dist/types/types/components.type.d.ts +3 -1
- package/dist/types/types/type-guard.d.ts +8 -0
- package/dist/types/types/ui.type.d.ts +9 -0
- package/dist/types/utils/sanitize.d.ts +71 -0
- package/dist/types/utils/spec-utils.d.ts +2 -0
- package/dist/types/utils/test/sanitize.test.d.ts +1 -0
- package/dist/vega/index.esm.js +1 -57
- package/dist/vega/{p-780cbfb0.entry.js → p-01dc2e48.entry.js} +1 -1
- package/dist/vega/p-0459a474.entry.js +1 -0
- package/dist/vega/p-0770a0eb.entry.js +1 -0
- package/dist/vega/{p-a924c1e2.entry.js → p-0bf4a3a7.entry.js} +1 -1
- package/dist/vega/{p-ff9a0e6e.js → p-0d57293b.js} +1 -1
- package/dist/vega/{p-22da15d7.entry.js → p-1199ebf6.entry.js} +1 -1
- package/dist/vega/p-11a6c1b7.js +1 -0
- package/dist/vega/{p-79e8236a.entry.js → p-1415d93b.entry.js} +1 -1
- package/dist/vega/p-1431c8b9.js +1 -0
- package/dist/vega/p-18560714.entry.js +1 -0
- package/dist/vega/{p-a007b493.entry.js → p-1a161082.entry.js} +1 -1
- package/dist/vega/{p-161b9c5b.js → p-1f83cebf.js} +1 -1
- package/dist/vega/{p-16af7681.js → p-20010bd6.js} +1 -1
- package/dist/vega/p-205d8401.js +1 -0
- package/dist/vega/{p-29a9c8f5.entry.js → p-20a98a99.entry.js} +1 -1
- package/dist/vega/{p-86caa739.entry.js → p-228784f7.entry.js} +1 -1
- package/dist/vega/{p-b91c2c9d.js → p-22989693.js} +1 -1
- package/dist/vega/{p-1bda4016.entry.js → p-273911b2.entry.js} +1 -1
- package/dist/vega/{p-e797bf8d.entry.js → p-28e630b2.entry.js} +1 -1
- package/dist/vega/{p-d466baf7.js → p-29f6b2d5.js} +1 -1
- package/dist/vega/{p-6d9731c1.entry.js → p-2af2e1ad.entry.js} +1 -1
- package/dist/vega/{p-d55365b9.entry.js → p-2af78c38.entry.js} +1 -1
- package/dist/vega/{p-c3d388b5.entry.js → p-2c830cba.entry.js} +1 -1
- package/dist/vega/{p-61ae4e9c.entry.js → p-3224d794.entry.js} +1 -1
- package/dist/vega/{p-216f3436.entry.js → p-326b5392.entry.js} +1 -1
- package/dist/vega/{p-69af3422.entry.js → p-3413a678.entry.js} +1 -1
- package/dist/vega/p-3532aa12.js +1 -0
- package/dist/vega/p-395cdd84.entry.js +1 -0
- package/dist/vega/{p-9aac9879.entry.js → p-3a6ff599.entry.js} +1 -1
- package/dist/vega/p-3be82c0f.entry.js +1 -0
- package/dist/vega/p-3c0f55f7.entry.js +1 -0
- package/dist/vega/{p-10ffb765.js → p-3e30567a.js} +1 -1
- package/dist/vega/p-3e5f362f.js +1 -0
- package/dist/vega/p-42cd1fde.js +1 -0
- package/dist/vega/p-476a173a.js +1 -0
- package/dist/vega/p-4b6c60cb.entry.js +1 -0
- package/dist/vega/{p-12a97dad.entry.js → p-4c36b528.entry.js} +1 -1
- package/dist/vega/{p-fa34ace2.entry.js → p-4ecf0ee7.entry.js} +1 -1
- package/dist/vega/{p-813b2915.entry.js → p-4f4c7593.entry.js} +1 -1
- package/dist/vega/p-585edae4.entry.js +1 -0
- package/dist/vega/{p-39d56e3d.js → p-5b048141.js} +1 -1
- package/dist/vega/p-5f377954.js +1 -1
- package/dist/vega/{p-63246470.js → p-5fdb9047.js} +1 -1
- package/dist/vega/{p-d4e35d2e.entry.js → p-60483e3d.entry.js} +1 -1
- package/dist/vega/{p-de70aac1.js → p-60851f9d.js} +1 -1
- package/dist/vega/{p-73688c4e.entry.js → p-61145506.entry.js} +1 -1
- package/dist/vega/{p-8162980c.js → p-61ddae59.js} +1 -1
- package/dist/vega/{p-98b78c75.entry.js → p-64386be8.entry.js} +1 -1
- package/dist/vega/{p-73689ec0.entry.js → p-6490b69a.entry.js} +1 -1
- package/dist/vega/{p-50a506ea.entry.js → p-6bc1552e.entry.js} +1 -1
- package/dist/vega/{p-206245d2.entry.js → p-6e4e7192.entry.js} +1 -1
- package/dist/vega/{p-8ac453cb.entry.js → p-76d144f5.entry.js} +1 -1
- package/dist/vega/{p-dc2813eb.entry.js → p-76eb9cd0.entry.js} +1 -1
- package/dist/vega/{p-e788598a.entry.js → p-77c9949d.entry.js} +1 -1
- package/dist/vega/p-8187878e.js +1 -0
- package/dist/vega/p-8198a77c.js +1 -0
- package/dist/vega/{p-0e4cecbd.entry.js → p-82ad1006.entry.js} +1 -1
- package/dist/vega/{p-8a4d8139.entry.js → p-839c9d62.entry.js} +1 -1
- package/dist/vega/{p-d07d04e0.entry.js → p-849f78a7.entry.js} +1 -1
- package/dist/vega/{p-ac4bd1f8.js → p-85bfa0f7.js} +1 -1
- package/dist/vega/{p-dd5d917b.entry.js → p-87764570.entry.js} +1 -1
- package/dist/vega/{p-abf871cd.entry.js → p-88c894e8.entry.js} +1 -1
- package/dist/vega/{p-c00adad9.js → p-89083d63.js} +1 -1
- package/dist/vega/{p-a8dad05d.js → p-920719ad.js} +1 -1
- package/dist/vega/p-9472d19a.js +1 -0
- package/dist/vega/{p-c6d98c60.entry.js → p-96657262.entry.js} +1 -1
- package/dist/vega/p-979e4bd4.entry.js +1 -0
- package/dist/vega/{p-f6eab527.entry.js → p-9c624e03.entry.js} +1 -1
- package/dist/vega/{p-088f4613.entry.js → p-a01f985f.entry.js} +1 -1
- package/dist/vega/{p-a4ec6575.js → p-a2aeb646.js} +1 -1
- package/dist/vega/{p-22c76be7.entry.js → p-a495463f.entry.js} +1 -1
- package/dist/vega/p-b4ea3fad.js +1 -0
- package/dist/vega/{p-151b1deb.js → p-b56b0b89.js} +1 -1
- package/dist/vega/{p-3bc7e162.entry.js → p-b5b75a2f.entry.js} +1 -1
- package/dist/vega/{p-d991fb11.js → p-badad9ed.js} +1 -1
- package/dist/vega/{p-24766b9d.entry.js → p-bccaf3d2.entry.js} +1 -1
- package/dist/vega/{p-e13c163c.entry.js → p-bde5c990.entry.js} +1 -1
- package/dist/vega/{p-ab0e013c.entry.js → p-beb6c1ce.entry.js} +1 -1
- package/dist/vega/{p-068ee55e.entry.js → p-c02b01ec.entry.js} +1 -1
- package/dist/vega/p-c1fdcb62.js +1 -0
- package/dist/vega/{p-5d2704c1.entry.js → p-c5e7035b.entry.js} +1 -1
- package/dist/vega/{p-5367eaab.js → p-c841be8d.js} +1 -1
- package/dist/vega/{p-6f08e3e1.entry.js → p-cd078909.entry.js} +1 -1
- package/dist/vega/{p-d1d0f08a.js → p-d0e31633.js} +1 -1
- package/dist/vega/{p-a439e59b.entry.js → p-d5c09a94.entry.js} +1 -1
- package/dist/vega/{p-c8ad47c9.js → p-d907f8a2.js} +1 -1
- package/dist/vega/{p-6c1ef2ed.js → p-dd11f735.js} +1 -1
- package/dist/vega/{p-c9541fc2.entry.js → p-de850e98.entry.js} +1 -1
- package/dist/vega/{p-3d85411d.js → p-e16b3adf.js} +1 -1
- package/dist/vega/{p-34a994a1.entry.js → p-e1dd23f8.entry.js} +1 -1
- package/dist/vega/{p-7ca9f6f1.js → p-e1de1cdc.js} +1 -1
- package/dist/vega/{p-1f4a814e.entry.js → p-e7cfb6b6.entry.js} +1 -1
- package/dist/vega/{p-ddf81373.js → p-e819940c.js} +1 -1
- package/dist/vega/{p-e0cefd90.entry.js → p-e95ed6f3.entry.js} +1 -1
- package/dist/vega/p-ebb14c84.js +1 -0
- package/dist/vega/{p-f519cdc3.entry.js → p-f0a8aed3.entry.js} +1 -1
- package/dist/vega/p-f2b8abd3.entry.js +1 -0
- package/dist/vega/{p-d4719c14.entry.js → p-fb238751.entry.js} +1 -1
- package/dist/vega/p-fdebc47f.entry.js +1 -0
- package/dist/vega/vega.esm.js +1 -172
- package/package.json +1 -1
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/text-node-color-controller.js +0 -51
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/text-node-rendering-registry.js +0 -26
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/text-node-color-controller.d.ts +0 -22
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/text-node-rendering-registry.d.ts +0 -22
- package/dist/vega/app-globals-955a2b3b.js +0 -427
- package/dist/vega/child-nodes-event-prevent-slimmer-a604a6dd.js +0 -156
- package/dist/vega/design-token-56b26205.js +0 -402
- package/dist/vega/element-appender-slimmer-8355fb28.js +0 -1508
- package/dist/vega/event-emit-slimmer-7a14f5e9.js +0 -265
- package/dist/vega/internal-vega-event-manager-8c62c88e.js +0 -458
- package/dist/vega/p-08b4d097.entry.js +0 -1
- package/dist/vega/p-207cfa6a.js +0 -1
- package/dist/vega/p-213be5e9.entry.js +0 -1
- package/dist/vega/p-224a4f3f.entry.js +0 -1
- package/dist/vega/p-40660c09.js +0 -1
- package/dist/vega/p-550ce71a.entry.js +0 -1
- package/dist/vega/p-6665d083.entry.js +0 -1
- package/dist/vega/p-7172332a.entry.js +0 -1
- package/dist/vega/p-82ec9721.entry.js +0 -1
- package/dist/vega/p-99e3dcab.js +0 -1
- package/dist/vega/p-9a83a6b0.js +0 -1
- package/dist/vega/p-a4d0ab07.js +0 -1
- package/dist/vega/p-a6e03df4.entry.js +0 -1
- package/dist/vega/p-c335088c.js +0 -1
- package/dist/vega/p-c674b07c.js +0 -1
- package/dist/vega/p-d1349401.entry.js +0 -1
- package/dist/vega/p-d2033624.js +0 -1
- package/dist/vega/p-db482ee1.js +0 -1
- package/dist/vega/p-f4b46f6b.entry.js +0 -1
- package/dist/vega/p-fbfb4c70.entry.js +0 -1
- package/dist/vega/p-ff57c872.js +0 -1
- package/dist/vega/p-ff921d10.js +0 -1
- package/dist/vega/public-api-8dd022fa.js +0 -6043
- package/dist/vega/public-api-baaf7593.js +0 -4
- package/dist/vega/responsive-format-facade-98596535.js +0 -913
- package/dist/vega/style-formatter-0ae102e9.js +0 -32
- package/dist/vega/vega-accordion.entry.js +0 -291
- package/dist/vega/vega-app-header-button.entry.js +0 -452
- package/dist/vega/vega-banner.entry.js +0 -351
- package/dist/vega/vega-box.entry.js +0 -353
- package/dist/vega/vega-breadcrumb.entry.js +0 -249
- package/dist/vega/vega-button-circle.entry.js +0 -245
- package/dist/vega/vega-button-group.entry.js +0 -203
- package/dist/vega/vega-button-link.entry.js +0 -226
- package/dist/vega/vega-button.entry.js +0 -259
- package/dist/vega/vega-calendar.entry.js +0 -3884
- package/dist/vega/vega-card.entry.js +0 -226
- package/dist/vega/vega-carousel.entry.js +0 -540
- package/dist/vega/vega-checkbox-group.entry.js +0 -266
- package/dist/vega/vega-checkbox.entry.js +0 -335
- package/dist/vega/vega-chip.entry.js +0 -321
- package/dist/vega/vega-code-block.entry.js +0 -4372
- package/dist/vega/vega-color-picker.entry.js +0 -258
- package/dist/vega/vega-combo-box.entry.js +0 -748
- package/dist/vega/vega-date-picker-calendar.entry.js +0 -1381
- package/dist/vega/vega-date-picker.entry.js +0 -1646
- package/dist/vega/vega-dialog.entry.js +0 -158
- package/dist/vega/vega-divider.entry.js +0 -179
- package/dist/vega/vega-dropdown-content-box.entry.js +0 -57
- package/dist/vega/vega-dropdown-item.entry.js +0 -352
- package/dist/vega/vega-dropdown.entry.js +0 -2136
- package/dist/vega/vega-field-label.entry.js +0 -182
- package/dist/vega/vega-file-uploader.entry.js +0 -751
- package/dist/vega/vega-flag-icon.entry.js +0 -216
- package/dist/vega/vega-flex.entry.js +0 -224
- package/dist/vega/vega-font.entry.js +0 -327
- package/dist/vega/vega-form.entry.js +0 -1008
- package/dist/vega/vega-grid.entry.js +0 -129
- package/dist/vega/vega-icon.entry.js +0 -256
- package/dist/vega/vega-image-uploader.entry.js +0 -977
- package/dist/vega/vega-input-credit-card.entry.js +0 -549
- package/dist/vega/vega-input-numeric.entry.js +0 -471
- package/dist/vega/vega-input-passcode.entry.js +0 -728
- package/dist/vega/vega-input-phone-number.entry.js +0 -9143
- package/dist/vega/vega-input-range.entry.js +0 -693
- package/dist/vega/vega-input-select.entry.js +0 -1268
- package/dist/vega/vega-input.entry.js +0 -1735
- package/dist/vega/vega-item-toggle.entry.js +0 -190
- package/dist/vega/vega-left-nav-group.entry.js +0 -433
- package/dist/vega/vega-left-nav-link.entry.js +0 -317
- package/dist/vega/vega-left-nav-section.entry.js +0 -97
- package/dist/vega/vega-left-nav.entry.js +0 -654
- package/dist/vega/vega-loading-indicator.entry.js +0 -209
- package/dist/vega/vega-modal.entry.js +0 -1287
- package/dist/vega/vega-nav-card.entry.js +0 -163
- package/dist/vega/vega-pagination-page-selector-mobile.entry.js +0 -214
- package/dist/vega/vega-pagination.entry.js +0 -629
- package/dist/vega/vega-popover-content-box.entry.js +0 -101
- package/dist/vega/vega-popover.entry.js +0 -362
- package/dist/vega/vega-progress-tracker.entry.js +0 -757
- package/dist/vega/vega-radio-group.entry.js +0 -496
- package/dist/vega/vega-radio.entry.js +0 -272
- package/dist/vega/vega-rich-text-editor-toolbar-button.entry.js +0 -169
- package/dist/vega/vega-rich-text-editor.entry.js +0 -4107
- package/dist/vega/vega-rich-text-image-editor.entry.js +0 -216
- package/dist/vega/vega-rich-text-link-editor.entry.js +0 -238
- package/dist/vega/vega-rich-text-table-properties.entry.js +0 -641
- package/dist/vega/vega-rich-text-table-setting.entry.js +0 -525
- package/dist/vega/vega-segment-control.entry.js +0 -350
- package/dist/vega/vega-selection-chip-group.entry.js +0 -447
- package/dist/vega/vega-selection-chip.entry.js +0 -443
- package/dist/vega/vega-selection-tile-group.entry.js +0 -438
- package/dist/vega/vega-selection-tile.entry.js +0 -409
- package/dist/vega/vega-sidenav-link.entry.js +0 -160
- package/dist/vega/vega-sidenav.entry.js +0 -766
- package/dist/vega/vega-signature-capture.entry.js +0 -589
- package/dist/vega/vega-stepper.entry.js +0 -292
- package/dist/vega/vega-tab-group-panel.entry.js +0 -79
- package/dist/vega/vega-tab-group.entry.js +0 -1281
- package/dist/vega/vega-table-body.entry.js +0 -48
- package/dist/vega/vega-table-cell.entry.js +0 -243
- package/dist/vega/vega-table-foot-cell.entry.js +0 -169
- package/dist/vega/vega-table-foot-row.entry.js +0 -219
- package/dist/vega/vega-table-foot.entry.js +0 -136
- package/dist/vega/vega-table-head-cell.entry.js +0 -339
- package/dist/vega/vega-table-head-row.entry.js +0 -416
- package/dist/vega/vega-table-head.entry.js +0 -113
- package/dist/vega/vega-table-row.entry.js +0 -666
- package/dist/vega/vega-table.entry.js +0 -3707
- package/dist/vega/vega-textarea.entry.js +0 -329
- package/dist/vega/vega-time-picker.entry.js +0 -2039
- package/dist/vega/vega-toggle-switch.entry.js +0 -194
- package/dist/vega/vega-tooltip.entry.js +0 -339
|
@@ -1,4372 +0,0 @@
|
|
|
1
|
-
import { h, F as Fragment, r as registerInstance, e as createEvent, g as Host, i as getElement } from './index-01a2f9c9.js';
|
|
2
|
-
import { V as VegaSlimmer, b as MapToComponentField, M as MapToComponentMethod, m as methodPlaceholder, e as InjectVegaGlobalSlimmer, a as InjectVegaSlimmer } from './vega-slimmer-core-83fd0e22.js';
|
|
3
|
-
import { V as VegaComponentUsageRuntimeMetricsSlimmer } from './component-usage-runtime-metrics-0513698f.js';
|
|
4
|
-
import { s as sanitizeVegaComponent } from './component-0cff85cf.js';
|
|
5
|
-
import { a as VegaInternalIconManager } from './internal-icon-manager-9279071a.js';
|
|
6
|
-
import { t as trashCan } from './trash-can-8819a939.js';
|
|
7
|
-
import { D as DomNodeSubjectObserverFactory } from './dom-node-subject-observer-factory-3b49c6b3.js';
|
|
8
|
-
import { h as VegaChange, a as VegaClick, n as VegaRemove } from './vega-event-id-61c8bd9f.js';
|
|
9
|
-
import { Q as CodeLanguage } from './code-block-b5f8fc8a.js';
|
|
10
|
-
import { a as arrayToClassString } from './ui-5f775fd9.js';
|
|
11
|
-
import { c as createEventEmitSlimmer } from './event-emit-slimmer-61db3eef.js';
|
|
12
|
-
import { d as deepEqual } from './object-66c37948.js';
|
|
13
|
-
import './index-9fdb7060.js';
|
|
14
|
-
import { A as AutoRunWhenReRenderTaskQueueSlimmer, S as ShadowSelectionPolyfill, a as SelectionController, C as ComponentValueHistoryControllerSlimmer } from './component-value-history-controller-slimmer.abstract-bacd9d3c.js';
|
|
15
|
-
import { C as ChangeManager } from './change-manager-b115783e.js';
|
|
16
|
-
import { d as domNodeSubjectFactory } from './dom-node-subject-factory-5798693b.js';
|
|
17
|
-
import { q as VegaInternalCodeBlockSelectionChange } from './vega-internal-event-id-b65a01a3.js';
|
|
18
|
-
import { d as debounce } from './timer-9321173b.js';
|
|
19
|
-
import { C as ChildNodesEventPreventSlimmer } from './child-nodes-event-prevent-slimmer-fcfc9c8b.js';
|
|
20
|
-
import { c as createCommonjsModule, a as commonjsGlobal } from './_commonjsHelpers-2088bffa.js';
|
|
21
|
-
import { C as ComponentGlobalStyleSlimmer } from './component-global-style-slimmer-6ecf43d7.js';
|
|
22
|
-
import { T as TranslationSlimmer } from './translation-slimmer-3c4e2876.js';
|
|
23
|
-
import './create-public-api-runtime-metrics-slimmer-8565f08b.js';
|
|
24
|
-
import './observer-3959f9dd.js';
|
|
25
|
-
import './string-a953eafc.js';
|
|
26
|
-
import './type-guard-09acedc9.js';
|
|
27
|
-
import './breakpoints-d9faf11c.js';
|
|
28
|
-
import './ui-189dae23.js';
|
|
29
|
-
import './typography-396de03f.js';
|
|
30
|
-
import './index-81ce67e2.js';
|
|
31
|
-
import './static-subject-title-6fdf8c8b.js';
|
|
32
|
-
import './dark-mode-style-controller-e2a2f76c.js';
|
|
33
|
-
import './vega-nonce-manager-497e5eb5.js';
|
|
34
|
-
import './try-get-document-bef0f526.js';
|
|
35
|
-
import './internal-vega-event-manager-826279b7.js';
|
|
36
|
-
import './range-429fb0e2.js';
|
|
37
|
-
import './synchronize-task-queue-ac8acc3b.js';
|
|
38
|
-
import './keyboard-manager-slimmer-a7b44d74.js';
|
|
39
|
-
import './keyboard-manager-3c463777.js';
|
|
40
|
-
import './vega-env-manager-8f8dc473.js';
|
|
41
|
-
import './feature-flag-controller-24b9f956.js';
|
|
42
|
-
import './index-1f9eab8f.js';
|
|
43
|
-
|
|
44
|
-
var __decorate$c = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
45
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
46
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
47
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
48
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* The code block editor renderer class.
|
|
52
|
-
*/
|
|
53
|
-
class VegaCodeBlockRenderer extends VegaSlimmer {
|
|
54
|
-
constructor() {
|
|
55
|
-
super(...arguments);
|
|
56
|
-
this.languageDropdownProps = {
|
|
57
|
-
searchable: false,
|
|
58
|
-
};
|
|
59
|
-
this.languageOptions = Object.keys(CodeLanguage).map((key) => {
|
|
60
|
-
return { id: CodeLanguage[key], displayName: key };
|
|
61
|
-
});
|
|
62
|
-
/**
|
|
63
|
-
* Handle the code language update.
|
|
64
|
-
*
|
|
65
|
-
* @param {HTMLVegaInputSelectElement} node - The language select element.
|
|
66
|
-
*/
|
|
67
|
-
this.handleLanguageChange = (node) => {
|
|
68
|
-
DomNodeSubjectObserverFactory.addUniqueObserverToNode(node, VegaChange, (payload) => {
|
|
69
|
-
var _a;
|
|
70
|
-
this.valueController.updateValue((_a = this.value) === null || _a === void 0 ? void 0 : _a.code, payload.detail);
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Handle the code language update.
|
|
75
|
-
*
|
|
76
|
-
* @param {HTMLVegaButtonCircleElement} node - The delete button.
|
|
77
|
-
*/
|
|
78
|
-
this.handleDeleteClick = (node) => {
|
|
79
|
-
DomNodeSubjectObserverFactory.addUniqueObserverToNode(node, VegaClick, () => {
|
|
80
|
-
const event = this.removeEventEmitter.emit();
|
|
81
|
-
if (!event.defaultPrevented) {
|
|
82
|
-
this.host.remove();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Get the toolbar container element ref.
|
|
89
|
-
*
|
|
90
|
-
* @returns {HTMLDivElement} - The div element.
|
|
91
|
-
*/
|
|
92
|
-
getToolbarContainerRef() {
|
|
93
|
-
return this.toolbarContainerRef;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Render the code block editor toolbar element or copy element.
|
|
97
|
-
*
|
|
98
|
-
* @returns {HTMLElement} - The code block operate action button.
|
|
99
|
-
*/
|
|
100
|
-
render() {
|
|
101
|
-
return (h(Fragment, null,
|
|
102
|
-
h("div", { part: "editor-toolbar", contenteditable: false, class: {
|
|
103
|
-
'editor-toolbar': !this.readOnly,
|
|
104
|
-
'copy-button-container': this.showCopyButton && this.readOnly,
|
|
105
|
-
}, ref: (node) => (this.toolbarContainerRef = node) },
|
|
106
|
-
this.renderEditorToolbar(),
|
|
107
|
-
this.copyButtonRenderer.render()),
|
|
108
|
-
this.contentRenderer.render()));
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Render a language select and delete button.
|
|
112
|
-
*
|
|
113
|
-
* @returns {Nullable<HTMLElement>} The editor toolbar container element.
|
|
114
|
-
*/
|
|
115
|
-
renderEditorToolbar() {
|
|
116
|
-
var _a, _b;
|
|
117
|
-
if (!this.readOnly) {
|
|
118
|
-
return (h(Fragment, null,
|
|
119
|
-
h("vega-input-select", { source: this.languageOptions, value: (_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.language) !== null && _b !== void 0 ? _b : '', disabled: this.disabled, placeholder: this.translationSlimmer.t('Select Language'), size: "small", vegaDropdownProps: this.languageDropdownProps, exportparts: "select-container, selected-box, placeholder, toggle-icon-container, toggle-icon", ref: this.handleLanguageChange }),
|
|
120
|
-
h("vega-button-circle", { key: "delete-button", disabled: this.disabled, label: this.translationSlimmer.t('Delete Code'), icon: VegaInternalIconManager.getIconKey('trash-can'), iconColor: "text-secondary", variant: "icon-only", size: "extra-small", ref: this.handleDeleteClick })));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
(() => {
|
|
125
|
-
VegaInternalIconManager.register({
|
|
126
|
-
'trash-can': trashCan,
|
|
127
|
-
});
|
|
128
|
-
})();
|
|
129
|
-
__decorate$c([
|
|
130
|
-
MapToComponentField()
|
|
131
|
-
], VegaCodeBlockRenderer.prototype, "readOnly", void 0);
|
|
132
|
-
__decorate$c([
|
|
133
|
-
MapToComponentField()
|
|
134
|
-
], VegaCodeBlockRenderer.prototype, "host", void 0);
|
|
135
|
-
__decorate$c([
|
|
136
|
-
MapToComponentField()
|
|
137
|
-
], VegaCodeBlockRenderer.prototype, "disabled", void 0);
|
|
138
|
-
__decorate$c([
|
|
139
|
-
MapToComponentField()
|
|
140
|
-
], VegaCodeBlockRenderer.prototype, "showCopyButton", void 0);
|
|
141
|
-
__decorate$c([
|
|
142
|
-
MapToComponentField()
|
|
143
|
-
], VegaCodeBlockRenderer.prototype, "value", void 0);
|
|
144
|
-
__decorate$c([
|
|
145
|
-
MapToComponentField()
|
|
146
|
-
], VegaCodeBlockRenderer.prototype, "contentRenderer", void 0);
|
|
147
|
-
__decorate$c([
|
|
148
|
-
MapToComponentField()
|
|
149
|
-
], VegaCodeBlockRenderer.prototype, "valueController", void 0);
|
|
150
|
-
__decorate$c([
|
|
151
|
-
MapToComponentField()
|
|
152
|
-
], VegaCodeBlockRenderer.prototype, "removeEventEmitter", void 0);
|
|
153
|
-
__decorate$c([
|
|
154
|
-
MapToComponentField()
|
|
155
|
-
], VegaCodeBlockRenderer.prototype, "translationSlimmer", void 0);
|
|
156
|
-
__decorate$c([
|
|
157
|
-
MapToComponentField()
|
|
158
|
-
], VegaCodeBlockRenderer.prototype, "copyButtonRenderer", void 0);
|
|
159
|
-
|
|
160
|
-
var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
161
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
162
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
163
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
164
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* The code block content renderer class.
|
|
168
|
-
*/
|
|
169
|
-
class VegaCodeBlockContentRenderer extends VegaSlimmer {
|
|
170
|
-
constructor() {
|
|
171
|
-
super(...arguments);
|
|
172
|
-
/**
|
|
173
|
-
* The code input area focus.
|
|
174
|
-
*/
|
|
175
|
-
this.handleFocus = () => {
|
|
176
|
-
if (!this.readOnly && !this.disabled) {
|
|
177
|
-
this.host.classList.add('focus');
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
/**
|
|
181
|
-
* The code input area blur.
|
|
182
|
-
*/
|
|
183
|
-
this.handleBlur = () => {
|
|
184
|
-
this.host.classList.remove('focus');
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Get the editable root element.
|
|
189
|
-
*
|
|
190
|
-
* @returns {HTMLElement} - The root element.
|
|
191
|
-
*/
|
|
192
|
-
getCodeContentContainerRef() {
|
|
193
|
-
return this.codeContentContainerRef;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Add focus and blur event listener.
|
|
197
|
-
*/
|
|
198
|
-
registerEventListener() {
|
|
199
|
-
if (this.codeContentContainerRef) {
|
|
200
|
-
this.codeContentContainerRef.addEventListener('focusin', this.handleFocus);
|
|
201
|
-
this.codeContentContainerRef.addEventListener('focusout', this.handleBlur);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Remove the event listener.
|
|
206
|
-
*/
|
|
207
|
-
unregisterEventListener() {
|
|
208
|
-
if (this.codeContentContainerRef) {
|
|
209
|
-
this.codeContentContainerRef.removeEventListener('focusin', this.handleFocus);
|
|
210
|
-
this.codeContentContainerRef.removeEventListener('focusout', this.handleBlur);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Render the code content.
|
|
215
|
-
*
|
|
216
|
-
* @returns {HTMLElement} - The code element.
|
|
217
|
-
*/
|
|
218
|
-
render() {
|
|
219
|
-
var _a;
|
|
220
|
-
const codeNodes = this.contentParseController.parseCode();
|
|
221
|
-
const language = ((_a = this.value) === null || _a === void 0 ? void 0 : _a.language) || '';
|
|
222
|
-
return (h(Fragment, null,
|
|
223
|
-
h("style", null, this.getLineNumberStyleVariable(codeNodes)),
|
|
224
|
-
h("code", { role: "textbox", tabIndex: 0, spellcheck: false, ref: (node) => (this.codeContentContainerRef = node), contenteditable: this.readOnly || this.disabled ? false : true, "data-language": language, innerHTML: codeNodes
|
|
225
|
-
.map((codeNode) => this.renderCodeNode(codeNode))
|
|
226
|
-
.join('') })));
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Render the code node the html element.
|
|
230
|
-
*
|
|
231
|
-
* @param {CodeNodeType} codeNode - The code node object.
|
|
232
|
-
* @returns {string} - The html element.
|
|
233
|
-
*/
|
|
234
|
-
renderCodeNode(codeNode) {
|
|
235
|
-
const { key, className, mark, text } = codeNode;
|
|
236
|
-
return `<span key='${key}' class='${className}' data-mark='${mark}' data-index='${key}'>${text}</span>`;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Dynamic calculate line number element width and update the margin and padding variable.
|
|
240
|
-
*
|
|
241
|
-
* @param {CodeNodeType[]} codeNodes - The code node array.
|
|
242
|
-
* @returns {string} - The style content.
|
|
243
|
-
*/
|
|
244
|
-
getLineNumberStyleVariable(codeNodes) {
|
|
245
|
-
const lineCountArray = codeNodes.filter((item) => {
|
|
246
|
-
return item.text === '\n';
|
|
247
|
-
});
|
|
248
|
-
const singleTextLength = 10;
|
|
249
|
-
const gap = 16;
|
|
250
|
-
const space = (lineCountArray.length + 1).toString().length * singleTextLength;
|
|
251
|
-
return `code{--v-code-line-number-width:${space}px;--v-code-line-number-ml:-${space + gap}px;--v-code-block-pl:${space + gap}px}`;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
__decorate$b([
|
|
255
|
-
MapToComponentField()
|
|
256
|
-
], VegaCodeBlockContentRenderer.prototype, "host", void 0);
|
|
257
|
-
__decorate$b([
|
|
258
|
-
MapToComponentField()
|
|
259
|
-
], VegaCodeBlockContentRenderer.prototype, "readOnly", void 0);
|
|
260
|
-
__decorate$b([
|
|
261
|
-
MapToComponentField()
|
|
262
|
-
], VegaCodeBlockContentRenderer.prototype, "disabled", void 0);
|
|
263
|
-
__decorate$b([
|
|
264
|
-
MapToComponentField()
|
|
265
|
-
], VegaCodeBlockContentRenderer.prototype, "value", void 0);
|
|
266
|
-
__decorate$b([
|
|
267
|
-
MapToComponentField()
|
|
268
|
-
], VegaCodeBlockContentRenderer.prototype, "contentParseController", void 0);
|
|
269
|
-
__decorate$b([
|
|
270
|
-
MapToComponentMethod('componentDidLoad')
|
|
271
|
-
], VegaCodeBlockContentRenderer.prototype, "registerEventListener", null);
|
|
272
|
-
__decorate$b([
|
|
273
|
-
MapToComponentMethod('disconnectedCallback')
|
|
274
|
-
], VegaCodeBlockContentRenderer.prototype, "unregisterEventListener", null);
|
|
275
|
-
|
|
276
|
-
var __decorate$a = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
277
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
278
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
279
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
280
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* The component value controller.
|
|
284
|
-
*/
|
|
285
|
-
class VegaCodeBlockValueController extends VegaSlimmer {
|
|
286
|
-
/**
|
|
287
|
-
* Update the component value if code content or code language update.
|
|
288
|
-
*
|
|
289
|
-
* @param {string} code - The new code content.
|
|
290
|
-
* @param {string} language - The new code language.
|
|
291
|
-
* @param {CodeBlockHistoryState} codeBlockHistoryState - Update the history or not.
|
|
292
|
-
*/
|
|
293
|
-
updateValue(code, language, codeBlockHistoryState) {
|
|
294
|
-
if (!this.value || this.value.code !== code || this.value.language !== language) {
|
|
295
|
-
this.value = {
|
|
296
|
-
language: language,
|
|
297
|
-
code,
|
|
298
|
-
};
|
|
299
|
-
this.changeEventEmitter.emit(this.value);
|
|
300
|
-
if (codeBlockHistoryState && codeBlockHistoryState.recordHistory) {
|
|
301
|
-
this.historyController.registerHistory({
|
|
302
|
-
value: this.value,
|
|
303
|
-
offset: codeBlockHistoryState.offset,
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Set a default value if the value is not defined.
|
|
310
|
-
*/
|
|
311
|
-
initialValue() {
|
|
312
|
-
if (!this.value) {
|
|
313
|
-
this.value = { code: '', language: 'plainText' };
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
__decorate$a([
|
|
318
|
-
MapToComponentField({ writable: true })
|
|
319
|
-
], VegaCodeBlockValueController.prototype, "value", void 0);
|
|
320
|
-
__decorate$a([
|
|
321
|
-
MapToComponentField()
|
|
322
|
-
], VegaCodeBlockValueController.prototype, "changeEventEmitter", void 0);
|
|
323
|
-
__decorate$a([
|
|
324
|
-
MapToComponentField()
|
|
325
|
-
], VegaCodeBlockValueController.prototype, "historyController", void 0);
|
|
326
|
-
__decorate$a([
|
|
327
|
-
MapToComponentMethod('connectedCallback')
|
|
328
|
-
], VegaCodeBlockValueController.prototype, "initialValue", null);
|
|
329
|
-
|
|
330
|
-
var __decorate$9 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
331
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
332
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
333
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
334
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
335
|
-
};
|
|
336
|
-
/**
|
|
337
|
-
* Parse the code content to different tokens.
|
|
338
|
-
*/
|
|
339
|
-
class CodeContentParseController extends VegaSlimmer {
|
|
340
|
-
constructor() {
|
|
341
|
-
super(...arguments);
|
|
342
|
-
this.codeNodes = [];
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Get the current rendering code node array.
|
|
346
|
-
*
|
|
347
|
-
* @returns {CodeNodeType[]} - The code node array.
|
|
348
|
-
*/
|
|
349
|
-
getCurrentCodeNodes() {
|
|
350
|
-
return this.codeNodes;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Split the code content to code node array. The default parse used if the language is not defined.
|
|
354
|
-
*
|
|
355
|
-
* @returns {CodeNodeType[]} - The code node array.
|
|
356
|
-
*/
|
|
357
|
-
parseCode() {
|
|
358
|
-
const parsers = [
|
|
359
|
-
this.prismCodeHighlightParser,
|
|
360
|
-
this.defaultCodeHighlightParser,
|
|
361
|
-
];
|
|
362
|
-
let result = [];
|
|
363
|
-
for (const parser of parsers) {
|
|
364
|
-
if (parser.canParse()) {
|
|
365
|
-
result = parser.parse();
|
|
366
|
-
break;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
this.codeNodes = result;
|
|
370
|
-
return result;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
__decorate$9([
|
|
374
|
-
MapToComponentField()
|
|
375
|
-
], CodeContentParseController.prototype, "prismCodeHighlightParser", void 0);
|
|
376
|
-
__decorate$9([
|
|
377
|
-
MapToComponentField()
|
|
378
|
-
], CodeContentParseController.prototype, "defaultCodeHighlightParser", void 0);
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* The code block component range class.
|
|
382
|
-
*/
|
|
383
|
-
class CodeBlockRange {
|
|
384
|
-
/**
|
|
385
|
-
* Initial the code block range.
|
|
386
|
-
*
|
|
387
|
-
* @param {HTMLElement} codeContainerRef - The code content container ref.
|
|
388
|
-
*/
|
|
389
|
-
constructor(codeContainerRef) {
|
|
390
|
-
// The cursor position.
|
|
391
|
-
this.contentOffset = 0;
|
|
392
|
-
// The range selected text, the value will be empty if the range is collapsed.
|
|
393
|
-
this.selectedText = '';
|
|
394
|
-
this.codeContainerRef = codeContainerRef;
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Update the code block range when the focus node changed or focus node content changed.
|
|
398
|
-
*
|
|
399
|
-
* @param {Node} startContainer - The focus node instance.
|
|
400
|
-
* @param {number} startOffset - The focus offset.
|
|
401
|
-
* @param {CodeNodeType[]} currentNodes - The current code node array.
|
|
402
|
-
* @param {string} [selectedText] - The range selected text.
|
|
403
|
-
* @returns {CodeBlockRange} - The new code block range instance.
|
|
404
|
-
*/
|
|
405
|
-
updateRange(startContainer, startOffset, currentNodes, selectedText = '') {
|
|
406
|
-
const range = new CodeBlockRange(this.codeContainerRef);
|
|
407
|
-
range.selectedText = selectedText;
|
|
408
|
-
range.contentOffset = range.getContentOffset(startContainer, startOffset, currentNodes);
|
|
409
|
-
return range;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Update the cursor position when insert text or delete text...
|
|
413
|
-
*
|
|
414
|
-
* @param {number} newContentOffset - New value for content offset.
|
|
415
|
-
* @returns {number} - The new content offset.
|
|
416
|
-
*/
|
|
417
|
-
updateContentOffset(newContentOffset) {
|
|
418
|
-
this.contentOffset = Math.max(0, newContentOffset);
|
|
419
|
-
this.selectedText = '';
|
|
420
|
-
return this.contentOffset;
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Create a native range from the current code block range.
|
|
424
|
-
*
|
|
425
|
-
* @param {CodeNodeType[]} nextCodeNodes - The code block node array.
|
|
426
|
-
* @returns {Nullable<Range>} - The range instance.
|
|
427
|
-
*/
|
|
428
|
-
createNativeRange(nextCodeNodes) {
|
|
429
|
-
const { nodeIndex, offset } = this.getFocusNodeState(nextCodeNodes, this.contentOffset);
|
|
430
|
-
const range = new Range();
|
|
431
|
-
const focusNode = this.codeContainerRef.querySelector(`span[data-index="${nodeIndex}"]`);
|
|
432
|
-
if (focusNode) {
|
|
433
|
-
const startOffset = Math.min(focusNode.firstChild.textContent.length, offset);
|
|
434
|
-
range.setStart(focusNode.firstChild, startOffset);
|
|
435
|
-
range.setEnd(focusNode.firstChild, startOffset);
|
|
436
|
-
return range;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Calculate the cursor position.
|
|
441
|
-
*
|
|
442
|
-
* @param {Node} startContainer - The cursor node.
|
|
443
|
-
* @param {number} startOffset - The cursor offset.
|
|
444
|
-
* @param {CodeNodeType[]} currentNodes - The code block node array.
|
|
445
|
-
* @returns {number} - A number value.
|
|
446
|
-
*/
|
|
447
|
-
getContentOffset(startContainer, startOffset, currentNodes) {
|
|
448
|
-
let startSpan = startContainer.nodeType === Node.TEXT_NODE
|
|
449
|
-
? startContainer.parentElement
|
|
450
|
-
: startContainer;
|
|
451
|
-
if (startSpan.nodeName === 'CODE' && startSpan.childNodes && startSpan.childNodes.length) {
|
|
452
|
-
startSpan = startSpan.childNodes[Math.min(startOffset, startSpan.childNodes.length - 1)];
|
|
453
|
-
startOffset = 0;
|
|
454
|
-
}
|
|
455
|
-
if (startSpan && startSpan.hasAttribute('data-index')) {
|
|
456
|
-
const index = Number(startSpan.dataset.index);
|
|
457
|
-
let beforeText = '';
|
|
458
|
-
for (let i = 0; i < index; i++) {
|
|
459
|
-
beforeText += currentNodes[i].text;
|
|
460
|
-
}
|
|
461
|
-
return beforeText.length + startOffset;
|
|
462
|
-
}
|
|
463
|
-
return 0;
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Get the next focus node of the code block node array.
|
|
467
|
-
*
|
|
468
|
-
* @param {CodeNodeType[]} codeNodes - The current code block array.
|
|
469
|
-
* @param {number} contentOffset - The cursor position.
|
|
470
|
-
* @returns {FocusNodeStateType} - The object contains next focus node index and offset.
|
|
471
|
-
*/
|
|
472
|
-
getFocusNodeState(codeNodes, contentOffset) {
|
|
473
|
-
const content = this.getCodeContent(codeNodes);
|
|
474
|
-
const result = { nodeIndex: 0, offset: 0 };
|
|
475
|
-
if (!content || contentOffset >= content.length) {
|
|
476
|
-
result.nodeIndex = codeNodes.length - 1;
|
|
477
|
-
result.offset = codeNodes[result.nodeIndex].text.length;
|
|
478
|
-
}
|
|
479
|
-
else {
|
|
480
|
-
let text = '';
|
|
481
|
-
for (let i = 0; i < codeNodes.length; i++) {
|
|
482
|
-
text += codeNodes[i].text;
|
|
483
|
-
if (text.length >= contentOffset) {
|
|
484
|
-
result.offset = Math.max(0, codeNodes[i].text.length - (text.length - contentOffset));
|
|
485
|
-
result.nodeIndex = i;
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
// The cursor position is incorrect in firefox when cursor node is line break node.
|
|
491
|
-
if (codeNodes[result.nodeIndex].text === '\n' &&
|
|
492
|
-
result.offset > 0 &&
|
|
493
|
-
codeNodes[result.nodeIndex + 1]) {
|
|
494
|
-
result.nodeIndex += 1;
|
|
495
|
-
result.offset = 0;
|
|
496
|
-
}
|
|
497
|
-
return result;
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Get all code content from the code block node array.
|
|
501
|
-
*
|
|
502
|
-
* @param {CodeNodeType[]} codeNodes - The code block node array.
|
|
503
|
-
* @returns {string} - The code content.
|
|
504
|
-
*/
|
|
505
|
-
getCodeContent(codeNodes) {
|
|
506
|
-
return codeNodes.map((codeNode) => codeNode.text).join('');
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
var __decorate$8 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
511
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
512
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
513
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
514
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
515
|
-
};
|
|
516
|
-
/**
|
|
517
|
-
* The class used to control the code block input cursor.
|
|
518
|
-
*/
|
|
519
|
-
class VegaCodeBlockSelectionController extends AutoRunWhenReRenderTaskQueueSlimmer {
|
|
520
|
-
constructor() {
|
|
521
|
-
super(1);
|
|
522
|
-
this.handleSelectionWithDebounce = debounce(this.handleSelectionChange, VegaCodeBlockSelectionController.SELECTION_CHANGE_DEBOUNCE_TIME, this);
|
|
523
|
-
/**
|
|
524
|
-
* The method invoke after the component re-render.
|
|
525
|
-
*/
|
|
526
|
-
this.doTask = async () => {
|
|
527
|
-
// add await Promise.resolve to put the code behind to a micro task
|
|
528
|
-
await Promise.resolve();
|
|
529
|
-
const selection = this.getSelection();
|
|
530
|
-
const range = this.codeBlockRange.createNativeRange(this.contentParseController.getCurrentCodeNodes());
|
|
531
|
-
if (selection && range) {
|
|
532
|
-
selection.removeAllRanges();
|
|
533
|
-
selection.addRange(range);
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Get current range instance.
|
|
539
|
-
*
|
|
540
|
-
* @returns {Nullable<CodeBlockRange>} - The range instance or null.
|
|
541
|
-
*/
|
|
542
|
-
getCurrentRange() {
|
|
543
|
-
return this.codeBlockRange;
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Update the text content offset, push the update native range task to a queue.
|
|
547
|
-
*
|
|
548
|
-
* @param {number} contentOffset - The next content offset.
|
|
549
|
-
* @param {boolean} [immediatelyRun] - Run the task immediately or not.
|
|
550
|
-
*/
|
|
551
|
-
setNextCodeBlockRange(contentOffset, immediatelyRun = false) {
|
|
552
|
-
this.codeBlockRange.updateContentOffset(contentOffset);
|
|
553
|
-
super.enqueueTheTaskIntoQueue(immediatelyRun);
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Component lifecycle
|
|
557
|
-
*/
|
|
558
|
-
addSelectionChangeEventListener() {
|
|
559
|
-
this.codeBlockRange = new CodeBlockRange(this.contentRenderer.getCodeContentContainerRef());
|
|
560
|
-
// eslint-disable-next-line no-restricted-globals
|
|
561
|
-
document.addEventListener('selectionchange', this.handleSelectionWithDebounce);
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* Component lifecycle
|
|
565
|
-
*/
|
|
566
|
-
removeSelectionChangeEventListener() {
|
|
567
|
-
// eslint-disable-next-line no-restricted-globals
|
|
568
|
-
document.removeEventListener('selectionchange', this.handleSelectionWithDebounce);
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* Get the code block selected range
|
|
572
|
-
*
|
|
573
|
-
* @returns {Selection} A [Selection](https://developer.mozilla.org/en-US/docs/Web/API/Selection) object
|
|
574
|
-
*/
|
|
575
|
-
getSelection() {
|
|
576
|
-
return ShadowSelectionPolyfill.getSelection(this.host.shadowRoot);
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Notify the code content selection change event.
|
|
580
|
-
*/
|
|
581
|
-
handleSelectionChange() {
|
|
582
|
-
const selection = this.getSelection();
|
|
583
|
-
if (selection && selection.rangeCount > 0) {
|
|
584
|
-
this.syncCodeRangeByNativeRange();
|
|
585
|
-
ChangeManager.notify(domNodeSubjectFactory.getSubject(this.host, VegaInternalCodeBlockSelectionChange), { detail: true });
|
|
586
|
-
}
|
|
587
|
-
else {
|
|
588
|
-
ChangeManager.notify(domNodeSubjectFactory.getSubject(this.host, VegaInternalCodeBlockSelectionChange), { detail: false });
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* Sync the code block range to make sure the code block range content offset is up to date after user click or selected text.
|
|
593
|
-
*/
|
|
594
|
-
syncCodeRangeByNativeRange() {
|
|
595
|
-
const selection = this.getSelection();
|
|
596
|
-
if (this.isCodeBlockActive() &&
|
|
597
|
-
this.autoRunTaskQueue.queue.length === 0 &&
|
|
598
|
-
!this.insertCompositionTextController.isComposing()) {
|
|
599
|
-
const range = selection.getRangeAt(0);
|
|
600
|
-
const { startContainer, startOffset } = range;
|
|
601
|
-
this.codeBlockRange = this.codeBlockRange.updateRange(startContainer, startOffset, this.contentParseController.getCurrentCodeNodes(), range.toString());
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* This method is used to determine if the code block is currently focused or active.
|
|
606
|
-
* In firefox and safari, the selection change event will trigger when the code block is not active, because the shadow selection polyfill will always return the selection of the code block.
|
|
607
|
-
*
|
|
608
|
-
* @returns {boolean} - Returns true if the code block is active, otherwise false.
|
|
609
|
-
*/
|
|
610
|
-
isCodeBlockActive() {
|
|
611
|
-
return this.host && this.host.classList.contains('focus');
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
// Must make sure the debounce time will not greater than the RTE selection range debounce time.
|
|
615
|
-
VegaCodeBlockSelectionController.SELECTION_CHANGE_DEBOUNCE_TIME = Math.min(SelectionController.SELECTION_CHANGE_DEBOUNCE_TIME, 40);
|
|
616
|
-
__decorate$8([
|
|
617
|
-
MapToComponentField()
|
|
618
|
-
], VegaCodeBlockSelectionController.prototype, "host", void 0);
|
|
619
|
-
__decorate$8([
|
|
620
|
-
MapToComponentField()
|
|
621
|
-
], VegaCodeBlockSelectionController.prototype, "contentRenderer", void 0);
|
|
622
|
-
__decorate$8([
|
|
623
|
-
MapToComponentField()
|
|
624
|
-
], VegaCodeBlockSelectionController.prototype, "contentParseController", void 0);
|
|
625
|
-
__decorate$8([
|
|
626
|
-
MapToComponentField()
|
|
627
|
-
], VegaCodeBlockSelectionController.prototype, "insertCompositionTextController", void 0);
|
|
628
|
-
__decorate$8([
|
|
629
|
-
MapToComponentMethod('componentDidLoad')
|
|
630
|
-
], VegaCodeBlockSelectionController.prototype, "addSelectionChangeEventListener", null);
|
|
631
|
-
__decorate$8([
|
|
632
|
-
MapToComponentMethod('disconnectedCallback')
|
|
633
|
-
], VegaCodeBlockSelectionController.prototype, "removeSelectionChangeEventListener", null);
|
|
634
|
-
|
|
635
|
-
/**
|
|
636
|
-
* The abstract class used to control the code block input paste action.
|
|
637
|
-
*/
|
|
638
|
-
class CodeInputPaste extends VegaSlimmer {
|
|
639
|
-
/**
|
|
640
|
-
* Delete the selected text from a string.
|
|
641
|
-
*
|
|
642
|
-
* @param {string} oldValue - The original string value.
|
|
643
|
-
* @param {number} contentStartOffset - The start index for deletion.
|
|
644
|
-
* @param {number} length - The length of text to delete.
|
|
645
|
-
* @returns {string} The content after deletion.
|
|
646
|
-
*/
|
|
647
|
-
deleteSelectedText(oldValue, contentStartOffset, length) {
|
|
648
|
-
if (length >= oldValue.length) {
|
|
649
|
-
oldValue = '';
|
|
650
|
-
}
|
|
651
|
-
else {
|
|
652
|
-
oldValue = oldValue.slice(0, contentStartOffset) + oldValue.slice(contentStartOffset + length);
|
|
653
|
-
}
|
|
654
|
-
return oldValue;
|
|
655
|
-
}
|
|
656
|
-
/**
|
|
657
|
-
* Collect the code nodes content from the code nodes array.
|
|
658
|
-
*
|
|
659
|
-
* @param {CodeNodeType[]} codeNodes - The code nodes array.
|
|
660
|
-
* @returns {string} The concatenated content of code nodes.
|
|
661
|
-
*/
|
|
662
|
-
getCodeNodesContent(codeNodes) {
|
|
663
|
-
return codeNodes.map((codeNode) => codeNode.text).join('');
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Stop event propagation.
|
|
667
|
-
*
|
|
668
|
-
* @param {Event} e - The event object.
|
|
669
|
-
*/
|
|
670
|
-
stopEventPropagation(e) {
|
|
671
|
-
if (e && typeof e.stopPropagation === 'function') {
|
|
672
|
-
e.stopPropagation();
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Re-calculate the next offset and content after insert or delete operation.
|
|
677
|
-
*
|
|
678
|
-
* @param {CodeBlockRange} range - The current code block range.
|
|
679
|
-
* @param {string} content - The current code content.
|
|
680
|
-
* @param {string} newlyAddedContent - The new content to be inserted.
|
|
681
|
-
* @returns {NextOffsetAndContentResult} The next offset and updated content.
|
|
682
|
-
*/
|
|
683
|
-
reCalculateRangeAndContent(range, content, newlyAddedContent) {
|
|
684
|
-
let nextOffset = range.contentOffset;
|
|
685
|
-
let updatedContent = content;
|
|
686
|
-
if (range) {
|
|
687
|
-
if (range.selectedText.length) {
|
|
688
|
-
updatedContent = this.deleteSelectedText(updatedContent, range.contentOffset, range.selectedText.length);
|
|
689
|
-
}
|
|
690
|
-
updatedContent =
|
|
691
|
-
updatedContent.slice(0, range.contentOffset) +
|
|
692
|
-
newlyAddedContent +
|
|
693
|
-
updatedContent.slice(range.contentOffset);
|
|
694
|
-
nextOffset = range.contentOffset + newlyAddedContent.length;
|
|
695
|
-
}
|
|
696
|
-
return { nextOffset, updatedContent };
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
var __decorate$7 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
701
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
702
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
703
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
704
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
705
|
-
};
|
|
706
|
-
/**
|
|
707
|
-
* The class used to control the code block modify content action.
|
|
708
|
-
*/
|
|
709
|
-
class CodeBlockInputController extends CodeInputPaste {
|
|
710
|
-
constructor() {
|
|
711
|
-
super(...arguments);
|
|
712
|
-
/**
|
|
713
|
-
* Stop the input event bubbles and update the code value.
|
|
714
|
-
*
|
|
715
|
-
* @param {InputEvent} e - The input event object.
|
|
716
|
-
*/
|
|
717
|
-
this.handleInputEvent = (e) => {
|
|
718
|
-
this.stopEventPropagation(e);
|
|
719
|
-
this.updateCodeContent();
|
|
720
|
-
};
|
|
721
|
-
/**
|
|
722
|
-
* Prevent paste the file into code block. Prevent to delete the last space.
|
|
723
|
-
*
|
|
724
|
-
* @param {InputEvent} e - The input event object.
|
|
725
|
-
*/
|
|
726
|
-
this.handleBeforeInput = (e) => {
|
|
727
|
-
e.stopPropagation();
|
|
728
|
-
const inputType = e.inputType;
|
|
729
|
-
switch (inputType) {
|
|
730
|
-
case 'deleteContentBackward':
|
|
731
|
-
if (!this.value || !this.value.code || this.value.code === '') {
|
|
732
|
-
e.preventDefault();
|
|
733
|
-
}
|
|
734
|
-
else {
|
|
735
|
-
this.handleDeleteAction(e);
|
|
736
|
-
}
|
|
737
|
-
return;
|
|
738
|
-
case 'historyUndo':
|
|
739
|
-
case 'historyRedo':
|
|
740
|
-
e.preventDefault();
|
|
741
|
-
return;
|
|
742
|
-
}
|
|
743
|
-
this.updateCodeBlockRange(e);
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
/**
|
|
747
|
-
* Stop `beforeinput` and `input` event bubbles to parent element.
|
|
748
|
-
*/
|
|
749
|
-
registerInputEvent() {
|
|
750
|
-
const codeContentContainerRef = this.contentRenderer.getCodeContentContainerRef();
|
|
751
|
-
if (codeContentContainerRef) {
|
|
752
|
-
codeContentContainerRef.addEventListener('beforeinput', this.handleBeforeInput);
|
|
753
|
-
codeContentContainerRef.addEventListener('input', this.handleInputEvent);
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
/**
|
|
757
|
-
* Remove the event listener.
|
|
758
|
-
*/
|
|
759
|
-
unregisterEventListener() {
|
|
760
|
-
const codeContentContainerRef = this.contentRenderer.getCodeContentContainerRef();
|
|
761
|
-
if (codeContentContainerRef) {
|
|
762
|
-
codeContentContainerRef.removeEventListener('beforeinput', this.handleBeforeInput);
|
|
763
|
-
codeContentContainerRef.removeEventListener('input', this.handleInputEvent);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
/**
|
|
767
|
-
* Modify the component code content when user press delete key.
|
|
768
|
-
*
|
|
769
|
-
* @param {InputEvent} e - The input event object.
|
|
770
|
-
*/
|
|
771
|
-
handleDeleteAction(e) {
|
|
772
|
-
const range = this.selectionController.getCurrentRange();
|
|
773
|
-
if (range) {
|
|
774
|
-
e.preventDefault();
|
|
775
|
-
const contentStartOffset = range.contentOffset;
|
|
776
|
-
const currentNodes = this.contentParseController.getCurrentCodeNodes();
|
|
777
|
-
let content = this.getCodeNodesContent(currentNodes);
|
|
778
|
-
let nextOffset = contentStartOffset;
|
|
779
|
-
// In low version firefox, the selected text could not delete when press delete key, so we handle the action manually.
|
|
780
|
-
if (range.selectedText.length) {
|
|
781
|
-
content = this.deleteSelectedText(content, contentStartOffset, range.selectedText.length);
|
|
782
|
-
}
|
|
783
|
-
else if (contentStartOffset > 0) {
|
|
784
|
-
content = content.slice(0, contentStartOffset - 1) + content.slice(contentStartOffset);
|
|
785
|
-
nextOffset -= 1;
|
|
786
|
-
}
|
|
787
|
-
this.selectionController.setNextCodeBlockRange(nextOffset);
|
|
788
|
-
this.valueController.updateValue(content, this.value.language, {
|
|
789
|
-
recordHistory: true,
|
|
790
|
-
offset: nextOffset,
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
/**
|
|
795
|
-
* Update the code block range base on input data.
|
|
796
|
-
*
|
|
797
|
-
* @param {InputEvent} e - The input event object.
|
|
798
|
-
*/
|
|
799
|
-
updateCodeBlockRange(e) {
|
|
800
|
-
const range = this.selectionController.getCurrentRange();
|
|
801
|
-
if (!this.insertCompositionTextController.isComposing() && range) {
|
|
802
|
-
this.selectionController.setNextCodeBlockRange(range.contentOffset + this.getInsertDataLength(e));
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Calculates the length of the inserted data based on the input event type.
|
|
807
|
-
*
|
|
808
|
-
* @param {InputEvent} e - The input event object.
|
|
809
|
-
* @returns {number} - The length of the inserted data.
|
|
810
|
-
*/
|
|
811
|
-
getInsertDataLength(e) {
|
|
812
|
-
const { data, inputType } = e;
|
|
813
|
-
switch (inputType) {
|
|
814
|
-
case 'insertText':
|
|
815
|
-
return data.length; // For insert text, we return the length of the inserted text.
|
|
816
|
-
case 'insertParagraph':
|
|
817
|
-
case 'insertLineBreak':
|
|
818
|
-
return 1;
|
|
819
|
-
default:
|
|
820
|
-
return 0; // For other input types, we return 0.
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
/**
|
|
824
|
-
* Update the code content after user modify action.
|
|
825
|
-
*/
|
|
826
|
-
updateCodeContent() {
|
|
827
|
-
var _a;
|
|
828
|
-
if (!this.insertCompositionTextController.isComposing()) {
|
|
829
|
-
const codeContentContainerRef = this.contentRenderer.getCodeContentContainerRef();
|
|
830
|
-
let newText = codeContentContainerRef.innerText;
|
|
831
|
-
if (this.isInsertLineBreakInLowVersionFirefox(newText)) {
|
|
832
|
-
newText = newText + '\n';
|
|
833
|
-
}
|
|
834
|
-
this.valueController.updateValue(newText, (_a = this.value) === null || _a === void 0 ? void 0 : _a.language, {
|
|
835
|
-
recordHistory: true,
|
|
836
|
-
offset: this.selectionController.getCurrentRange().contentOffset,
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* Check if the new content update by insert line break in low version Firefox.
|
|
842
|
-
*
|
|
843
|
-
* @param {string} newText - The new text content.
|
|
844
|
-
* @returns {boolean} - Boolean value.
|
|
845
|
-
*/
|
|
846
|
-
isInsertLineBreakInLowVersionFirefox(newText) {
|
|
847
|
-
var _a;
|
|
848
|
-
const oldValue = ((_a = this.value) === null || _a === void 0 ? void 0 : _a.code) || '';
|
|
849
|
-
if (!oldValue.endsWith('\n') && newText === oldValue + '\n') {
|
|
850
|
-
return true;
|
|
851
|
-
}
|
|
852
|
-
return false;
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
__decorate$7([
|
|
856
|
-
MapToComponentField()
|
|
857
|
-
], CodeBlockInputController.prototype, "selectionController", void 0);
|
|
858
|
-
__decorate$7([
|
|
859
|
-
MapToComponentField()
|
|
860
|
-
], CodeBlockInputController.prototype, "contentRenderer", void 0);
|
|
861
|
-
__decorate$7([
|
|
862
|
-
MapToComponentField()
|
|
863
|
-
], CodeBlockInputController.prototype, "valueController", void 0);
|
|
864
|
-
__decorate$7([
|
|
865
|
-
MapToComponentField()
|
|
866
|
-
], CodeBlockInputController.prototype, "contentParseController", void 0);
|
|
867
|
-
__decorate$7([
|
|
868
|
-
MapToComponentField()
|
|
869
|
-
], CodeBlockInputController.prototype, "insertCompositionTextController", void 0);
|
|
870
|
-
__decorate$7([
|
|
871
|
-
MapToComponentField()
|
|
872
|
-
], CodeBlockInputController.prototype, "value", void 0);
|
|
873
|
-
__decorate$7([
|
|
874
|
-
MapToComponentMethod('componentDidLoad')
|
|
875
|
-
], CodeBlockInputController.prototype, "registerInputEvent", null);
|
|
876
|
-
__decorate$7([
|
|
877
|
-
MapToComponentMethod('disconnectedCallback')
|
|
878
|
-
], CodeBlockInputController.prototype, "unregisterEventListener", null);
|
|
879
|
-
|
|
880
|
-
var __decorate$6 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
881
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
882
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
883
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
884
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
885
|
-
};
|
|
886
|
-
/**
|
|
887
|
-
* Control the component focus state.
|
|
888
|
-
*/
|
|
889
|
-
class VegaCodeBlockFocusController extends VegaSlimmer {
|
|
890
|
-
/**
|
|
891
|
-
* Focus the code block and update the selection range offset to end.
|
|
892
|
-
*/
|
|
893
|
-
focusAndUpdateSelection() {
|
|
894
|
-
if (!this.disabled && !this.readOnly) {
|
|
895
|
-
const codeContentContainerRef = this.contentRenderer.getCodeContentContainerRef();
|
|
896
|
-
if (codeContentContainerRef) {
|
|
897
|
-
codeContentContainerRef.focus();
|
|
898
|
-
const offset = this.value && this.value.code && this.value.code !== ' ' ? this.value.code.length : 0;
|
|
899
|
-
this.selectionController.setNextCodeBlockRange(offset, true);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* Remove the focus class when component disabled or readonly.
|
|
905
|
-
*/
|
|
906
|
-
removeFocusAfterDisabled() {
|
|
907
|
-
if (this.disabled || this.readOnly) {
|
|
908
|
-
this.host.classList.remove('focus');
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
__decorate$6([
|
|
913
|
-
MapToComponentField()
|
|
914
|
-
], VegaCodeBlockFocusController.prototype, "host", void 0);
|
|
915
|
-
__decorate$6([
|
|
916
|
-
MapToComponentField()
|
|
917
|
-
], VegaCodeBlockFocusController.prototype, "value", void 0);
|
|
918
|
-
__decorate$6([
|
|
919
|
-
MapToComponentField()
|
|
920
|
-
], VegaCodeBlockFocusController.prototype, "readOnly", void 0);
|
|
921
|
-
__decorate$6([
|
|
922
|
-
MapToComponentField()
|
|
923
|
-
], VegaCodeBlockFocusController.prototype, "disabled", void 0);
|
|
924
|
-
__decorate$6([
|
|
925
|
-
MapToComponentField()
|
|
926
|
-
], VegaCodeBlockFocusController.prototype, "contentRenderer", void 0);
|
|
927
|
-
__decorate$6([
|
|
928
|
-
MapToComponentField()
|
|
929
|
-
], VegaCodeBlockFocusController.prototype, "selectionController", void 0);
|
|
930
|
-
__decorate$6([
|
|
931
|
-
MapToComponentMethod('doFocus')
|
|
932
|
-
], VegaCodeBlockFocusController.prototype, "focusAndUpdateSelection", null);
|
|
933
|
-
__decorate$6([
|
|
934
|
-
MapToComponentMethod('watchEditableChange')
|
|
935
|
-
], VegaCodeBlockFocusController.prototype, "removeFocusAfterDisabled", null);
|
|
936
|
-
|
|
937
|
-
const copy = {
|
|
938
|
-
icon: `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"><g clip-path="url(#clip0_70002_574)"><path fill="currentColor" d="M11.7794 1.65539L10.3439 0.219844C10.2044 0.0790078 10.0122 0 9.81303 0H5.97865C5.15014 0 4.47865 0.671719 4.47865 1.5L4.47911 7.5C4.49975 8.32969 5.1724 9 5.99975 9H10.4997C11.3247 9 11.9997 8.325 11.9997 7.5V2.18555C11.9997 1.9868 11.9201 1.79602 11.7794 1.65539ZM10.8747 7.5C10.8747 7.70709 10.7068 7.875 10.4997 7.875H5.97865C5.77151 7.875 5.60365 7.70709 5.60365 7.5V1.50305C5.60365 1.29595 5.77156 1.12805 5.97865 1.12805H8.97865L8.99975 2.25C8.99975 2.66414 9.33561 3 9.74975 3H10.8537V7.5H10.8747ZM6.37475 10.5C6.37475 10.7071 6.20684 10.875 5.99975 10.875H1.47865C1.27151 10.875 1.10365 10.7071 1.10365 10.5L1.12428 4.50234C1.12428 4.29525 1.29218 4.12734 1.49928 4.12734H3.74975V3H1.49951C0.670996 3 -0.000488281 3.67148 -0.000488281 4.5L-0.000258594 10.5C-0.000207031 11.3273 0.671465 12 1.49975 12H5.99975C6.82475 12 7.49975 11.325 7.49975 10.5V9.75H6.39584L6.37475 10.5Z"/></g><defs><clipPath id="clip0_70002_574"><rect width="12" height="12" fill="currentColor"/></clipPath></defs></svg>`,
|
|
939
|
-
};
|
|
940
|
-
|
|
941
|
-
var __decorate$5 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
942
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
943
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
944
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
945
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
946
|
-
};
|
|
947
|
-
class VegaCodeBlockCopyButtonRenderer extends VegaSlimmer {
|
|
948
|
-
constructor() {
|
|
949
|
-
super(...arguments);
|
|
950
|
-
/**
|
|
951
|
-
* Copy the code.
|
|
952
|
-
*
|
|
953
|
-
* @param {HTMLVegaButtonCircleElement} node - The copy button.
|
|
954
|
-
*/
|
|
955
|
-
this.handleCopyClick = (node) => {
|
|
956
|
-
DomNodeSubjectObserverFactory.addUniqueObserverToNode(node, VegaClick, async () => {
|
|
957
|
-
var _a;
|
|
958
|
-
const content = ((_a = this.value) === null || _a === void 0 ? void 0 : _a.code) || '';
|
|
959
|
-
if (content && globalThis.navigator && globalThis.navigator.clipboard) {
|
|
960
|
-
clearTimeout(this.updateLabelTimer);
|
|
961
|
-
await globalThis.navigator.clipboard.writeText(content);
|
|
962
|
-
const oldTooltip = node.label;
|
|
963
|
-
node.label = this.translationSlimmer.t('Copied');
|
|
964
|
-
this.updateLabelTimer = setTimeout(() => {
|
|
965
|
-
if (node) {
|
|
966
|
-
node.label = oldTooltip;
|
|
967
|
-
}
|
|
968
|
-
}, VegaCodeBlockCopyButtonRenderer.RESET_TOOLTIP_TIME);
|
|
969
|
-
}
|
|
970
|
-
});
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
/**
|
|
974
|
-
* Render a copy button.
|
|
975
|
-
*
|
|
976
|
-
* @returns {Nullable<HTMLElement>} The button element.
|
|
977
|
-
*/
|
|
978
|
-
render() {
|
|
979
|
-
if (this.showCopyButton && this.readOnly) {
|
|
980
|
-
return (h("vega-button-circle", { key: "copy-button", label: this.translationSlimmer.t('Copy Code'), class: "copy-code-button", icon: VegaInternalIconManager.getIconKey('copy'), iconColor: "text-secondary", variant: "icon-only", size: "extra-small", ref: this.handleCopyClick }));
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
(() => {
|
|
985
|
-
VegaInternalIconManager.register({
|
|
986
|
-
copy: copy,
|
|
987
|
-
});
|
|
988
|
-
})();
|
|
989
|
-
VegaCodeBlockCopyButtonRenderer.RESET_TOOLTIP_TIME = 1000;
|
|
990
|
-
__decorate$5([
|
|
991
|
-
MapToComponentField()
|
|
992
|
-
], VegaCodeBlockCopyButtonRenderer.prototype, "value", void 0);
|
|
993
|
-
__decorate$5([
|
|
994
|
-
MapToComponentField()
|
|
995
|
-
], VegaCodeBlockCopyButtonRenderer.prototype, "readOnly", void 0);
|
|
996
|
-
__decorate$5([
|
|
997
|
-
MapToComponentField()
|
|
998
|
-
], VegaCodeBlockCopyButtonRenderer.prototype, "showCopyButton", void 0);
|
|
999
|
-
__decorate$5([
|
|
1000
|
-
MapToComponentField()
|
|
1001
|
-
], VegaCodeBlockCopyButtonRenderer.prototype, "translationSlimmer", void 0);
|
|
1002
|
-
|
|
1003
|
-
var prism = createCommonjsModule(function (module) {
|
|
1004
|
-
/* **********************************************
|
|
1005
|
-
Begin prism-core.js
|
|
1006
|
-
********************************************** */
|
|
1007
|
-
|
|
1008
|
-
/// <reference lib="WebWorker"/>
|
|
1009
|
-
|
|
1010
|
-
var _self = (typeof window !== 'undefined')
|
|
1011
|
-
? window // if in browser
|
|
1012
|
-
: (
|
|
1013
|
-
(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
|
|
1014
|
-
? self // if in worker
|
|
1015
|
-
: {} // if in node js
|
|
1016
|
-
);
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
* Prism: Lightweight, robust, elegant syntax highlighting
|
|
1020
|
-
*
|
|
1021
|
-
* @license MIT <https://opensource.org/licenses/MIT>
|
|
1022
|
-
* @author Lea Verou <https://lea.verou.me>
|
|
1023
|
-
* @namespace
|
|
1024
|
-
* @public
|
|
1025
|
-
*/
|
|
1026
|
-
var Prism = (function (_self) {
|
|
1027
|
-
|
|
1028
|
-
// Private helper vars
|
|
1029
|
-
var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
|
|
1030
|
-
var uniqueId = 0;
|
|
1031
|
-
|
|
1032
|
-
// The grammar object for plaintext
|
|
1033
|
-
var plainTextGrammar = {};
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
var _ = {
|
|
1037
|
-
/**
|
|
1038
|
-
* By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
|
|
1039
|
-
* current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
|
|
1040
|
-
* additional languages or plugins yourself.
|
|
1041
|
-
*
|
|
1042
|
-
* By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
|
|
1043
|
-
*
|
|
1044
|
-
* You obviously have to change this value before the automatic highlighting started. To do this, you can add an
|
|
1045
|
-
* empty Prism object into the global scope before loading the Prism script like this:
|
|
1046
|
-
*
|
|
1047
|
-
* ```js
|
|
1048
|
-
* window.Prism = window.Prism || {};
|
|
1049
|
-
* Prism.manual = true;
|
|
1050
|
-
* // add a new <script> to load Prism's script
|
|
1051
|
-
* ```
|
|
1052
|
-
*
|
|
1053
|
-
* @default false
|
|
1054
|
-
* @type {boolean}
|
|
1055
|
-
* @memberof Prism
|
|
1056
|
-
* @public
|
|
1057
|
-
*/
|
|
1058
|
-
manual: _self.Prism && _self.Prism.manual,
|
|
1059
|
-
/**
|
|
1060
|
-
* By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
|
|
1061
|
-
* `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
|
|
1062
|
-
* own worker, you don't want it to do this.
|
|
1063
|
-
*
|
|
1064
|
-
* By setting this value to `true`, Prism will not add its own listeners to the worker.
|
|
1065
|
-
*
|
|
1066
|
-
* You obviously have to change this value before Prism executes. To do this, you can add an
|
|
1067
|
-
* empty Prism object into the global scope before loading the Prism script like this:
|
|
1068
|
-
*
|
|
1069
|
-
* ```js
|
|
1070
|
-
* window.Prism = window.Prism || {};
|
|
1071
|
-
* Prism.disableWorkerMessageHandler = true;
|
|
1072
|
-
* // Load Prism's script
|
|
1073
|
-
* ```
|
|
1074
|
-
*
|
|
1075
|
-
* @default false
|
|
1076
|
-
* @type {boolean}
|
|
1077
|
-
* @memberof Prism
|
|
1078
|
-
* @public
|
|
1079
|
-
*/
|
|
1080
|
-
disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
|
|
1081
|
-
|
|
1082
|
-
/**
|
|
1083
|
-
* A namespace for utility methods.
|
|
1084
|
-
*
|
|
1085
|
-
* All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
|
|
1086
|
-
* change or disappear at any time.
|
|
1087
|
-
*
|
|
1088
|
-
* @namespace
|
|
1089
|
-
* @memberof Prism
|
|
1090
|
-
*/
|
|
1091
|
-
util: {
|
|
1092
|
-
encode: function encode(tokens) {
|
|
1093
|
-
if (tokens instanceof Token) {
|
|
1094
|
-
return new Token(tokens.type, encode(tokens.content), tokens.alias);
|
|
1095
|
-
} else if (Array.isArray(tokens)) {
|
|
1096
|
-
return tokens.map(encode);
|
|
1097
|
-
} else {
|
|
1098
|
-
return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
|
|
1099
|
-
}
|
|
1100
|
-
},
|
|
1101
|
-
|
|
1102
|
-
/**
|
|
1103
|
-
* Returns the name of the type of the given value.
|
|
1104
|
-
*
|
|
1105
|
-
* @param {any} o
|
|
1106
|
-
* @returns {string}
|
|
1107
|
-
* @example
|
|
1108
|
-
* type(null) === 'Null'
|
|
1109
|
-
* type(undefined) === 'Undefined'
|
|
1110
|
-
* type(123) === 'Number'
|
|
1111
|
-
* type('foo') === 'String'
|
|
1112
|
-
* type(true) === 'Boolean'
|
|
1113
|
-
* type([1, 2]) === 'Array'
|
|
1114
|
-
* type({}) === 'Object'
|
|
1115
|
-
* type(String) === 'Function'
|
|
1116
|
-
* type(/abc+/) === 'RegExp'
|
|
1117
|
-
*/
|
|
1118
|
-
type: function (o) {
|
|
1119
|
-
return Object.prototype.toString.call(o).slice(8, -1);
|
|
1120
|
-
},
|
|
1121
|
-
|
|
1122
|
-
/**
|
|
1123
|
-
* Returns a unique number for the given object. Later calls will still return the same number.
|
|
1124
|
-
*
|
|
1125
|
-
* @param {Object} obj
|
|
1126
|
-
* @returns {number}
|
|
1127
|
-
*/
|
|
1128
|
-
objId: function (obj) {
|
|
1129
|
-
if (!obj['__id']) {
|
|
1130
|
-
Object.defineProperty(obj, '__id', { value: ++uniqueId });
|
|
1131
|
-
}
|
|
1132
|
-
return obj['__id'];
|
|
1133
|
-
},
|
|
1134
|
-
|
|
1135
|
-
/**
|
|
1136
|
-
* Creates a deep clone of the given object.
|
|
1137
|
-
*
|
|
1138
|
-
* The main intended use of this function is to clone language definitions.
|
|
1139
|
-
*
|
|
1140
|
-
* @param {T} o
|
|
1141
|
-
* @param {Record<number, any>} [visited]
|
|
1142
|
-
* @returns {T}
|
|
1143
|
-
* @template T
|
|
1144
|
-
*/
|
|
1145
|
-
clone: function deepClone(o, visited) {
|
|
1146
|
-
visited = visited || {};
|
|
1147
|
-
|
|
1148
|
-
var clone; var id;
|
|
1149
|
-
switch (_.util.type(o)) {
|
|
1150
|
-
case 'Object':
|
|
1151
|
-
id = _.util.objId(o);
|
|
1152
|
-
if (visited[id]) {
|
|
1153
|
-
return visited[id];
|
|
1154
|
-
}
|
|
1155
|
-
clone = /** @type {Record<string, any>} */ ({});
|
|
1156
|
-
visited[id] = clone;
|
|
1157
|
-
|
|
1158
|
-
for (var key in o) {
|
|
1159
|
-
if (o.hasOwnProperty(key)) {
|
|
1160
|
-
clone[key] = deepClone(o[key], visited);
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
return /** @type {any} */ (clone);
|
|
1165
|
-
|
|
1166
|
-
case 'Array':
|
|
1167
|
-
id = _.util.objId(o);
|
|
1168
|
-
if (visited[id]) {
|
|
1169
|
-
return visited[id];
|
|
1170
|
-
}
|
|
1171
|
-
clone = [];
|
|
1172
|
-
visited[id] = clone;
|
|
1173
|
-
|
|
1174
|
-
(/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
|
|
1175
|
-
clone[i] = deepClone(v, visited);
|
|
1176
|
-
});
|
|
1177
|
-
|
|
1178
|
-
return /** @type {any} */ (clone);
|
|
1179
|
-
|
|
1180
|
-
default:
|
|
1181
|
-
return o;
|
|
1182
|
-
}
|
|
1183
|
-
},
|
|
1184
|
-
|
|
1185
|
-
/**
|
|
1186
|
-
* Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
|
|
1187
|
-
*
|
|
1188
|
-
* If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
|
|
1189
|
-
*
|
|
1190
|
-
* @param {Element} element
|
|
1191
|
-
* @returns {string}
|
|
1192
|
-
*/
|
|
1193
|
-
getLanguage: function (element) {
|
|
1194
|
-
while (element) {
|
|
1195
|
-
var m = lang.exec(element.className);
|
|
1196
|
-
if (m) {
|
|
1197
|
-
return m[1].toLowerCase();
|
|
1198
|
-
}
|
|
1199
|
-
element = element.parentElement;
|
|
1200
|
-
}
|
|
1201
|
-
return 'none';
|
|
1202
|
-
},
|
|
1203
|
-
|
|
1204
|
-
/**
|
|
1205
|
-
* Sets the Prism `language-xxxx` class of the given element.
|
|
1206
|
-
*
|
|
1207
|
-
* @param {Element} element
|
|
1208
|
-
* @param {string} language
|
|
1209
|
-
* @returns {void}
|
|
1210
|
-
*/
|
|
1211
|
-
setLanguage: function (element, language) {
|
|
1212
|
-
// remove all `language-xxxx` classes
|
|
1213
|
-
// (this might leave behind a leading space)
|
|
1214
|
-
element.className = element.className.replace(RegExp(lang, 'gi'), '');
|
|
1215
|
-
|
|
1216
|
-
// add the new `language-xxxx` class
|
|
1217
|
-
// (using `classList` will automatically clean up spaces for us)
|
|
1218
|
-
element.classList.add('language-' + language);
|
|
1219
|
-
},
|
|
1220
|
-
|
|
1221
|
-
/**
|
|
1222
|
-
* Returns the script element that is currently executing.
|
|
1223
|
-
*
|
|
1224
|
-
* This does __not__ work for line script element.
|
|
1225
|
-
*
|
|
1226
|
-
* @returns {HTMLScriptElement | null}
|
|
1227
|
-
*/
|
|
1228
|
-
currentScript: function () {
|
|
1229
|
-
if (typeof document === 'undefined') {
|
|
1230
|
-
return null;
|
|
1231
|
-
}
|
|
1232
|
-
if (document.currentScript && document.currentScript.tagName === 'SCRIPT' && 1 < 2 /* hack to trip TS' flow analysis */) {
|
|
1233
|
-
return /** @type {any} */ (document.currentScript);
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
// IE11 workaround
|
|
1237
|
-
// we'll get the src of the current script by parsing IE11's error stack trace
|
|
1238
|
-
// this will not work for inline scripts
|
|
1239
|
-
|
|
1240
|
-
try {
|
|
1241
|
-
throw new Error();
|
|
1242
|
-
} catch (err) {
|
|
1243
|
-
// Get file src url from stack. Specifically works with the format of stack traces in IE.
|
|
1244
|
-
// A stack will look like this:
|
|
1245
|
-
//
|
|
1246
|
-
// Error
|
|
1247
|
-
// at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
|
|
1248
|
-
// at Global code (http://localhost/components/prism-core.js:606:1)
|
|
1249
|
-
|
|
1250
|
-
var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
|
|
1251
|
-
if (src) {
|
|
1252
|
-
var scripts = document.getElementsByTagName('script');
|
|
1253
|
-
for (var i in scripts) {
|
|
1254
|
-
if (scripts[i].src == src) {
|
|
1255
|
-
return scripts[i];
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
return null;
|
|
1260
|
-
}
|
|
1261
|
-
},
|
|
1262
|
-
|
|
1263
|
-
/**
|
|
1264
|
-
* Returns whether a given class is active for `element`.
|
|
1265
|
-
*
|
|
1266
|
-
* The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
|
|
1267
|
-
* if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
|
|
1268
|
-
* given class is just the given class with a `no-` prefix.
|
|
1269
|
-
*
|
|
1270
|
-
* Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
|
|
1271
|
-
* closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
|
|
1272
|
-
* ancestors have the given class or the negated version of it, then the default activation will be returned.
|
|
1273
|
-
*
|
|
1274
|
-
* In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
|
|
1275
|
-
* version of it, the class is considered active.
|
|
1276
|
-
*
|
|
1277
|
-
* @param {Element} element
|
|
1278
|
-
* @param {string} className
|
|
1279
|
-
* @param {boolean} [defaultActivation=false]
|
|
1280
|
-
* @returns {boolean}
|
|
1281
|
-
*/
|
|
1282
|
-
isActive: function (element, className, defaultActivation) {
|
|
1283
|
-
var no = 'no-' + className;
|
|
1284
|
-
|
|
1285
|
-
while (element) {
|
|
1286
|
-
var classList = element.classList;
|
|
1287
|
-
if (classList.contains(className)) {
|
|
1288
|
-
return true;
|
|
1289
|
-
}
|
|
1290
|
-
if (classList.contains(no)) {
|
|
1291
|
-
return false;
|
|
1292
|
-
}
|
|
1293
|
-
element = element.parentElement;
|
|
1294
|
-
}
|
|
1295
|
-
return !!defaultActivation;
|
|
1296
|
-
}
|
|
1297
|
-
},
|
|
1298
|
-
|
|
1299
|
-
/**
|
|
1300
|
-
* This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
|
|
1301
|
-
*
|
|
1302
|
-
* @namespace
|
|
1303
|
-
* @memberof Prism
|
|
1304
|
-
* @public
|
|
1305
|
-
*/
|
|
1306
|
-
languages: {
|
|
1307
|
-
/**
|
|
1308
|
-
* The grammar for plain, unformatted text.
|
|
1309
|
-
*/
|
|
1310
|
-
plain: plainTextGrammar,
|
|
1311
|
-
plaintext: plainTextGrammar,
|
|
1312
|
-
text: plainTextGrammar,
|
|
1313
|
-
txt: plainTextGrammar,
|
|
1314
|
-
|
|
1315
|
-
/**
|
|
1316
|
-
* Creates a deep copy of the language with the given id and appends the given tokens.
|
|
1317
|
-
*
|
|
1318
|
-
* If a token in `redef` also appears in the copied language, then the existing token in the copied language
|
|
1319
|
-
* will be overwritten at its original position.
|
|
1320
|
-
*
|
|
1321
|
-
* ## Best practices
|
|
1322
|
-
*
|
|
1323
|
-
* Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
|
|
1324
|
-
* doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
|
|
1325
|
-
* understand the language definition because, normally, the order of tokens matters in Prism grammars.
|
|
1326
|
-
*
|
|
1327
|
-
* Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
|
|
1328
|
-
* Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
|
|
1329
|
-
*
|
|
1330
|
-
* @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
|
|
1331
|
-
* @param {Grammar} redef The new tokens to append.
|
|
1332
|
-
* @returns {Grammar} The new language created.
|
|
1333
|
-
* @public
|
|
1334
|
-
* @example
|
|
1335
|
-
* Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
|
|
1336
|
-
* // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
|
|
1337
|
-
* // at its original position
|
|
1338
|
-
* 'comment': { ... },
|
|
1339
|
-
* // CSS doesn't have a 'color' token, so this token will be appended
|
|
1340
|
-
* 'color': /\b(?:red|green|blue)\b/
|
|
1341
|
-
* });
|
|
1342
|
-
*/
|
|
1343
|
-
extend: function (id, redef) {
|
|
1344
|
-
var lang = _.util.clone(_.languages[id]);
|
|
1345
|
-
|
|
1346
|
-
for (var key in redef) {
|
|
1347
|
-
lang[key] = redef[key];
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
return lang;
|
|
1351
|
-
},
|
|
1352
|
-
|
|
1353
|
-
/**
|
|
1354
|
-
* Inserts tokens _before_ another token in a language definition or any other grammar.
|
|
1355
|
-
*
|
|
1356
|
-
* ## Usage
|
|
1357
|
-
*
|
|
1358
|
-
* This helper method makes it easy to modify existing languages. For example, the CSS language definition
|
|
1359
|
-
* not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
|
|
1360
|
-
* in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
|
|
1361
|
-
* appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
|
|
1362
|
-
* this:
|
|
1363
|
-
*
|
|
1364
|
-
* ```js
|
|
1365
|
-
* Prism.languages.markup.style = {
|
|
1366
|
-
* // token
|
|
1367
|
-
* };
|
|
1368
|
-
* ```
|
|
1369
|
-
*
|
|
1370
|
-
* then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
|
|
1371
|
-
* before existing tokens. For the CSS example above, you would use it like this:
|
|
1372
|
-
*
|
|
1373
|
-
* ```js
|
|
1374
|
-
* Prism.languages.insertBefore('markup', 'cdata', {
|
|
1375
|
-
* 'style': {
|
|
1376
|
-
* // token
|
|
1377
|
-
* }
|
|
1378
|
-
* });
|
|
1379
|
-
* ```
|
|
1380
|
-
*
|
|
1381
|
-
* ## Special cases
|
|
1382
|
-
*
|
|
1383
|
-
* If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
|
|
1384
|
-
* will be ignored.
|
|
1385
|
-
*
|
|
1386
|
-
* This behavior can be used to insert tokens after `before`:
|
|
1387
|
-
*
|
|
1388
|
-
* ```js
|
|
1389
|
-
* Prism.languages.insertBefore('markup', 'comment', {
|
|
1390
|
-
* 'comment': Prism.languages.markup.comment,
|
|
1391
|
-
* // tokens after 'comment'
|
|
1392
|
-
* });
|
|
1393
|
-
* ```
|
|
1394
|
-
*
|
|
1395
|
-
* ## Limitations
|
|
1396
|
-
*
|
|
1397
|
-
* The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
|
|
1398
|
-
* properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
|
|
1399
|
-
* differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
|
|
1400
|
-
* deleting properties which is necessary to insert at arbitrary positions.
|
|
1401
|
-
*
|
|
1402
|
-
* To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
|
|
1403
|
-
* Instead, it will create a new object and replace all references to the target object with the new one. This
|
|
1404
|
-
* can be done without temporarily deleting properties, so the iteration order is well-defined.
|
|
1405
|
-
*
|
|
1406
|
-
* However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
|
|
1407
|
-
* you hold the target object in a variable, then the value of the variable will not change.
|
|
1408
|
-
*
|
|
1409
|
-
* ```js
|
|
1410
|
-
* var oldMarkup = Prism.languages.markup;
|
|
1411
|
-
* var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
|
|
1412
|
-
*
|
|
1413
|
-
* assert(oldMarkup !== Prism.languages.markup);
|
|
1414
|
-
* assert(newMarkup === Prism.languages.markup);
|
|
1415
|
-
* ```
|
|
1416
|
-
*
|
|
1417
|
-
* @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
|
|
1418
|
-
* object to be modified.
|
|
1419
|
-
* @param {string} before The key to insert before.
|
|
1420
|
-
* @param {Grammar} insert An object containing the key-value pairs to be inserted.
|
|
1421
|
-
* @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
|
|
1422
|
-
* object to be modified.
|
|
1423
|
-
*
|
|
1424
|
-
* Defaults to `Prism.languages`.
|
|
1425
|
-
* @returns {Grammar} The new grammar object.
|
|
1426
|
-
* @public
|
|
1427
|
-
*/
|
|
1428
|
-
insertBefore: function (inside, before, insert, root) {
|
|
1429
|
-
root = root || /** @type {any} */ (_.languages);
|
|
1430
|
-
var grammar = root[inside];
|
|
1431
|
-
/** @type {Grammar} */
|
|
1432
|
-
var ret = {};
|
|
1433
|
-
|
|
1434
|
-
for (var token in grammar) {
|
|
1435
|
-
if (grammar.hasOwnProperty(token)) {
|
|
1436
|
-
|
|
1437
|
-
if (token == before) {
|
|
1438
|
-
for (var newToken in insert) {
|
|
1439
|
-
if (insert.hasOwnProperty(newToken)) {
|
|
1440
|
-
ret[newToken] = insert[newToken];
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
// Do not insert token which also occur in insert. See #1525
|
|
1446
|
-
if (!insert.hasOwnProperty(token)) {
|
|
1447
|
-
ret[token] = grammar[token];
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
var old = root[inside];
|
|
1453
|
-
root[inside] = ret;
|
|
1454
|
-
|
|
1455
|
-
// Update references in other language definitions
|
|
1456
|
-
_.languages.DFS(_.languages, function (key, value) {
|
|
1457
|
-
if (value === old && key != inside) {
|
|
1458
|
-
this[key] = ret;
|
|
1459
|
-
}
|
|
1460
|
-
});
|
|
1461
|
-
|
|
1462
|
-
return ret;
|
|
1463
|
-
},
|
|
1464
|
-
|
|
1465
|
-
// Traverse a language definition with Depth First Search
|
|
1466
|
-
DFS: function DFS(o, callback, type, visited) {
|
|
1467
|
-
visited = visited || {};
|
|
1468
|
-
|
|
1469
|
-
var objId = _.util.objId;
|
|
1470
|
-
|
|
1471
|
-
for (var i in o) {
|
|
1472
|
-
if (o.hasOwnProperty(i)) {
|
|
1473
|
-
callback.call(o, i, o[i], type || i);
|
|
1474
|
-
|
|
1475
|
-
var property = o[i];
|
|
1476
|
-
var propertyType = _.util.type(property);
|
|
1477
|
-
|
|
1478
|
-
if (propertyType === 'Object' && !visited[objId(property)]) {
|
|
1479
|
-
visited[objId(property)] = true;
|
|
1480
|
-
DFS(property, callback, null, visited);
|
|
1481
|
-
} else if (propertyType === 'Array' && !visited[objId(property)]) {
|
|
1482
|
-
visited[objId(property)] = true;
|
|
1483
|
-
DFS(property, callback, i, visited);
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
},
|
|
1489
|
-
|
|
1490
|
-
plugins: {},
|
|
1491
|
-
|
|
1492
|
-
/**
|
|
1493
|
-
* This is the most high-level function in Prism’s API.
|
|
1494
|
-
* It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
|
|
1495
|
-
* each one of them.
|
|
1496
|
-
*
|
|
1497
|
-
* This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
|
|
1498
|
-
*
|
|
1499
|
-
* @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
|
|
1500
|
-
* @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
|
|
1501
|
-
* @memberof Prism
|
|
1502
|
-
* @public
|
|
1503
|
-
*/
|
|
1504
|
-
highlightAll: function (async, callback) {
|
|
1505
|
-
_.highlightAllUnder(document, async, callback);
|
|
1506
|
-
},
|
|
1507
|
-
|
|
1508
|
-
/**
|
|
1509
|
-
* Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
|
|
1510
|
-
* {@link Prism.highlightElement} on each one of them.
|
|
1511
|
-
*
|
|
1512
|
-
* The following hooks will be run:
|
|
1513
|
-
* 1. `before-highlightall`
|
|
1514
|
-
* 2. `before-all-elements-highlight`
|
|
1515
|
-
* 3. All hooks of {@link Prism.highlightElement} for each element.
|
|
1516
|
-
*
|
|
1517
|
-
* @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
|
|
1518
|
-
* @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
|
|
1519
|
-
* @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
|
|
1520
|
-
* @memberof Prism
|
|
1521
|
-
* @public
|
|
1522
|
-
*/
|
|
1523
|
-
highlightAllUnder: function (container, async, callback) {
|
|
1524
|
-
var env = {
|
|
1525
|
-
callback: callback,
|
|
1526
|
-
container: container,
|
|
1527
|
-
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
|
1528
|
-
};
|
|
1529
|
-
|
|
1530
|
-
_.hooks.run('before-highlightall', env);
|
|
1531
|
-
|
|
1532
|
-
env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
|
|
1533
|
-
|
|
1534
|
-
_.hooks.run('before-all-elements-highlight', env);
|
|
1535
|
-
|
|
1536
|
-
for (var i = 0, element; (element = env.elements[i++]);) {
|
|
1537
|
-
_.highlightElement(element, async === true, env.callback);
|
|
1538
|
-
}
|
|
1539
|
-
},
|
|
1540
|
-
|
|
1541
|
-
/**
|
|
1542
|
-
* Highlights the code inside a single element.
|
|
1543
|
-
*
|
|
1544
|
-
* The following hooks will be run:
|
|
1545
|
-
* 1. `before-sanity-check`
|
|
1546
|
-
* 2. `before-highlight`
|
|
1547
|
-
* 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
|
|
1548
|
-
* 4. `before-insert`
|
|
1549
|
-
* 5. `after-highlight`
|
|
1550
|
-
* 6. `complete`
|
|
1551
|
-
*
|
|
1552
|
-
* Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
|
|
1553
|
-
* the element's language.
|
|
1554
|
-
*
|
|
1555
|
-
* @param {Element} element The element containing the code.
|
|
1556
|
-
* It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
|
|
1557
|
-
* @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
|
|
1558
|
-
* to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
|
|
1559
|
-
* [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
|
|
1560
|
-
*
|
|
1561
|
-
* Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
|
|
1562
|
-
* asynchronous highlighting to work. You can build your own bundle on the
|
|
1563
|
-
* [Download page](https://prismjs.com/download.html).
|
|
1564
|
-
* @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
|
|
1565
|
-
* Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
|
|
1566
|
-
* @memberof Prism
|
|
1567
|
-
* @public
|
|
1568
|
-
*/
|
|
1569
|
-
highlightElement: function (element, async, callback) {
|
|
1570
|
-
// Find language
|
|
1571
|
-
var language = _.util.getLanguage(element);
|
|
1572
|
-
var grammar = _.languages[language];
|
|
1573
|
-
|
|
1574
|
-
// Set language on the element, if not present
|
|
1575
|
-
_.util.setLanguage(element, language);
|
|
1576
|
-
|
|
1577
|
-
// Set language on the parent, for styling
|
|
1578
|
-
var parent = element.parentElement;
|
|
1579
|
-
if (parent && parent.nodeName.toLowerCase() === 'pre') {
|
|
1580
|
-
_.util.setLanguage(parent, language);
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
var code = element.textContent;
|
|
1584
|
-
|
|
1585
|
-
var env = {
|
|
1586
|
-
element: element,
|
|
1587
|
-
language: language,
|
|
1588
|
-
grammar: grammar,
|
|
1589
|
-
code: code
|
|
1590
|
-
};
|
|
1591
|
-
|
|
1592
|
-
function insertHighlightedCode(highlightedCode) {
|
|
1593
|
-
env.highlightedCode = highlightedCode;
|
|
1594
|
-
|
|
1595
|
-
_.hooks.run('before-insert', env);
|
|
1596
|
-
|
|
1597
|
-
env.element.innerHTML = env.highlightedCode;
|
|
1598
|
-
|
|
1599
|
-
_.hooks.run('after-highlight', env);
|
|
1600
|
-
_.hooks.run('complete', env);
|
|
1601
|
-
callback && callback.call(env.element);
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
|
-
_.hooks.run('before-sanity-check', env);
|
|
1605
|
-
|
|
1606
|
-
// plugins may change/add the parent/element
|
|
1607
|
-
parent = env.element.parentElement;
|
|
1608
|
-
if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
|
|
1609
|
-
parent.setAttribute('tabindex', '0');
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
if (!env.code) {
|
|
1613
|
-
_.hooks.run('complete', env);
|
|
1614
|
-
callback && callback.call(env.element);
|
|
1615
|
-
return;
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
_.hooks.run('before-highlight', env);
|
|
1619
|
-
|
|
1620
|
-
if (!env.grammar) {
|
|
1621
|
-
insertHighlightedCode(_.util.encode(env.code));
|
|
1622
|
-
return;
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
if (async && _self.Worker) {
|
|
1626
|
-
var worker = new Worker(_.filename);
|
|
1627
|
-
|
|
1628
|
-
worker.onmessage = function (evt) {
|
|
1629
|
-
insertHighlightedCode(evt.data);
|
|
1630
|
-
};
|
|
1631
|
-
|
|
1632
|
-
worker.postMessage(JSON.stringify({
|
|
1633
|
-
language: env.language,
|
|
1634
|
-
code: env.code,
|
|
1635
|
-
immediateClose: true
|
|
1636
|
-
}));
|
|
1637
|
-
} else {
|
|
1638
|
-
insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
|
|
1639
|
-
}
|
|
1640
|
-
},
|
|
1641
|
-
|
|
1642
|
-
/**
|
|
1643
|
-
* Low-level function, only use if you know what you’re doing. It accepts a string of text as input
|
|
1644
|
-
* and the language definitions to use, and returns a string with the HTML produced.
|
|
1645
|
-
*
|
|
1646
|
-
* The following hooks will be run:
|
|
1647
|
-
* 1. `before-tokenize`
|
|
1648
|
-
* 2. `after-tokenize`
|
|
1649
|
-
* 3. `wrap`: On each {@link Token}.
|
|
1650
|
-
*
|
|
1651
|
-
* @param {string} text A string with the code to be highlighted.
|
|
1652
|
-
* @param {Grammar} grammar An object containing the tokens to use.
|
|
1653
|
-
*
|
|
1654
|
-
* Usually a language definition like `Prism.languages.markup`.
|
|
1655
|
-
* @param {string} language The name of the language definition passed to `grammar`.
|
|
1656
|
-
* @returns {string} The highlighted HTML.
|
|
1657
|
-
* @memberof Prism
|
|
1658
|
-
* @public
|
|
1659
|
-
* @example
|
|
1660
|
-
* Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
|
|
1661
|
-
*/
|
|
1662
|
-
highlight: function (text, grammar, language) {
|
|
1663
|
-
var env = {
|
|
1664
|
-
code: text,
|
|
1665
|
-
grammar: grammar,
|
|
1666
|
-
language: language
|
|
1667
|
-
};
|
|
1668
|
-
_.hooks.run('before-tokenize', env);
|
|
1669
|
-
if (!env.grammar) {
|
|
1670
|
-
throw new Error('The language "' + env.language + '" has no grammar.');
|
|
1671
|
-
}
|
|
1672
|
-
env.tokens = _.tokenize(env.code, env.grammar);
|
|
1673
|
-
_.hooks.run('after-tokenize', env);
|
|
1674
|
-
return Token.stringify(_.util.encode(env.tokens), env.language);
|
|
1675
|
-
},
|
|
1676
|
-
|
|
1677
|
-
/**
|
|
1678
|
-
* This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
|
|
1679
|
-
* and the language definitions to use, and returns an array with the tokenized code.
|
|
1680
|
-
*
|
|
1681
|
-
* When the language definition includes nested tokens, the function is called recursively on each of these tokens.
|
|
1682
|
-
*
|
|
1683
|
-
* This method could be useful in other contexts as well, as a very crude parser.
|
|
1684
|
-
*
|
|
1685
|
-
* @param {string} text A string with the code to be highlighted.
|
|
1686
|
-
* @param {Grammar} grammar An object containing the tokens to use.
|
|
1687
|
-
*
|
|
1688
|
-
* Usually a language definition like `Prism.languages.markup`.
|
|
1689
|
-
* @returns {TokenStream} An array of strings and tokens, a token stream.
|
|
1690
|
-
* @memberof Prism
|
|
1691
|
-
* @public
|
|
1692
|
-
* @example
|
|
1693
|
-
* let code = `var foo = 0;`;
|
|
1694
|
-
* let tokens = Prism.tokenize(code, Prism.languages.javascript);
|
|
1695
|
-
* tokens.forEach(token => {
|
|
1696
|
-
* if (token instanceof Prism.Token && token.type === 'number') {
|
|
1697
|
-
* console.log(`Found numeric literal: ${token.content}`);
|
|
1698
|
-
* }
|
|
1699
|
-
* });
|
|
1700
|
-
*/
|
|
1701
|
-
tokenize: function (text, grammar) {
|
|
1702
|
-
var rest = grammar.rest;
|
|
1703
|
-
if (rest) {
|
|
1704
|
-
for (var token in rest) {
|
|
1705
|
-
grammar[token] = rest[token];
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
|
-
delete grammar.rest;
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
var tokenList = new LinkedList();
|
|
1712
|
-
addAfter(tokenList, tokenList.head, text);
|
|
1713
|
-
|
|
1714
|
-
matchGrammar(text, tokenList, grammar, tokenList.head, 0);
|
|
1715
|
-
|
|
1716
|
-
return toArray(tokenList);
|
|
1717
|
-
},
|
|
1718
|
-
|
|
1719
|
-
/**
|
|
1720
|
-
* @namespace
|
|
1721
|
-
* @memberof Prism
|
|
1722
|
-
* @public
|
|
1723
|
-
*/
|
|
1724
|
-
hooks: {
|
|
1725
|
-
all: {},
|
|
1726
|
-
|
|
1727
|
-
/**
|
|
1728
|
-
* Adds the given callback to the list of callbacks for the given hook.
|
|
1729
|
-
*
|
|
1730
|
-
* The callback will be invoked when the hook it is registered for is run.
|
|
1731
|
-
* Hooks are usually directly run by a highlight function but you can also run hooks yourself.
|
|
1732
|
-
*
|
|
1733
|
-
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
|
1734
|
-
*
|
|
1735
|
-
* @param {string} name The name of the hook.
|
|
1736
|
-
* @param {HookCallback} callback The callback function which is given environment variables.
|
|
1737
|
-
* @public
|
|
1738
|
-
*/
|
|
1739
|
-
add: function (name, callback) {
|
|
1740
|
-
var hooks = _.hooks.all;
|
|
1741
|
-
|
|
1742
|
-
hooks[name] = hooks[name] || [];
|
|
1743
|
-
|
|
1744
|
-
hooks[name].push(callback);
|
|
1745
|
-
},
|
|
1746
|
-
|
|
1747
|
-
/**
|
|
1748
|
-
* Runs a hook invoking all registered callbacks with the given environment variables.
|
|
1749
|
-
*
|
|
1750
|
-
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
|
1751
|
-
*
|
|
1752
|
-
* @param {string} name The name of the hook.
|
|
1753
|
-
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
|
1754
|
-
* @public
|
|
1755
|
-
*/
|
|
1756
|
-
run: function (name, env) {
|
|
1757
|
-
var callbacks = _.hooks.all[name];
|
|
1758
|
-
|
|
1759
|
-
if (!callbacks || !callbacks.length) {
|
|
1760
|
-
return;
|
|
1761
|
-
}
|
|
1762
|
-
|
|
1763
|
-
for (var i = 0, callback; (callback = callbacks[i++]);) {
|
|
1764
|
-
callback(env);
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
},
|
|
1768
|
-
|
|
1769
|
-
Token: Token
|
|
1770
|
-
};
|
|
1771
|
-
_self.Prism = _;
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
// Typescript note:
|
|
1775
|
-
// The following can be used to import the Token type in JSDoc:
|
|
1776
|
-
//
|
|
1777
|
-
// @typedef {InstanceType<import("./prism-core")["Token"]>} Token
|
|
1778
|
-
|
|
1779
|
-
/**
|
|
1780
|
-
* Creates a new token.
|
|
1781
|
-
*
|
|
1782
|
-
* @param {string} type See {@link Token#type type}
|
|
1783
|
-
* @param {string | TokenStream} content See {@link Token#content content}
|
|
1784
|
-
* @param {string|string[]} [alias] The alias(es) of the token.
|
|
1785
|
-
* @param {string} [matchedStr=""] A copy of the full string this token was created from.
|
|
1786
|
-
* @class
|
|
1787
|
-
* @global
|
|
1788
|
-
* @public
|
|
1789
|
-
*/
|
|
1790
|
-
function Token(type, content, alias, matchedStr) {
|
|
1791
|
-
/**
|
|
1792
|
-
* The type of the token.
|
|
1793
|
-
*
|
|
1794
|
-
* This is usually the key of a pattern in a {@link Grammar}.
|
|
1795
|
-
*
|
|
1796
|
-
* @type {string}
|
|
1797
|
-
* @see GrammarToken
|
|
1798
|
-
* @public
|
|
1799
|
-
*/
|
|
1800
|
-
this.type = type;
|
|
1801
|
-
/**
|
|
1802
|
-
* The strings or tokens contained by this token.
|
|
1803
|
-
*
|
|
1804
|
-
* This will be a token stream if the pattern matched also defined an `inside` grammar.
|
|
1805
|
-
*
|
|
1806
|
-
* @type {string | TokenStream}
|
|
1807
|
-
* @public
|
|
1808
|
-
*/
|
|
1809
|
-
this.content = content;
|
|
1810
|
-
/**
|
|
1811
|
-
* The alias(es) of the token.
|
|
1812
|
-
*
|
|
1813
|
-
* @type {string|string[]}
|
|
1814
|
-
* @see GrammarToken
|
|
1815
|
-
* @public
|
|
1816
|
-
*/
|
|
1817
|
-
this.alias = alias;
|
|
1818
|
-
// Copy of the full string this token was created from
|
|
1819
|
-
this.length = (matchedStr || '').length | 0;
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
/**
|
|
1823
|
-
* A token stream is an array of strings and {@link Token Token} objects.
|
|
1824
|
-
*
|
|
1825
|
-
* Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
|
|
1826
|
-
* them.
|
|
1827
|
-
*
|
|
1828
|
-
* 1. No adjacent strings.
|
|
1829
|
-
* 2. No empty strings.
|
|
1830
|
-
*
|
|
1831
|
-
* The only exception here is the token stream that only contains the empty string and nothing else.
|
|
1832
|
-
*
|
|
1833
|
-
* @typedef {Array<string | Token>} TokenStream
|
|
1834
|
-
* @global
|
|
1835
|
-
* @public
|
|
1836
|
-
*/
|
|
1837
|
-
|
|
1838
|
-
/**
|
|
1839
|
-
* Converts the given token or token stream to an HTML representation.
|
|
1840
|
-
*
|
|
1841
|
-
* The following hooks will be run:
|
|
1842
|
-
* 1. `wrap`: On each {@link Token}.
|
|
1843
|
-
*
|
|
1844
|
-
* @param {string | Token | TokenStream} o The token or token stream to be converted.
|
|
1845
|
-
* @param {string} language The name of current language.
|
|
1846
|
-
* @returns {string} The HTML representation of the token or token stream.
|
|
1847
|
-
* @memberof Token
|
|
1848
|
-
* @static
|
|
1849
|
-
*/
|
|
1850
|
-
Token.stringify = function stringify(o, language) {
|
|
1851
|
-
if (typeof o == 'string') {
|
|
1852
|
-
return o;
|
|
1853
|
-
}
|
|
1854
|
-
if (Array.isArray(o)) {
|
|
1855
|
-
var s = '';
|
|
1856
|
-
o.forEach(function (e) {
|
|
1857
|
-
s += stringify(e, language);
|
|
1858
|
-
});
|
|
1859
|
-
return s;
|
|
1860
|
-
}
|
|
1861
|
-
|
|
1862
|
-
var env = {
|
|
1863
|
-
type: o.type,
|
|
1864
|
-
content: stringify(o.content, language),
|
|
1865
|
-
tag: 'span',
|
|
1866
|
-
classes: ['token', o.type],
|
|
1867
|
-
attributes: {},
|
|
1868
|
-
language: language
|
|
1869
|
-
};
|
|
1870
|
-
|
|
1871
|
-
var aliases = o.alias;
|
|
1872
|
-
if (aliases) {
|
|
1873
|
-
if (Array.isArray(aliases)) {
|
|
1874
|
-
Array.prototype.push.apply(env.classes, aliases);
|
|
1875
|
-
} else {
|
|
1876
|
-
env.classes.push(aliases);
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
|
-
_.hooks.run('wrap', env);
|
|
1881
|
-
|
|
1882
|
-
var attributes = '';
|
|
1883
|
-
for (var name in env.attributes) {
|
|
1884
|
-
attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"';
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
|
|
1888
|
-
};
|
|
1889
|
-
|
|
1890
|
-
/**
|
|
1891
|
-
* @param {RegExp} pattern
|
|
1892
|
-
* @param {number} pos
|
|
1893
|
-
* @param {string} text
|
|
1894
|
-
* @param {boolean} lookbehind
|
|
1895
|
-
* @returns {RegExpExecArray | null}
|
|
1896
|
-
*/
|
|
1897
|
-
function matchPattern(pattern, pos, text, lookbehind) {
|
|
1898
|
-
pattern.lastIndex = pos;
|
|
1899
|
-
var match = pattern.exec(text);
|
|
1900
|
-
if (match && lookbehind && match[1]) {
|
|
1901
|
-
// change the match to remove the text matched by the Prism lookbehind group
|
|
1902
|
-
var lookbehindLength = match[1].length;
|
|
1903
|
-
match.index += lookbehindLength;
|
|
1904
|
-
match[0] = match[0].slice(lookbehindLength);
|
|
1905
|
-
}
|
|
1906
|
-
return match;
|
|
1907
|
-
}
|
|
1908
|
-
|
|
1909
|
-
/**
|
|
1910
|
-
* @param {string} text
|
|
1911
|
-
* @param {LinkedList<string | Token>} tokenList
|
|
1912
|
-
* @param {any} grammar
|
|
1913
|
-
* @param {LinkedListNode<string | Token>} startNode
|
|
1914
|
-
* @param {number} startPos
|
|
1915
|
-
* @param {RematchOptions} [rematch]
|
|
1916
|
-
* @returns {void}
|
|
1917
|
-
* @private
|
|
1918
|
-
*
|
|
1919
|
-
* @typedef RematchOptions
|
|
1920
|
-
* @property {string} cause
|
|
1921
|
-
* @property {number} reach
|
|
1922
|
-
*/
|
|
1923
|
-
function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
|
|
1924
|
-
for (var token in grammar) {
|
|
1925
|
-
if (!grammar.hasOwnProperty(token) || !grammar[token]) {
|
|
1926
|
-
continue;
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
var patterns = grammar[token];
|
|
1930
|
-
patterns = Array.isArray(patterns) ? patterns : [patterns];
|
|
1931
|
-
|
|
1932
|
-
for (var j = 0; j < patterns.length; ++j) {
|
|
1933
|
-
if (rematch && rematch.cause == token + ',' + j) {
|
|
1934
|
-
return;
|
|
1935
|
-
}
|
|
1936
|
-
|
|
1937
|
-
var patternObj = patterns[j];
|
|
1938
|
-
var inside = patternObj.inside;
|
|
1939
|
-
var lookbehind = !!patternObj.lookbehind;
|
|
1940
|
-
var greedy = !!patternObj.greedy;
|
|
1941
|
-
var alias = patternObj.alias;
|
|
1942
|
-
|
|
1943
|
-
if (greedy && !patternObj.pattern.global) {
|
|
1944
|
-
// Without the global flag, lastIndex won't work
|
|
1945
|
-
var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
|
|
1946
|
-
patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
/** @type {RegExp} */
|
|
1950
|
-
var pattern = patternObj.pattern || patternObj;
|
|
1951
|
-
|
|
1952
|
-
for ( // iterate the token list and keep track of the current token/string position
|
|
1953
|
-
var currentNode = startNode.next, pos = startPos;
|
|
1954
|
-
currentNode !== tokenList.tail;
|
|
1955
|
-
pos += currentNode.value.length, currentNode = currentNode.next
|
|
1956
|
-
) {
|
|
1957
|
-
|
|
1958
|
-
if (rematch && pos >= rematch.reach) {
|
|
1959
|
-
break;
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
|
-
var str = currentNode.value;
|
|
1963
|
-
|
|
1964
|
-
if (tokenList.length > text.length) {
|
|
1965
|
-
// Something went terribly wrong, ABORT, ABORT!
|
|
1966
|
-
return;
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
if (str instanceof Token) {
|
|
1970
|
-
continue;
|
|
1971
|
-
}
|
|
1972
|
-
|
|
1973
|
-
var removeCount = 1; // this is the to parameter of removeBetween
|
|
1974
|
-
var match;
|
|
1975
|
-
|
|
1976
|
-
if (greedy) {
|
|
1977
|
-
match = matchPattern(pattern, pos, text, lookbehind);
|
|
1978
|
-
if (!match || match.index >= text.length) {
|
|
1979
|
-
break;
|
|
1980
|
-
}
|
|
1981
|
-
|
|
1982
|
-
var from = match.index;
|
|
1983
|
-
var to = match.index + match[0].length;
|
|
1984
|
-
var p = pos;
|
|
1985
|
-
|
|
1986
|
-
// find the node that contains the match
|
|
1987
|
-
p += currentNode.value.length;
|
|
1988
|
-
while (from >= p) {
|
|
1989
|
-
currentNode = currentNode.next;
|
|
1990
|
-
p += currentNode.value.length;
|
|
1991
|
-
}
|
|
1992
|
-
// adjust pos (and p)
|
|
1993
|
-
p -= currentNode.value.length;
|
|
1994
|
-
pos = p;
|
|
1995
|
-
|
|
1996
|
-
// the current node is a Token, then the match starts inside another Token, which is invalid
|
|
1997
|
-
if (currentNode.value instanceof Token) {
|
|
1998
|
-
continue;
|
|
1999
|
-
}
|
|
2000
|
-
|
|
2001
|
-
// find the last node which is affected by this match
|
|
2002
|
-
for (
|
|
2003
|
-
var k = currentNode;
|
|
2004
|
-
k !== tokenList.tail && (p < to || typeof k.value === 'string');
|
|
2005
|
-
k = k.next
|
|
2006
|
-
) {
|
|
2007
|
-
removeCount++;
|
|
2008
|
-
p += k.value.length;
|
|
2009
|
-
}
|
|
2010
|
-
removeCount--;
|
|
2011
|
-
|
|
2012
|
-
// replace with the new match
|
|
2013
|
-
str = text.slice(pos, p);
|
|
2014
|
-
match.index -= pos;
|
|
2015
|
-
} else {
|
|
2016
|
-
match = matchPattern(pattern, 0, str, lookbehind);
|
|
2017
|
-
if (!match) {
|
|
2018
|
-
continue;
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
|
|
2022
|
-
// eslint-disable-next-line no-redeclare
|
|
2023
|
-
var from = match.index;
|
|
2024
|
-
var matchStr = match[0];
|
|
2025
|
-
var before = str.slice(0, from);
|
|
2026
|
-
var after = str.slice(from + matchStr.length);
|
|
2027
|
-
|
|
2028
|
-
var reach = pos + str.length;
|
|
2029
|
-
if (rematch && reach > rematch.reach) {
|
|
2030
|
-
rematch.reach = reach;
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
|
-
var removeFrom = currentNode.prev;
|
|
2034
|
-
|
|
2035
|
-
if (before) {
|
|
2036
|
-
removeFrom = addAfter(tokenList, removeFrom, before);
|
|
2037
|
-
pos += before.length;
|
|
2038
|
-
}
|
|
2039
|
-
|
|
2040
|
-
removeRange(tokenList, removeFrom, removeCount);
|
|
2041
|
-
|
|
2042
|
-
var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
|
|
2043
|
-
currentNode = addAfter(tokenList, removeFrom, wrapped);
|
|
2044
|
-
|
|
2045
|
-
if (after) {
|
|
2046
|
-
addAfter(tokenList, currentNode, after);
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
|
-
if (removeCount > 1) {
|
|
2050
|
-
// at least one Token object was removed, so we have to do some rematching
|
|
2051
|
-
// this can only happen if the current pattern is greedy
|
|
2052
|
-
|
|
2053
|
-
/** @type {RematchOptions} */
|
|
2054
|
-
var nestedRematch = {
|
|
2055
|
-
cause: token + ',' + j,
|
|
2056
|
-
reach: reach
|
|
2057
|
-
};
|
|
2058
|
-
matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
|
|
2059
|
-
|
|
2060
|
-
// the reach might have been extended because of the rematching
|
|
2061
|
-
if (rematch && nestedRematch.reach > rematch.reach) {
|
|
2062
|
-
rematch.reach = nestedRematch.reach;
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2070
|
-
/**
|
|
2071
|
-
* @typedef LinkedListNode
|
|
2072
|
-
* @property {T} value
|
|
2073
|
-
* @property {LinkedListNode<T> | null} prev The previous node.
|
|
2074
|
-
* @property {LinkedListNode<T> | null} next The next node.
|
|
2075
|
-
* @template T
|
|
2076
|
-
* @private
|
|
2077
|
-
*/
|
|
2078
|
-
|
|
2079
|
-
/**
|
|
2080
|
-
* @template T
|
|
2081
|
-
* @private
|
|
2082
|
-
*/
|
|
2083
|
-
function LinkedList() {
|
|
2084
|
-
/** @type {LinkedListNode<T>} */
|
|
2085
|
-
var head = { value: null, prev: null, next: null };
|
|
2086
|
-
/** @type {LinkedListNode<T>} */
|
|
2087
|
-
var tail = { value: null, prev: head, next: null };
|
|
2088
|
-
head.next = tail;
|
|
2089
|
-
|
|
2090
|
-
/** @type {LinkedListNode<T>} */
|
|
2091
|
-
this.head = head;
|
|
2092
|
-
/** @type {LinkedListNode<T>} */
|
|
2093
|
-
this.tail = tail;
|
|
2094
|
-
this.length = 0;
|
|
2095
|
-
}
|
|
2096
|
-
|
|
2097
|
-
/**
|
|
2098
|
-
* Adds a new node with the given value to the list.
|
|
2099
|
-
*
|
|
2100
|
-
* @param {LinkedList<T>} list
|
|
2101
|
-
* @param {LinkedListNode<T>} node
|
|
2102
|
-
* @param {T} value
|
|
2103
|
-
* @returns {LinkedListNode<T>} The added node.
|
|
2104
|
-
* @template T
|
|
2105
|
-
*/
|
|
2106
|
-
function addAfter(list, node, value) {
|
|
2107
|
-
// assumes that node != list.tail && values.length >= 0
|
|
2108
|
-
var next = node.next;
|
|
2109
|
-
|
|
2110
|
-
var newNode = { value: value, prev: node, next: next };
|
|
2111
|
-
node.next = newNode;
|
|
2112
|
-
next.prev = newNode;
|
|
2113
|
-
list.length++;
|
|
2114
|
-
|
|
2115
|
-
return newNode;
|
|
2116
|
-
}
|
|
2117
|
-
/**
|
|
2118
|
-
* Removes `count` nodes after the given node. The given node will not be removed.
|
|
2119
|
-
*
|
|
2120
|
-
* @param {LinkedList<T>} list
|
|
2121
|
-
* @param {LinkedListNode<T>} node
|
|
2122
|
-
* @param {number} count
|
|
2123
|
-
* @template T
|
|
2124
|
-
*/
|
|
2125
|
-
function removeRange(list, node, count) {
|
|
2126
|
-
var next = node.next;
|
|
2127
|
-
for (var i = 0; i < count && next !== list.tail; i++) {
|
|
2128
|
-
next = next.next;
|
|
2129
|
-
}
|
|
2130
|
-
node.next = next;
|
|
2131
|
-
next.prev = node;
|
|
2132
|
-
list.length -= i;
|
|
2133
|
-
}
|
|
2134
|
-
/**
|
|
2135
|
-
* @param {LinkedList<T>} list
|
|
2136
|
-
* @returns {T[]}
|
|
2137
|
-
* @template T
|
|
2138
|
-
*/
|
|
2139
|
-
function toArray(list) {
|
|
2140
|
-
var array = [];
|
|
2141
|
-
var node = list.head.next;
|
|
2142
|
-
while (node !== list.tail) {
|
|
2143
|
-
array.push(node.value);
|
|
2144
|
-
node = node.next;
|
|
2145
|
-
}
|
|
2146
|
-
return array;
|
|
2147
|
-
}
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
if (!_self.document) {
|
|
2151
|
-
if (!_self.addEventListener) {
|
|
2152
|
-
// in Node.js
|
|
2153
|
-
return _;
|
|
2154
|
-
}
|
|
2155
|
-
|
|
2156
|
-
if (!_.disableWorkerMessageHandler) {
|
|
2157
|
-
// In worker
|
|
2158
|
-
_self.addEventListener('message', function (evt) {
|
|
2159
|
-
var message = JSON.parse(evt.data);
|
|
2160
|
-
var lang = message.language;
|
|
2161
|
-
var code = message.code;
|
|
2162
|
-
var immediateClose = message.immediateClose;
|
|
2163
|
-
|
|
2164
|
-
_self.postMessage(_.highlight(code, _.languages[lang], lang));
|
|
2165
|
-
if (immediateClose) {
|
|
2166
|
-
_self.close();
|
|
2167
|
-
}
|
|
2168
|
-
}, false);
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
return _;
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
// Get current script and highlight
|
|
2175
|
-
var script = _.util.currentScript();
|
|
2176
|
-
|
|
2177
|
-
if (script) {
|
|
2178
|
-
_.filename = script.src;
|
|
2179
|
-
|
|
2180
|
-
if (script.hasAttribute('data-manual')) {
|
|
2181
|
-
_.manual = true;
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
|
|
2185
|
-
function highlightAutomaticallyCallback() {
|
|
2186
|
-
if (!_.manual) {
|
|
2187
|
-
_.highlightAll();
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
|
|
2191
|
-
if (!_.manual) {
|
|
2192
|
-
// If the document state is "loading", then we'll use DOMContentLoaded.
|
|
2193
|
-
// If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
|
|
2194
|
-
// DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
|
|
2195
|
-
// might take longer one animation frame to execute which can create a race condition where only some plugins have
|
|
2196
|
-
// been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
|
|
2197
|
-
// See https://github.com/PrismJS/prism/issues/2102
|
|
2198
|
-
var readyState = document.readyState;
|
|
2199
|
-
if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
|
|
2200
|
-
document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
|
|
2201
|
-
} else {
|
|
2202
|
-
if (window.requestAnimationFrame) {
|
|
2203
|
-
window.requestAnimationFrame(highlightAutomaticallyCallback);
|
|
2204
|
-
} else {
|
|
2205
|
-
window.setTimeout(highlightAutomaticallyCallback, 16);
|
|
2206
|
-
}
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2210
|
-
return _;
|
|
2211
|
-
|
|
2212
|
-
}(_self));
|
|
2213
|
-
|
|
2214
|
-
if ('object' !== 'undefined' && module.exports) {
|
|
2215
|
-
module.exports = Prism;
|
|
2216
|
-
}
|
|
2217
|
-
|
|
2218
|
-
// hack for components to work correctly in node.js
|
|
2219
|
-
if (typeof commonjsGlobal !== 'undefined') {
|
|
2220
|
-
commonjsGlobal.Prism = Prism;
|
|
2221
|
-
}
|
|
2222
|
-
|
|
2223
|
-
// some additional documentation/types
|
|
2224
|
-
|
|
2225
|
-
/**
|
|
2226
|
-
* The expansion of a simple `RegExp` literal to support additional properties.
|
|
2227
|
-
*
|
|
2228
|
-
* @typedef GrammarToken
|
|
2229
|
-
* @property {RegExp} pattern The regular expression of the token.
|
|
2230
|
-
* @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
|
|
2231
|
-
* behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
|
|
2232
|
-
* @property {boolean} [greedy=false] Whether the token is greedy.
|
|
2233
|
-
* @property {string|string[]} [alias] An optional alias or list of aliases.
|
|
2234
|
-
* @property {Grammar} [inside] The nested grammar of this token.
|
|
2235
|
-
*
|
|
2236
|
-
* The `inside` grammar will be used to tokenize the text value of each token of this kind.
|
|
2237
|
-
*
|
|
2238
|
-
* This can be used to make nested and even recursive language definitions.
|
|
2239
|
-
*
|
|
2240
|
-
* Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
|
|
2241
|
-
* each another.
|
|
2242
|
-
* @global
|
|
2243
|
-
* @public
|
|
2244
|
-
*/
|
|
2245
|
-
|
|
2246
|
-
/**
|
|
2247
|
-
* @typedef Grammar
|
|
2248
|
-
* @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
|
|
2249
|
-
* @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
|
|
2250
|
-
* @global
|
|
2251
|
-
* @public
|
|
2252
|
-
*/
|
|
2253
|
-
|
|
2254
|
-
/**
|
|
2255
|
-
* A function which will invoked after an element was successfully highlighted.
|
|
2256
|
-
*
|
|
2257
|
-
* @callback HighlightCallback
|
|
2258
|
-
* @param {Element} element The element successfully highlighted.
|
|
2259
|
-
* @returns {void}
|
|
2260
|
-
* @global
|
|
2261
|
-
* @public
|
|
2262
|
-
*/
|
|
2263
|
-
|
|
2264
|
-
/**
|
|
2265
|
-
* @callback HookCallback
|
|
2266
|
-
* @param {Object<string, any>} env The environment variables of the hook.
|
|
2267
|
-
* @returns {void}
|
|
2268
|
-
* @global
|
|
2269
|
-
* @public
|
|
2270
|
-
*/
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
/* **********************************************
|
|
2274
|
-
Begin prism-markup.js
|
|
2275
|
-
********************************************** */
|
|
2276
|
-
|
|
2277
|
-
Prism.languages.markup = {
|
|
2278
|
-
'comment': {
|
|
2279
|
-
pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
|
|
2280
|
-
greedy: true
|
|
2281
|
-
},
|
|
2282
|
-
'prolog': {
|
|
2283
|
-
pattern: /<\?[\s\S]+?\?>/,
|
|
2284
|
-
greedy: true
|
|
2285
|
-
},
|
|
2286
|
-
'doctype': {
|
|
2287
|
-
// https://www.w3.org/TR/xml/#NT-doctypedecl
|
|
2288
|
-
pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
|
|
2289
|
-
greedy: true,
|
|
2290
|
-
inside: {
|
|
2291
|
-
'internal-subset': {
|
|
2292
|
-
pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
|
|
2293
|
-
lookbehind: true,
|
|
2294
|
-
greedy: true,
|
|
2295
|
-
inside: null // see below
|
|
2296
|
-
},
|
|
2297
|
-
'string': {
|
|
2298
|
-
pattern: /"[^"]*"|'[^']*'/,
|
|
2299
|
-
greedy: true
|
|
2300
|
-
},
|
|
2301
|
-
'punctuation': /^<!|>$|[[\]]/,
|
|
2302
|
-
'doctype-tag': /^DOCTYPE/i,
|
|
2303
|
-
'name': /[^\s<>'"]+/
|
|
2304
|
-
}
|
|
2305
|
-
},
|
|
2306
|
-
'cdata': {
|
|
2307
|
-
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
|
2308
|
-
greedy: true
|
|
2309
|
-
},
|
|
2310
|
-
'tag': {
|
|
2311
|
-
pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
|
|
2312
|
-
greedy: true,
|
|
2313
|
-
inside: {
|
|
2314
|
-
'tag': {
|
|
2315
|
-
pattern: /^<\/?[^\s>\/]+/,
|
|
2316
|
-
inside: {
|
|
2317
|
-
'punctuation': /^<\/?/,
|
|
2318
|
-
'namespace': /^[^\s>\/:]+:/
|
|
2319
|
-
}
|
|
2320
|
-
},
|
|
2321
|
-
'special-attr': [],
|
|
2322
|
-
'attr-value': {
|
|
2323
|
-
pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
|
|
2324
|
-
inside: {
|
|
2325
|
-
'punctuation': [
|
|
2326
|
-
{
|
|
2327
|
-
pattern: /^=/,
|
|
2328
|
-
alias: 'attr-equals'
|
|
2329
|
-
},
|
|
2330
|
-
{
|
|
2331
|
-
pattern: /^(\s*)["']|["']$/,
|
|
2332
|
-
lookbehind: true
|
|
2333
|
-
}
|
|
2334
|
-
]
|
|
2335
|
-
}
|
|
2336
|
-
},
|
|
2337
|
-
'punctuation': /\/?>/,
|
|
2338
|
-
'attr-name': {
|
|
2339
|
-
pattern: /[^\s>\/]+/,
|
|
2340
|
-
inside: {
|
|
2341
|
-
'namespace': /^[^\s>\/:]+:/
|
|
2342
|
-
}
|
|
2343
|
-
}
|
|
2344
|
-
|
|
2345
|
-
}
|
|
2346
|
-
},
|
|
2347
|
-
'entity': [
|
|
2348
|
-
{
|
|
2349
|
-
pattern: /&[\da-z]{1,8};/i,
|
|
2350
|
-
alias: 'named-entity'
|
|
2351
|
-
},
|
|
2352
|
-
/&#x?[\da-f]{1,8};/i
|
|
2353
|
-
]
|
|
2354
|
-
};
|
|
2355
|
-
|
|
2356
|
-
Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
|
|
2357
|
-
Prism.languages.markup['entity'];
|
|
2358
|
-
Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
|
|
2359
|
-
|
|
2360
|
-
// Plugin to make entity title show the real entity, idea by Roman Komarov
|
|
2361
|
-
Prism.hooks.add('wrap', function (env) {
|
|
2362
|
-
|
|
2363
|
-
if (env.type === 'entity') {
|
|
2364
|
-
env.attributes['title'] = env.content.replace(/&/, '&');
|
|
2365
|
-
}
|
|
2366
|
-
});
|
|
2367
|
-
|
|
2368
|
-
Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
|
|
2369
|
-
/**
|
|
2370
|
-
* Adds an inlined language to markup.
|
|
2371
|
-
*
|
|
2372
|
-
* An example of an inlined language is CSS with `<style>` tags.
|
|
2373
|
-
*
|
|
2374
|
-
* @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
|
|
2375
|
-
* case insensitive.
|
|
2376
|
-
* @param {string} lang The language key.
|
|
2377
|
-
* @example
|
|
2378
|
-
* addInlined('style', 'css');
|
|
2379
|
-
*/
|
|
2380
|
-
value: function addInlined(tagName, lang) {
|
|
2381
|
-
var includedCdataInside = {};
|
|
2382
|
-
includedCdataInside['language-' + lang] = {
|
|
2383
|
-
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
|
|
2384
|
-
lookbehind: true,
|
|
2385
|
-
inside: Prism.languages[lang]
|
|
2386
|
-
};
|
|
2387
|
-
includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
|
|
2388
|
-
|
|
2389
|
-
var inside = {
|
|
2390
|
-
'included-cdata': {
|
|
2391
|
-
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
|
2392
|
-
inside: includedCdataInside
|
|
2393
|
-
}
|
|
2394
|
-
};
|
|
2395
|
-
inside['language-' + lang] = {
|
|
2396
|
-
pattern: /[\s\S]+/,
|
|
2397
|
-
inside: Prism.languages[lang]
|
|
2398
|
-
};
|
|
2399
|
-
|
|
2400
|
-
var def = {};
|
|
2401
|
-
def[tagName] = {
|
|
2402
|
-
pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
|
|
2403
|
-
lookbehind: true,
|
|
2404
|
-
greedy: true,
|
|
2405
|
-
inside: inside
|
|
2406
|
-
};
|
|
2407
|
-
|
|
2408
|
-
Prism.languages.insertBefore('markup', 'cdata', def);
|
|
2409
|
-
}
|
|
2410
|
-
});
|
|
2411
|
-
Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
|
|
2412
|
-
/**
|
|
2413
|
-
* Adds an pattern to highlight languages embedded in HTML attributes.
|
|
2414
|
-
*
|
|
2415
|
-
* An example of an inlined language is CSS with `style` attributes.
|
|
2416
|
-
*
|
|
2417
|
-
* @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
|
|
2418
|
-
* case insensitive.
|
|
2419
|
-
* @param {string} lang The language key.
|
|
2420
|
-
* @example
|
|
2421
|
-
* addAttribute('style', 'css');
|
|
2422
|
-
*/
|
|
2423
|
-
value: function (attrName, lang) {
|
|
2424
|
-
Prism.languages.markup.tag.inside['special-attr'].push({
|
|
2425
|
-
pattern: RegExp(
|
|
2426
|
-
/(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
|
|
2427
|
-
'i'
|
|
2428
|
-
),
|
|
2429
|
-
lookbehind: true,
|
|
2430
|
-
inside: {
|
|
2431
|
-
'attr-name': /^[^\s=]+/,
|
|
2432
|
-
'attr-value': {
|
|
2433
|
-
pattern: /=[\s\S]+/,
|
|
2434
|
-
inside: {
|
|
2435
|
-
'value': {
|
|
2436
|
-
pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
|
|
2437
|
-
lookbehind: true,
|
|
2438
|
-
alias: [lang, 'language-' + lang],
|
|
2439
|
-
inside: Prism.languages[lang]
|
|
2440
|
-
},
|
|
2441
|
-
'punctuation': [
|
|
2442
|
-
{
|
|
2443
|
-
pattern: /^=/,
|
|
2444
|
-
alias: 'attr-equals'
|
|
2445
|
-
},
|
|
2446
|
-
/"|'/
|
|
2447
|
-
]
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
});
|
|
2452
|
-
}
|
|
2453
|
-
});
|
|
2454
|
-
|
|
2455
|
-
Prism.languages.html = Prism.languages.markup;
|
|
2456
|
-
Prism.languages.mathml = Prism.languages.markup;
|
|
2457
|
-
Prism.languages.svg = Prism.languages.markup;
|
|
2458
|
-
|
|
2459
|
-
Prism.languages.xml = Prism.languages.extend('markup', {});
|
|
2460
|
-
Prism.languages.ssml = Prism.languages.xml;
|
|
2461
|
-
Prism.languages.atom = Prism.languages.xml;
|
|
2462
|
-
Prism.languages.rss = Prism.languages.xml;
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
/* **********************************************
|
|
2466
|
-
Begin prism-css.js
|
|
2467
|
-
********************************************** */
|
|
2468
|
-
|
|
2469
|
-
(function (Prism) {
|
|
2470
|
-
|
|
2471
|
-
var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
|
|
2472
|
-
|
|
2473
|
-
Prism.languages.css = {
|
|
2474
|
-
'comment': /\/\*[\s\S]*?\*\//,
|
|
2475
|
-
'atrule': {
|
|
2476
|
-
pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
|
|
2477
|
-
inside: {
|
|
2478
|
-
'rule': /^@[\w-]+/,
|
|
2479
|
-
'selector-function-argument': {
|
|
2480
|
-
pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
|
|
2481
|
-
lookbehind: true,
|
|
2482
|
-
alias: 'selector'
|
|
2483
|
-
},
|
|
2484
|
-
'keyword': {
|
|
2485
|
-
pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
|
|
2486
|
-
lookbehind: true
|
|
2487
|
-
}
|
|
2488
|
-
// See rest below
|
|
2489
|
-
}
|
|
2490
|
-
},
|
|
2491
|
-
'url': {
|
|
2492
|
-
// https://drafts.csswg.org/css-values-3/#urls
|
|
2493
|
-
pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
|
|
2494
|
-
greedy: true,
|
|
2495
|
-
inside: {
|
|
2496
|
-
'function': /^url/i,
|
|
2497
|
-
'punctuation': /^\(|\)$/,
|
|
2498
|
-
'string': {
|
|
2499
|
-
pattern: RegExp('^' + string.source + '$'),
|
|
2500
|
-
alias: 'url'
|
|
2501
|
-
}
|
|
2502
|
-
}
|
|
2503
|
-
},
|
|
2504
|
-
'selector': {
|
|
2505
|
-
pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
|
|
2506
|
-
lookbehind: true
|
|
2507
|
-
},
|
|
2508
|
-
'string': {
|
|
2509
|
-
pattern: string,
|
|
2510
|
-
greedy: true
|
|
2511
|
-
},
|
|
2512
|
-
'property': {
|
|
2513
|
-
pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
|
|
2514
|
-
lookbehind: true
|
|
2515
|
-
},
|
|
2516
|
-
'important': /!important\b/i,
|
|
2517
|
-
'function': {
|
|
2518
|
-
pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
|
|
2519
|
-
lookbehind: true
|
|
2520
|
-
},
|
|
2521
|
-
'punctuation': /[(){};:,]/
|
|
2522
|
-
};
|
|
2523
|
-
|
|
2524
|
-
Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
|
|
2525
|
-
|
|
2526
|
-
var markup = Prism.languages.markup;
|
|
2527
|
-
if (markup) {
|
|
2528
|
-
markup.tag.addInlined('style', 'css');
|
|
2529
|
-
markup.tag.addAttribute('style', 'css');
|
|
2530
|
-
}
|
|
2531
|
-
|
|
2532
|
-
}(Prism));
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
/* **********************************************
|
|
2536
|
-
Begin prism-clike.js
|
|
2537
|
-
********************************************** */
|
|
2538
|
-
|
|
2539
|
-
Prism.languages.clike = {
|
|
2540
|
-
'comment': [
|
|
2541
|
-
{
|
|
2542
|
-
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
|
|
2543
|
-
lookbehind: true,
|
|
2544
|
-
greedy: true
|
|
2545
|
-
},
|
|
2546
|
-
{
|
|
2547
|
-
pattern: /(^|[^\\:])\/\/.*/,
|
|
2548
|
-
lookbehind: true,
|
|
2549
|
-
greedy: true
|
|
2550
|
-
}
|
|
2551
|
-
],
|
|
2552
|
-
'string': {
|
|
2553
|
-
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
|
2554
|
-
greedy: true
|
|
2555
|
-
},
|
|
2556
|
-
'class-name': {
|
|
2557
|
-
pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
|
|
2558
|
-
lookbehind: true,
|
|
2559
|
-
inside: {
|
|
2560
|
-
'punctuation': /[.\\]/
|
|
2561
|
-
}
|
|
2562
|
-
},
|
|
2563
|
-
'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
|
|
2564
|
-
'boolean': /\b(?:false|true)\b/,
|
|
2565
|
-
'function': /\b\w+(?=\()/,
|
|
2566
|
-
'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
|
2567
|
-
'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
|
2568
|
-
'punctuation': /[{}[\];(),.:]/
|
|
2569
|
-
};
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
/* **********************************************
|
|
2573
|
-
Begin prism-javascript.js
|
|
2574
|
-
********************************************** */
|
|
2575
|
-
|
|
2576
|
-
Prism.languages.javascript = Prism.languages.extend('clike', {
|
|
2577
|
-
'class-name': [
|
|
2578
|
-
Prism.languages.clike['class-name'],
|
|
2579
|
-
{
|
|
2580
|
-
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
|
|
2581
|
-
lookbehind: true
|
|
2582
|
-
}
|
|
2583
|
-
],
|
|
2584
|
-
'keyword': [
|
|
2585
|
-
{
|
|
2586
|
-
pattern: /((?:^|\})\s*)catch\b/,
|
|
2587
|
-
lookbehind: true
|
|
2588
|
-
},
|
|
2589
|
-
{
|
|
2590
|
-
pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
|
|
2591
|
-
lookbehind: true
|
|
2592
|
-
},
|
|
2593
|
-
],
|
|
2594
|
-
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
|
2595
|
-
'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
|
2596
|
-
'number': {
|
|
2597
|
-
pattern: RegExp(
|
|
2598
|
-
/(^|[^\w$])/.source +
|
|
2599
|
-
'(?:' +
|
|
2600
|
-
(
|
|
2601
|
-
// constant
|
|
2602
|
-
/NaN|Infinity/.source +
|
|
2603
|
-
'|' +
|
|
2604
|
-
// binary integer
|
|
2605
|
-
/0[bB][01]+(?:_[01]+)*n?/.source +
|
|
2606
|
-
'|' +
|
|
2607
|
-
// octal integer
|
|
2608
|
-
/0[oO][0-7]+(?:_[0-7]+)*n?/.source +
|
|
2609
|
-
'|' +
|
|
2610
|
-
// hexadecimal integer
|
|
2611
|
-
/0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source +
|
|
2612
|
-
'|' +
|
|
2613
|
-
// decimal bigint
|
|
2614
|
-
/\d+(?:_\d+)*n/.source +
|
|
2615
|
-
'|' +
|
|
2616
|
-
// decimal number (integer or float) but no bigint
|
|
2617
|
-
/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source
|
|
2618
|
-
) +
|
|
2619
|
-
')' +
|
|
2620
|
-
/(?![\w$])/.source
|
|
2621
|
-
),
|
|
2622
|
-
lookbehind: true
|
|
2623
|
-
},
|
|
2624
|
-
'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
|
2625
|
-
});
|
|
2626
|
-
|
|
2627
|
-
Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
|
|
2628
|
-
|
|
2629
|
-
Prism.languages.insertBefore('javascript', 'keyword', {
|
|
2630
|
-
'regex': {
|
|
2631
|
-
pattern: RegExp(
|
|
2632
|
-
// lookbehind
|
|
2633
|
-
// eslint-disable-next-line regexp/no-dupe-characters-character-class
|
|
2634
|
-
/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source +
|
|
2635
|
-
// Regex pattern:
|
|
2636
|
-
// There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
|
|
2637
|
-
// classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
|
|
2638
|
-
// with the only syntax, so we have to define 2 different regex patterns.
|
|
2639
|
-
/\//.source +
|
|
2640
|
-
'(?:' +
|
|
2641
|
-
/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source +
|
|
2642
|
-
'|' +
|
|
2643
|
-
// `v` flag syntax. This supports 3 levels of nested character classes.
|
|
2644
|
-
/(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source +
|
|
2645
|
-
')' +
|
|
2646
|
-
// lookahead
|
|
2647
|
-
/(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
|
|
2648
|
-
),
|
|
2649
|
-
lookbehind: true,
|
|
2650
|
-
greedy: true,
|
|
2651
|
-
inside: {
|
|
2652
|
-
'regex-source': {
|
|
2653
|
-
pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
|
|
2654
|
-
lookbehind: true,
|
|
2655
|
-
alias: 'language-regex',
|
|
2656
|
-
inside: Prism.languages.regex
|
|
2657
|
-
},
|
|
2658
|
-
'regex-delimiter': /^\/|\/$/,
|
|
2659
|
-
'regex-flags': /^[a-z]+$/,
|
|
2660
|
-
}
|
|
2661
|
-
},
|
|
2662
|
-
// This must be declared before keyword because we use "function" inside the look-forward
|
|
2663
|
-
'function-variable': {
|
|
2664
|
-
pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
|
|
2665
|
-
alias: 'function'
|
|
2666
|
-
},
|
|
2667
|
-
'parameter': [
|
|
2668
|
-
{
|
|
2669
|
-
pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
|
|
2670
|
-
lookbehind: true,
|
|
2671
|
-
inside: Prism.languages.javascript
|
|
2672
|
-
},
|
|
2673
|
-
{
|
|
2674
|
-
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
|
|
2675
|
-
lookbehind: true,
|
|
2676
|
-
inside: Prism.languages.javascript
|
|
2677
|
-
},
|
|
2678
|
-
{
|
|
2679
|
-
pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
|
|
2680
|
-
lookbehind: true,
|
|
2681
|
-
inside: Prism.languages.javascript
|
|
2682
|
-
},
|
|
2683
|
-
{
|
|
2684
|
-
pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
|
|
2685
|
-
lookbehind: true,
|
|
2686
|
-
inside: Prism.languages.javascript
|
|
2687
|
-
}
|
|
2688
|
-
],
|
|
2689
|
-
'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
|
2690
|
-
});
|
|
2691
|
-
|
|
2692
|
-
Prism.languages.insertBefore('javascript', 'string', {
|
|
2693
|
-
'hashbang': {
|
|
2694
|
-
pattern: /^#!.*/,
|
|
2695
|
-
greedy: true,
|
|
2696
|
-
alias: 'comment'
|
|
2697
|
-
},
|
|
2698
|
-
'template-string': {
|
|
2699
|
-
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
|
2700
|
-
greedy: true,
|
|
2701
|
-
inside: {
|
|
2702
|
-
'template-punctuation': {
|
|
2703
|
-
pattern: /^`|`$/,
|
|
2704
|
-
alias: 'string'
|
|
2705
|
-
},
|
|
2706
|
-
'interpolation': {
|
|
2707
|
-
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
|
2708
|
-
lookbehind: true,
|
|
2709
|
-
inside: {
|
|
2710
|
-
'interpolation-punctuation': {
|
|
2711
|
-
pattern: /^\$\{|\}$/,
|
|
2712
|
-
alias: 'punctuation'
|
|
2713
|
-
},
|
|
2714
|
-
rest: Prism.languages.javascript
|
|
2715
|
-
}
|
|
2716
|
-
},
|
|
2717
|
-
'string': /[\s\S]+/
|
|
2718
|
-
}
|
|
2719
|
-
},
|
|
2720
|
-
'string-property': {
|
|
2721
|
-
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
|
|
2722
|
-
lookbehind: true,
|
|
2723
|
-
greedy: true,
|
|
2724
|
-
alias: 'property'
|
|
2725
|
-
}
|
|
2726
|
-
});
|
|
2727
|
-
|
|
2728
|
-
Prism.languages.insertBefore('javascript', 'operator', {
|
|
2729
|
-
'literal-property': {
|
|
2730
|
-
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
|
|
2731
|
-
lookbehind: true,
|
|
2732
|
-
alias: 'property'
|
|
2733
|
-
},
|
|
2734
|
-
});
|
|
2735
|
-
|
|
2736
|
-
if (Prism.languages.markup) {
|
|
2737
|
-
Prism.languages.markup.tag.addInlined('script', 'javascript');
|
|
2738
|
-
|
|
2739
|
-
// add attribute support for all DOM events.
|
|
2740
|
-
// https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
|
|
2741
|
-
Prism.languages.markup.tag.addAttribute(
|
|
2742
|
-
/on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
|
|
2743
|
-
'javascript'
|
|
2744
|
-
);
|
|
2745
|
-
}
|
|
2746
|
-
|
|
2747
|
-
Prism.languages.js = Prism.languages.javascript;
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
/* **********************************************
|
|
2751
|
-
Begin prism-file-highlight.js
|
|
2752
|
-
********************************************** */
|
|
2753
|
-
|
|
2754
|
-
(function () {
|
|
2755
|
-
|
|
2756
|
-
if (typeof Prism === 'undefined' || typeof document === 'undefined') {
|
|
2757
|
-
return;
|
|
2758
|
-
}
|
|
2759
|
-
|
|
2760
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
|
|
2761
|
-
if (!Element.prototype.matches) {
|
|
2762
|
-
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
|
2763
|
-
}
|
|
2764
|
-
|
|
2765
|
-
var LOADING_MESSAGE = 'Loading…';
|
|
2766
|
-
var FAILURE_MESSAGE = function (status, message) {
|
|
2767
|
-
return '✖ Error ' + status + ' while fetching file: ' + message;
|
|
2768
|
-
};
|
|
2769
|
-
var FAILURE_EMPTY_MESSAGE = '✖ Error: File does not exist or is empty';
|
|
2770
|
-
|
|
2771
|
-
var EXTENSIONS = {
|
|
2772
|
-
'js': 'javascript',
|
|
2773
|
-
'py': 'python',
|
|
2774
|
-
'rb': 'ruby',
|
|
2775
|
-
'ps1': 'powershell',
|
|
2776
|
-
'psm1': 'powershell',
|
|
2777
|
-
'sh': 'bash',
|
|
2778
|
-
'bat': 'batch',
|
|
2779
|
-
'h': 'c',
|
|
2780
|
-
'tex': 'latex'
|
|
2781
|
-
};
|
|
2782
|
-
|
|
2783
|
-
var STATUS_ATTR = 'data-src-status';
|
|
2784
|
-
var STATUS_LOADING = 'loading';
|
|
2785
|
-
var STATUS_LOADED = 'loaded';
|
|
2786
|
-
var STATUS_FAILED = 'failed';
|
|
2787
|
-
|
|
2788
|
-
var SELECTOR = 'pre[data-src]:not([' + STATUS_ATTR + '="' + STATUS_LOADED + '"])'
|
|
2789
|
-
+ ':not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
|
|
2790
|
-
|
|
2791
|
-
/**
|
|
2792
|
-
* Loads the given file.
|
|
2793
|
-
*
|
|
2794
|
-
* @param {string} src The URL or path of the source file to load.
|
|
2795
|
-
* @param {(result: string) => void} success
|
|
2796
|
-
* @param {(reason: string) => void} error
|
|
2797
|
-
*/
|
|
2798
|
-
function loadFile(src, success, error) {
|
|
2799
|
-
var xhr = new XMLHttpRequest();
|
|
2800
|
-
xhr.open('GET', src, true);
|
|
2801
|
-
xhr.onreadystatechange = function () {
|
|
2802
|
-
if (xhr.readyState == 4) {
|
|
2803
|
-
if (xhr.status < 400 && xhr.responseText) {
|
|
2804
|
-
success(xhr.responseText);
|
|
2805
|
-
} else {
|
|
2806
|
-
if (xhr.status >= 400) {
|
|
2807
|
-
error(FAILURE_MESSAGE(xhr.status, xhr.statusText));
|
|
2808
|
-
} else {
|
|
2809
|
-
error(FAILURE_EMPTY_MESSAGE);
|
|
2810
|
-
}
|
|
2811
|
-
}
|
|
2812
|
-
}
|
|
2813
|
-
};
|
|
2814
|
-
xhr.send(null);
|
|
2815
|
-
}
|
|
2816
|
-
|
|
2817
|
-
/**
|
|
2818
|
-
* Parses the given range.
|
|
2819
|
-
*
|
|
2820
|
-
* This returns a range with inclusive ends.
|
|
2821
|
-
*
|
|
2822
|
-
* @param {string | null | undefined} range
|
|
2823
|
-
* @returns {[number, number | undefined] | undefined}
|
|
2824
|
-
*/
|
|
2825
|
-
function parseRange(range) {
|
|
2826
|
-
var m = /^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(range || '');
|
|
2827
|
-
if (m) {
|
|
2828
|
-
var start = Number(m[1]);
|
|
2829
|
-
var comma = m[2];
|
|
2830
|
-
var end = m[3];
|
|
2831
|
-
|
|
2832
|
-
if (!comma) {
|
|
2833
|
-
return [start, start];
|
|
2834
|
-
}
|
|
2835
|
-
if (!end) {
|
|
2836
|
-
return [start, undefined];
|
|
2837
|
-
}
|
|
2838
|
-
return [start, Number(end)];
|
|
2839
|
-
}
|
|
2840
|
-
return undefined;
|
|
2841
|
-
}
|
|
2842
|
-
|
|
2843
|
-
Prism.hooks.add('before-highlightall', function (env) {
|
|
2844
|
-
env.selector += ', ' + SELECTOR;
|
|
2845
|
-
});
|
|
2846
|
-
|
|
2847
|
-
Prism.hooks.add('before-sanity-check', function (env) {
|
|
2848
|
-
var pre = /** @type {HTMLPreElement} */ (env.element);
|
|
2849
|
-
if (pre.matches(SELECTOR)) {
|
|
2850
|
-
env.code = ''; // fast-path the whole thing and go to complete
|
|
2851
|
-
|
|
2852
|
-
pre.setAttribute(STATUS_ATTR, STATUS_LOADING); // mark as loading
|
|
2853
|
-
|
|
2854
|
-
// add code element with loading message
|
|
2855
|
-
var code = pre.appendChild(document.createElement('CODE'));
|
|
2856
|
-
code.textContent = LOADING_MESSAGE;
|
|
2857
|
-
|
|
2858
|
-
var src = pre.getAttribute('data-src');
|
|
2859
|
-
|
|
2860
|
-
var language = env.language;
|
|
2861
|
-
if (language === 'none') {
|
|
2862
|
-
// the language might be 'none' because there is no language set;
|
|
2863
|
-
// in this case, we want to use the extension as the language
|
|
2864
|
-
var extension = (/\.(\w+)$/.exec(src) || [, 'none'])[1];
|
|
2865
|
-
language = EXTENSIONS[extension] || extension;
|
|
2866
|
-
}
|
|
2867
|
-
|
|
2868
|
-
// set language classes
|
|
2869
|
-
Prism.util.setLanguage(code, language);
|
|
2870
|
-
Prism.util.setLanguage(pre, language);
|
|
2871
|
-
|
|
2872
|
-
// preload the language
|
|
2873
|
-
var autoloader = Prism.plugins.autoloader;
|
|
2874
|
-
if (autoloader) {
|
|
2875
|
-
autoloader.loadLanguages(language);
|
|
2876
|
-
}
|
|
2877
|
-
|
|
2878
|
-
// load file
|
|
2879
|
-
loadFile(
|
|
2880
|
-
src,
|
|
2881
|
-
function (text) {
|
|
2882
|
-
// mark as loaded
|
|
2883
|
-
pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
|
|
2884
|
-
|
|
2885
|
-
// handle data-range
|
|
2886
|
-
var range = parseRange(pre.getAttribute('data-range'));
|
|
2887
|
-
if (range) {
|
|
2888
|
-
var lines = text.split(/\r\n?|\n/g);
|
|
2889
|
-
|
|
2890
|
-
// the range is one-based and inclusive on both ends
|
|
2891
|
-
var start = range[0];
|
|
2892
|
-
var end = range[1] == null ? lines.length : range[1];
|
|
2893
|
-
|
|
2894
|
-
if (start < 0) { start += lines.length; }
|
|
2895
|
-
start = Math.max(0, Math.min(start - 1, lines.length));
|
|
2896
|
-
if (end < 0) { end += lines.length; }
|
|
2897
|
-
end = Math.max(0, Math.min(end, lines.length));
|
|
2898
|
-
|
|
2899
|
-
text = lines.slice(start, end).join('\n');
|
|
2900
|
-
|
|
2901
|
-
// add data-start for line numbers
|
|
2902
|
-
if (!pre.hasAttribute('data-start')) {
|
|
2903
|
-
pre.setAttribute('data-start', String(start + 1));
|
|
2904
|
-
}
|
|
2905
|
-
}
|
|
2906
|
-
|
|
2907
|
-
// highlight code
|
|
2908
|
-
code.textContent = text;
|
|
2909
|
-
Prism.highlightElement(code);
|
|
2910
|
-
},
|
|
2911
|
-
function (error) {
|
|
2912
|
-
// mark as failed
|
|
2913
|
-
pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
|
|
2914
|
-
|
|
2915
|
-
code.textContent = error;
|
|
2916
|
-
}
|
|
2917
|
-
);
|
|
2918
|
-
}
|
|
2919
|
-
});
|
|
2920
|
-
|
|
2921
|
-
Prism.plugins.fileHighlight = {
|
|
2922
|
-
/**
|
|
2923
|
-
* Executes the File Highlight plugin for all matching `pre` elements under the given container.
|
|
2924
|
-
*
|
|
2925
|
-
* Note: Elements which are already loaded or currently loading will not be touched by this method.
|
|
2926
|
-
*
|
|
2927
|
-
* @param {ParentNode} [container=document]
|
|
2928
|
-
*/
|
|
2929
|
-
highlight: function highlight(container) {
|
|
2930
|
-
var elements = (container || document).querySelectorAll(SELECTOR);
|
|
2931
|
-
|
|
2932
|
-
for (var i = 0, element; (element = elements[i++]);) {
|
|
2933
|
-
Prism.highlightElement(element);
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
};
|
|
2937
|
-
|
|
2938
|
-
var logged = false;
|
|
2939
|
-
/** @deprecated Use `Prism.plugins.fileHighlight.highlight` instead. */
|
|
2940
|
-
Prism.fileHighlight = function () {
|
|
2941
|
-
if (!logged) {
|
|
2942
|
-
console.warn('Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.');
|
|
2943
|
-
logged = true;
|
|
2944
|
-
}
|
|
2945
|
-
Prism.plugins.fileHighlight.highlight.apply(this, arguments);
|
|
2946
|
-
};
|
|
2947
|
-
|
|
2948
|
-
}());
|
|
2949
|
-
});
|
|
2950
|
-
|
|
2951
|
-
Prism.languages.clike = {
|
|
2952
|
-
'comment': [
|
|
2953
|
-
{
|
|
2954
|
-
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
|
|
2955
|
-
lookbehind: true,
|
|
2956
|
-
greedy: true
|
|
2957
|
-
},
|
|
2958
|
-
{
|
|
2959
|
-
pattern: /(^|[^\\:])\/\/.*/,
|
|
2960
|
-
lookbehind: true,
|
|
2961
|
-
greedy: true
|
|
2962
|
-
}
|
|
2963
|
-
],
|
|
2964
|
-
'string': {
|
|
2965
|
-
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
|
2966
|
-
greedy: true
|
|
2967
|
-
},
|
|
2968
|
-
'class-name': {
|
|
2969
|
-
pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
|
|
2970
|
-
lookbehind: true,
|
|
2971
|
-
inside: {
|
|
2972
|
-
'punctuation': /[.\\]/
|
|
2973
|
-
}
|
|
2974
|
-
},
|
|
2975
|
-
'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
|
|
2976
|
-
'boolean': /\b(?:false|true)\b/,
|
|
2977
|
-
'function': /\b\w+(?=\()/,
|
|
2978
|
-
'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
|
2979
|
-
'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
|
2980
|
-
'punctuation': /[{}[\];(),.:]/
|
|
2981
|
-
};
|
|
2982
|
-
|
|
2983
|
-
Prism.languages.javascript = Prism.languages.extend('clike', {
|
|
2984
|
-
'class-name': [
|
|
2985
|
-
Prism.languages.clike['class-name'],
|
|
2986
|
-
{
|
|
2987
|
-
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
|
|
2988
|
-
lookbehind: true
|
|
2989
|
-
}
|
|
2990
|
-
],
|
|
2991
|
-
'keyword': [
|
|
2992
|
-
{
|
|
2993
|
-
pattern: /((?:^|\})\s*)catch\b/,
|
|
2994
|
-
lookbehind: true
|
|
2995
|
-
},
|
|
2996
|
-
{
|
|
2997
|
-
pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
|
|
2998
|
-
lookbehind: true
|
|
2999
|
-
},
|
|
3000
|
-
],
|
|
3001
|
-
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
|
3002
|
-
'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
|
3003
|
-
'number': {
|
|
3004
|
-
pattern: RegExp(
|
|
3005
|
-
/(^|[^\w$])/.source +
|
|
3006
|
-
'(?:' +
|
|
3007
|
-
(
|
|
3008
|
-
// constant
|
|
3009
|
-
/NaN|Infinity/.source +
|
|
3010
|
-
'|' +
|
|
3011
|
-
// binary integer
|
|
3012
|
-
/0[bB][01]+(?:_[01]+)*n?/.source +
|
|
3013
|
-
'|' +
|
|
3014
|
-
// octal integer
|
|
3015
|
-
/0[oO][0-7]+(?:_[0-7]+)*n?/.source +
|
|
3016
|
-
'|' +
|
|
3017
|
-
// hexadecimal integer
|
|
3018
|
-
/0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source +
|
|
3019
|
-
'|' +
|
|
3020
|
-
// decimal bigint
|
|
3021
|
-
/\d+(?:_\d+)*n/.source +
|
|
3022
|
-
'|' +
|
|
3023
|
-
// decimal number (integer or float) but no bigint
|
|
3024
|
-
/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source
|
|
3025
|
-
) +
|
|
3026
|
-
')' +
|
|
3027
|
-
/(?![\w$])/.source
|
|
3028
|
-
),
|
|
3029
|
-
lookbehind: true
|
|
3030
|
-
},
|
|
3031
|
-
'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
|
3032
|
-
});
|
|
3033
|
-
|
|
3034
|
-
Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
|
|
3035
|
-
|
|
3036
|
-
Prism.languages.insertBefore('javascript', 'keyword', {
|
|
3037
|
-
'regex': {
|
|
3038
|
-
pattern: RegExp(
|
|
3039
|
-
// lookbehind
|
|
3040
|
-
// eslint-disable-next-line regexp/no-dupe-characters-character-class
|
|
3041
|
-
/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source +
|
|
3042
|
-
// Regex pattern:
|
|
3043
|
-
// There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
|
|
3044
|
-
// classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
|
|
3045
|
-
// with the only syntax, so we have to define 2 different regex patterns.
|
|
3046
|
-
/\//.source +
|
|
3047
|
-
'(?:' +
|
|
3048
|
-
/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source +
|
|
3049
|
-
'|' +
|
|
3050
|
-
// `v` flag syntax. This supports 3 levels of nested character classes.
|
|
3051
|
-
/(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source +
|
|
3052
|
-
')' +
|
|
3053
|
-
// lookahead
|
|
3054
|
-
/(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
|
|
3055
|
-
),
|
|
3056
|
-
lookbehind: true,
|
|
3057
|
-
greedy: true,
|
|
3058
|
-
inside: {
|
|
3059
|
-
'regex-source': {
|
|
3060
|
-
pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
|
|
3061
|
-
lookbehind: true,
|
|
3062
|
-
alias: 'language-regex',
|
|
3063
|
-
inside: Prism.languages.regex
|
|
3064
|
-
},
|
|
3065
|
-
'regex-delimiter': /^\/|\/$/,
|
|
3066
|
-
'regex-flags': /^[a-z]+$/,
|
|
3067
|
-
}
|
|
3068
|
-
},
|
|
3069
|
-
// This must be declared before keyword because we use "function" inside the look-forward
|
|
3070
|
-
'function-variable': {
|
|
3071
|
-
pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
|
|
3072
|
-
alias: 'function'
|
|
3073
|
-
},
|
|
3074
|
-
'parameter': [
|
|
3075
|
-
{
|
|
3076
|
-
pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
|
|
3077
|
-
lookbehind: true,
|
|
3078
|
-
inside: Prism.languages.javascript
|
|
3079
|
-
},
|
|
3080
|
-
{
|
|
3081
|
-
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
|
|
3082
|
-
lookbehind: true,
|
|
3083
|
-
inside: Prism.languages.javascript
|
|
3084
|
-
},
|
|
3085
|
-
{
|
|
3086
|
-
pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
|
|
3087
|
-
lookbehind: true,
|
|
3088
|
-
inside: Prism.languages.javascript
|
|
3089
|
-
},
|
|
3090
|
-
{
|
|
3091
|
-
pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
|
|
3092
|
-
lookbehind: true,
|
|
3093
|
-
inside: Prism.languages.javascript
|
|
3094
|
-
}
|
|
3095
|
-
],
|
|
3096
|
-
'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
|
3097
|
-
});
|
|
3098
|
-
|
|
3099
|
-
Prism.languages.insertBefore('javascript', 'string', {
|
|
3100
|
-
'hashbang': {
|
|
3101
|
-
pattern: /^#!.*/,
|
|
3102
|
-
greedy: true,
|
|
3103
|
-
alias: 'comment'
|
|
3104
|
-
},
|
|
3105
|
-
'template-string': {
|
|
3106
|
-
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
|
3107
|
-
greedy: true,
|
|
3108
|
-
inside: {
|
|
3109
|
-
'template-punctuation': {
|
|
3110
|
-
pattern: /^`|`$/,
|
|
3111
|
-
alias: 'string'
|
|
3112
|
-
},
|
|
3113
|
-
'interpolation': {
|
|
3114
|
-
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
|
3115
|
-
lookbehind: true,
|
|
3116
|
-
inside: {
|
|
3117
|
-
'interpolation-punctuation': {
|
|
3118
|
-
pattern: /^\$\{|\}$/,
|
|
3119
|
-
alias: 'punctuation'
|
|
3120
|
-
},
|
|
3121
|
-
rest: Prism.languages.javascript
|
|
3122
|
-
}
|
|
3123
|
-
},
|
|
3124
|
-
'string': /[\s\S]+/
|
|
3125
|
-
}
|
|
3126
|
-
},
|
|
3127
|
-
'string-property': {
|
|
3128
|
-
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
|
|
3129
|
-
lookbehind: true,
|
|
3130
|
-
greedy: true,
|
|
3131
|
-
alias: 'property'
|
|
3132
|
-
}
|
|
3133
|
-
});
|
|
3134
|
-
|
|
3135
|
-
Prism.languages.insertBefore('javascript', 'operator', {
|
|
3136
|
-
'literal-property': {
|
|
3137
|
-
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
|
|
3138
|
-
lookbehind: true,
|
|
3139
|
-
alias: 'property'
|
|
3140
|
-
},
|
|
3141
|
-
});
|
|
3142
|
-
|
|
3143
|
-
if (Prism.languages.markup) {
|
|
3144
|
-
Prism.languages.markup.tag.addInlined('script', 'javascript');
|
|
3145
|
-
|
|
3146
|
-
// add attribute support for all DOM events.
|
|
3147
|
-
// https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
|
|
3148
|
-
Prism.languages.markup.tag.addAttribute(
|
|
3149
|
-
/on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
|
|
3150
|
-
'javascript'
|
|
3151
|
-
);
|
|
3152
|
-
}
|
|
3153
|
-
|
|
3154
|
-
Prism.languages.js = Prism.languages.javascript;
|
|
3155
|
-
|
|
3156
|
-
Prism.languages.markup = {
|
|
3157
|
-
'comment': {
|
|
3158
|
-
pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
|
|
3159
|
-
greedy: true
|
|
3160
|
-
},
|
|
3161
|
-
'prolog': {
|
|
3162
|
-
pattern: /<\?[\s\S]+?\?>/,
|
|
3163
|
-
greedy: true
|
|
3164
|
-
},
|
|
3165
|
-
'doctype': {
|
|
3166
|
-
// https://www.w3.org/TR/xml/#NT-doctypedecl
|
|
3167
|
-
pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
|
|
3168
|
-
greedy: true,
|
|
3169
|
-
inside: {
|
|
3170
|
-
'internal-subset': {
|
|
3171
|
-
pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
|
|
3172
|
-
lookbehind: true,
|
|
3173
|
-
greedy: true,
|
|
3174
|
-
inside: null // see below
|
|
3175
|
-
},
|
|
3176
|
-
'string': {
|
|
3177
|
-
pattern: /"[^"]*"|'[^']*'/,
|
|
3178
|
-
greedy: true
|
|
3179
|
-
},
|
|
3180
|
-
'punctuation': /^<!|>$|[[\]]/,
|
|
3181
|
-
'doctype-tag': /^DOCTYPE/i,
|
|
3182
|
-
'name': /[^\s<>'"]+/
|
|
3183
|
-
}
|
|
3184
|
-
},
|
|
3185
|
-
'cdata': {
|
|
3186
|
-
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
|
3187
|
-
greedy: true
|
|
3188
|
-
},
|
|
3189
|
-
'tag': {
|
|
3190
|
-
pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
|
|
3191
|
-
greedy: true,
|
|
3192
|
-
inside: {
|
|
3193
|
-
'tag': {
|
|
3194
|
-
pattern: /^<\/?[^\s>\/]+/,
|
|
3195
|
-
inside: {
|
|
3196
|
-
'punctuation': /^<\/?/,
|
|
3197
|
-
'namespace': /^[^\s>\/:]+:/
|
|
3198
|
-
}
|
|
3199
|
-
},
|
|
3200
|
-
'special-attr': [],
|
|
3201
|
-
'attr-value': {
|
|
3202
|
-
pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
|
|
3203
|
-
inside: {
|
|
3204
|
-
'punctuation': [
|
|
3205
|
-
{
|
|
3206
|
-
pattern: /^=/,
|
|
3207
|
-
alias: 'attr-equals'
|
|
3208
|
-
},
|
|
3209
|
-
{
|
|
3210
|
-
pattern: /^(\s*)["']|["']$/,
|
|
3211
|
-
lookbehind: true
|
|
3212
|
-
}
|
|
3213
|
-
]
|
|
3214
|
-
}
|
|
3215
|
-
},
|
|
3216
|
-
'punctuation': /\/?>/,
|
|
3217
|
-
'attr-name': {
|
|
3218
|
-
pattern: /[^\s>\/]+/,
|
|
3219
|
-
inside: {
|
|
3220
|
-
'namespace': /^[^\s>\/:]+:/
|
|
3221
|
-
}
|
|
3222
|
-
}
|
|
3223
|
-
|
|
3224
|
-
}
|
|
3225
|
-
},
|
|
3226
|
-
'entity': [
|
|
3227
|
-
{
|
|
3228
|
-
pattern: /&[\da-z]{1,8};/i,
|
|
3229
|
-
alias: 'named-entity'
|
|
3230
|
-
},
|
|
3231
|
-
/&#x?[\da-f]{1,8};/i
|
|
3232
|
-
]
|
|
3233
|
-
};
|
|
3234
|
-
|
|
3235
|
-
Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
|
|
3236
|
-
Prism.languages.markup['entity'];
|
|
3237
|
-
Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
|
|
3238
|
-
|
|
3239
|
-
// Plugin to make entity title show the real entity, idea by Roman Komarov
|
|
3240
|
-
Prism.hooks.add('wrap', function (env) {
|
|
3241
|
-
|
|
3242
|
-
if (env.type === 'entity') {
|
|
3243
|
-
env.attributes['title'] = env.content.replace(/&/, '&');
|
|
3244
|
-
}
|
|
3245
|
-
});
|
|
3246
|
-
|
|
3247
|
-
Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
|
|
3248
|
-
/**
|
|
3249
|
-
* Adds an inlined language to markup.
|
|
3250
|
-
*
|
|
3251
|
-
* An example of an inlined language is CSS with `<style>` tags.
|
|
3252
|
-
*
|
|
3253
|
-
* @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
|
|
3254
|
-
* case insensitive.
|
|
3255
|
-
* @param {string} lang The language key.
|
|
3256
|
-
* @example
|
|
3257
|
-
* addInlined('style', 'css');
|
|
3258
|
-
*/
|
|
3259
|
-
value: function addInlined(tagName, lang) {
|
|
3260
|
-
var includedCdataInside = {};
|
|
3261
|
-
includedCdataInside['language-' + lang] = {
|
|
3262
|
-
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
|
|
3263
|
-
lookbehind: true,
|
|
3264
|
-
inside: Prism.languages[lang]
|
|
3265
|
-
};
|
|
3266
|
-
includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
|
|
3267
|
-
|
|
3268
|
-
var inside = {
|
|
3269
|
-
'included-cdata': {
|
|
3270
|
-
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
|
3271
|
-
inside: includedCdataInside
|
|
3272
|
-
}
|
|
3273
|
-
};
|
|
3274
|
-
inside['language-' + lang] = {
|
|
3275
|
-
pattern: /[\s\S]+/,
|
|
3276
|
-
inside: Prism.languages[lang]
|
|
3277
|
-
};
|
|
3278
|
-
|
|
3279
|
-
var def = {};
|
|
3280
|
-
def[tagName] = {
|
|
3281
|
-
pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
|
|
3282
|
-
lookbehind: true,
|
|
3283
|
-
greedy: true,
|
|
3284
|
-
inside: inside
|
|
3285
|
-
};
|
|
3286
|
-
|
|
3287
|
-
Prism.languages.insertBefore('markup', 'cdata', def);
|
|
3288
|
-
}
|
|
3289
|
-
});
|
|
3290
|
-
Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
|
|
3291
|
-
/**
|
|
3292
|
-
* Adds an pattern to highlight languages embedded in HTML attributes.
|
|
3293
|
-
*
|
|
3294
|
-
* An example of an inlined language is CSS with `style` attributes.
|
|
3295
|
-
*
|
|
3296
|
-
* @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
|
|
3297
|
-
* case insensitive.
|
|
3298
|
-
* @param {string} lang The language key.
|
|
3299
|
-
* @example
|
|
3300
|
-
* addAttribute('style', 'css');
|
|
3301
|
-
*/
|
|
3302
|
-
value: function (attrName, lang) {
|
|
3303
|
-
Prism.languages.markup.tag.inside['special-attr'].push({
|
|
3304
|
-
pattern: RegExp(
|
|
3305
|
-
/(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
|
|
3306
|
-
'i'
|
|
3307
|
-
),
|
|
3308
|
-
lookbehind: true,
|
|
3309
|
-
inside: {
|
|
3310
|
-
'attr-name': /^[^\s=]+/,
|
|
3311
|
-
'attr-value': {
|
|
3312
|
-
pattern: /=[\s\S]+/,
|
|
3313
|
-
inside: {
|
|
3314
|
-
'value': {
|
|
3315
|
-
pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
|
|
3316
|
-
lookbehind: true,
|
|
3317
|
-
alias: [lang, 'language-' + lang],
|
|
3318
|
-
inside: Prism.languages[lang]
|
|
3319
|
-
},
|
|
3320
|
-
'punctuation': [
|
|
3321
|
-
{
|
|
3322
|
-
pattern: /^=/,
|
|
3323
|
-
alias: 'attr-equals'
|
|
3324
|
-
},
|
|
3325
|
-
/"|'/
|
|
3326
|
-
]
|
|
3327
|
-
}
|
|
3328
|
-
}
|
|
3329
|
-
}
|
|
3330
|
-
});
|
|
3331
|
-
}
|
|
3332
|
-
});
|
|
3333
|
-
|
|
3334
|
-
Prism.languages.html = Prism.languages.markup;
|
|
3335
|
-
Prism.languages.mathml = Prism.languages.markup;
|
|
3336
|
-
Prism.languages.svg = Prism.languages.markup;
|
|
3337
|
-
|
|
3338
|
-
Prism.languages.xml = Prism.languages.extend('markup', {});
|
|
3339
|
-
Prism.languages.ssml = Prism.languages.xml;
|
|
3340
|
-
Prism.languages.atom = Prism.languages.xml;
|
|
3341
|
-
Prism.languages.rss = Prism.languages.xml;
|
|
3342
|
-
|
|
3343
|
-
Prism.languages.c = Prism.languages.extend('clike', {
|
|
3344
|
-
'comment': {
|
|
3345
|
-
pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
|
|
3346
|
-
greedy: true
|
|
3347
|
-
},
|
|
3348
|
-
'string': {
|
|
3349
|
-
// https://en.cppreference.com/w/c/language/string_literal
|
|
3350
|
-
pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
|
|
3351
|
-
greedy: true
|
|
3352
|
-
},
|
|
3353
|
-
'class-name': {
|
|
3354
|
-
pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
|
|
3355
|
-
lookbehind: true
|
|
3356
|
-
},
|
|
3357
|
-
'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,
|
|
3358
|
-
'function': /\b[a-z_]\w*(?=\s*\()/i,
|
|
3359
|
-
'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
|
|
3360
|
-
'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
|
|
3361
|
-
});
|
|
3362
|
-
|
|
3363
|
-
Prism.languages.insertBefore('c', 'string', {
|
|
3364
|
-
'char': {
|
|
3365
|
-
// https://en.cppreference.com/w/c/language/character_constant
|
|
3366
|
-
pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,
|
|
3367
|
-
greedy: true
|
|
3368
|
-
}
|
|
3369
|
-
});
|
|
3370
|
-
|
|
3371
|
-
Prism.languages.insertBefore('c', 'string', {
|
|
3372
|
-
'macro': {
|
|
3373
|
-
// allow for multiline macro definitions
|
|
3374
|
-
// spaces after the # character compile fine with gcc
|
|
3375
|
-
pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
|
|
3376
|
-
lookbehind: true,
|
|
3377
|
-
greedy: true,
|
|
3378
|
-
alias: 'property',
|
|
3379
|
-
inside: {
|
|
3380
|
-
'string': [
|
|
3381
|
-
{
|
|
3382
|
-
// highlight the path of the include statement as a string
|
|
3383
|
-
pattern: /^(#\s*include\s*)<[^>]+>/,
|
|
3384
|
-
lookbehind: true
|
|
3385
|
-
},
|
|
3386
|
-
Prism.languages.c['string']
|
|
3387
|
-
],
|
|
3388
|
-
'char': Prism.languages.c['char'],
|
|
3389
|
-
'comment': Prism.languages.c['comment'],
|
|
3390
|
-
'macro-name': [
|
|
3391
|
-
{
|
|
3392
|
-
pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
|
|
3393
|
-
lookbehind: true
|
|
3394
|
-
},
|
|
3395
|
-
{
|
|
3396
|
-
pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
|
|
3397
|
-
lookbehind: true,
|
|
3398
|
-
alias: 'function'
|
|
3399
|
-
}
|
|
3400
|
-
],
|
|
3401
|
-
// highlight macro directives as keywords
|
|
3402
|
-
'directive': {
|
|
3403
|
-
pattern: /^(#\s*)[a-z]+/,
|
|
3404
|
-
lookbehind: true,
|
|
3405
|
-
alias: 'keyword'
|
|
3406
|
-
},
|
|
3407
|
-
'directive-hash': /^#/,
|
|
3408
|
-
'punctuation': /##|\\(?=[\r\n])/,
|
|
3409
|
-
'expression': {
|
|
3410
|
-
pattern: /\S[\s\S]*/,
|
|
3411
|
-
inside: Prism.languages.c
|
|
3412
|
-
}
|
|
3413
|
-
}
|
|
3414
|
-
}
|
|
3415
|
-
});
|
|
3416
|
-
|
|
3417
|
-
Prism.languages.insertBefore('c', 'function', {
|
|
3418
|
-
// highlight predefined macros as constants
|
|
3419
|
-
'constant': /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
|
|
3420
|
-
});
|
|
3421
|
-
|
|
3422
|
-
delete Prism.languages.c['boolean'];
|
|
3423
|
-
|
|
3424
|
-
(function (Prism) {
|
|
3425
|
-
|
|
3426
|
-
var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
|
|
3427
|
-
|
|
3428
|
-
Prism.languages.css = {
|
|
3429
|
-
'comment': /\/\*[\s\S]*?\*\//,
|
|
3430
|
-
'atrule': {
|
|
3431
|
-
pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
|
|
3432
|
-
inside: {
|
|
3433
|
-
'rule': /^@[\w-]+/,
|
|
3434
|
-
'selector-function-argument': {
|
|
3435
|
-
pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
|
|
3436
|
-
lookbehind: true,
|
|
3437
|
-
alias: 'selector'
|
|
3438
|
-
},
|
|
3439
|
-
'keyword': {
|
|
3440
|
-
pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
|
|
3441
|
-
lookbehind: true
|
|
3442
|
-
}
|
|
3443
|
-
// See rest below
|
|
3444
|
-
}
|
|
3445
|
-
},
|
|
3446
|
-
'url': {
|
|
3447
|
-
// https://drafts.csswg.org/css-values-3/#urls
|
|
3448
|
-
pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
|
|
3449
|
-
greedy: true,
|
|
3450
|
-
inside: {
|
|
3451
|
-
'function': /^url/i,
|
|
3452
|
-
'punctuation': /^\(|\)$/,
|
|
3453
|
-
'string': {
|
|
3454
|
-
pattern: RegExp('^' + string.source + '$'),
|
|
3455
|
-
alias: 'url'
|
|
3456
|
-
}
|
|
3457
|
-
}
|
|
3458
|
-
},
|
|
3459
|
-
'selector': {
|
|
3460
|
-
pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
|
|
3461
|
-
lookbehind: true
|
|
3462
|
-
},
|
|
3463
|
-
'string': {
|
|
3464
|
-
pattern: string,
|
|
3465
|
-
greedy: true
|
|
3466
|
-
},
|
|
3467
|
-
'property': {
|
|
3468
|
-
pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
|
|
3469
|
-
lookbehind: true
|
|
3470
|
-
},
|
|
3471
|
-
'important': /!important\b/i,
|
|
3472
|
-
'function': {
|
|
3473
|
-
pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
|
|
3474
|
-
lookbehind: true
|
|
3475
|
-
},
|
|
3476
|
-
'punctuation': /[(){};:,]/
|
|
3477
|
-
};
|
|
3478
|
-
|
|
3479
|
-
Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
|
|
3480
|
-
|
|
3481
|
-
var markup = Prism.languages.markup;
|
|
3482
|
-
if (markup) {
|
|
3483
|
-
markup.tag.addInlined('style', 'css');
|
|
3484
|
-
markup.tag.addAttribute('style', 'css');
|
|
3485
|
-
}
|
|
3486
|
-
|
|
3487
|
-
}(Prism));
|
|
3488
|
-
|
|
3489
|
-
(function (Prism) {
|
|
3490
|
-
|
|
3491
|
-
Prism.languages.typescript = Prism.languages.extend('javascript', {
|
|
3492
|
-
'class-name': {
|
|
3493
|
-
pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
|
|
3494
|
-
lookbehind: true,
|
|
3495
|
-
greedy: true,
|
|
3496
|
-
inside: null // see below
|
|
3497
|
-
},
|
|
3498
|
-
'builtin': /\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/,
|
|
3499
|
-
});
|
|
3500
|
-
|
|
3501
|
-
// The keywords TypeScript adds to JavaScript
|
|
3502
|
-
Prism.languages.typescript.keyword.push(
|
|
3503
|
-
/\b(?:abstract|declare|is|keyof|readonly|require)\b/,
|
|
3504
|
-
// keywords that have to be followed by an identifier
|
|
3505
|
-
/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,
|
|
3506
|
-
// This is for `import type *, {}`
|
|
3507
|
-
/\btype\b(?=\s*(?:[\{*]|$))/
|
|
3508
|
-
);
|
|
3509
|
-
|
|
3510
|
-
// doesn't work with TS because TS is too complex
|
|
3511
|
-
delete Prism.languages.typescript['parameter'];
|
|
3512
|
-
delete Prism.languages.typescript['literal-property'];
|
|
3513
|
-
|
|
3514
|
-
// a version of typescript specifically for highlighting types
|
|
3515
|
-
var typeInside = Prism.languages.extend('typescript', {});
|
|
3516
|
-
delete typeInside['class-name'];
|
|
3517
|
-
|
|
3518
|
-
Prism.languages.typescript['class-name'].inside = typeInside;
|
|
3519
|
-
|
|
3520
|
-
Prism.languages.insertBefore('typescript', 'function', {
|
|
3521
|
-
'decorator': {
|
|
3522
|
-
pattern: /@[$\w\xA0-\uFFFF]+/,
|
|
3523
|
-
inside: {
|
|
3524
|
-
'at': {
|
|
3525
|
-
pattern: /^@/,
|
|
3526
|
-
alias: 'operator'
|
|
3527
|
-
},
|
|
3528
|
-
'function': /^[\s\S]+/
|
|
3529
|
-
}
|
|
3530
|
-
},
|
|
3531
|
-
'generic-function': {
|
|
3532
|
-
// e.g. foo<T extends "bar" | "baz">( ...
|
|
3533
|
-
pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
|
|
3534
|
-
greedy: true,
|
|
3535
|
-
inside: {
|
|
3536
|
-
'function': /^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,
|
|
3537
|
-
'generic': {
|
|
3538
|
-
pattern: /<[\s\S]+/, // everything after the first <
|
|
3539
|
-
alias: 'class-name',
|
|
3540
|
-
inside: typeInside
|
|
3541
|
-
}
|
|
3542
|
-
}
|
|
3543
|
-
}
|
|
3544
|
-
});
|
|
3545
|
-
|
|
3546
|
-
Prism.languages.ts = Prism.languages.typescript;
|
|
3547
|
-
|
|
3548
|
-
}(Prism));
|
|
3549
|
-
|
|
3550
|
-
(function (Prism) {
|
|
3551
|
-
|
|
3552
|
-
var javascript = Prism.util.clone(Prism.languages.javascript);
|
|
3553
|
-
|
|
3554
|
-
var space = /(?:\s|\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))\*\/)/.source;
|
|
3555
|
-
var braces = /(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])*\})/.source;
|
|
3556
|
-
var spread = /(?:\{<S>*\.{3}(?:[^{}]|<BRACES>)*\})/.source;
|
|
3557
|
-
|
|
3558
|
-
/**
|
|
3559
|
-
* @param {string} source
|
|
3560
|
-
* @param {string} [flags]
|
|
3561
|
-
*/
|
|
3562
|
-
function re(source, flags) {
|
|
3563
|
-
source = source
|
|
3564
|
-
.replace(/<S>/g, function () { return space; })
|
|
3565
|
-
.replace(/<BRACES>/g, function () { return braces; })
|
|
3566
|
-
.replace(/<SPREAD>/g, function () { return spread; });
|
|
3567
|
-
return RegExp(source, flags);
|
|
3568
|
-
}
|
|
3569
|
-
|
|
3570
|
-
spread = re(spread).source;
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
Prism.languages.jsx = Prism.languages.extend('markup', javascript);
|
|
3574
|
-
Prism.languages.jsx.tag.pattern = re(
|
|
3575
|
-
/<\/?(?:[\w.:-]+(?:<S>+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\/?)?>/.source
|
|
3576
|
-
);
|
|
3577
|
-
|
|
3578
|
-
Prism.languages.jsx.tag.inside['tag'].pattern = /^<\/?[^\s>\/]*/;
|
|
3579
|
-
Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/;
|
|
3580
|
-
Prism.languages.jsx.tag.inside['tag'].inside['class-name'] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/;
|
|
3581
|
-
Prism.languages.jsx.tag.inside['comment'] = javascript['comment'];
|
|
3582
|
-
|
|
3583
|
-
Prism.languages.insertBefore('inside', 'attr-name', {
|
|
3584
|
-
'spread': {
|
|
3585
|
-
pattern: re(/<SPREAD>/.source),
|
|
3586
|
-
inside: Prism.languages.jsx
|
|
3587
|
-
}
|
|
3588
|
-
}, Prism.languages.jsx.tag);
|
|
3589
|
-
|
|
3590
|
-
Prism.languages.insertBefore('inside', 'special-attr', {
|
|
3591
|
-
'script': {
|
|
3592
|
-
// Allow for two levels of nesting
|
|
3593
|
-
pattern: re(/=<BRACES>/.source),
|
|
3594
|
-
alias: 'language-javascript',
|
|
3595
|
-
inside: {
|
|
3596
|
-
'script-punctuation': {
|
|
3597
|
-
pattern: /^=(?=\{)/,
|
|
3598
|
-
alias: 'punctuation'
|
|
3599
|
-
},
|
|
3600
|
-
rest: Prism.languages.jsx
|
|
3601
|
-
},
|
|
3602
|
-
}
|
|
3603
|
-
}, Prism.languages.jsx.tag);
|
|
3604
|
-
|
|
3605
|
-
// The following will handle plain text inside tags
|
|
3606
|
-
var stringifyToken = function (token) {
|
|
3607
|
-
if (!token) {
|
|
3608
|
-
return '';
|
|
3609
|
-
}
|
|
3610
|
-
if (typeof token === 'string') {
|
|
3611
|
-
return token;
|
|
3612
|
-
}
|
|
3613
|
-
if (typeof token.content === 'string') {
|
|
3614
|
-
return token.content;
|
|
3615
|
-
}
|
|
3616
|
-
return token.content.map(stringifyToken).join('');
|
|
3617
|
-
};
|
|
3618
|
-
|
|
3619
|
-
var walkTokens = function (tokens) {
|
|
3620
|
-
var openedTags = [];
|
|
3621
|
-
for (var i = 0; i < tokens.length; i++) {
|
|
3622
|
-
var token = tokens[i];
|
|
3623
|
-
var notTagNorBrace = false;
|
|
3624
|
-
|
|
3625
|
-
if (typeof token !== 'string') {
|
|
3626
|
-
if (token.type === 'tag' && token.content[0] && token.content[0].type === 'tag') {
|
|
3627
|
-
// We found a tag, now find its kind
|
|
3628
|
-
|
|
3629
|
-
if (token.content[0].content[0].content === '</') {
|
|
3630
|
-
// Closing tag
|
|
3631
|
-
if (openedTags.length > 0 && openedTags[openedTags.length - 1].tagName === stringifyToken(token.content[0].content[1])) {
|
|
3632
|
-
// Pop matching opening tag
|
|
3633
|
-
openedTags.pop();
|
|
3634
|
-
}
|
|
3635
|
-
} else {
|
|
3636
|
-
if (token.content[token.content.length - 1].content === '/>') {
|
|
3637
|
-
// Autoclosed tag, ignore
|
|
3638
|
-
} else {
|
|
3639
|
-
// Opening tag
|
|
3640
|
-
openedTags.push({
|
|
3641
|
-
tagName: stringifyToken(token.content[0].content[1]),
|
|
3642
|
-
openedBraces: 0
|
|
3643
|
-
});
|
|
3644
|
-
}
|
|
3645
|
-
}
|
|
3646
|
-
} else if (openedTags.length > 0 && token.type === 'punctuation' && token.content === '{') {
|
|
3647
|
-
|
|
3648
|
-
// Here we might have entered a JSX context inside a tag
|
|
3649
|
-
openedTags[openedTags.length - 1].openedBraces++;
|
|
3650
|
-
|
|
3651
|
-
} else if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces > 0 && token.type === 'punctuation' && token.content === '}') {
|
|
3652
|
-
|
|
3653
|
-
// Here we might have left a JSX context inside a tag
|
|
3654
|
-
openedTags[openedTags.length - 1].openedBraces--;
|
|
3655
|
-
|
|
3656
|
-
} else {
|
|
3657
|
-
notTagNorBrace = true;
|
|
3658
|
-
}
|
|
3659
|
-
}
|
|
3660
|
-
if (notTagNorBrace || typeof token === 'string') {
|
|
3661
|
-
if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces === 0) {
|
|
3662
|
-
// Here we are inside a tag, and not inside a JSX context.
|
|
3663
|
-
// That's plain text: drop any tokens matched.
|
|
3664
|
-
var plainText = stringifyToken(token);
|
|
3665
|
-
|
|
3666
|
-
// And merge text with adjacent text
|
|
3667
|
-
if (i < tokens.length - 1 && (typeof tokens[i + 1] === 'string' || tokens[i + 1].type === 'plain-text')) {
|
|
3668
|
-
plainText += stringifyToken(tokens[i + 1]);
|
|
3669
|
-
tokens.splice(i + 1, 1);
|
|
3670
|
-
}
|
|
3671
|
-
if (i > 0 && (typeof tokens[i - 1] === 'string' || tokens[i - 1].type === 'plain-text')) {
|
|
3672
|
-
plainText = stringifyToken(tokens[i - 1]) + plainText;
|
|
3673
|
-
tokens.splice(i - 1, 1);
|
|
3674
|
-
i--;
|
|
3675
|
-
}
|
|
3676
|
-
|
|
3677
|
-
tokens[i] = new Prism.Token('plain-text', plainText, null, plainText);
|
|
3678
|
-
}
|
|
3679
|
-
}
|
|
3680
|
-
|
|
3681
|
-
if (token.content && typeof token.content !== 'string') {
|
|
3682
|
-
walkTokens(token.content);
|
|
3683
|
-
}
|
|
3684
|
-
}
|
|
3685
|
-
};
|
|
3686
|
-
|
|
3687
|
-
Prism.hooks.add('after-tokenize', function (env) {
|
|
3688
|
-
if (env.language !== 'jsx' && env.language !== 'tsx') {
|
|
3689
|
-
return;
|
|
3690
|
-
}
|
|
3691
|
-
walkTokens(env.tokens);
|
|
3692
|
-
});
|
|
3693
|
-
|
|
3694
|
-
}(Prism));
|
|
3695
|
-
|
|
3696
|
-
(function (Prism) {
|
|
3697
|
-
var typescript = Prism.util.clone(Prism.languages.typescript);
|
|
3698
|
-
Prism.languages.tsx = Prism.languages.extend('jsx', typescript);
|
|
3699
|
-
|
|
3700
|
-
// doesn't work with TS because TS is too complex
|
|
3701
|
-
delete Prism.languages.tsx['parameter'];
|
|
3702
|
-
delete Prism.languages.tsx['literal-property'];
|
|
3703
|
-
|
|
3704
|
-
// This will prevent collisions between TSX tags and TS generic types.
|
|
3705
|
-
// Idea by https://github.com/karlhorky
|
|
3706
|
-
// Discussion: https://github.com/PrismJS/prism/issues/2594#issuecomment-710666928
|
|
3707
|
-
var tag = Prism.languages.tsx.tag;
|
|
3708
|
-
tag.pattern = RegExp(/(^|[^\w$]|(?=<\/))/.source + '(?:' + tag.pattern.source + ')', tag.pattern.flags);
|
|
3709
|
-
tag.lookbehind = true;
|
|
3710
|
-
}(Prism));
|
|
3711
|
-
|
|
3712
|
-
var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
3713
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3714
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3715
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3716
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3717
|
-
};
|
|
3718
|
-
const presetLanguages = Object.values(CodeLanguage);
|
|
3719
|
-
/**
|
|
3720
|
-
* Processing the code content into different types of nodes.
|
|
3721
|
-
*/
|
|
3722
|
-
class CodeHighlightParser extends VegaSlimmer {
|
|
3723
|
-
/**
|
|
3724
|
-
* Split the HTML tag to avoid the content render to a html element.
|
|
3725
|
-
*
|
|
3726
|
-
* @example <div> -> ['<', 'div', '>']
|
|
3727
|
-
* @param {string} text - The code content.
|
|
3728
|
-
* @returns {string[]} - The code content array.
|
|
3729
|
-
*/
|
|
3730
|
-
splitTag(text) {
|
|
3731
|
-
if (!this.hasSpecialCharacter(text) || text.length < 2) {
|
|
3732
|
-
return [text];
|
|
3733
|
-
}
|
|
3734
|
-
else {
|
|
3735
|
-
const result = [];
|
|
3736
|
-
const textArray = text.split('');
|
|
3737
|
-
let nextIndex = 0;
|
|
3738
|
-
textArray.forEach((item) => {
|
|
3739
|
-
if (item === '<' || item === '>' || item === '/') {
|
|
3740
|
-
result.push(item);
|
|
3741
|
-
nextIndex = result.length;
|
|
3742
|
-
}
|
|
3743
|
-
else {
|
|
3744
|
-
result[nextIndex] = result[nextIndex] ? result[nextIndex] + item : item;
|
|
3745
|
-
}
|
|
3746
|
-
});
|
|
3747
|
-
return result;
|
|
3748
|
-
}
|
|
3749
|
-
}
|
|
3750
|
-
/**
|
|
3751
|
-
* Check the current language is a preset language and the language is not plain text.
|
|
3752
|
-
*
|
|
3753
|
-
* @param {Nullable<string>} language - The input language.
|
|
3754
|
-
* @returns {boolean} - The boolean result.
|
|
3755
|
-
*/
|
|
3756
|
-
isHighlightLanguage(language) {
|
|
3757
|
-
return language !== 'plainText' && presetLanguages.includes(language);
|
|
3758
|
-
}
|
|
3759
|
-
/**
|
|
3760
|
-
* Mark the line number class for the first node of each line.
|
|
3761
|
-
*
|
|
3762
|
-
* @param {CodeNodeType[]} codeNodes - The code nodes array.
|
|
3763
|
-
* @returns {CodeNodeType[]} - The code node array with line number tag.
|
|
3764
|
-
*/
|
|
3765
|
-
markLineNumberNodes(codeNodes) {
|
|
3766
|
-
if (codeNodes.length === 0) {
|
|
3767
|
-
codeNodes.push({ text: '\n', key: '0', className: '' });
|
|
3768
|
-
}
|
|
3769
|
-
let lineNumber = 0;
|
|
3770
|
-
return codeNodes.map((node, index) => {
|
|
3771
|
-
let className = node.className;
|
|
3772
|
-
if (index === 0 || codeNodes[index - 1].text === '\n') {
|
|
3773
|
-
lineNumber++;
|
|
3774
|
-
className = `v-code-line-number ${node.className}`;
|
|
3775
|
-
}
|
|
3776
|
-
return {
|
|
3777
|
-
text: node.text,
|
|
3778
|
-
key: `${index}`,
|
|
3779
|
-
className,
|
|
3780
|
-
mark: `${lineNumber}`,
|
|
3781
|
-
};
|
|
3782
|
-
});
|
|
3783
|
-
}
|
|
3784
|
-
/**
|
|
3785
|
-
* Check the text has special character.
|
|
3786
|
-
*
|
|
3787
|
-
* @param {string} text - The test text.
|
|
3788
|
-
* @returns {boolean} - Return true is the text has <, > , /.
|
|
3789
|
-
*/
|
|
3790
|
-
hasSpecialCharacter(text) {
|
|
3791
|
-
return /[<|>|\\/]/.test(text);
|
|
3792
|
-
}
|
|
3793
|
-
}
|
|
3794
|
-
__decorate$4([
|
|
3795
|
-
MapToComponentField()
|
|
3796
|
-
], CodeHighlightParser.prototype, "value", void 0);
|
|
3797
|
-
|
|
3798
|
-
/**
|
|
3799
|
-
* Use the plugin Prism to highlight the code content.
|
|
3800
|
-
*/
|
|
3801
|
-
class PrismCodeHighlightParseController extends CodeHighlightParser {
|
|
3802
|
-
/**
|
|
3803
|
-
* Return true when the content and language are defined.
|
|
3804
|
-
*
|
|
3805
|
-
* @returns {boolean} - Boolean value.
|
|
3806
|
-
*/
|
|
3807
|
-
canParse() {
|
|
3808
|
-
const { code, language } = this.value || { code: '' };
|
|
3809
|
-
return code && language && this.isHighlightLanguage(language);
|
|
3810
|
-
}
|
|
3811
|
-
/**
|
|
3812
|
-
* Use plugin to parse the string code into an array of nodes with different keywords.
|
|
3813
|
-
*
|
|
3814
|
-
* @returns {CodeNodeType[]} - The object contains content and highlight type.
|
|
3815
|
-
*/
|
|
3816
|
-
parse() {
|
|
3817
|
-
const { code, language } = this.value;
|
|
3818
|
-
let result = [];
|
|
3819
|
-
const parseLanguage = prism.languages[language];
|
|
3820
|
-
const tokens = prism.tokenize(code, parseLanguage);
|
|
3821
|
-
result = this.getHighlightNodes(tokens);
|
|
3822
|
-
return this.markLineNumberNodes(result);
|
|
3823
|
-
}
|
|
3824
|
-
/**
|
|
3825
|
-
* Parse the plugin parse result to a usable array.
|
|
3826
|
-
*
|
|
3827
|
-
* @param {(string | CodeHighlightToken)[]} tokens - The plugin parse result.
|
|
3828
|
-
* @param {string} [type] - The keywords. Such as variable, function-name, attr-name...
|
|
3829
|
-
* @returns {CodeNodeType[]} - The code node array.
|
|
3830
|
-
*/
|
|
3831
|
-
getHighlightNodes(tokens, type) {
|
|
3832
|
-
const nodes = [];
|
|
3833
|
-
for (const token of tokens) {
|
|
3834
|
-
if (typeof token === 'string') {
|
|
3835
|
-
const partials = token.split(/(\n|\t)/);
|
|
3836
|
-
const partialsLength = partials.length;
|
|
3837
|
-
for (let i = 0; i < partialsLength; i++) {
|
|
3838
|
-
const part = partials[i];
|
|
3839
|
-
if (part) {
|
|
3840
|
-
const textArray = this.splitTag(part);
|
|
3841
|
-
nodes.push(...textArray.map((text) => this.createCodeNode(text, type)));
|
|
3842
|
-
}
|
|
3843
|
-
}
|
|
3844
|
-
}
|
|
3845
|
-
else {
|
|
3846
|
-
const { content } = token;
|
|
3847
|
-
if (typeof content === 'string') {
|
|
3848
|
-
nodes.push(...this.getHighlightNodes([content], token.type));
|
|
3849
|
-
}
|
|
3850
|
-
else if (Array.isArray(content)) {
|
|
3851
|
-
nodes.push(...this.getHighlightNodes(content, token.type));
|
|
3852
|
-
}
|
|
3853
|
-
}
|
|
3854
|
-
}
|
|
3855
|
-
return nodes;
|
|
3856
|
-
}
|
|
3857
|
-
/**
|
|
3858
|
-
* Create a CodeNodeType type object by the code content and highlight type.
|
|
3859
|
-
*
|
|
3860
|
-
* @param {string} text - The code content.
|
|
3861
|
-
* @param {string} highlightType - The highlight type.
|
|
3862
|
-
* @returns {CodeNodeType} - The code node object.
|
|
3863
|
-
*/
|
|
3864
|
-
createCodeNode(text, highlightType) {
|
|
3865
|
-
return {
|
|
3866
|
-
text,
|
|
3867
|
-
key: '',
|
|
3868
|
-
className: `token ${highlightType || ''}`,
|
|
3869
|
-
mark: '',
|
|
3870
|
-
};
|
|
3871
|
-
}
|
|
3872
|
-
}
|
|
3873
|
-
|
|
3874
|
-
/**
|
|
3875
|
-
* Plain text parse logic.
|
|
3876
|
-
*/
|
|
3877
|
-
class DefaultCodeHighlightParseController extends CodeHighlightParser {
|
|
3878
|
-
/**
|
|
3879
|
-
* Default parser will handle if others not catch.
|
|
3880
|
-
*
|
|
3881
|
-
* @returns {boolean} True value.
|
|
3882
|
-
*/
|
|
3883
|
-
canParse() {
|
|
3884
|
-
const { code, language } = this.value || { code: '' };
|
|
3885
|
-
return !code || !language || language === 'plainText' || !this.isHighlightLanguage(language);
|
|
3886
|
-
}
|
|
3887
|
-
/**
|
|
3888
|
-
* The default parse will split the html tag and create the line number.
|
|
3889
|
-
*
|
|
3890
|
-
* @returns {CodeNodeType[]} - The code node array.
|
|
3891
|
-
*/
|
|
3892
|
-
parse() {
|
|
3893
|
-
var _a, _b;
|
|
3894
|
-
const code = (_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : '';
|
|
3895
|
-
const nodes = code.split(/(\n)/);
|
|
3896
|
-
let result = [];
|
|
3897
|
-
nodes.forEach((item) => {
|
|
3898
|
-
if (item) {
|
|
3899
|
-
const textArray = this.splitTag(item);
|
|
3900
|
-
result.push(...textArray.map((text) => ({ text, key: '', className: '' })));
|
|
3901
|
-
}
|
|
3902
|
-
});
|
|
3903
|
-
result = this.markLineNumberNodes(result);
|
|
3904
|
-
return result;
|
|
3905
|
-
}
|
|
3906
|
-
}
|
|
3907
|
-
|
|
3908
|
-
const codeColorVariableCss = ":root{--code-orange:#cd3e00;--code-green:#007e7e;--code-purple:#6851f5;--code-gray:#67727e;--code-neutral:rgb(15, 36, 51);--code-neutral-8:rgba(15, 36, 51, 0.8);--code-neutral-7:rgba(15, 36, 51, 0.7)}.dark{--code-orange:#ff9571;--code-green:#73e6dc;--code-purple:#c7bdff;--code-gray:#8b959f;--code-neutral:rgb(252, 252, 252);--code-neutral-8:rgba(252, 252, 252, 0.8);--code-neutral-7:rgba(252, 252, 252, 0.7)}";
|
|
3909
|
-
|
|
3910
|
-
var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
3911
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3912
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3913
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3914
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3915
|
-
};
|
|
3916
|
-
/**
|
|
3917
|
-
* The class used to control the code block insert composition text action.
|
|
3918
|
-
*/
|
|
3919
|
-
class InsertCompositionTextController extends VegaSlimmer {
|
|
3920
|
-
constructor() {
|
|
3921
|
-
super(...arguments);
|
|
3922
|
-
this.insertCompositionTextEndFlag = true;
|
|
3923
|
-
/**
|
|
3924
|
-
* An event handler function that is triggered when the composition of text input starts. In this case,
|
|
3925
|
-
* it sets the `insertCompositionTextEndFlag` property of the `UserInputController` class to `false`.
|
|
3926
|
-
*
|
|
3927
|
-
* @param {CompositionEvent} e The composition event instance
|
|
3928
|
-
*/
|
|
3929
|
-
this.handleCompositionStart = (e) => {
|
|
3930
|
-
this.insertCompositionTextEndFlag = false;
|
|
3931
|
-
this.stopEventPropagation(e);
|
|
3932
|
-
};
|
|
3933
|
-
/**
|
|
3934
|
-
* An event handler function that is triggered when the composition of text input ends. In this case,
|
|
3935
|
-
* it sets the `insertCompositionTextEndFlag` property of the `UserInputController` class to `true`.
|
|
3936
|
-
*
|
|
3937
|
-
* @param {CompositionEvent} e The composition event instance
|
|
3938
|
-
*/
|
|
3939
|
-
this.handleCompositionEnd = (e) => {
|
|
3940
|
-
var _a;
|
|
3941
|
-
this.insertCompositionTextEndFlag = true;
|
|
3942
|
-
this.stopEventPropagation(e);
|
|
3943
|
-
const range = this.selectionController.getCurrentRange();
|
|
3944
|
-
if (range) {
|
|
3945
|
-
this.selectionController.setNextCodeBlockRange(range.contentOffset + e.data.length);
|
|
3946
|
-
}
|
|
3947
|
-
const newContent = this.contentRenderer.getCodeContentContainerRef().innerText;
|
|
3948
|
-
this.valueController.updateValue(newContent, (_a = this.value) === null || _a === void 0 ? void 0 : _a.language);
|
|
3949
|
-
};
|
|
3950
|
-
}
|
|
3951
|
-
/**
|
|
3952
|
-
* The method is to get the composition text insert end or not.
|
|
3953
|
-
*
|
|
3954
|
-
* @returns {boolean} The false is mean that insert composition text process is end.
|
|
3955
|
-
*/
|
|
3956
|
-
isComposing() {
|
|
3957
|
-
return !this.insertCompositionTextEndFlag;
|
|
3958
|
-
}
|
|
3959
|
-
/**
|
|
3960
|
-
* Stop `beforeinput` and `input` event bubbles to parent element.
|
|
3961
|
-
*/
|
|
3962
|
-
registerInputEvent() {
|
|
3963
|
-
const codeContentContainerRef = this.contentRenderer.getCodeContentContainerRef();
|
|
3964
|
-
if (codeContentContainerRef) {
|
|
3965
|
-
codeContentContainerRef.addEventListener('compositionstart', this.handleCompositionStart);
|
|
3966
|
-
codeContentContainerRef.addEventListener('compositionend', this.handleCompositionEnd);
|
|
3967
|
-
}
|
|
3968
|
-
}
|
|
3969
|
-
/**
|
|
3970
|
-
* Remove the event listener.
|
|
3971
|
-
*/
|
|
3972
|
-
unregisterEventListener() {
|
|
3973
|
-
const codeContentContainerRef = this.contentRenderer.getCodeContentContainerRef();
|
|
3974
|
-
if (codeContentContainerRef) {
|
|
3975
|
-
codeContentContainerRef.removeEventListener('compositionstart', this.handleCompositionStart);
|
|
3976
|
-
codeContentContainerRef.removeEventListener('compositionend', this.handleCompositionEnd);
|
|
3977
|
-
}
|
|
3978
|
-
}
|
|
3979
|
-
/**
|
|
3980
|
-
* Stop the event bubbles.
|
|
3981
|
-
*
|
|
3982
|
-
* @param {Event} e - The event object.
|
|
3983
|
-
*/
|
|
3984
|
-
stopEventPropagation(e) {
|
|
3985
|
-
e.stopPropagation();
|
|
3986
|
-
}
|
|
3987
|
-
}
|
|
3988
|
-
__decorate$3([
|
|
3989
|
-
MapToComponentField()
|
|
3990
|
-
], InsertCompositionTextController.prototype, "selectionController", void 0);
|
|
3991
|
-
__decorate$3([
|
|
3992
|
-
MapToComponentField()
|
|
3993
|
-
], InsertCompositionTextController.prototype, "contentRenderer", void 0);
|
|
3994
|
-
__decorate$3([
|
|
3995
|
-
MapToComponentField()
|
|
3996
|
-
], InsertCompositionTextController.prototype, "valueController", void 0);
|
|
3997
|
-
__decorate$3([
|
|
3998
|
-
MapToComponentField()
|
|
3999
|
-
], InsertCompositionTextController.prototype, "contentParseController", void 0);
|
|
4000
|
-
__decorate$3([
|
|
4001
|
-
MapToComponentField()
|
|
4002
|
-
], InsertCompositionTextController.prototype, "value", void 0);
|
|
4003
|
-
__decorate$3([
|
|
4004
|
-
MapToComponentMethod('componentDidLoad')
|
|
4005
|
-
], InsertCompositionTextController.prototype, "registerInputEvent", null);
|
|
4006
|
-
__decorate$3([
|
|
4007
|
-
MapToComponentMethod('disconnectedCallback')
|
|
4008
|
-
], InsertCompositionTextController.prototype, "unregisterEventListener", null);
|
|
4009
|
-
|
|
4010
|
-
var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
4011
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4012
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4013
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4014
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4015
|
-
};
|
|
4016
|
-
/**
|
|
4017
|
-
* The class used to control the code block history.
|
|
4018
|
-
* It extends the ComponentValueHistoryControllerSlimmer to manage the history of code block states.
|
|
4019
|
-
*/
|
|
4020
|
-
class VegaCodeBlockHistoryController extends ComponentValueHistoryControllerSlimmer {
|
|
4021
|
-
constructor() {
|
|
4022
|
-
super(...arguments);
|
|
4023
|
-
/**
|
|
4024
|
-
* Get the effective target elements for the code block history.
|
|
4025
|
-
*
|
|
4026
|
-
* @returns {HTMLElement[]} - An array of effective target elements.
|
|
4027
|
-
*/
|
|
4028
|
-
this.getEffectiveTargets = () => {
|
|
4029
|
-
return [this.contentRenderer.getCodeContentContainerRef()];
|
|
4030
|
-
};
|
|
4031
|
-
}
|
|
4032
|
-
/**
|
|
4033
|
-
* Invoke the method to back up the current code block state.
|
|
4034
|
-
*/
|
|
4035
|
-
async undo() {
|
|
4036
|
-
if (this.undoStack.length > 1) {
|
|
4037
|
-
const clonedState = this.undoStack.pop();
|
|
4038
|
-
this.redoStack.push(clonedState);
|
|
4039
|
-
const prev = this.undoStack[this.undoStack.length - 1];
|
|
4040
|
-
if (prev) {
|
|
4041
|
-
await this.restoreState(prev);
|
|
4042
|
-
}
|
|
4043
|
-
}
|
|
4044
|
-
}
|
|
4045
|
-
/**
|
|
4046
|
-
* Invoke the redo action to restore the last undone state.
|
|
4047
|
-
*/
|
|
4048
|
-
async redo() {
|
|
4049
|
-
const clonedState = this.redoStack.pop();
|
|
4050
|
-
this.undoStack.push(clonedState);
|
|
4051
|
-
await this.restoreState(clonedState);
|
|
4052
|
-
}
|
|
4053
|
-
/**
|
|
4054
|
-
* Set the initial state of the code block history when the component is loaded.
|
|
4055
|
-
*/
|
|
4056
|
-
initialHistory() {
|
|
4057
|
-
this.registerHistory({
|
|
4058
|
-
value: this.value,
|
|
4059
|
-
offset: this.value.code.length,
|
|
4060
|
-
}, true);
|
|
4061
|
-
}
|
|
4062
|
-
/**
|
|
4063
|
-
* Get the ineffective target elements for the code block history.
|
|
4064
|
-
*
|
|
4065
|
-
* @returns { HTMLElement[]} - An empty array, as there are no ineffective targets for the code block.
|
|
4066
|
-
*/
|
|
4067
|
-
getIneffectiveTargets() {
|
|
4068
|
-
return [];
|
|
4069
|
-
}
|
|
4070
|
-
/**
|
|
4071
|
-
* Restore the state of the code block from the given state.
|
|
4072
|
-
*
|
|
4073
|
-
* @param {CodeBlockState} state - The state to restore.
|
|
4074
|
-
*/
|
|
4075
|
-
async restoreState(state) {
|
|
4076
|
-
const { value, offset } = state;
|
|
4077
|
-
this.selectionController.setNextCodeBlockRange(offset);
|
|
4078
|
-
this.valueController.updateValue(value.code, value.language);
|
|
4079
|
-
}
|
|
4080
|
-
}
|
|
4081
|
-
__decorate$2([
|
|
4082
|
-
MapToComponentField()
|
|
4083
|
-
], VegaCodeBlockHistoryController.prototype, "contentRenderer", void 0);
|
|
4084
|
-
__decorate$2([
|
|
4085
|
-
MapToComponentField()
|
|
4086
|
-
], VegaCodeBlockHistoryController.prototype, "value", void 0);
|
|
4087
|
-
__decorate$2([
|
|
4088
|
-
MapToComponentField()
|
|
4089
|
-
], VegaCodeBlockHistoryController.prototype, "valueController", void 0);
|
|
4090
|
-
__decorate$2([
|
|
4091
|
-
MapToComponentField()
|
|
4092
|
-
], VegaCodeBlockHistoryController.prototype, "selectionController", void 0);
|
|
4093
|
-
__decorate$2([
|
|
4094
|
-
MapToComponentMethod('componentDidLoad')
|
|
4095
|
-
], VegaCodeBlockHistoryController.prototype, "initialHistory", null);
|
|
4096
|
-
|
|
4097
|
-
var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
4098
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4099
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4100
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4101
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4102
|
-
};
|
|
4103
|
-
/**
|
|
4104
|
-
* Controller for handling paste events in VegaCodeBlock.
|
|
4105
|
-
* Handles insertion, selection, and content update logic for pasted code.
|
|
4106
|
-
*/
|
|
4107
|
-
class CodeBlockPasteController extends CodeInputPaste {
|
|
4108
|
-
constructor() {
|
|
4109
|
-
super(...arguments);
|
|
4110
|
-
/**
|
|
4111
|
-
* Handle the paste event.
|
|
4112
|
-
*
|
|
4113
|
-
* @param {ClipboardEvent} e - The clipboard event object.
|
|
4114
|
-
* @returns {void}
|
|
4115
|
-
*/
|
|
4116
|
-
this.handlePasteEvent = (e) => {
|
|
4117
|
-
var _a, _b;
|
|
4118
|
-
e.preventDefault();
|
|
4119
|
-
this.stopEventPropagation(e);
|
|
4120
|
-
const pasteData = e.clipboardData;
|
|
4121
|
-
if ((_a = pasteData === null || pasteData === void 0 ? void 0 : pasteData.files) === null || _a === void 0 ? void 0 : _a.length) {
|
|
4122
|
-
// Prevent paste if the clipboard contains files.
|
|
4123
|
-
return;
|
|
4124
|
-
}
|
|
4125
|
-
const pastedContent = (_b = pasteData === null || pasteData === void 0 ? void 0 : pasteData.getData('text/plain')) !== null && _b !== void 0 ? _b : '';
|
|
4126
|
-
if (!pastedContent) {
|
|
4127
|
-
return;
|
|
4128
|
-
}
|
|
4129
|
-
this.updateCodeBlockRangeAndContent(pastedContent);
|
|
4130
|
-
};
|
|
4131
|
-
}
|
|
4132
|
-
/**
|
|
4133
|
-
* Register paste event listener on component load.
|
|
4134
|
-
*/
|
|
4135
|
-
registerInputEvent() {
|
|
4136
|
-
const codeContentContainerRef = this.contentRenderer.getCodeContentContainerRef();
|
|
4137
|
-
if (codeContentContainerRef) {
|
|
4138
|
-
codeContentContainerRef.addEventListener('paste', this.handlePasteEvent);
|
|
4139
|
-
}
|
|
4140
|
-
}
|
|
4141
|
-
/**
|
|
4142
|
-
* Remove the event listener.
|
|
4143
|
-
*/
|
|
4144
|
-
unregisterEventListener() {
|
|
4145
|
-
const codeContentContainerRef = this.contentRenderer.getCodeContentContainerRef();
|
|
4146
|
-
if (codeContentContainerRef) {
|
|
4147
|
-
codeContentContainerRef.removeEventListener('paste', this.handlePasteEvent);
|
|
4148
|
-
}
|
|
4149
|
-
}
|
|
4150
|
-
/**
|
|
4151
|
-
* Update the code block range based on pasted data.
|
|
4152
|
-
*
|
|
4153
|
-
* @param {string} pastedContent - The content that has been pasted.
|
|
4154
|
-
* @returns {void}
|
|
4155
|
-
*/
|
|
4156
|
-
updateCodeBlockRangeAndContent(pastedContent) {
|
|
4157
|
-
const { nextOffset: updatedOffset, updatedContent } = this.getLatestRangeAndContent(pastedContent);
|
|
4158
|
-
this.selectionController.setNextCodeBlockRange(updatedOffset);
|
|
4159
|
-
this.valueController.updateValue(updatedContent, this.value.language, {
|
|
4160
|
-
recordHistory: true,
|
|
4161
|
-
offset: this.selectionController.getCurrentRange().contentOffset,
|
|
4162
|
-
});
|
|
4163
|
-
}
|
|
4164
|
-
/**
|
|
4165
|
-
* Get the latest range and content after paste operation.
|
|
4166
|
-
*
|
|
4167
|
-
* @param {string} pastedContent - The content that has been pasted.
|
|
4168
|
-
* @returns {NextOffsetAndContentResult}} The next offset and updated content.
|
|
4169
|
-
*/
|
|
4170
|
-
getLatestRangeAndContent(pastedContent) {
|
|
4171
|
-
const range = this.selectionController.getCurrentRange();
|
|
4172
|
-
const currentNodes = this.contentParseController.getCurrentCodeNodes();
|
|
4173
|
-
const content = this.getCodeNodesContent(currentNodes);
|
|
4174
|
-
return this.reCalculateRangeAndContent(range, content, pastedContent);
|
|
4175
|
-
}
|
|
4176
|
-
}
|
|
4177
|
-
__decorate$1([
|
|
4178
|
-
MapToComponentField()
|
|
4179
|
-
], CodeBlockPasteController.prototype, "host", void 0);
|
|
4180
|
-
__decorate$1([
|
|
4181
|
-
MapToComponentField()
|
|
4182
|
-
], CodeBlockPasteController.prototype, "valueController", void 0);
|
|
4183
|
-
__decorate$1([
|
|
4184
|
-
MapToComponentField()
|
|
4185
|
-
], CodeBlockPasteController.prototype, "contentRenderer", void 0);
|
|
4186
|
-
__decorate$1([
|
|
4187
|
-
MapToComponentField()
|
|
4188
|
-
], CodeBlockPasteController.prototype, "value", void 0);
|
|
4189
|
-
__decorate$1([
|
|
4190
|
-
MapToComponentField()
|
|
4191
|
-
], CodeBlockPasteController.prototype, "selectionController", void 0);
|
|
4192
|
-
__decorate$1([
|
|
4193
|
-
MapToComponentField()
|
|
4194
|
-
], CodeBlockPasteController.prototype, "contentParseController", void 0);
|
|
4195
|
-
__decorate$1([
|
|
4196
|
-
MapToComponentField()
|
|
4197
|
-
], CodeBlockPasteController.prototype, "inputController", void 0);
|
|
4198
|
-
__decorate$1([
|
|
4199
|
-
MapToComponentMethod('componentDidLoad')
|
|
4200
|
-
], CodeBlockPasteController.prototype, "registerInputEvent", null);
|
|
4201
|
-
__decorate$1([
|
|
4202
|
-
MapToComponentMethod('disconnectedCallback')
|
|
4203
|
-
], CodeBlockPasteController.prototype, "unregisterEventListener", null);
|
|
4204
|
-
|
|
4205
|
-
const vegaCodeBlockCss = ":host{display:block;border-radius:2px;background-color:rgba(var(--v-bg-secondary, 245, 247, 247, 1));padding-left:12px;padding-right:12px;padding-top:12px;padding-bottom:12px}:host code{display:block;box-sizing:border-box;color:rgba(var(--v-text-primary, 32, 54, 69, 1));text-align:left;font-family:\"Roboto Mono\";font-weight:400;line-height:22px;font-size:16px;white-space:pre-wrap;min-height:22px;tab-size:2px;word-break:break-word}:host code:focus-visible{outline:none}:host .editor-toolbar{display:flex;flex-direction:row;justify-content:space-between;align-items:center;padding-bottom:12px;border:1px solid rgba(var(--v-border-divider-secondary, 199, 217, 229, 1));border-top-width:0px;border-left-width:0px;border-right-width:0px;margin-bottom:12px;user-select:none}:host .editor-toolbar vega-input-select{width:auto;min-width:161px}:host(.show-line-number) code .v-code-line-number::before{content:attr(data-mark);width:var(--v-code-line-number-width);margin-left:var(--v-code-line-number-ml);padding-right:16px;text-align:right;user-select:none;font-style:normal;word-break:keep-all;color:rgba(var(--v-text-secondary, 107, 116, 125, 1));display:inline-block}:host(.show-line-number) code{padding-left:var(--v-code-block-pl)}:host::part(select-container){padding-top:0px;padding-bottom:0px;padding-left:8px;padding-right:8px;border-radius:4px}:host::part(selected-box),:host::part(placeholder){font-size:14px;user-select:none}:host::part(toggle-icon-container){width:12px;height:12px;line-height:12px}:host::part(toggle-icon){width:12px;height:12px}:host(.readonly) .copy-button-container{position:relative}:host(.readonly) .copy-button-container .copy-code-button{position:absolute;top:0px;right:0px}:host(.disabled:not(.highlight)) code{color:rgba(var(--v-text-input-disabled, 107, 116, 125, 1))}:host(.disabled.highlight){opacity:0.5}:host(.focus:not(.disabled,.readonly)){outline:2px solid rgba(var(--v-border-color-action, 19, 98, 226, 1));outline-offset:2px}:host(.highlight) code{color:var(--code-neutral)}code .comment,code .prolog,code .doctype,code .cdata{color:var(--code-gray);font-style:italic}code .namespace{color:var(--code-neutral-7)}code .string,code .attr-value,code .builtin{color:var(--code-green)}code .punctuation,code .operator,code .attr-equals{color:var(--code-gray)}code .entity,code .url,code .symbol,code .number,code .boolean,code .variable,code .constant,code .property,code .regex,code .inserted{color:var(--code-neutral-8)}code .atrule,code .function,code .attr-name{color:var(--code-orange)}code .deleted{color:var(--code-neutral)}code .function-variable{color:#ff0000}code .tag,code .selector,code .keyword{color:var(--code-purple)}";
|
|
4206
|
-
|
|
4207
|
-
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
4208
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4209
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4210
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
4211
|
-
else
|
|
4212
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
4213
|
-
if (d = decorators[i])
|
|
4214
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4215
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4216
|
-
};
|
|
4217
|
-
const VegaCodeBlock = class {
|
|
4218
|
-
constructor(hostRef) {
|
|
4219
|
-
registerInstance(this, hostRef);
|
|
4220
|
-
this.vegaChange = createEvent(this, "vegaChange", 7);
|
|
4221
|
-
this.change = createEvent(this, "change", 7);
|
|
4222
|
-
this.vegaRemove = createEvent(this, "vegaRemove", 7);
|
|
4223
|
-
this.remove = createEvent(this, "remove", 7);
|
|
4224
|
-
this.globalSlimmers = {};
|
|
4225
|
-
//TODO: The global style should be removed after the code color change to the color token.
|
|
4226
|
-
this.componentGlobalStyleSlimmer = new ComponentGlobalStyleSlimmer(codeColorVariableCss);
|
|
4227
|
-
this.translationSlimmer = new TranslationSlimmer();
|
|
4228
|
-
this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
|
|
4229
|
-
this.codeBlockRenderer = new VegaCodeBlockRenderer();
|
|
4230
|
-
this.contentRenderer = new VegaCodeBlockContentRenderer();
|
|
4231
|
-
this.copyButtonRenderer = new VegaCodeBlockCopyButtonRenderer();
|
|
4232
|
-
this.valueController = new VegaCodeBlockValueController();
|
|
4233
|
-
this.contentParseController = new CodeContentParseController();
|
|
4234
|
-
this.prismCodeHighlightParser = new PrismCodeHighlightParseController();
|
|
4235
|
-
this.defaultCodeHighlightParser = new DefaultCodeHighlightParseController();
|
|
4236
|
-
this.selectionController = new VegaCodeBlockSelectionController();
|
|
4237
|
-
this.inputController = new CodeBlockInputController();
|
|
4238
|
-
this.insertCompositionTextController = new InsertCompositionTextController();
|
|
4239
|
-
this.focusController = new VegaCodeBlockFocusController();
|
|
4240
|
-
this.historyController = new VegaCodeBlockHistoryController();
|
|
4241
|
-
this.changeEventEmitter = createEventEmitSlimmer(VegaCodeBlock, VegaChange);
|
|
4242
|
-
this.removeEventEmitter = createEventEmitSlimmer(VegaCodeBlock, VegaRemove);
|
|
4243
|
-
this.codeBlockPasteController = new CodeBlockPasteController();
|
|
4244
|
-
this.eventPreventSlimmer = new ChildNodesEventPreventSlimmer([VegaChange], () => this.codeBlockRenderer.getToolbarContainerRef());
|
|
4245
|
-
/**
|
|
4246
|
-
* Specifies whether the code block editor is in read-only mode.
|
|
4247
|
-
*
|
|
4248
|
-
* @vegaVersion 2.50.0
|
|
4249
|
-
*/
|
|
4250
|
-
this.readOnly = false;
|
|
4251
|
-
/**
|
|
4252
|
-
* Specifies whether the code block editor is disabled.
|
|
4253
|
-
*
|
|
4254
|
-
* @vegaVersion 2.50.0
|
|
4255
|
-
*/
|
|
4256
|
-
this.disabled = false;
|
|
4257
|
-
/**
|
|
4258
|
-
* Specifies whether to display the copy button in the code block.
|
|
4259
|
-
*
|
|
4260
|
-
* @vegaVersion 2.50.0
|
|
4261
|
-
*/
|
|
4262
|
-
this.showCopyButton = true;
|
|
4263
|
-
/**
|
|
4264
|
-
* Specifies whether to display the code line number in the code block.
|
|
4265
|
-
*
|
|
4266
|
-
* @vegaVersion 2.50.0
|
|
4267
|
-
*/
|
|
4268
|
-
this.showLineNumber = true;
|
|
4269
|
-
}
|
|
4270
|
-
watchEditableChange() {
|
|
4271
|
-
methodPlaceholder();
|
|
4272
|
-
}
|
|
4273
|
-
/**
|
|
4274
|
-
* Check the props value to avoid unnecessary updates.
|
|
4275
|
-
*
|
|
4276
|
-
* @param {unknown} newValue - The new props value.
|
|
4277
|
-
* @param {unknown} oldValue - The old props value.
|
|
4278
|
-
* @param {string} name - The property name.
|
|
4279
|
-
* @returns {boolean} Return false to skip the current update flow.
|
|
4280
|
-
*/
|
|
4281
|
-
componentShouldUpdate(newValue, oldValue, name) {
|
|
4282
|
-
if (name === 'value' && deepEqual(newValue, oldValue)) {
|
|
4283
|
-
return false;
|
|
4284
|
-
}
|
|
4285
|
-
return true;
|
|
4286
|
-
}
|
|
4287
|
-
/**
|
|
4288
|
-
* Invoke this method to focus the current code block.
|
|
4289
|
-
*
|
|
4290
|
-
* @vegaVersion 2.50.0
|
|
4291
|
-
*/
|
|
4292
|
-
async doFocus() {
|
|
4293
|
-
methodPlaceholder();
|
|
4294
|
-
}
|
|
4295
|
-
render() {
|
|
4296
|
-
const classNames = arrayToClassString([
|
|
4297
|
-
this.readOnly ? 'readonly' : '',
|
|
4298
|
-
this.disabled ? 'disabled' : '',
|
|
4299
|
-
this.showLineNumber ? 'show-line-number' : '',
|
|
4300
|
-
this.prismCodeHighlightParser.canParse() ? 'highlight' : '',
|
|
4301
|
-
]);
|
|
4302
|
-
return sanitizeVegaComponent(h(Host, { contenteditable: false, class: classNames }, this.codeBlockRenderer.render()), this.host);
|
|
4303
|
-
}
|
|
4304
|
-
get host() { return getElement(this); }
|
|
4305
|
-
static get watchers() { return {
|
|
4306
|
-
"readOnly": ["watchEditableChange"],
|
|
4307
|
-
"disabled": ["watchEditableChange"]
|
|
4308
|
-
}; }
|
|
4309
|
-
};
|
|
4310
|
-
__decorate([
|
|
4311
|
-
InjectVegaGlobalSlimmer()
|
|
4312
|
-
], VegaCodeBlock.prototype, "globalSlimmers", void 0);
|
|
4313
|
-
__decorate([
|
|
4314
|
-
InjectVegaSlimmer()
|
|
4315
|
-
], VegaCodeBlock.prototype, "componentGlobalStyleSlimmer", void 0);
|
|
4316
|
-
__decorate([
|
|
4317
|
-
InjectVegaSlimmer()
|
|
4318
|
-
], VegaCodeBlock.prototype, "translationSlimmer", void 0);
|
|
4319
|
-
__decorate([
|
|
4320
|
-
InjectVegaSlimmer()
|
|
4321
|
-
], VegaCodeBlock.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
|
|
4322
|
-
__decorate([
|
|
4323
|
-
InjectVegaSlimmer()
|
|
4324
|
-
], VegaCodeBlock.prototype, "codeBlockRenderer", void 0);
|
|
4325
|
-
__decorate([
|
|
4326
|
-
InjectVegaSlimmer()
|
|
4327
|
-
], VegaCodeBlock.prototype, "contentRenderer", void 0);
|
|
4328
|
-
__decorate([
|
|
4329
|
-
InjectVegaSlimmer()
|
|
4330
|
-
], VegaCodeBlock.prototype, "copyButtonRenderer", void 0);
|
|
4331
|
-
__decorate([
|
|
4332
|
-
InjectVegaSlimmer()
|
|
4333
|
-
], VegaCodeBlock.prototype, "valueController", void 0);
|
|
4334
|
-
__decorate([
|
|
4335
|
-
InjectVegaSlimmer()
|
|
4336
|
-
], VegaCodeBlock.prototype, "contentParseController", void 0);
|
|
4337
|
-
__decorate([
|
|
4338
|
-
InjectVegaSlimmer()
|
|
4339
|
-
], VegaCodeBlock.prototype, "prismCodeHighlightParser", void 0);
|
|
4340
|
-
__decorate([
|
|
4341
|
-
InjectVegaSlimmer()
|
|
4342
|
-
], VegaCodeBlock.prototype, "defaultCodeHighlightParser", void 0);
|
|
4343
|
-
__decorate([
|
|
4344
|
-
InjectVegaSlimmer()
|
|
4345
|
-
], VegaCodeBlock.prototype, "selectionController", void 0);
|
|
4346
|
-
__decorate([
|
|
4347
|
-
InjectVegaSlimmer()
|
|
4348
|
-
], VegaCodeBlock.prototype, "inputController", void 0);
|
|
4349
|
-
__decorate([
|
|
4350
|
-
InjectVegaSlimmer()
|
|
4351
|
-
], VegaCodeBlock.prototype, "insertCompositionTextController", void 0);
|
|
4352
|
-
__decorate([
|
|
4353
|
-
InjectVegaSlimmer()
|
|
4354
|
-
], VegaCodeBlock.prototype, "focusController", void 0);
|
|
4355
|
-
__decorate([
|
|
4356
|
-
InjectVegaSlimmer()
|
|
4357
|
-
], VegaCodeBlock.prototype, "historyController", void 0);
|
|
4358
|
-
__decorate([
|
|
4359
|
-
InjectVegaSlimmer()
|
|
4360
|
-
], VegaCodeBlock.prototype, "changeEventEmitter", void 0);
|
|
4361
|
-
__decorate([
|
|
4362
|
-
InjectVegaSlimmer()
|
|
4363
|
-
], VegaCodeBlock.prototype, "removeEventEmitter", void 0);
|
|
4364
|
-
__decorate([
|
|
4365
|
-
InjectVegaSlimmer()
|
|
4366
|
-
], VegaCodeBlock.prototype, "codeBlockPasteController", void 0);
|
|
4367
|
-
__decorate([
|
|
4368
|
-
InjectVegaSlimmer()
|
|
4369
|
-
], VegaCodeBlock.prototype, "eventPreventSlimmer", void 0);
|
|
4370
|
-
VegaCodeBlock.style = vegaCodeBlockCss;
|
|
4371
|
-
|
|
4372
|
-
export { VegaCodeBlock as vega_code_block };
|