Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(watermark): new component #2341

Merged
merged 7 commits into from
Feb 13, 2022
Merged

feat(watermark): new component #2341

merged 7 commits into from
Feb 13, 2022

Conversation

Sepush
Copy link
Collaborator

@Sepush Sepush commented Feb 6, 2022

Signed-off-by: Sepush [email protected]

close #1745

@vercel
Copy link

vercel bot commented Feb 6, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tusimple/naive-ui/4tmDE98frZVx27SwWq1uP9gEWEx4
✅ Preview: https://naive-ui-git-fork-sepush-watermark-tusimple.vercel.app

@codecov
Copy link

codecov bot commented Feb 6, 2022

Codecov Report

Merging #2341 (f182aab) into main (f6bf6b5) will increase coverage by 0.04%.
The diff coverage is 69.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2341      +/-   ##
==========================================
+ Coverage   64.22%   64.27%   +0.04%     
==========================================
  Files         936      942       +6     
  Lines       18656    18721      +65     
  Branches     4550     4560      +10     
==========================================
+ Hits        11982    12033      +51     
- Misses       5779     5792      +13     
- Partials      895      896       +1     
Impacted Files Coverage Δ
src/watermark/src/Watermark.tsx 59.18% <59.18%> (ø)
src/components.ts 100.00% <100.00%> (ø)
src/styles.ts 100.00% <100.00%> (ø)
src/themes/dark.ts 100.00% <100.00%> (ø)
src/themes/light.ts 100.00% <100.00%> (ø)
src/watermark/index.ts 100.00% <100.00%> (ø)
src/watermark/src/styles/index.cssr.ts 100.00% <100.00%> (ø)
src/watermark/styles/dark.ts 100.00% <100.00%> (ø)
src/watermark/styles/index.ts 100.00% <100.00%> (ø)
src/watermark/styles/light.ts 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f6bf6b5...f182aab. Read the comment docs.

@07akioni
Copy link
Collaborator

07akioni commented Feb 7, 2022

image

清晰度有问题,应该调整一下渲染精度

@Sepush
Copy link
Collaborator Author

Sepush commented Feb 7, 2022

image

清晰度有问题,应该调整一下渲染精度

看起来是在高分辨率屏幕上的缩放问题 我研究一下

@Sepush
Copy link
Collaborator Author

Sepush commented Feb 7, 2022

可以康康效果 不知道还模糊不 我没有 mac
这个写法有一些api是过期的
查了一下 mdn 另一种写法
https://www.html5rocks.com/en/tutorials/canvas/hidpi/

function setupCanvas (canvas: HTMLCanvasElement): CanvasRenderingContext2D|null {
  const dpr = window.devicePixelRatio || 1
  const rect = canvas.getBoundingClientRect()
  canvas.width = rect.width * dpr
  canvas.height = rect.height * dpr
  const ctx = canvas.getContext('2d')
  ctx?.scale(dpr, dpr)
  return ctx
}

@Sepush
Copy link
Collaborator Author

Sepush commented Feb 7, 2022

另一个问题 是因为用了canvas所以之前那种写法的 ssr 测试的写法行不通了 所以暂时没写测试

@07akioni
Copy link
Collaborator

07akioni commented Feb 8, 2022

另一个问题 是因为用了canvas所以之前那种写法的 ssr 测试的写法行不通了 所以暂时没写测试

canvas 可以 mock 一下

@07akioni
Copy link
Collaborator

07akioni commented Feb 8, 2022

image

被 watermark 盖住的东西无法选中了

@Sepush
Copy link
Collaborator Author

Sepush commented Feb 8, 2022

image

被 watermark 盖住的东西无法选中了

因为我css加了user-select: none; 当时的考虑是覆盖水印的或许内容并不想让人选中或者复制

@Sepush
Copy link
Collaborator Author

Sepush commented Feb 8, 2022

另一个问题 是因为用了canvas所以之前那种写法的 ssr 测试的写法行不通了 所以暂时没写测试

canvas 可以 mock 一下

好 我去看看怎么写

@07akioni
Copy link
Collaborator

07akioni commented Feb 8, 2022

image
被 watermark 盖住的东西无法选中了

因为我css加了user-select: none; 当时的考虑是覆盖水印的或许内容并不想让人选中或者复制

这还真不好说,可以给个选项吧

很多公司水印只是为了防止员工拍照

@07akioni
Copy link
Collaborator

07akioni commented Feb 8, 2022

不能耽误他们工作

@Sepush
Copy link
Collaborator Author

Sepush commented Feb 8, 2022

image
被 watermark 盖住的东西无法选中了

因为我css加了user-select: none; 当时的考虑是覆盖水印的或许内容并不想让人选中或者复制

这还真不好说,可以给个选项吧

很多公司水印只是为了防止员工拍照

好的

const canvasOffsetTop = offsetTop || gapY / 2
canvas.width = canvasWidth
canvas.height = canvasHeight
if (ctx) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

真要检查应该在一开始获取 canvas context 的时候就检查,不应该等到现在了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getContext 的返回类型可能为 null 这个地方更像是一个 type guard 其实每个出现ctx的地方用 ctx?.xxx 也行 但是每次都写有点麻烦

Comment on lines 57 to 74
fontFamily: {
type: String,
default: 'sans-serif'
},
fontWeight: {
type: [String, Number] as PropType<'normal' | 'light' | 'weight' | number>,
default: 'normal'
},
fontSize: {
type: [Number, String] as PropType<number | string>,
default: 16
},
fontStyle: {
type: [String, Number] as PropType<
'normal' | 'italic' | 'oblique' | number
>,
default: 'normal'
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些值应该可以从主体变量里面拿

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通过 themeOverrides 覆盖就行了

@Sepush Sepush deleted the watermark branch February 14, 2022 08:46
jaulz pushed a commit to jaulz/naive-ui that referenced this pull request Mar 11, 2022
* feat(watermark): new component

Signed-off-by: Sepush <[email protected]>

* changelog

* fix(watermark): render

* feat(watermark): add selectable prop&test case

* refactor(watermark): use useThemeVars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add block-protection component
2 participants