@hackersheet/next-document-content-kifu 0.1.0-alpha.1

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @hackersheet/next-document-content-kifu
2
+
3
+ Hacker Sheet document content kifu components for Next.js
@@ -0,0 +1,4 @@
1
+ export { default as Kifu } from './kifu/kifu.js';
2
+ export { default as KifuTo } from './kifu-to/kifu-to.js';
3
+ import '@hackersheet/react-document-content';
4
+ import 'react';
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var components_exports = {};
30
+ __export(components_exports, {
31
+ Kifu: () => import_kifu.default,
32
+ KifuTo: () => import_kifu_to.default
33
+ });
34
+ module.exports = __toCommonJS(components_exports);
35
+ var import_kifu = __toESM(require("./kifu/kifu"));
36
+ var import_kifu_to = __toESM(require("./kifu-to/kifu-to"));
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ Kifu,
40
+ KifuTo
41
+ });
@@ -0,0 +1,6 @@
1
+ import { KifuComponentProps } from '@hackersheet/react-document-content';
2
+ import React from 'react';
3
+
4
+ declare function Kifu({ code, language }: KifuComponentProps): React.JSX.Element | null;
5
+
6
+ export { Kifu as default };
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var kifu_exports = {};
31
+ __export(kifu_exports, {
32
+ default: () => Kifu
33
+ });
34
+ module.exports = __toCommonJS(kifu_exports);
35
+ var import_kifu_for_js = require("kifu-for-js");
36
+ var import_navigation = require("next/navigation");
37
+ var import_react = __toESM(require("react"));
38
+ function Kifu({ code, language }) {
39
+ const [, filename] = language.split(":");
40
+ const searchParams = (0, import_navigation.useSearchParams)();
41
+ const id = filename ? `user-content-${filename}` : void 0;
42
+ const [kifuStore] = (0, import_react.useState)(() => new import_kifu_for_js.KifuStore({ kifu: code }));
43
+ (0, import_react.useEffect)(() => {
44
+ initKifuUserSettings();
45
+ }, []);
46
+ (0, import_react.useEffect)(() => {
47
+ const newPly = Number(searchParams.get("ply") ?? 0);
48
+ const hash = typeof window !== "undefined" ? window.location.hash.replace(/^#!?/, "") : "";
49
+ if (hash === id) {
50
+ kifuStore.player.goto(newPly);
51
+ }
52
+ }, [searchParams, kifuStore, id]);
53
+ if (!kifuStore) {
54
+ return null;
55
+ }
56
+ return /* @__PURE__ */ import_react.default.createElement("div", { className: "my-4 flex justify-center", id }, /* @__PURE__ */ import_react.default.createElement(import_kifu_for_js.KifuLite, { style: { width: "100%" }, kifuStore }));
57
+ }
58
+ function initKifuUserSettings() {
59
+ const LOCALSTORAGE_KEY = "kifuforjs";
60
+ const defaultSettings = {
61
+ hapticFeedback: false
62
+ };
63
+ const settings = localStorage.getItem(LOCALSTORAGE_KEY);
64
+ if (!settings) {
65
+ localStorage.setItem(LOCALSTORAGE_KEY, JSON.stringify(defaultSettings));
66
+ }
67
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { KifuToComponentProps } from '@hackersheet/react-document-content';
3
+
4
+ declare function KifuTo({ id, ply, label: defaultLabel }: KifuToComponentProps): React.JSX.Element;
5
+
6
+ export { KifuTo as default };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var kifu_to_exports = {};
30
+ __export(kifu_to_exports, {
31
+ default: () => KifuTo
32
+ });
33
+ module.exports = __toCommonJS(kifu_to_exports);
34
+ var import_link = __toESM(require("next/link"));
35
+ var import_react = __toESM(require("react"));
36
+ function KifuTo({ id, ply, label: defaultLabel }) {
37
+ const fullId = `user-content-${id}`;
38
+ const href = `?ply=${ply}#${fullId}`;
39
+ const label = defaultLabel ?? `${ply}\u624B\u76EE`;
40
+ return /* @__PURE__ */ import_react.default.createElement(import_link.default, { href }, label);
41
+ }
@@ -0,0 +1,4 @@
1
+ export { default as Kifu } from './components/kifu/kifu.js';
2
+ export { default as KifuTo } from './components/kifu-to/kifu-to.js';
3
+ import '@hackersheet/react-document-content';
4
+ import 'react';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var src_exports = {};
17
+ module.exports = __toCommonJS(src_exports);
18
+ __reExport(src_exports, require("./components"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./components")
22
+ });
@@ -0,0 +1,4 @@
1
+ export { default as Kifu } from './kifu/kifu.mjs';
2
+ export { default as KifuTo } from './kifu-to/kifu-to.mjs';
3
+ import '@hackersheet/react-document-content';
4
+ import 'react';
@@ -0,0 +1,6 @@
1
+ import Kifu from "./kifu/kifu";
2
+ import KifuTo from "./kifu-to/kifu-to";
3
+ export {
4
+ Kifu,
5
+ KifuTo
6
+ };
@@ -0,0 +1,6 @@
1
+ import { KifuComponentProps } from '@hackersheet/react-document-content';
2
+ import React from 'react';
3
+
4
+ declare function Kifu({ code, language }: KifuComponentProps): React.JSX.Element | null;
5
+
6
+ export { Kifu as default };
@@ -0,0 +1,37 @@
1
+ "use client";
2
+ import { KifuLite, KifuStore } from "kifu-for-js";
3
+ import { useSearchParams } from "next/navigation";
4
+ import React, { useEffect, useState } from "react";
5
+ function Kifu({ code, language }) {
6
+ const [, filename] = language.split(":");
7
+ const searchParams = useSearchParams();
8
+ const id = filename ? `user-content-${filename}` : void 0;
9
+ const [kifuStore] = useState(() => new KifuStore({ kifu: code }));
10
+ useEffect(() => {
11
+ initKifuUserSettings();
12
+ }, []);
13
+ useEffect(() => {
14
+ const newPly = Number(searchParams.get("ply") ?? 0);
15
+ const hash = typeof window !== "undefined" ? window.location.hash.replace(/^#!?/, "") : "";
16
+ if (hash === id) {
17
+ kifuStore.player.goto(newPly);
18
+ }
19
+ }, [searchParams, kifuStore, id]);
20
+ if (!kifuStore) {
21
+ return null;
22
+ }
23
+ return /* @__PURE__ */ React.createElement("div", { className: "my-4 flex justify-center", id }, /* @__PURE__ */ React.createElement(KifuLite, { style: { width: "100%" }, kifuStore }));
24
+ }
25
+ function initKifuUserSettings() {
26
+ const LOCALSTORAGE_KEY = "kifuforjs";
27
+ const defaultSettings = {
28
+ hapticFeedback: false
29
+ };
30
+ const settings = localStorage.getItem(LOCALSTORAGE_KEY);
31
+ if (!settings) {
32
+ localStorage.setItem(LOCALSTORAGE_KEY, JSON.stringify(defaultSettings));
33
+ }
34
+ }
35
+ export {
36
+ Kifu as default
37
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { KifuToComponentProps } from '@hackersheet/react-document-content';
3
+
4
+ declare function KifuTo({ id, ply, label: defaultLabel }: KifuToComponentProps): React.JSX.Element;
5
+
6
+ export { KifuTo as default };
@@ -0,0 +1,11 @@
1
+ import Link from "next/link";
2
+ import React from "react";
3
+ function KifuTo({ id, ply, label: defaultLabel }) {
4
+ const fullId = `user-content-${id}`;
5
+ const href = `?ply=${ply}#${fullId}`;
6
+ const label = defaultLabel ?? `${ply}\u624B\u76EE`;
7
+ return /* @__PURE__ */ React.createElement(Link, { href }, label);
8
+ }
9
+ export {
10
+ KifuTo as default
11
+ };
@@ -0,0 +1,4 @@
1
+ export { default as Kifu } from './components/kifu/kifu.mjs';
2
+ export { default as KifuTo } from './components/kifu-to/kifu-to.mjs';
3
+ import '@hackersheet/react-document-content';
4
+ import 'react';
@@ -0,0 +1 @@
1
+ export * from "./components";
package/license.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Hacker Sheet
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/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@hackersheet/next-document-content-kifu",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Hacker Sheet document content kifu components for Next.js",
5
+ "keywords": [],
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/hackersheet/javascript.git",
9
+ "directory": "packages/next-document-content-kifu"
10
+ },
11
+ "license": "MIT",
12
+ "author": "",
13
+ "exports": {
14
+ ".": {
15
+ "require": "./dist/cjs/index.js",
16
+ "import": "./dist/esm/index.mjs",
17
+ "types": "./dist/esm/index.d.ts"
18
+ }
19
+ },
20
+ "main": "./dist/cjs/index.js",
21
+ "module": "./dist/esm/index.mjs",
22
+ "types": "./dist/esm/index.d.ts",
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "dependencies": {
27
+ "@hackersheet/core": "alpha",
28
+ "@hackersheet/react-document-content": "alpha",
29
+ "kifu-for-js": "^5.4.1"
30
+ },
31
+ "devDependencies": {
32
+ "@types/react": "^18.0.0",
33
+ "@types/react-dom": "^18.0.0",
34
+ "next": "14.2.5",
35
+ "react": "^18.0.0",
36
+ "react-dom": "^18.0.0",
37
+ "@hackersheet/eslint-config-custom": "0.0.0"
38
+ },
39
+ "peerDependencies": {
40
+ "next": "^14.0.0",
41
+ "react": "^18.0.0",
42
+ "react-dom": "^18.0.0"
43
+ },
44
+ "scripts": {
45
+ "build": "rm -rf ./dist && pnpm tsup",
46
+ "check": "pnpm tsc && pnpm lint",
47
+ "format": "pnpm -w format && pnpm lint:fix",
48
+ "lint": "eslint \"**/*.{ts,tsx}\"",
49
+ "lint:fix": "eslint --fix \"**/*.{ts,tsx}\"",
50
+ "pub": "pnpm publish --access=public --tag alpha",
51
+ "test": "echo \"Error: no test specified\" && exit 1"
52
+ }
53
+ }