@plaidev/karte-action-sdk 1.1.176-28039456.06c11c78 → 1.1.177-28039844.a230804c

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.
@@ -1,8 +1,33 @@
1
- import 'svelte/easing';
2
1
  import { writable, get } from 'svelte/store';
3
2
  import { onMount as onMount$1, onDestroy as onDestroy$1, beforeUpdate as beforeUpdate$1, afterUpdate as afterUpdate$1, tick as tick$1, setContext, getContext, createEventDispatcher } from 'svelte';
4
3
  import { SvelteComponent, init, safe_not_equal, create_slot, update_slot_base, get_all_dirty_from_scope, get_slot_changes, transition_in, transition_out, append_styles, empty, insert_hydration, group_outros, check_outros, detach, component_subscribe, element, space, claim_element, children, claim_space, attr, noop, listen, null_to_empty, is_function, create_component, claim_component, mount_component, destroy_component, add_render_callback, create_in_transition, binding_callbacks, set_style, svg_element, claim_svg_element, append_hydration, destroy_each, text, claim_text, set_data, src_url_equal, HtmlTagHydration, claim_html_tag, construct_svelte_component, subscribe } from 'svelte/internal';
4
+ import 'svelte/easing';
5
+
6
+ /** @internal */
7
+ const ACTION_HOOK_LABEL = '__ACTION_HOOK__';
8
+ /** @internal */
9
+ const KARTE_ACTION_ROOT = 'karte-action-root';
10
+ /** @internal */
11
+ const KARTE_ACTION_RID = 'karte-action-rid';
12
+ /** @internal */
13
+ const KARTE_ACTION_SHORTEN_ID = 'karte-action-id';
14
+ /** @internal */
15
+ const ALL_ACTION_ID = 'KARTE_ALL_ACTION_ID';
16
+ /** @internal */
17
+ const ALL_ACTION_SHORTEN_ID = 'KARTE_ALL_ACTION_SHORTEN_ID';
18
+ // -------- The following codes are deprecated --------
19
+ /**
20
+ * 非推奨
21
+ *
22
+ * @deprecated 非推奨
23
+ *
24
+ * @internal
25
+ */
26
+ const KARTE_MODAL_ROOT = 'karte-modal-root';
5
27
 
28
+ /**
29
+ * 静的変数に関連するコードを管理する
30
+ */
6
31
  /** @internal */
