Skip to content

feat(PdfReader): add OnScaleChangedAsync parameter#756

Merged
ArgoZhang merged 5 commits intomasterfrom
dev-localizer
Nov 29, 2025
Merged

feat(PdfReader): add OnScaleChangedAsync parameter#756
ArgoZhang merged 5 commits intomasterfrom
dev-localizer

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Nov 29, 2025

Link issues

fixes #755

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add support for notifying consumers when the PDF viewer scale changes in PdfReader.

New Features:

  • Expose an OnScaleChangedAsync callback parameter on PdfReader to handle zoom level changes.

Enhancements:

  • Wire the PDF.js scalechanging event to the new ScaleChanged .NET callback, gated by a trigger flag in the interop options.

Copilot AI review requested due to automatic review settings November 29, 2025 05:14
@bb-auto bb-auto Bot added the enhancement New feature or request label Nov 29, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Nov 29, 2025
@ArgoZhang ArgoZhang merged commit 56d3cbd into master Nov 29, 2025
6 checks passed
@ArgoZhang ArgoZhang deleted the dev-localizer branch November 29, 2025 05:15
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Nov 29, 2025

Reviewer's Guide

Adds a new OnScaleChangedAsync callback to PdfReader so consumers can react to zoom changes, wiring it through both the Blazor component and the underlying pdf.js event bus.

Sequence diagram for PdfReader scale change callback flow

sequenceDiagram
    actor User
    participant BrowserPdfViewer
    participant PdfJsEventBus
    participant PdfReaderJs as PdfReader_js
    participant DotNetInterop
    participant PdfReader as PdfReader_component

    User->>BrowserPdfViewer: Change zoom level
    BrowserPdfViewer->>PdfJsEventBus: Emit scalechanging(scale)
    PdfJsEventBus->>PdfReaderJs: scalechanging event
    activate PdfReaderJs
    PdfReaderJs->>PdfReaderJs: updateScaleValue(el, scale)
    PdfReaderJs->>PdfReaderJs: Check options.triggerScaleChanged
    alt triggerScaleChanged is true
        PdfReaderJs->>DotNetInterop: invokeMethodAsync(ScaleChanged, scale)
        activate DotNetInterop
        DotNetInterop->>PdfReader_component: Invoke JSInvokable ScaleChanged(scale)
        activate PdfReader_component
        PdfReader_component->>PdfReader_component: if OnScaleChangedAsync != null
        PdfReader_component->>PdfReader_component: await OnScaleChangedAsync(scale)
        deactivate PdfReader_component
        deactivate DotNetInterop
    else triggerScaleChanged is false
        PdfReaderJs-->>PdfJsEventBus: No .NET callback invoked
    end
    deactivate PdfReaderJs
Loading

Updated class diagram for PdfReader scale change support

classDiagram
    class PdfReader {
        +Func~bool, Task~ OnTwoPagesOneViewAsync
        +Func~float, Task~ OnScaleChangedAsync
        +Task OnAfterRenderAsync(bool firstRender)
        +Task PageChanged(uint pageIndex)
        +Task ScaleChanged(float val)
    }

    class PdfReaderInteropOptions {
        +bool TriggerPagesInit
        +bool TriggerPagesLoaded
        +bool TriggerPageChanged
        +bool TriggerTowPagesOnViewChanged
        +bool TriggerScaleChanged
    }

    PdfReader --> PdfReaderInteropOptions : configures

    class PdfReaderJsInterop {
        +void addEventBus(element el, object pdfViewer, object eventBus, object invoke, PdfReaderInteropOptions options)
    }

    PdfReader ..> PdfReaderJsInterop : uses via JS interop
    PdfReaderJsInterop ..> PdfReader : invokes ScaleChanged(float val) via JSInvokable
Loading

File-Level Changes

