clipper: make imports esm compatible

This commit is contained in:
Abdullah Atta
2024-09-23 12:13:46 +05:00
parent f7db306c26
commit 7458aa53ae
12 changed files with 36 additions and 32 deletions

View File

@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { expect, test } from "@playwright/test";
import { buildSync } from "esbuild";
import path, { join } from "path";
import type { Clipper } from "../src";
import type { Clipper } from "../src/index.js";
import Websites from "./pages.json";
import slugify from "slugify";
import { mkdirSync, rmSync, writeFileSync } from "fs";

View File

@@ -1,12 +1,12 @@
{
"name": "@notesnook/clipper",
"version": "2.0.7",
"version": "2.1.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@notesnook/clipper",
"version": "2.0.7",
"version": "2.1.1",
"hasInstallScript": true,
"license": "GPL-3.0-or-later",
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@notesnook/clipper",
"version": "2.0.7",
"version": "2.1.1",
"description": "Web clipper core used by the Notesnook Web Clipper",
"keywords": [
"web-clipper"

View File

@@ -16,9 +16,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { createImage, FetchOptions } from "./fetch";
import { Filter } from "./types";
import { uid } from "./utils";
import { createImage, FetchOptions } from "./fetch.js";
import { Filter } from "./types.js";
import { uid } from "./utils.js";
const SVGElements = [
"altGlyph",

View File

@@ -16,13 +16,13 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { cloneNode, isSVGElement } from "./clone";
import { createImage, FetchOptions } from "./fetch";
import { resolveAll } from "./fontfaces";
import { inlineAllImages } from "./images";
import { Options } from "./types";
import { canvasToBlob, delay, escapeXhtml, height, width } from "./utils";
import { cacheStylesheets, inlineStylesheets } from "./styles";
import { cloneNode, isSVGElement } from "./clone.js";
import { createImage, FetchOptions } from "./fetch.js";
import { resolveAll } from "./fontfaces.js";
import { inlineAllImages } from "./images.js";
import { Options } from "./types.js";
import { canvasToBlob, delay, escapeXhtml, height, width } from "./utils.js";
import { cacheStylesheets, inlineStylesheets } from "./styles.js";
// Default impl options
const defaultOptions: Options = {

View File

@@ -16,8 +16,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { FetchOptions } from "./fetch";
import { inlineAll, shouldProcess } from "./inliner";
import { FetchOptions } from "./fetch.js";
import { inlineAll, shouldProcess } from "./inliner.js";
async function resolveAll(options?: FetchOptions) {
const fonts = readAll();

View File

@@ -16,9 +16,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { FetchOptions, fetchResource } from "./fetch";
import { inlineAll } from "./inliner";
import { isDataUrl } from "./utils";
import { FetchOptions, fetchResource } from "./fetch.js";
import { inlineAll } from "./inliner.js";
import { isDataUrl } from "./utils.js";
async function inlineAllImages(root: HTMLElement, options?: FetchOptions) {
const imageNodes = root.querySelectorAll("img");

View File

@@ -16,10 +16,14 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { clipArticle, clipPage } from "./index";
import { clipArticle, clipPage } from "./index.js";
declare module global {
var Clipper: any;
declare global {
// eslint-disable-next-line no-var
var Clipper: {
clipArticle: typeof clipArticle;
clipPage: typeof clipPage;
};
}
global.Clipper = {

View File

@@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Readability } from "@mozilla/readability";
import { injectCss } from "./utils";
import { injectCss } from "./utils.js";
import { app, h, text } from "hyperapp";
import { getInlinedNode, toBlob, toJpeg, toPng } from "./domtoimage";
import { Config, InlineOptions } from "./types";
import { FetchOptions } from "./fetch";
import { getInlinedNode, toBlob, toJpeg, toPng } from "./domtoimage.js";
import { Config, InlineOptions } from "./types.js";
import { FetchOptions } from "./fetch.js";
type ReadabilityEnhanced = Readability<string> & {
PRESENTATIONAL_ATTRIBUTES: string[];

View File

@@ -16,8 +16,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { FetchOptions, fetchResource } from "./fetch";
import { isDataUrl, resolveUrl, escape } from "./utils";
import { FetchOptions, fetchResource } from "./fetch.js";
import { isDataUrl, resolveUrl, escape } from "./utils.js";
const URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/g;

View File

@@ -16,11 +16,11 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { constructUrl, FetchOptions } from "./fetch";
import { constructUrl, FetchOptions } from "./fetch.js";
import { compare, calculate, SpecificityArray } from "specificity";
import { tokenize } from "./css-tokenizer";
import { tokenize } from "./css-tokenizer.js";
import { stringify, parse, SelectorType } from "css-what";
import { safeQuerySelectorAll } from "./utils";
import { safeQuerySelectorAll } from "./utils.js";
const SHORTHANDS = [
"animation",

View File

@@ -16,7 +16,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { FetchOptions } from "./fetch";
import { FetchOptions } from "./fetch.js";
export type ClipArea = "full-page" | "visible" | "selection" | "article";
export type ClipMode = "simplified" | "screenshot" | "complete";