@viewfly/scoped-css 0.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 TanBo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ Viewfly
2
+ ================================
3
+
4
+ Viewfly 是一个简单、数据驱动的前端视图库,完整文档请参考官方网站:[viewfly.org](https://viewfly.org)
@@ -0,0 +1,2 @@
1
+ import { ComponentSetup } from '@viewfly/core';
2
+ export declare function scopedCss<T extends ComponentSetup>(css: Record<string, string>, factory: T): T;
@@ -0,0 +1,33 @@
1
+ import { JSXElement, Props } from '@viewfly/core';
2
+
3
+ function replaceCSSClass(template, css) {
4
+ if (template instanceof JSXElement) {
5
+ const cssNames = template.props.attrs.get('css');
6
+ if (typeof cssNames !== 'string') {
7
+ return;
8
+ }
9
+ template.props.attrs.delete('css');
10
+ const classes = template.props.classes;
11
+ Props.classToArray(cssNames).forEach(i => {
12
+ const klass = css[i];
13
+ if (klass) {
14
+ classes.add(klass);
15
+ }
16
+ });
17
+ template.props.children.forEach(child => {
18
+ replaceCSSClass(child, css);
19
+ });
20
+ }
21
+ }
22
+ function scopedCss(css, factory) {
23
+ return function (props) {
24
+ const componentRender = factory(props);
25
+ return function () {
26
+ const template = componentRender();
27
+ replaceCSSClass(template, css);
28
+ return template;
29
+ };
30
+ };
31
+ }
32
+
33
+ export { scopedCss };
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ var core = require('@viewfly/core');
4
+
5
+ function replaceCSSClass(template, css) {
6
+ if (template instanceof core.JSXElement) {
7
+ const cssNames = template.props.attrs.get('css');
8
+ if (typeof cssNames !== 'string') {
9
+ return;
10
+ }
11
+ template.props.attrs.delete('css');
12
+ const classes = template.props.classes;
13
+ core.Props.classToArray(cssNames).forEach(i => {
14
+ const klass = css[i];
15
+ if (klass) {
16
+ classes.add(klass);
17
+ }
18
+ });
19
+ template.props.children.forEach(child => {
20
+ replaceCSSClass(child, css);
21
+ });
22
+ }
23
+ }
24
+ function scopedCss(css, factory) {
25
+ return function (props) {
26
+ const componentRender = factory(props);
27
+ return function () {
28
+ const template = componentRender();
29
+ replaceCSSClass(template, css);
30
+ return template;
31
+ };
32
+ };
33
+ }
34
+
35
+ exports.scopedCss = scopedCss;
@@ -0,0 +1 @@
1
+ export * from './css-modules';
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@viewfly/scoped-css",
3
+ "version": "0.0.1-alpha.0",
4
+ "description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience",
5
+ "main": "./bundles/index.js",
6
+ "module": "./bundles/index.esm.js",
7
+ "typings": "./bundles/public-api.d.ts",
8
+ "scripts": {
9
+ "start": "webpack-dev-server",
10
+ "test": "cross-env env=test jest",
11
+ "test-c": "cross-env env=test jest --coverage",
12
+ "build:lib": "rimraf bundles && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
13
+ "publish:lib": "npm run build:lib && npm publish --access=public"
14
+ },
15
+ "license": "MIT",
16
+ "keywords": [],
17
+ "dependencies": {
18
+ "@viewfly/core": "^0.0.1-alpha.0"
19
+ },
20
+ "devDependencies": {
21
+ "@rollup/plugin-commonjs": "^23.0.2",
22
+ "@rollup/plugin-typescript": "^9.0.2",
23
+ "rimraf": "^3.0.2",
24
+ "rollup": "^3.2.5",
25
+ "tslib": "^2.4.1"
26
+ },
27
+ "author": {
28
+ "name": "Tanbo",
29
+ "email": "tanbohb@qq.com"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/viewfly/viewfly.git"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/viewfly/viewfly.git/issues"
37
+ }
38
+ }
@@ -0,0 +1,24 @@
1
+ import commonjs from '@rollup/plugin-commonjs'
2
+ import typescript from '@rollup/plugin-typescript'
3
+
4
+ export default {
5
+ input: 'src/public-api.ts',
6
+ output: [
7
+ {
8
+ file: './bundles/index.js',
9
+ format: 'cjs'
10
+ },
11
+ {
12
+ file: './bundles/index.esm.js',
13
+ format: 'esm'
14
+ }
15
+ ],
16
+ plugins: [
17
+ commonjs(),
18
+ typescript({
19
+ compilerOptions: {
20
+ paths: {}
21
+ }
22
+ })
23
+ ]
24
+ }
@@ -0,0 +1,32 @@
1
+ import { JSXElement, ComponentSetup, Props } from '@viewfly/core'
2
+
3
+ function replaceCSSClass(template, css: Record<string, string>) {
4
+ if (template instanceof JSXElement) {
5
+ const cssNames = template.props.attrs.get('css')
6
+ if (typeof cssNames !== 'string') {
7
+ return
8
+ }
9
+ template.props.attrs.delete('css')
10
+ const classes = template.props.classes
11
+ Props.classToArray(cssNames).forEach(i => {
12
+ const klass = css[i]
13
+ if (klass) {
14
+ classes.add(klass)
15
+ }
16
+ })
17
+ template.props.children.forEach(child => {
18
+ replaceCSSClass(child, css)
19
+ })
20
+ }
21
+ }
22
+
23
+ export function scopedCss<T extends ComponentSetup>(css: Record<string, string>, factory: T): T {
24
+ return function (props: any) {
25
+ const componentRender = factory(props)
26
+ return function () {
27
+ const template = componentRender()
28
+ replaceCSSClass(template, css)
29
+ return template
30
+ }
31
+ } as T
32
+ }
@@ -0,0 +1 @@
1
+ export * from './css-modules'
package/tsconfig.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "useDefineForClassFields": false,
5
+ "emitDecoratorMetadata": true,
6
+ "experimentalDecorators": true,
7
+ "allowSyntheticDefaultImports": true,
8
+ "lib": [
9
+ "esnext",
10
+ "dom"
11
+ ],
12
+ "target": "es6",
13
+ "strict": true,
14
+ "module": "es2020",
15
+ "moduleResolution": "node",
16
+ "inlineSourceMap": true,
17
+ "inlineSources": true,
18
+ "noImplicitAny": false,
19
+ "ignoreDeprecations": "5.0",
20
+ "suppressImplicitAnyIndexErrors": true,
21
+ "outDir": "bundles/",
22
+ "downlevelIteration": true,
23
+ "paths": {
24
+ "@viewfly/core": [
25
+ "../core/src/public-api.ts"
26
+ ]
27
+ }
28
+ },
29
+ "include": [
30
+ "src"
31
+ ],
32
+ "ts-node": {
33
+ "compilerOptions": {
34
+ "module": "CommonJS"
35
+ }
36
+ }
37
+ }