@eggjs/mock 6.0.7 → 6.1.0-beta.10
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.
- package/README.md +35 -56
- package/README.zh_CN.md +30 -50
- package/dist/_virtual/rolldown_runtime.js +30 -0
- package/dist/app/extend/agent.d.ts +39 -0
- package/dist/app/extend/agent.js +48 -0
- package/dist/app/extend/application.d.ts +175 -0
- package/dist/app/extend/application.js +385 -0
- package/dist/app/middleware/cluster_app_mock.d.ts +6 -0
- package/dist/app/middleware/cluster_app_mock.js +97 -0
- package/dist/app.d.ts +10 -0
- package/dist/app.js +17 -0
- package/dist/bootstrap.d.ts +9 -0
- package/dist/bootstrap.js +14 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +47 -0
- package/dist/inject_mocha.d.ts +1 -0
- package/dist/inject_mocha.js +35 -0
- package/dist/lib/agent_handler.d.ts +7 -0
- package/dist/lib/agent_handler.js +26 -0
- package/dist/lib/app.d.ts +7 -0
- package/dist/lib/app.js +251 -0
- package/dist/lib/app_handler.d.ts +9 -0
- package/dist/lib/app_handler.js +56 -0
- package/dist/lib/cluster.d.ts +126 -0
- package/dist/lib/cluster.js +283 -0
- package/dist/lib/context.d.ts +4 -0
- package/dist/lib/context.js +12 -0
- package/dist/lib/format_options.d.ts +10 -0
- package/dist/lib/format_options.js +65 -0
- package/dist/lib/inject_context.d.ts +9 -0
- package/dist/lib/inject_context.js +106 -0
- package/dist/lib/mock_agent.d.ts +9 -0
- package/dist/lib/mock_agent.js +45 -0
- package/dist/lib/mock_custom_loader.d.ts +4 -0
- package/dist/lib/mock_custom_loader.js +35 -0
- package/dist/lib/mock_http_server.d.ts +6 -0
- package/dist/lib/mock_http_server.js +17 -0
- package/dist/lib/mock_httpclient.d.ts +40 -0
- package/dist/lib/mock_httpclient.js +110 -0
- package/dist/lib/parallel/agent.d.ts +24 -0
- package/dist/lib/parallel/agent.js +111 -0
- package/dist/lib/parallel/app.d.ts +24 -0
- package/dist/lib/parallel/app.js +99 -0
- package/dist/lib/parallel/util.d.ts +6 -0
- package/dist/lib/parallel/util.js +59 -0
- package/dist/lib/prerequire.d.ts +1 -0
- package/dist/lib/prerequire.js +1 -0
- package/dist/lib/request_call_function.d.ts +1 -0
- package/dist/lib/request_call_function.js +37 -0
- package/dist/lib/restore.d.ts +4 -0
- package/dist/lib/restore.js +16 -0
- package/dist/lib/start-cluster.d.ts +1 -0
- package/dist/lib/start-cluster.js +19 -0
- package/dist/lib/supertest.d.ts +16 -0
- package/dist/lib/supertest.js +39 -0
- package/dist/lib/tmp/empty.d.ts +1 -0
- package/dist/lib/tmp/empty.js +1 -0
- package/{src/lib/types.ts → dist/lib/types.d.ts} +12 -29
- package/dist/lib/types.js +1 -0
- package/dist/lib/utils.d.ts +12 -0
- package/dist/lib/utils.js +40 -0
- package/dist/node_modules/.pnpm/ansi-styles@4.3.0/node_modules/ansi-styles/index.js +142 -0
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js +157 -0
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/templates.js +97 -0
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/util.js +40 -0
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js +814 -0
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js +50 -0
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js +68 -0
- package/dist/node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js +752 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/browser.js +203 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/common.js +209 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js +18 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/node.js +215 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/dmp.js +24 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/xml.js +33 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/array.js +29 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/base.js +185 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/character.js +23 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/css.js +26 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/json.js +83 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/line.js +51 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/sentence.js +26 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/word.js +151 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/index.js +178 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/apply.js +168 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/create.js +301 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/line-endings.js +137 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/merge.js +367 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/parse.js +91 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/reverse.js +99 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/array.js +23 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/distance-iterator.js +30 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/params.js +22 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/string.js +97 -0
- package/dist/node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js +14 -0
- package/dist/node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js +16 -0
- package/dist/node_modules/.pnpm/he@1.2.0/node_modules/he/he.js +4093 -0
- package/dist/node_modules/.pnpm/is-unicode-supported@0.1.0/node_modules/is-unicode-supported/index.js +14 -0
- package/dist/node_modules/.pnpm/log-symbols@4.1.0/node_modules/log-symbols/index.js +27 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/index.js +12 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/context.js +83 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/error-constants.js +35 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/errors.js +392 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/hook.js +86 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/bdd.js +104 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/common.js +99 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/exports.js +65 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/index.js +18 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/qunit.js +95 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/tdd.js +105 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocha.js +1037 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocharc.js +24 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/buffered-worker-pool.js +152 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/esm-utils.js +74 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/file-unloader.js +22 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/parallel-buffered-runner.js +329 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/serializer.js +314 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/pending.js +22 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/base.js +417 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/doc.js +79 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/dot.js +75 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/html.js +283 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/index.js +40 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json-stream.js +90 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json.js +145 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/landing.js +107 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/list.js +77 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/markdown.js +106 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/min.js +57 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/nyan.js +233 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/progress.js +92 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/spec.js +91 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/tap.js +261 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/xunit.js +166 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runnable.js +346 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runner.js +922 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/stats-collector.js +72 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/suite.js +517 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/test.js +105 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/utils.js +505 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/package.js +225 -0
- package/dist/node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js +124 -0
- package/dist/node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js +11 -0
- package/dist/node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js +114 -0
- package/dist/node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js +76 -0
- package/dist/node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js +89 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Pool.js +366 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Promise.js +248 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/WorkerHandler.js +419 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/debug-port-allocator.js +27 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/environment.js +18 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/generated/embeddedWorker.js +16 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/index.js +63 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/transfer.js +21 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/validateOptions.js +9 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/worker.js +277 -0
- package/dist/register.d.ts +10 -0
- package/dist/register.js +40 -0
- package/dist/typings/index.d.ts +1 -0
- package/package.json +71 -98
- package/dist/commonjs/app/extend/agent.d.ts +0 -34
- package/dist/commonjs/app/extend/agent.js +0 -49
- package/dist/commonjs/app/extend/application.d.ts +0 -172
- package/dist/commonjs/app/extend/application.js +0 -450
- package/dist/commonjs/app/middleware/cluster_app_mock.d.ts +0 -3
- package/dist/commonjs/app/middleware/cluster_app_mock.js +0 -101
- package/dist/commonjs/app.d.ts +0 -6
- package/dist/commonjs/app.js +0 -20
- package/dist/commonjs/bootstrap.d.ts +0 -5
- package/dist/commonjs/bootstrap.js +0 -59
- package/dist/commonjs/index.d.ts +0 -77
- package/dist/commonjs/index.js +0 -114
- package/dist/commonjs/lib/agent_handler.d.ts +0 -3
- package/dist/commonjs/lib/agent_handler.js +0 -28
- package/dist/commonjs/lib/app.d.ts +0 -3
- package/dist/commonjs/lib/app.js +0 -301
- package/dist/commonjs/lib/app_handler.d.ts +0 -5
- package/dist/commonjs/lib/app_handler.js +0 -71
- package/dist/commonjs/lib/cluster.d.ts +0 -114
- package/dist/commonjs/lib/cluster.js +0 -337
- package/dist/commonjs/lib/context.d.ts +0 -1
- package/dist/commonjs/lib/context.js +0 -16
- package/dist/commonjs/lib/format_options.d.ts +0 -5
- package/dist/commonjs/lib/format_options.js +0 -100
- package/dist/commonjs/lib/inject_context.d.ts +0 -6
- package/dist/commonjs/lib/inject_context.js +0 -132
- package/dist/commonjs/lib/mock_agent.d.ts +0 -5
- package/dist/commonjs/lib/mock_agent.js +0 -49
- package/dist/commonjs/lib/mock_custom_loader.d.ts +0 -1
- package/dist/commonjs/lib/mock_custom_loader.js +0 -37
- package/dist/commonjs/lib/mock_http_server.d.ts +0 -2
- package/dist/commonjs/lib/mock_http_server.js +0 -24
- package/dist/commonjs/lib/mock_httpclient.d.ts +0 -36
- package/dist/commonjs/lib/mock_httpclient.js +0 -147
- package/dist/commonjs/lib/parallel/agent.d.ts +0 -20
- package/dist/commonjs/lib/parallel/agent.js +0 -125
- package/dist/commonjs/lib/parallel/app.d.ts +0 -20
- package/dist/commonjs/lib/parallel/app.js +0 -115
- package/dist/commonjs/lib/parallel/util.d.ts +0 -3
- package/dist/commonjs/lib/parallel/util.js +0 -77
- package/dist/commonjs/lib/prerequire.d.ts +0 -1
- package/dist/commonjs/lib/prerequire.js +0 -26
- package/dist/commonjs/lib/request_call_function.d.ts +0 -1
- package/dist/commonjs/lib/request_call_function.js +0 -52
- package/dist/commonjs/lib/restore.d.ts +0 -1
- package/dist/commonjs/lib/restore.js +0 -16
- package/dist/commonjs/lib/start-cluster.d.ts +0 -2
- package/dist/commonjs/lib/start-cluster.js +0 -23
- package/dist/commonjs/lib/supertest.d.ts +0 -11
- package/dist/commonjs/lib/supertest.js +0 -48
- package/dist/commonjs/lib/tmp/empty.d.ts +0 -1
- package/dist/commonjs/lib/tmp/empty.js +0 -3
- package/dist/commonjs/lib/types.d.ts +0 -68
- package/dist/commonjs/lib/types.js +0 -3
- package/dist/commonjs/lib/utils.d.ts +0 -9
- package/dist/commonjs/lib/utils.js +0 -80
- package/dist/commonjs/package.json +0 -3
- package/dist/commonjs/register.d.ts +0 -8
- package/dist/commonjs/register.js +0 -80
- package/dist/esm/app/extend/agent.d.ts +0 -34
- package/dist/esm/app/extend/agent.js +0 -46
- package/dist/esm/app/extend/application.d.ts +0 -172
- package/dist/esm/app/extend/application.js +0 -444
- package/dist/esm/app/middleware/cluster_app_mock.d.ts +0 -3
- package/dist/esm/app/middleware/cluster_app_mock.js +0 -99
- package/dist/esm/app.d.ts +0 -6
- package/dist/esm/app.js +0 -17
- package/dist/esm/bootstrap.d.ts +0 -5
- package/dist/esm/bootstrap.js +0 -15
- package/dist/esm/index.d.ts +0 -77
- package/dist/esm/index.js +0 -91
- package/dist/esm/lib/agent_handler.d.ts +0 -3
- package/dist/esm/lib/agent_handler.js +0 -24
- package/dist/esm/lib/app.d.ts +0 -3
- package/dist/esm/lib/app.js +0 -295
- package/dist/esm/lib/app_handler.d.ts +0 -5
- package/dist/esm/lib/app_handler.js +0 -65
- package/dist/esm/lib/cluster.d.ts +0 -114
- package/dist/esm/lib/cluster.js +0 -328
- package/dist/esm/lib/context.d.ts +0 -1
- package/dist/esm/lib/context.js +0 -13
- package/dist/esm/lib/format_options.d.ts +0 -5
- package/dist/esm/lib/format_options.js +0 -94
- package/dist/esm/lib/inject_context.d.ts +0 -6
- package/dist/esm/lib/inject_context.js +0 -126
- package/dist/esm/lib/mock_agent.d.ts +0 -5
- package/dist/esm/lib/mock_agent.js +0 -45
- package/dist/esm/lib/mock_custom_loader.d.ts +0 -1
- package/dist/esm/lib/mock_custom_loader.js +0 -34
- package/dist/esm/lib/mock_http_server.d.ts +0 -2
- package/dist/esm/lib/mock_http_server.js +0 -18
- package/dist/esm/lib/mock_httpclient.d.ts +0 -36
- package/dist/esm/lib/mock_httpclient.js +0 -144
- package/dist/esm/lib/parallel/agent.d.ts +0 -20
- package/dist/esm/lib/parallel/agent.js +0 -117
- package/dist/esm/lib/parallel/app.d.ts +0 -20
- package/dist/esm/lib/parallel/app.js +0 -110
- package/dist/esm/lib/parallel/util.d.ts +0 -3
- package/dist/esm/lib/parallel/util.js +0 -73
- package/dist/esm/lib/prerequire.d.ts +0 -1
- package/dist/esm/lib/prerequire.js +0 -25
- package/dist/esm/lib/request_call_function.d.ts +0 -1
- package/dist/esm/lib/request_call_function.js +0 -47
- package/dist/esm/lib/restore.d.ts +0 -1
- package/dist/esm/lib/restore.js +0 -13
- package/dist/esm/lib/start-cluster.d.ts +0 -2
- package/dist/esm/lib/start-cluster.js +0 -18
- package/dist/esm/lib/supertest.d.ts +0 -11
- package/dist/esm/lib/supertest.js +0 -40
- package/dist/esm/lib/tmp/empty.d.ts +0 -1
- package/dist/esm/lib/tmp/empty.js +0 -2
- package/dist/esm/lib/types.d.ts +0 -68
- package/dist/esm/lib/types.js +0 -2
- package/dist/esm/lib/utils.d.ts +0 -9
- package/dist/esm/lib/utils.js +0 -69
- package/dist/esm/package.json +0 -3
- package/dist/esm/register.d.ts +0 -8
- package/dist/esm/register.js +0 -75
- package/dist/package.json +0 -4
- package/src/app/extend/agent.ts +0 -57
- package/src/app/extend/application.ts +0 -512
- package/src/app/middleware/cluster_app_mock.ts +0 -102
- package/src/app.ts +0 -18
- package/src/bootstrap.ts +0 -25
- package/src/index.ts +0 -112
- package/src/lib/agent_handler.ts +0 -28
- package/src/lib/app.ts +0 -314
- package/src/lib/app_handler.ts +0 -77
- package/src/lib/cluster.ts +0 -363
- package/src/lib/context.ts +0 -14
- package/src/lib/format_options.ts +0 -103
- package/src/lib/inject_context.ts +0 -134
- package/src/lib/mock_agent.ts +0 -57
- package/src/lib/mock_custom_loader.ts +0 -36
- package/src/lib/mock_http_server.ts +0 -19
- package/src/lib/mock_httpclient.ts +0 -183
- package/src/lib/parallel/agent.ts +0 -128
- package/src/lib/parallel/app.ts +0 -123
- package/src/lib/parallel/util.ts +0 -66
- package/src/lib/prerequire.ts +0 -25
- package/src/lib/request_call_function.ts +0 -49
- package/src/lib/restore.ts +0 -14
- package/src/lib/start-cluster.ts +0 -23
- package/src/lib/supertest.ts +0 -45
- package/src/lib/tmp/.gitkeep +0 -0
- package/src/lib/tmp/empty.ts +0 -0
- package/src/lib/utils.ts +0 -82
- package/src/register.ts +0 -80
- package/src/typings/index.d.ts +0 -4
|
@@ -0,0 +1,814 @@
|
|
|
1
|
+
import { __commonJS } from "../../../../../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { require_color_name } from "../../../color-name@1.1.4/node_modules/color-name/index.js";
|
|
3
|
+
|
|
4
|
+
//#region ../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js
|
|
5
|
+
var require_conversions = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js": ((exports, module) => {
|
|
6
|
+
const cssKeywords = require_color_name();
|
|
7
|
+
const reverseKeywords = {};
|
|
8
|
+
for (const key of Object.keys(cssKeywords)) reverseKeywords[cssKeywords[key]] = key;
|
|
9
|
+
const convert = {
|
|
10
|
+
rgb: {
|
|
11
|
+
channels: 3,
|
|
12
|
+
labels: "rgb"
|
|
13
|
+
},
|
|
14
|
+
hsl: {
|
|
15
|
+
channels: 3,
|
|
16
|
+
labels: "hsl"
|
|
17
|
+
},
|
|
18
|
+
hsv: {
|
|
19
|
+
channels: 3,
|
|
20
|
+
labels: "hsv"
|
|
21
|
+
},
|
|
22
|
+
hwb: {
|
|
23
|
+
channels: 3,
|
|
24
|
+
labels: "hwb"
|
|
25
|
+
},
|
|
26
|
+
cmyk: {
|
|
27
|
+
channels: 4,
|
|
28
|
+
labels: "cmyk"
|
|
29
|
+
},
|
|
30
|
+
xyz: {
|
|
31
|
+
channels: 3,
|
|
32
|
+
labels: "xyz"
|
|
33
|
+
},
|
|
34
|
+
lab: {
|
|
35
|
+
channels: 3,
|
|
36
|
+
labels: "lab"
|
|
37
|
+
},
|
|
38
|
+
lch: {
|
|
39
|
+
channels: 3,
|
|
40
|
+
labels: "lch"
|
|
41
|
+
},
|
|
42
|
+
hex: {
|
|
43
|
+
channels: 1,
|
|
44
|
+
labels: ["hex"]
|
|
45
|
+
},
|
|
46
|
+
keyword: {
|
|
47
|
+
channels: 1,
|
|
48
|
+
labels: ["keyword"]
|
|
49
|
+
},
|
|
50
|
+
ansi16: {
|
|
51
|
+
channels: 1,
|
|
52
|
+
labels: ["ansi16"]
|
|
53
|
+
},
|
|
54
|
+
ansi256: {
|
|
55
|
+
channels: 1,
|
|
56
|
+
labels: ["ansi256"]
|
|
57
|
+
},
|
|
58
|
+
hcg: {
|
|
59
|
+
channels: 3,
|
|
60
|
+
labels: [
|
|
61
|
+
"h",
|
|
62
|
+
"c",
|
|
63
|
+
"g"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
apple: {
|
|
67
|
+
channels: 3,
|
|
68
|
+
labels: [
|
|
69
|
+
"r16",
|
|
70
|
+
"g16",
|
|
71
|
+
"b16"
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
gray: {
|
|
75
|
+
channels: 1,
|
|
76
|
+
labels: ["gray"]
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
module.exports = convert;
|
|
80
|
+
for (const model of Object.keys(convert)) {
|
|
81
|
+
if (!("channels" in convert[model])) throw new Error("missing channels property: " + model);
|
|
82
|
+
if (!("labels" in convert[model])) throw new Error("missing channel labels property: " + model);
|
|
83
|
+
if (convert[model].labels.length !== convert[model].channels) throw new Error("channel and label counts mismatch: " + model);
|
|
84
|
+
const { channels, labels } = convert[model];
|
|
85
|
+
delete convert[model].channels;
|
|
86
|
+
delete convert[model].labels;
|
|
87
|
+
Object.defineProperty(convert[model], "channels", { value: channels });
|
|
88
|
+
Object.defineProperty(convert[model], "labels", { value: labels });
|
|
89
|
+
}
|
|
90
|
+
convert.rgb.hsl = function(rgb) {
|
|
91
|
+
const r = rgb[0] / 255;
|
|
92
|
+
const g = rgb[1] / 255;
|
|
93
|
+
const b = rgb[2] / 255;
|
|
94
|
+
const min = Math.min(r, g, b);
|
|
95
|
+
const max = Math.max(r, g, b);
|
|
96
|
+
const delta = max - min;
|
|
97
|
+
let h;
|
|
98
|
+
let s;
|
|
99
|
+
if (max === min) h = 0;
|
|
100
|
+
else if (r === max) h = (g - b) / delta;
|
|
101
|
+
else if (g === max) h = 2 + (b - r) / delta;
|
|
102
|
+
else if (b === max) h = 4 + (r - g) / delta;
|
|
103
|
+
h = Math.min(h * 60, 360);
|
|
104
|
+
if (h < 0) h += 360;
|
|
105
|
+
const l = (min + max) / 2;
|
|
106
|
+
if (max === min) s = 0;
|
|
107
|
+
else if (l <= .5) s = delta / (max + min);
|
|
108
|
+
else s = delta / (2 - max - min);
|
|
109
|
+
return [
|
|
110
|
+
h,
|
|
111
|
+
s * 100,
|
|
112
|
+
l * 100
|
|
113
|
+
];
|
|
114
|
+
};
|
|
115
|
+
convert.rgb.hsv = function(rgb) {
|
|
116
|
+
let rdif;
|
|
117
|
+
let gdif;
|
|
118
|
+
let bdif;
|
|
119
|
+
let h;
|
|
120
|
+
let s;
|
|
121
|
+
const r = rgb[0] / 255;
|
|
122
|
+
const g = rgb[1] / 255;
|
|
123
|
+
const b = rgb[2] / 255;
|
|
124
|
+
const v = Math.max(r, g, b);
|
|
125
|
+
const diff = v - Math.min(r, g, b);
|
|
126
|
+
const diffc = function(c) {
|
|
127
|
+
return (v - c) / 6 / diff + 1 / 2;
|
|
128
|
+
};
|
|
129
|
+
if (diff === 0) {
|
|
130
|
+
h = 0;
|
|
131
|
+
s = 0;
|
|
132
|
+
} else {
|
|
133
|
+
s = diff / v;
|
|
134
|
+
rdif = diffc(r);
|
|
135
|
+
gdif = diffc(g);
|
|
136
|
+
bdif = diffc(b);
|
|
137
|
+
if (r === v) h = bdif - gdif;
|
|
138
|
+
else if (g === v) h = 1 / 3 + rdif - bdif;
|
|
139
|
+
else if (b === v) h = 2 / 3 + gdif - rdif;
|
|
140
|
+
if (h < 0) h += 1;
|
|
141
|
+
else if (h > 1) h -= 1;
|
|
142
|
+
}
|
|
143
|
+
return [
|
|
144
|
+
h * 360,
|
|
145
|
+
s * 100,
|
|
146
|
+
v * 100
|
|
147
|
+
];
|
|
148
|
+
};
|
|
149
|
+
convert.rgb.hwb = function(rgb) {
|
|
150
|
+
const r = rgb[0];
|
|
151
|
+
const g = rgb[1];
|
|
152
|
+
let b = rgb[2];
|
|
153
|
+
const h = convert.rgb.hsl(rgb)[0];
|
|
154
|
+
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
155
|
+
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
156
|
+
return [
|
|
157
|
+
h,
|
|
158
|
+
w * 100,
|
|
159
|
+
b * 100
|
|
160
|
+
];
|
|
161
|
+
};
|
|
162
|
+
convert.rgb.cmyk = function(rgb) {
|
|
163
|
+
const r = rgb[0] / 255;
|
|
164
|
+
const g = rgb[1] / 255;
|
|
165
|
+
const b = rgb[2] / 255;
|
|
166
|
+
const k = Math.min(1 - r, 1 - g, 1 - b);
|
|
167
|
+
const c = (1 - r - k) / (1 - k) || 0;
|
|
168
|
+
const m = (1 - g - k) / (1 - k) || 0;
|
|
169
|
+
const y = (1 - b - k) / (1 - k) || 0;
|
|
170
|
+
return [
|
|
171
|
+
c * 100,
|
|
172
|
+
m * 100,
|
|
173
|
+
y * 100,
|
|
174
|
+
k * 100
|
|
175
|
+
];
|
|
176
|
+
};
|
|
177
|
+
function comparativeDistance(x, y) {
|
|
178
|
+
return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
|
|
179
|
+
}
|
|
180
|
+
convert.rgb.keyword = function(rgb) {
|
|
181
|
+
const reversed = reverseKeywords[rgb];
|
|
182
|
+
if (reversed) return reversed;
|
|
183
|
+
let currentClosestDistance = Infinity;
|
|
184
|
+
let currentClosestKeyword;
|
|
185
|
+
for (const keyword of Object.keys(cssKeywords)) {
|
|
186
|
+
const value = cssKeywords[keyword];
|
|
187
|
+
const distance = comparativeDistance(rgb, value);
|
|
188
|
+
if (distance < currentClosestDistance) {
|
|
189
|
+
currentClosestDistance = distance;
|
|
190
|
+
currentClosestKeyword = keyword;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return currentClosestKeyword;
|
|
194
|
+
};
|
|
195
|
+
convert.keyword.rgb = function(keyword) {
|
|
196
|
+
return cssKeywords[keyword];
|
|
197
|
+
};
|
|
198
|
+
convert.rgb.xyz = function(rgb) {
|
|
199
|
+
let r = rgb[0] / 255;
|
|
200
|
+
let g = rgb[1] / 255;
|
|
201
|
+
let b = rgb[2] / 255;
|
|
202
|
+
r = r > .04045 ? ((r + .055) / 1.055) ** 2.4 : r / 12.92;
|
|
203
|
+
g = g > .04045 ? ((g + .055) / 1.055) ** 2.4 : g / 12.92;
|
|
204
|
+
b = b > .04045 ? ((b + .055) / 1.055) ** 2.4 : b / 12.92;
|
|
205
|
+
const x = r * .4124 + g * .3576 + b * .1805;
|
|
206
|
+
const y = r * .2126 + g * .7152 + b * .0722;
|
|
207
|
+
const z = r * .0193 + g * .1192 + b * .9505;
|
|
208
|
+
return [
|
|
209
|
+
x * 100,
|
|
210
|
+
y * 100,
|
|
211
|
+
z * 100
|
|
212
|
+
];
|
|
213
|
+
};
|
|
214
|
+
convert.rgb.lab = function(rgb) {
|
|
215
|
+
const xyz = convert.rgb.xyz(rgb);
|
|
216
|
+
let x = xyz[0];
|
|
217
|
+
let y = xyz[1];
|
|
218
|
+
let z = xyz[2];
|
|
219
|
+
x /= 95.047;
|
|
220
|
+
y /= 100;
|
|
221
|
+
z /= 108.883;
|
|
222
|
+
x = x > .008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
223
|
+
y = y > .008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
224
|
+
z = z > .008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
225
|
+
const l = 116 * y - 16;
|
|
226
|
+
const a = 500 * (x - y);
|
|
227
|
+
const b = 200 * (y - z);
|
|
228
|
+
return [
|
|
229
|
+
l,
|
|
230
|
+
a,
|
|
231
|
+
b
|
|
232
|
+
];
|
|
233
|
+
};
|
|
234
|
+
convert.hsl.rgb = function(hsl) {
|
|
235
|
+
const h = hsl[0] / 360;
|
|
236
|
+
const s = hsl[1] / 100;
|
|
237
|
+
const l = hsl[2] / 100;
|
|
238
|
+
let t2;
|
|
239
|
+
let t3;
|
|
240
|
+
let val;
|
|
241
|
+
if (s === 0) {
|
|
242
|
+
val = l * 255;
|
|
243
|
+
return [
|
|
244
|
+
val,
|
|
245
|
+
val,
|
|
246
|
+
val
|
|
247
|
+
];
|
|
248
|
+
}
|
|
249
|
+
if (l < .5) t2 = l * (1 + s);
|
|
250
|
+
else t2 = l + s - l * s;
|
|
251
|
+
const t1 = 2 * l - t2;
|
|
252
|
+
const rgb = [
|
|
253
|
+
0,
|
|
254
|
+
0,
|
|
255
|
+
0
|
|
256
|
+
];
|
|
257
|
+
for (let i = 0; i < 3; i++) {
|
|
258
|
+
t3 = h + 1 / 3 * -(i - 1);
|
|
259
|
+
if (t3 < 0) t3++;
|
|
260
|
+
if (t3 > 1) t3--;
|
|
261
|
+
if (6 * t3 < 1) val = t1 + (t2 - t1) * 6 * t3;
|
|
262
|
+
else if (2 * t3 < 1) val = t2;
|
|
263
|
+
else if (3 * t3 < 2) val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
264
|
+
else val = t1;
|
|
265
|
+
rgb[i] = val * 255;
|
|
266
|
+
}
|
|
267
|
+
return rgb;
|
|
268
|
+
};
|
|
269
|
+
convert.hsl.hsv = function(hsl) {
|
|
270
|
+
const h = hsl[0];
|
|
271
|
+
let s = hsl[1] / 100;
|
|
272
|
+
let l = hsl[2] / 100;
|
|
273
|
+
let smin = s;
|
|
274
|
+
const lmin = Math.max(l, .01);
|
|
275
|
+
l *= 2;
|
|
276
|
+
s *= l <= 1 ? l : 2 - l;
|
|
277
|
+
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
278
|
+
const v = (l + s) / 2;
|
|
279
|
+
const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
|
|
280
|
+
return [
|
|
281
|
+
h,
|
|
282
|
+
sv * 100,
|
|
283
|
+
v * 100
|
|
284
|
+
];
|
|
285
|
+
};
|
|
286
|
+
convert.hsv.rgb = function(hsv) {
|
|
287
|
+
const h = hsv[0] / 60;
|
|
288
|
+
const s = hsv[1] / 100;
|
|
289
|
+
let v = hsv[2] / 100;
|
|
290
|
+
const hi = Math.floor(h) % 6;
|
|
291
|
+
const f = h - Math.floor(h);
|
|
292
|
+
const p = 255 * v * (1 - s);
|
|
293
|
+
const q = 255 * v * (1 - s * f);
|
|
294
|
+
const t = 255 * v * (1 - s * (1 - f));
|
|
295
|
+
v *= 255;
|
|
296
|
+
switch (hi) {
|
|
297
|
+
case 0: return [
|
|
298
|
+
v,
|
|
299
|
+
t,
|
|
300
|
+
p
|
|
301
|
+
];
|
|
302
|
+
case 1: return [
|
|
303
|
+
q,
|
|
304
|
+
v,
|
|
305
|
+
p
|
|
306
|
+
];
|
|
307
|
+
case 2: return [
|
|
308
|
+
p,
|
|
309
|
+
v,
|
|
310
|
+
t
|
|
311
|
+
];
|
|
312
|
+
case 3: return [
|
|
313
|
+
p,
|
|
314
|
+
q,
|
|
315
|
+
v
|
|
316
|
+
];
|
|
317
|
+
case 4: return [
|
|
318
|
+
t,
|
|
319
|
+
p,
|
|
320
|
+
v
|
|
321
|
+
];
|
|
322
|
+
case 5: return [
|
|
323
|
+
v,
|
|
324
|
+
p,
|
|
325
|
+
q
|
|
326
|
+
];
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
convert.hsv.hsl = function(hsv) {
|
|
330
|
+
const h = hsv[0];
|
|
331
|
+
const s = hsv[1] / 100;
|
|
332
|
+
const v = hsv[2] / 100;
|
|
333
|
+
const vmin = Math.max(v, .01);
|
|
334
|
+
let sl;
|
|
335
|
+
let l;
|
|
336
|
+
l = (2 - s) * v;
|
|
337
|
+
const lmin = (2 - s) * vmin;
|
|
338
|
+
sl = s * vmin;
|
|
339
|
+
sl /= lmin <= 1 ? lmin : 2 - lmin;
|
|
340
|
+
sl = sl || 0;
|
|
341
|
+
l /= 2;
|
|
342
|
+
return [
|
|
343
|
+
h,
|
|
344
|
+
sl * 100,
|
|
345
|
+
l * 100
|
|
346
|
+
];
|
|
347
|
+
};
|
|
348
|
+
convert.hwb.rgb = function(hwb) {
|
|
349
|
+
const h = hwb[0] / 360;
|
|
350
|
+
let wh = hwb[1] / 100;
|
|
351
|
+
let bl = hwb[2] / 100;
|
|
352
|
+
const ratio = wh + bl;
|
|
353
|
+
let f;
|
|
354
|
+
if (ratio > 1) {
|
|
355
|
+
wh /= ratio;
|
|
356
|
+
bl /= ratio;
|
|
357
|
+
}
|
|
358
|
+
const i = Math.floor(6 * h);
|
|
359
|
+
const v = 1 - bl;
|
|
360
|
+
f = 6 * h - i;
|
|
361
|
+
if ((i & 1) !== 0) f = 1 - f;
|
|
362
|
+
const n = wh + f * (v - wh);
|
|
363
|
+
let r;
|
|
364
|
+
let g;
|
|
365
|
+
let b;
|
|
366
|
+
switch (i) {
|
|
367
|
+
default:
|
|
368
|
+
case 6:
|
|
369
|
+
case 0:
|
|
370
|
+
r = v;
|
|
371
|
+
g = n;
|
|
372
|
+
b = wh;
|
|
373
|
+
break;
|
|
374
|
+
case 1:
|
|
375
|
+
r = n;
|
|
376
|
+
g = v;
|
|
377
|
+
b = wh;
|
|
378
|
+
break;
|
|
379
|
+
case 2:
|
|
380
|
+
r = wh;
|
|
381
|
+
g = v;
|
|
382
|
+
b = n;
|
|
383
|
+
break;
|
|
384
|
+
case 3:
|
|
385
|
+
r = wh;
|
|
386
|
+
g = n;
|
|
387
|
+
b = v;
|
|
388
|
+
break;
|
|
389
|
+
case 4:
|
|
390
|
+
r = n;
|
|
391
|
+
g = wh;
|
|
392
|
+
b = v;
|
|
393
|
+
break;
|
|
394
|
+
case 5:
|
|
395
|
+
r = v;
|
|
396
|
+
g = wh;
|
|
397
|
+
b = n;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
return [
|
|
401
|
+
r * 255,
|
|
402
|
+
g * 255,
|
|
403
|
+
b * 255
|
|
404
|
+
];
|
|
405
|
+
};
|
|
406
|
+
convert.cmyk.rgb = function(cmyk) {
|
|
407
|
+
const c = cmyk[0] / 100;
|
|
408
|
+
const m = cmyk[1] / 100;
|
|
409
|
+
const y = cmyk[2] / 100;
|
|
410
|
+
const k = cmyk[3] / 100;
|
|
411
|
+
const r = 1 - Math.min(1, c * (1 - k) + k);
|
|
412
|
+
const g = 1 - Math.min(1, m * (1 - k) + k);
|
|
413
|
+
const b = 1 - Math.min(1, y * (1 - k) + k);
|
|
414
|
+
return [
|
|
415
|
+
r * 255,
|
|
416
|
+
g * 255,
|
|
417
|
+
b * 255
|
|
418
|
+
];
|
|
419
|
+
};
|
|
420
|
+
convert.xyz.rgb = function(xyz) {
|
|
421
|
+
const x = xyz[0] / 100;
|
|
422
|
+
const y = xyz[1] / 100;
|
|
423
|
+
const z = xyz[2] / 100;
|
|
424
|
+
let r;
|
|
425
|
+
let g;
|
|
426
|
+
let b;
|
|
427
|
+
r = x * 3.2406 + y * -1.5372 + z * -.4986;
|
|
428
|
+
g = x * -.9689 + y * 1.8758 + z * .0415;
|
|
429
|
+
b = x * .0557 + y * -.204 + z * 1.057;
|
|
430
|
+
r = r > .0031308 ? 1.055 * r ** (1 / 2.4) - .055 : r * 12.92;
|
|
431
|
+
g = g > .0031308 ? 1.055 * g ** (1 / 2.4) - .055 : g * 12.92;
|
|
432
|
+
b = b > .0031308 ? 1.055 * b ** (1 / 2.4) - .055 : b * 12.92;
|
|
433
|
+
r = Math.min(Math.max(0, r), 1);
|
|
434
|
+
g = Math.min(Math.max(0, g), 1);
|
|
435
|
+
b = Math.min(Math.max(0, b), 1);
|
|
436
|
+
return [
|
|
437
|
+
r * 255,
|
|
438
|
+
g * 255,
|
|
439
|
+
b * 255
|
|
440
|
+
];
|
|
441
|
+
};
|
|
442
|
+
convert.xyz.lab = function(xyz) {
|
|
443
|
+
let x = xyz[0];
|
|
444
|
+
let y = xyz[1];
|
|
445
|
+
let z = xyz[2];
|
|
446
|
+
x /= 95.047;
|
|
447
|
+
y /= 100;
|
|
448
|
+
z /= 108.883;
|
|
449
|
+
x = x > .008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
450
|
+
y = y > .008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
451
|
+
z = z > .008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
452
|
+
const l = 116 * y - 16;
|
|
453
|
+
const a = 500 * (x - y);
|
|
454
|
+
const b = 200 * (y - z);
|
|
455
|
+
return [
|
|
456
|
+
l,
|
|
457
|
+
a,
|
|
458
|
+
b
|
|
459
|
+
];
|
|
460
|
+
};
|
|
461
|
+
convert.lab.xyz = function(lab) {
|
|
462
|
+
const l = lab[0];
|
|
463
|
+
const a = lab[1];
|
|
464
|
+
const b = lab[2];
|
|
465
|
+
let x;
|
|
466
|
+
let y;
|
|
467
|
+
let z;
|
|
468
|
+
y = (l + 16) / 116;
|
|
469
|
+
x = a / 500 + y;
|
|
470
|
+
z = y - b / 200;
|
|
471
|
+
const y2 = y ** 3;
|
|
472
|
+
const x2 = x ** 3;
|
|
473
|
+
const z2 = z ** 3;
|
|
474
|
+
y = y2 > .008856 ? y2 : (y - 16 / 116) / 7.787;
|
|
475
|
+
x = x2 > .008856 ? x2 : (x - 16 / 116) / 7.787;
|
|
476
|
+
z = z2 > .008856 ? z2 : (z - 16 / 116) / 7.787;
|
|
477
|
+
x *= 95.047;
|
|
478
|
+
y *= 100;
|
|
479
|
+
z *= 108.883;
|
|
480
|
+
return [
|
|
481
|
+
x,
|
|
482
|
+
y,
|
|
483
|
+
z
|
|
484
|
+
];
|
|
485
|
+
};
|
|
486
|
+
convert.lab.lch = function(lab) {
|
|
487
|
+
const l = lab[0];
|
|
488
|
+
const a = lab[1];
|
|
489
|
+
const b = lab[2];
|
|
490
|
+
let h;
|
|
491
|
+
h = Math.atan2(b, a) * 360 / 2 / Math.PI;
|
|
492
|
+
if (h < 0) h += 360;
|
|
493
|
+
const c = Math.sqrt(a * a + b * b);
|
|
494
|
+
return [
|
|
495
|
+
l,
|
|
496
|
+
c,
|
|
497
|
+
h
|
|
498
|
+
];
|
|
499
|
+
};
|
|
500
|
+
convert.lch.lab = function(lch) {
|
|
501
|
+
const l = lch[0];
|
|
502
|
+
const c = lch[1];
|
|
503
|
+
const hr = lch[2] / 360 * 2 * Math.PI;
|
|
504
|
+
const a = c * Math.cos(hr);
|
|
505
|
+
const b = c * Math.sin(hr);
|
|
506
|
+
return [
|
|
507
|
+
l,
|
|
508
|
+
a,
|
|
509
|
+
b
|
|
510
|
+
];
|
|
511
|
+
};
|
|
512
|
+
convert.rgb.ansi16 = function(args, saturation = null) {
|
|
513
|
+
const [r, g, b] = args;
|
|
514
|
+
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
|
|
515
|
+
value = Math.round(value / 50);
|
|
516
|
+
if (value === 0) return 30;
|
|
517
|
+
let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
|
|
518
|
+
if (value === 2) ansi += 60;
|
|
519
|
+
return ansi;
|
|
520
|
+
};
|
|
521
|
+
convert.hsv.ansi16 = function(args) {
|
|
522
|
+
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
523
|
+
};
|
|
524
|
+
convert.rgb.ansi256 = function(args) {
|
|
525
|
+
const r = args[0];
|
|
526
|
+
const g = args[1];
|
|
527
|
+
const b = args[2];
|
|
528
|
+
if (r === g && g === b) {
|
|
529
|
+
if (r < 8) return 16;
|
|
530
|
+
if (r > 248) return 231;
|
|
531
|
+
return Math.round((r - 8) / 247 * 24) + 232;
|
|
532
|
+
}
|
|
533
|
+
return 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
|
|
534
|
+
};
|
|
535
|
+
convert.ansi16.rgb = function(args) {
|
|
536
|
+
let color = args % 10;
|
|
537
|
+
if (color === 0 || color === 7) {
|
|
538
|
+
if (args > 50) color += 3.5;
|
|
539
|
+
color = color / 10.5 * 255;
|
|
540
|
+
return [
|
|
541
|
+
color,
|
|
542
|
+
color,
|
|
543
|
+
color
|
|
544
|
+
];
|
|
545
|
+
}
|
|
546
|
+
const mult = (~~(args > 50) + 1) * .5;
|
|
547
|
+
const r = (color & 1) * mult * 255;
|
|
548
|
+
const g = (color >> 1 & 1) * mult * 255;
|
|
549
|
+
const b = (color >> 2 & 1) * mult * 255;
|
|
550
|
+
return [
|
|
551
|
+
r,
|
|
552
|
+
g,
|
|
553
|
+
b
|
|
554
|
+
];
|
|
555
|
+
};
|
|
556
|
+
convert.ansi256.rgb = function(args) {
|
|
557
|
+
if (args >= 232) {
|
|
558
|
+
const c = (args - 232) * 10 + 8;
|
|
559
|
+
return [
|
|
560
|
+
c,
|
|
561
|
+
c,
|
|
562
|
+
c
|
|
563
|
+
];
|
|
564
|
+
}
|
|
565
|
+
args -= 16;
|
|
566
|
+
let rem;
|
|
567
|
+
const r = Math.floor(args / 36) / 5 * 255;
|
|
568
|
+
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
569
|
+
const b = rem % 6 / 5 * 255;
|
|
570
|
+
return [
|
|
571
|
+
r,
|
|
572
|
+
g,
|
|
573
|
+
b
|
|
574
|
+
];
|
|
575
|
+
};
|
|
576
|
+
convert.rgb.hex = function(args) {
|
|
577
|
+
const string = (((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255)).toString(16).toUpperCase();
|
|
578
|
+
return "000000".substring(string.length) + string;
|
|
579
|
+
};
|
|
580
|
+
convert.hex.rgb = function(args) {
|
|
581
|
+
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
582
|
+
if (!match) return [
|
|
583
|
+
0,
|
|
584
|
+
0,
|
|
585
|
+
0
|
|
586
|
+
];
|
|
587
|
+
let colorString = match[0];
|
|
588
|
+
if (match[0].length === 3) colorString = colorString.split("").map((char) => {
|
|
589
|
+
return char + char;
|
|
590
|
+
}).join("");
|
|
591
|
+
const integer = parseInt(colorString, 16);
|
|
592
|
+
const r = integer >> 16 & 255;
|
|
593
|
+
const g = integer >> 8 & 255;
|
|
594
|
+
const b = integer & 255;
|
|
595
|
+
return [
|
|
596
|
+
r,
|
|
597
|
+
g,
|
|
598
|
+
b
|
|
599
|
+
];
|
|
600
|
+
};
|
|
601
|
+
convert.rgb.hcg = function(rgb) {
|
|
602
|
+
const r = rgb[0] / 255;
|
|
603
|
+
const g = rgb[1] / 255;
|
|
604
|
+
const b = rgb[2] / 255;
|
|
605
|
+
const max = Math.max(Math.max(r, g), b);
|
|
606
|
+
const min = Math.min(Math.min(r, g), b);
|
|
607
|
+
const chroma = max - min;
|
|
608
|
+
let grayscale;
|
|
609
|
+
let hue;
|
|
610
|
+
if (chroma < 1) grayscale = min / (1 - chroma);
|
|
611
|
+
else grayscale = 0;
|
|
612
|
+
if (chroma <= 0) hue = 0;
|
|
613
|
+
else if (max === r) hue = (g - b) / chroma % 6;
|
|
614
|
+
else if (max === g) hue = 2 + (b - r) / chroma;
|
|
615
|
+
else hue = 4 + (r - g) / chroma;
|
|
616
|
+
hue /= 6;
|
|
617
|
+
hue %= 1;
|
|
618
|
+
return [
|
|
619
|
+
hue * 360,
|
|
620
|
+
chroma * 100,
|
|
621
|
+
grayscale * 100
|
|
622
|
+
];
|
|
623
|
+
};
|
|
624
|
+
convert.hsl.hcg = function(hsl) {
|
|
625
|
+
const s = hsl[1] / 100;
|
|
626
|
+
const l = hsl[2] / 100;
|
|
627
|
+
const c = l < .5 ? 2 * s * l : 2 * s * (1 - l);
|
|
628
|
+
let f = 0;
|
|
629
|
+
if (c < 1) f = (l - .5 * c) / (1 - c);
|
|
630
|
+
return [
|
|
631
|
+
hsl[0],
|
|
632
|
+
c * 100,
|
|
633
|
+
f * 100
|
|
634
|
+
];
|
|
635
|
+
};
|
|
636
|
+
convert.hsv.hcg = function(hsv) {
|
|
637
|
+
const s = hsv[1] / 100;
|
|
638
|
+
const v = hsv[2] / 100;
|
|
639
|
+
const c = s * v;
|
|
640
|
+
let f = 0;
|
|
641
|
+
if (c < 1) f = (v - c) / (1 - c);
|
|
642
|
+
return [
|
|
643
|
+
hsv[0],
|
|
644
|
+
c * 100,
|
|
645
|
+
f * 100
|
|
646
|
+
];
|
|
647
|
+
};
|
|
648
|
+
convert.hcg.rgb = function(hcg) {
|
|
649
|
+
const h = hcg[0] / 360;
|
|
650
|
+
const c = hcg[1] / 100;
|
|
651
|
+
const g = hcg[2] / 100;
|
|
652
|
+
if (c === 0) return [
|
|
653
|
+
g * 255,
|
|
654
|
+
g * 255,
|
|
655
|
+
g * 255
|
|
656
|
+
];
|
|
657
|
+
const pure = [
|
|
658
|
+
0,
|
|
659
|
+
0,
|
|
660
|
+
0
|
|
661
|
+
];
|
|
662
|
+
const hi = h % 1 * 6;
|
|
663
|
+
const v = hi % 1;
|
|
664
|
+
const w = 1 - v;
|
|
665
|
+
let mg = 0;
|
|
666
|
+
switch (Math.floor(hi)) {
|
|
667
|
+
case 0:
|
|
668
|
+
pure[0] = 1;
|
|
669
|
+
pure[1] = v;
|
|
670
|
+
pure[2] = 0;
|
|
671
|
+
break;
|
|
672
|
+
case 1:
|
|
673
|
+
pure[0] = w;
|
|
674
|
+
pure[1] = 1;
|
|
675
|
+
pure[2] = 0;
|
|
676
|
+
break;
|
|
677
|
+
case 2:
|
|
678
|
+
pure[0] = 0;
|
|
679
|
+
pure[1] = 1;
|
|
680
|
+
pure[2] = v;
|
|
681
|
+
break;
|
|
682
|
+
case 3:
|
|
683
|
+
pure[0] = 0;
|
|
684
|
+
pure[1] = w;
|
|
685
|
+
pure[2] = 1;
|
|
686
|
+
break;
|
|
687
|
+
case 4:
|
|
688
|
+
pure[0] = v;
|
|
689
|
+
pure[1] = 0;
|
|
690
|
+
pure[2] = 1;
|
|
691
|
+
break;
|
|
692
|
+
default:
|
|
693
|
+
pure[0] = 1;
|
|
694
|
+
pure[1] = 0;
|
|
695
|
+
pure[2] = w;
|
|
696
|
+
}
|
|
697
|
+
mg = (1 - c) * g;
|
|
698
|
+
return [
|
|
699
|
+
(c * pure[0] + mg) * 255,
|
|
700
|
+
(c * pure[1] + mg) * 255,
|
|
701
|
+
(c * pure[2] + mg) * 255
|
|
702
|
+
];
|
|
703
|
+
};
|
|
704
|
+
convert.hcg.hsv = function(hcg) {
|
|
705
|
+
const c = hcg[1] / 100;
|
|
706
|
+
const g = hcg[2] / 100;
|
|
707
|
+
const v = c + g * (1 - c);
|
|
708
|
+
let f = 0;
|
|
709
|
+
if (v > 0) f = c / v;
|
|
710
|
+
return [
|
|
711
|
+
hcg[0],
|
|
712
|
+
f * 100,
|
|
713
|
+
v * 100
|
|
714
|
+
];
|
|
715
|
+
};
|
|
716
|
+
convert.hcg.hsl = function(hcg) {
|
|
717
|
+
const c = hcg[1] / 100;
|
|
718
|
+
const l = hcg[2] / 100 * (1 - c) + .5 * c;
|
|
719
|
+
let s = 0;
|
|
720
|
+
if (l > 0 && l < .5) s = c / (2 * l);
|
|
721
|
+
else if (l >= .5 && l < 1) s = c / (2 * (1 - l));
|
|
722
|
+
return [
|
|
723
|
+
hcg[0],
|
|
724
|
+
s * 100,
|
|
725
|
+
l * 100
|
|
726
|
+
];
|
|
727
|
+
};
|
|
728
|
+
convert.hcg.hwb = function(hcg) {
|
|
729
|
+
const c = hcg[1] / 100;
|
|
730
|
+
const g = hcg[2] / 100;
|
|
731
|
+
const v = c + g * (1 - c);
|
|
732
|
+
return [
|
|
733
|
+
hcg[0],
|
|
734
|
+
(v - c) * 100,
|
|
735
|
+
(1 - v) * 100
|
|
736
|
+
];
|
|
737
|
+
};
|
|
738
|
+
convert.hwb.hcg = function(hwb) {
|
|
739
|
+
const w = hwb[1] / 100;
|
|
740
|
+
const v = 1 - hwb[2] / 100;
|
|
741
|
+
const c = v - w;
|
|
742
|
+
let g = 0;
|
|
743
|
+
if (c < 1) g = (v - c) / (1 - c);
|
|
744
|
+
return [
|
|
745
|
+
hwb[0],
|
|
746
|
+
c * 100,
|
|
747
|
+
g * 100
|
|
748
|
+
];
|
|
749
|
+
};
|
|
750
|
+
convert.apple.rgb = function(apple) {
|
|
751
|
+
return [
|
|
752
|
+
apple[0] / 65535 * 255,
|
|
753
|
+
apple[1] / 65535 * 255,
|
|
754
|
+
apple[2] / 65535 * 255
|
|
755
|
+
];
|
|
756
|
+
};
|
|
757
|
+
convert.rgb.apple = function(rgb) {
|
|
758
|
+
return [
|
|
759
|
+
rgb[0] / 255 * 65535,
|
|
760
|
+
rgb[1] / 255 * 65535,
|
|
761
|
+
rgb[2] / 255 * 65535
|
|
762
|
+
];
|
|
763
|
+
};
|
|
764
|
+
convert.gray.rgb = function(args) {
|
|
765
|
+
return [
|
|
766
|
+
args[0] / 100 * 255,
|
|
767
|
+
args[0] / 100 * 255,
|
|
768
|
+
args[0] / 100 * 255
|
|
769
|
+
];
|
|
770
|
+
};
|
|
771
|
+
convert.gray.hsl = function(args) {
|
|
772
|
+
return [
|
|
773
|
+
0,
|
|
774
|
+
0,
|
|
775
|
+
args[0]
|
|
776
|
+
];
|
|
777
|
+
};
|
|
778
|
+
convert.gray.hsv = convert.gray.hsl;
|
|
779
|
+
convert.gray.hwb = function(gray) {
|
|
780
|
+
return [
|
|
781
|
+
0,
|
|
782
|
+
100,
|
|
783
|
+
gray[0]
|
|
784
|
+
];
|
|
785
|
+
};
|
|
786
|
+
convert.gray.cmyk = function(gray) {
|
|
787
|
+
return [
|
|
788
|
+
0,
|
|
789
|
+
0,
|
|
790
|
+
0,
|
|
791
|
+
gray[0]
|
|
792
|
+
];
|
|
793
|
+
};
|
|
794
|
+
convert.gray.lab = function(gray) {
|
|
795
|
+
return [
|
|
796
|
+
gray[0],
|
|
797
|
+
0,
|
|
798
|
+
0
|
|
799
|
+
];
|
|
800
|
+
};
|
|
801
|
+
convert.gray.hex = function(gray) {
|
|
802
|
+
const val = Math.round(gray[0] / 100 * 255) & 255;
|
|
803
|
+
const string = ((val << 16) + (val << 8) + val).toString(16).toUpperCase();
|
|
804
|
+
return "000000".substring(string.length) + string;
|
|
805
|
+
};
|
|
806
|
+
convert.rgb.gray = function(rgb) {
|
|
807
|
+
return [(rgb[0] + rgb[1] + rgb[2]) / 3 / 255 * 100];
|
|
808
|
+
};
|
|
809
|
+
}) });
|
|
810
|
+
|
|
811
|
+
//#endregion
|
|
812
|
+
export default require_conversions();
|
|
813
|
+
|
|
814
|
+
export { require_conversions };
|