| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 5× 5× 5× 1× 1× 1× 1× 4× 3× 5× 1× 1× 1× 5× 1× 1× 1× 5× 1× 1× 1× 1× 1× 1× 5× 1× 5× 1× 5× 1× 1× 1× 60× 60× 60× 60× 60× 60× 60× 60× 60× 60× 60× 60× 1× 60× 2× 60× 60× 60× 1× 120× 120× 58× 62× 3× 62× 2× 62× 62× 58× 62× 62× 62× 62× 62× 1× 122× 60× 60× 62× 62× 62× 62× 62× 62× 62× 62× 62× 1× 63× 63× 63× 411× 63× 1× 167× 5× 167× 1× 63× 63× 63× 62× 63× 1× 1× 1× 62× 62× 62× 62× 62× 398× 398× 398× 105× 398× 398× 2× 398× 1× 185× 62× 62× 1× 105× 1× 104× 232× 232× 103× 1× 1× 3× 1× 2× 1× 3× 1× 105× 105× 105× 215× 105× 1× 104× 104× 104× 104× 1× 103× 2× 101× 101× 101× 101× 62× 7× 11× 6× 2× 5× 7× 1× 62× 7× 11× 6× 2× 5× 7× 7× 1× 2× 2× 1× 105× 1× 21× 21× 4× 21× 21× 21× 60× 60× 60× 4× 56× 21× 21× 21× 21× 21× 4× 4× 21× 21× 1× 7× 1× 47× 1× 7× 1× 67× 133× 133× 5× 2× 3× 65× 128× 128× 7× 3× 4× 62× 4× 2× 2× 60× 8× 8× 1× 7× 21× 21× 9× 4× 5× 3× 55× 1× 62× 3× 59× 59× 59× 42× 17× 17× 1× 51× 51× 51× 6× 1× 5× 1× 4× 2× 2× 47× 70× 36× 34× 34× 20× 14× 14× 47× 17× 14× 2× 12× 15× 15× 2× 1× 1× 14× 4× 10× 5× 5× 5× 9× 9× 4× 5× 5× 5× 5× 3× 2× 2× 8× 8× 4× 4× 3× 4× 2× 1× 1× 3× 9× 9× 5× 4× 2× 1× 1× 3× 2× 1× 1× 2× 4× 3× 1× 1× 1× 1× 7× 7× 7× 7× 72× 7× 2× 2× 1× 1× 1× 2× 7× 7× 7× 7× 7× 7× 7× 1× 11× 11× 3× 1× 2× 10× 2× 1× 1× 9× 2× 1× 1× 8× 4× 2× 2× 6× 2× 1× 1× 5× 3× 1× 2× 4× 2× 2× 2× 1× 1× 3× 1× 2× 2× 1× 6× 6× 6× 3× 3× 1× 2× 2× 1× 2× 25× 2× 1× 5× 2× 3× 3× 1× 2× 4× 1× 7× 7× 7× 9× 7× 1× 6× 6× 6× 2× 2× 2× 4× 2× 2× 1× 120× 120× 120× 1× 147× 1× 40× 1× 65× 1× 1× 1× 1× 1× 60× 1× 1× 1× 1× 1× | /* istanbul ignore next */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; /* istanbul ignore next */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /* istanbul ignore next */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; /* istanbul ignore next */ var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; define(["require", "exports", "@syncfusion/ej2-base", "../../gs1/gs1-parser"], function (require, exports, ej2_base_1, gs1_parser_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var kindByModuleName = { barcode: 'barcode', QRCodeGenerator: 'qrcode', DataMatrixGenerator: 'datamatrix', PDF417Generator: 'pdf417', DotCodeGenerator: 'dotcode' }; var barcodeTypeRules = { Code39: 'Upper case letters A-Z, digits 0-9, space and - . $ / + %', Code39Extension: 'Full ASCII (encoded with Code 39 shift characters)', Code128: 'Full ASCII; code sets are chosen automatically', Code128A: 'Upper case letters, digits and ASCII control characters', Code128B: 'Upper and lower case letters, digits and printable ASCII', Code128C: 'Digits only, in pairs (even length)', Codabar: 'Digits and - $ : / . + ; optional start/stop characters A-D', Ean8: 'Digits only: 7 digits plus check digit (8 digits)', Ean13: 'Digits only: 12 digits plus check digit (13 digits)', UpcA: 'Digits only: 11 digits plus check digit (12 digits)', UpcE: 'Digits only: compressed UPC-A', Code11: 'Digits and -', Code93: 'Upper case letters A-Z, digits 0-9, space and - . $ / + %', Code93Extension: 'Full ASCII (encoded with Code 93 shift characters)', Code32: 'Digits only (Italian pharmacode)', GS1Code128: 'GS1 data in bracketed AI notation, e.g. (01)09506000134376(10)ABC123', ITF14: 'Digits only: 13 digits plus check digit (14 digits); supports bearerBarWidth', GS1DataBarOmnidirectional: 'Digits only: GTIN', GS1DataBarTruncated: 'Digits only: GTIN', GS1DataBarStacked: 'Digits only: GTIN', GS1DataBarStackedOmnidirectional: 'Digits only: GTIN', GS1DataBarLimited: 'Digits only: GTIN with indicator digit 0 or 1', GS1DataBarExpanded: 'GS1 data in bracketed AI notation', GS1DataBarExpandedStacked: 'GS1 data in bracketed AI notation; supports segmentsPerRow' }; var webMcpBarcodeTypes = Object.keys(barcodeTypeRules); var twoDimensionalRules = { qrcode: { QRCode: 'Any text (numeric, alphanumeric, byte and kanji modes are chosen automatically). Set enableGS1 for GS1 QR Code.' }, datamatrix: { DataMatrix: 'ASCII, ASCIINumeric or Base256 content. Set enableGS1 for GS1 DataMatrix (ASCII only).' }, pdf417: { PDF417: 'Text, numeric or byte content, with configurable columns, rows and error correction level.' }, dotcode: { DotCode: 'Any text or bytes. Set enableGS1 for GS1 DotCode.' } }; var RESULT_SCHEMA = { type: 'object', properties: { success: { type: 'boolean' }, data: { type: 'object' }, message: { type: 'string' } } }; var COLOR_PROPS = { foreColor: { type: 'string', description: 'The foreground (bar or module) color, hex or named' }, backgroundColor: { type: 'string', description: 'The background color, hex or named' } }; var SIZE_PROPS = { width: { type: ['string', 'number'], description: 'Width as a CSS unit string (e.g. "300px", "100%") or pixels' }, height: { type: ['string', 'number'], description: 'Height as a CSS unit string (e.g. "150px", "100%") or pixels' } }; var MARGIN_SCHEMA = { type: 'object', description: 'Margin in pixels around the code', properties: { left: { type: 'number' }, right: { type: 'number' }, top: { type: 'number' }, bottom: { type: 'number' } } }; var MODE_PROP = { type: 'string', enum: ['SVG', 'Canvas'], description: 'Rendering mode' }; var GENERATE_NAMES = { barcode: 'generateBarcode', qrcode: 'generateQRCode', datamatrix: 'generateDataMatrix', pdf417: 'generatePDF417', dotcode: 'generateDotCode' }; function createGenerateTool(kind) { var properties = __assign({ value: { type: 'string', description: 'The value to encode' } }, COLOR_PROPS, SIZE_PROPS); var label = { barcode: 'one dimensional barcode', qrcode: 'QR code', datamatrix: 'Data Matrix code', pdf417: 'PDF417 code', dotcode: 'DotCode' }; if (kind === 'barcode') { properties.type = { type: 'string', description: 'The barcode type, e.g. Code128, Ean13. See getSupportedBarcodeTypes.', enum: webMcpBarcodeTypes }; properties.enableCheckSum = { type: 'boolean', description: 'Whether to enable checksum calculation' }; properties.bearerBarWidth = { type: 'number', description: 'ITF14 only: bearer bar width multiplier (1-10)' }; properties.segmentsPerRow = { type: 'number', description: 'GS1DataBarExpandedStacked only: segments per row (even, 2-20)' }; } else if (kind !== 'pdf417') { properties.enableGS1 = { type: 'boolean', description: 'Encode the value as GS1 data (bracketed AI notation or raw). Use validateGs1Data first.' }; } if (kind === 'qrcode') { properties.xDimension = { type: 'number', description: 'Module size in pixels' }; properties.errorCorrectionLevel = { type: ['string', 'number'], description: 'Low (7%), Medium (15%), Quartile (25%) or High (30%)' }; properties.version = { type: 'number', description: 'QR version 1-40, or 0 for automatic' }; } if (kind === 'datamatrix') { properties.xDimension = { type: 'number', description: 'Module size in pixels' }; properties.encoding = { type: 'string', enum: ['Auto', 'ASCII', 'ASCIINumeric', 'Base256'], description: 'Encoding mode' }; properties.symbolSize = { type: 'number', description: 'Symbol size index 0-19 (0 = Auto, 1 = 10x10 ... 19 = 88x88)' }; } if (kind === 'pdf417') { properties.compactionMode = { type: 'string', enum: ['Auto', 'Text', 'Numeric', 'Byte'], description: 'Compaction mode' }; properties.errorCorrectionLevel = { type: 'number', description: 'Error correction level 0-8, or -1 for automatic' }; properties.columns = { type: 'number', description: 'Number of data columns (0 or omitted = automatic)' }; properties.rows = { type: 'number', description: 'Number of rows (0 or omitted = automatic)' }; properties.isCompact = { type: 'boolean', description: 'Render the compact (truncated) PDF417 variant' }; properties.rowHeightRatio = { type: 'number', description: 'Row height to module width ratio' }; } if (kind === 'dotcode') { properties.columns = { type: 'number', description: 'Dot grid columns: 0 for automatic, otherwise 5 or more' }; } return { name: GENERATE_NAMES[kind], description: "Generates or updates the " + label[kind] + " with the specified value and appearance. All supplied values are " + 'validated before any is applied. The response reports whether the component accepted the value (valid) and the validation message if not.', annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }, inputSchema: { type: 'object', properties: properties, required: ['value'] }, outputSchema: RESULT_SCHEMA }; } function createTools(kind) { return [ createGenerateTool(kind), { name: 'getBarcodeConfiguration', description: 'Reads the full current configuration (symbology settings, colors, size, margin, display text, rendering mode) ' + 'and whether the current value is valid, with the validation message if not. No side effects: does not modify the barcode.', annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }, inputSchema: { type: 'object', properties: {} }, outputSchema: RESULT_SCHEMA }, { name: 'manageDisplayText', description: 'Updates the human readable text shown with the code: custom text, visibility, font, size, alignment, ' + 'position (Top/Bottom) and margin.', annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }, inputSchema: { type: 'object', properties: { text: { type: 'string', description: 'Custom text. Empty string shows the encoded value.' }, visibility: { type: 'boolean' }, font: { type: 'string', description: 'Font family' }, size: { type: 'number', description: 'Font size in pixels' }, alignment: { type: 'string', enum: ['Left', 'Right', 'Center'] }, position: { type: 'string', enum: ['Top', 'Bottom'] }, margin: MARGIN_SCHEMA } }, outputSchema: RESULT_SCHEMA }, { name: 'manageBarcodeLayout', description: 'Updates the layout of the code: width, height, margin and rendering mode (SVG or Canvas).', annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }, inputSchema: { type: 'object', properties: __assign({}, SIZE_PROPS, { margin: MARGIN_SCHEMA, mode: MODE_PROP }) }, outputSchema: RESULT_SCHEMA }, { name: 'getSupportedBarcodeTypes', description: 'Lists the symbologies this component supports with the value rules for each, so a valid type and value can be chosen.', annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }, inputSchema: { type: 'object', properties: {} }, outputSchema: RESULT_SCHEMA }, { name: 'validateGs1Data', description: 'Validates GS1 element data (bracketed such as (01)09506000134376(10)ABC123, or raw) without changing the code. ' + 'Returns the parsed Application Identifiers or the error.', annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }, inputSchema: { type: 'object', properties: { value: { type: 'string', description: 'GS1 element string to validate' } }, required: ['value'] }, outputSchema: RESULT_SCHEMA }, { name: 'exportBarcodeImage', description: 'Exports the code as a PNG or JPG. Can return as base64 string or trigger a browser download. When download is true, it triggers a file download to the user\'s device. When download is false or omitted, returns the image as a base64 string for programmatic use.', annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }, inputSchema: { type: 'object', properties: { exportType: { type: 'string', description: 'The export format', enum: ['PNG', 'JPG'] }, download: { type: 'boolean', description: 'If true, triggers browser file download. If false or omitted, returns base64 string.' }, fileName: { type: 'string', description: 'File name for download. Only used when download is true. Defaults to the element id.' } }, required: ['exportType'] }, outputSchema: RESULT_SCHEMA } ]; } var toolCache = {}; var WebMcpBarcode = (function () { function WebMcpBarcode(parent) { this.parent = null; this.kind = 'barcode'; this.webMcpAbortController = null; this.listenersAttached = false; this.getToolsHandler = null; this.registerToolsHandler = null; this.unregisterToolsHandler = null; this.destroyHandler = null; this.parent = parent || null; Eif (parent) { this.kind = kindByModuleName[parent.getModuleName()] || 'barcode'; this.addEventListener(); } } WebMcpBarcode.prototype.init = function (parent) { if (this.parent && this.parent !== parent) { this.removeEventListener(); } this.parent = parent || null; this.kind = parent ? (kindByModuleName[parent.getModuleName()] || 'barcode') : 'barcode'; this.addEventListener(); }; WebMcpBarcode.prototype.addEventListener = function () { var _this = this; if (ej2_base_1.isNullOrUndefined(this.parent) || this.listenersAttached) { return; } this.getToolsHandler = function (args) { _this.getTools(args); }; this.registerToolsHandler = function (args) { _this.registerTools(args); }; this.unregisterToolsHandler = function () { _this.unregisterTools(); }; this.destroyHandler = function () { _this.destroy(); }; this.parent.on('getWebMcpTools', this.getToolsHandler, this); this.parent.on('registerWebMcpTools', this.registerToolsHandler, this); this.parent.on('unregisterWebMcpTools', this.unregisterToolsHandler, this); this.parent.on('destroy', this.destroyHandler, this); this.listenersAttached = true; }; WebMcpBarcode.prototype.removeEventListener = function () { if (ej2_base_1.isNullOrUndefined(this.parent) || this.parent.isDestroyed || !this.listenersAttached) { this.listenersAttached = false; return; } this.parent.off('getWebMcpTools', this.getToolsHandler); this.parent.off('registerWebMcpTools', this.registerToolsHandler); this.parent.off('unregisterWebMcpTools', this.unregisterToolsHandler); this.parent.off('destroy', this.destroyHandler); this.getToolsHandler = null; this.registerToolsHandler = null; this.unregisterToolsHandler = null; this.destroyHandler = null; this.listenersAttached = false; }; WebMcpBarcode.prototype.getTools = function (args) { var toolNames = args.toolNames; var all = this.catalogue(); args.tools = (toolNames && toolNames.length !== 0 ? all.filter(function (t) { return toolNames.indexOf(t.name) !== -1; }) : all) .map(function (t) { return (__assign({}, t)); }); return args.tools; }; WebMcpBarcode.prototype.catalogue = function () { if (!toolCache[this.kind]) { toolCache[this.kind] = createTools(this.kind); } return toolCache[this.kind]; }; WebMcpBarcode.prototype.registerTools = function (args) { var _this = this; var modelContext = navigator.modelContext; if (!modelContext) { modelContext = document.modelContext; } if (!modelContext || typeof modelContext.registerTool !== 'function') { Eif (typeof console !== 'undefined' && console.warn) { console.warn("[WebMcpBarcode] WebMCP tools registration failed: modelContext not found on navigator or document. \n Ensure the page is run in a WebMCP-capable context (Chrome preview or equivalent)."); } return; } this.unregisterTools(); this.webMcpAbortController = new AbortController(); var toolPrefix = (ej2_base_1.isNullOrUndefined(args.prefix) ? this.parent.element.id : args.prefix); var tools = args.tools && args.tools.length && typeof args.tools[0] === 'object' ? args.tools : this.getTools({ toolNames: args.tools }); tools.forEach(function (tool) { var toolCopy = __assign({}, tool); toolCopy.name = toolPrefix + "_" + toolCopy.name; toolCopy.execute = function (args) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { return [2, this.executeHandler(toolCopy.name, args || {})]; }); }); }; var registerOptions = { signal: _this.webMcpAbortController.signal }; if (Array.isArray(args.exposedTo) && args.exposedTo.length > 0) { registerOptions.exposedTo = args.exposedTo; } modelContext.registerTool(toolCopy, registerOptions); }); }; WebMcpBarcode.prototype.unregisterTools = function () { if (this.webMcpAbortController) { this.webMcpAbortController.abort(); this.webMcpAbortController = null; } }; WebMcpBarcode.prototype.resolveBaseCommand = function (command) { if (!command) { return command; } for (var _i = 0, _a = this.catalogue(); _i < _a.length; _i++) { var tool = _a[_i]; if (command === tool.name || command.endsWith("_" + tool.name)) { return tool.name; } } return command; }; WebMcpBarcode.prototype.confirmExecution = function (eventArgs) { if (typeof window === 'undefined' || typeof window.confirm !== 'function') { return false; } return window.confirm("Allow the AI assistant to run \"" + eventArgs.toolName + "\" on this " + (this.kind === 'barcode' ? 'barcode' : this.kind) + "?"); }; WebMcpBarcode.prototype.cancelled = function (command, reason) { return this.message({ success: false, action: command, cancelled: true, message: reason || "[USER_CANCELLED] Tool \"" + command + "\" was cancelled. This is final. Do NOT retry." }); }; WebMcpBarcode.prototype.executeHandler = function (command, args) { return __awaiter(this, void 0, void 0, function () { var baseCommand, eventArgs, _a, err_1; return __generator(this, function (_b) { switch (_b.label) { case 0: if (!this.ensureParent()) { return [2, this.error('WebMcpBarcode is not properly initialized. Parent barcode is not available.')]; } baseCommand = this.resolveBaseCommand(command); eventArgs = { cancel: false, toolName: baseCommand, registeredName: command, toolArgs: args, showConfirmationDialog: false }; this.parent.trigger('beforeWebMcpToolExecute', eventArgs); if (eventArgs.cancel) { return [2, this.cancelled(baseCommand, eventArgs.cancellationResponse)]; } if (eventArgs.showConfirmationDialog && !this.confirmExecution(eventArgs)) { return [2, this.cancelled(baseCommand, eventArgs.cancellationResponse)]; } _b.label = 1; case 1: _b.trys.push([1, 12, , 13]); _a = baseCommand; switch (_a) { case GENERATE_NAMES[this.kind]: return [3, 2]; case 'getBarcodeConfiguration': return [3, 3]; case 'manageDisplayText': return [3, 4]; case 'manageBarcodeLayout': return [3, 5]; case 'getSupportedBarcodeTypes': return [3, 6]; case 'validateGs1Data': return [3, 7]; case 'exportBarcodeImage': return [3, 8]; } return [3, 10]; case 2: return [2, this.handleGenerate(args)]; case 3: return [2, this.handleGetConfiguration()]; case 4: return [2, this.handleManageDisplayText(args)]; case 5: return [2, this.handleManageLayout(args)]; case 6: return [2, this.handleSupportedTypes()]; case 7: return [2, this.handleValidateGs1(args)]; case 8: return [4, this.handleExport(args)]; case 9: return [2, _b.sent()]; case 10: return [2, this.error("Tool \"" + baseCommand + "\" not found.")]; case 11: return [3, 13]; case 12: err_1 = _b.sent(); return [2, this.error("Tool execution failed: " + (err_1.message || 'Unknown error'))]; case 13: return [2]; } }); }); }; WebMcpBarcode.prototype.ensureParent = function () { return !ej2_base_1.isNullOrUndefined(this.parent) && !this.parent.isDestroyed; }; WebMcpBarcode.prototype.applyModel = function (model) { var message; var handler = function (e) { message = e && e.message ? e.message : 'Invalid value.'; }; var parent = this.parent; var backup = {}; for (var _i = 0, _a = Object.keys(model); _i < _a.length; _i++) { var key = _a[_i]; var value = parent[key]; if (value && typeof value === 'object' && !Array.isArray(value)) { backup[key] = __assign({}, value); } else { backup[key] = value; } } parent.addEventListener('invalid', handler); try { this.parent.setProperties(model); } finally { parent.removeEventListener('invalid', handler); } if (message) { this.parent.setProperties(backup); message = undefined; } this.lastValidationMessage = message; return message; }; WebMcpBarcode.prototype.currentValidation = function () { return this.lastValidationMessage; }; WebMcpBarcode.prototype.isNumber = function (value) { return typeof value === 'number' && isFinite(value); }; WebMcpBarcode.prototype.isSize = function (value) { return (typeof value === 'number' && isFinite(value) && value > 0) || (typeof value === 'string' && value.trim() !== ''); }; WebMcpBarcode.prototype.collectCommon = function (args, model) { for (var _i = 0, _a = ['foreColor', 'backgroundColor']; _i < _a.length; _i++) { var color = _a[_i]; if (!ej2_base_1.isNullOrUndefined(args["" + color])) { if (typeof args["" + color] !== 'string' || !args["" + color]) { return color + " must be a non-empty string."; } model["" + color] = args["" + color]; } } for (var _b = 0, _c = ['width', 'height']; _b < _c.length; _b++) { var dim = _c[_b]; if (!ej2_base_1.isNullOrUndefined(args["" + dim])) { if (!this.isSize(args["" + dim])) { return dim + " must be a positive number or a CSS size string."; } model["" + dim] = args["" + dim]; } } if (!ej2_base_1.isNullOrUndefined(args.mode)) { if (args.mode !== 'SVG' && args.mode !== 'Canvas') { return 'mode must be SVG or Canvas.'; } model.mode = args.mode; } if (!ej2_base_1.isNullOrUndefined(args.margin)) { var margin = {}; if (typeof args.margin !== 'object') { return 'margin must be an object.'; } for (var _d = 0, _e = ['left', 'right', 'top', 'bottom']; _d < _e.length; _d++) { var side = _e[_d]; if (!ej2_base_1.isNullOrUndefined(args.margin["" + side])) { if (!this.isNumber(args.margin["" + side]) || args.margin["" + side] < 0) { return "margin." + side + " must be a non-negative number."; } margin["" + side] = args.margin["" + side]; } } model.margin = margin; } return undefined; }; WebMcpBarcode.prototype.handleGenerate = function (args) { if (typeof args.value !== 'string' || args.value === '') { return this.error('Missing or invalid required parameter: value (non-empty string).'); } var model = { value: args.value }; var problem = this.collectCommon(args, model) || this.collectSpecific(args, model); if (problem) { return this.error(problem); } var validation = this.applyModel(model); return this.message({ success: !validation, valid: !validation, validationMessage: validation, data: __assign({}, model), message: validation ? 'The component rejected the value. Settings were rolled back.' : 'Generated successfully.' }); }; WebMcpBarcode.prototype.collectSpecific = function (args, model) { var _this = this; var parent = this.parent; if (!ej2_base_1.isNullOrUndefined(args.enableGS1)) { if (this.kind === 'barcode') { return 'enableGS1 is not supported by barcode; use a GS1 type such as GS1Code128.'; } if (this.kind === 'pdf417') { return 'enableGS1 is not supported by PDF417.'; } if (typeof args.enableGS1 !== 'boolean') { return 'enableGS1 must be a boolean.'; } model.enableGS1 = args.enableGS1; } var range = function (name, min, max, integer) { if (ej2_base_1.isNullOrUndefined(args["" + name])) { return undefined; } var v = args["" + name]; if (!_this.isNumber(v) || v < min || v > max || (integer && Math.floor(v) !== v)) { return name + " must be " + (integer ? 'an integer' : 'a number') + " between " + min + " and " + max + "."; } model["" + name] = v; return undefined; }; switch (this.kind) { case 'barcode': { if (!ej2_base_1.isNullOrUndefined(args.type)) { if (webMcpBarcodeTypes.indexOf(args.type) === -1) { return "Invalid barcode type: " + args.type; } model.type = args.type; } var type = args.type || parent.type; if (!ej2_base_1.isNullOrUndefined(args.enableCheckSum)) { if (typeof args.enableCheckSum !== 'boolean') { return 'enableCheckSum must be a boolean.'; } model.enableCheckSum = args.enableCheckSum; } if (type === 'ITF14') { return range('bearerBarWidth', 1, 10, false); } if (type === 'GS1DataBarExpandedStacked' && !ej2_base_1.isNullOrUndefined(args.segmentsPerRow)) { var r = range('segmentsPerRow', 2, 20, true); return r || (args.segmentsPerRow % 2 !== 0 ? 'segmentsPerRow must be an even number between 2 and 20.' : undefined); } return undefined; } case 'qrcode': { var r = range('xDimension', 1, 100, false) || range('version', 0, 40, true); if (r) { return r; } Eif (!ej2_base_1.isNullOrUndefined(args.errorCorrectionLevel)) { var levels = { Low: 7, Medium: 15, Quartile: 25, High: 30 }; var level = typeof args.errorCorrectionLevel === 'string' ? levels[args.errorCorrectionLevel] : args.errorCorrectionLevel; if ([7, 15, 25, 30].indexOf(level) === -1) { return 'errorCorrectionLevel must be Low, Medium, Quartile or High.'; } model.errorCorrectionLevel = level; } return undefined; } case 'datamatrix': { var r = range('xDimension', 1, 100, false) || range('symbolSize', 0, 19, true); if (r) { return r; } if (!ej2_base_1.isNullOrUndefined(args.symbolSize)) { model.size = args.symbolSize; } if (!ej2_base_1.isNullOrUndefined(args.encoding)) { if (['Auto', 'ASCII', 'ASCIINumeric', 'Base256'].indexOf(args.encoding) === -1) { return 'Invalid encoding.'; } model.encoding = args.encoding; } return undefined; } case 'pdf417': { var r = range('errorCorrectionLevel', -1, 8, true) || range('columns', 0, 30, true) || range('rows', 0, 90, true) || range('rowHeightRatio', 1, 20, false); if (r) { return r; } if (!ej2_base_1.isNullOrUndefined(args.compactionMode)) { if (['Auto', 'Text', 'Numeric', 'Byte'].indexOf(args.compactionMode) === -1) { return 'Invalid compactionMode.'; } model.compactionMode = args.compactionMode; } if (!ej2_base_1.isNullOrUndefined(args.isCompact)) { if (typeof args.isCompact !== 'boolean') { return 'isCompact must be a boolean.'; } model.isCompact = args.isCompact; } return undefined; } default: { if (!ej2_base_1.isNullOrUndefined(args.columns) && args.columns !== 0) { return range('columns', 5, 1000, true); } Eif (args.columns === 0) { model.columns = 0; } return undefined; } } }; WebMcpBarcode.prototype.handleGetConfiguration = function () { var parent = this.parent; var keys = { barcode: ['type', 'enableCheckSum', 'bearerBarWidth', 'segmentsPerRow'], qrcode: ['enableGS1', 'xDimension', 'errorCorrectionLevel', 'version'], datamatrix: ['enableGS1', 'xDimension', 'encoding', 'size'], pdf417: ['compactionMode', 'errorCorrectionLevel', 'columns', 'rows', 'isCompact', 'rowHeightRatio'], dotcode: ['enableGS1', 'columns'] }; var data = { kind: this.kind }; ['value', 'foreColor', 'backgroundColor', 'width', 'height', 'mode'].concat(keys[this.kind]).forEach(function (key) { data["" + key] = parent["" + key]; }); if (this.kind === 'datamatrix') { var symbolSize = parent.size; if (typeof symbolSize === 'number' && (symbolSize < 0 || symbolSize > 19)) { data.symbolSize = symbolSize; data._symbolSizeWarning = "Symbol size " + symbolSize + " is out of valid range (0\u201319). Component may have invalid state."; } else { data.symbolSize = symbolSize; } delete data.size; } var dt = parent.displayText || {}; var m = parent.margin || {}; data.displayText = { text: dt.text, visibility: dt.visibility, font: dt.font, size: dt.size, alignment: dt.alignment, position: dt.position, margin: dt.margin ? { left: dt.margin.left, right: dt.margin.right, top: dt.margin.top, bottom: dt.margin.bottom } : undefined }; data.margin = { left: m.left, right: m.right, top: m.top, bottom: m.bottom }; Iif (parent.symbolInfo) { data.symbolInfo = parent.symbolInfo; } var validation = this.currentValidation(); return this.message({ success: true, valid: !validation, validationMessage: validation, data: data }); }; WebMcpBarcode.prototype.handleManageDisplayText = function (args) { var text = {}; if (!ej2_base_1.isNullOrUndefined(args.text)) { if (typeof args.text !== 'string') { return this.error('text must be a string.'); } text.text = args.text; } if (!ej2_base_1.isNullOrUndefined(args.visibility)) { if (typeof args.visibility !== 'boolean') { return this.error('visibility must be a boolean.'); } text.visibility = args.visibility; } if (!ej2_base_1.isNullOrUndefined(args.font)) { if (typeof args.font !== 'string' || !args.font) { return this.error('font must be a non-empty string.'); } text.font = args.font; } if (!ej2_base_1.isNullOrUndefined(args.size)) { if (!this.isNumber(args.size) || args.size <= 0) { return this.error('size must be a positive number.'); } text.size = args.size; } if (!ej2_base_1.isNullOrUndefined(args.alignment)) { if (['Left', 'Right', 'Center'].indexOf(args.alignment) === -1) { return this.error('alignment must be Left, Right or Center.'); } text.alignment = args.alignment; } if (!ej2_base_1.isNullOrUndefined(args.position)) { if (['Top', 'Bottom'].indexOf(args.position) === -1) { return this.error('position must be Top or Bottom.'); } text.position = args.position; } if (!ej2_base_1.isNullOrUndefined(args.margin)) { var holder = {}; var problem = this.collectCommon({ margin: args.margin }, holder); if (problem) { return this.error(problem); } text.margin = holder.margin; } if (Object.keys(text).length === 0) { return this.error('Supply at least one of text, visibility, font, size, alignment, position or margin.'); } var validation = this.applyModel({ displayText: text }); return this.message({ success: !validation, valid: !validation, validationMessage: validation, data: { displayText: text }, message: 'Display text updated.' }); }; WebMcpBarcode.prototype.handleManageLayout = function (args) { var model = {}; var problem = this.collectCommon({ width: args.width, height: args.height, margin: args.margin, mode: args.mode }, model); if (problem) { return this.error(problem); } if (Object.keys(model).length === 0) { return this.error('Supply at least one of width, height, margin or mode.'); } var validation = this.applyModel(model); return this.message({ success: !validation, valid: !validation, validationMessage: validation, data: model, message: 'Layout updated.' }); }; WebMcpBarcode.prototype.handleSupportedTypes = function () { var rules = this.kind === 'barcode' ? barcodeTypeRules : twoDimensionalRules[this.kind]; var types = Object.keys(rules).map(function (name) { return ({ type: name, valueRules: rules["" + name] }); }); return this.message({ success: true, data: { kind: this.kind, types: types } }); }; WebMcpBarcode.prototype.handleValidateGs1 = function (args) { if (typeof args.value !== 'string' || args.value === '') { return this.error('Missing or invalid required parameter: value (non-empty string).'); } var result = gs1_parser_1.parseGs1(args.value); if (result.ok === false) { return this.message({ success: true, valid: false, error: result.error }); } return this.message({ success: true, valid: true, data: { elements: result.elements.map(function (e) { return ({ ai: e.ai, value: e.value }); }), humanReadableText: result.humanReadableText } }); }; WebMcpBarcode.prototype.handleExport = function (args) { return __awaiter(this, void 0, void 0, function () { var download, parent, fileName, image; return __generator(this, function (_a) { switch (_a.label) { case 0: if (args.exportType !== 'PNG' && args.exportType !== 'JPG') { return [2, this.error('Invalid or missing exportType. Must be PNG or JPG.')]; } download = args.download === true; parent = this.parent; if (download) { fileName = typeof args.fileName === 'string' && args.fileName ? args.fileName : this.parent.element.id; parent.exportImage(fileName, args.exportType); return [2, this.message({ success: true, data: { exportType: args.exportType, fileName: fileName, downloaded: true } })]; } return [4, parent.exportAsBase64Image(args.exportType)]; case 1: image = _a.sent(); return [2, this.message({ success: true, data: { exportType: args.exportType, image: image } })]; } }); }); }; WebMcpBarcode.prototype.destroy = function () { this.removeEventListener(); this.unregisterTools(); this.parent = null; }; WebMcpBarcode.prototype.getModuleName = function () { return 'WebMcpBarcode'; }; WebMcpBarcode.prototype.message = function (data) { return { content: [{ type: 'text', text: JSON.stringify(data) }] }; }; WebMcpBarcode.prototype.error = function (text) { return { content: [{ type: 'text', text: text }], isError: true }; }; return WebMcpBarcode; }()); exports.WebMcpBarcode = WebMcpBarcode; var WebMcpBarcodeSettings = (function (_super) { __extends(WebMcpBarcodeSettings, _super); function WebMcpBarcodeSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate([ ej2_base_1.Property(null) ], WebMcpBarcodeSettings.prototype, "name", void 0); __decorate([ ej2_base_1.Property(null) ], WebMcpBarcodeSettings.prototype, "tools", void 0); __decorate([ ej2_base_1.Property(null) ], WebMcpBarcodeSettings.prototype, "exposedTo", void 0); return WebMcpBarcodeSettings; }(ej2_base_1.ChildProperty)); exports.WebMcpBarcodeSettings = WebMcpBarcodeSettings; }); |