Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: francoischalifour/medium-zoom
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b527c3b33871f534c62e68def07687afc64f6e51
Choose a base ref
...
head repository: francoischalifour/medium-zoom
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f4c7d657d44b0424eed28e09d99fff2143ec1374
Choose a head ref
  • 20 commits
  • 93 files changed
  • 6 contributors

Commits on Jul 8, 2020

  1. chore(release): don't update examples right after release

    The `afterRelease` hook happens too soon and is triggered before the new version of the library is published to npm, resulting in an error.
    francoischalifour committed Jul 8, 2020
    Copy the full SHA
    4d5e18d View commit details
  2. Copy the full SHA
    09d41d2 View commit details
  3. Copy the full SHA
    dc46cf1 View commit details
  4. Copy the full SHA
    e082f9b View commit details

Commits on Sep 3, 2020

  1. Copy the full SHA
    fb3934e View commit details

Commits on Jan 28, 2021

  1. Copy the full SHA
    219a95f View commit details

Commits on Mar 15, 2022

  1. Copy the full SHA
    dd01423 View commit details

Commits on Nov 14, 2022

  1. Copy the full SHA
    b920940 View commit details
  2. Copy the full SHA
    8a7777d View commit details

Commits on Nov 15, 2022

  1. Copy the full SHA
    32ee39f View commit details
  2. Copy the full SHA
    022c886 View commit details
  3. Copy the full SHA
    d4c8a83 View commit details
  4. Copy the full SHA
    25ed18a View commit details
  5. Copy the full SHA
    e67c1e8 View commit details

Commits on Apr 9, 2023

  1. Copy the full SHA
    aca64db View commit details

Commits on Apr 10, 2023

  1. Copy the full SHA
    dec550a View commit details
  2. Copy the full SHA
    b4ec7c6 View commit details

Commits on Nov 15, 2023

  1. Copy the full SHA
    efa7430 View commit details

