@connexup/react-native-xprinter 0.1.0

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.
Files changed (145) hide show
  1. package/LICENSE +20 -0
  2. package/NativeXPrinter.podspec +23 -0
  3. package/README.md +24 -0
  4. package/android/build.gradle +73 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/libs/printer-lib-3.4.7.aar +0 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/java/com/connexup/xprinter/Errors.kt +11 -0
  9. package/android/src/main/java/com/connexup/xprinter/Util.kt +106 -0
  10. package/android/src/main/java/com/connexup/xprinter/XPrinterPackage.kt +77 -0
  11. package/android/src/main/java/com/connexup/xprinter/esc/Convert.kt +211 -0
  12. package/android/src/main/java/com/connexup/xprinter/esc/XPrinterESCModule.kt +1995 -0
  13. package/android/src/main/java/com/connexup/xprinter/printer/Convert.kt +46 -0
  14. package/android/src/main/java/com/connexup/xprinter/printer/DeviceConnection.kt +14 -0
  15. package/android/src/main/java/com/connexup/xprinter/printer/Printers.kt +153 -0
  16. package/android/src/main/java/com/connexup/xprinter/printer/XPrinterPrinterModule.kt +295 -0
  17. package/android/src/main/java/com/connexup/xprinter/tspl/Convert.kt +151 -0
  18. package/android/src/main/java/com/connexup/xprinter/tspl/XPrinterTSPLModule.kt +1408 -0
  19. package/android/src/main/java/com/connexup/xprinter/utils/XPrinterUtilsModule.kt +54 -0
  20. package/ios/ESC/ESCConvert.swift +283 -0
  21. package/ios/ESC/Models/RCTESCPrintBarCodeRequest.swift +23 -0
  22. package/ios/ESC/Models/RCTESCPrintBitmapRequest.swift +23 -0
  23. package/ios/ESC/Models/RCTESCPrintPDF417Request.swift +27 -0
  24. package/ios/ESC/Models/RCTESCPrintQRCodeRequest.swift +19 -0
  25. package/ios/ESC/Models/RCTESCPrintTableBarcode.swift +23 -0
  26. package/ios/ESC/Models/RCTESCPrintTableRequest.swift +19 -0
  27. package/ios/ESC/Models/RCTESCPrintTableRow.swift +19 -0
  28. package/ios/ESC/Models/RCTESCPrintTextRequest.swift +21 -0
  29. package/ios/ESC/Models/RCTESCPrintTextSizeRequest.swift +17 -0
  30. package/ios/ESC/Models/RCTESCSelectBitmapModelRequest.swift +17 -0
  31. package/ios/ESC/Models/RCTESCSetNetAllRequest.swift +19 -0
  32. package/ios/ESC/Models/RCTESCSetPrintAreaRequest.swift +19 -0
  33. package/ios/ESC/Models/RCTESCSetTextStyleRequest.swift +17 -0
  34. package/ios/ESC/Models/RCTESCWifiConfigRequest.swift +23 -0
  35. package/ios/ESC/NativeXPrinterESC.swift +1339 -0
  36. package/ios/ESC/RCTNativeXPrinterESC.h +10 -0
  37. package/ios/ESC/RCTNativeXPrinterESC.mm +541 -0
  38. package/ios/Errors.swift +11 -0
  39. package/ios/NativeErrorInfo.swift +21 -0
  40. package/ios/Printer/Connecter.swift +214 -0
  41. package/ios/Printer/Models/RCTDeviceConnectStatusChangeEvent.swift +19 -0
  42. package/ios/Printer/Models/RCTNetDevice.swift +21 -0
  43. package/ios/Printer/Models/RCTUSBDevice.swift +17 -0
  44. package/ios/Printer/Models/RCTUpdateUdpNetConfigRequest.swift +21 -0
  45. package/ios/Printer/NativeXPrinterPrinter.swift +209 -0
  46. package/ios/Printer/Printers.swift +59 -0
  47. package/ios/Printer/RCTNativeXPrinterPrinter.h +12 -0
  48. package/ios/Printer/RCTNativeXPrinterPrinter.mm +123 -0
  49. package/ios/PrinterSDK/Headers/CPCLCommand.h +324 -0
  50. package/ios/PrinterSDK/Headers/KDS_Log.h +47 -0
  51. package/ios/PrinterSDK/Headers/LabelDocument.h +32 -0
  52. package/ios/PrinterSDK/Headers/LabelImageTranster.h +19 -0
  53. package/ios/PrinterSDK/Headers/POSBLEManager.h +164 -0
  54. package/ios/PrinterSDK/Headers/POSCommand.h +760 -0
  55. package/ios/PrinterSDK/Headers/POSImageTranster.h +34 -0
  56. package/ios/PrinterSDK/Headers/POSPrinter.h +47 -0
  57. package/ios/PrinterSDK/Headers/POSPrinterSDK.h +13 -0
  58. package/ios/PrinterSDK/Headers/POSWIFIManager.h +162 -0
  59. package/ios/PrinterSDK/Headers/PTable.h +50 -0
  60. package/ios/PrinterSDK/Headers/PrinterProfile.h +28 -0
  61. package/ios/PrinterSDK/Headers/TSCBLEManager.h +142 -0
  62. package/ios/PrinterSDK/Headers/TSCCommand.h +701 -0
  63. package/ios/PrinterSDK/Headers/TSCPrinterSDK.h +15 -0
  64. package/ios/PrinterSDK/Headers/TSCWIFIManager.h +99 -0
  65. package/ios/PrinterSDK/Headers/WIFIConnecter.h +131 -0
  66. package/ios/PrinterSDK/Headers/ZPLCommand.h +372 -0
  67. package/ios/PrinterSDK/libPrinterSDK.a +0 -0
  68. package/ios/TSPL/Models/RCTTSPLBarRequest.swift +19 -0
  69. package/ios/TSPL/Models/RCTTSPLBarcodeRequest.swift +29 -0
  70. package/ios/TSPL/Models/RCTTSPLBitmapCompressionRequest.swift +25 -0
  71. package/ios/TSPL/Models/RCTTSPLBitmapRequest.swift +25 -0
  72. package/ios/TSPL/Models/RCTTSPLBoxRequest.swift +21 -0
  73. package/ios/TSPL/Models/RCTTSPLEraseRequest.swift +19 -0
  74. package/ios/TSPL/Models/RCTTSPLPDFBase64Request.swift +21 -0
  75. package/ios/TSPL/Models/RCTTSPLPutBMPRequest.swift +17 -0
  76. package/ios/TSPL/Models/RCTTSPLQRCodeRequest.swift +29 -0
  77. package/ios/TSPL/Models/RCTTSPLReverseRequest.swift +19 -0
  78. package/ios/TSPL/Models/RCTTSPLTextRequest.swift +25 -0
  79. package/ios/TSPL/NativeXPrinterTSPL.swift +831 -0
  80. package/ios/TSPL/RCTNativeXPrinterTSPL.h +10 -0
  81. package/ios/TSPL/RCTNativeXPrinterTSPL.mm +445 -0
  82. package/ios/TSPL/TSPLConvert.swift +140 -0
  83. package/ios/Utils/Models/RCTCheckIsPureWhiteImageRequest.swift +16 -0
  84. package/ios/Utils/NativeXPrinterUtils.swift +17 -0
  85. package/ios/Utils/RCTNativeXPrinterUtils.h +10 -0
  86. package/ios/Utils/RCTNativeXPrinterUtils.mm +38 -0
  87. package/ios/Utils.swift +126 -0
  88. package/lib/module/esc/NativeXPrinterESC.js +218 -0
  89. package/lib/module/esc/NativeXPrinterESC.js.map +1 -0
  90. package/lib/module/esc/index.js +324 -0
  91. package/lib/module/esc/index.js.map +1 -0
  92. package/lib/module/index.js +8 -0
  93. package/lib/module/index.js.map +1 -0
  94. package/lib/module/package.json +1 -0
  95. package/lib/module/printer/NativeXPrinterPrinter.js +30 -0
  96. package/lib/module/printer/NativeXPrinterPrinter.js.map +1 -0
  97. package/lib/module/printer/index.js +110 -0
  98. package/lib/module/printer/index.js.map +1 -0
  99. package/lib/module/tspl/NativeXPrinterTSPL.js +143 -0
  100. package/lib/module/tspl/NativeXPrinterTSPL.js.map +1 -0
  101. package/lib/module/tspl/index.js +347 -0
  102. package/lib/module/tspl/index.js.map +1 -0
  103. package/lib/module/type.js +12 -0
  104. package/lib/module/type.js.map +1 -0
  105. package/lib/module/util.js +4 -0
  106. package/lib/module/util.js.map +1 -0
  107. package/lib/module/utils/NativeXPrinterUtils.js +5 -0
  108. package/lib/module/utils/NativeXPrinterUtils.js.map +1 -0
  109. package/lib/module/utils/index.js +17 -0
  110. package/lib/module/utils/index.js.map +1 -0
  111. package/lib/typescript/package.json +1 -0
  112. package/lib/typescript/src/esc/NativeXPrinterESC.d.ts +343 -0
  113. package/lib/typescript/src/esc/NativeXPrinterESC.d.ts.map +1 -0
  114. package/lib/typescript/src/esc/index.d.ts +122 -0
  115. package/lib/typescript/src/esc/index.d.ts.map +1 -0
  116. package/lib/typescript/src/index.d.ts +6 -0
  117. package/lib/typescript/src/index.d.ts.map +1 -0
  118. package/lib/typescript/src/printer/NativeXPrinterPrinter.d.ts +61 -0
  119. package/lib/typescript/src/printer/NativeXPrinterPrinter.d.ts.map +1 -0
  120. package/lib/typescript/src/printer/index.d.ts +32 -0
  121. package/lib/typescript/src/printer/index.d.ts.map +1 -0
  122. package/lib/typescript/src/tspl/NativeXPrinterTSPL.d.ts +261 -0
  123. package/lib/typescript/src/tspl/NativeXPrinterTSPL.d.ts.map +1 -0
  124. package/lib/typescript/src/tspl/index.d.ts +128 -0
  125. package/lib/typescript/src/tspl/index.d.ts.map +1 -0
  126. package/lib/typescript/src/type.d.ts +9 -0
  127. package/lib/typescript/src/type.d.ts.map +1 -0
  128. package/lib/typescript/src/util.d.ts +2 -0
  129. package/lib/typescript/src/util.d.ts.map +1 -0
  130. package/lib/typescript/src/utils/NativeXPrinterUtils.d.ts +10 -0
  131. package/lib/typescript/src/utils/NativeXPrinterUtils.d.ts.map +1 -0
  132. package/lib/typescript/src/utils/index.d.ts +9 -0
  133. package/lib/typescript/src/utils/index.d.ts.map +1 -0
  134. package/package.json +178 -0
  135. package/src/esc/NativeXPrinterESC.ts +516 -0
  136. package/src/esc/index.ts +489 -0
  137. package/src/index.ts +5 -0
  138. package/src/printer/NativeXPrinterPrinter.ts +84 -0
  139. package/src/printer/index.ts +160 -0
  140. package/src/tspl/NativeXPrinterTSPL.ts +388 -0
  141. package/src/tspl/index.ts +535 -0
  142. package/src/type.ts +11 -0
  143. package/src/util.ts +1 -0
  144. package/src/utils/NativeXPrinterUtils.ts +14 -0
  145. package/src/utils/index.ts +27 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Connexup
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
@@ -0,0 +1,23 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "NativeXPrinter"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => package["repository"]["url"], :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
17
+ s.public_header_files = "ios/PrinterSDK/Headers/**/*.h"
18
+ # s.private_header_files = "ios/**/*.h"
19
+ s.preserve_paths = 'ios/PrinterSDK/libPrinterSDK.a'
20
+ s.vendored_libraries = 'ios/PrinterSDK/libPrinterSDK.a'
21
+
22
+ install_modules_dependencies(s)
23
+ end
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # react-native-xprinter
2
+
3
+ XPrinter's SDK for React Native
4
+
5
+ ## Installation
6
+
7
+
8
+ ```sh
9
+ yarn add react-native-xprinter
10
+ ```
11
+
12
+ ## Contributing
13
+
14
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
15
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
16
+ - [Code of conduct](CODE_OF_CONDUCT.md)
17
+
18
+ ## License
19
+
20
+ MIT
21
+
22
+ ---
23
+
24
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,73 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['NativeXPrinter_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+
19
+ apply plugin: "com.android.library"
20
+ apply plugin: "kotlin-android"
21
+
22
+ apply plugin: "com.facebook.react"
23
+
24
+ def getExtOrIntegerDefault(name) {
25
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["NativeXPrinter_" + name]).toInteger()
26
+ }
27
+
28
+ android {
29
+ namespace "com.connexup.xprinter"
30
+
31
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
+
33
+ defaultConfig {
34
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
+ }
37
+
38
+ buildFeatures {
39
+ buildConfig true
40
+ }
41
+
42
+ buildTypes {
43
+ release {
44
+ minifyEnabled false
45
+ }
46
+ }
47
+
48
+ lint {
49
+ disable "GradleCompatible"
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_1_8
54
+ targetCompatibility JavaVersion.VERSION_1_8
55
+ }
56
+
57
+ sourceSets {
58
+ main {
59
+ java.srcDirs += [
60
+ "generated/java",
61
+ "generated/jni"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+
67
+ def kotlin_version = getExtOrDefault("kotlinVersion")
68
+
69
+ dependencies {
70
+ implementation fileTree(include: ['*.aar'], dir: 'libs')
71
+ implementation "com.facebook.react:react-android"
72
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
73
+ }
@@ -0,0 +1,5 @@
1
+ NativeXPrinter_kotlinVersion=2.0.21
2
+ NativeXPrinter_minSdkVersion=28
3
+ NativeXPrinter_targetSdkVersion=35
4
+ NativeXPrinter_compileSdkVersion=35
5
+ NativeXPrinter_ndkVersion=27.1.12297006
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,11 @@
1
+ package com.connexup.xprinter
2
+
3
+ /**
4
+ * Description:
5
+ * @author lukechen@chancetop.com
6
+ * @date 2026/2/5
7
+ */
8
+ const val PARAMS_ERROR = "PARAMS_ERROR"
9
+ const val COMMON_ERROR = "COMMON_ERROR"
10
+ const val PRINTER_NOT_FOUND_ERROR = "PRINTER_NOT_FOUND_ERROR"
11
+ const val NOT_YET_IMPLEMENTED_ERROR = "NOT_YET_IMPLEMENTED_ERROR"
@@ -0,0 +1,106 @@
1
+ package com.connexup.xprinter
2
+
3
+ import android.graphics.Bitmap
4
+ import android.graphics.BitmapFactory
5
+ import android.graphics.Color
6
+ import android.util.Base64
7
+ import androidx.core.graphics.scale
8
+ import kotlinx.coroutines.DelicateCoroutinesApi
9
+ import kotlinx.coroutines.Dispatchers
10
+ import kotlinx.coroutines.GlobalScope
11
+ import kotlinx.coroutines.launch
12
+ import kotlin.math.ceil
13
+
14
+ /**
15
+ * Description:
16
+ * @author lukechen@chancetop.com
17
+ * @date 2025/1/22
18
+ */
19
+
20
+ fun parseAddressData(str: String): ByteArray? {
21
+ val arr = str.split(".")
22
+ if (arr.size != 4) {
23
+ return null
24
+ }
25
+ return byteArrayOf(
26
+ arr[0].toInt().toByte(),
27
+ arr[1].toInt().toByte(),
28
+ arr[2].toInt().toByte(),
29
+ arr[3].toInt().toByte()
30
+ )
31
+ }
32
+
33
+ fun loadAndScaleBitmap(
34
+ bitmapContent: String?,
35
+ bitmapPath: String?,
36
+ width: Int,
37
+ ): Bitmap? {
38
+ val bitmap = loadBitmap(bitmapContent = bitmapContent, bitmapPath = bitmapPath)
39
+ if (bitmap == null) {
40
+ return null
41
+ }
42
+ if (bitmap.width == width) {
43
+ return bitmap
44
+ }
45
+ val scale = width.toFloat() / bitmap.width
46
+ val height = ceil((bitmap.height * scale)).toInt()
47
+ val scaledBitmap = bitmap.scale(width, height, true)
48
+ if (scaledBitmap != bitmap) {
49
+ GlobalScope.launch(Dispatchers.IO) {
50
+ try {
51
+ if (!bitmap.isRecycled) {
52
+ bitmap.recycle()
53
+ }
54
+ } catch (_: Exception) {
55
+ }
56
+ }
57
+ }
58
+ return scaledBitmap
59
+ }
60
+
61
+ fun isPureWhiteImage(
62
+ bitmapContent: String?,
63
+ bitmapPath: String?
64
+ ): Boolean {
65
+ val bitmap = loadBitmap(bitmapContent = bitmapContent, bitmapPath = bitmapPath)
66
+ ?: throw RuntimeException("Image is nil or failed to decode.")
67
+ val scaledBitmap = bitmap.scale(8, 8, false)
68
+ val w = scaledBitmap.width
69
+ val h = scaledBitmap.height
70
+ val pixels = IntArray(w * h)
71
+ scaledBitmap.getPixels(pixels, 0, w, 0, 0, w, h)
72
+ var result = true
73
+ for (c in pixels) {
74
+ val r = Color.red(c)
75
+ val g = Color.green(c)
76
+ val b = Color.blue(c)
77
+ if (r != 255 || g != 255 || b != 255) {
78
+ result = false
79
+ break
80
+ }
81
+ }
82
+ GlobalScope.launch(Dispatchers.IO) {
83
+ try {
84
+ if (!bitmap.isRecycled) {
85
+ bitmap.recycle()
86
+ }
87
+ if (!scaledBitmap.isRecycled) {
88
+ scaledBitmap.recycle()
89
+ }
90
+ } catch (_: Exception) {
91
+ }
92
+ }
93
+ return result
94
+ }
95
+
96
+ private fun loadBitmap(
97
+ bitmapContent: String?,
98
+ bitmapPath: String?,
99
+ ): Bitmap? {
100
+ return if (bitmapContent != null) {
101
+ val bytes = Base64.decode(bitmapContent, Base64.DEFAULT)
102
+ BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
103
+ } else {
104
+ BitmapFactory.decodeFile(bitmapPath)
105
+ }
106
+ }
@@ -0,0 +1,77 @@
1
+ package com.connexup.xprinter
2
+
3
+ import com.connexup.xprinter.esc.XPrinterESCModule
4
+ import com.connexup.xprinter.printer.XPrinterPrinterModule
5
+ import com.connexup.xprinter.tspl.XPrinterTSPLModule
6
+ import com.connexup.xprinter.utils.XPrinterUtilsModule
7
+ import com.facebook.react.BaseReactPackage
8
+ import com.facebook.react.bridge.NativeModule
9
+ import com.facebook.react.bridge.ReactApplicationContext
10
+ import com.facebook.react.module.model.ReactModuleInfo
11
+ import com.facebook.react.module.model.ReactModuleInfoProvider
12
+ import java.util.HashMap
13
+
14
+ class XPrinterPackage : BaseReactPackage() {
15
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
16
+ return when (name) {
17
+ XPrinterPrinterModule.NAME -> {
18
+ XPrinterPrinterModule(reactContext)
19
+ }
20
+
21
+ XPrinterESCModule.NAME -> {
22
+ XPrinterESCModule(reactContext)
23
+ }
24
+
25
+ XPrinterTSPLModule.NAME -> {
26
+ XPrinterTSPLModule(reactContext)
27
+ }
28
+
29
+ XPrinterUtilsModule.NAME -> {
30
+ XPrinterUtilsModule(reactContext)
31
+ }
32
+
33
+ else -> {
34
+ null
35
+ }
36
+ }
37
+ }
38
+
39
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
40
+ return ReactModuleInfoProvider {
41
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
42
+ moduleInfos[XPrinterPrinterModule.NAME] = ReactModuleInfo(
43
+ name = XPrinterPrinterModule.NAME,
44
+ className = XPrinterPrinterModule.NAME,
45
+ canOverrideExistingModule = false,
46
+ needsEagerInit = false,
47
+ isCxxModule = false,
48
+ isTurboModule = true
49
+ )
50
+ moduleInfos[XPrinterESCModule.NAME] = ReactModuleInfo(
51
+ name = XPrinterESCModule.NAME,
52
+ className = XPrinterESCModule.NAME,
53
+ canOverrideExistingModule = false,
54
+ needsEagerInit = false,
55
+ isCxxModule = false,
56
+ isTurboModule = true
57
+ )
58
+ moduleInfos[XPrinterTSPLModule.NAME] = ReactModuleInfo(
59
+ name = XPrinterTSPLModule.NAME,
60
+ className = XPrinterTSPLModule.NAME,
61
+ canOverrideExistingModule = false, // canOverrideExistingModule
62
+ needsEagerInit = false, // needsEagerInit
63
+ isCxxModule = false, // isCxxModule
64
+ isTurboModule = true // isTurboModule
65
+ )
66
+ moduleInfos[XPrinterUtilsModule.NAME] = ReactModuleInfo(
67
+ name = XPrinterUtilsModule.NAME,
68
+ className = XPrinterUtilsModule.NAME,
69
+ canOverrideExistingModule = false,
70
+ needsEagerInit = false,
71
+ isCxxModule = false,
72
+ isTurboModule = true
73
+ )
74
+ moduleInfos
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,211 @@
1
+ package com.connexup.xprinter.esc
2
+
3
+ import net.posprinter.POSConst
4
+
5
+ fun String.toCharSet(): String? {
6
+ return when (this) {
7
+ "GBK" -> "GBK"
8
+ "UTF-8" -> "UTF-8"
9
+ else -> null
10
+ }
11
+ }
12
+
13
+ fun String.toESCTextWidth(): Int? {
14
+ return when (this) {
15
+ "TXT_1_WIDTH" -> POSConst.TXT_1WIDTH
16
+ "TXT_2_WIDTH" -> POSConst.TXT_2WIDTH
17
+ "TXT_3_WIDTH" -> POSConst.TXT_3WIDTH
18
+ "TXT_4_WIDTH" -> POSConst.TXT_4WIDTH
19
+ "TXT_5_WIDTH" -> POSConst.TXT_5WIDTH
20
+ "TXT_6_WIDTH" -> POSConst.TXT_6WIDTH
21
+ "TXT_7_WIDTH" -> POSConst.TXT_7WIDTH
22
+ "TXT_8_WIDTH" -> POSConst.TXT_8WIDTH
23
+ else -> null
24
+ }
25
+ }
26
+
27
+ fun String.toESCTextHeight(): Int? {
28
+ return when (this) {
29
+ "TXT_1_HEIGHT" -> POSConst.TXT_1HEIGHT
30
+ "TXT_2_HEIGHT" -> POSConst.TXT_2HEIGHT
31
+ "TXT_3_HEIGHT" -> POSConst.TXT_3HEIGHT
32
+ "TXT_4_HEIGHT" -> POSConst.TXT_4HEIGHT
33
+ "TXT_5_HEIGHT" -> POSConst.TXT_5HEIGHT
34
+ "TXT_6_HEIGHT" -> POSConst.TXT_6HEIGHT
35
+ "TXT_7_HEIGHT" -> POSConst.TXT_7HEIGHT
36
+ "TXT_8_HEIGHT" -> POSConst.TXT_8HEIGHT
37
+ else -> null
38
+ }
39
+ }
40
+
41
+ fun String.toESCTextAttribute(): Int? {
42
+ return when (this) {
43
+ "DEFAULT" -> POSConst.FNT_DEFAULT
44
+ "FONTB" -> POSConst.FNT_FONTB
45
+ "BOLD" -> POSConst.FNT_BOLD
46
+ "REVERSE" -> POSConst.FNT_REVERSE
47
+ "UNDERLINE" -> POSConst.FNT_UNDERLINE
48
+ "UNDERLINE2" -> POSConst.FNT_UNDERLINE2
49
+ else -> null
50
+ }
51
+ }
52
+
53
+ fun String.toESCAlignment(): Int? {
54
+ return when (this) {
55
+ "LEFT" -> POSConst.ALIGNMENT_LEFT
56
+ "CENTER" -> POSConst.ALIGNMENT_CENTER
57
+ "RIGHT" -> POSConst.ALIGNMENT_RIGHT
58
+ else -> null
59
+ }
60
+ }
61
+
62
+ fun String.toESCBmpModel(): Int? {
63
+ return when (this) {
64
+ "NORMAL" -> POSConst.BMP_NORMAL
65
+ "WIDTH_DOUBLE" -> POSConst.BMP_WIDTH_DOUBLE
66
+ "HEIGHT_DOUBLE" -> POSConst.BMP_HEIGHT_DOUBLE
67
+ "WIDTH_HEIGHT_DOUBLE" -> POSConst.BMP_WIDTH_HEIGHT_DOUBLE
68
+ else -> null
69
+ }
70
+ }
71
+
72
+ fun String.toESCBarcodeType(): Int? {
73
+ return when (this) {
74
+ "UPCA" -> POSConst.BCS_UPCA
75
+ "UPCE" -> POSConst.BCS_UPCE
76
+ "EAN8" -> POSConst.BCS_EAN8
77
+ "EAN13" -> POSConst.BCS_EAN13
78
+ "JAN8" -> POSConst.BCS_JAN8
79
+ "JAN13" -> POSConst.BCS_JAN13
80
+ "ITF" -> POSConst.BCS_ITF
81
+ "CODEBAR" -> POSConst.BCS_Codabar
82
+ "CODE39" -> POSConst.BCS_Code39
83
+ "CODE93" -> POSConst.BCS_Code93
84
+ "CODE128" -> POSConst.BCS_Code128
85
+ else -> null
86
+ }
87
+ }
88
+
89
+ fun String.toESCTextPosition(): Int? {
90
+ return when (this) {
91
+ "NONE" -> POSConst.HRI_TEXT_NONE
92
+ "ABOVE" -> POSConst.HRI_TEXT_ABOVE
93
+ "BELOW" -> POSConst.HRI_TEXT_BELOW
94
+ "BOTH" -> POSConst.HRI_TEXT_BOTH
95
+ else -> null
96
+ }
97
+ }
98
+
99
+ fun String.toESCPrinterCheckType(): Int? {
100
+ return when (this) {
101
+ "PRINT" -> POSConst.STS_TYPE_PRINT
102
+ "OFFLINE" -> POSConst.STS_TYPE_OFFLINE
103
+ "ERR" -> POSConst.STS_TYPE_ERR
104
+ "PAPER" -> POSConst.STS_TYPE_PAPER
105
+ else -> null
106
+ }
107
+ }
108
+
109
+ fun Int.toESCPrinterCheckStatus(): String {
110
+ return when (this) {
111
+ -2 -> "START_READ_LOOP_RETURN"
112
+ -3 -> "DISCONNECT"
113
+ -4 -> "TIMEOUT"
114
+ else -> "UNKNOWN"
115
+ }
116
+ }
117
+
118
+
119
+ fun Int.toESCPrinterStatus(): String {
120
+ return when (this) {
121
+ POSConst.STS_NORMAL -> "NORMAL"
122
+ POSConst.STS_COVEROPEN -> "COVER_OPEN"
123
+ POSConst.STS_PRESS_FEED -> "PRESS_FEED"
124
+ POSConst.STS_PAPEREMPTY -> "PAPER_EMPTY"
125
+ POSConst.STS_PRINTER_ERR -> "PRINTER_ERR"
126
+ 54 -> "COVER_OPEN_AND_PAPER_EMPTY"
127
+ -1 -> "OTHER_ERROR"
128
+ -3 -> "DISCONNECT"
129
+ -4 -> "TIMEOUT"
130
+ else -> "UNKNOWN"
131
+ }
132
+ }
133
+
134
+ fun Int.toESCPrinterStatusII(): String {
135
+ return when (this) {
136
+ 0 -> "NORMAL"
137
+ 1 -> "PRINTING"
138
+ 2 -> "COVER_OPEN"
139
+ 4 -> "PAPER_EMPTY"
140
+ 8 -> "PAPER_IS_OVER"
141
+ 16 -> "MONEY_BOX_OPEN"
142
+ 32 -> "OTHER_ERROR"
143
+ 64 -> "CUTTING_ERROR"
144
+ 128 -> "PRINT_HEAD_OVERHEATING"
145
+ -3 -> "DISCONNECT"
146
+ -4 -> "TIMEOUT"
147
+ else -> "UNKNOWN"
148
+ }
149
+ }
150
+
151
+ fun String.toESCECLevel(): Int? {
152
+ return when (this) {
153
+ "LEVEL_L" -> POSConst.QRCODE_EC_LEVEL_L
154
+ "LEVEL_M" -> POSConst.QRCODE_EC_LEVEL_M
155
+ "LEVEL_Q" -> POSConst.QRCODE_EC_LEVEL_Q
156
+ "LEVEL_H" -> POSConst.QRCODE_EC_LEVEL_H
157
+ else -> null
158
+ }
159
+ }
160
+
161
+ fun String.toESCCutModel(): Int? {
162
+ return when (this) {
163
+ "CUT_ALL" -> POSConst.CUT_ALL
164
+ "CUT_HALF" -> POSConst.CUT_HALF
165
+ else -> null
166
+ }
167
+ }
168
+
169
+ fun String.toESCDirection(): Int? {
170
+ return when (this) {
171
+ "LEFT_TOP" -> POSConst.DIRECTION_LEFT_TOP
172
+ "LEFT_BOTTOM" -> POSConst.DIRECTION_LEFT_BOTTOM
173
+ "RIGHT_BOTTOM" -> POSConst.DIRECTION_RIGHT_BOTTOM
174
+ "RIGHT_TOP" -> POSConst.DIRECTION_RIGHT_TOP
175
+ else -> null
176
+ }
177
+ }
178
+
179
+ fun String.toESCSelectBitmapModel(): Int? {
180
+ return when (this) {
181
+ "SINGLE_DENSITY_8" -> POSConst.SINGLE_DENSITY_8
182
+ "DOUBLE_DENSITY_8" -> POSConst.DOUBLE_DENSITY_8
183
+ "SINGLE_DENSITY_24" -> POSConst.SINGLE_DENSITY_24
184
+ "DOUBLE_DENSITY_24" -> POSConst.DOUBLE_DENSITY_24
185
+ else -> null
186
+ }
187
+ }
188
+
189
+ fun String.toESCFontType(): Int? {
190
+ return when (this) {
191
+ "STANDARD" -> POSConst.FONT_STANDARD
192
+ "COMPRESS" -> POSConst.FONT_COMPRESS
193
+ else -> null
194
+ }
195
+ }
196
+
197
+ fun String.toESCWifiEncrypt(): Byte? {
198
+ return when (this) {
199
+ "NULL" -> POSConst.ENCRYPT_NULL
200
+ "WEP64" -> POSConst.ENCRYPT_WEP64
201
+ "WEP128" -> POSConst.ENCRYPT_WEP128
202
+ "WPA_AES_PSK" -> POSConst.ENCRYPT_WPA_AES_PSK
203
+ "WPA_TKIP_PSK" -> POSConst.ENCRYPT_WPA_TKIP_PSK
204
+ "WPA_TKIP_AES_PSK" -> POSConst.ENCRYPT_WPA_TKIP_AES_PSK
205
+ "WPA2_AES_PSK" -> POSConst.ENCRYPT_WPA2_AES_PSK
206
+ "WPA2_TKIP" -> POSConst.ENCRYPT_WPA2_TKIP
207
+ "WPA2_TKIP_AES_PSK" -> POSConst.ENCRYPT_WPA2_TKIP_AES_PSK
208
+ "WPA_WPA2_MixedMode" -> POSConst.ENCRYPT_WPA_WPA2_MixedMode
209
+ else -> null
210
+ }
211
+ }