spec-cat 0.1.0 → 0.1.2

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 (110) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/_nuxt/{Bqlz6CoK.js → BE_75kPa.js} +1 -1
  3. package/.output/public/_nuxt/{B2wdmh_w.js → BJ7m4fRW.js} +53 -53
  4. package/.output/public/_nuxt/{KNuzSjk0.js → CCNYUZ9m.js} +1 -1
  5. package/.output/public/_nuxt/{BvosqTnx.js → DGtcdWVl.js} +1 -1
  6. package/.output/public/_nuxt/DxEx-kFx.js +1 -0
  7. package/.output/public/_nuxt/{BwcbSlWF.js → DyMq_cQC.js} +2 -2
  8. package/.output/public/_nuxt/{COTT6rNZ.js → _cj5lOdZ.js} +1 -1
  9. package/.output/public/_nuxt/builds/latest.json +1 -1
  10. package/.output/public/_nuxt/builds/meta/3a0aacc1-0bd1-4d15-8b8a-3cee48cbfc69.json +1 -0
  11. package/.output/public/_nuxt/{BUOk7wkI.js → gDut6QrP.js} +1 -1
  12. package/.output/public/_nuxt/{C5wk2twv.js → nJpWpjzg.js} +1 -1
  13. package/.output/public/_nuxt/{DBab5Zcv.js → waQ9fPC1.js} +1 -1
  14. package/.output/server/chunks/_/codexProvider.mjs +64 -18
  15. package/.output/server/chunks/_/codexProvider.mjs.map +1 -1
  16. package/.output/server/chunks/build/client.precomputed.mjs +1 -1
  17. package/.output/server/chunks/build/client.precomputed.mjs.map +1 -1
  18. package/.output/server/chunks/nitro/nitro.mjs +702 -703
  19. package/.output/server/chunks/routes/_ws.mjs +37 -7
  20. package/.output/server/chunks/routes/_ws.mjs.map +1 -1
  21. package/.output/server/node_modules/@huggingface/jinja/dist/index.js +1572 -0
  22. package/.output/server/node_modules/@huggingface/jinja/package.json +55 -0
  23. package/.output/server/node_modules/@xenova/transformers/package.json +84 -0
  24. package/.output/server/node_modules/@xenova/transformers/src/backends/onnx.js +50 -0
  25. package/.output/server/node_modules/@xenova/transformers/src/configs.js +107 -0
  26. package/.output/server/node_modules/@xenova/transformers/src/env.js +128 -0
  27. package/.output/server/node_modules/@xenova/transformers/src/models.js +6267 -0
  28. package/.output/server/node_modules/@xenova/transformers/src/pipelines.js +3287 -0
  29. package/.output/server/node_modules/@xenova/transformers/src/processors.js +2248 -0
  30. package/.output/server/node_modules/@xenova/transformers/src/tokenizers.js +4479 -0
  31. package/.output/server/node_modules/@xenova/transformers/src/transformers.js +24 -0
  32. package/.output/server/node_modules/@xenova/transformers/src/utils/audio.js +672 -0
  33. package/.output/server/node_modules/@xenova/transformers/src/utils/core.js +175 -0
  34. package/.output/server/node_modules/@xenova/transformers/src/utils/data-structures.js +415 -0
  35. package/.output/server/node_modules/@xenova/transformers/src/utils/generation.js +873 -0
  36. package/.output/server/node_modules/@xenova/transformers/src/utils/hub.js +658 -0
  37. package/.output/server/node_modules/@xenova/transformers/src/utils/image.js +731 -0
  38. package/.output/server/node_modules/@xenova/transformers/src/utils/maths.js +985 -0
  39. package/.output/server/node_modules/@xenova/transformers/src/utils/tensor.js +1239 -0
  40. package/.output/server/node_modules/color/index.js +496 -0
  41. package/.output/server/node_modules/color/package.json +47 -0
  42. package/.output/server/node_modules/color-convert/conversions.js +839 -0
  43. package/.output/server/node_modules/color-convert/index.js +81 -0
  44. package/.output/server/node_modules/color-convert/package.json +48 -0
  45. package/.output/server/node_modules/color-convert/route.js +97 -0
  46. package/.output/server/node_modules/color-name/index.js +152 -0
  47. package/.output/server/node_modules/color-name/package.json +28 -0
  48. package/.output/server/node_modules/color-string/index.js +242 -0
  49. package/.output/server/node_modules/color-string/package.json +39 -0
  50. package/.output/server/node_modules/detect-libc/lib/detect-libc.js +313 -0
  51. package/.output/server/node_modules/detect-libc/lib/elf.js +39 -0
  52. package/.output/server/node_modules/detect-libc/lib/filesystem.js +51 -0
  53. package/.output/server/node_modules/detect-libc/lib/process.js +24 -0
  54. package/.output/server/node_modules/detect-libc/package.json +44 -0
  55. package/.output/server/node_modules/is-arrayish/index.js +9 -0
  56. package/.output/server/node_modules/is-arrayish/package.json +45 -0
  57. package/.output/server/node_modules/onnxruntime-common/dist/ort-common.node.js +7 -0
  58. package/.output/server/node_modules/onnxruntime-common/package.json +31 -0
  59. package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/darwin/arm64/onnxruntime_binding.node +0 -0
  60. package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/darwin/x64/onnxruntime_binding.node +0 -0
  61. package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/linux/arm64/libonnxruntime.so.1.14.0 +0 -0
  62. package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/linux/arm64/onnxruntime_binding.node +0 -0
  63. package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/linux/x64/libonnxruntime.so.1.14.0 +0 -0
  64. package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/linux/x64/onnxruntime_binding.node +0 -0
  65. package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/win32/arm64/onnxruntime_binding.node +0 -0
  66. package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/win32/x64/onnxruntime_binding.node +0 -0
  67. package/.output/server/node_modules/onnxruntime-node/dist/backend.js +75 -0
  68. package/.output/server/node_modules/onnxruntime-node/dist/binding.js +10 -0
  69. package/.output/server/node_modules/onnxruntime-node/dist/index.js +23 -0
  70. package/.output/server/node_modules/onnxruntime-node/package.json +58 -0
  71. package/.output/server/node_modules/onnxruntime-web/dist/ort-web.node.js +7 -0
  72. package/.output/server/node_modules/onnxruntime-web/package.json +84 -0
  73. package/.output/server/node_modules/semver/classes/semver.js +333 -0
  74. package/.output/server/node_modules/semver/functions/coerce.js +62 -0
  75. package/.output/server/node_modules/semver/functions/compare.js +7 -0
  76. package/.output/server/node_modules/semver/functions/gte.js +5 -0
  77. package/.output/server/node_modules/semver/functions/parse.js +18 -0
  78. package/.output/server/node_modules/semver/internal/constants.js +37 -0
  79. package/.output/server/node_modules/semver/internal/debug.js +11 -0
  80. package/.output/server/node_modules/semver/internal/identifiers.js +29 -0
  81. package/.output/server/node_modules/semver/internal/parse-options.js +17 -0
  82. package/.output/server/node_modules/semver/internal/re.js +223 -0
  83. package/.output/server/node_modules/semver/package.json +78 -0
  84. package/.output/server/node_modules/sharp/build/Release/sharp-linux-x64.node +0 -0
  85. package/.output/server/node_modules/sharp/lib/channel.js +174 -0
  86. package/.output/server/node_modules/sharp/lib/colour.js +184 -0
  87. package/.output/server/node_modules/sharp/lib/composite.js +210 -0
  88. package/.output/server/node_modules/sharp/lib/constructor.js +439 -0
  89. package/.output/server/node_modules/sharp/lib/index.js +16 -0
  90. package/.output/server/node_modules/sharp/lib/input.js +631 -0
  91. package/.output/server/node_modules/sharp/lib/is.js +155 -0
  92. package/.output/server/node_modules/sharp/lib/libvips.js +140 -0
  93. package/.output/server/node_modules/sharp/lib/operation.js +919 -0
  94. package/.output/server/node_modules/sharp/lib/output.js +1413 -0
  95. package/.output/server/node_modules/sharp/lib/platform.js +30 -0
  96. package/.output/server/node_modules/sharp/lib/resize.js +582 -0
  97. package/.output/server/node_modules/sharp/lib/sharp.js +38 -0
  98. package/.output/server/node_modules/sharp/lib/utility.js +287 -0
  99. package/.output/server/node_modules/sharp/package.json +204 -0
  100. package/.output/server/node_modules/sharp/vendor/8.14.5/linux-x64/THIRD-PARTY-NOTICES.md +43 -0
  101. package/.output/server/node_modules/sharp/vendor/8.14.5/linux-x64/lib/libvips-cpp.so.42 +0 -0
  102. package/.output/server/node_modules/sharp/vendor/8.14.5/linux-x64/platform.json +1 -0
  103. package/.output/server/node_modules/sharp/vendor/8.14.5/linux-x64/versions.json +31 -0
  104. package/.output/server/node_modules/simple-swizzle/index.js +29 -0
  105. package/.output/server/node_modules/simple-swizzle/package.json +36 -0
  106. package/.output/server/package.json +15 -1
  107. package/README.md +2 -0
  108. package/package.json +12 -19
  109. package/.output/public/_nuxt/5FxpIoe_.js +0 -1
  110. package/.output/public/_nuxt/builds/meta/21578a05-1b7e-4847-a8ff-7480800ea4a6.json +0 -1
