* Generates data uri. * @param {NormalModule} module module for which the code should be generated * @returns {string} DataURI
(module)
| 496 | * @returns {string} DataURI |
| 497 | */ |
| 498 | generateDataUri(module) { |
| 499 | const source = /** @type {Source} */ (module.originalSource()); |
| 500 | |
| 501 | /** @type {string} */ |
| 502 | let encodedSource; |
| 503 | |
| 504 | if (typeof this.dataUrlOptions === "function") { |
| 505 | encodedSource = this.dataUrlOptions.call(null, source.source(), { |
| 506 | filename: /** @type {string} */ (module.getResource()), |
| 507 | module |
| 508 | }); |
| 509 | } else { |
| 510 | let encoding = |
| 511 | /** @type {AssetGeneratorDataUrlOptions} */ |
| 512 | (this.dataUrlOptions).encoding; |
| 513 | if ( |
| 514 | encoding === undefined && |
| 515 | module.resourceResolveData && |
| 516 | module.resourceResolveData.encoding !== undefined |
| 517 | ) { |
| 518 | encoding = module.resourceResolveData.encoding; |
| 519 | } |
| 520 | if (encoding === undefined) { |
| 521 | encoding = DEFAULT_ENCODING; |
| 522 | } |
| 523 | const mimeType = this.getMimeType(module); |
| 524 | |
| 525 | /** @type {string} */ |
| 526 | let encodedContent; |
| 527 | |
| 528 | if ( |
| 529 | module.resourceResolveData && |
| 530 | module.resourceResolveData.encoding === encoding && |
| 531 | decodeDataUriContent( |
| 532 | module.resourceResolveData.encoding, |
| 533 | /** @type {string} */ (module.resourceResolveData.encodedContent) |
| 534 | ).equals(source.buffer()) |
| 535 | ) { |
| 536 | encodedContent = |
| 537 | /** @type {string} */ |
| 538 | (module.resourceResolveData.encodedContent); |
| 539 | } else { |
| 540 | encodedContent = encodeDataUri( |
| 541 | /** @type {"base64" | false} */ (encoding), |
| 542 | source |
| 543 | ); |
| 544 | } |
| 545 | |
| 546 | encodedSource = `data:${mimeType}${ |
| 547 | encoding ? `;${encoding}` : "" |
| 548 | },${encodedContent}`; |
| 549 | } |
| 550 | |
| 551 | return encodedSource; |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * Generates generated code for this runtime module. |
no test coverage detected