Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow enhanced to be first query parameter #12650

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Extarys
Copy link

@Extarys Extarys commented Sep 4, 2024

Add &enhanced

Currently, the following throws an error:

import MyImage from './path/to/your/image.jpg?quality=80&tint=#ffaa22&enhanced;

Ideally, we would also be able to put the enhanced query at the beginning, but I'm not TS fluent enough to know how to do that.

// Doesn't work
import MyImage from './path/to/your/image.jpg?enhanced&quality=80&tint=#ffaa22;

Fix #12608
Thanks to https://github.com/vvnsrzn for the solution.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Add `&enhanced`
Copy link

changeset-bot bot commented Sep 4, 2024

⚠️ No Changeset found

Latest commit: 9dd9bed

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@benmccann benmccann changed the title fix: enhanced-img type to allow image filter on image import fix: allow enhanced to be first query parameter Sep 14, 2024
@eltigerchino
Copy link
Member

eltigerchino commented Oct 7, 2024

Ideally, we would also be able to put the enhanced query at the beginning, but I'm not TS fluent enough to know how to do that.

Yeah, not sure if this is possible since we can only use a single wildcard * either at the beginning or the end.

This leaves us with two options:

  1. The current option only allows ?enhanced.
declare module '*?enhanced' {
	import type { Picture } from 'vite-imagetools';

	const value: Picture;
	export default value;
}
  1. This option allows &enhanced at the end of all the other image modifications, but doesn't correctly type it. For example, if you included metadata, you would have more than just the picture values from the image import.
declare module '*&enhanced' {
	import type { Picture } from 'vite-imagetools';

	const value: Picture;
	export default value;
}

Unless we specify every combination, or if there's another solution to this, users are forced to declare their own types as many have this case in JonasKruckenberg/imagetools#160

@dummdidumm
Copy link
Member

Yeah I'm honestly not sure if there's anything we can really do here. *&enhanced only gets you so far, and as pointed out the types are very likely wrong then because it contains something else, so we could only fall back to any or sth. Not sure how you feel about that @benmccann - I lean towards not doing anything here, instead document this somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow passing imagetools parameters when dynamically importing images for enhanced:img
4 participants