@univerjs/watermark 0.5.0-alpha.0 → 0.5.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -9
- package/lib/es/index.js +133 -775
- package/lib/types/controllers/config.schema.d.ts +0 -1
- package/lib/types/index.d.ts +2 -1
- package/lib/types/plugin.d.ts +2 -4
- package/lib/umd/index.js +1 -9
- package/package.json +9 -10
- package/lib/index.css +0 -1
- package/lib/types/commands/operations/open-watermark-panel.operation.d.ts +0 -2
- package/lib/types/controllers/menu.d.ts +0 -3
- package/lib/types/controllers/menu.schema.d.ts +0 -2
- package/lib/types/controllers/watermark.menu.controller.d.ts +0 -9
- package/lib/types/views/components/WatermarkImageSetting.d.ts +0 -8
- package/lib/types/views/components/WatermarkPanel.d.ts +0 -2
- package/lib/types/views/components/WatermarkPanelFooter.d.ts +0 -2
- package/lib/types/views/components/WatermarkTextSetting.d.ts +0 -8
package/lib/cjs/index.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
"use strict";var ne=Object.defineProperty;var ie=(e,t,a)=>t in e?ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a;var x=(e,t,a)=>ie(e,typeof t!="symbol"?t+"":t,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),X=require("@univerjs/engine-render"),N=require("@univerjs/ui"),v=require("react"),u=require("@univerjs/design"),R=require("rxjs"),K="UNIVER_WATERMARK_MENU",V="WATERMARK_PANEL",z="WATERMARK_PANEL_FOOTER",I="UNIVER_WATERMARK_STORAGE_KEY",se=10,oe=["image/png","image/jpeg","image/jpg","image/bmp"],L={content:"",fontSize:16,color:"rgb(0,0,0)",bold:!1,italic:!1,direction:"ltr",x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},$={url:"",width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},q={name:!0,email:!1,phone:!1,uid:!1,fontSize:16,color:"rgb(0,0,0)",bold:!1,italic:!1,direction:"ltr",x:60,y:60,repeat:!0,spacingX:200,spacingY:100,rotate:-30,opacity:.15},H={type:c.CommandType.OPERATION,id:"univer.operation.open-watermark-panel",handler(e){const t=e.get(N.ISidebarService),a=e.get(c.LocaleService);return t.open({header:{title:a.t("univer-watermark.title")},children:{label:V},footer:{label:z},onClose:()=>{},width:330}),!0}};var d=(e=>(e.UserInfo="userInfo",e.Text="text",e.Image="image",e))(d||{}),w=function(){return w=Object.assign||function(e){for(var t,a=1,r=arguments.length;a<r;a++){t=arguments[a];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},w.apply(this,arguments)},le=function(e,t){var a={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(a[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(a[r[i]]=e[r[i]]);return a},P=v.forwardRef(function(e,t){var a=e.icon,r=e.id,i=e.className,n=e.extend,l=le(e,["icon","id","className","extend"]),p="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),g=v.useRef("_".concat(ue()));return G(a,"".concat(r),{defIds:a.defIds,idSuffix:g.current},w({ref:t,className:p},l),n)});function G(e,t,a,r,i){return v.createElement(e.tag,w(w({key:t},ce(e,a,i)),r),(me(e,a).children||[]).map(function(n,l){return G(n,"".concat(t,"-").concat(e.tag,"-").concat(l),a,void 0,i)}))}function ce(e,t,a){var r=w({},e.attrs);a!=null&&a.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=a.colorChannel1);var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+t.idSuffix),Object.entries(r).forEach(function(n){var l=n[0],p=n[1];typeof p=="string"&&(r[l]=p.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),r}function me(e,t){var a,r=t.defIds;return!r||r.length===0?e:e.tag==="defs"&&(!((a=e.children)===null||a===void 0)&&a.length)?w(w({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.indexOf(i.attrs.id)>-1?w(w({},i),{attrs:w(w({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function ue(){return Math.random().toString(36).substring(2,8)}P.displayName="UniverIcon";var de={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.65791 1.30005C3.77355 1.30005 3.05664 2.01696 3.05664 2.90132V12.8588C3.05664 13.8755 3.88086 14.6998 4.89759 14.6998H9.1016C11.2233 14.6998 12.9433 12.9798 12.9433 10.8581C12.9433 9.13925 11.8145 7.68407 10.2578 7.1934C10.8806 6.56856 11.2655 5.70659 11.2655 4.75472C11.2655 2.84676 9.71883 1.30005 7.81087 1.30005H4.65791ZM4.25664 2.90132C4.25664 2.6797 4.4363 2.50005 4.65791 2.50005H7.81087C9.05609 2.50005 10.0655 3.5095 10.0655 4.75472C10.0655 5.99993 9.05609 7.00938 7.81087 7.00938H4.25664V2.90132ZM4.25664 12.8588V8.21636H9.1016C10.5606 8.21636 11.7433 9.39909 11.7433 10.8581C11.7433 12.317 10.5606 13.4998 9.1016 13.4998H4.89759C4.5436 13.4998 4.25664 13.2128 4.25664 12.8588Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Z=v.forwardRef(function(e,t){return v.createElement(P,Object.assign({},e,{id:"bold-single",ref:t,icon:de}))});Z.displayName="BoldSingle";var pe={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1198",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_1198)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.68731 9.98425C5.73282 9.87144 5.77827 9.75442 5.82366 9.63323L6.3312 8.27586H9.65859L10.3523 10.1159C10.405 10.284 10.4868 10.4276 10.6023 10.5378C10.74 10.669 10.9119 10.7236 11.1014 10.714C11.3544 10.7131 11.5919 10.6379 11.6996 10.4032L11.7013 10.3992C11.7901 10.1937 11.7749 9.9634 11.6929 9.7289L8.85351 1.86337C8.79546 1.68828 8.6901 1.54881 8.54213 1.45002C8.38836 1.33863 8.1989 1.29112 7.98798 1.29112C7.78272 1.29112 7.59752 1.34014 7.4446 1.45198C7.30481 1.55223 7.20617 1.69184 7.14935 1.86343L4.324 9.70145L4.32281 9.70495C4.27002 9.86052 4.23828 10.0056 4.23828 10.1346C4.23828 10.2646 4.27116 10.3937 4.36281 10.4909C4.50256 10.6468 4.6921 10.714 4.90604 10.714C5.0369 10.714 5.15805 10.6745 5.26156 10.5916C5.3633 10.5247 5.44621 10.4332 5.51101 10.3217C5.57988 10.2177 5.63858 10.1051 5.68731 9.98425ZM6.72105 7.00152L8.00144 3.32827L9.28183 7.00152H6.72105Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"rect",attrs:{width:11.58,height:2.56,x:2.21,y:12.2,fill:"colorChannel1",rx:1.28}}]}]},J=v.forwardRef(function(e,t){return v.createElement(P,Object.assign({},e,{id:"font-color",ref:t,icon:pe}))});J.displayName="FontColor";var ge={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M9.80385 1.40005H11.9997C12.3311 1.40005 12.5997 1.66868 12.5997 2.00005C12.5997 2.33143 12.3311 2.60005 11.9997 2.60005H10.1185L7.12251 13.4001H9.33324C9.66461 13.4001 9.93324 13.6687 9.93324 14.0001C9.93324 14.3314 9.66461 14.6001 9.33324 14.6001H6.34785C6.33847 14.6003 6.32905 14.6003 6.31962 14.6001H3.9999C3.66853 14.6001 3.3999 14.3314 3.3999 14.0001C3.3999 13.6687 3.66853 13.4001 3.9999 13.4001H5.87719L8.87322 2.60005H6.66641C6.33504 2.60005 6.06641 2.33143 6.06641 2.00005C6.06641 1.66868 6.33504 1.40005 6.66641 1.40005H9.52916C9.61698 1.37929 9.71064 1.3781 9.80385 1.40005Z"}}]},Q=v.forwardRef(function(e,t){return v.createElement(P,Object.assign({},e,{id:"italic-single",ref:t,icon:ge}))});Q.displayName="ItalicSingle";var he={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.93949 12.3363L1.94048 12.3357 1.95034 12.33C1.95981 12.3245 1.97499 12.3158 1.99548 12.3043 2.0365 12.2813 2.09866 12.2474 2.17888 12.2061 2.33971 12.1234 2.57112 12.0123 2.84885 11.9012 3.41339 11.6754 4.12822 11.4664 4.81552 11.4664 5.82167 11.4664 6.71309 11.8774 7.74399 12.3643 7.7595 12.3717 7.77504 12.379 7.79061 12.3864 8.77119 12.8497 9.88765 13.3772 11.185 13.3772 12.0901 13.3772 12.9676 13.1085 13.5973 12.8566 13.9167 12.7289 14.1829 12.6011 14.3704 12.5047 14.4644 12.4564 14.5391 12.4157 14.5914 12.3864 14.6175 12.3717 14.6381 12.3599 14.6527 12.3514L14.6702 12.3412 14.6755 12.3381 14.6772 12.337 14.6782 12.3365C14.6782 12.3365 14.6784 12.3363 14.3697 11.8218L14.6782 12.3365C14.9623 12.166 15.0547 11.7973 14.8842 11.5131 14.7138 11.2291 14.3454 11.1369 14.0613 11.3071L14.06 11.3079 14.0502 11.3137C14.0407 11.3192 14.0255 11.3279 14.005 11.3394 13.964 11.3623 13.9019 11.3963 13.8216 11.4375 13.6608 11.5202 13.4294 11.6314 13.1517 11.7424 12.5871 11.9683 11.8723 12.1772 11.185 12.1772 10.1788 12.1772 9.28742 11.7663 8.25652 11.2793 8.24101 11.272 8.22547 11.2646 8.2099 11.2573 7.22931 10.7939 6.11286 10.2664 4.81552 10.2664 3.91046 10.2664 3.03292 10.5351 2.40318 10.787 2.08377 10.9148 1.81757 11.0425 1.63007 11.139 1.53613 11.1873 1.46144 11.228 1.40916 11.2573 1.383 11.2719 1.36241 11.2837 1.34778 11.2922L1.33033 11.3024 1.32504 11.3056 1.32327 11.3066 1.32233 11.3072C1.32233 11.3072 1.32209 11.3073 1.63068 11.8217L1.32233 11.3072C1.03818 11.4777.945803 11.8464 1.11629 12.1305 1.28674 12.4146 1.65536 12.5066 1.93949 12.3363zM1.93949 8.51464L1.94048 8.51406 1.95034 8.50829C1.95981 8.50279 1.97499 8.49407 1.99548 8.4826 2.0365 8.45963 2.09866 8.4257 2.17888 8.38443 2.33971 8.30172 2.57112 8.19061 2.84885 8.07952 3.41339 7.85371 4.12822 7.64473 4.81552 7.64473 5.82167 7.64473 6.71309 8.05572 7.74399 8.54267 7.7595 8.54999 7.77504 8.55733 7.79061 8.56469 8.77119 9.02803 9.88765 9.55557 11.185 9.55557 12.0901 9.55557 12.9676 9.28684 13.5973 9.03494 13.9167 8.90718 14.1829 8.77943 14.3704 8.683 14.4644 8.63469 14.5391 8.59398 14.5914 8.5647 14.6175 8.55006 14.6381 8.53825 14.6527 8.52975L14.6702 8.51954 14.6755 8.51641 14.6772 8.51535 14.6782 8.51479C14.6782 8.51479 14.6784 8.51464 14.3697 8.00015L14.6782 8.51479C14.9623 8.3443 15.0547 7.9756 14.8842 7.69145 14.7138 7.4074 14.3454 7.31523 14.0613 7.48547L14.06 7.48623 14.0502 7.492C14.0407 7.4975 14.0255 7.50622 14.005 7.5177 13.964 7.54067 13.9019 7.5746 13.8216 7.61586 13.6608 7.69857 13.4294 7.80968 13.1517 7.92077 12.5871 8.14659 11.8723 8.35557 11.185 8.35557 10.1788 8.35557 9.28742 7.94457 8.25652 7.45762 8.24101 7.4503 8.22547 7.44296 8.2099 7.4356 7.22931 6.97226 6.11286 6.44473 4.81552 6.44473 3.91046 6.44473 3.03292 6.71346 2.40318 6.96535 2.08377 7.09311 1.81757 7.22086 1.63007 7.31729 1.53613 7.3656 1.46144 7.40631 1.40916 7.43559 1.383 7.45024 1.36241 7.46205 1.34778 7.47054L1.33033 7.48075 1.32504 7.48389 1.32327 7.48494 1.32233 7.48551C1.32233 7.48551 1.32209 7.48565 1.63068 7.99997L1.32233 7.48551C1.03818 7.656.945803 8.0247 1.11629 8.30884 1.28674 8.59292 1.65536 8.68496 1.93949 8.51464zM1.93949 4.69296L1.94048 4.69238 1.95034 4.68661C1.95981 4.68111 1.97499 4.67239 1.99548 4.66092 2.0365 4.63795 2.09866 4.60402 2.17888 4.56276 2.33971 4.48004 2.57112 4.36893 2.84885 4.25784 3.41339 4.03203 4.12822 3.82305 4.81552 3.82305 5.82167 3.82305 6.71309 4.23404 7.74399 4.72099 7.7595 4.72831 7.77504 4.73566 7.79061 4.74301 8.77119 5.20635 9.88765 5.73389 11.185 5.73389 12.0901 5.73389 12.9676 5.46516 13.5973 5.21326 13.9167 5.0855 14.1829 4.95775 14.3704 4.86132 14.4644 4.81301 14.5391 4.7723 14.5914 4.74302 14.6175 4.72838 14.6381 4.71657 14.6527 4.70807L14.6702 4.69786 14.6755 4.69473 14.6772 4.69367 14.6782 4.69311C14.6782 4.69311 14.6784 4.69296 14.3697 4.17847L14.6782 4.69311C14.9623 4.52262 15.0547 4.15392 14.8842 3.86977 14.7138 3.58572 14.3454 3.49355 14.0613 3.66379L14.06 3.66455 14.0502 3.67032C14.0407 3.67582 14.0255 3.68454 14.005 3.69602 13.964 3.71899 13.9019 3.75292 13.8216 3.79418 13.6608 3.87689 13.4294 3.988 13.1517 4.09909 12.5871 4.32491 11.8723 4.53389 11.185 4.53389 10.1788 4.53389 9.28742 4.12289 8.25652 3.63594 8.24101 3.62862 8.22547 3.62128 8.2099 3.61392 7.22931 3.15058 6.11286 2.62305 4.81552 2.62305 3.91046 2.62305 3.03292 2.89178 2.40318 3.14367 2.08377 3.27143 1.81757 3.39918 1.63007 3.49561 1.53613 3.54392 1.46144 3.58463 1.40916 3.61391 1.383 3.62856 1.36241 3.64037 1.34778 3.64886L1.33033 3.65907 1.32504 3.66221 1.32327 3.66326 1.32233 3.66383C1.32233 3.66383 1.32209 3.66397 1.63068 4.17829L1.32233 3.66383C1.03818 3.83432.945803 4.20302 1.11629 4.48716 1.28674 4.77124 1.65536 4.86329 1.93949 4.69296z",fillRule:"evenodd",clipRule:"evenodd"}}]},ee=v.forwardRef(function(e,t){return v.createElement(P,Object.assign({},e,{id:"watermark-single",ref:t,icon:he}))});ee.displayName="WatermarkSingle";var te={exports:{}},O={};/**
|
|
2
|
-
* @license React
|
|
3
|
-
* react-jsx-runtime.production.min.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ve=v,fe=Symbol.for("react.element"),ke=Symbol.for("react.fragment"),we=Object.prototype.hasOwnProperty,Se=ve.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,xe={key:!0,ref:!0,__self:!0,__source:!0};function re(e,t,a){var r,i={},n=null,l=null;a!==void 0&&(n=""+a),t.key!==void 0&&(n=""+t.key),t.ref!==void 0&&(l=t.ref);for(r in t)we.call(t,r)&&!xe.hasOwnProperty(r)&&(i[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)i[r]===void 0&&(i[r]=t[r]);return{$$typeof:fe,type:e,key:n,ref:l,props:i,_owner:Se.current}}O.Fragment=ke;O.jsx=re;O.jsxs=re;te.exports=O;var s=te.exports,Ie=Object.defineProperty,_e=Object.getOwnPropertyDescriptor,ye=(e,t,a,r)=>{for(var i=r>1?void 0:r?_e(t,a):t,n=e.length-1,l;n>=0;n--)(l=e[n])&&(i=(r?l(t,a,i):l(i))||i);return r&&i&&Ie(t,a,i),i},Ce=(e,t)=>(a,r)=>t(a,r,e);exports.WatermarkService=class extends c.Disposable{constructor(a){super();x(this,"_updateConfig$",new R.Subject);x(this,"updateConfig$",this._updateConfig$.asObservable());x(this,"_refresh$",new R.Subject);x(this,"refresh$",this._refresh$.asObservable());this._localStorageService=a}async getWatermarkConfig(){return await this._localStorageService.getItem(I)}updateWatermarkConfig(a){this._localStorageService.setItem(I,a),this._updateConfig$.next(a)}deleteWatermarkConfig(){this._localStorageService.removeItem(I),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}};exports.WatermarkService=ye([Ce(0,c.Inject(c.ILocalStorageService))],exports.WatermarkService);const je="univer-watermark-panel",Ne="univer-watermark-panel-type-title",We="univer-watermark-panel-type-select",be="univer-watermark-panel-setting",Te="univer-watermark-panel-footer",Re="univer-watermark-panel-footer-button-wrapper",Le="univer-watermark-panel-footer-reset",Pe="univer-watermark-text-setting",Me="univer-watermark-text-setting-header",Oe="univer-watermark-text-setting-font-content",Ee="univer-watermark-text-setting-font-style-part",Fe="univer-watermark-text-setting-layout-font-wrapper",Ae="univer-watermark-image-setting",Ue="univer-watermark-input",De="univer-watermark-input-content",$e="univer-watermark-icon",He="univer-watermark-icon-wrapper",Ye="univer-watermark-icon-wrapper-select",Be="univer-watermark-color-picker-wrapper",o={watermarkPanel:je,watermarkPanelTypeTitle:Ne,watermarkPanelTypeSelect:We,watermarkPanelSetting:be,watermarkPanelFooter:Te,watermarkPanelFooterButtonWrapper:Re,watermarkPanelFooterReset:Le,watermarkTextSetting:Pe,watermarkTextSettingHeader:Me,watermarkTextSettingFontContent:Oe,watermarkTextSettingFontStylePart:Ee,watermarkTextSettingLayoutFontWrapper:Fe,watermarkImageSetting:Ae,watermarkInput:Ue,watermarkInputContent:De,watermarkIcon:$e,watermarkIconWrapper:He,watermarkIconWrapperSelect:Ye,watermarkColorPickerWrapper:Be},Xe=({config:e,onChange:t})=>{const a=c.useDependency(N.ILocalFileService),r=c.useDependency(c.LocaleService);if(!e)return null;const i=async()=>{const n=await a.openFile({multiple:!1,accept:oe.map(h=>`.${h.replace("image/","")}`).join(",")});if(n.length===0)return!1;const p=n[0],g=new FileReader;g.onload=function(h){var m;if((m=h.target)!=null&&m.result){const f=h.target.result,k=new Image;k.onload=function(){t({...e,url:f,width:Math.max(20,k.width),height:Math.max(k.height,20),originRatio:k.width/k.height})},k.src=f}},g.readAsDataURL(p)};return s.jsxs("div",{className:o.watermarkImageSetting,children:[s.jsx("div",{className:o.watermarkTextSettingHeader,children:r.t("univer-watermark.image")}),s.jsxs("div",{className:o.watermarkTextSettingLayout,children:[s.jsx("span",{children:r.t("univer-watermark.image")}),s.jsx(u.Button,{onClick:i,style:{marginLeft:8},children:e.url?r.t("univer-watermark.replaceImage"):r.t("univer-watermark.uploadImage")}),s.jsxs("div",{className:o.watermarkTextSettingFontStylePart,children:[s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.opacity")}),s.jsx(u.InputNumber,{value:e.opacity,onChange:n=>{n!=null&&t({...e,opacity:Number.parseFloat(n.toString())})},max:1,min:0,step:.05,className:o.watermarkInput})]}),s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.keepRatio")}),s.jsx(u.Checkbox,{checked:e.maintainAspectRatio,onChange:n=>{t(n===!0?{...e,maintainAspectRatio:n,height:Math.round(e.width/e.originRatio)}:{...e,maintainAspectRatio:n})}})]})]})]}),s.jsx("div",{className:o.watermarkTextSettingLayout,children:s.jsxs("div",{className:o.watermarkTextSettingFontStylePart,children:[s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.width")}),s.jsx(u.InputNumber,{value:e.width,onChange:n=>{if(n!=null){const l=Math.max(20,Number.parseInt(n.toString()));e.maintainAspectRatio?t({...e,width:l,height:Math.round(l/e.originRatio)}):t({...e,width:l})}},min:20,className:o.watermarkInput})]}),s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.height")}),s.jsx(u.InputNumber,{value:e.height,onChange:n=>{if(n!=null){const l=Math.max(20,Number.parseInt(n.toString()));e.maintainAspectRatio?t({...e,height:l,width:Math.round(l*e.originRatio)}):t({...e,height:Number.parseInt(n.toString())})}},min:20,className:o.watermarkInput})]})]})}),s.jsx("div",{className:o.watermarkTextSettingHeader,children:r.t("univer-watermark.layout")}),s.jsxs("div",{className:o.watermarkTextSettingLayout,children:[s.jsxs("div",{className:o.watermarkTextSettingFontStylePart,children:[s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.rotate")}),s.jsx(u.InputNumber,{value:e.rotate,onChange:n=>{n!=null&&t({...e,rotate:Number.parseInt(n.toString())})},max:360,min:-360,className:o.watermarkInput})]}),s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.repeat")}),s.jsx(u.Checkbox,{checked:e.repeat,onChange:n=>t({...e,repeat:n})})]})]}),s.jsxs("div",{className:o.watermarkTextSettingFontStylePart,children:[s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.spacingX")}),s.jsx(u.InputNumber,{value:e.spacingX,onChange:n=>{n!=null&&t({...e,spacingX:Number.parseInt(n.toString())})},min:0,className:o.watermarkInput})]}),s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.spacingY")}),s.jsx(u.InputNumber,{value:e.spacingY,onChange:n=>{n!=null&&t({...e,spacingY:Number.parseInt(n.toString())})},min:0,className:o.watermarkInput})]})]}),s.jsxs("div",{className:o.watermarkTextSettingFontStylePart,children:[s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.startX")}),s.jsx(u.InputNumber,{value:e.x,onChange:n=>{n!=null&&t({...e,x:Number.parseInt(n.toString())})},min:0,className:o.watermarkInput})]}),s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.startY")}),s.jsx(u.InputNumber,{value:e.y,onChange:n=>{n!=null&&t({...e,y:Number.parseInt(n.toString())})},min:0,className:o.watermarkInput})]})]})]})]})};function ae(e){var t,a,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(a=ae(e[t]))&&(r&&(r+=" "),r+=a)}else for(a in e)e[a]&&(r&&(r+=" "),r+=a);return r}function Y(){for(var e,t,a=0,r="",i=arguments.length;a<i;a++)(e=arguments[a])&&(t=ae(e))&&(r&&(r+=" "),r+=t);return r}const Ke=e=>{var i;const{config:t,onChange:a}=e,r=c.useDependency(c.LocaleService);return t?s.jsxs("div",{className:o.watermarkTextSetting,children:[s.jsx("div",{className:o.watermarkTextSettingHeader,children:r.t("univer-watermark.style")}),s.jsxs("div",{className:o.watermarkTextSettingFontContent,children:[s.jsx("div",{children:r.t("univer-watermark.content")}),s.jsx(u.Input,{value:t.content,onChange:n=>a({...t,content:n}),className:o.watermarkInputContent,placeholder:r.t("univer-watermark.textPlaceholder")})]}),s.jsxs("div",{className:o.watermarkTextSettingFontStyle,children:[s.jsxs("div",{className:o.watermarkTextSettingFontStylePart,children:[s.jsxs("div",{children:[s.jsx("div",{children:r.t("univer-watermark.fontSize")}),s.jsx(u.InputNumber,{value:t.fontSize,onChange:n=>{n!=null&&a({...t,fontSize:Number.parseInt(n.toString())})},max:72,min:12,className:o.watermarkInput})]}),s.jsxs("div",{style:{margin:"0 8px"},children:[s.jsx("div",{children:r.t("univer-watermark.direction")}),s.jsx(u.Select,{value:t.direction,onChange:n=>a({...t,direction:n}),options:[{label:r.t("univer-watermark.ltr"),value:"ltr"},{label:r.t("univer-watermark.rtl"),value:"rtl"}]})]}),s.jsxs("div",{children:[s.jsx("div",{children:r.t("univer-watermark.opacity")}),s.jsx(u.InputNumber,{value:t.opacity,onChange:n=>{n!=null&&a({...t,opacity:Number.parseFloat(n.toString())})},max:1,min:0,step:.05,className:o.watermarkInput})]})]}),s.jsxs("div",{className:o.watermarkTextSettingFontStylePart,children:[s.jsx("div",{className:o.watermarkIconWrapper,children:s.jsx(u.Dropdown,{overlay:s.jsx("div",{className:o.watermarkColorPickerWrapper,children:s.jsx(u.ColorPicker,{color:t.color,onChange:n=>a({...t,color:n})})}),children:s.jsx(J,{className:o.watermarkIcon,extend:{colorChannel1:(i=t.color)!=null?i:"rgb(var(--primary-color))"}})})}),s.jsx("div",{className:Y(o.watermarkIconWrapper,{[o.watermarkIconWrapperSelect]:t.bold}),onClick:()=>{a({...t,bold:!t.bold})},children:s.jsx(Z,{className:o.watermarkIcon})}),s.jsx("div",{className:Y(o.watermarkIconWrapper,{[o.watermarkIconWrapperSelect]:t.italic}),onClick:()=>{a({...t,italic:!t.italic})},children:s.jsx(Q,{className:o.watermarkIcon})})]})]}),s.jsx("div",{className:o.watermarkTextSettingHeader,children:r.t("univer-watermark.layout")}),s.jsxs("div",{className:o.watermarkTextSettingLayout,children:[s.jsxs("div",{className:o.watermarkTextSettingFontStylePart,children:[s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.rotate")}),s.jsx(u.InputNumber,{value:t.rotate,onChange:n=>{n!=null&&a({...t,rotate:Number.parseInt(n.toString())})},max:360,min:-360,className:o.watermarkInput})]}),s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.repeat")}),s.jsx(u.Checkbox,{checked:t.repeat,onChange:n=>a({...t,repeat:n})})]})]}),s.jsxs("div",{className:o.watermarkTextSettingFontStylePart,children:[s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.spacingX")}),s.jsx(u.InputNumber,{value:t.spacingX,onChange:n=>{n!=null&&a({...t,spacingX:Number.parseInt(n.toString())})},min:0,className:o.watermarkInput})]}),s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.spacingY")}),s.jsx(u.InputNumber,{value:t.spacingY,onChange:n=>{n!=null&&a({...t,spacingY:Number.parseInt(n.toString())})},min:0,className:o.watermarkInput})]})]}),s.jsxs("div",{className:o.watermarkTextSettingFontStylePart,children:[s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.startX")}),s.jsx(u.InputNumber,{value:t.x,onChange:n=>{n!=null&&a({...t,x:Number.parseInt(n.toString())})},min:0,className:o.watermarkInput})]}),s.jsxs("div",{className:o.watermarkTextSettingLayoutFontWrapper,children:[s.jsx("div",{children:r.t("univer-watermark.startY")}),s.jsx(u.InputNumber,{value:t.y,onChange:n=>{n!=null&&a({...t,y:Number.parseInt(n.toString())})},min:0,className:o.watermarkInput})]})]})]})]}):null},Ve=()=>{const[e,t]=v.useState(d.Text),[a,r]=v.useState(),i=c.useDependency(exports.WatermarkService),n=c.useDependency(c.ILocalStorageService),l=c.useObservable(i.refresh$),p=c.useDependency(c.LocaleService);function g(m,f){r(m),i.updateWatermarkConfig({type:f!=null?f:e,config:m})}const h=v.useCallback(async()=>{const m=await n.getItem(I);m?(t(m.type),r(m.config)):r({text:L})},[]);return v.useEffect(()=>{h()},[l,h]),s.jsxs("div",{className:o.watermarkPanel,children:[s.jsx("div",{className:o.watermarkPanelTypeTitle,children:p.t("univer-watermark.type")}),s.jsx(u.Select,{value:e,onChange:m=>{t(m),m===d.Text?g({text:L},d.Text):m===d.Image&&g({image:$},d.Image)},options:[{label:p.t("univer-watermark.text"),value:d.Text},{label:p.t("univer-watermark.image"),value:d.Image}],className:o.watermarkPanelTypeSelect}),s.jsxs("div",{className:o.watermarkPanelSetting,children:[e===d.Text&&s.jsx(Ke,{config:a==null?void 0:a.text,onChange:m=>g({text:m})}),e===d.Image&&s.jsx(Xe,{config:a==null?void 0:a.image,onChange:m=>g({image:m})})]})]})},ze=()=>{const e=c.useDependency(N.ISidebarService),t=c.useDependency(exports.WatermarkService),a=c.useDependency(c.LocaleService),r=c.useDependency(N.IClipboardInterfaceService);return s.jsxs("div",{className:o.watermarkPanelFooter,children:[s.jsx("div",{className:o.watermarkPanelFooterReset,onClick:()=>{t.updateWatermarkConfig({type:d.Text,config:{text:L}}),t.refresh()},children:a.t("univer-watermark.cancel")}),s.jsxs("div",{className:o.watermarkPanelFooterButtonWrapper,children:[s.jsx(u.Button,{style:{marginRight:8},onClick:async()=>{const i=await t.getWatermarkConfig();let n;(i==null?void 0:i.type)===d.Text?n=i.config.text:(i==null?void 0:i.type)===d.Image&&(n=i.config.image),r.writeText(JSON.stringify(n))},children:a.t("univer-watermark.copy")}),s.jsx(u.Button,{onClick:async()=>{var n,l;const i=await t.getWatermarkConfig();((i==null?void 0:i.type)===d.Text&&!((n=i.config.text)!=null&&n.content)||(i==null?void 0:i.type)===d.Image&&!((l=i.config.image)!=null&&l.url))&&t.deleteWatermarkConfig(),e.close()},children:a.t("univer-watermark.close")})]})]})};function qe(e){return{id:H.id,title:"univer-watermark.title",tooltip:"univer-watermark.title",icon:K,type:N.MenuItemType.BUTTON,hidden$:Ge(e)}}function Ge(e){return e.get(c.IUniverInstanceService).focused$.pipe(R.switchMap(a=>a===c.DOCS_ZEN_EDITOR_UNIT_ID_KEY?R.of(!0):R.of(!1)))}const Ze={[N.RibbonStartGroup.OTHERS]:{[H.id]:{order:0,menuItemFactory:qe}}};var Je=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,et=(e,t,a,r)=>{for(var i=r>1?void 0:r?Qe(t,a):t,n=e.length-1,l;n>=0;n--)(l=e[n])&&(i=(r?l(t,a,i):l(i))||i);return r&&i&&Je(t,a,i),i},B=(e,t)=>(a,r)=>t(a,r,e);let M=class extends c.Disposable{constructor(e,t){super(),this._menuManagerService=e,this._componentManager=t,this._initMenu(),this._initComponents()}_initComponents(){[[K,ee],[V,Ve],[z,ze]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(Ze)}};M=et([B(0,N.IMenuManagerService),B(1,c.Inject(N.ComponentManager))],M);function tt(e,t,a,r){const i=t.type,n=t.config;i===d.UserInfo&&n.userInfo?rt(e,n.userInfo,r):i===d.Image&&n.image?nt(e,n.image,a):i===d.Text&&n.text&&at(e,n.text)}function rt(e,t,a){const{x:r,y:i,repeat:n,spacingX:l,spacingY:p,rotate:g,opacity:h,name:m,fontSize:f,color:k,bold:b,italic:W,direction:S}=t;if(!a)return;let _="";if(m&&(_+=`${a.name} `),!_)return;e.save(),e.globalAlpha=h,e.direction=S;let j="";if(W&&(j+="italic "),b&&(j+="bold "),j+=`${f}px Arial`,e.font=j,e.fillStyle=k,n){const y=e.canvas.width,C=e.canvas.height;for(let E=i;E<C;E+=f+p)for(let F=r;F<y;F+=e.measureText(_).width+l)e.save(),e.translate(F,E),e.rotate(Math.PI/180*g),e.fillText(_,0,0),e.restore()}else e.save(),e.translate(r,i),e.rotate(Math.PI/180*g),e.fillText(_,0,0),e.restore();e.restore()}function at(e,t){const{x:a,y:r,repeat:i,spacingX:n,spacingY:l,rotate:p,opacity:g,content:h,fontSize:m,color:f,bold:k,italic:b,direction:W}=t;e.save(),e.globalAlpha=g,e.direction=W;let S="";if(b&&(S+="italic "),k&&(S+="bold "),S+=`${m}px Arial`,e.font=S,e.fillStyle=f,h)if(i){const _=e.canvas.width,j=e.canvas.height;for(let y=r;y<j;y+=m+l)for(let C=a;C<_;C+=e.measureText(h).width+n)e.save(),e.translate(C,y),e.rotate(Math.PI/180*p),e.fillText(h,0,0),e.restore()}else e.save(),e.translate(a,r),e.rotate(Math.PI/180*p),e.fillText(h,0,0),e.restore();e.restore()}function nt(e,t,a){const{x:r,y:i,repeat:n,spacingX:l,spacingY:p,rotate:g,opacity:h,width:m,height:f,maintainAspectRatio:k,originRatio:b}=t;if(!(a!=null&&a.complete))return;e.save(),e.globalAlpha=h;const W=m,S=k?m/b:f;if(n){const _=e.canvas.width,j=e.canvas.height;for(let y=i;y<j;y+=S+p)for(let C=r;C<_;C+=W+l)e.save(),e.translate(C,y),e.rotate(Math.PI/180*g),e.drawImage(a,0,0,W,S),e.restore()}else e.save(),e.translate(r,i),e.rotate(Math.PI/180*g),e.drawImage(a,0,0,W,S),e.restore();e.restore()}class it extends X.Layer{constructor(){super(...arguments);x(this,"_config");x(this,"_image");x(this,"_user")}render(a,r=!1){var n;super.render(a,r);const i=a||((n=this.scene.getEngine())==null?void 0:n.getCanvas().getContext());return i&&i.getId()&&this._renderWatermark(i),this}updateConfig(a,r){var i;this._config=a,((i=this._config)==null?void 0:i.type)===d.Image&&this._config.config.image&&(this._image=new Image,this._image.src=this._config.config.image.url),r&&(this._user=r)}_renderWatermark(a){this._config&&tt(a,this._config,this._image,this._user)}}var st=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,lt=(e,t,a,r)=>{for(var i=r>1?void 0:r?ot(t,a):t,n=e.length-1,l;n>=0;n--)(l=e[n])&&(i=(r?l(t,a,i):l(i))||i);return r&&i&&st(t,a,i),i},A=(e,t)=>(a,r)=>t(a,r,e);let D=class extends c.RxDisposable{constructor(t,a,r,i){super();x(this,"_watermarkLayer");this._context=t,this._watermarkService=a,this._localStorageService=r,this._userManagerService=i,this._watermarkLayer=new it(t.scene,[],se),this._initAddRender(),this._initWatermarkUpdate(),this._initWatermarkConfig()}_initAddRender(){const{scene:t}=this._context;t.addLayer(this._watermarkLayer)}async _initWatermarkConfig(){var a;const t=await this._localStorageService.getItem(I);t&&(this._watermarkService.updateWatermarkConfig(t),(a=this._context.mainComponent)==null||a.makeDirty())}_initWatermarkUpdate(){this.disposeWithMe(this._watermarkService.updateConfig$.subscribe(t=>{var a,r;if(!t){this._watermarkLayer.updateConfig(),(a=this._context.mainComponent)==null||a.makeDirty();return}t.type===d.UserInfo?this._watermarkLayer.updateConfig(t,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(t),(r=this._context.mainComponent)==null||r.makeDirty()}))}};D=lt([A(1,c.Inject(exports.WatermarkService)),A(2,c.Inject(c.ILocalStorageService)),A(3,c.Inject(c.UserManagerService))],D);var ct=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,ut=(e,t,a,r)=>{for(var i=r>1?void 0:r?mt(t,a):t,n=e.length-1,l;n>=0;n--)(l=e[n])&&(i=(r?l(t,a,i):l(i))||i);return r&&i&&ct(t,a,i),i},T=(e,t)=>(a,r)=>t(a,r,e);const dt="UNIVER_WATERMARK_PLUGIN";var U;exports.UniverWatermarkPlugin=(U=class extends c.Plugin{constructor(t={},a,r,i,n,l){super(),this._config=t,this._injector=a,this._configService=r,this._commandService=i,this._renderManagerSrv=n,this._localStorageService=l;const{menu:p}=this._config;p&&this._configService.setConfig("menu",p,{merge:!0}),this._initWatermarkStorage(),this._initDependencies(),this._initRegisterCommand()}async _initWatermarkStorage(){const{menu:t,...a}=this._config;if(a.userWatermarkSettings)this._localStorageService.setItem(I,{type:d.UserInfo,config:{userInfo:{...q,...a.userWatermarkSettings}}});else if(a.textWatermarkSettings)this._localStorageService.setItem(I,{type:d.Text,config:{text:{...L,...a.textWatermarkSettings}}});else if(a.imageWatermarkSettings)this._localStorageService.setItem(I,{type:d.Image,config:{image:{...$,...a.imageWatermarkSettings}}});else{const r=await this._localStorageService.getItem(I);(r==null?void 0:r.type)===d.UserInfo&&this._localStorageService.removeItem(I)}}_initDependencies(){[[exports.WatermarkService],[M]].forEach(t=>{this._injector.add(t)})}_initRegisterCommand(){[H].forEach(t=>this._commandService.registerCommand(t))}onRendered(){const t=this._injector;t.get(exports.WatermarkService);const{userWatermarkSettings:a,textWatermarkSettings:r,imageWatermarkSettings:i,showMenu:n=!0}=this._config;!(a||r||i)&&n&&t.get(M),this._initRenderDependencies()}_initRenderDependencies(){[[D]].forEach(t=>{this._renderManagerSrv.registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,t),this._renderManagerSrv.registerRenderModule(c.UniverInstanceType.UNIVER_DOC,t)})}},x(U,"pluginName",dt),U);exports.UniverWatermarkPlugin=ut([T(1,c.Inject(c.Injector)),T(2,c.IConfigService),T(3,c.Inject(c.ICommandService)),T(4,X.IRenderManagerService),T(5,c.Inject(c.ILocalStorageService))],exports.UniverWatermarkPlugin);exports.IWatermarkTypeEnum=d;exports.WatermarkImageBaseConfig=$;exports.WatermarkTextBaseConfig=L;exports.WatermarkUserInfoBaseConfig=q;
|
|
1
|
+
"use strict";var $=Object.defineProperty;var L=(e,r,t)=>r in e?$(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var g=(e,r,t)=>L(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),P=require("@univerjs/engine-render"),M=require("rxjs"),f="UNIVER_WATERMARK_STORAGE_KEY",O=10,D=["image/png","image/jpeg","image/jpg","image/bmp"],T={content:"",fontSize:16,color:"rgb(0,0,0)",bold:!1,italic:!1,direction:"ltr",x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},U={url:"",width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},j={name:!0,email:!1,phone:!1,uid:!1,fontSize:16,color:"rgb(0,0,0)",bold:!1,italic:!1,direction:"ltr",x:60,y:60,repeat:!0,spacingX:200,spacingY:100,rotate:-30,opacity:.15};var c=(e=>(e.UserInfo="userInfo",e.Text="text",e.Image="image",e))(c||{}),Y=Object.defineProperty,N=Object.getOwnPropertyDescriptor,K=(e,r,t,a)=>{for(var i=a>1?void 0:a?N(r,t):r,n=e.length-1,s;n>=0;n--)(s=e[n])&&(i=(a?s(r,t,i):s(i))||i);return a&&i&&Y(r,t,i),i},X=(e,r)=>(t,a)=>r(t,a,e);exports.WatermarkService=class extends o.Disposable{constructor(t){super();g(this,"_updateConfig$",new M.Subject);g(this,"updateConfig$",this._updateConfig$.asObservable());g(this,"_refresh$",new M.Subject);g(this,"refresh$",this._refresh$.asObservable());this._localStorageService=t}async getWatermarkConfig(){return await this._localStorageService.getItem(f)}updateWatermarkConfig(t){this._localStorageService.setItem(f,t),this._updateConfig$.next(t)}deleteWatermarkConfig(){this._localStorageService.removeItem(f),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}};exports.WatermarkService=K([X(0,o.Inject(o.ILocalStorageService))],exports.WatermarkService);function G(e,r,t,a){const i=r.type,n=r.config;i===c.UserInfo&&n.userInfo?V(e,n.userInfo,a):i===c.Image&&n.image?H(e,n.image,t):i===c.Text&&n.text&&B(e,n.text)}function V(e,r,t){const{x:a,y:i,repeat:n,spacingX:s,spacingY:I,rotate:u,opacity:p,name:v,fontSize:W,color:y,bold:R,italic:S,direction:l}=r;if(!t)return;let _="";if(v&&(_+=`${t.name} `),!_)return;e.save(),e.globalAlpha=p,e.direction=l;let d="";if(S&&(d+="italic "),R&&(d+="bold "),d+=`${W}px Arial`,e.font=d,e.fillStyle=y,n){const h=e.canvas.width,m=e.canvas.height;for(let C=i;C<m;C+=W+I)for(let A=a;A<h;A+=e.measureText(_).width+s)e.save(),e.translate(A,C),e.rotate(Math.PI/180*u),e.fillText(_,0,0),e.restore()}else e.save(),e.translate(a,i),e.rotate(Math.PI/180*u),e.fillText(_,0,0),e.restore();e.restore()}function B(e,r){const{x:t,y:a,repeat:i,spacingX:n,spacingY:s,rotate:I,opacity:u,content:p,fontSize:v,color:W,bold:y,italic:R,direction:S}=r;e.save(),e.globalAlpha=u,e.direction=S;let l="";if(R&&(l+="italic "),y&&(l+="bold "),l+=`${v}px Arial`,e.font=l,e.fillStyle=W,p)if(i){const _=e.canvas.width,d=e.canvas.height;for(let h=a;h<d;h+=v+s)for(let m=t;m<_;m+=e.measureText(p).width+n)e.save(),e.translate(m,h),e.rotate(Math.PI/180*I),e.fillText(p,0,0),e.restore()}else e.save(),e.translate(t,a),e.rotate(Math.PI/180*I),e.fillText(p,0,0),e.restore();e.restore()}function H(e,r,t){const{x:a,y:i,repeat:n,spacingX:s,spacingY:I,rotate:u,opacity:p,width:v,height:W,maintainAspectRatio:y,originRatio:R}=r;if(!(t!=null&&t.complete))return;e.save(),e.globalAlpha=p;const S=v,l=y?v/R:W;if(n){const _=e.canvas.width,d=e.canvas.height;for(let h=i;h<d;h+=l+I)for(let m=a;m<_;m+=S+s)e.save(),e.translate(m,h),e.rotate(Math.PI/180*u),e.drawImage(t,0,0,S,l),e.restore()}else e.save(),e.translate(a,i),e.rotate(Math.PI/180*u),e.drawImage(t,0,0,S,l),e.restore();e.restore()}class z extends P.Layer{constructor(){super(...arguments);g(this,"_config");g(this,"_image");g(this,"_user")}render(t,a=!1){var n;super.render(t,a);const i=t||((n=this.scene.getEngine())==null?void 0:n.getCanvas().getContext());return i&&i.getId()&&this._renderWatermark(i),this}updateConfig(t,a){var i;this._config=t,((i=this._config)==null?void 0:i.type)===c.Image&&this._config.config.image&&(this._image=new Image,this._image.src=this._config.config.image.url),a&&(this._user=a)}_renderWatermark(t){this._config&&G(t,this._config,this._image,this._user)}}var q=Object.defineProperty,F=Object.getOwnPropertyDescriptor,J=(e,r,t,a)=>{for(var i=a>1?void 0:a?F(r,t):r,n=e.length-1,s;n>=0;n--)(s=e[n])&&(i=(a?s(r,t,i):s(i))||i);return a&&i&&q(r,t,i),i},w=(e,r)=>(t,a)=>r(t,a,e);let b=class extends o.RxDisposable{constructor(r,t,a,i){super();g(this,"_watermarkLayer");this._context=r,this._watermarkService=t,this._localStorageService=a,this._userManagerService=i,this._watermarkLayer=new z(r.scene,[],O),this._initAddRender(),this._initWatermarkUpdate(),this._initWatermarkConfig()}_initAddRender(){const{scene:r}=this._context;r.addLayer(this._watermarkLayer)}async _initWatermarkConfig(){var t;const r=await this._localStorageService.getItem(f);r&&(this._watermarkService.updateWatermarkConfig(r),(t=this._context.mainComponent)==null||t.makeDirty())}_initWatermarkUpdate(){this.disposeWithMe(this._watermarkService.updateConfig$.subscribe(r=>{var t,a;if(!r){this._watermarkLayer.updateConfig(),(t=this._context.mainComponent)==null||t.makeDirty();return}r.type===c.UserInfo?this._watermarkLayer.updateConfig(r,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(r),(a=this._context.mainComponent)==null||a.makeDirty()}))}};b=J([w(1,o.Inject(exports.WatermarkService)),w(2,o.Inject(o.ILocalStorageService)),w(3,o.Inject(o.UserManagerService))],b);var Q=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,x=(e,r,t,a)=>{for(var i=a>1?void 0:a?Z(r,t):r,n=e.length-1,s;n>=0;n--)(s=e[n])&&(i=(a?s(r,t,i):s(i))||i);return a&&i&&Q(r,t,i),i},k=(e,r)=>(t,a)=>r(t,a,e);const ee="UNIVER_WATERMARK_PLUGIN";var E;exports.UniverWatermarkPlugin=(E=class extends o.Plugin{constructor(r={},t,a,i,n){super(),this._config=r,this._injector=t,this._configService=a,this._renderManagerSrv=i,this._localStorageService=n;const{menu:s}=this._config;s&&this._configService.setConfig("menu",s,{merge:!0}),this._initWatermarkStorage(),this._initDependencies()}async _initWatermarkStorage(){const{menu:r,...t}=this._config;if(t.userWatermarkSettings)this._localStorageService.setItem(f,{type:c.UserInfo,config:{userInfo:{...j,...t.userWatermarkSettings}}});else if(t.textWatermarkSettings)this._localStorageService.setItem(f,{type:c.Text,config:{text:{...T,...t.textWatermarkSettings}}});else if(t.imageWatermarkSettings)this._localStorageService.setItem(f,{type:c.Image,config:{image:{...U,...t.imageWatermarkSettings}}});else{const a=await this._localStorageService.getItem(f);(a==null?void 0:a.type)===c.UserInfo&&this._localStorageService.removeItem(f)}}_initDependencies(){[[exports.WatermarkService]].forEach(r=>{this._injector.add(r)})}onRendered(){this._injector.get(exports.WatermarkService),this._initRenderDependencies()}_initRenderDependencies(){[[b]].forEach(r=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,r),this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,r)})}},g(E,"pluginName",ee),E);exports.UniverWatermarkPlugin=x([k(1,o.Inject(o.Injector)),k(2,o.IConfigService),k(3,P.IRenderManagerService),k(4,o.Inject(o.ILocalStorageService))],exports.UniverWatermarkPlugin);exports.IWatermarkTypeEnum=c;exports.UNIVER_WATERMARK_STORAGE_KEY=f;exports.WATERMARK_IMAGE_ALLOW_IMAGE_LIST=D;exports.WatermarkImageBaseConfig=U;exports.WatermarkTextBaseConfig=T;exports.WatermarkUserInfoBaseConfig=j;
|