Files
PowerToys/src/modules/cmdpal/ext/SamplePagesExtension/Assets/Images/FluentEmojiChipmunk.svg

1 line
30 KiB
XML
Raw Normal View History

CmdPal: Enable loading local images in MarkdownContent (#41754) Add a new image provider for `MarkdownTextBlock` that allows loading images from additional sources: - **file scheme** - Enables loading images using the `file:` scheme. - Intentionally restricts file URIs to absolute paths to ensure correct resolution when passed through the CmdPal extension/host boundary. (In most cases, 3rd-party extensions will provide the paths, but the CmdPal host performs the actual loading and would otherwise resolve paths relative to itself.) - **data scheme** - Enables loading images from URIs with the `data:` scheme (both Base64 and URL-encoded forms). - Note: the Markdown control itself cannot handle large input and may hang before the code introduced in this PR is invoked. - **ms-appx scheme** - This scheme is now supported for loading images. - However, since the Command Palette host performs the loading, `ms-appx:` resolution applies to the host and not the extensions, which limits its usefulness. - **ms-appdata scheme** - This scheme is now supported for loading images. - Similar to `ms-appx:`, resolution applies to the host, not the extensions, limiting its usefulness. --- Additionally, this PR introduces the concept of **_image source hints_**, implemented as query string parameters piggy-backed on the original URI. These hints allow users to influence the behavior of images within Markdown content. - `--x-cmdpal-fit` - `none`: no automatic scaling, provides image as is (default) - `fit`: scale to fit the available space - `--x-cmdpal-upscale` - `true`: allow upscaling - `false`: downscale only (default) - `--x-cmdpal-width`: desired width in pixels - `--x-cmdpal-height`: desired height in pixels - `--x-cmdpal-maxwidth`: max width in pixels - `--x-cmdpal-maxheight`: max height in pixels --- Since `MarkdownTextBlock` requires conforming to the `IImageProvider` interface—which accepts only a raw URI and must return an `Image` control—this PR also introduces a new class `RtbInlineImageFactory`. The factory hooks into the root text block upon loading and listens for events related to **layout** and **DPI changes**, ensuring that images adapt correctly to the control’s environment. ```csharp public interface IImageProvider { Task<Image> GetImage(string url); bool ShouldUseThisProvider(string url); } ``` --- Pictures? Videos! Loading images from new schemes: https://github.com/user-attachments/assets/e0f4308d-30b2-4c81-86db-353048c708c1 New image source scaling options: https://github.com/user-attachments/assets/ec5b007d-3140-4f0a-b163-7b278233ad40 <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #41752 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Michael Jolley <mike@baldbeardedbuilder.com>
2025-09-26 17:59:00 +02:00
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 32 32"><g fill="none"><g filter="url(#IconifyId199691df1f81eb73818217)"><path fill="url(#IconifyId199691df1f81eb73818194)" d="m28.046 9.04l-1.25-.62c-.2-.11-.13-.42.1-.42h.58a2.5 2.5 0 0 0 0-5h-2.03a4.468 4.468 0 0 0-2.3 8.3l1.88 1.13c.59.35.95.99.95 1.67V25a1 1 0 0 1-1 1h-3.48v4h4.48c2.21 0 4-1.79 4-4V12.16c0-1.33-.75-2.53-1.93-3.12"/><path fill="url(#IconifyId199691df1f81eb73818195)" d="m28.046 9.04l-1.25-.62c-.2-.11-.13-.42.1-.42h.58a2.5 2.5 0 0 0 0-5h-2.03a4.468 4.468 0 0 0-2.3 8.3l1.88 1.13c.59.35.95.99.95 1.67V25a1 1 0 0 1-1 1h-3.48v4h4.48c2.21 0 4-1.79 4-4V12.16c0-1.33-.75-2.53-1.93-3.12"/><path fill="url(#IconifyId199691df1f81eb73818196)" d="m28.046 9.04l-1.25-.62c-.2-.11-.13-.42.1-.42h.58a2.5 2.5 0 0 0 0-5h-2.03a4.468 4.468 0 0 0-2.3 8.3l1.88 1.13c.59.35.95.99.95 1.67V25a1 1 0 0 1-1 1h-3.48v4h4.48c2.21 0 4-1.79 4-4V12.16c0-1.33-.75-2.53-1.93-3.12"/><path fill="url(#IconifyId199691df1f81eb73818164)" d="m28.046 9.04l-1.25-.62c-.2-.11-.13-.42.1-.42h.58a2.5 2.5 0 0 0 0-5h-2.03a4.468 4.468 0 0 0-2.3 8.3l1.88 1.13c.59.35.95.99.95 1.67V25a1 1 0 0 1-1 1h-3.48v4h4.48c2.21 0 4-1.79 4-4V12.16c0-1.33-.75-2.53-1.93-3.12"/><path fill="url(#IconifyId199691df1f81eb73818165)" d="m28.046 9.04l-1.25-.62c-.2-.11-.13-.42.1-.42h.58a2.5 2.5 0 0 0 0-5h-2.03a4.468 4.468 0 0 0-2.3 8.3l1.88 1.13c.59.35.95.99.95 1.67V25a1 1 0 0 1-1 1h-3.48v4h4.48c2.21 0 4-1.79 4-4V12.16c0-1.33-.75-2.53-1.93-3.12"/><path fill="url(#IconifyId199691df1f81eb73818166)" d="m28.046 9.04l-1.25-.62c-.2-.11-.13-.42.1-.42h.58a2.5 2.5 0 0 0 0-5h-2.03a4.468 4.468 0 0 0-2.3 8.3l1.88 1.13c.59.35.95.99.95 1.67V25a1 1 0 0 1-1 1h-3.48v4h4.48c2.21 0 4-1.79 4-4V12.16c0-1.33-.75-2.53-1.93-3.12"/><path fill="url(#IconifyId199691df1f81eb73818167)" d="m28.046 9.04l-1.25-.62c-.2-.11-.13-.42.1-.42h.58a2.5 2.5 0 0 0 0-5h-2.03a4.468 4.468 0 0 0-2.3 8.3l1.88 1.13c.59.35.95.99.95 1.67V25a1 1 0 0 1-1 1h-3.48v4h4.48c2.21 0 4-1.79 4-4V12.16c0-1.33-.75-2.53-1.93-3.12"/></g><g filter="url(#IconifyId199691df1f81eb73818218)"><path stroke="url(#IconifyId199691df1f81eb73818197)" stroke-linecap="round" stroke-width=".75" d="m25.6 9.031l1.802.862a2 2 0 0 1 1.136 1.804V25.5a2 2 0 0 1-2 2h-2.187"/></g><path fill="url(#IconifyId199691df1f81eb73818198)" d="M3.836 16.99v1.99c0 .69.39 1.32 1.01 1.62l.69.33a.7.7 0 0 0 .6 0l.69-.33c.62-.3 1.01-.93 1.01-1.62v-1.99z"/><path fill="url(#IconifyId199691df1f81eb73818168)" d="M3.836 16.99v1.99c0 .69.39 1.32 1.01 1.62l.69.33a.7.7 0 0 0 .6 0l.69-.33c.62-.3 1.01-.93 1.01-1.62v-1.99z"/><path fill="url(#IconifyId199691df1f81eb73818199)" d="M16.526 11c-.95 0-1.82-.53-2.24-1.38l-.71-1.43a5.36 5.36 0 0 1-.59-2.48A2.687 2.687 0 0 0 10.306 3c-.18 0-.33.14-.33.33v2.076S9.374 5 8.288 5c-1.313 0-2.742.84-3.572 2.1c-.74 1.332-1.624 2.606-2.43 3.9c-.2.25-.31.56-.31.88c0 1.73 1.39 3.12 3.12 3.12h3.88v3h-1.46c-.85 0-1.56.69-1.54 1.53c.02.82.68 1.47 1.5 1.47l1.5.04v2.9c0 3.35 2.71 6.06 6.06 6.06h6.89a3.05 3.05 0 0 0 3.05-3.05v-7.49c0-4.67-3.78-8.46-8.45-8.46"/><path fill="url(#IconifyId199691df1f81eb73818169)" d="M16.526 11c-.95 0-1.82-.53-2.24-1.38l-.71-1.43a5.36 5.36 0 0 1-.59-2.48A2.687 2.687 0 0 0 10.306 3c-.18 0-.33.14-.33.33v2.076S9.374 5 8.288 5c-1.313 0-2.742.84-3.572 2.1c-.74 1.332-1.624 2.606-2.43 3.9c-.2.25-.31.56-.31.88c0 1.73 1.39 3.12 3.12 3.12h3.88v3h-1.46c-.85 0-1.56.69-1.54 1.53c.02.82.68 1.47 1.5 1.47l1.5.04v2.9c0 3.35 2.71 6.06 6.06 6.06h6.89a3.05 3.05 0 0 0 3.05-3.05v-7.49c0-4.67-3.78-8.46-8.45-8.46"/><path fill="url(#IconifyId199691df1f81eb73818170)" d="M16.526 11c-.95 0-1.82-.53-2.24-1.38l-.71-1.43a5.36 5.36 0 0 1-.59-2.48A2.687 2.687 0 0 0 10.306 3c-.18 0-.33.14-.33.33v2.076S9.374 5 8.288 5c-1.313 0-2.742.84-3.572 2.1c-.74 1.332-1.624 2.606-2.43 3.9c-.2.25-.31.56-.31.88c0 1.73 1.39 3.12 3.12 3.12h3.88v3h-1.46c-.85 0-1.56.69-1.54 1.53c.02.82.68 1.47 1.5 1.47l1.5.04v2.9c0 3.35 2.71 6.06 6.06 6.06h6.89a3.05 3.05 0 0 0 3.05-3.05v-7.49c0-4.67-3.78-8.46-8.45-8.46"/><path fill="url(#IconifyId199691df1f81eb73818171)" d="M16.526 11c-.95 0-1.82-.53-2.24-1.38l-.71-1.43a5.36 5.36 0 0 1-.59-