@pdfme/schemas 3.3.0-dev.0 → 3.3.0-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.
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCacheKey = void 0;
4
+ const getCacheKey = (schema, input) => `${schema.type}${input}`;
5
+ exports.getCacheKey = getCacheKey;
6
+ //# sourceMappingURL=cacheKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheKey.js","sourceRoot":"","sources":["../../../../src/graphics/cacheKey.ts"],"names":[],"mappings":";;;AAEO,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;AAA1E,QAAA,WAAW,eAA+D"}
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readOnlyImage = void 0;
4
- const buffer_1 = require("buffer");
5
4
  const utils_js_1 = require("../utils.js");
6
5
  const constants_js_1 = require("../constants.js");
7
- const helper_js_1 = require("./helper.js");
6
+ const imagehelper_js_1 = require("./imagehelper.js");
7
+ const pdfHelper_js_1 = require("./pdfHelper.js");
8
8
  const px2mm = (px) => {
9
9
  // http://www.endmemo.com/sconvert/millimeterpixel.php
10
10
  const ratio = 0.26458333333333;
@@ -16,20 +16,24 @@ const defaultValue = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUgAAAGQBAMA
16
16
  const imageSchema = {
17
17
  pdf: async (arg) => {
18
18
  const { value, schema, pdfDoc, page, _cache } = arg;
19
- if (!value || !value.startsWith('data:image/'))
19
+ const isGraphicPdf = (0, pdfHelper_js_1.isPdf)(value);
20
+ const isImageOrPdf = value.startsWith('data:image/') || isGraphicPdf;
21
+ if (!value || !isImageOrPdf)
20
22
  return;
21
23
  const inputImageCacheKey = getCacheKey(schema, value);
22
24
  let image = _cache.get(inputImageCacheKey);
23
25
  if (!image) {
24
- const isPng = value.startsWith('data:image/png;');
25
- image = await (isPng ? pdfDoc.embedPng(value) : pdfDoc.embedJpg(value));
26
+ if (isGraphicPdf) {
27
+ [image] = await pdfDoc.embedPdf(value);
28
+ }
29
+ else {
30
+ const isPng = value.startsWith('data:image/png;');
31
+ image = await (isPng ? pdfDoc.embedPng(value) : pdfDoc.embedJpg(value));
32
+ }
26
33
  _cache.set(inputImageCacheKey, image);
27
34
  }
28
35
  const _schema = { ...schema, position: { ...schema.position } };
29
- const dataUriPrefix = ';base64,';
30
- const idx = value.indexOf(dataUriPrefix);
31
- const imgBase64 = value.substring(idx + dataUriPrefix.length, value.length);
32
- const dimension = (0, helper_js_1.imageSize)(buffer_1.Buffer.from(imgBase64, 'base64'));
36
+ const dimension = isGraphicPdf ? image.scale(1) : (0, imagehelper_js_1.getImageDimension)(value);
33
37
  const imageWidth = px2mm(dimension.width);
34
38
  const imageHeight = px2mm(dimension.height);
35
39
  const boxWidth = _schema.width;
@@ -50,9 +54,12 @@ const imageSchema = {
50
54
  const lProps = (0, utils_js_1.convertForPdfLayoutProps)({ schema: _schema, pageHeight });
51
55
  const { width, height, rotate, position, opacity } = lProps;
52
56
  const { x, y } = position;
53
- page.drawImage(image, { x, y, rotate, width, height, opacity });
57
+ const drawOptions = { x, y, rotate, width, height, opacity };
58
+ isGraphicPdf
59
+ ? page.drawPage(image, drawOptions)
60
+ : page.drawImage(image, drawOptions);
54
61
  },
55
- ui: (arg) => {
62
+ ui: async (arg) => {
56
63
  const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, theme, schema, } = arg;
57
64
  const editable = (0, utils_js_1.isEditable)(mode, schema);
58
65
  const isDefault = value === defaultValue;
@@ -74,6 +81,7 @@ const imageSchema = {
74
81
  rootElement.appendChild(container);
75
82
  // image tag
76
83
  if (value) {
84
+ let src = (0, pdfHelper_js_1.isPdf)(value) ? await (0, pdfHelper_js_1.pdfToImage)(arg) : value;
77
85
  const img = document.createElement('img');
78
86
  const imgStyle = {
79
87
  height: '100%',
@@ -82,7 +90,7 @@ const imageSchema = {
82
90
  objectFit: 'contain',
83
91
  };
84
92
  Object.assign(img.style, imgStyle);
85
- img.src = value;
93
+ img.src = src;
86
94
  container.appendChild(img);
87
95
  }
88
96
  // remove button
@@ -138,7 +146,7 @@ const imageSchema = {
138
146
  Object.assign(input.style, inputStyle);
139
147
  input.tabIndex = tabIndex || 0;
140
148
  input.type = 'file';
141
- input.accept = 'image/jpeg, image/png';
149
+ input.accept = 'image/jpeg, image/png, application/pdf';
142
150
  input.addEventListener('change', (event) => {
143
151
  const changeEvent = event;
144
152
  (0, utils_js_1.readFile)(changeEvent.target.files).then((result) => onChange && onChange(result));
@@ -1 +1 @@
1
- {"version":3,"file":"image.js","sourceRoot":"","sources":["../../../../src/graphics/image.ts"],"names":[],"mappings":";;;AAKA,mCAAgC;AAEhC,0CAA4F;AAC5F,kDAAkD;AAClD,2CAAwC;AAExC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAU,EAAE;IACnC,sDAAsD;IACtD,MAAM,KAAK,GAAG,gBAAgB,CAAC;IAC/B,OAAO,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;AAChF,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACnD,MAAM,YAAY,GAChB,wsHAAwsH,CAAC;AAI3sH,MAAM,WAAW,GAAwB;IACvC,GAAG,EAAE,KAAK,EAAE,GAAgC,EAAE,EAAE;QAC9C,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;QACp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C;YACH,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW,IAAI,WAAW,EAAE,CAAC,CAAC;YACnE,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;SAC1B;IACH,CAAC;IACD,SAAS,EAAE;QACT,MAAM,EAAE,EAAE;QACV,YAAY;QACZ,aAAa,EAAE;YACb,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YACxB,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,EAAE;YACV,uGAAuG;YACvG,4GAA4G;YAC5G,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,8BAAe;SACzB;KACF;CACF,CAAC;AAEF,kBAAe,WAAW,CAAC;AAEd,QAAA,aAAa,GAAwB;IAChD,GAAG,EAAE,WAAW,CAAC,GAAG;IACpB,EAAE,EAAE,WAAW,CAAC,EAAE;IAClB,SAAS,EAAE;QACT,GAAG,WAAW,CAAC,SAAS;QACxB,aAAa,EAAE;YACb,GAAG,WAAW,CAAC,SAAS,CAAC,aAAa;YACtC,IAAI,EAAE,eAAe;YACrB,QAAQ,EAAE,IAAI;YACd,aAAa,EAAE,YAAY;SAC5B;KACF;CACF,CAAC"}
@@ -1,3 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getImageDimension = void 0;
4
+ // ref: https://github.com/image-size/image-size ----------------------------
5
+ // The following code is adapted from the image-size code. Unnecessary formats and dependencies on Node have been removed.
6
+ const buffer_1 = require("buffer");
1
7
  const decoder = new TextDecoder();
2
8
  const toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end));
3
9
  const toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + ('0' + i.toString(16)).slice(-2), '');
@@ -97,7 +103,14 @@ function detector(input) {
97
103
  const keys = Object.keys(typeHandlers);
98
104
  return keys.find((key) => typeHandlers[key].validate(input));
99
105
  }
100
- export const imageSize = (imgBuffer) => {
106
+ const getImageDimension = (value) => {
107
+ const dataUriPrefix = ';base64,';
108
+ const idx = value.indexOf(dataUriPrefix);
109
+ const imgBase64 = value.substring(idx + dataUriPrefix.length, value.length);
110
+ return imageSize(buffer_1.Buffer.from(imgBase64, 'base64'));
111
+ };
112
+ exports.getImageDimension = getImageDimension;
113
+ const imageSize = (imgBuffer) => {
101
114
  const type = detector(imgBuffer);
102
115
  if (typeof type !== 'undefined' && type in typeHandlers) {
103
116
  const size = typeHandlers[type].calculate(imgBuffer);
@@ -108,4 +121,4 @@ export const imageSize = (imgBuffer) => {
108
121
  throw new TypeError('[@pdfme/schemas/images] Unsupported file type: ' + (type === undefined ? 'undefined' : type));
109
122
  };
110
123
  // ----------------------------
111
- //# sourceMappingURL=helper.js.map
124
+ //# sourceMappingURL=imagehelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imagehelper.js","sourceRoot":"","sources":["../../../../src/graphics/imagehelper.ts"],"names":[],"mappings":";;;AAAA,6EAA6E;AAC7E,0HAA0H;AAC1H,mCAAgC;AAOhC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,YAAY,GAAG,CAAC,KAAiB,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CACxE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AAE1C,MAAM,WAAW,GAAG,CAAC,KAAiB,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CACvE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE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C;AAEM,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAqC,EAAE;IACpF,MAAM,aAAa,GAAG,UAAU,CAAC;IACjC,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,GAAG,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5E,OAAO,SAAS,CAAC,eAAM,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC;AALW,QAAA,iBAAiB,qBAK5B;AAEF,MAAM,SAAS,GAAG,CAAC,SAAiB,EAAqC,EAAE;IACzE,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IAEjC,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,IAAI,YAAY,EAAE;QACvD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QACrD,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO,IAAI,CAAC;SACb;KACF;IAED,MAAM,IAAI,SAAS,CACjB,iDAAiD,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAC9F,CAAC;AACJ,CAAC,CAAC;AACF,+BAA+B"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pdfToImage = exports.isPdf = void 0;
4
+ const cacheKey_1 = require("./cacheKey");
5
+ function isPdf(content) {
6
+ return content.startsWith('data:application/pdf;');
7
+ }
8
+ exports.isPdf = isPdf;
9
+ /**
10
+ * convert pdf to blob image url
11
+ * @param content
12
+ */
13
+ const pdfToImage = async ({ schema, value, _cache, pdfJs, }) => {
14
+ // using value from cache to prevent rerending pdf to image
15
+ const pdfImageCacheKey = (0, cacheKey_1.getCacheKey)(schema, value);
16
+ const imageSrc = _cache.get(pdfImageCacheKey);
17
+ if (imageSrc)
18
+ return imageSrc;
19
+ const pdfDoc = await pdfJs.getDocument({ url: value }).promise;
20
+ const page = await pdfDoc.getPage(1);
21
+ const canvas = document.createElement('canvas');
22
+ const viewport = page.getViewport({ scale: 1 });
23
+ canvas.width = viewport.width;
24
+ canvas.height = viewport.height;
25
+ const canvasContext = canvas.getContext('2d');
26
+ await page.render({ canvasContext, viewport }).promise;
27
+ const image = await _canvasToObjectUrl(canvas);
28
+ _cache.set(pdfImageCacheKey, image);
29
+ return image;
30
+ };
31
+ exports.pdfToImage = pdfToImage;
32
+ /**
33
+ * convert canvas to blob url
34
+ * @param canvas
35
+ */
36
+ const _canvasToObjectUrl = async (canvas) => {
37
+ return new Promise((resolve, reject) => {
38
+ canvas.toBlob(function (blob) {
39
+ if (!blob) {
40
+ reject('inavlid canvas');
41
+ }
42
+ else {
43
+ const url = URL.createObjectURL(blob);
44
+ resolve(url);
45
+ }
46
+ });
47
+ });
48
+ };
49
+ //# sourceMappingURL=pdfHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdfHelper.js","sourceRoot":"","sources":["../../../../src/graphics/pdfHelper.ts"],"names":[],"mappings":";;;AACA,yCAAyC;AAGzC,SAAgB,KAAK,CAAC,OAAe;IACnC,OAAO,OAAO,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC;AACrD,CAAC;AAFD,sBAEC;AAED;;;GAGG;AACI,MAAM,UAAU,GAAG,KAAK,EAAE,EAC/B,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,GACsB,EAAmB,EAAE;IAChD,2DAA2D;IAC3D,MAAM,gBAAgB,GAAG,IAAA,sBAAW,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC9C,IAAI,QAAQ;QAAE,OAAO,QAA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CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const getCacheKey = (schema, input) => `${schema.type}${input}`;
2
+ //# sourceMappingURL=cacheKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheKey.js","sourceRoot":"","sources":["../../../../src/graphics/cacheKey.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC"}
@@ -1,7 +1,7 @@
1
- import { Buffer } from 'buffer';
2
1
  import { convertForPdfLayoutProps, addAlphaToHex, isEditable, readFile } from '../utils.js';
3
2
  import { DEFAULT_OPACITY } from '../constants.js';
4
- import { imageSize } from './helper.js';
3
+ import { getImageDimension } from './imagehelper.js';
4
+ import { isPdf, pdfToImage } from './pdfHelper.js';
5
5
  const px2mm = (px) => {
6
6
  // http://www.endmemo.com/sconvert/millimeterpixel.php
7
7
  const ratio = 0.26458333333333;
@@ -13,20 +13,24 @@ const defaultValue = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUgAAAGQBAMA
13
13
  const imageSchema = {
14
14
  pdf: async (arg) => {
15
15
  const { value, schema, pdfDoc, page, _cache } = arg;
16
- if (!value || !value.startsWith('data:image/'))
16
+ const isGraphicPdf = isPdf(value);
17
+ const isImageOrPdf = value.startsWith('data:image/') || isGraphicPdf;
18
+ if (!value || !isImageOrPdf)
17
19
  return;
18
20
  const inputImageCacheKey = getCacheKey(schema, value);
19
21
  let image = _cache.get(inputImageCacheKey);
20
22
  if (!image) {
21
- const isPng = value.startsWith('data:image/png;');
22
- image = await (isPng ? pdfDoc.embedPng(value) : pdfDoc.embedJpg(value));
23
+ if (isGraphicPdf) {
24
+ [image] = await pdfDoc.embedPdf(value);
25
+ }
26
+ else {
27
+ const isPng = value.startsWith('data:image/png;');
28
+ image = await (isPng ? pdfDoc.embedPng(value) : pdfDoc.embedJpg(value));
29
+ }
23
30
  _cache.set(inputImageCacheKey, image);
24
31
  }
25
32
  const _schema = { ...schema, position: { ...schema.position } };
26
- const dataUriPrefix = ';base64,';
27
- const idx = value.indexOf(dataUriPrefix);
28
- const imgBase64 = value.substring(idx + dataUriPrefix.length, value.length);
29
- const dimension = imageSize(Buffer.from(imgBase64, 'base64'));
33
+ const dimension = isGraphicPdf ? image.scale(1) : getImageDimension(value);
30
34
  const imageWidth = px2mm(dimension.width);
31
35
  const imageHeight = px2mm(dimension.height);
32
36
  const boxWidth = _schema.width;
@@ -47,9 +51,12 @@ const imageSchema = {
47
51
  const lProps = convertForPdfLayoutProps({ schema: _schema, pageHeight });
48
52
  const { width, height, rotate, position, opacity } = lProps;
49
53
  const { x, y } = position;
50
- page.drawImage(image, { x, y, rotate, width, height, opacity });
54
+ const drawOptions = { x, y, rotate, width, height, opacity };
55
+ isGraphicPdf
56
+ ? page.drawPage(image, drawOptions)
57
+ : page.drawImage(image, drawOptions);
51
58
  },
52
- ui: (arg) => {
59
+ ui: async (arg) => {
53
60
  const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, theme, schema, } = arg;
54
61
  const editable = isEditable(mode, schema);
55
62
  const isDefault = value === defaultValue;
@@ -71,6 +78,7 @@ const imageSchema = {
71
78
  rootElement.appendChild(container);
72
79
  // image tag
73
80
  if (value) {
81
+ let src = isPdf(value) ? await pdfToImage(arg) : value;
74
82
  const img = document.createElement('img');
75
83
  const imgStyle = {
76
84
  height: '100%',
@@ -79,7 +87,7 @@ const imageSchema = {
79
87
  objectFit: 'contain',
80
88
  };
81
89
  Object.assign(img.style, imgStyle);
82
- img.src = value;
90
+ img.src = src;
83
91
  container.appendChild(img);
84
92
  }
85
93
  // remove button
@@ -135,7 +143,7 @@ const imageSchema = {
135
143
  Object.assign(input.style, inputStyle);
136
144
  input.tabIndex = tabIndex || 0;
137
145
  input.type = 'file';
138
- input.accept = 'image/jpeg, image/png';
146
+ input.accept = 'image/jpeg, image/png, application/pdf';
139
147
  input.addEventListener('change', (event) => {
140
148
  const changeEvent = event;
141
149
  readFile(changeEvent.target.files).then((result) => onChange && onChange(result));
@@ -1 +1 @@
1
- {"version":3,"file":"image.js","sourceRoot":"","sources":["../../../../src/graphics/image.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAU,EAAE;IACnC,sDAAsD;IACtD,MAAM,KAAK,GAAG,gBAAgB,CAAC;IAC/B,OAAO,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;AAChF,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACnD,MAAM,YAAY,GAChB,wsHAAwsH,CAAC;AAI3sH,MAAM,WAAW,GAAwB;IACvC,GAAG,EAAE,KAAK,EAAE,GAAgC,EAAE,EAAE;QAC9C,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;QACpD,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC;YAAE,OAAO;QAEvD,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACtD,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAA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AC;YACnE,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;SAC1B;IACH,CAAC;IACD,SAAS,EAAE;QACT,MAAM,EAAE,EAAE;QACV,YAAY;QACZ,aAAa,EAAE;YACb,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YACxB,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,EAAE;YACV,uGAAuG;YACvG,4GAA4G;YAC5G,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,eAAe;SACzB;KACF;CACF,CAAC;AAEF,eAAe,WAAW,CAAC;AAE3B,MAAM,CAAC,MAAM,aAAa,GAAwB;IAChD,GAAG,EAAE,WAAW,CAAC,GAAG;IACpB,EAAE,EAAE,WAAW,CAAC,EAAE;IAClB,SAAS,EAAE;QACT,GAAG,WAAW,CAAC,SAAS;QACxB,aAAa,EAAE;YACb,GAAG,WAAW,CAAC,SAAS,CAAC,aAAa;YACtC,IAAI,EAAE,eAAe;YACrB,QAAQ,EAAE,IAAI;YACd,aAAa,EAAE,YAAY;SAC5B;KACF;CACF,CAAC"}
@@ -1,6 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.imageSize = void 0;
1
+ // ref: https://github.com/image-size/image-size ----------------------------
2
+ // The following code is adapted from the image-size code. Unnecessary formats and dependencies on Node have been removed.
3
+ import { Buffer } from 'buffer';
4
4
  const decoder = new TextDecoder();
5
5
  const toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end));
6
6
  const toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + ('0' + i.toString(16)).slice(-2), '');
@@ -100,6 +100,12 @@ function detector(input) {
100
100
  const keys = Object.keys(typeHandlers);
101
101
  return keys.find((key) => typeHandlers[key].validate(input));
102
102
  }
103
+ export const getImageDimension = (value) => {
104
+ const dataUriPrefix = ';base64,';
105
+ const idx = value.indexOf(dataUriPrefix);
106
+ const imgBase64 = value.substring(idx + dataUriPrefix.length, value.length);
107
+ return imageSize(Buffer.from(imgBase64, 'base64'));
108
+ };
103
109
  const imageSize = (imgBuffer) => {
104
110
  const type = detector(imgBuffer);
105
111
  if (typeof type !== 'undefined' && type in typeHandlers) {
@@ -110,6 +116,5 @@ const imageSize = (imgBuffer) => {
110
116
  }
111
117
  throw new TypeError('[@pdfme/schemas/images] Unsupported file type: ' + (type === undefined ? 'undefined' : type));
112
118
  };
113
- exports.imageSize = imageSize;
114
119
  // ----------------------------
115
- //# sourceMappingURL=helper.js.map
120
+ //# sourceMappingURL=imagehelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imagehelper.js","sourceRoot":"","sources":["../../../../src/graphics/imagehelper.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0HAA0H;AAC1H,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAOhC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,YAAY,GAAG,CAAC,KAAiB,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CACxE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AAE1C,MAAM,WAAW,GAAG,CAAC,KAAiB,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CACvE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE3F,MAAM,YAAY,GAAG,CAAC,KAAiB,EAAE,MAAM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G,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,GAAG,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5E,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,SAAiB,EAAqC,EAAE;IACzE,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IAEjC,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,IAAI,YAAY,EAAE;QACvD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QACrD,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO,IAAI,CAAC;SACb;KACF;IAED,MAAM,IAAI,SAAS,CACjB,iDAAiD,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAC9F,CAAC;AACJ,CAAC,CAAC;AACF,+BAA+B"}
@@ -0,0 +1,44 @@
1
+ import { getCacheKey } from './cacheKey';
2
+ export function isPdf(content) {
3
+ return content.startsWith('data:application/pdf;');
4
+ }
5
+ /**
6
+ * convert pdf to blob image url
7
+ * @param content
8
+ */
9
+ export const pdfToImage = async ({ schema, value, _cache, pdfJs, }) => {
10
+ // using value from cache to prevent rerending pdf to image
11
+ const pdfImageCacheKey = getCacheKey(schema, value);
12
+ const imageSrc = _cache.get(pdfImageCacheKey);
13
+ if (imageSrc)
14
+ return imageSrc;
15
+ const pdfDoc = await pdfJs.getDocument({ url: value }).promise;
16
+ const page = await pdfDoc.getPage(1);
17
+ const canvas = document.createElement('canvas');
18
+ const viewport = page.getViewport({ scale: 1 });
19
+ canvas.width = viewport.width;
20
+ canvas.height = viewport.height;
21
+ const canvasContext = canvas.getContext('2d');
22
+ await page.render({ canvasContext, viewport }).promise;
23
+ const image = await _canvasToObjectUrl(canvas);
24
+ _cache.set(pdfImageCacheKey, image);
25
+ return image;
26
+ };
27
+ /**
28
+ * convert canvas to blob url
29
+ * @param canvas
30
+ */
31
+ const _canvasToObjectUrl = async (canvas) => {
32
+ return new Promise((resolve, reject) => {
33
+ canvas.toBlob(function (blob) {
34
+ if (!blob) {
35
+ reject('inavlid canvas');
36
+ }
37
+ else {
38
+ const url = URL.createObjectURL(blob);
39
+ resolve(url);
40
+ }
41
+ });
42
+ });
43
+ };
44
+ //# sourceMappingURL=pdfHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdfHelper.js","sourceRoot":"","sources":["../../../../src/graphics/pdfHelper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,MAAM,UAAU,KAAK,CAAC,OAAe;IACnC,OAAO,OAAO,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,EAC/B,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,GACsB,EAAmB,EAAE;IAChD,2DAA2D;IAC3D,MAAM,gBAAgB,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC9C,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAE9B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC;IAC/D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAErC,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IAChD,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC9B,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAChC,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAE,CAAC;IAE/C,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;IACvD,MAAM,KAAK,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAE/C,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,kBAAkB,GAAG,KAAK,EAAE,MAAyB,EAAmB,EAAE;IAC9E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI;YAC1B,IAAI,CAAC,IAAI,EAAE;gBACT,MAAM,CAAC,gBAAgB,CAAC,CAAC;aAC1B;iBAAM;gBACL,MAAM,GAAG,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;gBACtC,OAAO,CAAC,GAAG,CAAC,CAAC;aACd;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Schema } from '@pdfme/common';
2
+ export declare const getCacheKey: (schema: Schema, input: string) => string;
@@ -1,6 +1,6 @@
1
1
  import type { Plugin } from '@pdfme/common';
2
2
  import type { Schema } from '@pdfme/common';
3
- interface ImageSchema extends Schema {
3
+ export interface ImageSchema extends Schema {
4
4
  }
5
5
  declare const imageSchema: Plugin<ImageSchema>;
6
6
  export default imageSchema;
@@ -0,0 +1,4 @@
1
+ export declare const getImageDimension: (value: string) => {
2
+ height: number;
3
+ width: number;
4
+ };
@@ -0,0 +1,8 @@
1
+ import { UIRenderProps } from '@pdfme/common';
2
+ import { ImageSchema } from './image';
3
+ export declare function isPdf(content: string): boolean;
4
+ /**
5
+ * convert pdf to blob image url
6
+ * @param content
7
+ */
8
+ export declare const pdfToImage: ({ schema, value, _cache, pdfJs, }: UIRenderProps<ImageSchema>) => Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/schemas",
3
- "version": "3.3.0-dev.0",
3
+ "version": "3.3.0-dev.3",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
@@ -0,0 +1,3 @@
1
+ import { Schema } from '@pdfme/common';
2
+
3
+ export const getCacheKey = (schema: Schema, input: string) => `${schema.type}${input}`;
@@ -1,13 +1,13 @@
1
1
  import type { ChangeEvent } from 'react';
2
- import type { PDFImage } from '@pdfme/pdf-lib';
2
+ import type { PDFImage, PDFEmbeddedPage } from '@pdfme/pdf-lib';
3
3
  import type { Plugin } from '@pdfme/common';
4
4
  import type { PDFRenderProps, Schema } from '@pdfme/common';
5
5
  import type * as CSS from 'csstype';
6
- import { Buffer } from 'buffer';
7
6
  import { UIRenderProps } from '@pdfme/common';
8
7
  import { convertForPdfLayoutProps, addAlphaToHex, isEditable, readFile } from '../utils.js';
9
8
  import { DEFAULT_OPACITY } from '../constants.js';
10
- import { imageSize } from './helper.js';
9
+ import { getImageDimension } from './imagehelper.js';
10
+ import { isPdf, pdfToImage } from './pdfHelper.js';
11
11
 
12
12
  const px2mm = (px: number): number => {
13
13
  // http://www.endmemo.com/sconvert/millimeterpixel.php
@@ -20,27 +20,29 @@ const fullSize = { width: '100%', height: '100%' };
20
20
  const defaultValue =
21
21
  'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUgAAAGQBAMAAAA+V+RCAAAAAXNSR0IArs4c6QA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iXKPgE6sD3L+BeBVITKdxaws5gOcRlUh8hM3GSoNjAoX8iRgJ6VOeezaMmIpiykiehHiEe+aN/tmuYuMxktuby4NnxYitzchOjkrDLR6cZWCYMrIiXc7zoUnj3nX1s8ZUTbqc5eWhMeLpoibvkdJmemBejSPVeIn6V4ssr0nXo7QzNCxp+th4KVKEQXkmRvLQcaxcANKPXTO+eICkgWvIW0JkEDsWyB4hkgbuBRKRQexcIBFJA/cCichg5o5x7VUg6SCzTMN0YYikiSvIL1SNDGLnRg0i6ch2g2PeNUTSmQvIBwIknAtZLXgWiEgKY+sdckTfQ9J+Yte4eUOIhHJkQ4mJABGJSvvGeiT1F7aMyzH9KJL2biyN6zdUjUTlr6l54vZDj+qQWPrXmWEi5KUEJBa//26RGRMuP449+jEkprV8TLPGgenjx8uomkj0N73+g6V/XjknAAAAAElFTkSuQmCC';
22
22
 
23
- interface ImageSchema extends Schema {}
23
+ export interface ImageSchema extends Schema {}
24
24
 
25
25
  const imageSchema: Plugin<ImageSchema> = {
26
26
  pdf: async (arg: PDFRenderProps<ImageSchema>) => {
27
27
  const { value, schema, pdfDoc, page, _cache } = arg;
28
- if (!value || !value.startsWith('data:image/')) return;
28
+ const isGraphicPdf = isPdf(value);
29
+ const isImageOrPdf = value.startsWith('data:image/') || isGraphicPdf;
30
+ if (!value || !isImageOrPdf) return;
29
31
 
30
32
  const inputImageCacheKey = getCacheKey(schema, value);
31
- let image = _cache.get(inputImageCacheKey) as PDFImage;
33
+ let image = _cache.get(inputImageCacheKey) as PDFImage | PDFEmbeddedPage;
32
34
  if (!image) {
33
- const isPng = value.startsWith('data:image/png;');
34
- image = await (isPng ? pdfDoc.embedPng(value) : pdfDoc.embedJpg(value));
35
+ if (isGraphicPdf) {
36
+ [image] = await pdfDoc.embedPdf(value);
37
+ } else {
38
+ const isPng = value.startsWith('data:image/png;');
39
+ image = await (isPng ? pdfDoc.embedPng(value) : pdfDoc.embedJpg(value));
40
+ }
35
41
  _cache.set(inputImageCacheKey, image);
36
42
  }
37
43
 
38
44
  const _schema = { ...schema, position: { ...schema.position } };
39
- const dataUriPrefix = ';base64,';
40
- const idx = value.indexOf(dataUriPrefix);
41
- const imgBase64 = value.substring(idx + dataUriPrefix.length, value.length);
42
- const dimension = imageSize(Buffer.from(imgBase64, 'base64'));
43
-
45
+ const dimension = isGraphicPdf ? image.scale(1) : getImageDimension(value);
44
46
  const imageWidth = px2mm(dimension.width);
45
47
  const imageHeight = px2mm(dimension.height);
46
48
  const boxWidth = _schema.width;
@@ -63,9 +65,13 @@ const imageSchema: Plugin<ImageSchema> = {
63
65
  const lProps = convertForPdfLayoutProps({ schema: _schema, pageHeight });
64
66
  const { width, height, rotate, position, opacity } = lProps;
65
67
  const { x, y } = position;
66
- page.drawImage(image, { x, y, rotate, width, height, opacity });
68
+
69
+ const drawOptions = { x, y, rotate, width, height, opacity };
70
+ isGraphicPdf
71
+ ? page.drawPage(image as PDFEmbeddedPage, drawOptions)
72
+ : page.drawImage(image as PDFImage, drawOptions);
67
73
  },
68
- ui: (arg: UIRenderProps<ImageSchema>) => {
74
+ ui: async (arg: UIRenderProps<ImageSchema>) => {
69
75
  const {
70
76
  value,
71
77
  rootElement,
@@ -99,6 +105,7 @@ const imageSchema: Plugin<ImageSchema> = {
99
105
 
100
106
  // image tag
101
107
  if (value) {
108
+ let src = isPdf(value) ? await pdfToImage(arg) : value;
102
109
  const img = document.createElement('img');
103
110
  const imgStyle: CSS.Properties = {
104
111
  height: '100%',
@@ -107,7 +114,7 @@ const imageSchema: Plugin<ImageSchema> = {
107
114
  objectFit: 'contain',
108
115
  };
109
116
  Object.assign(img.style, imgStyle);
110
- img.src = value;
117
+ img.src = src;
111
118
  container.appendChild(img);
112
119
  }
113
120
 
@@ -165,7 +172,7 @@ const imageSchema: Plugin<ImageSchema> = {
165
172
  Object.assign(input.style, inputStyle);
166
173
  input.tabIndex = tabIndex || 0;
167
174
  input.type = 'file';
168
- input.accept = 'image/jpeg, image/png';
175
+ input.accept = 'image/jpeg, image/png, application/pdf';
169
176
  input.addEventListener('change', (event: Event) => {
170
177
  const changeEvent = event as unknown as ChangeEvent<HTMLInputElement>;
171
178
  readFile(changeEvent.target.files).then((result) => onChange && onChange(result as string));
@@ -1,5 +1,7 @@
1
1
  // ref: https://github.com/image-size/image-size ----------------------------
2
2
  // The following code is adapted from the image-size code. Unnecessary formats and dependencies on Node have been removed.
3
+ import { Buffer } from 'buffer';
4
+
3
5
  type IImage = {
4
6
  validate: (input: Uint8Array) => boolean;
5
7
  calculate: (input: Uint8Array) => { width: number; height: number } | undefined;
@@ -130,7 +132,14 @@ function detector(input: Uint8Array): imageType | undefined {
130
132
  return keys.find((key: imageType) => typeHandlers[key].validate(input));
131
133
  }
132
134
 
133
- export const imageSize = (imgBuffer: Buffer): { height: number; width: number } => {
135
+ export const getImageDimension = (value: string): { height: number; width: number } => {
136
+ const dataUriPrefix = ';base64,';
137
+ const idx = value.indexOf(dataUriPrefix);
138
+ const imgBase64 = value.substring(idx + dataUriPrefix.length, value.length);
139
+ return imageSize(Buffer.from(imgBase64, 'base64'));
140
+ };
141
+
142
+ const imageSize = (imgBuffer: Buffer): { height: number; width: number } => {
134
143
  const type = detector(imgBuffer);
135
144
 
136
145
  if (typeof type !== 'undefined' && type in typeHandlers) {
@@ -0,0 +1,55 @@
1
+ import { Schema, UIRenderProps } from '@pdfme/common';
2
+ import { getCacheKey } from './cacheKey';
3
+ import { ImageSchema } from './image';
4
+
5
+ export function isPdf(content: string): boolean {
6
+ return content.startsWith('data:application/pdf;');
7
+ }
8
+
9
+ /**
10
+ * convert pdf to blob image url
11
+ * @param content
12
+ */
13
+ export const pdfToImage = async ({
14
+ schema,
15
+ value,
16
+ _cache,
17
+ pdfJs,
18
+ }: UIRenderProps<ImageSchema>): Promise<string> => {
19
+ // using value from cache to prevent rerending pdf to image
20
+ const pdfImageCacheKey = getCacheKey(schema, value);
21
+ const imageSrc = _cache.get(pdfImageCacheKey);
22
+ if (imageSrc) return imageSrc;
23
+
24
+ const pdfDoc = await pdfJs.getDocument({ url: value }).promise;
25
+ const page = await pdfDoc.getPage(1);
26
+
27
+ const canvas = document.createElement('canvas');
28
+ const viewport = page.getViewport({ scale: 1 });
29
+ canvas.width = viewport.width;
30
+ canvas.height = viewport.height;
31
+ const canvasContext = canvas.getContext('2d')!;
32
+
33
+ await page.render({ canvasContext, viewport }).promise;
34
+ const image = await _canvasToObjectUrl(canvas);
35
+
36
+ _cache.set(pdfImageCacheKey, image);
37
+ return image;
38
+ };
39
+
40
+ /**
41
+ * convert canvas to blob url
42
+ * @param canvas
43
+ */
44
+ const _canvasToObjectUrl = async (canvas: HTMLCanvasElement): Promise<string> => {
45
+ return new Promise((resolve, reject) => {
46
+ canvas.toBlob(function (blob) {
47
+ if (!blob) {
48
+ reject('inavlid canvas');
49
+ } else {
50
+ const url = URL.createObjectURL(blob);
51
+ resolve(url);
52
+ }
53
+ });
54
+ });
55
+ };
@@ -1 +0,0 @@
1
- {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../src/graphics/helper.ts"],"names":[],"mappings":";;;AAOA,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,YAAY,GAAG,CAAC,KAAiB,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CACxE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AAE1C,MAAM,WAAW,GAAG,CAAC,KAAiB,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CACvE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,C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