Commits on Nov 16, 2023

  1. feat: introduce pure bundle (JS and CSS separated) (#206)

    Co-authored-by: Haibo <nomango@qq.com>
    francoischalifour and Nomango authored Nov 16, 2023
    Copy the full SHA
    0a05b46 View commit details
  2. Copy the full SHA
    f4c7d65 View commit details
Showing with 3,967 additions and 25,461 deletions.
  1. +1 −1 .github/ISSUE_TEMPLATE/bug_report.md
  2. +1 −2 .release-it.json
  3. +19 −0 CHANGELOG.md
  4. +58 −54 README.md
  5. +13 −1 bundlesize.config.json
  6. +1 −1 examples/dropbox-paper-template/package.json
  7. +4 −4 examples/dropbox-paper-template/yarn.lock
  8. +1 −1 examples/facebook-template/package.json
  9. +4 −4 examples/facebook-template/yarn.lock
  10. +21 −18 examples/react-markdown/.gitignore
  11. +5 −7 examples/react-markdown/README.md
  12. +17 −0 examples/react-markdown/index.html
  13. +15 −9 examples/react-markdown/package.json
  14. +0 −41 examples/react-markdown/public/index.html
  15. +0 −15 examples/react-markdown/public/manifest.json
  16. +24 −0 examples/react-markdown/src/{article.md → App.tsx}
  17. +0 −23 examples/react-markdown/src/Post.js
  18. +0 −11 examples/react-markdown/src/index.js
  19. +13 −0 examples/react-markdown/src/main.tsx
  20. +100 −19 examples/react-markdown/src/reset.css
  21. +1 −1 examples/react-markdown/src/{index.css → style.css}
  22. +1 −0 examples/react-markdown/src/vite-env.d.ts
  23. +21 −0 examples/react-markdown/tsconfig.json
  24. +9 −0 examples/react-markdown/tsconfig.node.json
  25. +7 −0 examples/react-markdown/vite.config.ts
  26. +1,066 −7,351 examples/react-markdown/yarn.lock
  27. +21 −18 examples/react/.gitignore
  28. +5 −13 examples/react/README.md
  29. +17 −0 examples/react/index.html
  30. +14 −9 examples/react/package.json
  31. +0 −41 examples/react/public/index.html
  32. +0 −15 examples/react/public/manifest.json
  33. +5 −22 examples/react/src/{App.js → App.tsx}
  34. +0 −13 examples/react/src/ImageZoom.js
  35. +30 −0 examples/react/src/ImageZoom.tsx
  36. +0 −9 examples/react/src/index.js
  37. +13 −0 examples/react/src/main.tsx
  38. +0 −108 examples/react/src/registerServiceWorker.js
  39. +100 −19 examples/react/src/reset.css
  40. +1 −1 examples/react/src/{index.css → style.css}
  41. +1 −0 examples/react/src/vite-env.d.ts
  42. +21 −0 examples/react/tsconfig.json
  43. +9 −0 examples/react/tsconfig.node.json
  44. +7 −0 examples/react/vite.config.ts
  45. +621 −10,574 examples/react/yarn.lock
  46. +24 −0 examples/svelte/.gitignore
  47. +10 −0 examples/svelte/README.md
  48. +17 −0 examples/svelte/index.html
  49. +33 −0 examples/svelte/jsconfig.json
  50. +19 −0 examples/svelte/package.json
  51. BIN examples/svelte/public/favicon.ico
  52. BIN examples/{vue/src → svelte/public}/images/image-1.jpg
  53. BIN examples/{vue/src → svelte/public}/images/image-2.jpg
  54. BIN examples/{vue/src → svelte/public}/images/image-3.jpg
  55. +30 −0 examples/svelte/src/App.svelte
  56. +80 −0 examples/svelte/src/app.css
  57. +33 −0 examples/svelte/src/lib/ImageZoom.svelte
  58. +10 −0 examples/svelte/src/main.js
  59. +129 −0 examples/svelte/src/reset.css
  60. +36 −0 examples/svelte/src/style.css
  61. +2 −0 examples/svelte/src/vite-env.d.ts
  62. +7 −0 examples/svelte/svelte.config.js
  63. +7 −0 examples/svelte/vite.config.js
  64. +293 −0 examples/svelte/yarn.lock
  65. +4 −12 examples/vanilla/README.md
  66. +1 −2 examples/vanilla/package.json
  67. +12 −185 examples/vanilla/yarn.lock
  68. +22 −1 examples/vue/.gitignore
  69. +5 −11 examples/vue/README.md
  70. +14 −39 examples/vue/index.html
  71. +11 −6 examples/vue/package.json
  72. BIN examples/vue/public/favicon.ico
  73. BIN examples/vue/public/images/image-1.jpg
  74. BIN examples/vue/public/images/image-2.jpg
  75. BIN examples/vue/public/images/image-3.jpg
  76. +32 −0 examples/vue/src/App.vue
  77. +40 −0 examples/vue/src/components/ImageZoom.vue
  78. +0 −8 examples/vue/src/index.js
  79. +8 −0 examples/vue/src/main.ts
  80. +100 −19 examples/vue/src/reset.css
  81. +0 −40 examples/vue/src/style.css
  82. +1 −0 examples/vue/src/vite-env.d.ts
  83. +18 −0 examples/vue/tsconfig.json
  84. +9 −0 examples/vue/tsconfig.node.json
  85. +7 −0 examples/vue/vite.config.ts
  86. +405 −5,537 examples/vue/yarn.lock
  87. +2 −2 package.json
  88. +52 −12 rollup.config.js
  89. +24 −0 src/__tests__/__snapshots__/medium-zoom.test.js.snap
  90. +35 −0 src/__tests__/medium-zoom.test.js
  91. +17 −2 src/medium-zoom.js
  92. +38 −0 stories/attributes.stories.js
  93. +113 −1,180 yarn.lock
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ about: Did something not work?

<!--
- Go to the vanilla JavaScript example on CodeSandbox: https://codesandbox.io/s/github/francoischalifour/medium-zoom/tree/master/examples/vanilla
- Fork it (top-left button)
- Fork it
- Reproduce the bug you noticed
- Share the link of the sandbox
-->
3 changes: 1 addition & 2 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"increment": "conventional:angular",
"scripts": {
"beforeStart": "yarn run lint && yarn run test --colors && yarn run build && yarn run test:size && yarn run test:cypress",
"afterRelease": "yarn run release:examples"
"beforeStart": "yarn run lint && yarn run test --colors && yarn run build && yarn run test:size && yarn run test:cypress"
},
"git": {
"requireUpstream": false,
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# [1.1.0](https://github.com/francoischalifour/medium-zoom/compare/1.0.8...1.1.0) (2023-11-16)

### Features

- introduce pure bundle (JS and CSS separated) ([#204](https://github.com/francoischalifour/medium-zoom/issues/204) and [#206](https://github.com/francoischalifour/medium-zoom/issues/206)) ([0a05b46](https://github.com/francoischalifour/medium-zoom/commit/0a05b4626b0f2820ae5bc3e2b0ef081244679750))

## [1.0.8](https://github.com/francoischalifour/medium-zoom/compare/1.0.7...1.0.8) (2022-11-15)

### Bug Fixes

- support images in `<picture>` elements with `currentSrc` ([#194](https://github.com/francoischalifour/medium-zoom/issues/194)) ([32ee39f](https://github.com/francoischalifour/medium-zoom/commit/32ee39f424f91e2f34e5e06e7ddc6bf8e4be9d23))

## [1.0.7](https://github.com/francoischalifour/medium-zoom/compare/1.0.6...1.0.7) (2022-11-14)

### Bug Fixes

- ensure zooming out doesn't happen ([#176](https://github.com/francoischalifour/medium-zoom/issues/176)) ([b920940](https://github.com/francoischalifour/medium-zoom/commit/b920940c061d2dcb280e873ac4ca577130d4efc1))
- remove `loading` attribute on HD target ([#186](https://github.com/francoischalifour/medium-zoom/issues/186)) ([dd01423](https://github.com/francoischalifour/medium-zoom/commit/dd01423b983a228be348c81ef9347d688a166cb6))

## [1.0.6](https://github.com/francoischalifour/medium-zoom/compare/1.0.5...1.0.6) (2020-07-08)

### Bug Fixes
112 changes: 58 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -62,7 +62,9 @@ npx doctoc README.md --maxlevel 3
- [Methods](#methods)
- [Attributes](#attributes)
- [Events](#events)
- [Framework integrations](#framework-integrations)
- [Examples](#examples)
- [Debugging](#debugging)
- [Browser support](#browser-support)
- [Contributing](#contributing)
- [License](#license)
@@ -73,15 +75,16 @@ npx doctoc README.md --maxlevel 3

## Features

- 📱 **Responsive**_scale on mobile and desktop_
- 🚀 **Performant and lightweight**_should be able to reach 60 [fps](https://en.wikipedia.org/wiki/Frame_rate)_
- ⚡️ **High definition support**_load the HD version of your image on zoom_
- 🔎 **Flexibility**_apply the zoom to a selection of images_
- 🖱 **Mouse, keyboard and gesture friendly**_click anywhere, press a key or scroll away to close the zoom_
- 🎂 **Event handling**_trigger events when the zoom enters a new state_
- 📦 **Customization**_set your own margin, background and scroll offset_
- 🔧 **Pluggable**_add your own features to the zoom_
- 💎 **Custom templates**_extend the default look to match the UI of your app_
- 📱 **Responsive** — scale on mobile and desktop
- 🚀 **Performant and lightweight** — optimized to reach 60 [fps](https://en.wikipedia.org/wiki/Framerate)
- ⚡️ **High definition support** — load the HD version of your image on zoom
- 🔎 **Flexibility** — apply the zoom to a selection of images
- 🖱 **Mouse, keyboard and gesture friendly** — click anywhere, press a key or scroll away to close the zoom
- 🎂 **Event handling** — trigger events when the zoom enters a new state
- 📦 **Customization** — set your own margin, background and scroll offset
- 🔧 **Pluggable** — add your own features to the zoom
- 💎 **Custom templates** — extend the default look to match the UI of your app
- 🔌 [**Framework agnostic**](#framework-integrations) — works with React, Vue, Angular, Svelte, Solid, etc.

## Installation

@@ -127,6 +130,14 @@ Assuming you add the `data-zoomable` attribute to your images:
mediumZoom('[data-zoomable]')
```

> [!TIP]
> If you want to control when to inject the Medium Zoom CSS styles, you can use the pure JavaScript bundle:
>
> ```js
> import mediumZoom from 'medium-zoom/dist/pure'
> import 'medium-zoom/dist/style.css'
> ```
## API
```ts
@@ -378,6 +389,15 @@ zoom.on('open', event => {

The zoom object is accessible in `event.detail.zoom`.

## Framework integrations

Medium Zoom is a JavaScript library that can be used with any framework. Here are some integrations that you can use to get started quickly:

- [React](./examples/react)
- [React Markdown](./examples/react-markdown)
- [Vue](./examples/vue)
- [Svelte](./examples/svelte)

## Examples

<details>
@@ -433,71 +453,55 @@ mediumZoom($('[data-zoomable]').toArray())
<details>
<summary>Create a zoomable React component</summary>

**Using React hooks**

```js
import React from 'react'
import React, { useRef } from 'react'
import mediumZoom from 'medium-zoom'

function ImageZoom({ zoom, src, alt, background }) {
const zoomRef = React.useRef(zoom.clone({ background }))
export function ImageZoom({ options, ...props }) {
const zoomRef = useRef(null)

function attachZoom(image) {
zoomRef.current.attach(image)
}
function getZoom() {
if (zoomRef.current === null) {
zoomRef.current = mediumZoom(options)
}

return <img src={src} alt={alt} ref={attachZoom} />
}
return zoomRef.current
}

function App() {
const zoom = React.useRef(mediumZoom({ background: '#000', margin: 48 }))
function attachZoom(image) {
const zoom = getZoom()

render() {
return (
<ImageZoom src="image.jpg" alt="Image" zoom={zoom.current} color="#BADA55" />
)
if (image) {
zoom.attach(image)
} else {
zoom.detach()
}
}

return <img {...props} ref={attachZoom} />
}
```

**Using React classes**
</details>
<br>

```js
import React, { Component } from 'react'
import mediumZoom from 'medium-zoom'
You can see [more examples](examples/) including [React](examples/react) and [Vue](examples/vue), or check out the [storybook](https://medium-zoom.francoischalifour.com/storybook).

class ImageZoom extends Component {
zoom = this.props.zoom.clone({
background: this.props.color,
})
## Debugging

attachZoom = image => {
this.zoom.attach(image)
}
### The zoomed image is not visible

render() {
return (
<img src={this.props.src} alt={this.props.alt} ref={this.attachZoom} />
)
}
}
The library doesn't provide a `z-index` value on the zoomed image to avoid conflicts with other frameworks. Some frameworks might specify a `z-index` for their elements, which makes the zoomed image not visible.

class App extends Component {
zoom = mediumZoom({ background: '#000', margin: 48 })
If that's the case, you can provide a `z-index` value in your CSS:

render() {
return (
<ImageZoom src="image.jpg" alt="Image" zoom={this.zoom} color="#BADA55" />
)
}
```css
.medium-zoom-overlay,
.medium-zoom-image--opened {
z-index: 999;
}
```

</details>
<br>

You can see [more examples](examples/) including [React](examples/react) and [Vue](examples/vue), or check out the [storybook](https://medium-zoom.francoischalifour.com/storybook).

## Browser support

| IE | Edge | Chrome | Firefox | Safari |
14 changes: 13 additions & 1 deletion bundlesize.config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
{
"files": [
{
"path": "dist/style.css",
"maxSize": "250 B"
},
{
"path": "dist/medium-zoom.esm.js",
"maxSize": "5 kB"
},
{
"path": "dist/medium-zoom.min.js",
"maxSize": "3 kB"
"maxSize": "3.25 kB"
},
{
"path": "dist/pure/index.js",
"maxSize": "4.75 kB"
},
{
"path": "dist/pure/medium-zoom.min.umd.js",
"maxSize": "2.75 kB"
}
]
}
2 changes: 1 addition & 1 deletion examples/dropbox-paper-template/package.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
"build": "parcel build index.html"
},
"dependencies": {
"medium-zoom": "1.0.5"
"medium-zoom": "1.0.8"
},
"devDependencies": {
"parcel-bundler": "1.12.4"
8 changes: 4 additions & 4 deletions examples/dropbox-paper-template/yarn.lock
Original file line number Diff line number Diff line change
@@ -3144,10 +3144,10 @@ mdn-data@^1.0.0, mdn-data@~1.1.0:
version "1.1.4"
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-1.1.4.tgz#50b5d4ffc4575276573c4eedb8780812a8419f01"

medium-zoom@1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/medium-zoom/-/medium-zoom-1.0.5.tgz#81413dda20ccdd857141ff420cfab788dd32e20e"
integrity sha512-aLGa6WlTuFKWvH88bqTrY5ztJMN+D0hd8UX6BYc4YSoPayppzETjZUcdVcksgaoQEMg4cZSmXPg846fTp2rjRQ==
medium-zoom@1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/medium-zoom/-/medium-zoom-1.0.6.tgz#9247f21ca9313d8bbe9420aca153a410df08d027"
integrity sha512-UdiUWfvz9fZMg1pzf4dcuqA0W079o0mpqbTnOz5ip4VGYX96QjmbM+OgOU/0uOzAytxC0Ny4z+VcYQnhdifimg==

merge-source-map@1.0.4:
version "1.0.4"
2 changes: 1 addition & 1 deletion examples/facebook-template/package.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
"build": "parcel build index.html"
},
"dependencies": {
"medium-zoom": "1.0.5"
"medium-zoom": "1.0.8"
},
"devDependencies": {
"parcel-bundler": "1.12.4"
8 changes: 4 additions & 4 deletions examples/facebook-template/yarn.lock
Original file line number Diff line number Diff line change
@@ -3152,10 +3152,10 @@ mdn-data@^1.0.0, mdn-data@~1.1.0:
version "1.1.4"
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-1.1.4.tgz#50b5d4ffc4575276573c4eedb8780812a8419f01"

medium-zoom@1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/medium-zoom/-/medium-zoom-1.0.5.tgz#81413dda20ccdd857141ff420cfab788dd32e20e"
integrity sha512-aLGa6WlTuFKWvH88bqTrY5ztJMN+D0hd8UX6BYc4YSoPayppzETjZUcdVcksgaoQEMg4cZSmXPg846fTp2rjRQ==
medium-zoom@1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/medium-zoom/-/medium-zoom-1.0.6.tgz#9247f21ca9313d8bbe9420aca153a410df08d027"
integrity sha512-UdiUWfvz9fZMg1pzf4dcuqA0W079o0mpqbTnOz5ip4VGYX96QjmbM+OgOU/0uOzAytxC0Ny4z+VcYQnhdifimg==

merge-source-map@1.0.4:
version "1.0.4"
39 changes: 21 additions & 18 deletions examples/react-markdown/.gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
12 changes: 5 additions & 7 deletions examples/react-markdown/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# React Markdown
# Medium Zoom React Markdown Example

> This is a medium-zoom example using React.
This example reads Markdown in a React component and attaches the zoom on the Markdown images.

![Preview](https://user-images.githubusercontent.com/6137112/32423266-67ccfd86-c273-11e7-9076-1df48ff85268.png)

This example reads from a Markdown file and imports its content in a React component to attach the zoom (see [`src/Post.js`](src/Post.js)).
[![Edit React Markdown Example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/francoischalifour/medium-zoom/tree/master/examples/react-markdown?file=/src/App.tsx)

## Usage

* Install dependencies: `yarn`
* Run: `yarn start`
- Install dependencies: `yarn`
- Run: `yarn dev`
17 changes: 17 additions & 0 deletions examples/react-markdown/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<title>Medium Zoom | React Markdown Demo</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
24 changes: 15 additions & 9 deletions examples/react-markdown/package.json
Original file line number Diff line number Diff line change
@@ -2,17 +2,23 @@
"name": "@medium-zoom/react-markdown-example",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"medium-zoom": "1.0.5",
"react": "16.12.0",
"react-dom": "16.12.0",
"react-markdown": "4.2.2",
"react-scripts": "1.1.5"
"medium-zoom": "1.0.8",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-markdown": "8.0.6"
},
"devDependencies": {
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react": "3.1.0",
"typescript": "4.9.3",
"vite": "4.2.0"
}
}
Loading