7
32
  const PropTypes = [
8
33
  'BooleanKeyword',
@@ -247,6 +272,10 @@ const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused
247
272
  const isPreview = () => {
248
273
  return true;
249
274
  };
275
+ // prettier-ignore
276
+ /** @internal */
277
+ const actionId = ALL_ACTION_ID
278
+ ;
250
279
  /** @internal */
251
280
  const handleFocus = (node) => (e) => {
252
281
  if (node) {
@@ -445,6 +474,23 @@ function hasSuffix(value, suffix) {
445
474
  function getGoogleFontsParam() {
446
475
  return 'family=' + Fonts.map(font => font.replace(/ /g, '+')).join('&family=');
447
476
  }
477
+ /** @internal */
478
+ const h = (type, props, ...children) => {
479
+ const el = document.createElement(type);
480
+ for (const key of Object.keys(props)) {
481
+ const v = props[key];
482
+ if (key === 'style') {
483
+ Object.assign(el.style, v);
484
+ }
485
+ else {
486
+ el.setAttribute(key, v);
487
+ }
488
+ }
489
+ for (const child of children) {
490
+ el.appendChild(child);
491
+ }
492
+ return el;
493
+ };
448
494
 
449
495
  /**
450
496
  * Store to handle action setting
@@ -807,385 +853,109 @@ function resetVariables() {
807
853
  */
808
854
  const formData = writable({});
809
855
 
810
- function isEmpty(value) {
811
- if (Array.isArray(value)) {
812
- return value.length === 0;
813
- }
814
- else {
815
- return !value;
816
- }
817
- }
856
+ /**
857
+ * アクションのログの記録の管理
858
+ */
859
+ const MESSAGES_LIMIT = 1000;
860
+ const EVENTS_LIMIT = 1000;
861
+ // 実行ログ
862
+ let logs = [];
863
+ // KARTEイベント
864
+ let events = [];
818
865
  /** @internal */
819
- function registerInput({ name, statePath, validator = () => true, initialValue, }) {
820
- const writableValue = {
821
- subscribe(run) {
822
- return formData.subscribe(formData => {
823
- run(formData[name]?.value);
824
- });
825
- },
826
- set(value) {
827
- formData.update(prev => ({
828
- ...prev,
829
- [name]: {
830
- statePath,
831
- value,
832
- isValid: validator(value),
833
- },
834
- }));
835
- },
836
- update(updater) {
837
- formData.update(prev => {
838
- const prevValue = prev[name]?.value;
839
- return {
840
- ...prev,
841
- [name]: {
842
- statePath,
843
- value: updater(prevValue),
844
- isValid: validator(prevValue),
845
- },
846
- };
847
- });
848
- },
849
- };
850
- if (isEmpty(get(writableValue))) {
851
- writableValue.set(initialValue);
852
- }
853
- return writableValue;
866
+ function getLogs() {
867
+ return logs;
854
868
  }
855
869
  /** @internal */
856
- const getValuesAreValidReader = statePath => ({
857
- subscribe(callback) {
858
- return formData.subscribe(formData => {
859
- const valuesAreValid = Object.entries(formData)
860
- .filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
861
- .every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
862
- callback(valuesAreValid);
863
- });
870
+ function getEvents() {
871
+ return events;
872
+ }
873
+ // iframe内の場合は親windowを参照する
874
+ function w(w) {
875
+ return w.parent === w ? w : w.parent;
876
+ }
877
+ /**
878
+ * ログを送信する関数群
879
+ *
880
+ * @internal
881
+ */
882
+ const logger = {
883
+ info: (...messages) => {
884
+ const log = cloneToJson({ level: 'info', messages, date: new Date() });
885
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
864
886
  },
865
- });
866
- function formDataToEventValues(campaignId, formData) {
867
- const questions = [];
868
- const answersMap = {};
869
- Object.entries(formData).forEach(([name, dataItem]) => {
870
- questions.push(name);
871
- const value = dataItem.value;
872
- const answerKey = `question_${name}`;
873
- if (Array.isArray(value)) {
874
- answersMap[answerKey] = {
875
- choices: value,
876
- };
887
+ log: (...messages) => {
888
+ const log = cloneToJson({ level: 'info', messages, date: new Date() });
889
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
890
+ },
891
+ error: (...messages) => {
892
+ const log = cloneToJson({ level: 'error', messages, date: new Date() });
893
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
894
+ },
895
+ warn: (...messages) => {
896
+ const log = cloneToJson({ level: 'warn', messages, date: new Date() });
897
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
898
+ },
899
+ system: (...messages) => {
900
+ const log = cloneToJson({ level: 'system', messages, date: new Date() });
901
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
902
+ },
903
+ event: (name, values) => {
904
+ const event = values ? { name, values, date: new Date() } : { name, date: new Date() };
905
+ w(window).postMessage({
906
+ type: 'KARTE-ACTION-LOGGER',
907
+ detail: { method: 'event', event, values: values },
908
+ }, '*');
909
+ },
910
+ clear: () => {
911
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clear' } }, '*');
912
+ },
913
+ clearEvents: () => {
914
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clearEvents' } }, '*');
915
+ },
916
+ };
917
+ /**
918
+ * メッセージを実行ログに表示する
919
+ *
920
+ * @internal
921
+ */
922
+ function listenLogger() {
923
+ const handler = (event) => {
924
+ const { type, detail } = event.data;
925
+ if (event.origin !== location.origin) {
926
+ return;
877
927
  }
878
- else if (typeof value === 'string') {
879
- answersMap[answerKey] = {
880
- free_answer: value,
881
- };
928
+ if (type !== 'KARTE-ACTION-LOGGER') {
929
+ return;
930
+ }
931
+ if (detail.method === 'clear') {
932
+ logs = [];
933
+ }
934
+ else if (detail.method === 'clearEvents') {
935
+ events = [];
936
+ }
937
+ else if (detail.method === 'log') {
938
+ if (MESSAGES_LIMIT <= logs.length) {
939
+ logs.shift();
940
+ }
941
+ const { level, messages } = detail.log;
942
+ const log = { level, messages, date: new Date() };
943
+ logs.push(log);
944
+ }
945
+ else if (detail.method === 'event') {
946
+ if (EVENTS_LIMIT <= events.length) {
947
+ events.shift();
948
+ }
949
+ const { name, values } = detail.event;
950
+ const karteEvent = values
951
+ ? { name, values, date: new Date() }
952
+ : { name, date: new Date() };
953
+ events.push(karteEvent);
882
954
  }
883
- });
884
- return {
885
- [campaignId]: {
886
- questions,
887
- ...answersMap,
888
- },
889
- };
890
- }
891
- /** @internal */
892
- function submit() {
893
- const systemConfig = getSystem();
894
- const campaignId = systemConfig.campaignId;
895
- if (campaignId) {
896
- const formData$1 = get(formData);
897
- const values = formDataToEventValues(campaignId, formData$1);
898
- return values;
899
- }
900
- {
901
- const formData$1 = get(formData);
902
- const values = formDataToEventValues('mock', formData$1);
903
- console.log('values: ', values);
904
- return values;
905
- }
906
- }
907
-
908
- /** @internal */
909
- const ALL_ACTION_ID = 'KARTE_ALL_ACTION_ID';
910
- /** @internal */
911
- const ALL_ACTION_SHORTEN_ID = 'KARTE_ALL_ACTION_SHORTEN_ID';
912
- // prettier-ignore
913
- /** @internal */
914
- const actionId = ALL_ACTION_ID
915
- ;
916
- /** @internal */
917
- const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
918
- /** @internal */
919
- const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
920
- /** @internal */
921
- const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
922
- /** @internal */
923
- const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
924
- /** @internal */
925
- const handleState = (event) => {
926
- if (event.detail.actionId === actionId || event.detail.actionId === ALL_ACTION_ID) {
927
- send_event('_message_state_changed', { state: event.detail.to });
928
- setState$1(event.detail.to, { disableInPreview: event.detail.disableInPreview });
929
- }
930
- };
931
- /** @internal */
932
- const initialize = (setting) => {
933
- const newSetting = setSetting(setting);
934
- if (newSetting.initialState) {
935
- setState$1(newSetting.initialState);
936
- }
937
- setOpened(true);
938
- setClosed(false); // deprecated
939
- return () => finalize();
940
- };
941
- /** @internal */
942
- const finalize = () => {
943
- resetSetting();
944
- };
945
- /** @internal */
946
- const send_event = (event_name, values) => {
947
- const setting = getSetting();
948
- setting?.send?.(event_name, values);
949
- };
950
- function _moveTo(to) {
951
- window.dispatchEvent(new CustomEvent(ACTION_CHANGE_STATE_EVENT, { detail: { to, actionId } }));
952
- }
953
- /** @internal */
954
- const moveTo = (to) => () => {
955
- _moveTo(to);
956
- };
957
- /** @internal */
958
- const linkTo = (to, targetBlank = true) => () => {
959
- send_event('message_click', { url: to, state: getState$1() });
960
- if (targetBlank) {
961
- window.open(to);
962
- }
963
- else {
964
- location.href = to;
965
- }
966
- };
967
- /** @internal */
968
- const closeApp = (trigger) => () => {
969
- window.dispatchEvent(new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } }));
970
- };
971
- /** @internal */
972
- const runScript = (handlerName) => () => {
973
- const handlers = getEventHandlers();
974
- const handler = handlers[handlerName];
975
- if (!handler)
976
- return;
977
- try {
978
- handler();
979
- }
980
- catch (e) {
981
- console.warn('Failed to run custom handler', handlerName, e);
982
- }
983
- };
984
- /** @internal */
985
- const submitForm = (to) => () => {
986
- const values = submit();
987
- send_event('_answer_question', values);
988
- _moveTo(to);
989
- };
990
- /** @internal */
991
- const execOnClickOperation = (onClickOperation) => {
992
- if (onClickOperation.operation === 'linkTo') {
993
- linkTo(...onClickOperation.args)();
994
- }
995
- else if (onClickOperation.operation === 'moveTo') {
996
- moveTo(...onClickOperation.args)();
997
- }
998
- else if (onClickOperation.operation === 'closeApp') {
999
- closeApp(onClickOperation.args[0] || 'button')();
1000
- }
1001
- else if (onClickOperation.operation === 'runScript') {
1002
- runScript(onClickOperation.args[0])();
1003
- }
1004
- else if (onClickOperation.operation === 'submitForm') {
1005
- submitForm(onClickOperation.args[0])();
1006
- }
1007
- };
1008
- /** @internal */
1009
- const haveFunction = (onClickOperation) => {
1010
- return onClickOperation.operation !== 'none';
1011
- };
1012
- /**
1013
- * The function to activate svelte animation.
1014
- *
1015
- * @param node - A target node of animation. This argument is passed by svelte, by default.
1016
- * @param customAnimationOptions - A custom animation option object
1017
- *
1018
- * @see {@link https://svelte.dev/docs#template-syntax-element-directives-transition-fn-custom-transition-functions| Custom transition functions} for detail documentation
1019
- *
1020
- * @internal
1021
- */
1022
- function customAnimation(node, { transform, animationStyle, delay = 0, duration = 1000 }) {
1023
- {
1024
- return {};
1025
- }
1026
- }
1027
- /**
1028
- * ES Modules に対応していない JavaScript をページに読み込む
1029
- *
1030
- * @param src - JavaScript ファイルのリンク URL
1031
- *
1032
- * @public
1033
- */
1034
- async function loadGlobalScript(src) {
1035
- return new Promise((resolve, reject) => {
1036
- const script = document.createElement('script');
1037
- script.src = src;
1038
- document.body.appendChild(script);
1039
- script.addEventListener('load', () => resolve(script));
1040
- script.addEventListener('error', () => reject(script));
1041
- });
1042
- }
1043
- /**
1044
- * グローバル CSS をページに適用する
1045
- *
1046
- * @param css - CSS
1047
- *
1048
- * @public
1049
- */
1050
- async function applyGlobalCss(css) {
1051
- return new Promise((resolve, reject) => {
1052
- const style = document.createElement('style');
1053
- style.textContent = css;
1054
- document.body.appendChild(style);
1055
- style.addEventListener('load', () => resolve(style));
1056
- style.addEventListener('error', () => reject(style));
1057
- });
1058
- }
1059
- /**
1060
- * style ファイルをページに読み込む
1061
- *
1062
- * @param href - style ファイルのリンク URL
1063
- *
1064
- * @public
1065
- */
1066
- async function loadGlobalStyle(href) {
1067
- return new Promise((resolve, reject) => {
1068
- const link = document.createElement('link');
1069
- link.rel = 'stylesheet';
1070
- link.href = href;
1071
- document.body.appendChild(link);
1072
- link.addEventListener('load', () => resolve(link));
1073
- link.addEventListener('error', () => reject(link));
1074
- });
1075
- }
1076
- // @internal
1077
- function getCssVariables(data) {
1078
- return Object.entries(data)
1079
- .filter(([key, value]) => {
1080
- return ['string', 'number'].includes(typeof value) && key.startsWith('--');
1081
- })
1082
- .map(([key, value]) => `${key}:${value}`)
1083
- .join(';');
1084
- }
1085
-
1086
- /**
1087
- * アクションのログの記録の管理
1088
- */
1089
- const MESSAGES_LIMIT = 1000;
1090
- const EVENTS_LIMIT = 1000;
1091
- // 実行ログ
1092
- let logs = [];
1093
- // KARTEイベント
1094
- let events = [];
1095
- /** @internal */
1096
- function getLogs() {
1097
- return logs;
1098
- }
1099
- /** @internal */
1100
- function getEvents() {
1101
- return events;
1102
- }
1103
- // iframe内の場合は親windowを参照する
1104
- function w(w) {
1105
- return w.parent === w ? w : w.parent;
1106
- }
1107
- /**
1108
- * ログを送信する関数群
1109
- *
1110
- * @internal
1111
- */
1112
- const logger = {
1113
- info: (...messages) => {
1114
- const log = cloneToJson({ level: 'info', messages, date: new Date() });
1115
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1116
- },
1117
- log: (...messages) => {
1118
- const log = cloneToJson({ level: 'info', messages, date: new Date() });
1119
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1120
- },
1121
- error: (...messages) => {
1122
- const log = cloneToJson({ level: 'error', messages, date: new Date() });
1123
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1124
- },
1125
- warn: (...messages) => {
1126
- const log = cloneToJson({ level: 'warn', messages, date: new Date() });
1127
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1128
- },
1129
- system: (...messages) => {
1130
- const log = cloneToJson({ level: 'system', messages, date: new Date() });
1131
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1132
- },
1133
- event: (name, values) => {
1134
- const event = values ? { name, values, date: new Date() } : { name, date: new Date() };
1135
- w(window).postMessage({
1136
- type: 'KARTE-ACTION-LOGGER',
1137
- detail: { method: 'event', event, values: values },
1138
- }, '*');
1139
- },
1140
- clear: () => {
1141
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clear' } }, '*');
1142
- },
1143
- clearEvents: () => {
1144
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clearEvents' } }, '*');
1145
- },
1146
- };
1147
- /**
1148
- * メッセージを実行ログに表示する
1149
- *
1150
- * @internal
1151
- */
1152
- function listenLogger() {
1153
- const handler = (event) => {
1154
- const { type, detail } = event.data;
1155
- if (event.origin !== location.origin) {
1156
- return;
1157
- }
1158
- if (type !== 'KARTE-ACTION-LOGGER') {
1159
- return;
1160
- }
1161
- if (detail.method === 'clear') {
1162
- logs = [];
1163
- }
1164
- else if (detail.method === 'clearEvents') {
1165
- events = [];
1166
- }
1167
- else if (detail.method === 'log') {
1168
- if (MESSAGES_LIMIT <= logs.length) {
1169
- logs.shift();
1170
- }
1171
- const { level, messages } = detail.log;
1172
- const log = { level, messages, date: new Date() };
1173
- logs.push(log);
1174
- }
1175
- else if (detail.method === 'event') {
1176
- if (EVENTS_LIMIT <= events.length) {
1177
- events.shift();
1178
- }
1179
- const { name, values } = detail.event;
1180
- const karteEvent = values
1181
- ? { name, values, date: new Date() }
1182
- : { name, date: new Date() };
1183
- events.push(karteEvent);
1184
- }
1185
- };
1186
- window.addEventListener('message', handler, false);
1187
- return () => {
1188
- window.removeEventListener('message', handler, false);
955
+ };
956
+ window.addEventListener('message', handler, false);
957
+ return () => {
958
+ window.removeEventListener('message', handler, false);
1189
959
  };
1190
960
  }
1191
961
  const { info, log, error, warn } = console;
@@ -1229,6 +999,9 @@ function cloneToJson(data) {
1229
999
  }
1230
1000
  }
1231
1001
 
1002
+ /**
1003
+ * モーダル(ポップアップ)のロジックを管理する
1004
+ */
1232
1005
  function doPresent({ direction, deltaRate }, downFn, upFn, condition = false) {
1233
1006
  if (direction === 'down' && deltaRate > 0) {
1234
1007
  downFn();
@@ -1321,6 +1094,23 @@ function showOnTime(props, show = NOOP) {
1321
1094
  : null;
1322
1095
  }
1323
1096
 
1097
+ /** @internal */
1098
+ const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
1099
+ /** @internal */
1100
+ const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
1101
+ /** @internal */
1102
+ const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
1103
+ /** @internal */
1104
+ const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
1105
+ /** @internal */
1106
+ const send_event = (event_name, values) => {
1107
+ const setting = getSetting();
1108
+ setting?.send?.(event_name, values);
1109
+ };
1110
+
1111
+ /**
1112
+ * アクションテーブルに関連するコードの管理
1113
+ */
1324
1114
  const DEFAULT_COLLECTION_ENDPOINT = typeof __FLYER_GEN_COLLECTION_API_ENDPOINT__ === 'string'
1325
1115
  ? __FLYER_GEN_COLLECTION_API_ENDPOINT__
1326
1116
  : 'https://t.karte.io/collection';
@@ -1413,83 +1203,34 @@ const loadActionTable = async (config, api_key, endpoint) => {
1413
1203
  }, {});
1414
1204
  };
1415
1205
 
1416
- /** @internal */
1417
- const ACTION_HOOK_LABEL = '__ACTION_HOOK__';
1418
1206
  /**
1419
- * アクションが作成 (create) される前にフックする関数
1207
+ * Edgeが起動するアクションに関連するコードを管理する
1420
1208
  *
1421
- * @param fn - 呼び出されるフック関数
1209
+ * アクションのCreate, Destroyの状態はここで管理する。
1422
1210
  *
1423
- * @public
1211
+ * FIXME: モーダルなどの機能ごとのコードを分離したい
1424
1212
  */
1425
- function onCreate(fn) {
1426
- let { onCreateHandlers } = getInternalHandlers();
1427
- if (!onCreateHandlers) {
1428
- onCreateHandlers = [];
1429
- }
1430
- onCreateHandlers.push(fn);
1431
- setInternalHandlers({ onCreateHandlers });
1432
- }
1433
- /**
1434
- * アクションが表示 (show) された後にフックする関数
1435
- *
1436
- * @param fn - 呼び出されるフック関数
1437
- *
1438
- * @public
1439
- */
1440
- function onShow(fn) {
1441
- let { onShowHandlers } = getInternalHandlers();
1442
- if (!onShowHandlers) {
1443
- onShowHandlers = [];
1444
- }
1445
- onShowHandlers.push(fn);
1446
- setInternalHandlers({ onShowHandlers });
1447
- }
1448
- /**
1449
- * アクションがクローズ (close) される前にフックする関数
1450
- *
1451
- * @param fn - 呼び出されるフック関数
1452
- *
1453
- * @public
1454
- */
1455
- function onClose(fn) {
1456
- let { onCloseHandlers } = getInternalHandlers();
1457
- if (!onCloseHandlers) {
1458
- onCloseHandlers = [];
1459
- }
1460
- onCloseHandlers.push(fn);
1461
- setInternalHandlers({ onCloseHandlers });
1462
- }
1463
- /**
1464
- * アクションが破棄 (destroy) される前にフックする関数
1465
- *
1466
- * @param fn - 呼び出されるフック関数
1467
- *
1468
- * @public
1469
- */
1470
- function onDestroy(fn) {
1471
- let { onDestroyHandlers } = getInternalHandlers();
1472
- if (!onDestroyHandlers) {
1473
- onDestroyHandlers = [];
1213
+ /** @internal */
1214
+ const handleState = (event) => {
1215
+ if (event.detail.actionId === actionId || event.detail.actionId === ALL_ACTION_ID) {
1216
+ send_event('_message_state_changed', { state: event.detail.to });
1217
+ setState$1(event.detail.to, { disableInPreview: event.detail.disableInPreview });
1474
1218
  }
1475
- onDestroyHandlers.push(fn);
1476
- setInternalHandlers({ onDestroyHandlers });
1477
- }
1478
- /**
1479
- * アクションのステートが変更された (changeState) 後にフックする関数
1480
- *
1481
- * @param fn - 呼び出されるフック関数
1482
- *
1483
- * @public
1484
- */
1485
- function onChangeState(fn) {
1486
- let { onChangeStateHandlers } = getInternalHandlers();
1487
- if (!onChangeStateHandlers) {
1488
- onChangeStateHandlers = [];
1219
+ };
1220
+ /** @internal */
1221
+ const initialize = (setting) => {
1222
+ const newSetting = setSetting(setting);
1223
+ if (newSetting.initialState) {
1224
+ setState$1(newSetting.initialState);
1489
1225
  }
1490
- onChangeStateHandlers.push(fn);
1491
- setInternalHandlers({ onChangeStateHandlers });
1492
- }
1226
+ setOpened(true);
1227
+ setClosed(false); // deprecated
1228
+ return () => finalize();
1229
+ };
1230
+ /** @internal */
1231
+ const finalize = () => {
1232
+ resetSetting();
1233
+ };
1493
1234
  /**
1494
1235
  * アクションを作成する
1495
1236
  *
@@ -1679,92 +1420,155 @@ function create(App, options = {
1679
1420
  window.removeEventListener('beforeunload', dispatchDestroyEvent, false);
1680
1421
  loggerCleanup();
1681
1422
  };
1682
- return appCleanup;
1423
+ return appCleanup;
1424
+ }
1425
+ /** @internal */
1426
+ function ensureActionRoot(useShadow = true) {
1427
+ const systemConfig = getSystem();
1428
+ const rootAttrs = {
1429
+ class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
1430
+ [`data-${KARTE_ACTION_RID}`]: actionId,
1431
+ [`data-${KARTE_ACTION_SHORTEN_ID}`]: systemConfig.shortenId
1432
+ ? systemConfig.shortenId
1433
+ : ALL_ACTION_SHORTEN_ID,
1434
+ };
1435
+ let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1436
+ if (el == null) {
1437
+ el = h('div', rootAttrs);
1438
+ document.body.appendChild(el);
1439
+ }
1440
+ const isShadow = !!document.body.attachShadow && useShadow;
1441
+ if (isShadow) {
1442
+ return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
1443
+ }
1444
+ else {
1445
+ return el;
1446
+ }
1447
+ }
1448
+ /**
1449
+ * Dispatch the event to destroy KARTE action
1450
+ *
1451
+ * @internal
1452
+ */
1453
+ function dispatchDestroyEvent() {
1454
+ const event = new CustomEvent(ACTION_DESTROY_EVENT);
1455
+ window.dispatchEvent(event);
1456
+ }
1457
+ /**
1458
+ * アクションの破棄する
1459
+ *
1460
+ * @public
1461
+ */
1462
+ function destroyAction() {
1463
+ setDestroyed(true);
1464
+ dispatchDestroyEvent();
1465
+ }
1466
+ /**
1467
+ * アクションが作成 (create) される前にフックする関数
1468
+ *
1469
+ * @param fn - 呼び出されるフック関数
1470
+ *
1471
+ * @public
1472
+ */
1473
+ function onCreate(fn) {
1474
+ let { onCreateHandlers } = getInternalHandlers();
1475
+ if (!onCreateHandlers) {
1476
+ onCreateHandlers = [];
1477
+ }
1478
+ onCreateHandlers.push(fn);
1479
+ setInternalHandlers({ onCreateHandlers });
1480
+ }
1481
+ /**
1482
+ * アクションが破棄 (destroy) される前にフックする関数
1483
+ *
1484
+ * @param fn - 呼び出されるフック関数
1485
+ *
1486
+ * @public
1487
+ */
1488
+ function onDestroy(fn) {
1489
+ let { onDestroyHandlers } = getInternalHandlers();
1490
+ if (!onDestroyHandlers) {
1491
+ onDestroyHandlers = [];
1492
+ }
1493
+ onDestroyHandlers.push(fn);
1494
+ setInternalHandlers({ onDestroyHandlers });
1495
+ }
1496
+ /**
1497
+ * 非推奨
1498
+ *
1499
+ * @deprecated 非推奨
1500
+ *
1501
+ * @internal
1502
+ */
1503
+ const showModal = create;
1504
+ /**
1505
+ * 非推奨
1506
+ *
1507
+ * @deprecated 非推奨
1508
+ *
1509
+ * @internal
1510
+ */
1511
+ const ensureModalRoot = ensureActionRoot;
1512
+ /**
1513
+ * 非推奨
1514
+ *
1515
+ * @deprecated 非推奨
1516
+ *
1517
+ * @internal
1518
+ */
1519
+ function createApp(App, options = {
1520
+ send: () => { },
1521
+ publish: () => { },
1522
+ props: {},
1523
+ variables: {},
1524
+ localVariablesQuery: undefined,
1525
+ }) {
1526
+ let app = null;
1527
+ const close = () => {
1528
+ if (app) {
1529
+ app.$destroy();
1530
+ app = null;
1531
+ }
1532
+ };
1533
+ const appArgs = {
1534
+ target: null,
1535
+ props: {
1536
+ send: options.send,
1537
+ publish: options.publish,
1538
+ close,
1539
+ data: {
1540
+ ...options.props,
1541
+ ...options.variables,
1542
+ },
1543
+ },
1544
+ };
1545
+ {
1546
+ const win = ensureModalRoot(false);
1547
+ appArgs.target = win;
1548
+ appArgs.hydrate = true;
1549
+ }
1550
+ return {
1551
+ close,
1552
+ show: () => {
1553
+ if (app) {
1554
+ return;
1555
+ }
1556
+ options.send('message_open');
1557
+ app = new App(appArgs);
1558
+ },
1559
+ };
1683
1560
  }
1684
1561
  /**
1685
- * Dispatch the event to destroy KARTE action
1562
+ * 非推奨
1686
1563
  *
1687
- * @internal
1688
- */
1689
- function dispatchDestroyEvent() {
1690
- const event = new CustomEvent(ACTION_DESTROY_EVENT);
1691
- window.dispatchEvent(event);
1692
- }
1693
- /**
1694
- * アクションの破棄する
1564
+ * @deprecated 非推奨
1695
1565
  *
1696
- * @public
1566
+ * @internal
1697
1567
  */
1698
- function destroyAction() {
1568
+ function destroy() {
1699
1569
  setDestroyed(true);
1700
1570
  dispatchDestroyEvent();
1701
1571
  }
1702
- /**
1703
- * アクションを表示する
1704
- *
1705
- * @public
1706
- */
1707
- function showAction() {
1708
- const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
1709
- window.dispatchEvent(event);
1710
- }
1711
- /**
1712
- * アクションを閉じる
1713
- *
1714
- * @param trigger - 閉じた時のトリガー。デフォルト `'none'`
1715
- *
1716
- * @public
1717
- */
1718
- function closeAction(trigger = 'none') {
1719
- const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
1720
- window.dispatchEvent(event);
1721
- }
1722
- /** @internal */
1723
- const KARTE_ACTION_ROOT = 'karte-action-root';
1724
- /** @internal */
1725
- const KARTE_ACTION_RID = 'karte-action-rid';
1726
- /** @internal */
1727
- const KARTE_ACTION_SHORTEN_ID = 'karte-action-id';
1728
- /** @internal */
1729
- function ensureActionRoot(useShadow = true) {
1730
- const systemConfig = getSystem();
1731
- const rootAttrs = {
1732
- class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
1733
- [`data-${KARTE_ACTION_RID}`]: actionId,
1734
- [`data-${KARTE_ACTION_SHORTEN_ID}`]: systemConfig.shortenId
1735
- ? systemConfig.shortenId
1736
- : ALL_ACTION_SHORTEN_ID,
1737
- };
1738
- let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1739
- if (el == null) {
1740
- el = h('div', rootAttrs);
1741
- document.body.appendChild(el);
1742
- }
1743
- const isShadow = !!document.body.attachShadow && useShadow;
1744
- if (isShadow) {
1745
- return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
1746
- }
1747
- else {
1748
- return el;
1749
- }
1750
- }
1751
- /** @internal */
1752
- const h = (type, props, ...children) => {
1753
- const el = document.createElement(type);
1754
- for (const key of Object.keys(props)) {
1755
- const v = props[key];
1756
- if (key === 'style') {
1757
- Object.assign(el.style, v);
1758
- }
1759
- else {
1760
- el.setAttribute(key, v);
1761
- }
1762
- }
1763
- for (const child of children) {
1764
- el.appendChild(child);
1765
- }
1766
- return el;
1767
- };
1768
1572
  /**
1769
1573
  * 非推奨
1770
1574
  *
@@ -1797,19 +1601,129 @@ function createFog({ color = '#000', opacity = '50%', zIndex = 999, onclick, })
1797
1601
  root.appendChild(fog);
1798
1602
  return { fog, close };
1799
1603
  }
1604
+
1800
1605
  /**
1801
- * アクションのルートの DOM 要素を取得する
1606
+ * スクリプト接客が利用するコードの管理
1607
+ */
1608
+ /**
1609
+ * ES Modules に対応していない JavaScript をページに読み込む
1802
1610
  *
1803
- * @returns アクションがルートの DOM 要素 を持つ場合は DOM 要素を返します。ない場合は `null` を返します
1611
+ * @param src - JavaScript ファイルのリンク URL
1804
1612
  *
1805
1613
  * @public
1806
1614
  */
1807
- function getActionRoot() {
1808
- const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1809
- if (!root?.shadowRoot) {
1810
- return null;
1615
+ async function loadGlobalScript(src) {
1616
+ return new Promise((resolve, reject) => {
1617
+ const script = document.createElement('script');
1618
+ script.src = src;
1619
+ document.body.appendChild(script);
1620
+ script.addEventListener('load', () => resolve(script));
1621
+ script.addEventListener('error', () => reject(script));
1622
+ });
1623
+ }
1624
+ /**
1625
+ * グローバル CSS をページに適用する
1626
+ *
1627
+ * @param css - CSS
1628
+ *
1629
+ * @public
1630
+ */
1631
+ async function applyGlobalCss(css) {
1632
+ return new Promise((resolve, reject) => {
1633
+ const style = document.createElement('style');
1634
+ style.textContent = css;
1635
+ document.body.appendChild(style);
1636
+ style.addEventListener('load', () => resolve(style));
1637
+ style.addEventListener('error', () => reject(style));
1638
+ });
1639
+ }
1640
+ /**
1641
+ * style ファイルをページに読み込む
1642
+ *
1643
+ * @param href - style ファイルのリンク URL
1644
+ *
1645
+ * @public
1646
+ */
1647
+ async function loadGlobalStyle(href) {
1648
+ return new Promise((resolve, reject) => {
1649
+ const link = document.createElement('link');
1650
+ link.rel = 'stylesheet';
1651
+ link.href = href;
1652
+ document.body.appendChild(link);
1653
+ link.addEventListener('load', () => resolve(link));
1654
+ link.addEventListener('error', () => reject(link));
1655
+ });
1656
+ }
1657
+
1658
+ /**
1659
+ * モーダル(ポップアップ)に関連するコードの管理
1660
+ *
1661
+ * アクションのShow, Close, ChangeStateの状態はここで管理する。
1662
+ */
1663
+ /**
1664
+ * アクションが表示 (show) された後にフックする関数
1665
+ *
1666
+ * @param fn - 呼び出されるフック関数
1667
+ *
1668
+ * @public
1669
+ */
1670
+ function onShow(fn) {
1671
+ let { onShowHandlers } = getInternalHandlers();
1672
+ if (!onShowHandlers) {
1673
+ onShowHandlers = [];
1811
1674
  }
1812
- return root.shadowRoot;
1675
+ onShowHandlers.push(fn);
1676
+ setInternalHandlers({ onShowHandlers });
1677
+ }
1678
+ /**
1679
+ * アクションがクローズ (close) される前にフックする関数
1680
+ *
1681
+ * @param fn - 呼び出されるフック関数
1682
+ *
1683
+ * @public
1684
+ */
1685
+ function onClose(fn) {
1686
+ let { onCloseHandlers } = getInternalHandlers();
1687
+ if (!onCloseHandlers) {
1688
+ onCloseHandlers = [];
1689
+ }
1690
+ onCloseHandlers.push(fn);
1691
+ setInternalHandlers({ onCloseHandlers });
1692
+ }
1693
+ /**
1694
+ * アクションのステートが変更された (changeState) 後にフックする関数
1695
+ *
1696
+ * @param fn - 呼び出されるフック関数
1697
+ *
1698
+ * @public
1699
+ */
1700
+ function onChangeState(fn) {
1701
+ let { onChangeStateHandlers } = getInternalHandlers();
1702
+ if (!onChangeStateHandlers) {
1703
+ onChangeStateHandlers = [];
1704
+ }
1705
+ onChangeStateHandlers.push(fn);
1706
+ setInternalHandlers({ onChangeStateHandlers });
1707
+ }
1708
+ /**
1709
+ * アクションを表示する
1710
+ *
1711
+ * @public
1712
+ */
1713
+ function showAction() {
1714
+ const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
1715
+ window.dispatchEvent(event);
1716
+ }
1717
+ /**
1718
+ * アクションを閉じる
1719
+ *
1720
+ * @param trigger - 閉じた時のトリガー。デフォルト `'none'`
1721
+ *
1722
+ * @public
1723
+ */
1724
+ function closeAction(trigger = 'none') {
1725
+ const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
1726
+ window.dispatchEvent(event);
1813
1727
  }
1814
1728
  /**
1815
1729
  * アクションに CSS を適用する
@@ -1824,7 +1738,7 @@ async function applyCss(css) {
1824
1738
  return new Promise((resolve, reject) => {
1825
1739
  const style = document.createElement('style');
1826
1740
  style.textContent = css;
1827
- const shadowRoot = getActionShadowRoot();
1741
+ const shadowRoot = getActionRoot();
1828
1742
  if (!shadowRoot)
1829
1743
  return;
1830
1744
  shadowRoot.append(style);
@@ -1863,7 +1777,7 @@ async function fixFontFaceIssue(href, cssRules) {
1863
1777
  * @public
1864
1778
  */
1865
1779
  async function loadStyle(href) {
1866
- const sr = getActionShadowRoot();
1780
+ const sr = getActionRoot();
1867
1781
  if (!sr)
1868
1782
  return;
1869
1783
  let cssRules = '';
@@ -1887,101 +1801,35 @@ async function loadStyle(href) {
1887
1801
  await fontFaceCss.replace(fontFaceRules);
1888
1802
  // @ts-ignore
1889
1803
  sr.adoptedStyleSheets = [...sr.adoptedStyleSheets, css, fontFaceCss];
1890
- // Chromeのバグで、ページとShadow Rootの両方に、@font-faceを設定する必要がある
1891
- // @see https://stackoverflow.com/a/63717709
1892
- // @ts-ignore
1893
- document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
1894
- }
1895
- // -------- The following codes are deprecated --------
1896
- /**
1897
- * 非推奨
1898
- *
1899
- * @deprecated 非推奨
1900
- *
1901
- * @internal
1902
- */
1903
- const showModal = create;
1904
- /**
1905
- * 非推奨
1906
- *
1907
- * @deprecated 非推奨
1908
- *
1909
- * @internal
1910
- */
1911
- const KARTE_MODAL_ROOT = 'karte-modal-root';
1912
- /**
1913
- * 非推奨
1914
- *
1915
- * @deprecated 非推奨
1916
- *
1917
- * @internal
1918
- */
1919
- const ensureModalRoot = ensureActionRoot;
1920
- /**
1921
- * 非推奨
1922
- *
1923
- * @deprecated 非推奨
1924
- *
1925
- * @internal
1926
- */
1927
- const show = showAction;
1928
- /**
1929
- * 非推奨
1930
- *
1931
- * @deprecated 非推奨
1932
- *
1933
- * @internal
1934
- */
1935
- const close = closeAction;
1804
+ // Chromeのバグで、ページとShadow Rootの両方に、@font-faceを設定する必要がある
1805
+ // @see https://stackoverflow.com/a/63717709
1806
+ // @ts-ignore
1807
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
1808
+ }
1809
+ // @internal
1810
+ function getCssVariables(data) {
1811
+ return Object.entries(data)
1812
+ .filter(([key, value]) => {
1813
+ return ['string', 'number'].includes(typeof value) && key.startsWith('--');
1814
+ })
1815
+ .map(([key, value]) => `${key}:${value}`)
1816
+ .join(';');
1817
+ }
1936
1818
  /**
1937
- * 非推奨
1819
+ * アクションのルートの DOM 要素を取得する
1938
1820
  *
1939
- * @deprecated 非推奨
1821
+ * @returns アクションがルートの DOM 要素 を持つ場合は DOM 要素を返します。ない場合は `null` を返します
1940
1822
  *
1941
- * @internal
1823
+ * @public
1942
1824
  */
1943
- function createApp(App, options = {
1944
- send: () => { },
1945
- publish: () => { },
1946
- props: {},
1947
- variables: {},
1948
- localVariablesQuery: undefined,
1949
- }) {
1950
- let app = null;
1951
- const close = () => {
1952
- if (app) {
1953
- app.$destroy();
1954
- app = null;
1955
- }
1956
- };
1957
- const appArgs = {
1958
- target: null,
1959
- props: {
1960
- send: options.send,
1961
- publish: options.publish,
1962
- close,
1963
- data: {
1964
- ...options.props,
1965
- ...options.variables,
1966
- },
1967
- },
1968
- };
1969
- {
1970
- const win = ensureModalRoot(false);
1971
- appArgs.target = win;
1972
- appArgs.hydrate = true;
1825
+ function getActionRoot() {
1826
+ const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1827
+ if (!root?.shadowRoot) {
1828
+ return null;
1973
1829
  }
1974
- return {
1975
- close,
1976
- show: () => {
1977
- if (app) {
1978
- return;
1979
- }
1980
- options.send('message_open');
1981
- app = new App(appArgs);
1982
- },
1983
- };
1830
+ return root.shadowRoot;
1984
1831
  }
1832
+ // -------- The following codes are deprecated --------
1985
1833
  /**
1986
1834
  * 非推奨
1987
1835
  *
@@ -1989,13 +1837,7 @@ function createApp(App, options = {
1989
1837
  *
1990
1838
  * @internal
1991
1839
  */
1992
- function getActionShadowRoot() {
1993
- const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1994
- if (!root?.shadowRoot) {
1995
- return null;
1996
- }
1997
- return root.shadowRoot;
1998
- }
1840
+ const show = showAction;
1999
1841
  /**
2000
1842
  * 非推奨
2001
1843
  *
@@ -2003,13 +1845,10 @@ function getActionShadowRoot() {
2003
1845
  *
2004
1846
  * @internal
2005
1847
  */
2006
- function destroy() {
2007
- setDestroyed(true);
2008
- dispatchDestroyEvent();
2009
- }
1848
+ const close = closeAction;
2010
1849
 
2011
1850
  /**
2012
- * Widget API 互換のインターフェース
1851
+ * エディタv1のWidget API 互換のインターフェース
2013
1852
  */
2014
1853
  const STORE_LS_KEY_PREFIX = 'krt___';
2015
1854
  const valCallbacks = {};
@@ -2543,6 +2382,185 @@ class StateItem extends SvelteComponent {
2543
2382
  }
2544
2383
  }
2545
2384
 
2385
+ function isEmpty(value) {
2386
+ if (Array.isArray(value)) {
2387
+ return value.length === 0;
2388
+ }
2389
+ else {
2390
+ return !value;
2391
+ }
2392
+ }
2393
+ /** @internal */
2394
+ function registerInput({ name, statePath, validator = () => true, initialValue, }) {
2395
+ const writableValue = {
2396
+ subscribe(run) {
2397
+ return formData.subscribe(formData => {
2398
+ run(formData[name]?.value);
2399
+ });
2400
+ },
2401
+ set(value) {
2402
+ formData.update(prev => ({
2403
+ ...prev,
2404
+ [name]: {
2405
+ statePath,
2406
+ value,
2407
+ isValid: validator(value),
2408
+ },
2409
+ }));
2410
+ },
2411
+ update(updater) {
2412
+ formData.update(prev => {
2413
+ const prevValue = prev[name]?.value;
2414
+ return {
2415
+ ...prev,
2416
+ [name]: {
2417
+ statePath,
2418
+ value: updater(prevValue),
2419
+ isValid: validator(prevValue),
2420
+ },
2421
+ };
2422
+ });
2423
+ },
2424
+ };
2425
+ if (isEmpty(get(writableValue))) {
2426
+ writableValue.set(initialValue);
2427
+ }
2428
+ return writableValue;
2429
+ }
2430
+ /** @internal */
2431
+ const getValuesAreValidReader = statePath => ({
2432
+ subscribe(callback) {
2433
+ return formData.subscribe(formData => {
2434
+ const valuesAreValid = Object.entries(formData)
2435
+ .filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
2436
+ .every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
2437
+ callback(valuesAreValid);
2438
+ });
2439
+ },
2440
+ });
2441
+ function formDataToEventValues(campaignId, formData) {
2442
+ const questions = [];
2443
+ const answersMap = {};
2444
+ Object.entries(formData).forEach(([name, dataItem]) => {
2445
+ questions.push(name);
2446
+ const value = dataItem.value;
2447
+ const answerKey = `question_${name}`;
2448
+ if (Array.isArray(value)) {
2449
+ answersMap[answerKey] = {
2450
+ choices: value,
2451
+ };
2452
+ }
2453
+ else if (typeof value === 'string') {
2454
+ answersMap[answerKey] = {
2455
+ free_answer: value,
2456
+ };
2457
+ }
2458
+ });
2459
+ return {
2460
+ [campaignId]: {
2461
+ questions,
2462
+ ...answersMap,
2463
+ },
2464
+ };
2465
+ }
2466
+ /** @internal */
2467
+ function submit() {
2468
+ const systemConfig = getSystem();
2469
+ const campaignId = systemConfig.campaignId;
2470
+ if (campaignId) {
2471
+ const formData$1 = get(formData);
2472
+ const values = formDataToEventValues(campaignId, formData$1);
2473
+ return values;
2474
+ }
2475
+ {
2476
+ const formData$1 = get(formData);
2477
+ const values = formDataToEventValues('mock', formData$1);
2478
+ console.log('values: ', values);
2479
+ return values;
2480
+ }
2481
+ }
2482
+
2483
+ /**
2484
+ * モーダル(ポップアップ)のコンポーネントが利用するコードの管理
2485
+ */
2486
+ function _moveTo(to) {
2487
+ window.dispatchEvent(new CustomEvent(ACTION_CHANGE_STATE_EVENT, { detail: { to, actionId } }));
2488
+ }
2489
+ /** @internal */
2490
+ const moveTo = (to) => () => {
2491
+ _moveTo(to);
2492
+ };
2493
+ /** @internal */
2494
+ const linkTo = (to, targetBlank = true) => () => {
2495
+ send_event('message_click', { url: to, state: getState$1() });
2496
+ if (targetBlank) {
2497
+ window.open(to);
2498
+ }
2499
+ else {
2500
+ location.href = to;
2501
+ }
2502
+ };
2503
+ /** @internal */
2504
+ const closeApp = (trigger) => () => {
2505
+ window.dispatchEvent(new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } }));
2506
+ };
2507
+ /** @internal */
2508
+ const runScript = (handlerName) => () => {
2509
+ const handlers = getEventHandlers();
2510
+ const handler = handlers[handlerName];
2511
+ if (!handler)
2512
+ return;
2513
+ try {
2514
+ handler();
2515
+ }
2516
+ catch (e) {
2517
+ console.warn('Failed to run custom handler', handlerName, e);
2518
+ }
2519
+ };
2520
+ /** @internal */
2521
+ const submitForm = (to) => () => {
2522
+ const values = submit();
2523
+ send_event('_answer_question', values);
2524
+ _moveTo(to);
2525
+ };
2526
+ /** @internal */
2527
+ const execOnClickOperation = (onClickOperation) => {
2528
+ if (onClickOperation.operation === 'linkTo') {
2529
+ linkTo(...onClickOperation.args)();
2530
+ }
2531
+ else if (onClickOperation.operation === 'moveTo') {
2532
+ moveTo(...onClickOperation.args)();
2533
+ }
2534
+ else if (onClickOperation.operation === 'closeApp') {
2535
+ closeApp(onClickOperation.args[0] || 'button')();
2536
+ }
2537
+ else if (onClickOperation.operation === 'runScript') {
2538
+ runScript(onClickOperation.args[0])();
2539
+ }
2540
+ else if (onClickOperation.operation === 'submitForm') {
2541
+ submitForm(onClickOperation.args[0])();
2542
+ }
2543
+ };
2544
+ /** @internal */
2545
+ const haveFunction = (onClickOperation) => {
2546
+ return onClickOperation.operation !== 'none';
2547
+ };
2548
+ /**
2549
+ * The function to activate svelte animation.
2550
+ *
2551
+ * @param node - A target node of animation. This argument is passed by svelte, by default.
2552
+ * @param customAnimationOptions - A custom animation option object
2553
+ *
2554
+ * @see {@link https://svelte.dev/docs#template-syntax-element-directives-transition-fn-custom-transition-functions| Custom transition functions} for detail documentation
2555
+ *
2556
+ * @internal
2557
+ */
2558
+ function customAnimation(node, { transform, animationStyle, delay = 0, duration = 1000 }) {
2559
+ {
2560
+ return {};
2561
+ }
2562
+ }
2563
+
2546
2564
  /* src/components/BackgroundOverray.svelte generated by Svelte v3.53.1 */
2547
2565
 
2548
2566
  function add_css$s(target) {
@@ -2650,7 +2668,7 @@ function add_css$r(target) {
2650
2668
  append_styles(target, "svelte-1tg0tf", ".button.svelte-1tg0tf{display:block;text-decoration:none;color:inherit;border:none;background:none;margin:0;padding:0}.button.svelte-1tg0tf:link,.button.svelte-1tg0tf:visited,.button.svelte-1tg0tf:active,.button.svelte-1tg0tf:hover{color:inherit}");
2651
2669
  }
2652
2670
 
2653
- // (48:0) {:else}
2671
+ // (49:0) {:else}
2654
2672
  function create_else_block$3(ctx) {
2655
2673
  let button;
2656
2674
  let current;
@@ -2728,7 +2746,7 @@ function create_else_block$3(ctx) {
2728
2746
  };
2729
2747
  }
2730
2748
 
2731
- // (44:39)
2749
+ // (45:39)
2732
2750
  function create_if_block_2(ctx) {
2733
2751
  let div;
2734
2752
  let current;
@@ -2797,7 +2815,7 @@ function create_if_block_2(ctx) {
2797
2815
  };
2798
2816
  }
2799
2817
 
2800
- // (40:41)
2818
+ // (41:41)
2801
2819
  function create_if_block_1$2(ctx) {
2802
2820
  let a;
2803
2821
  let a_href_value;
@@ -2893,7 +2911,7 @@ function create_if_block_1$2(ctx) {
2893
2911
  };
2894
2912
  }
2895
2913
 
2896
- // (36:0) {#if disabled}
2914
+ // (37:0) {#if disabled}
2897
2915
  function create_if_block$6(ctx) {
2898
2916
  let div;
2899
2917
  let current;
@@ -3136,7 +3154,7 @@ function add_css$q(target) {
3136
3154
  append_styles(target, "svelte-yyiwdt", ".modal.svelte-yyiwdt{position:fixed;box-sizing:border-box;z-index:2147483647;display:flex}.modal.svelte-yyiwdt > .button{flex:auto;display:flex}.close.svelte-yyiwdt{position:absolute;top:0;right:0}.close.svelte-yyiwdt > .button{position:absolute;display:flex;justify-content:center;align-items:center;background-color:transparent;border:none;cursor:pointer;padding:0;transition:all 0.25s}.close.svelte-yyiwdt > .button:hover{transform:rotate(90deg)}.modal-content.svelte-yyiwdt{flex:auto;display:flex;justify-content:center;align-items:center}");
3137
3155
  }
3138
3156
 
3139
- // (145:0) {#if visible}
3157
+ // (146:0) {#if visible}
3140
3158
  function create_if_block$5(ctx) {
3141
3159
  let div;
3142
3160
  let button;
@@ -3231,7 +3249,7 @@ function create_if_block$5(ctx) {
3231
3249
  };
3232
3250
  }
3233
3251
 
3234
- // (162:6) {#if closable}
3252
+ // (163:6) {#if closable}
3235
3253
  function create_if_block_1$1(ctx) {
3236
3254
  let div;
3237
3255
  let button;
@@ -3303,7 +3321,7 @@ function create_if_block_1$1(ctx) {
3303
3321
  };
3304
3322
  }
3305
3323
 
3306
- // (164:10) <Button onClick={onClose} style={_closeStyle} eventName={closeEventName} eventValue={closeEventValue}>
3324
+ // (165:10) <Button onClick={onClose} style={_closeStyle} eventName={closeEventName} eventValue={closeEventValue}>
3307
3325
  function create_default_slot_1$1(ctx) {
3308
3326
  let svg;
3309
3327
  let path;
@@ -3360,7 +3378,7 @@ function create_default_slot_1$1(ctx) {
3360
3378
  };
3361
3379
  }
3362
3380
 
3363
- // (161:4) <Button {onClick} eventName={clickEventName} eventValue={clickEventValue}>
3381
+ // (162:4) <Button {onClick} eventName={clickEventName} eventValue={clickEventValue}>
3364
3382
  function create_default_slot$6(ctx) {
3365
3383
  let t;
3366
3384
  let div;