{"version":3,"sources":["../src/lib/fileBase.ts","../src/lib/file2qr.ts","../src/lib/url2qr.ts"],"names":["Transform","PluginError","callbackify","PassThrough","QRCode","PLUGIN_NAME","parseIniFromString","Composer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAM,WAAA,GAAc,cAAA;AAQb,IAAe,mBAAA,GAAf,cAA2CA,iBAAA,CAAoB;AAAA;AAAA;AAAA;AAAA,EAKpE,MAAgB,cAAc,IAAA,EAAiC;AAC7D,IAAA,IAAI,IAAA,CAAK,UAAS,EAAG;AACnB,MAAA,OAAO,IAAA,CAAK,QAAA;AAAA,IACd;AACA,IAAA,IAAI,IAAA,CAAK,UAAS,EAAG;AACnB,MAAA,MAAM,SAAmB,EAAC;AAC1B,MAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AAC3C,QAAA,IAAA,CAAK,QAAA,CACF,GAAG,MAAA,EAAQ,CAAC,UAAkB,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,KAAK,CAAC,CAAC,CAAA,CAC7D,EAAA,CAAG,OAAA,EAAS,OAAO,CAAA,CACnB,EAAA,CAAG,OAAO,OAAO,CAAA,CACjB,EAAA,CAAG,OAAA,EAAS,MAAM,CAAA;AAAA,MACvB,CAAC,CAAA;AACD,MAAA,MAAM,YAAA,GAAe,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AACzC,MAAA,OAAO,YAAA;AAAA,IACT;AACA,IAAA,MAAM,IAAIC,4BAAA;AAAA,MAAY,WAAA;AAAA,MACpB,CAAA,6CAAA,EAAgD,KAAK,IAAI,CAAA,CAAA;AAAA,KAC3D;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAgB,YAAY,IAAA,EAAiC;AAC3D,IAAA,MAAM,YAAA,GAAuB,MAAM,IAAA,CAAK,aAAA,CAAc,IAAI,CAAA;AAC1D,IAAA,MAAM,QAAA,GAAmB,YAAA,CA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AAK,CAAA;AAC9C,IAAA,MAAM,QAAA,GAAW,WAAW,KAAA,EAAM;AAClC,IAAA,QAAA,CAAS,QAAA,GAAW,MAAA,CAAO,IAAA,CAAK,cAAA,CAAe,UAAU,CAAA;AACzD,IAAA,OAAO,QAAA;AAAA,EACT;AAEF,CAAA;AAqBO,SAAS,OAAO,OAAA,EAA2C;AAChE,EAAA,MAAM,eAA+BE,yBAAA,CAAS,QAAA;AAAA,IAC5C,IAAI,oBAAA,EAAqB;AAAA,IACzB,IAAI,YAAY,OAAO;AAAA,GACzB;AACA,EAAA,OAAO,YAAA;AACT","file":"index.cjs","sourcesContent":["// import assert from 'node:assert/strict';\nimport { Transform, type ResultCallback } from 'streamx';\nimport { callbackify } from 'util';\nimport PluginError from 'plugin-error';\nimport GulpFile, { type StreamFile, type BufferFile } from 'vinyl';\n\nconst PLUGIN_NAME = 'gulp-file2qr';\n\n/**\n * Gulp plugin base transform stream,\n * which support just BufferFile output\n *\n * @public @internal\n */\nexport abstract class GulpFile2BufferFile extends Transform<GulpFile> {\n\n  /**\n   * @internal\n   */\n  protected async getFileBuffer(file: GulpFile): Promise<Buffer> {\n    if (file.isBuffer()) {\n      return file.contents;\n    };\n    if (file.isStream()) {\n      const chunks: Buffer[] = [];\n      await new Promise<void>((resolve, reject) => {\n        file.contents\n          .on('data', (chunk: string) => chunks.push(Buffer.from(chunk)))\n          .on('close', resolve)\n          .on('end', resolve)\n          .on('error', reject);\n      });\n      const fileContents = Buffer.concat(chunks);\n      return fileContents;\n    };\n    throw new PluginError(PLUGIN_NAME,\n      `Null GulpFile processing does not supported (${file.path})`\n    );\n  };\n\n  /**\n   * @internal\n   */\n  protected async getFileText(file: GulpFile): Promise<string> {\n    const fileContents: Buffer = await this.getFileBuffer(file);\n    const fileText: string = fileContents.toString('utf8');\n    return fileText;\n  };\n\n  /**\n   * @internal\n   */\n  protected abstract _transform2BufferFile(\n    fileText: string, sourceFile: GulpFile\n  ): Promise<BufferFile>;\n\n  /**\n   * @internal\n   */\n  override _transform(\n    file: GulpFile,\n    callback: ResultCallback<GulpFile>\n  ): void {\n    callbackify(async (): Promise<GulpFile | undefined> => {\n      if (file.isNull()) {\n        return file;\n      };\n      const fileText: string = await this.getFileText(file);\n      try {\n        return await this._transform2BufferFile(fileText, file);\n      } catch (error) {\n        throw (error instanceof PluginError) ? error as PluginError :\n          new PluginError(PLUGIN_NAME,\n            error instanceof Error ? error : error as string);\n      };\n    })(callback);\n  };\n\n};\n\n/**\n * GulpFile2GulpFile options\n *\n * @public\n */\nexport interface Options {\n\n  /**\n   * Create output GulpFile with Buffer (true),\n   * or with stream (false).\n   *\n   * If not specified, created StreamFile\n   * when input file is StreamFile,\n   * and created BufferFile,\n   * when input file is BufferFile.\n   *\n   * @public\n   */\n  buffer?: boolean;\n\n};\n\n/**\n * Gulp plugin base transform stream\n *\n * @public @internal\n */\nexport abstract class GulpFile2GulpFile extends GulpFile2BufferFile {\n\n  private readonly _options: Options;\n\n  constructor(options?: Options) {\n    super();\n    this._options = { ...{}, ...options };\n  };\n\n  /**\n   * @internal\n   */\n  protected abstract _transform2StreamFile(\n    fileText: string, sourceFile: GulpFile\n  ): Promise<StreamFile>;\n\n  /**\n   * @internal\n   */\n  override _transform(\n    file: GulpFile,\n    callback: ResultCallback<GulpFile>\n  ): void {\n    callbackify(async (): Promise<GulpFile | undefined> => {\n      if (file.isNull()) {\n        return file;\n      };\n      const fileText: string = await this.getFileText(file);\n      try {\n        if (\n          ((this._options.buffer === undefined) && (file.isStream()))\n          || ((this._options.buffer !== undefined) && (!this._options.buffer))\n        ) {\n          return await this._transform2StreamFile(fileText, file);\n        } else if (\n          ((this._options.buffer === undefined) && (file.isBuffer()))\n          || ((this._options.buffer !== undefined))\n        ) {\n          return await this._transform2BufferFile(fileText, file);\n        };\n      } catch (error) {\n        throw (error instanceof PluginError) ? error as PluginError :\n          new PluginError(PLUGIN_NAME,\n            error instanceof Error ? error : error as string);\n      };\n    })(callback);\n  };\n\n};\n","import { PassThrough } from 'node:stream';\nimport GulpFile, { type StreamFile, type BufferFile } from 'vinyl';\nimport {\n  GulpFile2GulpFile,\n  type Options as GulpFile2GulpFileOptions\n} from './fileBase.ts';\nimport * as QRCode from 'qrcode';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst PLUGIN_NAME = 'gulp-file2qr';\n\n/**\n * gulp-file2qr plugin options\n *\n * @remarks\n *\n * @see {@link url2qr} for more details.\n *\n * @public\n */\nexport interface Options extends GulpFile2GulpFileOptions {\n\n  /**\n   * Options for generated PNG QR codes.\n   *\n   * See {@link https://www.npmjs.com/package/qrcode| `qrcode`}\n   * for more details.\n   *\n   * @public\n   */\n  qrOptions?: QRCode.QRCodeRenderersOptions;\n\n};\n\n/**\n * Gulp plugin stream for transformation text data from file\n * to PNG QR code\n *\n * @public @internal\n */\nexport class GulpFile2QR extends GulpFile2GulpFile {\n\n  /**\n   * @internal\n   */\n  protected readonly options: Options;\n\n  /**\n   * @internal\n   */\n  constructor(options?: Options) {\n    super(options);\n    const optionsDefaults: Options = {\n      qrOptions: {\n        scale: 4\n      }\n    };\n    this.options = { ...optionsDefaults, ...options };\n  };\n\n  /**\n   * @internal\n   */\n  protected override async _transform2StreamFile(\n    fileText: string, sourceFile: GulpFile\n  ): Promise<StreamFile> {\n    const QRCodeFile = sourceFile.clone();\n    QRCodeFile.extname = '.png';\n    const PNGStream = new PassThrough;\n    QRCodeFile.contents = PNGStream;\n    await QRCode.toFileStream(PNGStream, fileText, this.options.qrOptions);\n    return QRCodeFile as StreamFile;\n  };\n\n  /**\n   * @internal\n   */\n  protected override async _transform2BufferFile(\n    fileText: string, sourceFile: GulpFile\n  ): Promise<BufferFile> {\n    const QRCodeFile = sourceFile.clone();\n    QRCodeFile.extname = '.png';\n    QRCodeFile.contents =\n      await QRCode.toBuffer(fileText, this.options.qrOptions);\n    return QRCodeFile as BufferFile;\n  };\n\n}\n\n/**\n * Plugin fabric function.\n *\n * Returns Gulp plugin stream for transformation\n * GulpFile with utf-8 plain text data\n * to GulpFile with PNG QR code.\n *\n * Used in pipeline with other Gulp plugins,\n * which transforms source files to simple\n * buffered utf-8 text files with QR code data.\n *\n * @param options - {@link Options} for QRCode generator\n *\n * @internal\n */\nexport function file2qr(options?: Options): NodeJS.ReadWriteStream {\n  return new GulpFile2QR(options) as unknown as NodeJS.ReadWriteStream;\n};\n","/**\n * A Gulp plugin for creating PNG QRCodes with URI\n * from source .url files.\n *\n * .url files - INI files. For example:\n *\n * ```ini\n * [{000214A0-0000-0000-C000-000000000046}]\n * Prop3=19,2\n * [InternetShortcut]\n * URL=https://github.com/IT-Service-NPM/gulp-file2qr\n * ```\n *\n * @packageDocumentation\n */\n\nimport PluginError from 'plugin-error';\nimport GulpFile, { type BufferFile } from 'vinyl';\nimport streamx from 'streamx';\nimport { GulpFile2BufferFile } from './fileBase.ts';\nimport { type Options, GulpFile2QR } from './file2qr.ts';\nimport { parseIniFromString } from 'cool-ini-parser';\nimport Composer from 'stream-composer/index.js';\n\nconst PLUGIN_NAME = 'gulp-file2qr';\n\n/**\n * Gulp plugin stream for transformation .url files\n * to plain text utf-8 file with url\n * @public @internal\n */\nclass URLFile2TextGulpFile extends GulpFile2BufferFile {\n\n  /**\n   * @internal\n   */\n  // eslint-disable-next-line @typescript-eslint/require-await\n  protected async _transform2BufferFile(\n    fileText: string, sourceFile: GulpFile\n  ): Promise<BufferFile> {\n    const iniData = parseIniFromString(fileText);\n    const InternetShortcutSection = iniData.sections.find(\n      section => section.name === 'InternetShortcut'\n    );\n    const URLstring = InternetShortcutSection?.entries.find(\n      entry => entry.key === 'URL'\n    );\n    if (URLstring === undefined) {\n      throw new PluginError(PLUGIN_NAME,\n        `file \"${sourceFile.path}\" doesn't contains InternetShortcut/URL`\n      );\n    };\n    const urlFromURLFile = new URL(URLstring.value);\n    const TextFile = sourceFile.clone();\n    TextFile.contents = Buffer.from(urlFromURLFile.toString());\n    return TextFile as BufferFile;\n  };\n\n}\n\n/**\n * Plugin fabric function.\n *\n * Returns Gulp plugin stream for transformation\n * .url files to PNG QR codes.\n *\n * .url files - INI files. For example:\n *\n * ```ini\n * [{000214A0-0000-0000-C000-000000000046}]\n * Prop3=19,2\n * [InternetShortcut]\n * URL=https://github.com/IT-Service-NPM/gulp-file2qr\n * ```\n *\n * @param options - {@link Options} for QRCode generator\n *\n * @public\n */\nexport function url2qr(options?: Options): NodeJS.ReadWriteStream {\n  const pluginStream: streamx.Duplex = Composer.pipeline(\n    new URLFile2TextGulpFile(),\n    new GulpFile2QR(options)\n  );\n  return pluginStream as unknown as NodeJS.ReadWriteStream;\n};\n"]}