umberto 7.0.2 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -1799
- package/LICENSE.md +44 -5
- package/README.md +194 -9
- package/package.json +4 -8
- package/scripts/filter/after-post-render/gloria/append-copy-heading-buttons.js +99 -0
- package/scripts/filter/after-post-render/gloria/apply-design-doc-classes.js +145 -0
- package/scripts/filter/after-post-render/gloria/wrap-table-into-wrappers.js +30 -0
- package/scripts/filter/after-post-render/img-linker.js +1 -1
- package/scripts/filter/after-post-render/insert-error-codes.js +1 -1
- package/scripts/filter/after-post-render/linker.js +1 -1
- package/scripts/filter/after-post-render/snippets.js +5 -1
- package/scripts/filter/after-render/gloria/inline-svg.js +14 -0
- package/scripts/filter/after-render/gloria/spritesheet-svg.js +14 -0
- package/scripts/filter/before-post-render/add-project-info-to-page.js +1 -1
- package/scripts/filter/before-post-render/code-switcher.js +4 -0
- package/scripts/filter/before-post-render/execute-and-insert-function-results.js +3 -1
- package/scripts/filter/before-post-render/gloria/add-breadcrumbs-data-to-page.js +269 -0
- package/scripts/filter/before-post-render/gloria/prerender-admonitions.js +27 -0
- package/scripts/filter/before-post-render/gloria/prerender-xml-pug-components.js +339 -0
- package/scripts/filter/before-post-render/gloria/render-post-render-pug-components.js +94 -0
- package/scripts/filter/before-post-render/set-layout.js +4 -2
- package/scripts/helper/parse-href.js +28 -0
- package/scripts/helper/u-capitalize.js +13 -0
- package/scripts/helper/u-random-id.js +16 -0
- package/scripts/helper/u-remove-indentation.js +13 -0
- package/scripts/helper/u-toc.js +2 -63
- package/scripts/utils/add-indention.js +16 -0
- package/scripts/utils/capitalize.js +17 -0
- package/scripts/utils/concat-url-parts.js +19 -0
- package/scripts/utils/decode-html-entities.js +25 -0
- package/scripts/utils/drop-init-slash.js +14 -0
- package/scripts/utils/drop-trailing-slash.js +14 -0
- package/scripts/utils/drop-url-protocol.js +10 -0
- package/scripts/utils/inline-svg.js +152 -0
- package/scripts/utils/measure-call.js +16 -0
- package/scripts/utils/parse-href.js +37 -0
- package/scripts/utils/parseicontag.js +1 -1
- package/scripts/utils/parselinks.js +27 -6
- package/scripts/utils/parser-cursor.js +280 -0
- package/scripts/utils/pipe.js +17 -0
- package/scripts/utils/pug-renderer/create-prerender-pug-template.js +172 -0
- package/scripts/utils/pug-renderer/render-pug-component.js +73 -0
- package/scripts/utils/pug-to-xml-binding/parser/walk-xml-tree.js +150 -0
- package/scripts/utils/pug-to-xml-binding/parser/xml-components-parser.js +414 -0
- package/scripts/utils/pug-to-xml-binding/render-xml-pug-components-in-markdown.js +193 -0
- package/scripts/utils/pug-to-xml-binding/transform-xml-tree-to-pug.js +144 -0
- package/scripts/utils/random-id.js +67 -0
- package/scripts/utils/remove-indentation.js +48 -0
- package/scripts/utils/spritesheet-svg.js +183 -0
- package/scripts/utils/toc.js +71 -0
- package/scripts/utils/transform-markdown-admonitions.js +98 -0
- package/scripts/utils/uniq-by-last.js +32 -0
- package/src/api-builder/api-builder.js +49 -18
- package/src/api-builder/classes/description-parser.js +61 -10
- package/src/api-builder/classes/doc-data-factory.js +2 -2
- package/src/helpers/github-url.js +1 -1
- package/src/helpers/templates/scripts/default.js +1 -1
- package/src/helpers/templates/scripts/group.js +1 -1
- package/src/hexo/filter/project-locals.js +9 -0
- package/src/hexo/get-repo-urls.js +1 -1
- package/src/hexo/project-globals.js +4 -0
- package/src/hexo-manager.js +7 -2
- package/src/sdk-builder/sdk-builder.js +4 -4
- package/src/tasks/build-api-docs.js +5 -5
- package/src/tasks/build-documentation.js +45 -22
- package/src/tasks/cache-files.js +2 -2
- package/src/tasks/compile-sass.js +12 -0
- package/src/tasks/copy-assets.js +4 -0
- package/src/tasks/copy-project-icons.js +1 -1
- package/src/tasks/get-extra-files.js +1 -1
- package/src/tasks/get-project-config.js +1 -1
- package/src/tasks/overwrite-api-guides.js +1 -1
- package/themes/umberto/layout/gloria/404.pug +25 -16
- package/themes/umberto/layout/gloria/_api-docs/_header/_style.scss +31 -0
- package/themes/umberto/layout/gloria/_api-docs/_header/index.pug +50 -0
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_api-see-source.pug +1 -4
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_api-tree-item.pug +34 -26
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_class-item.pug +20 -13
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_dev-names.pug +1 -1
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_error.pug +10 -5
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_hierarchy-list.pug +1 -1
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_link-or-text.pug +1 -1
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_method.pug +45 -39
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_property.pug +26 -20
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_related.pug +1 -1
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_toc-list-item.pug +11 -0
- package/themes/umberto/layout/gloria/_api-docs/_partial/api-subheader.pug +0 -11
- package/themes/umberto/layout/gloria/_api-docs/_partial/api-toc.pug +33 -0
- package/themes/umberto/layout/gloria/_api-docs/_partial/classes.pug +5 -4
- package/themes/umberto/layout/gloria/_api-docs/_partial/config-options.pug +5 -4
- package/themes/umberto/layout/gloria/_api-docs/_partial/constants.pug +1 -1
- package/themes/umberto/layout/gloria/_api-docs/_partial/description.pug +2 -2
- package/themes/umberto/layout/gloria/_api-docs/_partial/events.pug +5 -4
- package/themes/umberto/layout/gloria/_api-docs/_partial/functions.pug +5 -4
- package/themes/umberto/layout/gloria/_api-docs/_partial/interfaces.pug +1 -1
- package/themes/umberto/layout/gloria/_api-docs/_partial/methods.pug +14 -13
- package/themes/umberto/layout/gloria/_api-docs/_partial/namespaces.pug +1 -1
- package/themes/umberto/layout/gloria/_api-docs/_partial/navtree.pug +4 -11
- package/themes/umberto/layout/gloria/_api-docs/_partial/properties.pug +14 -13
- package/themes/umberto/layout/gloria/_api-docs/_partial/type-parameters.pug +15 -12
- package/themes/umberto/layout/gloria/_api-docs/_partial/typedefs.pug +5 -4
- package/themes/umberto/layout/gloria/_api-docs/_subheader/_style.scss +5 -0
- package/themes/umberto/layout/gloria/_api-docs/_subheader/index.pug +10 -0
- package/themes/umberto/layout/gloria/_api-docs/_toc/_style.scss +227 -0
- package/themes/umberto/layout/gloria/_api-docs/_toc/index.pug +11 -0
- package/themes/umberto/layout/gloria/_api-docs/api-base.pug +24 -24
- package/themes/umberto/layout/gloria/_api-docs/class.pug +4 -4
- package/themes/umberto/layout/gloria/_api-docs/errors.pug +3 -3
- package/themes/umberto/layout/gloria/_api-docs/index.pug +3 -0
- package/themes/umberto/layout/gloria/_api-docs/interface.pug +4 -4
- package/themes/umberto/layout/gloria/_api-docs/mixin.pug +4 -4
- package/themes/umberto/layout/gloria/_api-docs/module.pug +4 -4
- package/themes/umberto/layout/gloria/_api-docs/namespace.pug +4 -4
- package/themes/umberto/layout/gloria/_api-docs/typedef.pug +22 -22
- package/themes/umberto/layout/gloria/_components/badge/_style.scss +27 -0
- package/themes/umberto/layout/gloria/_components/badge/index.pug +30 -0
- package/themes/umberto/layout/gloria/_components/banner/_style.scss +133 -0
- package/themes/umberto/layout/gloria/_components/banner/index.pug +3 -0
- package/themes/umberto/layout/gloria/_components/button/_style.scss +183 -0
- package/themes/umberto/layout/gloria/_components/button/index.pug +140 -0
- package/themes/umberto/layout/gloria/_components/callout/_style.scss +56 -0
- package/themes/umberto/layout/gloria/_components/callout/index.pug +87 -0
- package/themes/umberto/layout/gloria/_components/card/_style.scss +101 -0
- package/themes/umberto/layout/gloria/_components/card/index.pug +131 -0
- package/themes/umberto/layout/gloria/_components/card-learn-more-links/_style.scss +9 -0
- package/themes/umberto/layout/gloria/_components/card-learn-more-links/index.pug +56 -0
- package/themes/umberto/layout/gloria/_components/checkbox/_style.scss +117 -0
- package/themes/umberto/layout/gloria/_components/checkbox/index.pug +35 -0
- package/themes/umberto/layout/gloria/_components/cke5-code-switcher/index.pug +39 -0
- package/themes/umberto/layout/gloria/_components/code-block/_style.scss +111 -0
- package/themes/umberto/layout/gloria/_components/code-block/index.pug +67 -0
- package/themes/umberto/layout/gloria/_components/code-switcher/_style.scss +41 -0
- package/themes/umberto/layout/gloria/_components/code-switcher/index.pug +31 -0
- package/themes/umberto/layout/gloria/_components/columns/_style.scss +54 -0
- package/themes/umberto/layout/gloria/_components/columns/index.pug +30 -0
- package/themes/umberto/layout/gloria/_components/divider/_style.scss +6 -0
- package/themes/umberto/layout/gloria/_components/divider/index.pug +13 -0
- package/themes/umberto/layout/gloria/_components/dropdown/_style.scss +88 -0
- package/themes/umberto/layout/gloria/_components/dropdown/index.pug +77 -0
- package/themes/umberto/layout/gloria/_components/fake-devtools/_style.scss +233 -0
- package/themes/umberto/layout/gloria/_components/fake-devtools/index.pug +27 -0
- package/themes/umberto/layout/gloria/_components/heading-badge/index.pug +17 -0
- package/themes/umberto/layout/gloria/_components/heading-link/_style.scss +47 -0
- package/themes/umberto/layout/gloria/_components/heading-link/index.pug +26 -0
- package/themes/umberto/layout/gloria/_components/icon/_style.scss +12 -0
- package/themes/umberto/layout/gloria/_components/icon/index.pug +75 -0
- package/themes/umberto/layout/gloria/_components/icon-message/_style.scss +13 -0
- package/themes/umberto/layout/gloria/_components/icon-message/index.pug +17 -0
- package/themes/umberto/layout/gloria/_components/iframe/_style.scss +10 -0
- package/themes/umberto/layout/gloria/_components/iframe/index.pug +22 -0
- package/themes/umberto/layout/gloria/_components/img/index.pug +17 -0
- package/themes/umberto/layout/gloria/_components/index.pug +31 -0
- package/themes/umberto/layout/gloria/_components/input/_style.scss +82 -0
- package/themes/umberto/layout/gloria/_components/input/index.pug +34 -0
- package/themes/umberto/layout/gloria/_components/json-ld/index.pug +3 -0
- package/themes/umberto/layout/gloria/_components/keyboard-shortcut/_style.scss +49 -0
- package/themes/umberto/layout/gloria/_components/keyboard-shortcut/index.pug +23 -0
- package/themes/umberto/layout/gloria/_components/menu-dropdown/_style.scss +27 -0
- package/themes/umberto/layout/gloria/_components/menu-dropdown/index.pug +40 -0
- package/themes/umberto/layout/gloria/_components/mobile-overlay/_style.scss +70 -0
- package/themes/umberto/layout/gloria/_components/mobile-overlay/index.pug +37 -0
- package/themes/umberto/layout/gloria/_components/nav-tree/_style.scss +104 -0
- package/themes/umberto/layout/gloria/_components/nav-tree/index.pug +6 -0
- package/themes/umberto/layout/gloria/_components/nav-tree/nav-tree-item.pug +23 -0
- package/themes/umberto/layout/gloria/{_mixin → _components/nav-tree}/nav-tree-level.pug +31 -11
- package/themes/umberto/layout/gloria/_components/skeleton/_style.scss +22 -0
- package/themes/umberto/layout/gloria/_components/skeleton/index.pug +16 -0
- package/themes/umberto/layout/gloria/_components/spacer/_style.scss +9 -0
- package/themes/umberto/layout/gloria/_components/spacer/index.pug +19 -0
- package/themes/umberto/layout/gloria/_components/svg/index.pug +70 -0
- package/themes/umberto/layout/gloria/_components/tabs/_style.scss +80 -0
- package/themes/umberto/layout/gloria/_components/tabs/index.pug +81 -0
- package/themes/umberto/layout/gloria/_components/tag/_style.scss +79 -0
- package/themes/umberto/layout/gloria/_components/tag/index.pug +17 -0
- package/themes/umberto/layout/gloria/_components/tooltip-popover/_style.scss +194 -0
- package/themes/umberto/layout/gloria/_components/tooltip-popover/index.pug +38 -0
- package/themes/umberto/layout/gloria/_head/head-preloads.pug +32 -0
- package/themes/umberto/layout/gloria/{_partial → _head}/head.pug +8 -4
- package/themes/umberto/layout/gloria/_head/index.pug +1 -0
- package/themes/umberto/layout/gloria/_modules/algolia-search/_style.scss +202 -0
- package/themes/umberto/layout/gloria/_modules/algolia-search/_third-party.scss +1 -0
- package/themes/umberto/layout/gloria/_modules/algolia-search/index.pug +38 -0
- package/themes/umberto/layout/gloria/_modules/breadcrumbs/_style.scss +68 -0
- package/themes/umberto/layout/gloria/_modules/breadcrumbs/index.pug +18 -0
- package/themes/umberto/layout/gloria/_modules/footer/_style.scss +40 -0
- package/themes/umberto/layout/gloria/_modules/footer/index.pug +87 -0
- package/themes/umberto/layout/gloria/_modules/header/_style.scss +181 -0
- package/themes/umberto/layout/gloria/_modules/header/index.pug +70 -0
- package/themes/umberto/layout/gloria/_modules/header/nav-link.pug +19 -0
- package/themes/umberto/layout/gloria/_modules/header/nav-links.pug +11 -0
- package/themes/umberto/layout/gloria/_modules/header/nav-project-select-dropdown.pug +16 -0
- package/themes/umberto/layout/gloria/_modules/header/nav-suffix-links.pug +20 -0
- package/themes/umberto/layout/gloria/_modules/header-bar/_style.scss +56 -0
- package/themes/umberto/layout/gloria/_modules/header-bar/index.pug +40 -0
- package/themes/umberto/layout/gloria/_modules/header-legacy-warning/index.pug +11 -0
- package/themes/umberto/layout/gloria/_modules/header-nightly-info/index.pug +20 -0
- package/themes/umberto/layout/gloria/_modules/header-promobar/index.pug +18 -0
- package/themes/umberto/layout/gloria/_modules/index.pug +14 -0
- package/themes/umberto/layout/gloria/_modules/main/_style.scss +54 -0
- package/themes/umberto/layout/gloria/_modules/main/index.pug +10 -0
- package/themes/umberto/layout/gloria/_modules/mobile-nav/_style.scss +106 -0
- package/themes/umberto/layout/gloria/_modules/mobile-nav/index.pug +121 -0
- package/themes/umberto/layout/gloria/_modules/mobile-nav/slide-parts.pug +67 -0
- package/themes/umberto/layout/gloria/_modules/not-found/_style.scss +38 -0
- package/themes/umberto/layout/gloria/_modules/not-found/index.pug +16 -0
- package/themes/umberto/layout/gloria/_modules/sidebar/_style.scss +147 -0
- package/themes/umberto/layout/gloria/_modules/sidebar/index.pug +24 -0
- package/themes/umberto/layout/gloria/_modules/sidebar-api/_style.scss +2 -0
- package/themes/umberto/layout/gloria/_modules/sidebar-api/index.pug +6 -0
- package/themes/umberto/layout/gloria/_modules/toc/_style.scss +201 -0
- package/themes/umberto/layout/gloria/_modules/toc/index.pug +10 -0
- package/themes/umberto/layout/gloria/_trackers/google-tag-manager.pug +14 -0
- package/themes/umberto/layout/gloria/_trackers/index.pug +2 -0
- package/themes/umberto/layout/gloria/api.pug +43 -20
- package/themes/umberto/layout/gloria/base.pug +23 -32
- package/themes/umberto/layout/gloria/index.pug +19 -13
- package/themes/umberto/layout/gloria/page.pug +30 -11
- package/themes/umberto/layout/gloria/sdk.pug +1 -1
- package/themes/umberto/layout/gloria/theme.pug +304 -0
- package/themes/umberto/layout/umberto/404.pug +0 -1
- package/themes/umberto/layout/umberto/_partial/report-issue-widget.pug +0 -3
- package/themes/umberto/source/gloria/assets/_fonts/Menlo/Menlo-Regular.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Menlo/Menlo-Regular.woff +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/Mulish-Italic-VariableFont_wght.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/Mulish-Italic-VariableFont_wght.woff2 +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/Mulish-VariableFont_wght.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/Mulish-VariableFont_wght.woff2 +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-Black.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-BlackItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-Bold.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-BoldItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-ExtraBold.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-ExtraBoldItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-ExtraLight.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-ExtraLightItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-Italic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-Light.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-LightItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-Medium.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-MediumItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-Regular.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-SemiBold.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Mulish/static/Mulish-SemiBoldItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/PublicSans-Italic-VariableFont_wght.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/PublicSans-Italic-VariableFont_wght.woff2 +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/PublicSans-VariableFont_wght.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/PublicSans-VariableFont_wght.woff2 +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-Black.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-BlackItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-Bold.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-BoldItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-ExtraBold.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-ExtraBoldItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-ExtraLight.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-ExtraLightItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-Italic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-Light.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-LightItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-Medium.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-MediumItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-Regular.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-SemiBold.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-SemiBoldItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-Thin.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_fonts/Public_Sans/static/PublicSans-ThinItalic.ttf +0 -0
- package/themes/umberto/source/gloria/assets/_img/404-billboard.svg +181 -0
- package/themes/umberto/source/gloria/assets/_img/ckeditor-logo.svg +15 -0
- package/themes/umberto/source/gloria/assets/_img/hex-bg-2.svg +10 -0
- package/themes/umberto/source/gloria/assets/_img/hex-bg.svg +10 -0
- package/themes/umberto/source/gloria/assets/_img/icons/api-class.svg +10 -0
- package/themes/umberto/source/gloria/assets/_img/icons/api-folder.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/api-interface.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/api-module.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/api-package.svg +4 -0
- package/themes/umberto/source/gloria/assets/_img/icons/api-typedef.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/bulb.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/check-circle.svg +4 -0
- package/themes/umberto/source/gloria/assets/_img/icons/check.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/chevron-down.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/chevron-right.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/close-circle.svg +4 -0
- package/themes/umberto/source/gloria/assets/_img/icons/close.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/copy.svg +10 -0
- package/themes/umberto/source/gloria/assets/_img/icons/dislike.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/download.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/edit.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/exclamation-circle.svg +4 -0
- package/themes/umberto/source/gloria/assets/_img/icons/experiment.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/export.svg +4 -0
- package/themes/umberto/source/gloria/assets/_img/icons/eye.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/filter.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/github.svg +10 -0
- package/themes/umberto/source/gloria/assets/_img/icons/info-circle.svg +4 -0
- package/themes/umberto/source/gloria/assets/_img/icons/like.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/link.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/lock.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/menu-fold.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/menu-list.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/menu.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/more.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/notification.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/number.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/premium.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/right.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/search.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/status.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/trash.svg +3 -0
- package/themes/umberto/source/gloria/assets/_img/icons/unordered-list.svg +5 -0
- package/themes/umberto/source/gloria/assets/_img/icons/warning.svg +10 -0
- package/themes/umberto/src/gloria/css/_fonts.scss +51 -0
- package/themes/umberto/src/gloria/css/_layers.scss +1 -0
- package/themes/umberto/src/gloria/css/_normalize.scss +118 -0
- package/themes/umberto/src/gloria/css/a11y/_focusable.scss +7 -0
- package/themes/umberto/src/gloria/css/a11y/_index.scss +4 -0
- package/themes/umberto/src/gloria/css/a11y/_mixins.scss +32 -0
- package/themes/umberto/src/gloria/css/a11y/_reduce-motion.scss +9 -0
- package/themes/umberto/src/gloria/css/a11y/_screen-reader.scss +15 -0
- package/themes/umberto/src/gloria/css/base/_buttons.scss +13 -0
- package/themes/umberto/src/gloria/css/base/_descriptions-list.scss +33 -0
- package/themes/umberto/src/gloria/css/base/_details.scss +7 -0
- package/themes/umberto/src/gloria/css/base/_headings.scss +111 -0
- package/themes/umberto/src/gloria/css/base/_iframes.scss +7 -0
- package/themes/umberto/src/gloria/css/base/_index.scss +12 -0
- package/themes/umberto/src/gloria/css/base/_inline-code.scss +15 -0
- package/themes/umberto/src/gloria/css/base/_links.scss +30 -0
- package/themes/umberto/src/gloria/css/base/_lists.scss +58 -0
- package/themes/umberto/src/gloria/css/base/_mixins.scss +3 -0
- package/themes/umberto/src/gloria/css/base/_paragraphs.scss +15 -0
- package/themes/umberto/src/gloria/css/base/_tables.scss +68 -0
- package/themes/umberto/src/gloria/css/base/_typography.scss +62 -0
- package/themes/umberto/src/gloria/css/components/_api-collapsing-list.scss +148 -0
- package/themes/umberto/src/gloria/css/components/_api-filter-dropdown.scss +17 -0
- package/themes/umberto/src/gloria/css/components/_api-item-heading.scss +58 -0
- package/themes/umberto/src/gloria/css/components/_api-tree.scss +202 -0
- package/themes/umberto/src/gloria/css/components/_hierarchy-list.scss +35 -0
- package/themes/umberto/src/gloria/css/components/_image-zoom.scss +13 -0
- package/themes/umberto/src/gloria/css/components/_index.scss +55 -0
- package/themes/umberto/src/gloria/css/components/_notification.scss +36 -0
- package/themes/umberto/src/gloria/css/components/_utils.scss +5 -0
- package/themes/umberto/src/gloria/css/doc/_details.scss +11 -0
- package/themes/umberto/src/gloria/css/doc/_editor-icons.scss +21 -0
- package/themes/umberto/src/gloria/css/doc/_images.scss +9 -0
- package/themes/umberto/src/gloria/css/doc/_index.scss +5 -0
- package/themes/umberto/src/gloria/css/doc/_snippets.scss +126 -0
- package/themes/umberto/src/gloria/css/doc/_typography.scss +5 -0
- package/themes/umberto/src/gloria/css/layout/_base.scss +27 -0
- package/themes/umberto/src/gloria/css/layout/_breakpoints.scss +88 -0
- package/themes/umberto/src/gloria/css/layout/_container.scss +38 -0
- package/themes/umberto/src/gloria/css/layout/_index.scss +6 -0
- package/themes/umberto/src/gloria/css/layout/_layout.scss +64 -0
- package/themes/umberto/src/gloria/css/layout/_mixins.scss +34 -0
- package/themes/umberto/src/gloria/css/layout/_zindex.scss +12 -0
- package/themes/umberto/src/gloria/css/modules/_index.scss +29 -0
- package/themes/umberto/src/gloria/css/modules/_utils.scss +7 -0
- package/themes/umberto/src/gloria/css/styles.scss +11 -117
- package/themes/umberto/src/gloria/css/theme/_light.scss +344 -0
- package/themes/umberto/src/gloria/css/utilities/_animation.scss +32 -0
- package/themes/umberto/src/gloria/css/utilities/_colors.scss +14 -0
- package/themes/umberto/src/gloria/css/utilities/_display.scss +13 -0
- package/themes/umberto/src/gloria/css/utilities/_flex.scss +33 -0
- package/themes/umberto/src/gloria/css/utilities/_gap.scss +8 -0
- package/themes/umberto/src/gloria/css/utilities/_index.scss +11 -0
- package/themes/umberto/src/gloria/css/utilities/_radius.scss +21 -0
- package/themes/umberto/src/gloria/css/utilities/_rotation.scss +8 -0
- package/themes/umberto/src/gloria/css/utilities/_shadows.scss +13 -0
- package/themes/umberto/src/gloria/css/utilities/_spacing.scss +96 -0
- package/themes/umberto/src/gloria/css/utilities/_stop-scrolling.scss +9 -0
- package/themes/umberto/src/gloria/css/utilities/_text.scss +42 -0
- package/themes/umberto/src/gloria/js/app.js +92 -54
- package/themes/umberto/src/gloria/js/components/api-nav-tree.js +171 -0
- package/themes/umberto/src/gloria/js/components/api-toggle.js +92 -0
- package/themes/umberto/src/gloria/js/components/base-component.js +41 -0
- package/themes/umberto/src/gloria/js/components/breadcrumbs.js +115 -0
- package/themes/umberto/src/gloria/js/components/code-block.js +226 -0
- package/themes/umberto/src/gloria/js/components/code-switcher.js +177 -0
- package/themes/umberto/src/gloria/js/components/dropdown.js +516 -0
- package/themes/umberto/src/gloria/js/components/expandable.js +79 -0
- package/themes/umberto/src/gloria/js/components/fake-devtools.js +722 -0
- package/themes/umberto/src/gloria/js/components/hash-link.js +60 -0
- package/themes/umberto/src/gloria/js/components/heading-link.js +135 -0
- package/themes/umberto/src/gloria/js/components/iframe.js +158 -0
- package/themes/umberto/src/gloria/js/{_imageModal.js → components/image-zoom.js} +1 -1
- package/themes/umberto/src/gloria/js/components/mobile-overlay.js +315 -0
- package/themes/umberto/src/gloria/js/components/nav-tree.js +164 -0
- package/themes/umberto/src/gloria/js/components/tabs.js +284 -0
- package/themes/umberto/src/gloria/js/components/tooltip-popover.js +576 -0
- package/themes/umberto/src/gloria/js/helpers/after-dom-ready.js +16 -0
- package/themes/umberto/src/gloria/js/helpers/animate-element.js +78 -0
- package/themes/umberto/src/gloria/js/helpers/body-scroll.js +22 -0
- package/themes/umberto/src/gloria/js/helpers/clamp.js +16 -0
- package/themes/umberto/src/gloria/js/helpers/classnames.js +64 -0
- package/themes/umberto/src/gloria/js/helpers/copy-to-clipboard.js +19 -0
- package/themes/umberto/src/gloria/js/helpers/create-anchor-positioning-watcher.js +46 -0
- package/themes/umberto/src/gloria/js/helpers/create-cleanup-registry.js +88 -0
- package/themes/umberto/src/gloria/js/helpers/create-hover-manager.js +93 -0
- package/themes/umberto/src/gloria/js/helpers/create-keyboard-blur-watcher.js +90 -0
- package/themes/umberto/src/gloria/js/helpers/create-keyboard-focus-cycler.js +251 -0
- package/themes/umberto/src/gloria/js/helpers/create-mutation-observer.js +49 -0
- package/themes/umberto/src/gloria/js/helpers/create-outside-click-watcher.js +39 -0
- package/themes/umberto/src/gloria/js/helpers/cubic-bezier.js +55 -0
- package/themes/umberto/src/gloria/js/helpers/date-time.js +21 -0
- package/themes/umberto/src/gloria/js/helpers/decode-html-entities.js +23 -0
- package/themes/umberto/src/gloria/js/helpers/escape-handler.js +59 -0
- package/themes/umberto/src/gloria/js/helpers/fetch-stylesheet.js +25 -0
- package/themes/umberto/src/gloria/js/helpers/find-code-lang.js +85 -0
- package/themes/umberto/src/gloria/js/helpers/focus-first-interactive.js +50 -0
- package/themes/umberto/src/gloria/js/helpers/format-html.js +181 -0
- package/themes/umberto/src/gloria/js/helpers/get-all-scrollable-parents.js +34 -0
- package/themes/umberto/src/gloria/js/helpers/get-parents-until.js +26 -0
- package/themes/umberto/src/gloria/js/helpers/highlight-code.js +18 -0
- package/themes/umberto/src/gloria/js/helpers/html-builder.js +69 -0
- package/themes/umberto/src/gloria/js/helpers/identity.js +8 -0
- package/themes/umberto/src/gloria/js/helpers/inject-resource-preload.js +51 -0
- package/themes/umberto/src/gloria/js/helpers/inject-script.js +79 -0
- package/themes/umberto/src/gloria/js/helpers/inject-stylesheet.js +108 -0
- package/themes/umberto/src/gloria/js/helpers/is-element-attached.js +28 -0
- package/themes/umberto/src/gloria/js/helpers/is-focusable.js +14 -0
- package/themes/umberto/src/gloria/js/helpers/is-hidden-element.js +8 -0
- package/themes/umberto/src/gloria/js/helpers/is-mobile.js +8 -0
- package/themes/umberto/src/gloria/js/helpers/is-unsafe-key.js +14 -0
- package/themes/umberto/src/gloria/js/helpers/lerp.js +27 -0
- package/themes/umberto/src/gloria/js/helpers/local-storage-helper.js +133 -0
- package/themes/umberto/src/gloria/js/helpers/pipe.js +8 -0
- package/themes/umberto/src/gloria/js/helpers/prefers-reduced-motion.js +13 -0
- package/themes/umberto/src/gloria/js/helpers/random-id.js +51 -0
- package/themes/umberto/src/gloria/js/helpers/sanitize-text.js +27 -0
- package/themes/umberto/src/gloria/js/helpers/scroll-to-hash.js +31 -0
- package/themes/umberto/src/gloria/js/helpers/take-last.js +19 -0
- package/themes/umberto/src/gloria/js/helpers/tap.js +11 -0
- package/themes/umberto/src/gloria/js/helpers/throttle.js +46 -0
- package/themes/umberto/src/gloria/js/helpers/timeout.js +14 -0
- package/themes/umberto/src/gloria/js/helpers/toggle-height.js +46 -0
- package/themes/umberto/src/gloria/js/helpers/tween.js +100 -0
- package/themes/umberto/src/gloria/js/helpers/wrap-around.js +39 -0
- package/themes/umberto/src/gloria/js/modules/algolia-search.js +168 -0
- package/themes/umberto/src/gloria/js/modules/api-filter.js +184 -0
- package/themes/umberto/src/gloria/js/modules/header-bar.js +154 -0
- package/themes/umberto/src/gloria/js/modules/header.js +242 -0
- package/themes/umberto/src/gloria/js/modules/links-prefetch.js +196 -0
- package/themes/umberto/src/gloria/js/modules/mobile-nav.js +327 -0
- package/themes/umberto/src/gloria/js/modules/sidebar.js +114 -0
- package/themes/umberto/src/gloria/js/modules/table-of-contents-api.js +214 -0
- package/themes/umberto/src/gloria/js/modules/table-of-contents.js +287 -0
- package/themes/umberto/src/gloria/js/public-api.js +75 -0
- package/themes/umberto/src/gloria/js/web-components/svg-icon.js +117 -0
- package/themes/umberto/src/umberto/js/_codeswitcherbuttons.js +1 -1
- package/themes/umberto/layout/gloria/_api-docs/_mixin/_api-title.pug +0 -17
- package/themes/umberto/layout/gloria/_mixin/nav-tree-item.pug +0 -13
- package/themes/umberto/layout/gloria/_partial/docsearch.pug +0 -21
- package/themes/umberto/layout/gloria/_partial/dropdown.pug +0 -12
- package/themes/umberto/layout/gloria/_partial/feedback-widget.pug +0 -20
- package/themes/umberto/layout/gloria/_partial/footer.pug +0 -6
- package/themes/umberto/layout/gloria/_partial/gh-contribute.pug +0 -8
- package/themes/umberto/layout/gloria/_partial/google-tag-manager.pug +0 -18
- package/themes/umberto/layout/gloria/_partial/header.pug +0 -64
- package/themes/umberto/layout/gloria/_partial/nav-tree.pug +0 -9
- package/themes/umberto/layout/gloria/_partial/report-issue-widget.pug +0 -26
- package/themes/umberto/layout/gloria/_partial/rwd-breadcrumbs.pug +0 -13
- package/themes/umberto/layout/gloria/_partial/search-box.pug +0 -6
- package/themes/umberto/layout/gloria/_partial/vwo.pug +0 -11
- package/themes/umberto/source/gloria/assets/_img/arrows.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/book.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/box-brown.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/box-orange.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/box-red.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/bulb.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/clipboard.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/cog.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/data.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/documentation.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/download.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/edit.svg +0 -2
- package/themes/umberto/source/gloria/assets/_img/exclamation-circle.svg +0 -2
- package/themes/umberto/source/gloria/assets/_img/eye.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/filter.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/filtering.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/folder.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/github.svg +0 -6
- package/themes/umberto/source/gloria/assets/_img/header-info-configs.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/header-info-events.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/header-info-methods.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/header-info-properties.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/heart.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/info-circle.svg +0 -4
- package/themes/umberto/source/gloria/assets/_img/info.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/list-nest.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/loupe.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/menu.svg +0 -4
- package/themes/umberto/source/gloria/assets/_img/plug.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/star-in-circle.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/tick.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/triangle-down.svg +0 -1
- package/themes/umberto/source/gloria/assets/_img/triangle-right.svg +0 -1
- package/themes/umberto/src/gloria/css/_api-content.scss +0 -32
- package/themes/umberto/src/gloria/css/_api-info-box.scss +0 -86
- package/themes/umberto/src/gloria/css/_api-props-filter.scss +0 -106
- package/themes/umberto/src/gloria/css/_api-see-source.scss +0 -35
- package/themes/umberto/src/gloria/css/_api-subheader.scss +0 -167
- package/themes/umberto/src/gloria/css/_api-tree.scss +0 -121
- package/themes/umberto/src/gloria/css/_badge.scss +0 -74
- package/themes/umberto/src/gloria/css/_code-switcher.scss +0 -61
- package/themes/umberto/src/gloria/css/_collapsinglist.scss +0 -262
- package/themes/umberto/src/gloria/css/_content.scss +0 -236
- package/themes/umberto/src/gloria/css/_docsearch.scss +0 -109
- package/themes/umberto/src/gloria/css/_dropdown.scss +0 -63
- package/themes/umberto/src/gloria/css/_editor-icon.scss +0 -26
- package/themes/umberto/src/gloria/css/_feedback-widget.scss +0 -11
- package/themes/umberto/src/gloria/css/_font-external.scss +0 -8
- package/themes/umberto/src/gloria/css/_footer.scss +0 -40
- package/themes/umberto/src/gloria/css/_formatted.scss +0 -285
- package/themes/umberto/src/gloria/css/_guide-content.scss +0 -37
- package/themes/umberto/src/gloria/css/_guide-sdk-tree.scss +0 -14
- package/themes/umberto/src/gloria/css/_loading-spinner.scss +0 -33
- package/themes/umberto/src/gloria/css/_main.scss +0 -59
- package/themes/umberto/src/gloria/css/_navigation.scss +0 -35
- package/themes/umberto/src/gloria/css/_notice.scss +0 -116
- package/themes/umberto/src/gloria/css/_print.scss +0 -20
- package/themes/umberto/src/gloria/css/_prism.scss +0 -223
- package/themes/umberto/src/gloria/css/_rwd-breadcrumbs.scss +0 -28
- package/themes/umberto/src/gloria/css/_rwd-menu.scss +0 -89
- package/themes/umberto/src/gloria/css/_secondary-navigation.scss +0 -152
- package/themes/umberto/src/gloria/css/_theme-dark.scss +0 -175
- package/themes/umberto/src/gloria/css/_toggler.scss +0 -46
- package/themes/umberto/src/gloria/css/_top.scss +0 -350
- package/themes/umberto/src/gloria/css/_tree.scss +0 -218
- package/themes/umberto/src/gloria/css/_warning-banner.scss +0 -46
- package/themes/umberto/src/gloria/css/components/_lightbox.scss +0 -12
- package/themes/umberto/src/gloria/css/helpers/_color.scss +0 -49
- package/themes/umberto/src/gloria/css/helpers/_font.scss +0 -60
- package/themes/umberto/src/gloria/css/helpers/_globals.scss +0 -129
- package/themes/umberto/src/gloria/css/helpers/_reset.scss +0 -52
- package/themes/umberto/src/gloria/css/helpers/_spacing.scss +0 -21
- package/themes/umberto/src/gloria/css/pages/_sdk.scss +0 -111
- package/themes/umberto/src/gloria/js/_anchors.js +0 -57
- package/themes/umberto/src/gloria/js/_apisearch.js +0 -126
- package/themes/umberto/src/gloria/js/_apitree.js +0 -67
- package/themes/umberto/src/gloria/js/_attachpermalinklistener.js +0 -50
- package/themes/umberto/src/gloria/js/_codeswitcherbuttons.js +0 -146
- package/themes/umberto/src/gloria/js/_collapsables.js +0 -135
- package/themes/umberto/src/gloria/js/_copymobileapinavigation.js +0 -26
- package/themes/umberto/src/gloria/js/_devnames.js +0 -37
- package/themes/umberto/src/gloria/js/_dropdowns.js +0 -55
- package/themes/umberto/src/gloria/js/_filtering.js +0 -139
- package/themes/umberto/src/gloria/js/_pagenavigation.js +0 -93
- package/themes/umberto/src/gloria/js/_prism.js +0 -104
- package/themes/umberto/src/gloria/js/_rwdmenu.js +0 -15
- package/themes/umberto/src/gloria/js/_samplecode.js +0 -23
- package/themes/umberto/src/gloria/js/_sidenavigation.js +0 -59
- package/themes/umberto/src/gloria/js/_toc.js +0 -93
- package/themes/umberto/src/gloria/js/_tooltips.js +0 -39
- package/themes/umberto/src/gloria/js/_warningbanner.js +0 -18
- package/themes/umberto/src/gloria/js/vendor/prism.js +0 -45
- /package/themes/umberto/layout/gloria/_api-docs/_partial/{api-info-box.pug → api-hierarchy.pug} +0 -0
- /package/themes/umberto/layout/gloria/{_partial → _trackers}/google-analytics.pug +0 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A cursor class that enables creating a left recursion recursive descent parser.
|
|
10
|
+
* It maintains position state and provides backtracking capabilities for parsing operations.
|
|
11
|
+
*/
|
|
12
|
+
class ParserCursor {
|
|
13
|
+
#_stack = [];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new cursor instance for parsing text.
|
|
17
|
+
*
|
|
18
|
+
* @param text - The text to parse.
|
|
19
|
+
* @param [index=0] - The initial position in the text.
|
|
20
|
+
*/
|
|
21
|
+
constructor( text, index = 0 ) {
|
|
22
|
+
this.index = index;
|
|
23
|
+
this.text = text;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Executes a callback with automatic cursor position management.
|
|
28
|
+
* If the callback returns undefined, the cursor position is restored to the state before the call.
|
|
29
|
+
* This enables backtracking in the parser.
|
|
30
|
+
*
|
|
31
|
+
* @param callback - The callback function to execute.
|
|
32
|
+
* @returns The result of the callback function.
|
|
33
|
+
*/
|
|
34
|
+
try( callback ) {
|
|
35
|
+
this.#push();
|
|
36
|
+
|
|
37
|
+
const result = callback( this );
|
|
38
|
+
|
|
39
|
+
if ( result === undefined ) {
|
|
40
|
+
this.index = this.#pop();
|
|
41
|
+
} else {
|
|
42
|
+
this.#pop( false );
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Attempts to consume a single terminal character at the current position.
|
|
50
|
+
*
|
|
51
|
+
* @param ch - The character to match and consume.
|
|
52
|
+
* @returns True if the character was consumed, false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
eatTerminal( ch ) {
|
|
55
|
+
if ( this.text[ this.index ] !== ch ) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.index++;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Attempts to consume a sequence of terminal characters.
|
|
65
|
+
* All characters must match in order for the operation to succeed.
|
|
66
|
+
*
|
|
67
|
+
* @param chars - The sequence of characters to match and consume.
|
|
68
|
+
* @returns True if all characters were consumed, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
eatTerminals( chars ) {
|
|
71
|
+
this.#push();
|
|
72
|
+
|
|
73
|
+
for ( const ch of chars ) {
|
|
74
|
+
if ( !this.eatTerminal( ch ) ) {
|
|
75
|
+
this.#pop();
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.#pop( false );
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Consumes all terminal characters from the current position until a non-terminal character is encountered.
|
|
86
|
+
*
|
|
87
|
+
* @param chars - The characters to consume. If not provided, defaults to whitespace characters.
|
|
88
|
+
*/
|
|
89
|
+
eatAllNextTerminals( chars ) {
|
|
90
|
+
while ( this.index < this.text.length && chars.includes( this.text[ this.index ] ) ) {
|
|
91
|
+
this.index++;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Consumes all whitespace characters (spaces and tabs) from the current position.
|
|
97
|
+
*/
|
|
98
|
+
eatIndent() {
|
|
99
|
+
this.eatAllNextTerminals( ' \t' );
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Consumes characters from the current position until a character matches the provided matcher function.
|
|
104
|
+
* It consumes terminal character but does not include it in the result.
|
|
105
|
+
*
|
|
106
|
+
* @param matcher - A function that takes a character and returns true if it matches the condition to stop consuming.
|
|
107
|
+
*/
|
|
108
|
+
eatAllNextUntil( matcher ) {
|
|
109
|
+
let acc = '';
|
|
110
|
+
|
|
111
|
+
while ( this.index < this.text.length ) {
|
|
112
|
+
const ch = this.text[ this.index++ ];
|
|
113
|
+
|
|
114
|
+
if ( matcher( ch ) ) {
|
|
115
|
+
return acc;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
acc += ch;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return acc;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Consumes characters from the current position until a specific character is encountered.
|
|
126
|
+
* It consumes terminal character but does not include it in the result.
|
|
127
|
+
*
|
|
128
|
+
* @param char - The character to stop consuming at.
|
|
129
|
+
* @returns The consumed characters up to the specified character.
|
|
130
|
+
*/
|
|
131
|
+
eatUntilTerminal( char ) {
|
|
132
|
+
return this.eatAllNextUntil( c => c === char );
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Consumes characters from the current position until a newline character is encountered.
|
|
137
|
+
* It consumes terminal character but does not include it in the result.
|
|
138
|
+
*/
|
|
139
|
+
eatUntilEOL() {
|
|
140
|
+
return this.eatAllNextUntil( c => c === '\n' );
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Attempts to consume a quoted string (single or double quotes).
|
|
145
|
+
* Returns the content between the quotes without the quote characters.
|
|
146
|
+
* Supports escaped quotes using backslash.
|
|
147
|
+
*
|
|
148
|
+
* @returns The quoted content or null if no valid quote was found.
|
|
149
|
+
*/
|
|
150
|
+
eatQuote() {
|
|
151
|
+
const quoteChar = this.text[ this.index ];
|
|
152
|
+
|
|
153
|
+
let started = false;
|
|
154
|
+
let acc = '';
|
|
155
|
+
let escaped = false;
|
|
156
|
+
|
|
157
|
+
this.#push();
|
|
158
|
+
|
|
159
|
+
for ( ; this.index < this.text.length; ++this.index ) {
|
|
160
|
+
const ch = this.text[ this.index ];
|
|
161
|
+
|
|
162
|
+
if ( escaped ) {
|
|
163
|
+
// Handle escaped characters
|
|
164
|
+
if ( ch === quoteChar || ch === '\\' ) {
|
|
165
|
+
acc += ch;
|
|
166
|
+
} else {
|
|
167
|
+
acc += '\\' + ch;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
escaped = false;
|
|
171
|
+
} else if ( ch === '\\' ) {
|
|
172
|
+
escaped = true;
|
|
173
|
+
} else if ( ch !== quoteChar ) {
|
|
174
|
+
acc += ch;
|
|
175
|
+
} else if ( !started ) {
|
|
176
|
+
started = true;
|
|
177
|
+
} else {
|
|
178
|
+
// eat the closing quote
|
|
179
|
+
this.index++;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if ( started ) {
|
|
185
|
+
this.#pop( false );
|
|
186
|
+
return acc;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
this.#pop();
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Consumes a word (alphanumeric characters, underscore, and optionally other allowed characters).
|
|
195
|
+
*
|
|
196
|
+
* @param [whitelist=':-'] - Additional characters to allow in the word.
|
|
197
|
+
* @returns The consumed word, or empty string if no word was found.
|
|
198
|
+
*/
|
|
199
|
+
eatWord( whitelist = ':-' ) {
|
|
200
|
+
let acc = '';
|
|
201
|
+
|
|
202
|
+
this.#push();
|
|
203
|
+
|
|
204
|
+
for ( ; this.index < this.text.length; ++this.index ) {
|
|
205
|
+
const ch = this.text[ this.index ];
|
|
206
|
+
|
|
207
|
+
if ( !isWordChar( ch ) && !whitelist.includes( ch ) ) {
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
acc += ch;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
this.#pop( !acc );
|
|
215
|
+
|
|
216
|
+
return acc;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Attempts to consume Nth productions until a production is not matched.
|
|
221
|
+
*/
|
|
222
|
+
accumulateEaters( production ) {
|
|
223
|
+
const results = [];
|
|
224
|
+
|
|
225
|
+
for ( let watchdog = 0; watchdog < 1000; watchdog++ ) {
|
|
226
|
+
const result = this.try( production );
|
|
227
|
+
|
|
228
|
+
if ( result !== undefined ) {
|
|
229
|
+
results.push( result );
|
|
230
|
+
} else {
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return results;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Saves the current cursor position to the internal stack.
|
|
240
|
+
* This enables backtracking by restoring to this position later.
|
|
241
|
+
*/
|
|
242
|
+
#push() {
|
|
243
|
+
this.#_stack.push( this.index );
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Removes and optionally restores the last saved cursor position from the stack.
|
|
248
|
+
*
|
|
249
|
+
* @param [assign=true] - If true, restores the cursor to the popped position.
|
|
250
|
+
* @returns The popped position value.
|
|
251
|
+
*/
|
|
252
|
+
#pop( assign = true ) {
|
|
253
|
+
const value = this.#_stack.pop();
|
|
254
|
+
|
|
255
|
+
if ( assign ) {
|
|
256
|
+
this.index = value;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return value;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Checks if a character is a word character (alphanumeric or underscore).
|
|
265
|
+
*
|
|
266
|
+
* @param c - The character to check.
|
|
267
|
+
* @returns True if the character is a word character.
|
|
268
|
+
*/
|
|
269
|
+
function isWordChar( c ) {
|
|
270
|
+
const code = c.charCodeAt( 0 );
|
|
271
|
+
|
|
272
|
+
return (
|
|
273
|
+
( code >= 65 && code <= 90 ) || // A-Z
|
|
274
|
+
( code >= 97 && code <= 122 ) || // a-z
|
|
275
|
+
( code >= 48 && code <= 57 ) || // 0-9
|
|
276
|
+
code === 95 // _
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
module.exports = ParserCursor;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Applies a series of functions to an input value, passing the result of each function
|
|
10
|
+
* as the input to the next function.
|
|
11
|
+
*
|
|
12
|
+
* @param {*} value - The initial value to be processed by the functions.
|
|
13
|
+
* @returns {*} The final result after all functions have been applied.
|
|
14
|
+
*/
|
|
15
|
+
module.exports = function pipe( ...fns ) {
|
|
16
|
+
return value => fns.reduce( ( acc, fn ) => fn( acc ), value );
|
|
17
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const { randomId, regenerateRandomIds } = require( '../random-id' );
|
|
9
|
+
const renderPugComponent = require( './render-pug-component' );
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a template function for a Pug component with a built-in caching mechanism.
|
|
13
|
+
*
|
|
14
|
+
* This function is useful for optimizing the rendering of components that are used multiple times
|
|
15
|
+
* with minor changes in attributes. It divides attributes into three categories: `static`, `dynamic`, and `mask`,
|
|
16
|
+
* to efficiently manage caching.
|
|
17
|
+
*
|
|
18
|
+
* - `static`: Attributes that are the same for all instances of the component.
|
|
19
|
+
* They are passed to the Pug component during the first render.
|
|
20
|
+
*
|
|
21
|
+
* - `dynamic`: Attributes whose values can change and affect the component's appearance or structure.
|
|
22
|
+
* A cache key is generated based on the combination of these attribute values.
|
|
23
|
+
* A new version of the component is rendered and cached for each unique combination of these attribute values.
|
|
24
|
+
*
|
|
25
|
+
* - `mask`: Attributes whose values are unique for each call and should not be part of the cached HTML.
|
|
26
|
+
* Instead, unique identifiers (masks) are inserted into the cached template, which are replaced
|
|
27
|
+
* with the actual values after retrieving the template from the cache. This is ideal for content
|
|
28
|
+
* such as code in a code block.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const createPrerenderPugTemplate = require( './create-prerender-pug-template' );
|
|
32
|
+
*
|
|
33
|
+
* // Creates a template for the 'code-block' component.
|
|
34
|
+
* const codeBlockTemplate = createPrerenderPugTemplate( {
|
|
35
|
+
* // Attributes for `renderPugComponent`.
|
|
36
|
+
* includes: [ '_components/code-block/index' ],
|
|
37
|
+
* component: 'code-block',
|
|
38
|
+
*
|
|
39
|
+
* // Attributes for the component itself.
|
|
40
|
+
* componentAttrs: {
|
|
41
|
+
* // Static attributes are the same for every render.
|
|
42
|
+
* static: {
|
|
43
|
+
* copyable: true
|
|
44
|
+
* },
|
|
45
|
+
* // Dynamic attributes are used for caching.
|
|
46
|
+
* // A new version of the component will be rendered and cached
|
|
47
|
+
* // for each unique combination of these attribute values.
|
|
48
|
+
* dynamic: [ 'language' ],
|
|
49
|
+
* // Masked attributes are replaced after rendering (even from the cache).
|
|
50
|
+
* // They are used for unique content that should not be cached.
|
|
51
|
+
* mask: [ 'code' ]
|
|
52
|
+
* }
|
|
53
|
+
* } );
|
|
54
|
+
*
|
|
55
|
+
* // Using the template.
|
|
56
|
+
* // The first call will render the component for the 'javascript' language and cache it.
|
|
57
|
+
* const html1 = codeBlockTemplate( { language: 'javascript', code: 'console.log( "Hello" );' } );
|
|
58
|
+
*
|
|
59
|
+
* // This call will use the cached version for 'javascript'.
|
|
60
|
+
* // Only 'code' will be replaced.
|
|
61
|
+
* const html2 = codeBlockTemplate( { language: 'javascript', code: 'console.log( "World" );' } );
|
|
62
|
+
*
|
|
63
|
+
* // This will render a new version for 'html' and cache it.
|
|
64
|
+
* const html3 = codeBlockTemplate( { language: 'html', code: '<h1>Hello</h1>' } );
|
|
65
|
+
*/
|
|
66
|
+
module.exports = function createPrerenderPugTemplate( { componentAttrs, skipCacheIf, ...renderAttrs } ) {
|
|
67
|
+
const cacheStorage = new Map();
|
|
68
|
+
const maskAttrsMap = assignMaskAttrsIds( componentAttrs.mask || [] );
|
|
69
|
+
|
|
70
|
+
const allKnownAttributes = [
|
|
71
|
+
...componentAttrs.dynamic || [],
|
|
72
|
+
...Object.keys( componentAttrs.static || {} ),
|
|
73
|
+
...componentAttrs.mask || []
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
return dynamicAttrs => {
|
|
77
|
+
// Check if we should skip caching based on the provided condition.
|
|
78
|
+
const skipCache = skipCacheIf?.( dynamicAttrs );
|
|
79
|
+
|
|
80
|
+
if ( skipCache ) {
|
|
81
|
+
return renderPugComponent( {
|
|
82
|
+
...renderAttrs,
|
|
83
|
+
componentAttrs: {
|
|
84
|
+
...componentAttrs.static,
|
|
85
|
+
...dynamicAttrs
|
|
86
|
+
}
|
|
87
|
+
} );
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Check if component is already pre-rendered, if so, return cached HTML.
|
|
91
|
+
const _hasUnknownAttributes = hasUnknownAttributes( allKnownAttributes, dynamicAttrs );
|
|
92
|
+
const cacheKey = createCacheKey( componentAttrs.dynamic, dynamicAttrs );
|
|
93
|
+
|
|
94
|
+
let renderedHtml;
|
|
95
|
+
|
|
96
|
+
if ( !_hasUnknownAttributes && cacheStorage.has( cacheKey ) ) {
|
|
97
|
+
renderedHtml = cacheStorage.get( cacheKey );
|
|
98
|
+
} else {
|
|
99
|
+
renderedHtml = renderPugComponent( {
|
|
100
|
+
...renderAttrs,
|
|
101
|
+
componentAttrs: {
|
|
102
|
+
...componentAttrs.static,
|
|
103
|
+
...dynamicAttrs,
|
|
104
|
+
...maskAttrsMap
|
|
105
|
+
}
|
|
106
|
+
} );
|
|
107
|
+
|
|
108
|
+
if ( !_hasUnknownAttributes ) {
|
|
109
|
+
cacheStorage.set( cacheKey, renderedHtml );
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Regenerate random IDs in the rendered HTML to ensure uniqueness.
|
|
114
|
+
renderedHtml = regenerateRandomIds( renderedHtml );
|
|
115
|
+
|
|
116
|
+
for ( const maskKey in maskAttrsMap ) {
|
|
117
|
+
const dynamicValue = dynamicAttrs[ maskKey ] || '';
|
|
118
|
+
|
|
119
|
+
renderedHtml = renderedHtml.replace(
|
|
120
|
+
maskAttrsMap[ maskKey ],
|
|
121
|
+
dynamicValue
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return renderedHtml;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Checks if the provided component attributes contain any unknown attributes.
|
|
131
|
+
*/
|
|
132
|
+
function hasUnknownAttributes( knownAttributes, componentAttrs ) {
|
|
133
|
+
return Object.keys( componentAttrs ).some( attr => !knownAttributes.includes( attr ) );
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Creates a cache key based on the specified attributes and their values.
|
|
138
|
+
*
|
|
139
|
+
* @param cacheByAttributes An array of attribute names to be included in the cache key.
|
|
140
|
+
* @param componentAttrs An object containing component attributes and their values.
|
|
141
|
+
* @returns The generated cache key.
|
|
142
|
+
*/
|
|
143
|
+
function createCacheKey( cacheByAttributes, componentAttrs ) {
|
|
144
|
+
if ( !cacheByAttributes?.length ) {
|
|
145
|
+
return 'default';
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let acc = '';
|
|
149
|
+
|
|
150
|
+
for ( const attr of cacheByAttributes ) {
|
|
151
|
+
acc += `${ attr }-${ componentAttrs[ attr ] || 'undefined' }-`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return acc;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Creates an object that maps mask attribute names to unique random IDs.
|
|
159
|
+
*
|
|
160
|
+
* @param maskAttributes An array of attribute names that should be masked.
|
|
161
|
+
* @returns An object where keys are attribute names and values are unique mask IDs.
|
|
162
|
+
*/
|
|
163
|
+
function assignMaskAttrsIds( maskAttributes ) {
|
|
164
|
+
return maskAttributes.reduce(
|
|
165
|
+
( acc, attr ) => {
|
|
166
|
+
acc[ attr ] = randomId( 'mask', false );
|
|
167
|
+
|
|
168
|
+
return acc;
|
|
169
|
+
},
|
|
170
|
+
Object.create( {} )
|
|
171
|
+
);
|
|
172
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const path = require( 'path' );
|
|
9
|
+
const hexoManager = require( '../../../src/hexo-manager' );
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Renders a Pug component with specified includes and parameters.
|
|
13
|
+
*
|
|
14
|
+
* @param options - The rendering options.
|
|
15
|
+
* @param options.hexo - The Hexo instance.
|
|
16
|
+
* @param options.mixinContextVars - Context variables to be passed to the Pug mixin.
|
|
17
|
+
* @param [options.requires=[]] - Array of Pug includes to be added at the top of the template.
|
|
18
|
+
* @param options.component - The name of the component to render (without the + prefix).
|
|
19
|
+
* @param [options.componentAttrs={}] - Attributes to pass to the component.
|
|
20
|
+
* @param [options.basePath] - Base path for the component. Defaults to theme components directory.
|
|
21
|
+
* @returns The rendered HTML.
|
|
22
|
+
*/
|
|
23
|
+
module.exports = function renderPugComponent(
|
|
24
|
+
{
|
|
25
|
+
hexo,
|
|
26
|
+
mixinContextVars = {},
|
|
27
|
+
requires = [],
|
|
28
|
+
component,
|
|
29
|
+
componentAttrs = {},
|
|
30
|
+
basePath
|
|
31
|
+
}
|
|
32
|
+
) {
|
|
33
|
+
const { children, ...restComponentAttrs } = componentAttrs || {};
|
|
34
|
+
|
|
35
|
+
// Default base path is the components directory in the theme
|
|
36
|
+
// Handle case where hexo.theme_dir might be undefined
|
|
37
|
+
const resolvedHexo = hexo || hexoManager.hexo;
|
|
38
|
+
const themeDir = resolvedHexo && resolvedHexo.theme_dir || path.join( __dirname, '../../themes/umberto' );
|
|
39
|
+
const componentsPath = basePath || path.join( themeDir, 'layout', 'gloria', '_components' );
|
|
40
|
+
|
|
41
|
+
// Prepare includes statements
|
|
42
|
+
const includeStatements = requires.map( include => `include ${ include }` );
|
|
43
|
+
|
|
44
|
+
// Prepare the component call with its attributes
|
|
45
|
+
const componentCall = `+${ component }(${ JSON.stringify( restComponentAttrs ) })`;
|
|
46
|
+
|
|
47
|
+
// Complete content to be rendered
|
|
48
|
+
const content = [
|
|
49
|
+
...includeStatements,
|
|
50
|
+
componentCall,
|
|
51
|
+
children
|
|
52
|
+
]
|
|
53
|
+
.filter( Boolean )
|
|
54
|
+
.join( '\n' );
|
|
55
|
+
|
|
56
|
+
// Prepare locals for rendering
|
|
57
|
+
const locals = Object.assign(
|
|
58
|
+
{},
|
|
59
|
+
resolvedHexo.locals.toObject(),
|
|
60
|
+
resolvedHexo.extend.helper.list(),
|
|
61
|
+
{
|
|
62
|
+
...mixinContextVars,
|
|
63
|
+
config: resolvedHexo.config
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Render and return the component
|
|
68
|
+
return resolvedHexo.render.renderSync( {
|
|
69
|
+
text: content,
|
|
70
|
+
engine: 'pug',
|
|
71
|
+
path: componentsPath
|
|
72
|
+
}, locals );
|
|
73
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Symbols used to control tree walking behavior in leave callbacks
|
|
10
|
+
*/
|
|
11
|
+
const TREE_WALK_SYMBOLS = {
|
|
12
|
+
REMOVE: Symbol( 'REMOVE' ),
|
|
13
|
+
REPLACE: Symbol( 'REPLACE' ),
|
|
14
|
+
KEEP: Symbol( 'KEEP' ),
|
|
15
|
+
ABORT: Symbol( 'ABORT' )
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Walks through a tree structure, calling enter and leave callbacks for each node.
|
|
20
|
+
* The leave callback can return an object with a symbol to control the node's fate:
|
|
21
|
+
* - { symbol: TREE_WALK_SYMBOLS.REMOVE } - removes the node
|
|
22
|
+
* - { symbol: TREE_WALK_SYMBOLS.REPLACE, value: newNode } - replaces the node
|
|
23
|
+
* - { symbol: TREE_WALK_SYMBOLS.KEEP } or undefined - keeps the node unchanged
|
|
24
|
+
*
|
|
25
|
+
* @param tree - The tree or node to walk through
|
|
26
|
+
* @param options - Walking options
|
|
27
|
+
* @param [options.enter] - Callback called when entering a node (node, depth, parents)
|
|
28
|
+
* @param [options.leave] - Callback called when leaving a node (node, depth, parents)
|
|
29
|
+
* @param [depth=0] - Current depth (used internally for recursion)
|
|
30
|
+
* @param [parents=[]] - Array of parent nodes (used internally for recursion)
|
|
31
|
+
* @returns The potentially modified tree
|
|
32
|
+
*/
|
|
33
|
+
function walkXMLTree( tree, options = {}, depth = 0, parents = [] ) {
|
|
34
|
+
const { enter, leave } = options;
|
|
35
|
+
|
|
36
|
+
// Handle array of nodes
|
|
37
|
+
if ( Array.isArray( tree ) ) {
|
|
38
|
+
const result = [];
|
|
39
|
+
|
|
40
|
+
for ( let i = 0; i < tree.length; i++ ) {
|
|
41
|
+
const processedNode = walkXMLTree( tree[ i ], options, depth, parents );
|
|
42
|
+
|
|
43
|
+
if ( Array.isArray( processedNode ) ) {
|
|
44
|
+
result.push( ...processedNode );
|
|
45
|
+
} else if ( processedNode !== undefined ) {
|
|
46
|
+
result.push( processedNode );
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if ( enter ) {
|
|
54
|
+
const enterResult = enter( tree, depth, parents );
|
|
55
|
+
const processedResult = processCallbackResult( enterResult, tree );
|
|
56
|
+
|
|
57
|
+
if ( processedResult === Symbol.for( 'ABORT_WALK' ) ) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if ( processedResult !== tree ) {
|
|
62
|
+
return processedResult;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Create a working copy of the node to potentially modify
|
|
67
|
+
let workingNode = tree;
|
|
68
|
+
|
|
69
|
+
// Recursively walk children if they exist
|
|
70
|
+
if ( tree.children && Array.isArray( tree.children ) ) {
|
|
71
|
+
const modifiedChildren = walkXMLTree( tree.children, options, depth + 1, [ ...parents, tree ] );
|
|
72
|
+
|
|
73
|
+
// Only create a new node if children were actually modified
|
|
74
|
+
if ( modifiedChildren !== tree.children ) {
|
|
75
|
+
workingNode = { ...tree, children: modifiedChildren };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Call leave callback
|
|
80
|
+
if ( leave ) {
|
|
81
|
+
const leaveResult = leave( workingNode, depth, parents );
|
|
82
|
+
|
|
83
|
+
return processCallbackResult( leaveResult, workingNode );
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return workingNode;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Processes a callback result and returns the appropriate action.
|
|
91
|
+
*
|
|
92
|
+
* @param result - The result from enter/leave callback
|
|
93
|
+
* @param defaultValue - Value to return if no action is taken
|
|
94
|
+
* @returns The processed result
|
|
95
|
+
*/
|
|
96
|
+
function processCallbackResult( result, defaultValue ) {
|
|
97
|
+
if ( result && typeof result === 'object' && result.symbol ) {
|
|
98
|
+
switch ( result.symbol ) {
|
|
99
|
+
case TREE_WALK_SYMBOLS.KEEP:
|
|
100
|
+
return defaultValue;
|
|
101
|
+
|
|
102
|
+
case TREE_WALK_SYMBOLS.REMOVE:
|
|
103
|
+
return undefined;
|
|
104
|
+
|
|
105
|
+
case TREE_WALK_SYMBOLS.REPLACE:
|
|
106
|
+
return result.value;
|
|
107
|
+
|
|
108
|
+
case TREE_WALK_SYMBOLS.ABORT:
|
|
109
|
+
return Symbol.for( 'ABORT_WALK' );
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return defaultValue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Helper functions for tree walking control
|
|
118
|
+
*/
|
|
119
|
+
const TreeWalkActions = {
|
|
120
|
+
/**
|
|
121
|
+
* Creates an action to remove the current node.
|
|
122
|
+
*
|
|
123
|
+
* @returns Control object for node removal
|
|
124
|
+
*/
|
|
125
|
+
remove() {
|
|
126
|
+
return { symbol: TREE_WALK_SYMBOLS.REMOVE };
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Creates an action to replace the current node with a new value.
|
|
131
|
+
*
|
|
132
|
+
* @param value - The new value to replace the node with
|
|
133
|
+
* @returns Control object for node replacement
|
|
134
|
+
*/
|
|
135
|
+
replace( value ) {
|
|
136
|
+
return { symbol: TREE_WALK_SYMBOLS.REPLACE, value };
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Creates an action to keep the current node unchanged.
|
|
141
|
+
*
|
|
142
|
+
* @returns Control object for keeping the node
|
|
143
|
+
*/
|
|
144
|
+
keep() {
|
|
145
|
+
return { symbol: TREE_WALK_SYMBOLS.KEEP };
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
exports.walkXMLTree = walkXMLTree;
|
|
150
|
+
exports.TreeWalkActions = TreeWalkActions;
|