feature: vor und nachteile

This commit is contained in:
Hikyu
2026-05-31 13:54:31 +02:00
parent 552a947a1c
commit e3dad17446
23270 changed files with 3024794 additions and 200 deletions
+2
View File
@@ -0,0 +1,2 @@
node_modules/
dist/
+31
View File
@@ -0,0 +1,31 @@
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
ecmaVersion: 2017,
sourceType: 'module'
},
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: [
'standard',
'plugin:vue/recommended',
],
// required to lint *.vue files
plugins: [
'vue',
],
env: {
browser: true,
},
// add your custom rules here
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
// trailing comma
'comma-dangle': ['error', 'always-multiline'],
}
}
+108
View File
@@ -0,0 +1,108 @@
# vue-resize
[![npm](https://img.shields.io/npm/v/vue-resize.svg) ![npm](https://img.shields.io/npm/dm/vue-resize.svg)](https://www.npmjs.com/package/vue-resize)
[![vue2](https://img.shields.io/badge/vue-2.x-brightgreen.svg)](https://vuejs.org/)
Detect DOM element resizing
[JSFiddle](https://jsfiddle.net/Akryum/zqygwf3r/)
<p>
<a href="https://www.patreon.com/akryum" target="_blank">
<img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Become a Patreon">
</a>
</p>
## Sponsors
[![sponsors logos](https://guillaume-chau.info/sponsors.png)](https://guillaume-chau.info/sponsors)
<br>
# Installation
```
npm install --save vue-resize
```
## Module import
**⚠️ You need to include the package CSS:**
```js
import 'vue-resize/dist/vue-resize.css'
```
Then import the package and install it into Vue:
```javascript
import VueResize from 'vue-resize'
app.use(VueResize)
```
Or:
```javascript
import { ResizeObserver } from 'vue-resize'
app.component('resize-observer', ResizeObserver)
```
## Browser
```html
<link rel="stylesheet" href="vue-resize/dist/vue-resize.css"/>
<script src="vue.js"></script>
<script src="vue-resize/dist/vue-resize.min.js"></script>
```
```javascript
app.use(VueResize)
```
Or:
```javascript
app.component('resize-observer', VueResize.ResizeObserver)
```
# Usage
Add the `<resize-observer>` inside a DOM element and make its position to something other than `'static'` (for example `'relative'`), so that the observer can fill it.
Listen to the `notify` event that is fired when the above DOM element is resized.
# Example
```html
<template>
<div class="demo">
<h1>Hello world!</h1>
<resize-observer @notify="handleResize" />
</div>
</template>
<script>
export default {
methods: {
handleResize ({ width, height }) {
console.log('resized', width, height)
}
}
}
</script>
<style scoped>
.demo {
position: relative;
}
</style>
```
---
## License
[MIT](http://opensource.org/licenses/MIT)
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
presets: [
[require('@babel/preset-env'), { modules: false }],
],
}
+49
View File
@@ -0,0 +1,49 @@
import { babel } from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import vue from 'rollup-plugin-vue'
import cjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'
import eslint from '@rollup/plugin-eslint'
import css from 'rollup-plugin-css-only'
import autoprefixer from 'autoprefixer'
import fs from 'fs-extra'
import CleanCSS from 'clean-css'
const config = require('../package.json')
export default {
input: 'src/index.js',
plugins: [
resolve({
mainFields: ['module', 'jsnext', 'main', 'browser'],
}),
eslint({
include: ['src/**/*.{js,vue}'],
}),
vue({
css: false,
style: {
postcssPlugins: [autoprefixer],
},
}),
css({
output: styles => {
fs.ensureDirSync('dist')
fs.writeFileSync('dist/vue-resize.css', new CleanCSS().minify(styles).styles)
},
}),
babel({
exclude: 'node_modules/**',
}),
cjs(),
replace({
VERSION: JSON.stringify(config.version),
}),
],
watch: {
include: 'src/**',
},
external: [
'vue',
],
}
+19
View File
@@ -0,0 +1,19 @@
import base from './rollup.config.base'
import { terser } from 'rollup-plugin-terser'
const config = Object.assign({}, base, {
output: {
exports: 'named',
name: 'VueResize',
file: 'dist/vue-resize.min.js',
format: 'iife',
sourcemap: true,
globals: {
vue: 'Vue',
},
},
})
config.plugins.push(terser({}))
export default config
+16
View File
@@ -0,0 +1,16 @@
import base from './rollup.config.base'
const config = Object.assign({}, base, {
output: {
name: 'vue-resize',
file: 'dist/vue-resize.esm.js',
format: 'es',
sourcemap: true,
},
external: [
...base.external,
// Additional externals here
],
})
export default config
+13
View File
@@ -0,0 +1,13 @@
import base from './rollup.config.base'
const config = Object.assign({}, base, {
output: {
exports: 'named',
name: 'vue-resize',
file: 'dist/vue-resize.umd.js',
format: 'umd',
sourcemap: true,
},
})
export default config
+1
View File
@@ -0,0 +1 @@
.resize-observer[data-v-b329ee4c]{position:absolute;top:0;left:0;z-index:-1;width:100%;height:100%;border:none;background-color:transparent;pointer-events:none;display:block;overflow:hidden;opacity:0}.resize-observer[data-v-b329ee4c] object{display:block;position:absolute;top:0;left:0;height:100%;width:100%;overflow:hidden;pointer-events:none;z-index:-1}
+157
View File
@@ -0,0 +1,157 @@
import { nextTick, pushScopeId, popScopeId, openBlock, createBlock, withScopeId } from 'vue';
function getInternetExplorerVersion() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// Edge (IE 12+) => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
} // other browser
return -1;
}
let isIE;
function initCompat () {
if (!initCompat.init) {
initCompat.init = true;
isIE = getInternetExplorerVersion() !== -1;
}
}
var script = {
name: 'ResizeObserver',
props: {
emitOnMount: {
type: Boolean,
default: false,
},
ignoreWidth: {
type: Boolean,
default: false,
},
ignoreHeight: {
type: Boolean,
default: false,
},
},
emits: [
'notify',
],
mounted () {
initCompat();
nextTick(() => {
this._w = this.$el.offsetWidth;
this._h = this.$el.offsetHeight;
if (this.emitOnMount) {
this.emitSize();
}
});
const object = document.createElement('object');
this._resizeObject = object;
object.setAttribute('aria-hidden', 'true');
object.setAttribute('tabindex', -1);
object.onload = this.addResizeHandlers;
object.type = 'text/html';
if (isIE) {
this.$el.appendChild(object);
}
object.data = 'about:blank';
if (!isIE) {
this.$el.appendChild(object);
}
},
beforeUnmount () {
this.removeResizeHandlers();
},
methods: {
compareAndNotify () {
if ((!this.ignoreWidth && this._w !== this.$el.offsetWidth) || (!this.ignoreHeight && this._h !== this.$el.offsetHeight)) {
this._w = this.$el.offsetWidth;
this._h = this.$el.offsetHeight;
this.emitSize();
}
},
emitSize () {
this.$emit('notify', {
width: this._w,
height: this._h,
});
},
addResizeHandlers () {
this._resizeObject.contentDocument.defaultView.addEventListener('resize', this.compareAndNotify);
this.compareAndNotify();
},
removeResizeHandlers () {
if (this._resizeObject && this._resizeObject.onload) {
if (!isIE && this._resizeObject.contentDocument) {
this._resizeObject.contentDocument.defaultView.removeEventListener('resize', this.compareAndNotify);
}
this.$el.removeChild(this._resizeObject);
this._resizeObject.onload = null;
this._resizeObject = null;
}
},
},
};
const _withId = /*#__PURE__*/withScopeId("data-v-b329ee4c");
pushScopeId("data-v-b329ee4c");
const _hoisted_1 = {
class: "resize-observer",
tabindex: "-1"
};
popScopeId();
const render = /*#__PURE__*/_withId((_ctx, _cache, $props, $setup, $data, $options) => {
return (openBlock(), createBlock("div", _hoisted_1))
});
script.render = render;
script.__scopeId = "data-v-b329ee4c";
script.__file = "src/components/ResizeObserver.vue";
function install(app) {
// eslint-disable-next-line vue/component-definition-name-casing
app.component('resize-observer', script);
app.component('ResizeObserver', script);
}
var plugin = {
// eslint-disable-next-line no-undef
version: "2.0.0-alpha.1",
install: install
};
export default plugin;
export { script as ResizeObserver, install };
//# sourceMappingURL=vue-resize.esm.js.map
File diff suppressed because one or more lines are too long
+2
View File
@@ -0,0 +1,2 @@
var VueResize=function(e,t){"use strict";let i;function s(){s.init||(s.init=!0,i=-1!==function(){var e=window.navigator.userAgent,t=e.indexOf("MSIE ");if(t>0)return parseInt(e.substring(t+5,e.indexOf(".",t)),10);if(e.indexOf("Trident/")>0){var i=e.indexOf("rv:");return parseInt(e.substring(i+3,e.indexOf(".",i)),10)}var s=e.indexOf("Edge/");return s>0?parseInt(e.substring(s+5,e.indexOf(".",s)),10):-1}())}var n={name:"ResizeObserver",props:{emitOnMount:{type:Boolean,default:!1},ignoreWidth:{type:Boolean,default:!1},ignoreHeight:{type:Boolean,default:!1}},emits:["notify"],mounted(){s(),t.nextTick(()=>{this._w=this.$el.offsetWidth,this._h=this.$el.offsetHeight,this.emitOnMount&&this.emitSize()});const e=document.createElement("object");this._resizeObject=e,e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex",-1),e.onload=this.addResizeHandlers,e.type="text/html",i&&this.$el.appendChild(e),e.data="about:blank",i||this.$el.appendChild(e)},beforeUnmount(){this.removeResizeHandlers()},methods:{compareAndNotify(){(!this.ignoreWidth&&this._w!==this.$el.offsetWidth||!this.ignoreHeight&&this._h!==this.$el.offsetHeight)&&(this._w=this.$el.offsetWidth,this._h=this.$el.offsetHeight,this.emitSize())},emitSize(){this.$emit("notify",{width:this._w,height:this._h})},addResizeHandlers(){this._resizeObject.contentDocument.defaultView.addEventListener("resize",this.compareAndNotify),this.compareAndNotify()},removeResizeHandlers(){this._resizeObject&&this._resizeObject.onload&&(!i&&this._resizeObject.contentDocument&&this._resizeObject.contentDocument.defaultView.removeEventListener("resize",this.compareAndNotify),this.$el.removeChild(this._resizeObject),this._resizeObject.onload=null,this._resizeObject=null)}}};const r=t.withScopeId("data-v-b329ee4c");t.pushScopeId("data-v-b329ee4c");const o={class:"resize-observer",tabindex:"-1"};t.popScopeId();const d=r((e,i,s,n,r,d)=>(t.openBlock(),t.createBlock("div",o)));function h(e){e.component("resize-observer",n),e.component("ResizeObserver",n)}n.render=d,n.__scopeId="data-v-b329ee4c",n.__file="src/components/ResizeObserver.vue";var a={version:"2.0.0-alpha.1",install:h};return e.ResizeObserver=n,e.default=a,e.install=h,Object.defineProperty(e,"__esModule",{value:!0}),e}({},Vue);
//# sourceMappingURL=vue-resize.min.js.map
File diff suppressed because one or more lines are too long
+166
View File
@@ -0,0 +1,166 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) :
typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['vue-resize'] = {}, global.vue));
}(this, (function (exports, vue) { 'use strict';
function getInternetExplorerVersion() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// Edge (IE 12+) => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
} // other browser
return -1;
}
let isIE;
function initCompat () {
if (!initCompat.init) {
initCompat.init = true;
isIE = getInternetExplorerVersion() !== -1;
}
}
var script = {
name: 'ResizeObserver',
props: {
emitOnMount: {
type: Boolean,
default: false,
},
ignoreWidth: {
type: Boolean,
default: false,
},
ignoreHeight: {
type: Boolean,
default: false,
},
},
emits: [
'notify',
],
mounted () {
initCompat();
vue.nextTick(() => {
this._w = this.$el.offsetWidth;
this._h = this.$el.offsetHeight;
if (this.emitOnMount) {
this.emitSize();
}
});
const object = document.createElement('object');
this._resizeObject = object;
object.setAttribute('aria-hidden', 'true');
object.setAttribute('tabindex', -1);
object.onload = this.addResizeHandlers;
object.type = 'text/html';
if (isIE) {
this.$el.appendChild(object);
}
object.data = 'about:blank';
if (!isIE) {
this.$el.appendChild(object);
}
},
beforeUnmount () {
this.removeResizeHandlers();
},
methods: {
compareAndNotify () {
if ((!this.ignoreWidth && this._w !== this.$el.offsetWidth) || (!this.ignoreHeight && this._h !== this.$el.offsetHeight)) {
this._w = this.$el.offsetWidth;
this._h = this.$el.offsetHeight;
this.emitSize();
}
},
emitSize () {
this.$emit('notify', {
width: this._w,
height: this._h,
});
},
addResizeHandlers () {
this._resizeObject.contentDocument.defaultView.addEventListener('resize', this.compareAndNotify);
this.compareAndNotify();
},
removeResizeHandlers () {
if (this._resizeObject && this._resizeObject.onload) {
if (!isIE && this._resizeObject.contentDocument) {
this._resizeObject.contentDocument.defaultView.removeEventListener('resize', this.compareAndNotify);
}
this.$el.removeChild(this._resizeObject);
this._resizeObject.onload = null;
this._resizeObject = null;
}
},
},
};
const _withId = /*#__PURE__*/vue.withScopeId("data-v-b329ee4c");
vue.pushScopeId("data-v-b329ee4c");
const _hoisted_1 = {
class: "resize-observer",
tabindex: "-1"
};
vue.popScopeId();
const render = /*#__PURE__*/_withId((_ctx, _cache, $props, $setup, $data, $options) => {
return (vue.openBlock(), vue.createBlock("div", _hoisted_1))
});
script.render = render;
script.__scopeId = "data-v-b329ee4c";
script.__file = "src/components/ResizeObserver.vue";
function install(app) {
// eslint-disable-next-line vue/component-definition-name-casing
app.component('resize-observer', script);
app.component('ResizeObserver', script);
}
var plugin = {
// eslint-disable-next-line no-undef
version: "2.0.0-alpha.1",
install: install
};
exports.ResizeObserver = script;
exports.default = plugin;
exports.install = install;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=vue-resize.umd.js.map
File diff suppressed because one or more lines are too long
+77
View File
@@ -0,0 +1,77 @@
{
"name": "vue-resize",
"description": "Detects DOM element resizing",
"version": "2.0.0-alpha.1",
"author": {
"name": "Guillaume Chau",
"email": "guillaume.b.chau@gmail.com"
},
"keywords": [
"vue",
"vuejs",
"plugin"
],
"license": "MIT",
"main": "dist/vue-resize.umd.js",
"module": "dist/vue-resize.esm.js",
"unpkg": "dist/vue-resize.min.js",
"scripts": {
"build": "yarn run build:browser && yarn run build:es && yarn run build:umd",
"build:browser": "rollup --config build/rollup.config.browser.js",
"build:es": "rollup --config build/rollup.config.es.js",
"build:umd": "rollup --config build/rollup.config.umd.js",
"prepublishOnly": "yarn run test",
"dev": "cross-env NODE_ENV=development rollup --config build/rollup.config.es.js --watch",
"test": "yarn run build && yarn run lint && cd ../demo && yarn run test",
"lint": "eslint --ext .js,.vue src"
},
"watch": {
"build": "src/*.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Akryum/vue-resize.git",
"directory": "packages/vue-resize"
},
"bugs": {
"url": "https://github.com/Akryum/vue-resize/issues"
},
"homepage": "https://github.com/Akryum/vue-resize#readme",
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@rollup/plugin-babel": "^5.2.2",
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-eslint": "^8.0.1",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-replace": "^2.3.1",
"@vue/compiler-sfc": "^3.0.2",
"autoprefixer": "^9.7.5",
"babel-eslint": "^10.1.0",
"clean-css": "^4.1.8",
"cross-env": "^7.0.2",
"eslint": "^7.16.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-html": "^6.1.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^5.0.0",
"eslint-plugin-vue": "^7.4.0",
"fs-extra": "^9.0.0",
"rollup": "^2.2.0",
"rollup-plugin-css-only": "^2.0.0",
"rollup-plugin-css-porter": "^1.0.2",
"rollup-plugin-terser": "^5.3.0",
"rollup-plugin-vue": "^6.0.0",
"vue": "^3.0.0"
},
"peerDependencies": {
"vue": "^3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
+1
View File
@@ -0,0 +1 @@
module.exports = {}
+135
View File
@@ -0,0 +1,135 @@
<template>
<div
class="resize-observer"
tabindex="-1"
/>
</template>
<script>
import { nextTick } from 'vue'
import { getInternetExplorerVersion } from '../utils/compatibility'
let isIE
function initCompat () {
if (!initCompat.init) {
initCompat.init = true
isIE = getInternetExplorerVersion() !== -1
}
}
export default {
name: 'ResizeObserver',
props: {
emitOnMount: {
type: Boolean,
default: false,
},
ignoreWidth: {
type: Boolean,
default: false,
},
ignoreHeight: {
type: Boolean,
default: false,
},
},
emits: [
'notify',
],
mounted () {
initCompat()
nextTick(() => {
this._w = this.$el.offsetWidth
this._h = this.$el.offsetHeight
if (this.emitOnMount) {
this.emitSize()
}
})
const object = document.createElement('object')
this._resizeObject = object
object.setAttribute('aria-hidden', 'true')
object.setAttribute('tabindex', -1)
object.onload = this.addResizeHandlers
object.type = 'text/html'
if (isIE) {
this.$el.appendChild(object)
}
object.data = 'about:blank'
if (!isIE) {
this.$el.appendChild(object)
}
},
beforeUnmount () {
this.removeResizeHandlers()
},
methods: {
compareAndNotify () {
if ((!this.ignoreWidth && this._w !== this.$el.offsetWidth) || (!this.ignoreHeight && this._h !== this.$el.offsetHeight)) {
this._w = this.$el.offsetWidth
this._h = this.$el.offsetHeight
this.emitSize()
}
},
emitSize () {
this.$emit('notify', {
width: this._w,
height: this._h,
})
},
addResizeHandlers () {
this._resizeObject.contentDocument.defaultView.addEventListener('resize', this.compareAndNotify)
this.compareAndNotify()
},
removeResizeHandlers () {
if (this._resizeObject && this._resizeObject.onload) {
if (!isIE && this._resizeObject.contentDocument) {
this._resizeObject.contentDocument.defaultView.removeEventListener('resize', this.compareAndNotify)
}
this.$el.removeChild(this._resizeObject)
this._resizeObject.onload = null
this._resizeObject = null
}
},
},
}
</script>
<style scoped>
.resize-observer {
position: absolute;
top: 0;
left: 0;
z-index: -1;
width: 100%;
height: 100%;
border: none;
background-color: transparent;
pointer-events: none;
display: block;
overflow: hidden;
opacity: 0;
}
.resize-observer:deep(object) {
display: block;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
overflow: hidden;
pointer-events: none;
z-index: -1;
}
</style>
+21
View File
@@ -0,0 +1,21 @@
import ResizeObserver from './components/ResizeObserver.vue'
// Install the components
export function install (app) {
// eslint-disable-next-line vue/component-definition-name-casing
app.component('resize-observer', ResizeObserver)
app.component('ResizeObserver', ResizeObserver)
}
export {
ResizeObserver,
}
// Plugin
const plugin = {
// eslint-disable-next-line no-undef
version: VERSION,
install,
}
export default plugin
+25
View File
@@ -0,0 +1,25 @@
export function getInternetExplorerVersion () {
const ua = window.navigator.userAgent
const msie = ua.indexOf('MSIE ')
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10)
}
const trident = ua.indexOf('Trident/')
if (trident > 0) {
// IE 11 => return version number
const rv = ua.indexOf('rv:')
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10)
}
const edge = ua.indexOf('Edge/')
if (edge > 0) {
// Edge (IE 12+) => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10)
}
// other browser
return -1
}