diff --git a/package.json b/package.json new file mode 100644 index 0000000..4e296de --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "cell-watermark", + "version": "1.0.3", + "description": "Create watermark for webpage and automatic adjust when window resize", + "main": "src/watermark.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Lruihao/watermark.git" + }, + "keywords": [ + "watermark", + "cell-watermark" + ], + "author": "Lruihao", + "license": "MIT", + "bugs": { + "url": "https://github.com/Lruihao/watermark/issues" + }, + "homepage": "https://github.com/Lruihao/watermark#readme" +} diff --git a/watermark.js b/src/watermark.js similarity index 96% rename from watermark.js rename to src/watermark.js index 13cab74..a36efdc 100644 --- a/watermark.js +++ b/src/watermark.js @@ -1,6 +1,14 @@ /* global Watermark */ -var Watermark = (function () { +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + define([], factory()); + } else if (typeof module === 'object' && module.exports) { + module.exports = factory(); + } else { + root['Watermark'] = factory(); + } +})(this, function () { var _parentEle; var _wmContainer; var _wmObserver; @@ -199,4 +207,4 @@ var Watermark = (function () { }; } return Watermark; -})(); +}); diff --git a/src/watermark.min.js b/src/watermark.min.js new file mode 100644 index 0000000..848e4b3 --- /dev/null +++ b/src/watermark.min.js @@ -0,0 +1 @@ +(function(e,t){"function"==typeof define&&define.amd?define([],t()):"object"==typeof module&&module.exports?module.exports=t():e.Watermark=t()})(this,function(){function e(t={}){var n=e.prototype;this.options=t,s(this),d(this,this.options),h(this),p(this),n.upload=function(e){if(e){o.disconnect(),i.disconnect(),this.options.content=e;for(const t of this._container.querySelectorAll(".cell-watermark"))t.innerHTML=e;o.observe(this._container.parentNode,{childList:!0,subtree:!0}),i.observe(this._container,{attributes:!0,childList:!0,characterData:!0,subtree:!0})}},n.render=function(e={}){l(this,Object.assign(this.options,e))},n.destroy=function(){i.disconnect(),o.disconnect(),window.removeEventListener("resize",r),this._container.parentNode.removeChild(this._container)}}var t,n,i,o,r,c=window.outerWidth,a=window.outerHeight,s=function(e){e._container=document.createElement("div"),e._container.classList.add("cell-watermark-container"),e._container.style.cssText="display: block; pointer-events: none;",e._container.setAttribute("aria-hidden",!0),t=document.querySelector(e.options.appendTo)||document.body,t.appendChild(e._container)},d=function(e,t){t.rowSpacing=t.rowSpacing||60,t.colSpacing=t.colSpacing||30,t.width=t.width||150,t.height=t.height||20;let i=parseInt(a/(t.height+t.rowSpacing)),o=parseInt(c/(t.width+t.colSpacing)),r=(c-t.width*o-t.colSpacing*(o-1))/2,s=(a-t.height*i-t.rowSpacing*(i-1))/2,d=document.createElement("div");d.classList.add("cell-watermark"),d.style.cssText="transform: rotate(15deg); opacity: 0.1; font-size: 0.85rem; text-align: center;position: fixed; user-select: none; word-break: break-all; overflow: hidden; z-index: 999999;";for(let n=0;n0&&0===document.querySelectorAll(".cell-watermark-container").length&&t.appendChild(n)}),o.observe(e._container.parentNode,{childList:!0,subtree:!0})},p=function(e){r=function(){window.outerHeight===a&&window.outerWidth===c||(a=window.outerHeight,c=window.outerWidth,l(e,e.options))},window.addEventListener("resize",r)};return e}); \ No newline at end of file diff --git a/watermark.min.js b/watermark.min.js deleted file mode 100644 index 13fba31..0000000 --- a/watermark.min.js +++ /dev/null @@ -1 +0,0 @@ -var Watermark=function(){function t(e={}){var n=t.prototype;this.options=e,s(this),d(this,this.options),h(this),p(this),n.upload=function(t){if(t){o.disconnect(),i.disconnect(),this.options.content=t;for(const e of this._container.querySelectorAll(".cell-watermark"))e.innerHTML=t;o.observe(this._container.parentNode,{childList:!0,subtree:!0}),i.observe(this._container,{attributes:!0,childList:!0,characterData:!0,subtree:!0})}},n.render=function(t={}){l(this,Object.assign(this.options,t))},n.destroy=function(){i.disconnect(),o.disconnect(),window.removeEventListener("resize",r),this._container.parentNode.removeChild(this._container)}}var e,n,i,o,r,c=window.outerWidth,a=window.outerHeight,s=function(t){t._container=document.createElement("div"),t._container.classList.add("cell-watermark-container"),t._container.style.cssText="display: block; pointer-events: none;",t._container.setAttribute("aria-hidden",!0),e=document.querySelector(t.options.appendTo)||document.body,e.appendChild(t._container)},d=function(t,e){e.rowSpacing=e.rowSpacing||60,e.colSpacing=e.colSpacing||30,e.width=e.width||150,e.height=e.height||20;let i=parseInt(a/(e.height+e.rowSpacing)),o=parseInt(c/(e.width+e.colSpacing)),r=(c-e.width*o-e.colSpacing*(o-1))/2,s=(a-e.height*i-e.rowSpacing*(i-1))/2,d=document.createElement("div");d.classList.add("cell-watermark"),d.style.cssText="transform: rotate(15deg); opacity: 0.1; font-size: 0.85rem; text-align: center;position: fixed; user-select: none; word-break: break-all; overflow: hidden; z-index: 999999;";for(let n=0;n0&&0===document.querySelectorAll(".cell-watermark-container").length&&e.appendChild(n)}),o.observe(t._container.parentNode,{childList:!0,subtree:!0})},p=function(t){r=function(){window.outerHeight===a&&window.outerWidth===c||(a=window.outerHeight,c=window.outerWidth,l(t,t.options))},window.addEventListener("resize",r)};return t}(); \ No newline at end of file