Change Details Files
Introduce a new scale-changed callback parameter on PdfReader and wire it through component initialization and JS interop to respond to pdf.js zoom events.
  • Add an OnScaleChangedAsync Func<float, Task>? parameter on the PdfReader component for scale change notifications
  • Include TriggerScaleChanged flag in the options object passed during PdfReader initialization based on whether OnScaleChangedAsync is set
  • Expose a JSInvokable ScaleChanged(float) method that forwards scale changes to the OnScaleChangedAsync callback if present
  • Update the pdf.js event bus scalechanging handler to call the new ScaleChanged .NET method via invokeMethodAsync when the TriggerScaleChanged option is enabled, while still updating the UI scale value
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#755 Add an OnScaleChangedAsync parameter to the PdfReader component to allow consumers to supply an async callback when the zoom/scale changes.
#755 Wire the OnScaleChangedAsync parameter into the PdfReader’s JS interop so that the callback is invoked whenever the PDF viewer’s scale changes.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new OnScaleChangedAsync callback parameter to the PdfReader component, enabling consumers to react to scale/zoom changes in the PDF viewer. This enhancement follows the existing pattern of event callbacks in the component (similar to OnPageChangedAsync, OnPagesInitAsync, etc.) and addresses issue #755.

Key Changes:

  • Added OnScaleChangedAsync parameter to expose scale change events to component consumers
  • Implemented JavaScript event handler for the scalechanging event with callback to C#
  • Added TriggerScaleChanged option to control when the callback is invoked

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
PdfReader.razor.cs Added OnScaleChangedAsync parameter property, ScaleChanged JSInvokable method, and TriggerScaleChanged option configuration
PdfReader.razor.js Modified scalechanging event handler to invoke the C# callback asynchronously when enabled
Comments suppressed due to low confidence (10)

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:121

  • Unused variable title.
    const title = el.querySelector('.bb-view-pdf-dialog-title');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:122

  • Unused variable author.
    const author = el.querySelector('.bb-view-pdf-dialog-author');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:123

  • Unused variable subject.
    const subject = el.querySelector('.bb-view-pdf-dialog-subject');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:124

  • Unused variable keywords.
    const keywords = el.querySelector('.bb-view-pdf-dialog-keywords');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:128

  • Unused variable modified.
    const modified = el.querySelector('.bb-view-pdf-dialog-modified');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:148

  • Unused variable webview.
    const webview = el.querySelector('.bb-view-pdf-dialog-webview');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:462

  • Unused variable scaleEl.
    const scaleEl = el.querySelector(".bb-view-scale-input");

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:563

  • The initial value of v is unused, since it is always overwritten.
    let v = 100;

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:424

  • Avoid automated semicolon insertion (94% of all statements in the enclosing function have an explicit semicolon).
    })

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:486

  • Avoid automated semicolon insertion (91% of all statements in the enclosing function have an explicit semicolon).
    delete el.widths

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (options.triggerScaleChanged) {
await invoke.invokeMethodAsync("ScaleChanged", evt.scale);
}
})
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon at the end of the eventBus.on("scalechanging", ...) statement. All other event handler registrations in this function (lines 309, 325, 349, 365) end with semicolons for consistency.

Suggested change
})
});

Copilot uses AI. Check for mistakes.

/// <summary>
/// 缩放倍率更改回调方法
/// </summary>
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing <param> documentation for the val parameter. Other similar callback methods in this file (e.g., PagesInit, PagesLoaded, PageChanged) include <param> documentation for their parameters.

Suggested change
/// </summary>
/// </summary>
/// <param name="val">缩放倍率值</param>

Copilot uses AI. Check for mistakes.
eventBus.on("scalechanging", async evt => {
updateScaleValue(el, evt.scale);

if (options.triggerScaleChanged) {
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent boolean check pattern. Other trigger checks in this function use strict equality comparison with === true (lines 306, 312, 346). Consider changing if (options.triggerScaleChanged) to if (options.triggerScaleChanged === true) for consistency.

Suggested change
if (options.triggerScaleChanged) {
if (options.triggerScaleChanged === true) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(PdfReader): add OnScaleChangedAsync parameter

2 participants