This commit is contained in:
freedakgmail
2025-11-22 23:49:24 +08:00
parent b83382b604
commit c033e46782
3580 changed files with 1745279 additions and 2428 deletions
Generated Vendored
+18
View File
@@ -115,6 +115,8 @@ hoistedDependencies:
'@types/d3-timer': private
aria-hidden@1.2.6:
aria-hidden: private
base64-arraybuffer@1.0.2:
base64-arraybuffer: private
baseline-browser-mapping@2.8.30:
baseline-browser-mapping: private
browserslist@4.28.0:
@@ -123,6 +125,8 @@ hoistedDependencies:
caniuse-lite: private
client-only@0.0.1:
client-only: private
css-line-break@2.1.0:
css-line-break: private
csstype@3.2.3:
csstype: private
d3-array@3.2.4:
@@ -169,6 +173,8 @@ hoistedDependencies:
escalade: private
eventemitter3@4.0.7:
eventemitter3: private
fast-deep-equal@3.1.3:
fast-deep-equal: private
fast-equals@5.3.3:
fast-equals: private
fraction.js@5.3.4:
@@ -227,14 +233,20 @@ hoistedDependencies:
semver: private
sharp@0.34.5:
sharp: private
size-sensor@1.0.2:
size-sensor: private
source-map-js@1.2.1:
source-map-js: private
styled-jsx@5.1.6(react@19.2.0):
styled-jsx: private
tapable@2.3.0:
tapable: private
text-segmentation@1.0.3:
text-segmentation: private
tiny-invariant@1.3.3:
tiny-invariant: private
tslib@2.3.0:
tslib: private
tslib@2.8.1:
tslib: private
undici-types@6.21.0:
@@ -247,8 +259,14 @@ hoistedDependencies:
use-sidecar: private
use-sync-external-store@1.6.0(react@19.2.0):
use-sync-external-store: private
utrie@1.0.2:
utrie: private
uzip@0.20201231.0:
uzip: private
victory-vendor@36.9.2:
victory-vendor: private
zrender@6.0.0:
zrender: private
ignoredBuilds:
- sharp
included:
+1 -1
View File
@@ -1,5 +1,5 @@
{
"lastValidatedTimestamp": 1763812566534,
"lastValidatedTimestamp": 1763824262377,
"projects": {},
"pnpmfiles": [],
"settings": {
@@ -0,0 +1,28 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [1.0.2](https://github.com/niklasvh/base64-arraybuffer/compare/v1.0.1...v1.0.2) (2022-01-22)
### fix
* source maps (#33) ([bd5a8ef](https://github.com/niklasvh/base64-arraybuffer/commit/bd5a8eff3a44ea07f9b68533c477076124220ddd)), closes [#33](https://github.com/niklasvh/base64-arraybuffer/issues/33)
## [1.0.1](https://github.com/niklasvh/base64-arraybuffer/compare/v1.0.0...v1.0.1) (2021-08-10)
### fix
* make lib loadable on ie9 (#30) ([a618d14](https://github.com/niklasvh/base64-arraybuffer/commit/a618d14d323f4eb230321a3609bfbc9f23f430c0)), closes [#30](https://github.com/niklasvh/base64-arraybuffer/issues/30)
# [1.0.0](https://github.com/niklasvh/base64-arraybuffer/compare/v0.2.0...v1.0.0) (2021-08-10)
### docs
* update readme (#29) ([0a0253d](https://github.com/niklasvh/base64-arraybuffer/commit/0a0253dcc2e3f01a1f6d04fa81d578f714fce27f)), closes [#29](https://github.com/niklasvh/base64-arraybuffer/issues/29)
@@ -0,0 +1,22 @@
Copyright (c) 2012 Niklas von Hertzen
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
# base64-arraybuffer
![CI](https://github.com/niklasvh/base64-arraybuffer/workflows/CI/badge.svg?branch=master)
[![NPM Downloads](https://img.shields.io/npm/dm/base64-arraybuffer.svg)](https://www.npmjs.org/package/base64-arraybuffer)
[![NPM Version](https://img.shields.io/npm/v/base64-arraybuffer.svg)](https://www.npmjs.org/package/base64-arraybuffer)
Encode/decode base64 data into ArrayBuffers
### Installing
You can install the module via npm:
npm install base64-arraybuffer
## API
The library encodes and decodes base64 to and from ArrayBuffers
- __encode(buffer)__ - Encodes `ArrayBuffer` into base64 string
- __decode(str)__ - Decodes base64 string to `ArrayBuffer`
### Testing
You can run the test suite with:
npm test
## License
Copyright (c) 2012 Niklas von Hertzen
Licensed under the MIT license.
@@ -0,0 +1,50 @@
/*
* base64-arraybuffer 1.0.2 <https://github.com/niklasvh/base64-arraybuffer>
* Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>
* Released under MIT License
*/
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
var encode = function (arraybuffer) {
var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
}
else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
return base64;
};
var decode = function (base64) {
var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer;
};
export { decode, encode };
//# sourceMappingURL=base64-arraybuffer.es5.js.map
@@ -0,0 +1 @@
{"version":3,"file":"base64-arraybuffer.es5.js","sources":["../../src/index.ts"],"sourcesContent":["const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n// Use a lookup table to find the index.\nconst lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);\nfor (let i = 0; i < chars.length; i++) {\n lookup[chars.charCodeAt(i)] = i;\n}\n\nexport const encode = (arraybuffer: ArrayBuffer): string => {\n let bytes = new Uint8Array(arraybuffer),\n i,\n len = bytes.length,\n base64 = '';\n\n for (i = 0; i < len; i += 3) {\n base64 += chars[bytes[i] >> 2];\n base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];\n base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];\n base64 += chars[bytes[i + 2] & 63];\n }\n\n if (len % 3 === 2) {\n base64 = base64.substring(0, base64.length - 1) + '=';\n } else if (len % 3 === 1) {\n base64 = base64.substring(0, base64.length - 2) + '==';\n }\n\n return base64;\n};\n\nexport const decode = (base64: string): ArrayBuffer => {\n let bufferLength = base64.length * 0.75,\n len = base64.length,\n i,\n p = 0,\n encoded1,\n encoded2,\n encoded3,\n encoded4;\n\n if (base64[base64.length - 1] === '=') {\n bufferLength--;\n if (base64[base64.length - 2] === '=') {\n bufferLength--;\n }\n }\n\n const arraybuffer = new ArrayBuffer(bufferLength),\n bytes = new Uint8Array(arraybuffer);\n\n for (i = 0; i < len; i += 4) {\n encoded1 = lookup[base64.charCodeAt(i)];\n encoded2 = lookup[base64.charCodeAt(i + 1)];\n encoded3 = lookup[base64.charCodeAt(i + 2)];\n encoded4 = lookup[base64.charCodeAt(i + 3)];\n\n bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);\n bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);\n bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);\n }\n\n return arraybuffer;\n};\n"],"names":[],"mappings":";;;;;AAAA,IAAM,KAAK,GAAG,kEAAkE,CAAC;AAEjF;AACA,IAAM,MAAM,GAAG,OAAO,UAAU,KAAK,WAAW,GAAG,EAAE,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;AAC5E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IACnC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CACnC;IAEY,MAAM,GAAG,UAAC,WAAwB;IAC3C,IAAI,KAAK,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,EACnC,CAAC,EACD,GAAG,GAAG,KAAK,CAAC,MAAM,EAClB,MAAM,GAAG,EAAE,CAAC;IAEhB,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7D,MAAM,IAA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ACzB,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QACxC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5C,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5C,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAE5C,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC;QAC/C,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,GAAG,EAAE,KAAK,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC;QACtD,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,GAAG,CAAC,KAAK,CAAC,KAAK,QAAQ,GAAG,EAAE,CAAC,CAAC;KACxD;IAED,OAAO,WAAW,CAAC;AACvB;;;;"}
@@ -0,0 +1,61 @@
/*
* base64-arraybuffer 1.0.2 <https://github.com/niklasvh/base64-arraybuffer>
* Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>
* Released under MIT License
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['base64-arraybuffer'] = {}));
}(this, (function (exports) { 'use strict';
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
var encode = function (arraybuffer) {
var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
}
else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
return base64;
};
var decode = function (base64) {
var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer;
};
exports.decode = decode;
exports.encode = encode;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=base64-arraybuffer.umd.js.map
@@ -0,0 +1 @@
{"version":3,"file":"base64-arraybuffer.umd.js","sources":["../../src/index.ts"],"sourcesContent":["const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n// Use a lookup table to find the index.\nconst lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);\nfor (let i = 0; i < chars.length; i++) {\n lookup[chars.charCodeAt(i)] = i;\n}\n\nexport const encode = (arraybuffer: ArrayBuffer): string => {\n let bytes = new Uint8Array(arraybuffer),\n i,\n len = bytes.length,\n base64 = '';\n\n for (i = 0; i < len; i += 3) {\n base64 += chars[bytes[i] >> 2];\n base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];\n base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];\n base64 += chars[bytes[i + 2] & 63];\n }\n\n if (len % 3 === 2) {\n base64 = base64.substring(0, base64.length - 1) + '=';\n } else if (len % 3 === 1) {\n base64 = base64.substring(0, base64.length - 2) + '==';\n }\n\n return base64;\n};\n\nexport const decode = (base64: string): ArrayBuffer => {\n let bufferLength = base64.length * 0.75,\n len = base64.length,\n i,\n p = 0,\n encoded1,\n encoded2,\n encoded3,\n encoded4;\n\n if (base64[base64.length - 1] === '=') {\n bufferLength--;\n if (base64[base64.length - 2] === '=') {\n bufferLength--;\n }\n }\n\n const arraybuffer = new ArrayBuffer(bufferLength),\n bytes = new Uint8Array(arraybuffer);\n\n for (i = 0; i < len; i += 4) {\n encoded1 = lookup[base64.charCodeAt(i)];\n encoded2 = lookup[base64.charCodeAt(i + 1)];\n encoded3 = lookup[base64.charCodeAt(i + 2)];\n encoded4 = lookup[base64.charCodeAt(i + 3)];\n\n bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);\n bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);\n bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);\n }\n\n return arraybuffer;\n};\n"],"names":[],"mappings":";;;;;;;;;;;IAAA,IAAM,KAAK,GAAG,kEAAkE,CAAC;IAEjF;IACA,IAAM,MAAM,GAAG,OAAO,UAAU,KAAK,WAAW,GAAG,EAAE,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAC5E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG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AC;SACxD;QAED,OAAO,WAAW,CAAC;IACvB;;;;;;;;;;;"}
@@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decode = exports.encode = void 0;
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
var encode = function (arraybuffer) {
var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
}
else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
return base64;
};
exports.encode = encode;
var decode = function (base64) {
var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer;
};
exports.decode = decode;
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":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AC,CAAC;QAC5C,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAE5C,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC;QAC/C,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC;QACtD,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;KACxD;IAED,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAhCW,QAAA,MAAM,UAgCjB"}
@@ -0,0 +1,2 @@
export declare const encode: (arraybuffer: ArrayBuffer) => string;
export declare const decode: (base64: string) => ArrayBuffer;
@@ -0,0 +1,54 @@
{
"name": "base64-arraybuffer",
"description": "Encode/decode base64 data into ArrayBuffers",
"main": "dist/base64-arraybuffer.umd.js",
"module": "dist/base64-arraybuffer.es5.js",
"typings": "dist/types/index.d.ts",
"version": "1.0.2",
"homepage": "https://github.com/niklasvh/base64-arraybuffer",
"author": {
"name": "Niklas von Hertzen",
"email": "niklasvh@gmail.com",
"url": "https://hertzen.com"
},
"repository": {
"type": "git",
"url": "https://github.com/niklasvh/base64-arraybuffer"
},
"bugs": {
"url": "https://github.com/niklasvh/base64-arraybuffer/issues"
},
"license": "MIT",
"engines": {
"node": ">= 0.6.0"
},
"scripts": {
"prebuild": "rimraf dist/",
"build": "tsc --module commonjs && rollup -c rollup.config.ts",
"format": "prettier --write \"{src,test}/**/*.ts\"",
"lint": "tslint -c tslint.json --project tsconfig.json -t codeFrame src/**/*.ts test/**/*.ts",
"mocha": "mocha --require ts-node/register test/*.ts",
"test": "npm run lint && npm run mocha",
"release": "standard-version"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/mocha": "^8.2.2",
"@types/node": "^16.0.0",
"mocha": "9.0.2",
"prettier": "^2.3.2",
"rimraf": "3.0.2",
"rollup": "^2.52.7",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"standard-version": "^9.3.0",
"ts-node": "^10.0.0",
"tslib": "^2.3.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.3.5"
},
"keywords": []
}
@@ -0,0 +1,40 @@
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import sourceMaps from 'rollup-plugin-sourcemaps';
import typescript from '@rollup/plugin-typescript';
import json from 'rollup-plugin-json';
const pkg = require('./package.json');
const banner = `/*
* ${pkg.name} ${pkg.version} <${pkg.homepage}>
* Copyright (c) ${(new Date()).getFullYear()} ${pkg.author.name} <${pkg.author.url}>
* Released under ${pkg.license} License
*/`;
export default {
input: `src/index.ts`,
output: [
{ file: pkg.main, name: pkg.name, format: 'umd', banner, sourcemap: true },
{ file: pkg.module, format: 'esm', banner, sourcemap: true },
],
external: [],
watch: {
include: 'src/**',
},
plugins: [
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
resolve(),
// Allow json resolution
json(),
// Compile TypeScript files
typescript({ sourceMap: true, inlineSources: true }),
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs(),
// Resolve source maps to the original source
sourceMaps(),
],
}
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Donald Chan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,229 @@
# Browser Image Compression
[![npm](https://img.shields.io/npm/v/browser-image-compression.svg)](https://www.npmjs.com/package/browser-image-compression)
[![npm](./coverage/badge.svg)](https://github.com/Donaldcwl/browser-image-compression)
[![npm](https://img.shields.io/npm/l/browser-image-compression.svg)](https://github.com/Donaldcwl/browser-image-compression)
Javascript module to be run in the web browser for image compression.
## Features
- You can use this module to compress jpeg, png, webp, and bmp images by reducing **resolution** or **storage size** before uploading to the application server to save bandwidth.
- **Multi-thread** (web worker) non-blocking compression is supported through options.
## Demo / Example
open https://donaldcwl.github.io/browser-image-compression/example/basic.html
or check the "[example]" folder in this repo
## Usage
```html
<input type="file" accept="image/*" onchange="handleImageUpload(event);">
```
### async await syntax:
```javascript
async function handleImageUpload(event) {
const imageFile = event.target.files[0];
console.log('originalFile instanceof Blob', imageFile instanceof Blob); // true
console.log(`originalFile size ${imageFile.size / 1024 / 1024} MB`);
const options = {
maxSizeMB: 1,
maxWidthOrHeight: 1920,
useWebWorker: true,
}
try {
const compressedFile = await imageCompression(imageFile, options);
console.log('compressedFile instanceof Blob', compressedFile instanceof Blob); // true
console.log(`compressedFile size ${compressedFile.size / 1024 / 1024} MB`); // smaller than maxSizeMB
await uploadToServer(compressedFile); // write your own logic
} catch (error) {
console.log(error);
}
}
```
### Promise.then().catch() syntax:
<details>
<summary>Click to expand</summary>
```javascript
function handleImageUpload(event) {
var imageFile = event.target.files[0];
console.log('originalFile instanceof Blob', imageFile instanceof Blob); // true
console.log(`originalFile size ${imageFile.size / 1024 / 1024} MB`);
var options = {
maxSizeMB: 1,
maxWidthOrHeight: 1920,
useWebWorker: true
}
imageCompression(imageFile, options)
.then(function (compressedFile) {
console.log('compressedFile instanceof Blob', compressedFile instanceof Blob); // true
console.log(`compressedFile size ${compressedFile.size / 1024 / 1024} MB`); // smaller than maxSizeMB
return uploadToServer(compressedFile); // write your own logic
})
.catch(function (error) {
console.log(error.message);
});
}
```
</details>
## Installing
### Use as ES module:
You can install it via npm or yarn
```bash
npm install browser-image-compression --save
# or
yarn add browser-image-compression
```
```javascript
import imageCompression from 'browser-image-compression';
```
(can be used in frameworks like React, Angular, Vue etc)
(work with bundlers like webpack and rollup)
### (or) Load UMD js file:
You can download imageCompression from the [dist folder][dist].
Alternatively, you can use a CDN like [delivrjs]:
```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.1/dist/browser-image-compression.js"></script>
```
## Support
If this project helps you reduce the time to develop, you can buy me a cup of coffee :)
<a href="https://donaldcwl.github.io/donation/" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-red.png" alt="Buy Me A Coffee" height=60 width=217 ></a>
(powered by Stripe)
## API
### Main function
```javascript
// you should provide one of maxSizeMB, maxWidthOrHeight in the options
const options: Options = {
maxSizeMB: number, // (default: Number.POSITIVE_INFINITY)
maxWidthOrHeight: number, // compressedFile will scale down by ratio to a point that width or height is smaller than maxWidthOrHeight (default: undefined)
// but, automatically reduce the size to smaller than the maximum Canvas size supported by each browser.
// Please check the Caveat part for details.
onProgress: Function, // optional, a function takes one progress argument (percentage from 0 to 100)
useWebWorker: boolean, // optional, use multi-thread web worker, fallback to run in main-thread (default: true)
libURL: string, // optional, the libURL of this library for importing script in Web Worker (default: https://cdn.jsdelivr.net/npm/browser-image-compression/dist/browser-image-compression.js)
preserveExif: boolean, // optional, use preserve Exif metadata for JPEG image e.g., Camera model, Focal length, etc (default: false)
signal: AbortSignal, // optional, to abort / cancel the compression
// following options are for advanced users
maxIteration: number, // optional, max number of iteration to compress the image (default: 10)
exifOrientation: number, // optional, see https://stackoverflow.com/a/32490603/10395024
fileType: string, // optional, fileType override e.g., 'image/jpeg', 'image/png' (default: file.type)
initialQuality: number, // optional, initial quality value between 0 and 1 (default: 1)
alwaysKeepResolution: boolean // optional, only reduce quality, always keep width and height (default: false)
}
imageCompression(file: File, options: Options): Promise<File>
```
#### Caveat
Each browser limits [the maximum size](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas#maximum_canvas_size) of a browser Canvas object. <br/>
So, we resize the image to less than the maximum size that each browser restricts. <br/>
(However, the `proportion/ratio` of the image remains.)
#### Abort / Cancel Compression
To use this feature, please check the browser compatibility: https://caniuse.com/?search=AbortController
```javascript
function handleImageUpload(event) {
var imageFile = event.target.files[0];
var controller = new AbortController();
var options = {
// other options here
signal: controller.signal,
}
imageCompression(imageFile, options)
.then(function (compressedFile) {
return uploadToServer(compressedFile); // write your own logic
})
.catch(function (error) {
console.log(error.message); // output: I just want to stop
});
// simulate abort the compression after 1.5 seconds
setTimeout(function () {
controller.abort(new Error('I just want to stop'));
}, 1500);
}
```
### Helper function
- for advanced users only, most users won't need to use the helper functions
```javascript
imageCompression.getDataUrlFromFile(file: File): Promise<base64 encoded string>
imageCompression.getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise<File>
imageCompression.loadImage(url: string): Promise<HTMLImageElement>
imageCompression.drawImageInCanvas(img: HTMLImageElement, fileType?: string): HTMLCanvasElement | OffscreenCanvas
imageCompression.drawFileInCanvas(file: File, options?: Options): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement | OffscreenCanvas]>
imageCompression.canvasToFile(canvas: HTMLCanvasElement | OffscreenCanvas, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise<File>
imageCompression.getExifOrientation(file: File): Promise<number> // based on https://stackoverflow.com/a/32490603/10395024
imageCompression.copyExifWithoutOrientation(copyExifFromFile: File, copyExifToFile: File): Promise<File> // based on https://gist.github.com/tonytonyjan/ffb7cd0e82cb293b843ece7e79364233
```
## Browsers support
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>IE / Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari-ios/safari-ios_48x48.png" alt="iOS Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>iOS Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png" alt="Opera" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Opera |
| --------- | --------- | --------- | --------- | --------- | --------- |
| IE10, IE11, Edge| last 2 versions| last 2 versions| last 2 versions| last 2 versions| last 2 versions
### IE support
This library uses ES features such as Promise API, globalThis. If you need to support browsers that do not support new ES features like IE. You can include the core-js polyfill in your project.
You can include the following script to load the core-js polyfill:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/3.21.1/minified.min.js"></script>
```
### Webp support
The webp compression is supported on major browsers. Please see https://caniuse.com/mdn-api_offscreencanvas_converttoblob_option_type_parameter_webp for browser compatibility.
## Remarks for compression to work in Web Worker
The browser needs to support "OffscreenCanvas" API in order to take advantage of non-blocking compression. If the browser does not support "OffscreenCanvas" API, the main thread is used instead. See https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas#browser_compatibility for browser compatibility of "OffscreenCanvas" API.
## Typescript type definitions
Typescript definitions are included in the package & referenced in the `types` section of the `package.json`
## Remarks on Content Security Policy (CSP)
If your website has CSP enabled and you want to use Web Worker (useWebWorker: true), please add the following to the response header
`content-security-policy: script-src 'self' blob: https://cdn.jsdelivr.net`
- `blob:` is for loading Web Worker script
- `https://cdn.jsdelivr.net` is for importing this library from CDN inside Web Worker script. If you don't want to load this library from CDN, you can set your self hosted library URL in `options.libURL`.
## Contribution
1. fork the repo and git clone it
2. run `npm run watch` # it will watch code change in lib/ folder and generate js in dist/ folder
3. add/update code in lib/ folder
4. try the code by opening example/development.html which will load the js in dist/ folder
5. add/update test in test/ folder
6. `npm run test`
7. push to your forked repo on github
8. make a pull request to dev branch of this repo
[dist]: https://github.com/Donaldcwl/browser-image-compression/tree/master/dist
[example]: https://github.com/Donaldcwl/browser-image-compression/tree/master/example
[delivrjs]: https://cdn.jsdelivr.net/
@@ -0,0 +1,46 @@
// Type definitions for browser-image-compression 2.0
// Project: https://github.com/Donaldcwl/browser-image-compression
// Definitions by: Donald <https://github.com/Donaldcwl> & Jamie Haywood <https://github.com/jamiehaywood>
export interface Options {
/** @default Number.POSITIVE_INFINITY */
maxSizeMB?: number;
/** @default undefined */
maxWidthOrHeight?: number;
/** @default true */
useWebWorker?: boolean;
/** @default 10 */
maxIteration?: number;
/** Default to be the exif orientation from the image file */
exifOrientation?: number;
/** A function takes one progress argument (progress from 0 to 100) */
onProgress?: (progress: number) => void;
/** Default to be the original mime type from the image file */
fileType?: string;
/** @default 1.0 */
initialQuality?: number;
/** @default false */
alwaysKeepResolution?: boolean;
/** @default undefined */
signal?: AbortSignal;
/** @default false */
preserveExif?: boolean;
/** @default https://cdn.jsdelivr.net/npm/browser-image-compression/dist/browser-image-compression.js */
libURL?: string;
}
declare function imageCompression(image: File, options: Options): Promise<File>;
declare namespace imageCompression {
function getDataUrlFromFile(file: File): Promise<string>;
function getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise<File>;
function loadImage(src: string): Promise<HTMLImageElement>;
function drawImageInCanvas(img: HTMLImageElement, fileType?: string): HTMLCanvasElement;
function drawFileInCanvas(file: File, options?: Options): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement]>;
function canvasToFile(canvas: HTMLCanvasElement, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise<File>;
function getExifOrientation(file: File): Promise<number>;
}
export as namespace imageCompression;
export default imageCompression;
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,79 @@
{
"name": "browser-image-compression",
"version": "2.0.2",
"description": "Compress images in the browser",
"main": "dist/browser-image-compression.js",
"module": "dist/browser-image-compression.mjs",
"jsnext:main": "dist/browser-image-compression.mjs",
"types": "dist/browser-image-compression.d.ts",
"scripts": {
"eslint": "eslint lib test --fix",
"build": "rollup -c --environment BUILD:production --bundleConfigAsCjs",
"watch": "rollup -c -w --environment BUILD:development --bundleConfigAsCjs",
"dev": "npm run watch",
"test": "cross-env NODE_ENV=test nyc mocha",
"posttest": "npm run coverage-badges",
"test:watch": "cross-env NODE_ENV=test nyc mocha -w",
"prepublishOnly": "npm test && npm run build",
"coverage-badges": "make-coverage-badge",
"commit": "cz"
},
"homepage": "https://github.com/Donaldcwl/browser-image-compression#readme",
"repository": {
"type": "git",
"url": "https://github.com/Donaldcwl/browser-image-compression"
},
"bugs": {
"url": "https://github.com/Donaldcwl/browser-image-compression/issues"
},
"keywords": [
"image compression",
"browser",
"image processing",
"reduce resolution",
"reduce size"
],
"author": "Donald <donaldcwl@gmail.com>",
"license": "MIT",
"files": [
"dist"
],
"dependencies": {
"uzip": "0.20201231.0"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.3.1",
"@babel/register": "^7.0.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
"babel-plugin-istanbul": "^6.0.0",
"canvas": "2.6.1",
"chai": "^4.1.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.2",
"cz-conventional-changelog": "3.3.0",
"eslint": "^8.34.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.22.1",
"istanbul": "^0.4.5",
"jsdom": "^21.1.0",
"make-coverage-badge": "^1.0.1",
"mocha": "^10.2.0",
"nyc": "^15.0.1",
"rollup": "^3.15.0",
"rollup-plugin-copy": "^3.3.0",
"rollup-plugin-license": "^3.0.1",
"rollup-plugin-nodent": "^0.2.2",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^5.6.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
+1
View File
@@ -0,0 +1 @@
../../uzip@0.20201231.0/node_modules/uzip
@@ -0,0 +1,58 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
# [2.1.0](https://github.com/niklasvh/css-line-break/compare/v2.0.1...v2.1.0) (2022-01-22)
### feat
* update to use utrie dep (#20) ([18adab4](https://github.com/niklasvh/css-line-break/commit/18adab4010b54bb73add4f23c3325b27c2c13d91)), closes [#20](https://github.com/niklasvh/css-line-break/issues/20)
### fix
* source maps (#19) ([60cdede](https://github.com/niklasvh/css-line-break/commit/60cdedeaa025f685fc7002653f390233becce128)), closes [#19](https://github.com/niklasvh/css-line-break/issues/19)
## [2.0.1](https://github.com/niklasvh/css-line-break/compare/v2.0.0...v2.0.1) (2021-08-04)
### fix
* wordBreak break-word (#17) ([d615f1f](https://github.com/niklasvh/css-line-break/commit/d615f1f731c9074035d0dab843a17a64080ba7ba)), closes [#17](https://github.com/niklasvh/css-line-break/issues/17)
# [2.0.0](https://github.com/niklasvh/css-line-break/compare/v1.1.3-0...v2.0.0) (2021-08-02)
### fix
* zwj emojis #2 (#16) ([a314ea3](https://github.com/niklasvh/css-line-break/commit/a314ea33768cde9dab4e673d3339d6b4f9c32196)), closes [#2](https://github.com/niklasvh/css-line-break/issues/2) [#16](https://github.com/niklasvh/css-line-break/issues/16)
## [1.1.3-0](https://github.com/niklasvh/css-line-break/compare/v1.1.2-0...v1.1.3-0) (2021-07-15)
### deps
* update deps (#14) ([330cb73](https://github.com/niklasvh/css-line-break/commit/330cb734f635d4d5e0d61ea991651d6d49b03054)), closes [#14](https://github.com/niklasvh/css-line-break/issues/14)
### docs
* fix readme (#13) ([1f4a330](https://github.com/niklasvh/css-line-break/commit/1f4a3300752c8bbf5a0138c7924b231161f1e4ac)), closes [#13](https://github.com/niklasvh/css-line-break/issues/13) [#10](https://github.com/niklasvh/css-line-break/issues/10)
### feat
* implement line-break.txt v13 (#15) ([bc95c80](https://github.com/niklasvh/css-line-break/commit/bc95c809e12613a9531b7985450c6bc96717e8de)), closes [#15](https://github.com/niklasvh/css-line-break/issues/15)
## [1.1.2-0](https://github.com/niklasvh/css-line-break/compare/v1.1.1...v1.1.2-0) (2021-07-04)
### ci
* update to use github actions (#12) ([7aed118](https://github.com/niklasvh/css-line-break/commit/7aed11880975b6faf6e46caed93b6d225babd943)), closes [#12](https://github.com/niklasvh/css-line-break/issues/12)
@@ -0,0 +1,22 @@
Copyright (c) 2017 Niklas von Hertzen
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
css-line-break
==============
![CI](https://github.com/niklasvh/css-line-break/workflows/CI/badge.svg?branch=master)
[![NPM Downloads](https://img.shields.io/npm/dm/css-line-break.svg)](https://www.npmjs.org/package/css-line-break)
[![NPM Version](https://img.shields.io/npm/v/css-line-break.svg)](https://www.npmjs.org/package/css-line-break)
A JavaScript library for Line Breaking and identifying Word Boundaries,
[implementing the Unicode Line Breaking Algorithm (UAX #14)](http://unicode.org/reports/tr14/)
>> Line breaking, also known as word wrapping, is the process of breaking a section of text into
lines such that it will fit in the available width of a page, window or other display area.
The Unicode Line Breaking Algorithm performs part of this process. Given an input text,
it produces a set of positions called "break opportunities" that are appropriate points to
begin a new line. The selection of actual line break positions from the set of break opportunities
is not covered by the Unicode Line Breaking Algorithm, but is in the domain of higher level
software with knowledge of the available width and the display size of the text.
In addition, the module implements CSS specific tailoring options to line breaking as
defined in [CSS Text Module Level 3](https://www.w3.org/TR/css-text-3/#line-breaking).
### Installing
You can install the module via npm:
npm install css-line-break
### Usage
The `LineBreaker` creates an [iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators) that returns `Break`s for a given text.
LineBreaker(text, [options]);
### Example
[JSFiddle](https://jsfiddle.net/ofd3752k)
```javascript
import {LineBreaker} from 'css-line-break';
const breaker = LineBreaker('Lorem ipsum lol.', {
lineBreak: 'strict',
wordBreak: 'normal'
});
const words = [];
let bk;
while (!(bk = breaker.next()).done) {
words.push(bk.value.slice());
}
assert.deepEqual(words, ['Lorem ', 'ipsum ', 'lol.']);
```
### Options
The following parameters are available for the options:
- `lineBreak`: `normal` | `strict`
- `wordBreak`: `normal` | `break-all` | `break-word` | `keep-all`
For more information how they affect the line breaking algorithms,
check out [CSS Text Module Level 3](https://www.w3.org/TR/css-text-3/#line-breaking).
### Testing
You can run the test suite with:
npm test
The library implements all the [LineBreakTest.txt tests](http://www.unicode.org/Public/10.0.0/ucd/auxiliary/LineBreakTest.txt)
and a number of CSS web-platform-tests.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,516 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.LineBreaker = exports.inlineBreakOpportunities = exports.lineBreakAtIndex = exports.codePointsToCharacterClasses = exports.UnicodeTrie = exports.BREAK_ALLOWED = exports.BREAK_NOT_ALLOWED = exports.BREAK_MANDATORY = exports.classes = exports.LETTER_NUMBER_MODIFIER = void 0;
var utrie_1 = require("utrie");
var linebreak_trie_1 = require("./linebreak-trie");
var Util_1 = require("./Util");
exports.LETTER_NUMBER_MODIFIER = 50;
// Non-tailorable Line Breaking Classes
var BK = 1; // Cause a line break (after)
var CR = 2; // Cause a line break (after), except between CR and LF
var LF = 3; // Cause a line break (after)
var CM = 4; // Prohibit a line break between the character and the preceding character
var NL = 5; // Cause a line break (after)
var SG = 6; // Do not occur in well-formed text
var WJ = 7; // Prohibit line breaks before and after
var ZW = 8; // Provide a break opportunity
var GL = 9; // Prohibit line breaks before and after
var SP = 10; // Enable indirect line breaks
var ZWJ = 11; // Prohibit line breaks within joiner sequences
// Break Opportunities
var B2 = 12; // Provide a line break opportunity before and after the character
var BA = 13; // Generally provide a line break opportunity after the character
var BB = 14; // Generally provide a line break opportunity before the character
var HY = 15; // Provide a line break opportunity after the character, except in numeric context
var CB = 16; // Provide a line break opportunity contingent on additional information
// Characters Prohibiting Certain Breaks
var CL = 17; // Prohibit line breaks before
var CP = 18; // Prohibit line breaks before
var EX = 19; // Prohibit line breaks before
var IN = 20; // Allow only indirect line breaks between pairs
var NS = 21; // Allow only indirect line breaks before
var OP = 22; // Prohibit line breaks after
var QU = 23; // Act like they are both opening and closing
// Numeric Context
var IS = 24; // Prevent breaks after any and before numeric
var NU = 25; // Form numeric expressions for line breaking purposes
var PO = 26; // Do not break following a numeric expression
var PR = 27; // Do not break in front of a numeric expression
var SY = 28; // Prevent a break before; and allow a break after
// Other Characters
var AI = 29; // Act like AL when the resolvedEAW is N; otherwise; act as ID
var AL = 30; // Are alphabetic characters or symbols that are used with alphabetic characters
var CJ = 31; // Treat as NS or ID for strict or normal breaking.
var EB = 32; // Do not break from following Emoji Modifier
var EM = 33; // Do not break from preceding Emoji Base
var H2 = 34; // Form Korean syllable blocks
var H3 = 35; // Form Korean syllable blocks
var HL = 36; // Do not break around a following hyphen; otherwise act as Alphabetic
var ID = 37; // Break before or after; except in some numeric context
var JL = 38; // Form Korean syllable blocks
var JV = 39; // Form Korean syllable blocks
var JT = 40; // Form Korean syllable blocks
var RI = 41; // Keep pairs together. For pairs; break before and after other classes
var SA = 42; // Provide a line break opportunity contingent on additional, language-specific context analysis
var XX = 43; // Have as yet unknown line breaking behavior or unassigned code positions
var ea_OP = [0x2329, 0xff08];
exports.classes = {
BK: BK,
CR: CR,
LF: LF,
CM: CM,
NL: NL,
SG: SG,
WJ: WJ,
ZW: ZW,
GL: GL,
SP: SP,
ZWJ: ZWJ,
B2: B2,
BA: BA,
BB: BB,
HY: HY,
CB: CB,
CL: CL,
CP: CP,
EX: EX,
IN: IN,
NS: NS,
OP: OP,
QU: QU,
IS: IS,
NU: NU,
PO: PO,
PR: PR,
SY: SY,
AI: AI,
AL: AL,
CJ: CJ,
EB: EB,
EM: EM,
H2: H2,
H3: H3,
HL: HL,
ID: ID,
JL: JL,
JV: JV,
JT: JT,
RI: RI,
SA: SA,
XX: XX,
};
exports.BREAK_MANDATORY = '!';
exports.BREAK_NOT_ALLOWED = '×';
exports.BREAK_ALLOWED = '÷';
exports.UnicodeTrie = utrie_1.createTrieFromBase64(linebreak_trie_1.base64, linebreak_trie_1.byteLength);
var ALPHABETICS = [AL, HL];
var HARD_LINE_BREAKS = [BK, CR, LF, NL];
var SPACE = [SP, ZW];
var PREFIX_POSTFIX = [PR, PO];
var LINE_BREAKS = HARD_LINE_BREAKS.concat(SPACE);
var KOREAN_SYLLABLE_BLOCK = [JL, JV, JT, H2, H3];
var HYPHEN = [HY, BA];
var codePointsToCharacterClasses = function (codePoints, lineBreak) {
if (lineBreak === void 0) { lineBreak = 'strict'; }
var types = [];
var indices = [];
var categories = [];
codePoints.forEach(function (codePoint, index) {
var classType = exports.UnicodeTrie.get(codePoint);
if (classType > exports.LETTER_NUMBER_MODIFIER) {
categories.push(true);
classType -= exports.LETTER_NUMBER_MODIFIER;
}
else {
categories.push(false);
}
if (['normal', 'auto', 'loose'].indexOf(lineBreak) !== -1) {
// U+2010, U+2013, 〜 U+301C, U+30A0
if ([0x2010, 0x2013, 0x301c, 0x30a0].indexOf(codePoint) !== -1) {
indices.push(index);
return types.push(CB);
}
}
if (classType === CM || classType === ZWJ) {
// LB10 Treat any remaining combining mark or ZWJ as AL.
if (index === 0) {
indices.push(index);
return types.push(AL);
}
// LB9 Do not break a combining character sequence; treat it as if it has the line breaking class of
// the base character in all of the following rules. Treat ZWJ as if it were CM.
var prev = types[index - 1];
if (LINE_BREAKS.indexOf(prev) === -1) {
indices.push(indices[index - 1]);
return types.push(prev);
}
indices.push(index);
return types.push(AL);
}
indices.push(index);
if (classType === CJ) {
return types.push(lineBreak === 'strict' ? NS : ID);
}
if (classType === SA) {
return types.push(AL);
}
if (classType === AI) {
return types.push(AL);
}
// For supplementary characters, a useful default is to treat characters in the range 10000..1FFFD as AL
// and characters in the ranges 20000..2FFFD and 30000..3FFFD as ID, until the implementation can be revised
// to take into account the actual line breaking properties for these characters.
if (classType === XX) {
if ((codePoint >= 0x20000 && codePoint <= 0x2fffd) || (codePoint >= 0x30000 && codePoint <= 0x3fffd)) {
return types.push(ID);
}
else {
return types.push(AL);
}
}
types.push(classType);
});
return [indices, types, categories];
};
exports.codePointsToCharacterClasses = codePointsToCharacterClasses;
var isAdjacentWithSpaceIgnored = function (a, b, currentIndex, classTypes) {
var current = classTypes[currentIndex];
if (Array.isArray(a) ? a.indexOf(current) !== -1 : a === current) {
var i = currentIndex;
while (i <= classTypes.length) {
i++;
var next = classTypes[i];
if (next === b) {
return true;
}
if (next !== SP) {
break;
}
}
}
if (current === SP) {
var i = currentIndex;
while (i > 0) {
i--;
var prev = classTypes[i];
if (Array.isArray(a) ? a.indexOf(prev) !== -1 : a === prev) {
var n = currentIndex;
while (n <= classTypes.length) {
n++;
var next = classTypes[n];
if (next === b) {
return true;
}
if (next !== SP) {
break;
}
}
}
if (prev !== SP) {
break;
}
}
}
return false;
};
var previousNonSpaceClassType = function (currentIndex, classTypes) {
var i = currentIndex;
while (i >= 0) {
var type = classTypes[i];
if (type === SP) {
i--;
}
else {
return type;
}
}
return 0;
};
var _lineBreakAtIndex = function (codePoints, classTypes, indicies, index, forbiddenBreaks) {
if (indicies[index] === 0) {
return exports.BREAK_NOT_ALLOWED;
}
var currentIndex = index - 1;
if (Array.isArray(forbiddenBreaks) && forbiddenBreaks[currentIndex] === true) {
return exports.BREAK_NOT_ALLOWED;
}
var beforeIndex = currentIndex - 1;
var afterIndex = currentIndex + 1;
var current = classTypes[currentIndex];
// LB4 Always break after hard line breaks.
// LB5 Treat CR followed by LF, as well as CR, LF, and NL as hard line breaks.
var before = beforeIndex >= 0 ? classTypes[beforeIndex] : 0;
var next = classTypes[afterIndex];
if (current === CR && next === LF) {
return exports.BREAK_NOT_ALLOWED;
}
if (HARD_LINE_BREAKS.indexOf(current) !== -1) {
return exports.BREAK_MANDATORY;
}
// LB6 Do not break before hard line breaks.
if (HARD_LINE_BREAKS.indexOf(next) !== -1) {
return exports.BREAK_NOT_ALLOWED;
}
// LB7 Do not break before spaces or zero width space.
if (SPACE.indexOf(next) !== -1) {
return exports.BREAK_NOT_ALLOWED;
}
// LB8 Break before any character following a zero-width space, even if one or more spaces intervene.
if (previousNonSpaceClassType(currentIndex, classTypes) === ZW) {
return exports.BREAK_ALLOWED;
}
// LB8a Do not break after a zero width joiner.
if (exports.UnicodeTrie.get(codePoints[currentIndex]) === ZWJ) {
return exports.BREAK_NOT_ALLOWED;
}
// zwj emojis
if ((current === EB || current === EM) && exports.UnicodeTrie.get(codePoints[afterIndex]) === ZWJ) {
return exports.BREAK_NOT_ALLOWED;
}
// LB11 Do not break before or after Word joiner and related characters.
if (current === WJ || next === WJ) {
return exports.BREAK_NOT_ALLOWED;
}
// LB12 Do not break after NBSP and related characters.
if (current === GL) {
return exports.BREAK_NOT_ALLOWED;
}
// LB12a Do not break before NBSP and related characters, except after spaces and hyphens.
if ([SP, BA, HY].indexOf(current) === -1 && next === GL) {
return exports.BREAK_NOT_ALLOWED;
}
// LB13 Do not break before ] or ! or ; or /, even after spaces.
if ([CL, CP, EX, IS, SY].indexOf(next) !== -1) {
return exports.BREAK_NOT_ALLOWED;
}
// LB14 Do not break after [, even after spaces.
if (previousNonSpaceClassType(currentIndex, classTypes) === OP) {
return exports.BREAK_NOT_ALLOWED;
}
// LB15 Do not break within ‘”[, even with intervening spaces.
if (isAdjacentWithSpaceIgnored(QU, OP, currentIndex, classTypes)) {
return exports.BREAK_NOT_ALLOWED;
}
// LB16 Do not break between closing punctuation and a nonstarter (lb=NS), even with intervening spaces.
if (isAdjacentWithSpaceIgnored([CL, CP], NS, currentIndex, classTypes)) {
return exports.BREAK_NOT_ALLOWED;
}
// LB17 Do not break within ‘——’, even with intervening spaces.
if (isAdjacentWithSpaceIgnored(B2, B2, currentIndex, classTypes)) {
return exports.BREAK_NOT_ALLOWED;
}
// LB18 Break after spaces.
if (current === SP) {
return exports.BREAK_ALLOWED;
}
// LB19 Do not break before or after quotation marks, such as .
if (current === QU || next === QU) {
return exports.BREAK_NOT_ALLOWED;
}
// LB20 Break before and after unresolved CB.
if (next === CB || current === CB) {
return exports.BREAK_ALLOWED;
}
// LB21 Do not break before hyphen-minus, other hyphens, fixed-width spaces, small kana, and other non-starters, or after acute accents.
if ([BA, HY, NS].indexOf(next) !== -1 || current === BB) {
return exports.BREAK_NOT_ALLOWED;
}
// LB21a Don't break after Hebrew + Hyphen.
if (before === HL && HYPHEN.indexOf(current) !== -1) {
return exports.BREAK_NOT_ALLOWED;
}
// LB21b Dont break between Solidus and Hebrew letters.
if (current === SY && next === HL) {
return exports.BREAK_NOT_ALLOWED;
}
// LB22 Do not break before ellipsis.
if (next === IN) {
return exports.BREAK_NOT_ALLOWED;
}
// LB23 Do not break between digits and letters.
if ((ALPHABETICS.indexOf(next) !== -1 && current === NU) || (ALPHABETICS.indexOf(current) !== -1 && next === NU)) {
return exports.BREAK_NOT_ALLOWED;
}
// LB23a Do not break between numeric prefixes and ideographs, or between ideographs and numeric postfixes.
if ((current === PR && [ID, EB, EM].indexOf(next) !== -1) ||
([ID, EB, EM].indexOf(current) !== -1 && next === PO)) {
return exports.BREAK_NOT_ALLOWED;
}
// LB24 Do not break between numeric prefix/postfix and letters, or between letters and prefix/postfix.
if ((ALPHABETICS.indexOf(current) !== -1 && PREFIX_POSTFIX.indexOf(next) !== -1) ||
(PREFIX_POSTFIX.indexOf(current) !== -1 && ALPHABETICS.indexOf(next) !== -1)) {
return exports.BREAK_NOT_ALLOWED;
}
// LB25 Do not break between the following pairs of classes relevant to numbers:
if (
// (PR | PO) × ( OP | HY )? NU
([PR, PO].indexOf(current) !== -1 &&
(next === NU || ([OP, HY].indexOf(next) !== -1 && classTypes[afterIndex + 1] === NU))) ||
// ( OP | HY ) × NU
([OP, HY].indexOf(current) !== -1 && next === NU) ||
// NU × (NU | SY | IS)
(current === NU && [NU, SY, IS].indexOf(next) !== -1)) {
return exports.BREAK_NOT_ALLOWED;
}
// NU (NU | SY | IS)* × (NU | SY | IS | CL | CP)
if ([NU, SY, IS, CL, CP].indexOf(next) !== -1) {
var prevIndex = currentIndex;
while (prevIndex >= 0) {
var type = classTypes[prevIndex];
if (type === NU) {
return exports.BREAK_NOT_ALLOWED;
}
else if ([SY, IS].indexOf(type) !== -1) {
prevIndex--;
}
else {
break;
}
}
}
// NU (NU | SY | IS)* (CL | CP)? × (PO | PR))
if ([PR, PO].indexOf(next) !== -1) {
var prevIndex = [CL, CP].indexOf(current) !== -1 ? beforeIndex : currentIndex;
while (prevIndex >= 0) {
var type = classTypes[prevIndex];
if (type === NU) {
return exports.BREAK_NOT_ALLOWED;
}
else if ([SY, IS].indexOf(type) !== -1) {
prevIndex--;
}
else {
break;
}
}
}
// LB26 Do not break a Korean syllable.
if ((JL === current && [JL, JV, H2, H3].indexOf(next) !== -1) ||
([JV, H2].indexOf(current) !== -1 && [JV, JT].indexOf(next) !== -1) ||
([JT, H3].indexOf(current) !== -1 && next === JT)) {
return exports.BREAK_NOT_ALLOWED;
}
// LB27 Treat a Korean Syllable Block the same as ID.
if ((KOREAN_SYLLABLE_BLOCK.indexOf(current) !== -1 && [IN, PO].indexOf(next) !== -1) ||
(KOREAN_SYLLABLE_BLOCK.indexOf(next) !== -1 && current === PR)) {
return exports.BREAK_NOT_ALLOWED;
}
// LB28 Do not break between alphabetics (“at”).
if (ALPHABETICS.indexOf(current) !== -1 && ALPHABETICS.indexOf(next) !== -1) {
return exports.BREAK_NOT_ALLOWED;
}
// LB29 Do not break between numeric punctuation and alphabetics (“e.g.”).
if (current === IS && ALPHABETICS.indexOf(next) !== -1) {
return exports.BREAK_NOT_ALLOWED;
}
// LB30 Do not break between letters, numbers, or ordinary symbols and opening or closing parentheses.
if ((ALPHABETICS.concat(NU).indexOf(current) !== -1 &&
next === OP &&
ea_OP.indexOf(codePoints[afterIndex]) === -1) ||
(ALPHABETICS.concat(NU).indexOf(next) !== -1 && current === CP)) {
return exports.BREAK_NOT_ALLOWED;
}
// LB30a Break between two regional indicator symbols if and only if there are an even number of regional
// indicators preceding the position of the break.
if (current === RI && next === RI) {
var i = indicies[currentIndex];
var count = 1;
while (i > 0) {
i--;
if (classTypes[i] === RI) {
count++;
}
else {
break;
}
}
if (count % 2 !== 0) {
return exports.BREAK_NOT_ALLOWED;
}
}
// LB30b Do not break between an emoji base and an emoji modifier.
if (current === EB && next === EM) {
return exports.BREAK_NOT_ALLOWED;
}
return exports.BREAK_ALLOWED;
};
var lineBreakAtIndex = function (codePoints, index) {
// LB2 Never break at the start of text.
if (index === 0) {
return exports.BREAK_NOT_ALLOWED;
}
// LB3 Always break at the end of text.
if (index >= codePoints.length) {
return exports.BREAK_MANDATORY;
}
var _a = exports.codePointsToCharacterClasses(codePoints), indices = _a[0], classTypes = _a[1];
return _lineBreakAtIndex(codePoints, classTypes, indices, index);
};
exports.lineBreakAtIndex = lineBreakAtIndex;
var cssFormattedClasses = function (codePoints, options) {
if (!options) {
options = { lineBreak: 'normal', wordBreak: 'normal' };
}
var _a = exports.codePointsToCharacterClasses(codePoints, options.lineBreak), indicies = _a[0], classTypes = _a[1], isLetterNumber = _a[2];
if (options.wordBreak === 'break-all' || options.wordBreak === 'break-word') {
classTypes = classTypes.map(function (type) { return ([NU, AL, SA].indexOf(type) !== -1 ? ID : type); });
}
var forbiddenBreakpoints = options.wordBreak === 'keep-all'
? isLetterNumber.map(function (letterNumber, i) {
return letterNumber && codePoints[i] >= 0x4e00 && codePoints[i] <= 0x9fff;
})
: undefined;
return [indicies, classTypes, forbiddenBreakpoints];
};
var inlineBreakOpportunities = function (str, options) {
var codePoints = Util_1.toCodePoints(str);
var output = exports.BREAK_NOT_ALLOWED;
var _a = cssFormattedClasses(codePoints, options), indicies = _a[0], classTypes = _a[1], forbiddenBreakpoints = _a[2];
codePoints.forEach(function (codePoint, i) {
output +=
Util_1.fromCodePoint(codePoint) +
(i >= codePoints.length - 1
? exports.BREAK_MANDATORY
: _lineBreakAtIndex(codePoints, classTypes, indicies, i + 1, forbiddenBreakpoints));
});
return output;
};
exports.inlineBreakOpportunities = inlineBreakOpportunities;
var Break = /** @class */ (function () {
function Break(codePoints, lineBreak, start, end) {
this.codePoints = codePoints;
this.required = lineBreak === exports.BREAK_MANDATORY;
this.start = start;
this.end = end;
}
Break.prototype.slice = function () {
return Util_1.fromCodePoint.apply(void 0, this.codePoints.slice(this.start, this.end));
};
return Break;
}());
var LineBreaker = function (str, options) {
var codePoints = Util_1.toCodePoints(str);
var _a = cssFormattedClasses(codePoints, options), indicies = _a[0], classTypes = _a[1], forbiddenBreakpoints = _a[2];
var length = codePoints.length;
var lastEnd = 0;
var nextIndex = 0;
return {
next: function () {
if (nextIndex >= length) {
return { done: true, value: null };
}
var lineBreak = exports.BREAK_NOT_ALLOWED;
while (nextIndex < length &&
(lineBreak = _lineBreakAtIndex(codePoints, classTypes, indicies, ++nextIndex, forbiddenBreakpoints)) ===
exports.BREAK_NOT_ALLOWED) { }
if (lineBreak !== exports.BREAK_NOT_ALLOWED || nextIndex === length) {
var value = new Break(codePoints, lineBreak, lastEnd, nextIndex);
lastEnd = nextIndex;
return { value: value, done: false };
}
return { done: true, value: null };
},
};
};
exports.LineBreaker = LineBreaker;
//# sourceMappingURL=LineBreak.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,109 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.polyUint32Array = exports.polyUint16Array = exports.decode = exports.fromCodePoint = exports.toCodePoints = void 0;
var toCodePoints = function (str) {
var codePoints = [];
var i = 0;
var length = str.length;
while (i < length) {
var value = str.charCodeAt(i++);
if (value >= 0xd800 && value <= 0xdbff && i < length) {
var extra = str.charCodeAt(i++);
if ((extra & 0xfc00) === 0xdc00) {
codePoints.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);
}
else {
codePoints.push(value);
i--;
}
}
else {
codePoints.push(value);
}
}
return codePoints;
};
exports.toCodePoints = toCodePoints;
var fromCodePoint = function () {
var codePoints = [];
for (var _i = 0; _i < arguments.length; _i++) {
codePoints[_i] = arguments[_i];
}
if (String.fromCodePoint) {
return String.fromCodePoint.apply(String, codePoints);
}
var length = codePoints.length;
if (!length) {
return '';
}
var codeUnits = [];
var index = -1;
var result = '';
while (++index < length) {
var codePoint = codePoints[index];
if (codePoint <= 0xffff) {
codeUnits.push(codePoint);
}
else {
codePoint -= 0x10000;
codeUnits.push((codePoint >> 10) + 0xd800, (codePoint % 0x400) + 0xdc00);
}
if (index + 1 === length || codeUnits.length > 0x4000) {
result += String.fromCharCode.apply(String, codeUnits);
codeUnits.length = 0;
}
}
return result;
};
exports.fromCodePoint = fromCodePoint;
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
var decode = function (base64) {
var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var buffer = typeof ArrayBuffer !== 'undefined' &&
typeof Uint8Array !== 'undefined' &&
typeof Uint8Array.prototype.slice !== 'undefined'
? new ArrayBuffer(bufferLength)
: new Array(bufferLength);
var bytes = Array.isArray(buffer) ? buffer : new Uint8Array(buffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return buffer;
};
exports.decode = decode;
var polyUint16Array = function (buffer) {
var length = buffer.length;
var bytes = [];
for (var i = 0; i < length; i += 2) {
bytes.push((buffer[i + 1] << 8) | buffer[i]);
}
return bytes;
};
exports.polyUint16Array = polyUint16Array;
var polyUint32Array = function (buffer) {
var length = buffer.length;
var bytes = [];
for (var i = 0; i < length; i += 4) {
bytes.push((buffer[i + 3] << 24) | (buffer[i + 2] << 16) | (buffer[i + 1] << 8) | buffer[i]);
}
return bytes;
};
exports.polyUint32Array = polyUint32Array;
//# sourceMappingURL=Util.js.map
@@ -0,0 +1 @@
{"version":3,"file":"Util.js","sourceRoot":"","sources":["../../src/Util.ts"],"names":[],"mappings":";;;AAAO,IAAM,YAAY,GAAG,UAAC,GAAW;IACpC,IAAM,UAAU,GAAG,EAAE,CAAC;IACtB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,OAAO,CAAC,GAAG,MAAM,EAAE;QACf,IAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;QAClC,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,IAAI,CAAC,GAAG,MAAM,EAAE;YAClD,IAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;YAClC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,MAAM,EAAE;gBAC7B,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC;aACxE;iBAAM;gBACH,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC,EAAE,CAAC;aACP;SACJ;aAAM;YACH,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC1B;KACJ;IACD,OAAO,UAAU,CAAC;AACtB,CAAC,CAAC;AAnBW,QAAA,YAAY,gBAmBvB;AAEK,IAAM,aAAa,GAAG;IAAC,oBAAuB;SAAvB,UAAuB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AM,EAAE,CAAC,IAAI,CAAC,EAAE;QAChC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;KAChG;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAPW,QAAA,eAAe,mBAO1B"}
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LineBreaker = exports.fromCodePoint = exports.toCodePoints = void 0;
var Util_1 = require("./Util");
Object.defineProperty(exports, "toCodePoints", { enumerable: true, get: function () { return Util_1.toCodePoints; } });
Object.defineProperty(exports, "fromCodePoint", { enumerable: true, get: function () { return Util_1.fromCodePoint; } });
var LineBreak_1 = require("./LineBreak");
Object.defineProperty(exports, "LineBreaker", { enumerable: true, get: function () { return LineBreak_1.LineBreaker; } });
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,+BAAmD;AAA3C,oGAAA,YAAY,OAAA;AAAE,qGAAA,aAAa,OAAA;AACnC,yCAAwC;AAAhC,wGAAA,WAAW,OAAA"}
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
{"version":3,"file":"linebreak-trie.js","sourceRoot":"","sources":["../../src/linebreak-trie.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GACf,0pnDAA0pnD,CAAC;AAClpnD,QAAA,UAAU,GAAG,KAAK,CAAC"}
@@ -0,0 +1,38 @@
export declare const LETTER_NUMBER_MODIFIER = 50;
export declare const classes: {
[key: string]: number;
};
export declare const BREAK_MANDATORY = "!";
export declare const BREAK_NOT_ALLOWED = "\u00D7";
export declare const BREAK_ALLOWED = "\u00F7";
export declare const UnicodeTrie: import("utrie").Trie;
export declare const codePointsToCharacterClasses: (codePoints: number[], lineBreak?: string) => [number[], number[], boolean[]];
export declare type BREAK_OPPORTUNITIES = typeof BREAK_NOT_ALLOWED | typeof BREAK_ALLOWED | typeof BREAK_MANDATORY;
export declare const lineBreakAtIndex: (codePoints: number[], index: number) => BREAK_OPPORTUNITIES;
export declare type LINE_BREAK = 'auto' | 'normal' | 'strict';
export declare type WORD_BREAK = 'normal' | 'break-all' | 'break-word' | 'keep-all';
interface IOptions {
lineBreak?: LINE_BREAK;
wordBreak?: WORD_BREAK;
}
export declare const inlineBreakOpportunities: (str: string, options?: IOptions | undefined) => string;
declare class Break {
private readonly codePoints;
readonly required: boolean;
readonly start: number;
readonly end: number;
constructor(codePoints: number[], lineBreak: string, start: number, end: number);
slice(): string;
}
export declare type LineBreak = {
done: true;
value: null;
} | {
done: false;
value: Break;
};
interface ILineBreakIterator {
next: () => LineBreak;
}
export declare const LineBreaker: (str: string, options?: IOptions | undefined) => ILineBreakIterator;
export {};
@@ -0,0 +1,5 @@
export declare const toCodePoints: (str: string) => number[];
export declare const fromCodePoint: (...codePoints: number[]) => string;
export declare const decode: (base64: string) => ArrayBuffer | number[];
export declare const polyUint16Array: (buffer: number[]) => number[];
export declare const polyUint32Array: (buffer: number[]) => number[];
@@ -0,0 +1,2 @@
export { toCodePoints, fromCodePoint } from './Util';
export { LineBreaker } from './LineBreak';
File diff suppressed because one or more lines are too long
@@ -0,0 +1,61 @@
{
"name": "css-line-break",
"version": "2.1.0",
"description": "",
"main": "dist/css-line-break.umd.js",
"module": "dist/css-line-break.es5.js",
"typings": "dist/types/index.d.ts",
"scripts": {
"prebuild": "rimraf dist/",
"build": "tsc --module commonjs && rollup -c rollup.config.ts",
"format": "prettier --write \"{src,scripts}/**/*.ts\"",
"lint": "tslint -c tslint.json --project tsconfig.json -t codeFrame src/**/*.ts tests/**/*.ts scripts/**/*.ts",
"generate-trie": "ts-node scripts/generate_line_break_trie.ts",
"generate-tests": "ts-node scripts/generate_line_break_tests.ts",
"mocha": "mocha --require ts-node/register tests/*.ts",
"test": "npm run lint && npm run mocha",
"release": "standard-version"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/niklasvh/css-line-break.git"
},
"keywords": [
"white-space",
"line-break",
"word-break",
"word-wrap",
"overflow-wrap"
],
"dependencies": {
"utrie": "^1.0.2"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/mocha": "^8.2.2",
"@types/node": "^16.0.0",
"mocha": "9.0.2",
"prettier": "^2.3.2",
"rimraf": "3.0.2",
"rollup": "^2.52.7",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"standard-version": "^9.3.0",
"ts-node": "^10.0.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.3.5"
},
"author": {
"name": "Niklas von Hertzen",
"email": "niklasvh@gmail.com",
"url": "https://hertzen.com"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/niklasvh/css-line-break/issues"
},
"homepage": "https://github.com/niklasvh/css-line-break#readme"
}
@@ -0,0 +1,40 @@
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import sourceMaps from 'rollup-plugin-sourcemaps';
import typescript from '@rollup/plugin-typescript';
import json from 'rollup-plugin-json';
const pkg = require('./package.json');
const banner = `/*
* ${pkg.name} ${pkg.version} <${pkg.homepage}>
* Copyright (c) ${(new Date()).getFullYear()} ${pkg.author.name} <${pkg.author.url}>
* Released under ${pkg.license} License
*/`;
export default {
input: `src/index.ts`,
output: [
{ file: pkg.main, name: pkg.name, format: 'umd', banner, sourcemap: true },
{ file: pkg.module, format: 'esm', banner, sourcemap: true },
],
external: [],
watch: {
include: 'src/**',
},
plugins: [
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
resolve(),
// Allow json resolution
json(),
// Compile TypeScript files
typescript({ sourceMap: true, inlineSources: true }),
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs(),
// Resolve source maps to the original source
sourceMaps(),
],
}
+1
View File
@@ -0,0 +1 @@
../../utrie@1.0.2/node_modules/utrie
@@ -0,0 +1 @@
dist/*.min.js -diff
@@ -0,0 +1,14 @@
# Use case: description, code
[jsfiddle](https://jsfiddle.net/IDisposable/emjL1ow8/)
## Expected behavior
## Actual behavior (stack traces, console logs etc)
## Library version
## Browsers
- [ ] Chrome 49+
- [ ] Firefox 45+
@@ -0,0 +1,19 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: docker
directory: '/'
schedule:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- 'type: dependencies'
@@ -0,0 +1,42 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
template: |
# What's Changed
$CHANGES
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
categories:
- title: 'Breaking'
label: 'type: breaking'
- title: 'New'
label: 'type: feature'
- title: 'Bug Fixes'
label: 'type: bug'
- title: 'Maintenance'
label: 'type: maintenance'
- title: 'Documentation'
label: 'type: docs'
- title: 'Other changes'
- title: 'Dependency Updates'
label: 'type: dependencies'
collapse-after: 5
version-resolver:
major:
labels:
- 'type: breaking'
minor:
labels:
- 'type: feature'
patch:
labels:
- 'type: bug'
- 'type: maintenance'
- 'type: docs'
- 'type: dependencies'
- 'type: security'
exclude-labels:
- 'skip-changelog'
@@ -0,0 +1,75 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: 'CodeQL'
on:
push:
branches: ['main', 'v2.x']
pull_request:
# The branches below must be a subset of the branches above
branches: ['main', 'v2.x']
schedule:
- cron: '17 11 * * 1'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ['javascript']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: '/language:${{matrix.language}}'
@@ -0,0 +1,12 @@
---
name: Sync labels
# yamllint disable-line rule:truthy
on:
schedule:
- cron: "34 5 * * *"
workflow_dispatch:
jobs:
workflows:
uses: hassio-addons/workflows/.github/workflows/labels.yaml@main
@@ -0,0 +1,12 @@
---
name: Lock
# yamllint disable-line rule:truthy
on:
schedule:
- cron: "0 9 * * *"
workflow_dispatch:
jobs:
workflows:
uses: hassio-addons/workflows/.github/workflows/lock.yaml@main
@@ -0,0 +1,15 @@
---
name: PR Labels
# yamllint disable-line rule:truthy
on:
pull_request_target:
types:
- opened
- labeled
- unlabeled
- synchronize
jobs:
workflows:
uses: hassio-addons/workflows/.github/workflows/pr-labels.yaml@main
@@ -0,0 +1,30 @@
name: Publish Package to npmjs
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '19.x'
registry-url: 'https://registry.npmjs.org'
- name: Install npm packages
run: npm ci
- name: Build
run: npm run build:ci
- name: Publish NPM package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,17 @@
---
name: Release Drafter
# yamllint disable-line rule:truthy
on:
push:
branches:
- main
jobs:
workflows:
permissions:
# Write permission is required to create a github release
contents: write
# Write permission is required for autolabeler
pull-requests: write
uses: hassio-addons/workflows/.github/workflows/release-drafter.yaml@main
@@ -0,0 +1,12 @@
---
name: Stale
# yamllint disable-line rule:truthy
on:
schedule:
- cron: "0 8 * * *"
workflow_dispatch:
jobs:
workflows:
uses: hassio-addons/workflows/.github/workflows/stale.yaml@main
@@ -0,0 +1,30 @@
name: build
on:
push:
branches: [main, v2.x]
pull_request:
branches: [main, v2.x]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Setup Chrome
uses: browser-actions/setup-chrome@v1
- name: Check dependencies
run: npm ci --dry-run
- name: Install dependencies
run: npm ci
- name: Run build only
run: npm run build:ci
@@ -0,0 +1,8 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart
tasks:
- init: npm install && npm run build
@@ -0,0 +1,41 @@
{
"html": {
"brace_style": "collapse",
"end_with_newline": true,
"indent_char": " ",
"indent_scripts": "keep",
"indent_size": 4,
"preserve_newlines": true,
"max_preserve_newlines": 1,
"wrap_attributes": "auto",
"wrap_line_length": 100
},
"js": {
"allowed_file_extensions": ["js", "jsx", "json", "jsbeautifyrc"],
"brace_style": "collapse-preserve-inline",
"break_chained_methods": false,
"comma_first": false,
"e4x": false,
"end_with_newline": true,
"indent_char": " ",
"indent_level": 0,
"indent_size": 4,
"jslint_happy": false,
"keep_array_indentation": false,
"keep_function_indentation": false,
"max_preserve_newlines": 0,
"preserve_newlines": true,
"space_in_empty_paren": false,
"space_in_paren": false
},
"css": {
"allowed_file_extensions": ["css", "scss", "sass", "less"],
"end_with_newline": true,
"indent_char": " ",
"indent_size": 4,
"newline_between_rules": true,
"selector_separator": " ",
"selector_separator_newline": false,
"preserve_newlines": true
}
}
@@ -0,0 +1,8 @@
{
"eqeqeq": true,
"immed": true,
"newcap": true,
"unused": "strict",
"esnext": true,
"laxbreak": true
}
@@ -0,0 +1,9 @@
{
"list-marker-space": {
"ul_multi": 3,
"ul_single": 3
},
"ul-indent": {
"indent": 4
}
}
@@ -0,0 +1,2 @@
test-lib/
dist/
@@ -0,0 +1,12 @@
{
"singleQuote": true,
"semi": true,
"trailingComma": "es5",
"quoteProps": "consistent",
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf",
"tabWidth": 4,
"printWidth": 90,
"proseWrap": "always"
}
@@ -0,0 +1,5 @@
{
"rules": {
"indentation": 4
}
}
@@ -0,0 +1,42 @@
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'spec/**/*.js'],
options: {
jshintrc: true,
},
},
karma: {
unit: {
configFile: 'karma.conf.js',
background: false,
singleRun: true,
},
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
sourceMap: true,
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': ['src/dom-to-image-more.js'],
},
},
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['test'],
},
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('test', ['karma']);
grunt.registerTask('default', ['jshint', 'test', 'uglify']);
grunt.registerTask('ci', ['jshint', 'uglify']);
};
@@ -0,0 +1,29 @@
The MIT License (MIT)
Copyright 2018 Marc Brooks
https://about.me/idisposable
Copyright 2015 Anatolii Saienko
https://github.com/tsayen
Copyright 2012 Paul Bakaus
http://paulbakaus.com/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,419 @@
# DOM to Image
[![Version](https://img.shields.io/npm/v/dom-to-image-more.svg?style=flat-square)](https://npmjs.com/package/dom-to-image-more)
[![Bundle Size](https://img.shields.io/bundlephobia/minzip/dom-to-image-more?style=flat-square)](https://bundlephobia.com/result?p=dom-to-image-more)
[![Open Issues](https://img.shields.io/github/issues/1904labs/dom-to-image-more?style=flat-square)](https://github.com/1904labs/dom-to-image-more/issues)
[![GitHub Repo stars](https://img.shields.io/github/stars/1904labs/dom-to-image-more?style=social)](https://github.com/1904labs/dom-to-image-more)
[![Twitter](https://img.shields.io/twitter/follow/idisposable.svg?style=social&label=Follow)](https://www.twitter.com/idisposable)
## Breaking Change Notice
The 3.x release branch included some breaking changes in the very infrequently used
ability to configure some utility methods used in this internal processing of
dom-to-image-more. As browsers have matured, many of the hacks we're accumulated over the
years are not needed, or better ways have been found to handle some edge-cases. With the
help of folks like @meche-gh, in #99 we're stripping out the following members:
- `.mimes` - was the not-very-comprehensive list of mime types used to handle inlining
things
- `.parseExtension` - was a method to extract the extension from a filename, used to guess
mime types
- `.mimeType` - was a method to map file extensions to mime types
- `.dataAsUrl` - was a method to reassemble a `data:` URI from a Base64 representation and
mime type
The 3.x release branch should also fix more node compatibility and `iframe` issues.
## What is it
**dom-to-image-more** is a library which can turn arbitrary DOM node, including same
origin and blob iframes, into a vector (SVG) or raster (PNG or JPEG) image, written in
JavaScript.
This fork of
[dom-to-image by Anatolii Saienko (tsayen)](https://github.com/tsayen/dom-to-image) with
some important fixes merged. We are eternally grateful for his starting point.
Anatolii's version was based on [domvas by Paul Bakaus](https://github.com/pbakaus/domvas)
and has been completely rewritten, with some bugs fixed and some new features (like web
font and image support) added.
Moved to [1904labs organization](https://github.com/1904labs/) from my repositories
2019-02-06 as of version 2.7.3
## Installation
### NPM
`npm install dom-to-image-more`
Then load
```javascript
/* in ES 6 */
import domtoimage from 'dom-to-image-more';
/* in ES 5 */
var domtoimage = require('dom-to-image-more');
```
## Usage
All the top level functions accept DOM node and rendering options, and return promises,
which are fulfilled with corresponding data URLs. Get a PNG image base64-encoded data URL
and display right away:
```javascript
var node = document.getElementById('my-node');
domtoimage
.toPng(node)
.then(function (dataUrl) {
var img = new Image();
img.src = dataUrl;
document.body.appendChild(img);
})
.catch(function (error) {
console.error('oops, something went wrong!', error);
});
```
Get a PNG image blob and download it (using
[FileSaver](https://github.com/eligrey/FileSaver.js/), for example):
```javascript
domtoimage.toBlob(document.getElementById('my-node')).then(function (blob) {
window.saveAs(blob, 'my-node.png');
});
```
Save and download a compressed JPEG image:
```javascript
domtoimage
.toJpeg(document.getElementById('my-node'), { quality: 0.95 })
.then(function (dataUrl) {
var link = document.createElement('a');
link.download = 'my-image-name.jpeg';
link.href = dataUrl;
link.click();
});
```
Get an SVG data URL, but filter out all the `<i>` elements:
```javascript
function filter(node) {
return node.tagName !== 'i';
}
domtoimage
.toSvg(document.getElementById('my-node'), { filter: filter })
.then(function (dataUrl) {
/* do something */
});
```
Get the raw pixel data as a
[Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
with every 4 array elements representing the RGBA data of a pixel:
```javascript
var node = document.getElementById('my-node');
domtoimage.toPixelData(node).then(function (pixels) {
for (var y = 0; y < node.scrollHeight; ++y) {
for (var x = 0; x < node.scrollWidth; ++x) {
pixelAtXYOffset = 4 * y * node.scrollHeight + 4 * x;
/* pixelAtXY is a Uint8Array[4] containing RGBA values of the pixel at (x, y) in the range 0..255 */
pixelAtXY = pixels.slice(pixelAtXYOffset, pixelAtXYOffset + 4);
}
}
});
```
Get a canvas object:
```javascript
domtoimage.toCanvas(document.getElementById('my-node')).then(function (canvas) {
console.log('canvas', canvas.width, canvas.height);
});
```
Adjust cloned nodes before/after children are cloned
[sample fiddle](https://jsfiddle.net/IDisposable/grLtjwe5/12/)
```javascript
const adjustClone = (node, clone, after) => {
if (!after && clone.id === 'element') {
clone.style.transform = 'translateY(100px)';
}
return clone;
};
const wrapper = document.getElementById('wrapper');
const blob = domtoimage.toBlob(wrapper, { adjustClonedNode: adjustClone });
```
---
_All the functions under `impl` are not public API and are exposed only for unit testing._
---
### Rendering options
#### filter
A function taking DOM node as argument. Should return true if passed node should be
included in the output (excluding node means excluding it's children as well). Not called
on the root node.
#### filterStyles
A function taking style propertie name as argument. Should return true if passed propertie
should be included in the output
Sample use:
```javascript
filterStyles(node, propertyName) {
return !propertyName.startssWith('--'); // to filter out CSS variables
}
```
#### adjustClonedNode
A function that will be invoked on each node as they are cloned. Useful to adjust nodes in
any way needed before the conversion. Note that this be invoked before the onclone
callback. The handler gets the original node, the cloned node, and a boolean that says if
we've cloned the children already (so you can handle either before or after)
Sample use:
```javascript
const adjustClone = (node, clone, after) => {
if (!after && clone.id === 'element') {
clone.style.transform = 'translateY(100px)';
}
return clone;
};
```
const wrapper = document.getElementById('wrapper'); const blob =
domtoimage.toBlob(wrapper, { adjustClonedNode: adjustClone});
#### onclone
A function taking the cloned and modified DOM node as argument. It allows to make final
adjustements to the elements before rendering, on the whole clone, after all elements have
been individually cloned. Note that this will be invoked after all the onclone callbacks
have been fired.
The cloned DOM might differ a lot from the original DOM, for example canvas will be
replaced with image tags, some class might have changed, the style are inlined. It can be
useful to log the clone to get a better senses of the transformations.
#### bgcolor
A string value for the background color, any valid CSS color value.
#### height, width
Height and width in pixels to be applied to node before rendering.
#### style
An object whose properties to be copied to node's style before rendering. You might want
to check
[this reference](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Properties_Reference)
for JavaScript names of CSS properties.
#### quality
A number between 0 and 1 indicating image quality (e.g. 0.92 => 92%) of the JPEG image.
Defaults to 1.0 (100%)
#### cacheBust
Set to true to append the current time as a query string to URL requests to enable cache
busting. Defaults to false
#### imagePlaceholder
A data URL for a placeholder image that will be used when fetching an image fails.
Defaults to undefined and will throw an error on failed images
#### copyDefaultStyles
Set to true to enable the copying of the default styles of elements. This will make the
process faster. Try disabling it if seeing extra padding and using resetting / normalizing
in CSS. Defaults to true.
#### disableInlineImages
Set to true to disable the normal inlining images into the SVG output. This will generate
SVGs that reference the original image files, so they my break if a referenced URL fails.
This is always safe to use when generating a PNG/JPG file because the entire SVG image is
rendered.
#### useCredentialFeatures
Allows optionally setting the `useCredentials` option if the resource matches a pattern in
the `useCredentialFilters` array.
#### scale
Scale value to be applied on canvas's `ctx.scale()` on both x and y axis. Can be used to
increase the image quality with higher image size.
### Alternative Solutions to CORS Policy Issue
Are you facing a [CORS policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
issue in your app? Don't worry, there are alternative solutions to this problem that you
can explore. Here are some options to consider:
1. **Use the option.corsImg support by passing images** With this option, you can setup a
proxy service that will process the requests in a safe CORS context.
2. **Use third-party services like [allOrigins](https://allorigins.win/).** With this
service, you can fetch the source code or an image in base64 format from any website.
However, this method can be a bit slow.
3. **Set up your own API service.** Compared to third-party services like
[allOrigins](https://allorigins.win/), this method can be faster, but you'll need to
convert the image URL to base64 format. You can use the
"[image-to-base64](https://github.com/renanbastos93/image-to-base64)" package for this
purpose.
4. **Utilize
[server-side functions](https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props)
features of frameworks like [Next.js](https://nextjs.org/).** This is the easiest and
most convenient method, where you can directly fetch a URL source within
[server-side functions](https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props)
and convert it to base64 format if needed.
By exploring these alternative solutions, you can overcome
[the CORS policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) issue in your
app and ensure that your images are accessible to everyone.
## Browsers
It's tested on latest Chrome and Firefox (49 and 45 respectively at the time of writing),
with Chrome performing significantly better on big DOM trees, possibly due to it's more
performant SVG support, and the fact that it supports `CSSStyleDeclaration.cssText`
property.
_Internet Explorer is not (and will not be) supported, as it does not support SVG
`<foreignObject>` tag_
_Safari [is not supported](https://github.com/tsayen/dom-to-image/issues/27), as it uses a
stricter security model on `<foreignObject`> tag. Suggested workaround is to use `toSvg`
and render on the server._`
## Dependencies
Uses Object.hasOwn() so needs at least Chrome/Edge 93, Firefox 92, Opera 79. Safari 15.4
or Node 16.9.0
### Source
Only standard lib is currently used, but make sure your browser supports:
- [Promise](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise)
- SVG `<foreignObject>` tag
### Tests
As of this v3 branch chain, the testing jig is taking advantage of the `onclone` hook to
insert the clone-output into the testing page. This should make it a tiny bit easier to
track down where exactly the inlining of CSS styles against the DOM nodes is wrong.
Most importantly, tests **only** depend on:
- [ocrad.js](https://github.com/antimatter15/ocrad.js), for the parts when you can't
compare images (due to the browser rendering differences) and just have to test whether
the text is rendered
## How it works
There might some day exist (or maybe already exists?) a simple and standard way of
exporting parts of the HTML to image (and then this script can only serve as an evidence
of all the hoops I had to jump through in order to get such obvious thing done) but I
haven't found one so far.
This library uses a feature of SVG that allows having arbitrary HTML content inside of the
`<foreignObject>` tag. So, in order to render that DOM node for you, following steps are
taken:
1. Clone the original DOM node recursively
1. Compute the style for the node and each sub-node and copy it to corresponding clone
- and don't forget to recreate pseudo-elements, as they are not cloned in any way, of
course
1. Embed web fonts
- find all the `@font-face` declarations that might represent web fonts
- parse file URLs, download corresponding files
- base64-encode and inline content as `data:` URLs
- concatenate all the processed CSS rules and put them into one `<style>` element,
then attach it to the clone
1. Embed images
- embed image URLs in `<img>` elements
- inline images used in `background` CSS property, in a fashion similar to fonts
1. Serialize the cloned node to XML
1. Wrap XML into the `<foreignObject>` tag, then into the SVG, then make it a data URL
1. Optionally, to get PNG content or raw pixel data as a Uint8Array, create an Image
element with the SVG as a source, and render it on an off-screen canvas, that you have
also created, then read the content from the canvas
1. Done!
## Using Typescript
1. Use original `dom-to-image` type definition
`npm install @types/dom-to-image --save-dev`
1. Create dom-to-image-more type definition (`dom-to-image-more.d.ts`)
```javascript
declare module 'dom-to-image-more' {
import domToImage = require('dom-to-image-more');
export = domToImage;
}
```
## Things to watch out for
- if the DOM node you want to render includes a `<canvas>` element with something drawn on
it, it should be handled fine, unless the canvas is
[tainted](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image) - in
this case rendering will rather not succeed.
- at the time of writing, Firefox has a problem with some external stylesheets (see issue
#13). In such case, the error will be caught and logged.
## Authors
Marc Brooks, Anatolii Saienko (original dom-to-image), Paul Bakaus (original idea), Aidas
Klimas (fixes), Edgardo Di Gesto (fixes), 樊冬 Fan Dong (fixes), Shrijan Tripathi (docs),
SNDST00M (optimize), Joseph White (performance CSS), Phani Rithvij (test), David
DOLCIMASCOLO (packaging), Zee (ZM) @zm-cttae (many major updates), Joshua Walsh
@JoshuaWalsh (Firefox issues), Emre Coban @emrecoban (documentation), Nate Stuyvesant
@nstuyvesant (fixes), King Wang @eachmawzw (CORS image proxy), TMM Schmit @tmmschmit
(useCredentialsFilters), Aravind @codesculpture (fix overridden props), Shi Wenyu @cWenyu
(shadow slot fix), David Burns @davidburns573 and Yujia Cheng @YujiaCheng1996 (font copy
optional), Julien Dorra @juliendorra (documentation), Sean Zhang @SeanZhang-eaton (regex
fixes), Ludovic Bouges @ludovic (style property filter), Roland Ma @RolandMa1986 (URL
regex)", Kasim Tan @kasimtan
## License
MIT
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,42 @@
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
export default [
...compat.extends('eslint:recommended'),
{
languageOptions: {
globals: {
...globals.browser,
},
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'indent': ['error', 4],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['error', 'always'],
'no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
},
},
];
@@ -0,0 +1,54 @@
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['mocha', 'chai'],
concurrency: 1,
files: [
{
pattern: 'spec/resources/**/*',
included: false,
served: true,
},
{
pattern: 'test-lib/fontawesome/webfonts/*.*',
included: false,
served: true,
},
{
pattern: 'test-lib/fontawesome/css/*.*',
included: false,
served: true,
},
'test-lib/tesseract-4.0.2.min.js',
'src/dom-to-image-more.js',
'spec/dom-to-image-more.spec.js',
],
exclude: [],
preprocessors: {},
reporters: ['mocha'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
client: {
captureConsole: true,
},
autoWatch: true,
browsers: ['chrome'],
customLaunchers: {
chrome: {
base: 'Chrome',
flags: [
'--no-sandbox --remote-debugging-port=9876 --window-size=1024,768',
],
debug: true,
},
},
singleRun: false,
browserNoActivityTimeout: 60000,
});
};
@@ -0,0 +1,84 @@
{
"name": "dom-to-image-more",
"version": "3.7.2",
"description": "Generates an image from a DOM node using HTML5 canvas and SVG",
"main": "dist/dom-to-image-more.min.js",
"devDependencies": {
"chai": "^4.4.1",
"eslint": "^9.38.0",
"grunt": "^1.6.1",
"grunt-cli": "^1.5.0",
"grunt-contrib-jshint": "^3.2.0",
"grunt-contrib-uglify": "^5.2.2",
"grunt-contrib-watch": "^1.1.0",
"grunt-karma": "^4.0.2",
"js-yaml": "^4.1.0",
"karma": "^6.4.4",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.2.0",
"karma-firefox-launcher": "^2.1.3",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"mocha": "^11.7.4",
"prettier": "^3.6.2",
"semver": "^7.7.3"
},
"scripts": {
"format": "eslint src --fix && prettier --write .",
"lint": "eslint --max-warnings=0 src && prettier --check .",
"test": "grunt test --debug",
"build": "grunt",
"build:ci": "grunt ci",
"beta-version-patch": "npm version $(semver $npm_package_version -i prerelease --preid beta)",
"beta-version-minor": "npm version $(semver $npm_package_version -i preminor --preid beta)",
"beta-version-major": "npm version $(semver $npm_package_version -i premajor --preid beta)",
"rc-version": "npm version $(semver $npm_package_version -i prerelease --preid rc)",
"final-release": "npm version $(semver $npm_package_version -i)",
"postversion": "npm run test && git push && git push --tags"
},
"repository": "github:1904labs/dom-to-image-more",
"keywords": [
"dom",
"image",
"raster",
"render",
"html",
"canvas",
"svg",
"png"
],
"author": "Marc Brooks <idisposable@gmail.com> (https://about.me/IDisposable)",
"contributors": [
"Anatolii Saienko <anatoly.sayenko@gmail.com>",
"Marc Brooks <idisposable@gmail.com>",
"Daniel Fischer <daniel.fischer@iqdoq.de>",
"Aidas Klimas",
"Edgardo Di Gesto",
"樊冬 Fan Dong <CG-man@outlook.com>",
"Joseph White @JosWhite",
"Phani Rithvij @phanirithvij",
"David DOLCIMASCOLO @ddolcimascolo",
"Nikita Staroseltsev @Nikitozz13",
"Zee @zm-cttae",
"Andoni Zubimendi @AndoniZubimendi",
"Joshua Walsh @JoshuaWalsh",
"Emre Coban @emrecoban",
"Nate Stuyvesant @nstuyvesant",
"King Wang @eachmawzw",
"TMM Schmit @tmmschmit",
"Aravind @codesculpture",
"Shi Wenyu @cWenyu",
"David Burns @davidburns573",
"Yujia Cheng @YujiaCheng1996",
"Julien Dorra @juliendorra",
"Sean Zhang @SeanZhang-eaton",
"Ludovic Bouges @ludovic",
"Roland Ma @RolandMa1986",
"Kasim Tan @kasimtan"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/1904labs/dom-to-image-more/issues"
},
"homepage": "https://github.com/1904labs/dom-to-image-more#readme"
}
@@ -0,0 +1,4 @@
npm run build
git push
git push --tags
npm publish
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
<div class="high-gloss">There's a lot of style here</div>
@@ -0,0 +1,34 @@
<div
class="high-gloss"
style="
background-image: linear-gradient(
rgba(50, 50, 50, 0.95) 24%,
rgb(186, 186, 186) 45%,
rgba(226, 235, 238, 0.953) 49%,
rgba(50, 50, 50, 0.93) 50%,
rgba(50, 50, 50, 0.97) 100%
);
block-size: 32px;
border-block-color: rgba(0, 0, 0, 0);
border-color: rgba(0, 0, 0, 0);
border-inline-color: rgba(0, 0, 0, 0);
box-sizing: border-box;
caret-color: rgba(0, 0, 0, 0);
color: rgba(0, 0, 0, 0);
column-rule-color: rgba(0, 0, 0, 0);
height: 32px;
inline-size: 914px;
outline-color: rgba(0, 0, 0, 0);
perspective-origin: 457px 16px;
text-decoration: none solid rgba(0, 0, 0, 0);
text-emphasis-color: rgba(0, 0, 0, 0);
text-shadow: rgba(0, 0, 0, 0.1) 5px 5px 10px;
transform-origin: 457px 16px;
width: 914px;
background-clip: text;
-webkit-text-fill-color: rgba(0, 0, 0, 0);
-webkit-text-stroke-color: rgba(0, 0, 0, 0);
"
>
There's a lot of style here
</div>
@@ -0,0 +1,22 @@
#dom-node {
width: 400px;
height: 400px;
background-color: white;
color: black;
}
.high-gloss {
background: linear-gradient(
180deg,
rgba(50, 50, 50, 0.95) 24%,
rgba(186, 186, 186, 1) 45%,
rgba(226, 235, 238, 0.9514006286108193) 49%,
rgba(50, 50, 50, 0.93) 50%,
rgba(50, 50, 50, 0.97) 100%
);
color: transparent;
text-shadow: rgba(0, 0, 0, 0.1) 5px 5px 10px;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
@@ -0,0 +1,3 @@
BARE TEXT NODES ARE FUN
<!-- This is a comment -->
<div>IGNORE ME</div>
@@ -0,0 +1,16 @@
* {
color: black;
background-color: white;
font-family: monospace;
font-size: 20px;
font-style: normal;
font-weight: bold;
font-variant: normal;
}
#dom-node {
text-align: center;
width: 500px;
padding: 20px;
background-color: brown;
}
@@ -0,0 +1 @@
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAdxJREFUeF7t3MGJw1AUQ9HvCjL9V+kOPB1kIVAQ5nj/ZPleRHa57vt+zguez+fvBV9xzkXIlkdCtnxYyJgPQggpEfCjXgKbxhKSkivdEVICm8YSkpIr3RFSApvGEpKSK90RUgKbxhKSkivdEVICm8YSkpIr3RFSApvGEpKSK90RUgKbxhKSkivdEVICm8YSkpIr3RFSApvGEpKSK90RUgKbxhKSkivdEVICm8YSkpIr3RFSApvGEpKSK90RUgKbxhKSkivdEVICm8YSkpIr3RFSApvGEpKSK90RUgKbxhKSkivdEVICm8YSkpIr3RFSApvGEpKSK90RUgKbxhKSkivdEVICm8YSkpIr3RFSApvGEpKSK90RUgKbxhKSkivdvUbI85xX/KNcyfPPYy9Cfs786wsJ2fJxCCFkjMBYHQshZIzAWB0LIWSMwFgdCyFkjMBYHQshZIzAWB0LIWSMwFgdCyFkjMBYHQshZIzAWB0LIWSMwFgdCyFkjMBYHQshZIzAWB0LIWSMwFgdCyFkjMBYHQshZIzAWB0LIWSMwFgdCyFkjMBYHQshZIzAWB0LIWSMwFgdCyFkjMBYHQshZIzAWB0LIWSMwFgdCyFkjMBYHQshZIzAWB0LGRPyD33xXUh8cFpQAAAAAElFTkSuQmCC
@@ -0,0 +1 @@
<div id="content"></div>
@@ -0,0 +1,10 @@
#dom-node {
height: 100px;
width: 100px;
}
#content {
height: 50px;
width: 50px;
background-color: #f0f0f0;
}
@@ -0,0 +1 @@
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABlCAYAAAC7vkbxAAABMElEQVR4nO3XwQnEMBAEwQ3dOSog3c8gHIAarh4VQTNCOzOzSZm91iLgCLJnuOgThPsEiTmCzDNcZCFBgsScT9b9j8Zfs5AgQWIchiEWEiRIjMMwxEKCBIlxGIZYSJAgMQ7DEAsJEiTGYRhiIUGCxDgMQywkSJAYh2GIhQQJEuMwDLGQIEFiHIYhFhIkSIzDMMRCggSJcRiGWEiQIDEOwxALCRIkxmEYYiFBgsQ4DEMsJEiQGIdhiIUECRLjMAyxkCBBYhyGIRYSJEiMwzDEQoIEiXEYhlhIkCAxDsMQCwkSJMZhGGIhQYLEOAxDLCRIkBiHYYiFBAkS4zAMsZAgQWIchiEWEiRIjMMwxEKCBIlxGIZYSJAgMQ7DEAsJEiTGYRhiIUGCxDgMQywk6A1Cxw8SIrcz/VMBBAAAAABJRU5ErkJggg==
@@ -0,0 +1 @@
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABjCAYAAABt56XsAAAB10lEQVR4Xu3dgW3CQBAAQegHV0OdVPP0A7IRj54KRvKmggujnLxvO1zHGK9LP8wncN1BbtvGDHTmQZ5jXA6QM38I2u8eCCZygGyPVpbgMu6tLMFhmaGVhZF8VtZ2w8Y65zhjPLvK0uhbWZhIYQiBFIYQxneUVhaGUhhCIIUhhNHKAjH2kQpDCKYwhDBaWSDGXFndMTR0CkPDoeN30GGOVBhCOoUhhNFVFohRGGIohSEGMv9CwLlOO1J3DCH6whDC6CoLxPhdZfUoKcFTGBIM6xA95IChdMcQAikMIYyuskCM7hhiKIUhBtJZlgrSO4aGTGFoOCxTFIYYSmEIgRSGEEZhCGIUhhhKYYiBFIYqSGFoyBSGhkNhCDrMkQpDSKcwhDAKQxCjMMRQCkMMpDBUQQpDQ6YwNBwKQ9ChMBRRCkNQpYccMJTeMYRACkMIo7MsEGOWemFo6BSGhkNhCDoUhiJKYQiqFIYYSmEIgRSGEEZhCGIUhhhKYYiB9JCDCtL3GBoyhaHh0FkW6LCeZfV1FQZRYWg4tLJAh7/j9/4rKWFUGBIM6xAdv2MovWMIgRSGEEbH7yDGPFwsDA2dwtBwKAxBh8JQRCkMQZXCEEMpDCGQwhDC+I7yBsViutvRkyz3AAAAAElFTkSuQmCC
@@ -0,0 +1,5 @@
<div class="dom-child-node">
<div class="red"></div>
<div class="green"></div>
<div class="blue"></div>
</div>
@@ -0,0 +1,26 @@
#dom-node {
width: 100px;
}
.child-node {
height: auto;
}
.red {
background-color: red;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
.red,
.green,
.blue {
height: 3px;
border: 1px solid lightgrey;
}
@@ -0,0 +1 @@
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAACBElEQVR4Xu3dQQrDQAzAwPT/j25pX2DoYHxQzkZrJJaQU17P87yfnjMGXgU50+K3SEFu9SjIsR4FKcg1A8f26R1SkGMGjq3TDSnIMQPH1hnfkD7n/yv3FT15CjKxBGYKAiRKREGkTcAqCJAoEQWRNgGrIECiRBRE2gSsggCJElEQaROwCgIkSkRBpE3AKgiQKBEFkTYBqyBAokQURNoErIIAiRJREGkTsAoCJEpEQaRNwCoIkCgRBZE2AasgQKJEFETaBKyCAIkSURBpE7AKAiRKREGkTcAqCJAoEQWRNgGrIECiRBRE2gSsggCJElEQaROwCgIkSkRBpE3AKgiQKBEFkTYBqyBAokQURNoErIIAiRJREGkTsAoCJEpEQaRNwCoIkCgRBZE2AasgQKJEFETaBKyCAIkSURBpE7AKAiRKREGkTcAqCJAoEQWRNgGrIECiRBRE2gSsggCJElEQaROwCgIkSkRBpE3AKgiQKBEFkTYBqyBAokQURNoErIIAiRJREGkTsAoCJEpEQaRNwCoIkCgRBZE2AasgQKJEFETaBKyCAIkSURBpE7AKAiRKREGkTcAqCJAoEQWRNgGrIECiRBRE2gQsHgTsFGJg4Buuf9cPRG2NFGTL9PCcggxFbY0VZMv08JyCDEVtjRVky/TwnIIMRW2NFWTL9PCcggxFbY19AL3RtAEdMr15AAAAAElFTkSuQmCC
@@ -0,0 +1,9 @@
#dom-node {
font-size: 16px;
width: 100px;
height: 100px;
background-color: red;
border-color: black;
border: solid;
border-width: 10px 10px 0.625em 10px;
}
@@ -0,0 +1 @@
<canvas id="content"></canvas>
@@ -0,0 +1,7 @@
<div id="dom-node">
BLANK_TEMPLATE
<canvas width="0"></canvas>
</div>
<div id="result"></div>
@@ -0,0 +1,11 @@
#dom-node {
height: 100px;
width: 200px;
background-color: lightgrey;
text-align: center;
padding: 1em;
}
#result {
margin-top: 10px;
}
@@ -0,0 +1,10 @@
#dom-node {
height: 100px;
width: 100px;
font-family: monospace;
}
#content {
height: 100px;
width: 100px;
}
@@ -0,0 +1 @@
data:image/png;base64,iVB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jun/R6NSkmtLoqWaITHSDpibjmTyvrneWOrqKUJIcgt2z+0RcITYYxVIS0dIIDDbD+IIsccqkJaOkEBgth/EEWKPVSAtHSGBwGw/iCPEHqtAWjpCAoHZfhBHiD1WgbR0hAQCs/0gjhB7rAJp6QgJBGb7QRwh9lgF0tIREgjM9oM4QuyxCqSlIyQQmO0HcYTYYxVIS0dIIDDbD+IIsccqkJaOkEBgth/EEWKPVSAtHSGBwGw/iCPEHqtAWjpCAoHZfhBHiD1WgbR0hAQCs/0gjhB7rAJp+T8vFKN6Qw3MEwAAAABJRU5ErkJggg==
@@ -0,0 +1 @@
<div class="with-background"></div>
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

@@ -0,0 +1,12 @@
#dom-node {
width: 100px;
height: 100px;
background-color: white;
color: black;
}
.with-background {
background: url(/base/spec/resources/css-bg/image.jpeg) no-repeat left top;
background-size: 100px 100px;
width: 100px;
height: 100px;
}
File diff suppressed because one or more lines are too long
@@ -0,0 +1,53 @@
<div class="rounded-lg bg-gray-100 px-4 py-4" id="informacion_estadistica">
<div>
<h3 class="mt-5 text-2xl leading-6 font-medium text-gray-900">Results</h3>
<dl
class="m-auto w-3/4 mt-5 grid grid-cols-1 rounded-lg bg-white overflow-hidden shadow divide-y divide-gray-200 md:grid-cols-2 md:divide-y-0 md:divide-x"
>
<div class="px-4 py-5 sm:p-6">
<dt class="text-center text-base font-extrabold text-gray-900">
ABC <br />
DEF ABC ABC
</dt>
<dd class="mt-1 flex justify-center items-baseline md:block lg:flex">
<div class="text-gray-500">
<div
class="mx-auto px-2.5 py-0.5 text-5xl font-extrabold text-green-500 md:mt-2 lg:mt-0"
>
<p class="text-center">50.00%</p>
</div>
<div class="text-center text-sm">
<span class="font-semibold text-indigo-600">5</span> de
<span class="font-semibold text-indigo-600">10</span>
resueltas
</div>
</div>
</dd>
</div>
<div class="px-4 py-5 sm:p-6">
<dt class="text-center text-base font-extrabold text-gray-900">
Audiencias<br />
celebradas
</dt>
<dd class="mt-1 flex justify-center items-baseline md:block lg:flex">
<div class="text-gray-500">
<div
class="mx-auto px-2.5 py-0.5 text-5xl font-extrabold text-green-500 md:mt-2 lg:mt-0"
>
<p class="text-center">10</p>
</div>
<div class="text-center text-sm">
<span class="font-semibold text-indigo-600">5</span> Aud.
Preliminares
</div>
<div class="text-center text-sm">
<span class="font-semibold text-indigo-600">5</span> Aud.
Vista de Causa
</div>
</div>
</dd>
</div>
</dl>
</div>
<p class="text-sm text-gray-800 text-right mt-2">Last update: 2023-02-04</p>
</div>

Some files were not shown because too many files have changed in this diff Show More