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

Add bindings for VisualViewport #3931

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

DanielleHuisman
Copy link
Contributor

Add bindings for VisualViewport(MDN, specification).

I think the comment about SameObject above window.screen might also apply to window.visualViewport. For now, I just copied the IDL from the specification.

@xpe
Copy link

xpe commented May 25, 2024

@DanielleHuisman I noticed VisualViewport was missing and found this. Thanks!

@xpe
Copy link

xpe commented May 25, 2024

@rustwasm How does this look to you?

@xpe
Copy link

xpe commented May 25, 2024

In the meanwhile, I'll use a fork. But I'm not clear on the syntax. What do I write in Cargo.toml to specify a Github fork to provide web-sys? -- given that web-sys lives in wasm-bindgen?

@xpe
Copy link

xpe commented May 26, 2024

I've answered my own question.

First Attempt (Not Enough)

If one only specifies the git repository of a fork in Cargo.toml you will likely see an error like this:

% cargo build
    Updating crates.io index
error: failed to select a version for `wasm-bindgen-shared`.
    ... required by package `wasm-bindgen-macro-support v0.2.92 (https://github.com/xpe/wasm-bindgen?branch=feature/visual-viewport#0710b292)`
    ... which satisfies git dependency `wasm-bindgen-macro-support` (locked to 0.2.92) of package `wasm-bindgen-macro v0.2.92 (https://github.com/xpe/wasm-bindgen?branch=feature/visual-viewport#0710b292)`
    ... which satisfies git dependency `wasm-bindgen-macro` (locked to 0.2.92) of package `wasm-bindgen v0.2.92 (https://github.com/xpe/wasm-bindgen?branch=feature/visual-viewport#0710b292)`
    ... which satisfies git dependency `wasm-bindgen` (locked to 0.2.92) of package `web-sys v0.3.69 (https://github.com/xpe/wasm-bindgen?branch=feature/visual-viewport#0710b292)`
    ... which satisfies dependency `web-sys = "^0.3.69"` (locked to 0.3.69) of package `ais-graph v0.1.0 (/Users/xpe/ixe/web/ais-graph)`
versions that meet the requirements `=0.2.92` (locked to 0.2.92) are: 0.2.92

the package `wasm-bindgen-shared` links to the native library `wasm_bindgen`, but it conflicts with a previous package which links to `wasm_bindgen` as well:
package `wasm-bindgen-shared v0.2.92`
    ... which satisfies dependency `wasm-bindgen-shared = "=0.2.92"` of package `wasm-bindgen-macro-support v0.2.92`
    ... which satisfies dependency `wasm-bindgen-macro-support = "=0.2.92"` of package `wasm-bindgen-macro v0.2.92`
    ... which satisfies dependency `wasm-bindgen-macro = "=0.2.92"` of package `wasm-bindgen v0.2.92`
    ... which satisfies dependency `wasm-bindgen = "^0.2.92"` of package `ais-graph v0.1.0 (/Users/xpe/ixe/web/ais-graph)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "wasm_bindgen"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `wasm-bindgen-shared` which could resolve this conflict

Solution

Instead as recommend (see links at bottom), the [patch] section of Cargo.toml is needed.

With that in mind, here is how I use my fork of web-sys:

[package]
name = "project-name"
version = "0.1.0"
edition = "2021"

[dependencies]
console_error_panic_hook = "0.1.7"
wasm-bindgen = { version = "0.2.92" }
web-sys = { version = "0.3.69", features = [
    "Document",
    "Element",
    "VisualViewport",
    "Window",
] }

[patch.crates-io]
wasm-bindgen = { git = "https://github.com/xpe/wasm-bindgen", branch = "feature/visual-viewport" }
web-sys = { git = "https://github.com/xpe/wasm-bindgen", branch = "feature/visual-viewport" }

Relevant docs and issues

@xpe
Copy link

xpe commented May 31, 2024

@Liamolucko @daxpedda I'm not sure who the maintainers are, but I see that you both are recent active contributors, so I thought it might be wise to reach out. Could you help @DanielleHuisman and I get this PR merged? Much appreciated.

Copy link
Collaborator

@Liamolucko Liamolucko left a comment

Choose a reason for hiding this comment

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

Thanks!

Could you add a changelog entry?

@DanielleHuisman
Copy link
Contributor Author

I added a changelog entry. Hope it's all good now :)

@Liamolucko Liamolucko merged commit c108c75 into rustwasm:main Jun 1, 2024
25 checks passed
@DanielleHuisman DanielleHuisman deleted the feature/visual-viewport branch June 2, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants