@clinic/clinic-common

中文文档
7.1.0发布于 2022/08/24MITCommonJS近 30 天下载 18.3万

Clinic.js套房共用部分

中文使用文档
文档目录24 节
  1. 用户
  2. getLoggingPaths(toolName, toolSpecificFiles=[])
  3. checkForTranspiledCode(fileName)
  4. 脚本
  5. buildJs(opts = {})
  6. buildCss(opts = {})
  7. 模板
  8. mainTemplate(opts = {})
  9. 样式
  10. 使用量
  11. 标准
  12. 图标
  13. 图像
  14. 构成部分
  15. 按钮
  16. 链接
  17. 降级
  18. 复选框
  19. 重叠
  20. 走过去
  21. 行走按钮
  22. 帮助者
  23. 旋转器
  24. 许可证

常见诊所.js

整个诊所的共同功能.

目录

用户

getLoggingPaths(toolName, toolSpecificFiles=[])

创建用于构建工具日志信息路径的函数 。 返回函数返回对象映射虚拟路径名称到实际路径名称,例如:

{
  '/systeminfo': '{pid}.clinic-{toolName}/{pid}.clinic-{toolName}-systeminfo'
}

参数 :

  • toolName - 名为Clinic.js工具.
  • toolSpecificFiles - 要生成的文件名的阵列, 在默认值之上(/, (中文(简体) ), /systeminfo) (中文(简体) ). 若为 toolName 是“ 博士” , 默认为 ['/traceevent', '/processstat']。 。 。 . 若为 toolName 是“ bubbleprof ” , 默认为 ['/traceevent', '/stacktrace']。 。 。 .

checkForTranspiledCode(fileName)

用于检查文件内容以获取转录代码的函数 。 检查还包括搜索一个源地图注释.

参数 :

  • fileName - 正在传递的文件的路径.

脚本

buildJs(opts = {})

返回浏览器捆绑( 可读流)

使用量

const buildJs = require('@clinic/clinic-common/scripts/build-js')

const scriptFile = buildJs({
  basedir: __dirname, (String)
  debug: this.debug, (Boolean)
  fakeDataPath, (String)
  scriptPath, (String)
  beforeBundle: b => b.doSomethingWithBundle() (Function)
})

