@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
|
@@ -4,7 +4,6 @@ export declare const PLUGIN_CONFIG_KEY = "watermark.config";
|
|
|
4
4
|
export declare const configSymbol: unique symbol;
|
|
5
5
|
export interface IUniverWatermarkConfig {
|
|
6
6
|
menu?: MenuConfig;
|
|
7
|
-
showMenu?: boolean;
|
|
8
7
|
userWatermarkSettings?: Partial<IUserInfoWatermarkConfig>;
|
|
9
8
|
textWatermarkSettings?: Partial<ITextWatermarkConfig>;
|
|
10
9
|
imageWatermarkSettings?: Partial<IImageWatermarkConfig>;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export { UniverWatermarkPlugin } from './plugin';
|
|
17
|
-
export { WatermarkImageBaseConfig, WatermarkTextBaseConfig, WatermarkUserInfoBaseConfig } from './common/const';
|
|
17
|
+
export { UNIVER_WATERMARK_STORAGE_KEY, WATERMARK_IMAGE_ALLOW_IMAGE_LIST, WatermarkImageBaseConfig, WatermarkTextBaseConfig, WatermarkUserInfoBaseConfig } from './common/const';
|
|
18
18
|
export type { IImageWatermarkConfig, ITextWatermarkConfig } from './common/type';
|
|
19
19
|
export { IWatermarkTypeEnum } from './common/type';
|
|
20
20
|
export { WatermarkService } from './services/watermark.service';
|
|
21
|
+
export type { IWatermarkConfig, IWatermarkConfigWithType } from './common/type';
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { IUniverWatermarkConfig } from './controllers/config.schema';
|
|
2
|
-
import {
|
|
2
|
+
import { IConfigService, ILocalStorageService, Injector, Plugin } from '@univerjs/core';
|
|
3
3
|
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
4
4
|
export declare class UniverWatermarkPlugin extends Plugin {
|
|
5
5
|
private readonly _config;
|
|
6
6
|
protected _injector: Injector;
|
|
7
7
|
private readonly _configService;
|
|
8
|
-
private readonly _commandService;
|
|
9
8
|
private readonly _renderManagerSrv;
|
|
10
9
|
private readonly _localStorageService;
|
|
11
10
|
static pluginName: string;
|
|
12
|
-
constructor(_config: Partial<IUniverWatermarkConfig> | undefined, _injector: Injector, _configService: IConfigService,
|
|
11
|
+
constructor(_config: Partial<IUniverWatermarkConfig> | undefined, _injector: Injector, _configService: IConfigService, _renderManagerSrv: IRenderManagerService, _localStorageService: ILocalStorageService);
|
|
13
12
|
private _initWatermarkStorage;
|
|
14
13
|
private _initDependencies;
|
|
15
|
-
private _initRegisterCommand;
|
|
16
14
|
onRendered(): void;
|
|
17
15
|
private _initRenderDependencies;
|
|
18
16
|
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
(function(m,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("react"),require("@univerjs/design"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/ui","react","@univerjs/design","rxjs"],l):(m=typeof globalThis<"u"?globalThis:m||self,l(m.UniverWatermark={},m.UniverCore,m.UniverEngineRender,m.UniverUi,m.React,m.UniverDesign,m.rxjs))})(this,function(m,l,T,N,h,u,R){"use strict";var Ve=Object.defineProperty;var ze=(m,l,T)=>l in m?Ve(m,l,{enumerable:!0,configurable:!0,writable:!0,value:T}):m[l]=T;var _=(m,l,T)=>ze(m,typeof l!="symbol"?l+"":l,T);var Y;const K="UNIVER_WATERMARK_MENU",V="WATERMARK_PANEL",z="WATERMARK_PANEL_FOOTER",x="UNIVER_WATERMARK_STORAGE_KEY",ie=["image/png","image/jpeg","image/jpg","image/bmp"],P={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},A={url:"",width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},G={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},U={type:l.CommandType.OPERATION,id:"univer.operation.open-watermark-panel",handler(e){const t=e.get(N.ISidebarService),a=e.get(l.LocaleService);return t.open({header:{title:a.t("univer-watermark.title")},children:{label:V},footer:{label:z},onClose:()=>{},width:330}),!0}};var p=(e=>(e.UserInfo="userInfo",e.Text="text",e.Image="image",e))(p||{}),S=function(){return S=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},S.apply(this,arguments)},se=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},L=h.forwardRef(function(e,t){var a=e.icon,r=e.id,i=e.className,n=e.extend,c=se(e,["icon","id","className","extend"]),g="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),v=h.useRef("_".concat(ce()));return Z(a,"".concat(r),{defIds:a.defIds,idSuffix:v.current},S({ref:t,className:g},c),n)});function Z(e,t,a,r,i){return h.createElement(e.tag,S(S({key:t},oe(e,a,i)),r),(le(e,a).children||[]).map(function(n,c){return Z(n,"".concat(t,"-").concat(e.tag,"-").concat(c),a,void 0,i)}))}function oe(e,t,a){var r=S({},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 c=n[0],g=n[1];typeof g=="string"&&(r[c]=g.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),r}function le(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)?S(S({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.indexOf(i.attrs.id)>-1?S(S({},i),{attrs:S(S({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function ce(){return Math.random().toString(36).substring(2,8)}L.displayName="UniverIcon";var me={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"}}]},$=h.forwardRef(function(e,t){return h.createElement(L,Object.assign({},e,{id:"bold-single",ref:t,icon:me}))});$.displayName="BoldSingle";var ue={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=h.forwardRef(function(e,t){return h.createElement(L,Object.assign({},e,{id:"font-color",ref:t,icon:ue}))});J.displayName="FontColor";var de={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=h.forwardRef(function(e,t){return h.createElement(L,Object.assign({},e,{id:"italic-single",ref:t,icon:de}))});Q.displayName="ItalicSingle";var pe={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"}}]},q=h.forwardRef(function(e,t){return h.createElement(L,Object.assign({},e,{id:"watermark-single",ref:t,icon:pe}))});q.displayName="WatermarkSingle";var ee={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 ge=h,ve=Symbol.for("react.element"),he=Symbol.for("react.fragment"),fe=Object.prototype.hasOwnProperty,ke=ge.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,we={key:!0,ref:!0,__self:!0,__source:!0};function te(e,t,a){var r,i={},n=null,c=null;a!==void 0&&(n=""+a),t.key!==void 0&&(n=""+t.key),t.ref!==void 0&&(c=t.ref);for(r in t)fe.call(t,r)&&!we.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:ve,type:e,key:n,ref:c,props:i,_owner:ke.current}}O.Fragment=he,O.jsx=te,O.jsxs=te,ee.exports=O;var s=ee.exports,Se=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,Ie=(e,t,a,r)=>{for(var i=r>1?void 0:r?xe(t,a):t,n=e.length-1,c;n>=0;n--)(c=e[n])&&(i=(r?c(t,a,i):c(i))||i);return r&&i&&Se(t,a,i),i},_e=(e,t)=>(a,r)=>t(a,r,e);m.WatermarkService=class extends l.Disposable{constructor(a){super();_(this,"_updateConfig$",new R.Subject);_(this,"updateConfig$",this._updateConfig$.asObservable());_(this,"_refresh$",new R.Subject);_(this,"refresh$",this._refresh$.asObservable());this._localStorageService=a}async getWatermarkConfig(){return await this._localStorageService.getItem(x)}updateWatermarkConfig(a){this._localStorageService.setItem(x,a),this._updateConfig$.next(a)}deleteWatermarkConfig(){this._localStorageService.removeItem(x),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}},m.WatermarkService=Ie([_e(0,l.Inject(l.ILocalStorageService))],m.WatermarkService);const o={watermarkPanel:"univer-watermark-panel",watermarkPanelTypeTitle:"univer-watermark-panel-type-title",watermarkPanelTypeSelect:"univer-watermark-panel-type-select",watermarkPanelSetting:"univer-watermark-panel-setting",watermarkPanelFooter:"univer-watermark-panel-footer",watermarkPanelFooterButtonWrapper:"univer-watermark-panel-footer-button-wrapper",watermarkPanelFooterReset:"univer-watermark-panel-footer-reset",watermarkTextSetting:"univer-watermark-text-setting",watermarkTextSettingHeader:"univer-watermark-text-setting-header",watermarkTextSettingFontContent:"univer-watermark-text-setting-font-content",watermarkTextSettingFontStylePart:"univer-watermark-text-setting-font-style-part",watermarkTextSettingLayoutFontWrapper:"univer-watermark-text-setting-layout-font-wrapper",watermarkImageSetting:"univer-watermark-image-setting",watermarkInput:"univer-watermark-input",watermarkInputContent:"univer-watermark-input-content",watermarkIcon:"univer-watermark-icon",watermarkIconWrapper:"univer-watermark-icon-wrapper",watermarkIconWrapperSelect:"univer-watermark-icon-wrapper-select",watermarkColorPickerWrapper:"univer-watermark-color-picker-wrapper"},ye=({config:e,onChange:t})=>{const a=l.useDependency(N.ILocalFileService),r=l.useDependency(l.LocaleService);if(!e)return null;const i=async()=>{const n=await a.openFile({multiple:!1,accept:ie.map(f=>`.${f.replace("image/","")}`).join(",")});if(n.length===0)return!1;const g=n[0],v=new FileReader;v.onload=function(f){var d;if((d=f.target)!=null&&d.result){const k=f.target.result,w=new Image;w.onload=function(){t({...e,url:k,width:Math.max(20,w.width),height:Math.max(w.height,20),originRatio:w.width/w.height})},w.src=k}},v.readAsDataURL(g)};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 c=Math.max(20,Number.parseInt(n.toString()));e.maintainAspectRatio?t({...e,width:c,height:Math.round(c/e.originRatio)}):t({...e,width:c})}},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 c=Math.max(20,Number.parseInt(n.toString()));e.maintainAspectRatio?t({...e,height:c,width:Math.round(c*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 re(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=re(e[t]))&&(r&&(r+=" "),r+=a)}else for(a in e)e[a]&&(r&&(r+=" "),r+=a);return r}function ae(){for(var e,t,a=0,r="",i=arguments.length;a<i;a++)(e=arguments[a])&&(t=re(e))&&(r&&(r+=" "),r+=t);return r}const Ce=e=>{var i;const{config:t,onChange:a}=e,r=l.useDependency(l.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:ae(o.watermarkIconWrapper,{[o.watermarkIconWrapperSelect]:t.bold}),onClick:()=>{a({...t,bold:!t.bold})},children:s.jsx($,{className:o.watermarkIcon})}),s.jsx("div",{className:ae(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},je=()=>{const[e,t]=h.useState(p.Text),[a,r]=h.useState(),i=l.useDependency(m.WatermarkService),n=l.useDependency(l.ILocalStorageService),c=l.useObservable(i.refresh$),g=l.useDependency(l.LocaleService);function v(d,k){r(d),i.updateWatermarkConfig({type:k!=null?k:e,config:d})}const f=h.useCallback(async()=>{const d=await n.getItem(x);d?(t(d.type),r(d.config)):r({text:P})},[]);return h.useEffect(()=>{f()},[c,f]),s.jsxs("div",{className:o.watermarkPanel,children:[s.jsx("div",{className:o.watermarkPanelTypeTitle,children:g.t("univer-watermark.type")}),s.jsx(u.Select,{value:e,onChange:d=>{t(d),d===p.Text?v({text:P},p.Text):d===p.Image&&v({image:A},p.Image)},options:[{label:g.t("univer-watermark.text"),value:p.Text},{label:g.t("univer-watermark.image"),value:p.Image}],className:o.watermarkPanelTypeSelect}),s.jsxs("div",{className:o.watermarkPanelSetting,children:[e===p.Text&&s.jsx(Ce,{config:a==null?void 0:a.text,onChange:d=>v({text:d})}),e===p.Image&&s.jsx(ye,{config:a==null?void 0:a.image,onChange:d=>v({image:d})})]})]})},Ne=()=>{const e=l.useDependency(N.ISidebarService),t=l.useDependency(m.WatermarkService),a=l.useDependency(l.LocaleService),r=l.useDependency(N.IClipboardInterfaceService);return s.jsxs("div",{className:o.watermarkPanelFooter,children:[s.jsx("div",{className:o.watermarkPanelFooterReset,onClick:()=>{t.updateWatermarkConfig({type:p.Text,config:{text:P}}),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)===p.Text?n=i.config.text:(i==null?void 0:i.type)===p.Image&&(n=i.config.image),r.writeText(JSON.stringify(n))},children:a.t("univer-watermark.copy")}),s.jsx(u.Button,{onClick:async()=>{var n,c;const i=await t.getWatermarkConfig();((i==null?void 0:i.type)===p.Text&&!((n=i.config.text)!=null&&n.content)||(i==null?void 0:i.type)===p.Image&&!((c=i.config.image)!=null&&c.url))&&t.deleteWatermarkConfig(),e.close()},children:a.t("univer-watermark.close")})]})]})};function We(e){return{id:U.id,title:"univer-watermark.title",tooltip:"univer-watermark.title",icon:K,type:N.MenuItemType.BUTTON,hidden$:Te(e)}}function Te(e){return e.get(l.IUniverInstanceService).focused$.pipe(R.switchMap(a=>a===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY?R.of(!0):R.of(!1)))}const be={[N.RibbonStartGroup.OTHERS]:{[U.id]:{order:0,menuItemFactory:We}}};var Re=Object.defineProperty,Pe=Object.getOwnPropertyDescriptor,Le=(e,t,a,r)=>{for(var i=r>1?void 0:r?Pe(t,a):t,n=e.length-1,c;n>=0;n--)(c=e[n])&&(i=(r?c(t,a,i):c(i))||i);return r&&i&&Re(t,a,i),i},ne=(e,t)=>(a,r)=>t(a,r,e);let F=class extends l.Disposable{constructor(e,t){super(),this._menuManagerService=e,this._componentManager=t,this._initMenu(),this._initComponents()}_initComponents(){[[K,q],[V,je],[z,Ne]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(be)}};F=Le([ne(0,N.IMenuManagerService),ne(1,l.Inject(N.ComponentManager))],F);function Me(e,t,a,r){const i=t.type,n=t.config;i===p.UserInfo&&n.userInfo?Ee(e,n.userInfo,r):i===p.Image&&n.image?Fe(e,n.image,a):i===p.Text&&n.text&&Oe(e,n.text)}function Ee(e,t,a){const{x:r,y:i,repeat:n,spacingX:c,spacingY:g,rotate:v,opacity:f,name:d,fontSize:k,color:w,bold:E,italic:b,direction:I}=t;if(!a)return;let y="";if(d&&(y+=`${a.name} `),!y)return;e.save(),e.globalAlpha=f,e.direction=I;let W="";if(b&&(W+="italic "),E&&(W+="bold "),W+=`${k}px Arial`,e.font=W,e.fillStyle=w,n){const C=e.canvas.width,j=e.canvas.height;for(let B=i;B<j;B+=k+g)for(let X=r;X<C;X+=e.measureText(y).width+c)e.save(),e.translate(X,B),e.rotate(Math.PI/180*v),e.fillText(y,0,0),e.restore()}else e.save(),e.translate(r,i),e.rotate(Math.PI/180*v),e.fillText(y,0,0),e.restore();e.restore()}function Oe(e,t){const{x:a,y:r,repeat:i,spacingX:n,spacingY:c,rotate:g,opacity:v,content:f,fontSize:d,color:k,bold:w,italic:E,direction:b}=t;e.save(),e.globalAlpha=v,e.direction=b;let I="";if(E&&(I+="italic "),w&&(I+="bold "),I+=`${d}px Arial`,e.font=I,e.fillStyle=k,f)if(i){const y=e.canvas.width,W=e.canvas.height;for(let C=r;C<W;C+=d+c)for(let j=a;j<y;j+=e.measureText(f).width+n)e.save(),e.translate(j,C),e.rotate(Math.PI/180*g),e.fillText(f,0,0),e.restore()}else e.save(),e.translate(a,r),e.rotate(Math.PI/180*g),e.fillText(f,0,0),e.restore();e.restore()}function Fe(e,t,a){const{x:r,y:i,repeat:n,spacingX:c,spacingY:g,rotate:v,opacity:f,width:d,height:k,maintainAspectRatio:w,originRatio:E}=t;if(!(a!=null&&a.complete))return;e.save(),e.globalAlpha=f;const b=d,I=w?d/E:k;if(n){const y=e.canvas.width,W=e.canvas.height;for(let C=i;C<W;C+=I+g)for(let j=r;j<y;j+=b+c)e.save(),e.translate(j,C),e.rotate(Math.PI/180*v),e.drawImage(a,0,0,b,I),e.restore()}else e.save(),e.translate(r,i),e.rotate(Math.PI/180*v),e.drawImage(a,0,0,b,I),e.restore();e.restore()}class Ae extends T.Layer{constructor(){super(...arguments);_(this,"_config");_(this,"_image");_(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)===p.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&&Me(a,this._config,this._image,this._user)}}var Ue=Object.defineProperty,De=Object.getOwnPropertyDescriptor,He=(e,t,a,r)=>{for(var i=r>1?void 0:r?De(t,a):t,n=e.length-1,c;n>=0;n--)(c=e[n])&&(i=(r?c(t,a,i):c(i))||i);return r&&i&&Ue(t,a,i),i},D=(e,t)=>(a,r)=>t(a,r,e);let H=class extends l.RxDisposable{constructor(t,a,r,i){super();_(this,"_watermarkLayer");this._context=t,this._watermarkService=a,this._localStorageService=r,this._userManagerService=i,this._watermarkLayer=new Ae(t.scene,[],10),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(x);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===p.UserInfo?this._watermarkLayer.updateConfig(t,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(t),(r=this._context.mainComponent)==null||r.makeDirty()}))}};H=He([D(1,l.Inject(m.WatermarkService)),D(2,l.Inject(l.ILocalStorageService)),D(3,l.Inject(l.UserManagerService))],H);var Ye=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Xe=(e,t,a,r)=>{for(var i=r>1?void 0:r?Be(t,a):t,n=e.length-1,c;n>=0;n--)(c=e[n])&&(i=(r?c(t,a,i):c(i))||i);return r&&i&&Ye(t,a,i),i},M=(e,t)=>(a,r)=>t(a,r,e);const Ke="UNIVER_WATERMARK_PLUGIN";m.UniverWatermarkPlugin=(Y=class extends l.Plugin{constructor(t={},a,r,i,n,c){super(),this._config=t,this._injector=a,this._configService=r,this._commandService=i,this._renderManagerSrv=n,this._localStorageService=c;const{menu:g}=this._config;g&&this._configService.setConfig("menu",g,{merge:!0}),this._initWatermarkStorage(),this._initDependencies(),this._initRegisterCommand()}async _initWatermarkStorage(){const{menu:t,...a}=this._config;if(a.userWatermarkSettings)this._localStorageService.setItem(x,{type:p.UserInfo,config:{userInfo:{...G,...a.userWatermarkSettings}}});else if(a.textWatermarkSettings)this._localStorageService.setItem(x,{type:p.Text,config:{text:{...P,...a.textWatermarkSettings}}});else if(a.imageWatermarkSettings)this._localStorageService.setItem(x,{type:p.Image,config:{image:{...A,...a.imageWatermarkSettings}}});else{const r=await this._localStorageService.getItem(x);(r==null?void 0:r.type)===p.UserInfo&&this._localStorageService.removeItem(x)}}_initDependencies(){[[m.WatermarkService],[F]].forEach(t=>{this._injector.add(t)})}_initRegisterCommand(){[U].forEach(t=>this._commandService.registerCommand(t))}onRendered(){const t=this._injector;t.get(m.WatermarkService);const{userWatermarkSettings:a,textWatermarkSettings:r,imageWatermarkSettings:i,showMenu:n=!0}=this._config;!(a||r||i)&&n&&t.get(F),this._initRenderDependencies()}_initRenderDependencies(){[[H]].forEach(t=>{this._renderManagerSrv.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t),this._renderManagerSrv.registerRenderModule(l.UniverInstanceType.UNIVER_DOC,t)})}},_(Y,"pluginName",Ke),Y),m.UniverWatermarkPlugin=Xe([M(1,l.Inject(l.Injector)),M(2,l.IConfigService),M(3,l.Inject(l.ICommandService)),M(4,T.IRenderManagerService),M(5,l.Inject(l.ILocalStorageService))],m.UniverWatermarkPlugin),m.IWatermarkTypeEnum=p,m.WatermarkImageBaseConfig=A,m.WatermarkTextBaseConfig=P,m.WatermarkUserInfoBaseConfig=G,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(n,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs"],s):(n=typeof globalThis<"u"?globalThis:n||self,s(n.UniverWatermark={},n.UniverCore,n.UniverEngineRender,n.rxjs))})(this,function(n,s,S,T){"use strict";var x=Object.defineProperty;var ee=(n,s,S)=>s in n?x(n,s,{enumerable:!0,configurable:!0,writable:!0,value:S}):n[s]=S;var _=(n,s,S)=>ee(n,typeof s!="symbol"?s+"":s,S);var M;const g="UNIVER_WATERMARK_STORAGE_KEY",L=["image/png","image/jpeg","image/jpg","image/bmp"],P={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},b={url:"",width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},$={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 l=(e=>(e.UserInfo="userInfo",e.Text="text",e.Image="image",e))(l||{}),O=Object.defineProperty,D=Object.getOwnPropertyDescriptor,N=(e,r,t,a)=>{for(var i=a>1?void 0:a?D(r,t):r,o=e.length-1,f;o>=0;o--)(f=e[o])&&(i=(a?f(r,t,i):f(i))||i);return a&&i&&O(r,t,i),i},Y=(e,r)=>(t,a)=>r(t,a,e);n.WatermarkService=class extends s.Disposable{constructor(t){super();_(this,"_updateConfig$",new T.Subject);_(this,"updateConfig$",this._updateConfig$.asObservable());_(this,"_refresh$",new T.Subject);_(this,"refresh$",this._refresh$.asObservable());this._localStorageService=t}async getWatermarkConfig(){return await this._localStorageService.getItem(g)}updateWatermarkConfig(t){this._localStorageService.setItem(g,t),this._updateConfig$.next(t)}deleteWatermarkConfig(){this._localStorageService.removeItem(g),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}},n.WatermarkService=N([Y(0,s.Inject(s.ILocalStorageService))],n.WatermarkService);function K(e,r,t,a){const i=r.type,o=r.config;i===l.UserInfo&&o.userInfo?X(e,o.userInfo,a):i===l.Image&&o.image?V(e,o.image,t):i===l.Text&&o.text&&G(e,o.text)}function X(e,r,t){const{x:a,y:i,repeat:o,spacingX:f,spacingY:y,rotate:I,opacity:d,name:p,fontSize:R,color:k,bold:C,italic:W,direction:c}=r;if(!t)return;let h="";if(p&&(h+=`${t.name} `),!h)return;e.save(),e.globalAlpha=d,e.direction=c;let u="";if(W&&(u+="italic "),C&&(u+="bold "),u+=`${R}px Arial`,e.font=u,e.fillStyle=k,o){const m=e.canvas.width,v=e.canvas.height;for(let U=i;U<v;U+=R+y)for(let j=a;j<m;j+=e.measureText(h).width+f)e.save(),e.translate(j,U),e.rotate(Math.PI/180*I),e.fillText(h,0,0),e.restore()}else e.save(),e.translate(a,i),e.rotate(Math.PI/180*I),e.fillText(h,0,0),e.restore();e.restore()}function G(e,r){const{x:t,y:a,repeat:i,spacingX:o,spacingY:f,rotate:y,opacity:I,content:d,fontSize:p,color:R,bold:k,italic:C,direction:W}=r;e.save(),e.globalAlpha=I,e.direction=W;let c="";if(C&&(c+="italic "),k&&(c+="bold "),c+=`${p}px Arial`,e.font=c,e.fillStyle=R,d)if(i){const h=e.canvas.width,u=e.canvas.height;for(let m=a;m<u;m+=p+f)for(let v=t;v<h;v+=e.measureText(d).width+o)e.save(),e.translate(v,m),e.rotate(Math.PI/180*y),e.fillText(d,0,0),e.restore()}else e.save(),e.translate(t,a),e.rotate(Math.PI/180*y),e.fillText(d,0,0),e.restore();e.restore()}function V(e,r,t){const{x:a,y:i,repeat:o,spacingX:f,spacingY:y,rotate:I,opacity:d,width:p,height:R,maintainAspectRatio:k,originRatio:C}=r;if(!(t!=null&&t.complete))return;e.save(),e.globalAlpha=d;const W=p,c=k?p/C:R;if(o){const h=e.canvas.width,u=e.canvas.height;for(let m=i;m<u;m+=c+y)for(let v=a;v<h;v+=W+f)e.save(),e.translate(v,m),e.rotate(Math.PI/180*I),e.drawImage(t,0,0,W,c),e.restore()}else e.save(),e.translate(a,i),e.rotate(Math.PI/180*I),e.drawImage(t,0,0,W,c),e.restore();e.restore()}class B extends S.Layer{constructor(){super(...arguments);_(this,"_config");_(this,"_image");_(this,"_user")}render(t,a=!1){var o;super.render(t,a);const i=t||((o=this.scene.getEngine())==null?void 0:o.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)===l.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&&K(t,this._config,this._image,this._user)}}var H=Object.defineProperty,z=Object.getOwnPropertyDescriptor,q=(e,r,t,a)=>{for(var i=a>1?void 0:a?z(r,t):r,o=e.length-1,f;o>=0;o--)(f=e[o])&&(i=(a?f(r,t,i):f(i))||i);return a&&i&&H(r,t,i),i},E=(e,r)=>(t,a)=>r(t,a,e);let w=class extends s.RxDisposable{constructor(r,t,a,i){super();_(this,"_watermarkLayer");this._context=r,this._watermarkService=t,this._localStorageService=a,this._userManagerService=i,this._watermarkLayer=new B(r.scene,[],10),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(g);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===l.UserInfo?this._watermarkLayer.updateConfig(r,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(r),(a=this._context.mainComponent)==null||a.makeDirty()}))}};w=q([E(1,s.Inject(n.WatermarkService)),E(2,s.Inject(s.ILocalStorageService)),E(3,s.Inject(s.UserManagerService))],w);var F=Object.defineProperty,J=Object.getOwnPropertyDescriptor,Q=(e,r,t,a)=>{for(var i=a>1?void 0:a?J(r,t):r,o=e.length-1,f;o>=0;o--)(f=e[o])&&(i=(a?f(r,t,i):f(i))||i);return a&&i&&F(r,t,i),i},A=(e,r)=>(t,a)=>r(t,a,e);const Z="UNIVER_WATERMARK_PLUGIN";n.UniverWatermarkPlugin=(M=class extends s.Plugin{constructor(r={},t,a,i,o){super(),this._config=r,this._injector=t,this._configService=a,this._renderManagerSrv=i,this._localStorageService=o;const{menu:f}=this._config;f&&this._configService.setConfig("menu",f,{merge:!0}),this._initWatermarkStorage(),this._initDependencies()}async _initWatermarkStorage(){const{menu:r,...t}=this._config;if(t.userWatermarkSettings)this._localStorageService.setItem(g,{type:l.UserInfo,config:{userInfo:{...$,...t.userWatermarkSettings}}});else if(t.textWatermarkSettings)this._localStorageService.setItem(g,{type:l.Text,config:{text:{...P,...t.textWatermarkSettings}}});else if(t.imageWatermarkSettings)this._localStorageService.setItem(g,{type:l.Image,config:{image:{...b,...t.imageWatermarkSettings}}});else{const a=await this._localStorageService.getItem(g);(a==null?void 0:a.type)===l.UserInfo&&this._localStorageService.removeItem(g)}}_initDependencies(){[[n.WatermarkService]].forEach(r=>{this._injector.add(r)})}onRendered(){this._injector.get(n.WatermarkService),this._initRenderDependencies()}_initRenderDependencies(){[[w]].forEach(r=>{this._renderManagerSrv.registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,r),this._renderManagerSrv.registerRenderModule(s.UniverInstanceType.UNIVER_DOC,r)})}},_(M,"pluginName",Z),M),n.UniverWatermarkPlugin=Q([A(1,s.Inject(s.Injector)),A(2,s.IConfigService),A(3,S.IRenderManagerService),A(4,s.Inject(s.ILocalStorageService))],n.UniverWatermarkPlugin),n.IWatermarkTypeEnum=l,n.UNIVER_WATERMARK_STORAGE_KEY=g,n.WATERMARK_IMAGE_ALLOW_IMAGE_LIST=L,n.WatermarkImageBaseConfig=b,n.WatermarkTextBaseConfig=P,n.WatermarkUserInfoBaseConfig=$,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/watermark",
|
|
3
|
-
"version": "0.5.0-
|
|
3
|
+
"version": "0.5.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "univer watermark plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -61,20 +61,19 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@univerjs/icons": "^0.2.5",
|
|
63
63
|
"clsx": "^2.1.1",
|
|
64
|
-
"@univerjs/core": "0.5.0-
|
|
65
|
-
"@univerjs/design": "0.5.0-
|
|
66
|
-
"@univerjs/engine-render": "0.5.0-
|
|
67
|
-
"@univerjs/ui": "0.5.0-
|
|
64
|
+
"@univerjs/core": "0.5.0-beta.1",
|
|
65
|
+
"@univerjs/design": "0.5.0-beta.1",
|
|
66
|
+
"@univerjs/engine-render": "0.5.0-beta.1",
|
|
67
|
+
"@univerjs/ui": "0.5.0-beta.1"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@types/react": "^18.3.12",
|
|
71
70
|
"less": "^4.2.0",
|
|
72
71
|
"react": "18.3.1",
|
|
73
72
|
"rxjs": "^7.8.1",
|
|
74
73
|
"typescript": "^5.6.3",
|
|
75
|
-
"vite": "^5.4.
|
|
76
|
-
"vitest": "^2.1.
|
|
77
|
-
"@univerjs-infra/shared": "0.5.0-
|
|
74
|
+
"vite": "^5.4.11",
|
|
75
|
+
"vitest": "^2.1.5",
|
|
76
|
+
"@univerjs-infra/shared": "0.5.0-beta.1"
|
|
78
77
|
},
|
|
79
78
|
"space": {
|
|
80
79
|
".": {
|
|
@@ -104,7 +103,7 @@
|
|
|
104
103
|
"test:watch": "vitest",
|
|
105
104
|
"coverage": "vitest run --coverage",
|
|
106
105
|
"lint:types": "tsc --noEmit",
|
|
107
|
-
"build": "
|
|
106
|
+
"build": "univer-cli build"
|
|
108
107
|
},
|
|
109
108
|
"module": "./lib/es/index.js"
|
|
110
109
|
}
|
package/lib/index.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.univer-watermark-panel{margin:16px 0}.univer-watermark-panel-type-title{font-size:15px;color:rgb(var(--text-color-secondary))}.univer-watermark-panel-type-select{width:100%;margin-top:16px}.univer-watermark-panel-setting{width:100%;min-height:100px;border-radius:8px}.univer-watermark-panel-footer{display:flex;justify-content:space-between;align-items:center;font-size:12px}.univer-watermark-panel-footer-button-wrapper{display:flex;align-items:center}.univer-watermark-panel-footer-reset{cursor:pointer;white-space:nowrap;color:rgb(var(--primary-color));border-bottom:1px solid rgb(var(--primary-color))}.univer-watermark-text-setting{font-size:14px}.univer-watermark-text-setting-header{font-size:15px;color:rgb(var(--text-color-secondary));margin:16px 0}.univer-watermark-text-setting-font-content{display:flex;justify-content:space-between;align-items:center;margin-bottom:16px}.univer-watermark-text-setting-font-style-part{display:flex;justify-content:space-between;align-items:center;margin-top:16px}.univer-watermark-text-setting-font-style-part:first-child{margin-top:0}.univer-watermark-text-setting-layout-font-wrapper{width:calc(50% - 8px);align-self:flex-start;white-space:nowrap}.univer-watermark-image-setting{font-size:14px}.univer-watermark-input{height:28px;box-sizing:border-box}.univer-watermark-input-content{width:220px}.univer-watermark-icon{width:18px;height:18px;margin:2px}.univer-watermark-icon-wrapper{cursor:pointer;border-radius:4px;width:24px;height:24px}.univer-watermark-icon-wrapper-select,.univer-watermark-icon-wrapper:hover{background-color:rgb(var(--grey-100))}.univer-watermark-icon-wrapper:first-child{margin-left:28px}.univer-watermark-icon-wrapper:last-child{margin-right:28px}.univer-watermark-color-picker-wrapper{padding:16px;border-radius:8px;background-color:#fff;border:1px solid rgb(var(--grey-100))}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Disposable } from '@univerjs/core';
|
|
2
|
-
import { ComponentManager, IMenuManagerService } from '@univerjs/ui';
|
|
3
|
-
export declare class UniverWatermarkMenuController extends Disposable {
|
|
4
|
-
protected readonly _menuManagerService: IMenuManagerService;
|
|
5
|
-
private readonly _componentManager;
|
|
6
|
-
constructor(_menuManagerService: IMenuManagerService, _componentManager: ComponentManager);
|
|
7
|
-
private _initComponents;
|
|
8
|
-
private _initMenu;
|
|
9
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { IImageWatermarkConfig } from '../../common/type';
|
|
2
|
-
import { default as React } from 'react';
|
|
3
|
-
interface IWatermarkImageSettingProps {
|
|
4
|
-
config?: IImageWatermarkConfig;
|
|
5
|
-
onChange: (config: IImageWatermarkConfig) => void;
|
|
6
|
-
}
|
|
7
|
-
export declare const WatermarkImageSetting: React.FC<IWatermarkImageSettingProps>;
|
|
8
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ITextWatermarkConfig } from '../../common/type';
|
|
2
|
-
import { default as React } from 'react';
|
|
3
|
-
interface IWatermarkTextSettingProps {
|
|
4
|
-
config?: ITextWatermarkConfig;
|
|
5
|
-
onChange: (config: ITextWatermarkConfig) => void;
|
|
6
|
-
}
|
|
7
|
-
export declare const WatermarkTextSetting: React.FC<IWatermarkTextSettingProps>;
|
|
8
|
-
export {};
|