@pdfme/ui 4.5.2-dev.1 → 4.5.2-dev.3

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/README.md CHANGED
@@ -27,6 +27,7 @@
27
27
 
28
28
  <p align="center">TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!</p>
29
29
 
30
+
30
31
  ## Features
31
32
 
32
33
  | Fast PDF Generator | Easy PDF template design | Simple JSON template |
@@ -70,6 +71,9 @@ npm i @pdfme/ui @pdfme/common
70
71
 
71
72
  \*You must install `@pdfme/common` regardless of which package you use.
72
73
 
74
+ On NPM stable releases are published to the `latest` tag, and pre-releases are published to the `next` tag.
75
+ On the `dev` tag you can find releases for every commit to the `main` branch.
76
+
73
77
  The following type, function and classes are available in pdfme.
74
78
 
75
79
  `@pdfme/common`
@@ -117,9 +121,8 @@ The following image is a good illustration of a template.
117
121
  **basePdf** can be given a `string`(base64), `ArrayBuffer`, or `Uint8Array`.
118
122
  A blank A4 PDF can be imported with `BLANK_PDF`. You can use it to check how it works.
119
123
 
120
- **schemas** can only utilize text by default, but you can load images and various barcodes like QR codes as plugins from the `@pdfme/schemas` package.
121
- Additionally, you can create your own schemas, allowing you to render types other than the ones mentioned above.
122
- Check detail about [Custom Schemas](https://pdfme.com/docs/custom-schemas) from here
124
+ **Schemas** can only utilize text by default, but you can load images and various barcodes like QR codes as plugins from the `@pdfme/schemas` package.
125
+ Additionally, you can create your own schemas, allowing you to render types other than the ones mentioned above. Check detail about [Custom Schemas](https://pdfme.com/docs/custom-schemas) from here.
123
126
 
124
127
  Let's take a look at some specific data.
125
128
  (If you are using TypeScript, you can import the Template type.)
@@ -132,26 +135,29 @@ import { Template, BLANK_PDF } from '@pdfme/common';
132
135
  const template: Template = {
133
136
  basePdf: BLANK_PDF,
134
137
  schemas: [
135
- {
136
- a: {
138
+ [
139
+ {
140
+ name: 'a',
137
141
  type: 'text',
138
142
  position: { x: 0, y: 0 },
139
143
  width: 10,
140
144
  height: 10,
141
145
  },
142
- b: {
146
+ {
147
+ name: 'a',
143
148
  type: 'text',
144
149
  position: { x: 10, y: 10 },
145
150
  width: 10,
146
151
  height: 10,
147
152
  },
148
- c: {
153
+ {
154
+ name: 'c',
149
155
  type: 'text',
150
156
  position: { x: 20, y: 20 },
151
157
  width: 10,
152
158
  height: 10,
153
159
  },
154
- },
160
+ ],
155
161
  ],
156
162
  };
157
163
  ```
@@ -193,7 +199,7 @@ Also, each element in the inputs array corresponds to a page in the PDF, you can
193
199
 
194
200
  ## UI
195
201
 
196
- The UI is composed of the Designer, Form, and Viewer classes.
202
+ The UI is composed of the [Designer](https://pdfme.com/docs/getting-started#designer), [Form](https://pdfme.com/docs/getting-started#form), and [Viewer](https://pdfme.com/docs/getting-started#viewer) classes.
197
203
 
198
204
  ### Designer
199
205
 
@@ -225,7 +231,6 @@ The designer instance can be manipulated with the following methods.
225
231
  - `saveTemplate`
226
232
  - `updateTemplate`
227
233
  - `getTemplate`
228
- - `getPageCursor`
229
234
  - `onChangeTemplate`
230
235
  - `onSaveTemplate`
231
236
  - `destroy`
@@ -286,6 +291,72 @@ const viewer = new Viewer({ domContainer, template, inputs });
286
291
 
287
292
  ![](https://raw.githubusercontent.com/pdfme/pdfme/main/website/static/img/viewer.png)
288
293
 
294
+ ### Using additional schemas and custom plugins
295
+
296
+ The examples so far use only the `text` schema type. There are many others built-in within the `@pdfme/schemas` package, and you can use your own:
297
+
298
+ Here's an example using additional schemas from built-in and custom plugins:
299
+
300
+ ```ts
301
+ import { Template, BLANK_PDF } from '@pdfme/common';
302
+ import { text, barcodes, image } from '@pdfme/schemas';
303
+ import myPlugin from './custom-plugins';
304
+
305
+ const template: Template = {
306
+ basePdf: BLANK_PDF,
307
+ schemas: [
308
+ [
309
+ {
310
+ name: 'example_text',
311
+ type: 'text',
312
+ position: { x: 0, y: 0 },
313
+ width: 40,
314
+ height: 10,
315
+ },
316
+ {
317
+ name: 'example_image',
318
+ type: 'image',
319
+ position: { x: 200, y: 200 },
320
+ width: 60,
321
+ height: 40,
322
+ },
323
+ {
324
+ name: 'example_qr_code',
325
+ type: 'qrcode',
326
+ position: { x: 100, y: 100 },
327
+ width: 50,
328
+ height: 50,
329
+ },
330
+ ],
331
+ ],
332
+ };
333
+
334
+ const plugins = {
335
+ Text: multiVariableText,
336
+ 'QR Code': barcodes.qrcode,
337
+ Image: image,
338
+ MyPlugin: myPlugin
339
+ }
340
+
341
+ const inputs = [{
342
+ example_text: 'a1',
343
+ example_image: 'data:image/png;base64,iVBORw0KG....',
344
+ example_qr_code: 'https://pdfme.com/'
345
+ }];
346
+
347
+ generate({ template, inputs, plugins }).then((pdf) => {
348
+ console.log(pdf);
349
+ });
350
+
351
+ ```
352
+
353
+
354
+
355
+ ## Examples using pdfme
356
+
357
+ If you are looking for code examples using pdfme to get started, please check out the [pdfme-playground](https://github.com/pdfme/pdfme-playground) repository
358
+ or look at the examples in the `websit/src/pages/` folder of this repository. Settings these up is covered in the [DEVELOPMENT.md](DEVELOPMENT.md) file.
359
+
289
360
  ## Special Thanks
290
361
 
291
362
  - [pdf-lib](https://pdf-lib.js.org/): Used in PDF generation.
@@ -297,7 +368,7 @@ const viewer = new Viewer({ domContainer, template, inputs });
297
368
  - [react-moveable](https://daybrush.com/moveable/), [react-selecto](https://github.com/daybrush/selecto), [@scena/react-guides](https://daybrush.com/guides/): Used in Designer UI.
298
369
  - [dnd-kit](https://github.com/clauderic/dnd-kit): Used in Designer UI.
299
370
 
300
- I definitely could not have created pdfme without these libraries. I am grateful to the developers of these libraries.
371
+ I definitely could not have created pdfme without these libraries. I am grateful to the developers of these libraries.
301
372
 
302
373
  If you want to contribute to pdfme, please check the [Development Guide](https://pdfme.com/docs/development-guide) page.
303
374
  We look forward to your contribution!
package/dist/index.es.js CHANGED
@@ -9310,6 +9310,7 @@ z.enum(["viewer", "form", "designer"]);
9310
9310
  const ColorType = z.enum(["rgb", "cmyk"]).optional();
9311
9311
  z.object({ height: z.number(), width: z.number() });
9312
9312
  const Schema$1 = z.object({
9313
+ name: z.string(),
9313
9314
  type: z.string(),
9314
9315
  content: z.string().optional(),
9315
9316
  position: z.object({ x: z.number(), y: z.number() }),
@@ -9321,17 +9322,16 @@ const Schema$1 = z.object({
9321
9322
  required: z.boolean().optional(),
9322
9323
  __bodyRange: z.object({ start: z.number(), end: z.number().optional() }).optional(),
9323
9324
  __isSplit: z.boolean().optional()
9324
- }).passthrough(), SchemaForUIAdditionalInfo = z.object({
9325
- id: z.string(),
9326
- key: z.string()
9327
- });
9325
+ }).passthrough(), SchemaForUIAdditionalInfo = z.object({ id: z.string() });
9328
9326
  Schema$1.merge(SchemaForUIAdditionalInfo);
9329
9327
  const ArrayBufferSchema = z.any().refine((a) => a instanceof ArrayBuffer), Uint8ArraySchema = z.any().refine((a) => a instanceof Uint8Array), BlankPdf = z.object({
9330
9328
  width: z.number(),
9331
9329
  height: z.number(),
9332
9330
  padding: z.tuple([z.number(), z.number(), z.number(), z.number()])
9333
- }), CustomPdf = z.union([z.string(), ArrayBufferSchema, Uint8ArraySchema]), BasePdf = z.union([CustomPdf, BlankPdf]), Template = z.object({
9334
- schemas: z.array(z.record(Schema$1)),
9331
+ }), CustomPdf = z.union([z.string(), ArrayBufferSchema, Uint8ArraySchema]), BasePdf = z.union([CustomPdf, BlankPdf]);
9332
+ z.array(z.record(Schema$1));
9333
+ const SchemaPageArray = z.array(z.array(Schema$1)), Template = z.object({
9334
+ schemas: SchemaPageArray,
9335
9335
  basePdf: BasePdf,
9336
9336
  pdfmeVersion: z.string().optional()
9337
9337
  }).passthrough(), Inputs = z.array(z.record(z.any())).min(1), Font = z.record(z.object({
@@ -9385,14 +9385,19 @@ const UIOptions = CommonOptions.extend({
9385
9385
  _.onloadend = () => {
9386
9386
  _.result.startsWith("data:application/pdf;") ? s(_.result) : $(Error("[@pdfme/common] template.basePdf must be pdf data."));
9387
9387
  }, _.readAsDataURL(a);
9388
- }), isHexValid = (a) => /^#(?:[A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/i.test(a), getB64BasePdf = (a) => typeof a == "string" && !a.startsWith("data:application/pdf;") && typeof window < "u" ? fetch(a).then(($) => $.blob()).then(blob2Base64Pdf).catch(($) => {
9388
+ }), isHexValid = (a) => /^#(?:[A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/i.test(a), migrateTemplate = (a) => {
9389
+ a.schemas && Array.isArray(a.schemas) && a.schemas.length > 0 && !Array.isArray(a.schemas[0]) && (a.schemas = a.schemas.map((s) => Object.entries(s).map(([$, _]) => ({
9390
+ ..._,
9391
+ name: $
9392
+ }))));
9393
+ }, getB64BasePdf = (a) => typeof a == "string" && !a.startsWith("data:application/pdf;") && typeof window < "u" ? fetch(a).then(($) => $.blob()).then(blob2Base64Pdf).catch(($) => {
9389
9394
  throw $;
9390
9395
  }) : a, isBlankPdf = (a) => BlankPdf.safeParse(a).success, getByteString = (a) => buffer$1.Buffer.from(a, "base64").toString("binary"), b64toUint8Array = (a) => {
9391
9396
  const s = a.split(";base64,")[1] ? a.split(";base64,")[1] : a, $ = getByteString(s), _ = new Uint8Array($.length);
9392
9397
  for (let _e = 0; _e < $.length; _e += 1)
9393
9398
  _[_e] = $.charCodeAt(_e);
9394
9399
  return _;
9395
- }, getFontNamesInSchemas = (a) => uniq(a.map((s) => Object.values(s).map(($) => $.fontName ?? "")).reduce((s, $) => s.concat($), []).filter(Boolean)), checkFont = (a) => {
9400
+ }, getFontNamesInSchemas = (a) => uniq(a.map((s) => s.map(($) => $.fontName ?? "")).reduce((s, $) => s.concat($), []).filter(Boolean)), checkFont = (a) => {
9396
9401
  const { font: s, template: { schemas: $ } } = a, _e = Object.values(s).reduce((at, ot) => ot.fallback ? at + 1 : at, 0);
9397
9402
  if (_e === 0)
9398
9403
  throw Error(`[@pdfme/common] fallback flag is not found in font. true fallback flag must be only one.
@@ -9405,7 +9410,7 @@ Check this document: https://pdfme.com/docs/custom-fonts#about-font-type`);
9405
9410
  throw Error(`[@pdfme/common] ${tt.filter((at) => !nt.includes(at)).join()} of template.schemas is not found in font.
9406
9411
  Check this document: https://pdfme.com/docs/custom-fonts`);
9407
9412
  }, checkPlugins = (a) => {
9408
- const { plugins: s, template: { schemas: $ } } = a, _ = uniq($.map((tt) => Object.values(tt).map((nt) => nt.type)).flat()), _e = Object.values(s).map((tt) => tt == null ? void 0 : tt.propPanel.defaultSchema.type);
9413
+ const { plugins: s, template: { schemas: $ } } = a, _ = uniq($.map((tt) => tt.map((nt) => nt.type)).flat()), _e = Object.values(s).map((tt) => tt == null ? void 0 : tt.propPanel.defaultSchema.type);
9409
9414
  if (_.some((tt) => !_e.includes(tt)))
9410
9415
  throw Error(`[@pdfme/common] ${_.filter((tt) => !_e.includes(tt)).join()} of template.schemas is not found in plugins.`);
9411
9416
  }, checkProps = (a, s) => {
@@ -9430,7 +9435,11 @@ ${_e}`);
9430
9435
  const { template: $, plugins: _ } = a;
9431
9436
  _ && checkPlugins({ plugins: _, template: $ });
9432
9437
  }
9433
- }, checkInputs = (a) => checkProps(a, Inputs), checkUIOptions = (a) => checkProps(a, UIOptions), checkTemplate = (a) => checkProps(a, Template), checkUIProps = (a) => checkProps(a, UIProps), checkPreviewProps = (a) => checkProps(a, PreviewProps), checkDesignerProps = (a) => checkProps(a, DesignerProps);
9438
+ }, checkInputs = (a) => checkProps(a, Inputs), checkUIOptions = (a) => checkProps(a, UIOptions), checkPreviewProps = (a) => checkProps(a, PreviewProps), checkDesignerProps = (a) => checkProps(a, DesignerProps), checkUIProps = (a) => {
9439
+ typeof a == "object" && a !== null && "template" in a && migrateTemplate(a.template), checkProps(a, UIProps);
9440
+ }, checkTemplate = (a) => {
9441
+ migrateTemplate(a), checkProps(a, Template);
9442
+ };
9434
9443
  class Node {
9435
9444
  constructor({ width: s = 0, height: $ = 0 } = {}) {
9436
9445
  Object.defineProperty(this, "index", {
@@ -9438,11 +9447,6 @@ class Node {
9438
9447
  configurable: !0,
9439
9448
  writable: !0,
9440
9449
  value: 0
9441
- }), Object.defineProperty(this, "key", {
9442
- enumerable: !0,
9443
- configurable: !0,
9444
- writable: !0,
9445
- value: void 0
9446
9450
  }), Object.defineProperty(this, "schema", {
9447
9451
  enumerable: !0,
9448
9452
  configurable: !0,
@@ -9478,8 +9482,8 @@ class Node {
9478
9482
  setIndex(s) {
9479
9483
  this.index = s;
9480
9484
  }
9481
- setKeyAndSchema(s, $) {
9482
- this.key = s, this.schema = $;
9485
+ setSchema(s) {
9486
+ this.schema = s;
9483
9487
  }
9484
9488
  setWidth(s) {
9485
9489
  this.width = s;
@@ -9509,27 +9513,28 @@ function createPage(a) {
9509
9513
  return s.setPadding(a.padding), s;
9510
9514
  }
9511
9515
  function createNode(a) {
9512
- const { position: s, width: $, height: _, key: _e, schema: tt } = a, nt = new Node({ width: $, height: _ });
9513
- return nt.setPosition(s), nt.setKeyAndSchema(_e, tt), nt;
9516
+ const { position: s, width: $, height: _, schema: _e } = a, tt = new Node({ width: $, height: _ });
9517
+ return tt.setPosition(s), tt.setSchema(_e), tt;
9514
9518
  }
9515
9519
  function resortChildren(a, s) {
9516
9520
  a.children = a.children.sort(($, _) => {
9517
- const _e = s.get($.key), tt = s.get(_.key);
9521
+ var nt, at;
9522
+ const _e = s.get((nt = $.schema) == null ? void 0 : nt.name), tt = s.get((at = _.schema) == null ? void 0 : at.name);
9518
9523
  if (_e === void 0 || tt === void 0)
9519
9524
  throw new Error("[@pdfme/common] order is not defined");
9520
9525
  return _e - tt;
9521
9526
  }).map(($, _) => ($.setIndex(_), $));
9522
9527
  }
9523
9528
  async function createOnePage(a) {
9524
- const { basePdf: s, schemaObj: $, orderMap: _, input: _e, options: tt, _cache: nt, getDynamicHeights: at } = a, ot = createPage(s), rt = [], st = Object.entries($).sort((it, ut) => it[1].position.y - ut[1].position.y), lt = /* @__PURE__ */ new Map();
9525
- for (const [it, ut] of st) {
9526
- const { position: ft, width: ht } = ut, dt = { schema: ut, basePdf: s, options: tt, _cache: nt }, gt = (ut.readOnly ? ut.content : _e == null ? void 0 : _e[it]) || "", pt = await at(gt, dt), mt = pt.reduce((vt, At) => vt + At, 0), ct = ut.height;
9527
- mt !== ct && lt.set(ft.y + ct, mt - ct), pt.forEach((vt, At) => {
9528
- let xt = ut.position.y + pt.reduce((Et, St, Bt) => Bt < At ? Et + St : Et, 0);
9529
- for (const [Et, St] of lt.entries())
9530
- Et <= ut.position.y && (xt += St);
9531
- const bt = createNode({ key: it, schema: ut, position: { ...ft, y: xt }, width: ht, height: vt });
9532
- rt.push(xt + vt + s.padding[2]), ot.insertChild(bt);
9529
+ const { basePdf: s, schemaPage: $, orderMap: _, input: _e, options: tt, _cache: nt, getDynamicHeights: at } = a, ot = createPage(s), rt = [], st = cloneDeep$1($).sort((it, ut) => it.position.y - ut.position.y), lt = /* @__PURE__ */ new Map();
9530
+ for (const it of st) {
9531
+ const { position: ut, width: ft } = it, ht = { schema: it, basePdf: s, options: tt, _cache: nt }, dt = (it.readOnly ? it.content : _e == null ? void 0 : _e[it.name]) || "", gt = await at(dt, ht), pt = gt.reduce((ct, vt) => ct + vt, 0), mt = it.height;
9532
+ pt !== mt && lt.set(ut.y + mt, pt - mt), gt.forEach((ct, vt) => {
9533
+ let At = it.position.y + gt.reduce((bt, Et, St) => St < vt ? bt + Et : bt, 0);
9534
+ for (const [bt, Et] of lt.entries())
9535
+ bt <= it.position.y && (At += Et);
9536
+ const xt = createNode({ schema: it, position: { ...ut, y: At }, width: ft, height: ct });
9537
+ rt.push(At + ct + s.padding[2]), ot.insertChild(xt);
9533
9538
  });
9534
9539
  }
9535
9540
  const et = Math.max(...rt, s.height - s.padding[2]);
@@ -9544,35 +9549,41 @@ function breakIntoPages(a) {
9544
9549
  return it + (((ut = at.find((ft) => ft.page === et)) == null ? void 0 : ut.value) || 0);
9545
9550
  }, st = s.children.sort((lt, et) => lt.position.y - et.position.y);
9546
9551
  for (let lt = 0; lt < st.length; lt++) {
9547
- const { key: et, schema: it, position: ut, height: ft, width: ht } = st[lt], { y: dt, x: gt } = ut;
9548
- let pt = Math.floor(dt / ot(_e.length - 1)), mt = rt(dt, pt);
9549
- if (mt + ft > _.height - nt && (pt++, mt = rt(dt, pt)), !et || !it)
9550
- throw new Error("[@pdfme/common] key or schema is undefined");
9551
- const ct = createNode({ key: et, schema: it, position: { x: gt, y: mt }, width: ht, height: ft });
9552
- _e[pt].insertChild(ct);
9552
+ const { schema: et, position: it, height: ut, width: ft } = st[lt], { y: ht, x: dt } = it;
9553
+ let gt = Math.floor(ht / ot(_e.length - 1)), pt = rt(ht, gt);
9554
+ if (pt + ut > _.height - nt && (gt++, pt = rt(ht, gt)), !et)
9555
+ throw new Error("[@pdfme/common] schema is undefined");
9556
+ const mt = createNode({ schema: et, position: { x: dt, y: pt }, width: ft, height: ut });
9557
+ _e[gt].insertChild(mt);
9553
9558
  }
9554
9559
  return _e.forEach((lt) => resortChildren(lt, $)), _e;
9555
9560
  }
9556
9561
  function createNewTemplate(a, s) {
9557
9562
  const $ = {
9558
- schemas: Array.from({ length: a.length }, () => ({})),
9563
+ schemas: Array.from({ length: a.length }, () => []),
9559
9564
  basePdf: s
9560
9565
  }, _ = /* @__PURE__ */ new Map();
9561
9566
  return cloneDeep$1(a).forEach((_e, tt) => {
9562
9567
  _e.children.forEach((nt) => {
9563
- const { key: at, schema: ot } = nt;
9564
- if (!at || !ot)
9565
- throw new Error("[@pdfme/common] key or schema is undefined");
9566
- _.has(at) || _.set(at, []), _.get(at).push(nt);
9567
- const rt = _e.children.filter((lt) => lt.key === at), st = _.get(at).length - rt.length;
9568
+ const { schema: at } = nt;
9569
+ if (!at)
9570
+ throw new Error("[@pdfme/common] schema is undefined");
9571
+ const ot = at.name;
9572
+ _.has(ot) || _.set(ot, []), _.get(ot).push(nt);
9573
+ const rt = _e.children.filter((lt) => {
9574
+ var et;
9575
+ return ((et = lt.schema) == null ? void 0 : et.name) === ot;
9576
+ }), st = _.get(ot).length - rt.length;
9568
9577
  if (rt.length > 0) {
9569
9578
  if (!rt[0].schema)
9570
9579
  throw new Error("[@pdfme/common] schema is undefined");
9571
- const lt = rt[0].schema, et = rt.reduce((ut, ft) => ut + ft.height, 0), it = rt[0].position;
9580
+ const lt = rt[0].schema, et = rt.reduce((ht, dt) => ht + dt.height, 0), it = rt[0].position;
9572
9581
  lt.__bodyRange = {
9573
9582
  start: Math.max(st - 1, 0),
9574
9583
  end: st + rt.length - 1
9575
- }, lt.__isSplit = st > 0, $.schemas[tt][at] = Object.assign({}, lt, { position: it, height: et });
9584
+ }, lt.__isSplit = st > 0;
9585
+ const ut = Object.assign({}, lt, { position: it, height: et }), ft = $.schemas[tt].findIndex((ht) => ht.name === ot);
9586
+ ft !== -1 ? $.schemas[tt][ft] = ut : $.schemas[tt].push(ut);
9576
9587
  }
9577
9588
  });
9578
9589
  }), $;
@@ -9583,7 +9594,7 @@ const getDynamicTemplate = async (a) => {
9583
9594
  return s;
9584
9595
  const $ = s.basePdf, _ = [];
9585
9596
  for (const _e of s.schemas) {
9586
- const tt = new Map(Object.keys(_e).map((ot, rt) => [ot, rt])), nt = await createOnePage({ basePdf: $, schemaObj: _e, orderMap: tt, ...a }), at = breakIntoPages({ longPage: nt, basePdf: $, orderMap: tt });
9597
+ const tt = new Map(_e.map((ot, rt) => [ot.name, rt])), nt = await createOnePage({ basePdf: $, schemaPage: _e, orderMap: tt, ...a }), at = breakIntoPages({ longPage: nt, basePdf: $, orderMap: tt });
9587
9598
  _.push(...at);
9588
9599
  }
9589
9600
  return createNewTemplate(_, s.basePdf);
@@ -60278,34 +60289,31 @@ const uuid$6 = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (a)
60278
60289
  hotkeys.unbind(keys$2.join());
60279
60290
  }, getPdfPageSizes = async (a) => {
60280
60291
  const s = URL.createObjectURL(a), $ = await pdfExports.getDocument({ url: s }).promise, _ = Promise.all(
60281
- new Array($.numPages).fill("").map(async (_e, tt) => await $.getPage(tt + 1).then((at) => {
60282
- const { height: ot, width: rt } = at.getViewport({ scale: 1 });
60283
- return { height: pt2mm(ot), width: pt2mm(rt) };
60292
+ new Array($.numPages).fill("").map(async (_e, tt) => await $.getPage(tt + 1).then((nt) => {
60293
+ const { height: at, width: ot } = nt.getViewport({ scale: 1 });
60294
+ return { height: pt2mm(at), width: pt2mm(ot) };
60284
60295
  }))
60285
60296
  );
60286
60297
  return URL.revokeObjectURL(s), _;
60287
60298
  }, pdf2Images = async (a, s, $) => {
60288
60299
  const _ = URL.createObjectURL(a), _e = await pdfExports.getDocument({ url: _ }).promise, tt = Promise.all(
60289
- new Array(_e.numPages).fill("").map(async (nt, at) => await _e.getPage(at + 1).then((rt) => {
60290
- const st = document.createElement("canvas");
60291
- st.width = s * 2;
60292
- const lt = st.getContext("2d"), et = st.width / rt.getViewport({ scale: 1 }).width, it = rt.getViewport({ scale: et });
60293
- return st.height = it.height, rt.render({ canvasContext: lt, viewport: it }).promise.then(() => st.toDataURL(`image/${$}`));
60300
+ new Array(_e.numPages).fill("").map(async (nt, at) => await _e.getPage(at + 1).then((ot) => {
60301
+ const rt = document.createElement("canvas");
60302
+ rt.width = s * 2;
60303
+ const st = rt.getContext("2d"), lt = rt.width / ot.getViewport({ scale: 1 }).width, et = ot.getViewport({ scale: lt });
60304
+ return rt.height = et.height, ot.render({ canvasContext: st, viewport: et }).promise.then(() => rt.toDataURL(`image/${$}`));
60294
60305
  }))
60295
60306
  );
60296
60307
  return URL.revokeObjectURL(_), tt;
60297
60308
  }, pdf2Pngs = (a, s) => pdf2Images(a, s, "png"), b64toBlob = (a) => {
60298
60309
  const s = b64toUint8Array(a), [, , $] = a.match(/(:)([a-z/]+)(;)/);
60299
60310
  return new Blob([s.buffer], { type: $ });
60300
- }, sortSchemasList = (a) => {
60301
- const { schemas: s } = a, $ = s.length;
60302
- return new Array($).fill("").reduce((_e, tt, nt) => (_e.push(
60303
- s[nt] ? Object.entries(s[nt]).map(
60304
- ([at, ot]) => Object.assign(ot, { key: at, content: ot.content, id: uuid$6() })
60305
- ) : []
60306
- ), _e), []);
60307
- }, template2SchemasList = async (a) => {
60308
- const s = cloneDeep$1(a), { basePdf: $, schemas: _ } = s, _e = sortSchemasList(s);
60311
+ }, convertSchemasForUI = (a) => (a.schemas.forEach((s, $) => {
60312
+ s.forEach((_) => {
60313
+ _.id = uuid$6(), _.content = _.content || "";
60314
+ });
60315
+ }), a.schemas), template2SchemasList = async (a) => {
60316
+ const s = cloneDeep$1(a), { basePdf: $, schemas: _ } = s, _e = convertSchemasForUI(s);
60309
60317
  let tt = [];
60310
60318
  if (isBlankPdf($))
60311
60319
  tt = _.map(() => ({
@@ -60313,32 +60321,29 @@ const uuid$6 = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (a)
60313
60321
  height: $.height
60314
60322
  }));
60315
60323
  else {
60316
- const rt = await getB64BasePdf($), st = b64toBlob(rt);
60317
- tt = await getPdfPageSizes(st);
60324
+ const ot = await getB64BasePdf($), rt = b64toBlob(ot);
60325
+ tt = await getPdfPageSizes(rt);
60318
60326
  }
60319
60327
  const nt = _e.length, at = tt.length;
60320
- return (nt < at ? _e.concat(new Array(at - nt).fill(cloneDeep$1([]))) : _e.slice(0, tt.length)).map((rt, st) => (Object.values(rt).forEach((lt) => {
60321
- const { width: et, height: it } = tt[st], ut = lt.position.x + lt.width, ft = lt.position.y + lt.height;
60322
- if (et < ut) {
60323
- const ht = ut - et;
60324
- lt.position.x += ht;
60328
+ return (nt < at ? _e.concat(new Array(at - nt).fill(cloneDeep$1([]))) : _e.slice(0, tt.length)).map((ot, rt) => (Object.values(ot).forEach((st) => {
60329
+ const { width: lt, height: et } = tt[rt], it = st.position.x + st.width, ut = st.position.y + st.height;
60330
+ if (lt < it) {
60331
+ const ft = it - lt;
60332
+ st.position.x += ft;
60325
60333
  }
60326
- if (it < ft) {
60327
- const ht = ft - it;
60328
- lt.position.y += ht;
60334
+ if (et < ut) {
60335
+ const ft = ut - et;
60336
+ st.position.y += ft;
60329
60337
  }
60330
- }), rt));
60338
+ }), ot));
60331
60339
  }, schemasList2template = (a, s) => ({
60332
60340
  schemas: cloneDeep$1(a).map(
60333
- ($) => $.reduce((_, _e) => {
60334
- const tt = _e.key;
60335
- return delete _e.id, delete _e.key, _[tt] = _e, _;
60336
- }, {})
60341
+ ($) => $.map((_) => (delete _.id, _))
60337
60342
  ),
60338
60343
  basePdf: s
60339
- }), getUniqSchemaKey = (a) => {
60340
- const { copiedSchemaKey: s, schema: $, stackUniqSchemaKeys: _ } = a, _e = $.map((rt) => rt.key).concat(_), tt = _e.reduce(
60341
- (rt, st) => Object.assign(rt, { originalKey: st, copiedNum: 0 }),
60344
+ }), getUniqueSchemaName = (a) => {
60345
+ const { copiedSchemaName: s, schema: $, stackUniqueSchemaNames: _ } = a, _e = $.map((rt) => rt.name).concat(_), tt = _e.reduce(
60346
+ (rt, st) => Object.assign(rt, { originalName: st, copiedNum: 0 }),
60342
60347
  {}
60343
60348
  ), nt = (rt) => rt.replace(/ copy$| copy [0-9]*$/, "");
60344
60349
  _e.filter((rt) => / copy$| copy [0-9]*$/.test(rt)).forEach((rt) => {
@@ -60384,7 +60389,7 @@ const uuid$6 = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (a)
60384
60389
  var nt;
60385
60390
  if (s !== "type")
60386
60391
  return;
60387
- const _e = ["id", "key", "type", "position", "required"];
60392
+ const _e = ["id", "name", "type", "position", "required"];
60388
60393
  Object.keys(a).forEach((at) => {
60389
60394
  _e.includes(at) || delete a[at];
60390
60395
  });
@@ -81960,6 +81965,7 @@ const UseDynamicFontSize = (a) => {
81960
81965
  },
81961
81966
  widgets: { UseDynamicFontSize },
81962
81967
  defaultSchema: {
81968
+ name: "",
81963
81969
  type: "text",
81964
81970
  content: "Type Something...",
81965
81971
  position: { x: 0, y: 0 },
@@ -136559,11 +136565,11 @@ const { Text: Text$4 } = Typography$1, Item = React$a.memo(
136559
136565
  if (!ut.current || ut.current.length === 0)
136560
136566
  return;
136561
136567
  const pt = _e[a], mt = [], ct = ut.current.map((vt) => {
136562
- const At = uuid$6(), xt = getUniqSchemaKey({ copiedSchemaKey: vt.key, schema: pt, stackUniqSchemaKeys: mt }), { height: bt, width: Et, position: St } = vt, Bt = s[a], Ot = {
136568
+ const At = uuid$6(), xt = getUniqueSchemaName({ copiedSchemaName: vt.name, schema: pt, stackUniqueSchemaNames: mt }), { height: bt, width: Et, position: St } = vt, Bt = s[a], Ot = {
136563
136569
  x: St.x + 10 > Bt.width - Et ? Bt.width - Et : St.x + 10,
136564
136570
  y: St.y + 10 > Bt.height - bt ? Bt.height - bt : St.y + 10
136565
136571
  };
136566
- return Object.assign(cloneDeep$1(vt), { id: At, key: xt, position: Ot });
136572
+ return Object.assign(cloneDeep$1(vt), { id: At, name: xt, position: Ot });
136567
136573
  });
136568
136574
  nt(_e[a].concat(ct)), et(ct.map((vt) => document.getElementById(vt.id))), ut.current = ct;
136569
136575
  },
@@ -136622,7 +136628,7 @@ const { Text: Text$4 } = Typography$1, Item = React$a.memo(
136622
136628
  ([Et, St]) => (St == null ? void 0 : St.propPanel.defaultSchema.type) === _e.type
136623
136629
  ), vt = { width: 20, marginRight: "0.5rem" };
136624
136630
  let At;
136625
- _e.key ? tt.find((Et) => _e.key && Et.key === _e.key && Et.id !== _e.id) && (At = "is-danger") : At = "is-warning";
136631
+ _e.name ? tt.find((Et) => _e.name && Et.name === _e.name && Et.id !== _e.id) && (At = "is-danger") : At = "is-warning";
136626
136632
  let xt = rt("edit");
136627
136633
  At === "is-warning" ? xt = rt("plsInputName") : At === "is-danger" && (xt = rt("fieldMustUniq"));
136628
136634
  const bt = a ? { background: ot.colorPrimary, opacity: ut || it ? 0.5 : 1 } : {};
@@ -136634,7 +136640,7 @@ const { Text: Text$4 } = Typography$1, Item = React$a.memo(
136634
136640
  onMouseLeave: at,
136635
136641
  onClick: () => _(_e.id),
136636
136642
  icon: ct && /* @__PURE__ */ jsxRuntimeExports.jsx(PluginIcon$1, { plugin: ct, label: mt, size: 20, styles: vt }),
136637
- value: _e.key,
136643
+ value: _e.name,
136638
136644
  status: At,
136639
136645
  title: xt,
136640
136646
  required: _e.required,
@@ -136720,7 +136726,7 @@ const { Text: Text$4 } = Typography$1, Item = React$a.memo(
136720
136726
  Item$1,
136721
136727
  {
136722
136728
  icon: dt(lt),
136723
- value: gt.key,
136729
+ value: gt.name,
136724
136730
  required: gt.required,
136725
136731
  readOnly: gt.readOnly,
136726
136732
  style: { background: s.colorPrimary },
@@ -136731,7 +136737,7 @@ const { Text: Text$4 } = Typography$1, Item = React$a.memo(
136731
136737
  Item$1,
136732
136738
  {
136733
136739
  icon: dt(pt),
136734
- value: pt.key,
136740
+ value: pt.name,
136735
136741
  required: pt.required,
136736
136742
  readOnly: pt.readOnly,
136737
136743
  style: { background: s.colorPrimary },
@@ -136760,13 +136766,13 @@ const { Text: Text$4 } = Typography$1, Item = React$a.memo(
136760
136766
  `);
136761
136767
  dt.length !== s.length ? alert(rt("errorBulkUpdateFieldName")) : (at(
136762
136768
  dt.map((gt, pt) => ({
136763
- key: "key",
136769
+ key: "name",
136764
136770
  value: gt,
136765
136771
  schemaId: s[pt].id
136766
136772
  }))
136767
136773
  ), lt(!1));
136768
136774
  }, ht = () => {
136769
- it(s.map((dt) => dt.key).join(`
136775
+ it(s.map((dt) => dt.name).join(`
136770
136776
  `)), lt(!0);
136771
136777
  };
136772
136778
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
@@ -152036,7 +152042,7 @@ const FormRender = withProvider(FormCore, defaultWidgets), svgBaseProp = {
152036
152042
  it.current = (ct) => {
152037
152043
  for (const vt of _)
152038
152044
  for (const At of Object.values(vt))
152039
- if (At.key === ct && At.id !== nt.id)
152045
+ if (At.name === ct && At.id !== nt.id)
152040
152046
  return !1;
152041
152047
  return !0;
152042
152048
  };
@@ -152082,7 +152088,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
152082
152088
  required: !0,
152083
152089
  span: 12
152084
152090
  },
152085
- key: {
152091
+ name: {
152086
152092
  title: ot("fieldName"),
152087
152093
  type: "string",
152088
152094
  required: !0,
@@ -152262,7 +152268,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
152262
152268
  }) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
152263
152269
  "div",
152264
152270
  {
152265
- title: _.key,
152271
+ title: _.name,
152266
152272
  onMouseEnter: () => $ && $(_.id),
152267
152273
  onMouseLeave: () => $ && $(null),
152268
152274
  className: SELECTABLE_CLASSNAME,
@@ -152303,7 +152309,6 @@ Check this document: https://pdfme.com/docs/custom-schemas`), /* @__PURE__ */ js
152303
152309
  ut.current.innerHTML = "";
152304
152310
  const gt = ht.ui;
152305
152311
  gt({
152306
- key: tt.key,
152307
152312
  value: at,
152308
152313
  schema: tt,
152309
152314
  basePdf: nt,
@@ -152330,7 +152335,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`), /* @__PURE__ */ js
152330
152335
  lt && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { transform: `scale(${s})` }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
152331
152336
  Renderer$1,
152332
152337
  {
152333
- schema: { ...tt, id: tt.type, key: tt.type },
152338
+ schema: { ...tt, id: tt.type },
152334
152339
  basePdf: $,
152335
152340
  value: tt.content || "",
152336
152341
  onChangeHoveringSchemaId: () => {
@@ -162510,13 +162515,13 @@ const Guides$2 = Guides$1, guideStyle = (a, s, $, _) => ({
162510
162515
  }, []), jt = (Tt) => {
162511
162516
  const [Dt, Ut, Vt, Qt] = isBlankPdf(a.basePdf) ? a.basePdf.padding : [0, 0, 0, 0], qt = St[gt], Zt = (rr) => {
162512
162517
  let Yt = ht.reduce((nr, tr) => nr + tr.length, 1), Kt = rr + Yt;
162513
- for (; ht.some((nr) => nr.find((tr) => tr.key === Kt)); )
162518
+ for (; ht.some((nr) => nr.find((tr) => tr.name === Kt)); )
162514
162519
  Yt++, Kt = rr + Yt;
162515
162520
  return Kt;
162516
162521
  }, ar = (rr, Yt, Kt) => Math.min(Math.max(rr, Yt), Kt), Jt = {
162517
162522
  id: uuid$6(),
162518
- key: Zt(rt("field")),
162519
162523
  ...Tt,
162524
+ name: Zt(rt("field")),
162520
162525
  position: {
162521
162526
  x: ar(Qt, Tt.position.x, qt.width - Ut - Tt.width),
162522
162527
  y: ar(Dt, Tt.position.y, qt.height - Vt - Tt.height)
@@ -162846,7 +162851,7 @@ const Designer$1 = Designer, { Text } = Typography$1, icons = {
162846
162851
  pageCursor: st,
162847
162852
  onChangePageCursor: lt
162848
162853
  });
162849
- const xt = ({ key: bt, value: Et }) => _ && _({ index: ot, key: bt, value: Et });
162854
+ const xt = ({ name: bt, value: Et }) => _ && _({ index: ot, name: bt, value: Et });
162850
162855
  return pt ? /* @__PURE__ */ jsxRuntimeExports.jsx(ErrorScreen$1, { size: $, error: pt }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(Root$1, { size: $, scale: gt, children: [
162851
162856
  /* @__PURE__ */ jsxRuntimeExports.jsx(
162852
162857
  CtlBar$1,
@@ -162880,7 +162885,7 @@ const Designer$1 = Designer, { Text } = Typography$1, icons = {
162880
162885
  pageSizes: dt,
162881
162886
  backgrounds: ht,
162882
162887
  renderSchema: ({ schema: bt, index: Et }) => {
162883
- const { key: St, readOnly: Bt } = bt, Ot = Bt ? String(bt.content) || "" : String(vt && vt[St] || "");
162888
+ const { name: St, readOnly: Bt } = bt, Ot = Bt ? String(bt.content) || "" : String(vt && vt[St] || "");
162884
162889
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
162885
162890
  Renderer$1,
162886
162891
  {
@@ -162898,7 +162903,7 @@ const Designer$1 = Designer, { Text } = Typography$1, icons = {
162898
162903
  const Rt = yt, kt = (vt == null ? void 0 : vt[St]) || "";
162899
162904
  if (Rt === kt)
162900
162905
  return;
162901
- xt({ key: St, value: Rt }), bt.type === "table" && (Ct = !0);
162906
+ xt({ name: St, value: Rt }), bt.type === "table" && (Ct = !0);
162902
162907
  } else {
162903
162908
  const Rt = ut[st].find(
162904
162909
  (kt) => kt.id === bt.id
@@ -162944,8 +162949,8 @@ class Form extends PreviewUI {
162944
162949
  size: this.size,
162945
162950
  inputs: this.inputs,
162946
162951
  onChangeInput: (s) => {
162947
- const { index: $, value: _, key: _e } = s;
162948
- this.onChangeInputCallback && this.onChangeInputCallback({ index: $, value: _, key: _e }), this.inputs && this.inputs[$] && this.inputs[$][_e] !== _ && (this.inputs[$][_e] = _, this.render());
162952
+ const { index: $, value: _, name: _e } = s;
162953
+ this.onChangeInputCallback && this.onChangeInputCallback({ index: $, value: _, name: _e }), this.inputs && this.inputs[$] && this.inputs[$][_e] !== _ && (this.inputs[$][_e] = _, this.render());
162949
162954
  }
162950
162955
  }
162951
162956
  )