Imported from zhensherlock/watermark-js-plus (
AGENTS.md). Install upstream withnpx skills add zhensherlock/watermark-js-plus. Copyright stays with the author.
Commands
- Use npm;
.npmrcsetslegacy-peer-deps=true, and.nvmrcasks for Nodev22. Build/PR/docs CI uses Node 20, while release CI uses Node 24. - Install with
npm install. PR CI intentionally deletespackage-lock.jsonandnode_modulesbeforenpm i; release publish is the path that usesnpm ci. - Quick checks:
npm run lint,npm run build:types,npm test -- tests/utils/index.test.ts --runInBand. - Full PR-shaped verification:
npm run build,npm test, thennpm run docs:build. npm run buildcleansdist, runstscdeclaration emit, then Rollup production builds. It can also rewrite rootstats.htmlvia the Rollup visualizer.npm run devruns Rollup watch and VitePress docs together; usenpm run src:devornpm run docs:devwhen only one side is needed.
Architecture
- Public library exports start in
src/index.ts: it importssrc/styleand exportsWatermark,BlindWatermark,ImageWatermark, and all public types. src/index.ie.tsloads targetedcore-jsmodules,whatwg-fetch, andsrc/utils/polyfill, then registers the IE software fallback for blind-decodeoverlay/color-burncompositing before re-exportingsrc/index.ts; the regular entry does not register this fallback.- Main package outputs come from
rollup.config.js: root builds usesrc/index.ts, IE builds usesrc/index.ie.ts, and preserve-module ES builds write underdist/esanddist/ie/es. - Do not infer published entry routing from Rollup alone:
package.jsonsends Node ESM imports for both.and./iethrough trackedindex.mjs; non-Nodedefaultimport conditions use the builtdistfiles. - Core flow:
Watermarkowns DOM insertion and mutation protection,BlindWatermarksubclasses it with blind defaults/decoder,ImageWatermarkmutates a provided<img>src,WatermarkCanvasdraws content, andsrc/core/layoutonly switches between default and grid layout. - Keep
src/types/package.json; its only purpose is making TypeScript happy undermoduleResolution=node16+.
Tests
- Jest uses
ts-jestwithtestEnvironment: "jsdom"and always collects coverage intocoverage/. - Focus a file with
npm test -- tests/core/watermark.test.ts --runInBand. - Some core image/blind/watermark tests load remote COS images;
tests/core/image.test.tsalso sleeps twice for 10 seconds and has a 10 minute timeout, so it is not a fast smoke test. - For IE blind-decode changes, run
npm test -- tests/core/blind-decode.test.ts --runInBand;tests/manual/issue-1198-ie11is a self-contained offline IE11 old-vs-current harness. - Image imports in tests are handled by
tests/transformer/image.transformer.js.
Style And Hooks
- ESLint only targets
src/**/*.{ts,js}; Rollup also runs ESLint withthrowOnWarning: true, so warnings can failnpm run build. - Formatting is Prettier-enforced: 2 spaces, single quotes, no semicolons, trailing commas, LF.
npm run build:typesis strict ES5 + DOM declaration-only emit todist/typeswithnoUnusedLocals; it includessrc/**/*.tsandtests/declarations.d.ts, not Jest test files.- Husky pre-commit only checks Node
>=16and runsnpx lint-staged; lint-staged only lints stagedsrc/**/*.{ts,js}files. - Commit messages are Conventional Commits via commitlint; allowed types are in
commitlint.config.js.
Docs
- VitePress config is
docs/.vitepress/config.mtswithbase: "/watermark-js-plus/". - Docs are mirrored under
docs/enanddocs/zh; update both locales for user-facing API changes.