{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢 debug 选项将确保捆绑包含源图

如果 fakeDataPath 未提供,确保单独提供 dataFile 页:1 主模板。 。 。 .

buildCss(opts = {})

返回 PostCSS 组合( 保证)

使用量

const buildCss = require('@clinic/clinic-common/scripts/build-css')

const styleFile = buildCss({
  stylePath, (String)
  debug: this.debug (Boolean)
})

{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢 debug 选项将确保捆绑包含源图


模板

使用模板 stream-template 将流、承诺和字符串插入共同模板,而无需先缓冲.

mainTemplate(opts = {})

返回流图( 可读流)

使用此模板来构建带有常见的染色体,包括一个头和弹出托盘的工具输出.

这将需要结合共同的UI使用 样式 和托盘 行为。 。 。 .

使用量

const mainTemplate = require('@clinic/clinic-common/templates/main')

const outputFile = mainTemplate({
  htmlClass: '', (String)
  favicon: 'URI', (String)
  title: 'Title', (String)
  styles: styleFile, (Readable Stream)
  data: dataFile, (Readable Stream)
  script: scriptFile, (Promise)
  headerLogoUrl: 'https://github.com/somewhere', (String)
  headerLogoTitle: 'Logo title', (String)
  headerLogo: logoFile, (String)
  headerText: 'Text', (String)
  toolVersion: '1.2.3', (String)
  uploadId: 'ID', (String)
  head: 'extra <head> content', (String)
  body: 'extra <body> contents' (String)
})

💡 opts.data 可以提供将分析的JSON输出放入自己的脚本标记. 未提供分析数据时,应在 scriptFile 由用户进行.


样式

可导入 CSS 在使用时包含 mainTemplate 与《京都议定书》 buildCss 脚本可以确保它与特定工具的样式捆绑在一起. 这为信头和托盘增加了一些全局样式. CSS使用BEM来写来避免特异性,并具有以下可被推翻的CSS变量:

html {
  --nc-colour-text: white;
  --nc-colour-code: #E9F100;
  --nc-colour-notification-dot: #2165E5;
  --nc-colour-tray-backdrop: rgba(0, 0, 0, 0.6);
  --nc-colour-tray: #292d39;
  --nc-colour-header-background: #292d39;
}

使用量

@import '@clinic/clinic-common/styles/styles.css';

.your {
  tool: styles;
}

标准

CSS 应使用使用 贝姆 作为更好的封装和较低规格的命名公约.

里面,所有班级都有卖家 .nc- 以避免类别名称与第三方或工具特定样式相撞。 对于基于工具的样式,所有样式都应遵循相同的惯例,对工具前缀如下:

.ncd- Clinic.js Doctor
.ncb- Clinic.js Bubbleprof
.ncf- Clinic.js Flame

细目

/* Block: Tray component  */
.nc-tray { ...

/* Element: Tray inner component */
.nc-tray__inner { ...

图标

返回一个字典对象,其密钥是图标名称,其值是 svg 文件内容. 用于内置 svg 文件 .

在此查找图标列表

使用示例 :

const icons = require('@clinic/clinic-common/icons')

console.log(icons.activity)

output:
`<svg class="icon-img activity-svg" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.7069 3.00248C11.1545 3.03412 11.5262 3.36 11.6161 3.79959L14.2191 16.5255L15.7076 12.796C15.8593 12.4159 16.2272 12.1667 16.6364 12.1667H21C21.5523 12.1667 22 12.6144 22 13.1667C22 13.7189 21.5523 14.1667 21 14.1667H17.314L14.8379 20.3707C14.6741 20.7811 14.2603 21.0353 13.8202 20.996C13.3801 20.9568 13.0179 20.6333 12.9294 20.2004L10.3742 7.70839L8.30541 13.5029C8.1633 13.9009 7.78629 14.1667 7.36364 14.1667H3C2.44772 14.1667 2 13.7189 2 13.1667C2 12.6144 2.44772 12.1667 3 12.1667H6.65884L9.69459 3.66375C9.84545 3.24118 10.2593 2.97084 10.7069 3.00248Z" fill="#7A7F8F"></path>
</svg>`

或者您可以单独导入所需的图标 :

const cog = require('@clinic/clinic-common/icons/cog')
...
`<span class="my_icon_wrapper">${cog}</span>`

Basic 样式可以通过在您主 ass 文件( 如果您使用) 中添加以下行来导入页面 邮政进口:

@import "@clinic/clinic-common/icons/style.css";

这将增加以下规则:

  /* SVG icons */
  svg.icon-img {
    /* Default to same size as adjacent text */
    width: 1em;
    height: 1em;
    display: block;
  }

使用图标作为 BG 图像 也可以使用图标作为背景图像. 在你身边 style.css 导入所需的图标,即:

@import "@clinic/clinic-common/icons/cog.css";

这将生成以下 css 可变 数字 :

html {
    --cog-icon: url(data:image/svg+xml;utf8,<svg width="24" height="24" viewBox="0 0 24 24" fil…2 19.0006 14.7857 18.9737 14.8485L18.0545 14.4545Z" fill="#7A7F8F"></svg>);
}

现在你可以像这样使用它:

.settings-button{
  background-image: var(--cog-icon);
  width: 24px;
  height: 24px;
...
}

图像

可以嵌入 Base64-Encoded 图像.

scripts/build-images.js 揭露两种方法:

  path(sourceDir, exportDir)
  // and
  file(filePath, exportDir)

支持的文件扩展名为: png jpeg jpg 财务报告和审定财务报表 gif

使用实例 :

  // in your npm script
  const buildImg = require('@clinic/clinic-common/scripts/build-images')
  buildImg.file('my/amazing/image.jpg', 'visualizer/assets/images')

  // in your .js file you first import the image
  const myImage = require('visualizer/assets/images/image.js')

  // and then you use it
  `<img src=${myImage} ... />

构成部分

一套基础组件和帮助者. 所有组件样式都是 @imported 内 style.css 并且可以进口如下:

@import "@clinic/clinic-common/base/style.css";

每个组件可单独导入:

const button = require('@clinic/clinic-common/base/button.js')

或者您可以同时导入多个组件 :

const { button, checkbox, contextOverlay } = require('@clinic/clinic-common/base')

每个组件都是返回 HTML 元素的函数

按钮

  // button({label, classNames = [], leftIcon = '', rightIcon = '', disabled = false, onClick, title})
  myForm.appendChild(button({
    label: 'Submit',
    title: 'Click me!',
    classNames: ['submitBtn', 'primaryButton'],
    leftIcon: submitIcon,
    onClick: () => validateAndSubmit()
  }))

样式可以通过定义您 CSS 中的 CSS vars 来自定义

  --nc-button-bgColor
  --nc-button-color
  --nc-button-fontSize
  --nc-button-bgHover
  --nc-button-hoverOutline
  // link({ label, classNames = [], leftIcon = '', rightIcon = '', href, title = '', target = '' })
  div.appendChild(link({
    label: 'Documentation',
    title: 'Click me!',
    href: '/docs',
    classNames: ['openDocs'],
    rightIcon: externalLink
  }))

样式可以通过定义您 CSS 中的 CSS vars 来自定义

  --nc-link-bgColor
  --nc-link-color
  --nc-link-fontSize
  --nc-link-bgHover
  --nc-link-hoverOutline

降级

// dropdown({ label, classNames = [], disabled = false, expandAbove = false, content })
  div.appendChild(dropdown({
    classNames: ['key-v8'],
    label: checkbox({
      leftLabel: 'V8',
      onChange: e => {
        this.setCodeAreaVisibility('all-v8', e.target.checked)
      }
    }),
    content: `<span>This is some content. ${greetings}</span>`,
    expandAbove: true
  }))

样式可以通过定义您 CSS 中的 CSS vars 来自定义

  --nc-checkbox-bgColor
  --nc-checkbox-hoverColor
  --nc-checkbox-hoverOutline
  --nc-checkbox-borderColor
  --nc-checkbox-checkedIconColor
  --nc-checkbox-indeterminateIconColor

复选框

  // checkbox({ leftLabel, rightLabel, classNames = [], checked = false, disabled = false, indeterminate = false, onChange })
  checkbox({
    classNames: ['key-core'],
    leftLabel: `<span class='after-bp-1'>Node JS</span>
      <span class='before-bp-1'>Node</span>`,
    onChange: e => this.setCodeAreaVisibility('core', e.target.checked)
  })

样式可以通过定义您 CSS 中的 CSS vars 来自定义

  --nc-dropdown-borderColor
  --nc-dropdown-color
  --nc-dropdown-bgColor
  --nc-dropdown-contentBg
  --nc-dropdown-contentBorderColor

重叠

显示给定的覆盖符 msg 位于目标Element 或目标Rect旁边

若为 目标元素 财务报告和审定财务报表 目标矩形 为: null||undefined 然后将覆盖内容集中在页面上.

  // const options = {
  //   msg,
  //   targetElement,
  //   targetRect,
  //   outerRect,
  //   offset,
  //   pointerCoords,
  //   verticalAlign = 'bottom'
  // }

    overlay.show({
      msg: this.wrapper,
      classNames: ['wt-container'],
      offset: { y: 10, height: 20 },
      targetElement: document.querySelector('.my-cool-element'),
      showArrow: true
    })

走过去

用于显示UI特性分步向导的类.

const wt = new Walkthrough({ steps = [], showBackdrop = false, showControls = true, onProgress })

WT 揭露下列方法:

  `start`
  `next`
  `end`
  `skipTo`

steps 是一个对象阵列,每个步骤都有以下属性:

  • attachTo: 用于识别所描述元素的 css 选择器
  • msg: 要显示的消息的 HTML 元素或字符串模板

onProgress(index) 当行走组件状态发生变化时,会被触发.

// steps definition example
const steps = [
  {
    attachTo: '#selection-controls',
    msg: `
    <div>
      <div class="step-1">
        ${flame}
        Hello, and welcome to Flame!
      </div>
    </div>
    `
  },
  {
    attachTo: '.frame-dropdown',
    msg: `
    <div>
      <p>Do you like Flame?</p>
      <img style="width:400px; height: 225px; display:block;" src="https://images.pexels.com/photos/750225/pexels-photo-750225.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" />
      ${docs}
    </div>`
  }
]

行走按钮

用于激活行道的工具的标准化按钮

  // walkthroughButton(steps, onProgress, [label])
  const hdtw = walkthroughButton(wtSteps, index => {
    this.pushHistory()
  })

  // hdtw.WtPlayer -> the embeded walkthrough player
  // hdtw.button -> the button instance to append to the DOM

  // label defaults to 'How does this work'

帮助者

一套有用的函数. 目前载有:

  • toHtml(data) 数据可以是字符串,函数或HTMLElement. 输出为 HTML 元素
  const myHtml = helpers.toHtml(`<span>${greetings}</span>`)
  // or
  const myHtml = helpers.toHtml(getGreetings)

旋转器

添加 loading spinner 请导入您的应用程序 @clinic/clinic-common/spinner 在你身边 main.js 和样式.cs文件到您的 style.css

示例 主要为.js

require('@clinic/clinic-common/spinner')

样式.css

@import "@clinic/clinic-common/spinner/style.css";

这将在加载页面时显示加载旋转器 . 如果您需要稍后显示自旋器, 也许当应用程序忙于进行一些计算时, 您可以在程序上将自旋器打开和关闭, 如下例所示 :

const spinner = require('@clinic/clinic-common/spinner')

...
const redrawSpinner = spinner.attachTo(document.querySelector('#myHtmlContainerNode'))
redrawSpinner.show('Melting the North pole down...')

// when finished
redrawSpinner.hide()

旋转边框默认为白色, 您可以设置 cs s var 来自定义 --spinner-border-color 在您的阴道中:

html {
/* this will set the colour for the page-loading spinner*/
  --spinner-border-color: --my-fancy-primary-color;
}

#myHtmlContainerNode {
  /* this will set the colour for the in-page spinner*/
  /* this is optional and inherits from `html` if not defined*/
  --spinner-border-color: --my-fancy-secondary-color;
}

将自旋器附加到一个元素中,将产生一个新的实例: spinner 可以在开关/关闭后使用。 当显示自旋器时,自旋器所附带的元素会变得模糊并被一个暗箱所覆盖.

ezgif com-video-to-gif

许可证

麻省理工学院

版本与发布记录

@clinic/clinic-common 共发布 2 个版本,首次发布于 2021/11/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
7.1.0latest2022/08/244 年前
7.0.02021/11/124 年前

关于 @clinic/clinic-common 的常见问题

@clinic/clinic-common 是什么?

Clinic.js套房共用部分

如何安装 @clinic/clinic-common?

在项目目录运行 npm install @clinic/clinic-common,或使用 pnpm add / yarn add / bun add。

@clinic/clinic-common 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/clinic__clinic-common 是否存在。

@clinic/clinic-common 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@clinic/clinic-common 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 12.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@clinic/clinic-common 可以商用吗?

@clinic/clinic-common 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@clinic/clinic-common 的下载量有多少?

根据 npm 官方下载统计,@clinic/clinic-common 在 2026/10/10 – 2026/11/08 这 30 天内被下载 182,511 次,日均约 6,084 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@clinic/clinic-common 还在维护吗?

最新版本 7.1.0 发布于 2022/08/24(4 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/11/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。