@@ -0,0 +1,223 @@
1
+ 'use strict'
2
+
3
+ const {
4
+ MAX_SAFE_COMPONENT_LENGTH,
5
+ MAX_SAFE_BUILD_LENGTH,
6
+ MAX_LENGTH,
7
+ } = require('./constants')
8
+ const debug = require('./debug')
9
+ exports = module.exports = {}
10
+
11
+ // The actual regexps go on exports.re
12
+ const re = exports.re = []
13
+ const safeRe = exports.safeRe = []
14
+ const src = exports.src = []
15
+ const safeSrc = exports.safeSrc = []
16
+ const t = exports.t = {}
17
+ let R = 0
18
+
19
+ const LETTERDASHNUMBER = '[a-zA-Z0-9-]'
20
+
21
+ // Replace some greedy regex tokens to prevent regex dos issues. These regex are
22
+ // used internally via the safeRe object since all inputs in this library get
23
+ // normalized first to trim and collapse all extra whitespace. The original
24
+ // regexes are exported for userland consumption and lower level usage. A
25
+ // future breaking change could export the safer regex only with a note that
26
+ // all input should have extra whitespace removed.
27
+ const safeRegexReplacements = [
28
+ ['\\s', 1],
29
+ ['\\d', MAX_LENGTH],
30
+ [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
31
+ ]
32
+
33
+ const makeSafeRegex = (value) => {
34
+ for (const [token, max] of safeRegexReplacements) {
35
+ value = value
36
+ .split(`${token}*`).join(`${token}{0,${max}}`)
37
+ .split(`${token}+`).join(`${token}{1,${max}}`)
38
+ }
39
+ return value
40
+ }
41
+
42
+ const createToken = (name, value, isGlobal) => {
43
+ const safe = makeSafeRegex(value)
44
+ const index = R++
45
+ debug(name, index, value)
46
+ t[name] = index
47
+ src[index] = value
48
+ safeSrc[index] = safe
49
+ re[index] = new RegExp(value, isGlobal ? 'g' : undefined)
50
+ safeRe[index] = new RegExp(safe, isGlobal ? 'g' : undefined)
51
+ }
52
+
53
+ // The following Regular Expressions can be used for tokenizing,
54
+ // validating, and parsing SemVer version strings.
55
+
56
+ // ## Numeric Identifier
57
+ // A single `0`, or a non-zero digit followed by zero or more digits.
58
+
59
+ createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*')
60
+ createToken('NUMERICIDENTIFIERLOOSE', '\\d+')
61
+
62
+ // ## Non-numeric Identifier
63
+ // Zero or more digits, followed by a letter or hyphen, and then zero or
64
+ // more letters, digits, or hyphens.
65
+
66
+ createToken('NONNUMERICIDENTIFIER', `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`)
67
+
68
+ // ## Main Version
69
+ // Three dot-separated numeric identifiers.
70
+
71
+ createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
72
+ `(${src[t.NUMERICIDENTIFIER]})\\.` +
73
+ `(${src[t.NUMERICIDENTIFIER]})`)
74
+
75
+ createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
76
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
77
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})`)
78
+
79
+ // ## Pre-release Version Identifier
80
+ // A numeric identifier, or a non-numeric identifier.
81
+ // Non-numberic identifiers include numberic identifiers but can be longer.
82
+ // Therefore non-numberic identifiers must go first.
83
+
84
+ createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NONNUMERICIDENTIFIER]
85
+ }|${src[t.NUMERICIDENTIFIER]})`)
86
+
87
+ createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NONNUMERICIDENTIFIER]
88
+ }|${src[t.NUMERICIDENTIFIERLOOSE]})`)
89
+
90
+ // ## Pre-release Version
91
+ // Hyphen, followed by one or more dot-separated pre-release version
92
+ // identifiers.
93
+
94
+ createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
95
+ }(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`)
96
+
97
+ createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
98
+ }(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`)
99
+
100
+ // ## Build Metadata Identifier
101
+ // Any combination of digits, letters, or hyphens.
102
+
103
+ createToken('BUILDIDENTIFIER', `${LETTERDASHNUMBER}+`)
104
+
105
+ // ## Build Metadata
106
+ // Plus sign, followed by one or more period-separated build metadata
107
+ // identifiers.
108
+
109
+ createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
110
+ }(?:\\.${src[t.BUILDIDENTIFIER]})*))`)
111
+
112
+ // ## Full Version String
113
+ // A main version, followed optionally by a pre-release version and
114
+ // build metadata.
115
+
116
+ // Note that the only major, minor, patch, and pre-release sections of
117
+ // the version string are capturing groups. The build metadata is not a
118
+ // capturing group, because it should not ever be used in version
119
+ // comparison.
120
+
121
+ createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
122
+ }${src[t.PRERELEASE]}?${
123
+ src[t.BUILD]}?`)
124
+
125
+ createToken('FULL', `^${src[t.FULLPLAIN]}$`)
126
+
127
+ // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
128
+ // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
129
+ // common in the npm registry.
130
+ createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
131
+ }${src[t.PRERELEASELOOSE]}?${
132
+ src[t.BUILD]}?`)
133
+
134
+ createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`)
135
+
136
+ createToken('GTLT', '((?:<|>)?=?)')
137
+
138
+ // Something like "2.*" or "1.2.x".
139
+ // Note that "x.x" is a valid xRange identifer, meaning "any version"
140
+ // Only the first item is strictly required.
141
+ createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`)
142
+ createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`)
143
+
144
+ createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
145
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
146
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
147
+ `(?:${src[t.PRERELEASE]})?${
148
+ src[t.BUILD]}?` +
149
+ `)?)?`)
150
+
151
+ createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
152
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
153
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
154
+ `(?:${src[t.PRERELEASELOOSE]})?${
155
+ src[t.BUILD]}?` +
156
+ `)?)?`)
157
+
158
+ createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`)
159
+ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`)
160
+
161
+ // Coercion.
162
+ // Extract anything that could conceivably be a part of a valid semver
163
+ createToken('COERCEPLAIN', `${'(^|[^\\d])' +
164
+ '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
165
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
166
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`)
167
+ createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`)
168
+ createToken('COERCEFULL', src[t.COERCEPLAIN] +
169
+ `(?:${src[t.PRERELEASE]})?` +
170
+ `(?:${src[t.BUILD]})?` +
171
+ `(?:$|[^\\d])`)
172
+ createToken('COERCERTL', src[t.COERCE], true)
173
+ createToken('COERCERTLFULL', src[t.COERCEFULL], true)
174
+
175
+ // Tilde ranges.
176
+ // Meaning is "reasonably at or greater than"
177
+ createToken('LONETILDE', '(?:~>?)')
178
+
179
+ createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true)
180
+ exports.tildeTrimReplace = '$1~'
181
+
182
+ createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`)
183
+ createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`)
184
+
185
+ // Caret ranges.
186
+ // Meaning is "at least and backwards compatible with"
187
+ createToken('LONECARET', '(?:\\^)')
188
+
189
+ createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true)
190
+ exports.caretTrimReplace = '$1^'
191
+
192
+ createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`)
193
+ createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`)
194
+
195
+ // A simple gt/lt/eq thing, or just "" to indicate "any version"
196
+ createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`)
197
+ createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`)
198
+
199
+ // An expression to strip any whitespace between the gtlt and the thing
200
+ // it modifies, so that `> 1.2.3` ==> `>1.2.3`
201
+ createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
202
+ }\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true)
203
+ exports.comparatorTrimReplace = '$1$2$3'
204
+
205
+ // Something like `1.2.3 - 1.2.4`
206
+ // Note that these all use the loose form, because they'll be
207
+ // checked against either the strict or loose comparator form
208
+ // later.
209
+ createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
210
+ `\\s+-\\s+` +
211
+ `(${src[t.XRANGEPLAIN]})` +
212
+ `\\s*$`)
213
+
214
+ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
215
+ `\\s+-\\s+` +
216
+ `(${src[t.XRANGEPLAINLOOSE]})` +
217
+ `\\s*$`)
218
+
219
+ // Star ranges basically just allow anything at all.
220
+ createToken('STAR', '(<|>)?=?\\s*\\*')
221
+ // >=0.0.0 is like a star
222
+ createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$')
223
+ createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$')
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "semver",
3
+ "version": "7.7.3",
4
+ "description": "The semantic version parser used by npm.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "tap",
8
+ "snap": "tap",
9
+ "lint": "npm run eslint",
10
+ "postlint": "template-oss-check",
11
+ "lintfix": "npm run eslint -- --fix",
12
+ "posttest": "npm run lint",
13
+ "template-oss-apply": "template-oss-apply --force",
14
+ "eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
15
+ },
16
+ "devDependencies": {
17
+ "@npmcli/eslint-config": "^5.0.0",
18
+ "@npmcli/template-oss": "4.25.1",
19
+ "benchmark": "^2.1.4",
20
+ "tap": "^16.0.0"
21
+ },
22
+ "license": "ISC",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/npm/node-semver.git"
26
+ },
27
+ "bin": {
28
+ "semver": "bin/semver.js"
29
+ },
30
+ "files": [
31
+ "bin/",
32
+ "lib/",
33
+ "classes/",
34
+ "functions/",
35
+ "internal/",
36
+ "ranges/",
37
+ "index.js",
38
+ "preload.js",
39
+ "range.bnf"
40
+ ],
41
+ "tap": {
42
+ "timeout": 30,
43
+ "coverage-map": "map.js",
44
+ "nyc-arg": [
45
+ "--exclude",
46
+ "tap-snapshots/**"
47
+ ]
48
+ },
49
+ "engines": {
50
+ "node": ">=10"
51
+ },
52
+ "author": "GitHub Inc.",
53
+ "templateOSS": {
54
+ "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
55
+ "version": "4.25.1",
56
+ "engines": ">=10",
57
+ "distPaths": [
58
+ "classes/",
59
+ "functions/",
60
+ "internal/",
61
+ "ranges/",
62
+ "index.js",
63
+ "preload.js",
64
+ "range.bnf"
65
+ ],
66
+ "allowPaths": [
67
+ "/classes/",
68
+ "/functions/",
69
+ "/internal/",
70
+ "/ranges/",
71
+ "/index.js",
72
+ "/preload.js",
73
+ "/range.bnf",
74
+ "/benchmarks"
75
+ ],
76
+ "publish": "true"
77
+ }
78
+ }
@@ -0,0 +1,174 @@
1
+ // Copyright 2013 Lovell Fuller and others.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ 'use strict';
5
+
6
+ const is = require('./is');
7
+
8
+ /**
9
+ * Boolean operations for bandbool.
10
+ * @private
11
+ */
12
+ const bool = {
13
+ and: 'and',
14
+ or: 'or',
15
+ eor: 'eor'
16
+ };
17
+
18
+ /**
19
+ * Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
20
+ *
21
+ * See also {@link /api-operation#flatten|flatten}.
22
+ *
23
+ * @example
24
+ * sharp('rgba.png')
25
+ * .removeAlpha()
26
+ * .toFile('rgb.png', function(err, info) {
27
+ * // rgb.png is a 3 channel image without an alpha channel
28
+ * });
29
+ *
30
+ * @returns {Sharp}
31
+ */
32
+ function removeAlpha () {
33
+ this.options.removeAlpha = true;
34
+ return this;
35
+ }
36
+
37
+ /**
38
+ * Ensure the output image has an alpha transparency channel.
39
+ * If missing, the added alpha channel will have the specified
40
+ * transparency level, defaulting to fully-opaque (1).
41
+ * This is a no-op if the image already has an alpha channel.
42
+ *
43
+ * @since 0.21.2
44
+ *
45
+ * @example
46
+ * // rgba.png will be a 4 channel image with a fully-opaque alpha channel
47
+ * await sharp('rgb.jpg')
48
+ * .ensureAlpha()
49
+ * .toFile('rgba.png')
50
+ *
51
+ * @example
52
+ * // rgba is a 4 channel image with a fully-transparent alpha channel
53
+ * const rgba = await sharp(rgb)
54
+ * .ensureAlpha(0)
55
+ * .toBuffer();
56
+ *
57
+ * @param {number} [alpha=1] - alpha transparency level (0=fully-transparent, 1=fully-opaque)
58
+ * @returns {Sharp}
59
+ * @throws {Error} Invalid alpha transparency level
60
+ */
61
+ function ensureAlpha (alpha) {
62
+ if (is.defined(alpha)) {
63
+ if (is.number(alpha) && is.inRange(alpha, 0, 1)) {
64
+ this.options.ensureAlpha = alpha;
65
+ } else {
66
+ throw is.invalidParameterError('alpha', 'number between 0 and 1', alpha);
67
+ }
68
+ } else {
69
+ this.options.ensureAlpha = 1;
70
+ }
71
+ return this;
72
+ }
73
+
74
+ /**
75
+ * Extract a single channel from a multi-channel image.
76
+ *
77
+ * @example
78
+ * // green.jpg is a greyscale image containing the green channel of the input
79
+ * await sharp(input)
80
+ * .extractChannel('green')
81
+ * .toFile('green.jpg');
82
+ *
83
+ * @example
84
+ * // red1 is the red value of the first pixel, red2 the second pixel etc.
85
+ * const [red1, red2, ...] = await sharp(input)
86
+ * .extractChannel(0)
87
+ * .raw()
88
+ * .toBuffer();
89
+ *
90
+ * @param {number|string} channel - zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.
91
+ * @returns {Sharp}
92
+ * @throws {Error} Invalid channel
93
+ */
94
+ function extractChannel (channel) {
95
+ const channelMap = { red: 0, green: 1, blue: 2, alpha: 3 };
96
+ if (Object.keys(channelMap).includes(channel)) {
97
+ channel = channelMap[channel];
98
+ }
99
+ if (is.integer(channel) && is.inRange(channel, 0, 4)) {
100
+ this.options.extractChannel = channel;
101
+ } else {
102
+ throw is.invalidParameterError('channel', 'integer or one of: red, green, blue, alpha', channel);
103
+ }
104
+ return this;
105
+ }
106
+
107
+ /**
108
+ * Join one or more channels to the image.
109
+ * The meaning of the added channels depends on the output colourspace, set with `toColourspace()`.
110
+ * By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
111
+ * Channel ordering follows vips convention:
112
+ * - sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
113
+ * - CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
114
+ *
115
+ * Buffers may be any of the image formats supported by sharp.
116
+ * For raw pixel input, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor.
117
+ *
118
+ * @param {Array<string|Buffer>|string|Buffer} images - one or more images (file paths, Buffers).
119
+ * @param {Object} options - image options, see `sharp()` constructor.
120
+ * @returns {Sharp}
121
+ * @throws {Error} Invalid parameters
122
+ */
123
+ function joinChannel (images, options) {
124
+ if (Array.isArray(images)) {
125
+ images.forEach(function (image) {
126
+ this.options.joinChannelIn.push(this._createInputDescriptor(image, options));
127
+ }, this);
128
+ } else {
129
+ this.options.joinChannelIn.push(this._createInputDescriptor(images, options));
130
+ }
131
+ return this;
132
+ }
133
+
134
+ /**
135
+ * Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.
136
+ *
137
+ * @example
138
+ * sharp('3-channel-rgb-input.png')
139
+ * .bandbool(sharp.bool.and)
140
+ * .toFile('1-channel-output.png', function (err, info) {
141
+ * // The output will be a single channel image where each pixel `P = R & G & B`.
142
+ * // If `I(1,1) = [247, 170, 14] = [0b11110111, 0b10101010, 0b00001111]`
143
+ * // then `O(1,1) = 0b11110111 & 0b10101010 & 0b00001111 = 0b00000010 = 2`.
144
+ * });
145
+ *
146
+ * @param {string} boolOp - one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
147
+ * @returns {Sharp}
148
+ * @throws {Error} Invalid parameters
149
+ */
150
+ function bandbool (boolOp) {
151
+ if (is.string(boolOp) && is.inArray(boolOp, ['and', 'or', 'eor'])) {
152
+ this.options.bandBoolOp = boolOp;
153
+ } else {
154
+ throw is.invalidParameterError('boolOp', 'one of: and, or, eor', boolOp);
155
+ }
156
+ return this;
157
+ }
158
+
159
+ /**
160
+ * Decorate the Sharp prototype with channel-related functions.
161
+ * @private
162
+ */
163
+ module.exports = function (Sharp) {
164
+ Object.assign(Sharp.prototype, {
165
+ // Public instance functions
166
+ removeAlpha,
167
+ ensureAlpha,
168
+ extractChannel,
169
+ joinChannel,
170
+ bandbool
171
+ });
172
+ // Class attributes
173
+ Sharp.bool = bool;
174
+ };
@@ -0,0 +1,184 @@
1
+ // Copyright 2013 Lovell Fuller and others.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ 'use strict';
5
+
6
+ const color = require('color');
7
+ const is = require('./is');
8
+
9
+ /**
10
+ * Colourspaces.
11
+ * @private
12
+ */
13
+ const colourspace = {
14
+ multiband: 'multiband',
15
+ 'b-w': 'b-w',
16
+ bw: 'b-w',
17
+ cmyk: 'cmyk',
18
+ srgb: 'srgb'
19
+ };
20
+
21
+ /**
22
+ * Tint the image using the provided chroma while preserving the image luminance.
23
+ * An alpha channel may be present and will be unchanged by the operation.
24
+ *
25
+ * @example
26
+ * const output = await sharp(input)
27
+ * .tint({ r: 255, g: 240, b: 16 })
28
+ * .toBuffer();
29
+ *
30
+ * @param {string|Object} rgb - parsed by the [color](https://www.npmjs.org/package/color) module to extract chroma values.
31
+ * @returns {Sharp}
32
+ * @throws {Error} Invalid parameter
33
+ */
34
+ function tint (rgb) {
35
+ const colour = color(rgb);
36
+ this.options.tintA = colour.a();
37
+ this.options.tintB = colour.b();
38
+ return this;
39
+ }
40
+
41
+ /**
42
+ * Convert to 8-bit greyscale; 256 shades of grey.
43
+ * This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
44
+ * By default the output image will be web-friendly sRGB and contain three (identical) color channels.
45
+ * This may be overridden by other sharp operations such as `toColourspace('b-w')`,
46
+ * which will produce an output image containing one color channel.
47
+ * An alpha channel may be present, and will be unchanged by the operation.
48
+ *
49
+ * @example
50
+ * const output = await sharp(input).greyscale().toBuffer();
51
+ *
52
+ * @param {Boolean} [greyscale=true]
53
+ * @returns {Sharp}
54
+ */
55
+ function greyscale (greyscale) {
56
+ this.options.greyscale = is.bool(greyscale) ? greyscale : true;
57
+ return this;
58
+ }
59
+
60
+ /**
61
+ * Alternative spelling of `greyscale`.
62
+ * @param {Boolean} [grayscale=true]
63
+ * @returns {Sharp}
64
+ */
65
+ function grayscale (grayscale) {
66
+ return this.greyscale(grayscale);
67
+ }
68
+
69
+ /**
70
+ * Set the pipeline colourspace.
71
+ *
72
+ * The input image will be converted to the provided colourspace at the start of the pipeline.
73
+ * All operations will use this colourspace before converting to the output colourspace,
74
+ * as defined by {@link #tocolourspace|toColourspace}.
75
+ *
76
+ * This feature is experimental and has not yet been fully-tested with all operations.
77
+ *
78
+ * @since 0.29.0
79
+ *
80
+ * @example
81
+ * // Run pipeline in 16 bits per channel RGB while converting final result to 8 bits per channel sRGB.
82
+ * await sharp(input)
83
+ * .pipelineColourspace('rgb16')
84
+ * .toColourspace('srgb')
85
+ * .toFile('16bpc-pipeline-to-8bpc-output.png')
86
+ *
87
+ * @param {string} [colourspace] - pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://github.com/libvips/libvips/blob/41cff4e9d0838498487a00623462204eb10ee5b8/libvips/iofuncs/enumtypes.c#L774)
88
+ * @returns {Sharp}
89
+ * @throws {Error} Invalid parameters
90
+ */
91
+ function pipelineColourspace (colourspace) {
92
+ if (!is.string(colourspace)) {
93
+ throw is.invalidParameterError('colourspace', 'string', colourspace);
94
+ }
95
+ this.options.colourspaceInput = colourspace;
96
+ return this;
97
+ }
98
+
99
+ /**
100
+ * Alternative spelling of `pipelineColourspace`.
101
+ * @param {string} [colorspace] - pipeline colorspace.
102
+ * @returns {Sharp}
103
+ * @throws {Error} Invalid parameters
104
+ */
105
+ function pipelineColorspace (colorspace) {
106
+ return this.pipelineColourspace(colorspace);
107
+ }
108
+
109
+ /**
110
+ * Set the output colourspace.
111
+ * By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
112
+ *
113
+ * @example
114
+ * // Output 16 bits per pixel RGB
115
+ * await sharp(input)
116
+ * .toColourspace('rgb16')
117
+ * .toFile('16-bpp.png')
118
+ *
119
+ * @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/libvips/libvips/blob/3c0bfdf74ce1dc37a6429bed47fa76f16e2cd70a/libvips/iofuncs/enumtypes.c#L777-L794)
120
+ * @returns {Sharp}
121
+ * @throws {Error} Invalid parameters
122
+ */
123
+ function toColourspace (colourspace) {
124
+ if (!is.string(colourspace)) {
125
+ throw is.invalidParameterError('colourspace', 'string', colourspace);
126
+ }
127
+ this.options.colourspace = colourspace;
128
+ return this;
129
+ }
130
+
131
+ /**
132
+ * Alternative spelling of `toColourspace`.
133
+ * @param {string} [colorspace] - output colorspace.
134
+ * @returns {Sharp}
135
+ * @throws {Error} Invalid parameters
136
+ */
137
+ function toColorspace (colorspace) {
138
+ return this.toColourspace(colorspace);
139
+ }
140
+
141
+ /**
142
+ * Update a colour attribute of the this.options Object.
143
+ * @private
144
+ * @param {string} key
145
+ * @param {string|Object} value
146
+ * @throws {Error} Invalid value
147
+ */
148
+ function _setBackgroundColourOption (key, value) {
149
+ if (is.defined(value)) {
150
+ if (is.object(value) || is.string(value)) {
151
+ const colour = color(value);
152
+ this.options[key] = [
153
+ colour.red(),
154
+ colour.green(),
155
+ colour.blue(),
156
+ Math.round(colour.alpha() * 255)
157
+ ];
158
+ } else {
159
+ throw is.invalidParameterError('background', 'object or string', value);
160
+ }
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Decorate the Sharp prototype with colour-related functions.
166
+ * @private
167
+ */
168
+ module.exports = function (Sharp) {
169
+ Object.assign(Sharp.prototype, {
170
+ // Public
171
+ tint,
172
+ greyscale,
173
+ grayscale,
174
+ pipelineColourspace,
175
+ pipelineColorspace,
176
+ toColourspace,
177
+ toColorspace,
178
+ // Private
179
+ _setBackgroundColourOption
180
+ });
181
+ // Class attributes
182
+ Sharp.colourspace = colourspace;
183
+ Sharp.colorspace = colourspace;
184
+ };