diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-03-04 21:10:24 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-04 21:10:24 +0000 |
| commit | 7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b (patch) | |
| tree | 80a47f0dc40059014e9448c4c2eb34c54dff45fe | |
| parent | 1c5db277e4161470136dbd2a11e914ff1d383581 (diff) | |
| parent | 98c5490d94950608d31cd5ad9dd260f2f853735c (diff) | |
Merge #694
694: RTIC 2 r=AfoHT a=korken89
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Co-authored-by: Per Lindgren <per.lindgren@ltu.se>
387 files changed, 12456 insertions, 8514 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5e1467c..300bea5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,22 +11,28 @@ on: env: CARGO_TERM_COLOR: always + DEV_VERSION: 2 + STABLE_VERSION: 1 + OLDSTABLE_VERSION: 0.5 + OLDOLDSTABLE_VERSION: 0.4 jobs: - # Run cargo fmt --check, includes macros/ - style: - name: style + # Run cargo xtask format-check + formatcheck: + name: cargo fmt runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 - name: Fail on warnings - run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs macros/src/lib.rs + run: find . -type f -name lib.rs -execdir sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' {} + + - name: Cache Dependencies + uses: Swatinem/rust-cache@v2 - - name: cargo fmt --check - run: cargo fmt --all -- --check + - name: cargo xtask format-check + run: cargo xtask format-check # Compilation check check: @@ -34,98 +40,125 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - target: - - thumbv7m-none-eabi - - thumbv6m-none-eabi - - x86_64-unknown-linux-gnu + backend: + - thumbv7 + - thumbv6 + - thumbv8-base + - thumbv8-main toolchain: - - stable + - nightly steps: - name: Checkout uses: actions/checkout@v3 - name: Install Rust ${{ matrix.toolchain }} run: | - rustup set profile minimal rustup override set ${{ matrix.toolchain }} - - name: Configure Rust target (${{ matrix.target }}) - run: rustup target add ${{ matrix.target }} + - name: Configure Rust target (v6, v7, v8.b v8.m) + run: | + rustup target add thumbv7m-none-eabi + rustup target add thumbv6m-none-eabi + rustup target add thumbv8m.base-none-eabi + rustup target add thumbv8m.main-none-eabi - name: Fail on warnings - run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs macros/src/lib.rs + run: find . -type f -name lib.rs -execdir sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' {} + - name: Cache Dependencies uses: Swatinem/rust-cache@v2 - - name: cargo check - run: cargo check --target=${{ matrix.target }} + - run: cargo xtask --verbose --backend ${{ matrix.backend }} check # Clippy clippy: - name: Cargo clippy + name: clippy runs-on: ubuntu-22.04 + strategy: + matrix: + backend: + - thumbv7 + - thumbv6 + - thumbv8-base + - thumbv8-main + toolchain: + - nightly steps: - name: Checkout uses: actions/checkout@v3 - - name: Fail on warnings - run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs macros/src/lib.rs + - name: Install Rust ${{ matrix.toolchain }} + run: | + rustup override set ${{ matrix.toolchain }} + + - name: Configure Rust target (v6, v7, v8.b v8.m) + run: | + rustup target add thumbv7m-none-eabi + rustup target add thumbv6m-none-eabi + rustup target add thumbv8m.base-none-eabi + rustup target add thumbv8m.main-none-eabi - name: Add Rust component clippy run: rustup component add clippy + - name: Fail on warnings + run: find . -type f -name lib.rs -execdir sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' {} + + - name: Cache Dependencies uses: Swatinem/rust-cache@v2 - - name: cargo clippy - run: cargo clippy + - run: cargo xtask --verbose --backend ${{ matrix.backend }} clippy # Verify all examples, checks checkexamples: - name: checkexamples + name: check examples runs-on: ubuntu-22.04 strategy: matrix: - target: - - thumbv7m-none-eabi - - thumbv6m-none-eabi - - thumbv8m.base-none-eabi - - thumbv8m.main-none-eabi + backend: + - thumbv7 + - thumbv6 + - thumbv8-base + - thumbv8-main toolchain: - - stable + - nightly steps: - name: Checkout uses: actions/checkout@v3 - name: Install Rust ${{ matrix.toolchain }} run: | - rustup set profile minimal rustup override set ${{ matrix.toolchain }} - - name: Configure Rust target (${{ matrix.target }}) - run: rustup target add ${{ matrix.target }} - - - name: Add Rust component llvm-tools-preview - run: rustup component add llvm-tools-preview + - name: Configure Rust target (v6, v7, v8.b v8.m) + run: | + rustup target add thumbv7m-none-eabi + rustup target add thumbv6m-none-eabi + rustup target add thumbv8m.base-none-eabi + rustup target add thumbv8m.main-none-eabi - name: Cache Dependencies uses: Swatinem/rust-cache@v2 - name: Check the examples - run: cargo check --examples --target=${{ matrix.target }} + if: ${{ matrix.backend == 'thumbv8-base' }} + run: cargo xtask --verbose --backend ${{ matrix.backend }} --exampleexclude pool example-check + + - name: Check the examples + if: ${{ matrix.backend != 'thumbv8-base' }} + run: cargo xtask --verbose --backend ${{ matrix.backend }} example-check # Verify the example output with run-pass tests testexamples: - name: testexamples + name: QEMU run runs-on: ubuntu-22.04 strategy: matrix: - target: - - thumbv7m-none-eabi - - thumbv6m-none-eabi + backend: + - thumbv7 + - thumbv6 toolchain: - - stable + - nightly steps: - name: Checkout uses: actions/checkout@v3 @@ -135,15 +168,19 @@ jobs: rustup set profile minimal rustup override set ${{ matrix.toolchain }} - - name: Configure Rust target (${{ matrix.target }}) - run: rustup target add ${{ matrix.target }} + - name: Configure Rust target (v6, v7) + run: | + rustup target add thumbv7m-none-eabi + rustup target add thumbv6m-none-eabi - name: Add Rust component llvm-tools-preview run: rustup component add llvm-tools-preview # Use precompiled binutils - - name: cargo install cargo-binutils - run: cargo install cargo-binutils + - name: Install cargo-binutils + uses: taiki-e/install-action@v2 + with: + tool: cargo-binutils - name: Cache Dependencies uses: Swatinem/rust-cache@v2 @@ -154,46 +191,32 @@ jobs: sudo apt install -y qemu-system-arm - name: Fail on warnings - run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs macros/src/lib.rs + working-directory: ./rtic + run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs - name: Run-pass tests - run: cargo xtask --target ${{ matrix.target }} + run: cargo xtask --verbose --backend ${{ matrix.backend }} qemu - # Check the correctness of macros/ crate - checkmacros: - name: checkmacros + # Run test suite + tests: + name: tests runs-on: ubuntu-22.04 strategy: + fail-fast: false matrix: - target: - - x86_64-unknown-linux-gnu - toolchain: - - stable - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install Rust ${{ matrix.toolchain }} - run: | - rustup set profile minimal - rustup override set ${{ matrix.toolchain }} + backend: + - thumbv7 + - thumbv6 + - thumbv8-base + - thumbv8-main + package: + - rtic + - rtic-common + - rtic-macros + - rtic-monotonics + - rtic-sync + - rtic-time - - name: Configure Rust target (${{ matrix.target }}) - run: rustup target add ${{ matrix.target }} - - - name: Cache Dependencies - uses: Swatinem/rust-cache@v2 - - - name: Fail on warnings - run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs macros/src/lib.rs - - - name: cargo check - run: cargo check --manifest-path macros/Cargo.toml --target=${{ matrix.target }} - - # Run the macros test-suite - testmacros: - name: testmacros - runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 @@ -201,139 +224,201 @@ jobs: - name: Cache Dependencies uses: Swatinem/rust-cache@v2 - - name: Fail on warnings - run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs macros/src/lib.rs - - - name: cargo check - run: cargo test --manifest-path macros/Cargo.toml - - # Run test suite - tests: - name: tests - runs-on: ubuntu-22.04 - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Cache Dependencies - uses: Swatinem/rust-cache@v2 + - name: Configure Rust target (v6, v7, v8.b v8.m) + run: | + rustup target add thumbv7m-none-eabi + rustup target add thumbv6m-none-eabi + rustup target add thumbv8m.base-none-eabi + rustup target add thumbv8m.main-none-eabi - name: Fail on warnings - run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs macros/src/lib.rs + run: find . -type f -name lib.rs -execdir sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' {} + - name: Run cargo test - run: cargo test --test tests + run: cargo xtask --verbose --backend ${{ matrix.backend }} test ${{ matrix.package }} # Build documentation, check links docs: - name: docs + name: build docs runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 - - name: Cache pip installed linkchecker - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip - restore-keys: | - ${{ runner.os }}-pip- - - - name: Set up Python 3.x - uses: actions/setup-python@v4 + - name: Install lychee + uses: taiki-e/install-action@v2 with: - # Semantic version range syntax or exact version of a Python version - python-version: '3.x' - - # You can test your matrix by printing the current Python version - - name: Display Python version - run: python -c "import sys; print(sys.version)" - - - name: Install dependencies - run: pip install git+https://github.com/linkchecker/linkchecker.git + tool: lychee - name: Remove cargo-config run: rm -f .cargo/config - - name: Fail on warnings - run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs macros/src/lib.rs - - name: Build docs - run: cargo doc + # TODO: Any difference between backends? + run: cargo doc --features thumbv7-backend - name: Check links run: | td=$(mktemp -d) cp -r target/doc $td/api - linkchecker $td/api/rtic/ - linkchecker $td/api/cortex_m_rtic_macros/ + echo rtic + lychee --offline --format detailed $td/api/rtic/ + + echo rtic_common + lychee --offline --format detailed $td/api/rtic_common/ + + echo rtic_macros + lychee --offline --format detailed $td/api/rtic_macros/ + + echo rtic_monotonics + lychee --offline --format detailed $td/api/rtic_monotonics/ + + echo rtic_sync + lychee --offline --format detailed $td/api/rtic_sync/ + + echo rtic_time + lychee --offline --format detailed $td/api/rtic_time/ + + + - name: Archive the API docs + run: | + cp -r target/doc apidocs + tar -cf apidocs.tar apidocs + + - name: Store the API docs + uses: actions/upload-artifact@v3 + with: + name: apidocs + path: apidocs.tar # Build the books mdbook: - name: mdbook + name: build mdbook + needs: docs runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 - - name: Set up Python 3.x - uses: actions/setup-python@v4 - with: - # Semantic version range syntax or exact version of a Python version - python-version: '3.x' - # You can test your matrix by printing the current Python version - - name: Display Python version - run: python -c "import sys; print(sys.version)" + - name: Install lychee + uses: taiki-e/install-action@v2 + with: + tool: lychee - - name: Install dependencies - run: pip install git+https://github.com/linkchecker/linkchecker.git + - name: Install mdbook + uses: taiki-e/install-action@v2 + with: + tool: mdbook - - name: mdBook Action - uses: peaceiris/actions-mdbook@v1 + - name: Install mdbook-mermaid + uses: taiki-e/install-action@v2 with: - mdbook-version: 'latest' + tool: mdbook-mermaid - name: Build book in English - shell: 'script --return --quiet --command "bash {0}"' - run: cd book/en && if mdbook build |& tee /dev/tty | grep "\[ERROR\]"; then exit 1; else exit 0; fi + run: cargo xtask book - - name: Build book in Russian - shell: 'script --return --quiet --command "bash {0}"' - run: cd book/ru && if mdbook build |& tee /dev/tty | grep "\[ERROR\]"; then echo "Russian book needs updating!"; else exit 0; fi + - name: Download built API docs + uses: actions/download-artifact@v3 + with: + name: apidocs + + - name: Extract the API docs + run: tar -xf apidocs.tar - name: Check links run: | td=$(mktemp -d) mkdir $td/book cp -r book/en/book $td/book/en - cp -r book/ru/book $td/book/ru cp LICENSE-* $td/book/en - cp LICENSE-* $td/book/ru + cp -r apidocs/ $td/api - linkchecker $td/book/en/ - linkchecker $td/book/ru/ + lychee --offline --format detailed $td/book/en/ + mv $td bookroot - # Update stable branch - # - # This needs to run before book is built - mergetostablebranch: - name: If CI passes, merge master branch into release/vX + - name: Archive the book + API docs + run: | + tar -cf book.tar bookroot + + - name: Store the Book + API docs + uses: actions/upload-artifact@v3 + with: + name: book + path: book.tar + + mdbookold: + name: build docs and mdbook for older releases + needs: mergetostablebranch runs-on: ubuntu-22.04 - needs: - - style - - check - - clippy - - checkexamples - - testexamples - - checkmacros - - testmacros - - tests - - docs - - mdbook + steps: + - name: Checkout + uses: actions/checkout@v3 - # Only run this when pushing to master branch - if: github.ref == 'refs/heads/master' + - name: Install mdbook + uses: taiki-e/install-action@v2 + with: + tool: mdbook + + - name: Install mdbook-mermaid + uses: taiki-e/install-action@v2 + with: + tool: mdbook-mermaid + + - name: Remove cargo-config + run: rm -f .cargo/config + + - name: Prepare output folder + run: mkdir -p mdbookold + + - name: Fetch and build books for older versions + run: | + # The latest stable must be the first element in the array + vers=( "${{ env.STABLE_VERSION }}" "${{ env.OLDSTABLE_VERSION }}" ) + langs=( en ) + root=$(pwd) + webroot=$(pwd)/mdbookold + + for ver in ${vers[@]}; do + + mkdir -p src/$ver + src=$root/src/$ver + curl -L https://github.com/rtic-rs/rtic/archive/release/v${ver}.tar.gz | tar xz --strip-components 1 -C $src + + pushd $src + rm -f .cargo/config + cargo doc || cargo doc --features timer-queue + mkdir -p $webroot/$ver/book + cp -r target/doc $webroot/$ver/api + + sed 's|URL|rtic/index.html|g' $root/redirect.html > $webroot/$ver/api/index.html + popd + + for lang in ${langs[@]}; do + cargo xtask book build $src/book/$lang + + cp -r $src/book/$lang/book $webroot/$ver/book/$lang + cp LICENSE-* $webroot/$ver/book/$lang/ + done + # using master branch redirect file + sed 's|URL|book/en|g' $root/redirect.html > $webroot/$ver/index.html + + rm -rf $src + done + + - name: Archive the old books + run: | + tar -cf mdbookold.tar mdbookold + + - name: Store the old API docs + uses: actions/upload-artifact@v3 + with: + name: mdbookold + path: mdbookold.tar + + parseversion: + name: Parse the master branch RTIC version + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 @@ -341,18 +426,37 @@ jobs: id: crateversionbranch # Parse metadata for version number, extract the Semver Major run: | - VERSION=$(cargo metadata --format-version 1 --no-deps --offline | jq -r '.packages[] | select(.name =="cortex-m-rtic") | .version') + VERSION=$(cargo metadata --format-version 1 --no-deps --offline | jq -r '.packages[] | select(.name =="rtic") | .version') VERSIONMAJOR=${VERSION%.*.*} echo "branch=release/v$VERSIONMAJOR" >> $GITHUB_ENV echo "versionmajor=$VERSIONMAJOR" >> $GITHUB_ENV echo "version=$VERSION" >> $GITHUB_ENV - - uses: everlytic/branch-merge@1.1.5 - with: - github_token: ${{ github.token }} - source_ref: 'master' - target_branch: ${{ env.branch }} - commit_message_template: '[Bors] Merged {source_ref} into target {target_branch}' + + # Update stable branch + # + # This is only valid when current stable resides in + # master branch. + # As master moves on to development, the work on the + # stable version will happen in release/v"stable_version". + # Thus, no need to push changes + # + # This needs to run before book is built, as bookbuilding fetches from the branch + mergetostablebranch: + name: Merge branch into release/vX when pushing to master + runs-on: ubuntu-22.04 + needs: + - ci-success + - parseversion + + # Only run this when pushing to master branch + if: github.ref == 'refs/heads/master' + steps: + - uses: actions/checkout@v3 + + - name: Push to stable release branch if master contains stable version + if: ${{ env.versionmajor == env.STABLE_VERSION }} + run: git push -u origin ${{ env.branch }} # Only runs when pushing to master branch # Bors run CI against staging branch, @@ -362,65 +466,73 @@ jobs: name: deploy runs-on: ubuntu-22.04 needs: - mergetostablebranch + - mergetostablebranch + - docs + - mdbookold + - mdbook # Only run this when pushing to master branch if: github.ref == 'refs/heads/master' steps: - uses: actions/checkout@v3 - - name: Set up Python 3.x - uses: actions/setup-python@v4 + - name: Install lychee + uses: taiki-e/install-action@v2 with: - # Semantic version range syntax or exact version of a Python version - python-version: '3.x' - - # You can test your matrix by printing the current Python version - - name: Display Python version - run: python -c "import sys; print(sys.version)" + tool: lychee + - name: Install mdbook-mermaid + uses: taiki-e/install-action@v2 + with: + tool: mdbook-mermaid + - name: mdBook Action uses: peaceiris/actions-mdbook@v1 with: mdbook-version: 'latest' - - name: Get crate version - id: crateversion - # Parse metadata for version number, extract the Semver Major - run: | - VERSION=$(cargo metadata --format-version 1 --no-deps --offline | jq -r '.packages[] | select(.name =="cortex-m-rtic") | .version') - VERSIONMAJOR=${VERSION%.*.*} - echo "branch=release/v$VERSIONMAJOR" >> $GITHUB_ENV - echo "versionmajor=$VERSIONMAJOR" >> $GITHUB_ENV - echo "version=$VERSION" >> $GITHUB_ENV - - name: Remove cargo-config run: rm -f .cargo/config - - name: Build docs - run: cargo doc + - name: Download built dev-ver book and API docs + uses: actions/download-artifact@v3 + with: + name: book + + - name: Extract the dev-version book and API docs + run: | + tar -xf book.tar + + - name: Download built old versions of books and API docs + uses: actions/download-artifact@v3 + with: + name: mdbookold - - name: Build books + - name: Extract the old version books and API docs + run: | + tar -xf mdbookold.tar + + - name: Prepare books shell: 'script --return --quiet --command "bash {0}"' run: | - langs=( en ru ) + langs=( en ) devver=( dev ) # The latest stable must be the first element in the array - vers=( "1" "0.5" "0.4" ) + vers=( "${{ env.STABLE_VERSION }}" "${{ env.OLDSTABLE_VERSION }}" ) # All releases start with "v" # followed by MAJOR.MINOR.PATCH, see semver.org # Store first in array as stable stable=${vers} - crateversion={{ env.versionmajor }} + crateversion=${{ env.versionmajor }} echo "Latest stable version: $stable" echo "Current crate version: $crateversion" # Create directories td=$(mktemp -d) - mkdir -p $td/$devver/book/ - cp -r target/doc $td/$devver/api + mkdir -p $td/$devver/ + cp -r bookroot/* $td/$devver/ # Redirect rtic.rs/meeting/index.html to hackmd mkdir $td/meeting @@ -441,53 +553,50 @@ jobs: else # If the current stable and the "dev" version in master branch # share the same major version, redirect dev/ to stable book + # This makes sense, preferable to have doc/book updates going live directly to rtic.rs sed 's|URL|rtic.rs/$stable/api/rtic|g' redirect.html > $td/$devver/api/index.html sed 's|URL|rtic.rs/$stable|g' redirect.html > $td/$devver/index.html fi - # Build books - for lang in ${langs[@]}; do - ( cd book/$lang && - if mdbook build |& tee /dev/tty | grep "\[ERROR\]"; then exit 1; else exit 0; fi - ) - cp -r book/$lang/book $td/$devver/book/$lang - cp LICENSE-* $td/$devver/book/$lang/ - done - - # Build older versions, including stable - root=$(pwd) - for ver in ${vers[@]}; do - prefix=${ver} - - mkdir -p $td/$prefix/book - src=$(mktemp -d) - curl -L https://github.com/rtic-rs/cortex-m-rtic/archive/release/v${ver}.tar.gz | tar xz --strip-components 1 -C $src - - pushd $src - rm -f .cargo/config - cargo doc || cargo doc --features timer-queue - cp -r target/doc $td/$prefix/api - sed 's|URL|rtic/index.html|g' $root/redirect.html > $td/$prefix/api/index.html - for lang in ${langs[@]}; do - ( cd book/$lang && - if mdbook build |& tee /dev/tty | grep "\[ERROR\]"; then exit 1; else exit 0; fi - ) - cp -r book/$lang/book $td/$prefix/book/$lang - cp LICENSE-* $td/$prefix/book/$lang/ - done - sed 's|URL|book/en|g' $root/redirect.html > $td/$prefix/index.html - popd - - rm -rf $src - done + # Package older versions, including stable # Copy the stable book to the stable alias - cp -r $td/$stable $td/stable + cp -r mdbookold/${{ env.STABLE_VERSION }} $td/stable + + # Copy the stable book to the webroot + cp -r mdbookold/${{ env.STABLE_VERSION }} $td/ + # Copy the old stable book to the webroot + cp -r mdbookold/${{ env.OLDSTABLE_VERSION }} $td/ # Forward CNAME file cp CNAME $td/ mv $td/ bookstodeploy + - name: Archive the webroot + run: | + tar -cf bookstodeploy.tar bookstodeploy + + - name: Store the books + uses: actions/upload-artifact@v3 + with: + name: bookstodeploy + path: bookstodeploy.tar + + ghapages: + name: Publish rtic.rs + runs-on: ubuntu-22.04 + needs: + - deploy + steps: + - name: Download books + uses: actions/download-artifact@v3 + with: + name: bookstodeploy + + - name: Extract the books + run: | + tar -xf bookstodeploy.tar + - name: Deploy to GH-pages uses: peaceiris/actions-gh-pages@v3 with: @@ -503,13 +612,11 @@ jobs: name: ci if: github.event_name == 'push' && success() needs: - - style + - formatcheck - check - clippy - checkexamples - testexamples - - checkmacros - - testmacros - tests - docs - mdbook diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 74b821d..0eb4cf6 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -18,11 +18,56 @@ jobs: - name: Checkout sources uses: actions/checkout@v3 - - name: Check that changelog updated + - name: Check which component is modified + uses: dorny/paths-filter@v2 + id: changes + with: + filters: | + rtic: + - 'rtic/**' + rtic-channel: + - 'rtic-channel/**' + rtic-time: + - 'rtic-time/**' + rtic-monotonics: + - 'rtic-monotonics/**' + + - name: Check that changelog updated (rtic) + if: steps.changes.outputs.rtic == 'true' + uses: dangoslen/changelog-enforcer@v3 + with: + changeLogPath: ./rtic/CHANGELOG.md + skipLabels: 'needs-changelog, skip-changelog' + missingUpdateErrorMessage: 'Please add a changelog entry in the rtic/CHANGELOG.md file.' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check that changelog updated (rtic-channel) + if: steps.changes.outputs.rtic-channel == 'true' + uses: dangoslen/changelog-enforcer@v3 + with: + changeLogPath: ./rtic-channel/CHANGELOG.md + skipLabels: 'needs-changelog, skip-changelog' + missingUpdateErrorMessage: 'Please add a changelog entry in the rtic-channel/CHANGELOG.md file.' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check that changelog updated (rtic-time) + if: steps.changes.outputs.rtic-time == 'true' + uses: dangoslen/changelog-enforcer@v3 + with: + changeLogPath: ./rtic-time/CHANGELOG.md + skipLabels: 'needs-changelog, skip-changelog' + missingUpdateErrorMessage: 'Please add a changelog entry in the rtic-time/CHANGELOG.md file.' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check that changelog updated (rtic-monotonics) + if: steps.changes.outputs.rtic-monotonics == 'true' uses: dangoslen/changelog-enforcer@v3 with: - changeLogPath: CHANGELOG.md + changeLogPath: ./rtic-monotonics/CHANGELOG.md skipLabels: 'needs-changelog, skip-changelog' - missingUpdateErrorMessage: 'Please add a changelog entry in the CHANGELOG.md file.' + missingUpdateErrorMessage: 'Please add a changelog entry in the rtic-monotonics/CHANGELOG.md file.' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file diff --git a/.github/workflows/matrix-bot.yml b/.github/workflows/matrix-bot.yml index 6ef6787..bc985d9 100644 --- a/.github/workflows/matrix-bot.yml +++ b/.github/workflows/matrix-bot.yml @@ -5,7 +5,7 @@ on: jobs: new-pr: - if: github.event.action == 'opened' && github.repository == 'rtic-rs/cortex-m-rtic' + if: github.event.action == 'opened' && github.repository == 'rtic-rs/rtic' runs-on: ubuntu-latest continue-on-error: true steps: @@ -18,7 +18,7 @@ jobs: server: "matrix.org" merged-pr: - if: github.event.action == 'closed' && github.event.pull_request.merged == true && github.repository == 'rtic-rs/cortex-m-rtic' + if: github.event.action == 'closed' && github.event.pull_request.merged == true && github.repository == 'rtic-rs/rtic' runs-on: ubuntu-latest continue-on-error: true steps: @@ -31,7 +31,7 @@ jobs: server: "matrix.org" abandoned-pr: - if: github.event.action == 'closed' && github.event.pull_request.merged == false && github.repository == 'rtic-rs/cortex-m-rtic' + if: github.event.action == 'closed' && github.event.pull_request.merged == false && github.repository == 'rtic-rs/rtic' runs-on: ubuntu-latest continue-on-error: true steps: @@ -1,57 +1,18 @@ -[package] -authors = [ - "The Real-Time Interrupt-driven Concurrency developers", - "Jorge Aparicio <jorge@japaric.io>", - "Per Lindgren <per.lindgren@ltu.se>", +[workspace] +members = [ + "rtic", + "rtic-sync", + "rtic-common", + "rtic-macros", + "rtic-monotonics", + "rtic-time", + "xtask", ] -categories = ["concurrency", "embedded", "no-std"] -description = "Real-Time Interrupt-driven Concurrency (RTIC): a concurrency framework for building real-time systems" -documentation = "https://rtic.rs/" -edition = "2021" -keywords = ["arm", "cortex-m"] -license = "MIT OR Apache-2.0" -name = "cortex-m-rtic" -readme = "README.md" -repository = "https://github.com/rtic-rs/cortex-m-rtic" - -version = "1.1.4" - -[lib] -name = "rtic" - -[dependencies] -cortex-m = "0.7.0" -cortex-m-rtic-macros = { path = "macros", version = "1.1.6" } -rtic-monotonic = "1.0.0" -rtic-core = "1.0.0" -heapless = "0.7.7" -bare-metal = "1.0.0" - -[build-dependencies] -version_check = "0.9" - -[dev-dependencies] -lm3s6965 = "0.1.3" -cortex-m-semihosting = "0.5.0" -systick-monotonic = "1.0.0" - -[dev-dependencies.panic-semihosting] -features = ["exit"] -version = "0.6.0" - -[target.x86_64-unknown-linux-gnu.dev-dependencies] -trybuild = "1" [profile.release] codegen-units = 1 lto = true -[workspace] -members = [ - "macros", - "xtask", -] - # do not optimize proc-macro deps or build scripts [profile.dev.build-override] codegen-units = 16 @@ -70,10 +31,3 @@ overflow-checks = false [patch.crates-io] lm3s6965 = { git = "https://github.com/japaric/lm3s6965" } - -[features] -test-critical-section = ["cortex-m/critical-section-single-core"] - -[[example]] -name = "pool" -required-features = ["test-critical-section"] @@ -1,11 +1,11 @@ # Real-Time Interrupt-driven Concurrency -A concurrency framework for building real-time systems. +> The hardware accelerated Rust RTOS -Formerly known as Real-Time For the Masses. +A concurrency framework for building real-time systems. -[](https://crates.io/crates/cortex-m-rtic) -[](https://docs.rs/cortex-m-rtic) +[](https://crates.io/crates/rtic) +[](https://docs.rs/rtic) [](https://rtic.rs/) [](https://matrix.to/#/#rtic:matrix.org) [](https://hackmd.io/@xmis9JvZT8Gvo9lOEKyZ4Q/SkBJKsjuH) @@ -24,7 +24,7 @@ Formerly known as Real-Time For the Masses. - Support for prioritization of tasks and, thus, **preemptive multitasking**. -- **Efficient and data race free memory sharing** through fine grained *priority +- **Efficient and data race free memory sharing** through fine-grained *priority based* critical sections [^1]. - **Deadlock free execution** guaranteed at compile time. This is a stronger @@ -44,16 +44,6 @@ Formerly known as Real-Time For the Masses. - This task model is amenable to known WCET (Worst Case Execution Time) analysis and scheduling analysis techniques. -### Crate `cortex-m` 0.6 vs 0.7 in RTIC 0.5.x - -The crate `cortex-m` 0.7 started using trait `InterruptNumber` for interrupts instead of `Nr` from `bare-metal`. In order to preserve backwards compatibility, RTIC 0.5.x will keep using `cortex-m` 0.6 by default. `cortex-m` 0.7 can be enabled using the feature `cortex-m-7` and disabling default features: - -``` -cortex-m-rtic = { version = "0.5.8", default-features = false, features = ["cortex-m-7"] } -``` - -RTIC 1.0.0 already uses `cortex-m` 0.7 by default. - ## [User documentation](https://rtic.rs) Documentation for the [development version](https://rtic.rs/dev). @@ -68,10 +58,10 @@ Documentation for the [development version](https://rtic.rs/dev). Join us and talk about RTIC in the [Matrix room][matrix-room]. -Weekly meeting notes can be found over at [HackMD][hackmd] +Weekly meeting minutes can be found over at [RTIC HackMD][hackmd] [matrix-room]: https://matrix.to/#/#rtic:matrix.org -[hackmd]: https://hackmd.io/@xmis9JvZT8Gvo9lOEKyZ4Q/SkBJKsjuH +[hackmd]: rtic.rs/meeting ## Contributing diff --git a/book/.gitignore b/book/.gitignore new file mode 100644 index 0000000..79339e2 --- /dev/null +++ b/book/.gitignore @@ -0,0 +1,2 @@ +# Make sure that mdbook output in repo-root/book/<language>/book is ignored +*/book diff --git a/book/en/book.toml b/book/en/book.toml index 98c5bf3..8a89eeb 100644 --- a/book/en/book.toml +++ b/book/en/book.toml @@ -1,9 +1,22 @@ [book] -authors = ["Jorge Aparicio, Per Lindgren and The Real-Time Interrupt-driven Concurrency developers"] +authors = [ + "The Real-Time Interrupt-driven Concurrency developers", + "Emil Fresk <emil.fresk@gmail.com>", + "Henrik Tjäder <henrik@tjaders.com>", + "Jorge Aparicio <jorge@japaric.io>", + "Per Lindgren <per.lindgren@ltu.se>", +] multilingual = false src = "src" title = "Real-Time Interrupt-driven Concurrency" +[build] +create-missing = false + +[preprocessor.mermaid] +command = "mdbook-mermaid" + [output.html] -git-repository-url = "https://github.com/rtic-rs/cortex-m-rtic" +git-repository-url = "https://github.com/rtic-rs/rtic" git-repository-icon = "fa-github" +additional-js = ["mermaid.min.js", "mermaid-init.js"] diff --git a/book/en/mermaid-init.js b/book/en/mermaid-init.js new file mode 100644 index 0000000..313a6e8 --- /dev/null +++ b/book/en/mermaid-init.js @@ -0,0 +1 @@ +mermaid.initialize({startOnLoad:true}); diff --git a/book/en/mermaid.min.js b/book/en/mermaid.min.js new file mode 100644 index 0000000..8c7ea4e --- /dev/null +++ b/book/en/mermaid.min.js @@ -0,0 +1,1282 @@ +/* MIT Licensed. Copyright (c) 2014 - 2022 Knut Sveidqvist */ +/* For license information please see https://github.com/mermaid-js/mermaid/blob/v9.2.2/LICENSE */ +(function(jr,wn){typeof exports=="object"&&typeof module<"u"?module.exports=wn():typeof define=="function"&&define.amd?define(wn):(jr=typeof globalThis<"u"?globalThis:jr||self,jr.mermaid=wn())})(this,function(){"use strict";var Ost=Object.defineProperty;var Fst=(jr,wn,fn)=>wn in jr?Ost(jr,wn,{enumerable:!0,configurable:!0,writable:!0,value:fn}):jr[wn]=fn;var vl=(jr,wn,fn)=>(Fst(jr,typeof wn!="symbol"?wn+"":wn,fn),fn);var jr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function wn(t){var e=t.default;if(typeof e=="function"){var r=function(){return e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})}),r}function fn(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var y_={exports:{}};(function(t,e){(function(r,n){t.exports=n()})(jr,function(){var r;function n(){return r.apply(null,arguments)}function i(g){return g instanceof Array||Object.prototype.toString.call(g)==="[object Array]"}function a(g){return g!=null&&Object.prototype.toString.call(g)==="[object Object]"}function s(g,E){return Object.prototype.hasOwnProperty.call(g,E)}function o(g){if(Object.getOwnPropertyNames)return Object.getOwnPropertyNames(g).length===0;for(var E in g)if(s(g,E))return;return 1}function l(g){return g===void 0}function u(g){return typeof g=="number"||Object.prototype.toString.call(g)==="[object Number]"}function h(g){return g instanceof Date||Object.prototype.toString.call(g)==="[object Date]"}function d(g,E){for(var I=[],O=g.length,G=0;G<O;++G)I.push(E(g[G],G));return I}function f(g,E){for(var I in E)s(E,I)&&(g[I]=E[I]);return s(E,"toString")&&(g.toString=E.toString),s(E,"valueOf")&&(g.valueOf=E.valueOf),g}function p(g,E,I,O){return Dr(g,E,I,O,!0).utc()}function m(g){return g._pf==null&&(g._pf={empty:!1,unusedTokens:[],unusedInput:[],overflow:-2,charsLeftOver:0,nullInput:!1,invalidEra:null,invalidMonth:null,invalidFormat:!1,userInvalidated:!1,iso:!1,parsedDateParts:[],era:null,meridiem:null,rfc2822:!1,weekdayMismatch:!1}),g._pf}function _(g){if(g._isValid==null){var E=m(g),I=b.call(E.parsedDateParts,function(O){return O!=null}),I=!isNaN(g._d.getTime())&&E.overflow<0&&!E.empty&&!E.invalidEra&&!E.invalidMonth&&!E.invalidWeekday&&!E.weekdayMismatch&&!E.nullInput&&!E.invalidFormat&&!E.userInvalidated&&(!E.meridiem||E.meridiem&&I);if(g._strict&&(I=I&&E.charsLeftOver===0&&E.unusedTokens.length===0&&E.bigHour===void 0),Object.isFrozen!=null&&Object.isFrozen(g))return I;g._isValid=I}return g._isValid}function y(g){var E=p(NaN);return g!=null?f(m(E),g):m(E).userInvalidated=!0,E}var b=Array.prototype.some||function(g){for(var E=Object(this),I=E.length>>>0,O=0;O<I;O++)if(O in E&&g.call(this,E[O],O,E))return!0;return!1},x=n.momentProperties=[],k=!1;function T(g,E){var I,O,G,ht=x.length;if(l(E._isAMomentObject)||(g._isAMomentObject=E._isAMomentObject),l(E._i)||(g._i=E._i),l(E._f)||(g._f=E._f),l(E._l)||(g._l=E._l),l(E._strict)||(g._strict=E._strict),l(E._tzm)||(g._tzm=E._tzm),l(E._isUTC)||(g._isUTC=E._isUTC),l(E._offset)||(g._offset=E._offset),l(E._pf)||(g._pf=m(E)),l(E._locale)||(g._locale=E._locale),0<ht)for(I=0;I<ht;I++)l(G=E[O=x[I]])||(g[O]=G);return g}function C(g){T(this,g),this._d=new Date(g._d!=null?g._d.getTime():NaN),this.isValid()||(this._d=new Date(NaN)),k===!1&&(k=!0,n.updateOffset(this),k=!1)}function M(g){return g instanceof C||g!=null&&g._isAMomentObject!=null}function S(g){n.suppressDeprecationWarnings===!1&&typeof console<"u"&&console.warn&&console.warn("Deprecation warning: "+g)}function R(g,E){var I=!0;return f(function(){if(n.deprecationHandler!=null&&n.deprecationHandler(null,g),I){for(var O,G,ht=[],xt=arguments.length,Mt=0;Mt<xt;Mt++){if(O="",typeof arguments[Mt]=="object"){for(G in O+=` +[`+Mt+"] ",arguments[0])s(arguments[0],G)&&(O+=G+": "+arguments[0][G]+", ");O=O.slice(0,-2)}else O=arguments[Mt];ht.push(O)}S(g+` +Arguments: `+Array.prototype.slice.call(ht).join("")+` +`+new Error().stack),I=!1}return E.apply(this,arguments)},E)}var A={};function L(g,E){n.deprecationHandler!=null&&n.deprecationHandler(g,E),A[g]||(S(E),A[g]=!0)}function v(g){return typeof Function<"u"&&g instanceof Function||Object.prototype.toString.call(g)==="[object Function]"}function B(g,E){var I,O=f({},g);for(I in E)s(E,I)&&(a(g[I])&&a(E[I])?(O[I]={},f(O[I],g[I]),f(O[I],E[I])):E[I]!=null?O[I]=E[I]:delete O[I]);for(I in g)s(g,I)&&!s(E,I)&&a(g[I])&&(O[I]=f({},O[I]));return O}function w(g){g!=null&&this.set(g)}n.suppressDeprecationWarnings=!1,n.deprecationHandler=null;var D=Object.keys||function(g){var E,I=[];for(E in g)s(g,E)&&I.push(E);return I};function N(g,E,I){var O=""+Math.abs(g);return(0<=g?I?"+":"":"-")+Math.pow(10,Math.max(0,E-O.length)).toString().substr(1)+O}var z=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,X=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,ct={},J={};function Y(g,E,I,O){var G=typeof O=="string"?function(){return this[O]()}:O;g&&(J[g]=G),E&&(J[E[0]]=function(){return N(G.apply(this,arguments),E[1],E[2])}),I&&(J[I]=function(){return this.localeData().ordinal(G.apply(this,arguments),g)})}function $(g,E){return g.isValid()?(E=lt(E,g.localeData()),ct[E]=ct[E]||function(I){for(var O,G=I.match(z),ht=0,xt=G.length;ht<xt;ht++)J[G[ht]]?G[ht]=J[G[ht]]:G[ht]=(O=G[ht]).match(/\[[\s\S]/)?O.replace(/^\[|\]$/g,""):O.replace(/\\/g,"");return function(Mt){for(var Vt="",Ot=0;Ot<xt;Ot++)Vt+=v(G[Ot])?G[Ot].call(Mt,I):G[Ot];return Vt}}(E),ct[E](g)):g.localeData().invalidDate()}function lt(g,E){var I=5;function O(G){return E.longDateFormat(G)||G}for(X.lastIndex=0;0<=I&&X.test(g);)g=g.replace(X,O),X.lastIndex=0,--I;return g}var ut={};function W(g,E){var I=g.toLowerCase();ut[I]=ut[I+"s"]=ut[E]=g}function tt(g){return typeof g=="string"?ut[g]||ut[g.toLowerCase()]:void 0}function K(g){var E,I,O={};for(I in g)s(g,I)&&(E=tt(I))&&(O[E]=g[I]);return O}var it={};function Z(g,E){it[g]=E}function V(g){return g%4==0&&g%100!=0||g%400==0}function Q(g){return g<0?Math.ceil(g)||0:Math.floor(g)}function q(E){var E=+E,I=0;return I=E!=0&&isFinite(E)?Q(E):I}function U(g,E){return function(I){return I!=null?(j(this,g,I),n.updateOffset(this,E),this):F(this,g)}}function F(g,E){return g.isValid()?g._d["get"+(g._isUTC?"UTC":"")+E]():NaN}function j(g,E,I){g.isValid()&&!isNaN(I)&&(E==="FullYear"&&V(g.year())&&g.month()===1&&g.date()===29?(I=q(I),g._d["set"+(g._isUTC?"UTC":"")+E](I,g.month(),yt(I,g.month()))):g._d["set"+(g._isUTC?"UTC":"")+E](I))}var P=/\d/,fe=/\d\d/,et=/\d{3}/,to=/\d{4}/,os=/[+-]?\d{6}/,at=/\d\d?/,It=/\d\d\d\d?/,Lt=/\d\d\d\d\d\d?/,Rt=/\d{1,3}/,ls=/\d{1,4}/,ss=/[+-]?\d{1,6}/,Ct=/\d+/,pt=/[+-]?\d+/,mt=/Z|[+-]\d\d:?\d\d/gi,vt=/Z|[+-]\d\d(?::?\d\d)?/gi,Tt=/[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i;function ft(g,E,I){Gt[g]=v(E)?E:function(O,G){return O&&I?I:E}}function le(g,E){return s(Gt,g)?Gt[g](E._strict,E._locale):new RegExp(Dt(g.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(I,O,G,ht,xt){return O||G||ht||xt})))}function Dt(g){return g.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}var Gt={},$t={};function Qt(g,E){var I,O,G=E;for(typeof g=="string"&&(g=[g]),u(E)&&(G=function(ht,xt){xt[E]=q(ht)}),O=g.length,I=0;I<O;I++)$t[g[I]]=G}function we(g,E){Qt(g,function(I,O,G,ht){G._w=G._w||{},E(I,G._w,G,ht)})}var jt,Ft=0,zt=1,wt=2,bt=3,Et=4,kt=5,Ut=6,gt=7,he=8;function yt(g,E){if(isNaN(g)||isNaN(E))return NaN;var I=(E%(I=12)+I)%I;return g+=(E-I)/12,I==1?V(g)?29:28:31-I%7%2}jt=Array.prototype.indexOf||function(g){for(var E=0;E<this.length;++E)if(this[E]===g)return E;return-1},Y("M",["MM",2],"Mo",function(){return this.month()+1}),Y("MMM",0,0,function(g){return this.localeData().monthsShort(this,g)}),Y("MMMM",0,0,function(g){return this.localeData().months(this,g)}),W("month","M"),Z("month",8),ft("M",at),ft("MM",at,fe),ft("MMM",function(g,E){return E.monthsShortRegex(g)}),ft("MMMM",function(g,E){return E.monthsRegex(g)}),Qt(["M","MM"],function(g,E){E[zt]=q(g)-1}),Qt(["MMM","MMMM"],function(g,E,I,O){O=I._locale.monthsParse(g,O,I._strict),O!=null?E[zt]=O:m(I).invalidMonth=g});var ne="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ve="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),ye=/D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,be=Tt,Te=Tt;function Wt(g,E){var I;if(g.isValid()){if(typeof E=="string"){if(/^\d+$/.test(E))E=q(E);else if(!u(E=g.localeData().monthsParse(E)))return}I=Math.min(g.date(),yt(g.year(),E)),g._d["set"+(g._isUTC?"UTC":"")+"Month"](E,I)}}function se(g){return g!=null?(Wt(this,g),n.updateOffset(this,!0),this):F(this,"Month")}function me(){function g(xt,Mt){return Mt.length-xt.length}for(var E,I=[],O=[],G=[],ht=0;ht<12;ht++)E=p([2e3,ht]),I.push(this.monthsShort(E,"")),O.push(this.months(E,"")),G.push(this.months(E,"")),G.push(this.monthsShort(E,""));for(I.sort(g),O.sort(g),G.sort(g),ht=0;ht<12;ht++)I[ht]=Dt(I[ht]),O[ht]=Dt(O[ht]);for(ht=0;ht<24;ht++)G[ht]=Dt(G[ht]);this._monthsRegex=new RegExp("^("+G.join("|")+")","i"),this._monthsShortRegex=this._monthsRegex,this._monthsStrictRegex=new RegExp("^("+O.join("|")+")","i"),this._monthsShortStrictRegex=new RegExp("^("+I.join("|")+")","i")}function ue(g){return V(g)?366:365}Y("Y",0,0,function(){var g=this.year();return g<=9999?N(g,4):"+"+g}),Y(0,["YY",2],0,function(){return this.year()%100}),Y(0,["YYYY",4],0,"year"),Y(0,["YYYYY",5],0,"year"),Y(0,["YYYYYY",6,!0],0,"year"),W("year","y"),Z("year",1),ft("Y",pt),ft("YY",at,fe),ft("YYYY",ls,to),ft("YYYYY",ss,os),ft("YYYYYY",ss,os),Qt(["YYYYY","YYYYYY"],Ft),Qt("YYYY",function(g,E){E[Ft]=g.length===2?n.parseTwoDigitYear(g):q(g)}),Qt("YY",function(g,E){E[Ft]=n.parseTwoDigitYear(g)}),Qt("Y",function(g,E){E[Ft]=parseInt(g,10)}),n.parseTwoDigitYear=function(g){return q(g)+(68<q(g)?1900:2e3)};var N0=U("FullYear",!0);function _a(g,E,I,O,G,ht,xt){var Mt;return g<100&&0<=g?(Mt=new Date(g+400,E,I,O,G,ht,xt),isFinite(Mt.getFullYear())&&Mt.setFullYear(g)):Mt=new Date(g,E,I,O,G,ht,xt),Mt}function Hr(g){var E;return g<100&&0<=g?((E=Array.prototype.slice.call(arguments))[0]=g+400,E=new Date(Date.UTC.apply(null,E)),isFinite(E.getUTCFullYear())&&E.setUTCFullYear(g)):E=new Date(Date.UTC.apply(null,arguments)),E}function Ie(g,E,I){return I=7+E-I,I-(7+Hr(g,0,I).getUTCDay()-E)%7-1}function oe(g,xt,Mt,O,G){var ht,xt=1+7*(xt-1)+(7+Mt-O)%7+Ie(g,O,G),Mt=xt<=0?ue(ht=g-1)+xt:xt>ue(g)?(ht=g+1,xt-ue(g)):(ht=g,xt);return{year:ht,dayOfYear:Mt}}function Ke(g,E,I){var O,G,ht=Ie(g.year(),E,I),ht=Math.floor((g.dayOfYear()-ht-1)/7)+1;return ht<1?O=ht+wr(G=g.year()-1,E,I):ht>wr(g.year(),E,I)?(O=ht-wr(g.year(),E,I),G=g.year()+1):(G=g.year(),O=ht),{week:O,year:G}}function wr(g,G,I){var O=Ie(g,G,I),G=Ie(g+1,G,I);return(ue(g)-O+G)/7}Y("w",["ww",2],"wo","week"),Y("W",["WW",2],"Wo","isoWeek"),W("week","w"),W("isoWeek","W"),Z("week",5),Z("isoWeek",5),ft("w",at),ft("ww",at,fe),ft("W",at),ft("WW",at,fe),we(["w","ww","W","WW"],function(g,E,I,O){E[O.substr(0,1)]=q(g)});function Ge(g,E){return g.slice(E,7).concat(g.slice(0,E))}Y("d",0,"do","day"),Y("dd",0,0,function(g){return this.localeData().weekdaysMin(this,g)}),Y("ddd",0,0,function(g){return this.localeData().weekdaysShort(this,g)}),Y("dddd",0,0,function(g){return this.localeData().weekdays(this,g)}),Y("e",0,0,"weekday"),Y("E",0,0,"isoWeekday"),W("day","d"),W("weekday","e"),W("isoWeekday","E"),Z("day",11),Z("weekday",11),Z("isoWeekday",11),ft("d",at),ft("e",at),ft("E",at),ft("dd",function(g,E){return E.weekdaysMinRegex(g)}),ft("ddd",function(g,E){return E.weekdaysShortRegex(g)}),ft("dddd",function(g,E){return E.weekdaysRegex(g)}),we(["dd","ddd","dddd"],function(g,E,I,O){O=I._locale.weekdaysParse(g,O,I._strict),O!=null?E.d=O:m(I).invalidWeekday=g}),we(["d","e","E"],function(g,E,I,O){E[O]=q(g)});var Ze="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),qt="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),st="Su_Mo_Tu_We_Th_Fr_Sa".split("_"),At=Tt,Nt=Tt,Jt=Tt;function ze(){function g(Ot,de){return de.length-Ot.length}for(var E,I,O,G=[],ht=[],xt=[],Mt=[],Vt=0;Vt<7;Vt++)O=p([2e3,1]).day(Vt),E=Dt(this.weekdaysMin(O,"")),I=Dt(this.weekdaysShort(O,"")),O=Dt(this.weekdays(O,"")),G.push(E),ht.push(I),xt.push(O),Mt.push(E),Mt.push(I),Mt.push(O);G.sort(g),ht.sort(g),xt.sort(g),Mt.sort(g),this._weekdaysRegex=new RegExp("^("+Mt.join("|")+")","i"),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp("^("+xt.join("|")+")","i"),this._weekdaysShortStrictRegex=new RegExp("^("+ht.join("|")+")","i"),this._weekdaysMinStrictRegex=new RegExp("^("+G.join("|")+")","i")}function Pe(){return this.hours()%12||12}function qe(g,E){Y(g,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),E)})}function Tr(g,E){return E._meridiemParse}Y("H",["HH",2],0,"hour"),Y("h",["hh",2],0,Pe),Y("k",["kk",2],0,function(){return this.hours()||24}),Y("hmm",0,0,function(){return""+Pe.apply(this)+N(this.minutes(),2)}),Y("hmmss",0,0,function(){return""+Pe.apply(this)+N(this.minutes(),2)+N(this.seconds(),2)}),Y("Hmm",0,0,function(){return""+this.hours()+N(this.minutes(),2)}),Y("Hmmss",0,0,function(){return""+this.hours()+N(this.minutes(),2)+N(this.seconds(),2)}),qe("a",!0),qe("A",!1),W("hour","h"),Z("hour",13),ft("a",Tr),ft("A",Tr),ft("H",at),ft("h",at),ft("k",at),ft("HH",at,fe),ft("hh",at,fe),ft("kk",at,fe),ft("hmm",It),ft("hmmss",Lt),ft("Hmm",It),ft("Hmmss",Lt),Qt(["H","HH"],bt),Qt(["k","kk"],function(g,E,I){g=q(g),E[bt]=g===24?0:g}),Qt(["a","A"],function(g,E,I){I._isPm=I._locale.isPM(g),I._meridiem=g}),Qt(["h","hh"],function(g,E,I){E[bt]=q(g),m(I).bigHour=!0}),Qt("hmm",function(g,E,I){var O=g.length-2;E[bt]=q(g.substr(0,O)),E[Et]=q(g.substr(O)),m(I).bigHour=!0}),Qt("hmmss",function(g,E,I){var O=g.length-4,G=g.length-2;E[bt]=q(g.substr(0,O)),E[Et]=q(g.substr(O,2)),E[kt]=q(g.substr(G)),m(I).bigHour=!0}),Qt("Hmm",function(g,E,I){var O=g.length-2;E[bt]=q(g.substr(0,O)),E[Et]=q(g.substr(O))}),Qt("Hmmss",function(g,E,I){var O=g.length-4,G=g.length-2;E[bt]=q(g.substr(0,O)),E[Et]=q(g.substr(O,2)),E[kt]=q(g.substr(G))}),Tt=U("Hours",!0);var Ve,va={calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},longDateFormat:{LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},invalidDate:"Invalid date",ordinal:"%d",dayOfMonthOrdinalParse:/\d{1,2}/,relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",ss:"%d seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",w:"a week",ww:"%d weeks",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},months:ne,monthsShort:ve,week:{dow:0,doy:6},weekdays:Ze,weekdaysMin:st,weekdaysShort:qt,meridiemParse:/[ap]\.?m?\.?/i},Ce={},Wi={};function E0(g){return g&&g.toLowerCase().replace("_","-")}function _u(g){for(var E,I,O,G,ht=0;ht<g.length;){for(E=(G=E0(g[ht]).split("-")).length,I=(I=E0(g[ht+1]))?I.split("-"):null;0<E;){if(O=Ln(G.slice(0,E).join("-")))return O;if(I&&I.length>=E&&function(xt,Mt){for(var Vt=Math.min(xt.length,Mt.length),Ot=0;Ot<Vt;Ot+=1)if(xt[Ot]!==Mt[Ot])return Ot;return Vt}(G,I)>=E-1)break;E--}ht++}return Ve}function Ln(g){var E;if(Ce[g]===void 0&&!0&&t&&t.exports&&g.match("^[^/\\\\]*$")!=null)try{E=Ve._abbr,fn("./locale/"+g),Xt(E)}catch{Ce[g]=null}return Ce[g]}function Xt(g,E){return g&&((E=l(E)?ce(g):ee(g,E))?Ve=E:typeof console<"u"&&console.warn&&console.warn("Locale "+g+" not found. Did you forget to load it?")),Ve._abbr}function ee(g,E){if(E===null)return delete Ce[g],null;var I,O=va;if(E.abbr=g,Ce[g]!=null)L("defineLocaleOverride","use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info."),O=Ce[g]._config;else if(E.parentLocale!=null)if(Ce[E.parentLocale]!=null)O=Ce[E.parentLocale]._config;else{if((I=Ln(E.parentLocale))==null)return Wi[E.parentLocale]||(Wi[E.parentLocale]=[]),Wi[E.parentLocale].push({name:g,config:E}),null;O=I._config}return Ce[g]=new w(B(O,E)),Wi[g]&&Wi[g].forEach(function(G){ee(G.name,G.config)}),Xt(g),Ce[g]}function ce(g){var E;if(!(g=g&&g._locale&&g._locale._abbr?g._locale._abbr:g))return Ve;if(!i(g)){if(E=Ln(g))return E;g=[g]}return _u(g)}function Pt(g){var E=g._a;return E&&m(g).overflow===-2&&(E=E[zt]<0||11<E[zt]?zt:E[wt]<1||E[wt]>yt(E[Ft],E[zt])?wt:E[bt]<0||24<E[bt]||E[bt]===24&&(E[Et]!==0||E[kt]!==0||E[Ut]!==0)?bt:E[Et]<0||59<E[Et]?Et:E[kt]<0||59<E[kt]?kt:E[Ut]<0||999<E[Ut]?Ut:-1,m(g)._overflowDayOfYear&&(E<Ft||wt<E)&&(E=wt),m(g)._overflowWeeks&&E===-1&&(E=gt),m(g)._overflowWeekday&&E===-1&&(E=he),m(g).overflow=E),g}var je=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,rt=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,Ks=/Z|[+-]\d\d(?::?\d\d)?/,ot=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/],["YYYYMM",/\d{6}/,!1],["YYYY",/\d{4}/,!1]],Gr=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],C0=/^\/?Date\((-?\d+)/i,l_=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/,S0={UT:0,GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function A0(g){var E,I,O,G,ht,xt,Vt=g._i,Mt=je.exec(Vt)||rt.exec(Vt),Vt=ot.length,Ot=Gr.length;if(Mt){for(m(g).iso=!0,E=0,I=Vt;E<I;E++)if(ot[E][1].exec(Mt[1])){G=ot[E][0],O=ot[E][2]!==!1;break}if(G==null)g._isValid=!1;else{if(Mt[3]){for(E=0,I=Ot;E<I;E++)if(Gr[E][1].exec(Mt[3])){ht=(Mt[2]||" ")+Gr[E][0];break}if(ht==null)return void(g._isValid=!1)}if(O||ht==null){if(Mt[4]){if(!Ks.exec(Mt[4]))return void(g._isValid=!1);xt="Z"}g._f=G+(ht||"")+(xt||""),vu(g)}else g._isValid=!1}}else g._isValid=!1}function mr(g,E,I,O,G,ht){return g=[function(xt){xt=parseInt(xt,10);{if(xt<=49)return 2e3+xt;if(xt<=999)return 1900+xt}return xt}(g),ve.indexOf(E),parseInt(I,10),parseInt(O,10),parseInt(G,10)],ht&&g.push(parseInt(ht,10)),g}function Hi(g){var E,I,O,G,ht=l_.exec(g._i.replace(/\([^()]*\)|[\n\t]/g," ").replace(/(\s\s+)/g," ").replace(/^\s\s*/,"").replace(/\s\s*$/,""));ht?(E=mr(ht[4],ht[3],ht[2],ht[5],ht[6],ht[7]),I=ht[1],O=E,G=g,I&&qt.indexOf(I)!==new Date(O[0],O[1],O[2]).getDay()?(m(G).weekdayMismatch=!0,G._isValid=!1):(g._a=E,g._tzm=(I=ht[8],O=ht[9],G=ht[10],I?S0[I]:O?0:60*(((I=parseInt(G,10))-(O=I%100))/100)+O),g._d=Hr.apply(null,g._a),g._d.setUTCMinutes(g._d.getUTCMinutes()-g._tzm),m(g).rfc2822=!0)):g._isValid=!1}function Gi(g,E,I){return g!=null?g:E!=null?E:I}function Zs(g){var E,I,O,G,ht,xt,Mt,Vt,Ot,de,ie,er=[];if(!g._d){for(O=g,G=new Date(n.now()),I=O._useUTC?[G.getUTCFullYear(),G.getUTCMonth(),G.getUTCDate()]:[G.getFullYear(),G.getMonth(),G.getDate()],g._w&&g._a[wt]==null&&g._a[zt]==null&&((G=(O=g)._w).GG!=null||G.W!=null||G.E!=null?(Vt=1,Ot=4,ht=Gi(G.GG,O._a[Ft],Ke(De(),1,4).year),xt=Gi(G.W,1),((Mt=Gi(G.E,1))<1||7<Mt)&&(de=!0)):(Vt=O._locale._week.dow,Ot=O._locale._week.doy,ie=Ke(De(),Vt,Ot),ht=Gi(G.gg,O._a[Ft],ie.year),xt=Gi(G.w,ie.week),G.d!=null?((Mt=G.d)<0||6<Mt)&&(de=!0):G.e!=null?(Mt=G.e+Vt,(G.e<0||6<G.e)&&(de=!0)):Mt=Vt),xt<1||xt>wr(ht,Vt,Ot)?m(O)._overflowWeeks=!0:de!=null?m(O)._overflowWeekday=!0:(ie=oe(ht,xt,Mt,Vt,Ot),O._a[Ft]=ie.year,O._dayOfYear=ie.dayOfYear)),g._dayOfYear!=null&&(G=Gi(g._a[Ft],I[Ft]),(g._dayOfYear>ue(G)||g._dayOfYear===0)&&(m(g)._overflowDayOfYear=!0),de=Hr(G,0,g._dayOfYear),g._a[zt]=de.getUTCMonth(),g._a[wt]=de.getUTCDate()),E=0;E<3&&g._a[E]==null;++E)g._a[E]=er[E]=I[E];for(;E<7;E++)g._a[E]=er[E]=g._a[E]==null?E===2?1:0:g._a[E];g._a[bt]===24&&g._a[Et]===0&&g._a[kt]===0&&g._a[Ut]===0&&(g._nextDay=!0,g._a[bt]=0),g._d=(g._useUTC?Hr:_a).apply(null,er),ht=g._useUTC?g._d.getUTCDay():g._d.getDay(),g._tzm!=null&&g._d.setUTCMinutes(g._d.getUTCMinutes()-g._tzm),g._nextDay&&(g._a[bt]=24),g._w&&g._w.d!==void 0&&g._w.d!==ht&&(m(g).weekdayMismatch=!0)}}function vu(g){if(g._f===n.ISO_8601)A0(g);else if(g._f===n.RFC_2822)Hi(g);else{g._a=[],m(g).empty=!0;for(var E,I,O,G,ht,xt=""+g._i,Mt=xt.length,Vt=0,Ot=lt(g._f,g._locale).match(z)||[],de=Ot.length,ie=0;ie<de;ie++)I=Ot[ie],(E=(xt.match(le(I,g))||[])[0])&&(0<(O=xt.substr(0,xt.indexOf(E))).length&&m(g).unusedInput.push(O),xt=xt.slice(xt.indexOf(E)+E.length),Vt+=E.length),J[I]?(E?m(g).empty=!1:m(g).unusedTokens.push(I),O=I,ht=g,(G=E)!=null&&s($t,O)&&$t[O](G,ht._a,ht,O)):g._strict&&!E&&m(g).unusedTokens.push(I);m(g).charsLeftOver=Mt-Vt,0<xt.length&&m(g).unusedInput.push(xt),g._a[bt]<=12&&m(g).bigHour===!0&&0<g._a[bt]&&(m(g).bigHour=void 0),m(g).parsedDateParts=g._a.slice(0),m(g).meridiem=g._meridiem,g._a[bt]=function(er,br,xi){return xi==null?br:er.meridiemHour!=null?er.meridiemHour(br,xi):er.isPM!=null?((er=er.isPM(xi))&&br<12&&(br+=12),br=er||br!==12?br:0):br}(g._locale,g._a[bt],g._meridiem),(Mt=m(g).era)!==null&&(g._a[Ft]=g._locale.erasConvertYear(Mt,g._a[Ft])),Zs(g),Pt(g)}}function M0(g){var E,I,O,G=g._i,ht=g._f;return g._locale=g._locale||ce(g._l),G===null||ht===void 0&&G===""?y({nullInput:!0}):(typeof G=="string"&&(g._i=G=g._locale.preparse(G)),M(G)?new C(Pt(G)):(h(G)?g._d=G:i(ht)?function(xt){var Mt,Vt,Ot,de,ie,er,br=!1,xi=xt._f.length;if(xi===0)return m(xt).invalidFormat=!0,xt._d=new Date(NaN);for(de=0;de<xi;de++)ie=0,er=!1,Mt=T({},xt),xt._useUTC!=null&&(Mt._useUTC=xt._useUTC),Mt._f=xt._f[de],vu(Mt),_(Mt)&&(er=!0),ie=(ie+=m(Mt).charsLeftOver)+10*m(Mt).unusedTokens.length,m(Mt).score=ie,br?ie<Ot&&(Ot=ie,Vt=Mt):(Ot==null||ie<Ot||er)&&(Ot=ie,Vt=Mt,er&&(br=!0));f(xt,Vt||Mt)}(g):ht?vu(g):l(ht=(G=g)._i)?G._d=new Date(n.now()):h(ht)?G._d=new Date(ht.valueOf()):typeof ht=="string"?(I=G,(E=C0.exec(I._i))!==null?I._d=new Date(+E[1]):(A0(I),I._isValid===!1&&(delete I._isValid,Hi(I),I._isValid===!1&&(delete I._isValid,I._strict?I._isValid=!1:n.createFromInputFallback(I))))):i(ht)?(G._a=d(ht.slice(0),function(xt){return parseInt(xt,10)}),Zs(G)):a(ht)?(E=G)._d||(O=(I=K(E._i)).day===void 0?I.date:I.day,E._a=d([I.year,I.month,O,I.hour,I.minute,I.second,I.millisecond],function(xt){return xt&&parseInt(xt,10)}),Zs(E)):u(ht)?G._d=new Date(ht):n.createFromInputFallback(G),_(g)||(g._d=null),g))}function Dr(g,E,I,O,G){var ht={};return E!==!0&&E!==!1||(O=E,E=void 0),I!==!0&&I!==!1||(O=I,I=void 0),(a(g)&&o(g)||i(g)&&g.length===0)&&(g=void 0),ht._isAMomentObject=!0,ht._useUTC=ht._isUTC=G,ht._l=I,ht._i=g,ht._f=E,ht._strict=O,(G=new C(Pt(M0(G=ht))))._nextDay&&(G.add(1,"d"),G._nextDay=void 0),G}function De(g,E,I,O){return Dr(g,E,I,O,!1)}n.createFromInputFallback=R("value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.",function(g){g._d=new Date(g._i+(g._useUTC?" UTC":""))}),n.ISO_8601=function(){},n.RFC_2822=function(){},It=R("moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/",function(){var g=De.apply(null,arguments);return this.isValid()&&g.isValid()?g<this?this:g:y()}),Lt=R("moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/",function(){var g=De.apply(null,arguments);return this.isValid()&&g.isValid()?this<g?this:g:y()});function hn(g,E){var I,O;if(!(E=E.length===1&&i(E[0])?E[0]:E).length)return De();for(I=E[0],O=1;O<E.length;++O)E[O].isValid()&&!E[O][g](I)||(I=E[O]);return I}var xa=["year","quarter","month","week","day","hour","minute","second","millisecond"];function _i(E){var E=K(E),I=E.year||0,O=E.quarter||0,G=E.month||0,ht=E.week||E.isoWeek||0,xt=E.day||0,Mt=E.hour||0,Vt=E.minute||0,Ot=E.second||0,de=E.millisecond||0;this._isValid=function(ie){var er,br,xi=!1,g_=xa.length;for(er in ie)if(s(ie,er)&&(jt.call(xa,er)===-1||ie[er]!=null&&isNaN(ie[er])))return!1;for(br=0;br<g_;++br)if(ie[xa[br]]){if(xi)return!1;parseFloat(ie[xa[br]])!==q(ie[xa[br]])&&(xi=!0)}return!0}(E),this._milliseconds=+de+1e3*Ot+6e4*Vt+1e3*Mt*60*60,this._days=+xt+7*ht,this._months=+G+3*O+12*I,this._data={},this._locale=ce(),this._bubble()}function ka(g){return g instanceof _i}function Rn(g){return g<0?-1*Math.round(-1*g):Math.round(g)}function xu(g,E){Y(g,0,0,function(){var I=this.utcOffset(),O="+";return I<0&&(I=-I,O="-"),O+N(~~(I/60),2)+E+N(~~I%60,2)})}xu("Z",":"),xu("ZZ",""),ft("Z",vt),ft("ZZ",vt),Qt(["Z","ZZ"],function(g,E,I){I._useUTC=!0,I._tzm=Qs(vt,g)});var yl=/([\+\-]|\d\d)/gi;function Qs(g,I){var I=(I||"").match(g);return I===null?null:(I=60*(g=((I[I.length-1]||[])+"").match(yl)||["-",0,0])[1]+q(g[2]))===0?0:g[0]==="+"?I:-I}function In(g,E){var I;return E._isUTC?(E=E.clone(),I=(M(g)||h(g)?g:De(g)).valueOf()-E.valueOf(),E._d.setTime(E._d.valueOf()+I),n.updateOffset(E,!1),E):De(g).local()}function c_(g){return-Math.round(g._d.getTimezoneOffset())}function rR(){return!!this.isValid()&&this._isUTC&&this._offset===0}n.updateOffset=function(){};var Ast=/^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,Mst=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;function vi(g,E){var I,O=g,G=null;return ka(g)?O={ms:g._milliseconds,d:g._days,M:g._months}:u(g)||!isNaN(+g)?(O={},E?O[E]=+g:O.milliseconds=+g):(G=Ast.exec(g))?(I=G[1]==="-"?-1:1,O={y:0,d:q(G[wt])*I,h:q(G[bt])*I,m:q(G[Et])*I,s:q(G[kt])*I,ms:q(Rn(1e3*G[Ut]))*I}):(G=Mst.exec(g))?(I=G[1]==="-"?-1:1,O={y:Js(G[2],I),M:Js(G[3],I),w:Js(G[4],I),d:Js(G[5],I),h:Js(G[6],I),m:Js(G[7],I),s:Js(G[8],I)}):O==null?O={}:typeof O=="object"&&("from"in O||"to"in O)&&(E=function(ht,xt){var Mt;return!ht.isValid()||!xt.isValid()?{milliseconds:0,months:0}:(xt=In(xt,ht),ht.isBefore(xt)?Mt=nR(ht,xt):((Mt=nR(xt,ht)).milliseconds=-Mt.milliseconds,Mt.months=-Mt.months),Mt)}(De(O.from),De(O.to)),(O={}).ms=E.milliseconds,O.M=E.months),G=new _i(O),ka(g)&&s(g,"_locale")&&(G._locale=g._locale),ka(g)&&s(g,"_isValid")&&(G._isValid=g._isValid),G}function Js(g,E){return g=g&&parseFloat(g.replace(",",".")),(isNaN(g)?0:g)*E}function nR(g,E){var I={};return I.months=E.month()-g.month()+12*(E.year()-g.year()),g.clone().add(I.months,"M").isAfter(E)&&--I.months,I.milliseconds=+E-+g.clone().add(I.months,"M"),I}function iR(g,E){return function(I,O){var G;return O===null||isNaN(+O)||(L(E,"moment()."+E+"(period, number) is deprecated. Please use moment()."+E+"(number, period). See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info."),G=I,I=O,O=G),aR(this,vi(I,O),g),this}}function aR(g,xt,I,O){var G=xt._milliseconds,ht=Rn(xt._days),xt=Rn(xt._months);g.isValid()&&(O=O==null||O,xt&&Wt(g,F(g,"Month")+xt*I),ht&&j(g,"Date",F(g,"Date")+ht*I),G&&g._d.setTime(g._d.valueOf()+G*I),O&&n.updateOffset(g,ht||xt))}vi.fn=_i.prototype,vi.invalid=function(){return vi(NaN)},ne=iR(1,"add"),Ze=iR(-1,"subtract");function sR(g){return typeof g=="string"||g instanceof String}function Lst(g){return M(g)||h(g)||sR(g)||u(g)||function(E){var I=i(E),O=!1;return I&&(O=E.filter(function(G){return!u(G)&&sR(E)}).length===0),I&&O}(g)||function(E){var I,O,G=a(E)&&!o(E),ht=!1,xt=["years","year","y","months","month","M","days","day","d","dates","date","D","hours","hour","h","minutes","minute","m","seconds","second","s","milliseconds","millisecond","ms"],Mt=xt.length;for(I=0;I<Mt;I+=1)O=xt[I],ht=ht||s(E,O);return G&&ht}(g)||g==null}function L0(g,G){if(g.date()<G.date())return-L0(G,g);var I=12*(G.year()-g.year())+(G.month()-g.month()),O=g.clone().add(I,"months"),G=G-O<0?(G-O)/(O-g.clone().add(I-1,"months")):(G-O)/(g.clone().add(1+I,"months")-O);return-(I+G)||0}function oR(g){return g===void 0?this._locale._abbr:((g=ce(g))!=null&&(this._locale=g),this)}n.defaultFormat="YYYY-MM-DDTHH:mm:ssZ",n.defaultFormatUtc="YYYY-MM-DDTHH:mm:ss[Z]",st=R("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(g){return g===void 0?this.localeData():this.locale(g)});function lR(){return this._locale}var cR=126227808e5;function ml(g,E){return(g%E+E)%E}function uR(g,E,I){return g<100&&0<=g?new Date(g+400,E,I)-cR:new Date(g,E,I).valueOf()}function hR(g,E,I){return g<100&&0<=g?Date.UTC(g+400,E,I)-cR:Date.UTC(g,E,I)}function u_(g,E){return E.erasAbbrRegex(g)}function h_(){for(var g=[],E=[],I=[],O=[],G=this.eras(),ht=0,xt=G.length;ht<xt;++ht)E.push(Dt(G[ht].name)),g.push(Dt(G[ht].abbr)),I.push(Dt(G[ht].narrow)),O.push(Dt(G[ht].name)),O.push(Dt(G[ht].abbr)),O.push(Dt(G[ht].narrow));this._erasRegex=new RegExp("^("+O.join("|")+")","i"),this._erasNameRegex=new RegExp("^("+E.join("|")+")","i"),this._erasAbbrRegex=new RegExp("^("+g.join("|")+")","i"),this._erasNarrowRegex=new RegExp("^("+I.join("|")+")","i")}function R0(g,E){Y(0,[g,g.length],0,E)}function fR(g,E,I,O,G){var ht;return g==null?Ke(this,O,G).year:(ht=wr(g,O,G),function(xt,Mt,Vt,Ot,de){return xt=oe(xt,Mt,Vt,Ot,de),Mt=Hr(xt.year,0,xt.dayOfYear),this.year(Mt.getUTCFullYear()),this.month(Mt.getUTCMonth()),this.date(Mt.getUTCDate()),this}.call(this,g,E=ht<E?ht:E,I,O,G))}Y("N",0,0,"eraAbbr"),Y("NN",0,0,"eraAbbr"),Y("NNN",0,0,"eraAbbr"),Y("NNNN",0,0,"eraName"),Y("NNNNN",0,0,"eraNarrow"),Y("y",["y",1],"yo","eraYear"),Y("y",["yy",2],0,"eraYear"),Y("y",["yyy",3],0,"eraYear"),Y("y",["yyyy",4],0,"eraYear"),ft("N",u_),ft("NN",u_),ft("NNN",u_),ft("NNNN",function(g,E){return E.erasNameRegex(g)}),ft("NNNNN",function(g,E){return E.erasNarrowRegex(g)}),Qt(["N","NN","NNN","NNNN","NNNNN"],function(g,E,I,O){O=I._locale.erasParse(g,O,I._strict),O?m(I).era=O:m(I).invalidEra=g}),ft("y",Ct),ft("yy",Ct),ft("yyy",Ct),ft("yyyy",Ct),ft("yo",function(g,E){return E._eraYearOrdinalRegex||Ct}),Qt(["y","yy","yyy","yyyy"],Ft),Qt(["yo"],function(g,E,I,O){var G;I._locale._eraYearOrdinalRegex&&(G=g.match(I._locale._eraYearOrdinalRegex)),I._locale.eraYearOrdinalParse?E[Ft]=I._locale.eraYearOrdinalParse(g,G):E[Ft]=parseInt(g,10)}),Y(0,["gg",2],0,function(){return this.weekYear()%100}),Y(0,["GG",2],0,function(){return this.isoWeekYear()%100}),R0("gggg","weekYear"),R0("ggggg","weekYear"),R0("GGGG","isoWeekYear"),R0("GGGGG","isoWeekYear"),W("weekYear","gg"),W("isoWeekYear","GG"),Z("weekYear",1),Z("isoWeekYear",1),ft("G",pt),ft("g",pt),ft("GG",at,fe),ft("gg",at,fe),ft("GGGG",ls,to),ft("gggg",ls,to),ft("GGGGG",ss,os),ft("ggggg",ss,os),we(["gggg","ggggg","GGGG","GGGGG"],function(g,E,I,O){E[O.substr(0,2)]=q(g)}),we(["gg","GG"],function(g,E,I,O){E[O]=n.parseTwoDigitYear(g)}),Y("Q",0,"Qo","quarter"),W("quarter","Q"),Z("quarter",7),ft("Q",P),Qt("Q",function(g,E){E[zt]=3*(q(g)-1)}),Y("D",["DD",2],"Do","date"),W("date","D"),Z("date",9),ft("D",at),ft("DD",at,fe),ft("Do",function(g,E){return g?E._dayOfMonthOrdinalParse||E._ordinalParse:E._dayOfMonthOrdinalParseLenient}),Qt(["D","DD"],wt),Qt("Do",function(g,E){E[wt]=q(g.match(at)[0])}),ls=U("Date",!0),Y("DDD",["DDDD",3],"DDDo","dayOfYear"),W("dayOfYear","DDD"),Z("dayOfYear",4),ft("DDD",Rt),ft("DDDD",et),Qt(["DDD","DDDD"],function(g,E,I){I._dayOfYear=q(g)}),Y("m",["mm",2],0,"minute"),W("minute","m"),Z("minute",14),ft("m",at),ft("mm",at,fe),Qt(["m","mm"],Et);var as,to=U("Minutes",!1),ss=(Y("s",["ss",2],0,"second"),W("second","s"),Z("second",15),ft("s",at),ft("ss",at,fe),Qt(["s","ss"],kt),U("Seconds",!1));for(Y("S",0,0,function(){return~~(this.millisecond()/100)}),Y(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),Y(0,["SSS",3],0,"millisecond"),Y(0,["SSSS",4],0,function(){return 10*this.millisecond()}),Y(0,["SSSSS",5],0,function(){return 100*this.millisecond()}),Y(0,["SSSSSS",6],0,function(){return 1e3*this.millisecond()}),Y(0,["SSSSSSS",7],0,function(){return 1e4*this.millisecond()}),Y(0,["SSSSSSSS",8],0,function(){return 1e5*this.millisecond()}),Y(0,["SSSSSSSSS",9],0,function(){return 1e6*this.millisecond()}),W("millisecond","ms"),Z("millisecond",16),ft("S",Rt,P),ft("SS",Rt,fe),ft("SSS",Rt,et),as="SSSS";as.length<=9;as+="S")ft(as,Ct);function Rst(g,E){E[Ut]=q(1e3*("0."+g))}for(as="S";as.length<=9;as+="S")Qt(as,Rst);os=U("Milliseconds",!1),Y("z",0,0,"zoneAbbr"),Y("zz",0,0,"zoneName"),P=C.prototype;function dR(g){return g}P.add=ne,P.calendar=function(I,G){arguments.length===1&&(arguments[0]?Lst(arguments[0])?(I=arguments[0],G=void 0):function(ht){for(var xt=a(ht)&&!o(ht),Mt=!1,Vt=["sameDay","nextDay","lastDay","nextWeek","lastWeek","sameElse"],Ot=0;Ot<Vt.length;Ot+=1)Mt=Mt||s(ht,Vt[Ot]);return xt&&Mt}(arguments[0])&&(G=arguments[0],I=void 0):G=I=void 0);var I=I||De(),O=In(I,this).startOf("day"),O=n.calendarFormat(this,O)||"sameElse",G=G&&(v(G[O])?G[O].call(this,I):G[O]);return this.format(G||this.localeData().calendar(O,this,De(I)))},P.clone=function(){return new C(this)},P.diff=function(g,E,I){var O,G,ht;if(!this.isValid())return NaN;if(!(O=In(g,this)).isValid())return NaN;switch(G=6e4*(O.utcOffset()-this.utcOffset()),E=tt(E)){case"year":ht=L0(this,O)/12;break;case"month":ht=L0(this,O);break;case"quarter":ht=L0(this,O)/3;break;case"second":ht=(this-O)/1e3;break;case"minute":ht=(this-O)/6e4;break;case"hour":ht=(this-O)/36e5;break;case"day":ht=(this-O-G)/864e5;break;case"week":ht=(this-O-G)/6048e5;break;default:ht=this-O}return I?ht:Q(ht)},P.endOf=function(g){var E,I;if((g=tt(g))===void 0||g==="millisecond"||!this.isValid())return this;switch(I=this._isUTC?hR:uR,g){case"year":E=I(this.year()+1,0,1)-1;break;case"quarter":E=I(this.year(),this.month()-this.month()%3+3,1)-1;break;case"month":E=I(this.year(),this.month()+1,1)-1;break;case"week":E=I(this.year(),this.month(),this.date()-this.weekday()+7)-1;break;case"isoWeek":E=I(this.year(),this.month(),this.date()-(this.isoWeekday()-1)+7)-1;break;case"day":case"date":E=I(this.year(),this.month(),this.date()+1)-1;break;case"hour":E=this._d.valueOf(),E+=36e5-ml(E+(this._isUTC?0:6e4*this.utcOffset()),36e5)-1;break;case"minute":E=this._d.valueOf(),E+=6e4-ml(E,6e4)-1;break;case"second":E=this._d.valueOf(),E+=1e3-ml(E,1e3)-1;break}return this._d.setTime(E),n.updateOffset(this,!0),this},P.format=function(g){return g=g||(this.isUtc()?n.defaultFormatUtc:n.defaultFormat),g=$(this,g),this.localeData().postformat(g)},P.from=function(g,E){return this.isValid()&&(M(g)&&g.isValid()||De(g).isValid())?vi({to:this,from:g}).locale(this.locale()).humanize(!E):this.localeData().invalidDate()},P.fromNow=function(g){return this.from(De(),g)},P.to=function(g,E){return this.isValid()&&(M(g)&&g.isValid()||De(g).isValid())?vi({from:this,to:g}).locale(this.locale()).humanize(!E):this.localeData().invalidDate()},P.toNow=function(g){return this.to(De(),g)},P.get=function(g){return v(this[g=tt(g)])?this[g]():this},P.invalidAt=function(){return m(this).overflow},P.isAfter=function(g,E){return g=M(g)?g:De(g),!(!this.isValid()||!g.isValid())&&((E=tt(E)||"millisecond")==="millisecond"?this.valueOf()>g.valueOf():g.valueOf()<this.clone().startOf(E).valueOf())},P.isBefore=function(g,E){return g=M(g)?g:De(g),!(!this.isValid()||!g.isValid())&&((E=tt(E)||"millisecond")==="millisecond"?this.valueOf()<g.valueOf():this.clone().endOf(E).valueOf()<g.valueOf())},P.isBetween=function(g,E,I,O){return g=M(g)?g:De(g),E=M(E)?E:De(E),!!(this.isValid()&&g.isValid()&&E.isValid())&&((O=O||"()")[0]==="("?this.isAfter(g,I):!this.isBefore(g,I))&&(O[1]===")"?this.isBefore(E,I):!this.isAfter(E,I))},P.isSame=function(I,E){var I=M(I)?I:De(I);return!(!this.isValid()||!I.isValid())&&((E=tt(E)||"millisecond")==="millisecond"?this.valueOf()===I.valueOf():(I=I.valueOf(),this.clone().startOf(E).valueOf()<=I&&I<=this.clone().endOf(E).valueOf()))},P.isSameOrAfter=function(g,E){return this.isSame(g,E)||this.isAfter(g,E)},P.isSameOrBefore=function(g,E){return this.isSame(g,E)||this.isBefore(g,E)},P.isValid=function(){return _(this)},P.lang=st,P.locale=oR,P.localeData=lR,P.max=Lt,P.min=It,P.parsingFlags=function(){return f({},m(this))},P.set=function(g,E){if(typeof g=="object")for(var I=function(ht){var xt,Mt=[];for(xt in ht)s(ht,xt)&&Mt.push({unit:xt,priority:it[xt]});return Mt.sort(function(Vt,Ot){return Vt.priority-Ot.priority}),Mt}(g=K(g)),O=I.length,G=0;G<O;G++)this[I[G].unit](g[I[G].unit]);else if(v(this[g=tt(g)]))return this[g](E);return this},P.startOf=function(g){var E,I;if((g=tt(g))===void 0||g==="millisecond"||!this.isValid())return this;switch(I=this._isUTC?hR:uR,g){case"year":E=I(this.year(),0,1);break;case"quarter":E=I(this.year(),this.month()-this.month()%3,1);break;case"month":E=I(this.year(),this.month(),1);break;case"week":E=I(this.year(),this.month(),this.date()-this.weekday());break;case"isoWeek":E=I(this.year(),this.month(),this.date()-(this.isoWeekday()-1));break;case"day":case"date":E=I(this.year(),this.month(),this.date());break;case"hour":E=this._d.valueOf(),E-=ml(E+(this._isUTC?0:6e4*this.utcOffset()),36e5);break;case"minute":E=this._d.valueOf(),E-=ml(E,6e4);break;case"second":E=this._d.valueOf(),E-=ml(E,1e3);break}return this._d.setTime(E),n.updateOffset(this,!0),this},P.subtract=Ze,P.toArray=function(){var g=this;return[g.year(),g.month(),g.date(),g.hour(),g.minute(),g.second(),g.millisecond()]},P.toObject=function(){var g=this;return{years:g.year(),months:g.month(),date:g.date(),hours:g.hours(),minutes:g.minutes(),seconds:g.seconds(),milliseconds:g.milliseconds()}},P.toDate=function(){return new Date(this.valueOf())},P.toISOString=function(g){if(!this.isValid())return null;var E=(g=g!==!0)?this.clone().utc():this;return E.year()<0||9999<E.year()?$(E,g?"YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYYYY-MM-DD[T]HH:mm:ss.SSSZ"):v(Date.prototype.toISOString)?g?this.toDate().toISOString():new Date(this.valueOf()+60*this.utcOffset()*1e3).toISOString().replace("Z",$(E,"Z")):$(E,g?"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYY-MM-DD[T]HH:mm:ss.SSSZ")},P.inspect=function(){if(!this.isValid())return"moment.invalid(/* "+this._i+" */)";var g,E="moment",I="";return this.isLocal()||(E=this.utcOffset()===0?"moment.utc":"moment.parseZone",I="Z"),E="["+E+'("]',g=0<=this.year()&&this.year()<=9999?"YYYY":"YYYYYY",this.format(E+g+"-MM-DD[T]HH:mm:ss.SSS"+(I+'[")]'))},typeof Symbol<"u"&&Symbol.for!=null&&(P[Symbol.for("nodejs.util.inspect.custom")]=function(){return"Moment<"+this.format()+">"}),P.toJSON=function(){return this.isValid()?this.toISOString():null},P.toString=function(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")},P.unix=function(){return Math.floor(this.valueOf()/1e3)},P.valueOf=function(){return this._d.valueOf()-6e4*(this._offset||0)},P.creationData=function(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}},P.eraName=function(){for(var g,E=this.localeData().eras(),I=0,O=E.length;I<O;++I)if(g=this.clone().startOf("day").valueOf(),E[I].since<=g&&g<=E[I].until||E[I].until<=g&&g<=E[I].since)return E[I].name;return""},P.eraNarrow=function(){for(var g,E=this.localeData().eras(),I=0,O=E.length;I<O;++I)if(g=this.clone().startOf("day").valueOf(),E[I].since<=g&&g<=E[I].until||E[I].until<=g&&g<=E[I].since)return E[I].narrow;return""},P.eraAbbr=function(){for(var g,E=this.localeData().eras(),I=0,O=E.length;I<O;++I)if(g=this.clone().startOf("day").valueOf(),E[I].since<=g&&g<=E[I].until||E[I].until<=g&&g<=E[I].since)return E[I].abbr;return""},P.eraYear=function(){for(var g,E,I=this.localeData().eras(),O=0,G=I.length;O<G;++O)if(g=I[O].since<=I[O].until?1:-1,E=this.clone().startOf("day").valueOf(),I[O].since<=E&&E<=I[O].until||I[O].until<=E&&E<=I[O].since)return(this.year()-n(I[O].since).year())*g+I[O].offset;return this.year()},P.year=N0,P.isLeapYear=function(){return V(this.year())},P.weekYear=function(g){return fR.call(this,g,this.week(),this.weekday(),this.localeData()._week.dow,this.localeData()._week.doy)},P.isoWeekYear=function(g){return fR.call(this,g,this.isoWeek(),this.isoWeekday(),1,4)},P.quarter=P.quarters=function(g){return g==null?Math.ceil((this.month()+1)/3):this.month(3*(g-1)+this.month()%3)},P.month=se,P.daysInMonth=function(){return yt(this.year(),this.month())},P.week=P.weeks=function(g){var E=this.localeData().week(this);return g==null?E:this.add(7*(g-E),"d")},P.isoWeek=P.isoWeeks=function(g){var E=Ke(this,1,4).week;return g==null?E:this.add(7*(g-E),"d")},P.weeksInYear=function(){var g=this.localeData()._week;return wr(this.year(),g.dow,g.doy)},P.weeksInWeekYear=function(){var g=this.localeData()._week;return wr(this.weekYear(),g.dow,g.doy)},P.isoWeeksInYear=function(){return wr(this.year(),1,4)},P.isoWeeksInISOWeekYear=function(){return wr(this.isoWeekYear(),1,4)},P.date=ls,P.day=P.days=function(g){if(!this.isValid())return g!=null?this:NaN;var E,I,O=this._isUTC?this._d.getUTCDay():this._d.getDay();return g!=null?(E=g,I=this.localeData(),g=typeof E!="string"?E:isNaN(E)?typeof(E=I.weekdaysParse(E))=="number"?E:null:parseInt(E,10),this.add(g-O,"d")):O},P.weekday=function(g){if(!this.isValid())return g!=null?this:NaN;var E=(this.day()+7-this.localeData()._week.dow)%7;return g==null?E:this.add(g-E,"d")},P.isoWeekday=function(g){return this.isValid()?g!=null?(E=g,I=this.localeData(),I=typeof E=="string"?I.weekdaysParse(E)%7||7:isNaN(E)?null:E,this.day(this.day()%7?I:I-7)):this.day()||7:g!=null?this:NaN;var E,I},P.dayOfYear=function(g){var E=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return g==null?E:this.add(g-E,"d")},P.hour=P.hours=Tt,P.minute=P.minutes=to,P.second=P.seconds=ss,P.millisecond=P.milliseconds=os,P.utcOffset=function(g,E,I){var O,G=this._offset||0;if(!this.isValid())return g!=null?this:NaN;if(g==null)return this._isUTC?G:c_(this);if(typeof g=="string"){if((g=Qs(vt,g))===null)return this}else Math.abs(g)<16&&!I&&(g*=60);return!this._isUTC&&E&&(O=c_(this)),this._offset=g,this._isUTC=!0,O!=null&&this.add(O,"m"),G!==g&&(!E||this._changeInProgress?aR(this,vi(g-G,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,n.updateOffset(this,!0),this._changeInProgress=null)),this},P.utc=function(g){return this.utcOffset(0,g)},P.local=function(g){return this._isUTC&&(this.utcOffset(0,g),this._isUTC=!1,g&&this.subtract(c_(this),"m")),this},P.parseZone=function(){var g;return this._tzm!=null?this.utcOffset(this._tzm,!1,!0):typeof this._i=="string"&&((g=Qs(mt,this._i))!=null?this.utcOffset(g):this.utcOffset(0,!0)),this},P.hasAlignedHourOffset=function(g){return!!this.isValid()&&(g=g?De(g).utcOffset():0,(this.utcOffset()-g)%60==0)},P.isDST=function(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()},P.isLocal=function(){return!!this.isValid()&&!this._isUTC},P.isUtcOffset=function(){return!!this.isValid()&&this._isUTC},P.isUtc=rR,P.isUTC=rR,P.zoneAbbr=function(){return this._isUTC?"UTC":""},P.zoneName=function(){return this._isUTC?"Coordinated Universal Time":""},P.dates=R("dates accessor is deprecated. Use date instead.",ls),P.months=R("months accessor is deprecated. Use month instead",se),P.years=R("years accessor is deprecated. Use year instead",N0),P.zone=R("moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/",function(g,E){return g!=null?(this.utcOffset(g=typeof g!="string"?-g:g,E),this):-this.utcOffset()}),P.isDSTShifted=R("isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information",function(){if(!l(this._isDSTShifted))return this._isDSTShifted;var g,E={};return T(E,this),(E=M0(E))._a?(g=(E._isUTC?p:De)(E._a),this._isDSTShifted=this.isValid()&&0<function(I,O,G){for(var ht=Math.min(I.length,O.length),xt=Math.abs(I.length-O.length),Mt=0,Vt=0;Vt<ht;Vt++)(G&&I[Vt]!==O[Vt]||!G&&q(I[Vt])!==q(O[Vt]))&&Mt++;return Mt+xt}(E._a,g.toArray())):this._isDSTShifted=!1,this._isDSTShifted}),fe=w.prototype;function I0(g,E,I,ht){var G=ce(),ht=p().set(ht,E);return G[I](ht,g)}function pR(g,E,I){if(u(g)&&(E=g,g=void 0),g=g||"",E!=null)return I0(g,E,I,"month");for(var O=[],G=0;G<12;G++)O[G]=I0(g,G,I,"month");return O}function f_(g,E,I,O){E=(typeof g=="boolean"?u(E)&&(I=E,E=void 0):(E=g,g=!1,u(I=E)&&(I=E,E=void 0)),E||"");var G,ht=ce(),xt=g?ht._week.dow:0,Mt=[];if(I!=null)return I0(E,(I+xt)%7,O,"day");for(G=0;G<7;G++)Mt[G]=I0(E,(G+xt)%7,O,"day");return Mt}fe.calendar=function(g,E,I){return v(g=this._calendar[g]||this._calendar.sameElse)?g.call(E,I):g},fe.longDateFormat=function(g){var E=this._longDateFormat[g],I=this._longDateFormat[g.toUpperCase()];return E||!I?E:(this._longDateFormat[g]=I.match(z).map(function(O){return O==="MMMM"||O==="MM"||O==="DD"||O==="dddd"?O.slice(1):O}).join(""),this._longDateFormat[g])},fe.invalidDate=function(){return this._invalidDate},fe.ordinal=function(g){return this._ordinal.replace("%d",g)},fe.preparse=dR,fe.postformat=dR,fe.relativeTime=function(g,E,I,O){var G=this._relativeTime[I];return v(G)?G(g,E,I,O):G.replace(/%d/i,g)},fe.pastFuture=function(g,E){return v(g=this._relativeTime[0<g?"future":"past"])?g(E):g.replace(/%s/i,E)},fe.set=function(g){var E,I;for(I in g)s(g,I)&&(v(E=g[I])?this[I]=E:this["_"+I]=E);this._config=g,this._dayOfMonthOrdinalParseLenient=new RegExp((this._dayOfMonthOrdinalParse.source||this._ordinalParse.source)+"|"+/\d{1,2}/.source)},fe.eras=function(g,E){for(var I,O=this._eras||ce("en")._eras,G=0,ht=O.length;G<ht;++G){switch(typeof O[G].since){case"string":I=n(O[G].since).startOf("day"),O[G].since=I.valueOf();break}switch(typeof O[G].until){case"undefined":O[G].until=1/0;break;case"string":I=n(O[G].until).startOf("day").valueOf(),O[G].until=I.valueOf();break}}return O},fe.erasParse=function(g,E,I){var O,G,ht,xt,Mt,Vt=this.eras();for(g=g.toUpperCase(),O=0,G=Vt.length;O<G;++O)if(ht=Vt[O].name.toUpperCase(),xt=Vt[O].abbr.toUpperCase(),Mt=Vt[O].narrow.toUpperCase(),I)switch(E){case"N":case"NN":case"NNN":if(xt===g)return Vt[O];break;case"NNNN":if(ht===g)return Vt[O];break;case"NNNNN":if(Mt===g)return Vt[O];break}else if(0<=[ht,xt,Mt].indexOf(g))return Vt[O]},fe.erasConvertYear=function(g,E){var I=g.since<=g.until?1:-1;return E===void 0?n(g.since).year():n(g.since).year()+(E-g.offset)*I},fe.erasAbbrRegex=function(g){return s(this,"_erasAbbrRegex")||h_.call(this),g?this._erasAbbrRegex:this._erasRegex},fe.erasNameRegex=function(g){return s(this,"_erasNameRegex")||h_.call(this),g?this._erasNameRegex:this._erasRegex},fe.erasNarrowRegex=function(g){return s(this,"_erasNarrowRegex")||h_.call(this),g?this._erasNarrowRegex:this._erasRegex},fe.months=function(g,E){return g?(i(this._months)?this._months:this._months[(this._months.isFormat||ye).test(E)?"format":"standalone"])[g.month()]:i(this._months)?this._months:this._months.standalone},fe.monthsShort=function(g,E){return g?(i(this._monthsShort)?this._monthsShort:this._monthsShort[ye.test(E)?"format":"standalone"])[g.month()]:i(this._monthsShort)?this._monthsShort:this._monthsShort.standalone},fe.monthsParse=function(g,E,I){var O,G;if(this._monthsParseExact)return function(ie,xt,Mt){var Vt,Ot,de,ie=ie.toLocaleLowerCase();if(!this._monthsParse)for(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[],Vt=0;Vt<12;++Vt)de=p([2e3,Vt]),this._shortMonthsParse[Vt]=this.monthsShort(de,"").toLocaleLowerCase(),this._longMonthsParse[Vt]=this.months(de,"").toLocaleLowerCase();return Mt?xt==="MMM"?(Ot=jt.call(this._shortMonthsParse,ie))!==-1?Ot:null:(Ot=jt.call(this._longMonthsParse,ie))!==-1?Ot:null:xt==="MMM"?(Ot=jt.call(this._shortMonthsParse,ie))!==-1||(Ot=jt.call(this._longMonthsParse,ie))!==-1?Ot:null:(Ot=jt.call(this._longMonthsParse,ie))!==-1||(Ot=jt.call(this._shortMonthsParse,ie))!==-1?Ot:null}.call(this,g,E,I);for(this._monthsParse||(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[]),O=0;O<12;O++)if(G=p([2e3,O]),I&&!this._longMonthsParse[O]&&(this._longMonthsParse[O]=new RegExp("^"+this.months(G,"").replace(".","")+"$","i"),this._shortMonthsParse[O]=new RegExp("^"+this.monthsShort(G,"").replace(".","")+"$","i")),I||this._monthsParse[O]||(G="^"+this.months(G,"")+"|^"+this.monthsShort(G,""),this._monthsParse[O]=new RegExp(G.replace(".",""),"i")),I&&E==="MMMM"&&this._longMonthsParse[O].test(g)||I&&E==="MMM"&&this._shortMonthsParse[O].test(g)||!I&&this._monthsParse[O].test(g))return O},fe.monthsRegex=function(g){return this._monthsParseExact?(s(this,"_monthsRegex")||me.call(this),g?this._monthsStrictRegex:this._monthsRegex):(s(this,"_monthsRegex")||(this._monthsRegex=Te),this._monthsStrictRegex&&g?this._monthsStrictRegex:this._monthsRegex)},fe.monthsShortRegex=function(g){return this._monthsParseExact?(s(this,"_monthsRegex")||me.call(this),g?this._monthsShortStrictRegex:this._monthsShortRegex):(s(this,"_monthsShortRegex")||(this._monthsShortRegex=be),this._monthsShortStrictRegex&&g?this._monthsShortStrictRegex:this._monthsShortRegex)},fe.week=function(g){return Ke(g,this._week.dow,this._week.doy).week},fe.firstDayOfYear=function(){return this._week.doy},fe.firstDayOfWeek=function(){return this._week.dow},fe.weekdays=function(g,E){return E=i(this._weekdays)?this._weekdays:this._weekdays[g&&g!==!0&&this._weekdays.isFormat.test(E)?"format":"standalone"],g===!0?Ge(E,this._week.dow):g?E[g.day()]:E},fe.weekdaysMin=function(g){return g===!0?Ge(this._weekdaysMin,this._week.dow):g?this._weekdaysMin[g.day()]:this._weekdaysMin},fe.weekdaysShort=function(g){return g===!0?Ge(this._weekdaysShort,this._week.dow):g?this._weekdaysShort[g.day()]:this._weekdaysShort},fe.weekdaysParse=function(g,E,I){var O,G;if(this._weekdaysParseExact)return function(ie,xt,Mt){var Vt,Ot,de,ie=ie.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],Vt=0;Vt<7;++Vt)de=p([2e3,1]).day(Vt),this._minWeekdaysParse[Vt]=this.weekdaysMin(de,"").toLocaleLowerCase(),this._shortWeekdaysParse[Vt]=this.weekdaysShort(de,"").toLocaleLowerCase(),this._weekdaysParse[Vt]=this.weekdays(de,"").toLocaleLowerCase();return Mt?xt==="dddd"?(Ot=jt.call(this._weekdaysParse,ie))!==-1?Ot:null:xt==="ddd"?(Ot=jt.call(this._shortWeekdaysParse,ie))!==-1?Ot:null:(Ot=jt.call(this._minWeekdaysParse,ie))!==-1?Ot:null:xt==="dddd"?(Ot=jt.call(this._weekdaysParse,ie))!==-1||(Ot=jt.call(this._shortWeekdaysParse,ie))!==-1||(Ot=jt.call(this._minWeekdaysParse,ie))!==-1?Ot:null:xt==="ddd"?(Ot=jt.call(this._shortWeekdaysParse,ie))!==-1||(Ot=jt.call(this._weekdaysParse,ie))!==-1||(Ot=jt.call(this._minWeekdaysParse,ie))!==-1?Ot:null:(Ot=jt.call(this._minWeekdaysParse,ie))!==-1||(Ot=jt.call(this._weekdaysParse,ie))!==-1||(Ot=jt.call(this._shortWeekdaysParse,ie))!==-1?Ot:null}.call(this,g,E,I);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),O=0;O<7;O++)if(G=p([2e3,1]).day(O),I&&!this._fullWeekdaysParse[O]&&(this._fullWeekdaysParse[O]=new RegExp("^"+this.weekdays(G,"").replace(".","\\.?")+"$","i"),this._shortWeekdaysParse[O]=new RegExp("^"+this.weekdaysShort(G,"").replace(".","\\.?")+"$","i"),this._minWeekdaysParse[O]=new RegExp("^"+this.weekdaysMin(G,"").replace(".","\\.?")+"$","i")),this._weekdaysParse[O]||(G="^"+this.weekdays(G,"")+"|^"+this.weekdaysShort(G,"")+"|^"+this.weekdaysMin(G,""),this._weekdaysParse[O]=new RegExp(G.replace(".",""),"i")),I&&E==="dddd"&&this._fullWeekdaysParse[O].test(g)||I&&E==="ddd"&&this._shortWeekdaysParse[O].test(g)||I&&E==="dd"&&this._minWeekdaysParse[O].test(g)||!I&&this._weekdaysParse[O].test(g))return O},fe.weekdaysRegex=function(g){return this._weekdaysParseExact?(s(this,"_weekdaysRegex")||ze.call(this),g?this._weekdaysStrictRegex:this._weekdaysRegex):(s(this,"_weekdaysRegex")||(this._weekdaysRegex=At),this._weekdaysStrictRegex&&g?this._weekdaysStrictRegex:this._weekdaysRegex)},fe.weekdaysShortRegex=function(g){return this._weekdaysParseExact?(s(this,"_weekdaysRegex")||ze.call(this),g?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(s(this,"_weekdaysShortRegex")||(this._weekdaysShortRegex=Nt),this._weekdaysShortStrictRegex&&g?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)},fe.weekdaysMinRegex=function(g){return this._weekdaysParseExact?(s(this,"_weekdaysRegex")||ze.call(this),g?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(s(this,"_weekdaysMinRegex")||(this._weekdaysMinRegex=Jt),this._weekdaysMinStrictRegex&&g?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)},fe.isPM=function(g){return(g+"").toLowerCase().charAt(0)==="p"},fe.meridiem=function(g,E,I){return 11<g?I?"pm":"PM":I?"am":"AM"},Xt("en",{eras:[{since:"0001-01-01",until:1/0,offset:1,name:"Anno Domini",narrow:"AD",abbr:"AD"},{since:"0000-12-31",until:-1/0,offset:1,name:"Before Christ",narrow:"BC",abbr:"BC"}],dayOfMonthOrdinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(g){var E=g%10;return g+(q(g%100/10)===1?"th":E==1?"st":E==2?"nd":E==3?"rd":"th")}}),n.lang=R("moment.lang is deprecated. Use moment.locale instead.",Xt),n.langData=R("moment.langData is deprecated. Use moment.localeData instead.",ce);var wa=Math.abs;function gR(g,E,I,O){return E=vi(E,I),g._milliseconds+=O*E._milliseconds,g._days+=O*E._days,g._months+=O*E._months,g._bubble()}function yR(g){return g<0?Math.floor(g):Math.ceil(g)}function mR(g){return 4800*g/146097}function d_(g){return 146097*g/4800}function Ta(g){return function(){return this.as(g)}}Rt=Ta("ms"),et=Ta("s"),ne=Ta("m"),Lt=Ta("h"),It=Ta("d"),Ze=Ta("w"),Tt=Ta("M"),to=Ta("Q"),ss=Ta("y");function eo(g){return function(){return this.isValid()?this._data[g]:NaN}}var os=eo("milliseconds"),ls=eo("seconds"),N0=eo("minutes"),fe=eo("hours"),Ist=eo("days"),Nst=eo("months"),Bst=eo("years"),Ea=Math.round,bl={ss:44,s:45,m:45,h:22,d:26,w:null,M:11};function Dst(g,E,I,O){var Ot=vi(g).abs(),de=Ea(Ot.as("s")),G=Ea(Ot.as("m")),ht=Ea(Ot.as("h")),xt=Ea(Ot.as("d")),Mt=Ea(Ot.as("M")),Vt=Ea(Ot.as("w")),Ot=Ea(Ot.as("y")),de=(de<=I.ss?["s",de]:de<I.s&&["ss",de])||G<=1&&["m"]||G<I.m&&["mm",G]||ht<=1&&["h"]||ht<I.h&&["hh",ht]||xt<=1&&["d"]||xt<I.d&&["dd",xt];return(de=(de=I.w!=null?de||Vt<=1&&["w"]||Vt<I.w&&["ww",Vt]:de)||Mt<=1&&["M"]||Mt<I.M&&["MM",Mt]||Ot<=1&&["y"]||["yy",Ot])[2]=E,de[3]=0<+g,de[4]=O,function(ie,er,br,xi,g_){return g_.relativeTime(er||1,!!br,ie,xi)}.apply(null,de)}var p_=Math.abs;function _l(g){return(0<g)-(g<0)||+g}function B0(){if(!this.isValid())return this.localeData().invalidDate();var g,E,I,O,G,ht,xt,Mt=p_(this._milliseconds)/1e3,Vt=p_(this._days),Ot=p_(this._months),de=this.asSeconds();return de?(g=Q(Mt/60),E=Q(g/60),Mt%=60,g%=60,I=Q(Ot/12),Ot%=12,O=Mt?Mt.toFixed(3).replace(/\.?0+$/,""):"",G=_l(this._months)!==_l(de)?"-":"",ht=_l(this._days)!==_l(de)?"-":"",xt=_l(this._milliseconds)!==_l(de)?"-":"",(de<0?"-":"")+"P"+(I?G+I+"Y":"")+(Ot?G+Ot+"M":"")+(Vt?ht+Vt+"D":"")+(E||g||Mt?"T":"")+(E?xt+E+"H":"")+(g?xt+g+"M":"")+(Mt?xt+O+"S":"")):"P0D"}var Be=_i.prototype;return Be.isValid=function(){return this._isValid},Be.abs=function(){var g=this._data;return this._milliseconds=wa(this._milliseconds),this._days=wa(this._days),this._months=wa(this._months),g.milliseconds=wa(g.milliseconds),g.seconds=wa(g.seconds),g.minutes=wa(g.minutes),g.hours=wa(g.hours),g.months=wa(g.months),g.years=wa(g.years),this},Be.add=function(g,E){return gR(this,g,E,1)},Be.subtract=function(g,E){return gR(this,g,E,-1)},Be.as=function(g){if(!this.isValid())return NaN;var E,I,O=this._milliseconds;if((g=tt(g))==="month"||g==="quarter"||g==="year")switch(E=this._days+O/864e5,I=this._months+mR(E),g){case"month":return I;case"quarter":return I/3;case"year":return I/12}else switch(E=this._days+Math.round(d_(this._months)),g){case"week":return E/7+O/6048e5;case"day":return E+O/864e5;case"hour":return 24*E+O/36e5;case"minute":return 1440*E+O/6e4;case"second":return 86400*E+O/1e3;case"millisecond":return Math.floor(864e5*E)+O;default:throw new Error("Unknown unit "+g)}},Be.asMilliseconds=Rt,Be.asSeconds=et,Be.asMinutes=ne,Be.asHours=Lt,Be.asDays=It,Be.asWeeks=Ze,Be.asMonths=Tt,Be.asQuarters=to,Be.asYears=ss,Be.valueOf=function(){return this.isValid()?this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*q(this._months/12):NaN},Be._bubble=function(){var g=this._milliseconds,E=this._days,I=this._months,O=this._data;return 0<=g&&0<=E&&0<=I||g<=0&&E<=0&&I<=0||(g+=864e5*yR(d_(I)+E),I=E=0),O.milliseconds=g%1e3,g=Q(g/1e3),O.seconds=g%60,g=Q(g/60),O.minutes=g%60,g=Q(g/60),O.hours=g%24,E+=Q(g/24),I+=g=Q(mR(E)),E-=yR(d_(g)),g=Q(I/12),I%=12,O.days=E,O.months=I,O.years=g,this},Be.clone=function(){return vi(this)},Be.get=function(g){return g=tt(g),this.isValid()?this[g+"s"]():NaN},Be.milliseconds=os,Be.seconds=ls,Be.minutes=N0,Be.hours=fe,Be.days=Ist,Be.weeks=function(){return Q(this.days()/7)},Be.months=Nst,Be.years=Bst,Be.humanize=function(g,E){if(!this.isValid())return this.localeData().invalidDate();var I=!1,O=bl;return typeof g=="object"&&(E=g,g=!1),typeof g=="boolean"&&(I=g),typeof E=="object"&&(O=Object.assign({},bl,E),E.s!=null&&E.ss==null&&(O.ss=E.s-1)),g=this.localeData(),E=Dst(this,!I,O,g),I&&(E=g.pastFuture(+this,E)),g.postformat(E)},Be.toISOString=B0,Be.toString=B0,Be.toJSON=B0,Be.locale=oR,Be.localeData=lR,Be.toIsoString=R("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",B0),Be.lang=st,Y("X",0,0,"unix"),Y("x",0,0,"valueOf"),ft("x",pt),ft("X",/[+-]?\d+(\.\d{1,3})?/),Qt("X",function(g,E,I){I._d=new Date(1e3*parseFloat(g))}),Qt("x",function(g,E,I){I._d=new Date(q(g))}),n.version="2.29.4",r=De,n.fn=P,n.min=function(){return hn("isBefore",[].slice.call(arguments,0))},n.max=function(){return hn("isAfter",[].slice.call(arguments,0))},n.now=function(){return Date.now?Date.now():+new Date},n.utc=p,n.unix=function(g){return De(1e3*g)},n.months=function(g,E){return pR(g,E,"months")},n.isDate=h,n.locale=Xt,n.invalid=y,n.duration=vi,n.isMoment=M,n.weekdays=function(g,E,I){return f_(g,E,I,"weekdays")},n.parseZone=function(){return De.apply(null,arguments).parseZone()},n.localeData=ce,n.isDuration=ka,n.monthsShort=function(g,E){return pR(g,E,"monthsShort")},n.weekdaysMin=function(g,E,I){return f_(g,E,I,"weekdaysMin")},n.defineLocale=ee,n.updateLocale=function(g,E){var I,O;return E!=null?(O=va,Ce[g]!=null&&Ce[g].parentLocale!=null?Ce[g].set(B(Ce[g]._config,E)):(E=B(O=(I=Ln(g))!=null?I._config:O,E),I==null&&(E.abbr=g),(O=new w(E)).parentLocale=Ce[g],Ce[g]=O),Xt(g)):Ce[g]!=null&&(Ce[g].parentLocale!=null?(Ce[g]=Ce[g].parentLocale,g===Xt()&&Xt(g)):Ce[g]!=null&&delete Ce[g]),Ce[g]},n.locales=function(){return D(Ce)},n.weekdaysShort=function(g,E,I){return f_(g,E,I,"weekdaysShort")},n.normalizeUnits=tt,n.relativeTimeRounding=function(g){return g===void 0?Ea:typeof g=="function"&&(Ea=g,!0)},n.relativeTimeThreshold=function(g,E){return bl[g]!==void 0&&(E===void 0?bl[g]:(bl[g]=E,g==="s"&&(bl.ss=E-1),!0))},n.calendarFormat=function(g,E){return(g=g.diff(E,"days",!0))<-6?"sameElse":g<-1?"lastWeek":g<0?"lastDay":g<1?"sameDay":g<2?"nextDay":g<7?"nextWeek":"sameElse"},n.prototype=P,n.HTML5_FMT={DATETIME_LOCAL:"YYYY-MM-DDTHH:mm",DATETIME_LOCAL_SECONDS:"YYYY-MM-DDTHH:mm:ss",DATETIME_LOCAL_MS:"YYYY-MM-DDTHH:mm:ss.SSS",DATE:"YYYY-MM-DD",TIME:"HH:mm",TIME_SECONDS:"HH:mm:ss",TIME_MS:"HH:mm:ss.SSS",WEEK:"GGGG-[W]WW",MONTH:"YYYY-MM"},n})})(y_);const Xn=y_.exports,ji={trace:0,debug:1,info:2,warn:3,error:4,fatal:5},H={trace:(...t)=>{},debug:(...t)=>{},info:(...t)=>{},warn:(...t)=>{},error:(...t)=>{},fatal:(...t)=>{}},D0=function(t="fatal"){let e=ji.fatal;typeof t=="string"?(t=t.toLowerCase(),t in ji&&(e=ji[t])):typeof t=="number"&&(e=t),H.trace=()=>{},H.debug=()=>{},H.info=()=>{},H.warn=()=>{},H.error=()=>{},H.fatal=()=>{},e<=ji.fatal&&(H.fatal=console.error?console.error.bind(console,Nn("FATAL"),"color: orange"):console.log.bind(console,"\x1B[35m",Nn("FATAL"))),e<=ji.error&&(H.error=console.error?console.error.bind(console,Nn("ERROR"),"color: orange"):console.log.bind(console,"\x1B[31m",Nn("ERROR"))),e<=ji.warn&&(H.warn=console.warn?console.warn.bind(console,Nn("WARN"),"color: orange"):console.log.bind(console,"\x1B[33m",Nn("WARN"))),e<=ji.info&&(H.info=console.info?console.info.bind(console,Nn("INFO"),"color: lightblue"):console.log.bind(console,"\x1B[34m",Nn("INFO"))),e<=ji.debug&&(H.debug=console.debug?console.debug.bind(console,Nn("DEBUG"),"color: lightgreen"):console.log.bind(console,"\x1B[32m",Nn("DEBUG"))),e<=ji.trace&&(H.trace=console.debug?console.debug.bind(console,Nn("TRACE"),"color: lightgreen"):console.log.bind(console,"\x1B[32m",Nn("TRACE")))},Nn=t=>`%c${Xn().format("ss.SSS")} : ${t} : `;var O0={};Object.defineProperty(O0,"__esModule",{value:!0});var ki=O0.sanitizeUrl=void 0,bR=/^([^\w]*)(javascript|data|vbscript)/im,_R=/&#(\w+)(^\w|;)?/g,vR=/[\u0000-\u001F\u007F-\u009F\u2000-\u200D\uFEFF]/gim,xR=/^([^:]+):/gm,kR=[".","/"];function wR(t){return kR.indexOf(t[0])>-1}function TR(t){return t.replace(_R,function(e,r){return String.fromCharCode(r)})}function ER(t){var e=TR(t||"").replace(vR,"").trim();if(!e)return"about:blank";if(wR(e))return e;var r=e.match(xR);if(!r)return e;var n=r[0];return bR.test(n)?"about:blank":e}ki=O0.sanitizeUrl=ER;function Qe(t,e){return t==null||e==null?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function m_(t,e){return t==null||e==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function ku(t){let e,r,n;t.length!==2?(e=Qe,r=(o,l)=>Qe(t(o),l),n=(o,l)=>t(o)-l):(e=t===Qe||t===m_?t:CR,r=t,n=t);function i(o,l,u=0,h=o.length){if(u<h){if(e(l,l)!==0)return h;do{const d=u+h>>>1;r(o[d],l)<0?u=d+1:h=d}while(u<h)}return u}function a(o,l,u=0,h=o.length){if(u<h){if(e(l,l)!==0)return h;do{const d=u+h>>>1;r(o[d],l)<=0?u=d+1:h=d}while(u<h)}return u}function s(o,l,u=0,h=o.length){const d=i(o,l,u,h-1);return d>u&&n(o[d-1],l)>-n(o[d],l)?d-1:d}return{left:i,center:s,right:a}}function CR(){return 0}function b_(t){return t===null?NaN:+t}function*__(t,e){if(e===void 0)for(let r of t)r!=null&&(r=+r)>=r&&(yield r);else{let r=-1;for(let n of t)(n=e(n,++r,t))!=null&&(n=+n)>=n&&(yield n)}}const v_=ku(Qe),x_=v_.right,SR=v_.left,AR=ku(b_).center,cs=x_;function MR(t,e){if(!((e=+e)>=0))throw new RangeError("invalid r");let r=t.length;if(!((r=Math.floor(r))>=0))throw new RangeError("invalid length");if(!r||!e)return t;const n=F0(e),i=t.slice();return n(t,i,0,r,1),n(i,t,0,r,1),n(t,i,0,r,1),t}const k_=w_(F0),LR=w_(RR);function w_(t){return function(e,r,n=r){if(!((r=+r)>=0))throw new RangeError("invalid rx");if(!((n=+n)>=0))throw new RangeError("invalid ry");let{data:i,width:a,height:s}=e;if(!((a=Math.floor(a))>=0))throw new RangeError("invalid width");if(!((s=Math.floor(s!==void 0?s:i.length/a))>=0))throw new RangeError("invalid height");if(!a||!s||!r&&!n)return e;const o=r&&t(r),l=n&&t(n),u=i.slice();return o&&l?(ro(o,u,i,a,s),ro(o,i,u,a,s),ro(o,u,i,a,s),no(l,i,u,a,s),no(l,u,i,a,s),no(l,i,u,a,s)):o?(ro(o,i,u,a,s),ro(o,u,i,a,s),ro(o,i,u,a,s)):l&&(no(l,i,u,a,s),no(l,u,i,a,s),no(l,i,u,a,s)),e}}function ro(t,e,r,n,i){for(let a=0,s=n*i;a<s;)t(e,r,a,a+=n,1)}function no(t,e,r,n,i){for(let a=0,s=n*i;a<n;++a)t(e,r,a,a+s,n)}function RR(t){const e=F0(t);return(r,n,i,a,s)=>{i<<=2,a<<=2,s<<=2,e(r,n,i+0,a+0,s),e(r,n,i+1,a+1,s),e(r,n,i+2,a+2,s),e(r,n,i+3,a+3,s)}}function F0(t){const e=Math.floor(t);if(e===t)return IR(t);const r=t-e,n=2*t+1;return(i,a,s,o,l)=>{if(!((o-=l)>=s))return;let u=e*a[s];const h=l*e,d=h+l;for(let f=s,p=s+h;f<p;f+=l)u+=a[Math.min(o,f)];for(let f=s,p=o;f<=p;f+=l)u+=a[Math.min(o,f+h)],i[f]=(u+r*(a[Math.max(s,f-d)]+a[Math.min(o,f+d)]))/n,u-=a[Math.max(s,f-h)]}}function IR(t){const e=2*t+1;return(r,n,i,a,s)=>{if(!((a-=s)>=i))return;let o=t*n[i];const l=s*t;for(let u=i,h=i+l;u<h;u+=s)o+=n[Math.min(a,u)];for(let u=i,h=a;u<=h;u+=s)o+=n[Math.min(a,u+l)],r[u]=o/e,o-=n[Math.max(i,u-l)]}}function wu(t,e){let r=0;if(e===void 0)for(let n of t)n!=null&&(n=+n)>=n&&++r;else{let n=-1;for(let i of t)(i=e(i,++n,t))!=null&&(i=+i)>=i&&++r}return r}function NR(t){return t.length|0}function BR(t){return!(t>0)}function DR(t){return typeof t!="object"||"length"in t?t:Array.from(t)}function OR(t){return e=>t(...e)}function FR(...t){const e=typeof t[t.length-1]=="function"&&OR(t.pop());t=t.map(DR);const r=t.map(NR),n=t.length-1,i=new Array(n+1).fill(0),a=[];if(n<0||r.some(BR))return a;for(;;){a.push(i.map((o,l)=>t[l][o]));let s=n;for(;++i[s]===r[s];){if(s===0)return e?a.map(e):a;i[s--]=0}}}function PR(t,e){var r=0,n=0;return Float64Array.from(t,e===void 0?i=>r+=+i||0:i=>r+=+e(i,n++,t)||0)}function T_(t,e){let r=0,n,i=0,a=0;if(e===void 0)for(let s of t)s!=null&&(s=+s)>=s&&(n=s-i,i+=n/++r,a+=n*(s-i));else{let s=-1;for(let o of t)(o=e(o,++s,t))!=null&&(o=+o)>=o&&(n=o-i,i+=n/++r,a+=n*(o-i))}if(r>1)return a/(r-1)}function E_(t,e){const r=T_(t,e);return r&&Math.sqrt(r)}function xl(t,e){let r,n;if(e===void 0)for(const i of t)i!=null&&(r===void 0?i>=i&&(r=n=i):(r>i&&(r=i),n<i&&(n=i)));else{let i=-1;for(let a of t)(a=e(a,++i,t))!=null&&(r===void 0?a>=a&&(r=n=a):(r>a&&(r=a),n<a&&(n=a)))}return[r,n]}class _r{constructor(){this._partials=new Float64Array(32),this._n=0}add(e){const r=this._partials;let n=0;for(let i=0;i<this._n&&i<32;i++){const a=r[i],s=e+a,o=Math.abs(e)<Math.abs(a)?e-(s-a):a-(s-e);o&&(r[n++]=o),e=s}return r[n]=e,this._n=n+1,this}valueOf(){const e=this._partials;let r=this._n,n,i,a,s=0;if(r>0){for(s=e[--r];r>0&&(n=s,i=e[--r],s=n+i,a=i-(s-n),!a););r>0&&(a<0&&e[r-1]<0||a>0&&e[r-1]>0)&&(i=a*2,n=s+i,i==n-s&&(s=n))}return s}}function qR(t,e){const r=new _r;if(e===void 0)for(let n of t)(n=+n)&&r.add(n);else{let n=-1;for(let i of t)(i=+e(i,++n,t))&&r.add(i)}return+r}function VR(t,e){const r=new _r;let n=-1;return Float64Array.from(t,e===void 0?i=>r.add(+i||0):i=>r.add(+e(i,++n,t)||0))}class kl extends Map{constructor(e,r=A_){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:r}}),e!=null)for(const[n,i]of e)this.set(n,i)}get(e){return super.get(P0(this,e))}has(e){return super.has(P0(this,e))}set(e,r){return super.set(C_(this,e),r)}delete(e){return super.delete(S_(this,e))}}class us extends Set{constructor(e,r=A_){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:r}}),e!=null)for(const n of e)this.add(n)}has(e){return super.has(P0(this,e))}add(e){return super.add(C_(this,e))}delete(e){return super.delete(S_(this,e))}}function P0({_intern:t,_key:e},r){const n=e(r);return t.has(n)?t.get(n):r}function C_({_intern:t,_key:e},r){const n=e(r);return t.has(n)?t.get(n):(t.set(n,r),r)}function S_({_intern:t,_key:e},r){const n=e(r);return t.has(n)&&(r=t.get(n),t.delete(n)),r}function A_(t){return t!==null&&typeof t=="object"?t.valueOf():t}function io(t){return t}function M_(t,...e){return ao(t,io,io,e)}function L_(t,...e){return ao(t,Array.from,io,e)}function R_(t,e){for(let r=1,n=e.length;r<n;++r)t=t.flatMap(i=>i.pop().map(([a,s])=>[...i,a,s]));return t}function zR(t,...e){return R_(L_(t,...e),e)}function YR(t,e,...r){return R_(N_(t,e,...r),r)}function I_(t,e,...r){return ao(t,io,e,r)}function N_(t,e,...r){return ao(t,Array.from,e,r)}function UR(t,...e){return ao(t,io,B_,e)}function WR(t,...e){return ao(t,Array.from,B_,e)}function B_(t){if(t.length!==1)throw new Error("duplicate key");return t[0]}function ao(t,e,r,n){return function i(a,s){if(s>=n.length)return r(a);const o=new kl,l=n[s++];let u=-1;for(const h of a){const d=l(h,++u,a),f=o.get(d);f?f.push(h):o.set(d,[h])}for(const[h,d]of o)o.set(h,i(d,s));return e(o)}(t,0)}function D_(t,e){return Array.from(e,r=>t[r])}function q0(t,...e){if(typeof t[Symbol.iterator]!="function")throw new TypeError("values is not iterable");t=Array.from(t);let[r]=e;if(r&&r.length!==2||e.length>1){const n=Uint32Array.from(t,(i,a)=>a);return e.length>1?(e=e.map(i=>t.map(i)),n.sort((i,a)=>{for(const s of e){const o=so(s[i],s[a]);if(o)return o}})):(r=t.map(r),n.sort((i,a)=>so(r[i],r[a]))),D_(t,n)}return t.sort(V0(r))}function V0(t=Qe){if(t===Qe)return so;if(typeof t!="function")throw new TypeError("compare is not a function");return(e,r)=>{const n=t(e,r);return n||n===0?n:(t(r,r)===0)-(t(e,e)===0)}}function so(t,e){return(t==null||!(t>=t))-(e==null||!(e>=e))||(t<e?-1:t>e?1:0)}function HR(t,e,r){return(e.length!==2?q0(I_(t,e,r),([n,i],[a,s])=>Qe(i,s)||Qe(n,a)):q0(M_(t,r),([n,i],[a,s])=>e(i,s)||Qe(n,a))).map(([n])=>n)}var GR=Array.prototype,jR=GR.slice;function Tu(t){return()=>t}var z0=Math.sqrt(50),Y0=Math.sqrt(10),U0=Math.sqrt(2);function hs(t,e,r){var n,i=-1,a,s,o;if(e=+e,t=+t,r=+r,t===e&&r>0)return[t];if((n=e<t)&&(a=t,t=e,e=a),(o=oo(t,e,r))===0||!isFinite(o))return[];if(o>0){let l=Math.round(t/o),u=Math.round(e/o);for(l*o<t&&++l,u*o>e&&--u,s=new Array(a=u-l+1);++i<a;)s[i]=(l+i)*o}else{o=-o;let l=Math.round(t*o),u=Math.round(e*o);for(l/o<t&&++l,u/o>e&&--u,s=new Array(a=u-l+1);++i<a;)s[i]=(l+i)/o}return n&&s.reverse(),s}function oo(t,e,r){var n=(e-t)/Math.max(0,r),i=Math.floor(Math.log(n)/Math.LN10),a=n/Math.pow(10,i);return i>=0?(a>=z0?10:a>=Y0?5:a>=U0?2:1)*Math.pow(10,i):-Math.pow(10,-i)/(a>=z0?10:a>=Y0?5:a>=U0?2:1)}function wl(t,e,r){var n=Math.abs(e-t)/Math.max(0,r),i=Math.pow(10,Math.floor(Math.log(n)/Math.LN10)),a=n/i;return a>=z0?i*=10:a>=Y0?i*=5:a>=U0&&(i*=2),e<t?-i:i}function O_(t,e,r){let n;for(;;){const i=oo(t,e,r);if(i===n||i===0||!isFinite(i))return[t,e];i>0?(t=Math.floor(t/i)*i,e=Math.ceil(e/i)*i):i<0&&(t=Math.ceil(t*i)/i,e=Math.floor(e*i)/i),n=i}}function W0(t){return Math.ceil(Math.log(wu(t))/Math.LN2)+1}function F_(){var t=io,e=xl,r=W0;function n(i){Array.isArray(i)||(i=Array.from(i));var a,s=i.length,o,l,u=new Array(s);for(a=0;a<s;++a)u[a]=t(i[a],a,i);var h=e(u),d=h[0],f=h[1],p=r(u,d,f);if(!Array.isArray(p)){const b=f,x=+p;if(e===xl&&([d,f]=O_(d,f,x)),p=hs(d,f,x),p[0]<=d&&(l=oo(d,f,x)),p[p.length-1]>=f)if(b>=f&&e===xl){const k=oo(d,f,x);isFinite(k)&&(k>0?f=(Math.floor(f/k)+1)*k:k<0&&(f=(Math.ceil(f*-k)+1)/-k))}else p.pop()}for(var m=p.length;p[0]<=d;)p.shift(),--m;for(;p[m-1]>f;)p.pop(),--m;var _=new Array(m+1),y;for(a=0;a<=m;++a)y=_[a]=[],y.x0=a>0?p[a-1]:d,y.x1=a<m?p[a]:f;if(isFinite(l)){if(l>0)for(a=0;a<s;++a)(o=u[a])!=null&&d<=o&&o<=f&&_[Math.min(m,Math.floor((o-d)/l))].push(i[a]);else if(l<0){for(a=0;a<s;++a)if((o=u[a])!=null&&d<=o&&o<=f){const b=Math.floor((d-o)*l);_[Math.min(m,b+(p[b]<=o))].push(i[a])}}}else for(a=0;a<s;++a)(o=u[a])!=null&&d<=o&&o<=f&&_[cs(p,o,0,m)].push(i[a]);return _}return n.value=function(i){return arguments.length?(t=typeof i=="function"?i:Tu(i),n):t},n.domain=function(i){return arguments.length?(e=typeof i=="function"?i:Tu([i[0],i[1]]),n):e},n.thresholds=function(i){return arguments.length?(r=typeof i=="function"?i:Array.isArray(i)?Tu(jR.call(i)):Tu(i),n):r},n}function lo(t,e){let r;if(e===void 0)for(const n of t)n!=null&&(r<n||r===void 0&&n>=n)&&(r=n);else{let n=-1;for(let i of t)(i=e(i,++n,t))!=null&&(r<i||r===void 0&&i>=i)&&(r=i)}return r}function H0(t,e){let r,n=-1,i=-1;if(e===void 0)for(const a of t)++i,a!=null&&(r<a||r===void 0&&a>=a)&&(r=a,n=i);else for(let a of t)(a=e(a,++i,t))!=null&&(r<a||r===void 0&&a>=a)&&(r=a,n=i);return n}function Tl(t,e){let r;if(e===void 0)for(const n of t)n!=null&&(r>n||r===void 0&&n>=n)&&(r=n);else{let n=-1;for(let i of t)(i=e(i,++n,t))!=null&&(r>i||r===void 0&&i>=i)&&(r=i)}return r}function G0(t,e){let r,n=-1,i=-1;if(e===void 0)for(const a of t)++i,a!=null&&(r>a||r===void 0&&a>=a)&&(r=a,n=i);else for(let a of t)(a=e(a,++i,t))!=null&&(r>a||r===void 0&&a>=a)&&(r=a,n=i);return n}function Eu(t,e,r=0,n=t.length-1,i){for(i=i===void 0?so:V0(i);n>r;){if(n-r>600){const l=n-r+1,u=e-r+1,h=Math.log(l),d=.5*Math.exp(2*h/3),f=.5*Math.sqrt(h*d*(l-d)/l)*(u-l/2<0?-1:1),p=Math.max(r,Math.floor(e-u*d/l+f)),m=Math.min(n,Math.floor(e+(l-u)*d/l+f));Eu(t,e,p,m,i)}const a=t[e];let s=r,o=n;for(El(t,r,e),i(t[n],a)>0&&El(t,r,n);s<o;){for(El(t,s,o),++s,--o;i(t[s],a)<0;)++s;for(;i(t[o],a)>0;)--o}i(t[r],a)===0?El(t,r,o):(++o,El(t,o,n)),o<=e&&(r=o+1),e<=o&&(n=o-1)}return t}function El(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function P_(t,e=Qe){let r,n=!1;if(e.length===1){let i;for(const a of t){const s=e(a);(n?Qe(s,i)>0:Qe(s,s)===0)&&(r=a,i=s,n=!0)}}else for(const i of t)(n?e(i,r)>0:e(i,i)===0)&&(r=i,n=!0);return r}function Cl(t,e,r){if(t=Float64Array.from(__(t,r)),!!(n=t.length)){if((e=+e)<=0||n<2)return Tl(t);if(e>=1)return lo(t);var n,i=(n-1)*e,a=Math.floor(i),s=lo(Eu(t,a).subarray(0,a+1)),o=Tl(t.subarray(a+1));return s+(o-s)*(i-a)}}function q_(t,e,r=b_){if(!!(n=t.length)){if((e=+e)<=0||n<2)return+r(t[0],0,t);if(e>=1)return+r(t[n-1],n-1,t);var n,i=(n-1)*e,a=Math.floor(i),s=+r(t[a],a,t),o=+r(t[a+1],a+1,t);return s+(o-s)*(i-a)}}function V_(t,e,r){if(t=Float64Array.from(__(t,r)),!!(n=t.length)){if((e=+e)<=0||n<2)return G0(t);if(e>=1)return H0(t);var n,i=Math.floor((n-1)*e),a=(o,l)=>so(t[o],t[l]),s=Eu(Uint32Array.from(t,(o,l)=>l),i,0,n-1,a);return P_(s.subarray(0,i+1),o=>t[o])}}function $R(t,e,r){return Math.ceil((r-e)/(2*(Cl(t,.75)-Cl(t,.25))*Math.pow(wu(t),-1/3)))}function XR(t,e,r){return Math.ceil((r-e)*Math.cbrt(wu(t))/(3.49*E_(t)))}function KR(t,e){let r=0,n=0;if(e===void 0)for(let i of t)i!=null&&(i=+i)>=i&&(++r,n+=i);else{let i=-1;for(let a of t)(a=e(a,++i,t))!=null&&(a=+a)>=a&&(++r,n+=a)}if(r)return n/r}function ZR(t,e){return Cl(t,.5,e)}function QR(t,e){return V_(t,.5,e)}function*JR(t){for(const e of t)yield*e}function j0(t){return Array.from(JR(t))}function tI(t,e){const r=new kl;if(e===void 0)for(let a of t)a!=null&&a>=a&&r.set(a,(r.get(a)||0)+1);else{let a=-1;for(let s of t)(s=e(s,++a,t))!=null&&s>=s&&r.set(s,(r.get(s)||0)+1)}let n,i=0;for(const[a,s]of r)s>i&&(i=s,n=a);return n}function eI(t,e=rI){const r=[];let n,i=!1;for(const a of t)i&&r.push(e(n,a)),n=a,i=!0;return r}function rI(t,e){return[t,e]}function Ca(t,e,r){t=+t,e=+e,r=(i=arguments.length)<2?(e=t,t=0,1):i<3?1:+r;for(var n=-1,i=Math.max(0,Math.ceil((e-t)/r))|0,a=new Array(i);++n<i;)a[n]=t+n*r;return a}function nI(t,e=Qe){if(typeof t[Symbol.iterator]!="function")throw new TypeError("values is not iterable");let r=Array.from(t);const n=new Float64Array(r.length);e.length!==2&&(r=r.map(e),e=Qe);const i=(o,l)=>e(r[o],r[l]);let a,s;return Uint32Array.from(r,(o,l)=>l).sort(e===Qe?(o,l)=>so(r[o],r[l]):V0(i)).forEach((o,l)=>{const u=i(o,a===void 0?o:a);u>=0?((a===void 0||u>0)&&(a=o,s=l),n[o]=s):n[o]=NaN}),n}function iI(t,e=Qe){let r,n=!1;if(e.length===1){let i;for(const a of t){const s=e(a);(n?Qe(s,i)<0:Qe(s,s)===0)&&(r=a,i=s,n=!0)}}else for(const i of t)(n?e(i,r)<0:e(i,i)===0)&&(r=i,n=!0);return r}function z_(t,e=Qe){if(e.length===1)return G0(t,e);let r,n=-1,i=-1;for(const a of t)++i,(n<0?e(a,a)===0:e(a,r)<0)&&(r=a,n=i);return n}function aI(t,e=Qe){if(e.length===1)return H0(t,e);let r,n=-1,i=-1;for(const a of t)++i,(n<0?e(a,a)===0:e(a,r)>0)&&(r=a,n=i);return n}function sI(t,e){const r=z_(t,e);return r<0?void 0:r}const oI=Y_(Math.random);function Y_(t){return function(r,n=0,i=r.length){let a=i-(n=+n);for(;a;){const s=t()*a--|0,o=r[a+n];r[a+n]=r[s+n],r[s+n]=o}return r}}function lI(t,e){let r=0;if(e===void 0)for(let n of t)(n=+n)&&(r+=n);else{let n=-1;for(let i of t)(i=+e(i,++n,t))&&(r+=i)}return r}function U_(t){if(!(a=t.length))return[];for(var e=-1,r=Tl(t,cI),n=new Array(r);++e<r;)for(var i=-1,a,s=n[e]=new Array(a);++i<a;)s[i]=t[i][e];return n}function cI(t){return t.length}function uI(){return U_(arguments)}function hI(t,e){if(typeof e!="function")throw new TypeError("test is not a function");let r=-1;for(const n of t)if(!e(n,++r,t))return!1;return!0}function fI(t,e){if(typeof e!="function")throw new TypeError("test is not a function");let r=-1;for(const n of t)if(e(n,++r,t))return!0;return!1}function dI(t,e){if(typeof e!="function")throw new TypeError("test is not a function");const r=[];let n=-1;for(const i of t)e(i,++n,t)&&r.push(i);return r}function pI(t,e){if(typeof t[Symbol.iterator]!="function")throw new TypeError("values is not iterable");if(typeof e!="function")throw new TypeError("mapper is not a function");return Array.from(t,(r,n)=>e(r,n,t))}function gI(t,e,r){if(typeof e!="function")throw new TypeError("reducer is not a function");const n=t[Symbol.iterator]();let i,a,s=-1;if(arguments.length<3){if({done:i,value:r}=n.next(),i)return;++s}for(;{done:i,value:a}=n.next(),!i;)r=e(r,a,++s,t);return r}function yI(t){if(typeof t[Symbol.iterator]!="function")throw new TypeError("values is not iterable");return Array.from(t).reverse()}function mI(t,...e){t=new us(t);for(const r of e)for(const n of r)t.delete(n);return t}function bI(t,e){const r=e[Symbol.iterator](),n=new us;for(const i of t){if(n.has(i))return!1;let a,s;for(;({value:a,done:s}=r.next())&&!s;){if(Object.is(i,a))return!1;n.add(a)}}return!0}function _I(t,...e){t=new us(t),e=e.map(vI);t:for(const r of t)for(const n of e)if(!n.has(r)){t.delete(r);continue t}return t}function vI(t){return t instanceof us?t:new us(t)}function W_(t,e){const r=t[Symbol.iterator](),n=new Set;for(const i of e){const a=H_(i);if(n.has(a))continue;let s,o;for(;{value:s,done:o}=r.next();){if(o)return!1;const l=H_(s);if(n.add(l),Object.is(a,l))break}}return!0}function H_(t){return t!==null&&typeof t=="object"?t.valueOf():t}function xI(t,e){return W_(e,t)}function kI(...t){const e=new us;for(const r of t)for(const n of r)e.add(n);return e}function wI(t){return t}var Cu=1,Su=2,$0=3,Sl=4,G_=1e-6;function TI(t){return"translate("+t+",0)"}function EI(t){return"translate(0,"+t+")"}function CI(t){return e=>+t(e)}function SI(t,e){return e=Math.max(0,t.bandwidth()-e*2)/2,t.round()&&(e=Math.round(e)),r=>+t(r)+e}function AI(){return!this.__axis}function Au(t,e){var r=[],n=null,i=null,a=6,s=6,o=3,l=typeof window<"u"&&window.devicePixelRatio>1?0:.5,u=t===Cu||t===Sl?-1:1,h=t===Sl||t===Su?"x":"y",d=t===Cu||t===$0?TI:EI;function f(p){var m=n==null?e.ticks?e.ticks.apply(e,r):e.domain():n,_=i==null?e.tickFormat?e.tickFormat.apply(e,r):wI:i,y=Math.max(a,0)+o,b=e.range(),x=+b[0]+l,k=+b[b.length-1]+l,T=(e.bandwidth?SI:CI)(e.copy(),l),C=p.selection?p.selection():p,M=C.selectAll(".domain").data([null]),S=C.selectAll(".tick").data(m,e).order(),R=S.exit(),A=S.enter().append("g").attr("class","tick"),L=S.select("line"),v=S.select("text");M=M.merge(M.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),S=S.merge(A),L=L.merge(A.append("line").attr("stroke","currentColor").attr(h+"2",u*a)),v=v.merge(A.append("text").attr("fill","currentColor").attr(h,u*y).attr("dy",t===Cu?"0em":t===$0?"0.71em":"0.32em")),p!==C&&(M=M.transition(p),S=S.transition(p),L=L.transition(p),v=v.transition(p),R=R.transition(p).attr("opacity",G_).attr("transform",function(B){return isFinite(B=T(B))?d(B+l):this.getAttribute("transform")}),A.attr("opacity",G_).attr("transform",function(B){var w=this.parentNode.__axis;return d((w&&isFinite(w=w(B))?w:T(B))+l)})),R.remove(),M.attr("d",t===Sl||t===Su?s?"M"+u*s+","+x+"H"+l+"V"+k+"H"+u*s:"M"+l+","+x+"V"+k:s?"M"+x+","+u*s+"V"+l+"H"+k+"V"+u*s:"M"+x+","+l+"H"+k),S.attr("opacity",1).attr("transform",function(B){return d(T(B)+l)}),L.attr(h+"2",u*a),v.attr(h,u*y).text(_),C.filter(AI).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",t===Su?"start":t===Sl?"end":"middle"),C.each(function(){this.__axis=T})}return f.scale=function(p){return arguments.length?(e=p,f):e},f.ticks=function(){return r=Array.from(arguments),f},f.tickArguments=function(p){return arguments.length?(r=p==null?[]:Array.from(p),f):r.slice()},f.tickValues=function(p){return arguments.length?(n=p==null?null:Array.from(p),f):n&&n.slice()},f.tickFormat=function(p){return arguments.length?(i=p,f):i},f.tickSize=function(p){return arguments.length?(a=s=+p,f):a},f.tickSizeInner=function(p){return arguments.length?(a=+p,f):a},f.tickSizeOuter=function(p){return arguments.length?(s=+p,f):s},f.tickPadding=function(p){return arguments.length?(o=+p,f):o},f.offset=function(p){return arguments.length?(l=+p,f):l},f}function j_(t){return Au(Cu,t)}function MI(t){return Au(Su,t)}function $_(t){return Au($0,t)}function LI(t){return Au(Sl,t)}var RI={value:()=>{}};function fs(){for(var t=0,e=arguments.length,r={},n;t<e;++t){if(!(n=arguments[t]+"")||n in r||/[\s.]/.test(n))throw new Error("illegal type: "+n);r[n]=[]}return new Mu(r)}function Mu(t){this._=t}function II(t,e){return t.trim().split(/^|\s+/).map(function(r){var n="",i=r.indexOf(".");if(i>=0&&(n=r.slice(i+1),r=r.slice(0,i)),r&&!e.hasOwnProperty(r))throw new Error("unknown type: "+r);return{type:r,name:n}})}Mu.prototype=fs.prototype={constructor:Mu,on:function(t,e){var r=this._,n=II(t+"",r),i,a=-1,s=n.length;if(arguments.length<2){for(;++a<s;)if((i=(t=n[a]).type)&&(i=NI(r[i],t.name)))return i;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++a<s;)if(i=(t=n[a]).type)r[i]=X_(r[i],t.name,e);else if(e==null)for(i in r)r[i]=X_(r[i],t.name,null);return this},copy:function(){var t={},e=this._;for(var r in e)t[r]=e[r].slice();return new Mu(t)},call:function(t,e){if((i=arguments.length-2)>0)for(var r=new Array(i),n=0,i,a;n<i;++n)r[n]=arguments[n+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(a=this._[t],n=0,i=a.length;n<i;++n)a[n].value.apply(e,r)},apply:function(t,e,r){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var n=this._[t],i=0,a=n.length;i<a;++i)n[i].value.apply(e,r)}};function NI(t,e){for(var r=0,n=t.length,i;r<n;++r)if((i=t[r]).name===e)return i.value}function X_(t,e,r){for(var n=0,i=t.length;n<i;++n)if(t[n].name===e){t[n]=RI,t=t.slice(0,n).concat(t.slice(n+1));break}return r!=null&&t.push({name:e,value:r}),t}var X0="http://www.w3.org/1999/xhtml";const K0={svg:"http://www.w3.org/2000/svg",xhtml:X0,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Al(t){var e=t+="",r=e.indexOf(":");return r>=0&&(e=t.slice(0,r))!=="xmlns"&&(t=t.slice(r+1)),K0.hasOwnProperty(e)?{space:K0[e],local:t}:t}function BI(t){return function(){var e=this.ownerDocument,r=this.namespaceURI;return r===X0&&e.documentElement.namespaceURI===X0?e.createElement(t):e.createElementNS(r,t)}}function DI(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function Lu(t){var e=Al(t);return(e.local?DI:BI)(e)}function OI(){}function Ru(t){return t==null?OI:function(){return this.querySelector(t)}}function FI(t){typeof t!="function"&&(t=Ru(t));for(var e=this._groups,r=e.length,n=new Array(r),i=0;i<r;++i)for(var a=e[i],s=a.length,o=n[i]=new Array(s),l,u,h=0;h<s;++h)(l=a[h])&&(u=t.call(l,l.__data__,h,a))&&("__data__"in l&&(u.__data__=l.__data__),o[h]=u);return new $r(n,this._parents)}function K_(t){return t==null?[]:Array.isArray(t)?t:Array.from(t)}function PI(){return[]}function Z0(t){return t==null?PI:function(){return this.querySelectorAll(t)}}function qI(t){return function(){return K_(t.apply(this,arguments))}}function VI(t){typeof t=="function"?t=qI(t):t=Z0(t);for(var e=this._groups,r=e.length,n=[],i=[],a=0;a<r;++a)for(var s=e[a],o=s.length,l,u=0;u<o;++u)(l=s[u])&&(n.push(t.call(l,l.__data__,u,s)),i.push(l));return new $r(n,i)}function Q0(t){return function(){return this.matches(t)}}function Z_(t){return function(e){return e.matches(t)}}var zI=Array.prototype.find;function YI(t){return function(){return zI.call(this.children,t)}}function UI(){return this.firstElementChild}function WI(t){return this.select(t==null?UI:YI(typeof t=="function"?t:Z_(t)))}var HI=Array.prototype.filter;function GI(){return Array.from(this.children)}function jI(t){return function(){return HI.call(this.children,t)}}function $I(t){return this.selectAll(t==null?GI:jI(typeof t=="function"?t:Z_(t)))}function XI(t){typeof t!="function"&&(t=Q0(t));for(var e=this._groups,r=e.length,n=new Array(r),i=0;i<r;++i)for(var a=e[i],s=a.length,o=n[i]=[],l,u=0;u<s;++u)(l=a[u])&&t.call(l,l.__data__,u,a)&&o.push(l);return new $r(n,this._parents)}function Q_(t){return new Array(t.length)}function KI(){return new $r(this._enter||this._groups.map(Q_),this._parents)}function Iu(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}Iu.prototype={constructor:Iu,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};function ZI(t){return function(){return t}}function QI(t,e,r,n,i,a){for(var s=0,o,l=e.length,u=a.length;s<u;++s)(o=e[s])?(o.__data__=a[s],n[s]=o):r[s]=new Iu(t,a[s]);for(;s<l;++s)(o=e[s])&&(i[s]=o)}function JI(t,e,r,n,i,a,s){var o,l,u=new Map,h=e.length,d=a.length,f=new Array(h),p;for(o=0;o<h;++o)(l=e[o])&&(f[o]=p=s.call(l,l.__data__,o,e)+"",u.has(p)?i[o]=l:u.set(p,l));for(o=0;o<d;++o)p=s.call(t,a[o],o,a)+"",(l=u.get(p))?(n[o]=l,l.__data__=a[o],u.delete(p)):r[o]=new Iu(t,a[o]);for(o=0;o<h;++o)(l=e[o])&&u.get(f[o])===l&&(i[o]=l)}function tN(t){return t.__data__}function eN(t,e){if(!arguments.length)return Array.from(this,tN);var r=e?JI:QI,n=this._parents,i=this._groups;typeof t!="function"&&(t=ZI(t));for(var a=i.length,s=new Array(a),o=new Array(a),l=new Array(a),u=0;u<a;++u){var h=n[u],d=i[u],f=d.length,p=rN(t.call(h,h&&h.__data__,u,n)),m=p.length,_=o[u]=new Array(m),y=s[u]=new Array(m),b=l[u]=new Array(f);r(h,d,_,y,b,p,e);for(var x=0,k=0,T,C;x<m;++x)if(T=_[x]){for(x>=k&&(k=x+1);!(C=y[k])&&++k<m;);T._next=C||null}}return s=new $r(s,n),s._enter=o,s._exit=l,s}function rN(t){return typeof t=="object"&&"length"in t?t:Array.from(t)}function nN(){return new $r(this._exit||this._groups.map(Q_),this._parents)}function iN(t,e,r){var n=this.enter(),i=this,a=this.exit();return typeof t=="function"?(n=t(n),n&&(n=n.selection())):n=n.append(t+""),e!=null&&(i=e(i),i&&(i=i.selection())),r==null?a.remove():r(a),n&&i?n.merge(i).order():i}function aN(t){for(var e=t.selection?t.selection():t,r=this._groups,n=e._groups,i=r.length,a=n.length,s=Math.min(i,a),o=new Array(i),l=0;l<s;++l)for(var u=r[l],h=n[l],d=u.length,f=o[l]=new Array(d),p,m=0;m<d;++m)(p=u[m]||h[m])&&(f[m]=p);for(;l<i;++l)o[l]=r[l];return new $r(o,this._parents)}function sN(){for(var t=this._groups,e=-1,r=t.length;++e<r;)for(var n=t[e],i=n.length-1,a=n[i],s;--i>=0;)(s=n[i])&&(a&&s.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(s,a),a=s);return this}function oN(t){t||(t=lN);function e(d,f){return d&&f?t(d.__data__,f.__data__):!d-!f}for(var r=this._groups,n=r.length,i=new Array(n),a=0;a<n;++a){for(var s=r[a],o=s.length,l=i[a]=new Array(o),u,h=0;h<o;++h)(u=s[h])&&(l[h]=u);l.sort(e)}return new $r(i,this._parents).order()}function lN(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function cN(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this}function uN(){return Array.from(this)}function hN(){for(var t=this._groups,e=0,r=t.length;e<r;++e)for(var n=t[e],i=0,a=n.length;i<a;++i){var s=n[i];if(s)return s}return null}function fN(){let t=0;for(const e of this)++t;return t}function dN(){return!this.node()}function pN(t){for(var e=this._groups,r=0,n=e.length;r<n;++r)for(var i=e[r],a=0,s=i.length,o;a<s;++a)(o=i[a])&&t.call(o,o.__data__,a,i);return this}function gN(t){return function(){this.removeAttribute(t)}}function yN(t){return function(){this.removeAttributeNS(t.space,t.local)}}function mN(t,e){return function(){this.setAttribute(t,e)}}function bN(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function _N(t,e){return function(){var r=e.apply(this,arguments);r==null?this.removeAttribute(t):this.setAttribute(t,r)}}function vN(t,e){return function(){var r=e.apply(this,arguments);r==null?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,r)}}function xN(t,e){var r=Al(t);if(arguments.length<2){var n=this.node();return r.local?n.getAttributeNS(r.space,r.local):n.getAttribute(r)}return this.each((e==null?r.local?yN:gN:typeof e=="function"?r.local?vN:_N:r.local?bN:mN)(r,e))}function J0(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function kN(t){return function(){this.style.removeProperty(t)}}function wN(t,e,r){return function(){this.style.setProperty(t,e,r)}}function TN(t,e,r){return function(){var n=e.apply(this,arguments);n==null?this.style.removeProperty(t):this.style.setProperty(t,n,r)}}function EN(t,e,r){return arguments.length>1?this.each((e==null?kN:typeof e=="function"?TN:wN)(t,e,r==null?"":r)):ds(this.node(),t)}function ds(t,e){return t.style.getPropertyValue(e)||J0(t).getComputedStyle(t,null).getPropertyValue(e)}function CN(t){return function(){delete this[t]}}function SN(t,e){return function(){this[t]=e}}function AN(t,e){return function(){var r=e.apply(this,arguments);r==null?delete this[t]:this[t]=r}}function MN(t,e){return arguments.length>1?this.each((e==null?CN:typeof e=="function"?AN:SN)(t,e)):this.node()[t]}function J_(t){return t.trim().split(/^|\s+/)}function td(t){return t.classList||new t5(t)}function t5(t){this._node=t,this._names=J_(t.getAttribute("class")||"")}t5.prototype={add:function(t){var e=this._names.indexOf(t);e<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var e=this._names.indexOf(t);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};function e5(t,e){for(var r=td(t),n=-1,i=e.length;++n<i;)r.add(e[n])}function r5(t,e){for(var r=td(t),n=-1,i=e.length;++n<i;)r.remove(e[n])}function LN(t){return function(){e5(this,t)}}function RN(t){return function(){r5(this,t)}}function IN(t,e){return function(){(e.apply(this,arguments)?e5:r5)(this,t)}}function NN(t,e){var r=J_(t+"");if(arguments.length<2){for(var n=td(this.node()),i=-1,a=r.length;++i<a;)if(!n.contains(r[i]))return!1;return!0}return this.each((typeof e=="function"?IN:e?LN:RN)(r,e))}function BN(){this.textContent=""}function DN(t){return function(){this.textContent=t}}function ON(t){return function(){var e=t.apply(this,arguments);this.textContent=e==null?"":e}}function FN(t){return arguments.length?this.each(t==null?BN:(typeof t=="function"?ON:DN)(t)):this.node().textContent}function PN(){this.innerHTML=""}function qN(t){return function(){this.innerHTML=t}}function VN(t){return function(){var e=t.apply(this,arguments);this.innerHTML=e==null?"":e}}function zN(t){return arguments.length?this.each(t==null?PN:(typeof t=="function"?VN:qN)(t)):this.node().innerHTML}function YN(){this.nextSibling&&this.parentNode.appendChild(this)}function UN(){return this.each(YN)}function WN(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function HN(){return this.each(WN)}function GN(t){var e=typeof t=="function"?t:Lu(t);return this.select(function(){return this.appendChild(e.apply(this,arguments))})}function jN(){return null}function $N(t,e){var r=typeof t=="function"?t:Lu(t),n=e==null?jN:typeof e=="function"?e:Ru(e);return this.select(function(){return this.insertBefore(r.apply(this,arguments),n.apply(this,arguments)||null)})}function XN(){var t=this.parentNode;t&&t.removeChild(this)}function KN(){return this.each(XN)}function ZN(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function QN(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function JN(t){return this.select(t?QN:ZN)}function tB(t){return arguments.length?this.property("__data__",t):this.node().__data__}function eB(t){return function(e){t.call(this,e,this.__data__)}}function rB(t){return t.trim().split(/^|\s+/).map(function(e){var r="",n=e.indexOf(".");return n>=0&&(r=e.slice(n+1),e=e.slice(0,n)),{type:e,name:r}})}function nB(t){return function(){var e=this.__on;if(!!e){for(var r=0,n=-1,i=e.length,a;r<i;++r)a=e[r],(!t.type||a.type===t.type)&&a.name===t.name?this.removeEventListener(a.type,a.listener,a.options):e[++n]=a;++n?e.length=n:delete this.__on}}}function iB(t,e,r){return function(){var n=this.__on,i,a=eB(e);if(n){for(var s=0,o=n.length;s<o;++s)if((i=n[s]).type===t.type&&i.name===t.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=r),i.value=e;return}}this.addEventListener(t.type,a,r),i={type:t.type,name:t.name,value:e,listener:a,options:r},n?n.push(i):this.__on=[i]}}function aB(t,e,r){var n=rB(t+""),i,a=n.length,s;if(arguments.length<2){var o=this.node().__on;if(o){for(var l=0,u=o.length,h;l<u;++l)for(i=0,h=o[l];i<a;++i)if((s=n[i]).type===h.type&&s.name===h.name)return h.value}return}for(o=e?iB:nB,i=0;i<a;++i)this.each(o(n[i],e,r));return this}function n5(t,e,r){var n=J0(t),i=n.CustomEvent;typeof i=="function"?i=new i(e,r):(i=n.document.createEvent("Event"),r?(i.initEvent(e,r.bubbles,r.cancelable),i.detail=r.detail):i.initEvent(e,!1,!1)),t.dispatchEvent(i)}function sB(t,e){return function(){return n5(this,t,e)}}function oB(t,e){return function(){return n5(this,t,e.apply(this,arguments))}}function lB(t,e){return this.each((typeof e=="function"?oB:sB)(t,e))}function*cB(){for(var t=this._groups,e=0,r=t.length;e<r;++e)for(var n=t[e],i=0,a=n.length,s;i<a;++i)(s=n[i])&&(yield s)}var ed=[null];function $r(t,e){this._groups=t,this._parents=e}function ps(){return new $r([[document.documentElement]],ed)}function uB(){return this}$r.prototype=ps.prototype={constructor:$r,select:FI,selectAll:VI,selectChild:WI,selectChildren:$I,filter:XI,data:eN,enter:KI,exit:nN,join:iN,merge:aN,selection:uB,order:sN,sort:oN,call:cN,nodes:uN,node:hN,size:fN,empty:dN,each:pN,attr:xN,style:EN,property:MN,classed:NN,text:FN,html:zN,raise:UN,lower:HN,append:GN,insert:$N,remove:KN,clone:JN,datum:tB,on:aB,dispatch:lB,[Symbol.iterator]:cB};function St(t){return typeof t=="string"?new $r([[document.querySelector(t)]],[document.documentElement]):new $r([[t]],ed)}function hB(t){return St(Lu(t).call(document.documentElement))}var fB=0;function i5(){return new rd}function rd(){this._="@"+(++fB).toString(36)}rd.prototype=i5.prototype={constructor:rd,get:function(t){for(var e=this._;!(e in t);)if(!(t=t.parentNode))return;return t[e]},set:function(t,e){return t[this._]=e},remove:function(t){return this._ in t&&delete t[this._]},toString:function(){return this._}};function a5(t){let e;for(;e=t.sourceEvent;)t=e;return t}function Tn(t,e){if(t=a5(t),e===void 0&&(e=t.currentTarget),e){var r=e.ownerSVGElement||e;if(r.createSVGPoint){var n=r.createSVGPoint();return n.x=t.clientX,n.y=t.clientY,n=n.matrixTransform(e.getScreenCTM().inverse()),[n.x,n.y]}if(e.getBoundingClientRect){var i=e.getBoundingClientRect();return[t.clientX-i.left-e.clientLeft,t.clientY-i.top-e.clientTop]}}return[t.pageX,t.pageY]}function dB(t,e){return t.target&&(t=a5(t),e===void 0&&(e=t.currentTarget),t=t.touches||[t]),Array.from(t,r=>Tn(r,e))}function Nu(t){return typeof t=="string"?new $r([document.querySelectorAll(t)],[document.documentElement]):new $r([K_(t)],ed)}const pB={passive:!1},Ml={capture:!0,passive:!1};function nd(t){t.stopImmediatePropagation()}function co(t){t.preventDefault(),t.stopImmediatePropagation()}function Bu(t){var e=t.document.documentElement,r=St(t).on("dragstart.drag",co,Ml);"onselectstart"in e?r.on("selectstart.drag",co,Ml):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function Du(t,e){var r=t.document.documentElement,n=St(t).on("dragstart.drag",null);e&&(n.on("click.drag",co,Ml),setTimeout(function(){n.on("click.drag",null)},0)),"onselectstart"in r?n.on("selectstart.drag",null):(r.style.MozUserSelect=r.__noselect,delete r.__noselect)}const Ou=t=>()=>t;function id(t,{sourceEvent:e,subject:r,target:n,identifier:i,active:a,x:s,y:o,dx:l,dy:u,dispatch:h}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:r,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:o,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:h}})}id.prototype.on=function(){var t=this._.on.apply(this._,arguments);return t===this._?this:t};function gB(t){return!t.ctrlKey&&!t.button}function yB(){return this.parentNode}function mB(t,e){return e==null?{x:t.x,y:t.y}:e}function bB(){return navigator.maxTouchPoints||"ontouchstart"in this}function _B(){var t=gB,e=yB,r=mB,n=bB,i={},a=fs("start","drag","end"),s=0,o,l,u,h,d=0;function f(T){T.on("mousedown.drag",p).filter(n).on("touchstart.drag",y).on("touchmove.drag",b,pB).on("touchend.drag touchcancel.drag",x).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(T,C){if(!(h||!t.call(this,T,C))){var M=k(this,e.call(this,T,C),T,C,"mouse");!M||(St(T.view).on("mousemove.drag",m,Ml).on("mouseup.drag",_,Ml),Bu(T.view),nd(T),u=!1,o=T.clientX,l=T.clientY,M("start",T))}}function m(T){if(co(T),!u){var C=T.clientX-o,M=T.clientY-l;u=C*C+M*M>d}i.mouse("drag",T)}function _(T){St(T.view).on("mousemove.drag mouseup.drag",null),Du(T.view,u),co(T),i.mouse("end",T)}function y(T,C){if(!!t.call(this,T,C)){var M=T.changedTouches,S=e.call(this,T,C),R=M.length,A,L;for(A=0;A<R;++A)(L=k(this,S,T,C,M[A].identifier,M[A]))&&(nd(T),L("start",T,M[A]))}}function b(T){var C=T.changedTouches,M=C.length,S,R;for(S=0;S<M;++S)(R=i[C[S].identifier])&&(co(T),R("drag",T,C[S]))}function x(T){var C=T.changedTouches,M=C.length,S,R;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),S=0;S<M;++S)(R=i[C[S].identifier])&&(nd(T),R("end",T,C[S]))}function k(T,C,M,S,R,A){var L=a.copy(),v=Tn(A||M,C),B,w,D;if((D=r.call(T,new id("beforestart",{sourceEvent:M,target:f,identifier:R,active:s,x:v[0],y:v[1],dx:0,dy:0,dispatch:L}),S))!=null)return B=D.x-v[0]||0,w=D.y-v[1]||0,function N(z,X,ct){var J=v,Y;switch(z){case"start":i[R]=N,Y=s++;break;case"end":delete i[R],--s;case"drag":v=Tn(ct||X,C),Y=s;break}L.call(z,T,new id(z,{sourceEvent:X,subject:D,target:f,identifier:R,active:Y,x:v[0]+B,y:v[1]+w,dx:v[0]-J[0],dy:v[1]-J[1],dispatch:L}),S)}}return f.filter=function(T){return arguments.length?(t=typeof T=="function"?T:Ou(!!T),f):t},f.container=function(T){return arguments.length?(e=typeof T=="function"?T:Ou(T),f):e},f.subject=function(T){return arguments.length?(r=typeof T=="function"?T:Ou(T),f):r},f.touchable=function(T){return arguments.length?(n=typeof T=="function"?T:Ou(!!T),f):n},f.on=function(){var T=a.on.apply(a,arguments);return T===a?f:T},f.clickDistance=function(T){return arguments.length?(d=(T=+T)*T,f):Math.sqrt(d)},f}function uo(t,e,r){t.prototype=e.prototype=r,r.constructor=t}function Ll(t,e){var r=Object.create(t.prototype);for(var n in e)r[n]=e[n];return r}function Sa(){}var gs=.7,ho=1/gs,fo="\\s*([+-]?\\d+)\\s*",Rl="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",wi="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",vB=/^#([0-9a-f]{3,8})$/,xB=new RegExp(`^rgb\\(${fo},${fo},${fo}\\)$`),kB=new RegExp(`^rgb\\(${wi},${wi},${wi}\\)$`),wB=new RegExp(`^rgba\\(${fo},${fo},${fo},${Rl}\\)$`),TB=new RegExp(`^rgba\\(${wi},${wi},${wi},${Rl}\\)$`),EB=new RegExp(`^hsl\\(${Rl},${wi},${wi}\\)$`),CB=new RegExp(`^hsla\\(${Rl},${wi},${wi},${Rl}\\)$`),s5={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};uo(Sa,Aa,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:o5,formatHex:o5,formatHex8:SB,formatHsl:AB,formatRgb:l5,toString:l5});function o5(){return this.rgb().formatHex()}function SB(){return this.rgb().formatHex8()}function AB(){return d5(this).formatHsl()}function l5(){return this.rgb().formatRgb()}function Aa(t){var e,r;return t=(t+"").trim().toLowerCase(),(e=vB.exec(t))?(r=e[1].length,e=parseInt(e[1],16),r===6?c5(e):r===3?new Er(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):r===8?Fu(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):r===4?Fu(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=xB.exec(t))?new Er(e[1],e[2],e[3],1):(e=kB.exec(t))?new Er(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=wB.exec(t))?Fu(e[1],e[2],e[3],e[4]):(e=TB.exec(t))?Fu(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=EB.exec(t))?f5(e[1],e[2]/100,e[3]/100,1):(e=CB.exec(t))?f5(e[1],e[2]/100,e[3]/100,e[4]):s5.hasOwnProperty(t)?c5(s5[t]):t==="transparent"?new Er(NaN,NaN,NaN,0):null}function c5(t){return new Er(t>>16&255,t>>8&255,t&255,1)}function Fu(t,e,r,n){return n<=0&&(t=e=r=NaN),new Er(t,e,r,n)}function ad(t){return t instanceof Sa||(t=Aa(t)),t?(t=t.rgb(),new Er(t.r,t.g,t.b,t.opacity)):new Er}function po(t,e,r,n){return arguments.length===1?ad(t):new Er(t,e,r,n==null?1:n)}function Er(t,e,r,n){this.r=+t,this.g=+e,this.b=+r,this.opacity=+n}uo(Er,po,Ll(Sa,{brighter(t){return t=t==null?ho:Math.pow(ho,t),new Er(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=t==null?gs:Math.pow(gs,t),new Er(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Er(ys(this.r),ys(this.g),ys(this.b),Pu(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:u5,formatHex:u5,formatHex8:MB,formatRgb:h5,toString:h5}));function u5(){return`#${ms(this.r)}${ms(this.g)}${ms(this.b)}`}function MB(){return`#${ms(this.r)}${ms(this.g)}${ms(this.b)}${ms((isNaN(this.opacity)?1:this.opacity)*255)}`}function h5(){const t=Pu(this.opacity);return`${t===1?"rgb(":"rgba("}${ys(this.r)}, ${ys(this.g)}, ${ys(this.b)}${t===1?")":`, ${t})`}`}function Pu(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function ys(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function ms(t){return t=ys(t),(t<16?"0":"")+t.toString(16)}function f5(t,e,r,n){return n<=0?t=e=r=NaN:r<=0||r>=1?t=e=NaN:e<=0&&(t=NaN),new Kn(t,e,r,n)}function d5(t){if(t instanceof Kn)return new Kn(t.h,t.s,t.l,t.opacity);if(t instanceof Sa||(t=Aa(t)),!t)return new Kn;if(t instanceof Kn)return t;t=t.rgb();var e=t.r/255,r=t.g/255,n=t.b/255,i=Math.min(e,r,n),a=Math.max(e,r,n),s=NaN,o=a-i,l=(a+i)/2;return o?(e===a?s=(r-n)/o+(r<n)*6:r===a?s=(n-e)/o+2:s=(e-r)/o+4,o/=l<.5?a+i:2-a-i,s*=60):o=l>0&&l<1?0:s,new Kn(s,o,l,t.opacity)}function qu(t,e,r,n){return arguments.length===1?d5(t):new Kn(t,e,r,n==null?1:n)}function Kn(t,e,r,n){this.h=+t,this.s=+e,this.l=+r,this.opacity=+n}uo(Kn,qu,Ll(Sa,{brighter(t){return t=t==null?ho:Math.pow(ho,t),new Kn(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=t==null?gs:Math.pow(gs,t),new Kn(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+(this.h<0)*360,e=isNaN(t)||isNaN(this.s)?0:this.s,r=this.l,n=r+(r<.5?r:1-r)*e,i=2*r-n;return new Er(sd(t>=240?t-240:t+120,i,n),sd(t,i,n),sd(t<120?t+240:t-120,i,n),this.opacity)},clamp(){return new Kn(p5(this.h),Vu(this.s),Vu(this.l),Pu(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Pu(this.opacity);return`${t===1?"hsl(":"hsla("}${p5(this.h)}, ${Vu(this.s)*100}%, ${Vu(this.l)*100}%${t===1?")":`, ${t})`}`}}));function p5(t){return t=(t||0)%360,t<0?t+360:t}function Vu(t){return Math.max(0,Math.min(1,t||0))}function sd(t,e,r){return(t<60?e+(r-e)*t/60:t<180?r:t<240?e+(r-e)*(240-t)/60:e)*255}const g5=Math.PI/180,y5=180/Math.PI,zu=18,m5=.96422,b5=1,_5=.82521,v5=4/29,go=6/29,x5=3*go*go,LB=go*go*go;function k5(t){if(t instanceof Zn)return new Zn(t.l,t.a,t.b,t.opacity);if(t instanceof Ti)return T5(t);t instanceof Er||(t=ad(t));var e=ud(t.r),r=ud(t.g),n=ud(t.b),i=od((.2225045*e+.7168786*r+.0606169*n)/b5),a,s;return e===r&&r===n?a=s=i:(a=od((.4360747*e+.3850649*r+.1430804*n)/m5),s=od((.0139322*e+.0971045*r+.7141733*n)/_5)),new Zn(116*i-16,500*(a-i),200*(i-s),t.opacity)}function RB(t,e){return new Zn(t,0,0,e==null?1:e)}function Yu(t,e,r,n){return arguments.length===1?k5(t):new Zn(t,e,r,n==null?1:n)}function Zn(t,e,r,n){this.l=+t,this.a=+e,this.b=+r,this.opacity=+n}uo(Zn,Yu,Ll(Sa,{brighter(t){return new Zn(this.l+zu*(t==null?1:t),this.a,this.b,this.opacity)},darker(t){return new Zn(this.l-zu*(t==null?1:t),this.a,this.b,this.opacity)},rgb(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,r=isNaN(this.b)?t:t-this.b/200;return e=m5*ld(e),t=b5*ld(t),r=_5*ld(r),new Er(cd(3.1338561*e-1.6168667*t-.4906146*r),cd(-.9787684*e+1.9161415*t+.033454*r),cd(.0719453*e-.2289914*t+1.4052427*r),this.opacity)}}));function od(t){return t>LB?Math.pow(t,1/3):t/x5+v5}function ld(t){return t>go?t*t*t:x5*(t-v5)}function cd(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function ud(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function w5(t){if(t instanceof Ti)return new Ti(t.h,t.c,t.l,t.opacity);if(t instanceof Zn||(t=k5(t)),t.a===0&&t.b===0)return new Ti(NaN,0<t.l&&t.l<100?0:NaN,t.l,t.opacity);var e=Math.atan2(t.b,t.a)*y5;return new Ti(e<0?e+360:e,Math.sqrt(t.a*t.a+t.b*t.b),t.l,t.opacity)}function IB(t,e,r,n){return arguments.length===1?w5(t):new Ti(r,e,t,n==null?1:n)}function Uu(t,e,r,n){return arguments.length===1?w5(t):new Ti(t,e,r,n==null?1:n)}function Ti(t,e,r,n){this.h=+t,this.c=+e,this.l=+r,this.opacity=+n}function T5(t){if(isNaN(t.h))return new Zn(t.l,0,0,t.opacity);var e=t.h*g5;return new Zn(t.l,Math.cos(e)*t.c,Math.sin(e)*t.c,t.opacity)}uo(Ti,Uu,Ll(Sa,{brighter(t){return new Ti(this.h,this.c,this.l+zu*(t==null?1:t),this.opacity)},darker(t){return new Ti(this.h,this.c,this.l-zu*(t==null?1:t),this.opacity)},rgb(){return T5(this).rgb()}}));var E5=-.14861,hd=1.78277,fd=-.29227,Wu=-.90649,Il=1.97294,C5=Il*Wu,S5=Il*hd,A5=hd*fd-Wu*E5;function NB(t){if(t instanceof bs)return new bs(t.h,t.s,t.l,t.opacity);t instanceof Er||(t=ad(t));var e=t.r/255,r=t.g/255,n=t.b/255,i=(A5*n+C5*e-S5*r)/(A5+C5-S5),a=n-i,s=(Il*(r-i)-fd*a)/Wu,o=Math.sqrt(s*s+a*a)/(Il*i*(1-i)),l=o?Math.atan2(s,a)*y5-120:NaN;return new bs(l<0?l+360:l,o,i,t.opacity)}function Qn(t,e,r,n){return arguments.length===1?NB(t):new bs(t,e,r,n==null?1:n)}function bs(t,e,r,n){this.h=+t,this.s=+e,this.l=+r,this.opacity=+n}uo(bs,Qn,Ll(Sa,{brighter(t){return t=t==null?ho:Math.pow(ho,t),new bs(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=t==null?gs:Math.pow(gs,t),new bs(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=isNaN(this.h)?0:(this.h+120)*g5,e=+this.l,r=isNaN(this.s)?0:this.s*e*(1-e),n=Math.cos(t),i=Math.sin(t);return new Er(255*(e+r*(E5*n+hd*i)),255*(e+r*(fd*n+Wu*i)),255*(e+r*(Il*n)),this.opacity)}}));function M5(t,e,r,n,i){var a=t*t,s=a*t;return((1-3*t+3*a-s)*e+(4-6*a+3*s)*r+(1+3*t+3*a-3*s)*n+s*i)/6}function L5(t){var e=t.length-1;return function(r){var n=r<=0?r=0:r>=1?(r=1,e-1):Math.floor(r*e),i=t[n],a=t[n+1],s=n>0?t[n-1]:2*i-a,o=n<e-1?t[n+2]:2*a-i;return M5((r-n/e)*e,s,i,a,o)}}function R5(t){var e=t.length;return function(r){var n=Math.floor(((r%=1)<0?++r:r)*e),i=t[(n+e-1)%e],a=t[n%e],s=t[(n+1)%e],o=t[(n+2)%e];return M5((r-n/e)*e,i,a,s,o)}}const Hu=t=>()=>t;function I5(t,e){return function(r){return t+r*e}}function BB(t,e,r){return t=Math.pow(t,r),e=Math.pow(e,r)-t,r=1/r,function(n){return Math.pow(t+n*e,r)}}function Gu(t,e){var r=e-t;return r?I5(t,r>180||r<-180?r-360*Math.round(r/360):r):Hu(isNaN(t)?e:t)}function DB(t){return(t=+t)==1?Cr:function(e,r){return r-e?BB(e,r,t):Hu(isNaN(e)?r:e)}}function Cr(t,e){var r=e-t;return r?I5(t,r):Hu(isNaN(t)?e:t)}const Nl=function t(e){var r=DB(e);function n(i,a){var s=r((i=po(i)).r,(a=po(a)).r),o=r(i.g,a.g),l=r(i.b,a.b),u=Cr(i.opacity,a.opacity);return function(h){return i.r=s(h),i.g=o(h),i.b=l(h),i.opacity=u(h),i+""}}return n.gamma=t,n}(1);function N5(t){return function(e){var r=e.length,n=new Array(r),i=new Array(r),a=new Array(r),s,o;for(s=0;s<r;++s)o=po(e[s]),n[s]=o.r||0,i[s]=o.g||0,a[s]=o.b||0;return n=t(n),i=t(i),a=t(a),o.opacity=1,function(l){return o.r=n(l),o.g=i(l),o.b=a(l),o+""}}}var B5=N5(L5),OB=N5(R5);function dd(t,e){e||(e=[]);var r=t?Math.min(e.length,t.length):0,n=e.slice(),i;return function(a){for(i=0;i<r;++i)n[i]=t[i]*(1-a)+e[i]*a;return n}}function D5(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function FB(t,e){return(D5(e)?dd:O5)(t,e)}function O5(t,e){var r=e?e.length:0,n=t?Math.min(r,t.length):0,i=new Array(n),a=new Array(r),s;for(s=0;s<n;++s)i[s]=Ma(t[s],e[s]);for(;s<r;++s)a[s]=e[s];return function(o){for(s=0;s<n;++s)a[s]=i[s](o);return a}}function F5(t,e){var r=new Date;return t=+t,e=+e,function(n){return r.setTime(t*(1-n)+e*n),r}}function Bn(t,e){return t=+t,e=+e,function(r){return t*(1-r)+e*r}}function P5(t,e){var r={},n={},i;(t===null||typeof t!="object")&&(t={}),(e===null||typeof e!="object")&&(e={});for(i in e)i in t?r[i]=Ma(t[i],e[i]):n[i]=e[i];return function(a){for(i in r)n[i]=r[i](a);return n}}var pd=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,gd=new RegExp(pd.source,"g");function PB(t){return function(){return t}}function qB(t){return function(e){return t(e)+""}}function yd(t,e){var r=pd.lastIndex=gd.lastIndex=0,n,i,a,s=-1,o=[],l=[];for(t=t+"",e=e+"";(n=pd.exec(t))&&(i=gd.exec(e));)(a=i.index)>r&&(a=e.slice(r,a),o[s]?o[s]+=a:o[++s]=a),(n=n[0])===(i=i[0])?o[s]?o[s]+=i:o[++s]=i:(o[++s]=null,l.push({i:s,x:Bn(n,i)})),r=gd.lastIndex;return r<e.length&&(a=e.slice(r),o[s]?o[s]+=a:o[++s]=a),o.length<2?l[0]?qB(l[0].x):PB(e):(e=l.length,function(u){for(var h=0,d;h<e;++h)o[(d=l[h]).i]=d.x(u);return o.join("")})}function Ma(t,e){var r=typeof e,n;return e==null||r==="boolean"?Hu(e):(r==="number"?Bn:r==="string"?(n=Aa(e))?(e=n,Nl):yd:e instanceof Aa?Nl:e instanceof Date?F5:D5(e)?dd:Array.isArray(e)?O5:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?P5:Bn)(t,e)}function VB(t){var e=t.length;return function(r){return t[Math.max(0,Math.min(e-1,Math.floor(r*e)))]}}function zB(t,e){var r=Gu(+t,+e);return function(n){var i=r(n);return i-360*Math.floor(i/360)}}function ju(t,e){return t=+t,e=+e,function(r){return Math.round(t*(1-r)+e*r)}}var q5=180/Math.PI,md={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function V5(t,e,r,n,i,a){var s,o,l;return(s=Math.sqrt(t*t+e*e))&&(t/=s,e/=s),(l=t*r+e*n)&&(r-=t*l,n-=e*l),(o=Math.sqrt(r*r+n*n))&&(r/=o,n/=o,l/=o),t*n<e*r&&(t=-t,e=-e,l=-l,s=-s),{translateX:i,translateY:a,rotate:Math.atan2(e,t)*q5,skewX:Math.atan(l)*q5,scaleX:s,scaleY:o}}var $u;function YB(t){const e=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(t+"");return e.isIdentity?md:V5(e.a,e.b,e.c,e.d,e.e,e.f)}function UB(t){return t==null||($u||($u=document.createElementNS("http://www.w3.org/2000/svg","g")),$u.setAttribute("transform",t),!(t=$u.transform.baseVal.consolidate()))?md:(t=t.matrix,V5(t.a,t.b,t.c,t.d,t.e,t.f))}function z5(t,e,r,n){function i(u){return u.length?u.pop()+" ":""}function a(u,h,d,f,p,m){if(u!==d||h!==f){var _=p.push("translate(",null,e,null,r);m.push({i:_-4,x:Bn(u,d)},{i:_-2,x:Bn(h,f)})}else(d||f)&&p.push("translate("+d+e+f+r)}function s(u,h,d,f){u!==h?(u-h>180?h+=360:h-u>180&&(u+=360),f.push({i:d.push(i(d)+"rotate(",null,n)-2,x:Bn(u,h)})):h&&d.push(i(d)+"rotate("+h+n)}function o(u,h,d,f){u!==h?f.push({i:d.push(i(d)+"skewX(",null,n)-2,x:Bn(u,h)}):h&&d.push(i(d)+"skewX("+h+n)}function l(u,h,d,f,p,m){if(u!==d||h!==f){var _=p.push(i(p)+"scale(",null,",",null,")");m.push({i:_-4,x:Bn(u,d)},{i:_-2,x:Bn(h,f)})}else(d!==1||f!==1)&&p.push(i(p)+"scale("+d+","+f+")")}return function(u,h){var d=[],f=[];return u=t(u),h=t(h),a(u.translateX,u.translateY,h.translateX,h.translateY,d,f),s(u.rotate,h.rotate,d,f),o(u.skewX,h.skewX,d,f),l(u.scaleX,u.scaleY,h.scaleX,h.scaleY,d,f),u=h=null,function(p){for(var m=-1,_=f.length,y;++m<_;)d[(y=f[m]).i]=y.x(p);return d.join("")}}}var Y5=z5(YB,"px, ","px)","deg)"),U5=z5(UB,", ",")",")"),WB=1e-12;function W5(t){return((t=Math.exp(t))+1/t)/2}function HB(t){return((t=Math.exp(t))-1/t)/2}function GB(t){return((t=Math.exp(2*t))-1)/(t+1)}const H5=function t(e,r,n){function i(a,s){var o=a[0],l=a[1],u=a[2],h=s[0],d=s[1],f=s[2],p=h-o,m=d-l,_=p*p+m*m,y,b;if(_<WB)b=Math.log(f/u)/e,y=function(S){return[o+S*p,l+S*m,u*Math.exp(e*S*b)]};else{var x=Math.sqrt(_),k=(f*f-u*u+n*_)/(2*u*r*x),T=(f*f-u*u-n*_)/(2*f*r*x),C=Math.log(Math.sqrt(k*k+1)-k),M=Math.log(Math.sqrt(T*T+1)-T);b=(M-C)/e,y=function(S){var R=S*b,A=W5(C),L=u/(r*x)*(A*GB(e*R+C)-HB(C));return[o+L*p,l+L*m,u*A/W5(e*R+C)]}}return y.duration=b*1e3*e/Math.SQRT2,y}return i.rho=function(a){var s=Math.max(.001,+a),o=s*s,l=o*o;return t(s,o,l)},i}(Math.SQRT2,2,4);function G5(t){return function(e,r){var n=t((e=qu(e)).h,(r=qu(r)).h),i=Cr(e.s,r.s),a=Cr(e.l,r.l),s=Cr(e.opacity,r.opacity);return function(o){return e.h=n(o),e.s=i(o),e.l=a(o),e.opacity=s(o),e+""}}}const jB=G5(Gu);var $B=G5(Cr);function XB(t,e){var r=Cr((t=Yu(t)).l,(e=Yu(e)).l),n=Cr(t.a,e.a),i=Cr(t.b,e.b),a=Cr(t.opacity,e.opacity);return function(s){return t.l=r(s),t.a=n(s),t.b=i(s),t.opacity=a(s),t+""}}function j5(t){return function(e,r){var n=t((e=Uu(e)).h,(r=Uu(r)).h),i=Cr(e.c,r.c),a=Cr(e.l,r.l),s=Cr(e.opacity,r.opacity);return function(o){return e.h=n(o),e.c=i(o),e.l=a(o),e.opacity=s(o),e+""}}}const $5=j5(Gu);var KB=j5(Cr);function X5(t){return function e(r){r=+r;function n(i,a){var s=t((i=Qn(i)).h,(a=Qn(a)).h),o=Cr(i.s,a.s),l=Cr(i.l,a.l),u=Cr(i.opacity,a.opacity);return function(h){return i.h=s(h),i.s=o(h),i.l=l(Math.pow(h,r)),i.opacity=u(h),i+""}}return n.gamma=e,n}(1)}const ZB=X5(Gu);var Xu=X5(Cr);function K5(t,e){e===void 0&&(e=t,t=Ma);for(var r=0,n=e.length-1,i=e[0],a=new Array(n<0?0:n);r<n;)a[r]=t(i,i=e[++r]);return function(s){var o=Math.max(0,Math.min(n-1,Math.floor(s*=n)));return a[o](s-o)}}function QB(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t(n/(e-1));return r}var yo=0,Bl=0,Dl=0,Z5=1e3,Ku,Ol,Zu=0,_s=0,Qu=0,Fl=typeof performance=="object"&&performance.now?performance:Date,Q5=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Pl(){return _s||(Q5(JB),_s=Fl.now()+Qu)}function JB(){_s=0}function ql(){this._call=this._time=this._next=null}ql.prototype=Ju.prototype={constructor:ql,restart:function(t,e,r){if(typeof t!="function")throw new TypeError("callback is not a function");r=(r==null?Pl():+r)+(e==null?0:+e),!this._next&&Ol!==this&&(Ol?Ol._next=this:Ku=this,Ol=this),this._call=t,this._time=r,bd()},stop:function(){this._call&&(this._call=null,this._time=1/0,bd())}};function Ju(t,e,r){var n=new ql;return n.restart(t,e,r),n}function J5(){Pl(),++yo;for(var t=Ku,e;t;)(e=_s-t._time)>=0&&t._call.call(void 0,e),t=t._next;--yo}function tv(){_s=(Zu=Fl.now())+Qu,yo=Bl=0;try{J5()}finally{yo=0,eD(),_s=0}}function tD(){var t=Fl.now(),e=t-Zu;e>Z5&&(Qu-=e,Zu=t)}function eD(){for(var t,e=Ku,r,n=1/0;e;)e._call?(n>e._time&&(n=e._time),t=e,e=e._next):(r=e._next,e._next=null,e=t?t._next=r:Ku=r);Ol=t,bd(n)}function bd(t){if(!yo){Bl&&(Bl=clearTimeout(Bl));var e=t-_s;e>24?(t<1/0&&(Bl=setTimeout(tv,t-Fl.now()-Qu)),Dl&&(Dl=clearInterval(Dl))):(Dl||(Zu=Fl.now(),Dl=setInterval(tD,Z5)),yo=1,Q5(tv))}}function _d(t,e,r){var n=new ql;return e=e==null?0:+e,n.restart(i=>{n.stop(),t(i+e)},e,r),n}function rD(t,e,r){var n=new ql,i=e;return e==null?(n.restart(t,e,r),n):(n._restart=n.restart,n.restart=function(a,s,o){s=+s,o=o==null?Pl():+o,n._restart(function l(u){u+=i,n._restart(l,i+=s,o),a(u)},s,o)},n.restart(t,e,r),n)}var nD=fs("start","end","cancel","interrupt"),iD=[],ev=0,vd=1,xd=2,th=3,rv=4,kd=5,eh=6;function rh(t,e,r,n,i,a){var s=t.__transition;if(!s)t.__transition={};else if(r in s)return;aD(t,r,{name:e,index:n,group:i,on:nD,tween:iD,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:ev})}function wd(t,e){var r=Jn(t,e);if(r.state>ev)throw new Error("too late; already scheduled");return r}function Ei(t,e){var r=Jn(t,e);if(r.state>th)throw new Error("too late; already running");return r}function Jn(t,e){var r=t.__transition;if(!r||!(r=r[e]))throw new Error("transition not found");return r}function aD(t,e,r){var n=t.__transition,i;n[e]=r,r.timer=Ju(a,0,r.time);function a(u){r.state=vd,r.timer.restart(s,r.delay,r.time),r.delay<=u&&s(u-r.delay)}function s(u){var h,d,f,p;if(r.state!==vd)return l();for(h in n)if(p=n[h],p.name===r.name){if(p.state===th)return _d(s);p.state===rv?(p.state=eh,p.timer.stop(),p.on.call("interrupt",t,t.__data__,p.index,p.group),delete n[h]):+h<e&&(p.state=eh,p.timer.stop(),p.on.call("cancel",t,t.__data__,p.index,p.group),delete n[h])}if(_d(function(){r.state===th&&(r.state=rv,r.timer.restart(o,r.delay,r.time),o(u))}),r.state=xd,r.on.call("start",t,t.__data__,r.index,r.group),r.state===xd){for(r.state=th,i=new Array(f=r.tween.length),h=0,d=-1;h<f;++h)(p=r.tween[h].value.call(t,t.__data__,r.index,r.group))&&(i[++d]=p);i.length=d+1}}function o(u){for(var h=u<r.duration?r.ease.call(null,u/r.duration):(r.timer.restart(l),r.state=kd,1),d=-1,f=i.length;++d<f;)i[d].call(t,h);r.state===kd&&(r.on.call("end",t,t.__data__,r.index,r.group),l())}function l(){r.state=eh,r.timer.stop(),delete n[e];for(var u in n)return;delete t.__transition}}function vs(t,e){var r=t.__transition,n,i,a=!0,s;if(!!r){e=e==null?null:e+"";for(s in r){if((n=r[s]).name!==e){a=!1;continue}i=n.state>xd&&n.state<kd,n.state=eh,n.timer.stop(),n.on.call(i?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete r[s]}a&&delete t.__transition}}function sD(t){return this.each(function(){vs(this,t)})}function oD(t,e){var r,n;return function(){var i=Ei(this,t),a=i.tween;if(a!==r){n=r=a;for(var s=0,o=n.length;s<o;++s)if(n[s].name===e){n=n.slice(),n.splice(s,1);break}}i.tween=n}}function lD(t,e,r){var n,i;if(typeof r!="function")throw new Error;return function(){var a=Ei(this,t),s=a.tween;if(s!==n){i=(n=s).slice();for(var o={name:e,value:r},l=0,u=i.length;l<u;++l)if(i[l].name===e){i[l]=o;break}l===u&&i.push(o)}a.tween=i}}function cD(t,e){var r=this._id;if(t+="",arguments.length<2){for(var n=Jn(this.node(),r).tween,i=0,a=n.length,s;i<a;++i)if((s=n[i]).name===t)return s.value;return null}return this.each((e==null?oD:lD)(r,t,e))}function Td(t,e,r){var n=t._id;return t.each(function(){var i=Ei(this,n);(i.value||(i.value={}))[e]=r.apply(this,arguments)}),function(i){return Jn(i,n).value[e]}}function nv(t,e){var r;return(typeof e=="number"?Bn:e instanceof Aa?Nl:(r=Aa(e))?(e=r,Nl):yd)(t,e)}function uD(t){return function(){this.removeAttribute(t)}}function hD(t){return function(){this.removeAttributeNS(t.space,t.local)}}function fD(t,e,r){var n,i=r+"",a;return function(){var s=this.getAttribute(t);return s===i?null:s===n?a:a=e(n=s,r)}}function dD(t,e,r){var n,i=r+"",a;return function(){var s=this.getAttributeNS(t.space,t.local);return s===i?null:s===n?a:a=e(n=s,r)}}function pD(t,e,r){var n,i,a;return function(){var s,o=r(this),l;return o==null?void this.removeAttribute(t):(s=this.getAttribute(t),l=o+"",s===l?null:s===n&&l===i?a:(i=l,a=e(n=s,o)))}}function gD(t,e,r){var n,i,a;return function(){var s,o=r(this),l;return o==null?void this.removeAttributeNS(t.space,t.local):(s=this.getAttributeNS(t.space,t.local),l=o+"",s===l?null:s===n&&l===i?a:(i=l,a=e(n=s,o)))}}function yD(t,e){var r=Al(t),n=r==="transform"?U5:nv;return this.attrTween(t,typeof e=="function"?(r.local?gD:pD)(r,n,Td(this,"attr."+t,e)):e==null?(r.local?hD:uD)(r):(r.local?dD:fD)(r,n,e))}function mD(t,e){return function(r){this.setAttribute(t,e.call(this,r))}}function bD(t,e){return function(r){this.setAttributeNS(t.space,t.local,e.call(this,r))}}function _D(t,e){var r,n;function i(){var a=e.apply(this,arguments);return a!==n&&(r=(n=a)&&bD(t,a)),r}return i._value=e,i}function vD(t,e){var r,n;function i(){var a=e.apply(this,arguments);return a!==n&&(r=(n=a)&&mD(t,a)),r}return i._value=e,i}function xD(t,e){var r="attr."+t;if(arguments.length<2)return(r=this.tween(r))&&r._value;if(e==null)return this.tween(r,null);if(typeof e!="function")throw new Error;var n=Al(t);return this.tween(r,(n.local?_D:vD)(n,e))}function kD(t,e){return function(){wd(this,t).delay=+e.apply(this,arguments)}}function wD(t,e){return e=+e,function(){wd(this,t).delay=e}}function TD(t){var e=this._id;return arguments.length?this.each((typeof t=="function"?kD:wD)(e,t)):Jn(this.node(),e).delay}function ED(t,e){return function(){Ei(this,t).duration=+e.apply(this,arguments)}}function CD(t,e){return e=+e,function(){Ei(this,t).duration=e}}function SD(t){var e=this._id;return arguments.length?this.each((typeof t=="function"?ED:CD)(e,t)):Jn(this.node(),e).duration}function AD(t,e){if(typeof e!="function")throw new Error;return function(){Ei(this,t).ease=e}}function MD(t){var e=this._id;return arguments.length?this.each(AD(e,t)):Jn(this.node(),e).ease}function LD(t,e){return function(){var r=e.apply(this,arguments);if(typeof r!="function")throw new Error;Ei(this,t).ease=r}}function RD(t){if(typeof t!="function")throw new Error;return this.each(LD(this._id,t))}function ID(t){typeof t!="function"&&(t=Q0(t));for(var e=this._groups,r=e.length,n=new Array(r),i=0;i<r;++i)for(var a=e[i],s=a.length,o=n[i]=[],l,u=0;u<s;++u)(l=a[u])&&t.call(l,l.__data__,u,a)&&o.push(l);return new Ci(n,this._parents,this._name,this._id)}function ND(t){if(t._id!==this._id)throw new Error;for(var e=this._groups,r=t._groups,n=e.length,i=r.length,a=Math.min(n,i),s=new Array(n),o=0;o<a;++o)for(var l=e[o],u=r[o],h=l.length,d=s[o]=new Array(h),f,p=0;p<h;++p)(f=l[p]||u[p])&&(d[p]=f);for(;o<n;++o)s[o]=e[o];return new Ci(s,this._parents,this._name,this._id)}function BD(t){return(t+"").trim().split(/^|\s+/).every(function(e){var r=e.indexOf(".");return r>=0&&(e=e.slice(0,r)),!e||e==="start"})}function DD(t,e,r){var n,i,a=BD(e)?wd:Ei;return function(){var s=a(this,t),o=s.on;o!==n&&(i=(n=o).copy()).on(e,r),s.on=i}}function OD(t,e){var r=this._id;return arguments.length<2?Jn(this.node(),r).on.on(t):this.each(DD(r,t,e))}function FD(t){return function(){var e=this.parentNode;for(var r in this.__transition)if(+r!==t)return;e&&e.removeChild(this)}}function PD(){return this.on("end.remove",FD(this._id))}function qD(t){var e=this._name,r=this._id;typeof t!="function"&&(t=Ru(t));for(var n=this._groups,i=n.length,a=new Array(i),s=0;s<i;++s)for(var o=n[s],l=o.length,u=a[s]=new Array(l),h,d,f=0;f<l;++f)(h=o[f])&&(d=t.call(h,h.__data__,f,o))&&("__data__"in h&&(d.__data__=h.__data__),u[f]=d,rh(u[f],e,r,f,u,Jn(h,r)));return new Ci(a,this._parents,e,r)}function VD(t){var e=this._name,r=this._id;typeof t!="function"&&(t=Z0(t));for(var n=this._groups,i=n.length,a=[],s=[],o=0;o<i;++o)for(var l=n[o],u=l.length,h,d=0;d<u;++d)if(h=l[d]){for(var f=t.call(h,h.__data__,d,l),p,m=Jn(h,r),_=0,y=f.length;_<y;++_)(p=f[_])&&rh(p,e,r,_,f,m);a.push(f),s.push(h)}return new Ci(a,s,e,r)}var zD=ps.prototype.constructor;function YD(){return new zD(this._groups,this._parents)}function UD(t,e){var r,n,i;return function(){var a=ds(this,t),s=(this.style.removeProperty(t),ds(this,t));return a===s?null:a===r&&s===n?i:i=e(r=a,n=s)}}function iv(t){return function(){this.style.removeProperty(t)}}function WD(t,e,r){var n,i=r+"",a;return function(){var s=ds(this,t);return s===i?null:s===n?a:a=e(n=s,r)}}function HD(t,e,r){var n,i,a;return function(){var s=ds(this,t),o=r(this),l=o+"";return o==null&&(l=o=(this.style.removeProperty(t),ds(this,t))),s===l?null:s===n&&l===i?a:(i=l,a=e(n=s,o))}}function GD(t,e){var r,n,i,a="style."+e,s="end."+a,o;return function(){var l=Ei(this,t),u=l.on,h=l.value[a]==null?o||(o=iv(e)):void 0;(u!==r||i!==h)&&(n=(r=u).copy()).on(s,i=h),l.on=n}}function jD(t,e,r){var n=(t+="")=="transform"?Y5:nv;return e==null?this.styleTween(t,UD(t,n)).on("end.style."+t,iv(t)):typeof e=="function"?this.styleTween(t,HD(t,n,Td(this,"style."+t,e))).each(GD(this._id,t)):this.styleTween(t,WD(t,n,e),r).on("end.style."+t,null)}function $D(t,e,r){return function(n){this.style.setProperty(t,e.call(this,n),r)}}function XD(t,e,r){var n,i;function a(){var s=e.apply(this,arguments);return s!==i&&(n=(i=s)&&$D(t,s,r)),n}return a._value=e,a}function KD(t,e,r){var n="style."+(t+="");if(arguments.length<2)return(n=this.tween(n))&&n._value;if(e==null)return this.tween(n,null);if(typeof e!="function")throw new Error;return this.tween(n,XD(t,e,r==null?"":r))}function ZD(t){return function(){this.textContent=t}}function QD(t){return function(){var e=t(this);this.textContent=e==null?"":e}}function JD(t){return this.tween("text",typeof t=="function"?QD(Td(this,"text",t)):ZD(t==null?"":t+""))}function tO(t){return function(e){this.textContent=t.call(this,e)}}function eO(t){var e,r;function n(){var i=t.apply(this,arguments);return i!==r&&(e=(r=i)&&tO(i)),e}return n._value=t,n}function rO(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(t==null)return this.tween(e,null);if(typeof t!="function")throw new Error;return this.tween(e,eO(t))}function nO(){for(var t=this._name,e=this._id,r=sv(),n=this._groups,i=n.length,a=0;a<i;++a)for(var s=n[a],o=s.length,l,u=0;u<o;++u)if(l=s[u]){var h=Jn(l,e);rh(l,t,r,u,s,{time:h.time+h.delay+h.duration,delay:0,duration:h.duration,ease:h.ease})}return new Ci(n,this._parents,t,r)}function iO(){var t,e,r=this,n=r._id,i=r.size();return new Promise(function(a,s){var o={value:s},l={value:function(){--i===0&&a()}};r.each(function(){var u=Ei(this,n),h=u.on;h!==t&&(e=(t=h).copy(),e._.cancel.push(o),e._.interrupt.push(o),e._.end.push(l)),u.on=e}),i===0&&a()})}var aO=0;function Ci(t,e,r,n){this._groups=t,this._parents=e,this._name=r,this._id=n}function av(t){return ps().transition(t)}function sv(){return++aO}var $i=ps.prototype;Ci.prototype=av.prototype={constructor:Ci,select:qD,selectAll:VD,selectChild:$i.selectChild,selectChildren:$i.selectChildren,filter:ID,merge:ND,selection:YD,transition:nO,call:$i.call,nodes:$i.nodes,node:$i.node,size:$i.size,empty:$i.empty,each:$i.each,on:OD,attr:yD,attrTween:xD,style:jD,styleTween:KD,text:JD,textTween:rO,remove:PD,tween:cD,delay:TD,duration:SD,ease:MD,easeVarying:RD,end:iO,[Symbol.iterator]:$i[Symbol.iterator]};const sO=t=>+t;function oO(t){return t*t}function lO(t){return t*(2-t)}function ov(t){return((t*=2)<=1?t*t:--t*(2-t)+1)/2}function cO(t){return t*t*t}function uO(t){return--t*t*t+1}function Ed(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}var Cd=3,hO=function t(e){e=+e;function r(n){return Math.pow(n,e)}return r.exponent=t,r}(Cd),fO=function t(e){e=+e;function r(n){return 1-Math.pow(1-n,e)}return r.exponent=t,r}(Cd),lv=function t(e){e=+e;function r(n){return((n*=2)<=1?Math.pow(n,e):2-Math.pow(2-n,e))/2}return r.exponent=t,r}(Cd),cv=Math.PI,uv=cv/2;function dO(t){return+t==1?1:1-Math.cos(t*uv)}function pO(t){return Math.sin(t*uv)}function hv(t){return(1-Math.cos(cv*t))/2}function La(t){return(Math.pow(2,-10*t)-.0009765625)*1.0009775171065494}function gO(t){return La(1-+t)}function yO(t){return 1-La(t)}function fv(t){return((t*=2)<=1?La(1-t):2-La(t-1))/2}function mO(t){return 1-Math.sqrt(1-t*t)}function bO(t){return Math.sqrt(1- --t*t)}function dv(t){return((t*=2)<=1?1-Math.sqrt(1-t*t):Math.sqrt(1-(t-=2)*t)+1)/2}var Sd=4/11,_O=6/11,vO=8/11,xO=3/4,kO=9/11,wO=10/11,TO=15/16,EO=21/22,CO=63/64,nh=1/Sd/Sd;function SO(t){return 1-Vl(1-t)}function Vl(t){return(t=+t)<Sd?nh*t*t:t<vO?nh*(t-=_O)*t+xO:t<wO?nh*(t-=kO)*t+TO:nh*(t-=EO)*t+CO}function AO(t){return((t*=2)<=1?1-Vl(1-t):Vl(t-1)+1)/2}var Ad=1.70158,MO=function t(e){e=+e;function r(n){return(n=+n)*n*(e*(n-1)+n)}return r.overshoot=t,r}(Ad),LO=function t(e){e=+e;function r(n){return--n*n*((n+1)*e+n)+1}return r.overshoot=t,r}(Ad),pv=function t(e){e=+e;function r(n){return((n*=2)<1?n*n*((e+1)*n-e):(n-=2)*n*((e+1)*n+e)+2)/2}return r.overshoot=t,r}(Ad),mo=2*Math.PI,Md=1,Ld=.3,RO=function t(e,r){var n=Math.asin(1/(e=Math.max(1,e)))*(r/=mo);function i(a){return e*La(- --a)*Math.sin((n-a)/r)}return i.amplitude=function(a){return t(a,r*mo)},i.period=function(a){return t(e,a)},i}(Md,Ld),gv=function t(e,r){var n=Math.asin(1/(e=Math.max(1,e)))*(r/=mo);function i(a){return 1-e*La(a=+a)*Math.sin((a+n)/r)}return i.amplitude=function(a){return t(a,r*mo)},i.period=function(a){return t(e,a)},i}(Md,Ld),IO=function t(e,r){var n=Math.asin(1/(e=Math.max(1,e)))*(r/=mo);function i(a){return((a=a*2-1)<0?e*La(-a)*Math.sin((n-a)/r):2-e*La(a)*Math.sin((n+a)/r))/2}return i.amplitude=function(a){return t(a,r*mo)},i.period=function(a){return t(e,a)},i}(Md,Ld),NO={time:null,delay:0,duration:250,ease:Ed};function BO(t,e){for(var r;!(r=t.__transition)||!(r=r[e]);)if(!(t=t.parentNode))throw new Error(`transition ${e} not found`);return r}function DO(t){var e,r;t instanceof Ci?(e=t._id,t=t._name):(e=sv(),(r=NO).time=Pl(),t=t==null?null:t+"");for(var n=this._groups,i=n.length,a=0;a<i;++a)for(var s=n[a],o=s.length,l,u=0;u<o;++u)(l=s[u])&&rh(l,t,e,u,s,r||BO(l,e));return new Ci(n,this._parents,t,e)}ps.prototype.interrupt=sD,ps.prototype.transition=DO;var OO=[null];function FO(t,e){var r=t.__transition,n,i;if(r){e=e==null?null:e+"";for(i in r)if((n=r[i]).state>vd&&n.name===e)return new Ci([[t]],OO,e,+i)}return null}const Rd=t=>()=>t;function PO(t,{sourceEvent:e,target:r,selection:n,mode:i,dispatch:a}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},selection:{value:n,enumerable:!0,configurable:!0},mode:{value:i,enumerable:!0,configurable:!0},_:{value:a}})}function qO(t){t.stopImmediatePropagation()}function Id(t){t.preventDefault(),t.stopImmediatePropagation()}var yv={name:"drag"},Nd={name:"space"},bo={name:"handle"},_o={name:"center"};const{abs:mv,max:Or,min:Fr}=Math;function bv(t){return[+t[0],+t[1]]}function Bd(t){return[bv(t[0]),bv(t[1])]}var ih={name:"x",handles:["w","e"].map(zl),input:function(t,e){return t==null?null:[[+t[0],e[0][1]],[+t[1],e[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},ah={name:"y",handles:["n","s"].map(zl),input:function(t,e){return t==null?null:[[e[0][0],+t[0]],[e[1][0],+t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},VO={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(zl),input:function(t){return t==null?null:Bd(t)},output:function(t){return t}},Xi={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},_v={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},vv={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},zO={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},YO={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function zl(t){return{type:t}}function UO(t){return!t.ctrlKey&&!t.button}function WO(){var t=this.ownerSVGElement||this;return t.hasAttribute("viewBox")?(t=t.viewBox.baseVal,[[t.x,t.y],[t.x+t.width,t.y+t.height]]):[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]}function HO(){return navigator.maxTouchPoints||"ontouchstart"in this}function Dd(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function GO(t){return t[0][0]===t[1][0]||t[0][1]===t[1][1]}function jO(t){var e=t.__brush;return e?e.dim.output(e.selection):null}function $O(){return Od(ih)}function XO(){return Od(ah)}function KO(){return Od(VO)}function Od(t){var e=WO,r=UO,n=HO,i=!0,a=fs("start","brush","end"),s=6,o;function l(y){var b=y.property("__brush",_).selectAll(".overlay").data([zl("overlay")]);b.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",Xi.overlay).merge(b).each(function(){var k=Dd(this).extent;St(this).attr("x",k[0][0]).attr("y",k[0][1]).attr("width",k[1][0]-k[0][0]).attr("height",k[1][1]-k[0][1])}),y.selectAll(".selection").data([zl("selection")]).enter().append("rect").attr("class","selection").attr("cursor",Xi.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var x=y.selectAll(".handle").data(t.handles,function(k){return k.type});x.exit().remove(),x.enter().append("rect").attr("class",function(k){return"handle handle--"+k.type}).attr("cursor",function(k){return Xi[k.type]}),y.each(u).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",f).filter(n).on("touchstart.brush",f).on("touchmove.brush",p).on("touchend.brush touchcancel.brush",m).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}l.move=function(y,b,x){y.tween?y.on("start.brush",function(k){h(this,arguments).beforestart().start(k)}).on("interrupt.brush end.brush",function(k){h(this,arguments).end(k)}).tween("brush",function(){var k=this,T=k.__brush,C=h(k,arguments),M=T.selection,S=t.input(typeof b=="function"?b.apply(this,arguments):b,T.extent),R=Ma(M,S);function A(L){T.selection=L===1&&S===null?null:R(L),u.call(k),C.brush()}return M!==null&&S!==null?A:A(1)}):y.each(function(){var k=this,T=arguments,C=k.__brush,M=t.input(typeof b=="function"?b.apply(k,T):b,C.extent),S=h(k,T).beforestart();vs(k),C.selection=M===null?null:M,u.call(k),S.start(x).brush(x).end(x)})},l.clear=function(y,b){l.move(y,null,b)};function u(){var y=St(this),b=Dd(this).selection;b?(y.selectAll(".selection").style("display",null).attr("x",b[0][0]).attr("y",b[0][1]).attr("width",b[1][0]-b[0][0]).attr("height",b[1][1]-b[0][1]),y.selectAll(".handle").style("display",null).attr("x",function(x){return x.type[x.type.length-1]==="e"?b[1][0]-s/2:b[0][0]-s/2}).attr("y",function(x){return x.type[0]==="s"?b[1][1]-s/2:b[0][1]-s/2}).attr("width",function(x){return x.type==="n"||x.type==="s"?b[1][0]-b[0][0]+s:s}).attr("height",function(x){return x.type==="e"||x.type==="w"?b[1][1]-b[0][1]+s:s})):y.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function h(y,b,x){var k=y.__brush.emitter;return k&&(!x||!k.clean)?k:new d(y,b,x)}function d(y,b,x){this.that=y,this.args=b,this.state=y.__brush,this.active=0,this.clean=x}d.prototype={beforestart:function(){return++this.active===1&&(this.state.emitter=this,this.starting=!0),this},start:function(y,b){return this.starting?(this.starting=!1,this.emit("start",y,b)):this.emit("brush",y),this},brush:function(y,b){return this.emit("brush",y,b),this},end:function(y,b){return--this.active===0&&(delete this.state.emitter,this.emit("end",y,b)),this},emit:function(y,b,x){var k=St(this.that).datum();a.call(y,this.that,new PO(y,{sourceEvent:b,target:l,selection:t.output(this.state.selection),mode:x,dispatch:a}),k)}};function f(y){if(o&&!y.touches||!r.apply(this,arguments))return;var b=this,x=y.target.__data__.type,k=(i&&y.metaKey?x="overlay":x)==="selection"?yv:i&&y.altKey?_o:bo,T=t===ah?null:zO[x],C=t===ih?null:YO[x],M=Dd(b),S=M.extent,R=M.selection,A=S[0][0],L,v,B=S[0][1],w,D,N=S[1][0],z,X,ct=S[1][1],J,Y,$=0,lt=0,ut,W=T&&C&&i&&y.shiftKey,tt,K,it=Array.from(y.touches||[y],at=>{const It=at.identifier;return at=Tn(at,b),at.point0=at.slice(),at.identifier=It,at});vs(b);var Z=h(b,arguments,!0).beforestart();if(x==="overlay"){R&&(ut=!0);const at=[it[0],it[1]||it[0]];M.selection=R=[[L=t===ah?A:Fr(at[0][0],at[1][0]),w=t===ih?B:Fr(at[0][1],at[1][1])],[z=t===ah?N:Or(at[0][0],at[1][0]),J=t===ih?ct:Or(at[0][1],at[1][1])]],it.length>1&&F(y)}else L=R[0][0],w=R[0][1],z=R[1][0],J=R[1][1];v=L,D=w,X=z,Y=J;var V=St(b).attr("pointer-events","none"),Q=V.selectAll(".overlay").attr("cursor",Xi[x]);if(y.touches)Z.moved=U,Z.ended=j;else{var q=St(y.view).on("mousemove.brush",U,!0).on("mouseup.brush",j,!0);i&&q.on("keydown.brush",P,!0).on("keyup.brush",et,!0),Bu(y.view)}u.call(b),Z.start(y,k.name);function U(at){for(const It of at.changedTouches||[at])for(const Lt of it)Lt.identifier===It.identifier&&(Lt.cur=Tn(It,b));if(W&&!tt&&!K&&it.length===1){const It=it[0];mv(It.cur[0]-It[0])>mv(It.cur[1]-It[1])?K=!0:tt=!0}for(const It of it)It.cur&&(It[0]=It.cur[0],It[1]=It.cur[1]);ut=!0,Id(at),F(at)}function F(at){const It=it[0],Lt=It.point0;var Rt;switch($=It[0]-Lt[0],lt=It[1]-Lt[1],k){case Nd:case yv:{T&&($=Or(A-L,Fr(N-z,$)),v=L+$,X=z+$),C&&(lt=Or(B-w,Fr(ct-J,lt)),D=w+lt,Y=J+lt);break}case bo:{it[1]?(T&&(v=Or(A,Fr(N,it[0][0])),X=Or(A,Fr(N,it[1][0])),T=1),C&&(D=Or(B,Fr(ct,it[0][1])),Y=Or(B,Fr(ct,it[1][1])),C=1)):(T<0?($=Or(A-L,Fr(N-L,$)),v=L+$,X=z):T>0&&($=Or(A-z,Fr(N-z,$)),v=L,X=z+$),C<0?(lt=Or(B-w,Fr(ct-w,lt)),D=w+lt,Y=J):C>0&&(lt=Or(B-J,Fr(ct-J,lt)),D=w,Y=J+lt));break}case _o:{T&&(v=Or(A,Fr(N,L-$*T)),X=Or(A,Fr(N,z+$*T))),C&&(D=Or(B,Fr(ct,w-lt*C)),Y=Or(B,Fr(ct,J+lt*C)));break}}X<v&&(T*=-1,Rt=L,L=z,z=Rt,Rt=v,v=X,X=Rt,x in _v&&Q.attr("cursor",Xi[x=_v[x]])),Y<D&&(C*=-1,Rt=w,w=J,J=Rt,Rt=D,D=Y,Y=Rt,x in vv&&Q.attr("cursor",Xi[x=vv[x]])),M.selection&&(R=M.selection),tt&&(v=R[0][0],X=R[1][0]),K&&(D=R[0][1],Y=R[1][1]),(R[0][0]!==v||R[0][1]!==D||R[1][0]!==X||R[1][1]!==Y)&&(M.selection=[[v,D],[X,Y]],u.call(b),Z.brush(at,k.name))}function j(at){if(qO(at),at.touches){if(at.touches.length)return;o&&clearTimeout(o),o=setTimeout(function(){o=null},500)}else Du(at.view,ut),q.on("keydown.brush keyup.brush mousemove.brush mouseup.brush",null);V.attr("pointer-events","all"),Q.attr("cursor",Xi.overlay),M.selection&&(R=M.selection),GO(R)&&(M.selection=null,u.call(b)),Z.end(at,k.name)}function P(at){switch(at.keyCode){case 16:{W=T&&C;break}case 18:{k===bo&&(T&&(z=X-$*T,L=v+$*T),C&&(J=Y-lt*C,w=D+lt*C),k=_o,F(at));break}case 32:{(k===bo||k===_o)&&(T<0?z=X-$:T>0&&(L=v-$),C<0?J=Y-lt:C>0&&(w=D-lt),k=Nd,Q.attr("cursor",Xi.selection),F(at));break}default:return}Id(at)}function et(at){switch(at.keyCode){case 16:{W&&(tt=K=W=!1,F(at));break}case 18:{k===_o&&(T<0?z=X:T>0&&(L=v),C<0?J=Y:C>0&&(w=D),k=bo,F(at));break}case 32:{k===Nd&&(at.altKey?(T&&(z=X-$*T,L=v+$*T),C&&(J=Y-lt*C,w=D+lt*C),k=_o):(T<0?z=X:T>0&&(L=v),C<0?J=Y:C>0&&(w=D),k=bo),Q.attr("cursor",Xi[x]),F(at));break}default:return}Id(at)}}function p(y){h(this,arguments).moved(y)}function m(y){h(this,arguments).ended(y)}function _(){var y=this.__brush||{selection:null};return y.extent=Bd(e.apply(this,arguments)),y.dim=t,y}return l.extent=function(y){return arguments.length?(e=typeof y=="function"?y:Rd(Bd(y)),l):e},l.filter=function(y){return arguments.length?(r=typeof y=="function"?y:Rd(!!y),l):r},l.touchable=function(y){return arguments.length?(n=typeof y=="function"?y:Rd(!!y),l):n},l.handleSize=function(y){return arguments.length?(s=+y,l):s},l.keyModifiers=function(y){return arguments.length?(i=!!y,l):i},l.on=function(){var y=a.on.apply(a,arguments);return y===a?l:y},l}var xv=Math.abs,vo=Math.cos,xo=Math.sin,kv=Math.PI,sh=kv/2,wv=kv*2,Tv=Math.max,Fd=1e-12;function Pd(t,e){return Array.from({length:e-t},(r,n)=>t+n)}function ZO(t){return function(e,r){return t(e.source.value+e.target.value,r.source.value+r.target.value)}}function QO(){return qd(!1,!1)}function JO(){return qd(!1,!0)}function tF(){return qd(!0,!1)}function qd(t,e){var r=0,n=null,i=null,a=null;function s(o){var l=o.length,u=new Array(l),h=Pd(0,l),d=new Array(l*l),f=new Array(l),p=0,m;o=Float64Array.from({length:l*l},e?(_,y)=>o[y%l][y/l|0]:(_,y)=>o[y/l|0][y%l]);for(let _=0;_<l;++_){let y=0;for(let b=0;b<l;++b)y+=o[_*l+b]+t*o[b*l+_];p+=u[_]=y}p=Tv(0,wv-r*l)/p,m=p?r:wv/l;{let _=0;n&&h.sort((y,b)=>n(u[y],u[b]));for(const y of h){const b=_;if(t){const x=Pd(~l+1,l).filter(k=>k<0?o[~k*l+y]:o[y*l+k]);i&&x.sort((k,T)=>i(k<0?-o[~k*l+y]:o[y*l+k],T<0?-o[~T*l+y]:o[y*l+T]));for(const k of x)if(k<0){const T=d[~k*l+y]||(d[~k*l+y]={source:null,target:null});T.target={index:y,startAngle:_,endAngle:_+=o[~k*l+y]*p,value:o[~k*l+y]}}else{const T=d[y*l+k]||(d[y*l+k]={source:null,target:null});T.source={index:y,startAngle:_,endAngle:_+=o[y*l+k]*p,value:o[y*l+k]}}f[y]={index:y,startAngle:b,endAngle:_,value:u[y]}}else{const x=Pd(0,l).filter(k=>o[y*l+k]||o[k*l+y]);i&&x.sort((k,T)=>i(o[y*l+k],o[y*l+T]));for(const k of x){let T;if(y<k?(T=d[y*l+k]||(d[y*l+k]={source:null,target:null}),T.source={index:y,startAngle:_,endAngle:_+=o[y*l+k]*p,value:o[y*l+k]}):(T=d[k*l+y]||(d[k*l+y]={source:null,target:null}),T.target={index:y,startAngle:_,endAngle:_+=o[y*l+k]*p,value:o[y*l+k]},y===k&&(T.source=T.target)),T.source&&T.target&&T.source.value<T.target.value){const C=T.source;T.source=T.target,T.target=C}}f[y]={index:y,startAngle:b,endAngle:_,value:u[y]}}_+=m}}return d=Object.values(d),d.groups=f,a?d.sort(a):d}return s.padAngle=function(o){return arguments.length?(r=Tv(0,o),s):r},s.sortGroups=function(o){return arguments.length?(n=o,s):n},s.sortSubgroups=function(o){return arguments.length?(i=o,s):i},s.sortChords=function(o){return arguments.length?(o==null?a=null:(a=ZO(o))._=o,s):a&&a._},s}const Vd=Math.PI,zd=2*Vd,xs=1e-6,eF=zd-xs;function Yd(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function Ra(){return new Yd}Yd.prototype=Ra.prototype={constructor:Yd,moveTo:function(t,e){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)},closePath:function(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(t,e){this._+="L"+(this._x1=+t)+","+(this._y1=+e)},quadraticCurveTo:function(t,e,r,n){this._+="Q"+ +t+","+ +e+","+(this._x1=+r)+","+(this._y1=+n)},bezierCurveTo:function(t,e,r,n,i,a){this._+="C"+ +t+","+ +e+","+ +r+","+ +n+","+(this._x1=+i)+","+(this._y1=+a)},arcTo:function(t,e,r,n,i){t=+t,e=+e,r=+r,n=+n,i=+i;var a=this._x1,s=this._y1,o=r-t,l=n-e,u=a-t,h=s-e,d=u*u+h*h;if(i<0)throw new Error("negative radius: "+i);if(this._x1===null)this._+="M"+(this._x1=t)+","+(this._y1=e);else if(d>xs)if(!(Math.abs(h*o-l*u)>xs)||!i)this._+="L"+(this._x1=t)+","+(this._y1=e);else{var f=r-a,p=n-s,m=o*o+l*l,_=f*f+p*p,y=Math.sqrt(m),b=Math.sqrt(d),x=i*Math.tan((Vd-Math.acos((m+d-_)/(2*y*b)))/2),k=x/b,T=x/y;Math.abs(k-1)>xs&&(this._+="L"+(t+k*u)+","+(e+k*h)),this._+="A"+i+","+i+",0,0,"+ +(h*f>u*p)+","+(this._x1=t+T*o)+","+(this._y1=e+T*l)}},arc:function(t,e,r,n,i,a){t=+t,e=+e,r=+r,a=!!a;var s=r*Math.cos(n),o=r*Math.sin(n),l=t+s,u=e+o,h=1^a,d=a?n-i:i-n;if(r<0)throw new Error("negative radius: "+r);this._x1===null?this._+="M"+l+","+u:(Math.abs(this._x1-l)>xs||Math.abs(this._y1-u)>xs)&&(this._+="L"+l+","+u),r&&(d<0&&(d=d%zd+zd),d>eF?this._+="A"+r+","+r+",0,1,"+h+","+(t-s)+","+(e-o)+"A"+r+","+r+",0,1,"+h+","+(this._x1=l)+","+(this._y1=u):d>xs&&(this._+="A"+r+","+r+",0,"+ +(d>=Vd)+","+h+","+(this._x1=t+r*Math.cos(i))+","+(this._y1=e+r*Math.sin(i))))},rect:function(t,e,r,n){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)+"h"+ +r+"v"+ +n+"h"+-r+"Z"},toString:function(){return this._}};var rF=Array.prototype.slice;function ks(t){return function(){return t}}function nF(t){return t.source}function iF(t){return t.target}function Ev(t){return t.radius}function aF(t){return t.startAngle}function sF(t){return t.endAngle}function oF(){return 0}function lF(){return 10}function Cv(t){var e=nF,r=iF,n=Ev,i=Ev,a=aF,s=sF,o=oF,l=null;function u(){var h,d=e.apply(this,arguments),f=r.apply(this,arguments),p=o.apply(this,arguments)/2,m=rF.call(arguments),_=+n.apply(this,(m[0]=d,m)),y=a.apply(this,m)-sh,b=s.apply(this,m)-sh,x=+i.apply(this,(m[0]=f,m)),k=a.apply(this,m)-sh,T=s.apply(this,m)-sh;if(l||(l=h=Ra()),p>Fd&&(xv(b-y)>p*2+Fd?b>y?(y+=p,b-=p):(y-=p,b+=p):y=b=(y+b)/2,xv(T-k)>p*2+Fd?T>k?(k+=p,T-=p):(k-=p,T+=p):k=T=(k+T)/2),l.moveTo(_*vo(y),_*xo(y)),l.arc(0,0,_,y,b),y!==k||b!==T)if(t){var C=+t.apply(this,arguments),M=x-C,S=(k+T)/2;l.quadraticCurveTo(0,0,M*vo(k),M*xo(k)),l.lineTo(x*vo(S),x*xo(S)),l.lineTo(M*vo(T),M*xo(T))}else l.quadraticCurveTo(0,0,x*vo(k),x*xo(k)),l.arc(0,0,x,k,T);if(l.quadraticCurveTo(0,0,_*vo(y),_*xo(y)),l.closePath(),h)return l=null,h+""||null}return t&&(u.headRadius=function(h){return arguments.length?(t=typeof h=="function"?h:ks(+h),u):t}),u.radius=function(h){return arguments.length?(n=i=typeof h=="function"?h:ks(+h),u):n},u.sourceRadius=function(h){return arguments.length?(n=typeof h=="function"?h:ks(+h),u):n},u.targetRadius=function(h){return arguments.length?(i=typeof h=="function"?h:ks(+h),u):i},u.startAngle=function(h){return arguments.length?(a=typeof h=="function"?h:ks(+h),u):a},u.endAngle=function(h){return arguments.length?(s=typeof h=="function"?h:ks(+h),u):s},u.padAngle=function(h){return arguments.length?(o=typeof h=="function"?h:ks(+h),u):o},u.source=function(h){return arguments.length?(e=h,u):e},u.target=function(h){return arguments.length?(r=h,u):r},u.context=function(h){return arguments.length?(l=h==null?null:h,u):l},u}function cF(){return Cv()}function uF(){return Cv(lF)}var hF=Array.prototype,Sv=hF.slice;function fF(t,e){return t-e}function dF(t){for(var e=0,r=t.length,n=t[r-1][1]*t[0][0]-t[r-1][0]*t[0][1];++e<r;)n+=t[e-1][1]*t[e][0]-t[e-1][0]*t[e][1];return n}const Ia=t=>()=>t;function pF(t,e){for(var r=-1,n=e.length,i;++r<n;)if(i=gF(t,e[r]))return i;return 0}function gF(t,e){for(var r=e[0],n=e[1],i=-1,a=0,s=t.length,o=s-1;a<s;o=a++){var l=t[a],u=l[0],h=l[1],d=t[o],f=d[0],p=d[1];if(yF(l,d,e))return 0;h>n!=p>n&&r<(f-u)*(n-h)/(p-h)+u&&(i=-i)}return i}function yF(t,e,r){var n;return mF(t,e,r)&&bF(t[n=+(t[0]===e[0])],r[n],e[n])}function mF(t,e,r){return(e[0]-t[0])*(r[1]-t[1])===(r[0]-t[0])*(e[1]-t[1])}function bF(t,e,r){return t<=e&&e<=r||r<=e&&e<=t}function _F(){}var Ki=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function Ud(){var t=1,e=1,r=W0,n=l;function i(u){var h=r(u);if(Array.isArray(h))h=h.slice().sort(fF);else{const d=xl(u),f=wl(d[0],d[1],h);h=hs(Math.floor(d[0]/f)*f,Math.floor(d[1]/f-1)*f,h)}return h.map(d=>a(u,d))}function a(u,h){var d=[],f=[];return s(u,h,function(p){n(p,u,h),dF(p)>0?d.push([p]):f.push(p)}),f.forEach(function(p){for(var m=0,_=d.length,y;m<_;++m)if(pF((y=d[m])[0],p)!==-1){y.push(p);return}}),{type:"MultiPolygon",value:h,coordinates:d}}function s(u,h,d){var f=new Array,p=new Array,m,_,y,b,x,k;for(m=_=-1,b=u[0]>=h,Ki[b<<1].forEach(T);++m<t-1;)y=b,b=u[m+1]>=h,Ki[y|b<<1].forEach(T);for(Ki[b<<0].forEach(T);++_<e-1;){for(m=-1,b=u[_*t+t]>=h,x=u[_*t]>=h,Ki[b<<1|x<<2].forEach(T);++m<t-1;)y=b,b=u[_*t+t+m+1]>=h,k=x,x=u[_*t+m+1]>=h,Ki[y|b<<1|x<<2|k<<3].forEach(T);Ki[b|x<<3].forEach(T)}for(m=-1,x=u[_*t]>=h,Ki[x<<2].forEach(T);++m<t-1;)k=x,x=u[_*t+m+1]>=h,Ki[x<<2|k<<3].forEach(T);Ki[x<<3].forEach(T);function T(C){var M=[C[0][0]+m,C[0][1]+_],S=[C[1][0]+m,C[1][1]+_],R=o(M),A=o(S),L,v;(L=p[R])?(v=f[A])?(delete p[L.end],delete f[v.start],L===v?(L.ring.push(S),d(L.ring)):f[L.start]=p[v.end]={start:L.start,end:v.end,ring:L.ring.concat(v.ring)}):(delete p[L.end],L.ring.push(S),p[L.end=A]=L):(L=f[A])?(v=p[R])?(delete f[L.start],delete p[v.end],L===v?(L.ring.push(S),d(L.ring)):f[v.start]=p[L.end]={start:v.start,end:L.end,ring:v.ring.concat(L.ring)}):(delete f[L.start],L.ring.unshift(M),f[L.start=R]=L):f[R]=p[A]={start:R,end:A,ring:[M,S]}}}function o(u){return u[0]*2+u[1]*(t+1)*4}function l(u,h,d){u.forEach(function(f){var p=f[0],m=f[1],_=p|0,y=m|0,b,x=h[y*t+_];p>0&&p<t&&_===p&&(b=h[y*t+_-1],f[0]=p+(d-b)/(x-b)-.5),m>0&&m<e&&y===m&&(b=h[(y-1)*t+_],f[1]=m+(d-b)/(x-b)-.5)})}return i.contour=a,i.size=function(u){if(!arguments.length)return[t,e];var h=Math.floor(u[0]),d=Math.floor(u[1]);if(!(h>=0&&d>=0))throw new Error("invalid size");return t=h,e=d,i},i.thresholds=function(u){return arguments.length?(r=typeof u=="function"?u:Array.isArray(u)?Ia(Sv.call(u)):Ia(u),i):r},i.smooth=function(u){return arguments.length?(n=u?l:_F,i):n===l},i}function vF(t){return t[0]}function xF(t){return t[1]}function kF(){return 1}function wF(){var t=vF,e=xF,r=kF,n=960,i=500,a=20,s=2,o=a*3,l=n+o*2>>s,u=i+o*2>>s,h=Ia(20);function d(x){var k=new Float32Array(l*u),T=Math.pow(2,-s),C=-1;for(const w of x){var M=(t(w,++C,x)+o)*T,S=(e(w,C,x)+o)*T,R=+r(w,C,x);if(M>=0&&M<l&&S>=0&&S<u){var A=Math.floor(M),L=Math.floor(S),v=M-A-.5,B=S-L-.5;k[A+L*l]+=(1-v)*(1-B)*R,k[A+1+L*l]+=v*(1-B)*R,k[A+1+(L+1)*l]+=v*B*R,k[A+(L+1)*l]+=(1-v)*B*R}}return k_({data:k,width:l,height:u},a*T),k}function f(x){var k=d(x),T=h(k),C=Math.pow(2,2*s);return Array.isArray(T)||(T=hs(Number.MIN_VALUE,lo(k)/C,T)),Ud().size([l,u]).thresholds(T.map(M=>M*C))(k).map((M,S)=>(M.value=+T[S],p(M)))}f.contours=function(x){var k=d(x),T=Ud().size([l,u]),C=Math.pow(2,2*s),M=S=>{S=+S;var R=p(T.contour(k,S*C));return R.value=S,R};return Object.defineProperty(M,"max",{get:()=>lo(k)/C}),M};function p(x){return x.coordinates.forEach(m),x}function m(x){x.forEach(_)}function _(x){x.forEach(y)}function y(x){x[0]=x[0]*Math.pow(2,s)-o,x[1]=x[1]*Math.pow(2,s)-o}function b(){return o=a*3,l=n+o*2>>s,u=i+o*2>>s,f}return f.x=function(x){return arguments.length?(t=typeof x=="function"?x:Ia(+x),f):t},f.y=function(x){return arguments.length?(e=typeof x=="function"?x:Ia(+x),f):e},f.weight=function(x){return arguments.length?(r=typeof x=="function"?x:Ia(+x),f):r},f.size=function(x){if(!arguments.length)return[n,i];var k=+x[0],T=+x[1];if(!(k>=0&&T>=0))throw new Error("invalid size");return n=k,i=T,b()},f.cellSize=function(x){if(!arguments.length)return 1<<s;if(!((x=+x)>=1))throw new Error("invalid cell size");return s=Math.floor(Math.log(x)/Math.LN2),b()},f.thresholds=function(x){return arguments.length?(h=typeof x=="function"?x:Array.isArray(x)?Ia(Sv.call(x)):Ia(x),f):h},f.bandwidth=function(x){if(!arguments.length)return Math.sqrt(a*(a+1));if(!((x=+x)>=0))throw new Error("invalid bandwidth");return a=(Math.sqrt(4*x*x+1)-1)/2,b()},f}const Zi=11102230246251565e-32,Pr=134217729,TF=(3+8*Zi)*Zi;function Wd(t,e,r,n,i){let a,s,o,l,u=e[0],h=n[0],d=0,f=0;h>u==h>-u?(a=u,u=e[++d]):(a=h,h=n[++f]);let p=0;if(d<t&&f<r)for(h>u==h>-u?(s=u+a,o=a-(s-u),u=e[++d]):(s=h+a,o=a-(s-h),h=n[++f]),a=s,o!==0&&(i[p++]=o);d<t&&f<r;)h>u==h>-u?(s=a+u,l=s-a,o=a-(s-l)+(u-l),u=e[++d]):(s=a+h,l=s-a,o=a-(s-l)+(h-l),h=n[++f]),a=s,o!==0&&(i[p++]=o);for(;d<t;)s=a+u,l=s-a,o=a-(s-l)+(u-l),u=e[++d],a=s,o!==0&&(i[p++]=o);for(;f<r;)s=a+h,l=s-a,o=a-(s-l)+(h-l),h=n[++f],a=s,o!==0&&(i[p++]=o);return(a!==0||p===0)&&(i[p++]=a),p}function EF(t,e){let r=e[0];for(let n=1;n<t;n++)r+=e[n];return r}function Yl(t){return new Float64Array(t)}const CF=(3+16*Zi)*Zi,SF=(2+12*Zi)*Zi,AF=(9+64*Zi)*Zi*Zi,ko=Yl(4),Av=Yl(8),Mv=Yl(12),Lv=Yl(16),Xr=Yl(4);function MF(t,e,r,n,i,a,s){let o,l,u,h,d,f,p,m,_,y,b,x,k,T,C,M,S,R;const A=t-i,L=r-i,v=e-a,B=n-a;T=A*B,f=Pr*A,p=f-(f-A),m=A-p,f=Pr*B,_=f-(f-B),y=B-_,C=m*y-(T-p*_-m*_-p*y),M=v*L,f=Pr*v,p=f-(f-v),m=v-p,f=Pr*L,_=f-(f-L),y=L-_,S=m*y-(M-p*_-m*_-p*y),b=C-S,d=C-b,ko[0]=C-(b+d)+(d-S),x=T+b,d=x-T,k=T-(x-d)+(b-d),b=k-M,d=k-b,ko[1]=k-(b+d)+(d-M),R=x+b,d=R-x,ko[2]=x-(R-d)+(b-d),ko[3]=R;let w=EF(4,ko),D=SF*s;if(w>=D||-w>=D||(d=t-A,o=t-(A+d)+(d-i),d=r-L,u=r-(L+d)+(d-i),d=e-v,l=e-(v+d)+(d-a),d=n-B,h=n-(B+d)+(d-a),o===0&&l===0&&u===0&&h===0)||(D=AF*s+TF*Math.abs(w),w+=A*h+B*o-(v*u+L*l),w>=D||-w>=D))return w;T=o*B,f=Pr*o,p=f-(f-o),m=o-p,f=Pr*B,_=f-(f-B),y=B-_,C=m*y-(T-p*_-m*_-p*y),M=l*L,f=Pr*l,p=f-(f-l),m=l-p,f=Pr*L,_=f-(f-L),y=L-_,S=m*y-(M-p*_-m*_-p*y),b=C-S,d=C-b,Xr[0]=C-(b+d)+(d-S),x=T+b,d=x-T,k=T-(x-d)+(b-d),b=k-M,d=k-b,Xr[1]=k-(b+d)+(d-M),R=x+b,d=R-x,Xr[2]=x-(R-d)+(b-d),Xr[3]=R;const N=Wd(4,ko,4,Xr,Av);T=A*h,f=Pr*A,p=f-(f-A),m=A-p,f=Pr*h,_=f-(f-h),y=h-_,C=m*y-(T-p*_-m*_-p*y),M=v*u,f=Pr*v,p=f-(f-v),m=v-p,f=Pr*u,_=f-(f-u),y=u-_,S=m*y-(M-p*_-m*_-p*y),b=C-S,d=C-b,Xr[0]=C-(b+d)+(d-S),x=T+b,d=x-T,k=T-(x-d)+(b-d),b=k-M,d=k-b,Xr[1]=k-(b+d)+(d-M),R=x+b,d=R-x,Xr[2]=x-(R-d)+(b-d),Xr[3]=R;const z=Wd(N,Av,4,Xr,Mv);T=o*h,f=Pr*o,p=f-(f-o),m=o-p,f=Pr*h,_=f-(f-h),y=h-_,C=m*y-(T-p*_-m*_-p*y),M=l*u,f=Pr*l,p=f-(f-l),m=l-p,f=Pr*u,_=f-(f-u),y=u-_,S=m*y-(M-p*_-m*_-p*y),b=C-S,d=C-b,Xr[0]=C-(b+d)+(d-S),x=T+b,d=x-T,k=T-(x-d)+(b-d),b=k-M,d=k-b,Xr[1]=k-(b+d)+(d-M),R=x+b,d=R-x,Xr[2]=x-(R-d)+(b-d),Xr[3]=R;const X=Wd(z,Mv,4,Xr,Lv);return Lv[X-1]}function oh(t,e,r,n,i,a){const s=(e-a)*(r-i),o=(t-i)*(n-a),l=s-o;if(s===0||o===0||s>0!=o>0)return l;const u=Math.abs(s+o);return Math.abs(l)>=CF*u?l:-MF(t,e,r,n,i,a,u)}const Rv=Math.pow(2,-52),lh=new Uint32Array(512);class ch{static from(e,r=BF,n=DF){const i=e.length,a=new Float64Array(i*2);for(let s=0;s<i;s++){const o=e[s];a[2*s]=r(o),a[2*s+1]=n(o)}return new ch(a)}constructor(e){const r=e.length>>1;if(r>0&&typeof e[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=e;const n=Math.max(2*r-5,0);this._triangles=new Uint32Array(n*3),this._halfedges=new Int32Array(n*3),this._hashSize=Math.ceil(Math.sqrt(r)),this._hullPrev=new Uint32Array(r),this._hullNext=new Uint32Array(r),this._hullTri=new Uint32Array(r),this._hullHash=new Int32Array(this._hashSize).fill(-1),this._ids=new Uint32Array(r),this._dists=new Float64Array(r),this.update()}update(){const{coords:e,_hullPrev:r,_hullNext:n,_hullTri:i,_hullHash:a}=this,s=e.length>>1;let o=1/0,l=1/0,u=-1/0,h=-1/0;for(let L=0;L<s;L++){const v=e[2*L],B=e[2*L+1];v<o&&(o=v),B<l&&(l=B),v>u&&(u=v),B>h&&(h=B),this._ids[L]=L}const d=(o+u)/2,f=(l+h)/2;let p=1/0,m,_,y;for(let L=0;L<s;L++){const v=Hd(d,f,e[2*L],e[2*L+1]);v<p&&(m=L,p=v)}const b=e[2*m],x=e[2*m+1];p=1/0;for(let L=0;L<s;L++){if(L===m)continue;const v=Hd(b,x,e[2*L],e[2*L+1]);v<p&&v>0&&(_=L,p=v)}let k=e[2*_],T=e[2*_+1],C=1/0;for(let L=0;L<s;L++){if(L===m||L===_)continue;const v=IF(b,x,k,T,e[2*L],e[2*L+1]);v<C&&(y=L,C=v)}let M=e[2*y],S=e[2*y+1];if(C===1/0){for(let B=0;B<s;B++)this._dists[B]=e[2*B]-e[0]||e[2*B+1]-e[1];wo(this._ids,this._dists,0,s-1);const L=new Uint32Array(s);let v=0;for(let B=0,w=-1/0;B<s;B++){const D=this._ids[B];this._dists[D]>w&&(L[v++]=D,w=this._dists[D])}this.hull=L.subarray(0,v),this.triangles=new Uint32Array(0),this.halfedges=new Uint32Array(0);return}if(oh(b,x,k,T,M,S)<0){const L=_,v=k,B=T;_=y,k=M,T=S,y=L,M=v,S=B}const R=NF(b,x,k,T,M,S);this._cx=R.x,this._cy=R.y;for(let L=0;L<s;L++)this._dists[L]=Hd(e[2*L],e[2*L+1],R.x,R.y);wo(this._ids,this._dists,0,s-1),this._hullStart=m;let A=3;n[m]=r[y]=_,n[_]=r[m]=y,n[y]=r[_]=m,i[m]=0,i[_]=1,i[y]=2,a.fill(-1),a[this._hashKey(b,x)]=m,a[this._hashKey(k,T)]=_,a[this._hashKey(M,S)]=y,this.trianglesLen=0,this._addTriangle(m,_,y,-1,-1,-1);for(let L=0,v,B;L<this._ids.length;L++){const w=this._ids[L],D=e[2*w],N=e[2*w+1];if(L>0&&Math.abs(D-v)<=Rv&&Math.abs(N-B)<=Rv||(v=D,B=N,w===m||w===_||w===y))continue;let z=0;for(let $=0,lt=this._hashKey(D,N);$<this._hashSize&&(z=a[(lt+$)%this._hashSize],!(z!==-1&&z!==n[z]));$++);z=r[z];let X=z,ct;for(;ct=n[X],oh(D,N,e[2*X],e[2*X+1],e[2*ct],e[2*ct+1])>=0;)if(X=ct,X===z){X=-1;break}if(X===-1)continue;let J=this._addTriangle(X,w,n[X],-1,-1,i[X]);i[w]=this._legalize(J+2),i[X]=J,A++;let Y=n[X];for(;ct=n[Y],oh(D,N,e[2*Y],e[2*Y+1],e[2*ct],e[2*ct+1])<0;)J=this._addTriangle(Y,w,ct,i[w],-1,i[Y]),i[w]=this._legalize(J+2),n[Y]=Y,A--,Y=ct;if(X===z)for(;ct=r[X],oh(D,N,e[2*ct],e[2*ct+1],e[2*X],e[2*X+1])<0;)J=this._addTriangle(ct,w,X,-1,i[X],i[ct]),this._legalize(J+2),i[ct]=J,n[X]=X,A--,X=ct;this._hullStart=r[w]=X,n[X]=r[Y]=w,n[w]=Y,a[this._hashKey(D,N)]=w,a[this._hashKey(e[2*X],e[2*X+1])]=X}this.hull=new Uint32Array(A);for(let L=0,v=this._hullStart;L<A;L++)this.hull[L]=v,v=n[v];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,r){return Math.floor(LF(e-this._cx,r-this._cy)*this._hashSize)%this._hashSize}_legalize(e){const{_triangles:r,_halfedges:n,coords:i}=this;let a=0,s=0;for(;;){const o=n[e],l=e-e%3;if(s=l+(e+2)%3,o===-1){if(a===0)break;e=lh[--a];continue}const u=o-o%3,h=l+(e+1)%3,d=u+(o+2)%3,f=r[s],p=r[e],m=r[h],_=r[d];if(RF(i[2*f],i[2*f+1],i[2*p],i[2*p+1],i[2*m],i[2*m+1],i[2*_],i[2*_+1])){r[e]=_,r[o]=f;const b=n[d];if(b===-1){let k=this._hullStart;do{if(this._hullTri[k]===d){this._hullTri[k]=e;break}k=this._hullPrev[k]}while(k!==this._hullStart)}this._link(e,b),this._link(o,n[s]),this._link(s,d);const x=u+(o+1)%3;a<lh.length&&(lh[a++]=x)}else{if(a===0)break;e=lh[--a]}}return s}_link(e,r){this._halfedges[e]=r,r!==-1&&(this._halfedges[r]=e)}_addTriangle(e,r,n,i,a,s){const o=this.trianglesLen;return this._triangles[o]=e,this._triangles[o+1]=r,this._triangles[o+2]=n,this._link(o,i),this._link(o+1,a),this._link(o+2,s),this.trianglesLen+=3,o}}function LF(t,e){const r=t/(Math.abs(t)+Math.abs(e));return(e>0?3-r:1+r)/4}function Hd(t,e,r,n){const i=t-r,a=e-n;return i*i+a*a}function RF(t,e,r,n,i,a,s,o){const l=t-s,u=e-o,h=r-s,d=n-o,f=i-s,p=a-o,m=l*l+u*u,_=h*h+d*d,y=f*f+p*p;return l*(d*y-_*p)-u*(h*y-_*f)+m*(h*p-d*f)<0}function IF(t,e,r,n,i,a){const s=r-t,o=n-e,l=i-t,u=a-e,h=s*s+o*o,d=l*l+u*u,f=.5/(s*u-o*l),p=(u*h-o*d)*f,m=(s*d-l*h)*f;return p*p+m*m}function NF(t,e,r,n,i,a){const s=r-t,o=n-e,l=i-t,u=a-e,h=s*s+o*o,d=l*l+u*u,f=.5/(s*u-o*l),p=t+(u*h-o*d)*f,m=e+(s*d-l*h)*f;return{x:p,y:m}}function wo(t,e,r,n){if(n-r<=20)for(let i=r+1;i<=n;i++){const a=t[i],s=e[a];let o=i-1;for(;o>=r&&e[t[o]]>s;)t[o+1]=t[o--];t[o+1]=a}else{const i=r+n>>1;let a=r+1,s=n;Ul(t,i,a),e[t[r]]>e[t[n]]&&Ul(t,r,n),e[t[a]]>e[t[n]]&&Ul(t,a,n),e[t[r]]>e[t[a]]&&Ul(t,r,a);const o=t[a],l=e[o];for(;;){do a++;while(e[t[a]]<l);do s--;while(e[t[s]]>l);if(s<a)break;Ul(t,a,s)}t[r+1]=t[s],t[s]=o,n-a+1>=s-r?(wo(t,e,a,n),wo(t,e,r,s-1)):(wo(t,e,r,s-1),wo(t,e,a,n))}}function Ul(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function BF(t){return t[0]}function DF(t){return t[1]}const Iv=1e-6;class ws{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(e,r){this._+=`M${this._x0=this._x1=+e},${this._y0=this._y1=+r}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(e,r){this._+=`L${this._x1=+e},${this._y1=+r}`}arc(e,r,n){e=+e,r=+r,n=+n;const i=e+n,a=r;if(n<0)throw new Error("negative radius");this._x1===null?this._+=`M${i},${a}`:(Math.abs(this._x1-i)>Iv||Math.abs(this._y1-a)>Iv)&&(this._+="L"+i+","+a),n&&(this._+=`A${n},${n},0,1,1,${e-n},${r}A${n},${n},0,1,1,${this._x1=i},${this._y1=a}`)}rect(e,r,n,i){this._+=`M${this._x0=this._x1=+e},${this._y0=this._y1=+r}h${+n}v${+i}h${-n}Z`}value(){return this._||null}}class Gd{constructor(){this._=[]}moveTo(e,r){this._.push([e,r])}closePath(){this._.push(this._[0].slice())}lineTo(e,r){this._.push([e,r])}value(){return this._.length?this._:null}}class Nv{constructor(e,[r,n,i,a]=[0,0,960,500]){if(!((i=+i)>=(r=+r))||!((a=+a)>=(n=+n)))throw new Error("invalid bounds");this.delaunay=e,this._circumcenters=new Float64Array(e.points.length*2),this.vectors=new Float64Array(e.points.length*2),this.xmax=i,this.xmin=r,this.ymax=a,this.ymin=n,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:e,hull:r,triangles:n},vectors:i}=this,a=this.circumcenters=this._circumcenters.subarray(0,n.length/3*2);for(let p=0,m=0,_=n.length,y,b;p<_;p+=3,m+=2){const x=n[p]*2,k=n[p+1]*2,T=n[p+2]*2,C=e[x],M=e[x+1],S=e[k],R=e[k+1],A=e[T],L=e[T+1],v=S-C,B=R-M,w=A-C,D=L-M,N=(v*D-B*w)*2;if(Math.abs(N)<1e-9){let z=1e9;const X=n[0]*2;z*=Math.sign((e[X]-C)*D-(e[X+1]-M)*w),y=(C+A)/2-z*D,b=(M+L)/2+z*w}else{const z=1/N,X=v*v+B*B,ct=w*w+D*D;y=C+(D*X-B*ct)*z,b=M+(v*ct-w*X)*z}a[m]=y,a[m+1]=b}let s=r[r.length-1],o,l=s*4,u,h=e[2*s],d,f=e[2*s+1];i.fill(0);for(let p=0;p<r.length;++p)s=r[p],o=l,u=h,d=f,l=s*4,h=e[2*s],f=e[2*s+1],i[o+2]=i[l]=d-f,i[o+3]=i[l+1]=h-u}render(e){const r=e==null?e=new ws:void 0,{delaunay:{halfedges:n,inedges:i,hull:a},circumcenters:s,vectors:o}=this;if(a.length<=1)return null;for(let h=0,d=n.length;h<d;++h){const f=n[h];if(f<h)continue;const p=Math.floor(h/3)*2,m=Math.floor(f/3)*2,_=s[p],y=s[p+1],b=s[m],x=s[m+1];this._renderSegment(_,y,b,x,e)}let l,u=a[a.length-1];for(let h=0;h<a.length;++h){l=u,u=a[h];const d=Math.floor(i[u]/3)*2,f=s[d],p=s[d+1],m=l*4,_=this._project(f,p,o[m+2],o[m+3]);_&&this._renderSegment(f,p,_[0],_[1],e)}return r&&r.value()}renderBounds(e){const r=e==null?e=new ws:void 0;return e.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),r&&r.value()}renderCell(e,r){const n=r==null?r=new ws:void 0,i=this._clip(e);if(i===null||!i.length)return;r.moveTo(i[0],i[1]);let a=i.length;for(;i[0]===i[a-2]&&i[1]===i[a-1]&&a>1;)a-=2;for(let s=2;s<a;s+=2)(i[s]!==i[s-2]||i[s+1]!==i[s-1])&&r.lineTo(i[s],i[s+1]);return r.closePath(),n&&n.value()}*cellPolygons(){const{delaunay:{points:e}}=this;for(let r=0,n=e.length/2;r<n;++r){const i=this.cellPolygon(r);i&&(i.index=r,yield i)}}cellPolygon(e){const r=new Gd;return this.renderCell(e,r),r.value()}_renderSegment(e,r,n,i,a){let s;const o=this._regioncode(e,r),l=this._regioncode(n,i);o===0&&l===0?(a.moveTo(e,r),a.lineTo(n,i)):(s=this._clipSegment(e,r,n,i,o,l))&&(a.moveTo(s[0],s[1]),a.lineTo(s[2],s[3]))}contains(e,r,n){return r=+r,r!==r||(n=+n,n!==n)?!1:this.delaunay._step(e,r,n)===e}*neighbors(e){const r=this._clip(e);if(r)for(const n of this.delaunay.neighbors(e)){const i=this._clip(n);if(i){t:for(let a=0,s=r.length;a<s;a+=2)for(let o=0,l=i.length;o<l;o+=2)if(r[a]==i[o]&&r[a+1]==i[o+1]&&r[(a+2)%s]==i[(o+l-2)%l]&&r[(a+3)%s]==i[(o+l-1)%l]){yield n;break t}}}}_cell(e){const{circumcenters:r,delaunay:{inedges:n,halfedges:i,triangles:a}}=this,s=n[e];if(s===-1)return null;const o=[];let l=s;do{const u=Math.floor(l/3);if(o.push(r[u*2],r[u*2+1]),l=l%3===2?l-2:l+1,a[l]!==e)break;l=i[l]}while(l!==s&&l!==-1);return o}_clip(e){if(e===0&&this.delaunay.hull.length===1)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const r=this._cell(e);if(r===null)return null;const{vectors:n}=this,i=e*4;return n[i]||n[i+1]?this._clipInfinite(e,r,n[i],n[i+1],n[i+2],n[i+3]):this._clipFinite(e,r)}_clipFinite(e,r){const n=r.length;let i=null,a,s,o=r[n-2],l=r[n-1],u,h=this._regioncode(o,l),d,f=0;for(let p=0;p<n;p+=2)if(a=o,s=l,o=r[p],l=r[p+1],u=h,h=this._regioncode(o,l),u===0&&h===0)d=f,f=0,i?i.push(o,l):i=[o,l];else{let m,_,y,b,x;if(u===0){if((m=this._clipSegment(a,s,o,l,u,h))===null)continue;[_,y,b,x]=m}else{if((m=this._clipSegment(o,l,a,s,h,u))===null)continue;[b,x,_,y]=m,d=f,f=this._edgecode(_,y),d&&f&&this._edge(e,d,f,i,i.length),i?i.push(_,y):i=[_,y]}d=f,f=this._edgecode(b,x),d&&f&&this._edge(e,d,f,i,i.length),i?i.push(b,x):i=[b,x]}if(i)d=f,f=this._edgecode(i[0],i[1]),d&&f&&this._edge(e,d,f,i,i.length);else if(this.contains(e,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return i}_clipSegment(e,r,n,i,a,s){for(;;){if(a===0&&s===0)return[e,r,n,i];if(a&s)return null;let o,l,u=a||s;u&8?(o=e+(n-e)*(this.ymax-r)/(i-r),l=this.ymax):u&4?(o=e+(n-e)*(this.ymin-r)/(i-r),l=this.ymin):u&2?(l=r+(i-r)*(this.xmax-e)/(n-e),o=this.xmax):(l=r+(i-r)*(this.xmin-e)/(n-e),o=this.xmin),a?(e=o,r=l,a=this._regioncode(e,r)):(n=o,i=l,s=this._regioncode(n,i))}}_clipInfinite(e,r,n,i,a,s){let o=Array.from(r),l;if((l=this._project(o[0],o[1],n,i))&&o.unshift(l[0],l[1]),(l=this._project(o[o.length-2],o[o.length-1],a,s))&&o.push(l[0],l[1]),o=this._clipFinite(e,o))for(let u=0,h=o.length,d,f=this._edgecode(o[h-2],o[h-1]);u<h;u+=2)d=f,f=this._edgecode(o[u],o[u+1]),d&&f&&(u=this._edge(e,d,f,o,u),h=o.length);else this.contains(e,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(o=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return o}_edge(e,r,n,i,a){for(;r!==n;){let s,o;switch(r){case 5:r=4;continue;case 4:r=6,s=this.xmax,o=this.ymin;break;case 6:r=2;continue;case 2:r=10,s=this.xmax,o=this.ymax;break;case 10:r=8;continue;case 8:r=9,s=this.xmin,o=this.ymax;break;case 9:r=1;continue;case 1:r=5,s=this.xmin,o=this.ymin;break}(i[a]!==s||i[a+1]!==o)&&this.contains(e,s,o)&&(i.splice(a,0,s,o),a+=2)}if(i.length>4)for(let s=0;s<i.length;s+=2){const o=(s+2)%i.length,l=(s+4)%i.length;(i[s]===i[o]&&i[o]===i[l]||i[s+1]===i[o+1]&&i[o+1]===i[l+1])&&(i.splice(o,2),s-=2)}return a}_project(e,r,n,i){let a=1/0,s,o,l;if(i<0){if(r<=this.ymin)return null;(s=(this.ymin-r)/i)<a&&(l=this.ymin,o=e+(a=s)*n)}else if(i>0){if(r>=this.ymax)return null;(s=(this.ymax-r)/i)<a&&(l=this.ymax,o=e+(a=s)*n)}if(n>0){if(e>=this.xmax)return null;(s=(this.xmax-e)/n)<a&&(o=this.xmax,l=r+(a=s)*i)}else if(n<0){if(e<=this.xmin)return null;(s=(this.xmin-e)/n)<a&&(o=this.xmin,l=r+(a=s)*i)}return[o,l]}_edgecode(e,r){return(e===this.xmin?1:e===this.xmax?2:0)|(r===this.ymin?4:r===this.ymax?8:0)}_regioncode(e,r){return(e<this.xmin?1:e>this.xmax?2:0)|(r<this.ymin?4:r>this.ymax?8:0)}}const OF=2*Math.PI,To=Math.pow;function FF(t){return t[0]}function PF(t){return t[1]}function qF(t){const{triangles:e,coords:r}=t;for(let n=0;n<e.length;n+=3){const i=2*e[n],a=2*e[n+1],s=2*e[n+2];if((r[s]-r[i])*(r[a+1]-r[i+1])-(r[a]-r[i])*(r[s+1]-r[i+1])>1e-10)return!1}return!0}function VF(t,e,r){return[t+Math.sin(t+e)*r,e+Math.cos(t-e)*r]}class jd{static from(e,r=FF,n=PF,i){return new jd("length"in e?zF(e,r,n,i):Float64Array.from(YF(e,r,n,i)))}constructor(e){this._delaunator=new ch(e),this.inedges=new Int32Array(e.length/2),this._hullIndex=new Int32Array(e.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const e=this._delaunator,r=this.points;if(e.hull&&e.hull.length>2&&qF(e)){this.collinear=Int32Array.from({length:r.length/2},(f,p)=>p).sort((f,p)=>r[2*f]-r[2*p]||r[2*f+1]-r[2*p+1]);const l=this.collinear[0],u=this.collinear[this.collinear.length-1],h=[r[2*l],r[2*l+1],r[2*u],r[2*u+1]],d=1e-8*Math.hypot(h[3]-h[1],h[2]-h[0]);for(let f=0,p=r.length/2;f<p;++f){const m=VF(r[2*f],r[2*f+1],d);r[2*f]=m[0],r[2*f+1]=m[1]}this._delaunator=new ch(r)}else delete this.collinear;const n=this.halfedges=this._delaunator.halfedges,i=this.hull=this._delaunator.hull,a=this.triangles=this._delaunator.triangles,s=this.inedges.fill(-1),o=this._hullIndex.fill(-1);for(let l=0,u=n.length;l<u;++l){const h=a[l%3===2?l-2:l+1];(n[l]===-1||s[h]===-1)&&(s[h]=l)}for(let l=0,u=i.length;l<u;++l)o[i[l]]=l;i.length<=2&&i.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=i[0],s[i[0]]=1,i.length===2&&(s[i[1]]=0,this.triangles[1]=i[1],this.triangles[2]=i[1]))}voronoi(e){return new Nv(this,e)}*neighbors(e){const{inedges:r,hull:n,_hullIndex:i,halfedges:a,triangles:s,collinear:o}=this;if(o){const d=o.indexOf(e);d>0&&(yield o[d-1]),d<o.length-1&&(yield o[d+1]);return}const l=r[e];if(l===-1)return;let u=l,h=-1;do{if(yield h=s[u],u=u%3===2?u-2:u+1,s[u]!==e)return;if(u=a[u],u===-1){const d=n[(i[e]+1)%n.length];d!==h&&(yield d);return}}while(u!==l)}find(e,r,n=0){if(e=+e,e!==e||(r=+r,r!==r))return-1;const i=n;let a;for(;(a=this._step(n,e,r))>=0&&a!==n&&a!==i;)n=a;return a}_step(e,r,n){const{inedges:i,hull:a,_hullIndex:s,halfedges:o,triangles:l,points:u}=this;if(i[e]===-1||!u.length)return(e+1)%(u.length>>1);let h=e,d=To(r-u[e*2],2)+To(n-u[e*2+1],2);const f=i[e];let p=f;do{let m=l[p];const _=To(r-u[m*2],2)+To(n-u[m*2+1],2);if(_<d&&(d=_,h=m),p=p%3===2?p-2:p+1,l[p]!==e)break;if(p=o[p],p===-1){if(p=a[(s[e]+1)%a.length],p!==m&&To(r-u[p*2],2)+To(n-u[p*2+1],2)<d)return p;break}}while(p!==f);return h}render(e){const r=e==null?e=new ws:void 0,{points:n,halfedges:i,triangles:a}=this;for(let s=0,o=i.length;s<o;++s){const l=i[s];if(l<s)continue;const u=a[s]*2,h=a[l]*2;e.moveTo(n[u],n[u+1]),e.lineTo(n[h],n[h+1])}return this.renderHull(e),r&&r.value()}renderPoints(e,r){r===void 0&&(!e||typeof e.moveTo!="function")&&(r=e,e=null),r=r==null?2:+r;const n=e==null?e=new ws:void 0,{points:i}=this;for(let a=0,s=i.length;a<s;a+=2){const o=i[a],l=i[a+1];e.moveTo(o+r,l),e.arc(o,l,r,0,OF)}return n&&n.value()}renderHull(e){const r=e==null?e=new ws:void 0,{hull:n,points:i}=this,a=n[0]*2,s=n.length;e.moveTo(i[a],i[a+1]);for(let o=1;o<s;++o){const l=2*n[o];e.lineTo(i[l],i[l+1])}return e.closePath(),r&&r.value()}hullPolygon(){const e=new Gd;return this.renderHull(e),e.value()}renderTriangle(e,r){const n=r==null?r=new ws:void 0,{points:i,triangles:a}=this,s=a[e*=3]*2,o=a[e+1]*2,l=a[e+2]*2;return r.moveTo(i[s],i[s+1]),r.lineTo(i[o],i[o+1]),r.lineTo(i[l],i[l+1]),r.closePath(),n&&n.value()}*trianglePolygons(){const{triangles:e}=this;for(let r=0,n=e.length/3;r<n;++r)yield this.trianglePolygon(r)}trianglePolygon(e){const r=new Gd;return this.renderTriangle(e,r),r.value()}}function zF(t,e,r,n){const i=t.length,a=new Float64Array(i*2);for(let s=0;s<i;++s){const o=t[s];a[s*2]=e.call(n,o,s,t),a[s*2+1]=r.call(n,o,s,t)}return a}function*YF(t,e,r,n){let i=0;for(const a of t)yield e.call(n,a,i,t),yield r.call(n,a,i,t),++i}var Bv={},$d={},Xd=34,Wl=10,Kd=13;function Dv(t){return new Function("d","return {"+t.map(function(e,r){return JSON.stringify(e)+": d["+r+'] || ""'}).join(",")+"}")}function UF(t,e){var r=Dv(t);return function(n,i){return e(r(n),i,t)}}function Ov(t){var e=Object.create(null),r=[];return t.forEach(function(n){for(var i in n)i in e||r.push(e[i]=i)}),r}function dn(t,e){var r=t+"",n=r.length;return n<e?new Array(e-n+1).join(0)+r:r}function WF(t){return t<0?"-"+dn(-t,6):t>9999?"+"+dn(t,6):dn(t,4)}function HF(t){var e=t.getUTCHours(),r=t.getUTCMinutes(),n=t.getUTCSeconds(),i=t.getUTCMilliseconds();return isNaN(t)?"Invalid Date":WF(t.getUTCFullYear())+"-"+dn(t.getUTCMonth()+1,2)+"-"+dn(t.getUTCDate(),2)+(i?"T"+dn(e,2)+":"+dn(r,2)+":"+dn(n,2)+"."+dn(i,3)+"Z":n?"T"+dn(e,2)+":"+dn(r,2)+":"+dn(n,2)+"Z":r||e?"T"+dn(e,2)+":"+dn(r,2)+"Z":"")}function uh(t){var e=new RegExp('["'+t+` +\r]`),r=t.charCodeAt(0);function n(d,f){var p,m,_=i(d,function(y,b){if(p)return p(y,b-1);m=y,p=f?UF(y,f):Dv(y)});return _.columns=m||[],_}function i(d,f){var p=[],m=d.length,_=0,y=0,b,x=m<=0,k=!1;d.charCodeAt(m-1)===Wl&&--m,d.charCodeAt(m-1)===Kd&&--m;function T(){if(x)return $d;if(k)return k=!1,Bv;var M,S=_,R;if(d.charCodeAt(S)===Xd){for(;_++<m&&d.charCodeAt(_)!==Xd||d.charCodeAt(++_)===Xd;);return(M=_)>=m?x=!0:(R=d.charCodeAt(_++))===Wl?k=!0:R===Kd&&(k=!0,d.charCodeAt(_)===Wl&&++_),d.slice(S+1,M-1).replace(/""/g,'"')}for(;_<m;){if((R=d.charCodeAt(M=_++))===Wl)k=!0;else if(R===Kd)k=!0,d.charCodeAt(_)===Wl&&++_;else if(R!==r)continue;return d.slice(S,M)}return x=!0,d.slice(S,m)}for(;(b=T())!==$d;){for(var C=[];b!==Bv&&b!==$d;)C.push(b),b=T();f&&(C=f(C,y++))==null||p.push(C)}return p}function a(d,f){return d.map(function(p){return f.map(function(m){return h(p[m])}).join(t)})}function s(d,f){return f==null&&(f=Ov(d)),[f.map(h).join(t)].concat(a(d,f)).join(` +`)}function o(d,f){return f==null&&(f=Ov(d)),a(d,f).join(` +`)}function l(d){return d.map(u).join(` +`)}function u(d){return d.map(h).join(t)}function h(d){return d==null?"":d instanceof Date?HF(d):e.test(d+="")?'"'+d.replace(/"/g,'""')+'"':d}return{parse:n,parseRows:i,format:s,formatBody:o,formatRows:l,formatRow:u,formatValue:h}}var Ts=uh(","),Fv=Ts.parse,GF=Ts.parseRows,jF=Ts.format,$F=Ts.formatBody,XF=Ts.formatRows,KF=Ts.formatRow,ZF=Ts.formatValue,Es=uh(" "),Pv=Es.parse,QF=Es.parseRows,JF=Es.format,tP=Es.formatBody,eP=Es.formatRows,rP=Es.formatRow,nP=Es.formatValue;function iP(t){for(var e in t){var r=t[e].trim(),n,i;if(!r)r=null;else if(r==="true")r=!0;else if(r==="false")r=!1;else if(r==="NaN")r=NaN;else if(!isNaN(n=+r))r=n;else if(i=r.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/))aP&&!!i[4]&&!i[7]&&(r=r.replace(/-/g,"/").replace(/T/," ")),r=new Date(r);else continue;t[e]=r}return t}const aP=new Date("2019-01-01T00:00").getHours()||new Date("2019-07-01T00:00").getHours();function sP(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.blob()}function oP(t,e){return fetch(t,e).then(sP)}function lP(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.arrayBuffer()}function cP(t,e){return fetch(t,e).then(lP)}function uP(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.text()}function hh(t,e){return fetch(t,e).then(uP)}function qv(t){return function(e,r,n){return arguments.length===2&&typeof r=="function"&&(n=r,r=void 0),hh(e,r).then(function(i){return t(i,n)})}}function hP(t,e,r,n){arguments.length===3&&typeof r=="function"&&(n=r,r=void 0);var i=uh(t);return hh(e,r).then(function(a){return i.parse(a,n)})}var fP=qv(Fv),dP=qv(Pv);function pP(t,e){return new Promise(function(r,n){var i=new Image;for(var a in e)i[a]=e[a];i.onerror=n,i.onload=function(){r(i)},i.src=t})}function gP(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);if(!(t.status===204||t.status===205))return t.json()}function yP(t,e){return fetch(t,e).then(gP)}function Zd(t){return(e,r)=>hh(e,r).then(n=>new DOMParser().parseFromString(n,t))}const mP=Zd("application/xml");var bP=Zd("text/html"),_P=Zd("image/svg+xml");function vP(t,e){var r,n=1;t==null&&(t=0),e==null&&(e=0);function i(){var a,s=r.length,o,l=0,u=0;for(a=0;a<s;++a)o=r[a],l+=o.x,u+=o.y;for(l=(l/s-t)*n,u=(u/s-e)*n,a=0;a<s;++a)o=r[a],o.x-=l,o.y-=u}return i.initialize=function(a){r=a},i.x=function(a){return arguments.length?(t=+a,i):t},i.y=function(a){return arguments.length?(e=+a,i):e},i.strength=function(a){return arguments.length?(n=+a,i):n},i}function xP(t){const e=+this._x.call(null,t),r=+this._y.call(null,t);return Vv(this.cover(e,r),e,r,t)}function Vv(t,e,r,n){if(isNaN(e)||isNaN(r))return t;var i,a=t._root,s={data:n},o=t._x0,l=t._y0,u=t._x1,h=t._y1,d,f,p,m,_,y,b,x;if(!a)return t._root=s,t;for(;a.length;)if((_=e>=(d=(o+u)/2))?o=d:u=d,(y=r>=(f=(l+h)/2))?l=f:h=f,i=a,!(a=a[b=y<<1|_]))return i[b]=s,t;if(p=+t._x.call(null,a.data),m=+t._y.call(null,a.data),e===p&&r===m)return s.next=a,i?i[b]=s:t._root=s,t;do i=i?i[b]=new Array(4):t._root=new Array(4),(_=e>=(d=(o+u)/2))?o=d:u=d,(y=r>=(f=(l+h)/2))?l=f:h=f;while((b=y<<1|_)===(x=(m>=f)<<1|p>=d));return i[x]=a,i[b]=s,t}function kP(t){var e,r,n=t.length,i,a,s=new Array(n),o=new Array(n),l=1/0,u=1/0,h=-1/0,d=-1/0;for(r=0;r<n;++r)isNaN(i=+this._x.call(null,e=t[r]))||isNaN(a=+this._y.call(null,e))||(s[r]=i,o[r]=a,i<l&&(l=i),i>h&&(h=i),a<u&&(u=a),a>d&&(d=a));if(l>h||u>d)return this;for(this.cover(l,u).cover(h,d),r=0;r<n;++r)Vv(this,s[r],o[r],t[r]);return this}function wP(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var r=this._x0,n=this._y0,i=this._x1,a=this._y1;if(isNaN(r))i=(r=Math.floor(t))+1,a=(n=Math.floor(e))+1;else{for(var s=i-r||1,o=this._root,l,u;r>t||t>=i||n>e||e>=a;)switch(u=(e<n)<<1|t<r,l=new Array(4),l[u]=o,o=l,s*=2,u){case 0:i=r+s,a=n+s;break;case 1:r=i-s,a=n+s;break;case 2:i=r+s,n=a-s;break;case 3:r=i-s,n=a-s;break}this._root&&this._root.length&&(this._root=o)}return this._x0=r,this._y0=n,this._x1=i,this._y1=a,this}function TP(){var t=[];return this.visit(function(e){if(!e.length)do t.push(e.data);while(e=e.next)}),t}function EP(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function Kr(t,e,r,n,i){this.node=t,this.x0=e,this.y0=r,this.x1=n,this.y1=i}function CP(t,e,r){var n,i=this._x0,a=this._y0,s,o,l,u,h=this._x1,d=this._y1,f=[],p=this._root,m,_;for(p&&f.push(new Kr(p,i,a,h,d)),r==null?r=1/0:(i=t-r,a=e-r,h=t+r,d=e+r,r*=r);m=f.pop();)if(!(!(p=m.node)||(s=m.x0)>h||(o=m.y0)>d||(l=m.x1)<i||(u=m.y1)<a))if(p.length){var y=(s+l)/2,b=(o+u)/2;f.push(new Kr(p[3],y,b,l,u),new Kr(p[2],s,b,y,u),new Kr(p[1],y,o,l,b),new Kr(p[0],s,o,y,b)),(_=(e>=b)<<1|t>=y)&&(m=f[f.length-1],f[f.length-1]=f[f.length-1-_],f[f.length-1-_]=m)}else{var x=t-+this._x.call(null,p.data),k=e-+this._y.call(null,p.data),T=x*x+k*k;if(T<r){var C=Math.sqrt(r=T);i=t-C,a=e-C,h=t+C,d=e+C,n=p.data}}return n}function SP(t){if(isNaN(h=+this._x.call(null,t))||isNaN(d=+this._y.call(null,t)))return this;var e,r=this._root,n,i,a,s=this._x0,o=this._y0,l=this._x1,u=this._y1,h,d,f,p,m,_,y,b;if(!r)return this;if(r.length)for(;;){if((m=h>=(f=(s+l)/2))?s=f:l=f,(_=d>=(p=(o+u)/2))?o=p:u=p,e=r,!(r=r[y=_<<1|m]))return this;if(!r.length)break;(e[y+1&3]||e[y+2&3]||e[y+3&3])&&(n=e,b=y)}for(;r.data!==t;)if(i=r,!(r=r.next))return this;return(a=r.next)&&delete r.next,i?(a?i.next=a:delete i.next,this):e?(a?e[y]=a:delete e[y],(r=e[0]||e[1]||e[2]||e[3])&&r===(e[3]||e[2]||e[1]||e[0])&&!r.length&&(n?n[b]=r:this._root=r),this):(this._root=a,this)}function AP(t){for(var e=0,r=t.length;e<r;++e)this.remove(t[e]);return this}function MP(){return this._root}function LP(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function RP(t){var e=[],r,n=this._root,i,a,s,o,l;for(n&&e.push(new Kr(n,this._x0,this._y0,this._x1,this._y1));r=e.pop();)if(!t(n=r.node,a=r.x0,s=r.y0,o=r.x1,l=r.y1)&&n.length){var u=(a+o)/2,h=(s+l)/2;(i=n[3])&&e.push(new Kr(i,u,h,o,l)),(i=n[2])&&e.push(new Kr(i,a,h,u,l)),(i=n[1])&&e.push(new Kr(i,u,s,o,h)),(i=n[0])&&e.push(new Kr(i,a,s,u,h))}return this}function IP(t){var e=[],r=[],n;for(this._root&&e.push(new Kr(this._root,this._x0,this._y0,this._x1,this._y1));n=e.pop();){var i=n.node;if(i.length){var a,s=n.x0,o=n.y0,l=n.x1,u=n.y1,h=(s+l)/2,d=(o+u)/2;(a=i[0])&&e.push(new Kr(a,s,o,h,d)),(a=i[1])&&e.push(new Kr(a,h,o,l,d)),(a=i[2])&&e.push(new Kr(a,s,d,h,u)),(a=i[3])&&e.push(new Kr(a,h,d,l,u))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.y0,n.x1,n.y1);return this}function NP(t){return t[0]}function BP(t){return arguments.length?(this._x=t,this):this._x}function DP(t){return t[1]}function OP(t){return arguments.length?(this._y=t,this):this._y}function fh(t,e,r){var n=new Qd(e==null?NP:e,r==null?DP:r,NaN,NaN,NaN,NaN);return t==null?n:n.addAll(t)}function Qd(t,e,r,n,i,a){this._x=t,this._y=e,this._x0=r,this._y0=n,this._x1=i,this._y1=a,this._root=void 0}function zv(t){for(var e={data:t.data},r=e;t=t.next;)r=r.next={data:t.data};return e}var Zr=fh.prototype=Qd.prototype;Zr.copy=function(){var t=new Qd(this._x,this._y,this._x0,this._y0,this._x1,this._y1),e=this._root,r,n;if(!e)return t;if(!e.length)return t._root=zv(e),t;for(r=[{source:e,target:t._root=new Array(4)}];e=r.pop();)for(var i=0;i<4;++i)(n=e.source[i])&&(n.length?r.push({source:n,target:e.target[i]=new Array(4)}):e.target[i]=zv(n));return t},Zr.add=xP,Zr.addAll=kP,Zr.cover=wP,Zr.data=TP,Zr.extent=EP,Zr.find=CP,Zr.remove=SP,Zr.removeAll=AP,Zr.root=MP,Zr.size=LP,Zr.visit=RP,Zr.visitAfter=IP,Zr.x=BP,Zr.y=OP;function vr(t){return function(){return t}}function Na(t){return(t()-.5)*1e-6}function FP(t){return t.x+t.vx}function PP(t){return t.y+t.vy}function qP(t){var e,r,n,i=1,a=1;typeof t!="function"&&(t=vr(t==null?1:+t));function s(){for(var u,h=e.length,d,f,p,m,_,y,b=0;b<a;++b)for(d=fh(e,FP,PP).visitAfter(o),u=0;u<h;++u)f=e[u],_=r[f.index],y=_*_,p=f.x+f.vx,m=f.y+f.vy,d.visit(x);function x(k,T,C,M,S){var R=k.data,A=k.r,L=_+A;if(R){if(R.index>f.index){var v=p-R.x-R.vx,B=m-R.y-R.vy,w=v*v+B*B;w<L*L&&(v===0&&(v=Na(n),w+=v*v),B===0&&(B=Na(n),w+=B*B),w=(L-(w=Math.sqrt(w)))/w*i,f.vx+=(v*=w)*(L=(A*=A)/(y+A)),f.vy+=(B*=w)*L,R.vx-=v*(L=1-L),R.vy-=B*L)}return}return T>p+L||M<p-L||C>m+L||S<m-L}}function o(u){if(u.data)return u.r=r[u.data.index];for(var h=u.r=0;h<4;++h)u[h]&&u[h].r>u.r&&(u.r=u[h].r)}function l(){if(!!e){var u,h=e.length,d;for(r=new Array(h),u=0;u<h;++u)d=e[u],r[d.index]=+t(d,u,e)}}return s.initialize=function(u,h){e=u,n=h,l()},s.iterations=function(u){return arguments.length?(a=+u,s):a},s.strength=function(u){return arguments.length?(i=+u,s):i},s.radius=function(u){return arguments.length?(t=typeof u=="function"?u:vr(+u),l(),s):t},s}function VP(t){return t.index}function Yv(t,e){var r=t.get(e);if(!r)throw new Error("node not found: "+e);return r}function zP(t){var e=VP,r=d,n,i=vr(30),a,s,o,l,u,h=1;t==null&&(t=[]);function d(y){return 1/Math.min(o[y.source.index],o[y.target.index])}function f(y){for(var b=0,x=t.length;b<h;++b)for(var k=0,T,C,M,S,R,A,L;k<x;++k)T=t[k],C=T.source,M=T.target,S=M.x+M.vx-C.x-C.vx||Na(u),R=M.y+M.vy-C.y-C.vy||Na(u),A=Math.sqrt(S*S+R*R),A=(A-a[k])/A*y*n[k],S*=A,R*=A,M.vx-=S*(L=l[k]),M.vy-=R*L,C.vx+=S*(L=1-L),C.vy+=R*L}function p(){if(!!s){var y,b=s.length,x=t.length,k=new Map(s.map((C,M)=>[e(C,M,s),C])),T;for(y=0,o=new Array(b);y<x;++y)T=t[y],T.index=y,typeof T.source!="object"&&(T.source=Yv(k,T.source)),typeof T.target!="object"&&(T.target=Yv(k,T.target)),o[T.source.index]=(o[T.source.index]||0)+1,o[T.target.index]=(o[T.target.index]||0)+1;for(y=0,l=new Array(x);y<x;++y)T=t[y],l[y]=o[T.source.index]/(o[T.source.index]+o[T.target.index]);n=new Array(x),m(),a=new Array(x),_()}}function m(){if(!!s)for(var y=0,b=t.length;y<b;++y)n[y]=+r(t[y],y,t)}function _(){if(!!s)for(var y=0,b=t.length;y<b;++y)a[y]=+i(t[y],y,t)}return f.initialize=function(y,b){s=y,u=b,p()},f.links=function(y){return arguments.length?(t=y,p(),f):t},f.id=function(y){return arguments.length?(e=y,f):e},f.iterations=function(y){return arguments.length?(h=+y,f):h},f.strength=function(y){return arguments.length?(r=typeof y=="function"?y:vr(+y),m(),f):r},f.distance=function(y){return arguments.length?(i=typeof y=="function"?y:vr(+y),_(),f):i},f}const YP=1664525,UP=1013904223,Uv=4294967296;function WP(){let t=1;return()=>(t=(YP*t+UP)%Uv)/Uv}function HP(t){return t.x}function GP(t){return t.y}var jP=10,$P=Math.PI*(3-Math.sqrt(5));function XP(t){var e,r=1,n=.001,i=1-Math.pow(n,1/300),a=0,s=.6,o=new Map,l=Ju(d),u=fs("tick","end"),h=WP();t==null&&(t=[]);function d(){f(),u.call("tick",e),r<n&&(l.stop(),u.call("end",e))}function f(_){var y,b=t.length,x;_===void 0&&(_=1);for(var k=0;k<_;++k)for(r+=(a-r)*i,o.forEach(function(T){T(r)}),y=0;y<b;++y)x=t[y],x.fx==null?x.x+=x.vx*=s:(x.x=x.fx,x.vx=0),x.fy==null?x.y+=x.vy*=s:(x.y=x.fy,x.vy=0);return e}function p(){for(var _=0,y=t.length,b;_<y;++_){if(b=t[_],b.index=_,b.fx!=null&&(b.x=b.fx),b.fy!=null&&(b.y=b.fy),isNaN(b.x)||isNaN(b.y)){var x=jP*Math.sqrt(.5+_),k=_*$P;b.x=x*Math.cos(k),b.y=x*Math.sin(k)}(isNaN(b.vx)||isNaN(b.vy))&&(b.vx=b.vy=0)}}function m(_){return _.initialize&&_.initialize(t,h),_}return p(),e={tick:f,restart:function(){return l.restart(d),e},stop:function(){return l.stop(),e},nodes:function(_){return arguments.length?(t=_,p(),o.forEach(m),e):t},alpha:function(_){return arguments.length?(r=+_,e):r},alphaMin:function(_){return arguments.length?(n=+_,e):n},alphaDecay:function(_){return arguments.length?(i=+_,e):+i},alphaTarget:function(_){return arguments.length?(a=+_,e):a},velocityDecay:function(_){return arguments.length?(s=1-_,e):1-s},randomSource:function(_){return arguments.length?(h=_,o.forEach(m),e):h},force:function(_,y){return arguments.length>1?(y==null?o.delete(_):o.set(_,m(y)),e):o.get(_)},find:function(_,y,b){var x=0,k=t.length,T,C,M,S,R;for(b==null?b=1/0:b*=b,x=0;x<k;++x)S=t[x],T=_-S.x,C=y-S.y,M=T*T+C*C,M<b&&(R=S,b=M);return R},on:function(_,y){return arguments.length>1?(u.on(_,y),e):u.on(_)}}}function KP(){var t,e,r,n,i=vr(-30),a,s=1,o=1/0,l=.81;function u(p){var m,_=t.length,y=fh(t,HP,GP).visitAfter(d);for(n=p,m=0;m<_;++m)e=t[m],y.visit(f)}function h(){if(!!t){var p,m=t.length,_;for(a=new Array(m),p=0;p<m;++p)_=t[p],a[_.index]=+i(_,p,t)}}function d(p){var m=0,_,y,b=0,x,k,T;if(p.length){for(x=k=T=0;T<4;++T)(_=p[T])&&(y=Math.abs(_.value))&&(m+=_.value,b+=y,x+=y*_.x,k+=y*_.y);p.x=x/b,p.y=k/b}else{_=p,_.x=_.data.x,_.y=_.data.y;do m+=a[_.data.index];while(_=_.next)}p.value=m}function f(p,m,_,y){if(!p.value)return!0;var b=p.x-e.x,x=p.y-e.y,k=y-m,T=b*b+x*x;if(k*k/l<T)return T<o&&(b===0&&(b=Na(r),T+=b*b),x===0&&(x=Na(r),T+=x*x),T<s&&(T=Math.sqrt(s*T)),e.vx+=b*p.value*n/T,e.vy+=x*p.value*n/T),!0;if(p.length||T>=o)return;(p.data!==e||p.next)&&(b===0&&(b=Na(r),T+=b*b),x===0&&(x=Na(r),T+=x*x),T<s&&(T=Math.sqrt(s*T)));do p.data!==e&&(k=a[p.data.index]*n/T,e.vx+=b*k,e.vy+=x*k);while(p=p.next)}return u.initialize=function(p,m){t=p,r=m,h()},u.strength=function(p){return arguments.length?(i=typeof p=="function"?p:vr(+p),h(),u):i},u.distanceMin=function(p){return arguments.length?(s=p*p,u):Math.sqrt(s)},u.distanceMax=function(p){return arguments.length?(o=p*p,u):Math.sqrt(o)},u.theta=function(p){return arguments.length?(l=p*p,u):Math.sqrt(l)},u}function ZP(t,e,r){var n,i=vr(.1),a,s;typeof t!="function"&&(t=vr(+t)),e==null&&(e=0),r==null&&(r=0);function o(u){for(var h=0,d=n.length;h<d;++h){var f=n[h],p=f.x-e||1e-6,m=f.y-r||1e-6,_=Math.sqrt(p*p+m*m),y=(s[h]-_)*a[h]*u/_;f.vx+=p*y,f.vy+=m*y}}function l(){if(!!n){var u,h=n.length;for(a=new Array(h),s=new Array(h),u=0;u<h;++u)s[u]=+t(n[u],u,n),a[u]=isNaN(s[u])?0:+i(n[u],u,n)}}return o.initialize=function(u){n=u,l()},o.strength=function(u){return arguments.length?(i=typeof u=="function"?u:vr(+u),l(),o):i},o.radius=function(u){return arguments.length?(t=typeof u=="function"?u:vr(+u),l(),o):t},o.x=function(u){return arguments.length?(e=+u,o):e},o.y=function(u){return arguments.length?(r=+u,o):r},o}function QP(t){var e=vr(.1),r,n,i;typeof t!="function"&&(t=vr(t==null?0:+t));function a(o){for(var l=0,u=r.length,h;l<u;++l)h=r[l],h.vx+=(i[l]-h.x)*n[l]*o}function s(){if(!!r){var o,l=r.length;for(n=new Array(l),i=new Array(l),o=0;o<l;++o)n[o]=isNaN(i[o]=+t(r[o],o,r))?0:+e(r[o],o,r)}}return a.initialize=function(o){r=o,s()},a.strength=function(o){return arguments.length?(e=typeof o=="function"?o:vr(+o),s(),a):e},a.x=function(o){return arguments.length?(t=typeof o=="function"?o:vr(+o),s(),a):t},a}function JP(t){var e=vr(.1),r,n,i;typeof t!="function"&&(t=vr(t==null?0:+t));function a(o){for(var l=0,u=r.length,h;l<u;++l)h=r[l],h.vy+=(i[l]-h.y)*n[l]*o}function s(){if(!!r){var o,l=r.length;for(n=new Array(l),i=new Array(l),o=0;o<l;++o)n[o]=isNaN(i[o]=+t(r[o],o,r))?0:+e(r[o],o,r)}}return a.initialize=function(o){r=o,s()},a.strength=function(o){return arguments.length?(e=typeof o=="function"?o:vr(+o),s(),a):e},a.y=function(o){return arguments.length?(t=typeof o=="function"?o:vr(+o),s(),a):t},a}function tq(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)}function dh(t,e){if((r=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var r,n=t.slice(0,r);return[n.length>1?n[0]+n.slice(2):n,+t.slice(r+1)]}function Eo(t){return t=dh(Math.abs(t)),t?t[1]:NaN}function eq(t,e){return function(r,n){for(var i=r.length,a=[],s=0,o=t[0],l=0;i>0&&o>0&&(l+o+1>n&&(o=Math.max(1,n-l)),a.push(r.substring(i-=o,i+o)),!((l+=o+1)>n));)o=t[s=(s+1)%t.length];return a.reverse().join(e)}}function rq(t){return function(e){return e.replace(/[0-9]/g,function(r){return t[+r]})}}var nq=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Co(t){if(!(e=nq.exec(t)))throw new Error("invalid format: "+t);var e;return new ph({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}Co.prototype=ph.prototype;function ph(t){this.fill=t.fill===void 0?" ":t.fill+"",this.align=t.align===void 0?">":t.align+"",this.sign=t.sign===void 0?"-":t.sign+"",this.symbol=t.symbol===void 0?"":t.symbol+"",this.zero=!!t.zero,this.width=t.width===void 0?void 0:+t.width,this.comma=!!t.comma,this.precision=t.precision===void 0?void 0:+t.precision,this.trim=!!t.trim,this.type=t.type===void 0?"":t.type+""}ph.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function iq(t){t:for(var e=t.length,r=1,n=-1,i;r<e;++r)switch(t[r]){case".":n=i=r;break;case"0":n===0&&(n=r),i=r;break;default:if(!+t[r])break t;n>0&&(n=0);break}return n>0?t.slice(0,n)+t.slice(i+1):t}var Wv;function aq(t,e){var r=dh(t,e);if(!r)return t+"";var n=r[0],i=r[1],a=i-(Wv=Math.max(-8,Math.min(8,Math.floor(i/3)))*3)+1,s=n.length;return a===s?n:a>s?n+new Array(a-s+1).join("0"):a>0?n.slice(0,a)+"."+n.slice(a):"0."+new Array(1-a).join("0")+dh(t,Math.max(0,e+a-1))[0]}function Hv(t,e){var r=dh(t,e);if(!r)return t+"";var n=r[0],i=r[1];return i<0?"0."+new Array(-i).join("0")+n:n.length>i+1?n.slice(0,i+1)+"."+n.slice(i+1):n+new Array(i-n.length+2).join("0")}const Gv={"%":(t,e)=>(t*100).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:tq,e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>Hv(t*100,e),r:Hv,s:aq,X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function jv(t){return t}var $v=Array.prototype.map,Xv=["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];function Kv(t){var e=t.grouping===void 0||t.thousands===void 0?jv:eq($v.call(t.grouping,Number),t.thousands+""),r=t.currency===void 0?"":t.currency[0]+"",n=t.currency===void 0?"":t.currency[1]+"",i=t.decimal===void 0?".":t.decimal+"",a=t.numerals===void 0?jv:rq($v.call(t.numerals,String)),s=t.percent===void 0?"%":t.percent+"",o=t.minus===void 0?"\u2212":t.minus+"",l=t.nan===void 0?"NaN":t.nan+"";function u(d){d=Co(d);var f=d.fill,p=d.align,m=d.sign,_=d.symbol,y=d.zero,b=d.width,x=d.comma,k=d.precision,T=d.trim,C=d.type;C==="n"?(x=!0,C="g"):Gv[C]||(k===void 0&&(k=12),T=!0,C="g"),(y||f==="0"&&p==="=")&&(y=!0,f="0",p="=");var M=_==="$"?r:_==="#"&&/[boxX]/.test(C)?"0"+C.toLowerCase():"",S=_==="$"?n:/[%p]/.test(C)?s:"",R=Gv[C],A=/[defgprs%]/.test(C);k=k===void 0?6:/[gprs]/.test(C)?Math.max(1,Math.min(21,k)):Math.max(0,Math.min(20,k));function L(v){var B=M,w=S,D,N,z;if(C==="c")w=R(v)+w,v="";else{v=+v;var X=v<0||1/v<0;if(v=isNaN(v)?l:R(Math.abs(v),k),T&&(v=iq(v)),X&&+v==0&&m!=="+"&&(X=!1),B=(X?m==="("?m:o:m==="-"||m==="("?"":m)+B,w=(C==="s"?Xv[8+Wv/3]:"")+w+(X&&m==="("?")":""),A){for(D=-1,N=v.length;++D<N;)if(z=v.charCodeAt(D),48>z||z>57){w=(z===46?i+v.slice(D+1):v.slice(D))+w,v=v.slice(0,D);break}}}x&&!y&&(v=e(v,1/0));var ct=B.length+v.length+w.length,J=ct<b?new Array(b-ct+1).join(f):"";switch(x&&y&&(v=e(J+v,J.length?b-w.length:1/0),J=""),p){case"<":v=B+v+w+J;break;case"=":v=B+J+v+w;break;case"^":v=J.slice(0,ct=J.length>>1)+B+v+w+J.slice(ct);break;default:v=J+B+v+w;break}return a(v)}return L.toString=function(){return d+""},L}function h(d,f){var p=u((d=Co(d),d.type="f",d)),m=Math.max(-8,Math.min(8,Math.floor(Eo(f)/3)))*3,_=Math.pow(10,-m),y=Xv[8+m/3];return function(b){return p(_*b)+y}}return{format:u,formatPrefix:h}}var gh,yh,Jd;Zv({thousands:",",grouping:[3],currency:["$",""]});function Zv(t){return gh=Kv(t),yh=gh.format,Jd=gh.formatPrefix,gh}function Qv(t){return Math.max(0,-Eo(Math.abs(t)))}function Jv(t,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Eo(e)/3)))*3-Eo(Math.abs(t)))}function t6(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,Eo(e)-Eo(t))+1}var te=1e-6,Hl=1e-12,Ae=Math.PI,rr=Ae/2,mh=Ae/4,Qr=Ae*2,Ue=180/Ae,re=Ae/180,Ne=Math.abs,So=Math.atan,Jr=Math.atan2,Kt=Math.cos,bh=Math.ceil,e6=Math.exp,t2=Math.hypot,_h=Math.log,e2=Math.pow,Ht=Math.sin,Dn=Math.sign||function(t){return t>0?1:t<0?-1:0},Sr=Math.sqrt,r2=Math.tan;function r6(t){return t>1?0:t<-1?Ae:Math.acos(t)}function tn(t){return t>1?rr:t<-1?-rr:Math.asin(t)}function n6(t){return(t=Ht(t/2))*t}function Je(){}function vh(t,e){t&&a6.hasOwnProperty(t.type)&&a6[t.type](t,e)}var i6={Feature:function(t,e){vh(t.geometry,e)},FeatureCollection:function(t,e){for(var r=t.features,n=-1,i=r.length;++n<i;)vh(r[n].geometry,e)}},a6={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)t=r[n],e.point(t[0],t[1],t[2])},LineString:function(t,e){n2(t.coordinates,e,0)},MultiLineString:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)n2(r[n],e,0)},Polygon:function(t,e){s6(t.coordinates,e)},MultiPolygon:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)s6(r[n],e)},GeometryCollection:function(t,e){for(var r=t.geometries,n=-1,i=r.length;++n<i;)vh(r[n],e)}};function n2(t,e,r){var n=-1,i=t.length-r,a;for(e.lineStart();++n<i;)a=t[n],e.point(a[0],a[1],a[2]);e.lineEnd()}function s6(t,e){var r=-1,n=t.length;for(e.polygonStart();++r<n;)n2(t[r],e,1);e.polygonEnd()}function ti(t,e){t&&i6.hasOwnProperty(t.type)?i6[t.type](t,e):vh(t,e)}var xh=new _r,kh=new _r,o6,l6,i2,a2,s2,Si={point:Je,lineStart:Je,lineEnd:Je,polygonStart:function(){xh=new _r,Si.lineStart=sq,Si.lineEnd=oq},polygonEnd:function(){var t=+xh;kh.add(t<0?Qr+t:t),this.lineStart=this.lineEnd=this.point=Je},sphere:function(){kh.add(Qr)}};function sq(){Si.point=lq}function oq(){c6(o6,l6)}function lq(t,e){Si.point=c6,o6=t,l6=e,t*=re,e*=re,i2=t,a2=Kt(e=e/2+mh),s2=Ht(e)}function c6(t,e){t*=re,e*=re,e=e/2+mh;var r=t-i2,n=r>=0?1:-1,i=n*r,a=Kt(e),s=Ht(e),o=s2*s,l=a2*a+o*Kt(i),u=o*n*Ht(i);xh.add(Jr(u,l)),i2=t,a2=a,s2=s}function cq(t){return kh=new _r,ti(t,Si),kh*2}function wh(t){return[Jr(t[1],t[0]),tn(t[2])]}function Cs(t){var e=t[0],r=t[1],n=Kt(r);return[n*Kt(e),n*Ht(e),Ht(r)]}function Th(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Ao(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function o2(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function Eh(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Ch(t){var e=Sr(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}var tr,pn,nr,En,Ss,u6,h6,Mo,Gl,Ba,Qi,Ji={point:l2,lineStart:d6,lineEnd:p6,polygonStart:function(){Ji.point=g6,Ji.lineStart=uq,Ji.lineEnd=hq,Gl=new _r,Si.polygonStart()},polygonEnd:function(){Si.polygonEnd(),Ji.point=l2,Ji.lineStart=d6,Ji.lineEnd=p6,xh<0?(tr=-(nr=180),pn=-(En=90)):Gl>te?En=90:Gl<-te&&(pn=-90),Qi[0]=tr,Qi[1]=nr},sphere:function(){tr=-(nr=180),pn=-(En=90)}};function l2(t,e){Ba.push(Qi=[tr=t,nr=t]),e<pn&&(pn=e),e>En&&(En=e)}function f6(t,e){var r=Cs([t*re,e*re]);if(Mo){var n=Ao(Mo,r),i=[n[1],-n[0],0],a=Ao(i,n);Ch(a),a=wh(a);var s=t-Ss,o=s>0?1:-1,l=a[0]*Ue*o,u,h=Ne(s)>180;h^(o*Ss<l&&l<o*t)?(u=a[1]*Ue,u>En&&(En=u)):(l=(l+360)%360-180,h^(o*Ss<l&&l<o*t)?(u=-a[1]*Ue,u<pn&&(pn=u)):(e<pn&&(pn=e),e>En&&(En=e))),h?t<Ss?Cn(tr,t)>Cn(tr,nr)&&(nr=t):Cn(t,nr)>Cn(tr,nr)&&(tr=t):nr>=tr?(t<tr&&(tr=t),t>nr&&(nr=t)):t>Ss?Cn(tr,t)>Cn(tr,nr)&&(nr=t):Cn(t,nr)>Cn(tr,nr)&&(tr=t)}else Ba.push(Qi=[tr=t,nr=t]);e<pn&&(pn=e),e>En&&(En=e),Mo=r,Ss=t}function d6(){Ji.point=f6}function p6(){Qi[0]=tr,Qi[1]=nr,Ji.point=l2,Mo=null}function g6(t,e){if(Mo){var r=t-Ss;Gl.add(Ne(r)>180?r+(r>0?360:-360):r)}else u6=t,h6=e;Si.point(t,e),f6(t,e)}function uq(){Si.lineStart()}function hq(){g6(u6,h6),Si.lineEnd(),Ne(Gl)>te&&(tr=-(nr=180)),Qi[0]=tr,Qi[1]=nr,Mo=null}function Cn(t,e){return(e-=t)<0?e+360:e}function fq(t,e){return t[0]-e[0]}function y6(t,e){return t[0]<=t[1]?t[0]<=e&&e<=t[1]:e<t[0]||t[1]<e}function dq(t){var e,r,n,i,a,s,o;if(En=nr=-(tr=pn=1/0),Ba=[],ti(t,Ji),r=Ba.length){for(Ba.sort(fq),e=1,n=Ba[0],a=[n];e<r;++e)i=Ba[e],y6(n,i[0])||y6(n,i[1])?(Cn(n[0],i[1])>Cn(n[0],n[1])&&(n[1]=i[1]),Cn(i[0],n[1])>Cn(n[0],n[1])&&(n[0]=i[0])):a.push(n=i);for(s=-1/0,r=a.length-1,e=0,n=a[r];e<=r;n=i,++e)i=a[e],(o=Cn(n[1],i[0]))>s&&(s=o,tr=i[0],nr=n[1])}return Ba=Qi=null,tr===1/0||pn===1/0?[[NaN,NaN],[NaN,NaN]]:[[tr,pn],[nr,En]]}var jl,Sh,Ah,Mh,Lh,Rh,Ih,Nh,c2,u2,h2,m6,b6,en,rn,nn,ei={sphere:Je,point:f2,lineStart:_6,lineEnd:v6,polygonStart:function(){ei.lineStart=yq,ei.lineEnd=mq},polygonEnd:function(){ei.lineStart=_6,ei.lineEnd=v6}};function f2(t,e){t*=re,e*=re;var r=Kt(e);$l(r*Kt(t),r*Ht(t),Ht(e))}function $l(t,e,r){++jl,Ah+=(t-Ah)/jl,Mh+=(e-Mh)/jl,Lh+=(r-Lh)/jl}function _6(){ei.point=pq}function pq(t,e){t*=re,e*=re;var r=Kt(e);en=r*Kt(t),rn=r*Ht(t),nn=Ht(e),ei.point=gq,$l(en,rn,nn)}function gq(t,e){t*=re,e*=re;var r=Kt(e),n=r*Kt(t),i=r*Ht(t),a=Ht(e),s=Jr(Sr((s=rn*a-nn*i)*s+(s=nn*n-en*a)*s+(s=en*i-rn*n)*s),en*n+rn*i+nn*a);Sh+=s,Rh+=s*(en+(en=n)),Ih+=s*(rn+(rn=i)),Nh+=s*(nn+(nn=a)),$l(en,rn,nn)}function v6(){ei.point=f2}function yq(){ei.point=bq}function mq(){x6(m6,b6),ei.point=f2}function bq(t,e){m6=t,b6=e,t*=re,e*=re,ei.point=x6;var r=Kt(e);en=r*Kt(t),rn=r*Ht(t),nn=Ht(e),$l(en,rn,nn)}function x6(t,e){t*=re,e*=re;var r=Kt(e),n=r*Kt(t),i=r*Ht(t),a=Ht(e),s=rn*a-nn*i,o=nn*n-en*a,l=en*i-rn*n,u=t2(s,o,l),h=tn(u),d=u&&-h/u;c2.add(d*s),u2.add(d*o),h2.add(d*l),Sh+=h,Rh+=h*(en+(en=n)),Ih+=h*(rn+(rn=i)),Nh+=h*(nn+(nn=a)),$l(en,rn,nn)}function _q(t){jl=Sh=Ah=Mh=Lh=Rh=Ih=Nh=0,c2=new _r,u2=new _r,h2=new _r,ti(t,ei);var e=+c2,r=+u2,n=+h2,i=t2(e,r,n);return i<Hl&&(e=Rh,r=Ih,n=Nh,Sh<te&&(e=Ah,r=Mh,n=Lh),i=t2(e,r,n),i<Hl)?[NaN,NaN]:[Jr(r,e)*Ue,tn(n/i)*Ue]}function Lo(t){return function(){return t}}function d2(t,e){function r(n,i){return n=t(n,i),e(n[0],n[1])}return t.invert&&e.invert&&(r.invert=function(n,i){return n=e.invert(n,i),n&&t.invert(n[0],n[1])}),r}function p2(t,e){return[Ne(t)>Ae?t+Math.round(-t/Qr)*Qr:t,e]}p2.invert=p2;function g2(t,e,r){return(t%=Qr)?e||r?d2(w6(t),T6(e,r)):w6(t):e||r?T6(e,r):p2}function k6(t){return function(e,r){return e+=t,[e>Ae?e-Qr:e<-Ae?e+Qr:e,r]}}function w6(t){var e=k6(t);return e.invert=k6(-t),e}function T6(t,e){var r=Kt(t),n=Ht(t),i=Kt(e),a=Ht(e);function s(o,l){var u=Kt(l),h=Kt(o)*u,d=Ht(o)*u,f=Ht(l),p=f*r+h*n;return[Jr(d*i-p*a,h*r-f*n),tn(p*i+d*a)]}return s.invert=function(o,l){var u=Kt(l),h=Kt(o)*u,d=Ht(o)*u,f=Ht(l),p=f*i-d*a;return[Jr(d*i+f*a,h*r+p*n),tn(p*r-h*n)]},s}function E6(t){t=g2(t[0]*re,t[1]*re,t.length>2?t[2]*re:0);function e(r){return r=t(r[0]*re,r[1]*re),r[0]*=Ue,r[1]*=Ue,r}return e.invert=function(r){return r=t.invert(r[0]*re,r[1]*re),r[0]*=Ue,r[1]*=Ue,r},e}function C6(t,e,r,n,i,a){if(!!r){var s=Kt(e),o=Ht(e),l=n*r;i==null?(i=e+n*Qr,a=e-l/2):(i=S6(s,i),a=S6(s,a),(n>0?i<a:i>a)&&(i+=n*Qr));for(var u,h=i;n>0?h>a:h<a;h-=l)u=wh([s,-o*Kt(h),-o*Ht(h)]),t.point(u[0],u[1])}}function S6(t,e){e=Cs(e),e[0]-=t,Ch(e);var r=r6(-e[1]);return((-e[2]<0?-r:r)+Qr-te)%Qr}function vq(){var t=Lo([0,0]),e=Lo(90),r=Lo(6),n,i,a={point:s};function s(l,u){n.push(l=i(l,u)),l[0]*=Ue,l[1]*=Ue}function o(){var l=t.apply(this,arguments),u=e.apply(this,arguments)*re,h=r.apply(this,arguments)*re;return n=[],i=g2(-l[0]*re,-l[1]*re,0).invert,C6(a,u,h,1),l={type:"Polygon",coordinates:[n]},n=i=null,l}return o.center=function(l){return arguments.length?(t=typeof l=="function"?l:Lo([+l[0],+l[1]]),o):t},o.radius=function(l){return arguments.length?(e=typeof l=="function"?l:Lo(+l),o):e},o.precision=function(l){return arguments.length?(r=typeof l=="function"?l:Lo(+l),o):r},o}function A6(){var t=[],e;return{point:function(r,n,i){e.push([r,n,i])},lineStart:function(){t.push(e=[])},lineEnd:Je,rejoin:function(){t.length>1&&t.push(t.pop().concat(t.shift()))},result:function(){var r=t;return t=[],e=null,r}}}function Bh(t,e){return Ne(t[0]-e[0])<te&&Ne(t[1]-e[1])<te}function Dh(t,e,r,n){this.x=t,this.z=e,this.o=r,this.e=n,this.v=!1,this.n=this.p=null}function M6(t,e,r,n,i){var a=[],s=[],o,l;if(t.forEach(function(m){if(!((_=m.length-1)<=0)){var _,y=m[0],b=m[_],x;if(Bh(y,b)){if(!y[2]&&!b[2]){for(i.lineStart(),o=0;o<_;++o)i.point((y=m[o])[0],y[1]);i.lineEnd();return}b[0]+=2*te}a.push(x=new Dh(y,m,null,!0)),s.push(x.o=new Dh(y,null,x,!1)),a.push(x=new Dh(b,m,null,!1)),s.push(x.o=new Dh(b,null,x,!0))}}),!!a.length){for(s.sort(e),L6(a),L6(s),o=0,l=s.length;o<l;++o)s[o].e=r=!r;for(var u=a[0],h,d;;){for(var f=u,p=!0;f.v;)if((f=f.n)===u)return;h=f.z,i.lineStart();do{if(f.v=f.o.v=!0,f.e){if(p)for(o=0,l=h.length;o<l;++o)i.point((d=h[o])[0],d[1]);else n(f.x,f.n.x,1,i);f=f.n}else{if(p)for(h=f.p.z,o=h.length-1;o>=0;--o)i.point((d=h[o])[0],d[1]);else n(f.x,f.p.x,-1,i);f=f.p}f=f.o,h=f.z,p=!p}while(!f.v);i.lineEnd()}}}function L6(t){if(!!(e=t.length)){for(var e,r=0,n=t[0],i;++r<e;)n.n=i=t[r],i.p=n,n=i;n.n=i=t[0],i.p=n}}function y2(t){return Ne(t[0])<=Ae?t[0]:Dn(t[0])*((Ne(t[0])+Ae)%Qr-Ae)}function R6(t,e){var r=y2(e),n=e[1],i=Ht(n),a=[Ht(r),-Kt(r),0],s=0,o=0,l=new _r;i===1?n=rr+te:i===-1&&(n=-rr-te);for(var u=0,h=t.length;u<h;++u)if(!!(f=(d=t[u]).length))for(var d,f,p=d[f-1],m=y2(p),_=p[1]/2+mh,y=Ht(_),b=Kt(_),x=0;x<f;++x,m=T,y=M,b=S,p=k){var k=d[x],T=y2(k),C=k[1]/2+mh,M=Ht(C),S=Kt(C),R=T-m,A=R>=0?1:-1,L=A*R,v=L>Ae,B=y*M;if(l.add(Jr(B*A*Ht(L),b*S+B*Kt(L))),s+=v?R+A*Qr:R,v^m>=r^T>=r){var w=Ao(Cs(p),Cs(k));Ch(w);var D=Ao(a,w);Ch(D);var N=(v^R>=0?-1:1)*tn(D[2]);(n>N||n===N&&(w[0]||w[1]))&&(o+=v^R>=0?1:-1)}}return(s<-te||s<te&&l<-Hl)^o&1}function I6(t,e,r,n){return function(i){var a=e(i),s=A6(),o=e(s),l=!1,u,h,d,f={point:p,lineStart:_,lineEnd:y,polygonStart:function(){f.point=b,f.lineStart=x,f.lineEnd=k,h=[],u=[]},polygonEnd:function(){f.point=p,f.lineStart=_,f.lineEnd=y,h=j0(h);var T=R6(u,n);h.length?(l||(i.polygonStart(),l=!0),M6(h,kq,T,r,i)):T&&(l||(i.polygonStart(),l=!0),i.lineStart(),r(null,null,1,i),i.lineEnd()),l&&(i.polygonEnd(),l=!1),h=u=null},sphere:function(){i.polygonStart(),i.lineStart(),r(null,null,1,i),i.lineEnd(),i.polygonEnd()}};function p(T,C){t(T,C)&&i.point(T,C)}function m(T,C){a.point(T,C)}function _(){f.point=m,a.lineStart()}function y(){f.point=p,a.lineEnd()}function b(T,C){d.push([T,C]),o.point(T,C)}function x(){o.lineStart(),d=[]}function k(){b(d[0][0],d[0][1]),o.lineEnd();var T=o.clean(),C=s.result(),M,S=C.length,R,A,L;if(d.pop(),u.push(d),d=null,!!S){if(T&1){if(A=C[0],(R=A.length-1)>0){for(l||(i.polygonStart(),l=!0),i.lineStart(),M=0;M<R;++M)i.point((L=A[M])[0],L[1]);i.lineEnd()}return}S>1&&T&2&&C.push(C.pop().concat(C.shift())),h.push(C.filter(xq))}}return f}}function xq(t){return t.length>1}function kq(t,e){return((t=t.x)[0]<0?t[1]-rr-te:rr-t[1])-((e=e.x)[0]<0?e[1]-rr-te:rr-e[1])}const m2=I6(function(){return!0},wq,Eq,[-Ae,-rr]);function wq(t){var e=NaN,r=NaN,n=NaN,i;return{lineStart:function(){t.lineStart(),i=1},point:function(a,s){var o=a>0?Ae:-Ae,l=Ne(a-e);Ne(l-Ae)<te?(t.point(e,r=(r+s)/2>0?rr:-rr),t.point(n,r),t.lineEnd(),t.lineStart(),t.point(o,r),t.point(a,r),i=0):n!==o&&l>=Ae&&(Ne(e-n)<te&&(e-=n*te),Ne(a-o)<te&&(a-=o*te),r=Tq(e,r,a,s),t.point(n,r),t.lineEnd(),t.lineStart(),t.point(o,r),i=0),t.point(e=a,r=s),n=o},lineEnd:function(){t.lineEnd(),e=r=NaN},clean:function(){return 2-i}}}function Tq(t,e,r,n){var i,a,s=Ht(t-r);return Ne(s)>te?So((Ht(e)*(a=Kt(n))*Ht(r)-Ht(n)*(i=Kt(e))*Ht(t))/(i*a*s)):(e+n)/2}function Eq(t,e,r,n){var i;if(t==null)i=r*rr,n.point(-Ae,i),n.point(0,i),n.point(Ae,i),n.point(Ae,0),n.point(Ae,-i),n.point(0,-i),n.point(-Ae,-i),n.point(-Ae,0),n.point(-Ae,i);else if(Ne(t[0]-e[0])>te){var a=t[0]<e[0]?Ae:-Ae;i=r*a/2,n.point(-a,i),n.point(0,i),n.point(a,i)}else n.point(e[0],e[1])}function N6(t){var e=Kt(t),r=6*re,n=e>0,i=Ne(e)>te;function a(h,d,f,p){C6(p,t,r,f,h,d)}function s(h,d){return Kt(h)*Kt(d)>e}function o(h){var d,f,p,m,_;return{lineStart:function(){m=p=!1,_=1},point:function(y,b){var x=[y,b],k,T=s(y,b),C=n?T?0:u(y,b):T?u(y+(y<0?Ae:-Ae),b):0;if(!d&&(m=p=T)&&h.lineStart(),T!==p&&(k=l(d,x),(!k||Bh(d,k)||Bh(x,k))&&(x[2]=1)),T!==p)_=0,T?(h.lineStart(),k=l(x,d),h.point(k[0],k[1])):(k=l(d,x),h.point(k[0],k[1],2),h.lineEnd()),d=k;else if(i&&d&&n^T){var M;!(C&f)&&(M=l(x,d,!0))&&(_=0,n?(h.lineStart(),h.point(M[0][0],M[0][1]),h.point(M[1][0],M[1][1]),h.lineEnd()):(h.point(M[1][0],M[1][1]),h.lineEnd(),h.lineStart(),h.point(M[0][0],M[0][1],3)))}T&&(!d||!Bh(d,x))&&h.point(x[0],x[1]),d=x,p=T,f=C},lineEnd:function(){p&&h.lineEnd(),d=null},clean:function(){return _|(m&&p)<<1}}}function l(h,d,f){var p=Cs(h),m=Cs(d),_=[1,0,0],y=Ao(p,m),b=Th(y,y),x=y[0],k=b-x*x;if(!k)return!f&&h;var T=e*b/k,C=-e*x/k,M=Ao(_,y),S=Eh(_,T),R=Eh(y,C);o2(S,R);var A=M,L=Th(S,A),v=Th(A,A),B=L*L-v*(Th(S,S)-1);if(!(B<0)){var w=Sr(B),D=Eh(A,(-L-w)/v);if(o2(D,S),D=wh(D),!f)return D;var N=h[0],z=d[0],X=h[1],ct=d[1],J;z<N&&(J=N,N=z,z=J);var Y=z-N,$=Ne(Y-Ae)<te,lt=$||Y<te;if(!$&&ct<X&&(J=X,X=ct,ct=J),lt?$?X+ct>0^D[1]<(Ne(D[0]-N)<te?X:ct):X<=D[1]&&D[1]<=ct:Y>Ae^(N<=D[0]&&D[0]<=z)){var ut=Eh(A,(-L+w)/v);return o2(ut,S),[D,wh(ut)]}}}function u(h,d){var f=n?t:Ae-t,p=0;return h<-f?p|=1:h>f&&(p|=2),d<-f?p|=4:d>f&&(p|=8),p}return I6(s,o,a,n?[0,-t]:[-Ae,t-Ae])}function Cq(t,e,r,n,i,a){var s=t[0],o=t[1],l=e[0],u=e[1],h=0,d=1,f=l-s,p=u-o,m;if(m=r-s,!(!f&&m>0)){if(m/=f,f<0){if(m<h)return;m<d&&(d=m)}else if(f>0){if(m>d)return;m>h&&(h=m)}if(m=i-s,!(!f&&m<0)){if(m/=f,f<0){if(m>d)return;m>h&&(h=m)}else if(f>0){if(m<h)return;m<d&&(d=m)}if(m=n-o,!(!p&&m>0)){if(m/=p,p<0){if(m<h)return;m<d&&(d=m)}else if(p>0){if(m>d)return;m>h&&(h=m)}if(m=a-o,!(!p&&m<0)){if(m/=p,p<0){if(m>d)return;m>h&&(h=m)}else if(p>0){if(m<h)return;m<d&&(d=m)}return h>0&&(t[0]=s+h*f,t[1]=o+h*p),d<1&&(e[0]=s+d*f,e[1]=o+d*p),!0}}}}}var Xl=1e9,Oh=-Xl;function Fh(t,e,r,n){function i(u,h){return t<=u&&u<=r&&e<=h&&h<=n}function a(u,h,d,f){var p=0,m=0;if(u==null||(p=s(u,d))!==(m=s(h,d))||l(u,h)<0^d>0)do f.point(p===0||p===3?t:r,p>1?n:e);while((p=(p+d+4)%4)!==m);else f.point(h[0],h[1])}function s(u,h){return Ne(u[0]-t)<te?h>0?0:3:Ne(u[0]-r)<te?h>0?2:1:Ne(u[1]-e)<te?h>0?1:0:h>0?3:2}function o(u,h){return l(u.x,h.x)}function l(u,h){var d=s(u,1),f=s(h,1);return d!==f?d-f:d===0?h[1]-u[1]:d===1?u[0]-h[0]:d===2?u[1]-h[1]:h[0]-u[0]}return function(u){var h=u,d=A6(),f,p,m,_,y,b,x,k,T,C,M,S={point:R,lineStart:B,lineEnd:w,polygonStart:L,polygonEnd:v};function R(N,z){i(N,z)&&h.point(N,z)}function A(){for(var N=0,z=0,X=p.length;z<X;++z)for(var ct=p[z],J=1,Y=ct.length,$=ct[0],lt,ut,W=$[0],tt=$[1];J<Y;++J)lt=W,ut=tt,$=ct[J],W=$[0],tt=$[1],ut<=n?tt>n&&(W-lt)*(n-ut)>(tt-ut)*(t-lt)&&++N:tt<=n&&(W-lt)*(n-ut)<(tt-ut)*(t-lt)&&--N;return N}function L(){h=d,f=[],p=[],M=!0}function v(){var N=A(),z=M&&N,X=(f=j0(f)).length;(z||X)&&(u.polygonStart(),z&&(u.lineStart(),a(null,null,1,u),u.lineEnd()),X&&M6(f,o,N,a,u),u.polygonEnd()),h=u,f=p=m=null}function B(){S.point=D,p&&p.push(m=[]),C=!0,T=!1,x=k=NaN}function w(){f&&(D(_,y),b&&T&&d.rejoin(),f.push(d.result())),S.point=R,T&&h.lineEnd()}function D(N,z){var X=i(N,z);if(p&&m.push([N,z]),C)_=N,y=z,b=X,C=!1,X&&(h.lineStart(),h.point(N,z));else if(X&&T)h.point(N,z);else{var ct=[x=Math.max(Oh,Math.min(Xl,x)),k=Math.max(Oh,Math.min(Xl,k))],J=[N=Math.max(Oh,Math.min(Xl,N)),z=Math.max(Oh,Math.min(Xl,z))];Cq(ct,J,t,e,r,n)?(T||(h.lineStart(),h.point(ct[0],ct[1])),h.point(J[0],J[1]),X||h.lineEnd(),M=!1):X&&(h.lineStart(),h.point(N,z),M=!1)}x=N,k=z,T=X}return S}}function Sq(){var t=0,e=0,r=960,n=500,i,a,s;return s={stream:function(o){return i&&a===o?i:i=Fh(t,e,r,n)(a=o)},extent:function(o){return arguments.length?(t=+o[0][0],e=+o[0][1],r=+o[1][0],n=+o[1][1],i=a=null,s):[[t,e],[r,n]]}}}var b2,_2,Ph,qh,Ro={sphere:Je,point:Je,lineStart:Aq,lineEnd:Je,polygonStart:Je,polygonEnd:Je};function Aq(){Ro.point=Lq,Ro.lineEnd=Mq}function Mq(){Ro.point=Ro.lineEnd=Je}function Lq(t,e){t*=re,e*=re,_2=t,Ph=Ht(e),qh=Kt(e),Ro.point=Rq}function Rq(t,e){t*=re,e*=re;var r=Ht(e),n=Kt(e),i=Ne(t-_2),a=Kt(i),s=Ht(i),o=n*s,l=qh*r-Ph*n*a,u=Ph*r+qh*n*a;b2.add(Jr(Sr(o*o+l*l),u)),_2=t,Ph=r,qh=n}function B6(t){return b2=new _r,ti(t,Ro),+b2}var v2=[null,null],Iq={type:"LineString",coordinates:v2};function Vh(t,e){return v2[0]=t,v2[1]=e,B6(Iq)}var D6={Feature:function(t,e){return zh(t.geometry,e)},FeatureCollection:function(t,e){for(var r=t.features,n=-1,i=r.length;++n<i;)if(zh(r[n].geometry,e))return!0;return!1}},O6={Sphere:function(){return!0},Point:function(t,e){return F6(t.coordinates,e)},MultiPoint:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)if(F6(r[n],e))return!0;return!1},LineString:function(t,e){return P6(t.coordinates,e)},MultiLineString:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)if(P6(r[n],e))return!0;return!1},Polygon:function(t,e){return q6(t.coordinates,e)},MultiPolygon:function(t,e){for(var r=t.coordinates,n=-1,i=r.length;++n<i;)if(q6(r[n],e))return!0;return!1},GeometryCollection:function(t,e){for(var r=t.geometries,n=-1,i=r.length;++n<i;)if(zh(r[n],e))return!0;return!1}};function zh(t,e){return t&&O6.hasOwnProperty(t.type)?O6[t.type](t,e):!1}function F6(t,e){return Vh(t,e)===0}function P6(t,e){for(var r,n,i,a=0,s=t.length;a<s;a++){if(n=Vh(t[a],e),n===0||a>0&&(i=Vh(t[a],t[a-1]),i>0&&r<=i&&n<=i&&(r+n-i)*(1-Math.pow((r-n)/i,2))<Hl*i))return!0;r=n}return!1}function q6(t,e){return!!R6(t.map(Nq),V6(e))}function Nq(t){return t=t.map(V6),t.pop(),t}function V6(t){return[t[0]*re,t[1]*re]}function Bq(t,e){return(t&&D6.hasOwnProperty(t.type)?D6[t.type]:zh)(t,e)}function z6(t,e,r){var n=Ca(t,e-te,r).concat(e);return function(i){return n.map(function(a){return[i,a]})}}function Y6(t,e,r){var n=Ca(t,e-te,r).concat(e);return function(i){return n.map(function(a){return[a,i]})}}function U6(){var t,e,r,n,i,a,s,o,l=10,u=l,h=90,d=360,f,p,m,_,y=2.5;function b(){return{type:"MultiLineString",coordinates:x()}}function x(){return Ca(bh(n/h)*h,r,h).map(m).concat(Ca(bh(o/d)*d,s,d).map(_)).concat(Ca(bh(e/l)*l,t,l).filter(function(k){return Ne(k%h)>te}).map(f)).concat(Ca(bh(a/u)*u,i,u).filter(function(k){return Ne(k%d)>te}).map(p))}return b.lines=function(){return x().map(function(k){return{type:"LineString",coordinates:k}})},b.outline=function(){return{type:"Polygon",coordinates:[m(n).concat(_(s).slice(1),m(r).reverse().slice(1),_(o).reverse().slice(1))]}},b.extent=function(k){return arguments.length?b.extentMajor(k).extentMinor(k):b.extentMinor()},b.extentMajor=function(k){return arguments.length?(n=+k[0][0],r=+k[1][0],o=+k[0][1],s=+k[1][1],n>r&&(k=n,n=r,r=k),o>s&&(k=o,o=s,s=k),b.precision(y)):[[n,o],[r,s]]},b.extentMinor=function(k){return arguments.length?(e=+k[0][0],t=+k[1][0],a=+k[0][1],i=+k[1][1],e>t&&(k=e,e=t,t=k),a>i&&(k=a,a=i,i=k),b.precision(y)):[[e,a],[t,i]]},b.step=function(k){return arguments.length?b.stepMajor(k).stepMinor(k):b.stepMinor()},b.stepMajor=function(k){return arguments.length?(h=+k[0],d=+k[1],b):[h,d]},b.stepMinor=function(k){return arguments.length?(l=+k[0],u=+k[1],b):[l,u]},b.precision=function(k){return arguments.length?(y=+k,f=z6(a,i,90),p=Y6(e,t,y),m=z6(o,s,90),_=Y6(n,r,y),b):y},b.extentMajor([[-180,-90+te],[180,90-te]]).extentMinor([[-180,-80-te],[180,80+te]])}function Dq(){return U6()()}function Oq(t,e){var r=t[0]*re,n=t[1]*re,i=e[0]*re,a=e[1]*re,s=Kt(n),o=Ht(n),l=Kt(a),u=Ht(a),h=s*Kt(r),d=s*Ht(r),f=l*Kt(i),p=l*Ht(i),m=2*tn(Sr(n6(a-n)+s*l*n6(i-r))),_=Ht(m),y=m?function(b){var x=Ht(b*=m)/_,k=Ht(m-b)/_,T=k*h+x*f,C=k*d+x*p,M=k*o+x*u;return[Jr(C,T)*Ue,Jr(M,Sr(T*T+C*C))*Ue]}:function(){return[r*Ue,n*Ue]};return y.distance=m,y}const Kl=t=>t;var x2=new _r,k2=new _r,W6,H6,w2,T2,Da={point:Je,lineStart:Je,lineEnd:Je,polygonStart:function(){Da.lineStart=Fq,Da.lineEnd=qq},polygonEnd:function(){Da.lineStart=Da.lineEnd=Da.point=Je,x2.add(Ne(k2)),k2=new _r},result:function(){var t=x2/2;return x2=new _r,t}};function Fq(){Da.point=Pq}function Pq(t,e){Da.point=G6,W6=w2=t,H6=T2=e}function G6(t,e){k2.add(T2*t-w2*e),w2=t,T2=e}function qq(){G6(W6,H6)}const j6=Da;var Io=1/0,Yh=Io,Zl=-Io,Uh=Zl,Vq={point:zq,lineStart:Je,lineEnd:Je,polygonStart:Je,polygonEnd:Je,result:function(){var t=[[Io,Yh],[Zl,Uh]];return Zl=Uh=-(Yh=Io=1/0),t}};function zq(t,e){t<Io&&(Io=t),t>Zl&&(Zl=t),e<Yh&&(Yh=e),e>Uh&&(Uh=e)}const Wh=Vq;var E2=0,C2=0,Ql=0,Hh=0,Gh=0,No=0,S2=0,A2=0,Jl=0,$6,X6,Ai,Mi,ri={point:As,lineStart:K6,lineEnd:Z6,polygonStart:function(){ri.lineStart=Wq,ri.lineEnd=Hq},polygonEnd:function(){ri.point=As,ri.lineStart=K6,ri.lineEnd=Z6},result:function(){var t=Jl?[S2/Jl,A2/Jl]:No?[Hh/No,Gh/No]:Ql?[E2/Ql,C2/Ql]:[NaN,NaN];return E2=C2=Ql=Hh=Gh=No=S2=A2=Jl=0,t}};function As(t,e){E2+=t,C2+=e,++Ql}function K6(){ri.point=Yq}function Yq(t,e){ri.point=Uq,As(Ai=t,Mi=e)}function Uq(t,e){var r=t-Ai,n=e-Mi,i=Sr(r*r+n*n);Hh+=i*(Ai+t)/2,Gh+=i*(Mi+e)/2,No+=i,As(Ai=t,Mi=e)}function Z6(){ri.point=As}function Wq(){ri.point=Gq}function Hq(){Q6($6,X6)}function Gq(t,e){ri.point=Q6,As($6=Ai=t,X6=Mi=e)}function Q6(t,e){var r=t-Ai,n=e-Mi,i=Sr(r*r+n*n);Hh+=i*(Ai+t)/2,Gh+=i*(Mi+e)/2,No+=i,i=Mi*t-Ai*e,S2+=i*(Ai+t),A2+=i*(Mi+e),Jl+=i*3,As(Ai=t,Mi=e)}const J6=ri;function tx(t){this._context=t}tx.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._context.closePath(),this._point=NaN},point:function(t,e){switch(this._point){case 0:{this._context.moveTo(t,e),this._point=1;break}case 1:{this._context.lineTo(t,e);break}default:{this._context.moveTo(t+this._radius,e),this._context.arc(t,e,this._radius,0,Qr);break}}},result:Je};var M2=new _r,L2,ex,rx,tc,ec,jh={point:Je,lineStart:function(){jh.point=jq},lineEnd:function(){L2&&nx(ex,rx),jh.point=Je},polygonStart:function(){L2=!0},polygonEnd:function(){L2=null},result:function(){var t=+M2;return M2=new _r,t}};function jq(t,e){jh.point=nx,ex=tc=t,rx=ec=e}function nx(t,e){tc-=t,ec-=e,M2.add(Sr(tc*tc+ec*ec)),tc=t,ec=e}const ix=jh;function ax(){this._string=[]}ax.prototype={_radius:4.5,_circle:sx(4.5),pointRadius:function(t){return(t=+t)!==this._radius&&(this._radius=t,this._circle=null),this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._string.push("Z"),this._point=NaN},point:function(t,e){switch(this._point){case 0:{this._string.push("M",t,",",e),this._point=1;break}case 1:{this._string.push("L",t,",",e);break}default:{this._circle==null&&(this._circle=sx(this._radius)),this._string.push("M",t,",",e,this._circle);break}}},result:function(){if(this._string.length){var t=this._string.join("");return this._string=[],t}else return null}};function sx(t){return"m0,"+t+"a"+t+","+t+" 0 1,1 0,"+-2*t+"a"+t+","+t+" 0 1,1 0,"+2*t+"z"}function $q(t,e){var r=4.5,n,i;function a(s){return s&&(typeof r=="function"&&i.pointRadius(+r.apply(this,arguments)),ti(s,n(i))),i.result()}return a.area=function(s){return ti(s,n(j6)),j6.result()},a.measure=function(s){return ti(s,n(ix)),ix.result()},a.bounds=function(s){return ti(s,n(Wh)),Wh.result()},a.centroid=function(s){return ti(s,n(J6)),J6.result()},a.projection=function(s){return arguments.length?(n=s==null?(t=null,Kl):(t=s).stream,a):t},a.context=function(s){return arguments.length?(i=s==null?(e=null,new ax):new tx(e=s),typeof r!="function"&&i.pointRadius(r),a):e},a.pointRadius=function(s){return arguments.length?(r=typeof s=="function"?s:(i.pointRadius(+s),+s),a):r},a.projection(t).context(e)}function Xq(t){return{stream:rc(t)}}function rc(t){return function(e){var r=new R2;for(var n in t)r[n]=t[n];return r.stream=e,r}}function R2(){}R2.prototype={constructor:R2,point:function(t,e){this.stream.point(t,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function I2(t,e,r){var n=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),n!=null&&t.clipExtent(null),ti(r,t.stream(Wh)),e(Wh.result()),n!=null&&t.clipExtent(n),t}function $h(t,e,r){return I2(t,function(n){var i=e[1][0]-e[0][0],a=e[1][1]-e[0][1],s=Math.min(i/(n[1][0]-n[0][0]),a/(n[1][1]-n[0][1])),o=+e[0][0]+(i-s*(n[1][0]+n[0][0]))/2,l=+e[0][1]+(a-s*(n[1][1]+n[0][1]))/2;t.scale(150*s).translate([o,l])},r)}function N2(t,e,r){return $h(t,[[0,0],e],r)}function B2(t,e,r){return I2(t,function(n){var i=+e,a=i/(n[1][0]-n[0][0]),s=(i-a*(n[1][0]+n[0][0]))/2,o=-a*n[0][1];t.scale(150*a).translate([s,o])},r)}function D2(t,e,r){return I2(t,function(n){var i=+e,a=i/(n[1][1]-n[0][1]),s=-a*n[0][0],o=(i-a*(n[1][1]+n[0][1]))/2;t.scale(150*a).translate([s,o])},r)}var ox=16,Kq=Kt(30*re);function lx(t,e){return+e?Qq(t,e):Zq(t)}function Zq(t){return rc({point:function(e,r){e=t(e,r),this.stream.point(e[0],e[1])}})}function Qq(t,e){function r(n,i,a,s,o,l,u,h,d,f,p,m,_,y){var b=u-n,x=h-i,k=b*b+x*x;if(k>4*e&&_--){var T=s+f,C=o+p,M=l+m,S=Sr(T*T+C*C+M*M),R=tn(M/=S),A=Ne(Ne(M)-1)<te||Ne(a-d)<te?(a+d)/2:Jr(C,T),L=t(A,R),v=L[0],B=L[1],w=v-n,D=B-i,N=x*w-b*D;(N*N/k>e||Ne((b*w+x*D)/k-.5)>.3||s*f+o*p+l*m<Kq)&&(r(n,i,a,s,o,l,v,B,A,T/=S,C/=S,M,_,y),y.point(v,B),r(v,B,A,T,C,M,u,h,d,f,p,m,_,y))}}return function(n){var i,a,s,o,l,u,h,d,f,p,m,_,y={point:b,lineStart:x,lineEnd:T,polygonStart:function(){n.polygonStart(),y.lineStart=C},polygonEnd:function(){n.polygonEnd(),y.lineStart=x}};function b(R,A){R=t(R,A),n.point(R[0],R[1])}function x(){d=NaN,y.point=k,n.lineStart()}function k(R,A){var L=Cs([R,A]),v=t(R,A);r(d,f,h,p,m,_,d=v[0],f=v[1],h=R,p=L[0],m=L[1],_=L[2],ox,n),n.point(d,f)}function T(){y.point=b,n.lineEnd()}function C(){x(),y.point=M,y.lineEnd=S}function M(R,A){k(i=R,A),a=d,s=f,o=p,l=m,u=_,y.point=k}function S(){r(d,f,h,p,m,_,a,s,i,o,l,u,ox,n),y.lineEnd=T,T()}return y}}var Jq=rc({point:function(t,e){this.stream.point(t*re,e*re)}});function tV(t){return rc({point:function(e,r){var n=t(e,r);return this.stream.point(n[0],n[1])}})}function eV(t,e,r,n,i){function a(s,o){return s*=n,o*=i,[e+t*s,r-t*o]}return a.invert=function(s,o){return[(s-e)/t*n,(r-o)/t*i]},a}function cx(t,e,r,n,i,a){if(!a)return eV(t,e,r,n,i);var s=Kt(a),o=Ht(a),l=s*t,u=o*t,h=s/t,d=o/t,f=(o*r-s*e)/t,p=(o*e+s*r)/t;function m(_,y){return _*=n,y*=i,[l*_-u*y+e,r-u*_-l*y]}return m.invert=function(_,y){return[n*(h*_-d*y+f),i*(p-d*_-h*y)]},m}function Li(t){return O2(function(){return t})()}function O2(t){var e,r=150,n=480,i=250,a=0,s=0,o=0,l=0,u=0,h,d=0,f=1,p=1,m=null,_=m2,y=null,b,x,k,T=Kl,C=.5,M,S,R,A,L;function v(N){return R(N[0]*re,N[1]*re)}function B(N){return N=R.invert(N[0],N[1]),N&&[N[0]*Ue,N[1]*Ue]}v.stream=function(N){return A&&L===N?A:A=Jq(tV(h)(_(M(T(L=N)))))},v.preclip=function(N){return arguments.length?(_=N,m=void 0,D()):_},v.postclip=function(N){return arguments.length?(T=N,y=b=x=k=null,D()):T},v.clipAngle=function(N){return arguments.length?(_=+N?N6(m=N*re):(m=null,m2),D()):m*Ue},v.clipExtent=function(N){return arguments.length?(T=N==null?(y=b=x=k=null,Kl):Fh(y=+N[0][0],b=+N[0][1],x=+N[1][0],k=+N[1][1]),D()):y==null?null:[[y,b],[x,k]]},v.scale=function(N){return arguments.length?(r=+N,w()):r},v.translate=function(N){return arguments.length?(n=+N[0],i=+N[1],w()):[n,i]},v.center=function(N){return arguments.length?(a=N[0]%360*re,s=N[1]%360*re,w()):[a*Ue,s*Ue]},v.rotate=function(N){return arguments.length?(o=N[0]%360*re,l=N[1]%360*re,u=N.length>2?N[2]%360*re:0,w()):[o*Ue,l*Ue,u*Ue]},v.angle=function(N){return arguments.length?(d=N%360*re,w()):d*Ue},v.reflectX=function(N){return arguments.length?(f=N?-1:1,w()):f<0},v.reflectY=function(N){return arguments.length?(p=N?-1:1,w()):p<0},v.precision=function(N){return arguments.length?(M=lx(S,C=N*N),D()):Sr(C)},v.fitExtent=function(N,z){return $h(v,N,z)},v.fitSize=function(N,z){return N2(v,N,z)},v.fitWidth=function(N,z){return B2(v,N,z)},v.fitHeight=function(N,z){return D2(v,N,z)};function w(){var N=cx(r,0,0,f,p,d).apply(null,e(a,s)),z=cx(r,n-N[0],i-N[1],f,p,d);return h=g2(o,l,u),S=d2(e,z),R=d2(h,S),M=lx(S,C),D()}function D(){return A=L=null,v}return function(){return e=t.apply(this,arguments),v.invert=e.invert&&B,w()}}function F2(t){var e=0,r=Ae/3,n=O2(t),i=n(e,r);return i.parallels=function(a){return arguments.length?n(e=a[0]*re,r=a[1]*re):[e*Ue,r*Ue]},i}function rV(t){var e=Kt(t);function r(n,i){return[n*e,Ht(i)/e]}return r.invert=function(n,i){return[n/e,tn(i*e)]},r}function ux(t,e){var r=Ht(t),n=(r+Ht(e))/2;if(Ne(n)<te)return rV(t);var i=1+r*(2*n-r),a=Sr(i)/n;function s(o,l){var u=Sr(i-2*n*Ht(l))/n;return[u*Ht(o*=n),a-u*Kt(o)]}return s.invert=function(o,l){var u=a-l,h=Jr(o,Ne(u))*Dn(u);return u*n<0&&(h-=Ae*Dn(o)*Dn(u)),[h/n,tn((i-(o*o+u*u)*n*n)/(2*n))]},s}function Xh(){return F2(ux).scale(155.424).center([0,33.6442])}function hx(){return Xh().parallels([29.5,45.5]).scale(1070).translate([480,250]).rotate([96,0]).center([-.6,38.7])}function nV(t){var e=t.length;return{point:function(r,n){for(var i=-1;++i<e;)t[i].point(r,n)},sphere:function(){for(var r=-1;++r<e;)t[r].sphere()},lineStart:function(){for(var r=-1;++r<e;)t[r].lineStart()},lineEnd:function(){for(var r=-1;++r<e;)t[r].lineEnd()},polygonStart:function(){for(var r=-1;++r<e;)t[r].polygonStart()},polygonEnd:function(){for(var r=-1;++r<e;)t[r].polygonEnd()}}}function iV(){var t,e,r=hx(),n,i=Xh().rotate([154,0]).center([-2,58.5]).parallels([55,65]),a,s=Xh().rotate([157,0]).center([-3,19.9]).parallels([8,18]),o,l,u={point:function(f,p){l=[f,p]}};function h(f){var p=f[0],m=f[1];return l=null,n.point(p,m),l||(a.point(p,m),l)||(o.point(p,m),l)}h.invert=function(f){var p=r.scale(),m=r.translate(),_=(f[0]-m[0])/p,y=(f[1]-m[1])/p;return(y>=.12&&y<.234&&_>=-.425&&_<-.214?i:y>=.166&&y<.234&&_>=-.214&&_<-.115?s:r).invert(f)},h.stream=function(f){return t&&e===f?t:t=nV([r.stream(e=f),i.stream(f),s.stream(f)])},h.precision=function(f){return arguments.length?(r.precision(f),i.precision(f),s.precision(f),d()):r.precision()},h.scale=function(f){return arguments.length?(r.scale(f),i.scale(f*.35),s.scale(f),h.translate(r.translate())):r.scale()},h.translate=function(f){if(!arguments.length)return r.translate();var p=r.scale(),m=+f[0],_=+f[1];return n=r.translate(f).clipExtent([[m-.455*p,_-.238*p],[m+.455*p,_+.238*p]]).stream(u),a=i.translate([m-.307*p,_+.201*p]).clipExtent([[m-.425*p+te,_+.12*p+te],[m-.214*p-te,_+.234*p-te]]).stream(u),o=s.translate([m-.205*p,_+.212*p]).clipExtent([[m-.214*p+te,_+.166*p+te],[m-.115*p-te,_+.234*p-te]]).stream(u),d()},h.fitExtent=function(f,p){return $h(h,f,p)},h.fitSize=function(f,p){return N2(h,f,p)},h.fitWidth=function(f,p){return B2(h,f,p)},h.fitHeight=function(f,p){return D2(h,f,p)};function d(){return t=e=null,h}return h.scale(1070)}function fx(t){return function(e,r){var n=Kt(e),i=Kt(r),a=t(n*i);return a===1/0?[2,0]:[a*i*Ht(e),a*Ht(r)]}}function nc(t){return function(e,r){var n=Sr(e*e+r*r),i=t(n),a=Ht(i),s=Kt(i);return[Jr(e*a,n*s),tn(n&&r*a/n)]}}var P2=fx(function(t){return Sr(2/(1+t))});P2.invert=nc(function(t){return 2*tn(t/2)});function aV(){return Li(P2).scale(124.75).clipAngle(180-.001)}var q2=fx(function(t){return(t=r6(t))&&t/Ht(t)});q2.invert=nc(function(t){return t});function sV(){return Li(q2).scale(79.4188).clipAngle(180-.001)}function ic(t,e){return[t,_h(r2((rr+e)/2))]}ic.invert=function(t,e){return[t,2*So(e6(e))-rr]};function oV(){return dx(ic).scale(961/Qr)}function dx(t){var e=Li(t),r=e.center,n=e.scale,i=e.translate,a=e.clipExtent,s=null,o,l,u;e.scale=function(d){return arguments.length?(n(d),h()):n()},e.translate=function(d){return arguments.length?(i(d),h()):i()},e.center=function(d){return arguments.length?(r(d),h()):r()},e.clipExtent=function(d){return arguments.length?(d==null?s=o=l=u=null:(s=+d[0][0],o=+d[0][1],l=+d[1][0],u=+d[1][1]),h()):s==null?null:[[s,o],[l,u]]};function h(){var d=Ae*n(),f=e(E6(e.rotate()).invert([0,0]));return a(s==null?[[f[0]-d,f[1]-d],[f[0]+d,f[1]+d]]:t===ic?[[Math.max(f[0]-d,s),o],[Math.min(f[0]+d,l),u]]:[[s,Math.max(f[1]-d,o)],[l,Math.min(f[1]+d,u)]])}return h()}function Kh(t){return r2((rr+t)/2)}function px(t,e){var r=Kt(t),n=t===e?Ht(t):_h(r/Kt(e))/_h(Kh(e)/Kh(t)),i=r*e2(Kh(t),n)/n;if(!n)return ic;function a(s,o){i>0?o<-rr+te&&(o=-rr+te):o>rr-te&&(o=rr-te);var l=i/e2(Kh(o),n);return[l*Ht(n*s),i-l*Kt(n*s)]}return a.invert=function(s,o){var l=i-o,u=Dn(n)*Sr(s*s+l*l),h=Jr(s,Ne(l))*Dn(l);return l*n<0&&(h-=Ae*Dn(s)*Dn(l)),[h/n,2*So(e2(i/u,1/n))-rr]},a}function lV(){return F2(px).scale(109.5).parallels([30,30])}function ac(t,e){return[t,e]}ac.invert=ac;function cV(){return Li(ac).scale(152.63)}function gx(t,e){var r=Kt(t),n=t===e?Ht(t):(r-Kt(e))/(e-t),i=r/n+t;if(Ne(n)<te)return ac;function a(s,o){var l=i-o,u=n*s;return[l*Ht(u),i-l*Kt(u)]}return a.invert=function(s,o){var l=i-o,u=Jr(s,Ne(l))*Dn(l);return l*n<0&&(u-=Ae*Dn(s)*Dn(l)),[u/n,i-Dn(n)*Sr(s*s+l*l)]},a}function uV(){return F2(gx).scale(131.154).center([0,13.9389])}var sc=1.340264,oc=-.081106,lc=893e-6,cc=.003796,Zh=Sr(3)/2,hV=12;function V2(t,e){var r=tn(Zh*Ht(e)),n=r*r,i=n*n*n;return[t*Kt(r)/(Zh*(sc+3*oc*n+i*(7*lc+9*cc*n))),r*(sc+oc*n+i*(lc+cc*n))]}V2.invert=function(t,e){for(var r=e,n=r*r,i=n*n*n,a=0,s,o,l;a<hV&&(o=r*(sc+oc*n+i*(lc+cc*n))-e,l=sc+3*oc*n+i*(7*lc+9*cc*n),r-=s=o/l,n=r*r,i=n*n*n,!(Ne(s)<Hl));++a);return[Zh*t*(sc+3*oc*n+i*(7*lc+9*cc*n))/Kt(r),tn(Ht(r)/Zh)]};function fV(){return Li(V2).scale(177.158)}function z2(t,e){var r=Kt(e),n=Kt(t)*r;return[r*Ht(t)/n,Ht(e)/n]}z2.invert=nc(So);function dV(){return Li(z2).scale(144.049).clipAngle(60)}function pV(){var t=1,e=0,r=0,n=1,i=1,a=0,s,o,l=null,u,h,d,f=1,p=1,m=rc({point:function(T,C){var M=k([T,C]);this.stream.point(M[0],M[1])}}),_=Kl,y,b;function x(){return f=t*n,p=t*i,y=b=null,k}function k(T){var C=T[0]*f,M=T[1]*p;if(a){var S=M*s-C*o;C=C*s+M*o,M=S}return[C+e,M+r]}return k.invert=function(T){var C=T[0]-e,M=T[1]-r;if(a){var S=M*s+C*o;C=C*s-M*o,M=S}return[C/f,M/p]},k.stream=function(T){return y&&b===T?y:y=m(_(b=T))},k.postclip=function(T){return arguments.length?(_=T,l=u=h=d=null,x()):_},k.clipExtent=function(T){return arguments.length?(_=T==null?(l=u=h=d=null,Kl):Fh(l=+T[0][0],u=+T[0][1],h=+T[1][0],d=+T[1][1]),x()):l==null?null:[[l,u],[h,d]]},k.scale=function(T){return arguments.length?(t=+T,x()):t},k.translate=function(T){return arguments.length?(e=+T[0],r=+T[1],x()):[e,r]},k.angle=function(T){return arguments.length?(a=T%360*re,o=Ht(a),s=Kt(a),x()):a*Ue},k.reflectX=function(T){return arguments.length?(n=T?-1:1,x()):n<0},k.reflectY=function(T){return arguments.length?(i=T?-1:1,x()):i<0},k.fitExtent=function(T,C){return $h(k,T,C)},k.fitSize=function(T,C){return N2(k,T,C)},k.fitWidth=function(T,C){return B2(k,T,C)},k.fitHeight=function(T,C){return D2(k,T,C)},k}function Y2(t,e){var r=e*e,n=r*r;return[t*(.8707-.131979*r+n*(-.013791+n*(.003971*r-.001529*n))),e*(1.007226+r*(.015085+n*(-.044475+.028874*r-.005916*n)))]}Y2.invert=function(t,e){var r=e,n=25,i;do{var a=r*r,s=a*a;r-=i=(r*(1.007226+a*(.015085+s*(-.044475+.028874*a-.005916*s)))-e)/(1.007226+a*(.015085*3+s*(-.044475*7+.028874*9*a-.005916*11*s)))}while(Ne(i)>te&&--n>0);return[t/(.8707+(a=r*r)*(-.131979+a*(-.013791+a*a*a*(.003971-.001529*a)))),r]};function gV(){return Li(Y2).scale(175.295)}function U2(t,e){return[Kt(e)*Ht(t),Ht(e)]}U2.invert=nc(tn);function yV(){return Li(U2).scale(249.5).clipAngle(90+te)}function W2(t,e){var r=Kt(e),n=1+Kt(t)*r;return[r*Ht(t)/n,Ht(e)/n]}W2.invert=nc(function(t){return 2*So(t)});function mV(){return Li(W2).scale(250).clipAngle(142)}function H2(t,e){return[_h(r2((rr+e)/2)),-t]}H2.invert=function(t,e){return[-e,2*So(e6(t))-rr]};function bV(){var t=dx(H2),e=t.center,r=t.rotate;return t.center=function(n){return arguments.length?e([-n[1],n[0]]):(n=e(),[n[1],-n[0]])},t.rotate=function(n){return arguments.length?r([n[0],n[1],n.length>2?n[2]+90:90]):(n=r(),[n[0],n[1],n[2]-90])},r([0,0,90]).scale(159.155)}function _V(t,e){return t.parent===e.parent?1:2}function vV(t){return t.reduce(xV,0)/t.length}function xV(t,e){return t+e.x}function kV(t){return 1+t.reduce(wV,0)}function wV(t,e){return Math.max(t,e.y)}function TV(t){for(var e;e=t.children;)t=e[0];return t}function EV(t){for(var e;e=t.children;)t=e[e.length-1];return t}function CV(){var t=_V,e=1,r=1,n=!1;function i(a){var s,o=0;a.eachAfter(function(f){var p=f.children;p?(f.x=vV(p),f.y=kV(p)):(f.x=s?o+=t(f,s):0,f.y=0,s=f)});var l=TV(a),u=EV(a),h=l.x-t(l,u)/2,d=u.x+t(u,l)/2;return a.eachAfter(n?function(f){f.x=(f.x-a.x)*e,f.y=(a.y-f.y)*r}:function(f){f.x=(f.x-h)/(d-h)*e,f.y=(1-(a.y?f.y/a.y:1))*r})}return i.separation=function(a){return arguments.length?(t=a,i):t},i.size=function(a){return arguments.length?(n=!1,e=+a[0],r=+a[1],i):n?null:[e,r]},i.nodeSize=function(a){return arguments.length?(n=!0,e=+a[0],r=+a[1],i):n?[e,r]:null},i}function SV(t){var e=0,r=t.children,n=r&&r.length;if(!n)e=1;else for(;--n>=0;)e+=r[n].value;t.value=e}function AV(){return this.eachAfter(SV)}function MV(t,e){let r=-1;for(const n of this)t.call(e,n,++r,this);return this}function LV(t,e){for(var r=this,n=[r],i,a,s=-1;r=n.pop();)if(t.call(e,r,++s,this),i=r.children)for(a=i.length-1;a>=0;--a)n.push(i[a]);return this}function RV(t,e){for(var r=this,n=[r],i=[],a,s,o,l=-1;r=n.pop();)if(i.push(r),a=r.children)for(s=0,o=a.length;s<o;++s)n.push(a[s]);for(;r=i.pop();)t.call(e,r,++l,this);return this}function IV(t,e){let r=-1;for(const n of this)if(t.call(e,n,++r,this))return n}function NV(t){return this.eachAfter(function(e){for(var r=+t(e.data)||0,n=e.children,i=n&&n.length;--i>=0;)r+=n[i].value;e.value=r})}function BV(t){return this.eachBefore(function(e){e.children&&e.children.sort(t)})}function DV(t){for(var e=this,r=OV(e,t),n=[e];e!==r;)e=e.parent,n.push(e);for(var i=n.length;t!==r;)n.splice(i,0,t),t=t.parent;return n}function OV(t,e){if(t===e)return t;var r=t.ancestors(),n=e.ancestors(),i=null;for(t=r.pop(),e=n.pop();t===e;)i=t,t=r.pop(),e=n.pop();return i}function FV(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e}function PV(){return Array.from(this)}function qV(){var t=[];return this.eachBefore(function(e){e.children||t.push(e)}),t}function VV(){var t=this,e=[];return t.each(function(r){r!==t&&e.push({source:r.parent,target:r})}),e}function*zV(){var t=this,e,r=[t],n,i,a;do for(e=r.reverse(),r=[];t=e.pop();)if(yield t,n=t.children)for(i=0,a=n.length;i<a;++i)r.push(n[i]);while(r.length)}function G2(t,e){t instanceof Map?(t=[void 0,t],e===void 0&&(e=WV)):e===void 0&&(e=UV);for(var r=new Ms(t),n,i=[r],a,s,o,l;n=i.pop();)if((s=e(n.data))&&(l=(s=Array.from(s)).length))for(n.children=s,o=l-1;o>=0;--o)i.push(a=s[o]=new Ms(s[o])),a.parent=n,a.depth=n.depth+1;return r.eachBefore(yx)}function YV(){return G2(this).eachBefore(HV)}function UV(t){return t.children}function WV(t){return Array.isArray(t)?t[1]:null}function HV(t){t.data.value!==void 0&&(t.value=t.data.value),t.data=t.data.data}function yx(t){var e=0;do t.height=e;while((t=t.parent)&&t.height<++e)}function Ms(t){this.data=t,this.depth=this.height=0,this.parent=null}Ms.prototype=G2.prototype={constructor:Ms,count:AV,each:MV,eachAfter:RV,eachBefore:LV,find:IV,sum:NV,sort:BV,path:DV,ancestors:FV,descendants:PV,leaves:qV,links:VV,copy:YV,[Symbol.iterator]:zV};function Qh(t){return t==null?null:mx(t)}function mx(t){if(typeof t!="function")throw new Error;return t}function Ls(){return 0}function Bo(t){return function(){return t}}const GV=1664525,jV=1013904223,bx=4294967296;function j2(){let t=1;return()=>(t=(GV*t+jV)%bx)/bx}function $V(t){return typeof t=="object"&&"length"in t?t:Array.from(t)}function XV(t,e){let r=t.length,n,i;for(;r;)i=e()*r--|0,n=t[r],t[r]=t[i],t[i]=n;return t}function KV(t){return _x(t,j2())}function _x(t,e){for(var r=0,n=(t=XV(Array.from(t),e)).length,i=[],a,s;r<n;)a=t[r],s&&vx(s,a)?++r:(s=QV(i=ZV(i,a)),r=0);return s}function ZV(t,e){var r,n;if($2(e,t))return[e];for(r=0;r<t.length;++r)if(Jh(e,t[r])&&$2(uc(t[r],e),t))return[t[r],e];for(r=0;r<t.length-1;++r)for(n=r+1;n<t.length;++n)if(Jh(uc(t[r],t[n]),e)&&Jh(uc(t[r],e),t[n])&&Jh(uc(t[n],e),t[r])&&$2(xx(t[r],t[n],e),t))return[t[r],t[n],e];throw new Error}function Jh(t,e){var r=t.r-e.r,n=e.x-t.x,i=e.y-t.y;return r<0||r*r<n*n+i*i}function vx(t,e){var r=t.r-e.r+Math.max(t.r,e.r,1)*1e-9,n=e.x-t.x,i=e.y-t.y;return r>0&&r*r>n*n+i*i}function $2(t,e){for(var r=0;r<e.length;++r)if(!vx(t,e[r]))return!1;return!0}function QV(t){switch(t.length){case 1:return JV(t[0]);case 2:return uc(t[0],t[1]);case 3:return xx(t[0],t[1],t[2])}}function JV(t){return{x:t.x,y:t.y,r:t.r}}function uc(t,e){var r=t.x,n=t.y,i=t.r,a=e.x,s=e.y,o=e.r,l=a-r,u=s-n,h=o-i,d=Math.sqrt(l*l+u*u);return{x:(r+a+l/d*h)/2,y:(n+s+u/d*h)/2,r:(d+i+o)/2}}function xx(t,e,r){var n=t.x,i=t.y,a=t.r,s=e.x,o=e.y,l=e.r,u=r.x,h=r.y,d=r.r,f=n-s,p=n-u,m=i-o,_=i-h,y=l-a,b=d-a,x=n*n+i*i-a*a,k=x-s*s-o*o+l*l,T=x-u*u-h*h+d*d,C=p*m-f*_,M=(m*T-_*k)/(C*2)-n,S=(_*y-m*b)/C,R=(p*k-f*T)/(C*2)-i,A=(f*b-p*y)/C,L=S*S+A*A-1,v=2*(a+M*S+R*A),B=M*M+R*R-a*a,w=-(Math.abs(L)>1e-6?(v+Math.sqrt(v*v-4*L*B))/(2*L):B/v);return{x:n+M+S*w,y:i+R+A*w,r:w}}function kx(t,e,r){var n=t.x-e.x,i,a,s=t.y-e.y,o,l,u=n*n+s*s;u?(a=e.r+r.r,a*=a,l=t.r+r.r,l*=l,a>l?(i=(u+l-a)/(2*u),o=Math.sqrt(Math.max(0,l/u-i*i)),r.x=t.x-i*n-o*s,r.y=t.y-i*s+o*n):(i=(u+a-l)/(2*u),o=Math.sqrt(Math.max(0,a/u-i*i)),r.x=e.x+i*n-o*s,r.y=e.y+i*s+o*n)):(r.x=e.x+r.r,r.y=e.y)}function wx(t,e){var r=t.r+e.r-1e-6,n=e.x-t.x,i=e.y-t.y;return r>0&&r*r>n*n+i*i}function Tx(t){var e=t._,r=t.next._,n=e.r+r.r,i=(e.x*r.r+r.x*e.r)/n,a=(e.y*r.r+r.y*e.r)/n;return i*i+a*a}function tf(t){this._=t,this.next=null,this.previous=null}function Ex(t,e){if(!(a=(t=$V(t)).length))return 0;var r,n,i,a,s,o,l,u,h,d,f;if(r=t[0],r.x=0,r.y=0,!(a>1))return r.r;if(n=t[1],r.x=-n.r,n.x=r.r,n.y=0,!(a>2))return r.r+n.r;kx(n,r,i=t[2]),r=new tf(r),n=new tf(n),i=new tf(i),r.next=i.previous=n,n.next=r.previous=i,i.next=n.previous=r;t:for(l=3;l<a;++l){kx(r._,n._,i=t[l]),i=new tf(i),u=n.next,h=r.previous,d=n._.r,f=r._.r;do if(d<=f){if(wx(u._,i._)){n=u,r.next=n,n.previous=r,--l;continue t}d+=u._.r,u=u.next}else{if(wx(h._,i._)){r=h,r.next=n,n.previous=r,--l;continue t}f+=h._.r,h=h.previous}while(u!==h.next);for(i.previous=r,i.next=n,r.next=n.previous=n=i,s=Tx(r);(i=i.next)!==n;)(o=Tx(i))<s&&(r=i,s=o);n=r.next}for(r=[n._],i=n;(i=i.next)!==n;)r.push(i._);for(i=_x(r,e),l=0;l<a;++l)r=t[l],r.x-=i.x,r.y-=i.y;return i.r}function tz(t){return Ex(t,j2()),t}function ez(t){return Math.sqrt(t.value)}function rz(){var t=null,e=1,r=1,n=Ls;function i(a){const s=j2();return a.x=e/2,a.y=r/2,t?a.eachBefore(Cx(t)).eachAfter(X2(n,.5,s)).eachBefore(Sx(1)):a.eachBefore(Cx(ez)).eachAfter(X2(Ls,1,s)).eachAfter(X2(n,a.r/Math.min(e,r),s)).eachBefore(Sx(Math.min(e,r)/(2*a.r))),a}return i.radius=function(a){return arguments.length?(t=Qh(a),i):t},i.size=function(a){return arguments.length?(e=+a[0],r=+a[1],i):[e,r]},i.padding=function(a){return arguments.length?(n=typeof a=="function"?a:Bo(+a),i):n},i}function Cx(t){return function(e){e.children||(e.r=Math.max(0,+t(e)||0))}}function X2(t,e,r){return function(n){if(i=n.children){var i,a,s=i.length,o=t(n)*e||0,l;if(o)for(a=0;a<s;++a)i[a].r+=o;if(l=Ex(i,r),o)for(a=0;a<s;++a)i[a].r-=o;n.r=l+o}}}function Sx(t){return function(e){var r=e.parent;e.r*=t,r&&(e.x=r.x+t*e.x,e.y=r.y+t*e.y)}}function Ax(t){t.x0=Math.round(t.x0),t.y0=Math.round(t.y0),t.x1=Math.round(t.x1),t.y1=Math.round(t.y1)}function hc(t,e,r,n,i){for(var a=t.children,s,o=-1,l=a.length,u=t.value&&(n-e)/t.value;++o<l;)s=a[o],s.y0=r,s.y1=i,s.x0=e,s.x1=e+=s.value*u}function nz(){var t=1,e=1,r=0,n=!1;function i(s){var o=s.height+1;return s.x0=s.y0=r,s.x1=t,s.y1=e/o,s.eachBefore(a(e,o)),n&&s.eachBefore(Ax),s}function a(s,o){return function(l){l.children&&hc(l,l.x0,s*(l.depth+1)/o,l.x1,s*(l.depth+2)/o);var u=l.x0,h=l.y0,d=l.x1-r,f=l.y1-r;d<u&&(u=d=(u+d)/2),f<h&&(h=f=(h+f)/2),l.x0=u,l.y0=h,l.x1=d,l.y1=f}}return i.round=function(s){return arguments.length?(n=!!s,i):n},i.size=function(s){return arguments.length?(t=+s[0],e=+s[1],i):[t,e]},i.padding=function(s){return arguments.length?(r=+s,i):r},i}var iz={depth:-1},Mx={},K2={};function az(t){return t.id}function sz(t){return t.parentId}function oz(){var t=az,e=sz,r;function n(i){var a=Array.from(i),s=t,o=e,l,u,h,d,f,p,m,_,y=new Map;if(r!=null){const b=a.map((T,C)=>lz(r(T,C,i))),x=b.map(Lx),k=new Set(b).add("");for(const T of x)k.has(T)||(k.add(T),b.push(T),x.push(Lx(T)),a.push(K2));s=(T,C)=>b[C],o=(T,C)=>x[C]}for(h=0,l=a.length;h<l;++h)u=a[h],p=a[h]=new Ms(u),(m=s(u,h,i))!=null&&(m+="")&&(_=p.id=m,y.set(_,y.has(_)?Mx:p)),(m=o(u,h,i))!=null&&(m+="")&&(p.parent=m);for(h=0;h<l;++h)if(p=a[h],m=p.parent){if(f=y.get(m),!f)throw new Error("missing: "+m);if(f===Mx)throw new Error("ambiguous: "+m);f.children?f.children.push(p):f.children=[p],p.parent=f}else{if(d)throw new Error("multiple roots");d=p}if(!d)throw new Error("no root");if(r!=null){for(;d.data===K2&&d.children.length===1;)d=d.children[0],--l;for(let b=a.length-1;b>=0&&(p=a[b],p.data===K2);--b)p.data=null}if(d.parent=iz,d.eachBefore(function(b){b.depth=b.parent.depth+1,--l}).eachBefore(yx),d.parent=null,l>0)throw new Error("cycle");return d}return n.id=function(i){return arguments.length?(t=Qh(i),n):t},n.parentId=function(i){return arguments.length?(e=Qh(i),n):e},n.path=function(i){return arguments.length?(r=Qh(i),n):r},n}function lz(t){t=`${t}`;let e=t.length;return Z2(t,e-1)&&!Z2(t,e-2)&&(t=t.slice(0,-1)),t[0]==="/"?t:`/${t}`}function Lx(t){let e=t.length;if(e<2)return"";for(;--e>1&&!Z2(t,e););return t.slice(0,e)}function Z2(t,e){if(t[e]==="/"){let r=0;for(;e>0&&t[--e]==="\\";)++r;if((r&1)===0)return!0}return!1}function cz(t,e){return t.parent===e.parent?1:2}function Q2(t){var e=t.children;return e?e[0]:t.t}function J2(t){var e=t.children;return e?e[e.length-1]:t.t}function uz(t,e,r){var n=r/(e.i-t.i);e.c-=n,e.s+=r,t.c+=n,e.z+=r,e.m+=r}function hz(t){for(var e=0,r=0,n=t.children,i=n.length,a;--i>=0;)a=n[i],a.z+=e,a.m+=e,e+=a.s+(r+=a.c)}function fz(t,e,r){return t.a.parent===e.parent?t.a:r}function ef(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}ef.prototype=Object.create(Ms.prototype);function dz(t){for(var e=new ef(t,0),r,n=[e],i,a,s,o;r=n.pop();)if(a=r._.children)for(r.children=new Array(o=a.length),s=o-1;s>=0;--s)n.push(i=r.children[s]=new ef(a[s],s)),i.parent=r;return(e.parent=new ef(null,0)).children=[e],e}function pz(){var t=cz,e=1,r=1,n=null;function i(u){var h=dz(u);if(h.eachAfter(a),h.parent.m=-h.z,h.eachBefore(s),n)u.eachBefore(l);else{var d=u,f=u,p=u;u.eachBefore(function(x){x.x<d.x&&(d=x),x.x>f.x&&(f=x),x.depth>p.depth&&(p=x)});var m=d===f?1:t(d,f)/2,_=m-d.x,y=e/(f.x+m+_),b=r/(p.depth||1);u.eachBefore(function(x){x.x=(x.x+_)*y,x.y=x.depth*b})}return u}function a(u){var h=u.children,d=u.parent.children,f=u.i?d[u.i-1]:null;if(h){hz(u);var p=(h[0].z+h[h.length-1].z)/2;f?(u.z=f.z+t(u._,f._),u.m=u.z-p):u.z=p}else f&&(u.z=f.z+t(u._,f._));u.parent.A=o(u,f,u.parent.A||d[0])}function s(u){u._.x=u.z+u.parent.m,u.m+=u.parent.m}function o(u,h,d){if(h){for(var f=u,p=u,m=h,_=f.parent.children[0],y=f.m,b=p.m,x=m.m,k=_.m,T;m=J2(m),f=Q2(f),m&&f;)_=Q2(_),p=J2(p),p.a=u,T=m.z+x-f.z-y+t(m._,f._),T>0&&(uz(fz(m,u,d),u,T),y+=T,b+=T),x+=m.m,y+=f.m,k+=_.m,b+=p.m;m&&!J2(p)&&(p.t=m,p.m+=x-b),f&&!Q2(_)&&(_.t=f,_.m+=y-k,d=u)}return d}function l(u){u.x*=e,u.y=u.depth*r}return i.separation=function(u){return arguments.length?(t=u,i):t},i.size=function(u){return arguments.length?(n=!1,e=+u[0],r=+u[1],i):n?null:[e,r]},i.nodeSize=function(u){return arguments.length?(n=!0,e=+u[0],r=+u[1],i):n?[e,r]:null},i}function rf(t,e,r,n,i){for(var a=t.children,s,o=-1,l=a.length,u=t.value&&(i-r)/t.value;++o<l;)s=a[o],s.x0=e,s.x1=n,s.y0=r,s.y1=r+=s.value*u}var Rx=(1+Math.sqrt(5))/2;function Ix(t,e,r,n,i,a){for(var s=[],o=e.children,l,u,h=0,d=0,f=o.length,p,m,_=e.value,y,b,x,k,T,C,M;h<f;){p=i-r,m=a-n;do y=o[d++].value;while(!y&&d<f);for(b=x=y,C=Math.max(m/p,p/m)/(_*t),M=y*y*C,T=Math.max(x/M,M/b);d<f;++d){if(y+=u=o[d].value,u<b&&(b=u),u>x&&(x=u),M=y*y*C,k=Math.max(x/M,M/b),k>T){y-=u;break}T=k}s.push(l={value:y,dice:p<m,children:o.slice(h,d)}),l.dice?hc(l,r,n,i,_?n+=m*y/_:a):rf(l,r,n,_?r+=p*y/_:i,a),_-=y,h=d}return s}const Nx=function t(e){function r(n,i,a,s,o){Ix(e,n,i,a,s,o)}return r.ratio=function(n){return t((n=+n)>1?n:1)},r}(Rx);function gz(){var t=Nx,e=!1,r=1,n=1,i=[0],a=Ls,s=Ls,o=Ls,l=Ls,u=Ls;function h(f){return f.x0=f.y0=0,f.x1=r,f.y1=n,f.eachBefore(d),i=[0],e&&f.eachBefore(Ax),f}function d(f){var p=i[f.depth],m=f.x0+p,_=f.y0+p,y=f.x1-p,b=f.y1-p;y<m&&(m=y=(m+y)/2),b<_&&(_=b=(_+b)/2),f.x0=m,f.y0=_,f.x1=y,f.y1=b,f.children&&(p=i[f.depth+1]=a(f)/2,m+=u(f)-p,_+=s(f)-p,y-=o(f)-p,b-=l(f)-p,y<m&&(m=y=(m+y)/2),b<_&&(_=b=(_+b)/2),t(f,m,_,y,b))}return h.round=function(f){return arguments.length?(e=!!f,h):e},h.size=function(f){return arguments.length?(r=+f[0],n=+f[1],h):[r,n]},h.tile=function(f){return arguments.length?(t=mx(f),h):t},h.padding=function(f){return arguments.length?h.paddingInner(f).paddingOuter(f):h.paddingInner()},h.paddingInner=function(f){return arguments.length?(a=typeof f=="function"?f:Bo(+f),h):a},h.paddingOuter=function(f){return arguments.length?h.paddingTop(f).paddingRight(f).paddingBottom(f).paddingLeft(f):h.paddingTop()},h.paddingTop=function(f){return arguments.length?(s=typeof f=="function"?f:Bo(+f),h):s},h.paddingRight=function(f){return arguments.length?(o=typeof f=="function"?f:Bo(+f),h):o},h.paddingBottom=function(f){return arguments.length?(l=typeof f=="function"?f:Bo(+f),h):l},h.paddingLeft=function(f){return arguments.length?(u=typeof f=="function"?f:Bo(+f),h):u},h}function yz(t,e,r,n,i){var a=t.children,s,o=a.length,l,u=new Array(o+1);for(u[0]=l=s=0;s<o;++s)u[s+1]=l+=a[s].value;h(0,o,t.value,e,r,n,i);function h(d,f,p,m,_,y,b){if(d>=f-1){var x=a[d];x.x0=m,x.y0=_,x.x1=y,x.y1=b;return}for(var k=u[d],T=p/2+k,C=d+1,M=f-1;C<M;){var S=C+M>>>1;u[S]<T?C=S+1:M=S}T-u[C-1]<u[C]-T&&d+1<C&&--C;var R=u[C]-k,A=p-R;if(y-m>b-_){var L=p?(m*A+y*R)/p:y;h(d,C,R,m,_,L,b),h(C,f,A,L,_,y,b)}else{var v=p?(_*A+b*R)/p:b;h(d,C,R,m,_,y,v),h(C,f,A,m,v,y,b)}}}function mz(t,e,r,n,i){(t.depth&1?rf:hc)(t,e,r,n,i)}const bz=function t(e){function r(n,i,a,s,o){if((l=n._squarify)&&l.ratio===e)for(var l,u,h,d,f=-1,p,m=l.length,_=n.value;++f<m;){for(u=l[f],h=u.children,d=u.value=0,p=h.length;d<p;++d)u.value+=h[d].value;u.dice?hc(u,i,a,s,_?a+=(o-a)*u.value/_:o):rf(u,i,a,_?i+=(s-i)*u.value/_:s,o),_-=u.value}else n._squarify=l=Ix(e,n,i,a,s,o),l.ratio=e}return r.ratio=function(n){return t((n=+n)>1?n:1)},r}(Rx);function _z(t){for(var e=-1,r=t.length,n,i=t[r-1],a=0;++e<r;)n=i,i=t[e],a+=n[1]*i[0]-n[0]*i[1];return a/2}function vz(t){for(var e=-1,r=t.length,n=0,i=0,a,s=t[r-1],o,l=0;++e<r;)a=s,s=t[e],l+=o=a[0]*s[1]-s[0]*a[1],n+=(a[0]+s[0])*o,i+=(a[1]+s[1])*o;return l*=3,[n/l,i/l]}function xz(t,e,r){return(e[0]-t[0])*(r[1]-t[1])-(e[1]-t[1])*(r[0]-t[0])}function kz(t,e){return t[0]-e[0]||t[1]-e[1]}function Bx(t){const e=t.length,r=[0,1];let n=2,i;for(i=2;i<e;++i){for(;n>1&&xz(t[r[n-2]],t[r[n-1]],t[i])<=0;)--n;r[n++]=i}return r.slice(0,n)}function wz(t){if((r=t.length)<3)return null;var e,r,n=new Array(r),i=new Array(r);for(e=0;e<r;++e)n[e]=[+t[e][0],+t[e][1],e];for(n.sort(kz),e=0;e<r;++e)i[e]=[n[e][0],-n[e][1]];var a=Bx(n),s=Bx(i),o=s[0]===a[0],l=s[s.length-1]===a[a.length-1],u=[];for(e=a.length-1;e>=0;--e)u.push(t[n[a[e]][2]]);for(e=+o;e<s.length-l;++e)u.push(t[n[s[e]][2]]);return u}function Tz(t,e){for(var r=t.length,n=t[r-1],i=e[0],a=e[1],s=n[0],o=n[1],l,u,h=!1,d=0;d<r;++d)n=t[d],l=n[0],u=n[1],u>a!=o>a&&i<(s-l)*(a-u)/(o-u)+l&&(h=!h),s=l,o=u;return h}function Ez(t){for(var e=-1,r=t.length,n=t[r-1],i,a,s=n[0],o=n[1],l=0;++e<r;)i=s,a=o,n=t[e],s=n[0],o=n[1],i-=s,a-=o,l+=Math.hypot(i,a);return l}const Ir=Math.random,Cz=function t(e){function r(n,i){return n=n==null?0:+n,i=i==null?1:+i,arguments.length===1?(i=n,n=0):i-=n,function(){return e()*i+n}}return r.source=t,r}(Ir),Sz=function t(e){function r(n,i){return arguments.length<2&&(i=n,n=0),n=Math.floor(n),i=Math.floor(i)-n,function(){return Math.floor(e()*i+n)}}return r.source=t,r}(Ir),tp=function t(e){function r(n,i){var a,s;return n=n==null?0:+n,i=i==null?1:+i,function(){var o;if(a!=null)o=a,a=null;else do a=e()*2-1,o=e()*2-1,s=a*a+o*o;while(!s||s>1);return n+i*o*Math.sqrt(-2*Math.log(s)/s)}}return r.source=t,r}(Ir),Az=function t(e){var r=tp.source(e);function n(){var i=r.apply(this,arguments);return function(){return Math.exp(i())}}return n.source=t,n}(Ir),Dx=function t(e){function r(n){return(n=+n)<=0?()=>0:function(){for(var i=0,a=n;a>1;--a)i+=e();return i+a*e()}}return r.source=t,r}(Ir),Mz=function t(e){var r=Dx.source(e);function n(i){if((i=+i)==0)return e;var a=r(i);return function(){return a()/i}}return n.source=t,n}(Ir),Lz=function t(e){function r(n){return function(){return-Math.log1p(-e())/n}}return r.source=t,r}(Ir),Rz=function t(e){function r(n){if((n=+n)<0)throw new RangeError("invalid alpha");return n=1/-n,function(){return Math.pow(1-e(),n)}}return r.source=t,r}(Ir),Iz=function t(e){function r(n){if((n=+n)<0||n>1)throw new RangeError("invalid p");return function(){return Math.floor(e()+n)}}return r.source=t,r}(Ir),Ox=function t(e){function r(n){if((n=+n)<0||n>1)throw new RangeError("invalid p");return n===0?()=>1/0:n===1?()=>1:(n=Math.log1p(-n),function(){return 1+Math.floor(Math.log1p(-e())/n)})}return r.source=t,r}(Ir),ep=function t(e){var r=tp.source(e)();function n(i,a){if((i=+i)<0)throw new RangeError("invalid k");if(i===0)return()=>0;if(a=a==null?1:+a,i===1)return()=>-Math.log1p(-e())*a;var s=(i<1?i+1:i)-1/3,o=1/(3*Math.sqrt(s)),l=i<1?()=>Math.pow(e(),1/i):()=>1;return function(){do{do var u=r(),h=1+o*u;while(h<=0);h*=h*h;var d=1-e()}while(d>=1-.0331*u*u*u*u&&Math.log(d)>=.5*u*u+s*(1-h+Math.log(h)));return s*h*l()*a}}return n.source=t,n}(Ir),Fx=function t(e){var r=ep.source(e);function n(i,a){var s=r(i),o=r(a);return function(){var l=s();return l===0?0:l/(l+o())}}return n.source=t,n}(Ir),Px=function t(e){var r=Ox.source(e),n=Fx.source(e);function i(a,s){return a=+a,(s=+s)>=1?()=>a:s<=0?()=>0:function(){for(var o=0,l=a,u=s;l*u>16&&l*(1-u)>16;){var h=Math.floor((l+1)*u),d=n(h,l-h+1)();d<=u?(o+=h,l-=h,u=(u-d)/(1-d)):(l=h-1,u/=d)}for(var f=u<.5,p=f?u:1-u,m=r(p),_=m(),y=0;_<=l;++y)_+=m();return o+(f?y:l-y)}}return i.source=t,i}(Ir),Nz=function t(e){function r(n,i,a){var s;return(n=+n)==0?s=o=>-Math.log(o):(n=1/n,s=o=>Math.pow(o,n)),i=i==null?0:+i,a=a==null?1:+a,function(){return i+a*s(-Math.log1p(-e()))}}return r.source=t,r}(Ir),Bz=function t(e){function r(n,i){return n=n==null?0:+n,i=i==null?1:+i,function(){return n+i*Math.tan(Math.PI*e())}}return r.source=t,r}(Ir),Dz=function t(e){function r(n,i){return n=n==null?0:+n,i=i==null?1:+i,function(){var a=e();return n+i*Math.log(a/(1-a))}}return r.source=t,r}(Ir),Oz=function t(e){var r=ep.source(e),n=Px.source(e);function i(a){return function(){for(var s=0,o=a;o>16;){var l=Math.floor(.875*o),u=r(l)();if(u>o)return s+n(l-1,o/u)();s+=l,o-=u}for(var h=-Math.log1p(-e()),d=0;h<=o;++d)h-=Math.log1p(-e());return s+d}}return i.source=t,i}(Ir),Fz=1664525,Pz=1013904223,qx=1/4294967296;function qz(t=Math.random()){let e=(0<=t&&t<1?t/qx:Math.abs(t))|0;return()=>(e=Fz*e+Pz|0,qx*(e>>>0))}function On(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t);break}return this}function ta(t,e){switch(arguments.length){case 0:break;case 1:{typeof t=="function"?this.interpolator(t):this.range(t);break}default:{this.domain(t),typeof e=="function"?this.interpolator(e):this.range(e);break}}return this}const rp=Symbol("implicit");function nf(){var t=new kl,e=[],r=[],n=rp;function i(a){let s=t.get(a);if(s===void 0){if(n!==rp)return n;t.set(a,s=e.push(a)-1)}return r[s%r.length]}return i.domain=function(a){if(!arguments.length)return e.slice();e=[],t=new kl;for(const s of a)t.has(s)||t.set(s,e.push(s)-1);return i},i.range=function(a){return arguments.length?(r=Array.from(a),i):r.slice()},i.unknown=function(a){return arguments.length?(n=a,i):n},i.copy=function(){return nf(e,r).unknown(n)},On.apply(i,arguments),i}function np(){var t=nf().unknown(void 0),e=t.domain,r=t.range,n=0,i=1,a,s,o=!1,l=0,u=0,h=.5;delete t.unknown;function d(){var f=e().length,p=i<n,m=p?i:n,_=p?n:i;a=(_-m)/Math.max(1,f-l+u*2),o&&(a=Math.floor(a)),m+=(_-m-a*(f-l))*h,s=a*(1-l),o&&(m=Math.round(m),s=Math.round(s));var y=Ca(f).map(function(b){return m+a*b});return r(p?y.reverse():y)}return t.domain=function(f){return arguments.length?(e(f),d()):e()},t.range=function(f){return arguments.length?([n,i]=f,n=+n,i=+i,d()):[n,i]},t.rangeRound=function(f){return[n,i]=f,n=+n,i=+i,o=!0,d()},t.bandwidth=function(){return s},t.step=function(){return a},t.round=function(f){return arguments.length?(o=!!f,d()):o},t.padding=function(f){return arguments.length?(l=Math.min(1,u=+f),d()):l},t.paddingInner=function(f){return arguments.length?(l=Math.min(1,f),d()):l},t.paddingOuter=function(f){return arguments.length?(u=+f,d()):u},t.align=function(f){return arguments.length?(h=Math.max(0,Math.min(1,f)),d()):h},t.copy=function(){return np(e(),[n,i]).round(o).paddingInner(l).paddingOuter(u).align(h)},On.apply(d(),arguments)}function Vx(t){var e=t.copy;return t.padding=t.paddingOuter,delete t.paddingInner,delete t.paddingOuter,t.copy=function(){return Vx(e())},t}function Vz(){return Vx(np.apply(null,arguments).paddingInner(1))}function zz(t){return function(){return t}}function af(t){return+t}var zx=[0,1];function an(t){return t}function ip(t,e){return(e-=t=+t)?function(r){return(r-t)/e}:zz(isNaN(e)?NaN:.5)}function Yz(t,e){var r;return t>e&&(r=t,t=e,e=r),function(n){return Math.max(t,Math.min(e,n))}}function Uz(t,e,r){var n=t[0],i=t[1],a=e[0],s=e[1];return i<n?(n=ip(i,n),a=r(s,a)):(n=ip(n,i),a=r(a,s)),function(o){return a(n(o))}}function Wz(t,e,r){var n=Math.min(t.length,e.length)-1,i=new Array(n),a=new Array(n),s=-1;for(t[n]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++s<n;)i[s]=ip(t[s],t[s+1]),a[s]=r(e[s],e[s+1]);return function(o){var l=cs(t,o,1,n)-1;return a[l](i[l](o))}}function fc(t,e){return e.domain(t.domain()).range(t.range()).interpolate(t.interpolate()).clamp(t.clamp()).unknown(t.unknown())}function sf(){var t=zx,e=zx,r=Ma,n,i,a,s=an,o,l,u;function h(){var f=Math.min(t.length,e.length);return s!==an&&(s=Yz(t[0],t[f-1])),o=f>2?Wz:Uz,l=u=null,d}function d(f){return f==null||isNaN(f=+f)?a:(l||(l=o(t.map(n),e,r)))(n(s(f)))}return d.invert=function(f){return s(i((u||(u=o(e,t.map(n),Bn)))(f)))},d.domain=function(f){return arguments.length?(t=Array.from(f,af),h()):t.slice()},d.range=function(f){return arguments.length?(e=Array.from(f),h()):e.slice()},d.rangeRound=function(f){return e=Array.from(f),r=ju,h()},d.clamp=function(f){return arguments.length?(s=f?!0:an,h()):s!==an},d.interpolate=function(f){return arguments.length?(r=f,h()):r},d.unknown=function(f){return arguments.length?(a=f,d):a},function(f,p){return n=f,i=p,h()}}function ap(){return sf()(an,an)}function Yx(t,e,r,n){var i=wl(t,e,r),a;switch(n=Co(n==null?",f":n),n.type){case"s":{var s=Math.max(Math.abs(t),Math.abs(e));return n.precision==null&&!isNaN(a=Jv(i,s))&&(n.precision=a),Jd(n,s)}case"":case"e":case"g":case"p":case"r":{n.precision==null&&!isNaN(a=t6(i,Math.max(Math.abs(t),Math.abs(e))))&&(n.precision=a-(n.type==="e"));break}case"f":case"%":{n.precision==null&&!isNaN(a=Qv(i))&&(n.precision=a-(n.type==="%")*2);break}}return yh(n)}function Oa(t){var e=t.domain;return t.ticks=function(r){var n=e();return hs(n[0],n[n.length-1],r==null?10:r)},t.tickFormat=function(r,n){var i=e();return Yx(i[0],i[i.length-1],r==null?10:r,n)},t.nice=function(r){r==null&&(r=10);var n=e(),i=0,a=n.length-1,s=n[i],o=n[a],l,u,h=10;for(o<s&&(u=s,s=o,o=u,u=i,i=a,a=u);h-- >0;){if(u=oo(s,o,r),u===l)return n[i]=s,n[a]=o,e(n);if(u>0)s=Math.floor(s/u)*u,o=Math.ceil(o/u)*u;else if(u<0)s=Math.ceil(s*u)/u,o=Math.floor(o*u)/u;else break;l=u}return t},t}function sp(){var t=ap();return t.copy=function(){return fc(t,sp())},On.apply(t,arguments),Oa(t)}function Ux(t){var e;function r(n){return n==null||isNaN(n=+n)?e:n}return r.invert=r,r.domain=r.range=function(n){return arguments.length?(t=Array.from(n,af),r):t.slice()},r.unknown=function(n){return arguments.length?(e=n,r):e},r.copy=function(){return Ux(t).unknown(e)},t=arguments.length?Array.from(t,af):[0,1],Oa(r)}function Wx(t,e){t=t.slice();var r=0,n=t.length-1,i=t[r],a=t[n],s;return a<i&&(s=r,r=n,n=s,s=i,i=a,a=s),t[r]=e.floor(i),t[n]=e.ceil(a),t}function Hx(t){return Math.log(t)}function Gx(t){return Math.exp(t)}function Hz(t){return-Math.log(-t)}function Gz(t){return-Math.exp(-t)}function jz(t){return isFinite(t)?+("1e"+t):t<0?0:t}function $z(t){return t===10?jz:t===Math.E?Math.exp:e=>Math.pow(t,e)}function Xz(t){return t===Math.E?Math.log:t===10&&Math.log10||t===2&&Math.log2||(t=Math.log(t),e=>Math.log(e)/t)}function jx(t){return(e,r)=>-t(-e,r)}function op(t){const e=t(Hx,Gx),r=e.domain;let n=10,i,a;function s(){return i=Xz(n),a=$z(n),r()[0]<0?(i=jx(i),a=jx(a),t(Hz,Gz)):t(Hx,Gx),e}return e.base=function(o){return arguments.length?(n=+o,s()):n},e.domain=function(o){return arguments.length?(r(o),s()):r()},e.ticks=o=>{const l=r();let u=l[0],h=l[l.length-1];const d=h<u;d&&([u,h]=[h,u]);let f=i(u),p=i(h),m,_;const y=o==null?10:+o;let b=[];if(!(n%1)&&p-f<y){if(f=Math.floor(f),p=Math.ceil(p),u>0){for(;f<=p;++f)for(m=1;m<n;++m)if(_=f<0?m/a(-f):m*a(f),!(_<u)){if(_>h)break;b.push(_)}}else for(;f<=p;++f)for(m=n-1;m>=1;--m)if(_=f>0?m/a(-f):m*a(f),!(_<u)){if(_>h)break;b.push(_)}b.length*2<y&&(b=hs(u,h,y))}else b=hs(f,p,Math.min(p-f,y)).map(a);return d?b.reverse():b},e.tickFormat=(o,l)=>{if(o==null&&(o=10),l==null&&(l=n===10?"s":","),typeof l!="function"&&(!(n%1)&&(l=Co(l)).precision==null&&(l.trim=!0),l=yh(l)),o===1/0)return l;const u=Math.max(1,n*o/e.ticks().length);return h=>{let d=h/a(Math.round(i(h)));return d*n<n-.5&&(d*=n),d<=u?l(h):""}},e.nice=()=>r(Wx(r(),{floor:o=>a(Math.floor(i(o))),ceil:o=>a(Math.ceil(i(o)))})),e}function $x(){const t=op(sf()).domain([1,10]);return t.copy=()=>fc(t,$x()).base(t.base()),On.apply(t,arguments),t}function Xx(t){return function(e){return Math.sign(e)*Math.log1p(Math.abs(e/t))}}function Kx(t){return function(e){return Math.sign(e)*Math.expm1(Math.abs(e))*t}}function lp(t){var e=1,r=t(Xx(e),Kx(e));return r.constant=function(n){return arguments.length?t(Xx(e=+n),Kx(e)):e},Oa(r)}function Zx(){var t=lp(sf());return t.copy=function(){return fc(t,Zx()).constant(t.constant())},On.apply(t,arguments)}function Qx(t){return function(e){return e<0?-Math.pow(-e,t):Math.pow(e,t)}}function Kz(t){return t<0?-Math.sqrt(-t):Math.sqrt(t)}function Zz(t){return t<0?-t*t:t*t}function cp(t){var e=t(an,an),r=1;function n(){return r===1?t(an,an):r===.5?t(Kz,Zz):t(Qx(r),Qx(1/r))}return e.exponent=function(i){return arguments.length?(r=+i,n()):r},Oa(e)}function up(){var t=cp(sf());return t.copy=function(){return fc(t,up()).exponent(t.exponent())},On.apply(t,arguments),t}function Qz(){return up.apply(null,arguments).exponent(.5)}function Jx(t){return Math.sign(t)*t*t}function Jz(t){return Math.sign(t)*Math.sqrt(Math.abs(t))}function t8(){var t=ap(),e=[0,1],r=!1,n;function i(a){var s=Jz(t(a));return isNaN(s)?n:r?Math.round(s):s}return i.invert=function(a){return t.invert(Jx(a))},i.domain=function(a){return arguments.length?(t.domain(a),i):t.domain()},i.range=function(a){return arguments.length?(t.range((e=Array.from(a,af)).map(Jx)),i):e.slice()},i.rangeRound=function(a){return i.range(a).round(!0)},i.round=function(a){return arguments.length?(r=!!a,i):r},i.clamp=function(a){return arguments.length?(t.clamp(a),i):t.clamp()},i.unknown=function(a){return arguments.length?(n=a,i):n},i.copy=function(){return t8(t.domain(),e).round(r).clamp(t.clamp()).unknown(n)},On.apply(i,arguments),Oa(i)}function e8(){var t=[],e=[],r=[],n;function i(){var s=0,o=Math.max(1,e.length);for(r=new Array(o-1);++s<o;)r[s-1]=q_(t,s/o);return a}function a(s){return s==null||isNaN(s=+s)?n:e[cs(r,s)]}return a.invertExtent=function(s){var o=e.indexOf(s);return o<0?[NaN,NaN]:[o>0?r[o-1]:t[0],o<r.length?r[o]:t[t.length-1]]},a.domain=function(s){if(!arguments.length)return t.slice();t=[];for(let o of s)o!=null&&!isNaN(o=+o)&&t.push(o);return t.sort(Qe),i()},a.range=function(s){return arguments.length?(e=Array.from(s),i()):e.slice()},a.unknown=function(s){return arguments.length?(n=s,a):n},a.quantiles=function(){return r.slice()},a.copy=function(){return e8().domain(t).range(e).unknown(n)},On.apply(a,arguments)}function r8(){var t=0,e=1,r=1,n=[.5],i=[0,1],a;function s(l){return l!=null&&l<=l?i[cs(n,l,0,r)]:a}function o(){var l=-1;for(n=new Array(r);++l<r;)n[l]=((l+1)*e-(l-r)*t)/(r+1);return s}return s.domain=function(l){return arguments.length?([t,e]=l,t=+t,e=+e,o()):[t,e]},s.range=function(l){return arguments.length?(r=(i=Array.from(l)).length-1,o()):i.slice()},s.invertExtent=function(l){var u=i.indexOf(l);return u<0?[NaN,NaN]:u<1?[t,n[0]]:u>=r?[n[r-1],e]:[n[u-1],n[u]]},s.unknown=function(l){return arguments.length&&(a=l),s},s.thresholds=function(){return n.slice()},s.copy=function(){return r8().domain([t,e]).range(i).unknown(a)},On.apply(Oa(s),arguments)}function n8(){var t=[.5],e=[0,1],r,n=1;function i(a){return a!=null&&a<=a?e[cs(t,a,0,n)]:r}return i.domain=function(a){return arguments.length?(t=Array.from(a),n=Math.min(t.length,e.length-1),i):t.slice()},i.range=function(a){return arguments.length?(e=Array.from(a),n=Math.min(t.length,e.length-1),i):e.slice()},i.invertExtent=function(a){var s=e.indexOf(a);return[t[s-1],t[s]]},i.unknown=function(a){return arguments.length?(r=a,i):r},i.copy=function(){return n8().domain(t).range(e).unknown(r)},On.apply(i,arguments)}var hp=new Date,fp=new Date;function xr(t,e,r,n){function i(a){return t(a=arguments.length===0?new Date:new Date(+a)),a}return i.floor=function(a){return t(a=new Date(+a)),a},i.ceil=function(a){return t(a=new Date(a-1)),e(a,1),t(a),a},i.round=function(a){var s=i(a),o=i.ceil(a);return a-s<o-a?s:o},i.offset=function(a,s){return e(a=new Date(+a),s==null?1:Math.floor(s)),a},i.range=function(a,s,o){var l=[],u;if(a=i.ceil(a),o=o==null?1:Math.floor(o),!(a<s)||!(o>0))return l;do l.push(u=new Date(+a)),e(a,o),t(a);while(u<a&&a<s);return l},i.filter=function(a){return xr(function(s){if(s>=s)for(;t(s),!a(s);)s.setTime(s-1)},function(s,o){if(s>=s)if(o<0)for(;++o<=0;)for(;e(s,-1),!a(s););else for(;--o>=0;)for(;e(s,1),!a(s););})},r&&(i.count=function(a,s){return hp.setTime(+a),fp.setTime(+s),t(hp),t(fp),Math.floor(r(hp,fp))},i.every=function(a){return a=Math.floor(a),!isFinite(a)||!(a>0)?null:a>1?i.filter(n?function(s){return n(s)%a===0}:function(s){return i.count(0,s)%a===0}):i}),i}var of=xr(function(){},function(t,e){t.setTime(+t+e)},function(t,e){return e-t});of.every=function(t){return t=Math.floor(t),!isFinite(t)||!(t>0)?null:t>1?xr(function(e){e.setTime(Math.floor(e/t)*t)},function(e,r){e.setTime(+e+r*t)},function(e,r){return(r-e)/t}):of};const dp=of;var i8=of.range;const ea=1e3,Fn=ea*60,ra=Fn*60,Rs=ra*24,pp=Rs*7,a8=Rs*30,gp=Rs*365;var s8=xr(function(t){t.setTime(t-t.getMilliseconds())},function(t,e){t.setTime(+t+e*ea)},function(t,e){return(e-t)/ea},function(t){return t.getUTCSeconds()});const Fa=s8;var o8=s8.range,l8=xr(function(t){t.setTime(t-t.getMilliseconds()-t.getSeconds()*ea)},function(t,e){t.setTime(+t+e*Fn)},function(t,e){return(e-t)/Fn},function(t){return t.getMinutes()});const yp=l8;var tY=l8.range,c8=xr(function(t){t.setTime(t-t.getMilliseconds()-t.getSeconds()*ea-t.getMinutes()*Fn)},function(t,e){t.setTime(+t+e*ra)},function(t,e){return(e-t)/ra},function(t){return t.getHours()});const mp=c8;var eY=c8.range,u8=xr(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*Fn)/Rs,t=>t.getDate()-1);const dc=u8;var rY=u8.range;function Is(t){return xr(function(e){e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)},function(e,r){e.setDate(e.getDate()+r*7)},function(e,r){return(r-e-(r.getTimezoneOffset()-e.getTimezoneOffset())*Fn)/pp})}var Do=Is(0),pc=Is(1),h8=Is(2),f8=Is(3),Ns=Is(4),d8=Is(5),p8=Is(6),g8=Do.range,nY=pc.range,iY=h8.range,aY=f8.range,sY=Ns.range,oY=d8.range,lY=p8.range,y8=xr(function(t){t.setDate(1),t.setHours(0,0,0,0)},function(t,e){t.setMonth(t.getMonth()+e)},function(t,e){return e.getMonth()-t.getMonth()+(e.getFullYear()-t.getFullYear())*12},function(t){return t.getMonth()});const bp=y8;var cY=y8.range,_p=xr(function(t){t.setMonth(0,1),t.setHours(0,0,0,0)},function(t,e){t.setFullYear(t.getFullYear()+e)},function(t,e){return e.getFullYear()-t.getFullYear()},function(t){return t.getFullYear()});_p.every=function(t){return!isFinite(t=Math.floor(t))||!(t>0)?null:xr(function(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)},function(e,r){e.setFullYear(e.getFullYear()+r*t)})};const Pa=_p;var uY=_p.range,m8=xr(function(t){t.setUTCSeconds(0,0)},function(t,e){t.setTime(+t+e*Fn)},function(t,e){return(e-t)/Fn},function(t){return t.getUTCMinutes()});const vp=m8;var hY=m8.range,b8=xr(function(t){t.setUTCMinutes(0,0,0)},function(t,e){t.setTime(+t+e*ra)},function(t,e){return(e-t)/ra},function(t){return t.getUTCHours()});const xp=b8;var fY=b8.range,_8=xr(function(t){t.setUTCHours(0,0,0,0)},function(t,e){t.setUTCDate(t.getUTCDate()+e)},function(t,e){return(e-t)/Rs},function(t){return t.getUTCDate()-1});const gc=_8;var dY=_8.range;function Bs(t){return xr(function(e){e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)},function(e,r){e.setUTCDate(e.getUTCDate()+r*7)},function(e,r){return(r-e)/pp})}var Oo=Bs(0),yc=Bs(1),v8=Bs(2),x8=Bs(3),Ds=Bs(4),k8=Bs(5),w8=Bs(6),T8=Oo.range,pY=yc.range,gY=v8.range,yY=x8.range,mY=Ds.range,bY=k8.range,_Y=w8.range,E8=xr(function(t){t.setUTCDate(1),t.setUTCHours(0,0,0,0)},function(t,e){t.setUTCMonth(t.getUTCMonth()+e)},function(t,e){return e.getUTCMonth()-t.getUTCMonth()+(e.getUTCFullYear()-t.getUTCFullYear())*12},function(t){return t.getUTCMonth()});const kp=E8;var vY=E8.range,wp=xr(function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e)},function(t,e){return e.getUTCFullYear()-t.getUTCFullYear()},function(t){return t.getUTCFullYear()});wp.every=function(t){return!isFinite(t=Math.floor(t))||!(t>0)?null:xr(function(e){e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},function(e,r){e.setUTCFullYear(e.getUTCFullYear()+r*t)})};const qa=wp;var xY=wp.range;function C8(t,e,r,n,i,a){const s=[[Fa,1,ea],[Fa,5,5*ea],[Fa,15,15*ea],[Fa,30,30*ea],[a,1,Fn],[a,5,5*Fn],[a,15,15*Fn],[a,30,30*Fn],[i,1,ra],[i,3,3*ra],[i,6,6*ra],[i,12,12*ra],[n,1,Rs],[n,2,2*Rs],[r,1,pp],[e,1,a8],[e,3,3*a8],[t,1,gp]];function o(u,h,d){const f=h<u;f&&([u,h]=[h,u]);const p=d&&typeof d.range=="function"?d:l(u,h,d),m=p?p.range(u,+h+1):[];return f?m.reverse():m}function l(u,h,d){const f=Math.abs(h-u)/d,p=ku(([,,y])=>y).right(s,f);if(p===s.length)return t.every(wl(u/gp,h/gp,d));if(p===0)return dp.every(Math.max(wl(u,h,d),1));const[m,_]=s[f/s[p-1][2]<s[p][2]/f?p-1:p];return m.every(_)}return[o,l]}const[S8,A8]=C8(qa,kp,Oo,gc,xp,vp),[M8,L8]=C8(Pa,bp,Do,dc,mp,yp);function Tp(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function Ep(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function mc(t,e,r){return{y:t,m:e,d:r,H:0,M:0,S:0,L:0}}function R8(t){var e=t.dateTime,r=t.date,n=t.time,i=t.periods,a=t.days,s=t.shortDays,o=t.months,l=t.shortMonths,u=bc(i),h=_c(i),d=bc(a),f=_c(a),p=bc(s),m=_c(s),_=bc(o),y=_c(o),b=bc(l),x=_c(l),k={a:X,A:ct,b:J,B:Y,c:null,d:F8,e:F8,f:WY,g:tU,G:rU,H:zY,I:YY,j:UY,L:P8,m:HY,M:GY,p:$,q:lt,Q:W8,s:H8,S:jY,u:$Y,U:XY,V:KY,w:ZY,W:QY,x:null,X:null,y:JY,Y:eU,Z:nU,"%":U8},T={a:ut,A:W,b:tt,B:K,c:null,d:V8,e:V8,f:oU,g:mU,G:_U,H:iU,I:aU,j:sU,L:z8,m:lU,M:cU,p:it,q:Z,Q:W8,s:H8,S:uU,u:hU,U:fU,V:dU,w:pU,W:gU,x:null,X:null,y:yU,Y:bU,Z:vU,"%":U8},C={a:L,A:v,b:B,B:w,c:D,d:D8,e:D8,f:FY,g:B8,G:N8,H:O8,I:O8,j:NY,L:OY,m:IY,M:BY,p:A,q:RY,Q:qY,s:VY,S:DY,u:CY,U:SY,V:AY,w:EY,W:MY,x:N,X:z,y:B8,Y:N8,Z:LY,"%":PY};k.x=M(r,k),k.X=M(n,k),k.c=M(e,k),T.x=M(r,T),T.X=M(n,T),T.c=M(e,T);function M(V,Q){return function(q){var U=[],F=-1,j=0,P=V.length,et,at,It;for(q instanceof Date||(q=new Date(+q));++F<P;)V.charCodeAt(F)===37&&(U.push(V.slice(j,F)),(at=I8[et=V.charAt(++F)])!=null?et=V.charAt(++F):at=et==="e"?" ":"0",(It=Q[et])&&(et=It(q,at)),U.push(et),j=F+1);return U.push(V.slice(j,F)),U.join("")}}function S(V,Q){return function(q){var U=mc(1900,void 0,1),F=R(U,V,q+="",0),j,P;if(F!=q.length)return null;if("Q"in U)return new Date(U.Q);if("s"in U)return new Date(U.s*1e3+("L"in U?U.L:0));if(Q&&!("Z"in U)&&(U.Z=0),"p"in U&&(U.H=U.H%12+U.p*12),U.m===void 0&&(U.m="q"in U?U.q:0),"V"in U){if(U.V<1||U.V>53)return null;"w"in U||(U.w=1),"Z"in U?(j=Ep(mc(U.y,0,1)),P=j.getUTCDay(),j=P>4||P===0?yc.ceil(j):yc(j),j=gc.offset(j,(U.V-1)*7),U.y=j.getUTCFullYear(),U.m=j.getUTCMonth(),U.d=j.getUTCDate()+(U.w+6)%7):(j=Tp(mc(U.y,0,1)),P=j.getDay(),j=P>4||P===0?pc.ceil(j):pc(j),j=dc.offset(j,(U.V-1)*7),U.y=j.getFullYear(),U.m=j.getMonth(),U.d=j.getDate()+(U.w+6)%7)}else("W"in U||"U"in U)&&("w"in U||(U.w="u"in U?U.u%7:"W"in U?1:0),P="Z"in U?Ep(mc(U.y,0,1)).getUTCDay():Tp(mc(U.y,0,1)).getDay(),U.m=0,U.d="W"in U?(U.w+6)%7+U.W*7-(P+5)%7:U.w+U.U*7-(P+6)%7);return"Z"in U?(U.H+=U.Z/100|0,U.M+=U.Z%100,Ep(U)):Tp(U)}}function R(V,Q,q,U){for(var F=0,j=Q.length,P=q.length,et,at;F<j;){if(U>=P)return-1;if(et=Q.charCodeAt(F++),et===37){if(et=Q.charAt(F++),at=C[et in I8?Q.charAt(F++):et],!at||(U=at(V,q,U))<0)return-1}else if(et!=q.charCodeAt(U++))return-1}return U}function A(V,Q,q){var U=u.exec(Q.slice(q));return U?(V.p=h.get(U[0].toLowerCase()),q+U[0].length):-1}function L(V,Q,q){var U=p.exec(Q.slice(q));return U?(V.w=m.get(U[0].toLowerCase()),q+U[0].length):-1}function v(V,Q,q){var U=d.exec(Q.slice(q));return U?(V.w=f.get(U[0].toLowerCase()),q+U[0].length):-1}function B(V,Q,q){var U=b.exec(Q.slice(q));return U?(V.m=x.get(U[0].toLowerCase()),q+U[0].length):-1}function w(V,Q,q){var U=_.exec(Q.slice(q));return U?(V.m=y.get(U[0].toLowerCase()),q+U[0].length):-1}function D(V,Q,q){return R(V,e,Q,q)}function N(V,Q,q){return R(V,r,Q,q)}function z(V,Q,q){return R(V,n,Q,q)}function X(V){return s[V.getDay()]}function ct(V){return a[V.getDay()]}function J(V){return l[V.getMonth()]}function Y(V){return o[V.getMonth()]}function $(V){return i[+(V.getHours()>=12)]}function lt(V){return 1+~~(V.getMonth()/3)}function ut(V){return s[V.getUTCDay()]}function W(V){return a[V.getUTCDay()]}function tt(V){return l[V.getUTCMonth()]}function K(V){return o[V.getUTCMonth()]}function it(V){return i[+(V.getUTCHours()>=12)]}function Z(V){return 1+~~(V.getUTCMonth()/3)}return{format:function(V){var Q=M(V+="",k);return Q.toString=function(){return V},Q},parse:function(V){var Q=S(V+="",!1);return Q.toString=function(){return V},Q},utcFormat:function(V){var Q=M(V+="",T);return Q.toString=function(){return V},Q},utcParse:function(V){var Q=S(V+="",!0);return Q.toString=function(){return V},Q}}}var I8={"-":"",_:" ",0:"0"},Ar=/^\s*\d+/,kY=/^%/,wY=/[\\^$*+?|[\]().{}]/g;function Oe(t,e,r){var n=t<0?"-":"",i=(n?-t:t)+"",a=i.length;return n+(a<r?new Array(r-a+1).join(e)+i:i)}function TY(t){return t.replace(wY,"\\$&")}function bc(t){return new RegExp("^(?:"+t.map(TY).join("|")+")","i")}function _c(t){return new Map(t.map((e,r)=>[e.toLowerCase(),r]))}function EY(t,e,r){var n=Ar.exec(e.slice(r,r+1));return n?(t.w=+n[0],r+n[0].length):-1}function CY(t,e,r){var n=Ar.exec(e.slice(r,r+1));return n?(t.u=+n[0],r+n[0].length):-1}function SY(t,e,r){var n=Ar.exec(e.slice(r,r+2));return n?(t.U=+n[0],r+n[0].length):-1}function AY(t,e,r){var n=Ar.exec(e.slice(r,r+2));return n?(t.V=+n[0],r+n[0].length):-1}function MY(t,e,r){var n=Ar.exec(e.slice(r,r+2));return n?(t.W=+n[0],r+n[0].length):-1}function N8(t,e,r){var n=Ar.exec(e.slice(r,r+4));return n?(t.y=+n[0],r+n[0].length):-1}function B8(t,e,r){var n=Ar.exec(e.slice(r,r+2));return n?(t.y=+n[0]+(+n[0]>68?1900:2e3),r+n[0].length):-1}function LY(t,e,r){var n=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(r,r+6));return n?(t.Z=n[1]?0:-(n[2]+(n[3]||"00")),r+n[0].length):-1}function RY(t,e,r){var n=Ar.exec(e.slice(r,r+1));return n?(t.q=n[0]*3-3,r+n[0].length):-1}function IY(t,e,r){var n=Ar.exec(e.slice(r,r+2));return n?(t.m=n[0]-1,r+n[0].length):-1}function D8(t,e,r){var n=Ar.exec(e.slice(r,r+2));return n?(t.d=+n[0],r+n[0].length):-1}function NY(t,e,r){var n=Ar.exec(e.slice(r,r+3));return n?(t.m=0,t.d=+n[0],r+n[0].length):-1}function O8(t,e,r){var n=Ar.exec(e.slice(r,r+2));return n?(t.H=+n[0],r+n[0].length):-1}function BY(t,e,r){var n=Ar.exec(e.slice(r,r+2));return n?(t.M=+n[0],r+n[0].length):-1}function DY(t,e,r){var n=Ar.exec(e.slice(r,r+2));return n?(t.S=+n[0],r+n[0].length):-1}function OY(t,e,r){var n=Ar.exec(e.slice(r,r+3));return n?(t.L=+n[0],r+n[0].length):-1}function FY(t,e,r){var n=Ar.exec(e.slice(r,r+6));return n?(t.L=Math.floor(n[0]/1e3),r+n[0].length):-1}function PY(t,e,r){var n=kY.exec(e.slice(r,r+1));return n?r+n[0].length:-1}function qY(t,e,r){var n=Ar.exec(e.slice(r));return n?(t.Q=+n[0],r+n[0].length):-1}function VY(t,e,r){var n=Ar.exec(e.slice(r));return n?(t.s=+n[0],r+n[0].length):-1}function F8(t,e){return Oe(t.getDate(),e,2)}function zY(t,e){return Oe(t.getHours(),e,2)}function YY(t,e){return Oe(t.getHours()%12||12,e,2)}function UY(t,e){return Oe(1+dc.count(Pa(t),t),e,3)}function P8(t,e){return Oe(t.getMilliseconds(),e,3)}function WY(t,e){return P8(t,e)+"000"}function HY(t,e){return Oe(t.getMonth()+1,e,2)}function GY(t,e){return Oe(t.getMinutes(),e,2)}function jY(t,e){return Oe(t.getSeconds(),e,2)}function $Y(t){var e=t.getDay();return e===0?7:e}function XY(t,e){return Oe(Do.count(Pa(t)-1,t),e,2)}function q8(t){var e=t.getDay();return e>=4||e===0?Ns(t):Ns.ceil(t)}function KY(t,e){return t=q8(t),Oe(Ns.count(Pa(t),t)+(Pa(t).getDay()===4),e,2)}function ZY(t){return t.getDay()}function QY(t,e){return Oe(pc.count(Pa(t)-1,t),e,2)}function JY(t,e){return Oe(t.getFullYear()%100,e,2)}function tU(t,e){return t=q8(t),Oe(t.getFullYear()%100,e,2)}function eU(t,e){return Oe(t.getFullYear()%1e4,e,4)}function rU(t,e){var r=t.getDay();return t=r>=4||r===0?Ns(t):Ns.ceil(t),Oe(t.getFullYear()%1e4,e,4)}function nU(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+Oe(e/60|0,"0",2)+Oe(e%60,"0",2)}function V8(t,e){return Oe(t.getUTCDate(),e,2)}function iU(t,e){return Oe(t.getUTCHours(),e,2)}function aU(t,e){return Oe(t.getUTCHours()%12||12,e,2)}function sU(t,e){return Oe(1+gc.count(qa(t),t),e,3)}function z8(t,e){return Oe(t.getUTCMilliseconds(),e,3)}function oU(t,e){return z8(t,e)+"000"}function lU(t,e){return Oe(t.getUTCMonth()+1,e,2)}function cU(t,e){return Oe(t.getUTCMinutes(),e,2)}function uU(t,e){return Oe(t.getUTCSeconds(),e,2)}function hU(t){var e=t.getUTCDay();return e===0?7:e}function fU(t,e){return Oe(Oo.count(qa(t)-1,t),e,2)}function Y8(t){var e=t.getUTCDay();return e>=4||e===0?Ds(t):Ds.ceil(t)}function dU(t,e){return t=Y8(t),Oe(Ds.count(qa(t),t)+(qa(t).getUTCDay()===4),e,2)}function pU(t){return t.getUTCDay()}function gU(t,e){return Oe(yc.count(qa(t)-1,t),e,2)}function yU(t,e){return Oe(t.getUTCFullYear()%100,e,2)}function mU(t,e){return t=Y8(t),Oe(t.getUTCFullYear()%100,e,2)}function bU(t,e){return Oe(t.getUTCFullYear()%1e4,e,4)}function _U(t,e){var r=t.getUTCDay();return t=r>=4||r===0?Ds(t):Ds.ceil(t),Oe(t.getUTCFullYear()%1e4,e,4)}function vU(){return"+0000"}function U8(){return"%"}function W8(t){return+t}function H8(t){return Math.floor(+t/1e3)}var Fo,vc,G8,lf,Cp;j8({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function j8(t){return Fo=R8(t),vc=Fo.format,G8=Fo.parse,lf=Fo.utcFormat,Cp=Fo.utcParse,Fo}var $8="%Y-%m-%dT%H:%M:%S.%LZ";function xU(t){return t.toISOString()}var kU=Date.prototype.toISOString?xU:lf($8);const wU=kU;function TU(t){var e=new Date(t);return isNaN(e)?null:e}var EU=+new Date("2000-01-01T00:00:00.000Z")?TU:Cp($8);const CU=EU;function SU(t){return new Date(t)}function AU(t){return t instanceof Date?+t:+new Date(+t)}function Sp(t,e,r,n,i,a,s,o,l,u){var h=ap(),d=h.invert,f=h.domain,p=u(".%L"),m=u(":%S"),_=u("%I:%M"),y=u("%I %p"),b=u("%a %d"),x=u("%b %d"),k=u("%B"),T=u("%Y");function C(M){return(l(M)<M?p:o(M)<M?m:s(M)<M?_:a(M)<M?y:n(M)<M?i(M)<M?b:x:r(M)<M?k:T)(M)}return h.invert=function(M){return new Date(d(M))},h.domain=function(M){return arguments.length?f(Array.from(M,AU)):f().map(SU)},h.ticks=function(M){var S=f();return t(S[0],S[S.length-1],M==null?10:M)},h.tickFormat=function(M,S){return S==null?C:u(S)},h.nice=function(M){var S=f();return(!M||typeof M.range!="function")&&(M=e(S[0],S[S.length-1],M==null?10:M)),M?f(Wx(S,M)):h},h.copy=function(){return fc(h,Sp(t,e,r,n,i,a,s,o,l,u))},h}function X8(){return On.apply(Sp(M8,L8,Pa,bp,Do,dc,mp,yp,Fa,vc).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}function MU(){return On.apply(Sp(S8,A8,qa,kp,Oo,gc,xp,vp,Fa,lf).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)]),arguments)}function cf(){var t=0,e=1,r,n,i,a,s=an,o=!1,l;function u(d){return d==null||isNaN(d=+d)?l:s(i===0?.5:(d=(a(d)-r)*i,o?Math.max(0,Math.min(1,d)):d))}u.domain=function(d){return arguments.length?([t,e]=d,r=a(t=+t),n=a(e=+e),i=r===n?0:1/(n-r),u):[t,e]},u.clamp=function(d){return arguments.length?(o=!!d,u):o},u.interpolator=function(d){return arguments.length?(s=d,u):s};function h(d){return function(f){var p,m;return arguments.length?([p,m]=f,s=d(p,m),u):[s(0),s(1)]}}return u.range=h(Ma),u.rangeRound=h(ju),u.unknown=function(d){return arguments.length?(l=d,u):l},function(d){return a=d,r=d(t),n=d(e),i=r===n?0:1/(n-r),u}}function Va(t,e){return e.domain(t.domain()).interpolator(t.interpolator()).clamp(t.clamp()).unknown(t.unknown())}function K8(){var t=Oa(cf()(an));return t.copy=function(){return Va(t,K8())},ta.apply(t,arguments)}function Z8(){var t=op(cf()).domain([1,10]);return t.copy=function(){return Va(t,Z8()).base(t.base())},ta.apply(t,arguments)}function Q8(){var t=lp(cf());return t.copy=function(){return Va(t,Q8()).constant(t.constant())},ta.apply(t,arguments)}function Ap(){var t=cp(cf());return t.copy=function(){return Va(t,Ap()).exponent(t.exponent())},ta.apply(t,arguments)}function LU(){return Ap.apply(null,arguments).exponent(.5)}function J8(){var t=[],e=an;function r(n){if(n!=null&&!isNaN(n=+n))return e((cs(t,n,1)-1)/(t.length-1))}return r.domain=function(n){if(!arguments.length)return t.slice();t=[];for(let i of n)i!=null&&!isNaN(i=+i)&&t.push(i);return t.sort(Qe),r},r.interpolator=function(n){return arguments.length?(e=n,r):e},r.range=function(){return t.map((n,i)=>e(i/(t.length-1)))},r.quantiles=function(n){return Array.from({length:n+1},(i,a)=>Cl(t,a/n))},r.copy=function(){return J8(e).domain(t)},ta.apply(r,arguments)}function uf(){var t=0,e=.5,r=1,n=1,i,a,s,o,l,u=an,h,d=!1,f;function p(_){return isNaN(_=+_)?f:(_=.5+((_=+h(_))-a)*(n*_<n*a?o:l),u(d?Math.max(0,Math.min(1,_)):_))}p.domain=function(_){return arguments.length?([t,e,r]=_,i=h(t=+t),a=h(e=+e),s=h(r=+r),o=i===a?0:.5/(a-i),l=a===s?0:.5/(s-a),n=a<i?-1:1,p):[t,e,r]},p.clamp=function(_){return arguments.length?(d=!!_,p):d},p.interpolator=function(_){return arguments.length?(u=_,p):u};function m(_){return function(y){var b,x,k;return arguments.length?([b,x,k]=y,u=K5(_,[b,x,k]),p):[u(0),u(.5),u(1)]}}return p.range=m(Ma),p.rangeRound=m(ju),p.unknown=function(_){return arguments.length?(f=_,p):f},function(_){return h=_,i=_(t),a=_(e),s=_(r),o=i===a?0:.5/(a-i),l=a===s?0:.5/(s-a),n=a<i?-1:1,p}}function t7(){var t=Oa(uf()(an));return t.copy=function(){return Va(t,t7())},ta.apply(t,arguments)}function e7(){var t=op(uf()).domain([.1,1,10]);return t.copy=function(){return Va(t,e7()).base(t.base())},ta.apply(t,arguments)}function r7(){var t=lp(uf());return t.copy=function(){return Va(t,r7()).constant(t.constant())},ta.apply(t,arguments)}function Mp(){var t=cp(uf());return t.copy=function(){return Va(t,Mp()).exponent(t.exponent())},ta.apply(t,arguments)}function RU(){return Mp.apply(null,arguments).exponent(.5)}function Ee(t){for(var e=t.length/6|0,r=new Array(e),n=0;n<e;)r[n]="#"+t.slice(n*6,++n*6);return r}const IU=Ee("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf"),NU=Ee("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666"),BU=Ee("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666"),DU=Ee("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928"),OU=Ee("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2"),FU=Ee("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc"),PU=Ee("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999"),qU=Ee("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3"),VU=Ee("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"),zU=Ee("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab"),We=t=>B5(t[t.length-1]);var n7=new Array(3).concat("d8b365f5f5f55ab4ac","a6611adfc27d80cdc1018571","a6611adfc27df5f5f580cdc1018571","8c510ad8b365f6e8c3c7eae55ab4ac01665e","8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e","8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e","8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e","5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30","5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30").map(Ee);const YU=We(n7);var i7=new Array(3).concat("af8dc3f7f7f77fbf7b","7b3294c2a5cfa6dba0008837","7b3294c2a5cff7f7f7a6dba0008837","762a83af8dc3e7d4e8d9f0d37fbf7b1b7837","762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837","762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837","762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837","40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b","40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b").map(Ee);const UU=We(i7);var a7=new Array(3).concat("e9a3c9f7f7f7a1d76a","d01c8bf1b6dab8e1864dac26","d01c8bf1b6daf7f7f7b8e1864dac26","c51b7de9a3c9fde0efe6f5d0a1d76a4d9221","c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221","c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221","c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221","8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419","8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419").map(Ee);const WU=We(a7);var s7=new Array(3).concat("998ec3f7f7f7f1a340","5e3c99b2abd2fdb863e66101","5e3c99b2abd2f7f7f7fdb863e66101","542788998ec3d8daebfee0b6f1a340b35806","542788998ec3d8daebf7f7f7fee0b6f1a340b35806","5427888073acb2abd2d8daebfee0b6fdb863e08214b35806","5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806","2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08","2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08").map(Ee);const HU=We(s7);var o7=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(Ee);const GU=We(o7);var l7=new Array(3).concat("ef8a62ffffff999999","ca0020f4a582bababa404040","ca0020f4a582ffffffbababa404040","b2182bef8a62fddbc7e0e0e09999994d4d4d","b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d","b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d","b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d","67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a","67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a").map(Ee);const jU=We(l7);var c7=new Array(3).concat("fc8d59ffffbf91bfdb","d7191cfdae61abd9e92c7bb6","d7191cfdae61ffffbfabd9e92c7bb6","d73027fc8d59fee090e0f3f891bfdb4575b4","d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4","d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4","d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4","a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695","a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695").map(Ee);const $U=We(c7);var u7=new Array(3).concat("fc8d59ffffbf91cf60","d7191cfdae61a6d96a1a9641","d7191cfdae61ffffbfa6d96a1a9641","d73027fc8d59fee08bd9ef8b91cf601a9850","d73027fc8d59fee08bffffbfd9ef8b91cf601a9850","d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850","d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850","a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837","a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837").map(Ee);const XU=We(u7);var h7=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(Ee);const KU=We(h7);var f7=new Array(3).concat("e5f5f999d8c92ca25f","edf8fbb2e2e266c2a4238b45","edf8fbb2e2e266c2a42ca25f006d2c","edf8fbccece699d8c966c2a42ca25f006d2c","edf8fbccece699d8c966c2a441ae76238b45005824","f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824","f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b").map(Ee);const ZU=We(f7);var d7=new Array(3).concat("e0ecf49ebcda8856a7","edf8fbb3cde38c96c688419d","edf8fbb3cde38c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b").map(Ee);const QU=We(d7);var p7=new Array(3).concat("e0f3dba8ddb543a2ca","f0f9e8bae4bc7bccc42b8cbe","f0f9e8bae4bc7bccc443a2ca0868ac","f0f9e8ccebc5a8ddb57bccc443a2ca0868ac","f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e","f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e","f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081").map(Ee);const JU=We(p7);var g7=new Array(3).concat("fee8c8fdbb84e34a33","fef0d9fdcc8afc8d59d7301f","fef0d9fdcc8afc8d59e34a33b30000","fef0d9fdd49efdbb84fc8d59e34a33b30000","fef0d9fdd49efdbb84fc8d59ef6548d7301f990000","fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000","fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000").map(Ee);const tW=We(g7);var y7=new Array(3).concat("ece2f0a6bddb1c9099","f6eff7bdc9e167a9cf02818a","f6eff7bdc9e167a9cf1c9099016c59","f6eff7d0d1e6a6bddb67a9cf1c9099016c59","f6eff7d0d1e6a6bddb67a9cf3690c002818a016450","fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450","fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636").map(Ee);const eW=We(y7);var m7=new Array(3).concat("ece7f2a6bddb2b8cbe","f1eef6bdc9e174a9cf0570b0","f1eef6bdc9e174a9cf2b8cbe045a8d","f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d","f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b","fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b","fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858").map(Ee);const rW=We(m7);var b7=new Array(3).concat("e7e1efc994c7dd1c77","f1eef6d7b5d8df65b0ce1256","f1eef6d7b5d8df65b0dd1c77980043","f1eef6d4b9dac994c7df65b0dd1c77980043","f1eef6d4b9dac994c7df65b0e7298ace125691003f","f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f","f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f").map(Ee);const nW=We(b7);var _7=new Array(3).concat("fde0ddfa9fb5c51b8a","feebe2fbb4b9f768a1ae017e","feebe2fbb4b9f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a").map(Ee);const iW=We(_7);var v7=new Array(3).concat("edf8b17fcdbb2c7fb8","ffffcca1dab441b6c4225ea8","ffffcca1dab441b6c42c7fb8253494","ffffccc7e9b47fcdbb41b6c42c7fb8253494","ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84","ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84","ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58").map(Ee);const aW=We(v7);var x7=new Array(3).concat("f7fcb9addd8e31a354","ffffccc2e69978c679238443","ffffccc2e69978c67931a354006837","ffffccd9f0a3addd8e78c67931a354006837","ffffccd9f0a3addd8e78c67941ab5d238443005a32","ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32","ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529").map(Ee);const sW=We(x7);var k7=new Array(3).concat("fff7bcfec44fd95f0e","ffffd4fed98efe9929cc4c02","ffffd4fed98efe9929d95f0e993404","ffffd4fee391fec44ffe9929d95f0e993404","ffffd4fee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506").map(Ee);const oW=We(k7);var w7=new Array(3).concat("ffeda0feb24cf03b20","ffffb2fecc5cfd8d3ce31a1c","ffffb2fecc5cfd8d3cf03b20bd0026","ffffb2fed976feb24cfd8d3cf03b20bd0026","ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026","ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026","ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026").map(Ee);const lW=We(w7);var T7=new Array(3).concat("deebf79ecae13182bd","eff3ffbdd7e76baed62171b5","eff3ffbdd7e76baed63182bd08519c","eff3ffc6dbef9ecae16baed63182bd08519c","eff3ffc6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b").map(Ee);const cW=We(T7);var E7=new Array(3).concat("e5f5e0a1d99b31a354","edf8e9bae4b374c476238b45","edf8e9bae4b374c47631a354006d2c","edf8e9c7e9c0a1d99b74c47631a354006d2c","edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b").map(Ee);const uW=We(E7);var C7=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(Ee);const hW=We(C7);var S7=new Array(3).concat("efedf5bcbddc756bb1","f2f0f7cbc9e29e9ac86a51a3","f2f0f7cbc9e29e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d").map(Ee);const fW=We(S7);var A7=new Array(3).concat("fee0d2fc9272de2d26","fee5d9fcae91fb6a4acb181d","fee5d9fcae91fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d").map(Ee);const dW=We(A7);var M7=new Array(3).concat("fee6cefdae6be6550d","feeddefdbe85fd8d3cd94701","feeddefdbe85fd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704").map(Ee);const pW=We(M7);function gW(t){return t=Math.max(0,Math.min(1,t)),"rgb("+Math.max(0,Math.min(255,Math.round(-4.54-t*(35.34-t*(2381.73-t*(6402.7-t*(7024.72-t*2710.57)))))))+", "+Math.max(0,Math.min(255,Math.round(32.49+t*(170.73+t*(52.82-t*(131.46-t*(176.58-t*67.37)))))))+", "+Math.max(0,Math.min(255,Math.round(81.24+t*(442.36-t*(2482.43-t*(6167.24-t*(6614.94-t*2475.67)))))))+")"}const yW=Xu(Qn(300,.5,0),Qn(-240,.5,1));var mW=Xu(Qn(-100,.75,.35),Qn(80,1.5,.8)),bW=Xu(Qn(260,.75,.35),Qn(80,1.5,.8)),hf=Qn();function _W(t){(t<0||t>1)&&(t-=Math.floor(t));var e=Math.abs(t-.5);return hf.h=360*t-100,hf.s=1.5-1.5*e,hf.l=.8-.9*e,hf+""}var ff=po(),vW=Math.PI/3,xW=Math.PI*2/3;function kW(t){var e;return t=(.5-t)*Math.PI,ff.r=255*(e=Math.sin(t))*e,ff.g=255*(e=Math.sin(t+vW))*e,ff.b=255*(e=Math.sin(t+xW))*e,ff+""}function wW(t){return t=Math.max(0,Math.min(1,t)),"rgb("+Math.max(0,Math.min(255,Math.round(34.61+t*(1172.33-t*(10793.56-t*(33300.12-t*(38394.49-t*14825.05)))))))+", "+Math.max(0,Math.min(255,Math.round(23.31+t*(557.33+t*(1225.33-t*(3574.96-t*(1073.77+t*707.56)))))))+", "+Math.max(0,Math.min(255,Math.round(27.2+t*(3211.1-t*(15327.97-t*(27814-t*(22569.18-t*6838.66)))))))+")"}function df(t){var e=t.length;return function(r){return t[Math.max(0,Math.min(e-1,Math.floor(r*e)))]}}const TW=df(Ee("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));var EW=df(Ee("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")),CW=df(Ee("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")),SW=df(Ee("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));function xe(t){return function(){return t}}const L7=Math.abs,qr=Math.atan2,na=Math.cos,AW=Math.max,Po=Math.min,gn=Math.sin,He=Math.sqrt,Vr=1e-12,za=Math.PI,pf=za/2,Ya=2*za;function MW(t){return t>1?0:t<-1?za:Math.acos(t)}function R7(t){return t>=1?pf:t<=-1?-pf:Math.asin(t)}function LW(t){return t.innerRadius}function RW(t){return t.outerRadius}function IW(t){return t.startAngle}function NW(t){return t.endAngle}function BW(t){return t&&t.padAngle}function DW(t,e,r,n,i,a,s,o){var l=r-t,u=n-e,h=s-i,d=o-a,f=d*l-h*u;if(!(f*f<Vr))return f=(h*(e-a)-d*(t-i))/f,[t+f*l,e+f*u]}function gf(t,e,r,n,i,a,s){var o=t-r,l=e-n,u=(s?a:-a)/He(o*o+l*l),h=u*l,d=-u*o,f=t+h,p=e+d,m=r+h,_=n+d,y=(f+m)/2,b=(p+_)/2,x=m-f,k=_-p,T=x*x+k*k,C=i-a,M=f*_-m*p,S=(k<0?-1:1)*He(AW(0,C*C*T-M*M)),R=(M*k-x*S)/T,A=(-M*x-k*S)/T,L=(M*k+x*S)/T,v=(-M*x+k*S)/T,B=R-y,w=A-b,D=L-y,N=v-b;return B*B+w*w>D*D+N*N&&(R=L,A=v),{cx:R,cy:A,x01:-h,y01:-d,x11:R*(i/C-1),y11:A*(i/C-1)}}function yf(){var t=LW,e=RW,r=xe(0),n=null,i=IW,a=NW,s=BW,o=null;function l(){var u,h,d=+t.apply(this,arguments),f=+e.apply(this,arguments),p=i.apply(this,arguments)-pf,m=a.apply(this,arguments)-pf,_=L7(m-p),y=m>p;if(o||(o=u=Ra()),f<d&&(h=f,f=d,d=h),!(f>Vr))o.moveTo(0,0);else if(_>Ya-Vr)o.moveTo(f*na(p),f*gn(p)),o.arc(0,0,f,p,m,!y),d>Vr&&(o.moveTo(d*na(m),d*gn(m)),o.arc(0,0,d,m,p,y));else{var b=p,x=m,k=p,T=m,C=_,M=_,S=s.apply(this,arguments)/2,R=S>Vr&&(n?+n.apply(this,arguments):He(d*d+f*f)),A=Po(L7(f-d)/2,+r.apply(this,arguments)),L=A,v=A,B,w;if(R>Vr){var D=R7(R/d*gn(S)),N=R7(R/f*gn(S));(C-=D*2)>Vr?(D*=y?1:-1,k+=D,T-=D):(C=0,k=T=(p+m)/2),(M-=N*2)>Vr?(N*=y?1:-1,b+=N,x-=N):(M=0,b=x=(p+m)/2)}var z=f*na(b),X=f*gn(b),ct=d*na(T),J=d*gn(T);if(A>Vr){var Y=f*na(x),$=f*gn(x),lt=d*na(k),ut=d*gn(k),W;if(_<za&&(W=DW(z,X,lt,ut,Y,$,ct,J))){var tt=z-W[0],K=X-W[1],it=Y-W[0],Z=$-W[1],V=1/gn(MW((tt*it+K*Z)/(He(tt*tt+K*K)*He(it*it+Z*Z)))/2),Q=He(W[0]*W[0]+W[1]*W[1]);L=Po(A,(d-Q)/(V-1)),v=Po(A,(f-Q)/(V+1))}}M>Vr?v>Vr?(B=gf(lt,ut,z,X,f,v,y),w=gf(Y,$,ct,J,f,v,y),o.moveTo(B.cx+B.x01,B.cy+B.y01),v<A?o.arc(B.cx,B.cy,v,qr(B.y01,B.x01),qr(w.y01,w.x01),!y):(o.arc(B.cx,B.cy,v,qr(B.y01,B.x01),qr(B.y11,B.x11),!y),o.arc(0,0,f,qr(B.cy+B.y11,B.cx+B.x11),qr(w.cy+w.y11,w.cx+w.x11),!y),o.arc(w.cx,w.cy,v,qr(w.y11,w.x11),qr(w.y01,w.x01),!y))):(o.moveTo(z,X),o.arc(0,0,f,b,x,!y)):o.moveTo(z,X),!(d>Vr)||!(C>Vr)?o.lineTo(ct,J):L>Vr?(B=gf(ct,J,Y,$,d,-L,y),w=gf(z,X,lt,ut,d,-L,y),o.lineTo(B.cx+B.x01,B.cy+B.y01),L<A?o.arc(B.cx,B.cy,L,qr(B.y01,B.x01),qr(w.y01,w.x01),!y):(o.arc(B.cx,B.cy,L,qr(B.y01,B.x01),qr(B.y11,B.x11),!y),o.arc(0,0,d,qr(B.cy+B.y11,B.cx+B.x11),qr(w.cy+w.y11,w.cx+w.x11),y),o.arc(w.cx,w.cy,L,qr(w.y11,w.x11),qr(w.y01,w.x01),!y))):o.arc(0,0,d,T,k,y)}if(o.closePath(),u)return o=null,u+""||null}return l.centroid=function(){var u=(+t.apply(this,arguments)+ +e.apply(this,arguments))/2,h=(+i.apply(this,arguments)+ +a.apply(this,arguments))/2-za/2;return[na(h)*u,gn(h)*u]},l.innerRadius=function(u){return arguments.length?(t=typeof u=="function"?u:xe(+u),l):t},l.outerRadius=function(u){return arguments.length?(e=typeof u=="function"?u:xe(+u),l):e},l.cornerRadius=function(u){return arguments.length?(r=typeof u=="function"?u:xe(+u),l):r},l.padRadius=function(u){return arguments.length?(n=u==null?null:typeof u=="function"?u:xe(+u),l):n},l.startAngle=function(u){return arguments.length?(i=typeof u=="function"?u:xe(+u),l):i},l.endAngle=function(u){return arguments.length?(a=typeof u=="function"?u:xe(+u),l):a},l.padAngle=function(u){return arguments.length?(s=typeof u=="function"?u:xe(+u),l):s},l.context=function(u){return arguments.length?(o=u==null?null:u,l):o},l}var OW=Array.prototype.slice;function mf(t){return typeof t=="object"&&"length"in t?t:Array.from(t)}function I7(t){this._context=t}I7.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e);break}}};function yn(t){return new I7(t)}function Lp(t){return t[0]}function Rp(t){return t[1]}function Ua(t,e){var r=xe(!0),n=null,i=yn,a=null;t=typeof t=="function"?t:t===void 0?Lp:xe(t),e=typeof e=="function"?e:e===void 0?Rp:xe(e);function s(o){var l,u=(o=mf(o)).length,h,d=!1,f;for(n==null&&(a=i(f=Ra())),l=0;l<=u;++l)!(l<u&&r(h=o[l],l,o))===d&&((d=!d)?a.lineStart():a.lineEnd()),d&&a.point(+t(h,l,o),+e(h,l,o));if(f)return a=null,f+""||null}return s.x=function(o){return arguments.length?(t=typeof o=="function"?o:xe(+o),s):t},s.y=function(o){return arguments.length?(e=typeof o=="function"?o:xe(+o),s):e},s.defined=function(o){return arguments.length?(r=typeof o=="function"?o:xe(!!o),s):r},s.curve=function(o){return arguments.length?(i=o,n!=null&&(a=i(n)),s):i},s.context=function(o){return arguments.length?(o==null?n=a=null:a=i(n=o),s):n},s}function N7(t,e,r){var n=null,i=xe(!0),a=null,s=yn,o=null;t=typeof t=="function"?t:t===void 0?Lp:xe(+t),e=typeof e=="function"?e:xe(e===void 0?0:+e),r=typeof r=="function"?r:r===void 0?Rp:xe(+r);function l(h){var d,f,p,m=(h=mf(h)).length,_,y=!1,b,x=new Array(m),k=new Array(m);for(a==null&&(o=s(b=Ra())),d=0;d<=m;++d){if(!(d<m&&i(_=h[d],d,h))===y)if(y=!y)f=d,o.areaStart(),o.lineStart();else{for(o.lineEnd(),o.lineStart(),p=d-1;p>=f;--p)o.point(x[p],k[p]);o.lineEnd(),o.areaEnd()}y&&(x[d]=+t(_,d,h),k[d]=+e(_,d,h),o.point(n?+n(_,d,h):x[d],r?+r(_,d,h):k[d]))}if(b)return o=null,b+""||null}function u(){return Ua().defined(i).curve(s).context(a)}return l.x=function(h){return arguments.length?(t=typeof h=="function"?h:xe(+h),n=null,l):t},l.x0=function(h){return arguments.length?(t=typeof h=="function"?h:xe(+h),l):t},l.x1=function(h){return arguments.length?(n=h==null?null:typeof h=="function"?h:xe(+h),l):n},l.y=function(h){return arguments.length?(e=typeof h=="function"?h:xe(+h),r=null,l):e},l.y0=function(h){return arguments.length?(e=typeof h=="function"?h:xe(+h),l):e},l.y1=function(h){return arguments.length?(r=h==null?null:typeof h=="function"?h:xe(+h),l):r},l.lineX0=l.lineY0=function(){return u().x(t).y(e)},l.lineY1=function(){return u().x(t).y(r)},l.lineX1=function(){return u().x(n).y(e)},l.defined=function(h){return arguments.length?(i=typeof h=="function"?h:xe(!!h),l):i},l.curve=function(h){return arguments.length?(s=h,a!=null&&(o=s(a)),l):s},l.context=function(h){return arguments.length?(h==null?a=o=null:o=s(a=h),l):a},l}function FW(t,e){return e<t?-1:e>t?1:e>=t?0:NaN}function PW(t){return t}function B7(){var t=PW,e=FW,r=null,n=xe(0),i=xe(Ya),a=xe(0);function s(o){var l,u=(o=mf(o)).length,h,d,f=0,p=new Array(u),m=new Array(u),_=+n.apply(this,arguments),y=Math.min(Ya,Math.max(-Ya,i.apply(this,arguments)-_)),b,x=Math.min(Math.abs(y)/u,a.apply(this,arguments)),k=x*(y<0?-1:1),T;for(l=0;l<u;++l)(T=m[p[l]=l]=+t(o[l],l,o))>0&&(f+=T);for(e!=null?p.sort(function(C,M){return e(m[C],m[M])}):r!=null&&p.sort(function(C,M){return r(o[C],o[M])}),l=0,d=f?(y-u*k)/f:0;l<u;++l,_=b)h=p[l],T=m[h],b=_+(T>0?T*d:0)+k,m[h]={data:o[h],index:l,value:T,startAngle:_,endAngle:b,padAngle:x};return m}return s.value=function(o){return arguments.length?(t=typeof o=="function"?o:xe(+o),s):t},s.sortValues=function(o){return arguments.length?(e=o,r=null,s):e},s.sort=function(o){return arguments.length?(r=o,e=null,s):r},s.startAngle=function(o){return arguments.length?(n=typeof o=="function"?o:xe(+o),s):n},s.endAngle=function(o){return arguments.length?(i=typeof o=="function"?o:xe(+o),s):i},s.padAngle=function(o){return arguments.length?(a=typeof o=="function"?o:xe(+o),s):a},s}var D7=Ip(yn);function O7(t){this._curve=t}O7.prototype={areaStart:function(){this._curve.areaStart()},areaEnd:function(){this._curve.areaEnd()},lineStart:function(){this._curve.lineStart()},lineEnd:function(){this._curve.lineEnd()},point:function(t,e){this._curve.point(e*Math.sin(t),e*-Math.cos(t))}};function Ip(t){function e(r){return new O7(t(r))}return e._curve=t,e}function xc(t){var e=t.curve;return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t.curve=function(r){return arguments.length?e(Ip(r)):e()._curve},t}function F7(){return xc(Ua().curve(D7))}function P7(){var t=N7().curve(D7),e=t.curve,r=t.lineX0,n=t.lineX1,i=t.lineY0,a=t.lineY1;return t.angle=t.x,delete t.x,t.startAngle=t.x0,delete t.x0,t.endAngle=t.x1,delete t.x1,t.radius=t.y,delete t.y,t.innerRadius=t.y0,delete t.y0,t.outerRadius=t.y1,delete t.y1,t.lineStartAngle=function(){return xc(r())},delete t.lineX0,t.lineEndAngle=function(){return xc(n())},delete t.lineX1,t.lineInnerRadius=function(){return xc(i())},delete t.lineY0,t.lineOuterRadius=function(){return xc(a())},delete t.lineY1,t.curve=function(s){return arguments.length?e(Ip(s)):e()._curve},t}function kc(t,e){return[(e=+e)*Math.cos(t-=Math.PI/2),e*Math.sin(t)]}class q7{constructor(e,r){this._context=e,this._x=r}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line}point(e,r){switch(e=+e,r=+r,this._point){case 0:{this._point=1,this._line?this._context.lineTo(e,r):this._context.moveTo(e,r);break}case 1:this._point=2;default:{this._x?this._context.bezierCurveTo(this._x0=(this._x0+e)/2,this._y0,this._x0,r,e,r):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+r)/2,e,this._y0,e,r);break}}this._x0=e,this._y0=r}}class qW{constructor(e){this._context=e}lineStart(){this._point=0}lineEnd(){}point(e,r){if(e=+e,r=+r,this._point++===0)this._x0=e,this._y0=r;else{const n=kc(this._x0,this._y0),i=kc(this._x0,this._y0=(this._y0+r)/2),a=kc(e,this._y0),s=kc(e,r);this._context.moveTo(...n),this._context.bezierCurveTo(...i,...a,...s)}}}function V7(t){return new q7(t,!0)}function z7(t){return new q7(t,!1)}function VW(t){return new qW(t)}function zW(t){return t.source}function YW(t){return t.target}function bf(t){let e=zW,r=YW,n=Lp,i=Rp,a=null,s=null;function o(){let l;const u=OW.call(arguments),h=e.apply(this,u),d=r.apply(this,u);if(a==null&&(s=t(l=Ra())),s.lineStart(),u[0]=h,s.point(+n.apply(this,u),+i.apply(this,u)),u[0]=d,s.point(+n.apply(this,u),+i.apply(this,u)),s.lineEnd(),l)return s=null,l+""||null}return o.source=function(l){return arguments.length?(e=l,o):e},o.target=function(l){return arguments.length?(r=l,o):r},o.x=function(l){return arguments.length?(n=typeof l=="function"?l:xe(+l),o):n},o.y=function(l){return arguments.length?(i=typeof l=="function"?l:xe(+l),o):i},o.context=function(l){return arguments.length?(l==null?a=s=null:s=t(a=l),o):a},o}function UW(){return bf(V7)}function WW(){return bf(z7)}function HW(){const t=bf(VW);return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t}const GW=He(3),Y7={draw(t,e){const r=He(e+Po(e/28,.75))*.59436,n=r/2,i=n*GW;t.moveTo(0,r),t.lineTo(0,-r),t.moveTo(-i,-n),t.lineTo(i,n),t.moveTo(-i,n),t.lineTo(i,-n)}},_f={draw(t,e){const r=He(e/za);t.moveTo(r,0),t.arc(0,0,r,0,Ya)}},U7={draw(t,e){const r=He(e/5)/2;t.moveTo(-3*r,-r),t.lineTo(-r,-r),t.lineTo(-r,-3*r),t.lineTo(r,-3*r),t.lineTo(r,-r),t.lineTo(3*r,-r),t.lineTo(3*r,r),t.lineTo(r,r),t.lineTo(r,3*r),t.lineTo(-r,3*r),t.lineTo(-r,r),t.lineTo(-3*r,r),t.closePath()}},W7=He(1/3),jW=W7*2,H7={draw(t,e){const r=He(e/jW),n=r*W7;t.moveTo(0,-r),t.lineTo(n,0),t.lineTo(0,r),t.lineTo(-n,0),t.closePath()}},G7={draw(t,e){const r=He(e)*.62625;t.moveTo(0,-r),t.lineTo(r,0),t.lineTo(0,r),t.lineTo(-r,0),t.closePath()}},j7={draw(t,e){const r=He(e-Po(e/7,2))*.87559;t.moveTo(-r,0),t.lineTo(r,0),t.moveTo(0,r),t.lineTo(0,-r)}},$7={draw(t,e){const r=He(e),n=-r/2;t.rect(n,n,r,r)}},X7={draw(t,e){const r=He(e)*.4431;t.moveTo(r,r),t.lineTo(r,-r),t.lineTo(-r,-r),t.lineTo(-r,r),t.closePath()}},$W=.8908130915292852,K7=gn(za/10)/gn(7*za/10),XW=gn(Ya/10)*K7,KW=-na(Ya/10)*K7,Z7={draw(t,e){const r=He(e*$W),n=XW*r,i=KW*r;t.moveTo(0,-r),t.lineTo(n,i);for(let a=1;a<5;++a){const s=Ya*a/5,o=na(s),l=gn(s);t.lineTo(l*r,-o*r),t.lineTo(o*n-l*i,l*n+o*i)}t.closePath()}},Np=He(3),Q7={draw(t,e){const r=-He(e/(Np*3));t.moveTo(0,r*2),t.lineTo(-Np*r,-r),t.lineTo(Np*r,-r),t.closePath()}},ZW=He(3),J7={draw(t,e){const r=He(e)*.6824,n=r/2,i=r*ZW/2;t.moveTo(0,-r),t.lineTo(i,n),t.lineTo(-i,n),t.closePath()}},Pn=-.5,qn=He(3)/2,Bp=1/He(12),QW=(Bp/2+1)*3,tk={draw(t,e){const r=He(e/QW),n=r/2,i=r*Bp,a=n,s=r*Bp+r,o=-a,l=s;t.moveTo(n,i),t.lineTo(a,s),t.lineTo(o,l),t.lineTo(Pn*n-qn*i,qn*n+Pn*i),t.lineTo(Pn*a-qn*s,qn*a+Pn*s),t.lineTo(Pn*o-qn*l,qn*o+Pn*l),t.lineTo(Pn*n+qn*i,Pn*i-qn*n),t.lineTo(Pn*a+qn*s,Pn*s-qn*a),t.lineTo(Pn*o+qn*l,Pn*l-qn*o),t.closePath()}},ek={draw(t,e){const r=He(e-Po(e/6,1.7))*.6189;t.moveTo(-r,-r),t.lineTo(r,r),t.moveTo(-r,r),t.lineTo(r,-r)}},rk=[_f,U7,H7,$7,Z7,Q7,tk],JW=[_f,j7,ek,J7,Y7,X7,G7];function tH(t,e){let r=null;t=typeof t=="function"?t:xe(t||_f),e=typeof e=="function"?e:xe(e===void 0?64:+e);function n(){let i;if(r||(r=i=Ra()),t.apply(this,arguments).draw(r,+e.apply(this,arguments)),i)return r=null,i+""||null}return n.type=function(i){return arguments.length?(t=typeof i=="function"?i:xe(i),n):t},n.size=function(i){return arguments.length?(e=typeof i=="function"?i:xe(+i),n):e},n.context=function(i){return arguments.length?(r=i==null?null:i,n):r},n}function Wa(){}function vf(t,e,r){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+r)/6)}function xf(t){this._context=t}xf.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:vf(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:vf(this,t,e);break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function Os(t){return new xf(t)}function nk(t){this._context=t}nk.prototype={areaStart:Wa,areaEnd:Wa,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:{this._context.moveTo(this._x2,this._y2),this._context.closePath();break}case 2:{this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break}case 3:{this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4);break}}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x2=t,this._y2=e;break;case 1:this._point=2,this._x3=t,this._y3=e;break;case 2:this._point=3,this._x4=t,this._y4=e,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+e)/6);break;default:vf(this,t,e);break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function ik(t){return new nk(t)}function ak(t){this._context=t}ak.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var r=(this._x0+4*this._x1+t)/6,n=(this._y0+4*this._y1+e)/6;this._line?this._context.lineTo(r,n):this._context.moveTo(r,n);break;case 3:this._point=4;default:vf(this,t,e);break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function sk(t){return new ak(t)}function ok(t,e){this._basis=new xf(t),this._beta=e}ok.prototype={lineStart:function(){this._x=[],this._y=[],this._basis.lineStart()},lineEnd:function(){var t=this._x,e=this._y,r=t.length-1;if(r>0)for(var n=t[0],i=e[0],a=t[r]-n,s=e[r]-i,o=-1,l;++o<=r;)l=o/r,this._basis.point(this._beta*t[o]+(1-this._beta)*(n+l*a),this._beta*e[o]+(1-this._beta)*(i+l*s));this._x=this._y=null,this._basis.lineEnd()},point:function(t,e){this._x.push(+t),this._y.push(+e)}};const eH=function t(e){function r(n){return e===1?new xf(n):new ok(n,e)}return r.beta=function(n){return t(+n)},r}(.85);function kf(t,e,r){t._context.bezierCurveTo(t._x1+t._k*(t._x2-t._x0),t._y1+t._k*(t._y2-t._y0),t._x2+t._k*(t._x1-e),t._y2+t._k*(t._y1-r),t._x2,t._y2)}function Dp(t,e){this._context=t,this._k=(1-e)/6}Dp.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:kf(this,this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2,this._x1=t,this._y1=e;break;case 2:this._point=3;default:kf(this,t,e);break}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const rH=function t(e){function r(n){return new Dp(n,e)}return r.tension=function(n){return t(+n)},r}(0);function Op(t,e){this._context=t,this._k=(1-e)/6}Op.prototype={areaStart:Wa,areaEnd:Wa,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:{this._context.moveTo(this._x3,this._y3),this._context.closePath();break}case 2:{this._context.lineTo(this._x3,this._y3),this._context.closePath();break}case 3:{this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5);break}}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:kf(this,t,e);break}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const nH=function t(e){function r(n){return new Op(n,e)}return r.tension=function(n){return t(+n)},r}(0);function Fp(t,e){this._context=t,this._k=(1-e)/6}Fp.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:kf(this,t,e);break}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const iH=function t(e){function r(n){return new Fp(n,e)}return r.tension=function(n){return t(+n)},r}(0);function Pp(t,e,r){var n=t._x1,i=t._y1,a=t._x2,s=t._y2;if(t._l01_a>Vr){var o=2*t._l01_2a+3*t._l01_a*t._l12_a+t._l12_2a,l=3*t._l01_a*(t._l01_a+t._l12_a);n=(n*o-t._x0*t._l12_2a+t._x2*t._l01_2a)/l,i=(i*o-t._y0*t._l12_2a+t._y2*t._l01_2a)/l}if(t._l23_a>Vr){var u=2*t._l23_2a+3*t._l23_a*t._l12_a+t._l12_2a,h=3*t._l23_a*(t._l23_a+t._l12_a);a=(a*u+t._x1*t._l23_2a-e*t._l12_2a)/h,s=(s*u+t._y1*t._l23_2a-r*t._l12_2a)/h}t._context.bezierCurveTo(n,i,a,s,t._x2,t._y2)}function lk(t,e){this._context=t,this._alpha=e}lk.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var r=this._x2-t,n=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(r*r+n*n,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3;default:Pp(this,t,e);break}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const aH=function t(e){function r(n){return e?new lk(n,e):new Dp(n,0)}return r.alpha=function(n){return t(+n)},r}(.5);function ck(t,e){this._context=t,this._alpha=e}ck.prototype={areaStart:Wa,areaEnd:Wa,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 1:{this._context.moveTo(this._x3,this._y3),this._context.closePath();break}case 2:{this._context.lineTo(this._x3,this._y3),this._context.closePath();break}case 3:{this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5);break}}},point:function(t,e){if(t=+t,e=+e,this._point){var r=this._x2-t,n=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(r*r+n*n,this._alpha))}switch(this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:Pp(this,t,e);break}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const sH=function t(e){function r(n){return e?new ck(n,e):new Op(n,0)}return r.alpha=function(n){return t(+n)},r}(.5);function uk(t,e){this._context=t,this._alpha=e}uk.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var r=this._x2-t,n=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(r*r+n*n,this._alpha))}switch(this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:Pp(this,t,e);break}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const oH=function t(e){function r(n){return e?new uk(n,e):new Fp(n,0)}return r.alpha=function(n){return t(+n)},r}(.5);function hk(t){this._context=t}hk.prototype={areaStart:Wa,areaEnd:Wa,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(t,e){t=+t,e=+e,this._point?this._context.lineTo(t,e):(this._point=1,this._context.moveTo(t,e))}};function fk(t){return new hk(t)}function dk(t){return t<0?-1:1}function pk(t,e,r){var n=t._x1-t._x0,i=e-t._x1,a=(t._y1-t._y0)/(n||i<0&&-0),s=(r-t._y1)/(i||n<0&&-0),o=(a*i+s*n)/(n+i);return(dk(a)+dk(s))*Math.min(Math.abs(a),Math.abs(s),.5*Math.abs(o))||0}function gk(t,e){var r=t._x1-t._x0;return r?(3*(t._y1-t._y0)/r-e)/2:e}function qp(t,e,r){var n=t._x0,i=t._y0,a=t._x1,s=t._y1,o=(a-n)/3;t._context.bezierCurveTo(n+o,i+o*e,a-o,s-o*r,a,s)}function wf(t){this._context=t}wf.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:qp(this,this._t0,gk(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){var r=NaN;if(t=+t,e=+e,!(t===this._x1&&e===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,qp(this,gk(this,r=pk(this,t,e)),r);break;default:qp(this,this._t0,r=pk(this,t,e));break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e,this._t0=r}}};function yk(t){this._context=new mk(t)}(yk.prototype=Object.create(wf.prototype)).point=function(t,e){wf.prototype.point.call(this,e,t)};function mk(t){this._context=t}mk.prototype={moveTo:function(t,e){this._context.moveTo(e,t)},closePath:function(){this._context.closePath()},lineTo:function(t,e){this._context.lineTo(e,t)},bezierCurveTo:function(t,e,r,n,i,a){this._context.bezierCurveTo(e,t,n,r,a,i)}};function bk(t){return new wf(t)}function _k(t){return new yk(t)}function vk(t){this._context=t}vk.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var t=this._x,e=this._y,r=t.length;if(r)if(this._line?this._context.lineTo(t[0],e[0]):this._context.moveTo(t[0],e[0]),r===2)this._context.lineTo(t[1],e[1]);else for(var n=xk(t),i=xk(e),a=0,s=1;s<r;++a,++s)this._context.bezierCurveTo(n[0][a],i[0][a],n[1][a],i[1][a],t[s],e[s]);(this._line||this._line!==0&&r===1)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(t,e){this._x.push(+t),this._y.push(+e)}};function xk(t){var e,r=t.length-1,n,i=new Array(r),a=new Array(r),s=new Array(r);for(i[0]=0,a[0]=2,s[0]=t[0]+2*t[1],e=1;e<r-1;++e)i[e]=1,a[e]=4,s[e]=4*t[e]+2*t[e+1];for(i[r-1]=2,a[r-1]=7,s[r-1]=8*t[r-1]+t[r],e=1;e<r;++e)n=i[e]/a[e-1],a[e]-=n,s[e]-=n*s[e-1];for(i[r-1]=s[r-1]/a[r-1],e=r-2;e>=0;--e)i[e]=(s[e]-i[e+1])/a[e];for(a[r-1]=(t[r]+i[r-1])/2,e=0;e<r-1;++e)a[e]=2*t[e+1]-i[e+1];return[i,a]}function kk(t){return new vk(t)}function Tf(t,e){this._context=t,this._t=e}Tf.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&this._point===2&&this._context.lineTo(this._x,this._y),(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:{if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var r=this._x*(1-this._t)+t*this._t;this._context.lineTo(r,this._y),this._context.lineTo(r,e)}break}}this._x=t,this._y=e}};function wk(t){return new Tf(t,.5)}function Tk(t){return new Tf(t,0)}function Ek(t){return new Tf(t,1)}function qo(t,e){if((s=t.length)>1)for(var r=1,n,i,a=t[e[0]],s,o=a.length;r<s;++r)for(i=a,a=t[e[r]],n=0;n<o;++n)a[n][1]+=a[n][0]=isNaN(i[n][1])?i[n][0]:i[n][1]}function Vo(t){for(var e=t.length,r=new Array(e);--e>=0;)r[e]=e;return r}function lH(t,e){return t[e]}function cH(t){const e=[];return e.key=t,e}function uH(){var t=xe([]),e=Vo,r=qo,n=lH;function i(a){var s=Array.from(t.apply(this,arguments),cH),o,l=s.length,u=-1,h;for(const d of a)for(o=0,++u;o<l;++o)(s[o][u]=[0,+n(d,s[o].key,u,a)]).data=d;for(o=0,h=mf(e(s));o<l;++o)s[h[o]].index=o;return r(s,h),s}return i.keys=function(a){return arguments.length?(t=typeof a=="function"?a:xe(Array.from(a)),i):t},i.value=function(a){return arguments.length?(n=typeof a=="function"?a:xe(+a),i):n},i.order=function(a){return arguments.length?(e=a==null?Vo:typeof a=="function"?a:xe(Array.from(a)),i):e},i.offset=function(a){return arguments.length?(r=a==null?qo:a,i):r},i}function hH(t,e){if((n=t.length)>0){for(var r,n,i=0,a=t[0].length,s;i<a;++i){for(s=r=0;r<n;++r)s+=t[r][i][1]||0;if(s)for(r=0;r<n;++r)t[r][i][1]/=s}qo(t,e)}}function fH(t,e){if((l=t.length)>0)for(var r,n=0,i,a,s,o,l,u=t[e[0]].length;n<u;++n)for(s=o=0,r=0;r<l;++r)(a=(i=t[e[r]][n])[1]-i[0])>0?(i[0]=s,i[1]=s+=a):a<0?(i[1]=o,i[0]=o+=a):(i[0]=0,i[1]=a)}function dH(t,e){if((i=t.length)>0){for(var r=0,n=t[e[0]],i,a=n.length;r<a;++r){for(var s=0,o=0;s<i;++s)o+=t[s][r][1]||0;n[r][1]+=n[r][0]=-o/2}qo(t,e)}}function pH(t,e){if(!(!((s=t.length)>0)||!((a=(i=t[e[0]]).length)>0))){for(var r=0,n=1,i,a,s;n<a;++n){for(var o=0,l=0,u=0;o<s;++o){for(var h=t[e[o]],d=h[n][1]||0,f=h[n-1][1]||0,p=(d-f)/2,m=0;m<o;++m){var _=t[e[m]],y=_[n][1]||0,b=_[n-1][1]||0;p+=y-b}l+=d,u+=p*d}i[n-1][1]+=i[n-1][0]=r,l&&(r-=u/l)}i[n-1][1]+=i[n-1][0]=r,qo(t,e)}}function Ck(t){var e=t.map(gH);return Vo(t).sort(function(r,n){return e[r]-e[n]})}function gH(t){for(var e=-1,r=0,n=t.length,i,a=-1/0;++e<n;)(i=+t[e][1])>a&&(a=i,r=e);return r}function Sk(t){var e=t.map(Ak);return Vo(t).sort(function(r,n){return e[r]-e[n]})}function Ak(t){for(var e=0,r=-1,n=t.length,i;++r<n;)(i=+t[r][1])&&(e+=i);return e}function yH(t){return Sk(t).reverse()}function mH(t){var e=t.length,r,n,i=t.map(Ak),a=Ck(t),s=0,o=0,l=[],u=[];for(r=0;r<e;++r)n=a[r],s<o?(s+=i[n],l.push(n)):(o+=i[n],u.push(n));return u.reverse().concat(l)}function bH(t){return Vo(t).reverse()}const Ef=t=>()=>t;function _H(t,{sourceEvent:e,target:r,transform:n,dispatch:i}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},transform:{value:n,enumerable:!0,configurable:!0},_:{value:i}})}function Ri(t,e,r){this.k=t,this.x=e,this.y=r}Ri.prototype={constructor:Ri,scale:function(t){return t===1?this:new Ri(this.k*t,this.x,this.y)},translate:function(t,e){return t===0&e===0?this:new Ri(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Cf=new Ri(1,0,0);Mk.prototype=Ri.prototype;function Mk(t){for(;!t.__zoom;)if(!(t=t.parentNode))return Cf;return t.__zoom}function Vp(t){t.stopImmediatePropagation()}function wc(t){t.preventDefault(),t.stopImmediatePropagation()}function vH(t){return(!t.ctrlKey||t.type==="wheel")&&!t.button}function xH(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t,t.hasAttribute("viewBox")?(t=t.viewBox.baseVal,[[t.x,t.y],[t.x+t.width,t.y+t.height]]):[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]):[[0,0],[t.clientWidth,t.clientHeight]]}function Lk(){return this.__zoom||Cf}function kH(t){return-t.deltaY*(t.deltaMode===1?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function wH(){return navigator.maxTouchPoints||"ontouchstart"in this}function TH(t,e,r){var n=t.invertX(e[0][0])-r[0][0],i=t.invertX(e[1][0])-r[1][0],a=t.invertY(e[0][1])-r[0][1],s=t.invertY(e[1][1])-r[1][1];return t.translate(i>n?(n+i)/2:Math.min(0,n)||Math.max(0,i),s>a?(a+s)/2:Math.min(0,a)||Math.max(0,s))}function EH(){var t=vH,e=xH,r=TH,n=kH,i=wH,a=[0,1/0],s=[[-1/0,-1/0],[1/0,1/0]],o=250,l=H5,u=fs("start","zoom","end"),h,d,f,p=500,m=150,_=0,y=10;function b(D){D.property("__zoom",Lk).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",A).on("dblclick.zoom",L).filter(i).on("touchstart.zoom",v).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",w).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}b.transform=function(D,N,z,X){var ct=D.selection?D.selection():D;ct.property("__zoom",Lk),D!==ct?C(D,N,z,X):ct.interrupt().each(function(){M(this,arguments).event(X).start().zoom(null,typeof N=="function"?N.apply(this,arguments):N).end()})},b.scaleBy=function(D,N,z,X){b.scaleTo(D,function(){var ct=this.__zoom.k,J=typeof N=="function"?N.apply(this,arguments):N;return ct*J},z,X)},b.scaleTo=function(D,N,z,X){b.transform(D,function(){var ct=e.apply(this,arguments),J=this.__zoom,Y=z==null?T(ct):typeof z=="function"?z.apply(this,arguments):z,$=J.invert(Y),lt=typeof N=="function"?N.apply(this,arguments):N;return r(k(x(J,lt),Y,$),ct,s)},z,X)},b.translateBy=function(D,N,z,X){b.transform(D,function(){return r(this.__zoom.translate(typeof N=="function"?N.apply(this,arguments):N,typeof z=="function"?z.apply(this,arguments):z),e.apply(this,arguments),s)},null,X)},b.translateTo=function(D,N,z,X,ct){b.transform(D,function(){var J=e.apply(this,arguments),Y=this.__zoom,$=X==null?T(J):typeof X=="function"?X.apply(this,arguments):X;return r(Cf.translate($[0],$[1]).scale(Y.k).translate(typeof N=="function"?-N.apply(this,arguments):-N,typeof z=="function"?-z.apply(this,arguments):-z),J,s)},X,ct)};function x(D,N){return N=Math.max(a[0],Math.min(a[1],N)),N===D.k?D:new Ri(N,D.x,D.y)}function k(D,N,z){var X=N[0]-z[0]*D.k,ct=N[1]-z[1]*D.k;return X===D.x&&ct===D.y?D:new Ri(D.k,X,ct)}function T(D){return[(+D[0][0]+ +D[1][0])/2,(+D[0][1]+ +D[1][1])/2]}function C(D,N,z,X){D.on("start.zoom",function(){M(this,arguments).event(X).start()}).on("interrupt.zoom end.zoom",function(){M(this,arguments).event(X).end()}).tween("zoom",function(){var ct=this,J=arguments,Y=M(ct,J).event(X),$=e.apply(ct,J),lt=z==null?T($):typeof z=="function"?z.apply(ct,J):z,ut=Math.max($[1][0]-$[0][0],$[1][1]-$[0][1]),W=ct.__zoom,tt=typeof N=="function"?N.apply(ct,J):N,K=l(W.invert(lt).concat(ut/W.k),tt.invert(lt).concat(ut/tt.k));return function(it){if(it===1)it=tt;else{var Z=K(it),V=ut/Z[2];it=new Ri(V,lt[0]-Z[0]*V,lt[1]-Z[1]*V)}Y.zoom(null,it)}})}function M(D,N,z){return!z&&D.__zooming||new S(D,N)}function S(D,N){this.that=D,this.args=N,this.active=0,this.sourceEvent=null,this.extent=e.apply(D,N),this.taps=0}S.prototype={event:function(D){return D&&(this.sourceEvent=D),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(D,N){return this.mouse&&D!=="mouse"&&(this.mouse[1]=N.invert(this.mouse[0])),this.touch0&&D!=="touch"&&(this.touch0[1]=N.invert(this.touch0[0])),this.touch1&&D!=="touch"&&(this.touch1[1]=N.invert(this.touch1[0])),this.that.__zoom=N,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(D){var N=St(this.that).datum();u.call(D,this.that,new _H(D,{sourceEvent:this.sourceEvent,target:b,type:D,transform:this.that.__zoom,dispatch:u}),N)}};function R(D,...N){if(!t.apply(this,arguments))return;var z=M(this,N).event(D),X=this.__zoom,ct=Math.max(a[0],Math.min(a[1],X.k*Math.pow(2,n.apply(this,arguments)))),J=Tn(D);if(z.wheel)(z.mouse[0][0]!==J[0]||z.mouse[0][1]!==J[1])&&(z.mouse[1]=X.invert(z.mouse[0]=J)),clearTimeout(z.wheel);else{if(X.k===ct)return;z.mouse=[J,X.invert(J)],vs(this),z.start()}wc(D),z.wheel=setTimeout(Y,m),z.zoom("mouse",r(k(x(X,ct),z.mouse[0],z.mouse[1]),z.extent,s));function Y(){z.wheel=null,z.end()}}function A(D,...N){if(f||!t.apply(this,arguments))return;var z=D.currentTarget,X=M(this,N,!0).event(D),ct=St(D.view).on("mousemove.zoom",lt,!0).on("mouseup.zoom",ut,!0),J=Tn(D,z),Y=D.clientX,$=D.clientY;Bu(D.view),Vp(D),X.mouse=[J,this.__zoom.invert(J)],vs(this),X.start();function lt(W){if(wc(W),!X.moved){var tt=W.clientX-Y,K=W.clientY-$;X.moved=tt*tt+K*K>_}X.event(W).zoom("mouse",r(k(X.that.__zoom,X.mouse[0]=Tn(W,z),X.mouse[1]),X.extent,s))}function ut(W){ct.on("mousemove.zoom mouseup.zoom",null),Du(W.view,X.moved),wc(W),X.event(W).end()}}function L(D,...N){if(!!t.apply(this,arguments)){var z=this.__zoom,X=Tn(D.changedTouches?D.changedTouches[0]:D,this),ct=z.invert(X),J=z.k*(D.shiftKey?.5:2),Y=r(k(x(z,J),X,ct),e.apply(this,N),s);wc(D),o>0?St(this).transition().duration(o).call(C,Y,X,D):St(this).call(b.transform,Y,X,D)}}function v(D,...N){if(!!t.apply(this,arguments)){var z=D.touches,X=z.length,ct=M(this,N,D.changedTouches.length===X).event(D),J,Y,$,lt;for(Vp(D),Y=0;Y<X;++Y)$=z[Y],lt=Tn($,this),lt=[lt,this.__zoom.invert(lt),$.identifier],ct.touch0?!ct.touch1&&ct.touch0[2]!==lt[2]&&(ct.touch1=lt,ct.taps=0):(ct.touch0=lt,J=!0,ct.taps=1+!!h);h&&(h=clearTimeout(h)),J&&(ct.taps<2&&(d=lt[0],h=setTimeout(function(){h=null},p)),vs(this),ct.start())}}function B(D,...N){if(!!this.__zooming){var z=M(this,N).event(D),X=D.changedTouches,ct=X.length,J,Y,$,lt;for(wc(D),J=0;J<ct;++J)Y=X[J],$=Tn(Y,this),z.touch0&&z.touch0[2]===Y.identifier?z.touch0[0]=$:z.touch1&&z.touch1[2]===Y.identifier&&(z.touch1[0]=$);if(Y=z.that.__zoom,z.touch1){var ut=z.touch0[0],W=z.touch0[1],tt=z.touch1[0],K=z.touch1[1],it=(it=tt[0]-ut[0])*it+(it=tt[1]-ut[1])*it,Z=(Z=K[0]-W[0])*Z+(Z=K[1]-W[1])*Z;Y=x(Y,Math.sqrt(it/Z)),$=[(ut[0]+tt[0])/2,(ut[1]+tt[1])/2],lt=[(W[0]+K[0])/2,(W[1]+K[1])/2]}else if(z.touch0)$=z.touch0[0],lt=z.touch0[1];else return;z.zoom("touch",r(k(Y,$,lt),z.extent,s))}}function w(D,...N){if(!!this.__zooming){var z=M(this,N).event(D),X=D.changedTouches,ct=X.length,J,Y;for(Vp(D),f&&clearTimeout(f),f=setTimeout(function(){f=null},p),J=0;J<ct;++J)Y=X[J],z.touch0&&z.touch0[2]===Y.identifier?delete z.touch0:z.touch1&&z.touch1[2]===Y.identifier&&delete z.touch1;if(z.touch1&&!z.touch0&&(z.touch0=z.touch1,delete z.touch1),z.touch0)z.touch0[1]=this.__zoom.invert(z.touch0[0]);else if(z.end(),z.taps===2&&(Y=Tn(Y,this),Math.hypot(d[0]-Y[0],d[1]-Y[1])<y)){var $=St(this).on("dblclick.zoom");$&&$.apply(this,arguments)}}}return b.wheelDelta=function(D){return arguments.length?(n=typeof D=="function"?D:Ef(+D),b):n},b.filter=function(D){return arguments.length?(t=typeof D=="function"?D:Ef(!!D),b):t},b.touchable=function(D){return arguments.length?(i=typeof D=="function"?D:Ef(!!D),b):i},b.extent=function(D){return arguments.length?(e=typeof D=="function"?D:Ef([[+D[0][0],+D[0][1]],[+D[1][0],+D[1][1]]]),b):e},b.scaleExtent=function(D){return arguments.length?(a[0]=+D[0],a[1]=+D[1],b):[a[0],a[1]]},b.translateExtent=function(D){return arguments.length?(s[0][0]=+D[0][0],s[1][0]=+D[1][0],s[0][1]=+D[0][1],s[1][1]=+D[1][1],b):[[s[0][0],s[0][1]],[s[1][0],s[1][1]]]},b.constrain=function(D){return arguments.length?(r=D,b):r},b.duration=function(D){return arguments.length?(o=+D,b):o},b.interpolate=function(D){return arguments.length?(l=D,b):l},b.on=function(){var D=u.on.apply(u,arguments);return D===u?b:D},b.clickDistance=function(D){return arguments.length?(_=(D=+D)*D,b):Math.sqrt(_)},b.tapDistance=function(D){return arguments.length?(y=+D,b):y},b}const CH=Object.freeze(Object.defineProperty({__proto__:null,bisect:cs,bisectRight:x_,bisectLeft:SR,bisectCenter:AR,ascending:Qe,bisector:ku,blur:MR,blur2:k_,blurImage:LR,count:wu,cross:FR,cumsum:PR,descending:m_,deviation:E_,extent:xl,Adder:_r,fsum:qR,fcumsum:VR,group:M_,flatGroup:zR,flatRollup:YR,groups:L_,index:UR,indexes:WR,rollup:I_,rollups:N_,groupSort:HR,bin:F_,histogram:F_,thresholdFreedmanDiaconis:$R,thresholdScott:XR,thresholdSturges:W0,max:lo,maxIndex:H0,mean:KR,median:ZR,medianIndex:QR,merge:j0,min:Tl,minIndex:G0,mode:tI,nice:O_,pairs:eI,permute:D_,quantile:Cl,quantileIndex:V_,quantileSorted:q_,quickselect:Eu,range:Ca,rank:nI,least:iI,leastIndex:z_,greatest:P_,greatestIndex:aI,scan:sI,shuffle:oI,shuffler:Y_,sum:lI,ticks:hs,tickIncrement:oo,tickStep:wl,transpose:U_,variance:T_,zip:uI,every:hI,some:fI,filter:dI,map:pI,reduce:gI,reverse:yI,sort:q0,difference:mI,disjoint:bI,intersection:_I,subset:xI,superset:W_,union:kI,InternMap:kl,InternSet:us,axisTop:j_,axisRight:MI,axisBottom:$_,axisLeft:LI,brush:KO,brushX:$O,brushY:XO,brushSelection:jO,chord:QO,chordTranspose:JO,chordDirected:tF,ribbon:cF,ribbonArrow:uF,color:Aa,rgb:po,hsl:qu,lab:Yu,hcl:Uu,lch:IB,gray:RB,cubehelix:Qn,contours:Ud,contourDensity:wF,Delaunay:jd,Voronoi:Nv,dispatch:fs,drag:_B,dragDisable:Bu,dragEnable:Du,dsvFormat:uh,csvParse:Fv,csvParseRows:GF,csvFormat:jF,csvFormatBody:$F,csvFormatRows:XF,csvFormatRow:KF,csvFormatValue:ZF,tsvParse:Pv,tsvParseRows:QF,tsvFormat:JF,tsvFormatBody:tP,tsvFormatRows:eP,tsvFormatRow:rP,tsvFormatValue:nP,autoType:iP,easeLinear:sO,easeQuad:ov,easeQuadIn:oO,easeQuadOut:lO,easeQuadInOut:ov,easeCubic:Ed,easeCubicIn:cO,easeCubicOut:uO,easeCubicInOut:Ed,easePoly:lv,easePolyIn:hO,easePolyOut:fO,easePolyInOut:lv,easeSin:hv,easeSinIn:dO,easeSinOut:pO,easeSinInOut:hv,easeExp:fv,easeExpIn:gO,easeExpOut:yO,easeExpInOut:fv,easeCircle:dv,easeCircleIn:mO,easeCircleOut:bO,easeCircleInOut:dv,easeBounce:Vl,easeBounceIn:SO,easeBounceOut:Vl,easeBounceInOut:AO,easeBack:pv,easeBackIn:MO,easeBackOut:LO,easeBackInOut:pv,easeElastic:gv,easeElasticIn:RO,easeElasticOut:gv,easeElasticInOut:IO,blob:oP,buffer:cP,dsv:hP,csv:fP,tsv:dP,image:pP,json:yP,text:hh,xml:mP,html:bP,svg:_P,forceCenter:vP,forceCollide:qP,forceLink:zP,forceManyBody:KP,forceRadial:ZP,forceSimulation:XP,forceX:QP,forceY:JP,formatDefaultLocale:Zv,get format(){return yh},get formatPrefix(){return Jd},formatLocale:Kv,formatSpecifier:Co,FormatSpecifier:ph,precisionFixed:Qv,precisionPrefix:Jv,precisionRound:t6,geoArea:cq,geoBounds:dq,geoCentroid:_q,geoCircle:vq,geoClipAntimeridian:m2,geoClipCircle:N6,geoClipExtent:Sq,geoClipRectangle:Fh,geoContains:Bq,geoDistance:Vh,geoGraticule:U6,geoGraticule10:Dq,geoInterpolate:Oq,geoLength:B6,geoPath:$q,geoAlbers:hx,geoAlbersUsa:iV,geoAzimuthalEqualArea:aV,geoAzimuthalEqualAreaRaw:P2,geoAzimuthalEquidistant:sV,geoAzimuthalEquidistantRaw:q2,geoConicConformal:lV,geoConicConformalRaw:px,geoConicEqualArea:Xh,geoConicEqualAreaRaw:ux,geoConicEquidistant:uV,geoConicEquidistantRaw:gx,geoEqualEarth:fV,geoEqualEarthRaw:V2,geoEquirectangular:cV,geoEquirectangularRaw:ac,geoGnomonic:dV,geoGnomonicRaw:z2,geoIdentity:pV,geoProjection:Li,geoProjectionMutator:O2,geoMercator:oV,geoMercatorRaw:ic,geoNaturalEarth1:gV,geoNaturalEarth1Raw:Y2,geoOrthographic:yV,geoOrthographicRaw:U2,geoStereographic:mV,geoStereographicRaw:W2,geoTransverseMercator:bV,geoTransverseMercatorRaw:H2,geoRotation:E6,geoStream:ti,geoTransform:Xq,cluster:CV,hierarchy:G2,Node:Ms,pack:rz,packSiblings:tz,packEnclose:KV,partition:nz,stratify:oz,tree:pz,treemap:gz,treemapBinary:yz,treemapDice:hc,treemapSlice:rf,treemapSliceDice:mz,treemapSquarify:Nx,treemapResquarify:bz,interpolate:Ma,interpolateArray:FB,interpolateBasis:L5,interpolateBasisClosed:R5,interpolateDate:F5,interpolateDiscrete:VB,interpolateHue:zB,interpolateNumber:Bn,interpolateNumberArray:dd,interpolateObject:P5,interpolateRound:ju,interpolateString:yd,interpolateTransformCss:Y5,interpolateTransformSvg:U5,interpolateZoom:H5,interpolateRgb:Nl,interpolateRgbBasis:B5,interpolateRgbBasisClosed:OB,interpolateHsl:jB,interpolateHslLong:$B,interpolateLab:XB,interpolateHcl:$5,interpolateHclLong:KB,interpolateCubehelix:ZB,interpolateCubehelixLong:Xu,piecewise:K5,quantize:QB,path:Ra,polygonArea:_z,polygonCentroid:vz,polygonHull:wz,polygonContains:Tz,polygonLength:Ez,quadtree:fh,randomUniform:Cz,randomInt:Sz,randomNormal:tp,randomLogNormal:Az,randomBates:Mz,randomIrwinHall:Dx,randomExponential:Lz,randomPareto:Rz,randomBernoulli:Iz,randomGeometric:Ox,randomBinomial:Px,randomGamma:ep,randomBeta:Fx,randomWeibull:Nz,randomCauchy:Bz,randomLogistic:Dz,randomPoisson:Oz,randomLcg:qz,scaleBand:np,scalePoint:Vz,scaleIdentity:Ux,scaleLinear:sp,scaleLog:$x,scaleSymlog:Zx,scaleOrdinal:nf,scaleImplicit:rp,scalePow:up,scaleSqrt:Qz,scaleRadial:t8,scaleQuantile:e8,scaleQuantize:r8,scaleThreshold:n8,scaleTime:X8,scaleUtc:MU,scaleSequential:K8,scaleSequentialLog:Z8,scaleSequentialPow:Ap,scaleSequentialSqrt:LU,scaleSequentialSymlog:Q8,scaleSequentialQuantile:J8,scaleDiverging:t7,scaleDivergingLog:e7,scaleDivergingPow:Mp,scaleDivergingSqrt:RU,scaleDivergingSymlog:r7,tickFormat:Yx,schemeCategory10:IU,schemeAccent:NU,schemeDark2:BU,schemePaired:DU,schemePastel1:OU,schemePastel2:FU,schemeSet1:PU,schemeSet2:qU,schemeSet3:VU,schemeTableau10:zU,interpolateBrBG:YU,schemeBrBG:n7,interpolatePRGn:UU,schemePRGn:i7,interpolatePiYG:WU,schemePiYG:a7,interpolatePuOr:HU,schemePuOr:s7,interpolateRdBu:GU,schemeRdBu:o7,interpolateRdGy:jU,schemeRdGy:l7,interpolateRdYlBu:$U,schemeRdYlBu:c7,interpolateRdYlGn:XU,schemeRdYlGn:u7,interpolateSpectral:KU,schemeSpectral:h7,interpolateBuGn:ZU,schemeBuGn:f7,interpolateBuPu:QU,schemeBuPu:d7,interpolateGnBu:JU,schemeGnBu:p7,interpolateOrRd:tW,schemeOrRd:g7,interpolatePuBuGn:eW,schemePuBuGn:y7,interpolatePuBu:rW,schemePuBu:m7,interpolatePuRd:nW,schemePuRd:b7,interpolateRdPu:iW,schemeRdPu:_7,interpolateYlGnBu:aW,schemeYlGnBu:v7,interpolateYlGn:sW,schemeYlGn:x7,interpolateYlOrBr:oW,schemeYlOrBr:k7,interpolateYlOrRd:lW,schemeYlOrRd:w7,interpolateBlues:cW,schemeBlues:T7,interpolateGreens:uW,schemeGreens:E7,interpolateGreys:hW,schemeGreys:C7,interpolatePurples:fW,schemePurples:S7,interpolateReds:dW,schemeReds:A7,interpolateOranges:pW,schemeOranges:M7,interpolateCividis:gW,interpolateCubehelixDefault:yW,interpolateRainbow:_W,interpolateWarm:mW,interpolateCool:bW,interpolateSinebow:kW,interpolateTurbo:wW,interpolateViridis:TW,interpolateMagma:EW,interpolateInferno:CW,interpolatePlasma:SW,create:hB,creator:Lu,local:i5,matcher:Q0,namespace:Al,namespaces:K0,pointer:Tn,pointers:dB,select:St,selectAll:Nu,selection:ps,selector:Ru,selectorAll:Z0,style:ds,window:J0,arc:yf,area:N7,line:Ua,pie:B7,areaRadial:P7,radialArea:P7,lineRadial:F7,radialLine:F7,pointRadial:kc,link:bf,linkHorizontal:UW,linkVertical:WW,linkRadial:HW,symbol:tH,symbolsStroke:JW,symbolsFill:rk,symbols:rk,symbolAsterisk:Y7,symbolCircle:_f,symbolCross:U7,symbolDiamond:H7,symbolDiamond2:G7,symbolPlus:j7,symbolSquare:$7,symbolSquare2:X7,symbolStar:Z7,symbolTriangle:Q7,symbolTriangle2:J7,symbolWye:tk,symbolX:ek,curveBasisClosed:ik,curveBasisOpen:sk,curveBasis:Os,curveBumpX:V7,curveBumpY:z7,curveBundle:eH,curveCardinalClosed:nH,curveCardinalOpen:iH,curveCardinal:rH,curveCatmullRomClosed:sH,curveCatmullRomOpen:oH,curveCatmullRom:aH,curveLinearClosed:fk,curveLinear:yn,curveMonotoneX:bk,curveMonotoneY:_k,curveNatural:kk,curveStep:wk,curveStepAfter:Ek,curveStepBefore:Tk,stack:uH,stackOffsetExpand:hH,stackOffsetDiverging:fH,stackOffsetNone:qo,stackOffsetSilhouette:dH,stackOffsetWiggle:pH,stackOrderAppearance:Ck,stackOrderAscending:Sk,stackOrderDescending:yH,stackOrderInsideOut:mH,stackOrderNone:Vo,stackOrderReverse:bH,timeInterval:xr,timeMillisecond:dp,timeMilliseconds:i8,utcMillisecond:dp,utcMilliseconds:i8,timeSecond:Fa,timeSeconds:o8,utcSecond:Fa,utcSeconds:o8,timeMinute:yp,timeMinutes:tY,timeHour:mp,timeHours:eY,timeDay:dc,timeDays:rY,timeWeek:Do,timeWeeks:g8,timeSunday:Do,timeSundays:g8,timeMonday:pc,timeMondays:nY,timeTuesday:h8,timeTuesdays:iY,timeWednesday:f8,timeWednesdays:aY,timeThursday:Ns,timeThursdays:sY,timeFriday:d8,timeFridays:oY,timeSaturday:p8,timeSaturdays:lY,timeMonth:bp,timeMonths:cY,timeYear:Pa,timeYears:uY,utcMinute:vp,utcMinutes:hY,utcHour:xp,utcHours:fY,utcDay:gc,utcDays:dY,utcWeek:Oo,utcWeeks:T8,utcSunday:Oo,utcSundays:T8,utcMonday:yc,utcMondays:pY,utcTuesday:v8,utcTuesdays:gY,utcWednesday:x8,utcWednesdays:yY,utcThursday:Ds,utcThursdays:mY,utcFriday:k8,utcFridays:bY,utcSaturday:w8,utcSaturdays:_Y,utcMonth:kp,utcMonths:vY,utcYear:qa,utcYears:xY,utcTicks:S8,utcTickInterval:A8,timeTicks:M8,timeTickInterval:L8,timeFormatDefaultLocale:j8,get timeFormat(){return vc},get timeParse(){return G8},get utcFormat(){return lf},get utcParse(){return Cp},timeFormatLocale:R8,isoFormat:wU,isoParse:CU,now:Pl,timer:Ju,timerFlush:J5,timeout:_d,interval:rD,transition:av,active:FO,interrupt:vs,zoom:EH,zoomTransform:Mk,zoomIdentity:Cf,ZoomTransform:Ri},Symbol.toStringTag,{value:"Module"}));/*! @license DOMPurify 2.4.0 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.4.0/LICENSE */function Ha(t){return Ha=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ha(t)}function zp(t,e){return zp=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},zp(t,e)}function SH(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Sf(t,e,r){return SH()?Sf=Reflect.construct:Sf=function(i,a,s){var o=[null];o.push.apply(o,a);var l=Function.bind.apply(i,o),u=new l;return s&&zp(u,s.prototype),u},Sf.apply(null,arguments)}function ni(t){return AH(t)||MH(t)||LH(t)||RH()}function AH(t){if(Array.isArray(t))return Yp(t)}function MH(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function LH(t,e){if(!!t){if(typeof t=="string")return Yp(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);if(r==="Object"&&t.constructor&&(r=t.constructor.name),r==="Map"||r==="Set")return Array.from(t);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Yp(t,e)}}function Yp(t,e){(e==null||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function RH(){throw new TypeError(`Invalid attempt to spread non-iterable instance. +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var IH=Object.hasOwnProperty,Rk=Object.setPrototypeOf,NH=Object.isFrozen,BH=Object.getPrototypeOf,DH=Object.getOwnPropertyDescriptor,sn=Object.freeze,Ii=Object.seal,OH=Object.create,Ik=typeof Reflect<"u"&&Reflect,Af=Ik.apply,Up=Ik.construct;Af||(Af=function(e,r,n){return e.apply(r,n)}),sn||(sn=function(e){return e}),Ii||(Ii=function(e){return e}),Up||(Up=function(e,r){return Sf(e,ni(r))});var FH=ii(Array.prototype.forEach),Nk=ii(Array.prototype.pop),Tc=ii(Array.prototype.push),Mf=ii(String.prototype.toLowerCase),PH=ii(String.prototype.match),Ga=ii(String.prototype.replace),qH=ii(String.prototype.indexOf),VH=ii(String.prototype.trim),on=ii(RegExp.prototype.test),Wp=zH(TypeError);function ii(t){return function(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];return Af(t,e,n)}}function zH(t){return function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return Up(t,r)}}function Me(t,e,r){r=r||Mf,Rk&&Rk(t,null);for(var n=e.length;n--;){var i=e[n];if(typeof i=="string"){var a=r(i);a!==i&&(NH(e)||(e[n]=a),i=a)}t[i]=!0}return t}function Fs(t){var e=OH(null),r;for(r in t)Af(IH,t,[r])&&(e[r]=t[r]);return e}function Lf(t,e){for(;t!==null;){var r=DH(t,e);if(r){if(r.get)return ii(r.get);if(typeof r.value=="function")return ii(r.value)}t=BH(t)}function n(i){return console.warn("fallback value for",i),null}return n}var Bk=sn(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),Hp=sn(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),Gp=sn(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),YH=sn(["animate","color-profile","cursor","discard","fedropshadow","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),jp=sn(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover"]),UH=sn(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Dk=sn(["#text"]),Ok=sn(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","xmlns","slot"]),$p=sn(["accent-height","accumulate","additive","alignment-baseline","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Fk=sn(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Rf=sn(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),WH=Ii(/\{\{[\w\W]*|[\w\W]*\}\}/gm),HH=Ii(/<%[\w\W]*|[\w\W]*%>/gm),GH=Ii(/^data-[\-\w.\u00B7-\uFFFF]/),jH=Ii(/^aria-[\-\w]+$/),$H=Ii(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),XH=Ii(/^(?:\w+script|data):/i),KH=Ii(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),ZH=Ii(/^html$/i),QH=function(){return typeof window>"u"?null:window},JH=function(e,r){if(Ha(e)!=="object"||typeof e.createPolicy!="function")return null;var n=null,i="data-tt-policy-suffix";r.currentScript&&r.currentScript.hasAttribute(i)&&(n=r.currentScript.getAttribute(i));var a="dompurify"+(n?"#"+n:"");try{return e.createPolicy(a,{createHTML:function(o){return o},createScriptURL:function(o){return o}})}catch{return console.warn("TrustedTypes policy "+a+" could not be created."),null}};function Pk(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:QH(),e=function(st){return Pk(st)};if(e.version="2.4.0",e.removed=[],!t||!t.document||t.document.nodeType!==9)return e.isSupported=!1,e;var r=t.document,n=t.document,i=t.DocumentFragment,a=t.HTMLTemplateElement,s=t.Node,o=t.Element,l=t.NodeFilter,u=t.NamedNodeMap,h=u===void 0?t.NamedNodeMap||t.MozNamedAttrMap:u,d=t.HTMLFormElement,f=t.DOMParser,p=t.trustedTypes,m=o.prototype,_=Lf(m,"cloneNode"),y=Lf(m,"nextSibling"),b=Lf(m,"childNodes"),x=Lf(m,"parentNode");if(typeof a=="function"){var k=n.createElement("template");k.content&&k.content.ownerDocument&&(n=k.content.ownerDocument)}var T=JH(p,r),C=T?T.createHTML(""):"",M=n,S=M.implementation,R=M.createNodeIterator,A=M.createDocumentFragment,L=M.getElementsByTagName,v=r.importNode,B={};try{B=Fs(n).documentMode?n.documentMode:{}}catch{}var w={};e.isSupported=typeof x=="function"&&S&&typeof S.createHTMLDocument<"u"&&B!==9;var D=WH,N=HH,z=GH,X=jH,ct=XH,J=KH,Y=$H,$=null,lt=Me({},[].concat(ni(Bk),ni(Hp),ni(Gp),ni(jp),ni(Dk))),ut=null,W=Me({},[].concat(ni(Ok),ni($p),ni(Fk),ni(Rf))),tt=Object.seal(Object.create(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),K=null,it=null,Z=!0,V=!0,Q=!1,q=!1,U=!1,F=!1,j=!1,P=!1,et=!1,at=!1,It=!0,Lt=!1,Rt="user-content-",Ct=!0,pt=!1,mt={},vt=null,Tt=Me({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),ft=null,le=Me({},["audio","video","img","source","image","track"]),Dt=null,Gt=Me({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),$t="http://www.w3.org/1998/Math/MathML",Qt="http://www.w3.org/2000/svg",we="http://www.w3.org/1999/xhtml",jt=we,Ft=!1,zt,wt=["application/xhtml+xml","text/html"],bt="text/html",Et,kt=null,Ut=n.createElement("form"),gt=function(st){return st instanceof RegExp||st instanceof Function},he=function(st){kt&&kt===st||((!st||Ha(st)!=="object")&&(st={}),st=Fs(st),zt=wt.indexOf(st.PARSER_MEDIA_TYPE)===-1?zt=bt:zt=st.PARSER_MEDIA_TYPE,Et=zt==="application/xhtml+xml"?function(At){return At}:Mf,$="ALLOWED_TAGS"in st?Me({},st.ALLOWED_TAGS,Et):lt,ut="ALLOWED_ATTR"in st?Me({},st.ALLOWED_ATTR,Et):W,Dt="ADD_URI_SAFE_ATTR"in st?Me(Fs(Gt),st.ADD_URI_SAFE_ATTR,Et):Gt,ft="ADD_DATA_URI_TAGS"in st?Me(Fs(le),st.ADD_DATA_URI_TAGS,Et):le,vt="FORBID_CONTENTS"in st?Me({},st.FORBID_CONTENTS,Et):Tt,K="FORBID_TAGS"in st?Me({},st.FORBID_TAGS,Et):{},it="FORBID_ATTR"in st?Me({},st.FORBID_ATTR,Et):{},mt="USE_PROFILES"in st?st.USE_PROFILES:!1,Z=st.ALLOW_ARIA_ATTR!==!1,V=st.ALLOW_DATA_ATTR!==!1,Q=st.ALLOW_UNKNOWN_PROTOCOLS||!1,q=st.SAFE_FOR_TEMPLATES||!1,U=st.WHOLE_DOCUMENT||!1,P=st.RETURN_DOM||!1,et=st.RETURN_DOM_FRAGMENT||!1,at=st.RETURN_TRUSTED_TYPE||!1,j=st.FORCE_BODY||!1,It=st.SANITIZE_DOM!==!1,Lt=st.SANITIZE_NAMED_PROPS||!1,Ct=st.KEEP_CONTENT!==!1,pt=st.IN_PLACE||!1,Y=st.ALLOWED_URI_REGEXP||Y,jt=st.NAMESPACE||we,st.CUSTOM_ELEMENT_HANDLING&>(st.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(tt.tagNameCheck=st.CUSTOM_ELEMENT_HANDLING.tagNameCheck),st.CUSTOM_ELEMENT_HANDLING&>(st.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(tt.attributeNameCheck=st.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),st.CUSTOM_ELEMENT_HANDLING&&typeof st.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(tt.allowCustomizedBuiltInElements=st.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),q&&(V=!1),et&&(P=!0),mt&&($=Me({},ni(Dk)),ut=[],mt.html===!0&&(Me($,Bk),Me(ut,Ok)),mt.svg===!0&&(Me($,Hp),Me(ut,$p),Me(ut,Rf)),mt.svgFilters===!0&&(Me($,Gp),Me(ut,$p),Me(ut,Rf)),mt.mathMl===!0&&(Me($,jp),Me(ut,Fk),Me(ut,Rf))),st.ADD_TAGS&&($===lt&&($=Fs($)),Me($,st.ADD_TAGS,Et)),st.ADD_ATTR&&(ut===W&&(ut=Fs(ut)),Me(ut,st.ADD_ATTR,Et)),st.ADD_URI_SAFE_ATTR&&Me(Dt,st.ADD_URI_SAFE_ATTR,Et),st.FORBID_CONTENTS&&(vt===Tt&&(vt=Fs(vt)),Me(vt,st.FORBID_CONTENTS,Et)),Ct&&($["#text"]=!0),U&&Me($,["html","head","body"]),$.table&&(Me($,["tbody"]),delete K.tbody),sn&&sn(st),kt=st)},yt=Me({},["mi","mo","mn","ms","mtext"]),ne=Me({},["foreignobject","desc","title","annotation-xml"]),ve=Me({},["title","style","font","a","script"]),ye=Me({},Hp);Me(ye,Gp),Me(ye,YH);var be=Me({},jp);Me(be,UH);var Te=function(st){var At=x(st);(!At||!At.tagName)&&(At={namespaceURI:we,tagName:"template"});var Nt=Mf(st.tagName),Jt=Mf(At.tagName);return st.namespaceURI===Qt?At.namespaceURI===we?Nt==="svg":At.namespaceURI===$t?Nt==="svg"&&(Jt==="annotation-xml"||yt[Jt]):Boolean(ye[Nt]):st.namespaceURI===$t?At.namespaceURI===we?Nt==="math":At.namespaceURI===Qt?Nt==="math"&&ne[Jt]:Boolean(be[Nt]):st.namespaceURI===we?At.namespaceURI===Qt&&!ne[Jt]||At.namespaceURI===$t&&!yt[Jt]?!1:!be[Nt]&&(ve[Nt]||!ye[Nt]):!1},Wt=function(st){Tc(e.removed,{element:st});try{st.parentNode.removeChild(st)}catch{try{st.outerHTML=C}catch{st.remove()}}},se=function(st,At){try{Tc(e.removed,{attribute:At.getAttributeNode(st),from:At})}catch{Tc(e.removed,{attribute:null,from:At})}if(At.removeAttribute(st),st==="is"&&!ut[st])if(P||et)try{Wt(At)}catch{}else try{At.setAttribute(st,"")}catch{}},me=function(st){var At,Nt;if(j)st="<remove></remove>"+st;else{var Jt=PH(st,/^[\r\n\t ]+/);Nt=Jt&&Jt[0]}zt==="application/xhtml+xml"&&(st='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+st+"</body></html>");var ze=T?T.createHTML(st):st;if(jt===we)try{At=new f().parseFromString(ze,zt)}catch{}if(!At||!At.documentElement){At=S.createDocument(jt,"template",null);try{At.documentElement.innerHTML=Ft?"":ze}catch{}}var Pe=At.body||At.documentElement;return st&&Nt&&Pe.insertBefore(n.createTextNode(Nt),Pe.childNodes[0]||null),jt===we?L.call(At,U?"html":"body")[0]:U?At.documentElement:Pe},ue=function(st){return R.call(st.ownerDocument||st,st,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT,null,!1)},_a=function(st){return st instanceof d&&(typeof st.nodeName!="string"||typeof st.textContent!="string"||typeof st.removeChild!="function"||!(st.attributes instanceof h)||typeof st.removeAttribute!="function"||typeof st.setAttribute!="function"||typeof st.namespaceURI!="string"||typeof st.insertBefore!="function")},Hr=function(st){return Ha(s)==="object"?st instanceof s:st&&Ha(st)==="object"&&typeof st.nodeType=="number"&&typeof st.nodeName=="string"},Ie=function(st,At,Nt){!w[st]||FH(w[st],function(Jt){Jt.call(e,At,Nt,kt)})},oe=function(st){var At;if(Ie("beforeSanitizeElements",st,null),_a(st)||on(/[\u0080-\uFFFF]/,st.nodeName))return Wt(st),!0;var Nt=Et(st.nodeName);if(Ie("uponSanitizeElement",st,{tagName:Nt,allowedTags:$}),st.hasChildNodes()&&!Hr(st.firstElementChild)&&(!Hr(st.content)||!Hr(st.content.firstElementChild))&&on(/<[/\w]/g,st.innerHTML)&&on(/<[/\w]/g,st.textContent)||Nt==="select"&&on(/<template/i,st.innerHTML))return Wt(st),!0;if(!$[Nt]||K[Nt]){if(!K[Nt]&&wr(Nt)&&(tt.tagNameCheck instanceof RegExp&&on(tt.tagNameCheck,Nt)||tt.tagNameCheck instanceof Function&&tt.tagNameCheck(Nt)))return!1;if(Ct&&!vt[Nt]){var Jt=x(st)||st.parentNode,ze=b(st)||st.childNodes;if(ze&&Jt)for(var Pe=ze.length,qe=Pe-1;qe>=0;--qe)Jt.insertBefore(_(ze[qe],!0),y(st))}return Wt(st),!0}return st instanceof o&&!Te(st)||(Nt==="noscript"||Nt==="noembed")&&on(/<\/no(script|embed)/i,st.innerHTML)?(Wt(st),!0):(q&&st.nodeType===3&&(At=st.textContent,At=Ga(At,D," "),At=Ga(At,N," "),st.textContent!==At&&(Tc(e.removed,{element:st.cloneNode()}),st.textContent=At)),Ie("afterSanitizeElements",st,null),!1)},Ke=function(st,At,Nt){if(It&&(At==="id"||At==="name")&&(Nt in n||Nt in Ut))return!1;if(!(V&&!it[At]&&on(z,At))){if(!(Z&&on(X,At))){if(!ut[At]||it[At]){if(!(wr(st)&&(tt.tagNameCheck instanceof RegExp&&on(tt.tagNameCheck,st)||tt.tagNameCheck instanceof Function&&tt.tagNameCheck(st))&&(tt.attributeNameCheck instanceof RegExp&&on(tt.attributeNameCheck,At)||tt.attributeNameCheck instanceof Function&&tt.attributeNameCheck(At))||At==="is"&&tt.allowCustomizedBuiltInElements&&(tt.tagNameCheck instanceof RegExp&&on(tt.tagNameCheck,Nt)||tt.tagNameCheck instanceof Function&&tt.tagNameCheck(Nt))))return!1}else if(!Dt[At]){if(!on(Y,Ga(Nt,J,""))){if(!((At==="src"||At==="xlink:href"||At==="href")&&st!=="script"&&qH(Nt,"data:")===0&&ft[st])){if(!(Q&&!on(ct,Ga(Nt,J,"")))){if(Nt)return!1}}}}}}return!0},wr=function(st){return st.indexOf("-")>0},Ge=function(st){var At,Nt,Jt,ze;Ie("beforeSanitizeAttributes",st,null);var Pe=st.attributes;if(!!Pe){var qe={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ut};for(ze=Pe.length;ze--;){At=Pe[ze];var Tr=At,Ve=Tr.name,va=Tr.namespaceURI;if(Nt=Ve==="value"?At.value:VH(At.value),Jt=Et(Ve),qe.attrName=Jt,qe.attrValue=Nt,qe.keepAttr=!0,qe.forceKeepAttr=void 0,Ie("uponSanitizeAttribute",st,qe),Nt=qe.attrValue,!qe.forceKeepAttr&&(se(Ve,st),!!qe.keepAttr)){if(on(/\/>/i,Nt)){se(Ve,st);continue}q&&(Nt=Ga(Nt,D," "),Nt=Ga(Nt,N," "));var Ce=Et(st.nodeName);if(!!Ke(Ce,Jt,Nt)){if(Lt&&(Jt==="id"||Jt==="name")&&(se(Ve,st),Nt=Rt+Nt),T&&Ha(p)==="object"&&typeof p.getAttributeType=="function"&&!va)switch(p.getAttributeType(Ce,Jt)){case"TrustedHTML":Nt=T.createHTML(Nt);break;case"TrustedScriptURL":Nt=T.createScriptURL(Nt);break}try{va?st.setAttributeNS(va,Ve,Nt):st.setAttribute(Ve,Nt),Nk(e.removed)}catch{}}}}Ie("afterSanitizeAttributes",st,null)}},Ze=function qt(st){var At,Nt=ue(st);for(Ie("beforeSanitizeShadowDOM",st,null);At=Nt.nextNode();)Ie("uponSanitizeShadowNode",At,null),!oe(At)&&(At.content instanceof i&&qt(At.content),Ge(At));Ie("afterSanitizeShadowDOM",st,null)};return e.sanitize=function(qt){var st=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},At,Nt,Jt,ze,Pe;if(Ft=!qt,Ft&&(qt="<!-->"),typeof qt!="string"&&!Hr(qt)){if(typeof qt.toString!="function")throw Wp("toString is not a function");if(qt=qt.toString(),typeof qt!="string")throw Wp("dirty is not a string, aborting")}if(!e.isSupported){if(Ha(t.toStaticHTML)==="object"||typeof t.toStaticHTML=="function"){if(typeof qt=="string")return t.toStaticHTML(qt);if(Hr(qt))return t.toStaticHTML(qt.outerHTML)}return qt}if(F||he(st),e.removed=[],typeof qt=="string"&&(pt=!1),pt){if(qt.nodeName){var qe=Et(qt.nodeName);if(!$[qe]||K[qe])throw Wp("root node is forbidden and cannot be sanitized in-place")}}else if(qt instanceof s)At=me("<!---->"),Nt=At.ownerDocument.importNode(qt,!0),Nt.nodeType===1&&Nt.nodeName==="BODY"||Nt.nodeName==="HTML"?At=Nt:At.appendChild(Nt);else{if(!P&&!q&&!U&&qt.indexOf("<")===-1)return T&&at?T.createHTML(qt):qt;if(At=me(qt),!At)return P?null:at?C:""}At&&j&&Wt(At.firstChild);for(var Tr=ue(pt?qt:At);Jt=Tr.nextNode();)Jt.nodeType===3&&Jt===ze||oe(Jt)||(Jt.content instanceof i&&Ze(Jt.content),Ge(Jt),ze=Jt);if(ze=null,pt)return qt;if(P){if(et)for(Pe=A.call(At.ownerDocument);At.firstChild;)Pe.appendChild(At.firstChild);else Pe=At;return ut.shadowroot&&(Pe=v.call(r,Pe,!0)),Pe}var Ve=U?At.outerHTML:At.innerHTML;return U&&$["!doctype"]&&At.ownerDocument&&At.ownerDocument.doctype&&At.ownerDocument.doctype.name&&on(ZH,At.ownerDocument.doctype.name)&&(Ve="<!DOCTYPE "+At.ownerDocument.doctype.name+`> +`+Ve),q&&(Ve=Ga(Ve,D," "),Ve=Ga(Ve,N," ")),T&&at?T.createHTML(Ve):Ve},e.setConfig=function(qt){he(qt),F=!0},e.clearConfig=function(){kt=null,F=!1},e.isValidAttribute=function(qt,st,At){kt||he({});var Nt=Et(qt),Jt=Et(st);return Ke(Nt,Jt,At)},e.addHook=function(qt,st){typeof st=="function"&&(w[qt]=w[qt]||[],Tc(w[qt],st))},e.removeHook=function(qt){if(w[qt])return Nk(w[qt])},e.removeHooks=function(qt){w[qt]&&(w[qt]=[])},e.removeAllHooks=function(){w={}},e}var Ec=Pk();const tG=t=>t?zk(t).replace(/\\n/g,"#br#").split("#br#"):[""],qk=t=>Ec.sanitize(t),Vk=(t,e)=>{var r;if(((r=e.flowchart)==null?void 0:r.htmlLabels)!==!1){const n=e.securityLevel;n==="antiscript"||n==="strict"?t=qk(t):n!=="loose"&&(t=zk(t),t=t.replace(/</g,"<").replace(/>/g,">"),t=t.replace(/=/g,"="),t=iG(t))}return t},ai=(t,e)=>t&&(e.dompurifyConfig?t=Ec.sanitize(Vk(t,e),e.dompurifyConfig).toString():t=Ec.sanitize(Vk(t,e)),t),eG=(t,e)=>typeof t=="string"?ai(t,e):t.flat().map(r=>ai(r,e)),If=/<br\s*\/?>/gi,rG=t=>If.test(t),nG=t=>t.split(If),iG=t=>t.replace(/#br#/g,"<br/>"),zk=t=>t.replace(If,"#br#"),aG=t=>{let e="";return t&&(e=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,e=e.replaceAll(/\(/g,"\\("),e=e.replaceAll(/\)/g,"\\)")),e},Mr=t=>!(t===!1||["false","null","0"].includes(String(t).trim().toLowerCase())),ja=function(t){let e=t;return t.indexOf("~")!==-1?(e=e.replace(/~([^~].*)/,"<$1"),e=e.replace(/~([^~]*)$/,">$1"),ja(e)):e},pe={getRows:tG,sanitizeText:ai,sanitizeTextOrArray:eG,hasBreaks:rG,splitBreaks:nG,lineBreakRegex:If,removeScript:qk,getUrl:aG,evaluate:Mr},Nf={min:{r:0,g:0,b:0,s:0,l:0,a:0},max:{r:255,g:255,b:255,h:360,s:100,l:100,a:1},clamp:{r:t=>t>=255?255:t<0?0:t,g:t=>t>=255?255:t<0?0:t,b:t=>t>=255?255:t<0?0:t,h:t=>t%360,s:t=>t>=100?100:t<0?0:t,l:t=>t>=100?100:t<0?0:t,a:t=>t>=1?1:t<0?0:t},toLinear:t=>{const e=t/255;return t>.03928?Math.pow((e+.055)/1.055,2.4):e/12.92},hue2rgb:(t,e,r)=>(r<0&&(r+=1),r>1&&(r-=1),r<1/6?t+(e-t)*6*r:r<1/2?e:r<2/3?t+(e-t)*(2/3-r)*6:t),hsl2rgb:({h:t,s:e,l:r},n)=>{if(!e)return r*2.55;t/=360,e/=100,r/=100;const i=r<.5?r*(1+e):r+e-r*e,a=2*r-i;switch(n){case"r":return Nf.hue2rgb(a,i,t+1/3)*255;case"g":return Nf.hue2rgb(a,i,t)*255;case"b":return Nf.hue2rgb(a,i,t-1/3)*255}},rgb2hsl:({r:t,g:e,b:r},n)=>{t/=255,e/=255,r/=255;const i=Math.max(t,e,r),a=Math.min(t,e,r),s=(i+a)/2;if(n==="l")return s*100;if(i===a)return 0;const o=i-a,l=s>.5?o/(2-i-a):o/(i+a);if(n==="s")return l*100;switch(i){case t:return((e-r)/o+(e<r?6:0))*60;case e:return((r-t)/o+2)*60;case r:return((t-e)/o+4)*60;default:return-1}}},ke={channel:Nf,lang:{clamp:(t,e,r)=>e>r?Math.min(e,Math.max(r,t)):Math.min(r,Math.max(e,t)),round:t=>Math.round(t*1e10)/1e10},unit:{dec2hex:t=>{const e=Math.round(t).toString(16);return e.length>1?e:`0${e}`}}},$a={};for(let t=0;t<=255;t++)$a[t]=ke.unit.dec2hex(t);const zr={ALL:0,RGB:1,HSL:2};class sG{constructor(){this.type=zr.ALL}get(){return this.type}set(e){if(this.type&&this.type!==e)throw new Error("Cannot change both RGB and HSL channels at the same time");this.type=e}reset(){this.type=zr.ALL}is(e){return this.type===e}}const oG=sG;class lG{constructor(e,r){this.color=r,this.changed=!1,this.data=e,this.type=new oG}set(e,r){return this.color=r,this.changed=!1,this.data=e,this.type.type=zr.ALL,this}_ensureHSL(){const e=this.data,{h:r,s:n,l:i}=e;r===void 0&&(e.h=ke.channel.rgb2hsl(e,"h")),n===void 0&&(e.s=ke.channel.rgb2hsl(e,"s")),i===void 0&&(e.l=ke.channel.rgb2hsl(e,"l"))}_ensureRGB(){const e=this.data,{r,g:n,b:i}=e;r===void 0&&(e.r=ke.channel.hsl2rgb(e,"r")),n===void 0&&(e.g=ke.channel.hsl2rgb(e,"g")),i===void 0&&(e.b=ke.channel.hsl2rgb(e,"b"))}get r(){const e=this.data,r=e.r;return!this.type.is(zr.HSL)&&r!==void 0?r:(this._ensureHSL(),ke.channel.hsl2rgb(e,"r"))}get g(){const e=this.data,r=e.g;return!this.type.is(zr.HSL)&&r!==void 0?r:(this._ensureHSL(),ke.channel.hsl2rgb(e,"g"))}get b(){const e=this.data,r=e.b;return!this.type.is(zr.HSL)&&r!==void 0?r:(this._ensureHSL(),ke.channel.hsl2rgb(e,"b"))}get h(){const e=this.data,r=e.h;return!this.type.is(zr.RGB)&&r!==void 0?r:(this._ensureRGB(),ke.channel.rgb2hsl(e,"h"))}get s(){const e=this.data,r=e.s;return!this.type.is(zr.RGB)&&r!==void 0?r:(this._ensureRGB(),ke.channel.rgb2hsl(e,"s"))}get l(){const e=this.data,r=e.l;return!this.type.is(zr.RGB)&&r!==void 0?r:(this._ensureRGB(),ke.channel.rgb2hsl(e,"l"))}get a(){return this.data.a}set r(e){this.type.set(zr.RGB),this.changed=!0,this.data.r=e}set g(e){this.type.set(zr.RGB),this.changed=!0,this.data.g=e}set b(e){this.type.set(zr.RGB),this.changed=!0,this.data.b=e}set h(e){this.type.set(zr.HSL),this.changed=!0,this.data.h=e}set s(e){this.type.set(zr.HSL),this.changed=!0,this.data.s=e}set l(e){this.type.set(zr.HSL),this.changed=!0,this.data.l=e}set a(e){this.changed=!0,this.data.a=e}}const cG=lG,Bf=new cG({r:0,g:0,b:0,a:0},"transparent"),Yk={re:/^#((?:[a-f0-9]{2}){2,4}|[a-f0-9]{3})$/i,parse:t=>{if(t.charCodeAt(0)!==35)return;const e=t.match(Yk.re);if(!e)return;const r=e[1],n=parseInt(r,16),i=r.length,a=i%4===0,s=i>4,o=s?1:17,l=s?8:4,u=a?0:-1,h=s?255:15;return Bf.set({r:(n>>l*(u+3)&h)*o,g:(n>>l*(u+2)&h)*o,b:(n>>l*(u+1)&h)*o,a:a?(n&h)*o/255:1},t)},stringify:t=>{const{r:e,g:r,b:n,a:i}=t;return i<1?`#${$a[Math.round(e)]}${$a[Math.round(r)]}${$a[Math.round(n)]}${$a[Math.round(i*255)]}`:`#${$a[Math.round(e)]}${$a[Math.round(r)]}${$a[Math.round(n)]}`}},Cc=Yk,Df={re:/^hsla?\(\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?(?:deg|grad|rad|turn)?)\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?%)\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?%)(?:\s*?(?:,|\/)\s*?\+?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?(%)?))?\s*?\)$/i,hueRe:/^(.+?)(deg|grad|rad|turn)$/i,_hue2deg:t=>{const e=t.match(Df.hueRe);if(e){const[,r,n]=e;switch(n){case"grad":return ke.channel.clamp.h(parseFloat(r)*.9);case"rad":return ke.channel.clamp.h(parseFloat(r)*180/Math.PI);case"turn":return ke.channel.clamp.h(parseFloat(r)*360)}}return ke.channel.clamp.h(parseFloat(t))},parse:t=>{const e=t.charCodeAt(0);if(e!==104&&e!==72)return;const r=t.match(Df.re);if(!r)return;const[,n,i,a,s,o]=r;return Bf.set({h:Df._hue2deg(n),s:ke.channel.clamp.s(parseFloat(i)),l:ke.channel.clamp.l(parseFloat(a)),a:s?ke.channel.clamp.a(o?parseFloat(s)/100:parseFloat(s)):1},t)},stringify:t=>{const{h:e,s:r,l:n,a:i}=t;return i<1?`hsla(${ke.lang.round(e)}, ${ke.lang.round(r)}%, ${ke.lang.round(n)}%, ${i})`:`hsl(${ke.lang.round(e)}, ${ke.lang.round(r)}%, ${ke.lang.round(n)}%)`}},Of=Df,Ff={colors:{aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyanaqua:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",transparent:"#00000000",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},parse:t=>{t=t.toLowerCase();const e=Ff.colors[t];if(!!e)return Cc.parse(e)},stringify:t=>{const e=Cc.stringify(t);for(const r in Ff.colors)if(Ff.colors[r]===e)return r}},Uk=Ff,Wk={re:/^rgba?\(\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))(?:\s*?(?:,|\/)\s*?\+?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?)))?\s*?\)$/i,parse:t=>{const e=t.charCodeAt(0);if(e!==114&&e!==82)return;const r=t.match(Wk.re);if(!r)return;const[,n,i,a,s,o,l,u,h]=r;return Bf.set({r:ke.channel.clamp.r(i?parseFloat(n)*2.55:parseFloat(n)),g:ke.channel.clamp.g(s?parseFloat(a)*2.55:parseFloat(a)),b:ke.channel.clamp.b(l?parseFloat(o)*2.55:parseFloat(o)),a:u?ke.channel.clamp.a(h?parseFloat(u)/100:parseFloat(u)):1},t)},stringify:t=>{const{r:e,g:r,b:n,a:i}=t;return i<1?`rgba(${ke.lang.round(e)}, ${ke.lang.round(r)}, ${ke.lang.round(n)}, ${ke.lang.round(i)})`:`rgb(${ke.lang.round(e)}, ${ke.lang.round(r)}, ${ke.lang.round(n)})`}},Pf=Wk,ia={format:{keyword:Uk,hex:Cc,rgb:Pf,rgba:Pf,hsl:Of,hsla:Of},parse:t=>{if(typeof t!="string")return t;const e=Cc.parse(t)||Pf.parse(t)||Of.parse(t)||Uk.parse(t);if(e)return e;throw new Error(`Unsupported color format: "${t}"`)},stringify:t=>!t.changed&&t.color?t.color:t.type.is(zr.HSL)||t.data.r===void 0?Of.stringify(t):t.a<1||!Number.isInteger(t.r)||!Number.isInteger(t.g)||!Number.isInteger(t.b)?Pf.stringify(t):Cc.stringify(t)},Hk=(t,e)=>{const r=ia.parse(t);for(const n in e)r[n]=ke.channel.clamp[n](e[n]);return ia.stringify(r)},Sc=(t,e,r=0,n=1)=>{if(typeof t!="number")return Hk(t,{a:e});const i=Bf.set({r:ke.channel.clamp.r(t),g:ke.channel.clamp.g(e),b:ke.channel.clamp.b(r),a:ke.channel.clamp.a(n)});return ia.stringify(i)},Gk=(t,e,r)=>{const n=ia.parse(t),i=n[e],a=ke.channel.clamp[e](i+r);return i!==a&&(n[e]=a),ia.stringify(n)},ae=(t,e)=>Gk(t,"l",e),ge=(t,e)=>Gk(t,"l",-e),_t=(t,e)=>{const r=ia.parse(t),n={};for(const i in e)!e[i]||(n[i]=r[i]+e[i]);return Hk(t,n)},uG=(t,e,r=50)=>{const{r:n,g:i,b:a,a:s}=ia.parse(t),{r:o,g:l,b:u,a:h}=ia.parse(e),d=r/100,f=d*2-1,p=s-h,_=((f*p===-1?f:(f+p)/(1+f*p))+1)/2,y=1-_,b=n*_+o*y,x=i*_+l*y,k=a*_+u*y,T=s*d+h*(1-d);return Sc(b,x,k,T)},Yt=(t,e=100)=>{const r=ia.parse(t);return r.r=255-r.r,r.g=255-r.g,r.b=255-r.b,uG(r,t,e)},ln=(t,e)=>e?_t(t,{s:-40,l:10}):_t(t,{s:-40,l:-10}),qf="#ffffff",Vf="#f2f2f2";class hG{constructor(){this.background="#f4f4f4",this.darkMode=!1,this.primaryColor="#fff4dd",this.noteBkgColor="#fff5ad",this.noteTextColor="#333",this.THEME_COLOR_LIMIT=12,this.fontFamily='"trebuchet ms", verdana, arial, sans-serif',this.fontSize="16px"}updateColors(){if(this.primaryTextColor=this.primaryTextColor||(this.darkMode?"#eee":"#333"),this.secondaryColor=this.secondaryColor||_t(this.primaryColor,{h:-120}),this.tertiaryColor=this.tertiaryColor||_t(this.primaryColor,{h:180,l:5}),this.primaryBorderColor=this.primaryBorderColor||ln(this.primaryColor,this.darkMode),this.secondaryBorderColor=this.secondaryBorderColor||ln(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=this.tertiaryBorderColor||ln(this.tertiaryColor,this.darkMode),this.noteBorderColor=this.noteBorderColor||ln(this.noteBkgColor,this.darkMode),this.noteBkgColor=this.noteBkgColor||"#fff5ad",this.noteTextColor=this.noteTextColor||"#333",this.secondaryTextColor=this.secondaryTextColor||Yt(this.secondaryColor),this.tertiaryTextColor=this.tertiaryTextColor||Yt(this.tertiaryColor),this.lineColor=this.lineColor||Yt(this.background),this.textColor=this.textColor||this.primaryTextColor,this.nodeBkg=this.nodeBkg||this.primaryColor,this.mainBkg=this.mainBkg||this.primaryColor,this.nodeBorder=this.nodeBorder||this.primaryBorderColor,this.clusterBkg=this.clusterBkg||this.tertiaryColor,this.clusterBorder=this.clusterBorder||this.tertiaryBorderColor,this.defaultLinkColor=this.defaultLinkColor||this.lineColor,this.titleColor=this.titleColor||this.tertiaryTextColor,this.edgeLabelBackground=this.edgeLabelBackground||(this.darkMode?ge(this.secondaryColor,30):this.secondaryColor),this.nodeTextColor=this.nodeTextColor||this.primaryTextColor,this.actorBorder=this.actorBorder||this.primaryBorderColor,this.actorBkg=this.actorBkg||this.mainBkg,this.actorTextColor=this.actorTextColor||this.primaryTextColor,this.actorLineColor=this.actorLineColor||"grey",this.labelBoxBkgColor=this.labelBoxBkgColor||this.actorBkg,this.signalColor=this.signalColor||this.textColor,this.signalTextColor=this.signalTextColor||this.textColor,this.labelBoxBorderColor=this.labelBoxBorderColor||this.actorBorder,this.labelTextColor=this.labelTextColor||this.actorTextColor,this.loopTextColor=this.loopTextColor||this.actorTextColor,this.activationBorderColor=this.activationBorderColor||ge(this.secondaryColor,10),this.activationBkgColor=this.activationBkgColor||this.secondaryColor,this.sequenceNumberColor=this.sequenceNumberColor||Yt(this.lineColor),this.sectionBkgColor=this.sectionBkgColor||this.tertiaryColor,this.altSectionBkgColor=this.altSectionBkgColor||"white",this.sectionBkgColor=this.sectionBkgColor||this.secondaryColor,this.sectionBkgColor2=this.sectionBkgColor2||this.primaryColor,this.excludeBkgColor=this.excludeBkgColor||"#eeeeee",this.taskBorderColor=this.taskBorderColor||this.primaryBorderColor,this.taskBkgColor=this.taskBkgColor||this.primaryColor,this.activeTaskBorderColor=this.activeTaskBorderColor||this.primaryColor,this.activeTaskBkgColor=this.activeTaskBkgColor||ae(this.primaryColor,23),this.gridColor=this.gridColor||"lightgrey",this.doneTaskBkgColor=this.doneTaskBkgColor||"lightgrey",this.doneTaskBorderColor=this.doneTaskBorderColor||"grey",this.critBorderColor=this.critBorderColor||"#ff8888",this.critBkgColor=this.critBkgColor||"red",this.todayLineColor=this.todayLineColor||"red",this.taskTextColor=this.taskTextColor||this.textColor,this.taskTextOutsideColor=this.taskTextOutsideColor||this.textColor,this.taskTextLightColor=this.taskTextLightColor||this.textColor,this.taskTextColor=this.taskTextColor||this.primaryTextColor,this.taskTextDarkColor=this.taskTextDarkColor||this.textColor,this.taskTextClickableColor=this.taskTextClickableColor||"#003163",this.personBorder=this.personBorder||this.primaryBorderColor,this.personBkg=this.personBkg||this.mainBkg,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||this.tertiaryColor,this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.nodeBorder,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.specialStateColor=this.lineColor,this.cScale0=this.cScale0||this.primaryColor,this.cScale1=this.cScale1||this.secondaryColor,this.cScale2=this.cScale2||this.tertiaryColor,this.cScale3=this.cScale3||_t(this.primaryColor,{h:30}),this.cScale4=this.cScale4||_t(this.primaryColor,{h:60}),this.cScale5=this.cScale5||_t(this.primaryColor,{h:90}),this.cScale6=this.cScale6||_t(this.primaryColor,{h:120}),this.cScale7=this.cScale7||_t(this.primaryColor,{h:150}),this.cScale8=this.cScale8||_t(this.primaryColor,{h:210,l:150}),this.cScale9=this.cScale9||_t(this.primaryColor,{h:270}),this.cScale10=this.cScale10||_t(this.primaryColor,{h:300}),this.cScale11=this.cScale11||_t(this.primaryColor,{h:330}),this.darkMode)for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScale"+e]=ge(this["cScale"+e],75);else for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScale"+e]=ge(this["cScale"+e],25);for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScaleInv"+e]=this["cScaleInv"+e]||Yt(this["cScale"+e]);for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this.darkMode?this["cScalePeer"+e]=this["cScalePeer"+e]||ae(this["cScale"+e],10):this["cScalePeer"+e]=this["cScalePeer"+e]||ge(this["cScale"+e],10);this.scaleLabelColor=this.scaleLabelColor||this.labelTextColor;for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScaleLabel"+e]=this["cScaleLabel"+e]||this.scaleLabelColor;this.classText=this.classText||this.textColor,this.fillType0=this.fillType0||this.primaryColor,this.fillType1=this.fillType1||this.secondaryColor,this.fillType2=this.fillType2||_t(this.primaryColor,{h:64}),this.fillType3=this.fillType3||_t(this.secondaryColor,{h:64}),this.fillType4=this.fillType4||_t(this.primaryColor,{h:-64}),this.fillType5=this.fillType5||_t(this.secondaryColor,{h:-64}),this.fillType6=this.fillType6||_t(this.primaryColor,{h:128}),this.fillType7=this.fillType7||_t(this.secondaryColor,{h:128}),this.pie1=this.pie1||this.primaryColor,this.pie2=this.pie2||this.secondaryColor,this.pie3=this.pie3||this.tertiaryColor,this.pie4=this.pie4||_t(this.primaryColor,{l:-10}),this.pie5=this.pie5||_t(this.secondaryColor,{l:-10}),this.pie6=this.pie6||_t(this.tertiaryColor,{l:-10}),this.pie7=this.pie7||_t(this.primaryColor,{h:60,l:-10}),this.pie8=this.pie8||_t(this.primaryColor,{h:-60,l:-10}),this.pie9=this.pie9||_t(this.primaryColor,{h:120,l:0}),this.pie10=this.pie10||_t(this.primaryColor,{h:60,l:-20}),this.pie11=this.pie11||_t(this.primaryColor,{h:-60,l:-20}),this.pie12=this.pie12||_t(this.primaryColor,{h:120,l:-10}),this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOpacity=this.pieOpacity||"0.7",this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||this.primaryBorderColor,this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||(this.darkMode?ge(this.secondaryColor,30):this.secondaryColor),this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=this.git0||this.primaryColor,this.git1=this.git1||this.secondaryColor,this.git2=this.git2||this.tertiaryColor,this.git3=this.git3||_t(this.primaryColor,{h:-30}),this.git4=this.git4||_t(this.primaryColor,{h:-60}),this.git5=this.git5||_t(this.primaryColor,{h:-90}),this.git6=this.git6||_t(this.primaryColor,{h:60}),this.git7=this.git7||_t(this.primaryColor,{h:120}),this.darkMode?(this.git0=ae(this.git0,25),this.git1=ae(this.git1,25),this.git2=ae(this.git2,25),this.git3=ae(this.git3,25),this.git4=ae(this.git4,25),this.git5=ae(this.git5,25),this.git6=ae(this.git6,25),this.git7=ae(this.git7,25)):(this.git0=ge(this.git0,25),this.git1=ge(this.git1,25),this.git2=ge(this.git2,25),this.git3=ge(this.git3,25),this.git4=ge(this.git4,25),this.git5=ge(this.git5,25),this.git6=ge(this.git6,25),this.git7=ge(this.git7,25)),this.gitInv0=this.gitInv0||Yt(this.git0),this.gitInv1=this.gitInv1||Yt(this.git1),this.gitInv2=this.gitInv2||Yt(this.git2),this.gitInv3=this.gitInv3||Yt(this.git3),this.gitInv4=this.gitInv4||Yt(this.git4),this.gitInv5=this.gitInv5||Yt(this.git5),this.gitInv6=this.gitInv6||Yt(this.git6),this.gitInv7=this.gitInv7||Yt(this.git7),this.branchLabelColor=this.branchLabelColor||(this.darkMode?"black":this.labelTextColor),this.gitBranchLabel0=this.gitBranchLabel0||this.branchLabelColor,this.gitBranchLabel1=this.gitBranchLabel1||this.branchLabelColor,this.gitBranchLabel2=this.gitBranchLabel2||this.branchLabelColor,this.gitBranchLabel3=this.gitBranchLabel3||this.branchLabelColor,this.gitBranchLabel4=this.gitBranchLabel4||this.branchLabelColor,this.gitBranchLabel5=this.gitBranchLabel5||this.branchLabelColor,this.gitBranchLabel6=this.gitBranchLabel6||this.branchLabelColor,this.gitBranchLabel7=this.gitBranchLabel7||this.branchLabelColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||qf,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||Vf}calculate(e){if(typeof e!="object"){this.updateColors();return}const r=Object.keys(e);r.forEach(n=>{this[n]=e[n]}),this.updateColors(),r.forEach(n=>{this[n]=e[n]})}}const fG=t=>{const e=new hG;return e.calculate(t),e};class dG{constructor(){this.background="#333",this.primaryColor="#1f2020",this.secondaryColor=ae(this.primaryColor,16),this.tertiaryColor=_t(this.primaryColor,{h:-160}),this.primaryBorderColor=Yt(this.background),this.secondaryBorderColor=ln(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=ln(this.tertiaryColor,this.darkMode),this.primaryTextColor=Yt(this.primaryColor),this.secondaryTextColor=Yt(this.secondaryColor),this.tertiaryTextColor=Yt(this.tertiaryColor),this.lineColor=Yt(this.background),this.textColor=Yt(this.background),this.mainBkg="#1f2020",this.secondBkg="calculated",this.mainContrastColor="lightgrey",this.darkTextColor=ae(Yt("#323D47"),10),this.lineColor="calculated",this.border1="#81B1DB",this.border2=Sc(255,255,255,.25),this.arrowheadColor="calculated",this.fontFamily='"trebuchet ms", verdana, arial, sans-serif',this.fontSize="16px",this.labelBackground="#181818",this.textColor="#ccc",this.THEME_COLOR_LIMIT=12,this.nodeBkg="calculated",this.nodeBorder="calculated",this.clusterBkg="calculated",this.clusterBorder="calculated",this.defaultLinkColor="calculated",this.titleColor="#F9FFFE",this.edgeLabelBackground="calculated",this.actorBorder="calculated",this.actorBkg="calculated",this.actorTextColor="calculated",this.actorLineColor="calculated",this.signalColor="calculated",this.signalTextColor="calculated",this.labelBoxBkgColor="calculated",this.labelBoxBorderColor="calculated",this.labelTextColor="calculated",this.loopTextColor="calculated",this.noteBorderColor="calculated",this.noteBkgColor="#fff5ad",this.noteTextColor="calculated",this.activationBorderColor="calculated",this.activationBkgColor="calculated",this.sequenceNumberColor="black",this.sectionBkgColor=ge("#EAE8D9",30),this.altSectionBkgColor="calculated",this.sectionBkgColor2="#EAE8D9",this.taskBorderColor=Sc(255,255,255,70),this.taskBkgColor="calculated",this.taskTextColor="calculated",this.taskTextLightColor="calculated",this.taskTextOutsideColor="calculated",this.taskTextClickableColor="#003163",this.activeTaskBorderColor=Sc(255,255,255,50),this.activeTaskBkgColor="#81B1DB",this.gridColor="calculated",this.doneTaskBkgColor="calculated",this.doneTaskBorderColor="grey",this.critBorderColor="#E83737",this.critBkgColor="#E83737",this.taskTextDarkColor="calculated",this.todayLineColor="#DB5757",this.personBorder="calculated",this.personBkg="calculated",this.labelColor="calculated",this.errorBkgColor="#a44141",this.errorTextColor="#ddd"}updateColors(){this.secondBkg=ae(this.mainBkg,16),this.lineColor=this.mainContrastColor,this.arrowheadColor=this.mainContrastColor,this.nodeBkg=this.mainBkg,this.nodeBorder=this.border1,this.clusterBkg=this.secondBkg,this.clusterBorder=this.border2,this.defaultLinkColor=this.lineColor,this.edgeLabelBackground=ae(this.labelBackground,25),this.actorBorder=this.border1,this.actorBkg=this.mainBkg,this.actorTextColor=this.mainContrastColor,this.actorLineColor=this.mainContrastColor,this.signalColor=this.mainContrastColor,this.signalTextColor=this.mainContrastColor,this.labelBoxBkgColor=this.actorBkg,this.labelBoxBorderColor=this.actorBorder,this.labelTextColor=this.mainContrastColor,this.loopTextColor=this.mainContrastColor,this.noteBorderColor=this.secondaryBorderColor,this.noteBkgColor=this.secondBkg,this.noteTextColor=this.secondaryTextColor,this.activationBorderColor=this.border1,this.activationBkgColor=this.secondBkg,this.altSectionBkgColor=this.background,this.taskBkgColor=ae(this.mainBkg,23),this.taskTextColor=this.darkTextColor,this.taskTextLightColor=this.mainContrastColor,this.taskTextOutsideColor=this.taskTextLightColor,this.gridColor=this.mainContrastColor,this.doneTaskBkgColor=this.mainContrastColor,this.taskTextDarkColor=this.darkTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#555",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.primaryBorderColor,this.specialStateColor="#f4f4f4",this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.fillType0=this.primaryColor,this.fillType1=this.secondaryColor,this.fillType2=_t(this.primaryColor,{h:64}),this.fillType3=_t(this.secondaryColor,{h:64}),this.fillType4=_t(this.primaryColor,{h:-64}),this.fillType5=_t(this.secondaryColor,{h:-64}),this.fillType6=_t(this.primaryColor,{h:128}),this.fillType7=_t(this.secondaryColor,{h:128}),this.cScale1=this.cScale1||"#0b0000",this.cScale2=this.cScale2||"#4d1037",this.cScale3=this.cScale3||"#3f5258",this.cScale4=this.cScale4||"#4f2f1b",this.cScale5=this.cScale5||"#6e0a0a",this.cScale6=this.cScale6||"#3b0048",this.cScale7=this.cScale7||"#995a01",this.cScale8=this.cScale8||"#154706",this.cScale9=this.cScale9||"#161722",this.cScale10=this.cScale10||"#00296f",this.cScale11=this.cScale11||"#01629c",this.cScale12=this.cScale12||"#010029",this.cScale0=this.cScale0||this.primaryColor,this.cScale1=this.cScale1||this.secondaryColor,this.cScale2=this.cScale2||this.tertiaryColor,this.cScale3=this.cScale3||_t(this.primaryColor,{h:30}),this.cScale4=this.cScale4||_t(this.primaryColor,{h:60}),this.cScale5=this.cScale5||_t(this.primaryColor,{h:90}),this.cScale6=this.cScale6||_t(this.primaryColor,{h:120}),this.cScale7=this.cScale7||_t(this.primaryColor,{h:150}),this.cScale8=this.cScale8||_t(this.primaryColor,{h:210}),this.cScale9=this.cScale9||_t(this.primaryColor,{h:270}),this.cScale10=this.cScale10||_t(this.primaryColor,{h:300}),this.cScale11=this.cScale11||_t(this.primaryColor,{h:330});for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScaleInv"+e]=this["cScaleInv"+e]||Yt(this["cScale"+e]);for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScalePeer"+e]=this["cScalePeer"+e]||ae(this["cScale"+e],10);this.scaleLabelColor=this.scaleLabelColor||(this.darkMode?"black":this.labelTextColor);for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScaleLabel"+e]=this["cScaleLabel"+e]||this.scaleLabelColor;for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["pie"+e]=this["cScale"+e];this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOpacity=this.pieOpacity||"0.7",this.classText=this.primaryTextColor,this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||this.primaryBorderColor,this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||(this.darkMode?ge(this.secondaryColor,30):this.secondaryColor),this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=ae(this.secondaryColor,20),this.git1=ae(this.pie2||this.secondaryColor,20),this.git2=ae(this.pie3||this.tertiaryColor,20),this.git3=ae(this.pie4||_t(this.primaryColor,{h:-30}),20),this.git4=ae(this.pie5||_t(this.primaryColor,{h:-60}),20),this.git5=ae(this.pie6||_t(this.primaryColor,{h:-90}),10),this.git6=ae(this.pie7||_t(this.primaryColor,{h:60}),10),this.git7=ae(this.pie8||_t(this.primaryColor,{h:120}),20),this.gitInv0=this.gitInv0||Yt(this.git0),this.gitInv1=this.gitInv1||Yt(this.git1),this.gitInv2=this.gitInv2||Yt(this.git2),this.gitInv3=this.gitInv3||Yt(this.git3),this.gitInv4=this.gitInv4||Yt(this.git4),this.gitInv5=this.gitInv5||Yt(this.git5),this.gitInv6=this.gitInv6||Yt(this.git6),this.gitInv7=this.gitInv7||Yt(this.git7),this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||ae(this.background,12),this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ae(this.background,2)}calculate(e){if(typeof e!="object"){this.updateColors();return}const r=Object.keys(e);r.forEach(n=>{this[n]=e[n]}),this.updateColors(),r.forEach(n=>{this[n]=e[n]})}}const pG=t=>{const e=new dG;return e.calculate(t),e};class gG{constructor(){this.background="#f4f4f4",this.primaryColor="#ECECFF",this.secondaryColor=_t(this.primaryColor,{h:120}),this.secondaryColor="#ffffde",this.tertiaryColor=_t(this.primaryColor,{h:-160}),this.primaryBorderColor=ln(this.primaryColor,this.darkMode),this.secondaryBorderColor=ln(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=ln(this.tertiaryColor,this.darkMode),this.primaryTextColor=Yt(this.primaryColor),this.secondaryTextColor=Yt(this.secondaryColor),this.tertiaryTextColor=Yt(this.tertiaryColor),this.lineColor=Yt(this.background),this.textColor=Yt(this.background),this.background="white",this.mainBkg="#ECECFF",this.secondBkg="#ffffde",this.lineColor="#333333",this.border1="#9370DB",this.border2="#aaaa33",this.arrowheadColor="#333333",this.fontFamily='"trebuchet ms", verdana, arial, sans-serif',this.fontSize="16px",this.labelBackground="#e8e8e8",this.textColor="#333",this.THEME_COLOR_LIMIT=12,this.nodeBkg="calculated",this.nodeBorder="calculated",this.clusterBkg="calculated",this.clusterBorder="calculated",this.defaultLinkColor="calculated",this.titleColor="calculated",this.edgeLabelBackground="calculated",this.actorBorder="calculated",this.actorBkg="calculated",this.actorTextColor="black",this.actorLineColor="grey",this.signalColor="calculated",this.signalTextColor="calculated",this.labelBoxBkgColor="calculated",this.labelBoxBorderColor="calculated",this.labelTextColor="calculated",this.loopTextColor="calculated",this.noteBorderColor="calculated",this.noteBkgColor="#fff5ad",this.noteTextColor="calculated",this.activationBorderColor="#666",this.activationBkgColor="#f4f4f4",this.sequenceNumberColor="white",this.sectionBkgColor="calculated",this.altSectionBkgColor="calculated",this.sectionBkgColor2="calculated",this.excludeBkgColor="#eeeeee",this.taskBorderColor="calculated",this.taskBkgColor="calculated",this.taskTextLightColor="calculated",this.taskTextColor=this.taskTextLightColor,this.taskTextDarkColor="calculated",this.taskTextOutsideColor=this.taskTextDarkColor,this.taskTextClickableColor="calculated",this.activeTaskBorderColor="calculated",this.activeTaskBkgColor="calculated",this.gridColor="calculated",this.doneTaskBkgColor="calculated",this.doneTaskBorderColor="calculated",this.critBorderColor="calculated",this.critBkgColor="calculated",this.todayLineColor="calculated",this.sectionBkgColor=Sc(102,102,255,.49),this.altSectionBkgColor="white",this.sectionBkgColor2="#fff400",this.taskBorderColor="#534fbc",this.taskBkgColor="#8a90dd",this.taskTextLightColor="white",this.taskTextColor="calculated",this.taskTextDarkColor="black",this.taskTextOutsideColor="calculated",this.taskTextClickableColor="#003163",this.activeTaskBorderColor="#534fbc",this.activeTaskBkgColor="#bfc7ff",this.gridColor="lightgrey",this.doneTaskBkgColor="lightgrey",this.doneTaskBorderColor="grey",this.critBorderColor="#ff8888",this.critBkgColor="red",this.todayLineColor="red",this.personBorder="calculated",this.personBkg="calculated",this.labelColor="black",this.errorBkgColor="#552222",this.errorTextColor="#552222",this.updateColors()}updateColors(){this.cScale0=this.cScale0||this.primaryColor,this.cScale1=this.cScale1||this.secondaryColor,this.cScale2=this.cScale2||this.tertiaryColor,this.cScale3=this.cScale3||_t(this.primaryColor,{h:30}),this.cScale4=this.cScale4||_t(this.primaryColor,{h:60}),this.cScale5=this.cScale5||_t(this.primaryColor,{h:90}),this.cScale6=this.cScale6||_t(this.primaryColor,{h:120}),this.cScale7=this.cScale7||_t(this.primaryColor,{h:150}),this.cScale8=this.cScale8||_t(this.primaryColor,{h:210}),this.cScale9=this.cScale9||_t(this.primaryColor,{h:270}),this.cScale10=this.cScale10||_t(this.primaryColor,{h:300}),this.cScale11=this.cScale11||_t(this.primaryColor,{h:330}),this["cScalePeer"+1]=this["cScalePeer"+1]||ge(this.secondaryColor,45),this["cScalePeer"+2]=this["cScalePeer"+2]||ge(this.tertiaryColor,40);for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScale"+e]=ge(this["cScale"+e],10),this["cScalePeer"+e]=this["cScalePeer"+e]||ge(this["cScale"+e],25);for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScaleInv"+e]=this["cScaleInv"+e]||_t(this["cScale"+e],{h:180});if(this.scaleLabelColor=this.scaleLabelColor!=="calculated"&&this.scaleLabelColor?this.scaleLabelColor:this.labelTextColor,this.labelTextColor!=="calculated"){this.cScaleLabel0=this.cScaleLabel0||Yt(this.labelTextColor),this.cScaleLabel3=this.cScaleLabel3||Yt(this.labelTextColor);for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScaleLabel"+e]=this["cScaleLabel"+e]||this.labelTextColor}this.nodeBkg=this.mainBkg,this.nodeBorder=this.border1,this.clusterBkg=this.secondBkg,this.clusterBorder=this.border2,this.defaultLinkColor=this.lineColor,this.titleColor=this.textColor,this.edgeLabelBackground=this.labelBackground,this.actorBorder=ae(this.border1,23),this.actorBkg=this.mainBkg,this.labelBoxBkgColor=this.actorBkg,this.signalColor=this.textColor,this.signalTextColor=this.textColor,this.labelBoxBorderColor=this.actorBorder,this.labelTextColor=this.actorTextColor,this.loopTextColor=this.actorTextColor,this.noteBorderColor=this.border2,this.noteTextColor=this.actorTextColor,this.taskTextColor=this.taskTextLightColor,this.taskTextOutsideColor=this.taskTextDarkColor,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#f0f0f0",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.nodeBorder,this.specialStateColor=this.lineColor,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.classText=this.primaryTextColor,this.fillType0=this.primaryColor,this.fillType1=this.secondaryColor,this.fillType2=_t(this.primaryColor,{h:64}),this.fillType3=_t(this.secondaryColor,{h:64}),this.fillType4=_t(this.primaryColor,{h:-64}),this.fillType5=_t(this.secondaryColor,{h:-64}),this.fillType6=_t(this.primaryColor,{h:128}),this.fillType7=_t(this.secondaryColor,{h:128}),this.pie1=this.pie1||this.primaryColor,this.pie2=this.pie2||this.secondaryColor,this.pie3=this.pie3||_t(this.tertiaryColor,{l:-40}),this.pie4=this.pie4||_t(this.primaryColor,{l:-10}),this.pie5=this.pie5||_t(this.secondaryColor,{l:-30}),this.pie6=this.pie6||_t(this.tertiaryColor,{l:-20}),this.pie7=this.pie7||_t(this.primaryColor,{h:60,l:-20}),this.pie8=this.pie8||_t(this.primaryColor,{h:-60,l:-40}),this.pie9=this.pie9||_t(this.primaryColor,{h:120,l:-40}),this.pie10=this.pie10||_t(this.primaryColor,{h:60,l:-40}),this.pie11=this.pie11||_t(this.primaryColor,{h:-90,l:-40}),this.pie12=this.pie12||_t(this.primaryColor,{h:120,l:-30}),this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOpacity=this.pieOpacity||"0.7",this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||this.primaryBorderColor,this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||this.labelBackground,this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=this.git0||this.primaryColor,this.git1=this.git1||this.secondaryColor,this.git2=this.git2||this.tertiaryColor,this.git3=this.git3||_t(this.primaryColor,{h:-30}),this.git4=this.git4||_t(this.primaryColor,{h:-60}),this.git5=this.git5||_t(this.primaryColor,{h:-90}),this.git6=this.git6||_t(this.primaryColor,{h:60}),this.git7=this.git7||_t(this.primaryColor,{h:120}),this.darkMode?(this.git0=ae(this.git0,25),this.git1=ae(this.git1,25),this.git2=ae(this.git2,25),this.git3=ae(this.git3,25),this.git4=ae(this.git4,25),this.git5=ae(this.git5,25),this.git6=ae(this.git6,25),this.git7=ae(this.git7,25)):(this.git0=ge(this.git0,25),this.git1=ge(this.git1,25),this.git2=ge(this.git2,25),this.git3=ge(this.git3,25),this.git4=ge(this.git4,25),this.git5=ge(this.git5,25),this.git6=ge(this.git6,25),this.git7=ge(this.git7,25)),this.gitInv0=this.gitInv0||ge(Yt(this.git0),25),this.gitInv1=this.gitInv1||Yt(this.git1),this.gitInv2=this.gitInv2||Yt(this.git2),this.gitInv3=this.gitInv3||Yt(this.git3),this.gitInv4=this.gitInv4||Yt(this.git4),this.gitInv5=this.gitInv5||Yt(this.git5),this.gitInv6=this.gitInv6||Yt(this.git6),this.gitInv7=this.gitInv7||Yt(this.git7),this.gitBranchLabel0=this.gitBranchLabel0||Yt(this.labelTextColor),this.gitBranchLabel1=this.gitBranchLabel1||this.labelTextColor,this.gitBranchLabel2=this.gitBranchLabel2||this.labelTextColor,this.gitBranchLabel3=this.gitBranchLabel3||Yt(this.labelTextColor),this.gitBranchLabel4=this.gitBranchLabel4||this.labelTextColor,this.gitBranchLabel5=this.gitBranchLabel5||this.labelTextColor,this.gitBranchLabel6=this.gitBranchLabel6||this.labelTextColor,this.gitBranchLabel7=this.gitBranchLabel7||this.labelTextColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||qf,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||Vf}calculate(e){if(typeof e!="object"){this.updateColors();return}const r=Object.keys(e);r.forEach(n=>{this[n]=e[n]}),this.updateColors(),r.forEach(n=>{this[n]=e[n]})}}const yG=t=>{const e=new gG;return e.calculate(t),e};class mG{constructor(){this.background="#f4f4f4",this.primaryColor="#cde498",this.secondaryColor="#cdffb2",this.background="white",this.mainBkg="#cde498",this.secondBkg="#cdffb2",this.lineColor="green",this.border1="#13540c",this.border2="#6eaa49",this.arrowheadColor="green",this.fontFamily='"trebuchet ms", verdana, arial, sans-serif',this.fontSize="16px",this.tertiaryColor=ae("#cde498",10),this.primaryBorderColor=ln(this.primaryColor,this.darkMode),this.secondaryBorderColor=ln(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=ln(this.tertiaryColor,this.darkMode),this.primaryTextColor=Yt(this.primaryColor),this.secondaryTextColor=Yt(this.secondaryColor),this.tertiaryTextColor=Yt(this.primaryColor),this.lineColor=Yt(this.background),this.textColor=Yt(this.background),this.THEME_COLOR_LIMIT=12,this.nodeBkg="calculated",this.nodeBorder="calculated",this.clusterBkg="calculated",this.clusterBorder="calculated",this.defaultLinkColor="calculated",this.titleColor="#333",this.edgeLabelBackground="#e8e8e8",this.actorBorder="calculated",this.actorBkg="calculated",this.actorTextColor="black",this.actorLineColor="grey",this.signalColor="#333",this.signalTextColor="#333",this.labelBoxBkgColor="calculated",this.labelBoxBorderColor="#326932",this.labelTextColor="calculated",this.loopTextColor="calculated",this.noteBorderColor="calculated",this.noteBkgColor="#fff5ad",this.noteTextColor="calculated",this.activationBorderColor="#666",this.activationBkgColor="#f4f4f4",this.sequenceNumberColor="white",this.sectionBkgColor="#6eaa49",this.altSectionBkgColor="white",this.sectionBkgColor2="#6eaa49",this.excludeBkgColor="#eeeeee",this.taskBorderColor="calculated",this.taskBkgColor="#487e3a",this.taskTextLightColor="white",this.taskTextColor="calculated",this.taskTextDarkColor="black",this.taskTextOutsideColor="calculated",this.taskTextClickableColor="#003163",this.activeTaskBorderColor="calculated",this.activeTaskBkgColor="calculated",this.gridColor="lightgrey",this.doneTaskBkgColor="lightgrey",this.doneTaskBorderColor="grey",this.critBorderColor="#ff8888",this.critBkgColor="red",this.todayLineColor="red",this.personBorder="calculated",this.personBkg="calculated",this.labelColor="black",this.errorBkgColor="#552222",this.errorTextColor="#552222"}updateColors(){this.cScale0=this.cScale0||this.primaryColor,this.cScale1=this.cScale1||this.secondaryColor,this.cScale2=this.cScale2||this.tertiaryColor,this.cScale3=this.cScale3||_t(this.primaryColor,{h:30}),this.cScale4=this.cScale4||_t(this.primaryColor,{h:60}),this.cScale5=this.cScale5||_t(this.primaryColor,{h:90}),this.cScale6=this.cScale6||_t(this.primaryColor,{h:120}),this.cScale7=this.cScale7||_t(this.primaryColor,{h:150}),this.cScale8=this.cScale8||_t(this.primaryColor,{h:210}),this.cScale9=this.cScale9||_t(this.primaryColor,{h:270}),this.cScale10=this.cScale10||_t(this.primaryColor,{h:300}),this.cScale11=this.cScale11||_t(this.primaryColor,{h:330}),this["cScalePeer"+1]=this["cScalePeer"+1]||ge(this.secondaryColor,45),this["cScalePeer"+2]=this["cScalePeer"+2]||ge(this.tertiaryColor,40);for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScale"+e]=ge(this["cScale"+e],10),this["cScalePeer"+e]=this["cScalePeer"+e]||ge(this["cScale"+e],25);for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScaleInv"+e]=this["cScaleInv"+e]||_t(this["cScale"+e],{h:180});this.scaleLabelColor=this.scaleLabelColor!=="calculated"&&this.scaleLabelColor?this.scaleLabelColor:this.labelTextColor;for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScaleLabel"+e]=this["cScaleLabel"+e]||this.scaleLabelColor;this.nodeBkg=this.mainBkg,this.nodeBorder=this.border1,this.clusterBkg=this.secondBkg,this.clusterBorder=this.border2,this.defaultLinkColor=this.lineColor,this.actorBorder=ge(this.mainBkg,20),this.actorBkg=this.mainBkg,this.labelBoxBkgColor=this.actorBkg,this.labelTextColor=this.actorTextColor,this.loopTextColor=this.actorTextColor,this.noteBorderColor=this.border2,this.noteTextColor=this.actorTextColor,this.taskBorderColor=this.border1,this.taskTextColor=this.taskTextLightColor,this.taskTextOutsideColor=this.taskTextDarkColor,this.activeTaskBorderColor=this.taskBorderColor,this.activeTaskBkgColor=this.mainBkg,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#f0f0f0",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.primaryBorderColor,this.specialStateColor=this.lineColor,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.classText=this.primaryTextColor,this.fillType0=this.primaryColor,this.fillType1=this.secondaryColor,this.fillType2=_t(this.primaryColor,{h:64}),this.fillType3=_t(this.secondaryColor,{h:64}),this.fillType4=_t(this.primaryColor,{h:-64}),this.fillType5=_t(this.secondaryColor,{h:-64}),this.fillType6=_t(this.primaryColor,{h:128}),this.fillType7=_t(this.secondaryColor,{h:128}),this.pie1=this.pie1||this.primaryColor,this.pie2=this.pie2||this.secondaryColor,this.pie3=this.pie3||this.tertiaryColor,this.pie4=this.pie4||_t(this.primaryColor,{l:-30}),this.pie5=this.pie5||_t(this.secondaryColor,{l:-30}),this.pie6=this.pie6||_t(this.tertiaryColor,{h:40,l:-40}),this.pie7=this.pie7||_t(this.primaryColor,{h:60,l:-10}),this.pie8=this.pie8||_t(this.primaryColor,{h:-60,l:-10}),this.pie9=this.pie9||_t(this.primaryColor,{h:120,l:0}),this.pie10=this.pie10||_t(this.primaryColor,{h:60,l:-50}),this.pie11=this.pie11||_t(this.primaryColor,{h:-60,l:-50}),this.pie12=this.pie12||_t(this.primaryColor,{h:120,l:-50}),this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOpacity=this.pieOpacity||"0.7",this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||this.primaryBorderColor,this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||this.edgeLabelBackground,this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=this.git0||this.primaryColor,this.git1=this.git1||this.secondaryColor,this.git2=this.git2||this.tertiaryColor,this.git3=this.git3||_t(this.primaryColor,{h:-30}),this.git4=this.git4||_t(this.primaryColor,{h:-60}),this.git5=this.git5||_t(this.primaryColor,{h:-90}),this.git6=this.git6||_t(this.primaryColor,{h:60}),this.git7=this.git7||_t(this.primaryColor,{h:120}),this.darkMode?(this.git0=ae(this.git0,25),this.git1=ae(this.git1,25),this.git2=ae(this.git2,25),this.git3=ae(this.git3,25),this.git4=ae(this.git4,25),this.git5=ae(this.git5,25),this.git6=ae(this.git6,25),this.git7=ae(this.git7,25)):(this.git0=ge(this.git0,25),this.git1=ge(this.git1,25),this.git2=ge(this.git2,25),this.git3=ge(this.git3,25),this.git4=ge(this.git4,25),this.git5=ge(this.git5,25),this.git6=ge(this.git6,25),this.git7=ge(this.git7,25)),this.gitInv0=this.gitInv0||Yt(this.git0),this.gitInv1=this.gitInv1||Yt(this.git1),this.gitInv2=this.gitInv2||Yt(this.git2),this.gitInv3=this.gitInv3||Yt(this.git3),this.gitInv4=this.gitInv4||Yt(this.git4),this.gitInv5=this.gitInv5||Yt(this.git5),this.gitInv6=this.gitInv6||Yt(this.git6),this.gitInv7=this.gitInv7||Yt(this.git7),this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||qf,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||Vf}calculate(e){if(typeof e!="object"){this.updateColors();return}const r=Object.keys(e);r.forEach(n=>{this[n]=e[n]}),this.updateColors(),r.forEach(n=>{this[n]=e[n]})}}const bG=t=>{const e=new mG;return e.calculate(t),e};class _G{constructor(){this.primaryColor="#eee",this.contrast="#707070",this.secondaryColor=ae(this.contrast,55),this.background="#ffffff",this.tertiaryColor=_t(this.primaryColor,{h:-160}),this.primaryBorderColor=ln(this.primaryColor,this.darkMode),this.secondaryBorderColor=ln(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=ln(this.tertiaryColor,this.darkMode),this.primaryTextColor=Yt(this.primaryColor),this.secondaryTextColor=Yt(this.secondaryColor),this.tertiaryTextColor=Yt(this.tertiaryColor),this.lineColor=Yt(this.background),this.textColor=Yt(this.background),this.mainBkg="#eee",this.secondBkg="calculated",this.lineColor="#666",this.border1="#999",this.border2="calculated",this.note="#ffa",this.text="#333",this.critical="#d42",this.done="#bbb",this.arrowheadColor="#333333",this.fontFamily='"trebuchet ms", verdana, arial, sans-serif',this.fontSize="16px",this.THEME_COLOR_LIMIT=12,this.nodeBkg="calculated",this.nodeBorder="calculated",this.clusterBkg="calculated",this.clusterBorder="calculated",this.defaultLinkColor="calculated",this.titleColor="calculated",this.edgeLabelBackground="white",this.actorBorder="calculated",this.actorBkg="calculated",this.actorTextColor="calculated",this.actorLineColor="calculated",this.signalColor="calculated",this.signalTextColor="calculated",this.labelBoxBkgColor="calculated",this.labelBoxBorderColor="calculated",this.labelTextColor="calculated",this.loopTextColor="calculated",this.noteBorderColor="calculated",this.noteBkgColor="calculated",this.noteTextColor="calculated",this.activationBorderColor="#666",this.activationBkgColor="#f4f4f4",this.sequenceNumberColor="white",this.sectionBkgColor="calculated",this.altSectionBkgColor="white",this.sectionBkgColor2="calculated",this.excludeBkgColor="#eeeeee",this.taskBorderColor="calculated",this.taskBkgColor="calculated",this.taskTextLightColor="white",this.taskTextColor="calculated",this.taskTextDarkColor="calculated",this.taskTextOutsideColor="calculated",this.taskTextClickableColor="#003163",this.activeTaskBorderColor="calculated",this.activeTaskBkgColor="calculated",this.gridColor="calculated",this.doneTaskBkgColor="calculated",this.doneTaskBorderColor="calculated",this.critBkgColor="calculated",this.critBorderColor="calculated",this.todayLineColor="calculated",this.personBorder="calculated",this.personBkg="calculated",this.labelColor="black",this.errorBkgColor="#552222",this.errorTextColor="#552222"}updateColors(){this.secondBkg=ae(this.contrast,55),this.border2=this.contrast,this.cScale0=this.cScale0||"#555",this.cScale1=this.cScale1||"#F4F4F4",this.cScale2=this.cScale2||"#555",this.cScale3=this.cScale3||"#BBB",this.cScale4=this.cScale4||"#777",this.cScale5=this.cScale5||"#999",this.cScale6=this.cScale6||"#DDD",this.cScale7=this.cScale7||"#FFF",this.cScale8=this.cScale8||"#DDD",this.cScale9=this.cScale9||"#BBB",this.cScale10=this.cScale10||"#999",this.cScale11=this.cScale11||"#777";for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScaleInv"+e]=this["cScaleInv"+e]||Yt(this["cScale"+e]);for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this.darkMode?this["cScalePeer"+e]=this["cScalePeer"+e]||ae(this["cScale"+e],10):this["cScalePeer"+e]=this["cScalePeer"+e]||ge(this["cScale"+e],10);this.scaleLabelColor=this.scaleLabelColor||(this.darkMode?"black":this.labelTextColor),this.cScaleLabel0=this.cScaleLabel0||this.cScale1,this.cScaleLabel2=this.cScaleLabel2||this.cScale1;for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["cScaleLabel"+e]=this["cScaleLabel"+e]||this.scaleLabelColor;this.nodeBkg=this.mainBkg,this.nodeBorder=this.border1,this.clusterBkg=this.secondBkg,this.clusterBorder=this.border2,this.defaultLinkColor=this.lineColor,this.titleColor=this.text,this.actorBorder=ae(this.border1,23),this.actorBkg=this.mainBkg,this.actorTextColor=this.text,this.actorLineColor=this.lineColor,this.signalColor=this.text,this.signalTextColor=this.text,this.labelBoxBkgColor=this.actorBkg,this.labelBoxBorderColor=this.actorBorder,this.labelTextColor=this.text,this.loopTextColor=this.text,this.noteBorderColor="#999",this.noteBkgColor="#666",this.noteTextColor="#fff",this.sectionBkgColor=ae(this.contrast,30),this.sectionBkgColor2=ae(this.contrast,30),this.taskBorderColor=ge(this.contrast,10),this.taskBkgColor=this.contrast,this.taskTextColor=this.taskTextLightColor,this.taskTextDarkColor=this.text,this.taskTextOutsideColor=this.taskTextDarkColor,this.activeTaskBorderColor=this.taskBorderColor,this.activeTaskBkgColor=this.mainBkg,this.gridColor=ae(this.border1,30),this.doneTaskBkgColor=this.done,this.doneTaskBorderColor=this.lineColor,this.critBkgColor=this.critical,this.critBorderColor=ge(this.critBkgColor,10),this.todayLineColor=this.critBkgColor,this.transitionColor=this.transitionColor||"#000",this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#f4f4f4",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.stateBorder=this.stateBorder||"#000",this.innerEndBackground=this.primaryBorderColor,this.specialStateColor="#222",this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.classText=this.primaryTextColor,this.fillType0=this.primaryColor,this.fillType1=this.secondaryColor,this.fillType2=_t(this.primaryColor,{h:64}),this.fillType3=_t(this.secondaryColor,{h:64}),this.fillType4=_t(this.primaryColor,{h:-64}),this.fillType5=_t(this.secondaryColor,{h:-64}),this.fillType6=_t(this.primaryColor,{h:128}),this.fillType7=_t(this.secondaryColor,{h:128});for(let e=0;e<this.THEME_COLOR_LIMIT;e++)this["pie"+e]=this["cScale"+e];this.pie12=this.pie0,this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOpacity=this.pieOpacity||"0.7",this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||this.primaryBorderColor,this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||this.edgeLabelBackground,this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=ge(this.pie1,25)||this.primaryColor,this.git1=this.pie2||this.secondaryColor,this.git2=this.pie3||this.tertiaryColor,this.git3=this.pie4||_t(this.primaryColor,{h:-30}),this.git4=this.pie5||_t(this.primaryColor,{h:-60}),this.git5=this.pie6||_t(this.primaryColor,{h:-90}),this.git6=this.pie7||_t(this.primaryColor,{h:60}),this.git7=this.pie8||_t(this.primaryColor,{h:120}),this.gitInv0=this.gitInv0||Yt(this.git0),this.gitInv1=this.gitInv1||Yt(this.git1),this.gitInv2=this.gitInv2||Yt(this.git2),this.gitInv3=this.gitInv3||Yt(this.git3),this.gitInv4=this.gitInv4||Yt(this.git4),this.gitInv5=this.gitInv5||Yt(this.git5),this.gitInv6=this.gitInv6||Yt(this.git6),this.gitInv7=this.gitInv7||Yt(this.git7),this.branchLabelColor=this.branchLabelColor||this.labelTextColor,this.gitBranchLabel0=this.branchLabelColor,this.gitBranchLabel1="white",this.gitBranchLabel2=this.branchLabelColor,this.gitBranchLabel3="white",this.gitBranchLabel4=this.branchLabelColor,this.gitBranchLabel5=this.branchLabelColor,this.gitBranchLabel6=this.branchLabelColor,this.gitBranchLabel7=this.branchLabelColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||qf,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||Vf}calculate(e){if(typeof e!="object"){this.updateColors();return}const r=Object.keys(e);r.forEach(n=>{this[n]=e[n]}),this.updateColors(),r.forEach(n=>{this[n]=e[n]})}}const aa={base:{getThemeVariables:fG},dark:{getThemeVariables:pG},default:{getThemeVariables:yG},forest:{getThemeVariables:bG},neutral:{getThemeVariables:t=>{const e=new _G;return e.calculate(t),e}}},Xa={theme:"default",themeVariables:aa.default.getThemeVariables(),themeCSS:void 0,maxTextSize:5e4,darkMode:!1,fontFamily:'"trebuchet ms", verdana, arial, sans-serif;',logLevel:5,securityLevel:"strict",startOnLoad:!0,arrowMarkerAbsolute:!1,secure:["secure","securityLevel","startOnLoad","maxTextSize"],deterministicIds:!1,deterministicIDSeed:void 0,flowchart:{diagramPadding:8,htmlLabels:!0,nodeSpacing:50,rankSpacing:50,curve:"basis",padding:15,useMaxWidth:!0,defaultRenderer:"dagre-wrapper"},sequence:{hideUnusedParticipants:!1,activationWidth:10,diagramMarginX:50,diagramMarginY:10,actorMargin:50,width:150,height:65,boxMargin:10,boxTextMargin:5,noteMargin:10,messageMargin:35,messageAlign:"center",mirrorActors:!0,forceMenus:!1,bottomMarginAdj:1,useMaxWidth:!0,rightAngles:!1,showSequenceNumbers:!1,actorFontSize:14,actorFontFamily:'"Open Sans", sans-serif',actorFontWeight:400,noteFontSize:14,noteFontFamily:'"trebuchet ms", verdana, arial, sans-serif',noteFontWeight:400,noteAlign:"center",messageFontSize:16,messageFontFamily:'"trebuchet ms", verdana, arial, sans-serif',messageFontWeight:400,wrap:!1,wrapPadding:10,labelBoxWidth:50,labelBoxHeight:20,messageFont:function(){return{fontFamily:this.messageFontFamily,fontSize:this.messageFontSize,fontWeight:this.messageFontWeight}},noteFont:function(){return{fontFamily:this.noteFontFamily,fontSize:this.noteFontSize,fontWeight:this.noteFontWeight}},actorFont:function(){return{fontFamily:this.actorFontFamily,fontSize:this.actorFontSize,fontWeight:this.actorFontWeight}}},gantt:{titleTopMargin:25,barHeight:20,barGap:4,topPadding:50,rightPadding:75,leftPadding:75,gridLineStartPadding:35,fontSize:11,sectionFontSize:11,numberSectionStyles:4,axisFormat:"%Y-%m-%d",useMaxWidth:!0,topAxis:!1,useWidth:void 0},journey:{diagramMarginX:50,diagramMarginY:10,leftMargin:150,width:150,height:50,boxMargin:10,boxTextMargin:5,noteMargin:10,messageMargin:35,messageAlign:"center",bottomMarginAdj:1,useMaxWidth:!0,rightAngles:!1,taskFontSize:14,taskFontFamily:'"Open Sans", sans-serif',taskMargin:50,activationWidth:10,textPlacement:"fo",actorColours:["#8FBC8F","#7CFC00","#00FFFF","#20B2AA","#B0E0E6","#FFFFE0"],sectionFills:["#191970","#8B008B","#4B0082","#2F4F4F","#800000","#8B4513","#00008B"],sectionColours:["#fff"]},class:{arrowMarkerAbsolute:!1,dividerMargin:10,padding:5,textHeight:10,useMaxWidth:!0,defaultRenderer:"dagre-wrapper"},state:{dividerMargin:10,sizeUnit:5,padding:8,textHeight:10,titleShift:-15,noteMargin:10,forkWidth:70,forkHeight:7,miniPadding:2,fontSizeFactor:5.02,fontSize:24,labelHeight:16,edgeLengthFactor:"20",compositTitleSize:35,radius:5,useMaxWidth:!0,defaultRenderer:"dagre-wrapper"},er:{diagramPadding:20,layoutDirection:"TB",minEntityWidth:100,minEntityHeight:75,entityPadding:15,stroke:"gray",fill:"honeydew",fontSize:12,useMaxWidth:!0},pie:{useWidth:void 0,useMaxWidth:!0},requirement:{useWidth:void 0,useMaxWidth:!0,rect_fill:"#f9f9f9",text_color:"#333",rect_border_size:"0.5px",rect_border_color:"#bbb",rect_min_width:200,rect_min_height:200,fontSize:14,rect_padding:10,line_height:20},gitGraph:{diagramPadding:8,nodeLabel:{width:75,height:100,x:-25,y:0},mainBranchName:"main",mainBranchOrder:0,showCommitLabel:!0,showBranches:!0,rotateCommitLabel:!0},c4:{useWidth:void 0,diagramMarginX:50,diagramMarginY:10,c4ShapeMargin:50,c4ShapePadding:20,width:216,height:60,boxMargin:10,useMaxWidth:!0,c4ShapeInRow:4,nextLinePaddingX:0,c4BoundaryInRow:2,personFontSize:14,personFontFamily:'"Open Sans", sans-serif',personFontWeight:"normal",external_personFontSize:14,external_personFontFamily:'"Open Sans", sans-serif',external_personFontWeight:"normal",systemFontSize:14,systemFontFamily:'"Open Sans", sans-serif',systemFontWeight:"normal",external_systemFontSize:14,external_systemFontFamily:'"Open Sans", sans-serif',external_systemFontWeight:"normal",system_dbFontSize:14,system_dbFontFamily:'"Open Sans", sans-serif',system_dbFontWeight:"normal",external_system_dbFontSize:14,external_system_dbFontFamily:'"Open Sans", sans-serif',external_system_dbFontWeight:"normal",system_queueFontSize:14,system_queueFontFamily:'"Open Sans", sans-serif',system_queueFontWeight:"normal",external_system_queueFontSize:14,external_system_queueFontFamily:'"Open Sans", sans-serif',external_system_queueFontWeight:"normal",boundaryFontSize:14,boundaryFontFamily:'"Open Sans", sans-serif',boundaryFontWeight:"normal",messageFontSize:12,messageFontFamily:'"Open Sans", sans-serif',messageFontWeight:"normal",containerFontSize:14,containerFontFamily:'"Open Sans", sans-serif',containerFontWeight:"normal",external_containerFontSize:14,external_containerFontFamily:'"Open Sans", sans-serif',external_containerFontWeight:"normal",container_dbFontSize:14,container_dbFontFamily:'"Open Sans", sans-serif',container_dbFontWeight:"normal",external_container_dbFontSize:14,external_container_dbFontFamily:'"Open Sans", sans-serif',external_container_dbFontWeight:"normal",container_queueFontSize:14,container_queueFontFamily:'"Open Sans", sans-serif',container_queueFontWeight:"normal",external_container_queueFontSize:14,external_container_queueFontFamily:'"Open Sans", sans-serif',external_container_queueFontWeight:"normal",componentFontSize:14,componentFontFamily:'"Open Sans", sans-serif',componentFontWeight:"normal",external_componentFontSize:14,external_componentFontFamily:'"Open Sans", sans-serif',external_componentFontWeight:"normal",component_dbFontSize:14,component_dbFontFamily:'"Open Sans", sans-serif',component_dbFontWeight:"normal",external_component_dbFontSize:14,external_component_dbFontFamily:'"Open Sans", sans-serif',external_component_dbFontWeight:"normal",component_queueFontSize:14,component_queueFontFamily:'"Open Sans", sans-serif',component_queueFontWeight:"normal",external_component_queueFontSize:14,external_component_queueFontFamily:'"Open Sans", sans-serif',external_component_queueFontWeight:"normal",wrap:!0,wrapPadding:10,personFont:function(){return{fontFamily:this.personFontFamily,fontSize:this.personFontSize,fontWeight:this.personFontWeight}},external_personFont:function(){return{fontFamily:this.external_personFontFamily,fontSize:this.external_personFontSize,fontWeight:this.external_personFontWeight}},systemFont:function(){return{fontFamily:this.systemFontFamily,fontSize:this.systemFontSize,fontWeight:this.systemFontWeight}},external_systemFont:function(){return{fontFamily:this.external_systemFontFamily,fontSize:this.external_systemFontSize,fontWeight:this.external_systemFontWeight}},system_dbFont:function(){return{fontFamily:this.system_dbFontFamily,fontSize:this.system_dbFontSize,fontWeight:this.system_dbFontWeight}},external_system_dbFont:function(){return{fontFamily:this.external_system_dbFontFamily,fontSize:this.external_system_dbFontSize,fontWeight:this.external_system_dbFontWeight}},system_queueFont:function(){return{fontFamily:this.system_queueFontFamily,fontSize:this.system_queueFontSize,fontWeight:this.system_queueFontWeight}},external_system_queueFont:function(){return{fontFamily:this.external_system_queueFontFamily,fontSize:this.external_system_queueFontSize,fontWeight:this.external_system_queueFontWeight}},containerFont:function(){return{fontFamily:this.containerFontFamily,fontSize:this.containerFontSize,fontWeight:this.containerFontWeight}},external_containerFont:function(){return{fontFamily:this.external_containerFontFamily,fontSize:this.external_containerFontSize,fontWeight:this.external_containerFontWeight}},container_dbFont:function(){return{fontFamily:this.container_dbFontFamily,fontSize:this.container_dbFontSize,fontWeight:this.container_dbFontWeight}},external_container_dbFont:function(){return{fontFamily:this.external_container_dbFontFamily,fontSize:this.external_container_dbFontSize,fontWeight:this.external_container_dbFontWeight}},container_queueFont:function(){return{fontFamily:this.container_queueFontFamily,fontSize:this.container_queueFontSize,fontWeight:this.container_queueFontWeight}},external_container_queueFont:function(){return{fontFamily:this.external_container_queueFontFamily,fontSize:this.external_container_queueFontSize,fontWeight:this.external_container_queueFontWeight}},componentFont:function(){return{fontFamily:this.componentFontFamily,fontSize:this.componentFontSize,fontWeight:this.componentFontWeight}},external_componentFont:function(){return{fontFamily:this.external_componentFontFamily,fontSize:this.external_componentFontSize,fontWeight:this.external_componentFontWeight}},component_dbFont:function(){return{fontFamily:this.component_dbFontFamily,fontSize:this.component_dbFontSize,fontWeight:this.component_dbFontWeight}},external_component_dbFont:function(){return{fontFamily:this.external_component_dbFontFamily,fontSize:this.external_component_dbFontSize,fontWeight:this.external_component_dbFontWeight}},component_queueFont:function(){return{fontFamily:this.component_queueFontFamily,fontSize:this.component_queueFontSize,fontWeight:this.component_queueFontWeight}},external_component_queueFont:function(){return{fontFamily:this.external_component_queueFontFamily,fontSize:this.external_component_queueFontSize,fontWeight:this.external_component_queueFontWeight}},boundaryFont:function(){return{fontFamily:this.boundaryFontFamily,fontSize:this.boundaryFontSize,fontWeight:this.boundaryFontWeight}},messageFont:function(){return{fontFamily:this.messageFontFamily,fontSize:this.messageFontSize,fontWeight:this.messageFontWeight}},person_bg_color:"#08427B",person_border_color:"#073B6F",external_person_bg_color:"#686868",external_person_border_color:"#8A8A8A",system_bg_color:"#1168BD",system_border_color:"#3C7FC0",system_db_bg_color:"#1168BD",system_db_border_color:"#3C7FC0",system_queue_bg_color:"#1168BD",system_queue_border_color:"#3C7FC0",external_system_bg_color:"#999999",external_system_border_color:"#8A8A8A",external_system_db_bg_color:"#999999",external_system_db_border_color:"#8A8A8A",external_system_queue_bg_color:"#999999",external_system_queue_border_color:"#8A8A8A",container_bg_color:"#438DD5",container_border_color:"#3C7FC0",container_db_bg_color:"#438DD5",container_db_border_color:"#3C7FC0",container_queue_bg_color:"#438DD5",container_queue_border_color:"#3C7FC0",external_container_bg_color:"#B3B3B3",external_container_border_color:"#A6A6A6",external_container_db_bg_color:"#B3B3B3",external_container_db_border_color:"#A6A6A6",external_container_queue_bg_color:"#B3B3B3",external_container_queue_border_color:"#A6A6A6",component_bg_color:"#85BBF0",component_border_color:"#78A8D8",component_db_bg_color:"#85BBF0",component_db_border_color:"#78A8D8",component_queue_bg_color:"#85BBF0",component_queue_border_color:"#78A8D8",external_component_bg_color:"#CCCCCC",external_component_border_color:"#BFBFBF",external_component_db_bg_color:"#CCCCCC",external_component_db_border_color:"#BFBFBF",external_component_queue_bg_color:"#CCCCCC",external_component_queue_border_color:"#BFBFBF"},mindmap:{useMaxWidth:!0,padding:10,maxNodeWidth:200},fontSize:16};Xa.class&&(Xa.class.arrowMarkerAbsolute=Xa.arrowMarkerAbsolute),Xa.gitGraph&&(Xa.gitGraph.arrowMarkerAbsolute=Xa.arrowMarkerAbsolute);const jk=(t,e="")=>Object.keys(t).reduce((r,n)=>Array.isArray(t[n])?r:typeof t[n]=="object"&&t[n]!==null?[...r,e+n,...jk(t[n],"")]:[...r,e+n],[]),vG=jk(Xa,""),xG=/[%]{2}[{]\s*(?:(?:(\w+)\s*:|(\w+))\s*(?:(?:(\w+))|((?:(?![}][%]{2}).|\r?\n)*))?\s*)(?:[}][%]{2})?/gi,kG=/\s*%%.*\n/gm,zf={},Xp=function(t,e){t=t.replace(xG,"").replace(kG,` +`);for(const[r,{detector:n}]of Object.entries(zf))if(n(t,e))return r;throw new Error(`No diagram type detected for text: ${t}`)},$k=(t,e,r)=>{if(zf[t])throw new Error(`Detector with key ${t} already exists`);zf[t]={detector:e,loader:r},H.debug(`Detector with key ${t} added${r?" with loader":""}`)},wG=t=>zf[t].loader,fr=function(t,e,r){const{depth:n,clobber:i}=Object.assign({depth:2,clobber:!1},r);return Array.isArray(e)&&!Array.isArray(t)?(e.forEach(a=>fr(t,a,r)),t):Array.isArray(e)&&Array.isArray(t)?(e.forEach(a=>{t.indexOf(a)===-1&&t.push(a)}),t):typeof t>"u"||n<=0?t!=null&&typeof t=="object"&&typeof e=="object"?Object.assign(t,e):e:(typeof e<"u"&&typeof t=="object"&&typeof e=="object"&&Object.keys(e).forEach(a=>{typeof e[a]=="object"&&(t[a]===void 0||typeof t[a]=="object")?(t[a]===void 0&&(t[a]=Array.isArray(e[a])?[]:{}),t[a]=fr(t[a],e[a],{depth:n-1,clobber:i})):(i||typeof t[a]!="object"&&typeof e[a]!="object")&&(t[a]=e[a])}),t)};var TG=typeof jr=="object"&&jr&&jr.Object===Object&&jr,Xk=TG,EG=Xk,CG=typeof self=="object"&&self&&self.Object===Object&&self,SG=EG||CG||Function("return this")(),si=SG,AG=si,MG=AG.Symbol,zo=MG,Kk=zo,Zk=Object.prototype,LG=Zk.hasOwnProperty,RG=Zk.toString,Ac=Kk?Kk.toStringTag:void 0;function IG(t){var e=LG.call(t,Ac),r=t[Ac];try{t[Ac]=void 0;var n=!0}catch{}var i=RG.call(t);return n&&(e?t[Ac]=r:delete t[Ac]),i}var NG=IG,BG=Object.prototype,DG=BG.toString;function OG(t){return DG.call(t)}var FG=OG,Qk=zo,PG=NG,qG=FG,VG="[object Null]",zG="[object Undefined]",Jk=Qk?Qk.toStringTag:void 0;function YG(t){return t==null?t===void 0?zG:VG:Jk&&Jk in Object(t)?PG(t):qG(t)}var Ps=YG;function UG(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var Vn=UG,WG=Ps,HG=Vn,GG="[object AsyncFunction]",jG="[object Function]",$G="[object GeneratorFunction]",XG="[object Proxy]";function KG(t){if(!HG(t))return!1;var e=WG(t);return e==jG||e==$G||e==GG||e==XG}var Yo=KG,ZG=si,QG=ZG["__core-js_shared__"],JG=QG,Kp=JG,tw=function(){var t=/[^.]+$/.exec(Kp&&Kp.keys&&Kp.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function tj(t){return!!tw&&tw in t}var ej=tj,rj=Function.prototype,nj=rj.toString;function ij(t){if(t!=null){try{return nj.call(t)}catch{}try{return t+""}catch{}}return""}var ew=ij,aj=Yo,sj=ej,oj=Vn,lj=ew,cj=/[\\^$.*+?()[\]{}|]/g,uj=/^\[object .+?Constructor\]$/,hj=Function.prototype,fj=Object.prototype,dj=hj.toString,pj=fj.hasOwnProperty,gj=RegExp("^"+dj.call(pj).replace(cj,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function yj(t){if(!oj(t)||sj(t))return!1;var e=aj(t)?gj:uj;return e.test(lj(t))}var mj=yj;function bj(t,e){return t==null?void 0:t[e]}var _j=bj,vj=mj,xj=_j;function kj(t,e){var r=xj(t,e);return vj(r)?r:void 0}var qs=kj,wj=qs,Tj=wj(Object,"create"),Yf=Tj,rw=Yf;function Ej(){this.__data__=rw?rw(null):{},this.size=0}var Cj=Ej;function Sj(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var Aj=Sj,Mj=Yf,Lj="__lodash_hash_undefined__",Rj=Object.prototype,Ij=Rj.hasOwnProperty;function Nj(t){var e=this.__data__;if(Mj){var r=e[t];return r===Lj?void 0:r}return Ij.call(e,t)?e[t]:void 0}var Bj=Nj,Dj=Yf,Oj=Object.prototype,Fj=Oj.hasOwnProperty;function Pj(t){var e=this.__data__;return Dj?e[t]!==void 0:Fj.call(e,t)}var qj=Pj,Vj=Yf,zj="__lodash_hash_undefined__";function Yj(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Vj&&e===void 0?zj:e,this}var Uj=Yj,Wj=Cj,Hj=Aj,Gj=Bj,jj=qj,$j=Uj;function Uo(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Uo.prototype.clear=Wj,Uo.prototype.delete=Hj,Uo.prototype.get=Gj,Uo.prototype.has=jj,Uo.prototype.set=$j;var Xj=Uo;function Kj(){this.__data__=[],this.size=0}var Zj=Kj;function Qj(t,e){return t===e||t!==t&&e!==e}var Wo=Qj,Jj=Wo;function t$(t,e){for(var r=t.length;r--;)if(Jj(t[r][0],e))return r;return-1}var Uf=t$,e$=Uf,r$=Array.prototype,n$=r$.splice;function i$(t){var e=this.__data__,r=e$(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():n$.call(e,r,1),--this.size,!0}var a$=i$,s$=Uf;function o$(t){var e=this.__data__,r=s$(e,t);return r<0?void 0:e[r][1]}var l$=o$,c$=Uf;function u$(t){return c$(this.__data__,t)>-1}var h$=u$,f$=Uf;function d$(t,e){var r=this.__data__,n=f$(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this}var p$=d$,g$=Zj,y$=a$,m$=l$,b$=h$,_$=p$;function Ho(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Ho.prototype.clear=g$,Ho.prototype.delete=y$,Ho.prototype.get=m$,Ho.prototype.has=b$,Ho.prototype.set=_$;var Wf=Ho,v$=qs,x$=si,k$=v$(x$,"Map"),Zp=k$,nw=Xj,w$=Wf,T$=Zp;function E$(){this.size=0,this.__data__={hash:new nw,map:new(T$||w$),string:new nw}}var C$=E$;function S$(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var A$=S$,M$=A$;function L$(t,e){var r=t.__data__;return M$(e)?r[typeof e=="string"?"string":"hash"]:r.map}var Hf=L$,R$=Hf;function I$(t){var e=R$(this,t).delete(t);return this.size-=e?1:0,e}var N$=I$,B$=Hf;function D$(t){return B$(this,t).get(t)}var O$=D$,F$=Hf;function P$(t){return F$(this,t).has(t)}var q$=P$,V$=Hf;function z$(t,e){var r=V$(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this}var Y$=z$,U$=C$,W$=N$,H$=O$,G$=q$,j$=Y$;function Go(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Go.prototype.clear=U$,Go.prototype.delete=W$,Go.prototype.get=H$,Go.prototype.has=G$,Go.prototype.set=j$;var Qp=Go,iw=Qp,$$="Expected a function";function Jp(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError($$);var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],a=r.cache;if(a.has(i))return a.get(i);var s=t.apply(this,n);return r.cache=a.set(i,s)||a,s};return r.cache=new(Jp.Cache||iw),r}Jp.Cache=iw;var Gf=Jp;const X$={curveBasis:Os,curveBasisClosed:ik,curveBasisOpen:sk,curveLinear:yn,curveLinearClosed:fk,curveMonotoneX:bk,curveMonotoneY:_k,curveNatural:kk,curveStep:wk,curveStepAfter:Ek,curveStepBefore:Tk},tg=/[%]{2}[{]\s*(?:(?:(\w+)\s*:|(\w+))\s*(?:(?:(\w+))|((?:(?![}][%]{2}).|\r?\n)*))?\s*)(?:[}][%]{2})?/gi,K$=/\s*(?:(?:(\w+)(?=:):|(\w+))\s*(?:(?:(\w+))|((?:(?![}][%]{2}).|\r?\n)*))?\s*)(?:[}][%]{2})?/gi,Z$=function(t,e){const r=aw(t,/(?:init\b)|(?:initialize\b)/);let n={};if(Array.isArray(r)){const i=r.map(a=>a.args);Vs(i),n=fr(n,[...i])}else n=r.args;if(n){let i=Xp(t,e);["config"].forEach(a=>{typeof n[a]<"u"&&(i==="flowchart-v2"&&(i="flowchart"),n[i]=n[a],delete n[a])})}return n},aw=function(t,e=null){try{const r=new RegExp(`[%]{2}(?![{]${K$.source})(?=[}][%]{2}).* +`,"ig");t=t.trim().replace(r,"").replace(/'/gm,'"'),H.debug(`Detecting diagram directive${e!==null?" type:"+e:""} based on the text:${t}`);let n;const i=[];for(;(n=tg.exec(t))!==null;)if(n.index===tg.lastIndex&&tg.lastIndex++,n&&!e||e&&n[1]&&n[1].match(e)||e&&n[2]&&n[2].match(e)){const a=n[1]?n[1]:n[2],s=n[3]?n[3].trim():n[4]?JSON.parse(n[4].trim()):null;i.push({type:a,args:s})}return i.length===0&&i.push({type:t,args:null}),i.length===1?i[0]:i}catch(r){return H.error(`ERROR: ${r.message} - Unable to parse directive + ${e!==null?" type:"+e:""} based on the text:${t}`),{type:null,args:null}}},Q$=function(t,e){for(let r=0;r<e.length;r++)if(e[r].match(t))return r;return-1},Ni=(t,e)=>{if(!t)return e;const r=`curve${t.charAt(0).toUpperCase()+t.slice(1)}`;return X$[r]||e},J$=(t,e)=>{const r=t.trim();if(r)return e.securityLevel!=="loose"?ki(r):r},tX=(t,...e)=>{const r=t.split("."),n=r.length-1,i=r[n];let a=window;for(let s=0;s<n;s++)if(a=a[r[s]],!a)return;a[i](...e)},Mc=(t,e)=>t&&e?Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)):0,eX=t=>{let e,r=0;t.forEach(a=>{r+=Mc(a,e),e=a});let n=r/2,i;return e=void 0,t.forEach(a=>{if(e&&!i){const s=Mc(a,e);if(s<n)n-=s;else{const o=n/s;o<=0&&(i=e),o>=1&&(i={x:a.x,y:a.y}),o>0&&o<1&&(i={x:(1-o)*e.x+o*a.x,y:(1-o)*e.y+o*a.y})}}e=a}),i},rX=t=>t.length===1?t[0]:eX(t),nX=(t,e,r)=>{let n;H.info("our points",e),e[0]!==r&&(e=e.reverse()),e.forEach(h=>{totalDistance+=Mc(h,n),n=h});let a=25,s;n=void 0,e.forEach(h=>{if(n&&!s){const d=Mc(h,n);if(d<a)a-=d;else{const f=a/d;f<=0&&(s=n),f>=1&&(s={x:h.x,y:h.y}),f>0&&f<1&&(s={x:(1-f)*n.x+f*h.x,y:(1-f)*n.y+f*h.y})}}n=h});const o=t?10:5,l=Math.atan2(e[0].y-s.y,e[0].x-s.x),u={x:0,y:0};return u.x=Math.sin(l)*o+(e[0].x+s.x)/2,u.y=-Math.cos(l)*o+(e[0].y+s.y)/2,u},iX=(t,e,r)=>{let n=JSON.parse(JSON.stringify(r)),i;H.info("our points",n),e!=="start_left"&&e!=="start_right"&&(n=n.reverse()),n.forEach(d=>{i=d});let s=25+t,o;i=void 0,n.forEach(d=>{if(i&&!o){const f=Mc(d,i);if(f<s)s-=f;else{const p=s/f;p<=0&&(o=i),p>=1&&(o={x:d.x,y:d.y}),p>0&&p<1&&(o={x:(1-p)*i.x+p*d.x,y:(1-p)*i.y+p*d.y})}}i=d});const l=10+t*.5,u=Math.atan2(n[0].y-o.y,n[0].x-o.x),h={x:0,y:0};return h.x=Math.sin(u)*l+(n[0].x+o.x)/2,h.y=-Math.cos(u)*l+(n[0].y+o.y)/2,e==="start_left"&&(h.x=Math.sin(u+Math.PI)*l+(n[0].x+o.x)/2,h.y=-Math.cos(u+Math.PI)*l+(n[0].y+o.y)/2),e==="end_right"&&(h.x=Math.sin(u-Math.PI)*l+(n[0].x+o.x)/2-5,h.y=-Math.cos(u-Math.PI)*l+(n[0].y+o.y)/2-5),e==="end_left"&&(h.x=Math.sin(u)*l+(n[0].x+o.x)/2-5,h.y=-Math.cos(u)*l+(n[0].y+o.y)/2-5),h},Ka=t=>{let e="",r="";for(let n=0;n<t.length;n++)typeof t[n]<"u"&&(t[n].startsWith("color:")||t[n].startsWith("text-align:")?r=r+t[n]+";":e=e+t[n]+";");return{style:e,labelStyle:r}};let sw=0;const ow=()=>(sw++,"id-"+Math.random().toString(36).substr(2,12)+"-"+sw);function aX(t){let e="";const r="0123456789abcdef",n=r.length;for(let i=0;i<t;i++)e+=r.charAt(Math.floor(Math.random()*n));return e}const lw=t=>aX(t.length),sX=function(){return{x:0,y:0,fill:void 0,anchor:"start",style:"#666",width:100,height:100,textMargin:0,rx:0,ry:0,valign:void 0}},oX=function(t,e){const r=e.text.replace(pe.lineBreakRegex," "),n=t.append("text");n.attr("x",e.x),n.attr("y",e.y),n.style("text-anchor",e.anchor),n.style("font-family",e.fontFamily),n.style("font-size",e.fontSize),n.style("font-weight",e.fontWeight),n.attr("fill",e.fill),typeof e.class<"u"&&n.attr("class",e.class);const i=n.append("tspan");return i.attr("x",e.x+e.textMargin*2),i.attr("fill",e.fill),i.text(r),n},cw=Gf((t,e,r)=>{if(!t||(r=Object.assign({fontSize:12,fontWeight:400,fontFamily:"Arial",joinWith:"<br/>"},r),pe.lineBreakRegex.test(t)))return t;const n=t.split(" "),i=[];let a="";return n.forEach((s,o)=>{const l=Bi(`${s} `,r),u=Bi(a,r);if(l>e){const{hyphenatedStrings:f,remainingWord:p}=lX(s,e,"-",r);i.push(a,...f),a=p}else u+l>=e?(i.push(a),a=s):a=[a,s].filter(Boolean).join(" ");o+1===n.length&&i.push(a)}),i.filter(s=>s!=="").join(r.joinWith)},(t,e,r)=>`${t}${e}${r.fontSize}${r.fontWeight}${r.fontFamily}${r.joinWith}`),lX=Gf((t,e,r="-",n)=>{n=Object.assign({fontSize:12,fontWeight:400,fontFamily:"Arial",margin:0},n);const i=t.split(""),a=[];let s="";return i.forEach((o,l)=>{const u=`${s}${o}`;if(Bi(u,n)>=e){const d=l+1,f=i.length===d,p=`${u}${r}`;a.push(f?u:p),s=""}else s=u}),{hyphenatedStrings:a,remainingWord:s}},(t,e,r="-",n)=>`${t}${e}${r}${n.fontSize}${n.fontWeight}${n.fontFamily}`),eg=function(t,e){return e=Object.assign({fontSize:12,fontWeight:400,fontFamily:"Arial",margin:15},e),rg(t,e).height},Bi=function(t,e){return e=Object.assign({fontSize:12,fontWeight:400,fontFamily:"Arial"},e),rg(t,e).width},rg=Gf(function(t,e){e=Object.assign({fontSize:12,fontWeight:400,fontFamily:"Arial"},e);const{fontSize:r,fontFamily:n,fontWeight:i}=e;if(!t)return{width:0,height:0};const a=["sans-serif",n],s=t.split(pe.lineBreakRegex),o=[],l=St("body");if(!l.remove)return{width:0,height:0,lineHeight:0};const u=l.append("svg");for(const d of a){let f=0;const p={width:0,height:0,lineHeight:0};for(const m of s){const _=sX();_.text=m;const y=oX(u,_).style("font-size",r).style("font-weight",i).style("font-family",d),b=(y._groups||y)[0][0].getBBox();p.width=Math.round(Math.max(p.width,b.width)),f=Math.round(b.height),p.height+=f,p.lineHeight=Math.round(Math.max(p.lineHeight,f))}o.push(p)}u.remove();const h=isNaN(o[1].height)||isNaN(o[1].width)||isNaN(o[1].lineHeight)||o[0].height>o[1].height&&o[0].width>o[1].width&&o[0].lineHeight>o[1].lineHeight?0:1;return o[h]},(t,e)=>`${t}${e.fontSize}${e.fontWeight}${e.fontFamily}`),cX=class{constructor(e,r){this.deterministic=e,this.seed=r,this.count=r?r.length:0}next(){return this.deterministic?this.count++:Date.now()}};let jf;const uX=function(t){return jf=jf||document.createElement("div"),t=escape(t).replace(/%26/g,"&").replace(/%23/g,"#").replace(/%3B/g,";"),jf.innerHTML=t,unescape(jf.textContent)},Vs=t=>{if(H.debug("directiveSanitizer called with",t),typeof t=="object"&&(t.length?t.forEach(e=>Vs(e)):Object.keys(t).forEach(e=>{H.debug("Checking key",e),e.indexOf("__")===0&&(H.debug("sanitize deleting __ option",e),delete t[e]),e.indexOf("proto")>=0&&(H.debug("sanitize deleting proto option",e),delete t[e]),e.indexOf("constr")>=0&&(H.debug("sanitize deleting constr option",e),delete t[e]),e.indexOf("themeCSS")>=0&&(H.debug("sanitizing themeCss option"),t[e]=$f(t[e])),e.indexOf("fontFamily")>=0&&(H.debug("sanitizing fontFamily option"),t[e]=$f(t[e])),e.indexOf("altFontFamily")>=0&&(H.debug("sanitizing altFontFamily option"),t[e]=$f(t[e])),vG.indexOf(e)<0?(H.debug("sanitize deleting option",e),delete t[e]):typeof t[e]=="object"&&(H.debug("sanitize deleting object",e),Vs(t[e]))})),t.themeVariables){const e=Object.keys(t.themeVariables);for(let r=0;r<e.length;r++){const n=e[r],i=t.themeVariables[n];i&&i.match&&!i.match(/^[a-zA-Z0-9#,";()%. ]+$/)&&(t.themeVariables[n]="")}}H.debug("After sanitization",t)},$f=t=>{let e=0,r=0;for(let n=0;n<t.length;n++){if(e<r)return"{ /* ERROR: Unbalanced CSS */ }";t[n]==="{"?e++:t[n]==="}"&&r++}return e!==r?"{ /* ERROR: Unbalanced CSS */ }":t};function ng(t){return"str"in t}function hX(t){return t instanceof Error?t.message:String(t)}const Se={assignWithDepth:fr,wrapLabel:cw,calculateTextHeight:eg,calculateTextWidth:Bi,calculateTextDimensions:rg,detectInit:Z$,detectDirective:aw,isSubstringInArray:Q$,interpolateToCurve:Ni,calcLabelPosition:rX,calcCardinalityPosition:nX,calcTerminalLabelPosition:iX,formatUrl:J$,getStylesFromArray:Ka,generateId:ow,random:lw,runFunc:tX,entityDecode:uX,initIdGenerator:cX,directiveSanitizer:Vs,sanitizeCss:$f};var uw="comm",hw="rule",fw="decl",fX="@import",dX="@keyframes",pX=Math.abs,ig=String.fromCharCode;function dw(t){return t.trim()}function ag(t,e,r){return t.replace(e,r)}function gX(t,e){return t.indexOf(e)}function Xf(t,e){return t.charCodeAt(e)|0}function Lc(t,e,r){return t.slice(e,r)}function Za(t){return t.length}function pw(t){return t.length}function Kf(t,e){return e.push(t),t}var Zf=1,jo=1,gw=0,zn=0,dr=0,$o="";function sg(t,e,r,n,i,a,s){return{value:t,root:e,parent:r,type:n,props:i,children:a,line:Zf,column:jo,length:s,return:""}}function yX(){return dr}function mX(){return dr=zn>0?Xf($o,--zn):0,jo--,dr===10&&(jo=1,Zf--),dr}function oi(){return dr=zn<gw?Xf($o,zn++):0,jo++,dr===10&&(jo=1,Zf++),dr}function zs(){return Xf($o,zn)}function Qf(){return zn}function Jf(t,e){return Lc($o,t,e)}function og(t){switch(t){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function bX(t){return Zf=jo=1,gw=Za($o=t),zn=0,[]}function _X(t){return $o="",t}function lg(t){return dw(Jf(zn-1,cg(t===91?t+2:t===40?t+1:t)))}function vX(t){for(;(dr=zs())&&dr<33;)oi();return og(t)>2||og(dr)>3?"":" "}function xX(t,e){for(;--e&&oi()&&!(dr<48||dr>102||dr>57&&dr<65||dr>70&&dr<97););return Jf(t,Qf()+(e<6&&zs()==32&&oi()==32))}function cg(t){for(;oi();)switch(dr){case t:return zn;case 34:case 39:t!==34&&t!==39&&cg(dr);break;case 40:t===41&&cg(t);break;case 92:oi();break}return zn}function kX(t,e){for(;oi()&&t+dr!==47+10;)if(t+dr===42+42&&zs()===47)break;return"/*"+Jf(e,zn-1)+"*"+ig(t===47?t:oi())}function wX(t){for(;!og(zs());)oi();return Jf(t,zn)}function yw(t){return _X(t1("",null,null,null,[""],t=bX(t),0,[0],t))}function t1(t,e,r,n,i,a,s,o,l){for(var u=0,h=0,d=s,f=0,p=0,m=0,_=1,y=1,b=1,x=0,k="",T=i,C=a,M=n,S=k;y;)switch(m=x,x=oi()){case 40:if(m!=108&&Xf(S,d-1)==58){gX(S+=ag(lg(x),"&","&\f"),"&\f")!=-1&&(b=-1);break}case 34:case 39:case 91:S+=lg(x);break;case 9:case 10:case 13:case 32:S+=vX(m);break;case 92:S+=xX(Qf()-1,7);continue;case 47:switch(zs()){case 42:case 47:Kf(TX(kX(oi(),Qf()),e,r),l);break;default:S+="/"}break;case 123*_:o[u++]=Za(S)*b;case 125*_:case 59:case 0:switch(x){case 0:case 125:y=0;case 59+h:p>0&&Za(S)-d&&Kf(p>32?bw(S+";",n,r,d-1):bw(ag(S," ","")+";",n,r,d-2),l);break;case 59:S+=";";default:if(Kf(M=mw(S,e,r,u,h,i,o,k,T=[],C=[],d),a),x===123)if(h===0)t1(S,e,M,M,T,a,d,o,C);else switch(f){case 100:case 109:case 115:t1(t,M,M,n&&Kf(mw(t,M,M,0,0,i,o,k,i,T=[],d),C),i,C,d,o,n?T:C);break;default:t1(S,M,M,M,[""],C,0,o,C)}}u=h=p=0,_=b=1,k=S="",d=s;break;case 58:d=1+Za(S),p=m;default:if(_<1){if(x==123)--_;else if(x==125&&_++==0&&mX()==125)continue}switch(S+=ig(x),x*_){case 38:b=h>0?1:(S+="\f",-1);break;case 44:o[u++]=(Za(S)-1)*b,b=1;break;case 64:zs()===45&&(S+=lg(oi())),f=zs(),h=d=Za(k=S+=wX(Qf())),x++;break;case 45:m===45&&Za(S)==2&&(_=0)}}return a}function mw(t,e,r,n,i,a,s,o,l,u,h){for(var d=i-1,f=i===0?a:[""],p=pw(f),m=0,_=0,y=0;m<n;++m)for(var b=0,x=Lc(t,d+1,d=pX(_=s[m])),k=t;b<p;++b)(k=dw(_>0?f[b]+" "+x:ag(x,/&\f/g,f[b])))&&(l[y++]=k);return sg(t,e,r,i===0?hw:o,l,u,h)}function TX(t,e,r){return sg(t,e,r,uw,ig(yX()),Lc(t,2,-2),0)}function bw(t,e,r,n){return sg(t,e,r,fw,Lc(t,0,n),Lc(t,n+1,-1),n)}function e1(t,e){for(var r="",n=pw(t),i=0;i<n;i++)r+=e(t[i],i,t,e)||"";return r}function _w(t,e,r,n){switch(t.type){case fX:case fw:return t.return=t.return||t.value;case uw:return"";case dX:return t.return=t.value+"{"+e1(t.children,n)+"}";case hw:t.value=t.props.join(",")}return Za(r=e1(t.children,n))?t.return=t.value+"{"+r+"}":""}const r1={name:"mermaid",version:"9.2.2",description:"Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",main:"./dist/mermaid.min.js",module:"./dist/mermaid.core.mjs",types:"./dist/mermaid.d.ts",type:"commonjs",exports:{".":{require:"./dist/mermaid.min.js",import:"./dist/mermaid.core.mjs",types:"./dist/mermaid.d.ts"},"./*":"./*"},keywords:["diagram","markdown","flowchart","sequence diagram","gantt","class diagram","git graph"],scripts:{clean:"rimraf dist","build:code":"node .esbuild/esbuild.cjs","build:types":"tsc -p ./tsconfig.json --emitDeclarationOnly","build:watch":"yarn build:code --watch","build:esbuild":'concurrently "yarn build:code" "yarn build:types"',build:"yarn clean; yarn build:esbuild",dev:"node .esbuild/serve.cjs","docs:build":"ts-node-esm src/docs.mts","docs:verify":"yarn docs:build --verify","todo-postbuild":"documentation build src/mermaidAPI.ts src/config.ts src/defaultConfig.ts --shallow -f md --markdown-toc false > src/docs/Setup.md && prettier --write src/docs/Setup.md",release:"yarn build",lint:"eslint --cache --ignore-path .gitignore . && yarn lint:jison && prettier --check .","lint:fix":"eslint --fix --ignore-path .gitignore . && prettier --write .","lint:jison":"ts-node-esm src/jison/lint.mts",cypress:"cypress run","cypress:open":"cypress open",e2e:"start-server-and-test dev http://localhost:9000/ cypress","todo-prepare":'concurrently "husky install" "yarn build"',"pre-commit":"lint-staged"},repository:{type:"git",url:"https://github.com/mermaid-js/mermaid"},author:"Knut Sveidqvist",license:"MIT",standard:{ignore:["**/parser/*.js","dist/**/*.js","cypress/**/*.js"],globals:["page"]},dependencies:{"@braintree/sanitize-url":"^6.0.0",d3:"^7.0.0",dagre:"^0.8.5","dagre-d3":"^0.6.4",dompurify:"2.4.0","fast-clone":"^1.5.13",graphlib:"^2.1.8",khroma:"^2.0.0",lodash:"^4.17.21","moment-mini":"^2.24.0","non-layered-tidy-tree-layout":"^2.0.2",stylis:"^4.1.2",uuid:"^9.0.0"},devDependencies:{"@applitools/eyes-cypress":"^3.25.7","@commitlint/cli":"^17.1.2","@commitlint/config-conventional":"^17.0.0","@types/d3":"^7.4.0","@types/dompurify":"^2.3.4","@types/eslint":"^8.4.6","@types/express":"^4.17.13","@types/jsdom":"^20.0.0","@types/lodash":"^4.14.185","@types/prettier":"^2.7.0","@types/stylis":"^4.0.2","@types/uuid":"^8.3.4","@typescript-eslint/eslint-plugin":"^5.37.0","@typescript-eslint/parser":"^5.37.0",concurrently:"^7.4.0",coveralls:"^3.1.1",cypress:"^10.0.0","cypress-image-snapshot":"^4.0.1",documentation:"13.2.0",esbuild:"^0.15.8",eslint:"^8.23.1","eslint-config-prettier":"^8.5.0","eslint-plugin-cypress":"^2.12.1","eslint-plugin-html":"^7.1.0","eslint-plugin-jest":"^27.0.4","eslint-plugin-jsdoc":"^39.3.6","eslint-plugin-json":"^3.1.0","eslint-plugin-markdown":"^3.0.0",express:"^4.18.1",globby:"^13.1.2",husky:"^8.0.0","identity-obj-proxy":"^3.0.0",jison:"^0.4.18","js-base64":"3.7.2",jsdom:"^20.0.0","lint-staged":"^13.0.0",moment:"^2.23.0","path-browserify":"^1.0.1",prettier:"^2.7.1","prettier-plugin-jsdoc":"^0.4.2",remark:"^14.0.2",rimraf:"^3.0.2","start-server-and-test":"^1.12.6","ts-node":"^10.9.1",typescript:"^4.8.3","unist-util-flatmap":"^1.0.0"},resolutions:{d3:"^7.0.0"},files:["dist","README.md"],sideEffects:["**/*.css","**/*.scss"]},Xo=Object.freeze(Xa);let mn=fr({},Xo),vw,Ko=[],Rc=fr({},Xo);const n1=(t,e)=>{let r=fr({},t),n={};for(let i=0;i<e.length;i++){const a=e[i];ww(a),n=fr(n,a)}if(r=fr(r,n),n.theme&&n.theme in aa){const i=fr({},vw),a=fr(i.themeVariables||{},n.themeVariables);r.theme&&r.theme in aa&&(r.themeVariables=aa[r.theme].getThemeVariables(a))}return Rc=r,Cw(Rc),Rc},EX=t=>(mn=fr({},Xo),mn=fr(mn,t),t.theme&&aa[t.theme]&&(mn.themeVariables=aa[t.theme].getThemeVariables(t.themeVariables)),n1(mn,Ko),mn),CX=t=>{vw=fr({},t)},SX=t=>(mn=fr(mn,t),n1(mn,Ko),mn),xw=()=>fr({},mn),kw=t=>(Cw(t),fr(Rc,t),nt()),nt=()=>fr({},Rc),ww=t=>{var e;["secure",...(e=mn.secure)!=null?e:[]].forEach(r=>{typeof t[r]<"u"&&(H.debug(`Denied attempt to modify a secure key ${r}`,t[r]),delete t[r])}),Object.keys(t).forEach(r=>{r.indexOf("__")===0&&delete t[r]}),Object.keys(t).forEach(r=>{typeof t[r]=="string"&&(t[r].indexOf("<")>-1||t[r].indexOf(">")>-1||t[r].indexOf("url(data:")>-1)&&delete t[r],typeof t[r]=="object"&&ww(t[r])})},ug=t=>{t.fontFamily&&(t.themeVariables?t.themeVariables.fontFamily||(t.themeVariables={fontFamily:t.fontFamily}):t.themeVariables={fontFamily:t.fontFamily}),Ko.push(t),n1(mn,Ko)},Ic=(t=mn)=>{Ko=[],n1(t,Ko)};var Tw=(t=>(t.LAZY_LOAD_DEPRECATED="The configuration options lazyLoadedDiagrams and loadExternalDiagramsAtStartup are deprecated. Please use registerExternalDiagrams instead.",t))(Tw||{});const Ew={},AX=t=>{Ew[t]||(H.warn(Tw[t]),Ew[t]=!0)},Cw=t=>{!t||(t.lazyLoadedDiagrams||t.loadExternalDiagramsAtStartup)&&AX("LAZY_LOAD_DEPRECATED")},MX=function(t,e){for(let r of e)t.attr(r[0],r[1])},LX=function(t,e,r){let n=new Map;return r?(n.set("width","100%"),n.set("style",`max-width: ${e}px;`)):n.set("width",e),n},li=function(t,e,r,n){const i=LX(e,r,n);MX(t,i)},i1=function(t,e,r,n){const i=e.node().getBBox(),a=i.width,s=i.height;H.info(`SVG bounds: ${a}x${s}`,i);let o=0,l=0;H.info(`Graph bounds: ${o}x${l}`,t),o=a+r*2,l=s+r*2,H.info(`Calculated bounds: ${o}x${l}`),li(e,l,o,n);const u=`${i.x-r} ${i.y-r} ${i.width+2*r} ${i.height+2*r}`;e.attr("viewBox",u)},Nc=t=>`g.classGroup text { + fill: ${t.nodeBorder}; + fill: ${t.classText}; + stroke: none; + font-family: ${t.fontFamily}; + font-size: 10px; + + .title { + font-weight: bolder; + } + +} + +.nodeLabel, .edgeLabel { + color: ${t.classText}; +} +.edgeLabel .label rect { + fill: ${t.mainBkg}; +} +.label text { + fill: ${t.classText}; +} +.edgeLabel .label span { + background: ${t.mainBkg}; +} + +.classTitle { + font-weight: bolder; +} +.node rect, + .node circle, + .node ellipse, + .node polygon, + .node path { + fill: ${t.mainBkg}; + stroke: ${t.nodeBorder}; + stroke-width: 1px; + } + + +.divider { + stroke: ${t.nodeBorder}; + stroke: 1; +} + +g.clickable { + cursor: pointer; +} + +g.classGroup rect { + fill: ${t.mainBkg}; + stroke: ${t.nodeBorder}; +} + +g.classGroup line { + stroke: ${t.nodeBorder}; + stroke-width: 1; +} + +.classLabel .box { + stroke: none; + stroke-width: 0; + fill: ${t.mainBkg}; + opacity: 0.5; +} + +.classLabel .label { + fill: ${t.nodeBorder}; + font-size: 10px; +} + +.relation { + stroke: ${t.lineColor}; + stroke-width: 1; + fill: none; +} + +.dashed-line{ + stroke-dasharray: 3; +} + +#compositionStart, .composition { + fill: ${t.lineColor} !important; + stroke: ${t.lineColor} !important; + stroke-width: 1; +} + +#compositionEnd, .composition { + fill: ${t.lineColor} !important; + stroke: ${t.lineColor} !important; + stroke-width: 1; +} + +#dependencyStart, .dependency { + fill: ${t.lineColor} !important; + stroke: ${t.lineColor} !important; + stroke-width: 1; +} + +#dependencyStart, .dependency { + fill: ${t.lineColor} !important; + stroke: ${t.lineColor} !important; + stroke-width: 1; +} + +#extensionStart, .extension { + fill: ${t.lineColor} !important; + stroke: ${t.lineColor} !important; + stroke-width: 1; +} + +#extensionEnd, .extension { + fill: ${t.lineColor} !important; + stroke: ${t.lineColor} !important; + stroke-width: 1; +} + +#aggregationStart, .aggregation { + fill: ${t.mainBkg} !important; + stroke: ${t.lineColor} !important; + stroke-width: 1; +} + +#aggregationEnd, .aggregation { + fill: ${t.mainBkg} !important; + stroke: ${t.lineColor} !important; + stroke-width: 1; +} + +#lollipopStart, .lollipop { + fill: ${t.mainBkg} !important; + stroke: ${t.lineColor} !important; + stroke-width: 1; +} + +#lollipopEnd, .lollipop { + fill: ${t.mainBkg} !important; + stroke: ${t.lineColor} !important; + stroke-width: 1; +} + +.edgeTerminals { + font-size: 11px; +} + +`,Sw=t=>` + .entityBox { + fill: ${t.mainBkg}; + stroke: ${t.nodeBorder}; + } + + .attributeBoxOdd { + fill: ${t.attributeBackgroundColorOdd}; + stroke: ${t.nodeBorder}; + } + + .attributeBoxEven { + fill: ${t.attributeBackgroundColorEven}; + stroke: ${t.nodeBorder}; + } + + .relationshipLabelBox { + fill: ${t.tertiaryColor}; + opacity: 0.7; + background-color: ${t.tertiaryColor}; + rect { + opacity: 0.5; + } + } + + .relationshipLine { + stroke: ${t.lineColor}; + } +`,Aw=()=>"",a1=t=>`.label { + font-family: ${t.fontFamily}; + color: ${t.nodeTextColor||t.textColor}; + } + .cluster-label text { + fill: ${t.titleColor}; + } + .cluster-label span { + color: ${t.titleColor}; + } + + .label text,span { + fill: ${t.nodeTextColor||t.textColor}; + color: ${t.nodeTextColor||t.textColor}; + } + + .node rect, + .node circle, + .node ellipse, + .node polygon, + .node path { + fill: ${t.mainBkg}; + stroke: ${t.nodeBorder}; + stroke-width: 1px; + } + + .node .label { + text-align: center; + } + .node.clickable { + cursor: pointer; + } + + .arrowheadPath { + fill: ${t.arrowheadColor}; + } + + .edgePath .path { + stroke: ${t.lineColor}; + stroke-width: 2.0px; + } + + .flowchart-link { + stroke: ${t.lineColor}; + fill: none; + } + + .edgeLabel { + background-color: ${t.edgeLabelBackground}; + rect { + opacity: 0.5; + background-color: ${t.edgeLabelBackground}; + fill: ${t.edgeLabelBackground}; + } + text-align: center; + } + + .cluster rect { + fill: ${t.clusterBkg}; + stroke: ${t.clusterBorder}; + stroke-width: 1px; + } + + .cluster text { + fill: ${t.titleColor}; + } + + .cluster span { + color: ${t.titleColor}; + } + /* .cluster div { + color: ${t.titleColor}; + } */ + + div.mermaidTooltip { + position: absolute; + text-align: center; + max-width: 200px; + padding: 2px; + font-family: ${t.fontFamily}; + font-size: 12px; + background: ${t.tertiaryColor}; + border: 1px solid ${t.border2}; + border-radius: 2px; + pointer-events: none; + z-index: 100; + } +`,Mw=t=>` + .mermaid-main-font { + font-family: "trebuchet ms", verdana, arial, sans-serif; + font-family: var(--mermaid-font-family); + } + .exclude-range { + fill: ${t.excludeBkgColor}; + } + + .section { + stroke: none; + opacity: 0.2; + } + + .section0 { + fill: ${t.sectionBkgColor}; + } + + .section2 { + fill: ${t.sectionBkgColor2}; + } + + .section1, + .section3 { + fill: ${t.altSectionBkgColor}; + opacity: 0.2; + } + + .sectionTitle0 { + fill: ${t.titleColor}; + } + + .sectionTitle1 { + fill: ${t.titleColor}; + } + + .sectionTitle2 { + fill: ${t.titleColor}; + } + + .sectionTitle3 { + fill: ${t.titleColor}; + } + + .sectionTitle { + text-anchor: start; + // font-size: ${t.ganttFontSize}; + // text-height: 14px; + font-family: 'trebuchet ms', verdana, arial, sans-serif; + font-family: var(--mermaid-font-family); + + } + + + /* Grid and axis */ + + .grid .tick { + stroke: ${t.gridColor}; + opacity: 0.8; + shape-rendering: crispEdges; + text { + font-family: ${t.fontFamily}; + fill: ${t.textColor}; + } + } + + .grid path { + stroke-width: 0; + } + + + /* Today line */ + + .today { + fill: none; + stroke: ${t.todayLineColor}; + stroke-width: 2px; + } + + + /* Task styling */ + + /* Default task */ + + .task { + stroke-width: 2; + } + + .taskText { + text-anchor: middle; + font-family: 'trebuchet ms', verdana, arial, sans-serif; + font-family: var(--mermaid-font-family); + } + + // .taskText:not([font-size]) { + // font-size: ${t.ganttFontSize}; + // } + + .taskTextOutsideRight { + fill: ${t.taskTextDarkColor}; + text-anchor: start; + // font-size: ${t.ganttFontSize}; + font-family: 'trebuchet ms', verdana, arial, sans-serif; + font-family: var(--mermaid-font-family); + + } + + .taskTextOutsideLeft { + fill: ${t.taskTextDarkColor}; + text-anchor: end; + // font-size: ${t.ganttFontSize}; + } + + /* Special case clickable */ + .task.clickable { + cursor: pointer; + } + .taskText.clickable { + cursor: pointer; + fill: ${t.taskTextClickableColor} !important; + font-weight: bold; + } + + .taskTextOutsideLeft.clickable { + cursor: pointer; + fill: ${t.taskTextClickableColor} !important; + font-weight: bold; + } + + .taskTextOutsideRight.clickable { + cursor: pointer; + fill: ${t.taskTextClickableColor} !important; + font-weight: bold; + } + + /* Specific task settings for the sections*/ + + .taskText0, + .taskText1, + .taskText2, + .taskText3 { + fill: ${t.taskTextColor}; + } + + .task0, + .task1, + .task2, + .task3 { + fill: ${t.taskBkgColor}; + stroke: ${t.taskBorderColor}; + } + + .taskTextOutside0, + .taskTextOutside2 + { + fill: ${t.taskTextOutsideColor}; + } + + .taskTextOutside1, + .taskTextOutside3 { + fill: ${t.taskTextOutsideColor}; + } + + + /* Active task */ + + .active0, + .active1, + .active2, + .active3 { + fill: ${t.activeTaskBkgColor}; + stroke: ${t.activeTaskBorderColor}; + } + + .activeText0, + .activeText1, + .activeText2, + .activeText3 { + fill: ${t.taskTextDarkColor} !important; + } + + + /* Completed task */ + + .done0, + .done1, + .done2, + .done3 { + stroke: ${t.doneTaskBorderColor}; + fill: ${t.doneTaskBkgColor}; + stroke-width: 2; + } + + .doneText0, + .doneText1, + .doneText2, + .doneText3 { + fill: ${t.taskTextDarkColor} !important; + } + + + /* Tasks on the critical line */ + + .crit0, + .crit1, + .crit2, + .crit3 { + stroke: ${t.critBorderColor}; + fill: ${t.critBkgColor}; + stroke-width: 2; + } + + .activeCrit0, + .activeCrit1, + .activeCrit2, + .activeCrit3 { + stroke: ${t.critBorderColor}; + fill: ${t.activeTaskBkgColor}; + stroke-width: 2; + } + + .doneCrit0, + .doneCrit1, + .doneCrit2, + .doneCrit3 { + stroke: ${t.critBorderColor}; + fill: ${t.doneTaskBkgColor}; + stroke-width: 2; + cursor: pointer; + shape-rendering: crispEdges; + } + + .milestone { + transform: rotate(45deg) scale(0.8,0.8); + } + + .milestoneText { + font-style: italic; + } + .doneCritText0, + .doneCritText1, + .doneCritText2, + .doneCritText3 { + fill: ${t.taskTextDarkColor} !important; + } + + .activeCritText0, + .activeCritText1, + .activeCritText2, + .activeCritText3 { + fill: ${t.taskTextDarkColor} !important; + } + + .titleText { + text-anchor: middle; + font-size: 18px; + fill: ${t.textColor} ; + font-family: 'trebuchet ms', verdana, arial, sans-serif; + font-family: var(--mermaid-font-family); + } +`,Lw=()=>"",Rw=t=>` + .pieCircle{ + stroke: ${t.pieStrokeColor}; + stroke-width : ${t.pieStrokeWidth}; + opacity : ${t.pieOpacity}; + } + .pieTitleText { + text-anchor: middle; + font-size: ${t.pieTitleTextSize}; + fill: ${t.pieTitleTextColor}; + font-family: ${t.fontFamily}; + } + .slice { + font-family: ${t.fontFamily}; + fill: ${t.pieSectionTextColor}; + font-size:${t.pieSectionTextSize}; + // fill: white; + } + .legend text { + fill: ${t.pieLegendTextColor}; + font-family: ${t.fontFamily}; + font-size: ${t.pieLegendTextSize}; + } +`,Iw=t=>` + + marker { + fill: ${t.relationColor}; + stroke: ${t.relationColor}; + } + + marker.cross { + stroke: ${t.lineColor}; + } + + svg { + font-family: ${t.fontFamily}; + font-size: ${t.fontSize}; + } + + .reqBox { + fill: ${t.requirementBackground}; + fill-opacity: 100%; + stroke: ${t.requirementBorderColor}; + stroke-width: ${t.requirementBorderSize}; + } + + .reqTitle, .reqLabel{ + fill: ${t.requirementTextColor}; + } + .reqLabelBox { + fill: ${t.relationLabelBackground}; + fill-opacity: 100%; + } + + .req-title-line { + stroke: ${t.requirementBorderColor}; + stroke-width: ${t.requirementBorderSize}; + } + .relationshipLine { + stroke: ${t.relationColor}; + stroke-width: 1; + } + .relationshipLabel { + fill: ${t.relationLabelColor}; + } + +`,Nw=t=>`.actor { + stroke: ${t.actorBorder}; + fill: ${t.actorBkg}; + } + + text.actor > tspan { + fill: ${t.actorTextColor}; + stroke: none; + } + + .actor-line { + stroke: ${t.actorLineColor}; + } + + .messageLine0 { + stroke-width: 1.5; + stroke-dasharray: none; + stroke: ${t.signalColor}; + } + + .messageLine1 { + stroke-width: 1.5; + stroke-dasharray: 2, 2; + stroke: ${t.signalColor}; + } + + #arrowhead path { + fill: ${t.signalColor}; + stroke: ${t.signalColor}; + } + + .sequenceNumber { + fill: ${t.sequenceNumberColor}; + } + + #sequencenumber { + fill: ${t.signalColor}; + } + + #crosshead path { + fill: ${t.signalColor}; + stroke: ${t.signalColor}; + } + + .messageText { + fill: ${t.signalTextColor}; + stroke: none; + } + + .labelBox { + stroke: ${t.labelBoxBorderColor}; + fill: ${t.labelBoxBkgColor}; + } + + .labelText, .labelText > tspan { + fill: ${t.labelTextColor}; + stroke: none; + } + + .loopText, .loopText > tspan { + fill: ${t.loopTextColor}; + stroke: none; + } + + .loopLine { + stroke-width: 2px; + stroke-dasharray: 2, 2; + stroke: ${t.labelBoxBorderColor}; + fill: ${t.labelBoxBorderColor}; + } + + .note { + //stroke: #decc93; + stroke: ${t.noteBorderColor}; + fill: ${t.noteBkgColor}; + } + + .noteText, .noteText > tspan { + fill: ${t.noteTextColor}; + stroke: none; + } + + .activation0 { + fill: ${t.activationBkgColor}; + stroke: ${t.activationBorderColor}; + } + + .activation1 { + fill: ${t.activationBkgColor}; + stroke: ${t.activationBorderColor}; + } + + .activation2 { + fill: ${t.activationBkgColor}; + stroke: ${t.activationBorderColor}; + } + + .actorPopupMenu { + position: absolute; + } + + .actorPopupMenuPanel { + position: absolute; + fill: ${t.actorBkg}; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + filter: drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4)); +} + .actor-man line { + stroke: ${t.actorBorder}; + fill: ${t.actorBkg}; + } + .actor-man circle, line { + stroke: ${t.actorBorder}; + fill: ${t.actorBkg}; + stroke-width: 2px; + } +`,s1=t=>` +defs #statediagram-barbEnd { + fill: ${t.transitionColor}; + stroke: ${t.transitionColor}; + } +g.stateGroup text { + fill: ${t.nodeBorder}; + stroke: none; + font-size: 10px; +} +g.stateGroup text { + fill: ${t.textColor}; + stroke: none; + font-size: 10px; + +} +g.stateGroup .state-title { + font-weight: bolder; + fill: ${t.stateLabelColor}; +} + +g.stateGroup rect { + fill: ${t.mainBkg}; + stroke: ${t.nodeBorder}; +} + +g.stateGroup line { + stroke: ${t.lineColor}; + stroke-width: 1; +} + +.transition { + stroke: ${t.transitionColor}; + stroke-width: 1; + fill: none; +} + +.stateGroup .composit { + fill: ${t.background}; + border-bottom: 1px +} + +.stateGroup .alt-composit { + fill: #e0e0e0; + border-bottom: 1px +} + +.state-note { + stroke: ${t.noteBorderColor}; + fill: ${t.noteBkgColor}; + + text { + fill: ${t.noteTextColor}; + stroke: none; + font-size: 10px; + } +} + +.stateLabel .box { + stroke: none; + stroke-width: 0; + fill: ${t.mainBkg}; + opacity: 0.5; +} + +.edgeLabel .label rect { + fill: ${t.labelBackgroundColor}; + opacity: 0.5; +} +.edgeLabel .label text { + fill: ${t.transitionLabelColor||t.tertiaryTextColor}; +} +.label div .edgeLabel { + color: ${t.transitionLabelColor||t.tertiaryTextColor}; +} + +.stateLabel text { + fill: ${t.stateLabelColor}; + font-size: 10px; + font-weight: bold; +} + +.node circle.state-start { + fill: ${t.specialStateColor}; + stroke: ${t.specialStateColor}; +} + +.node .fork-join { + fill: ${t.specialStateColor}; + stroke: ${t.specialStateColor}; +} + +.node circle.state-end { + fill: ${t.innerEndBackground}; + stroke: ${t.background}; + stroke-width: 1.5 +} +.end-state-inner { + fill: ${t.compositeBackground||t.background}; + // stroke: ${t.background}; + stroke-width: 1.5 +} + +.node rect { + fill: ${t.stateBkg||t.mainBkg}; + stroke: ${t.stateBorder||t.nodeBorder}; + stroke-width: 1px; +} +.node polygon { + fill: ${t.mainBkg}; + stroke: ${t.stateBorder||t.nodeBorder};; + stroke-width: 1px; +} +#statediagram-barbEnd { + fill: ${t.lineColor}; +} + +.statediagram-cluster rect { + fill: ${t.compositeTitleBackground}; + stroke: ${t.stateBorder||t.nodeBorder}; + stroke-width: 1px; +} + +.cluster-label, .nodeLabel { + color: ${t.stateLabelColor}; +} + +.statediagram-cluster rect.outer { + rx: 5px; + ry: 5px; +} +.statediagram-state .divider { + stroke: ${t.stateBorder||t.nodeBorder}; +} + +.statediagram-state .title-state { + rx: 5px; + ry: 5px; +} +.statediagram-cluster.statediagram-cluster .inner { + fill: ${t.compositeBackground||t.background}; +} +.statediagram-cluster.statediagram-cluster-alt .inner { + fill: ${t.altBackground?t.altBackground:"#efefef"}; +} + +.statediagram-cluster .inner { + rx:0; + ry:0; +} + +.statediagram-state rect.basic { + rx: 5px; + ry: 5px; +} +.statediagram-state rect.divider { + stroke-dasharray: 10,10; + fill: ${t.altBackground?t.altBackground:"#efefef"}; +} + +.note-edge { + stroke-dasharray: 5; +} + +.statediagram-note rect { + fill: ${t.noteBkgColor}; + stroke: ${t.noteBorderColor}; + stroke-width: 1px; + rx: 0; + ry: 0; +} +.statediagram-note rect { + fill: ${t.noteBkgColor}; + stroke: ${t.noteBorderColor}; + stroke-width: 1px; + rx: 0; + ry: 0; +} + +.statediagram-note text { + fill: ${t.noteTextColor}; +} + +.statediagram-note .nodeLabel { + color: ${t.noteTextColor}; +} +.statediagram .edgeLabel { + color: red; // ${t.noteTextColor}; +} + +#dependencyStart, #dependencyEnd { + fill: ${t.lineColor}; + stroke: ${t.lineColor}; + stroke-width: 1; +} +`,Bw=t=>`.label { + font-family: 'trebuchet ms', verdana, arial, sans-serif; + font-family: var(--mermaid-font-family); + color: ${t.textColor}; + } + .mouth { + stroke: #666; + } + + line { + stroke: ${t.textColor} + } + + .legend { + fill: ${t.textColor}; + } + + .label text { + fill: #333; + } + .label { + color: ${t.textColor} + } + + .face { + ${t.faceColor?`fill: ${t.faceColor}`:"fill: #FFF8DC"}; + stroke: #999; + } + + .node rect, + .node circle, + .node ellipse, + .node polygon, + .node path { + fill: ${t.mainBkg}; + stroke: ${t.nodeBorder}; + stroke-width: 1px; + } + + .node .label { + text-align: center; + } + .node.clickable { + cursor: pointer; + } + + .arrowheadPath { + fill: ${t.arrowheadColor}; + } + + .edgePath .path { + stroke: ${t.lineColor}; + stroke-width: 1.5px; + } + + .flowchart-link { + stroke: ${t.lineColor}; + fill: none; + } + + .edgeLabel { + background-color: ${t.edgeLabelBackground}; + rect { + opacity: 0.5; + } + text-align: center; + } + + .cluster rect { + } + + .cluster text { + fill: ${t.titleColor}; + } + + div.mermaidTooltip { + position: absolute; + text-align: center; + max-width: 200px; + padding: 2px; + font-family: 'trebuchet ms', verdana, arial, sans-serif; + font-family: var(--mermaid-font-family); + font-size: 12px; + background: ${t.tertiaryColor}; + border: 1px solid ${t.border2}; + border-radius: 2px; + pointer-events: none; + z-index: 100; + } + + .task-type-0, .section-type-0 { + ${t.fillType0?`fill: ${t.fillType0}`:""}; + } + .task-type-1, .section-type-1 { + ${t.fillType0?`fill: ${t.fillType1}`:""}; + } + .task-type-2, .section-type-2 { + ${t.fillType0?`fill: ${t.fillType2}`:""}; + } + .task-type-3, .section-type-3 { + ${t.fillType0?`fill: ${t.fillType3}`:""}; + } + .task-type-4, .section-type-4 { + ${t.fillType0?`fill: ${t.fillType4}`:""}; + } + .task-type-5, .section-type-5 { + ${t.fillType0?`fill: ${t.fillType5}`:""}; + } + .task-type-6, .section-type-6 { + ${t.fillType0?`fill: ${t.fillType6}`:""}; + } + .task-type-7, .section-type-7 { + ${t.fillType0?`fill: ${t.fillType7}`:""}; + } + + .actor-0 { + ${t.actor0?`fill: ${t.actor0}`:""}; + } + .actor-1 { + ${t.actor1?`fill: ${t.actor1}`:""}; + } + .actor-2 { + ${t.actor2?`fill: ${t.actor2}`:""}; + } + .actor-3 { + ${t.actor3?`fill: ${t.actor3}`:""}; + } + .actor-4 { + ${t.actor4?`fill: ${t.actor4}`:""}; + } + .actor-5 { + ${t.actor5?`fill: ${t.actor5}`:""}; + } +`,Dw=t=>`.person { + stroke: ${t.personBorder}; + fill: ${t.personBkg}; + } +`,o1={flowchart:a1,"flowchart-v2":a1,sequence:Nw,gantt:Mw,classDiagram:Nc,"classDiagram-v2":Nc,class:Nc,stateDiagram:s1,state:s1,info:Lw,pie:Rw,er:Sw,error:Aw,journey:Bw,requirement:Iw,c4:Dw},Ow=(t,e,r)=>{let n="";return t in o1&&o1[t]?n=o1[t](r):H.warn(`No theme found for ${t}`),` { + font-family: ${r.fontFamily}; + font-size: ${r.fontSize}; + fill: ${r.textColor} + } + + /* Classes common for multiple diagrams */ + + .error-icon { + fill: ${r.errorBkgColor}; + } + .error-text { + fill: ${r.errorTextColor}; + stroke: ${r.errorTextColor}; + } + + .edge-thickness-normal { + stroke-width: 2px; + } + .edge-thickness-thick { + stroke-width: 3.5px + } + .edge-pattern-solid { + stroke-dasharray: 0; + } + + .edge-pattern-dashed{ + stroke-dasharray: 3; + } + .edge-pattern-dotted { + stroke-dasharray: 2; + } + + .marker { + fill: ${r.lineColor}; + stroke: ${r.lineColor}; + } + .marker.cross { + stroke: ${r.lineColor}; + } + + svg { + font-family: ${r.fontFamily}; + font-size: ${r.fontSize}; + } + + ${n} + + ${e} +`},RX=(t,e)=>{o1[t]=e},Bc=H,IX=D0,Zo=nt,NX=t=>ai(t,Zo()),Fw=i1,Qo={},Lr=(t,e,r)=>{Bc.debug(`Registering diagram ${t}`),Qo[t]&&Bc.warn(`Diagram ${t} already registered.`),Qo[t]=e,r&&$k(t,r),RX(t,e.styles),e.injectUtils&&e.injectUtils(Bc,IX,Zo,NX,Fw),Bc.debug(`Registered diagram ${t}. ${Object.keys(Qo).join(", ")} diagrams registered.`)},Pw=t=>{if(Bc.debug(`Getting diagram ${t}. ${Object.keys(Qo).join(", ")} diagrams registered.`),t in Qo)return Qo[t];throw new qw(t)};class qw extends Error{constructor(e){super(`Diagram ${e} not found.`)}}var hg=function(){var t=function(C,M,S,R){for(S=S||{},R=C.length;R--;S[C[R]]=M);return S},e=[1,4],r=[1,7],n=[1,5],i=[1,9],a=[1,6],s=[2,6],o=[1,16],l=[6,8,14,20,22,24,25,27,29,32,37,40,50,54],u=[8,14,20,22,24,25,27,29,32,37,40],h=[8,13,14,20,22,24,25,27,29,32,37,40],d=[1,26],f=[6,8,14,50,54],p=[8,14,54],m=[1,65],_=[1,66],y=[1,67],b=[8,14,33,35,42,54],x={trace:function(){},yy:{},symbols_:{error:2,start:3,eol:4,directive:5,GG:6,document:7,EOF:8,":":9,DIR:10,options:11,body:12,OPT:13,NL:14,line:15,statement:16,commitStatement:17,mergeStatement:18,cherryPickStatement:19,acc_title:20,acc_title_value:21,acc_descr:22,acc_descr_value:23,acc_descr_multiline_value:24,section:25,branchStatement:26,CHECKOUT:27,ID:28,BRANCH:29,ORDER:30,NUM:31,CHERRY_PICK:32,COMMIT_ID:33,STR:34,COMMIT_TAG:35,EMPTYSTR:36,MERGE:37,COMMIT_TYPE:38,commitType:39,COMMIT:40,commit_arg:41,COMMIT_MSG:42,NORMAL:43,REVERSE:44,HIGHLIGHT:45,openDirective:46,typeDirective:47,closeDirective:48,argDirective:49,open_directive:50,type_directive:51,arg_directive:52,close_directive:53,";":54,$accept:0,$end:1},terminals_:{2:"error",6:"GG",8:"EOF",9:":",10:"DIR",13:"OPT",14:"NL",20:"acc_title",21:"acc_title_value",22:"acc_descr",23:"acc_descr_value",24:"acc_descr_multiline_value",25:"section",27:"CHECKOUT",28:"ID",29:"BRANCH",30:"ORDER",31:"NUM",32:"CHERRY_PICK",33:"COMMIT_ID",34:"STR",35:"COMMIT_TAG",36:"EMPTYSTR",37:"MERGE",38:"COMMIT_TYPE",40:"COMMIT",42:"COMMIT_MSG",43:"NORMAL",44:"REVERSE",45:"HIGHLIGHT",50:"open_directive",51:"type_directive",52:"arg_directive",53:"close_directive",54:";"},productions_:[0,[3,2],[3,2],[3,3],[3,4],[3,5],[7,0],[7,2],[11,2],[11,1],[12,0],[12,2],[15,2],[15,1],[16,1],[16,1],[16,1],[16,2],[16,2],[16,1],[16,1],[16,1],[16,2],[26,2],[26,4],[19,3],[19,5],[19,5],[19,5],[19,5],[18,2],[18,4],[18,4],[18,4],[18,6],[18,6],[18,6],[18,6],[18,6],[18,6],[18,8],[18,8],[18,8],[18,8],[18,8],[18,8],[17,2],[17,3],[17,3],[17,5],[17,5],[17,3],[17,5],[17,5],[17,5],[17,5],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,3],[17,5],[17,5],[17,5],[17,5],[17,5],[17,5],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,7],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[17,9],[41,0],[41,1],[39,1],[39,1],[39,1],[5,3],[5,5],[46,1],[47,1],[49,1],[48,1],[4,1],[4,1],[4,1]],performAction:function(M,S,R,A,L,v,B){var w=v.length-1;switch(L){case 3:return v[w];case 4:return v[w-1];case 5:return A.setDirection(v[w-3]),v[w-1];case 7:A.setOptions(v[w-1]),this.$=v[w];break;case 8:v[w-1]+=v[w],this.$=v[w-1];break;case 10:this.$=[];break;case 11:v[w-1].push(v[w]),this.$=v[w-1];break;case 12:this.$=v[w-1];break;case 17:this.$=v[w].trim(),A.setAccTitle(this.$);break;case 18:case 19:this.$=v[w].trim(),A.setAccDescription(this.$);break;case 20:A.addSection(v[w].substr(8)),this.$=v[w].substr(8);break;case 22:A.checkout(v[w]);break;case 23:A.branch(v[w]);break;case 24:A.branch(v[w-2],v[w]);break;case 25:A.cherryPick(v[w],"",void 0);break;case 26:A.cherryPick(v[w-2],"",v[w]);break;case 27:case 29:A.cherryPick(v[w-2],"","");break;case 28:A.cherryPick(v[w],"",v[w-2]);break;case 30:A.merge(v[w],"","","");break;case 31:A.merge(v[w-2],v[w],"","");break;case 32:A.merge(v[w-2],"",v[w],"");break;case 33:A.merge(v[w-2],"","",v[w]);break;case 34:A.merge(v[w-4],v[w],"",v[w-2]);break;case 35:A.merge(v[w-4],"",v[w],v[w-2]);break;case 36:A.merge(v[w-4],"",v[w-2],v[w]);break;case 37:A.merge(v[w-4],v[w-2],v[w],"");break;case 38:A.merge(v[w-4],v[w-2],"",v[w]);break;case 39:A.merge(v[w-4],v[w],v[w-2],"");break;case 40:A.merge(v[w-6],v[w-4],v[w-2],v[w]);break;case 41:A.merge(v[w-6],v[w],v[w-4],v[w-2]);break;case 42:A.merge(v[w-6],v[w-4],v[w],v[w-2]);break;case 43:A.merge(v[w-6],v[w-2],v[w-4],v[w]);break;case 44:A.merge(v[w-6],v[w],v[w-2],v[w-4]);break;case 45:A.merge(v[w-6],v[w-2],v[w],v[w-4]);break;case 46:A.commit(v[w]);break;case 47:A.commit("","",A.commitType.NORMAL,v[w]);break;case 48:A.commit("","",v[w],"");break;case 49:A.commit("","",v[w],v[w-2]);break;case 50:A.commit("","",v[w-2],v[w]);break;case 51:A.commit("",v[w],A.commitType.NORMAL,"");break;case 52:A.commit("",v[w-2],A.commitType.NORMAL,v[w]);break;case 53:A.commit("",v[w],A.commitType.NORMAL,v[w-2]);break;case 54:A.commit("",v[w-2],v[w],"");break;case 55:A.commit("",v[w],v[w-2],"");break;case 56:A.commit("",v[w-4],v[w-2],v[w]);break;case 57:A.commit("",v[w-4],v[w],v[w-2]);break;case 58:A.commit("",v[w-2],v[w-4],v[w]);break;case 59:A.commit("",v[w],v[w-4],v[w-2]);break;case 60:A.commit("",v[w],v[w-2],v[w-4]);break;case 61:A.commit("",v[w-2],v[w],v[w-4]);break;case 62:A.commit(v[w],"",A.commitType.NORMAL,"");break;case 63:A.commit(v[w],"",A.commitType.NORMAL,v[w-2]);break;case 64:A.commit(v[w-2],"",A.commitType.NORMAL,v[w]);break;case 65:A.commit(v[w-2],"",v[w],"");break;case 66:A.commit(v[w],"",v[w-2],"");break;case 67:A.commit(v[w],v[w-2],A.commitType.NORMAL,"");break;case 68:A.commit(v[w-2],v[w],A.commitType.NORMAL,"");break;case 69:A.commit(v[w-4],"",v[w-2],v[w]);break;case 70:A.commit(v[w-4],"",v[w],v[w-2]);break;case 71:A.commit(v[w-2],"",v[w-4],v[w]);break;case 72:A.commit(v[w],"",v[w-4],v[w-2]);break;case 73:A.commit(v[w],"",v[w-2],v[w-4]);break;case 74:A.commit(v[w-2],"",v[w],v[w-4]);break;case 75:A.commit(v[w-4],v[w],v[w-2],"");break;case 76:A.commit(v[w-4],v[w-2],v[w],"");break;case 77:A.commit(v[w-2],v[w],v[w-4],"");break;case 78:A.commit(v[w],v[w-2],v[w-4],"");break;case 79:A.commit(v[w],v[w-4],v[w-2],"");break;case 80:A.commit(v[w-2],v[w-4],v[w],"");break;case 81:A.commit(v[w-4],v[w],A.commitType.NORMAL,v[w-2]);break;case 82:A.commit(v[w-4],v[w-2],A.commitType.NORMAL,v[w]);break;case 83:A.commit(v[w-2],v[w],A.commitType.NORMAL,v[w-4]);break;case 84:A.commit(v[w],v[w-2],A.commitType.NORMAL,v[w-4]);break;case 85:A.commit(v[w],v[w-4],A.commitType.NORMAL,v[w-2]);break;case 86:A.commit(v[w-2],v[w-4],A.commitType.NORMAL,v[w]);break;case 87:A.commit(v[w-6],v[w-4],v[w-2],v[w]);break;case 88:A.commit(v[w-6],v[w-4],v[w],v[w-2]);break;case 89:A.commit(v[w-6],v[w-2],v[w-4],v[w]);break;case 90:A.commit(v[w-6],v[w],v[w-4],v[w-2]);break;case 91:A.commit(v[w-6],v[w-2],v[w],v[w-4]);break;case 92:A.commit(v[w-6],v[w],v[w-2],v[w-4]);break;case 93:A.commit(v[w-4],v[w-6],v[w-2],v[w]);break;case 94:A.commit(v[w-4],v[w-6],v[w],v[w-2]);break;case 95:A.commit(v[w-2],v[w-6],v[w-4],v[w]);break;case 96:A.commit(v[w],v[w-6],v[w-4],v[w-2]);break;case 97:A.commit(v[w-2],v[w-6],v[w],v[w-4]);break;case 98:A.commit(v[w],v[w-6],v[w-2],v[w-4]);break;case 99:A.commit(v[w],v[w-4],v[w-2],v[w-6]);break;case 100:A.commit(v[w-2],v[w-4],v[w],v[w-6]);break;case 101:A.commit(v[w],v[w-2],v[w-4],v[w-6]);break;case 102:A.commit(v[w-2],v[w],v[w-4],v[w-6]);break;case 103:A.commit(v[w-4],v[w-2],v[w],v[w-6]);break;case 104:A.commit(v[w-4],v[w],v[w-2],v[w-6]);break;case 105:A.commit(v[w-2],v[w-4],v[w-6],v[w]);break;case 106:A.commit(v[w],v[w-4],v[w-6],v[w-2]);break;case 107:A.commit(v[w-2],v[w],v[w-6],v[w-4]);break;case 108:A.commit(v[w],v[w-2],v[w-6],v[w-4]);break;case 109:A.commit(v[w-4],v[w-2],v[w-6],v[w]);break;case 110:A.commit(v[w-4],v[w],v[w-6],v[w-2]);break;case 111:this.$="";break;case 112:this.$=v[w];break;case 113:this.$=A.commitType.NORMAL;break;case 114:this.$=A.commitType.REVERSE;break;case 115:this.$=A.commitType.HIGHLIGHT;break;case 118:A.parseDirective("%%{","open_directive");break;case 119:A.parseDirective(v[w],"type_directive");break;case 120:v[w]=v[w].trim().replace(/'/g,'"'),A.parseDirective(v[w],"arg_directive");break;case 121:A.parseDirective("}%%","close_directive","gitGraph");break}},table:[{3:1,4:2,5:3,6:e,8:r,14:n,46:8,50:i,54:a},{1:[3]},{3:10,4:2,5:3,6:e,8:r,14:n,46:8,50:i,54:a},{3:11,4:2,5:3,6:e,8:r,14:n,46:8,50:i,54:a},{7:12,8:s,9:[1,13],10:[1,14],11:15,14:o},t(l,[2,122]),t(l,[2,123]),t(l,[2,124]),{47:17,51:[1,18]},{51:[2,118]},{1:[2,1]},{1:[2,2]},{8:[1,19]},{7:20,8:s,11:15,14:o},{9:[1,21]},t(u,[2,10],{12:22,13:[1,23]}),t(h,[2,9]),{9:[1,25],48:24,53:d},t([9,53],[2,119]),{1:[2,3]},{8:[1,27]},{7:28,8:s,11:15,14:o},{8:[2,7],14:[1,31],15:29,16:30,17:32,18:33,19:34,20:[1,35],22:[1,36],24:[1,37],25:[1,38],26:39,27:[1,40],29:[1,44],32:[1,43],37:[1,42],40:[1,41]},t(h,[2,8]),t(f,[2,116]),{49:45,52:[1,46]},t(f,[2,121]),{1:[2,4]},{8:[1,47]},t(u,[2,11]),{4:48,8:r,14:n,54:a},t(u,[2,13]),t(p,[2,14]),t(p,[2,15]),t(p,[2,16]),{21:[1,49]},{23:[1,50]},t(p,[2,19]),t(p,[2,20]),t(p,[2,21]),{28:[1,51]},t(p,[2,111],{41:52,33:[1,55],34:[1,57],35:[1,53],38:[1,54],42:[1,56]}),{28:[1,58]},{33:[1,59],35:[1,60]},{28:[1,61]},{48:62,53:d},{53:[2,120]},{1:[2,5]},t(u,[2,12]),t(p,[2,17]),t(p,[2,18]),t(p,[2,22]),t(p,[2,46]),{34:[1,63]},{39:64,43:m,44:_,45:y},{34:[1,68]},{34:[1,69]},t(p,[2,112]),t(p,[2,30],{33:[1,70],35:[1,72],38:[1,71]}),{34:[1,73]},{34:[1,74],36:[1,75]},t(p,[2,23],{30:[1,76]}),t(f,[2,117]),t(p,[2,47],{33:[1,78],38:[1,77],42:[1,79]}),t(p,[2,48],{33:[1,81],35:[1,80],42:[1,82]}),t(b,[2,113]),t(b,[2,114]),t(b,[2,115]),t(p,[2,51],{35:[1,83],38:[1,84],42:[1,85]}),t(p,[2,62],{33:[1,88],35:[1,86],38:[1,87]}),{34:[1,89]},{39:90,43:m,44:_,45:y},{34:[1,91]},t(p,[2,25],{35:[1,92]}),{33:[1,93]},{33:[1,94]},{31:[1,95]},{39:96,43:m,44:_,45:y},{34:[1,97]},{34:[1,98]},{34:[1,99]},{34:[1,100]},{34:[1,101]},{34:[1,102]},{39:103,43:m,44:_,45:y},{34:[1,104]},{34:[1,105]},{39:106,43:m,44:_,45:y},{34:[1,107]},t(p,[2,31],{35:[1,109],38:[1,108]}),t(p,[2,32],{33:[1,111],35:[1,110]}),t(p,[2,33],{33:[1,112],38:[1,113]}),{34:[1,114],36:[1,115]},{34:[1,116]},{34:[1,117]},t(p,[2,24]),t(p,[2,49],{33:[1,118],42:[1,119]}),t(p,[2,53],{38:[1,120],42:[1,121]}),t(p,[2,63],{33:[1,123],38:[1,122]}),t(p,[2,50],{33:[1,124],42:[1,125]}),t(p,[2,55],{35:[1,126],42:[1,127]}),t(p,[2,66],{33:[1,129],35:[1,128]}),t(p,[2,52],{38:[1,130],42:[1,131]}),t(p,[2,54],{35:[1,132],42:[1,133]}),t(p,[2,67],{35:[1,135],38:[1,134]}),t(p,[2,64],{33:[1,137],38:[1,136]}),t(p,[2,65],{33:[1,139],35:[1,138]}),t(p,[2,68],{35:[1,141],38:[1,140]}),{39:142,43:m,44:_,45:y},{34:[1,143]},{34:[1,144]},{34:[1,145]},{34:[1,146]},{39:147,43:m,44:_,45:y},t(p,[2,26]),t(p,[2,27]),t(p,[2,28]),t(p,[2,29]),{34:[1,148]},{34:[1,149]},{39:150,43:m,44:_,45:y},{34:[1,151]},{39:152,43:m,44:_,45:y},{34:[1,153]},{34:[1,154]},{34:[1,155]},{34:[1,156]},{34:[1,157]},{34:[1,158]},{34:[1,159]},{39:160,43:m,44:_,45:y},{34:[1,161]},{34:[1,162]},{34:[1,163]},{39:164,43:m,44:_,45:y},{34:[1,165]},{39:166,43:m,44:_,45:y},{34:[1,167]},{34:[1,168]},{34:[1,169]},{39:170,43:m,44:_,45:y},{34:[1,171]},t(p,[2,37],{35:[1,172]}),t(p,[2,38],{38:[1,173]}),t(p,[2,36],{33:[1,174]}),t(p,[2,39],{35:[1,175]}),t(p,[2,34],{38:[1,176]}),t(p,[2,35],{33:[1,177]}),t(p,[2,60],{42:[1,178]}),t(p,[2,73],{33:[1,179]}),t(p,[2,61],{42:[1,180]}),t(p,[2,84],{38:[1,181]}),t(p,[2,74],{33:[1,182]}),t(p,[2,83],{38:[1,183]}),t(p,[2,59],{42:[1,184]}),t(p,[2,72],{33:[1,185]}),t(p,[2,58],{42:[1,186]}),t(p,[2,78],{35:[1,187]}),t(p,[2,71],{33:[1,188]}),t(p,[2,77],{35:[1,189]}),t(p,[2,57],{42:[1,190]}),t(p,[2,85],{38:[1,191]}),t(p,[2,56],{42:[1,192]}),t(p,[2,79],{35:[1,193]}),t(p,[2,80],{35:[1,194]}),t(p,[2,86],{38:[1,195]}),t(p,[2,70],{33:[1,196]}),t(p,[2,81],{38:[1,197]}),t(p,[2,69],{33:[1,198]}),t(p,[2,75],{35:[1,199]}),t(p,[2,76],{35:[1,200]}),t(p,[2,82],{38:[1,201]}),{34:[1,202]},{39:203,43:m,44:_,45:y},{34:[1,204]},{34:[1,205]},{39:206,43:m,44:_,45:y},{34:[1,207]},{34:[1,208]},{34:[1,209]},{34:[1,210]},{39:211,43:m,44:_,45:y},{34:[1,212]},{39:213,43:m,44:_,45:y},{34:[1,214]},{34:[1,215]},{34:[1,216]},{34:[1,217]},{34:[1,218]},{34:[1,219]},{34:[1,220]},{39:221,43:m,44:_,45:y},{34:[1,222]},{34:[1,223]},{34:[1,224]},{39:225,43:m,44:_,45:y},{34:[1,226]},{39:227,43:m,44:_,45:y},{34:[1,228]},{34:[1,229]},{34:[1,230]},{39:231,43:m,44:_,45:y},t(p,[2,40]),t(p,[2,42]),t(p,[2,41]),t(p,[2,43]),t(p,[2,45]),t(p,[2,44]),t(p,[2,101]),t(p,[2,102]),t(p,[2,99]),t(p,[2,100]),t(p,[2,104]),t(p,[2,103]),t(p,[2,108]),t(p,[2,107]),t(p,[2,106]),t(p,[2,105]),t(p,[2,110]),t(p,[2,109]),t(p,[2,98]),t(p,[2,97]),t(p,[2,96]),t(p,[2,95]),t(p,[2,93]),t(p,[2,94]),t(p,[2,92]),t(p,[2,91]),t(p,[2,90]),t(p,[2,89]),t(p,[2,87]),t(p,[2,88])],defaultActions:{9:[2,118],10:[2,1],11:[2,2],19:[2,3],27:[2,4],46:[2,120],47:[2,5]},parseError:function(M,S){if(S.recoverable)this.trace(M);else{var R=new Error(M);throw R.hash=S,R}},parse:function(M){var S=this,R=[0],A=[],L=[null],v=[],B=this.table,w="",D=0,N=0,z=2,X=1,ct=v.slice.call(arguments,1),J=Object.create(this.lexer),Y={yy:{}};for(var $ in this.yy)Object.prototype.hasOwnProperty.call(this.yy,$)&&(Y.yy[$]=this.yy[$]);J.setInput(M,Y.yy),Y.yy.lexer=J,Y.yy.parser=this,typeof J.yylloc>"u"&&(J.yylloc={});var lt=J.yylloc;v.push(lt);var ut=J.options&&J.options.ranges;typeof Y.yy.parseError=="function"?this.parseError=Y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function W(){var P;return P=A.pop()||J.lex()||X,typeof P!="number"&&(P instanceof Array&&(A=P,P=A.pop()),P=S.symbols_[P]||P),P}for(var tt,K,it,Z,V={},Q,q,U,F;;){if(K=R[R.length-1],this.defaultActions[K]?it=this.defaultActions[K]:((tt===null||typeof tt>"u")&&(tt=W()),it=B[K]&&B[K][tt]),typeof it>"u"||!it.length||!it[0]){var j="";F=[];for(Q in B[K])this.terminals_[Q]&&Q>z&&F.push("'"+this.terminals_[Q]+"'");J.showPosition?j="Parse error on line "+(D+1)+`: +`+J.showPosition()+` +Expecting `+F.join(", ")+", got '"+(this.terminals_[tt]||tt)+"'":j="Parse error on line "+(D+1)+": Unexpected "+(tt==X?"end of input":"'"+(this.terminals_[tt]||tt)+"'"),this.parseError(j,{text:J.match,token:this.terminals_[tt]||tt,line:J.yylineno,loc:lt,expected:F})}if(it[0]instanceof Array&&it.length>1)throw new Error("Parse Error: multiple actions possible at state: "+K+", token: "+tt);switch(it[0]){case 1:R.push(tt),L.push(J.yytext),v.push(J.yylloc),R.push(it[1]),tt=null,N=J.yyleng,w=J.yytext,D=J.yylineno,lt=J.yylloc;break;case 2:if(q=this.productions_[it[1]][1],V.$=L[L.length-q],V._$={first_line:v[v.length-(q||1)].first_line,last_line:v[v.length-1].last_line,first_column:v[v.length-(q||1)].first_column,last_column:v[v.length-1].last_column},ut&&(V._$.range=[v[v.length-(q||1)].range[0],v[v.length-1].range[1]]),Z=this.performAction.apply(V,[w,N,D,Y.yy,it[1],L,v].concat(ct)),typeof Z<"u")return Z;q&&(R=R.slice(0,-1*q*2),L=L.slice(0,-1*q),v=v.slice(0,-1*q)),R.push(this.productions_[it[1]][0]),L.push(V.$),v.push(V._$),U=B[R[R.length-2]][R[R.length-1]],R.push(U);break;case 3:return!0}}return!0}},k=function(){var C={EOF:1,parseError:function(S,R){if(this.yy.parser)this.yy.parser.parseError(S,R);else throw new Error(S)},setInput:function(M,S){return this.yy=S||this.yy||{},this._input=M,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var M=this._input[0];this.yytext+=M,this.yyleng++,this.offset++,this.match+=M,this.matched+=M;var S=M.match(/(?:\r\n?|\n).*/g);return S?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),M},unput:function(M){var S=M.length,R=M.split(/(?:\r\n?|\n)/g);this._input=M+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-S),this.offset-=S;var A=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),R.length-1&&(this.yylineno-=R.length-1);var L=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:R?(R.length===A.length?this.yylloc.first_column:0)+A[A.length-R.length].length-R[0].length:this.yylloc.first_column-S},this.options.ranges&&(this.yylloc.range=[L[0],L[0]+this.yyleng-S]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(M){this.unput(this.match.slice(M))},pastInput:function(){var M=this.matched.substr(0,this.matched.length-this.match.length);return(M.length>20?"...":"")+M.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var M=this.match;return M.length<20&&(M+=this._input.substr(0,20-M.length)),(M.substr(0,20)+(M.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var M=this.pastInput(),S=new Array(M.length+1).join("-");return M+this.upcomingInput()+` +`+S+"^"},test_match:function(M,S){var R,A,L;if(this.options.backtrack_lexer&&(L={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(L.yylloc.range=this.yylloc.range.slice(0))),A=M[0].match(/(?:\r\n?|\n).*/g),A&&(this.yylineno+=A.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:A?A[A.length-1].length-A[A.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+M[0].length},this.yytext+=M[0],this.match+=M[0],this.matches=M,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(M[0].length),this.matched+=M[0],R=this.performAction.call(this,this.yy,this,S,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),R)return R;if(this._backtrack){for(var v in L)this[v]=L[v];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var M,S,R,A;this._more||(this.yytext="",this.match="");for(var L=this._currentRules(),v=0;v<L.length;v++)if(R=this._input.match(this.rules[L[v]]),R&&(!S||R[0].length>S[0].length)){if(S=R,A=v,this.options.backtrack_lexer){if(M=this.test_match(R,L[v]),M!==!1)return M;if(this._backtrack){S=!1;continue}else return!1}else if(!this.options.flex)break}return S?(M=this.test_match(S,L[A]),M!==!1?M:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var S=this.next();return S||this.lex()},begin:function(S){this.conditionStack.push(S)},popState:function(){var S=this.conditionStack.length-1;return S>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(S){return S=this.conditionStack.length-1-Math.abs(S||0),S>=0?this.conditionStack[S]:"INITIAL"},pushState:function(S){this.begin(S)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(S,R,A,L){switch(A){case 0:return this.begin("open_directive"),50;case 1:return this.begin("type_directive"),51;case 2:return this.popState(),this.begin("arg_directive"),9;case 3:return this.popState(),this.popState(),53;case 4:return 52;case 5:return this.begin("acc_title"),20;case 6:return this.popState(),"acc_title_value";case 7:return this.begin("acc_descr"),22;case 8:return this.popState(),"acc_descr_value";case 9:this.begin("acc_descr_multiline");break;case 10:this.popState();break;case 11:return"acc_descr_multiline_value";case 12:return 14;case 13:break;case 14:break;case 15:return 6;case 16:return 40;case 17:return 33;case 18:return 38;case 19:return 42;case 20:return 43;case 21:return 44;case 22:return 45;case 23:return 35;case 24:return 29;case 25:return 30;case 26:return 37;case 27:return 32;case 28:return 27;case 29:return 10;case 30:return 10;case 31:return 9;case 32:return"CARET";case 33:this.begin("options");break;case 34:this.popState();break;case 35:return 13;case 36:return 36;case 37:this.begin("string");break;case 38:this.popState();break;case 39:return 34;case 40:return 31;case 41:return 28;case 42:return 8}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:accTitle\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*\{\s*)/i,/^(?:[\}])/i,/^(?:[^\}]*)/i,/^(?:(\r?\n)+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:gitGraph\b)/i,/^(?:commit(?=\s|$))/i,/^(?:id:)/i,/^(?:type:)/i,/^(?:msg:)/i,/^(?:NORMAL\b)/i,/^(?:REVERSE\b)/i,/^(?:HIGHLIGHT\b)/i,/^(?:tag:)/i,/^(?:branch(?=\s|$))/i,/^(?:order:)/i,/^(?:merge(?=\s|$))/i,/^(?:cherry-pick(?=\s|$))/i,/^(?:checkout(?=\s|$))/i,/^(?:LR\b)/i,/^(?:BT\b)/i,/^(?::)/i,/^(?:\^)/i,/^(?:options\r?\n)/i,/^(?:[ \r\n\t]+end\b)/i,/^(?:[\s\S]+(?=[ \r\n\t]+end))/i,/^(?:["]["])/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[0-9]+(?=\s|$))/i,/^(?:\w([-\./\w]*[-\w])?)/i,/^(?:$)/i,/^(?:\s+)/i],conditions:{acc_descr_multiline:{rules:[10,11],inclusive:!1},acc_descr:{rules:[8],inclusive:!1},acc_title:{rules:[6],inclusive:!1},close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},options:{rules:[34,35],inclusive:!1},string:{rules:[38,39],inclusive:!1},INITIAL:{rules:[0,5,7,9,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,36,37,40,41,42,43],inclusive:!0}}};return C}();x.lexer=k;function T(){this.yy={}}return T.prototype=x,x.Parser=T,new T}();hg.parser=hg;const BX=t=>t.match(/^\s*gitGraph/)!==null;let fg="",l1="",dg="";const pg=t=>ai(t,nt()),ci=function(){fg="",dg="",l1=""},Yn=function(t){fg=pg(t).replace(/^\s+/g,"")},ui=function(){return fg||l1},hi=function(t){dg=pg(t).replace(/\n\s+/g,` +`)},fi=function(){return dg},c1=function(t){l1=pg(t)},u1=function(){return l1};let h1=nt().gitGraph.mainBranchName,DX=nt().gitGraph.mainBranchOrder,kr={},cn=null,Dc={};Dc[h1]={name:h1,order:DX};let pr={};pr[h1]=cn;let Rr=h1,Vw="LR",Ys=0;function gg(){return lw({length:7})}const OX=function(t,e,r){Xe.parseDirective(this,t,e,r)};function FX(t,e){const r=Object.create(null);return t.reduce((n,i)=>{const a=e(i);return r[a]||(r[a]=!0,n.push(i)),n},[])}const PX=function(t){Vw=t};let zw={};const qX=function(t){H.debug("options str",t),t=t&&t.trim(),t=t||"{}";try{zw=JSON.parse(t)}catch(e){H.error("error while parsing gitGraph options",e.message)}},VX=function(){return zw},zX=function(t,e,r,n){H.debug("Entering commit:",t,e,r,n),e=pe.sanitizeText(e,nt()),t=pe.sanitizeText(t,nt()),n=pe.sanitizeText(n,nt());const i={id:e||Ys+"-"+gg(),message:t,seq:Ys++,type:r||Oc.NORMAL,tag:n||"",parents:cn==null?[]:[cn.id],branch:Rr};cn=i,kr[i.id]=i,pr[Rr]=i.id,H.debug("in pushCommit "+i.id)},YX=function(t,e){if(t=pe.sanitizeText(t,nt()),typeof pr[t]>"u")pr[t]=cn!=null?cn.id:null,Dc[t]={name:t,order:e?parseInt(e,10):null},Yw(t),H.debug("in createBranch");else{let r=new Error('Trying to create an existing branch. (Help: Either use a new name if you want create a new branch or try using "checkout '+t+'")');throw r.hash={text:"branch "+t,token:"branch "+t,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:['"checkout '+t+'"']},r}},UX=function(t,e,r,n){t=pe.sanitizeText(t,nt()),e=pe.sanitizeText(e,nt());const i=kr[pr[Rr]],a=kr[pr[t]];if(Rr===t){let o=new Error('Incorrect usage of "merge". Cannot merge a branch to itself');throw o.hash={text:"merge "+t,token:"merge "+t,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:["branch abc"]},o}else if(typeof i>"u"||!i){let o=new Error('Incorrect usage of "merge". Current branch ('+Rr+")has no commits");throw o.hash={text:"merge "+t,token:"merge "+t,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:["commit"]},o}else if(typeof pr[t]>"u"){let o=new Error('Incorrect usage of "merge". Branch to be merged ('+t+") does not exist");throw o.hash={text:"merge "+t,token:"merge "+t,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:["branch "+t]},o}else if(typeof a>"u"||!a){let o=new Error('Incorrect usage of "merge". Branch to be merged ('+t+") has no commits");throw o.hash={text:"merge "+t,token:"merge "+t,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:['"commit"']},o}else if(i===a){let o=new Error('Incorrect usage of "merge". Both branches have same head');throw o.hash={text:"merge "+t,token:"merge "+t,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:["branch abc"]},o}else if(e&&typeof kr[e]<"u"){let o=new Error('Incorrect usage of "merge". Commit with id:'+e+" already exists, use different custom Id");throw o.hash={text:"merge "+t+e+r+n,token:"merge "+t+e+r+n,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:["merge "+t+" "+e+"_UNIQUE "+r+" "+n]},o}const s={id:e||Ys+"-"+gg(),message:"merged branch "+t+" into "+Rr,seq:Ys++,parents:[cn==null?null:cn.id,pr[t]],branch:Rr,type:Oc.MERGE,customType:r,customId:!!e,tag:n||""};cn=s,kr[s.id]=s,pr[Rr]=s.id,H.debug(pr),H.debug("in mergeBranch")},WX=function(t,e,r){if(H.debug("Entering cherryPick:",t,e,r),t=pe.sanitizeText(t,nt()),e=pe.sanitizeText(e,nt()),r=pe.sanitizeText(r,nt()),!t||typeof kr[t]>"u"){let a=new Error('Incorrect usage of "cherryPick". Source commit id should exist and provided');throw a.hash={text:"cherryPick "+t+" "+e,token:"cherryPick "+t+" "+e,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:["cherry-pick abc"]},a}let n=kr[t],i=n.branch;if(n.type===Oc.MERGE){let a=new Error('Incorrect usage of "cherryPick". Source commit should not be a merge commit');throw a.hash={text:"cherryPick "+t+" "+e,token:"cherryPick "+t+" "+e,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:["cherry-pick abc"]},a}if(!e||typeof kr[e]>"u"){if(i===Rr){let o=new Error('Incorrect usage of "cherryPick". Source commit is already on current branch');throw o.hash={text:"cherryPick "+t+" "+e,token:"cherryPick "+t+" "+e,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:["cherry-pick abc"]},o}const a=kr[pr[Rr]];if(typeof a>"u"||!a){let o=new Error('Incorrect usage of "cherry-pick". Current branch ('+Rr+")has no commits");throw o.hash={text:"cherryPick "+t+" "+e,token:"cherryPick "+t+" "+e,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:["cherry-pick abc"]},o}const s={id:Ys+"-"+gg(),message:"cherry-picked "+n+" into "+Rr,seq:Ys++,parents:[cn==null?null:cn.id,n.id],branch:Rr,type:Oc.CHERRY_PICK,tag:r!=null?r:"cherry-pick:"+n.id};cn=s,kr[s.id]=s,pr[Rr]=s.id,H.debug(pr),H.debug("in cherryPick")}},Yw=function(t){if(t=pe.sanitizeText(t,nt()),typeof pr[t]>"u"){let e=new Error('Trying to checkout branch which is not yet created. (Help try using "branch '+t+'")');throw e.hash={text:"checkout "+t,token:"checkout "+t,line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:['"branch '+t+'"']},e}else{Rr=t;const e=pr[Rr];cn=kr[e]}};function Uw(t,e,r){const n=t.indexOf(e);n===-1?t.push(r):t.splice(n,1,r)}function Ww(t){const e=t.reduce((i,a)=>i.seq>a.seq?i:a,t[0]);let r="";t.forEach(function(i){i===e?r+=" *":r+=" |"});const n=[r,e.id,e.seq];for(let i in pr)pr[i]===e.id&&n.push(i);if(H.debug(n.join(" ")),e.parents&&e.parents.length==2){const i=kr[e.parents[0]];Uw(t,e,i),t.push(kr[e.parents[1]])}else{if(e.parents.length==0)return;{const i=kr[e.parents];Uw(t,e,i)}}t=FX(t,i=>i.id),Ww(t)}const HX=function(){H.debug(kr);const t=Hw()[0];Ww([t])},GX=function(){kr={},cn=null;let t=nt().gitGraph.mainBranchName,e=nt().gitGraph.mainBranchOrder;pr={},pr[t]=null,Dc={},Dc[t]={name:t,order:e},Rr=t,Ys=0,ci()},jX=function(){return Object.values(Dc).map((e,r)=>e.order!==null?e:{...e,order:parseFloat(`0.${r}`,10)}).sort((e,r)=>e.order-r.order).map(({name:e})=>({name:e}))},$X=function(){return pr},XX=function(){return kr},Hw=function(){const t=Object.keys(kr).map(function(e){return kr[e]});return t.forEach(function(e){H.debug(e.id)}),t.sort((e,r)=>e.seq-r.seq),t},KX=function(){return Rr},ZX=function(){return Vw},QX=function(){return cn},Oc={NORMAL:0,REVERSE:1,HIGHLIGHT:2,MERGE:3,CHERRY_PICK:4},JX={parseDirective:OX,getConfig:()=>nt().gitGraph,setDirection:PX,setOptions:qX,getOptions:VX,commit:zX,branch:YX,merge:UX,cherryPick:WX,checkout:Yw,prettyPrint:HX,clear:GX,getBranchesAsObjArray:jX,getBranches:$X,getCommits:XX,getCommitsArray:Hw,getCurrentBranch:KX,getDirection:ZX,getHead:QX,setAccTitle:Yn,getAccTitle:ui,getAccDescription:fi,setAccDescription:hi,commitType:Oc};function bn(t,e,r){if(typeof e.insert>"u")return;let n=t.getAccTitle(),i=t.getAccDescription();e.attr("role","img").attr("aria-labelledby","chart-title-"+r+" chart-desc-"+r),e.insert("desc",":first-child").attr("id","chart-desc-"+r).text(i),e.insert("title",":first-child").attr("id","chart-title-"+r).text(n)}let Fc={};const Sn={NORMAL:0,REVERSE:1,HIGHLIGHT:2,MERGE:3,CHERRY_PICK:4},Us=8;let _n={},f1={},Pc=[],d1=0;const tK=()=>{_n={},f1={},Fc={},d1=0,Pc=[]},eK=t=>{const e=document.createElementNS("http://www.w3.org/2000/svg","text");let r=[];typeof t=="string"?r=t.split(/\\n|\n|<br\s*\/?>/gi):Array.isArray(t)?r=t:r=[];for(let n=0;n<r.length;n++){const i=document.createElementNS("http://www.w3.org/2000/svg","tspan");i.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:space","preserve"),i.setAttribute("dy","1em"),i.setAttribute("x","0"),i.setAttribute("class","row"),i.textContent=r[n].trim(),e.appendChild(i)}return e},Gw=(t,e,r)=>{const n=Zo().gitGraph,i=t.append("g").attr("class","commit-bullets"),a=t.append("g").attr("class","commit-labels");let s=0;Object.keys(e).sort((u,h)=>e[u].seq-e[h].seq).forEach(u=>{const h=e[u],d=_n[h.branch].pos,f=s+10;if(r){let p,m=typeof h.customType<"u"&&h.customType!==""?h.customType:h.type;switch(m){case Sn.NORMAL:p="commit-normal";break;case Sn.REVERSE:p="commit-reverse";break;case Sn.HIGHLIGHT:p="commit-highlight";break;case Sn.MERGE:p="commit-merge";break;case Sn.CHERRY_PICK:p="commit-cherry-pick";break;default:p="commit-normal"}if(m===Sn.HIGHLIGHT){const _=i.append("rect");_.attr("x",f-10),_.attr("y",d-10),_.attr("height",20),_.attr("width",20),_.attr("class",`commit ${h.id} commit-highlight${_n[h.branch].index%Us} ${p}-outer`),i.append("rect").attr("x",f-6).attr("y",d-6).attr("height",12).attr("width",12).attr("class",`commit ${h.id} commit${_n[h.branch].index%Us} ${p}-inner`)}else if(m===Sn.CHERRY_PICK)i.append("circle").attr("cx",f).attr("cy",d).attr("r",10).attr("class",`commit ${h.id} ${p}`),i.append("circle").attr("cx",f-3).attr("cy",d+2).attr("r",2.75).attr("fill","#fff").attr("class",`commit ${h.id} ${p}`),i.append("circle").attr("cx",f+3).attr("cy",d+2).attr("r",2.75).attr("fill","#fff").attr("class",`commit ${h.id} ${p}`),i.append("line").attr("x1",f+3).attr("y1",d+1).attr("x2",f).attr("y2",d-5).attr("stroke","#fff").attr("class",`commit ${h.id} ${p}`),i.append("line").attr("x1",f-3).attr("y1",d+1).attr("x2",f).attr("y2",d-5).attr("stroke","#fff").attr("class",`commit ${h.id} ${p}`);else{const _=i.append("circle");if(_.attr("cx",f),_.attr("cy",d),_.attr("r",h.type===Sn.MERGE?9:10),_.attr("class",`commit ${h.id} commit${_n[h.branch].index%Us}`),m===Sn.MERGE){const y=i.append("circle");y.attr("cx",f),y.attr("cy",d),y.attr("r",6),y.attr("class",`commit ${p} ${h.id} commit${_n[h.branch].index%Us}`)}m===Sn.REVERSE&&i.append("path").attr("d",`M ${f-5},${d-5}L${f+5},${d+5}M${f-5},${d+5}L${f+5},${d-5}`).attr("class",`commit ${p} ${h.id} commit${_n[h.branch].index%Us}`)}}if(f1[h.id]={x:s+10,y:d},r){if(h.type!==Sn.CHERRY_PICK&&(h.customId&&h.type===Sn.MERGE||h.type!==Sn.MERGE)&&n.showCommitLabel){const _=a.append("g"),y=_.insert("rect").attr("class","commit-label-bkg"),b=_.append("text").attr("x",s).attr("y",d+25).attr("class","commit-label").text(h.id);let x=b.node().getBBox();if(y.attr("x",s+10-x.width/2-2).attr("y",d+13.5).attr("width",x.width+2*2).attr("height",x.height+2*2),b.attr("x",s+10-x.width/2),n.rotateCommitLabel){let k=-7.5-(x.width+10)/25*9.5,T=10+x.width/25*8.5;_.attr("transform","translate("+k+", "+T+") rotate("+-45+", "+s+", "+d+")")}}if(h.tag){const _=a.insert("polygon"),y=a.append("circle"),b=a.append("text").attr("y",d-16).attr("class","tag-label").text(h.tag);let x=b.node().getBBox();b.attr("x",s+10-x.width/2);const k=x.height/2,T=d-19.2;_.attr("class","tag-label-bkg").attr("points",` + ${s-x.width/2-4/2},${T+2} + ${s-x.width/2-4/2},${T-2} + ${s+10-x.width/2-4},${T-k-2} + ${s+10+x.width/2+4},${T-k-2} + ${s+10+x.width/2+4},${T+k+2} + ${s+10-x.width/2-4},${T+k+2}`),y.attr("cx",s-x.width/2+4/2).attr("cy",T).attr("r",1.5).attr("class","tag-hole")}}s+=50,s>d1&&(d1=s)})},rK=(t,e,r)=>Object.keys(r).filter(a=>r[a].branch===e.branch&&r[a].seq>t.seq&&r[a].seq<e.seq).length>0,yg=(t,e,r)=>{const n=r||0,i=t+Math.abs(t-e)/2;if(n>5)return i;let a=!0;for(let o=0;o<Pc.length;o++)Math.abs(Pc[o]-i)<10&&(a=!1);if(a)return Pc.push(i),i;const s=Math.abs(t-e);return yg(t,e-s/5,n+1)},nK=(t,e,r,n)=>{const i=f1[e.id],a=f1[r.id],s=rK(e,r,n);let o="",l="",u=0,h=0,d=_n[r.branch].index,f;if(s){o="A 10 10, 0, 0, 0,",l="A 10 10, 0, 0, 1,",u=10,h=10,d=_n[r.branch].index;const p=i.y<a.y?yg(i.y,a.y):yg(a.y,i.y);i.y<a.y?f=`M ${i.x} ${i.y} L ${i.x} ${p-u} ${o} ${i.x+h} ${p} L ${a.x-u} ${p} ${l} ${a.x} ${p+h} L ${a.x} ${a.y}`:f=`M ${i.x} ${i.y} L ${i.x} ${p+u} ${l} ${i.x+h} ${p} L ${a.x-u} ${p} ${o} ${a.x} ${p-h} L ${a.x} ${a.y}`}else i.y<a.y&&(o="A 20 20, 0, 0, 0,",u=20,h=20,d=_n[r.branch].index,f=`M ${i.x} ${i.y} L ${i.x} ${a.y-u} ${o} ${i.x+h} ${a.y} L ${a.x} ${a.y}`),i.y>a.y&&(o="A 20 20, 0, 0, 0,",u=20,h=20,d=_n[e.branch].index,f=`M ${i.x} ${i.y} L ${a.x-u} ${i.y} ${o} ${a.x} ${i.y-h} L ${a.x} ${a.y}`),i.y===a.y&&(d=_n[e.branch].index,f=`M ${i.x} ${i.y} L ${i.x} ${a.y-u} ${o} ${i.x+h} ${a.y} L ${a.x} ${a.y}`);t.append("path").attr("d",f).attr("class","arrow arrow"+d%Us)},iK=(t,e)=>{const r=t.append("g").attr("class","commit-arrows");Object.keys(e).forEach(n=>{const i=e[n];i.parents&&i.parents.length>0&&i.parents.forEach(a=>{nK(r,e[a],i,e)})})},aK=(t,e)=>{const r=Zo().gitGraph,n=t.append("g");e.forEach((i,a)=>{const s=a%Us,o=_n[i.name].pos,l=n.append("line");l.attr("x1",0),l.attr("y1",o),l.attr("x2",d1),l.attr("y2",o),l.attr("class","branch branch"+s),Pc.push(o);let u=i.name;const h=eK(u),d=n.insert("rect"),p=n.insert("g").attr("class","branchLabel").insert("g").attr("class","label branch-label"+s);p.node().appendChild(h);let m=h.getBBox();d.attr("class","branchLabelBkg label"+s).attr("rx",4).attr("ry",4).attr("x",-m.width-4-(r.rotateCommitLabel===!0?30:0)).attr("y",-m.height/2+8).attr("width",m.width+18).attr("height",m.height+4),p.attr("transform","translate("+(-m.width-14-(r.rotateCommitLabel===!0?30:0))+", "+(o-m.height/2-1)+")"),d.attr("transform","translate("+-19+", "+(o-m.height/2)+")")})},sK={draw:function(t,e,r,n){tK();const i=Zo(),a=Zo().gitGraph;H.debug("in gitgraph renderer",t+` +`,"id:",e,r),Fc=n.db.getCommits();const s=n.db.getBranchesAsObjArray();let o=0;s.forEach((u,h)=>{_n[u.name]={pos:o,index:h},o+=50+(a.rotateCommitLabel?40:0)});const l=St(`[id="${e}"]`);bn(n.db,l,e),Gw(l,Fc,!1),a.showBranches&&aK(l,s),iK(l,Fc),Gw(l,Fc,!0),Fw(void 0,l,a.diagramPadding,i.useMaxWidth)}},oK=t=>` + .commit-id, + .commit-msg, + .branch-label { + fill: lightgrey; + color: lightgrey; + font-family: 'trebuchet ms', verdana, arial, sans-serif; + font-family: var(--mermaid-font-family); + } + ${[0,1,2,3,4,5,6,7].map(e=>` + .branch-label${e} { fill: ${t["gitBranchLabel"+e]}; } + .commit${e} { stroke: ${t["git"+e]}; fill: ${t["git"+e]}; } + .commit-highlight${e} { stroke: ${t["gitInv"+e]}; fill: ${t["gitInv"+e]}; } + .label${e} { fill: ${t["git"+e]}; } + .arrow${e} { stroke: ${t["git"+e]}; } + `).join(` +`)} + + .branch { + stroke-width: 1; + stroke: ${t.lineColor}; + stroke-dasharray: 2; + } + .commit-label { font-size: ${t.commitLabelFontSize}; fill: ${t.commitLabelColor};} + .commit-label-bkg { font-size: ${t.commitLabelFontSize}; fill: ${t.commitLabelBackground}; opacity: 0.5; } + .tag-label { font-size: ${t.tagLabelFontSize}; fill: ${t.tagLabelColor};} + .tag-label-bkg { fill: ${t.tagLabelBackground}; stroke: ${t.tagLabelBorder}; } + .tag-hole { fill: ${t.textColor}; } + + .commit-merge { + stroke: ${t.primaryColor}; + fill: ${t.primaryColor}; + } + .commit-reverse { + stroke: ${t.primaryColor}; + fill: ${t.primaryColor}; + stroke-width: 3; + } + .commit-highlight-outer { + } + .commit-highlight-inner { + stroke: ${t.primaryColor}; + fill: ${t.primaryColor}; + } + + .arrow { stroke-width: 8; stroke-linecap: round; fill: none} + } +`;var qc=function(){var t=function(zt,wt,bt,Et){for(bt=bt||{},Et=zt.length;Et--;bt[zt[Et]]=wt);return bt},e=[1,6],r=[1,7],n=[1,8],i=[1,9],a=[1,16],s=[1,11],o=[1,12],l=[1,13],u=[1,14],h=[1,15],d=[1,27],f=[1,33],p=[1,34],m=[1,35],_=[1,36],y=[1,37],b=[1,72],x=[1,73],k=[1,74],T=[1,75],C=[1,76],M=[1,77],S=[1,78],R=[1,38],A=[1,39],L=[1,40],v=[1,41],B=[1,42],w=[1,43],D=[1,44],N=[1,45],z=[1,46],X=[1,47],ct=[1,48],J=[1,49],Y=[1,50],$=[1,51],lt=[1,52],ut=[1,53],W=[1,54],tt=[1,55],K=[1,56],it=[1,57],Z=[1,59],V=[1,60],Q=[1,61],q=[1,62],U=[1,63],F=[1,64],j=[1,65],P=[1,66],et=[1,67],at=[1,68],It=[1,69],Lt=[24,52],Rt=[24,44,46,47,48,49,50,51,52,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84],Ct=[15,24,44,46,47,48,49,50,51,52,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84],pt=[1,94],mt=[1,95],vt=[1,96],Tt=[1,97],ft=[15,24,52],le=[7,8,9,10,18,22,25,26,27,28],Dt=[15,24,43,52],Gt=[15,24,43,52,86,87,89,90],$t=[15,43],Qt=[44,46,47,48,49,50,51,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84],we={trace:function(){},yy:{},symbols_:{error:2,start:3,mermaidDoc:4,direction:5,directive:6,direction_tb:7,direction_bt:8,direction_rl:9,direction_lr:10,graphConfig:11,openDirective:12,typeDirective:13,closeDirective:14,NEWLINE:15,":":16,argDirective:17,open_directive:18,type_directive:19,arg_directive:20,close_directive:21,C4_CONTEXT:22,statements:23,EOF:24,C4_CONTAINER:25,C4_COMPONENT:26,C4_DYNAMIC:27,C4_DEPLOYMENT:28,otherStatements:29,diagramStatements:30,otherStatement:31,title:32,accDescription:33,acc_title:34,acc_title_value:35,acc_descr:36,acc_descr_value:37,acc_descr_multiline_value:38,boundaryStatement:39,boundaryStartStatement:40,boundaryStopStatement:41,boundaryStart:42,LBRACE:43,ENTERPRISE_BOUNDARY:44,attributes:45,SYSTEM_BOUNDARY:46,BOUNDARY:47,CONTAINER_BOUNDARY:48,NODE:49,NODE_L:50,NODE_R:51,RBRACE:52,diagramStatement:53,PERSON:54,PERSON_EXT:55,SYSTEM:56,SYSTEM_DB:57,SYSTEM_QUEUE:58,SYSTEM_EXT:59,SYSTEM_EXT_DB:60,SYSTEM_EXT_QUEUE:61,CONTAINER:62,CONTAINER_DB:63,CONTAINER_QUEUE:64,CONTAINER_EXT:65,CONTAINER_EXT_DB:66,CONTAINER_EXT_QUEUE:67,COMPONENT:68,COMPONENT_DB:69,COMPONENT_QUEUE:70,COMPONENT_EXT:71,COMPONENT_EXT_DB:72,COMPONENT_EXT_QUEUE:73,REL:74,BIREL:75,REL_U:76,REL_D:77,REL_L:78,REL_R:79,REL_B:80,REL_INDEX:81,UPDATE_EL_STYLE:82,UPDATE_REL_STYLE:83,UPDATE_LAYOUT_CONFIG:84,attribute:85,STR:86,STR_KEY:87,STR_VALUE:88,ATTRIBUTE:89,ATTRIBUTE_EMPTY:90,$accept:0,$end:1},terminals_:{2:"error",7:"direction_tb",8:"direction_bt",9:"direction_rl",10:"direction_lr",15:"NEWLINE",16:":",18:"open_directive",19:"type_directive",20:"arg_directive",21:"close_directive",22:"C4_CONTEXT",24:"EOF",25:"C4_CONTAINER",26:"C4_COMPONENT",27:"C4_DYNAMIC",28:"C4_DEPLOYMENT",32:"title",33:"accDescription",34:"acc_title",35:"acc_title_value",36:"acc_descr",37:"acc_descr_value",38:"acc_descr_multiline_value",43:"LBRACE",44:"ENTERPRISE_BOUNDARY",46:"SYSTEM_BOUNDARY",47:"BOUNDARY",48:"CONTAINER_BOUNDARY",49:"NODE",50:"NODE_L",51:"NODE_R",52:"RBRACE",54:"PERSON",55:"PERSON_EXT",56:"SYSTEM",57:"SYSTEM_DB",58:"SYSTEM_QUEUE",59:"SYSTEM_EXT",60:"SYSTEM_EXT_DB",61:"SYSTEM_EXT_QUEUE",62:"CONTAINER",63:"CONTAINER_DB",64:"CONTAINER_QUEUE",65:"CONTAINER_EXT",66:"CONTAINER_EXT_DB",67:"CONTAINER_EXT_QUEUE",68:"COMPONENT",69:"COMPONENT_DB",70:"COMPONENT_QUEUE",71:"COMPONENT_EXT",72:"COMPONENT_EXT_DB",73:"COMPONENT_EXT_QUEUE",74:"REL",75:"BIREL",76:"REL_U",77:"REL_D",78:"REL_L",79:"REL_R",80:"REL_B",81:"REL_INDEX",82:"UPDATE_EL_STYLE",83:"UPDATE_REL_STYLE",84:"UPDATE_LAYOUT_CONFIG",86:"STR",87:"STR_KEY",88:"STR_VALUE",89:"ATTRIBUTE",90:"ATTRIBUTE_EMPTY"},productions_:[0,[3,1],[3,1],[3,2],[5,1],[5,1],[5,1],[5,1],[4,1],[6,4],[6,6],[12,1],[13,1],[17,1],[14,1],[11,4],[11,4],[11,4],[11,4],[11,4],[23,1],[23,1],[23,2],[29,1],[29,2],[29,3],[31,1],[31,1],[31,2],[31,2],[31,1],[39,3],[40,3],[40,3],[40,4],[42,2],[42,2],[42,2],[42,2],[42,2],[42,2],[42,2],[41,1],[30,1],[30,2],[30,3],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,1],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[53,2],[45,1],[45,2],[85,1],[85,2],[85,1],[85,1]],performAction:function(wt,bt,Et,kt,Ut,gt,he){var yt=gt.length-1;switch(Ut){case 4:kt.setDirection("TB");break;case 5:kt.setDirection("BT");break;case 6:kt.setDirection("RL");break;case 7:kt.setDirection("LR");break;case 11:kt.parseDirective("%%{","open_directive");break;case 12:break;case 13:gt[yt]=gt[yt].trim().replace(/'/g,'"'),kt.parseDirective(gt[yt],"arg_directive");break;case 14:kt.parseDirective("}%%","close_directive","c4Context");break;case 15:case 16:case 17:case 18:case 19:kt.setC4Type(gt[yt-3]);break;case 26:kt.setTitle(gt[yt].substring(6)),this.$=gt[yt].substring(6);break;case 27:kt.setAccDescription(gt[yt].substring(15)),this.$=gt[yt].substring(15);break;case 28:this.$=gt[yt].trim(),kt.setTitle(this.$);break;case 29:case 30:this.$=gt[yt].trim(),kt.setAccDescription(this.$);break;case 35:case 36:gt[yt].splice(2,0,"ENTERPRISE"),kt.addPersonOrSystemBoundary(...gt[yt]),this.$=gt[yt];break;case 37:kt.addPersonOrSystemBoundary(...gt[yt]),this.$=gt[yt];break;case 38:gt[yt].splice(2,0,"CONTAINER"),kt.addContainerBoundary(...gt[yt]),this.$=gt[yt];break;case 39:kt.addDeploymentNode("node",...gt[yt]),this.$=gt[yt];break;case 40:kt.addDeploymentNode("nodeL",...gt[yt]),this.$=gt[yt];break;case 41:kt.addDeploymentNode("nodeR",...gt[yt]),this.$=gt[yt];break;case 42:kt.popBoundaryParseStack();break;case 46:kt.addPersonOrSystem("person",...gt[yt]),this.$=gt[yt];break;case 47:kt.addPersonOrSystem("external_person",...gt[yt]),this.$=gt[yt];break;case 48:kt.addPersonOrSystem("system",...gt[yt]),this.$=gt[yt];break;case 49:kt.addPersonOrSystem("system_db",...gt[yt]),this.$=gt[yt];break;case 50:kt.addPersonOrSystem("system_queue",...gt[yt]),this.$=gt[yt];break;case 51:kt.addPersonOrSystem("external_system",...gt[yt]),this.$=gt[yt];break;case 52:kt.addPersonOrSystem("external_system_db",...gt[yt]),this.$=gt[yt];break;case 53:kt.addPersonOrSystem("external_system_queue",...gt[yt]),this.$=gt[yt];break;case 54:kt.addContainer("container",...gt[yt]),this.$=gt[yt];break;case 55:kt.addContainer("container_db",...gt[yt]),this.$=gt[yt];break;case 56:kt.addContainer("container_queue",...gt[yt]),this.$=gt[yt];break;case 57:kt.addContainer("external_container",...gt[yt]),this.$=gt[yt];break;case 58:kt.addContainer("external_container_db",...gt[yt]),this.$=gt[yt];break;case 59:kt.addContainer("external_container_queue",...gt[yt]),this.$=gt[yt];break;case 60:kt.addComponent("component",...gt[yt]),this.$=gt[yt];break;case 61:kt.addComponent("component_db",...gt[yt]),this.$=gt[yt];break;case 62:kt.addComponent("component_queue",...gt[yt]),this.$=gt[yt];break;case 63:kt.addComponent("external_component",...gt[yt]),this.$=gt[yt];break;case 64:kt.addComponent("external_component_db",...gt[yt]),this.$=gt[yt];break;case 65:kt.addComponent("external_component_queue",...gt[yt]),this.$=gt[yt];break;case 67:kt.addRel("rel",...gt[yt]),this.$=gt[yt];break;case 68:kt.addRel("birel",...gt[yt]),this.$=gt[yt];break;case 69:kt.addRel("rel_u",...gt[yt]),this.$=gt[yt];break;case 70:kt.addRel("rel_d",...gt[yt]),this.$=gt[yt];break;case 71:kt.addRel("rel_l",...gt[yt]),this.$=gt[yt];break;case 72:kt.addRel("rel_r",...gt[yt]),this.$=gt[yt];break;case 73:kt.addRel("rel_b",...gt[yt]),this.$=gt[yt];break;case 74:gt[yt].splice(0,1),kt.addRel("rel",...gt[yt]),this.$=gt[yt];break;case 75:kt.updateElStyle("update_el_style",...gt[yt]),this.$=gt[yt];break;case 76:kt.updateRelStyle("update_rel_style",...gt[yt]),this.$=gt[yt];break;case 77:kt.updateLayoutConfig("update_layout_config",...gt[yt]),this.$=gt[yt];break;case 78:this.$=[gt[yt]];break;case 79:gt[yt].unshift(gt[yt-1]),this.$=gt[yt];break;case 80:case 82:this.$=gt[yt].trim();break;case 81:let ne={};ne[gt[yt-1].trim()]=gt[yt].trim(),this.$=ne;break;case 83:this.$="";break}},table:[{3:1,4:2,5:3,6:4,7:e,8:r,9:n,10:i,11:5,12:10,18:a,22:s,25:o,26:l,27:u,28:h},{1:[3]},{1:[2,1]},{1:[2,2]},{3:17,4:2,5:3,6:4,7:e,8:r,9:n,10:i,11:5,12:10,18:a,22:s,25:o,26:l,27:u,28:h},{1:[2,8]},{1:[2,4]},{1:[2,5]},{1:[2,6]},{1:[2,7]},{13:18,19:[1,19]},{15:[1,20]},{15:[1,21]},{15:[1,22]},{15:[1,23]},{15:[1,24]},{19:[2,11]},{1:[2,3]},{14:25,16:[1,26],21:d},t([16,21],[2,12]),{23:28,29:29,30:30,31:31,32:f,33:p,34:m,36:_,38:y,39:58,40:70,42:71,44:b,46:x,47:k,48:T,49:C,50:M,51:S,53:32,54:R,55:A,56:L,57:v,58:B,59:w,60:D,61:N,62:z,63:X,64:ct,65:J,66:Y,67:$,68:lt,69:ut,70:W,71:tt,72:K,73:it,74:Z,75:V,76:Q,77:q,78:U,79:F,80:j,81:P,82:et,83:at,84:It},{23:79,29:29,30:30,31:31,32:f,33:p,34:m,36:_,38:y,39:58,40:70,42:71,44:b,46:x,47:k,48:T,49:C,50:M,51:S,53:32,54:R,55:A,56:L,57:v,58:B,59:w,60:D,61:N,62:z,63:X,64:ct,65:J,66:Y,67:$,68:lt,69:ut,70:W,71:tt,72:K,73:it,74:Z,75:V,76:Q,77:q,78:U,79:F,80:j,81:P,82:et,83:at,84:It},{23:80,29:29,30:30,31:31,32:f,33:p,34:m,36:_,38:y,39:58,40:70,42:71,44:b,46:x,47:k,48:T,49:C,50:M,51:S,53:32,54:R,55:A,56:L,57:v,58:B,59:w,60:D,61:N,62:z,63:X,64:ct,65:J,66:Y,67:$,68:lt,69:ut,70:W,71:tt,72:K,73:it,74:Z,75:V,76:Q,77:q,78:U,79:F,80:j,81:P,82:et,83:at,84:It},{23:81,29:29,30:30,31:31,32:f,33:p,34:m,36:_,38:y,39:58,40:70,42:71,44:b,46:x,47:k,48:T,49:C,50:M,51:S,53:32,54:R,55:A,56:L,57:v,58:B,59:w,60:D,61:N,62:z,63:X,64:ct,65:J,66:Y,67:$,68:lt,69:ut,70:W,71:tt,72:K,73:it,74:Z,75:V,76:Q,77:q,78:U,79:F,80:j,81:P,82:et,83:at,84:It},{23:82,29:29,30:30,31:31,32:f,33:p,34:m,36:_,38:y,39:58,40:70,42:71,44:b,46:x,47:k,48:T,49:C,50:M,51:S,53:32,54:R,55:A,56:L,57:v,58:B,59:w,60:D,61:N,62:z,63:X,64:ct,65:J,66:Y,67:$,68:lt,69:ut,70:W,71:tt,72:K,73:it,74:Z,75:V,76:Q,77:q,78:U,79:F,80:j,81:P,82:et,83:at,84:It},{15:[1,83]},{17:84,20:[1,85]},{15:[2,14]},{24:[1,86]},t(Lt,[2,20],{53:32,39:58,40:70,42:71,30:87,44:b,46:x,47:k,48:T,49:C,50:M,51:S,54:R,55:A,56:L,57:v,58:B,59:w,60:D,61:N,62:z,63:X,64:ct,65:J,66:Y,67:$,68:lt,69:ut,70:W,71:tt,72:K,73:it,74:Z,75:V,76:Q,77:q,78:U,79:F,80:j,81:P,82:et,83:at,84:It}),t(Lt,[2,21]),t(Rt,[2,23],{15:[1,88]}),t(Lt,[2,43],{15:[1,89]}),t(Ct,[2,26]),t(Ct,[2,27]),{35:[1,90]},{37:[1,91]},t(Ct,[2,30]),{45:92,85:93,86:pt,87:mt,89:vt,90:Tt},{45:98,85:93,86:pt,87:mt,89:vt,90:Tt},{45:99,85:93,86:pt,87:mt,89:vt,90:Tt},{45:100,85:93,86:pt,87:mt,89:vt,90:Tt},{45:101,85:93,86:pt,87:mt,89:vt,90:Tt},{45:102,85:93,86:pt,87:mt,89:vt,90:Tt},{45:103,85:93,86:pt,87:mt,89:vt,90:Tt},{45:104,85:93,86:pt,87:mt,89:vt,90:Tt},{45:105,85:93,86:pt,87:mt,89:vt,90:Tt},{45:106,85:93,86:pt,87:mt,89:vt,90:Tt},{45:107,85:93,86:pt,87:mt,89:vt,90:Tt},{45:108,85:93,86:pt,87:mt,89:vt,90:Tt},{45:109,85:93,86:pt,87:mt,89:vt,90:Tt},{45:110,85:93,86:pt,87:mt,89:vt,90:Tt},{45:111,85:93,86:pt,87:mt,89:vt,90:Tt},{45:112,85:93,86:pt,87:mt,89:vt,90:Tt},{45:113,85:93,86:pt,87:mt,89:vt,90:Tt},{45:114,85:93,86:pt,87:mt,89:vt,90:Tt},{45:115,85:93,86:pt,87:mt,89:vt,90:Tt},{45:116,85:93,86:pt,87:mt,89:vt,90:Tt},t(ft,[2,66]),{45:117,85:93,86:pt,87:mt,89:vt,90:Tt},{45:118,85:93,86:pt,87:mt,89:vt,90:Tt},{45:119,85:93,86:pt,87:mt,89:vt,90:Tt},{45:120,85:93,86:pt,87:mt,89:vt,90:Tt},{45:121,85:93,86:pt,87:mt,89:vt,90:Tt},{45:122,85:93,86:pt,87:mt,89:vt,90:Tt},{45:123,85:93,86:pt,87:mt,89:vt,90:Tt},{45:124,85:93,86:pt,87:mt,89:vt,90:Tt},{45:125,85:93,86:pt,87:mt,89:vt,90:Tt},{45:126,85:93,86:pt,87:mt,89:vt,90:Tt},{45:127,85:93,86:pt,87:mt,89:vt,90:Tt},{30:128,39:58,40:70,42:71,44:b,46:x,47:k,48:T,49:C,50:M,51:S,53:32,54:R,55:A,56:L,57:v,58:B,59:w,60:D,61:N,62:z,63:X,64:ct,65:J,66:Y,67:$,68:lt,69:ut,70:W,71:tt,72:K,73:it,74:Z,75:V,76:Q,77:q,78:U,79:F,80:j,81:P,82:et,83:at,84:It},{15:[1,130],43:[1,129]},{45:131,85:93,86:pt,87:mt,89:vt,90:Tt},{45:132,85:93,86:pt,87:mt,89:vt,90:Tt},{45:133,85:93,86:pt,87:mt,89:vt,90:Tt},{45:134,85:93,86:pt,87:mt,89:vt,90:Tt},{45:135,85:93,86:pt,87:mt,89:vt,90:Tt},{45:136,85:93,86:pt,87:mt,89:vt,90:Tt},{45:137,85:93,86:pt,87:mt,89:vt,90:Tt},{24:[1,138]},{24:[1,139]},{24:[1,140]},{24:[1,141]},t(le,[2,9]),{14:142,21:d},{21:[2,13]},{1:[2,15]},t(Lt,[2,22]),t(Rt,[2,24],{31:31,29:143,32:f,33:p,34:m,36:_,38:y}),t(Lt,[2,44],{29:29,30:30,31:31,53:32,39:58,40:70,42:71,23:144,32:f,33:p,34:m,36:_,38:y,44:b,46:x,47:k,48:T,49:C,50:M,51:S,54:R,55:A,56:L,57:v,58:B,59:w,60:D,61:N,62:z,63:X,64:ct,65:J,66:Y,67:$,68:lt,69:ut,70:W,71:tt,72:K,73:it,74:Z,75:V,76:Q,77:q,78:U,79:F,80:j,81:P,82:et,83:at,84:It}),t(Ct,[2,28]),t(Ct,[2,29]),t(ft,[2,46]),t(Dt,[2,78],{85:93,45:145,86:pt,87:mt,89:vt,90:Tt}),t(Gt,[2,80]),{88:[1,146]},t(Gt,[2,82]),t(Gt,[2,83]),t(ft,[2,47]),t(ft,[2,48]),t(ft,[2,49]),t(ft,[2,50]),t(ft,[2,51]),t(ft,[2,52]),t(ft,[2,53]),t(ft,[2,54]),t(ft,[2,55]),t(ft,[2,56]),t(ft,[2,57]),t(ft,[2,58]),t(ft,[2,59]),t(ft,[2,60]),t(ft,[2,61]),t(ft,[2,62]),t(ft,[2,63]),t(ft,[2,64]),t(ft,[2,65]),t(ft,[2,67]),t(ft,[2,68]),t(ft,[2,69]),t(ft,[2,70]),t(ft,[2,71]),t(ft,[2,72]),t(ft,[2,73]),t(ft,[2,74]),t(ft,[2,75]),t(ft,[2,76]),t(ft,[2,77]),{41:147,52:[1,148]},{15:[1,149]},{43:[1,150]},t($t,[2,35]),t($t,[2,36]),t($t,[2,37]),t($t,[2,38]),t($t,[2,39]),t($t,[2,40]),t($t,[2,41]),{1:[2,16]},{1:[2,17]},{1:[2,18]},{1:[2,19]},{15:[1,151]},t(Rt,[2,25]),t(Lt,[2,45]),t(Dt,[2,79]),t(Gt,[2,81]),t(ft,[2,31]),t(ft,[2,42]),t(Qt,[2,32]),t(Qt,[2,33],{15:[1,152]}),t(le,[2,10]),t(Qt,[2,34])],defaultActions:{2:[2,1],3:[2,2],5:[2,8],6:[2,4],7:[2,5],8:[2,6],9:[2,7],16:[2,11],17:[2,3],27:[2,14],85:[2,13],86:[2,15],138:[2,16],139:[2,17],140:[2,18],141:[2,19]},parseError:function(wt,bt){if(bt.recoverable)this.trace(wt);else{var Et=new Error(wt);throw Et.hash=bt,Et}},parse:function(wt){var bt=this,Et=[0],kt=[],Ut=[null],gt=[],he=this.table,yt="",ne=0,ve=0,ye=2,be=1,Te=gt.slice.call(arguments,1),Wt=Object.create(this.lexer),se={yy:{}};for(var me in this.yy)Object.prototype.hasOwnProperty.call(this.yy,me)&&(se.yy[me]=this.yy[me]);Wt.setInput(wt,se.yy),se.yy.lexer=Wt,se.yy.parser=this,typeof Wt.yylloc>"u"&&(Wt.yylloc={});var ue=Wt.yylloc;gt.push(ue);var _a=Wt.options&&Wt.options.ranges;typeof se.yy.parseError=="function"?this.parseError=se.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function Hr(){var Jt;return Jt=kt.pop()||Wt.lex()||be,typeof Jt!="number"&&(Jt instanceof Array&&(kt=Jt,Jt=kt.pop()),Jt=bt.symbols_[Jt]||Jt),Jt}for(var Ie,oe,Ke,wr,Ge={},Ze,qt,st,At;;){if(oe=Et[Et.length-1],this.defaultActions[oe]?Ke=this.defaultActions[oe]:((Ie===null||typeof Ie>"u")&&(Ie=Hr()),Ke=he[oe]&&he[oe][Ie]),typeof Ke>"u"||!Ke.length||!Ke[0]){var Nt="";At=[];for(Ze in he[oe])this.terminals_[Ze]&&Ze>ye&&At.push("'"+this.terminals_[Ze]+"'");Wt.showPosition?Nt="Parse error on line "+(ne+1)+`: +`+Wt.showPosition()+` +Expecting `+At.join(", ")+", got '"+(this.terminals_[Ie]||Ie)+"'":Nt="Parse error on line "+(ne+1)+": Unexpected "+(Ie==be?"end of input":"'"+(this.terminals_[Ie]||Ie)+"'"),this.parseError(Nt,{text:Wt.match,token:this.terminals_[Ie]||Ie,line:Wt.yylineno,loc:ue,expected:At})}if(Ke[0]instanceof Array&&Ke.length>1)throw new Error("Parse Error: multiple actions possible at state: "+oe+", token: "+Ie);switch(Ke[0]){case 1:Et.push(Ie),Ut.push(Wt.yytext),gt.push(Wt.yylloc),Et.push(Ke[1]),Ie=null,ve=Wt.yyleng,yt=Wt.yytext,ne=Wt.yylineno,ue=Wt.yylloc;break;case 2:if(qt=this.productions_[Ke[1]][1],Ge.$=Ut[Ut.length-qt],Ge._$={first_line:gt[gt.length-(qt||1)].first_line,last_line:gt[gt.length-1].last_line,first_column:gt[gt.length-(qt||1)].first_column,last_column:gt[gt.length-1].last_column},_a&&(Ge._$.range=[gt[gt.length-(qt||1)].range[0],gt[gt.length-1].range[1]]),wr=this.performAction.apply(Ge,[yt,ve,ne,se.yy,Ke[1],Ut,gt].concat(Te)),typeof wr<"u")return wr;qt&&(Et=Et.slice(0,-1*qt*2),Ut=Ut.slice(0,-1*qt),gt=gt.slice(0,-1*qt)),Et.push(this.productions_[Ke[1]][0]),Ut.push(Ge.$),gt.push(Ge._$),st=he[Et[Et.length-2]][Et[Et.length-1]],Et.push(st);break;case 3:return!0}}return!0}},jt=function(){var zt={EOF:1,parseError:function(bt,Et){if(this.yy.parser)this.yy.parser.parseError(bt,Et);else throw new Error(bt)},setInput:function(wt,bt){return this.yy=bt||this.yy||{},this._input=wt,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var wt=this._input[0];this.yytext+=wt,this.yyleng++,this.offset++,this.match+=wt,this.matched+=wt;var bt=wt.match(/(?:\r\n?|\n).*/g);return bt?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),wt},unput:function(wt){var bt=wt.length,Et=wt.split(/(?:\r\n?|\n)/g);this._input=wt+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-bt),this.offset-=bt;var kt=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),Et.length-1&&(this.yylineno-=Et.length-1);var Ut=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:Et?(Et.length===kt.length?this.yylloc.first_column:0)+kt[kt.length-Et.length].length-Et[0].length:this.yylloc.first_column-bt},this.options.ranges&&(this.yylloc.range=[Ut[0],Ut[0]+this.yyleng-bt]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(wt){this.unput(this.match.slice(wt))},pastInput:function(){var wt=this.matched.substr(0,this.matched.length-this.match.length);return(wt.length>20?"...":"")+wt.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var wt=this.match;return wt.length<20&&(wt+=this._input.substr(0,20-wt.length)),(wt.substr(0,20)+(wt.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var wt=this.pastInput(),bt=new Array(wt.length+1).join("-");return wt+this.upcomingInput()+` +`+bt+"^"},test_match:function(wt,bt){var Et,kt,Ut;if(this.options.backtrack_lexer&&(Ut={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(Ut.yylloc.range=this.yylloc.range.slice(0))),kt=wt[0].match(/(?:\r\n?|\n).*/g),kt&&(this.yylineno+=kt.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:kt?kt[kt.length-1].length-kt[kt.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+wt[0].length},this.yytext+=wt[0],this.match+=wt[0],this.matches=wt,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(wt[0].length),this.matched+=wt[0],Et=this.performAction.call(this,this.yy,this,bt,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),Et)return Et;if(this._backtrack){for(var gt in Ut)this[gt]=Ut[gt];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var wt,bt,Et,kt;this._more||(this.yytext="",this.match="");for(var Ut=this._currentRules(),gt=0;gt<Ut.length;gt++)if(Et=this._input.match(this.rules[Ut[gt]]),Et&&(!bt||Et[0].length>bt[0].length)){if(bt=Et,kt=gt,this.options.backtrack_lexer){if(wt=this.test_match(Et,Ut[gt]),wt!==!1)return wt;if(this._backtrack){bt=!1;continue}else return!1}else if(!this.options.flex)break}return bt?(wt=this.test_match(bt,Ut[kt]),wt!==!1?wt:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var bt=this.next();return bt||this.lex()},begin:function(bt){this.conditionStack.push(bt)},popState:function(){var bt=this.conditionStack.length-1;return bt>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(bt){return bt=this.conditionStack.length-1-Math.abs(bt||0),bt>=0?this.conditionStack[bt]:"INITIAL"},pushState:function(bt){this.begin(bt)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(bt,Et,kt,Ut){switch(kt){case 0:return this.begin("open_directive"),18;case 1:return 7;case 2:return 8;case 3:return 9;case 4:return 10;case 5:return this.begin("type_directive"),19;case 6:return this.popState(),this.begin("arg_directive"),16;case 7:return this.popState(),this.popState(),21;case 8:return 20;case 9:return 32;case 10:return 33;case 11:return this.begin("acc_title"),34;case 12:return this.popState(),"acc_title_value";case 13:return this.begin("acc_descr"),36;case 14:return this.popState(),"acc_descr_value";case 15:this.begin("acc_descr_multiline");break;case 16:this.popState();break;case 17:return"acc_descr_multiline_value";case 18:break;case 19:c;break;case 20:return 15;case 21:break;case 22:return 22;case 23:return 25;case 24:return 26;case 25:return 27;case 26:return 28;case 27:return this.begin("person_ext"),55;case 28:return this.begin("person"),54;case 29:return this.begin("system_ext_queue"),61;case 30:return this.begin("system_ext_db"),60;case 31:return this.begin("system_ext"),59;case 32:return this.begin("system_queue"),58;case 33:return this.begin("system_db"),57;case 34:return this.begin("system"),56;case 35:return this.begin("boundary"),47;case 36:return this.begin("enterprise_boundary"),44;case 37:return this.begin("system_boundary"),46;case 38:return this.begin("container_ext_queue"),67;case 39:return this.begin("container_ext_db"),66;case 40:return this.begin("container_ext"),65;case 41:return this.begin("container_queue"),64;case 42:return this.begin("container_db"),63;case 43:return this.begin("container"),62;case 44:return this.begin("container_boundary"),48;case 45:return this.begin("component_ext_queue"),73;case 46:return this.begin("component_ext_db"),72;case 47:return this.begin("component_ext"),71;case 48:return this.begin("component_queue"),70;case 49:return this.begin("component_db"),69;case 50:return this.begin("component"),68;case 51:return this.begin("node"),49;case 52:return this.begin("node"),49;case 53:return this.begin("node_l"),50;case 54:return this.begin("node_r"),51;case 55:return this.begin("rel"),74;case 56:return this.begin("birel"),75;case 57:return this.begin("rel_u"),76;case 58:return this.begin("rel_u"),76;case 59:return this.begin("rel_d"),77;case 60:return this.begin("rel_d"),77;case 61:return this.begin("rel_l"),78;case 62:return this.begin("rel_l"),78;case 63:return this.begin("rel_r"),79;case 64:return this.begin("rel_r"),79;case 65:return this.begin("rel_b"),80;case 66:return this.begin("rel_index"),81;case 67:return this.begin("update_el_style"),82;case 68:return this.begin("update_rel_style"),83;case 69:return this.begin("update_layout_config"),84;case 70:return"EOF_IN_STRUCT";case 71:return this.begin("attribute"),"ATTRIBUTE_EMPTY";case 72:this.begin("attribute");break;case 73:this.popState(),this.popState();break;case 74:return 90;case 75:break;case 76:return 90;case 77:this.begin("string");break;case 78:this.popState();break;case 79:return"STR";case 80:this.begin("string_kv");break;case 81:return this.begin("string_kv_key"),"STR_KEY";case 82:this.popState(),this.begin("string_kv_value");break;case 83:return"STR_VALUE";case 84:this.popState(),this.popState();break;case 85:return"STR";case 86:return"LBRACE";case 87:return"RBRACE";case 88:return"SPACE";case 89:return"EOL";case 90:return 24}},rules:[/^(?:%%\{)/,/^(?:.*direction\s+TB[^\n]*)/,/^(?:.*direction\s+BT[^\n]*)/,/^(?:.*direction\s+RL[^\n]*)/,/^(?:.*direction\s+LR[^\n]*)/,/^(?:((?:(?!\}%%)[^:.])*))/,/^(?::)/,/^(?:\}%%)/,/^(?:((?:(?!\}%%).|\n)*))/,/^(?:title\s[^#\n;]+)/,/^(?:accDescription\s[^#\n;]+)/,/^(?:accTitle\s*:\s*)/,/^(?:(?!\n||)*[^\n]*)/,/^(?:accDescr\s*:\s*)/,/^(?:(?!\n||)*[^\n]*)/,/^(?:accDescr\s*\{\s*)/,/^(?:[\}])/,/^(?:[^\}]*)/,/^(?:%%(?!\{)*[^\n]*(\r?\n?)+)/,/^(?:%%[^\n]*(\r?\n)*)/,/^(?:\s*(\r?\n)+)/,/^(?:\s+)/,/^(?:C4Context\b)/,/^(?:C4Container\b)/,/^(?:C4Component\b)/,/^(?:C4Dynamic\b)/,/^(?:C4Deployment\b)/,/^(?:Person_Ext\b)/,/^(?:Person\b)/,/^(?:SystemQueue_Ext\b)/,/^(?:SystemDb_Ext\b)/,/^(?:System_Ext\b)/,/^(?:SystemQueue\b)/,/^(?:SystemDb\b)/,/^(?:System\b)/,/^(?:Boundary\b)/,/^(?:Enterprise_Boundary\b)/,/^(?:System_Boundary\b)/,/^(?:ContainerQueue_Ext\b)/,/^(?:ContainerDb_Ext\b)/,/^(?:Container_Ext\b)/,/^(?:ContainerQueue\b)/,/^(?:ContainerDb\b)/,/^(?:Container\b)/,/^(?:Container_Boundary\b)/,/^(?:ComponentQueue_Ext\b)/,/^(?:ComponentDb_Ext\b)/,/^(?:Component_Ext\b)/,/^(?:ComponentQueue\b)/,/^(?:ComponentDb\b)/,/^(?:Component\b)/,/^(?:Deployment_Node\b)/,/^(?:Node\b)/,/^(?:Node_L\b)/,/^(?:Node_R\b)/,/^(?:Rel\b)/,/^(?:BiRel\b)/,/^(?:Rel_Up\b)/,/^(?:Rel_U\b)/,/^(?:Rel_Down\b)/,/^(?:Rel_D\b)/,/^(?:Rel_Left\b)/,/^(?:Rel_L\b)/,/^(?:Rel_Right\b)/,/^(?:Rel_R\b)/,/^(?:Rel_Back\b)/,/^(?:RelIndex\b)/,/^(?:UpdateElementStyle\b)/,/^(?:UpdateRelStyle\b)/,/^(?:UpdateLayoutConfig\b)/,/^(?:$)/,/^(?:[(][ ]*[,])/,/^(?:[(])/,/^(?:[)])/,/^(?:,,)/,/^(?:,)/,/^(?:[ ]*["]["])/,/^(?:[ ]*["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:[ ]*[\$])/,/^(?:[^=]*)/,/^(?:[=][ ]*["])/,/^(?:[^"]+)/,/^(?:["])/,/^(?:[^,]+)/,/^(?:\{)/,/^(?:\})/,/^(?:[\s]+)/,/^(?:[\n\r]+)/,/^(?:$)/],conditions:{acc_descr_multiline:{rules:[16,17],inclusive:!1},acc_descr:{rules:[14],inclusive:!1},acc_title:{rules:[12],inclusive:!1},close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[7,8],inclusive:!1},type_directive:{rules:[6,7],inclusive:!1},open_directive:{rules:[5],inclusive:!1},string_kv_value:{rules:[83,84],inclusive:!1},string_kv_key:{rules:[82],inclusive:!1},string_kv:{rules:[81],inclusive:!1},string:{rules:[78,79],inclusive:!1},attribute:{rules:[73,74,75,76,77,80,85],inclusive:!1},update_layout_config:{rules:[70,71,72,73],inclusive:!1},update_rel_style:{rules:[70,71,72,73],inclusive:!1},update_el_style:{rules:[70,71,72,73],inclusive:!1},rel_b:{rules:[70,71,72,73],inclusive:!1},rel_r:{rules:[70,71,72,73],inclusive:!1},rel_l:{rules:[70,71,72,73],inclusive:!1},rel_d:{rules:[70,71,72,73],inclusive:!1},rel_u:{rules:[70,71,72,73],inclusive:!1},rel_bi:{rules:[],inclusive:!1},rel:{rules:[70,71,72,73],inclusive:!1},node_r:{rules:[70,71,72,73],inclusive:!1},node_l:{rules:[70,71,72,73],inclusive:!1},node:{rules:[70,71,72,73],inclusive:!1},index:{rules:[],inclusive:!1},rel_index:{rules:[70,71,72,73],inclusive:!1},component_ext_queue:{rules:[],inclusive:!1},component_ext_db:{rules:[70,71,72,73],inclusive:!1},component_ext:{rules:[70,71,72,73],inclusive:!1},component_queue:{rules:[70,71,72,73],inclusive:!1},component_db:{rules:[70,71,72,73],inclusive:!1},component:{rules:[70,71,72,73],inclusive:!1},container_boundary:{rules:[70,71,72,73],inclusive:!1},container_ext_queue:{rules:[],inclusive:!1},container_ext_db:{rules:[70,71,72,73],inclusive:!1},container_ext:{rules:[70,71,72,73],inclusive:!1},container_queue:{rules:[70,71,72,73],inclusive:!1},container_db:{rules:[70,71,72,73],inclusive:!1},container:{rules:[70,71,72,73],inclusive:!1},birel:{rules:[70,71,72,73],inclusive:!1},system_boundary:{rules:[70,71,72,73],inclusive:!1},enterprise_boundary:{rules:[70,71,72,73],inclusive:!1},boundary:{rules:[70,71,72,73],inclusive:!1},system_ext_queue:{rules:[70,71,72,73],inclusive:!1},system_ext_db:{rules:[70,71,72,73],inclusive:!1},system_ext:{rules:[70,71,72,73],inclusive:!1},system_queue:{rules:[70,71,72,73],inclusive:!1},system_db:{rules:[70,71,72,73],inclusive:!1},system:{rules:[70,71,72,73],inclusive:!1},person_ext:{rules:[70,71,72,73],inclusive:!1},person:{rules:[70,71,72,73],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,9,10,11,13,15,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,86,87,88,89,90],inclusive:!0}}};return zt}();we.lexer=jt;function Ft(){this.yy={}}return Ft.prototype=we,we.Parser=Ft,new Ft}();qc.parser=qc;const lK=t=>t.match(/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/)!==null;let di=[],Qa=[""],un="global",pi="",Di=[{alias:"global",label:{text:"global"},type:{text:"global"},tags:null,link:null,parentBoundary:""}],Vc=[],mg="",bg=!1,p1=4,g1=2;var jw;const cK=function(){return jw},uK=function(t){jw=ai(t,nt())},hK=function(t,e,r){Xe.parseDirective(this,t,e,r)},fK=function(t,e,r,n,i,a,s,o,l){if(t==null||e===void 0||e===null||r===void 0||r===null||n===void 0||n===null)return;let u={};const h=Vc.find(d=>d.from===e&&d.to===r);if(h?u=h:Vc.push(u),u.type=t,u.from=e,u.to=r,u.label={text:n},i==null)u.techn={text:""};else if(typeof i=="object"){let[d,f]=Object.entries(i)[0];u[d]={text:f}}else u.techn={text:i};if(a==null)u.descr={text:""};else if(typeof a=="object"){let[d,f]=Object.entries(a)[0];u[d]={text:f}}else u.descr={text:a};if(typeof s=="object"){let[d,f]=Object.entries(s)[0];u[d]=f}else u.sprite=s;if(typeof o=="object"){let[d,f]=Object.entries(o)[0];u[d]=f}else u.tags=o;if(typeof l=="object"){let[d,f]=Object.entries(l)[0];u[d]=f}else u.link=l;u.wrap=Ja()},dK=function(t,e,r,n,i,a,s){if(e===null||r===null)return;let o={};const l=di.find(u=>u.alias===e);if(l&&e===l.alias?o=l:(o.alias=e,di.push(o)),r==null?o.label={text:""}:o.label={text:r},n==null)o.descr={text:""};else if(typeof n=="object"){let[u,h]=Object.entries(n)[0];o[u]={text:h}}else o.descr={text:n};if(typeof i=="object"){let[u,h]=Object.entries(i)[0];o[u]=h}else o.sprite=i;if(typeof a=="object"){let[u,h]=Object.entries(a)[0];o[u]=h}else o.tags=a;if(typeof s=="object"){let[u,h]=Object.entries(s)[0];o[u]=h}else o.link=s;o.typeC4Shape={text:t},o.parentBoundary=un,o.wrap=Ja()},pK=function(t,e,r,n,i,a,s,o){if(e===null||r===null)return;let l={};const u=di.find(h=>h.alias===e);if(u&&e===u.alias?l=u:(l.alias=e,di.push(l)),r==null?l.label={text:""}:l.label={text:r},n==null)l.techn={text:""};else if(typeof n=="object"){let[h,d]=Object.entries(n)[0];l[h]={text:d}}else l.techn={text:n};if(i==null)l.descr={text:""};else if(typeof i=="object"){let[h,d]=Object.entries(i)[0];l[h]={text:d}}else l.descr={text:i};if(typeof a=="object"){let[h,d]=Object.entries(a)[0];l[h]=d}else l.sprite=a;if(typeof s=="object"){let[h,d]=Object.entries(s)[0];l[h]=d}else l.tags=s;if(typeof o=="object"){let[h,d]=Object.entries(o)[0];l[h]=d}else l.link=o;l.wrap=Ja(),l.typeC4Shape={text:t},l.parentBoundary=un},gK=function(t,e,r,n,i,a,s,o){if(e===null||r===null)return;let l={};const u=di.find(h=>h.alias===e);if(u&&e===u.alias?l=u:(l.alias=e,di.push(l)),r==null?l.label={text:""}:l.label={text:r},n==null)l.techn={text:""};else if(typeof n=="object"){let[h,d]=Object.entries(n)[0];l[h]={text:d}}else l.techn={text:n};if(i==null)l.descr={text:""};else if(typeof i=="object"){let[h,d]=Object.entries(i)[0];l[h]={text:d}}else l.descr={text:i};if(typeof a=="object"){let[h,d]=Object.entries(a)[0];l[h]=d}else l.sprite=a;if(typeof s=="object"){let[h,d]=Object.entries(s)[0];l[h]=d}else l.tags=s;if(typeof o=="object"){let[h,d]=Object.entries(o)[0];l[h]=d}else l.link=o;l.wrap=Ja(),l.typeC4Shape={text:t},l.parentBoundary=un},yK=function(t,e,r,n,i){if(t===null||e===null)return;let a={};const s=Di.find(o=>o.alias===t);if(s&&t===s.alias?a=s:(a.alias=t,Di.push(a)),e==null?a.label={text:""}:a.label={text:e},r==null)a.type={text:"system"};else if(typeof r=="object"){let[o,l]=Object.entries(r)[0];a[o]={text:l}}else a.type={text:r};if(typeof n=="object"){let[o,l]=Object.entries(n)[0];a[o]=l}else a.tags=n;if(typeof i=="object"){let[o,l]=Object.entries(i)[0];a[o]=l}else a.link=i;a.parentBoundary=un,a.wrap=Ja(),pi=un,un=t,Qa.push(pi)},mK=function(t,e,r,n,i){if(t===null||e===null)return;let a={};const s=Di.find(o=>o.alias===t);if(s&&t===s.alias?a=s:(a.alias=t,Di.push(a)),e==null?a.label={text:""}:a.label={text:e},r==null)a.type={text:"container"};else if(typeof r=="object"){let[o,l]=Object.entries(r)[0];a[o]={text:l}}else a.type={text:r};if(typeof n=="object"){let[o,l]=Object.entries(n)[0];a[o]=l}else a.tags=n;if(typeof i=="object"){let[o,l]=Object.entries(i)[0];a[o]=l}else a.link=i;a.parentBoundary=un,a.wrap=Ja(),pi=un,un=t,Qa.push(pi)},bK=function(t,e,r,n,i,a,s,o){if(e===null||r===null)return;let l={};const u=Di.find(h=>h.alias===e);if(u&&e===u.alias?l=u:(l.alias=e,Di.push(l)),r==null?l.label={text:""}:l.label={text:r},n==null)l.type={text:"node"};else if(typeof n=="object"){let[h,d]=Object.entries(n)[0];l[h]={text:d}}else l.type={text:n};if(i==null)l.descr={text:""};else if(typeof i=="object"){let[h,d]=Object.entries(i)[0];l[h]={text:d}}else l.descr={text:i};if(typeof s=="object"){let[h,d]=Object.entries(s)[0];l[h]=d}else l.tags=s;if(typeof o=="object"){let[h,d]=Object.entries(o)[0];l[h]=d}else l.link=o;l.nodeType=t,l.parentBoundary=un,l.wrap=Ja(),pi=un,un=e,Qa.push(pi)},_K=function(){un=pi,Qa.pop(),pi=Qa.pop(),Qa.push(pi)},vK=function(t,e,r,n,i,a,s,o,l,u,h){let d=di.find(f=>f.alias===e);if(!(d===void 0&&(d=Di.find(f=>f.alias===e),d===void 0))){if(r!=null)if(typeof r=="object"){let[f,p]=Object.entries(r)[0];d[f]=p}else d.bgColor=r;if(n!=null)if(typeof n=="object"){let[f,p]=Object.entries(n)[0];d[f]=p}else d.fontColor=n;if(i!=null)if(typeof i=="object"){let[f,p]=Object.entries(i)[0];d[f]=p}else d.borderColor=i;if(a!=null)if(typeof a=="object"){let[f,p]=Object.entries(a)[0];d[f]=p}else d.shadowing=a;if(s!=null)if(typeof s=="object"){let[f,p]=Object.entries(s)[0];d[f]=p}else d.shape=s;if(o!=null)if(typeof o=="object"){let[f,p]=Object.entries(o)[0];d[f]=p}else d.sprite=o;if(l!=null)if(typeof l=="object"){let[f,p]=Object.entries(l)[0];d[f]=p}else d.techn=l;if(u!=null)if(typeof u=="object"){let[f,p]=Object.entries(u)[0];d[f]=p}else d.legendText=u;if(h!=null)if(typeof h=="object"){let[f,p]=Object.entries(h)[0];d[f]=p}else d.legendSprite=h}},xK=function(t,e,r,n,i,a,s){const o=Vc.find(l=>l.from===e&&l.to===r);if(o!==void 0){if(n!=null)if(typeof n=="object"){let[l,u]=Object.entries(n)[0];o[l]=u}else o.textColor=n;if(i!=null)if(typeof i=="object"){let[l,u]=Object.entries(i)[0];o[l]=u}else o.lineColor=i;if(a!=null)if(typeof a=="object"){let[l,u]=Object.entries(a)[0];o[l]=parseInt(u)}else o.offsetX=parseInt(a);if(s!=null)if(typeof s=="object"){let[l,u]=Object.entries(s)[0];o[l]=parseInt(u)}else o.offsetY=parseInt(s)}},kK=function(t,e,r){let n=p1,i=g1;if(typeof e=="object"){const a=Object.values(e)[0];n=parseInt(a)}else n=parseInt(e);if(typeof r=="object"){const a=Object.values(r)[0];i=parseInt(a)}else i=parseInt(r);n>=1&&(p1=n),i>=1&&(g1=i)},wK=function(){return p1},TK=function(){return g1},EK=function(){return un},CK=function(){return pi},$w=function(t){return t==null?di:di.filter(e=>e.parentBoundary===t)},SK=function(t){return di.find(e=>e.alias===t)},AK=function(t){return Object.keys($w(t))},MK=function(t){return t==null?Di:Di.filter(e=>e.parentBoundary===t)},LK=function(){return Vc},RK=function(){return mg},IK=function(t){bg=t},Ja=function(){return bg},Xw={addPersonOrSystem:dK,addPersonOrSystemBoundary:yK,addContainer:pK,addContainerBoundary:mK,addComponent:gK,addDeploymentNode:bK,popBoundaryParseStack:_K,addRel:fK,updateElStyle:vK,updateRelStyle:xK,updateLayoutConfig:kK,autoWrap:Ja,setWrap:IK,getC4ShapeArray:$w,getC4Shape:SK,getC4ShapeKeys:AK,getBoundarys:MK,getCurrentBoundaryParse:EK,getParentBoundaryParse:CK,getRels:LK,getTitle:RK,getC4Type:cK,getC4ShapeInRow:wK,getC4BoundaryInRow:TK,setAccTitle:Yn,getAccTitle:ui,getAccDescription:fi,setAccDescription:hi,parseDirective:hK,getConfig:()=>nt().c4,clear:function(){di=[],Di=[{alias:"global",label:{text:"global"},type:{text:"global"},tags:null,link:null,parentBoundary:""}],pi="",un="global",Qa=[""],Vc=[],Qa=[""],mg="",bg=!1,p1=4,g1=2},LINETYPE:{SOLID:0,DOTTED:1,NOTE:2,SOLID_CROSS:3,DOTTED_CROSS:4,SOLID_OPEN:5,DOTTED_OPEN:6,LOOP_START:10,LOOP_END:11,ALT_START:12,ALT_ELSE:13,ALT_END:14,OPT_START:15,OPT_END:16,ACTIVE_START:17,ACTIVE_END:18,PAR_START:19,PAR_AND:20,PAR_END:21,RECT_START:22,RECT_END:23,SOLID_POINT:24,DOTTED_POINT:25},ARROWTYPE:{FILLED:0,OPEN:1},PLACEMENT:{LEFTOF:0,RIGHTOF:1,OVER:2},setTitle:function(t){mg=ai(t,nt())},setC4Type:uK},_g=function(t,e){const r=t.append("rect");if(r.attr("x",e.x),r.attr("y",e.y),r.attr("fill",e.fill),r.attr("stroke",e.stroke),r.attr("width",e.width),r.attr("height",e.height),r.attr("rx",e.rx),r.attr("ry",e.ry),e.attrs!=="undefined"&&e.attrs!==null)for(let n in e.attrs)r.attr(n,e.attrs[n]);return e.class!=="undefined"&&r.attr("class",e.class),r},Kw=function(t,e,r,n,i,a){const s=t.append("image");s.attr("width",e),s.attr("height",r),s.attr("x",n),s.attr("y",i);let o=a.startsWith("data:image/png;base64")?a:ki(a);s.attr("xlink:href",o)},NK=function(t,e,r,n){const i=t.append("use");i.attr("x",e),i.attr("y",r);var a=ki(n);i.attr("xlink:href","#"+a)},Zw=function(t,e){let r=0,n=0;const i=e.text.split(pe.lineBreakRegex);let a=[],s=0,o=()=>e.y;if(typeof e.valign<"u"&&typeof e.textMargin<"u"&&e.textMargin>0)switch(e.valign){case"top":case"start":o=()=>Math.round(e.y+e.textMargin);break;case"middle":case"center":o=()=>Math.round(e.y+(r+n+e.textMargin)/2);break;case"bottom":case"end":o=()=>Math.round(e.y+(r+n+2*e.textMargin)-e.textMargin);break}if(typeof e.anchor<"u"&&typeof e.textMargin<"u"&&typeof e.width<"u")switch(e.anchor){case"left":case"start":e.x=Math.round(e.x+e.textMargin),e.anchor="start",e.dominantBaseline="text-after-edge",e.alignmentBaseline="middle";break;case"middle":case"center":e.x=Math.round(e.x+e.width/2),e.anchor="middle",e.dominantBaseline="middle",e.alignmentBaseline="middle";break;case"right":case"end":e.x=Math.round(e.x+e.width-e.textMargin),e.anchor="end",e.dominantBaseline="text-before-edge",e.alignmentBaseline="middle";break}for(let l=0;l<i.length;l++){let u=i[l];typeof e.textMargin<"u"&&e.textMargin===0&&typeof e.fontSize<"u"&&(s=l*e.fontSize);const h=t.append("text");if(h.attr("x",e.x),h.attr("y",o()),typeof e.anchor<"u"&&h.attr("text-anchor",e.anchor).attr("dominant-baseline",e.dominantBaseline).attr("alignment-baseline",e.alignmentBaseline),typeof e.fontFamily<"u"&&h.style("font-family",e.fontFamily),typeof e.fontSize<"u"&&h.style("font-size",e.fontSize),typeof e.fontWeight<"u"&&h.style("font-weight",e.fontWeight),typeof e.fill<"u"&&h.attr("fill",e.fill),typeof e.class<"u"&&h.attr("class",e.class),typeof e.dy<"u"?h.attr("dy",e.dy):s!==0&&h.attr("dy",s),e.tspan){const d=h.append("tspan");d.attr("x",e.x),typeof e.fill<"u"&&d.attr("fill",e.fill),d.text(u)}else h.text(u);typeof e.valign<"u"&&typeof e.textMargin<"u"&&e.textMargin>0&&(n+=(h._groups||h)[0][0].getBBox().height,r=n),a.push(h)}return a},BK=function(t,e){function r(i,a,s,o,l){return i+","+a+" "+(i+s)+","+a+" "+(i+s)+","+(a+o-l)+" "+(i+s-l*1.2)+","+(a+o)+" "+i+","+(a+o)}const n=t.append("polygon");return n.attr("points",r(e.x,e.y,e.width,e.height,7)),n.attr("class","labelBox"),e.y=e.y+e.height/2,Zw(t,e),n},DK=(t,e,r)=>{const n=t.append("g");let i=0;for(let a of e){let s=a.textColor?a.textColor:"#444444",o=a.lineColor?a.lineColor:"#444444",l=a.offsetX?parseInt(a.offsetX):0,u=a.offsetY?parseInt(a.offsetY):0,h="";if(i===0){let f=n.append("line");f.attr("x1",a.startPoint.x),f.attr("y1",a.startPoint.y),f.attr("x2",a.endPoint.x),f.attr("y2",a.endPoint.y),f.attr("stroke-width","1"),f.attr("stroke",o),f.style("fill","none"),a.type!=="rel_b"&&f.attr("marker-end","url("+h+"#arrowhead)"),(a.type==="birel"||a.type==="rel_b")&&f.attr("marker-start","url("+h+"#arrowend)"),i=-1}else{let f=n.append("path");f.attr("fill","none").attr("stroke-width","1").attr("stroke",o).attr("d","Mstartx,starty Qcontrolx,controly stopx,stopy ".replaceAll("startx",a.startPoint.x).replaceAll("starty",a.startPoint.y).replaceAll("controlx",a.startPoint.x+(a.endPoint.x-a.startPoint.x)/2-(a.endPoint.x-a.startPoint.x)/4).replaceAll("controly",a.startPoint.y+(a.endPoint.y-a.startPoint.y)/2).replaceAll("stopx",a.endPoint.x).replaceAll("stopy",a.endPoint.y)),a.type!=="rel_b"&&f.attr("marker-end","url("+h+"#arrowhead)"),(a.type==="birel"||a.type==="rel_b")&&f.attr("marker-start","url("+h+"#arrowend)")}let d=r.messageFont();sa(r)(a.label.text,n,Math.min(a.startPoint.x,a.endPoint.x)+Math.abs(a.endPoint.x-a.startPoint.x)/2+l,Math.min(a.startPoint.y,a.endPoint.y)+Math.abs(a.endPoint.y-a.startPoint.y)/2+u,a.label.width,a.label.height,{fill:s},d),a.techn&&a.techn.text!==""&&(d=r.messageFont(),sa(r)("["+a.techn.text+"]",n,Math.min(a.startPoint.x,a.endPoint.x)+Math.abs(a.endPoint.x-a.startPoint.x)/2+l,Math.min(a.startPoint.y,a.endPoint.y)+Math.abs(a.endPoint.y-a.startPoint.y)/2+r.messageFontSize+5+u,Math.max(a.label.width,a.techn.width),a.techn.height,{fill:s,"font-style":"italic"},d))}},OK=function(t,e,r){const n=t.append("g");let i=e.bgColor?e.bgColor:"none",a=e.borderColor?e.borderColor:"#444444",s=e.fontColor?e.fontColor:"black",o={"stroke-width":1,"stroke-dasharray":"7.0,7.0"};e.nodeType&&(o={"stroke-width":1});let l={x:e.x,y:e.y,fill:i,stroke:a,width:e.width,height:e.height,rx:2.5,ry:2.5,attrs:o};_g(n,l);let u=r.boundaryFont();u.fontWeight="bold",u.fontSize=u.fontSize+2,u.fontColor=s,sa(r)(e.label.text,n,e.x,e.y+e.label.Y,e.width,e.height,{fill:"#444444"},u),e.type&&e.type.text!==""&&(u=r.boundaryFont(),u.fontColor=s,sa(r)(e.type.text,n,e.x,e.y+e.type.Y,e.width,e.height,{fill:"#444444"},u)),e.descr&&e.descr.text!==""&&(u=r.boundaryFont(),u.fontSize=u.fontSize-2,u.fontColor=s,sa(r)(e.descr.text,n,e.x,e.y+e.descr.Y,e.width,e.height,{fill:"#444444"},u))},FK=function(t,e,r){let n=e.bgColor?e.bgColor:r[e.typeC4Shape.text+"_bg_color"],i=e.borderColor?e.borderColor:r[e.typeC4Shape.text+"_border_color"],a=e.fontColor?e.fontColor:"#FFFFFF",s="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACD0lEQVR4Xu2YoU4EMRCGT+4j8Ai8AhaH4QHgAUjQuFMECUgMIUgwJAgMhgQsAYUiJCiQIBBY+EITsjfTdme6V24v4c8vyGbb+ZjOtN0bNcvjQXmkH83WvYBWto6PLm6v7p7uH1/w2fXD+PBycX1Pv2l3IdDm/vn7x+dXQiAubRzoURa7gRZWd0iGRIiJbOnhnfYBQZNJjNbuyY2eJG8fkDE3bbG4ep6MHUAsgYxmE3nVs6VsBWJSGccsOlFPmLIViMzLOB7pCVO2AtHJMohH7Fh6zqitQK7m0rJvAVYgGcEpe//PLdDz65sM4pF9N7ICcXDKIB5Nv6j7tD0NoSdM2QrU9Gg0ewE1LqBhHR3BBdvj2vapnidjHxD/q6vd7Pvhr31AwcY8eXMTXAKECZZJFXuEq27aLgQK5uLMohCenGGuGewOxSjBvYBqeG6B+Nqiblggdjnc+ZXDy+FNFpFzw76O3UBAROuXh6FoiAcf5g9eTvUgzy0nWg6I8cXHRUpg5bOVBCo+KDpFajOf23GgPme7RSQ+lacIENUgJ6gg1k6HjgOlqnLqip4tEuhv0hNEMXUD0clyXE3p6pZA0S2nnvTlXwLJEZWlb7cTQH1+USgTN4VhAenm/wea1OCAOmqo6fE1WCb9WSKBah+rbUWPWAmE2Rvk0ApiB45eOyNAzU8xcTvj8KvkKEoOaIYeHNA3ZuygAvFMUO0AAAAASUVORK5CYII=";switch(e.typeC4Shape.text){case"person":s="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACD0lEQVR4Xu2YoU4EMRCGT+4j8Ai8AhaH4QHgAUjQuFMECUgMIUgwJAgMhgQsAYUiJCiQIBBY+EITsjfTdme6V24v4c8vyGbb+ZjOtN0bNcvjQXmkH83WvYBWto6PLm6v7p7uH1/w2fXD+PBycX1Pv2l3IdDm/vn7x+dXQiAubRzoURa7gRZWd0iGRIiJbOnhnfYBQZNJjNbuyY2eJG8fkDE3bbG4ep6MHUAsgYxmE3nVs6VsBWJSGccsOlFPmLIViMzLOB7pCVO2AtHJMohH7Fh6zqitQK7m0rJvAVYgGcEpe//PLdDz65sM4pF9N7ICcXDKIB5Nv6j7tD0NoSdM2QrU9Gg0ewE1LqBhHR3BBdvj2vapnidjHxD/q6vd7Pvhr31AwcY8eXMTXAKECZZJFXuEq27aLgQK5uLMohCenGGuGewOxSjBvYBqeG6B+Nqiblggdjnc+ZXDy+FNFpFzw76O3UBAROuXh6FoiAcf5g9eTvUgzy0nWg6I8cXHRUpg5bOVBCo+KDpFajOf23GgPme7RSQ+lacIENUgJ6gg1k6HjgOlqnLqip4tEuhv0hNEMXUD0clyXE3p6pZA0S2nnvTlXwLJEZWlb7cTQH1+USgTN4VhAenm/wea1OCAOmqo6fE1WCb9WSKBah+rbUWPWAmE2Rvk0ApiB45eOyNAzU8xcTvj8KvkKEoOaIYeHNA3ZuygAvFMUO0AAAAASUVORK5CYII=";break;case"external_person":s="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAAB6ElEQVR4Xu2YLY+EMBCG9+dWr0aj0Wg0Go1Go0+j8Xdv2uTCvv1gpt0ebHKPuhDaeW4605Z9mJvx4AdXUyTUdd08z+u6flmWZRnHsWkafk9DptAwDPu+f0eAYtu2PEaGWuj5fCIZrBAC2eLBAnRCsEkkxmeaJp7iDJ2QMDdHsLg8SxKFEJaAo8lAXnmuOFIhTMpxxKATebo4UiFknuNo4OniSIXQyRxEA3YsnjGCVEjVXD7yLUAqxBGUyPv/Y4W2beMgGuS7kVQIBycH0fD+oi5pezQETxdHKmQKGk1eQEYldK+jw5GxPfZ9z7Mk0Qnhf1W1m3w//EUn5BDmSZsbR44QQLBEqrBHqOrmSKaQAxdnLArCrxZcM7A7ZKs4ioRq8LFC+NpC3WCBJsvpVw5edm9iEXFuyNfxXAgSwfrFQ1c0iNda8AdejvUgnktOtJQQxmcfFzGglc5WVCj7oDgFqU18boeFSs52CUh8LE8BIVQDT1ABrB0HtgSEYlX5doJnCwv9TXocKCaKbnwhdDKPq4lf3SwU3HLq4V/+WYhHVMa/3b4IlfyikAduCkcBc7mQ3/z/Qq/cTuikhkzB12Ae/mcJC9U+Vo8Ej1gWAtgbeGgFsAMHr50BIWOLCbezvhpBFUdY6EJuJ/QDW0XoMX60zZ0AAAAASUVORK5CYII=";break}const o=t.append("g");o.attr("class","person-man");const l=Qw();switch(e.typeC4Shape.text){case"person":case"external_person":case"system":case"external_system":case"container":case"external_container":case"component":case"external_component":l.x=e.x,l.y=e.y,l.fill=n,l.width=e.width,l.height=e.height,l.style="stroke:"+i+";stroke-width:0.5;",l.rx=2.5,l.ry=2.5,_g(o,l);break;case"system_db":case"external_system_db":case"container_db":case"external_container_db":case"component_db":case"external_component_db":o.append("path").attr("fill",n).attr("stroke-width","0.5").attr("stroke",i).attr("d","Mstartx,startyc0,-10 half,-10 half,-10c0,0 half,0 half,10l0,heightc0,10 -half,10 -half,10c0,0 -half,0 -half,-10l0,-height".replaceAll("startx",e.x).replaceAll("starty",e.y).replaceAll("half",e.width/2).replaceAll("height",e.height)),o.append("path").attr("fill","none").attr("stroke-width","0.5").attr("stroke",i).attr("d","Mstartx,startyc0,10 half,10 half,10c0,0 half,0 half,-10".replaceAll("startx",e.x).replaceAll("starty",e.y).replaceAll("half",e.width/2));break;case"system_queue":case"external_system_queue":case"container_queue":case"external_container_queue":case"component_queue":case"external_component_queue":o.append("path").attr("fill",n).attr("stroke-width","0.5").attr("stroke",i).attr("d","Mstartx,startylwidth,0c5,0 5,half 5,halfc0,0 0,half -5,halfl-width,0c-5,0 -5,-half -5,-halfc0,0 0,-half 5,-half".replaceAll("startx",e.x).replaceAll("starty",e.y).replaceAll("width",e.width).replaceAll("half",e.height/2)),o.append("path").attr("fill","none").attr("stroke-width","0.5").attr("stroke",i).attr("d","Mstartx,startyc-5,0 -5,half -5,halfc0,half 5,half 5,half".replaceAll("startx",e.x+e.width).replaceAll("starty",e.y).replaceAll("half",e.height/2));break}let u=jK(r,e.typeC4Shape.text);switch(o.append("text").attr("fill",a).attr("font-family",u.fontFamily).attr("font-size",u.fontSize-2).attr("font-style","italic").attr("lengthAdjust","spacing").attr("textLength",e.typeC4Shape.width).attr("x",e.x+e.width/2-e.typeC4Shape.width/2).attr("y",e.y+e.typeC4Shape.Y).text("<<"+e.typeC4Shape.text+">>"),e.typeC4Shape.text){case"person":case"external_person":Kw(o,48,48,e.x+e.width/2-24,e.y+e.image.Y,s);break}let h=r[e.typeC4Shape.text+"Font"]();return h.fontWeight="bold",h.fontSize=h.fontSize+2,h.fontColor=a,sa(r)(e.label.text,o,e.x,e.y+e.label.Y,e.width,e.height,{fill:a},h),h=r[e.typeC4Shape.text+"Font"](),h.fontColor=a,e.thchn&&e.thchn.text!==""?sa(r)(e.thchn.text,o,e.x,e.y+e.thchn.Y,e.width,e.height,{fill:a,"font-style":"italic"},h):e.type&&e.type.text!==""&&sa(r)(e.type.text,o,e.x,e.y+e.type.Y,e.width,e.height,{fill:a,"font-style":"italic"},h),e.descr&&e.descr.text!==""&&(h=r.personFont(),h.fontColor=a,sa(r)(e.descr.text,o,e.x,e.y+e.descr.Y,e.width,e.height,{fill:a},h)),e.height},PK=function(t){t.append("defs").append("symbol").attr("id","database").attr("fill-rule","evenodd").attr("clip-rule","evenodd").append("path").attr("transform","scale(.5)").attr("d","M12.258.001l.256.004.255.005.253.008.251.01.249.012.247.015.246.016.242.019.241.02.239.023.236.024.233.027.231.028.229.031.225.032.223.034.22.036.217.038.214.04.211.041.208.043.205.045.201.046.198.048.194.05.191.051.187.053.183.054.18.056.175.057.172.059.168.06.163.061.16.063.155.064.15.066.074.033.073.033.071.034.07.034.069.035.068.035.067.035.066.035.064.036.064.036.062.036.06.036.06.037.058.037.058.037.055.038.055.038.053.038.052.038.051.039.05.039.048.039.047.039.045.04.044.04.043.04.041.04.04.041.039.041.037.041.036.041.034.041.033.042.032.042.03.042.029.042.027.042.026.043.024.043.023.043.021.043.02.043.018.044.017.043.015.044.013.044.012.044.011.045.009.044.007.045.006.045.004.045.002.045.001.045v17l-.001.045-.002.045-.004.045-.006.045-.007.045-.009.044-.011.045-.012.044-.013.044-.015.044-.017.043-.018.044-.02.043-.021.043-.023.043-.024.043-.026.043-.027.042-.029.042-.03.042-.032.042-.033.042-.034.041-.036.041-.037.041-.039.041-.04.041-.041.04-.043.04-.044.04-.045.04-.047.039-.048.039-.05.039-.051.039-.052.038-.053.038-.055.038-.055.038-.058.037-.058.037-.06.037-.06.036-.062.036-.064.036-.064.036-.066.035-.067.035-.068.035-.069.035-.07.034-.071.034-.073.033-.074.033-.15.066-.155.064-.16.063-.163.061-.168.06-.172.059-.175.057-.18.056-.183.054-.187.053-.191.051-.194.05-.198.048-.201.046-.205.045-.208.043-.211.041-.214.04-.217.038-.22.036-.223.034-.225.032-.229.031-.231.028-.233.027-.236.024-.239.023-.241.02-.242.019-.246.016-.247.015-.249.012-.251.01-.253.008-.255.005-.256.004-.258.001-.258-.001-.256-.004-.255-.005-.253-.008-.251-.01-.249-.012-.247-.015-.245-.016-.243-.019-.241-.02-.238-.023-.236-.024-.234-.027-.231-.028-.228-.031-.226-.032-.223-.034-.22-.036-.217-.038-.214-.04-.211-.041-.208-.043-.204-.045-.201-.046-.198-.048-.195-.05-.19-.051-.187-.053-.184-.054-.179-.056-.176-.057-.172-.059-.167-.06-.164-.061-.159-.063-.155-.064-.151-.066-.074-.033-.072-.033-.072-.034-.07-.034-.069-.035-.068-.035-.067-.035-.066-.035-.064-.036-.063-.036-.062-.036-.061-.036-.06-.037-.058-.037-.057-.037-.056-.038-.055-.038-.053-.038-.052-.038-.051-.039-.049-.039-.049-.039-.046-.039-.046-.04-.044-.04-.043-.04-.041-.04-.04-.041-.039-.041-.037-.041-.036-.041-.034-.041-.033-.042-.032-.042-.03-.042-.029-.042-.027-.042-.026-.043-.024-.043-.023-.043-.021-.043-.02-.043-.018-.044-.017-.043-.015-.044-.013-.044-.012-.044-.011-.045-.009-.044-.007-.045-.006-.045-.004-.045-.002-.045-.001-.045v-17l.001-.045.002-.045.004-.045.006-.045.007-.045.009-.044.011-.045.012-.044.013-.044.015-.044.017-.043.018-.044.02-.043.021-.043.023-.043.024-.043.026-.043.027-.042.029-.042.03-.042.032-.042.033-.042.034-.041.036-.041.037-.041.039-.041.04-.041.041-.04.043-.04.044-.04.046-.04.046-.039.049-.039.049-.039.051-.039.052-.038.053-.038.055-.038.056-.038.057-.037.058-.037.06-.037.061-.036.062-.036.063-.036.064-.036.066-.035.067-.035.068-.035.069-.035.07-.034.072-.034.072-.033.074-.033.151-.066.155-.064.159-.063.164-.061.167-.06.172-.059.176-.057.179-.056.184-.054.187-.053.19-.051.195-.05.198-.048.201-.046.204-.045.208-.043.211-.041.214-.04.217-.038.22-.036.223-.034.226-.032.228-.031.231-.028.234-.027.236-.024.238-.023.241-.02.243-.019.245-.016.247-.015.249-.012.251-.01.253-.008.255-.005.256-.004.258-.001.258.001zm-9.258 20.499v.01l.001.021.003.021.004.022.005.021.006.022.007.022.009.023.01.022.011.023.012.023.013.023.015.023.016.024.017.023.018.024.019.024.021.024.022.025.023.024.024.025.052.049.056.05.061.051.066.051.07.051.075.051.079.052.084.052.088.052.092.052.097.052.102.051.105.052.11.052.114.051.119.051.123.051.127.05.131.05.135.05.139.048.144.049.147.047.152.047.155.047.16.045.163.045.167.043.171.043.176.041.178.041.183.039.187.039.19.037.194.035.197.035.202.033.204.031.209.03.212.029.216.027.219.025.222.024.226.021.23.02.233.018.236.016.24.015.243.012.246.01.249.008.253.005.256.004.259.001.26-.001.257-.004.254-.005.25-.008.247-.011.244-.012.241-.014.237-.016.233-.018.231-.021.226-.021.224-.024.22-.026.216-.027.212-.028.21-.031.205-.031.202-.034.198-.034.194-.036.191-.037.187-.039.183-.04.179-.04.175-.042.172-.043.168-.044.163-.045.16-.046.155-.046.152-.047.148-.048.143-.049.139-.049.136-.05.131-.05.126-.05.123-.051.118-.052.114-.051.11-.052.106-.052.101-.052.096-.052.092-.052.088-.053.083-.051.079-.052.074-.052.07-.051.065-.051.06-.051.056-.05.051-.05.023-.024.023-.025.021-.024.02-.024.019-.024.018-.024.017-.024.015-.023.014-.024.013-.023.012-.023.01-.023.01-.022.008-.022.006-.022.006-.022.004-.022.004-.021.001-.021.001-.021v-4.127l-.077.055-.08.053-.083.054-.085.053-.087.052-.09.052-.093.051-.095.05-.097.05-.1.049-.102.049-.105.048-.106.047-.109.047-.111.046-.114.045-.115.045-.118.044-.12.043-.122.042-.124.042-.126.041-.128.04-.13.04-.132.038-.134.038-.135.037-.138.037-.139.035-.142.035-.143.034-.144.033-.147.032-.148.031-.15.03-.151.03-.153.029-.154.027-.156.027-.158.026-.159.025-.161.024-.162.023-.163.022-.165.021-.166.02-.167.019-.169.018-.169.017-.171.016-.173.015-.173.014-.175.013-.175.012-.177.011-.178.01-.179.008-.179.008-.181.006-.182.005-.182.004-.184.003-.184.002h-.37l-.184-.002-.184-.003-.182-.004-.182-.005-.181-.006-.179-.008-.179-.008-.178-.01-.176-.011-.176-.012-.175-.013-.173-.014-.172-.015-.171-.016-.17-.017-.169-.018-.167-.019-.166-.02-.165-.021-.163-.022-.162-.023-.161-.024-.159-.025-.157-.026-.156-.027-.155-.027-.153-.029-.151-.03-.15-.03-.148-.031-.146-.032-.145-.033-.143-.034-.141-.035-.14-.035-.137-.037-.136-.037-.134-.038-.132-.038-.13-.04-.128-.04-.126-.041-.124-.042-.122-.042-.12-.044-.117-.043-.116-.045-.113-.045-.112-.046-.109-.047-.106-.047-.105-.048-.102-.049-.1-.049-.097-.05-.095-.05-.093-.052-.09-.051-.087-.052-.085-.053-.083-.054-.08-.054-.077-.054v4.127zm0-5.654v.011l.001.021.003.021.004.021.005.022.006.022.007.022.009.022.01.022.011.023.012.023.013.023.015.024.016.023.017.024.018.024.019.024.021.024.022.024.023.025.024.024.052.05.056.05.061.05.066.051.07.051.075.052.079.051.084.052.088.052.092.052.097.052.102.052.105.052.11.051.114.051.119.052.123.05.127.051.131.05.135.049.139.049.144.048.147.048.152.047.155.046.16.045.163.045.167.044.171.042.176.042.178.04.183.04.187.038.19.037.194.036.197.034.202.033.204.032.209.03.212.028.216.027.219.025.222.024.226.022.23.02.233.018.236.016.24.014.243.012.246.01.249.008.253.006.256.003.259.001.26-.001.257-.003.254-.006.25-.008.247-.01.244-.012.241-.015.237-.016.233-.018.231-.02.226-.022.224-.024.22-.025.216-.027.212-.029.21-.03.205-.032.202-.033.198-.035.194-.036.191-.037.187-.039.183-.039.179-.041.175-.042.172-.043.168-.044.163-.045.16-.045.155-.047.152-.047.148-.048.143-.048.139-.05.136-.049.131-.05.126-.051.123-.051.118-.051.114-.052.11-.052.106-.052.101-.052.096-.052.092-.052.088-.052.083-.052.079-.052.074-.051.07-.052.065-.051.06-.05.056-.051.051-.049.023-.025.023-.024.021-.025.02-.024.019-.024.018-.024.017-.024.015-.023.014-.023.013-.024.012-.022.01-.023.01-.023.008-.022.006-.022.006-.022.004-.021.004-.022.001-.021.001-.021v-4.139l-.077.054-.08.054-.083.054-.085.052-.087.053-.09.051-.093.051-.095.051-.097.05-.1.049-.102.049-.105.048-.106.047-.109.047-.111.046-.114.045-.115.044-.118.044-.12.044-.122.042-.124.042-.126.041-.128.04-.13.039-.132.039-.134.038-.135.037-.138.036-.139.036-.142.035-.143.033-.144.033-.147.033-.148.031-.15.03-.151.03-.153.028-.154.028-.156.027-.158.026-.159.025-.161.024-.162.023-.163.022-.165.021-.166.02-.167.019-.169.018-.169.017-.171.016-.173.015-.173.014-.175.013-.175.012-.177.011-.178.009-.179.009-.179.007-.181.007-.182.005-.182.004-.184.003-.184.002h-.37l-.184-.002-.184-.003-.182-.004-.182-.005-.181-.007-.179-.007-.179-.009-.178-.009-.176-.011-.176-.012-.175-.013-.173-.014-.172-.015-.171-.016-.17-.017-.169-.018-.167-.019-.166-.02-.165-.021-.163-.022-.162-.023-.161-.024-.159-.025-.157-.026-.156-.027-.155-.028-.153-.028-.151-.03-.15-.03-.148-.031-.146-.033-.145-.033-.143-.033-.141-.035-.14-.036-.137-.036-.136-.037-.134-.038-.132-.039-.13-.039-.128-.04-.126-.041-.124-.042-.122-.043-.12-.043-.117-.044-.116-.044-.113-.046-.112-.046-.109-.046-.106-.047-.105-.048-.102-.049-.1-.049-.097-.05-.095-.051-.093-.051-.09-.051-.087-.053-.085-.052-.083-.054-.08-.054-.077-.054v4.139zm0-5.666v.011l.001.02.003.022.004.021.005.022.006.021.007.022.009.023.01.022.011.023.012.023.013.023.015.023.016.024.017.024.018.023.019.024.021.025.022.024.023.024.024.025.052.05.056.05.061.05.066.051.07.051.075.052.079.051.084.052.088.052.092.052.097.052.102.052.105.051.11.052.114.051.119.051.123.051.127.05.131.05.135.05.139.049.144.048.147.048.152.047.155.046.16.045.163.045.167.043.171.043.176.042.178.04.183.04.187.038.19.037.194.036.197.034.202.033.204.032.209.03.212.028.216.027.219.025.222.024.226.021.23.02.233.018.236.017.24.014.243.012.246.01.249.008.253.006.256.003.259.001.26-.001.257-.003.254-.006.25-.008.247-.01.244-.013.241-.014.237-.016.233-.018.231-.02.226-.022.224-.024.22-.025.216-.027.212-.029.21-.03.205-.032.202-.033.198-.035.194-.036.191-.037.187-.039.183-.039.179-.041.175-.042.172-.043.168-.044.163-.045.16-.045.155-.047.152-.047.148-.048.143-.049.139-.049.136-.049.131-.051.126-.05.123-.051.118-.052.114-.051.11-.052.106-.052.101-.052.096-.052.092-.052.088-.052.083-.052.079-.052.074-.052.07-.051.065-.051.06-.051.056-.05.051-.049.023-.025.023-.025.021-.024.02-.024.019-.024.018-.024.017-.024.015-.023.014-.024.013-.023.012-.023.01-.022.01-.023.008-.022.006-.022.006-.022.004-.022.004-.021.001-.021.001-.021v-4.153l-.077.054-.08.054-.083.053-.085.053-.087.053-.09.051-.093.051-.095.051-.097.05-.1.049-.102.048-.105.048-.106.048-.109.046-.111.046-.114.046-.115.044-.118.044-.12.043-.122.043-.124.042-.126.041-.128.04-.13.039-.132.039-.134.038-.135.037-.138.036-.139.036-.142.034-.143.034-.144.033-.147.032-.148.032-.15.03-.151.03-.153.028-.154.028-.156.027-.158.026-.159.024-.161.024-.162.023-.163.023-.165.021-.166.02-.167.019-.169.018-.169.017-.171.016-.173.015-.173.014-.175.013-.175.012-.177.01-.178.01-.179.009-.179.007-.181.006-.182.006-.182.004-.184.003-.184.001-.185.001-.185-.001-.184-.001-.184-.003-.182-.004-.182-.006-.181-.006-.179-.007-.179-.009-.178-.01-.176-.01-.176-.012-.175-.013-.173-.014-.172-.015-.171-.016-.17-.017-.169-.018-.167-.019-.166-.02-.165-.021-.163-.023-.162-.023-.161-.024-.159-.024-.157-.026-.156-.027-.155-.028-.153-.028-.151-.03-.15-.03-.148-.032-.146-.032-.145-.033-.143-.034-.141-.034-.14-.036-.137-.036-.136-.037-.134-.038-.132-.039-.13-.039-.128-.041-.126-.041-.124-.041-.122-.043-.12-.043-.117-.044-.116-.044-.113-.046-.112-.046-.109-.046-.106-.048-.105-.048-.102-.048-.1-.05-.097-.049-.095-.051-.093-.051-.09-.052-.087-.052-.085-.053-.083-.053-.08-.054-.077-.054v4.153zm8.74-8.179l-.257.004-.254.005-.25.008-.247.011-.244.012-.241.014-.237.016-.233.018-.231.021-.226.022-.224.023-.22.026-.216.027-.212.028-.21.031-.205.032-.202.033-.198.034-.194.036-.191.038-.187.038-.183.04-.179.041-.175.042-.172.043-.168.043-.163.045-.16.046-.155.046-.152.048-.148.048-.143.048-.139.049-.136.05-.131.05-.126.051-.123.051-.118.051-.114.052-.11.052-.106.052-.101.052-.096.052-.092.052-.088.052-.083.052-.079.052-.074.051-.07.052-.065.051-.06.05-.056.05-.051.05-.023.025-.023.024-.021.024-.02.025-.019.024-.018.024-.017.023-.015.024-.014.023-.013.023-.012.023-.01.023-.01.022-.008.022-.006.023-.006.021-.004.022-.004.021-.001.021-.001.021.001.021.001.021.004.021.004.022.006.021.006.023.008.022.01.022.01.023.012.023.013.023.014.023.015.024.017.023.018.024.019.024.02.025.021.024.023.024.023.025.051.05.056.05.06.05.065.051.07.052.074.051.079.052.083.052.088.052.092.052.096.052.101.052.106.052.11.052.114.052.118.051.123.051.126.051.131.05.136.05.139.049.143.048.148.048.152.048.155.046.16.046.163.045.168.043.172.043.175.042.179.041.183.04.187.038.191.038.194.036.198.034.202.033.205.032.21.031.212.028.216.027.22.026.224.023.226.022.231.021.233.018.237.016.241.014.244.012.247.011.25.008.254.005.257.004.26.001.26-.001.257-.004.254-.005.25-.008.247-.011.244-.012.241-.014.237-.016.233-.018.231-.021.226-.022.224-.023.22-.026.216-.027.212-.028.21-.031.205-.032.202-.033.198-.034.194-.036.191-.038.187-.038.183-.04.179-.041.175-.042.172-.043.168-.043.163-.045.16-.046.155-.046.152-.048.148-.048.143-.048.139-.049.136-.05.131-.05.126-.051.123-.051.118-.051.114-.052.11-.052.106-.052.101-.052.096-.052.092-.052.088-.052.083-.052.079-.052.074-.051.07-.052.065-.051.06-.05.056-.05.051-.05.023-.025.023-.024.021-.024.02-.025.019-.024.018-.024.017-.023.015-.024.014-.023.013-.023.012-.023.01-.023.01-.022.008-.022.006-.023.006-.021.004-.022.004-.021.001-.021.001-.021-.001-.021-.001-.021-.004-.021-.004-.022-.006-.021-.006-.023-.008-.022-.01-.022-.01-.023-.012-.023-.013-.023-.014-.023-.015-.024-.017-.023-.018-.024-.019-.024-.02-.025-.021-.024-.023-.024-.023-.025-.051-.05-.056-.05-.06-.05-.065-.051-.07-.052-.074-.051-.079-.052-.083-.052-.088-.052-.092-.052-.096-.052-.101-.052-.106-.052-.11-.052-.114-.052-.118-.051-.123-.051-.126-.051-.131-.05-.136-.05-.139-.049-.143-.048-.148-.048-.152-.048-.155-.046-.16-.046-.163-.045-.168-.043-.172-.043-.175-.042-.179-.041-.183-.04-.187-.038-.191-.038-.194-.036-.198-.034-.202-.033-.205-.032-.21-.031-.212-.028-.216-.027-.22-.026-.224-.023-.226-.022-.231-.021-.233-.018-.237-.016-.241-.014-.244-.012-.247-.011-.25-.008-.254-.005-.257-.004-.26-.001-.26.001z")},qK=function(t){t.append("defs").append("symbol").attr("id","computer").attr("width","24").attr("height","24").append("path").attr("transform","scale(.5)").attr("d","M2 2v13h20v-13h-20zm18 11h-16v-9h16v9zm-10.228 6l.466-1h3.524l.467 1h-4.457zm14.228 3h-24l2-6h2.104l-1.33 4h18.45l-1.297-4h2.073l2 6zm-5-10h-14v-7h14v7z")},VK=function(t){t.append("defs").append("symbol").attr("id","clock").attr("width","24").attr("height","24").append("path").attr("transform","scale(.5)").attr("d","M12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm5.848 12.459c.202.038.202.333.001.372-1.907.361-6.045 1.111-6.547 1.111-.719 0-1.301-.582-1.301-1.301 0-.512.77-5.447 1.125-7.445.034-.192.312-.181.343.014l.985 6.238 5.394 1.011z")},zK=function(t){t.append("defs").append("marker").attr("id","arrowhead").attr("refX",9).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",12).attr("markerHeight",12).attr("orient","auto").append("path").attr("d","M 0 0 L 10 5 L 0 10 z")},YK=function(t){t.append("defs").append("marker").attr("id","arrowend").attr("refX",1).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",12).attr("markerHeight",12).attr("orient","auto").append("path").attr("d","M 10 0 L 0 5 L 10 10 z")},UK=function(t){t.append("defs").append("marker").attr("id","filled-head").attr("refX",18).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L14,7 L9,1 Z")},WK=function(t){t.append("defs").append("marker").attr("id","sequencenumber").attr("refX",15).attr("refY",15).attr("markerWidth",60).attr("markerHeight",40).attr("orient","auto").append("circle").attr("cx",15).attr("cy",15).attr("r",6)},HK=function(t){const r=t.append("defs").append("marker").attr("id","crosshead").attr("markerWidth",15).attr("markerHeight",8).attr("orient","auto").attr("refX",16).attr("refY",4);r.append("path").attr("fill","black").attr("stroke","#000000").style("stroke-dasharray","0, 0").attr("stroke-width","1px").attr("d","M 9,2 V 6 L16,4 Z"),r.append("path").attr("fill","none").attr("stroke","#000000").style("stroke-dasharray","0, 0").attr("stroke-width","1px").attr("d","M 0,1 L 6,7 M 6,1 L 0,7")},GK=function(){return{x:0,y:0,fill:void 0,anchor:void 0,style:"#666",width:void 0,height:void 0,textMargin:0,rx:0,ry:0,tspan:!0,valign:void 0}},Qw=function(){return{x:0,y:0,fill:"#EDF2AE",stroke:"#666",width:100,anchor:"start",height:100,rx:0,ry:0}},jK=(t,e)=>({fontFamily:t[e+"FontFamily"],fontSize:t[e+"FontSize"],fontWeight:t[e+"FontWeight"]}),sa=function(){function t(i,a,s,o,l,u,h){const d=a.append("text").attr("x",s+l/2).attr("y",o+u/2+5).style("text-anchor","middle").text(i);n(d,h)}function e(i,a,s,o,l,u,h,d){const{fontSize:f,fontFamily:p,fontWeight:m}=d,_=i.split(pe.lineBreakRegex);for(let y=0;y<_.length;y++){const b=y*f-f*(_.length-1)/2,x=a.append("text").attr("x",s+l/2).attr("y",o).style("text-anchor","middle").attr("dominant-baseline","middle").style("font-size",f).style("font-weight",m).style("font-family",p);x.append("tspan").attr("dy",b).text(_[y]).attr("alignment-baseline","mathematical"),n(x,h)}}function r(i,a,s,o,l,u,h,d){const f=a.append("switch"),m=f.append("foreignObject").attr("x",s).attr("y",o).attr("width",l).attr("height",u).append("xhtml:div").style("display","table").style("height","100%").style("width","100%");m.append("div").style("display","table-cell").style("text-align","center").style("vertical-align","middle").text(i),e(i,f,s,o,l,u,h,d),n(m,h)}function n(i,a){for(const s in a)a.hasOwnProperty(s)&&i.attr(s,a[s])}return function(i){return i.textPlacement==="fo"?r:i.textPlacement==="old"?t:e}}(),Oi={drawRect:_g,drawText:Zw,drawLabel:BK,drawBoundary:OK,drawC4Shape:FK,drawRels:DK,drawImage:Kw,drawEmbeddedImage:NK,insertArrowHead:zK,insertArrowEnd:YK,insertArrowFilledHead:UK,insertDynamicNumber:WK,insertArrowCrossHead:HK,insertDatabaseIcon:PK,insertComputerIcon:qK,insertClockIcon:VK,getTextObj:GK,getNoteRect:Qw,sanitizeUrl:ki};let y1=0,m1=0,Jw=4,vg=2;qc.yy=Xw;let Zt={};class t9{constructor(e){this.name="",this.data={},this.data.startx=void 0,this.data.stopx=void 0,this.data.starty=void 0,this.data.stopy=void 0,this.data.widthLimit=void 0,this.nextData={},this.nextData.startx=void 0,this.nextData.stopx=void 0,this.nextData.starty=void 0,this.nextData.stopy=void 0,this.nextData.cnt=0,xg(e.db.getConfig())}setData(e,r,n,i){this.nextData.startx=this.data.startx=e,this.nextData.stopx=this.data.stopx=r,this.nextData.starty=this.data.starty=n,this.nextData.stopy=this.data.stopy=i}updateVal(e,r,n,i){typeof e[r]>"u"?e[r]=n:e[r]=i(n,e[r])}insert(e){this.nextData.cnt=this.nextData.cnt+1;let r=this.nextData.startx===this.nextData.stopx?this.nextData.stopx+e.margin:this.nextData.stopx+e.margin*2,n=r+e.width,i=this.nextData.starty+e.margin*2,a=i+e.height;(r>=this.data.widthLimit||n>=this.data.widthLimit||this.nextData.cnt>Jw)&&(r=this.nextData.startx+e.margin+Zt.nextLinePaddingX,i=this.nextData.stopy+e.margin*2,this.nextData.stopx=n=r+e.width,this.nextData.starty=this.nextData.stopy,this.nextData.stopy=a=i+e.height,this.nextData.cnt=1),e.x=r,e.y=i,this.updateVal(this.data,"startx",r,Math.min),this.updateVal(this.data,"starty",i,Math.min),this.updateVal(this.data,"stopx",n,Math.max),this.updateVal(this.data,"stopy",a,Math.max),this.updateVal(this.nextData,"startx",r,Math.min),this.updateVal(this.nextData,"starty",i,Math.min),this.updateVal(this.nextData,"stopx",n,Math.max),this.updateVal(this.nextData,"stopy",a,Math.max)}init(e){this.name="",this.data={startx:void 0,stopx:void 0,starty:void 0,stopy:void 0,widthLimit:void 0},this.nextData={startx:void 0,stopx:void 0,starty:void 0,stopy:void 0,cnt:0},xg(e.db.getConfig())}bumpLastMargin(e){this.data.stopx+=e,this.data.stopy+=e}}const xg=function(t){fr(Zt,t),t.fontFamily&&(Zt.personFontFamily=Zt.systemFontFamily=Zt.messageFontFamily=t.fontFamily),t.fontSize&&(Zt.personFontSize=Zt.systemFontSize=Zt.messageFontSize=t.fontSize),t.fontWeight&&(Zt.personFontWeight=Zt.systemFontWeight=Zt.messageFontWeight=t.fontWeight)},zc=(t,e)=>({fontFamily:t[e+"FontFamily"],fontSize:t[e+"FontSize"],fontWeight:t[e+"FontWeight"]}),b1=t=>({fontFamily:t.boundaryFontFamily,fontSize:t.boundaryFontSize,fontWeight:t.boundaryFontWeight}),$K=t=>({fontFamily:t.messageFontFamily,fontSize:t.messageFontSize,fontWeight:t.messageFontWeight});function gi(t,e,r,n,i){if(!e[t].width)if(r)e[t].text=cw(e[t].text,i,n),e[t].textLines=e[t].text.split(pe.lineBreakRegex).length,e[t].width=i,e[t].height=eg(e[t].text,n);else{let a=e[t].text.split(pe.lineBreakRegex);e[t].textLines=a.length;let s=0;e[t].height=0,e[t].width=0;for(let o=0;o<a.length;o++)e[t].width=Math.max(Bi(a[o],n),e[t].width),s=eg(a[o],n),e[t].height=e[t].height+s}}const e9=function(t,e,r){e.x=r.data.startx,e.y=r.data.starty,e.width=r.data.stopx-r.data.startx,e.height=r.data.stopy-r.data.starty,e.label.y=Zt.c4ShapeMargin-35;let n=e.wrap&&Zt.wrap,i=b1(Zt);i.fontSize=i.fontSize+2,i.fontWeight="bold";let a=Bi(e.label.text,i);gi("label",e,n,i,a),Oi.drawBoundary(t,e,Zt)},r9=function(t,e,r,n){let i=0;for(let a=0;a<n.length;a++){i=0;const s=r[n[a]];let o=zc(Zt,s.typeC4Shape.text);switch(o.fontSize=o.fontSize-2,s.typeC4Shape.width=Bi("<<"+s.typeC4Shape.text+">>",o),s.typeC4Shape.height=o.fontSize+2,s.typeC4Shape.Y=Zt.c4ShapePadding,i=s.typeC4Shape.Y+s.typeC4Shape.height-4,s.image={width:0,height:0,Y:0},s.typeC4Shape.text){case"person":case"external_person":s.image.width=48,s.image.height=48,s.image.Y=i,i=s.image.Y+s.image.height;break}s.sprite&&(s.image.width=48,s.image.height=48,s.image.Y=i,i=s.image.Y+s.image.height);let l=s.wrap&&Zt.wrap,u=Zt.width-Zt.c4ShapePadding*2,h=zc(Zt,s.typeC4Shape.text);if(h.fontSize=h.fontSize+2,h.fontWeight="bold",gi("label",s,l,h,u),s.label.Y=i+8,i=s.label.Y+s.label.height,s.type&&s.type.text!==""){s.type.text="["+s.type.text+"]";let p=zc(Zt,s.typeC4Shape.text);gi("type",s,l,p,u),s.type.Y=i+5,i=s.type.Y+s.type.height}else if(s.techn&&s.techn.text!==""){s.techn.text="["+s.techn.text+"]";let p=zc(Zt,s.techn.text);gi("techn",s,l,p,u),s.techn.Y=i+5,i=s.techn.Y+s.techn.height}let d=i,f=s.label.width;if(s.descr&&s.descr.text!==""){let p=zc(Zt,s.typeC4Shape.text);gi("descr",s,l,p,u),s.descr.Y=i+20,i=s.descr.Y+s.descr.height,f=Math.max(s.label.width,s.descr.width),d=i-s.descr.textLines*5}f=f+Zt.c4ShapePadding,s.width=Math.max(s.width||Zt.width,f,Zt.width),s.height=Math.max(s.height||Zt.height,d,Zt.height),s.margin=s.margin||Zt.c4ShapeMargin,t.insert(s),Oi.drawC4Shape(e,s,Zt)}t.bumpLastMargin(Zt.c4ShapeMargin)};class Un{constructor(e,r){this.x=e,this.y=r}}let n9=function(t,e){let r=t.x,n=t.y,i=e.x,a=e.y,s=r+t.width/2,o=n+t.height/2,l=Math.abs(r-i),u=Math.abs(n-a),h=u/l,d=t.height/t.width,f=null;return n==a&&r<i?f=new Un(r+t.width,o):n==a&&r>i?f=new Un(r,o):r==i&&n<a?f=new Un(s,n+t.height):r==i&&n>a&&(f=new Un(s,n)),r>i&&n<a?d>=h?f=new Un(r,o+h*t.width/2):f=new Un(s-l/u*t.height/2,n+t.height):r<i&&n<a?d>=h?f=new Un(r+t.width,o+h*t.width/2):f=new Un(s+l/u*t.height/2,n+t.height):r<i&&n>a?d>=h?f=new Un(r+t.width,o-h*t.width/2):f=new Un(s+t.height/2*l/u,n):r>i&&n>a&&(d>=h?f=new Un(r,o-t.width/2*h):f=new Un(s-t.height/2*l/u,n)),f},XK=function(t,e){let r={x:0,y:0};r.x=e.x+e.width/2,r.y=e.y+e.height/2;let n=n9(t,r);r.x=t.x+t.width/2,r.y=t.y+t.height/2;let i=n9(e,r);return{startPoint:n,endPoint:i}};const KK=function(t,e,r,n){let i=0;for(let a of e){i=i+1;let s=a.wrap&&Zt.wrap,o=$K(Zt);n.db.getC4Type()==="C4Dynamic"&&(a.label.text=i+": "+a.label.text);let u=Bi(a.label.text,o);gi("label",a,s,o,u),a.techn&&a.techn.text!==""&&(u=Bi(a.techn.text,o),gi("techn",a,s,o,u)),a.descr&&a.descr.text!==""&&(u=Bi(a.descr.text,o),gi("descr",a,s,o,u));let h=r(a.from),d=r(a.to),f=XK(h,d);a.startPoint=f.startPoint,a.endPoint=f.endPoint}Oi.drawRels(t,e,Zt)};function i9(t,e,r,n,i){let a=new t9(i);a.data.widthLimit=r.data.widthLimit/Math.min(vg,n.length);for(let s=0;s<n.length;s++){let o=n[s],l=0;o.image={width:0,height:0,Y:0},o.sprite&&(o.image.width=48,o.image.height=48,o.image.Y=l,l=o.image.Y+o.image.height);let u=o.wrap&&Zt.wrap,h=b1(Zt);if(h.fontSize=h.fontSize+2,h.fontWeight="bold",gi("label",o,u,h,a.data.widthLimit),o.label.Y=l+8,l=o.label.Y+o.label.height,o.type&&o.type.text!==""){o.type.text="["+o.type.text+"]";let m=b1(Zt);gi("type",o,u,m,a.data.widthLimit),o.type.Y=l+5,l=o.type.Y+o.type.height}if(o.descr&&o.descr.text!==""){let m=b1(Zt);m.fontSize=m.fontSize-2,gi("descr",o,u,m,a.data.widthLimit),o.descr.Y=l+20,l=o.descr.Y+o.descr.height}if(s==0||s%vg===0){let m=r.data.startx+Zt.diagramMarginX,_=r.data.stopy+Zt.diagramMarginY+l;a.setData(m,m,_,_)}else{let m=a.data.stopx!==a.data.startx?a.data.stopx+Zt.diagramMarginX:a.data.startx,_=a.data.starty;a.setData(m,m,_,_)}a.name=o.alias;let d=i.db.getC4ShapeArray(o.alias),f=i.db.getC4ShapeKeys(o.alias);f.length>0&&r9(a,t,d,f),e=o.alias;let p=i.db.getBoundarys(e);p.length>0&&i9(t,e,a,p,i),o.alias!=="global"&&e9(t,o,a),r.data.stopy=Math.max(a.data.stopy+Zt.c4ShapeMargin,r.data.stopy),r.data.stopx=Math.max(a.data.stopx+Zt.c4ShapeMargin,r.data.stopx),y1=Math.max(y1,r.data.stopx),m1=Math.max(m1,r.data.stopy)}}const a9={drawPersonOrSystemArray:r9,drawBoundary:e9,setConf:xg,draw:function(t,e,r,n){Zt=nt().c4;const i=nt().securityLevel;let a;i==="sandbox"&&(a=St("#i"+e));const s=St(i==="sandbox"?a.nodes()[0].contentDocument.body:"body");let o=n.db;n.db.setWrap(Zt.wrap),Jw=o.getC4ShapeInRow(),vg=o.getC4BoundaryInRow(),H.debug(`C:${JSON.stringify(Zt,null,2)}`);const l=i==="sandbox"?s.select(`[id="${e}"]`):St(`[id="${e}"]`);Oi.insertComputerIcon(l),Oi.insertDatabaseIcon(l),Oi.insertClockIcon(l);let u=new t9(n);u.setData(Zt.diagramMarginX,Zt.diagramMarginX,Zt.diagramMarginY,Zt.diagramMarginY),u.data.widthLimit=screen.availWidth,y1=Zt.diagramMarginX,m1=Zt.diagramMarginY;const h=n.db.getTitle();let d=n.db.getBoundarys("");i9(l,"",u,d,n),Oi.insertArrowHead(l),Oi.insertArrowEnd(l),Oi.insertArrowCrossHead(l),Oi.insertArrowFilledHead(l),KK(l,n.db.getRels(),n.db.getC4Shape,n),u.data.stopx=y1,u.data.stopy=m1;const f=u.data;let m=f.stopy-f.starty+2*Zt.diagramMarginY;const y=f.stopx-f.startx+2*Zt.diagramMarginX;h&&l.append("text").text(h).attr("x",(f.stopx-f.startx)/2-4*Zt.diagramMarginX).attr("y",f.starty+Zt.diagramMarginY),li(l,m,y,Zt.useMaxWidth);const b=h?60:0;l.attr("viewBox",f.startx-Zt.diagramMarginX+" -"+(Zt.diagramMarginY+b)+" "+y+" "+(m+b)),bn(qc.yy,l,e),H.debug("models:",f)}};var _1=function(){var t=function(Z,V,Q,q){for(Q=Q||{},q=Z.length;q--;Q[Z[q]]=V);return Q},e=[1,3],r=[1,7],n=[1,8],i=[1,9],a=[1,10],s=[1,13],o=[1,12],l=[1,16,25],u=[1,20],h=[1,31],d=[1,32],f=[1,33],p=[1,35],m=[1,38],_=[1,36],y=[1,37],b=[1,39],x=[1,40],k=[1,41],T=[1,42],C=[1,45],M=[1,46],S=[1,47],R=[1,48],A=[16,25],L=[1,62],v=[1,63],B=[1,64],w=[1,65],D=[1,66],N=[1,67],z=[1,68],X=[16,25,32,44,45,53,56,57,58,59,60,61,62,67,69],ct=[16,25,30,32,44,45,49,53,56,57,58,59,60,61,62,67,69,84,85,86,87],J=[5,8,9,10,11,16,19,23,25],Y=[53,84,85,86,87],$=[53,61,62,84,85,86,87],lt=[53,56,57,58,59,60,84,85,86,87],ut=[16,25,32],W=[1,100],tt={trace:function(){},yy:{},symbols_:{error:2,start:3,mermaidDoc:4,statments:5,direction:6,directive:7,direction_tb:8,direction_bt:9,direction_rl:10,direction_lr:11,graphConfig:12,openDirective:13,typeDirective:14,closeDirective:15,NEWLINE:16,":":17,argDirective:18,open_directive:19,type_directive:20,arg_directive:21,close_directive:22,CLASS_DIAGRAM:23,statements:24,EOF:25,statement:26,className:27,alphaNumToken:28,classLiteralName:29,GENERICTYPE:30,relationStatement:31,LABEL:32,classStatement:33,methodStatement:34,annotationStatement:35,clickStatement:36,cssClassStatement:37,acc_title:38,acc_title_value:39,acc_descr:40,acc_descr_value:41,acc_descr_multiline_value:42,CLASS:43,STYLE_SEPARATOR:44,STRUCT_START:45,members:46,STRUCT_STOP:47,ANNOTATION_START:48,ANNOTATION_END:49,MEMBER:50,SEPARATOR:51,relation:52,STR:53,relationType:54,lineType:55,AGGREGATION:56,EXTENSION:57,COMPOSITION:58,DEPENDENCY:59,LOLLIPOP:60,LINE:61,DOTTED_LINE:62,CALLBACK:63,LINK:64,LINK_TARGET:65,CLICK:66,CALLBACK_NAME:67,CALLBACK_ARGS:68,HREF:69,CSSCLASS:70,commentToken:71,textToken:72,graphCodeTokens:73,textNoTagsToken:74,TAGSTART:75,TAGEND:76,"==":77,"--":78,PCT:79,DEFAULT:80,SPACE:81,MINUS:82,keywords:83,UNICODE_TEXT:84,NUM:85,ALPHA:86,BQUOTE_STR:87,$accept:0,$end:1},terminals_:{2:"error",5:"statments",8:"direction_tb",9:"direction_bt",10:"direction_rl",11:"direction_lr",16:"NEWLINE",17:":",19:"open_directive",20:"type_directive",21:"arg_directive",22:"close_directive",23:"CLASS_DIAGRAM",25:"EOF",30:"GENERICTYPE",32:"LABEL",38:"acc_title",39:"acc_title_value",40:"acc_descr",41:"acc_descr_value",42:"acc_descr_multiline_value",43:"CLASS",44:"STYLE_SEPARATOR",45:"STRUCT_START",47:"STRUCT_STOP",48:"ANNOTATION_START",49:"ANNOTATION_END",50:"MEMBER",51:"SEPARATOR",53:"STR",56:"AGGREGATION",57:"EXTENSION",58:"COMPOSITION",59:"DEPENDENCY",60:"LOLLIPOP",61:"LINE",62:"DOTTED_LINE",63:"CALLBACK",64:"LINK",65:"LINK_TARGET",66:"CLICK",67:"CALLBACK_NAME",68:"CALLBACK_ARGS",69:"HREF",70:"CSSCLASS",73:"graphCodeTokens",75:"TAGSTART",76:"TAGEND",77:"==",78:"--",79:"PCT",80:"DEFAULT",81:"SPACE",82:"MINUS",83:"keywords",84:"UNICODE_TEXT",85:"NUM",86:"ALPHA",87:"BQUOTE_STR"},productions_:[0,[3,1],[3,1],[3,1],[3,2],[6,1],[6,1],[6,1],[6,1],[4,1],[7,4],[7,6],[13,1],[14,1],[18,1],[15,1],[12,4],[24,1],[24,2],[24,3],[27,1],[27,1],[27,2],[27,2],[27,2],[26,1],[26,2],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,2],[26,2],[26,1],[33,2],[33,4],[33,5],[33,7],[35,4],[46,1],[46,2],[34,1],[34,2],[34,1],[34,1],[31,3],[31,4],[31,4],[31,5],[52,3],[52,2],[52,2],[52,1],[54,1],[54,1],[54,1],[54,1],[54,1],[55,1],[55,1],[36,3],[36,4],[36,3],[36,4],[36,4],[36,5],[36,3],[36,4],[36,4],[36,5],[36,3],[36,4],[36,4],[36,5],[37,3],[71,1],[71,1],[72,1],[72,1],[72,1],[72,1],[72,1],[72,1],[72,1],[74,1],[74,1],[74,1],[74,1],[28,1],[28,1],[28,1],[29,1]],performAction:function(V,Q,q,U,F,j,P){var et=j.length-1;switch(F){case 5:U.setDirection("TB");break;case 6:U.setDirection("BT");break;case 7:U.setDirection("RL");break;case 8:U.setDirection("LR");break;case 12:U.parseDirective("%%{","open_directive");break;case 13:U.parseDirective(j[et],"type_directive");break;case 14:j[et]=j[et].trim().replace(/'/g,'"'),U.parseDirective(j[et],"arg_directive");break;case 15:U.parseDirective("}%%","close_directive","class");break;case 20:case 21:this.$=j[et];break;case 22:this.$=j[et-1]+j[et];break;case 23:case 24:this.$=j[et-1]+"~"+j[et];break;case 25:U.addRelation(j[et]);break;case 26:j[et-1].title=U.cleanupLabel(j[et]),U.addRelation(j[et-1]);break;case 34:this.$=j[et].trim(),U.setAccTitle(this.$);break;case 35:case 36:this.$=j[et].trim(),U.setAccDescription(this.$);break;case 37:U.addClass(j[et]);break;case 38:U.addClass(j[et-2]),U.setCssClass(j[et-2],j[et]);break;case 39:U.addClass(j[et-3]),U.addMembers(j[et-3],j[et-1]);break;case 40:U.addClass(j[et-5]),U.setCssClass(j[et-5],j[et-3]),U.addMembers(j[et-5],j[et-1]);break;case 41:U.addAnnotation(j[et],j[et-2]);break;case 42:this.$=[j[et]];break;case 43:j[et].push(j[et-1]),this.$=j[et];break;case 44:break;case 45:U.addMember(j[et-1],U.cleanupLabel(j[et]));break;case 46:break;case 47:break;case 48:this.$={id1:j[et-2],id2:j[et],relation:j[et-1],relationTitle1:"none",relationTitle2:"none"};break;case 49:this.$={id1:j[et-3],id2:j[et],relation:j[et-1],relationTitle1:j[et-2],relationTitle2:"none"};break;case 50:this.$={id1:j[et-3],id2:j[et],relation:j[et-2],relationTitle1:"none",relationTitle2:j[et-1]};break;case 51:this.$={id1:j[et-4],id2:j[et],relation:j[et-2],relationTitle1:j[et-3],relationTitle2:j[et-1]};break;case 52:this.$={type1:j[et-2],type2:j[et],lineType:j[et-1]};break;case 53:this.$={type1:"none",type2:j[et],lineType:j[et-1]};break;case 54:this.$={type1:j[et-1],type2:"none",lineType:j[et]};break;case 55:this.$={type1:"none",type2:"none",lineType:j[et]};break;case 56:this.$=U.relationType.AGGREGATION;break;case 57:this.$=U.relationType.EXTENSION;break;case 58:this.$=U.relationType.COMPOSITION;break;case 59:this.$=U.relationType.DEPENDENCY;break;case 60:this.$=U.relationType.LOLLIPOP;break;case 61:this.$=U.lineType.LINE;break;case 62:this.$=U.lineType.DOTTED_LINE;break;case 63:case 69:this.$=j[et-2],U.setClickEvent(j[et-1],j[et]);break;case 64:case 70:this.$=j[et-3],U.setClickEvent(j[et-2],j[et-1]),U.setTooltip(j[et-2],j[et]);break;case 65:case 73:this.$=j[et-2],U.setLink(j[et-1],j[et]);break;case 66:this.$=j[et-3],U.setLink(j[et-2],j[et-1],j[et]);break;case 67:case 75:this.$=j[et-3],U.setLink(j[et-2],j[et-1]),U.setTooltip(j[et-2],j[et]);break;case 68:case 76:this.$=j[et-4],U.setLink(j[et-3],j[et-2],j[et]),U.setTooltip(j[et-3],j[et-1]);break;case 71:this.$=j[et-3],U.setClickEvent(j[et-2],j[et-1],j[et]);break;case 72:this.$=j[et-4],U.setClickEvent(j[et-3],j[et-2],j[et-1]),U.setTooltip(j[et-3],j[et]);break;case 74:this.$=j[et-3],U.setLink(j[et-2],j[et-1],j[et]);break;case 77:U.setCssClass(j[et-1],j[et]);break}},table:[{3:1,4:2,5:e,6:4,7:5,8:r,9:n,10:i,11:a,12:6,13:11,19:s,23:o},{1:[3]},{1:[2,1]},{1:[2,2]},{1:[2,3]},{3:14,4:2,5:e,6:4,7:5,8:r,9:n,10:i,11:a,12:6,13:11,19:s,23:o},{1:[2,9]},t(l,[2,5]),t(l,[2,6]),t(l,[2,7]),t(l,[2,8]),{14:15,20:[1,16]},{16:[1,17]},{20:[2,12]},{1:[2,4]},{15:18,17:[1,19],22:u},t([17,22],[2,13]),{6:30,7:29,8:r,9:n,10:i,11:a,13:11,19:s,24:21,26:22,27:34,28:43,29:44,31:23,33:24,34:25,35:26,36:27,37:28,38:h,40:d,42:f,43:p,48:m,50:_,51:y,63:b,64:x,66:k,70:T,84:C,85:M,86:S,87:R},{16:[1,49]},{18:50,21:[1,51]},{16:[2,15]},{25:[1,52]},{16:[1,53],25:[2,17]},t(A,[2,25],{32:[1,54]}),t(A,[2,27]),t(A,[2,28]),t(A,[2,29]),t(A,[2,30]),t(A,[2,31]),t(A,[2,32]),t(A,[2,33]),{39:[1,55]},{41:[1,56]},t(A,[2,36]),t(A,[2,44],{52:57,54:60,55:61,32:[1,59],53:[1,58],56:L,57:v,58:B,59:w,60:D,61:N,62:z}),{27:69,28:43,29:44,84:C,85:M,86:S,87:R},t(A,[2,46]),t(A,[2,47]),{28:70,84:C,85:M,86:S},{27:71,28:43,29:44,84:C,85:M,86:S,87:R},{27:72,28:43,29:44,84:C,85:M,86:S,87:R},{27:73,28:43,29:44,84:C,85:M,86:S,87:R},{53:[1,74]},t(X,[2,20],{28:43,29:44,27:75,30:[1,76],84:C,85:M,86:S,87:R}),t(X,[2,21],{30:[1,77]}),t(ct,[2,91]),t(ct,[2,92]),t(ct,[2,93]),t([16,25,30,32,44,45,53,56,57,58,59,60,61,62,67,69],[2,94]),t(J,[2,10]),{15:78,22:u},{22:[2,14]},{1:[2,16]},{6:30,7:29,8:r,9:n,10:i,11:a,13:11,19:s,24:79,25:[2,18],26:22,27:34,28:43,29:44,31:23,33:24,34:25,35:26,36:27,37:28,38:h,40:d,42:f,43:p,48:m,50:_,51:y,63:b,64:x,66:k,70:T,84:C,85:M,86:S,87:R},t(A,[2,26]),t(A,[2,34]),t(A,[2,35]),{27:80,28:43,29:44,53:[1,81],84:C,85:M,86:S,87:R},{52:82,54:60,55:61,56:L,57:v,58:B,59:w,60:D,61:N,62:z},t(A,[2,45]),{55:83,61:N,62:z},t(Y,[2,55],{54:84,56:L,57:v,58:B,59:w,60:D}),t($,[2,56]),t($,[2,57]),t($,[2,58]),t($,[2,59]),t($,[2,60]),t(lt,[2,61]),t(lt,[2,62]),t(A,[2,37],{44:[1,85],45:[1,86]}),{49:[1,87]},{53:[1,88]},{53:[1,89]},{67:[1,90],69:[1,91]},{28:92,84:C,85:M,86:S},t(X,[2,22]),t(X,[2,23]),t(X,[2,24]),{16:[1,93]},{25:[2,19]},t(ut,[2,48]),{27:94,28:43,29:44,84:C,85:M,86:S,87:R},{27:95,28:43,29:44,53:[1,96],84:C,85:M,86:S,87:R},t(Y,[2,54],{54:97,56:L,57:v,58:B,59:w,60:D}),t(Y,[2,53]),{28:98,84:C,85:M,86:S},{46:99,50:W},{27:101,28:43,29:44,84:C,85:M,86:S,87:R},t(A,[2,63],{53:[1,102]}),t(A,[2,65],{53:[1,104],65:[1,103]}),t(A,[2,69],{53:[1,105],68:[1,106]}),t(A,[2,73],{53:[1,108],65:[1,107]}),t(A,[2,77]),t(J,[2,11]),t(ut,[2,50]),t(ut,[2,49]),{27:109,28:43,29:44,84:C,85:M,86:S,87:R},t(Y,[2,52]),t(A,[2,38],{45:[1,110]}),{47:[1,111]},{46:112,47:[2,42],50:W},t(A,[2,41]),t(A,[2,64]),t(A,[2,66]),t(A,[2,67],{65:[1,113]}),t(A,[2,70]),t(A,[2,71],{53:[1,114]}),t(A,[2,74]),t(A,[2,75],{65:[1,115]}),t(ut,[2,51]),{46:116,50:W},t(A,[2,39]),{47:[2,43]},t(A,[2,68]),t(A,[2,72]),t(A,[2,76]),{47:[1,117]},t(A,[2,40])],defaultActions:{2:[2,1],3:[2,2],4:[2,3],6:[2,9],13:[2,12],14:[2,4],20:[2,15],51:[2,14],52:[2,16],79:[2,19],112:[2,43]},parseError:function(V,Q){if(Q.recoverable)this.trace(V);else{var q=new Error(V);throw q.hash=Q,q}},parse:function(V){var Q=this,q=[0],U=[],F=[null],j=[],P=this.table,et="",at=0,It=0,Lt=2,Rt=1,Ct=j.slice.call(arguments,1),pt=Object.create(this.lexer),mt={yy:{}};for(var vt in this.yy)Object.prototype.hasOwnProperty.call(this.yy,vt)&&(mt.yy[vt]=this.yy[vt]);pt.setInput(V,mt.yy),mt.yy.lexer=pt,mt.yy.parser=this,typeof pt.yylloc>"u"&&(pt.yylloc={});var Tt=pt.yylloc;j.push(Tt);var ft=pt.options&&pt.options.ranges;typeof mt.yy.parseError=="function"?this.parseError=mt.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function le(){var Et;return Et=U.pop()||pt.lex()||Rt,typeof Et!="number"&&(Et instanceof Array&&(U=Et,Et=U.pop()),Et=Q.symbols_[Et]||Et),Et}for(var Dt,Gt,$t,Qt,we={},jt,Ft,zt,wt;;){if(Gt=q[q.length-1],this.defaultActions[Gt]?$t=this.defaultActions[Gt]:((Dt===null||typeof Dt>"u")&&(Dt=le()),$t=P[Gt]&&P[Gt][Dt]),typeof $t>"u"||!$t.length||!$t[0]){var bt="";wt=[];for(jt in P[Gt])this.terminals_[jt]&&jt>Lt&&wt.push("'"+this.terminals_[jt]+"'");pt.showPosition?bt="Parse error on line "+(at+1)+`: +`+pt.showPosition()+` +Expecting `+wt.join(", ")+", got '"+(this.terminals_[Dt]||Dt)+"'":bt="Parse error on line "+(at+1)+": Unexpected "+(Dt==Rt?"end of input":"'"+(this.terminals_[Dt]||Dt)+"'"),this.parseError(bt,{text:pt.match,token:this.terminals_[Dt]||Dt,line:pt.yylineno,loc:Tt,expected:wt})}if($t[0]instanceof Array&&$t.length>1)throw new Error("Parse Error: multiple actions possible at state: "+Gt+", token: "+Dt);switch($t[0]){case 1:q.push(Dt),F.push(pt.yytext),j.push(pt.yylloc),q.push($t[1]),Dt=null,It=pt.yyleng,et=pt.yytext,at=pt.yylineno,Tt=pt.yylloc;break;case 2:if(Ft=this.productions_[$t[1]][1],we.$=F[F.length-Ft],we._$={first_line:j[j.length-(Ft||1)].first_line,last_line:j[j.length-1].last_line,first_column:j[j.length-(Ft||1)].first_column,last_column:j[j.length-1].last_column},ft&&(we._$.range=[j[j.length-(Ft||1)].range[0],j[j.length-1].range[1]]),Qt=this.performAction.apply(we,[et,It,at,mt.yy,$t[1],F,j].concat(Ct)),typeof Qt<"u")return Qt;Ft&&(q=q.slice(0,-1*Ft*2),F=F.slice(0,-1*Ft),j=j.slice(0,-1*Ft)),q.push(this.productions_[$t[1]][0]),F.push(we.$),j.push(we._$),zt=P[q[q.length-2]][q[q.length-1]],q.push(zt);break;case 3:return!0}}return!0}},K=function(){var Z={EOF:1,parseError:function(Q,q){if(this.yy.parser)this.yy.parser.parseError(Q,q);else throw new Error(Q)},setInput:function(V,Q){return this.yy=Q||this.yy||{},this._input=V,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var V=this._input[0];this.yytext+=V,this.yyleng++,this.offset++,this.match+=V,this.matched+=V;var Q=V.match(/(?:\r\n?|\n).*/g);return Q?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),V},unput:function(V){var Q=V.length,q=V.split(/(?:\r\n?|\n)/g);this._input=V+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-Q),this.offset-=Q;var U=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),q.length-1&&(this.yylineno-=q.length-1);var F=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:q?(q.length===U.length?this.yylloc.first_column:0)+U[U.length-q.length].length-q[0].length:this.yylloc.first_column-Q},this.options.ranges&&(this.yylloc.range=[F[0],F[0]+this.yyleng-Q]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(V){this.unput(this.match.slice(V))},pastInput:function(){var V=this.matched.substr(0,this.matched.length-this.match.length);return(V.length>20?"...":"")+V.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var V=this.match;return V.length<20&&(V+=this._input.substr(0,20-V.length)),(V.substr(0,20)+(V.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var V=this.pastInput(),Q=new Array(V.length+1).join("-");return V+this.upcomingInput()+` +`+Q+"^"},test_match:function(V,Q){var q,U,F;if(this.options.backtrack_lexer&&(F={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(F.yylloc.range=this.yylloc.range.slice(0))),U=V[0].match(/(?:\r\n?|\n).*/g),U&&(this.yylineno+=U.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:U?U[U.length-1].length-U[U.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+V[0].length},this.yytext+=V[0],this.match+=V[0],this.matches=V,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(V[0].length),this.matched+=V[0],q=this.performAction.call(this,this.yy,this,Q,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),q)return q;if(this._backtrack){for(var j in F)this[j]=F[j];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var V,Q,q,U;this._more||(this.yytext="",this.match="");for(var F=this._currentRules(),j=0;j<F.length;j++)if(q=this._input.match(this.rules[F[j]]),q&&(!Q||q[0].length>Q[0].length)){if(Q=q,U=j,this.options.backtrack_lexer){if(V=this.test_match(q,F[j]),V!==!1)return V;if(this._backtrack){Q=!1;continue}else return!1}else if(!this.options.flex)break}return Q?(V=this.test_match(Q,F[U]),V!==!1?V:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var Q=this.next();return Q||this.lex()},begin:function(Q){this.conditionStack.push(Q)},popState:function(){var Q=this.conditionStack.length-1;return Q>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(Q){return Q=this.conditionStack.length-1-Math.abs(Q||0),Q>=0?this.conditionStack[Q]:"INITIAL"},pushState:function(Q){this.begin(Q)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(Q,q,U,F){switch(U){case 0:return this.begin("open_directive"),19;case 1:return 8;case 2:return 9;case 3:return 10;case 4:return 11;case 5:return this.begin("type_directive"),20;case 6:return this.popState(),this.begin("arg_directive"),17;case 7:return this.popState(),this.popState(),22;case 8:return 21;case 9:break;case 10:break;case 11:return this.begin("acc_title"),38;case 12:return this.popState(),"acc_title_value";case 13:return this.begin("acc_descr"),40;case 14:return this.popState(),"acc_descr_value";case 15:this.begin("acc_descr_multiline");break;case 16:this.popState();break;case 17:return"acc_descr_multiline_value";case 18:return 16;case 19:break;case 20:return 23;case 21:return 23;case 22:return this.begin("struct"),45;case 23:return"EDGE_STATE";case 24:return"EOF_IN_STRUCT";case 25:return"OPEN_IN_STRUCT";case 26:return this.popState(),47;case 27:break;case 28:return"MEMBER";case 29:return 43;case 30:return 70;case 31:return 63;case 32:return 64;case 33:return 66;case 34:return 48;case 35:return 49;case 36:this.begin("generic");break;case 37:this.popState();break;case 38:return"GENERICTYPE";case 39:this.begin("string");break;case 40:this.popState();break;case 41:return"STR";case 42:this.begin("bqstring");break;case 43:this.popState();break;case 44:return"BQUOTE_STR";case 45:this.begin("href");break;case 46:this.popState();break;case 47:return 69;case 48:this.begin("callback_name");break;case 49:this.popState();break;case 50:this.popState(),this.begin("callback_args");break;case 51:return 67;case 52:this.popState();break;case 53:return 68;case 54:return 65;case 55:return 65;case 56:return 65;case 57:return 65;case 58:return 57;case 59:return 57;case 60:return 59;case 61:return 59;case 62:return 58;case 63:return 56;case 64:return 60;case 65:return 61;case 66:return 62;case 67:return 32;case 68:return 44;case 69:return 82;case 70:return"DOT";case 71:return"PLUS";case 72:return 79;case 73:return"EQUALS";case 74:return"EQUALS";case 75:return 86;case 76:return"PUNCTUATION";case 77:return 85;case 78:return 84;case 79:return 81;case 80:return 25}},rules:[/^(?:%%\{)/,/^(?:.*direction\s+TB[^\n]*)/,/^(?:.*direction\s+BT[^\n]*)/,/^(?:.*direction\s+RL[^\n]*)/,/^(?:.*direction\s+LR[^\n]*)/,/^(?:((?:(?!\}%%)[^:.])*))/,/^(?::)/,/^(?:\}%%)/,/^(?:((?:(?!\}%%).|\n)*))/,/^(?:%%(?!\{)*[^\n]*(\r?\n?)+)/,/^(?:%%[^\n]*(\r?\n)*)/,/^(?:accTitle\s*:\s*)/,/^(?:(?!\n||)*[^\n]*)/,/^(?:accDescr\s*:\s*)/,/^(?:(?!\n||)*[^\n]*)/,/^(?:accDescr\s*\{\s*)/,/^(?:[\}])/,/^(?:[^\}]*)/,/^(?:\s*(\r?\n)+)/,/^(?:\s+)/,/^(?:classDiagram-v2\b)/,/^(?:classDiagram\b)/,/^(?:[{])/,/^(?:\[\*\])/,/^(?:$)/,/^(?:[{])/,/^(?:[}])/,/^(?:[\n])/,/^(?:[^{}\n]*)/,/^(?:class\b)/,/^(?:cssClass\b)/,/^(?:callback\b)/,/^(?:link\b)/,/^(?:click\b)/,/^(?:<<)/,/^(?:>>)/,/^(?:[~])/,/^(?:[~])/,/^(?:[^~]*)/,/^(?:["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:[`])/,/^(?:[`])/,/^(?:[^`]+)/,/^(?:href[\s]+["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:call[\s]+)/,/^(?:\([\s]*\))/,/^(?:\()/,/^(?:[^(]*)/,/^(?:\))/,/^(?:[^)]*)/,/^(?:_self\b)/,/^(?:_blank\b)/,/^(?:_parent\b)/,/^(?:_top\b)/,/^(?:\s*<\|)/,/^(?:\s*\|>)/,/^(?:\s*>)/,/^(?:\s*<)/,/^(?:\s*\*)/,/^(?:\s*o\b)/,/^(?:\s*\(\))/,/^(?:--)/,/^(?:\.\.)/,/^(?::{1}[^:\n;]+)/,/^(?::{3})/,/^(?:-)/,/^(?:\.)/,/^(?:\+)/,/^(?:%)/,/^(?:=)/,/^(?:=)/,/^(?:\w+)/,/^(?:[!"#$%&'*+,-.`?\\/])/,/^(?:[0-9]+)/,/^(?:[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|[\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA]|[\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE]|[\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA]|[\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0]|[\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977]|[\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2]|[\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A]|[\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39]|[\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8]|[\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C]|[\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C]|[\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99]|[\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0]|[\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D]|[\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3]|[\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10]|[\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1]|[\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81]|[\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3]|[\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6]|[\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A]|[\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081]|[\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D]|[\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0]|[\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310]|[\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C]|[\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711]|[\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7]|[\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C]|[\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16]|[\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF]|[\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC]|[\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D]|[\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D]|[\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3]|[\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F]|[\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128]|[\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184]|[\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3]|[\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6]|[\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE]|[\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C]|[\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D]|[\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC]|[\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B]|[\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788]|[\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805]|[\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB]|[\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28]|[\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5]|[\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4]|[\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E]|[\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D]|[\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36]|[\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D]|[\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC]|[\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF]|[\uFFD2-\uFFD7\uFFDA-\uFFDC])/,/^(?:\s)/,/^(?:$)/],conditions:{acc_descr_multiline:{rules:[16,17],inclusive:!1},acc_descr:{rules:[14],inclusive:!1},acc_title:{rules:[12],inclusive:!1},arg_directive:{rules:[7,8],inclusive:!1},type_directive:{rules:[6,7],inclusive:!1},open_directive:{rules:[5],inclusive:!1},callback_args:{rules:[52,53],inclusive:!1},callback_name:{rules:[49,50,51],inclusive:!1},href:{rules:[46,47],inclusive:!1},struct:{rules:[23,24,25,26,27,28],inclusive:!1},generic:{rules:[37,38],inclusive:!1},bqstring:{rules:[43,44],inclusive:!1},string:{rules:[40,41],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,9,10,11,13,15,18,19,20,21,22,23,29,30,31,32,33,34,35,36,39,42,45,48,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80],inclusive:!0}}};return Z}();tt.lexer=K;function it(){this.yy={}}return it.prototype=tt,tt.Parser=it,new it}();_1.parser=_1;const ZK=(t,e)=>{var r;return((r=e==null?void 0:e.class)==null?void 0:r.defaultRenderer)==="dagre-wrapper"?!1:t.match(/^\s*classDiagram/)!==null},QK=(t,e)=>{var r;return t.match(/^\s*classDiagram/)!==null&&((r=e==null?void 0:e.class)==null?void 0:r.defaultRenderer)==="dagre-wrapper"?!0:t.match(/^\s*classDiagram-v2/)!==null},kg="classid-";let wg=[],lr={},s9=0,Yc=[];const Uc=t=>pe.sanitizeText(t,nt()),JK=function(t,e,r){Xe.parseDirective(this,t,e,r)},Wc=function(t){let e="",r=t;if(t.indexOf("~")>0){let n=t.split("~");r=n[0],e=pe.sanitizeText(n[1],nt())}return{className:r,type:e}},Tg=function(t){let e=Wc(t);typeof lr[e.className]<"u"||(lr[e.className]={id:e.className,type:e.type,cssClasses:[],methods:[],members:[],annotations:[],domId:kg+e.className+"-"+s9},s9++)},o9=function(t){const e=Object.keys(lr);for(let r=0;r<e.length;r++)if(lr[e[r]].id===t)return lr[e[r]].domId},tZ=function(){wg=[],lr={},Yc=[],Yc.push(c9),ci()},eZ=function(t){return lr[t]},rZ=function(){return lr},nZ=function(){return wg},iZ=function(t){H.debug("Adding relation: "+JSON.stringify(t)),Tg(t.id1),Tg(t.id2),t.id1=Wc(t.id1).className,t.id2=Wc(t.id2).className,t.relationTitle1=pe.sanitizeText(t.relationTitle1.trim(),nt()),t.relationTitle2=pe.sanitizeText(t.relationTitle2.trim(),nt()),wg.push(t)},aZ=function(t,e){const r=Wc(t).className;lr[r].annotations.push(e)},l9=function(t,e){const r=Wc(t).className,n=lr[r];if(typeof e=="string"){const i=e.trim();i.startsWith("<<")&&i.endsWith(">>")?n.annotations.push(Uc(i.substring(2,i.length-2))):i.indexOf(")")>0?n.methods.push(Uc(i)):i&&n.members.push(Uc(i))}},sZ=function(t,e){Array.isArray(e)&&(e.reverse(),e.forEach(r=>l9(t,r)))},oZ=function(t){return t.substring(0,1)===":"?pe.sanitizeText(t.substr(1).trim(),nt()):Uc(t.trim())},Eg=function(t,e){t.split(",").forEach(function(r){let n=r;r[0].match(/\d/)&&(n=kg+n),typeof lr[n]<"u"&&lr[n].cssClasses.push(e)})},lZ=function(t,e){const r=nt();t.split(",").forEach(function(n){typeof e<"u"&&(lr[n].tooltip=pe.sanitizeText(e,r))})},cZ=function(t){return lr[t].tooltip},uZ=function(t,e,r){const n=nt();t.split(",").forEach(function(i){let a=i;i[0].match(/\d/)&&(a=kg+a),typeof lr[a]<"u"&&(lr[a].link=Se.formatUrl(e,n),n.securityLevel==="sandbox"?lr[a].linkTarget="_top":typeof r=="string"?lr[a].linkTarget=Uc(r):lr[a].linkTarget="_blank")}),Eg(t,"clickable")},hZ=function(t,e,r){t.split(",").forEach(function(n){fZ(n,e,r),lr[n].haveCallback=!0}),Eg(t,"clickable")},fZ=function(t,e,r){const n=nt();let i=t,a=o9(i);if(n.securityLevel==="loose"&&!(typeof e>"u")&&typeof lr[i]<"u"){let s=[];if(typeof r=="string"){s=r.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/);for(let o=0;o<s.length;o++){let l=s[o].trim();l.charAt(0)==='"'&&l.charAt(l.length-1)==='"'&&(l=l.substr(1,l.length-2)),s[o]=l}}s.length===0&&s.push(a),Yc.push(function(){const o=document.querySelector(`[id="${a}"]`);o!==null&&o.addEventListener("click",function(){Se.runFunc(e,...s)},!1)})}},dZ=function(t){Yc.forEach(function(e){e(t)})},pZ={LINE:0,DOTTED_LINE:1},gZ={AGGREGATION:0,EXTENSION:1,COMPOSITION:2,DEPENDENCY:3,LOLLIPOP:4},c9=function(t){let e=St(".mermaidTooltip");(e._groups||e)[0][0]===null&&(e=St("body").append("div").attr("class","mermaidTooltip").style("opacity",0)),St(t).select("svg").selectAll("g.node").on("mouseover",function(){const i=St(this);if(i.attr("title")===null)return;const s=this.getBoundingClientRect();e.transition().duration(200).style("opacity",".9"),e.text(i.attr("title")).style("left",window.scrollX+s.left+(s.right-s.left)/2+"px").style("top",window.scrollY+s.top-14+document.body.scrollTop+"px"),e.html(e.html().replace(/<br\/>/g,"<br/>")),i.classed("hover",!0)}).on("mouseout",function(){e.transition().duration(500).style("opacity",0),St(this).classed("hover",!1)})};Yc.push(c9);let u9="TB";const Jo={parseDirective:JK,setAccTitle:Yn,getAccTitle:ui,getAccDescription:fi,setAccDescription:hi,getConfig:()=>nt().class,addClass:Tg,bindFunctions:dZ,clear:tZ,getClass:eZ,getClasses:rZ,addAnnotation:aZ,getRelations:nZ,addRelation:iZ,getDirection:()=>u9,setDirection:t=>{u9=t},addMember:l9,addMembers:sZ,cleanupLabel:oZ,lineType:pZ,relationType:gZ,setClickEvent:hZ,setCssClass:Eg,setLink:uZ,getTooltip:cZ,setTooltip:lZ,lookUpDomId:o9};var Cg,h9;function yZ(){if(h9)return Cg;h9=1;var t=Wf;function e(){this.__data__=new t,this.size=0}return Cg=e,Cg}var Sg,f9;function mZ(){if(f9)return Sg;f9=1;function t(e){var r=this.__data__,n=r.delete(e);return this.size=r.size,n}return Sg=t,Sg}var Ag,d9;function bZ(){if(d9)return Ag;d9=1;function t(e){return this.__data__.get(e)}return Ag=t,Ag}var Mg,p9;function _Z(){if(p9)return Mg;p9=1;function t(e){return this.__data__.has(e)}return Mg=t,Mg}var Lg,g9;function vZ(){if(g9)return Lg;g9=1;var t=Wf,e=Zp,r=Qp,n=200;function i(a,s){var o=this.__data__;if(o instanceof t){var l=o.__data__;if(!e||l.length<n-1)return l.push([a,s]),this.size=++o.size,this;o=this.__data__=new r(l)}return o.set(a,s),this.size=o.size,this}return Lg=i,Lg}var Rg,y9;function v1(){if(y9)return Rg;y9=1;var t=Wf,e=yZ(),r=mZ(),n=bZ(),i=_Z(),a=vZ();function s(o){var l=this.__data__=new t(o);this.size=l.size}return s.prototype.clear=e,s.prototype.delete=r,s.prototype.get=n,s.prototype.has=i,s.prototype.set=a,Rg=s,Rg}var Ig,m9;function Ng(){if(m9)return Ig;m9=1;function t(e,r){for(var n=-1,i=e==null?0:e.length;++n<i&&r(e[n],n,e)!==!1;);return e}return Ig=t,Ig}var Bg,b9;function _9(){if(b9)return Bg;b9=1;var t=qs,e=function(){try{var r=t(Object,"defineProperty");return r({},"",{}),r}catch{}}();return Bg=e,Bg}var Dg,v9;function x1(){if(v9)return Dg;v9=1;var t=_9();function e(r,n,i){n=="__proto__"&&t?t(r,n,{configurable:!0,enumerable:!0,value:i,writable:!0}):r[n]=i}return Dg=e,Dg}var Og,x9;function k1(){if(x9)return Og;x9=1;var t=x1(),e=Wo,r=Object.prototype,n=r.hasOwnProperty;function i(a,s,o){var l=a[s];(!(n.call(a,s)&&e(l,o))||o===void 0&&!(s in a))&&t(a,s,o)}return Og=i,Og}var Fg,k9;function Hc(){if(k9)return Fg;k9=1;var t=k1(),e=x1();function r(n,i,a,s){var o=!a;a||(a={});for(var l=-1,u=i.length;++l<u;){var h=i[l],d=s?s(a[h],n[h],h,a,n):void 0;d===void 0&&(d=n[h]),o?e(a,h,d):t(a,h,d)}return a}return Fg=r,Fg}var Pg,w9;function xZ(){if(w9)return Pg;w9=1;function t(e,r){for(var n=-1,i=Array(e);++n<e;)i[n]=r(n);return i}return Pg=t,Pg}var qg,T9;function Fi(){if(T9)return qg;T9=1;function t(e){return e!=null&&typeof e=="object"}return qg=t,qg}var Vg,E9;function kZ(){if(E9)return Vg;E9=1;var t=Ps,e=Fi(),r="[object Arguments]";function n(i){return e(i)&&t(i)==r}return Vg=n,Vg}var zg,C9;function Gc(){if(C9)return zg;C9=1;var t=kZ(),e=Fi(),r=Object.prototype,n=r.hasOwnProperty,i=r.propertyIsEnumerable,a=t(function(){return arguments}())?t:function(s){return e(s)&&n.call(s,"callee")&&!i.call(s,"callee")};return zg=a,zg}var Yg,S9;function gr(){if(S9)return Yg;S9=1;var t=Array.isArray;return Yg=t,Yg}var w1={exports:{}},Ug,A9;function wZ(){if(A9)return Ug;A9=1;function t(){return!1}return Ug=t,Ug}var M9;function tl(){return M9||(M9=1,function(t,e){var r=si,n=wZ(),i=e&&!e.nodeType&&e,a=i&&!0&&t&&!t.nodeType&&t,s=a&&a.exports===i,o=s?r.Buffer:void 0,l=o?o.isBuffer:void 0,u=l||n;t.exports=u}(w1,w1.exports)),w1.exports}var Wg,L9;function T1(){if(L9)return Wg;L9=1;var t=9007199254740991,e=/^(?:0|[1-9]\d*)$/;function r(n,i){var a=typeof n;return i=i==null?t:i,!!i&&(a=="number"||a!="symbol"&&e.test(n))&&n>-1&&n%1==0&&n<i}return Wg=r,Wg}var Hg,R9;function Gg(){if(R9)return Hg;R9=1;var t=9007199254740991;function e(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=t}return Hg=e,Hg}var jg,I9;function TZ(){if(I9)return jg;I9=1;var t=Ps,e=Gg(),r=Fi(),n="[object Arguments]",i="[object Array]",a="[object Boolean]",s="[object Date]",o="[object Error]",l="[object Function]",u="[object Map]",h="[object Number]",d="[object Object]",f="[object RegExp]",p="[object Set]",m="[object String]",_="[object WeakMap]",y="[object ArrayBuffer]",b="[object DataView]",x="[object Float32Array]",k="[object Float64Array]",T="[object Int8Array]",C="[object Int16Array]",M="[object Int32Array]",S="[object Uint8Array]",R="[object Uint8ClampedArray]",A="[object Uint16Array]",L="[object Uint32Array]",v={};v[x]=v[k]=v[T]=v[C]=v[M]=v[S]=v[R]=v[A]=v[L]=!0,v[n]=v[i]=v[y]=v[a]=v[b]=v[s]=v[o]=v[l]=v[u]=v[h]=v[d]=v[f]=v[p]=v[m]=v[_]=!1;function B(w){return r(w)&&e(w.length)&&!!v[t(w)]}return jg=B,jg}var $g,N9;function E1(){if(N9)return $g;N9=1;function t(e){return function(r){return e(r)}}return $g=t,$g}var C1={exports:{}},B9;function Xg(){return B9||(B9=1,function(t,e){var r=Xk,n=e&&!e.nodeType&&e,i=n&&!0&&t&&!t.nodeType&&t,a=i&&i.exports===n,s=a&&r.process,o=function(){try{var l=i&&i.require&&i.require("util").types;return l||s&&s.binding&&s.binding("util")}catch{}}();t.exports=o}(C1,C1.exports)),C1.exports}var Kg,D9;function jc(){if(D9)return Kg;D9=1;var t=TZ(),e=E1(),r=Xg(),n=r&&r.isTypedArray,i=n?e(n):t;return Kg=i,Kg}var Zg,O9;function F9(){if(O9)return Zg;O9=1;var t=xZ(),e=Gc(),r=gr(),n=tl(),i=T1(),a=jc(),s=Object.prototype,o=s.hasOwnProperty;function l(u,h){var d=r(u),f=!d&&e(u),p=!d&&!f&&n(u),m=!d&&!f&&!p&&a(u),_=d||f||p||m,y=_?t(u.length,String):[],b=y.length;for(var x in u)(h||o.call(u,x))&&!(_&&(x=="length"||p&&(x=="offset"||x=="parent")||m&&(x=="buffer"||x=="byteLength"||x=="byteOffset")||i(x,b)))&&y.push(x);return y}return Zg=l,Zg}var Qg,P9;function S1(){if(P9)return Qg;P9=1;var t=Object.prototype;function e(r){var n=r&&r.constructor,i=typeof n=="function"&&n.prototype||t;return r===i}return Qg=e,Qg}var Jg,q9;function V9(){if(q9)return Jg;q9=1;function t(e,r){return function(n){return e(r(n))}}return Jg=t,Jg}var ty,z9;function EZ(){if(z9)return ty;z9=1;var t=V9(),e=t(Object.keys,Object);return ty=e,ty}var ey,Y9;function ry(){if(Y9)return ey;Y9=1;var t=S1(),e=EZ(),r=Object.prototype,n=r.hasOwnProperty;function i(a){if(!t(a))return e(a);var s=[];for(var o in Object(a))n.call(a,o)&&o!="constructor"&&s.push(o);return s}return ey=i,ey}var ny,U9;function oa(){if(U9)return ny;U9=1;var t=Yo,e=Gg();function r(n){return n!=null&&e(n.length)&&!t(n)}return ny=r,ny}var iy,W9;function ts(){if(W9)return iy;W9=1;var t=F9(),e=ry(),r=oa();function n(i){return r(i)?t(i):e(i)}return iy=n,iy}var ay,H9;function CZ(){if(H9)return ay;H9=1;var t=Hc(),e=ts();function r(n,i){return n&&t(i,e(i),n)}return ay=r,ay}var sy,G9;function SZ(){if(G9)return sy;G9=1;function t(e){var r=[];if(e!=null)for(var n in Object(e))r.push(n);return r}return sy=t,sy}var oy,j9;function AZ(){if(j9)return oy;j9=1;var t=Vn,e=S1(),r=SZ(),n=Object.prototype,i=n.hasOwnProperty;function a(s){if(!t(s))return r(s);var o=e(s),l=[];for(var u in s)u=="constructor"&&(o||!i.call(s,u))||l.push(u);return l}return oy=a,oy}var ly,$9;function Ws(){if($9)return ly;$9=1;var t=F9(),e=AZ(),r=oa();function n(i){return r(i)?t(i,!0):e(i)}return ly=n,ly}var cy,X9;function MZ(){if(X9)return cy;X9=1;var t=Hc(),e=Ws();function r(n,i){return n&&t(i,e(i),n)}return cy=r,cy}var A1={exports:{}},K9;function Z9(){return K9||(K9=1,function(t,e){var r=si,n=e&&!e.nodeType&&e,i=n&&!0&&t&&!t.nodeType&&t,a=i&&i.exports===n,s=a?r.Buffer:void 0,o=s?s.allocUnsafe:void 0;function l(u,h){if(h)return u.slice();var d=u.length,f=o?o(d):new u.constructor(d);return u.copy(f),f}t.exports=l}(A1,A1.exports)),A1.exports}var uy,Q9;function J9(){if(Q9)return uy;Q9=1;function t(e,r){var n=-1,i=e.length;for(r||(r=Array(i));++n<i;)r[n]=e[n];return r}return uy=t,uy}var hy,tT;function eT(){if(tT)return hy;tT=1;function t(e,r){for(var n=-1,i=e==null?0:e.length,a=0,s=[];++n<i;){var o=e[n];r(o,n,e)&&(s[a++]=o)}return s}return hy=t,hy}var fy,rT;function nT(){if(rT)return fy;rT=1;function t(){return[]}return fy=t,fy}var dy,iT;function py(){if(iT)return dy;iT=1;var t=eT(),e=nT(),r=Object.prototype,n=r.propertyIsEnumerable,i=Object.getOwnPropertySymbols,a=i?function(s){return s==null?[]:(s=Object(s),t(i(s),function(o){return n.call(s,o)}))}:e;return dy=a,dy}var gy,aT;function LZ(){if(aT)return gy;aT=1;var t=Hc(),e=py();function r(n,i){return t(n,e(n),i)}return gy=r,gy}var yy,sT;function my(){if(sT)return yy;sT=1;function t(e,r){for(var n=-1,i=r.length,a=e.length;++n<i;)e[a+n]=r[n];return e}return yy=t,yy}var by,oT;function M1(){if(oT)return by;oT=1;var t=V9(),e=t(Object.getPrototypeOf,Object);return by=e,by}var _y,lT;function cT(){if(lT)return _y;lT=1;var t=my(),e=M1(),r=py(),n=nT(),i=Object.getOwnPropertySymbols,a=i?function(s){for(var o=[];s;)t(o,r(s)),s=e(s);return o}:n;return _y=a,_y}var vy,uT;function RZ(){if(uT)return vy;uT=1;var t=Hc(),e=cT();function r(n,i){return t(n,e(n),i)}return vy=r,vy}var xy,hT;function fT(){if(hT)return xy;hT=1;var t=my(),e=gr();function r(n,i,a){var s=i(n);return e(n)?s:t(s,a(n))}return xy=r,xy}var ky,dT;function pT(){if(dT)return ky;dT=1;var t=fT(),e=py(),r=ts();function n(i){return t(i,r,e)}return ky=n,ky}var wy,gT;function IZ(){if(gT)return wy;gT=1;var t=fT(),e=cT(),r=Ws();function n(i){return t(i,r,e)}return wy=n,wy}var Ty,yT;function NZ(){if(yT)return Ty;yT=1;var t=qs,e=si,r=t(e,"DataView");return Ty=r,Ty}var Ey,mT;function BZ(){if(mT)return Ey;mT=1;var t=qs,e=si,r=t(e,"Promise");return Ey=r,Ey}var Cy,bT;function _T(){if(bT)return Cy;bT=1;var t=qs,e=si,r=t(e,"Set");return Cy=r,Cy}var Sy,vT;function DZ(){if(vT)return Sy;vT=1;var t=qs,e=si,r=t(e,"WeakMap");return Sy=r,Sy}var Ay,xT;function el(){if(xT)return Ay;xT=1;var t=NZ(),e=Zp,r=BZ(),n=_T(),i=DZ(),a=Ps,s=ew,o="[object Map]",l="[object Object]",u="[object Promise]",h="[object Set]",d="[object WeakMap]",f="[object DataView]",p=s(t),m=s(e),_=s(r),y=s(n),b=s(i),x=a;return(t&&x(new t(new ArrayBuffer(1)))!=f||e&&x(new e)!=o||r&&x(r.resolve())!=u||n&&x(new n)!=h||i&&x(new i)!=d)&&(x=function(k){var T=a(k),C=T==l?k.constructor:void 0,M=C?s(C):"";if(M)switch(M){case p:return f;case m:return o;case _:return u;case y:return h;case b:return d}return T}),Ay=x,Ay}var My,kT;function OZ(){if(kT)return My;kT=1;var t=Object.prototype,e=t.hasOwnProperty;function r(n){var i=n.length,a=new n.constructor(i);return i&&typeof n[0]=="string"&&e.call(n,"index")&&(a.index=n.index,a.input=n.input),a}return My=r,My}var Ly,wT;function TT(){if(wT)return Ly;wT=1;var t=si,e=t.Uint8Array;return Ly=e,Ly}var Ry,ET;function Iy(){if(ET)return Ry;ET=1;var t=TT();function e(r){var n=new r.constructor(r.byteLength);return new t(n).set(new t(r)),n}return Ry=e,Ry}var Ny,CT;function FZ(){if(CT)return Ny;CT=1;var t=Iy();function e(r,n){var i=n?t(r.buffer):r.buffer;return new r.constructor(i,r.byteOffset,r.byteLength)}return Ny=e,Ny}var By,ST;function PZ(){if(ST)return By;ST=1;var t=/\w*$/;function e(r){var n=new r.constructor(r.source,t.exec(r));return n.lastIndex=r.lastIndex,n}return By=e,By}var Dy,AT;function qZ(){if(AT)return Dy;AT=1;var t=zo,e=t?t.prototype:void 0,r=e?e.valueOf:void 0;function n(i){return r?Object(r.call(i)):{}}return Dy=n,Dy}var Oy,MT;function LT(){if(MT)return Oy;MT=1;var t=Iy();function e(r,n){var i=n?t(r.buffer):r.buffer;return new r.constructor(i,r.byteOffset,r.length)}return Oy=e,Oy}var Fy,RT;function VZ(){if(RT)return Fy;RT=1;var t=Iy(),e=FZ(),r=PZ(),n=qZ(),i=LT(),a="[object Boolean]",s="[object Date]",o="[object Map]",l="[object Number]",u="[object RegExp]",h="[object Set]",d="[object String]",f="[object Symbol]",p="[object ArrayBuffer]",m="[object DataView]",_="[object Float32Array]",y="[object Float64Array]",b="[object Int8Array]",x="[object Int16Array]",k="[object Int32Array]",T="[object Uint8Array]",C="[object Uint8ClampedArray]",M="[object Uint16Array]",S="[object Uint32Array]";function R(A,L,v){var B=A.constructor;switch(L){case p:return t(A);case a:case s:return new B(+A);case m:return e(A,v);case _:case y:case b:case x:case k:case T:case C:case M:case S:return i(A,v);case o:return new B;case l:case d:return new B(A);case u:return r(A);case h:return new B;case f:return n(A)}}return Fy=R,Fy}var Py,IT;function NT(){if(IT)return Py;IT=1;var t=Vn,e=Object.create,r=function(){function n(){}return function(i){if(!t(i))return{};if(e)return e(i);n.prototype=i;var a=new n;return n.prototype=void 0,a}}();return Py=r,Py}var qy,BT;function DT(){if(BT)return qy;BT=1;var t=NT(),e=M1(),r=S1();function n(i){return typeof i.constructor=="function"&&!r(i)?t(e(i)):{}}return qy=n,qy}var Vy,OT;function zZ(){if(OT)return Vy;OT=1;var t=el(),e=Fi(),r="[object Map]";function n(i){return e(i)&&t(i)==r}return Vy=n,Vy}var zy,FT;function YZ(){if(FT)return zy;FT=1;var t=zZ(),e=E1(),r=Xg(),n=r&&r.isMap,i=n?e(n):t;return zy=i,zy}var Yy,PT;function UZ(){if(PT)return Yy;PT=1;var t=el(),e=Fi(),r="[object Set]";function n(i){return e(i)&&t(i)==r}return Yy=n,Yy}var Uy,qT;function WZ(){if(qT)return Uy;qT=1;var t=UZ(),e=E1(),r=Xg(),n=r&&r.isSet,i=n?e(n):t;return Uy=i,Uy}var Wy,VT;function zT(){if(VT)return Wy;VT=1;var t=v1(),e=Ng(),r=k1(),n=CZ(),i=MZ(),a=Z9(),s=J9(),o=LZ(),l=RZ(),u=pT(),h=IZ(),d=el(),f=OZ(),p=VZ(),m=DT(),_=gr(),y=tl(),b=YZ(),x=Vn,k=WZ(),T=ts(),C=Ws(),M=1,S=2,R=4,A="[object Arguments]",L="[object Array]",v="[object Boolean]",B="[object Date]",w="[object Error]",D="[object Function]",N="[object GeneratorFunction]",z="[object Map]",X="[object Number]",ct="[object Object]",J="[object RegExp]",Y="[object Set]",$="[object String]",lt="[object Symbol]",ut="[object WeakMap]",W="[object ArrayBuffer]",tt="[object DataView]",K="[object Float32Array]",it="[object Float64Array]",Z="[object Int8Array]",V="[object Int16Array]",Q="[object Int32Array]",q="[object Uint8Array]",U="[object Uint8ClampedArray]",F="[object Uint16Array]",j="[object Uint32Array]",P={};P[A]=P[L]=P[W]=P[tt]=P[v]=P[B]=P[K]=P[it]=P[Z]=P[V]=P[Q]=P[z]=P[X]=P[ct]=P[J]=P[Y]=P[$]=P[lt]=P[q]=P[U]=P[F]=P[j]=!0,P[w]=P[D]=P[ut]=!1;function et(at,It,Lt,Rt,Ct,pt){var mt,vt=It&M,Tt=It&S,ft=It&R;if(Lt&&(mt=Ct?Lt(at,Rt,Ct,pt):Lt(at)),mt!==void 0)return mt;if(!x(at))return at;var le=_(at);if(le){if(mt=f(at),!vt)return s(at,mt)}else{var Dt=d(at),Gt=Dt==D||Dt==N;if(y(at))return a(at,vt);if(Dt==ct||Dt==A||Gt&&!Ct){if(mt=Tt||Gt?{}:m(at),!vt)return Tt?l(at,i(mt,at)):o(at,n(mt,at))}else{if(!P[Dt])return Ct?at:{};mt=p(at,Dt,vt)}}pt||(pt=new t);var $t=pt.get(at);if($t)return $t;pt.set(at,mt),k(at)?at.forEach(function(jt){mt.add(et(jt,It,Lt,jt,at,pt))}):b(at)&&at.forEach(function(jt,Ft){mt.set(Ft,et(jt,It,Lt,Ft,at,pt))});var Qt=ft?Tt?h:u:Tt?C:T,we=le?void 0:Qt(at);return e(we||at,function(jt,Ft){we&&(Ft=jt,jt=at[Ft]),r(mt,Ft,et(jt,It,Lt,Ft,at,pt))}),mt}return Wy=et,Wy}var Hy,YT;function HZ(){if(YT)return Hy;YT=1;var t=zT(),e=4;function r(n){return t(n,e)}return Hy=r,Hy}var Gy,UT;function jy(){if(UT)return Gy;UT=1;function t(e){return function(){return e}}return Gy=t,Gy}var $y={exports:{}},Xy,WT;function GZ(){if(WT)return Xy;WT=1;function t(e){return function(r,n,i){for(var a=-1,s=Object(r),o=i(r),l=o.length;l--;){var u=o[e?l:++a];if(n(s[u],u,s)===!1)break}return r}}return Xy=t,Xy}var Ky,HT;function Zy(){if(HT)return Ky;HT=1;var t=GZ(),e=t();return Ky=e,Ky}var Qy,GT;function Jy(){if(GT)return Qy;GT=1;var t=Zy(),e=ts();function r(n,i){return n&&t(n,i,e)}return Qy=r,Qy}var tm,jT;function jZ(){if(jT)return tm;jT=1;var t=oa();function e(r,n){return function(i,a){if(i==null)return i;if(!t(i))return r(i,a);for(var s=i.length,o=n?s:-1,l=Object(i);(n?o--:++o<s)&&a(l[o],o,l)!==!1;);return i}}return tm=e,tm}var em,$T;function L1(){if($T)return em;$T=1;var t=Jy(),e=jZ(),r=e(t);return em=r,em}var rm,XT;function Hs(){if(XT)return rm;XT=1;function t(e){return e}return rm=t,rm}var nm,KT;function ZT(){if(KT)return nm;KT=1;var t=Hs();function e(r){return typeof r=="function"?r:t}return nm=e,nm}var im,QT;function JT(){if(QT)return im;QT=1;var t=Ng(),e=L1(),r=ZT(),n=gr();function i(a,s){var o=n(a)?t:e;return o(a,r(s))}return im=i,im}var tE;function am(){return tE||(tE=1,function(t){t.exports=JT()}($y)),$y.exports}var sm,eE;function $Z(){if(eE)return sm;eE=1;var t=L1();function e(r,n){var i=[];return t(r,function(a,s,o){n(a,s,o)&&i.push(a)}),i}return sm=e,sm}var om,rE;function XZ(){if(rE)return om;rE=1;var t="__lodash_hash_undefined__";function e(r){return this.__data__.set(r,t),this}return om=e,om}var lm,nE;function KZ(){if(nE)return lm;nE=1;function t(e){return this.__data__.has(e)}return lm=t,lm}var cm,iE;function aE(){if(iE)return cm;iE=1;var t=Qp,e=XZ(),r=KZ();function n(i){var a=-1,s=i==null?0:i.length;for(this.__data__=new t;++a<s;)this.add(i[a])}return n.prototype.add=n.prototype.push=e,n.prototype.has=r,cm=n,cm}var um,sE;function ZZ(){if(sE)return um;sE=1;function t(e,r){for(var n=-1,i=e==null?0:e.length;++n<i;)if(r(e[n],n,e))return!0;return!1}return um=t,um}var hm,oE;function lE(){if(oE)return hm;oE=1;function t(e,r){return e.has(r)}return hm=t,hm}var fm,cE;function uE(){if(cE)return fm;cE=1;var t=aE(),e=ZZ(),r=lE(),n=1,i=2;function a(s,o,l,u,h,d){var f=l&n,p=s.length,m=o.length;if(p!=m&&!(f&&m>p))return!1;var _=d.get(s),y=d.get(o);if(_&&y)return _==o&&y==s;var b=-1,x=!0,k=l&i?new t:void 0;for(d.set(s,o),d.set(o,s);++b<p;){var T=s[b],C=o[b];if(u)var M=f?u(C,T,b,o,s,d):u(T,C,b,s,o,d);if(M!==void 0){if(M)continue;x=!1;break}if(k){if(!e(o,function(S,R){if(!r(k,R)&&(T===S||h(T,S,l,u,d)))return k.push(R)})){x=!1;break}}else if(!(T===C||h(T,C,l,u,d))){x=!1;break}}return d.delete(s),d.delete(o),x}return fm=a,fm}var dm,hE;function QZ(){if(hE)return dm;hE=1;function t(e){var r=-1,n=Array(e.size);return e.forEach(function(i,a){n[++r]=[a,i]}),n}return dm=t,dm}var pm,fE;function gm(){if(fE)return pm;fE=1;function t(e){var r=-1,n=Array(e.size);return e.forEach(function(i){n[++r]=i}),n}return pm=t,pm}var ym,dE;function JZ(){if(dE)return ym;dE=1;var t=zo,e=TT(),r=Wo,n=uE(),i=QZ(),a=gm(),s=1,o=2,l="[object Boolean]",u="[object Date]",h="[object Error]",d="[object Map]",f="[object Number]",p="[object RegExp]",m="[object Set]",_="[object String]",y="[object Symbol]",b="[object ArrayBuffer]",x="[object DataView]",k=t?t.prototype:void 0,T=k?k.valueOf:void 0;function C(M,S,R,A,L,v,B){switch(R){case x:if(M.byteLength!=S.byteLength||M.byteOffset!=S.byteOffset)return!1;M=M.buffer,S=S.buffer;case b:return!(M.byteLength!=S.byteLength||!v(new e(M),new e(S)));case l:case u:case f:return r(+M,+S);case h:return M.name==S.name&&M.message==S.message;case p:case _:return M==S+"";case d:var w=i;case m:var D=A&s;if(w||(w=a),M.size!=S.size&&!D)return!1;var N=B.get(M);if(N)return N==S;A|=o,B.set(M,S);var z=n(w(M),w(S),A,L,v,B);return B.delete(M),z;case y:if(T)return T.call(M)==T.call(S)}return!1}return ym=C,ym}var mm,pE;function tQ(){if(pE)return mm;pE=1;var t=pT(),e=1,r=Object.prototype,n=r.hasOwnProperty;function i(a,s,o,l,u,h){var d=o&e,f=t(a),p=f.length,m=t(s),_=m.length;if(p!=_&&!d)return!1;for(var y=p;y--;){var b=f[y];if(!(d?b in s:n.call(s,b)))return!1}var x=h.get(a),k=h.get(s);if(x&&k)return x==s&&k==a;var T=!0;h.set(a,s),h.set(s,a);for(var C=d;++y<p;){b=f[y];var M=a[b],S=s[b];if(l)var R=d?l(S,M,b,s,a,h):l(M,S,b,a,s,h);if(!(R===void 0?M===S||u(M,S,o,l,h):R)){T=!1;break}C||(C=b=="constructor")}if(T&&!C){var A=a.constructor,L=s.constructor;A!=L&&"constructor"in a&&"constructor"in s&&!(typeof A=="function"&&A instanceof A&&typeof L=="function"&&L instanceof L)&&(T=!1)}return h.delete(a),h.delete(s),T}return mm=i,mm}var bm,gE;function eQ(){if(gE)return bm;gE=1;var t=v1(),e=uE(),r=JZ(),n=tQ(),i=el(),a=gr(),s=tl(),o=jc(),l=1,u="[object Arguments]",h="[object Array]",d="[object Object]",f=Object.prototype,p=f.hasOwnProperty;function m(_,y,b,x,k,T){var C=a(_),M=a(y),S=C?h:i(_),R=M?h:i(y);S=S==u?d:S,R=R==u?d:R;var A=S==d,L=R==d,v=S==R;if(v&&s(_)){if(!s(y))return!1;C=!0,A=!1}if(v&&!A)return T||(T=new t),C||o(_)?e(_,y,b,x,k,T):r(_,y,S,b,x,k,T);if(!(b&l)){var B=A&&p.call(_,"__wrapped__"),w=L&&p.call(y,"__wrapped__");if(B||w){var D=B?_.value():_,N=w?y.value():y;return T||(T=new t),k(D,N,b,x,T)}}return v?(T||(T=new t),n(_,y,b,x,k,T)):!1}return bm=m,bm}var _m,yE;function mE(){if(yE)return _m;yE=1;var t=eQ(),e=Fi();function r(n,i,a,s,o){return n===i?!0:n==null||i==null||!e(n)&&!e(i)?n!==n&&i!==i:t(n,i,a,s,r,o)}return _m=r,_m}var vm,bE;function rQ(){if(bE)return vm;bE=1;var t=v1(),e=mE(),r=1,n=2;function i(a,s,o,l){var u=o.length,h=u,d=!l;if(a==null)return!h;for(a=Object(a);u--;){var f=o[u];if(d&&f[2]?f[1]!==a[f[0]]:!(f[0]in a))return!1}for(;++u<h;){f=o[u];var p=f[0],m=a[p],_=f[1];if(d&&f[2]){if(m===void 0&&!(p in a))return!1}else{var y=new t;if(l)var b=l(m,_,p,a,s,y);if(!(b===void 0?e(_,m,r|n,l,y):b))return!1}}return!0}return vm=i,vm}var xm,_E;function vE(){if(_E)return xm;_E=1;var t=Vn;function e(r){return r===r&&!t(r)}return xm=e,xm}var km,xE;function nQ(){if(xE)return km;xE=1;var t=vE(),e=ts();function r(n){for(var i=e(n),a=i.length;a--;){var s=i[a],o=n[s];i[a]=[s,o,t(o)]}return i}return km=r,km}var wm,kE;function wE(){if(kE)return wm;kE=1;function t(e,r){return function(n){return n==null?!1:n[e]===r&&(r!==void 0||e in Object(n))}}return wm=t,wm}var Tm,TE;function iQ(){if(TE)return Tm;TE=1;var t=rQ(),e=nQ(),r=wE();function n(i){var a=e(i);return a.length==1&&a[0][2]?r(a[0][0],a[0][1]):function(s){return s===i||t(s,i,a)}}return Tm=n,Tm}var Em,EE;function rl(){if(EE)return Em;EE=1;var t=Ps,e=Fi(),r="[object Symbol]";function n(i){return typeof i=="symbol"||e(i)&&t(i)==r}return Em=n,Em}var Cm,CE;function Sm(){if(CE)return Cm;CE=1;var t=gr(),e=rl(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function i(a,s){if(t(a))return!1;var o=typeof a;return o=="number"||o=="symbol"||o=="boolean"||a==null||e(a)?!0:n.test(a)||!r.test(a)||s!=null&&a in Object(s)}return Cm=i,Cm}var Am,SE;function aQ(){if(SE)return Am;SE=1;var t=Gf,e=500;function r(n){var i=t(n,function(s){return a.size===e&&a.clear(),s}),a=i.cache;return i}return Am=r,Am}var Mm,AE;function sQ(){if(AE)return Mm;AE=1;var t=aQ(),e=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,n=t(function(i){var a=[];return i.charCodeAt(0)===46&&a.push(""),i.replace(e,function(s,o,l,u){a.push(l?u.replace(r,"$1"):o||s)}),a});return Mm=n,Mm}var Lm,ME;function R1(){if(ME)return Lm;ME=1;function t(e,r){for(var n=-1,i=e==null?0:e.length,a=Array(i);++n<i;)a[n]=r(e[n],n,e);return a}return Lm=t,Lm}var Rm,LE;function oQ(){if(LE)return Rm;LE=1;var t=zo,e=R1(),r=gr(),n=rl(),i=1/0,a=t?t.prototype:void 0,s=a?a.toString:void 0;function o(l){if(typeof l=="string")return l;if(r(l))return e(l,o)+"";if(n(l))return s?s.call(l):"";var u=l+"";return u=="0"&&1/l==-i?"-0":u}return Rm=o,Rm}var Im,RE;function IE(){if(RE)return Im;RE=1;var t=oQ();function e(r){return r==null?"":t(r)}return Im=e,Im}var Nm,NE;function I1(){if(NE)return Nm;NE=1;var t=gr(),e=Sm(),r=sQ(),n=IE();function i(a,s){return t(a)?a:e(a,s)?[a]:r(n(a))}return Nm=i,Nm}var Bm,BE;function $c(){if(BE)return Bm;BE=1;var t=rl(),e=1/0;function r(n){if(typeof n=="string"||t(n))return n;var i=n+"";return i=="0"&&1/n==-e?"-0":i}return Bm=r,Bm}var Dm,DE;function N1(){if(DE)return Dm;DE=1;var t=I1(),e=$c();function r(n,i){i=t(i,n);for(var a=0,s=i.length;n!=null&&a<s;)n=n[e(i[a++])];return a&&a==s?n:void 0}return Dm=r,Dm}var Om,OE;function lQ(){if(OE)return Om;OE=1;var t=N1();function e(r,n,i){var a=r==null?void 0:t(r,n);return a===void 0?i:a}return Om=e,Om}var Fm,FE;function cQ(){if(FE)return Fm;FE=1;function t(e,r){return e!=null&&r in Object(e)}return Fm=t,Fm}var Pm,PE;function qE(){if(PE)return Pm;PE=1;var t=I1(),e=Gc(),r=gr(),n=T1(),i=Gg(),a=$c();function s(o,l,u){l=t(l,o);for(var h=-1,d=l.length,f=!1;++h<d;){var p=a(l[h]);if(!(f=o!=null&&u(o,p)))break;o=o[p]}return f||++h!=d?f:(d=o==null?0:o.length,!!d&&i(d)&&n(p,d)&&(r(o)||e(o)))}return Pm=s,Pm}var qm,VE;function zE(){if(VE)return qm;VE=1;var t=cQ(),e=qE();function r(n,i){return n!=null&&e(n,i,t)}return qm=r,qm}var Vm,YE;function uQ(){if(YE)return Vm;YE=1;var t=mE(),e=lQ(),r=zE(),n=Sm(),i=vE(),a=wE(),s=$c(),o=1,l=2;function u(h,d){return n(h)&&i(d)?a(s(h),d):function(f){var p=e(f,h);return p===void 0&&p===d?r(f,h):t(d,p,o|l)}}return Vm=u,Vm}var zm,UE;function WE(){if(UE)return zm;UE=1;function t(e){return function(r){return r==null?void 0:r[e]}}return zm=t,zm}var Ym,HE;function hQ(){if(HE)return Ym;HE=1;var t=N1();function e(r){return function(n){return t(n,r)}}return Ym=e,Ym}var Um,GE;function fQ(){if(GE)return Um;GE=1;var t=WE(),e=hQ(),r=Sm(),n=$c();function i(a){return r(a)?t(n(a)):e(a)}return Um=i,Um}var Wm,jE;function la(){if(jE)return Wm;jE=1;var t=iQ(),e=uQ(),r=Hs(),n=gr(),i=fQ();function a(s){return typeof s=="function"?s:s==null?r:typeof s=="object"?n(s)?e(s[0],s[1]):t(s):i(s)}return Wm=a,Wm}var Hm,$E;function XE(){if($E)return Hm;$E=1;var t=eT(),e=$Z(),r=la(),n=gr();function i(a,s){var o=n(a)?t:e;return o(a,r(s,3))}return Hm=i,Hm}var Gm,KE;function dQ(){if(KE)return Gm;KE=1;var t=Object.prototype,e=t.hasOwnProperty;function r(n,i){return n!=null&&e.call(n,i)}return Gm=r,Gm}var jm,ZE;function $m(){if(ZE)return jm;ZE=1;var t=dQ(),e=qE();function r(n,i){return n!=null&&e(n,i,t)}return jm=r,jm}var Xm,QE;function pQ(){if(QE)return Xm;QE=1;var t=ry(),e=el(),r=Gc(),n=gr(),i=oa(),a=tl(),s=S1(),o=jc(),l="[object Map]",u="[object Set]",h=Object.prototype,d=h.hasOwnProperty;function f(p){if(p==null)return!0;if(i(p)&&(n(p)||typeof p=="string"||typeof p.splice=="function"||a(p)||o(p)||r(p)))return!p.length;var m=e(p);if(m==l||m==u)return!p.size;if(s(p))return!t(p).length;for(var _ in p)if(d.call(p,_))return!1;return!0}return Xm=f,Xm}var Km,JE;function tC(){if(JE)return Km;JE=1;function t(e){return e===void 0}return Km=t,Km}var Zm,eC;function rC(){if(eC)return Zm;eC=1;var t=L1(),e=oa();function r(n,i){var a=-1,s=e(n)?Array(n.length):[];return t(n,function(o,l,u){s[++a]=i(o,l,u)}),s}return Zm=r,Zm}var Qm,nC;function iC(){if(nC)return Qm;nC=1;var t=R1(),e=la(),r=rC(),n=gr();function i(a,s){var o=n(a)?t:r;return o(a,e(s,3))}return Qm=i,Qm}var Jm,aC;function gQ(){if(aC)return Jm;aC=1;function t(e,r,n,i){var a=-1,s=e==null?0:e.length;for(i&&s&&(n=e[++a]);++a<s;)n=r(n,e[a],a,e);return n}return Jm=t,Jm}var tb,sC;function yQ(){if(sC)return tb;sC=1;function t(e,r,n,i,a){return a(e,function(s,o,l){n=i?(i=!1,s):r(n,s,o,l)}),n}return tb=t,tb}var eb,oC;function lC(){if(oC)return eb;oC=1;var t=gQ(),e=L1(),r=la(),n=yQ(),i=gr();function a(s,o,l){var u=i(s)?t:n,h=arguments.length<3;return u(s,r(o,4),l,h,e)}return eb=a,eb}var rb,cC;function mQ(){if(cC)return rb;cC=1;var t=Ps,e=gr(),r=Fi(),n="[object String]";function i(a){return typeof a=="string"||!e(a)&&r(a)&&t(a)==n}return rb=i,rb}var nb,uC;function bQ(){if(uC)return nb;uC=1;var t=WE(),e=t("length");return nb=e,nb}var ib,hC;function _Q(){if(hC)return ib;hC=1;var t="\\ud800-\\udfff",e="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",i=e+r+n,a="\\ufe0e\\ufe0f",s="\\u200d",o=RegExp("["+s+t+i+a+"]");function l(u){return o.test(u)}return ib=l,ib}var ab,fC;function vQ(){if(fC)return ab;fC=1;var t="\\ud800-\\udfff",e="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",i=e+r+n,a="\\ufe0e\\ufe0f",s="["+t+"]",o="["+i+"]",l="\\ud83c[\\udffb-\\udfff]",u="(?:"+o+"|"+l+")",h="[^"+t+"]",d="(?:\\ud83c[\\udde6-\\uddff]){2}",f="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",m=u+"?",_="["+a+"]?",y="(?:"+p+"(?:"+[h,d,f].join("|")+")"+_+m+")*",b=_+m+y,x="(?:"+[h+o+"?",o,d,f,s].join("|")+")",k=RegExp(l+"(?="+l+")|"+x+b,"g");function T(C){for(var M=k.lastIndex=0;k.test(C);)++M;return M}return ab=T,ab}var sb,dC;function xQ(){if(dC)return sb;dC=1;var t=bQ(),e=_Q(),r=vQ();function n(i){return e(i)?r(i):t(i)}return sb=n,sb}var ob,pC;function kQ(){if(pC)return ob;pC=1;var t=ry(),e=el(),r=oa(),n=mQ(),i=xQ(),a="[object Map]",s="[object Set]";function o(l){if(l==null)return 0;if(r(l))return n(l)?i(l):l.length;var u=e(l);return u==a||u==s?l.size:t(l).length}return ob=o,ob}var lb,gC;function wQ(){if(gC)return lb;gC=1;var t=Ng(),e=NT(),r=Jy(),n=la(),i=M1(),a=gr(),s=tl(),o=Yo,l=Vn,u=jc();function h(d,f,p){var m=a(d),_=m||s(d)||u(d);if(f=n(f,4),p==null){var y=d&&d.constructor;_?p=m?new y:[]:l(d)?p=o(y)?e(i(d)):{}:p={}}return(_?t:r)(d,function(b,x,k){return f(p,b,x,k)}),p}return lb=h,lb}var cb,yC;function TQ(){if(yC)return cb;yC=1;var t=zo,e=Gc(),r=gr(),n=t?t.isConcatSpreadable:void 0;function i(a){return r(a)||e(a)||!!(n&&a&&a[n])}return cb=i,cb}var ub,mC;function hb(){if(mC)return ub;mC=1;var t=my(),e=TQ();function r(n,i,a,s,o){var l=-1,u=n.length;for(a||(a=e),o||(o=[]);++l<u;){var h=n[l];i>0&&a(h)?i>1?r(h,i-1,a,s,o):t(o,h):s||(o[o.length]=h)}return o}return ub=r,ub}var fb,bC;function EQ(){if(bC)return fb;bC=1;function t(e,r,n){switch(n.length){case 0:return e.call(r);case 1:return e.call(r,n[0]);case 2:return e.call(r,n[0],n[1]);case 3:return e.call(r,n[0],n[1],n[2])}return e.apply(r,n)}return fb=t,fb}var db,_C;function vC(){if(_C)return db;_C=1;var t=EQ(),e=Math.max;function r(n,i,a){return i=e(i===void 0?n.length-1:i,0),function(){for(var s=arguments,o=-1,l=e(s.length-i,0),u=Array(l);++o<l;)u[o]=s[i+o];o=-1;for(var h=Array(i+1);++o<i;)h[o]=s[o];return h[i]=a(u),t(n,this,h)}}return db=r,db}var pb,xC;function CQ(){if(xC)return pb;xC=1;var t=jy(),e=_9(),r=Hs(),n=e?function(i,a){return e(i,"toString",{configurable:!0,enumerable:!1,value:t(a),writable:!0})}:r;return pb=n,pb}var gb,kC;function SQ(){if(kC)return gb;kC=1;var t=800,e=16,r=Date.now;function n(i){var a=0,s=0;return function(){var o=r(),l=e-(o-s);if(s=o,l>0){if(++a>=t)return arguments[0]}else a=0;return i.apply(void 0,arguments)}}return gb=n,gb}var yb,wC;function TC(){if(wC)return yb;wC=1;var t=CQ(),e=SQ(),r=e(t);return yb=r,yb}var mb,EC;function B1(){if(EC)return mb;EC=1;var t=Hs(),e=vC(),r=TC();function n(i,a){return r(e(i,a,t),i+"")}return mb=n,mb}var bb,CC;function SC(){if(CC)return bb;CC=1;function t(e,r,n,i){for(var a=e.length,s=n+(i?1:-1);i?s--:++s<a;)if(r(e[s],s,e))return s;return-1}return bb=t,bb}var _b,AC;function AQ(){if(AC)return _b;AC=1;function t(e){return e!==e}return _b=t,_b}var vb,MC;function MQ(){if(MC)return vb;MC=1;function t(e,r,n){for(var i=n-1,a=e.length;++i<a;)if(e[i]===r)return i;return-1}return vb=t,vb}var xb,LC;function LQ(){if(LC)return xb;LC=1;var t=SC(),e=AQ(),r=MQ();function n(i,a,s){return a===a?r(i,a,s):t(i,e,s)}return xb=n,xb}var kb,RC;function RQ(){if(RC)return kb;RC=1;var t=LQ();function e(r,n){var i=r==null?0:r.length;return!!i&&t(r,n,0)>-1}return kb=e,kb}var wb,IC;function IQ(){if(IC)return wb;IC=1;function t(e,r,n){for(var i=-1,a=e==null?0:e.length;++i<a;)if(n(r,e[i]))return!0;return!1}return wb=t,wb}var Tb,NC;function NQ(){if(NC)return Tb;NC=1;function t(){}return Tb=t,Tb}var Eb,BC;function BQ(){if(BC)return Eb;BC=1;var t=_T(),e=NQ(),r=gm(),n=1/0,i=t&&1/r(new t([,-0]))[1]==n?function(a){return new t(a)}:e;return Eb=i,Eb}var Cb,DC;function DQ(){if(DC)return Cb;DC=1;var t=aE(),e=RQ(),r=IQ(),n=lE(),i=BQ(),a=gm(),s=200;function o(l,u,h){var d=-1,f=e,p=l.length,m=!0,_=[],y=_;if(h)m=!1,f=r;else if(p>=s){var b=u?null:i(l);if(b)return a(b);m=!1,f=n,y=new t}else y=u?[]:_;t:for(;++d<p;){var x=l[d],k=u?u(x):x;if(x=h||x!==0?x:0,m&&k===k){for(var T=y.length;T--;)if(y[T]===k)continue t;u&&y.push(k),_.push(x)}else f(y,k,h)||(y!==_&&y.push(k),_.push(x))}return _}return Cb=o,Cb}var Sb,OC;function FC(){if(OC)return Sb;OC=1;var t=oa(),e=Fi();function r(n){return e(n)&&t(n)}return Sb=r,Sb}var Ab,PC;function OQ(){if(PC)return Ab;PC=1;var t=hb(),e=B1(),r=DQ(),n=FC(),i=e(function(a){return r(t(a,1,n,!0))});return Ab=i,Ab}var Mb,qC;function FQ(){if(qC)return Mb;qC=1;var t=R1();function e(r,n){return t(n,function(i){return r[i]})}return Mb=e,Mb}var Lb,VC;function zC(){if(VC)return Lb;VC=1;var t=FQ(),e=ts();function r(n){return n==null?[]:t(n,e(n))}return Lb=r,Lb}var D1;if(typeof fn=="function")try{D1={clone:HZ(),constant:jy(),each:am(),filter:XE(),has:$m(),isArray:gr(),isEmpty:pQ(),isFunction:Yo,isUndefined:tC(),keys:ts(),map:iC(),reduce:lC(),size:kQ(),transform:wQ(),union:OQ(),values:zC()}}catch{}D1||(D1=window._);var Wn=D1,_e=Wn,Rb=Le,PQ="\0",Gs="\0",YC="";function Le(t){this._isDirected=_e.has(t,"directed")?t.directed:!0,this._isMultigraph=_e.has(t,"multigraph")?t.multigraph:!1,this._isCompound=_e.has(t,"compound")?t.compound:!1,this._label=void 0,this._defaultNodeLabelFn=_e.constant(void 0),this._defaultEdgeLabelFn=_e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[Gs]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}Le.prototype._nodeCount=0,Le.prototype._edgeCount=0,Le.prototype.isDirected=function(){return this._isDirected},Le.prototype.isMultigraph=function(){return this._isMultigraph},Le.prototype.isCompound=function(){return this._isCompound},Le.prototype.setGraph=function(t){return this._label=t,this},Le.prototype.graph=function(){return this._label},Le.prototype.setDefaultNodeLabel=function(t){return _e.isFunction(t)||(t=_e.constant(t)),this._defaultNodeLabelFn=t,this},Le.prototype.nodeCount=function(){return this._nodeCount},Le.prototype.nodes=function(){return _e.keys(this._nodes)},Le.prototype.sources=function(){var t=this;return _e.filter(this.nodes(),function(e){return _e.isEmpty(t._in[e])})},Le.prototype.sinks=function(){var t=this;return _e.filter(this.nodes(),function(e){return _e.isEmpty(t._out[e])})},Le.prototype.setNodes=function(t,e){var r=arguments,n=this;return _e.each(t,function(i){r.length>1?n.setNode(i,e):n.setNode(i)}),this},Le.prototype.setNode=function(t,e){return _e.has(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=e),this):(this._nodes[t]=arguments.length>1?e:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=Gs,this._children[t]={},this._children[Gs][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)},Le.prototype.node=function(t){return this._nodes[t]},Le.prototype.hasNode=function(t){return _e.has(this._nodes,t)},Le.prototype.removeNode=function(t){var e=this;if(_e.has(this._nodes,t)){var r=function(n){e.removeEdge(e._edgeObjs[n])};delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],_e.each(this.children(t),function(n){e.setParent(n)}),delete this._children[t]),_e.each(_e.keys(this._in[t]),r),delete this._in[t],delete this._preds[t],_e.each(_e.keys(this._out[t]),r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this},Le.prototype.setParent=function(t,e){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(_e.isUndefined(e))e=Gs;else{e+="";for(var r=e;!_e.isUndefined(r);r=this.parent(r))if(r===t)throw new Error("Setting "+e+" as parent of "+t+" would create a cycle");this.setNode(e)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=e,this._children[e][t]=!0,this},Le.prototype._removeFromParentsChildList=function(t){delete this._children[this._parent[t]][t]},Le.prototype.parent=function(t){if(this._isCompound){var e=this._parent[t];if(e!==Gs)return e}},Le.prototype.children=function(t){if(_e.isUndefined(t)&&(t=Gs),this._isCompound){var e=this._children[t];if(e)return _e.keys(e)}else{if(t===Gs)return this.nodes();if(this.hasNode(t))return[]}},Le.prototype.predecessors=function(t){var e=this._preds[t];if(e)return _e.keys(e)},Le.prototype.successors=function(t){var e=this._sucs[t];if(e)return _e.keys(e)},Le.prototype.neighbors=function(t){var e=this.predecessors(t);if(e)return _e.union(e,this.successors(t))},Le.prototype.isLeaf=function(t){var e;return this.isDirected()?e=this.successors(t):e=this.neighbors(t),e.length===0},Le.prototype.filterNodes=function(t){var e=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});e.setGraph(this.graph());var r=this;_e.each(this._nodes,function(a,s){t(s)&&e.setNode(s,a)}),_e.each(this._edgeObjs,function(a){e.hasNode(a.v)&&e.hasNode(a.w)&&e.setEdge(a,r.edge(a))});var n={};function i(a){var s=r.parent(a);return s===void 0||e.hasNode(s)?(n[a]=s,s):s in n?n[s]:i(s)}return this._isCompound&&_e.each(e.nodes(),function(a){e.setParent(a,i(a))}),e},Le.prototype.setDefaultEdgeLabel=function(t){return _e.isFunction(t)||(t=_e.constant(t)),this._defaultEdgeLabelFn=t,this},Le.prototype.edgeCount=function(){return this._edgeCount},Le.prototype.edges=function(){return _e.values(this._edgeObjs)},Le.prototype.setPath=function(t,e){var r=this,n=arguments;return _e.reduce(t,function(i,a){return n.length>1?r.setEdge(i,a,e):r.setEdge(i,a),a}),this},Le.prototype.setEdge=function(){var t,e,r,n,i=!1,a=arguments[0];typeof a=="object"&&a!==null&&"v"in a?(t=a.v,e=a.w,r=a.name,arguments.length===2&&(n=arguments[1],i=!0)):(t=a,e=arguments[1],r=arguments[3],arguments.length>2&&(n=arguments[2],i=!0)),t=""+t,e=""+e,_e.isUndefined(r)||(r=""+r);var s=Xc(this._isDirected,t,e,r);if(_e.has(this._edgeLabels,s))return i&&(this._edgeLabels[s]=n),this;if(!_e.isUndefined(r)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(e),this._edgeLabels[s]=i?n:this._defaultEdgeLabelFn(t,e,r);var o=qQ(this._isDirected,t,e,r);return t=o.v,e=o.w,Object.freeze(o),this._edgeObjs[s]=o,UC(this._preds[e],t),UC(this._sucs[t],e),this._in[e][s]=o,this._out[t][s]=o,this._edgeCount++,this},Le.prototype.edge=function(t,e,r){var n=arguments.length===1?Ib(this._isDirected,arguments[0]):Xc(this._isDirected,t,e,r);return this._edgeLabels[n]},Le.prototype.hasEdge=function(t,e,r){var n=arguments.length===1?Ib(this._isDirected,arguments[0]):Xc(this._isDirected,t,e,r);return _e.has(this._edgeLabels,n)},Le.prototype.removeEdge=function(t,e,r){var n=arguments.length===1?Ib(this._isDirected,arguments[0]):Xc(this._isDirected,t,e,r),i=this._edgeObjs[n];return i&&(t=i.v,e=i.w,delete this._edgeLabels[n],delete this._edgeObjs[n],WC(this._preds[e],t),WC(this._sucs[t],e),delete this._in[e][n],delete this._out[t][n],this._edgeCount--),this},Le.prototype.inEdges=function(t,e){var r=this._in[t];if(r){var n=_e.values(r);return e?_e.filter(n,function(i){return i.v===e}):n}},Le.prototype.outEdges=function(t,e){var r=this._out[t];if(r){var n=_e.values(r);return e?_e.filter(n,function(i){return i.w===e}):n}},Le.prototype.nodeEdges=function(t,e){var r=this.inEdges(t,e);if(r)return r.concat(this.outEdges(t,e))};function UC(t,e){t[e]?t[e]++:t[e]=1}function WC(t,e){--t[e]||delete t[e]}function Xc(t,e,r,n){var i=""+e,a=""+r;if(!t&&i>a){var s=i;i=a,a=s}return i+YC+a+YC+(_e.isUndefined(n)?PQ:n)}function qQ(t,e,r,n){var i=""+e,a=""+r;if(!t&&i>a){var s=i;i=a,a=s}var o={v:i,w:a};return n&&(o.name=n),o}function Ib(t,e){return Xc(t,e.v,e.w,e.name)}var VQ="2.1.8",zQ={Graph:Rb,version:VQ},Pi=Wn,YQ=Rb,UQ={write:WQ,read:jQ};function WQ(t){var e={options:{directed:t.isDirected(),multigraph:t.isMultigraph(),compound:t.isCompound()},nodes:HQ(t),edges:GQ(t)};return Pi.isUndefined(t.graph())||(e.value=Pi.clone(t.graph())),e}function HQ(t){return Pi.map(t.nodes(),function(e){var r=t.node(e),n=t.parent(e),i={v:e};return Pi.isUndefined(r)||(i.value=r),Pi.isUndefined(n)||(i.parent=n),i})}function GQ(t){return Pi.map(t.edges(),function(e){var r=t.edge(e),n={v:e.v,w:e.w};return Pi.isUndefined(e.name)||(n.name=e.name),Pi.isUndefined(r)||(n.value=r),n})}function jQ(t){var e=new YQ(t.options).setGraph(t.value);return Pi.each(t.nodes,function(r){e.setNode(r.v,r.value),r.parent&&e.setParent(r.v,r.parent)}),Pi.each(t.edges,function(r){e.setEdge({v:r.v,w:r.w,name:r.name},r.value)}),e}var O1=Wn,$Q=XQ;function XQ(t){var e={},r=[],n;function i(a){O1.has(e,a)||(e[a]=!0,n.push(a),O1.each(t.successors(a),i),O1.each(t.predecessors(a),i))}return O1.each(t.nodes(),function(a){n=[],i(a),n.length&&r.push(n)}),r}var HC=Wn,GC=Hn;function Hn(){this._arr=[],this._keyIndices={}}Hn.prototype.size=function(){return this._arr.length},Hn.prototype.keys=function(){return this._arr.map(function(t){return t.key})},Hn.prototype.has=function(t){return HC.has(this._keyIndices,t)},Hn.prototype.priority=function(t){var e=this._keyIndices[t];if(e!==void 0)return this._arr[e].priority},Hn.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},Hn.prototype.add=function(t,e){var r=this._keyIndices;if(t=String(t),!HC.has(r,t)){var n=this._arr,i=n.length;return r[t]=i,n.push({key:t,priority:e}),this._decrease(i),!0}return!1},Hn.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key},Hn.prototype.decrease=function(t,e){var r=this._keyIndices[t];if(e>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+e);this._arr[r].priority=e,this._decrease(r)},Hn.prototype._heapify=function(t){var e=this._arr,r=2*t,n=r+1,i=t;r<e.length&&(i=e[r].priority<e[i].priority?r:i,n<e.length&&(i=e[n].priority<e[i].priority?n:i),i!==t&&(this._swap(t,i),this._heapify(i)))},Hn.prototype._decrease=function(t){for(var e=this._arr,r=e[t].priority,n;t!==0&&(n=t>>1,!(e[n].priority<r));)this._swap(t,n),t=n},Hn.prototype._swap=function(t,e){var r=this._arr,n=this._keyIndices,i=r[t],a=r[e];r[t]=a,r[e]=i,n[a.key]=t,n[i.key]=e};var KQ=Wn,ZQ=GC,jC=JQ,QQ=KQ.constant(1);function JQ(t,e,r,n){return tJ(t,String(e),r||QQ,n||function(i){return t.outEdges(i)})}function tJ(t,e,r,n){var i={},a=new ZQ,s,o,l=function(u){var h=u.v!==s?u.v:u.w,d=i[h],f=r(u),p=o.distance+f;if(f<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+u+" Weight: "+f);p<d.distance&&(d.distance=p,d.predecessor=s,a.decrease(h,p))};for(t.nodes().forEach(function(u){var h=u===e?0:Number.POSITIVE_INFINITY;i[u]={distance:h},a.add(u,h)});a.size()>0&&(s=a.removeMin(),o=i[s],o.distance!==Number.POSITIVE_INFINITY);)n(s).forEach(l);return i}var eJ=jC,rJ=Wn,nJ=iJ;function iJ(t,e,r){return rJ.transform(t.nodes(),function(n,i){n[i]=eJ(t,i,e,r)},{})}var $C=Wn,XC=aJ;function aJ(t){var e=0,r=[],n={},i=[];function a(s){var o=n[s]={onStack:!0,lowlink:e,index:e++};if(r.push(s),t.successors(s).forEach(function(h){$C.has(n,h)?n[h].onStack&&(o.lowlink=Math.min(o.lowlink,n[h].index)):(a(h),o.lowlink=Math.min(o.lowlink,n[h].lowlink))}),o.lowlink===o.index){var l=[],u;do u=r.pop(),n[u].onStack=!1,l.push(u);while(s!==u);i.push(l)}}return t.nodes().forEach(function(s){$C.has(n,s)||a(s)}),i}var sJ=Wn,oJ=XC,lJ=cJ;function cJ(t){return sJ.filter(oJ(t),function(e){return e.length>1||e.length===1&&t.hasEdge(e[0],e[0])})}var uJ=Wn,hJ=dJ,fJ=uJ.constant(1);function dJ(t,e,r){return pJ(t,e||fJ,r||function(n){return t.outEdges(n)})}function pJ(t,e,r){var n={},i=t.nodes();return i.forEach(function(a){n[a]={},n[a][a]={distance:0},i.forEach(function(s){a!==s&&(n[a][s]={distance:Number.POSITIVE_INFINITY})}),r(a).forEach(function(s){var o=s.v===a?s.w:s.v,l=e(s);n[a][o]={distance:l,predecessor:a}})}),i.forEach(function(a){var s=n[a];i.forEach(function(o){var l=n[o];i.forEach(function(u){var h=l[a],d=s[u],f=l[u],p=h.distance+d.distance;p<f.distance&&(f.distance=p,f.predecessor=d.predecessor)})})}),n}var Kc=Wn,KC=ZC;ZC.CycleException=F1;function ZC(t){var e={},r={},n=[];function i(a){if(Kc.has(r,a))throw new F1;Kc.has(e,a)||(r[a]=!0,e[a]=!0,Kc.each(t.predecessors(a),i),delete r[a],n.push(a))}if(Kc.each(t.sinks(),i),Kc.size(e)!==t.nodeCount())throw new F1;return n}function F1(){}F1.prototype=new Error;var QC=KC,gJ=yJ;function yJ(t){try{QC(t)}catch(e){if(e instanceof QC.CycleException)return!1;throw e}return!0}var P1=Wn,JC=mJ;function mJ(t,e,r){P1.isArray(e)||(e=[e]);var n=(t.isDirected()?t.successors:t.neighbors).bind(t),i=[],a={};return P1.each(e,function(s){if(!t.hasNode(s))throw new Error("Graph does not have node: "+s);tS(t,s,r==="post",a,n,i)}),i}function tS(t,e,r,n,i,a){P1.has(n,e)||(n[e]=!0,r||a.push(e),P1.each(i(e),function(s){tS(t,s,r,n,i,a)}),r&&a.push(e))}var bJ=JC,_J=vJ;function vJ(t,e){return bJ(t,e,"post")}var xJ=JC,kJ=wJ;function wJ(t,e){return xJ(t,e,"pre")}var eS=Wn,TJ=Rb,EJ=GC,CJ=SJ;function SJ(t,e){var r=new TJ,n={},i=new EJ,a;function s(l){var u=l.v===a?l.w:l.v,h=i.priority(u);if(h!==void 0){var d=e(l);d<h&&(n[u]=a,i.decrease(u,d))}}if(t.nodeCount()===0)return r;eS.each(t.nodes(),function(l){i.add(l,Number.POSITIVE_INFINITY),r.setNode(l)}),i.decrease(t.nodes()[0],0);for(var o=!1;i.size()>0;){if(a=i.removeMin(),eS.has(n,a))r.setEdge(a,n[a]);else{if(o)throw new Error("Input graph is not connected: "+t);o=!0}t.nodeEdges(a).forEach(s)}return r}var AJ={components:$Q,dijkstra:jC,dijkstraAll:nJ,findCycles:lJ,floydWarshall:hJ,isAcyclic:gJ,postorder:_J,preorder:kJ,prim:CJ,tarjan:XC,topsort:KC},rS=zQ,cr={Graph:rS.Graph,json:UQ,alg:AJ,version:rS.version},Nb,nS;function yi(){if(nS)return Nb;nS=1;var t;if(typeof fn=="function")try{t=cr}catch{}return t||(t=window.graphlib),Nb=t,Nb}var Bb,iS;function MJ(){if(iS)return Bb;iS=1;var t=zT(),e=1,r=4;function n(i){return t(i,e|r)}return Bb=n,Bb}var Db,aS;function q1(){if(aS)return Db;aS=1;var t=Wo,e=oa(),r=T1(),n=Vn;function i(a,s,o){if(!n(o))return!1;var l=typeof s;return(l=="number"?e(o)&&r(s,o.length):l=="string"&&s in o)?t(o[s],a):!1}return Db=i,Db}var Ob,sS;function oS(){if(sS)return Ob;sS=1;var t=B1(),e=Wo,r=q1(),n=Ws(),i=Object.prototype,a=i.hasOwnProperty,s=t(function(o,l){o=Object(o);var u=-1,h=l.length,d=h>2?l[2]:void 0;for(d&&r(l[0],l[1],d)&&(h=1);++u<h;)for(var f=l[u],p=n(f),m=-1,_=p.length;++m<_;){var y=p[m],b=o[y];(b===void 0||e(b,i[y])&&!a.call(o,y))&&(o[y]=f[y])}return o});return Ob=s,Ob}var Fb,lS;function LJ(){if(lS)return Fb;lS=1;var t=la(),e=oa(),r=ts();function n(i){return function(a,s,o){var l=Object(a);if(!e(a)){var u=t(s,3);a=r(a),s=function(d){return u(l[d],d,l)}}var h=i(a,s,o);return h>-1?l[u?a[h]:h]:void 0}}return Fb=n,Fb}var Pb,cS;function RJ(){if(cS)return Pb;cS=1;var t=/\s/;function e(r){for(var n=r.length;n--&&t.test(r.charAt(n)););return n}return Pb=e,Pb}var qb,uS;function IJ(){if(uS)return qb;uS=1;var t=RJ(),e=/^\s+/;function r(n){return n&&n.slice(0,t(n)+1).replace(e,"")}return qb=r,qb}var Vb,hS;function NJ(){if(hS)return Vb;hS=1;var t=IJ(),e=Vn,r=rl(),n=0/0,i=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,s=/^0o[0-7]+$/i,o=parseInt;function l(u){if(typeof u=="number")return u;if(r(u))return n;if(e(u)){var h=typeof u.valueOf=="function"?u.valueOf():u;u=e(h)?h+"":h}if(typeof u!="string")return u===0?u:+u;u=t(u);var d=a.test(u);return d||s.test(u)?o(u.slice(2),d?2:8):i.test(u)?n:+u}return Vb=l,Vb}var zb,fS;function dS(){if(fS)return zb;fS=1;var t=NJ(),e=1/0,r=17976931348623157e292;function n(i){if(!i)return i===0?i:0;if(i=t(i),i===e||i===-e){var a=i<0?-1:1;return a*r}return i===i?i:0}return zb=n,zb}var Yb,pS;function BJ(){if(pS)return Yb;pS=1;var t=dS();function e(r){var n=t(r),i=n%1;return n===n?i?n-i:n:0}return Yb=e,Yb}var Ub,gS;function DJ(){if(gS)return Ub;gS=1;var t=SC(),e=la(),r=BJ(),n=Math.max;function i(a,s,o){var l=a==null?0:a.length;if(!l)return-1;var u=o==null?0:r(o);return u<0&&(u=n(l+u,0)),t(a,e(s,3),u)}return Ub=i,Ub}var Wb,yS;function OJ(){if(yS)return Wb;yS=1;var t=LJ(),e=DJ(),r=t(e);return Wb=r,Wb}var Hb,mS;function bS(){if(mS)return Hb;mS=1;var t=hb();function e(r){var n=r==null?0:r.length;return n?t(r,1):[]}return Hb=e,Hb}var Gb,_S;function FJ(){if(_S)return Gb;_S=1;var t=Zy(),e=ZT(),r=Ws();function n(i,a){return i==null?i:t(i,e(a),r)}return Gb=n,Gb}var jb,vS;function PJ(){if(vS)return jb;vS=1;function t(e){var r=e==null?0:e.length;return r?e[r-1]:void 0}return jb=t,jb}var $b,xS;function qJ(){if(xS)return $b;xS=1;var t=x1(),e=Jy(),r=la();function n(i,a){var s={};return a=r(a,3),e(i,function(o,l,u){t(s,l,a(o,l,u))}),s}return $b=n,$b}var Xb,kS;function Kb(){if(kS)return Xb;kS=1;var t=rl();function e(r,n,i){for(var a=-1,s=r.length;++a<s;){var o=r[a],l=n(o);if(l!=null&&(u===void 0?l===l&&!t(l):i(l,u)))var u=l,h=o}return h}return Xb=e,Xb}var Zb,wS;function VJ(){if(wS)return Zb;wS=1;function t(e,r){return e>r}return Zb=t,Zb}var Qb,TS;function zJ(){if(TS)return Qb;TS=1;var t=Kb(),e=VJ(),r=Hs();function n(i){return i&&i.length?t(i,r,e):void 0}return Qb=n,Qb}var Jb,ES;function CS(){if(ES)return Jb;ES=1;var t=x1(),e=Wo;function r(n,i,a){(a!==void 0&&!e(n[i],a)||a===void 0&&!(i in n))&&t(n,i,a)}return Jb=r,Jb}var t3,SS;function AS(){if(SS)return t3;SS=1;var t=Ps,e=M1(),r=Fi(),n="[object Object]",i=Function.prototype,a=Object.prototype,s=i.toString,o=a.hasOwnProperty,l=s.call(Object);function u(h){if(!r(h)||t(h)!=n)return!1;var d=e(h);if(d===null)return!0;var f=o.call(d,"constructor")&&d.constructor;return typeof f=="function"&&f instanceof f&&s.call(f)==l}return t3=u,t3}var e3,MS;function LS(){if(MS)return e3;MS=1;function t(e,r){if(!(r==="constructor"&&typeof e[r]=="function")&&r!="__proto__")return e[r]}return e3=t,e3}var r3,RS;function YJ(){if(RS)return r3;RS=1;var t=Hc(),e=Ws();function r(n){return t(n,e(n))}return r3=r,r3}var n3,IS;function UJ(){if(IS)return n3;IS=1;var t=CS(),e=Z9(),r=LT(),n=J9(),i=DT(),a=Gc(),s=gr(),o=FC(),l=tl(),u=Yo,h=Vn,d=AS(),f=jc(),p=LS(),m=YJ();function _(y,b,x,k,T,C,M){var S=p(y,x),R=p(b,x),A=M.get(R);if(A){t(y,x,A);return}var L=C?C(S,R,x+"",y,b,M):void 0,v=L===void 0;if(v){var B=s(R),w=!B&&l(R),D=!B&&!w&&f(R);L=R,B||w||D?s(S)?L=S:o(S)?L=n(S):w?(v=!1,L=e(R,!0)):D?(v=!1,L=r(R,!0)):L=[]:d(R)||a(R)?(L=S,a(S)?L=m(S):(!h(S)||u(S))&&(L=i(R))):v=!1}v&&(M.set(R,L),T(L,R,k,C,M),M.delete(R)),t(y,x,L)}return n3=_,n3}var i3,NS;function WJ(){if(NS)return i3;NS=1;var t=v1(),e=CS(),r=Zy(),n=UJ(),i=Vn,a=Ws(),s=LS();function o(l,u,h,d,f){l!==u&&r(u,function(p,m){if(f||(f=new t),i(p))n(l,u,m,h,o,d,f);else{var _=d?d(s(l,m),p,m+"",l,u,f):void 0;_===void 0&&(_=p),e(l,m,_)}},a)}return i3=o,i3}var a3,BS;function HJ(){if(BS)return a3;BS=1;var t=B1(),e=q1();function r(n){return t(function(i,a){var s=-1,o=a.length,l=o>1?a[o-1]:void 0,u=o>2?a[2]:void 0;for(l=n.length>3&&typeof l=="function"?(o--,l):void 0,u&&e(a[0],a[1],u)&&(l=o<3?void 0:l,o=1),i=Object(i);++s<o;){var h=a[s];h&&n(i,h,s,l)}return i})}return a3=r,a3}var s3,DS;function GJ(){if(DS)return s3;DS=1;var t=WJ(),e=HJ(),r=e(function(n,i,a){t(n,i,a)});return s3=r,s3}var o3,OS;function FS(){if(OS)return o3;OS=1;function t(e,r){return e<r}return o3=t,o3}var l3,PS;function jJ(){if(PS)return l3;PS=1;var t=Kb(),e=FS(),r=Hs();function n(i){return i&&i.length?t(i,r,e):void 0}return l3=n,l3}var c3,qS;function $J(){if(qS)return c3;qS=1;var t=Kb(),e=la(),r=FS();function n(i,a){return i&&i.length?t(i,e(a,2),r):void 0}return c3=n,c3}var u3,VS;function XJ(){if(VS)return u3;VS=1;var t=si,e=function(){return t.Date.now()};return u3=e,u3}var h3,zS;function KJ(){if(zS)return h3;zS=1;var t=k1(),e=I1(),r=T1(),n=Vn,i=$c();function a(s,o,l,u){if(!n(s))return s;o=e(o,s);for(var h=-1,d=o.length,f=d-1,p=s;p!=null&&++h<d;){var m=i(o[h]),_=l;if(m==="__proto__"||m==="constructor"||m==="prototype")return s;if(h!=f){var y=p[m];_=u?u(y,m,p):void 0,_===void 0&&(_=n(y)?y:r(o[h+1])?[]:{})}t(p,m,_),p=p[m]}return s}return h3=a,h3}var f3,YS;function ZJ(){if(YS)return f3;YS=1;var t=N1(),e=KJ(),r=I1();function n(i,a,s){for(var o=-1,l=a.length,u={};++o<l;){var h=a[o],d=t(i,h);s(d,h)&&e(u,r(h,i),d)}return u}return f3=n,f3}var d3,US;function QJ(){if(US)return d3;US=1;var t=ZJ(),e=zE();function r(n,i){return t(n,i,function(a,s){return e(n,s)})}return d3=r,d3}var p3,WS;function JJ(){if(WS)return p3;WS=1;var t=bS(),e=vC(),r=TC();function n(i){return r(e(i,void 0,t),i+"")}return p3=n,p3}var g3,HS;function GS(){if(HS)return g3;HS=1;var t=QJ(),e=JJ(),r=e(function(n,i){return n==null?{}:t(n,i)});return g3=r,g3}var y3,jS;function ttt(){if(jS)return y3;jS=1;var t=Math.ceil,e=Math.max;function r(n,i,a,s){for(var o=-1,l=e(t((i-n)/(a||1)),0),u=Array(l);l--;)u[s?l:++o]=n,n+=a;return u}return y3=r,y3}var m3,$S;function ett(){if($S)return m3;$S=1;var t=ttt(),e=q1(),r=dS();function n(i){return function(a,s,o){return o&&typeof o!="number"&&e(a,s,o)&&(s=o=void 0),a=r(a),s===void 0?(s=a,a=0):s=r(s),o=o===void 0?a<s?1:-1:r(o),t(a,s,o,i)}}return m3=n,m3}var b3,XS;function KS(){if(XS)return b3;XS=1;var t=ett(),e=t();return b3=e,b3}var _3,ZS;function rtt(){if(ZS)return _3;ZS=1;function t(e,r){var n=e.length;for(e.sort(r);n--;)e[n]=e[n].value;return e}return _3=t,_3}var v3,QS;function ntt(){if(QS)return v3;QS=1;var t=rl();function e(r,n){if(r!==n){var i=r!==void 0,a=r===null,s=r===r,o=t(r),l=n!==void 0,u=n===null,h=n===n,d=t(n);if(!u&&!d&&!o&&r>n||o&&l&&h&&!u&&!d||a&&l&&h||!i&&h||!s)return 1;if(!a&&!o&&!d&&r<n||d&&i&&s&&!a&&!o||u&&i&&s||!l&&s||!h)return-1}return 0}return v3=e,v3}var x3,JS;function itt(){if(JS)return x3;JS=1;var t=ntt();function e(r,n,i){for(var a=-1,s=r.criteria,o=n.criteria,l=s.length,u=i.length;++a<l;){var h=t(s[a],o[a]);if(h){if(a>=u)return h;var d=i[a];return h*(d=="desc"?-1:1)}}return r.index-n.index}return x3=e,x3}var k3,tA;function att(){if(tA)return k3;tA=1;var t=R1(),e=N1(),r=la(),n=rC(),i=rtt(),a=E1(),s=itt(),o=Hs(),l=gr();function u(h,d,f){d.length?d=t(d,function(_){return l(_)?function(y){return e(y,_.length===1?_[0]:_)}:_}):d=[o];var p=-1;d=t(d,a(r));var m=n(h,function(_,y,b){var x=t(d,function(k){return k(_)});return{criteria:x,index:++p,value:_}});return i(m,function(_,y){return s(_,y,f)})}return k3=u,k3}var w3,eA;function stt(){if(eA)return w3;eA=1;var t=hb(),e=att(),r=B1(),n=q1(),i=r(function(a,s){if(a==null)return[];var o=s.length;return o>1&&n(a,s[0],s[1])?s=[]:o>2&&n(s[0],s[1],s[2])&&(s=[s[0]]),e(a,t(s,1),[])});return w3=i,w3}var T3,rA;function nA(){if(rA)return T3;rA=1;var t=IE(),e=0;function r(n){var i=++e;return t(n)+i}return T3=r,T3}var E3,iA;function ott(){if(iA)return E3;iA=1;function t(e,r,n){for(var i=-1,a=e.length,s=r.length,o={};++i<a;){var l=i<s?r[i]:void 0;n(o,e[i],l)}return o}return E3=t,E3}var C3,aA;function ltt(){if(aA)return C3;aA=1;var t=k1(),e=ott();function r(n,i){return e(n||[],i||[],t)}return C3=r,C3}var S3,sA;function $e(){if(sA)return S3;sA=1;var t;if(typeof fn=="function")try{t={cloneDeep:MJ(),constant:jy(),defaults:oS(),each:am(),filter:XE(),find:OJ(),flatten:bS(),forEach:JT(),forIn:FJ(),has:$m(),isUndefined:tC(),last:PJ(),map:iC(),mapValues:qJ(),max:zJ(),merge:GJ(),min:jJ(),minBy:$J(),now:XJ(),pick:GS(),range:KS(),reduce:lC(),sortBy:stt(),uniqueId:nA(),values:zC(),zipObject:ltt()}}catch{}return t||(t=window._),S3=t,S3}var A3,oA;function ctt(){if(oA)return A3;oA=1,A3=t;function t(){var n={};n._next=n._prev=n,this._sentinel=n}t.prototype.dequeue=function(){var n=this._sentinel,i=n._prev;if(i!==n)return e(i),i},t.prototype.enqueue=function(n){var i=this._sentinel;n._prev&&n._next&&e(n),n._next=i._next,i._next._prev=n,i._next=n,n._prev=i},t.prototype.toString=function(){for(var n=[],i=this._sentinel,a=i._prev;a!==i;)n.push(JSON.stringify(a,r)),a=a._prev;return"["+n.join(", ")+"]"};function e(n){n._prev._next=n._next,n._next._prev=n._prev,delete n._next,delete n._prev}function r(n,i){if(n!=="_next"&&n!=="_prev")return i}return A3}var M3,lA;function utt(){if(lA)return M3;lA=1;var t=$e(),e=yi().Graph,r=ctt();M3=i;var n=t.constant(1);function i(u,h){if(u.nodeCount()<=1)return[];var d=o(u,h||n),f=a(d.graph,d.buckets,d.zeroIdx);return t.flatten(t.map(f,function(p){return u.outEdges(p.v,p.w)}),!0)}function a(u,h,d){for(var f=[],p=h[h.length-1],m=h[0],_;u.nodeCount();){for(;_=m.dequeue();)s(u,h,d,_);for(;_=p.dequeue();)s(u,h,d,_);if(u.nodeCount()){for(var y=h.length-2;y>0;--y)if(_=h[y].dequeue(),_){f=f.concat(s(u,h,d,_,!0));break}}}return f}function s(u,h,d,f,p){var m=p?[]:void 0;return t.forEach(u.inEdges(f.v),function(_){var y=u.edge(_),b=u.node(_.v);p&&m.push({v:_.v,w:_.w}),b.out-=y,l(h,d,b)}),t.forEach(u.outEdges(f.v),function(_){var y=u.edge(_),b=_.w,x=u.node(b);x.in-=y,l(h,d,x)}),u.removeNode(f.v),m}function o(u,h){var d=new e,f=0,p=0;t.forEach(u.nodes(),function(y){d.setNode(y,{v:y,in:0,out:0})}),t.forEach(u.edges(),function(y){var b=d.edge(y.v,y.w)||0,x=h(y),k=b+x;d.setEdge(y.v,y.w,k),p=Math.max(p,d.node(y.v).out+=x),f=Math.max(f,d.node(y.w).in+=x)});var m=t.range(p+f+3).map(function(){return new r}),_=f+1;return t.forEach(d.nodes(),function(y){l(m,_,d.node(y))}),{graph:d,buckets:m,zeroIdx:_}}function l(u,h,d){d.out?d.in?u[d.out-d.in+h].enqueue(d):u[u.length-1].enqueue(d):u[0].enqueue(d)}return M3}var L3,cA;function htt(){if(cA)return L3;cA=1;var t=$e(),e=utt();L3={run:r,undo:i};function r(a){var s=a.graph().acyclicer==="greedy"?e(a,o(a)):n(a);t.forEach(s,function(l){var u=a.edge(l);a.removeEdge(l),u.forwardName=l.name,u.reversed=!0,a.setEdge(l.w,l.v,u,t.uniqueId("rev"))});function o(l){return function(u){return l.edge(u).weight}}}function n(a){var s=[],o={},l={};function u(h){t.has(l,h)||(l[h]=!0,o[h]=!0,t.forEach(a.outEdges(h),function(d){t.has(o,d.w)?s.push(d):u(d.w)}),delete o[h])}return t.forEach(a.nodes(),u),s}function i(a){t.forEach(a.edges(),function(s){var o=a.edge(s);if(o.reversed){a.removeEdge(s);var l=o.forwardName;delete o.reversed,delete o.forwardName,a.setEdge(s.w,s.v,o,l)}})}return L3}var R3,uA;function vn(){if(uA)return R3;uA=1;var t=$e(),e=yi().Graph;R3={addDummyNode:r,simplify:n,asNonCompoundGraph:i,successorWeights:a,predecessorWeights:s,intersectRect:o,buildLayerMatrix:l,normalizeRanks:u,removeEmptyRanks:h,addBorderNode:d,maxRank:f,partition:p,time:m,notime:_};function r(y,b,x,k){var T;do T=t.uniqueId(k);while(y.hasNode(T));return x.dummy=b,y.setNode(T,x),T}function n(y){var b=new e().setGraph(y.graph());return t.forEach(y.nodes(),function(x){b.setNode(x,y.node(x))}),t.forEach(y.edges(),function(x){var k=b.edge(x.v,x.w)||{weight:0,minlen:1},T=y.edge(x);b.setEdge(x.v,x.w,{weight:k.weight+T.weight,minlen:Math.max(k.minlen,T.minlen)})}),b}function i(y){var b=new e({multigraph:y.isMultigraph()}).setGraph(y.graph());return t.forEach(y.nodes(),function(x){y.children(x).length||b.setNode(x,y.node(x))}),t.forEach(y.edges(),function(x){b.setEdge(x,y.edge(x))}),b}function a(y){var b=t.map(y.nodes(),function(x){var k={};return t.forEach(y.outEdges(x),function(T){k[T.w]=(k[T.w]||0)+y.edge(T).weight}),k});return t.zipObject(y.nodes(),b)}function s(y){var b=t.map(y.nodes(),function(x){var k={};return t.forEach(y.inEdges(x),function(T){k[T.v]=(k[T.v]||0)+y.edge(T).weight}),k});return t.zipObject(y.nodes(),b)}function o(y,b){var x=y.x,k=y.y,T=b.x-x,C=b.y-k,M=y.width/2,S=y.height/2;if(!T&&!C)throw new Error("Not possible to find intersection inside of the rectangle");var R,A;return Math.abs(C)*M>Math.abs(T)*S?(C<0&&(S=-S),R=S*T/C,A=S):(T<0&&(M=-M),R=M,A=M*C/T),{x:x+R,y:k+A}}function l(y){var b=t.map(t.range(f(y)+1),function(){return[]});return t.forEach(y.nodes(),function(x){var k=y.node(x),T=k.rank;t.isUndefined(T)||(b[T][k.order]=x)}),b}function u(y){var b=t.min(t.map(y.nodes(),function(x){return y.node(x).rank}));t.forEach(y.nodes(),function(x){var k=y.node(x);t.has(k,"rank")&&(k.rank-=b)})}function h(y){var b=t.min(t.map(y.nodes(),function(C){return y.node(C).rank})),x=[];t.forEach(y.nodes(),function(C){var M=y.node(C).rank-b;x[M]||(x[M]=[]),x[M].push(C)});var k=0,T=y.graph().nodeRankFactor;t.forEach(x,function(C,M){t.isUndefined(C)&&M%T!==0?--k:k&&t.forEach(C,function(S){y.node(S).rank+=k})})}function d(y,b,x,k){var T={width:0,height:0};return arguments.length>=4&&(T.rank=x,T.order=k),r(y,"border",T,b)}function f(y){return t.max(t.map(y.nodes(),function(b){var x=y.node(b).rank;if(!t.isUndefined(x))return x}))}function p(y,b){var x={lhs:[],rhs:[]};return t.forEach(y,function(k){b(k)?x.lhs.push(k):x.rhs.push(k)}),x}function m(y,b){var x=t.now();try{return b()}finally{console.log(y+" time: "+(t.now()-x)+"ms")}}function _(y,b){return b()}return R3}var I3,hA;function ftt(){if(hA)return I3;hA=1;var t=$e(),e=vn();I3={run:r,undo:i};function r(a){a.graph().dummyChains=[],t.forEach(a.edges(),function(s){n(a,s)})}function n(a,s){var o=s.v,l=a.node(o).rank,u=s.w,h=a.node(u).rank,d=s.name,f=a.edge(s),p=f.labelRank;if(h!==l+1){a.removeEdge(s);var m,_,y;for(y=0,++l;l<h;++y,++l)f.points=[],_={width:0,height:0,edgeLabel:f,edgeObj:s,rank:l},m=e.addDummyNode(a,"edge",_,"_d"),l===p&&(_.width=f.width,_.height=f.height,_.dummy="edge-label",_.labelpos=f.labelpos),a.setEdge(o,m,{weight:f.weight},d),y===0&&a.graph().dummyChains.push(m),o=m;a.setEdge(o,u,{weight:f.weight},d)}}function i(a){t.forEach(a.graph().dummyChains,function(s){var o=a.node(s),l=o.edgeLabel,u;for(a.setEdge(o.edgeObj,l);o.dummy;)u=a.successors(s)[0],a.removeNode(s),l.points.push({x:o.x,y:o.y}),o.dummy==="edge-label"&&(l.x=o.x,l.y=o.y,l.width=o.width,l.height=o.height),s=u,o=a.node(s)})}return I3}var N3,fA;function V1(){if(fA)return N3;fA=1;var t=$e();N3={longestPath:e,slack:r};function e(n){var i={};function a(s){var o=n.node(s);if(t.has(i,s))return o.rank;i[s]=!0;var l=t.min(t.map(n.outEdges(s),function(u){return a(u.w)-n.edge(u).minlen}));return(l===Number.POSITIVE_INFINITY||l===void 0||l===null)&&(l=0),o.rank=l}t.forEach(n.sources(),a)}function r(n,i){return n.node(i.w).rank-n.node(i.v).rank-n.edge(i).minlen}return N3}var B3,dA;function pA(){if(dA)return B3;dA=1;var t=$e(),e=yi().Graph,r=V1().slack;B3=n;function n(o){var l=new e({directed:!1}),u=o.nodes()[0],h=o.nodeCount();l.setNode(u,{});for(var d,f;i(l,o)<h;)d=a(l,o),f=l.hasNode(d.v)?r(o,d):-r(o,d),s(l,o,f);return l}function i(o,l){function u(h){t.forEach(l.nodeEdges(h),function(d){var f=d.v,p=h===f?d.w:f;!o.hasNode(p)&&!r(l,d)&&(o.setNode(p,{}),o.setEdge(h,p,{}),u(p))})}return t.forEach(o.nodes(),u),o.nodeCount()}function a(o,l){return t.minBy(l.edges(),function(u){if(o.hasNode(u.v)!==o.hasNode(u.w))return r(l,u)})}function s(o,l,u){t.forEach(o.nodes(),function(h){l.node(h).rank+=u})}return B3}var D3,gA;function dtt(){if(gA)return D3;gA=1;var t=$e(),e=pA(),r=V1().slack,n=V1().longestPath,i=yi().alg.preorder,a=yi().alg.postorder,s=vn().simplify;D3=o,o.initLowLimValues=d,o.initCutValues=l,o.calcCutValue=h,o.leaveEdge=p,o.enterEdge=m,o.exchangeEdges=_;function o(k){k=s(k),n(k);var T=e(k);d(T),l(T,k);for(var C,M;C=p(T);)M=m(T,k,C),_(T,k,C,M)}function l(k,T){var C=a(k,k.nodes());C=C.slice(0,C.length-1),t.forEach(C,function(M){u(k,T,M)})}function u(k,T,C){var M=k.node(C),S=M.parent;k.edge(C,S).cutvalue=h(k,T,C)}function h(k,T,C){var M=k.node(C),S=M.parent,R=!0,A=T.edge(C,S),L=0;return A||(R=!1,A=T.edge(S,C)),L=A.weight,t.forEach(T.nodeEdges(C),function(v){var B=v.v===C,w=B?v.w:v.v;if(w!==S){var D=B===R,N=T.edge(v).weight;if(L+=D?N:-N,b(k,C,w)){var z=k.edge(C,w).cutvalue;L+=D?-z:z}}}),L}function d(k,T){arguments.length<2&&(T=k.nodes()[0]),f(k,{},1,T)}function f(k,T,C,M,S){var R=C,A=k.node(M);return T[M]=!0,t.forEach(k.neighbors(M),function(L){t.has(T,L)||(C=f(k,T,C,L,M))}),A.low=R,A.lim=C++,S?A.parent=S:delete A.parent,C}function p(k){return t.find(k.edges(),function(T){return k.edge(T).cutvalue<0})}function m(k,T,C){var M=C.v,S=C.w;T.hasEdge(M,S)||(M=C.w,S=C.v);var R=k.node(M),A=k.node(S),L=R,v=!1;R.lim>A.lim&&(L=A,v=!0);var B=t.filter(T.edges(),function(w){return v===x(k,k.node(w.v),L)&&v!==x(k,k.node(w.w),L)});return t.minBy(B,function(w){return r(T,w)})}function _(k,T,C,M){var S=C.v,R=C.w;k.removeEdge(S,R),k.setEdge(M.v,M.w,{}),d(k),l(k,T),y(k,T)}function y(k,T){var C=t.find(k.nodes(),function(S){return!T.node(S).parent}),M=i(k,C);M=M.slice(1),t.forEach(M,function(S){var R=k.node(S).parent,A=T.edge(S,R),L=!1;A||(A=T.edge(R,S),L=!0),T.node(S).rank=T.node(R).rank+(L?A.minlen:-A.minlen)})}function b(k,T,C){return k.hasEdge(T,C)}function x(k,T,C){return C.low<=T.lim&&T.lim<=C.lim}return D3}var O3,yA;function ptt(){if(yA)return O3;yA=1;var t=V1(),e=t.longestPath,r=pA(),n=dtt();O3=i;function i(l){switch(l.graph().ranker){case"network-simplex":o(l);break;case"tight-tree":s(l);break;case"longest-path":a(l);break;default:o(l)}}var a=e;function s(l){e(l),r(l)}function o(l){n(l)}return O3}var F3,mA;function gtt(){if(mA)return F3;mA=1;var t=$e();F3=e;function e(i){var a=n(i);t.forEach(i.graph().dummyChains,function(s){for(var o=i.node(s),l=o.edgeObj,u=r(i,a,l.v,l.w),h=u.path,d=u.lca,f=0,p=h[f],m=!0;s!==l.w;){if(o=i.node(s),m){for(;(p=h[f])!==d&&i.node(p).maxRank<o.rank;)f++;p===d&&(m=!1)}if(!m){for(;f<h.length-1&&i.node(p=h[f+1]).minRank<=o.rank;)f++;p=h[f]}i.setParent(s,p),s=i.successors(s)[0]}})}function r(i,a,s,o){var l=[],u=[],h=Math.min(a[s].low,a[o].low),d=Math.max(a[s].lim,a[o].lim),f,p;f=s;do f=i.parent(f),l.push(f);while(f&&(a[f].low>h||d>a[f].lim));for(p=f,f=o;(f=i.parent(f))!==p;)u.push(f);return{path:l.concat(u.reverse()),lca:p}}function n(i){var a={},s=0;function o(l){var u=s;t.forEach(i.children(l),o),a[l]={low:u,lim:s++}}return t.forEach(i.children(),o),a}return F3}var P3,bA;function ytt(){if(bA)return P3;bA=1;var t=$e(),e=vn();P3={run:r,cleanup:s};function r(o){var l=e.addDummyNode(o,"root",{},"_root"),u=i(o),h=t.max(t.values(u))-1,d=2*h+1;o.graph().nestingRoot=l,t.forEach(o.edges(),function(p){o.edge(p).minlen*=d});var f=a(o)+1;t.forEach(o.children(),function(p){n(o,l,d,f,h,u,p)}),o.graph().nodeRankFactor=d}function n(o,l,u,h,d,f,p){var m=o.children(p);if(!m.length){p!==l&&o.setEdge(l,p,{weight:0,minlen:u});return}var _=e.addBorderNode(o,"_bt"),y=e.addBorderNode(o,"_bb"),b=o.node(p);o.setParent(_,p),b.borderTop=_,o.setParent(y,p),b.borderBottom=y,t.forEach(m,function(x){n(o,l,u,h,d,f,x);var k=o.node(x),T=k.borderTop?k.borderTop:x,C=k.borderBottom?k.borderBottom:x,M=k.borderTop?h:2*h,S=T!==C?1:d-f[p]+1;o.setEdge(_,T,{weight:M,minlen:S,nestingEdge:!0}),o.setEdge(C,y,{weight:M,minlen:S,nestingEdge:!0})}),o.parent(p)||o.setEdge(l,_,{weight:0,minlen:d+f[p]})}function i(o){var l={};function u(h,d){var f=o.children(h);f&&f.length&&t.forEach(f,function(p){u(p,d+1)}),l[h]=d}return t.forEach(o.children(),function(h){u(h,1)}),l}function a(o){return t.reduce(o.edges(),function(l,u){return l+o.edge(u).weight},0)}function s(o){var l=o.graph();o.removeNode(l.nestingRoot),delete l.nestingRoot,t.forEach(o.edges(),function(u){var h=o.edge(u);h.nestingEdge&&o.removeEdge(u)})}return P3}var q3,_A;function mtt(){if(_A)return q3;_A=1;var t=$e(),e=vn();q3=r;function r(i){function a(s){var o=i.children(s),l=i.node(s);if(o.length&&t.forEach(o,a),t.has(l,"minRank")){l.borderLeft=[],l.borderRight=[];for(var u=l.minRank,h=l.maxRank+1;u<h;++u)n(i,"borderLeft","_bl",s,l,u),n(i,"borderRight","_br",s,l,u)}}t.forEach(i.children(),a)}function n(i,a,s,o,l,u){var h={width:0,height:0,rank:u,borderType:a},d=l[a][u-1],f=e.addDummyNode(i,"border",h,s);l[a][u]=f,i.setParent(f,o),d&&i.setEdge(d,f,{weight:1})}return q3}var V3,vA;function btt(){if(vA)return V3;vA=1;var t=$e();V3={adjust:e,undo:r};function e(u){var h=u.graph().rankdir.toLowerCase();(h==="lr"||h==="rl")&&n(u)}function r(u){var h=u.graph().rankdir.toLowerCase();(h==="bt"||h==="rl")&&a(u),(h==="lr"||h==="rl")&&(o(u),n(u))}function n(u){t.forEach(u.nodes(),function(h){i(u.node(h))}),t.forEach(u.edges(),function(h){i(u.edge(h))})}function i(u){var h=u.width;u.width=u.height,u.height=h}function a(u){t.forEach(u.nodes(),function(h){s(u.node(h))}),t.forEach(u.edges(),function(h){var d=u.edge(h);t.forEach(d.points,s),t.has(d,"y")&&s(d)})}function s(u){u.y=-u.y}function o(u){t.forEach(u.nodes(),function(h){l(u.node(h))}),t.forEach(u.edges(),function(h){var d=u.edge(h);t.forEach(d.points,l),t.has(d,"x")&&l(d)})}function l(u){var h=u.x;u.x=u.y,u.y=h}return V3}var z3,xA;function _tt(){if(xA)return z3;xA=1;var t=$e();z3=e;function e(r){var n={},i=t.filter(r.nodes(),function(u){return!r.children(u).length}),a=t.max(t.map(i,function(u){return r.node(u).rank})),s=t.map(t.range(a+1),function(){return[]});function o(u){if(!t.has(n,u)){n[u]=!0;var h=r.node(u);s[h.rank].push(u),t.forEach(r.successors(u),o)}}var l=t.sortBy(i,function(u){return r.node(u).rank});return t.forEach(l,o),s}return z3}var Y3,kA;function vtt(){if(kA)return Y3;kA=1;var t=$e();Y3=e;function e(n,i){for(var a=0,s=1;s<i.length;++s)a+=r(n,i[s-1],i[s]);return a}function r(n,i,a){for(var s=t.zipObject(a,t.map(a,function(f,p){return p})),o=t.flatten(t.map(i,function(f){return t.sortBy(t.map(n.outEdges(f),function(p){return{pos:s[p.w],weight:n.edge(p).weight}}),"pos")}),!0),l=1;l<a.length;)l<<=1;var u=2*l-1;l-=1;var h=t.map(new Array(u),function(){return 0}),d=0;return t.forEach(o.forEach(function(f){var p=f.pos+l;h[p]+=f.weight;for(var m=0;p>0;)p%2&&(m+=h[p+1]),p=p-1>>1,h[p]+=f.weight;d+=f.weight*m})),d}return Y3}var U3,wA;function xtt(){if(wA)return U3;wA=1;var t=$e();U3=e;function e(r,n){return t.map(n,function(i){var a=r.inEdges(i);if(a.length){var s=t.reduce(a,function(o,l){var u=r.edge(l),h=r.node(l.v);return{sum:o.sum+u.weight*h.order,weight:o.weight+u.weight}},{sum:0,weight:0});return{v:i,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:i}})}return U3}var W3,TA;function ktt(){if(TA)return W3;TA=1;var t=$e();W3=e;function e(i,a){var s={};t.forEach(i,function(l,u){var h=s[l.v]={indegree:0,in:[],out:[],vs:[l.v],i:u};t.isUndefined(l.barycenter)||(h.barycenter=l.barycenter,h.weight=l.weight)}),t.forEach(a.edges(),function(l){var u=s[l.v],h=s[l.w];!t.isUndefined(u)&&!t.isUndefined(h)&&(h.indegree++,u.out.push(s[l.w]))});var o=t.filter(s,function(l){return!l.indegree});return r(o)}function r(i){var a=[];function s(u){return function(h){h.merged||(t.isUndefined(h.barycenter)||t.isUndefined(u.barycenter)||h.barycenter>=u.barycenter)&&n(u,h)}}function o(u){return function(h){h.in.push(u),--h.indegree===0&&i.push(h)}}for(;i.length;){var l=i.pop();a.push(l),t.forEach(l.in.reverse(),s(l)),t.forEach(l.out,o(l))}return t.map(t.filter(a,function(u){return!u.merged}),function(u){return t.pick(u,["vs","i","barycenter","weight"])})}function n(i,a){var s=0,o=0;i.weight&&(s+=i.barycenter*i.weight,o+=i.weight),a.weight&&(s+=a.barycenter*a.weight,o+=a.weight),i.vs=a.vs.concat(i.vs),i.barycenter=s/o,i.weight=o,i.i=Math.min(a.i,i.i),a.merged=!0}return W3}var H3,EA;function wtt(){if(EA)return H3;EA=1;var t=$e(),e=vn();H3=r;function r(a,s){var o=e.partition(a,function(_){return t.has(_,"barycenter")}),l=o.lhs,u=t.sortBy(o.rhs,function(_){return-_.i}),h=[],d=0,f=0,p=0;l.sort(i(!!s)),p=n(h,u,p),t.forEach(l,function(_){p+=_.vs.length,h.push(_.vs),d+=_.barycenter*_.weight,f+=_.weight,p=n(h,u,p)});var m={vs:t.flatten(h,!0)};return f&&(m.barycenter=d/f,m.weight=f),m}function n(a,s,o){for(var l;s.length&&(l=t.last(s)).i<=o;)s.pop(),a.push(l.vs),o++;return o}function i(a){return function(s,o){return s.barycenter<o.barycenter?-1:s.barycenter>o.barycenter?1:a?o.i-s.i:s.i-o.i}}return H3}var G3,CA;function Ttt(){if(CA)return G3;CA=1;var t=$e(),e=xtt(),r=ktt(),n=wtt();G3=i;function i(o,l,u,h){var d=o.children(l),f=o.node(l),p=f?f.borderLeft:void 0,m=f?f.borderRight:void 0,_={};p&&(d=t.filter(d,function(C){return C!==p&&C!==m}));var y=e(o,d);t.forEach(y,function(C){if(o.children(C.v).length){var M=i(o,C.v,u,h);_[C.v]=M,t.has(M,"barycenter")&&s(C,M)}});var b=r(y,u);a(b,_);var x=n(b,h);if(p&&(x.vs=t.flatten([p,x.vs,m],!0),o.predecessors(p).length)){var k=o.node(o.predecessors(p)[0]),T=o.node(o.predecessors(m)[0]);t.has(x,"barycenter")||(x.barycenter=0,x.weight=0),x.barycenter=(x.barycenter*x.weight+k.order+T.order)/(x.weight+2),x.weight+=2}return x}function a(o,l){t.forEach(o,function(u){u.vs=t.flatten(u.vs.map(function(h){return l[h]?l[h].vs:h}),!0)})}function s(o,l){t.isUndefined(o.barycenter)?(o.barycenter=l.barycenter,o.weight=l.weight):(o.barycenter=(o.barycenter*o.weight+l.barycenter*l.weight)/(o.weight+l.weight),o.weight+=l.weight)}return G3}var j3,SA;function Ett(){if(SA)return j3;SA=1;var t=$e(),e=yi().Graph;j3=r;function r(i,a,s){var o=n(i),l=new e({compound:!0}).setGraph({root:o}).setDefaultNodeLabel(function(u){return i.node(u)});return t.forEach(i.nodes(),function(u){var h=i.node(u),d=i.parent(u);(h.rank===a||h.minRank<=a&&a<=h.maxRank)&&(l.setNode(u),l.setParent(u,d||o),t.forEach(i[s](u),function(f){var p=f.v===u?f.w:f.v,m=l.edge(p,u),_=t.isUndefined(m)?0:m.weight;l.setEdge(p,u,{weight:i.edge(f).weight+_})}),t.has(h,"minRank")&&l.setNode(u,{borderLeft:h.borderLeft[a],borderRight:h.borderRight[a]}))}),l}function n(i){for(var a;i.hasNode(a=t.uniqueId("_root")););return a}return j3}var $3,AA;function Ctt(){if(AA)return $3;AA=1;var t=$e();$3=e;function e(r,n,i){var a={},s;t.forEach(i,function(o){for(var l=r.parent(o),u,h;l;){if(u=r.parent(l),u?(h=a[u],a[u]=l):(h=s,s=l),h&&h!==l){n.setEdge(h,l);return}l=u}})}return $3}var X3,MA;function Stt(){if(MA)return X3;MA=1;var t=$e(),e=_tt(),r=vtt(),n=Ttt(),i=Ett(),a=Ctt(),s=yi().Graph,o=vn();X3=l;function l(f){var p=o.maxRank(f),m=u(f,t.range(1,p+1),"inEdges"),_=u(f,t.range(p-1,-1,-1),"outEdges"),y=e(f);d(f,y);for(var b=Number.POSITIVE_INFINITY,x,k=0,T=0;T<4;++k,++T){h(k%2?m:_,k%4>=2),y=o.buildLayerMatrix(f);var C=r(f,y);C<b&&(T=0,x=t.cloneDeep(y),b=C)}d(f,x)}function u(f,p,m){return t.map(p,function(_){return i(f,_,m)})}function h(f,p){var m=new s;t.forEach(f,function(_){var y=_.graph().root,b=n(_,y,m,p);t.forEach(b.vs,function(x,k){_.node(x).order=k}),a(_,m,b.vs)})}function d(f,p){t.forEach(p,function(m){t.forEach(m,function(_,y){f.node(_).order=y})})}return X3}var K3,LA;function Att(){if(LA)return K3;LA=1;var t=$e(),e=yi().Graph,r=vn();K3={positionX:m,findType1Conflicts:n,findType2Conflicts:i,addConflict:s,hasConflict:o,verticalAlignment:l,horizontalCompaction:u,alignCoordinates:f,findSmallestWidthAlignment:d,balance:p};function n(b,x){var k={};function T(C,M){var S=0,R=0,A=C.length,L=t.last(M);return t.forEach(M,function(v,B){var w=a(b,v),D=w?b.node(w).order:A;(w||v===L)&&(t.forEach(M.slice(R,B+1),function(N){t.forEach(b.predecessors(N),function(z){var X=b.node(z),ct=X.order;(ct<S||D<ct)&&!(X.dummy&&b.node(N).dummy)&&s(k,z,N)})}),R=B+1,S=D)}),M}return t.reduce(x,T),k}function i(b,x){var k={};function T(M,S,R,A,L){var v;t.forEach(t.range(S,R),function(B){v=M[B],b.node(v).dummy&&t.forEach(b.predecessors(v),function(w){var D=b.node(w);D.dummy&&(D.order<A||D.order>L)&&s(k,w,v)})})}function C(M,S){var R=-1,A,L=0;return t.forEach(S,function(v,B){if(b.node(v).dummy==="border"){var w=b.predecessors(v);w.length&&(A=b.node(w[0]).order,T(S,L,B,R,A),L=B,R=A)}T(S,L,S.length,A,M.length)}),S}return t.reduce(x,C),k}function a(b,x){if(b.node(x).dummy)return t.find(b.predecessors(x),function(k){return b.node(k).dummy})}function s(b,x,k){if(x>k){var T=x;x=k,k=T}var C=b[x];C||(b[x]=C={}),C[k]=!0}function o(b,x,k){if(x>k){var T=x;x=k,k=T}return t.has(b[x],k)}function l(b,x,k,T){var C={},M={},S={};return t.forEach(x,function(R){t.forEach(R,function(A,L){C[A]=A,M[A]=A,S[A]=L})}),t.forEach(x,function(R){var A=-1;t.forEach(R,function(L){var v=T(L);if(v.length){v=t.sortBy(v,function(z){return S[z]});for(var B=(v.length-1)/2,w=Math.floor(B),D=Math.ceil(B);w<=D;++w){var N=v[w];M[L]===L&&A<S[N]&&!o(k,L,N)&&(M[N]=L,M[L]=C[L]=C[N],A=S[N])}}})}),{root:C,align:M}}function u(b,x,k,T,C){var M={},S=h(b,x,k,C),R=C?"borderLeft":"borderRight";function A(B,w){for(var D=S.nodes(),N=D.pop(),z={};N;)z[N]?B(N):(z[N]=!0,D.push(N),D=D.concat(w(N))),N=D.pop()}function L(B){M[B]=S.inEdges(B).reduce(function(w,D){return Math.max(w,M[D.v]+S.edge(D))},0)}function v(B){var w=S.outEdges(B).reduce(function(N,z){return Math.min(N,M[z.w]-S.edge(z))},Number.POSITIVE_INFINITY),D=b.node(B);w!==Number.POSITIVE_INFINITY&&D.borderType!==R&&(M[B]=Math.max(M[B],w))}return A(L,S.predecessors.bind(S)),A(v,S.successors.bind(S)),t.forEach(T,function(B){M[B]=M[k[B]]}),M}function h(b,x,k,T){var C=new e,M=b.graph(),S=_(M.nodesep,M.edgesep,T);return t.forEach(x,function(R){var A;t.forEach(R,function(L){var v=k[L];if(C.setNode(v),A){var B=k[A],w=C.edge(B,v);C.setEdge(B,v,Math.max(S(b,L,A),w||0))}A=L})}),C}function d(b,x){return t.minBy(t.values(x),function(k){var T=Number.NEGATIVE_INFINITY,C=Number.POSITIVE_INFINITY;return t.forIn(k,function(M,S){var R=y(b,S)/2;T=Math.max(M+R,T),C=Math.min(M-R,C)}),T-C})}function f(b,x){var k=t.values(x),T=t.min(k),C=t.max(k);t.forEach(["u","d"],function(M){t.forEach(["l","r"],function(S){var R=M+S,A=b[R],L;if(A!==x){var v=t.values(A);L=S==="l"?T-t.min(v):C-t.max(v),L&&(b[R]=t.mapValues(A,function(B){return B+L}))}})})}function p(b,x){return t.mapValues(b.ul,function(k,T){if(x)return b[x.toLowerCase()][T];var C=t.sortBy(t.map(b,T));return(C[1]+C[2])/2})}function m(b){var x=r.buildLayerMatrix(b),k=t.merge(n(b,x),i(b,x)),T={},C;t.forEach(["u","d"],function(S){C=S==="u"?x:t.values(x).reverse(),t.forEach(["l","r"],function(R){R==="r"&&(C=t.map(C,function(B){return t.values(B).reverse()}));var A=(S==="u"?b.predecessors:b.successors).bind(b),L=l(b,C,k,A),v=u(b,C,L.root,L.align,R==="r");R==="r"&&(v=t.mapValues(v,function(B){return-B})),T[S+R]=v})});var M=d(b,T);return f(T,M),p(T,b.graph().align)}function _(b,x,k){return function(T,C,M){var S=T.node(C),R=T.node(M),A=0,L;if(A+=S.width/2,t.has(S,"labelpos"))switch(S.labelpos.toLowerCase()){case"l":L=-S.width/2;break;case"r":L=S.width/2;break}if(L&&(A+=k?L:-L),L=0,A+=(S.dummy?x:b)/2,A+=(R.dummy?x:b)/2,A+=R.width/2,t.has(R,"labelpos"))switch(R.labelpos.toLowerCase()){case"l":L=R.width/2;break;case"r":L=-R.width/2;break}return L&&(A+=k?L:-L),L=0,A}}function y(b,x){return b.node(x).width}return K3}var Z3,RA;function Mtt(){if(RA)return Z3;RA=1;var t=$e(),e=vn(),r=Att().positionX;Z3=n;function n(a){a=e.asNonCompoundGraph(a),i(a),t.forEach(r(a),function(s,o){a.node(o).x=s})}function i(a){var s=e.buildLayerMatrix(a),o=a.graph().ranksep,l=0;t.forEach(s,function(u){var h=t.max(t.map(u,function(d){return a.node(d).height}));t.forEach(u,function(d){a.node(d).y=l+h/2}),l+=h+o})}return Z3}var Q3,IA;function Ltt(){if(IA)return Q3;IA=1;var t=$e(),e=htt(),r=ftt(),n=ptt(),i=vn().normalizeRanks,a=gtt(),s=vn().removeEmptyRanks,o=ytt(),l=mtt(),u=btt(),h=Stt(),d=Mtt(),f=vn(),p=yi().Graph;Q3=m;function m(W,tt){var K=tt&&tt.debugTiming?f.time:f.notime;K("layout",function(){var it=K(" buildLayoutGraph",function(){return A(W)});K(" runLayout",function(){_(it,K)}),K(" updateInputGraph",function(){y(W,it)})})}function _(W,tt){tt(" makeSpaceForEdgeLabels",function(){L(W)}),tt(" removeSelfEdges",function(){J(W)}),tt(" acyclic",function(){e.run(W)}),tt(" nestingGraph.run",function(){o.run(W)}),tt(" rank",function(){n(f.asNonCompoundGraph(W))}),tt(" injectEdgeLabelProxies",function(){v(W)}),tt(" removeEmptyRanks",function(){s(W)}),tt(" nestingGraph.cleanup",function(){o.cleanup(W)}),tt(" normalizeRanks",function(){i(W)}),tt(" assignRankMinMax",function(){B(W)}),tt(" removeEdgeLabelProxies",function(){w(W)}),tt(" normalize.run",function(){r.run(W)}),tt(" parentDummyChains",function(){a(W)}),tt(" addBorderSegments",function(){l(W)}),tt(" order",function(){h(W)}),tt(" insertSelfEdges",function(){Y(W)}),tt(" adjustCoordinateSystem",function(){u.adjust(W)}),tt(" position",function(){d(W)}),tt(" positionSelfEdges",function(){$(W)}),tt(" removeBorderNodes",function(){ct(W)}),tt(" normalize.undo",function(){r.undo(W)}),tt(" fixupEdgeLabelCoords",function(){z(W)}),tt(" undoCoordinateSystem",function(){u.undo(W)}),tt(" translateGraph",function(){D(W)}),tt(" assignNodeIntersects",function(){N(W)}),tt(" reversePoints",function(){X(W)}),tt(" acyclic.undo",function(){e.undo(W)})}function y(W,tt){t.forEach(W.nodes(),function(K){var it=W.node(K),Z=tt.node(K);it&&(it.x=Z.x,it.y=Z.y,tt.children(K).length&&(it.width=Z.width,it.height=Z.height))}),t.forEach(W.edges(),function(K){var it=W.edge(K),Z=tt.edge(K);it.points=Z.points,t.has(Z,"x")&&(it.x=Z.x,it.y=Z.y)}),W.graph().width=tt.graph().width,W.graph().height=tt.graph().height}var b=["nodesep","edgesep","ranksep","marginx","marginy"],x={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},k=["acyclicer","ranker","rankdir","align"],T=["width","height"],C={width:0,height:0},M=["minlen","weight","width","height","labeloffset"],S={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},R=["labelpos"];function A(W){var tt=new p({multigraph:!0,compound:!0}),K=ut(W.graph());return tt.setGraph(t.merge({},x,lt(K,b),t.pick(K,k))),t.forEach(W.nodes(),function(it){var Z=ut(W.node(it));tt.setNode(it,t.defaults(lt(Z,T),C)),tt.setParent(it,W.parent(it))}),t.forEach(W.edges(),function(it){var Z=ut(W.edge(it));tt.setEdge(it,t.merge({},S,lt(Z,M),t.pick(Z,R)))}),tt}function L(W){var tt=W.graph();tt.ranksep/=2,t.forEach(W.edges(),function(K){var it=W.edge(K);it.minlen*=2,it.labelpos.toLowerCase()!=="c"&&(tt.rankdir==="TB"||tt.rankdir==="BT"?it.width+=it.labeloffset:it.height+=it.labeloffset)})}function v(W){t.forEach(W.edges(),function(tt){var K=W.edge(tt);if(K.width&&K.height){var it=W.node(tt.v),Z=W.node(tt.w),V={rank:(Z.rank-it.rank)/2+it.rank,e:tt};f.addDummyNode(W,"edge-proxy",V,"_ep")}})}function B(W){var tt=0;t.forEach(W.nodes(),function(K){var it=W.node(K);it.borderTop&&(it.minRank=W.node(it.borderTop).rank,it.maxRank=W.node(it.borderBottom).rank,tt=t.max(tt,it.maxRank))}),W.graph().maxRank=tt}function w(W){t.forEach(W.nodes(),function(tt){var K=W.node(tt);K.dummy==="edge-proxy"&&(W.edge(K.e).labelRank=K.rank,W.removeNode(tt))})}function D(W){var tt=Number.POSITIVE_INFINITY,K=0,it=Number.POSITIVE_INFINITY,Z=0,V=W.graph(),Q=V.marginx||0,q=V.marginy||0;function U(F){var j=F.x,P=F.y,et=F.width,at=F.height;tt=Math.min(tt,j-et/2),K=Math.max(K,j+et/2),it=Math.min(it,P-at/2),Z=Math.max(Z,P+at/2)}t.forEach(W.nodes(),function(F){U(W.node(F))}),t.forEach(W.edges(),function(F){var j=W.edge(F);t.has(j,"x")&&U(j)}),tt-=Q,it-=q,t.forEach(W.nodes(),function(F){var j=W.node(F);j.x-=tt,j.y-=it}),t.forEach(W.edges(),function(F){var j=W.edge(F);t.forEach(j.points,function(P){P.x-=tt,P.y-=it}),t.has(j,"x")&&(j.x-=tt),t.has(j,"y")&&(j.y-=it)}),V.width=K-tt+Q,V.height=Z-it+q}function N(W){t.forEach(W.edges(),function(tt){var K=W.edge(tt),it=W.node(tt.v),Z=W.node(tt.w),V,Q;K.points?(V=K.points[0],Q=K.points[K.points.length-1]):(K.points=[],V=Z,Q=it),K.points.unshift(f.intersectRect(it,V)),K.points.push(f.intersectRect(Z,Q))})}function z(W){t.forEach(W.edges(),function(tt){var K=W.edge(tt);if(t.has(K,"x"))switch((K.labelpos==="l"||K.labelpos==="r")&&(K.width-=K.labeloffset),K.labelpos){case"l":K.x-=K.width/2+K.labeloffset;break;case"r":K.x+=K.width/2+K.labeloffset;break}})}function X(W){t.forEach(W.edges(),function(tt){var K=W.edge(tt);K.reversed&&K.points.reverse()})}function ct(W){t.forEach(W.nodes(),function(tt){if(W.children(tt).length){var K=W.node(tt),it=W.node(K.borderTop),Z=W.node(K.borderBottom),V=W.node(t.last(K.borderLeft)),Q=W.node(t.last(K.borderRight));K.width=Math.abs(Q.x-V.x),K.height=Math.abs(Z.y-it.y),K.x=V.x+K.width/2,K.y=it.y+K.height/2}}),t.forEach(W.nodes(),function(tt){W.node(tt).dummy==="border"&&W.removeNode(tt)})}function J(W){t.forEach(W.edges(),function(tt){if(tt.v===tt.w){var K=W.node(tt.v);K.selfEdges||(K.selfEdges=[]),K.selfEdges.push({e:tt,label:W.edge(tt)}),W.removeEdge(tt)}})}function Y(W){var tt=f.buildLayerMatrix(W);t.forEach(tt,function(K){var it=0;t.forEach(K,function(Z,V){var Q=W.node(Z);Q.order=V+it,t.forEach(Q.selfEdges,function(q){f.addDummyNode(W,"selfedge",{width:q.label.width,height:q.label.height,rank:Q.rank,order:V+ ++it,e:q.e,label:q.label},"_se")}),delete Q.selfEdges})})}function $(W){t.forEach(W.nodes(),function(tt){var K=W.node(tt);if(K.dummy==="selfedge"){var it=W.node(K.e.v),Z=it.x+it.width/2,V=it.y,Q=K.x-Z,q=it.height/2;W.setEdge(K.e,K.label),W.removeNode(tt),K.label.points=[{x:Z+2*Q/3,y:V-q},{x:Z+5*Q/6,y:V-q},{x:Z+Q,y:V},{x:Z+5*Q/6,y:V+q},{x:Z+2*Q/3,y:V+q}],K.label.x=K.x,K.label.y=K.y}})}function lt(W,tt){return t.mapValues(t.pick(W,tt),Number)}function ut(W){var tt={};return t.forEach(W,function(K,it){tt[it.toLowerCase()]=K}),tt}return Q3}var J3,NA;function Rtt(){if(NA)return J3;NA=1;var t=$e(),e=vn(),r=yi().Graph;J3={debugOrdering:n};function n(i){var a=e.buildLayerMatrix(i),s=new r({compound:!0,multigraph:!0}).setGraph({});return t.forEach(i.nodes(),function(o){s.setNode(o,{label:o}),s.setParent(o,"layer"+i.node(o).rank)}),t.forEach(i.edges(),function(o){s.setEdge(o.v,o.w,{},o.name)}),t.forEach(a,function(o,l){var u="layer"+l;s.setNode(u,{rank:"same"}),t.reduce(o,function(h,d){return s.setEdge(h,d,{style:"invis"}),d})}),s}return J3}var t4,BA;function Itt(){return BA||(BA=1,t4="0.8.5"),t4}var e4,DA;function OA(){return DA||(DA=1,e4={graphlib:yi(),layout:Ltt(),debug:Rtt(),util:{time:vn().time,notime:vn().notime},version:Itt()}),e4}var Zc=OA();let FA=0;const Ntt=function(t,e,r,n,i){const a=function(x){switch(x){case i.db.relationType.AGGREGATION:return"aggregation";case i.db.EXTENSION:return"extension";case i.db.COMPOSITION:return"composition";case i.db.DEPENDENCY:return"dependency";case i.db.LOLLIPOP:return"lollipop"}};e.points=e.points.filter(x=>!Number.isNaN(x.y));const s=e.points,o=Ua().x(function(x){return x.x}).y(function(x){return x.y}).curve(Os),l=t.append("path").attr("d",o(s)).attr("id","edge"+FA).attr("class","relation");let u="";n.arrowMarkerAbsolute&&(u=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,u=u.replace(/\(/g,"\\("),u=u.replace(/\)/g,"\\)")),r.relation.lineType==1&&l.attr("class","relation dashed-line"),r.relation.type1!=="none"&&l.attr("marker-start","url("+u+"#"+a(r.relation.type1)+"Start)"),r.relation.type2!=="none"&&l.attr("marker-end","url("+u+"#"+a(r.relation.type2)+"End)");let h,d;const f=e.points.length;let p=Se.calcLabelPosition(e.points);h=p.x,d=p.y;let m,_,y,b;if(f%2!==0&&f>1){let x=Se.calcCardinalityPosition(r.relation.type1!=="none",e.points,e.points[0]),k=Se.calcCardinalityPosition(r.relation.type2!=="none",e.points,e.points[f-1]);H.debug("cardinality_1_point "+JSON.stringify(x)),H.debug("cardinality_2_point "+JSON.stringify(k)),m=x.x,_=x.y,y=k.x,b=k.y}if(typeof r.title<"u"){const x=t.append("g").attr("class","classLabel"),k=x.append("text").attr("class","label").attr("x",h).attr("y",d).attr("fill","red").attr("text-anchor","middle").text(r.title);window.label=k;const T=k.node().getBBox();x.insert("rect",":first-child").attr("class","box").attr("x",T.x-n.padding/2).attr("y",T.y-n.padding/2).attr("width",T.width+n.padding).attr("height",T.height+n.padding)}H.info("Rendering relation "+JSON.stringify(r)),typeof r.relationTitle1<"u"&&r.relationTitle1!=="none"&&t.append("g").attr("class","cardinality").append("text").attr("class","type1").attr("x",m).attr("y",_).attr("fill","black").attr("font-size","6").text(r.relationTitle1),typeof r.relationTitle2<"u"&&r.relationTitle2!=="none"&&t.append("g").attr("class","cardinality").append("text").attr("class","type2").attr("x",y).attr("y",b).attr("fill","black").attr("font-size","6").text(r.relationTitle2),FA++},Btt=function(t,e,r,n){H.debug("Rendering class ",e,r);const i=e.id,a={id:i,label:e.id,width:0,height:0},s=t.append("g").attr("id",n.db.lookUpDomId(i)).attr("class","classGroup");let o;e.link?o=s.append("svg:a").attr("xlink:href",e.link).attr("target",e.linkTarget).append("text").attr("y",r.textHeight+r.padding).attr("x",0):o=s.append("text").attr("y",r.textHeight+r.padding).attr("x",0);let l=!0;e.annotations.forEach(function(C){const M=o.append("tspan").text("\xAB"+C+"\xBB");l||M.attr("dy",r.textHeight),l=!1});let u=e.id;e.type!==void 0&&e.type!==""&&(u+="<"+e.type+">");const h=o.append("tspan").text(u).attr("class","title");l||h.attr("dy",r.textHeight);const d=o.node().getBBox().height,f=s.append("line").attr("x1",0).attr("y1",r.padding+d+r.dividerMargin/2).attr("y2",r.padding+d+r.dividerMargin/2),p=s.append("text").attr("x",r.padding).attr("y",d+r.dividerMargin+r.textHeight).attr("fill","white").attr("class","classText");l=!0,e.members.forEach(function(C){PA(p,C,l,r),l=!1});const m=p.node().getBBox(),_=s.append("line").attr("x1",0).attr("y1",r.padding+d+r.dividerMargin+m.height).attr("y2",r.padding+d+r.dividerMargin+m.height),y=s.append("text").attr("x",r.padding).attr("y",d+2*r.dividerMargin+m.height+r.textHeight).attr("fill","white").attr("class","classText");l=!0,e.methods.forEach(function(C){PA(y,C,l,r),l=!1});const b=s.node().getBBox();var x=" ";e.cssClasses.length>0&&(x=x+e.cssClasses.join(" "));const T=s.insert("rect",":first-child").attr("x",0).attr("y",0).attr("width",b.width+2*r.padding).attr("height",b.height+r.padding+.5*r.dividerMargin).attr("class",x).node().getBBox().width;return o.node().childNodes.forEach(function(C){C.setAttribute("x",(T-C.getBBox().width)/2)}),e.tooltip&&o.insert("title").text(e.tooltip),f.attr("x2",T),_.attr("x2",T),a.width=T,a.height=b.height+r.padding+.5*r.dividerMargin,a},z1=function(t){const e=/^(\+|-|~|#)?(\w+)(~\w+~|\[\])?\s+(\w+) *(\*|\$)?$/,r=/^([+|\-|~|#])?(\w+) *\( *(.*)\) *(\*|\$)? *(\w*[~|[\]]*\s*\w*~?)$/;let n=t.match(e),i=t.match(r);return n&&!i?Dtt(n):i?Ott(i):Ftt(t)},Dtt=function(t){let e="",r="";try{let n=t[1]?t[1].trim():"",i=t[2]?t[2].trim():"",a=t[3]?ja(t[3].trim()):"",s=t[4]?t[4].trim():"",o=t[5]?t[5].trim():"";r=n+i+a+" "+s,e=r4(o)}catch{r=t}return{displayText:r,cssStyle:e}},Ott=function(t){let e="",r="";try{let n=t[1]?t[1].trim():"",i=t[2]?t[2].trim():"",a=t[3]?ja(t[3].trim()):"",s=t[4]?t[4].trim():"",o=t[5]?" : "+ja(t[5]).trim():"";r=n+i+"("+a+")"+o,e=r4(s)}catch{r=t}return{displayText:r,cssStyle:e}},Ftt=function(t){let e="",r="",n="",i=t.indexOf("("),a=t.indexOf(")");if(i>1&&a>i&&a<=t.length){let s="",o="",l=t.substring(0,1);l.match(/\w/)?o=t.substring(0,i).trim():(l.match(/\+|-|~|#/)&&(s=l),o=t.substring(1,i).trim());const u=t.substring(i+1,a);t.substring(a+1,1),r=r4(t.substring(a+1,a+2)),e=s+o+"("+ja(u.trim())+")",a<t.length&&(n=t.substring(a+2).trim(),n!==""&&(n=" : "+ja(n),e+=n))}else e=ja(t);return{displayText:e,cssStyle:r}},PA=function(t,e,r,n){let i=z1(e);const a=t.append("tspan").attr("x",n.padding).text(i.displayText);i.cssStyle!==""&&a.attr("style",i.cssStyle),r||a.attr("dy",n.textHeight)},r4=function(t){switch(t){case"*":return"font-style:italic;";case"$":return"text-decoration:underline;";default:return""}},qA={drawClass:Btt,drawEdge:Ntt,parseMember:z1};let n4={};const Y1=20,U1=function(t){const e=Object.entries(n4).find(r=>r[1].label===t);if(e)return e[0]},Ptt=function(t){t.append("defs").append("marker").attr("id","extensionStart").attr("class","extension").attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 1,7 L18,13 V 1 Z"),t.append("defs").append("marker").attr("id","extensionEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 1,1 V 13 L18,7 Z"),t.append("defs").append("marker").attr("id","compositionStart").attr("class","extension").attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),t.append("defs").append("marker").attr("id","compositionEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),t.append("defs").append("marker").attr("id","aggregationStart").attr("class","extension").attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),t.append("defs").append("marker").attr("id","aggregationEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),t.append("defs").append("marker").attr("id","dependencyStart").attr("class","extension").attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 5,7 L9,13 L1,7 L9,1 Z"),t.append("defs").append("marker").attr("id","dependencyEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L14,7 L9,1 Z")},qtt={draw:function(t,e,r,n){const i=nt().class;n4={},H.info("Rendering diagram "+t);const a=nt().securityLevel;let s;a==="sandbox"&&(s=St("#i"+e));const o=St(a==="sandbox"?s.nodes()[0].contentDocument.body:"body"),l=o.select(`[id='${e}']`);Ptt(l);const u=new cr.Graph({multigraph:!0});u.setGraph({isMultiGraph:!0}),u.setDefaultEdgeLabel(function(){return{}});const h=n.db.getClasses(),d=Object.keys(h);for(let b=0;b<d.length;b++){const x=h[d[b]],k=qA.drawClass(l,x,i,n);n4[k.id]=k,u.setNode(k.id,k),H.info("Org height: "+k.height)}n.db.getRelations().forEach(function(b){H.info("tjoho"+U1(b.id1)+U1(b.id2)+JSON.stringify(b)),u.setEdge(U1(b.id1),U1(b.id2),{relation:b},b.title||"DEFAULT")}),Zc.layout(u),u.nodes().forEach(function(b){typeof b<"u"&&typeof u.node(b)<"u"&&(H.debug("Node "+b+": "+JSON.stringify(u.node(b))),o.select("#"+n.db.lookUpDomId(b)).attr("transform","translate("+(u.node(b).x-u.node(b).width/2)+","+(u.node(b).y-u.node(b).height/2)+" )"))}),u.edges().forEach(function(b){typeof b<"u"&&typeof u.edge(b)<"u"&&(H.debug("Edge "+b.v+" -> "+b.w+": "+JSON.stringify(u.edge(b))),qA.drawEdge(l,u.edge(b),u.edge(b).relation,i,n))});const p=l.node().getBBox(),m=p.width+Y1*2,_=p.height+Y1*2;li(l,_,m,i.useMaxWidth);const y=`${p.x-Y1} ${p.y-Y1} ${m} ${_}`;H.debug(`viewBox ${y}`),l.attr("viewBox",y),bn(n.db,l,e)}},Vtt=(t,e,r,n)=>{e.forEach(i=>{ztt[i](t,r,n)})},ztt={extension:(t,e,r)=>{H.trace("Making markers for ",r),t.append("defs").append("marker").attr("id",e+"-extensionStart").attr("class","marker extension "+e).attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 1,7 L18,13 V 1 Z"),t.append("defs").append("marker").attr("id",e+"-extensionEnd").attr("class","marker extension "+e).attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 1,1 V 13 L18,7 Z")},composition:(t,e)=>{t.append("defs").append("marker").attr("id",e+"-compositionStart").attr("class","marker composition "+e).attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),t.append("defs").append("marker").attr("id",e+"-compositionEnd").attr("class","marker composition "+e).attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z")},aggregation:(t,e)=>{t.append("defs").append("marker").attr("id",e+"-aggregationStart").attr("class","marker aggregation "+e).attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),t.append("defs").append("marker").attr("id",e+"-aggregationEnd").attr("class","marker aggregation "+e).attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z")},dependency:(t,e)=>{t.append("defs").append("marker").attr("id",e+"-dependencyStart").attr("class","marker dependency "+e).attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 5,7 L9,13 L1,7 L9,1 Z"),t.append("defs").append("marker").attr("id",e+"-dependencyEnd").attr("class","marker dependency "+e).attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L14,7 L9,1 Z")},lollipop:(t,e)=>{t.append("defs").append("marker").attr("id",e+"-lollipopStart").attr("class","marker lollipop "+e).attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("circle").attr("stroke","black").attr("fill","white").attr("cx",6).attr("cy",7).attr("r",6)},point:(t,e)=>{t.append("marker").attr("id",e+"-pointEnd").attr("class","marker "+e).attr("viewBox","0 0 10 10").attr("refX",10).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",12).attr("markerHeight",12).attr("orient","auto").append("path").attr("d","M 0 0 L 10 5 L 0 10 z").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0"),t.append("marker").attr("id",e+"-pointStart").attr("class","marker "+e).attr("viewBox","0 0 10 10").attr("refX",0).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",12).attr("markerHeight",12).attr("orient","auto").append("path").attr("d","M 0 5 L 10 10 L 10 0 z").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0")},circle:(t,e)=>{t.append("marker").attr("id",e+"-circleEnd").attr("class","marker "+e).attr("viewBox","0 0 10 10").attr("refX",11).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("circle").attr("cx","5").attr("cy","5").attr("r","5").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0"),t.append("marker").attr("id",e+"-circleStart").attr("class","marker "+e).attr("viewBox","0 0 10 10").attr("refX",-1).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("circle").attr("cx","5").attr("cy","5").attr("r","5").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0")},cross:(t,e)=>{t.append("marker").attr("id",e+"-crossEnd").attr("class","marker cross "+e).attr("viewBox","0 0 11 11").attr("refX",12).attr("refY",5.2).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("path").attr("d","M 1,1 l 9,9 M 10,1 l -9,9").attr("class","arrowMarkerPath").style("stroke-width",2).style("stroke-dasharray","1,0"),t.append("marker").attr("id",e+"-crossStart").attr("class","marker cross "+e).attr("viewBox","0 0 11 11").attr("refX",-1).attr("refY",5.2).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("path").attr("d","M 1,1 l 9,9 M 10,1 l -9,9").attr("class","arrowMarkerPath").style("stroke-width",2).style("stroke-dasharray","1,0")},barb:(t,e)=>{t.append("defs").append("marker").attr("id",e+"-barbEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",14).attr("markerUnits","strokeWidth").attr("orient","auto").append("path").attr("d","M 19,7 L9,13 L14,7 L9,1 Z")}};function Ytt(t,e){e&&t.attr("style",e)}function Utt(t){const e=St(document.createElementNS("http://www.w3.org/2000/svg","foreignObject")),r=e.append("xhtml:div"),n=t.label,i=t.isNode?"nodeLabel":"edgeLabel";return r.html('<span class="'+i+'" '+(t.labelStyle?'style="'+t.labelStyle+'"':"")+">"+n+"</span>"),Ytt(r,t.labelStyle),r.style("display","inline-block"),r.style("white-space","nowrap"),r.attr("xmlns","http://www.w3.org/1999/xhtml"),e.node()}const xn=(t,e,r,n)=>{let i=t||"";if(typeof i=="object"&&(i=i[0]),Mr(nt().flowchart.htmlLabels)){i=i.replace(/\\n|\n/g,"<br />"),H.info("vertexText"+i);const a={isNode:n,label:w0(i).replace(/fa[lrsb]?:fa-[\w-]+/g,o=>`<i class='${o.replace(":"," ")}'></i>`),labelStyle:e.replace("fill:","color:")};return Utt(a)}else{const a=document.createElementNS("http://www.w3.org/2000/svg","text");a.setAttribute("style",e.replace("color:","fill:"));let s=[];typeof i=="string"?s=i.split(/\\n|\n|<br\s*\/?>/gi):Array.isArray(i)?s=i:s=[];for(let o=0;o<s.length;o++){const l=document.createElementNS("http://www.w3.org/2000/svg","tspan");l.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:space","preserve"),l.setAttribute("dy","1em"),l.setAttribute("x","0"),r?l.setAttribute("class","title-row"):l.setAttribute("class","row"),l.textContent=s[o].trim(),a.appendChild(l)}return a}},Yr=(t,e,r,n)=>{let i;r?i=r:i="node default";const a=t.insert("g").attr("class",i).attr("id",e.domId||e.id),s=a.insert("g").attr("class","label").attr("style",e.labelStyle);let o;typeof e.labelText>"u"?o="":o=typeof e.labelText=="string"?e.labelText:e.labelText[0];const l=s.node().appendChild(xn(ai(w0(o),nt()),e.labelStyle,!1,n));let u=l.getBBox();if(Mr(nt().flowchart.htmlLabels)){const d=l.children[0],f=St(l);u=d.getBoundingClientRect(),f.attr("width",u.width),f.attr("height",u.height)}const h=e.padding/2;return s.attr("transform","translate("+-u.width/2+", "+-u.height/2+")"),{shapeSvg:a,bbox:u,halfPadding:h,label:s}},ur=(t,e)=>{const r=e.node().getBBox();t.width=r.width,t.height=r.height};function ca(t,e,r,n){return t.insert("polygon",":first-child").attr("points",n.map(function(i){return i.x+","+i.y}).join(" ")).attr("class","label-container").attr("transform","translate("+-e/2+","+r/2+")")}let Re={},mi={},VA={};const Wtt=()=>{mi={},VA={},Re={}},W1=(t,e)=>(H.trace("In isDecendant",e," ",t," = ",mi[e].indexOf(t)>=0),mi[e].indexOf(t)>=0),Htt=(t,e)=>(H.info("Decendants of ",e," is ",mi[e]),H.info("Edge is ",t),t.v===e||t.w===e?!1:mi[e]?!!(mi[e].indexOf(t.v)>=0||W1(t.v,e)||W1(t.w,e)||mi[e].indexOf(t.w)>=0):(H.debug("Tilt, ",e,",not in decendants"),!1)),zA=(t,e,r,n)=>{H.warn("Copying children of ",t,"root",n,"data",e.node(t),n);const i=e.children(t)||[];t!==n&&i.push(t),H.warn("Copying (nodes) clusterId",t,"nodes",i),i.forEach(a=>{if(e.children(a).length>0)zA(a,e,r,n);else{const s=e.node(a);H.info("cp ",a," to ",n," with parent ",t),r.setNode(a,s),n!==e.parent(a)&&(H.warn("Setting parent",a,e.parent(a)),r.setParent(a,e.parent(a))),t!==n&&a!==t?(H.debug("Setting parent",a,t),r.setParent(a,t)):(H.info("In copy ",t,"root",n,"data",e.node(t),n),H.debug("Not Setting parent for node=",a,"cluster!==rootId",t!==n,"node!==clusterId",a!==t));const o=e.edges(a);H.debug("Copying Edges",o),o.forEach(l=>{H.info("Edge",l);const u=e.edge(l.v,l.w,l.name);H.info("Edge data",u,n);try{Htt(l,n)?(H.info("Copying as ",l.v,l.w,u,l.name),r.setEdge(l.v,l.w,u,l.name),H.info("newGraph edges ",r.edges(),r.edge(r.edges()[0]))):H.info("Skipping copy of edge ",l.v,"-->",l.w," rootId: ",n," clusterId:",t)}catch(h){H.error(h)}})}H.debug("Removing node",a),e.removeNode(a)})},YA=(t,e)=>{const r=e.children(t);let n=[].concat(r);for(let i=0;i<r.length;i++)VA[r[i]]=t,n=n.concat(YA(r[i],e));return n},Qc=(t,e)=>{H.trace("Searching",t);const r=e.children(t);if(H.trace("Searching children of id ",t,r),r.length<1)return H.trace("This is a valid node",t),t;for(let n=0;n<r.length;n++){const i=Qc(r[n],e);if(i)return H.trace("Found replacement for",t," => ",i),i}},H1=t=>!Re[t]||!Re[t].externalConnections?t:Re[t]?Re[t].id:t,Gtt=(t,e)=>{if(!t||e>10){H.debug("Opting out, no graph ");return}else H.debug("Opting in, graph ");t.nodes().forEach(function(r){t.children(r).length>0&&(H.warn("Cluster identified",r," Replacement id in edges: ",Qc(r,t)),mi[r]=YA(r,t),Re[r]={id:Qc(r,t),clusterData:t.node(r)})}),t.nodes().forEach(function(r){const n=t.children(r),i=t.edges();n.length>0?(H.debug("Cluster identified",r,mi),i.forEach(a=>{if(a.v!==r&&a.w!==r){const s=W1(a.v,r),o=W1(a.w,r);s^o&&(H.warn("Edge: ",a," leaves cluster ",r),H.warn("Decendants of XXX ",r,": ",mi[r]),Re[r].externalConnections=!0)}})):H.debug("Not a cluster ",r,mi)}),t.edges().forEach(function(r){const n=t.edge(r);H.warn("Edge "+r.v+" -> "+r.w+": "+JSON.stringify(r)),H.warn("Edge "+r.v+" -> "+r.w+": "+JSON.stringify(t.edge(r)));let i=r.v,a=r.w;if(H.warn("Fix XXX",Re,"ids:",r.v,r.w,"Translateing: ",Re[r.v]," --- ",Re[r.w]),Re[r.v]&&Re[r.w]&&Re[r.v]===Re[r.w]){H.warn("Fixing and trixing link to self - removing XXX",r.v,r.w,r.name),H.warn("Fixing and trixing - removing XXX",r.v,r.w,r.name),i=H1(r.v),a=H1(r.w),t.removeEdge(r.v,r.w,r.name);const s=r.w+"---"+r.v;t.setNode(s,{domId:s,id:s,labelStyle:"",labelText:n.label,padding:0,shape:"labelRect",style:""});const o=JSON.parse(JSON.stringify(n)),l=JSON.parse(JSON.stringify(n));o.label="",o.arrowTypeEnd="none",l.label="",o.fromCluster=r.v,l.toCluster=r.v,t.setEdge(i,s,o,r.name+"-cyclic-special"),t.setEdge(s,a,l,r.name+"-cyclic-special")}else(Re[r.v]||Re[r.w])&&(H.warn("Fixing and trixing - removing XXX",r.v,r.w,r.name),i=H1(r.v),a=H1(r.w),t.removeEdge(r.v,r.w,r.name),i!==r.v&&(n.fromCluster=r.v),a!==r.w&&(n.toCluster=r.w),H.warn("Fix Replacing with XXX",i,a,r.name),t.setEdge(i,a,n,r.name))}),H.warn("Adjusted Graph",cr.json.write(t)),UA(t,0),H.trace(Re)},UA=(t,e)=>{if(H.warn("extractor - ",e,cr.json.write(t),t.children("D")),e>10){H.error("Bailing out");return}let r=t.nodes(),n=!1;for(let i=0;i<r.length;i++){const a=r[i],s=t.children(a);n=n||s.length>0}if(!n){H.debug("Done, no node has children",t.nodes());return}H.debug("Nodes = ",r,e);for(let i=0;i<r.length;i++){const a=r[i];if(H.debug("Extracting node",a,Re,Re[a]&&!Re[a].externalConnections,!t.parent(a),t.node(a),t.children("D")," Depth ",e),!Re[a])H.debug("Not a cluster",a,e);else if(!Re[a].externalConnections&&t.children(a)&&t.children(a).length>0){H.warn("Cluster without external connections, without a parent and with children",a,e);let o=t.graph().rankdir==="TB"?"LR":"TB";Re[a]&&Re[a].clusterData&&Re[a].clusterData.dir&&(o=Re[a].clusterData.dir,H.warn("Fixing dir",Re[a].clusterData.dir,o));const l=new cr.Graph({multigraph:!0,compound:!0}).setGraph({rankdir:o,nodesep:50,ranksep:50,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});H.warn("Old graph before copy",cr.json.write(t)),zA(a,t,l,a),t.setNode(a,{clusterNode:!0,id:a,clusterData:Re[a].clusterData,labelText:Re[a].labelText,graph:l}),H.warn("New graph after copy node: (",a,")",cr.json.write(l)),H.debug("Old graph after copy",cr.json.write(t))}else H.warn("Cluster ** ",a," **not meeting the criteria !externalConnections:",!Re[a].externalConnections," no parent: ",!t.parent(a)," children ",t.children(a)&&t.children(a).length>0,t.children("D"),e),H.debug(Re)}r=t.nodes(),H.warn("New list of nodes",r);for(let i=0;i<r.length;i++){const a=r[i],s=t.node(a);H.warn(" Now next level",a,s),s.clusterNode&&UA(s.graph,e+1)}},WA=(t,e)=>{if(e.length===0)return[];let r=Object.assign(e);return e.forEach(n=>{const i=t.children(n),a=WA(t,i);r=r.concat(a)}),r},jtt=t=>WA(t,t.children());function $tt(t,e){return t.intersect(e)}function HA(t,e,r,n){var i=t.x,a=t.y,s=i-n.x,o=a-n.y,l=Math.sqrt(e*e*o*o+r*r*s*s),u=Math.abs(e*r*s/l);n.x<i&&(u=-u);var h=Math.abs(e*r*o/l);return n.y<a&&(h=-h),{x:i+u,y:a+h}}function Xtt(t,e,r){return HA(t,e,e,r)}function Ktt(t,e,r,n){var i,a,s,o,l,u,h,d,f,p,m,_,y,b,x;if(i=e.y-t.y,s=t.x-e.x,l=e.x*t.y-t.x*e.y,f=i*r.x+s*r.y+l,p=i*n.x+s*n.y+l,!(f!==0&&p!==0&&GA(f,p))&&(a=n.y-r.y,o=r.x-n.x,u=n.x*r.y-r.x*n.y,h=a*t.x+o*t.y+u,d=a*e.x+o*e.y+u,!(h!==0&&d!==0&&GA(h,d))&&(m=i*o-a*s,m!==0)))return _=Math.abs(m/2),y=s*u-o*l,b=y<0?(y-_)/m:(y+_)/m,y=a*l-i*u,x=y<0?(y-_)/m:(y+_)/m,{x:b,y:x}}function GA(t,e){return t*e>0}function Ztt(t,e,r){var n=t.x,i=t.y,a=[],s=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY;typeof e.forEach=="function"?e.forEach(function(m){s=Math.min(s,m.x),o=Math.min(o,m.y)}):(s=Math.min(s,e.x),o=Math.min(o,e.y));for(var l=n-t.width/2-s,u=i-t.height/2-o,h=0;h<e.length;h++){var d=e[h],f=e[h<e.length-1?h+1:0],p=Ktt(t,r,{x:l+d.x,y:u+d.y},{x:l+f.x,y:u+f.y});p&&a.push(p)}return a.length?(a.length>1&&a.sort(function(m,_){var y=m.x-r.x,b=m.y-r.y,x=Math.sqrt(y*y+b*b),k=_.x-r.x,T=_.y-r.y,C=Math.sqrt(k*k+T*T);return x<C?-1:x===C?0:1}),a[0]):t}const Jc=(t,e)=>{var r=t.x,n=t.y,i=e.x-r,a=e.y-n,s=t.width/2,o=t.height/2,l,u;return Math.abs(a)*s>Math.abs(i)*o?(a<0&&(o=-o),l=a===0?0:o*i/a,u=o):(i<0&&(s=-s),l=s,u=i===0?0:s*a/i),{x:r+l,y:n+u}},ir={node:$tt,circle:Xtt,ellipse:HA,polygon:Ztt,rect:Jc},Qtt=(t,e)=>{const{shapeSvg:r,bbox:n,halfPadding:i}=Yr(t,e,"node "+e.classes,!0);H.info("Classes = ",e.classes);const a=r.insert("rect",":first-child");return a.attr("rx",e.rx).attr("ry",e.ry).attr("x",-n.width/2-i).attr("y",-n.height/2-i).attr("width",n.width+e.padding).attr("height",n.height+e.padding),ur(e,a),e.intersect=function(s){return ir.rect(e,s)},r},Jtt=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=n.width+e.padding,a=n.height+e.padding,s=i+a,o=[{x:s/2,y:0},{x:s,y:-s/2},{x:s/2,y:-s},{x:0,y:-s/2}];H.info("Question main (Circle)");const l=ca(r,s,s,o);return l.attr("style",e.style),ur(e,l),e.intersect=function(u){return H.warn("Intersect called"),ir.polygon(e,o,u)},r},tet=(t,e)=>{const r=t.insert("g").attr("class","node default").attr("id",e.domId||e.id),n=28,i=[{x:0,y:n/2},{x:n/2,y:0},{x:0,y:-n/2},{x:-n/2,y:0}];return r.insert("polygon",":first-child").attr("points",i.map(function(s){return s.x+","+s.y}).join(" ")).attr("class","state-start").attr("r",7).attr("width",28).attr("height",28),e.width=28,e.height=28,e.intersect=function(s){return ir.circle(e,14,s)},r},eet=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=4,a=n.height+e.padding,s=a/i,o=n.width+2*s+e.padding,l=[{x:s,y:0},{x:o-s,y:0},{x:o,y:-a/2},{x:o-s,y:-a},{x:s,y:-a},{x:0,y:-a/2}],u=ca(r,o,a,l);return u.attr("style",e.style),ur(e,u),e.intersect=function(h){return ir.polygon(e,l,h)},r},ret=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=n.width+e.padding,a=n.height+e.padding,s=[{x:-a/2,y:0},{x:i,y:0},{x:i,y:-a},{x:-a/2,y:-a},{x:0,y:-a/2}];return ca(r,i,a,s).attr("style",e.style),e.width=i+a,e.height=a,e.intersect=function(l){return ir.polygon(e,s,l)},r},net=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=n.width+e.padding,a=n.height+e.padding,s=[{x:-2*a/6,y:0},{x:i-a/6,y:0},{x:i+2*a/6,y:-a},{x:a/6,y:-a}],o=ca(r,i,a,s);return o.attr("style",e.style),ur(e,o),e.intersect=function(l){return ir.polygon(e,s,l)},r},iet=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=n.width+e.padding,a=n.height+e.padding,s=[{x:2*a/6,y:0},{x:i+a/6,y:0},{x:i-2*a/6,y:-a},{x:-a/6,y:-a}],o=ca(r,i,a,s);return o.attr("style",e.style),ur(e,o),e.intersect=function(l){return ir.polygon(e,s,l)},r},aet=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=n.width+e.padding,a=n.height+e.padding,s=[{x:-2*a/6,y:0},{x:i+2*a/6,y:0},{x:i-a/6,y:-a},{x:a/6,y:-a}],o=ca(r,i,a,s);return o.attr("style",e.style),ur(e,o),e.intersect=function(l){return ir.polygon(e,s,l)},r},set=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=n.width+e.padding,a=n.height+e.padding,s=[{x:a/6,y:0},{x:i-a/6,y:0},{x:i+2*a/6,y:-a},{x:-2*a/6,y:-a}],o=ca(r,i,a,s);return o.attr("style",e.style),ur(e,o),e.intersect=function(l){return ir.polygon(e,s,l)},r},oet=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=n.width+e.padding,a=n.height+e.padding,s=[{x:0,y:0},{x:i+a/2,y:0},{x:i,y:-a/2},{x:i+a/2,y:-a},{x:0,y:-a}],o=ca(r,i,a,s);return o.attr("style",e.style),ur(e,o),e.intersect=function(l){return ir.polygon(e,s,l)},r},cet=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=n.width+e.padding,a=i/2,s=a/(2.5+i/50),o=n.height+s+e.padding,l="M 0,"+s+" a "+a+","+s+" 0,0,0 "+i+" 0 a "+a+","+s+" 0,0,0 "+-i+" 0 l 0,"+o+" a "+a+","+s+" 0,0,0 "+i+" 0 l 0,"+-o,u=r.attr("label-offset-y",s).insert("path",":first-child").attr("style",e.style).attr("d",l).attr("transform","translate("+-i/2+","+-(o/2+s)+")");return ur(e,u),e.intersect=function(h){const d=ir.rect(e,h),f=d.x-e.x;if(a!=0&&(Math.abs(f)<e.width/2||Math.abs(f)==e.width/2&&Math.abs(d.y-e.y)>e.height/2-s)){let p=s*s*(1-f*f/(a*a));p!=0&&(p=Math.sqrt(p)),p=s-p,h.y-e.y>0&&(p=-p),d.y+=p}return d},r},uet=(t,e)=>{const{shapeSvg:r,bbox:n,halfPadding:i}=Yr(t,e,"node "+e.classes,!0);H.trace("Classes = ",e.classes);const a=r.insert("rect",":first-child"),s=n.width+e.padding,o=n.height+e.padding;if(a.attr("class","basic label-container").attr("style",e.style).attr("rx",e.rx).attr("ry",e.ry).attr("x",-n.width/2-i).attr("y",-n.height/2-i).attr("width",s).attr("height",o),e.props){const l=new Set(Object.keys(e.props));e.props.borders&&(jA(a,e.props.borders,s,o),l.delete("borders")),l.forEach(u=>{H.warn(`Unknown node property ${u}`)})}return ur(e,a),e.intersect=function(l){return ir.rect(e,l)},r},het=(t,e)=>{const{shapeSvg:r}=Yr(t,e,"label",!0);H.trace("Classes = ",e.classes);const n=r.insert("rect",":first-child"),i=0,a=0;if(n.attr("width",i).attr("height",a),r.attr("class","label edgeLabel"),e.props){const s=new Set(Object.keys(e.props));e.props.borders&&(jA(n,e.props.borders,i,a),s.delete("borders")),s.forEach(o=>{H.warn(`Unknown node property ${o}`)})}return ur(e,n),e.intersect=function(s){return ir.rect(e,s)},r};function jA(t,e,r,n){const i=[],a=o=>{i.push(o),i.push(0)},s=o=>{i.push(0),i.push(o)};e.includes("t")?(H.debug("add top border"),a(r)):s(r),e.includes("r")?(H.debug("add right border"),a(n)):s(n),e.includes("b")?(H.debug("add bottom border"),a(r)):s(r),e.includes("l")?(H.debug("add left border"),a(n)):s(n),t.attr("stroke-dasharray",i.join(" "))}const fet=(t,e)=>{let r;e.classes?r="node "+e.classes:r="node default";const n=t.insert("g").attr("class",r).attr("id",e.domId||e.id),i=n.insert("rect",":first-child"),a=n.insert("line"),s=n.insert("g").attr("class","label"),o=e.labelText.flat?e.labelText.flat():e.labelText;let l="";typeof o=="object"?l=o[0]:l=o,H.info("Label text abc79",l,o,typeof o=="object");const u=s.node().appendChild(xn(l,e.labelStyle,!0,!0));let h={width:0,height:0};if(Mr(nt().flowchart.htmlLabels)){const _=u.children[0],y=St(u);h=_.getBoundingClientRect(),y.attr("width",h.width),y.attr("height",h.height)}H.info("Text 2",o);const d=o.slice(1,o.length);let f=u.getBBox();const p=s.node().appendChild(xn(d.join?d.join("<br/>"):d,e.labelStyle,!0,!0));if(Mr(nt().flowchart.htmlLabels)){const _=p.children[0],y=St(p);h=_.getBoundingClientRect(),y.attr("width",h.width),y.attr("height",h.height)}const m=e.padding/2;return St(p).attr("transform","translate( "+(h.width>f.width?0:(f.width-h.width)/2)+", "+(f.height+m+5)+")"),St(u).attr("transform","translate( "+(h.width<f.width?0:-(f.width-h.width)/2)+", "+0+")"),h=s.node().getBBox(),s.attr("transform","translate("+-h.width/2+", "+(-h.height/2-m+3)+")"),i.attr("class","outer title-state").attr("x",-h.width/2-m).attr("y",-h.height/2-m).attr("width",h.width+e.padding).attr("height",h.height+e.padding),a.attr("class","divider").attr("x1",-h.width/2-m).attr("x2",h.width/2+m).attr("y1",-h.height/2-m+f.height+m).attr("y2",-h.height/2-m+f.height+m),ur(e,i),e.intersect=function(_){return ir.rect(e,_)},n},det=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=n.height+e.padding,a=n.width+i/4+e.padding,s=r.insert("rect",":first-child").attr("style",e.style).attr("rx",i/2).attr("ry",i/2).attr("x",-a/2).attr("y",-i/2).attr("width",a).attr("height",i);return ur(e,s),e.intersect=function(o){return ir.rect(e,o)},r},pet=(t,e)=>{const{shapeSvg:r,bbox:n,halfPadding:i}=Yr(t,e,void 0,!0),a=r.insert("circle",":first-child");return a.attr("style",e.style).attr("rx",e.rx).attr("ry",e.ry).attr("r",n.width/2+i).attr("width",n.width+e.padding).attr("height",n.height+e.padding),H.info("Circle main"),ur(e,a),e.intersect=function(s){return H.info("Circle intersect",e,n.width/2+i,s),ir.circle(e,n.width/2+i,s)},r},get=(t,e)=>{const{shapeSvg:r,bbox:n,halfPadding:i}=Yr(t,e,void 0,!0),a=5,s=r.insert("g",":first-child"),o=s.insert("circle"),l=s.insert("circle");return o.attr("style",e.style).attr("rx",e.rx).attr("ry",e.ry).attr("r",n.width/2+i+a).attr("width",n.width+e.padding+a*2).attr("height",n.height+e.padding+a*2),l.attr("style",e.style).attr("rx",e.rx).attr("ry",e.ry).attr("r",n.width/2+i).attr("width",n.width+e.padding).attr("height",n.height+e.padding),H.info("DoubleCircle main"),ur(e,o),e.intersect=function(u){return H.info("DoubleCircle intersect",e,n.width/2+i+a,u),ir.circle(e,n.width/2+i+a,u)},r},yet=(t,e)=>{const{shapeSvg:r,bbox:n}=Yr(t,e,void 0,!0),i=n.width+e.padding,a=n.height+e.padding,s=[{x:0,y:0},{x:i,y:0},{x:i,y:-a},{x:0,y:-a},{x:0,y:0},{x:-8,y:0},{x:i+8,y:0},{x:i+8,y:-a},{x:-8,y:-a},{x:-8,y:0}],o=ca(r,i,a,s);return o.attr("style",e.style),ur(e,o),e.intersect=function(l){return ir.polygon(e,s,l)},r},met=(t,e)=>{const r=t.insert("g").attr("class","node default").attr("id",e.domId||e.id),n=r.insert("circle",":first-child");return n.attr("class","state-start").attr("r",7).attr("width",14).attr("height",14),ur(e,n),e.intersect=function(i){return ir.circle(e,7,i)},r},$A=(t,e,r)=>{const n=t.insert("g").attr("class","node default").attr("id",e.domId||e.id);let i=70,a=10;r==="LR"&&(i=10,a=70);const s=n.append("rect").attr("x",-1*i/2).attr("y",-1*a/2).attr("width",i).attr("height",a).attr("class","fork-join");return ur(e,s),e.height=e.height+e.padding/2,e.width=e.width+e.padding/2,e.intersect=function(o){return ir.rect(e,o)},n},XA={question:Jtt,rect:uet,labelRect:het,rectWithTitle:fet,choice:tet,circle:pet,doublecircle:get,stadium:det,hexagon:eet,rect_left_inv_arrow:ret,lean_right:net,lean_left:iet,trapezoid:aet,inv_trapezoid:set,rect_right_inv_arrow:oet,cylinder:cet,start:met,end:(t,e)=>{const r=t.insert("g").attr("class","node default").attr("id",e.domId||e.id),n=r.insert("circle",":first-child"),i=r.insert("circle",":first-child");return i.attr("class","state-start").attr("r",7).attr("width",14).attr("height",14),n.attr("class","state-end").attr("r",5).attr("width",10).attr("height",10),ur(e,i),e.intersect=function(a){return ir.circle(e,7,a)},r},note:Qtt,subroutine:yet,fork:$A,join:$A,class_box:(t,e)=>{const r=e.padding/2,n=4,i=8;let a;e.classes?a="node "+e.classes:a="node default";const s=t.insert("g").attr("class",a).attr("id",e.domId||e.id),o=s.insert("rect",":first-child"),l=s.insert("line"),u=s.insert("line");let h=0,d=n;const f=s.insert("g").attr("class","label");let p=0;const m=e.classData.annotations&&e.classData.annotations[0],_=e.classData.annotations[0]?"\xAB"+e.classData.annotations[0]+"\xBB":"",y=f.node().appendChild(xn(_,e.labelStyle,!0,!0));let b=y.getBBox();if(Mr(nt().flowchart.htmlLabels)){const R=y.children[0],A=St(y);b=R.getBoundingClientRect(),A.attr("width",b.width),A.attr("height",b.height)}e.classData.annotations[0]&&(d+=b.height+n,h+=b.width);let x=e.classData.id;e.classData.type!==void 0&&e.classData.type!==""&&(nt().flowchart.htmlLabels?x+="<"+e.classData.type+">":x+="<"+e.classData.type+">");const k=f.node().appendChild(xn(x,e.labelStyle,!0,!0));St(k).attr("class","classTitle");let T=k.getBBox();if(Mr(nt().flowchart.htmlLabels)){const R=k.children[0],A=St(k);T=R.getBoundingClientRect(),A.attr("width",T.width),A.attr("height",T.height)}d+=T.height+n,T.width>h&&(h=T.width);const C=[];e.classData.members.forEach(R=>{const A=z1(R);let L=A.displayText;nt().flowchart.htmlLabels&&(L=L.replace(/</g,"<").replace(/>/g,">"));const v=f.node().appendChild(xn(L,A.cssStyle?A.cssStyle:e.labelStyle,!0,!0));let B=v.getBBox();if(Mr(nt().flowchart.htmlLabels)){const w=v.children[0],D=St(v);B=w.getBoundingClientRect(),D.attr("width",B.width),D.attr("height",B.height)}B.width>h&&(h=B.width),d+=B.height+n,C.push(v)}),d+=i;const M=[];if(e.classData.methods.forEach(R=>{const A=z1(R);let L=A.displayText;nt().flowchart.htmlLabels&&(L=L.replace(/</g,"<").replace(/>/g,">"));const v=f.node().appendChild(xn(L,A.cssStyle?A.cssStyle:e.labelStyle,!0,!0));let B=v.getBBox();if(Mr(nt().flowchart.htmlLabels)){const w=v.children[0],D=St(v);B=w.getBoundingClientRect(),D.attr("width",B.width),D.attr("height",B.height)}B.width>h&&(h=B.width),d+=B.height+n,M.push(v)}),d+=i,m){let R=(h-b.width)/2;St(y).attr("transform","translate( "+(-1*h/2+R)+", "+-1*d/2+")"),p=b.height+n}let S=(h-T.width)/2;return St(k).attr("transform","translate( "+(-1*h/2+S)+", "+(-1*d/2+p)+")"),p+=T.height+n,l.attr("class","divider").attr("x1",-h/2-r).attr("x2",h/2+r).attr("y1",-d/2-r+i+p).attr("y2",-d/2-r+i+p),p+=i,C.forEach(R=>{St(R).attr("transform","translate( "+-h/2+", "+(-1*d/2+p+i/2)+")"),p+=T.height+n}),p+=i,u.attr("class","divider").attr("x1",-h/2-r).attr("x2",h/2+r).attr("y1",-d/2-r+i+p).attr("y2",-d/2-r+i+p),p+=i,M.forEach(R=>{St(R).attr("transform","translate( "+-h/2+", "+(-1*d/2+p)+")"),p+=T.height+n}),o.attr("class","outer title-state").attr("x",-h/2-r).attr("y",-(d/2)-r).attr("width",h+e.padding).attr("height",d+e.padding),ur(e,o),e.intersect=function(R){return ir.rect(e,R)},s}};let nl={};const bet=(t,e,r)=>{let n,i;if(e.link){let a;nt().securityLevel==="sandbox"?a="_top":e.linkTarget&&(a=e.linkTarget||"_blank"),n=t.insert("svg:a").attr("xlink:href",e.link).attr("target",a),i=XA[e.shape](n,e,r)}else i=XA[e.shape](t,e,r),n=i;e.tooltip&&i.attr("title",e.tooltip),e.class&&i.attr("class","node default "+e.class),nl[e.id]=n,e.haveCallback&&nl[e.id].attr("class",nl[e.id].attr("class")+" clickable")},_et=(t,e)=>{nl[e.id]=t},vet=()=>{nl={}},KA=t=>{const e=nl[t.id];H.trace("Transforming node",t.diff,t,"translate("+(t.x-t.width/2-5)+", "+t.width/2+")");const r=8,n=t.diff||0;return t.clusterNode?e.attr("transform","translate("+(t.x+n-t.width/2)+", "+(t.y-t.height/2-r)+")"):e.attr("transform","translate("+t.x+", "+t.y+")"),n},xet={rect:(t,e)=>{H.trace("Creating subgraph rect for ",e.id,e);const r=t.insert("g").attr("class","cluster"+(e.class?" "+e.class:"")).attr("id",e.id),n=r.insert("rect",":first-child"),i=r.insert("g").attr("class","cluster-label"),a=i.node().appendChild(xn(e.labelText,e.labelStyle,void 0,!0));let s=a.getBBox();if(Mr(nt().flowchart.htmlLabels)){const d=a.children[0],f=St(a);s=d.getBoundingClientRect(),f.attr("width",s.width),f.attr("height",s.height)}const o=0*e.padding,l=o/2,u=e.width<=s.width+o?s.width+o:e.width;e.width<=s.width+o?e.diff=(s.width-e.width)/2-e.padding/2:e.diff=-e.padding/2,H.trace("Data ",e,JSON.stringify(e)),n.attr("style",e.style).attr("rx",e.rx).attr("ry",e.ry).attr("x",e.x-u/2).attr("y",e.y-e.height/2-l).attr("width",u).attr("height",e.height+o),i.attr("transform","translate("+(e.x-s.width/2)+", "+(e.y-e.height/2+e.padding/3)+")");const h=n.node().getBBox();return e.width=h.width,e.height=h.height,e.intersect=function(d){return Jc(e,d)},r},roundedWithTitle:(t,e)=>{const r=t.insert("g").attr("class",e.classes).attr("id",e.id),n=r.insert("rect",":first-child"),i=r.insert("g").attr("class","cluster-label"),a=r.append("rect"),s=i.node().appendChild(xn(e.labelText,e.labelStyle,void 0,!0));let o=s.getBBox();if(Mr(nt().flowchart.htmlLabels)){const f=s.children[0],p=St(s);o=f.getBoundingClientRect(),p.attr("width",o.width),p.attr("height",o.height)}o=s.getBBox();const l=0*e.padding,u=l/2,h=e.width<=o.width+e.padding?o.width+e.padding:e.width;e.width<=o.width+e.padding?e.diff=(o.width+e.padding*0-e.width)/2:e.diff=-e.padding/2,n.attr("class","outer").attr("x",e.x-h/2-u).attr("y",e.y-e.height/2-u).attr("width",h+l).attr("height",e.height+l),a.attr("class","inner").attr("x",e.x-h/2-u).attr("y",e.y-e.height/2-u+o.height-1).attr("width",h+l).attr("height",e.height+l-o.height-3),i.attr("transform","translate("+(e.x-o.width/2)+", "+(e.y-e.height/2-e.padding/3+(Mr(nt().flowchart.htmlLabels)?5:3))+")");const d=n.node().getBBox();return e.height=d.height,e.intersect=function(f){return Jc(e,f)},r},noteGroup:(t,e)=>{const r=t.insert("g").attr("class","note-cluster").attr("id",e.id),n=r.insert("rect",":first-child"),i=0*e.padding,a=i/2;n.attr("rx",e.rx).attr("ry",e.ry).attr("x",e.x-e.width/2-a).attr("y",e.y-e.height/2-a).attr("width",e.width+i).attr("height",e.height+i).attr("fill","none");const s=n.node().getBBox();return e.width=s.width,e.height=s.height,e.intersect=function(o){return Jc(e,o)},r},divider:(t,e)=>{const r=t.insert("g").attr("class",e.classes).attr("id",e.id),n=r.insert("rect",":first-child"),i=0*e.padding,a=i/2;n.attr("class","divider").attr("x",e.x-e.width/2-a).attr("y",e.y-e.height/2).attr("width",e.width+i).attr("height",e.height+i);const s=n.node().getBBox();return e.width=s.width,e.height=s.height,e.diff=-e.padding/2,e.intersect=function(o){return Jc(e,o)},r}};let ZA={};const ket=(t,e)=>{H.trace("Inserting cluster");const r=e.shape||"rect";ZA[e.id]=xet[r](t,e)},wet=()=>{ZA={}};let G1={},Nr={};const Tet=()=>{G1={},Nr={}},Eet=(t,e)=>{const r=xn(e.label,e.labelStyle),n=t.insert("g").attr("class","edgeLabel"),i=n.insert("g").attr("class","label");i.node().appendChild(r);let a=r.getBBox();if(Mr(nt().flowchart.htmlLabels)){const o=r.children[0],l=St(r);a=o.getBoundingClientRect(),l.attr("width",a.width),l.attr("height",a.height)}i.attr("transform","translate("+-a.width/2+", "+-a.height/2+")"),G1[e.id]=n,e.width=a.width,e.height=a.height;let s;if(e.startLabelLeft){const o=xn(e.startLabelLeft,e.labelStyle),l=t.insert("g").attr("class","edgeTerminals"),u=l.insert("g").attr("class","inner");s=u.node().appendChild(o);const h=o.getBBox();u.attr("transform","translate("+-h.width/2+", "+-h.height/2+")"),Nr[e.id]||(Nr[e.id]={}),Nr[e.id].startLeft=l,j1(s,e.startLabelLeft)}if(e.startLabelRight){const o=xn(e.startLabelRight,e.labelStyle),l=t.insert("g").attr("class","edgeTerminals"),u=l.insert("g").attr("class","inner");s=l.node().appendChild(o),u.node().appendChild(o);const h=o.getBBox();u.attr("transform","translate("+-h.width/2+", "+-h.height/2+")"),Nr[e.id]||(Nr[e.id]={}),Nr[e.id].startRight=l,j1(s,e.startLabelRight)}if(e.endLabelLeft){const o=xn(e.endLabelLeft,e.labelStyle),l=t.insert("g").attr("class","edgeTerminals"),u=l.insert("g").attr("class","inner");s=u.node().appendChild(o);const h=o.getBBox();u.attr("transform","translate("+-h.width/2+", "+-h.height/2+")"),l.node().appendChild(o),Nr[e.id]||(Nr[e.id]={}),Nr[e.id].endLeft=l,j1(s,e.endLabelLeft)}if(e.endLabelRight){const o=xn(e.endLabelRight,e.labelStyle),l=t.insert("g").attr("class","edgeTerminals"),u=l.insert("g").attr("class","inner");s=u.node().appendChild(o);const h=o.getBBox();u.attr("transform","translate("+-h.width/2+", "+-h.height/2+")"),l.node().appendChild(o),Nr[e.id]||(Nr[e.id]={}),Nr[e.id].endRight=l,j1(s,e.endLabelRight)}};function j1(t,e){nt().flowchart.htmlLabels&&t&&(t.style.width=e.length*9+"px",t.style.height="12px")}const Cet=(t,e)=>{H.info("Moving label abc78 ",t.id,t.label,G1[t.id]);let r=e.updatedPath?e.updatedPath:e.originalPath;if(t.label){const n=G1[t.id];let i=t.x,a=t.y;if(r){const s=Se.calcLabelPosition(r);H.info("Moving label from (",i,",",a,") to (",s.x,",",s.y,") abc78")}n.attr("transform","translate("+i+", "+a+")")}if(t.startLabelLeft){const n=Nr[t.id].startLeft;let i=t.x,a=t.y;if(r){const s=Se.calcTerminalLabelPosition(t.arrowTypeStart?10:0,"start_left",r);i=s.x,a=s.y}n.attr("transform","translate("+i+", "+a+")")}if(t.startLabelRight){const n=Nr[t.id].startRight;let i=t.x,a=t.y;if(r){const s=Se.calcTerminalLabelPosition(t.arrowTypeStart?10:0,"start_right",r);i=s.x,a=s.y}n.attr("transform","translate("+i+", "+a+")")}if(t.endLabelLeft){const n=Nr[t.id].endLeft;let i=t.x,a=t.y;if(r){const s=Se.calcTerminalLabelPosition(t.arrowTypeEnd?10:0,"end_left",r);i=s.x,a=s.y}n.attr("transform","translate("+i+", "+a+")")}if(t.endLabelRight){const n=Nr[t.id].endRight;let i=t.x,a=t.y;if(r){const s=Se.calcTerminalLabelPosition(t.arrowTypeEnd?10:0,"end_right",r);i=s.x,a=s.y}n.attr("transform","translate("+i+", "+a+")")}},Aet=(t,e)=>{const r=t.x,n=t.y,i=Math.abs(e.x-r),a=Math.abs(e.y-n),s=t.width/2,o=t.height/2;return i>=s||a>=o},Met=(t,e,r)=>{H.warn(`intersection calc abc89: + outsidePoint: ${JSON.stringify(e)} + insidePoint : ${JSON.stringify(r)} + node : x:${t.x} y:${t.y} w:${t.width} h:${t.height}`);const n=t.x,i=t.y,a=Math.abs(n-r.x),s=t.width/2;let o=r.x<e.x?s-a:s+a;const l=t.height/2,u=Math.abs(e.y-r.y),h=Math.abs(e.x-r.x);if(Math.abs(i-e.y)*s>Math.abs(n-e.x)*l){let d=r.y<e.y?e.y-l-i:i-l-e.y;o=h*d/u;const f={x:r.x<e.x?r.x+o:r.x-h+o,y:r.y<e.y?r.y+u-d:r.y-u+d};return o===0&&(f.x=e.x,f.y=e.y),h===0&&(f.x=e.x),u===0&&(f.y=e.y),H.warn(`abc89 topp/bott calc, Q ${u}, q ${d}, R ${h}, r ${o}`,f),f}else{r.x<e.x?o=e.x-s-n:o=n-s-e.x;let d=u*o/h,f=r.x<e.x?r.x+h-o:r.x-h+o,p=r.y<e.y?r.y+d:r.y-d;return H.warn(`sides calc abc89, Q ${u}, q ${d}, R ${h}, r ${o}`,{_x:f,_y:p}),o===0&&(f=e.x,p=e.y),h===0&&(f=e.x),u===0&&(p=e.y),{x:f,y:p}}},QA=(t,e)=>{H.warn("abc88 cutPathAtIntersect",t,e);let r=[],n=t[0],i=!1;return t.forEach(a=>{if(H.info("abc88 checking point",a,e),!Aet(e,a)&&!i){const s=Met(e,n,a);H.warn("abc88 inside",a,n,s),H.warn("abc88 intersection",s);let o=!1;r.forEach(l=>{o=o||l.x===s.x&&l.y===s.y}),r.find(l=>l.x===s.x&&l.y===s.y)?H.warn("abc88 no intersect",s,r):r.push(s),i=!0}else H.warn("abc88 outside",a,n),n=a,i||r.push(a)}),H.warn("abc88 returning points",r),r},Let=function(t,e,r,n,i,a){let s=r.points,o=!1;const l=a.node(e.v);var u=a.node(e.w);H.info("abc88 InsertEdge: ",r),u.intersect&&l.intersect&&(s=s.slice(1,r.points.length-1),s.unshift(l.intersect(s[0])),H.info("Last point",s[s.length-1],u,u.intersect(s[s.length-1])),s.push(u.intersect(s[s.length-1]))),r.toCluster&&(H.info("to cluster abc88",n[r.toCluster]),s=QA(r.points,n[r.toCluster].node),o=!0),r.fromCluster&&(H.info("from cluster abc88",n[r.fromCluster]),s=QA(s.reverse(),n[r.fromCluster].node).reverse(),o=!0);const h=s.filter(b=>!Number.isNaN(b.y));let d;i==="graph"||i==="flowchart"?d=r.curve||Os:d=Os;const f=Ua().x(function(b){return b.x}).y(function(b){return b.y}).curve(d);let p;switch(r.thickness){case"normal":p="edge-thickness-normal";break;case"thick":p="edge-thickness-thick";break;case"invisible":p="edge-thickness-thick";break;default:p=""}switch(r.pattern){case"solid":p+=" edge-pattern-solid";break;case"dotted":p+=" edge-pattern-dotted";break;case"dashed":p+=" edge-pattern-dashed";break}const m=t.append("path").attr("d",f(h)).attr("id",r.id).attr("class"," "+p+(r.classes?" "+r.classes:"")).attr("style",r.style);let _="";switch((nt().flowchart.arrowMarkerAbsolute||nt().state.arrowMarkerAbsolute)&&(_=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,_=_.replace(/\(/g,"\\("),_=_.replace(/\)/g,"\\)")),H.info("arrowTypeStart",r.arrowTypeStart),H.info("arrowTypeEnd",r.arrowTypeEnd),r.arrowTypeStart){case"arrow_cross":m.attr("marker-start","url("+_+"#"+i+"-crossStart)");break;case"arrow_point":m.attr("marker-start","url("+_+"#"+i+"-pointStart)");break;case"arrow_barb":m.attr("marker-start","url("+_+"#"+i+"-barbStart)");break;case"arrow_circle":m.attr("marker-start","url("+_+"#"+i+"-circleStart)");break;case"aggregation":m.attr("marker-start","url("+_+"#"+i+"-aggregationStart)");break;case"extension":m.attr("marker-start","url("+_+"#"+i+"-extensionStart)");break;case"composition":m.attr("marker-start","url("+_+"#"+i+"-compositionStart)");break;case"dependency":m.attr("marker-start","url("+_+"#"+i+"-dependencyStart)");break;case"lollipop":m.attr("marker-start","url("+_+"#"+i+"-lollipopStart)");break}switch(r.arrowTypeEnd){case"arrow_cross":m.attr("marker-end","url("+_+"#"+i+"-crossEnd)");break;case"arrow_point":m.attr("marker-end","url("+_+"#"+i+"-pointEnd)");break;case"arrow_barb":m.attr("marker-end","url("+_+"#"+i+"-barbEnd)");break;case"arrow_circle":m.attr("marker-end","url("+_+"#"+i+"-circleEnd)");break;case"aggregation":m.attr("marker-end","url("+_+"#"+i+"-aggregationEnd)");break;case"extension":m.attr("marker-end","url("+_+"#"+i+"-extensionEnd)");break;case"composition":m.attr("marker-end","url("+_+"#"+i+"-compositionEnd)");break;case"dependency":m.attr("marker-end","url("+_+"#"+i+"-dependencyEnd)");break;case"lollipop":m.attr("marker-end","url("+_+"#"+i+"-lollipopEnd)");break}let y={};return o&&(y.updatedPath=s),y.originalPath=r.points,y},JA=(t,e,r,n)=>{H.info("Graph in recursive render: XXX",cr.json.write(e),n);const i=e.graph().rankdir;H.trace("Dir in recursive render - dir:",i);const a=t.insert("g").attr("class","root");e.nodes()?H.info("Recursive render XXX",e.nodes()):H.info("No nodes found for",e),e.edges().length>0&&H.trace("Recursive edges",e.edge(e.edges()[0]));const s=a.insert("g").attr("class","clusters"),o=a.insert("g").attr("class","edgePaths"),l=a.insert("g").attr("class","edgeLabels"),u=a.insert("g").attr("class","nodes");e.nodes().forEach(function(d){const f=e.node(d);if(typeof n<"u"){const p=JSON.parse(JSON.stringify(n.clusterData));H.info("Setting data for cluster XXX (",d,") ",p,n),e.setNode(n.id,p),e.parent(d)||(H.trace("Setting parent",d,n.id),e.setParent(d,n.id,p))}if(H.info("(Insert) Node XXX"+d+": "+JSON.stringify(e.node(d))),f&&f.clusterNode){H.info("Cluster identified",d,f.width,e.node(d));const p=JA(u,f.graph,r,e.node(d)),m=p.elem;ur(f,m),f.diff=p.diff||0,H.info("Node bounds (abc123)",d,f,f.width,f.x,f.y),_et(m,f),H.warn("Recursive render complete ",m,f)}else e.children(d).length>0?(H.info("Cluster - the non recursive path XXX",d,f.id,f,e),H.info(Qc(f.id,e)),Re[f.id]={id:Qc(f.id,e),node:f}):(H.info("Node - the non recursive path",d,f.id,f),bet(u,e.node(d),i))}),e.edges().forEach(function(d){const f=e.edge(d.v,d.w,d.name);H.info("Edge "+d.v+" -> "+d.w+": "+JSON.stringify(d)),H.info("Edge "+d.v+" -> "+d.w+": ",d," ",JSON.stringify(e.edge(d))),H.info("Fix",Re,"ids:",d.v,d.w,"Translateing: ",Re[d.v],Re[d.w]),Eet(l,f)}),e.edges().forEach(function(d){H.info("Edge "+d.v+" -> "+d.w+": "+JSON.stringify(d))}),H.info("#############################################"),H.info("### Layout ###"),H.info("#############################################"),H.info(e),Zc.layout(e),H.info("Graph after layout:",cr.json.write(e));let h=0;return jtt(e).forEach(function(d){const f=e.node(d);H.info("Position "+d+": "+JSON.stringify(e.node(d))),H.info("Position "+d+": ("+f.x,","+f.y,") width: ",f.width," height: ",f.height),f&&f.clusterNode?KA(f):e.children(d).length>0?(ket(s,f),Re[f.id].node=f):KA(f)}),e.edges().forEach(function(d){const f=e.edge(d);H.info("Edge "+d.v+" -> "+d.w+": "+JSON.stringify(f),f);const p=Let(o,d,f,Re,r,e);Cet(f,p)}),e.nodes().forEach(function(d){const f=e.node(d);H.info(d,f.type,f.diff),f.type==="group"&&(h=f.diff)}),{elem:a,diff:h}},i4=(t,e,r,n,i)=>{Vtt(t,r,n,i),vet(),Tet(),wet(),Wtt(),H.warn("Graph at first:",cr.json.write(e)),Gtt(e),H.warn("Graph after:",cr.json.write(e)),JA(t,e,n)},Ret=t=>pe.sanitizeText(t,nt()),Iet=function(t,e,r,n){const i=Object.keys(t);H.info("keys:",i),H.info(t),i.forEach(function(a){const s=t[a];let o="";s.cssClasses.length>0&&(o=o+" "+s.cssClasses.join(" "));const l={labelStyle:""};let u=s.text!==void 0?s.text:s.id,h=0,d="";switch(s.type){case"class":d="class_box";break;default:d="class_box"}e.setNode(s.id,{labelStyle:l.labelStyle,shape:d,labelText:Ret(u),classData:s,rx:h,ry:h,class:o,style:l.style,id:s.id,domId:s.domId,tooltip:n.db.getTooltip(s.id)||"",haveCallback:s.haveCallback,link:s.link,width:s.type==="group"?500:void 0,type:s.type,padding:nt().flowchart.padding}),H.info("setNode",{labelStyle:l.labelStyle,shape:d,labelText:u,rx:h,ry:h,class:o,style:l.style,id:s.id,width:s.type==="group"?500:void 0,type:s.type,padding:nt().flowchart.padding})})},Net=function(t,e){const r=nt().flowchart;let n=0;t.forEach(function(i){n++;const a={};a.classes="relation",a.pattern=i.relation.lineType==1?"dashed":"solid",a.id="id"+n,i.type==="arrow_open"?a.arrowhead="none":a.arrowhead="normal",H.info(a,i),a.startLabelRight=i.relationTitle1==="none"?"":i.relationTitle1,a.endLabelLeft=i.relationTitle2==="none"?"":i.relationTitle2,a.arrowTypeStart=tM(i.relation.type1),a.arrowTypeEnd=tM(i.relation.type2);let s="",o="";if(typeof i.style<"u"){const l=Ka(i.style);s=l.style,o=l.labelStyle}else s="fill:none";a.style=s,a.labelStyle=o,typeof i.interpolate<"u"?a.curve=Ni(i.interpolate,yn):typeof t.defaultInterpolate<"u"?a.curve=Ni(t.defaultInterpolate,yn):a.curve=Ni(r.curve,yn),i.text=i.title,typeof i.text>"u"?typeof i.style<"u"&&(a.arrowheadStyle="fill: #333"):(a.arrowheadStyle="fill: #333",a.labelpos="c",nt().flowchart.htmlLabels?(a.labelType="html",a.label='<span class="edgeLabel">'+i.text+"</span>"):(a.labelType="text",a.label=i.text.replace(pe.lineBreakRegex,` +`),typeof i.style>"u"&&(a.style=a.style||"stroke: #333; stroke-width: 1.5px;fill:none"),a.labelStyle=a.labelStyle.replace("color:","fill:"))),e.setEdge(i.id1,i.id2,a,n)})},Bet=function(t){Object.keys(t).forEach(function(r){t[r]})},Det=function(t,e,r,n){H.info("Drawing class - ",e);const i=nt().flowchart,a=nt().securityLevel;H.info("config:",i);const s=i.nodeSpacing||50,o=i.rankSpacing||50,l=new cr.Graph({multigraph:!0,compound:!0}).setGraph({rankdir:n.db.getDirection(),nodesep:s,ranksep:o,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}}),u=n.db.getClasses(),h=n.db.getRelations();H.info(h),Iet(u,l,e,n),Net(h,l);let d;a==="sandbox"&&(d=St("#i"+e));const f=St(a==="sandbox"?d.nodes()[0].contentDocument.body:"body"),p=f.select(`[id="${e}"]`),m=f.select("#"+e+" g");if(i4(m,l,["aggregation","extension","composition","dependency","lollipop"],"classDiagram",e),i1(l,p,i.diagramPadding,i.useMaxWidth),!i.htmlLabels){const _=a==="sandbox"?d.nodes()[0].contentDocument:document,y=_.querySelectorAll('[id="'+e+'"] .edgeLabel .label');for(let b=0;b<y.length;b++){const x=y[b],k=x.getBBox(),T=_.createElementNS("http://www.w3.org/2000/svg","rect");T.setAttribute("rx",0),T.setAttribute("ry",0),T.setAttribute("width",k.width),T.setAttribute("height",k.height),x.insertBefore(T,x.firstChild)}}bn(n.db,p,e)};function tM(t){let e;switch(t){case 0:e="aggregation";break;case 1:e="extension";break;case 2:e="composition";break;case 3:e="dependency";break;case 4:e="lollipop";break;default:e="none"}return e}const Oet={setConf:Bet,draw:Det};var a4=function(){var t=function(A,L,v,B){for(v=v||{},B=A.length;B--;v[A[B]]=L);return v},e=[1,2],r=[1,5],n=[6,9,11,23,25,27,29,30,31,49],i=[1,17],a=[1,18],s=[1,19],o=[1,20],l=[1,21],u=[1,22],h=[1,25],d=[1,30],f=[1,31],p=[1,32],m=[1,33],_=[6,9,11,15,20,23,25,27,29,30,31,42,43,44,45,49],y=[1,45],b=[30,31,46,47],x=[4,6,9,11,23,25,27,29,30,31,49],k=[42,43,44,45],T=[22,37],C=[1,64],M={trace:function(){},yy:{},symbols_:{error:2,start:3,ER_DIAGRAM:4,document:5,EOF:6,directive:7,line:8,SPACE:9,statement:10,NEWLINE:11,openDirective:12,typeDirective:13,closeDirective:14,":":15,argDirective:16,entityName:17,relSpec:18,role:19,BLOCK_START:20,attributes:21,BLOCK_STOP:22,title:23,title_value:24,acc_title:25,acc_title_value:26,acc_descr:27,acc_descr_value:28,acc_descr_multiline_value:29,ALPHANUM:30,ENTITY_NAME:31,attribute:32,attributeType:33,attributeName:34,attributeKeyType:35,attributeComment:36,ATTRIBUTE_WORD:37,ATTRIBUTE_KEY:38,COMMENT:39,cardinality:40,relType:41,ZERO_OR_ONE:42,ZERO_OR_MORE:43,ONE_OR_MORE:44,ONLY_ONE:45,NON_IDENTIFYING:46,IDENTIFYING:47,WORD:48,open_directive:49,type_directive:50,arg_directive:51,close_directive:52,$accept:0,$end:1},terminals_:{2:"error",4:"ER_DIAGRAM",6:"EOF",9:"SPACE",11:"NEWLINE",15:":",20:"BLOCK_START",22:"BLOCK_STOP",23:"title",24:"title_value",25:"acc_title",26:"acc_title_value",27:"acc_descr",28:"acc_descr_value",29:"acc_descr_multiline_value",30:"ALPHANUM",31:"ENTITY_NAME",37:"ATTRIBUTE_WORD",38:"ATTRIBUTE_KEY",39:"COMMENT",42:"ZERO_OR_ONE",43:"ZERO_OR_MORE",44:"ONE_OR_MORE",45:"ONLY_ONE",46:"NON_IDENTIFYING",47:"IDENTIFYING",48:"WORD",49:"open_directive",50:"type_directive",51:"arg_directive",52:"close_directive"},productions_:[0,[3,3],[3,2],[5,0],[5,2],[8,2],[8,1],[8,1],[8,1],[7,4],[7,6],[10,1],[10,5],[10,4],[10,3],[10,1],[10,2],[10,2],[10,2],[10,1],[17,1],[17,1],[21,1],[21,2],[32,2],[32,3],[32,3],[32,4],[33,1],[34,1],[35,1],[36,1],[18,3],[40,1],[40,1],[40,1],[40,1],[41,1],[41,1],[19,1],[19,1],[19,1],[12,1],[13,1],[16,1],[14,1]],performAction:function(L,v,B,w,D,N,z){var X=N.length-1;switch(D){case 1:break;case 3:this.$=[];break;case 4:N[X-1].push(N[X]),this.$=N[X-1];break;case 5:case 6:this.$=N[X];break;case 7:case 8:this.$=[];break;case 12:w.addEntity(N[X-4]),w.addEntity(N[X-2]),w.addRelationship(N[X-4],N[X],N[X-2],N[X-3]);break;case 13:w.addEntity(N[X-3]),w.addAttributes(N[X-3],N[X-1]);break;case 14:w.addEntity(N[X-2]);break;case 15:w.addEntity(N[X]);break;case 16:case 17:this.$=N[X].trim(),w.setAccTitle(this.$);break;case 18:case 19:this.$=N[X].trim(),w.setAccDescription(this.$);break;case 20:case 41:this.$=N[X];break;case 21:case 39:case 40:this.$=N[X].replace(/"/g,"");break;case 22:this.$=[N[X]];break;case 23:N[X].push(N[X-1]),this.$=N[X];break;case 24:this.$={attributeType:N[X-1],attributeName:N[X]};break;case 25:this.$={attributeType:N[X-2],attributeName:N[X-1],attributeKeyType:N[X]};break;case 26:this.$={attributeType:N[X-2],attributeName:N[X-1],attributeComment:N[X]};break;case 27:this.$={attributeType:N[X-3],attributeName:N[X-2],attributeKeyType:N[X-1],attributeComment:N[X]};break;case 28:case 29:case 30:this.$=N[X];break;case 31:this.$=N[X].replace(/"/g,"");break;case 32:this.$={cardA:N[X],relType:N[X-1],cardB:N[X-2]};break;case 33:this.$=w.Cardinality.ZERO_OR_ONE;break;case 34:this.$=w.Cardinality.ZERO_OR_MORE;break;case 35:this.$=w.Cardinality.ONE_OR_MORE;break;case 36:this.$=w.Cardinality.ONLY_ONE;break;case 37:this.$=w.Identification.NON_IDENTIFYING;break;case 38:this.$=w.Identification.IDENTIFYING;break;case 42:w.parseDirective("%%{","open_directive");break;case 43:w.parseDirective(N[X],"type_directive");break;case 44:N[X]=N[X].trim().replace(/'/g,'"'),w.parseDirective(N[X],"arg_directive");break;case 45:w.parseDirective("}%%","close_directive","er");break}},table:[{3:1,4:e,7:3,12:4,49:r},{1:[3]},t(n,[2,3],{5:6}),{3:7,4:e,7:3,12:4,49:r},{13:8,50:[1,9]},{50:[2,42]},{6:[1,10],7:15,8:11,9:[1,12],10:13,11:[1,14],12:4,17:16,23:i,25:a,27:s,29:o,30:l,31:u,49:r},{1:[2,2]},{14:23,15:[1,24],52:h},t([15,52],[2,43]),t(n,[2,8],{1:[2,1]}),t(n,[2,4]),{7:15,10:26,12:4,17:16,23:i,25:a,27:s,29:o,30:l,31:u,49:r},t(n,[2,6]),t(n,[2,7]),t(n,[2,11]),t(n,[2,15],{18:27,40:29,20:[1,28],42:d,43:f,44:p,45:m}),{24:[1,34]},{26:[1,35]},{28:[1,36]},t(n,[2,19]),t(_,[2,20]),t(_,[2,21]),{11:[1,37]},{16:38,51:[1,39]},{11:[2,45]},t(n,[2,5]),{17:40,30:l,31:u},{21:41,22:[1,42],32:43,33:44,37:y},{41:46,46:[1,47],47:[1,48]},t(b,[2,33]),t(b,[2,34]),t(b,[2,35]),t(b,[2,36]),t(n,[2,16]),t(n,[2,17]),t(n,[2,18]),t(x,[2,9]),{14:49,52:h},{52:[2,44]},{15:[1,50]},{22:[1,51]},t(n,[2,14]),{21:52,22:[2,22],32:43,33:44,37:y},{34:53,37:[1,54]},{37:[2,28]},{40:55,42:d,43:f,44:p,45:m},t(k,[2,37]),t(k,[2,38]),{11:[1,56]},{19:57,30:[1,60],31:[1,59],48:[1,58]},t(n,[2,13]),{22:[2,23]},t(T,[2,24],{35:61,36:62,38:[1,63],39:C}),t([22,37,38,39],[2,29]),t([30,31],[2,32]),t(x,[2,10]),t(n,[2,12]),t(n,[2,39]),t(n,[2,40]),t(n,[2,41]),t(T,[2,25],{36:65,39:C}),t(T,[2,26]),t([22,37,39],[2,30]),t(T,[2,31]),t(T,[2,27])],defaultActions:{5:[2,42],7:[2,2],25:[2,45],39:[2,44],45:[2,28],52:[2,23]},parseError:function(L,v){if(v.recoverable)this.trace(L);else{var B=new Error(L);throw B.hash=v,B}},parse:function(L){var v=this,B=[0],w=[],D=[null],N=[],z=this.table,X="",ct=0,J=0,Y=2,$=1,lt=N.slice.call(arguments,1),ut=Object.create(this.lexer),W={yy:{}};for(var tt in this.yy)Object.prototype.hasOwnProperty.call(this.yy,tt)&&(W.yy[tt]=this.yy[tt]);ut.setInput(L,W.yy),W.yy.lexer=ut,W.yy.parser=this,typeof ut.yylloc>"u"&&(ut.yylloc={});var K=ut.yylloc;N.push(K);var it=ut.options&&ut.options.ranges;typeof W.yy.parseError=="function"?this.parseError=W.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function Z(){var Lt;return Lt=w.pop()||ut.lex()||$,typeof Lt!="number"&&(Lt instanceof Array&&(w=Lt,Lt=w.pop()),Lt=v.symbols_[Lt]||Lt),Lt}for(var V,Q,q,U,F={},j,P,et,at;;){if(Q=B[B.length-1],this.defaultActions[Q]?q=this.defaultActions[Q]:((V===null||typeof V>"u")&&(V=Z()),q=z[Q]&&z[Q][V]),typeof q>"u"||!q.length||!q[0]){var It="";at=[];for(j in z[Q])this.terminals_[j]&&j>Y&&at.push("'"+this.terminals_[j]+"'");ut.showPosition?It="Parse error on line "+(ct+1)+`: +`+ut.showPosition()+` +Expecting `+at.join(", ")+", got '"+(this.terminals_[V]||V)+"'":It="Parse error on line "+(ct+1)+": Unexpected "+(V==$?"end of input":"'"+(this.terminals_[V]||V)+"'"),this.parseError(It,{text:ut.match,token:this.terminals_[V]||V,line:ut.yylineno,loc:K,expected:at})}if(q[0]instanceof Array&&q.length>1)throw new Error("Parse Error: multiple actions possible at state: "+Q+", token: "+V);switch(q[0]){case 1:B.push(V),D.push(ut.yytext),N.push(ut.yylloc),B.push(q[1]),V=null,J=ut.yyleng,X=ut.yytext,ct=ut.yylineno,K=ut.yylloc;break;case 2:if(P=this.productions_[q[1]][1],F.$=D[D.length-P],F._$={first_line:N[N.length-(P||1)].first_line,last_line:N[N.length-1].last_line,first_column:N[N.length-(P||1)].first_column,last_column:N[N.length-1].last_column},it&&(F._$.range=[N[N.length-(P||1)].range[0],N[N.length-1].range[1]]),U=this.performAction.apply(F,[X,J,ct,W.yy,q[1],D,N].concat(lt)),typeof U<"u")return U;P&&(B=B.slice(0,-1*P*2),D=D.slice(0,-1*P),N=N.slice(0,-1*P)),B.push(this.productions_[q[1]][0]),D.push(F.$),N.push(F._$),et=z[B[B.length-2]][B[B.length-1]],B.push(et);break;case 3:return!0}}return!0}},S=function(){var A={EOF:1,parseError:function(v,B){if(this.yy.parser)this.yy.parser.parseError(v,B);else throw new Error(v)},setInput:function(L,v){return this.yy=v||this.yy||{},this._input=L,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var L=this._input[0];this.yytext+=L,this.yyleng++,this.offset++,this.match+=L,this.matched+=L;var v=L.match(/(?:\r\n?|\n).*/g);return v?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),L},unput:function(L){var v=L.length,B=L.split(/(?:\r\n?|\n)/g);this._input=L+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-v),this.offset-=v;var w=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),B.length-1&&(this.yylineno-=B.length-1);var D=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:B?(B.length===w.length?this.yylloc.first_column:0)+w[w.length-B.length].length-B[0].length:this.yylloc.first_column-v},this.options.ranges&&(this.yylloc.range=[D[0],D[0]+this.yyleng-v]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(L){this.unput(this.match.slice(L))},pastInput:function(){var L=this.matched.substr(0,this.matched.length-this.match.length);return(L.length>20?"...":"")+L.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var L=this.match;return L.length<20&&(L+=this._input.substr(0,20-L.length)),(L.substr(0,20)+(L.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var L=this.pastInput(),v=new Array(L.length+1).join("-");return L+this.upcomingInput()+` +`+v+"^"},test_match:function(L,v){var B,w,D;if(this.options.backtrack_lexer&&(D={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(D.yylloc.range=this.yylloc.range.slice(0))),w=L[0].match(/(?:\r\n?|\n).*/g),w&&(this.yylineno+=w.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:w?w[w.length-1].length-w[w.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+L[0].length},this.yytext+=L[0],this.match+=L[0],this.matches=L,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(L[0].length),this.matched+=L[0],B=this.performAction.call(this,this.yy,this,v,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),B)return B;if(this._backtrack){for(var N in D)this[N]=D[N];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var L,v,B,w;this._more||(this.yytext="",this.match="");for(var D=this._currentRules(),N=0;N<D.length;N++)if(B=this._input.match(this.rules[D[N]]),B&&(!v||B[0].length>v[0].length)){if(v=B,w=N,this.options.backtrack_lexer){if(L=this.test_match(B,D[N]),L!==!1)return L;if(this._backtrack){v=!1;continue}else return!1}else if(!this.options.flex)break}return v?(L=this.test_match(v,D[w]),L!==!1?L:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var v=this.next();return v||this.lex()},begin:function(v){this.conditionStack.push(v)},popState:function(){var v=this.conditionStack.length-1;return v>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(v){return v=this.conditionStack.length-1-Math.abs(v||0),v>=0?this.conditionStack[v]:"INITIAL"},pushState:function(v){this.begin(v)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(v,B,w,D){switch(w){case 0:return this.begin("acc_title"),25;case 1:return this.popState(),"acc_title_value";case 2:return this.begin("acc_descr"),27;case 3:return this.popState(),"acc_descr_value";case 4:this.begin("acc_descr_multiline");break;case 5:this.popState();break;case 6:return"acc_descr_multiline_value";case 7:return this.begin("open_directive"),49;case 8:return this.begin("type_directive"),50;case 9:return this.popState(),this.begin("arg_directive"),15;case 10:return this.popState(),this.popState(),52;case 11:return 51;case 12:break;case 13:break;case 14:return 11;case 15:break;case 16:return 9;case 17:return 31;case 18:return 48;case 19:return 4;case 20:return this.begin("block"),20;case 21:break;case 22:return 38;case 23:return 37;case 24:return 37;case 25:return 39;case 26:break;case 27:return this.popState(),22;case 28:return B.yytext[0];case 29:return 42;case 30:return 43;case 31:return 44;case 32:return 45;case 33:return 42;case 34:return 43;case 35:return 44;case 36:return 46;case 37:return 47;case 38:return 46;case 39:return 46;case 40:return 30;case 41:return B.yytext[0];case 42:return 6}},rules:[/^(?:accTitle\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*\{\s*)/i,/^(?:[\}])/i,/^(?:[^\}]*)/i,/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:[\s]+)/i,/^(?:"[^"%\r\n\v\b\\]+")/i,/^(?:"[^"]*")/i,/^(?:erDiagram\b)/i,/^(?:\{)/i,/^(?:\s+)/i,/^(?:\b((?:PK)|(?:FK))\b)/i,/^(?:(.*?)[~](.*?)*[~])/i,/^(?:[A-Za-z][A-Za-z0-9\-_\[\]]*)/i,/^(?:"[^"]*")/i,/^(?:[\n]+)/i,/^(?:\})/i,/^(?:.)/i,/^(?:\|o\b)/i,/^(?:\}o\b)/i,/^(?:\}\|)/i,/^(?:\|\|)/i,/^(?:o\|)/i,/^(?:o\{)/i,/^(?:\|\{)/i,/^(?:\.\.)/i,/^(?:--)/i,/^(?:\.-)/i,/^(?:-\.)/i,/^(?:[A-Za-z][A-Za-z0-9\-_]*)/i,/^(?:.)/i,/^(?:$)/i],conditions:{acc_descr_multiline:{rules:[5,6],inclusive:!1},acc_descr:{rules:[3],inclusive:!1},acc_title:{rules:[1],inclusive:!1},open_directive:{rules:[8],inclusive:!1},type_directive:{rules:[9,10],inclusive:!1},arg_directive:{rules:[10,11],inclusive:!1},block:{rules:[21,22,23,24,25,26,27,28],inclusive:!1},INITIAL:{rules:[0,2,4,7,12,13,14,15,16,17,18,19,20,29,30,31,32,33,34,35,36,37,38,39,40,41,42],inclusive:!0}}};return A}();M.lexer=S;function R(){this.yy={}}return R.prototype=M,M.Parser=R,new R}();a4.parser=a4;const Fet=t=>t.match(/^\s*erDiagram/)!==null;let tu={},s4=[];const Pet={ZERO_OR_ONE:"ZERO_OR_ONE",ZERO_OR_MORE:"ZERO_OR_MORE",ONE_OR_MORE:"ONE_OR_MORE",ONLY_ONE:"ONLY_ONE"},qet={NON_IDENTIFYING:"NON_IDENTIFYING",IDENTIFYING:"IDENTIFYING"},Vet=function(t,e,r){Xe.parseDirective(this,t,e,r)},eM=function(t){return typeof tu[t]>"u"&&(tu[t]={attributes:[]},H.info("Added new entity :",t)),tu[t]},zet={Cardinality:Pet,Identification:qet,parseDirective:Vet,getConfig:()=>nt().er,addEntity:eM,addAttributes:function(t,e){let r=eM(t),n;for(n=e.length-1;n>=0;n--)r.attributes.push(e[n]),H.debug("Added attribute ",e[n].attributeName)},getEntities:()=>tu,addRelationship:function(t,e,r,n){let i={entityA:t,roleA:e,entityB:r,relSpec:n};s4.push(i),H.debug("Added new relationship :",i)},getRelationships:()=>s4,clear:function(){tu={},s4=[],ci()},setAccTitle:Yn,getAccTitle:ui,setAccDescription:hi,getAccDescription:fi},ua={ONLY_ONE_START:"ONLY_ONE_START",ONLY_ONE_END:"ONLY_ONE_END",ZERO_OR_ONE_START:"ZERO_OR_ONE_START",ZERO_OR_ONE_END:"ZERO_OR_ONE_END",ONE_OR_MORE_START:"ONE_OR_MORE_START",ONE_OR_MORE_END:"ONE_OR_MORE_END",ZERO_OR_MORE_START:"ZERO_OR_MORE_START",ZERO_OR_MORE_END:"ZERO_OR_MORE_END"},ha={ERMarkers:ua,insertMarkers:function(t,e){let r;t.append("defs").append("marker").attr("id",ua.ONLY_ONE_START).attr("refX",0).attr("refY",9).attr("markerWidth",18).attr("markerHeight",18).attr("orient","auto").append("path").attr("stroke",e.stroke).attr("fill","none").attr("d","M9,0 L9,18 M15,0 L15,18"),t.append("defs").append("marker").attr("id",ua.ONLY_ONE_END).attr("refX",18).attr("refY",9).attr("markerWidth",18).attr("markerHeight",18).attr("orient","auto").append("path").attr("stroke",e.stroke).attr("fill","none").attr("d","M3,0 L3,18 M9,0 L9,18"),r=t.append("defs").append("marker").attr("id",ua.ZERO_OR_ONE_START).attr("refX",0).attr("refY",9).attr("markerWidth",30).attr("markerHeight",18).attr("orient","auto"),r.append("circle").attr("stroke",e.stroke).attr("fill","white").attr("cx",21).attr("cy",9).attr("r",6),r.append("path").attr("stroke",e.stroke).attr("fill","none").attr("d","M9,0 L9,18"),r=t.append("defs").append("marker").attr("id",ua.ZERO_OR_ONE_END).attr("refX",30).attr("refY",9).attr("markerWidth",30).attr("markerHeight",18).attr("orient","auto"),r.append("circle").attr("stroke",e.stroke).attr("fill","white").attr("cx",9).attr("cy",9).attr("r",6),r.append("path").attr("stroke",e.stroke).attr("fill","none").attr("d","M21,0 L21,18"),t.append("defs").append("marker").attr("id",ua.ONE_OR_MORE_START).attr("refX",18).attr("refY",18).attr("markerWidth",45).attr("markerHeight",36).attr("orient","auto").append("path").attr("stroke",e.stroke).attr("fill","none").attr("d","M0,18 Q 18,0 36,18 Q 18,36 0,18 M42,9 L42,27"),t.append("defs").append("marker").attr("id",ua.ONE_OR_MORE_END).attr("refX",27).attr("refY",18).attr("markerWidth",45).attr("markerHeight",36).attr("orient","auto").append("path").attr("stroke",e.stroke).attr("fill","none").attr("d","M3,9 L3,27 M9,18 Q27,0 45,18 Q27,36 9,18"),r=t.append("defs").append("marker").attr("id",ua.ZERO_OR_MORE_START).attr("refX",18).attr("refY",18).attr("markerWidth",57).attr("markerHeight",36).attr("orient","auto"),r.append("circle").attr("stroke",e.stroke).attr("fill","white").attr("cx",48).attr("cy",18).attr("r",6),r.append("path").attr("stroke",e.stroke).attr("fill","none").attr("d","M0,18 Q18,0 36,18 Q18,36 0,18"),r=t.append("defs").append("marker").attr("id",ua.ZERO_OR_MORE_END).attr("refX",39).attr("refY",18).attr("markerWidth",57).attr("markerHeight",36).attr("orient","auto"),r.append("circle").attr("stroke",e.stroke).attr("fill","white").attr("cx",9).attr("cy",18).attr("r",6),r.append("path").attr("stroke",e.stroke).attr("fill","none").attr("d","M21,18 Q39,0 57,18 Q39,36 21,18")}};let $1;const Yet=new Uint8Array(16);function Uet(){if(!$1&&($1=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!$1))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return $1(Yet)}const Br=[];for(let t=0;t<256;++t)Br.push((t+256).toString(16).slice(1));function Wet(t,e=0){return(Br[t[e+0]]+Br[t[e+1]]+Br[t[e+2]]+Br[t[e+3]]+"-"+Br[t[e+4]]+Br[t[e+5]]+"-"+Br[t[e+6]]+Br[t[e+7]]+"-"+Br[t[e+8]]+Br[t[e+9]]+"-"+Br[t[e+10]]+Br[t[e+11]]+Br[t[e+12]]+Br[t[e+13]]+Br[t[e+14]]+Br[t[e+15]]).toLowerCase()}const rM={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Het(t,e,r){if(rM.randomUUID&&!e&&!t)return rM.randomUUID();t=t||{};const n=t.random||(t.rng||Uet)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){r=r||0;for(let i=0;i<16;++i)e[r+i]=n[i];return e}return Wet(n)}const Get=/[^A-Za-z0-9]([\W])*/g;let Ye={},eu=new Map;const jet=function(t){const e=Object.keys(t);for(let r=0;r<e.length;r++)Ye[e[r]]=t[e[r]]},$et=(t,e,r)=>{const n=Ye.entityPadding/3,i=Ye.entityPadding/3,a=Ye.fontSize*.85,s=e.node().getBBox(),o=[];let l=!1,u=!1,h=0,d=0,f=0,p=0,m=s.height+n*2,_=1;r.forEach(k=>{k.attributeKeyType!==void 0&&(l=!0),k.attributeComment!==void 0&&(u=!0)}),r.forEach(k=>{const T=`${e.node().id}-attr-${_}`;let C=0;const M=ja(k.attributeType),S=t.append("text").attr("class","er entityLabel").attr("id",`${T}-type`).attr("x",0).attr("y",0).attr("dominant-baseline","middle").attr("text-anchor","left").attr("style","font-family: "+nt().fontFamily+"; font-size: "+a+"px").text(M),R=t.append("text").attr("class","er entityLabel").attr("id",`${T}-name`).attr("x",0).attr("y",0).attr("dominant-baseline","middle").attr("text-anchor","left").attr("style","font-family: "+nt().fontFamily+"; font-size: "+a+"px").text(k.attributeName),A={};A.tn=S,A.nn=R;const L=S.node().getBBox(),v=R.node().getBBox();if(h=Math.max(h,L.width),d=Math.max(d,v.width),C=Math.max(L.height,v.height),l){const B=t.append("text").attr("class","er entityLabel").attr("id",`${T}-key`).attr("x",0).attr("y",0).attr("dominant-baseline","middle").attr("text-anchor","left").attr("style","font-family: "+nt().fontFamily+"; font-size: "+a+"px").text(k.attributeKeyType||"");A.kn=B;const w=B.node().getBBox();f=Math.max(f,w.width),C=Math.max(C,w.height)}if(u){const B=t.append("text").attr("class","er entityLabel").attr("id",`${T}-comment`).attr("x",0).attr("y",0).attr("dominant-baseline","middle").attr("text-anchor","left").attr("style","font-family: "+nt().fontFamily+"; font-size: "+a+"px").text(k.attributeComment||"");A.cn=B;const w=B.node().getBBox();p=Math.max(p,w.width),C=Math.max(C,w.height)}A.height=C,o.push(A),m+=C+n*2,_+=1});let y=4;l&&(y+=2),u&&(y+=2);const b=h+d+f+p,x={width:Math.max(Ye.minEntityWidth,Math.max(s.width+Ye.entityPadding*2,b+i*y)),height:r.length>0?m:Math.max(Ye.minEntityHeight,s.height+Ye.entityPadding*2)};if(r.length>0){const k=Math.max(0,(x.width-b-i*y)/(y/2));e.attr("transform","translate("+x.width/2+","+(n+s.height/2)+")");let T=s.height+n*2,C="attributeBoxOdd";o.forEach(M=>{const S=T+n+M.height/2;M.tn.attr("transform","translate("+i+","+S+")");const R=t.insert("rect","#"+M.tn.node().id).attr("class",`er ${C}`).attr("fill",Ye.fill).attr("fill-opacity","100%").attr("stroke",Ye.stroke).attr("x",0).attr("y",T).attr("width",h+i*2+k).attr("height",M.height+n*2),A=parseFloat(R.attr("x"))+parseFloat(R.attr("width"));M.nn.attr("transform","translate("+(A+i)+","+S+")");const L=t.insert("rect","#"+M.nn.node().id).attr("class",`er ${C}`).attr("fill",Ye.fill).attr("fill-opacity","100%").attr("stroke",Ye.stroke).attr("x",A).attr("y",T).attr("width",d+i*2+k).attr("height",M.height+n*2);let v=parseFloat(L.attr("x"))+parseFloat(L.attr("width"));if(l){M.kn.attr("transform","translate("+(v+i)+","+S+")");const B=t.insert("rect","#"+M.kn.node().id).attr("class",`er ${C}`).attr("fill",Ye.fill).attr("fill-opacity","100%").attr("stroke",Ye.stroke).attr("x",v).attr("y",T).attr("width",f+i*2+k).attr("height",M.height+n*2);v=parseFloat(B.attr("x"))+parseFloat(B.attr("width"))}u&&(M.cn.attr("transform","translate("+(v+i)+","+S+")"),t.insert("rect","#"+M.cn.node().id).attr("class",`er ${C}`).attr("fill",Ye.fill).attr("fill-opacity","100%").attr("stroke",Ye.stroke).attr("x",v).attr("y",T).attr("width",p+i*2+k).attr("height",M.height+n*2)),T+=M.height+n*2,C=C==="attributeBoxOdd"?"attributeBoxEven":"attributeBoxOdd"})}else x.height=Math.max(Ye.minEntityHeight,m),e.attr("transform","translate("+x.width/2+","+x.height/2+")");return x},Xet=function(t,e,r){const n=Object.keys(e);let i;return n.forEach(function(a){const s=trt(a,"entity");eu.set(a,s);const o=t.append("g").attr("id",s);i=i===void 0?s:i;const l="text-"+s,u=o.append("text").attr("class","er entityLabel").attr("id",l).attr("x",0).attr("y",0).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("style","font-family: "+nt().fontFamily+"; font-size: "+Ye.fontSize+"px").text(a),{width:h,height:d}=$et(o,u,e[a].attributes),p=o.insert("rect","#"+l).attr("class","er entityBox").attr("fill",Ye.fill).attr("fill-opacity","100%").attr("stroke",Ye.stroke).attr("x",0).attr("y",0).attr("width",h).attr("height",d).node().getBBox();r.setNode(s,{width:p.width,height:p.height,shape:"rect",id:s})}),i},Ket=function(t,e){e.nodes().forEach(function(r){typeof r<"u"&&typeof e.node(r)<"u"&&t.select("#"+r).attr("transform","translate("+(e.node(r).x-e.node(r).width/2)+","+(e.node(r).y-e.node(r).height/2)+" )")})},nM=function(t){return(t.entityA+t.roleA+t.entityB).replace(/\s/g,"")},Zet=function(t,e){return t.forEach(function(r){e.setEdge(eu.get(r.entityA),eu.get(r.entityB),{relationship:r},nM(r))}),t};let iM=0;const Qet=function(t,e,r,n,i){iM++;const a=r.edge(eu.get(e.entityA),eu.get(e.entityB),nM(e)),s=Ua().x(function(m){return m.x}).y(function(m){return m.y}).curve(Os),o=t.insert("path","#"+n).attr("class","er relationshipLine").attr("d",s(a.points)).attr("stroke",Ye.stroke).attr("fill","none");e.relSpec.relType===i.db.Identification.NON_IDENTIFYING&&o.attr("stroke-dasharray","8,8");let l="";switch(Ye.arrowMarkerAbsolute&&(l=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,l=l.replace(/\(/g,"\\("),l=l.replace(/\)/g,"\\)")),e.relSpec.cardA){case i.db.Cardinality.ZERO_OR_ONE:o.attr("marker-end","url("+l+"#"+ha.ERMarkers.ZERO_OR_ONE_END+")");break;case i.db.Cardinality.ZERO_OR_MORE:o.attr("marker-end","url("+l+"#"+ha.ERMarkers.ZERO_OR_MORE_END+")");break;case i.db.Cardinality.ONE_OR_MORE:o.attr("marker-end","url("+l+"#"+ha.ERMarkers.ONE_OR_MORE_END+")");break;case i.db.Cardinality.ONLY_ONE:o.attr("marker-end","url("+l+"#"+ha.ERMarkers.ONLY_ONE_END+")");break}switch(e.relSpec.cardB){case i.db.Cardinality.ZERO_OR_ONE:o.attr("marker-start","url("+l+"#"+ha.ERMarkers.ZERO_OR_ONE_START+")");break;case i.db.Cardinality.ZERO_OR_MORE:o.attr("marker-start","url("+l+"#"+ha.ERMarkers.ZERO_OR_MORE_START+")");break;case i.db.Cardinality.ONE_OR_MORE:o.attr("marker-start","url("+l+"#"+ha.ERMarkers.ONE_OR_MORE_START+")");break;case i.db.Cardinality.ONLY_ONE:o.attr("marker-start","url("+l+"#"+ha.ERMarkers.ONLY_ONE_START+")");break}const u=o.node().getTotalLength(),h=o.node().getPointAtLength(u*.5),d="rel"+iM,p=t.append("text").attr("class","er relationshipLabel").attr("id",d).attr("x",h.x).attr("y",h.y).attr("text-anchor","middle").attr("dominant-baseline","middle").attr("style","font-family: "+nt().fontFamily+"; font-size: "+Ye.fontSize+"px").text(e.roleA).node().getBBox();t.insert("rect","#"+d).attr("class","er relationshipLabelBox").attr("x",h.x-p.width/2).attr("y",h.y-p.height/2).attr("width",p.width).attr("height",p.height).attr("fill","white").attr("fill-opacity","85%")},Jet=function(t,e,r,n){Ye=nt().er,H.info("Drawing ER diagram");const i=nt().securityLevel;let a;i==="sandbox"&&(a=St("#i"+e));const o=St(i==="sandbox"?a.nodes()[0].contentDocument.body:"body").select(`[id='${e}']`);ha.insertMarkers(o,Ye);let l;l=new cr.Graph({multigraph:!0,directed:!0,compound:!1}).setGraph({rankdir:Ye.layoutDirection,marginx:20,marginy:20,nodesep:100,edgesep:100,ranksep:100}).setDefaultEdgeLabel(function(){return{}});const u=Xet(o,n.db.getEntities(),l),h=Zet(n.db.getRelationships(),l);Zc.layout(l),Ket(o,l),h.forEach(function(_){Qet(o,_,l,u,n)});const d=Ye.diagramPadding,f=o.node().getBBox(),p=f.width+d*2,m=f.height+d*2;li(o,m,p,Ye.useMaxWidth),o.attr("viewBox",`${f.x-d} ${f.y-d} ${p} ${m}`),bn(n.db,o,e)};function trt(t="",e=""){const r=t.replace(Get,"");return`${aM(e)}${aM(r)}${Het()}`}function aM(t=""){return t.length>0?`${t}-`:""}const ert={setConf:jet,draw:Jet};var X1=function(){var t=function(Ln,Xt,ee,ce){for(ee=ee||{},ce=Ln.length;ce--;ee[Ln[ce]]=Xt);return ee},e=[1,9],r=[1,7],n=[1,6],i=[1,8],a=[1,20,21,22,23,38,44,46,48,52,66,67,86,87,88,89,90,91,95,105,106,109,111,112,118,119,120,121,122,123,124,125,126,127],s=[2,10],o=[1,20],l=[1,21],u=[1,22],h=[1,23],d=[1,30],f=[1,32],p=[1,33],m=[1,34],_=[1,62],y=[1,48],b=[1,52],x=[1,36],k=[1,37],T=[1,38],C=[1,39],M=[1,40],S=[1,56],R=[1,63],A=[1,51],L=[1,53],v=[1,55],B=[1,59],w=[1,60],D=[1,41],N=[1,42],z=[1,43],X=[1,44],ct=[1,61],J=[1,50],Y=[1,54],$=[1,57],lt=[1,58],ut=[1,49],W=[1,66],tt=[1,71],K=[1,20,21,22,23,38,42,44,46,48,52,66,67,86,87,88,89,90,91,95,105,106,109,111,112,118,119,120,121,122,123,124,125,126,127],it=[1,75],Z=[1,74],V=[1,76],Q=[20,21,23,81,82],q=[1,99],U=[1,104],F=[1,107],j=[1,108],P=[1,101],et=[1,106],at=[1,109],It=[1,102],Lt=[1,114],Rt=[1,113],Ct=[1,103],pt=[1,105],mt=[1,110],vt=[1,111],Tt=[1,112],ft=[1,115],le=[20,21,22,23,81,82],Dt=[20,21,22,23,53,81,82],Gt=[20,21,22,23,40,52,53,55,57,59,61,63,65,66,67,69,71,73,74,76,81,82,91,95,105,106,109,111,112,122,123,124,125,126,127],$t=[20,21,23],Qt=[20,21,23,52,66,67,81,82,91,95,105,106,109,111,112,122,123,124,125,126,127],we=[1,12,20,21,22,23,24,38,42,44,46,48,52,66,67,86,87,88,89,90,91,95,105,106,109,111,112,118,119,120,121,122,123,124,125,126,127],jt=[52,66,67,91,95,105,106,109,111,112,122,123,124,125,126,127],Ft=[1,149],zt=[1,157],wt=[1,158],bt=[1,159],Et=[1,160],kt=[1,144],Ut=[1,145],gt=[1,141],he=[1,152],yt=[1,153],ne=[1,154],ve=[1,155],ye=[1,156],be=[1,161],Te=[1,162],Wt=[1,147],se=[1,150],me=[1,146],ue=[1,143],_a=[20,21,22,23,38,42,44,46,48,52,66,67,86,87,88,89,90,91,95,105,106,109,111,112,118,119,120,121,122,123,124,125,126,127],Hr=[1,165],Ie=[20,21,22,23,26,52,66,67,91,105,106,109,111,112,122,123,124,125,126,127],oe=[20,21,22,23,24,26,38,40,41,42,52,56,58,60,62,64,66,67,68,70,72,73,75,77,81,82,86,87,88,89,90,91,92,95,105,106,109,111,112,113,114,122,123,124,125,126,127],Ke=[12,21,22,24],wr=[22,106],Ge=[1,250],Ze=[1,245],qt=[1,246],st=[1,254],At=[1,251],Nt=[1,248],Jt=[1,247],ze=[1,249],Pe=[1,252],qe=[1,253],Tr=[1,255],Ve=[1,273],va=[20,21,23,106],Ce=[20,21,22,23,66,67,86,102,105,106,109,110,111,112,113],Wi={trace:function(){},yy:{},symbols_:{error:2,start:3,mermaidDoc:4,directive:5,openDirective:6,typeDirective:7,closeDirective:8,separator:9,":":10,argDirective:11,open_directive:12,type_directive:13,arg_directive:14,close_directive:15,graphConfig:16,document:17,line:18,statement:19,SEMI:20,NEWLINE:21,SPACE:22,EOF:23,GRAPH:24,NODIR:25,DIR:26,FirstStmtSeperator:27,ending:28,endToken:29,spaceList:30,spaceListNewline:31,verticeStatement:32,styleStatement:33,linkStyleStatement:34,classDefStatement:35,classStatement:36,clickStatement:37,subgraph:38,text:39,SQS:40,SQE:41,end:42,direction:43,acc_title:44,acc_title_value:45,acc_descr:46,acc_descr_value:47,acc_descr_multiline_value:48,link:49,node:50,vertex:51,AMP:52,STYLE_SEPARATOR:53,idString:54,DOUBLECIRCLESTART:55,DOUBLECIRCLEEND:56,PS:57,PE:58,"(-":59,"-)":60,STADIUMSTART:61,STADIUMEND:62,SUBROUTINESTART:63,SUBROUTINEEND:64,VERTEX_WITH_PROPS_START:65,ALPHA:66,COLON:67,PIPE:68,CYLINDERSTART:69,CYLINDEREND:70,DIAMOND_START:71,DIAMOND_STOP:72,TAGEND:73,TRAPSTART:74,TRAPEND:75,INVTRAPSTART:76,INVTRAPEND:77,linkStatement:78,arrowText:79,TESTSTR:80,START_LINK:81,LINK:82,textToken:83,STR:84,keywords:85,STYLE:86,LINKSTYLE:87,CLASSDEF:88,CLASS:89,CLICK:90,DOWN:91,UP:92,textNoTags:93,textNoTagsToken:94,DEFAULT:95,stylesOpt:96,alphaNum:97,CALLBACKNAME:98,CALLBACKARGS:99,HREF:100,LINK_TARGET:101,HEX:102,numList:103,INTERPOLATE:104,NUM:105,COMMA:106,style:107,styleComponent:108,MINUS:109,UNIT:110,BRKT:111,DOT:112,PCT:113,TAGSTART:114,alphaNumToken:115,idStringToken:116,alphaNumStatement:117,direction_tb:118,direction_bt:119,direction_rl:120,direction_lr:121,PUNCTUATION:122,UNICODE_TEXT:123,PLUS:124,EQUALS:125,MULT:126,UNDERSCORE:127,graphCodeTokens:128,ARROW_CROSS:129,ARROW_POINT:130,ARROW_CIRCLE:131,ARROW_OPEN:132,QUOTE:133,$accept:0,$end:1},terminals_:{2:"error",10:":",12:"open_directive",13:"type_directive",14:"arg_directive",15:"close_directive",20:"SEMI",21:"NEWLINE",22:"SPACE",23:"EOF",24:"GRAPH",25:"NODIR",26:"DIR",38:"subgraph",40:"SQS",41:"SQE",42:"end",44:"acc_title",45:"acc_title_value",46:"acc_descr",47:"acc_descr_value",48:"acc_descr_multiline_value",52:"AMP",53:"STYLE_SEPARATOR",55:"DOUBLECIRCLESTART",56:"DOUBLECIRCLEEND",57:"PS",58:"PE",59:"(-",60:"-)",61:"STADIUMSTART",62:"STADIUMEND",63:"SUBROUTINESTART",64:"SUBROUTINEEND",65:"VERTEX_WITH_PROPS_START",66:"ALPHA",67:"COLON",68:"PIPE",69:"CYLINDERSTART",70:"CYLINDEREND",71:"DIAMOND_START",72:"DIAMOND_STOP",73:"TAGEND",74:"TRAPSTART",75:"TRAPEND",76:"INVTRAPSTART",77:"INVTRAPEND",80:"TESTSTR",81:"START_LINK",82:"LINK",84:"STR",86:"STYLE",87:"LINKSTYLE",88:"CLASSDEF",89:"CLASS",90:"CLICK",91:"DOWN",92:"UP",95:"DEFAULT",98:"CALLBACKNAME",99:"CALLBACKARGS",100:"HREF",101:"LINK_TARGET",102:"HEX",104:"INTERPOLATE",105:"NUM",106:"COMMA",109:"MINUS",110:"UNIT",111:"BRKT",112:"DOT",113:"PCT",114:"TAGSTART",118:"direction_tb",119:"direction_bt",120:"direction_rl",121:"direction_lr",122:"PUNCTUATION",123:"UNICODE_TEXT",124:"PLUS",125:"EQUALS",126:"MULT",127:"UNDERSCORE",129:"ARROW_CROSS",130:"ARROW_POINT",131:"ARROW_CIRCLE",132:"ARROW_OPEN",133:"QUOTE"},productions_:[0,[3,1],[3,2],[5,4],[5,6],[6,1],[7,1],[11,1],[8,1],[4,2],[17,0],[17,2],[18,1],[18,1],[18,1],[18,1],[18,1],[16,2],[16,2],[16,2],[16,3],[28,2],[28,1],[29,1],[29,1],[29,1],[27,1],[27,1],[27,2],[31,2],[31,2],[31,1],[31,1],[30,2],[30,1],[19,2],[19,2],[19,2],[19,2],[19,2],[19,2],[19,9],[19,6],[19,4],[19,1],[19,2],[19,2],[19,1],[9,1],[9,1],[9,1],[32,3],[32,4],[32,2],[32,1],[50,1],[50,5],[50,3],[51,4],[51,4],[51,6],[51,4],[51,4],[51,4],[51,8],[51,4],[51,4],[51,4],[51,6],[51,4],[51,4],[51,4],[51,4],[51,4],[51,1],[49,2],[49,3],[49,3],[49,1],[49,3],[78,1],[79,3],[39,1],[39,2],[39,1],[85,1],[85,1],[85,1],[85,1],[85,1],[85,1],[85,1],[85,1],[85,1],[85,1],[85,1],[93,1],[93,2],[35,5],[35,5],[36,5],[37,2],[37,4],[37,3],[37,5],[37,2],[37,4],[37,4],[37,6],[37,2],[37,4],[37,2],[37,4],[37,4],[37,6],[33,5],[33,5],[34,5],[34,5],[34,9],[34,9],[34,7],[34,7],[103,1],[103,3],[96,1],[96,3],[107,1],[107,2],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[83,1],[83,1],[83,1],[83,1],[83,1],[83,1],[94,1],[94,1],[94,1],[94,1],[54,1],[54,2],[97,1],[97,2],[117,1],[117,1],[117,1],[117,1],[43,1],[43,1],[43,1],[43,1],[115,1],[115,1],[115,1],[115,1],[115,1],[115,1],[115,1],[115,1],[115,1],[115,1],[115,1],[115,1],[115,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[116,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1],[128,1]],performAction:function(Xt,ee,ce,Pt,je,rt,Ks){var ot=rt.length-1;switch(je){case 5:Pt.parseDirective("%%{","open_directive");break;case 6:Pt.parseDirective(rt[ot],"type_directive");break;case 7:rt[ot]=rt[ot].trim().replace(/'/g,'"'),Pt.parseDirective(rt[ot],"arg_directive");break;case 8:Pt.parseDirective("}%%","close_directive","flowchart");break;case 10:this.$=[];break;case 11:(!Array.isArray(rt[ot])||rt[ot].length>0)&&rt[ot-1].push(rt[ot]),this.$=rt[ot-1];break;case 12:case 82:case 84:case 96:case 152:case 154:case 155:this.$=rt[ot];break;case 19:Pt.setDirection("TB"),this.$="TB";break;case 20:Pt.setDirection(rt[ot-1]),this.$=rt[ot-1];break;case 35:this.$=rt[ot-1].nodes;break;case 36:case 37:case 38:case 39:case 40:this.$=[];break;case 41:this.$=Pt.addSubGraph(rt[ot-6],rt[ot-1],rt[ot-4]);break;case 42:this.$=Pt.addSubGraph(rt[ot-3],rt[ot-1],rt[ot-3]);break;case 43:this.$=Pt.addSubGraph(void 0,rt[ot-1],void 0);break;case 45:this.$=rt[ot].trim(),Pt.setAccTitle(this.$);break;case 46:case 47:this.$=rt[ot].trim(),Pt.setAccDescription(this.$);break;case 51:Pt.addLink(rt[ot-2].stmt,rt[ot],rt[ot-1]),this.$={stmt:rt[ot],nodes:rt[ot].concat(rt[ot-2].nodes)};break;case 52:Pt.addLink(rt[ot-3].stmt,rt[ot-1],rt[ot-2]),this.$={stmt:rt[ot-1],nodes:rt[ot-1].concat(rt[ot-3].nodes)};break;case 53:this.$={stmt:rt[ot-1],nodes:rt[ot-1]};break;case 54:this.$={stmt:rt[ot],nodes:rt[ot]};break;case 55:this.$=[rt[ot]];break;case 56:this.$=rt[ot-4].concat(rt[ot]);break;case 57:this.$=[rt[ot-2]],Pt.setClass(rt[ot-2],rt[ot]);break;case 58:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"square");break;case 59:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"doublecircle");break;case 60:this.$=rt[ot-5],Pt.addVertex(rt[ot-5],rt[ot-2],"circle");break;case 61:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"ellipse");break;case 62:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"stadium");break;case 63:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"subroutine");break;case 64:this.$=rt[ot-7],Pt.addVertex(rt[ot-7],rt[ot-1],"rect",void 0,void 0,void 0,Object.fromEntries([[rt[ot-5],rt[ot-3]]]));break;case 65:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"cylinder");break;case 66:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"round");break;case 67:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"diamond");break;case 68:this.$=rt[ot-5],Pt.addVertex(rt[ot-5],rt[ot-2],"hexagon");break;case 69:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"odd");break;case 70:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"trapezoid");break;case 71:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"inv_trapezoid");break;case 72:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"lean_right");break;case 73:this.$=rt[ot-3],Pt.addVertex(rt[ot-3],rt[ot-1],"lean_left");break;case 74:this.$=rt[ot],Pt.addVertex(rt[ot]);break;case 75:rt[ot-1].text=rt[ot],this.$=rt[ot-1];break;case 76:case 77:rt[ot-2].text=rt[ot-1],this.$=rt[ot-2];break;case 78:this.$=rt[ot];break;case 79:var Gr=Pt.destructLink(rt[ot],rt[ot-2]);this.$={type:Gr.type,stroke:Gr.stroke,length:Gr.length,text:rt[ot-1]};break;case 80:var Gr=Pt.destructLink(rt[ot]);this.$={type:Gr.type,stroke:Gr.stroke,length:Gr.length};break;case 81:this.$=rt[ot-1];break;case 83:case 97:case 153:this.$=rt[ot-1]+""+rt[ot];break;case 98:case 99:this.$=rt[ot-4],Pt.addClass(rt[ot-2],rt[ot]);break;case 100:this.$=rt[ot-4],Pt.setClass(rt[ot-2],rt[ot]);break;case 101:case 109:this.$=rt[ot-1],Pt.setClickEvent(rt[ot-1],rt[ot]);break;case 102:case 110:this.$=rt[ot-3],Pt.setClickEvent(rt[ot-3],rt[ot-2]),Pt.setTooltip(rt[ot-3],rt[ot]);break;case 103:this.$=rt[ot-2],Pt.setClickEvent(rt[ot-2],rt[ot-1],rt[ot]);break;case 104:this.$=rt[ot-4],Pt.setClickEvent(rt[ot-4],rt[ot-3],rt[ot-2]),Pt.setTooltip(rt[ot-4],rt[ot]);break;case 105:case 111:this.$=rt[ot-1],Pt.setLink(rt[ot-1],rt[ot]);break;case 106:case 112:this.$=rt[ot-3],Pt.setLink(rt[ot-3],rt[ot-2]),Pt.setTooltip(rt[ot-3],rt[ot]);break;case 107:case 113:this.$=rt[ot-3],Pt.setLink(rt[ot-3],rt[ot-2],rt[ot]);break;case 108:case 114:this.$=rt[ot-5],Pt.setLink(rt[ot-5],rt[ot-4],rt[ot]),Pt.setTooltip(rt[ot-5],rt[ot-2]);break;case 115:this.$=rt[ot-4],Pt.addVertex(rt[ot-2],void 0,void 0,rt[ot]);break;case 116:case 118:this.$=rt[ot-4],Pt.updateLink(rt[ot-2],rt[ot]);break;case 117:this.$=rt[ot-4],Pt.updateLink([rt[ot-2]],rt[ot]);break;case 119:this.$=rt[ot-8],Pt.updateLinkInterpolate([rt[ot-6]],rt[ot-2]),Pt.updateLink([rt[ot-6]],rt[ot]);break;case 120:this.$=rt[ot-8],Pt.updateLinkInterpolate(rt[ot-6],rt[ot-2]),Pt.updateLink(rt[ot-6],rt[ot]);break;case 121:this.$=rt[ot-6],Pt.updateLinkInterpolate([rt[ot-4]],rt[ot]);break;case 122:this.$=rt[ot-6],Pt.updateLinkInterpolate(rt[ot-4],rt[ot]);break;case 123:case 125:this.$=[rt[ot]];break;case 124:case 126:rt[ot-2].push(rt[ot]),this.$=rt[ot-2];break;case 128:this.$=rt[ot-1]+rt[ot];break;case 150:this.$=rt[ot];break;case 151:this.$=rt[ot-1]+""+rt[ot];break;case 156:this.$="v";break;case 157:this.$="-";break;case 158:this.$={stmt:"dir",value:"TB"};break;case 159:this.$={stmt:"dir",value:"BT"};break;case 160:this.$={stmt:"dir",value:"RL"};break;case 161:this.$={stmt:"dir",value:"LR"};break}},table:[{3:1,4:2,5:3,6:5,12:e,16:4,21:r,22:n,24:i},{1:[3]},{1:[2,1]},{3:10,4:2,5:3,6:5,12:e,16:4,21:r,22:n,24:i},t(a,s,{17:11}),{7:12,13:[1,13]},{16:14,21:r,22:n,24:i},{16:15,21:r,22:n,24:i},{25:[1,16],26:[1,17]},{13:[2,5]},{1:[2,2]},{1:[2,9],18:18,19:19,20:o,21:l,22:u,23:h,32:24,33:25,34:26,35:27,36:28,37:29,38:d,43:31,44:f,46:p,48:m,50:35,51:45,52:_,54:46,66:y,67:b,86:x,87:k,88:T,89:C,90:M,91:S,95:R,105:A,106:L,109:v,111:B,112:w,116:47,118:D,119:N,120:z,121:X,122:ct,123:J,124:Y,125:$,126:lt,127:ut},{8:64,10:[1,65],15:W},t([10,15],[2,6]),t(a,[2,17]),t(a,[2,18]),t(a,[2,19]),{20:[1,68],21:[1,69],22:tt,27:67,30:70},t(K,[2,11]),t(K,[2,12]),t(K,[2,13]),t(K,[2,14]),t(K,[2,15]),t(K,[2,16]),{9:72,20:it,21:Z,23:V,49:73,78:77,81:[1,78],82:[1,79]},{9:80,20:it,21:Z,23:V},{9:81,20:it,21:Z,23:V},{9:82,20:it,21:Z,23:V},{9:83,20:it,21:Z,23:V},{9:84,20:it,21:Z,23:V},{9:86,20:it,21:Z,22:[1,85],23:V},t(K,[2,44]),{45:[1,87]},{47:[1,88]},t(K,[2,47]),t(Q,[2,54],{30:89,22:tt}),{22:[1,90]},{22:[1,91]},{22:[1,92]},{22:[1,93]},{26:q,52:U,66:F,67:j,84:[1,97],91:P,97:96,98:[1,94],100:[1,95],105:et,106:at,109:It,111:Lt,112:Rt,115:100,117:98,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t(K,[2,158]),t(K,[2,159]),t(K,[2,160]),t(K,[2,161]),t(le,[2,55],{53:[1,116]}),t(Dt,[2,74],{116:129,40:[1,117],52:_,55:[1,118],57:[1,119],59:[1,120],61:[1,121],63:[1,122],65:[1,123],66:y,67:b,69:[1,124],71:[1,125],73:[1,126],74:[1,127],76:[1,128],91:S,95:R,105:A,106:L,109:v,111:B,112:w,122:ct,123:J,124:Y,125:$,126:lt,127:ut}),t(Gt,[2,150]),t(Gt,[2,175]),t(Gt,[2,176]),t(Gt,[2,177]),t(Gt,[2,178]),t(Gt,[2,179]),t(Gt,[2,180]),t(Gt,[2,181]),t(Gt,[2,182]),t(Gt,[2,183]),t(Gt,[2,184]),t(Gt,[2,185]),t(Gt,[2,186]),t(Gt,[2,187]),t(Gt,[2,188]),t(Gt,[2,189]),t(Gt,[2,190]),{9:130,20:it,21:Z,23:V},{11:131,14:[1,132]},t($t,[2,8]),t(a,[2,20]),t(a,[2,26]),t(a,[2,27]),{21:[1,133]},t(Qt,[2,34],{30:134,22:tt}),t(K,[2,35]),{50:135,51:45,52:_,54:46,66:y,67:b,91:S,95:R,105:A,106:L,109:v,111:B,112:w,116:47,122:ct,123:J,124:Y,125:$,126:lt,127:ut},t(we,[2,48]),t(we,[2,49]),t(we,[2,50]),t(jt,[2,78],{79:136,68:[1,138],80:[1,137]}),{22:Ft,24:zt,26:wt,38:bt,39:139,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t([52,66,67,68,80,91,95,105,106,109,111,112,122,123,124,125,126,127],[2,80]),t(K,[2,36]),t(K,[2,37]),t(K,[2,38]),t(K,[2,39]),t(K,[2,40]),{22:Ft,24:zt,26:wt,38:bt,39:163,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t(_a,s,{17:164}),t(K,[2,45]),t(K,[2,46]),t(Q,[2,53],{52:Hr}),{26:q,52:U,66:F,67:j,91:P,97:166,102:[1,167],105:et,106:at,109:It,111:Lt,112:Rt,115:100,117:98,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{95:[1,168],103:169,105:[1,170]},{26:q,52:U,66:F,67:j,91:P,95:[1,171],97:172,105:et,106:at,109:It,111:Lt,112:Rt,115:100,117:98,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{26:q,52:U,66:F,67:j,91:P,97:173,105:et,106:at,109:It,111:Lt,112:Rt,115:100,117:98,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t($t,[2,101],{22:[1,174],99:[1,175]}),t($t,[2,105],{22:[1,176]}),t($t,[2,109],{115:100,117:178,22:[1,177],26:q,52:U,66:F,67:j,91:P,105:et,106:at,109:It,111:Lt,112:Rt,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft}),t($t,[2,111],{22:[1,179]}),t(Ie,[2,152]),t(Ie,[2,154]),t(Ie,[2,155]),t(Ie,[2,156]),t(Ie,[2,157]),t(oe,[2,162]),t(oe,[2,163]),t(oe,[2,164]),t(oe,[2,165]),t(oe,[2,166]),t(oe,[2,167]),t(oe,[2,168]),t(oe,[2,169]),t(oe,[2,170]),t(oe,[2,171]),t(oe,[2,172]),t(oe,[2,173]),t(oe,[2,174]),{52:_,54:180,66:y,67:b,91:S,95:R,105:A,106:L,109:v,111:B,112:w,116:47,122:ct,123:J,124:Y,125:$,126:lt,127:ut},{22:Ft,24:zt,26:wt,38:bt,39:181,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:182,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:184,42:Et,52:U,57:[1,183],66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:185,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:186,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:187,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{66:[1,188]},{22:Ft,24:zt,26:wt,38:bt,39:189,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:190,42:Et,52:U,66:F,67:j,71:[1,191],73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:192,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:193,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:194,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t(Gt,[2,151]),t(Ke,[2,3]),{8:195,15:W},{15:[2,7]},t(a,[2,28]),t(Qt,[2,33]),t(Q,[2,51],{30:196,22:tt}),t(jt,[2,75],{22:[1,197]}),{22:[1,198]},{22:Ft,24:zt,26:wt,38:bt,39:199,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,66:F,67:j,73:kt,81:Ut,82:[1,200],83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t(oe,[2,82]),t(oe,[2,84]),t(oe,[2,140]),t(oe,[2,141]),t(oe,[2,142]),t(oe,[2,143]),t(oe,[2,144]),t(oe,[2,145]),t(oe,[2,146]),t(oe,[2,147]),t(oe,[2,148]),t(oe,[2,149]),t(oe,[2,85]),t(oe,[2,86]),t(oe,[2,87]),t(oe,[2,88]),t(oe,[2,89]),t(oe,[2,90]),t(oe,[2,91]),t(oe,[2,92]),t(oe,[2,93]),t(oe,[2,94]),t(oe,[2,95]),{9:203,20:it,21:Z,22:Ft,23:V,24:zt,26:wt,38:bt,40:[1,202],42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{18:18,19:19,20:o,21:l,22:u,23:h,32:24,33:25,34:26,35:27,36:28,37:29,38:d,42:[1,204],43:31,44:f,46:p,48:m,50:35,51:45,52:_,54:46,66:y,67:b,86:x,87:k,88:T,89:C,90:M,91:S,95:R,105:A,106:L,109:v,111:B,112:w,116:47,118:D,119:N,120:z,121:X,122:ct,123:J,124:Y,125:$,126:lt,127:ut},{22:tt,30:205},{22:[1,206],26:q,52:U,66:F,67:j,91:P,105:et,106:at,109:It,111:Lt,112:Rt,115:100,117:178,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:[1,207]},{22:[1,208]},{22:[1,209],106:[1,210]},t(wr,[2,123]),{22:[1,211]},{22:[1,212],26:q,52:U,66:F,67:j,91:P,105:et,106:at,109:It,111:Lt,112:Rt,115:100,117:178,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:[1,213],26:q,52:U,66:F,67:j,91:P,105:et,106:at,109:It,111:Lt,112:Rt,115:100,117:178,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{84:[1,214]},t($t,[2,103],{22:[1,215]}),{84:[1,216],101:[1,217]},{84:[1,218]},t(Ie,[2,153]),{84:[1,219],101:[1,220]},t(le,[2,57],{116:129,52:_,66:y,67:b,91:S,95:R,105:A,106:L,109:v,111:B,112:w,122:ct,123:J,124:Y,125:$,126:lt,127:ut}),{22:Ft,24:zt,26:wt,38:bt,41:[1,221],42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,56:[1,222],66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:223,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,58:[1,224],66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,60:[1,225],66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,62:[1,226],66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,64:[1,227],66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{67:[1,228]},{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,66:F,67:j,70:[1,229],73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,66:F,67:j,72:[1,230],73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,39:231,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,41:[1,232],42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,66:F,67:j,73:kt,75:[1,233],77:[1,234],81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,66:F,67:j,73:kt,75:[1,236],77:[1,235],81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{9:237,20:it,21:Z,23:V},t(Q,[2,52],{52:Hr}),t(jt,[2,77]),t(jt,[2,76]),{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,66:F,67:j,68:[1,238],73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t(jt,[2,79]),t(oe,[2,83]),{22:Ft,24:zt,26:wt,38:bt,39:239,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t(_a,s,{17:240}),t(K,[2,43]),{51:241,52:_,54:46,66:y,67:b,91:S,95:R,105:A,106:L,109:v,111:B,112:w,116:47,122:ct,123:J,124:Y,125:$,126:lt,127:ut},{22:Ge,66:Ze,67:qt,86:st,96:242,102:At,105:Nt,107:243,108:244,109:Jt,110:ze,111:Pe,112:qe,113:Tr},{22:Ge,66:Ze,67:qt,86:st,96:256,102:At,105:Nt,107:243,108:244,109:Jt,110:ze,111:Pe,112:qe,113:Tr},{22:Ge,66:Ze,67:qt,86:st,96:257,102:At,104:[1,258],105:Nt,107:243,108:244,109:Jt,110:ze,111:Pe,112:qe,113:Tr},{22:Ge,66:Ze,67:qt,86:st,96:259,102:At,104:[1,260],105:Nt,107:243,108:244,109:Jt,110:ze,111:Pe,112:qe,113:Tr},{105:[1,261]},{22:Ge,66:Ze,67:qt,86:st,96:262,102:At,105:Nt,107:243,108:244,109:Jt,110:ze,111:Pe,112:qe,113:Tr},{22:Ge,66:Ze,67:qt,86:st,96:263,102:At,105:Nt,107:243,108:244,109:Jt,110:ze,111:Pe,112:qe,113:Tr},{26:q,52:U,66:F,67:j,91:P,97:264,105:et,106:at,109:It,111:Lt,112:Rt,115:100,117:98,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t($t,[2,102]),{84:[1,265]},t($t,[2,106],{22:[1,266]}),t($t,[2,107]),t($t,[2,110]),t($t,[2,112],{22:[1,267]}),t($t,[2,113]),t(Dt,[2,58]),t(Dt,[2,59]),{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,58:[1,268],66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t(Dt,[2,66]),t(Dt,[2,61]),t(Dt,[2,62]),t(Dt,[2,63]),{66:[1,269]},t(Dt,[2,65]),t(Dt,[2,67]),{22:Ft,24:zt,26:wt,38:bt,42:Et,52:U,66:F,67:j,72:[1,270],73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t(Dt,[2,69]),t(Dt,[2,70]),t(Dt,[2,72]),t(Dt,[2,71]),t(Dt,[2,73]),t(Ke,[2,4]),t([22,52,66,67,91,95,105,106,109,111,112,122,123,124,125,126,127],[2,81]),{22:Ft,24:zt,26:wt,38:bt,41:[1,271],42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{18:18,19:19,20:o,21:l,22:u,23:h,32:24,33:25,34:26,35:27,36:28,37:29,38:d,42:[1,272],43:31,44:f,46:p,48:m,50:35,51:45,52:_,54:46,66:y,67:b,86:x,87:k,88:T,89:C,90:M,91:S,95:R,105:A,106:L,109:v,111:B,112:w,116:47,118:D,119:N,120:z,121:X,122:ct,123:J,124:Y,125:$,126:lt,127:ut},t(le,[2,56]),t($t,[2,115],{106:Ve}),t(va,[2,125],{108:274,22:Ge,66:Ze,67:qt,86:st,102:At,105:Nt,109:Jt,110:ze,111:Pe,112:qe,113:Tr}),t(Ce,[2,127]),t(Ce,[2,129]),t(Ce,[2,130]),t(Ce,[2,131]),t(Ce,[2,132]),t(Ce,[2,133]),t(Ce,[2,134]),t(Ce,[2,135]),t(Ce,[2,136]),t(Ce,[2,137]),t(Ce,[2,138]),t(Ce,[2,139]),t($t,[2,116],{106:Ve}),t($t,[2,117],{106:Ve}),{22:[1,275]},t($t,[2,118],{106:Ve}),{22:[1,276]},t(wr,[2,124]),t($t,[2,98],{106:Ve}),t($t,[2,99],{106:Ve}),t($t,[2,100],{115:100,117:178,26:q,52:U,66:F,67:j,91:P,105:et,106:at,109:It,111:Lt,112:Rt,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft}),t($t,[2,104]),{101:[1,277]},{101:[1,278]},{58:[1,279]},{68:[1,280]},{72:[1,281]},{9:282,20:it,21:Z,23:V},t(K,[2,42]),{22:Ge,66:Ze,67:qt,86:st,102:At,105:Nt,107:283,108:244,109:Jt,110:ze,111:Pe,112:qe,113:Tr},t(Ce,[2,128]),{26:q,52:U,66:F,67:j,91:P,97:284,105:et,106:at,109:It,111:Lt,112:Rt,115:100,117:98,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{26:q,52:U,66:F,67:j,91:P,97:285,105:et,106:at,109:It,111:Lt,112:Rt,115:100,117:98,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t($t,[2,108]),t($t,[2,114]),t(Dt,[2,60]),{22:Ft,24:zt,26:wt,38:bt,39:286,42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:140,84:gt,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},t(Dt,[2,68]),t(_a,s,{17:287}),t(va,[2,126],{108:274,22:Ge,66:Ze,67:qt,86:st,102:At,105:Nt,109:Jt,110:ze,111:Pe,112:qe,113:Tr}),t($t,[2,121],{115:100,117:178,22:[1,288],26:q,52:U,66:F,67:j,91:P,105:et,106:at,109:It,111:Lt,112:Rt,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft}),t($t,[2,122],{115:100,117:178,22:[1,289],26:q,52:U,66:F,67:j,91:P,105:et,106:at,109:It,111:Lt,112:Rt,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft}),{22:Ft,24:zt,26:wt,38:bt,41:[1,290],42:Et,52:U,66:F,67:j,73:kt,81:Ut,83:201,85:151,86:he,87:yt,88:ne,89:ve,90:ye,91:be,92:Te,94:142,95:Wt,105:et,106:at,109:se,111:Lt,112:Rt,113:me,114:ue,115:148,122:Ct,123:pt,124:mt,125:vt,126:Tt,127:ft},{18:18,19:19,20:o,21:l,22:u,23:h,32:24,33:25,34:26,35:27,36:28,37:29,38:d,42:[1,291],43:31,44:f,46:p,48:m,50:35,51:45,52:_,54:46,66:y,67:b,86:x,87:k,88:T,89:C,90:M,91:S,95:R,105:A,106:L,109:v,111:B,112:w,116:47,118:D,119:N,120:z,121:X,122:ct,123:J,124:Y,125:$,126:lt,127:ut},{22:Ge,66:Ze,67:qt,86:st,96:292,102:At,105:Nt,107:243,108:244,109:Jt,110:ze,111:Pe,112:qe,113:Tr},{22:Ge,66:Ze,67:qt,86:st,96:293,102:At,105:Nt,107:243,108:244,109:Jt,110:ze,111:Pe,112:qe,113:Tr},t(Dt,[2,64]),t(K,[2,41]),t($t,[2,119],{106:Ve}),t($t,[2,120],{106:Ve})],defaultActions:{2:[2,1],9:[2,5],10:[2,2],132:[2,7]},parseError:function(Xt,ee){if(ee.recoverable)this.trace(Xt);else{var ce=new Error(Xt);throw ce.hash=ee,ce}},parse:function(Xt){var ee=this,ce=[0],Pt=[],je=[null],rt=[],Ks=this.table,ot="",Gr=0,C0=0,l_=2,S0=1,A0=rt.slice.call(arguments,1),mr=Object.create(this.lexer),Hi={yy:{}};for(var Gi in this.yy)Object.prototype.hasOwnProperty.call(this.yy,Gi)&&(Hi.yy[Gi]=this.yy[Gi]);mr.setInput(Xt,Hi.yy),Hi.yy.lexer=mr,Hi.yy.parser=this,typeof mr.yylloc>"u"&&(mr.yylloc={});var Zs=mr.yylloc;rt.push(Zs);var vu=mr.options&&mr.options.ranges;typeof Hi.yy.parseError=="function"?this.parseError=Hi.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function M0(){var In;return In=Pt.pop()||mr.lex()||S0,typeof In!="number"&&(In instanceof Array&&(Pt=In,In=Pt.pop()),In=ee.symbols_[In]||In),In}for(var Dr,De,hn,xa,_i={},ka,Rn,xu,yl;;){if(De=ce[ce.length-1],this.defaultActions[De]?hn=this.defaultActions[De]:((Dr===null||typeof Dr>"u")&&(Dr=M0()),hn=Ks[De]&&Ks[De][Dr]),typeof hn>"u"||!hn.length||!hn[0]){var Qs="";yl=[];for(ka in Ks[De])this.terminals_[ka]&&ka>l_&&yl.push("'"+this.terminals_[ka]+"'");mr.showPosition?Qs="Parse error on line "+(Gr+1)+`: +`+mr.showPosition()+` +Expecting `+yl.join(", ")+", got '"+(this.terminals_[Dr]||Dr)+"'":Qs="Parse error on line "+(Gr+1)+": Unexpected "+(Dr==S0?"end of input":"'"+(this.terminals_[Dr]||Dr)+"'"),this.parseError(Qs,{text:mr.match,token:this.terminals_[Dr]||Dr,line:mr.yylineno,loc:Zs,expected:yl})}if(hn[0]instanceof Array&&hn.length>1)throw new Error("Parse Error: multiple actions possible at state: "+De+", token: "+Dr);switch(hn[0]){case 1:ce.push(Dr),je.push(mr.yytext),rt.push(mr.yylloc),ce.push(hn[1]),Dr=null,C0=mr.yyleng,ot=mr.yytext,Gr=mr.yylineno,Zs=mr.yylloc;break;case 2:if(Rn=this.productions_[hn[1]][1],_i.$=je[je.length-Rn],_i._$={first_line:rt[rt.length-(Rn||1)].first_line,last_line:rt[rt.length-1].last_line,first_column:rt[rt.length-(Rn||1)].first_column,last_column:rt[rt.length-1].last_column},vu&&(_i._$.range=[rt[rt.length-(Rn||1)].range[0],rt[rt.length-1].range[1]]),xa=this.performAction.apply(_i,[ot,C0,Gr,Hi.yy,hn[1],je,rt].concat(A0)),typeof xa<"u")return xa;Rn&&(ce=ce.slice(0,-1*Rn*2),je=je.slice(0,-1*Rn),rt=rt.slice(0,-1*Rn)),ce.push(this.productions_[hn[1]][0]),je.push(_i.$),rt.push(_i._$),xu=Ks[ce[ce.length-2]][ce[ce.length-1]],ce.push(xu);break;case 3:return!0}}return!0}},E0=function(){var Ln={EOF:1,parseError:function(ee,ce){if(this.yy.parser)this.yy.parser.parseError(ee,ce);else throw new Error(ee)},setInput:function(Xt,ee){return this.yy=ee||this.yy||{},this._input=Xt,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var Xt=this._input[0];this.yytext+=Xt,this.yyleng++,this.offset++,this.match+=Xt,this.matched+=Xt;var ee=Xt.match(/(?:\r\n?|\n).*/g);return ee?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),Xt},unput:function(Xt){var ee=Xt.length,ce=Xt.split(/(?:\r\n?|\n)/g);this._input=Xt+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-ee),this.offset-=ee;var Pt=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),ce.length-1&&(this.yylineno-=ce.length-1);var je=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:ce?(ce.length===Pt.length?this.yylloc.first_column:0)+Pt[Pt.length-ce.length].length-ce[0].length:this.yylloc.first_column-ee},this.options.ranges&&(this.yylloc.range=[je[0],je[0]+this.yyleng-ee]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(Xt){this.unput(this.match.slice(Xt))},pastInput:function(){var Xt=this.matched.substr(0,this.matched.length-this.match.length);return(Xt.length>20?"...":"")+Xt.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var Xt=this.match;return Xt.length<20&&(Xt+=this._input.substr(0,20-Xt.length)),(Xt.substr(0,20)+(Xt.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var Xt=this.pastInput(),ee=new Array(Xt.length+1).join("-");return Xt+this.upcomingInput()+` +`+ee+"^"},test_match:function(Xt,ee){var ce,Pt,je;if(this.options.backtrack_lexer&&(je={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(je.yylloc.range=this.yylloc.range.slice(0))),Pt=Xt[0].match(/(?:\r\n?|\n).*/g),Pt&&(this.yylineno+=Pt.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:Pt?Pt[Pt.length-1].length-Pt[Pt.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+Xt[0].length},this.yytext+=Xt[0],this.match+=Xt[0],this.matches=Xt,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(Xt[0].length),this.matched+=Xt[0],ce=this.performAction.call(this,this.yy,this,ee,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),ce)return ce;if(this._backtrack){for(var rt in je)this[rt]=je[rt];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var Xt,ee,ce,Pt;this._more||(this.yytext="",this.match="");for(var je=this._currentRules(),rt=0;rt<je.length;rt++)if(ce=this._input.match(this.rules[je[rt]]),ce&&(!ee||ce[0].length>ee[0].length)){if(ee=ce,Pt=rt,this.options.backtrack_lexer){if(Xt=this.test_match(ce,je[rt]),Xt!==!1)return Xt;if(this._backtrack){ee=!1;continue}else return!1}else if(!this.options.flex)break}return ee?(Xt=this.test_match(ee,je[Pt]),Xt!==!1?Xt:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var ee=this.next();return ee||this.lex()},begin:function(ee){this.conditionStack.push(ee)},popState:function(){var ee=this.conditionStack.length-1;return ee>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(ee){return ee=this.conditionStack.length-1-Math.abs(ee||0),ee>=0?this.conditionStack[ee]:"INITIAL"},pushState:function(ee){this.begin(ee)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(ee,ce,Pt,je){switch(Pt){case 0:return this.begin("open_directive"),12;case 1:return this.begin("type_directive"),13;case 2:return this.popState(),this.begin("arg_directive"),10;case 3:return this.popState(),this.popState(),15;case 4:return 14;case 5:break;case 6:break;case 7:return this.begin("acc_title"),44;case 8:return this.popState(),"acc_title_value";case 9:return this.begin("acc_descr"),46;case 10:return this.popState(),"acc_descr_value";case 11:this.begin("acc_descr_multiline");break;case 12:this.popState();break;case 13:return"acc_descr_multiline_value";case 14:this.begin("string");break;case 15:this.popState();break;case 16:return"STR";case 17:return 86;case 18:return 95;case 19:return 87;case 20:return 104;case 21:return 88;case 22:return 89;case 23:this.begin("href");break;case 24:this.popState();break;case 25:return 100;case 26:this.begin("callbackname");break;case 27:this.popState();break;case 28:this.popState(),this.begin("callbackargs");break;case 29:return 98;case 30:this.popState();break;case 31:return 99;case 32:this.begin("click");break;case 33:this.popState();break;case 34:return 90;case 35:return ee.lex.firstGraph()&&this.begin("dir"),24;case 36:return ee.lex.firstGraph()&&this.begin("dir"),24;case 37:return 38;case 38:return 42;case 39:return 101;case 40:return 101;case 41:return 101;case 42:return 101;case 43:return this.popState(),25;case 44:return this.popState(),26;case 45:return this.popState(),26;case 46:return this.popState(),26;case 47:return this.popState(),26;case 48:return this.popState(),26;case 49:return this.popState(),26;case 50:return this.popState(),26;case 51:return this.popState(),26;case 52:return this.popState(),26;case 53:return this.popState(),26;case 54:return 118;case 55:return 119;case 56:return 120;case 57:return 121;case 58:return 105;case 59:return 111;case 60:return 53;case 61:return 67;case 62:return 52;case 63:return 20;case 64:return 106;case 65:return 126;case 66:return 82;case 67:return 82;case 68:return 82;case 69:return 82;case 70:return 81;case 71:return 81;case 72:return 81;case 73:return 59;case 74:return 60;case 75:return 61;case 76:return 62;case 77:return 63;case 78:return 64;case 79:return 65;case 80:return 69;case 81:return 70;case 82:return 55;case 83:return 56;case 84:return 109;case 85:return 112;case 86:return 127;case 87:return 124;case 88:return 113;case 89:return 125;case 90:return 125;case 91:return 114;case 92:return 73;case 93:return 92;case 94:return"SEP";case 95:return 91;case 96:return 66;case 97:return 75;case 98:return 74;case 99:return 77;case 100:return 76;case 101:return 122;case 102:return 123;case 103:return 68;case 104:return 57;case 105:return 58;case 106:return 40;case 107:return 41;case 108:return 71;case 109:return 72;case 110:return 133;case 111:return 21;case 112:return 22;case 113:return 23}},rules:[/^(?:%%\{)/,/^(?:((?:(?!\}%%)[^:.])*))/,/^(?::)/,/^(?:\}%%)/,/^(?:((?:(?!\}%%).|\n)*))/,/^(?:%%(?!\{)[^\n]*)/,/^(?:[^\}]%%[^\n]*)/,/^(?:accTitle\s*:\s*)/,/^(?:(?!\n||)*[^\n]*)/,/^(?:accDescr\s*:\s*)/,/^(?:(?!\n||)*[^\n]*)/,/^(?:accDescr\s*\{\s*)/,/^(?:[\}])/,/^(?:[^\}]*)/,/^(?:["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:style\b)/,/^(?:default\b)/,/^(?:linkStyle\b)/,/^(?:interpolate\b)/,/^(?:classDef\b)/,/^(?:class\b)/,/^(?:href[\s]+["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:call[\s]+)/,/^(?:\([\s]*\))/,/^(?:\()/,/^(?:[^(]*)/,/^(?:\))/,/^(?:[^)]*)/,/^(?:click[\s]+)/,/^(?:[\s\n])/,/^(?:[^\s\n]*)/,/^(?:graph\b)/,/^(?:flowchart\b)/,/^(?:subgraph\b)/,/^(?:end\b\s*)/,/^(?:_self\b)/,/^(?:_blank\b)/,/^(?:_parent\b)/,/^(?:_top\b)/,/^(?:(\r?\n)*\s*\n)/,/^(?:\s*LR\b)/,/^(?:\s*RL\b)/,/^(?:\s*TB\b)/,/^(?:\s*BT\b)/,/^(?:\s*TD\b)/,/^(?:\s*BR\b)/,/^(?:\s*<)/,/^(?:\s*>)/,/^(?:\s*\^)/,/^(?:\s*v\b)/,/^(?:.*direction\s+TB[^\n]*)/,/^(?:.*direction\s+BT[^\n]*)/,/^(?:.*direction\s+RL[^\n]*)/,/^(?:.*direction\s+LR[^\n]*)/,/^(?:[0-9]+)/,/^(?:#)/,/^(?::::)/,/^(?::)/,/^(?:&)/,/^(?:;)/,/^(?:,)/,/^(?:\*)/,/^(?:\s*[xo<]?--+[-xo>]\s*)/,/^(?:\s*[xo<]?==+[=xo>]\s*)/,/^(?:\s*[xo<]?-?\.+-[xo>]?\s*)/,/^(?:\s*~~[\~]+\s*)/,/^(?:\s*[xo<]?--\s*)/,/^(?:\s*[xo<]?==\s*)/,/^(?:\s*[xo<]?-\.\s*)/,/^(?:\(-)/,/^(?:-\))/,/^(?:\(\[)/,/^(?:\]\))/,/^(?:\[\[)/,/^(?:\]\])/,/^(?:\[\|)/,/^(?:\[\()/,/^(?:\)\])/,/^(?:\(\(\()/,/^(?:\)\)\))/,/^(?:-)/,/^(?:\.)/,/^(?:[\_])/,/^(?:\+)/,/^(?:%)/,/^(?:=)/,/^(?:=)/,/^(?:<)/,/^(?:>)/,/^(?:\^)/,/^(?:\\\|)/,/^(?:v\b)/,/^(?:[A-Za-z]+)/,/^(?:\\\])/,/^(?:\[\/)/,/^(?:\/\])/,/^(?:\[\\)/,/^(?:[!"#$%&'*+,-.`?\\_/])/,/^(?:[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|[\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA]|[\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE]|[\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA]|[\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0]|[\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977]|[\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2]|[\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A]|[\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39]|[\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8]|[\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C]|[\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C]|[\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99]|[\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0]|[\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D]|[\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3]|[\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10]|[\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1]|[\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81]|[\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3]|[\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6]|[\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A]|[\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081]|[\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D]|[\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0]|[\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310]|[\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C]|[\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711]|[\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7]|[\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C]|[\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16]|[\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF]|[\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC]|[\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D]|[\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D]|[\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3]|[\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F]|[\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128]|[\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184]|[\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3]|[\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6]|[\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE]|[\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C]|[\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D]|[\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC]|[\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B]|[\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788]|[\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805]|[\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB]|[\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28]|[\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5]|[\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4]|[\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E]|[\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D]|[\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36]|[\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D]|[\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC]|[\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF]|[\uFFD2-\uFFD7\uFFDA-\uFFDC])/,/^(?:\|)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:")/,/^(?:(\r?\n)+)/,/^(?:\s)/,/^(?:$)/],conditions:{close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},callbackargs:{rules:[30,31],inclusive:!1},callbackname:{rules:[27,28,29],inclusive:!1},href:{rules:[24,25],inclusive:!1},click:{rules:[33,34],inclusive:!1},vertex:{rules:[],inclusive:!1},dir:{rules:[43,44,45,46,47,48,49,50,51,52,53],inclusive:!1},acc_descr_multiline:{rules:[12,13],inclusive:!1},acc_descr:{rules:[10],inclusive:!1},acc_title:{rules:[8],inclusive:!1},string:{rules:[15,16],inclusive:!1},INITIAL:{rules:[0,5,6,7,9,11,14,17,18,19,20,21,22,23,26,32,35,36,37,38,39,40,41,42,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113],inclusive:!0}}};return Ln}();Wi.lexer=E0;function _u(){this.yy={}}return _u.prototype=Wi,Wi.Parser=_u,new _u}();X1.parser=X1;const rrt=(t,e)=>{var r;return((r=e==null?void 0:e.flowchart)==null?void 0:r.defaultRenderer)==="dagre-wrapper"?!1:t.match(/^\s*graph/)!==null},nrt=(t,e)=>{var r;return((r=e==null?void 0:e.flowchart)==null?void 0:r.defaultRenderer)==="dagre-wrapper"&&t.match(/^\s*graph/)!==null?!0:t.match(/^\s*flowchart/)!==null},irt="flowchart-";let sM=0,o4=nt(),ar={},js=[],il=[],qi=[],K1={},l4={},Z1=0,c4=!0,Vi,Q1,J1=[];const t0=t=>pe.sanitizeText(t,o4),art=function(t,e,r){Xe.parseDirective(this,t,e,r)},e0=function(t){const e=Object.keys(ar);for(let r=0;r<e.length;r++)if(ar[e[r]].id===t)return ar[e[r]].domId;return t},srt=function(t,e,r,n,i,a,s={}){let o,l=t;typeof l>"u"||l.trim().length!==0&&(typeof ar[l]>"u"&&(ar[l]={id:l,domId:irt+l+"-"+sM,styles:[],classes:[]}),sM++,typeof e<"u"?(o4=nt(),o=t0(e.trim()),o[0]==='"'&&o[o.length-1]==='"'&&(o=o.substring(1,o.length-1)),ar[l].text=o):typeof ar[l].text>"u"&&(ar[l].text=t),typeof r<"u"&&(ar[l].type=r),typeof n<"u"&&n!==null&&n.forEach(function(u){ar[l].styles.push(u)}),typeof i<"u"&&i!==null&&i.forEach(function(u){ar[l].classes.push(u)}),typeof a<"u"&&(ar[l].dir=a),ar[l].props=s)},ort=function(t,e,r,n){const s={start:t,end:e,type:void 0,text:""};n=r.text,typeof n<"u"&&(s.text=t0(n.trim()),s.text[0]==='"'&&s.text[s.text.length-1]==='"'&&(s.text=s.text.substring(1,s.text.length-1))),typeof r<"u"&&(s.type=r.type,s.stroke=r.stroke,s.length=r.length),js.push(s)},lrt=function(t,e,r,n){let i,a;for(i=0;i<t.length;i++)for(a=0;a<e.length;a++)ort(t[i],e[a],r,n)},crt=function(t,e){t.forEach(function(r){r==="default"?js.defaultInterpolate=e:js[r].interpolate=e})},urt=function(t,e){t.forEach(function(r){r==="default"?js.defaultStyle=e:(Se.isSubstringInArray("fill",e)===-1&&e.push("fill:none"),js[r].style=e)})},hrt=function(t,e){typeof il[t]>"u"&&(il[t]={id:t,styles:[],textStyles:[]}),typeof e<"u"&&e!==null&&e.forEach(function(r){if(r.match("color")){const i=r.replace("fill","bgFill").replace("color","fill");il[t].textStyles.push(i)}il[t].styles.push(r)})},frt=function(t){Vi=t,Vi.match(/.*</)&&(Vi="RL"),Vi.match(/.*\^/)&&(Vi="BT"),Vi.match(/.*>/)&&(Vi="LR"),Vi.match(/.*v/)&&(Vi="TB")},u4=function(t,e){t.split(",").forEach(function(r){let n=r;typeof ar[n]<"u"&&ar[n].classes.push(e),typeof K1[n]<"u"&&K1[n].classes.push(e)})},drt=function(t,e){t.split(",").forEach(function(r){typeof e<"u"&&(l4[Q1==="gen-1"?e0(r):r]=t0(e))})},prt=function(t,e,r){let n=e0(t);if(nt().securityLevel!=="loose"||typeof e>"u")return;let i=[];if(typeof r=="string"){i=r.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/);for(let a=0;a<i.length;a++){let s=i[a].trim();s.charAt(0)==='"'&&s.charAt(s.length-1)==='"'&&(s=s.substr(1,s.length-2)),i[a]=s}}i.length===0&&i.push(t),typeof ar[t]<"u"&&(ar[t].haveCallback=!0,J1.push(function(){const a=document.querySelector(`[id="${n}"]`);a!==null&&a.addEventListener("click",function(){Se.runFunc(e,...i)},!1)}))},grt=function(t,e,r){t.split(",").forEach(function(n){typeof ar[n]<"u"&&(ar[n].link=Se.formatUrl(e,o4),ar[n].linkTarget=r)}),u4(t,"clickable")},yrt=function(t){return l4[t]},mrt=function(t,e,r){t.split(",").forEach(function(n){prt(n,e,r)}),u4(t,"clickable")},brt=function(t){J1.forEach(function(e){e(t)})},_rt=function(){return Vi.trim()},vrt=function(){return ar},xrt=function(){return js},krt=function(){return il},oM=function(t){let e=St(".mermaidTooltip");(e._groups||e)[0][0]===null&&(e=St("body").append("div").attr("class","mermaidTooltip").style("opacity",0)),St(t).select("svg").selectAll("g.node").on("mouseover",function(){const i=St(this);if(i.attr("title")===null)return;const s=this.getBoundingClientRect();e.transition().duration(200).style("opacity",".9"),e.text(i.attr("title")).style("left",window.scrollX+s.left+(s.right-s.left)/2+"px").style("top",window.scrollY+s.top-14+document.body.scrollTop+"px"),e.html(e.html().replace(/<br\/>/g,"<br/>")),i.classed("hover",!0)}).on("mouseout",function(){e.transition().duration(500).style("opacity",0),St(this).classed("hover",!1)})};J1.push(oM);const wrt=function(t="gen-1"){ar={},il={},js=[],J1=[oM],qi=[],K1={},Z1=0,l4=[],c4=!0,Q1=t,ci()},Trt=t=>{Q1=t||"gen-1"},Ert=function(){return"fill:#ffa;stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;fill:#ffa;stroke: #666;"},Crt=function(t,e,r){let n=t.trim(),i=r.trim();n===i&&i.match(/\s/)&&(n=void 0);function a(h){const d={boolean:{},number:{},string:{}},f=[];let p;return{nodeList:h.filter(function(_){const y=typeof _;return _.stmt&&_.stmt==="dir"?(p=_.value,!1):_.trim()===""?!1:y in d?d[y].hasOwnProperty(_)?!1:d[y][_]=!0:f.indexOf(_)>=0?!1:f.push(_)}),dir:p}}let s=[];const{nodeList:o,dir:l}=a(s.concat.apply(s,e));if(s=o,Q1==="gen-1")for(let h=0;h<s.length;h++)s[h]=e0(s[h]);n=n||"subGraph"+Z1,i=i||"",i=t0(i),Z1=Z1+1;const u={id:n,nodes:s,title:i.trim(),classes:[],dir:l};return H.info("Adding",u.id,u.nodes,u.dir),u.nodes=hM(u,qi).nodes,qi.push(u),K1[n]=u,n},Srt=function(t){for(let e=0;e<qi.length;e++)if(qi[e].id===t)return e;return-1};let ru=-1;const lM=[],cM=function(t,e){const r=qi[e].nodes;if(ru=ru+1,ru>2e3)return;if(lM[ru]=e,qi[e].id===t)return{result:!0,count:0};let n=0,i=1;for(;n<r.length;){const a=Srt(r[n]);if(a>=0){const s=cM(t,a);if(s.result)return{result:!0,count:i+s.count};i=i+s.count}n=n+1}return{result:!1,count:i}},Art=function(t){return lM[t]},Mrt=function(){ru=-1,qi.length>0&&cM("none",qi.length-1)},Lrt=function(){return qi},Rrt=()=>c4?(c4=!1,!0):!1,Irt=t=>{let e=t.trim(),r="arrow_open";switch(e[0]){case"<":r="arrow_point",e=e.slice(1);break;case"x":r="arrow_cross",e=e.slice(1);break;case"o":r="arrow_circle",e=e.slice(1);break}let n="normal";return e.indexOf("=")!==-1&&(n="thick"),e.indexOf(".")!==-1&&(n="dotted"),{type:r,stroke:n}},Nrt=(t,e)=>{const r=e.length;let n=0;for(let i=0;i<r;++i)e[i]===t&&++n;return n},Brt=t=>{const e=t.trim();let r=e.slice(0,-1),n="arrow_open";switch(e.slice(-1)){case"x":n="arrow_cross",e[0]==="x"&&(n="double_"+n,r=r.slice(1));break;case">":n="arrow_point",e[0]==="<"&&(n="double_"+n,r=r.slice(1));break;case"o":n="arrow_circle",e[0]==="o"&&(n="double_"+n,r=r.slice(1));break}let i="normal",a=r.length-1;r[0]==="="&&(i="thick"),r[0]==="~"&&(i="invisible");let s=Nrt(".",r);return s&&(i="dotted",a=s),{type:n,stroke:i,length:a}},Drt=(t,e)=>{const r=Brt(t);let n;if(e){if(n=Irt(e),n.stroke!==r.stroke)return{type:"INVALID",stroke:"INVALID"};if(n.type==="arrow_open")n.type=r.type;else{if(n.type!==r.type)return{type:"INVALID",stroke:"INVALID"};n.type="double_"+n.type}return n.type==="double_arrow"&&(n.type="double_arrow_point"),n.length=r.length,n}return r},uM=(t,e)=>{let r=!1;return t.forEach(n=>{n.nodes.indexOf(e)>=0&&(r=!0)}),r},hM=(t,e)=>{const r=[];return t.nodes.forEach((n,i)=>{uM(e,n)||r.push(t.nodes[i])}),{nodes:r}},fa={parseDirective:art,defaultConfig:()=>Xo.flowchart,setAccTitle:Yn,getAccTitle:ui,getAccDescription:fi,setAccDescription:hi,addVertex:srt,lookUpDomId:e0,addLink:lrt,updateLinkInterpolate:crt,updateLink:urt,addClass:hrt,setDirection:frt,setClass:u4,setTooltip:drt,getTooltip:yrt,setClickEvent:mrt,setLink:grt,bindFunctions:brt,getDirection:_rt,getVertices:vrt,getEdges:xrt,getClasses:krt,clear:wrt,setGen:Trt,defaultStyle:Ert,addSubGraph:Crt,getDepthFirstPos:Art,indexNodes:Mrt,getSubGraphs:Lrt,destructLink:Drt,lex:{firstGraph:Rrt},exists:uM,makeUniq:hM};var r0;if(typeof fn=="function")try{r0=cr}catch{}r0||(r0=window.graphlib);var Ort=r0,n0;if(typeof fn=="function")try{n0=OA()}catch{}n0||(n0=window.dagre);var fM=n0,dM=Frt;function Frt(t,e){return t.intersect(e)}var h4=Prt;function Prt(t,e,r,n){var i=t.x,a=t.y,s=i-n.x,o=a-n.y,l=Math.sqrt(e*e*o*o+r*r*s*s),u=Math.abs(e*r*s/l);n.x<i&&(u=-u);var h=Math.abs(e*r*o/l);return n.y<a&&(h=-h),{x:i+u,y:a+h}}var qrt=h4,pM=Vrt;function Vrt(t,e,r){return qrt(t,e,e,r)}var zrt=Yrt;function Yrt(t,e,r,n){var i,a,s,o,l,u,h,d,f,p,m,_,y,b,x;if(i=e.y-t.y,s=t.x-e.x,l=e.x*t.y-t.x*e.y,f=i*r.x+s*r.y+l,p=i*n.x+s*n.y+l,!(f!==0&&p!==0&&gM(f,p))&&(a=n.y-r.y,o=r.x-n.x,u=n.x*r.y-r.x*n.y,h=a*t.x+o*t.y+u,d=a*e.x+o*e.y+u,!(h!==0&&d!==0&&gM(h,d))&&(m=i*o-a*s,m!==0)))return _=Math.abs(m/2),y=s*u-o*l,b=y<0?(y-_)/m:(y+_)/m,y=a*l-i*u,x=y<0?(y-_)/m:(y+_)/m,{x:b,y:x}}function gM(t,e){return t*e>0}var Urt=zrt,yM=Wrt;function Wrt(t,e,r){var n=t.x,i=t.y,a=[],s=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY;e.forEach(function(m){s=Math.min(s,m.x),o=Math.min(o,m.y)});for(var l=n-t.width/2-s,u=i-t.height/2-o,h=0;h<e.length;h++){var d=e[h],f=e[h<e.length-1?h+1:0],p=Urt(t,r,{x:l+d.x,y:u+d.y},{x:l+f.x,y:u+f.y});p&&a.push(p)}return a.length?(a.length>1&&a.sort(function(m,_){var y=m.x-r.x,b=m.y-r.y,x=Math.sqrt(y*y+b*b),k=_.x-r.x,T=_.y-r.y,C=Math.sqrt(k*k+T*T);return x<C?-1:x===C?0:1}),a[0]):(console.log("NO INTERSECTION FOUND, RETURN NODE CENTER",t),t)}var mM=Hrt;function Hrt(t,e){var r=t.x,n=t.y,i=e.x-r,a=e.y-n,s=t.width/2,o=t.height/2,l,u;return Math.abs(a)*s>Math.abs(i)*o?(a<0&&(o=-o),l=a===0?0:o*i/a,u=o):(i<0&&(s=-s),l=s,u=i===0?0:s*a/i),{x:r+l,y:n+u}}var Grt={node:dM,circle:pM,ellipse:h4,polygon:yM,rect:mM},i0;if(typeof fn=="function")try{i0={defaults:oS(),each:am(),isFunction:Yo,isPlainObject:AS(),pick:GS(),has:$m(),range:KS(),uniqueId:nA()}}catch{}i0||(i0=window._);var al=i0;const jrt=wn(CH);var nu;if(!nu&&typeof fn=="function")try{nu=jrt}catch{}nu||(nu=window.d3);var es=nu,bM=al,Gn={isSubgraph:$rt,edgeToId:Xrt,applyStyle:Zrt,applyClass:Qrt,applyTransition:Jrt};function $rt(t,e){return!!t.children(e).length}function Xrt(t){return f4(t.v)+":"+f4(t.w)+":"+f4(t.name)}var Krt=/:/g;function f4(t){return t?String(t).replace(Krt,"\\:"):""}function Zrt(t,e){e&&t.attr("style",e)}function Qrt(t,e,r){e&&t.attr("class",e).attr("class",r+" "+t.attr("class"))}function Jrt(t,e){var r=e.graph();if(bM.isPlainObject(r)){var n=r.transition;if(bM.isFunction(n))return n(t)}return t}var d4,_M;function tnt(){if(_M)return d4;_M=1;var t=Gn;d4=e;function e(n,i){for(var a=n.append("text"),s=r(i.label).split(` +`),o=0;o<s.length;o++)a.append("tspan").attr("xml:space","preserve").attr("dy","1em").attr("x","1").text(s[o]);return t.applyStyle(a,i.labelStyle),a}function r(n){for(var i="",a=!1,s,o=0;o<n.length;++o)if(s=n[o],a){switch(s){case"n":i+=` +`;break;default:i+=s}a=!1}else s==="\\"?a=!0:i+=s;return i}return d4}var ent=Gn,p4=rnt;function rnt(t,e){var r=t.append("foreignObject").attr("width","100000"),n=r.append("xhtml:div");n.attr("xmlns","http://www.w3.org/1999/xhtml");var i=e.label;switch(typeof i){case"function":n.insert(i);break;case"object":n.insert(function(){return i});break;default:n.html(i)}ent.applyStyle(n,e.labelStyle),n.style("display","inline-block"),n.style("white-space","nowrap");var a=n.node().getBoundingClientRect();return r.attr("width",a.width).attr("height",a.height),r}var g4,vM;function nnt(){if(vM)return g4;vM=1;var t=Gn;g4=e;function e(r,n){var i=r;return i.node().appendChild(n.label),t.applyStyle(i,n.labelStyle),i}return g4}var y4,xM;function m4(){if(xM)return y4;xM=1;var t=tnt(),e=p4,r=nnt();y4=n;function n(i,a,s){var o=a.label,l=i.append("g");a.labelType==="svg"?r(l,a):typeof o!="string"||a.labelType==="html"?e(l,a):t(l,a);var u=l.node().getBBox(),h;switch(s){case"top":h=-a.height/2;break;case"bottom":h=a.height/2-u.height;break;default:h=-u.height/2}return l.attr("transform","translate("+-u.width/2+","+h+")"),l}return y4}var b4,kM;function int(){if(kM)return b4;kM=1;var t=al,e=m4(),r=Gn,n=es;b4=i;function i(a,s,o){var l=s.nodes().filter(function(d){return!r.isSubgraph(s,d)}),u=a.selectAll("g.node").data(l,function(d){return d}).classed("update",!0);u.exit().remove(),u.enter().append("g").attr("class","node").style("opacity",0),u=a.selectAll("g.node"),u.each(function(d){var f=s.node(d),p=n.select(this);r.applyClass(p,f.class,(p.classed("update")?"update ":"")+"node"),p.select("g.label").remove();var m=p.append("g").attr("class","label"),_=e(m,f),y=o[f.shape],b=t.pick(_.node().getBBox(),"width","height");f.elem=this,f.id&&p.attr("id",f.id),f.labelId&&m.attr("id",f.labelId),t.has(f,"width")&&(b.width=f.width),t.has(f,"height")&&(b.height=f.height),b.width+=f.paddingLeft+f.paddingRight,b.height+=f.paddingTop+f.paddingBottom,m.attr("transform","translate("+(f.paddingLeft-f.paddingRight)/2+","+(f.paddingTop-f.paddingBottom)/2+")");var x=n.select(this);x.select(".label-container").remove();var k=y(x,b,f).classed("label-container",!0);r.applyStyle(k,f.style);var T=k.node().getBBox();f.width=T.width,f.height=T.height});var h;return u.exit?h=u.exit():h=u.selectAll(null),r.applyTransition(h,s).style("opacity",0).remove(),u}return b4}var _4,wM;function ant(){if(wM)return _4;wM=1;var t=Gn,e=es,r=m4();_4=n;function n(i,a){var s=a.nodes().filter(function(u){return t.isSubgraph(a,u)}),o=i.selectAll("g.cluster").data(s,function(u){return u});o.selectAll("*").remove(),o.enter().append("g").attr("class","cluster").attr("id",function(u){var h=a.node(u);return h.id}).style("opacity",0),o=i.selectAll("g.cluster"),t.applyTransition(o,a).style("opacity",1),o.each(function(u){var h=a.node(u),d=e.select(this);e.select(this).append("rect");var f=d.append("g").attr("class","label");r(f,h,h.clusterLabelPos)}),o.selectAll("rect").each(function(u){var h=a.node(u),d=e.select(this);t.applyStyle(d,h.style)});var l;return o.exit?l=o.exit():l=o.selectAll(null),t.applyTransition(l,a).style("opacity",0).remove(),o}return _4}var v4,TM;function snt(){if(TM)return v4;TM=1;var t=al,e=m4(),r=Gn,n=es;v4=i;function i(a,s){var o=a.selectAll("g.edgeLabel").data(s.edges(),function(u){return r.edgeToId(u)}).classed("update",!0);o.exit().remove(),o.enter().append("g").classed("edgeLabel",!0).style("opacity",0),o=a.selectAll("g.edgeLabel"),o.each(function(u){var h=n.select(this);h.select(".label").remove();var d=s.edge(u),f=e(h,s.edge(u),0,0).classed("label",!0),p=f.node().getBBox();d.labelId&&f.attr("id",d.labelId),t.has(d,"width")||(d.width=p.width),t.has(d,"height")||(d.height=p.height)});var l;return o.exit?l=o.exit():l=o.selectAll(null),r.applyTransition(l,s).style("opacity",0).remove(),o}return v4}var x4,EM;function ont(){if(EM)return x4;EM=1;var t=al,e=dM,r=Gn,n=es;x4=i;function i(d,f,p){var m=d.selectAll("g.edgePath").data(f.edges(),function(b){return r.edgeToId(b)}).classed("update",!0),_=u(m,f);h(m,f);var y=m.merge!==void 0?m.merge(_):m;return r.applyTransition(y,f).style("opacity",1),y.each(function(b){var x=n.select(this),k=f.edge(b);k.elem=this,k.id&&x.attr("id",k.id),r.applyClass(x,k.class,(x.classed("update")?"update ":"")+"edgePath")}),y.selectAll("path.path").each(function(b){var x=f.edge(b);x.arrowheadId=t.uniqueId("arrowhead");var k=n.select(this).attr("marker-end",function(){return"url("+a(location.href,x.arrowheadId)+")"}).style("fill","none");r.applyTransition(k,f).attr("d",function(T){return s(f,T)}),r.applyStyle(k,x.style)}),y.selectAll("defs *").remove(),y.selectAll("defs").each(function(b){var x=f.edge(b),k=p[x.arrowhead];k(n.select(this),x.arrowheadId,x,"arrowhead")}),y}function a(d,f){var p=d.split("#")[0];return p+"#"+f}function s(d,f){var p=d.edge(f),m=d.node(f.v),_=d.node(f.w),y=p.points.slice(1,p.points.length-1);return y.unshift(e(m,y[0])),y.push(e(_,y[y.length-1])),o(p,y)}function o(d,f){var p=(n.line||n.svg.line)().x(function(m){return m.x}).y(function(m){return m.y});return(p.curve||p.interpolate)(d.curve),p(f)}function l(d){var f=d.getBBox(),p=d.ownerSVGElement.getScreenCTM().inverse().multiply(d.getScreenCTM()).translate(f.width/2,f.height/2);return{x:p.e,y:p.f}}function u(d,f){var p=d.enter().append("g").attr("class","edgePath").style("opacity",0);return p.append("path").attr("class","path").attr("d",function(m){var _=f.edge(m),y=f.node(m.v).elem,b=t.range(_.points.length).map(function(){return l(y)});return o(_,b)}),p.append("defs"),p}function h(d,f){var p=d.exit();r.applyTransition(p,f).style("opacity",0).remove()}return x4}var k4,CM;function lnt(){if(CM)return k4;CM=1;var t=Gn,e=es;k4=r;function r(n,i){var a=n.filter(function(){return!e.select(this).classed("update")});function s(o){var l=i.node(o);return"translate("+l.x+","+l.y+")"}a.attr("transform",s),t.applyTransition(n,i).style("opacity",1).attr("transform",s)}return k4}var w4,SM;function cnt(){if(SM)return w4;SM=1;var t=Gn,e=es,r=al;w4=n;function n(i,a){var s=i.filter(function(){return!e.select(this).classed("update")});function o(l){var u=a.edge(l);return r.has(u,"x")?"translate("+u.x+","+u.y+")":""}s.attr("transform",o),t.applyTransition(i,a).style("opacity",1).attr("transform",o)}return w4}var T4,AM;function unt(){if(AM)return T4;AM=1;var t=Gn,e=es;T4=r;function r(n,i){var a=n.filter(function(){return!e.select(this).classed("update")});function s(o){var l=i.node(o);return"translate("+l.x+","+l.y+")"}a.attr("transform",s),t.applyTransition(n,i).style("opacity",1).attr("transform",s),t.applyTransition(a.selectAll("rect"),i).attr("width",function(o){return i.node(o).width}).attr("height",function(o){return i.node(o).height}).attr("x",function(o){var l=i.node(o);return-l.width/2}).attr("y",function(o){var l=i.node(o);return-l.height/2})}return T4}var E4,MM;function hnt(){if(MM)return E4;MM=1;var t=mM,e=h4,r=pM,n=yM;E4={rect:i,ellipse:a,circle:s,diamond:o};function i(l,u,h){var d=l.insert("rect",":first-child").attr("rx",h.rx).attr("ry",h.ry).attr("x",-u.width/2).attr("y",-u.height/2).attr("width",u.width).attr("height",u.height);return h.intersect=function(f){return t(h,f)},d}function a(l,u,h){var d=u.width/2,f=u.height/2,p=l.insert("ellipse",":first-child").attr("x",-u.width/2).attr("y",-u.height/2).attr("rx",d).attr("ry",f);return h.intersect=function(m){return e(h,d,f,m)},p}function s(l,u,h){var d=Math.max(u.width,u.height)/2,f=l.insert("circle",":first-child").attr("x",-u.width/2).attr("y",-u.height/2).attr("r",d);return h.intersect=function(p){return r(h,d,p)},f}function o(l,u,h){var d=u.width*Math.SQRT2/2,f=u.height*Math.SQRT2/2,p=[{x:0,y:-f},{x:-d,y:0},{x:0,y:f},{x:d,y:0}],m=l.insert("polygon",":first-child").attr("points",p.map(function(_){return _.x+","+_.y}).join(" "));return h.intersect=function(_){return n(h,p,_)},m}return E4}var C4,LM;function fnt(){if(LM)return C4;LM=1;var t=Gn;C4={default:e,normal:e,vee:r,undirected:n};function e(i,a,s,o){var l=i.append("marker").attr("id",a).attr("viewBox","0 0 10 10").attr("refX",9).attr("refY",5).attr("markerUnits","strokeWidth").attr("markerWidth",8).attr("markerHeight",6).attr("orient","auto"),u=l.append("path").attr("d","M 0 0 L 10 5 L 0 10 z").style("stroke-width",1).style("stroke-dasharray","1,0");t.applyStyle(u,s[o+"Style"]),s[o+"Class"]&&u.attr("class",s[o+"Class"])}function r(i,a,s,o){var l=i.append("marker").attr("id",a).attr("viewBox","0 0 10 10").attr("refX",9).attr("refY",5).attr("markerUnits","strokeWidth").attr("markerWidth",8).attr("markerHeight",6).attr("orient","auto"),u=l.append("path").attr("d","M 0 0 L 10 5 L 0 10 L 4 5 z").style("stroke-width",1).style("stroke-dasharray","1,0");t.applyStyle(u,s[o+"Style"]),s[o+"Class"]&&u.attr("class",s[o+"Class"])}function n(i,a,s,o){var l=i.append("marker").attr("id",a).attr("viewBox","0 0 10 10").attr("refX",9).attr("refY",5).attr("markerUnits","strokeWidth").attr("markerWidth",8).attr("markerHeight",6).attr("orient","auto"),u=l.append("path").attr("d","M 0 5 L 10 5").style("stroke-width",1).style("stroke-dasharray","1,0");t.applyStyle(u,s[o+"Style"]),s[o+"Class"]&&u.attr("class",s[o+"Class"])}return C4}var Ur=al,dnt=es,pnt=fM.layout,gnt=ynt;function ynt(){var t=int(),e=ant(),r=snt(),n=ont(),i=lnt(),a=cnt(),s=unt(),o=hnt(),l=fnt(),u=function(h,d){_nt(d);var f=iu(h,"output"),p=iu(f,"clusters"),m=iu(f,"edgePaths"),_=r(iu(f,"edgeLabels"),d),y=t(iu(f,"nodes"),d,o);pnt(d),i(y,d),a(_,d),n(m,d,l);var b=e(p,d);s(b,d),vnt(d)};return u.createNodes=function(h){return arguments.length?(t=h,u):t},u.createClusters=function(h){return arguments.length?(e=h,u):e},u.createEdgeLabels=function(h){return arguments.length?(r=h,u):r},u.createEdgePaths=function(h){return arguments.length?(n=h,u):n},u.shapes=function(h){return arguments.length?(o=h,u):o},u.arrows=function(h){return arguments.length?(l=h,u):l},u}var mnt={paddingLeft:10,paddingRight:10,paddingTop:10,paddingBottom:10,rx:0,ry:0,shape:"rect"},bnt={arrowhead:"normal",curve:dnt.curveLinear};function _nt(t){t.nodes().forEach(function(e){var r=t.node(e);!Ur.has(r,"label")&&!t.children(e).length&&(r.label=e),Ur.has(r,"paddingX")&&Ur.defaults(r,{paddingLeft:r.paddingX,paddingRight:r.paddingX}),Ur.has(r,"paddingY")&&Ur.defaults(r,{paddingTop:r.paddingY,paddingBottom:r.paddingY}),Ur.has(r,"padding")&&Ur.defaults(r,{paddingLeft:r.padding,paddingRight:r.padding,paddingTop:r.padding,paddingBottom:r.padding}),Ur.defaults(r,mnt),Ur.each(["paddingLeft","paddingRight","paddingTop","paddingBottom"],function(n){r[n]=Number(r[n])}),Ur.has(r,"width")&&(r._prevWidth=r.width),Ur.has(r,"height")&&(r._prevHeight=r.height)}),t.edges().forEach(function(e){var r=t.edge(e);Ur.has(r,"label")||(r.label=""),Ur.defaults(r,bnt)})}function vnt(t){Ur.each(t.nodes(),function(e){var r=t.node(e);Ur.has(r,"_prevWidth")?r.width=r._prevWidth:delete r.width,Ur.has(r,"_prevHeight")?r.height=r._prevHeight:delete r.height,delete r._prevWidth,delete r._prevHeight})}function iu(t,e){var r=t.select("g."+e);return r.empty()&&(r=t.append("g").attr("class",e)),r}var xnt="0.6.4";/** + * @license + * Copyright (c) 2012-2013 Chris Pettitt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */var An={graphlib:Ort,dagre:fM,intersect:Grt,render:gnt,util:Gn,version:xnt};function RM(t,e,r){const n=e.width,i=e.height,a=(n+i)*.9,s=[{x:a/2,y:0},{x:a,y:-a/2},{x:a/2,y:-a},{x:0,y:-a/2}],o=da(t,a,a,s);return r.intersect=function(l){return An.intersect.polygon(r,s,l)},o}function IM(t,e,r){const i=e.height,a=i/4,s=e.width+2*a,o=[{x:a,y:0},{x:s-a,y:0},{x:s,y:-i/2},{x:s-a,y:-i},{x:a,y:-i},{x:0,y:-i/2}],l=da(t,s,i,o);return r.intersect=function(u){return An.intersect.polygon(r,o,u)},l}function NM(t,e,r){const n=e.width,i=e.height,a=[{x:-i/2,y:0},{x:n,y:0},{x:n,y:-i},{x:-i/2,y:-i},{x:0,y:-i/2}],s=da(t,n,i,a);return r.intersect=function(o){return An.intersect.polygon(r,a,o)},s}function BM(t,e,r){const n=e.width,i=e.height,a=[{x:-2*i/6,y:0},{x:n-i/6,y:0},{x:n+2*i/6,y:-i},{x:i/6,y:-i}],s=da(t,n,i,a);return r.intersect=function(o){return An.intersect.polygon(r,a,o)},s}function DM(t,e,r){const n=e.width,i=e.height,a=[{x:2*i/6,y:0},{x:n+i/6,y:0},{x:n-2*i/6,y:-i},{x:-i/6,y:-i}],s=da(t,n,i,a);return r.intersect=function(o){return An.intersect.polygon(r,a,o)},s}function OM(t,e,r){const n=e.width,i=e.height,a=[{x:-2*i/6,y:0},{x:n+2*i/6,y:0},{x:n-i/6,y:-i},{x:i/6,y:-i}],s=da(t,n,i,a);return r.intersect=function(o){return An.intersect.polygon(r,a,o)},s}function FM(t,e,r){const n=e.width,i=e.height,a=[{x:i/6,y:0},{x:n-i/6,y:0},{x:n+2*i/6,y:-i},{x:-2*i/6,y:-i}],s=da(t,n,i,a);return r.intersect=function(o){return An.intersect.polygon(r,a,o)},s}function PM(t,e,r){const n=e.width,i=e.height,a=[{x:0,y:0},{x:n+i/2,y:0},{x:n,y:-i/2},{x:n+i/2,y:-i},{x:0,y:-i}],s=da(t,n,i,a);return r.intersect=function(o){return An.intersect.polygon(r,a,o)},s}function qM(t,e,r){const n=e.height,i=e.width+n/4,a=t.insert("rect",":first-child").attr("rx",n/2).attr("ry",n/2).attr("x",-i/2).attr("y",-n/2).attr("width",i).attr("height",n);return r.intersect=function(s){return An.intersect.rect(r,s)},a}function VM(t,e,r){const n=e.width,i=e.height,a=[{x:0,y:0},{x:n,y:0},{x:n,y:-i},{x:0,y:-i},{x:0,y:0},{x:-8,y:0},{x:n+8,y:0},{x:n+8,y:-i},{x:-8,y:-i},{x:-8,y:0}],s=da(t,n,i,a);return r.intersect=function(o){return An.intersect.polygon(r,a,o)},s}function zM(t,e,r){const n=e.width,i=n/2,a=i/(2.5+n/50),s=e.height+a,o="M 0,"+a+" a "+i+","+a+" 0,0,0 "+n+" 0 a "+i+","+a+" 0,0,0 "+-n+" 0 l 0,"+s+" a "+i+","+a+" 0,0,0 "+n+" 0 l 0,"+-s,l=t.attr("label-offset-y",a).insert("path",":first-child").attr("d",o).attr("transform","translate("+-n/2+","+-(s/2+a)+")");return r.intersect=function(u){const h=An.intersect.rect(r,u),d=h.x-r.x;if(i!=0&&(Math.abs(d)<r.width/2||Math.abs(d)==r.width/2&&Math.abs(h.y-r.y)>r.height/2-a)){let f=a*a*(1-d*d/(i*i));f!=0&&(f=Math.sqrt(f)),f=a-f,u.y-r.y>0&&(f=-f),h.y+=f}return h},l}function knt(t){t.shapes().question=RM,t.shapes().hexagon=IM,t.shapes().stadium=qM,t.shapes().subroutine=VM,t.shapes().cylinder=zM,t.shapes().rect_left_inv_arrow=NM,t.shapes().lean_right=BM,t.shapes().lean_left=DM,t.shapes().trapezoid=OM,t.shapes().inv_trapezoid=FM,t.shapes().rect_right_inv_arrow=PM}function wnt(t){t({question:RM}),t({hexagon:IM}),t({stadium:qM}),t({subroutine:VM}),t({cylinder:zM}),t({rect_left_inv_arrow:NM}),t({lean_right:BM}),t({lean_left:DM}),t({trapezoid:OM}),t({inv_trapezoid:FM}),t({rect_right_inv_arrow:PM})}function da(t,e,r,n){return t.insert("polygon",":first-child").attr("points",n.map(function(i){return i.x+","+i.y}).join(" ")).attr("transform","translate("+-e/2+","+r/2+")")}const Tnt={addToRender:knt,addToRenderV2:wnt},YM={},Ent=function(t){const e=Object.keys(t);for(let r=0;r<e.length;r++)YM[e[r]]=t[e[r]]},UM=function(t,e,r,n,i,a){const s=n?n.select(`[id="${r}"]`):St(`[id="${r}"]`),o=i||document;Object.keys(t).forEach(function(u){const h=t[u];let d="default";h.classes.length>0&&(d=h.classes.join(" "));const f=Ka(h.styles);let p=h.text!==void 0?h.text:h.id,m;if(Mr(nt().flowchart.htmlLabels)){const b={label:p.replace(/fa[lrsb]?:fa-[\w-]+/g,x=>`<i class='${x.replace(":"," ")}'></i>`)};m=p4(s,b).node(),m.parentNode.removeChild(m)}else{const b=o.createElementNS("http://www.w3.org/2000/svg","text");b.setAttribute("style",f.labelStyle.replace("color:","fill:"));const x=p.split(pe.lineBreakRegex);for(let k=0;k<x.length;k++){const T=o.createElementNS("http://www.w3.org/2000/svg","tspan");T.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:space","preserve"),T.setAttribute("dy","1em"),T.setAttribute("x","1"),T.textContent=x[k],b.appendChild(T)}m=b}let _=0,y="";switch(h.type){case"round":_=5,y="rect";break;case"square":y="rect";break;case"diamond":y="question";break;case"hexagon":y="hexagon";break;case"odd":y="rect_left_inv_arrow";break;case"lean_right":y="lean_right";break;case"lean_left":y="lean_left";break;case"trapezoid":y="trapezoid";break;case"inv_trapezoid":y="inv_trapezoid";break;case"odd_right":y="rect_left_inv_arrow";break;case"circle":y="circle";break;case"ellipse":y="ellipse";break;case"stadium":y="stadium";break;case"subroutine":y="subroutine";break;case"cylinder":y="cylinder";break;case"group":y="rect";break;default:y="rect"}H.warn("Adding node",h.id,h.domId),e.setNode(a.db.lookUpDomId(h.id),{labelType:"svg",labelStyle:f.labelStyle,shape:y,label:m,rx:_,ry:_,class:d,style:f.style,id:a.db.lookUpDomId(h.id)})})},WM=function(t,e,r){let n=0,i,a;if(typeof t.defaultStyle<"u"){const s=Ka(t.defaultStyle);i=s.style,a=s.labelStyle}t.forEach(function(s){n++;var o="L-"+s.start+"-"+s.end,l="LS-"+s.start,u="LE-"+s.end;const h={};s.type==="arrow_open"?h.arrowhead="none":h.arrowhead="normal";let d="",f="";if(typeof s.style<"u"){const p=Ka(s.style);d=p.style,f=p.labelStyle}else switch(s.stroke){case"normal":d="fill:none",typeof i<"u"&&(d=i),typeof a<"u"&&(f=a);break;case"dotted":d="fill:none;stroke-width:2px;stroke-dasharray:3;";break;case"thick":d=" stroke-width: 3.5px;fill:none";break}h.style=d,h.labelStyle=f,typeof s.interpolate<"u"?h.curve=Ni(s.interpolate,yn):typeof t.defaultInterpolate<"u"?h.curve=Ni(t.defaultInterpolate,yn):h.curve=Ni(YM.curve,yn),typeof s.text>"u"?typeof s.style<"u"&&(h.arrowheadStyle="fill: #333"):(h.arrowheadStyle="fill: #333",h.labelpos="c",Mr(nt().flowchart.htmlLabels)?(h.labelType="html",h.label=`<span id="L-${o}" class="edgeLabel L-${l}' L-${u}" style="${h.labelStyle}">${s.text.replace(/fa[lrsb]?:fa-[\w-]+/g,p=>`<i class='${p.replace(":"," ")}'></i>`)}</span>`):(h.labelType="text",h.label=s.text.replace(pe.lineBreakRegex,` +`),typeof s.style>"u"&&(h.style=h.style||"stroke: #333; stroke-width: 1.5px;fill:none"),h.labelStyle=h.labelStyle.replace("color:","fill:"))),h.id=o,h.class=l+" "+u,h.minlen=s.length||1,e.setEdge(r.db.lookUpDomId(s.start),r.db.lookUpDomId(s.end),h,n)})},S4={setConf:Ent,addVertices:UM,addEdges:WM,getClasses:function(t,e){H.info("Extracting classes"),e.db.clear();try{return e.parse(t),e.db.getClasses()}catch{return}},draw:function(t,e,r,n){H.info("Drawing flowchart"),n.db.clear();const{securityLevel:i,flowchart:a}=nt();let s;i==="sandbox"&&(s=St("#i"+e));const o=St(i==="sandbox"?s.nodes()[0].contentDocument.body:"body"),l=i==="sandbox"?s.nodes()[0].contentDocument:document;try{n.parser.parse(t)}catch{H.debug("Parsing failed")}let u=n.db.getDirection();typeof u>"u"&&(u="TD");const h=a.nodeSpacing||50,d=a.rankSpacing||50,f=new cr.Graph({multigraph:!0,compound:!0}).setGraph({rankdir:u,nodesep:h,ranksep:d,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});let p;const m=n.db.getSubGraphs();for(let S=m.length-1;S>=0;S--)p=m[S],n.db.addVertex(p.id,p.title,"group",void 0,p.classes);const _=n.db.getVertices();H.warn("Get vertices",_);const y=n.db.getEdges();let b=0;for(b=m.length-1;b>=0;b--){p=m[b],Nu("cluster").append("text");for(let S=0;S<p.nodes.length;S++)H.warn("Setting subgraph",p.nodes[S],n.db.lookUpDomId(p.nodes[S]),n.db.lookUpDomId(p.id)),f.setParent(n.db.lookUpDomId(p.nodes[S]),n.db.lookUpDomId(p.id))}UM(_,f,e,o,l,n),WM(y,f,n);const x=An.render,k=new x;Tnt.addToRender(k),k.arrows().none=function(R,A,L,v){const w=R.append("marker").attr("id",A).attr("viewBox","0 0 10 10").attr("refX",9).attr("refY",5).attr("markerUnits","strokeWidth").attr("markerWidth",8).attr("markerHeight",6).attr("orient","auto").append("path").attr("d","M 0 0 L 0 0 L 0 0 z");An.util.applyStyle(w,L[v+"Style"])},k.arrows().normal=function(R,A){R.append("marker").attr("id",A).attr("viewBox","0 0 10 10").attr("refX",9).attr("refY",5).attr("markerUnits","strokeWidth").attr("markerWidth",8).attr("markerHeight",6).attr("orient","auto").append("path").attr("d","M 0 0 L 10 5 L 0 10 z").attr("class","arrowheadPath").style("stroke-width",1).style("stroke-dasharray","1,0")};const T=o.select(`[id="${e}"]`);bn(n.db,T,e);const C=o.select("#"+e+" g");for(k(C,f),C.selectAll("g.node").attr("title",function(){return n.db.getTooltip(this.id)}),n.db.indexNodes("subGraph"+b),b=0;b<m.length;b++)if(p=m[b],p.title!=="undefined"){const S=l.querySelectorAll("#"+e+' [id="'+n.db.lookUpDomId(p.id)+'"] rect'),R=l.querySelectorAll("#"+e+' [id="'+n.db.lookUpDomId(p.id)+'"]'),A=S[0].x.baseVal.value,L=S[0].y.baseVal.value,v=S[0].width.baseVal.value,w=St(R[0]).select(".label");w.attr("transform",`translate(${A+v/2}, ${L+14})`),w.attr("id",e+"Text");for(let D=0;D<p.classes.length;D++)R[0].classList.add(p.classes[D])}if(!a.htmlLabels){const S=l.querySelectorAll('[id="'+e+'"] .edgeLabel .label');for(let R=0;R<S.length;R++){const A=S[R],L=A.getBBox(),v=l.createElementNS("http://www.w3.org/2000/svg","rect");v.setAttribute("rx",0),v.setAttribute("ry",0),v.setAttribute("width",L.width),v.setAttribute("height",L.height),A.insertBefore(v,A.firstChild)}}i1(f,T,a.diagramPadding,a.useMaxWidth),Object.keys(_).forEach(function(S){const R=_[S];if(R.link){const A=o.select("#"+e+' [id="'+n.db.lookUpDomId(S)+'"]');if(A){const L=l.createElementNS("http://www.w3.org/2000/svg","a");L.setAttributeNS("http://www.w3.org/2000/svg","class",R.classes.join(" ")),L.setAttributeNS("http://www.w3.org/2000/svg","href",R.link),L.setAttributeNS("http://www.w3.org/2000/svg","rel","noopener"),i==="sandbox"?L.setAttributeNS("http://www.w3.org/2000/svg","target","_top"):R.linkTarget&&L.setAttributeNS("http://www.w3.org/2000/svg","target",R.linkTarget);const v=A.insert(function(){return L},":first-child"),B=A.select(".label-container");B&&v.append(function(){return B.node()});const w=A.select(".label");w&&v.append(function(){return w.node()})}}})}},HM={},Cnt=function(t){const e=Object.keys(t);for(let r=0;r<e.length;r++)HM[e[r]]=t[e[r]]},GM=function(t,e,r,n,i,a){const s=n.select(`[id="${r}"]`);Object.keys(t).forEach(function(l){const u=t[l];let h="default";u.classes.length>0&&(h=u.classes.join(" "));const d=Ka(u.styles);let f=u.text!==void 0?u.text:u.id,p;if(Mr(nt().flowchart.htmlLabels)){const y={label:f.replace(/fa[lrsb]?:fa-[\w-]+/g,b=>`<i class='${b.replace(":"," ")}'></i>`)};p=p4(s,y).node(),p.parentNode.removeChild(p)}else{const y=i.createElementNS("http://www.w3.org/2000/svg","text");y.setAttribute("style",d.labelStyle.replace("color:","fill:"));const b=f.split(pe.lineBreakRegex);for(let x=0;x<b.length;x++){const k=i.createElementNS("http://www.w3.org/2000/svg","tspan");k.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:space","preserve"),k.setAttribute("dy","1em"),k.setAttribute("x","1"),k.textContent=b[x],y.appendChild(k)}p=y}let m=0,_="";switch(u.type){case"round":m=5,_="rect";break;case"square":_="rect";break;case"diamond":_="question";break;case"hexagon":_="hexagon";break;case"odd":_="rect_left_inv_arrow";break;case"lean_right":_="lean_right";break;case"lean_left":_="lean_left";break;case"trapezoid":_="trapezoid";break;case"inv_trapezoid":_="inv_trapezoid";break;case"odd_right":_="rect_left_inv_arrow";break;case"circle":_="circle";break;case"ellipse":_="ellipse";break;case"stadium":_="stadium";break;case"subroutine":_="subroutine";break;case"cylinder":_="cylinder";break;case"group":_="rect";break;case"doublecircle":_="doublecircle";break;default:_="rect"}e.setNode(u.id,{labelStyle:d.labelStyle,shape:_,labelText:f,rx:m,ry:m,class:h,style:d.style,id:u.id,link:u.link,linkTarget:u.linkTarget,tooltip:a.db.getTooltip(u.id)||"",domId:a.db.lookUpDomId(u.id),haveCallback:u.haveCallback,width:u.type==="group"?500:void 0,dir:u.dir,type:u.type,props:u.props,padding:nt().flowchart.padding}),H.info("setNode",{labelStyle:d.labelStyle,shape:_,labelText:f,rx:m,ry:m,class:h,style:d.style,id:u.id,domId:a.db.lookUpDomId(u.id),width:u.type==="group"?500:void 0,type:u.type,dir:u.dir,props:u.props,padding:nt().flowchart.padding})})},jM=function(t,e,r){H.info("abc78 edges = ",t);let n=0,i={},a,s;if(typeof t.defaultStyle<"u"){const o=Ka(t.defaultStyle);a=o.style,s=o.labelStyle}t.forEach(function(o){n++;var l="L-"+o.start+"-"+o.end;typeof i[l]>"u"?(i[l]=0,H.info("abc78 new entry",l,i[l])):(i[l]++,H.info("abc78 new entry",l,i[l]));let u=l+"-"+i[l];H.info("abc78 new link id to be used is",l,u,i[l]);var h="LS-"+o.start,d="LE-"+o.end;const f={style:"",labelStyle:""};switch(f.minlen=o.length||1,o.type==="arrow_open"?f.arrowhead="none":f.arrowhead="normal",f.arrowTypeStart="arrow_open",f.arrowTypeEnd="arrow_open",o.type){case"double_arrow_cross":f.arrowTypeStart="arrow_cross";case"arrow_cross":f.arrowTypeEnd="arrow_cross";break;case"double_arrow_point":f.arrowTypeStart="arrow_point";case"arrow_point":f.arrowTypeEnd="arrow_point";break;case"double_arrow_circle":f.arrowTypeStart="arrow_circle";case"arrow_circle":f.arrowTypeEnd="arrow_circle";break}let p="",m="";switch(o.stroke){case"normal":p="fill:none;",typeof a<"u"&&(p=a),typeof s<"u"&&(m=s),f.thickness="normal",f.pattern="solid";break;case"dotted":f.thickness="normal",f.pattern="dotted",f.style="fill:none;stroke-width:2px;stroke-dasharray:3;";break;case"thick":f.thickness="thick",f.pattern="solid",f.style="stroke-width: 3.5px;fill:none;";break;case"invisible":f.thickness="invisible",f.pattern="solid",f.style="stroke-width: 0;fill:none;";break}if(typeof o.style<"u"){const _=Ka(o.style);p=_.style,m=_.labelStyle}f.style=f.style+=p,f.labelStyle=f.labelStyle+=m,typeof o.interpolate<"u"?f.curve=Ni(o.interpolate,yn):typeof t.defaultInterpolate<"u"?f.curve=Ni(t.defaultInterpolate,yn):f.curve=Ni(HM.curve,yn),typeof o.text>"u"?typeof o.style<"u"&&(f.arrowheadStyle="fill: #333"):(f.arrowheadStyle="fill: #333",f.labelpos="c"),f.labelType="text",f.label=o.text.replace(pe.lineBreakRegex,` +`),typeof o.style>"u"&&(f.style=f.style||"stroke: #333; stroke-width: 1.5px;fill:none;"),f.labelStyle=f.labelStyle.replace("color:","fill:"),f.id=u,f.classes="flowchart-link "+h+" "+d,e.setEdge(o.start,o.end,f,n)})},A4={setConf:Cnt,addVertices:GM,addEdges:jM,getClasses:function(t,e){H.info("Extracting classes"),e.db.clear();try{return e.parse(t),e.db.getClasses()}catch{return}},draw:function(t,e,r,n){H.info("Drawing flowchart"),n.db.clear(),fa.setGen("gen-2"),n.parser.parse(t);let i=n.db.getDirection();typeof i>"u"&&(i="TD");const{securityLevel:a,flowchart:s}=nt(),o=s.nodeSpacing||50,l=s.rankSpacing||50;let u;a==="sandbox"&&(u=St("#i"+e));const h=St(a==="sandbox"?u.nodes()[0].contentDocument.body:"body"),d=a==="sandbox"?u.nodes()[0].contentDocument:document,f=new cr.Graph({multigraph:!0,compound:!0}).setGraph({rankdir:i,nodesep:o,ranksep:l,marginx:0,marginy:0}).setDefaultEdgeLabel(function(){return{}});let p;const m=n.db.getSubGraphs();H.info("Subgraphs - ",m);for(let C=m.length-1;C>=0;C--)p=m[C],H.info("Subgraph - ",p),n.db.addVertex(p.id,p.title,"group",void 0,p.classes,p.dir);const _=n.db.getVertices(),y=n.db.getEdges();H.info(y);let b=0;for(b=m.length-1;b>=0;b--){p=m[b],Nu("cluster").append("text");for(let C=0;C<p.nodes.length;C++)H.info("Setting up subgraphs",p.nodes[C],p.id),f.setParent(p.nodes[C],p.id)}GM(_,f,e,h,d,n),jM(y,f);const x=h.select(`[id="${e}"]`);bn(n.db,x,e);const k=h.select("#"+e+" g");if(i4(k,f,["point","circle","cross"],"flowchart",e),i1(f,x,s.diagramPadding,s.useMaxWidth),n.db.indexNodes("subGraph"+b),!s.htmlLabels){const C=d.querySelectorAll('[id="'+e+'"] .edgeLabel .label');for(let M=0;M<C.length;M++){const S=C[M],R=S.getBBox(),A=d.createElementNS("http://www.w3.org/2000/svg","rect");A.setAttribute("rx",0),A.setAttribute("ry",0),A.setAttribute("width",R.width),A.setAttribute("height",R.height),S.insertBefore(A,S.firstChild)}}Object.keys(_).forEach(function(C){const M=_[C];if(M.link){const S=St("#"+e+' [id="'+C+'"]');if(S){const R=d.createElementNS("http://www.w3.org/2000/svg","a");R.setAttributeNS("http://www.w3.org/2000/svg","class",M.classes.join(" ")),R.setAttributeNS("http://www.w3.org/2000/svg","href",M.link),R.setAttributeNS("http://www.w3.org/2000/svg","rel","noopener"),a==="sandbox"?R.setAttributeNS("http://www.w3.org/2000/svg","target","_top"):M.linkTarget&&R.setAttributeNS("http://www.w3.org/2000/svg","target",M.linkTarget);const A=S.insert(function(){return R},":first-child"),L=S.select(".label-container");L&&A.append(function(){return L.node()});const v=S.select(".label");v&&A.append(function(){return v.node()})}}})}};var M4=function(){var t=function(S,R,A,L){for(A=A||{},L=S.length;L--;A[S[L]]=R);return A},e=[1,3],r=[1,5],n=[7,9,11,12,13,14,15,16,17,18,19,20,22,24,25,27,34,39],i=[1,15],a=[1,16],s=[1,17],o=[1,18],l=[1,19],u=[1,20],h=[1,21],d=[1,22],f=[1,23],p=[1,24],m=[1,25],_=[1,26],y=[1,28],b=[1,30],x=[1,33],k=[5,7,9,11,12,13,14,15,16,17,18,19,20,22,24,25,27,34,39],T={trace:function(){},yy:{},symbols_:{error:2,start:3,directive:4,gantt:5,document:6,EOF:7,line:8,SPACE:9,statement:10,NL:11,dateFormat:12,inclusiveEndDates:13,topAxis:14,axisFormat:15,excludes:16,includes:17,todayMarker:18,title:19,acc_title:20,acc_title_value:21,acc_descr:22,acc_descr_value:23,acc_descr_multiline_value:24,section:25,clickStatement:26,taskTxt:27,taskData:28,openDirective:29,typeDirective:30,closeDirective:31,":":32,argDirective:33,click:34,callbackname:35,callbackargs:36,href:37,clickStatementDebug:38,open_directive:39,type_directive:40,arg_directive:41,close_directive:42,$accept:0,$end:1},terminals_:{2:"error",5:"gantt",7:"EOF",9:"SPACE",11:"NL",12:"dateFormat",13:"inclusiveEndDates",14:"topAxis",15:"axisFormat",16:"excludes",17:"includes",18:"todayMarker",19:"title",20:"acc_title",21:"acc_title_value",22:"acc_descr",23:"acc_descr_value",24:"acc_descr_multiline_value",25:"section",27:"taskTxt",28:"taskData",32:":",34:"click",35:"callbackname",36:"callbackargs",37:"href",39:"open_directive",40:"type_directive",41:"arg_directive",42:"close_directive"},productions_:[0,[3,2],[3,3],[6,0],[6,2],[8,2],[8,1],[8,1],[8,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,2],[10,2],[10,1],[10,1],[10,1],[10,2],[10,1],[4,4],[4,6],[26,2],[26,3],[26,3],[26,4],[26,3],[26,4],[26,2],[38,2],[38,3],[38,3],[38,4],[38,3],[38,4],[38,2],[29,1],[30,1],[33,1],[31,1]],performAction:function(R,A,L,v,B,w,D){var N=w.length-1;switch(B){case 2:return w[N-1];case 3:this.$=[];break;case 4:w[N-1].push(w[N]),this.$=w[N-1];break;case 5:case 6:this.$=w[N];break;case 7:case 8:this.$=[];break;case 9:v.setDateFormat(w[N].substr(11)),this.$=w[N].substr(11);break;case 10:v.enableInclusiveEndDates(),this.$=w[N].substr(18);break;case 11:v.TopAxis(),this.$=w[N].substr(8);break;case 12:v.setAxisFormat(w[N].substr(11)),this.$=w[N].substr(11);break;case 13:v.setExcludes(w[N].substr(9)),this.$=w[N].substr(9);break;case 14:v.setIncludes(w[N].substr(9)),this.$=w[N].substr(9);break;case 15:v.setTodayMarker(w[N].substr(12)),this.$=w[N].substr(12);break;case 16:v.setDiagramTitle(w[N].substr(6)),this.$=w[N].substr(6);break;case 17:this.$=w[N].trim(),v.setAccTitle(this.$);break;case 18:case 19:this.$=w[N].trim(),v.setAccDescription(this.$);break;case 20:v.addSection(w[N].substr(8)),this.$=w[N].substr(8);break;case 22:v.addTask(w[N-1],w[N]),this.$="task";break;case 26:this.$=w[N-1],v.setClickEvent(w[N-1],w[N],null);break;case 27:this.$=w[N-2],v.setClickEvent(w[N-2],w[N-1],w[N]);break;case 28:this.$=w[N-2],v.setClickEvent(w[N-2],w[N-1],null),v.setLink(w[N-2],w[N]);break;case 29:this.$=w[N-3],v.setClickEvent(w[N-3],w[N-2],w[N-1]),v.setLink(w[N-3],w[N]);break;case 30:this.$=w[N-2],v.setClickEvent(w[N-2],w[N],null),v.setLink(w[N-2],w[N-1]);break;case 31:this.$=w[N-3],v.setClickEvent(w[N-3],w[N-1],w[N]),v.setLink(w[N-3],w[N-2]);break;case 32:this.$=w[N-1],v.setLink(w[N-1],w[N]);break;case 33:case 39:this.$=w[N-1]+" "+w[N];break;case 34:case 35:case 37:this.$=w[N-2]+" "+w[N-1]+" "+w[N];break;case 36:case 38:this.$=w[N-3]+" "+w[N-2]+" "+w[N-1]+" "+w[N];break;case 40:v.parseDirective("%%{","open_directive");break;case 41:v.parseDirective(w[N],"type_directive");break;case 42:w[N]=w[N].trim().replace(/'/g,'"'),v.parseDirective(w[N],"arg_directive");break;case 43:v.parseDirective("}%%","close_directive","gantt");break}},table:[{3:1,4:2,5:e,29:4,39:r},{1:[3]},{3:6,4:2,5:e,29:4,39:r},t(n,[2,3],{6:7}),{30:8,40:[1,9]},{40:[2,40]},{1:[2,1]},{4:29,7:[1,10],8:11,9:[1,12],10:13,11:[1,14],12:i,13:a,14:s,15:o,16:l,17:u,18:h,19:d,20:f,22:p,24:m,25:_,26:27,27:y,29:4,34:b,39:r},{31:31,32:[1,32],42:x},t([32,42],[2,41]),t(n,[2,8],{1:[2,2]}),t(n,[2,4]),{4:29,10:34,12:i,13:a,14:s,15:o,16:l,17:u,18:h,19:d,20:f,22:p,24:m,25:_,26:27,27:y,29:4,34:b,39:r},t(n,[2,6]),t(n,[2,7]),t(n,[2,9]),t(n,[2,10]),t(n,[2,11]),t(n,[2,12]),t(n,[2,13]),t(n,[2,14]),t(n,[2,15]),t(n,[2,16]),{21:[1,35]},{23:[1,36]},t(n,[2,19]),t(n,[2,20]),t(n,[2,21]),{28:[1,37]},t(n,[2,23]),{35:[1,38],37:[1,39]},{11:[1,40]},{33:41,41:[1,42]},{11:[2,43]},t(n,[2,5]),t(n,[2,17]),t(n,[2,18]),t(n,[2,22]),t(n,[2,26],{36:[1,43],37:[1,44]}),t(n,[2,32],{35:[1,45]}),t(k,[2,24]),{31:46,42:x},{42:[2,42]},t(n,[2,27],{37:[1,47]}),t(n,[2,28]),t(n,[2,30],{36:[1,48]}),{11:[1,49]},t(n,[2,29]),t(n,[2,31]),t(k,[2,25])],defaultActions:{5:[2,40],6:[2,1],33:[2,43],42:[2,42]},parseError:function(R,A){if(A.recoverable)this.trace(R);else{var L=new Error(R);throw L.hash=A,L}},parse:function(R){var A=this,L=[0],v=[],B=[null],w=[],D=this.table,N="",z=0,X=0,ct=2,J=1,Y=w.slice.call(arguments,1),$=Object.create(this.lexer),lt={yy:{}};for(var ut in this.yy)Object.prototype.hasOwnProperty.call(this.yy,ut)&&(lt.yy[ut]=this.yy[ut]);$.setInput(R,lt.yy),lt.yy.lexer=$,lt.yy.parser=this,typeof $.yylloc>"u"&&($.yylloc={});var W=$.yylloc;w.push(W);var tt=$.options&&$.options.ranges;typeof lt.yy.parseError=="function"?this.parseError=lt.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function K(){var at;return at=v.pop()||$.lex()||J,typeof at!="number"&&(at instanceof Array&&(v=at,at=v.pop()),at=A.symbols_[at]||at),at}for(var it,Z,V,Q,q={},U,F,j,P;;){if(Z=L[L.length-1],this.defaultActions[Z]?V=this.defaultActions[Z]:((it===null||typeof it>"u")&&(it=K()),V=D[Z]&&D[Z][it]),typeof V>"u"||!V.length||!V[0]){var et="";P=[];for(U in D[Z])this.terminals_[U]&&U>ct&&P.push("'"+this.terminals_[U]+"'");$.showPosition?et="Parse error on line "+(z+1)+`: +`+$.showPosition()+` +Expecting `+P.join(", ")+", got '"+(this.terminals_[it]||it)+"'":et="Parse error on line "+(z+1)+": Unexpected "+(it==J?"end of input":"'"+(this.terminals_[it]||it)+"'"),this.parseError(et,{text:$.match,token:this.terminals_[it]||it,line:$.yylineno,loc:W,expected:P})}if(V[0]instanceof Array&&V.length>1)throw new Error("Parse Error: multiple actions possible at state: "+Z+", token: "+it);switch(V[0]){case 1:L.push(it),B.push($.yytext),w.push($.yylloc),L.push(V[1]),it=null,X=$.yyleng,N=$.yytext,z=$.yylineno,W=$.yylloc;break;case 2:if(F=this.productions_[V[1]][1],q.$=B[B.length-F],q._$={first_line:w[w.length-(F||1)].first_line,last_line:w[w.length-1].last_line,first_column:w[w.length-(F||1)].first_column,last_column:w[w.length-1].last_column},tt&&(q._$.range=[w[w.length-(F||1)].range[0],w[w.length-1].range[1]]),Q=this.performAction.apply(q,[N,X,z,lt.yy,V[1],B,w].concat(Y)),typeof Q<"u")return Q;F&&(L=L.slice(0,-1*F*2),B=B.slice(0,-1*F),w=w.slice(0,-1*F)),L.push(this.productions_[V[1]][0]),B.push(q.$),w.push(q._$),j=D[L[L.length-2]][L[L.length-1]],L.push(j);break;case 3:return!0}}return!0}},C=function(){var S={EOF:1,parseError:function(A,L){if(this.yy.parser)this.yy.parser.parseError(A,L);else throw new Error(A)},setInput:function(R,A){return this.yy=A||this.yy||{},this._input=R,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var R=this._input[0];this.yytext+=R,this.yyleng++,this.offset++,this.match+=R,this.matched+=R;var A=R.match(/(?:\r\n?|\n).*/g);return A?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),R},unput:function(R){var A=R.length,L=R.split(/(?:\r\n?|\n)/g);this._input=R+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-A),this.offset-=A;var v=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),L.length-1&&(this.yylineno-=L.length-1);var B=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:L?(L.length===v.length?this.yylloc.first_column:0)+v[v.length-L.length].length-L[0].length:this.yylloc.first_column-A},this.options.ranges&&(this.yylloc.range=[B[0],B[0]+this.yyleng-A]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(R){this.unput(this.match.slice(R))},pastInput:function(){var R=this.matched.substr(0,this.matched.length-this.match.length);return(R.length>20?"...":"")+R.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var R=this.match;return R.length<20&&(R+=this._input.substr(0,20-R.length)),(R.substr(0,20)+(R.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var R=this.pastInput(),A=new Array(R.length+1).join("-");return R+this.upcomingInput()+` +`+A+"^"},test_match:function(R,A){var L,v,B;if(this.options.backtrack_lexer&&(B={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(B.yylloc.range=this.yylloc.range.slice(0))),v=R[0].match(/(?:\r\n?|\n).*/g),v&&(this.yylineno+=v.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:v?v[v.length-1].length-v[v.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+R[0].length},this.yytext+=R[0],this.match+=R[0],this.matches=R,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(R[0].length),this.matched+=R[0],L=this.performAction.call(this,this.yy,this,A,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),L)return L;if(this._backtrack){for(var w in B)this[w]=B[w];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var R,A,L,v;this._more||(this.yytext="",this.match="");for(var B=this._currentRules(),w=0;w<B.length;w++)if(L=this._input.match(this.rules[B[w]]),L&&(!A||L[0].length>A[0].length)){if(A=L,v=w,this.options.backtrack_lexer){if(R=this.test_match(L,B[w]),R!==!1)return R;if(this._backtrack){A=!1;continue}else return!1}else if(!this.options.flex)break}return A?(R=this.test_match(A,B[v]),R!==!1?R:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var A=this.next();return A||this.lex()},begin:function(A){this.conditionStack.push(A)},popState:function(){var A=this.conditionStack.length-1;return A>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(A){return A=this.conditionStack.length-1-Math.abs(A||0),A>=0?this.conditionStack[A]:"INITIAL"},pushState:function(A){this.begin(A)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(A,L,v,B){switch(v){case 0:return this.begin("open_directive"),39;case 1:return this.begin("type_directive"),40;case 2:return this.popState(),this.begin("arg_directive"),32;case 3:return this.popState(),this.popState(),42;case 4:return 41;case 5:return this.begin("acc_title"),20;case 6:return this.popState(),"acc_title_value";case 7:return this.begin("acc_descr"),22;case 8:return this.popState(),"acc_descr_value";case 9:this.begin("acc_descr_multiline");break;case 10:this.popState();break;case 11:return"acc_descr_multiline_value";case 12:break;case 13:break;case 14:break;case 15:return 11;case 16:break;case 17:break;case 18:break;case 19:this.begin("href");break;case 20:this.popState();break;case 21:return 37;case 22:this.begin("callbackname");break;case 23:this.popState();break;case 24:this.popState(),this.begin("callbackargs");break;case 25:return 35;case 26:this.popState();break;case 27:return 36;case 28:this.begin("click");break;case 29:this.popState();break;case 30:return 34;case 31:return 5;case 32:return 12;case 33:return 13;case 34:return 14;case 35:return 15;case 36:return 17;case 37:return 16;case 38:return 18;case 39:return"date";case 40:return 19;case 41:return"accDescription";case 42:return 25;case 43:return 27;case 44:return 28;case 45:return 32;case 46:return 7;case 47:return"INVALID"}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:accTitle\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*\{\s*)/i,/^(?:[\}])/i,/^(?:[^\}]*)/i,/^(?:%%(?!\{)*[^\n]*)/i,/^(?:[^\}]%%*[^\n]*)/i,/^(?:%%*[^\n]*[\n]*)/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:href[\s]+["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:call[\s]+)/i,/^(?:\([\s]*\))/i,/^(?:\()/i,/^(?:[^(]*)/i,/^(?:\))/i,/^(?:[^)]*)/i,/^(?:click[\s]+)/i,/^(?:[\s\n])/i,/^(?:[^\s\n]*)/i,/^(?:gantt\b)/i,/^(?:dateFormat\s[^#\n;]+)/i,/^(?:inclusiveEndDates\b)/i,/^(?:topAxis\b)/i,/^(?:axisFormat\s[^#\n;]+)/i,/^(?:includes\s[^#\n;]+)/i,/^(?:excludes\s[^#\n;]+)/i,/^(?:todayMarker\s[^\n;]+)/i,/^(?:\d\d\d\d-\d\d-\d\d\b)/i,/^(?:title\s[^#\n;]+)/i,/^(?:accDescription\s[^#\n;]+)/i,/^(?:section\s[^#:\n;]+)/i,/^(?:[^#:\n;]+)/i,/^(?::[^#\n;]+)/i,/^(?::)/i,/^(?:$)/i,/^(?:.)/i],conditions:{acc_descr_multiline:{rules:[10,11],inclusive:!1},acc_descr:{rules:[8],inclusive:!1},acc_title:{rules:[6],inclusive:!1},close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},callbackargs:{rules:[26,27],inclusive:!1},callbackname:{rules:[23,24,25],inclusive:!1},href:{rules:[20,21],inclusive:!1},click:{rules:[29,30],inclusive:!1},INITIAL:{rules:[0,5,7,9,12,13,14,15,16,17,18,19,22,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47],inclusive:!0}}};return S}();T.lexer=C;function M(){this.yy={}}return M.prototype=T,T.Parser=M,new M}();M4.parser=M4;const Snt=t=>t.match(/^\s*gantt/)!==null;let zi="",L4="",R4="",au=[],su=[],I4={},N4=[],a0=[],sl="";const $M=["active","done","crit","milestone"];let s0=[],ou=!1,B4=!1,D4=0;const Ant=function(t,e,r){Xe.parseDirective(this,t,e,r)},Mnt=function(){N4=[],a0=[],sl="",s0=[],o0=0,F4=void 0,l0=void 0,yr=[],zi="",L4="",R4="",au=[],su=[],ou=!1,B4=!1,D4=0,I4={},ci()},Lnt=function(t){L4=t},Rnt=function(){return L4},Int=function(t){R4=t},Nnt=function(){return R4},Bnt=function(t){zi=t},Dnt=function(){ou=!0},Ont=function(){return ou},Fnt=function(){B4=!0},Pnt=function(){return B4},qnt=function(){return zi},Vnt=function(t){au=t.toLowerCase().split(/[\s,]+/)},znt=function(){return au},Ynt=function(t){su=t.toLowerCase().split(/[\s,]+/)},Unt=function(){return su},Wnt=function(){return I4},Hnt=function(t){sl=t,N4.push(t)},Gnt=function(){return N4},jnt=function(){let t=tL();const e=10;let r=0;for(;!t&&r<e;)t=tL(),r++;return a0=yr,a0},XM=function(t,e,r,n){return n.indexOf(t.format(e.trim()))>=0?!1:t.isoWeekday()>=6&&r.indexOf("weekends")>=0||r.indexOf(t.format("dddd").toLowerCase())>=0?!0:r.indexOf(t.format(e.trim()))>=0},KM=function(t,e,r,n){if(!r.length||t.manualEndTime)return;let i=Xn(t.startTime,e,!0);i.add(1,"d");let a=Xn(t.endTime,e,!0),s=$nt(i,a,e,r,n);t.endTime=a.toDate(),t.renderEndTime=s},$nt=function(t,e,r,n,i){let a=!1,s=null;for(;t<=e;)a||(s=e.toDate()),a=XM(t,r,n,i),a&&e.add(1,"d"),t.add(1,"d");return s},O4=function(t,e,r){r=r.trim();const i=/^after\s+([\d\w- ]+)/.exec(r.trim());if(i!==null){let s=null;if(i[1].split(" ").forEach(function(o){let l=ll(o);typeof l<"u"&&(s?l.endTime>s.endTime&&(s=l):s=l)}),s)return s.endTime;{const o=new Date;return o.setHours(0,0,0,0),o}}let a=Xn(r,e.trim(),!0);if(a.isValid())return a.toDate();{H.debug("Invalid date:"+r),H.debug("With date format:"+e.trim());const s=new Date(r);if(typeof s>"u"||isNaN(s.getTime()))throw new Error("Invalid date:"+r);return s}},ZM=function(t){const e=/^(\d+(?:\.\d+)?)([yMwdhms]|ms)$/.exec(t.trim());return e!==null?Xn.duration(Number.parseFloat(e[1]),e[2]):Xn.duration.invalid()},QM=function(t,e,r,n){n=n||!1,r=r.trim();let i=Xn(r,e.trim(),!0);if(i.isValid())return n&&i.add(1,"d"),i.toDate();const a=Xn(t),s=ZM(r);return s.isValid()&&a.add(s),a.toDate()};let o0=0;const ol=function(t){return typeof t>"u"?(o0=o0+1,"task"+o0):t},Xnt=function(t,e){let r;e.substr(0,1)===":"?r=e.substr(1,e.length):r=e;const n=r.split(","),i={};nL(n,i,$M);for(let s=0;s<n.length;s++)n[s]=n[s].trim();let a="";switch(n.length){case 1:i.id=ol(),i.startTime=t.endTime,a=n[0];break;case 2:i.id=ol(),i.startTime=O4(void 0,zi,n[0]),a=n[1];break;case 3:i.id=ol(n[0]),i.startTime=O4(void 0,zi,n[1]),a=n[2];break}return a&&(i.endTime=QM(i.startTime,zi,a,ou),i.manualEndTime=Xn(a,"YYYY-MM-DD",!0).isValid(),KM(i,zi,su,au)),i},Knt=function(t,e){let r;e.substr(0,1)===":"?r=e.substr(1,e.length):r=e;const n=r.split(","),i={};nL(n,i,$M);for(let a=0;a<n.length;a++)n[a]=n[a].trim();switch(n.length){case 1:i.id=ol(),i.startTime={type:"prevTaskEnd",id:t},i.endTime={data:n[0]};break;case 2:i.id=ol(),i.startTime={type:"getStartDate",startData:n[0]},i.endTime={data:n[1]};break;case 3:i.id=ol(n[0]),i.startTime={type:"getStartDate",startData:n[1]},i.endTime={data:n[2]};break}return i};let F4,l0,yr=[];const JM={},Znt=function(t,e){const r={section:sl,type:sl,processed:!1,manualEndTime:!1,renderEndTime:null,raw:{data:e},task:t,classes:[]},n=Knt(l0,e);r.raw.startTime=n.startTime,r.raw.endTime=n.endTime,r.id=n.id,r.prevTaskId=l0,r.active=n.active,r.done=n.done,r.crit=n.crit,r.milestone=n.milestone,r.order=D4,D4++;const i=yr.push(r);l0=r.id,JM[r.id]=i-1},ll=function(t){const e=JM[t];return yr[e]},Qnt=function(t,e){const r={section:sl,type:sl,description:t,task:t,classes:[]},n=Xnt(F4,e);r.startTime=n.startTime,r.endTime=n.endTime,r.id=n.id,r.active=n.active,r.done=n.done,r.crit=n.crit,r.milestone=n.milestone,F4=r,a0.push(r)},tL=function(){const t=function(r){const n=yr[r];let i="";switch(yr[r].raw.startTime.type){case"prevTaskEnd":{const a=ll(n.prevTaskId);n.startTime=a.endTime;break}case"getStartDate":i=O4(void 0,zi,yr[r].raw.startTime.startData),i&&(yr[r].startTime=i);break}return yr[r].startTime&&(yr[r].endTime=QM(yr[r].startTime,zi,yr[r].raw.endTime.data,ou),yr[r].endTime&&(yr[r].processed=!0,yr[r].manualEndTime=Xn(yr[r].raw.endTime.data,"YYYY-MM-DD",!0).isValid(),KM(yr[r],zi,su,au))),yr[r].processed};let e=!0;for(let r=0;r<yr.length;r++)t(r),e=e&&yr[r].processed;return e},Jnt=function(t,e){let r=e;nt().securityLevel!=="loose"&&(r=ki(e)),t.split(",").forEach(function(n){typeof ll(n)<"u"&&(rL(n,()=>{window.open(r,"_self")}),I4[n]=r)}),eL(t,"clickable")},eL=function(t,e){t.split(",").forEach(function(r){let n=ll(r);typeof n<"u"&&n.classes.push(e)})},tit=function(t,e,r){if(nt().securityLevel!=="loose"||typeof e>"u")return;let n=[];if(typeof r=="string"){n=r.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/);for(let a=0;a<n.length;a++){let s=n[a].trim();s.charAt(0)==='"'&&s.charAt(s.length-1)==='"'&&(s=s.substr(1,s.length-2)),n[a]=s}}n.length===0&&n.push(t),typeof ll(t)<"u"&&rL(t,()=>{Se.runFunc(e,...n)})},rL=function(t,e){s0.push(function(){const r=document.querySelector(`[id="${t}"]`);r!==null&&r.addEventListener("click",function(){e()})}),s0.push(function(){const r=document.querySelector(`[id="${t}-text"]`);r!==null&&r.addEventListener("click",function(){e()})})},P4={parseDirective:Ant,getConfig:()=>nt().gantt,clear:Mnt,setDateFormat:Bnt,getDateFormat:qnt,enableInclusiveEndDates:Dnt,endDatesAreInclusive:Ont,enableTopAxis:Fnt,topAxisEnabled:Pnt,setAxisFormat:Lnt,getAxisFormat:Rnt,setTodayMarker:Int,getTodayMarker:Nnt,setAccTitle:Yn,getAccTitle:ui,setDiagramTitle:c1,getDiagramTitle:u1,setAccDescription:hi,getAccDescription:fi,addSection:Hnt,getSections:Gnt,getTasks:jnt,addTask:Znt,findTaskById:ll,addTaskOrg:Qnt,setIncludes:Vnt,getIncludes:znt,setExcludes:Ynt,getExcludes:Unt,setClickEvent:function(t,e,r){t.split(",").forEach(function(n){tit(n,e,r)}),eL(t,"clickable")},setLink:Jnt,getLinks:Wnt,bindFunctions:function(t){s0.forEach(function(e){e(t)})},parseDuration:ZM,isInvalidDate:XM};function nL(t,e,r){let n=!0;for(;n;)n=!1,r.forEach(function(i){const a="^\\s*"+i+"\\s*$",s=new RegExp(a);t[0].match(s)&&(e[i]=!0,t.shift(1),n=!0)})}const eit=function(){H.debug("Something is calling, setConf, remove the call")};let pa;const rit={setConf:eit,draw:function(t,e,r,n){const i=nt().gantt,a=nt().securityLevel;let s;a==="sandbox"&&(s=St("#i"+e));const o=St(a==="sandbox"?s.nodes()[0].contentDocument.body:"body"),l=a==="sandbox"?s.nodes()[0].contentDocument:document,u=l.getElementById(e);pa=u.parentElement.offsetWidth,typeof pa>"u"&&(pa=1200),typeof i.useWidth<"u"&&(pa=i.useWidth);const h=n.db.getTasks(),d=h.length*(i.barHeight+i.barGap)+2*i.topPadding;u.setAttribute("viewBox","0 0 "+pa+" "+d);const f=o.select(`[id="${e}"]`),p=X8().domain([Tl(h,function(L){return L.startTime}),lo(h,function(L){return L.endTime})]).rangeRound([0,pa-i.leftPadding-i.rightPadding]);let m=[];for(let L=0;L<h.length;L++)m.push(h[L].type);const _=m;m=S(m);function y(L,v){const B=L.startTime,w=v.startTime;let D=0;return B>w?D=1:B<w&&(D=-1),D}h.sort(y),b(h,pa,d),li(f,d,pa,i.useMaxWidth),f.append("text").text(n.db.getDiagramTitle()).attr("x",pa/2).attr("y",i.titleTopMargin).attr("class","titleText"),bn(n.db,f,e);function b(L,v,B){const w=i.barHeight,D=w+i.barGap,N=i.topPadding,z=i.leftPadding,X=sp().domain([0,m.length]).range(["#00B9FA","#F95002"]).interpolate($5);k(D,N,z,v,B,L,n.db.getExcludes(),n.db.getIncludes()),T(z,N,v,B),x(L,D,N,z,w,X,v),C(D,N),M(z,N,v,B)}function x(L,v,B,w,D,N,z){f.append("g").selectAll("rect").data(L).enter().append("rect").attr("x",0).attr("y",function(Y,$){return $=Y.order,$*v+B-2}).attr("width",function(){return z-i.rightPadding/2}).attr("height",v).attr("class",function(Y){for(let $=0;$<m.length;$++)if(Y.type===m[$])return"section section"+$%i.numberSectionStyles;return"section section0"});const X=f.append("g").selectAll("rect").data(L).enter(),ct=n.db.getLinks();if(X.append("rect").attr("id",function(Y){return Y.id}).attr("rx",3).attr("ry",3).attr("x",function(Y){return Y.milestone?p(Y.startTime)+w+.5*(p(Y.endTime)-p(Y.startTime))-.5*D:p(Y.startTime)+w}).attr("y",function(Y,$){return $=Y.order,$*v+B}).attr("width",function(Y){return Y.milestone?D:p(Y.renderEndTime||Y.endTime)-p(Y.startTime)}).attr("height",D).attr("transform-origin",function(Y,$){return $=Y.order,(p(Y.startTime)+w+.5*(p(Y.endTime)-p(Y.startTime))).toString()+"px "+($*v+B+.5*D).toString()+"px"}).attr("class",function(Y){const $="task";let lt="";Y.classes.length>0&&(lt=Y.classes.join(" "));let ut=0;for(let tt=0;tt<m.length;tt++)Y.type===m[tt]&&(ut=tt%i.numberSectionStyles);let W="";return Y.active?Y.crit?W+=" activeCrit":W=" active":Y.done?Y.crit?W=" doneCrit":W=" done":Y.crit&&(W+=" crit"),W.length===0&&(W=" task"),Y.milestone&&(W=" milestone "+W),W+=ut,W+=" "+lt,$+W}),X.append("text").attr("id",function(Y){return Y.id+"-text"}).text(function(Y){return Y.task}).attr("font-size",i.fontSize).attr("x",function(Y){let $=p(Y.startTime),lt=p(Y.renderEndTime||Y.endTime);Y.milestone&&($+=.5*(p(Y.endTime)-p(Y.startTime))-.5*D),Y.milestone&&(lt=$+D);const ut=this.getBBox().width;return ut>lt-$?lt+ut+1.5*i.leftPadding>z?$+w-5:lt+w+5:(lt-$)/2+$+w}).attr("y",function(Y,$){return $=Y.order,$*v+i.barHeight/2+(i.fontSize/2-2)+B}).attr("text-height",D).attr("class",function(Y){const $=p(Y.startTime);let lt=p(Y.endTime);Y.milestone&&(lt=$+D);const ut=this.getBBox().width;let W="";Y.classes.length>0&&(W=Y.classes.join(" "));let tt=0;for(let it=0;it<m.length;it++)Y.type===m[it]&&(tt=it%i.numberSectionStyles);let K="";return Y.active&&(Y.crit?K="activeCritText"+tt:K="activeText"+tt),Y.done?Y.crit?K=K+" doneCritText"+tt:K=K+" doneText"+tt:Y.crit&&(K=K+" critText"+tt),Y.milestone&&(K+=" milestoneText"),ut>lt-$?lt+ut+1.5*i.leftPadding>z?W+" taskTextOutsideLeft taskTextOutside"+tt+" "+K:W+" taskTextOutsideRight taskTextOutside"+tt+" "+K+" width-"+ut:W+" taskText taskText"+tt+" "+K+" width-"+ut}),nt().securityLevel==="sandbox"){let Y;Y=St("#i"+e);const $=Y.nodes()[0].contentDocument;X.filter(function(lt){return typeof ct[lt.id]<"u"}).each(function(lt){var ut=$.querySelector("#"+lt.id),W=$.querySelector("#"+lt.id+"-text");const tt=ut.parentNode;var K=$.createElement("a");K.setAttribute("xlink:href",ct[lt.id]),K.setAttribute("target","_top"),tt.appendChild(K),K.appendChild(ut),K.appendChild(W)})}}function k(L,v,B,w,D,N,z,X){const ct=N.reduce((tt,{startTime:K})=>tt?Math.min(tt,K):K,0),J=N.reduce((tt,{endTime:K})=>tt?Math.max(tt,K):K,0),Y=n.db.getDateFormat();if(!ct||!J)return;const $=[];let lt=null,ut=Xn(ct);for(;ut.valueOf()<=J;)n.db.isInvalidDate(ut,Y,z,X)?lt?lt.end=ut.clone():lt={start:ut.clone(),end:ut.clone()}:lt&&($.push(lt),lt=null),ut.add(1,"d");f.append("g").selectAll("rect").data($).enter().append("rect").attr("id",function(tt){return"exclude-"+tt.start.format("YYYY-MM-DD")}).attr("x",function(tt){return p(tt.start)+B}).attr("y",i.gridLineStartPadding).attr("width",function(tt){const K=tt.end.clone().add(1,"day");return p(K)-p(tt.start)}).attr("height",D-v-i.gridLineStartPadding).attr("transform-origin",function(tt,K){return(p(tt.start)+B+.5*(p(tt.end)-p(tt.start))).toString()+"px "+(K*L+.5*D).toString()+"px"}).attr("class","exclude-range")}function T(L,v,B,w){let D=$_(p).tickSize(-w+v+i.gridLineStartPadding).tickFormat(vc(n.db.getAxisFormat()||i.axisFormat||"%Y-%m-%d"));if(f.append("g").attr("class","grid").attr("transform","translate("+L+", "+(w-50)+")").call(D).selectAll("text").style("text-anchor","middle").attr("fill","#000").attr("stroke","none").attr("font-size",10).attr("dy","1em"),n.db.topAxisEnabled()||i.topAxis){let N=j_(p).tickSize(-w+v+i.gridLineStartPadding).tickFormat(vc(n.db.getAxisFormat()||i.axisFormat||"%Y-%m-%d"));f.append("g").attr("class","grid").attr("transform","translate("+L+", "+v+")").call(N).selectAll("text").style("text-anchor","middle").attr("fill","#000").attr("stroke","none").attr("font-size",10)}}function C(L,v){const B=[];let w=0;for(let D=0;D<m.length;D++)B[D]=[m[D],A(m[D],_)];f.append("g").selectAll("text").data(B).enter().append(function(D){const N=D[0].split(pe.lineBreakRegex),z=-(N.length-1)/2,X=l.createElementNS("http://www.w3.org/2000/svg","text");X.setAttribute("dy",z+"em");for(let ct=0;ct<N.length;ct++){const J=l.createElementNS("http://www.w3.org/2000/svg","tspan");J.setAttribute("alignment-baseline","central"),J.setAttribute("x","10"),ct>0&&J.setAttribute("dy","1em"),J.textContent=N[ct],X.appendChild(J)}return X}).attr("x",10).attr("y",function(D,N){if(N>0)for(let z=0;z<N;z++)return w+=B[N-1][1],D[1]*L/2+w*L+v;else return D[1]*L/2+v}).attr("font-size",i.sectionFontSize).attr("font-size",i.sectionFontSize).attr("class",function(D){for(let N=0;N<m.length;N++)if(D[0]===m[N])return"sectionTitle sectionTitle"+N%i.numberSectionStyles;return"sectionTitle"})}function M(L,v,B,w){const D=n.db.getTodayMarker();if(D==="off")return;const N=f.append("g").attr("class","today"),z=new Date,X=N.append("line");X.attr("x1",p(z)+L).attr("x2",p(z)+L).attr("y1",i.titleTopMargin).attr("y2",w-i.titleTopMargin).attr("class","today"),D!==""&&X.attr("style",D.replace(/,/g,";"))}function S(L){const v={},B=[];for(let w=0,D=L.length;w<D;++w)Object.prototype.hasOwnProperty.call(v,L[w])||(v[L[w]]=!0,B.push(L[w]));return B}function R(L){let v=L.length;const B={};for(;v;)B[L[--v]]=(B[L[v]]||0)+1;return B}function A(L,v){return R(v)[L]||0}}};var q4=function(){var t=function(a,s,o,l){for(o=o||{},l=a.length;l--;o[a[l]]=s);return o},e=[6,9,10],r={trace:function(){},yy:{},symbols_:{error:2,start:3,info:4,document:5,EOF:6,line:7,statement:8,NL:9,showInfo:10,$accept:0,$end:1},terminals_:{2:"error",4:"info",6:"EOF",9:"NL",10:"showInfo"},productions_:[0,[3,3],[5,0],[5,2],[7,1],[7,1],[8,1]],performAction:function(s,o,l,u,h,d,f){switch(d.length-1,h){case 1:return u;case 4:break;case 6:u.setInfo(!0);break}},table:[{3:1,4:[1,2]},{1:[3]},t(e,[2,2],{5:3}),{6:[1,4],7:5,8:6,9:[1,7],10:[1,8]},{1:[2,1]},t(e,[2,3]),t(e,[2,4]),t(e,[2,5]),t(e,[2,6])],defaultActions:{4:[2,1]},parseError:function(s,o){if(o.recoverable)this.trace(s);else{var l=new Error(s);throw l.hash=o,l}},parse:function(s){var o=this,l=[0],u=[],h=[null],d=[],f=this.table,p="",m=0,_=0,y=2,b=1,x=d.slice.call(arguments,1),k=Object.create(this.lexer),T={yy:{}};for(var C in this.yy)Object.prototype.hasOwnProperty.call(this.yy,C)&&(T.yy[C]=this.yy[C]);k.setInput(s,T.yy),T.yy.lexer=k,T.yy.parser=this,typeof k.yylloc>"u"&&(k.yylloc={});var M=k.yylloc;d.push(M);var S=k.options&&k.options.ranges;typeof T.yy.parseError=="function"?this.parseError=T.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function R(){var J;return J=u.pop()||k.lex()||b,typeof J!="number"&&(J instanceof Array&&(u=J,J=u.pop()),J=o.symbols_[J]||J),J}for(var A,L,v,B,w={},D,N,z,X;;){if(L=l[l.length-1],this.defaultActions[L]?v=this.defaultActions[L]:((A===null||typeof A>"u")&&(A=R()),v=f[L]&&f[L][A]),typeof v>"u"||!v.length||!v[0]){var ct="";X=[];for(D in f[L])this.terminals_[D]&&D>y&&X.push("'"+this.terminals_[D]+"'");k.showPosition?ct="Parse error on line "+(m+1)+`: +`+k.showPosition()+` +Expecting `+X.join(", ")+", got '"+(this.terminals_[A]||A)+"'":ct="Parse error on line "+(m+1)+": Unexpected "+(A==b?"end of input":"'"+(this.terminals_[A]||A)+"'"),this.parseError(ct,{text:k.match,token:this.terminals_[A]||A,line:k.yylineno,loc:M,expected:X})}if(v[0]instanceof Array&&v.length>1)throw new Error("Parse Error: multiple actions possible at state: "+L+", token: "+A);switch(v[0]){case 1:l.push(A),h.push(k.yytext),d.push(k.yylloc),l.push(v[1]),A=null,_=k.yyleng,p=k.yytext,m=k.yylineno,M=k.yylloc;break;case 2:if(N=this.productions_[v[1]][1],w.$=h[h.length-N],w._$={first_line:d[d.length-(N||1)].first_line,last_line:d[d.length-1].last_line,first_column:d[d.length-(N||1)].first_column,last_column:d[d.length-1].last_column},S&&(w._$.range=[d[d.length-(N||1)].range[0],d[d.length-1].range[1]]),B=this.performAction.apply(w,[p,_,m,T.yy,v[1],h,d].concat(x)),typeof B<"u")return B;N&&(l=l.slice(0,-1*N*2),h=h.slice(0,-1*N),d=d.slice(0,-1*N)),l.push(this.productions_[v[1]][0]),h.push(w.$),d.push(w._$),z=f[l[l.length-2]][l[l.length-1]],l.push(z);break;case 3:return!0}}return!0}},n=function(){var a={EOF:1,parseError:function(o,l){if(this.yy.parser)this.yy.parser.parseError(o,l);else throw new Error(o)},setInput:function(s,o){return this.yy=o||this.yy||{},this._input=s,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var s=this._input[0];this.yytext+=s,this.yyleng++,this.offset++,this.match+=s,this.matched+=s;var o=s.match(/(?:\r\n?|\n).*/g);return o?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),s},unput:function(s){var o=s.length,l=s.split(/(?:\r\n?|\n)/g);this._input=s+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-o),this.offset-=o;var u=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),l.length-1&&(this.yylineno-=l.length-1);var h=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:l?(l.length===u.length?this.yylloc.first_column:0)+u[u.length-l.length].length-l[0].length:this.yylloc.first_column-o},this.options.ranges&&(this.yylloc.range=[h[0],h[0]+this.yyleng-o]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(s){this.unput(this.match.slice(s))},pastInput:function(){var s=this.matched.substr(0,this.matched.length-this.match.length);return(s.length>20?"...":"")+s.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var s=this.match;return s.length<20&&(s+=this._input.substr(0,20-s.length)),(s.substr(0,20)+(s.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var s=this.pastInput(),o=new Array(s.length+1).join("-");return s+this.upcomingInput()+` +`+o+"^"},test_match:function(s,o){var l,u,h;if(this.options.backtrack_lexer&&(h={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(h.yylloc.range=this.yylloc.range.slice(0))),u=s[0].match(/(?:\r\n?|\n).*/g),u&&(this.yylineno+=u.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:u?u[u.length-1].length-u[u.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+s[0].length},this.yytext+=s[0],this.match+=s[0],this.matches=s,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(s[0].length),this.matched+=s[0],l=this.performAction.call(this,this.yy,this,o,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),l)return l;if(this._backtrack){for(var d in h)this[d]=h[d];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var s,o,l,u;this._more||(this.yytext="",this.match="");for(var h=this._currentRules(),d=0;d<h.length;d++)if(l=this._input.match(this.rules[h[d]]),l&&(!o||l[0].length>o[0].length)){if(o=l,u=d,this.options.backtrack_lexer){if(s=this.test_match(l,h[d]),s!==!1)return s;if(this._backtrack){o=!1;continue}else return!1}else if(!this.options.flex)break}return o?(s=this.test_match(o,h[u]),s!==!1?s:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var o=this.next();return o||this.lex()},begin:function(o){this.conditionStack.push(o)},popState:function(){var o=this.conditionStack.length-1;return o>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(o){return o=this.conditionStack.length-1-Math.abs(o||0),o>=0?this.conditionStack[o]:"INITIAL"},pushState:function(o){this.begin(o)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(o,l,u,h){switch(u){case 0:return 4;case 1:return 9;case 2:return"space";case 3:return 10;case 4:return 6;case 5:return"TXT"}},rules:[/^(?:info\b)/i,/^(?:[\s\n\r]+)/i,/^(?:[\s]+)/i,/^(?:showInfo\b)/i,/^(?:$)/i,/^(?:.)/i],conditions:{INITIAL:{rules:[0,1,2,3,4,5],inclusive:!0}}};return a}();r.lexer=n;function i(){this.yy={}}return i.prototype=r,r.Parser=i,new i}();q4.parser=q4;var iL="",aL=!1;const nit={setMessage:t=>{H.debug("Setting message to: "+t),iL=t},getMessage:()=>iL,setInfo:t=>{aL=t},getInfo:()=>aL,clear:ci},iit={draw:(t,e,r,n)=>{try{H.debug(`Rendering info diagram +`+t);const i=nt().securityLevel;let a;i==="sandbox"&&(a=St("#i"+e));const o=St(i==="sandbox"?a.nodes()[0].contentDocument.body:"body").select("#"+e);o.append("g").append("text").attr("x",100).attr("y",40).attr("class","version").attr("font-size","32px").style("text-anchor","middle").text("v "+r),o.attr("height",100),o.attr("width",400)}catch(i){H.error("Error while rendering info diagram"),H.error(i.message)}}},ait=t=>t.match(/^\s*info/)!==null;var V4=function(){var t=function(M,S,R,A){for(R=R||{},A=M.length;A--;R[M[A]]=S);return R},e=[1,4],r=[1,5],n=[1,6],i=[1,7],a=[1,9],s=[1,11,13,15,17,19,20,26,27,28,29],o=[2,5],l=[1,6,11,13,15,17,19,20,26,27,28,29],u=[26,27,28],h=[2,8],d=[1,18],f=[1,19],p=[1,20],m=[1,21],_=[1,22],y=[1,23],b=[1,28],x=[6,26,27,28,29],k={trace:function(){},yy:{},symbols_:{error:2,start:3,eol:4,directive:5,PIE:6,document:7,showData:8,line:9,statement:10,txt:11,value:12,title:13,title_value:14,acc_title:15,acc_title_value:16,acc_descr:17,acc_descr_value:18,acc_descr_multiline_value:19,section:20,openDirective:21,typeDirective:22,closeDirective:23,":":24,argDirective:25,NEWLINE:26,";":27,EOF:28,open_directive:29,type_directive:30,arg_directive:31,close_directive:32,$accept:0,$end:1},terminals_:{2:"error",6:"PIE",8:"showData",11:"txt",12:"value",13:"title",14:"title_value",15:"acc_title",16:"acc_title_value",17:"acc_descr",18:"acc_descr_value",19:"acc_descr_multiline_value",20:"section",24:":",26:"NEWLINE",27:";",28:"EOF",29:"open_directive",30:"type_directive",31:"arg_directive",32:"close_directive"},productions_:[0,[3,2],[3,2],[3,2],[3,3],[7,0],[7,2],[9,2],[10,0],[10,2],[10,2],[10,2],[10,2],[10,1],[10,1],[10,1],[5,3],[5,5],[4,1],[4,1],[4,1],[21,1],[22,1],[25,1],[23,1]],performAction:function(S,R,A,L,v,B,w){var D=B.length-1;switch(v){case 4:L.setShowData(!0);break;case 7:this.$=B[D-1];break;case 9:L.addSection(B[D-1],L.cleanupValue(B[D]));break;case 10:this.$=B[D].trim(),L.setDiagramTitle(this.$);break;case 11:this.$=B[D].trim(),L.setAccTitle(this.$);break;case 12:case 13:this.$=B[D].trim(),L.setAccDescription(this.$);break;case 14:L.addSection(B[D].substr(8)),this.$=B[D].substr(8);break;case 21:L.parseDirective("%%{","open_directive");break;case 22:L.parseDirective(B[D],"type_directive");break;case 23:B[D]=B[D].trim().replace(/'/g,'"'),L.parseDirective(B[D],"arg_directive");break;case 24:L.parseDirective("}%%","close_directive","pie");break}},table:[{3:1,4:2,5:3,6:e,21:8,26:r,27:n,28:i,29:a},{1:[3]},{3:10,4:2,5:3,6:e,21:8,26:r,27:n,28:i,29:a},{3:11,4:2,5:3,6:e,21:8,26:r,27:n,28:i,29:a},t(s,o,{7:12,8:[1,13]}),t(l,[2,18]),t(l,[2,19]),t(l,[2,20]),{22:14,30:[1,15]},{30:[2,21]},{1:[2,1]},{1:[2,2]},t(u,h,{21:8,9:16,10:17,5:24,1:[2,3],11:d,13:f,15:p,17:m,19:_,20:y,29:a}),t(s,o,{7:25}),{23:26,24:[1,27],32:b},t([24,32],[2,22]),t(s,[2,6]),{4:29,26:r,27:n,28:i},{12:[1,30]},{14:[1,31]},{16:[1,32]},{18:[1,33]},t(u,[2,13]),t(u,[2,14]),t(u,[2,15]),t(u,h,{21:8,9:16,10:17,5:24,1:[2,4],11:d,13:f,15:p,17:m,19:_,20:y,29:a}),t(x,[2,16]),{25:34,31:[1,35]},t(x,[2,24]),t(s,[2,7]),t(u,[2,9]),t(u,[2,10]),t(u,[2,11]),t(u,[2,12]),{23:36,32:b},{32:[2,23]},t(x,[2,17])],defaultActions:{9:[2,21],10:[2,1],11:[2,2],35:[2,23]},parseError:function(S,R){if(R.recoverable)this.trace(S);else{var A=new Error(S);throw A.hash=R,A}},parse:function(S){var R=this,A=[0],L=[],v=[null],B=[],w=this.table,D="",N=0,z=0,X=2,ct=1,J=B.slice.call(arguments,1),Y=Object.create(this.lexer),$={yy:{}};for(var lt in this.yy)Object.prototype.hasOwnProperty.call(this.yy,lt)&&($.yy[lt]=this.yy[lt]);Y.setInput(S,$.yy),$.yy.lexer=Y,$.yy.parser=this,typeof Y.yylloc>"u"&&(Y.yylloc={});var ut=Y.yylloc;B.push(ut);var W=Y.options&&Y.options.ranges;typeof $.yy.parseError=="function"?this.parseError=$.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function tt(){var et;return et=L.pop()||Y.lex()||ct,typeof et!="number"&&(et instanceof Array&&(L=et,et=L.pop()),et=R.symbols_[et]||et),et}for(var K,it,Z,V,Q={},q,U,F,j;;){if(it=A[A.length-1],this.defaultActions[it]?Z=this.defaultActions[it]:((K===null||typeof K>"u")&&(K=tt()),Z=w[it]&&w[it][K]),typeof Z>"u"||!Z.length||!Z[0]){var P="";j=[];for(q in w[it])this.terminals_[q]&&q>X&&j.push("'"+this.terminals_[q]+"'");Y.showPosition?P="Parse error on line "+(N+1)+`: +`+Y.showPosition()+` +Expecting `+j.join(", ")+", got '"+(this.terminals_[K]||K)+"'":P="Parse error on line "+(N+1)+": Unexpected "+(K==ct?"end of input":"'"+(this.terminals_[K]||K)+"'"),this.parseError(P,{text:Y.match,token:this.terminals_[K]||K,line:Y.yylineno,loc:ut,expected:j})}if(Z[0]instanceof Array&&Z.length>1)throw new Error("Parse Error: multiple actions possible at state: "+it+", token: "+K);switch(Z[0]){case 1:A.push(K),v.push(Y.yytext),B.push(Y.yylloc),A.push(Z[1]),K=null,z=Y.yyleng,D=Y.yytext,N=Y.yylineno,ut=Y.yylloc;break;case 2:if(U=this.productions_[Z[1]][1],Q.$=v[v.length-U],Q._$={first_line:B[B.length-(U||1)].first_line,last_line:B[B.length-1].last_line,first_column:B[B.length-(U||1)].first_column,last_column:B[B.length-1].last_column},W&&(Q._$.range=[B[B.length-(U||1)].range[0],B[B.length-1].range[1]]),V=this.performAction.apply(Q,[D,z,N,$.yy,Z[1],v,B].concat(J)),typeof V<"u")return V;U&&(A=A.slice(0,-1*U*2),v=v.slice(0,-1*U),B=B.slice(0,-1*U)),A.push(this.productions_[Z[1]][0]),v.push(Q.$),B.push(Q._$),F=w[A[A.length-2]][A[A.length-1]],A.push(F);break;case 3:return!0}}return!0}},T=function(){var M={EOF:1,parseError:function(R,A){if(this.yy.parser)this.yy.parser.parseError(R,A);else throw new Error(R)},setInput:function(S,R){return this.yy=R||this.yy||{},this._input=S,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var S=this._input[0];this.yytext+=S,this.yyleng++,this.offset++,this.match+=S,this.matched+=S;var R=S.match(/(?:\r\n?|\n).*/g);return R?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),S},unput:function(S){var R=S.length,A=S.split(/(?:\r\n?|\n)/g);this._input=S+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-R),this.offset-=R;var L=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),A.length-1&&(this.yylineno-=A.length-1);var v=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:A?(A.length===L.length?this.yylloc.first_column:0)+L[L.length-A.length].length-A[0].length:this.yylloc.first_column-R},this.options.ranges&&(this.yylloc.range=[v[0],v[0]+this.yyleng-R]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(S){this.unput(this.match.slice(S))},pastInput:function(){var S=this.matched.substr(0,this.matched.length-this.match.length);return(S.length>20?"...":"")+S.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var S=this.match;return S.length<20&&(S+=this._input.substr(0,20-S.length)),(S.substr(0,20)+(S.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var S=this.pastInput(),R=new Array(S.length+1).join("-");return S+this.upcomingInput()+` +`+R+"^"},test_match:function(S,R){var A,L,v;if(this.options.backtrack_lexer&&(v={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(v.yylloc.range=this.yylloc.range.slice(0))),L=S[0].match(/(?:\r\n?|\n).*/g),L&&(this.yylineno+=L.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:L?L[L.length-1].length-L[L.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+S[0].length},this.yytext+=S[0],this.match+=S[0],this.matches=S,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(S[0].length),this.matched+=S[0],A=this.performAction.call(this,this.yy,this,R,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),A)return A;if(this._backtrack){for(var B in v)this[B]=v[B];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var S,R,A,L;this._more||(this.yytext="",this.match="");for(var v=this._currentRules(),B=0;B<v.length;B++)if(A=this._input.match(this.rules[v[B]]),A&&(!R||A[0].length>R[0].length)){if(R=A,L=B,this.options.backtrack_lexer){if(S=this.test_match(A,v[B]),S!==!1)return S;if(this._backtrack){R=!1;continue}else return!1}else if(!this.options.flex)break}return R?(S=this.test_match(R,v[L]),S!==!1?S:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var R=this.next();return R||this.lex()},begin:function(R){this.conditionStack.push(R)},popState:function(){var R=this.conditionStack.length-1;return R>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(R){return R=this.conditionStack.length-1-Math.abs(R||0),R>=0?this.conditionStack[R]:"INITIAL"},pushState:function(R){this.begin(R)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(R,A,L,v){switch(L){case 0:return this.begin("open_directive"),29;case 1:return this.begin("type_directive"),30;case 2:return this.popState(),this.begin("arg_directive"),24;case 3:return this.popState(),this.popState(),32;case 4:return 31;case 5:break;case 6:break;case 7:return 26;case 8:break;case 9:break;case 10:return this.begin("title"),13;case 11:return this.popState(),"title_value";case 12:return this.begin("acc_title"),15;case 13:return this.popState(),"acc_title_value";case 14:return this.begin("acc_descr"),17;case 15:return this.popState(),"acc_descr_value";case 16:this.begin("acc_descr_multiline");break;case 17:this.popState();break;case 18:return"acc_descr_multiline_value";case 19:this.begin("string");break;case 20:this.popState();break;case 21:return"txt";case 22:return 6;case 23:return 8;case 24:return"value";case 25:return 28}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n\r]+)/i,/^(?:%%[^\n]*)/i,/^(?:[\s]+)/i,/^(?:title\b)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accTitle\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*\{\s*)/i,/^(?:[\}])/i,/^(?:[^\}]*)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:pie\b)/i,/^(?:showData\b)/i,/^(?::[\s]*[\d]+(?:\.[\d]+)?)/i,/^(?:$)/i],conditions:{acc_descr_multiline:{rules:[17,18],inclusive:!1},acc_descr:{rules:[15],inclusive:!1},acc_title:{rules:[13],inclusive:!1},close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},title:{rules:[11],inclusive:!1},string:{rules:[20,21],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,12,14,16,19,22,23,24,25],inclusive:!0}}};return M}();k.lexer=T;function C(){this.yy={}}return C.prototype=k,k.Parser=C,new C}();V4.parser=V4;const sit=t=>t.match(/^\s*pie/)!==null;let c0={},z4=!1;const oit={parseDirective:function(t,e,r){Xe.parseDirective(this,t,e,r)},getConfig:()=>nt().pie,addSection:function(t,e){t=pe.sanitizeText(t,nt()),typeof c0[t]>"u"&&(c0[t]=e,H.debug("Added new section :",t))},getSections:()=>c0,cleanupValue:function(t){return t.substring(0,1)===":"&&(t=t.substring(1).trim()),Number(t.trim())},clear:function(){c0={},z4=!1,ci()},setAccTitle:Yn,getAccTitle:ui,setDiagramTitle:c1,getDiagramTitle:u1,setShowData:function(t){z4=t},getShowData:function(){return z4},getAccDescription:fi,setAccDescription:hi};let ga=nt(),ya;const lu=450,lit={draw:(t,e,r,n)=>{try{ga=nt(),H.debug(`Rendering info diagram +`+t);const b=nt().securityLevel;let x;b==="sandbox"&&(x=St("#i"+e));const k=St(b==="sandbox"?x.nodes()[0].contentDocument.body:"body"),T=b==="sandbox"?x.nodes()[0].contentDocument:document;n.db.clear(),n.parser.parse(t),H.debug("Parsed info diagram");const C=T.getElementById(e);ya=C.parentElement.offsetWidth,typeof ya>"u"&&(ya=1200),typeof ga.useWidth<"u"&&(ya=ga.useWidth),typeof ga.pie.useWidth<"u"&&(ya=ga.pie.useWidth);const M=k.select("#"+e);li(M,lu,ya,ga.pie.useMaxWidth),bn(n.db,M,e),C.setAttribute("viewBox","0 0 "+ya+" "+lu);var i=40,a=18,s=4,o=Math.min(ya,lu)/2-i,l=M.append("g").attr("transform","translate("+ya/2+","+lu/2+")"),u=n.db.getSections(),h=0;Object.keys(u).forEach(function(R){h+=u[R]});const S=ga.themeVariables;var d=[S.pie1,S.pie2,S.pie3,S.pie4,S.pie5,S.pie6,S.pie7,S.pie8,S.pie9,S.pie10,S.pie11,S.pie12],f=nf().range(d),p=B7().value(function(R){return R[1]}),m=p(Object.entries(u)),_=yf().innerRadius(0).outerRadius(o);l.selectAll("mySlices").data(m).enter().append("path").attr("d",_).attr("fill",function(R){return f(R.data[0])}).attr("class","pieCircle"),l.selectAll("mySlices").data(m).enter().append("text").text(function(R){return(R.data[1]/h*100).toFixed(0)+"%"}).attr("transform",function(R){return"translate("+_.centroid(R)+")"}).style("text-anchor","middle").attr("class","slice"),l.append("text").text(n.db.getDiagramTitle()).attr("x",0).attr("y",-(lu-50)/2).attr("class","pieTitleText");var y=l.selectAll(".legend").data(f.domain()).enter().append("g").attr("class","legend").attr("transform",function(R,A){var L=a+s,v=L*f.domain().length/2,B=12*a,w=A*L-v;return"translate("+B+","+w+")"});y.append("rect").attr("width",a).attr("height",a).style("fill",f).style("stroke",f),y.data(m).append("text").attr("x",a+s).attr("y",a-s).text(function(R){return n.db.getShowData()||ga.showData||ga.pie.showData?R.data[0]+" ["+R.data[1]+"]":R.data[0]})}catch(b){H.error("Error while rendering info diagram"),H.error(b)}}};var Y4=function(){var t=function(it,Z,V,Q){for(V=V||{},Q=it.length;Q--;V[it[Q]]=Z);return V},e=[1,3],r=[1,5],n=[1,6],i=[1,7],a=[1,8],s=[5,6,8,14,16,18,19,40,41,42,43,44,45,53,71,72],o=[1,22],l=[2,13],u=[1,26],h=[1,27],d=[1,28],f=[1,29],p=[1,30],m=[1,31],_=[1,24],y=[1,32],b=[1,33],x=[1,36],k=[71,72],T=[5,8,14,16,18,19,40,41,42,43,44,45,53,60,62,71,72],C=[1,56],M=[1,57],S=[1,58],R=[1,59],A=[1,60],L=[1,61],v=[1,62],B=[62,63],w=[1,74],D=[1,70],N=[1,71],z=[1,72],X=[1,73],ct=[1,75],J=[1,79],Y=[1,80],$=[1,77],lt=[1,78],ut=[5,8,14,16,18,19,40,41,42,43,44,45,53,71,72],W={trace:function(){},yy:{},symbols_:{error:2,start:3,directive:4,NEWLINE:5,RD:6,diagram:7,EOF:8,openDirective:9,typeDirective:10,closeDirective:11,":":12,argDirective:13,acc_title:14,acc_title_value:15,acc_descr:16,acc_descr_value:17,acc_descr_multiline_value:18,open_directive:19,type_directive:20,arg_directive:21,close_directive:22,requirementDef:23,elementDef:24,relationshipDef:25,requirementType:26,requirementName:27,STRUCT_START:28,requirementBody:29,ID:30,COLONSEP:31,id:32,TEXT:33,text:34,RISK:35,riskLevel:36,VERIFYMTHD:37,verifyType:38,STRUCT_STOP:39,REQUIREMENT:40,FUNCTIONAL_REQUIREMENT:41,INTERFACE_REQUIREMENT:42,PERFORMANCE_REQUIREMENT:43,PHYSICAL_REQUIREMENT:44,DESIGN_CONSTRAINT:45,LOW_RISK:46,MED_RISK:47,HIGH_RISK:48,VERIFY_ANALYSIS:49,VERIFY_DEMONSTRATION:50,VERIFY_INSPECTION:51,VERIFY_TEST:52,ELEMENT:53,elementName:54,elementBody:55,TYPE:56,type:57,DOCREF:58,ref:59,END_ARROW_L:60,relationship:61,LINE:62,END_ARROW_R:63,CONTAINS:64,COPIES:65,DERIVES:66,SATISFIES:67,VERIFIES:68,REFINES:69,TRACES:70,unqString:71,qString:72,$accept:0,$end:1},terminals_:{2:"error",5:"NEWLINE",6:"RD",8:"EOF",12:":",14:"acc_title",15:"acc_title_value",16:"acc_descr",17:"acc_descr_value",18:"acc_descr_multiline_value",19:"open_directive",20:"type_directive",21:"arg_directive",22:"close_directive",28:"STRUCT_START",30:"ID",31:"COLONSEP",33:"TEXT",35:"RISK",37:"VERIFYMTHD",39:"STRUCT_STOP",40:"REQUIREMENT",41:"FUNCTIONAL_REQUIREMENT",42:"INTERFACE_REQUIREMENT",43:"PERFORMANCE_REQUIREMENT",44:"PHYSICAL_REQUIREMENT",45:"DESIGN_CONSTRAINT",46:"LOW_RISK",47:"MED_RISK",48:"HIGH_RISK",49:"VERIFY_ANALYSIS",50:"VERIFY_DEMONSTRATION",51:"VERIFY_INSPECTION",52:"VERIFY_TEST",53:"ELEMENT",56:"TYPE",58:"DOCREF",60:"END_ARROW_L",62:"LINE",63:"END_ARROW_R",64:"CONTAINS",65:"COPIES",66:"DERIVES",67:"SATISFIES",68:"VERIFIES",69:"REFINES",70:"TRACES",71:"unqString",72:"qString"},productions_:[0,[3,3],[3,2],[3,4],[4,3],[4,5],[4,2],[4,2],[4,1],[9,1],[10,1],[13,1],[11,1],[7,0],[7,2],[7,2],[7,2],[7,2],[7,2],[23,5],[29,5],[29,5],[29,5],[29,5],[29,2],[29,1],[26,1],[26,1],[26,1],[26,1],[26,1],[26,1],[36,1],[36,1],[36,1],[38,1],[38,1],[38,1],[38,1],[24,5],[55,5],[55,5],[55,2],[55,1],[25,5],[25,5],[61,1],[61,1],[61,1],[61,1],[61,1],[61,1],[61,1],[27,1],[27,1],[32,1],[32,1],[34,1],[34,1],[54,1],[54,1],[57,1],[57,1],[59,1],[59,1]],performAction:function(Z,V,Q,q,U,F,j){var P=F.length-1;switch(U){case 6:this.$=F[P].trim(),q.setAccTitle(this.$);break;case 7:case 8:this.$=F[P].trim(),q.setAccDescription(this.$);break;case 9:q.parseDirective("%%{","open_directive");break;case 10:q.parseDirective(F[P],"type_directive");break;case 11:F[P]=F[P].trim().replace(/'/g,'"'),q.parseDirective(F[P],"arg_directive");break;case 12:q.parseDirective("}%%","close_directive","pie");break;case 13:this.$=[];break;case 19:q.addRequirement(F[P-3],F[P-4]);break;case 20:q.setNewReqId(F[P-2]);break;case 21:q.setNewReqText(F[P-2]);break;case 22:q.setNewReqRisk(F[P-2]);break;case 23:q.setNewReqVerifyMethod(F[P-2]);break;case 26:this.$=q.RequirementType.REQUIREMENT;break;case 27:this.$=q.RequirementType.FUNCTIONAL_REQUIREMENT;break;case 28:this.$=q.RequirementType.INTERFACE_REQUIREMENT;break;case 29:this.$=q.RequirementType.PERFORMANCE_REQUIREMENT;break;case 30:this.$=q.RequirementType.PHYSICAL_REQUIREMENT;break;case 31:this.$=q.RequirementType.DESIGN_CONSTRAINT;break;case 32:this.$=q.RiskLevel.LOW_RISK;break;case 33:this.$=q.RiskLevel.MED_RISK;break;case 34:this.$=q.RiskLevel.HIGH_RISK;break;case 35:this.$=q.VerifyType.VERIFY_ANALYSIS;break;case 36:this.$=q.VerifyType.VERIFY_DEMONSTRATION;break;case 37:this.$=q.VerifyType.VERIFY_INSPECTION;break;case 38:this.$=q.VerifyType.VERIFY_TEST;break;case 39:q.addElement(F[P-3]);break;case 40:q.setNewElementType(F[P-2]);break;case 41:q.setNewElementDocRef(F[P-2]);break;case 44:q.addRelationship(F[P-2],F[P],F[P-4]);break;case 45:q.addRelationship(F[P-2],F[P-4],F[P]);break;case 46:this.$=q.Relationships.CONTAINS;break;case 47:this.$=q.Relationships.COPIES;break;case 48:this.$=q.Relationships.DERIVES;break;case 49:this.$=q.Relationships.SATISFIES;break;case 50:this.$=q.Relationships.VERIFIES;break;case 51:this.$=q.Relationships.REFINES;break;case 52:this.$=q.Relationships.TRACES;break}},table:[{3:1,4:2,6:e,9:4,14:r,16:n,18:i,19:a},{1:[3]},{3:10,4:2,5:[1,9],6:e,9:4,14:r,16:n,18:i,19:a},{5:[1,11]},{10:12,20:[1,13]},{15:[1,14]},{17:[1,15]},t(s,[2,8]),{20:[2,9]},{3:16,4:2,6:e,9:4,14:r,16:n,18:i,19:a},{1:[2,2]},{4:21,5:o,7:17,8:l,9:4,14:r,16:n,18:i,19:a,23:18,24:19,25:20,26:23,32:25,40:u,41:h,42:d,43:f,44:p,45:m,53:_,71:y,72:b},{11:34,12:[1,35],22:x},t([12,22],[2,10]),t(s,[2,6]),t(s,[2,7]),{1:[2,1]},{8:[1,37]},{4:21,5:o,7:38,8:l,9:4,14:r,16:n,18:i,19:a,23:18,24:19,25:20,26:23,32:25,40:u,41:h,42:d,43:f,44:p,45:m,53:_,71:y,72:b},{4:21,5:o,7:39,8:l,9:4,14:r,16:n,18:i,19:a,23:18,24:19,25:20,26:23,32:25,40:u,41:h,42:d,43:f,44:p,45:m,53:_,71:y,72:b},{4:21,5:o,7:40,8:l,9:4,14:r,16:n,18:i,19:a,23:18,24:19,25:20,26:23,32:25,40:u,41:h,42:d,43:f,44:p,45:m,53:_,71:y,72:b},{4:21,5:o,7:41,8:l,9:4,14:r,16:n,18:i,19:a,23:18,24:19,25:20,26:23,32:25,40:u,41:h,42:d,43:f,44:p,45:m,53:_,71:y,72:b},{4:21,5:o,7:42,8:l,9:4,14:r,16:n,18:i,19:a,23:18,24:19,25:20,26:23,32:25,40:u,41:h,42:d,43:f,44:p,45:m,53:_,71:y,72:b},{27:43,71:[1,44],72:[1,45]},{54:46,71:[1,47],72:[1,48]},{60:[1,49],62:[1,50]},t(k,[2,26]),t(k,[2,27]),t(k,[2,28]),t(k,[2,29]),t(k,[2,30]),t(k,[2,31]),t(T,[2,55]),t(T,[2,56]),t(s,[2,4]),{13:51,21:[1,52]},t(s,[2,12]),{1:[2,3]},{8:[2,14]},{8:[2,15]},{8:[2,16]},{8:[2,17]},{8:[2,18]},{28:[1,53]},{28:[2,53]},{28:[2,54]},{28:[1,54]},{28:[2,59]},{28:[2,60]},{61:55,64:C,65:M,66:S,67:R,68:A,69:L,70:v},{61:63,64:C,65:M,66:S,67:R,68:A,69:L,70:v},{11:64,22:x},{22:[2,11]},{5:[1,65]},{5:[1,66]},{62:[1,67]},t(B,[2,46]),t(B,[2,47]),t(B,[2,48]),t(B,[2,49]),t(B,[2,50]),t(B,[2,51]),t(B,[2,52]),{63:[1,68]},t(s,[2,5]),{5:w,29:69,30:D,33:N,35:z,37:X,39:ct},{5:J,39:Y,55:76,56:$,58:lt},{32:81,71:y,72:b},{32:82,71:y,72:b},t(ut,[2,19]),{31:[1,83]},{31:[1,84]},{31:[1,85]},{31:[1,86]},{5:w,29:87,30:D,33:N,35:z,37:X,39:ct},t(ut,[2,25]),t(ut,[2,39]),{31:[1,88]},{31:[1,89]},{5:J,39:Y,55:90,56:$,58:lt},t(ut,[2,43]),t(ut,[2,44]),t(ut,[2,45]),{32:91,71:y,72:b},{34:92,71:[1,93],72:[1,94]},{36:95,46:[1,96],47:[1,97],48:[1,98]},{38:99,49:[1,100],50:[1,101],51:[1,102],52:[1,103]},t(ut,[2,24]),{57:104,71:[1,105],72:[1,106]},{59:107,71:[1,108],72:[1,109]},t(ut,[2,42]),{5:[1,110]},{5:[1,111]},{5:[2,57]},{5:[2,58]},{5:[1,112]},{5:[2,32]},{5:[2,33]},{5:[2,34]},{5:[1,113]},{5:[2,35]},{5:[2,36]},{5:[2,37]},{5:[2,38]},{5:[1,114]},{5:[2,61]},{5:[2,62]},{5:[1,115]},{5:[2,63]},{5:[2,64]},{5:w,29:116,30:D,33:N,35:z,37:X,39:ct},{5:w,29:117,30:D,33:N,35:z,37:X,39:ct},{5:w,29:118,30:D,33:N,35:z,37:X,39:ct},{5:w,29:119,30:D,33:N,35:z,37:X,39:ct},{5:J,39:Y,55:120,56:$,58:lt},{5:J,39:Y,55:121,56:$,58:lt},t(ut,[2,20]),t(ut,[2,21]),t(ut,[2,22]),t(ut,[2,23]),t(ut,[2,40]),t(ut,[2,41])],defaultActions:{8:[2,9],10:[2,2],16:[2,1],37:[2,3],38:[2,14],39:[2,15],40:[2,16],41:[2,17],42:[2,18],44:[2,53],45:[2,54],47:[2,59],48:[2,60],52:[2,11],93:[2,57],94:[2,58],96:[2,32],97:[2,33],98:[2,34],100:[2,35],101:[2,36],102:[2,37],103:[2,38],105:[2,61],106:[2,62],108:[2,63],109:[2,64]},parseError:function(Z,V){if(V.recoverable)this.trace(Z);else{var Q=new Error(Z);throw Q.hash=V,Q}},parse:function(Z){var V=this,Q=[0],q=[],U=[null],F=[],j=this.table,P="",et=0,at=0,It=2,Lt=1,Rt=F.slice.call(arguments,1),Ct=Object.create(this.lexer),pt={yy:{}};for(var mt in this.yy)Object.prototype.hasOwnProperty.call(this.yy,mt)&&(pt.yy[mt]=this.yy[mt]);Ct.setInput(Z,pt.yy),pt.yy.lexer=Ct,pt.yy.parser=this,typeof Ct.yylloc>"u"&&(Ct.yylloc={});var vt=Ct.yylloc;F.push(vt);var Tt=Ct.options&&Ct.options.ranges;typeof pt.yy.parseError=="function"?this.parseError=pt.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function ft(){var bt;return bt=q.pop()||Ct.lex()||Lt,typeof bt!="number"&&(bt instanceof Array&&(q=bt,bt=q.pop()),bt=V.symbols_[bt]||bt),bt}for(var le,Dt,Gt,$t,Qt={},we,jt,Ft,zt;;){if(Dt=Q[Q.length-1],this.defaultActions[Dt]?Gt=this.defaultActions[Dt]:((le===null||typeof le>"u")&&(le=ft()),Gt=j[Dt]&&j[Dt][le]),typeof Gt>"u"||!Gt.length||!Gt[0]){var wt="";zt=[];for(we in j[Dt])this.terminals_[we]&&we>It&&zt.push("'"+this.terminals_[we]+"'");Ct.showPosition?wt="Parse error on line "+(et+1)+`: +`+Ct.showPosition()+` +Expecting `+zt.join(", ")+", got '"+(this.terminals_[le]||le)+"'":wt="Parse error on line "+(et+1)+": Unexpected "+(le==Lt?"end of input":"'"+(this.terminals_[le]||le)+"'"),this.parseError(wt,{text:Ct.match,token:this.terminals_[le]||le,line:Ct.yylineno,loc:vt,expected:zt})}if(Gt[0]instanceof Array&&Gt.length>1)throw new Error("Parse Error: multiple actions possible at state: "+Dt+", token: "+le);switch(Gt[0]){case 1:Q.push(le),U.push(Ct.yytext),F.push(Ct.yylloc),Q.push(Gt[1]),le=null,at=Ct.yyleng,P=Ct.yytext,et=Ct.yylineno,vt=Ct.yylloc;break;case 2:if(jt=this.productions_[Gt[1]][1],Qt.$=U[U.length-jt],Qt._$={first_line:F[F.length-(jt||1)].first_line,last_line:F[F.length-1].last_line,first_column:F[F.length-(jt||1)].first_column,last_column:F[F.length-1].last_column},Tt&&(Qt._$.range=[F[F.length-(jt||1)].range[0],F[F.length-1].range[1]]),$t=this.performAction.apply(Qt,[P,at,et,pt.yy,Gt[1],U,F].concat(Rt)),typeof $t<"u")return $t;jt&&(Q=Q.slice(0,-1*jt*2),U=U.slice(0,-1*jt),F=F.slice(0,-1*jt)),Q.push(this.productions_[Gt[1]][0]),U.push(Qt.$),F.push(Qt._$),Ft=j[Q[Q.length-2]][Q[Q.length-1]],Q.push(Ft);break;case 3:return!0}}return!0}},tt=function(){var it={EOF:1,parseError:function(V,Q){if(this.yy.parser)this.yy.parser.parseError(V,Q);else throw new Error(V)},setInput:function(Z,V){return this.yy=V||this.yy||{},this._input=Z,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var Z=this._input[0];this.yytext+=Z,this.yyleng++,this.offset++,this.match+=Z,this.matched+=Z;var V=Z.match(/(?:\r\n?|\n).*/g);return V?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),Z},unput:function(Z){var V=Z.length,Q=Z.split(/(?:\r\n?|\n)/g);this._input=Z+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-V),this.offset-=V;var q=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),Q.length-1&&(this.yylineno-=Q.length-1);var U=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:Q?(Q.length===q.length?this.yylloc.first_column:0)+q[q.length-Q.length].length-Q[0].length:this.yylloc.first_column-V},this.options.ranges&&(this.yylloc.range=[U[0],U[0]+this.yyleng-V]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(Z){this.unput(this.match.slice(Z))},pastInput:function(){var Z=this.matched.substr(0,this.matched.length-this.match.length);return(Z.length>20?"...":"")+Z.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var Z=this.match;return Z.length<20&&(Z+=this._input.substr(0,20-Z.length)),(Z.substr(0,20)+(Z.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var Z=this.pastInput(),V=new Array(Z.length+1).join("-");return Z+this.upcomingInput()+` +`+V+"^"},test_match:function(Z,V){var Q,q,U;if(this.options.backtrack_lexer&&(U={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(U.yylloc.range=this.yylloc.range.slice(0))),q=Z[0].match(/(?:\r\n?|\n).*/g),q&&(this.yylineno+=q.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:q?q[q.length-1].length-q[q.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+Z[0].length},this.yytext+=Z[0],this.match+=Z[0],this.matches=Z,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(Z[0].length),this.matched+=Z[0],Q=this.performAction.call(this,this.yy,this,V,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),Q)return Q;if(this._backtrack){for(var F in U)this[F]=U[F];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var Z,V,Q,q;this._more||(this.yytext="",this.match="");for(var U=this._currentRules(),F=0;F<U.length;F++)if(Q=this._input.match(this.rules[U[F]]),Q&&(!V||Q[0].length>V[0].length)){if(V=Q,q=F,this.options.backtrack_lexer){if(Z=this.test_match(Q,U[F]),Z!==!1)return Z;if(this._backtrack){V=!1;continue}else return!1}else if(!this.options.flex)break}return V?(Z=this.test_match(V,U[q]),Z!==!1?Z:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var V=this.next();return V||this.lex()},begin:function(V){this.conditionStack.push(V)},popState:function(){var V=this.conditionStack.length-1;return V>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(V){return V=this.conditionStack.length-1-Math.abs(V||0),V>=0?this.conditionStack[V]:"INITIAL"},pushState:function(V){this.begin(V)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(V,Q,q,U){switch(q){case 0:return this.begin("open_directive"),19;case 1:return this.begin("type_directive"),20;case 2:return this.popState(),this.begin("arg_directive"),12;case 3:return this.popState(),this.popState(),22;case 4:return 21;case 5:return"title";case 6:return this.begin("acc_title"),14;case 7:return this.popState(),"acc_title_value";case 8:return this.begin("acc_descr"),16;case 9:return this.popState(),"acc_descr_value";case 10:this.begin("acc_descr_multiline");break;case 11:this.popState();break;case 12:return"acc_descr_multiline_value";case 13:return 5;case 14:break;case 15:break;case 16:break;case 17:return 8;case 18:return 6;case 19:return 28;case 20:return 39;case 21:return 31;case 22:return 30;case 23:return 33;case 24:return 35;case 25:return 37;case 26:return 40;case 27:return 41;case 28:return 42;case 29:return 43;case 30:return 44;case 31:return 45;case 32:return 46;case 33:return 47;case 34:return 48;case 35:return 49;case 36:return 50;case 37:return 51;case 38:return 52;case 39:return 53;case 40:return 64;case 41:return 65;case 42:return 66;case 43:return 67;case 44:return 68;case 45:return 69;case 46:return 70;case 47:return 56;case 48:return 58;case 49:return 60;case 50:return 63;case 51:return 62;case 52:this.begin("string");break;case 53:this.popState();break;case 54:return"qString";case 55:return Q.yytext=Q.yytext.trim(),71}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:title\s[^#\n;]+)/i,/^(?:accTitle\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*\{\s*)/i,/^(?:[\}])/i,/^(?:[^\}]*)/i,/^(?:(\r?\n)+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:$)/i,/^(?:requirementDiagram\b)/i,/^(?:\{)/i,/^(?:\})/i,/^(?::)/i,/^(?:id\b)/i,/^(?:text\b)/i,/^(?:risk\b)/i,/^(?:verifyMethod\b)/i,/^(?:requirement\b)/i,/^(?:functionalRequirement\b)/i,/^(?:interfaceRequirement\b)/i,/^(?:performanceRequirement\b)/i,/^(?:physicalRequirement\b)/i,/^(?:designConstraint\b)/i,/^(?:low\b)/i,/^(?:medium\b)/i,/^(?:high\b)/i,/^(?:analysis\b)/i,/^(?:demonstration\b)/i,/^(?:inspection\b)/i,/^(?:test\b)/i,/^(?:element\b)/i,/^(?:contains\b)/i,/^(?:copies\b)/i,/^(?:derives\b)/i,/^(?:satisfies\b)/i,/^(?:verifies\b)/i,/^(?:refines\b)/i,/^(?:traces\b)/i,/^(?:type\b)/i,/^(?:docref\b)/i,/^(?:<-)/i,/^(?:->)/i,/^(?:-)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[\w][^\r\n\{\<\>\-\=]*)/i],conditions:{acc_descr_multiline:{rules:[11,12],inclusive:!1},acc_descr:{rules:[9],inclusive:!1},acc_title:{rules:[7],inclusive:!1},close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},unqString:{rules:[],inclusive:!1},token:{rules:[],inclusive:!1},string:{rules:[53,54],inclusive:!1},INITIAL:{rules:[0,5,6,8,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,55],inclusive:!0}}};return it}();W.lexer=tt;function K(){this.yy={}}return K.prototype=W,W.Parser=K,new K}();Y4.parser=Y4;const cit=t=>t.match(/^\s*requirement(Diagram)?/)!==null;let U4=[],kn={},cu={},rs={},uu={};const uit={RequirementType:{REQUIREMENT:"Requirement",FUNCTIONAL_REQUIREMENT:"Functional Requirement",INTERFACE_REQUIREMENT:"Interface Requirement",PERFORMANCE_REQUIREMENT:"Performance Requirement",PHYSICAL_REQUIREMENT:"Physical Requirement",DESIGN_CONSTRAINT:"Design Constraint"},RiskLevel:{LOW_RISK:"Low",MED_RISK:"Medium",HIGH_RISK:"High"},VerifyType:{VERIFY_ANALYSIS:"Analysis",VERIFY_DEMONSTRATION:"Demonstration",VERIFY_INSPECTION:"Inspection",VERIFY_TEST:"Test"},Relationships:{CONTAINS:"contains",COPIES:"copies",DERIVES:"derives",SATISFIES:"satisfies",VERIFIES:"verifies",REFINES:"refines",TRACES:"traces"},parseDirective:function(t,e,r){Xe.parseDirective(this,t,e,r)},getConfig:()=>nt().req,addRequirement:(t,e)=>(typeof cu[t]>"u"&&(cu[t]={name:t,type:e,id:kn.id,text:kn.text,risk:kn.risk,verifyMethod:kn.verifyMethod}),kn={},cu[t]),getRequirements:()=>cu,setNewReqId:t=>{typeof kn<"u"&&(kn.id=t)},setNewReqText:t=>{typeof kn<"u"&&(kn.text=t)},setNewReqRisk:t=>{typeof kn<"u"&&(kn.risk=t)},setNewReqVerifyMethod:t=>{typeof kn<"u"&&(kn.verifyMethod=t)},setAccTitle:Yn,getAccTitle:ui,setAccDescription:hi,getAccDescription:fi,addElement:t=>(typeof uu[t]>"u"&&(uu[t]={name:t,type:rs.type,docRef:rs.docRef},H.info("Added new requirement: ",t)),rs={},uu[t]),getElements:()=>uu,setNewElementType:t=>{typeof rs<"u"&&(rs.type=t)},setNewElementDocRef:t=>{typeof rs<"u"&&(rs.docRef=t)},addRelationship:(t,e,r)=>{U4.push({type:t,src:e,dst:r})},getRelationships:()=>U4,clear:()=>{U4=[],kn={},cu={},rs={},uu={},ci()}},W4={CONTAINS:"contains",ARROW:"arrow"},sL={ReqMarkers:W4,insertLineEndings:(t,e)=>{let r=t.append("defs").append("marker").attr("id",W4.CONTAINS+"_line_ending").attr("refX",0).attr("refY",e.line_height/2).attr("markerWidth",e.line_height).attr("markerHeight",e.line_height).attr("orient","auto").append("g");r.append("circle").attr("cx",e.line_height/2).attr("cy",e.line_height/2).attr("r",e.line_height/2).attr("fill","none"),r.append("line").attr("x1",0).attr("x2",e.line_height).attr("y1",e.line_height/2).attr("y2",e.line_height/2).attr("stroke-width",1),r.append("line").attr("y1",0).attr("y2",e.line_height).attr("x1",e.line_height/2).attr("x2",e.line_height/2).attr("stroke-width",1),t.append("defs").append("marker").attr("id",W4.ARROW+"_line_ending").attr("refX",e.line_height).attr("refY",.5*e.line_height).attr("markerWidth",e.line_height).attr("markerHeight",e.line_height).attr("orient","auto").append("path").attr("d",`M0,0 + L${e.line_height},${e.line_height/2} + M${e.line_height},${e.line_height/2} + L0,${e.line_height}`).attr("stroke-width",1)}};let sr={},oL=0;const lL=(t,e)=>t.insert("rect","#"+e).attr("class","req reqBox").attr("x",0).attr("y",0).attr("width",sr.rect_min_width+"px").attr("height",sr.rect_min_height+"px"),cL=(t,e,r)=>{let n=sr.rect_min_width/2,i=t.append("text").attr("class","req reqLabel reqTitle").attr("id",e).attr("x",n).attr("y",sr.rect_padding).attr("dominant-baseline","hanging"),a=0;r.forEach(u=>{a==0?i.append("tspan").attr("text-anchor","middle").attr("x",sr.rect_min_width/2).attr("dy",0).text(u):i.append("tspan").attr("text-anchor","middle").attr("x",sr.rect_min_width/2).attr("dy",sr.line_height*.75).text(u),a++});let s=1.5*sr.rect_padding,o=a*sr.line_height*.75,l=s+o;return t.append("line").attr("class","req-title-line").attr("x1","0").attr("x2",sr.rect_min_width).attr("y1",l).attr("y2",l),{titleNode:i,y:l}},uL=(t,e,r,n)=>{let i=t.append("text").attr("class","req reqLabel").attr("id",e).attr("x",sr.rect_padding).attr("y",n).attr("dominant-baseline","hanging"),a=0;const s=30;let o=[];return r.forEach(l=>{let u=l.length;for(;u>s&&a<3;){let h=l.substring(0,s);l=l.substring(s,l.length),u=l.length,o[o.length]=h,a++}if(a==3){let h=o[o.length-1];o[o.length-1]=h.substring(0,h.length-4)+"..."}else o[o.length]=l;a=0}),o.forEach(l=>{i.append("tspan").attr("x",sr.rect_padding).attr("dy",sr.line_height).text(l)}),i},hit=(t,e,r,n)=>{const i=e.node().getTotalLength(),a=e.node().getPointAtLength(i*.5),s="rel"+oL;oL++;const l=t.append("text").attr("class","req relationshipLabel").attr("id",s).attr("x",a.x).attr("y",a.y).attr("text-anchor","middle").attr("dominant-baseline","middle").text(n).node().getBBox();t.insert("rect","#"+s).attr("class","req reqLabelBox").attr("x",a.x-l.width/2).attr("y",a.y-l.height/2).attr("width",l.width).attr("height",l.height).attr("fill","white").attr("fill-opacity","85%")},fit=function(t,e,r,n,i){const a=r.edge(cl(e.src),cl(e.dst)),s=Ua().x(function(l){return l.x}).y(function(l){return l.y}),o=t.insert("path","#"+n).attr("class","er relationshipLine").attr("d",s(a.points)).attr("fill","none");e.type==i.db.Relationships.CONTAINS?o.attr("marker-start","url("+pe.getUrl(sr.arrowMarkerAbsolute)+"#"+e.type+"_line_ending)"):(o.attr("stroke-dasharray","10,7"),o.attr("marker-end","url("+pe.getUrl(sr.arrowMarkerAbsolute)+"#"+sL.ReqMarkers.ARROW+"_line_ending)")),hit(t,o,sr,`<<${e.type}>>`)},dit=(t,e,r)=>{Object.keys(t).forEach(n=>{let i=t[n];n=cl(n),H.info("Added new requirement: ",n);const a=r.append("g").attr("id",n),s="req-"+n,o=lL(a,s);let l=cL(a,n+"_title",[`<<${i.type}>>`,`${i.name}`]);uL(a,n+"_body",[`Id: ${i.id}`,`Text: ${i.text}`,`Risk: ${i.risk}`,`Verification: ${i.verifyMethod}`],l.y);const u=o.node().getBBox();e.setNode(n,{width:u.width,height:u.height,shape:"rect",id:n})})},pit=(t,e,r)=>{Object.keys(t).forEach(n=>{let i=t[n];const a=cl(n),s=r.append("g").attr("id",a),o="element-"+a,l=lL(s,o);let u=cL(s,o+"_title",["<<Element>>",`${n}`]);uL(s,o+"_body",[`Type: ${i.type||"Not Specified"}`,`Doc Ref: ${i.docRef||"None"}`],u.y);const h=l.node().getBBox();e.setNode(a,{width:h.width,height:h.height,shape:"rect",id:a})})},git=(t,e)=>(t.forEach(function(r){let n=cl(r.src),i=cl(r.dst);e.setEdge(n,i,{relationship:r})}),t),yit=function(t,e){e.nodes().forEach(function(r){typeof r<"u"&&typeof e.node(r)<"u"&&(t.select("#"+r),t.select("#"+r).attr("transform","translate("+(e.node(r).x-e.node(r).width/2)+","+(e.node(r).y-e.node(r).height/2)+" )"))})},cl=t=>t.replace(/\s/g,"").replace(/\./g,"_"),mit={draw:(t,e,r,n)=>{sr=nt().requirement,n.db.clear(),n.parser.parse(t);const i=sr.securityLevel;let a;i==="sandbox"&&(a=St("#i"+e));const o=St(i==="sandbox"?a.nodes()[0].contentDocument.body:"body").select(`[id='${e}']`);sL.insertLineEndings(o,sr);const l=new cr.Graph({multigraph:!1,compound:!1,directed:!0}).setGraph({rankdir:sr.layoutDirection,marginx:20,marginy:20,nodesep:100,edgesep:100,ranksep:100}).setDefaultEdgeLabel(function(){return{}});let u=n.db.getRequirements(),h=n.db.getElements(),d=n.db.getRelationships();dit(u,l,o),pit(h,l,o),git(d,l),Zc.layout(l),yit(o,l),d.forEach(function(y){fit(o,y,l,e,n)});const f=sr.rect_padding,p=o.node().getBBox(),m=p.width+f*2,_=p.height+f*2;li(o,_,m,sr.useMaxWidth),o.attr("viewBox",`${p.x-f} ${p.y-f} ${m} ${_}`),bn(n.db,o,e)}};var H4=function(){var t=function(it,Z,V,Q){for(V=V||{},Q=it.length;Q--;V[it[Q]]=Z);return V},e=[1,2],r=[1,3],n=[1,5],i=[1,7],a=[2,5],s=[1,15],o=[1,17],l=[1,18],u=[1,19],h=[1,21],d=[1,22],f=[1,23],p=[1,29],m=[1,30],_=[1,31],y=[1,32],b=[1,33],x=[1,34],k=[1,35],T=[1,36],C=[1,37],M=[1,38],S=[1,39],R=[1,40],A=[1,43],L=[1,44],v=[1,45],B=[1,46],w=[1,47],D=[1,48],N=[1,51],z=[1,4,5,16,20,22,25,26,32,33,34,36,38,39,40,41,42,43,45,47,49,50,51,52,53,58,59,60,61,69,79],X=[4,5,16,20,22,25,26,32,33,34,36,38,39,40,41,42,43,45,47,49,53,58,59,60,61,69,79],ct=[4,5,16,20,22,25,26,32,33,34,36,38,39,40,41,42,43,45,47,49,52,53,58,59,60,61,69,79],J=[4,5,16,20,22,25,26,32,33,34,36,38,39,40,41,42,43,45,47,49,51,53,58,59,60,61,69,79],Y=[4,5,16,20,22,25,26,32,33,34,36,38,39,40,41,42,43,45,47,49,50,53,58,59,60,61,69,79],$=[67,68,69],lt=[1,121],ut=[1,4,5,7,16,20,22,25,26,32,33,34,36,38,39,40,41,42,43,45,47,49,50,51,52,53,58,59,60,61,69,79],W={trace:function(){},yy:{},symbols_:{error:2,start:3,SPACE:4,NEWLINE:5,directive:6,SD:7,document:8,line:9,statement:10,openDirective:11,typeDirective:12,closeDirective:13,":":14,argDirective:15,participant:16,actor:17,AS:18,restOfLine:19,participant_actor:20,signal:21,autonumber:22,NUM:23,off:24,activate:25,deactivate:26,note_statement:27,links_statement:28,link_statement:29,properties_statement:30,details_statement:31,title:32,legacy_title:33,acc_title:34,acc_title_value:35,acc_descr:36,acc_descr_value:37,acc_descr_multiline_value:38,loop:39,end:40,rect:41,opt:42,alt:43,else_sections:44,par:45,par_sections:46,critical:47,option_sections:48,break:49,option:50,and:51,else:52,note:53,placement:54,text2:55,over:56,actor_pair:57,links:58,link:59,properties:60,details:61,spaceList:62,",":63,left_of:64,right_of:65,signaltype:66,"+":67,"-":68,ACTOR:69,SOLID_OPEN_ARROW:70,DOTTED_OPEN_ARROW:71,SOLID_ARROW:72,DOTTED_ARROW:73,SOLID_CROSS:74,DOTTED_CROSS:75,SOLID_POINT:76,DOTTED_POINT:77,TXT:78,open_directive:79,type_directive:80,arg_directive:81,close_directive:82,$accept:0,$end:1},terminals_:{2:"error",4:"SPACE",5:"NEWLINE",7:"SD",14:":",16:"participant",18:"AS",19:"restOfLine",20:"participant_actor",22:"autonumber",23:"NUM",24:"off",25:"activate",26:"deactivate",32:"title",33:"legacy_title",34:"acc_title",35:"acc_title_value",36:"acc_descr",37:"acc_descr_value",38:"acc_descr_multiline_value",39:"loop",40:"end",41:"rect",42:"opt",43:"alt",45:"par",47:"critical",49:"break",50:"option",51:"and",52:"else",53:"note",56:"over",58:"links",59:"link",60:"properties",61:"details",63:",",64:"left_of",65:"right_of",67:"+",68:"-",69:"ACTOR",70:"SOLID_OPEN_ARROW",71:"DOTTED_OPEN_ARROW",72:"SOLID_ARROW",73:"DOTTED_ARROW",74:"SOLID_CROSS",75:"DOTTED_CROSS",76:"SOLID_POINT",77:"DOTTED_POINT",78:"TXT",79:"open_directive",80:"type_directive",81:"arg_directive",82:"close_directive"},productions_:[0,[3,2],[3,2],[3,2],[3,2],[8,0],[8,2],[9,2],[9,1],[9,1],[6,4],[6,6],[10,5],[10,3],[10,5],[10,3],[10,2],[10,4],[10,3],[10,3],[10,2],[10,3],[10,3],[10,2],[10,2],[10,2],[10,2],[10,2],[10,1],[10,1],[10,2],[10,2],[10,1],[10,4],[10,4],[10,4],[10,4],[10,4],[10,4],[10,4],[10,1],[48,1],[48,4],[46,1],[46,4],[44,1],[44,4],[27,4],[27,4],[28,3],[29,3],[30,3],[31,3],[62,2],[62,1],[57,3],[57,1],[54,1],[54,1],[21,5],[21,5],[21,4],[17,1],[66,1],[66,1],[66,1],[66,1],[66,1],[66,1],[66,1],[66,1],[55,1],[11,1],[12,1],[15,1],[13,1]],performAction:function(Z,V,Q,q,U,F,j){var P=F.length-1;switch(U){case 4:return q.apply(F[P]),F[P];case 5:this.$=[];break;case 6:F[P-1].push(F[P]),this.$=F[P-1];break;case 7:case 8:this.$=F[P];break;case 9:this.$=[];break;case 12:F[P-3].type="addParticipant",F[P-3].description=q.parseMessage(F[P-1]),this.$=F[P-3];break;case 13:F[P-1].type="addParticipant",this.$=F[P-1];break;case 14:F[P-3].type="addActor",F[P-3].description=q.parseMessage(F[P-1]),this.$=F[P-3];break;case 15:F[P-1].type="addActor",this.$=F[P-1];break;case 17:this.$={type:"sequenceIndex",sequenceIndex:Number(F[P-2]),sequenceIndexStep:Number(F[P-1]),sequenceVisible:!0,signalType:q.LINETYPE.AUTONUMBER};break;case 18:this.$={type:"sequenceIndex",sequenceIndex:Number(F[P-1]),sequenceIndexStep:1,sequenceVisible:!0,signalType:q.LINETYPE.AUTONUMBER};break;case 19:this.$={type:"sequenceIndex",sequenceVisible:!1,signalType:q.LINETYPE.AUTONUMBER};break;case 20:this.$={type:"sequenceIndex",sequenceVisible:!0,signalType:q.LINETYPE.AUTONUMBER};break;case 21:this.$={type:"activeStart",signalType:q.LINETYPE.ACTIVE_START,actor:F[P-1]};break;case 22:this.$={type:"activeEnd",signalType:q.LINETYPE.ACTIVE_END,actor:F[P-1]};break;case 28:q.setDiagramTitle(F[P].substring(6)),this.$=F[P].substring(6);break;case 29:q.setDiagramTitle(F[P].substring(7)),this.$=F[P].substring(7);break;case 30:this.$=F[P].trim(),q.setAccTitle(this.$);break;case 31:case 32:this.$=F[P].trim(),q.setAccDescription(this.$);break;case 33:F[P-1].unshift({type:"loopStart",loopText:q.parseMessage(F[P-2]),signalType:q.LINETYPE.LOOP_START}),F[P-1].push({type:"loopEnd",loopText:F[P-2],signalType:q.LINETYPE.LOOP_END}),this.$=F[P-1];break;case 34:F[P-1].unshift({type:"rectStart",color:q.parseMessage(F[P-2]),signalType:q.LINETYPE.RECT_START}),F[P-1].push({type:"rectEnd",color:q.parseMessage(F[P-2]),signalType:q.LINETYPE.RECT_END}),this.$=F[P-1];break;case 35:F[P-1].unshift({type:"optStart",optText:q.parseMessage(F[P-2]),signalType:q.LINETYPE.OPT_START}),F[P-1].push({type:"optEnd",optText:q.parseMessage(F[P-2]),signalType:q.LINETYPE.OPT_END}),this.$=F[P-1];break;case 36:F[P-1].unshift({type:"altStart",altText:q.parseMessage(F[P-2]),signalType:q.LINETYPE.ALT_START}),F[P-1].push({type:"altEnd",signalType:q.LINETYPE.ALT_END}),this.$=F[P-1];break;case 37:F[P-1].unshift({type:"parStart",parText:q.parseMessage(F[P-2]),signalType:q.LINETYPE.PAR_START}),F[P-1].push({type:"parEnd",signalType:q.LINETYPE.PAR_END}),this.$=F[P-1];break;case 38:F[P-1].unshift({type:"criticalStart",criticalText:q.parseMessage(F[P-2]),signalType:q.LINETYPE.CRITICAL_START}),F[P-1].push({type:"criticalEnd",signalType:q.LINETYPE.CRITICAL_END}),this.$=F[P-1];break;case 39:F[P-1].unshift({type:"breakStart",breakText:q.parseMessage(F[P-2]),signalType:q.LINETYPE.BREAK_START}),F[P-1].push({type:"breakEnd",optText:q.parseMessage(F[P-2]),signalType:q.LINETYPE.BREAK_END}),this.$=F[P-1];break;case 42:this.$=F[P-3].concat([{type:"option",optionText:q.parseMessage(F[P-1]),signalType:q.LINETYPE.CRITICAL_OPTION},F[P]]);break;case 44:this.$=F[P-3].concat([{type:"and",parText:q.parseMessage(F[P-1]),signalType:q.LINETYPE.PAR_AND},F[P]]);break;case 46:this.$=F[P-3].concat([{type:"else",altText:q.parseMessage(F[P-1]),signalType:q.LINETYPE.ALT_ELSE},F[P]]);break;case 47:this.$=[F[P-1],{type:"addNote",placement:F[P-2],actor:F[P-1].actor,text:F[P]}];break;case 48:F[P-2]=[].concat(F[P-1],F[P-1]).slice(0,2),F[P-2][0]=F[P-2][0].actor,F[P-2][1]=F[P-2][1].actor,this.$=[F[P-1],{type:"addNote",placement:q.PLACEMENT.OVER,actor:F[P-2].slice(0,2),text:F[P]}];break;case 49:this.$=[F[P-1],{type:"addLinks",actor:F[P-1].actor,text:F[P]}];break;case 50:this.$=[F[P-1],{type:"addALink",actor:F[P-1].actor,text:F[P]}];break;case 51:this.$=[F[P-1],{type:"addProperties",actor:F[P-1].actor,text:F[P]}];break;case 52:this.$=[F[P-1],{type:"addDetails",actor:F[P-1].actor,text:F[P]}];break;case 55:this.$=[F[P-2],F[P]];break;case 56:this.$=F[P];break;case 57:this.$=q.PLACEMENT.LEFTOF;break;case 58:this.$=q.PLACEMENT.RIGHTOF;break;case 59:this.$=[F[P-4],F[P-1],{type:"addMessage",from:F[P-4].actor,to:F[P-1].actor,signalType:F[P-3],msg:F[P]},{type:"activeStart",signalType:q.LINETYPE.ACTIVE_START,actor:F[P-1]}];break;case 60:this.$=[F[P-4],F[P-1],{type:"addMessage",from:F[P-4].actor,to:F[P-1].actor,signalType:F[P-3],msg:F[P]},{type:"activeEnd",signalType:q.LINETYPE.ACTIVE_END,actor:F[P-4]}];break;case 61:this.$=[F[P-3],F[P-1],{type:"addMessage",from:F[P-3].actor,to:F[P-1].actor,signalType:F[P-2],msg:F[P]}];break;case 62:this.$={type:"addParticipant",actor:F[P]};break;case 63:this.$=q.LINETYPE.SOLID_OPEN;break;case 64:this.$=q.LINETYPE.DOTTED_OPEN;break;case 65:this.$=q.LINETYPE.SOLID;break;case 66:this.$=q.LINETYPE.DOTTED;break;case 67:this.$=q.LINETYPE.SOLID_CROSS;break;case 68:this.$=q.LINETYPE.DOTTED_CROSS;break;case 69:this.$=q.LINETYPE.SOLID_POINT;break;case 70:this.$=q.LINETYPE.DOTTED_POINT;break;case 71:this.$=q.parseMessage(F[P].trim().substring(1));break;case 72:q.parseDirective("%%{","open_directive");break;case 73:q.parseDirective(F[P],"type_directive");break;case 74:F[P]=F[P].trim().replace(/'/g,'"'),q.parseDirective(F[P],"arg_directive");break;case 75:q.parseDirective("}%%","close_directive","sequence");break}},table:[{3:1,4:e,5:r,6:4,7:n,11:6,79:i},{1:[3]},{3:8,4:e,5:r,6:4,7:n,11:6,79:i},{3:9,4:e,5:r,6:4,7:n,11:6,79:i},{3:10,4:e,5:r,6:4,7:n,11:6,79:i},t([1,4,5,16,20,22,25,26,32,33,34,36,38,39,41,42,43,45,47,49,53,58,59,60,61,69,79],a,{8:11}),{12:12,80:[1,13]},{80:[2,72]},{1:[2,1]},{1:[2,2]},{1:[2,3]},{1:[2,4],4:s,5:o,6:41,9:14,10:16,11:6,16:l,17:42,20:u,21:20,22:h,25:d,26:f,27:24,28:25,29:26,30:27,31:28,32:p,33:m,34:_,36:y,38:b,39:x,41:k,42:T,43:C,45:M,47:S,49:R,53:A,58:L,59:v,60:B,61:w,69:D,79:i},{13:49,14:[1,50],82:N},t([14,82],[2,73]),t(z,[2,6]),{6:41,10:52,11:6,16:l,17:42,20:u,21:20,22:h,25:d,26:f,27:24,28:25,29:26,30:27,31:28,32:p,33:m,34:_,36:y,38:b,39:x,41:k,42:T,43:C,45:M,47:S,49:R,53:A,58:L,59:v,60:B,61:w,69:D,79:i},t(z,[2,8]),t(z,[2,9]),{17:53,69:D},{17:54,69:D},{5:[1,55]},{5:[1,58],23:[1,56],24:[1,57]},{17:59,69:D},{17:60,69:D},{5:[1,61]},{5:[1,62]},{5:[1,63]},{5:[1,64]},{5:[1,65]},t(z,[2,28]),t(z,[2,29]),{35:[1,66]},{37:[1,67]},t(z,[2,32]),{19:[1,68]},{19:[1,69]},{19:[1,70]},{19:[1,71]},{19:[1,72]},{19:[1,73]},{19:[1,74]},t(z,[2,40]),{66:75,70:[1,76],71:[1,77],72:[1,78],73:[1,79],74:[1,80],75:[1,81],76:[1,82],77:[1,83]},{54:84,56:[1,85],64:[1,86],65:[1,87]},{17:88,69:D},{17:89,69:D},{17:90,69:D},{17:91,69:D},t([5,18,63,70,71,72,73,74,75,76,77,78],[2,62]),{5:[1,92]},{15:93,81:[1,94]},{5:[2,75]},t(z,[2,7]),{5:[1,96],18:[1,95]},{5:[1,98],18:[1,97]},t(z,[2,16]),{5:[1,100],23:[1,99]},{5:[1,101]},t(z,[2,20]),{5:[1,102]},{5:[1,103]},t(z,[2,23]),t(z,[2,24]),t(z,[2,25]),t(z,[2,26]),t(z,[2,27]),t(z,[2,30]),t(z,[2,31]),t(X,a,{8:104}),t(X,a,{8:105}),t(X,a,{8:106}),t(ct,a,{44:107,8:108}),t(J,a,{46:109,8:110}),t(Y,a,{48:111,8:112}),t(X,a,{8:113}),{17:116,67:[1,114],68:[1,115],69:D},t($,[2,63]),t($,[2,64]),t($,[2,65]),t($,[2,66]),t($,[2,67]),t($,[2,68]),t($,[2,69]),t($,[2,70]),{17:117,69:D},{17:119,57:118,69:D},{69:[2,57]},{69:[2,58]},{55:120,78:lt},{55:122,78:lt},{55:123,78:lt},{55:124,78:lt},t(ut,[2,10]),{13:125,82:N},{82:[2,74]},{19:[1,126]},t(z,[2,13]),{19:[1,127]},t(z,[2,15]),{5:[1,128]},t(z,[2,18]),t(z,[2,19]),t(z,[2,21]),t(z,[2,22]),{4:s,5:o,6:41,9:14,10:16,11:6,16:l,17:42,20:u,21:20,22:h,25:d,26:f,27:24,28:25,29:26,30:27,31:28,32:p,33:m,34:_,36:y,38:b,39:x,40:[1,129],41:k,42:T,43:C,45:M,47:S,49:R,53:A,58:L,59:v,60:B,61:w,69:D,79:i},{4:s,5:o,6:41,9:14,10:16,11:6,16:l,17:42,20:u,21:20,22:h,25:d,26:f,27:24,28:25,29:26,30:27,31:28,32:p,33:m,34:_,36:y,38:b,39:x,40:[1,130],41:k,42:T,43:C,45:M,47:S,49:R,53:A,58:L,59:v,60:B,61:w,69:D,79:i},{4:s,5:o,6:41,9:14,10:16,11:6,16:l,17:42,20:u,21:20,22:h,25:d,26:f,27:24,28:25,29:26,30:27,31:28,32:p,33:m,34:_,36:y,38:b,39:x,40:[1,131],41:k,42:T,43:C,45:M,47:S,49:R,53:A,58:L,59:v,60:B,61:w,69:D,79:i},{40:[1,132]},{4:s,5:o,6:41,9:14,10:16,11:6,16:l,17:42,20:u,21:20,22:h,25:d,26:f,27:24,28:25,29:26,30:27,31:28,32:p,33:m,34:_,36:y,38:b,39:x,40:[2,45],41:k,42:T,43:C,45:M,47:S,49:R,52:[1,133],53:A,58:L,59:v,60:B,61:w,69:D,79:i},{40:[1,134]},{4:s,5:o,6:41,9:14,10:16,11:6,16:l,17:42,20:u,21:20,22:h,25:d,26:f,27:24,28:25,29:26,30:27,31:28,32:p,33:m,34:_,36:y,38:b,39:x,40:[2,43],41:k,42:T,43:C,45:M,47:S,49:R,51:[1,135],53:A,58:L,59:v,60:B,61:w,69:D,79:i},{40:[1,136]},{4:s,5:o,6:41,9:14,10:16,11:6,16:l,17:42,20:u,21:20,22:h,25:d,26:f,27:24,28:25,29:26,30:27,31:28,32:p,33:m,34:_,36:y,38:b,39:x,40:[2,41],41:k,42:T,43:C,45:M,47:S,49:R,50:[1,137],53:A,58:L,59:v,60:B,61:w,69:D,79:i},{4:s,5:o,6:41,9:14,10:16,11:6,16:l,17:42,20:u,21:20,22:h,25:d,26:f,27:24,28:25,29:26,30:27,31:28,32:p,33:m,34:_,36:y,38:b,39:x,40:[1,138],41:k,42:T,43:C,45:M,47:S,49:R,53:A,58:L,59:v,60:B,61:w,69:D,79:i},{17:139,69:D},{17:140,69:D},{55:141,78:lt},{55:142,78:lt},{55:143,78:lt},{63:[1,144],78:[2,56]},{5:[2,49]},{5:[2,71]},{5:[2,50]},{5:[2,51]},{5:[2,52]},{5:[1,145]},{5:[1,146]},{5:[1,147]},t(z,[2,17]),t(z,[2,33]),t(z,[2,34]),t(z,[2,35]),t(z,[2,36]),{19:[1,148]},t(z,[2,37]),{19:[1,149]},t(z,[2,38]),{19:[1,150]},t(z,[2,39]),{55:151,78:lt},{55:152,78:lt},{5:[2,61]},{5:[2,47]},{5:[2,48]},{17:153,69:D},t(ut,[2,11]),t(z,[2,12]),t(z,[2,14]),t(ct,a,{8:108,44:154}),t(J,a,{8:110,46:155}),t(Y,a,{8:112,48:156}),{5:[2,59]},{5:[2,60]},{78:[2,55]},{40:[2,46]},{40:[2,44]},{40:[2,42]}],defaultActions:{7:[2,72],8:[2,1],9:[2,2],10:[2,3],51:[2,75],86:[2,57],87:[2,58],94:[2,74],120:[2,49],121:[2,71],122:[2,50],123:[2,51],124:[2,52],141:[2,61],142:[2,47],143:[2,48],151:[2,59],152:[2,60],153:[2,55],154:[2,46],155:[2,44],156:[2,42]},parseError:function(Z,V){if(V.recoverable)this.trace(Z);else{var Q=new Error(Z);throw Q.hash=V,Q}},parse:function(Z){var V=this,Q=[0],q=[],U=[null],F=[],j=this.table,P="",et=0,at=0,It=2,Lt=1,Rt=F.slice.call(arguments,1),Ct=Object.create(this.lexer),pt={yy:{}};for(var mt in this.yy)Object.prototype.hasOwnProperty.call(this.yy,mt)&&(pt.yy[mt]=this.yy[mt]);Ct.setInput(Z,pt.yy),pt.yy.lexer=Ct,pt.yy.parser=this,typeof Ct.yylloc>"u"&&(Ct.yylloc={});var vt=Ct.yylloc;F.push(vt);var Tt=Ct.options&&Ct.options.ranges;typeof pt.yy.parseError=="function"?this.parseError=pt.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function ft(){var bt;return bt=q.pop()||Ct.lex()||Lt,typeof bt!="number"&&(bt instanceof Array&&(q=bt,bt=q.pop()),bt=V.symbols_[bt]||bt),bt}for(var le,Dt,Gt,$t,Qt={},we,jt,Ft,zt;;){if(Dt=Q[Q.length-1],this.defaultActions[Dt]?Gt=this.defaultActions[Dt]:((le===null||typeof le>"u")&&(le=ft()),Gt=j[Dt]&&j[Dt][le]),typeof Gt>"u"||!Gt.length||!Gt[0]){var wt="";zt=[];for(we in j[Dt])this.terminals_[we]&&we>It&&zt.push("'"+this.terminals_[we]+"'");Ct.showPosition?wt="Parse error on line "+(et+1)+`: +`+Ct.showPosition()+` +Expecting `+zt.join(", ")+", got '"+(this.terminals_[le]||le)+"'":wt="Parse error on line "+(et+1)+": Unexpected "+(le==Lt?"end of input":"'"+(this.terminals_[le]||le)+"'"),this.parseError(wt,{text:Ct.match,token:this.terminals_[le]||le,line:Ct.yylineno,loc:vt,expected:zt})}if(Gt[0]instanceof Array&&Gt.length>1)throw new Error("Parse Error: multiple actions possible at state: "+Dt+", token: "+le);switch(Gt[0]){case 1:Q.push(le),U.push(Ct.yytext),F.push(Ct.yylloc),Q.push(Gt[1]),le=null,at=Ct.yyleng,P=Ct.yytext,et=Ct.yylineno,vt=Ct.yylloc;break;case 2:if(jt=this.productions_[Gt[1]][1],Qt.$=U[U.length-jt],Qt._$={first_line:F[F.length-(jt||1)].first_line,last_line:F[F.length-1].last_line,first_column:F[F.length-(jt||1)].first_column,last_column:F[F.length-1].last_column},Tt&&(Qt._$.range=[F[F.length-(jt||1)].range[0],F[F.length-1].range[1]]),$t=this.performAction.apply(Qt,[P,at,et,pt.yy,Gt[1],U,F].concat(Rt)),typeof $t<"u")return $t;jt&&(Q=Q.slice(0,-1*jt*2),U=U.slice(0,-1*jt),F=F.slice(0,-1*jt)),Q.push(this.productions_[Gt[1]][0]),U.push(Qt.$),F.push(Qt._$),Ft=j[Q[Q.length-2]][Q[Q.length-1]],Q.push(Ft);break;case 3:return!0}}return!0}},tt=function(){var it={EOF:1,parseError:function(V,Q){if(this.yy.parser)this.yy.parser.parseError(V,Q);else throw new Error(V)},setInput:function(Z,V){return this.yy=V||this.yy||{},this._input=Z,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var Z=this._input[0];this.yytext+=Z,this.yyleng++,this.offset++,this.match+=Z,this.matched+=Z;var V=Z.match(/(?:\r\n?|\n).*/g);return V?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),Z},unput:function(Z){var V=Z.length,Q=Z.split(/(?:\r\n?|\n)/g);this._input=Z+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-V),this.offset-=V;var q=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),Q.length-1&&(this.yylineno-=Q.length-1);var U=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:Q?(Q.length===q.length?this.yylloc.first_column:0)+q[q.length-Q.length].length-Q[0].length:this.yylloc.first_column-V},this.options.ranges&&(this.yylloc.range=[U[0],U[0]+this.yyleng-V]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(Z){this.unput(this.match.slice(Z))},pastInput:function(){var Z=this.matched.substr(0,this.matched.length-this.match.length);return(Z.length>20?"...":"")+Z.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var Z=this.match;return Z.length<20&&(Z+=this._input.substr(0,20-Z.length)),(Z.substr(0,20)+(Z.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var Z=this.pastInput(),V=new Array(Z.length+1).join("-");return Z+this.upcomingInput()+` +`+V+"^"},test_match:function(Z,V){var Q,q,U;if(this.options.backtrack_lexer&&(U={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(U.yylloc.range=this.yylloc.range.slice(0))),q=Z[0].match(/(?:\r\n?|\n).*/g),q&&(this.yylineno+=q.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:q?q[q.length-1].length-q[q.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+Z[0].length},this.yytext+=Z[0],this.match+=Z[0],this.matches=Z,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(Z[0].length),this.matched+=Z[0],Q=this.performAction.call(this,this.yy,this,V,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),Q)return Q;if(this._backtrack){for(var F in U)this[F]=U[F];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var Z,V,Q,q;this._more||(this.yytext="",this.match="");for(var U=this._currentRules(),F=0;F<U.length;F++)if(Q=this._input.match(this.rules[U[F]]),Q&&(!V||Q[0].length>V[0].length)){if(V=Q,q=F,this.options.backtrack_lexer){if(Z=this.test_match(Q,U[F]),Z!==!1)return Z;if(this._backtrack){V=!1;continue}else return!1}else if(!this.options.flex)break}return V?(Z=this.test_match(V,U[q]),Z!==!1?Z:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var V=this.next();return V||this.lex()},begin:function(V){this.conditionStack.push(V)},popState:function(){var V=this.conditionStack.length-1;return V>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(V){return V=this.conditionStack.length-1-Math.abs(V||0),V>=0?this.conditionStack[V]:"INITIAL"},pushState:function(V){this.begin(V)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(V,Q,q,U){switch(q){case 0:return this.begin("open_directive"),79;case 1:return this.begin("type_directive"),80;case 2:return this.popState(),this.begin("arg_directive"),14;case 3:return this.popState(),this.popState(),82;case 4:return 81;case 5:return 5;case 6:break;case 7:break;case 8:break;case 9:break;case 10:break;case 11:return 23;case 12:return this.begin("ID"),16;case 13:return this.begin("ID"),20;case 14:return Q.yytext=Q.yytext.trim(),this.begin("ALIAS"),69;case 15:return this.popState(),this.popState(),this.begin("LINE"),18;case 16:return this.popState(),this.popState(),5;case 17:return this.begin("LINE"),39;case 18:return this.begin("LINE"),41;case 19:return this.begin("LINE"),42;case 20:return this.begin("LINE"),43;case 21:return this.begin("LINE"),52;case 22:return this.begin("LINE"),45;case 23:return this.begin("LINE"),51;case 24:return this.begin("LINE"),47;case 25:return this.begin("LINE"),50;case 26:return this.begin("LINE"),49;case 27:return this.popState(),19;case 28:return 40;case 29:return 64;case 30:return 65;case 31:return 58;case 32:return 59;case 33:return 60;case 34:return 61;case 35:return 56;case 36:return 53;case 37:return this.begin("ID"),25;case 38:return this.begin("ID"),26;case 39:return 32;case 40:return 33;case 41:return this.begin("acc_title"),34;case 42:return this.popState(),"acc_title_value";case 43:return this.begin("acc_descr"),36;case 44:return this.popState(),"acc_descr_value";case 45:this.begin("acc_descr_multiline");break;case 46:this.popState();break;case 47:return"acc_descr_multiline_value";case 48:return 7;case 49:return 22;case 50:return 24;case 51:return 63;case 52:return 5;case 53:return Q.yytext=Q.yytext.trim(),69;case 54:return 72;case 55:return 73;case 56:return 70;case 57:return 71;case 58:return 74;case 59:return 75;case 60:return 76;case 61:return 77;case 62:return 78;case 63:return 67;case 64:return 68;case 65:return 5;case 66:return"INVALID"}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:((?!\n)\s)+)/i,/^(?:#[^\n]*)/i,/^(?:%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[0-9]+(?=[ \n]+))/i,/^(?:participant\b)/i,/^(?:actor\b)/i,/^(?:[^\->:\n,;]+?([\-]*[^\->:\n,;]+?)*?(?=((?!\n)\s)+as(?!\n)\s|[#\n;]|$))/i,/^(?:as\b)/i,/^(?:(?:))/i,/^(?:loop\b)/i,/^(?:rect\b)/i,/^(?:opt\b)/i,/^(?:alt\b)/i,/^(?:else\b)/i,/^(?:par\b)/i,/^(?:and\b)/i,/^(?:critical\b)/i,/^(?:option\b)/i,/^(?:break\b)/i,/^(?:(?:[:]?(?:no)?wrap)?[^#\n;]*)/i,/^(?:end\b)/i,/^(?:left of\b)/i,/^(?:right of\b)/i,/^(?:links\b)/i,/^(?:link\b)/i,/^(?:properties\b)/i,/^(?:details\b)/i,/^(?:over\b)/i,/^(?:note\b)/i,/^(?:activate\b)/i,/^(?:deactivate\b)/i,/^(?:title\s[^#\n;]+)/i,/^(?:title:\s[^#\n;]+)/i,/^(?:accTitle\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*\{\s*)/i,/^(?:[\}])/i,/^(?:[^\}]*)/i,/^(?:sequenceDiagram\b)/i,/^(?:autonumber\b)/i,/^(?:off\b)/i,/^(?:,)/i,/^(?:;)/i,/^(?:[^\+\->:\n,;]+((?!(-x|--x|-\)|--\)))[\-]*[^\+\->:\n,;]+)*)/i,/^(?:->>)/i,/^(?:-->>)/i,/^(?:->)/i,/^(?:-->)/i,/^(?:-[x])/i,/^(?:--[x])/i,/^(?:-[\)])/i,/^(?:--[\)])/i,/^(?::(?:(?:no)?wrap)?[^#\n;]+)/i,/^(?:\+)/i,/^(?:-)/i,/^(?:$)/i,/^(?:.)/i],conditions:{acc_descr_multiline:{rules:[46,47],inclusive:!1},acc_descr:{rules:[44],inclusive:!1},acc_title:{rules:[42],inclusive:!1},open_directive:{rules:[1,8],inclusive:!1},type_directive:{rules:[2,3,8],inclusive:!1},arg_directive:{rules:[3,4,8],inclusive:!1},ID:{rules:[7,8,14],inclusive:!1},ALIAS:{rules:[7,8,15,16],inclusive:!1},LINE:{rules:[7,8,27],inclusive:!1},INITIAL:{rules:[0,5,6,8,9,10,11,12,13,17,18,19,20,21,22,23,24,25,26,28,29,30,31,32,33,34,35,36,37,38,39,40,41,43,45,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66],inclusive:!0}}};return it}();W.lexer=tt;function K(){this.yy={}}return K.prototype=W,W.Parser=K,new K}();H4.parser=H4;const bit=t=>t.match(/^\s*sequenceDiagram/)!==null;let hu,ns={},bi=[],u0=!1,G4;const _it=function(t,e,r){Xe.parseDirective(this,t,e,r)},j4=function(t,e,r,n){const i=ns[t];i&&e===i.name&&r==null||((r==null||r.text==null)&&(r={text:e,wrap:null,type:n}),(n==null||r.text==null)&&(r={text:e,wrap:null,type:n}),ns[t]={name:e,description:r.text,wrap:r.wrap===void 0&&ul()||!!r.wrap,prevActor:hu,links:{},properties:{},actorCnt:null,rectData:null,type:n||"participant"},hu&&ns[hu]&&(ns[hu].nextActor=t),hu=t)},vit=t=>{let e,r=0;for(e=0;e<bi.length;e++)bi[e].type===du.ACTIVE_START&&bi[e].from.actor===t&&r++,bi[e].type===du.ACTIVE_END&&bi[e].from.actor===t&&r--;return r},xit=function(t,e,r,n){bi.push({from:t,to:e,message:r.text,wrap:r.wrap===void 0&&ul()||!!r.wrap,answer:n})},hr=function(t,e,r={text:void 0,wrap:void 0},n){if(n===du.ACTIVE_END&&vit(t.actor)<1){let a=new Error("Trying to inactivate an inactive participant ("+t.actor+")");throw a.hash={text:"->>-",token:"->>-",line:"1",loc:{first_line:1,last_line:1,first_column:1,last_column:1},expected:["'ACTIVE_PARTICIPANT'"]},a}return bi.push({from:t,to:e,message:r.text,wrap:r.wrap===void 0&&ul()||!!r.wrap,type:n}),!0},kit=function(){return bi},wit=function(){return ns},fu=function(t){return ns[t]},Tit=function(){return Object.keys(ns)},Eit=function(){u0=!0},Cit=function(){u0=!1},Sit=()=>u0,Ait=function(t){G4=t},ul=()=>typeof G4<"u"?G4:nt().sequence.wrap,Mit=function(){ns={},bi=[],u0=!1,ci()},Lit=function(t){const e=t.trim(),r={text:e.replace(/^[:]?(?:no)?wrap:/,"").trim(),wrap:e.match(/^[:]?wrap:/)!==null?!0:e.match(/^[:]?nowrap:/)!==null?!1:void 0};return H.debug("parseMessage:",r),r},du={SOLID:0,DOTTED:1,NOTE:2,SOLID_CROSS:3,DOTTED_CROSS:4,SOLID_OPEN:5,DOTTED_OPEN:6,LOOP_START:10,LOOP_END:11,ALT_START:12,ALT_ELSE:13,ALT_END:14,OPT_START:15,OPT_END:16,ACTIVE_START:17,ACTIVE_END:18,PAR_START:19,PAR_AND:20,PAR_END:21,RECT_START:22,RECT_END:23,SOLID_POINT:24,DOTTED_POINT:25,AUTONUMBER:26,CRITICAL_START:27,CRITICAL_OPTION:28,CRITICAL_END:29,BREAK_START:30,BREAK_END:31},Rit={FILLED:0,OPEN:1},Iit={LEFTOF:0,RIGHTOF:1,OVER:2},hL=function(t,e,r){r.text,r.wrap===void 0&&ul()||r.wrap;const n=[].concat(t,t);bi.push({from:n[0],to:n[1],message:r.text,wrap:r.wrap===void 0&&ul()||!!r.wrap,type:du.NOTE,placement:e})},fL=function(t,e){const r=fu(t);try{let n=ai(e.text,nt());n=n.replace(/&/g,"&"),n=n.replace(/=/g,"=");const i=JSON.parse(n);$4(r,i)}catch(n){H.error("error while parsing actor link text",n)}},Nit=function(t,e){const r=fu(t);try{const s={};let o=ai(e.text,nt());var n=o.indexOf("@");o=o.replace(/&/g,"&"),o=o.replace(/=/g,"=");var i=o.slice(0,n-1).trim(),a=o.slice(n+1).trim();s[i]=a,$4(r,s)}catch(s){H.error("error while parsing actor link text",s)}};function $4(t,e){if(t.links==null)t.links=e;else for(let r in e)t.links[r]=e[r]}const dL=function(t,e){const r=fu(t);try{let n=ai(e.text,nt());const i=JSON.parse(n);pL(r,i)}catch(n){H.error("error while parsing actor properties text",n)}};function pL(t,e){if(t.properties==null)t.properties=e;else for(let r in e)t.properties[r]=e[r]}const gL=function(t,e){const r=fu(t),n=document.getElementById(e.text);try{const i=n.innerHTML,a=JSON.parse(i);a.properties&&pL(r,a.properties),a.links&&$4(r,a.links)}catch(i){H.error("error while parsing actor details text",i)}},Bit=function(t,e){if(typeof t<"u"&&typeof t.properties<"u")return t.properties[e]},yL=function(t){if(t instanceof Array)t.forEach(function(e){yL(e)});else switch(t.type){case"sequenceIndex":bi.push({from:void 0,to:void 0,message:{start:t.sequenceIndex,step:t.sequenceIndexStep,visible:t.sequenceVisible},wrap:!1,type:t.signalType});break;case"addParticipant":j4(t.actor,t.actor,t.description,"participant");break;case"addActor":j4(t.actor,t.actor,t.description,"actor");break;case"activeStart":hr(t.actor,void 0,void 0,t.signalType);break;case"activeEnd":hr(t.actor,void 0,void 0,t.signalType);break;case"addNote":hL(t.actor,t.placement,t.text);break;case"addLinks":fL(t.actor,t.text);break;case"addALink":Nit(t.actor,t.text);break;case"addProperties":dL(t.actor,t.text);break;case"addDetails":gL(t.actor,t.text);break;case"addMessage":hr(t.from,t.to,t.msg,t.signalType);break;case"loopStart":hr(void 0,void 0,t.loopText,t.signalType);break;case"loopEnd":hr(void 0,void 0,void 0,t.signalType);break;case"rectStart":hr(void 0,void 0,t.color,t.signalType);break;case"rectEnd":hr(void 0,void 0,void 0,t.signalType);break;case"optStart":hr(void 0,void 0,t.optText,t.signalType);break;case"optEnd":hr(void 0,void 0,void 0,t.signalType);break;case"altStart":hr(void 0,void 0,t.altText,t.signalType);break;case"else":hr(void 0,void 0,t.altText,t.signalType);break;case"altEnd":hr(void 0,void 0,void 0,t.signalType);break;case"setAccTitle":Yn(t.text);break;case"parStart":hr(void 0,void 0,t.parText,t.signalType);break;case"and":hr(void 0,void 0,t.parText,t.signalType);break;case"parEnd":hr(void 0,void 0,void 0,t.signalType);break;case"criticalStart":hr(void 0,void 0,t.criticalText,t.signalType);break;case"option":hr(void 0,void 0,t.optionText,t.signalType);break;case"criticalEnd":hr(void 0,void 0,void 0,t.signalType);break;case"breakStart":hr(void 0,void 0,t.breakText,t.signalType);break;case"breakEnd":hr(void 0,void 0,void 0,t.signalType);break}},mL={addActor:j4,addMessage:xit,addSignal:hr,addLinks:fL,addDetails:gL,addProperties:dL,autoWrap:ul,setWrap:Ait,enableSequenceNumbers:Eit,disableSequenceNumbers:Cit,showSequenceNumbers:Sit,getMessages:kit,getActors:wit,getActor:fu,getActorKeys:Tit,getActorProperty:Bit,getAccTitle:ui,getDiagramTitle:u1,setDiagramTitle:c1,parseDirective:_it,getConfig:()=>nt().sequence,clear:Mit,parseMessage:Lit,LINETYPE:du,ARROWTYPE:Rit,PLACEMENT:Iit,addNote:hL,setAccTitle:Yn,apply:yL,setAccDescription:hi,getAccDescription:fi};let X4=[];const Dit=t=>{X4.push(t)},bL=()=>{X4.forEach(t=>{t()}),X4=[]},h0=function(t,e){const r=t.append("rect");return r.attr("x",e.x),r.attr("y",e.y),r.attr("fill",e.fill),r.attr("stroke",e.stroke),r.attr("width",e.width),r.attr("height",e.height),r.attr("rx",e.rx),r.attr("ry",e.ry),typeof e.class<"u"&&r.attr("class",e.class),r},_L=(t,e)=>{Dit(()=>{const r=document.querySelectorAll(t);r.length!==0&&(r[0].addEventListener("mouseover",function(){qit("actor"+e+"_popup")}),r[0].addEventListener("mouseout",function(){Vit("actor"+e+"_popup")}))})},Oit=function(t,e,r,n,i){if(e.links===void 0||e.links===null||Object.keys(e.links).length===0)return{height:0,width:0};const a=e.links,s=e.actorCnt,o=e.rectData;var l="none";i&&(l="block !important");const u=t.append("g");u.attr("id","actor"+s+"_popup"),u.attr("class","actorPopupMenu"),u.attr("display",l),_L("#actor"+s+"_popup",s);var h="";typeof o.class<"u"&&(h=" "+o.class);let d=o.width>r?o.width:r;const f=u.append("rect");if(f.attr("class","actorPopupMenuPanel"+h),f.attr("x",o.x),f.attr("y",o.height),f.attr("fill",o.fill),f.attr("stroke",o.stroke),f.attr("width",d),f.attr("height",o.height),f.attr("rx",o.rx),f.attr("ry",o.ry),a!=null){var p=20;for(let y in a){var m=u.append("a"),_=ki(a[y]);m.attr("xlink:href",_),m.attr("target","_blank"),eat(n)(y,m,o.x+10,o.height+p,d,20,{class:"actor"},n),p+=30}}return f.attr("height",p),{height:o.height+p,width:d}},vL=function(t,e,r,n){const i=t.append("image");i.attr("x",e),i.attr("y",r);var a=ki(n);i.attr("xlink:href",a)},xL=function(t,e,r,n){const i=t.append("use");i.attr("x",e),i.attr("y",r);var a=ki(n);i.attr("xlink:href","#"+a)},Fit=function(t){return"var pu = document.getElementById('"+t+"'); if (pu != null) { pu.style.display = 'block'; }"},Pit=function(t){return"var pu = document.getElementById('"+t+"'); if (pu != null) { pu.style.display = 'none'; }"},qit=function(t){var e=document.getElementById(t);e!=null&&(e.style.display="block")},Vit=function(t){var e=document.getElementById(t);e!=null&&(e.style.display="none")},hl=function(t,e){let r=0,n=0;const i=e.text.split(pe.lineBreakRegex);let a=[],s=0,o=()=>e.y;if(typeof e.valign<"u"&&typeof e.textMargin<"u"&&e.textMargin>0)switch(e.valign){case"top":case"start":o=()=>Math.round(e.y+e.textMargin);break;case"middle":case"center":o=()=>Math.round(e.y+(r+n+e.textMargin)/2);break;case"bottom":case"end":o=()=>Math.round(e.y+(r+n+2*e.textMargin)-e.textMargin);break}if(typeof e.anchor<"u"&&typeof e.textMargin<"u"&&typeof e.width<"u")switch(e.anchor){case"left":case"start":e.x=Math.round(e.x+e.textMargin),e.anchor="start",e.dominantBaseline="middle",e.alignmentBaseline="middle";break;case"middle":case"center":e.x=Math.round(e.x+e.width/2),e.anchor="middle",e.dominantBaseline="middle",e.alignmentBaseline="middle";break;case"right":case"end":e.x=Math.round(e.x+e.width-e.textMargin),e.anchor="end",e.dominantBaseline="middle",e.alignmentBaseline="middle";break}for(let l=0;l<i.length;l++){let u=i[l];typeof e.textMargin<"u"&&e.textMargin===0&&typeof e.fontSize<"u"&&(s=l*e.fontSize);const h=t.append("text");if(h.attr("x",e.x),h.attr("y",o()),typeof e.anchor<"u"&&h.attr("text-anchor",e.anchor).attr("dominant-baseline",e.dominantBaseline).attr("alignment-baseline",e.alignmentBaseline),typeof e.fontFamily<"u"&&h.style("font-family",e.fontFamily),typeof e.fontSize<"u"&&h.style("font-size",e.fontSize),typeof e.fontWeight<"u"&&h.style("font-weight",e.fontWeight),typeof e.fill<"u"&&h.attr("fill",e.fill),typeof e.class<"u"&&h.attr("class",e.class),typeof e.dy<"u"?h.attr("dy",e.dy):s!==0&&h.attr("dy",s),e.tspan){const d=h.append("tspan");d.attr("x",e.x),typeof e.fill<"u"&&d.attr("fill",e.fill),d.text(u)}else h.text(u);typeof e.valign<"u"&&typeof e.textMargin<"u"&&e.textMargin>0&&(n+=(h._groups||h)[0][0].getBBox().height,r=n),a.push(h)}return a},kL=function(t,e){function r(i,a,s,o,l){return i+","+a+" "+(i+s)+","+a+" "+(i+s)+","+(a+o-l)+" "+(i+s-l*1.2)+","+(a+o)+" "+i+","+(a+o)}const n=t.append("polygon");return n.attr("points",r(e.x,e.y,e.width,e.height,7)),n.attr("class","labelBox"),e.y=e.y+e.height/2,hl(t,e),n};let Yi=-1;const wL=(t,e)=>{!t.selectAll||t.selectAll(".actor-line").attr("class","200").attr("y2",e-55)},zit=function(t,e,r){const n=e.x+e.width/2,i=t.append("g");var a=i;e.y===0&&(Yi++,a.append("line").attr("id","actor"+Yi).attr("x1",n).attr("y1",5).attr("x2",n).attr("y2",2e3).attr("class","actor-line").attr("stroke-width","0.5px").attr("stroke","#999"),a=i.append("g"),e.actorCnt=Yi,e.links!=null&&(a.attr("id","root-"+Yi),_L("#root-"+Yi,Yi)));const s=f0();var o="actor";e.properties!=null&&e.properties.class?o=e.properties.class:s.fill="#eaeaea",s.x=e.x,s.y=e.y,s.width=e.width,s.height=e.height,s.class=o,s.rx=3,s.ry=3;const l=h0(a,s);if(e.rectData=s,e.properties!=null&&e.properties.icon){const h=e.properties.icon.trim();h.charAt(0)==="@"?xL(a,s.x+s.width-20,s.y+10,h.substr(1)):vL(a,s.x+s.width-20,s.y+10,h)}TL(r)(e.description,a,s.x,s.y,s.width,s.height,{class:"actor"},r);let u=e.height;if(l.node){const h=l.node().getBBox();e.height=h.height,u=h.height}return u},Yit=function(t,e,r){const n=e.x+e.width/2;e.y===0&&(Yi++,t.append("line").attr("id","actor"+Yi).attr("x1",n).attr("y1",80).attr("x2",n).attr("y2",2e3).attr("class","actor-line").attr("stroke-width","0.5px").attr("stroke","#999"));const i=t.append("g");i.attr("class","actor-man");const a=f0();a.x=e.x,a.y=e.y,a.fill="#eaeaea",a.width=e.width,a.height=e.height,a.class="actor",a.rx=3,a.ry=3,i.append("line").attr("id","actor-man-torso"+Yi).attr("x1",n).attr("y1",e.y+25).attr("x2",n).attr("y2",e.y+45),i.append("line").attr("id","actor-man-arms"+Yi).attr("x1",n-18).attr("y1",e.y+33).attr("x2",n+18).attr("y2",e.y+33),i.append("line").attr("x1",n-18).attr("y1",e.y+60).attr("x2",n).attr("y2",e.y+45),i.append("line").attr("x1",n).attr("y1",e.y+45).attr("x2",n+16).attr("y2",e.y+60);const s=i.append("circle");s.attr("cx",e.x+e.width/2),s.attr("cy",e.y+10),s.attr("r",15),s.attr("width",e.width),s.attr("height",e.height);const o=i.node().getBBox();return e.height=o.height,TL(r)(e.description,i,a.x,a.y+35,a.width,a.height,{class:"actor"},r),e.height},Uit=function(t,e,r){switch(e.type){case"actor":return Yit(t,e,r);case"participant":return zit(t,e,r)}},Wit=function(t){return t.append("g")},Hit=function(t,e,r,n,i){const a=f0(),s=e.anchored;a.x=e.startx,a.y=e.starty,a.class="activation"+i%3,a.width=e.stopx-e.startx,a.height=r-e.starty,h0(s,a)},Git=function(t,e,r,n){const{boxMargin:i,boxTextMargin:a,labelBoxHeight:s,labelBoxWidth:o,messageFontFamily:l,messageFontSize:u,messageFontWeight:h}=n,d=t.append("g"),f=function(_,y,b,x){return d.append("line").attr("x1",_).attr("y1",y).attr("x2",b).attr("y2",x).attr("class","loopLine")};f(e.startx,e.starty,e.stopx,e.starty),f(e.stopx,e.starty,e.stopx,e.stopy),f(e.startx,e.stopy,e.stopx,e.stopy),f(e.startx,e.starty,e.startx,e.stopy),typeof e.sections<"u"&&e.sections.forEach(function(_){f(e.startx,_.y,e.stopx,_.y).style("stroke-dasharray","3, 3")});let p=K4();p.text=r,p.x=e.startx,p.y=e.starty,p.fontFamily=l,p.fontSize=u,p.fontWeight=h,p.anchor="middle",p.valign="middle",p.tspan=!1,p.width=o||50,p.height=s||20,p.textMargin=a,p.class="labelText",kL(d,p),p=K4(),p.text=e.title,p.x=e.startx+o/2+(e.stopx-e.startx)/2,p.y=e.starty+i+a,p.anchor="middle",p.valign="middle",p.textMargin=a,p.class="loopText",p.fontFamily=l,p.fontSize=u,p.fontWeight=h,p.wrap=!0;let m=hl(d,p);return typeof e.sectionTitles<"u"&&e.sectionTitles.forEach(function(_,y){if(_.message){p.text=_.message,p.x=e.startx+(e.stopx-e.startx)/2,p.y=e.sections[y].y+i+a,p.class="loopText",p.anchor="middle",p.valign="middle",p.tspan=!1,p.fontFamily=l,p.fontSize=u,p.fontWeight=h,p.wrap=e.wrap,m=hl(d,p);let b=Math.round(m.map(x=>(x._groups||x)[0][0].getBBox().height).reduce((x,k)=>x+k));e.sections[y].height+=b-(i+a)}}),e.height=Math.round(e.stopy-e.starty),d},jit=function(t,e){h0(t,{x:e.startx,y:e.starty,width:e.stopx-e.startx,height:e.stopy-e.starty,fill:e.fill,class:"rect"}).lower()},$it=function(t){t.append("defs").append("symbol").attr("id","database").attr("fill-rule","evenodd").attr("clip-rule","evenodd").append("path").attr("transform","scale(.5)").attr("d","M12.258.001l.256.004.255.005.253.008.251.01.249.012.247.015.246.016.242.019.241.02.239.023.236.024.233.027.231.028.229.031.225.032.223.034.22.036.217.038.214.04.211.041.208.043.205.045.201.046.198.048.194.05.191.051.187.053.183.054.18.056.175.057.172.059.168.06.163.061.16.063.155.064.15.066.074.033.073.033.071.034.07.034.069.035.068.035.067.035.066.035.064.036.064.036.062.036.06.036.06.037.058.037.058.037.055.038.055.038.053.038.052.038.051.039.05.039.048.039.047.039.045.04.044.04.043.04.041.04.04.041.039.041.037.041.036.041.034.041.033.042.032.042.03.042.029.042.027.042.026.043.024.043.023.043.021.043.02.043.018.044.017.043.015.044.013.044.012.044.011.045.009.044.007.045.006.045.004.045.002.045.001.045v17l-.001.045-.002.045-.004.045-.006.045-.007.045-.009.044-.011.045-.012.044-.013.044-.015.044-.017.043-.018.044-.02.043-.021.043-.023.043-.024.043-.026.043-.027.042-.029.042-.03.042-.032.042-.033.042-.034.041-.036.041-.037.041-.039.041-.04.041-.041.04-.043.04-.044.04-.045.04-.047.039-.048.039-.05.039-.051.039-.052.038-.053.038-.055.038-.055.038-.058.037-.058.037-.06.037-.06.036-.062.036-.064.036-.064.036-.066.035-.067.035-.068.035-.069.035-.07.034-.071.034-.073.033-.074.033-.15.066-.155.064-.16.063-.163.061-.168.06-.172.059-.175.057-.18.056-.183.054-.187.053-.191.051-.194.05-.198.048-.201.046-.205.045-.208.043-.211.041-.214.04-.217.038-.22.036-.223.034-.225.032-.229.031-.231.028-.233.027-.236.024-.239.023-.241.02-.242.019-.246.016-.247.015-.249.012-.251.01-.253.008-.255.005-.256.004-.258.001-.258-.001-.256-.004-.255-.005-.253-.008-.251-.01-.249-.012-.247-.015-.245-.016-.243-.019-.241-.02-.238-.023-.236-.024-.234-.027-.231-.028-.228-.031-.226-.032-.223-.034-.22-.036-.217-.038-.214-.04-.211-.041-.208-.043-.204-.045-.201-.046-.198-.048-.195-.05-.19-.051-.187-.053-.184-.054-.179-.056-.176-.057-.172-.059-.167-.06-.164-.061-.159-.063-.155-.064-.151-.066-.074-.033-.072-.033-.072-.034-.07-.034-.069-.035-.068-.035-.067-.035-.066-.035-.064-.036-.063-.036-.062-.036-.061-.036-.06-.037-.058-.037-.057-.037-.056-.038-.055-.038-.053-.038-.052-.038-.051-.039-.049-.039-.049-.039-.046-.039-.046-.04-.044-.04-.043-.04-.041-.04-.04-.041-.039-.041-.037-.041-.036-.041-.034-.041-.033-.042-.032-.042-.03-.042-.029-.042-.027-.042-.026-.043-.024-.043-.023-.043-.021-.043-.02-.043-.018-.044-.017-.043-.015-.044-.013-.044-.012-.044-.011-.045-.009-.044-.007-.045-.006-.045-.004-.045-.002-.045-.001-.045v-17l.001-.045.002-.045.004-.045.006-.045.007-.045.009-.044.011-.045.012-.044.013-.044.015-.044.017-.043.018-.044.02-.043.021-.043.023-.043.024-.043.026-.043.027-.042.029-.042.03-.042.032-.042.033-.042.034-.041.036-.041.037-.041.039-.041.04-.041.041-.04.043-.04.044-.04.046-.04.046-.039.049-.039.049-.039.051-.039.052-.038.053-.038.055-.038.056-.038.057-.037.058-.037.06-.037.061-.036.062-.036.063-.036.064-.036.066-.035.067-.035.068-.035.069-.035.07-.034.072-.034.072-.033.074-.033.151-.066.155-.064.159-.063.164-.061.167-.06.172-.059.176-.057.179-.056.184-.054.187-.053.19-.051.195-.05.198-.048.201-.046.204-.045.208-.043.211-.041.214-.04.217-.038.22-.036.223-.034.226-.032.228-.031.231-.028.234-.027.236-.024.238-.023.241-.02.243-.019.245-.016.247-.015.249-.012.251-.01.253-.008.255-.005.256-.004.258-.001.258.001zm-9.258 20.499v.01l.001.021.003.021.004.022.005.021.006.022.007.022.009.023.01.022.011.023.012.023.013.023.015.023.016.024.017.023.018.024.019.024.021.024.022.025.023.024.024.025.052.049.056.05.061.051.066.051.07.051.075.051.079.052.084.052.088.052.092.052.097.052.102.051.105.052.11.052.114.051.119.051.123.051.127.05.131.05.135.05.139.048.144.049.147.047.152.047.155.047.16.045.163.045.167.043.171.043.176.041.178.041.183.039.187.039.19.037.194.035.197.035.202.033.204.031.209.03.212.029.216.027.219.025.222.024.226.021.23.02.233.018.236.016.24.015.243.012.246.01.249.008.253.005.256.004.259.001.26-.001.257-.004.254-.005.25-.008.247-.011.244-.012.241-.014.237-.016.233-.018.231-.021.226-.021.224-.024.22-.026.216-.027.212-.028.21-.031.205-.031.202-.034.198-.034.194-.036.191-.037.187-.039.183-.04.179-.04.175-.042.172-.043.168-.044.163-.045.16-.046.155-.046.152-.047.148-.048.143-.049.139-.049.136-.05.131-.05.126-.05.123-.051.118-.052.114-.051.11-.052.106-.052.101-.052.096-.052.092-.052.088-.053.083-.051.079-.052.074-.052.07-.051.065-.051.06-.051.056-.05.051-.05.023-.024.023-.025.021-.024.02-.024.019-.024.018-.024.017-.024.015-.023.014-.024.013-.023.012-.023.01-.023.01-.022.008-.022.006-.022.006-.022.004-.022.004-.021.001-.021.001-.021v-4.127l-.077.055-.08.053-.083.054-.085.053-.087.052-.09.052-.093.051-.095.05-.097.05-.1.049-.102.049-.105.048-.106.047-.109.047-.111.046-.114.045-.115.045-.118.044-.12.043-.122.042-.124.042-.126.041-.128.04-.13.04-.132.038-.134.038-.135.037-.138.037-.139.035-.142.035-.143.034-.144.033-.147.032-.148.031-.15.03-.151.03-.153.029-.154.027-.156.027-.158.026-.159.025-.161.024-.162.023-.163.022-.165.021-.166.02-.167.019-.169.018-.169.017-.171.016-.173.015-.173.014-.175.013-.175.012-.177.011-.178.01-.179.008-.179.008-.181.006-.182.005-.182.004-.184.003-.184.002h-.37l-.184-.002-.184-.003-.182-.004-.182-.005-.181-.006-.179-.008-.179-.008-.178-.01-.176-.011-.176-.012-.175-.013-.173-.014-.172-.015-.171-.016-.17-.017-.169-.018-.167-.019-.166-.02-.165-.021-.163-.022-.162-.023-.161-.024-.159-.025-.157-.026-.156-.027-.155-.027-.153-.029-.151-.03-.15-.03-.148-.031-.146-.032-.145-.033-.143-.034-.141-.035-.14-.035-.137-.037-.136-.037-.134-.038-.132-.038-.13-.04-.128-.04-.126-.041-.124-.042-.122-.042-.12-.044-.117-.043-.116-.045-.113-.045-.112-.046-.109-.047-.106-.047-.105-.048-.102-.049-.1-.049-.097-.05-.095-.05-.093-.052-.09-.051-.087-.052-.085-.053-.083-.054-.08-.054-.077-.054v4.127zm0-5.654v.011l.001.021.003.021.004.021.005.022.006.022.007.022.009.022.01.022.011.023.012.023.013.023.015.024.016.023.017.024.018.024.019.024.021.024.022.024.023.025.024.024.052.05.056.05.061.05.066.051.07.051.075.052.079.051.084.052.088.052.092.052.097.052.102.052.105.052.11.051.114.051.119.052.123.05.127.051.131.05.135.049.139.049.144.048.147.048.152.047.155.046.16.045.163.045.167.044.171.042.176.042.178.04.183.04.187.038.19.037.194.036.197.034.202.033.204.032.209.03.212.028.216.027.219.025.222.024.226.022.23.02.233.018.236.016.24.014.243.012.246.01.249.008.253.006.256.003.259.001.26-.001.257-.003.254-.006.25-.008.247-.01.244-.012.241-.015.237-.016.233-.018.231-.02.226-.022.224-.024.22-.025.216-.027.212-.029.21-.03.205-.032.202-.033.198-.035.194-.036.191-.037.187-.039.183-.039.179-.041.175-.042.172-.043.168-.044.163-.045.16-.045.155-.047.152-.047.148-.048.143-.048.139-.05.136-.049.131-.05.126-.051.123-.051.118-.051.114-.052.11-.052.106-.052.101-.052.096-.052.092-.052.088-.052.083-.052.079-.052.074-.051.07-.052.065-.051.06-.05.056-.051.051-.049.023-.025.023-.024.021-.025.02-.024.019-.024.018-.024.017-.024.015-.023.014-.023.013-.024.012-.022.01-.023.01-.023.008-.022.006-.022.006-.022.004-.021.004-.022.001-.021.001-.021v-4.139l-.077.054-.08.054-.083.054-.085.052-.087.053-.09.051-.093.051-.095.051-.097.05-.1.049-.102.049-.105.048-.106.047-.109.047-.111.046-.114.045-.115.044-.118.044-.12.044-.122.042-.124.042-.126.041-.128.04-.13.039-.132.039-.134.038-.135.037-.138.036-.139.036-.142.035-.143.033-.144.033-.147.033-.148.031-.15.03-.151.03-.153.028-.154.028-.156.027-.158.026-.159.025-.161.024-.162.023-.163.022-.165.021-.166.02-.167.019-.169.018-.169.017-.171.016-.173.015-.173.014-.175.013-.175.012-.177.011-.178.009-.179.009-.179.007-.181.007-.182.005-.182.004-.184.003-.184.002h-.37l-.184-.002-.184-.003-.182-.004-.182-.005-.181-.007-.179-.007-.179-.009-.178-.009-.176-.011-.176-.012-.175-.013-.173-.014-.172-.015-.171-.016-.17-.017-.169-.018-.167-.019-.166-.02-.165-.021-.163-.022-.162-.023-.161-.024-.159-.025-.157-.026-.156-.027-.155-.028-.153-.028-.151-.03-.15-.03-.148-.031-.146-.033-.145-.033-.143-.033-.141-.035-.14-.036-.137-.036-.136-.037-.134-.038-.132-.039-.13-.039-.128-.04-.126-.041-.124-.042-.122-.043-.12-.043-.117-.044-.116-.044-.113-.046-.112-.046-.109-.046-.106-.047-.105-.048-.102-.049-.1-.049-.097-.05-.095-.051-.093-.051-.09-.051-.087-.053-.085-.052-.083-.054-.08-.054-.077-.054v4.139zm0-5.666v.011l.001.02.003.022.004.021.005.022.006.021.007.022.009.023.01.022.011.023.012.023.013.023.015.023.016.024.017.024.018.023.019.024.021.025.022.024.023.024.024.025.052.05.056.05.061.05.066.051.07.051.075.052.079.051.084.052.088.052.092.052.097.052.102.052.105.051.11.052.114.051.119.051.123.051.127.05.131.05.135.05.139.049.144.048.147.048.152.047.155.046.16.045.163.045.167.043.171.043.176.042.178.04.183.04.187.038.19.037.194.036.197.034.202.033.204.032.209.03.212.028.216.027.219.025.222.024.226.021.23.02.233.018.236.017.24.014.243.012.246.01.249.008.253.006.256.003.259.001.26-.001.257-.003.254-.006.25-.008.247-.01.244-.013.241-.014.237-.016.233-.018.231-.02.226-.022.224-.024.22-.025.216-.027.212-.029.21-.03.205-.032.202-.033.198-.035.194-.036.191-.037.187-.039.183-.039.179-.041.175-.042.172-.043.168-.044.163-.045.16-.045.155-.047.152-.047.148-.048.143-.049.139-.049.136-.049.131-.051.126-.05.123-.051.118-.052.114-.051.11-.052.106-.052.101-.052.096-.052.092-.052.088-.052.083-.052.079-.052.074-.052.07-.051.065-.051.06-.051.056-.05.051-.049.023-.025.023-.025.021-.024.02-.024.019-.024.018-.024.017-.024.015-.023.014-.024.013-.023.012-.023.01-.022.01-.023.008-.022.006-.022.006-.022.004-.022.004-.021.001-.021.001-.021v-4.153l-.077.054-.08.054-.083.053-.085.053-.087.053-.09.051-.093.051-.095.051-.097.05-.1.049-.102.048-.105.048-.106.048-.109.046-.111.046-.114.046-.115.044-.118.044-.12.043-.122.043-.124.042-.126.041-.128.04-.13.039-.132.039-.134.038-.135.037-.138.036-.139.036-.142.034-.143.034-.144.033-.147.032-.148.032-.15.03-.151.03-.153.028-.154.028-.156.027-.158.026-.159.024-.161.024-.162.023-.163.023-.165.021-.166.02-.167.019-.169.018-.169.017-.171.016-.173.015-.173.014-.175.013-.175.012-.177.01-.178.01-.179.009-.179.007-.181.006-.182.006-.182.004-.184.003-.184.001-.185.001-.185-.001-.184-.001-.184-.003-.182-.004-.182-.006-.181-.006-.179-.007-.179-.009-.178-.01-.176-.01-.176-.012-.175-.013-.173-.014-.172-.015-.171-.016-.17-.017-.169-.018-.167-.019-.166-.02-.165-.021-.163-.023-.162-.023-.161-.024-.159-.024-.157-.026-.156-.027-.155-.028-.153-.028-.151-.03-.15-.03-.148-.032-.146-.032-.145-.033-.143-.034-.141-.034-.14-.036-.137-.036-.136-.037-.134-.038-.132-.039-.13-.039-.128-.041-.126-.041-.124-.041-.122-.043-.12-.043-.117-.044-.116-.044-.113-.046-.112-.046-.109-.046-.106-.048-.105-.048-.102-.048-.1-.05-.097-.049-.095-.051-.093-.051-.09-.052-.087-.052-.085-.053-.083-.053-.08-.054-.077-.054v4.153zm8.74-8.179l-.257.004-.254.005-.25.008-.247.011-.244.012-.241.014-.237.016-.233.018-.231.021-.226.022-.224.023-.22.026-.216.027-.212.028-.21.031-.205.032-.202.033-.198.034-.194.036-.191.038-.187.038-.183.04-.179.041-.175.042-.172.043-.168.043-.163.045-.16.046-.155.046-.152.048-.148.048-.143.048-.139.049-.136.05-.131.05-.126.051-.123.051-.118.051-.114.052-.11.052-.106.052-.101.052-.096.052-.092.052-.088.052-.083.052-.079.052-.074.051-.07.052-.065.051-.06.05-.056.05-.051.05-.023.025-.023.024-.021.024-.02.025-.019.024-.018.024-.017.023-.015.024-.014.023-.013.023-.012.023-.01.023-.01.022-.008.022-.006.023-.006.021-.004.022-.004.021-.001.021-.001.021.001.021.001.021.004.021.004.022.006.021.006.023.008.022.01.022.01.023.012.023.013.023.014.023.015.024.017.023.018.024.019.024.02.025.021.024.023.024.023.025.051.05.056.05.06.05.065.051.07.052.074.051.079.052.083.052.088.052.092.052.096.052.101.052.106.052.11.052.114.052.118.051.123.051.126.051.131.05.136.05.139.049.143.048.148.048.152.048.155.046.16.046.163.045.168.043.172.043.175.042.179.041.183.04.187.038.191.038.194.036.198.034.202.033.205.032.21.031.212.028.216.027.22.026.224.023.226.022.231.021.233.018.237.016.241.014.244.012.247.011.25.008.254.005.257.004.26.001.26-.001.257-.004.254-.005.25-.008.247-.011.244-.012.241-.014.237-.016.233-.018.231-.021.226-.022.224-.023.22-.026.216-.027.212-.028.21-.031.205-.032.202-.033.198-.034.194-.036.191-.038.187-.038.183-.04.179-.041.175-.042.172-.043.168-.043.163-.045.16-.046.155-.046.152-.048.148-.048.143-.048.139-.049.136-.05.131-.05.126-.051.123-.051.118-.051.114-.052.11-.052.106-.052.101-.052.096-.052.092-.052.088-.052.083-.052.079-.052.074-.051.07-.052.065-.051.06-.05.056-.05.051-.05.023-.025.023-.024.021-.024.02-.025.019-.024.018-.024.017-.023.015-.024.014-.023.013-.023.012-.023.01-.023.01-.022.008-.022.006-.023.006-.021.004-.022.004-.021.001-.021.001-.021-.001-.021-.001-.021-.004-.021-.004-.022-.006-.021-.006-.023-.008-.022-.01-.022-.01-.023-.012-.023-.013-.023-.014-.023-.015-.024-.017-.023-.018-.024-.019-.024-.02-.025-.021-.024-.023-.024-.023-.025-.051-.05-.056-.05-.06-.05-.065-.051-.07-.052-.074-.051-.079-.052-.083-.052-.088-.052-.092-.052-.096-.052-.101-.052-.106-.052-.11-.052-.114-.052-.118-.051-.123-.051-.126-.051-.131-.05-.136-.05-.139-.049-.143-.048-.148-.048-.152-.048-.155-.046-.16-.046-.163-.045-.168-.043-.172-.043-.175-.042-.179-.041-.183-.04-.187-.038-.191-.038-.194-.036-.198-.034-.202-.033-.205-.032-.21-.031-.212-.028-.216-.027-.22-.026-.224-.023-.226-.022-.231-.021-.233-.018-.237-.016-.241-.014-.244-.012-.247-.011-.25-.008-.254-.005-.257-.004-.26-.001-.26.001z")},Xit=function(t){t.append("defs").append("symbol").attr("id","computer").attr("width","24").attr("height","24").append("path").attr("transform","scale(.5)").attr("d","M2 2v13h20v-13h-20zm18 11h-16v-9h16v9zm-10.228 6l.466-1h3.524l.467 1h-4.457zm14.228 3h-24l2-6h2.104l-1.33 4h18.45l-1.297-4h2.073l2 6zm-5-10h-14v-7h14v7z")},Kit=function(t){t.append("defs").append("symbol").attr("id","clock").attr("width","24").attr("height","24").append("path").attr("transform","scale(.5)").attr("d","M12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm5.848 12.459c.202.038.202.333.001.372-1.907.361-6.045 1.111-6.547 1.111-.719 0-1.301-.582-1.301-1.301 0-.512.77-5.447 1.125-7.445.034-.192.312-.181.343.014l.985 6.238 5.394 1.011z")},Zit=function(t){t.append("defs").append("marker").attr("id","arrowhead").attr("refX",9).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",12).attr("markerHeight",12).attr("orient","auto").append("path").attr("d","M 0 0 L 10 5 L 0 10 z")},Qit=function(t){t.append("defs").append("marker").attr("id","filled-head").attr("refX",18).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L14,7 L9,1 Z")},Jit=function(t){t.append("defs").append("marker").attr("id","sequencenumber").attr("refX",15).attr("refY",15).attr("markerWidth",60).attr("markerHeight",40).attr("orient","auto").append("circle").attr("cx",15).attr("cy",15).attr("r",6)},tat=function(t){const r=t.append("defs").append("marker").attr("id","crosshead").attr("markerWidth",15).attr("markerHeight",8).attr("orient","auto").attr("refX",16).attr("refY",4);r.append("path").attr("fill","black").attr("stroke","#000000").style("stroke-dasharray","0, 0").attr("stroke-width","1px").attr("d","M 9,2 V 6 L16,4 Z"),r.append("path").attr("fill","none").attr("stroke","#000000").style("stroke-dasharray","0, 0").attr("stroke-width","1px").attr("d","M 0,1 L 6,7 M 6,1 L 0,7")},K4=function(){return{x:0,y:0,fill:void 0,anchor:void 0,style:"#666",width:void 0,height:void 0,textMargin:0,rx:0,ry:0,tspan:!0,valign:void 0}},f0=function(){return{x:0,y:0,fill:"#EDF2AE",stroke:"#666",width:100,anchor:"start",height:100,rx:0,ry:0}},TL=function(){function t(i,a,s,o,l,u,h){const d=a.append("text").attr("x",s+l/2).attr("y",o+u/2+5).style("text-anchor","middle").text(i);n(d,h)}function e(i,a,s,o,l,u,h,d){const{actorFontSize:f,actorFontFamily:p,actorFontWeight:m}=d;let _=f&&f.replace?f.replace("px",""):f;const y=i.split(pe.lineBreakRegex);for(let b=0;b<y.length;b++){const x=b*_-_*(y.length-1)/2,k=a.append("text").attr("x",s+l/2).attr("y",o).style("text-anchor","middle").style("font-size",f).style("font-weight",m).style("font-family",p);k.append("tspan").attr("x",s+l/2).attr("dy",x).text(y[b]),k.attr("y",o+u/2).attr("dominant-baseline","central").attr("alignment-baseline","central"),n(k,h)}}function r(i,a,s,o,l,u,h,d){const f=a.append("switch"),m=f.append("foreignObject").attr("x",s).attr("y",o).attr("width",l).attr("height",u).append("xhtml:div").style("display","table").style("height","100%").style("width","100%");m.append("div").style("display","table-cell").style("text-align","center").style("vertical-align","middle").text(i),e(i,f,s,o,l,u,h,d),n(m,h)}function n(i,a){for(const s in a)a.hasOwnProperty(s)&&i.attr(s,a[s])}return function(i){return i.textPlacement==="fo"?r:i.textPlacement==="old"?t:e}}(),eat=function(){function t(i,a,s,o,l,u,h){const d=a.append("text").attr("x",s).attr("y",o).style("text-anchor","start").text(i);n(d,h)}function e(i,a,s,o,l,u,h,d){const{actorFontSize:f,actorFontFamily:p,actorFontWeight:m}=d,_=i.split(pe.lineBreakRegex);for(let y=0;y<_.length;y++){const b=y*f-f*(_.length-1)/2,x=a.append("text").attr("x",s).attr("y",o).style("text-anchor","start").style("font-size",f).style("font-weight",m).style("font-family",p);x.append("tspan").attr("x",s).attr("dy",b).text(_[y]),x.attr("y",o+u/2).attr("dominant-baseline","central").attr("alignment-baseline","central"),n(x,h)}}function r(i,a,s,o,l,u,h,d){const f=a.append("switch"),m=f.append("foreignObject").attr("x",s).attr("y",o).attr("width",l).attr("height",u).append("xhtml:div").style("display","table").style("height","100%").style("width","100%");m.append("div").style("display","table-cell").style("text-align","center").style("vertical-align","middle").text(i),e(i,f,s,o,l,u,h,d),n(m,h)}function n(i,a){for(const s in a)a.hasOwnProperty(s)&&i.attr(s,a[s])}return function(i){return i.textPlacement==="fo"?r:i.textPlacement==="old"?t:e}}(),or={drawRect:h0,drawText:hl,drawLabel:kL,drawActor:Uit,drawPopup:Oit,drawImage:vL,drawEmbeddedImage:xL,anchorElement:Wit,drawActivation:Hit,drawLoop:Git,drawBackgroundRect:jit,insertArrowHead:Zit,insertArrowFilledHead:Qit,insertSequenceNumber:Jit,insertArrowCrossHead:tat,insertDatabaseIcon:$it,insertComputerIcon:Xit,insertClockIcon:Kit,getTextObj:K4,getNoteRect:f0,popupMenu:Fit,popdownMenu:Pit,fixLifeLineHeights:wL,sanitizeUrl:ki};let dt={};const Bt={data:{startx:void 0,stopx:void 0,starty:void 0,stopy:void 0},verticalPos:0,sequenceItems:[],activations:[],models:{getHeight:function(){return Math.max.apply(null,this.actors.length===0?[0]:this.actors.map(t=>t.height||0))+(this.loops.length===0?0:this.loops.map(t=>t.height||0).reduce((t,e)=>t+e))+(this.messages.length===0?0:this.messages.map(t=>t.height||0).reduce((t,e)=>t+e))+(this.notes.length===0?0:this.notes.map(t=>t.height||0).reduce((t,e)=>t+e))},clear:function(){this.actors=[],this.loops=[],this.messages=[],this.notes=[]},addActor:function(t){this.actors.push(t)},addLoop:function(t){this.loops.push(t)},addMessage:function(t){this.messages.push(t)},addNote:function(t){this.notes.push(t)},lastActor:function(){return this.actors[this.actors.length-1]},lastLoop:function(){return this.loops[this.loops.length-1]},lastMessage:function(){return this.messages[this.messages.length-1]},lastNote:function(){return this.notes[this.notes.length-1]},actors:[],loops:[],messages:[],notes:[]},init:function(){this.sequenceItems=[],this.activations=[],this.models.clear(),this.data={startx:void 0,stopx:void 0,starty:void 0,stopy:void 0},this.verticalPos=0,CL(nt())},updateVal:function(t,e,r,n){typeof t[e]>"u"?t[e]=r:t[e]=n(r,t[e])},updateBounds:function(t,e,r,n){const i=this;let a=0;function s(o){return function(u){a++;const h=i.sequenceItems.length-a+1;i.updateVal(u,"starty",e-h*dt.boxMargin,Math.min),i.updateVal(u,"stopy",n+h*dt.boxMargin,Math.max),i.updateVal(Bt.data,"startx",t-h*dt.boxMargin,Math.min),i.updateVal(Bt.data,"stopx",r+h*dt.boxMargin,Math.max),o!=="activation"&&(i.updateVal(u,"startx",t-h*dt.boxMargin,Math.min),i.updateVal(u,"stopx",r+h*dt.boxMargin,Math.max),i.updateVal(Bt.data,"starty",e-h*dt.boxMargin,Math.min),i.updateVal(Bt.data,"stopy",n+h*dt.boxMargin,Math.max))}}this.sequenceItems.forEach(s()),this.activations.forEach(s("activation"))},insert:function(t,e,r,n){const i=Math.min(t,r),a=Math.max(t,r),s=Math.min(e,n),o=Math.max(e,n);this.updateVal(Bt.data,"startx",i,Math.min),this.updateVal(Bt.data,"starty",s,Math.min),this.updateVal(Bt.data,"stopx",a,Math.max),this.updateVal(Bt.data,"stopy",o,Math.max),this.updateBounds(i,s,a,o)},newActivation:function(t,e,r){const n=r[t.from.actor],i=d0(t.from.actor).length||0,a=n.x+n.width/2+(i-1)*dt.activationWidth/2;this.activations.push({startx:a,starty:this.verticalPos+2,stopx:a+dt.activationWidth,stopy:void 0,actor:t.from.actor,anchored:or.anchorElement(e)})},endActivation:function(t){const e=this.activations.map(function(r){return r.actor}).lastIndexOf(t.from.actor);return this.activations.splice(e,1)[0]},createLoop:function(t={message:void 0,wrap:!1,width:void 0},e){return{startx:void 0,starty:this.verticalPos,stopx:void 0,stopy:void 0,title:t.message,wrap:t.wrap,width:t.width,height:0,fill:e}},newLoop:function(t={message:void 0,wrap:!1,width:void 0},e){this.sequenceItems.push(this.createLoop(t,e))},endLoop:function(){return this.sequenceItems.pop()},addSectionToLoop:function(t){const e=this.sequenceItems.pop();e.sections=e.sections||[],e.sectionTitles=e.sectionTitles||[],e.sections.push({y:Bt.getVerticalPos(),height:0}),e.sectionTitles.push(t),this.sequenceItems.push(e)},bumpVerticalPos:function(t){this.verticalPos=this.verticalPos+t,this.data.stopy=this.verticalPos},getVerticalPos:function(){return this.verticalPos},getBounds:function(){return{bounds:this.data,models:this.models}}},rat=function(t,e){Bt.bumpVerticalPos(dt.boxMargin),e.height=dt.boxMargin,e.starty=Bt.getVerticalPos();const r=or.getNoteRect();r.x=e.startx,r.y=e.starty,r.width=e.width||dt.width,r.class="note";const n=t.append("g"),i=or.drawRect(n,r),a=or.getTextObj();a.x=e.startx,a.y=e.starty,a.width=r.width,a.dy="1em",a.text=e.message,a.class="noteText",a.fontFamily=dt.noteFontFamily,a.fontSize=dt.noteFontSize,a.fontWeight=dt.noteFontWeight,a.anchor=dt.noteAlign,a.textMargin=dt.noteMargin,a.valign="center";const s=hl(n,a),o=Math.round(s.map(l=>(l._groups||l)[0][0].getBBox().height).reduce((l,u)=>l+u));i.attr("height",o+2*dt.noteMargin),e.height+=o+2*dt.noteMargin,Bt.bumpVerticalPos(o+2*dt.noteMargin),e.stopy=e.starty+o+2*dt.noteMargin,e.stopx=e.startx+r.width,Bt.insert(e.startx,e.starty,e.stopx,e.stopy),Bt.models.addNote(e)},fl=t=>({fontFamily:t.messageFontFamily,fontSize:t.messageFontSize,fontWeight:t.messageFontWeight}),dl=t=>({fontFamily:t.noteFontFamily,fontSize:t.noteFontSize,fontWeight:t.noteFontWeight}),Z4=t=>({fontFamily:t.actorFontFamily,fontSize:t.actorFontSize,fontWeight:t.actorFontWeight}),nat=function(t,e){Bt.bumpVerticalPos(10);const{startx:r,stopx:n,message:i}=e,a=pe.splitBreaks(i).length,s=Se.calculateTextDimensions(i,fl(dt)),o=s.height/a;e.height+=o,Bt.bumpVerticalPos(o);let l,u=s.height-10;const h=s.width;if(r===n){l=Bt.getVerticalPos()+u,dt.rightAngles||(u+=dt.boxMargin,l=Bt.getVerticalPos()+u),u+=30;const d=Math.max(h/2,dt.width/2);Bt.insert(r-d,Bt.getVerticalPos()-10+u,n+d,Bt.getVerticalPos()+30+u)}else u+=dt.boxMargin,l=Bt.getVerticalPos()+u,Bt.insert(r,l-10,n,l);return Bt.bumpVerticalPos(u),e.height+=u,e.stopy=e.starty+e.height,Bt.insert(e.fromBounds,e.starty,e.toBounds,e.stopy),l},iat=function(t,e,r,n){const{startx:i,stopx:a,starty:s,message:o,type:l,sequenceIndex:u,sequenceVisible:h}=e,d=Se.calculateTextDimensions(o,fl(dt)),f=or.getTextObj();f.x=i,f.y=s+10,f.width=a-i,f.class="messageText",f.dy="1em",f.text=o,f.fontFamily=dt.messageFontFamily,f.fontSize=dt.messageFontSize,f.fontWeight=dt.messageFontWeight,f.anchor=dt.messageAlign,f.valign="center",f.textMargin=dt.wrapPadding,f.tspan=!1,hl(t,f);const p=d.width;let m;i===a?dt.rightAngles?m=t.append("path").attr("d",`M ${i},${r} H ${i+Math.max(dt.width/2,p/2)} V ${r+25} H ${i}`):m=t.append("path").attr("d","M "+i+","+r+" C "+(i+60)+","+(r-10)+" "+(i+60)+","+(r+30)+" "+i+","+(r+20)):(m=t.append("line"),m.attr("x1",i),m.attr("y1",r),m.attr("x2",a),m.attr("y2",r)),l===n.db.LINETYPE.DOTTED||l===n.db.LINETYPE.DOTTED_CROSS||l===n.db.LINETYPE.DOTTED_POINT||l===n.db.LINETYPE.DOTTED_OPEN?(m.style("stroke-dasharray","3, 3"),m.attr("class","messageLine1")):m.attr("class","messageLine0");let _="";dt.arrowMarkerAbsolute&&(_=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,_=_.replace(/\(/g,"\\("),_=_.replace(/\)/g,"\\)")),m.attr("stroke-width",2),m.attr("stroke","none"),m.style("fill","none"),(l===n.db.LINETYPE.SOLID||l===n.db.LINETYPE.DOTTED)&&m.attr("marker-end","url("+_+"#arrowhead)"),(l===n.db.LINETYPE.SOLID_POINT||l===n.db.LINETYPE.DOTTED_POINT)&&m.attr("marker-end","url("+_+"#filled-head)"),(l===n.db.LINETYPE.SOLID_CROSS||l===n.db.LINETYPE.DOTTED_CROSS)&&m.attr("marker-end","url("+_+"#crosshead)"),(h||dt.showSequenceNumbers)&&(m.attr("marker-start","url("+_+"#sequencenumber)"),t.append("text").attr("x",i).attr("y",r+4).attr("font-family","sans-serif").attr("font-size","12px").attr("text-anchor","middle").attr("class","sequenceNumber").text(u))},Q4=function(t,e,r,n,i,a){if(i.hideUnusedParticipants===!0){const u=new Set;a.forEach(h=>{u.add(h.from),u.add(h.to)}),r=r.filter(h=>u.has(h))}let s=0,o=0,l=0;for(let u=0;u<r.length;u++){const h=e[r[u]];h.width=h.width||dt.width,h.height=Math.max(h.height||dt.height,dt.height),h.margin=h.margin||dt.actorMargin,h.x=s+o,h.y=n;const d=or.drawActor(t,h,dt);l=Math.max(l,d),Bt.insert(h.x,n,h.x+h.width,h.height),s+=h.width,o+=h.margin,Bt.models.addActor(h)}Bt.bumpVerticalPos(l)},EL=function(t,e,r,n){let i=0,a=0;for(let s=0;s<r.length;s++){const o=e[r[s]],l=oat(o),u=or.drawPopup(t,o,l,dt,dt.forceMenus,n);u.height>i&&(i=u.height),u.width+o.x>a&&(a=u.width+o.x)}return{maxHeight:i,maxWidth:a}},CL=function(t){fr(dt,t),t.fontFamily&&(dt.actorFontFamily=dt.noteFontFamily=dt.messageFontFamily=t.fontFamily),t.fontSize&&(dt.actorFontSize=dt.noteFontSize=dt.messageFontSize=t.fontSize),t.fontWeight&&(dt.actorFontWeight=dt.noteFontWeight=dt.messageFontWeight=t.fontWeight)},d0=function(t){return Bt.activations.filter(function(e){return e.actor===t})},SL=function(t,e){const r=e[t],n=d0(t),i=n.reduce(function(s,o){return Math.min(s,o.startx)},r.x+r.width/2),a=n.reduce(function(s,o){return Math.max(s,o.stopx)},r.x+r.width/2);return[i,a]};function Ui(t,e,r,n,i){Bt.bumpVerticalPos(r);let a=n;if(e.id&&e.message&&t[e.id]){const s=t[e.id].width,o=fl(dt);e.message=Se.wrapLabel(`[${e.message}]`,s-2*dt.wrapPadding,o),e.width=s,e.wrap=!0;const l=Se.calculateTextDimensions(e.message,o),u=Math.max(l.height,dt.labelBoxHeight);a=n+u,H.debug(`${u} - ${e.message}`)}i(e),Bt.bumpVerticalPos(a)}const aat=function(t,e,r,n){const{securityLevel:i,sequence:a}=nt();dt=a;let s;i==="sandbox"&&(s=St("#i"+e));const o=St(i==="sandbox"?s.nodes()[0].contentDocument.body:"body"),l=i==="sandbox"?s.nodes()[0].contentDocument:document;Bt.init(),H.debug(n.db);const u=i==="sandbox"?o.select(`[id="${e}"]`):St(`[id="${e}"]`),h=n.db.getActors(),d=n.db.getActorKeys(),f=n.db.getMessages(),p=n.db.getDiagramTitle(),m=sat(h,f,n);dt.height=lat(h,m),or.insertComputerIcon(u),or.insertDatabaseIcon(u),or.insertClockIcon(u),Q4(u,h,d,0,dt,f);const _=hat(f,h,m,n);or.insertArrowHead(u),or.insertArrowCrossHead(u),or.insertArrowFilledHead(u),or.insertSequenceNumber(u);function y(B,w){const D=Bt.endActivation(B);D.starty+18>w&&(D.starty=w-6,w+=12),or.drawActivation(u,D,w,dt,d0(B.from.actor).length),Bt.insert(D.startx,w-10,D.stopx,w)}let b=1,x=1;const k=[];f.forEach(function(B){let w,D,N;switch(B.type){case n.db.LINETYPE.NOTE:D=B.noteModel,rat(u,D);break;case n.db.LINETYPE.ACTIVE_START:Bt.newActivation(B,u,h);break;case n.db.LINETYPE.ACTIVE_END:y(B,Bt.getVerticalPos());break;case n.db.LINETYPE.LOOP_START:Ui(_,B,dt.boxMargin,dt.boxMargin+dt.boxTextMargin,z=>Bt.newLoop(z));break;case n.db.LINETYPE.LOOP_END:w=Bt.endLoop(),or.drawLoop(u,w,"loop",dt),Bt.bumpVerticalPos(w.stopy-Bt.getVerticalPos()),Bt.models.addLoop(w);break;case n.db.LINETYPE.RECT_START:Ui(_,B,dt.boxMargin,dt.boxMargin,z=>Bt.newLoop(void 0,z.message));break;case n.db.LINETYPE.RECT_END:w=Bt.endLoop(),or.drawBackgroundRect(u,w),Bt.models.addLoop(w),Bt.bumpVerticalPos(w.stopy-Bt.getVerticalPos());break;case n.db.LINETYPE.OPT_START:Ui(_,B,dt.boxMargin,dt.boxMargin+dt.boxTextMargin,z=>Bt.newLoop(z));break;case n.db.LINETYPE.OPT_END:w=Bt.endLoop(),or.drawLoop(u,w,"opt",dt),Bt.bumpVerticalPos(w.stopy-Bt.getVerticalPos()),Bt.models.addLoop(w);break;case n.db.LINETYPE.ALT_START:Ui(_,B,dt.boxMargin,dt.boxMargin+dt.boxTextMargin,z=>Bt.newLoop(z));break;case n.db.LINETYPE.ALT_ELSE:Ui(_,B,dt.boxMargin+dt.boxTextMargin,dt.boxMargin,z=>Bt.addSectionToLoop(z));break;case n.db.LINETYPE.ALT_END:w=Bt.endLoop(),or.drawLoop(u,w,"alt",dt),Bt.bumpVerticalPos(w.stopy-Bt.getVerticalPos()),Bt.models.addLoop(w);break;case n.db.LINETYPE.PAR_START:Ui(_,B,dt.boxMargin,dt.boxMargin+dt.boxTextMargin,z=>Bt.newLoop(z));break;case n.db.LINETYPE.PAR_AND:Ui(_,B,dt.boxMargin+dt.boxTextMargin,dt.boxMargin,z=>Bt.addSectionToLoop(z));break;case n.db.LINETYPE.PAR_END:w=Bt.endLoop(),or.drawLoop(u,w,"par",dt),Bt.bumpVerticalPos(w.stopy-Bt.getVerticalPos()),Bt.models.addLoop(w);break;case n.db.LINETYPE.AUTONUMBER:b=B.message.start||b,x=B.message.step||x,B.message.visible?n.db.enableSequenceNumbers():n.db.disableSequenceNumbers();break;case n.db.LINETYPE.CRITICAL_START:Ui(_,B,dt.boxMargin,dt.boxMargin+dt.boxTextMargin,z=>Bt.newLoop(z));break;case n.db.LINETYPE.CRITICAL_OPTION:Ui(_,B,dt.boxMargin+dt.boxTextMargin,dt.boxMargin,z=>Bt.addSectionToLoop(z));break;case n.db.LINETYPE.CRITICAL_END:w=Bt.endLoop(),or.drawLoop(u,w,"critical",dt),Bt.bumpVerticalPos(w.stopy-Bt.getVerticalPos()),Bt.models.addLoop(w);break;case n.db.LINETYPE.BREAK_START:Ui(_,B,dt.boxMargin,dt.boxMargin+dt.boxTextMargin,z=>Bt.newLoop(z));break;case n.db.LINETYPE.BREAK_END:w=Bt.endLoop(),or.drawLoop(u,w,"break",dt),Bt.bumpVerticalPos(w.stopy-Bt.getVerticalPos()),Bt.models.addLoop(w);break;default:try{N=B.msgModel,N.starty=Bt.getVerticalPos(),N.sequenceIndex=b,N.sequenceVisible=n.db.showSequenceNumbers();const z=nat(u,N);k.push({messageModel:N,lineStarty:z}),Bt.models.addMessage(N)}catch(z){H.error("error while drawing message",z)}}[n.db.LINETYPE.SOLID_OPEN,n.db.LINETYPE.DOTTED_OPEN,n.db.LINETYPE.SOLID,n.db.LINETYPE.DOTTED,n.db.LINETYPE.SOLID_CROSS,n.db.LINETYPE.DOTTED_CROSS,n.db.LINETYPE.SOLID_POINT,n.db.LINETYPE.DOTTED_POINT].includes(B.type)&&(b=b+x)}),k.forEach(B=>iat(u,B.messageModel,B.lineStarty,n)),dt.mirrorActors&&(Bt.bumpVerticalPos(dt.boxMargin*2),Q4(u,h,d,Bt.getVerticalPos(),dt,f),Bt.bumpVerticalPos(dt.boxMargin),wL(u,Bt.getVerticalPos()));const T=EL(u,h,d,l),{bounds:C}=Bt.getBounds();H.debug("For line height fix Querying: #"+e+" .actor-line"),Nu("#"+e+" .actor-line").attr("y2",C.stopy);let S=C.stopy-C.starty;S<T.maxHeight&&(S=T.maxHeight);let R=S+2*dt.diagramMarginY;dt.mirrorActors&&(R=R-dt.boxMargin+dt.bottomMarginAdj);let A=C.stopx-C.startx;A<T.maxWidth&&(A=T.maxWidth);const L=A+2*dt.diagramMarginX;p&&u.append("text").text(p).attr("x",(C.stopx-C.startx)/2-2*dt.diagramMarginX).attr("y",-25),li(u,R,L,dt.useMaxWidth);const v=p?40:0;u.attr("viewBox",C.startx-dt.diagramMarginX+" -"+(dt.diagramMarginY+v)+" "+L+" "+(R+v)),bn(n.db,u,e),H.debug("models:",Bt.models)},sat=function(t,e,r){const n={};return e.forEach(function(i){if(t[i.to]&&t[i.from]){const a=t[i.to];if(i.placement===r.db.PLACEMENT.LEFTOF&&!a.prevActor||i.placement===r.db.PLACEMENT.RIGHTOF&&!a.nextActor)return;const s=i.placement!==void 0,o=!s,l=s?dl(dt):fl(dt),u=i.wrap?Se.wrapLabel(i.message,dt.width-2*dt.wrapPadding,l):i.message,d=Se.calculateTextDimensions(u,l).width+2*dt.wrapPadding;o&&i.from===a.nextActor?n[i.to]=Math.max(n[i.to]||0,d):o&&i.from===a.prevActor?n[i.from]=Math.max(n[i.from]||0,d):o&&i.from===i.to?(n[i.from]=Math.max(n[i.from]||0,d/2),n[i.to]=Math.max(n[i.to]||0,d/2)):i.placement===r.db.PLACEMENT.RIGHTOF?n[i.from]=Math.max(n[i.from]||0,d):i.placement===r.db.PLACEMENT.LEFTOF?n[a.prevActor]=Math.max(n[a.prevActor]||0,d):i.placement===r.db.PLACEMENT.OVER&&(a.prevActor&&(n[a.prevActor]=Math.max(n[a.prevActor]||0,d/2)),a.nextActor&&(n[i.from]=Math.max(n[i.from]||0,d/2)))}}),H.debug("maxMessageWidthPerActor:",n),n},oat=function(t){let e=0;const r=Z4(dt);for(const n in t.links){const a=Se.calculateTextDimensions(n,r).width+2*dt.wrapPadding+2*dt.boxMargin;e<a&&(e=a)}return e},lat=function(t,e){let r=0;Object.keys(t).forEach(n=>{const i=t[n];i.wrap&&(i.description=Se.wrapLabel(i.description,dt.width-2*dt.wrapPadding,Z4(dt)));const a=Se.calculateTextDimensions(i.description,Z4(dt));i.width=i.wrap?dt.width:Math.max(dt.width,a.width+2*dt.wrapPadding),i.height=i.wrap?Math.max(a.height,dt.height):dt.height,r=Math.max(r,i.height)});for(const n in e){const i=t[n];if(!i)continue;const a=t[i.nextActor];if(!a)continue;const o=e[n]+dt.actorMargin-i.width/2-a.width/2;i.margin=Math.max(o,dt.actorMargin)}return Math.max(r,dt.height)},cat=function(t,e,r){const n=e[t.from].x,i=e[t.to].x,a=t.wrap&&t.message;let s=Se.calculateTextDimensions(a?Se.wrapLabel(t.message,dt.width,dl(dt)):t.message,dl(dt));const o={width:a?dt.width:Math.max(dt.width,s.width+2*dt.noteMargin),height:0,startx:e[t.from].x,stopx:0,starty:0,stopy:0,message:t.message};return t.placement===r.db.PLACEMENT.RIGHTOF?(o.width=a?Math.max(dt.width,s.width):Math.max(e[t.from].width/2+e[t.to].width/2,s.width+2*dt.noteMargin),o.startx=n+(e[t.from].width+dt.actorMargin)/2):t.placement===r.db.PLACEMENT.LEFTOF?(o.width=Math.max(a?dt.width:e[t.from].width/2+e[t.to].width/2,s.width+2*dt.noteMargin),o.startx=n-o.width+(e[t.from].width-dt.actorMargin)/2):t.to===t.from?(s=Se.calculateTextDimensions(a?Se.wrapLabel(t.message,Math.max(dt.width,e[t.from].width),dl(dt)):t.message,dl(dt)),o.width=a?Math.max(dt.width,e[t.from].width):Math.max(e[t.from].width,dt.width,s.width+2*dt.noteMargin),o.startx=n+(e[t.from].width-o.width)/2):(o.width=Math.abs(n+e[t.from].width/2-(i+e[t.to].width/2))+dt.actorMargin,o.startx=n<i?n+e[t.from].width/2-dt.actorMargin/2:i+e[t.to].width/2-dt.actorMargin/2),a&&(o.message=Se.wrapLabel(t.message,o.width-2*dt.wrapPadding,dl(dt))),H.debug(`NM:[${o.startx},${o.stopx},${o.starty},${o.stopy}:${o.width},${o.height}=${t.message}]`),o},uat=function(t,e,r){let n=!1;if([r.db.LINETYPE.SOLID_OPEN,r.db.LINETYPE.DOTTED_OPEN,r.db.LINETYPE.SOLID,r.db.LINETYPE.DOTTED,r.db.LINETYPE.SOLID_CROSS,r.db.LINETYPE.DOTTED_CROSS,r.db.LINETYPE.SOLID_POINT,r.db.LINETYPE.DOTTED_POINT].includes(t.type)&&(n=!0),!n)return{};const i=SL(t.from,e),a=SL(t.to,e),s=i[0]<=a[0]?1:0,o=i[0]<a[0]?0:1,l=i.concat(a),u=Math.abs(a[o]-i[s]);t.wrap&&t.message&&(t.message=Se.wrapLabel(t.message,Math.max(u+2*dt.wrapPadding,dt.width),fl(dt)));const h=Se.calculateTextDimensions(t.message,fl(dt));return{width:Math.max(t.wrap?0:h.width+2*dt.wrapPadding,u+2*dt.wrapPadding,dt.width),height:0,startx:i[s],stopx:a[o],starty:0,stopy:0,message:t.message,type:t.type,wrap:t.wrap,fromBounds:Math.min.apply(null,l),toBounds:Math.max.apply(null,l)}},hat=function(t,e,r,n){const i={},a=[];let s,o,l;return t.forEach(function(u){switch(u.id=Se.random({length:10}),u.type){case n.db.LINETYPE.LOOP_START:case n.db.LINETYPE.ALT_START:case n.db.LINETYPE.OPT_START:case n.db.LINETYPE.PAR_START:case n.db.LINETYPE.CRITICAL_START:case n.db.LINETYPE.BREAK_START:a.push({id:u.id,msg:u.message,from:Number.MAX_SAFE_INTEGER,to:Number.MIN_SAFE_INTEGER,width:0});break;case n.db.LINETYPE.ALT_ELSE:case n.db.LINETYPE.PAR_AND:case n.db.LINETYPE.CRITICAL_OPTION:u.message&&(s=a.pop(),i[s.id]=s,i[u.id]=s,a.push(s));break;case n.db.LINETYPE.LOOP_END:case n.db.LINETYPE.ALT_END:case n.db.LINETYPE.OPT_END:case n.db.LINETYPE.PAR_END:case n.db.LINETYPE.CRITICAL_END:case n.db.LINETYPE.BREAK_END:s=a.pop(),i[s.id]=s;break;case n.db.LINETYPE.ACTIVE_START:{const d=e[u.from?u.from.actor:u.to.actor],f=d0(u.from?u.from.actor:u.to.actor).length,p=d.x+d.width/2+(f-1)*dt.activationWidth/2,m={startx:p,stopx:p+dt.activationWidth,actor:u.from.actor,enabled:!0};Bt.activations.push(m)}break;case n.db.LINETYPE.ACTIVE_END:{const d=Bt.activations.map(f=>f.actor).lastIndexOf(u.from.actor);delete Bt.activations.splice(d,1)[0]}break}u.placement!==void 0?(o=cat(u,e,n),u.noteModel=o,a.forEach(d=>{s=d,s.from=Math.min(s.from,o.startx),s.to=Math.max(s.to,o.startx+o.width),s.width=Math.max(s.width,Math.abs(s.from-s.to))-dt.labelBoxWidth})):(l=uat(u,e,n),u.msgModel=l,l.startx&&l.stopx&&a.length>0&&a.forEach(d=>{if(s=d,l.startx===l.stopx){const f=e[u.from],p=e[u.to];s.from=Math.min(f.x-l.width/2,f.x-f.width/2,s.from),s.to=Math.max(p.x+l.width/2,p.x+f.width/2,s.to),s.width=Math.max(s.width,Math.abs(s.to-s.from))-dt.labelBoxWidth}else s.from=Math.min(l.startx,s.from),s.to=Math.max(l.stopx,s.to),s.width=Math.max(s.width,l.width)-dt.labelBoxWidth}))}),Bt.activations=[],H.debug("Loop type widths:",i),i},AL={bounds:Bt,drawActors:Q4,drawActorsPopup:EL,setConf:CL,draw:aat};var p0=function(){var t=function(ct,J,Y,$){for(Y=Y||{},$=ct.length;$--;Y[ct[$]]=J);return Y},e=[1,2],r=[1,3],n=[1,5],i=[1,7],a=[2,5],s=[1,15],o=[1,17],l=[1,19],u=[1,20],h=[1,21],d=[1,22],f=[1,33],p=[1,23],m=[1,24],_=[1,25],y=[1,26],b=[1,27],x=[1,30],k=[1,31],T=[1,32],C=[1,35],M=[1,36],S=[1,37],R=[1,38],A=[1,34],L=[1,41],v=[1,4,5,14,15,17,19,20,22,23,24,25,26,27,31,33,35,41,42,43,44,47,50],B=[1,4,5,12,13,14,15,17,19,20,22,23,24,25,26,27,31,33,35,41,42,43,44,47,50],w=[1,4,5,7,14,15,17,19,20,22,23,24,25,26,27,31,33,35,41,42,43,44,47,50],D=[4,5,14,15,17,19,20,22,23,24,25,26,27,31,33,35,41,42,43,44,47,50],N={trace:function(){},yy:{},symbols_:{error:2,start:3,SPACE:4,NL:5,directive:6,SD:7,document:8,line:9,statement:10,idStatement:11,DESCR:12,"-->":13,HIDE_EMPTY:14,scale:15,WIDTH:16,COMPOSIT_STATE:17,STRUCT_START:18,STRUCT_STOP:19,STATE_DESCR:20,AS:21,ID:22,FORK:23,JOIN:24,CHOICE:25,CONCURRENT:26,note:27,notePosition:28,NOTE_TEXT:29,direction:30,acc_title:31,acc_title_value:32,acc_descr:33,acc_descr_value:34,acc_descr_multiline_value:35,openDirective:36,typeDirective:37,closeDirective:38,":":39,argDirective:40,direction_tb:41,direction_bt:42,direction_rl:43,direction_lr:44,eol:45,";":46,EDGE_STATE:47,left_of:48,right_of:49,open_directive:50,type_directive:51,arg_directive:52,close_directive:53,$accept:0,$end:1},terminals_:{2:"error",4:"SPACE",5:"NL",7:"SD",12:"DESCR",13:"-->",14:"HIDE_EMPTY",15:"scale",16:"WIDTH",17:"COMPOSIT_STATE",18:"STRUCT_START",19:"STRUCT_STOP",20:"STATE_DESCR",21:"AS",22:"ID",23:"FORK",24:"JOIN",25:"CHOICE",26:"CONCURRENT",27:"note",29:"NOTE_TEXT",31:"acc_title",32:"acc_title_value",33:"acc_descr",34:"acc_descr_value",35:"acc_descr_multiline_value",39:":",41:"direction_tb",42:"direction_bt",43:"direction_rl",44:"direction_lr",46:";",47:"EDGE_STATE",48:"left_of",49:"right_of",50:"open_directive",51:"type_directive",52:"arg_directive",53:"close_directive"},productions_:[0,[3,2],[3,2],[3,2],[3,2],[8,0],[8,2],[9,2],[9,1],[9,1],[10,1],[10,2],[10,3],[10,4],[10,1],[10,2],[10,1],[10,4],[10,3],[10,6],[10,1],[10,1],[10,1],[10,1],[10,4],[10,4],[10,1],[10,1],[10,2],[10,2],[10,1],[6,3],[6,5],[30,1],[30,1],[30,1],[30,1],[45,1],[45,1],[11,1],[11,1],[28,1],[28,1],[36,1],[37,1],[40,1],[38,1]],performAction:function(J,Y,$,lt,ut,W,tt){var K=W.length-1;switch(ut){case 4:return lt.setRootDoc(W[K]),W[K];case 5:this.$=[];break;case 6:W[K]!="nl"&&(W[K-1].push(W[K]),this.$=W[K-1]);break;case 7:case 8:this.$=W[K];break;case 9:this.$="nl";break;case 10:this.$={stmt:"state",id:W[K],type:"default",description:""};break;case 11:this.$={stmt:"state",id:W[K-1],type:"default",description:lt.trimColon(W[K])};break;case 12:this.$={stmt:"relation",state1:{stmt:"state",id:W[K-2],type:"default",description:""},state2:{stmt:"state",id:W[K],type:"default",description:""}};break;case 13:this.$={stmt:"relation",state1:{stmt:"state",id:W[K-3],type:"default",description:""},state2:{stmt:"state",id:W[K-1],type:"default",description:""},description:W[K].substr(1).trim()};break;case 17:this.$={stmt:"state",id:W[K-3],type:"default",description:"",doc:W[K-1]};break;case 18:var it=W[K],Z=W[K-2].trim();if(W[K].match(":")){var V=W[K].split(":");it=V[0],Z=[Z,V[1]]}this.$={stmt:"state",id:it,type:"default",description:Z};break;case 19:this.$={stmt:"state",id:W[K-3],type:"default",description:W[K-5],doc:W[K-1]};break;case 20:this.$={stmt:"state",id:W[K],type:"fork"};break;case 21:this.$={stmt:"state",id:W[K],type:"join"};break;case 22:this.$={stmt:"state",id:W[K],type:"choice"};break;case 23:this.$={stmt:"state",id:lt.getDividerId(),type:"divider"};break;case 24:this.$={stmt:"state",id:W[K-1].trim(),note:{position:W[K-2].trim(),text:W[K].trim()}};break;case 28:this.$=W[K].trim(),lt.setAccTitle(this.$);break;case 29:case 30:this.$=W[K].trim(),lt.setAccDescription(this.$);break;case 33:lt.setDirection("TB"),this.$={stmt:"dir",value:"TB"};break;case 34:lt.setDirection("BT"),this.$={stmt:"dir",value:"BT"};break;case 35:lt.setDirection("RL"),this.$={stmt:"dir",value:"RL"};break;case 36:lt.setDirection("LR"),this.$={stmt:"dir",value:"LR"};break;case 39:case 40:this.$=W[K];break;case 43:lt.parseDirective("%%{","open_directive");break;case 44:lt.parseDirective(W[K],"type_directive");break;case 45:W[K]=W[K].trim().replace(/'/g,'"'),lt.parseDirective(W[K],"arg_directive");break;case 46:lt.parseDirective("}%%","close_directive","state");break}},table:[{3:1,4:e,5:r,6:4,7:n,36:6,50:i},{1:[3]},{3:8,4:e,5:r,6:4,7:n,36:6,50:i},{3:9,4:e,5:r,6:4,7:n,36:6,50:i},{3:10,4:e,5:r,6:4,7:n,36:6,50:i},t([1,4,5,14,15,17,20,22,23,24,25,26,27,31,33,35,41,42,43,44,47,50],a,{8:11}),{37:12,51:[1,13]},{51:[2,43]},{1:[2,1]},{1:[2,2]},{1:[2,3]},{1:[2,4],4:s,5:o,6:28,9:14,10:16,11:18,14:l,15:u,17:h,20:d,22:f,23:p,24:m,25:_,26:y,27:b,30:29,31:x,33:k,35:T,36:6,41:C,42:M,43:S,44:R,47:A,50:i},{38:39,39:[1,40],53:L},t([39,53],[2,44]),t(v,[2,6]),{6:28,10:42,11:18,14:l,15:u,17:h,20:d,22:f,23:p,24:m,25:_,26:y,27:b,30:29,31:x,33:k,35:T,36:6,41:C,42:M,43:S,44:R,47:A,50:i},t(v,[2,8]),t(v,[2,9]),t(v,[2,10],{12:[1,43],13:[1,44]}),t(v,[2,14]),{16:[1,45]},t(v,[2,16],{18:[1,46]}),{21:[1,47]},t(v,[2,20]),t(v,[2,21]),t(v,[2,22]),t(v,[2,23]),{28:48,29:[1,49],48:[1,50],49:[1,51]},t(v,[2,26]),t(v,[2,27]),{32:[1,52]},{34:[1,53]},t(v,[2,30]),t(B,[2,39]),t(B,[2,40]),t(v,[2,33]),t(v,[2,34]),t(v,[2,35]),t(v,[2,36]),t(w,[2,31]),{40:54,52:[1,55]},t(w,[2,46]),t(v,[2,7]),t(v,[2,11]),{11:56,22:f,47:A},t(v,[2,15]),t(D,a,{8:57}),{22:[1,58]},{22:[1,59]},{21:[1,60]},{22:[2,41]},{22:[2,42]},t(v,[2,28]),t(v,[2,29]),{38:61,53:L},{53:[2,45]},t(v,[2,12],{12:[1,62]}),{4:s,5:o,6:28,9:14,10:16,11:18,14:l,15:u,17:h,19:[1,63],20:d,22:f,23:p,24:m,25:_,26:y,27:b,30:29,31:x,33:k,35:T,36:6,41:C,42:M,43:S,44:R,47:A,50:i},t(v,[2,18],{18:[1,64]}),{29:[1,65]},{22:[1,66]},t(w,[2,32]),t(v,[2,13]),t(v,[2,17]),t(D,a,{8:67}),t(v,[2,24]),t(v,[2,25]),{4:s,5:o,6:28,9:14,10:16,11:18,14:l,15:u,17:h,19:[1,68],20:d,22:f,23:p,24:m,25:_,26:y,27:b,30:29,31:x,33:k,35:T,36:6,41:C,42:M,43:S,44:R,47:A,50:i},t(v,[2,19])],defaultActions:{7:[2,43],8:[2,1],9:[2,2],10:[2,3],50:[2,41],51:[2,42],55:[2,45]},parseError:function(J,Y){if(Y.recoverable)this.trace(J);else{var $=new Error(J);throw $.hash=Y,$}},parse:function(J){var Y=this,$=[0],lt=[],ut=[null],W=[],tt=this.table,K="",it=0,Z=0,V=2,Q=1,q=W.slice.call(arguments,1),U=Object.create(this.lexer),F={yy:{}};for(var j in this.yy)Object.prototype.hasOwnProperty.call(this.yy,j)&&(F.yy[j]=this.yy[j]);U.setInput(J,F.yy),F.yy.lexer=U,F.yy.parser=this,typeof U.yylloc>"u"&&(U.yylloc={});var P=U.yylloc;W.push(P);var et=U.options&&U.options.ranges;typeof F.yy.parseError=="function"?this.parseError=F.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function at(){var Dt;return Dt=lt.pop()||U.lex()||Q,typeof Dt!="number"&&(Dt instanceof Array&&(lt=Dt,Dt=lt.pop()),Dt=Y.symbols_[Dt]||Dt),Dt}for(var It,Lt,Rt,Ct,pt={},mt,vt,Tt,ft;;){if(Lt=$[$.length-1],this.defaultActions[Lt]?Rt=this.defaultActions[Lt]:((It===null||typeof It>"u")&&(It=at()),Rt=tt[Lt]&&tt[Lt][It]),typeof Rt>"u"||!Rt.length||!Rt[0]){var le="";ft=[];for(mt in tt[Lt])this.terminals_[mt]&&mt>V&&ft.push("'"+this.terminals_[mt]+"'");U.showPosition?le="Parse error on line "+(it+1)+`: +`+U.showPosition()+` +Expecting `+ft.join(", ")+", got '"+(this.terminals_[It]||It)+"'":le="Parse error on line "+(it+1)+": Unexpected "+(It==Q?"end of input":"'"+(this.terminals_[It]||It)+"'"),this.parseError(le,{text:U.match,token:this.terminals_[It]||It,line:U.yylineno,loc:P,expected:ft})}if(Rt[0]instanceof Array&&Rt.length>1)throw new Error("Parse Error: multiple actions possible at state: "+Lt+", token: "+It);switch(Rt[0]){case 1:$.push(It),ut.push(U.yytext),W.push(U.yylloc),$.push(Rt[1]),It=null,Z=U.yyleng,K=U.yytext,it=U.yylineno,P=U.yylloc;break;case 2:if(vt=this.productions_[Rt[1]][1],pt.$=ut[ut.length-vt],pt._$={first_line:W[W.length-(vt||1)].first_line,last_line:W[W.length-1].last_line,first_column:W[W.length-(vt||1)].first_column,last_column:W[W.length-1].last_column},et&&(pt._$.range=[W[W.length-(vt||1)].range[0],W[W.length-1].range[1]]),Ct=this.performAction.apply(pt,[K,Z,it,F.yy,Rt[1],ut,W].concat(q)),typeof Ct<"u")return Ct;vt&&($=$.slice(0,-1*vt*2),ut=ut.slice(0,-1*vt),W=W.slice(0,-1*vt)),$.push(this.productions_[Rt[1]][0]),ut.push(pt.$),W.push(pt._$),Tt=tt[$[$.length-2]][$[$.length-1]],$.push(Tt);break;case 3:return!0}}return!0}},z=function(){var ct={EOF:1,parseError:function(Y,$){if(this.yy.parser)this.yy.parser.parseError(Y,$);else throw new Error(Y)},setInput:function(J,Y){return this.yy=Y||this.yy||{},this._input=J,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var J=this._input[0];this.yytext+=J,this.yyleng++,this.offset++,this.match+=J,this.matched+=J;var Y=J.match(/(?:\r\n?|\n).*/g);return Y?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),J},unput:function(J){var Y=J.length,$=J.split(/(?:\r\n?|\n)/g);this._input=J+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-Y),this.offset-=Y;var lt=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),$.length-1&&(this.yylineno-=$.length-1);var ut=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:$?($.length===lt.length?this.yylloc.first_column:0)+lt[lt.length-$.length].length-$[0].length:this.yylloc.first_column-Y},this.options.ranges&&(this.yylloc.range=[ut[0],ut[0]+this.yyleng-Y]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(J){this.unput(this.match.slice(J))},pastInput:function(){var J=this.matched.substr(0,this.matched.length-this.match.length);return(J.length>20?"...":"")+J.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var J=this.match;return J.length<20&&(J+=this._input.substr(0,20-J.length)),(J.substr(0,20)+(J.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var J=this.pastInput(),Y=new Array(J.length+1).join("-");return J+this.upcomingInput()+` +`+Y+"^"},test_match:function(J,Y){var $,lt,ut;if(this.options.backtrack_lexer&&(ut={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(ut.yylloc.range=this.yylloc.range.slice(0))),lt=J[0].match(/(?:\r\n?|\n).*/g),lt&&(this.yylineno+=lt.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:lt?lt[lt.length-1].length-lt[lt.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+J[0].length},this.yytext+=J[0],this.match+=J[0],this.matches=J,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(J[0].length),this.matched+=J[0],$=this.performAction.call(this,this.yy,this,Y,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),$)return $;if(this._backtrack){for(var W in ut)this[W]=ut[W];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var J,Y,$,lt;this._more||(this.yytext="",this.match="");for(var ut=this._currentRules(),W=0;W<ut.length;W++)if($=this._input.match(this.rules[ut[W]]),$&&(!Y||$[0].length>Y[0].length)){if(Y=$,lt=W,this.options.backtrack_lexer){if(J=this.test_match($,ut[W]),J!==!1)return J;if(this._backtrack){Y=!1;continue}else return!1}else if(!this.options.flex)break}return Y?(J=this.test_match(Y,ut[lt]),J!==!1?J:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var Y=this.next();return Y||this.lex()},begin:function(Y){this.conditionStack.push(Y)},popState:function(){var Y=this.conditionStack.length-1;return Y>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(Y){return Y=this.conditionStack.length-1-Math.abs(Y||0),Y>=0?this.conditionStack[Y]:"INITIAL"},pushState:function(Y){this.begin(Y)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(Y,$,lt,ut){switch(lt){case 0:return 41;case 1:return 42;case 2:return 43;case 3:return 44;case 4:return this.begin("open_directive"),50;case 5:return this.begin("type_directive"),51;case 6:return this.popState(),this.begin("arg_directive"),39;case 7:return this.popState(),this.popState(),53;case 8:return 52;case 9:break;case 10:break;case 11:return 5;case 12:break;case 13:break;case 14:break;case 15:break;case 16:return this.pushState("SCALE"),15;case 17:return 16;case 18:this.popState();break;case 19:return this.begin("acc_title"),31;case 20:return this.popState(),"acc_title_value";case 21:return this.begin("acc_descr"),33;case 22:return this.popState(),"acc_descr_value";case 23:this.begin("acc_descr_multiline");break;case 24:this.popState();break;case 25:return"acc_descr_multiline_value";case 26:this.pushState("STATE");break;case 27:return this.popState(),$.yytext=$.yytext.slice(0,-8).trim(),23;case 28:return this.popState(),$.yytext=$.yytext.slice(0,-8).trim(),24;case 29:return this.popState(),$.yytext=$.yytext.slice(0,-10).trim(),25;case 30:return this.popState(),$.yytext=$.yytext.slice(0,-8).trim(),23;case 31:return this.popState(),$.yytext=$.yytext.slice(0,-8).trim(),24;case 32:return this.popState(),$.yytext=$.yytext.slice(0,-10).trim(),25;case 33:return 41;case 34:return 42;case 35:return 43;case 36:return 44;case 37:this.begin("STATE_STRING");break;case 38:return this.popState(),this.pushState("STATE_ID"),"AS";case 39:return this.popState(),"ID";case 40:this.popState();break;case 41:return"STATE_DESCR";case 42:return 17;case 43:this.popState();break;case 44:return this.popState(),this.pushState("struct"),18;case 45:return this.popState(),19;case 46:break;case 47:return this.begin("NOTE"),27;case 48:return this.popState(),this.pushState("NOTE_ID"),48;case 49:return this.popState(),this.pushState("NOTE_ID"),49;case 50:this.popState(),this.pushState("FLOATING_NOTE");break;case 51:return this.popState(),this.pushState("FLOATING_NOTE_ID"),"AS";case 52:break;case 53:return"NOTE_TEXT";case 54:return this.popState(),"ID";case 55:return this.popState(),this.pushState("NOTE_TEXT"),22;case 56:return this.popState(),$.yytext=$.yytext.substr(2).trim(),29;case 57:return this.popState(),$.yytext=$.yytext.slice(0,-8).trim(),29;case 58:return 7;case 59:return 7;case 60:return 14;case 61:return 47;case 62:return 22;case 63:return $.yytext=$.yytext.trim(),12;case 64:return 13;case 65:return 26;case 66:return 5;case 67:return"INVALID"}},rules:[/^(?:.*direction\s+TB[^\n]*)/i,/^(?:.*direction\s+BT[^\n]*)/i,/^(?:.*direction\s+RL[^\n]*)/i,/^(?:.*direction\s+LR[^\n]*)/i,/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n]+)/i,/^(?:[\s]+)/i,/^(?:((?!\n)\s)+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:scale\s+)/i,/^(?:\d+)/i,/^(?:\s+width\b)/i,/^(?:accTitle\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*\{\s*)/i,/^(?:[\}])/i,/^(?:[^\}]*)/i,/^(?:state\s+)/i,/^(?:.*<<fork>>)/i,/^(?:.*<<join>>)/i,/^(?:.*<<choice>>)/i,/^(?:.*\[\[fork\]\])/i,/^(?:.*\[\[join\]\])/i,/^(?:.*\[\[choice\]\])/i,/^(?:.*direction\s+TB[^\n]*)/i,/^(?:.*direction\s+BT[^\n]*)/i,/^(?:.*direction\s+RL[^\n]*)/i,/^(?:.*direction\s+LR[^\n]*)/i,/^(?:["])/i,/^(?:\s*as\s+)/i,/^(?:[^\n\{]*)/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[^\n\s\{]+)/i,/^(?:\n)/i,/^(?:\{)/i,/^(?:\})/i,/^(?:[\n])/i,/^(?:note\s+)/i,/^(?:left of\b)/i,/^(?:right of\b)/i,/^(?:")/i,/^(?:\s*as\s*)/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[^\n]*)/i,/^(?:\s*[^:\n\s\-]+)/i,/^(?:\s*:[^:\n;]+)/i,/^(?:[\s\S]*?end note\b)/i,/^(?:stateDiagram\s+)/i,/^(?:stateDiagram-v2\s+)/i,/^(?:hide empty description\b)/i,/^(?:\[\*\])/i,/^(?:[^:\n\s\-\{]+)/i,/^(?:\s*:[^:\n;]+)/i,/^(?:-->)/i,/^(?:--)/i,/^(?:$)/i,/^(?:.)/i],conditions:{LINE:{rules:[13,14],inclusive:!1},close_directive:{rules:[13,14],inclusive:!1},arg_directive:{rules:[7,8,13,14],inclusive:!1},type_directive:{rules:[6,7,13,14],inclusive:!1},open_directive:{rules:[5,13,14],inclusive:!1},struct:{rules:[13,14,26,33,34,35,36,45,46,47,61,62,63,64,65],inclusive:!1},FLOATING_NOTE_ID:{rules:[54],inclusive:!1},FLOATING_NOTE:{rules:[51,52,53],inclusive:!1},NOTE_TEXT:{rules:[56,57],inclusive:!1},NOTE_ID:{rules:[55],inclusive:!1},NOTE:{rules:[48,49,50],inclusive:!1},acc_descr_multiline:{rules:[24,25],inclusive:!1},acc_descr:{rules:[22],inclusive:!1},acc_title:{rules:[20],inclusive:!1},SCALE:{rules:[17,18],inclusive:!1},ALIAS:{rules:[],inclusive:!1},STATE_ID:{rules:[39],inclusive:!1},STATE_STRING:{rules:[40,41],inclusive:!1},FORK_STATE:{rules:[],inclusive:!1},STATE:{rules:[13,14,27,28,29,30,31,32,37,38,42,43,44],inclusive:!1},ID:{rules:[13,14],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,9,10,11,12,14,15,16,19,21,23,26,44,47,58,59,60,61,62,63,64,66,67],inclusive:!0}}};return ct}();N.lexer=z;function X(){this.yy={}}return X.prototype=N,N.Parser=X,new X}();p0.parser=p0;const fat=(t,e)=>{var r;return((r=e==null?void 0:e.state)==null?void 0:r.defaultRenderer)==="dagre-wrapper"?!1:t.match(/^\s*stateDiagram/)!==null},dat=(t,e)=>{var r;return!!(t.match(/^\s*stateDiagram-v2/)!==null||t.match(/^\s*stateDiagram/)&&((r=e==null?void 0:e.state)==null?void 0:r.defaultRenderer)==="dagre-wrapper")},g0=t=>JSON.parse(JSON.stringify(t));let y0=[];const pat=function(t,e,r){Xe.parseDirective(this,t,e,r)},gat=t=>{H.info("Setting root doc",t),y0=t},yat=()=>y0,m0=(t,e,r)=>{if(e.stmt==="relation")m0(t,e.state1,!0),m0(t,e.state2,!1);else if(e.stmt==="state"&&e.id==="[*]"&&(e.id=r?t.id+"_start":t.id+"_end",e.start=r),e.doc){const n=[];let i=0,a=[];for(i=0;i<e.doc.length;i++)if(e.doc[i].type==="divider"){const s=g0(e.doc[i]);s.doc=g0(a),n.push(s),a=[]}else a.push(e.doc[i]);if(n.length>0&&a.length>0){const s={stmt:"state",id:ow(),type:"divider",doc:g0(a)};n.push(g0(s)),e.doc=n}e.doc.forEach(s=>m0(e,s,!0))}},mat=()=>(m0({id:"root"},{id:"root",doc:y0},!0),{id:"root",doc:y0}),bat=t=>{let e;t.doc?e=t.doc:e=t,H.info(e),LL(!0),H.info("Extract",e),e.forEach(r=>{r.stmt==="state"&&_0(r.id,r.type,r.doc,r.description,r.note),r.stmt==="relation"&&RL(r.state1.id,r.state2.id,r.description)})},ML=()=>({relations:[],states:{},documents:{}});let pu={root:ML()},Wr=pu.root,b0=0;const _0=function(t,e,r,n,i){typeof Wr.states[t]>"u"?Wr.states[t]={id:t,descriptions:[],type:e,doc:r,note:i}:(Wr.states[t].doc||(Wr.states[t].doc=r),Wr.states[t].type||(Wr.states[t].type=e)),n&&(H.info("Adding state ",t,n),typeof n=="string"&&IL(t,n.trim()),typeof n=="object"&&n.forEach(a=>IL(t,a.trim()))),i&&(Wr.states[t].note=i,Wr.states[t].note.text=pe.sanitizeText(Wr.states[t].note.text,nt()))},LL=function(t){pu={root:ML()},Wr=pu.root,Wr=pu.root,b0=0,BL=[],t||ci()},_at=function(t){return Wr.states[t]},vat=function(){return Wr.states},xat=function(){H.info("Documents = ",pu)},kat=function(){return Wr.relations},RL=function(t,e,r){let n=t,i=e,a="default",s="default";t==="[*]"&&(b0++,n="start"+b0,a="start"),e==="[*]"&&(i="end"+b0,s="end"),_0(n,a),_0(i,s),Wr.relations.push({id1:n,id2:i,title:pe.sanitizeText(r,nt())})},IL=function(t,e){const r=Wr.states[t];let n=e;n[0]===":"&&(n=n.substr(1).trim()),r.descriptions.push(pe.sanitizeText(n,nt()))},wat=function(t){return t.substring(0,1)===":"?t.substr(2).trim():t.trim()},Tat={LINE:0,DOTTED_LINE:1};let NL=0;const Eat=()=>(NL++,"divider-id-"+NL);let BL=[];const Cat=()=>BL;let DL="TB";const ma={parseDirective:pat,getConfig:()=>nt().state,addState:_0,clear:LL,getState:_at,getStates:vat,getRelations:kat,getClasses:Cat,getDirection:()=>DL,addRelation:RL,getDividerId:Eat,setDirection:t=>{DL=t},cleanupLabel:wat,lineType:Tat,relationType:{AGGREGATION:0,EXTENSION:1,COMPOSITION:2,DEPENDENCY:3},logDocuments:xat,getRootDoc:yat,setRootDoc:gat,getRootDocV2:mat,extract:bat,trimColon:t=>t&&t[0]===":"?t.substr(1).trim():t.trim(),getAccTitle:ui,setAccTitle:Yn,getAccDescription:fi,setAccDescription:hi},Sat=t=>t.append("circle").attr("class","start-state").attr("r",nt().state.sizeUnit).attr("cx",nt().state.padding+nt().state.sizeUnit).attr("cy",nt().state.padding+nt().state.sizeUnit),Aat=t=>t.append("line").style("stroke","grey").style("stroke-dasharray","3").attr("x1",nt().state.textHeight).attr("class","divider").attr("x2",nt().state.textHeight*2).attr("y1",0).attr("y2",0),Mat=(t,e)=>{const r=t.append("text").attr("x",2*nt().state.padding).attr("y",nt().state.textHeight+2*nt().state.padding).attr("font-size",nt().state.fontSize).attr("class","state-title").text(e.id),n=r.node().getBBox();return t.insert("rect",":first-child").attr("x",nt().state.padding).attr("y",nt().state.padding).attr("width",n.width+2*nt().state.padding).attr("height",n.height+2*nt().state.padding).attr("rx",nt().state.radius),r},Lat=(t,e)=>{const r=function(f,p,m){const _=f.append("tspan").attr("x",2*nt().state.padding).text(p);m||_.attr("dy",nt().state.textHeight)},i=t.append("text").attr("x",2*nt().state.padding).attr("y",nt().state.textHeight+1.3*nt().state.padding).attr("font-size",nt().state.fontSize).attr("class","state-title").text(e.descriptions[0]).node().getBBox(),a=i.height,s=t.append("text").attr("x",nt().state.padding).attr("y",a+nt().state.padding*.4+nt().state.dividerMargin+nt().state.textHeight).attr("class","state-description");let o=!0,l=!0;e.descriptions.forEach(function(f){o||(r(s,f,l),l=!1),o=!1});const u=t.append("line").attr("x1",nt().state.padding).attr("y1",nt().state.padding+a+nt().state.dividerMargin/2).attr("y2",nt().state.padding+a+nt().state.dividerMargin/2).attr("class","descr-divider"),h=s.node().getBBox(),d=Math.max(h.width,i.width);return u.attr("x2",d+3*nt().state.padding),t.insert("rect",":first-child").attr("x",nt().state.padding).attr("y",nt().state.padding).attr("width",d+2*nt().state.padding).attr("height",h.height+a+2*nt().state.padding).attr("rx",nt().state.radius),t},Rat=(t,e,r)=>{const n=nt().state.padding,i=2*nt().state.padding,a=t.node().getBBox(),s=a.width,o=a.x,l=t.append("text").attr("x",0).attr("y",nt().state.titleShift).attr("font-size",nt().state.fontSize).attr("class","state-title").text(e.id),h=l.node().getBBox().width+i;let d=Math.max(h,s);d===s&&(d=d+i);let f;const p=t.node().getBBox();e.doc,f=o-n,h>s&&(f=(s-d)/2+n),Math.abs(o-p.x)<n&&h>s&&(f=o-(h-s)/2);const m=1-nt().state.textHeight;return t.insert("rect",":first-child").attr("x",f).attr("y",m).attr("class",r?"alt-composit":"composit").attr("width",d).attr("height",p.height+nt().state.textHeight+nt().state.titleShift+1).attr("rx","0"),l.attr("x",f+n),h<=s&&l.attr("x",o+(d-i)/2-h/2+n),t.insert("rect",":first-child").attr("x",f).attr("y",nt().state.titleShift-nt().state.textHeight-nt().state.padding).attr("width",d).attr("height",nt().state.textHeight*3).attr("rx",nt().state.radius),t.insert("rect",":first-child").attr("x",f).attr("y",nt().state.titleShift-nt().state.textHeight-nt().state.padding).attr("width",d).attr("height",p.height+3+2*nt().state.textHeight).attr("rx",nt().state.radius),t},Iat=t=>(t.append("circle").attr("class","end-state-outer").attr("r",nt().state.sizeUnit+nt().state.miniPadding).attr("cx",nt().state.padding+nt().state.sizeUnit+nt().state.miniPadding).attr("cy",nt().state.padding+nt().state.sizeUnit+nt().state.miniPadding),t.append("circle").attr("class","end-state-inner").attr("r",nt().state.sizeUnit).attr("cx",nt().state.padding+nt().state.sizeUnit+2).attr("cy",nt().state.padding+nt().state.sizeUnit+2)),Nat=(t,e)=>{let r=nt().state.forkWidth,n=nt().state.forkHeight;if(e.parentId){let i=r;r=n,n=i}return t.append("rect").style("stroke","black").style("fill","black").attr("width",r).attr("height",n).attr("x",nt().state.padding).attr("y",nt().state.padding)},Bat=(t,e,r,n)=>{let i=0;const a=n.append("text");a.style("text-anchor","start"),a.attr("class","noteText");let s=t.replace(/\r\n/g,"<br/>");s=s.replace(/\n/g,"<br/>");const o=s.split(pe.lineBreakRegex);let l=1.25*nt().state.noteMargin;for(const u of o){const h=u.trim();if(h.length>0){const d=a.append("tspan");d.text(h),l===0&&(l+=d.node().getBBox().height),i+=l,d.attr("x",e+nt().state.noteMargin),d.attr("y",r+i+1.25*nt().state.noteMargin)}}return{textWidth:a.node().getBBox().width,textHeight:i}},Dat=(t,e)=>{e.attr("class","state-note");const r=e.append("rect").attr("x",0).attr("y",nt().state.padding),n=e.append("g"),{textWidth:i,textHeight:a}=Bat(t,0,0,n);return r.attr("height",a+2*nt().state.noteMargin),r.attr("width",i+nt().state.noteMargin*2),r},OL=function(t,e){const r=e.id,n={id:r,label:e.id,width:0,height:0},i=t.append("g").attr("id",r).attr("class","stateGroup");e.type==="start"&&Sat(i),e.type==="end"&&Iat(i),(e.type==="fork"||e.type==="join")&&Nat(i,e),e.type==="note"&&Dat(e.note.text,i),e.type==="divider"&&Aat(i),e.type==="default"&&e.descriptions.length===0&&Mat(i,e),e.type==="default"&&e.descriptions.length>0&&Lat(i,e);const a=i.node().getBBox();return n.width=a.width+2*nt().state.padding,n.height=a.height+2*nt().state.padding,n};let FL=0;const Oat=function(t,e,r){const n=function(l){switch(l){case ma.relationType.AGGREGATION:return"aggregation";case ma.relationType.EXTENSION:return"extension";case ma.relationType.COMPOSITION:return"composition";case ma.relationType.DEPENDENCY:return"dependency"}};e.points=e.points.filter(l=>!Number.isNaN(l.y));const i=e.points,a=Ua().x(function(l){return l.x}).y(function(l){return l.y}).curve(Os),s=t.append("path").attr("d",a(i)).attr("id","edge"+FL).attr("class","transition");let o="";if(nt().state.arrowMarkerAbsolute&&(o=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,o=o.replace(/\(/g,"\\("),o=o.replace(/\)/g,"\\)")),s.attr("marker-end","url("+o+"#"+n(ma.relationType.DEPENDENCY)+"End)"),typeof r.title<"u"){const l=t.append("g").attr("class","stateLabel"),{x:u,y:h}=Se.calcLabelPosition(e.points),d=pe.getRows(r.title);let f=0;const p=[];let m=0,_=0;for(let x=0;x<=d.length;x++){const k=l.append("text").attr("text-anchor","middle").text(d[x]).attr("x",u).attr("y",h+f),T=k.node().getBBox();m=Math.max(m,T.width),_=Math.min(_,T.x),H.info(T.x,u,h+f),f===0&&(f=k.node().getBBox().height,H.info("Title height",f,h)),p.push(k)}let y=f*d.length;if(d.length>1){const x=(d.length-1)*f*.5;p.forEach((k,T)=>k.attr("y",h+T*f-x)),y=f*d.length}const b=l.node().getBBox();l.insert("rect",":first-child").attr("class","box").attr("x",u-m/2-nt().state.padding/2).attr("y",h-y/2-nt().state.padding/2-3.5).attr("width",m+nt().state.padding).attr("height",y+nt().state.padding),H.info(b)}FL++};let Mn;const J4={},Fat=function(){},Pat=function(t){t.append("defs").append("marker").attr("id","dependencyEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 19,7 L9,13 L14,7 L9,1 Z")},qat=function(t,e,r,n){Mn=nt().state;const i=nt().securityLevel;let a;i==="sandbox"&&(a=St("#i"+e));const s=St(i==="sandbox"?a.nodes()[0].contentDocument.body:"body"),o=i==="sandbox"?a.nodes()[0].contentDocument:document;H.debug("Rendering diagram "+t);const l=s.select(`[id='${e}']`);Pat(l),new cr.Graph({multigraph:!0,compound:!0,rankdir:"RL"}).setDefaultEdgeLabel(function(){return{}});const h=n.db.getRootDoc();PL(h,l,void 0,!1,s,o,n);const d=Mn.padding,f=l.node().getBBox(),p=f.width+d*2,m=f.height+d*2,_=p*1.75;li(l,m,_,Mn.useMaxWidth),l.attr("viewBox",`${f.x-Mn.padding} ${f.y-Mn.padding} `+p+" "+m),bn(n.db,l,e)},Vat=t=>t?t.length*Mn.fontSizeFactor:1,PL=(t,e,r,n,i,a,s)=>{const o=new cr.Graph({compound:!0,multigraph:!0});let l,u=!0;for(l=0;l<t.length;l++)if(t[l].stmt==="relation"){u=!1;break}r?o.setGraph({rankdir:"LR",multigraph:!0,compound:!0,ranker:"tight-tree",ranksep:u?1:Mn.edgeLengthFactor,nodeSep:u?1:50,isMultiGraph:!0}):o.setGraph({rankdir:"TB",multigraph:!0,compound:!0,ranksep:u?1:Mn.edgeLengthFactor,nodeSep:u?1:50,ranker:"tight-tree",isMultiGraph:!0}),o.setDefaultEdgeLabel(function(){return{}}),s.db.extract(t);const h=s.db.getStates(),d=s.db.getRelations(),f=Object.keys(h);for(let b=0;b<f.length;b++){const x=h[f[b]];r&&(x.parentId=r);let k;if(x.doc){let T=e.append("g").attr("id",x.id).attr("class","stateGroup");k=PL(x.doc,T,x.id,!n,i,a,s);{T=Rat(T,x,n);let C=T.node().getBBox();k.width=C.width,k.height=C.height+Mn.padding/2,J4[x.id]={y:Mn.compositTitleSize}}}else k=OL(e,x);if(x.note){const T={descriptions:[],id:x.id+"-note",note:x.note,type:"note"},C=OL(e,T);x.note.position==="left of"?(o.setNode(k.id+"-note",C),o.setNode(k.id,k)):(o.setNode(k.id,k),o.setNode(k.id+"-note",C)),o.setParent(k.id,k.id+"-group"),o.setParent(k.id+"-note",k.id+"-group")}else o.setNode(k.id,k)}H.debug("Count=",o.nodeCount(),o);let p=0;d.forEach(function(b){p++,H.debug("Setting edge",b),o.setEdge(b.id1,b.id2,{relation:b,width:Vat(b.title),height:Mn.labelHeight*pe.getRows(b.title).length,labelpos:"c"},"id"+p)}),Zc.layout(o),H.debug("Graph after layout",o.nodes());const m=e.node();o.nodes().forEach(function(b){typeof b<"u"&&typeof o.node(b)<"u"?(H.warn("Node "+b+": "+JSON.stringify(o.node(b))),i.select("#"+m.id+" #"+b).attr("transform","translate("+(o.node(b).x-o.node(b).width/2)+","+(o.node(b).y+(J4[b]?J4[b].y:0)-o.node(b).height/2)+" )"),i.select("#"+m.id+" #"+b).attr("data-x-shift",o.node(b).x-o.node(b).width/2),a.querySelectorAll("#"+m.id+" #"+b+" .divider").forEach(k=>{const T=k.parentElement;let C=0,M=0;T&&(T.parentElement&&(C=T.parentElement.getBBox().width),M=parseInt(T.getAttribute("data-x-shift"),10),Number.isNaN(M)&&(M=0)),k.setAttribute("x1",0-M+8),k.setAttribute("x2",C-M-8)})):H.debug("No Node "+b+": "+JSON.stringify(o.node(b)))});let _=m.getBBox();o.edges().forEach(function(b){typeof b<"u"&&typeof o.edge(b)<"u"&&(H.debug("Edge "+b.v+" -> "+b.w+": "+JSON.stringify(o.edge(b))),Oat(e,o.edge(b),o.edge(b).relation))}),_=m.getBBox();const y={id:r||"root",label:r||"root",width:0,height:0};return y.width=_.width+2*Mn.padding,y.height=_.height+2*Mn.padding,H.debug("Doc rendered",y,o),y},zat={setConf:Fat,draw:qat},Yat={},Uat=function(t){const e=Object.keys(t);for(let r=0;r<e.length;r++)Yat[e[r]]=t[e[r]]};let Fe={};const Wat=function(t,e){return H.trace("Extracting classes"),e.sb.clear(),e.parser.parse(t),e.sb.getClasses()},v0=(t,e,r,n)=>{if(r.id!=="root"){let i="rect";r.start===!0&&(i="start"),r.start===!1&&(i="end"),r.type!=="default"&&(i=r.type),Fe[r.id]||(Fe[r.id]={id:r.id,shape:i,description:pe.sanitizeText(r.id,nt()),classes:"statediagram-state"}),r.description&&(Array.isArray(Fe[r.id].description)?(Fe[r.id].shape="rectWithTitle",Fe[r.id].description.push(r.description)):Fe[r.id].description.length>0?(Fe[r.id].shape="rectWithTitle",Fe[r.id].description===r.id?Fe[r.id].description=[r.description]:Fe[r.id].description=[Fe[r.id].description,r.description]):(Fe[r.id].shape="rect",Fe[r.id].description=r.description),Fe[r.id].description=pe.sanitizeTextOrArray(Fe[r.id].description,nt())),Fe[r.id].description.length===1&&Fe[r.id].shape==="rectWithTitle"&&(Fe[r.id].shape="rect"),!Fe[r.id].type&&r.doc&&(H.info("Setting cluster for ",r.id,t_(r)),Fe[r.id].type="group",Fe[r.id].dir=t_(r),Fe[r.id].shape=r.type==="divider"?"divider":"roundedWithTitle",Fe[r.id].classes=Fe[r.id].classes+" "+(n?"statediagram-cluster statediagram-cluster-alt":"statediagram-cluster"));const a={labelStyle:"",shape:Fe[r.id].shape,labelText:Fe[r.id].description,classes:Fe[r.id].classes,style:"",id:r.id,dir:Fe[r.id].dir,domId:"state-"+r.id+"-"+is,type:Fe[r.id].type,padding:15};if(r.note){const s={labelStyle:"",shape:"note",labelText:r.note.text,classes:"statediagram-note",style:"",id:r.id+"----note-"+is,domId:"state-"+r.id+"----note-"+is,type:Fe[r.id].type,padding:15},o={labelStyle:"",shape:"noteGroup",labelText:r.note.text,classes:Fe[r.id].classes,style:"",id:r.id+"----parent",domId:"state-"+r.id+"----parent-"+is,type:"group",padding:0};is++,t.setNode(r.id+"----parent",o),t.setNode(s.id,s),t.setNode(r.id,a),t.setParent(r.id,r.id+"----parent"),t.setParent(s.id,r.id+"----parent");let l=r.id,u=s.id;r.note.position==="left of"&&(l=s.id,u=r.id),t.setEdge(l,u,{arrowhead:"none",arrowType:"",style:"fill:none",labelStyle:"",classes:"transition note-edge",arrowheadStyle:"fill: #333",labelpos:"c",labelType:"text",thickness:"normal"})}else t.setNode(r.id,a)}e&&e.id!=="root"&&(H.trace("Setting node ",r.id," to be child of its parent ",e.id),t.setParent(r.id,e.id)),r.doc&&(H.trace("Adding nodes children "),Hat(t,r,r.doc,!n))};let is=0;const Hat=(t,e,r,n)=>{H.trace("items",r),r.forEach(i=>{if(i.stmt==="state"||i.stmt==="default")v0(t,e,i,n);else if(i.stmt==="relation"){v0(t,e,i.state1,n),v0(t,e,i.state2,n);const a={id:"edge"+is,arrowhead:"normal",arrowTypeEnd:"arrow_barb",style:"fill:none",labelStyle:"",label:pe.sanitizeText(i.description,nt()),arrowheadStyle:"fill: #333",labelpos:"c",labelType:"text",thickness:"normal",classes:"transition"};let s=i.state1.id,o=i.state2.id;t.setEdge(s,o,a,is),is++}})},t_=(t,e)=>{let r=e||"TB";if(t.doc)for(let n=0;n<t.doc.length;n++){const i=t.doc[n];i.stmt==="dir"&&(r=i.value)}return r},Gat={setConf:Uat,getClasses:Wat,draw:function(t,e,r,n){H.info("Drawing state diagram (v2)",e),Fe={},n.db.getDirection();const{securityLevel:i,state:a}=nt(),s=a.nodeSpacing||50,o=a.rankSpacing||50;H.info(n.db.getRootDocV2()),n.db.extract(n.db.getRootDocV2()),H.info(n.db.getRootDocV2());const l=new cr.Graph({multigraph:!0,compound:!0}).setGraph({rankdir:t_(n.db.getRootDocV2()),nodesep:s,ranksep:o,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});v0(l,void 0,n.db.getRootDocV2(),!0);let u;i==="sandbox"&&(u=St("#i"+e));const h=St(i==="sandbox"?u.nodes()[0].contentDocument.body:"body"),d=h.select(`[id="${e}"]`),f=h.select("#"+e+" g");i4(f,l,["barb"],"statediagram",e);const p=8,m=d.node().getBBox(),_=m.width+p*2,y=m.height+p*2;d.attr("class","statediagram");const b=d.node().getBBox();li(d,y,_,a.useMaxWidth);const x=`${b.x-p} ${b.y-p} ${_} ${y}`;H.debug(`viewBox ${x}`),d.attr("viewBox",x);const k=document.querySelectorAll('[id="'+e+'"] .edgeLabel .label');for(let T=0;T<k.length;T++){const C=k[T],M=C.getBBox(),S=document.createElementNS("http://www.w3.org/2000/svg","rect");S.setAttribute("rx",0),S.setAttribute("ry",0),S.setAttribute("width",M.width),S.setAttribute("height",M.height),C.insertBefore(S,C.firstChild)}bn(n.db,d,e)}};var e_=function(){var t=function(_,y,b,x){for(b=b||{},x=_.length;x--;b[_[x]]=y);return b},e=[1,2],r=[1,5],n=[6,9,11,17,18,20,22,23,24,26],i=[1,15],a=[1,16],s=[1,17],o=[1,18],l=[1,19],u=[1,20],h=[1,24],d=[4,6,9,11,17,18,20,22,23,24,26],f={trace:function(){},yy:{},symbols_:{error:2,start:3,journey:4,document:5,EOF:6,directive:7,line:8,SPACE:9,statement:10,NEWLINE:11,openDirective:12,typeDirective:13,closeDirective:14,":":15,argDirective:16,title:17,acc_title:18,acc_title_value:19,acc_descr:20,acc_descr_value:21,acc_descr_multiline_value:22,section:23,taskName:24,taskData:25,open_directive:26,type_directive:27,arg_directive:28,close_directive:29,$accept:0,$end:1},terminals_:{2:"error",4:"journey",6:"EOF",9:"SPACE",11:"NEWLINE",15:":",17:"title",18:"acc_title",19:"acc_title_value",20:"acc_descr",21:"acc_descr_value",22:"acc_descr_multiline_value",23:"section",24:"taskName",25:"taskData",26:"open_directive",27:"type_directive",28:"arg_directive",29:"close_directive"},productions_:[0,[3,3],[3,2],[5,0],[5,2],[8,2],[8,1],[8,1],[8,1],[7,4],[7,6],[10,1],[10,2],[10,2],[10,1],[10,1],[10,2],[10,1],[12,1],[13,1],[16,1],[14,1]],performAction:function(y,b,x,k,T,C,M){var S=C.length-1;switch(T){case 1:return C[S-1];case 3:this.$=[];break;case 4:C[S-1].push(C[S]),this.$=C[S-1];break;case 5:case 6:this.$=C[S];break;case 7:case 8:this.$=[];break;case 11:k.setDiagramTitle(C[S].substr(6)),this.$=C[S].substr(6);break;case 12:this.$=C[S].trim(),k.setAccTitle(this.$);break;case 13:case 14:this.$=C[S].trim(),k.setAccDescription(this.$);break;case 15:k.addSection(C[S].substr(8)),this.$=C[S].substr(8);break;case 16:k.addTask(C[S-1],C[S]),this.$="task";break;case 18:k.parseDirective("%%{","open_directive");break;case 19:k.parseDirective(C[S],"type_directive");break;case 20:C[S]=C[S].trim().replace(/'/g,'"'),k.parseDirective(C[S],"arg_directive");break;case 21:k.parseDirective("}%%","close_directive","journey");break}},table:[{3:1,4:e,7:3,12:4,26:r},{1:[3]},t(n,[2,3],{5:6}),{3:7,4:e,7:3,12:4,26:r},{13:8,27:[1,9]},{27:[2,18]},{6:[1,10],7:21,8:11,9:[1,12],10:13,11:[1,14],12:4,17:i,18:a,20:s,22:o,23:l,24:u,26:r},{1:[2,2]},{14:22,15:[1,23],29:h},t([15,29],[2,19]),t(n,[2,8],{1:[2,1]}),t(n,[2,4]),{7:21,10:25,12:4,17:i,18:a,20:s,22:o,23:l,24:u,26:r},t(n,[2,6]),t(n,[2,7]),t(n,[2,11]),{19:[1,26]},{21:[1,27]},t(n,[2,14]),t(n,[2,15]),{25:[1,28]},t(n,[2,17]),{11:[1,29]},{16:30,28:[1,31]},{11:[2,21]},t(n,[2,5]),t(n,[2,12]),t(n,[2,13]),t(n,[2,16]),t(d,[2,9]),{14:32,29:h},{29:[2,20]},{11:[1,33]},t(d,[2,10])],defaultActions:{5:[2,18],7:[2,2],24:[2,21],31:[2,20]},parseError:function(y,b){if(b.recoverable)this.trace(y);else{var x=new Error(y);throw x.hash=b,x}},parse:function(y){var b=this,x=[0],k=[],T=[null],C=[],M=this.table,S="",R=0,A=0,L=2,v=1,B=C.slice.call(arguments,1),w=Object.create(this.lexer),D={yy:{}};for(var N in this.yy)Object.prototype.hasOwnProperty.call(this.yy,N)&&(D.yy[N]=this.yy[N]);w.setInput(y,D.yy),D.yy.lexer=w,D.yy.parser=this,typeof w.yylloc>"u"&&(w.yylloc={});var z=w.yylloc;C.push(z);var X=w.options&&w.options.ranges;typeof D.yy.parseError=="function"?this.parseError=D.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function ct(){var V;return V=k.pop()||w.lex()||v,typeof V!="number"&&(V instanceof Array&&(k=V,V=k.pop()),V=b.symbols_[V]||V),V}for(var J,Y,$,lt,ut={},W,tt,K,it;;){if(Y=x[x.length-1],this.defaultActions[Y]?$=this.defaultActions[Y]:((J===null||typeof J>"u")&&(J=ct()),$=M[Y]&&M[Y][J]),typeof $>"u"||!$.length||!$[0]){var Z="";it=[];for(W in M[Y])this.terminals_[W]&&W>L&&it.push("'"+this.terminals_[W]+"'");w.showPosition?Z="Parse error on line "+(R+1)+`: +`+w.showPosition()+` +Expecting `+it.join(", ")+", got '"+(this.terminals_[J]||J)+"'":Z="Parse error on line "+(R+1)+": Unexpected "+(J==v?"end of input":"'"+(this.terminals_[J]||J)+"'"),this.parseError(Z,{text:w.match,token:this.terminals_[J]||J,line:w.yylineno,loc:z,expected:it})}if($[0]instanceof Array&&$.length>1)throw new Error("Parse Error: multiple actions possible at state: "+Y+", token: "+J);switch($[0]){case 1:x.push(J),T.push(w.yytext),C.push(w.yylloc),x.push($[1]),J=null,A=w.yyleng,S=w.yytext,R=w.yylineno,z=w.yylloc;break;case 2:if(tt=this.productions_[$[1]][1],ut.$=T[T.length-tt],ut._$={first_line:C[C.length-(tt||1)].first_line,last_line:C[C.length-1].last_line,first_column:C[C.length-(tt||1)].first_column,last_column:C[C.length-1].last_column},X&&(ut._$.range=[C[C.length-(tt||1)].range[0],C[C.length-1].range[1]]),lt=this.performAction.apply(ut,[S,A,R,D.yy,$[1],T,C].concat(B)),typeof lt<"u")return lt;tt&&(x=x.slice(0,-1*tt*2),T=T.slice(0,-1*tt),C=C.slice(0,-1*tt)),x.push(this.productions_[$[1]][0]),T.push(ut.$),C.push(ut._$),K=M[x[x.length-2]][x[x.length-1]],x.push(K);break;case 3:return!0}}return!0}},p=function(){var _={EOF:1,parseError:function(b,x){if(this.yy.parser)this.yy.parser.parseError(b,x);else throw new Error(b)},setInput:function(y,b){return this.yy=b||this.yy||{},this._input=y,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var y=this._input[0];this.yytext+=y,this.yyleng++,this.offset++,this.match+=y,this.matched+=y;var b=y.match(/(?:\r\n?|\n).*/g);return b?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),y},unput:function(y){var b=y.length,x=y.split(/(?:\r\n?|\n)/g);this._input=y+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b),this.offset-=b;var k=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),x.length-1&&(this.yylineno-=x.length-1);var T=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:x?(x.length===k.length?this.yylloc.first_column:0)+k[k.length-x.length].length-x[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[T[0],T[0]+this.yyleng-b]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true). +`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(y){this.unput(this.match.slice(y))},pastInput:function(){var y=this.matched.substr(0,this.matched.length-this.match.length);return(y.length>20?"...":"")+y.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var y=this.match;return y.length<20&&(y+=this._input.substr(0,20-y.length)),(y.substr(0,20)+(y.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var y=this.pastInput(),b=new Array(y.length+1).join("-");return y+this.upcomingInput()+` +`+b+"^"},test_match:function(y,b){var x,k,T;if(this.options.backtrack_lexer&&(T={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(T.yylloc.range=this.yylloc.range.slice(0))),k=y[0].match(/(?:\r\n?|\n).*/g),k&&(this.yylineno+=k.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:k?k[k.length-1].length-k[k.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+y[0].length},this.yytext+=y[0],this.match+=y[0],this.matches=y,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(y[0].length),this.matched+=y[0],x=this.performAction.call(this,this.yy,this,b,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),x)return x;if(this._backtrack){for(var C in T)this[C]=T[C];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var y,b,x,k;this._more||(this.yytext="",this.match="");for(var T=this._currentRules(),C=0;C<T.length;C++)if(x=this._input.match(this.rules[T[C]]),x&&(!b||x[0].length>b[0].length)){if(b=x,k=C,this.options.backtrack_lexer){if(y=this.test_match(x,T[C]),y!==!1)return y;if(this._backtrack){b=!1;continue}else return!1}else if(!this.options.flex)break}return b?(y=this.test_match(b,T[k]),y!==!1?y:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text. +`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var b=this.next();return b||this.lex()},begin:function(b){this.conditionStack.push(b)},popState:function(){var b=this.conditionStack.length-1;return b>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(b){return b=this.conditionStack.length-1-Math.abs(b||0),b>=0?this.conditionStack[b]:"INITIAL"},pushState:function(b){this.begin(b)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(b,x,k,T){switch(k){case 0:return this.begin("open_directive"),26;case 1:return this.begin("type_directive"),27;case 2:return this.popState(),this.begin("arg_directive"),15;case 3:return this.popState(),this.popState(),29;case 4:return 28;case 5:break;case 6:break;case 7:return 11;case 8:break;case 9:break;case 10:return 4;case 11:return 17;case 12:return this.begin("acc_title"),18;case 13:return this.popState(),"acc_title_value";case 14:return this.begin("acc_descr"),20;case 15:return this.popState(),"acc_descr_value";case 16:this.begin("acc_descr_multiline");break;case 17:this.popState();break;case 18:return"acc_descr_multiline_value";case 19:return 23;case 20:return 24;case 21:return 25;case 22:return 15;case 23:return 6;case 24:return"INVALID"}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:journey\b)/i,/^(?:title\s[^#\n;]+)/i,/^(?:accTitle\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*\{\s*)/i,/^(?:[\}])/i,/^(?:[^\}]*)/i,/^(?:section\s[^#:\n;]+)/i,/^(?:[^#:\n;]+)/i,/^(?::[^#\n;]+)/i,/^(?::)/i,/^(?:$)/i,/^(?:.)/i],conditions:{open_directive:{rules:[1],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},acc_descr_multiline:{rules:[17,18],inclusive:!1},acc_descr:{rules:[15],inclusive:!1},acc_title:{rules:[13],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,11,12,14,16,19,20,21,22,23,24],inclusive:!0}}};return _}();f.lexer=p;function m(){this.yy={}}return m.prototype=f,f.Parser=m,new m}();e_.parser=e_;const jat=t=>t.match(/^\s*journey/)!==null;let pl="";const r_=[],gu=[],gl=[],$at=function(t,e,r){Xe.parseDirective(this,t,e,r)},Xat=function(){r_.length=0,gu.length=0,pl="",gl.length=0,ci()},Kat=function(t){pl=t,r_.push(t)},Zat=function(){return r_},Qat=function(){let t=qL();const e=100;let r=0;for(;!t&&r<e;)t=qL(),r++;return gu.push(...gl),gu},Jat=function(){const t=[];return gu.forEach(r=>{r.people&&t.push(...r.people)}),[...new Set(t)].sort()},tst=function(t,e){const r=e.substr(1).split(":");let n=0,i=[];r.length===1?(n=Number(r[0]),i=[]):(n=Number(r[0]),i=r[1].split(","));const a=i.map(o=>o.trim()),s={section:pl,type:pl,people:a,task:t,score:n};gl.push(s)},est=function(t){const e={section:pl,type:pl,description:t,task:t,classes:[]};gu.push(e)},qL=function(){const t=function(r){return gl[r].processed};let e=!0;for(let r=0;r<gl.length;r++)t(r),e=e&&gl[r].processed;return e},VL={parseDirective:$at,getConfig:()=>nt().journey,clear:Xat,setDiagramTitle:c1,getDiagramTitle:u1,setAccTitle:Yn,getAccTitle:ui,setAccDescription:hi,getAccDescription:fi,addSection:Kat,getSections:Zat,getTasks:Qat,addTask:tst,addTaskOrg:est,getActors:function(){return Jat()}},x0=function(t,e){const r=t.append("rect");return r.attr("x",e.x),r.attr("y",e.y),r.attr("fill",e.fill),r.attr("stroke",e.stroke),r.attr("width",e.width),r.attr("height",e.height),r.attr("rx",e.rx),r.attr("ry",e.ry),typeof e.class<"u"&&r.attr("class",e.class),r},rst=function(t,e){const n=t.append("circle").attr("cx",e.cx).attr("cy",e.cy).attr("class","face").attr("r",15).attr("stroke-width",2).attr("overflow","visible"),i=t.append("g");i.append("circle").attr("cx",e.cx-15/3).attr("cy",e.cy-15/3).attr("r",1.5).attr("stroke-width",2).attr("fill","#666").attr("stroke","#666"),i.append("circle").attr("cx",e.cx+15/3).attr("cy",e.cy-15/3).attr("r",1.5).attr("stroke-width",2).attr("fill","#666").attr("stroke","#666");function a(l){const u=yf().startAngle(Math.PI/2).endAngle(3*(Math.PI/2)).innerRadius(7.5).outerRadius(6.8181818181818175);l.append("path").attr("class","mouth").attr("d",u).attr("transform","translate("+e.cx+","+(e.cy+2)+")")}function s(l){const u=yf().startAngle(3*Math.PI/2).endAngle(5*(Math.PI/2)).innerRadius(7.5).outerRadius(6.8181818181818175);l.append("path").attr("class","mouth").attr("d",u).attr("transform","translate("+e.cx+","+(e.cy+7)+")")}function o(l){l.append("line").attr("class","mouth").attr("stroke",2).attr("x1",e.cx-5).attr("y1",e.cy+7).attr("x2",e.cx+5).attr("y2",e.cy+7).attr("class","mouth").attr("stroke-width","1px").attr("stroke","#666")}return e.score>3?a(i):e.score<3?s(i):o(i),n},zL=function(t,e){const r=t.append("circle");return r.attr("cx",e.cx),r.attr("cy",e.cy),r.attr("class","actor-"+e.pos),r.attr("fill",e.fill),r.attr("stroke",e.stroke),r.attr("r",e.r),typeof r.class<"u"&&r.attr("class",r.class),typeof e.title<"u"&&r.append("title").text(e.title),r},YL=function(t,e){const r=e.text.replace(/<br\s*\/?>/gi," "),n=t.append("text");n.attr("x",e.x),n.attr("y",e.y),n.attr("class","legend"),n.style("text-anchor",e.anchor),typeof e.class<"u"&&n.attr("class",e.class);const i=n.append("tspan");return i.attr("x",e.x+e.textMargin*2),i.text(r),n},nst=function(t,e){function r(i,a,s,o,l){return i+","+a+" "+(i+s)+","+a+" "+(i+s)+","+(a+o-l)+" "+(i+s-l*1.2)+","+(a+o)+" "+i+","+(a+o)}const n=t.append("polygon");n.attr("points",r(e.x,e.y,50,20,7)),n.attr("class","labelBox"),e.y=e.y+e.labelMargin,e.x=e.x+.5*e.labelMargin,YL(t,e)},ist=function(t,e,r){const n=t.append("g"),i=n_();i.x=e.x,i.y=e.y,i.fill=e.fill,i.width=r.width,i.height=r.height,i.class="journey-section section-type-"+e.num,i.rx=3,i.ry=3,x0(n,i),WL(r)(e.text,n,i.x,i.y,i.width,i.height,{class:"journey-section section-type-"+e.num},r,e.colour)};let UL=-1;const ast=function(t,e,r){const n=e.x+r.width/2,i=t.append("g");UL++;const a=300+5*30;i.append("line").attr("id","task"+UL).attr("x1",n).attr("y1",e.y).attr("x2",n).attr("y2",a).attr("class","task-line").attr("stroke-width","1px").attr("stroke-dasharray","4 2").attr("stroke","#666"),rst(i,{cx:n,cy:300+(5-e.score)*30,score:e.score});const s=n_();s.x=e.x,s.y=e.y,s.fill=e.fill,s.width=r.width,s.height=r.height,s.class="task task-type-"+e.num,s.rx=3,s.ry=3,x0(i,s);let o=e.x+14;e.people.forEach(l=>{const u=e.actors[l].color,h={cx:o,cy:e.y,r:7,fill:u,stroke:"#000",title:l,pos:e.actors[l].position};zL(i,h),o+=10}),WL(r)(e.task,i,s.x,s.y,s.width,s.height,{class:"task"},r,e.colour)},sst=function(t,e){x0(t,{x:e.startx,y:e.starty,width:e.stopx-e.startx,height:e.stopy-e.starty,fill:e.fill,class:"rect"}).lower()},ost=function(){return{x:0,y:0,fill:void 0,"text-anchor":"start",width:100,height:100,textMargin:0,rx:0,ry:0}},n_=function(){return{x:0,y:0,width:100,anchor:"start",height:100,rx:0,ry:0}},WL=function(){function t(i,a,s,o,l,u,h,d){const f=a.append("text").attr("x",s+l/2).attr("y",o+u/2+5).style("font-color",d).style("text-anchor","middle").text(i);n(f,h)}function e(i,a,s,o,l,u,h,d,f){const{taskFontSize:p,taskFontFamily:m}=d,_=i.split(/<br\s*\/?>/gi);for(let y=0;y<_.length;y++){const b=y*p-p*(_.length-1)/2,x=a.append("text").attr("x",s+l/2).attr("y",o).attr("fill",f).style("text-anchor","middle").style("font-size",p).style("font-family",m);x.append("tspan").attr("x",s+l/2).attr("dy",b).text(_[y]),x.attr("y",o+u/2).attr("dominant-baseline","central").attr("alignment-baseline","central"),n(x,h)}}function r(i,a,s,o,l,u,h,d){const f=a.append("switch"),m=f.append("foreignObject").attr("x",s).attr("y",o).attr("width",l).attr("height",u).attr("position","fixed").append("xhtml:div").style("display","table").style("height","100%").style("width","100%");m.append("div").attr("class","label").style("display","table-cell").style("text-align","center").style("vertical-align","middle").text(i),e(i,f,s,o,l,u,h,d),n(m,h)}function n(i,a){for(const s in a)s in a&&i.attr(s,a[s])}return function(i){return i.textPlacement==="fo"?r:i.textPlacement==="old"?t:e}}(),yu={drawRect:x0,drawCircle:zL,drawSection:ist,drawText:YL,drawLabel:nst,drawTask:ast,drawBackgroundRect:sst,getTextObj:ost,getNoteRect:n_,initGraphics:function(t){t.append("defs").append("marker").attr("id","arrowhead").attr("refX",5).attr("refY",2).attr("markerWidth",6).attr("markerHeight",4).attr("orient","auto").append("path").attr("d","M 0,0 V 4 L6,2 Z")}},lst=function(t){Object.keys(t).forEach(function(r){k0[r]=t[r]})},ba={};function cst(t){const e=nt().journey;let r=60;Object.keys(ba).forEach(n=>{const i=ba[n].color,a={cx:20,cy:r,r:7,fill:i,stroke:"#000",pos:ba[n].position};yu.drawCircle(t,a);const s={x:40,y:r+7,fill:"#666",text:n,textMargin:e.boxTextMargin|5};yu.drawText(t,s),r+=20})}const k0=nt().journey,$s=k0.leftMargin,ust=function(t,e,r,n){const i=nt().journey;n.db.clear(),n.parser.parse(t+` +`);const a=nt().securityLevel;let s;a==="sandbox"&&(s=St("#i"+e));const o=St(a==="sandbox"?s.nodes()[0].contentDocument.body:"body");jn.init();const l=o.select("#"+e);yu.initGraphics(l);const u=n.db.getTasks(),h=n.db.getDiagramTitle(),d=n.db.getActors();for(const b in ba)delete ba[b];let f=0;d.forEach(b=>{ba[b]={color:i.actorColours[f%i.actorColours.length],position:f},f++}),cst(l),jn.insert(0,0,$s,Object.keys(ba).length*50),hst(l,u,0);const p=jn.getBounds();h&&l.append("text").text(h).attr("x",$s).attr("font-size","4ex").attr("font-weight","bold").attr("y",25);const m=p.stopy-p.starty+2*i.diagramMarginY,_=$s+p.stopx+2*i.diagramMarginX;li(l,m,_,i.useMaxWidth),l.append("line").attr("x1",$s).attr("y1",i.height*4).attr("x2",_-$s-4).attr("y2",i.height*4).attr("stroke-width",4).attr("stroke","black").attr("marker-end","url(#arrowhead)");const y=h?70:0;l.attr("viewBox",`${p.startx} -25 ${_} ${m+y}`),l.attr("preserveAspectRatio","xMinYMin meet"),l.attr("height",m+y+25),bn(n.db,l,e)},jn={data:{startx:void 0,stopx:void 0,starty:void 0,stopy:void 0},verticalPos:0,sequenceItems:[],init:function(){this.sequenceItems=[],this.data={startx:void 0,stopx:void 0,starty:void 0,stopy:void 0},this.verticalPos=0},updateVal:function(t,e,r,n){typeof t[e]>"u"?t[e]=r:t[e]=n(r,t[e])},updateBounds:function(t,e,r,n){const i=nt().journey,a=this;let s=0;function o(l){return function(h){s++;const d=a.sequenceItems.length-s+1;a.updateVal(h,"starty",e-d*i.boxMargin,Math.min),a.updateVal(h,"stopy",n+d*i.boxMargin,Math.max),a.updateVal(jn.data,"startx",t-d*i.boxMargin,Math.min),a.updateVal(jn.data,"stopx",r+d*i.boxMargin,Math.max),l!=="activation"&&(a.updateVal(h,"startx",t-d*i.boxMargin,Math.min),a.updateVal(h,"stopx",r+d*i.boxMargin,Math.max),a.updateVal(jn.data,"starty",e-d*i.boxMargin,Math.min),a.updateVal(jn.data,"stopy",n+d*i.boxMargin,Math.max))}}this.sequenceItems.forEach(o())},insert:function(t,e,r,n){const i=Math.min(t,r),a=Math.max(t,r),s=Math.min(e,n),o=Math.max(e,n);this.updateVal(jn.data,"startx",i,Math.min),this.updateVal(jn.data,"starty",s,Math.min),this.updateVal(jn.data,"stopx",a,Math.max),this.updateVal(jn.data,"stopy",o,Math.max),this.updateBounds(i,s,a,o)},bumpVerticalPos:function(t){this.verticalPos=this.verticalPos+t,this.data.stopy=this.verticalPos},getVerticalPos:function(){return this.verticalPos},getBounds:function(){return this.data}},i_=k0.sectionFills,HL=k0.sectionColours,hst=function(t,e,r){const n=nt().journey;let i="";const a=n.height*2+n.diagramMarginY,s=r+a;let o=0,l="#CCC",u="black",h=0;for(let d=0;d<e.length;d++){const f=e[d];if(i!==f.section){l=i_[o%i_.length],h=o%i_.length,u=HL[o%HL.length];const m={x:d*n.taskMargin+d*n.width+$s,y:50,text:f.section,fill:l,num:h,colour:u};yu.drawSection(t,m,n),i=f.section,o++}const p=f.people.reduce((m,_)=>(ba[_]&&(m[_]=ba[_]),m),{});f.x=d*n.taskMargin+d*n.width+$s,f.y=s,f.width=n.diagramMarginX,f.height=n.diagramMarginY,f.colour=u,f.fill=l,f.num=h,f.actors=p,yu.drawTask(t,f,n),jn.insert(f.x,f.y,f.x+f.width+n.taskMargin,300+5*30)}},GL={setConf:lst,draw:ust};let jL={};const a_={setConf:function(t){jL={...jL,...t}},draw:(t,e,r)=>{try{H.debug(`Renering svg for syntax error +`);const n=St("#"+e),i=n.append("g");i.append("path").attr("class","error-icon").attr("d","m411.313,123.313c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32-9.375,9.375-20.688-20.688c-12.484-12.5-32.766-12.5-45.25,0l-16,16c-1.261,1.261-2.304,2.648-3.31,4.051-21.739-8.561-45.324-13.426-70.065-13.426-105.867,0-192,86.133-192,192s86.133,192 192,192 192-86.133 192-192c0-24.741-4.864-48.327-13.426-70.065 1.402-1.007 2.79-2.049 4.051-3.31l16-16c12.5-12.492 12.5-32.758 0-45.25l-20.688-20.688 9.375-9.375 32.001-31.999zm-219.313,100.687c-52.938,0-96,43.063-96,96 0,8.836-7.164,16-16,16s-16-7.164-16-16c0-70.578 57.422-128 128-128 8.836,0 16,7.164 16,16s-7.164,16-16,16z"),i.append("path").attr("class","error-icon").attr("d","m459.02,148.98c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l16,16c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16.001-16z"),i.append("path").attr("class","error-icon").attr("d","m340.395,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16-16c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l15.999,16z"),i.append("path").attr("class","error-icon").attr("d","m400,64c8.844,0 16-7.164 16-16v-32c0-8.836-7.156-16-16-16-8.844,0-16,7.164-16,16v32c0,8.836 7.156,16 16,16z"),i.append("path").attr("class","error-icon").attr("d","m496,96.586h-32c-8.844,0-16,7.164-16,16 0,8.836 7.156,16 16,16h32c8.844,0 16-7.164 16-16 0-8.836-7.156-16-16-16z"),i.append("path").attr("class","error-icon").attr("d","m436.98,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688l32-32c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32c-6.251,6.25-6.251,16.375-0.001,22.625z"),i.append("text").attr("class","error-text").attr("x",1440).attr("y",250).attr("font-size","150px").style("text-anchor","middle").text("Syntax error in graph"),i.append("text").attr("class","error-text").attr("x",1250).attr("y",400).attr("font-size","100px").style("text-anchor","middle").text("mermaid version "+r),n.attr("height",100),n.attr("width",500),n.attr("viewBox","768 0 912 512")}catch(n){H.error("Error while rendering info diagram"),H.error(hX(n))}}};let $L=!1;const mu=()=>{$L||($L=!0,Lr("error",{db:{clear:()=>{}},styles:Aw,renderer:a_,parser:{parser:{yy:{}},parse:()=>{}},init:()=>{}},t=>t.toLowerCase().trim()==="error"),Lr("c4",{parser:qc,db:Xw,renderer:a9,styles:Dw,init:t=>{a9.setConf(t.c4)}},lK),Lr("class",{parser:_1,db:Jo,renderer:qtt,styles:Nc,init:t=>{t.class||(t.class={}),t.class.arrowMarkerAbsolute=t.arrowMarkerAbsolute,Jo.clear()}},ZK),Lr("classDiagram",{parser:_1,db:Jo,renderer:Oet,styles:Nc,init:t=>{t.class||(t.class={}),t.class.arrowMarkerAbsolute=t.arrowMarkerAbsolute,Jo.clear()}},QK),Lr("er",{parser:a4,db:zet,renderer:ert,styles:Sw},Fet),Lr("gantt",{parser:M4,db:P4,renderer:rit,styles:Mw},Snt),Lr("info",{parser:q4,db:nit,renderer:iit,styles:Lw},ait),Lr("pie",{parser:V4,db:oit,renderer:lit,styles:Rw},sit),Lr("requirement",{parser:Y4,db:uit,renderer:mit,styles:Iw},cit),Lr("sequence",{parser:H4,db:mL,renderer:AL,styles:Nw,init:t=>{if(t.sequence||(t.sequence={}),t.sequence.arrowMarkerAbsolute=t.arrowMarkerAbsolute,"sequenceDiagram"in t)throw new Error("`mermaid config.sequenceDiagram` has been renamed to `config.sequence`. Please update your mermaid config.");mL.setWrap(t.wrap),AL.setConf(t.sequence)}},bit),Lr("state",{parser:p0,db:ma,renderer:zat,styles:s1,init:t=>{t.state||(t.state={}),t.state.arrowMarkerAbsolute=t.arrowMarkerAbsolute,ma.clear()}},fat),Lr("stateDiagram",{parser:p0,db:ma,renderer:Gat,styles:s1,init:t=>{t.state||(t.state={}),t.state.arrowMarkerAbsolute=t.arrowMarkerAbsolute,ma.clear()}},dat),Lr("journey",{parser:e_,db:VL,renderer:GL,styles:Bw,init:t=>{GL.setConf(t.journey),VL.clear()}},jat),Lr("flowchart",{parser:X1,db:fa,renderer:A4,styles:a1,init:t=>{t.flowchart||(t.flowchart={}),t.flowchart.arrowMarkerAbsolute=t.arrowMarkerAbsolute,S4.setConf(t.flowchart),fa.clear(),fa.setGen("gen-1")}},rrt),Lr("flowchart-v2",{parser:X1,db:fa,renderer:A4,styles:a1,init:t=>{t.flowchart||(t.flowchart={}),t.flowchart.arrowMarkerAbsolute=t.arrowMarkerAbsolute,kw({flowchart:{arrowMarkerAbsolute:t.arrowMarkerAbsolute}}),A4.setConf(t.flowchart),fa.clear(),fa.setGen("gen-2")}},nrt),Lr("gitGraph",{parser:hg,db:JX,renderer:sK,styles:oK},BX))};class bu{constructor(e,r){vl(this,"type","graph");vl(this,"parser");vl(this,"renderer");vl(this,"db");vl(this,"detectTypeFailed",!1);var a,s;this.txt=e;const n=nt();this.txt=e;try{this.type=Xp(e,n)}catch(o){this.handleError(o,r),this.type="error",this.detectTypeFailed=!0}const i=Pw(this.type);H.debug("Type "+this.type),this.db=i.db,(s=(a=this.db).clear)==null||s.call(a),this.renderer=i.renderer,this.parser=i.parser,this.parser.parser.yy=this.db,i.init&&(i.init(n),H.debug("Initialized diagram "+this.type,n)),this.txt+=` +`,this.parse(this.txt,r)}parse(e,r){if(this.detectTypeFailed)return!1;try{return e=e+` +`,this.db.clear(),this.parser.parse(e),!0}catch(n){this.handleError(n,r)}return!1}handleError(e,r){if(r)ng(e)?r(e.str,e.hash):r(e);else throw e}getParser(){return this.parser}getType(){return this.type}}const s_=(t,e)=>{const r=Xp(t,nt());try{return Pw(r),new bu(t,e)}catch(n){if(!(n instanceof qw))throw H.error(n),n;const i=wG(r);if(!i)throw new Error(`Loader for ${r} not found.`);return i().then(({diagram:a})=>(Lr(r,a,void 0),new bu(t,e)))}};function fst(t,e){return mu(),new bu(t,e).parse(t,e)}async function dst(t,e){return mu(),(await s_(t,e)).parse(t,e)}const XL=function(t){let e=t;return e=e.replace(/style.*:\S*#.*;/g,function(r){return r.substring(0,r.length-1)}),e=e.replace(/classDef.*:\S*#.*;/g,function(r){return r.substring(0,r.length-1)}),e=e.replace(/#\w+;/g,function(r){const n=r.substring(1,r.length-1);return/^\+?\d+$/.test(n)?"\uFB02\xB0\xB0"+n+"\xB6\xDF":"\uFB02\xB0"+n+"\xB6\xDF"}),e},w0=function(t){let e=t;return e=e.replace(/fl°°/g,function(){return"&#"}),e=e.replace(/fl°/g,function(){return"&"}),e=e.replace(/¶ß/g,function(){return";"}),e},pst=function(t,e,r,n){var T;mu(),Ic(),e=e.replace(/\r\n?/g,` +`);const i=Se.detectInit(e);i&&(Vs(i),ug(i));const a=nt();H.debug(a),e.length>a.maxTextSize&&(e="graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa");let s=St("body");if(typeof n<"u"){if(n&&(n.innerHTML=""),a.securityLevel==="sandbox"){const C=St(n).append("iframe").attr("id","i"+t).attr("style","width: 100%; height: 100%;").attr("sandbox","");s=St(C.nodes()[0].contentDocument.body),s.node().style.margin=0}else s=St(n);s.append("div").attr("id","d"+t).attr("style","font-family: "+a.fontFamily).append("svg").attr("id",t).attr("width","100%").attr("xmlns","http://www.w3.org/2000/svg").attr("xmlns:xlink","http://www.w3.org/1999/xlink").append("g")}else{const C=document.getElementById(t);C&&C.remove();let M;if(a.securityLevel==="sandbox"?M=document.querySelector("#i"+t):M=document.querySelector("#d"+t),M&&M.remove(),a.securityLevel==="sandbox"){const S=St("body").append("iframe").attr("id","i"+t).attr("style","width: 100%; height: 100%;").attr("sandbox","");s=St(S.nodes()[0].contentDocument.body),s.node().style.margin=0}else s=St("body");s.append("div").attr("id","d"+t).append("svg").attr("id",t).attr("width","100%").attr("xmlns","http://www.w3.org/2000/svg").append("g")}e=XL(e);let o,l;try{if(o=s_(e),"then"in o)throw new Error("Diagram is a promise")}catch(C){o=new bu("error"),l=C}const u=s.select("#d"+t).node(),h=o.type,d=u.firstChild,f=d.firstChild;let p="";if(a.themeCSS!==void 0&&(p+=` +${a.themeCSS}`),a.fontFamily!==void 0&&(p+=` +:root { --mermaid-font-family: ${a.fontFamily}}`),a.altFontFamily!==void 0&&(p+=` +:root { --mermaid-alt-font-family: ${a.altFontFamily}}`),h==="flowchart"||h==="flowchart-v2"||h==="graph"){const C=S4.getClasses(e,o),M=a.htmlLabels||((T=a.flowchart)==null?void 0:T.htmlLabels);for(const S in C)M?(p+=` +.${S} > * { ${C[S].styles.join(" !important; ")} !important; }`,p+=` +.${S} span { ${C[S].styles.join(" !important; ")} !important; }`):(p+=` +.${S} path { ${C[S].styles.join(" !important; ")} !important; }`,p+=` +.${S} rect { ${C[S].styles.join(" !important; ")} !important; }`,p+=` +.${S} polygon { ${C[S].styles.join(" !important; ")} !important; }`,p+=` +.${S} ellipse { ${C[S].styles.join(" !important; ")} !important; }`,p+=` +.${S} circle { ${C[S].styles.join(" !important; ")} !important; }`,C[S].textStyles&&(p+=` +.${S} tspan { ${C[S].textStyles.join(" !important; ")} !important; }`))}const _=((C,M)=>e1(yw(`${C}{${M}}`),_w))(`#${t}`,Ow(h,p,a.themeVariables)),y=document.createElement("style");y.innerHTML=`#${t} `+_,d.insertBefore(y,f);try{o.renderer.draw(e,t,r1.version,o)}catch(C){throw a_.draw(e,t,r1.version),C}s.select(`[id="${t}"]`).selectAll("foreignobject > *").attr("xmlns","http://www.w3.org/1999/xhtml");let b=s.select("#d"+t).node().innerHTML;if(H.debug("cnf.arrowMarkerAbsolute",a.arrowMarkerAbsolute),!Mr(a.arrowMarkerAbsolute)&&a.securityLevel!=="sandbox"&&(b=b.replace(/marker-end="url\(.*?#/g,'marker-end="url(#',"g")),b=w0(b),b=b.replace(/<br>/g,"<br/>"),a.securityLevel==="sandbox"){const C=s.select("#d"+t+" svg").node(),M="100%";let S="100%";C&&(S=C.viewBox.baseVal.height+"px"),b=`<iframe style="width:${M};height:${S};border:0;margin:0;" src="data:text/html;base64,${btoa('<body style="margin:0">'+b+"</body>")}" sandbox="allow-top-navigation-by-user-activation allow-popups"> + The \u201Ciframe\u201D tag is not supported by your browser. +</iframe>`}else a.securityLevel!=="loose"&&(b=Ec.sanitize(b,{ADD_TAGS:["foreignobject"],ADD_ATTR:["dominant-baseline"]}));if(typeof r<"u")switch(h){case"flowchart":case"flowchart-v2":r(b,fa.bindFunctions);break;case"gantt":r(b,P4.bindFunctions);break;case"class":case"classDiagram":r(b,Jo.bindFunctions);break;default:r(b)}else H.debug("CB = undefined!");bL();const x=a.securityLevel==="sandbox"?"#i"+t:"#d"+t,k=St(x).node();if(k&&"remove"in k&&k.remove(),l)throw l;return b},gst=async function(t,e,r,n){var T;mu(),Ic(),e=e.replace(/\r\n?/g,` +`);const i=Se.detectInit(e);i&&(Vs(i),ug(i));const a=nt();H.debug(a),e.length>a.maxTextSize&&(e="graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa");let s=St("body");if(typeof n<"u"){if(n&&(n.innerHTML=""),a.securityLevel==="sandbox"){const C=St(n).append("iframe").attr("id","i"+t).attr("style","width: 100%; height: 100%;").attr("sandbox","");s=St(C.nodes()[0].contentDocument.body),s.node().style.margin=0}else s=St(n);s.append("div").attr("id","d"+t).attr("style","font-family: "+a.fontFamily).append("svg").attr("id",t).attr("width","100%").attr("xmlns","http://www.w3.org/2000/svg").attr("xmlns:xlink","http://www.w3.org/1999/xlink").append("g")}else{const C=document.getElementById(t);C&&C.remove();let M;if(a.securityLevel==="sandbox"?M=document.querySelector("#i"+t):M=document.querySelector("#d"+t),M&&M.remove(),a.securityLevel==="sandbox"){const S=St("body").append("iframe").attr("id","i"+t).attr("style","width: 100%; height: 100%;").attr("sandbox","");s=St(S.nodes()[0].contentDocument.body),s.node().style.margin=0}else s=St("body");s.append("div").attr("id","d"+t).append("svg").attr("id",t).attr("width","100%").attr("xmlns","http://www.w3.org/2000/svg").append("g")}e=XL(e);let o,l;try{o=await s_(e)}catch(C){o=new bu("error"),l=C}const u=s.select("#d"+t).node(),h=o.type,d=u.firstChild,f=d.firstChild;let p="";if(a.themeCSS!==void 0&&(p+=` +${a.themeCSS}`),a.fontFamily!==void 0&&(p+=` +:root { --mermaid-font-family: ${a.fontFamily}}`),a.altFontFamily!==void 0&&(p+=` +:root { --mermaid-alt-font-family: ${a.altFontFamily}}`),h==="flowchart"||h==="flowchart-v2"||h==="graph"){const C=S4.getClasses(e,o),M=a.htmlLabels||((T=a.flowchart)==null?void 0:T.htmlLabels);for(const S in C)M?(p+=` +.${S} > * { ${C[S].styles.join(" !important; ")} !important; }`,p+=` +.${S} span { ${C[S].styles.join(" !important; ")} !important; }`):(p+=` +.${S} path { ${C[S].styles.join(" !important; ")} !important; }`,p+=` +.${S} rect { ${C[S].styles.join(" !important; ")} !important; }`,p+=` +.${S} polygon { ${C[S].styles.join(" !important; ")} !important; }`,p+=` +.${S} ellipse { ${C[S].styles.join(" !important; ")} !important; }`,p+=` +.${S} circle { ${C[S].styles.join(" !important; ")} !important; }`,C[S].textStyles&&(p+=` +.${S} tspan { ${C[S].textStyles.join(" !important; ")} !important; }`))}const _=((C,M)=>e1(yw(`${C}{${M}}`),_w))(`#${t}`,Ow(h,p,a.themeVariables)),y=document.createElement("style");y.innerHTML=`#${t} `+_,d.insertBefore(y,f);try{await o.renderer.draw(e,t,r1.version,o)}catch(C){throw a_.draw(e,t,r1.version),C}s.select(`[id="${t}"]`).selectAll("foreignobject > *").attr("xmlns","http://www.w3.org/1999/xhtml");let b=s.select("#d"+t).node().innerHTML;if(H.debug("cnf.arrowMarkerAbsolute",a.arrowMarkerAbsolute),!Mr(a.arrowMarkerAbsolute)&&a.securityLevel!=="sandbox"&&(b=b.replace(/marker-end="url\(.*?#/g,'marker-end="url(#',"g")),b=w0(b),b=b.replace(/<br>/g,"<br/>"),a.securityLevel==="sandbox"){const C=s.select("#d"+t+" svg").node(),M="100%";let S="100%";C&&(S=C.viewBox.baseVal.height+"px"),b=`<iframe style="width:${M};height:${S};border:0;margin:0;" src="data:text/html;base64,${btoa('<body style="margin:0">'+b+"</body>")}" sandbox="allow-top-navigation-by-user-activation allow-popups"> + The \u201Ciframe\u201D tag is not supported by your browser. +</iframe>`}else a.securityLevel!=="loose"&&(b=Ec.sanitize(b,{ADD_TAGS:["foreignobject"],ADD_ATTR:["dominant-baseline"]}));if(typeof r<"u")switch(h){case"flowchart":case"flowchart-v2":r(b,fa.bindFunctions);break;case"gantt":r(b,P4.bindFunctions);break;case"class":case"classDiagram":r(b,Jo.bindFunctions);break;default:r(b)}else H.debug("CB = undefined!");bL();const x=a.securityLevel==="sandbox"?"#i"+t:"#d"+t,k=St(x).node();if(k&&"remove"in k&&k.remove(),l)throw l;return b};let Xs={};const yst=function(t,e,r,n){try{if(e!==void 0)switch(e=e.trim(),r){case"open_directive":Xs={};break;case"type_directive":if(!Xs)throw new Error("currentDirective is undefined");Xs.type=e.toLowerCase();break;case"arg_directive":if(!Xs)throw new Error("currentDirective is undefined");Xs.args=JSON.parse(e);break;case"close_directive":mst(t,Xs,n),Xs=void 0;break}}catch(i){H.error(`Error while rendering sequenceDiagram directive: ${e} jison context: ${r}`),H.error(i.message)}},mst=function(t,e,r){switch(H.debug(`Directive type=${e.type} with args:`,e.args),e.type){case"init":case"initialize":{["config"].forEach(n=>{typeof e.args[n]<"u"&&(r==="flowchart-v2"&&(r="flowchart"),e.args[r]=e.args[n],delete e.args[n])}),H.debug("sanitize in handleDirective",e.args),Vs(e.args),H.debug("sanitize in handleDirective (done)",e.args),ug(e.args);break}case"wrap":case"nowrap":t&&t.setWrap&&t.setWrap(e.type==="wrap");break;case"themeCss":H.warn("themeCss encountered");break;default:H.warn(`Unhandled directive: source: '%%{${e.type}: ${JSON.stringify(e.args?e.args:{})}}%%`,e);break}};function bst(t={}){t.fontFamily&&(t.themeVariables||(t.themeVariables={}),t.themeVariables.fontFamily=t.fontFamily),CX(t),(t==null?void 0:t.theme)&&t.theme in aa?t.themeVariables=aa[t.theme].getThemeVariables(t.themeVariables):t&&(t.themeVariables=aa.default.getThemeVariables(t.themeVariables));const e=typeof t=="object"?EX(t):xw();D0(e.logLevel),mu()}const Xe=Object.freeze({render:pst,renderAsync:gst,parse:fst,parseAsync:dst,parseDirective:yst,initialize:bst,getConfig:nt,setConfig:kw,getSiteConfig:xw,updateSiteConfig:SX,reset:()=>{Ic()},globalReset:()=>{Ic(Xo)},defaultConfig:Xo});D0(nt().logLevel),Ic(nt());let KL=!1;const _st=async function(t,e,r){try{KL?await JL(t,e,r):QL(t,e,r)}catch(n){H.warn("Syntax Error rendering"),ng(n)&&H.warn(n.str),$n.parseError&&$n.parseError(n)}},ZL=(t,e,r)=>{H.warn(t),ng(t)?(r&&r(t.str,t.hash),e.push({...t,message:t.str,error:t})):(r&&r(t),t instanceof Error&&e.push({str:t.message,message:t.message,hash:t.name,error:t}))},QL=function(t,e,r){const n=Xe.getConfig();t&&($n.sequenceConfig=t),H.debug(`${r?"":"No "}Callback function found`);let i;if(typeof e>"u")i=document.querySelectorAll(".mermaid");else if(typeof e=="string")i=document.querySelectorAll(e);else if(e instanceof HTMLElement)i=[e];else if(e instanceof NodeList)i=e;else throw new Error("Invalid argument nodes for mermaid.init");H.debug(`Found ${i.length} diagrams`),typeof(t==null?void 0:t.startOnLoad)<"u"&&(H.debug("Start On Load: "+(t==null?void 0:t.startOnLoad)),Xe.updateSiteConfig({startOnLoad:t==null?void 0:t.startOnLoad}));const a=new Se.initIdGenerator(n.deterministicIds,n.deterministicIDSeed);let s;const o=[];for(const l of Array.from(i)){H.info("Rendering diagram: "+l.id);/*! Check if previously processed */if(l.getAttribute("data-processed"))continue;l.setAttribute("data-processed","true");const u=`mermaid-${a.next()}`;s=l.innerHTML,s=Se.entityDecode(s).trim().replace(/<br\s*\/?>/gi,"<br/>");const h=Se.detectInit(s);h&&H.debug("Detected early reinit: ",h);try{Xe.render(u,s,(d,f)=>{l.innerHTML=d,typeof r<"u"&&r(u),f&&f(l)},l)}catch(d){ZL(d,o,$n.parseError)}}if(o.length>0)throw o[0]},vst=t=>{for(const{id:e,detector:r,loader:n}of t)$k(e,r,n)},xst=async t=>{H.debug(`Loading ${t.length} external diagrams`);const r=(await Promise.allSettled(t.map(async({id:n,detector:i,loader:a})=>{const{diagram:s}=await a();Lr(n,s,i)}))).filter(n=>n.status==="rejected");if(r.length>0){H.error(`Failed to load ${r.length} external diagrams`);for(const n of r)H.error(n);throw new Error(`Failed to load ${r.length} external diagrams`)}},JL=async function(t,e,r){const n=Xe.getConfig();t&&($n.sequenceConfig=t),H.debug(`${r?"":"No "}Callback function found`);let i;if(typeof e>"u")i=document.querySelectorAll(".mermaid");else if(typeof e=="string")i=document.querySelectorAll(e);else if(e instanceof HTMLElement)i=[e];else if(e instanceof NodeList)i=e;else throw new Error("Invalid argument nodes for mermaid.init");H.debug(`Found ${i.length} diagrams`),typeof(t==null?void 0:t.startOnLoad)<"u"&&(H.debug("Start On Load: "+(t==null?void 0:t.startOnLoad)),Xe.updateSiteConfig({startOnLoad:t==null?void 0:t.startOnLoad}));const a=new Se.initIdGenerator(n.deterministicIds,n.deterministicIDSeed);let s;const o=[];for(const l of Array.from(i)){H.info("Rendering diagram: "+l.id);/*! Check if previously processed */if(l.getAttribute("data-processed"))continue;l.setAttribute("data-processed","true");const u=`mermaid-${a.next()}`;s=l.innerHTML,s=Se.entityDecode(s).trim().replace(/<br\s*\/?>/gi,"<br/>");const h=Se.detectInit(s);h&&H.debug("Detected early reinit: ",h);try{await Xe.renderAsync(u,s,(d,f)=>{l.innerHTML=d,typeof r<"u"&&r(u),f&&f(l)},l)}catch(d){ZL(d,o,$n.parseError)}}if(o.length>0)throw o[0]},kst=function(t){Xe.initialize(t)},wst=async(t,{lazyLoad:e=!0}={})=>{e?vst(t):await xst(t),KL=!0},tR=function(){if($n.startOnLoad){const{startOnLoad:t}=Xe.getConfig();t&&$n.init()}};if(typeof document<"u"){/*! + * Wait for document loaded before starting the execution + */window.addEventListener("load",tR,!1)}const Tst=function(t){$n.parseError=t},Est=t=>Xe.parse(t,$n.parseError),T0=[];let o_=!1;const eR=async()=>{if(!o_){for(o_=!0;T0.length>0;){const t=T0.shift();if(t)try{await t()}catch(e){H.error("Error executing queue",e)}}o_=!1}},Cst=t=>new Promise((e,r)=>{const n=()=>new Promise((i,a)=>{Xe.parseAsync(t,$n.parseError).then(s=>{i(s),e(s)},s=>{H.error("Error parsing",s),a(s),r(s)})});T0.push(n),eR()}),Sst=(t,e,r,n)=>new Promise((i,a)=>{const s=()=>new Promise((o,l)=>{Xe.renderAsync(t,e,r,n).then(u=>{o(u),i(u)},u=>{H.error("Error parsing",u),l(u),a(u)})});T0.push(s),eR()}),$n={startOnLoad:!0,diagrams:{},mermaidAPI:Xe,parse:Est,parseAsync:Cst,render:Xe.render,renderAsync:Sst,init:_st,initThrowsErrors:QL,initThrowsErrorsAsync:JL,registerExternalDiagrams:wst,initialize:kst,parseError:void 0,contentLoaded:tR,setParseErrorHandler:Tst};return $n}); +//# sourceMappingURL=mermaid.min.js.map diff --git a/book/en/src/SUMMARY.md b/book/en/src/SUMMARY.md index 853f3a5..587117c 100644 --- a/book/en/src/SUMMARY.md +++ b/book/en/src/SUMMARY.md @@ -4,15 +4,13 @@ - [RTIC by example](./by-example.md) - [The `app`](./by-example/app.md) + - [Hardware tasks & `pend`](./by-example/hardware_tasks.md) + - [Software tasks & `spawn`](./by-example/software_tasks.md) - [Resources](./by-example/resources.md) - [The init task](./by-example/app_init.md) - [The idle task](./by-example/app_idle.md) - - [Defining tasks](./by-example/app_task.md) - - [Hardware tasks](./by-example/hardware_tasks.md) - - [Software tasks & `spawn`](./by-example/software_tasks.md) - - [Message passing & `capacity`](./by-example/message_passing.md) - - [Task priorities](./by-example/app_priorities.md) - - [Monotonic & `spawn_{at/after}`](./by-example/monotonic.md) + - [Channel based communication](./by-example/channel.md) + - [Delay and Timeout](./by-example/delay.md) - [Starting a new project](./by-example/starting_a_project.md) - [The minimal app](./by-example/app_minimal.md) - [Tips & Tricks](./by-example/tips.md) @@ -21,13 +19,14 @@ - [Avoid copies when message passing](./by-example/tips_indirection.md) - [`'static` super-powers](./by-example/tips_static_lifetimes.md) - [Inspecting generated code](./by-example/tips_view_code.md) - - [Running tasks from RAM](./by-example/tips_from_ram.md) + <!-- - [Running tasks from RAM](./by-example/tips_from_ram.md) --> <!-- - [`#[cfg(..)]` support](./by-example/tips.md) --> +- [RTIC vs. the world](./rtic_vs.md) - [Awesome RTIC examples](./awesome_rtic.md) -- [Migration Guides](./migration.md) +<!-- - [Migration Guides](./migration.md) - [v0.5.x to v1.0.x](./migration/migration_v5.md) - [v0.4.x to v0.5.x](./migration/migration_v4.md) - - [RTFM to RTIC](./migration/migration_rtic.md) + - [RTFM to RTIC](./migration/migration_rtic.md) --> - [Under the hood](./internals.md) - [Cortex-M architectures](./internals/targets.md) <!--- [Interrupt configuration](./internals/interrupt-configuration.md)--> @@ -38,3 +37,10 @@ <!--- [Ceiling analysis](./internals/ceilings.md)--> <!--- [Software tasks](./internals/tasks.md)--> <!--- [Timer queue](./internals/timer-queue.md)--> + + <!-- - [Defining tasks](./by-example/app_task.md) --> + <!-- - [Software tasks & `spawn`](./by-example/software_tasks.md) + - [Message passing & `capacity`](./by-example/message_passing.md) + - [Task priorities](./by-example/app_priorities.md) + - [Monotonic & `spawn_{at/after}`](./by-example/monotonic.md) + -->
\ No newline at end of file diff --git a/book/en/src/by-example.md b/book/en/src/by-example.md index 419a4ba..a2e5b27 100644 --- a/book/en/src/by-example.md +++ b/book/en/src/by-example.md @@ -1,14 +1,15 @@ # RTIC by example -This part of the book introduces the Real-Time Interrupt-driven Concurrency (RTIC) framework -to new users by walking them through examples of increasing complexity. +This part of the book introduces the RTIC framework to new users by walking them through examples of increasing complexity. All examples in this part of the book are accessible at the [GitHub repository][repoexamples]. The examples are runnable on QEMU (emulating a Cortex M3 target), thus no special hardware required to follow along. -[repoexamples]: https://github.com/rtic-rs/cortex-m-rtic/tree/master/examples +[repoexamples]: https://github.com/rtic-rs/rtic/tree/master/examples + +## Running an example To run the examples with QEMU you will need the `qemu-system-arm` program. Check [the embedded Rust book] for instructions on how to set up an @@ -28,11 +29,12 @@ $ cargo run --target thumbv7m-none-eabi --example locals Yields this output: ``` console -{{#include ../../../ci/expected/locals.run}} +{{#include ../../../rtic/ci/expected/locals.run}} ``` > **NOTE**: You can choose target device by passing a target > triple to cargo (e.g. `cargo run --example init --target thumbv7m-none-eabi`) or > configure a default target in `.cargo/config.toml`. > -> For running the examples, we use a Cortex M3 emulated in QEMU, so the target is `thumbv7m-none-eabi`.
\ No newline at end of file +> For running the examples, we (typically) use a Cortex M3 emulated in QEMU, so the target is `thumbv7m-none-eabi`. +> Since the M3 architecture is backwards compatible to the M0/M0+ architecture, you may also use the `thumbv6m-none-eabi`, in case you want to inspect generated assembly code for the M0/M0+ architecture. diff --git a/book/en/src/by-example/app.md b/book/en/src/by-example/app.md index 2c6aca7..0d977a1 100644 --- a/book/en/src/by-example/app.md +++ b/book/en/src/by-example/app.md @@ -2,19 +2,25 @@ ## Requirements on the `app` attribute -All RTIC applications use the [`app`] attribute (`#[app(..)]`). This attribute -only applies to a `mod`-item containing the RTIC application. The `app` -attribute has a mandatory `device` argument that takes a *path* as a value. -This must be a full path pointing to a -*peripheral access crate* (PAC) generated using [`svd2rust`] **v0.14.x** or -newer. +All RTIC applications use the [`app`] attribute (`#[app(..)]`). This attribute only applies to a `mod`-item containing the RTIC application. The `app` attribute has a mandatory `device` argument that takes a *path* as a value. This must be a full path pointing to a *peripheral access crate* (PAC) generated using [`svd2rust`] **v0.14.x** or newer. -The `app` attribute will expand into a suitable entry point and thus replaces -the use of the [`cortex_m_rt::entry`] attribute. +The `app` attribute will expand into a suitable entry point and thus replaces the use of the [`cortex_m_rt::entry`] attribute. -[`app`]: ../../../api/cortex_m_rtic_macros/attr.app.html +[`app`]: ../../../api/rtic_macros/attr.app.html [`svd2rust`]: https://crates.io/crates/svd2rust -[`cortex_m_rt::entry`]: ../../../api/cortex_m_rt_macros/attr.entry.html +[`cortex_m_rt::entry`]: https://docs.rs/cortex-m-rt-macros/latest/cortex_m_rt_macros/attr.entry.html + +## Structure and zero-cost concurrency + +An RTIC `app` is an executable system model for single-core applications, declaring a set of `local` and `shared` resources operated on by a set of `init`, `idle`, *hardware* and *software* tasks. In short the `init` task runs before any other task returning the set of `local` and `shared` resources. Tasks run preemptively based on their associated static priority, `idle` has the lowest priority (and can be used for background work, and/or to put the system to sleep until woken by some event). Hardware tasks are bound to underlying hardware interrupts, while software tasks are scheduled by asynchronous executors (one for each software task priority). + +At compile time the task/resource model is analyzed under the Stack Resource Policy (SRP) and executable code generated with the following outstanding properties: + +- guaranteed race-free resource access and deadlock-free execution on a single-shared stack + - hardware task scheduling is performed directly by the hardware, and + - software task scheduling is performed by auto generated async executors tailored to the application. + +Overall, the generated code infers no additional overhead in comparison to a hand-written implementation, thus in Rust terms RTIC offers a zero-cost abstraction to concurrency. ## An RTIC application example @@ -22,5 +28,5 @@ To give a flavour of RTIC, the following example contains commonly used features In the following sections we will go through each feature in detail. ``` rust -{{#include ../../../../examples/common.rs}} +{{#include ../../../../rtic/examples/common.rs}} ``` diff --git a/book/en/src/by-example/app_idle.md b/book/en/src/by-example/app_idle.md index 537902a..cbfd7ba 100644 --- a/book/en/src/by-example/app_idle.md +++ b/book/en/src/by-example/app_idle.md @@ -1,52 +1,53 @@ # The background task `#[idle]` -A function marked with the `idle` attribute can optionally appear in the -module. This becomes the special *idle task* and must have signature -`fn(idle::Context) -> !`. +A function marked with the `idle` attribute can optionally appear in the module. This becomes the special *idle task* and must have signature `fn(idle::Context) -> !`. -When present, the runtime will execute the `idle` task after `init`. Unlike -`init`, `idle` will run *with interrupts enabled* and must never return, -as the `-> !` function signature indicates. +When present, the runtime will execute the `idle` task after `init`. Unlike `init`, `idle` will run *with interrupts enabled* and must never return, as the `-> !` function signature indicates. [The Rust type `!` means “never”][nevertype]. [nevertype]: https://doc.rust-lang.org/core/primitive.never.html -Like in `init`, locally declared resources will have `'static` lifetimes that -are safe to access. +Like in `init`, locally declared resources will have `'static` lifetimes that are safe to access. The example below shows that `idle` runs after `init`. ``` rust -{{#include ../../../../examples/idle.rs}} +{{#include ../../../../rtic/examples/idle.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example idle -{{#include ../../../../ci/expected/idle.run}} +``` + +``` console +{{#include ../../../../rtic/ci/expected/idle.run}} ``` By default, the RTIC `idle` task does not try to optimize for any specific targets. -A common useful optimization is to enable the [SLEEPONEXIT] and allow the MCU -to enter sleep when reaching `idle`. +A common useful optimization is to enable the [SLEEPONEXIT] and allow the MCU to enter sleep when reaching `idle`. ->**Caution** some hardware unless configured disables the debug unit during sleep mode. +>**Caution**: some hardware unless configured disables the debug unit during sleep mode. > >Consult your hardware specific documentation as this is outside the scope of RTIC. The following example shows how to enable sleep by setting the -[`SLEEPONEXIT`][SLEEPONEXIT] and providing a custom `idle` task replacing the -default [`nop()`][NOP] with [`wfi()`][WFI]. +[`SLEEPONEXIT`][SLEEPONEXIT] and providing a custom `idle` task replacing the default [`nop()`][NOP] with [`wfi()`][WFI]. [SLEEPONEXIT]: https://developer.arm.com/docs/100737/0100/power-management/sleep-mode/sleep-on-exit-bit [WFI]: https://developer.arm.com/documentation/dui0662/b/The-Cortex-M0--Instruction-Set/Miscellaneous-instructions/WFI [NOP]: https://developer.arm.com/documentation/dui0662/b/The-Cortex-M0--Instruction-Set/Miscellaneous-instructions/NOP ``` rust -{{#include ../../../../examples/idle-wfi.rs}} +{{#include ../../../../rtic/examples/idle-wfi.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example idle-wfi -{{#include ../../../../ci/expected/idle-wfi.run}} ``` + +``` console +{{#include ../../../../rtic/ci/expected/idle-wfi.run}} +``` + +> **Notice**: The `idle` task cannot be used together with *software* tasks running at priority zero. The reason is that `idle` is running as a non-returning Rust function at priority zero. Thus there would be no way for an executor at priority zero to give control to *software* tasks at the same priority. diff --git a/book/en/src/by-example/app_init.md b/book/en/src/by-example/app_init.md index 5bf6200..fb37387 100644 --- a/book/en/src/by-example/app_init.md +++ b/book/en/src/by-example/app_init.md @@ -1,35 +1,31 @@ # App initialization and the `#[init]` task An RTIC application requires an `init` task setting up the system. The corresponding `init` function must have the -signature `fn(init::Context) -> (Shared, Local, init::Monotonics)`, where `Shared` and `Local` are resource -structures defined by the user. +signature `fn(init::Context) -> (Shared, Local)`, where `Shared` and `Local` are resource structures defined by the user. -The `init` task executes after system reset, [after an optionally defined `pre-init` code section][pre-init] and an always occurring internal RTIC -initialization. +The `init` task executes after system reset, [after an optionally defined `pre-init` code section][pre-init] and an always occurring internal RTIC initialization. [pre-init]: https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.pre_init.html -[pre-init]: https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.pre_init.html - -The `init` and optional `pre-init` tasks runs *with interrupts disabled* and have exclusive access to Cortex-M (the -`bare_metal::CriticalSection` token is available as `cs`). +The `init` and optional `pre-init` tasks runs *with interrupts disabled* and have exclusive access to Cortex-M (the `bare_metal::CriticalSection` token is available as `cs`). Device specific peripherals are available through the `core` and `device` fields of `init::Context`. ## Example -The example below shows the types of the `core`, `device` and `cs` fields, and showcases the use of a `local` -variable with `'static` lifetime. -Such variables can be delegated from the `init` task to other tasks of the RTIC application. +The example below shows the types of the `core`, `device` and `cs` fields, and showcases the use of a `local` variable with `'static` lifetime. Such variables can be delegated from the `init` task to other tasks of the RTIC application. The `device` field is only available when the `peripherals` argument is set to the default value `true`. In the rare case you want to implement an ultra-slim application you can explicitly set `peripherals` to `false`. ``` rust -{{#include ../../../../examples/init.rs}} +{{#include ../../../../rtic/examples/init.rs}} ``` Running the example will print `init` to the console and then exit the QEMU process. ``` console $ cargo run --target thumbv7m-none-eabi --example init -{{#include ../../../../ci/expected/init.run}} +``` + +``` console +{{#include ../../../../rtic/ci/expected/init.run}} ``` diff --git a/book/en/src/by-example/app_minimal.md b/book/en/src/by-example/app_minimal.md index d0ff40a..714f543 100644 --- a/book/en/src/by-example/app_minimal.md +++ b/book/en/src/by-example/app_minimal.md @@ -3,5 +3,22 @@ This is the smallest possible RTIC application: ``` rust -{{#include ../../../../examples/smallest.rs}} +{{#include ../../../../rtic/examples/smallest.rs}} ``` + +RTIC is designed with resource efficiency in mind. RTIC itself does not rely on any dynamic memory allocation, thus RAM requirement is dependent only on the application. The flash memory footprint is below 1kB including the interrupt vector table. + +For a minimal example you can expect something like: +``` console +$ cargo size --example smallest --target thumbv7m-none-eabi --release +``` + +``` console +Finished release [optimized] target(s) in 0.07s + text data bss dec hex filename + 924 0 0 924 39c smallest +``` + +<!-- --- + +Technically, RTIC will generate a statically allocated future for each *software* task (holding the execution context, including the `Context` struct and stack allocated variables). Futures associated to the same static priority will share an asynchronous stack during execution. --> diff --git a/book/en/src/by-example/app_priorities.md b/book/en/src/by-example/app_priorities.md index 8cee749..9d27658 100644 --- a/book/en/src/by-example/app_priorities.md +++ b/book/en/src/by-example/app_priorities.md @@ -4,23 +4,18 @@ The `priority` argument declares the static priority of each `task`. -For Cortex-M, tasks can have priorities in the range `1..=(1 << NVIC_PRIO_BITS)` -where `NVIC_PRIO_BITS` is a constant defined in the `device` crate. +For Cortex-M, tasks can have priorities in the range `1..=(1 << NVIC_PRIO_BITS)` where `NVIC_PRIO_BITS` is a constant defined in the `device` crate. -Omitting the `priority` argument the task priority defaults to `1`. -The `idle` task has a non-configurable static priority of `0`, the lowest priority. +Omitting the `priority` argument the task priority defaults to `1`. The `idle` task has a non-configurable static priority of `0`, the lowest priority. > A higher number means a higher priority in RTIC, which is the opposite from what > Cortex-M does in the NVIC peripheral. > Explicitly, this means that number `10` has a **higher** priority than number `9`. -The highest static priority task takes precedence when more than one -task are ready to execute. +The highest static priority task takes precedence when more than one task are ready to execute. The following scenario demonstrates task prioritization: -Spawning a higher priority task A during execution of a lower priority task B suspends -task B. Task A has higher priority thus preempting task B which gets suspended -until task A completes execution. Thus, when task A completes task B resumes execution. +Spawning a higher priority task A during execution of a lower priority task B suspends task B. Task A has higher priority thus preempting task B which gets suspended until task A completes execution. Thus, when task A completes task B resumes execution. ```text Task Priority @@ -39,23 +34,19 @@ Task Priority The following example showcases the priority based scheduling of tasks: ``` rust -{{#include ../../../../examples/preempt.rs}} +{{#include ../../../../rtic/examples/preempt.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example preempt -{{#include ../../../../ci/expected/preempt.run}} +{{#include ../../../../rtic/ci/expected/preempt.run}} ``` -Note that the task `bar` does *not* preempt task `baz` because its priority -is the *same* as `baz`'s. The higher priority task `bar` runs before `foo` -when `baz`returns. When `bar` returns `foo` can resume. +Note that the task `bar` does *not* preempt task `baz` because its priority is the *same* as `baz`'s. The higher priority task `bar` runs before `foo` when `baz`returns. When `bar` returns `foo` can resume. -One more note about priorities: choosing a priority higher than what the device -supports will result in a compilation error. +One more note about priorities: choosing a priority higher than what the device supports will result in a compilation error. The error is cryptic due to limitations in the Rust language, if `priority = 9` for task `uart0_interrupt` in `example/common.rs` this looks like: -The error is cryptic due to limitations in the Rust language -if `priority = 9` for task `uart0_interrupt` in `example/common.rs` this looks like: +The error is cryptic due to limitations in the Rust language if `priority = 9` for task `uart0_interrupt` in `example/common.rs` this looks like: ```text error[E0080]: evaluation of constant value failed @@ -68,5 +59,4 @@ if `priority = 9` for task `uart0_interrupt` in `example/common.rs` this looks l ``` -The error message incorrectly points to the starting point of the macro, but at least the -value subtracted (in this case 9) will suggest which task causes the error. +The error message incorrectly points to the starting point of the macro, but at least the value subtracted (in this case 9) will suggest which task causes the error. diff --git a/book/en/src/by-example/app_task.md b/book/en/src/by-example/app_task.md index d83f1ff..b2731f6 100644 --- a/book/en/src/by-example/app_task.md +++ b/book/en/src/by-example/app_task.md @@ -1,3 +1,5 @@ +<!-- Should probably be removed --> + # Defining tasks with `#[task]` Tasks, defined with `#[task]`, are the main mechanism of getting work done in RTIC. diff --git a/book/en/src/by-example/channel.md b/book/en/src/by-example/channel.md new file mode 100644 index 0000000..c020870 --- /dev/null +++ b/book/en/src/by-example/channel.md @@ -0,0 +1,126 @@ +# Communication over channels. + +Channels can be used to communicate data between running *software* tasks. The channel is essentially a wait queue, allowing tasks with multiple producers and a single receiver. A channel is constructed in the `init` task and backed by statically allocated memory. Send and receive endpoints are distributed to *software* tasks: + +``` rust +... +const CAPACITY: usize = 5; +#[init] + fn init(_: init::Context) -> (Shared, Local) { + let (s, r) = make_channel!(u32, CAPACITY); + receiver::spawn(r).unwrap(); + sender1::spawn(s.clone()).unwrap(); + sender2::spawn(s.clone()).unwrap(); + ... +``` + +In this case the channel holds data of `u32` type with a capacity of 5 elements. + +## Sending data + +The `send` method post a message on the channel as shown below: + +``` rust +#[task] +async fn sender1(_c: sender1::Context, mut sender: Sender<'static, u32, CAPACITY>) { + hprintln!("Sender 1 sending: 1"); + sender.send(1).await.unwrap(); +} +``` + +## Receiving data + +The receiver can `await` incoming messages: + +``` rust +#[task] +async fn receiver(_c: receiver::Context, mut receiver: Receiver<'static, u32, CAPACITY>) { + while let Ok(val) = receiver.recv().await { + hprintln!("Receiver got: {}", val); + ... + } +} +``` + +Channels are implemented using a small (global) *Critical Section* (CS) for protection against race-conditions. The user must provide an CS implementation. Compiling the examples given the `--features test-critical-section` gives one possible implementation. + +For a complete example: + +``` rust +{{#include ../../../../rtic/examples/async-channel.rs}} +``` + +``` console +$ cargo run --target thumbv7m-none-eabi --example async-channel --features test-critical-section +``` + +``` console +{{#include ../../../../rtic/ci/expected/async-channel.run}} +``` + +Also sender endpoint can be awaited. In case the channel capacity has not yet been reached, `await`-ing the sender can progress immediately, while in the case the capacity is reached, the sender is blocked until there is free space in the queue. In this way data is never lost. + +In the following example the `CAPACITY` has been reduced to 1, forcing sender tasks to wait until the data in the channel has been received. + +``` rust +{{#include ../../../../rtic/examples/async-channel-done.rs}} +``` + +Looking at the output, we find that `Sender 2` will wait until the data sent by `Sender 1` as been received. + +> **NOTICE** *Software* tasks at the same priority are executed asynchronously to each other, thus **NO** strict order can be assumed. (The presented order here applies only to the current implementation, and may change between RTIC framework releases.) + +``` console +$ cargo run --target thumbv7m-none-eabi --example async-channel-done --features test-critical-section +{{#include ../../../../rtic/ci/expected/async-channel-done.run}} +``` + +## Error handling + +In case all senders have been dropped `await`-ing on an empty receiver channel results in an error. This allows to gracefully implement different types of shutdown operations. + +``` rust +{{#include ../../../../rtic/examples/async-channel-no-sender.rs}} +``` + +``` console +$ cargo run --target thumbv7m-none-eabi --example async-channel-no-sender --features test-critical-section +``` + +``` console +{{#include ../../../../rtic/ci/expected/async-channel-no-sender.run}} +``` + +Similarly, `await`-ing on a send channel results in an error in case the receiver has been dropped. This allows to gracefully implement application level error handling. + +The resulting error returns the data back to the sender, allowing the sender to take appropriate action (e.g., storing the data to later retry sending it). + +``` rust +{{#include ../../../../rtic/examples/async-channel-no-receiver.rs}} +``` + +``` console +$ cargo run --target thumbv7m-none-eabi --example async-channel-no-receiver --features test-critical-section +``` + +``` console +{{#include ../../../../rtic/ci/expected/async-channel-no-receiver.run}} +``` + + + +## Try API + +In cases you wish the sender to proceed even in case the channel is full. To that end, a `try_send` API is provided. + +``` rust +{{#include ../../../../rtic/examples/async-channel-try.rs}} +``` + +``` console +$ cargo run --target thumbv7m-none-eabi --example async-channel-try --features test-critical-section +``` + +``` console +{{#include ../../../../rtic/ci/expected/async-channel-try.run}} +```
\ No newline at end of file diff --git a/book/en/src/by-example/delay.md b/book/en/src/by-example/delay.md new file mode 100644 index 0000000..f286363 --- /dev/null +++ b/book/en/src/by-example/delay.md @@ -0,0 +1,127 @@ +# Tasks with delay + +A convenient way to express *miniminal* timing requirements is by means of delaying progression. + +This can be achieved by instantiating a monotonic timer: + +``` rust +... +rtic_monotonics::make_systick_handler!(); + +#[init] +fn init(cx: init::Context) -> (Shared, Local) { + hprintln!("init"); + + Systick::start(cx.core.SYST, 12_000_000); + ... +``` + +A *software* task can `await` the delay to expire: + +``` rust +#[task] +async fn foo(_cx: foo::Context) { + ... + Systick::delay(100.millis()).await; + ... +} + +``` + +Technically, the timer queue is implemented as a list based priority queue, where list-nodes are statically allocated as part of the underlying task `Future`. Thus, the timer queue is infallible at run-time (its size and allocation is determined at compile time). + +Similarly the channels implementation, the timer-queue implementation relies on a global *Critical Section* (CS) for race protection. For the examples a CS implementation is provided by adding `--features test-critical-section` to the build options. + +For a complete example: + +``` rust +{{#include ../../../../rtic/examples/async-delay.rs}} +``` + +``` console +$ cargo run --target thumbv7m-none-eabi --example async-delay --features test-critical-section +``` + +``` console +{{#include ../../../../rtic/ci/expected/async-delay.run}} +``` + +## Timeout + +Rust `Futures` (underlying Rust `async`/`await`) are composable. This makes it possible to `select` in between `Futures` that have completed. + +A common use case is transactions with associated timeout. In the examples shown below, we introduce a fake HAL device which performs some transaction. We have modelled the time it takes based on the input parameter (`n`) as `350ms + n * 100ms)`. + +Using the `select_biased` macro from the `futures` crate it may look like this: + +``` rust +// Call hal with short relative timeout using `select_biased` +select_biased! { + v = hal_get(1).fuse() => hprintln!("hal returned {}", v), + _ = Systick::delay(200.millis()).fuse() => hprintln!("timeout", ), // this will finish first +} +``` + +Assuming the `hal_get` will take 450ms to finish, a short timeout of 200ms will expire. + +``` rust +// Call hal with long relative timeout using `select_biased` +select_biased! { + v = hal_get(1).fuse() => hprintln!("hal returned {}", v), // hal finish first + _ = Systick::delay(1000.millis()).fuse() => hprintln!("timeout", ), +} +``` + +By extending the timeout to 1000ms, the `hal_get` will finish first. + +Using `select_biased` any number of futures can be combined, so its very powerful. However, as the timeout pattern is frequently used, it is directly supported by the RTIC [rtc-monotonics] and [rtic-time] crates. The second example from above using `timeout_after`: + +``` rust +// Call hal with long relative timeout using monotonic `timeout_after` +match Systick::timeout_after(1000.millis(), hal_get(1)).await { + Ok(v) => hprintln!("hal returned {}", v), + _ => hprintln!("timeout"), +} +``` + +In cases you want exact control over time without drift. For this purpose we can use exact points in time using `Instance`, and spans of time using `Duration`. Operations on the `Instance` and `Duration` types are given by the [fugit] crate. + +[fugit]: https://crates.io/crates/fugit + +``` rust +// get the current time instance +let mut instant = Systick::now(); + +// do this 3 times +for n in 0..3 { + // absolute point in time without drift + instant += 1000.millis(); + Systick::delay_until(instant).await; + + // absolute point it time for timeout + let timeout = instant + 500.millis(); + hprintln!("now is {:?}, timeout at {:?}", Systick::now(), timeout); + + match Systick::timeout_at(timeout, hal_get(n)).await { + Ok(v) => hprintln!("hal returned {} at time {:?}", v, Systick::now()), + _ => hprintln!("timeout"), + } +} +``` + +`instant = Systick::now()` gives the baseline (i.e., the absolute current point in time). We want to call `hal_get` after 1000ms relative to this absolute point in time. This can be accomplished by `Systick::delay_until(instant).await;`. We define the absolute point in time for the `timeout`, and call `Systick::timeout_at(timeout, hal_get(n)).await`. For the first loop iteration `n == 0`, and the `hal_get` will take 350ms (and finishes before the timeout). For the second iteration `n == 1`, and `hal_get` will take 450ms (and again succeeds to finish before the timeout). For the third iteration `n == 2` (`hal_get` will take 5500ms to finish). In this case we will run into a timeout. + + +The complete example: + +``` rust +{{#include ../../../../rtic/examples/async-timeout.rs}} +``` + +``` console +$ cargo run --target thumbv7m-none-eabi --example async-timeout --features test-critical-section +``` + +``` console +{{#include ../../../../rtic/ci/expected/async-timeout.run}} +``` diff --git a/book/en/src/by-example/hardware_tasks.md b/book/en/src/by-example/hardware_tasks.md index 2d405d3..75dd1a4 100644 --- a/book/en/src/by-example/hardware_tasks.md +++ b/book/en/src/by-example/hardware_tasks.md @@ -1,39 +1,32 @@ # Hardware tasks -At its core RTIC is using a hardware interrupt controller ([ARM NVIC on cortex-m][NVIC]) -to schedule and start execution of tasks. All tasks except `pre-init`, `#[init]` and `#[idle]` -run as interrupt handlers. +At its core RTIC is using a hardware interrupt controller ([ARM NVIC on cortex-m][NVIC]) to schedule and start execution of tasks. All tasks except `pre-init`, `#[init]` and `#[idle]` run as interrupt handlers. Hardware tasks are explicitly bound to interrupt handlers. -To bind a task to an interrupt, use the `#[task]` attribute argument `binds = InterruptName`. -This task then becomes the interrupt handler for this hardware interrupt vector. +To bind a task to an interrupt, use the `#[task]` attribute argument `binds = InterruptName`. This task then becomes the interrupt handler for this hardware interrupt vector. -All tasks bound to an explicit interrupt are called *hardware tasks* since they -start execution in reaction to a hardware event. +All tasks bound to an explicit interrupt are called *hardware tasks* since they start execution in reaction to a hardware event. -Specifying a non-existing interrupt name will cause a compilation error. The interrupt names -are commonly defined by [PAC or HAL][pacorhal] crates. +Specifying a non-existing interrupt name will cause a compilation error. The interrupt names are commonly defined by [PAC or HAL][pacorhal] crates. -Any available interrupt vector should work. Specific devices may bind -specific interrupt priorities to specific interrupt vectors outside -user code control. See for example the -[nRF “softdevice”](https://github.com/rtic-rs/cortex-m-rtic/issues/434). +Any available interrupt vector should work. Specific devices may bind specific interrupt priorities to specific interrupt vectors outside user code control. See for example the [nRF “softdevice”](https://github.com/rtic-rs/rtic/issues/434). -Beware of using interrupt vectors that are used internally by hardware features; -RTIC is unaware of such hardware specific details. +Beware of using interrupt vectors that are used internally by hardware features; RTIC is unaware of such hardware specific details. [pacorhal]: https://docs.rust-embedded.org/book/start/registers.html [NVIC]: https://developer.arm.com/documentation/100166/0001/Nested-Vectored-Interrupt-Controller/NVIC-functional-description/NVIC-interrupts -The example below demonstrates the use of the `#[task(binds = InterruptName)]` attribute to declare a -hardware task bound to an interrupt handler. +The example below demonstrates the use of the `#[task(binds = InterruptName)]` attribute to declare a hardware task bound to an interrupt handler. ``` rust -{{#include ../../../../examples/hardware.rs}} +{{#include ../../../../rtic/examples/hardware.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example hardware -{{#include ../../../../ci/expected/hardware.run}} +``` + +``` console +{{#include ../../../../rtic/ci/expected/hardware.run}} ``` diff --git a/book/en/src/by-example/resources.md b/book/en/src/by-example/resources.md index 30089d3..0bf5d11 100644 --- a/book/en/src/by-example/resources.md +++ b/book/en/src/by-example/resources.md @@ -1,176 +1,155 @@ # Resource usage -The RTIC framework manages shared and task local resources allowing persistent data -storage and safe accesses without the use of `unsafe` code. +The RTIC framework manages shared and task local resources allowing persistent data storage and safe accesses without the use of `unsafe` code. -RTIC resources are visible only to functions declared within the `#[app]` module and the framework -gives the user complete control (on a per-task basis) over resource accessibility. +RTIC resources are visible only to functions declared within the `#[app]` module and the framework gives the user complete control (on a per-task basis) over resource accessibility. -Declaration of system-wide resources is done by annotating **two** `struct`s within the `#[app]` module -with the attribute `#[local]` and `#[shared]`. -Each field in these structures corresponds to a different resource (identified by field name). -The difference between these two sets of resources will be covered below. +Declaration of system-wide resources is done by annotating **two** `struct`s within the `#[app]` module with the attribute `#[local]` and `#[shared]`. Each field in these structures corresponds to a different resource (identified by field name). The difference between these two sets of resources will be covered below. -Each task must declare the resources it intends to access in its corresponding metadata attribute -using the `local` and `shared` arguments. Each argument takes a list of resource identifiers. -The listed resources are made available to the context under the `local` and `shared` fields of the -`Context` structure. +Each task must declare the resources it intends to access in its corresponding metadata attribute using the `local` and `shared` arguments. Each argument takes a list of resource identifiers. The listed resources are made available to the context under the `local` and `shared` fields of the `Context` structure. -The `init` task returns the initial values for the system-wide (`#[shared]` and `#[local]`) -resources, and the set of initialized timers used by the application. The monotonic timers will be -further discussed in [Monotonic & `spawn_{at/after}`](./monotonic.md). +The `init` task returns the initial values for the system-wide (`#[shared]` and `#[local]`) resources. + +<!-- and the set of initialized timers used by the application. The monotonic timers will be +further discussed in [Monotonic & `spawn_{at/after}`](./monotonic.md). --> ## `#[local]` resources -`#[local]` resources are locally accessible to a specific task, meaning that only that task can -access the resource and does so without locks or critical sections. This allows for the resources, -commonly drivers or large objects, to be initialized in `#[init]` and then be passed to a specific -task. +`#[local]` resources are locally accessible to a specific task, meaning that only that task can access the resource and does so without locks or critical sections. This allows for the resources, commonly drivers or large objects, to be initialized in `#[init]` and then be passed to a specific task. -Thus, a task `#[local]` resource can only be accessed by one singular task. -Attempting to assign the same `#[local]` resource to more than one task is a compile-time error. +Thus, a task `#[local]` resource can only be accessed by one singular task. Attempting to assign the same `#[local]` resource to more than one task is a compile-time error. -Types of `#[local]` resources must implement a [`Send`] trait as they are being sent from `init` -to a target task, crossing a thread boundary. +Types of `#[local]` resources must implement a [`Send`] trait as they are being sent from `init` to a target task, crossing a thread boundary. [`Send`]: https://doc.rust-lang.org/stable/core/marker/trait.Send.html -The example application shown below contains two tasks where each task has access to its own -`#[local]` resource; the `idle` task has its own `#[local]` as well. +The example application shown below contains three tasks `foo`, `bar` and `idle`, each having access to its own `#[local]` resource. ``` rust -{{#include ../../../../examples/locals.rs}} +{{#include ../../../../rtic/examples/locals.rs}} ``` Running the example: ``` console $ cargo run --target thumbv7m-none-eabi --example locals -{{#include ../../../../ci/expected/locals.run}} ``` -Local resources in `#[init]` and `#[idle]` have `'static` -lifetimes. This is safe since both tasks are not re-entrant. +``` console +{{#include ../../../../rtic/ci/expected/locals.run}} +``` + +Local resources in `#[init]` and `#[idle]` have `'static` lifetimes. This is safe since both tasks are not re-entrant. ### Task local initialized resources -Local resources can also be specified directly in the resource claim like so: -`#[task(local = [my_var: TYPE = INITIAL_VALUE, ...])]`; this allows for creating locals which do no need to be -initialized in `#[init]`. +Local resources can also be specified directly in the resource claim like so: `#[task(local = [my_var: TYPE = INITIAL_VALUE, ...])]`; this allows for creating locals which do no need to be initialized in `#[init]`. -Types of `#[task(local = [..])]` resources have to be neither [`Send`] nor [`Sync`] as they -are not crossing any thread boundary. +Types of `#[task(local = [..])]` resources have to be neither [`Send`] nor [`Sync`] as they are not crossing any thread boundary. [`Sync`]: https://doc.rust-lang.org/stable/core/marker/trait.Sync.html In the example below the different uses and lifetimes are shown: ``` rust -{{#include ../../../../examples/declared_locals.rs}} +{{#include ../../../../rtic/examples/declared_locals.rs}} ``` -<!-- ``` console -$ cargo run --target thumbv7m-none-eabi --example declared_locals -{{#include ../../../../ci/expected/declared_locals.run}} -``` --> +You can run the application, but as the example is designed merely to showcase the lifetime properties there is no output (it suffices to build the application). + +``` console +$ cargo build --target thumbv7m-none-eabi --example declared_locals +``` +<!-- {{#include ../../../../rtic/ci/expected/declared_locals.run}} --> ## `#[shared]` resources and `lock` -Critical sections are required to access `#[shared]` resources in a data race-free manner and to -achieve this the `shared` field of the passed `Context` implements the [`Mutex`] trait for each -shared resource accessible to the task. This trait has only one method, [`lock`], which runs its -closure argument in a critical section. +Critical sections are required to access `#[shared]` resources in a data race-free manner and to achieve this the `shared` field of the passed `Context` implements the [`Mutex`] trait for each shared resource accessible to the task. This trait has only one method, [`lock`], which runs its closure argument in a critical section. [`Mutex`]: ../../../api/rtic/trait.Mutex.html [`lock`]: ../../../api/rtic/trait.Mutex.html#method.lock -The critical section created by the `lock` API is based on dynamic priorities: it temporarily -raises the dynamic priority of the context to a *ceiling* priority that prevents other tasks from -preempting the critical section. This synchronization protocol is known as the -[Immediate Ceiling Priority Protocol (ICPP)][icpp], and complies with -[Stack Resource Policy (SRP)][srp] based scheduling of RTIC. +The critical section created by the `lock` API is based on dynamic priorities: it temporarily raises the dynamic priority of the context to a *ceiling* priority that prevents other tasks from preempting the critical section. This synchronization protocol is known as the [Immediate Ceiling Priority Protocol (ICPP)][icpp], and complies with [Stack Resource Policy (SRP)][srp] based scheduling of RTIC. [icpp]: https://en.wikipedia.org/wiki/Priority_ceiling_protocol [srp]: https://en.wikipedia.org/wiki/Stack_Resource_Policy -In the example below we have three interrupt handlers with priorities ranging from one to three. -The two handlers with the lower priorities contend for a `shared` resource and need to succeed in locking the -resource in order to access its data. The highest priority handler, which does not access the `shared` -resource, is free to preempt a critical section created by the lowest priority handler. +In the example below we have three interrupt handlers with priorities ranging from one to three. The two handlers with the lower priorities contend for a `shared` resource and need to succeed in locking the resource in order to access its data. The highest priority handler, which does not access the `shared` resource, is free to preempt a critical section created by the lowest priority handler. ``` rust -{{#include ../../../../examples/lock.rs}} +{{#include ../../../../rtic/examples/lock.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example lock -{{#include ../../../../ci/expected/lock.run}} +``` + +``` console +{{#include ../../../../rtic/ci/expected/lock.run}} ``` Types of `#[shared]` resources have to be [`Send`]. ## Multi-lock -As an extension to `lock`, and to reduce rightward drift, locks can be taken as tuples. The -following examples show this in use: +As an extension to `lock`, and to reduce rightward drift, locks can be taken as tuples. The following examples show this in use: ``` rust -{{#include ../../../../examples/multilock.rs}} +{{#include ../../../../rtic/examples/multilock.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example multilock -{{#include ../../../../ci/expected/multilock.run}} +``` + +``` console +{{#include ../../../../rtic/ci/expected/multilock.run}} ``` ## Only shared (`&-`) access -By default, the framework assumes that all tasks require exclusive access (`&mut-`) to resources, -but it is possible to specify that a task only requires shared access (`&-`) to a resource using the -`&resource_name` syntax in the `shared` list. +By default, the framework assumes that all tasks require exclusive mutable access (`&mut-`) to resources, but it is possible to specify that a task only requires shared access (`&-`) to a resource using the `&resource_name` syntax in the `shared` list. -The advantage of specifying shared access (`&-`) to a resource is that no locks are required to -access the resource even if the resource is contended by more than one task running at different -priorities. The downside is that the task only gets a shared reference (`&-`) to the resource, -limiting the operations it can perform on it, but where a shared reference is enough this approach -reduces the number of required locks. In addition to simple immutable data, this shared access can -be useful where the resource type safely implements interior mutability, with appropriate locking -or atomic operations of its own. +The advantage of specifying shared access (`&-`) to a resource is that no locks are required to access the resource even if the resource is contended by more than one task running at different priorities. The downside is that the task only gets a shared reference (`&-`) to the resource, limiting the operations it can perform on it, but where a shared reference is enough this approach reduces the number of required locks. In addition to simple immutable data, this shared access can be useful where the resource type safely implements interior mutability, with appropriate locking or atomic operations of its own. -Note that in this release of RTIC it is not possible to request both exclusive access (`&mut-`) -and shared access (`&-`) to the *same* resource from different tasks. Attempting to do so will -result in a compile error. +Note that in this release of RTIC it is not possible to request both exclusive access (`&mut-`) and shared access (`&-`) to the *same* resource from different tasks. Attempting to do so will result in a compile error. -In the example below a key (e.g. a cryptographic key) is loaded (or created) at runtime and then -used from two tasks that run at different priorities without any kind of lock. +In the example below a key (e.g. a cryptographic key) is loaded (or created) at runtime (returned by `init`) and then used from two tasks that run at different priorities without any kind of lock. ``` rust -{{#include ../../../../examples/only-shared-access.rs}} +{{#include ../../../../rtic/examples/only-shared-access.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example only-shared-access -{{#include ../../../../ci/expected/only-shared-access.run}} ``` -## Lock-free resource access of shared resources +``` console +{{#include ../../../../rtic/ci/expected/only-shared-access.run}} +``` + +## Lock-free access of shared resources + +A critical section is *not* required to access a `#[shared]` resource that's only accessed by tasks running at the *same* priority. In this case, you can opt out of the `lock` API by adding the `#[lock_free]` field-level attribute to the resource declaration (see example below). -A critical section is *not* required to access a `#[shared]` resource that's only accessed by tasks -running at the *same* priority. In this case, you can opt out of the `lock` API by adding the -`#[lock_free]` field-level attribute to the resource declaration (see example below). Note that -this is merely a convenience to reduce needless resource locking code, because even if the +<!-- Note that this is merely a convenience to reduce needless resource locking code, because even if the `lock` API is used, at runtime the framework will **not** produce a critical section due to how -the underlying resource-ceiling preemption works. +the underlying resource-ceiling preemption works. --> -Also worth noting: using `#[lock_free]` on resources shared by -tasks running at different priorities will result in a *compile-time* error -- not using the `lock` -API would be a data race in that case. +To adhere to the Rust [aliasing] rule, a resource may be either accessed through multiple immutable references or a singe mutable reference (but not both at the same time). + +[aliasing]: https://doc.rust-lang.org/nomicon/aliasing.html + +Using `#[lock_free]` on resources shared by tasks running at different priorities will result in a *compile-time* error -- not using the `lock` API would violate the aforementioned alias rule. Similarly, for each priority there can be only a single *software* task accessing a shared resource (as an `async` task may yield execution to other *software* or *hardware* tasks running at the same priority). However, under this single-task restriction, we make the observation that the resource is in effect no longer `shared` but rather `local`. Thus, using a `#[lock_free]` shared resource will result in a *compile-time* error -- where applicable, use a `#[local]` resource instead. ``` rust -{{#include ../../../../examples/lock-free.rs}} +{{#include ../../../../rtic/examples/lock-free.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example lock-free -{{#include ../../../../ci/expected/lock-free.run}} +``` + +``` console +{{#include ../../../../rtic/ci/expected/lock-free.run}} ``` diff --git a/book/en/src/by-example/software_tasks.md b/book/en/src/by-example/software_tasks.md index 8ee185b..0efc57b 100644 --- a/book/en/src/by-example/software_tasks.md +++ b/book/en/src/by-example/software_tasks.md @@ -1,47 +1,111 @@ # Software tasks & spawn -The RTIC concept of a software task shares a lot with that of [hardware tasks](./hardware_tasks.md) -with the core difference that a software task is not explicitly bound to a specific -interrupt vector, but rather bound to a “dispatcher” interrupt vector running -at the intended priority of the software task (see below). +The RTIC concept of a software task shares a lot with that of [hardware tasks](./hardware_tasks.md) with the core difference that a software task is not explicitly bound to a specific +interrupt vector, but rather bound to a “dispatcher” interrupt vector running at the intended priority of the software task (see below). -Thus, software tasks are tasks which are not *directly* bound to an interrupt vector. +Similarly to *hardware* tasks, the `#[task]` attribute used on a function declare it as a task. The absence of a `binds = InterruptName` argument to the attribute declares the function as a *software task*. -The `#[task]` attributes used on a function determine if it is -software tasks, specifically the absence of a `binds = InterruptName` -argument to the attribute definition. +The static method `task_name::spawn()` spawns (starts) a software task and given that there are no higher priority tasks running the task will start executing directly. -The static method `task_name::spawn()` spawns (schedules) a software -task by registering it with a specific dispatcher. If there are no -higher priority tasks available to the scheduler (which serves a set -of dispatchers), the task will start executing directly. +The *software* task itself is given as an `async` Rust function, which allows the user to optionally `await` future events. This allows to blend reactive programming (by means of *hardware* tasks) with sequential programming (by means of *software* tasks). -All software tasks at the same priority level share an interrupt handler bound to their dispatcher. -What differentiates software and hardware tasks is the usage of either a dispatcher or a bound interrupt vector. +Whereas, *hardware* tasks are assumed to run-to-completion (and return), *software* tasks may be started (`spawned`) once and run forever, with the side condition that any loop (execution path) is broken by at least one `await` (yielding operation). -The interrupt vectors used as dispatchers cannot be used by hardware tasks. +All *software* tasks at the same priority level shares an interrupt handler acting as an async executor dispatching the software tasks. -Availability of a set of “free” (not in use by hardware tasks) and usable interrupt vectors allows the framework -to dispatch software tasks via dedicated interrupt handlers. +This list of dispatchers, `dispatchers = [FreeInterrupt1, FreeInterrupt2, ...]` is an argument to the `#[app]` attribute, where you define the set of free and usable interrupts. -This set of dispatchers, `dispatchers = [FreeInterrupt1, FreeInterrupt2, ...]` is an -argument to the `#[app]` attribute. +Each interrupt vector acting as dispatcher gets assigned to one priority level meaning that the list of dispatchers need to cover all priority levels used by software tasks. -Each interrupt vector acting as dispatcher gets assigned to a unique priority level meaning that -the list of dispatchers needs to cover all priority levels used by software tasks. +Example: The `dispatchers =` argument needs to have at least 3 entries for an application using three different priorities for software tasks. -Example: The `dispatchers =` argument needs to have at least 3 entries for an application using -three different priorities for software tasks. - -The framework will give a compilation error if there are not enough dispatchers provided. +The framework will give a compilation error if there are not enough dispatchers provided, or if a clash occurs between the list of dispatchers and interrupts bound to *hardware* tasks. See the following example: ``` rust -{{#include ../../../../examples/spawn.rs}} +{{#include ../../../../rtic/examples/spawn.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example spawn -{{#include ../../../../ci/expected/spawn.run}} ``` + +``` console +{{#include ../../../../rtic/ci/expected/spawn.run}} +``` +You may `spawn` a *software* task again, given that it has run-to-completion (returned). + +In the below example, we `spawn` the *software* task `foo` from the `idle` task. Since the default priority of the *software* task is 1 (higher than `idle`), the dispatcher will execute `foo` (preempting `idle`). Since `foo` runs-to-completion. It is ok to `spawn` the `foo` task again. + +Technically the async executor will `poll` the `foo` *future* which in this case leaves the *future* in a *completed* state. + +``` rust +{{#include ../../../../rtic/examples/spawn_loop.rs}} +``` + +``` console +$ cargo run --target thumbv7m-none-eabi --example spawn_loop +``` + +``` console +{{#include ../../../../rtic/ci/expected/spawn_loop.run}} +``` + +An attempt to `spawn` an already spawned task (running) task will result in an error. Notice, the that the error is reported before the `foo` task is actually run. This is since, the actual execution of the *software* task is handled by the dispatcher interrupt (`SSIO`), which is not enabled until we exit the `init` task. (Remember, `init` runs in a critical section, i.e. all interrupts being disabled.) + +Technically, a `spawn` to a *future* that is not in *completed* state is considered an error. + +``` rust +{{#include ../../../../rtic/examples/spawn_err.rs}} +``` + +``` console +$ cargo run --target thumbv7m-none-eabi --example spawn_err +``` + +``` console +{{#include ../../../../rtic/ci/expected/spawn_err.run}} +``` + +## Passing arguments +You can also pass arguments at spawn as follows. + +``` rust +{{#include ../../../../rtic/examples/spawn_arguments.rs}} +``` + +``` console +$ cargo run --target thumbv7m-none-eabi --example spawn_arguments +``` + +``` console +{{#include ../../../../rtic/ci/expected/spawn_arguments.run}} +``` + +## Priority zero tasks + +In RTIC tasks run preemptively to each other, with priority zero (0) the lowest priority. You can use priority zero tasks for background work, without any strict real-time requirements. + +Conceptually, one can see such tasks as running in the `main` thread of the application, thus the resources associated are not required the [Send] bound. + +[Send]: https://doc.rust-lang.org/nomicon/send-and-sync.html + + +``` rust +{{#include ../../../../rtic/examples/zero-prio-task.rs}} +``` + +``` console +$ cargo run --target thumbv7m-none-eabi --example zero-prio-task +``` + +``` console +{{#include ../../../../rtic/ci/expected/zero-prio-task.run}} +``` + +> **Notice**: *software* task at zero priority cannot co-exist with the [idle] task. The reason is that `idle` is running as a non-returning Rust function at priority zero. Thus there would be no way for an executor at priority zero to give control to *software* tasks at the same priority. + +--- + +Application side safety: Technically, the RTIC framework ensures that `poll` is never executed on any *software* task with *completed* future, thus adhering to the soundness rules of async Rust. diff --git a/book/en/src/by-example/starting_a_project.md b/book/en/src/by-example/starting_a_project.md index fe7be57..86d7e71 100644 --- a/book/en/src/by-example/starting_a_project.md +++ b/book/en/src/by-example/starting_a_project.md @@ -3,13 +3,15 @@ A recommendation when starting a RTIC project from scratch is to follow RTIC's [`defmt-app-template`]. -If you are targeting ARMv6-M or ARMv8-M-base architecture, check out the section [Target Architecture](../internals/targets.md) for more information on hardware limitations to be aware of. +If you are targeting ARMv6-M or ARMv8-M-base architecture, check out the section [Target Architecture](../internals/targets.md) for more information on hardware limitations to be aware of. [`defmt-app-template`]: https://github.com/rtic-rs/defmt-app-template This will give you an RTIC application with support for RTT logging with [`defmt`] and stack overflow protection using [`flip-link`]. There is also a multitude of examples provided by the community: +For inspiration, you may look at the below resources. For now, they cover RTIC v1.x, but will be updated with RTIC v2.x examples over time. + - [`rtic-examples`] - Multiple projects - [https://github.com/kalkyl/f411-rtic](https://github.com/kalkyl/f411-rtic) - ... More to come diff --git a/book/en/src/by-example/tips_destructureing.md b/book/en/src/by-example/tips_destructureing.md index 4637b48..ab27987 100644 --- a/book/en/src/by-example/tips_destructureing.md +++ b/book/en/src/by-example/tips_destructureing.md @@ -1,14 +1,15 @@ # Resource de-structure-ing Destructuring task resources might help readability if a task takes multiple -resources. -Here are two examples on how to split up the resource struct: +resources. Here are two examples on how to split up the resource struct: ``` rust -{{#include ../../../../examples/destructure.rs}} +{{#include ../../../../rtic/examples/destructure.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example destructure -{{#include ../../../../ci/expected/destructure.run}} +``` +``` console +{{#include ../../../../rtic/ci/expected/destructure.run}} ``` diff --git a/book/en/src/by-example/tips_from_ram.md b/book/en/src/by-example/tips_from_ram.md index fc47803..f6b2173 100644 --- a/book/en/src/by-example/tips_from_ram.md +++ b/book/en/src/by-example/tips_from_ram.md @@ -1,33 +1,28 @@ # Running tasks from RAM -The main goal of moving the specification of RTIC applications to attributes in -RTIC v0.4.0 was to allow inter-operation with other attributes. For example, the -`link_section` attribute can be applied to tasks to place them in RAM; this can +The main goal of moving the specification of RTIC applications to attributes in RTIC v0.4.0 was to allow inter-operation with other attributes. For example, the `link_section` attribute can be applied to tasks to place them in RAM; this can improve performance in some cases. -> **IMPORTANT**: In general, the `link_section`, `export_name` and `no_mangle` -> attributes are powerful but also easy to misuse. Incorrectly using any of -> these attributes can cause undefined behavior; you should always prefer to use -> safe, higher level attributes around them like `cortex-m-rt`'s `interrupt` and -> `exception` attributes. +> **IMPORTANT**: In general, the `link_section`, `export_name` and `no_mangle` attributes are powerful but also easy to misuse. Incorrectly using any of these attributes can cause undefined behavior; you should always prefer to use safe, higher level attributes around them like `cortex-m-rt`'s `interrupt` and `exception` attributes. > -> In the particular case of RAM functions there's no -> safe abstraction for it in `cortex-m-rt` v0.6.5 but there's an [RFC] for -> adding a `ramfunc` attribute in a future release. +> In the particular case of RAM functions there's no safe abstraction for it in `cortex-m-rt` v0.6.5 but there's an [RFC] for adding a `ramfunc` attribute in a future release. [RFC]: https://github.com/rust-embedded/cortex-m-rt/pull/100 The example below shows how to place the higher priority task, `bar`, in RAM. ``` rust -{{#include ../../../../examples/ramfunc.rs}} +{{#include ../../../../rtic/examples/ramfunc.rs}} ``` Running this program produces the expected output. ``` console $ cargo run --target thumbv7m-none-eabi --example ramfunc -{{#include ../../../../ci/expected/ramfunc.run}} +``` + +``` console +{{#include ../../../../rtic/ci/expected/ramfunc.run}} ``` One can look at the output of `cargo-nm` to confirm that `bar` ended in RAM @@ -35,10 +30,16 @@ One can look at the output of `cargo-nm` to confirm that `bar` ended in RAM ``` console $ cargo nm --example ramfunc --release | grep ' foo::' -{{#include ../../../../ci/expected/ramfunc.run.grep.foo}} ``` ``` console -$ cargo nm --example ramfunc --release | grep ' bar::' -{{#include ../../../../ci/expected/ramfunc.run.grep.bar}} +{{#include ../../../../rtic/ci/expected/ramfunc.run.grep.foo}} +``` + +``` console +$ cargo nm --example ramfunc --target thumbv7m-none-eabi --release | grep '*bar::' +``` + +``` console +{{#include ../../../../rtic/ci/expected/ramfunc.run.grep.bar}} ``` diff --git a/book/en/src/by-example/tips_indirection.md b/book/en/src/by-example/tips_indirection.md index 567a5e7..0de14a6 100644 --- a/book/en/src/by-example/tips_indirection.md +++ b/book/en/src/by-example/tips_indirection.md @@ -1,31 +1,26 @@ # Using indirection for faster message passing -Message passing always involves copying the payload from the sender into a -static variable and then from the static variable into the receiver. Thus -sending a large buffer, like a `[u8; 128]`, as a message involves two expensive +Message passing always involves copying the payload from the sender into a static variable and then from the static variable into the receiver. Thus sending a large buffer, like a `[u8; 128]`, as a message involves two expensive `memcpy`s. -Indirection can minimize message passing overhead: -instead of sending the buffer by value, one can send an owning pointer into the -buffer. +Indirection can minimize message passing overhead: instead of sending the buffer by value, one can send an owning pointer into the buffer. -One can use a global memory allocator to achieve indirection (`alloc::Box`, -`alloc::Rc`, etc.), which requires using the nightly channel as of Rust v1.37.0, -or one can use a statically allocated memory pool like [`heapless::Pool`]. +One can use a global memory allocator to achieve indirection (`alloc::Box`, `alloc::Rc`, etc.), which requires using the nightly channel as of Rust v1.37.0, or one can use a statically allocated memory pool like [`heapless::Pool`]. [`heapless::Pool`]: https://docs.rs/heapless/0.5.0/heapless/pool/index.html -As this example of approach goes completely outside of RTIC resource -model with shared and local the program would rely on the correctness -of the memory allocator, in this case `heapless::pool`. +As this example of approach goes completely outside of RTIC resource model with shared and local the program would rely on the correctness of the memory allocator, in this case `heapless::pool`. Here's an example where `heapless::Pool` is used to "box" buffers of 128 bytes. ``` rust -{{#include ../../../../examples/pool.rs}} +{{#include ../../../../rtic/examples/pool.rs}} ``` ``` console $ cargo run --target thumbv7m-none-eabi --example pool -{{#include ../../../../ci/expected/pool.run}} +``` + +``` console +{{#include ../../../../rtic/ci/expected/pool.run}} ``` diff --git a/book/en/src/by-example/tips_monotonic_impl.md b/book/en/src/by-example/tips_monotonic_impl.md index 7c3449b..57b0a01 100644 --- a/book/en/src/by-example/tips_monotonic_impl.md +++ b/book/en/src/by-example/tips_monotonic_impl.md @@ -1,35 +1,29 @@ # Implementing a `Monotonic` timer for scheduling -The framework is flexible because it can use any timer which has compare-match and optionally -supporting overflow interrupts for scheduling. -The single requirement to make a timer usable with RTIC is implementing the -[`rtic_monotonic::Monotonic`] trait. - -Implementing time counting that supports large time spans is generally **difficult**, in RTIC 0.5 -implementing time handling was a common problem. -Moreover, the relation between time and timers used for scheduling was difficult to understand. - -For RTIC 1.0 we instead assume the user has a time library, e.g. [`fugit`] or [`embedded_time`], -as the basis for all time-based operations when implementing `Monotonic`. -These libraries make it much easier to correctly implement the `Monotonic` trait, allowing the use of +The framework is flexible because it can use any timer which has compare-match and optionally supporting overflow interrupts for scheduling. The single requirement to make a timer usable with RTIC is implementing the [`rtic-time::Monotonic`] trait. + +For RTIC 1.0 and 2.0 we instead assume the user has a time library, e.g. [`fugit`] or [`embedded_time`], as the basis for all time-based operations when implementing `Monotonic`. These libraries make it much easier to correctly implement the `Monotonic` trait, allowing the use of almost any timer in the system for scheduling. -The trait documents the requirements for each method, -and for inspiration here is a list of `Monotonic` implementations: +The trait documents the requirements for each method, and for inspiration +there is a reference implementation based on the `SysTick` timer available on all ARM Cortex M MCUs. + +- [`Systick based`], runs at a fixed interrupt (tick) rate - with some overhead but simple and provides support for large time spans + +Here is a list of `Monotonic` implementations for RTIC 1.0: - [`STM32F411 series`], implemented for the 32-bit timers - [`Nordic nRF52 series Timer`], implemented for the 32-bit timers - [`Nordic nRF52 series RTC`], implemented for the RTCs -- [`Systick based`], runs at a fixed interrupt (tick) rate - with some overhead but simple and with support for large time spans - [`DWT and Systick based`], a more efficient (tickless) implementation - requires both `SysTick` and `DWT`, supports both high resolution and large time spans If you know of more implementations feel free to add them to this list. -[`rtic_monotonic::Monotonic`]: https://docs.rs/rtic-monotonic/ +[`rtic_time::Monotonic`]: https://docs.rs/rtic_time/ [`fugit`]: https://docs.rs/fugit/ [`embedded_time`]: https://docs.rs/embedded_time/ [`STM32F411 series`]: https://github.com/kalkyl/f411-rtic/blob/a696fce7d6d19fda2356c37642c4d53547982cca/src/mono.rs [`Nordic nRF52 series Timer`]: https://github.com/kalkyl/nrf-play/blob/47f4410d4e39374c18ff58dc17c25159085fb526/src/mono.rs [`Nordic nRF52 series RTC`]: https://gist.github.com/korken89/fe94a475726414dd1bce031c76adc3dd -[`Systick based`]: https://github.com/rtic-rs/systick-monotonic +[`Systick based`]: https://github.com/rtic-monotonics [`DWT and Systick based`]: https://github.com/rtic-rs/dwt-systick-monotonic diff --git a/book/en/src/by-example/tips_static_lifetimes.md b/book/en/src/by-example/tips_static_lifetimes.md index dadd9c9..0eaa59f 100644 --- a/book/en/src/by-example/tips_static_lifetimes.md +++ b/book/en/src/by-example/tips_static_lifetimes.md @@ -2,23 +2,22 @@ In `#[init]` and `#[idle]` `local` resources have `'static` lifetime. -Useful when pre-allocating and/or splitting resources between tasks, drivers -or some other object. -This comes in handy when drivers, such as USB drivers, need to allocate memory and -when using splittable data structures such as [`heapless::spsc::Queue`]. +Useful when pre-allocating and/or splitting resources between tasks, drivers or some other object. This comes in handy when drivers, such as USB drivers, need to allocate memory and when using splittable data structures such as [`heapless::spsc::Queue`]. -In the following example two different tasks share a [`heapless::spsc::Queue`] -for lock-free access to the shared queue. +In the following example two different tasks share a [`heapless::spsc::Queue`] for lock-free access to the shared queue. [`heapless::spsc::Queue`]: https://docs.rs/heapless/0.7.5/heapless/spsc/struct.Queue.html ``` rust -{{#include ../../../../examples/static.rs}} +{{#include ../../../../rtic/examples/static.rs}} ``` Running this program produces the expected output. ``` console $ cargo run --target thumbv7m-none-eabi --example static -{{#include ../../../../ci/expected/static.run}} +``` + +``` console +{{#include ../../../../rtic/ci/expected/static.run}} ``` diff --git a/book/en/src/by-example/tips_view_code.md b/book/en/src/by-example/tips_view_code.md index 736b7ac..b4a9066 100644 --- a/book/en/src/by-example/tips_view_code.md +++ b/book/en/src/by-example/tips_view_code.md @@ -1,21 +1,19 @@ # Inspecting generated code -`#[rtic::app]` is a procedural macro that produces support code. If for some -reason you need to inspect the code generated by this macro you have two -options: +`#[rtic::app]` is a procedural macro that produces support code. If for some reason you need to inspect the code generated by this macro you have two options: -You can inspect the file `rtic-expansion.rs` inside the `target` directory. This -file contains the expansion of the `#[rtic::app]` item (not your whole program!) -of the *last built* (via `cargo build` or `cargo check`) RTIC application. The -expanded code is not pretty printed by default, so you'll want to run `rustfmt` -on it before you read it. +You can inspect the file `rtic-expansion.rs` inside the `target` directory. This file contains the expansion of the `#[rtic::app]` item (not your whole program!) of the *last built* (via `cargo build` or `cargo check`) RTIC application. The expanded code is not pretty printed by default, so you'll want to run `rustfmt` on it before you read it. ``` console -$ cargo build --example foo +$ cargo build --example smallest --target thumbv7m-none-eabi +``` +``` console $ rustfmt target/rtic-expansion.rs +``` -tail target/rtic-expansion.rs +``` console +$ tail target/rtic-expansion.rs ``` ``` rust @@ -36,13 +34,14 @@ mod app { } ``` -Or, you can use the [`cargo-expand`] sub-command. This sub-command will expand -*all* the macros, including the `#[rtic::app]` attribute, and modules in your -crate and print the output to the console. +Or, you can use the [`cargo-expand`] sub-command. This sub-command will expand *all* the macros, including the `#[rtic::app]` attribute, and modules in your crate and print the output to the console. [`cargo-expand`]: https://crates.io/crates/cargo-expand ``` console # produces the same output as before +``` + +``` console cargo expand --example smallest | tail ``` diff --git a/book/en/src/internals/targets.md b/book/en/src/internals/targets.md index 04fd592..3562eef 100644 --- a/book/en/src/internals/targets.md +++ b/book/en/src/internals/targets.md @@ -1,13 +1,13 @@ # Target Architecture -While RTIC can currently target all Cortex-m devices there are some key architecure differences that -users should be aware of. Namely the absence of Base Priority Mask Register (`BASEPRI`) which lends +While RTIC can currently target all Cortex-m devices there are some key architecture differences that +users should be aware of. Namely, the absence of Base Priority Mask Register (`BASEPRI`) which lends itself exceptionally well to the hardware priority ceiling support used in RTIC, in the ARMv6-M and ARMv8-M-base architectures, which forces RTIC to use source masking instead. For each implementation of lock and a detailed commentary of pros and cons, see the implementation of [lock in src/export.rs][src_export]. -[src_export]: https://github.com/rtic-rs/cortex-m-rtic/blob/master/src/export.rs +[src_export]: https://github.com/rtic-rs/rtic/blob/master/src/export.rs These differences influence how critical sections are realized, but functionality should be the same except that ARMv6-M/ARMv8-M-base cannot have tasks with shared resources bound to exception @@ -29,7 +29,7 @@ Table 1 below shows a list of Cortex-m processors and which type of critical sec ## Priority Ceiling -This implementation is covered in depth by the [Critical Sections][critical_sections] page of this book. +This is covered by the [Resources][resources] page of this book. ## Source Masking @@ -55,17 +55,14 @@ with B. ``` At time *t1*, task B locks the shared resource by selectively disabling (using the NVIC) all other -tasks which have a priority equal to or less than any task which shares resouces with B. In effect -this creates a virtual priority ceiling, miroring the `BASEPRI` approach described in the -[Critical Sections][critical_Sections] page. Task A is one such task that shares resources with +tasks which have a priority equal to or less than any task which shares resources with B. In effect +this creates a virtual priority ceiling, mirroring the `BASEPRI` approach. Task A is one such task that shares resources with task B. At time *t2*, task A is either spawned by task B or becomes pending through an interrupt condition, but does not yet preempt task B even though its priority is greater. This is because the -NVIC is preventing it from starting due to task A being being disabled. At time *t3*, task B +NVIC is preventing it from starting due to task A being disabled. At time *t3*, task B releases the lock by re-enabling the tasks in the NVIC. Because task A was pending and has a higher priority than task B, it immediately preempts task B and is free to use the shared resource without risk of data race conditions. At time *t4*, task A completes and returns the execution context to B. Since source masking relies on use of the NVIC, core exception sources such as HardFault, SVCall, PendSV, and SysTick cannot share data with other tasks. - -[critical_sections]: https://github.com/rtic-rs/cortex-m-rtic/blob/master/book/en/src/internals/critical-sections.md diff --git a/book/en/src/preface.md b/book/en/src/preface.md index 6041dfe..5cba633 100644 --- a/book/en/src/preface.md +++ b/book/en/src/preface.md @@ -1,7 +1,7 @@ <div align="center"><img width="300" height="300" src="RTIC.svg"></div> <div style="font-size: 6em; font-weight: bolder;" align="center">RTIC</div> -<h1 align="center">Real-Time Interrupt-driven Concurrency</h1> +<h1 align="center">The hardware accelerated Rust RTOS</h1> <p align="center">A concurrency framework for building real-time systems</p> @@ -10,29 +10,152 @@ This book contains user level documentation for the Real-Time Interrupt-driven Concurrency (RTIC) framework. The API reference is available [here](../../api/). -Formerly known as Real-Time For the Masses. +This is the documentation for RTIC v2.x. -<!--There is a translation of this book in [Russian].--> +Older releases: +[RTIC v1.x](/1.0) | [RTIC v0.5.x (unsupported)](/0.5) | [RTFM v0.4.x (unsupported)](/0.4) -<!--[Russian]: ../ru/index.html--> - -This is the documentation of v1.0.x of RTIC; for the documentation of version - -* v0.5.x go [here](/0.5). -* v0.4.x go [here](/0.4). +{{#include ../../../README.md:7:12}} ## Is RTIC an RTOS? -A common question is whether RTIC is an RTOS or not, and depending on your background the -answer may vary. From RTIC's developers point of view; RTIC is a hardware accelerated -RTOS that utilizes the NVIC in Cortex-M MCUs to perform scheduling, rather than the more -classical software kernel. +A common question is whether RTIC is an RTOS or not, and depending on your background the answer may vary. From RTIC's developers point of view; RTIC is a hardware accelerated RTOS that utilizes the hardware such as the NVIC on Cortex-M MCUs, CLIC on RISC-V etc. to perform scheduling, rather than the more classical software kernel. Another common view from the community is that RTIC is a concurrency framework as there is no software kernel and that it relies on external HALs. ---- +## RTIC - The Past, current and Future + +This section gives a background to the RTIC model. Feel free to skip to section [RTIC the model](preface.md#rtic-the-model) for a TL;DR. + +The RTIC framework takes the outset from real-time systems research at Luleå University of Technology (LTU) Sweden. RTIC is inspired by the concurrency model of the [Timber] language, the [RTFM-SRP] based scheduler, the [RTFM-core] language and [Abstract Timer] implementation. For a full list of related research see [TODO]. + +[Timber]: https://timber-lang.org/ +[RTFM-SRP]: https://www.diva-portal.org/smash/get/diva2:1005680/FULLTEXT01.pdf +[RTFM-core]: https://ltu.diva-portal.org/smash/get/diva2:1013248/FULLTEXT01.pdf +[Abstract Timer]: https://ltu.diva-portal.org/smash/get/diva2:1013030/FULLTEXT01.pdf + +## Stack Resource Policy based Scheduling + +[Stack Resource Policy (SRP)][SRP] based concurrency and resource management is at heart of the RTIC framework. The SRP model itself extends on [Priority Inheritance Protocols], and provides a set of outstanding properties for single core scheduling. To name a few: + +- preemptive deadlock and race-free scheduling +- resource efficiency + - tasks execute on a single shared stack + - tasks run-to-completion with wait free access to shared resources +- predictable scheduling, with bounded priority inversion by a single (named) critical section +- theoretical underpinning amenable to static analysis (e.g., for task response times and overall schedulability) + +SRP comes with a set of system-wide requirements: +- each task is associated a static priority, +- tasks execute on a single-core, +- tasks must be run-to-completion, and +- resources must be claimed/locked in LIFO order. + +[SRP]: https://link.springer.com/article/10.1007/BF00365393 +[Priority Inheritance Protocols]: https://ieeexplore.ieee.org/document/57058 + +## SRP analysis + +SRP based scheduling requires the set of static priority tasks and their access to shared resources to be known in order to compute a static *ceiling* (𝝅) for each resource. The static resource *ceiling* 𝝅(r) reflects the maximum static priority of any task that accesses the resource `r`. + +### Example + +Assume two tasks `A` (with priority `p(A) = 2`) and `B` (with priority `p(B) = 4`) both accessing the shared resource `R`. The static ceiling of `R` is 4 (computed from `𝝅(R) = max(p(A) = 2, p(B) = 4) = 4`). + +A graph representation of the example: + +```mermaid +graph LR + A["p(A) = 2"] --> R + B["p(A) = 4"] --> R + R["𝝅(R) = 4"] +``` + +## RTIC the hardware accelerated real-time scheduler + +SRP itself is compatible with both dynamic and static priority scheduling. For the implementation of RTIC we leverage on the underlying hardware for accelerated static priority scheduling. + +In the case of the `ARM Cortex-M` architecture, each interrupt vector entry `v[i]` is associated a function pointer (`v[i].fn`), and a static priority (`v[i].priority`), an enabled- (`v[i].enabled`) and a pending-bit (`v[i].pending`). + +An interrupt `i` is scheduled (run) by the hardware under the conditions: +1. is `pended` and `enabled` and has a priority higher than the (optional `BASEPRI`) register, and +1. has the highest priority among interrupts meeting 1. + +The first condition (1) can be seen a filter allowing RTIC to take control over which tasks should be allowed to start (and which should be prevented from starting). + +The SPR model for single-core static scheduling on the other hand states that a task should be scheduled (run) under the conditions: +1. it is `requested` to run and has a static priority higher than the current system ceiling (𝜫) +1. it has the highest static priority among tasks meeting 1. + +The similarities are striking and it is not by chance/luck/coincidence. The hardware was cleverly designed with real-time scheduling in mind. + +In order to map the SRP scheduling onto the hardware we need to take a closer look at the system ceiling (𝜫). Under SRP 𝜫 is computed as the maximum priority ceiling of the currently held resources, and will thus change dynamically during the system operation. + +## Example + +Assume the task model above. Starting from an idle system, 𝜫 is 0, (no task is holding any resource). Assume that `A` is requested for execution, it will immediately be scheduled. Assume that `A` claims (locks) the resource `R`. During the claim (lock of `R`) any request `B` will be blocked from starting (by 𝜫 = `max(𝝅(R) = 4) = 4`, `p(B) = 4`, thus SRP scheduling condition 1 is not met). + +## Mapping + +The mapping of static priority SRP based scheduling to the Cortex M hardware is straightforward: + +- each task `t` are mapped to an interrupt vector index `i` with a corresponding function `v[i].fn = t` and given the static priority `v[i].priority = p(t)`. +- the current system ceiling is mapped to the `BASEPRI` register or implemented through masking the interrupt enable bits accordingly. + +## Example + +For the running example, a snapshot of the ARM Cortex M [Nested Vectored Interrupt Controller (NVIC)][NVIC] may have the following configuration (after task `A` has been pended for execution.) + +| Index | Fn | Priority | Enabled | Pended | +| ----- | --- | -------- | ------- | ------ | +| 0 | A | 2 | true | true | +| 1 | B | 4 | true | false | + +[NVIC]: https://developer.arm.com/documentation/ddi0337/h/nested-vectored-interrupt-controller/about-the-nvic + +(As discussed later, the assignment of interrupt and exception vectors is up to the user.) + + +A claim (lock(r)) will change the current system ceiling (𝜫) and can be implemented as a *named* critical section: + - old_ceiling = 𝜫, 𝜫 = 𝝅(r) + - execute code within critical section + - old_ceiling = 𝜫 + +This amounts to a resource protection mechanism requiring only two machine instructions on enter and one on exit the critical section for managing the `BASEPRI` register. For architectures lacking `BASEPRI`, we can implement the system ceiling through a set of machine instructions for disabling/enabling interrupts on entry/exit for the named critical section. The number of machine instructions vary depending on the number of mask registers that needs to be updated (a single machine operation can operate on up to 32 interrupts, so for the M0/M0+ architecture a single instruction suffice). RTIC will determine the ceiling values and masking constants at compile time, thus all operations is in Rust terms zero-cost. + +In this way RTIC fuses SRP based preemptive scheduling with a zero-cost hardware accelerated implementation, resulting in "best in class" guarantees and performance. + +Given that the approach is dead simple, how come SRP and hardware accelerated scheduling is not adopted by any other mainstream RTOS? + +The answer is simple, the commonly adopted threading model does not lend itself well to static analysis - there is no known way to extract the task/resource dependencies from the source code at compile time (thus ceilings cannot be efficiently computed and the LIFO resource locking requirement cannot be ensured). Thus, SRP based scheduling is in the general case out of reach for any thread based RTOS. + +## RTIC into the Future + +Asynchronous programming in various forms are getting increased popularity and language support. Rust natively provides an `async`/`await` API for cooperative multitasking and the compiler generates the necessary boilerplate for storing and retrieving execution contexts (i.e., managing the set of local variables that spans each `await`). + +The Rust standard library provides collections for dynamically allocated data-structures which are useful to manage execution contexts at run-time. However, in the setting of resource constrained real-time systems, dynamic allocations are problematic (both regarding performance and reliability - Rust runs into a *panic* on an out-of-memory condition). Thus, static allocation is the preferable approach! + +RTIC provides a mechanism for `async`/`await` that relies solely on static allocations. However, the implementation relies on the `#![feature(type_alias_impl_trait)]` (TAIT) which is undergoing stabilization (thus RTIC v2.x currently requires a *nightly* toolchain). Technically, using TAIT, the compiler determines the size of each execution context allowing static allocation. + +From a modelling perspective `async/await` lifts the run-to-completion requirement of SRP, and each section of code between two yield points (`await`s) can be seen as an individual task. The compiler will reject any attempt to `await` while holding a resource (not doing so would break the strict LIFO requirement on resource usage under SRP). + +So with the technical stuff out of the way, what does `async/await` bring to the table? + +The answer is - improved ergonomics! A recurring use case is to have task perform a sequence of requests and then await their results in order to progress. Without `async`/`await` the programmer would be forced to split the task into individual sub-tasks and maintain some sort of state encoding (and manually progress by selecting sub-task). Using `async/await` each yield point (`await`) essentially represents a state, and the progression mechanism is built automatically for you at compile time by means of `Futures`. + +Rust `async`/`await` support is still incomplete and/or under development (e.g., there are no stable way to express `async` closures, precluding use in iterator patterns). Nevertheless, Rust `async`/`await` is production ready and covers most common use cases. + +An important property is that futures are composable, thus you can await either, all, or any combination of possible futures (allowing e.g., timeouts and/or asynchronous errors to be promptly handled). For more details and examples see Section [todo]. + +## RTIC the model + +An RTIC `app` is a declarative and executable system model for single-core applications, defining a set of (`local` and `shared`) resources operated on by a set of (`init`, `idle`, *hardware* and *software*) tasks. In short the `init` task runs before any other task returning a set of resources (`local` and `shared`). Tasks run preemptively based on their associated static priority, `idle` has the lowest priority (and can be used for background work, and/or to put the system to sleep until woken by some event). Hardware tasks are bound to underlying hardware interrupts, while software tasks are scheduled by asynchronous executors (one for each software task priority). + +At compile time the task/resource model is analyzed under SRP and executable code generated with the following outstanding properties: -{{#include ../../../README.md:7:47}} +- guaranteed race-free resource access and deadlock-free execution on a single-shared stack (thanks to SRP) + - hardware task scheduling is performed directly by the hardware, and + - software task scheduling is performed by auto generated async executors tailored to the application. -{{#include ../../../README.md:48:}} +The RTIC API design ensures that both SRP requirements and Rust soundness rules are upheld at all times, thus the executable model is correct by construction. Overall, the generated code infers no additional overhead in comparison to a handwritten implementation, thus in Rust terms RTIC offers a zero-cost abstraction to concurrency. diff --git a/book/en/src/rtic_vs.md b/book/en/src/rtic_vs.md new file mode 100644 index 0000000..454b239 --- /dev/null +++ b/book/en/src/rtic_vs.md @@ -0,0 +1,33 @@ +# RTIC vs. the world + +RTIC aims to provide the lowest level of abstraction needed for developing robust and reliable embedded software. + +It provides a minimal set of required mechanisms for safe sharing of mutable resources among interrupts and asynchronously executing tasks. The scheduling primitives leverages on the underlying hardware for unparalleled performance and predictability, in effect RTIC provides in Rust terms a zero-cost abstraction to concurrent real-time programming. + + + +## Comparison regarding safety and security + +Comparing RTIC to traditional a Real-Time Operating System (RTOS) is hard. Firstly, a traditional RTOS typically comes with no guarantees regarding system safety, even the most hardened kernels like the formally verified [seL4] kernel. Their claims to integrity, confidentiality, and availability regards only the kernel itself (under additional assumptions its configuration and environment). They even state: + +"An OS kernel, verified or not, does not automatically make a system secure. In fact, any system, no matter how secure, can be used in insecure ways." - [seL4 FAQ][sel4faq] + +[sel4faq]: https://docs.sel4.systems/projects/sel4/frequently-asked-questions.html + +[seL4]: https://sel4.systems/ + +### Security by design + +In the world of information security we commonly find: + +- confidentiality, protecting the information from being exposed to an unauthorized party, +- integrity, referring to accuracy and completeness of data, and +- availability, referring to data being accessible to authorized users. + +Obviously, a traditional OS can guarantee neither confidentiality nor integrity, as both requires the security critical code to be trusted. Regarding availability, this typically boils down to the usage of system resources. Any OS that allows for dynamic allocation of resources, relies on that the application correctly handles allocations/de-allocations, and cases of allocation failures. + +Thus their claim is correct, security is completely out of hands for the OS, the best we can hope for is that it does not add further vulnerabilities. + +RTIC on the other hand holds your back. The declarative system wide model gives you a static set of tasks and resources, with precise control over what data is shared and between which parties. Moreover, Rust as a programming language comes with strong properties regarding integrity (compile time aliasing, mutability and lifetime guarantees, together with ensured data validity). + +Using RTIC these properties propagate to the system wide model, without interference of other applications running. The RTIC kernel is internally infallible without any need of dynamically allocated data.
\ No newline at end of file diff --git a/book/ru/book.toml b/book/ru/book.toml deleted file mode 100644 index 98c5bf3..0000000 --- a/book/ru/book.toml +++ /dev/null @@ -1,9 +0,0 @@ -[book] -authors = ["Jorge Aparicio, Per Lindgren and The Real-Time Interrupt-driven Concurrency developers"] -multilingual = false -src = "src" -title = "Real-Time Interrupt-driven Concurrency" - -[output.html] -git-repository-url = "https://github.com/rtic-rs/cortex-m-rtic" -git-repository-icon = "fa-github" diff --git a/book/ru/src/RTIC.svg b/book/ru/src/RTIC.svg deleted file mode 100644 index 1c65cba..0000000 --- a/book/ru/src/RTIC.svg +++ /dev/null @@ -1,109 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)" - inkscape:export-ydpi="145.74001" - inkscape:export-xdpi="145.74001" - inkscape:export-filename="/home/emifre/Documents/logo/v2_seller1/vctr/g248_2.png" - sodipodi:docname="RTIC.svg" - viewBox="0 0 375.55994 408.84339" - height="408.84338" - width="375.55994" - xml:space="preserve" - id="svg2" - version="1.1"><metadata - id="metadata8"><rdf:RDF><cc:Work - rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs - id="defs6"><clipPath - id="clipPath18" - clipPathUnits="userSpaceOnUse"><path - id="path16" - d="M 0,500 H 500 V 0 H 0 Z" /></clipPath></defs><sodipodi:namedview - inkscape:current-layer="g10" - inkscape:window-maximized="1" - inkscape:window-y="0" - inkscape:window-x="0" - inkscape:cy="229.27385" - inkscape:cx="150.39187" - inkscape:zoom="1.5119999" - fit-margin-bottom="0" - fit-margin-right="0" - fit-margin-left="0" - fit-margin-top="0" - inkscape:pagecheckerboard="false" - showgrid="false" - id="namedview4" - inkscape:window-height="1016" - inkscape:window-width="1920" - inkscape:pageshadow="2" - inkscape:pageopacity="0" - guidetolerance="10" - gridtolerance="10" - objecttolerance="10" - borderopacity="1" - bordercolor="#666666" - pagecolor="#ffffff" - inkscape:document-rotation="0" /><g - transform="matrix(1.3333333,0,0,-1.3333333,-148.85309,622.34951)" - inkscape:label="45453_RTIC logo_JK" - inkscape:groupmode="layer" - id="g10"><g - inkscape:export-filename="/home/emifre/Documents/logo/v2_seller1/vctr/g248.png" - inkscape:export-ydpi="153.37898" - inkscape:export-xdpi="153.37898" - style="opacity:1;fill:#4d4d4d;fill-opacity:1" - transform="matrix(7.464224,0,0,7.464224,393.30978,300.96457)" - id="g248"><path - id="path250" - style="fill:#4d4d4d;fill-opacity:1;fill-rule:nonzero;stroke:none" - d="m 0,0 c 0,-10.421 -8.448,-18.868 -18.868,-18.868 -10.421,0 -18.868,8.447 -18.868,18.868 0,10.421 8.447,18.868 18.868,18.868 C -8.448,18.868 0,10.421 0,0" /></g><g - inkscape:export-filename="/home/emifre/Documents/logo/v2_seller1/vctr/g248.png" - inkscape:export-ydpi="153.37898" - inkscape:export-xdpi="153.37898" - transform="matrix(7.464224,0,0,7.464224,292.89574,388.12804)" - id="g252"><path - sodipodi:nodetypes="cccccccccc" - id="path254" - style="fill:#cccccc;fill-opacity:1;fill-rule:nonzero;stroke:none" - d="M 0,0 C -0.604,5.477 -5.967,9.765 -6.856,10.442 -6.487,9.748 -5.71,8.123 -5.267,6.023 -4.92,4.374 -4.845,2.758 -5.043,1.221 -5.291,-0.701 -5.97,-2.505 -7.062,-4.14 c -0.294,-0.441 -0.601,-0.894 -0.926,-1.374 -3.428,-5.065 -8.25205,-11.907209 -7.04305,-17.843209 0.528,-2.592 2.166,-4.805 4.866,-6.583 -7.606,6.593 -2.20795,13.944209 1.62005,17.105209 C -5.253,-10.117 0.659,-5.974 0,0" /></g><g - inkscape:export-filename="/home/emifre/Documents/logo/v2_seller1/vctr/g248.png" - inkscape:export-ydpi="153.37898" - inkscape:export-xdpi="153.37898" - transform="matrix(7.464224,0,0,7.464224,193.42458,186.62982)" - id="g256"><path - sodipodi:nodetypes="ccccccccccc" - id="path258" - style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none" - d="m 0,0 c -0.777,1.074 -1.303,2.263 -1.562,3.535 -1.212,5.951 3.488,12.895 6.92,17.966 0.325,0.48 0.632,0.933 0.926,1.374 2.464,3.693 2.333,7.549 1.789,10.135 -0.456,2.168 -1.27,3.828 -1.621,4.477 -0.038,0.028 -0.058,0.043 -0.058,0.043 0,0 -6.038,-7.951 -8.738,-12.258 C -5.045,20.964 -8.509,12.81 -5.274,5.863 -2.263,-0.605 2.4913395,-2.6700085 3.1613395,-2.9450085 1.7523395,-2.0240085 0.824,-1.138 0,0" /></g><g - inkscape:export-filename="/home/emifre/Documents/logo/v2_seller1/vctr/g248.png" - inkscape:export-ydpi="153.37898" - inkscape:export-xdpi="153.37898" - transform="matrix(7.464224,0,0,7.464224,286.22601,210.85049)" - id="g260"><path - sodipodi:nodetypes="cccccccssc" - id="path262" - style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none" - d="m 0,0 c -0.199,-4.847 -3.7433301,-6.7788234 -3.7433301,-6.7788234 0,0 0.2005158,0.00584 0.4557728,0.023109 C -0.01255733,-5.7517164 4.496,-3.342 4.518,2.624 4.53,5.687 2.682,7.663 1.13,8.781 c -1.149,0.828 -2.309,1.321 -2.935,1.551 -0.396,-0.067 -2.392,-0.519 -2.51,-2.836 0,0 -3.5425677,-1.2008654 -3.56,-1.632 C -7.9046856,5.1298176 -6.9355723,4.1874599 -6.187,3.63 -5.1908601,2.8881772 0.199,4.847 0,0" /></g><g - inkscape:export-filename="/home/emifre/Documents/logo/v2_seller1/vctr/g248.png" - inkscape:export-ydpi="153.37898" - inkscape:export-xdpi="153.37898" - transform="matrix(7.464224,0,0,7.464224,360.6426,228.88853)" - id="g264"><path - sodipodi:nodetypes="zcccccccccccczzz" - id="path266" - style="fill:#cccccc;fill-opacity:1;fill-rule:nonzero;stroke:none" - d="M -0.34917151,1.6816738 C -0.7974951,5.9368052 -3.1264734,7.1611735 -5.072,8.56 c 0,0 -0.8516082,3.022335 -1.7015402,3.1237 0,0 0.3570815,0.04169 0,0 -0.6687287,0.05444 -1.1522423,-0.270149 -1.9532423,-1.364149 0,0 -1.1502065,1.167917 -2.4848885,1.093235 C -12.505303,11.107968 -11.817,7.957 -11.818,7.928 c 0.64,-0.24 1.768,-0.729 2.886,-1.535 0.992,-0.715 1.781,-1.534 2.346,-2.437 0.707,-1.128 1.062,-2.389 1.057,-3.748 -0.006,-1.773 -0.433,-3.369 -1.267,-4.743 -0.712,-1.172 -1.724,-2.193 -3.01,-3.036 -1.181,-0.774 -2.329326,-1.2453139 -3.451326,-1.6013139 1.173268,0.050293 3.778241,0.431572 5.8646425,1.3359556 2.0864016,0.9043837 3.5682459,1.7417342 4.4081274,2.592566 0.8398814,0.8508318 3.08370818,2.6703347 2.63538459,6.9254661 z" /></g><path - inkscape:export-filename="/home/emifre/Documents/logo/v2_seller1/vctr/g248.png" - sodipodi:nodetypes="ssss" - inkscape:export-ydpi="153.37898" - inkscape:export-xdpi="153.37898" - id="path1340" - d="m 227.38125,254.73726 c -0.52355,-1.50734 0.39304,-4.38366 2.33326,-6.47436 2.23581,-2.40923 7.33976,11.89073 4.18714,10.96111 -2.21547,-0.65328 -6.03712,-3.09534 -6.5204,-4.48675 z" - style="fill:#808080;fill-opacity:1;stroke:#cccccc;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /></g></svg> diff --git a/book/ru/src/SUMMARY.md b/book/ru/src/SUMMARY.md deleted file mode 100644 index cf03cda..0000000 --- a/book/ru/src/SUMMARY.md +++ /dev/null @@ -1,25 +0,0 @@ -# Summary - -[Введение](./preface.md) - -- [RTIC в примерах](./by-example.md) - - [Атрибут `app`](./by-example/app.md) - - [Ресурсы](./by-example/resources.md) - - [Программные задачи](./by-example/tasks.md) - - [Очередь таймера](./by-example/timer-queue.md) - - [Типы, Send и Sync](./by-example/types-send-sync.md) - - [Создание нового проекта](./by-example/new.md) - - [Советы и хитрости](./by-example/tips.md) -- [Инструкции по миграции](./migration.md) - - [v0.5.x на v1.0.x](./migration/migration_v5.md) - - [v0.4.x на v0.5.x](./migration/migration_v4.md) - - [RTFM на RTIC](./migration/migration_rtic.md) -- [Под капотом](./internals.md) - - [Настройка прерываний](./internals/interrupt-configuration.md) - - [Нереентерабельнось](./internals/non-reentrancy.md) - - [Контроль доступа](./internals/access.md) - - [Поздние ресурсы](./internals/late-resources.md) - - [Критические секции](./internals/critical-sections.md) - - [Анализ приоритетов](./internals/ceilings.md) - - [Программные задачи](./internals/tasks.md) - - [Очередь таймера](./internals/timer-queue.md) diff --git a/book/ru/src/by-example.md b/book/ru/src/by-example.md deleted file mode 100644 index 027716f..0000000 --- a/book/ru/src/by-example.md +++ /dev/null @@ -1,23 +0,0 @@ -# RTIC в примерах - -В этой части книги фреймворк Real-Time Interrupt-driven Concurrency (RTIC) представляется -новым пользователям путем прохода по примерам от простых к более сложным. - -Все примеры в этой части книги можно найти в [репозитарии] проекта. -Большинство из них можно пройти, запустив их на эмуляторе QEMU без специального оборудования. - -[репозитарии]: https://github.com/rtic-rs/cortex-m-rtic - -Для запуска примеров на вашем ПК, вам понадобится программа `qemu-system-arm`. -В [the embedded Rust book] есть инструкции по настройке среды для эмбеддед разработке, -в том числе QEMU. - -[the embedded Rust book]: https://rust-embedded.github.io/book/intro/install.html - -## Примеры из реальной жизни - -Ниже представлены примеры использования RTIC (RTFM) в реальных проектах. - -### RTFM V0.4.2 - -- [etrombly/sandbox](https://github.com/etrombly/sandbox/tree/41d423bcdd0d8e42fd46b79771400a8ca349af55). Аппаратный дзэн-сад, рисующий картинки на песке. Картинки передаются по последовательному порту с помощью G-кода. diff --git a/book/ru/src/by-example/app.md b/book/ru/src/by-example/app.md deleted file mode 100644 index 5259bfa..0000000 --- a/book/ru/src/by-example/app.md +++ /dev/null @@ -1,161 +0,0 @@ -# Атрибут `app` - -Это простейшая из возможных программ на RTIC: - -``` rust -{{#include ../../../../examples/smallest.rs}} -``` - -Все программы на RTIC используют атрибут [`app`] (`#[app(..)]`). Этот атрибут -должен применяться к элементу `mod`. Атрибут `app` имеет обязательный аргумент `device`, -который принимает *путь* как значение. Это должен быть полный путь, указывающий на -*крейт доступа к периферии* (PAC), сгенерированный с помощью [`svd2rust`] версии **v0.14.x** -или новее. Более подробно в разделе [Создание нового проекта](./new.md). - -Атрибут `app` будет раскрыт в подходящую точку входа программы, поэтому -атрибут [`cortex_m_rt::entry`] не нужен. - -[`app`]: ../../../api/cortex_m_rtic_macros/attr.app.html -[`svd2rust`]: https://crates.io/crates/svd2rust -[`cortex_m_rt::entry`]: ../../../api/cortex_m_rt_macros/attr.entry.html - -## `init` - -Внутри модуля `app` атрибут ожидает найти функцию инициализации, помеченную -атрибутом `init`. Эта функция должна иметь сигнатуру -`fn(init::Context) (-> init::LateResources, init::Monotonics)`. - -Эта функция инициализации будет первой частью программы, выполняемой при запуске. -Функция `init` будет запущена *с отключенными прерываниями* и будет иметь эксклюзивный доступ -к Cortex-M, в котором токен `bare_metal::CriticalSection` доступен как `cs`. -Опционально, устройство-специфичные периферия доступна через поля `core` и `device` структуры -`init::Context`. - -`static mut` переменные, определенные в начале `init` будут преобразованы в -`&'static mut` ссылки, безопасные для доступа. Обратите внимание, данная возможность может -быть удалена в следующем релизе, см. `task_local` ресурсы. - -[`rtic::Peripherals`]: ../../api/rtic/struct.Peripherals.html - -Пример ниже показывает типы полей `core`, `device` и `cs`, и демонстрирует -безопасный доступ к `static mut` переменной. Поле `device` доступно только -когда аргумент `peripherals` установлен в `true` (по умолчанию). -В редких случаях, когда вы захотите создать приложение с минимальным потреблением ресурсов, -можно явно установить `peripherals` в `false`. - -``` rust -{{#include ../../../../examples/init.rs}} -``` - -Запуск примера напечатате `init` в консоли, а затем завершит процесс QEMU. - -``` console -$ cargo run --example init -{{#include ../../../../ci/expected/init.run}} -``` - -> **ПРИМЕЧАНИЕ**: Не забывайте указывать выбранное вами целевое устройство, передавая параметр target -> в cargo (например `cargo run --example init --target thumbv7m-none-eabi`) или -> настроив устройство, используемое по умолчанию для сборки примеров в `.cargo/config.toml`. -> В нашем случае используется Cortex M3, эмулируемый с помощью QEMU, поэтому пишем `thumbv7m-none-eabi`. -> Смотрите [`Создание нового проекта`](./new.md) для большей информации. - -## `idle` - -Функцию, помеченную атрибутом `idle` может опционально добавить в модуль. -Эта функция используется как специальная *задача ожидания* и должна иметь сигнатуру -`fn(idle::Context) - > !`. - -Если она присутствует, задача `idle` будет запущена после `init`. В отличие от -`init`, `idle` будет запущена *с включенными прерываниями* и она не может вернуть результат, -а значит должна работать вечно. - -Как и в `init`, `static mut` переменные будут трансформированы в `&'static mut` ссылки, -безопасные для доступа. Обратите внимание, данная возможность может -быть удалена в следующем релизе, см. `task_local` ресурсы. - -Пример ниже показывает, что `idle` запускается после `init`. - -**Примечание:** Цикл `loop {}` в функци ожидания не может быть пустым, так как это сломает -микроконтроллер, из-за того, что LLVM компилирует пустые циклы в инструкцию `UDF` в release mode. -Чтобы избежать неопределенного поведения, цикл должен включать "side-effect" -путем вставки ассемблерной инструкции (например, `WFI`) или ключевого слова `continue`. - -``` rust -{{#include ../../../../examples/idle.rs}} -``` - -``` console -$ cargo run --example idle -{{#include ../../../../ci/expected/idle.run}} -``` - -## Аппаратные задачи - -Чтобы объявить обработчик прерывания, фреймворк предоставляет атрибут `#[task]`, -который можно применять к функциям. Этот атрибут берет аргумент `binds`, чье значение - -это имя прерывания, которому будет назначен обработчик; -функция, декорированная этим атрибутом становится обработчиком прерывания. -В фреймворке такие типы задач именуются *аппаратными*, потому что они начинают -выполняться в ответ на аппаратное событие. - -Пример ниже демонстрирует использование атрибута `#[task]`, чтобы объявить -обработчик прерывания. Как и в случае с `#[init]` и `#[idle]` локальные `static -mut` переменные безопасны для использования с аппаратной задачей. - -``` rust -{{#include ../../../../examples/hardware.rs}} -``` - -``` console -$ cargo run --example hardware -{{#include ../../../../ci/expected/hardware.run}} -``` - -До сих пор все программы на RTIC, которые мы видели, не отличались от программ, -которые можно написать, используя лишь крейт `cortex-m-rt`. С этого момента мы -начинаем представлять возможности, уникальные для RTIC. - -## Приоритеты - -Статический приоритет каждого обработчика можно оределить в атрибуте `task`, используя -аргумент `priority`. Задачи могут иметь приоритет в диапазоне `1..=(1 << NVIC_PRIO_BITS)`, -где `NVIC_PRIO_BITS` - это константа, определенная в крейте `устройства`. -Когда аргумент `priority` не указан, предполагается, что приоритет равен `1`. -Задача `idle` имеет ненастраиваемый приоритет `0`, наименьший из возможных. - -> Более высокое значение означает более высокий приоритет в RTIC, что противоположно тому, -> что указано в периферии NVIC Cortex-M. -> Точнее, это значит, что число `10` обозначает приоритет **выше**, чем число `9`. - -Когда несколько задач готовы к запуску, задача с самым большим статическим -приоритетом будет запущена первой. Приоритезацию задач можно рассматривать по -такому сценарию: сигнал прерывания приходит во время выполнения задачи с низким приоритетом; -сигнал переключает задачу с высоким приоритетом в режим ожидания. -Разница в приоритетах приводи к тому, что задача с высоким приоритетом вытесняет задачу с низким: -выполнение задачи с низким приоритетом замораживается и задача с высоким приоритетом выполняется, -пока не будет завершена. Как только задача с высоким приоритетом будет остановлена, -продолжится выполнение задачи с низким приоритетом. - -Следующий пример демонстрирует диспетчеризацию на основе приоритетов задач. - -``` rust -{{#include ../../../../examples/preempt.rs}} -``` - -``` console -$ cargo run --example preempt -{{#include ../../../../ci/expected/preempt.run}} -``` - -Заметьте, что задача `gpiob` *не* вытесняет задачу `gpioc`, потому что ее приоритет -*такой же*, как и у `gpioc`. Однако, как только `gpioc` возвращает результат, -выполненяется задача `gpiob`, как более приоритетная по сравнению с `gpioa`. -Выполнение `gpioa` возобновляется только после выхода из `gpiob`. - -Еще одно замечание по поводу приоритетов: выбор приоритета большего, чем поддерживает устройство -(а именно `1 << NVIC_PRIO_BITS`) приведет к ошибке компиляции. -Из-за ограничений языка, сообщение об ошибке далеко от понимания: -вам скажут что-то похожее на "evaluation of constant value failed", а указатель на ошибку -*не* покажет на проблемное значение прерывания -- -мы извиняемся за это! diff --git a/book/ru/src/by-example/new.md b/book/ru/src/by-example/new.md deleted file mode 100644 index 0ff8d98..0000000 --- a/book/ru/src/by-example/new.md +++ /dev/null @@ -1,84 +0,0 @@ -# Создание нового проекта - -Теперь, когда Вы изучили основные возможности фреймворка RTIC, Вы можете -попробовать его использовать на Вашем оборудовании следуя этим инструкциям. - -1. Создайте экземпляр из шаблона [`cortex-m-quickstart`]. - -[`cortex-m-quickstart`]: https://github.com/rust-embedded/cortex-m-quickstart#cortex-m-quickstart - -``` console -$ # например используя `cargo-generate` -$ cargo generate \ - --git https://github.com/rust-embedded/cortex-m-quickstart \ - --name app - -$ # следуйте остальным инструкциям -``` - -2. Добавьте крейт доступа к периферии (PAC), сгенерированный с помощью[`svd2rust`] - **v0.14.x**, или крейт отладочной платы, у которой в зависимостях один из таких PAC'ов. - Убедитесь, что опция `rt` крейта включена. - -[`svd2rust`]: https://crates.io/crates/svd2rust - -В этом примере я буду использовать крейт устройства [`lm3s6965`]. -Эта библиотека не имеет Cargo-опции `rt`; эта опция всегда включена. - -[`lm3s6965`]: https://crates.io/crates/lm3s6965 - -Этот крейт устройства предоставляет линковочный скрипт с макетом памяти -целевого устройства, поэтому `memory.x` и `build.rs` нужно удалить. - -``` console -$ cargo add lm3s6965 --vers 0.1.3 - -$ rm memory.x build.rs -``` - -3. Добавьте крейт `cortex-m-rtic` как зависимость. - -``` console -$ cargo add cortex-m-rtic --allow-prerelease -``` - -4. Напишите свою RTIC программу. - -Здесь я буду использовать пример `init` из крейта `cortex-m-rtic`. - -Примеры находтся в папке `examples`, а содержание `init.rs` показано здесь: - -``` console -{{#include ../../../../examples/init.rs}} -``` - -Пример `init` использует устройство `lm3s6965`. Не забудьте настроить аргумент `device` -в атрибуте макроса app так, чтобы он соответствовал пути к PAC-крейту, если он отличается, -а также добавить перифериб и другие аргументы если необходимо. -Несмотря на то, что в программе могут использоваться псевдонимы типов, -здесь необходимо указать полный путь (из корня крейта). Для многих устройств, -есть общий подход в крейтах реализации HAL (с псевдонимом `hal`) и крейтах поддержки -отладочных плат реекспортиорвать PAC как `pac`, что приводит нас к образцу, аналогичному -приведенному ниже: - -```rust -use abcd123_hal as hal; -//... - -#[rtic::app(device = crate::hal::pac, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)] -mod app { /*...*/ } -``` - -Пример `init` также зависит от крейта `panic-semihosting`: - -``` console -$ cargo add panic-semihosting -``` - -5. Соберите его, загрузите в микроконтроллер и запустите. - -``` console -$ # ПРИМЕЧАНИЕ: Я раскомментировал опцию `runner` в `.cargo/config.toml` -$ cargo run -{{#include ../../../../ci/expected/init.run}} -``` diff --git a/book/ru/src/by-example/resources.md b/book/ru/src/by-example/resources.md deleted file mode 100644 index ed8904b..0000000 --- a/book/ru/src/by-example/resources.md +++ /dev/null @@ -1,140 +0,0 @@ -# Ресурсы - -Фреймворк предоставляет абстракцию для разделения данных между любыми контекстами, -с которыми мы встречались в предыдущей главе (задачами-обработчиками, `init` и `idle`): ресурсы. - -Ресурсы - это данные, видимые только функциями, определенными внутри модуля `#[app]`. -Фреймворк дает пользователю полный контроль за тем, какой контекст может -получить доступ к какому ресурсу. - -Все ресурсы определены в *двух* структурах внутри модуля `#[app]`. -Каждое поле этих структур соответствует отдельному ресурсу. -Одна `struct`-ура должна быть аннотирована атрибутом `#[local]`. -Другая `struct`-ура должна быть аннотирована атрибутом `#[shared]`. -Разница между этими двумя множествами ресурсов будет описана познее. - -Каждый контекс (задача-обработчик, `init` или `idle`) должен указать ресурсы, к которым -он намерен обращаться, в соответсятвующем ему атрибуте с метаданными, используя -либо аргумент `local`, либо `shared`. Этот аргумент принимает список имен ресурсов в качестве значения. -Перечисленные ресурсы становятся доступны в контексте через поля `local` и `shared` структуры `Context`. - -Во время выполнения при выходе из функции `#[init]` все ресурсы инициализированы. -Функция `#[init]` должна возвращать начальные значения для всех ресурсов; -отсюда следует, что тип возвращаемого ею значения включает типы -структур `#[shared]` и `#[local]`. -Поскольку ресурсы инициализированы в ходе функции `#[init]`, к ним нельзя -получить доступ внетри функции `#[init]`. - -Пример программы, показанной ниже содержит два обработчика прерывания. -Каждый обработчик имеет доступ к его собственному `#[local]` ресурсу. - -``` rust -{{#include ../../../../examples/resource.rs}} -``` - -``` console -$ cargo run --example resource -{{#include ../../../../ci/expected/resource.run}} -``` - -К ресурсу `#[local]` нельзя получить доступ извне задачи к которой он -привязан атрибутом `#[task]`. -Попытка обращения к одному и тому же ресурсу `#[local]` из более чем одной -задачи - ошибка компиляции. - -## `lock` - -Критические секции необходимы для доступа к ресурсам `#[shared]` таким образом, -чтобы избежать гонок данных. - -Поле `shared`, передаваемого `Context` реализует трейт [`Mutex`] для каждого разделяемого -ресурса, доступного задаче. - -Единственный метод этого трейта, [`lock`], запускает свой аргумент-замыкание в критической секции. - -[`Mutex`]: ../../../api/rtic/trait.Mutex.html -[`lock`]: ../../../api/rtic/trait.Mutex.html#method.lock - -Критическая секция, создаваемая интерфейсом `lock` основана на динамических приоритетах: -она временно повышает динамический приоритет контекста до *максимального* приоритета, -что не дает другим задачам возможности вытеснить критическую секцию. -Этот протокол синхронизации известен как [Протокол немедленного максимального приоритета -(ICPP)][icpp], и компилируется диспетчером RTIC с [Политикой ресурсов стека(SRP)][srp]. - -[icpp]: https://en.wikipedia.org/wiki/Priority_ceiling_protocol -[srp]: https://en.wikipedia.org/wiki/Stack_Resource_Policy - -В примере ниже у нас есть три обработчика прерываний с приоритетами от одного до трех. -Два из обработчиков с более низким приоритетом соревнуются за ресурс `shared`, -поэтому должны блокировать доступа к данным ресурса. -Обработчик с наивысшим приоритетом, который не имеет доступа к ресурсу `shared`, -может свободно вытеснять критическую секцию, созданную обработчиком с низким приоритетом. - -``` rust -{{#include ../../../../examples/lock.rs}} -``` - -``` console -$ cargo run --example lock -{{#include ../../../../ci/expected/lock.run}} -``` - -## Множественное блокировка - -Это расширение к `lock`, чтобы уменьшить количесво отступов, блокируемые ресурсы можно объединять в кортежи. -Следующий пример это демонстрирует: - -``` rust -{{#include ../../../../examples/multilock.rs}} -``` - -## Только разделяемый (`&-`) доступ - -По-умолчанию фреймворк предполагает, что все задачи требуют эксклюзивный доступ (`&mut-`) к ресурсам, -но возможно указать, что задаче достаточен разделяемый доступ (`&-`) к ресурсы с помощью синтакисиса -`&resource_name` в списке `resources`. - -Преимущество указания разделяемого досупа (`&-`) к ресурсу в том, что для доступа к ресурсу -не нужна блокировка, даже если за ресурс соревнуются несколько задач, запускаемые с -разными приоритетами. Недостаток в том, что задача получает только разделяемую ссылку (`&-`) -на ресурс, и ограничена операциями, возможными с ней, но там, где разделяемой ссылки достаточно, -такой подход уменьшает количесво требуемых блокировок. -В дополнение к простым неизменяемым данным, такой разделяемый доступ может быть полезен для -ресурсов, безопасно реализующих внутреннюю мутабельность с самоблокировкой или атомарными операциями. - -Заметьте, что в этом релизе RTIC невозможно запросить и эксклюзивный доступ (`&mut-`) -и разделяемый (`&-`) для *одного и того же* ресурса из различных задач. -Попытка это сделать приведет к ошибке компиляции. - -В примере ниже ключ (например криптографический ключ) загружается (или создается) во время выполнения, -а затем используется двумя задачами, запускаемымы с различным приоритетом без каких-либо блокировок. - -``` rust -{{#include ../../../../examples/only-shared-access.rs}} -``` - -``` console -$ cargo run --example only-shared-access -{{#include ../../../../ci/expected/only-shared-access.run}} -``` - -## Неблокируемый доступ к изменяемым ресурсам - -Критическая секция *не* требуется для доступа к ресурсу `#[shared]`, -к которому обращаются только из задач с *одинаковым* приоритетом. -В этом случае вы можете избежать `lock` API, добавив атрибут поля `#[lock_free]` при объявдении ресурса (смотреть пример ниже). -Заметьте, что это лишь для удобства: даже если вы используете `lock` API, -во время выполнения фреймворк *не* создаст критическую секцию. -Еще одно ценное замечание: использование `#[lock_free]` на ресурсах, -разделяемых задачами, запускаемыми с разными приоритетами -приведет к ошибке *компиляции* -- не импользование `lock` API может -привести к гонке данных в этом случае. - -``` rust -{{#include ../../../../examples/lock-free.rs}} -``` - -``` console -$ cargo run --example lock-free -{{#include ../../../../ci/expected/lock-free.run}} -```
\ No newline at end of file diff --git a/book/ru/src/by-example/tasks.md b/book/ru/src/by-example/tasks.md deleted file mode 100644 index 3c99d00..0000000 --- a/book/ru/src/by-example/tasks.md +++ /dev/null @@ -1,116 +0,0 @@ -# Программные задачи - -В дополнение к аппаратным задачам, вызываемым в ответ на аппаратные события, -RTIC также поддерживает *программные* задачи, которые могут порождаться -приложением из любого контекста выполнения. - -Программным задачам можно также назначать приоритет и, под капотом, они -диспетчеризуются обработчиками прерываний. RTIC требует, чтобы свободные -прерывания, были указаны в аргументе `dispatchers` модуля `app`, если используются -программные задачи; часть из этих свободных прерываний будут использованы для -управления программными задачами. Преимущество программных задач над аппаратными -в том, что множество задач можно назначить на один обработчик прерывания. - -Программные задачи также определяются атрибутом `task`, но аргумент `binds` опускается. - -Пример ниже демонстрирует три программные задачи, запускаемых 2-х разных приоритетах. -Три программные задачи привязаны к 2-м обработчикам прерываний. - -``` rust -{{#include ../../../../examples/task.rs}} -``` - -``` console -$ cargo run --example task -{{#include ../../../../ci/expected/task.run}} -``` - -## Передача сообщений - -Другое преимущество программной задачи в том, что задачам можно передать сообщения -в момент их запуска. Тип передаваемого сообщения должен быть определен в сигнатуре -задачи-обработчика. - -Пример ниже демонстрирует три задачи, две из которых ожидают сообщение. - -``` rust -{{#include ../../../../examples/message.rs}} -``` - -``` console -$ cargo run --example message -{{#include ../../../../ci/expected/message.run}} -``` - -## Вместимость - -RTIC *не* производит никакого рода аллокаций памяти в куче. -Память, необходимая для размещения сообщения резервируется статически. -По-умолчанию фреймворк минимизирует выделение памяти программой таким образом, -что каждая задача имеет "вместимость" для сообщения равную 1: -это значит, что не более одного сообщения можно передать задаче перед тем, как -у нее появится возможность к запуску. Это значение по-умолчанию можно -изменить для каждой задачи, используя аргумент `capacity`. -Этот аргумент принимает положительное целое, которое определяет как много -сообщений буфер сообщений задачи может хранить. - -Пример ниже устанавливает вместимость программной задачи `foo` равной 4. -Если вместимость не установить, второй вызов `spawn.foo` в `UART0` приведет к ошибке (панике). - -``` rust -{{#include ../../../../examples/capacity.rs}} -``` - -``` console -$ cargo run --example capacity -{{#include ../../../../ci/expected/capacity.run}} -``` - -## Обработка ошибок - -Интерфейс `spawn` возвращает вариант `Err`, если для размещения сообщения нет места. -В большинстве сценариев возникающие ошибки обрабатываются одним из двух способов: - -- Паника, с помощью `unwrap`, `expect`, и т.п. Этот метод используется, чтобы обнаружить - ошибку программиста (например bug) выбора вместительности, которая оказалась недостаточна. - Когда эта паника встречается во время тестирования, выбирается большая вместительность, - и перекомпиляция программы может решить проблему, но иногда достаточно окунуться глубже - и провести анализ времени выполнения программы, чтобы выяснить, может ли платформа - обрабатывать пиковые нагрузки, или процессор необходимо заменить на более быстрый. - -- Игнорирование результата. В программах реального времени, как и в обычных, может быть - нормальным иногда терять данные, или не получать ответ на некоторые события в пиковых ситуациях. - В таких сценариях может быть допустимо игнорирование ошибки вызова `spawn`. - -Следует отметить, что повторная попытка вызова `spawn` обычно неверный подход, поскольку -такая операция на практике вероятно никогда не завершится успешно. -Так как у нас есть только переключения контекста на задачи с *более высоким* приоритетом, -повторение вызова `spawn` на задаче с низким приоритом никогда не позволит планировщику -вызвать задачу, что значит, что буфер никогда не будет очищен. Такая ситуация отражена в -следующем наброске: - -``` rust -#[rtic::app(..)] -mod app { - #[init(spawn = [foo, bar])] - fn init(cx: init::Context) { - cx.spawn.foo().unwrap(); - cx.spawn.bar().unwrap(); - } - - #[task(priority = 2, spawn = [bar])] - fn foo(cx: foo::Context) { - // .. - - // программа зависнет здесь - while cx.spawn.bar(payload).is_err() { - // повтор попытки вызова spawn, если произошла ошибка - } - } - - #[task(priority = 1)] - fn bar(cx: bar::Context, payload: i32) { - // .. - } -} -``` diff --git a/book/ru/src/by-example/timer-queue.md b/book/ru/src/by-example/timer-queue.md deleted file mode 100644 index c8818d7..0000000 --- a/book/ru/src/by-example/timer-queue.md +++ /dev/null @@ -1,108 +0,0 @@ -# Очередь таймера - -В отличие от интерфейса `spawn`, который немедленно передает программную задачу -планировщику для немедленного запуска, интерфейс `schedule` можно использовать -для планирования задачи к запуске через какое-то время в будущем. - -Чтобы использовать интерфейс `schedule`, предварительно должен быть определен -монотонный таймер с помощью аргумента `monotonic` атрибута `#[app]`. -Этот аргумент принимает путь к типу, реализующему трейт [`Monotonic`]. -Ассоциированный тип, `Instant`, этого трейта представляет метку времени в соответствущих -единицах измерения и широко используется в интерфейсе `schedule` -- предлагается смоделировать -этот тип позднее [один из таких есть в стандартной библиотеке][std-instant]. - -Хотя это не отражено в определении трейта (из-за ограничений системы типов / трейтов), -разница двух `Instant`ов должна возвращать какой-то тип `Duration` (см. [`core::time::Duration`]) -и этот `Duration` должен реализовывать трейт `TryInto<u32>`. -Реализация этого трейта должна конвертировать значение `Duration`, которое -использует какую-то определенную единицу измерения времени, в единицы измерения "тактов системного таймера -(SYST)". Результат преобразований должен быть 32-битным целым. -Если результат не соответствует 32-битному целому, тогда операция должна возвращать ошибку любого типа. - -[`Monotonic`]: ../../../api/rtic/trait.Monotonic.html -[std-instant]: https://doc.rust-lang.org/std/time/struct.Instant.html -[`core::time::Duration`]: https://doc.rust-lang.org/core/time/struct.Duration.html - -Для целевых платформ ARMv7+ крейт `rtic` предоставляет реализацию `Monotonic`, основанную на -встроенном CYCle CouNTer (CYCCNT). Заметьте, что это 32-битный таймер, работающий на -частоте центрального процессора, и поэтому не подходит для отслеживания интервалов времени в секундах. - -Когда планируется задача, (определенный пользователем) `Instant`, в который задача должна быть -выполнена, должен передаваться в качестве первого аргумента вызова `schedule`. - -К тому же, выбранный `monotonic` таймер, необходимо сконфигурировать и инициализировать в -фазе работы `#[init]`. Заметьте, что *также* касается случая использования `CYCCNT`, -предоставляемого крейтом `cortex-m-rtic`. - -Пример ниже планирует к выполнению две задачи из `init`: `foo` и `bar`. `foo` запланирована -к запуску через 8 миллионов циклов в будущем. Далее, `bar` запланировано запустить через -4 миллиона циклов в будущем. Таким образом, `bar` запустится до `foo`, так как и запланировано. - -> **DF:YJ**: Примеры, использующие интерфейс `schedule` или абстракцию `Instant` -> **не будут** правильно работать на эмуляторе QEMU, поскольку счетчик циклов Cortex-M -> функционально не был реализован в `qemu-system-arm`. - -``` rust -{{#include ../../../../examples/schedule.rs}} -``` - -Запусе программы на реальном оборудовании создает следующий вывод в консоли: - -``` text -{{#include ../../../../ci/expected/schedule.run}} -``` - -Когда интерфейс `schedule` используется, среда исполнения использует внутри -обработчик прерываний `SysTick` и периферию системного таймера (`SYST`), поэтому ни -тот ни другой нельзя использовать в программе. Это гарантируется изменением типа -`init::Context.core` с `cortex_m::Peripherals` на `rtic::Peripherals`. -Последняя структура содержит все поля из предыдущей кроме `SYST`. - -## Периодические задачи - -Программные задачи имеют доступ к моменту времени `Instant`, в который они были запланированы -на выполнение переменной `scheduled`. Эта информация и интерфейс `schedule` можно использовать, -чтобы реализовать периодические задачи, как показано ниже. - -``` rust -{{#include ../../../../examples/periodic.rs}} -``` - -Это вывод, создаваемый примером. Заметьте, что здесь пристствует небольшой дрейф / колебания -даже несмотря на то, что `schedule.foo` была вызвана в *конце* `foo`. Использование -`Instant::now` вместо `scheduled` вызвало бы дрейф / колебания. - -``` text -{{#include ../../../../ci/expected/periodic.run}} -``` - -## Базовое время - -Для задач, вызываемых из `init` мы имеем точную информацию о их `scheduled` времени. -Для аппаратных задач такого времени нет, поскольку они асинхронны по природе. -Для аппаратных задач среда исполнения предоставляет время запуска (`start`), которое отражает -время, в которое обработчик прерывания будет запущен. - -Заметьте, что `start` **не** равно времени прихода события, которое вызывает задачу. -В зависимости от приоритета задачи и загрузки системы, время `start` может сильно отдалиться от -времени прихода события. - -Какое по вашему мнению будет значение `scheduled` для программных задач, которые вызываются через -`spawn` вместо планирования? Ответ в том, что вызываемые задачи наследуют -*базовое* время того контекста, который их вызывает. Базовое время аппаратных задач - -это их время `start`, базовое время программных задач - их время `scheduled`, а -базовое время `init` - время старта системы, или нулевое -(`Instant::zero()`). `idle` на самом деле не имеет базового времени, но задачи вызываемые из нее, -используют `Instant::now()` в качестве базового. - -Пример ниже демонстрирует разные смыслы *базового времени*. - -``` rust -{{#include ../../../../examples/baseline.rs}} -``` - -Запуск программы на реальном оборудовании приведет к следующему выводу в консоли: - -``` text -{{#include ../../../../ci/expected/baseline.run}} -``` diff --git a/book/ru/src/by-example/tips.md b/book/ru/src/by-example/tips.md deleted file mode 100644 index 7d4fc2f..0000000 --- a/book/ru/src/by-example/tips.md +++ /dev/null @@ -1,175 +0,0 @@ -# Советы и хитрости - -Полные примеры для RTIC смотрите в репозитарии [rtic-examples][rtic-examples]. - -[rtic-examples]: https://github.com/rtic-rs/rtic-examples - -## Обобщенное программирование (Generics) - -Все объекты, предоставляющие ресурысы реализуют трейт `rtic::Mutex`. -Если ресурс не реализует его, можно обернуть его в новый тип [`rtic::Exclusive`], -который реализует трейт `Mutex`. С помощью этого нового типа -можно написать обобщенную функцию, которая работает с обобщенным ресурсом и -вызывать его из различных задач, чтобы производить однотипные операции над -похожим множеством ресурсов. -Вот один такой пример: - -[`rtic::Exclusive`]: ../../../api/rtic/struct.Exclusive.html - -``` rust -{{#include ../../../../examples/generics.rs}} -``` - -``` console -$ cargo run --example generics -{{#include ../../../../ci/expected/generics.run}} -``` - -## Условная компиляция - -Вы можете использовать условную компиляцию (`#[cfg]`) на ресурсах (полях структуры -`#[resources] struct Resources`) и задачах (элементах `fn`). -Эффект использования атрибутов `#[cfg]` в том, что ресурс/ задача -будут *не* доступны в соответствующих структурах `Context` если условие не выполняется. - -В примере ниже выводится сообщение каждый раз, когда вызывается задача `foo`, но только -если программы скомпилирова с профилем `dev`. - -``` rust -{{#include ../../../../examples/cfg.rs}} -``` - -``` console -$ cargo run --example cfg --release - -$ cargo run --example cfg -{{#include ../../../../ci/expected/cfg.run}} -``` - -## Запуск задач из ОЗУ - -Главной целью переноса описания программы на RTIC в атрибуты в -RTIC v0.4.x была возможность взаимодействия с другими атрибутами. -Напримерe, атрибут `link_section` можно применять к задачам, чтобы разместить -их в ОЗУ; это может улучшить производительность в некоторых случаях. - -> **ВАЖНО**: Обычно атрибуты `link_section`, `export_name` и `no_mangle` -> очень мощные, но их легко использовать неправильно. Неверное использование -> любого из этих атрибутов может вызвать неопределенное поведение; -> Вам следует всегда предпочитать использование безопасных, высокоуровневых -> атрибутов вместо них, таких как атрибуты `interrupt` и `exception` -> из `cortex-m-rt`. -> -> В особых функций, размещаемых в ОЗУ нет безопасной абстракции в `cortex-m-rt` -> v0.6.5 но создано [RFC] для добавления атрибута `ramfunc` в будущем релизе. - -[RFC]: https://github.com/rust-embedded/cortex-m-rt/pull/100 - -В примере ниже показано как разместить высокоприоритетную задачу `bar` в ОЗУ. - -``` rust -{{#include ../../../../examples/ramfunc.rs}} -``` - -Запуск этой программы создаст ожидаемый вывод. - -``` console -$ cargo run --example ramfunc -{{#include ../../../../ci/expected/ramfunc.run}} -``` - -Можно посмотреть на вывод `cargo-nm`, чтобы убедиться, что `bar` расположен в ОЗУ -(`0x2000_0000`), тогда как `foo` расположен во Flash (`0x0000_0000`). - -``` console -$ cargo nm --example ramfunc --release | grep ' foo::' -{{#include ../../../../ci/expected/ramfunc.run.grep.foo}} -``` - -``` console -$ cargo nm --example ramfunc --release | grep ' bar::' -{{#include ../../../../ci/expected/ramfunc.run.grep.bar}} -``` - -## Обходной путь для быстрой передачи сообщений - -Передача сообщений всегда вызывает копирование от отправителя в -статическую переменную, а затем из статической переменной получателю. -Таким образом, при передаче большого буфера, например `[u8; 128]`, передача сообщения -вызывает два дорогих вызова `memcpy`. Чтобы минимизировать накладные расходы на передачу -сообщения, можно использовать обходной путь: вместо передачи буфера по значению, -можно передавать владеющий указатель на буфер. - -Можно использовать глобальный аллокатор, чтобы реализовать данный трюк (`alloc::Box`, -`alloc::Rc`, и т.п.), либо использовать статически аллоцируемый пул памяти, например [`heapless::Pool`]. - -[`heapless::Pool`]: https://docs.rs/heapless/0.5.0/heapless/pool/index.html - -Здесь приведен пример использования `heapless::Pool` для "упаковки" буфера из 128 байт. - -``` rust -{{#include ../../../../examples/pool.rs}} -``` - -``` console -$ cargo run --example pool -{{#include ../../../../ci/expected/pool.run}} -``` - -## Инспектирование раскрываемого кода - -`#[rtic::app]` - это процедурный макрос, который создает код. -Если по какой-то причине вам нужно увидеть код, сгенерированный этим макросом, -у вас есть два пути: - -Вы можете изучить файл `rtic-expansion.rs` внутри папки `target`. Этот файл -содержит элемент `#[rtic::app]` в раскрытом виде (не всю вашу программу!) -из *последней сборки* (с помощью `cargo build` или `cargo check`) RTIC программы. -Раскрытый код не отформатирован по-умолчанию, но вы можете запустить `rustfmt` -на нем перед тем, как читать. - -``` console -$ cargo build --example foo - -$ rustfmt target/rtic-expansion.rs - -$ tail target/rtic-expansion.rs -``` - -``` rust -#[doc = r" Implementation details"] -mod app { - #[doc = r" Always include the device crate which contains the vector table"] - use lm3s6965 as _; - #[no_mangle] - unsafe extern "C" fn main() -> ! { - rtic::export::interrupt::disable(); - let mut core: rtic::export::Peripherals = core::mem::transmute(()); - core.SCB.scr.modify(|r| r | 1 << 1); - rtic::export::interrupt::enable(); - loop { - rtic::export::wfi() - } - } -} -``` - -Или, вы можете использовать подкоманду [`cargo-expand`]. Она раскроет -*все* макросы, включая атрибут `#[rtic::app]`, и модули в вашем крейте и -напечатает вывод в консоль. - -[`cargo-expand`]: https://crates.io/crates/cargo-expand - -``` console -$ # создаст такой же вывод, как выше -$ cargo expand --example smallest | tail -``` - -## Деструктуризация ресурса - -Если задача требует нескольких ресурсов, разбиение структуры ресурсов -может улучшить читабельность. Вот два примера того, как это можно сделать: - -``` rust -{{#include ../../../../examples/destructure.rs}} -``` diff --git a/book/ru/src/by-example/types-send-sync.md b/book/ru/src/by-example/types-send-sync.md deleted file mode 100644 index 755a379..0000000 --- a/book/ru/src/by-example/types-send-sync.md +++ /dev/null @@ -1,49 +0,0 @@ -# Типы, Send и Sync - -Каждая функция в модуле `app` принимает структуру `Context` в качесте первого параметра. -Все поля этих структур имеют предсказуемые, неанонимные типы, -поэтому вы можете написать обычные функции, принимающие их как аргументы. - -Справочник по API определяет как эти типы генерируются на основе входных данных. -Вы можете также сгенерировать документацию к вашему крейту программы (`cargo doc --bin <name>`); -в документации вы найдете структуры `Context` (например `init::Context` и -`idle::Context`). - -Пример ниже показывает различные типы, сгенерированные атрибутом `app`. - -``` rust -{{#include ../../../../examples/types.rs}} -``` - -## `Send` - -[`Send`] - это маркерный трейт для "типов, которые можно передавать через границы -потоков", как это определено в `core`. В контексте RTIC трейт `Send` необходим -только там, где возможна передача значения между задачами, запускаемыми на -*разных* приоритетах. Это возникает в нескольких случаях: при передаче сообщений, -в разделяемых `static mut` ресурсах и при инициализации поздних ресурсов. - -[`Send`]: https://doc.rust-lang.org/core/marker/trait.Send.html - -Атрибут `app` проверит, что `Send` реализован, где необходимо, поэтому вам не -стоит волноваться об этом. В настоящий момент все передаваемые типы в RTIC должны быть `Send`, но -это ограничение возможно будет ослаблено в будущем. - -## `Sync` - -Аналогично, [`Sync`] - маркерный трейт для "типов, на которые можно безопасно разделять между потоками", -как это определено в `core`. В контексте RTIC типаж `Sync` необходим только там, -где возможно для двух или более задач, запускаемых на разных приоритетах получить разделяемую ссылку (`&-`) на -ресурс. Это возникает только (`&-`) ресурсах с разделяемым доступом. - -[`Sync`]: https://doc.rust-lang.org/core/marker/trait.Sync.html - -Атрибут `app` проверит, что `Sync` реализован, где необходимо, но важно знать, -где ограничение `Sync` не требуется: в (`&-`) ресурсах с разделяемым доступом, за которые -соперничают задачи с *одинаковым* приоритетом. - -В примере ниже показано, где можно использовать типы, не реализующие `Sync`. - -``` rust -{{#include ../../../../examples/not-sync.rs}} -``` diff --git a/book/ru/src/internals.md b/book/ru/src/internals.md deleted file mode 100644 index 48495b0..0000000 --- a/book/ru/src/internals.md +++ /dev/null @@ -1,14 +0,0 @@ -# Под капотом - -**Этот раздел в настоящий момент находится в разработке, -он появится снова, когда будет завершен** - -Этот раздел описывает внутренности фреймворка RTIC на *высоком уровне*. -Низкоуровневые детали, такие как парсинг и генерация кода, выполняемые процедурным макросом -(`#[app]`) объясняться не будут. Внимание будет сосредоточено на анализе -спецификации пользователя и структурах данных, используемых на этапе выполнения. - -Мы настоятельно рекомендуем вам прочитать раздел о [конкуренции] в embedonomicon -перед тем, как погружаться в материал. - -[конкуренции]: https://github.com/rust-embedded/embedonomicon/pull/48 diff --git a/book/ru/src/internals/access.md b/book/ru/src/internals/access.md deleted file mode 100644 index ea073a4..0000000 --- a/book/ru/src/internals/access.md +++ /dev/null @@ -1,158 +0,0 @@ -# Контроль доступа - -Одна из основ RTIC - контроль доступа. Контроль того, какая часть программы -может получить доступ к какой статической переменной - инструмент обеспечения -безопасности памяти. - -Статические переменные используются для разделения состояний между обработчиками -прерываний, или между обработчиком прерывания и нижним контекстом выполнения, `main`. -В обычном Rust коде трудно обеспечить гранулированный контроль за тем, какие функции -могут получать доступ к статическим переменным, поскольку к статическим переменным -можно получить доступ из любой функции, находящейся в той же области видимости, -в которой они определены. Модули дают частичный контроль над доступом -к статическим переменным, но они недостаточно гибкие. - -Чтобы добиться полного контроля за тем, что задачи могут получить доступ -только к статическим переменным (ресурсам), которые им были указаны в RTIC атрибуте, -фреймворк RTIC производит трансформацию структуры кода. -Эта трансформация состоит из размещения ресурсов (статических переменных), определенных -пользователем *внутри* модуля, а пользовательского кода *вне* модуля. -Это делает невозможным обращение пользовательского кода к статическим переменным. - -Затем доступ к ресурсам предоставляется каждой задаче с помощью структуры `Resources`, -чьи поля соответствуют ресурсам, к которым получает доступ задача. -Есть лишь одна такая структура на задачу и структура `Resources` инициализируется -либо уникальной ссылкой (`&mut-`) на статическую переменную, либо с помощью прокси-ресурса (см. -раздел [критические секции](critical-sections.html)). - -Код ниже - пример разных трансформаций структуры кода, происходящих за сценой: - -``` rust -#[rtic::app(device = ..)] -mod app { - static mut X: u64: 0; - static mut Y: bool: 0; - - #[init(resources = [Y])] - fn init(c: init::Context) { - // .. пользовательский код .. - } - - #[interrupt(binds = UART0, resources = [X])] - fn foo(c: foo::Context) { - // .. пользовательский код .. - } - - #[interrupt(binds = UART1, resources = [X, Y])] - fn bar(c: bar::Context) { - // .. пользовательский код .. - } - - // .. -} -``` - -Фреймворк создает код, подобный этому: - -``` rust -fn init(c: init::Context) { - // .. пользовательский код .. -} - -fn foo(c: foo::Context) { - // .. пользовательский код .. -} - -fn bar(c: bar::Context) { - // .. пользовательский код .. -} - -// Публичное API -pub mod init { - pub struct Context<'a> { - pub resources: Resources<'a>, - // .. - } - - pub struct Resources<'a> { - pub Y: &'a mut bool, - } -} - -pub mod foo { - pub struct Context<'a> { - pub resources: Resources<'a>, - // .. - } - - pub struct Resources<'a> { - pub X: &'a mut u64, - } -} - -pub mod bar { - pub struct Context<'a> { - pub resources: Resources<'a>, - // .. - } - - pub struct Resources<'a> { - pub X: &'a mut u64, - pub Y: &'a mut bool, - } -} - -/// Детали реализации -mod app { - // все, что внутри этого модуля спрятано от пользовательского кода - - static mut X: u64 = 0; - static mut Y: bool = 0; - - // настоящая точка входа в программу - unsafe fn main() -> ! { - interrupt::disable(); - - // .. - - // вызов пользовательского кода; передача ссылок на статические переменные - init(init::Context { - resources: init::Resources { - X: &mut X, - }, - // .. - }); - - // .. - - interrupt::enable(); - - // .. - } - - // обработчик прерывания,с которым связан `foo` - #[no_mangle] - unsafe fn UART0() { - // вызов пользовательского кода; передача ссылок на статические переменные - foo(foo::Context { - resources: foo::Resources { - X: &mut X, - }, - // .. - }); - } - - // обработчик прерывания,с которым связан `bar` - #[no_mangle] - unsafe fn UART1() { - // вызов пользовательского кода; передача ссылок на статические переменные - bar(bar::Context { - resources: bar::Resources { - X: &mut X, - Y: &mut Y, - }, - // .. - }); - } -} -``` diff --git a/book/ru/src/internals/ceilings.md b/book/ru/src/internals/ceilings.md deleted file mode 100644 index df9901a..0000000 --- a/book/ru/src/internals/ceilings.md +++ /dev/null @@ -1,92 +0,0 @@ -# Анализ приоритетов - -*Поиск максимального приоритета* ресурса (*ceiling*) - поиск динамического -приоритета, который любая задача должна иметь, чтобы безопасно работать с -памятью ресурсов. Анализ приоритетов - относительно прост, -но критичен для безопасности памяти RTIC программ. - -Для расчета максимального приоритета ресурса мы должны сначала составить -список задач, имеющих доступ к ресурсу -- так как фреймворк RTIC -форсирует контроль доступа к ресурсам на этапе компиляции, он -также имеет доступ к этой информации на этапе компиляции. -Максимальный приоритет ресурса - просто наивысший логический приоритет -среди этих задач. - -`init` и `idle` не настоящие задачи, но у них есть доступ к ресурсам, -поэтому они должны учитываться при анализе приоритетов. -`idle` учитывается как задача, имеющая логический приоритет `0`, -в то время как `init` полностью исключается из анализа -- -причина этому в том, что `init` никогда не использует (не нуждается) критические -секции для доступа к статическим переменным. - -В предыдущем разделе мы показывали, что разделяемые ресусы -могут быть представлены уникальными ссылками (`&mut-`) или скрываться за -прокси в зависимости от того, имеет ли задача к ним доступ. -Какой из вариантов представляется задаче зависит от приоритета задачи и -максимального приоритета ресурса. -Если приоритет задачи такой же, как максимальный приоритет ресурса, тогда -задача получает уникальную ссылку (`&mut-`) на память ресурса, -в противном случае задача получает прокси -- это также касается `idle`. -`init` особеннвй: он всегда получает уникальные ссылки (`&mut-`) на ресурсы. - -Пример для иллюстрации анализа приоритетов: - -``` rust -#[rtic::app(device = ..)] -mod app { - struct Resources { - // доступен из `foo` (prio = 1) и `bar` (prio = 2) - // -> CEILING = 2 - #[init(0)] - x: u64, - - // доступен из `idle` (prio = 0) - // -> CEILING = 0 - #[init(0)] - y: u64, - } - - #[init(resources = [x])] - fn init(c: init::Context) { - // уникальная ссылка, потому что это `init` - let x: &mut u64 = c.resources.x; - - // уникальная ссылка, потому что это `init` - let y: &mut u64 = c.resources.y; - - // .. - } - - // PRIORITY = 0 - #[idle(resources = [y])] - fn idle(c: idle::Context) -> ! { - // уникальная ссылка, потому что - // приоритет (0) == максимальному приоритету ресурса (0) - let y: &'static mut u64 = c.resources.y; - - loop { - // .. - } - } - - #[interrupt(binds = UART0, priority = 1, resources = [x])] - fn foo(c: foo::Context) { - // прокси-ресурс, потому что - // приоритет задач (1) < максимальному приоритету ресурса (2) - let x: resources::x = c.resources.x; - - // .. - } - - #[interrupt(binds = UART1, priority = 2, resources = [x])] - fn bar(c: foo::Context) { - // уникальная ссылка, потому что - // приоритет задачи (2) == максимальному приоритету ресурса (2) - let x: &mut u64 = c.resources.x; - - // .. - } - - // .. -} -``` diff --git a/book/ru/src/internals/critical-sections.md b/book/ru/src/internals/critical-sections.md deleted file mode 100644 index e4c3d0a..0000000 --- a/book/ru/src/internals/critical-sections.md +++ /dev/null @@ -1,521 +0,0 @@ -# Критические секции - -Когда ресурсы (статические переменные) разделяются между двумя или более задачами, -которые выполняются с разными приоритетами, некая форма запрета изменений -необходима, чтобы изменять память без гонки данных. В RTIC мы используем -основанные на приоритетах критические секции, чтобы гарантировать запрет изменений -(см. [Протокол немедленного максимального приоритета][icpp]). - -[icpp]: https://en.wikipedia.org/wiki/Priority_ceiling_protocol - -Критическия секция состоит во временном увеличении *динамического* приоритета задачи. -Пока задача находится в критической секции, все другие задачи, которые могут -послать запрос переменной *не могут запуститься*. - -Насколько большим должен быть динамический приориткт, чтобы гарантировать запрет изменений -определенного ресурса? [Анализ приоритетов](ceilings.html) отвечает на этот вопрос -и будет обсужден в следующем разделе. В этом разделе мы сфокусируемся -на реализации критической секции. - -## Прокси-ресурсы - -Для упрощения, давайте взглянем на ресурс, разделяемый двумя задачами, -запускаемыми с разными приоритетами. Очевидно, что одна задача может вытеснить -другую; чтобы предотвратить гонку данных задача с *низким приоритетом* должна -использовать критическую секцию, когда необходимо изменять разделяемую память. -С другой стороны, высокоприоритетная задача может напрямую изменять -разделяемую память, поскольку не может быть вытеснена низкоприоритетной задачей. -Чтобы заставить использовать критическую секцию на задаче с низким приоритетом, -мы предоставляем *прокси-ресурсы*, в которых мы отдаем уникальную ссылку -(`&mut-`) высокоприоритетной задаче. - -Пример ниже показывает разные типы, передаваемые каждой задаче: - -``` rust -#[rtic::app(device = ..)] -mut app { - struct Resources { - #[init(0)] - x: u64, - } - - #[interrupt(binds = UART0, priority = 1, resources = [x])] - fn foo(c: foo::Context) { - // прокси-ресурс - let mut x: resources::x = c.resources.x; - - x.lock(|x: &mut u64| { - // критическая секция - *x += 1 - }); - } - - #[interrupt(binds = UART1, priority = 2, resources = [x])] - fn bar(c: bar::Context) { - let mut x: &mut u64 = c.resources.x; - - *x += 1; - } - - // .. -} -``` - -Теперь давайте посмотрим. как эти типы создаются фреймворком. - -``` rust -fn foo(c: foo::Context) { - // .. пользовательский код .. -} - -fn bar(c: bar::Context) { - // .. пользовательский код .. -} - -pub mod resources { - pub struct x { - // .. - } -} - -pub mod foo { - pub struct Resources { - pub x: resources::x, - } - - pub struct Context { - pub resources: Resources, - // .. - } -} - -pub mod bar { - pub struct Resources<'a> { - pub x: &'a mut u64, - } - - pub struct Context { - pub resources: Resources, - // .. - } -} - -mod app { - static mut x: u64 = 0; - - impl rtic::Mutex for resources::x { - type T = u64; - - fn lock<R>(&mut self, f: impl FnOnce(&mut u64) -> R) -> R { - // мы рассмотрим это детально позднее - } - } - - #[no_mangle] - unsafe fn UART0() { - foo(foo::Context { - resources: foo::Resources { - x: resources::x::new(/* .. */), - }, - // .. - }) - } - - #[no_mangle] - unsafe fn UART1() { - bar(bar::Context { - resources: bar::Resources { - x: &mut x, - }, - // .. - }) - } -} -``` - -## `lock` - -Теперь давайте рассмотрим непосредственно критическую секцию. В этом примере мы должны -увеличить динамический приоритет минимум до `2`, чтобы избежать гонки данных. -В архитектуре Cortex-M динамический приоритет можно изменить записью в регистр `BASEPRI`. - -Семантика регистра `BASEPRI` такова: - -- Запись `0` в `BASEPRI` отключает его функциональность. -- Запись ненулевого значения в `BASEPRI` изменяет уровень приоритета, требуемого для - вытеснения прерывания. Однако, это имеет эффект, только когда записываемое значение - *меньше*, чем уровень приоритета текущего контекста выполнения, но обращаем внимание, что - более низкий уровень аппаратного приоритета означает более высокий логический приоритет - -Таким образом, динамический приоритет в любой момент времени может быть рассчитан как - -``` rust -dynamic_priority = max(hw2logical(BASEPRI), hw2logical(static_priority)) -``` - -Где `static_priority` - приоритет, запрограммированный в NVIC для текущего прерывания, -или логический `0`, когда текущий контекств - это `idle`. - -В этом конкретном примере мы можем реализовать критическую секцию так: - -> **ПРИМЕЧАНИЕ:** это упрощенная реализация - -``` rust -impl rtic::Mutex for resources::x { - type T = u64; - - fn lock<R, F>(&mut self, f: F) -> R - where - F: FnOnce(&mut u64) -> R, - { - unsafe { - // начать критическую секцию: увеличить динамический приоритет до `2` - asm!("msr BASEPRI, 192" : : : "memory" : "volatile"); - - // запустить пользовательский код в критической секции - let r = f(&mut x); - - // окончить критическую секцию: восстановить динамический приоритет до статического значения (`1`) - asm!("msr BASEPRI, 0" : : : "memory" : "volatile"); - - r - } - } -} -``` - -В данном случае важно указать `"memory"` в блоке `asm!`. -Это не даст компилятору менять местами операции вокруг него. -Это важно, поскольку доступ к переменной `x` вне критической секции привело бы -к гонке данных. - -Важно отметить, что сигнатура метода `lock` препятствет его вложенным вызовам. -Это необходимо для безопасности памяти, так как вложенные вызовы привели бы -к созданию множественных уникальных ссылок (`&mut-`) на `x`, ломая правила заимствования Rust. -Смотреть ниже: - -``` rust -#[interrupt(binds = UART0, priority = 1, resources = [x])] -fn foo(c: foo::Context) { - // resource proxy - let mut res: resources::x = c.resources.x; - - res.lock(|x: &mut u64| { - res.lock(|alias: &mut u64| { - //~^ ошибка: `res` уже был заимствован уникально (`&mut-`) - // .. - }); - }); -} -``` - -## Вложенность - -Вложенные вызовы `lock` на *том же* ресурсе должны отклоняться компилятором -для безопасности памяти, однако вложенные вызовы `lock` на *разных* ресурсах - -нормальная операция. В этом случае мы хотим убедиться, что вложенные критические секции -никогда не приведут к понижению динамического приоритета, так как это плохо, -и мы хотим оптимизировать несколько записей в регистр `BASEPRI` и compiler fences. -Чтобы справиться с этим, мы проследим динамический приоритет задачи, с помощью стековой -переменной и используем ее, чтобы решить, записывать `BASEPRI` или нет. -На практике, стековая переменная будет соптимизирована компилятором, но все еще -будет предоставлять информацию компилятору. - -Рассмотрим такую программу: - -``` rust -#[rtic::app(device = ..)] -mod app { - struct Resources { - #[init(0)] - x: u64, - #[init(0)] - y: u64, - } - - #[init] - fn init() { - rtic::pend(Interrupt::UART0); - } - - #[interrupt(binds = UART0, priority = 1, resources = [x, y])] - fn foo(c: foo::Context) { - let mut x = c.resources.x; - let mut y = c.resources.y; - - y.lock(|y| { - *y += 1; - - *x.lock(|x| { - x += 1; - }); - - *y += 1; - }); - - // середина - - x.lock(|x| { - *x += 1; - - y.lock(|y| { - *y += 1; - }); - - *x += 1; - }) - } - - #[interrupt(binds = UART1, priority = 2, resources = [x])] - fn bar(c: foo::Context) { - // .. - } - - #[interrupt(binds = UART2, priority = 3, resources = [y])] - fn baz(c: foo::Context) { - // .. - } - - // .. -} -``` - -Код, сгенерированный фреймворком, выглядит так: - -``` rust -// опущено: пользовательский код - -pub mod resources { - pub struct x<'a> { - priority: &'a Cell<u8>, - } - - impl<'a> x<'a> { - pub unsafe fn new(priority: &'a Cell<u8>) -> Self { - x { priority } - } - - pub unsafe fn priority(&self) -> &Cell<u8> { - self.priority - } - } - - // repeat for `y` -} - -pub mod foo { - pub struct Context { - pub resources: Resources, - // .. - } - - pub struct Resources<'a> { - pub x: resources::x<'a>, - pub y: resources::y<'a>, - } -} - -mod app { - use cortex_m::register::basepri; - - #[no_mangle] - unsafe fn UART1() { - // статический приоритет прерывания (определено пользователем) - const PRIORITY: u8 = 2; - - // сделать снимок BASEPRI - let initial = basepri::read(); - - let priority = Cell::new(PRIORITY); - bar(bar::Context { - resources: bar::Resources::new(&priority), - // .. - }); - - // вернуть BASEPRI значение из снимка, сделанного ранее - basepri::write(initial); // то же, что и `asm!` блок, виденный ранее - } - - // так же для `UART0` / `foo` и `UART2` / `baz` - - impl<'a> rtic::Mutex for resources::x<'a> { - type T = u64; - - fn lock<R>(&mut self, f: impl FnOnce(&mut u64) -> R) -> R { - unsafe { - // определение максимального приоритет ресурса - const CEILING: u8 = 2; - - let current = self.priority().get(); - if current < CEILING { - // увеличить динамический приоритет - self.priority().set(CEILING); - basepri::write(logical2hw(CEILING)); - - let r = f(&mut y); - - // восстановить динамический приоритет - basepri::write(logical2hw(current)); - self.priority().set(current); - - r - } else { - // динамический приоритет достаточно высок - f(&mut y) - } - } - } - } - - // повторить для ресурса `y` -} -``` - -Наконец, компилятор оптимизирует функцию `foo` во что-то наподобие такого: - -``` rust -fn foo(c: foo::Context) { - // ПРИМЕЧАНИЕ: BASEPRI содержит значение `0` (значение сброса) в этот момент - - // увеличить динамический приоритет до `3` - unsafe { basepri::write(160) } - - // две операции над `y` объединены в одну - y += 2; - - // BASEPRI не изменяется для доступа к `x`, потому что динамический приоритет достаточно высок - x += 1; - - // уменьшить (восстановить) динамический приоритет до `1` - unsafe { basepri::write(224) } - - // средина - - // увеличить динамический приоритет до `2` - unsafe { basepri::write(192) } - - x += 1; - - // увеличить динамический приоритет до `3` - unsafe { basepri::write(160) } - - y += 1; - - // уменьшить (восстановить) динамический приоритет до `2` - unsafe { basepri::write(192) } - - // ПРИМЕЧАНИЕ: было вы правильно объединить эту операцию над `x` с предыдущей, но - // compiler fences грубые и предотвращают оптимизацию - x += 1; - - // уменьшить (восстановить) динамический приоритет до `1` - unsafe { basepri::write(224) } - - // ПРИМЕЧАНИЕ: BASEPRI содержит значение `224` в этот момент - // обработчик UART0 восстановит значение `0` перед завершением -} -``` - -## Инвариант BASEPRI - -Инвариант, который фреймворк RTIC должен сохранять в том, что значение -BASEPRI в начале обработчика *прерывания* должно быть таким же, как и при выходе -из него. BASEPRI может изменяться в процессе выполнения обработчика прерывания, -но но выполнения обработчика прерывания в начале и конце не должно вызвать -наблюдаемого изменения BASEPRI. - -Этот инвариант нужен, чтобы избежать уеличения динамического приоритета до значений, -при которых обработчик не сможет быть вытеснен. Лучше всего это видно на следующем примере: - -``` rust -#[rtic::app(device = ..)] -mod app { - struct Resources { - #[init(0)] - x: u64, - } - - #[init] - fn init() { - // `foo` запустится сразу после завершения `init` - rtic::pend(Interrupt::UART0); - } - - #[task(binds = UART0, priority = 1)] - fn foo() { - // BASEPRI равен `0` в этот момент; динамический приоритет равен `1` - - // `bar` вытеснит `foo` в этот момент - rtic::pend(Interrupt::UART1); - - // BASEPRI равен `192` в этот момент (из-за бага); динамический приоритет равен `2` - // эта функция возвращается в `idle` - } - - #[task(binds = UART1, priority = 2, resources = [x])] - fn bar() { - // BASEPRI равен `0` (динамический приоритет = 2) - - x.lock(|x| { - // BASEPRI увеличен до `160` (динамический приоритет = 3) - - // .. - }); - - // BASEPRI восстановлен до `192` (динамический приоритет = 2) - } - - #[idle] - fn idle() -> ! { - // BASEPRI равен `192` (из-за бага); динамический приоритет = 2 - - // это не оказывает эффекта, из-за значени BASEPRI - // задача `foo` не будет выполнена снова никогда - rtic::pend(Interrupt::UART0); - - loop { - // .. - } - } - - #[task(binds = UART2, priority = 3, resources = [x])] - fn baz() { - // .. - } - -} -``` - -ВАЖНО: давайте например мы *забудем* восстановить `BASEPRI` в `UART1` -- из-за -какого нибудь бага в генераторе кода RTIC. - -``` rust -// код, сгенерированный RTIC - -mod app { - // .. - - #[no_mangle] - unsafe fn UART1() { - // статический приоритет этого прерывания (определен пользователем) - const PRIORITY: u8 = 2; - - // сделать снимок BASEPRI - let initial = basepri::read(); - - let priority = Cell::new(PRIORITY); - bar(bar::Context { - resources: bar::Resources::new(&priority), - // .. - }); - - // БАГ: ЗАБЫЛИ восстановить BASEPRI на значение из снимка - basepri::write(initial); - } -} -``` - -В результате, `idle` запустится на динамическом приоритете `2` и на самом деле -система больше никогда не перейдет на динамический приоритет ниже `2`. -Это не компромис для безопасности памяти программы, а влияет на диспетчеризацию задач: -в этом конкретном случае задачи с приоритетом `1` никогда не получат шанс на запуск. diff --git a/book/ru/src/internals/interrupt-configuration.md b/book/ru/src/internals/interrupt-configuration.md deleted file mode 100644 index 5631b37..0000000 --- a/book/ru/src/internals/interrupt-configuration.md +++ /dev/null @@ -1,72 +0,0 @@ -# Настройка прерываний - -Прерывания - это основа работы программ на RTIC. Правильно настроить приоритеты -прерываний и убедиться, что они не изменяются во время выполнения обязательно -для безопасной работы программы. - -Фреймворк RTIC представляет приоритеты прерываний, как нечто, что должно быть определено -на этапе компиляции. Однако, статическая настройка должна быть зашита в соответствующие регистры -в процессе инициализации программы. Настройка прерываний происходит до запуска функции `init`. - -Этот пример дает представление о коде, запускаемом фреймворком RTIC: - -``` rust -#[rtic::app(device = lm3s6965)] -mod app { - #[init] - fn init(c: init::Context) { - // .. пользовательский код .. - } - - #[idle] - fn idle(c: idle::Context) -> ! { - // .. пользовательский код .. - } - - #[interrupt(binds = UART0, priority = 2)] - fn foo(c: foo::Context) { - // .. пользовательский код .. - } -} -``` - -Фреймворк генерирует точку входа в программу, которая выглядит примерно так: - -``` rust -// настоящая точку входа в программу -#[no_mangle] -unsafe fn main() -> ! { - // преобразует логические приоритеты в аппаратные / NVIC приоритеты - fn logical2hw(priority: u8) -> u8 { - use lm3s6965::NVIC_PRIO_BITS; - - // NVIC кодирует приоритеты верхними битами - // большие значения обозначают меньший приоритет - ((1 << NVIC_PRIORITY_BITS) - priority) << (8 - NVIC_PRIO_BITS) - } - - cortex_m::interrupt::disable(); - - let mut core = cortex_m::Peripheral::steal(); - - core.NVIC.enable(Interrupt::UART0); - - // значение, определенное пользователем - let uart0_prio = 2; - - // проверка на этапе компиляции, что определенный приоритет входит в поддерживаемый диапазон - let _ = [(); (1 << NVIC_PRIORITY_BITS) - (uart0_prio as usize)]; - - core.NVIC.set_priority(Interrupt::UART0, logical2hw(uart0_prio)); - - // вызов пользовательского кода - init(/* .. */); - - // .. - - cortex_m::interrupt::enable(); - - // вызов пользовательского кода - idle(/* .. */) -} -``` diff --git a/book/ru/src/internals/late-resources.md b/book/ru/src/internals/late-resources.md deleted file mode 100644 index 146c438..0000000 --- a/book/ru/src/internals/late-resources.md +++ /dev/null @@ -1,113 +0,0 @@ -# Поздние ресурсы - -Некоторые ресурсы инициализируются во время выполнения после завершения функции `init`. -Важно то, что ресурсы (статические переменные) полностью инициализируются -до того, как задачи смогут запуститься, вот почему они должны быть инициализированы -пока прерывания отключены. - -Ниже показан пример кода, генерируемого фреймворком для инициализации позних ресурсов. - -``` rust -#[rtic::app(device = ..)] -mod app { - struct Resources { - x: Thing, - } - - #[init] - fn init() -> init::LateResources { - // .. - - init::LateResources { - x: Thing::new(..), - } - } - - #[task(binds = UART0, resources = [x])] - fn foo(c: foo::Context) { - let x: &mut Thing = c.resources.x; - - x.frob(); - - // .. - } - - // .. -} -``` - -Код, генерируемы фреймворком выглядит примерно так: - -``` rust -fn init(c: init::Context) -> init::LateResources { - // .. пользовательский код .. -} - -fn foo(c: foo::Context) { - // .. пользовательский код .. -} - -// Public API -pub mod init { - pub struct LateResources { - pub x: Thing, - } - - // .. -} - -pub mod foo { - pub struct Resources<'a> { - pub x: &'a mut Thing, - } - - pub struct Context<'a> { - pub resources: Resources<'a>, - // .. - } -} - -/// Детали реализации -mod app { - // неинициализированная статическая переменная - static mut x: MaybeUninit<Thing> = MaybeUninit::uninit(); - - #[no_mangle] - unsafe fn main() -> ! { - cortex_m::interrupt::disable(); - - // .. - - let late = init(..); - - // инициализация поздних ресурсов - x.as_mut_ptr().write(late.x); - - cortex_m::interrupt::enable(); //~ compiler fence - - // исключения, прерывания и задачи могут вытеснить `main` в этой точке - - idle(..) - } - - #[no_mangle] - unsafe fn UART0() { - foo(foo::Context { - resources: foo::Resources { - // `x` уже инициализирована к этому моменту - x: &mut *x.as_mut_ptr(), - }, - // .. - }) - } -} -``` - -Важная деталь здесь то, что `interrupt::enable` ведет себя как *барьер компиляции*, который не дает компилятору переставить запись в `X` *после* -`interrupt::enable`. Если бы компилятор мог делать такие перестановки появились -бы гонки данных между этой записью и любой операцией `foo`, взаимодействующей с `X`. - -Архитектурам с более сложным конвейером инструкций нужен барьер памяти -(`atomic::fence`) вместо compiler fence для полной очистки операции записи -перед включением прерываний. Архитектура ARM Cortex-M не нуждается в барьере памяти -в одноядерном контексте. diff --git a/book/ru/src/internals/non-reentrancy.md b/book/ru/src/internals/non-reentrancy.md deleted file mode 100644 index 98eb00f..0000000 --- a/book/ru/src/internals/non-reentrancy.md +++ /dev/null @@ -1,79 +0,0 @@ -# Нереентерабельность - -В RTIC задачи-обработчики *не* могут использоваться повторно. Переиспользование задачи-обработчика -может сломать правила заимствования Rust и привести к *неопределенному поведению*. -Задача-обработчик теоретически может быть переиспользована одним из двух способов: программно или аппаратно. - -## Программно - -Чтобы переиспользовать задачу-обработчик программно, назначенный ей обработчик прерывания -должен быть вызван с помощью FFI (смотрите пример ниже). FFI требует `unsafe` код, -что уменьшает желание конечных пользователей вызывать обработчик прерывания. - -``` rust -#[rtic::app(device = ..)] -mod app { - #[init] - fn init(c: init::Context) { .. } - - #[interrupt(binds = UART0)] - fn foo(c: foo::Context) { - static mut X: u64 = 0; - - let x: &mut u64 = X; - - // .. - - //~ `bar` может вытеснить `foo` в этом месте - - // .. - } - - #[interrupt(binds = UART1, priority = 2)] - fn bar(c: foo::Context) { - extern "C" { - fn UART0(); - } - - // этот обработчик прерывания вызовет задачу-обработчик `foo`, что сломает - // ссылку на статическую переменную `X` - unsafe { UART0() } - } -} -``` - -Фреймворк RTIC должен сгенерировать код обработчика прерывания, который вызывает -определенные пользователем задачи-обработчики. Мы аккуратны в том, чтобы обеспечить -невозможность вызова этих обработчиков из пользовательского кода. - -Пример выше раскрывается в: - -``` rust -fn foo(c: foo::Context) { - // .. пользовательский код .. -} - -fn bar(c: bar::Context) { - // .. пользовательский код .. -} - -mod app { - // все в этом блоке невидимо для пользовательского кода - - #[no_mangle] - unsafe fn USART0() { - foo(..); - } - - #[no_mangle] - unsafe fn USART1() { - bar(..); - } -} -``` - -## Аппаратно - -Обработчик прерывания также может быть вызван без программного вмешательства. -Это может произойти, если один обработчик будет назначен двум или более прерываниям -в векторе прерываний, но синтаксиса для такого рода функциональности в RTIC нет. diff --git a/book/ru/src/internals/tasks.md b/book/ru/src/internals/tasks.md deleted file mode 100644 index 01380ba..0000000 --- a/book/ru/src/internals/tasks.md +++ /dev/null @@ -1,399 +0,0 @@ -# Программные задачи - -RTIC поддерживает программные и аппаратные задачи. Каждая аппаратная задача -назначается на отдельный обработчик прерывания. С другой стороны, несколько -программных задач могут управляться одним обработчиком прерывания -- -это сделано, чтобы минимизировать количество обработчиков прерывания, -используемых фреймворком. - -Фреймворк группирует задачи, для которых вызывается `spawn` по уровню приоритета, -и генерирует один *диспетчер задачи* для каждого уровня приоритета. -Каждый диспетчер запускается на отдельном обработчике прерывания, -а приоритет этого обработчика прерывания устанавливается так, чтобы соответствовать -уровню приоритета задач, управляемых диспетчером. - -Каждый диспетчер задач хранит *очередь* задач, *готовых* к выполнению; -эта очередь называется *очередью готовности*. Вызов программной задачи состоит -из добавления записи в очередь и вызова прерывания, который запускает соответствующий -диспетчер задач. Каждая запись в эту очередь содержит метку (`enum`), -которая идентифицирует задачу, которую необходимо выполнить и *указатель* -на сообщение, передаваемое задаче. - -Очередь готовности - неблокируемая очередь типа SPSC (один производитель - один потребитель). -Диспетчер задач владеет конечным потребителем в очереди; конечным производителем -считается ресурс, за который соперничают задачи, которые могут вызывать (`spawn`) другие задачи. - -## Дисметчер задач - -Давайте сначала глянем на код, генерируемый фреймворком для диспетчеризации задач. -Рассмотрим пример: - -``` rust -#[rtic::app(device = ..)] -mod app { - // .. - - #[interrupt(binds = UART0, priority = 2, spawn = [bar, baz])] - fn foo(c: foo::Context) { - foo.spawn.bar().ok(); - - foo.spawn.baz(42).ok(); - } - - #[task(capacity = 2, priority = 1)] - fn bar(c: bar::Context) { - // .. - } - - #[task(capacity = 2, priority = 1, resources = [X])] - fn baz(c: baz::Context, input: i32) { - // .. - } - - extern "C" { - fn UART1(); - } -} -``` - -Фреймворк создает следующий диспетчер задач, состоящий из обработчика прерывания и очереди готовности: - -``` rust -fn bar(c: bar::Context) { - // .. пользовательский код .. -} - -mod app { - use heapless::spsc::Queue; - use cortex_m::register::basepri; - - struct Ready<T> { - task: T, - // .. - } - - /// вызываемые (`spawn`) задачи, выполняющиеся с уровнем приоритета `1` - enum T1 { - bar, - baz, - } - - // очередь готовности диспетчера задач - // `5-1=4` - представляет собой емкость этой очереди - static mut RQ1: Queue<Ready<T1>, 5> = Queue::new(); - - // обработчик прерывания, выбранный для диспетчеризации задач с приоритетом `1` - #[no_mangle] - unsafe UART1() { - // приоритет данного обработчика прерывания - const PRIORITY: u8 = 1; - - let snapshot = basepri::read(); - - while let Some(ready) = RQ1.split().1.dequeue() { - match ready.task { - T1::bar => { - // **ПРИМЕЧАНИЕ** упрощенная реализация - - // используется для отслеживания динамического приоритета - let priority = Cell::new(PRIORITY); - - // вызов пользовательского кода - bar(bar::Context::new(&priority)); - } - - T1::baz => { - // рассмотрим `baz` позднее - } - } - } - - // инвариант BASEPRI - basepri::write(snapshot); - } -} -``` - -## Вызов задачи - -Интерфейс `spawn` предоставлен пользователю как методы структурв `Spawn`. -Для каждой задачи существует своя структура `Spawn`. - -Код `Spawn`, генерируемый фреймворком для предыдущего примера выглядит так: - -``` rust -mod foo { - // .. - - pub struct Context<'a> { - pub spawn: Spawn<'a>, - // .. - } - - pub struct Spawn<'a> { - // отслеживает динамический приоритет задачи - priority: &'a Cell<u8>, - } - - impl<'a> Spawn<'a> { - // `unsafe` и спрятано, поскольку сы не хотит, чтобы пользователь вмешивался сюда - #[doc(hidden)] - pub unsafe fn priority(&self) -> &Cell<u8> { - self.priority - } - } -} - -mod app { - // .. - - // Поиск максимального приоритета для конечного производителя `RQ1` - const RQ1_CEILING: u8 = 2; - - // используется, чтобы отследить сколько еще сообщений для `bar` можно поставить в очередь - // `3-1=2` - емкость задачи `bar`; максимум 2 экземпляра можно добавить в очередь - // эта очередь заполняется фреймворком до того, как запустится `init` - static mut bar_FQ: Queue<(), 3> = Queue::new(); - - // Поиск максимального приоритета для конечного потребителя `bar_FQ` - const bar_FQ_CEILING: u8 = 2; - - // приоритет-ориентированная критическая секция - // - // это запускае переданное замыкание `f` с динамическим приоритетом не ниже - // `ceiling` - fn lock(priority: &Cell<u8>, ceiling: u8, f: impl FnOnce()) { - // .. - } - - impl<'a> foo::Spawn<'a> { - /// Вызывает задачу `bar` - pub fn bar(&self) -> Result<(), ()> { - unsafe { - match lock(self.priority(), bar_FQ_CEILING, || { - bar_FQ.split().1.dequeue() - }) { - Some(()) => { - lock(self.priority(), RQ1_CEILING, || { - // помещаем задачу в очередь готовности - RQ1.split().1.enqueue_unchecked(Ready { - task: T1::bar, - // .. - }) - }); - - // вызываем прерывание, которое запускает диспетчер задач - rtic::pend(Interrupt::UART0); - } - - None => { - // достигнута максимальная вместительность; неудачный вызов - Err(()) - } - } - } - } - } -} -``` - -Использование `bar_FQ` для ограничения числа задач `bar`, которые могут бы вызваны, -может показаться искусственным, но это будет иметь больше смысла, когда мы поговорим -о вместительности задач. - -## Сообщения - -Мы пропустили, как на самом деле работает передача сообщений, поэтому давайте вернемся -к реализации `spawn`, но в этот раз для задачи `baz`, которая принимает сообщение типа `u64`. - -``` rust -fn baz(c: baz::Context, input: u64) { - // .. пользовательский код .. -} - -mod app { - // .. - - // Теперь мы покажем все содержимое структуры `Ready` - struct Ready { - task: Task, - // индекс сообщения; используется с буфером `INPUTS` - index: u8, - } - - // память, зарезервированная для хранения сообщений, переданных `baz` - static mut baz_INPUTS: [MaybeUninit<u64>; 2] = - [MaybeUninit::uninit(), MaybeUninit::uninit()]; - - // список свободной памяти: используется для отслеживания свободных ячеек в массиве `baz_INPUTS` - // эта очередь инициализируется значениями `0` и `1` перед запуском `init` - static mut baz_FQ: Queue<u8, 3> = Queue::new(); - - // Поиск максимального приоритета для конечного потребителя `baz_FQ` - const baz_FQ_CEILING: u8 = 2; - - impl<'a> foo::Spawn<'a> { - /// Spawns the `baz` task - pub fn baz(&self, message: u64) -> Result<(), u64> { - unsafe { - match lock(self.priority(), baz_FQ_CEILING, || { - baz_FQ.split().1.dequeue() - }) { - Some(index) => { - // ПРИМЕЧАНИЕ: `index` - владеющий указатель на ячейку буфера - baz_INPUTS[index as usize].write(message); - - lock(self.priority(), RQ1_CEILING, || { - // помещаем задачу в очередь готовности - RQ1.split().1.enqueue_unchecked(Ready { - task: T1::baz, - index, - }); - }); - - // вызываем прерывание, которое запускает диспетчер задач - rtic::pend(Interrupt::UART0); - } - - None => { - // достигнута максимальная вместительность; неудачный вызов - Err(message) - } - } - } - } - } -} -``` - -А теперь давайте взглянем на настоящую реализацию диспетчера задач: - -``` rust -mod app { - // .. - - #[no_mangle] - unsafe UART1() { - const PRIORITY: u8 = 1; - - let snapshot = basepri::read(); - - while let Some(ready) = RQ1.split().1.dequeue() { - match ready.task { - Task::baz => { - // ПРИМЕЧАНИЕ: `index` - владеющий указатель на ячейку буфера - let input = baz_INPUTS[ready.index as usize].read(); - - // сообщение было прочитано, поэтому можно вернуть ячейку обратно - // чтобы освободить очередь - // (диспетчер задач имеет эксклюзивный доступ к - // последнему элементу очереди) - baz_FQ.split().0.enqueue_unchecked(ready.index); - - let priority = Cell::new(PRIORITY); - baz(baz::Context::new(&priority), input) - } - - Task::bar => { - // выглядит также как ветка для `baz` - } - - } - } - - // инвариант BASEPRI - basepri::write(snapshot); - } -} -``` - -`INPUTS` плюс `FQ`, список свободной памяти равняется эффективному пулу памяти. -Однако, вместо того *список свободной памяти* (связный список), чтобы отслеживать -пустые ячейки в буфере `INPUTS`, мы используем SPSC очередь; это позволяет нам -уменьшить количество критических секций. -На самом деле благодаря этому выбору код диспетчера задач неблокируемый. - -## Вместительность очереди - -Фреймворк RTIC использует несколько очередей, такие как очереди готовности и -списки свободной памяти. Когда список свободной памяти пуст, попытка выызова -(`spawn`) задачи приводит к ошибке; это условие проверяется во время выполнения. -Не все операции, произвожимые фреймворком с этими очередями проверяют их -пустоту / наличие места. Например, возвращение ячейки списка свободной памяти -(см. диспетчер задач) не проверяется, поскольку есть фиксированное количество -таких ячеек циркулирующих в системе, равное вместительности списка свободной памяти. -Аналогично, добавление записи в очередь готовности (см. `Spawn`) не проверяется, -потому что вместительность очереди выбрана фреймворком. - -Пользователи могут задавать вместительность программных задач; -эта вместительность - максимальное количество сообщений, которые можно -послать указанной задаче от задачи более высоким приоритетом до того, -как `spawn` вернет ошибку. Эта определяемая пользователем иместительность - -размер списка свободной памяти задачи (например `foo_FQ`), а также размер массива, -содержащего входные данные для задачи (например `foo_INPUTS`). - -Вместительность очереди готовности (например `RQ1`) вычисляется как *сумма* -вместительностей всех задач, управляемх диспетчером; эта сумма является также -количеством сообщений, которые очередь может хранить в худшем сценарии, когда -все возможные сообщения были посланы до того, как диспетчер задач получает шанс -на запуск. По этой причине получение ячейки списка свободной памяти при любой -операции `spawn` приводит к тому, что очередь готовности еще не заполнена, -поэтому вставка записи в список готовности может пропустить проверку "полна ли очередь?". - -В нашем запущенном примере задача `bar` не принимает входных данных, поэтому -мы можем пропустить проверку как `bar_INPUTS`, так и `bar_FQ` и позволить -пользователю посылать неограниченное число сообщений задаче, но если бы мы сделали это, -было бы невозможно превысить вместительность для `RQ1`, что позволяет нам -пропустить проверку "полна ли очередь?" при вызове задачи `baz`. -В разделе о [очереди таймера](timer-queue.html) мы увидим как -список свободной памяти используется для задач без входных данных. - -## Анализ приоритетов - -Очереди, использемые внутри интерфейса `spawn`, рассматриваются как обычные ресурсы -и для них тоже работает анализ приоритетов. Важно заметить, что это SPSC очереди, -и только один из конечных элементов становится ресурсом; другим конечным элементом -владеет диспетчер задач. - -Рассмотрим следующий пример: - -``` rust -#[rtic::app(device = ..)] -mod app { - #[idle(spawn = [foo, bar])] - fn idle(c: idle::Context) -> ! { - // .. - } - - #[task] - fn foo(c: foo::Context) { - // .. - } - - #[task] - fn bar(c: bar::Context) { - // .. - } - - #[task(priority = 2, spawn = [foo])] - fn baz(c: baz::Context) { - // .. - } - - #[task(priority = 3, spawn = [bar])] - fn quux(c: quux::Context) { - // .. - } -} -``` - -Вот как будет проходить анализ приоритетов: - -- `idle` (prio = 0) и `baz` (prio = 2) соревнуются за конечный потребитель - `foo_FQ`; это приводит к максимальному приоритету `2`. - -- `idle` (prio = 0) и `quux` (prio = 3) соревнуются за конечный потребитель - `bar_FQ`; это приводит к максимальному приоритету `3`. - -- `idle` (prio = 0), `baz` (prio = 2) и `quux` (prio = 3) соревнуются за - конечный производитель `RQ1`; это приводит к максимальному приоритету `3` diff --git a/book/ru/src/internals/timer-queue.md b/book/ru/src/internals/timer-queue.md deleted file mode 100644 index 9f2dc37..0000000 --- a/book/ru/src/internals/timer-queue.md +++ /dev/null @@ -1,372 +0,0 @@ -# Очередь таймера - -Функциональность очередь таймера позволяет пользователю планировать задачи на запуск -в опреленное время в будущем. Неудивительно, что эта функция также реализуется с помощью очереди: -очередь приоритетов, где запланированные задачи сортируются в порядке аозрастания времени. -Эта функция требует таймер, способный устанавливать прерывания истечения времени. -Таймер используется для пуска прерывания, когда настает запланированное время задачи; -в этот момент задача удаляется из очереди таймера и помещается в очередь готовности. - -Давайте посмотрим, как это реализовано в коде. Рассмотрим следующую программу: - -``` rust -#[rtic::app(device = ..)] -mod app { - // .. - - #[task(capacity = 2, schedule = [foo])] - fn foo(c: foo::Context, x: u32) { - // запланировать задачу на повторный запуск через 1 млн. тактов - c.schedule.foo(c.scheduled + Duration::cycles(1_000_000), x + 1).ok(); - } - - extern "C" { - fn UART0(); - } -} -``` - -## `schedule` - -Давайте сначала взглянем на интерфейс `schedule`. - -``` rust -mod foo { - pub struct Schedule<'a> { - priority: &'a Cell<u8>, - } - - impl<'a> Schedule<'a> { - // `unsafe` и спрятано, потому что мы не хотим, чтобы пользовать сюда вмешивался - #[doc(hidden)] - pub unsafe fn priority(&self) -> &Cell<u8> { - self.priority - } - } -} - -mod app { - type Instant = <path::to::user::monotonic::timer as rtic::Monotonic>::Instant; - - // все задачи, которые могут быть запланированы (`schedule`) - enum T { - foo, - } - - struct NotReady { - index: u8, - instant: Instant, - task: T, - } - - // Очередь таймера - двоичная куча (min-heap) задач `NotReady` - static mut TQ: TimerQueue<U2> = ..; - const TQ_CEILING: u8 = 1; - - static mut foo_FQ: Queue<u8, U2> = Queue::new(); - const foo_FQ_CEILING: u8 = 1; - - static mut foo_INPUTS: [MaybeUninit<u32>; 2] = - [MaybeUninit::uninit(), MaybeUninit::uninit()]; - - static mut foo_INSTANTS: [MaybeUninit<Instant>; 2] = - [MaybeUninit::uninit(), MaybeUninit::uninit()]; - - impl<'a> foo::Schedule<'a> { - fn foo(&self, instant: Instant, input: u32) -> Result<(), u32> { - unsafe { - let priority = self.priority(); - if let Some(index) = lock(priority, foo_FQ_CEILING, || { - foo_FQ.split().1.dequeue() - }) { - // `index` - владеющий укачатель на ячейки в этих буферах - foo_INSTANTS[index as usize].write(instant); - foo_INPUTS[index as usize].write(input); - - let nr = NotReady { - index, - instant, - task: T::foo, - }; - - lock(priority, TQ_CEILING, || { - TQ.enqueue_unchecked(nr); - }); - } else { - // Не осталось места, чтобы разместить входные данные / instant - Err(input) - } - } - } - } -} -``` - -Это очень похоже на реализацию `Spawn`. На самом деле одни и те же буфер -`INPUTS` и список сободной памяти (`FQ`) используются совместно интерфейсами -`spawn` и `schedule`. Главное отличие между ними в том, что `schedule` также -размещает `Instant`, момент на который задача запланирована на запуск, -в отдельном буфере (`foo_INSTANTS` в нашем случае). - -`TimerQueue::enqueue_unchecked` делает немного больше работы, чем -просто добавление записи в min-heap: он также вызывает прерывание -системного таймера (`SysTick`), если новая запись оказывается первой в очереди. - -## Системный таймер - -Прерывание системного таймера (`SysTick`) заботится о двух вещах: -передаче задач, которых становятся готовыми из очереди таймера в очередь готовности -и установке прерывания истечения времени, когда наступит запланированное -время следующей задачи. - -Давайте посмотрим на соответствующий код. - -``` rust -mod app { - #[no_mangle] - fn SysTick() { - const PRIORITY: u8 = 1; - - let priority = &Cell::new(PRIORITY); - while let Some(ready) = lock(priority, TQ_CEILING, || TQ.dequeue()) { - match ready.task { - T::foo => { - // переместить эту задачу в очередь готовности `RQ1` - lock(priority, RQ1_CEILING, || { - RQ1.split().0.enqueue_unchecked(Ready { - task: T1::foo, - index: ready.index, - }) - }); - - // вызвать диспетчер задач - rtic::pend(Interrupt::UART0); - } - } - } - } -} -``` - -Выглядит похоже на диспетчер задач, за исключением того, что -вместо запуска готовой задачи, она лишь переносится в очередь готовности, -что ведет к ее запуску с нужным приоритетом. - -`TimerQueue::dequeue` установит новое прерывание истечения времени, если вернет -`None`. Он сязан с `TimerQueue::enqueue_unchecked`, который вызывает это -прерывание; на самом деле, `enqueue_unchecked` передает задачу установки -нового прерывание истечения времени обработчику `SysTick`. - -## Точность и диапазон `cyccnt::Instant` и `cyccnt::Duration` - -RTIC предоставляет реализацию `Monotonic`, основанную на счетчике тактов `DWT` (Data Watchpoint and Trace). `Instant::now` возвращает снимок таймера; эти снимки -DWT (`Instant`ы) используются для сортировки записей в очереди таймера. -Счетчик тактов - 32-битный счетчик, работающий на частоте ядра. -Этот счетчик обнуляется каждые `(1 << 32)` тактов; у нас нет прерывания, -ассоциированног с этим счетчиком, поэтому ничего ужасного не случится, -когда он пройдет оборот. - -Чтобы упорядочить `Instant`ы в очереди, нам нужно сравнить 32-битные целые. -Чтобы учесть обороты, мы используем разницу между двумя `Instant`ами, `a - b`, -и рассматриваем результат как 32-битное знаковое целое. -Если результат меньше нуля, значит `b` более поздний `Instant`; -если результат больше нуля, значит `b` более ранний `Instant`. -Это значит, что планирование задачи на `Instant`, который на `(1 << 31) - 1` тактов -больше, чем запланированное время (`Instant`) первой (самой ранней) записи -в очереди приведет к тому, что задача будет помещена в неправильное -место в очереди. У нас есть несколько debug assertions в коде, чтобы -предотвратить эту пользовательскую ошибку, но этого нельзя избежать, -поскольку пользователь может написать -`(instant + duration_a) + duration_b` и переполнить `Instant`. - -Системный таймер, `SysTick` - 24-битный счетчик также работающий -на частоте процессора. Когда следующая планируемая задача более, чем в -`1 << 24` тактов в будущем, прерывание устанавливается на время в пределах -`1 << 24` тактов. Этот процесс может происходить несколько раз, пока -следующая запланированная задача не будет в диапазоне счетчика `SysTick`. - -Подведем итог, оба `Instant` и `Duration` имеют разрешение 1 такт ядра, и `Duration` эффективно имеет (полуоткрытый) диапазон `0..(1 << 31)` (не включая максимум) тактов ядра. - -## Вместительность очереди - -Вместительность очереди таймера рассчитывается как сумма вместительностей -всех планируемых (`schedule`) задач. Как и в случае очередей готовности, -это значит, что как только мы затребовали пустую ячейку в буфере `INPUTS`, -мы гарантируем, что способны передать задачу в очередь таймера; -это позволяет нам опустить проверки времени выполнения. - -## Приоритет системного таймера - -Приориет системного таймера не может быть установлен пользователем; -он выбирается фреймворком. -Чтобы убедиться, что низкоприоритетные задачи не препятствуют -запуску высокоприоритетных, мы выбираем приоритет системного таймера -максимальным из всех планируемых задач. - -Чтобы понять, почему это нужно, рассмотрим вариант, когда две ранее -запланированные задачи с приоритетами `2` и `3` становятся готовыми в -примерно одинаковое время, но низкоприоритетная задача перемещается -в очередь готовности первой. -Если бы приоритет системного таймера был, например, равен `1`, -тогда после перемещения низкоприоритетной (`2`) задачи, это бы привело -к завершению (из-за того, что приоритет выше приоритета системного таймера) -ожидания выполнения высокоприоритетной задачи (`3`). -Чтобы избежать такого сценария, системный таймер должен работать на -приоритете, равном наивысшему из приоритетов планируемых задач; -в этом примере это `3`. - -## Анализ приоритетов - -Очередь таймера - это ресурс, разделяемый всеми задачами, которые могут -планировать (`schedule`) задачи и обработчиком `SysTick`. -Также интерфейс `schedule` соперничает с интерфейсом `spawn` -за списки свободной памяти. Все это должно уситываться в анализе приоритетов. - -Чтобы проиллюстрировать, рассмотрим следующий пример: - -``` rust -#[rtic::app(device = ..)] -mod app { - #[task(priority = 3, spawn = [baz])] - fn foo(c: foo::Context) { - // .. - } - - #[task(priority = 2, schedule = [foo, baz])] - fn bar(c: bar::Context) { - // .. - } - - #[task(priority = 1)] - fn baz(c: baz::Context) { - // .. - } -} -``` - -Анализ приоритетов происходил бы вот так: - -- `foo` (prio = 3) и `baz` (prio = 1) планируемые задачи, поэтому - `SysTick` должен работать на максимальном из этих двух приоритетов, т.е. `3`. - -- `foo::Spawn` (prio = 3) и `bar::Schedule` (prio = 2) соперничают за - конечный потребитель `baz_FQ`; это приводит к максимальному приоритету `3`. - -- `bar::Schedule` (prio = 2) имеет экслюзивный доступ к - конечному потребителю `foo_FQ`; поэтому максимальный приоритет `foo_FQ` фактически `2`. - -- `SysTick` (prio = 3) и `bar::Schedule` (prio = 2) соперничают за - очередь таймера `TQ`; это приводит к максимальному приоритету `3`. - -- `SysTick` (prio = 3) и `foo::Spawn` (prio = 3) оба имеют неблокируемый - доступ к очереди готовности `RQ3`, что хранит записи `foo`; - поэтому максимальный приоритет `RQ3` фактически `3`. - -- `SysTick` имеет эксклюзивный доступ к очереди готовности `RQ1`, - которая хранит записи `baz`; поэтому максимальный приоритет `RQ1` фактически `3`. - -## Изменения в реализации `spawn` - -Когда интерфейс `schedule` используется, реализация `spawn` немного -изменяется, чтобы отслеживать baseline задач. Как можете видеть в -реализации `schedule` есть буферы `INSTANTS`, используемые, чтобы -хранить время, в которое задача была запланирована навыполнение; -этот `Instant` читается диспетчером задач и передается в пользовательский -код, как часть контекста задачи. - -``` rust -mod app { - // .. - - #[no_mangle] - unsafe UART1() { - const PRIORITY: u8 = 1; - - let snapshot = basepri::read(); - - while let Some(ready) = RQ1.split().1.dequeue() { - match ready.task { - Task::baz => { - let input = baz_INPUTS[ready.index as usize].read(); - // ADDED - let instant = baz_INSTANTS[ready.index as usize].read(); - - baz_FQ.split().0.enqueue_unchecked(ready.index); - - let priority = Cell::new(PRIORITY); - // ИЗМЕНЕНО instant передан как часть контекста задачи - baz(baz::Context::new(&priority, instant), input) - } - - Task::bar => { - // выглядит также как ветка для `baz` - } - - } - } - - // инвариант BASEPRI - basepri::write(snapshot); - } -} -``` - -И наоборот, реализации `spawn` нужно писать значение в буфер `INSTANTS`. -Записанное значение располагается в структуре `Spawn` и это либо -время `start` аппаратной задачи, либо время `scheduled` программной задачи. - -``` rust -mod foo { - // .. - - pub struct Spawn<'a> { - priority: &'a Cell<u8>, - // ADDED - instant: Instant, - } - - impl<'a> Spawn<'a> { - pub unsafe fn priority(&self) -> &Cell<u8> { - &self.priority - } - - // ADDED - pub unsafe fn instant(&self) -> Instant { - self.instant - } - } -} - -mod app { - impl<'a> foo::Spawn<'a> { - /// Spawns the `baz` task - pub fn baz(&self, message: u64) -> Result<(), u64> { - unsafe { - match lock(self.priority(), baz_FQ_CEILING, || { - baz_FQ.split().1.dequeue() - }) { - Some(index) => { - baz_INPUTS[index as usize].write(message); - // ADDED - baz_INSTANTS[index as usize].write(self.instant()); - - lock(self.priority(), RQ1_CEILING, || { - RQ1.split().1.enqueue_unchecked(Ready { - task: Task::foo, - index, - }); - }); - - rtic::pend(Interrupt::UART0); - } - - None => { - // достигнута максимальная вместительность; неудачный вызов - Err(message) - } - } - } - } - } -} -``` diff --git a/book/ru/src/migration.md b/book/ru/src/migration.md deleted file mode 100644 index b7f2fa1..0000000 --- a/book/ru/src/migration.md +++ /dev/null @@ -1,4 +0,0 @@ -# Инструкции по миграции - -В этом разделе описывается как мигрировать между различными версиями RTIC. -Можно также использовать для сравнения версий. diff --git a/book/ru/src/migration/migration_rtic.md b/book/ru/src/migration/migration_rtic.md deleted file mode 100644 index 28813fe..0000000 --- a/book/ru/src/migration/migration_rtic.md +++ /dev/null @@ -1,48 +0,0 @@ -# Миграция с RTFM на RTIC - -В этом разделе описано, как обновить приложение, написанное на RTFM v0.5.x на RTIC той же версии. -Это необходимо из-за переименования фреймворка в соответствии с [RFC #33]. - -**Примечание:** Между RTFM v0.5.3 и RTIC v0.5.3 нет разниц в коде, это исключительно изменение имен. - -[RFC #33]: https://github.com/rtic-rs/rfcs/pull/33 - -## `Cargo.toml` - -Во-первых, зависимость `cortex-m-rtfm` должна быть изменена на `cortex-m-rtic`. - -``` toml -[dependencies] -# измените это -cortex-m-rtfm = "0.5.3" - -# на это -cortex-m-rtic = "0.5.3" -``` - -## Изменения в коде - -Единственное изменение в коде, которое нужно сделать - поменять все ссылки на `rtfm`, -чтобы они указывали на `rtic`: - -``` rust -// -// Измените это -// - -#[rtfm::app(/* .. */, monotonic = rtfm::cyccnt::CYCCNT)] -const APP: () = { - // ... - -}; - -// -// На это -// - -#[rtic::app(/* .. */, monotonic = rtic::cyccnt::CYCCNT)] -const APP: () = { - // ... - -}; -``` diff --git a/book/ru/src/migration/migration_v4.md b/book/ru/src/migration/migration_v4.md deleted file mode 100644 index 0ff8039..0000000 --- a/book/ru/src/migration/migration_v4.md +++ /dev/null @@ -1,230 +0,0 @@ -# Миграция с v0.4.x на v0.5.0 - -Этот раздел описывает как обновить программы, написанные на RTIC v0.4.x -на версию v0.5.0 фреймворка. - -## `Cargo.toml` - -Во-первых, нужно обновить версию зависимости `cortex-m-rtic` до -`"0.5.0"`. Опцию `timer-queue` нужно удалить. - -``` toml -[dependencies.cortex-m-rtic] -# изменить это -version = "0.4.3" - -# на это -version = "0.5.0" - -# и удалить Cargo feature -features = ["timer-queue"] -# ^^^^^^^^^^^^^ -``` - -## Аргумент `Context` - -Все функции внутри элемента `#[rtic::app]` должны принимать первым аргументом -структуру `Context`. Этот тип `Context` будет содержать переменные, которые были магически -инъецированы в область видимости функции версией v0.4.x фреймворка: -`resources`, `spawn`, `schedule` -- эти переменные станут полями структуры `Context`. -Каждая функция элемента `#[rtic::app]` получит отдельный тип `Context`. - -``` rust -#[rtic::app(/* .. */)] -const APP: () = { - // change this - #[task(resources = [x], spawn = [a], schedule = [b])] - fn foo() { - resources.x.lock(|x| /* .. */); - spawn.a(message); - schedule.b(baseline); - } - - // into this - #[task(resources = [x], spawn = [a], schedule = [b])] - fn foo(mut cx: foo::Context) { - // ^^^^^^^^^^^^^^^^^^^^ - - cx.resources.x.lock(|x| /* .. */); - // ^^^ - - cx.spawn.a(message); - // ^^^ - - cx.schedule.b(message, baseline); - // ^^^ - } - - // change this - #[init] - fn init() { - // .. - } - - // into this - #[init] - fn init(cx: init::Context) { - // ^^^^^^^^^^^^^^^^^ - // .. - } - - // .. -}; -``` - -## Ресурсы - -Синтаксис, используемый, для определения ресурсов был изменен с переменных `static mut` -на структуру `Resources`. - -``` rust -#[rtic::app(/* .. */)] -const APP: () = { - // измените это - static mut X: u32 = 0; - static mut Y: u32 = (); // поздний ресурс - - // на это - struct Resources { - #[init(0)] // <- начальное значение - X: u32, // ПРИМЕЧАНИЕ: мы предлагаем изменить стиль именования на `snake_case` - - Y: u32, // поздний ресурс - } - - // .. -}; -``` - -## Периферия устройства - -Если ваша программа получала доступ к периферии в `#[init]` через -переменну `device`, вам нужно будет добавить `peripherals = true` в атрибут -`#[rtic::app]`, чтобы и дальше получать доступ к периферии через поле `device` структуры `init::Context`. - -Измените это: - -``` rust -#[rtic::app(/* .. */)] -const APP: () = { - #[init] - fn init() { - device.SOME_PERIPHERAL.write(something); - } - - // .. -}; -``` - -На это: - -``` rust -#[rtic::app(/* .. */, peripherals = true)] -// ^^^^^^^^^^^^^^^^^^ -const APP: () = { - #[init] - fn init(cx: init::Context) { - // ^^^^^^^^^^^^^^^^^ - cx.device.SOME_PERIPHERAL.write(something); - // ^^^ - } - - // .. -}; -``` - -## `#[interrupt]` и `#[exception]` - -Атрибуты `#[interrupt]` и `#[exception]` были удалены. Чтобы определять аппаратные задачи в v0.5.x -используте атрибут `#[task]` с аргументом `binds`. - -Измените это: - -``` rust -#[rtic::app(/* .. */)] -const APP: () = { - // аппаратные задачи - #[exception] - fn SVCall() { /* .. */ } - - #[interrupt] - fn UART0() { /* .. */ } - - // программные задачи - #[task] - fn foo() { /* .. */ } - - // .. -}; -``` - -На это: - -``` rust -#[rtic::app(/* .. */)] -const APP: () = { - #[task(binds = SVCall)] - // ^^^^^^^^^^^^^^ - fn svcall(cx: svcall::Context) { /* .. */ } - // ^^^^^^ мы предлагаем использовать `snake_case` имя здесь - - #[task(binds = UART0)] - // ^^^^^^^^^^^^^ - fn uart0(cx: uart0::Context) { /* .. */ } - - #[task] - fn foo(cx: foo::Context) { /* .. */ } - - // .. -}; -``` - -## `schedule` - -Интерфейс `schedule` больше не требует cargo опции `timer-queue`, которая была удалена. -Чтобы использовать интерфес `schedule`, нужно сначала определить -монотонный тамер, который будет использоваьт среды выполнения, с помощью аргумента `monotonic` -атрибута `#[rtic::app]`. Чтобы продолжить использовать счетчик циклов -(CYCCNT) в качестве монотонного таймера, как было в версии v0.4.x, добавьте -аргумент `monotonic = rtic::cyccnt::CYCCNT` в атрибут `#[rtic::app]`. - -Также были добавлены типы `Duration` и `Instant`, а трейт `U32Ext` был перемещен в модуль `rtic::cyccnt`. -Этот модуль доступен только на устройствах ARMv7-M+. -Удаление `timer-queue` также возвращает периферию `DWT` в структуру периферии ядра, -включить ее в работу можно внутри `init`. - -Измените это: - -``` rust -use rtic::{Duration, Instant, U32Ext}; - -#[rtic::app(/* .. */)] -const APP: () = { - #[task(schedule = [b])] - fn a() { - // .. - } -}; -``` - -На это: - -``` rust -use rtic::cyccnt::{Duration, Instant, U32Ext}; -// ^^^^^^^^ - -#[rtic::app(/* .. */, monotonic = rtic::cyccnt::CYCCNT)] -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -const APP: () = { - #[init] - fn init(cx: init::Context) { - cx.core.DWT.enable_cycle_counter(); - // опционально, настройка запуска DWT без подключенного отладчика - cx.core.DCB.enable_trace(); - } - #[task(schedule = [b])] - fn a(cx: a::Context) { - // .. - } -}; -``` diff --git a/book/ru/src/migration/migration_v5.md b/book/ru/src/migration/migration_v5.md deleted file mode 100644 index 84bd9fb..0000000 --- a/book/ru/src/migration/migration_v5.md +++ /dev/null @@ -1,365 +0,0 @@ -# Миграция с v0.5.x на v1.0.0 - -Этот раздел описывает как обновиться с версии v0.5.x на v1.0.0 фреймворка RTIC. - -## `Cargo.toml` - увеличьте версию - -Измените версию `cortex-m-rtic` на `"0.6.0"`. - -## `mod` вместо `const` - -С поддержкой атрибутов над модулями трюк с `const APP` теперь не нужен. - -Измените - -``` rust -#[rtic::app(/* .. */)] -const APP: () = { - [код здесь] -}; -``` - -на - -``` rust -#[rtic::app(/* .. */)] -mod app { - [код здесь] -} -``` - -Так как теперь используется обычный модуль Rust, это значит, что можно использовать -обычный пользовательский код в этом модуле. -Также это значит, что `use`-выражения для ресурсов, используемые -в пользовательском коде должны быть перемещены внутрь `mod app`, -либо на них можно сослаться с помощью `super`. Например, измените: - -```rust -use some_crate::some_func; - -#[rtic::app(/* .. */)] -const APP: () = { - fn func() { - some_crate::some_func(); - } -}; -``` - -на - -```rust -#[rtic::app(/* .. */)] -mod app { - use some_crate::some_func; - - fn func() { - some_crate::some_func(); - } -} -``` - -или - -```rust -use some_crate::some_func; - -#[rtic::app(/* .. */)] -mod app { - fn func() { - super::some_crate::some_func(); - } -} -``` - -## Перенос диспетчеров из `extern "C"` в аргументы app. - -Измените - -``` rust -#[rtic::app(/* .. */)] -const APP: () = { - [код здесь] - - // RTIC требует, чтобы неиспользуемые прерывания были задекларированы в блоке extern, когда - // используются программные задачи; эти свободные прерывания будут использованы для управления - // программными задачами. - extern "C" { - fn SSI0(); - fn QEI0(); - } -}; -``` - -на - -``` rust -#[rtic::app(/* .. */, dispatchers = [SSI0, QEI0])] -mod app { - [код здесь] -} -``` - -Это работает и для ОЗУ-функций, см. examples/ramfunc.rs - - -## Структуры ресурсов - `#[shared]`, `#[local]` - -Ранее ресурсы RTIC должны были размещаться в структуре с именем "Resources": - -``` rust -struct Resources { - // Ресурсы определяются здесь -} -``` - -Начиная с RTIC v1.0.0 структуры ресурсов аннотируются подобно -`#[task]`, `#[init]`, `#[idle]`: аттрибутами `#[shared]` и `#[local]` - -``` rust -#[shared] -struct MySharedResources { - // Разделяемые задачами ресурсы определены здесь -} - -#[local] -struct MyLocalResources { - // Ресурсы, определенные здесь нельзя передавать между задачами; каждый из них локальный для единственной задачи -} -``` - -Эти структуры разработчик может называть по своему желанию. - -## `shared` и `local` аргументы в `#[task]`'ах - -В v1.0.0 ресурсы разделены на `shared` ресурсы и `local` ресурсы. -`#[task]`, `#[init]` и `#[idle]` больше не имеют аргумента `resources`; -они должны использовать аргументы `shared` и `local`. - -В v0.5.x: - -``` rust -struct Resources { - local_to_b: i64, - shared_by_a_and_b: i64, -} - -#[task(resources = [shared_by_a_and_b])] -fn a(_: a::Context) {} - -#[task(resources = [shared_by_a_and_b, local_to_b])] -fn b(_: b::Context) {} -``` - -В v1.0.0: - -``` rust -#[shared] -struct Shared { - shared_by_a_and_b: i64, -} - -#[local] -struct Local { - local_to_b: i64, -} - -#[task(shared = [shared_by_a_and_b])] -fn a(_: a::Context) {} - -#[task(shared = [shared_by_a_and_b], local = [local_to_b])] -fn b(_: b::Context) {} -``` - -## Симметричные блокировки - -Теперь RTIC использует симметричные блокировки, это значит, что метод `lock` нужно использовать для -всех доступов к `shared` ресурсам. Поскольку высокоприоритетные задачи имеют эксклюзивный доступ к ресурсу, -в старом коде можно было следующее: - -``` rust -#[task(priority = 2, resources = [r])] -fn foo(cx: foo::Context) { - cx.resources.r = /* ... */; -} - -#[task(resources = [r])] -fn bar(cx: bar::Context) { - cx.resources.r.lock(|r| r = /* ... */); -} -``` - -С симметричными блокировками нужно вызывать `lock` для обоих задач: - -``` rust -#[task(priority = 2, shared = [r])] -fn foo(cx: foo::Context) { - cx.shared.r.lock(|r| r = /* ... */); -} - -#[task(shared = [r])] -fn bar(cx: bar::Context) { - cx.shared.r.lock(|r| r = /* ... */); -} -``` - -Заметьте, что скорость работы не изменяется благодаря оптимизациям LLVM, которые убирают ненужные блокировки. - -## Неблокирующий доступ к ресурсам - -В RTIC 0.5 к ресурсам разделяемым задачами, запускаемыми с одинаковым -приоритетом, можно получить доступ *без* `lock` API. -Это все еще возможно в 0.6: ресурс `#[shared]` должен быть аннотирован -аттрибутом поля `#[lock_free]`. - -v0.5 код: - -``` rust -struct Resources { - counter: u64, -} - -#[task(resources = [counter])] -fn a(cx: a::Context) { - *cx.resources.counter += 1; -} - -#[task(resources = [counter])] -fn b(cx: b::Context) { - *cx.resources.counter += 1; -} -``` - -v1.0 код: - -``` rust -#[shared] -struct Shared { - #[lock_free] - counter: u64, -} - -#[task(shared = [counter])] -fn a(cx: a::Context) { - *cx.shared.counter += 1; -} - -#[task(shared = [counter])] -fn b(cx: b::Context) { - *cx.shared.counter += 1; -} -``` - -## нет преобразования `static mut` - -`static mut` переменные больше не преобразуются в безопасные `&'static mut` ссылки. -Вместо этого синтаксиса используйте аргумент `local` в `#[init]`. - -v0.5.x code: - -``` rust -#[init] -fn init(_: init::Context) { - static mut BUFFER: [u8; 1024] = [0; 1024]; - let buffer: &'static mut [u8; 1024] = BUFFER; -} -``` - -v1.0.0 code: - -``` rust -#[init(local = [ - buffer: [u8; 1024] = [0; 1024] -// type ^^^^^^^^^^^^ ^^^^^^^^^ initial value -])] -fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - let buffer: &'static mut [u8; 1024] = cx.local.buffer; - - (Shared {}, Local {}, init::Monotonics()) -} -``` - -## Init всегда возвращает поздние ресурсы - -С целью сделать API более симметричным задача #[init] всегда возвращает поздние ресурсы. - -С этого: - -``` rust -#[rtic::app(device = lm3s6965)] -mod app { - #[init] - fn init(_: init::Context) { - rtic::pend(Interrupt::UART0); - } - - // [еще код] -} -``` - -на это: - - -``` rust -#[rtic::app(device = lm3s6965)] -mod app { - #[shared] - struct MySharedResources {} - - #[local] - struct MyLocalResources {} - - #[init] - fn init(_: init::Context) -> (MySharedResources, MyLocalResources, init::Monotonics) { - rtic::pend(Interrupt::UART0); - - (MySharedResources, MyLocalResources, init::Monotonics()) - } - - // [more code] -} -``` - -## Вызов/планирование откуда угодно - -С этой новой возвожностью, старый код, такой как: - - -``` rust -#[task(spawn = [bar])] -fn foo(cx: foo::Context) { - cx.spawn.bar().unwrap(); -} - -#[task(schedule = [bar])] -fn bar(cx: bar::Context) { - cx.schedule.foo(/* ... */).unwrap(); -} -``` - -Теперь будет выглядеть так: - -``` rust -#[task] -fn foo(_c: foo::Context) { - bar::spawn().unwrap(); -} - -#[task] -fn bar(_c: bar::Context) { - foo::schedule(/* ... */).unwrap(); -} -``` - -Заметьте, что атрибуты `spawn` и `schedule` больше не нужны. - ---- - -## Дополнительно - -### Внешние задачи - -Как программные, так и аппаратные задачи теперь можно определять вне модуля `mod app`. -Ранее это было возможно только путем реализации обертки, вызывающей реализацию задачи. - -Смотреть примеры `examples/extern_binds.rs` и `examples/extern_spawn.rs`. - diff --git a/book/ru/src/preface.md b/book/ru/src/preface.md deleted file mode 100644 index 894b6b4..0000000 --- a/book/ru/src/preface.md +++ /dev/null @@ -1,26 +0,0 @@ -<div align="center"><img width="300" height="300" src="RTIC.svg"></div> -<div style="font-size: 6em; font-weight: bolder;" align="center">RTIC</div> - -<h1 align="center">Real-Time Interrupt-driven Concurrency</h1> - -<p align="center">Конкурентный фреймворк для создания систем реального времени</p> - -# Введение - -Эта книга содержит документацию пользовательского уровня о фреймворке Real-Time Interrupt-driven Concurrency -(RTIC). Справочник по API можно найти [здесь](../../api/). - -Также известен как Real-Time For the Masses. - -<!--Оригинал данного руководства на [английском].--> - -<!--[английском]: ../en/index.html--> - -Это документация по RTIC версии v1.0.x; за документацией по другим версиям: - -* v0.5.x [сюда](/0.5). -* v0.4.x [сюда](/0.4). - -{{#include ../../../README_ru.md:7:45}} - -{{#include ../../../README_ru.md:51:}} diff --git a/build.rs b/build.rs deleted file mode 100644 index ff9ebe3..0000000 --- a/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::env; - -fn main() { - let target = env::var("TARGET").unwrap(); - - if version_check::Channel::read().unwrap().is_nightly() { - println!("cargo:rustc-cfg=rustc_is_nightly"); - } - - // These targets all have know support for the BASEPRI register. - if target.starts_with("thumbv7m") - | target.starts_with("thumbv7em") - | target.starts_with("thumbv8m.main") - { - println!("cargo:rustc-cfg=have_basepri"); - - // These targets are all known to _not_ have the BASEPRI register. - } else if target.starts_with("thumb") - && !(target.starts_with("thumbv6m") | target.starts_with("thumbv8m.base")) - { - panic!( - "Unknown target '{}'. Need to update BASEPRI logic in build.rs.", - target - ); - } - - println!("cargo:rerun-if-changed=build.rs"); -} diff --git a/ci/expected/big-struct-opt.run b/ci/expected/big-struct-opt.run deleted file mode 100644 index e69de29..0000000 --- a/ci/expected/big-struct-opt.run +++ /dev/null diff --git a/ci/expected/cfg-monotonic.run b/ci/expected/cfg-monotonic.run deleted file mode 100644 index e69de29..0000000 --- a/ci/expected/cfg-monotonic.run +++ /dev/null diff --git a/ci/expected/common.run b/ci/expected/common.run deleted file mode 100644 index e69de29..0000000 --- a/ci/expected/common.run +++ /dev/null diff --git a/ci/expected/destructure.run b/ci/expected/destructure.run deleted file mode 100644 index b9b7cc9..0000000 --- a/ci/expected/destructure.run +++ /dev/null @@ -1,2 +0,0 @@ -foo: a = 0, b = 0, c = 0 -bar: a = 0, b = 0, c = 0 diff --git a/ci/expected/extern_spawn.run b/ci/expected/extern_spawn.run deleted file mode 100644 index 2f8c74f..0000000 --- a/ci/expected/extern_spawn.run +++ /dev/null @@ -1,2 +0,0 @@ -foo 1, 2 -foo 2, 3 diff --git a/ci/expected/message_passing.run b/ci/expected/message_passing.run deleted file mode 100644 index a1448d8..0000000 --- a/ci/expected/message_passing.run +++ /dev/null @@ -1,3 +0,0 @@ -foo 1, 1 -foo 1, 2 -foo 2, 3 diff --git a/ci/expected/not-sync.run b/ci/expected/not-sync.run deleted file mode 100644 index e69de29..0000000 --- a/ci/expected/not-sync.run +++ /dev/null diff --git a/ci/expected/periodic-at.run b/ci/expected/periodic-at.run deleted file mode 100644 index 54020f9..0000000 --- a/ci/expected/periodic-at.run +++ /dev/null @@ -1,4 +0,0 @@ -foo Instant { ticks: 0 } -foo Instant { ticks: 100 } -foo Instant { ticks: 200 } -foo Instant { ticks: 300 } diff --git a/ci/expected/periodic-at2.run b/ci/expected/periodic-at2.run deleted file mode 100644 index 47adbef..0000000 --- a/ci/expected/periodic-at2.run +++ /dev/null @@ -1,7 +0,0 @@ -foo Instant { ticks: 0 } -bar Instant { ticks: 10 } -foo Instant { ticks: 110 } -bar Instant { ticks: 120 } -foo Instant { ticks: 220 } -bar Instant { ticks: 230 } -foo Instant { ticks: 330 } diff --git a/examples/cancel-reschedule.rs b/examples/cancel-reschedule.rs deleted file mode 100644 index 36c496b..0000000 --- a/examples/cancel-reschedule.rs +++ /dev/null @@ -1,74 +0,0 @@ -//! examples/cancel-reschedule.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use systick_monotonic::*; - - #[monotonic(binds = SysTick, default = true)] - type MyMono = Systick<100>; // 100 Hz / 10 ms granularity - - #[shared] - struct Shared {} - - #[local] - struct Local {} - - #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - let systick = cx.core.SYST; - - // Initialize the monotonic (SysTick rate in QEMU is 12 MHz) - let mono = Systick::new(systick, 12_000_000); - - hprintln!("init"); - - // Schedule `foo` to run 1 second in the future - foo::spawn_after(1.secs()).unwrap(); - - ( - Shared {}, - Local {}, - init::Monotonics(mono), // Give the monotonic to RTIC - ) - } - - #[task] - fn foo(_: foo::Context) { - hprintln!("foo"); - - // Schedule `bar` to run 2 seconds in the future (1 second after foo runs) - let spawn_handle = baz::spawn_after(2.secs()).unwrap(); - bar::spawn_after(1.secs(), spawn_handle, false).unwrap(); // Change to true - } - - #[task] - fn bar(_: bar::Context, baz_handle: baz::SpawnHandle, do_reschedule: bool) { - hprintln!("bar"); - - if do_reschedule { - // Reschedule baz 2 seconds from now, instead of the original 1 second - // from now. - baz_handle.reschedule_after(2.secs()).unwrap(); - // Or baz_handle.reschedule_at(/* time */) - } else { - // Or cancel it - baz_handle.cancel().unwrap(); - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - } - } - - #[task] - fn baz(_: baz::Context) { - hprintln!("baz"); - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - } -} diff --git a/examples/capacity.rs b/examples/capacity.rs deleted file mode 100644 index 550829b..0000000 --- a/examples/capacity.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! examples/capacity.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use lm3s6965::Interrupt; - - #[shared] - struct Shared {} - - #[local] - struct Local {} - - #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { - rtic::pend(Interrupt::UART0); - - (Shared {}, Local {}, init::Monotonics()) - } - - #[task(binds = UART0)] - fn uart0(_: uart0::Context) { - foo::spawn(0).unwrap(); - foo::spawn(1).unwrap(); - foo::spawn(2).unwrap(); - foo::spawn(3).unwrap(); - - bar::spawn().unwrap(); - } - - #[task(capacity = 4)] - fn foo(_: foo::Context, x: u32) { - hprintln!("foo({})", x); - } - - #[task] - fn bar(_: bar::Context) { - hprintln!("bar"); - - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - } -} diff --git a/examples/cfg-monotonic.rs b/examples/cfg-monotonic.rs deleted file mode 100644 index 88c0d6f..0000000 --- a/examples/cfg-monotonic.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! examples/cfg-monotonic.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0])] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use systick_monotonic::*; // Implements the `Monotonic` trait - - // A monotonic timer to enable scheduling in RTIC - #[cfg(feature = "killmono")] - #[monotonic(binds = SysTick, default = true)] - type MyMono = Systick<100>; // 100 Hz / 10 ms granularity - - // Not allowed by current rtic-syntax: - // error: `#[monotonic(...)]` on a specific type must appear at most once - // --> examples/cfg-monotonic.rs:23:10 - // | - // 23 | type MyMono = Systick<100>; // 100 Hz / 10 ms granularity - // | ^^^^^^ - // #[monotonic(binds = SysTick, default = true)] - // type MyMono = Systick<100>; // 100 Hz / 10 ms granularity - - // Not allowed by current rtic-syntax: - // error: this interrupt is already bound - // --> examples/cfg-monotonic.rs:31:25 - // | - // 31 | #[monotonic(binds = SysTick, default = true)] - // | ^^^^^^^ - // #[monotonic(binds = SysTick, default = true)] - // type MyMono2 = DwtSystick<100>; // 100 Hz / 10 ms granularity - - // Resources shared between tasks - #[shared] - struct Shared { - s1: u32, - s2: i32, - } - - // Local resources to specific tasks (cannot be shared) - #[local] - struct Local { - l1: u8, - l2: i8, - } - - #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - let _systick = cx.core.SYST; - - // Initialize the monotonic (SysTick rate in QEMU is 12 MHz) - #[cfg(feature = "killmono")] - let mono = Systick::new(systick, 12_000_000); - - // Spawn the task `foo` directly after `init` finishes - foo::spawn().unwrap(); - - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - - ( - // Initialization of shared resources - Shared { s1: 0, s2: 1 }, - // Initialization of task local resources - Local { l1: 2, l2: 3 }, - // Move the monotonic timer to the RTIC run-time, this enables - // scheduling - #[cfg(feature = "killmono")] - init::Monotonics(mono), - init::Monotonics(), - ) - } - - // Background task, runs whenever no other tasks are running - #[idle] - fn idle(_: idle::Context) -> ! { - loop { - continue; - } - } - - // Software task, not bound to a hardware interrupt. - // This task takes the task local resource `l1` - // The resources `s1` and `s2` are shared between all other tasks. - #[task(shared = [s1, s2], local = [l1])] - fn foo(_: foo::Context) { - // This task is only spawned once in `init`, hence this task will run - // only once - - hprintln!("foo"); - } - - // Software task, also not bound to a hardware interrupt - // This task takes the task local resource `l2` - // The resources `s1` and `s2` are shared between all other tasks. - #[task(shared = [s1, s2], local = [l2])] - fn bar(_: bar::Context) { - hprintln!("bar"); - - // Run `bar` once per second - // bar::spawn_after(1.secs()).unwrap(); - } - - // Hardware task, bound to a hardware interrupt - // The resources `s1` and `s2` are shared between all other tasks. - #[task(binds = UART0, priority = 3, shared = [s1, s2])] - fn uart0_interrupt(_: uart0_interrupt::Context) { - // This task is bound to the interrupt `UART0` and will run - // whenever the interrupt fires - - // Note that RTIC does NOT clear the interrupt flag, this is up to the - // user - - hprintln!("UART0 interrupt!"); - } -} diff --git a/examples/cfg-whole-task.rs b/examples/cfg-whole-task.rs deleted file mode 100644 index 17f31f4..0000000 --- a/examples/cfg-whole-task.rs +++ /dev/null @@ -1,107 +0,0 @@ -//! examples/cfg-whole-task.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0])] -mod app { - use cortex_m_semihosting::debug; - #[cfg(debug_assertions)] - use cortex_m_semihosting::hprintln; - - #[shared] - struct Shared { - count: u32, - #[cfg(never)] - unused: u32, - } - - #[local] - struct Local {} - - #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { - foo::spawn().unwrap(); - foo::spawn().unwrap(); - - ( - Shared { - count: 0, - #[cfg(never)] - unused: 1, - }, - Local {}, - init::Monotonics(), - ) - } - - #[idle] - fn idle(_: idle::Context) -> ! { - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - - loop { - cortex_m::asm::nop(); - } - } - - #[task(capacity = 2, shared = [count])] - fn foo(mut _cx: foo::Context) { - #[cfg(debug_assertions)] - { - _cx.shared.count.lock(|count| *count += 1); - - log::spawn(_cx.shared.count.lock(|count| *count)).unwrap(); - } - - // this wouldn't compile in `release` mode - // *_cx.shared.count += 1; - - // .. - } - - // The whole task should disappear, - // currently still present in the Tasks enum - #[cfg(never)] - #[task(capacity = 2, shared = [count])] - fn foo2(mut _cx: foo2::Context) { - #[cfg(debug_assertions)] - { - _cx.shared.count.lock(|count| *count += 10); - - log::spawn(_cx.shared.count.lock(|count| *count)).unwrap(); - } - - // this wouldn't compile in `release` mode - // *_cx.shared.count += 1; - - // .. - } - - // The whole task should disappear, - // currently still present in the Tasks enum - #[cfg(never)] - #[task(binds = UART1, shared = [count])] - fn foo3(mut _cx: foo3::Context) { - #[cfg(debug_assertions)] - { - _cx.shared.count.lock(|count| *count += 10); - - log::spawn(_cx.shared.count.lock(|count| *count)).unwrap(); - } - } - - #[cfg(debug_assertions)] - #[task(capacity = 2)] - fn log(_: log::Context, n: u32) { - hprintln!( - "foo has been called {} time{}", - n, - if n == 1 { "" } else { "s" } - ); - } -} diff --git a/examples/common.rs b/examples/common.rs deleted file mode 100644 index 74ee8db..0000000 --- a/examples/common.rs +++ /dev/null @@ -1,103 +0,0 @@ -//! examples/common.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0])] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use systick_monotonic::*; // Implements the `Monotonic` trait - - // A monotonic timer to enable scheduling in RTIC - #[monotonic(binds = SysTick, default = true)] - type MyMono = Systick<100>; // 100 Hz / 10 ms granularity - - // Resources shared between tasks - #[shared] - struct Shared { - s1: u32, - s2: i32, - } - - // Local resources to specific tasks (cannot be shared) - #[local] - struct Local { - l1: u8, - l2: i8, - } - - #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - let systick = cx.core.SYST; - - // Initialize the monotonic (SysTick rate in QEMU is 12 MHz) - let mono = Systick::new(systick, 12_000_000); - - // Spawn the task `foo` directly after `init` finishes - foo::spawn().unwrap(); - - // Spawn the task `bar` 1 second after `init` finishes, this is enabled - // by the `#[monotonic(..)]` above - bar::spawn_after(1.secs()).unwrap(); - - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - - ( - // Initialization of shared resources - Shared { s1: 0, s2: 1 }, - // Initialization of task local resources - Local { l1: 2, l2: 3 }, - // Move the monotonic timer to the RTIC run-time, this enables - // scheduling - init::Monotonics(mono), - ) - } - - // Background task, runs whenever no other tasks are running - #[idle] - fn idle(_: idle::Context) -> ! { - loop { - continue; - } - } - - // Software task, not bound to a hardware interrupt. - // This task takes the task local resource `l1` - // The resources `s1` and `s2` are shared between all other tasks. - #[task(shared = [s1, s2], local = [l1])] - fn foo(_: foo::Context) { - // This task is only spawned once in `init`, hence this task will run - // only once - - hprintln!("foo"); - } - - // Software task, also not bound to a hardware interrupt - // This task takes the task local resource `l2` - // The resources `s1` and `s2` are shared between all other tasks. - #[task(shared = [s1, s2], local = [l2])] - fn bar(_: bar::Context) { - hprintln!("bar"); - - // Run `bar` once per second - bar::spawn_after(1.secs()).unwrap(); - } - - // Hardware task, bound to a hardware interrupt - // The resources `s1` and `s2` are shared between all other tasks. - #[task(binds = UART0, priority = 3, shared = [s1, s2])] - fn uart0_interrupt(_: uart0_interrupt::Context) { - // This task is bound to the interrupt `UART0` and will run - // whenever the interrupt fires - - // Note that RTIC does NOT clear the interrupt flag, this is up to the - // user - - hprintln!("UART0 interrupt!"); - } -} diff --git a/examples/message.rs b/examples/message.rs deleted file mode 100644 index 8a6a12d..0000000 --- a/examples/message.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! examples/message.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - - #[shared] - struct Shared {} - - #[local] - struct Local {} - - #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { - foo::spawn(/* no message */).unwrap(); - - (Shared {}, Local {}, init::Monotonics()) - } - - #[task(local = [count: u32 = 0])] - fn foo(cx: foo::Context) { - hprintln!("foo"); - - bar::spawn(*cx.local.count).unwrap(); - *cx.local.count += 1; - } - - #[task] - fn bar(_: bar::Context, x: u32) { - hprintln!("bar({})", x); - - baz::spawn(x + 1, x + 2).unwrap(); - } - - #[task] - fn baz(_: baz::Context, x: u32, y: u32) { - hprintln!("baz({}, {})", x, y); - - if x + y > 4 { - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - } - - foo::spawn().unwrap(); - } -} diff --git a/examples/periodic-at.rs b/examples/periodic-at.rs deleted file mode 100644 index ad8a549..0000000 --- a/examples/periodic-at.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! examples/periodic-at.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use systick_monotonic::*; - - #[monotonic(binds = SysTick, default = true)] - type MyMono = Systick<100>; // 100 Hz / 10 ms granularity - - #[shared] - struct Shared {} - - #[local] - struct Local {} - - #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - let systick = cx.core.SYST; - - // Initialize the monotonic (SysTick rate in QEMU is 12 MHz) - let mut mono = Systick::new(systick, 12_000_000); - - foo::spawn_after(1.secs(), mono.now()).unwrap(); - - (Shared {}, Local {}, init::Monotonics(mono)) - } - - #[task(local = [cnt: u32 = 0])] - fn foo(cx: foo::Context, instant: fugit::TimerInstantU64<100>) { - hprintln!("foo {:?}", instant); - *cx.local.cnt += 1; - - if *cx.local.cnt == 4 { - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - } - - // Periodic ever 1 seconds - let next_instant = instant + 1.secs(); - foo::spawn_at(next_instant, next_instant).unwrap(); - } -} diff --git a/examples/periodic-at2.rs b/examples/periodic-at2.rs deleted file mode 100644 index 4719bdb..0000000 --- a/examples/periodic-at2.rs +++ /dev/null @@ -1,62 +0,0 @@ -//! examples/periodic-at2.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use systick_monotonic::*; - - #[monotonic(binds = SysTick, default = true)] - type MyMono = Systick<100>; // 100 Hz / 10 ms granularity - - #[shared] - struct Shared {} - - #[local] - struct Local {} - - #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - let systick = cx.core.SYST; - - // Initialize the monotonic (SysTick rate in QEMU is 12 MHz) - let mut mono = Systick::new(systick, 12_000_000); - - foo::spawn_after(1.secs(), mono.now()).unwrap(); - - (Shared {}, Local {}, init::Monotonics(mono)) - } - - // Using the explicit type of the timer implementation - #[task(local = [cnt: u32 = 0])] - fn foo(cx: foo::Context, instant: fugit::TimerInstantU64<100>) { - hprintln!("foo {:?}", instant); - *cx.local.cnt += 1; - - if *cx.local.cnt == 4 { - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - } - - // Spawn a new message with 100 ms offset to spawned time - let next_instant = instant + 100.millis(); - bar::spawn_at(next_instant, next_instant).unwrap(); - } - - // Using the Instant from the Monotonic trait - // This remains agnostic to the timer implementation - #[task(local = [cnt: u32 = 0])] - fn bar(_cx: bar::Context, instant: <MyMono as rtic_monotonic::Monotonic>::Instant) { - hprintln!("bar {:?}", instant); - - // Spawn a new message with 1s offset to spawned time - let next_instant = instant + 1.secs(); - foo::spawn_at(next_instant, next_instant).unwrap(); - } -} diff --git a/examples/periodic.rs b/examples/periodic.rs deleted file mode 100644 index 13ca7c8..0000000 --- a/examples/periodic.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! examples/periodic.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use systick_monotonic::*; - - #[monotonic(binds = SysTick, default = true)] - type MyMono = Systick<100>; // 100 Hz / 10 ms granularity - - #[shared] - struct Shared {} - - #[local] - struct Local {} - - #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - let systick = cx.core.SYST; - - // Initialize the monotonic (SysTick rate in QEMU is 12 MHz) - let mono = Systick::new(systick, 12_000_000); - - foo::spawn_after(1.secs()).unwrap(); - - (Shared {}, Local {}, init::Monotonics(mono)) - } - - #[task(local = [cnt: u32 = 0])] - fn foo(cx: foo::Context) { - hprintln!("foo"); - *cx.local.cnt += 1; - - if *cx.local.cnt == 4 { - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - } - - // Periodic ever 1 seconds - foo::spawn_after(1.secs()).unwrap(); - } -} diff --git a/examples/schedule.rs b/examples/schedule.rs deleted file mode 100644 index 9b86929..0000000 --- a/examples/schedule.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! examples/schedule.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use cortex_m_semihosting::{debug, hprintln}; - use systick_monotonic::*; - - #[monotonic(binds = SysTick, default = true)] - type MyMono = Systick<100>; // 100 Hz / 10 ms granularity - - #[shared] - struct Shared {} - - #[local] - struct Local {} - - #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - let systick = cx.core.SYST; - - // Initialize the monotonic (SysTick rate in QEMU is 12 MHz) - let mono = Systick::new(systick, 12_000_000); - - hprintln!("init"); - - // Schedule `foo` to run 1 second in the future - foo::spawn_after(1.secs()).unwrap(); - - ( - Shared {}, - Local {}, - init::Monotonics(mono), // Give the monotonic to RTIC - ) - } - - #[task] - fn foo(_: foo::Context) { - hprintln!("foo"); - - // Schedule `bar` to run 2 seconds in the future (1 second after foo runs) - bar::spawn_after(1.secs()).unwrap(); - } - - #[task] - fn bar(_: bar::Context) { - hprintln!("bar"); - - // Schedule `baz` to run 1 seconds from now, but with a specific time instant. - baz::spawn_at(monotonics::now() + 1.secs()).unwrap(); - } - - #[task] - fn baz(_: baz::Context) { - hprintln!("baz"); - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - } -} diff --git a/examples/t-schedule.rs b/examples/t-schedule.rs deleted file mode 100644 index f3979dd..0000000 --- a/examples/t-schedule.rs +++ /dev/null @@ -1,137 +0,0 @@ -//! [compile-pass] Check `schedule` code generation - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use cortex_m_semihosting::debug; - use systick_monotonic::*; - - #[monotonic(binds = SysTick, default = true)] - type MyMono = Systick<100>; // 100 Hz / 10 ms granularity - - #[shared] - struct Shared {} - - #[local] - struct Local {} - - #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - let systick = cx.core.SYST; - - // Initialize the monotonic (SysTick rate in QEMU is 12 MHz) - let mono = Systick::new(systick, 12_000_000); - - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - - (Shared {}, Local {}, init::Monotonics(mono)) - } - - #[idle] - fn idle(_: idle::Context) -> ! { - // Task without message passing - - // Not default - let _: Result<foo::MyMono::SpawnHandle, ()> = - foo::MyMono::spawn_at(monotonics::MyMono::now()); - let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(1.secs()); - let _: Result<foo::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs()); - - let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(1.secs()); - let _: Result<foo::MyMono::SpawnHandle, ()> = - handle.unwrap().reschedule_at(monotonics::MyMono::now()); - - let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(1.secs()); - let _: Result<(), ()> = handle.unwrap().cancel(); - - // Using default - let _: Result<foo::SpawnHandle, ()> = foo::spawn_at(monotonics::now()); - let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(1.secs()); - let _: Result<foo::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs()); - - let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(1.secs()); - let _: Result<foo::SpawnHandle, ()> = - handle.unwrap().reschedule_at(monotonics::MyMono::now()); - - let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(1.secs()); - let _: Result<(), ()> = handle.unwrap().cancel(); - - // Task with single message passing - - // Not default - let _: Result<bar::MyMono::SpawnHandle, u32> = - bar::MyMono::spawn_at(monotonics::MyMono::now(), 0); - let handle: Result<bar::MyMono::SpawnHandle, u32> = bar::MyMono::spawn_after(1.secs(), 1); - let _: Result<bar::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs()); - - let handle: Result<bar::MyMono::SpawnHandle, u32> = bar::MyMono::spawn_after(1.secs(), 1); - let _: Result<bar::MyMono::SpawnHandle, ()> = - handle.unwrap().reschedule_at(monotonics::MyMono::now()); - - let handle: Result<bar::MyMono::SpawnHandle, u32> = bar::MyMono::spawn_after(1.secs(), 1); - let _: Result<u32, ()> = handle.unwrap().cancel(); - - // Using default - let _: Result<bar::SpawnHandle, u32> = bar::spawn_at(monotonics::MyMono::now(), 0); - let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(1.secs(), 1); - let _: Result<bar::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs()); - - let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(1.secs(), 1); - let _: Result<bar::SpawnHandle, ()> = - handle.unwrap().reschedule_at(monotonics::MyMono::now()); - - let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(1.secs(), 1); - let _: Result<u32, ()> = handle.unwrap().cancel(); - - // Task with multiple message passing - - // Not default - let _: Result<baz::MyMono::SpawnHandle, (u32, u32)> = - baz::MyMono::spawn_at(monotonics::MyMono::now(), 0, 1); - let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> = - baz::MyMono::spawn_after(1.secs(), 1, 2); - let _: Result<baz::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs()); - - let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> = - baz::MyMono::spawn_after(1.secs(), 1, 2); - let _: Result<baz::MyMono::SpawnHandle, ()> = - handle.unwrap().reschedule_at(monotonics::MyMono::now()); - - let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> = - baz::MyMono::spawn_after(1.secs(), 1, 2); - let _: Result<(u32, u32), ()> = handle.unwrap().cancel(); - - // Using default - let _: Result<baz::SpawnHandle, (u32, u32)> = - baz::spawn_at(monotonics::MyMono::now(), 0, 1); - let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(1.secs(), 1, 2); - let _: Result<baz::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs()); - - let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(1.secs(), 1, 2); - let _: Result<baz::SpawnHandle, ()> = - handle.unwrap().reschedule_at(monotonics::MyMono::now()); - - let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(1.secs(), 1, 2); - let _: Result<(u32, u32), ()> = handle.unwrap().cancel(); - - loop { - cortex_m::asm::nop(); - } - } - - #[task] - fn foo(_: foo::Context) {} - - #[task] - fn bar(_: bar::Context, _x: u32) {} - - #[task] - fn baz(_: baz::Context, _x: u32, _y: u32) {} -} diff --git a/examples/t-spawn.rs b/examples/t-spawn.rs deleted file mode 100644 index 7483a84..0000000 --- a/examples/t-spawn.rs +++ /dev/null @@ -1,69 +0,0 @@ -//! [compile-pass] Check code generation of `spawn` - -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![no_main] -#![no_std] - -use panic_semihosting as _; - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use cortex_m_semihosting::debug; - - #[shared] - struct Shared {} - - #[local] - struct Local {} - - #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { - let _: Result<(), ()> = foo::spawn(); - let _: Result<(), u32> = bar::spawn(0); - let _: Result<(), (u32, u32)> = baz::spawn(0, 1); - - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - - (Shared {}, Local {}, init::Monotonics()) - } - - #[idle] - fn idle(_: idle::Context) -> ! { - let _: Result<(), ()> = foo::spawn(); - let _: Result<(), u32> = bar::spawn(0); - let _: Result<(), (u32, u32)> = baz::spawn(0, 1); - - loop { - cortex_m::asm::nop(); - } - } - - #[task(binds = SVCall)] - fn svcall(_: svcall::Context) { - let _: Result<(), ()> = foo::spawn(); - let _: Result<(), u32> = bar::spawn(0); - let _: Result<(), (u32, u32)> = baz::spawn(0, 1); - } - - #[task(binds = UART0)] - fn uart0(_: uart0::Context) { - let _: Result<(), ()> = foo::spawn(); - let _: Result<(), u32> = bar::spawn(0); - let _: Result<(), (u32, u32)> = baz::spawn(0, 1); - } - - #[task] - fn foo(_: foo::Context) { - let _: Result<(), ()> = foo::spawn(); - let _: Result<(), u32> = bar::spawn(0); - let _: Result<(), (u32, u32)> = baz::spawn(0, 1); - } - - #[task] - fn bar(_: bar::Context, _x: u32) {} - - #[task] - fn baz(_: baz::Context, _x: u32, _y: u32) {} -} diff --git a/macros/Cargo.toml b/macros/Cargo.toml deleted file mode 100644 index c3f0561..0000000 --- a/macros/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -authors = [ - "The Real-Time Interrupt-driven Concurrency developers", - "Jorge Aparicio <jorge@japaric.io>", -] -categories = ["concurrency", "embedded", "no-std"] -description = "Procedural macros of the cortex-m-rtic crate" -documentation = "https://rtic-rs.github.io/cortex-m-rtic/api/cortex_m_rtic" -edition = "2021" -keywords = ["arm", "cortex-m"] -license = "MIT OR Apache-2.0" -name = "cortex-m-rtic-macros" -readme = "../README.md" -repository = "https://github.com/rtic-rs/cortex-m-rtic" -version = "1.1.6" - -[lib] -proc-macro = true - -[dependencies] -proc-macro2 = "1" -proc-macro-error = "1" -quote = "1" -syn = "1" -rtic-syntax = "1.0.3" - -[features] -debugprint = [] diff --git a/macros/src/check.rs b/macros/src/check.rs deleted file mode 100644 index b0ad6f8..0000000 --- a/macros/src/check.rs +++ /dev/null @@ -1,86 +0,0 @@ -use std::collections::HashSet; - -use proc_macro2::Span; -use rtic_syntax::{analyze::Analysis, ast::App}; -use syn::{parse, Path}; - -pub struct Extra { - pub device: Path, - pub peripherals: bool, -} - -pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<Extra> { - // Check that external (device-specific) interrupts are not named after known (Cortex-M) - // exceptions - for name in app.args.extern_interrupts.keys() { - let name_s = name.to_string(); - - match &*name_s { - "NonMaskableInt" | "HardFault" | "MemoryManagement" | "BusFault" | "UsageFault" - | "SecureFault" | "SVCall" | "DebugMonitor" | "PendSV" | "SysTick" => { - return Err(parse::Error::new( - name.span(), - "Cortex-M exceptions can't be used as `extern` interrupts", - )); - } - - _ => {} - } - } - - // Check that there are enough external interrupts to dispatch the software tasks and the timer - // queue handler - let mut first = None; - let priorities = app - .software_tasks - .iter() - .map(|(name, task)| { - first = Some(name); - task.args.priority - }) - .collect::<HashSet<_>>(); - - let need = priorities.len(); - let given = app.args.extern_interrupts.len(); - if need > given { - let s = { - format!( - "not enough interrupts to dispatch \ - all software tasks (need: {}; given: {})", - need, given - ) - }; - - // If not enough tasks and first still is None, may cause - // "custom attribute panicked" due to unwrap on None - return Err(parse::Error::new(first.unwrap().span(), s)); - } - - // Check that all exceptions are valid; only exceptions with configurable priorities are - // accepted - for (name, task) in &app.hardware_tasks { - let name_s = task.args.binds.to_string(); - match &*name_s { - "NonMaskableInt" | "HardFault" => { - return Err(parse::Error::new( - name.span(), - "only exceptions with configurable priority can be used as hardware tasks", - )); - } - - _ => {} - } - } - - if let Some(device) = app.args.device.clone() { - Ok(Extra { - device, - peripherals: app.args.peripherals, - }) - } else { - Err(parse::Error::new( - Span::call_site(), - "a `device` argument must be specified in `#[rtic::app]`", - )) - } -} diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs deleted file mode 100644 index 89173d4..0000000 --- a/macros/src/codegen.rs +++ /dev/null @@ -1,213 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::ast::App; - -use crate::{analyze::Analysis, check::Extra}; - -mod assertions; -mod dispatchers; -mod hardware_tasks; -mod idle; -mod init; -mod local_resources; -mod local_resources_struct; -mod module; -mod post_init; -mod pre_init; -mod shared_resources; -mod shared_resources_struct; -mod software_tasks; -mod timer_queue; -mod util; - -#[allow(clippy::too_many_lines)] -pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { - let mut mod_app = vec![]; - let mut mains = vec![]; - let mut root = vec![]; - let mut user = vec![]; - - // Generate the `main` function - let assertion_stmts = assertions::codegen(app, analysis, extra); - - let pre_init_stmts = pre_init::codegen(app, analysis, extra); - - let (mod_app_init, root_init, user_init, call_init) = init::codegen(app, analysis, extra); - - let post_init_stmts = post_init::codegen(app, analysis); - - let (mod_app_idle, root_idle, user_idle, call_idle) = idle::codegen(app, analysis, extra); - - user.push(quote!( - #user_init - - #user_idle - )); - - root.push(quote!( - #(#root_init)* - - #(#root_idle)* - )); - - mod_app.push(quote!( - #mod_app_init - - #(#mod_app_idle)* - )); - - let main = util::suffixed("main"); - mains.push(quote!( - #[doc(hidden)] - mod rtic_ext { - use super::*; - #[no_mangle] - unsafe extern "C" fn #main() -> ! { - #(#assertion_stmts)* - - #(#pre_init_stmts)* - - #[inline(never)] - fn __rtic_init_resources<F>(f: F) where F: FnOnce() { - f(); - } - - // Wrap late_init_stmts in a function to ensure that stack space is reclaimed. - __rtic_init_resources(||{ - #call_init - - #(#post_init_stmts)* - }); - - #call_idle - } - } - )); - - let (mod_app_shared_resources, mod_shared_resources) = - shared_resources::codegen(app, analysis, extra); - let (mod_app_local_resources, mod_local_resources) = - local_resources::codegen(app, analysis, extra); - - let (mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) = - hardware_tasks::codegen(app, analysis, extra); - - let (mod_app_software_tasks, root_software_tasks, user_software_tasks) = - software_tasks::codegen(app, analysis, extra); - - let mod_app_dispatchers = dispatchers::codegen(app, analysis, extra); - let mod_app_timer_queue = timer_queue::codegen(app, analysis, extra); - let user_imports = &app.user_imports; - let user_code = &app.user_code; - let name = &app.name; - let device = &extra.device; - - let monotonic_parts: Vec<_> = app - .monotonics - .iter() - .map(|(_, monotonic)| { - let name = &monotonic.ident; - let name_str = &name.to_string(); - let cfgs = &monotonic.cfgs; - let ident = util::monotonic_ident(name_str); - let doc = &format!( - "This module holds the static implementation for `{}::now()`", - name_str - ); - - let default_monotonic = if monotonic.args.default { - quote!( - #(#cfgs)* - pub use #name::now; - ) - } else { - quote!() - }; - - quote! { - #default_monotonic - - #[doc = #doc] - #[allow(non_snake_case)] - #(#cfgs)* - pub mod #name { - - /// Read the current time from this monotonic - pub fn now() -> <super::super::#name as rtic::Monotonic>::Instant { - rtic::export::interrupt::free(|_| { - use rtic::Monotonic as _; - if let Some(m) = unsafe{ &mut *super::super::#ident.get_mut() } { - m.now() - } else { - <super::super::#name as rtic::Monotonic>::zero() - } - }) - } - } - } - }) - .collect(); - - let monotonics = if monotonic_parts.is_empty() { - quote!() - } else { - quote!( - pub use rtic::Monotonic as _; - - /// Holds static methods for each monotonic. - pub mod monotonics { - #(#monotonic_parts)* - } - ) - }; - let rt_err = util::rt_err_ident(); - - quote!( - /// The RTIC application module - pub mod #name { - /// Always include the device crate which contains the vector table - use #device as #rt_err; - - #monotonics - - #(#user_imports)* - - /// User code from within the module - #(#user_code)* - /// User code end - - #(#user)* - - #(#user_hardware_tasks)* - - #(#user_software_tasks)* - - #(#root)* - - #mod_shared_resources - - #mod_local_resources - - #(#root_hardware_tasks)* - - #(#root_software_tasks)* - - /// App module - #(#mod_app)* - - #(#mod_app_shared_resources)* - - #(#mod_app_local_resources)* - - #(#mod_app_hardware_tasks)* - - #(#mod_app_software_tasks)* - - #(#mod_app_dispatchers)* - - #(#mod_app_timer_queue)* - - #(#mains)* - } - ) -} diff --git a/macros/src/codegen/assertions.rs b/macros/src/codegen/assertions.rs deleted file mode 100644 index 3e0ad61..0000000 --- a/macros/src/codegen/assertions.rs +++ /dev/null @@ -1,60 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; - -use crate::{analyze::Analysis, check::Extra, codegen::util}; -use rtic_syntax::ast::App; - -/// Generates compile-time assertions that check that types implement the `Send` / `Sync` traits -pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream2> { - let mut stmts = vec![]; - - for ty in &analysis.send_types { - stmts.push(quote!(rtic::export::assert_send::<#ty>();)); - } - - for ty in &analysis.sync_types { - stmts.push(quote!(rtic::export::assert_sync::<#ty>();)); - } - - for (_, monotonic) in &app.monotonics { - let ty = &monotonic.ty; - stmts.push(quote!(rtic::export::assert_monotonic::<#ty>();)); - } - - let device = &extra.device; - let chunks_name = util::priority_mask_chunks_ident(); - let no_basepri_checks: Vec<_> = app - .hardware_tasks - .iter() - .filter_map(|(_, task)| { - if !util::is_exception(&task.args.binds) { - let interrupt_name = &task.args.binds; - let cfgs = &task.cfgs; - Some(quote!( - #(#cfgs)* - if (#device::Interrupt::#interrupt_name as usize) >= (#chunks_name * 32) { - ::core::panic!("An interrupt out of range is used while in armv6 or armv8m.base"); - } - )) - } else { - None - } - }) - .collect(); - - let const_check = quote! { - const _CONST_CHECK: () = { - if !rtic::export::have_basepri() { - #(#no_basepri_checks)* - } else { - // TODO: Add armv7 checks here - } - }; - - let _ = _CONST_CHECK; - }; - - stmts.push(const_check); - - stmts -} diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs deleted file mode 100644 index a90a97c..0000000 --- a/macros/src/codegen/dispatchers.rs +++ /dev/null @@ -1,125 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::ast::App; - -use crate::{analyze::Analysis, check::Extra, codegen::util}; - -/// Generates task dispatchers -pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStream2> { - let mut items = vec![]; - - let interrupts = &analysis.interrupts; - - for (&level, channel) in &analysis.channels { - let mut stmts = vec![]; - - let variants = channel - .tasks - .iter() - .map(|name| { - let cfgs = &app.software_tasks[name].cfgs; - - quote!( - #(#cfgs)* - #name - ) - }) - .collect::<Vec<_>>(); - - // For future use - // let doc = format!( - // "Software tasks to be dispatched at priority level {}", - // level, - // ); - let t = util::spawn_t_ident(level); - items.push(quote!( - #[allow(non_snake_case)] - #[allow(non_camel_case_types)] - #[derive(Clone, Copy)] - // #[doc = #doc] - #[doc(hidden)] - pub enum #t { - #(#variants,)* - } - )); - - let n = util::capacity_literal(channel.capacity as usize + 1); - let rq = util::rq_ident(level); - let (rq_ty, rq_expr) = { - ( - quote!(rtic::export::SCRQ<#t, #n>), - quote!(rtic::export::Queue::new()), - ) - }; - - // For future use - // let doc = format!( - // "Queue of tasks ready to be dispatched at priority level {}", - // level - // ); - items.push(quote!( - #[doc(hidden)] - #[allow(non_camel_case_types)] - #[allow(non_upper_case_globals)] - static #rq: rtic::RacyCell<#rq_ty> = rtic::RacyCell::new(#rq_expr); - )); - - let arms = channel - .tasks - .iter() - .map(|name| { - let task = &app.software_tasks[name]; - let cfgs = &task.cfgs; - let fq = util::fq_ident(name); - let inputs = util::inputs_ident(name); - let (_, tupled, pats, _) = util::regroup_inputs(&task.inputs); - - quote!( - #(#cfgs)* - #t::#name => { - let #tupled = - (&*#inputs - .get()) - .get_unchecked(usize::from(index)) - .as_ptr() - .read(); - (&mut *#fq.get_mut()).split().0.enqueue_unchecked(index); - let priority = &rtic::export::Priority::new(PRIORITY); - #name( - #name::Context::new(priority) - #(,#pats)* - ) - } - ) - }) - .collect::<Vec<_>>(); - - stmts.push(quote!( - while let Some((task, index)) = (&mut *#rq.get_mut()).split().1.dequeue() { - match task { - #(#arms)* - } - } - )); - - let doc = format!("Interrupt handler to dispatch tasks at priority {}", level); - let interrupt = util::suffixed(&interrupts[&level].0.to_string()); - let attribute = &interrupts[&level].1.attrs; - items.push(quote!( - #[allow(non_snake_case)] - #[doc = #doc] - #[no_mangle] - #(#attribute)* - unsafe fn #interrupt() { - /// The priority of this interrupt handler - const PRIORITY: u8 = #level; - - rtic::export::run(PRIORITY, || { - #(#stmts)* - }); - } - )); - } - - items -} diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs deleted file mode 100644 index b3f05d2..0000000 --- a/macros/src/codegen/hardware_tasks.rs +++ /dev/null @@ -1,115 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::{ast::App, Context}; - -use crate::{ - analyze::Analysis, - check::Extra, - codegen::{local_resources_struct, module, shared_resources_struct}, -}; - -/// Generate support code for hardware tasks (`#[exception]`s and `#[interrupt]`s) -pub fn codegen( - app: &App, - analysis: &Analysis, - extra: &Extra, -) -> ( - // mod_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors - Vec<TokenStream2>, - // root_hardware_tasks -- items that must be placed in the root of the crate: - // - `${task}Locals` structs - // - `${task}Resources` structs - // - `${task}` modules - Vec<TokenStream2>, - // user_hardware_tasks -- the `#[task]` functions written by the user - Vec<TokenStream2>, -) { - let mut mod_app = vec![]; - let mut root = vec![]; - let mut user_tasks = vec![]; - - for (name, task) in &app.hardware_tasks { - let symbol = task.args.binds.clone(); - let priority = task.args.priority; - let cfgs = &task.cfgs; - let attrs = &task.attrs; - let user_hardware_task_isr_doc = &format!(" User HW task ISR trampoline for {name}"); - - mod_app.push(quote!( - #[allow(non_snake_case)] - #[no_mangle] - #[doc = #user_hardware_task_isr_doc] - #(#attrs)* - #(#cfgs)* - unsafe fn #symbol() { - const PRIORITY: u8 = #priority; - - rtic::export::run(PRIORITY, || { - #name( - #name::Context::new(&rtic::export::Priority::new(PRIORITY)) - ) - }); - } - )); - - let mut shared_needs_lt = false; - let mut local_needs_lt = false; - - // `${task}Locals` - if !task.args.local_resources.is_empty() { - let (item, constructor) = local_resources_struct::codegen( - Context::HardwareTask(name), - &mut local_needs_lt, - app, - ); - - root.push(item); - - mod_app.push(constructor); - } - - // `${task}Resources` - if !task.args.shared_resources.is_empty() { - let (item, constructor) = shared_resources_struct::codegen( - Context::HardwareTask(name), - &mut shared_needs_lt, - app, - ); - - root.push(item); - - mod_app.push(constructor); - } - - root.push(module::codegen( - Context::HardwareTask(name), - shared_needs_lt, - local_needs_lt, - app, - analysis, - extra, - )); - - let user_hardware_task_doc = &format!(" User HW task: {name}"); - if !task.is_extern { - let attrs = &task.attrs; - let cfgs = &task.cfgs; - let context = &task.context; - let stmts = &task.stmts; - user_tasks.push(quote!( - #[doc = #user_hardware_task_doc] - #(#attrs)* - #(#cfgs)* - #[allow(non_snake_case)] - fn #name(#context: #name::Context) { - use rtic::Mutex as _; - use rtic::mutex::prelude::*; - - #(#stmts)* - } - )); - } - } - - (mod_app, root, user_tasks) -} diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs deleted file mode 100644 index 77a7f9f..0000000 --- a/macros/src/codegen/idle.rs +++ /dev/null @@ -1,94 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::{ast::App, Context}; - -use crate::{ - analyze::Analysis, - check::Extra, - codegen::{local_resources_struct, module, shared_resources_struct}, -}; - -/// Generates support code for `#[idle]` functions -pub fn codegen( - app: &App, - analysis: &Analysis, - extra: &Extra, -) -> ( - // mod_app_idle -- the `${idle}Resources` constructor - Vec<TokenStream2>, - // root_idle -- items that must be placed in the root of the crate: - // - the `${idle}Locals` struct - // - the `${idle}Resources` struct - // - the `${idle}` module, which contains types like `${idle}::Context` - Vec<TokenStream2>, - // user_idle - Option<TokenStream2>, - // call_idle - TokenStream2, -) { - if let Some(idle) = &app.idle { - let mut shared_needs_lt = false; - let mut local_needs_lt = false; - let mut mod_app = vec![]; - let mut root_idle = vec![]; - - let name = &idle.name; - - if !idle.args.shared_resources.is_empty() { - let (item, constructor) = - shared_resources_struct::codegen(Context::Idle, &mut shared_needs_lt, app); - - root_idle.push(item); - mod_app.push(constructor); - } - - if !idle.args.local_resources.is_empty() { - let (item, constructor) = - local_resources_struct::codegen(Context::Idle, &mut local_needs_lt, app); - - root_idle.push(item); - - mod_app.push(constructor); - } - - root_idle.push(module::codegen( - Context::Idle, - shared_needs_lt, - local_needs_lt, - app, - analysis, - extra, - )); - let idle_doc = " User provided idle function".to_string(); - - let attrs = &idle.attrs; - let context = &idle.context; - let stmts = &idle.stmts; - let user_idle = Some(quote!( - #(#attrs)* - #[doc = #idle_doc] - #[allow(non_snake_case)] - fn #name(#context: #name::Context) -> ! { - use rtic::Mutex as _; - use rtic::mutex::prelude::*; - - #(#stmts)* - } - )); - - let call_idle = quote!(#name( - #name::Context::new(&rtic::export::Priority::new(0)) - )); - - (mod_app, root_idle, user_idle, call_idle) - } else { - ( - vec![], - vec![], - None, - quote!(loop { - rtic::export::nop() - }), - ) - } -} diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs deleted file mode 100644 index 8dcdbcf..0000000 --- a/macros/src/codegen/module.rs +++ /dev/null @@ -1,468 +0,0 @@ -use crate::{analyze::Analysis, check::Extra, codegen::util}; -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::{ast::App, Context}; - -#[allow(clippy::too_many_lines)] -pub fn codegen( - ctxt: Context, - shared_resources_tick: bool, - local_resources_tick: bool, - app: &App, - analysis: &Analysis, - extra: &Extra, -) -> TokenStream2 { - let mut items = vec![]; - let mut module_items = vec![]; - let mut fields = vec![]; - let mut values = vec![]; - - let name = ctxt.ident(app); - - let mut lt = None; - match ctxt { - Context::Init => { - fields.push(quote!( - /// Core (Cortex-M) peripherals - pub core: rtic::export::Peripherals - )); - - if extra.peripherals { - let device = &extra.device; - - fields.push(quote!( - /// Device peripherals - pub device: #device::Peripherals - )); - - values.push(quote!(device: #device::Peripherals::steal())); - } - - lt = Some(quote!('a)); - fields.push(quote!( - /// Critical section token for init - pub cs: rtic::export::CriticalSection<#lt> - )); - - values.push(quote!(cs: rtic::export::CriticalSection::new())); - - values.push(quote!(core)); - } - - Context::Idle | Context::HardwareTask(_) | Context::SoftwareTask(_) => {} - } - - // if ctxt.has_locals(app) { - // let ident = util::locals_ident(ctxt, app); - // module_items.push(quote!( - // #[doc(inline)] - // pub use super::#ident as Locals; - // )); - // } - - if ctxt.has_local_resources(app) { - let ident = util::local_resources_ident(ctxt, app); - let lt = if local_resources_tick { - lt = Some(quote!('a)); - Some(quote!('a)) - } else { - None - }; - - module_items.push(quote!( - #[doc(inline)] - pub use super::#ident as LocalResources; - )); - - fields.push(quote!( - /// Local Resources this task has access to - pub local: #name::LocalResources<#lt> - )); - - values.push(quote!(local: #name::LocalResources::new())); - } - - if ctxt.has_shared_resources(app) { - let ident = util::shared_resources_ident(ctxt, app); - let lt = if shared_resources_tick { - lt = Some(quote!('a)); - Some(quote!('a)) - } else { - None - }; - - module_items.push(quote!( - #[doc(inline)] - pub use super::#ident as SharedResources; - )); - - fields.push(quote!( - /// Shared Resources this task has access to - pub shared: #name::SharedResources<#lt> - )); - - let priority = if ctxt.is_init() { - None - } else { - Some(quote!(priority)) - }; - values.push(quote!(shared: #name::SharedResources::new(#priority))); - } - - if let Context::Init = ctxt { - let monotonic_types: Vec<_> = app - .monotonics - .iter() - .map(|(_, monotonic)| { - let cfgs = &monotonic.cfgs; - let mono = &monotonic.ty; - quote! { - #(#cfgs)* - pub #mono - } - }) - .collect(); - - let internal_monotonics_ident = util::mark_internal_name("Monotonics"); - - items.push(quote!( - /// Monotonics used by the system - #[allow(non_snake_case)] - #[allow(non_camel_case_types)] - pub struct #internal_monotonics_ident( - #(#monotonic_types),* - ); - )); - - module_items.push(quote!( - #[doc(inline)] - pub use super::#internal_monotonics_ident as Monotonics; - )); - } - - let doc = match ctxt { - Context::Idle => " Idle loop", - Context::Init => " Initialization function", - Context::HardwareTask(_) => " Hardware task", - Context::SoftwareTask(_) => " Software task", - }; - - let v = Vec::new(); - let cfgs = match ctxt { - Context::HardwareTask(t) => { - &app.hardware_tasks[t].cfgs - // ... - } - Context::SoftwareTask(t) => { - &app.software_tasks[t].cfgs - // ... - } - _ => &v, - }; - - let core = if ctxt.is_init() { - Some(quote!(core: rtic::export::Peripherals,)) - } else { - None - }; - - let priority = if ctxt.is_init() { - None - } else { - Some(quote!(priority: &#lt rtic::export::Priority)) - }; - - let internal_context_name = util::internal_task_ident(name, "Context"); - - items.push(quote!( - /// Execution context - #(#cfgs)* - #[allow(non_snake_case)] - #[allow(non_camel_case_types)] - pub struct #internal_context_name<#lt> { - #(#fields,)* - } - - #(#cfgs)* - impl<#lt> #internal_context_name<#lt> { - #[doc(hidden)] - #[inline(always)] - pub unsafe fn new(#core #priority) -> Self { - #internal_context_name { - #(#values,)* - } - } - } - )); - - module_items.push(quote!( - #[doc(inline)] - #(#cfgs)* - pub use super::#internal_context_name as Context; - )); - - if let Context::SoftwareTask(..) = ctxt { - let spawnee = &app.software_tasks[name]; - let priority = spawnee.args.priority; - let t = util::spawn_t_ident(priority); - let cfgs = &spawnee.cfgs; - let (args, tupled, untupled, ty) = util::regroup_inputs(&spawnee.inputs); - let args = &args; - let tupled = &tupled; - let fq = util::fq_ident(name); - let rq = util::rq_ident(priority); - let inputs = util::inputs_ident(name); - - let device = &extra.device; - let enum_ = util::interrupt_ident(); - let interrupt = &analysis - .interrupts - .get(&priority) - .expect("RTIC-ICE: interrupt identifer not found") - .0; - - let internal_spawn_ident = util::internal_task_ident(name, "spawn"); - - // Spawn caller - items.push(quote!( - - /// Spawns the task directly - #(#cfgs)* - pub fn #internal_spawn_ident(#(#args,)*) -> Result<(), #ty> { - let input = #tupled; - - unsafe { - if let Some(index) = rtic::export::interrupt::free(|_| (&mut *#fq.get_mut()).dequeue()) { - (&mut *#inputs - .get_mut()) - .get_unchecked_mut(usize::from(index)) - .as_mut_ptr() - .write(input); - - rtic::export::interrupt::free(|_| { - (&mut *#rq.get_mut()).enqueue_unchecked((#t::#name, index)); - }); - - rtic::pend(#device::#enum_::#interrupt); - - Ok(()) - } else { - Err(input) - } - } - - })); - - module_items.push(quote!( - #[doc(inline)] - #(#cfgs)* - pub use super::#internal_spawn_ident as spawn; - )); - - // Schedule caller - for (_, monotonic) in &app.monotonics { - let instants = util::monotonic_instants_ident(name, &monotonic.ident); - let monotonic_name = monotonic.ident.to_string(); - - let tq = util::tq_ident(&monotonic.ident.to_string()); - let t = util::schedule_t_ident(); - let m = &monotonic.ident; - let cfgs = &monotonic.cfgs; - let m_ident = util::monotonic_ident(&monotonic_name); - let m_isr = &monotonic.args.binds; - let enum_ = util::interrupt_ident(); - let spawn_handle_string = format!("{}::SpawnHandle", m); - - let (enable_interrupt, pend) = if &*m_isr.to_string() == "SysTick" { - ( - quote!(core::mem::transmute::<_, rtic::export::SYST>(()).enable_interrupt()), - quote!(rtic::export::SCB::set_pendst()), - ) - } else { - let rt_err = util::rt_err_ident(); - ( - quote!(rtic::export::NVIC::unmask(#rt_err::#enum_::#m_isr)), - quote!(rtic::pend(#rt_err::#enum_::#m_isr)), - ) - }; - - let tq_marker = &util::timer_queue_marker_ident(); - - // For future use - // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); - // items.push(quote!(#[doc = #doc])); - let internal_spawn_handle_ident = - util::internal_monotonics_ident(name, m, "SpawnHandle"); - let internal_spawn_at_ident = util::internal_monotonics_ident(name, m, "spawn_at"); - let internal_spawn_after_ident = - util::internal_monotonics_ident(name, m, "spawn_after"); - - if monotonic.args.default { - module_items.push(quote!( - #(#cfgs)* - pub use #m::spawn_after; - #(#cfgs)* - pub use #m::spawn_at; - #(#cfgs)* - pub use #m::SpawnHandle; - )); - } - module_items.push(quote!( - #[doc(hidden)] - #(#cfgs)* - pub mod #m { - pub use super::super::#internal_spawn_after_ident as spawn_after; - pub use super::super::#internal_spawn_at_ident as spawn_at; - pub use super::super::#internal_spawn_handle_ident as SpawnHandle; - } - )); - - items.push(quote!( - #[doc(hidden)] - #(#cfgs)* - #[allow(non_snake_case)] - #[allow(non_camel_case_types)] - pub struct #internal_spawn_handle_ident { - #[doc(hidden)] - marker: u32, - } - - #(#cfgs)* - impl core::fmt::Debug for #internal_spawn_handle_ident { - #[doc(hidden)] - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct(#spawn_handle_string).finish() - } - } - - #(#cfgs)* - impl #internal_spawn_handle_ident { - pub fn cancel(self) -> Result<#ty, ()> { - rtic::export::interrupt::free(|_| unsafe { - let tq = &mut *#tq.get_mut(); - if let Some((_task, index)) = tq.cancel_marker(self.marker) { - // Get the message - let msg = (&*#inputs - .get()) - .get_unchecked(usize::from(index)) - .as_ptr() - .read(); - // Return the index to the free queue - (&mut *#fq.get_mut()).split().0.enqueue_unchecked(index); - - Ok(msg) - } else { - Err(()) - } - }) - } - - /// Reschedule after - #[inline] - #(#cfgs)* - pub fn reschedule_after( - self, - duration: <#m as rtic::Monotonic>::Duration - ) -> Result<Self, ()> { - self.reschedule_at(monotonics::#m::now() + duration) - } - - /// Reschedule at - #(#cfgs)* - pub fn reschedule_at( - self, - instant: <#m as rtic::Monotonic>::Instant - ) -> Result<Self, ()> { - rtic::export::interrupt::free(|_| unsafe { - let marker = #tq_marker.get().read(); - #tq_marker.get_mut().write(marker.wrapping_add(1)); - - let tq = (&mut *#tq.get_mut()); - - tq.update_marker(self.marker, marker, instant, || #pend).map(|_| #name::#m::SpawnHandle { marker }) - }) - } - } - - /// Spawns the task after a set duration relative to the current time - /// - /// This will use the time `Instant::new(0)` as baseline if called in `#[init]`, - /// so if you use a non-resetable timer use `spawn_at` when in `#[init]` - #(#cfgs)* - #[allow(non_snake_case)] - pub fn #internal_spawn_after_ident( - duration: <#m as rtic::Monotonic>::Duration - #(,#args)* - ) -> Result<#name::#m::SpawnHandle, #ty> - { - let instant = monotonics::#m::now(); - - #internal_spawn_at_ident(instant + duration #(,#untupled)*) - } - - #(#cfgs)* - /// Spawns the task at a fixed time instant - #[allow(non_snake_case)] - pub fn #internal_spawn_at_ident( - instant: <#m as rtic::Monotonic>::Instant - #(,#args)* - ) -> Result<#name::#m::SpawnHandle, #ty> { - unsafe { - let input = #tupled; - if let Some(index) = rtic::export::interrupt::free(|_| (&mut *#fq.get_mut()).dequeue()) { - (&mut *#inputs - .get_mut()) - .get_unchecked_mut(usize::from(index)) - .as_mut_ptr() - .write(input); - - (&mut *#instants - .get_mut()) - .get_unchecked_mut(usize::from(index)) - .as_mut_ptr() - .write(instant); - - rtic::export::interrupt::free(|_| { - let marker = #tq_marker.get().read(); - let nr = rtic::export::NotReady { - instant, - index, - task: #t::#name, - marker, - }; - - #tq_marker.get_mut().write(#tq_marker.get().read().wrapping_add(1)); - - let tq = &mut *#tq.get_mut(); - - tq.enqueue_unchecked( - nr, - || #enable_interrupt, - || #pend, - (&mut *#m_ident.get_mut()).as_mut()); - - Ok(#name::#m::SpawnHandle { marker }) - }) - } else { - Err(input) - } - } - } - )); - } - } - - if items.is_empty() { - quote!() - } else { - quote!( - #(#items)* - #[allow(non_snake_case)] - #(#cfgs)* - #[doc = #doc] - pub mod #name { - #(#module_items)* - } - ) - } -} diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs deleted file mode 100644 index 2362cb7..0000000 --- a/macros/src/codegen/pre_init.rs +++ /dev/null @@ -1,147 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::ast::App; - -use crate::{analyze::Analysis, check::Extra, codegen::util}; - -/// Generates code that runs before `#[init]` -pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream2> { - let mut stmts = vec![]; - - let rt_err = util::rt_err_ident(); - - // Disable interrupts -- `init` must run with interrupts disabled - stmts.push(quote!(rtic::export::interrupt::disable();)); - - // Populate the FreeQueue - for (name, task) in &app.software_tasks { - let cap = task.args.capacity; - let cfgs = &task.cfgs; - let fq_ident = util::fq_ident(name); - - stmts.push(quote!( - #(#cfgs)* - (0..#cap).for_each(|i| (&mut *#fq_ident.get_mut()).enqueue_unchecked(i)); - )); - } - - stmts.push(quote!( - // To set the variable in cortex_m so the peripherals cannot be taken multiple times - let mut core: rtic::export::Peripherals = rtic::export::Peripherals::steal().into(); - )); - - let device = &extra.device; - let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS); - - // check that all dispatchers exists in the `Interrupt` enumeration regardless of whether - // they are used or not - let interrupt = util::interrupt_ident(); - for name in app.args.extern_interrupts.keys() { - stmts.push(quote!(let _ = #rt_err::#interrupt::#name;)); - } - - let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id)); - - // Unmask interrupts and set their priorities - for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().filter_map(|task| { - if util::is_exception(&task.args.binds) { - // We do exceptions in another pass - None - } else { - Some((&task.args.priority, &task.args.binds)) - } - })) { - let es = format!( - "Maximum priority used by interrupt vector '{}' is more than supported by hardware", - name - ); - // Compile time assert that this priority is supported by the device - stmts.push(quote!( - const _: () = if (1 << #nvic_prio_bits) < #priority as usize { ::core::panic!(#es); }; - )); - - stmts.push(quote!( - core.NVIC.set_priority( - #rt_err::#interrupt::#name, - rtic::export::logical2hw(#priority, #nvic_prio_bits), - ); - )); - - // NOTE unmask the interrupt *after* setting its priority: changing the priority of a pended - // interrupt is implementation defined - stmts.push(quote!(rtic::export::NVIC::unmask(#rt_err::#interrupt::#name);)); - } - - // Set exception priorities - for (name, priority) in app.hardware_tasks.values().filter_map(|task| { - if util::is_exception(&task.args.binds) { - Some((&task.args.binds, task.args.priority)) - } else { - None - } - }) { - let es = format!( - "Maximum priority used by interrupt vector '{}' is more than supported by hardware", - name - ); - // Compile time assert that this priority is supported by the device - stmts.push(quote!( - const _: () = if (1 << #nvic_prio_bits) < #priority as usize { ::core::panic!(#es); }; - )); - - stmts.push(quote!(core.SCB.set_priority( - rtic::export::SystemHandler::#name, - rtic::export::logical2hw(#priority, #nvic_prio_bits), - );)); - } - - // Initialize monotonic's interrupts - for (_, monotonic) in &app.monotonics { - let priority = if let Some(prio) = monotonic.args.priority { - quote! { #prio } - } else { - quote! { (1 << #nvic_prio_bits) } - }; - let binds = &monotonic.args.binds; - - let name = &monotonic.ident; - let es = format!( - "Maximum priority used by monotonic '{}' is more than supported by hardware", - name - ); - // Compile time assert that this priority is supported by the device - stmts.push(quote!( - const _: () = if (1 << #nvic_prio_bits) < #priority as usize { ::core::panic!(#es); }; - )); - - let mono_type = &monotonic.ty; - - if &*binds.to_string() == "SysTick" { - stmts.push(quote!( - core.SCB.set_priority( - rtic::export::SystemHandler::SysTick, - rtic::export::logical2hw(#priority, #nvic_prio_bits), - ); - - // Always enable monotonic interrupts if they should never be off - if !<#mono_type as rtic::Monotonic>::DISABLE_INTERRUPT_ON_EMPTY_QUEUE { - core::mem::transmute::<_, rtic::export::SYST>(()) - .enable_interrupt(); - } - )); - } else { - stmts.push(quote!( - core.NVIC.set_priority( - #rt_err::#interrupt::#binds, - rtic::export::logical2hw(#priority, #nvic_prio_bits), - ); - - // Always enable monotonic interrupts if they should never be off - if !<#mono_type as rtic::Monotonic>::DISABLE_INTERRUPT_ON_EMPTY_QUEUE { - rtic::export::NVIC::unmask(#rt_err::#interrupt::#binds); - } - )); - } - } - stmts -} diff --git a/macros/src/codegen/shared_resources.rs b/macros/src/codegen/shared_resources.rs deleted file mode 100644 index b5dff09..0000000 --- a/macros/src/codegen/shared_resources.rs +++ /dev/null @@ -1,196 +0,0 @@ -use crate::{analyze::Analysis, check::Extra, codegen::util}; -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::{analyze::Ownership, ast::App}; -use std::collections::HashMap; - -/// Generates `static` variables and shared resource proxies -pub fn codegen( - app: &App, - analysis: &Analysis, - extra: &Extra, -) -> ( - // mod_app -- the `static` variables behind the proxies - Vec<TokenStream2>, - // mod_resources -- the `resources` module - TokenStream2, -) { - let mut mod_app = vec![]; - let mut mod_resources = vec![]; - - for (name, res) in &app.shared_resources { - let cfgs = &res.cfgs; - let ty = &res.ty; - let mangled_name = &util::static_shared_resource_ident(name); - - let attrs = &res.attrs; - - // late resources in `util::link_section_uninit` - // unless user specifies custom link section - let section = if attrs.iter().any(|attr| attr.path.is_ident("link_section")) { - None - } else { - Some(util::link_section_uninit()) - }; - - // For future use - // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); - mod_app.push(quote!( - #[allow(non_camel_case_types)] - #[allow(non_upper_case_globals)] - // #[doc = #doc] - #[doc(hidden)] - #(#attrs)* - #(#cfgs)* - #section - static #mangled_name: rtic::RacyCell<core::mem::MaybeUninit<#ty>> = rtic::RacyCell::new(core::mem::MaybeUninit::uninit()); - )); - - // For future use - // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); - - let shared_name = util::need_to_lock_ident(name); - - if !res.properties.lock_free { - mod_resources.push(quote!( - // #[doc = #doc] - #[doc(hidden)] - #[allow(non_camel_case_types)] - #(#cfgs)* - pub struct #shared_name<'a> { - priority: &'a Priority, - } - - #(#cfgs)* - impl<'a> #shared_name<'a> { - #[inline(always)] - pub unsafe fn new(priority: &'a Priority) -> Self { - #shared_name { priority } - } - - #[inline(always)] - pub unsafe fn priority(&self) -> &Priority { - self.priority - } - } - )); - - let ptr = quote!( - #(#cfgs)* - #mangled_name.get_mut() as *mut _ - ); - - let ceiling = match analysis.ownerships.get(name) { - Some(Ownership::Owned { priority } | Ownership::CoOwned { priority }) => *priority, - Some(Ownership::Contended { ceiling }) => *ceiling, - None => 0, - }; - - // For future use - // let doc = format!(" RTIC internal ({} resource): {}:{}", doc, file!(), line!()); - - mod_app.push(util::impl_mutex( - extra, - cfgs, - true, - &shared_name, - "e!(#ty), - ceiling, - &ptr, - )); - } - } - - let mod_resources = if mod_resources.is_empty() { - quote!() - } else { - quote!(mod shared_resources { - use rtic::export::Priority; - - #(#mod_resources)* - }) - }; - - // Computing mapping of used interrupts to masks - let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id)); - - let mut prio_to_masks = HashMap::new(); - let device = &extra.device; - let mut uses_exceptions_with_resources = false; - - let mut mask_ids = Vec::new(); - - for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().flat_map(|task| { - if !util::is_exception(&task.args.binds) { - Some((&task.args.priority, &task.args.binds)) - } else { - // If any resource to the exception uses non-lock-free or non-local resources this is - // not allwed on thumbv6. - uses_exceptions_with_resources = uses_exceptions_with_resources - || task - .args - .shared_resources - .iter() - .map(|(ident, access)| { - if access.is_exclusive() { - if let Some(r) = app.shared_resources.get(ident) { - !r.properties.lock_free - } else { - false - } - } else { - false - } - }) - .any(|v| v); - - None - } - })) { - #[allow(clippy::or_fun_call)] - let v = prio_to_masks.entry(priority - 1).or_insert(Vec::new()); - v.push(quote!(#device::Interrupt::#name as u32)); - mask_ids.push(quote!(#device::Interrupt::#name as u32)); - } - - // Call rtic::export::create_mask([Mask; N]), where the array is the list of shifts - - let mut mask_arr = Vec::new(); - // NOTE: 0..3 assumes max 4 priority levels according to M0, M23 spec - for i in 0..3 { - let v = if let Some(v) = prio_to_masks.get(&i) { - v.clone() - } else { - Vec::new() - }; - - mask_arr.push(quote!( - rtic::export::create_mask([#(#v),*]) - )); - } - - // Generate a constant for the number of chunks needed by Mask. - let chunks_name = util::priority_mask_chunks_ident(); - mod_app.push(quote!( - #[doc(hidden)] - #[allow(non_upper_case_globals)] - const #chunks_name: usize = rtic::export::compute_mask_chunks([#(#mask_ids),*]); - )); - - let masks_name = util::priority_masks_ident(); - mod_app.push(quote!( - #[doc(hidden)] - #[allow(non_upper_case_globals)] - const #masks_name: [rtic::export::Mask<#chunks_name>; 3] = [#(#mask_arr),*]; - )); - - if uses_exceptions_with_resources { - mod_app.push(quote!( - #[doc(hidden)] - #[allow(non_upper_case_globals)] - const __rtic_internal_V6_ERROR: () = rtic::export::no_basepri_panic(); - )); - } - - (mod_app, mod_resources) -} diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs deleted file mode 100644 index 226121d..0000000 --- a/macros/src/codegen/software_tasks.rs +++ /dev/null @@ -1,159 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::{ast::App, Context}; - -use crate::{ - analyze::Analysis, - check::Extra, - codegen::{local_resources_struct, module, shared_resources_struct, util}, -}; - -pub fn codegen( - app: &App, - analysis: &Analysis, - extra: &Extra, -) -> ( - // mod_app_software_tasks -- free queues, buffers and `${task}Resources` constructors - Vec<TokenStream2>, - // root_software_tasks -- items that must be placed in the root of the crate: - // - `${task}Locals` structs - // - `${task}Resources` structs - // - `${task}` modules - Vec<TokenStream2>, - // user_software_tasks -- the `#[task]` functions written by the user - Vec<TokenStream2>, -) { - let mut mod_app = vec![]; - let mut root = vec![]; - let mut user_tasks = vec![]; - - for (name, task) in &app.software_tasks { - let inputs = &task.inputs; - let cfgs = &task.cfgs; - let (_, _, _, input_ty) = util::regroup_inputs(inputs); - - let cap = task.args.capacity; - let cap_lit = util::capacity_literal(cap as usize); - let cap_lit_p1 = util::capacity_literal(cap as usize + 1); - - // Create free queues and inputs / instants buffers - let fq = util::fq_ident(name); - - #[allow(clippy::redundant_closure)] - let (fq_ty, fq_expr, mk_uninit): (_, _, Box<dyn Fn() -> Option<_>>) = { - ( - quote!(rtic::export::SCFQ<#cap_lit_p1>), - quote!(rtic::export::Queue::new()), - Box::new(|| Some(util::link_section_uninit())), - ) - }; - mod_app.push(quote!( - // /// Queue version of a free-list that keeps track of empty slots in - // /// the following buffers - #(#cfgs)* - #[allow(non_camel_case_types)] - #[allow(non_upper_case_globals)] - #[doc(hidden)] - static #fq: rtic::RacyCell<#fq_ty> = rtic::RacyCell::new(#fq_expr); - )); - - let elems = &(0..cap) - .map(|_| quote!(core::mem::MaybeUninit::uninit())) - .collect::<Vec<_>>(); - - for (_, monotonic) in &app.monotonics { - let instants = util::monotonic_instants_ident(name, &monotonic.ident); - let mono_type = &monotonic.ty; - let cfgs = &monotonic.cfgs; - - let uninit = mk_uninit(); - // For future use - // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); - mod_app.push(quote!( - #uninit - // /// Buffer that holds the instants associated to the inputs of a task - // #[doc = #doc] - #[allow(non_camel_case_types)] - #[allow(non_upper_case_globals)] - #[doc(hidden)] - #(#cfgs)* - static #instants: - rtic::RacyCell<[core::mem::MaybeUninit<<#mono_type as rtic::Monotonic>::Instant>; #cap_lit]> = - rtic::RacyCell::new([#(#elems,)*]); - )); - } - - let uninit = mk_uninit(); - let inputs_ident = util::inputs_ident(name); - mod_app.push(quote!( - #uninit - // /// Buffer that holds the inputs of a task - #[allow(non_camel_case_types)] - #[allow(non_upper_case_globals)] - #[doc(hidden)] - #(#cfgs)* - static #inputs_ident: rtic::RacyCell<[core::mem::MaybeUninit<#input_ty>; #cap_lit]> = - rtic::RacyCell::new([#(#elems,)*]); - )); - - // `${task}Resources` - let mut shared_needs_lt = false; - let mut local_needs_lt = false; - - // `${task}Locals` - if !task.args.local_resources.is_empty() { - let (item, constructor) = local_resources_struct::codegen( - Context::SoftwareTask(name), - &mut local_needs_lt, - app, - ); - - root.push(item); - - mod_app.push(constructor); - } - - if !task.args.shared_resources.is_empty() { - let (item, constructor) = shared_resources_struct::codegen( - Context::SoftwareTask(name), - &mut shared_needs_lt, - app, - ); - - root.push(item); - - mod_app.push(constructor); - } - - if !&task.is_extern { - let context = &task.context; - let attrs = &task.attrs; - let cfgs = &task.cfgs; - let stmts = &task.stmts; - let user_task_doc = format!(" User SW task {name}"); - user_tasks.push(quote!( - #[doc = #user_task_doc] - #(#attrs)* - #(#cfgs)* - #[allow(non_snake_case)] - fn #name(#context: #name::Context #(,#inputs)*) { - use rtic::Mutex as _; - use rtic::mutex::prelude::*; - - #(#stmts)* - } - )); - } - - root.push(module::codegen( - Context::SoftwareTask(name), - shared_needs_lt, - local_needs_lt, - app, - analysis, - extra, - )); - } - - (mod_app, root, user_tasks) -} diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs deleted file mode 100644 index f5867dc..0000000 --- a/macros/src/codegen/timer_queue.rs +++ /dev/null @@ -1,167 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::ast::App; - -use crate::{analyze::Analysis, check::Extra, codegen::util}; - -/// Generates timer queues and timer queue handlers -#[allow(clippy::too_many_lines)] -pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStream2> { - let mut items = vec![]; - - if !app.monotonics.is_empty() { - // Generate the marker counter used to track for `cancel` and `reschedule` - let tq_marker = util::timer_queue_marker_ident(); - items.push(quote!( - #[doc(hidden)] - #[allow(non_camel_case_types)] - #[allow(non_upper_case_globals)] - static #tq_marker: rtic::RacyCell<u32> = rtic::RacyCell::new(0); - )); - - let t = util::schedule_t_ident(); - - // Enumeration of `schedule`-able tasks - { - let variants = app - .software_tasks - .iter() - .map(|(name, task)| { - let cfgs = &task.cfgs; - - quote!( - #(#cfgs)* - #name - ) - }) - .collect::<Vec<_>>(); - - // For future use - // let doc = "Tasks that can be scheduled".to_string(); - items.push(quote!( - // #[doc = #doc] - #[doc(hidden)] - #[allow(non_camel_case_types)] - #[derive(Clone, Copy)] - pub enum #t { - #(#variants,)* - } - )); - } - } - - for (_, monotonic) in &app.monotonics { - let monotonic_name = monotonic.ident.to_string(); - let tq = util::tq_ident(&monotonic_name); - let t = util::schedule_t_ident(); - let mono_type = &monotonic.ty; - let cfgs = &monotonic.cfgs; - let m_ident = util::monotonic_ident(&monotonic_name); - - // Static variables and resource proxy - { - // For future use - // let doc = &format!("Timer queue for {}", monotonic_name); - let cap: usize = app - .software_tasks - .iter() - .map(|(_name, task)| task.args.capacity as usize) - .sum(); - let n = util::capacity_literal(cap); - let tq_ty = quote!(rtic::export::TimerQueue<#mono_type, #t, #n>); - - // For future use - // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); - items.push(quote!( - #[doc(hidden)] - #[allow(non_camel_case_types)] - #[allow(non_upper_case_globals)] - #(#cfgs)* - static #tq: rtic::RacyCell<#tq_ty> = - rtic::RacyCell::new(rtic::export::TimerQueue(rtic::export::SortedLinkedList::new_u16())); - )); - - let mono = util::monotonic_ident(&monotonic_name); - // For future use - // let doc = &format!("Storage for {}", monotonic_name); - - items.push(quote!( - #[doc(hidden)] - #[allow(non_camel_case_types)] - #[allow(non_upper_case_globals)] - #(#cfgs)* - static #mono: rtic::RacyCell<Option<#mono_type>> = rtic::RacyCell::new(None); - )); - } - - // Timer queue handler - { - let enum_ = util::interrupt_ident(); - let rt_err = util::rt_err_ident(); - - let arms = app - .software_tasks - .iter() - .map(|(name, task)| { - let cfgs = &task.cfgs; - let priority = task.args.priority; - let rq = util::rq_ident(priority); - let rqt = util::spawn_t_ident(priority); - - // The interrupt that runs the task dispatcher - let interrupt = &analysis.interrupts.get(&priority).expect("RTIC-ICE: interrupt not found").0; - - let pend = { - quote!( - rtic::pend(#rt_err::#enum_::#interrupt); - ) - }; - - quote!( - #(#cfgs)* - #t::#name => { - rtic::export::interrupt::free(|_| (&mut *#rq.get_mut()).split().0.enqueue_unchecked((#rqt::#name, index))); - - #pend - } - ) - }) - .collect::<Vec<_>>(); - - let cfgs = &monotonic.cfgs; - let bound_interrupt = &monotonic.args.binds; - let disable_isr = if &*bound_interrupt.to_string() == "SysTick" { - quote!(core::mem::transmute::<_, rtic::export::SYST>(()).disable_interrupt()) - } else { - quote!(rtic::export::NVIC::mask(#rt_err::#enum_::#bound_interrupt)) - }; - - items.push(quote!( - #[no_mangle] - #[allow(non_snake_case)] - #(#cfgs)* - unsafe fn #bound_interrupt() { - while let Some((task, index)) = rtic::export::interrupt::free(|_| - if let Some(mono) = (&mut *#m_ident.get_mut()).as_mut() { - (&mut *#tq.get_mut()).dequeue(|| #disable_isr, mono) - } else { - // We can only use the timer queue if `init` has returned, and it - // writes the `Some(monotonic)` we are accessing here. - core::hint::unreachable_unchecked() - }) - { - match task { - #(#arms)* - } - } - - rtic::export::interrupt::free(|_| if let Some(mono) = (&mut *#m_ident.get_mut()).as_mut() { - mono.on_interrupt(); - }); - } - )); - } - } - - items -} diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs deleted file mode 100644 index 0a3edc2..0000000 --- a/macros/src/codegen/util.rs +++ /dev/null @@ -1,283 +0,0 @@ -use core::sync::atomic::{AtomicUsize, Ordering}; - -use proc_macro2::{Span, TokenStream as TokenStream2}; -use quote::quote; -use rtic_syntax::{ast::App, Context}; -use syn::{Attribute, Ident, LitInt, PatType}; - -use crate::check::Extra; - -const RTIC_INTERNAL: &str = "__rtic_internal"; - -/// Turns `capacity` into an unsuffixed integer literal -pub fn capacity_literal(capacity: usize) -> LitInt { - LitInt::new(&capacity.to_string(), Span::call_site()) -} - -/// Identifier for the free queue -pub fn fq_ident(task: &Ident) -> Ident { - mark_internal_name(&format!("{}_FQ", task)) -} - -/// Generates a `Mutex` implementation -pub fn impl_mutex( - extra: &Extra, - cfgs: &[Attribute], - resources_prefix: bool, - name: &Ident, - ty: &TokenStream2, - ceiling: u8, - ptr: &TokenStream2, -) -> TokenStream2 { - let (path, priority) = if resources_prefix { - (quote!(shared_resources::#name), quote!(self.priority())) - } else { - (quote!(#name), quote!(self.priority)) - }; - - let device = &extra.device; - let masks_name = priority_masks_ident(); - quote!( - #(#cfgs)* - impl<'a> rtic::Mutex for #path<'a> { - type T = #ty; - - #[inline(always)] - fn lock<RTIC_INTERNAL_R>(&mut self, f: impl FnOnce(&mut #ty) -> RTIC_INTERNAL_R) -> RTIC_INTERNAL_R { - /// Priority ceiling - const CEILING: u8 = #ceiling; - - unsafe { - rtic::export::lock( - #ptr, - #priority, - CEILING, - #device::NVIC_PRIO_BITS, - &#masks_name, - f, - ) - } - } - } - ) -} - -/// Generates an identifier for the `INPUTS` buffer (`spawn` & `schedule` API) -pub fn inputs_ident(task: &Ident) -> Ident { - mark_internal_name(&format!("{}_INPUTS", task)) -} - -/// Generates an identifier for the `INSTANTS` buffer (`schedule` API) -pub fn monotonic_instants_ident(task: &Ident, monotonic: &Ident) -> Ident { - mark_internal_name(&format!("{}_{}_INSTANTS", task, monotonic)) -} - -pub fn interrupt_ident() -> Ident { - let span = Span::call_site(); - Ident::new("interrupt", span) -} - -pub fn timer_queue_marker_ident() -> Ident { - mark_internal_name("TIMER_QUEUE_MARKER") -} - -/// Whether `name` is an exception with configurable priority -pub fn is_exception(name: &Ident) -> bool { - let s = name.to_string(); - - matches!( - &*s, - "MemoryManagement" - | "BusFault" - | "UsageFault" - | "SecureFault" - | "SVCall" - | "DebugMonitor" - | "PendSV" - | "SysTick" - ) -} - -/// Mark a name as internal -pub fn mark_internal_name(name: &str) -> Ident { - Ident::new(&format!("{}_{}", RTIC_INTERNAL, name), Span::call_site()) -} - -/// Generate an internal identifier for monotonics -pub fn internal_monotonics_ident(task: &Ident, monotonic: &Ident, ident_name: &str) -> Ident { - mark_internal_name(&format!("{}_{}_{}", task, monotonic, ident_name,)) -} - -/// Generate an internal identifier for tasks -pub fn internal_task_ident(task: &Ident, ident_name: &str) -> Ident { - mark_internal_name(&format!("{}_{}", task, ident_name)) -} - -fn link_section_index() -> usize { - static INDEX: AtomicUsize = AtomicUsize::new(0); - - INDEX.fetch_add(1, Ordering::Relaxed) -} - -/// Add `link_section` attribute -pub fn link_section_uninit() -> TokenStream2 { - let section = format!(".uninit.rtic{}", link_section_index()); - - quote!(#[link_section = #section]) -} - -// Regroups the inputs of a task -// -// `inputs` could be &[`input: Foo`] OR &[`mut x: i32`, `ref y: i64`] -pub fn regroup_inputs( - inputs: &[PatType], -) -> ( - // args e.g. &[`_0`], &[`_0: i32`, `_1: i64`] - Vec<TokenStream2>, - // tupled e.g. `_0`, `(_0, _1)` - TokenStream2, - // untupled e.g. &[`_0`], &[`_0`, `_1`] - Vec<TokenStream2>, - // ty e.g. `Foo`, `(i32, i64)` - TokenStream2, -) { - if inputs.len() == 1 { - let ty = &inputs[0].ty; - - ( - vec![quote!(_0: #ty)], - quote!(_0), - vec![quote!(_0)], - quote!(#ty), - ) - } else { - let mut args = vec![]; - let mut pats = vec![]; - let mut tys = vec![]; - - for (i, input) in inputs.iter().enumerate() { - let i = Ident::new(&format!("_{}", i), Span::call_site()); - let ty = &input.ty; - - args.push(quote!(#i: #ty)); - - pats.push(quote!(#i)); - - tys.push(quote!(#ty)); - } - - let tupled = { - let pats = pats.clone(); - quote!((#(#pats,)*)) - }; - let ty = quote!((#(#tys,)*)); - (args, tupled, pats, ty) - } -} - -/// Get the ident for the name of the task -pub fn get_task_name(ctxt: Context, app: &App) -> Ident { - let s = match ctxt { - Context::Init => app.init.name.to_string(), - Context::Idle => app.idle.as_ref().unwrap().name.to_string(), - Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), - }; - - Ident::new(&s, Span::call_site()) -} - -/// Generates a pre-reexport identifier for the "shared resources" struct -pub fn shared_resources_ident(ctxt: Context, app: &App) -> Ident { - let mut s = match ctxt { - Context::Init => app.init.name.to_string(), - Context::Idle => app.idle.as_ref().unwrap().name.to_string(), - Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), - }; - - s.push_str("SharedResources"); - - mark_internal_name(&s) -} - -/// Generates a pre-reexport identifier for the "local resources" struct -pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { - let mut s = match ctxt { - Context::Init => app.init.name.to_string(), - Context::Idle => app.idle.as_ref().unwrap().name.to_string(), - Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), - }; - - s.push_str("LocalResources"); - - mark_internal_name(&s) -} - -/// Generates an identifier for a ready queue -/// -/// There may be several task dispatchers, one for each priority level. -/// The ready queues are SPSC queues -pub fn rq_ident(priority: u8) -> Ident { - mark_internal_name(&format!("P{}_RQ", priority)) -} - -/// Generates an identifier for the `enum` of `schedule`-able tasks -pub fn schedule_t_ident() -> Ident { - Ident::new("SCHED_T", Span::call_site()) -} - -/// Generates an identifier for the `enum` of `spawn`-able tasks -/// -/// This identifier needs the same structure as the `RQ` identifier because there's one ready queue -/// for each of these `T` enums -pub fn spawn_t_ident(priority: u8) -> Ident { - Ident::new(&format!("P{}_T", priority), Span::call_site()) -} - -/// Suffixed identifier -pub fn suffixed(name: &str) -> Ident { - let span = Span::call_site(); - Ident::new(name, span) -} - -/// Generates an identifier for a timer queue -pub fn tq_ident(name: &str) -> Ident { - mark_internal_name(&format!("TQ_{}", name)) -} - -/// Generates an identifier for monotonic timer storage -pub fn monotonic_ident(name: &str) -> Ident { - mark_internal_name(&format!("MONOTONIC_STORAGE_{}", name)) -} - -pub fn static_shared_resource_ident(name: &Ident) -> Ident { - mark_internal_name(&format!("shared_resource_{}", name)) -} - -/// Generates an Ident for the number of 32 bit chunks used for Mask storage. -pub fn priority_mask_chunks_ident() -> Ident { - mark_internal_name("MASK_CHUNKS") -} - -pub fn priority_masks_ident() -> Ident { - mark_internal_name("MASKS") -} - -pub fn static_local_resource_ident(name: &Ident) -> Ident { - mark_internal_name(&format!("local_resource_{}", name)) -} - -pub fn declared_static_local_resource_ident(name: &Ident, task_name: &Ident) -> Ident { - mark_internal_name(&format!("local_{}_{}", task_name, name)) -} - -pub fn need_to_lock_ident(name: &Ident) -> Ident { - Ident::new(&format!("{}_that_needs_to_be_locked", name), name.span()) -} - -/// The name to get better RT flag errors -pub fn rt_err_ident() -> Ident { - Ident::new( - "you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml", - Span::call_site(), - ) -} diff --git a/macros/src/tests.rs b/macros/src/tests.rs deleted file mode 100644 index e9e3326..0000000 --- a/macros/src/tests.rs +++ /dev/null @@ -1,4 +0,0 @@ -// NOTE these tests are specific to the Cortex-M port; `rtic-syntax` has a more extensive test suite -// that tests functionality common to all the RTIC ports - -mod single; diff --git a/macros/src/tests/single.rs b/macros/src/tests/single.rs deleted file mode 100644 index f20c9cc..0000000 --- a/macros/src/tests/single.rs +++ /dev/null @@ -1,40 +0,0 @@ -use quote::quote; -use rtic_syntax::Settings; - -#[test] -fn analyze() { - let mut settings = Settings::default(); - settings.parse_extern_interrupt = true; - let (app, analysis) = rtic_syntax::parse2( - // First interrupt is assigned to the highest priority dispatcher - quote!(device = pac, dispatchers = [B, A]), - quote!( - mod app { - #[shared] - struct Shared {} - - #[local] - struct Local {} - - #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { - (Shared {}, Local {}, init::Monotonics()) - } - - #[task(priority = 1)] - fn a(_: a::Context) {} - - #[task(priority = 2)] - fn b(_: b::Context) {} - } - ), - settings, - ) - .unwrap(); - - let analysis = crate::analyze::app(analysis, &app); - let interrupts = &analysis.interrupts; - assert_eq!(interrupts.len(), 2); - assert_eq!(interrupts[&2].0.to_string(), "B"); - assert_eq!(interrupts[&1].0.to_string(), "A"); -} diff --git a/rtic-common/.gitignore b/rtic-common/.gitignore new file mode 100644 index 0000000..1e7caa9 --- /dev/null +++ b/rtic-common/.gitignore @@ -0,0 +1,2 @@ +Cargo.lock +target/ diff --git a/rtic-common/CHANGELOG.md b/rtic-common/CHANGELOG.md new file mode 100644 index 0000000..d3a9d84 --- /dev/null +++ b/rtic-common/CHANGELOG.md @@ -0,0 +1,16 @@ +# Change Log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +For each category, *Added*, *Changed*, *Fixed* add new entries at the top! + +## [Unreleased] + +### Added + +### Changed + +### Fixed + +## [v1.0.0] - 2023-xx-xx diff --git a/rtic-common/Cargo.toml b/rtic-common/Cargo.toml new file mode 100644 index 0000000..726090a --- /dev/null +++ b/rtic-common/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "rtic-common" +version = "1.0.0-alpha.0" + +edition = "2021" +authors = [ + "The Real-Time Interrupt-driven Concurrency developers", + "Emil Fresk <emil.fresk@gmail.com>", + "Henrik Tjäder <henrik@tjaders.com>", + "Jorge Aparicio <jorge@japaric.io>", + "Per Lindgren <per.lindgren@ltu.se>", +] +categories = ["concurrency", "embedded", "no-std", "asynchronous"] +description = "rtic-common lib TODO" +license = "MIT OR Apache-2.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +critical-section = "1" + +[features] +default = [] +testing = ["critical-section/std"] diff --git a/rtic-common/src/dropper.rs b/rtic-common/src/dropper.rs new file mode 100644 index 0000000..a4b4d15 --- /dev/null +++ b/rtic-common/src/dropper.rs @@ -0,0 +1,26 @@ +//! A drop implementation runner. + +/// Runs a closure on drop. +pub struct OnDrop<F: FnOnce()> { + f: core::mem::MaybeUninit<F>, +} + +impl<F: FnOnce()> OnDrop<F> { + /// Make a new droppper given a closure. + pub fn new(f: F) -> Self { + Self { + f: core::mem::MaybeUninit::new(f), + } + } + + /// Make it not run drop. + pub fn defuse(self) { + core::mem::forget(self) + } +} + +impl<F: FnOnce()> Drop for OnDrop<F> { + fn drop(&mut self) { + unsafe { self.f.as_ptr().read()() } + } +} diff --git a/rtic-common/src/lib.rs b/rtic-common/src/lib.rs new file mode 100644 index 0000000..03d0306 --- /dev/null +++ b/rtic-common/src/lib.rs @@ -0,0 +1,13 @@ +//! Crate + +#![no_std] +#![deny(missing_docs)] +//deny_warnings_placeholder_for_ci + +#[cfg(test)] +#[macro_use] +extern crate std; + +pub mod dropper; +pub mod wait_queue; +pub mod waker_registration; diff --git a/rtic-common/src/wait_queue.rs b/rtic-common/src/wait_queue.rs new file mode 100644 index 0000000..b1aa775 --- /dev/null +++ b/rtic-common/src/wait_queue.rs @@ -0,0 +1,275 @@ +//! ... + +use core::marker::PhantomPinned; +use core::pin::Pin; +use core::ptr::null_mut; +use core::sync::atomic::{AtomicBool, AtomicPtr, Ordering}; +use core::task::Waker; +use critical_section as cs; + +/// A helper definition of a wait queue. +pub type WaitQueue = LinkedList<Waker>; + +/// A FIFO linked list for a wait queue. +pub struct LinkedList<T> { + head: AtomicPtr<Link<T>>, // UnsafeCell<*mut Link<T>> + tail: AtomicPtr<Link<T>>, +} + +impl<T> LinkedList<T> { + /// Create a new linked list. + pub const fn new() -> Self { + Self { + head: AtomicPtr::new(null_mut()), + tail: AtomicPtr::new(null_mut()), + } + } +} + +impl<T: Clone> LinkedList<T> { + const R: Ordering = Ordering::Relaxed; + + /// Pop the first element in the queue. + pub fn pop(&self) -> Option<T> { + cs::with(|_| { + // Make sure all previous writes are visible + core::sync::atomic::fence(Ordering::SeqCst); + + let head = self.head.load(Self::R); + + // SAFETY: `as_ref` is safe as `insert` requires a valid reference to a link + if let Some(head_ref) = unsafe { head.as_ref() } { + // Move head to the next element + self.head.store(head_ref.next.load(Self::R), Self::R); + + // We read the value at head + let head_val = head_ref.val.clone(); + + let tail = self.tail.load(Self::R); + if head == tail { + // The queue is empty + self.tail.store(null_mut(), Self::R); + } + + if let Some(next_ref) = unsafe { head_ref.next.load(Self::R).as_ref() } { + next_ref.prev.store(null_mut(), Self::R); + } + + // Clear the pointers in the node. + head_ref.next.store(null_mut(), Self::R); + head_ref.prev.store(null_mut(), Self::R); + head_ref.is_popped.store(true, Self::R); + + return Some(head_val); + } + + None + }) + } + + /// Put an element at the back of the queue. + /// + /// # Safety + /// + /// The link must live until it is removed from the queue. + pub unsafe fn push(&self, link: Pin<&Link<T>>) { + cs::with(|_| { + // Make sure all previous writes are visible + core::sync::atomic::fence(Ordering::SeqCst); + + let tail = self.tail.load(Self::R); + + // SAFETY: This datastructure does not move the underlying value. + let link = link.get_ref(); + + if let Some(tail_ref) = unsafe { tail.as_ref() } { + // Queue is not empty + link.prev.store(tail, Self::R); + self.tail.store(link as *const _ as *mut _, Self::R); + tail_ref.next.store(link as *const _ as *mut _, Self::R); + } else { + // Queue is empty + self.tail.store(link as *const _ as *mut _, Self::R); + self.head.store(link as *const _ as *mut _, Self::R); + } + }); + } + + /// Check if the queue is empty. + pub fn is_empty(&self) -> bool { + self.head.load(Self::R).is_null() + } +} + +/// A link in the linked list. +pub struct Link<T> { + pub(crate) val: T, + next: AtomicPtr<Link<T>>, + prev: AtomicPtr<Link<T>>, + is_popped: AtomicBool, + _up: PhantomPinned, +} + +impl<T: Clone> Link<T> { + const R: Ordering = Ordering::Relaxed; + + /// Create a new link. + pub const fn new(val: T) -> Self { + Self { + val, + next: AtomicPtr::new(null_mut()), + prev: AtomicPtr::new(null_mut()), + is_popped: AtomicBool::new(false), + _up: PhantomPinned, + } + } + + /// Return true if this link has been poped from the list. + pub fn is_popped(&self) -> bool { + self.is_popped.load(Self::R) + } + + /// Remove this link from a linked list. + pub fn remove_from_list(&self, list: &LinkedList<T>) { + cs::with(|_| { + // Make sure all previous writes are visible + core::sync::atomic::fence(Ordering::SeqCst); + + let prev = self.prev.load(Self::R); + let next = self.next.load(Self::R); + self.is_popped.store(true, Self::R); + + match unsafe { (prev.as_ref(), next.as_ref()) } { + (None, None) => { + // Not in the list or alone in the list, check if list head == node address + let sp = self as *const _; + + if sp == list.head.load(Ordering::Relaxed) { + list.head.store(null_mut(), Self::R); + list.tail.store(null_mut(), Self::R); + } + } + (None, Some(next_ref)) => { + // First in the list + next_ref.prev.store(null_mut(), Self::R); + list.head.store(next, Self::R); + } + (Some(prev_ref), None) => { + // Last in the list + prev_ref.next.store(null_mut(), Self::R); + list.tail.store(prev, Self::R); + } + (Some(prev_ref), Some(next_ref)) => { + // Somewhere in the list + + // Connect the `prev.next` and `next.prev` with each other to remove the node + prev_ref.next.store(next, Self::R); + next_ref.prev.store(prev, Self::R); + } + } + }) + } +} + +#[cfg(test)] +impl<T: core::fmt::Debug + Clone> LinkedList<T> { + fn print(&self) { + cs::with(|_| { + // Make sure all previous writes are visible + core::sync::atomic::fence(Ordering::SeqCst); + + let mut head = self.head.load(Self::R); + let tail = self.tail.load(Self::R); + + println!( + "List - h = 0x{:x}, t = 0x{:x}", + head as usize, tail as usize + ); + + let mut i = 0; + + // SAFETY: `as_ref` is safe as `insert` requires a valid reference to a link + while let Some(head_ref) = unsafe { head.as_ref() } { + println!( + " {}: {:?}, s = 0x{:x}, n = 0x{:x}, p = 0x{:x}", + i, + head_ref.val, + head as usize, + head_ref.next.load(Ordering::Relaxed) as usize, + head_ref.prev.load(Ordering::Relaxed) as usize + ); + + head = head_ref.next.load(Self::R); + + i += 1; + } + }); + } +} + +#[cfg(test)] +impl<T: core::fmt::Debug + Clone> Link<T> { + fn print(&self) { + cs::with(|_| { + // Make sure all previous writes are visible + core::sync::atomic::fence(Ordering::SeqCst); + + println!("Link:"); + + println!( + " val = {:?}, n = 0x{:x}, p = 0x{:x}", + self.val, + self.next.load(Ordering::Relaxed) as usize, + self.prev.load(Ordering::Relaxed) as usize + ); + }); + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn linked_list() { + let wq = LinkedList::<u32>::new(); + + let i1 = Link::new(10); + let i2 = Link::new(11); + let i3 = Link::new(12); + let i4 = Link::new(13); + let i5 = Link::new(14); + + unsafe { wq.push(Pin::new_unchecked(&i1)) }; + unsafe { wq.push(Pin::new_unchecked(&i2)) }; + unsafe { wq.push(Pin::new_unchecked(&i3)) }; + unsafe { wq.push(Pin::new_unchecked(&i4)) }; + unsafe { wq.push(Pin::new_unchecked(&i5)) }; + + wq.print(); + + wq.pop(); + i1.print(); + + wq.print(); + + i4.remove_from_list(&wq); + + wq.print(); + + // i1.remove_from_list(&wq); + // wq.print(); + + println!("i2"); + i2.remove_from_list(&wq); + wq.print(); + + println!("i3"); + i3.remove_from_list(&wq); + wq.print(); + + println!("i5"); + i5.remove_from_list(&wq); + wq.print(); + } +} diff --git a/rtic-common/src/waker_registration.rs b/rtic-common/src/waker_registration.rs new file mode 100644 index 0000000..174765c --- /dev/null +++ b/rtic-common/src/waker_registration.rs @@ -0,0 +1,66 @@ +//! Waker registration utility. + +use core::cell::UnsafeCell; +use core::task::Waker; + +/// A critical section based waker handler. +pub struct CriticalSectionWakerRegistration { + waker: UnsafeCell<Option<Waker>>, +} + +unsafe impl Send for CriticalSectionWakerRegistration {} +unsafe impl Sync for CriticalSectionWakerRegistration {} + +impl CriticalSectionWakerRegistration { + /// Create a new waker registration. + pub const fn new() -> Self { + Self { + waker: UnsafeCell::new(None), + } + } + + /// Register a waker. + /// This will overwrite the previous waker if there was one. + pub fn register(&self, new_waker: &Waker) { + critical_section::with(|_| { + // SAFETY: This access is protected by the critical section. + let self_waker = unsafe { &mut *self.waker.get() }; + + // From embassy + // https://github.com/embassy-rs/embassy/blob/b99533607ceed225dd12ae73aaa9a0d969a7365e/embassy-sync/src/waitqueue/waker.rs#L59-L61 + match self_waker { + // Optimization: If both the old and new Wakers wake the same task, we can simply + // keep the old waker, skipping the clone. (In most executor implementations, + // cloning a waker is somewhat expensive, comparable to cloning an Arc). + Some(ref w2) if (w2.will_wake(new_waker)) => {} + _ => { + // clone the new waker and store it + if let Some(old_waker) = core::mem::replace(self_waker, Some(new_waker.clone())) + { + // We had a waker registered for another task. Wake it, so the other task can + // reregister itself if it's still interested. + // + // If two tasks are waiting on the same thing concurrently, this will cause them + // to wake each other in a loop fighting over this WakerRegistration. This wastes + // CPU but things will still work. + // + // If the user wants to have two tasks waiting on the same thing they should use + // a more appropriate primitive that can store multiple wakers. + old_waker.wake() + } + } + } + }); + } + + /// Wake the waker. + pub fn wake(&self) { + critical_section::with(|_| { + // SAFETY: This access is protected by the critical section. + let self_waker = unsafe { &mut *self.waker.get() }; + if let Some(waker) = self_waker.take() { + waker.wake() + } + }); + } +} diff --git a/rtic-macros/.gitignore b/rtic-macros/.gitignore new file mode 100644 index 0000000..4fffb2f --- /dev/null +++ b/rtic-macros/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/rtic-macros/Cargo.toml b/rtic-macros/Cargo.toml new file mode 100644 index 0000000..94aa88b --- /dev/null +++ b/rtic-macros/Cargo.toml @@ -0,0 +1,44 @@ +[package] +authors = [ + "The Real-Time Interrupt-driven Concurrency developers", + "Emil Fresk <emil.fresk@gmail.com>", + "Henrik Tjäder <henrik@tjaders.com>", + "Jorge Aparicio <jorge@japaric.io>", + "Per Lindgren <per.lindgren@ltu.se>", +] +categories = ["concurrency", "embedded", "no-std", "asynchronous"] +description = "Procedural macros, syntax parsing, and codegen of the RTIC crate" +documentation = "https://rtic-rs.github.io/rtic/api/rtic" +edition = "2021" +keywords = ["arm", "cortex-m", "risc-v", "embedded", "async", "runtime", "futures", "await", "no-std", "rtos", "bare-metal"] +license = "MIT OR Apache-2.0" +name = "rtic-macros" +readme = "../../README.md" +repository = "https://github.com/rtic-rs/rtic" + +version = "2.0.0-alpha.0" + +[lib] +proc-macro = true + +[features] +default = [] + +# list of supported codegen backends +cortex-m-source-masking = [] +cortex-m-basepri = [] +# riscv-clic = [] +# riscv-ch32 = [] + +# backend API test +test-template = [] + +[dependencies] +indexmap = "1.9.2" +proc-macro2 = "1.0.49" +proc-macro-error = "1.0.4" +quote = "1.0.23" +syn = { version = "1.0.107", features = ["extra-traits", "full"] } + +[dev-dependencies] +trybuild = "1.0.73" diff --git a/macros/src/analyze.rs b/rtic-macros/src/analyze.rs index d255b7f..65774f6 100644 --- a/macros/src/analyze.rs +++ b/rtic-macros/src/analyze.rs @@ -1,17 +1,16 @@ use core::ops; use std::collections::{BTreeMap, BTreeSet}; -use rtic_syntax::{ +use crate::syntax::{ analyze::{self, Priority}, - ast::{App, ExternInterrupt}, - P, + ast::{App, Dispatcher}, }; use syn::Ident; /// Extend the upstream `Analysis` struct with our field pub struct Analysis { - parent: P<analyze::Analysis>, - pub interrupts: BTreeMap<Priority, (Ident, ExternInterrupt)>, + parent: analyze::Analysis, + pub interrupts: BTreeMap<Priority, (Ident, Dispatcher)>, } impl ops::Deref for Analysis { @@ -23,7 +22,9 @@ impl ops::Deref for Analysis { } // Assign an interrupt to each priority level -pub fn app(analysis: P<analyze::Analysis>, app: &App) -> P<Analysis> { +pub fn app(analysis: analyze::Analysis, app: &App) -> Analysis { + let mut available_interrupt = app.args.dispatchers.clone(); + // the set of priorities (each priority only once) let priorities = app .software_tasks @@ -32,16 +33,17 @@ pub fn app(analysis: P<analyze::Analysis>, app: &App) -> P<Analysis> { .collect::<BTreeSet<_>>(); // map from priorities to interrupts (holding name and attributes) + let interrupts: BTreeMap<Priority, _> = priorities .iter() + .filter(|prio| **prio > 0) // 0 prio tasks are run in main .copied() .rev() - .zip(&app.args.extern_interrupts) - .map(|(p, (id, ext))| (p, (id.clone(), ext.clone()))) + .map(|p| (p, available_interrupt.pop().expect("UNREACHABLE"))) .collect(); - P::new(Analysis { + Analysis { parent: analysis, interrupts, - }) + } } diff --git a/rtic-macros/src/check.rs b/rtic-macros/src/check.rs new file mode 100644 index 0000000..957a9b3 --- /dev/null +++ b/rtic-macros/src/check.rs @@ -0,0 +1,7 @@ +use crate::codegen::bindings::architecture_specific_analysis; +use crate::syntax::{analyze::Analysis, ast::App}; +use syn::parse; + +pub fn app(app: &App, analysis: &Analysis) -> parse::Result<()> { + architecture_specific_analysis(app, analysis) +} diff --git a/rtic-macros/src/codegen.rs b/rtic-macros/src/codegen.rs new file mode 100644 index 0000000..48ee5e3 --- /dev/null +++ b/rtic-macros/src/codegen.rs @@ -0,0 +1,77 @@ +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +use crate::analyze::Analysis; +use crate::syntax::ast::App; + +pub mod bindings; + +mod assertions; +mod async_dispatchers; +mod hardware_tasks; +mod idle; +mod init; +mod local_resources; +mod local_resources_struct; +mod module; +mod post_init; +mod pre_init; +mod shared_resources; +mod shared_resources_struct; +mod software_tasks; +mod util; + +mod main; + +// TODO: organize codegen to actual parts of code +// so `main::codegen` generates ALL the code for `fn main`, +// `software_tasks::codegen` generates ALL the code for software tasks etc... + +#[allow(clippy::too_many_lines)] +pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 { + // Generate the `main` function + let main = main::codegen(app, analysis); + let init_codegen = init::codegen(app, analysis); + let idle_codegen = idle::codegen(app, analysis); + let shared_resources_codegen = shared_resources::codegen(app, analysis); + let local_resources_codegen = local_resources::codegen(app, analysis); + let hardware_tasks_codegen = hardware_tasks::codegen(app, analysis); + let software_tasks_codegen = software_tasks::codegen(app, analysis); + let async_dispatchers_codegen = async_dispatchers::codegen(app, analysis); + + let user_imports = &app.user_imports; + let user_code = &app.user_code; + let name = &app.name; + let device = &app.args.device; + + let rt_err = util::rt_err_ident(); + + quote!( + /// The RTIC application module + pub mod #name { + /// Always include the device crate which contains the vector table + use #device as #rt_err; + + #(#user_imports)* + + #(#user_code)* + /// User code end + + #init_codegen + + #idle_codegen + + #hardware_tasks_codegen + + #software_tasks_codegen + + #shared_resources_codegen + + #local_resources_codegen + + #async_dispatchers_codegen + + #main + } + ) +} diff --git a/rtic-macros/src/codegen/assertions.rs b/rtic-macros/src/codegen/assertions.rs new file mode 100644 index 0000000..2f5dd52 --- /dev/null +++ b/rtic-macros/src/codegen/assertions.rs @@ -0,0 +1,23 @@ +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +use super::bindings::extra_assertions; +use crate::analyze::Analysis; +use crate::syntax::ast::App; + +/// Generates compile-time assertions that check that types implement the `Send` / `Sync` traits +pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { + let mut stmts = vec![]; + + for ty in &analysis.send_types { + stmts.push(quote!(rtic::export::assert_send::<#ty>();)); + } + + for ty in &analysis.sync_types { + stmts.push(quote!(rtic::export::assert_sync::<#ty>();)); + } + + stmts.append(&mut extra_assertions(app, analysis)); + + stmts +} diff --git a/rtic-macros/src/codegen/async_dispatchers.rs b/rtic-macros/src/codegen/async_dispatchers.rs new file mode 100644 index 0000000..bdbfeaa --- /dev/null +++ b/rtic-macros/src/codegen/async_dispatchers.rs @@ -0,0 +1,102 @@ +use crate::syntax::ast::App; +use crate::{ + analyze::Analysis, + codegen::{ + bindings::{interrupt_entry, interrupt_exit}, + util, + }, +}; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +/// Generates task dispatchers +pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { + let mut items = vec![]; + + let interrupts = &analysis.interrupts; + + // Generate executor definition and priority in global scope + for (name, _) in app.software_tasks.iter() { + let type_name = util::internal_task_ident(name, "F"); + let exec_name = util::internal_task_ident(name, "EXEC"); + + items.push(quote!( + #[allow(non_camel_case_types)] + type #type_name = impl core::future::Future; + #[allow(non_upper_case_globals)] + static #exec_name: rtic::export::executor::AsyncTaskExecutor<#type_name> = + rtic::export::executor::AsyncTaskExecutor::new(); + )); + } + + for (&level, channel) in &analysis.channels { + let mut stmts = vec![]; + + let dispatcher_name = if level > 0 { + util::suffixed(&interrupts.get(&level).expect("UNREACHABLE").0.to_string()) + } else { + util::zero_prio_dispatcher_ident() + }; + + let pend_interrupt = if level > 0 { + let device = &app.args.device; + let enum_ = util::interrupt_ident(); + + quote!(rtic::pend(#device::#enum_::#dispatcher_name);) + } else { + // For 0 priority tasks we don't need to pend anything + quote!() + }; + + for name in channel.tasks.iter() { + let exec_name = util::internal_task_ident(name, "EXEC"); + // TODO: Fix cfg + // let task = &app.software_tasks[name]; + // let cfgs = &task.cfgs; + + stmts.push(quote!( + #exec_name.poll(|| { + #exec_name.set_pending(); + #pend_interrupt + }); + )); + } + + if level > 0 { + let doc = format!("Interrupt handler to dispatch async tasks at priority {level}"); + let attribute = &interrupts.get(&level).expect("UNREACHABLE").1.attrs; + let entry_stmts = interrupt_entry(app, analysis); + let exit_stmts = interrupt_exit(app, analysis); + + items.push(quote!( + #[allow(non_snake_case)] + #[doc = #doc] + #[no_mangle] + #(#attribute)* + unsafe fn #dispatcher_name() { + #(#entry_stmts)* + + /// The priority of this interrupt handler + const PRIORITY: u8 = #level; + + rtic::export::run(PRIORITY, || { + #(#stmts)* + }); + + #(#exit_stmts)* + } + )); + } else { + items.push(quote!( + #[allow(non_snake_case)] + unsafe fn #dispatcher_name() -> ! { + loop { + #(#stmts)* + } + } + )); + } + } + + quote!(#(#items)*) +} diff --git a/rtic-macros/src/codegen/bindings.rs b/rtic-macros/src/codegen/bindings.rs new file mode 100644 index 0000000..6c214cd --- /dev/null +++ b/rtic-macros/src/codegen/bindings.rs @@ -0,0 +1,18 @@ +#[cfg(not(any( + feature = "cortex-m-source-masking", + feature = "cortex-m-basepri", + feature = "test-template" +)))] +compile_error!("No backend selected"); + +#[cfg(any(feature = "cortex-m-source-masking", feature = "cortex-m-basepri"))] +pub use cortex::*; + +#[cfg(feature = "test-template")] +pub use template::*; + +#[cfg(any(feature = "cortex-m-source-masking", feature = "cortex-m-basepri"))] +mod cortex; + +#[cfg(feature = "test-template")] +mod template; diff --git a/rtic-macros/src/codegen/bindings/cortex.rs b/rtic-macros/src/codegen/bindings/cortex.rs new file mode 100644 index 0000000..767befa --- /dev/null +++ b/rtic-macros/src/codegen/bindings/cortex.rs @@ -0,0 +1,324 @@ +use crate::{ + analyze::Analysis as CodegenAnalysis, + codegen::util, + syntax::{analyze::Analysis as SyntaxAnalysis, ast::App}, +}; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; +use std::collections::HashSet; +use syn::{parse, Attribute, Ident}; + +#[cfg(feature = "cortex-m-basepri")] +pub use basepri::*; +#[cfg(feature = "cortex-m-source-masking")] +pub use source_masking::*; + +/// Whether `name` is an exception with configurable priority +fn is_exception(name: &Ident) -> bool { + let s = name.to_string(); + + matches!( + &*s, + "MemoryManagement" + | "BusFault" + | "UsageFault" + | "SecureFault" + | "SVCall" + | "DebugMonitor" + | "PendSV" + | "SysTick" + ) +} + +#[cfg(feature = "cortex-m-source-masking")] +mod source_masking { + use super::*; + use std::collections::HashMap; + + /// Generates a `Mutex` implementation + #[allow(clippy::too_many_arguments)] + pub fn impl_mutex( + app: &App, + analysis: &CodegenAnalysis, + cfgs: &[Attribute], + resources_prefix: bool, + name: &Ident, + ty: &TokenStream2, + ceiling: u8, + ptr: &TokenStream2, + ) -> TokenStream2 { + let path = if resources_prefix { + quote!(shared_resources::#name) + } else { + quote!(#name) + }; + + // Computing mapping of used interrupts to masks + let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id)); + + let mut prio_to_masks = HashMap::new(); + let device = &app.args.device; + // let mut uses_exceptions_with_resources = false; + + let mut mask_ids = Vec::new(); + + for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().flat_map(|task| { + if !is_exception(&task.args.binds) { + Some((&task.args.priority, &task.args.binds)) + } else { + None + } + })) { + let v: &mut Vec<_> = prio_to_masks.entry(priority - 1).or_default(); + v.push(quote!(#device::Interrupt::#name as u32)); + mask_ids.push(quote!(#device::Interrupt::#name as u32)); + } + + // Call rtic::export::create_mask([Mask; N]), where the array is the list of shifts + + let mut mask_arr = Vec::new(); + // NOTE: 0..3 assumes max 4 priority levels according to M0, M23 spec + for i in 0..3 { + let v = if let Some(v) = prio_to_masks.get(&i) { + v.clone() + } else { + Vec::new() + }; + + mask_arr.push(quote!( + rtic::export::create_mask([#(#v),*]) + )); + } + + quote!( + #(#cfgs)* + impl<'a> rtic::Mutex for #path<'a> { + type T = #ty; + + #[inline(always)] + fn lock<RTIC_INTERNAL_R>(&mut self, f: impl FnOnce(&mut #ty) -> RTIC_INTERNAL_R) -> RTIC_INTERNAL_R { + /// Priority ceiling + const CEILING: u8 = #ceiling; + const N_CHUNKS: usize = rtic::export::compute_mask_chunks([#(#mask_ids),*]); + const MASKS: [rtic::export::Mask<N_CHUNKS>; 3] = [#(#mask_arr),*]; + + unsafe { + rtic::export::lock( + #ptr, + CEILING, + &MASKS, + f, + ) + } + } + } + ) + } + + pub fn extra_assertions(_: &App, _: &SyntaxAnalysis) -> Vec<TokenStream2> { + vec![] + } +} + +#[cfg(feature = "cortex-m-basepri")] +mod basepri { + use super::*; + + /// Generates a `Mutex` implementation + #[allow(clippy::too_many_arguments)] + pub fn impl_mutex( + app: &App, + _analysis: &CodegenAnalysis, + cfgs: &[Attribute], + resources_prefix: bool, + name: &Ident, + ty: &TokenStream2, + ceiling: u8, + ptr: &TokenStream2, + ) -> TokenStream2 { + let path = if resources_prefix { + quote!(shared_resources::#name) + } else { + quote!(#name) + }; + + let device = &app.args.device; + quote!( + #(#cfgs)* + impl<'a> rtic::Mutex for #path<'a> { + type T = #ty; + + #[inline(always)] + fn lock<RTIC_INTERNAL_R>(&mut self, f: impl FnOnce(&mut #ty) -> RTIC_INTERNAL_R) -> RTIC_INTERNAL_R { + /// Priority ceiling + const CEILING: u8 = #ceiling; + + unsafe { + rtic::export::lock( + #ptr, + CEILING, + #device::NVIC_PRIO_BITS, + f, + ) + } + } + } + ) + } + + pub fn extra_assertions(_: &App, _: &SyntaxAnalysis) -> Vec<TokenStream2> { + vec![] + } +} + +pub fn pre_init_checks(app: &App, _: &SyntaxAnalysis) -> Vec<TokenStream2> { + let mut stmts = vec![]; + + // check that all dispatchers exists in the `Interrupt` enumeration regardless of whether + // they are used or not + let interrupt = util::interrupt_ident(); + let rt_err = util::rt_err_ident(); + + for name in app.args.dispatchers.keys() { + stmts.push(quote!(let _ = #rt_err::#interrupt::#name;)); + } + + stmts +} + +pub fn pre_init_enable_interrupts(app: &App, analysis: &CodegenAnalysis) -> Vec<TokenStream2> { + let mut stmts = vec![]; + + let interrupt = util::interrupt_ident(); + let rt_err = util::rt_err_ident(); + let device = &app.args.device; + let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS); + let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id)); + + // Unmask interrupts and set their priorities + for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().filter_map(|task| { + if is_exception(&task.args.binds) { + // We do exceptions in another pass + None + } else { + Some((&task.args.priority, &task.args.binds)) + } + })) { + let es = format!( + "Maximum priority used by interrupt vector '{name}' is more than supported by hardware" + ); + // Compile time assert that this priority is supported by the device + stmts.push(quote!( + const _: () = if (1 << #nvic_prio_bits) < #priority as usize { ::core::panic!(#es); }; + )); + + stmts.push(quote!( + core.NVIC.set_priority( + #rt_err::#interrupt::#name, + rtic::export::cortex_logical2hw(#priority, #nvic_prio_bits), + ); + )); + + // NOTE unmask the interrupt *after* setting its priority: changing the priority of a pended + // interrupt is implementation defined + stmts.push(quote!(rtic::export::NVIC::unmask(#rt_err::#interrupt::#name);)); + } + + // Set exception priorities + for (name, priority) in app.hardware_tasks.values().filter_map(|task| { + if is_exception(&task.args.binds) { + Some((&task.args.binds, task.args.priority)) + } else { + None + } + }) { + let es = format!( + "Maximum priority used by interrupt vector '{name}' is more than supported by hardware" + ); + // Compile time assert that this priority is supported by the device + stmts.push(quote!( + const _: () = if (1 << #nvic_prio_bits) < #priority as usize { ::core::panic!(#es); }; + )); + + stmts.push(quote!(core.SCB.set_priority( + rtic::export::SystemHandler::#name, + rtic::export::cortex_logical2hw(#priority, #nvic_prio_bits), + );)); + } + + stmts +} + +pub fn architecture_specific_analysis(app: &App, _: &SyntaxAnalysis) -> parse::Result<()> { + // Check that external (device-specific) interrupts are not named after known (Cortex-M) + // exceptions + for name in app.args.dispatchers.keys() { + let name_s = name.to_string(); + + match &*name_s { + "NonMaskableInt" | "HardFault" | "MemoryManagement" | "BusFault" | "UsageFault" + | "SecureFault" | "SVCall" | "DebugMonitor" | "PendSV" | "SysTick" => { + return Err(parse::Error::new( + name.span(), + "Cortex-M exceptions can't be used as `extern` interrupts", + )); + } + + _ => {} + } + } + + // Check that there are enough external interrupts to dispatch the software tasks and the timer + // queue handler + let mut first = None; + let priorities = app + .software_tasks + .iter() + .map(|(name, task)| { + first = Some(name); + task.args.priority + }) + .filter(|prio| *prio > 0) + .collect::<HashSet<_>>(); + + let need = priorities.len(); + let given = app.args.dispatchers.len(); + if need > given { + let s = { + format!( + "not enough interrupts to dispatch \ + all software tasks (need: {need}; given: {given})" + ) + }; + + // If not enough tasks and first still is None, may cause + // "custom attribute panicked" due to unwrap on None + return Err(parse::Error::new(first.unwrap().span(), s)); + } + + // Check that all exceptions are valid; only exceptions with configurable priorities are + // accepted + for (name, task) in &app.hardware_tasks { + let name_s = task.args.binds.to_string(); + match &*name_s { + "NonMaskableInt" | "HardFault" => { + return Err(parse::Error::new( + name.span(), + "only exceptions with configurable priority can be used as hardware tasks", + )); + } + + _ => {} + } + } + + Ok(()) +} + +pub fn interrupt_entry(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> { + vec![] +} + +pub fn interrupt_exit(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> { + vec![] +} diff --git a/rtic-macros/src/codegen/bindings/template.rs b/rtic-macros/src/codegen/bindings/template.rs new file mode 100644 index 0000000..18f88fe --- /dev/null +++ b/rtic-macros/src/codegen/bindings/template.rs @@ -0,0 +1,44 @@ +use crate::{ + analyze::Analysis as CodegenAnalysis, + syntax::{analyze::Analysis as SyntaxAnalysis, ast::App}, +}; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; +use syn::{parse, Attribute, Ident}; + +pub fn impl_mutex( + _app: &App, + _analysis: &CodegenAnalysis, + _cfgs: &[Attribute], + _resources_prefix: bool, + _name: &Ident, + _ty: &TokenStream2, + _ceiling: u8, + _ptr: &TokenStream2, +) -> TokenStream2 { + quote!() +} + +pub fn extra_assertions(_app: &App, _analysis: &SyntaxAnalysis) -> Vec<TokenStream2> { + vec![] +} + +pub fn pre_init_checks(_app: &App, _analysis: &SyntaxAnalysis) -> Vec<TokenStream2> { + vec![] +} + +pub fn pre_init_enable_interrupts(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> { + vec![] +} + +pub fn architecture_specific_analysis(_app: &App, _analysis: &SyntaxAnalysis) -> parse::Result<()> { + Ok(()) +} + +pub fn interrupt_entry(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> { + vec![] +} + +pub fn interrupt_exit(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> { + vec![] +} diff --git a/rtic-macros/src/codegen/hardware_tasks.rs b/rtic-macros/src/codegen/hardware_tasks.rs new file mode 100644 index 0000000..2c5254e --- /dev/null +++ b/rtic-macros/src/codegen/hardware_tasks.rs @@ -0,0 +1,96 @@ +use crate::syntax::{ast::App, Context}; +use crate::{ + analyze::Analysis, + codegen::{ + bindings::{interrupt_entry, interrupt_exit}, + local_resources_struct, module, shared_resources_struct, + }, +}; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +/// Generate support code for hardware tasks (`#[exception]`s and `#[interrupt]`s) +pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { + let mut mod_app = vec![]; + let mut root = vec![]; + let mut user_tasks = vec![]; + + for (name, task) in &app.hardware_tasks { + let symbol = task.args.binds.clone(); + let priority = task.args.priority; + let cfgs = &task.cfgs; + let attrs = &task.attrs; + let entry_stmts = interrupt_entry(app, analysis); + let exit_stmts = interrupt_exit(app, analysis); + + mod_app.push(quote!( + #[allow(non_snake_case)] + #[no_mangle] + #(#attrs)* + #(#cfgs)* + unsafe fn #symbol() { + #(#entry_stmts)* + + const PRIORITY: u8 = #priority; + + rtic::export::run(PRIORITY, || { + #name( + #name::Context::new() + ) + }); + + #(#exit_stmts)* + } + )); + + // `${task}Locals` + if !task.args.local_resources.is_empty() { + let (item, constructor) = + local_resources_struct::codegen(Context::HardwareTask(name), app); + + root.push(item); + + mod_app.push(constructor); + } + + // `${task}Resources` + if !task.args.shared_resources.is_empty() { + let (item, constructor) = + shared_resources_struct::codegen(Context::HardwareTask(name), app); + + root.push(item); + + mod_app.push(constructor); + } + + // Module generation... + + root.push(module::codegen(Context::HardwareTask(name), app, analysis)); + + // End module generation + + if !task.is_extern { + let attrs = &task.attrs; + let context = &task.context; + let stmts = &task.stmts; + user_tasks.push(quote!( + #(#attrs)* + #[allow(non_snake_case)] + fn #name(#context: #name::Context) { + use rtic::Mutex as _; + use rtic::mutex::prelude::*; + + #(#stmts)* + } + )); + } + } + + quote!( + #(#mod_app)* + + #(#root)* + + #(#user_tasks)* + ) +} diff --git a/rtic-macros/src/codegen/idle.rs b/rtic-macros/src/codegen/idle.rs new file mode 100644 index 0000000..0c833ef --- /dev/null +++ b/rtic-macros/src/codegen/idle.rs @@ -0,0 +1,58 @@ +use crate::syntax::{ast::App, Context}; +use crate::{ + analyze::Analysis, + codegen::{local_resources_struct, module, shared_resources_struct}, +}; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +/// Generates support code for `#[idle]` functions +pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { + if let Some(idle) = &app.idle { + let mut mod_app = vec![]; + let mut root_idle = vec![]; + + let name = &idle.name; + + if !idle.args.shared_resources.is_empty() { + let (item, constructor) = shared_resources_struct::codegen(Context::Idle, app); + + root_idle.push(item); + mod_app.push(constructor); + } + + if !idle.args.local_resources.is_empty() { + let (item, constructor) = local_resources_struct::codegen(Context::Idle, app); + + root_idle.push(item); + + mod_app.push(constructor); + } + + root_idle.push(module::codegen(Context::Idle, app, analysis)); + + let attrs = &idle.attrs; + let context = &idle.context; + let stmts = &idle.stmts; + let user_idle = Some(quote!( + #(#attrs)* + #[allow(non_snake_case)] + fn #name(#context: #name::Context) -> ! { + use rtic::Mutex as _; + use rtic::mutex::prelude::*; + + #(#stmts)* + } + )); + + quote!( + #(#mod_app)* + + #(#root_idle)* + + #user_idle + ) + } else { + quote!() + } +} diff --git a/macros/src/codegen/init.rs b/rtic-macros/src/codegen/init.rs index 34f86f2..6e1059f 100644 --- a/macros/src/codegen/init.rs +++ b/rtic-macros/src/codegen/init.rs @@ -1,32 +1,15 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use rtic_syntax::{ast::App, Context}; use crate::{ analyze::Analysis, - check::Extra, codegen::{local_resources_struct, module}, + syntax::{ast::App, Context}, }; -type CodegenResult = ( - // mod_app_idle -- the `${init}Resources` constructor - Option<TokenStream2>, - // root_init -- items that must be placed in the root of the crate: - // - the `${init}Locals` struct - // - the `${init}Resources` struct - // - the `${init}LateResources` struct - // - the `${init}` module, which contains types like `${init}::Context` - Vec<TokenStream2>, - // user_init -- the `#[init]` function written by the user - TokenStream2, - // call_init -- the call to the user `#[init]` - TokenStream2, -); - /// Generates support code for `#[init]` functions -pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult { +pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { let init = &app.init; - let mut local_needs_lt = false; let name = &init.name; let mut root_init = vec![]; @@ -66,26 +49,22 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult { }) .collect(); - let shared_resources_doc = " RTIC shared resource struct".to_string(); - let local_resources_doc = " RTIC local resource struct".to_string(); root_init.push(quote! { - #[doc = #shared_resources_doc] struct #shared { #(#shared_resources)* } - #[doc = #local_resources_doc] struct #local { #(#local_resources)* } }); - let user_init_return = quote! {#shared, #local, #name::Monotonics}; - let user_init_doc = " User provided init function".to_string(); + // let locals_pat = locals_pat.iter(); + + let user_init_return = quote! {#shared, #local}; let user_init = quote!( #(#attrs)* - #[doc = #user_init_doc] #[inline(always)] #[allow(non_snake_case)] fn #name(#context: #name::Context) -> (#user_init_return) { @@ -97,26 +76,20 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult { // `${task}Locals` if !init.args.local_resources.is_empty() { - let (item, constructor) = - local_resources_struct::codegen(Context::Init, &mut local_needs_lt, app); + let (item, constructor) = local_resources_struct::codegen(Context::Init, app); root_init.push(item); mod_app = Some(constructor); } - let call_init = quote! { - let (shared_resources, local_resources, mut monotonics) = #name(#name::Context::new(core.into())); - }; + root_init.push(module::codegen(Context::Init, app, analysis)); + + quote!( + #mod_app - root_init.push(module::codegen( - Context::Init, - false, - local_needs_lt, - app, - analysis, - extra, - )); + #(#root_init)* - (mod_app, root_init, user_init, call_init) + #user_init + ) } diff --git a/macros/src/codegen/local_resources.rs b/rtic-macros/src/codegen/local_resources.rs index 6e7c1da..e6d1553 100644 --- a/macros/src/codegen/local_resources.rs +++ b/rtic-macros/src/codegen/local_resources.rs @@ -1,24 +1,13 @@ +use crate::syntax::ast::App; +use crate::{analyze::Analysis, codegen::util}; use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use rtic_syntax::ast::App; - -use crate::{analyze::Analysis, check::Extra, codegen::util}; /// Generates `local` variables and local resource proxies /// /// I.e. the `static` variables and theirs proxies. -pub fn codegen( - app: &App, - _analysis: &Analysis, - _extra: &Extra, -) -> ( - // mod_app -- the `static` variables behind the proxies - Vec<TokenStream2>, - // mod_resources -- the `resources` module - TokenStream2, -) { +pub fn codegen(app: &App, _analysis: &Analysis) -> TokenStream2 { let mut mod_app = vec![]; - // let mut mod_resources: _ = vec![]; // All local resources declared in the `#[local]' struct for (name, res) in &app.local_resources { @@ -72,5 +61,5 @@ pub fn codegen( )); } - (mod_app, TokenStream2::new()) + quote!(#(#mod_app)*) } diff --git a/macros/src/codegen/local_resources_struct.rs b/rtic-macros/src/codegen/local_resources_struct.rs index 74bdbf8..100c3eb 100644 --- a/macros/src/codegen/local_resources_struct.rs +++ b/rtic-macros/src/codegen/local_resources_struct.rs @@ -1,19 +1,23 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::{ +use crate::syntax::{ ast::{App, TaskLocal}, Context, }; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; use crate::codegen::util; /// Generates local resources structs -pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, TokenStream2) { - let mut lt = None; - +pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) { let resources = match ctxt { Context::Init => &app.init.args.local_resources, - Context::Idle => &app.idle.as_ref().unwrap().args.local_resources, + Context::Idle => { + &app.idle + .as_ref() + .expect("RTIC-ICE: unable to get idle name") + .args + .local_resources + } Context::HardwareTask(name) => &app.hardware_tasks[name].args.local_resources, Context::SoftwareTask(name) => &app.software_tasks[name].args.local_resources, }; @@ -22,7 +26,6 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, let mut fields = vec![]; let mut values = vec![]; - let mut has_cfgs = false; for (name, task_local) in resources { let (cfgs, ty, is_declared) = match task_local { @@ -31,15 +34,11 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, (&r.cfgs, &r.ty, false) } TaskLocal::Declared(r) => (&r.cfgs, &r.ty, true), - _ => unreachable!(), }; - has_cfgs |= !cfgs.is_empty(); - let lt = if ctxt.runs_once() { quote!('static) } else { - lt = Some(quote!('a)); quote!('a) }; @@ -49,10 +48,9 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, util::declared_static_local_resource_ident(name, &task_name) }; - let local_resource_doc = format!(" Local resource `{name}`"); fields.push(quote!( - #[doc = #local_resource_doc] #(#cfgs)* + #[allow(missing_docs)] pub #name: &#lt mut #ty )); @@ -70,35 +68,28 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, )); } - if lt.is_some() { - *needs_lt = true; - - // The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused - if has_cfgs { - fields.push(quote!( - #[doc(hidden)] - pub __marker__: core::marker::PhantomData<&'a ()> - )); + fields.push(quote!( + #[doc(hidden)] + pub __rtic_internal_marker: ::core::marker::PhantomData<&'a ()> + )); - values.push(quote!(__marker__: core::marker::PhantomData)); - } - } + values.push(quote!(__rtic_internal_marker: ::core::marker::PhantomData)); - let doc = format!(" Local resources `{}` has access to", ctxt.ident(app)); + let doc = format!("Local resources `{}` has access to", ctxt.ident(app)); let ident = util::local_resources_ident(ctxt, app); let item = quote!( #[allow(non_snake_case)] #[allow(non_camel_case_types)] #[doc = #doc] - pub struct #ident<#lt> { + pub struct #ident<'a> { #(#fields,)* } ); let constructor = quote!( - impl<#lt> #ident<#lt> { + impl<'a> #ident<'a> { #[inline(always)] - #[doc(hidden)] + #[allow(missing_docs)] pub unsafe fn new() -> Self { #ident { #(#values,)* diff --git a/rtic-macros/src/codegen/main.rs b/rtic-macros/src/codegen/main.rs new file mode 100644 index 0000000..2775d25 --- /dev/null +++ b/rtic-macros/src/codegen/main.rs @@ -0,0 +1,52 @@ +use crate::{analyze::Analysis, codegen::util, syntax::ast::App}; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +use super::{assertions, post_init, pre_init}; + +/// Generates code for `fn main` +pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { + let assertion_stmts = assertions::codegen(app, analysis); + + let pre_init_stmts = pre_init::codegen(app, analysis); + + let post_init_stmts = post_init::codegen(app, analysis); + + let call_idle = if let Some(idle) = &app.idle { + let name = &idle.name; + quote!(#name(#name::Context::new())) + } else if analysis.channels.get(&0).is_some() { + let dispatcher = util::zero_prio_dispatcher_ident(); + quote!(#dispatcher();) + } else { + quote!(loop { + rtic::export::nop() + }) + }; + + let main = util::suffixed("main"); + let init_name = &app.init.name; + quote!( + #[doc(hidden)] + #[no_mangle] + unsafe extern "C" fn #main() -> ! { + #(#assertion_stmts)* + + #(#pre_init_stmts)* + + #[inline(never)] + fn __rtic_init_resources<F>(f: F) where F: FnOnce() { + f(); + } + + // Wrap late_init_stmts in a function to ensure that stack space is reclaimed. + __rtic_init_resources(||{ + let (shared_resources, local_resources) = #init_name(#init_name::Context::new(core.into())); + + #(#post_init_stmts)* + }); + + #call_idle + } + ) +} diff --git a/rtic-macros/src/codegen/module.rs b/rtic-macros/src/codegen/module.rs new file mode 100644 index 0000000..af4e034 --- /dev/null +++ b/rtic-macros/src/codegen/module.rs @@ -0,0 +1,197 @@ +use crate::syntax::{ast::App, Context}; +use crate::{analyze::Analysis, codegen::util}; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +#[allow(clippy::too_many_lines)] +pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 { + let mut items = vec![]; + let mut module_items = vec![]; + let mut fields = vec![]; + let mut values = vec![]; + // Used to copy task cfgs to the whole module + let mut task_cfgs = vec![]; + + let name = ctxt.ident(app); + + match ctxt { + Context::Init => { + fields.push(quote!( + /// Core peripherals + pub core: rtic::export::Peripherals + )); + + if app.args.peripherals { + let device = &app.args.device; + + fields.push(quote!( + /// Device peripherals (PAC) + pub device: #device::Peripherals + )); + + values.push(quote!(device: #device::Peripherals::steal())); + } + + fields.push(quote!( + /// Critical section token for init + pub cs: rtic::export::CriticalSection<'a> + )); + + values.push(quote!(cs: rtic::export::CriticalSection::new())); + + values.push(quote!(core)); + } + + Context::Idle | Context::HardwareTask(_) | Context::SoftwareTask(_) => {} + } + + if ctxt.has_local_resources(app) { + let ident = util::local_resources_ident(ctxt, app); + + module_items.push(quote!( + #[doc(inline)] + pub use super::#ident as LocalResources; + )); + + fields.push(quote!( + /// Local Resources this task has access to + pub local: #name::LocalResources<'a> + )); + + values.push(quote!(local: #name::LocalResources::new())); + } + + if ctxt.has_shared_resources(app) { + let ident = util::shared_resources_ident(ctxt, app); + + module_items.push(quote!( + #[doc(inline)] + pub use super::#ident as SharedResources; + )); + + fields.push(quote!( + /// Shared Resources this task has access to + pub shared: #name::SharedResources<'a> + )); + + values.push(quote!(shared: #name::SharedResources::new())); + } + + let doc = match ctxt { + Context::Idle => "Idle loop", + Context::Init => "Initialization function", + Context::HardwareTask(_) => "Hardware task", + Context::SoftwareTask(_) => "Software task", + }; + + let v = Vec::new(); + let cfgs = match ctxt { + Context::HardwareTask(t) => &app.hardware_tasks[t].cfgs, + Context::SoftwareTask(t) => &app.software_tasks[t].cfgs, + _ => &v, + }; + + let core = if ctxt.is_init() { + Some(quote!(core: rtic::export::Peripherals,)) + } else { + None + }; + + let internal_context_name = util::internal_task_ident(name, "Context"); + let exec_name = util::internal_task_ident(name, "EXEC"); + + items.push(quote!( + #(#cfgs)* + /// Execution context + #[allow(non_snake_case)] + #[allow(non_camel_case_types)] + pub struct #internal_context_name<'a> { + #[doc(hidden)] + __rtic_internal_p: ::core::marker::PhantomData<&'a ()>, + #(#fields,)* + } + + #(#cfgs)* + impl<'a> #internal_context_name<'a> { + #[inline(always)] + #[allow(missing_docs)] + pub unsafe fn new(#core) -> Self { + #internal_context_name { + __rtic_internal_p: ::core::marker::PhantomData, + #(#values,)* + } + } + } + )); + + module_items.push(quote!( + #(#cfgs)* + #[doc(inline)] + pub use super::#internal_context_name as Context; + )); + + if let Context::SoftwareTask(..) = ctxt { + let spawnee = &app.software_tasks[name]; + let priority = spawnee.args.priority; + let cfgs = &spawnee.cfgs; + // Store a copy of the task cfgs + task_cfgs = cfgs.clone(); + + let pend_interrupt = if priority > 0 { + let device = &app.args.device; + let enum_ = util::interrupt_ident(); + let interrupt = &analysis.interrupts.get(&priority).expect("UREACHABLE").0; + quote!(rtic::pend(#device::#enum_::#interrupt);) + } else { + quote!() + }; + + let internal_spawn_ident = util::internal_task_ident(name, "spawn"); + let (input_args, input_tupled, input_untupled, input_ty) = + util::regroup_inputs(&spawnee.inputs); + + // Spawn caller + items.push(quote!( + #(#cfgs)* + /// Spawns the task directly + #[allow(non_snake_case)] + #[doc(hidden)] + pub fn #internal_spawn_ident(#(#input_args,)*) -> Result<(), #input_ty> { + // SAFETY: If `try_allocate` suceeds one must call `spawn`, which we do. + unsafe { + if #exec_name.try_allocate() { + let f = #name(unsafe { #name::Context::new() } #(,#input_untupled)*); + #exec_name.spawn(f); + #pend_interrupt + + Ok(()) + } else { + Err(#input_tupled) + } + } + + } + )); + + module_items.push(quote!( + #(#cfgs)* + #[doc(inline)] + pub use super::#internal_spawn_ident as spawn; + )); + } + + if items.is_empty() { + quote!() + } else { + quote!( + #(#items)* + + #[allow(non_snake_case)] + #(#task_cfgs)* + #[doc = #doc] + pub mod #name { + #(#module_items)* + } + ) + } +} diff --git a/macros/src/codegen/post_init.rs b/rtic-macros/src/codegen/post_init.rs index 460b4e2..c4e5383 100644 --- a/macros/src/codegen/post_init.rs +++ b/rtic-macros/src/codegen/post_init.rs @@ -1,9 +1,6 @@ -use proc_macro2::{Span, TokenStream as TokenStream2}; +use crate::{analyze::Analysis, codegen::util, syntax::ast::App}; +use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use rtic_syntax::ast::App; -use syn::Index; - -use crate::{analyze::Analysis, codegen::util}; /// Generates code that runs after `#[init]` returns pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { @@ -43,30 +40,6 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { } } - for (i, (monotonic_ident, monotonic)) in app.monotonics.iter().enumerate() { - // For future use - // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); - // stmts.push(quote!(#[doc = #doc])); - let cfgs = &monotonic.cfgs; - - #[allow(clippy::cast_possible_truncation)] - let idx = Index { - index: i as u32, - span: Span::call_site(), - }; - stmts.push(quote!( - #(#cfgs)* - monotonics.#idx.reset(); - )); - - // Store the monotonic - let name = util::monotonic_ident(&monotonic_ident.to_string()); - stmts.push(quote!( - #(#cfgs)* - #name.get_mut().write(Some(monotonics.#idx)); - )); - } - // Enable the interrupts -- this completes the `init`-ialization phase stmts.push(quote!(rtic::export::interrupt::enable();)); diff --git a/rtic-macros/src/codegen/pre_init.rs b/rtic-macros/src/codegen/pre_init.rs new file mode 100644 index 0000000..a2d0e8c --- /dev/null +++ b/rtic-macros/src/codegen/pre_init.rs @@ -0,0 +1,24 @@ +use super::bindings::{pre_init_checks, pre_init_enable_interrupts}; +use crate::analyze::Analysis; +use crate::syntax::ast::App; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +/// Generates code that runs before `#[init]` +pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { + let mut stmts = vec![]; + + // Disable interrupts -- `init` must run with interrupts disabled + stmts.push(quote!(rtic::export::interrupt::disable();)); + + stmts.push(quote!( + // To set the variable in cortex_m so the peripherals cannot be taken multiple times + let mut core: rtic::export::Peripherals = rtic::export::Peripherals::steal().into(); + )); + + stmts.append(&mut pre_init_checks(app, analysis)); + + stmts.append(&mut pre_init_enable_interrupts(app, analysis)); + + stmts +} diff --git a/rtic-macros/src/codegen/shared_resources.rs b/rtic-macros/src/codegen/shared_resources.rs new file mode 100644 index 0000000..686c280 --- /dev/null +++ b/rtic-macros/src/codegen/shared_resources.rs @@ -0,0 +1,105 @@ +use crate::syntax::{analyze::Ownership, ast::App}; +use crate::{analyze::Analysis, codegen::util}; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +use super::bindings::impl_mutex; + +/// Generates `static` variables and shared resource proxies +pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { + let mut mod_app = vec![]; + let mut mod_resources = vec![]; + + for (name, res) in &app.shared_resources { + let cfgs = &res.cfgs; + let ty = &res.ty; + let mangled_name = &util::static_shared_resource_ident(name); + + let attrs = &res.attrs; + + // late resources in `util::link_section_uninit` + // unless user specifies custom link section + let section = if attrs.iter().any(|attr| attr.path.is_ident("link_section")) { + None + } else { + Some(util::link_section_uninit()) + }; + + // For future use + // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + mod_app.push(quote!( + #[allow(non_camel_case_types)] + #[allow(non_upper_case_globals)] + // #[doc = #doc] + #[doc(hidden)] + #(#attrs)* + #(#cfgs)* + #section + static #mangled_name: rtic::RacyCell<core::mem::MaybeUninit<#ty>> = rtic::RacyCell::new(core::mem::MaybeUninit::uninit()); + )); + + // For future use + // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + + let shared_name = util::need_to_lock_ident(name); + + if !res.properties.lock_free { + mod_resources.push(quote!( + // #[doc = #doc] + #[doc(hidden)] + #[allow(non_camel_case_types)] + #(#cfgs)* + pub struct #shared_name<'a> { + __rtic_internal_p: ::core::marker::PhantomData<&'a ()>, + } + + #(#cfgs)* + impl<'a> #shared_name<'a> { + #[inline(always)] + pub unsafe fn new() -> Self { + #shared_name { __rtic_internal_p: ::core::marker::PhantomData } + } + } + )); + + let ptr = quote!( + #(#cfgs)* + #mangled_name.get_mut() as *mut _ + ); + + let ceiling = match analysis.ownerships.get(name) { + Some(Ownership::Owned { priority } | Ownership::CoOwned { priority }) => *priority, + Some(Ownership::Contended { ceiling }) => *ceiling, + None => 0, + }; + + // For future use + // let doc = format!(" RTIC internal ({} resource): {}:{}", doc, file!(), line!()); + + mod_app.push(impl_mutex( + app, + analysis, + cfgs, + true, + &shared_name, + "e!(#ty), + ceiling, + &ptr, + )); + } + } + + let mod_resources = if mod_resources.is_empty() { + quote!() + } else { + quote!(mod shared_resources { + #(#mod_resources)* + }) + }; + + quote!( + #(#mod_app)* + + #mod_resources + ) +} diff --git a/macros/src/codegen/shared_resources_struct.rs b/rtic-macros/src/codegen/shared_resources_struct.rs index df36271..fa6f0fc 100644 --- a/macros/src/codegen/shared_resources_struct.rs +++ b/rtic-macros/src/codegen/shared_resources_struct.rs @@ -1,42 +1,31 @@ +use crate::syntax::{ast::App, Context}; use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use rtic_syntax::{ast::App, Context}; use crate::codegen::util; /// Generate shared resources structs -pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, TokenStream2) { - let mut lt = None; - +pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) { let resources = match ctxt { Context::Init => unreachable!("Tried to generate shared resources struct for init"), - Context::Idle => &app.idle.as_ref().unwrap().args.shared_resources, + Context::Idle => { + &app.idle + .as_ref() + .expect("RTIC-ICE: unable to get idle name") + .args + .shared_resources + } Context::HardwareTask(name) => &app.hardware_tasks[name].args.shared_resources, Context::SoftwareTask(name) => &app.software_tasks[name].args.shared_resources, }; - let v = Vec::new(); - let task_cfgs = match ctxt { - Context::HardwareTask(t) => { - &app.hardware_tasks[t].cfgs - // ... - } - Context::SoftwareTask(t) => { - &app.software_tasks[t].cfgs - // ... - } - _ => &v, - }; - let mut fields = vec![]; let mut values = vec![]; - let mut has_cfgs = false; for (name, access) in resources { let res = app.shared_resources.get(name).expect("UNREACHABLE"); let cfgs = &res.cfgs; - has_cfgs |= !cfgs.is_empty(); // access hold if the resource is [x] (exclusive) or [&x] (shared) let mut_ = if access.is_exclusive() { @@ -53,41 +42,30 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, let lt = if ctxt.runs_once() { quote!('static) } else { - lt = Some(quote!('a)); quote!('a) }; - let lock_free_resource_doc = format!(" Lock free resource `{name}`"); fields.push(quote!( - #[doc = #lock_free_resource_doc] #(#cfgs)* + #[allow(missing_docs)] pub #name: &#lt #mut_ #ty )); } else if access.is_shared() { - lt = Some(quote!('a)); - - let shared_resource_doc = format!(" Shared resource `{name}`"); fields.push(quote!( - #[doc = #shared_resource_doc] #(#cfgs)* + #[allow(missing_docs)] pub #name: &'a #ty )); } else { - // Resource proxy - lt = Some(quote!('a)); - - let resource_doc = - format!(" Resource proxy resource `{name}`. Use method `.lock()` to gain access"); fields.push(quote!( - #[doc = #resource_doc] #(#cfgs)* + #[allow(missing_docs)] pub #name: shared_resources::#shared_name<'a> )); values.push(quote!( - #[doc(hidden)] #(#cfgs)* - #name: shared_resources::#shared_name::new(priority) + #name: shared_resources::#shared_name::new() )); @@ -95,59 +73,41 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, continue; } - let resource_doc; let expr = if access.is_exclusive() { - resource_doc = format!(" Exclusive access resource `{name}`"); quote!(&mut *(&mut *#mangled_name.get_mut()).as_mut_ptr()) } else { - resource_doc = format!(" Non-exclusive access resource `{name}`"); quote!(&*(&*#mangled_name.get()).as_ptr()) }; values.push(quote!( - #[doc = #resource_doc] #(#cfgs)* #name: #expr )); } - if lt.is_some() { - *needs_lt = true; + fields.push(quote!( + #[doc(hidden)] + pub __rtic_internal_marker: core::marker::PhantomData<&'a ()> + )); - // The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused - if has_cfgs { - fields.push(quote!( - #[doc(hidden)] - pub __marker__: core::marker::PhantomData<&'a ()> - )); + values.push(quote!(__rtic_internal_marker: core::marker::PhantomData)); - values.push(quote!(__marker__: core::marker::PhantomData)); - } - } - - let doc = format!(" Shared resources `{}` has access to", ctxt.ident(app)); + let doc = format!("Shared resources `{}` has access to", ctxt.ident(app)); let ident = util::shared_resources_ident(ctxt, app); let item = quote!( #[allow(non_snake_case)] #[allow(non_camel_case_types)] #[doc = #doc] - #(#task_cfgs)* - pub struct #ident<#lt> { + pub struct #ident<'a> { #(#fields,)* } ); - let arg = if ctxt.is_init() { - None - } else { - Some(quote!(priority: &#lt rtic::export::Priority)) - }; let constructor = quote!( - #(#task_cfgs)* - impl<#lt> #ident<#lt> { - #[doc(hidden)] + impl<'a> #ident<'a> { #[inline(always)] - pub unsafe fn new(#arg) -> Self { + #[allow(missing_docs)] + pub unsafe fn new() -> Self { #ident { #(#values,)* } diff --git a/rtic-macros/src/codegen/software_tasks.rs b/rtic-macros/src/codegen/software_tasks.rs new file mode 100644 index 0000000..34fc851 --- /dev/null +++ b/rtic-macros/src/codegen/software_tasks.rs @@ -0,0 +1,64 @@ +use crate::syntax::{ast::App, Context}; +use crate::{ + analyze::Analysis, + codegen::{local_resources_struct, module, shared_resources_struct}, +}; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { + let mut mod_app = vec![]; + let mut root = vec![]; + let mut user_tasks = vec![]; + + // Any task + for (name, task) in app.software_tasks.iter() { + if !task.args.local_resources.is_empty() { + let (item, constructor) = + local_resources_struct::codegen(Context::SoftwareTask(name), app); + + root.push(item); + + mod_app.push(constructor); + } + + if !task.args.shared_resources.is_empty() { + let (item, constructor) = + shared_resources_struct::codegen(Context::SoftwareTask(name), app); + + root.push(item); + + mod_app.push(constructor); + } + + if !&task.is_extern { + let context = &task.context; + let attrs = &task.attrs; + let cfgs = &task.cfgs; + let stmts = &task.stmts; + let inputs = &task.inputs; + + user_tasks.push(quote!( + #(#attrs)* + #(#cfgs)* + #[allow(non_snake_case)] + async fn #name<'a>(#context: #name::Context<'a> #(,#inputs)*) { + use rtic::Mutex as _; + use rtic::mutex::prelude::*; + + #(#stmts)* + } + )); + } + + root.push(module::codegen(Context::SoftwareTask(name), app, analysis)); + } + + quote!( + #(#mod_app)* + + #(#root)* + + #(#user_tasks)* + ) +} diff --git a/rtic-macros/src/codegen/util.rs b/rtic-macros/src/codegen/util.rs new file mode 100644 index 0000000..2f44edb --- /dev/null +++ b/rtic-macros/src/codegen/util.rs @@ -0,0 +1,170 @@ +use crate::syntax::{ast::App, Context}; +use core::sync::atomic::{AtomicUsize, Ordering}; +use proc_macro2::{Span, TokenStream as TokenStream2}; +use quote::quote; +use syn::{Ident, PatType}; + +const RTIC_INTERNAL: &str = "__rtic_internal"; + +pub fn interrupt_ident() -> Ident { + let span = Span::call_site(); + Ident::new("interrupt", span) +} + +/// Mark a name as internal +pub fn mark_internal_name(name: &str) -> Ident { + Ident::new(&format!("{RTIC_INTERNAL}_{name}"), Span::call_site()) +} + +/// Generate an internal identifier for tasks +pub fn internal_task_ident(task: &Ident, ident_name: &str) -> Ident { + mark_internal_name(&format!("{task}_{ident_name}")) +} + +fn link_section_index() -> usize { + static INDEX: AtomicUsize = AtomicUsize::new(0); + + INDEX.fetch_add(1, Ordering::Relaxed) +} + +/// Add `link_section` attribute +pub fn link_section_uninit() -> TokenStream2 { + let section = format!(".uninit.rtic{}", link_section_index()); + + quote!(#[link_section = #section]) +} + +/// Regroups the inputs of a task +/// +/// `inputs` could be &[`input: Foo`] OR &[`mut x: i32`, `ref y: i64`] +pub fn regroup_inputs( + inputs: &[PatType], +) -> ( + // args e.g. &[`_0`], &[`_0: i32`, `_1: i64`] + Vec<TokenStream2>, + // tupled e.g. `_0`, `(_0, _1)` + TokenStream2, + // untupled e.g. &[`_0`], &[`_0`, `_1`] + Vec<TokenStream2>, + // ty e.g. `Foo`, `(i32, i64)` + TokenStream2, +) { + if inputs.len() == 1 { + let ty = &inputs[0].ty; + + ( + vec![quote!(_0: #ty)], + quote!(_0), + vec![quote!(_0)], + quote!(#ty), + ) + } else { + let mut args = vec![]; + let mut pats = vec![]; + let mut tys = vec![]; + + for (i, input) in inputs.iter().enumerate() { + let i = Ident::new(&format!("_{i}"), Span::call_site()); + let ty = &input.ty; + + args.push(quote!(#i: #ty)); + + pats.push(quote!(#i)); + + tys.push(quote!(#ty)); + } + + let tupled = { + let pats = pats.clone(); + quote!((#(#pats,)*)) + }; + let ty = quote!((#(#tys,)*)); + (args, tupled, pats, ty) + } +} + +/// Get the ident for the name of the task +pub fn get_task_name(ctxt: Context, app: &App) -> Ident { + let s = match ctxt { + Context::Init => app.init.name.to_string(), + Context::Idle => app + .idle + .as_ref() + .expect("RTIC-ICE: unable to find idle name") + .name + .to_string(), + Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), + }; + + Ident::new(&s, Span::call_site()) +} + +/// Generates a pre-reexport identifier for the "shared resources" struct +pub fn shared_resources_ident(ctxt: Context, app: &App) -> Ident { + let mut s = match ctxt { + Context::Init => app.init.name.to_string(), + Context::Idle => app + .idle + .as_ref() + .expect("RTIC-ICE: unable to find idle name") + .name + .to_string(), + Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), + }; + + s.push_str("SharedResources"); + + mark_internal_name(&s) +} + +/// Generates a pre-reexport identifier for the "local resources" struct +pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { + let mut s = match ctxt { + Context::Init => app.init.name.to_string(), + Context::Idle => app + .idle + .as_ref() + .expect("RTIC-ICE: unable to find idle name") + .name + .to_string(), + Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), + }; + + s.push_str("LocalResources"); + + mark_internal_name(&s) +} + +/// Suffixed identifier +pub fn suffixed(name: &str) -> Ident { + let span = Span::call_site(); + Ident::new(name, span) +} + +pub fn static_shared_resource_ident(name: &Ident) -> Ident { + mark_internal_name(&format!("shared_resource_{name}")) +} + +pub fn static_local_resource_ident(name: &Ident) -> Ident { + mark_internal_name(&format!("local_resource_{name}")) +} + +pub fn declared_static_local_resource_ident(name: &Ident, task_name: &Ident) -> Ident { + mark_internal_name(&format!("local_{task_name}_{name}")) +} + +pub fn need_to_lock_ident(name: &Ident) -> Ident { + Ident::new(&format!("{name}_that_needs_to_be_locked"), name.span()) +} + +pub fn zero_prio_dispatcher_ident() -> Ident { + Ident::new("__rtic_internal_async_0_prio_dispatcher", Span::call_site()) +} + +/// The name to get better RT flag errors +pub fn rt_err_ident() -> Ident { + Ident::new( + "you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml", + Span::call_site(), + ) +} diff --git a/macros/src/lib.rs b/rtic-macros/src/lib.rs index 2b52601..cd2a924 100644 --- a/macros/src/lib.rs +++ b/rtic-macros/src/lib.rs @@ -1,21 +1,27 @@ #![doc( - html_logo_url = "https://raw.githubusercontent.com/rtic-rs/cortex-m-rtic/master/book/en/src/RTIC.svg", - html_favicon_url = "https://raw.githubusercontent.com/rtic-rs/cortex-m-rtic/master/book/en/src/RTIC.svg" + html_logo_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg", + html_favicon_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg" )] //deny_warnings_placeholder_for_ci -extern crate proc_macro; - use proc_macro::TokenStream; use std::{env, fs, path::Path}; -use rtic_syntax::Settings; - mod analyze; mod check; mod codegen; -#[cfg(test)] -mod tests; +mod syntax; + +// Used for mocking the API in testing +#[doc(hidden)] +#[proc_macro_attribute] +pub fn mock_app(args: TokenStream, input: TokenStream) -> TokenStream { + if let Err(e) = syntax::parse(args, input) { + e.to_compile_error().into() + } else { + "fn main() {}".parse().unwrap() + } +} /// Attribute used to declare a RTIC application /// @@ -26,24 +32,18 @@ mod tests; /// Should never panic, cargo feeds a path which is later converted to a string #[proc_macro_attribute] pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { - let mut settings = Settings::default(); - settings.optimize_priorities = false; - settings.parse_binds = true; - settings.parse_extern_interrupt = true; - - let (app, analysis) = match rtic_syntax::parse(args, input, settings) { + let (app, analysis) = match syntax::parse(args, input) { Err(e) => return e.to_compile_error().into(), Ok(x) => x, }; - let extra = match check::app(&app, &analysis) { - Err(e) => return e.to_compile_error().into(), - Ok(x) => x, - }; + if let Err(e) = check::app(&app, &analysis) { + return e.to_compile_error().into(); + } let analysis = analyze::app(analysis, &app); - let ts = codegen::app(&app, &analysis, &extra); + let ts = codegen::app(&app, &analysis); // Default output path: <project_dir>/target/ let mut out_dir = Path::new("target"); @@ -52,28 +52,13 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { // TODO don't want to break builds if OUT_DIR is not set, is this ever the case? let out_str = env::var("OUT_DIR").unwrap_or_else(|_| "".to_string()); - // Assuming we are building for a thumbv* target - let target_triple_prefix = "thumbv"; - - // Check for special scenario where default target/ directory is not present - // - // This is configurable in .cargo/config: - // - // [build] - // target-dir = "target" - #[cfg(feature = "debugprint")] - println!("OUT_DIR\n{:#?}", out_str); - - if out_dir.exists() { - #[cfg(feature = "debugprint")] - println!("\ntarget/ exists\n"); - } else { + if !out_dir.exists() { // Set out_dir to OUT_DIR out_dir = Path::new(&out_str); // Default build path, annotated below: - // $(pwd)/target/thumbv7em-none-eabihf/debug/build/cortex-m-rtic-<HASH>/out/ - // <project_dir>/<target-dir>/<TARGET>/debug/build/cortex-m-rtic-<HASH>/out/ + // $(pwd)/target/thumbv7em-none-eabihf/debug/build/rtic-<HASH>/out/ + // <project_dir>/<target-dir>/<TARGET>/debug/build/rtic-<HASH>/out/ // // traverse up to first occurrence of TARGET, approximated with starts_with("thumbv") // and use the parent() of this path @@ -81,16 +66,11 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { // If no "target" directory is found, <project_dir>/<out_dir_root> is used for path in out_dir.ancestors() { if let Some(dir) = path.components().last() { - if dir - .as_os_str() - .to_str() - .unwrap() - .starts_with(target_triple_prefix) - { + let dir = dir.as_os_str().to_str().unwrap(); + + if dir.starts_with("thumbv") || dir.starts_with("riscv") { if let Some(out) = path.parent() { out_dir = out; - #[cfg(feature = "debugprint")] - println!("{:#?}\n", out_dir); break; } // If no parent, just use it @@ -103,9 +83,7 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { // Try to write the expanded code to disk if let Some(out_str) = out_dir.to_str() { - #[cfg(feature = "debugprint")] - println!("Write file:\n{}/rtic-expansion.rs\n", out_str); - fs::write(format!("{}/rtic-expansion.rs", out_str), ts.to_string()).ok(); + fs::write(format!("{out_str}/rtic-expansion.rs"), ts.to_string()).ok(); } ts.into() diff --git a/rtic-macros/src/syntax.rs b/rtic-macros/src/syntax.rs new file mode 100644 index 0000000..d6f5a47 --- /dev/null +++ b/rtic-macros/src/syntax.rs @@ -0,0 +1,121 @@ +#[allow(unused_extern_crates)] +extern crate proc_macro; + +use proc_macro::TokenStream; + +use indexmap::{IndexMap, IndexSet}; +use proc_macro2::TokenStream as TokenStream2; +use syn::Ident; + +use crate::syntax::ast::App; + +mod accessors; +pub mod analyze; +pub mod ast; +mod check; +mod parse; + +/// An ordered map keyed by identifier +pub type Map<T> = IndexMap<Ident, T>; + +/// An order set +pub type Set<T> = IndexSet<T>; + +/// Execution context +#[derive(Clone, Copy)] +pub enum Context<'a> { + /// The `idle` context + Idle, + + /// The `init`-ialization function + Init, + + /// A async software task + SoftwareTask(&'a Ident), + + /// A hardware task + HardwareTask(&'a Ident), +} + +impl<'a> Context<'a> { + /// The identifier of this context + pub fn ident(&self, app: &'a App) -> &'a Ident { + match self { + Context::HardwareTask(ident) => ident, + Context::Idle => &app.idle.as_ref().unwrap().name, + Context::Init => &app.init.name, + Context::SoftwareTask(ident) => ident, + } + } + + /// Is this the `idle` context? + pub fn is_idle(&self) -> bool { + matches!(self, Context::Idle) + } + + /// Is this the `init`-ialization context? + pub fn is_init(&self) -> bool { + matches!(self, Context::Init) + } + + /// Whether this context runs only once + pub fn runs_once(&self) -> bool { + self.is_init() || self.is_idle() + } + + /// Whether this context has shared resources + pub fn has_shared_resources(&self, app: &App) -> bool { + match *self { + Context::HardwareTask(name) => { + !app.hardware_tasks[name].args.shared_resources.is_empty() + } + Context::Idle => !app.idle.as_ref().unwrap().args.shared_resources.is_empty(), + Context::Init => false, + Context::SoftwareTask(name) => { + !app.software_tasks[name].args.shared_resources.is_empty() + } + } + } + + /// Whether this context has local resources + pub fn has_local_resources(&self, app: &App) -> bool { + match *self { + Context::HardwareTask(name) => { + !app.hardware_tasks[name].args.local_resources.is_empty() + } + Context::Idle => !app.idle.as_ref().unwrap().args.local_resources.is_empty(), + Context::Init => !app.init.args.local_resources.is_empty(), + Context::SoftwareTask(name) => { + !app.software_tasks[name].args.local_resources.is_empty() + } + } + } +} + +/// Parses the input of the `#[app]` attribute +pub fn parse( + args: TokenStream, + input: TokenStream, +) -> Result<(ast::App, analyze::Analysis), syn::parse::Error> { + parse2(args.into(), input.into()) +} + +/// `proc_macro2::TokenStream` version of `parse` +pub fn parse2( + args: TokenStream2, + input: TokenStream2, +) -> Result<(ast::App, analyze::Analysis), syn::parse::Error> { + let app = parse::app(args, input)?; + check::app(&app)?; + + match analyze::app(&app) { + Err(e) => Err(e), + // If no errors, return the app and analysis results + Ok(analysis) => Ok((app, analysis)), + } +} + +enum Either<A, B> { + Left(A), + Right(B), +} diff --git a/rtic-macros/src/syntax/.travis.yml b/rtic-macros/src/syntax/.travis.yml new file mode 100644 index 0000000..52d1ffd --- /dev/null +++ b/rtic-macros/src/syntax/.travis.yml @@ -0,0 +1,31 @@ +language: rust + +matrix: + include: + # MSRV + - env: TARGET=x86_64-unknown-linux-gnu + rust: 1.36.0 + + - env: TARGET=x86_64-unknown-linux-gnu + rust: stable + +before_install: set -e + +script: + - bash ci/script.sh + +after_script: set +e + +cache: cargo + +before_cache: + - chmod -R a+r $HOME/.cargo; + +branches: + only: + - staging + - trying + +notifications: + email: + on_success: never diff --git a/rtic-macros/src/syntax/accessors.rs b/rtic-macros/src/syntax/accessors.rs new file mode 100644 index 0000000..e75dde6 --- /dev/null +++ b/rtic-macros/src/syntax/accessors.rs @@ -0,0 +1,113 @@ +use syn::Ident; + +use crate::syntax::{ + analyze::Priority, + ast::{Access, App, Local, TaskLocal}, +}; + +impl App { + pub(crate) fn shared_resource_accesses( + &self, + ) -> impl Iterator<Item = (Option<Priority>, &Ident, Access)> { + self.idle + .iter() + .flat_map(|idle| { + idle.args + .shared_resources + .iter() + .map(move |(name, access)| (Some(0), name, *access)) + }) + .chain(self.hardware_tasks.values().flat_map(|task| { + task.args + .shared_resources + .iter() + .map(move |(name, access)| (Some(task.args.priority), name, *access)) + })) + .chain(self.software_tasks.values().flat_map(|task| { + task.args + .shared_resources + .iter() + .map(move |(name, access)| (Some(task.args.priority), name, *access)) + })) + } + + fn is_external(task_local: &TaskLocal) -> bool { + matches!(task_local, TaskLocal::External) + } + + pub(crate) fn local_resource_accesses(&self) -> impl Iterator<Item = &Ident> { + self.init + .args + .local_resources + .iter() + .filter(|(_, task_local)| Self::is_external(task_local)) // Only check the resources declared in `#[local]` + .map(move |(name, _)| name) + .chain(self.idle.iter().flat_map(|idle| { + idle.args + .local_resources + .iter() + .filter(|(_, task_local)| Self::is_external(task_local)) // Only check the resources declared in `#[local]` + .map(move |(name, _)| name) + })) + .chain(self.hardware_tasks.values().flat_map(|task| { + task.args + .local_resources + .iter() + .filter(|(_, task_local)| Self::is_external(task_local)) // Only check the resources declared in `#[local]` + .map(move |(name, _)| name) + })) + .chain(self.software_tasks.values().flat_map(|task| { + task.args + .local_resources + .iter() + .filter(|(_, task_local)| Self::is_external(task_local)) // Only check the resources declared in `#[local]` + .map(move |(name, _)| name) + })) + } + + fn get_declared_local(tl: &TaskLocal) -> Option<&Local> { + match tl { + TaskLocal::External => None, + TaskLocal::Declared(l) => Some(l), + } + } + + /// Get all declared local resources, i.e. `local = [NAME: TYPE = EXPR]`. + /// + /// Returns a vector of (task name, resource name, `Local` struct) + pub fn declared_local_resources(&self) -> Vec<(&Ident, &Ident, &Local)> { + self.init + .args + .local_resources + .iter() + .filter_map(move |(name, tl)| { + Self::get_declared_local(tl).map(|l| (&self.init.name, name, l)) + }) + .chain(self.idle.iter().flat_map(|idle| { + idle.args + .local_resources + .iter() + .filter_map(move |(name, tl)| { + Self::get_declared_local(tl) + .map(|l| (&self.idle.as_ref().unwrap().name, name, l)) + }) + })) + .chain(self.hardware_tasks.iter().flat_map(|(task_name, task)| { + task.args + .local_resources + .iter() + .filter_map(move |(name, tl)| { + Self::get_declared_local(tl).map(|l| (task_name, name, l)) + }) + })) + .chain(self.software_tasks.iter().flat_map(|(task_name, task)| { + task.args + .local_resources + .iter() + .filter_map(move |(name, tl)| { + Self::get_declared_local(tl).map(|l| (task_name, name, l)) + }) + })) + .collect() + } +} diff --git a/rtic-macros/src/syntax/analyze.rs b/rtic-macros/src/syntax/analyze.rs new file mode 100644 index 0000000..57f9f2c --- /dev/null +++ b/rtic-macros/src/syntax/analyze.rs @@ -0,0 +1,414 @@ +//! RTIC application analysis + +use core::cmp; +use std::collections::{BTreeMap, BTreeSet, HashMap}; + +use indexmap::{IndexMap, IndexSet}; +use syn::{Ident, Type}; + +use crate::syntax::{ + ast::{App, LocalResources, TaskLocal}, + Set, +}; + +pub(crate) fn app(app: &App) -> Result<Analysis, syn::Error> { + // Collect all tasks into a vector + type TaskName = Ident; + type Priority = u8; + + // The task list is a Tuple (Name, Shared Resources, Local Resources, Priority) + let task_resources_list: Vec<(TaskName, Vec<&Ident>, &LocalResources, Priority)> = + Some(&app.init) + .iter() + .map(|ht| (ht.name.clone(), Vec::new(), &ht.args.local_resources, 0)) + .chain(app.idle.iter().map(|ht| { + ( + ht.name.clone(), + ht.args + .shared_resources + .iter() + .map(|(v, _)| v) + .collect::<Vec<_>>(), + &ht.args.local_resources, + 0, + ) + })) + .chain(app.software_tasks.iter().map(|(name, ht)| { + ( + name.clone(), + ht.args + .shared_resources + .iter() + .map(|(v, _)| v) + .collect::<Vec<_>>(), + &ht.args.local_resources, + ht.args.priority, + ) + })) + .chain(app.hardware_tasks.iter().map(|(name, ht)| { + ( + name.clone(), + ht.args + .shared_resources + .iter() + .map(|(v, _)| v) + .collect::<Vec<_>>(), + &ht.args.local_resources, + ht.args.priority, + ) + })) + .collect(); + + let mut error = vec![]; + let mut lf_res_with_error = vec![]; + let mut lf_hash = HashMap::new(); + + // Collect lock free resources + let lock_free: Vec<&Ident> = app + .shared_resources + .iter() + .filter(|(_, r)| r.properties.lock_free) + .map(|(i, _)| i) + .collect(); + + // Check that lock_free resources are correct + for lf_res in lock_free.iter() { + for (task, tr, _, priority) in task_resources_list.iter() { + for r in tr { + // Get all uses of resources annotated lock_free + if lf_res == r { + // Check so async tasks do not use lock free resources + if app.software_tasks.get(task).is_some() { + error.push(syn::Error::new( + r.span(), + format!( + "Lock free shared resource {:?} is used by an async tasks, which is forbidden", + r.to_string(), + ), + )); + } + + // HashMap returns the previous existing object if old.key == new.key + if let Some(lf_res) = lf_hash.insert(r.to_string(), (task, r, priority)) { + // Check if priority differ, if it does, append to + // list of resources which will be annotated with errors + if priority != lf_res.2 { + lf_res_with_error.push(lf_res.1); + lf_res_with_error.push(r); + } + + // If the resource already violates lock free properties + if lf_res_with_error.contains(&r) { + lf_res_with_error.push(lf_res.1); + lf_res_with_error.push(r); + } + } + } + } + } + } + + // Add error message in the resource struct + for r in lock_free { + if lf_res_with_error.contains(&&r) { + error.push(syn::Error::new( + r.span(), + format!( + "Lock free shared resource {:?} is used by tasks at different priorities", + r.to_string(), + ), + )); + } + } + + // Add error message for each use of the shared resource + for resource in lf_res_with_error.clone() { + error.push(syn::Error::new( + resource.span(), + format!( + "Shared resource {:?} is declared lock free but used by tasks at different priorities", + resource.to_string(), + ), + )); + } + + // Collect local resources + let local: Vec<&Ident> = app.local_resources.iter().map(|(i, _)| i).collect(); + + let mut lr_with_error = vec![]; + let mut lr_hash = HashMap::new(); + + // Check that local resources are not shared + for lr in local { + for (task, _, local_resources, _) in task_resources_list.iter() { + for (name, res) in local_resources.iter() { + // Get all uses of resources annotated lock_free + if lr == name { + match res { + TaskLocal::External => { + // HashMap returns the previous existing object if old.key == new.key + if let Some(lr) = lr_hash.insert(name.to_string(), (task, name)) { + lr_with_error.push(lr.1); + lr_with_error.push(name); + } + } + // If a declared local has the same name as the `#[local]` struct, it's an + // direct error + TaskLocal::Declared(_) => { + lr_with_error.push(lr); + lr_with_error.push(name); + } + } + } + } + } + } + + // Add error message for each use of the local resource + for resource in lr_with_error.clone() { + error.push(syn::Error::new( + resource.span(), + format!( + "Local resource {:?} is used by multiple tasks or collides with multiple definitions", + resource.to_string(), + ), + )); + } + + // Check 0-priority async software tasks and idle dependency + for (name, task) in &app.software_tasks { + if task.args.priority == 0 { + // If there is a 0-priority task, there must be no idle + if app.idle.is_some() { + error.push(syn::Error::new( + name.span(), + format!( + "Async task {:?} has priority 0, but `#[idle]` is defined. 0-priority async tasks are only allowed if there is no `#[idle]`.", + name.to_string(), + ) + )); + } + } + } + + // Collect errors if any and return/halt + if !error.is_empty() { + let mut err = error.get(0).unwrap().clone(); + error.iter().for_each(|e| err.combine(e.clone())); + return Err(err); + } + + // e. Location of resources + let mut used_shared_resource = IndexSet::new(); + let mut ownerships = Ownerships::new(); + let mut sync_types = SyncTypes::new(); + for (prio, name, access) in app.shared_resource_accesses() { + let res = app.shared_resources.get(name).expect("UNREACHABLE"); + + // (e) + // This shared resource is used + used_shared_resource.insert(name.clone()); + + // (c) + if let Some(priority) = prio { + if let Some(ownership) = ownerships.get_mut(name) { + match *ownership { + Ownership::Owned { priority: ceiling } + | Ownership::CoOwned { priority: ceiling } + | Ownership::Contended { ceiling } + if priority != ceiling => + { + *ownership = Ownership::Contended { + ceiling: cmp::max(ceiling, priority), + }; + + if access.is_shared() { + sync_types.insert(res.ty.clone()); + } + } + + Ownership::Owned { priority: ceil } if ceil == priority => { + *ownership = Ownership::CoOwned { priority }; + } + + _ => {} + } + } else { + ownerships.insert(name.clone(), Ownership::Owned { priority }); + } + } + } + + // Create the list of used local resource Idents + let mut used_local_resource = IndexSet::new(); + + for (_, _, locals, _) in task_resources_list { + for (local, _) in locals { + used_local_resource.insert(local.clone()); + } + } + + // Most shared resources need to be `Send`, only 0 prio does not need it + let mut send_types = SendTypes::new(); + + for (name, res) in app.shared_resources.iter() { + if ownerships + .get(name) + .map(|ownership| match *ownership { + Ownership::Owned { priority: ceiling } + | Ownership::CoOwned { priority: ceiling } + | Ownership::Contended { ceiling } => ceiling != 0, + }) + .unwrap_or(false) + { + send_types.insert(res.ty.clone()); + } + } + + // Most local resources need to be `Send` as well, only 0 prio does not need it + for (name, res) in app.local_resources.iter() { + if ownerships + .get(name) + .map(|ownership| match *ownership { + Ownership::Owned { priority: ceiling } + | Ownership::CoOwned { priority: ceiling } + | Ownership::Contended { ceiling } => ceiling != 0, + }) + .unwrap_or(false) + { + send_types.insert(res.ty.clone()); + } + } + + let mut channels = Channels::new(); + + for (name, spawnee) in &app.software_tasks { + let spawnee_prio = spawnee.args.priority; + + let channel = channels.entry(spawnee_prio).or_default(); + channel.tasks.insert(name.clone()); + + // All inputs are send as we do not know from where they may be spawned. + spawnee.inputs.iter().for_each(|input| { + send_types.insert(input.ty.clone()); + }); + } + + // No channel should ever be empty + debug_assert!(channels.values().all(|channel| !channel.tasks.is_empty())); + + Ok(Analysis { + channels, + shared_resources: used_shared_resource, + local_resources: used_local_resource, + ownerships, + send_types, + sync_types, + }) +} + +// /// Priority ceiling +// pub type Ceiling = Option<u8>; + +/// Task priority +pub type Priority = u8; + +/// Resource name +pub type Resource = Ident; + +/// Task name +pub type Task = Ident; + +/// The result of analyzing an RTIC application +pub struct Analysis { + /// SPSC message channels + pub channels: Channels, + + /// Shared resources + /// + /// If a resource is not listed here it means that's a "dead" (never + /// accessed) resource and the backend should not generate code for it + pub shared_resources: UsedSharedResource, + + /// Local resources + /// + /// If a resource is not listed here it means that's a "dead" (never + /// accessed) resource and the backend should not generate code for it + pub local_resources: UsedLocalResource, + + /// Resource ownership + pub ownerships: Ownerships, + + /// These types must implement the `Send` trait + pub send_types: SendTypes, + + /// These types must implement the `Sync` trait + pub sync_types: SyncTypes, +} + +/// All channels, keyed by dispatch priority +pub type Channels = BTreeMap<Priority, Channel>; + +/// Location of all *used* shared resources +pub type UsedSharedResource = IndexSet<Resource>; + +/// Location of all *used* local resources +pub type UsedLocalResource = IndexSet<Resource>; + +/// Resource ownership +pub type Ownerships = IndexMap<Resource, Ownership>; + +/// These types must implement the `Send` trait +pub type SendTypes = Set<Box<Type>>; + +/// These types must implement the `Sync` trait +pub type SyncTypes = Set<Box<Type>>; + +/// A channel used to send messages +#[derive(Debug, Default)] +pub struct Channel { + /// Tasks that can be spawned on this channel + pub tasks: BTreeSet<Task>, +} + +/// Resource ownership +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum Ownership { + /// Owned by a single task + Owned { + /// Priority of the task that owns this resource + priority: u8, + }, + + /// "Co-owned" by more than one task; all of them have the same priority + CoOwned { + /// Priority of the tasks that co-own this resource + priority: u8, + }, + + /// Contended by more than one task; the tasks have different priorities + Contended { + /// Priority ceiling + ceiling: u8, + }, +} + +// impl Ownership { +// /// Whether this resource needs to a lock at this priority level +// pub fn needs_lock(&self, priority: u8) -> bool { +// match self { +// Ownership::Owned { .. } | Ownership::CoOwned { .. } => false, +// +// Ownership::Contended { ceiling } => { +// debug_assert!(*ceiling >= priority); +// +// priority < *ceiling +// } +// } +// } +// +// /// Whether this resource is exclusively owned +// pub fn is_owned(&self) -> bool { +// matches!(self, Ownership::Owned { .. }) +// } +// } diff --git a/rtic-macros/src/syntax/ast.rs b/rtic-macros/src/syntax/ast.rs new file mode 100644 index 0000000..27e6773 --- /dev/null +++ b/rtic-macros/src/syntax/ast.rs @@ -0,0 +1,335 @@ +//! Abstract Syntax Tree + +use syn::{Attribute, Expr, Ident, Item, ItemUse, Pat, PatType, Path, Stmt, Type}; + +use crate::syntax::Map; + +/// The `#[app]` attribute +#[derive(Debug)] +#[non_exhaustive] +pub struct App { + /// The arguments to the `#[app]` attribute + pub args: AppArgs, + + /// The name of the `const` item on which the `#[app]` attribute has been placed + pub name: Ident, + + /// The `#[init]` function + pub init: Init, + + /// The `#[idle]` function + pub idle: Option<Idle>, + + /// Resources shared between tasks defined in `#[shared]` + pub shared_resources: Map<SharedResource>, + + /// Task local resources defined in `#[local]` + pub local_resources: Map<LocalResource>, + + /// User imports + pub user_imports: Vec<ItemUse>, + + /// User code + pub user_code: Vec<Item>, + + /// Hardware tasks: `#[task(binds = ..)]`s + pub hardware_tasks: Map<HardwareTask>, + + /// Async software tasks: `#[task]` + pub software_tasks: Map<SoftwareTask>, +} + +/// Interrupts used to dispatch software tasks +pub type Dispatchers = Map<Dispatcher>; + +/// Interrupt that could be used to dispatch software tasks +#[derive(Debug, Clone)] +#[non_exhaustive] +pub struct Dispatcher { + /// Attributes that will apply to this interrupt handler + pub attrs: Vec<Attribute>, +} + +/// The arguments of the `#[app]` attribute +#[derive(Debug)] +pub struct AppArgs { + /// Device + pub device: Path, + + /// Peripherals + pub peripherals: bool, + + /// Interrupts used to dispatch software tasks + pub dispatchers: Dispatchers, +} + +/// The `init`-ialization function +#[derive(Debug)] +#[non_exhaustive] +pub struct Init { + /// `init` context metadata + pub args: InitArgs, + + /// Attributes that will apply to this `init` function + pub attrs: Vec<Attribute>, + + /// The name of the `#[init]` function + pub name: Ident, + + /// The context argument + pub context: Box<Pat>, + + /// The statements that make up this `init` function + pub stmts: Vec<Stmt>, + + /// The name of the user provided shared resources struct + pub user_shared_struct: Ident, + + /// The name of the user provided local resources struct + pub user_local_struct: Ident, +} + +/// `init` context metadata +#[derive(Debug)] +#[non_exhaustive] +pub struct InitArgs { + /// Local resources that can be accessed from this context + pub local_resources: LocalResources, +} + +impl Default for InitArgs { + fn default() -> Self { + Self { + local_resources: LocalResources::new(), + } + } +} + +/// The `idle` context +#[derive(Debug)] +#[non_exhaustive] +pub struct Idle { + /// `idle` context metadata + pub args: IdleArgs, + + /// Attributes that will apply to this `idle` function + pub attrs: Vec<Attribute>, + + /// The name of the `#[idle]` function + pub name: Ident, + + /// The context argument + pub context: Box<Pat>, + + /// The statements that make up this `idle` function + pub stmts: Vec<Stmt>, +} + +/// `idle` context metadata +#[derive(Debug)] +#[non_exhaustive] +pub struct IdleArgs { + /// Local resources that can be accessed from this context + pub local_resources: LocalResources, + + /// Shared resources that can be accessed from this context + pub shared_resources: SharedResources, +} + +impl Default for IdleArgs { + fn default() -> Self { + Self { + local_resources: LocalResources::new(), + shared_resources: SharedResources::new(), + } + } +} + +/// Shared resource properties +#[derive(Debug)] +pub struct SharedResourceProperties { + /// A lock free (exclusive resource) + pub lock_free: bool, +} + +/// A shared resource, defined in `#[shared]` +#[derive(Debug)] +#[non_exhaustive] +pub struct SharedResource { + /// `#[cfg]` attributes like `#[cfg(debug_assertions)]` + pub cfgs: Vec<Attribute>, + + /// `#[doc]` attributes like `/// this is a docstring` + pub docs: Vec<Attribute>, + + /// Attributes that will apply to this resource + pub attrs: Vec<Attribute>, + + /// The type of this resource + pub ty: Box<Type>, + + /// Shared resource properties + pub properties: SharedResourceProperties, +} + +/// A local resource, defined in `#[local]` +#[derive(Debug)] +#[non_exhaustive] +pub struct LocalResource { + /// `#[cfg]` attributes like `#[cfg(debug_assertions)]` + pub cfgs: Vec<Attribute>, + + /// `#[doc]` attributes like `/// this is a docstring` + pub docs: Vec<Attribute>, + + /// Attributes that will apply to this resource + pub attrs: Vec<Attribute>, + + /// The type of this resource + pub ty: Box<Type>, +} + +/// An async software task +#[derive(Debug)] +#[non_exhaustive] +pub struct SoftwareTask { + /// Software task metadata + pub args: SoftwareTaskArgs, + + /// `#[cfg]` attributes like `#[cfg(debug_assertions)]` + pub cfgs: Vec<Attribute>, + + /// Attributes that will apply to this interrupt handler + pub attrs: Vec<Attribute>, + + /// The context argument + pub context: Box<Pat>, + + /// The inputs of this software task + pub inputs: Vec<PatType>, + + /// The statements that make up the task handler + pub stmts: Vec<Stmt>, + + /// The task is declared externally + pub is_extern: bool, +} + +/// Software task metadata +#[derive(Debug)] +#[non_exhaustive] +pub struct SoftwareTaskArgs { + /// The priority of this task + pub priority: u8, + + /// Local resources that can be accessed from this context + pub local_resources: LocalResources, + + /// Shared resources that can be accessed from this context + pub shared_resources: SharedResources, +} + +impl Default for SoftwareTaskArgs { + fn default() -> Self { + Self { + priority: 1, + local_resources: LocalResources::new(), + shared_resources: SharedResources::new(), + } + } +} + +/// A hardware task +#[derive(Debug)] +#[non_exhaustive] +pub struct HardwareTask { + /// Hardware task metadata + pub args: HardwareTaskArgs, + + /// `#[cfg]` attributes like `#[cfg(debug_assertions)]` + pub cfgs: Vec<Attribute>, + + /// Attributes that will apply to this interrupt handler + pub attrs: Vec<Attribute>, + + /// The context argument + pub context: Box<Pat>, + + /// The statements that make up the task handler + pub stmts: Vec<Stmt>, + + /// The task is declared externally + pub is_extern: bool, +} + +/// Hardware task metadata +#[derive(Debug)] +#[non_exhaustive] +pub struct HardwareTaskArgs { + /// The interrupt or exception that this task is bound to + pub binds: Ident, + + /// The priority of this task + pub priority: u8, + + /// Local resources that can be accessed from this context + pub local_resources: LocalResources, + + /// Shared resources that can be accessed from this context + pub shared_resources: SharedResources, +} + +/// A `static mut` variable local to and owned by a context +#[derive(Debug)] +#[non_exhaustive] +pub struct Local { + /// Attributes like `#[link_section]` + pub attrs: Vec<Attribute>, + + /// `#[cfg]` attributes like `#[cfg(debug_assertions)]` + pub cfgs: Vec<Attribute>, + + /// Type + pub ty: Box<Type>, + + /// Initial value + pub expr: Box<Expr>, +} + +/// A wrapper of the 2 kinds of locals that tasks can have +#[derive(Debug)] +#[non_exhaustive] +pub enum TaskLocal { + /// The local is declared externally (i.e. `#[local]` struct) + External, + /// The local is declared in the task + Declared(Local), +} + +/// Resource access +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum Access { + /// `[x]`, a mutable resource + Exclusive, + + /// `[&x]`, a static non-mutable resource + Shared, +} + +impl Access { + /// Is this enum in the `Exclusive` variant? + pub fn is_exclusive(&self) -> bool { + *self == Access::Exclusive + } + + /// Is this enum in the `Shared` variant? + pub fn is_shared(&self) -> bool { + *self == Access::Shared + } +} + +/// Shared resource access list in task attribute +pub type SharedResources = Map<Access>; + +/// Local resource access/declaration list in task attribute +pub type LocalResources = Map<TaskLocal>; diff --git a/rtic-macros/src/syntax/check.rs b/rtic-macros/src/syntax/check.rs new file mode 100644 index 0000000..989d418 --- /dev/null +++ b/rtic-macros/src/syntax/check.rs @@ -0,0 +1,66 @@ +use std::collections::HashSet; + +use syn::parse; + +use crate::syntax::ast::App; + +pub fn app(app: &App) -> parse::Result<()> { + // Check that all referenced resources have been declared + // Check that resources are NOT `Exclusive`-ly shared + let mut owners = HashSet::new(); + for (_, name, access) in app.shared_resource_accesses() { + if app.shared_resources.get(name).is_none() { + return Err(parse::Error::new( + name.span(), + "this shared resource has NOT been declared", + )); + } + + if access.is_exclusive() { + owners.insert(name); + } + } + + for name in app.local_resource_accesses() { + if app.local_resources.get(name).is_none() { + return Err(parse::Error::new( + name.span(), + "this local resource has NOT been declared", + )); + } + } + + // Check that no resource has both types of access (`Exclusive` & `Shared`) + let exclusive_accesses = app + .shared_resource_accesses() + .filter_map(|(priority, name, access)| { + if priority.is_some() && access.is_exclusive() { + Some(name) + } else { + None + } + }) + .collect::<HashSet<_>>(); + for (_, name, access) in app.shared_resource_accesses() { + if access.is_shared() && exclusive_accesses.contains(name) { + return Err(parse::Error::new( + name.span(), + "this implementation doesn't support shared (`&-`) - exclusive (`&mut-`) locks; use `x` instead of `&x`", + )); + } + } + + // check that dispatchers are not used as hardware tasks + for task in app.hardware_tasks.values() { + let binds = &task.args.binds; + + if app.args.dispatchers.contains_key(binds) { + return Err(parse::Error::new( + binds.span(), + "dispatcher interrupts can't be used as hardware tasks", + )); + } + } + + Ok(()) +} diff --git a/rtic-macros/src/syntax/optimize.rs b/rtic-macros/src/syntax/optimize.rs new file mode 100644 index 0000000..e83ba31 --- /dev/null +++ b/rtic-macros/src/syntax/optimize.rs @@ -0,0 +1,36 @@ +use std::collections::{BTreeSet, HashMap}; + +use crate::syntax::ast::App; + +pub fn app(app: &mut App, settings: &Settings) { + // "compress" priorities + // If the user specified, for example, task priorities of "1, 3, 6", + // compress them into "1, 2, 3" as to leave no gaps + if settings.optimize_priorities { + // all task priorities ordered in ascending order + let priorities = app + .hardware_tasks + .values() + .map(|task| Some(task.args.priority)) + .chain( + app.software_tasks + .values() + .map(|task| Some(task.args.priority)), + ) + .collect::<BTreeSet<_>>(); + + let map = priorities + .iter() + .cloned() + .zip(1..) + .collect::<HashMap<_, _>>(); + + for task in app.hardware_tasks.values_mut() { + task.args.priority = map[&Some(task.args.priority)]; + } + + for task in app.software_tasks.values_mut() { + task.args.priority = map[&Some(task.args.priority)]; + } + } +} diff --git a/rtic-macros/src/syntax/parse.rs b/rtic-macros/src/syntax/parse.rs new file mode 100644 index 0000000..72eeeaf --- /dev/null +++ b/rtic-macros/src/syntax/parse.rs @@ -0,0 +1,319 @@ +mod app; +mod hardware_task; +mod idle; +mod init; +mod resource; +mod software_task; +mod util; + +use proc_macro2::TokenStream as TokenStream2; +use syn::{ + braced, parenthesized, + parse::{self, Parse, ParseStream, Parser}, + token::Brace, + Ident, Item, LitInt, Token, +}; + +use crate::syntax::{ + ast::{App, AppArgs, HardwareTaskArgs, IdleArgs, InitArgs, SoftwareTaskArgs, TaskLocal}, + Either, +}; + +// Parse the app, both app arguments and body (input) +pub fn app(args: TokenStream2, input: TokenStream2) -> parse::Result<App> { + let args = AppArgs::parse(args)?; + let input: Input = syn::parse2(input)?; + + App::parse(args, input) +} + +pub(crate) struct Input { + _mod_token: Token![mod], + pub ident: Ident, + _brace_token: Brace, + pub items: Vec<Item>, +} + +impl Parse for Input { + fn parse(input: ParseStream<'_>) -> parse::Result<Self> { + fn parse_items(input: ParseStream<'_>) -> parse::Result<Vec<Item>> { + let mut items = vec![]; + + while !input.is_empty() { + items.push(input.parse()?); + } + + Ok(items) + } + + let content; + + let _mod_token = input.parse()?; + let ident = input.parse()?; + let _brace_token = braced!(content in input); + let items = content.call(parse_items)?; + + Ok(Input { + _mod_token, + ident, + _brace_token, + items, + }) + } +} + +fn init_args(tokens: TokenStream2) -> parse::Result<InitArgs> { + (|input: ParseStream<'_>| -> parse::Result<InitArgs> { + if input.is_empty() { + return Ok(InitArgs::default()); + } + + let mut local_resources = None; + + let content; + parenthesized!(content in input); + + if !content.is_empty() { + loop { + // Parse identifier name + let ident: Ident = content.parse()?; + // Handle equal sign + let _: Token![=] = content.parse()?; + + match &*ident.to_string() { + "local" => { + if local_resources.is_some() { + return Err(parse::Error::new( + ident.span(), + "argument appears more than once", + )); + } + + local_resources = Some(util::parse_local_resources(&content)?); + } + _ => { + return Err(parse::Error::new(ident.span(), "unexpected argument")); + } + } + + if content.is_empty() { + break; + } + // Handle comma: , + let _: Token![,] = content.parse()?; + } + } + + if let Some(locals) = &local_resources { + for (ident, task_local) in locals { + if let TaskLocal::External = task_local { + return Err(parse::Error::new( + ident.span(), + "only declared local resources are allowed in init", + )); + } + } + } + + Ok(InitArgs { + local_resources: local_resources.unwrap_or_default(), + }) + }) + .parse2(tokens) +} + +fn idle_args(tokens: TokenStream2) -> parse::Result<IdleArgs> { + (|input: ParseStream<'_>| -> parse::Result<IdleArgs> { + if input.is_empty() { + return Ok(IdleArgs::default()); + } + + let mut shared_resources = None; + let mut local_resources = None; + + let content; + parenthesized!(content in input); + if !content.is_empty() { + loop { + // Parse identifier name + let ident: Ident = content.parse()?; + // Handle equal sign + let _: Token![=] = content.parse()?; + + match &*ident.to_string() { + "shared" => { + if shared_resources.is_some() { + return Err(parse::Error::new( + ident.span(), + "argument appears more than once", + )); + } + + shared_resources = Some(util::parse_shared_resources(&content)?); + } + + "local" => { + if local_resources.is_some() { + return Err(parse::Error::new( + ident.span(), + "argument appears more than once", + )); + } + + local_resources = Some(util::parse_local_resources(&content)?); + } + + _ => { + return Err(parse::Error::new(ident.span(), "unexpected argument")); + } + } + if content.is_empty() { + break; + } + + // Handle comma: , + let _: Token![,] = content.parse()?; + } + } + + Ok(IdleArgs { + shared_resources: shared_resources.unwrap_or_default(), + local_resources: local_resources.unwrap_or_default(), + }) + }) + .parse2(tokens) +} + +fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, SoftwareTaskArgs>> { + (|input: ParseStream<'_>| -> parse::Result<Either<HardwareTaskArgs, SoftwareTaskArgs>> { + if input.is_empty() { + return Ok(Either::Right(SoftwareTaskArgs::default())); + } + + let mut binds = None; + let mut priority = None; + let mut shared_resources = None; + let mut local_resources = None; + let mut prio_span = None; + + let content; + parenthesized!(content in input); + loop { + if content.is_empty() { + break; + } + + // Parse identifier name + let ident: Ident = content.parse()?; + let ident_s = ident.to_string(); + + // Handle equal sign + let _: Token![=] = content.parse()?; + + match &*ident_s { + "binds" => { + if binds.is_some() { + return Err(parse::Error::new( + ident.span(), + "argument appears more than once", + )); + } + + // Parse identifier name + let ident = content.parse()?; + + binds = Some(ident); + } + + "priority" => { + if priority.is_some() { + return Err(parse::Error::new( + ident.span(), + "argument appears more than once", + )); + } + + // #lit + let lit: LitInt = content.parse()?; + + if !lit.suffix().is_empty() { + return Err(parse::Error::new( + lit.span(), + "this literal must be unsuffixed", + )); + } + + let value = lit.base10_parse::<u8>().ok(); + if value.is_none() { + return Err(parse::Error::new( + lit.span(), + "this literal must be in the range 0...255", + )); + } + + prio_span = Some(lit.span()); + priority = Some(value.unwrap()); + } + + "shared" => { + if shared_resources.is_some() { + return Err(parse::Error::new( + ident.span(), + "argument appears more than once", + )); + } + + shared_resources = Some(util::parse_shared_resources(&content)?); + } + + "local" => { + if local_resources.is_some() { + return Err(parse::Error::new( + ident.span(), + "argument appears more than once", + )); + } + + local_resources = Some(util::parse_local_resources(&content)?); + } + + _ => { + return Err(parse::Error::new(ident.span(), "unexpected argument")); + } + } + + if content.is_empty() { + break; + } + + // Handle comma: , + let _: Token![,] = content.parse()?; + } + let priority = priority.unwrap_or(1); + let shared_resources = shared_resources.unwrap_or_default(); + let local_resources = local_resources.unwrap_or_default(); + + Ok(if let Some(binds) = binds { + if priority == 0 { + return Err(parse::Error::new( + prio_span.unwrap(), + "hardware tasks are not allowed to be at priority 0", + )); + } + + Either::Left(HardwareTaskArgs { + binds, + priority, + shared_resources, + local_resources, + }) + } else { + Either::Right(SoftwareTaskArgs { + priority, + shared_resources, + local_resources, + }) + }) + }) + .parse2(tokens) +} diff --git a/rtic-macros/src/syntax/parse/app.rs b/rtic-macros/src/syntax/parse/app.rs new file mode 100644 index 0000000..e797f75 --- /dev/null +++ b/rtic-macros/src/syntax/parse/app.rs @@ -0,0 +1,480 @@ +use std::collections::HashSet; + +// use indexmap::map::Entry; +use proc_macro2::TokenStream as TokenStream2; +use syn::{ + parse::{self, ParseStream, Parser}, + spanned::Spanned, + Expr, ExprArray, Fields, ForeignItem, Ident, Item, LitBool, Path, Token, Visibility, +}; + +use super::Input; +use crate::syntax::{ + ast::{ + App, AppArgs, Dispatcher, Dispatchers, HardwareTask, Idle, IdleArgs, Init, InitArgs, + LocalResource, SharedResource, SoftwareTask, + }, + parse::{self as syntax_parse, util}, + Either, Map, Set, +}; + +impl AppArgs { + pub(crate) fn parse(tokens: TokenStream2) -> parse::Result<Self> { + (|input: ParseStream<'_>| -> parse::Result<Self> { + let mut custom = Set::new(); + let mut device = None; + let mut peripherals = true; + let mut dispatchers = Dispatchers::new(); + + loop { + if input.is_empty() { + break; + } + + // #ident = .. + let ident: Ident = input.parse()?; + let _eq_token: Token![=] = input.parse()?; + + if custom.contains(&ident) { + return Err(parse::Error::new( + ident.span(), + "argument appears more than once", + )); + } + + custom.insert(ident.clone()); + + let ks = ident.to_string(); + + match &*ks { + "device" => { + if let Ok(p) = input.parse::<Path>() { + device = Some(p); + } else { + return Err(parse::Error::new( + ident.span(), + "unexpected argument value; this should be a path", + )); + } + } + + "peripherals" => { + if let Ok(p) = input.parse::<LitBool>() { + peripherals = p.value; + } else { + return Err(parse::Error::new( + ident.span(), + "unexpected argument value; this should be a boolean", + )); + } + } + + "dispatchers" => { + if let Ok(p) = input.parse::<ExprArray>() { + for e in p.elems { + match e { + Expr::Path(ep) => { + let path = ep.path; + let ident = if path.leading_colon.is_some() + || path.segments.len() != 1 + { + return Err(parse::Error::new( + path.span(), + "interrupt must be an identifier, not a path", + )); + } else { + path.segments[0].ident.clone() + }; + let span = ident.span(); + if dispatchers.contains_key(&ident) { + return Err(parse::Error::new( + span, + "this extern interrupt is listed more than once", + )); + } else { + dispatchers + .insert(ident, Dispatcher { attrs: ep.attrs }); + } + } + _ => { + return Err(parse::Error::new( + e.span(), + "interrupt must be an identifier", + )); + } + } + } + } else { + return Err(parse::Error::new( + ident.span(), + // increasing the length of the error message will break rustfmt + "unexpected argument value; expected an array", + )); + } + } + _ => { + return Err(parse::Error::new(ident.span(), "unexpected argument")); + } + } + + if input.is_empty() { + break; + } + + // , + let _: Token![,] = input.parse()?; + } + + let device = if let Some(device) = device { + device + } else { + return Err(parse::Error::new(input.span(), "missing `device = ...`")); + }; + + Ok(AppArgs { + device, + peripherals, + dispatchers, + }) + }) + .parse2(tokens) + } +} + +impl App { + pub(crate) fn parse(args: AppArgs, input: Input) -> parse::Result<Self> { + let mut init = None; + let mut idle = None; + + let mut shared_resources_ident = None; + let mut shared_resources = Map::new(); + let mut local_resources_ident = None; + let mut local_resources = Map::new(); + let mut hardware_tasks = Map::new(); + let mut software_tasks = Map::new(); + let mut user_imports = vec![]; + let mut user_code = vec![]; + + let mut seen_idents = HashSet::<Ident>::new(); + let mut bindings = HashSet::<Ident>::new(); + + let mut check_binding = |ident: &Ident| { + if bindings.contains(ident) { + return Err(parse::Error::new( + ident.span(), + "this interrupt is already bound", + )); + } else { + bindings.insert(ident.clone()); + } + + Ok(()) + }; + + let mut check_ident = |ident: &Ident| { + if seen_idents.contains(ident) { + return Err(parse::Error::new( + ident.span(), + "this identifier has already been used", + )); + } else { + seen_idents.insert(ident.clone()); + } + + Ok(()) + }; + + for mut item in input.items { + match item { + Item::Fn(mut item) => { + let span = item.sig.ident.span(); + if let Some(pos) = item + .attrs + .iter() + .position(|attr| util::attr_eq(attr, "init")) + { + let args = InitArgs::parse(item.attrs.remove(pos).tokens)?; + + // If an init function already exists, error + if init.is_some() { + return Err(parse::Error::new( + span, + "`#[init]` function must appear at most once", + )); + } + + check_ident(&item.sig.ident)?; + + init = Some(Init::parse(args, item)?); + } else if let Some(pos) = item + .attrs + .iter() + .position(|attr| util::attr_eq(attr, "idle")) + { + let args = IdleArgs::parse(item.attrs.remove(pos).tokens)?; + + // If an idle function already exists, error + if idle.is_some() { + return Err(parse::Error::new( + span, + "`#[idle]` function must appear at most once", + )); + } + + check_ident(&item.sig.ident)?; + + idle = Some(Idle::parse(args, item)?); + } else if let Some(pos) = item + .attrs + .iter() + .position(|attr| util::attr_eq(attr, "task")) + { + if hardware_tasks.contains_key(&item.sig.ident) + || software_tasks.contains_key(&item.sig.ident) + { + return Err(parse::Error::new( + span, + "this task is defined multiple times", + )); + } + + match syntax_parse::task_args(item.attrs.remove(pos).tokens)? { + Either::Left(args) => { + check_binding(&args.binds)?; + check_ident(&item.sig.ident)?; + + hardware_tasks.insert( + item.sig.ident.clone(), + HardwareTask::parse(args, item)?, + ); + } + + Either::Right(args) => { + check_ident(&item.sig.ident)?; + + software_tasks.insert( + item.sig.ident.clone(), + SoftwareTask::parse(args, item)?, + ); + } + } + } else { + // Forward normal functions + user_code.push(Item::Fn(item.clone())); + } + } + + Item::Struct(ref mut struct_item) => { + // Match structures with the attribute #[shared], name of structure is not + // important + if let Some(_pos) = struct_item + .attrs + .iter() + .position(|attr| util::attr_eq(attr, "shared")) + { + let span = struct_item.ident.span(); + + shared_resources_ident = Some(struct_item.ident.clone()); + + if !shared_resources.is_empty() { + return Err(parse::Error::new( + span, + "`#[shared]` struct must appear at most once", + )); + } + + if struct_item.vis != Visibility::Inherited { + return Err(parse::Error::new( + struct_item.span(), + "this item must have inherited / private visibility", + )); + } + + if let Fields::Named(fields) = &mut struct_item.fields { + for field in &mut fields.named { + let ident = field.ident.as_ref().expect("UNREACHABLE"); + + if shared_resources.contains_key(ident) { + return Err(parse::Error::new( + ident.span(), + "this resource is listed more than once", + )); + } + + shared_resources.insert( + ident.clone(), + SharedResource::parse(field, ident.span())?, + ); + } + } else { + return Err(parse::Error::new( + struct_item.span(), + "this `struct` must have named fields", + )); + } + } else if let Some(_pos) = struct_item + .attrs + .iter() + .position(|attr| util::attr_eq(attr, "local")) + { + let span = struct_item.ident.span(); + + local_resources_ident = Some(struct_item.ident.clone()); + + if !local_resources.is_empty() { + return Err(parse::Error::new( + span, + "`#[local]` struct must appear at most once", + )); + } + + if struct_item.vis != Visibility::Inherited { + return Err(parse::Error::new( + struct_item.span(), + "this item must have inherited / private visibility", + )); + } + + if let Fields::Named(fields) = &mut struct_item.fields { + for field in &mut fields.named { + let ident = field.ident.as_ref().expect("UNREACHABLE"); + + if local_resources.contains_key(ident) { + return Err(parse::Error::new( + ident.span(), + "this resource is listed more than once", + )); + } + + local_resources.insert( + ident.clone(), + LocalResource::parse(field, ident.span())?, + ); + } + } else { + return Err(parse::Error::new( + struct_item.span(), + "this `struct` must have named fields", + )); + } + } else { + // Structure without the #[resources] attribute should just be passed along + user_code.push(item.clone()); + } + } + + Item::ForeignMod(mod_) => { + if !util::abi_is_rust(&mod_.abi) { + return Err(parse::Error::new( + mod_.abi.extern_token.span(), + "this `extern` block must use the \"Rust\" ABI", + )); + } + + for item in mod_.items { + if let ForeignItem::Fn(mut item) = item { + let span = item.sig.ident.span(); + if let Some(pos) = item + .attrs + .iter() + .position(|attr| util::attr_eq(attr, "task")) + { + if hardware_tasks.contains_key(&item.sig.ident) + || software_tasks.contains_key(&item.sig.ident) + { + return Err(parse::Error::new( + span, + "this task is defined multiple times", + )); + } + + if item.attrs.len() != 1 { + return Err(parse::Error::new( + span, + "`extern` task required `#[task(..)]` attribute", + )); + } + + match syntax_parse::task_args(item.attrs.remove(pos).tokens)? { + Either::Left(args) => { + check_binding(&args.binds)?; + check_ident(&item.sig.ident)?; + + hardware_tasks.insert( + item.sig.ident.clone(), + HardwareTask::parse_foreign(args, item)?, + ); + } + + Either::Right(args) => { + check_ident(&item.sig.ident)?; + + software_tasks.insert( + item.sig.ident.clone(), + SoftwareTask::parse_foreign(args, item)?, + ); + } + } + } else { + return Err(parse::Error::new( + span, + "`extern` task required `#[task(..)]` attribute", + )); + } + } else { + return Err(parse::Error::new( + item.span(), + "this item must live outside the `#[app]` module", + )); + } + } + } + Item::Use(itemuse_) => { + // Store the user provided use-statements + user_imports.push(itemuse_.clone()); + } + _ => { + // Anything else within the module should not make any difference + user_code.push(item.clone()); + } + } + } + + let shared_resources_ident = + shared_resources_ident.expect("No `#[shared]` resource struct defined"); + let local_resources_ident = + local_resources_ident.expect("No `#[local]` resource struct defined"); + let init = init.expect("No `#[init]` function defined"); + + if shared_resources_ident != init.user_shared_struct { + return Err(parse::Error::new( + init.user_shared_struct.span(), + format!( + "This name and the one defined on `#[shared]` are not the same. Should this be `{shared_resources_ident}`?" + ), + )); + } + + if local_resources_ident != init.user_local_struct { + return Err(parse::Error::new( + init.user_local_struct.span(), + format!( + "This name and the one defined on `#[local]` are not the same. Should this be `{local_resources_ident}`?" + ), + )); + } + + Ok(App { + args, + name: input.ident, + init, + idle, + shared_resources, + local_resources, + user_imports, + user_code, + hardware_tasks, + software_tasks, + }) + } +} diff --git a/rtic-macros/src/syntax/parse/hardware_task.rs b/rtic-macros/src/syntax/parse/hardware_task.rs new file mode 100644 index 0000000..7f6dfbe --- /dev/null +++ b/rtic-macros/src/syntax/parse/hardware_task.rs @@ -0,0 +1,76 @@ +use syn::{parse, ForeignItemFn, ItemFn, Stmt}; + +use crate::syntax::parse::util::FilterAttrs; +use crate::syntax::{ + ast::{HardwareTask, HardwareTaskArgs}, + parse::util, +}; + +impl HardwareTask { + pub(crate) fn parse(args: HardwareTaskArgs, item: ItemFn) -> parse::Result<Self> { + let span = item.sig.ident.span(); + let valid_signature = util::check_fn_signature(&item, false) + && item.sig.inputs.len() == 1 + && util::type_is_unit(&item.sig.output); + + let name = item.sig.ident.to_string(); + + if valid_signature { + if let Some((context, Ok(rest))) = util::parse_inputs(item.sig.inputs, &name) { + if rest.is_empty() { + let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs); + + return Ok(HardwareTask { + args, + cfgs, + attrs, + context, + stmts: item.block.stmts, + is_extern: false, + }); + } + } + } + + Err(parse::Error::new( + span, + format!("this task handler must have type signature `fn({name}::Context)`"), + )) + } +} + +impl HardwareTask { + pub(crate) fn parse_foreign( + args: HardwareTaskArgs, + item: ForeignItemFn, + ) -> parse::Result<Self> { + let span = item.sig.ident.span(); + let valid_signature = util::check_foreign_fn_signature(&item, false) + && item.sig.inputs.len() == 1 + && util::type_is_unit(&item.sig.output); + + let name = item.sig.ident.to_string(); + + if valid_signature { + if let Some((context, Ok(rest))) = util::parse_inputs(item.sig.inputs, &name) { + if rest.is_empty() { + let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs); + + return Ok(HardwareTask { + args, + cfgs, + attrs, + context, + stmts: Vec::<Stmt>::new(), + is_extern: true, + }); + } + } + } + + Err(parse::Error::new( + span, + format!("this task handler must have type signature `fn({name}::Context)`"), + )) + } +} diff --git a/rtic-macros/src/syntax/parse/idle.rs b/rtic-macros/src/syntax/parse/idle.rs new file mode 100644 index 0000000..124c136 --- /dev/null +++ b/rtic-macros/src/syntax/parse/idle.rs @@ -0,0 +1,42 @@ +use proc_macro2::TokenStream as TokenStream2; +use syn::{parse, ItemFn}; + +use crate::syntax::{ + ast::{Idle, IdleArgs}, + parse::util, +}; + +impl IdleArgs { + pub(crate) fn parse(tokens: TokenStream2) -> parse::Result<Self> { + crate::syntax::parse::idle_args(tokens) + } +} + +impl Idle { + pub(crate) fn parse(args: IdleArgs, item: ItemFn) -> parse::Result<Self> { + let valid_signature = util::check_fn_signature(&item, false) + && item.sig.inputs.len() == 1 + && util::type_is_bottom(&item.sig.output); + + let name = item.sig.ident.to_string(); + + if valid_signature { + if let Some((context, Ok(rest))) = util::parse_inputs(item.sig.inputs, &name) { + if rest.is_empty() { + return Ok(Idle { + args, + attrs: item.attrs, + context, + name: item.sig.ident, + stmts: item.block.stmts, + }); + } + } + } + + Err(parse::Error::new( + item.sig.ident.span(), + format!("this `#[idle]` function must have signature `fn({name}::Context) -> !`"), + )) + } +} diff --git a/rtic-macros/src/syntax/parse/init.rs b/rtic-macros/src/syntax/parse/init.rs new file mode 100644 index 0000000..0aea20b --- /dev/null +++ b/rtic-macros/src/syntax/parse/init.rs @@ -0,0 +1,51 @@ +use proc_macro2::TokenStream as TokenStream2; + +use syn::{parse, ItemFn}; + +use crate::syntax::{ + ast::{Init, InitArgs}, + parse::{self as syntax_parse, util}, +}; + +impl InitArgs { + pub(crate) fn parse(tokens: TokenStream2) -> parse::Result<Self> { + syntax_parse::init_args(tokens) + } +} + +impl Init { + pub(crate) fn parse(args: InitArgs, item: ItemFn) -> parse::Result<Self> { + let valid_signature = util::check_fn_signature(&item, false) && item.sig.inputs.len() == 1; + + let span = item.sig.ident.span(); + + let name = item.sig.ident.to_string(); + + if valid_signature { + if let Ok((user_shared_struct, user_local_struct)) = + util::type_is_init_return(&item.sig.output) + { + if let Some((context, Ok(rest))) = util::parse_inputs(item.sig.inputs, &name) { + if rest.is_empty() { + return Ok(Init { + args, + attrs: item.attrs, + context, + name: item.sig.ident, + stmts: item.block.stmts, + user_shared_struct, + user_local_struct, + }); + } + } + } + } + + Err(parse::Error::new( + span, + format!( + "the `#[init]` function must have signature `fn({name}::Context) -> (Shared resources struct, Local resources struct)`" + ), + )) + } +} diff --git a/rtic-macros/src/syntax/parse/resource.rs b/rtic-macros/src/syntax/parse/resource.rs new file mode 100644 index 0000000..ff10057 --- /dev/null +++ b/rtic-macros/src/syntax/parse/resource.rs @@ -0,0 +1,55 @@ +use proc_macro2::Span; +use syn::{parse, Field, Visibility}; + +use crate::syntax::parse::util::FilterAttrs; +use crate::syntax::{ + ast::{LocalResource, SharedResource, SharedResourceProperties}, + parse::util, +}; + +impl SharedResource { + pub(crate) fn parse(item: &Field, span: Span) -> parse::Result<Self> { + if item.vis != Visibility::Inherited { + return Err(parse::Error::new( + span, + "this field must have inherited / private visibility", + )); + } + + let FilterAttrs { + cfgs, + mut attrs, + docs, + } = util::filter_attributes(item.attrs.clone()); + + let lock_free = util::extract_lock_free(&mut attrs)?; + + Ok(SharedResource { + cfgs, + attrs, + docs, + ty: Box::new(item.ty.clone()), + properties: SharedResourceProperties { lock_free }, + }) + } +} + +impl LocalResource { + pub(crate) fn parse(item: &Field, span: Span) -> parse::Result<Self> { + if item.vis != Visibility::Inherited { + return Err(parse::Error::new( + span, + "this field must have inherited / private visibility", + )); + } + + let FilterAttrs { cfgs, attrs, docs } = util::filter_attributes(item.attrs.clone()); + + Ok(LocalResource { + cfgs, + attrs, + docs, + ty: Box::new(item.ty.clone()), + }) + } +} diff --git a/rtic-macros/src/syntax/parse/software_task.rs b/rtic-macros/src/syntax/parse/software_task.rs new file mode 100644 index 0000000..769aa65 --- /dev/null +++ b/rtic-macros/src/syntax/parse/software_task.rs @@ -0,0 +1,76 @@ +use syn::{parse, ForeignItemFn, ItemFn, Stmt}; + +use crate::syntax::parse::util::FilterAttrs; +use crate::syntax::{ + ast::{SoftwareTask, SoftwareTaskArgs}, + parse::util, +}; + +impl SoftwareTask { + pub(crate) fn parse(args: SoftwareTaskArgs, item: ItemFn) -> parse::Result<Self> { + let valid_signature = util::check_fn_signature(&item, true) + && util::type_is_unit(&item.sig.output) + && item.sig.asyncness.is_some(); + + let span = item.sig.ident.span(); + + let name = item.sig.ident.to_string(); + + if valid_signature { + if let Some((context, Ok(inputs))) = util::parse_inputs(item.sig.inputs, &name) { + let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs); + + return Ok(SoftwareTask { + args, + attrs, + cfgs, + context, + inputs, + stmts: item.block.stmts, + is_extern: false, + }); + } + } + + Err(parse::Error::new( + span, + format!("this task handler must have type signature `async fn({name}::Context, ..)`"), + )) + } +} + +impl SoftwareTask { + pub(crate) fn parse_foreign( + args: SoftwareTaskArgs, + item: ForeignItemFn, + ) -> parse::Result<Self> { + let valid_signature = util::check_foreign_fn_signature(&item, true) + && util::type_is_unit(&item.sig.output) + && item.sig.asyncness.is_some(); + + let span = item.sig.ident.span(); + + let name = item.sig.ident.to_string(); + + if valid_signature { + if let Some((context, Ok(inputs))) = util::parse_inputs(item.sig.inputs, &name) { + let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs); + + return Ok(SoftwareTask { + args, + attrs, + cfgs, + context, + inputs, + stmts: Vec::<Stmt>::new(), + is_extern: true, + }); + } + } + + Err(parse::Error::new( + span, + format!("this task handler must have type signature `async fn({name}::Context, ..)`"), + )) + } +} diff --git a/rtic-macros/src/syntax/parse/util.rs b/rtic-macros/src/syntax/parse/util.rs new file mode 100644 index 0000000..5a5e0c0 --- /dev/null +++ b/rtic-macros/src/syntax/parse/util.rs @@ -0,0 +1,338 @@ +use syn::{ + bracketed, + parse::{self, ParseStream}, + punctuated::Punctuated, + spanned::Spanned, + Abi, AttrStyle, Attribute, Expr, FnArg, ForeignItemFn, Ident, ItemFn, Pat, PatType, Path, + PathArguments, ReturnType, Token, Type, Visibility, +}; + +use crate::syntax::{ + ast::{Access, Local, LocalResources, SharedResources, TaskLocal}, + Map, +}; + +pub fn abi_is_rust(abi: &Abi) -> bool { + match &abi.name { + None => true, + Some(s) => s.value() == "Rust", + } +} + +pub fn attr_eq(attr: &Attribute, name: &str) -> bool { + attr.style == AttrStyle::Outer && attr.path.segments.len() == 1 && { + let segment = attr.path.segments.first().unwrap(); + segment.arguments == PathArguments::None && *segment.ident.to_string() == *name + } +} + +/// checks that a function signature +/// +/// - has no bounds (like where clauses) +/// - is not `async` +/// - is not `const` +/// - is not `unsafe` +/// - is not generic (has no type parameters) +/// - is not variadic +/// - uses the Rust ABI (and not e.g. "C") +pub fn check_fn_signature(item: &ItemFn, allow_async: bool) -> bool { + item.vis == Visibility::Inherited + && item.sig.constness.is_none() + && (item.sig.asyncness.is_none() || allow_async) + && item.sig.abi.is_none() + && item.sig.unsafety.is_none() + && item.sig.generics.params.is_empty() + && item.sig.generics.where_clause.is_none() + && item.sig.variadic.is_none() +} + +#[allow(dead_code)] +pub fn check_foreign_fn_signature(item: &ForeignItemFn, allow_async: bool) -> bool { + item.vis == Visibility::Inherited + && item.sig.constness.is_none() + && (item.sig.asyncness.is_none() || allow_async) + && item.sig.abi.is_none() + && item.sig.unsafety.is_none() + && item.sig.generics.params.is_empty() + && item.sig.generics.where_clause.is_none() + && item.sig.variadic.is_none() +} + +pub struct FilterAttrs { + pub cfgs: Vec<Attribute>, + pub docs: Vec<Attribute>, + pub attrs: Vec<Attribute>, +} + +pub fn filter_attributes(input_attrs: Vec<Attribute>) -> FilterAttrs { + let mut cfgs = vec![]; + let mut docs = vec![]; + let mut attrs = vec![]; + + for attr in input_attrs { + if attr_eq(&attr, "cfg") { + cfgs.push(attr); + } else if attr_eq(&attr, "doc") { + docs.push(attr); + } else { + attrs.push(attr); + } + } + + FilterAttrs { cfgs, docs, attrs } +} + +pub fn extract_lock_free(attrs: &mut Vec<Attribute>) -> parse::Result<bool> { + if let Some(pos) = attrs.iter().position(|attr| attr_eq(attr, "lock_free")) { + attrs.remove(pos); + Ok(true) + } else { + Ok(false) + } +} + +pub fn parse_shared_resources(content: ParseStream<'_>) -> parse::Result<SharedResources> { + let inner; + bracketed!(inner in content); + + let mut resources = Map::new(); + for e in inner.call(Punctuated::<Expr, Token![,]>::parse_terminated)? { + let err = Err(parse::Error::new( + e.span(), + "identifier appears more than once in list", + )); + let (access, path) = match e { + Expr::Path(e) => (Access::Exclusive, e.path), + + Expr::Reference(ref r) if r.mutability.is_none() => match &*r.expr { + Expr::Path(e) => (Access::Shared, e.path.clone()), + + _ => return err, + }, + + _ => return err, + }; + + let ident = extract_resource_name_ident(path)?; + + if resources.contains_key(&ident) { + return Err(parse::Error::new( + ident.span(), + "resource appears more than once in list", + )); + } + + resources.insert(ident, access); + } + + Ok(resources) +} + +fn extract_resource_name_ident(path: Path) -> parse::Result<Ident> { + if path.leading_colon.is_some() + || path.segments.len() != 1 + || path.segments[0].arguments != PathArguments::None + { + Err(parse::Error::new( + path.span(), + "resource must be an identifier, not a path", + )) + } else { + Ok(path.segments[0].ident.clone()) + } +} + +pub fn parse_local_resources(content: ParseStream<'_>) -> parse::Result<LocalResources> { + let inner; + bracketed!(inner in content); + + let mut resources = Map::new(); + + for e in inner.call(Punctuated::<Expr, Token![,]>::parse_terminated)? { + let err = Err(parse::Error::new( + e.span(), + "identifier appears more than once in list", + )); + + let (name, local) = match e { + // local = [IDENT], + Expr::Path(path) => { + if !path.attrs.is_empty() { + return Err(parse::Error::new( + path.span(), + "attributes are not supported here", + )); + } + + let ident = extract_resource_name_ident(path.path)?; + // let (cfgs, attrs) = extract_cfgs(path.attrs); + + (ident, TaskLocal::External) + } + + // local = [IDENT: TYPE = EXPR] + Expr::Assign(e) => { + let (name, ty, cfgs, attrs) = match *e.left { + Expr::Type(t) => { + // Extract name and attributes + let (name, cfgs, attrs) = match *t.expr { + Expr::Path(path) => { + let name = extract_resource_name_ident(path.path)?; + let FilterAttrs { cfgs, attrs, .. } = filter_attributes(path.attrs); + + (name, cfgs, attrs) + } + _ => return err, + }; + + let ty = t.ty; + + // Error check + match &*ty { + Type::Array(_) => {} + Type::Path(_) => {} + Type::Ptr(_) => {} + Type::Tuple(_) => {} + _ => return Err(parse::Error::new( + ty.span(), + "unsupported type, must be an array, tuple, pointer or type path", + )), + }; + + (name, ty, cfgs, attrs) + } + e => return Err(parse::Error::new(e.span(), "malformed, expected a type")), + }; + + let expr = e.right; // Expr + + ( + name, + TaskLocal::Declared(Local { + attrs, + cfgs, + ty, + expr, + }), + ) + } + + expr => { + return Err(parse::Error::new( + expr.span(), + "malformed, expected 'IDENT: TYPE = EXPR'", + )) + } + }; + + resources.insert(name, local); + } + + Ok(resources) +} + +type ParseInputResult = Option<(Box<Pat>, Result<Vec<PatType>, FnArg>)>; + +pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, name: &str) -> ParseInputResult { + let mut inputs = inputs.into_iter(); + + match inputs.next() { + Some(FnArg::Typed(first)) => { + if type_is_path(&first.ty, &[name, "Context"]) { + let rest = inputs + .map(|arg| match arg { + FnArg::Typed(arg) => Ok(arg), + _ => Err(arg), + }) + .collect::<Result<Vec<_>, _>>(); + + Some((first.pat, rest)) + } else { + None + } + } + + _ => None, + } +} + +pub fn type_is_bottom(ty: &ReturnType) -> bool { + if let ReturnType::Type(_, ty) = ty { + matches!(**ty, Type::Never(_)) + } else { + false + } +} + +fn extract_init_resource_name_ident(ty: Type) -> Result<Ident, ()> { + match ty { + Type::Path(path) => { + let path = path.path; + + if path.leading_colon.is_some() + || path.segments.len() != 1 + || path.segments[0].arguments != PathArguments::None + { + Err(()) + } else { + Ok(path.segments[0].ident.clone()) + } + } + _ => Err(()), + } +} + +/// Checks Init's return type, return the user provided types for analysis +pub fn type_is_init_return(ty: &ReturnType) -> Result<(Ident, Ident), ()> { + match ty { + ReturnType::Default => Err(()), + + ReturnType::Type(_, ty) => match &**ty { + Type::Tuple(t) => { + // return should be: + // fn -> (User's #[shared] struct, User's #[local] struct) + // + // We check the length and the last one here, analysis checks that the user + // provided structs are correct. + if t.elems.len() == 2 { + return Ok(( + extract_init_resource_name_ident(t.elems[0].clone())?, + extract_init_resource_name_ident(t.elems[1].clone())?, + )); + } + + Err(()) + } + + _ => Err(()), + }, + } +} + +pub fn type_is_path(ty: &Type, segments: &[&str]) -> bool { + match ty { + Type::Path(tpath) if tpath.qself.is_none() => { + tpath.path.segments.len() == segments.len() + && tpath + .path + .segments + .iter() + .zip(segments) + .all(|(lhs, rhs)| lhs.ident == **rhs) + } + + _ => false, + } +} + +pub fn type_is_unit(ty: &ReturnType) -> bool { + if let ReturnType::Type(_, ty) = ty { + if let Type::Tuple(ref tuple) = **ty { + tuple.elems.is_empty() + } else { + false + } + } else { + true + } +} diff --git a/tests/tests.rs b/rtic-macros/tests/ui.rs index 9fb88a1..9fb88a1 100644 --- a/tests/tests.rs +++ b/rtic-macros/tests/ui.rs diff --git a/rtic-macros/ui/extern-interrupt-used.rs b/rtic-macros/ui/extern-interrupt-used.rs new file mode 100644 index 0000000..6346a7d --- /dev/null +++ b/rtic-macros/ui/extern-interrupt-used.rs @@ -0,0 +1,16 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock, dispatchers = [EXTI0])] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} + + #[task(binds = EXTI0)] + fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/extern-interrupt-used.stderr b/rtic-macros/ui/extern-interrupt-used.stderr new file mode 100644 index 0000000..970d39b --- /dev/null +++ b/rtic-macros/ui/extern-interrupt-used.stderr @@ -0,0 +1,5 @@ +error: dispatcher interrupts can't be used as hardware tasks + --> ui/extern-interrupt-used.rs:14:20 + | +14 | #[task(binds = EXTI0)] + | ^^^^^ diff --git a/rtic-macros/ui/idle-double-local.rs b/rtic-macros/ui/idle-double-local.rs new file mode 100644 index 0000000..54e67d3 --- /dev/null +++ b/rtic-macros/ui/idle-double-local.rs @@ -0,0 +1,9 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[idle(local = [A], local = [B])] + fn idle(_: idle::Context) -> ! { + loop {} + } +} diff --git a/rtic-macros/ui/idle-double-local.stderr b/rtic-macros/ui/idle-double-local.stderr new file mode 100644 index 0000000..b558136 --- /dev/null +++ b/rtic-macros/ui/idle-double-local.stderr @@ -0,0 +1,5 @@ +error: argument appears more than once + --> ui/idle-double-local.rs:5:25 + | +5 | #[idle(local = [A], local = [B])] + | ^^^^^ diff --git a/rtic-macros/ui/idle-double-shared.rs b/rtic-macros/ui/idle-double-shared.rs new file mode 100644 index 0000000..f66cb93 --- /dev/null +++ b/rtic-macros/ui/idle-double-shared.rs @@ -0,0 +1,9 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[idle(shared = [A], shared = [B])] + fn idle(_: idle::Context) -> ! { + loop {} + } +} diff --git a/rtic-macros/ui/idle-double-shared.stderr b/rtic-macros/ui/idle-double-shared.stderr new file mode 100644 index 0000000..6f62ad2 --- /dev/null +++ b/rtic-macros/ui/idle-double-shared.stderr @@ -0,0 +1,5 @@ +error: argument appears more than once + --> ui/idle-double-shared.rs:5:26 + | +5 | #[idle(shared = [A], shared = [B])] + | ^^^^^^ diff --git a/rtic-macros/ui/idle-input.rs b/rtic-macros/ui/idle-input.rs new file mode 100644 index 0000000..c896b1c --- /dev/null +++ b/rtic-macros/ui/idle-input.rs @@ -0,0 +1,9 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[idle] + fn idle(_: idle::Context, _undef: u32) -> ! { + loop {} + } +} diff --git a/rtic-macros/ui/idle-input.stderr b/rtic-macros/ui/idle-input.stderr new file mode 100644 index 0000000..34c38fc --- /dev/null +++ b/rtic-macros/ui/idle-input.stderr @@ -0,0 +1,5 @@ +error: this `#[idle]` function must have signature `fn(idle::Context) -> !` + --> ui/idle-input.rs:6:8 + | +6 | fn idle(_: idle::Context, _undef: u32) -> ! { + | ^^^^ diff --git a/rtic-macros/ui/idle-no-context.rs b/rtic-macros/ui/idle-no-context.rs new file mode 100644 index 0000000..bab4680 --- /dev/null +++ b/rtic-macros/ui/idle-no-context.rs @@ -0,0 +1,9 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[idle] + fn idle() -> ! { + loop {} + } +} diff --git a/rtic-macros/ui/idle-no-context.stderr b/rtic-macros/ui/idle-no-context.stderr new file mode 100644 index 0000000..c9f4b3d --- /dev/null +++ b/rtic-macros/ui/idle-no-context.stderr @@ -0,0 +1,5 @@ +error: this `#[idle]` function must have signature `fn(idle::Context) -> !` + --> ui/idle-no-context.rs:6:8 + | +6 | fn idle() -> ! { + | ^^^^ diff --git a/rtic-macros/ui/idle-not-divergent.rs b/rtic-macros/ui/idle-not-divergent.rs new file mode 100644 index 0000000..d1ae8b1 --- /dev/null +++ b/rtic-macros/ui/idle-not-divergent.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[idle] + fn idle(_: idle::Context) {} +} diff --git a/rtic-macros/ui/idle-not-divergent.stderr b/rtic-macros/ui/idle-not-divergent.stderr new file mode 100644 index 0000000..e318f58 --- /dev/null +++ b/rtic-macros/ui/idle-not-divergent.stderr @@ -0,0 +1,5 @@ +error: this `#[idle]` function must have signature `fn(idle::Context) -> !` + --> ui/idle-not-divergent.rs:6:8 + | +6 | fn idle(_: idle::Context) {} + | ^^^^ diff --git a/rtic-macros/ui/idle-output.rs b/rtic-macros/ui/idle-output.rs new file mode 100644 index 0000000..1662157 --- /dev/null +++ b/rtic-macros/ui/idle-output.rs @@ -0,0 +1,9 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[idle] + fn idle(_: idle::Context) -> u32 { + 0 + } +} diff --git a/rtic-macros/ui/idle-output.stderr b/rtic-macros/ui/idle-output.stderr new file mode 100644 index 0000000..7070e25 --- /dev/null +++ b/rtic-macros/ui/idle-output.stderr @@ -0,0 +1,5 @@ +error: this `#[idle]` function must have signature `fn(idle::Context) -> !` + --> ui/idle-output.rs:6:8 + | +6 | fn idle(_: idle::Context) -> u32 { + | ^^^^ diff --git a/rtic-macros/ui/idle-pub.rs b/rtic-macros/ui/idle-pub.rs new file mode 100644 index 0000000..0d8dd01 --- /dev/null +++ b/rtic-macros/ui/idle-pub.rs @@ -0,0 +1,9 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[idle] + pub fn idle(_: idle::Context) -> ! { + loop {} + } +} diff --git a/rtic-macros/ui/idle-pub.stderr b/rtic-macros/ui/idle-pub.stderr new file mode 100644 index 0000000..aa46ac3 --- /dev/null +++ b/rtic-macros/ui/idle-pub.stderr @@ -0,0 +1,5 @@ +error: this `#[idle]` function must have signature `fn(idle::Context) -> !` + --> ui/idle-pub.rs:6:12 + | +6 | pub fn idle(_: idle::Context) -> ! { + | ^^^^ diff --git a/rtic-macros/ui/idle-unsafe.rs b/rtic-macros/ui/idle-unsafe.rs new file mode 100644 index 0000000..3422ef2 --- /dev/null +++ b/rtic-macros/ui/idle-unsafe.rs @@ -0,0 +1,9 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[idle] + unsafe fn idle(_: idle::Context) -> ! { + loop {} + } +} diff --git a/rtic-macros/ui/idle-unsafe.stderr b/rtic-macros/ui/idle-unsafe.stderr new file mode 100644 index 0000000..a416800 --- /dev/null +++ b/rtic-macros/ui/idle-unsafe.stderr @@ -0,0 +1,5 @@ +error: this `#[idle]` function must have signature `fn(idle::Context) -> !` + --> ui/idle-unsafe.rs:6:15 + | +6 | unsafe fn idle(_: idle::Context) -> ! { + | ^^^^ diff --git a/rtic-macros/ui/init-divergent.rs b/rtic-macros/ui/init-divergent.rs new file mode 100644 index 0000000..5e4e96a --- /dev/null +++ b/rtic-macros/ui/init-divergent.rs @@ -0,0 +1,13 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> ! {} +} diff --git a/rtic-macros/ui/init-divergent.stderr b/rtic-macros/ui/init-divergent.stderr new file mode 100644 index 0000000..9f6acf6 --- /dev/null +++ b/rtic-macros/ui/init-divergent.stderr @@ -0,0 +1,5 @@ +error: the `#[init]` function must have signature `fn(init::Context) -> (Shared resources struct, Local resources struct)` + --> ui/init-divergent.rs:12:8 + | +12 | fn init(_: init::Context) -> ! {} + | ^^^^ diff --git a/rtic-macros/ui/init-double-local.rs b/rtic-macros/ui/init-double-local.rs new file mode 100644 index 0000000..5f6d7ac --- /dev/null +++ b/rtic-macros/ui/init-double-local.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[init(local = [A], local = [B])] + fn init(_: init::Context) {} +} diff --git a/rtic-macros/ui/init-double-local.stderr b/rtic-macros/ui/init-double-local.stderr new file mode 100644 index 0000000..07c3b50 --- /dev/null +++ b/rtic-macros/ui/init-double-local.stderr @@ -0,0 +1,5 @@ +error: argument appears more than once + --> ui/init-double-local.rs:5:25 + | +5 | #[init(local = [A], local = [B])] + | ^^^^^ diff --git a/rtic-macros/ui/init-double-shared.rs b/rtic-macros/ui/init-double-shared.rs new file mode 100644 index 0000000..4503c87 --- /dev/null +++ b/rtic-macros/ui/init-double-shared.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[init(shared = [A], shared = [B])] + fn init(_: init::Context) {} +} diff --git a/rtic-macros/ui/init-double-shared.stderr b/rtic-macros/ui/init-double-shared.stderr new file mode 100644 index 0000000..af2a97b --- /dev/null +++ b/rtic-macros/ui/init-double-shared.stderr @@ -0,0 +1,5 @@ +error: unexpected argument + --> ui/init-double-shared.rs:5:12 + | +5 | #[init(shared = [A], shared = [B])] + | ^^^^^^ diff --git a/rtic-macros/ui/init-input.rs b/rtic-macros/ui/init-input.rs new file mode 100644 index 0000000..d41a503 --- /dev/null +++ b/rtic-macros/ui/init-input.rs @@ -0,0 +1,13 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context, _undef: u32) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/init-input.stderr b/rtic-macros/ui/init-input.stderr new file mode 100644 index 0000000..e236043 --- /dev/null +++ b/rtic-macros/ui/init-input.stderr @@ -0,0 +1,5 @@ +error: the `#[init]` function must have signature `fn(init::Context) -> (Shared resources struct, Local resources struct)` + --> ui/init-input.rs:12:8 + | +12 | fn init(_: init::Context, _undef: u32) -> (Shared, Local) {} + | ^^^^ diff --git a/rtic-macros/ui/init-no-context.rs b/rtic-macros/ui/init-no-context.rs new file mode 100644 index 0000000..cdce4c5 --- /dev/null +++ b/rtic-macros/ui/init-no-context.rs @@ -0,0 +1,13 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init() -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/init-no-context.stderr b/rtic-macros/ui/init-no-context.stderr new file mode 100644 index 0000000..28e1fd4 --- /dev/null +++ b/rtic-macros/ui/init-no-context.stderr @@ -0,0 +1,5 @@ +error: the `#[init]` function must have signature `fn(init::Context) -> (Shared resources struct, Local resources struct)` + --> ui/init-no-context.rs:12:8 + | +12 | fn init() -> (Shared, Local) {} + | ^^^^ diff --git a/rtic-macros/ui/init-output.rs b/rtic-macros/ui/init-output.rs new file mode 100644 index 0000000..7057c95 --- /dev/null +++ b/rtic-macros/ui/init-output.rs @@ -0,0 +1,9 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[init] + fn init(_: init::Context) -> u32 { + 0 + } +} diff --git a/rtic-macros/ui/init-output.stderr b/rtic-macros/ui/init-output.stderr new file mode 100644 index 0000000..8bc3c83 --- /dev/null +++ b/rtic-macros/ui/init-output.stderr @@ -0,0 +1,5 @@ +error: the `#[init]` function must have signature `fn(init::Context) -> (Shared resources struct, Local resources struct)` + --> ui/init-output.rs:6:8 + | +6 | fn init(_: init::Context) -> u32 { + | ^^^^ diff --git a/rtic-macros/ui/init-pub.rs b/rtic-macros/ui/init-pub.rs new file mode 100644 index 0000000..dd59aa1 --- /dev/null +++ b/rtic-macros/ui/init-pub.rs @@ -0,0 +1,13 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + pub fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/init-pub.stderr b/rtic-macros/ui/init-pub.stderr new file mode 100644 index 0000000..b1610ed --- /dev/null +++ b/rtic-macros/ui/init-pub.stderr @@ -0,0 +1,5 @@ +error: the `#[init]` function must have signature `fn(init::Context) -> (Shared resources struct, Local resources struct)` + --> ui/init-pub.rs:12:12 + | +12 | pub fn init(_: init::Context) -> (Shared, Local) {} + | ^^^^ diff --git a/rtic-macros/ui/init-unsafe.rs b/rtic-macros/ui/init-unsafe.rs new file mode 100644 index 0000000..4f89baf --- /dev/null +++ b/rtic-macros/ui/init-unsafe.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[init] + unsafe fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/init-unsafe.stderr b/rtic-macros/ui/init-unsafe.stderr new file mode 100644 index 0000000..fd0b8f3 --- /dev/null +++ b/rtic-macros/ui/init-unsafe.stderr @@ -0,0 +1,5 @@ +error: the `#[init]` function must have signature `fn(init::Context) -> (Shared resources struct, Local resources struct)` + --> ui/init-unsafe.rs:6:15 + | +6 | unsafe fn init(_: init::Context) -> (Shared, Local) {} + | ^^^^ diff --git a/rtic-macros/ui/interrupt-double.rs b/rtic-macros/ui/interrupt-double.rs new file mode 100644 index 0000000..e2addc7 --- /dev/null +++ b/rtic-macros/ui/interrupt-double.rs @@ -0,0 +1,10 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task(binds = UART0)] + fn foo(_: foo::Context) {} + + #[task(binds = UART0)] + fn bar(_: bar::Context) {} +} diff --git a/rtic-macros/ui/interrupt-double.stderr b/rtic-macros/ui/interrupt-double.stderr new file mode 100644 index 0000000..8db34e2 --- /dev/null +++ b/rtic-macros/ui/interrupt-double.stderr @@ -0,0 +1,5 @@ +error: this interrupt is already bound + --> ui/interrupt-double.rs:8:20 + | +8 | #[task(binds = UART0)] + | ^^^^^ diff --git a/rtic-macros/ui/local-collision-2.rs b/rtic-macros/ui/local-collision-2.rs new file mode 100644 index 0000000..08bc8e5 --- /dev/null +++ b/rtic-macros/ui/local-collision-2.rs @@ -0,0 +1,18 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local { + a: u32, + } + + #[task(local = [a: u8 = 3])] + async fn bar(_: bar::Context) {} + + #[init(local = [a: u16 = 2])] + fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/local-collision-2.stderr b/rtic-macros/ui/local-collision-2.stderr new file mode 100644 index 0000000..47dbbe3 --- /dev/null +++ b/rtic-macros/ui/local-collision-2.stderr @@ -0,0 +1,17 @@ +error: Local resource "a" is used by multiple tasks or collides with multiple definitions + --> ui/local-collision-2.rs:10:9 + | +10 | a: u32, + | ^ + +error: Local resource "a" is used by multiple tasks or collides with multiple definitions + --> ui/local-collision-2.rs:16:21 + | +16 | #[init(local = [a: u16 = 2])] + | ^ + +error: Local resource "a" is used by multiple tasks or collides with multiple definitions + --> ui/local-collision-2.rs:13:21 + | +13 | #[task(local = [a: u8 = 3])] + | ^ diff --git a/rtic-macros/ui/local-collision.rs b/rtic-macros/ui/local-collision.rs new file mode 100644 index 0000000..0e4eef7 --- /dev/null +++ b/rtic-macros/ui/local-collision.rs @@ -0,0 +1,21 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local { + a: u32, + } + + #[task(local = [a])] + async fn foo(_: foo::Context) {} + + #[task(local = [a: u8 = 3])] + async fn bar(_: bar::Context) {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/local-collision.stderr b/rtic-macros/ui/local-collision.stderr new file mode 100644 index 0000000..47fbb6e --- /dev/null +++ b/rtic-macros/ui/local-collision.stderr @@ -0,0 +1,11 @@ +error: Local resource "a" is used by multiple tasks or collides with multiple definitions + --> ui/local-collision.rs:10:9 + | +10 | a: u32, + | ^ + +error: Local resource "a" is used by multiple tasks or collides with multiple definitions + --> ui/local-collision.rs:16:21 + | +16 | #[task(local = [a: u8 = 3])] + | ^ diff --git a/rtic-macros/ui/local-malformed-1.rs b/rtic-macros/ui/local-malformed-1.rs new file mode 100644 index 0000000..219eef5 --- /dev/null +++ b/rtic-macros/ui/local-malformed-1.rs @@ -0,0 +1,16 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[task(local = [a:])] + async fn foo(_: foo::Context) {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/local-malformed-1.stderr b/rtic-macros/ui/local-malformed-1.stderr new file mode 100644 index 0000000..d15c324 --- /dev/null +++ b/rtic-macros/ui/local-malformed-1.stderr @@ -0,0 +1,5 @@ +error: unexpected end of input, expected one of: `for`, parentheses, `fn`, `unsafe`, `extern`, identifier, `::`, `<`, square brackets, `*`, `&`, `!`, `impl`, `_`, lifetime + --> ui/local-malformed-1.rs:11:23 + | +11 | #[task(local = [a:])] + | ^ diff --git a/rtic-macros/ui/local-malformed-2.rs b/rtic-macros/ui/local-malformed-2.rs new file mode 100644 index 0000000..d691453 --- /dev/null +++ b/rtic-macros/ui/local-malformed-2.rs @@ -0,0 +1,16 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[task(local = [a: u32])] + async fn foo(_: foo::Context) {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/local-malformed-2.stderr b/rtic-macros/ui/local-malformed-2.stderr new file mode 100644 index 0000000..0b448f0 --- /dev/null +++ b/rtic-macros/ui/local-malformed-2.stderr @@ -0,0 +1,5 @@ +error: malformed, expected 'IDENT: TYPE = EXPR' + --> ui/local-malformed-2.rs:11:21 + | +11 | #[task(local = [a: u32])] + | ^^^^^^ diff --git a/rtic-macros/ui/local-malformed-3.rs b/rtic-macros/ui/local-malformed-3.rs new file mode 100644 index 0000000..7eddfa4 --- /dev/null +++ b/rtic-macros/ui/local-malformed-3.rs @@ -0,0 +1,16 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[task(local = [a: u32 =])] + async fn foo(_: foo::Context) {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/local-malformed-3.stderr b/rtic-macros/ui/local-malformed-3.stderr new file mode 100644 index 0000000..61af4f3 --- /dev/null +++ b/rtic-macros/ui/local-malformed-3.stderr @@ -0,0 +1,5 @@ +error: unexpected end of input, expected expression + --> ui/local-malformed-3.rs:11:29 + | +11 | #[task(local = [a: u32 =])] + | ^ diff --git a/rtic-macros/ui/local-malformed-4.rs b/rtic-macros/ui/local-malformed-4.rs new file mode 100644 index 0000000..b913947 --- /dev/null +++ b/rtic-macros/ui/local-malformed-4.rs @@ -0,0 +1,16 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[task(local = [a = u32])] + async fn foo(_: foo::Context) {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/local-malformed-4.stderr b/rtic-macros/ui/local-malformed-4.stderr new file mode 100644 index 0000000..0f7d9e7 --- /dev/null +++ b/rtic-macros/ui/local-malformed-4.stderr @@ -0,0 +1,5 @@ +error: malformed, expected a type + --> ui/local-malformed-4.rs:11:21 + | +11 | #[task(local = [a = u32])] + | ^ diff --git a/rtic-macros/ui/local-not-declared.rs b/rtic-macros/ui/local-not-declared.rs new file mode 100644 index 0000000..7c087e4 --- /dev/null +++ b/rtic-macros/ui/local-not-declared.rs @@ -0,0 +1,16 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[task(local = [A])] + async fn foo(_: foo::Context) {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/local-not-declared.stderr b/rtic-macros/ui/local-not-declared.stderr new file mode 100644 index 0000000..10d4b04 --- /dev/null +++ b/rtic-macros/ui/local-not-declared.stderr @@ -0,0 +1,5 @@ +error: this local resource has NOT been declared + --> ui/local-not-declared.rs:11:21 + | +11 | #[task(local = [A])] + | ^ diff --git a/rtic-macros/ui/local-pub.rs b/rtic-macros/ui/local-pub.rs new file mode 100644 index 0000000..42da4f4 --- /dev/null +++ b/rtic-macros/ui/local-pub.rs @@ -0,0 +1,15 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local { + pub x: u32, + } + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/local-pub.stderr b/rtic-macros/ui/local-pub.stderr new file mode 100644 index 0000000..e4814ca --- /dev/null +++ b/rtic-macros/ui/local-pub.stderr @@ -0,0 +1,5 @@ +error: this field must have inherited / private visibility + --> ui/local-pub.rs:10:13 + | +10 | pub x: u32, + | ^ diff --git a/rtic-macros/ui/local-shared-attribute.rs b/rtic-macros/ui/local-shared-attribute.rs new file mode 100644 index 0000000..c594b5f --- /dev/null +++ b/rtic-macros/ui/local-shared-attribute.rs @@ -0,0 +1,21 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} + + #[task(local = [ + #[test] + a: u32 = 0, // Ok + #[test] + b, // Error + ])] + fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/local-shared-attribute.stderr b/rtic-macros/ui/local-shared-attribute.stderr new file mode 100644 index 0000000..a8130e8 --- /dev/null +++ b/rtic-macros/ui/local-shared-attribute.stderr @@ -0,0 +1,6 @@ +error: attributes are not supported here + --> ui/local-shared-attribute.rs:17:9 + | +17 | / #[test] +18 | | b, // Error + | |_________^ diff --git a/rtic-macros/ui/local-shared.rs b/rtic-macros/ui/local-shared.rs new file mode 100644 index 0000000..4e8f9f4 --- /dev/null +++ b/rtic-macros/ui/local-shared.rs @@ -0,0 +1,28 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local { + l1: u32, + l2: u32, + } + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} + + // l2 ok + #[idle(local = [l2])] + fn idle(cx: idle::Context) -> ! {} + + // l1 rejected (not local) + #[task(priority = 1, local = [l1])] + async fn uart0(cx: uart0::Context) {} + + // l1 rejected (not lock_free) + #[task(priority = 2, local = [l1])] + async fn uart1(cx: uart1::Context) {} +} diff --git a/rtic-macros/ui/local-shared.stderr b/rtic-macros/ui/local-shared.stderr new file mode 100644 index 0000000..fceb763 --- /dev/null +++ b/rtic-macros/ui/local-shared.stderr @@ -0,0 +1,11 @@ +error: Local resource "l1" is used by multiple tasks or collides with multiple definitions + --> ui/local-shared.rs:22:35 + | +22 | #[task(priority = 1, local = [l1])] + | ^^ + +error: Local resource "l1" is used by multiple tasks or collides with multiple definitions + --> ui/local-shared.rs:26:35 + | +26 | #[task(priority = 2, local = [l1])] + | ^^ diff --git a/rtic-macros/ui/shared-lock-free.rs b/rtic-macros/ui/shared-lock-free.rs new file mode 100644 index 0000000..b3a4b9c --- /dev/null +++ b/rtic-macros/ui/shared-lock-free.rs @@ -0,0 +1,38 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared { + // An exclusive, early resource + #[lock_free] + e1: u32, + + // An exclusive, late resource + #[lock_free] + e2: u32, + } + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} + + // e2 ok + #[idle(shared = [e2])] + fn idle(cx: idle::Context) -> ! { + debug::exit(debug::EXIT_SUCCESS); + loop {} + } + + // e1 rejected (not lock_free) + #[task(binds = UART0, priority = 1, shared = [e1])] + fn uart0(cx: uart0::Context) { + *cx.resources.e1 += 10; + } + + // e1 rejected (not lock_free) + #[task(binds = UART1, priority = 2, shared = [e1])] + fn uart1(cx: uart1::Context) {} +} diff --git a/rtic-macros/ui/shared-lock-free.stderr b/rtic-macros/ui/shared-lock-free.stderr new file mode 100644 index 0000000..51e99a0 --- /dev/null +++ b/rtic-macros/ui/shared-lock-free.stderr @@ -0,0 +1,17 @@ +error: Lock free shared resource "e1" is used by tasks at different priorities + --> ui/shared-lock-free.rs:9:9 + | +9 | e1: u32, + | ^^ + +error: Shared resource "e1" is declared lock free but used by tasks at different priorities + --> ui/shared-lock-free.rs:30:51 + | +30 | #[task(binds = UART0, priority = 1, shared = [e1])] + | ^^ + +error: Shared resource "e1" is declared lock free but used by tasks at different priorities + --> ui/shared-lock-free.rs:36:51 + | +36 | #[task(binds = UART1, priority = 2, shared = [e1])] + | ^^ diff --git a/rtic-macros/ui/shared-not-declared.rs b/rtic-macros/ui/shared-not-declared.rs new file mode 100644 index 0000000..5fef534 --- /dev/null +++ b/rtic-macros/ui/shared-not-declared.rs @@ -0,0 +1,16 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[task(shared = [A])] + async fn foo(_: foo::Context) {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} +} diff --git a/rtic-macros/ui/shared-not-declared.stderr b/rtic-macros/ui/shared-not-declared.stderr new file mode 100644 index 0000000..7c5fb32 --- /dev/null +++ b/rtic-macros/ui/shared-not-declared.stderr @@ -0,0 +1,5 @@ +error: this shared resource has NOT been declared + --> ui/shared-not-declared.rs:11:22 + | +11 | #[task(shared = [A])] + | ^ diff --git a/rtic-macros/ui/shared-pub.rs b/rtic-macros/ui/shared-pub.rs new file mode 100644 index 0000000..10351fd --- /dev/null +++ b/rtic-macros/ui/shared-pub.rs @@ -0,0 +1,9 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared { + pub x: u32, + } +} diff --git a/rtic-macros/ui/shared-pub.stderr b/rtic-macros/ui/shared-pub.stderr new file mode 100644 index 0000000..7148893 --- /dev/null +++ b/rtic-macros/ui/shared-pub.stderr @@ -0,0 +1,5 @@ +error: this field must have inherited / private visibility + --> ui/shared-pub.rs:7:13 + | +7 | pub x: u32, + | ^ diff --git a/rtic-macros/ui/task-divergent.rs b/rtic-macros/ui/task-divergent.rs new file mode 100644 index 0000000..ffe2dc0 --- /dev/null +++ b/rtic-macros/ui/task-divergent.rs @@ -0,0 +1,9 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task] + async fn foo(_: foo::Context) -> ! { + loop {} + } +} diff --git a/rtic-macros/ui/task-divergent.stderr b/rtic-macros/ui/task-divergent.stderr new file mode 100644 index 0000000..dd00208 --- /dev/null +++ b/rtic-macros/ui/task-divergent.stderr @@ -0,0 +1,5 @@ +error: this task handler must have type signature `async fn(foo::Context, ..)` + --> ui/task-divergent.rs:6:14 + | +6 | async fn foo(_: foo::Context) -> ! { + | ^^^ diff --git a/rtic-macros/ui/task-double-local.rs b/rtic-macros/ui/task-double-local.rs new file mode 100644 index 0000000..c5277e2 --- /dev/null +++ b/rtic-macros/ui/task-double-local.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task(local = [A], local = [B])] + async fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/task-double-local.stderr b/rtic-macros/ui/task-double-local.stderr new file mode 100644 index 0000000..91ed844 --- /dev/null +++ b/rtic-macros/ui/task-double-local.stderr @@ -0,0 +1,5 @@ +error: argument appears more than once + --> ui/task-double-local.rs:5:25 + | +5 | #[task(local = [A], local = [B])] + | ^^^^^ diff --git a/rtic-macros/ui/task-double-priority.rs b/rtic-macros/ui/task-double-priority.rs new file mode 100644 index 0000000..5c8bd5b --- /dev/null +++ b/rtic-macros/ui/task-double-priority.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task(priority = 1, priority = 2)] + async fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/task-double-priority.stderr b/rtic-macros/ui/task-double-priority.stderr new file mode 100644 index 0000000..b3c814a --- /dev/null +++ b/rtic-macros/ui/task-double-priority.stderr @@ -0,0 +1,5 @@ +error: argument appears more than once + --> ui/task-double-priority.rs:5:26 + | +5 | #[task(priority = 1, priority = 2)] + | ^^^^^^^^ diff --git a/rtic-macros/ui/task-double-shared.rs b/rtic-macros/ui/task-double-shared.rs new file mode 100644 index 0000000..f9812d3 --- /dev/null +++ b/rtic-macros/ui/task-double-shared.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task(shared = [A], shared = [B])] + async fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/task-double-shared.stderr b/rtic-macros/ui/task-double-shared.stderr new file mode 100644 index 0000000..bb90212 --- /dev/null +++ b/rtic-macros/ui/task-double-shared.stderr @@ -0,0 +1,5 @@ +error: argument appears more than once + --> ui/task-double-shared.rs:5:26 + | +5 | #[task(shared = [A], shared = [B])] + | ^^^^^^ diff --git a/rtic-macros/ui/task-idle.rs b/rtic-macros/ui/task-idle.rs new file mode 100644 index 0000000..353c782 --- /dev/null +++ b/rtic-macros/ui/task-idle.rs @@ -0,0 +1,13 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[idle] + fn foo(_: foo::Context) -> ! { + loop {} + } + + // name collides with `#[idle]` function + #[task] + async fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/task-idle.stderr b/rtic-macros/ui/task-idle.stderr new file mode 100644 index 0000000..4ccc113 --- /dev/null +++ b/rtic-macros/ui/task-idle.stderr @@ -0,0 +1,5 @@ +error: this identifier has already been used + --> ui/task-idle.rs:12:14 + | +12 | async fn foo(_: foo::Context) {} + | ^^^ diff --git a/rtic-macros/ui/task-init.rs b/rtic-macros/ui/task-init.rs new file mode 100644 index 0000000..e58fdce --- /dev/null +++ b/rtic-macros/ui/task-init.rs @@ -0,0 +1,17 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn foo(_: foo::Context) -> (Shared, Local) {} + + // name collides with `#[idle]` function + #[task] + async fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/task-init.stderr b/rtic-macros/ui/task-init.stderr new file mode 100644 index 0000000..161e194 --- /dev/null +++ b/rtic-macros/ui/task-init.stderr @@ -0,0 +1,5 @@ +error: this identifier has already been used + --> ui/task-init.rs:16:14 + | +16 | async fn foo(_: foo::Context) {} + | ^^^ diff --git a/rtic-macros/ui/task-interrupt.rs b/rtic-macros/ui/task-interrupt.rs new file mode 100644 index 0000000..3d50bd8 --- /dev/null +++ b/rtic-macros/ui/task-interrupt.rs @@ -0,0 +1,10 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task(binds = SysTick)] + fn foo(_: foo::Context) {} + + #[task] + async fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/task-interrupt.stderr b/rtic-macros/ui/task-interrupt.stderr new file mode 100644 index 0000000..087b6c6 --- /dev/null +++ b/rtic-macros/ui/task-interrupt.stderr @@ -0,0 +1,5 @@ +error: this task is defined multiple times + --> ui/task-interrupt.rs:9:14 + | +9 | async fn foo(_: foo::Context) {} + | ^^^ diff --git a/rtic-macros/ui/task-no-context.rs b/rtic-macros/ui/task-no-context.rs new file mode 100644 index 0000000..55e8c3b --- /dev/null +++ b/rtic-macros/ui/task-no-context.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task] + async fn foo() {} +} diff --git a/rtic-macros/ui/task-no-context.stderr b/rtic-macros/ui/task-no-context.stderr new file mode 100644 index 0000000..62147aa --- /dev/null +++ b/rtic-macros/ui/task-no-context.stderr @@ -0,0 +1,5 @@ +error: this task handler must have type signature `async fn(foo::Context, ..)` + --> ui/task-no-context.rs:6:14 + | +6 | async fn foo() {} + | ^^^ diff --git a/rtic-macros/ui/task-priority-too-high.rs b/rtic-macros/ui/task-priority-too-high.rs new file mode 100644 index 0000000..f33ba56 --- /dev/null +++ b/rtic-macros/ui/task-priority-too-high.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task(priority = 256)] + async fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/task-priority-too-high.stderr b/rtic-macros/ui/task-priority-too-high.stderr new file mode 100644 index 0000000..5790c88 --- /dev/null +++ b/rtic-macros/ui/task-priority-too-high.stderr @@ -0,0 +1,5 @@ +error: this literal must be in the range 0...255 + --> ui/task-priority-too-high.rs:5:23 + | +5 | #[task(priority = 256)] + | ^^^ diff --git a/rtic-macros/ui/task-priority-too-low.rs b/rtic-macros/ui/task-priority-too-low.rs new file mode 100644 index 0000000..16e0557 --- /dev/null +++ b/rtic-macros/ui/task-priority-too-low.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task(binds = UART0, priority = 0)] + fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/task-priority-too-low.stderr b/rtic-macros/ui/task-priority-too-low.stderr new file mode 100644 index 0000000..85c8660 --- /dev/null +++ b/rtic-macros/ui/task-priority-too-low.stderr @@ -0,0 +1,5 @@ +error: hardware tasks are not allowed to be at priority 0 + --> ui/task-priority-too-low.rs:5:38 + | +5 | #[task(binds = UART0, priority = 0)] + | ^ diff --git a/rtic-macros/ui/task-pub.rs b/rtic-macros/ui/task-pub.rs new file mode 100644 index 0000000..1ae533f --- /dev/null +++ b/rtic-macros/ui/task-pub.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task] + pub async fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/task-pub.stderr b/rtic-macros/ui/task-pub.stderr new file mode 100644 index 0000000..7b9813d --- /dev/null +++ b/rtic-macros/ui/task-pub.stderr @@ -0,0 +1,5 @@ +error: this task handler must have type signature `async fn(foo::Context, ..)` + --> ui/task-pub.rs:6:18 + | +6 | pub async fn foo(_: foo::Context) {} + | ^^^ diff --git a/rtic-macros/ui/task-unsafe.rs b/rtic-macros/ui/task-unsafe.rs new file mode 100644 index 0000000..a8383ef --- /dev/null +++ b/rtic-macros/ui/task-unsafe.rs @@ -0,0 +1,7 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[task] + async unsafe fn foo(_: foo::Context) {} +} diff --git a/rtic-macros/ui/task-unsafe.stderr b/rtic-macros/ui/task-unsafe.stderr new file mode 100644 index 0000000..90ac76f --- /dev/null +++ b/rtic-macros/ui/task-unsafe.stderr @@ -0,0 +1,5 @@ +error: this task handler must have type signature `async fn(foo::Context, ..)` + --> ui/task-unsafe.rs:6:21 + | +6 | async unsafe fn foo(_: foo::Context) {} + | ^^^ diff --git a/rtic-macros/ui/task-zero-prio.rs b/rtic-macros/ui/task-zero-prio.rs new file mode 100644 index 0000000..de3c86f --- /dev/null +++ b/rtic-macros/ui/task-zero-prio.rs @@ -0,0 +1,19 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} + + #[task(priority = 0)] + fn foo(_: foo::Context) {} + + #[idle] + fn idle(_: idle::Context) -> ! {} +} diff --git a/rtic-macros/ui/task-zero-prio.stderr b/rtic-macros/ui/task-zero-prio.stderr new file mode 100644 index 0000000..1ab9aab --- /dev/null +++ b/rtic-macros/ui/task-zero-prio.stderr @@ -0,0 +1,5 @@ +error: this task handler must have type signature `async fn(foo::Context, ..)` + --> ui/task-zero-prio.rs:15:8 + | +15 | fn foo(_: foo::Context) {} + | ^^^ diff --git a/rtic-monotonics/.gitignore b/rtic-monotonics/.gitignore new file mode 100644 index 0000000..c400256 --- /dev/null +++ b/rtic-monotonics/.gitignore @@ -0,0 +1,6 @@ +**/*.rs.bk +.#* +.gdb_history +/target +Cargo.lock +*.hex diff --git a/rtic-monotonics/CHANGELOG.md b/rtic-monotonics/CHANGELOG.md new file mode 100644 index 0000000..d3a9d84 --- /dev/null +++ b/rtic-monotonics/CHANGELOG.md @@ -0,0 +1,16 @@ +# Change Log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +For each category, *Added*, *Changed*, *Fixed* add new entries at the top! + +## [Unreleased] + +### Added + +### Changed + +### Fixed + +## [v1.0.0] - 2023-xx-xx diff --git a/rtic-monotonics/Cargo.toml b/rtic-monotonics/Cargo.toml new file mode 100644 index 0000000..c961c05 --- /dev/null +++ b/rtic-monotonics/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "rtic-monotonics" +version = "1.0.0-alpha.0" + +edition = "2021" +authors = [ + "The Real-Time Interrupt-driven Concurrency developers", + "Emil Fresk <emil.fresk@gmail.com>", + "Henrik Tjäder <henrik@tjaders.com>", + "Jorge Aparicio <jorge@japaric.io>", + "Per Lindgren <per.lindgren@ltu.se>", +] +categories = ["concurrency", "embedded", "no-std", "asynchronous"] +description = "rtic-monotonics lib TODO" +license = "MIT OR Apache-2.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rtic-time = { version = "1.0.0-alpha.0", path = "../rtic-time" } +embedded-hal-async = { version = "0.2.0-alpha.0", optional = true } +fugit = { version = "0.3.6" } +atomic-polyfill = "1" +cfg-if = "1.0.0" +cortex-m = { version = "0.7.6", optional = true } +rp2040-pac = { version = ">=0.2.0,<0.5", optional = true } + +[features] +default = [] +defmt = ["fugit/defmt"] + +# Systick on Cortex-M, default 1 kHz +cortex-m-systick = ["dep:cortex-m"] +systick-100hz = [] +systick-10khz = [] + +# Timer peripheral on the RP2040 +rp2040 = ["dep:rp2040-pac"] diff --git a/rtic-monotonics/rust-toolchain.toml b/rtic-monotonics/rust-toolchain.toml new file mode 100644 index 0000000..e28b55d --- /dev/null +++ b/rtic-monotonics/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly" +components = [ "rust-src", "rustfmt", "llvm-tools-preview" ] +targets = [ "thumbv6m-none-eabi", "thumbv7m-none-eabi" ] diff --git a/rtic-monotonics/src/lib.rs b/rtic-monotonics/src/lib.rs new file mode 100644 index 0000000..a4a1f42 --- /dev/null +++ b/rtic-monotonics/src/lib.rs @@ -0,0 +1,15 @@ +//! Crate + +#![no_std] +#![deny(missing_docs)] +//deny_warnings_placeholder_for_ci +#![allow(incomplete_features)] +#![feature(async_fn_in_trait)] + +pub use rtic_time::{Monotonic, TimeoutError, TimerQueue}; + +#[cfg(feature = "cortex-m-systick")] +pub mod systick; + +#[cfg(feature = "rp2040")] +pub mod rp2040; diff --git a/rtic-monotonics/src/rp2040.rs b/rtic-monotonics/src/rp2040.rs new file mode 100644 index 0000000..e42c148 --- /dev/null +++ b/rtic-monotonics/src/rp2040.rs @@ -0,0 +1,143 @@ +//! A monotonic implementation for RP2040's Timer peripheral. + +use super::Monotonic; +pub use super::{TimeoutError, TimerQueue}; +use core::future::Future; +pub use fugit::ExtU64; +use rp2040_pac::{timer, Interrupt, RESETS, TIMER}; + +/// Timer implementing `rtic_monotonic::Monotonic` which runs at 1 MHz. +pub struct Timer; + +impl Timer { + /// Start a `Monotonic` based on RP2040's Timer. + pub fn start(timer: TIMER, resets: &mut RESETS) { + resets.reset.modify(|_, w| w.timer().clear_bit()); + while resets.reset_done.read().timer().bit_is_clear() {} + timer.inte.modify(|_, w| w.alarm_0().set_bit()); + + TIMER_QUEUE.initialize(Self {}); + } + + fn timer() -> &'static timer::RegisterBlock { + unsafe { &*TIMER::ptr() } + } +} + +static TIMER_QUEUE: TimerQueue<Timer> = TimerQueue::new(); + +// Forward timerqueue interface +impl Timer { + /// Used to access the underlying timer queue + #[doc(hidden)] + pub fn __tq() -> &'static TimerQueue<Timer> { + &TIMER_QUEUE + } + + /// Timeout at a specific time. + pub async fn timeout_at<F: Future>( + instant: <Self as Monotonic>::Instant, + future: F, + ) -> Result<F::Output, TimeoutError> { + TIMER_QUEUE.timeout_at(instant, future).await + } + + /// Timeout after a specific duration. + #[inline] + pub async fn timeout_after<F: Future>( + duration: <Self as Monotonic>::Duration, + future: F, + ) -> Result<F::Output, TimeoutError> { + TIMER_QUEUE.timeout_after(duration, future).await + } + + /// Delay for some duration of time. + #[inline] + pub async fn delay(duration: <Self as Monotonic>::Duration) { + TIMER_QUEUE.delay(duration).await; + } + + /// Delay to some specific time instant. + pub async fn delay_until(instant: <Self as Monotonic>::Instant) { + TIMER_QUEUE.delay_until(instant).await; + } +} + +impl Monotonic for Timer { + type Instant = fugit::TimerInstantU64<1_000_000>; + type Duration = fugit::TimerDurationU64<1_000_000>; + + const ZERO: Self::Instant = Self::Instant::from_ticks(0); + + fn now() -> Self::Instant { + let timer = Self::timer(); + + let mut hi0 = timer.timerawh.read().bits(); + loop { + let low = timer.timerawl.read().bits(); + let hi1 = timer.timerawh.read().bits(); + if hi0 == hi1 { + break Self::Instant::from_ticks((u64::from(hi0) << 32) | u64::from(low)); + } + hi0 = hi1; + } + } + + fn set_compare(instant: Self::Instant) { + let now = Self::now(); + + let max = u32::MAX as u64; + + // Since the timer may or may not overflow based on the requested compare val, we check + // how many ticks are left. + let val = match instant.checked_duration_since(now) { + Some(x) if x.ticks() <= max => instant.duration_since_epoch().ticks() & max, // Will not overflow + _ => 0, // Will overflow or in the past, set the same value as after overflow to not get extra interrupts + }; + + Self::timer() + .alarm0 + .write(|w| unsafe { w.bits(val as u32) }); + } + + fn clear_compare_flag() { + Self::timer().intr.modify(|_, w| w.alarm_0().set_bit()); + } + + fn pend_interrupt() { + rp2040_pac::NVIC::pend(Interrupt::TIMER_IRQ_0); + } + + fn on_interrupt() {} + + fn enable_timer() {} + + fn disable_timer() {} +} + +#[cfg(feature = "embedded-hal-async")] +impl embedded_hal_async::delay::DelayUs for Timer { + type Error = core::convert::Infallible; + + async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { + TIMER_QUEUE.delay((us as u64).micros()).await; + Ok(()) + } + + async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { + TIMER_QUEUE.delay((ms as u64).millis()).await; + Ok(()) + } +} + +/// Register the Timer interrupt for the monotonic. +#[macro_export] +macro_rules! make_rp2040_monotonic_handler { + () => { + #[no_mangle] + #[allow(non_snake_case)] + unsafe extern "C" fn TIMER_IRQ_0() { + rtic_monotonics::rp2040::Timer::__tq().on_monotonic_interrupt(); + } + }; +} diff --git a/rtic-monotonics/src/systick.rs b/rtic-monotonics/src/systick.rs new file mode 100644 index 0000000..691d7c7 --- /dev/null +++ b/rtic-monotonics/src/systick.rs @@ -0,0 +1,163 @@ +//! ... + +use super::Monotonic; +pub use super::{TimeoutError, TimerQueue}; +use atomic_polyfill::{AtomicU32, Ordering}; +use core::future::Future; +use cortex_m::peripheral::SYST; +pub use fugit::ExtU32; + +// Features should be additive, here systick-100hz gets picked if both +// `systick-100hz` and `systick-10khz` are enabled. + +cfg_if::cfg_if! { + if #[cfg(feature = "systick-100hz")] + { + const TIMER_HZ: u32 = 100; + } else if #[cfg(feature = "systick-10khz")] + { + const TIMER_HZ: u32 = 10_000; + } else { + // Default case is 1 kHz + const TIMER_HZ: u32 = 1_000; + } +} + +/// Systick implementing `rtic_monotonic::Monotonic` which runs at 1 kHz, 100Hz or 10 kHz. +pub struct Systick; + +impl Systick { + /// Start a `Monotonic` based on SysTick. + /// + /// The `sysclk` parameter is the speed at which SysTick runs at. This value should come from + /// the clock generation function of the used HAL. + /// + /// Notice that the actual rate of the timer is a best approximation based on the given + /// `sysclk` and `TIMER_HZ`. + /// + /// Note: Give the return value to `TimerQueue::initialize()` to initialize the timer queue. + pub fn start(mut systick: cortex_m::peripheral::SYST, sysclk: u32) { + // + TIMER_HZ / 2 provides round to nearest instead of round to 0. + // - 1 as the counter range is inclusive [0, reload] + let reload = (sysclk + TIMER_HZ / 2) / TIMER_HZ - 1; + + assert!(reload <= 0x00ff_ffff); + assert!(reload > 0); + + systick.disable_counter(); + systick.set_clock_source(cortex_m::peripheral::syst::SystClkSource::Core); + systick.set_reload(reload); + systick.enable_interrupt(); + systick.enable_counter(); + + SYSTICK_TIMER_QUEUE.initialize(Systick {}); + } + + fn systick() -> SYST { + unsafe { core::mem::transmute::<(), SYST>(()) } + } +} + +static SYSTICK_CNT: AtomicU32 = AtomicU32::new(0); +static SYSTICK_TIMER_QUEUE: TimerQueue<Systick> = TimerQueue::new(); + +// Forward timerqueue interface +impl Systick { + /// Used to access the underlying timer queue + #[doc(hidden)] + pub fn __tq() -> &'static TimerQueue<Systick> { + &SYSTICK_TIMER_QUEUE + } + + /// Timeout at a specific time. + pub async fn timeout_at<F: Future>( + instant: <Self as Monotonic>::Instant, + future: F, + ) -> Result<F::Output, TimeoutError> { + SYSTICK_TIMER_QUEUE.timeout_at(instant, future).await + } + + /// Timeout after a specific duration. + #[inline] + pub async fn timeout_after<F: Future>( + duration: <Self as Monotonic>::Duration, + future: F, + ) -> Result<F::Output, TimeoutError> { + SYSTICK_TIMER_QUEUE.timeout_after(duration, future).await + } + + /// Delay for some duration of time. + #[inline] + pub async fn delay(duration: <Self as Monotonic>::Duration) { + SYSTICK_TIMER_QUEUE.delay(duration).await; + } + + /// Delay to some specific time instant. + pub async fn delay_until(instant: <Self as Monotonic>::Instant) { + SYSTICK_TIMER_QUEUE.delay_until(instant).await; + } +} + +impl Monotonic for Systick { + type Instant = fugit::TimerInstantU32<TIMER_HZ>; + type Duration = fugit::TimerDurationU32<TIMER_HZ>; + + const ZERO: Self::Instant = Self::Instant::from_ticks(0); + + fn now() -> Self::Instant { + if Self::systick().has_wrapped() { + SYSTICK_CNT.fetch_add(1, Ordering::AcqRel); + } + + Self::Instant::from_ticks(SYSTICK_CNT.load(Ordering::Relaxed)) + } + + fn set_compare(_: Self::Instant) { + // No need to do something here, we get interrupts anyway. + } + + fn clear_compare_flag() { + // NOOP with SysTick interrupt + } + + fn pend_interrupt() { + cortex_m::peripheral::SCB::set_pendst(); + } + + fn on_interrupt() { + if Self::systick().has_wrapped() { + SYSTICK_CNT.fetch_add(1, Ordering::AcqRel); + } + } + + fn enable_timer() {} + + fn disable_timer() {} +} + +#[cfg(feature = "embedded-hal-async")] +impl embedded_hal_async::delay::DelayUs for Systick { + type Error = core::convert::Infallible; + + async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { + SYSTICK_TIMER_QUEUE.delay(us.micros()).await; + Ok(()) + } + + async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { + SYSTICK_TIMER_QUEUE.delay(ms.millis()).await; + Ok(()) + } +} + +/// Register the Systick interrupt for the monotonic. +#[macro_export] +macro_rules! make_systick_handler { + () => { + #[no_mangle] + #[allow(non_snake_case)] + unsafe extern "C" fn SysTick() { + rtic_monotonics::systick::Systick::__tq().on_monotonic_interrupt(); + } + }; +} diff --git a/rtic-sync/.gitignore b/rtic-sync/.gitignore new file mode 100644 index 0000000..1e7caa9 --- /dev/null +++ b/rtic-sync/.gitignore @@ -0,0 +1,2 @@ +Cargo.lock +target/ diff --git a/rtic-sync/CHANGELOG.md b/rtic-sync/CHANGELOG.md new file mode 100644 index 0000000..d3a9d84 --- /dev/null +++ b/rtic-sync/CHANGELOG.md @@ -0,0 +1,16 @@ +# Change Log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +For each category, *Added*, *Changed*, *Fixed* add new entries at the top! + +## [Unreleased] + +### Added + +### Changed + +### Fixed + +## [v1.0.0] - 2023-xx-xx diff --git a/rtic-sync/Cargo.toml b/rtic-sync/Cargo.toml new file mode 100644 index 0000000..440a6be --- /dev/null +++ b/rtic-sync/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "rtic-sync" +version = "1.0.0-alpha.0" + +edition = "2021" +authors = [ + "The Real-Time Interrupt-driven Concurrency developers", + "Emil Fresk <emil.fresk@gmail.com>", + "Henrik Tjäder <henrik@tjaders.com>", + "Jorge Aparicio <jorge@japaric.io>", + "Per Lindgren <per.lindgren@ltu.se>", +] +categories = ["concurrency", "embedded", "no-std", "asynchronous"] +description = "Synchronization primitives for asynchronous contexts" +license = "MIT OR Apache-2.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +heapless = "0.7" +critical-section = "1" +rtic-common = { version = "1.0.0-alpha.0", path = "../rtic-common" } + +[dev-dependencies] +tokio = { version = "1", features = ["rt", "macros", "time"] } + + +[features] +default = [] +testing = ["critical-section/std", "rtic-common/testing"] diff --git a/rtic-sync/src/arbiter.rs b/rtic-sync/src/arbiter.rs new file mode 100644 index 0000000..d50b1ea --- /dev/null +++ b/rtic-sync/src/arbiter.rs @@ -0,0 +1,194 @@ +//! Crate + +use core::cell::UnsafeCell; +use core::future::poll_fn; +use core::ops::{Deref, DerefMut}; +use core::pin::Pin; +use core::sync::atomic::{fence, AtomicBool, Ordering}; +use core::task::{Poll, Waker}; + +use rtic_common::dropper::OnDrop; +use rtic_common::wait_queue::{Link, WaitQueue}; + +/// This is needed to make the async closure in `send` accept that we "share" +/// the link possible between threads. +#[derive(Clone)] +struct LinkPtr(*mut Option<Link<Waker>>); + +impl LinkPtr { + /// This will dereference the pointer stored within and give out an `&mut`. + unsafe fn get(&mut self) -> &mut Option<Link<Waker>> { + &mut *self.0 + } +} + +unsafe impl Send for LinkPtr {} +unsafe impl Sync for LinkPtr {} + +/// An FIFO waitqueue for use in shared bus usecases. +pub struct Arbiter<T> { + wait_queue: WaitQueue, + inner: UnsafeCell<T>, + taken: AtomicBool, +} + +unsafe impl<T> Send for Arbiter<T> {} +unsafe impl<T> Sync for Arbiter<T> {} + +impl<T> Arbiter<T> { + /// Create a new arbiter. + pub const fn new(inner: T) -> Self { + Self { + wait_queue: WaitQueue::new(), + inner: UnsafeCell::new(inner), + taken: AtomicBool::new(false), + } + } + + /// Get access to the inner value in the `Arbiter`. This will wait until access is granted, + /// for non-blocking access use `try_access`. + pub async fn access(&self) -> ExclusiveAccess<'_, T> { + let mut link_ptr: Option<Link<Waker>> = None; + + // Make this future `Drop`-safe. + // SAFETY(link_ptr): Shadow the original definition of `link_ptr` so we can't abuse it. + let mut link_ptr = LinkPtr(&mut link_ptr as *mut Option<Link<Waker>>); + + let mut link_ptr2 = link_ptr.clone(); + let dropper = OnDrop::new(|| { + // SAFETY: We only run this closure and dereference the pointer if we have + // exited the `poll_fn` below in the `drop(dropper)` call. The other dereference + // of this pointer is in the `poll_fn`. + if let Some(link) = unsafe { link_ptr2.get() } { + link.remove_from_list(&self.wait_queue); + } + }); + + poll_fn(|cx| { + critical_section::with(|_| { + fence(Ordering::SeqCst); + + // The queue is empty and noone has taken the value. + if self.wait_queue.is_empty() && !self.taken.load(Ordering::Relaxed) { + self.taken.store(true, Ordering::Relaxed); + + return Poll::Ready(()); + } + + // SAFETY: This pointer is only dereferenced here and on drop of the future + // which happens outside this `poll_fn`'s stack frame. + let link = unsafe { link_ptr.get() }; + if let Some(link) = link { + if link.is_popped() { + return Poll::Ready(()); + } + } else { + // Place the link in the wait queue on first run. + let link_ref = link.insert(Link::new(cx.waker().clone())); + + // SAFETY(new_unchecked): The address to the link is stable as it is defined + // outside this stack frame. + // SAFETY(push): `link_ref` lifetime comes from `link_ptr` that is shadowed, + // and we make sure in `dropper` that the link is removed from the queue + // before dropping `link_ptr` AND `dropper` makes sure that the shadowed + // `link_ptr` lives until the end of the stack frame. + unsafe { self.wait_queue.push(Pin::new_unchecked(link_ref)) }; + } + + Poll::Pending + }) + }) + .await; + + // Make sure the link is removed from the queue. + drop(dropper); + + // SAFETY: One only gets here if there is exlusive access. + ExclusiveAccess { + arbiter: self, + inner: unsafe { &mut *self.inner.get() }, + } + } + + /// Non-blockingly tries to access the underlying value. + /// If someone is in queue to get it, this will return `None`. + pub fn try_access(&self) -> Option<ExclusiveAccess<'_, T>> { + critical_section::with(|_| { + fence(Ordering::SeqCst); + + // The queue is empty and noone has taken the value. + if self.wait_queue.is_empty() && !self.taken.load(Ordering::Relaxed) { + self.taken.store(true, Ordering::Relaxed); + + // SAFETY: One only gets here if there is exlusive access. + Some(ExclusiveAccess { + arbiter: self, + inner: unsafe { &mut *self.inner.get() }, + }) + } else { + None + } + }) + } +} + +/// This token represents exclusive access to the value protected by the `Arbiter`. +pub struct ExclusiveAccess<'a, T> { + arbiter: &'a Arbiter<T>, + inner: &'a mut T, +} + +impl<'a, T> Drop for ExclusiveAccess<'a, T> { + fn drop(&mut self) { + critical_section::with(|_| { + fence(Ordering::SeqCst); + + if self.arbiter.wait_queue.is_empty() { + // If noone is in queue and we release exclusive access, reset `taken`. + self.arbiter.taken.store(false, Ordering::Relaxed); + } else if let Some(next) = self.arbiter.wait_queue.pop() { + // Wake the next one in queue. + next.wake(); + } + }) + } +} + +impl<'a, T> Deref for ExclusiveAccess<'a, T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + self.inner + } +} + +impl<'a, T> DerefMut for ExclusiveAccess<'a, T> { + fn deref_mut(&mut self) -> &mut Self::Target { + self.inner + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn stress_channel() { + const NUM_RUNS: usize = 100_000; + + static ARB: Arbiter<usize> = Arbiter::new(0); + let mut v = std::vec::Vec::new(); + + for _ in 0..NUM_RUNS { + v.push(tokio::spawn(async move { + *ARB.access().await += 1; + })); + } + + for v in v { + v.await.unwrap(); + } + + assert_eq!(*ARB.access().await, NUM_RUNS) + } +} diff --git a/rtic-sync/src/channel.rs b/rtic-sync/src/channel.rs new file mode 100644 index 0000000..8a817c8 --- /dev/null +++ b/rtic-sync/src/channel.rs @@ -0,0 +1,573 @@ +//! Crate + +use core::{ + cell::UnsafeCell, + future::poll_fn, + mem::MaybeUninit, + pin::Pin, + ptr, + sync::atomic::{fence, Ordering}, + task::{Poll, Waker}, +}; +use heapless::Deque; +use rtic_common::waker_registration::CriticalSectionWakerRegistration as WakerRegistration; +use rtic_common::{ + dropper::OnDrop, + wait_queue::{Link, WaitQueue}, +}; + +/// An MPSC channel for use in no-alloc systems. `N` sets the size of the queue. +/// +/// This channel uses critical sections, however there are extremely small and all `memcpy` +/// operations of `T` are done without critical sections. +pub struct Channel<T, const N: usize> { + // Here are all indexes that are not used in `slots` and ready to be allocated. + freeq: UnsafeCell<Deque<u8, N>>, + // Here are wakers and indexes to slots that are ready to be dequeued by the receiver. + readyq: UnsafeCell<Deque<u8, N>>, + // Waker for the receiver. + receiver_waker: WakerRegistration, + // Storage for N `T`s, so we don't memcpy around a lot of `T`s. + slots: [UnsafeCell<MaybeUninit<T>>; N], + // If there is no room in the queue a `Sender`s can wait for there to be place in the queue. + wait_queue: WaitQueue, + // Keep track of the receiver. + receiver_dropped: UnsafeCell<bool>, + // Keep track of the number of senders. + num_senders: UnsafeCell<usize>, +} + +unsafe impl<T, const N: usize> Send for Channel<T, N> {} +unsafe impl<T, const N: usize> Sync for Channel<T, N> {} + +struct UnsafeAccess<'a, const N: usize> { + freeq: &'a mut Deque<u8, N>, + readyq: &'a mut Deque<u8, N>, + receiver_dropped: &'a mut bool, + num_senders: &'a mut usize, +} + +impl<T, const N: usize> Channel<T, N> { + const _CHECK: () = assert!(N < 256, "This queue support a maximum of 255 entries"); + + const INIT_SLOTS: UnsafeCell<MaybeUninit<T>> = UnsafeCell::new(MaybeUninit::uninit()); + + /// Create a new channel. + pub const fn new() -> Self { + Self { + freeq: UnsafeCell::new(Deque::new()), + readyq: UnsafeCell::new(Deque::new()), + receiver_waker: WakerRegistration::new(), + slots: [Self::INIT_SLOTS; N], + wait_queue: WaitQueue::new(), + receiver_dropped: UnsafeCell::new(false), + num_senders: UnsafeCell::new(0), + } + } + + /// Split the queue into a `Sender`/`Receiver` pair. + pub fn split(&mut self) -> (Sender<'_, T, N>, Receiver<'_, T, N>) { + // Fill free queue + for idx in 0..N as u8 { + debug_assert!(!self.freeq.get_mut().is_full()); + + // SAFETY: This safe as the loop goes from 0 to the capacity of the underlying queue. + unsafe { + self.freeq.get_mut().push_back_unchecked(idx); + } + } + + debug_assert!(self.freeq.get_mut().is_full()); + + // There is now 1 sender + *self.num_senders.get_mut() = 1; + + (Sender(self), Receiver(self)) + } + + fn access<'a>(&'a self, _cs: critical_section::CriticalSection) -> UnsafeAccess<'a, N> { + // SAFETY: This is safe as are in a critical section. + unsafe { + UnsafeAccess { + freeq: &mut *self.freeq.get(), + readyq: &mut *self.readyq.get(), + receiver_dropped: &mut *self.receiver_dropped.get(), + num_senders: &mut *self.num_senders.get(), + } + } + } +} + +/// Creates a split channel with `'static` lifetime. +#[macro_export] +macro_rules! make_channel { + ($type:path, $size:expr) => {{ + static mut CHANNEL: Channel<$type, $size> = Channel::new(); + + // SAFETY: This is safe as we hide the static mut from others to access it. + // Only this point is where the mutable access happens. + unsafe { CHANNEL.split() } + }}; +} + +// -------- Sender + +/// Error state for when the receiver has been dropped. +pub struct NoReceiver<T>(pub T); + +/// Errors that 'try_send` can have. +pub enum TrySendError<T> { + /// Error state for when the receiver has been dropped. + NoReceiver(T), + /// Error state when the queue is full. + Full(T), +} + +impl<T> core::fmt::Debug for NoReceiver<T> +where + T: core::fmt::Debug, +{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "NoReceiver({:?})", self.0) + } +} + +impl<T> core::fmt::Debug for TrySendError<T> +where + T: core::fmt::Debug, +{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + TrySendError::NoReceiver(v) => write!(f, "NoReceiver({v:?})"), + TrySendError::Full(v) => write!(f, "Full({v:?})"), + } + } +} + +impl<T> PartialEq for TrySendError<T> +where + T: PartialEq, +{ + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (TrySendError::NoReceiver(v1), TrySendError::NoReceiver(v2)) => v1.eq(v2), + (TrySendError::NoReceiver(_), TrySendError::Full(_)) => false, + (TrySendError::Full(_), TrySendError::NoReceiver(_)) => false, + (TrySendError::Full(v1), TrySendError::Full(v2)) => v1.eq(v2), + } + } +} + +/// A `Sender` can send to the channel and can be cloned. +pub struct Sender<'a, T, const N: usize>(&'a Channel<T, N>); + +unsafe impl<'a, T, const N: usize> Send for Sender<'a, T, N> {} + +/// This is needed to make the async closure in `send` accept that we "share" +/// the link possible between threads. +#[derive(Clone)] +struct LinkPtr(*mut Option<Link<Waker>>); + +impl LinkPtr { + /// This will dereference the pointer stored within and give out an `&mut`. + unsafe fn get(&mut self) -> &mut Option<Link<Waker>> { + &mut *self.0 + } +} + +unsafe impl Send for LinkPtr {} +unsafe impl Sync for LinkPtr {} + +impl<'a, T, const N: usize> core::fmt::Debug for Sender<'a, T, N> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "Sender") + } +} + +impl<'a, T, const N: usize> Sender<'a, T, N> { + #[inline(always)] + fn send_footer(&mut self, idx: u8, val: T) { + // Write the value to the slots, note; this memcpy is not under a critical section. + unsafe { + ptr::write( + self.0.slots.get_unchecked(idx as usize).get() as *mut T, + val, + ) + } + + // Write the value into the ready queue. + critical_section::with(|cs| { + debug_assert!(!self.0.access(cs).readyq.is_full()); + unsafe { self.0.access(cs).readyq.push_back_unchecked(idx) } + }); + + fence(Ordering::SeqCst); + + // If there is a receiver waker, wake it. + self.0.receiver_waker.wake(); + } + + /// Try to send a value, non-blocking. If the channel is full this will return an error. + pub fn try_send(&mut self, val: T) -> Result<(), TrySendError<T>> { + // If the wait queue is not empty, we can't try to push into the queue. + if !self.0.wait_queue.is_empty() { + return Err(TrySendError::Full(val)); + } + + // No receiver available. + if self.is_closed() { + return Err(TrySendError::NoReceiver(val)); + } + + let idx = + if let Some(idx) = critical_section::with(|cs| self.0.access(cs).freeq.pop_front()) { + idx + } else { + return Err(TrySendError::Full(val)); + }; + + self.send_footer(idx, val); + + Ok(()) + } + + /// Send a value. If there is no place left in the queue this will wait until there is. + /// If the receiver does not exist this will return an error. + pub async fn send(&mut self, val: T) -> Result<(), NoReceiver<T>> { + let mut link_ptr: Option<Link<Waker>> = None; + + // Make this future `Drop`-safe. + // SAFETY(link_ptr): Shadow the original definition of `link_ptr` so we can't abuse it. + let mut link_ptr = LinkPtr(&mut link_ptr as *mut Option<Link<Waker>>); + + let mut link_ptr2 = link_ptr.clone(); + let dropper = OnDrop::new(|| { + // SAFETY: We only run this closure and dereference the pointer if we have + // exited the `poll_fn` below in the `drop(dropper)` call. The other dereference + // of this pointer is in the `poll_fn`. + if let Some(link) = unsafe { link_ptr2.get() } { + link.remove_from_list(&self.0.wait_queue); + } + }); + + let idx = poll_fn(|cx| { + if self.is_closed() { + return Poll::Ready(Err(())); + } + + // Do all this in one critical section, else there can be race conditions + let queue_idx = critical_section::with(|cs| { + let wq_empty = self.0.wait_queue.is_empty(); + let fq_empty = self.0.access(cs).freeq.is_empty(); + if !wq_empty || fq_empty { + // SAFETY: This pointer is only dereferenced here and on drop of the future + // which happens outside this `poll_fn`'s stack frame. + let link = unsafe { link_ptr.get() }; + if let Some(link) = link { + if !link.is_popped() { + return None; + } else { + // Fall through to dequeue + } + } else { + // Place the link in the wait queue on first run. + let link_ref = link.insert(Link::new(cx.waker().clone())); + + // SAFETY(new_unchecked): The address to the link is stable as it is defined + // outside this stack frame. + // SAFETY(push): `link_ref` lifetime comes from `link_ptr` that is shadowed, + // and we make sure in `dropper` that the link is removed from the queue + // before dropping `link_ptr` AND `dropper` makes sure that the shadowed + // `link_ptr` lives until the end of the stack frame. + unsafe { self.0.wait_queue.push(Pin::new_unchecked(link_ref)) }; + + return None; + } + } + + debug_assert!(!self.0.access(cs).freeq.is_empty()); + // Get index as the queue is guaranteed not empty and the wait queue is empty + let idx = unsafe { self.0.access(cs).freeq.pop_front_unchecked() }; + + Some(idx) + }); + + if let Some(idx) = queue_idx { + // Return the index + Poll::Ready(Ok(idx)) + } else { + Poll::Pending + } + }) + .await; + + // Make sure the link is removed from the queue. + drop(dropper); + + if let Ok(idx) = idx { + self.send_footer(idx, val); + + Ok(()) + } else { + Err(NoReceiver(val)) + } + } + + /// Returns true if there is no `Receiver`s. + pub fn is_closed(&self) -> bool { + critical_section::with(|cs| *self.0.access(cs).receiver_dropped) + } + + /// Is the queue full. + pub fn is_full(&self) -> bool { + critical_section::with(|cs| self.0.access(cs).freeq.is_empty()) + } + + /// Is the queue empty. + pub fn is_empty(&self) -> bool { + critical_section::with(|cs| self.0.access(cs).freeq.is_full()) + } +} + +impl<'a, T, const N: usize> Drop for Sender<'a, T, N> { + fn drop(&mut self) { + // Count down the reference counter + let num_senders = critical_section::with(|cs| { + *self.0.access(cs).num_senders -= 1; + + *self.0.access(cs).num_senders + }); + + // If there are no senders, wake the receiver to do error handling. + if num_senders == 0 { + self.0.receiver_waker.wake(); + } + } +} + +impl<'a, T, const N: usize> Clone for Sender<'a, T, N> { + fn clone(&self) -> Self { + // Count up the reference counter + critical_section::with(|cs| *self.0.access(cs).num_senders += 1); + + Self(self.0) + } +} + +// -------- Receiver + +/// A receiver of the channel. There can only be one receiver at any time. +pub struct Receiver<'a, T, const N: usize>(&'a Channel<T, N>); + +unsafe impl<'a, T, const N: usize> Send for Receiver<'a, T, N> {} + +impl<'a, T, const N: usize> core::fmt::Debug for Receiver<'a, T, N> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "Receiver") + } +} + +/// Possible receive errors. +#[derive(Debug, PartialEq, Eq)] +pub enum ReceiveError { + /// Error state for when all senders has been dropped. + NoSender, + /// Error state for when the queue is empty. + Empty, +} + +impl<'a, T, const N: usize> Receiver<'a, T, N> { + /// Receives a value if there is one in the channel, non-blocking. + pub fn try_recv(&mut self) -> Result<T, ReceiveError> { + // Try to get a ready slot. + let ready_slot = critical_section::with(|cs| self.0.access(cs).readyq.pop_front()); + + if let Some(rs) = ready_slot { + // Read the value from the slots, note; this memcpy is not under a critical section. + let r = unsafe { ptr::read(self.0.slots.get_unchecked(rs as usize).get() as *const T) }; + + // Return the index to the free queue after we've read the value. + critical_section::with(|cs| { + debug_assert!(!self.0.access(cs).freeq.is_full()); + unsafe { self.0.access(cs).freeq.push_back_unchecked(rs) } + }); + + fence(Ordering::SeqCst); + + // If someone is waiting in the WaiterQueue, wake the first one up. + if let Some(wait_head) = self.0.wait_queue.pop() { + wait_head.wake(); + } + + Ok(r) + } else if self.is_closed() { + Err(ReceiveError::NoSender) + } else { + Err(ReceiveError::Empty) + } + } + + /// Receives a value, waiting if the queue is empty. + /// If all senders are dropped this will error with `NoSender`. + pub async fn recv(&mut self) -> Result<T, ReceiveError> { + // There was nothing in the queue, setup the waiting. + poll_fn(|cx| { + // Register waker. + // TODO: Should it happen here or after the if? This might cause a spurious wake. + self.0.receiver_waker.register(cx.waker()); + + // Try to dequeue. + match self.try_recv() { + Ok(val) => { + return Poll::Ready(Ok(val)); + } + Err(ReceiveError::NoSender) => { + return Poll::Ready(Err(ReceiveError::NoSender)); + } + _ => {} + } + + Poll::Pending + }) + .await + } + + /// Returns true if there are no `Sender`s. + pub fn is_closed(&self) -> bool { + critical_section::with(|cs| *self.0.access(cs).num_senders == 0) + } + + /// Is the queue full. + pub fn is_full(&self) -> bool { + critical_section::with(|cs| self.0.access(cs).readyq.is_full()) + } + + /// Is the queue empty. + pub fn is_empty(&self) -> bool { + critical_section::with(|cs| self.0.access(cs).readyq.is_empty()) + } +} + +impl<'a, T, const N: usize> Drop for Receiver<'a, T, N> { + fn drop(&mut self) { + // Mark the receiver as dropped and wake all waiters + critical_section::with(|cs| *self.0.access(cs).receiver_dropped = true); + + while let Some(waker) = self.0.wait_queue.pop() { + waker.wake(); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn empty() { + let (mut s, mut r) = make_channel!(u32, 10); + + assert!(s.is_empty()); + assert!(r.is_empty()); + + s.try_send(1).unwrap(); + + assert!(!s.is_empty()); + assert!(!r.is_empty()); + + r.try_recv().unwrap(); + + assert!(s.is_empty()); + assert!(r.is_empty()); + } + + #[test] + fn full() { + let (mut s, mut r) = make_channel!(u32, 3); + + for _ in 0..3 { + assert!(!s.is_full()); + assert!(!r.is_full()); + + s.try_send(1).unwrap(); + } + + assert!(s.is_full()); + assert!(r.is_full()); + + for _ in 0..3 { + r.try_recv().unwrap(); + + assert!(!s.is_full()); + assert!(!r.is_full()); + } + } + + #[test] + fn send_recieve() { + let (mut s, mut r) = make_channel!(u32, 10); + + for i in 0..10 { + s.try_send(i).unwrap(); + } + + assert_eq!(s.try_send(11), Err(TrySendError::Full(11))); + + for i in 0..10 { + assert_eq!(r.try_recv().unwrap(), i); + } + + assert_eq!(r.try_recv(), Err(ReceiveError::Empty)); + } + + #[test] + fn closed_recv() { + let (s, mut r) = make_channel!(u32, 10); + + drop(s); + + assert!(r.is_closed()); + + assert_eq!(r.try_recv(), Err(ReceiveError::NoSender)); + } + + #[test] + fn closed_sender() { + let (mut s, r) = make_channel!(u32, 10); + + drop(r); + + assert!(s.is_closed()); + + assert_eq!(s.try_send(11), Err(TrySendError::NoReceiver(11))); + } + + #[tokio::test] + async fn stress_channel() { + const NUM_RUNS: usize = 1_000; + const QUEUE_SIZE: usize = 10; + + let (s, mut r) = make_channel!(u32, QUEUE_SIZE); + let mut v = std::vec::Vec::new(); + + for i in 0..NUM_RUNS { + let mut s = s.clone(); + + v.push(tokio::spawn(async move { + s.send(i as _).await.unwrap(); + })); + } + + let mut map = std::collections::BTreeSet::new(); + + for _ in 0..NUM_RUNS { + map.insert(r.recv().await.unwrap()); + } + + assert_eq!(map.len(), NUM_RUNS); + + for v in v { + v.await.unwrap(); + } + } +} diff --git a/rtic-sync/src/lib.rs b/rtic-sync/src/lib.rs new file mode 100644 index 0000000..ac06220 --- /dev/null +++ b/rtic-sync/src/lib.rs @@ -0,0 +1,12 @@ +//! Synchronization primitives for asynchronous contexts. + +#![no_std] +#![deny(missing_docs)] +//deny_warnings_placeholder_for_ci + +pub mod arbiter; +pub mod channel; + +#[cfg(test)] +#[macro_use] +extern crate std; diff --git a/rtic-time/.gitignore b/rtic-time/.gitignore new file mode 100644 index 0000000..c400256 --- /dev/null +++ b/rtic-time/.gitignore @@ -0,0 +1,6 @@ +**/*.rs.bk +.#* +.gdb_history +/target +Cargo.lock +*.hex diff --git a/rtic-time/CHANGELOG.md b/rtic-time/CHANGELOG.md new file mode 100644 index 0000000..d3a9d84 --- /dev/null +++ b/rtic-time/CHANGELOG.md @@ -0,0 +1,16 @@ +# Change Log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +For each category, *Added*, *Changed*, *Fixed* add new entries at the top! + +## [Unreleased] + +### Added + +### Changed + +### Fixed + +## [v1.0.0] - 2023-xx-xx diff --git a/rtic-time/Cargo.toml b/rtic-time/Cargo.toml new file mode 100644 index 0000000..c7d13bb --- /dev/null +++ b/rtic-time/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "rtic-time" +version = "1.0.0-alpha.0" + +edition = "2021" +authors = [ + "The Real-Time Interrupt-driven Concurrency developers", + "Emil Fresk <emil.fresk@gmail.com>", + "Henrik Tjäder <henrik@tjaders.com>", + "Jorge Aparicio <jorge@japaric.io>", + "Per Lindgren <per.lindgren@ltu.se>", +] +categories = ["concurrency", "embedded", "no-std", "asynchronous"] +description = "rtic-time lib TODO" +license = "MIT OR Apache-2.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +critical-section = "1" +futures-util = { version = "0.3.25", default-features = false } +rtic-common = { version = "1.0.0-alpha.0", path = "../rtic-common" } diff --git a/rtic-time/rust-toolchain.toml b/rtic-time/rust-toolchain.toml new file mode 100644 index 0000000..e28b55d --- /dev/null +++ b/rtic-time/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly" +components = [ "rust-src", "rustfmt", "llvm-tools-preview" ] +targets = [ "thumbv6m-none-eabi", "thumbv7m-none-eabi" ] diff --git a/rtic-time/src/lib.rs b/rtic-time/src/lib.rs new file mode 100644 index 0000000..78b57a4 --- /dev/null +++ b/rtic-time/src/lib.rs @@ -0,0 +1,273 @@ +//! Crate + +#![no_std] +#![deny(missing_docs)] +//deny_warnings_placeholder_for_ci +#![allow(incomplete_features)] +#![feature(async_fn_in_trait)] + +use core::future::{poll_fn, Future}; +use core::pin::Pin; +use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; +use core::task::{Poll, Waker}; +use futures_util::{ + future::{select, Either}, + pin_mut, +}; +use linked_list::{Link, LinkedList}; +pub use monotonic::Monotonic; +use rtic_common::dropper::OnDrop; + +mod linked_list; +mod monotonic; + +/// Holds a waker and at which time instant this waker shall be awoken. +struct WaitingWaker<Mono: Monotonic> { + waker: Waker, + release_at: Mono::Instant, + was_poped: AtomicBool, +} + +impl<Mono: Monotonic> Clone for WaitingWaker<Mono> { + fn clone(&self) -> Self { + Self { + waker: self.waker.clone(), + release_at: self.release_at, + was_poped: AtomicBool::new(self.was_poped.load(Ordering::Relaxed)), + } + } +} + +impl<Mono: Monotonic> PartialEq for WaitingWaker<Mono> { + fn eq(&self, other: &Self) -> bool { + self.release_at == other.release_at + } +} + +impl<Mono: Monotonic> PartialOrd for WaitingWaker<Mono> { + fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> { + self.release_at.partial_cmp(&other.release_at) + } +} + +/// A generic timer queue for async executors. +/// +/// # Blocking +/// +/// The internal priority queue uses global critical sections to manage access. This means that +/// `await`ing a delay will cause a lock of the entire system for O(n) time. In practice the lock +/// duration is ~10 clock cycles per element in the queue. +/// +/// # Safety +/// +/// This timer queue is based on an intrusive linked list, and by extension the links are strored +/// on the async stacks of callers. The links are deallocated on `drop` or when the wait is +/// complete. +/// +/// Do not call `mem::forget` on an awaited future, or there will be dragons! +pub struct TimerQueue<Mono: Monotonic> { + queue: LinkedList<WaitingWaker<Mono>>, + initialized: AtomicBool, +} + +/// This indicates that there was a timeout. +pub struct TimeoutError; + +/// This is needed to make the async closure in `delay_until` accept that we "share" +/// the link possible between threads. +struct LinkPtr<Mono: Monotonic>(*mut Option<linked_list::Link<WaitingWaker<Mono>>>); + +impl<Mono: Monotonic> Clone for LinkPtr<Mono> { + fn clone(&self) -> Self { + LinkPtr(self.0) + } +} + +impl<Mono: Monotonic> LinkPtr<Mono> { + /// This will dereference the pointer stored within and give out an `&mut`. + unsafe fn get(&mut self) -> &mut Option<linked_list::Link<WaitingWaker<Mono>>> { + &mut *self.0 + } +} + +unsafe impl<Mono: Monotonic> Send for LinkPtr<Mono> {} +unsafe impl<Mono: Monotonic> Sync for LinkPtr<Mono> {} + +impl<Mono: Monotonic> TimerQueue<Mono> { + /// Make a new queue. + pub const fn new() -> Self { + Self { + queue: LinkedList::new(), + initialized: AtomicBool::new(false), + } + } + + /// Forwards the `Monotonic::now()` method. + #[inline(always)] + pub fn now(&self) -> Mono::Instant { + Mono::now() + } + + /// Takes the initialized monotonic to initialize the TimerQueue. + pub fn initialize(&self, monotonic: Mono) { + self.initialized.store(true, Ordering::SeqCst); + + // Don't run drop on `Mono` + core::mem::forget(monotonic); + } + + /// Call this in the interrupt handler of the hardware timer supporting the `Monotonic` + /// + /// # Safety + /// + /// It's always safe to call, but it must only be called from the interrupt of the + /// monotonic timer for correct operation. + pub unsafe fn on_monotonic_interrupt(&self) { + Mono::clear_compare_flag(); + Mono::on_interrupt(); + + loop { + let mut release_at = None; + let head = self.queue.pop_if(|head| { + release_at = Some(head.release_at); + + let should_pop = Mono::now() >= head.release_at; + head.was_poped.store(should_pop, Ordering::Relaxed); + + should_pop + }); + + match (head, release_at) { + (Some(link), _) => { + link.waker.wake(); + } + (None, Some(instant)) => { + Mono::enable_timer(); + Mono::set_compare(instant); + + if Mono::now() >= instant { + // The time for the next instant passed while handling it, + // continue dequeueing + continue; + } + + break; + } + (None, None) => { + // Queue is empty + Mono::disable_timer(); + + break; + } + } + } + } + + /// Timeout at a specific time. + pub async fn timeout_at<F: Future>( + &self, + instant: Mono::Instant, + future: F, + ) -> Result<F::Output, TimeoutError> { + let delay = self.delay_until(instant); + + pin_mut!(future); + pin_mut!(delay); + + match select(future, delay).await { + Either::Left((r, _)) => Ok(r), + Either::Right(_) => Err(TimeoutError), + } + } + + /// Timeout after a specific duration. + #[inline] + pub async fn timeout_after<F: Future>( + &self, + duration: Mono::Duration, + future: F, + ) -> Result<F::Output, TimeoutError> { + self.timeout_at(Mono::now() + duration, future).await + } + + /// Delay for some duration of time. + #[inline] + pub async fn delay(&self, duration: Mono::Duration) { + let now = Mono::now(); + + self.delay_until(now + duration).await; + } + + /// Delay to some specific time instant. + pub async fn delay_until(&self, instant: Mono::Instant) { + if !self.initialized.load(Ordering::Relaxed) { + panic!( + "The timer queue is not initialized with a monotonic, you need to run `initialize`" + ); + } + + let mut link_ptr: Option<linked_list::Link<WaitingWaker<Mono>>> = None; + + // Make this future `Drop`-safe + // SAFETY(link_ptr): Shadow the original definition of `link_ptr` so we can't abuse it. + let mut link_ptr = + LinkPtr(&mut link_ptr as *mut Option<linked_list::Link<WaitingWaker<Mono>>>); + let mut link_ptr2 = link_ptr.clone(); + + let queue = &self.queue; + let marker = &AtomicUsize::new(0); + + let dropper = OnDrop::new(|| { + queue.delete(marker.load(Ordering::Relaxed)); + }); + + poll_fn(|cx| { + if Mono::now() >= instant { + return Poll::Ready(()); + } + + // SAFETY: This pointer is only dereferenced here and on drop of the future + // which happens outside this `poll_fn`'s stack frame, so this mutable access cannot + // happen at the same time as `dropper` runs. + let link = unsafe { link_ptr2.get() }; + if link.is_none() { + let link_ref = link.insert(Link::new(WaitingWaker { + waker: cx.waker().clone(), + release_at: instant, + was_poped: AtomicBool::new(false), + })); + + // SAFETY(new_unchecked): The address to the link is stable as it is defined + //outside this stack frame. + // SAFETY(insert): `link_ref` lifetime comes from `link_ptr` that is shadowed, and + // we make sure in `dropper` that the link is removed from the queue before + // dropping `link_ptr` AND `dropper` makes sure that the shadowed `link_ptr` lives + // until the end of the stack frame. + let (was_empty, addr) = unsafe { queue.insert(Pin::new_unchecked(link_ref)) }; + + marker.store(addr, Ordering::Relaxed); + + if was_empty { + // Pend the monotonic handler if the queue was empty to setup the timer. + Mono::pend_interrupt(); + } + } + + Poll::Pending + }) + .await; + + // SAFETY: We only run this and dereference the pointer if we have + // exited the `poll_fn` below in the `drop(dropper)` call. The other dereference + // of this pointer is in the `poll_fn`. + if let Some(link) = unsafe { link_ptr.get() } { + if link.val.was_poped.load(Ordering::Relaxed) { + // If it was poped from the queue there is no need to run delete + dropper.defuse(); + } + } else { + // Make sure that our link is deleted from the list before we drop this stack + drop(dropper); + } + } +} diff --git a/rtic-time/src/linked_list.rs b/rtic-time/src/linked_list.rs new file mode 100644 index 0000000..d4256c9 --- /dev/null +++ b/rtic-time/src/linked_list.rs @@ -0,0 +1,182 @@ +//! ... + +use core::marker::PhantomPinned; +use core::pin::Pin; +use core::sync::atomic::{AtomicPtr, Ordering}; +use critical_section as cs; + +/// A sorted linked list for the timer queue. +pub(crate) struct LinkedList<T> { + head: AtomicPtr<Link<T>>, +} + +impl<T> LinkedList<T> { + /// Create a new linked list. + pub const fn new() -> Self { + Self { + head: AtomicPtr::new(core::ptr::null_mut()), + } + } +} + +impl<T: PartialOrd + Clone> LinkedList<T> { + /// Pop the first element in the queue if the closure returns true. + pub fn pop_if<F: FnOnce(&T) -> bool>(&self, f: F) -> Option<T> { + cs::with(|_| { + // Make sure all previous writes are visible + core::sync::atomic::fence(Ordering::SeqCst); + + let head = self.head.load(Ordering::Relaxed); + + // SAFETY: `as_ref` is safe as `insert` requires a valid reference to a link + if let Some(head) = unsafe { head.as_ref() } { + if f(&head.val) { + // Move head to the next element + self.head + .store(head.next.load(Ordering::Relaxed), Ordering::Relaxed); + + // We read the value at head + let head_val = head.val.clone(); + + return Some(head_val); + } + } + None + }) + } + + /// Delete a link at an address. + pub fn delete(&self, addr: usize) { + cs::with(|_| { + // Make sure all previous writes are visible + core::sync::atomic::fence(Ordering::SeqCst); + + let head = self.head.load(Ordering::Relaxed); + + // SAFETY: `as_ref` is safe as `insert` requires a valid reference to a link + let head_ref = if let Some(head_ref) = unsafe { head.as_ref() } { + head_ref + } else { + // 1. List is empty, do nothing + return; + }; + + if head as *const _ as usize == addr { + // 2. Replace head with head.next + self.head + .store(head_ref.next.load(Ordering::Relaxed), Ordering::Relaxed); + + return; + } + + // 3. search list for correct node + let mut curr = head_ref; + let mut next = head_ref.next.load(Ordering::Relaxed); + + // SAFETY: `as_ref` is safe as `insert` requires a valid reference to a link + while let Some(next_link) = unsafe { next.as_ref() } { + // Next is not null + + if next as *const _ as usize == addr { + curr.next + .store(next_link.next.load(Ordering::Relaxed), Ordering::Relaxed); + + return; + } + + // Continue searching + curr = next_link; + next = next_link.next.load(Ordering::Relaxed); + } + }) + } + + /// Insert a new link into the linked list. + /// The return is (was_empty, address), where the address of the link is for use with `delete`. + /// + /// SAFETY: The pinned link must live until it is removed from this list. + pub unsafe fn insert(&self, val: Pin<&Link<T>>) -> (bool, usize) { + cs::with(|_| { + // SAFETY: This datastructure does not move the underlying value. + let val = val.get_ref(); + let addr = val as *const _ as usize; + + // Make sure all previous writes are visible + core::sync::atomic::fence(Ordering::SeqCst); + + let head = self.head.load(Ordering::Relaxed); + + // 3 cases to handle + + // 1. List is empty, write to head + // SAFETY: `as_ref` is safe as `insert` requires a valid reference to a link + let head_ref = if let Some(head_ref) = unsafe { head.as_ref() } { + head_ref + } else { + self.head + .store(val as *const _ as *mut _, Ordering::Relaxed); + return (true, addr); + }; + + // 2. val needs to go in first + if val.val < head_ref.val { + // Set current head as next of `val` + val.next.store(head, Ordering::Relaxed); + + // `val` is now first in the queue + self.head + .store(val as *const _ as *mut _, Ordering::Relaxed); + + return (false, addr); + } + + // 3. search list for correct place + let mut curr = head_ref; + let mut next = head_ref.next.load(Ordering::Relaxed); + + // SAFETY: `as_ref` is safe as `insert` requires a valid reference to a link + while let Some(next_link) = unsafe { next.as_ref() } { + // Next is not null + + if val.val < next_link.val { + // Replace next with `val` + val.next.store(next, Ordering::Relaxed); + + // Insert `val` + curr.next + .store(val as *const _ as *mut _, Ordering::Relaxed); + + return (false, addr); + } + + // Continue searching + curr = next_link; + next = next_link.next.load(Ordering::Relaxed); + } + + // No next, write link to last position in list + curr.next + .store(val as *const _ as *mut _, Ordering::Relaxed); + + (false, addr) + }) + } +} + +/// A link in the linked list. +pub struct Link<T> { + pub(crate) val: T, + next: AtomicPtr<Link<T>>, + _up: PhantomPinned, +} + +impl<T> Link<T> { + /// Create a new link. + pub const fn new(val: T) -> Self { + Self { + val, + next: AtomicPtr::new(core::ptr::null_mut()), + _up: PhantomPinned, + } + } +} diff --git a/rtic-time/src/monotonic.rs b/rtic-time/src/monotonic.rs new file mode 100644 index 0000000..9b3742f --- /dev/null +++ b/rtic-time/src/monotonic.rs @@ -0,0 +1,60 @@ +//! ... + +/// # A monotonic clock / counter definition. +/// +/// ## Correctness +/// +/// The trait enforces that proper time-math is implemented between `Instant` and `Duration`. This +/// is a requirement on the time library that the user chooses to use. +pub trait Monotonic { + /// The time at time zero. + const ZERO: Self::Instant; + + /// The type for instant, defining an instant in time. + /// + /// **Note:** In all APIs in RTIC that use instants from this monotonic, this type will be used. + type Instant: Ord + + Copy + + core::ops::Add<Self::Duration, Output = Self::Instant> + + core::ops::Sub<Self::Duration, Output = Self::Instant> + + core::ops::Sub<Self::Instant, Output = Self::Duration>; + + /// The type for duration, defining an duration of time. + /// + /// **Note:** In all APIs in RTIC that use duration from this monotonic, this type will be used. + type Duration; + + /// Get the current time. + fn now() -> Self::Instant; + + /// Set the compare value of the timer interrupt. + /// + /// **Note:** This method does not need to handle race conditions of the monotonic, the timer + /// queue in RTIC checks this. + fn set_compare(instant: Self::Instant); + + /// Clear the compare interrupt flag. + fn clear_compare_flag(); + + /// Pend the timer's interrupt. + fn pend_interrupt(); + + /// Optional. Runs on interrupt before any timer queue handling. + fn on_interrupt() {} + + /// Optional. This is used to save power, this is called when the timer queue is not empty. + /// + /// Enabling and disabling the monotonic needs to propagate to `now` so that an instant + /// based of `now()` is still valid. + /// + /// NOTE: This may be called more than once. + fn enable_timer() {} + + /// Optional. This is used to save power, this is called when the timer queue is empty. + /// + /// Enabling and disabling the monotonic needs to propagate to `now` so that an instant + /// based of `now()` is still valid. + /// + /// NOTE: This may be called more than once. + fn disable_timer() {} +} diff --git a/rtic/.gitignore b/rtic/.gitignore new file mode 100644 index 0000000..c400256 --- /dev/null +++ b/rtic/.gitignore @@ -0,0 +1,6 @@ +**/*.rs.bk +.#* +.gdb_history +/target +Cargo.lock +*.hex diff --git a/CHANGELOG.md b/rtic/CHANGELOG.md index d172278..d172278 100644 --- a/CHANGELOG.md +++ b/rtic/CHANGELOG.md diff --git a/rtic/Cargo.toml b/rtic/Cargo.toml new file mode 100644 index 0000000..9f6d24d --- /dev/null +++ b/rtic/Cargo.toml @@ -0,0 +1,83 @@ +[package] +authors = [ + "The Real-Time Interrupt-driven Concurrency developers", + "Emil Fresk <emil.fresk@gmail.com>", + "Henrik Tjäder <henrik@tjaders.com>", + "Jorge Aparicio <jorge@japaric.io>", + "Per Lindgren <per.lindgren@ltu.se>", +] +categories = ["concurrency", "embedded", "no-std", "asynchronous"] +description = "Real-Time Interrupt-driven Concurrency (RTIC): a concurrency framework for building real-time systems" +documentation = "https://rtic.rs/" +edition = "2021" +keywords = [ + "arm", + "cortex-m", + "risc-v", + "embedded", + "async", + "runtime", + "futures", + "await", + "no-std", + "rtos", + "bare-metal", +] +license = "MIT OR Apache-2.0" +name = "rtic" +readme = "../README.md" +repository = "https://github.com/rtic-rs/rtic" + +version = "2.0.0-alpha.0" + +[lib] +name = "rtic" + +[dependencies] +cortex-m = "0.7.0" +bare-metal = "1.0.0" +#portable-atomic = { version = "0.3.19" } +atomic-polyfill = "1" +rtic-macros = { path = "../rtic-macros", version = "2.0.0-alpha.0" } +rtic-core = "1" +critical-section = "1" + +[dev-dependencies] +heapless = "0.7.7" +lm3s6965 = "0.1.3" +cortex-m-semihosting = "0.5.0" +rtic-time = { path = "../rtic-time" } +rtic-sync = { path = "../rtic-sync" } +rtic-monotonics = { path = "../rtic-monotonics", features = ["cortex-m-systick"] } + +[dev-dependencies.futures] +version = "0.3.26" +default-features = false +features = ["async-await"] + +[dev-dependencies.panic-semihosting] +features = ["exit"] +version = "0.6.0" + +[target.x86_64-unknown-linux-gnu.dev-dependencies] +trybuild = "1" + +[features] +default = [] + +thumbv6-backend = ["rtic-macros/cortex-m-source-masking"] +thumbv7-backend = ["rtic-macros/cortex-m-basepri"] +thumbv8base-backend = ["rtic-macros/cortex-m-source-masking"] +thumbv8main-backend = ["rtic-macros/cortex-m-basepri"] +# riscv-clic-backend = ["rtic-macros/riscv-clic"] +# riscv-ch32-backend = ["rtic-macros/riscv-ch32"] +# riscv-esp32c3-backend = ["rtic-macros/riscv-esp32c3"] + +# needed for testing +rtic-uitestv7 = ["thumbv7-backend", "rtic-macros/cortex-m-basepri"] +rtic-uitestv6 = ["thumbv6-backend", "rtic-macros/cortex-m-source-masking"] +test-critical-section = ["cortex-m/critical-section-single-core", "rtic-monotonics/systick-100hz"] + +# [[example]] +# name = "pool" +# required-features = ["test-critical-section"] diff --git a/rtic/build.rs b/rtic/build.rs new file mode 100644 index 0000000..c88175d --- /dev/null +++ b/rtic/build.rs @@ -0,0 +1,24 @@ +use std::env; + +fn main() { + let target = env::var("TARGET").unwrap(); + + // These targets all have know support for the BASEPRI register. + if target.starts_with("thumbv7m") + | target.starts_with("thumbv7em") + | target.starts_with("thumbv8m.main") + { + println!("cargo:rustc-cfg=feature=\"cortex-m-basepri\""); + } else if target.starts_with("thumbv6m") | target.starts_with("thumbv8m.base") { + println!("cargo:rustc-cfg=feature=\"cortex-m-source-masking\""); + } else if target.starts_with("riscv32i") { + panic!("No RISC-V support yet."); + + // TODO: Add feature here for risc-v targets + // println!("cargo:rustc-cfg=feature=\"riscv\""); + } else if target.starts_with("thumb") || target.starts_with("riscv32") { + panic!("Unknown target '{target}'. Need to update logic in build.rs."); + } + + println!("cargo:rerun-if-changed=build.rs"); +} diff --git a/rtic/ci/expected/async-channel-done.run b/rtic/ci/expected/async-channel-done.run new file mode 100644 index 0000000..525962a --- /dev/null +++ b/rtic/ci/expected/async-channel-done.run @@ -0,0 +1,9 @@ +Sender 1 sending: 1 +Sender 1 done +Sender 2 sending: 2 +Sender 3 sending: 3 +Receiver got: 1 +Sender 2 done +Receiver got: 2 +Sender 3 done +Receiver got: 3 diff --git a/rtic/ci/expected/async-channel-no-receiver.run b/rtic/ci/expected/async-channel-no-receiver.run new file mode 100644 index 0000000..34624e1 --- /dev/null +++ b/rtic/ci/expected/async-channel-no-receiver.run @@ -0,0 +1 @@ +Sender 1 sending: 1 Err(NoReceiver(1)) diff --git a/rtic/ci/expected/async-channel-no-sender.run b/rtic/ci/expected/async-channel-no-sender.run new file mode 100644 index 0000000..237f2f1 --- /dev/null +++ b/rtic/ci/expected/async-channel-no-sender.run @@ -0,0 +1 @@ +Receiver got: Err(NoSender) diff --git a/rtic/ci/expected/async-channel-try.run b/rtic/ci/expected/async-channel-try.run new file mode 100644 index 0000000..c3a4092 --- /dev/null +++ b/rtic/ci/expected/async-channel-try.run @@ -0,0 +1,2 @@ +Sender 1 sending: 1 +Sender 1 try sending: 2 Err(Full(2)) diff --git a/rtic/ci/expected/async-channel.run b/rtic/ci/expected/async-channel.run new file mode 100644 index 0000000..4e313a1 --- /dev/null +++ b/rtic/ci/expected/async-channel.run @@ -0,0 +1,6 @@ +Sender 1 sending: 1 +Sender 2 sending: 2 +Sender 3 sending: 3 +Receiver got: 1 +Receiver got: 2 +Receiver got: 3 diff --git a/rtic/ci/expected/async-delay.run b/rtic/ci/expected/async-delay.run new file mode 100644 index 0000000..61852ab --- /dev/null +++ b/rtic/ci/expected/async-delay.run @@ -0,0 +1,7 @@ +init +hello from bar +hello from baz +hello from foo +bye from foo +bye from bar +bye from baz diff --git a/rtic/ci/expected/async-infinite-loop.run b/rtic/ci/expected/async-infinite-loop.run new file mode 100644 index 0000000..f9fd4e4 --- /dev/null +++ b/rtic/ci/expected/async-infinite-loop.run @@ -0,0 +1,6 @@ +init +hello from async 0 +hello from async 1 +hello from async 2 +hello from async 3 +hello from async 4 diff --git a/rtic/ci/expected/async-task-multiple-prios.run b/rtic/ci/expected/async-task-multiple-prios.run new file mode 100644 index 0000000..0b42df0 --- /dev/null +++ b/rtic/ci/expected/async-task-multiple-prios.run @@ -0,0 +1,6 @@ +init +hello from async 3 a 1 +hello from async 4 a 2 +hello from async 1 a 3 +hello from async 2 a 4 +idle diff --git a/rtic/ci/expected/async-task.run b/rtic/ci/expected/async-task.run new file mode 100644 index 0000000..1f93a4c --- /dev/null +++ b/rtic/ci/expected/async-task.run @@ -0,0 +1,5 @@ +init +hello from async2 +hello from async +hello from async with args a: 1, b: 2 +idle diff --git a/rtic/ci/expected/async-timeout.run b/rtic/ci/expected/async-timeout.run new file mode 100644 index 0000000..dea8e5d --- /dev/null +++ b/rtic/ci/expected/async-timeout.run @@ -0,0 +1,16 @@ +init +the hal takes a duration of Duration { ticks: 45 } +timeout +the hal takes a duration of Duration { ticks: 45 } +hal returned 5 +the hal takes a duration of Duration { ticks: 45 } +hal returned 5 +now is Instant { ticks: 210 }, timeout at Instant { ticks: 260 } +the hal takes a duration of Duration { ticks: 35 } +hal returned 5 at time Instant { ticks: 245 } +now is Instant { ticks: 310 }, timeout at Instant { ticks: 360 } +the hal takes a duration of Duration { ticks: 45 } +hal returned 5 at time Instant { ticks: 355 } +now is Instant { ticks: 410 }, timeout at Instant { ticks: 460 } +the hal takes a duration of Duration { ticks: 55 } +timeout diff --git a/rtic/ci/expected/big-struct-opt.run b/rtic/ci/expected/big-struct-opt.run new file mode 100644 index 0000000..7fdef35 --- /dev/null +++ b/rtic/ci/expected/big-struct-opt.run @@ -0,0 +1,3 @@ +async_task data:[22, 22, 22, 22, 22] +uart0 data:[22, 22, 22, 22, 22] +idle diff --git a/ci/expected/binds.run b/rtic/ci/expected/binds.run index f84cff0..f84cff0 100644 --- a/ci/expected/binds.run +++ b/rtic/ci/expected/binds.run diff --git a/ci/expected/cancel-reschedule.run b/rtic/ci/expected/cancel-reschedule.run index 5a94752..5a94752 100644 --- a/ci/expected/cancel-reschedule.run +++ b/rtic/ci/expected/cancel-reschedule.run diff --git a/ci/expected/capacity.run b/rtic/ci/expected/capacity.run index f96815d..f96815d 100644 --- a/ci/expected/capacity.run +++ b/rtic/ci/expected/capacity.run diff --git a/ci/expected/cfg-whole-task.run b/rtic/ci/expected/cfg-whole-task.run index e69de29..e69de29 100644 --- a/ci/expected/cfg-whole-task.run +++ b/rtic/ci/expected/cfg-whole-task.run diff --git a/rtic/ci/expected/common.run b/rtic/ci/expected/common.run new file mode 100644 index 0000000..4f1d350 --- /dev/null +++ b/rtic/ci/expected/common.run @@ -0,0 +1,3 @@ +bar: local_to_bar = 1 +foo: local_to_foo = 1 +idle: local_to_idle = 1 diff --git a/ci/expected/complex.run b/rtic/ci/expected/complex.run index 5df884d..5df884d 100644 --- a/ci/expected/complex.run +++ b/rtic/ci/expected/complex.run diff --git a/ci/expected/declared_locals.run b/rtic/ci/expected/declared_locals.run index e69de29..e69de29 100644 --- a/ci/expected/declared_locals.run +++ b/rtic/ci/expected/declared_locals.run diff --git a/rtic/ci/expected/destructure.run b/rtic/ci/expected/destructure.run new file mode 100644 index 0000000..25a4b1b --- /dev/null +++ b/rtic/ci/expected/destructure.run @@ -0,0 +1,2 @@ +bar: a = 0, b = 1, c = 2 +foo: a = 0, b = 1, c = 2 diff --git a/ci/expected/extern_binds.run b/rtic/ci/expected/extern_binds.run index 9d925d5..9d925d5 100644 --- a/ci/expected/extern_binds.run +++ b/rtic/ci/expected/extern_binds.run diff --git a/ci/expected/ramfunc.run b/rtic/ci/expected/extern_spawn.run index 257cc56..257cc56 100644 --- a/ci/expected/ramfunc.run +++ b/rtic/ci/expected/extern_spawn.run diff --git a/ci/expected/generics.run b/rtic/ci/expected/generics.run index fb31731..fb31731 100644 --- a/ci/expected/generics.run +++ b/rtic/ci/expected/generics.run diff --git a/ci/expected/hardware.run b/rtic/ci/expected/hardware.run index ef00864..ef00864 100644 --- a/ci/expected/hardware.run +++ b/rtic/ci/expected/hardware.run diff --git a/ci/expected/idle-wfi.run b/rtic/ci/expected/idle-wfi.run index 4307776..4307776 100644 --- a/ci/expected/idle-wfi.run +++ b/rtic/ci/expected/idle-wfi.run diff --git a/ci/expected/idle.run b/rtic/ci/expected/idle.run index 4307776..4307776 100644 --- a/ci/expected/idle.run +++ b/rtic/ci/expected/idle.run diff --git a/ci/expected/init.run b/rtic/ci/expected/init.run index b1b7161..b1b7161 100644 --- a/ci/expected/init.run +++ b/rtic/ci/expected/init.run diff --git a/ci/expected/locals.run b/rtic/ci/expected/locals.run index bf1d207..4f1d350 100644 --- a/ci/expected/locals.run +++ b/rtic/ci/expected/locals.run @@ -1,3 +1,3 @@ -foo: local_to_foo = 1 bar: local_to_bar = 1 +foo: local_to_foo = 1 idle: local_to_idle = 1 diff --git a/ci/expected/lock-free.run b/rtic/ci/expected/lock-free.run index 18de0ec..18de0ec 100644 --- a/ci/expected/lock-free.run +++ b/rtic/ci/expected/lock-free.run diff --git a/ci/expected/lock.run b/rtic/ci/expected/lock.run index a987b37..a987b37 100644 --- a/ci/expected/lock.run +++ b/rtic/ci/expected/lock.run diff --git a/ci/expected/message.run b/rtic/ci/expected/message.run index 11814db..11814db 100644 --- a/ci/expected/message.run +++ b/rtic/ci/expected/message.run diff --git a/ci/expected/multilock.run b/rtic/ci/expected/multilock.run index dd8c1f2..dd8c1f2 100644 --- a/ci/expected/multilock.run +++ b/rtic/ci/expected/multilock.run diff --git a/rtic/ci/expected/not-sync.run b/rtic/ci/expected/not-sync.run new file mode 100644 index 0000000..cd91476 --- /dev/null +++ b/rtic/ci/expected/not-sync.run @@ -0,0 +1,3 @@ +init +bar a 13 +foo a 13 diff --git a/ci/expected/only-shared-access.run b/rtic/ci/expected/only-shared-access.run index dcc73e6..dcc73e6 100644 --- a/ci/expected/only-shared-access.run +++ b/rtic/ci/expected/only-shared-access.run diff --git a/rtic/ci/expected/periodic-at.run b/rtic/ci/expected/periodic-at.run new file mode 100644 index 0000000..bf5bb06 --- /dev/null +++ b/rtic/ci/expected/periodic-at.run @@ -0,0 +1,4 @@ +foo Instant { ticks: 0 } +foo Instant { ticks: 10 } +foo Instant { ticks: 20 } +foo Instant { ticks: 30 } diff --git a/rtic/ci/expected/periodic-at2.run b/rtic/ci/expected/periodic-at2.run new file mode 100644 index 0000000..6e56421 --- /dev/null +++ b/rtic/ci/expected/periodic-at2.run @@ -0,0 +1,7 @@ +foo Instant { ticks: 0 } +bar Instant { ticks: 10 } +foo Instant { ticks: 30 } +bar Instant { ticks: 40 } +foo Instant { ticks: 60 } +bar Instant { ticks: 70 } +foo Instant { ticks: 90 } diff --git a/ci/expected/periodic.run b/rtic/ci/expected/periodic.run index a1f8944..a1f8944 100644 --- a/ci/expected/periodic.run +++ b/rtic/ci/expected/periodic.run diff --git a/ci/expected/peripherals-taken.run b/rtic/ci/expected/peripherals-taken.run index e69de29..e69de29 100644 --- a/ci/expected/peripherals-taken.run +++ b/rtic/ci/expected/peripherals-taken.run diff --git a/ci/expected/pool.run b/rtic/ci/expected/pool.run index e69de29..e69de29 100644 --- a/ci/expected/pool.run +++ b/rtic/ci/expected/pool.run diff --git a/ci/expected/preempt.run b/rtic/ci/expected/preempt.run index 932b2b3..932b2b3 100644 --- a/ci/expected/preempt.run +++ b/rtic/ci/expected/preempt.run diff --git a/rtic/ci/expected/ramfunc.run b/rtic/ci/expected/ramfunc.run new file mode 100644 index 0000000..257cc56 --- /dev/null +++ b/rtic/ci/expected/ramfunc.run @@ -0,0 +1 @@ +foo diff --git a/ci/expected/ramfunc.run.grep.bar b/rtic/ci/expected/ramfunc.run.grep.bar index 33e002f..33e002f 100644 --- a/ci/expected/ramfunc.run.grep.bar +++ b/rtic/ci/expected/ramfunc.run.grep.bar diff --git a/ci/expected/ramfunc.run.grep.foo b/rtic/ci/expected/ramfunc.run.grep.foo index 44e8822..44e8822 100644 --- a/ci/expected/ramfunc.run.grep.foo +++ b/rtic/ci/expected/ramfunc.run.grep.foo diff --git a/ci/expected/resource-user-struct.run b/rtic/ci/expected/resource-user-struct.run index a587a94..a587a94 100644 --- a/ci/expected/resource-user-struct.run +++ b/rtic/ci/expected/resource-user-struct.run diff --git a/ci/expected/schedule.run b/rtic/ci/expected/schedule.run index 1dbd445..1dbd445 100644 --- a/ci/expected/schedule.run +++ b/rtic/ci/expected/schedule.run diff --git a/ci/expected/shared.run b/rtic/ci/expected/shared.run index 6d3d3e4..6d3d3e4 100644 --- a/ci/expected/shared.run +++ b/rtic/ci/expected/shared.run diff --git a/ci/expected/smallest.run b/rtic/ci/expected/smallest.run index e69de29..e69de29 100644 --- a/ci/expected/smallest.run +++ b/rtic/ci/expected/smallest.run diff --git a/ci/expected/spawn.run b/rtic/ci/expected/spawn.run index 240cd18..240cd18 100644 --- a/ci/expected/spawn.run +++ b/rtic/ci/expected/spawn.run diff --git a/rtic/ci/expected/spawn_arguments.run b/rtic/ci/expected/spawn_arguments.run new file mode 100644 index 0000000..9085e13 --- /dev/null +++ b/rtic/ci/expected/spawn_arguments.run @@ -0,0 +1 @@ +foo 1, 1 diff --git a/rtic/ci/expected/spawn_err.run b/rtic/ci/expected/spawn_err.run new file mode 100644 index 0000000..97c4112 --- /dev/null +++ b/rtic/ci/expected/spawn_err.run @@ -0,0 +1,3 @@ +init +Cannot spawn a spawned (running) task! +foo diff --git a/rtic/ci/expected/spawn_loop.run b/rtic/ci/expected/spawn_loop.run new file mode 100644 index 0000000..ee6e1e3 --- /dev/null +++ b/rtic/ci/expected/spawn_loop.run @@ -0,0 +1,7 @@ +init +foo +idle +foo +idle +foo +idle diff --git a/ci/expected/static.run b/rtic/ci/expected/static.run index 3d3f46f..3d3f46f 100644 --- a/ci/expected/static.run +++ b/rtic/ci/expected/static.run diff --git a/ci/expected/t-binds.run b/rtic/ci/expected/t-binds.run index e69de29..e69de29 100644 --- a/ci/expected/t-binds.run +++ b/rtic/ci/expected/t-binds.run diff --git a/ci/expected/t-cfg-resources.run b/rtic/ci/expected/t-cfg-resources.run index e69de29..e69de29 100644 --- a/ci/expected/t-cfg-resources.run +++ b/rtic/ci/expected/t-cfg-resources.run diff --git a/ci/expected/t-htask-main.run b/rtic/ci/expected/t-htask-main.run index e69de29..e69de29 100644 --- a/ci/expected/t-htask-main.run +++ b/rtic/ci/expected/t-htask-main.run diff --git a/ci/expected/t-idle-main.run b/rtic/ci/expected/t-idle-main.run index e69de29..e69de29 100644 --- a/ci/expected/t-idle-main.run +++ b/rtic/ci/expected/t-idle-main.run diff --git a/ci/expected/t-late-not-send.run b/rtic/ci/expected/t-late-not-send.run index e69de29..e69de29 100644 --- a/ci/expected/t-late-not-send.run +++ b/rtic/ci/expected/t-late-not-send.run diff --git a/ci/expected/t-schedule.run b/rtic/ci/expected/t-schedule.run index e69de29..e69de29 100644 --- a/ci/expected/t-schedule.run +++ b/rtic/ci/expected/t-schedule.run diff --git a/ci/expected/t-spawn.run b/rtic/ci/expected/t-spawn.run index e69de29..e69de29 100644 --- a/ci/expected/t-spawn.run +++ b/rtic/ci/expected/t-spawn.run diff --git a/ci/expected/task.run b/rtic/ci/expected/task.run index de45dce..de45dce 100644 --- a/ci/expected/task.run +++ b/rtic/ci/expected/task.run diff --git a/rtic/ci/expected/zero-prio-task.run b/rtic/ci/expected/zero-prio-task.run new file mode 100644 index 0000000..123b0f2 --- /dev/null +++ b/rtic/ci/expected/zero-prio-task.run @@ -0,0 +1,3 @@ +init +hello from async +hello from async2 diff --git a/rtic/examples/async-channel-done.rs b/rtic/examples/async-channel-done.rs new file mode 100644 index 0000000..62ed656 --- /dev/null +++ b/rtic/examples/async-channel-done.rs @@ -0,0 +1,66 @@ +//! examples/async-channel-done.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + use rtic_sync::{channel::*, make_channel}; + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + const CAPACITY: usize = 1; + #[init] + fn init(_: init::Context) -> (Shared, Local) { + let (s, r) = make_channel!(u32, CAPACITY); + + receiver::spawn(r).unwrap(); + sender1::spawn(s.clone()).unwrap(); + sender2::spawn(s.clone()).unwrap(); + sender3::spawn(s).unwrap(); + + (Shared {}, Local {}) + } + + #[task] + async fn receiver(_c: receiver::Context, mut receiver: Receiver<'static, u32, CAPACITY>) { + while let Ok(val) = receiver.recv().await { + hprintln!("Receiver got: {}", val); + if val == 3 { + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + } + } + } + + #[task] + async fn sender1(_c: sender1::Context, mut sender: Sender<'static, u32, CAPACITY>) { + hprintln!("Sender 1 sending: 1"); + sender.send(1).await.unwrap(); + hprintln!("Sender 1 done"); + } + + #[task] + async fn sender2(_c: sender2::Context, mut sender: Sender<'static, u32, CAPACITY>) { + hprintln!("Sender 2 sending: 2"); + sender.send(2).await.unwrap(); + hprintln!("Sender 2 done"); + } + + #[task] + async fn sender3(_c: sender3::Context, mut sender: Sender<'static, u32, CAPACITY>) { + hprintln!("Sender 3 sending: 3"); + sender.send(3).await.unwrap(); + hprintln!("Sender 3 done"); + } +} diff --git a/rtic/examples/async-channel-no-receiver.rs b/rtic/examples/async-channel-no-receiver.rs new file mode 100644 index 0000000..ab590e6 --- /dev/null +++ b/rtic/examples/async-channel-no-receiver.rs @@ -0,0 +1,38 @@ +//! examples/async-channel-no-receiver.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + use rtic_sync::{channel::*, make_channel}; + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + const CAPACITY: usize = 1; + #[init] + fn init(_: init::Context) -> (Shared, Local) { + let (s, _r) = make_channel!(u32, CAPACITY); + + sender1::spawn(s.clone()).unwrap(); + + (Shared {}, Local {}) + } + + #[task] + async fn sender1(_c: sender1::Context, mut sender: Sender<'static, u32, CAPACITY>) { + hprintln!("Sender 1 sending: 1 {:?}", sender.send(1).await); + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + } +} diff --git a/rtic/examples/async-channel-no-sender.rs b/rtic/examples/async-channel-no-sender.rs new file mode 100644 index 0000000..852dc1d --- /dev/null +++ b/rtic/examples/async-channel-no-sender.rs @@ -0,0 +1,39 @@ +//! examples/async-channel-no-sender.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + use rtic_sync::{channel::*, make_channel}; + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + const CAPACITY: usize = 1; + #[init] + fn init(_: init::Context) -> (Shared, Local) { + let (_s, r) = make_channel!(u32, CAPACITY); + + receiver::spawn(r).unwrap(); + + (Shared {}, Local {}) + } + + #[task] + async fn receiver(_c: receiver::Context, mut receiver: Receiver<'static, u32, CAPACITY>) { + hprintln!("Receiver got: {:?}", receiver.recv().await); + + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + } +} diff --git a/rtic/examples/async-channel-try.rs b/rtic/examples/async-channel-try.rs new file mode 100644 index 0000000..54a51d9 --- /dev/null +++ b/rtic/examples/async-channel-try.rs @@ -0,0 +1,48 @@ +//! examples/async-channel-try.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + use rtic_sync::{channel::*, make_channel}; + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + const CAPACITY: usize = 1; + #[init] + fn init(_: init::Context) -> (Shared, Local) { + let (s, r) = make_channel!(u32, CAPACITY); + + receiver::spawn(r).unwrap(); + sender1::spawn(s.clone()).unwrap(); + + (Shared {}, Local {}) + } + + #[task] + async fn receiver(_c: receiver::Context, mut receiver: Receiver<'static, u32, CAPACITY>) { + while let Ok(val) = receiver.recv().await { + hprintln!("Receiver got: {}", val); + } + } + + #[task] + async fn sender1(_c: sender1::Context, mut sender: Sender<'static, u32, CAPACITY>) { + hprintln!("Sender 1 sending: 1"); + sender.send(1).await.unwrap(); + hprintln!("Sender 1 try sending: 2 {:?}", sender.try_send(2)); + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + } +} diff --git a/rtic/examples/async-channel.rs b/rtic/examples/async-channel.rs new file mode 100644 index 0000000..9798901 --- /dev/null +++ b/rtic/examples/async-channel.rs @@ -0,0 +1,63 @@ +//! examples/async-channel.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + use rtic_sync::{channel::*, make_channel}; + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + const CAPACITY: usize = 5; + #[init] + fn init(_: init::Context) -> (Shared, Local) { + let (s, r) = make_channel!(u32, CAPACITY); + + receiver::spawn(r).unwrap(); + sender1::spawn(s.clone()).unwrap(); + sender2::spawn(s.clone()).unwrap(); + sender3::spawn(s).unwrap(); + + (Shared {}, Local {}) + } + + #[task] + async fn receiver(_c: receiver::Context, mut receiver: Receiver<'static, u32, CAPACITY>) { + while let Ok(val) = receiver.recv().await { + hprintln!("Receiver got: {}", val); + if val == 3 { + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + } + } + } + + #[task] + async fn sender1(_c: sender1::Context, mut sender: Sender<'static, u32, CAPACITY>) { + hprintln!("Sender 1 sending: 1"); + sender.send(1).await.unwrap(); + } + + #[task] + async fn sender2(_c: sender2::Context, mut sender: Sender<'static, u32, CAPACITY>) { + hprintln!("Sender 2 sending: 2"); + sender.send(2).await.unwrap(); + } + + #[task] + async fn sender3(_c: sender3::Context, mut sender: Sender<'static, u32, CAPACITY>) { + hprintln!("Sender 3 sending: 3"); + sender.send(3).await.unwrap(); + } +} diff --git a/rtic/examples/async-delay.rs b/rtic/examples/async-delay.rs new file mode 100644 index 0000000..c163a3e --- /dev/null +++ b/rtic/examples/async-delay.rs @@ -0,0 +1,69 @@ +//! examples/async-delay.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + use rtic_monotonics::systick::*; + + rtic_monotonics::make_systick_handler!(); + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(cx: init::Context) -> (Shared, Local) { + hprintln!("init"); + + Systick::start(cx.core.SYST, 12_000_000); + + foo::spawn().ok(); + bar::spawn().ok(); + baz::spawn().ok(); + + (Shared {}, Local {}) + } + + #[idle] + fn idle(_: idle::Context) -> ! { + // debug::exit(debug::EXIT_SUCCESS); + loop { + // hprintln!("idle"); + cortex_m::asm::wfi(); // put the MCU in sleep mode until interrupt occurs + } + } + + #[task] + async fn foo(_cx: foo::Context) { + hprintln!("hello from foo"); + Systick::delay(100.millis()).await; + hprintln!("bye from foo"); + } + + #[task] + async fn bar(_cx: bar::Context) { + hprintln!("hello from bar"); + Systick::delay(200.millis()).await; + hprintln!("bye from bar"); + } + + #[task] + async fn baz(_cx: baz::Context) { + hprintln!("hello from baz"); + Systick::delay(300.millis()).await; + hprintln!("bye from baz"); + + debug::exit(debug::EXIT_SUCCESS); + } +} diff --git a/rtic/examples/async-task-multiple-prios.rs b/rtic/examples/async-task-multiple-prios.rs new file mode 100644 index 0000000..88f4cf4 --- /dev/null +++ b/rtic/examples/async-task-multiple-prios.rs @@ -0,0 +1,94 @@ +//! examples/async-task-multiple-prios.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +// NOTES: +// +// - Async tasks cannot have `#[lock_free]` resources, as they can interleave and each async +// task can have a mutable reference stored. +// - Spawning an async task equates to it being polled once. + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0])] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + + #[shared] + struct Shared { + a: u32, + b: u32, + } + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) { + hprintln!("init"); + + async_task1::spawn().ok(); + async_task2::spawn().ok(); + async_task3::spawn().ok(); + async_task4::spawn().ok(); + + (Shared { a: 0, b: 0 }, Local {}) + } + + #[idle] + fn idle(_: idle::Context) -> ! { + loop { + hprintln!("idle"); + debug::exit(debug::EXIT_SUCCESS); + } + } + + #[task(priority = 1, shared = [a, b])] + async fn async_task1(mut cx: async_task1::Context) { + hprintln!( + "hello from async 1 a {}", + cx.shared.a.lock(|a| { + *a += 1; + *a + }) + ); + } + + #[task(priority = 1, shared = [a, b])] + async fn async_task2(mut cx: async_task2::Context) { + hprintln!( + "hello from async 2 a {}", + cx.shared.a.lock(|a| { + *a += 1; + *a + }) + ); + } + + #[task(priority = 2, shared = [a, b])] + async fn async_task3(mut cx: async_task3::Context) { + hprintln!( + "hello from async 3 a {}", + cx.shared.a.lock(|a| { + *a += 1; + *a + }) + ); + } + + #[task(priority = 2, shared = [a, b])] + async fn async_task4(mut cx: async_task4::Context) { + hprintln!( + "hello from async 4 a {}", + cx.shared.a.lock(|a| { + *a += 1; + *a + }) + ); + } +} diff --git a/rtic/examples/async-task.rs b/rtic/examples/async-task.rs new file mode 100644 index 0000000..b70151a --- /dev/null +++ b/rtic/examples/async-task.rs @@ -0,0 +1,72 @@ +//! examples/async-task.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +// NOTES: +// +// - Async tasks cannot have `#[lock_free]` resources, as they can interleave and each async +// task can have a mutable reference stored. +// - Spawning an async task equates to it being polled once. + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + + #[shared] + struct Shared { + a: u32, + } + + #[local] + struct Local {} + + #[init] + fn init(_cx: init::Context) -> (Shared, Local) { + hprintln!("init"); + + async_task::spawn().unwrap(); + async_task_args::spawn(1, 2).unwrap(); + async_task2::spawn().unwrap(); + + (Shared { a: 0 }, Local {}) + } + + #[idle(shared = [a])] + fn idle(_: idle::Context) -> ! { + loop { + hprintln!("idle"); + debug::exit(debug::EXIT_SUCCESS); + cortex_m::asm::wfi(); // put the MCU in sleep mode until interrupt occurs + } + } + + #[task(binds = UART1, shared = [a])] + fn hw_task(cx: hw_task::Context) { + let hw_task::SharedResources { a: _, .. } = cx.shared; + hprintln!("hello from hw"); + } + + #[task(shared = [a])] + async fn async_task(cx: async_task::Context) { + let async_task::SharedResources { a: _, .. } = cx.shared; + hprintln!("hello from async"); + } + + #[task] + async fn async_task_args(_cx: async_task_args::Context, a: u32, b: i32) { + hprintln!("hello from async with args a: {}, b: {}", a, b); + } + + #[task(priority = 2, shared = [a])] + async fn async_task2(cx: async_task2::Context) { + let async_task2::SharedResources { a: _, .. } = cx.shared; + hprintln!("hello from async2"); + } +} diff --git a/rtic/examples/async-timeout.rs b/rtic/examples/async-timeout.rs new file mode 100644 index 0000000..384c888 --- /dev/null +++ b/rtic/examples/async-timeout.rs @@ -0,0 +1,90 @@ +//! examples/async-timeout.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use cortex_m_semihosting::{debug, hprintln}; +use panic_semihosting as _; +use rtic_monotonics::systick::*; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)] +mod app { + use super::*; + use futures::{future::FutureExt, select_biased}; + use rtic_monotonics::Monotonic; + + rtic_monotonics::make_systick_handler!(); + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(cx: init::Context) -> (Shared, Local) { + hprintln!("init"); + + Systick::start(cx.core.SYST, 12_000_000); + + foo::spawn().ok(); + + (Shared {}, Local {}) + } + + #[task] + async fn foo(_cx: foo::Context) { + // Call hal with short relative timeout using `select_biased` + select_biased! { + v = hal_get(1).fuse() => hprintln!("hal returned {}", v), + _ = Systick::delay(200.millis()).fuse() => hprintln!("timeout", ), // this will finish first + } + + // Call hal with long relative timeout using `select_biased` + select_biased! { + v = hal_get(1).fuse() => hprintln!("hal returned {}", v), // hal finish first + _ = Systick::delay(1000.millis()).fuse() => hprintln!("timeout", ), + } + + // Call hal with long relative timeout using monotonic `timeout_after` + match Systick::timeout_after(1000.millis(), hal_get(1)).await { + Ok(v) => hprintln!("hal returned {}", v), + _ => hprintln!("timeout"), + } + + // get the current time instance + let mut instant = Systick::now(); + + // do this 3 times + for n in 0..3 { + // absolute point in time without drift + instant += 1000.millis(); + Systick::delay_until(instant).await; + + // absolute point it time for timeout + let timeout = instant + 500.millis(); + hprintln!("now is {:?}, timeout at {:?}", Systick::now(), timeout); + + match Systick::timeout_at(timeout, hal_get(n)).await { + Ok(v) => hprintln!("hal returned {} at time {:?}", v, Systick::now()), + _ => hprintln!("timeout"), + } + } + + debug::exit(debug::EXIT_SUCCESS); + } +} + +// Emulate some hal +async fn hal_get(n: u32) -> u32 { + // emulate some delay time dependent on n + let d = 350.millis() + n * 100.millis(); + hprintln!("the hal takes a duration of {:?}", d); + Systick::delay(d).await; + // emulate some return value + 5 +} diff --git a/examples/big-struct-opt.rs b/rtic/examples/big-struct-opt.rs index bbc2535..4326247 100644 --- a/examples/big-struct-opt.rs +++ b/rtic/examples/big-struct-opt.rs @@ -5,6 +5,9 @@ #![no_main] #![no_std] +#![deny(warnings)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -20,11 +23,12 @@ impl BigStruct { } } -#[rtic::app(device = lm3s6965)] +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] mod app { use super::BigStruct; use core::mem::MaybeUninit; - use cortex_m_semihosting::debug; + use cortex_m_semihosting::{debug, hprintln}; + use lm3s6965::Interrupt; #[shared] struct Shared { @@ -35,25 +39,43 @@ mod app { struct Local {} #[init(local = [bs: MaybeUninit<BigStruct> = MaybeUninit::uninit()])] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(cx: init::Context) -> (Shared, Local) { let big_struct = unsafe { // write directly into the static storage cx.local.bs.as_mut_ptr().write(BigStruct::new()); &mut *cx.local.bs.as_mut_ptr() }; - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - + rtic::pend(Interrupt::UART0); + async_task::spawn().unwrap(); ( Shared { // assign the reference so we can use the resource big_struct, }, Local {}, - init::Monotonics(), ) } + #[idle] + fn idle(_: idle::Context) -> ! { + loop { + hprintln!("idle"); + debug::exit(debug::EXIT_SUCCESS); + } + } + #[task(binds = UART0, shared = [big_struct])] - fn task(_: task::Context) {} + fn uart0(mut cx: uart0::Context) { + cx.shared + .big_struct + .lock(|b| hprintln!("uart0 data:{:?}", &b.data[0..5])); + } + + #[task(shared = [big_struct], priority = 2)] + async fn async_task(mut cx: async_task::Context) { + cx.shared + .big_struct + .lock(|b| hprintln!("async_task data:{:?}", &b.data[0..5])); + } } diff --git a/examples/binds.rs b/rtic/examples/binds.rs index 1b0c8c5..b101d54 100644 --- a/examples/binds.rs +++ b/rtic/examples/binds.rs @@ -1,10 +1,10 @@ //! examples/binds.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -21,12 +21,12 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { rtic::pend(Interrupt::UART0); hprintln!("init"); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[idle] @@ -36,8 +36,6 @@ mod app { rtic::pend(Interrupt::UART0); loop { - // Exit moved after nop to ensure that rtic::pend gets - // to run before exiting cortex_m::asm::nop(); debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator } diff --git a/rtic/examples/common.rs b/rtic/examples/common.rs new file mode 100644 index 0000000..ed6cb7d --- /dev/null +++ b/rtic/examples/common.rs @@ -0,0 +1,87 @@ +//! examples/common.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [UART0, UART1])] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + + #[shared] + struct Shared {} + + #[local] + struct Local { + local_to_foo: i64, + local_to_bar: i64, + local_to_idle: i64, + } + + // `#[init]` cannot access locals from the `#[local]` struct as they are initialized here. + #[init] + fn init(_: init::Context) -> (Shared, Local) { + foo::spawn().unwrap(); + bar::spawn().unwrap(); + + ( + Shared {}, + // initial values for the `#[local]` resources + Local { + local_to_foo: 0, + local_to_bar: 0, + local_to_idle: 0, + }, + ) + } + + // `local_to_idle` can only be accessed from this context + #[idle(local = [local_to_idle])] + fn idle(cx: idle::Context) -> ! { + let local_to_idle = cx.local.local_to_idle; + *local_to_idle += 1; + + hprintln!("idle: local_to_idle = {}", local_to_idle); + + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + + // error: no `local_to_foo` field in `idle::LocalResources` + // _cx.local.local_to_foo += 1; + + // error: no `local_to_bar` field in `idle::LocalResources` + // _cx.local.local_to_bar += 1; + + loop { + cortex_m::asm::nop(); + } + } + + // `local_to_foo` can only be accessed from this context + #[task(local = [local_to_foo])] + async fn foo(cx: foo::Context) { + let local_to_foo = cx.local.local_to_foo; + *local_to_foo += 1; + + // error: no `local_to_bar` field in `foo::LocalResources` + // cx.local.local_to_bar += 1; + + hprintln!("foo: local_to_foo = {}", local_to_foo); + } + + // `local_to_bar` can only be accessed from this context + #[task(local = [local_to_bar])] + async fn bar(cx: bar::Context) { + let local_to_bar = cx.local.local_to_bar; + *local_to_bar += 1; + + // error: no `local_to_foo` field in `bar::LocalResources` + // cx.local.local_to_foo += 1; + + hprintln!("bar: local_to_bar = {}", local_to_bar); + } +} diff --git a/examples/complex.rs b/rtic/examples/complex.rs index 73df025..a4fe659 100644 --- a/examples/complex.rs +++ b/rtic/examples/complex.rs @@ -1,10 +1,10 @@ //! examples/complex.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -25,7 +25,7 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { hprintln!("init"); ( @@ -35,7 +35,6 @@ mod app { s4: 0, }, Local {}, - init::Monotonics(), ) } diff --git a/examples/declared_locals.rs b/rtic/examples/declared_locals.rs index cb62149..b1bb9f4 100644 --- a/examples/declared_locals.rs +++ b/rtic/examples/declared_locals.rs @@ -1,14 +1,14 @@ //! examples/declared_locals.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; -#[rtic::app(device = lm3s6965, dispatchers = [UART0])] +#[rtic::app(device = lm3s6965)] mod app { use cortex_m_semihosting::debug; @@ -19,13 +19,13 @@ mod app { struct Local {} #[init(local = [a: u32 = 0])] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(cx: init::Context) -> (Shared, Local) { // Locals in `#[init]` have 'static lifetime let _a: &'static mut u32 = cx.local.a; debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[idle(local = [a: u32 = 0])] @@ -36,7 +36,7 @@ mod app { loop {} } - #[task(local = [a: u32 = 0])] + #[task(binds = UART0, local = [a: u32 = 0])] fn foo(cx: foo::Context) { // Locals in `#[task]`s have a local lifetime let _a: &mut u32 = cx.local.a; diff --git a/examples/destructure.rs b/rtic/examples/destructure.rs index 70b0dd7..b5d564b 100644 --- a/examples/destructure.rs +++ b/rtic/examples/destructure.rs @@ -1,10 +1,11 @@ //! examples/destructure.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -23,11 +24,11 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { foo::spawn().unwrap(); bar::spawn().unwrap(); - (Shared { a: 0, b: 0, c: 0 }, Local {}, init::Monotonics()) + (Shared { a: 0, b: 1, c: 2 }, Local {}) } #[idle] @@ -38,7 +39,7 @@ mod app { // Direct destructure #[task(shared = [&a, &b, &c])] - fn foo(cx: foo::Context) { + async fn foo(cx: foo::Context) { let a = cx.shared.a; let b = cx.shared.b; let c = cx.shared.c; @@ -48,8 +49,8 @@ mod app { // De-structure-ing syntax #[task(shared = [&a, &b, &c])] - fn bar(cx: bar::Context) { - let bar::SharedResources { a, b, c } = cx.shared; + async fn bar(cx: bar::Context) { + let bar::SharedResources { a, b, c, .. } = cx.shared; hprintln!("bar: a = {}, b = {}, c = {}", a, b, c); } diff --git a/examples/extern_binds.rs b/rtic/examples/extern_binds.rs index bfc85cf..f03a8a9 100644 --- a/examples/extern_binds.rs +++ b/rtic/examples/extern_binds.rs @@ -1,10 +1,10 @@ //! examples/extern_binds.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use cortex_m_semihosting::hprintln; use panic_semihosting as _; @@ -27,12 +27,12 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { rtic::pend(Interrupt::UART0); hprintln!("init"); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[idle] @@ -43,8 +43,6 @@ mod app { loop { cortex_m::asm::nop(); - // Exit moved after nop to ensure that rtic::pend gets - // to run before exiting debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator } } diff --git a/examples/extern_spawn.rs b/rtic/examples/extern_spawn.rs index 446d31a..2ab5550 100644 --- a/examples/extern_spawn.rs +++ b/rtic/examples/extern_spawn.rs @@ -1,21 +1,20 @@ //! examples/extern_spawn.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; // Free function implementing the spawnable task `foo`. -fn foo(_c: app::foo::Context, x: i32, y: u32) { - hprintln!("foo {}, {}", x, y); - if x == 2 { - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - } - app::foo::spawn(2, 3).unwrap(); +// Notice, you need to indicate an anonymous lifetime <'a_> +async fn foo(_c: app::foo::Context<'_>) { + hprintln!("foo"); + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator } #[rtic::app(device = lm3s6965, dispatchers = [SSI0])] @@ -29,14 +28,14 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { - foo::spawn(1, 2).unwrap(); + fn init(_: init::Context) -> (Shared, Local) { + foo::spawn().unwrap(); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } extern "Rust" { #[task()] - fn foo(_c: foo::Context, _x: i32, _y: u32); + async fn foo(_c: foo::Context); } } diff --git a/examples/generics.rs b/rtic/examples/generics.rs index bc4959f..dd042a3 100644 --- a/examples/generics.rs +++ b/rtic/examples/generics.rs @@ -1,10 +1,10 @@ //! examples/generics.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use cortex_m_semihosting::hprintln; use panic_semihosting as _; @@ -24,11 +24,11 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { rtic::pend(Interrupt::UART0); rtic::pend(Interrupt::UART1); - (Shared { shared: 0 }, Local {}, init::Monotonics()) + (Shared { shared: 0 }, Local {}) } #[task(binds = UART0, shared = [shared], local = [state: u32 = 0])] @@ -40,8 +40,6 @@ mod app { rtic::pend(Interrupt::UART1); - // Exit moved after nop to ensure that rtic::pend gets - // to run before exiting cortex_m::asm::nop(); debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator } diff --git a/examples/hardware.rs b/rtic/examples/hardware.rs index a7fdb47..b4c6b6c 100644 --- a/examples/hardware.rs +++ b/rtic/examples/hardware.rs @@ -1,10 +1,10 @@ //! examples/hardware.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -20,14 +20,14 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { // Pends the UART0 interrupt but its handler won't run until *after* // `init` returns because interrupts are disabled rtic::pend(Interrupt::UART0); // equivalent to NVIC::pend hprintln!("init"); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[idle] @@ -39,8 +39,6 @@ mod app { rtic::pend(Interrupt::UART0); loop { - // Exit moved after nop to ensure that rtic::pend gets - // to run before exiting cortex_m::asm::nop(); debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator } diff --git a/examples/idle-wfi.rs b/rtic/examples/idle-wfi.rs index 5e52620..72aaa95 100644 --- a/examples/idle-wfi.rs +++ b/rtic/examples/idle-wfi.rs @@ -1,10 +1,10 @@ //! examples/idle-wfi.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -19,14 +19,14 @@ mod app { struct Local {} #[init] - fn init(mut cx: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(mut cx: init::Context) -> (Shared, Local) { hprintln!("init"); // Set the ARM SLEEPONEXIT bit to go to sleep after handling interrupts // See https://developer.arm.com/docs/100737/0100/power-management/sleep-mode/sleep-on-exit-bit cx.core.SCB.set_sleepdeep(); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[idle(local = [x: u32 = 0])] diff --git a/examples/idle.rs b/rtic/examples/idle.rs index ccec9bf..4149818 100644 --- a/examples/idle.rs +++ b/rtic/examples/idle.rs @@ -1,10 +1,10 @@ //! examples/idle.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -19,10 +19,10 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { hprintln!("init"); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[idle(local = [x: u32 = 0])] diff --git a/examples/init.rs b/rtic/examples/init.rs index afd3b98..634d309 100644 --- a/examples/init.rs +++ b/rtic/examples/init.rs @@ -1,10 +1,10 @@ //! examples/init.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -19,7 +19,7 @@ mod app { struct Local {} #[init(local = [x: u32 = 0])] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(cx: init::Context) -> (Shared, Local) { // Cortex-M peripherals let _core: cortex_m::Peripherals = cx.core; @@ -30,13 +30,13 @@ mod app { let _x: &'static mut u32 = cx.local.x; // Access to the critical section token, - // to indicate that this is a critical seciton + // to indicate that this is a critical section let _cs_token: bare_metal::CriticalSection = cx.cs; hprintln!("init"); debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } } diff --git a/examples/locals.rs b/rtic/examples/locals.rs index 9e112be..2408f90 100644 --- a/examples/locals.rs +++ b/rtic/examples/locals.rs @@ -1,11 +1,11 @@ //! examples/locals.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -18,17 +18,14 @@ mod app { #[local] struct Local { - /// Local foo local_to_foo: i64, - /// Local bar local_to_bar: i64, - /// Local idle local_to_idle: i64, } // `#[init]` cannot access locals from the `#[local]` struct as they are initialized here. #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { foo::spawn().unwrap(); bar::spawn().unwrap(); @@ -40,7 +37,6 @@ mod app { local_to_bar: 0, local_to_idle: 0, }, - init::Monotonics(), ) } @@ -67,7 +63,7 @@ mod app { // `local_to_foo` can only be accessed from this context #[task(local = [local_to_foo])] - fn foo(cx: foo::Context) { + async fn foo(cx: foo::Context) { let local_to_foo = cx.local.local_to_foo; *local_to_foo += 1; @@ -79,7 +75,7 @@ mod app { // `local_to_bar` can only be accessed from this context #[task(local = [local_to_bar])] - fn bar(cx: bar::Context) { + async fn bar(cx: bar::Context) { let local_to_bar = cx.local.local_to_bar; *local_to_bar += 1; diff --git a/examples/lock-free.rs b/rtic/examples/lock-free.rs index 6e5faad..c17d70d 100644 --- a/examples/lock-free.rs +++ b/rtic/examples/lock-free.rs @@ -1,16 +1,18 @@ //! examples/lock-free.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; -#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])] +#[rtic::app(device = lm3s6965)] mod app { use cortex_m_semihosting::{debug, hprintln}; + use lm3s6965::Interrupt; #[shared] struct Shared { @@ -22,25 +24,24 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { - foo::spawn().unwrap(); + fn init(_: init::Context) -> (Shared, Local) { + rtic::pend(Interrupt::UART0); - (Shared { counter: 0 }, Local {}, init::Monotonics()) + (Shared { counter: 0 }, Local {}) } - #[task(shared = [counter])] // <- same priority + #[task(binds = UART0, shared = [counter])] // <- same priority fn foo(c: foo::Context) { - bar::spawn().unwrap(); + rtic::pend(Interrupt::UART1); *c.shared.counter += 1; // <- no lock API required let counter = *c.shared.counter; hprintln!(" foo = {}", counter); } - #[task(shared = [counter])] // <- same priority + #[task(binds = UART1, shared = [counter])] // <- same priority fn bar(c: bar::Context) { - foo::spawn().unwrap(); - + rtic::pend(Interrupt::UART0); *c.shared.counter += 1; // <- no lock API required let counter = *c.shared.counter; hprintln!(" bar = {}", counter); diff --git a/examples/lock.rs b/rtic/examples/lock.rs index 5b3e0bc..c09d99d 100644 --- a/examples/lock.rs +++ b/rtic/examples/lock.rs @@ -1,10 +1,11 @@ //! examples/lock.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -21,15 +22,15 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { foo::spawn().unwrap(); - (Shared { shared: 0 }, Local {}, init::Monotonics()) + (Shared { shared: 0 }, Local {}) } // when omitted priority is assumed to be `1` #[task(shared = [shared])] - fn foo(mut c: foo::Context) { + async fn foo(mut c: foo::Context) { hprintln!("A"); // the lower priority task requires a critical section to access the data @@ -54,7 +55,7 @@ mod app { } #[task(priority = 2, shared = [shared])] - fn bar(mut c: bar::Context) { + async fn bar(mut c: bar::Context) { // the higher priority task does still need a critical section let shared = c.shared.shared.lock(|shared| { *shared += 1; @@ -66,7 +67,7 @@ mod app { } #[task(priority = 3)] - fn baz(_: baz::Context) { + async fn baz(_: baz::Context) { hprintln!("C"); } } diff --git a/examples/multilock.rs b/rtic/examples/multilock.rs index c7085cd..ba9588b 100644 --- a/examples/multilock.rs +++ b/rtic/examples/multilock.rs @@ -1,10 +1,11 @@ //! examples/mutlilock.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -23,7 +24,7 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { locks::spawn().unwrap(); ( @@ -33,13 +34,12 @@ mod app { shared3: 0, }, Local {}, - init::Monotonics(), ) } // when omitted priority is assumed to be `1` #[task(shared = [shared1, shared2, shared3])] - fn locks(c: locks::Context) { + async fn locks(c: locks::Context) { let s1 = c.shared.shared1; let s2 = c.shared.shared2; let s3 = c.shared.shared3; diff --git a/examples/not-sync.rs b/rtic/examples/not-sync.rs index 68af04a..cd6b0bf 100644 --- a/examples/not-sync.rs +++ b/rtic/examples/not-sync.rs @@ -1,18 +1,18 @@ //! `examples/not-sync.rs` -// #![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use core::marker::PhantomData; use panic_semihosting as _; /// Not sync pub struct NotSync { - /// Phantom action _0: PhantomData<*const ()>, + data: u32, } unsafe impl Send for NotSync {} @@ -21,11 +21,10 @@ unsafe impl Send for NotSync {} mod app { use super::NotSync; use core::marker::PhantomData; - use cortex_m_semihosting::debug; + use cortex_m_semihosting::{debug, hprintln}; #[shared] struct Shared { - /// This resource is not Sync shared: NotSync, } @@ -33,25 +32,37 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + fn init(_: init::Context) -> (Shared, Local) { + hprintln!("init"); + foo::spawn().unwrap(); + bar::spawn().unwrap(); ( Shared { - shared: NotSync { _0: PhantomData }, + shared: NotSync { + _0: PhantomData, + data: 13, + }, }, Local {}, - init::Monotonics(), ) } + #[idle] + fn idle(_: idle::Context) -> ! { + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + loop {} + } + #[task(shared = [&shared])] - fn foo(c: foo::Context) { - let _: &NotSync = c.shared.shared; + async fn foo(c: foo::Context) { + let shared: &NotSync = c.shared.shared; + hprintln!("foo a {}", shared.data); } #[task(shared = [&shared])] - fn bar(c: bar::Context) { - let _: &NotSync = c.shared.shared; + async fn bar(c: bar::Context) { + let shared: &NotSync = c.shared.shared; + hprintln!("bar a {}", shared.data); } } diff --git a/examples/only-shared-access.rs b/rtic/examples/only-shared-access.rs index b32827a..23ae67e 100644 --- a/examples/only-shared-access.rs +++ b/rtic/examples/only-shared-access.rs @@ -1,10 +1,11 @@ //! examples/only-shared-access.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -21,15 +22,15 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { foo::spawn().unwrap(); bar::spawn().unwrap(); - (Shared { key: 0xdeadbeef }, Local {}, init::Monotonics()) + (Shared { key: 0xdeadbeef }, Local {}) } #[task(shared = [&key])] - fn foo(cx: foo::Context) { + async fn foo(cx: foo::Context) { let key: &u32 = cx.shared.key; hprintln!("foo(key = {:#x})", key); @@ -37,7 +38,7 @@ mod app { } #[task(priority = 2, shared = [&key])] - fn bar(cx: bar::Context) { + async fn bar(cx: bar::Context) { hprintln!("bar(key = {:#x})", cx.shared.key); } } diff --git a/examples/peripherals-taken.rs b/rtic/examples/peripherals-taken.rs index cc9b9a1..2f63001 100644 --- a/examples/peripherals-taken.rs +++ b/rtic/examples/peripherals-taken.rs @@ -1,9 +1,10 @@ //! examples/peripherals-taken.rs + +#![no_main] +#![no_std] #![deny(warnings)] #![deny(unsafe_code)] #![deny(missing_docs)] -#![no_main] -#![no_std] use panic_semihosting as _; @@ -18,10 +19,10 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { assert!(cortex_m::Peripherals::take().is_none()); debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } } diff --git a/examples/pool.rs b/rtic/examples/pool.rs index 4c551be..92c10c4 100644 --- a/examples/pool.rs +++ b/rtic/examples/pool.rs @@ -1,11 +1,9 @@ //! examples/pool.rs -#![deny(unsafe_code)] -#![deny(warnings)] -// pool!() generates a struct without docs -//#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![feature(type_alias_impl_trait)] use heapless::{ pool, @@ -33,13 +31,13 @@ mod app { struct Local {} #[init(local = [memory: [u8; 512] = [0; 512]])] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(cx: init::Context) -> (Shared, Local) { // Increase the capacity of the memory pool by ~4 P::grow(cx.local.memory); rtic::pend(Interrupt::I2C0); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[task(binds = I2C0, priority = 2)] @@ -57,7 +55,7 @@ mod app { } #[task] - fn foo(_: foo::Context, _x: Box<P>) { + async fn foo(_: foo::Context, _x: Box<P>) { // explicitly return the block to the pool drop(_x); @@ -65,8 +63,8 @@ mod app { } #[task(priority = 2)] - fn bar(_: bar::Context, _x: Box<P>) { + async fn bar(_: bar::Context, _x: Box<P>) { // this is done automatically so we can omit the call to `drop` - // drop(x); + // drop(_x); } } diff --git a/examples/preempt.rs b/rtic/examples/preempt.rs index 3c7f242..f1a92b0 100644 --- a/examples/preempt.rs +++ b/rtic/examples/preempt.rs @@ -2,6 +2,10 @@ #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; use rtic::app; @@ -17,14 +21,14 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { foo::spawn().unwrap(); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[task(priority = 1)] - fn foo(_: foo::Context) { + async fn foo(_: foo::Context) { hprintln!("foo - start"); baz::spawn().unwrap(); hprintln!("foo - end"); @@ -32,12 +36,12 @@ mod app { } #[task(priority = 2)] - fn bar(_: bar::Context) { + async fn bar(_: bar::Context) { hprintln!(" bar"); } #[task(priority = 2)] - fn baz(_: baz::Context) { + async fn baz(_: baz::Context) { hprintln!(" baz - start"); bar::spawn().unwrap(); hprintln!(" baz - end"); diff --git a/examples/ramfunc.rs b/rtic/examples/ramfunc.rs index 956a255..1134926 100644 --- a/examples/ramfunc.rs +++ b/rtic/examples/ramfunc.rs @@ -1,9 +1,10 @@ //! examples/ramfunc.rs +//! TODO: verify that ram-sections are properly used -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -25,15 +26,15 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { foo::spawn().unwrap(); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[inline(never)] #[task] - fn foo(_: foo::Context) { + async fn foo(_: foo::Context) { hprintln!("foo"); debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator @@ -43,7 +44,7 @@ mod app { #[inline(never)] #[link_section = ".data.bar"] #[task(priority = 2)] - fn bar(_: bar::Context) { + async fn bar(_: bar::Context) { foo::spawn().unwrap(); } } diff --git a/examples/resource-user-struct.rs b/rtic/examples/resource-user-struct.rs index 37a8856..cad42d7 100644 --- a/examples/resource-user-struct.rs +++ b/rtic/examples/resource-user-struct.rs @@ -1,10 +1,10 @@ //! examples/resource.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -30,11 +30,11 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { rtic::pend(Interrupt::UART0); rtic::pend(Interrupt::UART1); - (Shared { shared: 0 }, Local {}, init::Monotonics()) + (Shared { shared: 0 }, Local {}) } // `shared` cannot be accessed from this context diff --git a/examples/shared.rs b/rtic/examples/shared.rs index b43a19a..79ebab8 100644 --- a/examples/shared.rs +++ b/rtic/examples/shared.rs @@ -1,10 +1,10 @@ //! examples/late.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -16,9 +16,7 @@ mod app { #[shared] struct Shared { - /// Producer p: Producer<'static, u32, 5>, - /// Consumer c: Consumer<'static, u32, 5>, } @@ -26,11 +24,11 @@ mod app { struct Local {} #[init(local = [q: Queue<u32, 5> = Queue::new()])] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(cx: init::Context) -> (Shared, Local) { let (p, c) = cx.local.q.split(); // Initialization of shared resources - (Shared { p, c }, Local {}, init::Monotonics()) + (Shared { p, c }, Local {}) } #[idle(shared = [c])] diff --git a/examples/smallest.rs b/rtic/examples/smallest.rs index b121fcf..fee3f05 100644 --- a/examples/smallest.rs +++ b/rtic/examples/smallest.rs @@ -2,6 +2,9 @@ #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; // panic handler use rtic::app; @@ -17,8 +20,8 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } } diff --git a/examples/spawn.rs b/rtic/examples/spawn.rs index 50ae7e7..58f9bc0 100644 --- a/examples/spawn.rs +++ b/rtic/examples/spawn.rs @@ -1,10 +1,11 @@ //! examples/spawn.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -19,15 +20,15 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { hprintln!("init"); foo::spawn().unwrap(); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[task] - fn foo(_: foo::Context) { + async fn foo(_: foo::Context) { hprintln!("foo"); debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator diff --git a/examples/message_passing.rs b/rtic/examples/spawn_arguments.rs index 9550a50..5ca700f 100644 --- a/examples/message_passing.rs +++ b/rtic/examples/spawn_arguments.rs @@ -1,10 +1,11 @@ -//! examples/message_passing.rs +//! examples/spawn_arguments.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -19,20 +20,16 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { foo::spawn(1, 1).unwrap(); - foo::spawn(1, 2).unwrap(); - foo::spawn(2, 3).unwrap(); assert!(foo::spawn(1, 4).is_err()); // The capacity of `foo` is reached - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } - #[task(capacity = 3)] - fn foo(_c: foo::Context, x: i32, y: u32) { + #[task] + async fn foo(_c: foo::Context, x: i32, y: u32) { hprintln!("foo {}, {}", x, y); - if x == 2 { - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - } + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator } } diff --git a/rtic/examples/spawn_err.rs b/rtic/examples/spawn_err.rs new file mode 100644 index 0000000..abe6295 --- /dev/null +++ b/rtic/examples/spawn_err.rs @@ -0,0 +1,40 @@ +//! examples/spawn_err.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) { + hprintln!("init"); + foo::spawn().unwrap(); + match foo::spawn() { + Ok(_) => {} + Err(()) => hprintln!("Cannot spawn a spawned (running) task!"), + } + + (Shared {}, Local {}) + } + + #[task] + async fn foo(_: foo::Context) { + hprintln!("foo"); + + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + } +} diff --git a/rtic/examples/spawn_loop.rs b/rtic/examples/spawn_loop.rs new file mode 100644 index 0000000..9328a94 --- /dev/null +++ b/rtic/examples/spawn_loop.rs @@ -0,0 +1,42 @@ +//! examples/spawn_loop.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) { + hprintln!("init"); + + (Shared {}, Local {}) + } + #[idle] + fn idle(_: idle::Context) -> ! { + for _ in 0..3 { + foo::spawn().unwrap(); + hprintln!("idle"); + } + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + loop {} + } + + #[task] + async fn foo(_: foo::Context) { + hprintln!("foo"); + } +} diff --git a/examples/static.rs b/rtic/examples/static.rs index efafcc7..a98e2e5 100644 --- a/examples/static.rs +++ b/rtic/examples/static.rs @@ -1,10 +1,11 @@ //! examples/static.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -23,14 +24,14 @@ mod app { } #[init(local = [q: Queue<u32, 5> = Queue::new()])] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(cx: init::Context) -> (Shared, Local) { // q has 'static life-time so after the split and return of `init` // it will continue to exist and be allocated let (p, c) = cx.local.q.split(); foo::spawn().unwrap(); - (Shared {}, Local { p, c }, init::Monotonics()) + (Shared {}, Local { p, c }) } #[idle(local = [c])] @@ -51,7 +52,7 @@ mod app { } #[task(local = [p, state: u32 = 0])] - fn foo(c: foo::Context) { + async fn foo(c: foo::Context) { *c.local.state += 1; // Lock-free access to the same underlying queue! diff --git a/examples/t-binds.rs b/rtic/examples/t-binds.rs index 822a2ee..01c262c 100644 --- a/examples/t-binds.rs +++ b/rtic/examples/t-binds.rs @@ -1,10 +1,10 @@ //! [compile-pass] Check that `binds` works as advertised -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -19,10 +19,10 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } // Cortex-M exception diff --git a/examples/t-cfg-resources.rs b/rtic/examples/t-cfg-resources.rs index 99c97ba..2ddfae7 100644 --- a/examples/t-cfg-resources.rs +++ b/rtic/examples/t-cfg-resources.rs @@ -1,7 +1,10 @@ //! [compile-pass] check that `#[cfg]` attributes applied on resources work -//! + #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -20,7 +23,7 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator ( @@ -29,7 +32,6 @@ mod app { x: 0, }, Local {}, - init::Monotonics(), ) } diff --git a/examples/t-htask-main.rs b/rtic/examples/t-htask-main.rs index 2b17b2e..61280f8 100644 --- a/examples/t-htask-main.rs +++ b/rtic/examples/t-htask-main.rs @@ -1,9 +1,10 @@ -//! examples/t-htask-main.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] +//! examples/t-task-main.rs + #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -18,10 +19,10 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { rtic::pend(lm3s6965::Interrupt::UART0); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[task(binds = UART0)] diff --git a/examples/t-idle-main.rs b/rtic/examples/t-idle-main.rs index 48635b2..88566a9 100644 --- a/examples/t-idle-main.rs +++ b/rtic/examples/t-idle-main.rs @@ -1,9 +1,10 @@ //! examples/t-idle-main.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] + #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use panic_semihosting as _; @@ -18,8 +19,8 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { - (Shared {}, Local {}, init::Monotonics()) + fn init(_: init::Context) -> (Shared, Local) { + (Shared {}, Local {}) } #[idle] diff --git a/examples/t-late-not-send.rs b/rtic/examples/t-late-not-send.rs index 06aedaa..be5cc66 100644 --- a/examples/t-late-not-send.rs +++ b/rtic/examples/t-late-not-send.rs @@ -2,11 +2,14 @@ #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] use core::marker::PhantomData; - use panic_semihosting as _; +/// Not send pub struct NotSend { _0: PhantomData<*const ()>, } @@ -27,14 +30,13 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { ( Shared { x: NotSend { _0: PhantomData }, y: None, }, Local {}, - init::Monotonics(), ) } diff --git a/examples/task.rs b/rtic/examples/task.rs index 9757f2f..9b06bb4 100644 --- a/examples/task.rs +++ b/rtic/examples/task.rs @@ -1,10 +1,11 @@ //! examples/task.rs -#![deny(unsafe_code)] -#![deny(warnings)] -#![deny(missing_docs)] #![no_main] #![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -19,14 +20,14 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { foo::spawn().unwrap(); - (Shared {}, Local {}, init::Monotonics()) + (Shared {}, Local {}) } #[task] - fn foo(_: foo::Context) { + async fn foo(_: foo::Context) { hprintln!("foo - start"); // spawns `bar` onto the task scheduler @@ -44,14 +45,14 @@ mod app { } #[task] - fn bar(_: bar::Context) { + async fn bar(_: bar::Context) { hprintln!("bar"); debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator } #[task(priority = 2)] - fn baz(_: baz::Context) { + async fn baz(_: baz::Context) { hprintln!("baz"); } } diff --git a/rtic/examples/zero-prio-task.rs b/rtic/examples/zero-prio-task.rs new file mode 100644 index 0000000..dbe1959 --- /dev/null +++ b/rtic/examples/zero-prio-task.rs @@ -0,0 +1,62 @@ +//! examples/zero-prio-task.rs + +#![no_main] +#![no_std] +#![deny(warnings)] +#![deny(unsafe_code)] +#![deny(missing_docs)] +#![feature(type_alias_impl_trait)] + +use core::marker::PhantomData; +use panic_semihosting as _; + +/// Does not impl send +pub struct NotSend { + _0: PhantomData<*const ()>, +} + +#[rtic::app(device = lm3s6965, peripherals = true)] +mod app { + use super::NotSend; + use core::marker::PhantomData; + use cortex_m_semihosting::{debug, hprintln}; + + #[shared] + struct Shared { + x: NotSend, + } + + #[local] + struct Local { + y: NotSend, + } + + #[init] + fn init(_cx: init::Context) -> (Shared, Local) { + hprintln!("init"); + + async_task::spawn().unwrap(); + async_task2::spawn().unwrap(); + + ( + Shared { + x: NotSend { _0: PhantomData }, + }, + Local { + y: NotSend { _0: PhantomData }, + }, + ) + } + + #[task(priority = 0, shared = [x], local = [y])] + async fn async_task(_: async_task::Context) { + hprintln!("hello from async"); + } + + #[task(priority = 0, shared = [x])] + async fn async_task2(_: async_task2::Context) { + hprintln!("hello from async2"); + + debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator + } +} diff --git a/rtic/src/export.rs b/rtic/src/export.rs new file mode 100644 index 0000000..9040b63 --- /dev/null +++ b/rtic/src/export.rs @@ -0,0 +1,60 @@ +pub use bare_metal::CriticalSection; +//pub use portable_atomic as atomic; +pub use atomic_polyfill as atomic; + +pub mod executor; + +#[cfg(all( + feature = "cortex-m-basepri", + not(any(feature = "thumbv7-backend", feature = "thumbv8main-backend")) +))] +compile_error!( + "Building for Cortex-M with basepri, but 'thumbv7-backend' or 'thumbv8main-backend' backend not selected" +); + +#[cfg(all( + feature = "cortex-m-source-masking", + not(any(feature = "thumbv6-backend", feature = "thumbv8base-backend")) +))] +compile_error!( + "Building for Cortex-M with source masking, but 'thumbv6-backend' or 'thumbv8base-backend' backend not selected" +); + +#[cfg(any(feature = "cortex-m-basepri", feature = "rtic-uitestv7"))] +pub use cortex_basepri::*; + +#[cfg(any(feature = "cortex-m-basepri", feature = "rtic-uitestv7"))] +mod cortex_basepri; + +#[cfg(any(feature = "cortex-m-source-masking", feature = "rtic-uitestv6"))] +pub use cortex_source_mask::*; + +#[cfg(any(feature = "cortex-m-source-masking", feature = "rtic-uitestv6"))] +mod cortex_source_mask; + +/// Priority conversion, takes logical priorities 1..=N and converts it to NVIC priority. +#[cfg(any( + feature = "cortex-m-basepri", + feature = "cortex-m-source-masking", + feature = "rtic-uitestv6", + feature = "rtic-uitestv7", +))] +#[inline] +#[must_use] +pub const fn cortex_logical2hw(logical: u8, nvic_prio_bits: u8) -> u8 { + ((1 << nvic_prio_bits) - logical) << (8 - nvic_prio_bits) +} + +#[inline(always)] +pub fn assert_send<T>() +where + T: Send, +{ +} + +#[inline(always)] +pub fn assert_sync<T>() +where + T: Sync, +{ +} diff --git a/rtic/src/export/cortex_basepri.rs b/rtic/src/export/cortex_basepri.rs new file mode 100644 index 0000000..d3ceba3 --- /dev/null +++ b/rtic/src/export/cortex_basepri.rs @@ -0,0 +1,78 @@ +use super::cortex_logical2hw; +use cortex_m::register::basepri; +pub use cortex_m::{ + asm::nop, + asm::wfi, + interrupt, + peripheral::{scb::SystemHandler, DWT, NVIC, SCB, SYST}, + Peripherals, +}; + +#[inline(always)] +pub fn run<F>(priority: u8, f: F) +where + F: FnOnce(), +{ + if priority == 1 { + // If the priority of this interrupt is `1` then BASEPRI can only be `0` + f(); + unsafe { basepri::write(0) } + } else { + let initial = basepri::read(); + f(); + unsafe { basepri::write(initial) } + } +} + +/// Lock implementation using BASEPRI and global Critical Section (CS) +/// +/// # Safety +/// +/// The system ceiling is raised from current to ceiling +/// by either +/// - raising the BASEPRI to the ceiling value, or +/// - disable all interrupts in case we want to +/// mask interrupts with maximum priority +/// +/// Dereferencing a raw pointer inside CS +/// +/// The priority.set/priority.get can safely be outside the CS +/// as being a context local cell (not affected by preemptions). +/// It is merely used in order to omit masking in case current +/// priority is current priority >= ceiling. +/// +/// Lock Efficiency: +/// Experiments validate (sub)-zero cost for CS implementation +/// (Sub)-zero as: +/// - Either zero OH (lock optimized out), or +/// - Amounting to an optimal assembly implementation +/// - The BASEPRI value is folded to a constant at compile time +/// - CS entry, single assembly instruction to write BASEPRI +/// - CS exit, single assembly instruction to write BASEPRI +/// - priority.set/get optimized out (their effect not) +/// - On par or better than any handwritten implementation of SRP +/// +/// Limitations: +/// The current implementation reads/writes BASEPRI once +/// even in some edge cases where this may be omitted. +/// Total OH of per task is max 2 clock cycles, negligible in practice +/// but can in theory be fixed. +/// +#[inline(always)] +pub unsafe fn lock<T, R>( + ptr: *mut T, + ceiling: u8, + nvic_prio_bits: u8, + f: impl FnOnce(&mut T) -> R, +) -> R { + if ceiling == (1 << nvic_prio_bits) { + let r = critical_section::with(|_| f(&mut *ptr)); + r + } else { + let current = basepri::read(); + basepri::write(cortex_logical2hw(ceiling, nvic_prio_bits)); + let r = f(&mut *ptr); + basepri::write(current); + r + } +} diff --git a/rtic/src/export/cortex_source_mask.rs b/rtic/src/export/cortex_source_mask.rs new file mode 100644 index 0000000..fe95b1b --- /dev/null +++ b/rtic/src/export/cortex_source_mask.rs @@ -0,0 +1,195 @@ +pub use cortex_m::{ + asm::nop, + asm::wfi, + interrupt, + peripheral::{scb::SystemHandler, DWT, NVIC, SCB, SYST}, + Peripherals, +}; + +/// Mask is used to store interrupt masks on systems without a BASEPRI register (M0, M0+, M23). +/// It needs to be large enough to cover all the relevant interrupts in use. +/// For M0/M0+ there are only 32 interrupts so we only need one u32 value. +/// For M23 there can be as many as 480 interrupts. +/// Rather than providing space for all possible interrupts, we just detect the highest interrupt in +/// use at compile time and allocate enough u32 chunks to cover them. +#[derive(Copy, Clone)] +pub struct Mask<const M: usize>([u32; M]); + +pub const fn create_mask<const N: usize, const M: usize>(list_of_shifts: [u32; N]) -> Mask<M> { + let mut mask = Mask([0; M]); + let mut i = 0; + + while i < N { + let shift = list_of_shifts[i]; + i += 1; + mask = mask.set_bit(shift); + } + + mask +} + +/// Compute the number of u32 chunks needed to store the Mask value. +/// On M0, M0+ this should always end up being 1. +/// On M23 we will pick a number that allows us to store the highest index used by the code. +/// This means the amount of overhead will vary based on the actually interrupts used by the code. +pub const fn compute_mask_chunks<const L: usize>(ids: [u32; L]) -> usize { + let mut max: usize = 0; + let mut i = 0; + + while i < L { + let id = ids[i] as usize; + i += 1; + + if id > max { + max = id; + } + } + (max + 32) / 32 +} + +impl<const M: usize> Mask<M> { + /// Set a bit inside a Mask. + const fn set_bit(mut self, bit: u32) -> Self { + let block = bit / 32; + + if block as usize >= M { + panic!("Generating masks for thumbv6/thumbv8m.base failed! Are you compiling for thumbv6 on an thumbv7 MCU or using an unsupported thumbv8m.base MCU?"); + } + + let offset = bit - (block * 32); + self.0[block as usize] |= 1 << offset; + self + } +} + +#[inline(always)] +pub fn run<F>(_priority: u8, f: F) +where + F: FnOnce(), +{ + f(); +} + +/// Lock implementation using interrupt masking +/// +/// # Safety +/// +/// The system ceiling is raised from current to ceiling +/// by computing a 32 bit `mask` (1 bit per interrupt) +/// 1: ceiling >= priority > current +/// 0: else +/// +/// On CS entry, `clear_enable_mask(mask)` disables interrupts +/// On CS exit, `set_enable_mask(mask)` re-enables interrupts +/// +/// The priority.set/priority.get can safely be outside the CS +/// as being a context local cell (not affected by preemptions). +/// It is merely used in order to omit masking in case +/// current priority >= ceiling. +/// +/// Dereferencing a raw pointer is done safely inside the CS +/// +/// Lock Efficiency: +/// Early experiments validate (sub)-zero cost for CS implementation +/// (Sub)-zero as: +/// - Either zero OH (lock optimized out), or +/// - Amounting to an optimal assembly implementation +/// - if ceiling == (1 << nvic_prio_bits) +/// - we execute the closure in a global critical section (interrupt free) +/// - CS entry cost, single write to core register +/// - CS exit cost, single write to core register +/// else +/// - The `mask` value is folded to a constant at compile time +/// - CS entry, single write of the 32 bit `mask` to the `icer` register +/// - CS exit, single write of the 32 bit `mask` to the `iser` register +/// - priority.set/get optimized out (their effect not) +/// - On par or better than any hand written implementation of SRP +/// +/// Limitations: +/// Current implementation does not allow for tasks with shared resources +/// to be bound to exception handlers, as these cannot be masked in HW. +/// +/// Possible solutions: +/// - Mask exceptions by global critical sections (interrupt::free) +/// - Temporary lower exception priority +/// +/// These possible solutions are set goals for future work +#[inline(always)] +pub unsafe fn lock<T, R, const M: usize>( + ptr: *mut T, + ceiling: u8, + masks: &[Mask<M>; 3], + f: impl FnOnce(&mut T) -> R, +) -> R { + if ceiling >= 4 { + // safe to manipulate outside critical section + // execute closure under protection of raised system ceiling + + // safe to manipulate outside critical section + critical_section::with(|_| f(&mut *ptr)) + } else { + // safe to manipulate outside critical section + let mask = compute_mask(0, ceiling, masks); + clear_enable_mask(mask); + + // execute closure under protection of raised system ceiling + let r = f(&mut *ptr); + + set_enable_mask(mask); + + // safe to manipulate outside critical section + r + } +} + +#[inline(always)] +pub const fn compute_mask<const M: usize>( + from_prio: u8, + to_prio: u8, + masks: &[Mask<M>; 3], +) -> Mask<M> { + let mut res = Mask([0; M]); + + let mut idx = from_prio as usize; + + while idx < to_prio as usize { + let mut i = 0; + + while i < M { + //self.0[i] |= rhs.0[i]; + res.0[i] |= masks[idx].0[i]; + i += 1; + } + + idx += 1; + } + + // old code (non const) + // masks[from_prio as usize..to_prio as usize] + // .iter() + // .for_each(|m| res |= *m); + + res +} + +// enables interrupts +#[inline(always)] +unsafe fn set_enable_mask<const M: usize>(mask: Mask<M>) { + for i in 0..M { + // This check should involve compile time constants and be optimized out. + if mask.0[i] != 0 { + (*NVIC::PTR).iser[i].write(mask.0[i]); + } + } +} + +// disables interrupts +#[inline(always)] +unsafe fn clear_enable_mask<const M: usize>(mask: Mask<M>) { + for i in 0..M { + // This check should involve compile time constants and be optimized out. + if mask.0[i] != 0 { + (*NVIC::PTR).icer[i].write(mask.0[i]); + } + } +} diff --git a/rtic/src/export/executor.rs b/rtic/src/export/executor.rs new file mode 100644 index 0000000..36e47d7 --- /dev/null +++ b/rtic/src/export/executor.rs @@ -0,0 +1,108 @@ +use super::atomic::{AtomicBool, Ordering}; +use core::{ + cell::UnsafeCell, + future::Future, + mem::{self, MaybeUninit}, + pin::Pin, + task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, +}; + +static WAKER_VTABLE: RawWakerVTable = + RawWakerVTable::new(waker_clone, waker_wake, waker_wake, waker_drop); + +unsafe fn waker_clone(p: *const ()) -> RawWaker { + RawWaker::new(p, &WAKER_VTABLE) +} + +unsafe fn waker_wake(p: *const ()) { + // The only thing we need from a waker is the function to call to pend the async + // dispatcher. + let f: fn() = mem::transmute(p); + f(); +} + +unsafe fn waker_drop(_: *const ()) { + // nop +} + +//============ +// AsyncTaskExecutor + +/// Executor for an async task. +pub struct AsyncTaskExecutor<F: Future> { + // `task` is protected by the `running` flag. + task: UnsafeCell<MaybeUninit<F>>, + running: AtomicBool, + pending: AtomicBool, +} + +unsafe impl<F: Future> Sync for AsyncTaskExecutor<F> {} + +impl<F: Future> AsyncTaskExecutor<F> { + /// Create a new executor. + #[inline(always)] + pub const fn new() -> Self { + Self { + task: UnsafeCell::new(MaybeUninit::uninit()), + running: AtomicBool::new(false), + pending: AtomicBool::new(false), + } + } + + /// Check if there is an active task in the executor. + #[inline(always)] + pub fn is_running(&self) -> bool { + self.running.load(Ordering::Relaxed) + } + + /// Checks if a waker has pended the executor and simultaneously clears the flag. + #[inline(always)] + fn check_and_clear_pending(&self) -> bool { + // Ordering::Acquire to enforce that update of task is visible to poll + self.pending + .compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed) + .is_ok() + } + + // Used by wakers to indicate that the executor needs to run. + #[inline(always)] + pub fn set_pending(&self) { + self.pending.store(true, Ordering::Release); + } + + /// Allocate the executor. To use with `spawn`. + #[inline(always)] + pub unsafe fn try_allocate(&self) -> bool { + // Try to reserve the executor for a future. + self.running + .compare_exchange(false, true, Ordering::AcqRel, Ordering::Relaxed) + .is_ok() + } + + /// Spawn a future + #[inline(always)] + pub unsafe fn spawn(&self, future: F) { + // This unsafe is protected by `running` being false and the atomic setting it to true. + unsafe { + self.task.get().write(MaybeUninit::new(future)); + } + self.set_pending(); + } + + /// Poll the future in the executor. + #[inline(always)] + pub fn poll(&self, wake: fn()) { + if self.is_running() && self.check_and_clear_pending() { + let waker = unsafe { Waker::from_raw(RawWaker::new(wake as *const (), &WAKER_VTABLE)) }; + let mut cx = Context::from_waker(&waker); + let future = unsafe { Pin::new_unchecked(&mut *(self.task.get() as *mut F)) }; + + match future.poll(&mut cx) { + Poll::Ready(_) => { + self.running.store(false, Ordering::Release); + } + Poll::Pending => {} + } + } + } +} diff --git a/src/lib.rs b/rtic/src/lib.rs index 0c0d0cc..a193e5c 100644 --- a/src/lib.rs +++ b/rtic/src/lib.rs @@ -1,10 +1,5 @@ //! Real-Time Interrupt-driven Concurrency (RTIC) framework for ARM Cortex-M microcontrollers. //! -//! **IMPORTANT**: This crate is published as [`cortex-m-rtic`] on crates.io but the name of the -//! library is `rtic`. -//! -//! [`cortex-m-rtic`]: https://crates.io/crates/cortex-m-rtic -//! //! The user level documentation can be found [here]. //! //! [here]: https://rtic.rs @@ -32,16 +27,16 @@ #![deny(rust_2018_idioms)] #![no_std] #![doc( - html_logo_url = "https://raw.githubusercontent.com/rtic-rs/cortex-m-rtic/master/book/en/src/RTIC.svg", - html_favicon_url = "https://raw.githubusercontent.com/rtic-rs/cortex-m-rtic/master/book/en/src/RTIC.svg" + html_logo_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg", + html_favicon_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg" )] //deny_warnings_placeholder_for_ci #![allow(clippy::inline_always)] use cortex_m::{interrupt::InterruptNumber, peripheral::NVIC}; -pub use cortex_m_rtic_macros::app; pub use rtic_core::{prelude as mutex_prelude, Exclusive, Mutex}; -pub use rtic_monotonic::{self, Monotonic}; +pub use rtic_macros::app; +// pub use rtic_monotonic::{self, Monotonic}; /// module `mutex::prelude` provides `Mutex` and multi-lock variants. Recommended over `mutex_prelude` pub mod mutex { @@ -51,8 +46,6 @@ pub mod mutex { #[doc(hidden)] pub mod export; -#[doc(hidden)] -mod tq; /// Sets the given `interrupt` as pending /// diff --git a/rtic/tests/ui.rs b/rtic/tests/ui.rs new file mode 100644 index 0000000..9fb88a1 --- /dev/null +++ b/rtic/tests/ui.rs @@ -0,0 +1,7 @@ +use trybuild::TestCases; + +#[test] +fn ui() { + let t = TestCases::new(); + t.compile_fail("ui/*.rs"); +} diff --git a/ui/exception-invalid.rs b/rtic/ui/exception-invalid.rs index 07d3c21..4f8e943 100644 --- a/ui/exception-invalid.rs +++ b/rtic/ui/exception-invalid.rs @@ -9,8 +9,8 @@ mod app { struct Local {} #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - (Shared {}, Local {}, init::Monotonics()) + fn init(cx: init::Context) -> (Shared, Local) { + (Shared {}, Local {}) } #[task(binds = NonMaskableInt)] diff --git a/ui/exception-invalid.stderr b/rtic/ui/exception-invalid.stderr index 3212368..3212368 100644 --- a/ui/exception-invalid.stderr +++ b/rtic/ui/exception-invalid.stderr diff --git a/ui/extern-interrupt-not-enough.rs b/rtic/ui/extern-interrupt-not-enough.rs index 1dbe923..94c8ee1 100644 --- a/ui/extern-interrupt-not-enough.rs +++ b/rtic/ui/extern-interrupt-not-enough.rs @@ -9,10 +9,10 @@ mod app { struct Local {} #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - (Shared {}, Local {}, init::Monotonics()) + fn init(cx: init::Context) -> (Shared, Local) { + (Shared {}, Local {}) } #[task] - fn a(_: a::Context) {} + async fn a(_: a::Context) {} } diff --git a/rtic/ui/extern-interrupt-not-enough.stderr b/rtic/ui/extern-interrupt-not-enough.stderr new file mode 100644 index 0000000..e6c01b9 --- /dev/null +++ b/rtic/ui/extern-interrupt-not-enough.stderr @@ -0,0 +1,5 @@ +error: not enough interrupts to dispatch all software tasks (need: 1; given: 0) + --> ui/extern-interrupt-not-enough.rs:17:14 + | +17 | async fn a(_: a::Context) {} + | ^ diff --git a/ui/extern-interrupt-used.rs b/rtic/ui/extern-interrupt-used.rs index 882d5e3..42de4c0 100644 --- a/ui/extern-interrupt-used.rs +++ b/rtic/ui/extern-interrupt-used.rs @@ -9,8 +9,8 @@ mod app { struct Local {} #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - (Shared {}, Local {}, init::Monotonics()) + fn init(cx: init::Context) -> (Shared, Local) { + (Shared {}, Local {}) } #[task(binds = UART0)] diff --git a/ui/extern-interrupt-used.stderr b/rtic/ui/extern-interrupt-used.stderr index 7565739..7565739 100644 --- a/ui/extern-interrupt-used.stderr +++ b/rtic/ui/extern-interrupt-used.stderr diff --git a/ui/task-priority-too-high.rs b/rtic/ui/task-priority-too-high.rs index e7e0cce..44e4a25 100644 --- a/ui/task-priority-too-high.rs +++ b/rtic/ui/task-priority-too-high.rs @@ -9,8 +9,8 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { - (Shared {}, Local {}, init::Monotonics()) + fn init(cx: init::Context) -> (Shared, Local) { + (Shared {}, Local {}) } #[task(binds = GPIOA, priority = 1)] diff --git a/ui/task-priority-too-high.stderr b/rtic/ui/task-priority-too-high.stderr index 026124c..1256377 100644 --- a/ui/task-priority-too-high.stderr +++ b/rtic/ui/task-priority-too-high.stderr @@ -1,3 +1,11 @@ +warning: unused variable: `cx` + --> ui/task-priority-too-high.rs:12:13 + | +12 | fn init(cx: init::Context) -> (Shared, Local) { + | ^^ help: if this is intentional, prefix it with an underscore: `_cx` + | + = note: `#[warn(unused_variables)]` on by default + error[E0080]: evaluation of constant value failed --> ui/task-priority-too-high.rs:3:1 | diff --git a/ui/unknown-interrupt.rs b/rtic/ui/unknown-interrupt.rs index f2bc629..3c6c69f 100644 --- a/ui/unknown-interrupt.rs +++ b/rtic/ui/unknown-interrupt.rs @@ -9,7 +9,7 @@ mod app { struct Local {} #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - (Shared {}, Local {}, init::Monotonics()) + fn init(cx: init::Context) -> (Shared, Local) { + (Shared {}, Local {}) } } diff --git a/ui/unknown-interrupt.stderr b/rtic/ui/unknown-interrupt.stderr index c7d3269..c7d3269 100644 --- a/ui/unknown-interrupt.stderr +++ b/rtic/ui/unknown-interrupt.stderr diff --git a/ui/v6m-interrupt-not-enough.rs_no b/rtic/ui/v6m-interrupt-not-enough.rs_no index 3fbf3cf..3fbf3cf 100644 --- a/ui/v6m-interrupt-not-enough.rs_no +++ b/rtic/ui/v6m-interrupt-not-enough.rs_no diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..339b5f2 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly" +components = [ "rust-src", "rustfmt", "llvm-tools-preview" ] +targets = [ "thumbv6m-none-eabi", "thumbv7m-none-eabi", "thumbv8m.base-none-eabi", "thumbv8m.main-none-eabi" ] diff --git a/src/export.rs b/src/export.rs deleted file mode 100644 index 6f2a1b6..0000000 --- a/src/export.rs +++ /dev/null @@ -1,416 +0,0 @@ -#![allow(clippy::inline_always)] -use core::{ - cell::Cell, - sync::atomic::{AtomicBool, Ordering}, -}; - -pub use crate::tq::{NotReady, TimerQueue}; -pub use bare_metal::CriticalSection; -pub use cortex_m::{ - asm::nop, - asm::wfi, - interrupt, - peripheral::{scb::SystemHandler, DWT, NVIC, SCB, SYST}, - Peripherals, -}; -pub use heapless::sorted_linked_list::SortedLinkedList; -pub use heapless::spsc::Queue; -pub use heapless::BinaryHeap; -pub use rtic_monotonic as monotonic; - -pub type SCFQ<const N: usize> = Queue<u8, N>; -pub type SCRQ<T, const N: usize> = Queue<(T, u8), N>; - -/// Mask is used to store interrupt masks on systems without a BASEPRI register (M0, M0+, M23). -/// It needs to be large enough to cover all the relevant interrupts in use. -/// For M0/M0+ there are only 32 interrupts so we only need one u32 value. -/// For M23 there can be as many as 480 interrupts. -/// Rather than providing space for all possible interrupts, we just detect the highest interrupt in -/// use at compile time and allocate enough u32 chunks to cover them. -#[derive(Copy, Clone)] -pub struct Mask<const M: usize>([u32; M]); - -impl<const M: usize> core::ops::BitOrAssign for Mask<M> { - fn bitor_assign(&mut self, rhs: Self) { - for i in 0..M { - self.0[i] |= rhs.0[i]; - } - } -} - -#[cfg(not(have_basepri))] -impl<const M: usize> Mask<M> { - /// Set a bit inside a Mask. - const fn set_bit(mut self, bit: u32) -> Self { - let block = bit / 32; - - if block as usize >= M { - panic!("Generating masks for thumbv6/thumbv8m.base failed! Are you compiling for thumbv6 on an thumbv7 MCU or using an unsupported thumbv8m.base MCU?"); - } - - let offset = bit - (block * 32); - self.0[block as usize] |= 1 << offset; - self - } -} - -#[cfg(have_basepri)] -use cortex_m::register::basepri; - -#[cfg(have_basepri)] -#[inline(always)] -pub fn run<F>(priority: u8, f: F) -where - F: FnOnce(), -{ - if priority == 1 { - // If the priority of this interrupt is `1` then BASEPRI can only be `0` - f(); - unsafe { basepri::write(0) } - } else { - let initial = basepri::read(); - f(); - unsafe { basepri::write(initial) } - } -} - -#[cfg(not(have_basepri))] -#[inline(always)] -pub fn run<F>(_priority: u8, f: F) -where - F: FnOnce(), -{ - f(); -} - -pub struct Barrier { - inner: AtomicBool, -} - -impl Barrier { - pub const fn new() -> Self { - Barrier { - inner: AtomicBool::new(false), - } - } - - pub fn release(&self) { - self.inner.store(true, Ordering::Release); - } - - pub fn wait(&self) { - while !self.inner.load(Ordering::Acquire) { - core::hint::spin_loop() - } - } -} - -// Newtype over `Cell` that forbids mutation through a shared reference -pub struct Priority { - inner: Cell<u8>, -} - -impl Priority { - /// Create a new Priority - /// - /// # Safety - /// - /// Will overwrite the current Priority - #[inline(always)] - pub unsafe fn new(value: u8) -> Self { - Priority { - inner: Cell::new(value), - } - } - - /// Change the current priority to `value` - // These two methods are used by `lock` (see below) but can't be used from the RTIC application - #[inline(always)] - fn set(&self, value: u8) { - self.inner.set(value); - } - - /// Get the current priority - #[inline(always)] - fn get(&self) -> u8 { - self.inner.get() - } -} - -/// Const helper to check architecture -pub const fn have_basepri() -> bool { - #[cfg(have_basepri)] - { - true - } - - #[cfg(not(have_basepri))] - { - false - } -} - -#[inline(always)] -pub fn assert_send<T>() -where - T: Send, -{ -} - -#[inline(always)] -pub fn assert_sync<T>() -where - T: Sync, -{ -} - -#[inline(always)] -pub fn assert_monotonic<T>() -where - T: monotonic::Monotonic, -{ -} - -/// Lock implementation using BASEPRI and global Critical Section (CS) -/// -/// # Safety -/// -/// The system ceiling is raised from current to ceiling -/// by either -/// - raising the BASEPRI to the ceiling value, or -/// - disable all interrupts in case we want to -/// mask interrupts with maximum priority -/// -/// Dereferencing a raw pointer inside CS -/// -/// The priority.set/priority.get can safely be outside the CS -/// as being a context local cell (not affected by preemptions). -/// It is merely used in order to omit masking in case current -/// priority is current priority >= ceiling. -/// -/// Lock Efficiency: -/// Experiments validate (sub)-zero cost for CS implementation -/// (Sub)-zero as: -/// - Either zero OH (lock optimized out), or -/// - Amounting to an optimal assembly implementation -/// - The BASEPRI value is folded to a constant at compile time -/// - CS entry, single assembly instruction to write BASEPRI -/// - CS exit, single assembly instruction to write BASEPRI -/// - priority.set/get optimized out (their effect not) -/// - On par or better than any handwritten implementation of SRP -/// -/// Limitations: -/// The current implementation reads/writes BASEPRI once -/// even in some edge cases where this may be omitted. -/// Total OH of per task is max 2 clock cycles, negligible in practice -/// but can in theory be fixed. -/// -#[cfg(have_basepri)] -#[inline(always)] -pub unsafe fn lock<T, R, const M: usize>( - ptr: *mut T, - priority: &Priority, - ceiling: u8, - nvic_prio_bits: u8, - _mask: &[Mask<M>; 3], - f: impl FnOnce(&mut T) -> R, -) -> R { - let current = priority.get(); - - if current < ceiling { - if ceiling == (1 << nvic_prio_bits) { - priority.set(u8::max_value()); - let r = interrupt::free(|_| f(&mut *ptr)); - priority.set(current); - r - } else { - priority.set(ceiling); - basepri::write(logical2hw(ceiling, nvic_prio_bits)); - let r = f(&mut *ptr); - basepri::write(logical2hw(current, nvic_prio_bits)); - priority.set(current); - r - } - } else { - f(&mut *ptr) - } -} - -/// Lock implementation using interrupt masking -/// -/// # Safety -/// -/// The system ceiling is raised from current to ceiling -/// by computing a 32 bit `mask` (1 bit per interrupt) -/// 1: ceiling >= priority > current -/// 0: else -/// -/// On CS entry, `clear_enable_mask(mask)` disables interrupts -/// On CS exit, `set_enable_mask(mask)` re-enables interrupts -/// -/// The priority.set/priority.get can safely be outside the CS -/// as being a context local cell (not affected by preemptions). -/// It is merely used in order to omit masking in case -/// current priority >= ceiling. -/// -/// Dereferencing a raw pointer is done safely inside the CS -/// -/// Lock Efficiency: -/// Early experiments validate (sub)-zero cost for CS implementation -/// (Sub)-zero as: -/// - Either zero OH (lock optimized out), or -/// - Amounting to an optimal assembly implementation -/// - if ceiling == (1 << nvic_prio_bits) -/// - we execute the closure in a global critical section (interrupt free) -/// - CS entry cost, single write to core register -/// - CS exit cost, single write to core register -/// else -/// - The `mask` value is folded to a constant at compile time -/// - CS entry, single write of the 32 bit `mask` to the `icer` register -/// - CS exit, single write of the 32 bit `mask` to the `iser` register -/// - priority.set/get optimized out (their effect not) -/// - On par or better than any hand written implementation of SRP -/// -/// Limitations: -/// Current implementation does not allow for tasks with shared resources -/// to be bound to exception handlers, as these cannot be masked in HW. -/// -/// Possible solutions: -/// - Mask exceptions by global critical sections (interrupt::free) -/// - Temporary lower exception priority -/// -/// These possible solutions are set goals for future work -#[cfg(not(have_basepri))] -#[inline(always)] -pub unsafe fn lock<T, R, const M: usize>( - ptr: *mut T, - priority: &Priority, - ceiling: u8, - _nvic_prio_bits: u8, - masks: &[Mask<M>; 3], - f: impl FnOnce(&mut T) -> R, -) -> R { - let current = priority.get(); - if current < ceiling { - if ceiling >= 4 { - // safe to manipulate outside critical section - priority.set(ceiling); - // execute closure under protection of raised system ceiling - let r = interrupt::free(|_| f(&mut *ptr)); - // safe to manipulate outside critical section - priority.set(current); - r - } else { - // safe to manipulate outside critical section - priority.set(ceiling); - let mask = compute_mask(current, ceiling, masks); - clear_enable_mask(mask); - - // execute closure under protection of raised system ceiling - let r = f(&mut *ptr); - - set_enable_mask(mask); - - // safe to manipulate outside critical section - priority.set(current); - r - } - } else { - // execute closure without raising system ceiling - f(&mut *ptr) - } -} - -#[cfg(not(have_basepri))] -#[inline(always)] -fn compute_mask<const M: usize>(from_prio: u8, to_prio: u8, masks: &[Mask<M>; 3]) -> Mask<M> { - let mut res = Mask([0; M]); - masks[from_prio as usize..to_prio as usize] - .iter() - .for_each(|m| res |= *m); - res -} - -// enables interrupts -#[cfg(not(have_basepri))] -#[inline(always)] -unsafe fn set_enable_mask<const M: usize>(mask: Mask<M>) { - for i in 0..M { - // This check should involve compile time constants and be optimized out. - if mask.0[i] != 0 { - (*NVIC::PTR).iser[i].write(mask.0[i]); - } - } -} - -// disables interrupts -#[cfg(not(have_basepri))] -#[inline(always)] -unsafe fn clear_enable_mask<const M: usize>(mask: Mask<M>) { - for i in 0..M { - // This check should involve compile time constants and be optimized out. - if mask.0[i] != 0 { - (*NVIC::PTR).icer[i].write(mask.0[i]); - } - } -} - -#[inline] -#[must_use] -pub fn logical2hw(logical: u8, nvic_prio_bits: u8) -> u8 { - ((1 << nvic_prio_bits) - logical) << (8 - nvic_prio_bits) -} - -#[cfg(have_basepri)] -pub const fn create_mask<const N: usize, const M: usize>(_: [u32; N]) -> Mask<M> { - Mask([0; M]) -} - -#[cfg(not(have_basepri))] -pub const fn create_mask<const N: usize, const M: usize>(list_of_shifts: [u32; N]) -> Mask<M> { - let mut mask = Mask([0; M]); - let mut i = 0; - - while i < N { - let shift = list_of_shifts[i]; - i += 1; - mask = mask.set_bit(shift); - } - - mask -} - -#[cfg(have_basepri)] -pub const fn compute_mask_chunks<const L: usize>(_: [u32; L]) -> usize { - 0 -} - -/// Compute the number of u32 chunks needed to store the Mask value. -/// On M0, M0+ this should always end up being 1. -/// On M23 we will pick a number that allows us to store the highest index used by the code. -/// This means the amount of overhead will vary based on the actually interrupts used by the code. -#[cfg(not(have_basepri))] -pub const fn compute_mask_chunks<const L: usize>(ids: [u32; L]) -> usize { - let mut max: usize = 0; - let mut i = 0; - - while i < L { - let id = ids[i] as usize; - i += 1; - - if id > max { - max = id; - } - } - (max + 32) / 32 -} - -#[cfg(have_basepri)] -pub const fn no_basepri_panic() { - // For non-v6 all is fine -} - -#[cfg(not(have_basepri))] -pub const fn no_basepri_panic() { - panic!("Exceptions with shared resources are not allowed when compiling for thumbv6 or thumbv8m.base. Use local resources or `#[lock_free]` shared resources"); -} diff --git a/src/tq.rs b/src/tq.rs deleted file mode 100644 index 0f585ba..0000000 --- a/src/tq.rs +++ /dev/null @@ -1,179 +0,0 @@ -use crate::Monotonic; -use core::cmp::Ordering; -use heapless::sorted_linked_list::{LinkedIndexU16, Min, SortedLinkedList}; - -pub struct TimerQueue<Mono, Task, const N: usize>( - pub SortedLinkedList<NotReady<Mono, Task>, LinkedIndexU16, Min, N>, -) -where - Mono: Monotonic, - Task: Copy; - -impl<Mono, Task, const N: usize> TimerQueue<Mono, Task, N> -where - Mono: Monotonic, - Task: Copy, -{ - /// # Safety - /// - /// Writing to memory with a transmute in order to enable - /// interrupts of the ``SysTick`` timer - /// - /// Enqueue a task without checking if it is full - #[inline] - pub unsafe fn enqueue_unchecked<F1, F2>( - &mut self, - nr: NotReady<Mono, Task>, - enable_interrupt: F1, - pend_handler: F2, - mono: Option<&mut Mono>, - ) where - F1: FnOnce(), - F2: FnOnce(), - { - // Check if the top contains a non-empty element and if that element is - // greater than nr - let if_heap_max_greater_than_nr = - self.0.peek().map_or(true, |head| nr.instant < head.instant); - - if if_heap_max_greater_than_nr { - if Mono::DISABLE_INTERRUPT_ON_EMPTY_QUEUE && self.0.is_empty() { - if let Some(mono) = mono { - mono.enable_timer(); - } - enable_interrupt(); - } - - pend_handler(); - } - - self.0.push_unchecked(nr); - } - - /// Check if the timer queue is empty. - #[inline] - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } - - /// Cancel the marker value - pub fn cancel_marker(&mut self, marker: u32) -> Option<(Task, u8)> { - if let Some(val) = self.0.find_mut(|nr| nr.marker == marker) { - let nr = val.pop(); - - Some((nr.task, nr.index)) - } else { - None - } - } - - /// Update the instant at an marker value to a new instant - #[allow(clippy::result_unit_err)] - pub fn update_marker<F: FnOnce()>( - &mut self, - marker: u32, - new_marker: u32, - instant: Mono::Instant, - pend_handler: F, - ) -> Result<(), ()> { - if let Some(mut val) = self.0.find_mut(|nr| nr.marker == marker) { - val.instant = instant; - val.marker = new_marker; - - // On update pend the handler to reconfigure the next compare match - pend_handler(); - - Ok(()) - } else { - Err(()) - } - } - - /// Dequeue a task from the ``TimerQueue`` - pub fn dequeue<F>(&mut self, disable_interrupt: F, mono: &mut Mono) -> Option<(Task, u8)> - where - F: FnOnce(), - { - mono.clear_compare_flag(); - - if let Some(instant) = self.0.peek().map(|p| p.instant) { - if instant <= mono.now() { - // task became ready - let nr = unsafe { self.0.pop_unchecked() }; - - Some((nr.task, nr.index)) - } else { - // Set compare - mono.set_compare(instant); - - // Double check that the instant we set is really in the future, else - // dequeue. If the monotonic is fast enough it can happen that from the - // read of now to the set of the compare, the time can overflow. This is to - // guard against this. - if instant <= mono.now() { - let nr = unsafe { self.0.pop_unchecked() }; - - Some((nr.task, nr.index)) - } else { - None - } - } - } else { - // The queue is empty, disable the interrupt. - if Mono::DISABLE_INTERRUPT_ON_EMPTY_QUEUE { - disable_interrupt(); - mono.disable_timer(); - } - - None - } - } -} - -pub struct NotReady<Mono, Task> -where - Task: Copy, - Mono: Monotonic, -{ - pub index: u8, - pub instant: Mono::Instant, - pub task: Task, - pub marker: u32, -} - -impl<Mono, Task> Eq for NotReady<Mono, Task> -where - Task: Copy, - Mono: Monotonic, -{ -} - -impl<Mono, Task> Ord for NotReady<Mono, Task> -where - Task: Copy, - Mono: Monotonic, -{ - fn cmp(&self, other: &Self) -> Ordering { - self.instant.cmp(&other.instant) - } -} - -impl<Mono, Task> PartialEq for NotReady<Mono, Task> -where - Task: Copy, - Mono: Monotonic, -{ - fn eq(&self, other: &Self) -> bool { - self.instant == other.instant - } -} - -impl<Mono, Task> PartialOrd for NotReady<Mono, Task> -where - Task: Copy, - Mono: Monotonic, -{ - fn partial_cmp(&self, other: &Self) -> Option<Ordering> { - Some(self.cmp(other)) - } -} diff --git a/ui/extern-interrupt-not-enough.stderr b/ui/extern-interrupt-not-enough.stderr deleted file mode 100644 index a667c58..0000000 --- a/ui/extern-interrupt-not-enough.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: not enough interrupts to dispatch all software tasks (need: 1; given: 0) - --> $DIR/extern-interrupt-not-enough.rs:17:8 - | -17 | fn a(_: a::Context) {} - | ^ diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index f1c468e..3c72bf1 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -1,9 +1,15 @@ [package] name = "xtask" -version = "0.1.0" -edition = "2018" +version = "0.0.0" +edition = "2021" +publish = false [dependencies] anyhow = "1.0.43" os_pipe = "1.1.2" -structopt = "0.3.22" +clap = { version = "4", features = ["derive"] } +env_logger = "0.10.0" +log = "0.4.17" +rayon = "1.6.1" +diffy = "0.3.0" +exitcode = "1.1.2" diff --git a/xtask/src/argument_parsing.rs b/xtask/src/argument_parsing.rs new file mode 100644 index 0000000..8795213 --- /dev/null +++ b/xtask/src/argument_parsing.rs @@ -0,0 +1,260 @@ +use crate::{command::CargoCommand, ARMV6M, ARMV7M, ARMV8MBASE, ARMV8MMAIN, DEFAULT_FEATURES}; +use clap::{Args, Parser, Subcommand}; +use core::fmt; + +#[derive(clap::ValueEnum, Copy, Clone, Debug)] +pub enum Package { + Rtic, + RticCommon, + RticMacros, + RticMonotonics, + RticSync, + RticTime, +} + +impl fmt::Display for Package { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.name()) + } +} + +impl Package { + pub fn name(&self) -> &str { + match self { + Package::Rtic => "rtic", + Package::RticCommon => "rtic-common", + Package::RticMacros => "rtic-macros", + Package::RticMonotonics => "rtic-monotonics", + Package::RticSync => "rtic-sync", + Package::RticTime => "rtic-time", + } + } +} + +pub struct TestMetadata {} + +impl TestMetadata { + pub fn match_package(package: Package, backend: Backends) -> CargoCommand<'static> { + match package { + Package::Rtic => { + let features = Some(format!( + "{},{},{}", + DEFAULT_FEATURES, + backend.to_rtic_feature(), + backend.to_rtic_uitest_feature(), + )); + CargoCommand::Test { + package: Some(package), + features, + test: Some("ui".to_owned()), + } + } + Package::RticMacros => CargoCommand::Test { + package: Some(package), + features: Some(backend.to_rtic_macros_feature().to_owned()), + test: None, + }, + Package::RticSync => CargoCommand::Test { + package: Some(package), + features: Some("testing".to_owned()), + test: None, + }, + Package::RticCommon => CargoCommand::Test { + package: Some(package), + features: Some("testing".to_owned()), + test: None, + }, + Package::RticMonotonics => CargoCommand::Test { + package: Some(package), + features: None, + test: None, + }, + Package::RticTime => CargoCommand::Test { + package: Some(package), + features: None, + test: None, + }, + } + } +} + +#[derive(clap::ValueEnum, Copy, Clone, Default, Debug)] +pub enum Backends { + Thumbv6, + #[default] + Thumbv7, + Thumbv8Base, + Thumbv8Main, +} + +impl Backends { + #[allow(clippy::wrong_self_convention)] + pub fn to_target(&self) -> &str { + match self { + Backends::Thumbv6 => ARMV6M, + Backends::Thumbv7 => ARMV7M, + Backends::Thumbv8Base => ARMV8MBASE, + Backends::Thumbv8Main => ARMV8MMAIN, + } + } + + #[allow(clippy::wrong_self_convention)] + pub fn to_rtic_feature(&self) -> &str { + match self { + Backends::Thumbv6 => "thumbv6-backend", + Backends::Thumbv7 => "thumbv7-backend", + Backends::Thumbv8Base => "thumbv8base-backend", + Backends::Thumbv8Main => "thumbv8main-backend", + } + } + #[allow(clippy::wrong_self_convention)] + pub fn to_rtic_macros_feature(&self) -> &str { + match self { + Backends::Thumbv6 | Backends::Thumbv8Base => "cortex-m-source-masking", + Backends::Thumbv7 | Backends::Thumbv8Main => "cortex-m-basepri", + } + } + #[allow(clippy::wrong_self_convention)] + pub fn to_rtic_uitest_feature(&self) -> &str { + match self { + Backends::Thumbv6 | Backends::Thumbv8Base => "rtic-uitestv6", + Backends::Thumbv7 | Backends::Thumbv8Main => "rtic-uitestv7", + } + } +} + +#[derive(Copy, Clone, Default, Debug)] +pub enum BuildOrCheck { + #[default] + Check, + Build, +} + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +/// RTIC xtask powered testing toolbox +pub struct Cli { + /// For which backend to build (defaults to thumbv7) + #[arg(value_enum, short, long)] + pub backend: Option<Backends>, + + /// List of comma separated examples to include, all others are excluded + /// + /// If omitted all examples are included + /// + /// Example: `cargo xtask --example complex,spawn,init` + /// would include complex, spawn and init + #[arg(short, long, group = "example_group")] + pub example: Option<String>, + + /// List of comma separated examples to exclude, all others are included + /// + /// If omitted all examples are included + /// + /// Example: `cargo xtask --excludeexample complex,spawn,init` + /// would exclude complex, spawn and init + #[arg(long, group = "example_group")] + pub exampleexclude: Option<String>, + + /// Enable more verbose output, repeat up to `-vvv` for even more + #[arg(short, long, action = clap::ArgAction::Count)] + pub verbose: u8, + + /// Subcommand selecting operation + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Debug, Subcommand)] +pub enum Commands { + /// Check formatting + FormatCheck(PackageOpt), + + /// Format code + Format(PackageOpt), + + /// Run clippy + Clippy(PackageOpt), + + /// Check all packages + Check(PackageOpt), + + /// Build all packages + Build(PackageOpt), + + /// Check all examples + ExampleCheck, + + /// Build all examples + ExampleBuild, + + /// Run `cargo size` on selected or all examples + /// + /// To pass options to `cargo size`, add `--` and then the following + /// arguments will be passed on + /// + /// Example: `cargo xtask size -- -A` + Size(Arg), + + /// Run examples in QEMU and compare against expected output + /// + /// Example runtime output is matched against `rtic/ci/expected/` + /// + /// Requires that an ARM target is selected + Qemu(QemuAndRun), + + /// Run examples through embedded-ci and compare against expected output + /// + /// unimplemented!() For now TODO, equal to Qemu + /// + /// Example runtime output is matched against `rtic/ci/expected/` + /// + /// Requires that an ARM target is selected + Run(QemuAndRun), + + /// Build docs + /// + /// To pass options to `cargo doc`, add `--` and then the following + /// arguments will be passed on + /// + /// Example: `cargo xtask doc -- --open` + Doc(Arg), + + /// Run tests + Test(PackageOpt), + + /// Build books with mdbook + Book(Arg), +} + +#[derive(Args, Debug)] +/// Restrict to package, or run on whole workspace +pub struct PackageOpt { + /// For which package/workspace member to operate + /// + /// If omitted, work on all + pub package: Option<Package>, +} + +#[derive(Args, Debug)] +pub struct QemuAndRun { + /// If expected output is missing or mismatching, recreate the file + /// + /// This overwrites only missing or mismatching + #[arg(long)] + pub overwrite_expected: bool, +} + +#[derive(Debug, Parser)] +pub struct Arg { + /// Options to pass to `cargo size` + #[command(subcommand)] + pub arguments: Option<ExtraArguments>, +} + +#[derive(Clone, Debug, PartialEq, Parser)] +pub enum ExtraArguments { + /// All remaining flags and options + #[command(external_subcommand)] + Other(Vec<String>), +} diff --git a/xtask/src/build.rs b/xtask/src/build.rs index 148a9fd..a11b4e0 100644 --- a/xtask/src/build.rs +++ b/xtask/src/build.rs @@ -2,7 +2,7 @@ use std::{fs, path::Path}; const HEX_BUILD_ROOT: &str = "ci/builds"; -/// make sure we're starting with a clean,but existing slate +/// Make sure we're starting with a clean, but existing slate pub fn init_build_dir() -> anyhow::Result<()> { if Path::new(HEX_BUILD_ROOT).exists() { fs::remove_dir_all(HEX_BUILD_ROOT) diff --git a/xtask/src/cargo_commands.rs b/xtask/src/cargo_commands.rs new file mode 100644 index 0000000..7ac7aea --- /dev/null +++ b/xtask/src/cargo_commands.rs @@ -0,0 +1,269 @@ +use crate::{ + argument_parsing::{Backends, BuildOrCheck, ExtraArguments, Package, PackageOpt, TestMetadata}, + command::{BuildMode, CargoCommand}, + command_parser, package_feature_extractor, DEFAULT_FEATURES, +}; +use log::error; +use rayon::prelude::*; + +/// Cargo command to either build or check +pub fn cargo( + operation: BuildOrCheck, + cargoarg: &Option<&str>, + package: &PackageOpt, + backend: Backends, +) -> anyhow::Result<()> { + let features = package_feature_extractor(package, backend); + + let command = match operation { + BuildOrCheck::Check => CargoCommand::Check { + cargoarg, + package: package.package, + target: backend.to_target(), + features, + mode: BuildMode::Release, + }, + BuildOrCheck::Build => CargoCommand::Build { + cargoarg, + package: package.package, + target: backend.to_target(), + features, + mode: BuildMode::Release, + }, + }; + command_parser(&command, false)?; + Ok(()) +} + +/// Cargo command to either build or check all examples +/// +/// The examples are in rtic/examples +pub fn cargo_example( + operation: BuildOrCheck, + cargoarg: &Option<&str>, + backend: Backends, + examples: &[String], +) -> anyhow::Result<()> { + examples.into_par_iter().for_each(|example| { + let features = Some(format!( + "{},{}", + DEFAULT_FEATURES, + backend.to_rtic_feature() + )); + + let command = match operation { + BuildOrCheck::Check => CargoCommand::ExampleCheck { + cargoarg, + example, + target: backend.to_target(), + features, + mode: BuildMode::Release, + }, + BuildOrCheck::Build => CargoCommand::ExampleBuild { + cargoarg, + example, + target: backend.to_target(), + features, + mode: BuildMode::Release, + }, + }; + + if let Err(err) = command_parser(&command, false) { + error!("{err}"); + } + }); + + Ok(()) +} + +/// Run cargo clippy on selected package +pub fn cargo_clippy( + cargoarg: &Option<&str>, + package: &PackageOpt, + backend: Backends, +) -> anyhow::Result<()> { + let features = package_feature_extractor(package, backend); + command_parser( + &CargoCommand::Clippy { + cargoarg, + package: package.package, + target: backend.to_target(), + features, + }, + false, + )?; + Ok(()) +} + +/// Run cargo fmt on selected package +pub fn cargo_format( + cargoarg: &Option<&str>, + package: &PackageOpt, + check_only: bool, +) -> anyhow::Result<()> { + command_parser( + &CargoCommand::Format { + cargoarg, + package: package.package, + check_only, + }, + false, + )?; + Ok(()) +} + +/// Run cargo doc +pub fn cargo_doc( + cargoarg: &Option<&str>, + backend: Backends, + arguments: &Option<ExtraArguments>, +) -> anyhow::Result<()> { + let features = Some(format!( + "{},{}", + DEFAULT_FEATURES, + backend.to_rtic_feature() + )); + + command_parser( + &CargoCommand::Doc { + cargoarg, + features, + arguments: arguments.clone(), + }, + false, + )?; + Ok(()) +} + +/// Run cargo test on the selcted package or all packages +/// +/// If no package is specified, loop through all packages +pub fn cargo_test(package: &PackageOpt, backend: Backends) -> anyhow::Result<()> { + if let Some(package) = package.package { + let cmd = TestMetadata::match_package(package, backend); + command_parser(&cmd, false)?; + } else { + // Iterate over all workspace packages + for package in [ + Package::Rtic, + Package::RticCommon, + Package::RticMacros, + Package::RticMonotonics, + Package::RticSync, + Package::RticTime, + ] { + let mut error_messages = vec![]; + let cmd = &TestMetadata::match_package(package, backend); + if let Err(err) = command_parser(cmd, false) { + error_messages.push(err); + } + + if !error_messages.is_empty() { + for err in error_messages { + error!("{err}"); + } + } + } + } + Ok(()) +} + +/// Use mdbook to build the book +pub fn cargo_book(arguments: &Option<ExtraArguments>) -> anyhow::Result<()> { + command_parser( + &CargoCommand::Book { + arguments: arguments.clone(), + }, + false, + )?; + Ok(()) +} + +/// Run examples +/// +/// Supports updating the expected output via the overwrite argument +pub fn run_test( + cargoarg: &Option<&str>, + backend: Backends, + examples: &[String], + overwrite: bool, +) -> anyhow::Result<()> { + examples.into_par_iter().for_each(|example| { + let cmd = CargoCommand::ExampleBuild { + cargoarg: &Some("--quiet"), + example, + target: backend.to_target(), + features: Some(format!( + "{},{}", + DEFAULT_FEATURES, + backend.to_rtic_feature() + )), + mode: BuildMode::Release, + }; + if let Err(err) = command_parser(&cmd, false) { + error!("{err}"); + } + + let cmd = CargoCommand::Qemu { + cargoarg, + example, + target: backend.to_target(), + features: Some(format!( + "{},{}", + DEFAULT_FEATURES, + backend.to_rtic_feature() + )), + mode: BuildMode::Release, + }; + + if let Err(err) = command_parser(&cmd, overwrite) { + error!("{err}"); + } + }); + + Ok(()) +} + +/// Check the binary sizes of examples +pub fn build_and_check_size( + cargoarg: &Option<&str>, + backend: Backends, + examples: &[String], + arguments: &Option<ExtraArguments>, +) -> anyhow::Result<()> { + examples.into_par_iter().for_each(|example| { + // Make sure the requested example(s) are built + let cmd = CargoCommand::ExampleBuild { + cargoarg: &Some("--quiet"), + example, + target: backend.to_target(), + features: Some(format!( + "{},{}", + DEFAULT_FEATURES, + backend.to_rtic_feature() + )), + mode: BuildMode::Release, + }; + if let Err(err) = command_parser(&cmd, false) { + error!("{err}"); + } + + let cmd = CargoCommand::ExampleSize { + cargoarg, + example, + target: backend.to_target(), + features: Some(format!( + "{},{}", + DEFAULT_FEATURES, + backend.to_rtic_feature() + )), + mode: BuildMode::Release, + arguments: arguments.clone(), + }; + if let Err(err) = command_parser(&cmd, false) { + error!("{err}"); + } + }); + + Ok(()) +} diff --git a/xtask/src/command.rs b/xtask/src/command.rs index 100888c..6e91a52 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -1,4 +1,4 @@ -use crate::{RunResult, TestRunError}; +use crate::{debug, ExtraArguments, Package, RunResult, TestRunError}; use core::fmt; use os_pipe::pipe; use std::{fs::File, io::Read, process::Command}; @@ -12,64 +12,364 @@ pub enum BuildMode { #[derive(Debug)] pub enum CargoCommand<'a> { + // For future embedded-ci + #[allow(dead_code)] Run { + cargoarg: &'a Option<&'a str>, example: &'a str, target: &'a str, - features: Option<&'a str>, + features: Option<String>, mode: BuildMode, }, - BuildAll { + Qemu { + cargoarg: &'a Option<&'a str>, + example: &'a str, + target: &'a str, + features: Option<String>, + mode: BuildMode, + }, + ExampleBuild { + cargoarg: &'a Option<&'a str>, + example: &'a str, target: &'a str, - features: Option<&'a str>, + features: Option<String>, mode: BuildMode, }, - // Size { - // example_paths: Vec<&'a Path>, - // }, - // Clean, + ExampleCheck { + cargoarg: &'a Option<&'a str>, + example: &'a str, + target: &'a str, + features: Option<String>, + mode: BuildMode, + }, + Build { + cargoarg: &'a Option<&'a str>, + package: Option<Package>, + target: &'a str, + features: Option<String>, + mode: BuildMode, + }, + Check { + cargoarg: &'a Option<&'a str>, + package: Option<Package>, + target: &'a str, + features: Option<String>, + mode: BuildMode, + }, + Clippy { + cargoarg: &'a Option<&'a str>, + package: Option<Package>, + target: &'a str, + features: Option<String>, + }, + Format { + cargoarg: &'a Option<&'a str>, + package: Option<Package>, + check_only: bool, + }, + Doc { + cargoarg: &'a Option<&'a str>, + features: Option<String>, + arguments: Option<ExtraArguments>, + }, + Test { + package: Option<Package>, + features: Option<String>, + test: Option<String>, + }, + Book { + arguments: Option<ExtraArguments>, + }, + ExampleSize { + cargoarg: &'a Option<&'a str>, + example: &'a str, + target: &'a str, + features: Option<String>, + mode: BuildMode, + arguments: Option<ExtraArguments>, + }, } impl<'a> CargoCommand<'a> { - fn name(&self) -> &str { + fn command(&self) -> &str { + match self { + CargoCommand::Run { .. } | CargoCommand::Qemu { .. } => "run", + CargoCommand::ExampleCheck { .. } | CargoCommand::Check { .. } => "check", + CargoCommand::ExampleBuild { .. } | CargoCommand::Build { .. } => "build", + CargoCommand::ExampleSize { .. } => "size", + CargoCommand::Clippy { .. } => "clippy", + CargoCommand::Format { .. } => "fmt", + CargoCommand::Doc { .. } => "doc", + CargoCommand::Book { .. } => "build", + CargoCommand::Test { .. } => "test", + } + } + pub fn executable(&self) -> &str { match self { - CargoCommand::Run { .. } => "run", - // CargoCommand::Size { example_paths: _ } => "rust-size", - CargoCommand::BuildAll { .. } => "build", + CargoCommand::Run { .. } + | CargoCommand::Qemu { .. } + | CargoCommand::ExampleCheck { .. } + | CargoCommand::Check { .. } + | CargoCommand::ExampleBuild { .. } + | CargoCommand::Build { .. } + | CargoCommand::ExampleSize { .. } + | CargoCommand::Clippy { .. } + | CargoCommand::Format { .. } + | CargoCommand::Test { .. } + | CargoCommand::Doc { .. } => "cargo", + CargoCommand::Book { .. } => "mdbook", } } pub fn args(&self) -> Vec<&str> { match self { + // For future embedded-ci, for now the same as Qemu CargoCommand::Run { + cargoarg, example, target, features, mode, } => { - let mut args = vec![ - self.name(), - "--example", - example, - "--target", - target, - "--features", - "test-critical-section", - ]; + let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + args.extend_from_slice(&[self.command(), "--example", example, "--target", target]); - if let Some(feature_name) = features { - args.extend_from_slice(&["--features", feature_name]); + if let Some(feature) = features { + args.extend_from_slice(&["--features", feature]); + } + if let Some(flag) = mode.to_flag() { + args.push(flag); + } + args + } + CargoCommand::Qemu { + cargoarg, + example, + target, + features, + mode, + } => { + let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + args.extend_from_slice(&[self.command(), "--example", example, "--target", target]); + + if let Some(feature) = features { + args.extend_from_slice(&["--features", feature]); } if let Some(flag) = mode.to_flag() { args.push(flag); } args } - CargoCommand::BuildAll { + CargoCommand::Build { + cargoarg, + package, target, features, mode, } => { - let mut args = vec![self.name(), "--examples", "--target", target]; + let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + + args.extend_from_slice(&[self.command(), "--target", target]); + + if let Some(package) = package { + args.extend_from_slice(&["--package", package.name()]); + } + + if let Some(feature) = features { + args.extend_from_slice(&["--features", feature]); + } + if let Some(flag) = mode.to_flag() { + args.push(flag); + } + args + } + CargoCommand::Check { + cargoarg, + package, + target: _, + features, + mode, + } => { + let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + args.extend_from_slice(&[self.command()]); + + if let Some(package) = package { + args.extend_from_slice(&["--package", package.name()]); + } + + if let Some(feature) = features { + args.extend_from_slice(&["--features", feature]); + } + if let Some(flag) = mode.to_flag() { + args.push(flag); + } + args + } + CargoCommand::Clippy { + cargoarg, + package, + target: _, + features, + } => { + let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + + args.extend_from_slice(&[self.command()]); + + if let Some(package) = package { + args.extend_from_slice(&["--package", package.name()]); + } + + if let Some(feature) = features { + args.extend_from_slice(&["--features", feature]); + } + args + } + CargoCommand::Doc { + cargoarg, + features, + arguments, + } => { + let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + + args.extend_from_slice(&[self.command()]); + + if let Some(feature) = features { + args.extend_from_slice(&["--features", feature]); + } + if let Some(ExtraArguments::Other(arguments)) = arguments { + for arg in arguments { + args.extend_from_slice(&[arg.as_str()]); + } + } + args + } + CargoCommand::Test { + package, + features, + test, + } => { + let mut args = vec!["+nightly"]; + args.extend_from_slice(&[self.command()]); + + if let Some(package) = package { + args.extend_from_slice(&["--package", package.name()]); + } + + if let Some(feature) = features { + args.extend_from_slice(&["--features", feature]); + } + if let Some(test) = test { + args.extend_from_slice(&["--test", test]); + } + args + } + CargoCommand::Book { arguments } => { + let mut args = vec![]; + + if let Some(ExtraArguments::Other(arguments)) = arguments { + for arg in arguments { + args.extend_from_slice(&[arg.as_str()]); + } + } else { + // If no argument given, run mdbook build + // with default path to book + args.extend_from_slice(&[self.command()]); + args.extend_from_slice(&["book/en"]); + } + args + } + CargoCommand::Format { + cargoarg, + package, + check_only, + } => { + let mut args = vec!["+nightly", self.command()]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + + if let Some(package) = package { + args.extend_from_slice(&["--package", package.name()]); + } + if *check_only { + args.extend_from_slice(&["--check"]); + } + + args + } + CargoCommand::ExampleBuild { + cargoarg, + example, + target, + features, + mode, + } => { + let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + args.extend_from_slice(&[self.command(), "--example", example, "--target", target]); + + if let Some(feature) = features { + args.extend_from_slice(&["--features", feature]); + } + if let Some(flag) = mode.to_flag() { + args.push(flag); + } + args + } + CargoCommand::ExampleCheck { + cargoarg, + example, + target, + features, + mode, + } => { + let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + args.extend_from_slice(&[self.command(), "--example", example, "--target", target]); + + if let Some(feature) = features { + args.extend_from_slice(&["--features", feature]); + } + if let Some(flag) = mode.to_flag() { + args.push(flag); + } + args + } + CargoCommand::ExampleSize { + cargoarg, + example, + target, + features, + mode, + arguments, + } => { + let mut args = vec!["+nightly"]; + if let Some(cargoarg) = cargoarg { + args.extend_from_slice(&[cargoarg]); + } + args.extend_from_slice(&[self.command(), "--example", example, "--target", target]); if let Some(feature_name) = features { args.extend_from_slice(&["--features", feature_name]); @@ -77,25 +377,21 @@ impl<'a> CargoCommand<'a> { if let Some(flag) = mode.to_flag() { args.push(flag); } + if let Some(ExtraArguments::Other(arguments)) = arguments { + // Arguments to cargo size must be passed after "--" + args.extend_from_slice(&["--"]); + for arg in arguments { + args.extend_from_slice(&[arg.as_str()]); + } + } args - } // CargoCommand::Size { example_paths } => { - // example_paths.iter().map(|p| p.to_str().unwrap()).collect() - // } - } - } - - pub fn command(&self) -> &str { - match self { - // we need to cheat a little here: - // `cargo size` can't be ran on multiple files, so we're using `rust-size` instead – - // which isn't a command that starts wizh `cargo`. So we're sneakily swapping them out :) - // CargoCommand::Size { .. } => "rust-size", - _ => "cargo", + } } } } impl BuildMode { + #[allow(clippy::wrong_self_convention)] pub fn to_flag(&self) -> Option<&str> { match self { BuildMode::Release => Some("--release"), @@ -111,49 +407,55 @@ impl fmt::Display for BuildMode { BuildMode::Debug => "debug", }; - write!(f, "{}", cmd) + write!(f, "{cmd}") } } pub fn run_command(command: &CargoCommand) -> anyhow::Result<RunResult> { let (mut reader, writer) = pipe()?; - println!("👟 {} {}", command.command(), command.args().join(" ")); + let (mut error_reader, error_writer) = pipe()?; + debug!("👟 {} {}", command.executable(), command.args().join(" ")); - let mut handle = Command::new(command.command()) + let mut handle = Command::new(command.executable()) .args(command.args()) .stdout(writer) + .stderr(error_writer) .spawn()?; // retrieve output and clean up - let mut output = String::new(); - reader.read_to_string(&mut output)?; + let mut stdout = String::new(); + reader.read_to_string(&mut stdout)?; let exit_status = handle.wait()?; + let mut stderr = String::new(); + error_reader.read_to_string(&mut stderr)?; + Ok(RunResult { exit_status, - output, + stdout, + stderr, }) } -/// Check if `run` was sucessful. +/// Check if `run` was successful. /// returns Ok in case the run went as expected, /// Err otherwise -pub fn run_successful(run: &RunResult, expected_output_file: String) -> Result<(), TestRunError> { +pub fn run_successful(run: &RunResult, expected_output_file: &str) -> Result<(), TestRunError> { let mut file_handle = - File::open(expected_output_file.clone()).map_err(|_| TestRunError::FileError { - file: expected_output_file.clone(), + File::open(expected_output_file).map_err(|_| TestRunError::FileError { + file: expected_output_file.to_owned(), })?; let mut expected_output = String::new(); file_handle .read_to_string(&mut expected_output) .map_err(|_| TestRunError::FileError { - file: expected_output_file.clone(), + file: expected_output_file.to_owned(), })?; - if expected_output != run.output { + if expected_output != run.stdout { Err(TestRunError::FileCmpError { expected: expected_output.clone(), - got: run.output.clone(), + got: run.stdout.clone(), }) } else if !run.exit_status.success() { Err(TestRunError::CommandError(run.clone())) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 76ce04b..aed74eb 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,36 +1,51 @@ +mod argument_parsing; mod build; +mod cargo_commands; mod command; use anyhow::bail; +use argument_parsing::{ExtraArguments, Package}; +use clap::Parser; use core::fmt; +use diffy::{create_patch, PatchFormatter}; use std::{ error::Error, ffi::OsString, + fs::File, + io::prelude::*, path::{Path, PathBuf}, process, process::ExitStatus, str, }; -use structopt::StructOpt; + +use env_logger::Env; +use log::{debug, error, info, log_enabled, trace, Level}; use crate::{ + argument_parsing::{Backends, BuildOrCheck, Cli, Commands, PackageOpt}, build::init_build_dir, - command::{run_command, run_successful, BuildMode, CargoCommand}, + cargo_commands::{ + build_and_check_size, cargo, cargo_book, cargo_clippy, cargo_doc, cargo_example, + cargo_format, cargo_test, run_test, + }, + command::{run_command, run_successful, CargoCommand}, }; +// x86_64-unknown-linux-gnu +const _X86_64: &str = "x86_64-unknown-linux-gnu"; const ARMV6M: &str = "thumbv6m-none-eabi"; const ARMV7M: &str = "thumbv7m-none-eabi"; +const ARMV8MBASE: &str = "thumbv8m.base-none-eabi"; +const ARMV8MMAIN: &str = "thumbv8m.main-none-eabi"; -#[derive(Debug, StructOpt)] -struct Options { - #[structopt(short, long)] - target: String, -} +const DEFAULT_FEATURES: &str = "test-critical-section"; #[derive(Debug, Clone)] pub struct RunResult { exit_status: ExitStatus, - output: String, + stdout: String, + stderr: String, } #[derive(Debug)] @@ -41,31 +56,31 @@ pub enum TestRunError { CommandError(RunResult), IncompatibleCommand, } - impl fmt::Display for TestRunError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { TestRunError::FileCmpError { expected, got } => { - writeln!(f, "Differing output in files.")?; - writeln!(f, "")?; - writeln!(f, "Expected:")?; - writeln!(f, "{}", expected)?; - writeln!(f, "")?; - writeln!(f, "Got:")?; - write!(f, "{}", got) + let patch = create_patch(expected, got); + writeln!(f, "Differing output in files.\n")?; + let pf = PatchFormatter::new().with_color(); + writeln!(f, "{}", pf.fmt_patch(&patch))?; + write!( + f, + "See flag --overwrite-expected to create/update expected output." + ) } TestRunError::FileError { file } => { - write!(f, "File error on: {}", file) + write!(f, "File error on: {file}\nSee flag --overwrite-expected to create/update expected output.") } TestRunError::CommandError(e) => { write!( f, "Command failed with exit status {}: {}", - e.exit_status, e.output + e.exit_status, e.stdout ) } TestRunError::PathConversionError(p) => { - write!(f, "Can't convert path from `OsString` to `String`: {:?}", p) + write!(f, "Can't convert path from `OsString` to `String`: {p:?}") } TestRunError::IncompatibleCommand => { write!(f, "Can't run that command in this context") @@ -80,95 +95,262 @@ fn main() -> anyhow::Result<()> { // if there's an `xtask` folder, we're *probably* at the root of this repo (we can't just // check the name of `env::current_dir()` because people might clone it into a different name) let probably_running_from_repo_root = Path::new("./xtask").exists(); - if probably_running_from_repo_root == false { - bail!("xtasks can only be executed from the root of the `cortex-m-rtic` repository"); + if !probably_running_from_repo_root { + bail!("xtasks can only be executed from the root of the `rtic` repository"); } - let targets = [ARMV7M, ARMV6M]; - - let examples: Vec<_> = std::fs::read_dir("./examples")? - .filter_map(|path| { - path.map(|p| p.path().file_stem().unwrap().to_str().unwrap().to_string()) - .ok() - }) + let examples: Vec<_> = std::fs::read_dir("./rtic/examples")? + .filter_map(|p| p.ok()) + .map(|p| p.path()) + .filter(|p| p.display().to_string().ends_with(".rs")) + .map(|path| path.file_stem().unwrap().to_str().unwrap().to_string()) .collect(); - let opts = Options::from_args(); - let target = &opts.target; + let cli = Cli::parse(); - init_build_dir()?; + let env_logger_default_level = match cli.verbose { + 0 => Env::default().default_filter_or("error"), + 1 => Env::default().default_filter_or("info"), + 2 => Env::default().default_filter_or("debug"), + _ => Env::default().default_filter_or("trace"), + }; + env_logger::Builder::from_env(env_logger_default_level) + .format_module_path(false) + .format_timestamp(None) + .init(); - if target == "all" { - for t in targets { - run_test(t, &examples)?; - } - } else if targets.contains(&target.as_str()) { - run_test(&target, &examples)?; + trace!("default logging level: {0}", cli.verbose); + + let backend = if let Some(backend) = cli.backend { + backend } else { - eprintln!( - "The target you specified is not available. Available targets are:\ - \n{:?}\n\ - as well as `all` (testing on all of the above)", - targets - ); - process::exit(1); - } + Backends::default() + }; - Ok(()) -} + let example = cli.example; + let exampleexclude = cli.exampleexclude; + + let examples_to_run = { + let mut examples_to_run = examples.clone(); + + if let Some(example) = example { + examples_to_run = examples.clone(); + let examples_to_exclude = example.split(',').collect::<Vec<&str>>(); + // From the list of all examples, remove all not listed as included + for ex in examples_to_exclude { + examples_to_run.retain(|x| *x.as_str() == *ex); + } + }; -fn run_test(target: &str, examples: &[String]) -> anyhow::Result<()> { - arm_example(&CargoCommand::BuildAll { - target, - features: None, - mode: BuildMode::Release, - })?; - - for example in examples { - let cmd = CargoCommand::Run { - example, - target, - features: None, - mode: BuildMode::Release, + if let Some(example) = exampleexclude { + examples_to_run = examples.clone(); + let examples_to_exclude = example.split(',').collect::<Vec<&str>>(); + // From the list of all examples, remove all those listed as excluded + for ex in examples_to_exclude { + examples_to_run.retain(|x| *x.as_str() != *ex); + } }; - arm_example(&cmd)?; + if log_enabled!(Level::Trace) { + trace!("All examples:\n{examples:?} number: {}", examples.len()); + trace!( + "examples_to_run:\n{examples_to_run:?} number: {}", + examples_to_run.len() + ); + } + + if examples_to_run.is_empty() { + error!( + "\nThe example(s) you specified is not available. Available examples are:\ + \n{examples:#?}\n\ + By default if example flag is emitted, all examples are tested.", + ); + process::exit(exitcode::USAGE); + } else { + } + examples_to_run + }; + + init_build_dir()?; + #[allow(clippy::if_same_then_else)] + let cargologlevel = if log_enabled!(Level::Trace) { + Some("-v") + } else if log_enabled!(Level::Debug) { + None + } else if log_enabled!(Level::Info) { + None + } else if log_enabled!(Level::Warn) || log_enabled!(Level::Error) { + None + } else { + // Off case + Some("--quiet") + }; + + match cli.command { + Commands::FormatCheck(args) => { + info!("Running cargo fmt: {args:?}"); + let check_only = true; + cargo_format(&cargologlevel, &args, check_only)?; + } + Commands::Format(args) => { + info!("Running cargo fmt --check: {args:?}"); + let check_only = false; + cargo_format(&cargologlevel, &args, check_only)?; + } + Commands::Clippy(args) => { + info!("Running clippy on backend: {backend:?}"); + cargo_clippy(&cargologlevel, &args, backend)?; + } + Commands::Check(args) => { + info!("Checking on backend: {backend:?}"); + cargo(BuildOrCheck::Check, &cargologlevel, &args, backend)?; + } + Commands::Build(args) => { + info!("Building for backend: {backend:?}"); + cargo(BuildOrCheck::Build, &cargologlevel, &args, backend)?; + } + Commands::ExampleCheck => { + info!("Checking on backend: {backend:?}"); + cargo_example( + BuildOrCheck::Check, + &cargologlevel, + backend, + &examples_to_run, + )?; + } + Commands::ExampleBuild => { + info!("Building for backend: {backend:?}"); + cargo_example( + BuildOrCheck::Build, + &cargologlevel, + backend, + &examples_to_run, + )?; + } + Commands::Size(args) => { + // x86_64 target not valid + info!("Measuring for backend: {backend:?}"); + build_and_check_size(&cargologlevel, backend, &examples_to_run, &args.arguments)?; + } + Commands::Qemu(args) | Commands::Run(args) => { + // x86_64 target not valid + info!("Testing for backend: {backend:?}"); + run_test( + &cargologlevel, + backend, + &examples_to_run, + args.overwrite_expected, + )?; + } + Commands::Doc(args) => { + info!("Running cargo doc on backend: {backend:?}"); + cargo_doc(&cargologlevel, backend, &args.arguments)?; + } + Commands::Test(args) => { + info!("Running cargo test on backend: {backend:?}"); + cargo_test(&args, backend)?; + } + Commands::Book(args) => { + info!("Running mdbook"); + cargo_book(&args.arguments)?; + } } Ok(()) } +/// Get the features needed given the selected package +/// +/// Without package specified the features for RTIC are required +/// With only a single package which is not RTIC, no special +/// features are needed +fn package_feature_extractor(package: &PackageOpt, backend: Backends) -> Option<String> { + let default_features = Some(format!( + "{},{}", + DEFAULT_FEATURES, + backend.to_rtic_feature() + )); + if let Some(package) = package.package { + debug!("\nTesting package: {package}"); + match package { + Package::Rtic => default_features, + Package::RticMacros => Some(backend.to_rtic_macros_feature().to_owned()), + _ => None, + } + } else { + default_features + } +} + // run example binary `example` -fn arm_example(command: &CargoCommand) -> anyhow::Result<()> { +fn command_parser(command: &CargoCommand, overwrite: bool) -> anyhow::Result<()> { match *command { - CargoCommand::Run { example, .. } => { - let run_file = format!("{}.run", example); - let expected_output_file = ["ci", "expected", &run_file] + CargoCommand::Qemu { example, .. } | CargoCommand::Run { example, .. } => { + let run_file = format!("{example}.run"); + let expected_output_file = ["rtic", "ci", "expected", &run_file] .iter() .collect::<PathBuf>() .into_os_string() .into_string() - .map_err(|e| TestRunError::PathConversionError(e))?; + .map_err(TestRunError::PathConversionError)?; - // command is either build or run - let cargo_run_result = run_command(&command)?; - println!("{}", cargo_run_result.output); + // cargo run <..> + info!("Running example: {example}"); + let cargo_run_result = run_command(command)?; + info!("{}", cargo_run_result.stdout); - match &command { - CargoCommand::Run { .. } => { - run_successful(&cargo_run_result, expected_output_file)?; - } - _ => (), + // Create a file for the expected output if it does not exist or mismatches + if overwrite { + let result = run_successful(&cargo_run_result, &expected_output_file); + if let Err(e) = result { + // FileError means the file did not exist or was unreadable + error!("Error: {e}"); + let mut file_handle = File::create(&expected_output_file).map_err(|_| { + TestRunError::FileError { + file: expected_output_file.clone(), + } + })?; + info!("Flag --overwrite-expected enabled"); + info!("Creating/updating file: {expected_output_file}"); + file_handle.write_all(cargo_run_result.stdout.as_bytes())?; + }; + } else { + run_successful(&cargo_run_result, &expected_output_file)?; } - Ok(()) } - CargoCommand::BuildAll { .. } => { - // command is either build or run - let cargo_run_result = run_command(&command)?; - println!("{}", cargo_run_result.output); + CargoCommand::Format { .. } + | CargoCommand::ExampleCheck { .. } + | CargoCommand::ExampleBuild { .. } + | CargoCommand::Check { .. } + | CargoCommand::Build { .. } + | CargoCommand::Clippy { .. } + | CargoCommand::Doc { .. } + | CargoCommand::Test { .. } + | CargoCommand::Book { .. } + | CargoCommand::ExampleSize { .. } => { + let cargo_result = run_command(command)?; + if let Some(exit_code) = cargo_result.exit_status.code() { + if exit_code != exitcode::OK { + error!("Exit code from command: {exit_code}"); + if !cargo_result.stdout.is_empty() { + info!("{}", cargo_result.stdout); + } + if !cargo_result.stderr.is_empty() { + error!("{}", cargo_result.stderr); + } + process::exit(exit_code); + } else { + if !cargo_result.stdout.is_empty() { + info!("{}", cargo_result.stdout); + } + if !cargo_result.stderr.is_empty() { + info!("{}", cargo_result.stderr); + } + } + } Ok(()) - } // _ => Err(anyhow::Error::new(TestRunError::IncompatibleCommand)), + } } } |
