Compare commits

...

8 Commits

17 changed files with 912 additions and 427 deletions

1
.husky/pre-commit Executable file
View File

@@ -0,0 +1 @@
yarn lint-staged

View File

@@ -1,6 +1,6 @@
{ {
"name": "eslint", "name": "eslint",
"version": "9.39.2-sdk", "version": "10.0.0-sdk",
"main": "./lib/api.js", "main": "./lib/api.js",
"type": "commonjs", "type": "commonjs",
"bin": { "bin": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "prettier", "name": "prettier",
"version": "3.8.0-sdk", "version": "3.8.1-sdk",
"main": "./index.cjs", "main": "./index.cjs",
"type": "commonjs", "type": "commonjs",
"bin": "./bin/prettier.cjs" "bin": "./bin/prettier.cjs"

8
lint-staged.config.js Normal file
View File

@@ -0,0 +1,8 @@
export default {
'*.js': (filenames) => {
return [`eslint --max-warnings 10 --fix ${filenames.join(' ')}`, `prettier --write ${filenames.join(' ')}`];
},
'*.{json,md,yml}': (filenames) => {
return [`prettier --write ${filenames.join(' ')}`];
},
};

View File

@@ -5,10 +5,15 @@
"workspaces": [ "workspaces": [
"packages/*" "packages/*"
], ],
"scripts": {
"postinstall": "husky"
},
"devDependencies": { "devDependencies": {
"@advdominion/eslint-config": "workspace:*", "@advdominion/eslint-config": "workspace:*",
"eslint": "^9.39.2", "eslint": "^10.0.0",
"lerna": "^9.0.3", "husky": "^9.1.7",
"prettier": "^3.8.0" "lerna": "^9.0.4",
"lint-staged": "^16.2.7",
"prettier": "^3.8.1"
} }
} }

View File

@@ -64,7 +64,7 @@ njk`
## Опции ## Опции
- `templatesFolder` - строка, обязательный параметр. Путь до папки с файлами шаблонов - `templatesFolder` - строка, обязательный параметр. Путь до папки с файлами шаблонов
- `globals` - массив, необязательный параметр. Глобальные переменные для Nunjucks (например, `[{name: "message", value: "Hello, world!"}]`) - `globals` - массив, необязательный параметр. Глобальные переменные для Nunjucks (например, `[{name: "message", value: "Hello, world!"}]`)
**Важно:** Параметр `cacheDirectory` в опциях babel-loader должен быть отключён. **Важно:** Параметр `cacheDirectory` в опциях babel-loader должен быть отключён.

View File

@@ -1,19 +1,19 @@
import nunjucks from 'nunjucks'; import nunjucks from 'nunjucks';
const babelPluginNunjucks = ({types: t}) => { const babelPluginNunjucks = ({ types: t }) => {
return { return {
pre(state) { pre(state) {
const options = state.opts.plugins[0].options; const options = state.opts.plugins[0].options;
this.njkenv = new nunjucks.Environment(new nunjucks.FileSystemLoader(options.templatesFolder)); this.njkenv = new nunjucks.Environment(new nunjucks.FileSystemLoader(options.templatesFolder));
if (options.globals) { if (options.globals) {
for (const {name, value} of options.globals) { for (const { name, value } of options.globals) {
this.njkenv.addGlobal(name, value); this.njkenv.addGlobal(name, value);
} }
} }
}, },
visitor: { visitor: {
TaggedTemplateExpression(path) { TaggedTemplateExpression(path) {
if (path.get('tag').isIdentifier({name: 'njk'})) { if (path.get('tag').isIdentifier({ name: 'njk' })) {
const render = this.njkenv.renderString(path.node.quasi.quasis[0].value.raw); const render = this.njkenv.renderString(path.node.quasi.quasis[0].value.raw);
path.replaceWith(t.stringLiteral(render)); path.replaceWith(t.stringLiteral(render));
} }

View File

@@ -0,0 +1,25 @@
# css-var
Получение значений CSS-переменных в JS
## Использование
```css
:root {
--z-index: 100;
--height: 100px;
--duration-ms: 100ms;
--duration-s: 100s;
--easing: cubic-bezier(0.4, 0, 0.2, 1);
}
```
```js
import { cssVar } from '@advdominion/css-var';
cssVar('--z-index'); // '1' (String)
cssVar('--height'); // '100px' (String)
cssVar('--duration-ms'); // 100 (Number)
cssVar('--duration-s'); // 100 (Number)
cssVar('--easing'); // cubic-bezier(0.4, 0, 0.2, 1) (String)
```

View File

@@ -0,0 +1,9 @@
export const cssVar = (name, element = document.documentElement) => {
const value = window.getComputedStyle(element).getPropertyValue(name);
const durationRegExp = /(^[\d.]+)(ms|s)$/;
if (durationRegExp.test(value)) {
const [, numericValue, unit] = durationRegExp.exec(value);
return unit === 's' ? numericValue * 1000 : Number(numericValue);
}
return value;
};

View File

@@ -0,0 +1,14 @@
{
"name": "@advdominion/css-var",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://gitea.optiweb.ru/public/frontend.git"
},
"license": "MIT",
"publishConfig": {
"access": "public"
}
}

View File

@@ -22,19 +22,19 @@ const config = [
{ {
rules: { rules: {
...{ ...{
// Включаем правила из категории Possible Problems, которые не включенны в recommended
'array-callback-return': 'error', 'array-callback-return': 'error',
'no-await-in-loop': 'warn', 'no-await-in-loop': 'warn',
'no-duplicate-imports': 'warn', 'no-duplicate-imports': 'warn',
'no-promise-executor-return': 'error', 'no-promise-executor-return': 'error',
'no-self-compare': 'error', 'no-self-compare': 'error',
'no-template-curly-in-string': 'warn', 'no-template-curly-in-string': 'warn',
'no-unassigned-vars': 'warn',
'no-unmodified-loop-condition': 'error', 'no-unmodified-loop-condition': 'error',
'no-unreachable-loop': 'error', 'no-unreachable-loop': 'error',
'no-use-before-define': 'error', 'no-use-before-define': 'error',
'no-useless-assignment': 'warn',
}, },
...{ ...{
// Включаем правила из категории Suggestions, которые не включенны в recommended
'dot-notation': 'warn', 'dot-notation': 'warn',
'eqeqeq': 'error', 'eqeqeq': 'error',
'no-implicit-coercion': 'warn', 'no-implicit-coercion': 'warn',
@@ -49,6 +49,10 @@ const config = [
'prefer-const': 'warn', 'prefer-const': 'warn',
'prefer-template': 'warn', 'prefer-template': 'warn',
}, },
...{
// Переопределяем правила, которые включены в recommended
'no-irregular-whitespace': ['error', { skipTemplates: true }],
},
}, },
}, },
{ {
@@ -74,7 +78,6 @@ const config = [
'unicorn/filename-case': ['warn', { cases: { kebabCase: true, pascalCase: true } }], 'unicorn/filename-case': ['warn', { cases: { kebabCase: true, pascalCase: true } }],
'unicorn/prefer-global-this': 'off', 'unicorn/prefer-global-this': 'off',
'unicorn/prefer-import-meta-properties': 'warn', 'unicorn/prefer-import-meta-properties': 'warn',
'unicorn/prefer-top-level-await': 'off',
'unicorn/prevent-abbreviations': 'off', 'unicorn/prevent-abbreviations': 'off',
}, },
}, },
@@ -107,7 +110,7 @@ const config = [
'vue/no-constant-condition': 'error', 'vue/no-constant-condition': 'error',
'vue/no-empty-pattern': 'error', 'vue/no-empty-pattern': 'error',
'vue/no-implicit-coercion': 'warn', 'vue/no-implicit-coercion': 'warn',
'vue/no-irregular-whitespace': 'error', 'vue/no-irregular-whitespace': ['error', { skipTemplates: true }],
'vue/no-loss-of-precision': 'error', 'vue/no-loss-of-precision': 'error',
'vue/no-negated-condition': 'warn', 'vue/no-negated-condition': 'warn',
'vue/no-sparse-arrays': 'error', 'vue/no-sparse-arrays': 'error',

View File

@@ -12,15 +12,15 @@
"access": "public" "access": "public"
}, },
"dependencies": { "dependencies": {
"@eslint/js": "^9.39.2", "@eslint/js": "^10.0.1",
"eslint-config-prettier": "^10.1.8", "eslint-config-prettier": "^10.1.8",
"eslint-plugin-simple-import-sort": "^12.1.1", "eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unicorn": "^62.0.0", "eslint-plugin-unicorn": "^63.0.0",
"eslint-plugin-vue": "^10.7.0", "eslint-plugin-vue": "^10.7.0",
"globals": "^17.0.0", "globals": "^17.3.0",
"vue-eslint-parser": "^10.2.0" "vue-eslint-parser": "^10.2.0"
}, },
"peerDependencies": { "peerDependencies": {
"eslint": "^9.39.0" "eslint": "^10.0.0"
} }
} }

View File

@@ -19,11 +19,11 @@ await scrollTo(document.querySelector('#example'), 10);
## Параметры ## Параметры
| Параметр | Тип | По умолчанию | Описание | | Параметр | Тип | По умолчанию | Описание |
| :--- | :--- | :--- | :--- | | :------------- | :------------ | :----------- | :------------------------------------------------------------------------- |
| **$el** | `HTMLElement` | — | DOM-элемент, к которому нужно прокрутить страницу | | **$el** | `HTMLElement` | — | DOM-элемент, к которому нужно прокрутить страницу |
| **offset** | `number` | `0` | Величина отступа сверху от целевого элемента | | **offset** | `number` | `0` | Величина отступа сверху от целевого элемента |
| **offsetInPx** | `boolean` | `false` | Тип отступа: `true` — в пикселях, `false` — в процентах от высоты вьюпорта | | **offsetInPx** | `boolean` | `false` | Тип отступа: `true` — в пикселях, `false` — в процентах от высоты вьюпорта |
## Как это работает ## Как это работает

View File

@@ -0,0 +1,22 @@
# Конфигурация для Stylelint
Включает в себя:
- [stylelint-config-standard-scss](https://github.com/stylelint-scss/stylelint-config-standard-scss)
- [stylelint-order](https://github.com/hudochenkov/stylelint-order)
- Проверку кода тега `<style>` в файлах `.vue`
## Использование
### Требования
- [Stylelint](https://stylelint.io/) ^10.0.0
### Подключание
```js
export default {
extends: ['@advdominion/stylelint-config'],
// Дополнительная конфигурация проекта
};
```

View File

@@ -0,0 +1,54 @@
/* eslint-disable unicorn/no-null */
export default {
extends: ['stylelint-config-standard-scss'],
overrides: [
{
files: ['**/*.vue'],
customSyntax: 'postcss-html',
},
],
plugins: ['stylelint-order'],
rules: {
'block-no-empty': null,
'no-invalid-double-slash-comments': null,
'property-disallowed-list': [
'animation',
'background',
'border',
'flex',
'font',
'grid',
'margin',
'padding',
'transition',
],
'color-hex-length': 'long',
'font-weight-notation': 'named-where-possible',
'container-name-pattern': null,
'custom-media-pattern': null,
'custom-property-pattern': null,
'keyframes-name-pattern': null,
'layer-name-pattern': null,
'selector-class-pattern': null,
'selector-id-pattern': null,
'declaration-block-no-redundant-longhand-properties': null,
'scss/double-slash-comment-empty-line-before': null,
'order/order': [
{
type: 'at-rule',
name: 'use',
},
'dollar-variables',
'custom-properties',
'declarations',
{
type: 'at-rule',
name: 'include',
},
'at-rules',
'rules',
],
'order/properties-alphabetical-order': true,
},
};

View File

@@ -0,0 +1,22 @@
{
"name": "@advdominion/stylelint-config",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://gitea.optiweb.ru/public/frontend.git"
},
"license": "MIT",
"publishConfig": {
"access": "public"
},
"dependencies": {
"postcss-html": "^1.8.1",
"stylelint-config-standard-scss": "^17.0.0",
"stylelint-order": "^7.0.1"
},
"peerDependencies": {
"stylelint": "^17.0.0"
}
}

1130
yarn.lock

File diff suppressed because it is too large Load Diff