@pdfme/schemas 5.2.1 → 5.2.2-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.
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const svg_1 = __importDefault(require("../graphics/svg"));
7
+ const utils_js_1 = require("../utils.js");
8
+ const constants_js_1 = require("../constants.js");
9
+ const defaultStroke = 'currentColor';
10
+ const getCheckedIcon = (color = defaultStroke) => `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-square-check"><rect width="18" height="18" x="3" y="3" rx="0"/><path d="m9 12 2 2 4-4"/></svg>`;
11
+ const getUncheckedIcon = (color = defaultStroke) => `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-square"><rect width="18" height="18" x="3" y="3" rx="0"/></svg>`;
12
+ const getIcon = ({ value, color }) => value === 'true' ? getCheckedIcon(color) : getUncheckedIcon(color);
13
+ const schema = {
14
+ ui: (arg) => {
15
+ const { schema, value, onChange, rootElement, mode } = arg;
16
+ const container = document.createElement('div');
17
+ container.style.width = '100%';
18
+ container.style.height = '100%';
19
+ if ((0, utils_js_1.isEditable)(mode, schema)) {
20
+ container.addEventListener('click', () => {
21
+ onChange && onChange({ key: 'content', value: value === 'true' ? 'false' : 'true' });
22
+ });
23
+ }
24
+ void svg_1.default.ui({
25
+ ...arg,
26
+ rootElement: container,
27
+ mode: 'viewer',
28
+ value: getIcon({ value, color: schema.color }),
29
+ });
30
+ rootElement.appendChild(container);
31
+ },
32
+ pdf: (arg) => svg_1.default.pdf(Object.assign(arg, { value: getIcon({ value: arg.value, color: arg.schema.color }) })),
33
+ propPanel: {
34
+ schema: ({ i18n }) => ({
35
+ color: {
36
+ title: i18n('schemas.color'),
37
+ type: 'string',
38
+ widget: 'color',
39
+ required: true,
40
+ rules: [{ pattern: constants_js_1.HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
41
+ },
42
+ }),
43
+ defaultSchema: {
44
+ name: '',
45
+ type: 'checkbox',
46
+ content: 'false',
47
+ position: { x: 0, y: 0 },
48
+ width: 8,
49
+ height: 8,
50
+ color: '#000000',
51
+ },
52
+ },
53
+ icon: getCheckedIcon(),
54
+ };
55
+ exports.default = schema;
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/checkbox/index.ts"],"names":[],"mappings":";;;;;AAEA,0DAAkC;AAClC,0CAAyC;AACzC,kDAAoD;AAEpD,MAAM,aAAa,GAAG,cAAc,CAAC;AAErC,MAAM,cAAc,GAAG,CAAC,KAAK,GAAG,aAAa,EAAE,EAAE,CAC/C,0GAA0G,KAAK,uLAAuL,CAAC;AACzS,MAAM,gBAAgB,GAAG,CAAC,KAAK,GAAG,aAAa,EAAE,EAAE,CACjD,0GAA0G,KAAK,wJAAwJ,CAAC;AAM1Q,MAAM,OAAO,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAoC,EAAE,EAAE,CACrE,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAErE,MAAM,MAAM,GAAqB;IAC/B,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;QACV,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;QAC3D,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAChD,S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qBAAqB,CAAC,EAAE,CAAC;aAC9E;SACF,CAAC;QACF,aAAa,EAAE;YACb,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,OAAO;YAChB,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YACxB,KAAK,EAAE,CAAC;YACR,MAAM,EAAE,CAAC;YACT,KAAK,EAAE,SAAS;SACjB;KACF;IACD,IAAI,EAAE,cAAc,EAAE;CACvB,CAAC;AAEF,kBAAe,MAAM,CAAC"}
@@ -232,7 +232,7 @@ const getPlugin = ({ type, defaultFormat, icon, formatsByLang, }) => {
232
232
  type,
233
233
  content: (0, date_fns_1.format)(new Date(), defaultFormat),
234
234
  position: { x: 0, y: 0 },
235
- width: 70,
235
+ width: 50,
236
236
  height: 10,
237
237
  rotate: 0,
238
238
  alignment: constants_js_2.DEFAULT_ALIGNMENT,
@@ -75,7 +75,7 @@ const svgSchema = {
75
75
  content: defaultValue,
76
76
  position: { x: 0, y: 0 },
77
77
  width: 40,
78
- height: 40,
78
+ height: 50,
79
79
  },
80
80
  },
81
81
  icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-route"><circle cx="6" cy="19" r="3"/><path d="M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15"/><circle cx="18" cy="5" r="3"/></svg>',
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.select = exports.time = exports.date = exports.dateTime = exports.ellipse = exports.rectangle = exports.line = exports.barcodes = exports.table = exports.svg = exports.image = exports.multiVariableText = exports.text = exports.builtInPlugins = void 0;
6
+ exports.checkbox = exports.radioGroup = exports.select = exports.time = exports.date = exports.dateTime = exports.ellipse = exports.rectangle = exports.line = exports.barcodes = exports.table = exports.svg = exports.image = exports.multiVariableText = exports.text = exports.builtInPlugins = void 0;
7
7
  const index_1 = __importDefault(require("./multiVariableText/index"));
8
8
  exports.multiVariableText = index_1.default;
9
9
  const index_2 = __importDefault(require("./text/index"));
@@ -29,6 +29,10 @@ const time_1 = __importDefault(require("./date/time"));
29
29
  exports.time = time_1.default;
30
30
  const index_5 = __importDefault(require("./select/index"));
31
31
  exports.select = index_5.default;
32
+ const index_6 = __importDefault(require("./radioGroup/index"));
33
+ exports.radioGroup = index_6.default;
34
+ const index_7 = __importDefault(require("./checkbox/index"));
35
+ exports.checkbox = index_7.default;
32
36
  const builtInPlugins = { Text: index_2.default };
33
37
  exports.builtInPlugins = builtInPlugins;
34
38
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sEAA0D;AAmBxD,4BAnBK,eAAiB,CAmBL;AAlBnB,yDAAgC;AAiB9B,eAjBK,eAAI,CAiBL;AAhBN,6DAAqC;AAkBnC,gBAlBK,eAAK,CAkBL;AAjBP,yDAAiC;AAkB/B,cAlBK,aAAG,CAkBL;AAjBL,6DAAwC;AAmBtC,mBAnBK,eAAQ,CAmBL;AAlBV,yDAAiC;AAmB/B,eAnBK,cAAI,CAmBL;AAlBN,2DAAmC;AAgBjC,gBAhBK,eAAK,CAgBL;AAfP,4DAA6D;AAkB3D,0FAlBO,0BAAS,OAkBP;AACT,wFAnBkB,wBAAO,OAmBlB;AAlBT,+DAAuC;AAmBrC,mBAnBK,kBAAQ,CAmBL;AAlBV,uDAA+B;AAmB7B,eAnBK,cAAI,CAmBL;AAlBN,uDAA+B;AAmB7B,eAnBK,cAAI,CAmBL;AAlBN,2DAAoC;AAmBlC,iBAnBK,eAAM,CAmBL;AAjBR,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,eAAI,EAAE,CAAC;AAGpC,wCAAc"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sEAA0D;AAqBxD,4BArBK,eAAiB,CAqBL;AApBnB,yDAAgC;AAmB9B,eAnBK,eAAI,CAmBL;AAlBN,6DAAqC;AAoBnC,gBApBK,eAAK,CAoBL;AAnBP,yDAAiC;AAoB/B,cApBK,aAAG,CAoBL;AAnBL,6DAAwC;AAqBtC,mBArBK,eAAQ,CAqBL;AApBV,yDAAiC;AAqB/B,eArBK,cAAI,CAqBL;AApBN,2DAAmC;AAkBjC,gBAlBK,eAAK,CAkBL;AAjBP,4DAA6D;AAoB3D,0FApBO,0BAAS,OAoBP;AACT,wFArBkB,wBAAO,OAqBlB;AApBT,+DAAuC;AAqBrC,mBArBK,kBAAQ,CAqBL;AApBV,uDAA+B;AAqB7B,eArBK,cAAI,CAqBL;AApBN,uDAA+B;AAqB7B,eArBK,cAAI,CAqBL;AApBN,2DAAoC;AAqBlC,iBArBK,eAAM,CAqBL;AApBR,+DAA4C;AAqB1C,qBArBK,eAAU,CAqBL;AApBZ,6DAAwC;AAqBtC,mBArBK,eAAQ,CAqBL;AAnBV,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,eAAI,EAAE,CAAC;AAGpC,wCAAc"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const svg_1 = __importDefault(require("../graphics/svg"));
7
+ const utils_js_1 = require("../utils.js");
8
+ const constants_js_1 = require("../constants.js");
9
+ const defaultStroke = 'currentColor';
10
+ const getCheckedIcon = (color = defaultStroke) => `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-dot"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="1"/></svg>`;
11
+ const getUncheckedIcon = (color = defaultStroke) => `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle"><circle cx="12" cy="12" r="10"/></svg>`;
12
+ const getIcon = ({ value, color }) => value === 'true' ? getCheckedIcon(color) : getUncheckedIcon(color);
13
+ const eventEmitter = new EventTarget();
14
+ const radioButtonStates = new Map();
15
+ const eventListeners = new Map();
16
+ const schema = {
17
+ ui: (arg) => {
18
+ const { schema, value, onChange, rootElement, mode } = arg;
19
+ const container = document.createElement('div');
20
+ container.style.width = '100%';
21
+ container.style.height = '100%';
22
+ if (onChange) {
23
+ radioButtonStates.set(schema.name, { value, onChange });
24
+ }
25
+ const oldListener = eventListeners.get(schema.name);
26
+ if (oldListener) {
27
+ eventEmitter.removeEventListener(`group-${schema.group}`, oldListener);
28
+ }
29
+ const handleGroupEvent = (event) => {
30
+ const customEvent = event;
31
+ const selectedSchemaName = customEvent.detail;
32
+ if (selectedSchemaName !== schema.name) {
33
+ const radioButtonState = radioButtonStates.get(schema.name);
34
+ if (!radioButtonState)
35
+ return;
36
+ if (radioButtonState.value === 'true') {
37
+ radioButtonState.onChange({ key: 'content', value: 'false' });
38
+ }
39
+ }
40
+ };
41
+ eventListeners.set(schema.name, handleGroupEvent);
42
+ eventEmitter.addEventListener(`group-${schema.group}`, handleGroupEvent);
43
+ if ((0, utils_js_1.isEditable)(mode, schema)) {
44
+ container.addEventListener('click', () => {
45
+ if (value !== 'true' && onChange) {
46
+ onChange({ key: 'content', value: 'true' });
47
+ radioButtonStates.set(schema.name, { value: 'true', onChange });
48
+ eventEmitter.dispatchEvent(new CustomEvent(`group-${schema.group}`, { detail: schema.name }));
49
+ }
50
+ });
51
+ }
52
+ void svg_1.default.ui({
53
+ ...arg,
54
+ rootElement: container,
55
+ mode: 'viewer',
56
+ value: getIcon({ value, color: schema.color }),
57
+ });
58
+ rootElement.appendChild(container);
59
+ },
60
+ pdf: (arg) => svg_1.default.pdf(Object.assign(arg, { value: getIcon({ value: arg.value, color: arg.schema.color }) })),
61
+ propPanel: {
62
+ schema: ({ i18n }) => ({
63
+ color: {
64
+ title: i18n('schemas.color'),
65
+ type: 'string',
66
+ widget: 'color',
67
+ required: true,
68
+ rules: [{ pattern: constants_js_1.HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
69
+ },
70
+ group: {
71
+ title: i18n('schemas.radioGroup.groupName'),
72
+ type: 'string',
73
+ },
74
+ }),
75
+ defaultSchema: {
76
+ name: '',
77
+ type: 'radioGroup',
78
+ content: 'false',
79
+ position: { x: 0, y: 0 },
80
+ width: 8,
81
+ height: 8,
82
+ group: 'MyGroup',
83
+ color: '#000000',
84
+ },
85
+ },
86
+ icon: getCheckedIcon(),
87
+ };
88
+ exports.default = schema;
89
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/radioGroup/index.ts"],"names":[],"mappings":";;;;;AAEA,0DAAkC;AAClC,0CAAyC;AACzC,kDAAoD;AAEpD,MAAM,aAAa,GAAG,cAAc,CAAC;AAErC,MAAM,cAAc,GAAG,CAAC,KAAK,GAAG,aAAa,EAAE,EAAE,CAC/C,0GAA0G,KAAK,0KAA0K,CAAC;AAC5R,MAAM,gBAAgB,GAAG,CAAC,KAAK,GAAG,aAAa,EAAE,EAAE,CACjD,0GAA0G,KAAK,uIAAuI,CAAC;AAOzP,MAAM,OAAO,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAoC,EAAE,EAAE,CACrE,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAErE,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC;AAOvC,MA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EAAE,CAAC,EAAE,CAAC,CAAC;IAChG,SAAS,EAAE;QACT,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YACrB,KAAK,EAAE;gBACL,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC;gBAC5B,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,OAAO;gBACf,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,gCAAiB,EAAE,OAAO,EAAE,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC;aAC9E;YACD,KAAK,EAAE;gBACL,KAAK,EAAE,IAAI,CAAC,8BAA8B,CAAC;gBAC3C,IAAI,EAAE,QAAQ;aACf;SACF,CAAC;QACF,aAAa,EAAE;YACb,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,OAAO;YAChB,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YACxB,KAAK,EAAE,CAAC;YACR,MAAM,EAAE,CAAC;YACT,KAAK,EAAE,SAAS;YAChB,KAAK,EAAE,SAAS;SACjB;KACF;IACD,IAAI,EAAE,cAAc,EAAE;CACvB,CAAC;AAEF,kBAAe,MAAM,CAAC"}
@@ -43,7 +43,7 @@ const lineSchema = {
43
43
  type: 'line',
44
44
  position: { x: 0, y: 0 },
45
45
  width: 50,
46
- height: 1,
46
+ height: 0.5,
47
47
  rotate: 0,
48
48
  opacity: 1,
49
49
  readOnly: true,
@@ -1 +1 @@
1
- {"version":3,"file":"line.js","sourceRoot":"","sources":["../../../../src/shapes/line.ts"],"names":[],"mappings":";;AACA,0CAAuF;AACvF,kDAAoD;AAEpD,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAMrC,MAAM,UAAU,GAAuB;IACrC,GAAG,EAAE,CAAC,GAA+B,EAAE,EAAE;QACvC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,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AAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1C,GAAG,CAAC,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,KAAK,IAAI,aAAa,CAAC;QAC1D,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;QACzB,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;QAC1B,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IACD,SAAS,EAAE;QACT,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YACrB,KAAK,EAAE;gBACL,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC;gBAC5B,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,OAAO;gBACf,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,gCAAiB,EAAE,OAAO,EAAE,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC;aAC9E;SACF,CAAC;QACF,aAAa,EAAE;YACb,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YACxB,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,kBAAkB;SAC1B;KACF;IACD,IAAI,EAAC,6OAA6O;CACnP,CAAC;AACF,kBAAe,UAAU,CAAC"}
@@ -0,0 +1,51 @@
1
+ import svg from '../graphics/svg';
2
+ import { isEditable } from '../utils.js';
3
+ import { HEX_COLOR_PATTERN } from '../constants.js';
4
+ const defaultStroke = 'currentColor';
5
+ const getCheckedIcon = (color = defaultStroke) => `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-square-check"><rect width="18" height="18" x="3" y="3" rx="0"/><path d="m9 12 2 2 4-4"/></svg>`;
6
+ const getUncheckedIcon = (color = defaultStroke) => `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-square"><rect width="18" height="18" x="3" y="3" rx="0"/></svg>`;
7
+ const getIcon = ({ value, color }) => value === 'true' ? getCheckedIcon(color) : getUncheckedIcon(color);
8
+ const schema = {
9
+ ui: (arg) => {
10
+ const { schema, value, onChange, rootElement, mode } = arg;
11
+ const container = document.createElement('div');
12
+ container.style.width = '100%';
13
+ container.style.height = '100%';
14
+ if (isEditable(mode, schema)) {
15
+ container.addEventListener('click', () => {
16
+ onChange && onChange({ key: 'content', value: value === 'true' ? 'false' : 'true' });
17
+ });
18
+ }
19
+ void svg.ui({
20
+ ...arg,
21
+ rootElement: container,
22
+ mode: 'viewer',
23
+ value: getIcon({ value, color: schema.color }),
24
+ });
25
+ rootElement.appendChild(container);
26
+ },
27
+ pdf: (arg) => svg.pdf(Object.assign(arg, { value: getIcon({ value: arg.value, color: arg.schema.color }) })),
28
+ propPanel: {
29
+ schema: ({ i18n }) => ({
30
+ color: {
31
+ title: i18n('schemas.color'),
32
+ type: 'string',
33
+ widget: 'color',
34
+ required: true,
35
+ rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
36
+ },
37
+ }),
38
+ defaultSchema: {
39
+ name: '',
40
+ type: 'checkbox',
41
+ content: 'false',
42
+ position: { x: 0, y: 0 },
43
+ width: 8,
44
+ height: 8,
45
+ color: '#000000',
46
+ },
47
+ },
48
+ icon: getCheckedIcon(),
49
+ };
50
+ export default schema;
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/checkbox/index.ts"],"names":[],"mappings":"AAEA,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defaultFormat),
228
228
  position: { x: 0, y: 0 },
229
- width: 70,
229
+ width: 50,
230
230
  height: 10,
231
231
  rotate: 0,
232
232
  alignment: DEFAULT_ALIGNMENT,
@@ -73,7 +73,7 @@ const svgSchema = {
73
73
  content: defaultValue,
74
74
  position: { x: 0, y: 0 },
75
75
  width: 40,
76
- height: 40,
76
+ height: 50,
77
77
  },
78
78
  },
79
79
  icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-route"><circle cx="6" cy="19" r="3"/><path d="M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15"/><circle cx="18" cy="5" r="3"/></svg>',
@@ -10,8 +10,10 @@ import dateTime from './date/dateTime';
10
10
  import date from './date/date';
11
11
  import time from './date/time';
12
12
  import select from './select/index';
13
+ import radioGroup from './radioGroup/index';
14
+ import checkbox from './checkbox/index';
13
15
  const builtInPlugins = { Text: text };
14
16
  export { builtInPlugins,
15
17
  // schemas
16
- text, multiVariableText, image, svg, table, barcodes, line, rectangle, ellipse, dateTime, date, time, select, };
18
+ text, multiVariableText, image, svg, table, barcodes, line, rectangle, ellipse, dateTime, date, time, select, radioGroup, checkbox, };
17
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAC1D,OAAO,IAAI,MAAM,cAAc,CAAC;AAChC,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,GAAG,MAAM,gBAAgB,CAAC;AACjC,OAAO,QAAQ,MAAM,kBAAkB,CAAC;AACxC,OAAO,IAAI,MAAM,eAAe,CAAC;AACjC,OAAO,KAAK,MAAM,gBAAgB,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,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AI,EACJ,SAAS,EACT,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,UAAU,EACV,QAAQ,GACT,CAAC"}
@@ -0,0 +1,84 @@
1
+ import svg from '../graphics/svg';
2
+ import { isEditable } from '../utils.js';
3
+ import { HEX_COLOR_PATTERN } from '../constants.js';
4
+ const defaultStroke = 'currentColor';
5
+ const getCheckedIcon = (color = defaultStroke) => `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-dot"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="1"/></svg>`;
6
+ const getUncheckedIcon = (color = defaultStroke) => `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle"><circle cx="12" cy="12" r="10"/></svg>`;
7
+ const getIcon = ({ value, color }) => value === 'true' ? getCheckedIcon(color) : getUncheckedIcon(color);
8
+ const eventEmitter = new EventTarget();
9
+ const radioButtonStates = new Map();
10
+ const eventListeners = new Map();
11
+ const schema = {
12
+ ui: (arg) => {
13
+ const { schema, value, onChange, rootElement, mode } = arg;
14
+ const container = document.createElement('div');
15
+ container.style.width = '100%';
16
+ container.style.height = '100%';
17
+ if (onChange) {
18
+ radioButtonStates.set(schema.name, { value, onChange });
19
+ }
20
+ const oldListener = eventListeners.get(schema.name);
21
+ if (oldListener) {
22
+ eventEmitter.removeEventListener(`group-${schema.group}`, oldListener);
23
+ }
24
+ const handleGroupEvent = (event) => {
25
+ const customEvent = event;
26
+ const selectedSchemaName = customEvent.detail;
27
+ if (selectedSchemaName !== schema.name) {
28
+ const radioButtonState = radioButtonStates.get(schema.name);
29
+ if (!radioButtonState)
30
+ return;
31
+ if (radioButtonState.value === 'true') {
32
+ radioButtonState.onChange({ key: 'content', value: 'false' });
33
+ }
34
+ }
35
+ };
36
+ eventListeners.set(schema.name, handleGroupEvent);
37
+ eventEmitter.addEventListener(`group-${schema.group}`, handleGroupEvent);
38
+ if (isEditable(mode, schema)) {
39
+ container.addEventListener('click', () => {
40
+ if (value !== 'true' && onChange) {
41
+ onChange({ key: 'content', value: 'true' });
42
+ radioButtonStates.set(schema.name, { value: 'true', onChange });
43
+ eventEmitter.dispatchEvent(new CustomEvent(`group-${schema.group}`, { detail: schema.name }));
44
+ }
45
+ });
46
+ }
47
+ void svg.ui({
48
+ ...arg,
49
+ rootElement: container,
50
+ mode: 'viewer',
51
+ value: getIcon({ value, color: schema.color }),
52
+ });
53
+ rootElement.appendChild(container);
54
+ },
55
+ pdf: (arg) => svg.pdf(Object.assign(arg, { value: getIcon({ value: arg.value, color: arg.schema.color }) })),
56
+ propPanel: {
57
+ schema: ({ i18n }) => ({
58
+ color: {
59
+ title: i18n('schemas.color'),
60
+ type: 'string',
61
+ widget: 'color',
62
+ required: true,
63
+ rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
64
+ },
65
+ group: {
66
+ title: i18n('schemas.radioGroup.groupName'),
67
+ type: 'string',
68
+ },
69
+ }),
70
+ defaultSchema: {
71
+ name: '',
72
+ type: 'radioGroup',
73
+ content: 'false',
74
+ position: { x: 0, y: 0 },
75
+ width: 8,
76
+ height: 8,
77
+ group: 'MyGroup',
78
+ color: '#000000',
79
+ },
80
+ },
81
+ icon: getCheckedIcon(),
82
+ };
83
+ export default schema;
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/radioGroup/index.ts"],"names":[],"mappings":"AAEA,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,aAAa,GAAG,cAAc,CAAC;AAErC,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@@ -41,7 +41,7 @@ const lineSchema = {
41
41
  type: 'line',
42
42
  position: { x: 0, y: 0 },
43
43
  width: 50,
44
- height: 1,
44
+ height: 0.5,
45
45
  rotate: 0,
46
46
  opacity: 1,
47
47
  readOnly: true,
@@ -1 +1 @@
1
- {"version":3,"file":"line.js","sourceRoot":"","sources":["../../../../src/shapes/line.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAMrC,MAAM,UAAU,GAAuB;IACrC,GAAG,EAAE,CAAC,GAA+B,EAAE,EAAE;QACvC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;QACtC,IAAI,MAAM,CAAC,KAAK,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK;YAAE,OAAO;QACvE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QACpC,MAAM,EACJ,KAAK,EACL,MAAM,EACN,MAAM,EACN,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAClB,OAAO,GACR,GAAG,wBAAwB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC;QAClF,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC;QACtD,IAAI,CAAC,QAAQ,CAAC;YACZ,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,E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b,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YACxB,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,kBAAkB;SAC1B;KACF;IACD,IAAI,EAAC,6OAA6O;CACnP,CAAC;AACF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Plugin } from '@pdfme/common';
2
+ import { Schema } from '@pdfme/common';
3
+ interface Checkbox extends Schema {
4
+ color: string;
5
+ }
6
+ declare const schema: Plugin<Checkbox>;
7
+ export default schema;
@@ -10,7 +10,9 @@ import dateTime from './date/dateTime';
10
10
  import date from './date/date';
11
11
  import time from './date/time';
12
12
  import select from './select/index';
13
+ import radioGroup from './radioGroup/index';
14
+ import checkbox from './checkbox/index';
13
15
  declare const builtInPlugins: {
14
16
  Text: import("@pdfme/common").Plugin<import("./text/types").TextSchema>;
15
17
  };
16
- export { builtInPlugins, text, multiVariableText, image, svg, table, barcodes, line, rectangle, ellipse, dateTime, date, time, select, };
18
+ export { builtInPlugins, text, multiVariableText, image, svg, table, barcodes, line, rectangle, ellipse, dateTime, date, time, select, radioGroup, checkbox, };
@@ -0,0 +1,8 @@
1
+ import { Plugin } from '@pdfme/common';
2
+ import { Schema } from '@pdfme/common';
3
+ interface RadioGroup extends Schema {
4
+ group: string;
5
+ color: string;
6
+ }
7
+ declare const schema: Plugin<RadioGroup>;
8
+ export default schema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/schemas",
3
- "version": "5.2.1",
3
+ "version": "5.2.2-dev.1",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
@@ -0,0 +1,68 @@
1
+ import { Plugin } from '@pdfme/common';
2
+ import { Schema } from '@pdfme/common';
3
+ import svg from '../graphics/svg';
4
+ import { isEditable } from '../utils.js';
5
+ import { HEX_COLOR_PATTERN } from '../constants.js';
6
+
7
+ const defaultStroke = 'currentColor';
8
+
9
+ const getCheckedIcon = (color = defaultStroke) =>
10
+ `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-square-check"><rect width="18" height="18" x="3" y="3" rx="0"/><path d="m9 12 2 2 4-4"/></svg>`;
11
+ const getUncheckedIcon = (color = defaultStroke) =>
12
+ `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-square"><rect width="18" height="18" x="3" y="3" rx="0"/></svg>`;
13
+
14
+ interface Checkbox extends Schema {
15
+ color: string;
16
+ }
17
+
18
+ const getIcon = ({ value, color }: { value: string; color: string }) =>
19
+ value === 'true' ? getCheckedIcon(color) : getUncheckedIcon(color);
20
+
21
+ const schema: Plugin<Checkbox> = {
22
+ ui: (arg) => {
23
+ const { schema, value, onChange, rootElement, mode } = arg;
24
+ const container = document.createElement('div');
25
+ container.style.width = '100%';
26
+ container.style.height = '100%';
27
+
28
+ if (isEditable(mode, schema)) {
29
+ container.addEventListener('click', () => {
30
+ onChange && onChange({ key: 'content', value: value === 'true' ? 'false' : 'true' });
31
+ });
32
+ }
33
+
34
+ void svg.ui({
35
+ ...arg,
36
+ rootElement: container,
37
+ mode: 'viewer',
38
+ value: getIcon({ value, color: schema.color }),
39
+ });
40
+
41
+ rootElement.appendChild(container);
42
+ },
43
+ pdf: (arg) =>
44
+ svg.pdf(Object.assign(arg, { value: getIcon({ value: arg.value, color: arg.schema.color }) })),
45
+ propPanel: {
46
+ schema: ({ i18n }) => ({
47
+ color: {
48
+ title: i18n('schemas.color'),
49
+ type: 'string',
50
+ widget: 'color',
51
+ required: true,
52
+ rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
53
+ },
54
+ }),
55
+ defaultSchema: {
56
+ name: '',
57
+ type: 'checkbox',
58
+ content: 'false',
59
+ position: { x: 0, y: 0 },
60
+ width: 8,
61
+ height: 8,
62
+ color: '#000000',
63
+ },
64
+ },
65
+ icon: getCheckedIcon(),
66
+ };
67
+
68
+ export default schema;
@@ -277,7 +277,7 @@ export const getPlugin = ({
277
277
  type,
278
278
  content: format(new Date(), defaultFormat),
279
279
  position: { x: 0, y: 0 },
280
- width: 70,
280
+ width: 50,
281
281
  height: 10,
282
282
  rotate: 0,
283
283
  alignment: DEFAULT_ALIGNMENT,
@@ -77,7 +77,7 @@ const svgSchema: Plugin<SVGSchema> = {
77
77
  content: defaultValue,
78
78
  position: { x: 0, y: 0 },
79
79
  width: 40,
80
- height: 40,
80
+ height: 50,
81
81
  },
82
82
  },
83
83
  icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-route"><circle cx="6" cy="19" r="3"/><path d="M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15"/><circle cx="18" cy="5" r="3"/></svg>',
package/src/index.ts CHANGED
@@ -10,6 +10,8 @@ import dateTime from './date/dateTime';
10
10
  import date from './date/date';
11
11
  import time from './date/time';
12
12
  import select from './select/index';
13
+ import radioGroup from './radioGroup/index';
14
+ import checkbox from './checkbox/index';
13
15
 
14
16
  const builtInPlugins = { Text: text };
15
17
 
@@ -29,4 +31,6 @@ export {
29
31
  date,
30
32
  time,
31
33
  select,
34
+ radioGroup,
35
+ checkbox,
32
36
  };
@@ -0,0 +1,114 @@
1
+ import { Plugin } from '@pdfme/common';
2
+ import { Schema } from '@pdfme/common';
3
+ import svg from '../graphics/svg';
4
+ import { isEditable } from '../utils.js';
5
+ import { HEX_COLOR_PATTERN } from '../constants.js';
6
+
7
+ const defaultStroke = 'currentColor';
8
+
9
+ const getCheckedIcon = (color = defaultStroke) =>
10
+ `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-dot"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="1"/></svg>`;
11
+ const getUncheckedIcon = (color = defaultStroke) =>
12
+ `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle"><circle cx="12" cy="12" r="10"/></svg>`;
13
+
14
+ interface RadioGroup extends Schema {
15
+ group: string;
16
+ color: string;
17
+ }
18
+
19
+ const getIcon = ({ value, color }: { value: string; color: string }) =>
20
+ value === 'true' ? getCheckedIcon(color) : getUncheckedIcon(color);
21
+
22
+ const eventEmitter = new EventTarget();
23
+
24
+ interface RadioButtonState {
25
+ value: string;
26
+ onChange: (arg: { key: string; value: string }) => void;
27
+ }
28
+
29
+ const radioButtonStates = new Map<string, RadioButtonState>();
30
+ const eventListeners = new Map<string, EventListener>();
31
+
32
+ const schema: Plugin<RadioGroup> = {
33
+ ui: (arg) => {
34
+ const { schema, value, onChange, rootElement, mode } = arg;
35
+ const container = document.createElement('div');
36
+ container.style.width = '100%';
37
+ container.style.height = '100%';
38
+
39
+ if (onChange) {
40
+ radioButtonStates.set(schema.name, { value, onChange });
41
+ }
42
+
43
+ const oldListener = eventListeners.get(schema.name);
44
+ if (oldListener) {
45
+ eventEmitter.removeEventListener(`group-${schema.group}`, oldListener);
46
+ }
47
+
48
+ const handleGroupEvent = (event: Event) => {
49
+ const customEvent = event as CustomEvent<string>;
50
+ const selectedSchemaName = customEvent.detail;
51
+ if (selectedSchemaName !== schema.name) {
52
+ const radioButtonState = radioButtonStates.get(schema.name);
53
+ if (!radioButtonState) return;
54
+ if (radioButtonState.value === 'true') {
55
+ radioButtonState.onChange({ key: 'content', value: 'false' });
56
+ }
57
+ }
58
+ };
59
+
60
+ eventListeners.set(schema.name, handleGroupEvent);
61
+ eventEmitter.addEventListener(`group-${schema.group}`, handleGroupEvent);
62
+
63
+ if (isEditable(mode, schema)) {
64
+ container.addEventListener('click', () => {
65
+ if (value !== 'true' && onChange) {
66
+ onChange({ key: 'content', value: 'true' });
67
+ radioButtonStates.set(schema.name, { value: 'true', onChange });
68
+ eventEmitter.dispatchEvent(
69
+ new CustomEvent(`group-${schema.group}`, { detail: schema.name })
70
+ );
71
+ }
72
+ });
73
+ }
74
+
75
+ void svg.ui({
76
+ ...arg,
77
+ rootElement: container,
78
+ mode: 'viewer',
79
+ value: getIcon({ value, color: schema.color }),
80
+ });
81
+
82
+ rootElement.appendChild(container);
83
+ },
84
+ pdf: (arg) =>
85
+ svg.pdf(Object.assign(arg, { value: getIcon({ value: arg.value, color: arg.schema.color }) })),
86
+ propPanel: {
87
+ schema: ({ i18n }) => ({
88
+ color: {
89
+ title: i18n('schemas.color'),
90
+ type: 'string',
91
+ widget: 'color',
92
+ required: true,
93
+ rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
94
+ },
95
+ group: {
96
+ title: i18n('schemas.radioGroup.groupName'),
97
+ type: 'string',
98
+ },
99
+ }),
100
+ defaultSchema: {
101
+ name: '',
102
+ type: 'radioGroup',
103
+ content: 'false',
104
+ position: { x: 0, y: 0 },
105
+ width: 8,
106
+ height: 8,
107
+ group: 'MyGroup',
108
+ color: '#000000',
109
+ },
110
+ },
111
+ icon: getCheckedIcon(),
112
+ };
113
+
114
+ export default schema;
@@ -53,7 +53,7 @@ const lineSchema: Plugin<LineSchema> = {
53
53
  type: 'line',
54
54
  position: { x: 0, y: 0 },
55
55
  width: 50,
56
- height: 1,
56
+ height: 0.5,
57
57
  rotate: 0,
58
58
  opacity: 1,
59
59
  readOnly: true,