@cloudflare/vite-plugin 1.37.2 → 1.38.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.
package/dist/index.mjs
CHANGED
|
@@ -36,8 +36,8 @@ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
|
36
36
|
var __getOwnPropNames$1 = Object.getOwnPropertyNames;
|
|
37
37
|
var __getProtoOf$1 = Object.getPrototypeOf;
|
|
38
38
|
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
39
|
-
var __commonJS$1 = (cb, mod) => function() {
|
|
40
|
-
return mod || (0, cb[__getOwnPropNames$1(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
39
|
+
var __commonJS$1 = (cb, mod$1) => function() {
|
|
40
|
+
return mod$1 || (0, cb[__getOwnPropNames$1(cb)[0]])((mod$1 = { exports: {} }).exports, mod$1), mod$1.exports;
|
|
41
41
|
};
|
|
42
42
|
var __copyProps$1 = (to, from, except, desc) => {
|
|
43
43
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames$1(from), i$1 = 0, n$1 = keys.length, key; i$1 < n$1; i$1++) {
|
|
@@ -49,10 +49,10 @@ var __copyProps$1 = (to, from, except, desc) => {
|
|
|
49
49
|
}
|
|
50
50
|
return to;
|
|
51
51
|
};
|
|
52
|
-
var __toESM$1 = (mod, isNodeMode, target$1) => (target$1 = mod != null ? __create$1(__getProtoOf$1(mod)) : {}, __copyProps$1(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target$1, "default", {
|
|
53
|
-
value: mod,
|
|
52
|
+
var __toESM$1 = (mod$1, isNodeMode, target$1) => (target$1 = mod$1 != null ? __create$1(__getProtoOf$1(mod$1)) : {}, __copyProps$1(isNodeMode || !mod$1 || !mod$1.__esModule ? __defProp$1(target$1, "default", {
|
|
53
|
+
value: mod$1,
|
|
54
54
|
enumerable: true
|
|
55
|
-
}) : target$1, mod));
|
|
55
|
+
}) : target$1, mod$1));
|
|
56
56
|
var __require$2 = /* @__PURE__ */ createRequire(import.meta.url);
|
|
57
57
|
|
|
58
58
|
//#endregion
|
|
@@ -1503,7 +1503,7 @@ async function assertWranglerVersion() {
|
|
|
1503
1503
|
* The default compatibility date to use when the user omits one.
|
|
1504
1504
|
* This value is injected at build time and remains fixed for each release.
|
|
1505
1505
|
*/
|
|
1506
|
-
const DEFAULT_COMPAT_DATE = "2026-05-
|
|
1506
|
+
const DEFAULT_COMPAT_DATE = "2026-05-22";
|
|
1507
1507
|
|
|
1508
1508
|
//#endregion
|
|
1509
1509
|
//#region ../../node_modules/.pnpm/@remix-run+node-fetch-server@0.8.0/node_modules/@remix-run/node-fetch-server/dist/node-fetch-server.js
|
|
@@ -1582,8 +1582,6 @@ const kRequestType = Symbol("kRequestType");
|
|
|
1582
1582
|
//#endregion
|
|
1583
1583
|
//#region ../workers-utils/dist/chunk-OZQVB3L3.mjs
|
|
1584
1584
|
var INHERIT_SYMBOL = Symbol.for("inherit_binding");
|
|
1585
|
-
var SERVICE_TAG_PREFIX = "cf:service=";
|
|
1586
|
-
var ENVIRONMENT_TAG_PREFIX = "cf:environment=";
|
|
1587
1585
|
var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
|
|
1588
1586
|
|
|
1589
1587
|
//#endregion
|
|
@@ -1602,8 +1600,8 @@ var __require$1 = /* @__PURE__ */ ((x) => typeof __require$2 !== "undefined" ? _
|
|
|
1602
1600
|
if (typeof __require$2 !== "undefined") return __require$2.apply(this, arguments);
|
|
1603
1601
|
throw Error("Dynamic require of \"" + x + "\" is not supported");
|
|
1604
1602
|
});
|
|
1605
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
1606
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
1603
|
+
var __commonJS = (cb, mod$1) => function __require2() {
|
|
1604
|
+
return mod$1 || (0, cb[__getOwnPropNames(cb)[0]])((mod$1 = { exports: {} }).exports, mod$1), mod$1.exports;
|
|
1607
1605
|
};
|
|
1608
1606
|
var __export = (target$1, all$1) => {
|
|
1609
1607
|
for (var name in all$1) __defProp(target$1, name, {
|
|
@@ -1620,381 +1618,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
1620
1618
|
}
|
|
1621
1619
|
return to;
|
|
1622
1620
|
};
|
|
1623
|
-
var __reExport = (target$1, mod, secondTarget) => (__copyProps(target$1, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
1624
|
-
var __toESM = (mod, isNodeMode, target$1) => (target$1 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target$1, "default", {
|
|
1625
|
-
value: mod,
|
|
1621
|
+
var __reExport = (target$1, mod$1, secondTarget) => (__copyProps(target$1, mod$1, "default"), secondTarget && __copyProps(secondTarget, mod$1, "default"));
|
|
1622
|
+
var __toESM = (mod$1, isNodeMode, target$1) => (target$1 = mod$1 != null ? __create(__getProtoOf(mod$1)) : {}, __copyProps(isNodeMode || !mod$1 || !mod$1.__esModule ? __defProp(target$1, "default", {
|
|
1623
|
+
value: mod$1,
|
|
1626
1624
|
enumerable: true
|
|
1627
|
-
}) : target$1, mod));
|
|
1628
|
-
|
|
1629
|
-
//#endregion
|
|
1630
|
-
//#region ../workers-utils/dist/chunk-BLWXWFJK.mjs
|
|
1631
|
-
function isCompatDate(str) {
|
|
1632
|
-
return /^\d{4}-\d{2}-\d{2}$/.test(str);
|
|
1633
|
-
}
|
|
1634
|
-
__name(isCompatDate, "isCompatDate");
|
|
1635
|
-
function formatCompatibilityDate(date) {
|
|
1636
|
-
const compatDate = date.toISOString().slice(0, 10);
|
|
1637
|
-
assert(isCompatDate(compatDate));
|
|
1638
|
-
return compatDate;
|
|
1639
|
-
}
|
|
1640
|
-
__name(formatCompatibilityDate, "formatCompatibilityDate");
|
|
1641
|
-
function getTodaysCompatDate() {
|
|
1642
|
-
return formatCompatibilityDate(/* @__PURE__ */ new Date());
|
|
1643
|
-
}
|
|
1644
|
-
__name(getTodaysCompatDate, "getTodaysCompatDate");
|
|
1645
|
-
function assertNever(_value) {}
|
|
1646
|
-
__name(assertNever, "assertNever");
|
|
1647
|
-
function mapWorkerMetadataBindings(bindings) {
|
|
1648
|
-
return bindings.filter((binding) => binding.type !== "secret_text").reduce((configObj, binding) => {
|
|
1649
|
-
switch (binding.type) {
|
|
1650
|
-
case "plain_text":
|
|
1651
|
-
configObj.vars = {
|
|
1652
|
-
...configObj.vars ?? {},
|
|
1653
|
-
[binding.name]: binding.text
|
|
1654
|
-
};
|
|
1655
|
-
break;
|
|
1656
|
-
case "json":
|
|
1657
|
-
configObj.vars = {
|
|
1658
|
-
...configObj.vars ?? {},
|
|
1659
|
-
name: binding.name,
|
|
1660
|
-
json: binding.json
|
|
1661
|
-
};
|
|
1662
|
-
break;
|
|
1663
|
-
case "kv_namespace":
|
|
1664
|
-
configObj.kv_namespaces = [...configObj.kv_namespaces ?? [], {
|
|
1665
|
-
id: binding.namespace_id,
|
|
1666
|
-
binding: binding.name
|
|
1667
|
-
}];
|
|
1668
|
-
break;
|
|
1669
|
-
case "durable_object_namespace":
|
|
1670
|
-
configObj.durable_objects = { bindings: [...configObj.durable_objects?.bindings ?? [], {
|
|
1671
|
-
name: binding.name,
|
|
1672
|
-
class_name: binding.class_name,
|
|
1673
|
-
script_name: binding.script_name,
|
|
1674
|
-
environment: binding.environment
|
|
1675
|
-
}] };
|
|
1676
|
-
break;
|
|
1677
|
-
case "d1":
|
|
1678
|
-
configObj.d1_databases = [...configObj.d1_databases ?? [], {
|
|
1679
|
-
binding: binding.name,
|
|
1680
|
-
database_id: binding.id
|
|
1681
|
-
}];
|
|
1682
|
-
break;
|
|
1683
|
-
case "browser":
|
|
1684
|
-
configObj.browser = { binding: binding.name };
|
|
1685
|
-
break;
|
|
1686
|
-
case "ai":
|
|
1687
|
-
configObj.ai = { binding: binding.name };
|
|
1688
|
-
break;
|
|
1689
|
-
case "images":
|
|
1690
|
-
configObj.images = { binding: binding.name };
|
|
1691
|
-
break;
|
|
1692
|
-
case "stream":
|
|
1693
|
-
configObj.stream = { binding: binding.name };
|
|
1694
|
-
break;
|
|
1695
|
-
case "media":
|
|
1696
|
-
configObj.media = { binding: binding.name };
|
|
1697
|
-
break;
|
|
1698
|
-
case "r2_bucket":
|
|
1699
|
-
configObj.r2_buckets = [...configObj.r2_buckets ?? [], {
|
|
1700
|
-
binding: binding.name,
|
|
1701
|
-
bucket_name: binding.bucket_name,
|
|
1702
|
-
jurisdiction: binding.jurisdiction
|
|
1703
|
-
}];
|
|
1704
|
-
break;
|
|
1705
|
-
case "secrets_store_secret":
|
|
1706
|
-
configObj.secrets_store_secrets = [...configObj.secrets_store_secrets ?? [], {
|
|
1707
|
-
binding: binding.name,
|
|
1708
|
-
store_id: binding.store_id,
|
|
1709
|
-
secret_name: binding.secret_name
|
|
1710
|
-
}];
|
|
1711
|
-
break;
|
|
1712
|
-
case "artifacts":
|
|
1713
|
-
configObj.artifacts = [...configObj.artifacts ?? [], {
|
|
1714
|
-
binding: binding.name,
|
|
1715
|
-
namespace: binding.namespace
|
|
1716
|
-
}];
|
|
1717
|
-
break;
|
|
1718
|
-
case "unsafe_hello_world":
|
|
1719
|
-
configObj.unsafe_hello_world = [...configObj.unsafe_hello_world ?? [], {
|
|
1720
|
-
binding: binding.name,
|
|
1721
|
-
enable_timer: binding.enable_timer
|
|
1722
|
-
}];
|
|
1723
|
-
break;
|
|
1724
|
-
case "flagship":
|
|
1725
|
-
configObj.flagship = [...configObj.flagship ?? [], {
|
|
1726
|
-
binding: binding.name,
|
|
1727
|
-
app_id: binding.app_id
|
|
1728
|
-
}];
|
|
1729
|
-
break;
|
|
1730
|
-
case "service":
|
|
1731
|
-
configObj.services = [...configObj.services ?? [], {
|
|
1732
|
-
binding: binding.name,
|
|
1733
|
-
service: binding.service,
|
|
1734
|
-
environment: binding.environment,
|
|
1735
|
-
entrypoint: binding.entrypoint
|
|
1736
|
-
}];
|
|
1737
|
-
break;
|
|
1738
|
-
case "analytics_engine":
|
|
1739
|
-
configObj.analytics_engine_datasets = [...configObj.analytics_engine_datasets ?? [], {
|
|
1740
|
-
binding: binding.name,
|
|
1741
|
-
dataset: binding.dataset
|
|
1742
|
-
}];
|
|
1743
|
-
break;
|
|
1744
|
-
case "dispatch_namespace":
|
|
1745
|
-
configObj.dispatch_namespaces = [...configObj.dispatch_namespaces ?? [], {
|
|
1746
|
-
binding: binding.name,
|
|
1747
|
-
namespace: binding.namespace,
|
|
1748
|
-
...binding.outbound && { outbound: {
|
|
1749
|
-
service: binding.outbound.worker.service,
|
|
1750
|
-
environment: binding.outbound.worker.environment,
|
|
1751
|
-
parameters: binding.outbound.params?.map((p$1) => p$1.name) ?? []
|
|
1752
|
-
} }
|
|
1753
|
-
}];
|
|
1754
|
-
break;
|
|
1755
|
-
case "logfwdr":
|
|
1756
|
-
configObj.logfwdr = { bindings: [...configObj.logfwdr?.bindings ?? [], {
|
|
1757
|
-
name: binding.name,
|
|
1758
|
-
destination: binding.destination
|
|
1759
|
-
}] };
|
|
1760
|
-
break;
|
|
1761
|
-
case "wasm_module":
|
|
1762
|
-
configObj.wasm_modules = {
|
|
1763
|
-
...configObj.wasm_modules ?? {},
|
|
1764
|
-
[binding.name]: binding.part
|
|
1765
|
-
};
|
|
1766
|
-
break;
|
|
1767
|
-
case "text_blob":
|
|
1768
|
-
configObj.text_blobs = {
|
|
1769
|
-
...configObj.text_blobs ?? {},
|
|
1770
|
-
[binding.name]: binding.part
|
|
1771
|
-
};
|
|
1772
|
-
break;
|
|
1773
|
-
case "data_blob":
|
|
1774
|
-
configObj.data_blobs = {
|
|
1775
|
-
...configObj.data_blobs ?? {},
|
|
1776
|
-
[binding.name]: binding.part
|
|
1777
|
-
};
|
|
1778
|
-
break;
|
|
1779
|
-
case "secret_text": break;
|
|
1780
|
-
case "version_metadata":
|
|
1781
|
-
configObj.version_metadata = { binding: binding.name };
|
|
1782
|
-
break;
|
|
1783
|
-
case "send_email":
|
|
1784
|
-
configObj.send_email = [...configObj.send_email ?? [], {
|
|
1785
|
-
name: binding.name,
|
|
1786
|
-
destination_address: binding.destination_address,
|
|
1787
|
-
allowed_destination_addresses: binding.allowed_destination_addresses,
|
|
1788
|
-
allowed_sender_addresses: binding.allowed_sender_addresses
|
|
1789
|
-
}];
|
|
1790
|
-
break;
|
|
1791
|
-
case "queue":
|
|
1792
|
-
configObj.queues ??= { producers: [] };
|
|
1793
|
-
configObj.queues.producers = [...configObj.queues.producers ?? [], {
|
|
1794
|
-
binding: binding.name,
|
|
1795
|
-
queue: binding.queue_name,
|
|
1796
|
-
delivery_delay: binding.delivery_delay
|
|
1797
|
-
}];
|
|
1798
|
-
break;
|
|
1799
|
-
case "vectorize":
|
|
1800
|
-
configObj.vectorize = [...configObj.vectorize ?? [], {
|
|
1801
|
-
binding: binding.name,
|
|
1802
|
-
index_name: binding.index_name
|
|
1803
|
-
}];
|
|
1804
|
-
break;
|
|
1805
|
-
case "ai_search_namespace":
|
|
1806
|
-
configObj.ai_search_namespaces = [...configObj.ai_search_namespaces ?? [], {
|
|
1807
|
-
binding: binding.name,
|
|
1808
|
-
namespace: binding.namespace
|
|
1809
|
-
}];
|
|
1810
|
-
break;
|
|
1811
|
-
case "ai_search":
|
|
1812
|
-
configObj.ai_search = [...configObj.ai_search ?? [], {
|
|
1813
|
-
binding: binding.name,
|
|
1814
|
-
instance_name: binding.instance_name
|
|
1815
|
-
}];
|
|
1816
|
-
break;
|
|
1817
|
-
case "hyperdrive":
|
|
1818
|
-
configObj.hyperdrive = [...configObj.hyperdrive ?? [], {
|
|
1819
|
-
binding: binding.name,
|
|
1820
|
-
id: binding.id
|
|
1821
|
-
}];
|
|
1822
|
-
break;
|
|
1823
|
-
case "mtls_certificate":
|
|
1824
|
-
configObj.mtls_certificates = [...configObj.mtls_certificates ?? [], {
|
|
1825
|
-
binding: binding.name,
|
|
1826
|
-
certificate_id: binding.certificate_id
|
|
1827
|
-
}];
|
|
1828
|
-
break;
|
|
1829
|
-
case "pipelines":
|
|
1830
|
-
configObj.pipelines = [...configObj.pipelines ?? [], {
|
|
1831
|
-
binding: binding.name,
|
|
1832
|
-
pipeline: binding.pipeline
|
|
1833
|
-
}];
|
|
1834
|
-
break;
|
|
1835
|
-
case "assets":
|
|
1836
|
-
configObj.assets = { binding: binding.name };
|
|
1837
|
-
break;
|
|
1838
|
-
case "inherit":
|
|
1839
|
-
configObj.unsafe = {
|
|
1840
|
-
bindings: [...configObj.unsafe?.bindings ?? [], binding],
|
|
1841
|
-
metadata: configObj.unsafe?.metadata ?? void 0
|
|
1842
|
-
};
|
|
1843
|
-
break;
|
|
1844
|
-
case "workflow":
|
|
1845
|
-
configObj.workflows = [...configObj.workflows ?? [], {
|
|
1846
|
-
binding: binding.name,
|
|
1847
|
-
name: binding.workflow_name,
|
|
1848
|
-
class_name: binding.class_name,
|
|
1849
|
-
script_name: binding.script_name
|
|
1850
|
-
}];
|
|
1851
|
-
break;
|
|
1852
|
-
case "worker_loader":
|
|
1853
|
-
configObj.worker_loaders = [...configObj.worker_loaders ?? [], { binding: binding.name }];
|
|
1854
|
-
break;
|
|
1855
|
-
case "ratelimit":
|
|
1856
|
-
configObj.ratelimits = [...configObj.ratelimits ?? [], {
|
|
1857
|
-
name: binding.name,
|
|
1858
|
-
namespace_id: binding.namespace_id,
|
|
1859
|
-
simple: {
|
|
1860
|
-
limit: binding.simple.limit,
|
|
1861
|
-
period: binding.simple.period
|
|
1862
|
-
}
|
|
1863
|
-
}];
|
|
1864
|
-
break;
|
|
1865
|
-
case "vpc_service":
|
|
1866
|
-
configObj.vpc_services = [...configObj.vpc_services ?? [], {
|
|
1867
|
-
binding: binding.name,
|
|
1868
|
-
service_id: binding.service_id
|
|
1869
|
-
}];
|
|
1870
|
-
break;
|
|
1871
|
-
case "vpc_network":
|
|
1872
|
-
if (binding.tunnel_id !== void 0) configObj.vpc_networks = [...configObj.vpc_networks ?? [], {
|
|
1873
|
-
binding: binding.name,
|
|
1874
|
-
tunnel_id: binding.tunnel_id
|
|
1875
|
-
}];
|
|
1876
|
-
else if (binding.network_id !== void 0) configObj.vpc_networks = [...configObj.vpc_networks ?? [], {
|
|
1877
|
-
binding: binding.name,
|
|
1878
|
-
network_id: binding.network_id
|
|
1879
|
-
}];
|
|
1880
|
-
break;
|
|
1881
|
-
default: configObj.unsafe = {
|
|
1882
|
-
bindings: [...configObj.unsafe?.bindings ?? [], binding],
|
|
1883
|
-
metadata: configObj.unsafe?.metadata ?? void 0
|
|
1884
|
-
};
|
|
1885
|
-
}
|
|
1886
|
-
return configObj;
|
|
1887
|
-
}, {});
|
|
1888
|
-
}
|
|
1889
|
-
__name(mapWorkerMetadataBindings, "mapWorkerMetadataBindings");
|
|
1890
|
-
function convertWorkerToWranglerConfig(config) {
|
|
1891
|
-
const mappedBindings = mapWorkerMetadataBindings(config.bindings);
|
|
1892
|
-
const durableObjectClassNames = config.bindings.filter((binding) => binding.type === "durable_object_namespace" && binding.script_name === config.name).map((durableObject) => durableObject.class_name);
|
|
1893
|
-
const allRoutes = [...config.routes.map((r$1) => ({
|
|
1894
|
-
pattern: r$1.pattern,
|
|
1895
|
-
zone_name: r$1.zone_name
|
|
1896
|
-
})), ...config.domains.map((c) => ({
|
|
1897
|
-
pattern: c.hostname,
|
|
1898
|
-
zone_name: c.zone_name,
|
|
1899
|
-
custom_domain: true,
|
|
1900
|
-
enabled: c.enabled,
|
|
1901
|
-
previews_enabled: c.previews_enabled
|
|
1902
|
-
}))];
|
|
1903
|
-
return {
|
|
1904
|
-
name: config.name,
|
|
1905
|
-
main: config.entrypoint,
|
|
1906
|
-
workers_dev: config.subdomain.enabled,
|
|
1907
|
-
preview_urls: config.subdomain.previews_enabled,
|
|
1908
|
-
compatibility_date: config.compatibility_date ?? getTodaysCompatDate(),
|
|
1909
|
-
compatibility_flags: config.compatibility_flags,
|
|
1910
|
-
...allRoutes.length ? { routes: allRoutes } : {},
|
|
1911
|
-
placement: config.placement?.mode === "smart" ? { mode: "smart" } : void 0,
|
|
1912
|
-
limits: config.limits,
|
|
1913
|
-
...durableObjectClassNames.length && config.migration_tag ? { migrations: [{
|
|
1914
|
-
tag: config.migration_tag,
|
|
1915
|
-
new_classes: durableObjectClassNames
|
|
1916
|
-
}] } : {},
|
|
1917
|
-
...config.schedules.length ? { triggers: { crons: config.schedules.map((scheduled) => scheduled.cron) } } : {},
|
|
1918
|
-
tail_consumers: config.tail_consumers ?? void 0,
|
|
1919
|
-
observability: config.observability,
|
|
1920
|
-
...mappedBindings
|
|
1921
|
-
};
|
|
1922
|
-
}
|
|
1923
|
-
__name(convertWorkerToWranglerConfig, "convertWorkerToWranglerConfig");
|
|
1924
|
-
function constructWranglerConfig(workerOrWorkers) {
|
|
1925
|
-
let workers;
|
|
1926
|
-
if (Array.isArray(workerOrWorkers)) workers = workerOrWorkers;
|
|
1927
|
-
else workers = [workerOrWorkers];
|
|
1928
|
-
const topLevelEnv = workers.find((w) => !w.tags?.some((t$5) => t$5.startsWith(ENVIRONMENT_TAG_PREFIX)));
|
|
1929
|
-
const workerName = topLevelEnv?.name ?? workers[0].name;
|
|
1930
|
-
const entrypoint = topLevelEnv?.entrypoint ?? workers[0].entrypoint;
|
|
1931
|
-
let combinedConfig;
|
|
1932
|
-
if (topLevelEnv) combinedConfig = convertWorkerToWranglerConfig(topLevelEnv);
|
|
1933
|
-
else combinedConfig = {
|
|
1934
|
-
name: workerName,
|
|
1935
|
-
main: entrypoint
|
|
1936
|
-
};
|
|
1937
|
-
for (const env$1 of workers) {
|
|
1938
|
-
const serviceTag = env$1.tags?.find((t$5) => t$5 === `${SERVICE_TAG_PREFIX}${workerName}`);
|
|
1939
|
-
const envTag = env$1.tags?.find((t$5) => t$5.startsWith(ENVIRONMENT_TAG_PREFIX));
|
|
1940
|
-
if (serviceTag !== `${SERVICE_TAG_PREFIX}${workerName}` || envTag === void 0) continue;
|
|
1941
|
-
const [_, envName] = envTag.split("=");
|
|
1942
|
-
combinedConfig.env ??= {};
|
|
1943
|
-
combinedConfig.env[envName] = convertWorkerToWranglerConfig(env$1);
|
|
1944
|
-
}
|
|
1945
|
-
return combinedConfig;
|
|
1946
|
-
}
|
|
1947
|
-
__name(constructWranglerConfig, "constructWranglerConfig");
|
|
1948
|
-
|
|
1949
|
-
//#endregion
|
|
1950
|
-
//#region ../workers-utils/dist/chunk-O4YGOZSW.mjs
|
|
1951
|
-
var MetricsRegistry = class {
|
|
1952
|
-
static {
|
|
1953
|
-
__name(this, "MetricsRegistry");
|
|
1954
|
-
}
|
|
1955
|
-
counters = [];
|
|
1956
|
-
/**
|
|
1957
|
-
* Create and register a new counter metric.
|
|
1958
|
-
*
|
|
1959
|
-
* @param name - The metric name (e.g. "service_request_total")
|
|
1960
|
-
* @param help - A human-readable description of the metric
|
|
1961
|
-
* @returns A Counter that can be incremented
|
|
1962
|
-
*/
|
|
1963
|
-
createCounter(name, help) {
|
|
1964
|
-
const entry = {
|
|
1965
|
-
name,
|
|
1966
|
-
help,
|
|
1967
|
-
value: 0
|
|
1968
|
-
};
|
|
1969
|
-
this.counters.push(entry);
|
|
1970
|
-
return {
|
|
1971
|
-
inc: /* @__PURE__ */ __name(() => {
|
|
1972
|
-
entry.value++;
|
|
1973
|
-
}, "inc"),
|
|
1974
|
-
add: /* @__PURE__ */ __name((amount) => {
|
|
1975
|
-
if (amount < 0) throw new Error("Counter value cannot decrease");
|
|
1976
|
-
entry.value += amount;
|
|
1977
|
-
}, "add")
|
|
1978
|
-
};
|
|
1979
|
-
}
|
|
1980
|
-
/**
|
|
1981
|
-
* Serialize all registered metrics in Prometheus text exposition format.
|
|
1982
|
-
*
|
|
1983
|
-
* @see https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
|
|
1984
|
-
*/
|
|
1985
|
-
metrics() {
|
|
1986
|
-
return this.counters.map((c) => {
|
|
1987
|
-
let result = "";
|
|
1988
|
-
if (c.help.length > 0) result += `# HELP ${c.name} ${c.help}
|
|
1989
|
-
`;
|
|
1990
|
-
result += `# TYPE ${c.name} counter
|
|
1991
|
-
`;
|
|
1992
|
-
result += `${c.name} ${c.value}
|
|
1993
|
-
`;
|
|
1994
|
-
return result;
|
|
1995
|
-
}).join("");
|
|
1996
|
-
}
|
|
1997
|
-
};
|
|
1625
|
+
}) : target$1, mod$1));
|
|
1998
1626
|
|
|
1999
1627
|
//#endregion
|
|
2000
1628
|
//#region ../workers-utils/dist/chunk-GMTGAG26.mjs
|
|
@@ -10524,15 +10152,15 @@ var require_client_h1 = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm
|
|
|
10524
10152
|
let extractBody$4;
|
|
10525
10153
|
function lazyllhttp() {
|
|
10526
10154
|
const llhttpWasmData = process.env.JEST_WORKER_ID ? require_llhttp_wasm() : void 0;
|
|
10527
|
-
let mod;
|
|
10155
|
+
let mod$1;
|
|
10528
10156
|
let useWasmSIMD = process.arch !== "ppc64";
|
|
10529
10157
|
if (process.env.UNDICI_NO_WASM_SIMD === "1") useWasmSIMD = true;
|
|
10530
10158
|
else if (process.env.UNDICI_NO_WASM_SIMD === "0") useWasmSIMD = false;
|
|
10531
10159
|
if (useWasmSIMD) try {
|
|
10532
|
-
mod = new WebAssembly.Module(require_llhttp_simd_wasm());
|
|
10160
|
+
mod$1 = new WebAssembly.Module(require_llhttp_simd_wasm());
|
|
10533
10161
|
} catch {}
|
|
10534
|
-
if (!mod) mod = new WebAssembly.Module(llhttpWasmData || require_llhttp_wasm());
|
|
10535
|
-
return new WebAssembly.Instance(mod, { env: {
|
|
10162
|
+
if (!mod$1) mod$1 = new WebAssembly.Module(llhttpWasmData || require_llhttp_wasm());
|
|
10163
|
+
return new WebAssembly.Instance(mod$1, { env: {
|
|
10536
10164
|
wasm_on_url: (p$1, at, len) => {
|
|
10537
10165
|
return 0;
|
|
10538
10166
|
},
|
|
@@ -13462,8 +13090,8 @@ var require_socks5_proxy_agent = /* @__PURE__ */ __commonJS$1({ "../../node_modu
|
|
|
13462
13090
|
const timeout$1 = setTimeout(() => {
|
|
13463
13091
|
reject(/* @__PURE__ */ new Error("SOCKS5 connection timeout"));
|
|
13464
13092
|
}, 5e3);
|
|
13465
|
-
const onConnected = (info) => {
|
|
13466
|
-
debug("SOCKS5 tunnel established to", targetHost, targetPort, "via", info);
|
|
13093
|
+
const onConnected = (info$1) => {
|
|
13094
|
+
debug("SOCKS5 tunnel established to", targetHost, targetPort, "via", info$1);
|
|
13467
13095
|
clearTimeout(timeout$1);
|
|
13468
13096
|
socks5Client.removeListener("error", onError$1);
|
|
13469
13097
|
resolve$4();
|
|
@@ -26461,13 +26089,13 @@ var require_node = __commonJS({ "../../node_modules/.pnpm/os-paths@7.4.0/node_mo
|
|
|
26461
26089
|
} : function(o, v) {
|
|
26462
26090
|
o["default"] = v;
|
|
26463
26091
|
});
|
|
26464
|
-
var __importStar = exports$1 && exports$1.__importStar || function(mod) {
|
|
26465
|
-
if (mod && mod.__esModule) return mod;
|
|
26092
|
+
var __importStar = exports$1 && exports$1.__importStar || function(mod$1) {
|
|
26093
|
+
if (mod$1 && mod$1.__esModule) return mod$1;
|
|
26466
26094
|
var result = {};
|
|
26467
|
-
if (mod != null) {
|
|
26468
|
-
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26095
|
+
if (mod$1 != null) {
|
|
26096
|
+
for (var k in mod$1) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod$1, k)) __createBinding(result, mod$1, k);
|
|
26469
26097
|
}
|
|
26470
|
-
__setModuleDefault(result, mod);
|
|
26098
|
+
__setModuleDefault(result, mod$1);
|
|
26471
26099
|
return result;
|
|
26472
26100
|
};
|
|
26473
26101
|
exports$1.__esModule = true;
|
|
@@ -26510,17 +26138,17 @@ var require_node2 = __commonJS({ "../../node_modules/.pnpm/xdg-portable@10.6.0/n
|
|
|
26510
26138
|
} : function(o, v) {
|
|
26511
26139
|
o["default"] = v;
|
|
26512
26140
|
});
|
|
26513
|
-
var __importStar = exports$1 && exports$1.__importStar || function(mod) {
|
|
26514
|
-
if (mod && mod.__esModule) return mod;
|
|
26141
|
+
var __importStar = exports$1 && exports$1.__importStar || function(mod$1) {
|
|
26142
|
+
if (mod$1 && mod$1.__esModule) return mod$1;
|
|
26515
26143
|
var result = {};
|
|
26516
|
-
if (mod != null) {
|
|
26517
|
-
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26144
|
+
if (mod$1 != null) {
|
|
26145
|
+
for (var k in mod$1) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod$1, k)) __createBinding(result, mod$1, k);
|
|
26518
26146
|
}
|
|
26519
|
-
__setModuleDefault(result, mod);
|
|
26147
|
+
__setModuleDefault(result, mod$1);
|
|
26520
26148
|
return result;
|
|
26521
26149
|
};
|
|
26522
|
-
var __importDefault = exports$1 && exports$1.__importDefault || function(mod) {
|
|
26523
|
-
return mod && mod.__esModule ? mod : { "default": mod };
|
|
26150
|
+
var __importDefault = exports$1 && exports$1.__importDefault || function(mod$1) {
|
|
26151
|
+
return mod$1 && mod$1.__esModule ? mod$1 : { "default": mod$1 };
|
|
26524
26152
|
};
|
|
26525
26153
|
exports$1.__esModule = true;
|
|
26526
26154
|
exports$1.adapter = void 0;
|
|
@@ -26562,17 +26190,17 @@ var require_node3 = __commonJS({ "../../node_modules/.pnpm/xdg-app-paths@8.3.0/n
|
|
|
26562
26190
|
} : function(o, v) {
|
|
26563
26191
|
o["default"] = v;
|
|
26564
26192
|
});
|
|
26565
|
-
var __importStar = exports$1 && exports$1.__importStar || function(mod) {
|
|
26566
|
-
if (mod && mod.__esModule) return mod;
|
|
26193
|
+
var __importStar = exports$1 && exports$1.__importStar || function(mod$1) {
|
|
26194
|
+
if (mod$1 && mod$1.__esModule) return mod$1;
|
|
26567
26195
|
var result = {};
|
|
26568
|
-
if (mod != null) {
|
|
26569
|
-
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26196
|
+
if (mod$1 != null) {
|
|
26197
|
+
for (var k in mod$1) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod$1, k)) __createBinding(result, mod$1, k);
|
|
26570
26198
|
}
|
|
26571
|
-
__setModuleDefault(result, mod);
|
|
26199
|
+
__setModuleDefault(result, mod$1);
|
|
26572
26200
|
return result;
|
|
26573
26201
|
};
|
|
26574
|
-
var __importDefault = exports$1 && exports$1.__importDefault || function(mod) {
|
|
26575
|
-
return mod && mod.__esModule ? mod : { "default": mod };
|
|
26202
|
+
var __importDefault = exports$1 && exports$1.__importDefault || function(mod$1) {
|
|
26203
|
+
return mod$1 && mod$1.__esModule ? mod$1 : { "default": mod$1 };
|
|
26576
26204
|
};
|
|
26577
26205
|
exports$1.__esModule = true;
|
|
26578
26206
|
exports$1.adapter = void 0;
|
|
@@ -31617,6 +31245,26 @@ var validateWorkflowBinding = /* @__PURE__ */ __name((diagnostics, field, value)
|
|
|
31617
31245
|
diagnostics.errors.push(`"${field}" bindings should, optionally, have a boolean "remote" field but got ${JSON.stringify(value)}.`);
|
|
31618
31246
|
isValid2 = false;
|
|
31619
31247
|
}
|
|
31248
|
+
if (hasProperty(value, "schedule") && value.schedule !== void 0) if (typeof value.schedule === "string") {
|
|
31249
|
+
if (value.schedule.length === 0) {
|
|
31250
|
+
diagnostics.errors.push(`"${field}" bindings "schedule" field must not be an empty string.`);
|
|
31251
|
+
isValid2 = false;
|
|
31252
|
+
}
|
|
31253
|
+
} else if (Array.isArray(value.schedule)) {
|
|
31254
|
+
if (value.schedule.length === 0) {
|
|
31255
|
+
diagnostics.errors.push(`"${field}" bindings "schedule" field must not be an empty array.`);
|
|
31256
|
+
isValid2 = false;
|
|
31257
|
+
} else if (!value.schedule.every((s) => typeof s === "string")) {
|
|
31258
|
+
diagnostics.errors.push(`"${field}" bindings should, optionally, have a string or array of strings "schedule" field but got ${JSON.stringify(value)}.`);
|
|
31259
|
+
isValid2 = false;
|
|
31260
|
+
} else if (value.schedule.some((s) => s === "")) {
|
|
31261
|
+
diagnostics.errors.push(`"${field}" bindings "schedule" field must not contain empty strings.`);
|
|
31262
|
+
isValid2 = false;
|
|
31263
|
+
}
|
|
31264
|
+
} else {
|
|
31265
|
+
diagnostics.errors.push(`"${field}" bindings should, optionally, have a string or array of strings "schedule" field but got ${JSON.stringify(value)}.`);
|
|
31266
|
+
isValid2 = false;
|
|
31267
|
+
}
|
|
31620
31268
|
if (hasProperty(value, "limits") && value.limits !== void 0) if (typeof value.limits !== "object" || value.limits === null || Array.isArray(value.limits)) {
|
|
31621
31269
|
diagnostics.errors.push(`"${field}" bindings should, optionally, have an object "limits" field but got ${JSON.stringify(value)}.`);
|
|
31622
31270
|
isValid2 = false;
|
|
@@ -31636,7 +31284,8 @@ var validateWorkflowBinding = /* @__PURE__ */ __name((diagnostics, field, value)
|
|
|
31636
31284
|
"class_name",
|
|
31637
31285
|
"script_name",
|
|
31638
31286
|
"remote",
|
|
31639
|
-
"limits"
|
|
31287
|
+
"limits",
|
|
31288
|
+
"schedule"
|
|
31640
31289
|
]);
|
|
31641
31290
|
return isValid2;
|
|
31642
31291
|
}, "validateWorkflowBinding");
|
|
@@ -33830,8 +33479,1674 @@ var require_picocolors = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnp
|
|
|
33830
33479
|
}) });
|
|
33831
33480
|
|
|
33832
33481
|
//#endregion
|
|
33833
|
-
//#region
|
|
33482
|
+
//#region ../../node_modules/.pnpm/qr@0.6.0/node_modules/qr/index.js
|
|
33834
33483
|
var import_picocolors$5 = /* @__PURE__ */ __toESM$1(require_picocolors(), 1);
|
|
33484
|
+
/*!
|
|
33485
|
+
Copyright (c) 2023 Paul Miller (paulmillr.com)
|
|
33486
|
+
The library paulmillr-qr is dual-licensed under the Apache 2.0 OR MIT license.
|
|
33487
|
+
You can select a license of your choice.
|
|
33488
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
33489
|
+
you may not use this file except in compliance with the License.
|
|
33490
|
+
You may obtain a copy of the License at
|
|
33491
|
+
|
|
33492
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
33493
|
+
|
|
33494
|
+
Unless required by applicable law or agreed to in writing, software
|
|
33495
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
33496
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
33497
|
+
See the License for the specific language governing permissions and
|
|
33498
|
+
limitations under the License.
|
|
33499
|
+
*/
|
|
33500
|
+
const chCodes = {
|
|
33501
|
+
newline: 10,
|
|
33502
|
+
reset: 27
|
|
33503
|
+
};
|
|
33504
|
+
function assertNumber(n$1) {
|
|
33505
|
+
if (!Number.isSafeInteger(n$1)) throw new Error(`integer expected: ${n$1}`);
|
|
33506
|
+
}
|
|
33507
|
+
function validateVersion(ver) {
|
|
33508
|
+
if (!Number.isSafeInteger(ver) || ver < 1 || ver > 40) throw new Error(`Invalid version=${ver}. Expected number [1..40]`);
|
|
33509
|
+
}
|
|
33510
|
+
function bin(dec, pad) {
|
|
33511
|
+
return dec.toString(2).padStart(pad, "0");
|
|
33512
|
+
}
|
|
33513
|
+
function mod(a, b) {
|
|
33514
|
+
const result = a % b;
|
|
33515
|
+
return result >= 0 ? result : b + result;
|
|
33516
|
+
}
|
|
33517
|
+
function fillArr(length, val) {
|
|
33518
|
+
return new Array(length).fill(val);
|
|
33519
|
+
}
|
|
33520
|
+
function popcnt(n$1) {
|
|
33521
|
+
n$1 = n$1 - (n$1 >>> 1 & 1431655765);
|
|
33522
|
+
n$1 = (n$1 & 858993459) + (n$1 >>> 2 & 858993459);
|
|
33523
|
+
return (n$1 + (n$1 >>> 4) & 252645135) * 16843009 >>> 24;
|
|
33524
|
+
}
|
|
33525
|
+
/**
|
|
33526
|
+
* Interleaves byte blocks.
|
|
33527
|
+
* @param blocks [[1, 2, 3], [4, 5, 6]]
|
|
33528
|
+
* @returns [1, 4, 2, 5, 3, 6]
|
|
33529
|
+
*/
|
|
33530
|
+
function interleaveBytes(blocks) {
|
|
33531
|
+
let maxLen = 0;
|
|
33532
|
+
let totalLen = 0;
|
|
33533
|
+
for (const block of blocks) {
|
|
33534
|
+
maxLen = Math.max(maxLen, block.length);
|
|
33535
|
+
totalLen += block.length;
|
|
33536
|
+
}
|
|
33537
|
+
const result = new Uint8Array(totalLen);
|
|
33538
|
+
let idx = 0;
|
|
33539
|
+
for (let i$1 = 0; i$1 < maxLen; i$1++) for (const block of blocks) if (i$1 < block.length) result[idx++] = block[i$1];
|
|
33540
|
+
return result;
|
|
33541
|
+
}
|
|
33542
|
+
function best() {
|
|
33543
|
+
let best$1;
|
|
33544
|
+
let bestScore = Infinity;
|
|
33545
|
+
return {
|
|
33546
|
+
add(score, value) {
|
|
33547
|
+
if (score >= bestScore) return;
|
|
33548
|
+
best$1 = value;
|
|
33549
|
+
bestScore = score;
|
|
33550
|
+
},
|
|
33551
|
+
get: () => best$1,
|
|
33552
|
+
score: () => bestScore
|
|
33553
|
+
};
|
|
33554
|
+
}
|
|
33555
|
+
function alphabet(alphabet$1) {
|
|
33556
|
+
return Object.freeze({
|
|
33557
|
+
has: (char) => alphabet$1.includes(char),
|
|
33558
|
+
decode: (input) => {
|
|
33559
|
+
if (!Array.isArray(input) || input.length && typeof input[0] !== "string") throw new Error("alphabet.decode input should be array of strings");
|
|
33560
|
+
return input.map((letter) => {
|
|
33561
|
+
if (typeof letter !== "string") throw new Error(`alphabet.decode: not string element=${letter}`);
|
|
33562
|
+
const index = alphabet$1.indexOf(letter);
|
|
33563
|
+
if (index === -1) throw new Error(`Unknown letter: "${letter}". Allowed: ${alphabet$1}`);
|
|
33564
|
+
return index;
|
|
33565
|
+
});
|
|
33566
|
+
},
|
|
33567
|
+
encode: (digits) => {
|
|
33568
|
+
if (!Array.isArray(digits) || digits.length && typeof digits[0] !== "number") throw new Error("alphabet.encode input should be an array of numbers");
|
|
33569
|
+
return digits.map((i$1) => {
|
|
33570
|
+
assertNumber(i$1);
|
|
33571
|
+
if (i$1 < 0 || i$1 >= alphabet$1.length) throw new Error(`Digit index outside alphabet: ${i$1} (alphabet: ${alphabet$1.length})`);
|
|
33572
|
+
return alphabet$1[i$1];
|
|
33573
|
+
});
|
|
33574
|
+
}
|
|
33575
|
+
});
|
|
33576
|
+
}
|
|
33577
|
+
function transpose32(a) {
|
|
33578
|
+
if (a.length !== 32) throw new Error("expects 32 element matrix");
|
|
33579
|
+
const masks = [
|
|
33580
|
+
1431655765,
|
|
33581
|
+
858993459,
|
|
33582
|
+
252645135,
|
|
33583
|
+
16711935,
|
|
33584
|
+
65535
|
|
33585
|
+
];
|
|
33586
|
+
for (let stage = 0; stage < 5; stage++) {
|
|
33587
|
+
const m = masks[stage] >>> 0;
|
|
33588
|
+
const s = 1 << stage;
|
|
33589
|
+
const step = s << 1;
|
|
33590
|
+
for (let i$1 = 0; i$1 < 32; i$1 += step) for (let k = 0; k < s; k++) {
|
|
33591
|
+
const i0 = i$1 + k;
|
|
33592
|
+
const i1 = i0 + s;
|
|
33593
|
+
const x = a[i0] >>> 0;
|
|
33594
|
+
const y = a[i1] >>> 0;
|
|
33595
|
+
const t$5 = (x >>> s ^ y) & m;
|
|
33596
|
+
a[i0] = (x ^ t$5 << s) >>> 0;
|
|
33597
|
+
a[i1] = (y ^ t$5) >>> 0;
|
|
33598
|
+
}
|
|
33599
|
+
}
|
|
33600
|
+
}
|
|
33601
|
+
const bitMask = (x) => 1 << (x & 31) >>> 0;
|
|
33602
|
+
const rangeMask = (shift, len) => {
|
|
33603
|
+
if (len === 0) return 0;
|
|
33604
|
+
if (len === 32) return 4294967295;
|
|
33605
|
+
return (1 << len) - 1 << shift >>> 0;
|
|
33606
|
+
};
|
|
33607
|
+
/**
|
|
33608
|
+
* Mutable monochrome bitmap used as the internal QR representation.
|
|
33609
|
+
* @param size - Square edge length or explicit bitmap dimensions.
|
|
33610
|
+
* @param data - Optional row-major pixel matrix using `true`, `false`, or `undefined`.
|
|
33611
|
+
* @example
|
|
33612
|
+
* Create a bitmap, then scale it for display.
|
|
33613
|
+
* ```ts
|
|
33614
|
+
* import { Bitmap } from 'qr';
|
|
33615
|
+
* const bitmap = Bitmap.fromString('X \n X');
|
|
33616
|
+
* bitmap.scale(2);
|
|
33617
|
+
* ```
|
|
33618
|
+
*/
|
|
33619
|
+
var Bitmap = class Bitmap {
|
|
33620
|
+
static size(size, limit) {
|
|
33621
|
+
if (typeof size === "number") size = {
|
|
33622
|
+
height: size,
|
|
33623
|
+
width: size
|
|
33624
|
+
};
|
|
33625
|
+
if (!Number.isSafeInteger(size.height) && size.height !== Infinity) throw new Error(`Bitmap: invalid height=${size.height} (${typeof size.height})`);
|
|
33626
|
+
if (!Number.isSafeInteger(size.width) && size.width !== Infinity) throw new Error(`Bitmap: invalid width=${size.width} (${typeof size.width})`);
|
|
33627
|
+
if (limit !== void 0) size = {
|
|
33628
|
+
width: Math.min(size.width, limit.width),
|
|
33629
|
+
height: Math.min(size.height, limit.height)
|
|
33630
|
+
};
|
|
33631
|
+
return size;
|
|
33632
|
+
}
|
|
33633
|
+
static fromString(s) {
|
|
33634
|
+
s = s.replace(/^\n+/g, "").replace(/\n+$/g, "");
|
|
33635
|
+
const lines = s.split(String.fromCharCode(chCodes.newline));
|
|
33636
|
+
const height = lines.length;
|
|
33637
|
+
let width;
|
|
33638
|
+
const rows = [];
|
|
33639
|
+
for (const line of lines) {
|
|
33640
|
+
const row = line.split("").map((i$1) => {
|
|
33641
|
+
if (i$1 === "X") return true;
|
|
33642
|
+
if (i$1 === " ") return false;
|
|
33643
|
+
if (i$1 === "?") return void 0;
|
|
33644
|
+
throw new Error(`Bitmap.fromString: unknown symbol=${i$1}`);
|
|
33645
|
+
});
|
|
33646
|
+
if (width !== void 0 && row.length !== width) throw new Error(`Bitmap.fromString different row sizes: width=${width} cur=${row.length}`);
|
|
33647
|
+
width = row.length;
|
|
33648
|
+
rows.push(row);
|
|
33649
|
+
}
|
|
33650
|
+
if (width === void 0) width = 0;
|
|
33651
|
+
return new Bitmap({
|
|
33652
|
+
height,
|
|
33653
|
+
width
|
|
33654
|
+
}, rows);
|
|
33655
|
+
}
|
|
33656
|
+
defined;
|
|
33657
|
+
value;
|
|
33658
|
+
tailMask;
|
|
33659
|
+
words;
|
|
33660
|
+
fullWords;
|
|
33661
|
+
height;
|
|
33662
|
+
width;
|
|
33663
|
+
constructor(size, data$1) {
|
|
33664
|
+
const { height, width } = Bitmap.size(size);
|
|
33665
|
+
if (!Number.isSafeInteger(height) || height <= 0) throw new Error(`Bitmap: invalid height=${height}, expected positive safe integer dimension`);
|
|
33666
|
+
if (!Number.isSafeInteger(width) || width <= 0) throw new Error(`Bitmap: invalid width=${width}, expected positive safe integer dimension`);
|
|
33667
|
+
this.height = height;
|
|
33668
|
+
this.width = width;
|
|
33669
|
+
this.tailMask = rangeMask(0, width & 31 || 32);
|
|
33670
|
+
this.words = Math.ceil(width / 32) | 0;
|
|
33671
|
+
this.fullWords = Math.floor(width / 32) | 0;
|
|
33672
|
+
this.value = new Uint32Array(this.words * height);
|
|
33673
|
+
this.defined = new Uint32Array(this.value.length);
|
|
33674
|
+
if (data$1) {
|
|
33675
|
+
if (data$1.length !== height) throw new Error(`Bitmap: data height mismatch: exp=${height} got=${data$1.length}`);
|
|
33676
|
+
for (let y = 0; y < height; y++) {
|
|
33677
|
+
const row = data$1[y];
|
|
33678
|
+
if (!row || row.length !== width) throw new Error(`Bitmap: data width mismatch at y=${y}: exp=${width} got=${row?.length}`);
|
|
33679
|
+
for (let x = 0; x < width; x++) this.set(x, y, row[x]);
|
|
33680
|
+
}
|
|
33681
|
+
}
|
|
33682
|
+
}
|
|
33683
|
+
point(p$1) {
|
|
33684
|
+
return this.get(p$1.x, p$1.y);
|
|
33685
|
+
}
|
|
33686
|
+
isInside(p$1) {
|
|
33687
|
+
return 0 <= p$1.x && p$1.x < this.width && 0 <= p$1.y && p$1.y < this.height;
|
|
33688
|
+
}
|
|
33689
|
+
size(offset) {
|
|
33690
|
+
if (!offset) return {
|
|
33691
|
+
height: this.height,
|
|
33692
|
+
width: this.width
|
|
33693
|
+
};
|
|
33694
|
+
const { x, y } = this.xy(offset);
|
|
33695
|
+
return {
|
|
33696
|
+
height: this.height - y,
|
|
33697
|
+
width: this.width - x
|
|
33698
|
+
};
|
|
33699
|
+
}
|
|
33700
|
+
xy(c) {
|
|
33701
|
+
if (typeof c === "number") c = {
|
|
33702
|
+
x: c,
|
|
33703
|
+
y: c
|
|
33704
|
+
};
|
|
33705
|
+
if (!Number.isSafeInteger(c.x)) throw new Error(`Bitmap: invalid x=${c.x}`);
|
|
33706
|
+
if (!Number.isSafeInteger(c.y)) throw new Error(`Bitmap: invalid y=${c.y}`);
|
|
33707
|
+
c.x = mod(c.x, this.width);
|
|
33708
|
+
c.y = mod(c.y, this.height);
|
|
33709
|
+
return c;
|
|
33710
|
+
}
|
|
33711
|
+
/**
|
|
33712
|
+
* Return pixel bit index
|
|
33713
|
+
*/
|
|
33714
|
+
wordIndex(x, y) {
|
|
33715
|
+
return y * this.words + (x >>> 5);
|
|
33716
|
+
}
|
|
33717
|
+
bitIndex(x, y) {
|
|
33718
|
+
return {
|
|
33719
|
+
word: this.wordIndex(x, y),
|
|
33720
|
+
bit: x & 31
|
|
33721
|
+
};
|
|
33722
|
+
}
|
|
33723
|
+
isDefined(x, y) {
|
|
33724
|
+
const wi = this.wordIndex(x, y);
|
|
33725
|
+
const m = bitMask(x);
|
|
33726
|
+
return (this.defined[wi] & m) !== 0;
|
|
33727
|
+
}
|
|
33728
|
+
get(x, y) {
|
|
33729
|
+
const wi = this.wordIndex(x, y);
|
|
33730
|
+
const m = bitMask(x);
|
|
33731
|
+
return (this.value[wi] & m) !== 0;
|
|
33732
|
+
}
|
|
33733
|
+
maskWord(wi, mask, v) {
|
|
33734
|
+
const { defined, value } = this;
|
|
33735
|
+
defined[wi] |= mask;
|
|
33736
|
+
value[wi] = value[wi] & ~mask | -v & mask;
|
|
33737
|
+
}
|
|
33738
|
+
set(x, y, v) {
|
|
33739
|
+
if (v === void 0) return;
|
|
33740
|
+
this.maskWord(this.wordIndex(x, y), bitMask(x), v);
|
|
33741
|
+
}
|
|
33742
|
+
fillRectConst(x0, y0, w, h, v) {
|
|
33743
|
+
if (w <= 0 || h <= 0) return;
|
|
33744
|
+
if (v === void 0) return;
|
|
33745
|
+
const { value, defined, words } = this;
|
|
33746
|
+
const startWord = x0 >>> 5;
|
|
33747
|
+
const endWord = x0 + w - 1 >>> 5;
|
|
33748
|
+
const startBit = x0 & 31;
|
|
33749
|
+
const endBit = x0 + w - 1 & 31;
|
|
33750
|
+
for (let ry = 0; ry < h; ry++) {
|
|
33751
|
+
const rowBase = (y0 + ry) * words;
|
|
33752
|
+
if (startWord === endWord) {
|
|
33753
|
+
const mask = rangeMask(startBit, endBit - startBit + 1);
|
|
33754
|
+
this.maskWord(rowBase + startWord, mask, v);
|
|
33755
|
+
continue;
|
|
33756
|
+
}
|
|
33757
|
+
this.maskWord(rowBase + startWord, rangeMask(startBit, 32 - startBit), v);
|
|
33758
|
+
for (let i$1 = startWord + 1; i$1 < endWord; i$1++) {
|
|
33759
|
+
defined[rowBase + i$1] = 4294967295;
|
|
33760
|
+
value[rowBase + i$1] = v ? 4294967295 : 0;
|
|
33761
|
+
}
|
|
33762
|
+
this.maskWord(rowBase + endWord, rangeMask(0, endBit + 1), v);
|
|
33763
|
+
}
|
|
33764
|
+
}
|
|
33765
|
+
rectWords(x, y, width, height, cb) {
|
|
33766
|
+
for (let yPos = 0; yPos < height; yPos++) {
|
|
33767
|
+
const Py = y + yPos;
|
|
33768
|
+
for (let xPos = 0; xPos < width;) {
|
|
33769
|
+
const bitX = x + xPos;
|
|
33770
|
+
const { bit, word } = this.bitIndex(bitX, Py);
|
|
33771
|
+
const bitsPerWord = Math.min(32 - bit, width - xPos);
|
|
33772
|
+
cb(word, bitX, xPos, yPos, bitsPerWord);
|
|
33773
|
+
xPos += bitsPerWord;
|
|
33774
|
+
}
|
|
33775
|
+
}
|
|
33776
|
+
}
|
|
33777
|
+
rect(c, size, fn) {
|
|
33778
|
+
const { x, y } = this.xy(c);
|
|
33779
|
+
const { height, width } = Bitmap.size(size, this.size({
|
|
33780
|
+
x,
|
|
33781
|
+
y
|
|
33782
|
+
}));
|
|
33783
|
+
if (typeof fn !== "function") {
|
|
33784
|
+
this.fillRectConst(x, y, width, height, fn);
|
|
33785
|
+
return this;
|
|
33786
|
+
}
|
|
33787
|
+
const { defined, value } = this;
|
|
33788
|
+
this.rectWords(x, y, width, height, (wi, bitX, xPos, yPos, n$1) => {
|
|
33789
|
+
let defWord = 0;
|
|
33790
|
+
let valWord = value[wi];
|
|
33791
|
+
for (let b = 0; b < n$1; b++) {
|
|
33792
|
+
const mask = bitMask(bitX + b);
|
|
33793
|
+
const res = fn({
|
|
33794
|
+
x: xPos + b,
|
|
33795
|
+
y: yPos
|
|
33796
|
+
}, (valWord & mask) !== 0);
|
|
33797
|
+
if (res === void 0) continue;
|
|
33798
|
+
defWord |= mask;
|
|
33799
|
+
valWord = valWord & ~mask | -res & mask;
|
|
33800
|
+
}
|
|
33801
|
+
defined[wi] |= defWord;
|
|
33802
|
+
value[wi] = valWord;
|
|
33803
|
+
});
|
|
33804
|
+
return this;
|
|
33805
|
+
}
|
|
33806
|
+
rectRead(c, size, fn) {
|
|
33807
|
+
const { x, y } = this.xy(c);
|
|
33808
|
+
const { height, width } = Bitmap.size(size, this.size({
|
|
33809
|
+
x,
|
|
33810
|
+
y
|
|
33811
|
+
}));
|
|
33812
|
+
const { value } = this;
|
|
33813
|
+
this.rectWords(x, y, width, height, (wi, bitX, xPos, yPos, n$1) => {
|
|
33814
|
+
const valWord = value[wi];
|
|
33815
|
+
for (let b = 0; b < n$1; b++) {
|
|
33816
|
+
const mask = bitMask(bitX + b);
|
|
33817
|
+
fn({
|
|
33818
|
+
x: xPos + b,
|
|
33819
|
+
y: yPos
|
|
33820
|
+
}, (valWord & mask) !== 0);
|
|
33821
|
+
}
|
|
33822
|
+
});
|
|
33823
|
+
return this;
|
|
33824
|
+
}
|
|
33825
|
+
hLine(c, len, value) {
|
|
33826
|
+
return this.rect(c, {
|
|
33827
|
+
width: len,
|
|
33828
|
+
height: 1
|
|
33829
|
+
}, value);
|
|
33830
|
+
}
|
|
33831
|
+
vLine(c, len, value) {
|
|
33832
|
+
return this.rect(c, {
|
|
33833
|
+
width: 1,
|
|
33834
|
+
height: len
|
|
33835
|
+
}, value);
|
|
33836
|
+
}
|
|
33837
|
+
border(border = 2, value) {
|
|
33838
|
+
if (!Number.isSafeInteger(border) || border <= 0) throw new Error(`Bitmap.border: invalid size=${border}`);
|
|
33839
|
+
const out = new Bitmap({
|
|
33840
|
+
height: this.height + 2 * border,
|
|
33841
|
+
width: this.width + 2 * border
|
|
33842
|
+
});
|
|
33843
|
+
out.rect(0, Infinity, value);
|
|
33844
|
+
out.embed({
|
|
33845
|
+
x: border,
|
|
33846
|
+
y: border
|
|
33847
|
+
}, this);
|
|
33848
|
+
return out;
|
|
33849
|
+
}
|
|
33850
|
+
embed(c, src$1) {
|
|
33851
|
+
const { x, y } = this.xy(c);
|
|
33852
|
+
const { height, width } = Bitmap.size(src$1.size(), this.size({
|
|
33853
|
+
x,
|
|
33854
|
+
y
|
|
33855
|
+
}));
|
|
33856
|
+
if (width <= 0 || height <= 0) return this;
|
|
33857
|
+
const { value, defined } = this;
|
|
33858
|
+
const { words: srcStride, value: srcValue } = src$1;
|
|
33859
|
+
for (let yPos = 0; yPos < height; yPos++) {
|
|
33860
|
+
const srcRow = yPos * srcStride;
|
|
33861
|
+
for (let xPos = 0; xPos < width;) {
|
|
33862
|
+
const dstX = x + xPos;
|
|
33863
|
+
const { word: dstWord, bit: dstBit } = this.bitIndex(dstX, y + yPos);
|
|
33864
|
+
const { word: srcWord, bit: srcBit } = src$1.bitIndex(xPos, yPos);
|
|
33865
|
+
const len = Math.min(32 - dstBit, width - xPos);
|
|
33866
|
+
const w0 = srcValue[srcWord];
|
|
33867
|
+
const w1 = srcBit && srcWord + 1 < srcRow + srcStride ? srcValue[srcWord + 1] : 0;
|
|
33868
|
+
const sVal = srcBit ? (w0 >>> srcBit | w1 << 32 - srcBit) >>> 0 : w0;
|
|
33869
|
+
const dstMask = rangeMask(dstBit, len);
|
|
33870
|
+
const valBits = (sVal & rangeMask(0, len)) << dstBit >>> 0;
|
|
33871
|
+
defined[dstWord] |= dstMask;
|
|
33872
|
+
value[dstWord] = value[dstWord] & ~dstMask | valBits;
|
|
33873
|
+
xPos += len;
|
|
33874
|
+
}
|
|
33875
|
+
}
|
|
33876
|
+
return this;
|
|
33877
|
+
}
|
|
33878
|
+
rectSlice(c, size = this.size()) {
|
|
33879
|
+
const { x, y } = this.xy(c);
|
|
33880
|
+
const { height, width } = Bitmap.size(size, this.size({
|
|
33881
|
+
x,
|
|
33882
|
+
y
|
|
33883
|
+
}));
|
|
33884
|
+
const rect = new Bitmap({
|
|
33885
|
+
height,
|
|
33886
|
+
width
|
|
33887
|
+
});
|
|
33888
|
+
this.rectRead({
|
|
33889
|
+
x,
|
|
33890
|
+
y
|
|
33891
|
+
}, {
|
|
33892
|
+
height,
|
|
33893
|
+
width
|
|
33894
|
+
}, (p$1, cur) => {
|
|
33895
|
+
if (this.isDefined(x + p$1.x, y + p$1.y)) rect.set(p$1.x, p$1.y, cur);
|
|
33896
|
+
});
|
|
33897
|
+
return rect;
|
|
33898
|
+
}
|
|
33899
|
+
transpose() {
|
|
33900
|
+
const { height, width, value, defined, words } = this;
|
|
33901
|
+
const dst = new Bitmap({
|
|
33902
|
+
height: width,
|
|
33903
|
+
width: height
|
|
33904
|
+
});
|
|
33905
|
+
const { words: dstStride, value: dstValue, defined: dstDefined, tailMask: dstTail } = dst;
|
|
33906
|
+
const tmpV = new Uint32Array(32);
|
|
33907
|
+
const tmpD = new Uint32Array(32);
|
|
33908
|
+
for (let by = 0; by < height; by += 32) for (let bx = 0; bx < words; bx++) {
|
|
33909
|
+
const rows = Math.min(32, height - by);
|
|
33910
|
+
for (let r$1 = 0; r$1 < rows; r$1++) {
|
|
33911
|
+
const wi = this.wordIndex(32 * bx, by + r$1);
|
|
33912
|
+
tmpV[r$1] = value[wi];
|
|
33913
|
+
tmpD[r$1] = defined[wi];
|
|
33914
|
+
}
|
|
33915
|
+
tmpV.fill(0, rows);
|
|
33916
|
+
tmpD.fill(0, rows);
|
|
33917
|
+
transpose32(tmpV);
|
|
33918
|
+
transpose32(tmpD);
|
|
33919
|
+
for (let i$1 = 0; i$1 < 32; i$1++) {
|
|
33920
|
+
const dstY = bx * 32 + i$1;
|
|
33921
|
+
if (dstY >= width) break;
|
|
33922
|
+
const dstPos = dst.wordIndex(by, dstY);
|
|
33923
|
+
const curMask = by >>> 5 === dstStride - 1 ? dstTail : 4294967295;
|
|
33924
|
+
dstValue[dstPos] = tmpV[i$1] & curMask;
|
|
33925
|
+
dstDefined[dstPos] = tmpD[i$1] & curMask;
|
|
33926
|
+
}
|
|
33927
|
+
}
|
|
33928
|
+
return dst;
|
|
33929
|
+
}
|
|
33930
|
+
negate() {
|
|
33931
|
+
const n$1 = this.defined.length;
|
|
33932
|
+
for (let i$1 = 0; i$1 < n$1; i$1++) {
|
|
33933
|
+
this.value[i$1] = ~this.value[i$1];
|
|
33934
|
+
this.defined[i$1] = 4294967295;
|
|
33935
|
+
}
|
|
33936
|
+
return this;
|
|
33937
|
+
}
|
|
33938
|
+
scale(factor) {
|
|
33939
|
+
if (!Number.isSafeInteger(factor) || factor > 1024) throw new Error(`invalid scale factor: ${factor}`);
|
|
33940
|
+
const { height, width } = this;
|
|
33941
|
+
return new Bitmap({
|
|
33942
|
+
height: factor * height,
|
|
33943
|
+
width: factor * width
|
|
33944
|
+
}).rect({
|
|
33945
|
+
x: 0,
|
|
33946
|
+
y: 0
|
|
33947
|
+
}, Infinity, ({ x, y }) => this.get(x / factor | 0, y / factor | 0));
|
|
33948
|
+
}
|
|
33949
|
+
clone() {
|
|
33950
|
+
const res = new Bitmap(this.size());
|
|
33951
|
+
res.defined.set(this.defined);
|
|
33952
|
+
res.value.set(this.value);
|
|
33953
|
+
return res;
|
|
33954
|
+
}
|
|
33955
|
+
assertDrawn() {
|
|
33956
|
+
const { height, width, defined, tailMask, fullWords, words } = this;
|
|
33957
|
+
if (!height || !width) return;
|
|
33958
|
+
for (let y = 0; y < height; y++) {
|
|
33959
|
+
const rowBase = y * words;
|
|
33960
|
+
for (let wi = 0; wi < fullWords; wi++) if (defined[rowBase + wi] !== 4294967295) throw new Error(`Invalid color type=undefined`);
|
|
33961
|
+
if (words !== fullWords && (defined[rowBase + fullWords] & tailMask) !== tailMask) throw new Error(`Invalid color type=undefined`);
|
|
33962
|
+
}
|
|
33963
|
+
}
|
|
33964
|
+
countPatternInRow(y, patternLen, ...patterns) {
|
|
33965
|
+
if (!Number.isSafeInteger(patternLen) || patternLen <= 0 || patternLen >= 32) throw new Error("wrong patternLen");
|
|
33966
|
+
const mask = (1 << patternLen) - 1;
|
|
33967
|
+
const { height, width, value, words } = this;
|
|
33968
|
+
if (!Number.isSafeInteger(y) || y < 0 || y >= height) return 0;
|
|
33969
|
+
let count = 0;
|
|
33970
|
+
const rowBase = this.wordIndex(0, y);
|
|
33971
|
+
for (let i$1 = 0, window = 0; i$1 < words; i$1++) {
|
|
33972
|
+
const w = value[rowBase + i$1];
|
|
33973
|
+
const bitEnd = i$1 === words - 1 ? width & 31 || 32 : 32;
|
|
33974
|
+
for (let b = 0; b < bitEnd; b++) {
|
|
33975
|
+
window = (window << 1 | w >>> b & 1) & mask;
|
|
33976
|
+
if (i$1 * 32 + b + 1 < patternLen) continue;
|
|
33977
|
+
for (const p$1 of patterns) {
|
|
33978
|
+
if (window !== p$1) continue;
|
|
33979
|
+
count++;
|
|
33980
|
+
break;
|
|
33981
|
+
}
|
|
33982
|
+
}
|
|
33983
|
+
}
|
|
33984
|
+
return count;
|
|
33985
|
+
}
|
|
33986
|
+
getRuns(y, fn) {
|
|
33987
|
+
const { height, width, value, words } = this;
|
|
33988
|
+
if (width === 0) return;
|
|
33989
|
+
if (!Number.isSafeInteger(y) || y < 0 || y >= height) return;
|
|
33990
|
+
let runLen = 0;
|
|
33991
|
+
let runValue;
|
|
33992
|
+
const rowBase = this.wordIndex(0, y);
|
|
33993
|
+
for (let i$1 = 0; i$1 < words; i$1++) {
|
|
33994
|
+
const word = value[rowBase + i$1];
|
|
33995
|
+
const bitEnd = i$1 === words - 1 ? width & 31 || 32 : 32;
|
|
33996
|
+
for (let b = 0; b < bitEnd; b++) {
|
|
33997
|
+
const bit = (word & 1 << b) !== 0;
|
|
33998
|
+
if (bit === runValue) {
|
|
33999
|
+
runLen++;
|
|
34000
|
+
continue;
|
|
34001
|
+
}
|
|
34002
|
+
if (runValue !== void 0) fn(runLen, runValue);
|
|
34003
|
+
runValue = bit;
|
|
34004
|
+
runLen = 1;
|
|
34005
|
+
}
|
|
34006
|
+
}
|
|
34007
|
+
if (runValue !== void 0) fn(runLen, runValue);
|
|
34008
|
+
}
|
|
34009
|
+
popcnt() {
|
|
34010
|
+
const { height, width, words, fullWords, tailMask } = this;
|
|
34011
|
+
if (!height || !width) return 0;
|
|
34012
|
+
let count = 0;
|
|
34013
|
+
for (let y = 0; y < height; y++) {
|
|
34014
|
+
const rowBase = y * words;
|
|
34015
|
+
for (let wi = 0; wi < fullWords; wi++) count += popcnt(this.value[rowBase + wi]);
|
|
34016
|
+
if (words !== fullWords) count += popcnt(this.value[rowBase + fullWords] & tailMask);
|
|
34017
|
+
}
|
|
34018
|
+
return count;
|
|
34019
|
+
}
|
|
34020
|
+
countBoxes2x2(y) {
|
|
34021
|
+
const { height, width, words } = this;
|
|
34022
|
+
if (width < 2 || !Number.isSafeInteger(y) || y < 0 || y + 1 >= height) return 0;
|
|
34023
|
+
const base0 = this.wordIndex(0, y);
|
|
34024
|
+
const base1 = this.wordIndex(0, y + 1);
|
|
34025
|
+
const validLast = (width & 31) === 0 ? 2147483647 : rangeMask(0, width - 1 & 31);
|
|
34026
|
+
let boxes = 0;
|
|
34027
|
+
for (let wi = 0; wi < words; wi++) {
|
|
34028
|
+
const a0 = this.value[base0 + wi];
|
|
34029
|
+
const a1 = this.value[base1 + wi];
|
|
34030
|
+
const eqV = ~(a0 ^ a1) >>> 0;
|
|
34031
|
+
const n0 = wi + 1 < words ? this.value[base0 + wi + 1] >>> 0 : 0;
|
|
34032
|
+
const eqH0 = ~(a0 ^ (a0 >>> 1 | (n0 & 1) << 31) >>> 0) >>> 0;
|
|
34033
|
+
const n1 = wi + 1 < words ? this.value[base1 + wi + 1] >>> 0 : 0;
|
|
34034
|
+
const eqH1 = ~(a1 ^ (a1 >>> 1 | (n1 & 1) << 31) >>> 0) >>> 0;
|
|
34035
|
+
let m = (eqV & eqH0 & eqH1) >>> 0;
|
|
34036
|
+
if (wi === words - 1) m &= validLast;
|
|
34037
|
+
boxes += popcnt(m);
|
|
34038
|
+
}
|
|
34039
|
+
return boxes;
|
|
34040
|
+
}
|
|
34041
|
+
toString() {
|
|
34042
|
+
const nl = String.fromCharCode(chCodes.newline);
|
|
34043
|
+
let out = "";
|
|
34044
|
+
for (let y = 0; y < this.height; y++) {
|
|
34045
|
+
let line = "";
|
|
34046
|
+
for (let x = 0; x < this.width; x++) {
|
|
34047
|
+
const v = this.get(x, y);
|
|
34048
|
+
line += !this.isDefined(x, y) ? "?" : v ? "X" : " ";
|
|
34049
|
+
}
|
|
34050
|
+
out += line + (y + 1 === this.height ? "" : nl);
|
|
34051
|
+
}
|
|
34052
|
+
return out;
|
|
34053
|
+
}
|
|
34054
|
+
toRaw() {
|
|
34055
|
+
const out = Array.from({ length: this.height }, () => new Array(this.width));
|
|
34056
|
+
for (let y = 0; y < this.height; y++) {
|
|
34057
|
+
const row = out[y];
|
|
34058
|
+
for (let x = 0; x < this.width; x++) row[x] = this.get(x, y);
|
|
34059
|
+
}
|
|
34060
|
+
return out;
|
|
34061
|
+
}
|
|
34062
|
+
toASCII() {
|
|
34063
|
+
const { height, width } = this;
|
|
34064
|
+
let out = "";
|
|
34065
|
+
for (let y = 0; y < height; y += 2) {
|
|
34066
|
+
for (let x = 0; x < width; x++) {
|
|
34067
|
+
const first = this.get(x, y);
|
|
34068
|
+
const second = y + 1 >= height ? true : this.get(x, y + 1);
|
|
34069
|
+
if (!first && !second) out += "█";
|
|
34070
|
+
else if (!first && second) out += "▀";
|
|
34071
|
+
else if (first && !second) out += "▄";
|
|
34072
|
+
else if (first && second) out += " ";
|
|
34073
|
+
}
|
|
34074
|
+
out += String.fromCharCode(chCodes.newline);
|
|
34075
|
+
}
|
|
34076
|
+
return out;
|
|
34077
|
+
}
|
|
34078
|
+
toTerm() {
|
|
34079
|
+
const cc = String.fromCharCode(chCodes.reset);
|
|
34080
|
+
const reset = cc + "[0m";
|
|
34081
|
+
const whiteBG = cc + "[1;47m " + reset;
|
|
34082
|
+
const darkBG = cc + `[40m ` + reset;
|
|
34083
|
+
const nl = String.fromCharCode(chCodes.newline);
|
|
34084
|
+
let out = "";
|
|
34085
|
+
for (let y = 0; y < this.height; y++) {
|
|
34086
|
+
for (let x = 0; x < this.width; x++) {
|
|
34087
|
+
const v = this.get(x, y);
|
|
34088
|
+
out += v ? darkBG : whiteBG;
|
|
34089
|
+
}
|
|
34090
|
+
out += nl;
|
|
34091
|
+
}
|
|
34092
|
+
return out;
|
|
34093
|
+
}
|
|
34094
|
+
toSVG(optimize = true) {
|
|
34095
|
+
let out = `<svg viewBox="0 0 ${this.width} ${this.height}" xmlns="http://www.w3.org/2000/svg">`;
|
|
34096
|
+
let pathData = "";
|
|
34097
|
+
let prevPoint;
|
|
34098
|
+
this.rectRead(0, Infinity, (point, val) => {
|
|
34099
|
+
if (!val) return;
|
|
34100
|
+
const { x, y } = point;
|
|
34101
|
+
if (!optimize) {
|
|
34102
|
+
out += `<rect x="${x}" y="${y}" width="1" height="1" />`;
|
|
34103
|
+
return;
|
|
34104
|
+
}
|
|
34105
|
+
let m = `M${x} ${y}`;
|
|
34106
|
+
if (prevPoint) {
|
|
34107
|
+
const relM = `m${x - prevPoint.x} ${y - prevPoint.y}`;
|
|
34108
|
+
if (relM.length <= m.length) m = relM;
|
|
34109
|
+
}
|
|
34110
|
+
const bH = x < 10 ? `H${x}` : "h-1";
|
|
34111
|
+
pathData += `${m}h1v1${bH}Z`;
|
|
34112
|
+
prevPoint = point;
|
|
34113
|
+
});
|
|
34114
|
+
if (optimize) out += `<path d="${pathData}"/>`;
|
|
34115
|
+
out += `</svg>`;
|
|
34116
|
+
return out;
|
|
34117
|
+
}
|
|
34118
|
+
toGIF() {
|
|
34119
|
+
const u16le = (i$1) => [i$1 & 255, i$1 >>> 8 & 255];
|
|
34120
|
+
const dims = [...u16le(this.width), ...u16le(this.height)];
|
|
34121
|
+
const data$1 = [];
|
|
34122
|
+
this.rectRead(0, Infinity, (_, cur) => data$1.push(+(cur === true)));
|
|
34123
|
+
const N = 126;
|
|
34124
|
+
const bytes = [
|
|
34125
|
+
71,
|
|
34126
|
+
73,
|
|
34127
|
+
70,
|
|
34128
|
+
56,
|
|
34129
|
+
55,
|
|
34130
|
+
97,
|
|
34131
|
+
...dims,
|
|
34132
|
+
246,
|
|
34133
|
+
0,
|
|
34134
|
+
0,
|
|
34135
|
+
255,
|
|
34136
|
+
255,
|
|
34137
|
+
255,
|
|
34138
|
+
...fillArr(381, 0),
|
|
34139
|
+
44,
|
|
34140
|
+
0,
|
|
34141
|
+
0,
|
|
34142
|
+
0,
|
|
34143
|
+
0,
|
|
34144
|
+
...dims,
|
|
34145
|
+
0,
|
|
34146
|
+
7
|
|
34147
|
+
];
|
|
34148
|
+
const fullChunks = Math.floor(data$1.length / N);
|
|
34149
|
+
for (let i$1 = 0; i$1 < fullChunks; i$1++) bytes.push(N + 1, 128, ...data$1.slice(N * i$1, N * (i$1 + 1)).map((i$2) => +i$2));
|
|
34150
|
+
bytes.push(data$1.length % N + 1, 128, ...data$1.slice(fullChunks * N).map((i$1) => +i$1));
|
|
34151
|
+
bytes.push(1, 129, 0, 59);
|
|
34152
|
+
return new Uint8Array(bytes);
|
|
34153
|
+
}
|
|
34154
|
+
toImage(isRGB = false) {
|
|
34155
|
+
const { height, width } = this.size();
|
|
34156
|
+
const data$1 = new Uint8Array(height * width * (isRGB ? 3 : 4));
|
|
34157
|
+
let i$1 = 0;
|
|
34158
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
34159
|
+
const value = this.get(x, y) ? 0 : 255;
|
|
34160
|
+
data$1[i$1++] = value;
|
|
34161
|
+
data$1[i$1++] = value;
|
|
34162
|
+
data$1[i$1++] = value;
|
|
34163
|
+
if (!isRGB) data$1[i$1++] = 255;
|
|
34164
|
+
}
|
|
34165
|
+
return {
|
|
34166
|
+
height,
|
|
34167
|
+
width,
|
|
34168
|
+
data: data$1
|
|
34169
|
+
};
|
|
34170
|
+
}
|
|
34171
|
+
};
|
|
34172
|
+
/** Error correction mode. low: 7%, medium: 15%, quartile: 25%, high: 30%. */
|
|
34173
|
+
const ECMode = /* @__PURE__ */ Object.freeze([
|
|
34174
|
+
"low",
|
|
34175
|
+
"medium",
|
|
34176
|
+
"quartile",
|
|
34177
|
+
"high"
|
|
34178
|
+
]);
|
|
34179
|
+
/**
|
|
34180
|
+
* QR payload compaction mode names recognized by the type/validator.
|
|
34181
|
+
* `kanji` and `eci` are spec modes, but `encodeQR` currently rejects them until implemented.
|
|
34182
|
+
*/
|
|
34183
|
+
const Encoding = /* @__PURE__ */ Object.freeze([
|
|
34184
|
+
"numeric",
|
|
34185
|
+
"alphanumeric",
|
|
34186
|
+
"byte",
|
|
34187
|
+
"kanji",
|
|
34188
|
+
"eci"
|
|
34189
|
+
]);
|
|
34190
|
+
const BYTES = [
|
|
34191
|
+
26,
|
|
34192
|
+
44,
|
|
34193
|
+
70,
|
|
34194
|
+
100,
|
|
34195
|
+
134,
|
|
34196
|
+
172,
|
|
34197
|
+
196,
|
|
34198
|
+
242,
|
|
34199
|
+
292,
|
|
34200
|
+
346,
|
|
34201
|
+
404,
|
|
34202
|
+
466,
|
|
34203
|
+
532,
|
|
34204
|
+
581,
|
|
34205
|
+
655,
|
|
34206
|
+
733,
|
|
34207
|
+
815,
|
|
34208
|
+
901,
|
|
34209
|
+
991,
|
|
34210
|
+
1085,
|
|
34211
|
+
1156,
|
|
34212
|
+
1258,
|
|
34213
|
+
1364,
|
|
34214
|
+
1474,
|
|
34215
|
+
1588,
|
|
34216
|
+
1706,
|
|
34217
|
+
1828,
|
|
34218
|
+
1921,
|
|
34219
|
+
2051,
|
|
34220
|
+
2185,
|
|
34221
|
+
2323,
|
|
34222
|
+
2465,
|
|
34223
|
+
2611,
|
|
34224
|
+
2761,
|
|
34225
|
+
2876,
|
|
34226
|
+
3034,
|
|
34227
|
+
3196,
|
|
34228
|
+
3362,
|
|
34229
|
+
3532,
|
|
34230
|
+
3706
|
|
34231
|
+
];
|
|
34232
|
+
const WORDS_PER_BLOCK = {
|
|
34233
|
+
low: [
|
|
34234
|
+
7,
|
|
34235
|
+
10,
|
|
34236
|
+
15,
|
|
34237
|
+
20,
|
|
34238
|
+
26,
|
|
34239
|
+
18,
|
|
34240
|
+
20,
|
|
34241
|
+
24,
|
|
34242
|
+
30,
|
|
34243
|
+
18,
|
|
34244
|
+
20,
|
|
34245
|
+
24,
|
|
34246
|
+
26,
|
|
34247
|
+
30,
|
|
34248
|
+
22,
|
|
34249
|
+
24,
|
|
34250
|
+
28,
|
|
34251
|
+
30,
|
|
34252
|
+
28,
|
|
34253
|
+
28,
|
|
34254
|
+
28,
|
|
34255
|
+
28,
|
|
34256
|
+
30,
|
|
34257
|
+
30,
|
|
34258
|
+
26,
|
|
34259
|
+
28,
|
|
34260
|
+
30,
|
|
34261
|
+
30,
|
|
34262
|
+
30,
|
|
34263
|
+
30,
|
|
34264
|
+
30,
|
|
34265
|
+
30,
|
|
34266
|
+
30,
|
|
34267
|
+
30,
|
|
34268
|
+
30,
|
|
34269
|
+
30,
|
|
34270
|
+
30,
|
|
34271
|
+
30,
|
|
34272
|
+
30,
|
|
34273
|
+
30
|
|
34274
|
+
],
|
|
34275
|
+
medium: [
|
|
34276
|
+
10,
|
|
34277
|
+
16,
|
|
34278
|
+
26,
|
|
34279
|
+
18,
|
|
34280
|
+
24,
|
|
34281
|
+
16,
|
|
34282
|
+
18,
|
|
34283
|
+
22,
|
|
34284
|
+
22,
|
|
34285
|
+
26,
|
|
34286
|
+
30,
|
|
34287
|
+
22,
|
|
34288
|
+
22,
|
|
34289
|
+
24,
|
|
34290
|
+
24,
|
|
34291
|
+
28,
|
|
34292
|
+
28,
|
|
34293
|
+
26,
|
|
34294
|
+
26,
|
|
34295
|
+
26,
|
|
34296
|
+
26,
|
|
34297
|
+
28,
|
|
34298
|
+
28,
|
|
34299
|
+
28,
|
|
34300
|
+
28,
|
|
34301
|
+
28,
|
|
34302
|
+
28,
|
|
34303
|
+
28,
|
|
34304
|
+
28,
|
|
34305
|
+
28,
|
|
34306
|
+
28,
|
|
34307
|
+
28,
|
|
34308
|
+
28,
|
|
34309
|
+
28,
|
|
34310
|
+
28,
|
|
34311
|
+
28,
|
|
34312
|
+
28,
|
|
34313
|
+
28,
|
|
34314
|
+
28,
|
|
34315
|
+
28
|
|
34316
|
+
],
|
|
34317
|
+
quartile: [
|
|
34318
|
+
13,
|
|
34319
|
+
22,
|
|
34320
|
+
18,
|
|
34321
|
+
26,
|
|
34322
|
+
18,
|
|
34323
|
+
24,
|
|
34324
|
+
18,
|
|
34325
|
+
22,
|
|
34326
|
+
20,
|
|
34327
|
+
24,
|
|
34328
|
+
28,
|
|
34329
|
+
26,
|
|
34330
|
+
24,
|
|
34331
|
+
20,
|
|
34332
|
+
30,
|
|
34333
|
+
24,
|
|
34334
|
+
28,
|
|
34335
|
+
28,
|
|
34336
|
+
26,
|
|
34337
|
+
30,
|
|
34338
|
+
28,
|
|
34339
|
+
30,
|
|
34340
|
+
30,
|
|
34341
|
+
30,
|
|
34342
|
+
30,
|
|
34343
|
+
28,
|
|
34344
|
+
30,
|
|
34345
|
+
30,
|
|
34346
|
+
30,
|
|
34347
|
+
30,
|
|
34348
|
+
30,
|
|
34349
|
+
30,
|
|
34350
|
+
30,
|
|
34351
|
+
30,
|
|
34352
|
+
30,
|
|
34353
|
+
30,
|
|
34354
|
+
30,
|
|
34355
|
+
30,
|
|
34356
|
+
30,
|
|
34357
|
+
30
|
|
34358
|
+
],
|
|
34359
|
+
high: [
|
|
34360
|
+
17,
|
|
34361
|
+
28,
|
|
34362
|
+
22,
|
|
34363
|
+
16,
|
|
34364
|
+
22,
|
|
34365
|
+
28,
|
|
34366
|
+
26,
|
|
34367
|
+
26,
|
|
34368
|
+
24,
|
|
34369
|
+
28,
|
|
34370
|
+
24,
|
|
34371
|
+
28,
|
|
34372
|
+
22,
|
|
34373
|
+
24,
|
|
34374
|
+
24,
|
|
34375
|
+
30,
|
|
34376
|
+
28,
|
|
34377
|
+
28,
|
|
34378
|
+
26,
|
|
34379
|
+
28,
|
|
34380
|
+
30,
|
|
34381
|
+
24,
|
|
34382
|
+
30,
|
|
34383
|
+
30,
|
|
34384
|
+
30,
|
|
34385
|
+
30,
|
|
34386
|
+
30,
|
|
34387
|
+
30,
|
|
34388
|
+
30,
|
|
34389
|
+
30,
|
|
34390
|
+
30,
|
|
34391
|
+
30,
|
|
34392
|
+
30,
|
|
34393
|
+
30,
|
|
34394
|
+
30,
|
|
34395
|
+
30,
|
|
34396
|
+
30,
|
|
34397
|
+
30,
|
|
34398
|
+
30,
|
|
34399
|
+
30
|
|
34400
|
+
]
|
|
34401
|
+
};
|
|
34402
|
+
const ECC_BLOCKS = {
|
|
34403
|
+
low: [
|
|
34404
|
+
1,
|
|
34405
|
+
1,
|
|
34406
|
+
1,
|
|
34407
|
+
1,
|
|
34408
|
+
1,
|
|
34409
|
+
2,
|
|
34410
|
+
2,
|
|
34411
|
+
2,
|
|
34412
|
+
2,
|
|
34413
|
+
4,
|
|
34414
|
+
4,
|
|
34415
|
+
4,
|
|
34416
|
+
4,
|
|
34417
|
+
4,
|
|
34418
|
+
6,
|
|
34419
|
+
6,
|
|
34420
|
+
6,
|
|
34421
|
+
6,
|
|
34422
|
+
7,
|
|
34423
|
+
8,
|
|
34424
|
+
8,
|
|
34425
|
+
9,
|
|
34426
|
+
9,
|
|
34427
|
+
10,
|
|
34428
|
+
12,
|
|
34429
|
+
12,
|
|
34430
|
+
12,
|
|
34431
|
+
13,
|
|
34432
|
+
14,
|
|
34433
|
+
15,
|
|
34434
|
+
16,
|
|
34435
|
+
17,
|
|
34436
|
+
18,
|
|
34437
|
+
19,
|
|
34438
|
+
19,
|
|
34439
|
+
20,
|
|
34440
|
+
21,
|
|
34441
|
+
22,
|
|
34442
|
+
24,
|
|
34443
|
+
25
|
|
34444
|
+
],
|
|
34445
|
+
medium: [
|
|
34446
|
+
1,
|
|
34447
|
+
1,
|
|
34448
|
+
1,
|
|
34449
|
+
2,
|
|
34450
|
+
2,
|
|
34451
|
+
4,
|
|
34452
|
+
4,
|
|
34453
|
+
4,
|
|
34454
|
+
5,
|
|
34455
|
+
5,
|
|
34456
|
+
5,
|
|
34457
|
+
8,
|
|
34458
|
+
9,
|
|
34459
|
+
9,
|
|
34460
|
+
10,
|
|
34461
|
+
10,
|
|
34462
|
+
11,
|
|
34463
|
+
13,
|
|
34464
|
+
14,
|
|
34465
|
+
16,
|
|
34466
|
+
17,
|
|
34467
|
+
17,
|
|
34468
|
+
18,
|
|
34469
|
+
20,
|
|
34470
|
+
21,
|
|
34471
|
+
23,
|
|
34472
|
+
25,
|
|
34473
|
+
26,
|
|
34474
|
+
28,
|
|
34475
|
+
29,
|
|
34476
|
+
31,
|
|
34477
|
+
33,
|
|
34478
|
+
35,
|
|
34479
|
+
37,
|
|
34480
|
+
38,
|
|
34481
|
+
40,
|
|
34482
|
+
43,
|
|
34483
|
+
45,
|
|
34484
|
+
47,
|
|
34485
|
+
49
|
|
34486
|
+
],
|
|
34487
|
+
quartile: [
|
|
34488
|
+
1,
|
|
34489
|
+
1,
|
|
34490
|
+
2,
|
|
34491
|
+
2,
|
|
34492
|
+
4,
|
|
34493
|
+
4,
|
|
34494
|
+
6,
|
|
34495
|
+
6,
|
|
34496
|
+
8,
|
|
34497
|
+
8,
|
|
34498
|
+
8,
|
|
34499
|
+
10,
|
|
34500
|
+
12,
|
|
34501
|
+
16,
|
|
34502
|
+
12,
|
|
34503
|
+
17,
|
|
34504
|
+
16,
|
|
34505
|
+
18,
|
|
34506
|
+
21,
|
|
34507
|
+
20,
|
|
34508
|
+
23,
|
|
34509
|
+
23,
|
|
34510
|
+
25,
|
|
34511
|
+
27,
|
|
34512
|
+
29,
|
|
34513
|
+
34,
|
|
34514
|
+
34,
|
|
34515
|
+
35,
|
|
34516
|
+
38,
|
|
34517
|
+
40,
|
|
34518
|
+
43,
|
|
34519
|
+
45,
|
|
34520
|
+
48,
|
|
34521
|
+
51,
|
|
34522
|
+
53,
|
|
34523
|
+
56,
|
|
34524
|
+
59,
|
|
34525
|
+
62,
|
|
34526
|
+
65,
|
|
34527
|
+
68
|
|
34528
|
+
],
|
|
34529
|
+
high: [
|
|
34530
|
+
1,
|
|
34531
|
+
1,
|
|
34532
|
+
2,
|
|
34533
|
+
4,
|
|
34534
|
+
4,
|
|
34535
|
+
4,
|
|
34536
|
+
5,
|
|
34537
|
+
6,
|
|
34538
|
+
8,
|
|
34539
|
+
8,
|
|
34540
|
+
11,
|
|
34541
|
+
11,
|
|
34542
|
+
16,
|
|
34543
|
+
16,
|
|
34544
|
+
18,
|
|
34545
|
+
16,
|
|
34546
|
+
19,
|
|
34547
|
+
21,
|
|
34548
|
+
25,
|
|
34549
|
+
25,
|
|
34550
|
+
25,
|
|
34551
|
+
34,
|
|
34552
|
+
30,
|
|
34553
|
+
32,
|
|
34554
|
+
35,
|
|
34555
|
+
37,
|
|
34556
|
+
40,
|
|
34557
|
+
42,
|
|
34558
|
+
45,
|
|
34559
|
+
48,
|
|
34560
|
+
51,
|
|
34561
|
+
54,
|
|
34562
|
+
57,
|
|
34563
|
+
60,
|
|
34564
|
+
63,
|
|
34565
|
+
66,
|
|
34566
|
+
70,
|
|
34567
|
+
74,
|
|
34568
|
+
77,
|
|
34569
|
+
81
|
|
34570
|
+
]
|
|
34571
|
+
};
|
|
34572
|
+
const info = /* @__PURE__ */ Object.freeze({
|
|
34573
|
+
size: /* @__PURE__ */ Object.freeze({
|
|
34574
|
+
encode: (ver) => 21 + 4 * (ver - 1),
|
|
34575
|
+
decode: (size) => (size - 17) / 4
|
|
34576
|
+
}),
|
|
34577
|
+
sizeType: (ver) => Math.floor((ver + 7) / 17),
|
|
34578
|
+
alignmentPatterns(ver) {
|
|
34579
|
+
if (ver === 1) return [];
|
|
34580
|
+
const first = 6;
|
|
34581
|
+
const last = info.size.encode(ver) - first - 1;
|
|
34582
|
+
const distance = last - first;
|
|
34583
|
+
const count = Math.ceil(distance / 28);
|
|
34584
|
+
let interval = Math.floor(distance / count);
|
|
34585
|
+
if (interval % 2) interval += 1;
|
|
34586
|
+
else if (distance % count * 2 >= count) interval += 2;
|
|
34587
|
+
const res = [first];
|
|
34588
|
+
for (let m = 1; m < count; m++) res.push(last - (count - m) * interval);
|
|
34589
|
+
res.push(last);
|
|
34590
|
+
return res;
|
|
34591
|
+
},
|
|
34592
|
+
ECCode: /* @__PURE__ */ Object.freeze({
|
|
34593
|
+
low: 1,
|
|
34594
|
+
medium: 0,
|
|
34595
|
+
quartile: 3,
|
|
34596
|
+
high: 2
|
|
34597
|
+
}),
|
|
34598
|
+
formatMask: 21522,
|
|
34599
|
+
formatBits(ecc, maskIdx) {
|
|
34600
|
+
const data$1 = info.ECCode[ecc] << 3 | maskIdx;
|
|
34601
|
+
let d = data$1;
|
|
34602
|
+
for (let i$1 = 0; i$1 < 10; i$1++) d = d << 1 ^ (d >> 9) * 1335;
|
|
34603
|
+
return (data$1 << 10 | d) ^ info.formatMask;
|
|
34604
|
+
},
|
|
34605
|
+
versionBits(ver) {
|
|
34606
|
+
let d = ver;
|
|
34607
|
+
for (let i$1 = 0; i$1 < 12; i$1++) d = d << 1 ^ (d >> 11) * 7973;
|
|
34608
|
+
return ver << 12 | d;
|
|
34609
|
+
},
|
|
34610
|
+
alphabet: /* @__PURE__ */ Object.freeze({
|
|
34611
|
+
numeric: alphabet("0123456789"),
|
|
34612
|
+
alphanumerc: alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:")
|
|
34613
|
+
}),
|
|
34614
|
+
lengthBits(ver, type) {
|
|
34615
|
+
return {
|
|
34616
|
+
numeric: [
|
|
34617
|
+
10,
|
|
34618
|
+
12,
|
|
34619
|
+
14
|
|
34620
|
+
],
|
|
34621
|
+
alphanumeric: [
|
|
34622
|
+
9,
|
|
34623
|
+
11,
|
|
34624
|
+
13
|
|
34625
|
+
],
|
|
34626
|
+
byte: [
|
|
34627
|
+
8,
|
|
34628
|
+
16,
|
|
34629
|
+
16
|
|
34630
|
+
],
|
|
34631
|
+
kanji: [
|
|
34632
|
+
8,
|
|
34633
|
+
10,
|
|
34634
|
+
12
|
|
34635
|
+
],
|
|
34636
|
+
eci: [
|
|
34637
|
+
0,
|
|
34638
|
+
0,
|
|
34639
|
+
0
|
|
34640
|
+
]
|
|
34641
|
+
}[type][info.sizeType(ver)];
|
|
34642
|
+
},
|
|
34643
|
+
modeBits: /* @__PURE__ */ Object.freeze({
|
|
34644
|
+
numeric: "0001",
|
|
34645
|
+
alphanumeric: "0010",
|
|
34646
|
+
byte: "0100",
|
|
34647
|
+
kanji: "1000",
|
|
34648
|
+
eci: "0111"
|
|
34649
|
+
}),
|
|
34650
|
+
capacity(ver, ecc) {
|
|
34651
|
+
const bytes = BYTES[ver - 1];
|
|
34652
|
+
const words = WORDS_PER_BLOCK[ecc][ver - 1];
|
|
34653
|
+
const numBlocks = ECC_BLOCKS[ecc][ver - 1];
|
|
34654
|
+
const blockLen = Math.floor(bytes / numBlocks) - words;
|
|
34655
|
+
const shortBlocks = numBlocks - bytes % numBlocks;
|
|
34656
|
+
return {
|
|
34657
|
+
words,
|
|
34658
|
+
numBlocks,
|
|
34659
|
+
shortBlocks,
|
|
34660
|
+
blockLen,
|
|
34661
|
+
capacity: (bytes - words * numBlocks) * 8,
|
|
34662
|
+
total: (words + blockLen) * numBlocks + numBlocks - shortBlocks
|
|
34663
|
+
};
|
|
34664
|
+
}
|
|
34665
|
+
});
|
|
34666
|
+
const PATTERNS = /* @__PURE__ */ Object.freeze([
|
|
34667
|
+
(x, y) => (x + y) % 2 == 0,
|
|
34668
|
+
(_x, y) => y % 2 == 0,
|
|
34669
|
+
(x, _y) => x % 3 == 0,
|
|
34670
|
+
(x, y) => (x + y) % 3 == 0,
|
|
34671
|
+
(x, y) => (Math.floor(y / 2) + Math.floor(x / 3)) % 2 == 0,
|
|
34672
|
+
(x, y) => x * y % 2 + x * y % 3 == 0,
|
|
34673
|
+
(x, y) => (x * y % 2 + x * y % 3) % 2 == 0,
|
|
34674
|
+
(x, y) => ((x + y) % 2 + x * y % 3) % 2 == 0
|
|
34675
|
+
]);
|
|
34676
|
+
const GF = {
|
|
34677
|
+
tables: ((p_poly) => {
|
|
34678
|
+
const exp = fillArr(256, 0);
|
|
34679
|
+
const log$1 = fillArr(256, 0);
|
|
34680
|
+
for (let i$1 = 0, x = 1; i$1 < 256; i$1++) {
|
|
34681
|
+
exp[i$1] = x;
|
|
34682
|
+
log$1[x] = i$1;
|
|
34683
|
+
x <<= 1;
|
|
34684
|
+
if (x & 256) x ^= p_poly;
|
|
34685
|
+
}
|
|
34686
|
+
return {
|
|
34687
|
+
exp,
|
|
34688
|
+
log: log$1
|
|
34689
|
+
};
|
|
34690
|
+
})(285),
|
|
34691
|
+
exp: (x) => GF.tables.exp[x],
|
|
34692
|
+
log(x) {
|
|
34693
|
+
if (x === 0) throw new Error(`GF.log: invalid arg=${x}`);
|
|
34694
|
+
return GF.tables.log[x] % 255;
|
|
34695
|
+
},
|
|
34696
|
+
mul(x, y) {
|
|
34697
|
+
if (x === 0 || y === 0) return 0;
|
|
34698
|
+
return GF.tables.exp[(GF.tables.log[x] + GF.tables.log[y]) % 255];
|
|
34699
|
+
},
|
|
34700
|
+
add: (x, y) => x ^ y,
|
|
34701
|
+
pow: (x, e) => GF.tables.exp[GF.tables.log[x] * e % 255],
|
|
34702
|
+
inv(x) {
|
|
34703
|
+
if (x === 0) throw new Error(`GF.inverse: invalid arg=${x}`);
|
|
34704
|
+
return GF.tables.exp[255 - GF.tables.log[x]];
|
|
34705
|
+
},
|
|
34706
|
+
polynomial(poly) {
|
|
34707
|
+
if (poly.length == 0) throw new Error("GF.polymomial: invalid length");
|
|
34708
|
+
if (poly[0] !== 0) return poly;
|
|
34709
|
+
let i$1 = 0;
|
|
34710
|
+
for (; i$1 < poly.length - 1 && poly[i$1] == 0; i$1++);
|
|
34711
|
+
return poly.slice(i$1);
|
|
34712
|
+
},
|
|
34713
|
+
monomial(degree, coefficient) {
|
|
34714
|
+
if (degree < 0) throw new Error(`GF.monomial: invalid degree=${degree}`);
|
|
34715
|
+
if (coefficient == 0) return [0];
|
|
34716
|
+
let coefficients = fillArr(degree + 1, 0);
|
|
34717
|
+
coefficients[0] = coefficient;
|
|
34718
|
+
return GF.polynomial(coefficients);
|
|
34719
|
+
},
|
|
34720
|
+
degree: (a) => a.length - 1,
|
|
34721
|
+
coefficient: (a, degree) => a[GF.degree(a) - degree],
|
|
34722
|
+
mulPoly(a, b) {
|
|
34723
|
+
if (a[0] === 0 || b[0] === 0) return [0];
|
|
34724
|
+
const res = fillArr(a.length + b.length - 1, 0);
|
|
34725
|
+
for (let i$1 = 0; i$1 < a.length; i$1++) for (let j = 0; j < b.length; j++) res[i$1 + j] = GF.add(res[i$1 + j], GF.mul(a[i$1], b[j]));
|
|
34726
|
+
return GF.polynomial(res);
|
|
34727
|
+
},
|
|
34728
|
+
mulPolyScalar(a, scalar) {
|
|
34729
|
+
if (scalar == 0) return [0];
|
|
34730
|
+
if (scalar == 1) return a;
|
|
34731
|
+
const res = fillArr(a.length, 0);
|
|
34732
|
+
for (let i$1 = 0; i$1 < a.length; i$1++) res[i$1] = GF.mul(a[i$1], scalar);
|
|
34733
|
+
return GF.polynomial(res);
|
|
34734
|
+
},
|
|
34735
|
+
mulPolyMonomial(a, degree, coefficient) {
|
|
34736
|
+
if (degree < 0) throw new Error("GF.mulPolyMonomial: invalid degree");
|
|
34737
|
+
if (coefficient == 0) return [0];
|
|
34738
|
+
const res = fillArr(a.length + degree, 0);
|
|
34739
|
+
for (let i$1 = 0; i$1 < a.length; i$1++) res[i$1] = GF.mul(a[i$1], coefficient);
|
|
34740
|
+
return GF.polynomial(res);
|
|
34741
|
+
},
|
|
34742
|
+
addPoly(a, b) {
|
|
34743
|
+
if (a[0] === 0) return b;
|
|
34744
|
+
if (b[0] === 0) return a;
|
|
34745
|
+
let smaller = a;
|
|
34746
|
+
let larger = b;
|
|
34747
|
+
if (smaller.length > larger.length) [smaller, larger] = [larger, smaller];
|
|
34748
|
+
let sumDiff = fillArr(larger.length, 0);
|
|
34749
|
+
let lengthDiff = larger.length - smaller.length;
|
|
34750
|
+
let s = larger.slice(0, lengthDiff);
|
|
34751
|
+
for (let i$1 = 0; i$1 < s.length; i$1++) sumDiff[i$1] = s[i$1];
|
|
34752
|
+
for (let i$1 = lengthDiff; i$1 < larger.length; i$1++) sumDiff[i$1] = GF.add(smaller[i$1 - lengthDiff], larger[i$1]);
|
|
34753
|
+
return GF.polynomial(sumDiff);
|
|
34754
|
+
},
|
|
34755
|
+
remainderPoly(data$1, divisor) {
|
|
34756
|
+
const out = Array.from(data$1);
|
|
34757
|
+
for (let i$1 = 0; i$1 < data$1.length - divisor.length + 1; i$1++) {
|
|
34758
|
+
const elm = out[i$1];
|
|
34759
|
+
if (elm === 0) continue;
|
|
34760
|
+
for (let j = 1; j < divisor.length; j++) if (divisor[j] !== 0) out[i$1 + j] = GF.add(out[i$1 + j], GF.mul(divisor[j], elm));
|
|
34761
|
+
}
|
|
34762
|
+
return out.slice(data$1.length - divisor.length + 1, out.length);
|
|
34763
|
+
},
|
|
34764
|
+
divisorPoly(degree) {
|
|
34765
|
+
let g = [1];
|
|
34766
|
+
for (let i$1 = 0; i$1 < degree; i$1++) g = GF.mulPoly(g, [1, GF.pow(2, i$1)]);
|
|
34767
|
+
return g;
|
|
34768
|
+
},
|
|
34769
|
+
evalPoly(poly, a) {
|
|
34770
|
+
if (a == 0) return GF.coefficient(poly, 0);
|
|
34771
|
+
let res = poly[0];
|
|
34772
|
+
for (let i$1 = 1; i$1 < poly.length; i$1++) res = GF.add(GF.mul(a, res), poly[i$1]);
|
|
34773
|
+
return res;
|
|
34774
|
+
},
|
|
34775
|
+
euclidian(a, b, R$1) {
|
|
34776
|
+
if (GF.degree(a) < GF.degree(b)) [a, b] = [b, a];
|
|
34777
|
+
let rLast = a;
|
|
34778
|
+
let r$1 = b;
|
|
34779
|
+
let tLast = [0];
|
|
34780
|
+
let t$5 = [1];
|
|
34781
|
+
while (2 * GF.degree(r$1) >= R$1) {
|
|
34782
|
+
let rLastLast = rLast;
|
|
34783
|
+
let tLastLast = tLast;
|
|
34784
|
+
rLast = r$1;
|
|
34785
|
+
tLast = t$5;
|
|
34786
|
+
if (rLast[0] === 0) throw new Error("rLast[0] === 0");
|
|
34787
|
+
r$1 = rLastLast;
|
|
34788
|
+
let q = [0];
|
|
34789
|
+
const dltInverse = GF.inv(rLast[0]);
|
|
34790
|
+
while (GF.degree(r$1) >= GF.degree(rLast) && r$1[0] !== 0) {
|
|
34791
|
+
const degreeDiff = GF.degree(r$1) - GF.degree(rLast);
|
|
34792
|
+
const scale = GF.mul(r$1[0], dltInverse);
|
|
34793
|
+
q = GF.addPoly(q, GF.monomial(degreeDiff, scale));
|
|
34794
|
+
r$1 = GF.addPoly(r$1, GF.mulPolyMonomial(rLast, degreeDiff, scale));
|
|
34795
|
+
}
|
|
34796
|
+
q = GF.mulPoly(q, tLast);
|
|
34797
|
+
t$5 = GF.addPoly(q, tLastLast);
|
|
34798
|
+
if (GF.degree(r$1) >= GF.degree(rLast)) throw new Error(`Division failed r: ${r$1}, rLast: ${rLast}`);
|
|
34799
|
+
}
|
|
34800
|
+
const sigmaTildeAtZero = GF.coefficient(t$5, 0);
|
|
34801
|
+
if (sigmaTildeAtZero == 0) throw new Error("sigmaTilde(0) was zero");
|
|
34802
|
+
const inverse = GF.inv(sigmaTildeAtZero);
|
|
34803
|
+
return [GF.mulPolyScalar(t$5, inverse), GF.mulPolyScalar(r$1, inverse)];
|
|
34804
|
+
}
|
|
34805
|
+
};
|
|
34806
|
+
function RS(eccWords) {
|
|
34807
|
+
return {
|
|
34808
|
+
encode(from) {
|
|
34809
|
+
const d = GF.divisorPoly(eccWords);
|
|
34810
|
+
const pol = Array.from(from);
|
|
34811
|
+
pol.push(...d.slice(0, -1).fill(0));
|
|
34812
|
+
return Uint8Array.from(GF.remainderPoly(pol, d));
|
|
34813
|
+
},
|
|
34814
|
+
decode(to) {
|
|
34815
|
+
const res = to.slice();
|
|
34816
|
+
const poly = GF.polynomial(Array.from(to));
|
|
34817
|
+
let syndrome = fillArr(eccWords, 0);
|
|
34818
|
+
let hasError = false;
|
|
34819
|
+
for (let i$1 = 0; i$1 < eccWords; i$1++) {
|
|
34820
|
+
const evl = GF.evalPoly(poly, GF.exp(i$1));
|
|
34821
|
+
syndrome[syndrome.length - 1 - i$1] = evl;
|
|
34822
|
+
if (evl !== 0) hasError = true;
|
|
34823
|
+
}
|
|
34824
|
+
if (!hasError) return res;
|
|
34825
|
+
syndrome = GF.polynomial(syndrome);
|
|
34826
|
+
const monomial = GF.monomial(eccWords, 1);
|
|
34827
|
+
const [errorLocator, errorEvaluator] = GF.euclidian(monomial, syndrome, eccWords);
|
|
34828
|
+
const locations = fillArr(GF.degree(errorLocator), 0);
|
|
34829
|
+
let e = 0;
|
|
34830
|
+
for (let i$1 = 1; i$1 < 256 && e < locations.length; i$1++) if (GF.evalPoly(errorLocator, i$1) === 0) locations[e++] = GF.inv(i$1);
|
|
34831
|
+
if (e !== locations.length) throw new Error("RS.decode: invalid errors number");
|
|
34832
|
+
for (let i$1 = 0; i$1 < locations.length; i$1++) {
|
|
34833
|
+
const pos = res.length - 1 - GF.log(locations[i$1]);
|
|
34834
|
+
if (pos < 0) throw new Error("RS.decode: invalid error location");
|
|
34835
|
+
const xiInverse = GF.inv(locations[i$1]);
|
|
34836
|
+
let denominator = 1;
|
|
34837
|
+
for (let j = 0; j < locations.length; j++) {
|
|
34838
|
+
if (i$1 === j) continue;
|
|
34839
|
+
denominator = GF.mul(denominator, GF.add(1, GF.mul(locations[j], xiInverse)));
|
|
34840
|
+
}
|
|
34841
|
+
res[pos] = GF.add(res[pos], GF.mul(GF.evalPoly(errorEvaluator, xiInverse), GF.inv(denominator)));
|
|
34842
|
+
}
|
|
34843
|
+
return res;
|
|
34844
|
+
}
|
|
34845
|
+
};
|
|
34846
|
+
}
|
|
34847
|
+
function interleave(ver, ecc) {
|
|
34848
|
+
const { words, shortBlocks, numBlocks, blockLen, total } = info.capacity(ver, ecc);
|
|
34849
|
+
const rs = RS(words);
|
|
34850
|
+
return {
|
|
34851
|
+
encode(bytes) {
|
|
34852
|
+
const blocks = [];
|
|
34853
|
+
const eccBlocks = [];
|
|
34854
|
+
for (let i$1 = 0; i$1 < numBlocks; i$1++) {
|
|
34855
|
+
const len = blockLen + (i$1 < shortBlocks ? 0 : 1);
|
|
34856
|
+
blocks.push(bytes.subarray(0, len));
|
|
34857
|
+
eccBlocks.push(rs.encode(bytes.subarray(0, len)));
|
|
34858
|
+
bytes = bytes.subarray(len);
|
|
34859
|
+
}
|
|
34860
|
+
const resBlocks = interleaveBytes(blocks);
|
|
34861
|
+
const resECC = interleaveBytes(eccBlocks);
|
|
34862
|
+
const res = new Uint8Array(resBlocks.length + resECC.length);
|
|
34863
|
+
res.set(resBlocks);
|
|
34864
|
+
res.set(resECC, resBlocks.length);
|
|
34865
|
+
return res;
|
|
34866
|
+
},
|
|
34867
|
+
decode(data$1) {
|
|
34868
|
+
if (data$1.length !== total) throw new Error(`interleave.decode: len(data)=${data$1.length}, total=${total}`);
|
|
34869
|
+
const blocks = [];
|
|
34870
|
+
for (let i$1 = 0; i$1 < numBlocks; i$1++) {
|
|
34871
|
+
const isShort = i$1 < shortBlocks;
|
|
34872
|
+
blocks.push(new Uint8Array(words + blockLen + (isShort ? 0 : 1)));
|
|
34873
|
+
}
|
|
34874
|
+
let pos = 0;
|
|
34875
|
+
for (let i$1 = 0; i$1 < blockLen; i$1++) for (let j = 0; j < numBlocks; j++) blocks[j][i$1] = data$1[pos++];
|
|
34876
|
+
for (let j = shortBlocks; j < numBlocks; j++) blocks[j][blockLen] = data$1[pos++];
|
|
34877
|
+
for (let i$1 = blockLen; i$1 < blockLen + words; i$1++) for (let j = 0; j < numBlocks; j++) {
|
|
34878
|
+
const isShort = j < shortBlocks;
|
|
34879
|
+
blocks[j][i$1 + (isShort ? 0 : 1)] = data$1[pos++];
|
|
34880
|
+
}
|
|
34881
|
+
const res = [];
|
|
34882
|
+
for (const block of blocks) res.push(...Array.from(rs.decode(block)).slice(0, -words));
|
|
34883
|
+
return Uint8Array.from(res);
|
|
34884
|
+
}
|
|
34885
|
+
};
|
|
34886
|
+
}
|
|
34887
|
+
function drawTemplate(ver, ecc, maskIdx, test = false) {
|
|
34888
|
+
const size = info.size.encode(ver);
|
|
34889
|
+
let b = new Bitmap(size + 2);
|
|
34890
|
+
const finder = new Bitmap(3).rect(0, 3, true).border(1, false).border(1, true).border(1, false);
|
|
34891
|
+
b = b.embed(0, finder).embed({
|
|
34892
|
+
x: -finder.width,
|
|
34893
|
+
y: 0
|
|
34894
|
+
}, finder).embed({
|
|
34895
|
+
x: 0,
|
|
34896
|
+
y: -finder.height
|
|
34897
|
+
}, finder);
|
|
34898
|
+
b = b.rectSlice(1, size);
|
|
34899
|
+
const align = new Bitmap(1).rect(0, 1, true).border(1, false).border(1, true);
|
|
34900
|
+
const alignPos = info.alignmentPatterns(ver);
|
|
34901
|
+
for (const y of alignPos) for (const x of alignPos) {
|
|
34902
|
+
if (b.isDefined(x, y)) continue;
|
|
34903
|
+
b.embed({
|
|
34904
|
+
x: x - 2,
|
|
34905
|
+
y: y - 2
|
|
34906
|
+
}, align);
|
|
34907
|
+
}
|
|
34908
|
+
b = b.hLine({
|
|
34909
|
+
x: 0,
|
|
34910
|
+
y: 6
|
|
34911
|
+
}, Infinity, ({ x }) => b.isDefined(x, 6) ? void 0 : x % 2 == 0).vLine({
|
|
34912
|
+
x: 6,
|
|
34913
|
+
y: 0
|
|
34914
|
+
}, Infinity, ({ y }) => b.isDefined(6, y) ? void 0 : y % 2 == 0);
|
|
34915
|
+
{
|
|
34916
|
+
const bits = info.formatBits(ecc, maskIdx);
|
|
34917
|
+
const getBit = (i$1) => !test && (bits >> i$1 & 1) == 1;
|
|
34918
|
+
for (let i$1 = 0; i$1 < 6; i$1++) b.set(8, i$1, getBit(i$1));
|
|
34919
|
+
for (let i$1 = 6; i$1 < 8; i$1++) b.set(8, i$1 + 1, getBit(i$1));
|
|
34920
|
+
for (let i$1 = 8; i$1 < 15; i$1++) b.set(8, size - 15 + i$1, getBit(i$1));
|
|
34921
|
+
for (let i$1 = 0; i$1 < 8; i$1++) b.set(size - i$1 - 1, 8, getBit(i$1));
|
|
34922
|
+
for (let i$1 = 8; i$1 < 9; i$1++) b.set(15 - i$1 - 1 + 1, 8, getBit(i$1));
|
|
34923
|
+
for (let i$1 = 9; i$1 < 15; i$1++) b.set(15 - i$1 - 1, 8, getBit(i$1));
|
|
34924
|
+
b.set(8, size - 8, !test);
|
|
34925
|
+
}
|
|
34926
|
+
if (ver >= 7) {
|
|
34927
|
+
const bits = info.versionBits(ver);
|
|
34928
|
+
for (let i$1 = 0; i$1 < 18; i$1 += 1) {
|
|
34929
|
+
const bit = !test && (bits >> i$1 & 1) == 1;
|
|
34930
|
+
const x = Math.floor(i$1 / 3);
|
|
34931
|
+
const y = i$1 % 3 + size - 8 - 3;
|
|
34932
|
+
b.set(y, x, bit);
|
|
34933
|
+
b.set(x, y, bit);
|
|
34934
|
+
}
|
|
34935
|
+
}
|
|
34936
|
+
return b;
|
|
34937
|
+
}
|
|
34938
|
+
function zigzag(tpl, maskIdx, fn) {
|
|
34939
|
+
const bm = tpl;
|
|
34940
|
+
const size = bm.height;
|
|
34941
|
+
const pattern = PATTERNS[maskIdx];
|
|
34942
|
+
let dir = -1;
|
|
34943
|
+
let y = size - 1;
|
|
34944
|
+
for (let xOffset = size - 1; xOffset > 0; xOffset -= 2) {
|
|
34945
|
+
if (xOffset == 6) xOffset = 5;
|
|
34946
|
+
for (;; y += dir) {
|
|
34947
|
+
for (let j = 0; j < 2; j += 1) {
|
|
34948
|
+
const x = xOffset - j;
|
|
34949
|
+
if (bm.isDefined(x, y)) continue;
|
|
34950
|
+
fn(x, y, pattern(x, y));
|
|
34951
|
+
}
|
|
34952
|
+
if (y + dir < 0 || y + dir >= size) break;
|
|
34953
|
+
}
|
|
34954
|
+
dir = -dir;
|
|
34955
|
+
}
|
|
34956
|
+
}
|
|
34957
|
+
function detectType(str) {
|
|
34958
|
+
let type = "numeric";
|
|
34959
|
+
for (let x of str) {
|
|
34960
|
+
if (info.alphabet.numeric.has(x)) continue;
|
|
34961
|
+
type = "alphanumeric";
|
|
34962
|
+
if (!info.alphabet.alphanumerc.has(x)) return "byte";
|
|
34963
|
+
}
|
|
34964
|
+
return type;
|
|
34965
|
+
}
|
|
34966
|
+
/**
|
|
34967
|
+
* Encode a string as UTF-8 bytes.
|
|
34968
|
+
* @param str - Text to encode into UTF-8.
|
|
34969
|
+
* @returns UTF-8 bytes for the provided string.
|
|
34970
|
+
* @throws If the input is not a string. {@link Error}
|
|
34971
|
+
* @example
|
|
34972
|
+
* Encode a string as UTF-8 bytes.
|
|
34973
|
+
* ```ts
|
|
34974
|
+
* const bytes = utf8ToBytes('abc'); // new Uint8Array([97, 98, 99])
|
|
34975
|
+
* ```
|
|
34976
|
+
*/
|
|
34977
|
+
function utf8ToBytes(str) {
|
|
34978
|
+
if (typeof str !== "string") throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
34979
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
34980
|
+
}
|
|
34981
|
+
function encode$1(ver, ecc, data$1, type, encoder$1 = utf8ToBytes) {
|
|
34982
|
+
let encoded = "";
|
|
34983
|
+
let dataLen = data$1.length;
|
|
34984
|
+
if (type === "numeric") {
|
|
34985
|
+
const t$5 = info.alphabet.numeric.decode(data$1.split(""));
|
|
34986
|
+
const n$1 = t$5.length;
|
|
34987
|
+
for (let i$1 = 0; i$1 < n$1 - 2; i$1 += 3) encoded += bin(t$5[i$1] * 100 + t$5[i$1 + 1] * 10 + t$5[i$1 + 2], 10);
|
|
34988
|
+
if (n$1 % 3 === 1) encoded += bin(t$5[n$1 - 1], 4);
|
|
34989
|
+
else if (n$1 % 3 === 2) encoded += bin(t$5[n$1 - 2] * 10 + t$5[n$1 - 1], 7);
|
|
34990
|
+
} else if (type === "alphanumeric") {
|
|
34991
|
+
const t$5 = info.alphabet.alphanumerc.decode(data$1.split(""));
|
|
34992
|
+
const n$1 = t$5.length;
|
|
34993
|
+
for (let i$1 = 0; i$1 < n$1 - 1; i$1 += 2) encoded += bin(t$5[i$1] * 45 + t$5[i$1 + 1], 11);
|
|
34994
|
+
if (n$1 % 2 == 1) encoded += bin(t$5[n$1 - 1], 6);
|
|
34995
|
+
} else if (type === "byte") {
|
|
34996
|
+
const utf8 = encoder$1(data$1);
|
|
34997
|
+
dataLen = utf8.length;
|
|
34998
|
+
encoded = Array.from(utf8).map((i$1) => bin(i$1, 8)).join("");
|
|
34999
|
+
} else throw new Error("encode: unsupported type");
|
|
35000
|
+
const { capacity } = info.capacity(ver, ecc);
|
|
35001
|
+
const len = bin(dataLen, info.lengthBits(ver, type));
|
|
35002
|
+
let bits = info.modeBits[type] + len + encoded;
|
|
35003
|
+
if (bits.length > capacity) throw new Error("Capacity overflow");
|
|
35004
|
+
bits += "0".repeat(Math.min(4, Math.max(0, capacity - bits.length)));
|
|
35005
|
+
if (bits.length % 8) bits += "0".repeat(8 - bits.length % 8);
|
|
35006
|
+
const padding = "1110110000010001";
|
|
35007
|
+
for (let idx = 0; bits.length !== capacity; idx++) bits += padding[idx % 16];
|
|
35008
|
+
const bytes = Uint8Array.from(bits.match(/(.{8})/g).map((i$1) => Number(`0b${i$1}`)));
|
|
35009
|
+
return interleave(ver, ecc).encode(bytes);
|
|
35010
|
+
}
|
|
35011
|
+
function drawQR(ver, ecc, data$1, maskIdx, test = false) {
|
|
35012
|
+
const b = drawTemplate(ver, ecc, maskIdx, test);
|
|
35013
|
+
let i$1 = 0;
|
|
35014
|
+
const need = 8 * data$1.length;
|
|
35015
|
+
zigzag(b, maskIdx, (x, y, mask) => {
|
|
35016
|
+
let value = false;
|
|
35017
|
+
if (i$1 < need) {
|
|
35018
|
+
value = (data$1[i$1 >>> 3] >> (7 - i$1 & 7) & 1) !== 0;
|
|
35019
|
+
i$1++;
|
|
35020
|
+
}
|
|
35021
|
+
b.set(x, y, value !== mask);
|
|
35022
|
+
});
|
|
35023
|
+
if (i$1 !== need) throw new Error("QR: bytes left after draw");
|
|
35024
|
+
return b;
|
|
35025
|
+
}
|
|
35026
|
+
const mkPattern = (pattern) => {
|
|
35027
|
+
const s = pattern.map((i$1) => i$1 ? "1" : "0").join("");
|
|
35028
|
+
return {
|
|
35029
|
+
len: s.length,
|
|
35030
|
+
n: Number(`0b${s}`)
|
|
35031
|
+
};
|
|
35032
|
+
};
|
|
35033
|
+
const finderPattern = [
|
|
35034
|
+
true,
|
|
35035
|
+
false,
|
|
35036
|
+
true,
|
|
35037
|
+
true,
|
|
35038
|
+
true,
|
|
35039
|
+
false,
|
|
35040
|
+
true
|
|
35041
|
+
];
|
|
35042
|
+
const lightPattern = [
|
|
35043
|
+
false,
|
|
35044
|
+
false,
|
|
35045
|
+
false,
|
|
35046
|
+
false
|
|
35047
|
+
];
|
|
35048
|
+
const P1 = /* @__PURE__ */ (() => mkPattern([...finderPattern, ...lightPattern]))();
|
|
35049
|
+
const P2 = /* @__PURE__ */ (() => mkPattern([...lightPattern, ...finderPattern]))();
|
|
35050
|
+
function penalty(bm) {
|
|
35051
|
+
const b = bm;
|
|
35052
|
+
const { width, height } = b;
|
|
35053
|
+
const transposed = b.transpose();
|
|
35054
|
+
let adjacent = 0;
|
|
35055
|
+
for (let y = 0; y < height; y++) b.getRuns(y, (len) => {
|
|
35056
|
+
if (len >= 5) adjacent += 3 + (len - 5);
|
|
35057
|
+
});
|
|
35058
|
+
for (let y = 0; y < width; y++) transposed.getRuns(y, (len) => {
|
|
35059
|
+
if (len >= 5) adjacent += 3 + (len - 5);
|
|
35060
|
+
});
|
|
35061
|
+
let box = 0;
|
|
35062
|
+
for (let y = 0; y < height - 1; y++) box += 3 * b.countBoxes2x2(y);
|
|
35063
|
+
let finder = 0;
|
|
35064
|
+
for (let y = 0; y < height; y++) finder += 40 * b.countPatternInRow(y, P1.len, P1.n, P2.n);
|
|
35065
|
+
for (let y = 0; y < width; y++) finder += 40 * transposed.countPatternInRow(y, P1.len, P1.n, P2.n);
|
|
35066
|
+
const total = height * width;
|
|
35067
|
+
const darkPixels = b.popcnt();
|
|
35068
|
+
const dark = 10 * Math.ceil(Math.max(0, Math.abs(darkPixels * 100 - total * 50) - total * 5) / (total * 5));
|
|
35069
|
+
return adjacent + box + finder + dark;
|
|
35070
|
+
}
|
|
35071
|
+
function drawQRBest(ver, ecc, data$1, maskIdx) {
|
|
35072
|
+
if (maskIdx === void 0) {
|
|
35073
|
+
const bestMask = best();
|
|
35074
|
+
for (let mask = 0; mask < PATTERNS.length; mask++) bestMask.add(penalty(drawQR(ver, ecc, data$1, mask, true)), mask);
|
|
35075
|
+
maskIdx = bestMask.get();
|
|
35076
|
+
}
|
|
35077
|
+
if (maskIdx === void 0) throw new Error("Cannot find mask");
|
|
35078
|
+
return drawQR(ver, ecc, data$1, maskIdx);
|
|
35079
|
+
}
|
|
35080
|
+
function validateECC(ec) {
|
|
35081
|
+
if (!ECMode.includes(ec)) throw new Error(`Invalid error correction mode=${ec}. Expected: ${ECMode}`);
|
|
35082
|
+
}
|
|
35083
|
+
function validateEncoding(enc) {
|
|
35084
|
+
if (!Encoding.includes(enc)) throw new Error(`Encoding: invalid mode=${enc}. Expected: ${Encoding}`);
|
|
35085
|
+
if (enc === "kanji" || enc === "eci") throw new Error(`Encoding: ${enc} is not supported (yet?).`);
|
|
35086
|
+
}
|
|
35087
|
+
function validateMask(mask) {
|
|
35088
|
+
if (![
|
|
35089
|
+
0,
|
|
35090
|
+
1,
|
|
35091
|
+
2,
|
|
35092
|
+
3,
|
|
35093
|
+
4,
|
|
35094
|
+
5,
|
|
35095
|
+
6,
|
|
35096
|
+
7
|
|
35097
|
+
].includes(mask) || !PATTERNS[mask]) throw new Error(`Invalid mask=${mask}. Expected number [0..7]`);
|
|
35098
|
+
}
|
|
35099
|
+
function encodeQR(text, output = "raw", opts = {}) {
|
|
35100
|
+
const _opts = opts;
|
|
35101
|
+
const ecc = _opts.ecc !== void 0 ? _opts.ecc : "medium";
|
|
35102
|
+
validateECC(ecc);
|
|
35103
|
+
const encoding = _opts.encoding !== void 0 ? _opts.encoding : detectType(text);
|
|
35104
|
+
validateEncoding(encoding);
|
|
35105
|
+
if (_opts.mask !== void 0) validateMask(_opts.mask);
|
|
35106
|
+
let ver = _opts.version;
|
|
35107
|
+
let data$1, err = /* @__PURE__ */ new Error("Unknown error");
|
|
35108
|
+
if (ver !== void 0) {
|
|
35109
|
+
validateVersion(ver);
|
|
35110
|
+
data$1 = encode$1(ver, ecc, text, encoding, _opts.textEncoder);
|
|
35111
|
+
} else for (let i$1 = 1; i$1 <= 40; i$1++) try {
|
|
35112
|
+
data$1 = encode$1(i$1, ecc, text, encoding, _opts.textEncoder);
|
|
35113
|
+
ver = i$1;
|
|
35114
|
+
break;
|
|
35115
|
+
} catch (e) {
|
|
35116
|
+
err = e;
|
|
35117
|
+
}
|
|
35118
|
+
if (!ver || !data$1) throw err;
|
|
35119
|
+
let res = drawQRBest(ver, ecc, data$1, _opts.mask);
|
|
35120
|
+
res.assertDrawn();
|
|
35121
|
+
const border = _opts.border === void 0 ? 2 : _opts.border;
|
|
35122
|
+
if (!Number.isSafeInteger(border) || border <= 0) throw new Error(`invalid border=${border}`);
|
|
35123
|
+
res = res.border(border, false);
|
|
35124
|
+
if (_opts.scale !== void 0) res = res.scale(_opts.scale);
|
|
35125
|
+
if (output === "raw") return res.toRaw();
|
|
35126
|
+
else if (output === "ascii") return res.toASCII();
|
|
35127
|
+
else if (output === "svg") return res.toSVG(_opts.optimize);
|
|
35128
|
+
else if (output === "gif") return res.toGIF();
|
|
35129
|
+
else if (output === "term") return res.toTerm();
|
|
35130
|
+
else throw new Error(`Unknown output: ${output}`);
|
|
35131
|
+
}
|
|
35132
|
+
/**
|
|
35133
|
+
* Default export alias for {@link encodeQR}.
|
|
35134
|
+
* @param text - Text payload that should be encoded into the QR symbol.
|
|
35135
|
+
* @param output - Output format to generate: raw matrix, ASCII, terminal ANSI, GIF, or SVG.
|
|
35136
|
+
* @param opts - Encoding and rendering options. See {@link QrOpts} and {@link SvgQrOpts}.
|
|
35137
|
+
* @returns Encoded QR data in the format selected by `output`.
|
|
35138
|
+
* @throws If the payload, options, QR capacity, or output format are invalid. {@link Error}
|
|
35139
|
+
* @example
|
|
35140
|
+
* Encode text into the default export from the package root.
|
|
35141
|
+
* ```ts
|
|
35142
|
+
* import encodeQR from 'qr';
|
|
35143
|
+
* encodeQR('Hello world', 'ascii');
|
|
35144
|
+
* ```
|
|
35145
|
+
*/
|
|
35146
|
+
var qr_default = encodeQR;
|
|
35147
|
+
|
|
35148
|
+
//#endregion
|
|
35149
|
+
//#region src/plugins/tunnel.ts
|
|
33835
35150
|
function createPublicExposureWarning(mode, name, shortcutPressed) {
|
|
33836
35151
|
const intro = name === void 0 ? import_picocolors$5.default.dim("Once connected, this tunnel will be ") + "publicly accessible" + import_picocolors$5.default.dim(". Anyone who can reach it can:") : import_picocolors$5.default.dim("Once connected, this tunnel may be reachable from the Internet. Anyone who can reach it can:");
|
|
33837
35152
|
const concerns = [
|
|
@@ -34115,6 +35430,11 @@ function patchPrintUrls(server) {
|
|
|
34115
35430
|
if (!publicUrls || publicUrls.length === 0) return;
|
|
34116
35431
|
for (let i$1 = 0; i$1 < publicUrls.length; i$1++) if (i$1 === 0) server.config.logger.info(`${import_picocolors$5.default.green(" ➜")} ${import_picocolors$5.default.bold("Tunnel:")} ${import_picocolors$5.default.cyan(publicUrls[i$1])}`);
|
|
34117
35432
|
else server.config.logger.info(` ${import_picocolors$5.default.cyan(publicUrls[i$1])}`);
|
|
35433
|
+
const primaryUrl = publicUrls[0];
|
|
35434
|
+
if (primaryUrl) try {
|
|
35435
|
+
const qrCode = qr_default(primaryUrl, "ascii", { border: 1 });
|
|
35436
|
+
server.config.logger.info(`\n${qrCode}`);
|
|
35437
|
+
} catch {}
|
|
34118
35438
|
server.config.logger.info("");
|
|
34119
35439
|
};
|
|
34120
35440
|
}
|
|
@@ -44707,10 +46027,10 @@ var util;
|
|
|
44707
46027
|
util$27.assertEqual = (_) => {};
|
|
44708
46028
|
function assertIs(_arg) {}
|
|
44709
46029
|
util$27.assertIs = assertIs;
|
|
44710
|
-
function assertNever
|
|
46030
|
+
function assertNever(_x) {
|
|
44711
46031
|
throw new Error();
|
|
44712
46032
|
}
|
|
44713
|
-
util$27.assertNever = assertNever
|
|
46033
|
+
util$27.assertNever = assertNever;
|
|
44714
46034
|
util$27.arrayToEnum = (items) => {
|
|
44715
46035
|
const obj = {};
|
|
44716
46036
|
for (const item of items) obj[item] = item;
|
|
@@ -50047,10 +51367,16 @@ async function getImageRepoTags(dockerPath, imageTag) {
|
|
|
50047
51367
|
*/
|
|
50048
51368
|
async function cleanupDuplicateImageTags(dockerPath, imageTag) {
|
|
50049
51369
|
try {
|
|
50050
|
-
const
|
|
51370
|
+
const repoTags = await getImageRepoTags(dockerPath, imageTag);
|
|
51371
|
+
const currentBuildId = getImageTag(imageTag);
|
|
51372
|
+
const tagsToRemove = repoTags.filter((tag) => tag.startsWith("cloudflare-dev") && getImageTag(tag) !== currentBuildId);
|
|
50051
51373
|
if (tagsToRemove.length > 0) runDockerCmdWithOutput(dockerPath, ["rmi", ...tagsToRemove]);
|
|
50052
51374
|
} catch {}
|
|
50053
51375
|
}
|
|
51376
|
+
function getImageTag(imageTag) {
|
|
51377
|
+
const tagSeparatorIndex = imageTag.lastIndexOf(":");
|
|
51378
|
+
return tagSeparatorIndex === -1 ? void 0 : imageTag.slice(tagSeparatorIndex + 1);
|
|
51379
|
+
}
|
|
50054
51380
|
|
|
50055
51381
|
//#endregion
|
|
50056
51382
|
//#region ../containers-shared/src/images.ts
|