@pdfme/ui 3.1.5 → 3.2.0-dev.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.
@@ -1,214 +1 @@
1
- function F(n, a, r) {
2
- if (r || arguments.length === 2)
3
- for (var t = 0, o = a.length, l; t < o; t++)
4
- (l || !(t in a)) && (l || (l = Array.prototype.slice.call(a, 0, t)), l[t] = a[t]);
5
- return n.concat(l || Array.prototype.slice.call(a));
6
- }
7
- var q = {
8
- a: 7,
9
- c: 6,
10
- h: 1,
11
- l: 2,
12
- m: 2,
13
- q: 4,
14
- s: 4,
15
- t: 2,
16
- v: 1,
17
- z: 0
18
- }, Z = /([astvzqmhlc])([^astvzqmhlc]*)/gi, _ = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
19
- function U(n) {
20
- var a = n.match(_);
21
- return a ? a.map(Number) : [];
22
- }
23
- function j(n) {
24
- var a = [], r = String(n).trim();
25
- return r[0] !== "M" && r[0] !== "m" || r.replace(Z, function(t, o, l) {
26
- var s = U(l), u = o.toLowerCase(), h = o;
27
- if (u === "m" && s.length > 2 && (a.push(F([h], s.splice(0, 2), !0)), u = "l", h = h === "m" ? "l" : "L"), s.length < q[u])
28
- return "";
29
- for (a.push(F([h], s.splice(0, q[u]), !0)); s.length >= q[u] && s.length && q[u]; )
30
- a.push(F([h], s.splice(0, q[u]), !0));
31
- return "";
32
- }), a;
33
- }
34
- function B(n, a) {
35
- var r = n.x * Math.cos(a) - n.y * Math.sin(a), t = n.y * Math.cos(a) + n.x * Math.sin(a);
36
- n.x = r, n.y = t;
37
- }
38
- function J(n, a, r) {
39
- n.x += a, n.y += r;
40
- }
41
- function H(n, a) {
42
- n.x *= a, n.y *= a;
43
- }
44
- var L = (
45
- /** @class */
46
- function() {
47
- function n(a) {
48
- var r;
49
- this.commands = [], a && a instanceof n ? (r = this.commands).push.apply(r, a.commands) : a && (this.commands = j(a));
50
- }
51
- return n.prototype.addPath = function(a) {
52
- var r;
53
- a && a instanceof n && (r = this.commands).push.apply(r, a.commands);
54
- }, n.prototype.moveTo = function(a, r) {
55
- this.commands.push(["M", a, r]);
56
- }, n.prototype.lineTo = function(a, r) {
57
- this.commands.push(["L", a, r]);
58
- }, n.prototype.arc = function(a, r, t, o, l, s) {
59
- this.commands.push(["AC", a, r, t, o, l, !!s]);
60
- }, n.prototype.arcTo = function(a, r, t, o, l) {
61
- this.commands.push(["AT", a, r, t, o, l]);
62
- }, n.prototype.ellipse = function(a, r, t, o, l, s, u, h) {
63
- this.commands.push(["E", a, r, t, o, l, s, u, !!h]);
64
- }, n.prototype.closePath = function() {
65
- this.commands.push(["Z"]);
66
- }, n.prototype.bezierCurveTo = function(a, r, t, o, l, s) {
67
- this.commands.push(["C", a, r, t, o, l, s]);
68
- }, n.prototype.quadraticCurveTo = function(a, r, t, o) {
69
- this.commands.push(["Q", a, r, t, o]);
70
- }, n.prototype.rect = function(a, r, t, o) {
71
- this.commands.push(["R", a, r, t, o]);
72
- }, n.prototype.roundRect = function(a, r, t, o, l) {
73
- typeof l > "u" ? this.commands.push(["RR", a, r, t, o, 0]) : this.commands.push(["RR", a, r, t, o, l]);
74
- }, n;
75
- }()
76
- );
77
- function N(n, a) {
78
- var r = 0, t = 0, o, l, s, u, h, v, P, C, I, A, S, G, D, p, f, z, d, b, m, E, Q, g = null, R = null, y = null, T = null, M = null, k = null;
79
- n.beginPath();
80
- for (var i = 0; i < a.length; ++i) {
81
- b = a[i][0], b !== "S" && b !== "s" && b !== "C" && b !== "c" && (g = null, R = null), b !== "T" && b !== "t" && b !== "Q" && b !== "q" && (y = null, T = null);
82
- var e = void 0;
83
- switch (b) {
84
- case "m":
85
- case "M":
86
- e = a[i], b === "m" ? (r += e[1], t += e[2]) : (r = e[1], t = e[2]), (b === "M" || !M) && (M = { x: r, y: t }), n.moveTo(r, t);
87
- break;
88
- case "l":
89
- e = a[i], r += e[1], t += e[2], n.lineTo(r, t);
90
- break;
91
- case "L":
92
- e = a[i], r = e[1], t = e[2], n.lineTo(r, t);
93
- break;
94
- case "H":
95
- e = a[i], r = e[1], n.lineTo(r, t);
96
- break;
97
- case "h":
98
- e = a[i], r += e[1], n.lineTo(r, t);
99
- break;
100
- case "V":
101
- e = a[i], t = e[1], n.lineTo(r, t);
102
- break;
103
- case "v":
104
- e = a[i], t += e[1], n.lineTo(r, t);
105
- break;
106
- case "a":
107
- case "A":
108
- if (e = a[i], k === null)
109
- throw new Error("This should never happen");
110
- b === "a" ? (r += e[6], t += e[7]) : (r = e[6], t = e[7]), p = e[1], f = e[2], P = e[3] * Math.PI / 180, s = !!e[4], u = !!e[5], h = { x: r, y: t }, v = {
111
- x: (k.x - h.x) / 2,
112
- y: (k.y - h.y) / 2
113
- }, B(v, -P), C = v.x * v.x / (p * p) + v.y * v.y / (f * f), C > 1 && (C = Math.sqrt(C), p *= C, f *= C), m = {
114
- x: p * v.y / f,
115
- y: -(f * v.x) / p
116
- }, I = p * p * f * f, A = p * p * v.y * v.y + f * f * v.x * v.x, u !== s ? H(m, Math.sqrt((I - A) / A) || 0) : H(m, -Math.sqrt((I - A) / A) || 0), l = Math.atan2((v.y - m.y) / f, (v.x - m.x) / p), o = Math.atan2(-(v.y + m.y) / f, -(v.x + m.x) / p), B(m, P), J(m, (h.x + k.x) / 2, (h.y + k.y) / 2), n.save(), n.translate(m.x, m.y), n.rotate(P), n.scale(p, f), n.arc(0, 0, 1, l, o, !u), n.restore();
117
- break;
118
- case "C":
119
- e = a[i], g = e[3], R = e[4], r = e[5], t = e[6], n.bezierCurveTo(e[1], e[2], g, R, r, t);
120
- break;
121
- case "c":
122
- e = a[i], n.bezierCurveTo(e[1] + r, e[2] + t, e[3] + r, e[4] + t, e[5] + r, e[6] + t), g = e[3] + r, R = e[4] + t, r += e[5], t += e[6];
123
- break;
124
- case "S":
125
- e = a[i], (g === null || R === null) && (g = r, R = t), n.bezierCurveTo(2 * r - g, 2 * t - R, e[1], e[2], e[3], e[4]), g = e[1], R = e[2], r = e[3], t = e[4];
126
- break;
127
- case "s":
128
- e = a[i], (g === null || R === null) && (g = r, R = t), n.bezierCurveTo(2 * r - g, 2 * t - R, e[1] + r, e[2] + t, e[3] + r, e[4] + t), g = e[1] + r, R = e[2] + t, r += e[3], t += e[4];
129
- break;
130
- case "Q":
131
- e = a[i], y = e[1], T = e[2], r = e[3], t = e[4], n.quadraticCurveTo(y, T, r, t);
132
- break;
133
- case "q":
134
- e = a[i], y = e[1] + r, T = e[2] + t, r += e[3], t += e[4], n.quadraticCurveTo(y, T, r, t);
135
- break;
136
- case "T":
137
- e = a[i], (y === null || T === null) && (y = r, T = t), y = 2 * r - y, T = 2 * t - T, r = e[1], t = e[2], n.quadraticCurveTo(y, T, r, t);
138
- break;
139
- case "t":
140
- e = a[i], (y === null || T === null) && (y = r, T = t), y = 2 * r - y, T = 2 * t - T, r += e[1], t += e[2], n.quadraticCurveTo(y, T, r, t);
141
- break;
142
- case "z":
143
- case "Z":
144
- M && (r = M.x, t = M.y), M = null, n.closePath();
145
- break;
146
- case "AC":
147
- e = a[i], r = e[1], t = e[2], D = e[3], l = e[4], o = e[5], E = e[6], n.arc(r, t, D, l, o, E);
148
- break;
149
- case "AT":
150
- e = a[i], S = e[1], G = e[2], r = e[3], t = e[4], D = e[5], n.arcTo(S, G, r, t, D);
151
- break;
152
- case "E":
153
- e = a[i], r = e[1], t = e[2], p = e[3], f = e[4], P = e[5], l = e[6], o = e[7], E = e[8], n.save(), n.translate(r, t), n.rotate(P), n.scale(p, f), n.arc(0, 0, 1, l, o, E), n.restore();
154
- break;
155
- case "R":
156
- e = a[i], r = e[1], t = e[2], z = e[3], d = e[4], M = { x: r, y: t }, n.rect(r, t, z, d);
157
- break;
158
- case "RR":
159
- e = a[i], r = e[1], t = e[2], z = e[3], d = e[4], Q = e[5], M = { x: r, y: t }, n.roundRect(r, t, z, d, Q);
160
- break;
161
- }
162
- k ? (k.x = r, k.y = t) : k = { x: r, y: t };
163
- }
164
- }
165
- function K(n) {
166
- if (!(!n || !n.CanvasRenderingContext2D || n.Path2D)) {
167
- var a = n.CanvasRenderingContext2D, r = a.prototype.fill, t = a.prototype.stroke, o = a.prototype.isPointInPath;
168
- a.prototype.fill = function() {
169
- for (var s = [], u = 0; u < arguments.length; u++)
170
- s[u] = arguments[u];
171
- if (s[0] instanceof L) {
172
- var h = s[0], v = s[1] || "nonzero";
173
- N(this, h.commands), r.apply(this, [v]);
174
- } else {
175
- var v = s[0] || "nonzero";
176
- return r.apply(this, [v]);
177
- }
178
- }, a.prototype.stroke = function(s) {
179
- s && N(this, s.commands), t.apply(this);
180
- }, a.prototype.isPointInPath = function() {
181
- for (var s = [], u = 0; u < arguments.length; u++)
182
- s[u] = arguments[u];
183
- if (s[0] instanceof L) {
184
- var h = s[0], v = s[1], P = s[2], C = s[3] || "nonzero";
185
- return N(this, h.commands), o.apply(this, [v, P, C]);
186
- } else
187
- return o.apply(this, s);
188
- }, n.Path2D = L;
189
- }
190
- }
191
- function V(n, a, r, t, o) {
192
- var l = this;
193
- if (o === void 0 && (o = 0), typeof o == "number" && (o = [o]), Array.isArray(o)) {
194
- if (o.length === 0 || o.length > 4)
195
- throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name, "': ").concat(o.length, " radii provided. Between one and four radii are necessary."));
196
- o.forEach(function(C) {
197
- if (C < 0)
198
- throw new RangeError("Failed to execute 'roundRect' on '".concat(l.constructor.name, "': Radius value ").concat(C, " is negative."));
199
- });
200
- } else
201
- return;
202
- if (o.length === 1 && o[0] === 0)
203
- return this.rect(n, a, r, t);
204
- var s = Math.min(r, t) / 2, u, h, v, P = u = h = v = Math.min(s, o[0]);
205
- o.length === 2 && (u = v = Math.min(s, o[1])), o.length === 3 && (u = v = Math.min(s, o[1]), h = Math.min(s, o[2])), o.length === 4 && (u = Math.min(s, o[1]), h = Math.min(s, o[2]), v = Math.min(s, o[3])), this.moveTo(n, a + t - v), this.arcTo(n, a, n + P, a, P), this.arcTo(n + r, a, n + r, a + u, u), this.arcTo(n + r, a + t, n + r - h, a + t, h), this.arcTo(n, a + t, n, a + t - v, v), this.moveTo(n, a);
206
- }
207
- function O(n) {
208
- if (!(!n || !n.CanvasRenderingContext2D)) {
209
- var a = n.CanvasRenderingContext2D, r = n.Path2D;
210
- a && !a.prototype.roundRect && (a.prototype.roundRect = V), r && !r.prototype.roundRect && (r.prototype.roundRect = V);
211
- }
212
- }
213
- K(window);
214
- O(window);
1
+ function D(a,o,r){if(r||arguments.length===2)for(var n=0,s=o.length,c;n<s;n++)(c||!(n in o))&&(c||(c=Array.prototype.slice.call(o,0,n)),c[n]=o[n]);return a.concat(c||Array.prototype.slice.call(o))}var M={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},H=/([astvzqmhlc])([^astvzqmhlc]*)/gi,N=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function V(a){var o=a.match(N);return o?o.map(Number):[]}function j(a){var o=[],r=String(a).trim();return r[0]!=="M"&&r[0]!=="m"||r.replace(H,function(n,s,c){var e=V(c),h=s.toLowerCase(),u=s;if(h==="m"&&e.length>2&&(o.push(D([u],e.splice(0,2),!0)),h="l",u=u==="m"?"l":"L"),e.length<M[h])return"";for(o.push(D([u],e.splice(0,M[h]),!0));e.length>=M[h]&&e.length&&M[h];)o.push(D([u],e.splice(0,M[h]),!0));return""}),o}function F(a,o){var r=a.x*Math.cos(o)-a.y*Math.sin(o),n=a.y*Math.cos(o)+a.x*Math.sin(o);a.x=r,a.y=n}function G(a,o,r){a.x+=o,a.y+=r}function Z(a,o){a.x*=o,a.y*=o}var E=function(){function a(o){var r;this.commands=[],o&&o instanceof a?(r=this.commands).push.apply(r,o.commands):o&&(this.commands=j(o))}return a.prototype.addPath=function(o){var r;o&&o instanceof a&&(r=this.commands).push.apply(r,o.commands)},a.prototype.moveTo=function(o,r){this.commands.push(["M",o,r])},a.prototype.lineTo=function(o,r){this.commands.push(["L",o,r])},a.prototype.arc=function(o,r,n,s,c,e){this.commands.push(["AC",o,r,n,s,c,!!e])},a.prototype.arcTo=function(o,r,n,s,c){this.commands.push(["AT",o,r,n,s,c])},a.prototype.ellipse=function(o,r,n,s,c,e,h,u){this.commands.push(["E",o,r,n,s,c,e,h,!!u])},a.prototype.closePath=function(){this.commands.push(["Z"])},a.prototype.bezierCurveTo=function(o,r,n,s,c,e){this.commands.push(["C",o,r,n,s,c,e])},a.prototype.quadraticCurveTo=function(o,r,n,s){this.commands.push(["Q",o,r,n,s])},a.prototype.rect=function(o,r,n,s){this.commands.push(["R",o,r,n,s])},a.prototype.roundRect=function(o,r,n,s,c){typeof c>"u"?this.commands.push(["RR",o,r,n,s,0]):this.commands.push(["RR",o,r,n,s,c])},a}();function L(a,o){var r=0,n=0,s,c,e,h,u,i,g,b,A,R,I,Q,q,p,m,P,w,d,T,z,S,v=null,x=null,y=null,f=null,C=null,k=null;a.beginPath();for(var l=0;l<o.length;++l){d=o[l][0],d!=="S"&&d!=="s"&&d!=="C"&&d!=="c"&&(v=null,x=null),d!=="T"&&d!=="t"&&d!=="Q"&&d!=="q"&&(y=null,f=null);var t=void 0;switch(d){case"m":case"M":t=o[l],d==="m"?(r+=t[1],n+=t[2]):(r=t[1],n=t[2]),(d==="M"||!C)&&(C={x:r,y:n}),a.moveTo(r,n);break;case"l":t=o[l],r+=t[1],n+=t[2],a.lineTo(r,n);break;case"L":t=o[l],r=t[1],n=t[2],a.lineTo(r,n);break;case"H":t=o[l],r=t[1],a.lineTo(r,n);break;case"h":t=o[l],r+=t[1],a.lineTo(r,n);break;case"V":t=o[l],n=t[1],a.lineTo(r,n);break;case"v":t=o[l],n+=t[1],a.lineTo(r,n);break;case"a":case"A":if(t=o[l],k===null)throw new Error("This should never happen");d==="a"?(r+=t[6],n+=t[7]):(r=t[6],n=t[7]),p=t[1],m=t[2],g=t[3]*Math.PI/180,e=!!t[4],h=!!t[5],u={x:r,y:n},i={x:(k.x-u.x)/2,y:(k.y-u.y)/2},F(i,-g),b=i.x*i.x/(p*p)+i.y*i.y/(m*m),b>1&&(b=Math.sqrt(b),p*=b,m*=b),T={x:p*i.y/m,y:-(m*i.x)/p},A=p*p*m*m,R=p*p*i.y*i.y+m*m*i.x*i.x,h!==e?Z(T,Math.sqrt((A-R)/R)||0):Z(T,-Math.sqrt((A-R)/R)||0),c=Math.atan2((i.y-T.y)/m,(i.x-T.x)/p),s=Math.atan2(-(i.y+T.y)/m,-(i.x+T.x)/p),F(T,g),G(T,(u.x+k.x)/2,(u.y+k.y)/2),a.save(),a.translate(T.x,T.y),a.rotate(g),a.scale(p,m),a.arc(0,0,1,c,s,!h),a.restore();break;case"C":t=o[l],v=t[3],x=t[4],r=t[5],n=t[6],a.bezierCurveTo(t[1],t[2],v,x,r,n);break;case"c":t=o[l],a.bezierCurveTo(t[1]+r,t[2]+n,t[3]+r,t[4]+n,t[5]+r,t[6]+n),v=t[3]+r,x=t[4]+n,r+=t[5],n+=t[6];break;case"S":t=o[l],(v===null||x===null)&&(v=r,x=n),a.bezierCurveTo(2*r-v,2*n-x,t[1],t[2],t[3],t[4]),v=t[1],x=t[2],r=t[3],n=t[4];break;case"s":t=o[l],(v===null||x===null)&&(v=r,x=n),a.bezierCurveTo(2*r-v,2*n-x,t[1]+r,t[2]+n,t[3]+r,t[4]+n),v=t[1]+r,x=t[2]+n,r+=t[3],n+=t[4];break;case"Q":t=o[l],y=t[1],f=t[2],r=t[3],n=t[4],a.quadraticCurveTo(y,f,r,n);break;case"q":t=o[l],y=t[1]+r,f=t[2]+n,r+=t[3],n+=t[4],a.quadraticCurveTo(y,f,r,n);break;case"T":t=o[l],(y===null||f===null)&&(y=r,f=n),y=2*r-y,f=2*n-f,r=t[1],n=t[2],a.quadraticCurveTo(y,f,r,n);break;case"t":t=o[l],(y===null||f===null)&&(y=r,f=n),y=2*r-y,f=2*n-f,r+=t[1],n+=t[2],a.quadraticCurveTo(y,f,r,n);break;case"z":case"Z":C&&(r=C.x,n=C.y),C=null,a.closePath();break;case"AC":t=o[l],r=t[1],n=t[2],q=t[3],c=t[4],s=t[5],z=t[6],a.arc(r,n,q,c,s,z);break;case"AT":t=o[l],I=t[1],Q=t[2],r=t[3],n=t[4],q=t[5],a.arcTo(I,Q,r,n,q);break;case"E":t=o[l],r=t[1],n=t[2],p=t[3],m=t[4],g=t[5],c=t[6],s=t[7],z=t[8],a.save(),a.translate(r,n),a.rotate(g),a.scale(p,m),a.arc(0,0,1,c,s,z),a.restore();break;case"R":t=o[l],r=t[1],n=t[2],P=t[3],w=t[4],C={x:r,y:n},a.rect(r,n,P,w);break;case"RR":t=o[l],r=t[1],n=t[2],P=t[3],w=t[4],S=t[5],C={x:r,y:n},a.roundRect(r,n,P,w,S);break}k?(k.x=r,k.y=n):k={x:r,y:n}}}function J(a){if(!(!a||!a.CanvasRenderingContext2D||a.Path2D)){var o=a.CanvasRenderingContext2D,r=o.prototype.fill,n=o.prototype.stroke,s=o.prototype.isPointInPath;o.prototype.fill=function(){for(var c=[],e=0;e<arguments.length;e++)c[e]=arguments[e];if(c[0]instanceof E){var h=c[0],u=c[1]||"nonzero";L(this,h.commands),r.apply(this,[u])}else{var u=c[0]||"nonzero";return r.apply(this,[u])}},o.prototype.stroke=function(c){c&&L(this,c.commands),n.apply(this)},o.prototype.isPointInPath=function(){for(var c=[],e=0;e<arguments.length;e++)c[e]=arguments[e];if(c[0]instanceof E){var h=c[0],u=c[1],i=c[2],g=c[3]||"nonzero";return L(this,h.commands),s.apply(this,[u,i,g])}else return s.apply(this,c)},a.Path2D=E}}function B(a,o,r,n,s){var c=this;if(s===void 0&&(s=0),typeof s=="number"&&(s=[s]),Array.isArray(s)){if(s.length===0||s.length>4)throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name,"': ").concat(s.length," radii provided. Between one and four radii are necessary."));s.forEach(function(b){if(b<0)throw new RangeError("Failed to execute 'roundRect' on '".concat(c.constructor.name,"': Radius value ").concat(b," is negative."))})}else return;if(s.length===1&&s[0]===0)return this.rect(a,o,r,n);var e=Math.min(r,n)/2,h,u,i,g=h=u=i=Math.min(e,s[0]);s.length===2&&(h=i=Math.min(e,s[1])),s.length===3&&(h=i=Math.min(e,s[1]),u=Math.min(e,s[2])),s.length===4&&(h=Math.min(e,s[1]),u=Math.min(e,s[2]),i=Math.min(e,s[3])),this.moveTo(a,o+n-i),this.arcTo(a,o,a+g,o,g),this.arcTo(a+r,o,a+r,o+h,h),this.arcTo(a+r,o+n,a+r-u,o+n,u),this.arcTo(a,o+n,a,o+n-i,i),this.moveTo(a,o)}function K(a){if(!(!a||!a.CanvasRenderingContext2D)){var o=a.CanvasRenderingContext2D,r=a.Path2D;o&&!o.prototype.roundRect&&(o.prototype.roundRect=B),r&&!r.prototype.roundRect&&(r.prototype.roundRect=B)}}J(window),K(window);
@@ -10,7 +10,7 @@ export declare abstract class BaseUIClass {
10
10
  private readonly setSize;
11
11
  resizeObserver: ResizeObserver;
12
12
  constructor(props: UIProps);
13
- protected getLang(): "en" | "th" | "ja" | "ar" | "pl" | "it";
13
+ protected getLang(): "en" | "th" | "ja" | "ar" | "pl" | "it" | "de";
14
14
  protected getFont(): Record<string, {
15
15
  data: (string | Uint8Array | ArrayBuffer) & (string | Uint8Array | ArrayBuffer | undefined);
16
16
  fallback?: boolean | undefined;
@@ -21,6 +21,8 @@ export declare abstract class BaseUIClass {
21
21
  getTemplate(): {
22
22
  schemas: Record<string, import("zod").objectOutputType<{
23
23
  type: import("zod").ZodString;
24
+ readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
25
+ readOnlyValue: import("zod").ZodOptional<import("zod").ZodString>;
24
26
  position: import("zod").ZodObject<{
25
27
  x: import("zod").ZodNumber;
26
28
  y: import("zod").ZodNumber;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Plugins, UIOptions } from '@pdfme/common';
3
- export declare const I18nContext: import("react").Context<(key: "height" | "width" | "type" | "rotate" | "opacity" | "cancel" | "field" | "fieldName" | "align" | "edit" | "plsInputName" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "addNewField" | "editField" | "errorOccurred" | "errorBulkUpdateFieldName" | "commitBulkUpdateFieldName" | "bulkUpdateFieldName" | "schemas.textColor" | "schemas.bgColor" | "schemas.horizontal" | "schemas.vertical" | "schemas.left" | "schemas.center" | "schemas.right" | "schemas.top" | "schemas.middle" | "schemas.bottom" | "schemas.text.fontName" | "schemas.text.size" | "schemas.text.spacing" | "schemas.text.textAlign" | "schemas.text.verticalAlign" | "schemas.text.lineHeight" | "schemas.text.min" | "schemas.text.max" | "schemas.text.fit" | "schemas.text.dynamicFontSize" | "schemas.barcodes.barColor", dict?: {
3
+ export declare const I18nContext: import("react").Context<(key: "height" | "width" | "type" | "rotate" | "opacity" | "cancel" | "field" | "fieldName" | "align" | "edit" | "plsInputName" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "addNewField" | "editField" | "errorOccurred" | "errorBulkUpdateFieldName" | "commitBulkUpdateFieldName" | "bulkUpdateFieldName" | "hexColorPrompt" | "schemas.color" | "schemas.borderWidth" | "schemas.borderColor" | "schemas.textColor" | "schemas.bgColor" | "schemas.horizontal" | "schemas.vertical" | "schemas.left" | "schemas.center" | "schemas.right" | "schemas.top" | "schemas.middle" | "schemas.bottom" | "schemas.text.fontName" | "schemas.text.size" | "schemas.text.spacing" | "schemas.text.textAlign" | "schemas.text.verticalAlign" | "schemas.text.lineHeight" | "schemas.text.min" | "schemas.text.max" | "schemas.text.fit" | "schemas.text.dynamicFontSize" | "schemas.barcodes.barColor" | "schemas.barcodes.includetext", dict?: {
4
4
  cancel: string;
5
5
  field: string;
6
6
  fieldName: string;
@@ -22,6 +22,10 @@ export declare const I18nContext: import("react").Context<(key: "height" | "widt
22
22
  errorBulkUpdateFieldName: string;
23
23
  commitBulkUpdateFieldName: string;
24
24
  bulkUpdateFieldName: string;
25
+ hexColorPrompt: string;
26
+ 'schemas.color': string;
27
+ 'schemas.borderWidth': string;
28
+ 'schemas.borderColor': string;
25
29
  'schemas.textColor': string;
26
30
  'schemas.bgColor': string;
27
31
  'schemas.horizontal': string;
@@ -43,6 +47,7 @@ export declare const I18nContext: import("react").Context<(key: "height" | "widt
43
47
  'schemas.text.fit': string;
44
48
  'schemas.text.dynamicFontSize': string;
45
49
  'schemas.barcodes.barColor': string;
50
+ 'schemas.barcodes.includetext': string;
46
51
  } | undefined) => string>;
47
52
  export declare const FontContext: import("react").Context<Record<string, {
48
53
  data: (string | Uint8Array | ArrayBuffer) & (string | Uint8Array | ArrayBuffer | undefined);
@@ -37,7 +37,33 @@ export declare const templateSchemas2SchemasList: (_template: Template) => Promi
37
37
  key: string;
38
38
  opacity?: number | undefined;
39
39
  rotate?: number | undefined;
40
+ readOnly?: boolean | undefined;
41
+ readOnlyValue?: string | undefined;
40
42
  }[][]>;
43
+ export declare const generateColumnsAndSampledataIfNeeded: (template: Template) => {
44
+ schemas: Record<string, import("zod").objectOutputType<{
45
+ type: import("zod").ZodString;
46
+ readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
47
+ readOnlyValue: import("zod").ZodOptional<import("zod").ZodString>;
48
+ position: import("zod").ZodObject<{
49
+ x: import("zod").ZodNumber;
50
+ y: import("zod").ZodNumber;
51
+ }, "strip", import("zod").ZodTypeAny, {
52
+ x: number;
53
+ y: number;
54
+ }, {
55
+ x: number;
56
+ y: number;
57
+ }>;
58
+ width: import("zod").ZodNumber;
59
+ height: import("zod").ZodNumber;
60
+ rotate: import("zod").ZodOptional<import("zod").ZodNumber>;
61
+ opacity: import("zod").ZodOptional<import("zod").ZodNumber>;
62
+ }, import("zod").ZodTypeAny, "passthrough">>[];
63
+ basePdf: (string | Uint8Array | ArrayBuffer) & (string | Uint8Array | ArrayBuffer | undefined);
64
+ sampledata?: Record<string, string>[] | undefined;
65
+ columns?: string[] | undefined;
66
+ };
41
67
  export declare const fmtTemplate: (template: Template, schemasList: SchemaForUI[][]) => Template;
42
68
  export declare const getUniqSchemaKey: (arg: {
43
69
  copiedSchemaKey: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/ui",
3
- "version": "3.1.5",
3
+ "version": "3.2.0-dev.1",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "module": "dist/index.js",
27
27
  "types": "dist/types/index.d.ts",
28
28
  "scripts": {
29
- "develop": "npm-run-all --parallel devBuild:watch devBuildType:watch",
29
+ "dev": "npm-run-all --parallel devBuild:watch devBuildType:watch",
30
30
  "devBuild:watch": "esbuild src/index.ts --bundle --outfile=dist/index.js --format=esm --watch",
31
31
  "devBuildType:watch": "tsc --emitDeclarationOnly --watch",
32
32
  "build": "vite build && tsc --emitDeclarationOnly",
package/src/class.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import ReactDOM from 'react-dom';
2
2
  import { DESTROYED_ERR_MSG, DEFAULT_LANG } from './constants.js';
3
- import { debounce, flatten, cloneDeep } from './helper.js';
3
+ import { debounce, generateColumnsAndSampledataIfNeeded, cloneDeep } from './helper.js';
4
4
  import {
5
5
  Template,
6
6
  Size,
@@ -19,42 +19,6 @@ import {
19
19
  } from '@pdfme/common';
20
20
  import { builtInPlugins } from '@pdfme/schemas';
21
21
 
22
- const generateColumnsAndSampledataIfNeeded = (template: Template) => {
23
- const { schemas, columns, sampledata } = template;
24
-
25
- const flatSchemaLength = schemas
26
- .map((schema) => Object.keys(schema).length)
27
- .reduce((acc, cur) => acc + cur, 0);
28
-
29
- const needColumns = !columns || flatSchemaLength !== columns.length;
30
-
31
- const needSampledata = !sampledata || flatSchemaLength !== Object.keys(sampledata[0]).length;
32
-
33
- // columns
34
- if (needColumns) {
35
- template.columns = flatten(schemas.map((schema) => Object.keys(schema)));
36
- }
37
-
38
- // sampledata
39
- if (needSampledata) {
40
- template.sampledata = [
41
- schemas.reduce(
42
- (acc, cur) =>
43
- Object.assign(
44
- acc,
45
- Object.keys(cur).reduce(
46
- (a, c) => Object.assign(a, { [c]: '' }),
47
- {} as { [key: string]: string }
48
- )
49
- ),
50
- {} as { [key: string]: string }
51
- ),
52
- ];
53
- }
54
-
55
- return template;
56
- };
57
-
58
22
  export abstract class BaseUIClass {
59
23
  protected domContainer!: HTMLElement | null;
60
24
 
@@ -383,7 +383,7 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
383
383
  }}
384
384
  stopEditing={() => setEditing(false)}
385
385
  outline={`1px ${hoveringSchemaId === schema.id ? 'solid' : 'dashed'} ${
386
- token.colorPrimary
386
+ schema.readOnly ? 'transparent' : token.colorPrimary
387
387
  }`}
388
388
  scale={scale}
389
389
  />
@@ -77,7 +77,9 @@ const DetailView = (
77
77
  for (let key in newSchema) {
78
78
  if (['id', 'data'].includes(key)) continue;
79
79
  if (newSchema[key] !== (activeSchema as any)[key]) {
80
- const value = newSchema[key] || undefined;
80
+ let value = newSchema[key];
81
+ // FIXME memo: https://github.com/pdfme/pdfme/pull/367#issuecomment-1857468274
82
+ if (value === null && ['rotate', 'opacity'].includes(key)) value = undefined;
81
83
 
82
84
  // [position] Return the flattened position to its original form.
83
85
  if (key === 'x') key = 'position.x';
@@ -138,6 +140,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
138
140
  widget: 'inputNumber',
139
141
  required: true,
140
142
  span: 8,
143
+ min: 0,
141
144
  },
142
145
  height: {
143
146
  title: i18n('height'),
@@ -145,6 +148,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
145
148
  widget: 'inputNumber',
146
149
  required: true,
147
150
  span: 8,
151
+ min: 0,
148
152
  },
149
153
  opacity: {
150
154
  title: i18n('opacity'),
@@ -113,6 +113,8 @@ const TemplateEditor = ({
113
113
  )?.propPanel;
114
114
  set(tgt, 'data', propPanel?.defaultValue || '');
115
115
  Object.assign(tgt, propPanel?.defaultSchema || {});
116
+ } else if (key === 'data' && tgt.readOnly) {
117
+ set(tgt, 'readOnlyValue', value);
116
118
  }
117
119
 
118
120
  return acc;
@@ -74,7 +74,7 @@ const Paper = (props: {
74
74
  paperRefs.current[paperIndex] = e;
75
75
  }
76
76
  }}
77
- onClick={(e) => {
77
+ onMouseDown={(e) => {
78
78
  if (
79
79
  e.currentTarget === e.target &&
80
80
  document &&
@@ -104,7 +104,9 @@ const Preview = ({
104
104
  placeholder={template.sampledata?.[0]?.[key] ?? ''}
105
105
  tabIndex={index + 100}
106
106
  onChange={(value) => handleChangeInput({ key, value })}
107
- outline={isForm ? `1px dashed ${token.colorPrimary}` : 'transparent'}
107
+ outline={
108
+ isForm && !schema.readOnly ? `1px dashed ${token.colorPrimary}` : 'transparent'
109
+ }
108
110
  scale={scale}
109
111
  />
110
112
  );
@@ -29,12 +29,13 @@ const Wrapper = ({
29
29
  id={schema.id}
30
30
  style={{
31
31
  position: 'absolute',
32
- cursor: 'pointer',
32
+ cursor: schema.readOnly ? 'initial' : 'pointer',
33
33
  height: schema.height * ZOOM,
34
34
  width: schema.width * ZOOM,
35
35
  top: schema.position.y * ZOOM,
36
36
  left: schema.position.x * ZOOM,
37
37
  transform: `rotate(${schema.rotate ?? 0}deg)`,
38
+ opacity: schema.opacity ?? 1,
38
39
  outline,
39
40
  }}
40
41
  >
@@ -71,7 +72,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
71
72
 
72
73
  render({
73
74
  key: schema.key,
74
- value: schema.data,
75
+ value: schema.readOnly ? schema.readOnlyValue || '' : schema.data,
75
76
  schema,
76
77
  rootElement: ref.current,
77
78
  mode,
package/src/helper.ts CHANGED
@@ -309,6 +309,48 @@ export const templateSchemas2SchemasList = async (_template: Template) => {
309
309
  return schemasList;
310
310
  };
311
311
 
312
+ export const generateColumnsAndSampledataIfNeeded = (template: Template) => {
313
+ const { schemas, columns, sampledata } = template;
314
+
315
+ const flatSchemaLengthForColumns = schemas
316
+ .map((schema) => Object.keys(schema).length)
317
+ .reduce((acc, cur) => acc + cur, 0);
318
+ const needColumns = !columns || flatSchemaLengthForColumns !== columns.length;
319
+
320
+ const flatSchemaLengthForSampleData = schemas
321
+ .map((schema) => Object.keys(schema).filter((key) => !schema[key].readOnly).length)
322
+ .reduce((acc, cur) => acc + cur, 0);
323
+ const needSampledata =
324
+ !sampledata || flatSchemaLengthForSampleData !== Object.keys(sampledata[0]).length;
325
+
326
+ // columns
327
+ if (needColumns) {
328
+ template.columns = flatten(schemas.map((schema) => Object.keys(schema)));
329
+ }
330
+
331
+ // sampledata
332
+ if (needSampledata) {
333
+ template.sampledata = [
334
+ schemas.reduce(
335
+ (acc, cur) =>
336
+ Object.assign(
337
+ acc,
338
+ Object.keys(cur).reduce((a, c) => {
339
+ const { readOnly } = cur[c];
340
+ if (readOnly) {
341
+ return a;
342
+ }
343
+ return Object.assign(a, { [c]: '' });
344
+ }, {} as { [key: string]: string })
345
+ ),
346
+ {} as { [key: string]: string }
347
+ ),
348
+ ];
349
+ }
350
+
351
+ return template;
352
+ };
353
+
312
354
  export const fmtTemplate = (template: Template, schemasList: SchemaForUI[][]): Template => {
313
355
  const schemaAddedTemplate: Template = {
314
356
  ...template,
@@ -333,6 +375,9 @@ export const fmtTemplate = (template: Template, schemasList: SchemaForUI[][]): T
333
375
  sampledata: [
334
376
  cloneDeep(schemasList).reduce((acc, cur) => {
335
377
  cur.forEach((c) => {
378
+ if (c.readOnly) {
379
+ return;
380
+ }
336
381
  acc[c.key] = c.data;
337
382
  });
338
383