quill - QuillJS:如何为描边颜色添加格式
问题描述
在 quill 1.3.7 编辑器中,我想添加一个按钮来选择笔触颜色。
我尝试的是:复制此https://github.com/quilljs/quill/blob/develop/formats/color.js并将大多数“ Color
”替换为“ Stroke
”:
import Quill from 'quill';
const Parchment = Quill.import('parchment');
class StrokeAttributor extends Parchment.Attributor.Style {
value(domNode) {
let value = super.value(domNode);
if (!value.startsWith('rgb(')) return value;
value = value.replace(/^[^\d]+/, '').replace(/[^\d]+$/, '');
const hex = value.split(',').map(component => `00${parseInt(component, 10).toString(16)}`.slice(-2)).join('');
return `#${hex}`;
}
}
const StrokeClass = new Parchment.Attributor.Class('stroke', 'ql-stroke', {
scope: Parchment.Scope.INLINE,
});
const StrokeStyle = new StrokeAttributor('stroke', '-webkit-text-stroke-color', {
scope: Parchment.Scope.INLINE,
});
Quill.register(StrokeClass, true);
Quill.register(StrokeStyle, true);
工具栏容器选项以这种方式扩展:this.colors = [{ 'color': [] }, { 'stroke': [] }, { 'background': [] }];
像这样添加颜色值this.colors = [{ 'color': [] }, { 'stroke': ['#888888'] }, { 'background': [] }];
也不会显示可选择的颜色选项。
创建 Stroke Selector 的另一个想法是这样的示例https://github.com/quilljs/quill/blob/develop/formats/italic.js
:
import Quill from 'quill';
const Parchment = Quill.import('parchment');
const BackgroundClass = Quill.import('attributors/class/background');
class StrokeClass extends BackgroundClass {};
StrokeClass.attrName = 'stroke';
StrokeClass.keyName = 'ql-stroke';
class StrokeStyle extends BackgroundStyle {};
StrokeStyle.attrName = 'stroke';
StrokeStyle.keyName = '-webkit-text-stroke-color';
Quill.register(StrokeClass, true);
Quill.register(StrokeStyle, true);
但这显示了一个错误:Uncaught TypeError: Class extends value #<ClassAttributor> is not a constructor or null
什么是有效的(不幸的是,它应该不彻底):当直接在 BackgroundClass 设置属性值时,格式化工作(只要-webkit-text-stroke-width
在整个 CSS 中有设置):
import Quill from 'quill';
const BackgroundClass = Quill.import('attributors/class/background');
const BackgroundStyle = Quill.import('attributors/style/background');
BackgroundClass.keyName = 'ql-stroke';
BackgroundStyle.keyName = '-webkit-text-stroke-color';
由于不是每个浏览器都支持-webkit-text-stroke-width
(https://developer.mozilla.org/de/docs/Web/CSS/-webkit-text-stroke-width),Quill 扩展理想地设置样式属性-webkit-text-stroke
并使用例如1px [selected colorname]
或0px
如果有没有选择颜色。有什么可以复制的代码吗?
解决方案
推荐阅读
- random - Discord.js - 从文件夹错误发布图像
- brother-print-sdk - Brother QL-800 - Java Raw 打印
- python - Plotly:如何使用下拉菜单在每日烛台和每小时烛台之间进行切换?
- python - 如何在 tensorflow 上获得指向模型层的指针?
- python - 我使用 opencv python 进行人脸检测的代码是显示下面给出的错误消息
- java - 如何在模块之间共享外部身份验证
- prometheus - 从多个指标(相同的标签集,不同的名称)绘制 rate() 时如何避免“向量不能包含具有相同标签集的指标”错误
- javascript - Webpack css 包中不包含 FontAwesome 代码
- multithreading - gcc free() 仅在多线程环境中崩溃
- javascript - 如何使用 Firebase 身份验证制作受保护的网页/面板?